@capybara-hq/plugin-sdk 0.1.0-rc.2 → 0.1.0-rc.20

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.
Files changed (104) hide show
  1. package/README.md +1 -1
  2. package/agent-docs/agent-templates.md +59 -0
  3. package/agent-docs/concepts.md +63 -0
  4. package/agent-docs/connector-templates.md +48 -0
  5. package/agent-docs/extension-points/channel.md +15 -0
  6. package/agent-docs/extension-points/config-source.md +15 -0
  7. package/agent-docs/extension-points/connector.md +15 -0
  8. package/agent-docs/extension-points/context.md +15 -0
  9. package/agent-docs/extension-points/counter.md +15 -0
  10. package/agent-docs/extension-points/directory.md +15 -0
  11. package/agent-docs/extension-points/file-preview.md +15 -0
  12. package/agent-docs/extension-points/identity-source.md +15 -0
  13. package/agent-docs/extension-points/model-provider.md +15 -0
  14. package/agent-docs/extension-points/object-store.md +15 -0
  15. package/agent-docs/extension-points/sandbox.md +15 -0
  16. package/agent-docs/extension-points/secret-store.md +15 -0
  17. package/agent-docs/extension-points/web-fetch.md +15 -0
  18. package/agent-docs/extension-points/web-search.md +15 -0
  19. package/agent-docs/extensions.md +88 -0
  20. package/agent-docs/plugin-format.md +100 -0
  21. package/agent-docs/setup.md +46 -0
  22. package/agent-docs/skills.md +44 -0
  23. package/agent-docs/tool-naming.md +21 -0
  24. package/dist/agent-template.d.ts +96 -2
  25. package/dist/agent-template.js +381 -3
  26. package/dist/bootstrap.d.ts +15 -1
  27. package/dist/bootstrap.js +17 -1
  28. package/dist/cards.d.ts +39 -5
  29. package/dist/cards.js +70 -11
  30. package/dist/channel.d.ts +20 -1
  31. package/dist/client-css.d.ts +36 -0
  32. package/dist/client-css.js +326 -0
  33. package/dist/client-section.d.ts +35 -0
  34. package/dist/client-section.js +133 -0
  35. package/dist/config-ui.d.ts +24 -1
  36. package/dist/config-ui.js +89 -11
  37. package/dist/connector-auth.d.ts +2 -0
  38. package/dist/connector-auth.js +15 -0
  39. package/dist/context.d.ts +40 -0
  40. package/dist/context.js +2 -0
  41. package/dist/ctx.d.ts +86 -4
  42. package/dist/define-extension.d.ts +5 -1
  43. package/dist/define-extension.js +1 -0
  44. package/dist/dev-hosts.d.ts +6 -0
  45. package/dist/dev-hosts.js +48 -0
  46. package/dist/device-protocol.d.ts +260 -0
  47. package/dist/device-protocol.js +496 -0
  48. package/dist/directory.d.ts +11 -2
  49. package/dist/extension-point.d.ts +6 -0
  50. package/dist/extension-point.js +19 -14
  51. package/dist/file-preview.d.ts +9 -1
  52. package/dist/hooks.d.ts +111 -15
  53. package/dist/hooks.js +5 -0
  54. package/dist/index.d.ts +18 -1
  55. package/dist/index.js +18 -1
  56. package/dist/marketplace.d.ts +55 -2
  57. package/dist/marketplace.js +73 -3
  58. package/dist/model.d.ts +60 -2
  59. package/dist/model.js +22 -0
  60. package/dist/org-access.d.ts +27 -0
  61. package/dist/org-access.js +35 -0
  62. package/dist/permissions.d.ts +33 -8
  63. package/dist/permissions.js +89 -22
  64. package/dist/plugin-manifest.d.ts +60 -7
  65. package/dist/plugin-manifest.js +178 -7
  66. package/dist/sandbox.d.ts +239 -62
  67. package/dist/sandbox.js +99 -14
  68. package/dist/setup-check.d.ts +115 -0
  69. package/dist/setup-check.js +142 -0
  70. package/dist/setup-guide-parse.d.ts +121 -0
  71. package/dist/setup-guide-parse.js +350 -0
  72. package/dist/setup-guide-render.d.ts +45 -0
  73. package/dist/setup-guide-render.js +351 -0
  74. package/dist/setup-guide.d.ts +94 -0
  75. package/dist/setup-guide.js +336 -0
  76. package/dist/skill-invocation.d.ts +9 -5
  77. package/dist/skill-invocation.js +18 -8
  78. package/dist/skill.d.ts +23 -3
  79. package/dist/skill.js +31 -6
  80. package/dist/theme-assets.d.ts +39 -0
  81. package/dist/theme-assets.js +449 -0
  82. package/dist/theme-readability.d.ts +37 -0
  83. package/dist/theme-readability.js +145 -0
  84. package/dist/theme-tokens.generated.d.ts +275 -0
  85. package/dist/theme-tokens.generated.js +172 -0
  86. package/dist/theme.d.ts +152 -0
  87. package/dist/theme.js +392 -0
  88. package/dist/tool.d.ts +26 -3
  89. package/dist/tool.js +8 -0
  90. package/dist/ui-parts.d.ts +23 -0
  91. package/dist/ui-parts.js +337 -0
  92. package/dist/ui-resolve.d.ts +40 -0
  93. package/dist/ui-resolve.js +54 -0
  94. package/dist/ui-slots.d.ts +55 -0
  95. package/dist/ui-slots.js +247 -0
  96. package/dist/ui.d.ts +143 -37
  97. package/dist/ui.js +65 -5
  98. package/dist/web.d.ts +30 -5
  99. package/package.json +10 -2
  100. package/schemas/bootstrap.v1.schema.json +6 -0
  101. package/schemas/connector-template.v1.schema.json +3 -0
  102. package/schemas/marketplace.v1.schema.json +50 -0
  103. package/schemas/plugin.v1.schema.json +144 -7
  104. package/schemas/theme.v1.schema.json +225 -0
