@capybara-hq/plugin-sdk 0.1.0-rc.57 → 0.1.0-rc.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,11 +60,12 @@ Rules that the schema cannot show:
60
60
  Besides schemes and `fonts`, it may set `logo` (`mark`, `wordmark`, `favicon`, `illustration`,
61
61
  `appIcon`, `appIconMaskable`), `decoration` (`dither` or `none`), `avatars` (at most 12 presets) and
62
62
  `hideAvatarPresets`; every file it names is checked and packed, and nothing else is served.
63
- - `setupGuides` (at most 8): `{ id, place, template? }`. Each guide is a Markdown document at
63
+ - `setupGuides` (at most 8): `{ id, place, templates? }`. Each guide is a Markdown document at
64
64
  `guides/<id>.md` (English, required) and `guides/<id>.zh.md` (Chinese, optional), shown where a
65
65
  person sets up what the plugin brings. `place` is `channel-connection` (New channel and the channel
66
66
  detail; the extension must provide `channel@1`; one per plugin), `connector-template`
67
- (`template` names one of the plugin's `connectors/<id>.json`; one per template) or
67
+ (`templates` names one or more of the plugin's `connectors/<id>.json`, so one guide may serve
68
+ several templates; a template has at most one guide) or
68
69
  `extension-deployment` (the super admin's page of the extension; its checks get the extension's
69
70
  platform deployment config and `orgId: null`, for credentials such as a push provider's key) or
70
71
  `device-connection` (how a member connects a machine through a device provider). See "Setup
@@ -80,8 +81,9 @@ A guide is CommonMark + GFM:
80
81
  - `{{name}}` variables come from the place, and none is ever a secret: everywhere `publicUrl`,
81
82
  `orgName`, `pluginName`, `pluginVersion`, `mode`; `channel-connection` adds `webhookUrl`,
82
83
  `signInCallbackUrl`, `connectionName`; `connector-template` adds `oauthCallbackUrl`,
83
- `signInCallbackUrl`, `templateId`, `templateName`, `connectorName`; `extension-deployment` adds
84
- none (no modes, admin audience only); `device-connection` has only `publicUrl`, `orgId`,
84
+ `signInCallbackUrl`, `templateId`, `templateName` (the template the guide is shown for),
85
+ `connectorName`; `extension-deployment` adds `signInCallbackUrl` (no modes, admin audience
86
+ only); `device-connection` has only `publicUrl`, `orgId`,
85
87
  `orgName`, `pluginName` (no modes, member audience only). In `yaml` / `json` code put a
86
88
  variable inside double quotes. Directive lines and fence info strings hold no variables.
87
89
  - Sections: a line `::: mode webhook` (modes `long_connection`, `webhook`; channel guides) or
@@ -37,6 +37,12 @@ export declare function isSandboxScopeDeniedError(e: unknown): e is SandboxScope
37
37
  * every scope check treats it as the definite pre-effect failure it is) that the operation path
38
38
  * records as `not_sent`, never as an unknown outcome. It says nothing about an earlier request of
39
39
  * the same operation, so a recovery tells it apart ({@link isDeviceRequestNotSent}).
40
+ *
41
+ * A provider throws it too when it finds the instance gone before contacting the machine (for
42
+ * example the machine's runtime changed since the instance was created), with a
43
+ * `SandboxGoneError` as its `cause`: nothing ran, and the kernel also rebuilds the instance so a
44
+ * retry of the call runs on the new one. A gone instance found after the request was sent is a
45
+ * bare `SandboxGoneError` (its outcome is unknown).
40
46
  */
41
47
  export declare class DeviceRequestNotSentError extends SandboxScopeDeniedError {
42
48
  readonly notSent: true;
@@ -57,6 +57,12 @@ export function isSandboxScopeDeniedError(e) {
57
57
  * every scope check treats it as the definite pre-effect failure it is) that the operation path
58
58
  * records as `not_sent`, never as an unknown outcome. It says nothing about an earlier request of
59
59
  * the same operation, so a recovery tells it apart ({@link isDeviceRequestNotSent}).
60
+ *
61
+ * A provider throws it too when it finds the instance gone before contacting the machine (for
62
+ * example the machine's runtime changed since the instance was created), with a
63
+ * `SandboxGoneError` as its `cause`: nothing ran, and the kernel also rebuilds the instance so a
64
+ * retry of the call runs on the new one. A gone instance found after the request was sent is a
65
+ * bare `SandboxGoneError` (its outcome is unknown).
60
66
  */
61
67
  export class DeviceRequestNotSentError extends SandboxScopeDeniedError {
62
68
  notSent = true;
@@ -32,7 +32,18 @@ export type DeviceFeature = "networkReport" | "projects";
32
32
  export interface DeviceLocalPolicySummary {
33
33
  /** The device's sandbox allowlist (the owner's `allowedDomains`). */
34
34
  allowedDomains: string[];
35
+ /**
36
+ * This connection's project directories that another connection on the same machine also uses,
37
+ * only those the owner listed explicitly for this connection (its `projectPaths`): a directory
38
+ * the deployment picked itself is never reported, shared or not (absolute paths,
39
+ * {@link validateSandboxPathShape}; at most {@link MAX_DEVICE_SHARED_PROJECT_ROOTS}). Never names
40
+ * the other connection. Absent from an older device; a malformed value is dropped by the parser
41
+ * (the rest of the summary is kept).
42
+ */
43
+ sharedProjectRoots?: string[];
35
44
  }
45
+ /** The most project directories a policy summary's `sharedProjectRoots` lists. */
46
+ export declare const MAX_DEVICE_SHARED_PROJECT_ROOTS = 256;
36
47
  /**
37
48
  * A directory a `scan` found that looks like a project (it holds `.git` or `AGENTS.md`): a
38
49
  * suggestion, not a project. `path` is absolute ({@link validateSandboxPathShape});
@@ -18,6 +18,8 @@ export const DEVICE_PROTOCOL_VERSION = 6;
18
18
  */
19
19
  export const DEVICE_DIAL_IN_PROTOCOL = `capybara-device/${DEVICE_PROTOCOL_VERSION}`;
20
20
  const DEVICE_FEATURES = ["networkReport", "projects"];
21
+ /** The most project directories a policy summary's `sharedProjectRoots` lists. */
22
+ export const MAX_DEVICE_SHARED_PROJECT_ROOTS = 256;
21
23
  /** The most blocked hosts an exec result reports; the parser cuts longer lists. */
22
24
  export const MAX_NETWORK_BLOCKED_HOSTS = 20;
23
25
  /** The most hosts an exec's `grants` may carry. */
@@ -204,7 +206,22 @@ function parseScanResult(v) {
204
206
  }
205
207
  function parsePolicySummary(v) {
206
208
  const o = obj(v, 'field "policy"');
207
- return { allowedDomains: strArray(o, "allowedDomains") };
209
+ const shared = sharedProjectRoots(o.sharedProjectRoots);
210
+ return {
211
+ allowedDomains: strArray(o, "allowedDomains"),
212
+ ...(shared !== undefined && { sharedProjectRoots: shared }),
213
+ };
214
+ }
215
+ /**
216
+ * A summary's `sharedProjectRoots`: at most {@link MAX_DEVICE_SHARED_PROJECT_ROOTS} absolute paths.
217
+ * Undefined when absent or malformed (an optional field: only it is dropped).
218
+ */
219
+ function sharedProjectRoots(v) {
220
+ if (!Array.isArray(v) || v.length > MAX_DEVICE_SHARED_PROJECT_ROOTS)
221
+ return undefined;
222
+ if (!v.every((p) => typeof p === "string" && validateSandboxPathShape(p).length === 0))
223
+ return undefined;
224
+ return [...v];
208
225
  }
209
226
  /** Optional hello fields: malformed values are ignored so old and new peers interoperate. */
210
227
  function optionalHelloFields(o) {
@@ -99,7 +99,10 @@ export interface ExecResult {
99
99
  * The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
100
100
  * `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
101
101
  * instance gone; the kernel then rebuilds the instance and retries once. A transient connection
102
- * failure throws a plain error.
102
+ * failure throws a plain error. In a managed operation (`operation()`), a gone instance found
103
+ * **before** the request reached the machine throws a `DeviceRequestNotSentError` with this error
104
+ * as its `cause`: the operation is then recorded as not started rather than as an unknown outcome,
105
+ * and the instance is still rebuilt, so the call can be retried on it.
103
106
  */
104
107
  export declare class SandboxGoneError extends Error {
105
108
  readonly sandboxGone: true;
@@ -27,7 +27,10 @@ export function rootsOf(h) {
27
27
  * The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
28
28
  * `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
29
29
  * instance gone; the kernel then rebuilds the instance and retries once. A transient connection
30
- * failure throws a plain error.
30
+ * failure throws a plain error. In a managed operation (`operation()`), a gone instance found
31
+ * **before** the request reached the machine throws a `DeviceRequestNotSentError` with this error
32
+ * as its `cause`: the operation is then recorded as not started rather than as an unknown outcome,
33
+ * and the instance is still rebuilt, so the call can be retried on it.
31
34
  */
32
35
  export class SandboxGoneError extends Error {
33
36
  sandboxGone = true;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.57";
1
+ export declare const SDK_VERSION = "0.1.0-rc.59";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.57";
1
+ export const SDK_VERSION = "0.1.0-rc.59";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
@@ -114,9 +114,12 @@ const setupGuide = z.strictObject({
114
114
  message: "id must match ^[a-z0-9][a-z0-9-]{0,63}$",
115
115
  }),
116
116
  place: z.enum(SETUP_GUIDE_PLACES),
117
- template: z
118
- .string()
119
- .regex(CATALOG_ITEM_NAME_RE, { message: "template must match ^[a-z0-9][a-z0-9-]{0,63}$" })
117
+ templates: z
118
+ .array(z.string().regex(CATALOG_ITEM_NAME_RE, {
119
+ message: "a template must match ^[a-z0-9][a-z0-9-]{0,63}$",
120
+ }))
121
+ .min(1)
122
+ .max(SETUP_GUIDE_LIMITS.templatesPerGuide)
120
123
  .optional(),
121
124
  });
122
125
  const clientSection = z
@@ -271,21 +274,23 @@ const schema = z
271
274
  issue(["setupGuides", i, "id"], `duplicate setup guide id ${g.id}`);
272
275
  guideIds.add(g.id);
273
276
  if (g.place === "connector-template") {
274
- if (g.template === undefined) {
275
- issue(["setupGuides", i, "template"], "template is required for a connector-template guide");
277
+ if (g.templates === undefined) {
278
+ issue(["setupGuides", i, "templates"], "templates is required for a connector-template guide");
276
279
  }
277
280
  else {
278
- if (m.connectorTemplates !== undefined && !ids.has(g.template)) {
279
- issue(["setupGuides", i, "template"], `template ${g.template} is not one of the plugin's connector templates`);
280
- }
281
- if (guideTemplates.has(g.template)) {
282
- issue(["setupGuides", i, "template"], `at most one setup guide per connector template (${g.template} has two)`);
283
- }
284
- guideTemplates.add(g.template);
281
+ g.templates.forEach((t, j) => {
282
+ if (m.connectorTemplates !== undefined && !ids.has(t)) {
283
+ issue(["setupGuides", i, "templates", j], `template ${t} is not one of the plugin's connector templates`);
284
+ }
285
+ if (guideTemplates.has(t)) {
286
+ issue(["setupGuides", i, "templates", j], `at most one setup guide per connector template (${t} is named twice)`);
287
+ }
288
+ guideTemplates.add(t);
289
+ });
285
290
  }
286
291
  }
287
- else if (g.template !== undefined) {
288
- issue(["setupGuides", i, "template"], "template is only for connector-template guides");
292
+ else if (g.templates !== undefined) {
293
+ issue(["setupGuides", i, "templates"], "templates is only for connector-template guides");
289
294
  }
290
295
  if (g.place === "channel-connection") {
291
296
  channelGuides++;
@@ -37,6 +37,8 @@ export declare const SETUP_GUIDE_PLACE_INFO: Readonly<Record<SetupGuidePlace, Se
37
37
  export declare const SETUP_GUIDE_LIMITS: {
38
38
  /** Guides per plugin. */
39
39
  readonly guides: 8;
40
+ /** Connector templates one `connector-template` guide covers. */
41
+ readonly templatesPerGuide: 64;
40
42
  /** Bytes per document (each language). */
41
43
  readonly docBytes: 65536;
42
44
  /** Fenced code blocks per document. */
@@ -61,8 +63,13 @@ export interface PluginSetupGuide {
61
63
  /** `^[a-z0-9][a-z0-9-]{0,63}$`, unique in the plugin; the documents are `guides/<id>.md`. */
62
64
  id: string;
63
65
  place: SetupGuidePlace;
64
- /** Only and required for `connector-template`: one of the plugin's connector template ids. */
65
- template?: string;
66
+ /**
67
+ * Only and required for `connector-template`: the plugin's connector template ids the guide is
68
+ * for (one or more, at most {@link SETUP_GUIDE_LIMITS}`.templatesPerGuide`). A template has at
69
+ * most one guide; `{{templateId}}` / `{{templateName}}` render the template the guide is shown
70
+ * for.
71
+ */
72
+ templates?: string[];
66
73
  }
67
74
  /** The package path of a guide's document: `guides/<id>.md` (en) or `guides/<id>.zh.md` (zh). */
68
75
  export declare function setupGuideDocPath(id: string, locale: "en" | "zh"): string;
@@ -62,7 +62,7 @@ export const SETUP_GUIDE_PLACE_INFO = {
62
62
  "extension-deployment": {
63
63
  modes: [],
64
64
  audiences: ["admin"],
65
- variables: { ...COMMON_VARIABLES, pluginName: "text" },
65
+ variables: { ...COMMON_VARIABLES, pluginName: "text", signInCallbackUrl: "url" },
66
66
  drift: false,
67
67
  shellActions: [],
68
68
  },
@@ -78,6 +78,8 @@ export const SETUP_GUIDE_PLACE_INFO = {
78
78
  export const SETUP_GUIDE_LIMITS = {
79
79
  /** Guides per plugin. */
80
80
  guides: 8,
81
+ /** Connector templates one `connector-template` guide covers. */
82
+ templatesPerGuide: 64,
81
83
  /** Bytes per document (each language). */
82
84
  docBytes: 65536,
83
85
  /** Fenced code blocks per document. */
package/dist/tool.d.ts CHANGED
@@ -146,12 +146,42 @@ export interface InputRequired {
146
146
  state?: unknown;
147
147
  }
148
148
  export type FormAnswer = Record<string, string | number | boolean | string[]>;
149
+ /**
150
+ * What a tool handler gets with each invocation.
151
+ *
152
+ * **Side effects and idempotency.** The kernel runs a call's effect at most once: it records
153
+ * that the call started before invoking the handler, and when a run dies after that and before
154
+ * the result is recorded, the result is written as unknown (an error result the model sees:
155
+ * `Result unknown: the call was interrupted before a result was recorded. Verify the outcome
156
+ * before retrying.`) and **the handler is never called again** for that call. The model, or a
157
+ * person, may then decide to call the tool again: that is a new call with a new `callId`.
158
+ *
159
+ * One logical call may still invoke the handler more than once: each `InputRequired` round
160
+ * resumes it with `resume`. `callId` and `idempotencyKey` stay the same across those
161
+ * invocations. A tool with an external side effect passes `idempotencyKey` downstream (for
162
+ * example as an `Idempotency-Key` header, or stored with the record it creates) so the effect
163
+ * applies once per logical call and an unknown outcome can be checked against the external
164
+ * system before retrying.
165
+ */
149
166
  export interface ToolCallContext {
150
167
  orgId: string;
151
168
  accountId: string;
152
169
  agentId: string;
153
170
  conversationId: string;
171
+ /**
172
+ * The model's id for this call. Stable across every invocation of one logical call (the
173
+ * `InputRequired` rounds), but unique only within its run: two runs of one conversation may
174
+ * reuse an id, so `conversationId` + `callId` is not a key. Use `idempotencyKey`.
175
+ */
154
176
  callId: string;
177
+ /**
178
+ * The key of this logical call for idempotent side effects: 64 lowercase hex characters derived
179
+ * from the conversation, the run and `callId`. The same for every invocation of the call
180
+ * (each `InputRequired` round), different for every other call, including a later call the
181
+ * model makes to retry it. Optional in the type so older extensions compile; the kernel always
182
+ * passes it.
183
+ */
184
+ idempotencyKey?: string;
155
185
  signal: AbortSignal;
156
186
  /** null = the user cancelled or it timed out. */
157
187
  resume?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.57",
3
+ "version": "0.1.0-rc.59",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -229,9 +229,14 @@
229
229
  "device-connection"
230
230
  ]
231
231
  },
232
- "template": {
233
- "type": "string",
234
- "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
232
+ "templates": {
233
+ "minItems": 1,
234
+ "maxItems": 64,
235
+ "type": "array",
236
+ "items": {
237
+ "type": "string",
238
+ "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
239
+ }
235
240
  }
236
241
  },
237
242
  "required": [