Skip to content

Commit 15326ea

Browse files
committed
Add more missing guides
1 parent 18a2250 commit 15326ea

6 files changed

Lines changed: 385 additions & 2 deletions

File tree

src/guides/ai.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,34 @@ const provider = sdk.ai.createProvider();
1212

1313
This returns an `AIProvider` instance that can be used with the `ai` library.
1414

15+
## Getting Upstream Providers
16+
17+
To get information about available AI upstream providers and their configuration status:
18+
19+
```ts
20+
const providers = sdk.ai.getUpstreamProviders();
21+
```
22+
23+
This returns an array of `AIUpstreamProvider` objects, each containing:
24+
25+
- `id` - The provider ID (`"openai"`, `"anthropic"`, `"google"`, or `"openrouter"`)
26+
- `status` - The configuration status (`"Ready"` or `"Missing"`)
27+
28+
This is useful for checking which AI providers are configured before attempting to use them:
29+
30+
```ts
31+
const providers = sdk.ai.getUpstreamProviders();
32+
const openaiProvider = providers.find((p) => p.id === "openai");
33+
34+
if (openaiProvider?.status === "Ready") {
35+
// OpenAI is configured and ready to use
36+
const provider = sdk.ai.createProvider();
37+
// Use the provider...
38+
} else {
39+
sdk.window.showToast("OpenAI is not configured", { variant: "warning" });
40+
}
41+
```
42+
1543
::: tip
1644
The AI provider is compatible with all features of the `ai` library, including text generation, streaming, tool calling, and more. Refer to the [ai SDK documentation](https://ai-sdk.dev/) for advanced usage.
1745
:::

src/guides/files.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,72 @@ export const init = async (sdk: FrontendSDK) => {
179179
## The Result
180180

181181
<img alt="Event output." src="/_images/view_file_frontend.png" center/>
182+
183+
## Listening to File Events
184+
185+
You can listen for events when hosted files are uploaded, updated, or deleted:
186+
187+
### Listening for File Uploads
188+
189+
```ts
190+
const handle = sdk.files.onUploadedHostedFile((file) => {
191+
sdk.log.info(`File uploaded: ${file.name} (${file.size} bytes)`);
192+
sdk.window.showToast(`File "${file.name}" uploaded`, { variant: "success" });
193+
});
194+
195+
// Later, stop listening
196+
handle.stop();
197+
```
198+
199+
### Listening for File Updates
200+
201+
```ts
202+
const handle = sdk.files.onUpdatedHostedFile((file) => {
203+
sdk.log.info(`File updated: ${file.name}`);
204+
sdk.window.showToast(`File "${file.name}" updated`, { variant: "info" });
205+
});
206+
207+
// Later, stop listening
208+
handle.stop();
209+
```
210+
211+
### Listening for File Deletions
212+
213+
```ts
214+
const handle = sdk.files.onDeletedHostedFile((fileId) => {
215+
sdk.log.info(`File deleted: ${fileId}`);
216+
sdk.window.showToast("File deleted", { variant: "info" });
217+
});
218+
219+
// Later, stop listening
220+
handle.stop();
221+
```
222+
223+
## Example: File Monitor Plugin
224+
225+
This example creates a plugin that monitors all file operations and logs them:
226+
227+
```ts
228+
import type { Caido } from "@caido/sdk-frontend";
229+
230+
export type CaidoSDK = Caido;
231+
232+
export const init = (sdk: CaidoSDK) => {
233+
// Monitor file uploads
234+
sdk.files.onUploadedHostedFile((file) => {
235+
sdk.log.info(`[File Monitor] Uploaded: ${file.name} (${file.path})`);
236+
});
237+
238+
// Monitor file updates
239+
sdk.files.onUpdatedHostedFile((file) => {
240+
sdk.log.info(`[File Monitor] Updated: ${file.name} (${file.path})`);
241+
});
242+
243+
// Monitor file deletions
244+
sdk.files.onDeletedHostedFile((fileId) => {
245+
sdk.log.info(`[File Monitor] Deleted: ${fileId}`);
246+
});
247+
248+
sdk.log.info("File monitor plugin initialized");
249+
};
250+
```

src/guides/match_replace.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,69 @@ export const init = (sdk: CaidoSDK) => {
295295
};
296296
```
297297

298+
## Adding Indicators to Rules
299+
300+
Indicators are visual badges displayed next to rule names in the collections tree. They're useful for highlighting important rules or showing status information.
301+
302+
### Adding a Rule Indicator
303+
304+
```ts
305+
const indicator = sdk.matchReplace.addRuleIndicator(ruleId, {
306+
icon: "fas fa-exclamation-triangle",
307+
description: "Security warning",
308+
});
309+
```
310+
311+
The `addRuleIndicator` method returns a handle object with a `remove` method to remove the indicator later:
312+
313+
```ts
314+
// Later, remove the indicator
315+
indicator.remove();
316+
```
317+
318+
### Indicator Options
319+
320+
- `icon` - Font Awesome icon class (e.g., `"fas fa-check"`, `"fas fa-warning"`)
321+
- `description` - Tooltip text shown on hover
322+
323+
### Example: Rule Status Indicators
324+
325+
This example adds indicators to rules based on their enabled status:
326+
327+
```ts
328+
import type { Caido } from "@caido/sdk-frontend";
329+
330+
export type CaidoSDK = Caido;
331+
332+
export const init = (sdk: CaidoSDK) => {
333+
const updateRuleIndicators = () => {
334+
const rules = sdk.matchReplace.getRules();
335+
336+
rules.forEach((rule) => {
337+
if (rule.isEnabled) {
338+
sdk.matchReplace.addRuleIndicator(rule.id, {
339+
icon: "fas fa-check-circle",
340+
description: "Rule is enabled",
341+
});
342+
} else {
343+
sdk.matchReplace.addRuleIndicator(rule.id, {
344+
icon: "fas fa-circle",
345+
description: "Rule is disabled",
346+
});
347+
}
348+
});
349+
};
350+
351+
// Update indicators when rules change
352+
sdk.matchReplace.onCurrentRuleChange(() => {
353+
updateRuleIndicators();
354+
});
355+
356+
// Initial update
357+
updateRuleIndicators();
358+
};
359+
```
360+
298361
### Adding Custom Actions to Match and Replace Slots
299362

300363
This example adds a custom button to the rule update header that duplicates the current rule when clicked.

src/guides/page.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,74 @@ The `init` function creates the Vue app, mounts it to a root element, and regist
190190

191191
<img alt="Add page SKD." src="/_images/add_page_sdk.png" center/>
192192

193+
## Getting and Monitoring Context
194+
195+
The Window SDK provides methods to get and monitor the global application context, including the current page context.
196+
197+
### Getting Current Context
198+
199+
To get the current global context:
200+
201+
```ts
202+
const context = sdk.window.getContext();
203+
```
204+
205+
The context includes:
206+
- `page` - The current page context (if on a specific page), which varies by page type
207+
208+
### Monitoring Context Changes
209+
210+
To listen for changes to the global context:
211+
212+
```ts
213+
const handle = sdk.window.onContextChange((context) => {
214+
if (context.page) {
215+
console.log("Current page:", context.page.kind);
216+
217+
// Access page-specific context
218+
if (context.page.kind === "Replay") {
219+
const replayContext = context.page;
220+
console.log("Replay selection:", replayContext.selection);
221+
}
222+
}
223+
});
224+
225+
// Later, stop listening
226+
handle.stop();
227+
```
228+
229+
### Example: Context-Aware Plugin
230+
231+
This example creates a plugin that reacts to context changes:
232+
233+
```ts
234+
import type { Caido } from "@caido/sdk-frontend";
235+
236+
export type CaidoSDK = Caido;
237+
238+
export const init = (sdk: CaidoSDK) => {
239+
sdk.window.onContextChange((context) => {
240+
if (context.page) {
241+
switch (context.page.kind) {
242+
case "Replay":
243+
sdk.log.info("User is on the Replay page");
244+
break;
245+
case "HTTPHistory":
246+
sdk.log.info("User is on the HTTP History page");
247+
break;
248+
case "Sitemap":
249+
sdk.log.info("User is on the Sitemap page");
250+
break;
251+
default:
252+
sdk.log.info(`User is on the ${context.page.kind} page`);
253+
}
254+
} else {
255+
sdk.log.info("User is not on a specific page");
256+
}
257+
});
258+
};
259+
```
260+
193261
## Interacting with Windows and Editors
194262

195263
Used to interact with text within the application environment, allowing text selection, replacement, read permission designations, focusing and editor related messaging.

src/guides/replay.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,46 @@ const handler = sdk.replay.onCurrentSessionChange((event) => {
133133
handler.stop();
134134
```
135135

136+
## Adding Indicators to Sessions
137+
138+
Indicators are visual badges displayed next to session names in the collections tree. They're useful for highlighting important sessions or showing status information.
139+
140+
### Adding a Session Indicator
141+
142+
```ts
143+
const indicator = sdk.replay.addSessionIndicator(sessionId, {
144+
icon: "fas fa-exclamation-triangle",
145+
description: "Security warning",
146+
});
147+
```
148+
149+
The `addSessionIndicator` method returns a handle object with a `remove` method to remove the indicator later:
150+
151+
```ts
152+
// Later, remove the indicator
153+
indicator.remove();
154+
```
155+
156+
### Indicator Options
157+
158+
- `icon` - Font Awesome icon class (e.g., `"fas fa-check"`, `"fas fa-warning"`)
159+
- `description` - Tooltip text shown on hover
160+
161+
## Adding Response View Modes
162+
163+
You can add custom response view modes to the Replay page:
164+
165+
```ts
166+
sdk.replay.addResponseViewMode({
167+
label: "My Custom Response View",
168+
view: {
169+
component: MyResponseComponent,
170+
},
171+
});
172+
```
173+
174+
For more information on creating response view modes, see the [Add View Modes](/guides/view_modes.md) guide.
175+
136176
::: info
137177
Sessions and collections are persisted across Caido restarts, so programmatically created items will remain available.
138178
:::

0 commit comments

Comments
 (0)