package/dist/hooks.d.ts CHANGED
@@ -4,7 +4,9 @@ import type { ContentBlock, ModelRequest, ModelUsage } from "./model.js";
4
4
  * `HOOK_MOUNT_POINTS` (`session.*`, `agent.preStep`) stay reserved: they validate in a manifest but
5
5
  * cannot be registered yet.
6
6
  */
7
- export declare const HOOKS_AVAILABLE: readonly ["model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report"];
7
+ export declare const HOOKS_AVAILABLE: readonly ["model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report", "org.member_removed", "agent.deleted", "org.deleted"];
8
+ /** Lifecycle mount points: observe-only notices that something was removed. */
9
+ export declare const LIFECYCLE_HOOKS: readonly ["org.member_removed", "agent.deleted", "org.deleted"];
8
10
  /** A mount point that `ctx.hooks.on` accepts. */
9
11
  export type AvailableHook = (typeof HOOKS_AVAILABLE)[number];
10
12
  /** Where a sub-agent was dispatched from: the parent conversation, its run and the `Agent` call. */
@@ -39,8 +41,12 @@ export interface HookScope {
39
41
  * `WebFetch` tool.
40
42
  */
41
43
  export type ModelCallPurpose = "step" | "compaction" | "title" | "web_fetch";
42
- /** What a reported model call was for (the same values as {@link ModelCallPurpose}). */
43
- export type UsagePurpose = ModelCallPurpose;
44
+ /**
45
+ * What a reported or requested model call was for: the {@link ModelCallPurpose} values, or
46
+ * `embedding` for an embedding call an extension made through `ctx.models` (`usage.report`, and
47
+ * `model.request` with {@link EmbeddingRequestHookPayload}; never `model.response`).
48
+ */
49
+ export type UsagePurpose = ModelCallPurpose | "embedding";
44
50
  /**
45
51
  * An image or document of a `model.request` payload. Hook payloads never carry media bytes or
46
52
  * attachment ids: each image or document block is replaced by this placeholder.
@@ -74,14 +80,15 @@ export type HookModelRequest = Omit<ModelRequest, "messages"> & {
74
80
  messages: HookModelMessage[];
75
81
  };
76
82
  /**
77
- * `model.request`: before a model call is sent. A policy hook may deny it. Fires once per attempt of a
78
- * step (`purpose: "step"`), once for each compaction call (`purpose: "compaction"`, `attempt` 1) and
83
+ * `model.request` of a chat model call (see {@link ModelRequestHookPayload}): once per attempt of a
84
+ * step (`purpose: "step"`), once for each compaction call (`purpose: "compaction"`, `attempt` 1),
79
85
  * once for each conversation title call (`purpose: "title"`, `runId` "", `step` 0, `attempt` 1; a
80
- * denial skips the title and is recorded only in the audit log).
86
+ * denial skips the title and is recorded only in the audit log) and once for each `WebFetch`
87
+ * extraction call (`purpose: "web_fetch"`).
81
88
  * `request` is the request as sent, except that images and documents are placeholders
82
89
  * ({@link HookMediaPlaceholder}): no media bytes, no attachment ids.
83
90
  */
84
- export interface ModelRequestHookPayload extends HookScope {
91
+ export interface ModelCallRequestHookPayload extends HookScope {
85
92
  purpose: ModelCallPurpose;
86
93
  step: number;
87
94
  attempt: number;
@@ -89,6 +96,45 @@ export interface ModelRequestHookPayload extends HookScope {
89
96
  model: string;
90
97
  request: Readonly<HookModelRequest>;
91
98
  }
99
+ /**
100
+ * `model.request` of an embedding call an extension made through `ctx.models.embed`
101
+ * (`purpose: "embedding"`): fired once per `embed` call, before the first batch is sent, with every
102
+ * text of the call (the kernel splits them into batches afterwards). A call with no input sends
103
+ * nothing and fires nothing. There is no conversation: the conversation fields of a chat model call
104
+ * (`accountId`, `agentId`, `agentVersion`, `conversationId`, `runId`, `parent`, `step`, `attempt`,
105
+ * `request`) are absent. A policy denial makes `embed` reject (`model.hook_denied`); nothing is sent
106
+ * to the provider and no usage is recorded.
107
+ */
108
+ export interface EmbeddingRequestHookPayload {
109
+ purpose: "embedding";
110
+ orgId: string;
111
+ /** The extension that called `ctx.models.embed`. */
112
+ extension: string;
113
+ /** The embedding purpose the extension called with (one it declared in `permissions.models`). */
114
+ embeddingPurpose: string;
115
+ provider: string;
116
+ model: string;
117
+ /** The texts of the call, in order (text only). */
118
+ input: readonly string[];
119
+ /** The dimensions the extension asked for, when it asked. */
120
+ dimensions?: number;
121
+ /** The input type the extension gave, when it gave one. */
122
+ inputType?: "query" | "document";
123
+ accountId?: undefined;
124
+ agentId?: undefined;
125
+ agentVersion?: undefined;
126
+ conversationId?: undefined;
127
+ runId?: undefined;
128
+ parent?: undefined;
129
+ }
130
+ /**
131
+ * `model.request`: before a model call is sent. A policy hook may deny it. Either a chat model call
132
+ * ({@link ModelCallRequestHookPayload}: steps, compaction, titles, `WebFetch`) or an extension's
133
+ * embedding call ({@link EmbeddingRequestHookPayload}, `purpose: "embedding"`); tell them apart by
134
+ * `purpose`. Handlers must accept the absent conversation fields of an embedding call (a policy
135
+ * hook that throws on one denies the call). Payloads carry no media bytes.
136
+ */
137
+ export type ModelRequestHookPayload = ModelCallRequestHookPayload | EmbeddingRequestHookPayload;
92
138
  /**
93
139
  * `model.response`: after a sent model call finished or failed, with its usage when known (step
94
140
  * attempts, compaction and title calls, see `purpose`). Not fired for a call the user aborted (the run was
@@ -138,12 +184,18 @@ export interface UsageReportPayload {
138
184
  */
139
185
  purpose: UsagePurpose;
140
186
  orgId: string;
141
- accountId: string;
142
- agentId: string;
143
- conversationId: string;
144
- /** A sub-agent's calls report `chat`; `parent` tells them apart. */
145
- conversationKind: "chat" | "eval";
146
- runId: string;
187
+ /** Absent for `embedding`. */
188
+ accountId?: string;
189
+ /** Absent for `embedding`. */
190
+ agentId?: string;
191
+ /** Absent for `embedding`. */
192
+ conversationId?: string;
193
+ /** A sub-agent's calls report `chat`; `parent` tells them apart. Absent for `embedding`. */
194
+ conversationKind?: "chat" | "eval";
195
+ /** Absent for `embedding`. */
196
+ runId?: string;
197
+ /** The calling extension; set for `embedding`. */
198
+ extension?: string;
147
199
  /** Set when the call belongs to a sub-agent: where it was dispatched from. */
148
200
  parent?: HookParentScope;
149
201
  provider: string;
@@ -151,6 +203,34 @@ export interface UsageReportPayload {
151
203
  usage: ModelUsage;
152
204
  occurredAt: string;
153
205
  }
206
+ /**
207
+ * `org.member_removed`: an account left the org (offboarding: removed by an admin, left on its own,
208
+ * or offboarded by a directory sync). Lifecycle hooks are delivered durably, after the removal
209
+ * committed, through a queue, at least once per plugin that declares the mount in
210
+ * `permissions.hooks`, whether or not the org has the plugin enabled and whether or not the org's
211
+ * effective config of the plugin is valid (`call.config` is the platform deployment config): they
212
+ * exist so a plugin can delete the data it holds. Handlers must be idempotent. The payload carries
213
+ * ids only.
214
+ */
215
+ export interface OrgMemberRemovedPayload {
216
+ orgId: string;
217
+ accountId: string;
218
+ }
219
+ /**
220
+ * `agent.deleted`: an agent was deleted. Delivered like {@link OrgMemberRemovedPayload} (durably, at
221
+ * least once, regardless of org enablement or config validity; ids only).
222
+ */
223
+ export interface AgentDeletedPayload {
224
+ orgId: string;
225
+ agentId: string;
226
+ }
227
+ /**
228
+ * `org.deleted`: an org was deleted. Delivered like {@link OrgMemberRemovedPayload} (durably, at
229
+ * least once, regardless of org enablement or config validity; ids only).
230
+ */
231
+ export interface OrgDeletedPayload {
232
+ orgId: string;
233
+ }
154
234
  /** Payload type of each mount point. */
155
235
  export interface HookPayloads {
156
236
  "model.request": ModelRequestHookPayload;
@@ -158,6 +238,9 @@ export interface HookPayloads {
158
238
  "tool.preExecute": ToolPreHookPayload;
159
239
  "tool.postExecute": ToolPostHookPayload;
160
240
  "usage.report": UsageReportPayload;
241
+ "org.member_removed": OrgMemberRemovedPayload;
242
+ "agent.deleted": AgentDeletedPayload;
243
+ "org.deleted": OrgDeletedPayload;
161
244
  }
162
245
  /**
163
246
  * What a hook returns: nothing, or `{ deny: reason }`. A deny only takes effect for a `policy` hook
@@ -169,9 +252,22 @@ export type HookVerdict = void | {
169
252
  };
170
253
  /**
171
254
  * A hook handler. The payload is a deep-frozen copy (mutating it throws). `signal` aborts when the
172
- * hook runs past `hooks.timeoutMs` or the call it observes is aborted.
255
+ * hook runs past `hooks.timeoutMs` or the call it observes is aborted. `call.config` is the
256
+ * extension's effective deployment config for the payload's org (the platform's config with the
257
+ * org's copy applied to the overridable fields, or `ctx.config` while the org follows it); the
258
+ * kernel always passes it, and never calls a hook for an org where that config is not valid
259
+ * (observe hooks are skipped, policy hooks deny). Lifecycle hooks ({@link LIFECYCLE_HOOKS}) are the
260
+ * exception: they get the platform deployment config and are always called.
173
261
  */
174
- export type HookHandler<K extends AvailableHook> = (payload: HookPayloads[K], signal: AbortSignal) => Promise<HookVerdict> | HookVerdict;
262
+ export type HookHandler<K extends AvailableHook> = (payload: HookPayloads[K], signal: AbortSignal, call?: HookCall) => Promise<HookVerdict> | HookVerdict;
263
+ /** The per-call context of a hook handler (see {@link HookHandler}). */
264
+ export interface HookCall {
265
+ /**
266
+ * The extension's effective deployment config for the payload's org (lifecycle hooks: the
267
+ * platform deployment config).
268
+ */
269
+ config: unknown;
270
+ }
175
271
  /**
176
272
  * - `policy` (only on {@link POLICY_HOOKS}): policy hooks run serially by plugin name (registration
177
273
  * order within a plugin) before the call; the first `{ deny }`, error or timeout blocks the call and
package/dist/hooks.js CHANGED
@@ -9,6 +9,11 @@ export const HOOKS_AVAILABLE = [
9
9
  "tool.preExecute",
10
10
  "tool.postExecute",
11
11
  "usage.report",
12
+ "org.member_removed",
13
+ "agent.deleted",
14
+ "org.deleted",
12
15
  ];
16
+ /** Lifecycle mount points: observe-only notices that something was removed. */
17
+ export const LIFECYCLE_HOOKS = ["org.member_removed", "agent.deleted", "org.deleted"];
13
18
  /** Mount points where a `policy` hook may deny the call. */
14
19
  export const POLICY_HOOKS = ["model.request", "tool.preExecute"];
package/dist/index.d.ts CHANGED
@@ -1,13 +1,18 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.2";
1
+ export declare const SDK_VERSION = "0.1.0-rc.20";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
5
5
  export * from "./channel.js";
6
+ export * from "./client-css.js";
7
+ export * from "./client-section.js";
6
8
  export * from "./config-ui.js";
7
9
  export * from "./connector.js";
8
10
  export * from "./connector-auth.js";
11
+ export * from "./context.js";
9
12
  export * from "./ctx.js";
10
13
  export * from "./define-extension.js";
14
+ export * from "./dev-hosts.js";
15
+ export * from "./device-protocol.js";
11
16
  export * from "./directory.js";
12
17
  export * from "./extension-point.js";
13
18
  export * from "./file-preview.js";
@@ -16,15 +21,27 @@ export * from "./identity.js";
16
21
  export * from "./marketplace.js";
17
22
  export * from "./model.js";
18
23
  export * from "./model-params.js";
24
+ export * from "./org-access.js";
19
25
  export * from "./permissions.js";
20
26
  export * from "./plugin-manifest.js";
21
27
  export * from "./plugin-package.js";
22
28
  export * from "./sandbox.js";
23
29
  export * from "./secret.js";
30
+ export * from "./setup-check.js";
31
+ export * from "./setup-guide.js";
32
+ export { type ParsedSetupGuide, parseSetupGuide, type SetupGuideCheckLine, type SetupGuideCodeBlock, type SetupGuideParseIssue, type SetupGuideSection, } from "./setup-guide-parse.js";
33
+ export * from "./setup-guide-render.js";
24
34
  export * from "./skill.js";
25
35
  export * from "./skill-invocation.js";
26
36
  export * from "./storage.js";
37
+ export * from "./theme.js";
38
+ export * from "./theme-assets.js";
39
+ export * from "./theme-readability.js";
40
+ export * from "./theme-tokens.generated.js";
27
41
  export * from "./tool.js";
28
42
  export * from "./tool-key.js";
29
43
  export * from "./ui.js";
44
+ export * from "./ui-parts.js";
45
+ export * from "./ui-resolve.js";
46
+ export * from "./ui-slots.js";
30
47
  export * from "./web.js";
package/dist/index.js CHANGED
@@ -1,13 +1,18 @@
1
- export const SDK_VERSION = "0.1.0-rc.2";
1
+ export const SDK_VERSION = "0.1.0-rc.20";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
5
5
  export * from "./channel.js";
6
+ export * from "./client-css.js";
7
+ export * from "./client-section.js";
6
8
  export * from "./config-ui.js";
7
9
  export * from "./connector.js";
8
10
  export * from "./connector-auth.js";
11
+ export * from "./context.js";
9
12
  export * from "./ctx.js";
10
13
  export * from "./define-extension.js";
14
+ export * from "./dev-hosts.js";
15
+ export * from "./device-protocol.js";
11
16
  export * from "./directory.js";
12
17
  export * from "./extension-point.js";
13
18
  export * from "./file-preview.js";
@@ -16,15 +21,27 @@ export * from "./identity.js";
16
21
  export * from "./marketplace.js";
17
22
  export * from "./model.js";
18
23
  export * from "./model-params.js";
24
+ export * from "./org-access.js";
19
25
  export * from "./permissions.js";
20
26
  export * from "./plugin-manifest.js";
21
27
  export * from "./plugin-package.js";
22
28
  export * from "./sandbox.js";
23
29
  export * from "./secret.js";
30
+ export * from "./setup-check.js";
31
+ export * from "./setup-guide.js";
32
+ export { parseSetupGuide, } from "./setup-guide-parse.js";
33
+ export * from "./setup-guide-render.js";
24
34
  export * from "./skill.js";
25
35
  export * from "./skill-invocation.js";
26
36
  export * from "./storage.js";
37
+ export * from "./theme.js";
38
+ export * from "./theme-assets.js";
39
+ export * from "./theme-readability.js";
40
+ export * from "./theme-tokens.generated.js";
27
41
  export * from "./tool.js";
28
42
  export * from "./tool-key.js";
29
43
  export * from "./ui.js";
44
+ export * from "./ui-parts.js";
45
+ export * from "./ui-resolve.js";
46
+ export * from "./ui-slots.js";
30
47
  export * from "./web.js";
@@ -1,8 +1,10 @@
1
1
  import { z } from "zod";
2
2
  /**
3
3
  * The marketplace manifest `marketplace.json` (package ecosystem spec §5.2): a list of plugins,
4
- * each with one source. One entry is one version: a marketplace that offers several versions lists
5
- * the plugin once per version, so `(name, marketplaceEntryVersion)` is unique in a manifest.
4
+ * each with one source. One entry is one version. `capybara-plugin marketplace --write` lists one
5
+ * entry per plugin, its current version (plugin component management spec §13.2); readers still
6
+ * accept several versions of a plugin (marketplaces written in the older form), so
7
+ * `(name, marketplaceEntryVersion)` is unique in a manifest.
6
8
  *
7
9
  * Sources: a same-repo `path`, a `git` repo, an `npm` package (exact version + sha512, downloads
8
10
  * are verified against it, never npm metadata) or an `archive` URL (sha512 or sha256 SRI).
@@ -19,9 +21,15 @@ export declare const MARKETPLACE_MANIFEST_SCHEMA_VERSION = 1;
19
21
  export declare const MARKETPLACE_LIMITS: {
20
22
  readonly nameChars: 100;
21
23
  readonly summaryChars: 280;
24
+ /** Characters of each `displayName` language (as `plugin.json`'s). */
25
+ readonly displayNameChars: 100;
26
+ /** Characters of a `deprecated.reason`. */
27
+ readonly deprecationReasonChars: 280;
22
28
  readonly plugins: 5000;
23
29
  readonly permissionKeys: 500;
24
30
  readonly urlChars: 2000;
31
+ /** Bytes of an entry icon (the plugin icon limit, {@link CONNECTOR_TEMPLATE_LIMITS}). */
32
+ readonly iconBytes: number;
25
33
  };
26
34
  /** Where a marketplace entry's plugin comes from. */
27
35
  export type MarketplaceSource = {
@@ -53,6 +61,11 @@ export interface MarketplaceEntry {
53
61
  en: string;
54
62
  zh?: string;
55
63
  };
64
+ /** Display name (the plugin's `plugin.json` `displayName`); lists show it, else the name. */
65
+ displayName?: {
66
+ zh: string;
67
+ en: string;
68
+ };
56
69
  /** Exact semver; defaults to the npm source's version, otherwise the plugin's own. */
57
70
  version?: string;
58
71
  /** Exact semver. */
@@ -64,6 +77,27 @@ export interface MarketplaceEntry {
64
77
  };
65
78
  /** https URL. */
66
79
  homepage?: string;
80
+ /**
81
+ * The plugin's icon for marketplace lists, before the plugin is imported (display only; an
82
+ * imported plugin shows its own icon). Either an absolute `https://` URL whose path ends in
83
+ * `.svg` / `.png`, or `./<path>.svg|png` inside the marketplace's repository, read at the commit
84
+ * the marketplace was refreshed at (git marketplaces only; ignored in a marketplace fetched over
85
+ * http). The kernel downloads it on refresh (network rules of the marketplace downloads, never
86
+ * with the marketplace token), keeps it when it really is an svg / png of at most
87
+ * {@link MARKETPLACE_LIMITS}`.iconBytes`, and treats a URL's content as fixed: a new icon needs a
88
+ * new URL. A missing or invalid icon never fails the refresh. `capybara-plugin marketplace
89
+ * --write` fills it with the repository path of the plugin's `plugin.json` `icon`.
90
+ */
91
+ icon?: string;
92
+ /**
93
+ * This version is deprecated (`true`, or with a reason shown to admins): browsing lists it under
94
+ * the plugin's other versions, never as the one to import, and the kernel refuses importing it
95
+ * (`marketplace.entry_deprecated`). Set by hand on the entry by the marketplace maintainer;
96
+ * `capybara-plugin marketplace --write` keeps it. `false` is the same as absent.
97
+ */
98
+ deprecated?: boolean | {
99
+ reason?: string;
100
+ };
67
101
  source: MarketplaceSource;
68
102
  }
69
103
  /** `marketplace.json`. */
@@ -83,6 +117,8 @@ export interface MarketplaceParseOptions {
83
117
  /** Tests only: allow http on loopback addresses for `git` / `archive` URLs. */
84
118
  allowInsecureLoopback?: boolean;
85
119
  }
120
+ /** An entry icon's file extension (of the URL's path, or of the repository path). */
121
+ export declare const MARKETPLACE_ICON_RE: RegExp;
86
122
  /**
87
123
  * The zod schema of `marketplace.json` (https only; non-strict: unknown fields dropped). The JSON
88
124
  * Schema is generated with `z.toJSONSchema(MarketplaceManifestSchema, { io: "input" })`.
@@ -97,3 +133,20 @@ export declare function parseMarketplaceManifest(json: unknown, opts?: Marketpla
97
133
  };
98
134
  /** The entry's version: `version`, else the npm source's version, else `null` (the plugin's own). */
99
135
  export declare function marketplaceEntryVersion(e: MarketplaceEntry): string | null;
136
+ /**
137
+ * The entry's icon (see {@link MarketplaceEntry.icon}): `{ url }` for an absolute URL, `{ path }`
138
+ * (normalized, without the leading `./`) for a path inside the marketplace's repository, `null`
139
+ * without one.
140
+ */
141
+ export declare function marketplaceEntryIcon(e: Pick<MarketplaceEntry, "icon">): {
142
+ url: string;
143
+ } | {
144
+ path: string;
145
+ } | null;
146
+ /**
147
+ * The entry's deprecation (see {@link MarketplaceEntry.deprecated}): `null` when it is not
148
+ * deprecated (absent or `false`), else its reason (`null` without one).
149
+ */
150
+ export declare function marketplaceEntryDeprecation(e: MarketplaceEntry): {
151
+ reason: string | null;
152
+ } | null;
@@ -1,9 +1,11 @@
1
1
  import { z } from "zod";
2
- import { CATALOG_ITEM_NAME_RE, isSafePackagePath, NPM_PACKAGE_NAME_RE, SEMVER_VERSION_RE, SHA512_INTEGRITY_RE, } from "./plugin-package.js";
2
+ import { CATALOG_ITEM_NAME_RE, CONNECTOR_TEMPLATE_LIMITS, isSafePackagePath, NPM_PACKAGE_NAME_RE, SEMVER_VERSION_RE, SHA512_INTEGRITY_RE, } from "./plugin-package.js";
3
3
  /**
4
4
  * The marketplace manifest `marketplace.json` (package ecosystem spec §5.2): a list of plugins,
5
- * each with one source. One entry is one version: a marketplace that offers several versions lists
6
- * the plugin once per version, so `(name, marketplaceEntryVersion)` is unique in a manifest.
5
+ * each with one source. One entry is one version. `capybara-plugin marketplace --write` lists one
6
+ * entry per plugin, its current version (plugin component management spec §13.2); readers still
7
+ * accept several versions of a plugin (marketplaces written in the older form), so
8
+ * `(name, marketplaceEntryVersion)` is unique in a manifest.
7
9
  *
8
10
  * Sources: a same-repo `path`, a `git` repo, an `npm` package (exact version + sha512, downloads
9
11
  * are verified against it, never npm metadata) or an `archive` URL (sha512 or sha256 SRI).
@@ -20,9 +22,15 @@ export const MARKETPLACE_MANIFEST_SCHEMA_VERSION = 1;
20
22
  export const MARKETPLACE_LIMITS = {
21
23
  nameChars: 100,
22
24
  summaryChars: 280,
25
+ /** Characters of each `displayName` language (as `plugin.json`'s). */
26
+ displayNameChars: 100,
27
+ /** Characters of a `deprecated.reason`. */
28
+ deprecationReasonChars: 280,
23
29
  plugins: 5000,
24
30
  permissionKeys: 500,
25
31
  urlChars: 2000,
32
+ /** Bytes of an entry icon (the plugin icon limit, {@link CONNECTOR_TEMPLATE_LIMITS}). */
33
+ iconBytes: CONNECTOR_TEMPLATE_LIMITS.iconBytes,
26
34
  };
27
35
  const M = MARKETPLACE_LIMITS;
28
36
  const MAX_ERRORS = 50;
@@ -31,6 +39,13 @@ const PERMISSION_KEY_RE = /^[a-z][a-z.]{0,62}(?::[^\r\n]{1,256})?$/;
31
39
  const SHA256_INTEGRITY_RE = /^sha256-[A-Za-z0-9+/]{43}=$/;
32
40
  const COMMIT_RE = /^[0-9a-f]{40}$/;
33
41
  const HTTPS_URL_RE = /^https:\/\/\S+$/;
42
+ /** An entry icon's file extension (of the URL's path, or of the repository path). */
43
+ export const MARKETPLACE_ICON_RE = /\.(?:svg|png)$/i;
44
+ // Spelled without the `i` flag so the generated JSON Schema keeps the rule
45
+ const ICON_EXT = "\\.(?:[sS][vV][gG]|[pP][nN][gG])";
46
+ const ICON_URL_RE = new RegExp(`^https://[^\\s?#]+${ICON_EXT}(?:\\?[^\\s#]*)?$`);
47
+ const ICON_URL_OR_LOOPBACK_RE = new RegExp(`^(?:https://[^\\s?#]+|http://(?:127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|localhost|\\[::1\\])(?::\\d{1,5})?/[^\\s?#]*)${ICON_EXT}(?:\\?[^\\s#]*)?$`);
48
+ const ICON_PATH_RE = new RegExp(`^\\./[^\\s?#]+${ICON_EXT}$`);
34
49
  const HTTPS_OR_LOOPBACK_RE = /^(?:https:\/\/\S+|http:\/\/(?:127\.\d{1,3}\.\d{1,3}\.\d{1,3}|localhost|\[::1\])(?::\d{1,5})?(?:\/\S*)?)$/;
35
50
  const urlString = (re) => z
36
51
  .string()
@@ -49,6 +64,15 @@ const exactVersion = (what) => z
49
64
  .string()
50
65
  .max(256)
51
66
  .regex(SEMVER_VERSION_RE, { message: `${what} must be an exact semver version` });
67
+ /** The path of a URL (empty when it does not parse). */
68
+ const urlPathname = (s) => {
69
+ try {
70
+ return new URL(s).pathname;
71
+ }
72
+ catch {
73
+ return "";
74
+ }
75
+ };
52
76
  /** `./<safe path>` inside the marketplace repo. */
53
77
  const repoPath = z
54
78
  .string()
@@ -123,6 +147,12 @@ function buildSchema(opts) {
123
147
  en: z.string().min(1).max(M.summaryChars),
124
148
  zh: z.string().min(1).max(M.summaryChars).optional(),
125
149
  }),
150
+ displayName: z
151
+ .object({
152
+ zh: z.string().min(1).max(M.displayNameChars),
153
+ en: z.string().min(1).max(M.displayNameChars),
154
+ })
155
+ .optional(),
126
156
  version: exactVersion("version").optional(),
127
157
  minKernel: exactVersion("minKernel").optional(),
128
158
  permissions: z
@@ -132,6 +162,18 @@ function buildSchema(opts) {
132
162
  })
133
163
  .optional(),
134
164
  homepage: urlString(HTTPS_URL_RE).optional(),
165
+ icon: z
166
+ .union([
167
+ urlString(opts.allowInsecureLoopback ? ICON_URL_OR_LOOPBACK_RE : ICON_URL_RE).refine((s) => MARKETPLACE_ICON_RE.test(urlPathname(s)), { message: "an icon URL's path must end in .svg or .png" }),
168
+ repoPath.regex(ICON_PATH_RE, { message: "icon must be a .svg or .png file" }),
169
+ ])
170
+ .optional(),
171
+ deprecated: z
172
+ .union([
173
+ z.boolean(),
174
+ z.object({ reason: z.string().min(1).max(M.deprecationReasonChars).optional() }),
175
+ ])
176
+ .optional(),
135
177
  source,
136
178
  });
137
179
  return z
@@ -230,6 +272,14 @@ const SOURCE_FORMS = ["path", "git", "npm", "archive"];
230
272
  * form the source uses instead, or that it must use exactly one form.
231
273
  */
232
274
  function explainSource(json, issue) {
275
+ if (issue.code === "invalid_union" && issue.path[issue.path.length - 1] === "icon") {
276
+ return [
277
+ {
278
+ path: issue.path,
279
+ message: 'icon must be an https URL whose path ends in .svg or .png, or a "./" path inside the repository ending in .svg or .png',
280
+ },
281
+ ];
282
+ }
233
283
  if (issue.code !== "invalid_union" || issue.path[issue.path.length - 1] !== "source") {
234
284
  return [issue];
235
285
  }
@@ -254,3 +304,23 @@ export function marketplaceEntryVersion(e) {
254
304
  return e.source.npm.version;
255
305
  return null;
256
306
  }
307
+ /**
308
+ * The entry's icon (see {@link MarketplaceEntry.icon}): `{ url }` for an absolute URL, `{ path }`
309
+ * (normalized, without the leading `./`) for a path inside the marketplace's repository, `null`
310
+ * without one.
311
+ */
312
+ export function marketplaceEntryIcon(e) {
313
+ if (e.icon === undefined)
314
+ return null;
315
+ return e.icon.startsWith("./") ? { path: e.icon.slice(2) } : { url: e.icon };
316
+ }
317
+ /**
318
+ * The entry's deprecation (see {@link MarketplaceEntry.deprecated}): `null` when it is not
319
+ * deprecated (absent or `false`), else its reason (`null` without one).
320
+ */
321
+ export function marketplaceEntryDeprecation(e) {
322
+ const d = e.deprecated;
323
+ if (d === undefined || d === false)
324
+ return null;
325
+ return { reason: d === true ? null : (d.reason ?? null) };
326
+ }
package/dist/model.d.ts CHANGED
@@ -4,9 +4,32 @@
4
4
  * 见 `model-params.ts`);旧契约 `model-provider@1`(`ModelProviderV1` 等)由内核经适配层继续支持。
5
5
  */
6
6
  import type { Effort, ModelParameter, ParamValue } from "./model-params.js";
7
+ import type { LocalizedName } from "./plugin-package.js";
8
+ /** What a model does. Absent on a `ModelInfo` means `chat`. */
9
+ export type ModelKind = "chat" | "embedding" | "rerank" | "image_generation" | "video_generation" | "speech_to_text" | "text_to_speech";
10
+ /** Embedding facts of a model whose `kind` is `embedding`. */
11
+ export interface ModelEmbeddingInfo {
12
+ /** The output dimensions the model can produce (a single entry when not adjustable). */
13
+ dimensions: number[];
14
+ defaultDimensions: number;
15
+ /** Most tokens one input may hold. */
16
+ maxInputTokens: number;
17
+ /** Most inputs one `embed` call may carry. */
18
+ maxBatch: number;
19
+ }
7
20
  export interface ModelInfo {
8
21
  id: string;
9
22
  displayName: string;
23
+ /** Defaults to `chat`. Chat-only fields below stay required for every kind. */
24
+ kind?: ModelKind;
25
+ /** Who made the model (display only). */
26
+ publisher?: string;
27
+ /** Display only. */
28
+ description?: LocalizedName | string;
29
+ /** ISO date after which the model is retired (display only). */
30
+ retiresAt?: string;
31
+ /** Set when `kind` is `embedding`. */
32
+ embedding?: ModelEmbeddingInfo;
10
33
  contextWindow: number;
11
34
  maxOutputTokens: number;
12
35
  capabilities: {
@@ -206,14 +229,49 @@ export declare class ModelError extends Error {
206
229
  /** rate_limited / overloaded / server / timeout / network 为 true。 */
207
230
  get retryable(): boolean;
208
231
  }
232
+ /**
233
+ * Options of a model call made for an organization.
234
+ * `config` is the extension's effective deployment config for this org: the platform's deployment
235
+ * config with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
236
+ * platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`, for
237
+ * work done for this org. Optional in the type so older providers compile; the kernel always passes
238
+ * both.
239
+ */
240
+ export interface ModelCallOptions {
241
+ orgId?: string;
242
+ config?: unknown;
243
+ }
244
+ export interface EmbedRequest {
245
+ model: string;
246
+ input: string[];
247
+ /** One of the model's `embedding.dimensions`; the model's default when absent. */
248
+ dimensions?: number;
249
+ inputType?: "query" | "document";
250
+ }
251
+ export interface EmbedResult {
252
+ /** One vector per input, in input order. */
253
+ vectors: number[][];
254
+ usage: {
255
+ inputTokens: number;
256
+ };
257
+ }
258
+ /**
259
+ * Checks an embedding result against its request and the model's embedding facts. Returns null when
260
+ * valid, else the reason: wrong vector count, wrong dimension, or a non-finite number.
261
+ */
262
+ export declare function validateEmbedResult(req: EmbedRequest, info: ModelEmbeddingInfo, res: EmbedResult): string | null;
209
263
  /** `model-provider@2` 的实现。 */
210
264
  export interface ModelProvider {
211
265
  /** 每个模型的 `parameters` 须通过 `assertValidDeclarations`,否则内核不使用该供应商。 */
212
- listModels(): Promise<ModelInfo[]>;
266
+ listModels(opts?: ModelCallOptions): Promise<ModelInfo[]>;
213
267
  /** 事件序列必须以且仅以一个 message_complete 结束;出错抛 ModelError。 */
214
268
  stream(req: ModelRequest, opts: {
215
269
  signal: AbortSignal;
216
- }): AsyncIterable<ModelStreamEvent>;
270
+ } & ModelCallOptions): AsyncIterable<ModelStreamEvent>;
271
+ /** Present only on a provider that lists `embedding` models. */
272
+ embed?(req: EmbedRequest, opts: {
273
+ signal: AbortSignal;
274
+ } & ModelCallOptions): Promise<EmbedResult>;
217
275
  }
218
276
  /** `model-provider@1` 的实现(旧契约,内核经适配层接入:effort 由 `capabilities.effort` 推导)。 */
219
277
  export interface ModelProviderV1 {
package/dist/model.js CHANGED
@@ -148,5 +148,27 @@ export class ModelError extends Error {
148
148
  return isRetryableKind(this.kind);
149
149
  }
150
150
  }
151
+ /**
152
+ * Checks an embedding result against its request and the model's embedding facts. Returns null when
153
+ * valid, else the reason: wrong vector count, wrong dimension, or a non-finite number.
154
+ */
155
+ export function validateEmbedResult(req, info, res) {
156
+ if (res.vectors.length !== req.input.length) {
157
+ return `vector count ${res.vectors.length} does not match input count ${req.input.length}`;
158
+ }
159
+ const dims = req.dimensions ?? info.defaultDimensions;
160
+ for (let i = 0; i < res.vectors.length; i++) {
161
+ const v = res.vectors[i];
162
+ if (v.length !== dims) {
163
+ return `vector ${i} has dimension ${v.length}, expected ${dims}`;
164
+ }
165
+ for (const x of v) {
166
+ if (typeof x !== "number" || !Number.isFinite(x)) {
167
+ return `vector ${i} holds a non-finite number`;
168
+ }
169
+ }
170
+ }
171
+ return null;
172
+ }
151
173
  export const MODEL_PROVIDER_EXTENSION_POINT = "model-provider@1";
152
174
  export const MODEL_PROVIDER_EXTENSION_POINT_V2 = "model-provider@2";
@@ -0,0 +1,27 @@
1
+ import type { z } from "zod";
2
+ /**
3
+ * How an org may treat a deployment config field: `readonly` (the org sees it, never sets it) or
4
+ * `override` (an org may set its own value). A field without a level is deployment-only.
5
+ */
6
+ export type OrgAccess = "readonly" | "override";
7
+ /**
8
+ * Marks a deployment config field with an org access level (Zod 4 meta `{ org: access }`), merging
9
+ * with existing meta (`secret`, `hot`, `ui`), so `orgAccess(secret(x), …)` and
10
+ * `secret(orgAccess(x, …))` are the same. `configJsonSchema` publishes it as `"x-org"`.
11
+ *
12
+ * The author's promise for `override`: the extension reads the field from the per-call `config`
13
+ * the kernel passes with each request, not from `ctx.config`, and the field may be absent from
14
+ * `ctx.config` (the deployment value is the default, which an org may replace per call).
15
+ *
16
+ * The per-call config of an org that has its own copy still contains the platform's hidden
17
+ * (platform-only) secrets, which an org cannot set; it never contains an overridable platform
18
+ * secret. Never send a hidden secret to an endpoint taken from an overridable field: an org could
19
+ * point that endpoint at a server it controls.
20
+ */
21
+ export declare function orgAccess<T extends z.ZodTypeAny>(schema: T, access: OrgAccess): T;
22
+ /**
23
+ * The org access level of a schema's meta, or undefined when it has none. It sees through
24
+ * `.optional()`, `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()` (the
25
+ * outermost level wins), so it agrees with the `"x-org"` that `configJsonSchema` publishes.
26
+ */
27
+ export declare function orgAccessOf(schema: z.ZodTypeAny): OrgAccess | undefined;