@capybara-hq/plugin-sdk 0.1.0-rc.0 → 0.1.0-rc.10

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 (93) hide show
  1. package/README.md +3 -3
  2. package/agent-docs/agent-templates.md +47 -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/counter.md +15 -0
  9. package/agent-docs/extension-points/directory.md +15 -0
  10. package/agent-docs/extension-points/file-preview.md +15 -0
  11. package/agent-docs/extension-points/identity-source.md +15 -0
  12. package/agent-docs/extension-points/model-provider.md +15 -0
  13. package/agent-docs/extension-points/object-store.md +15 -0
  14. package/agent-docs/extension-points/sandbox.md +15 -0
  15. package/agent-docs/extension-points/secret-store.md +15 -0
  16. package/agent-docs/extension-points/web-fetch.md +15 -0
  17. package/agent-docs/extension-points/web-search.md +15 -0
  18. package/agent-docs/extensions.md +87 -0
  19. package/agent-docs/plugin-format.md +99 -0
  20. package/agent-docs/setup.md +46 -0
  21. package/agent-docs/skills.md +44 -0
  22. package/agent-docs/tool-naming.md +21 -0
  23. package/dist/agent-template.d.ts +85 -0
  24. package/dist/agent-template.js +362 -3
  25. package/dist/cards.d.ts +7 -0
  26. package/dist/cards.js +4 -4
  27. package/dist/channel.d.ts +20 -1
  28. package/dist/config-ui.d.ts +131 -0
  29. package/dist/config-ui.js +602 -0
  30. package/dist/connector-auth.d.ts +2 -0
  31. package/dist/connector-auth.js +15 -0
  32. package/dist/ctx.d.ts +86 -4
  33. package/dist/define-extension.d.ts +5 -1
  34. package/dist/define-extension.js +1 -0
  35. package/dist/device-protocol.d.ts +118 -0
  36. package/dist/device-protocol.js +276 -0
  37. package/dist/directory.d.ts +11 -2
  38. package/dist/extension-point.d.ts +9 -0
  39. package/dist/extension-point.js +17 -12
  40. package/dist/file-preview.d.ts +9 -1
  41. package/dist/hooks.d.ts +79 -18
  42. package/dist/index.d.ts +16 -1
  43. package/dist/index.js +16 -1
  44. package/dist/marketplace.d.ts +55 -2
  45. package/dist/marketplace.js +73 -3
  46. package/dist/model.d.ts +60 -2
  47. package/dist/model.js +22 -0
  48. package/dist/org-access.d.ts +27 -0
  49. package/dist/org-access.js +35 -0
  50. package/dist/permissions.d.ts +20 -5
  51. package/dist/permissions.js +51 -15
  52. package/dist/plugin-manifest.d.ts +48 -5
  53. package/dist/plugin-manifest.js +93 -6
  54. package/dist/sandbox.d.ts +164 -62
  55. package/dist/sandbox.js +71 -14
  56. package/dist/secret.d.ts +4 -1
  57. package/dist/secret.js +5 -2
  58. package/dist/setup-check.d.ts +115 -0
  59. package/dist/setup-check.js +142 -0
  60. package/dist/setup-guide-parse.d.ts +121 -0
  61. package/dist/setup-guide-parse.js +350 -0
  62. package/dist/setup-guide-render.d.ts +45 -0
  63. package/dist/setup-guide-render.js +351 -0
  64. package/dist/setup-guide.d.ts +94 -0
  65. package/dist/setup-guide.js +336 -0
  66. package/dist/skill-invocation.d.ts +12 -8
  67. package/dist/skill-invocation.js +19 -9
  68. package/dist/skill.d.ts +23 -3
  69. package/dist/skill.js +31 -6
  70. package/dist/theme-assets.d.ts +39 -0
  71. package/dist/theme-assets.js +449 -0
  72. package/dist/theme-readability.d.ts +37 -0
  73. package/dist/theme-readability.js +145 -0
  74. package/dist/theme-tokens.generated.d.ts +275 -0
  75. package/dist/theme-tokens.generated.js +167 -0
  76. package/dist/theme.d.ts +152 -0
  77. package/dist/theme.js +392 -0
  78. package/dist/tool-key.d.ts +28 -0
  79. package/dist/tool-key.js +40 -0
  80. package/dist/tool.d.ts +11 -3
  81. package/dist/ui-resolve.d.ts +40 -0
  82. package/dist/ui-resolve.js +54 -0
  83. package/dist/ui-slots.d.ts +43 -0
  84. package/dist/ui-slots.js +168 -0
  85. package/dist/ui.d.ts +114 -31
  86. package/dist/ui.js +0 -4
  87. package/dist/web.d.ts +105 -0
  88. package/dist/web.js +135 -0
  89. package/package.json +10 -2
  90. package/schemas/connector-template.v1.schema.json +3 -0
  91. package/schemas/marketplace.v1.schema.json +50 -0
  92. package/schemas/plugin.v1.schema.json +97 -4
  93. package/schemas/theme.v1.schema.json +225 -0
package/dist/hooks.d.ts CHANGED
@@ -7,12 +7,12 @@ import type { ContentBlock, ModelRequest, ModelUsage } from "./model.js";
7
7
  export declare const HOOKS_AVAILABLE: readonly ["model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report"];
8
8
  /** A mount point that `ctx.hooks.on` accepts. */
9
9
  export type AvailableHook = (typeof HOOKS_AVAILABLE)[number];
10
- /** Where a sub-agent was dispatched from: the parent conversation, its run and the `agent` call. */
10
+ /** Where a sub-agent was dispatched from: the parent conversation, its run and the `Agent` call. */
11
11
  export interface HookParentScope {
12
12
  conversationId: string;
13
13
  runId: string;
14
14
  /**
15
- * The `agent` call's id; `skill-<seq>` for a person's forked skill invocation, which has no
15
+ * The `Agent` call's id; `skill-<seq>` for a person's forked skill invocation, which has no
16
16
  * tool call in the parent's log.
17
17
  */
18
18
  callId: string;
@@ -35,11 +35,16 @@ export interface HookScope {
35
35
  * What a model call is for: `step` is a run step's call (the agent's turn), `compaction` is the call
36
36
  * that summarizes earlier history before a step when the context grows too large, `title` is the call
37
37
  * that writes a conversation's title after its first completed run (no run: `runId` is "", `step` 0,
38
- * `attempt` 1).
38
+ * `attempt` 1), `web_fetch` is the call that extracts an answer from a fetched web page for the
39
+ * `WebFetch` tool.
39
40
  */
40
- export type ModelCallPurpose = "step" | "compaction" | "title";
41
- /** What a reported model call was for (the same values as {@link ModelCallPurpose}). */
42
- export type UsagePurpose = ModelCallPurpose;
41
+ export type ModelCallPurpose = "step" | "compaction" | "title" | "web_fetch";
42
+ /**
43
+ * What a reported or requested model call was for: the {@link ModelCallPurpose} values, or
44
+ * `embedding` for an embedding call an extension made through `ctx.models` (`usage.report`, and
45
+ * `model.request` with {@link EmbeddingRequestHookPayload}; never `model.response`).
46
+ */
47
+ export type UsagePurpose = ModelCallPurpose | "embedding";
43
48
  /**
44
49
  * An image or document of a `model.request` payload. Hook payloads never carry media bytes or
45
50
  * attachment ids: each image or document block is replaced by this placeholder.
@@ -73,14 +78,15 @@ export type HookModelRequest = Omit<ModelRequest, "messages"> & {
73
78
  messages: HookModelMessage[];
74
79
  };
75
80
  /**
76
- * `model.request`: before a model call is sent. A policy hook may deny it. Fires once per attempt of a
77
- * step (`purpose: "step"`), once for each compaction call (`purpose: "compaction"`, `attempt` 1) and
81
+ * `model.request` of a chat model call (see {@link ModelRequestHookPayload}): once per attempt of a
82
+ * step (`purpose: "step"`), once for each compaction call (`purpose: "compaction"`, `attempt` 1),
78
83
  * once for each conversation title call (`purpose: "title"`, `runId` "", `step` 0, `attempt` 1; a
79
- * denial skips the title and is recorded only in the audit log).
84
+ * denial skips the title and is recorded only in the audit log) and once for each `WebFetch`
85
+ * extraction call (`purpose: "web_fetch"`).
80
86
  * `request` is the request as sent, except that images and documents are placeholders
81
87
  * ({@link HookMediaPlaceholder}): no media bytes, no attachment ids.
82
88
  */
83
- export interface ModelRequestHookPayload extends HookScope {
89
+ export interface ModelCallRequestHookPayload extends HookScope {
84
90
  purpose: ModelCallPurpose;
85
91
  step: number;
86
92
  attempt: number;
@@ -88,6 +94,45 @@ export interface ModelRequestHookPayload extends HookScope {
88
94
  model: string;
89
95
  request: Readonly<HookModelRequest>;
90
96
  }
97
+ /**
98
+ * `model.request` of an embedding call an extension made through `ctx.models.embed`
99
+ * (`purpose: "embedding"`): fired once per `embed` call, before the first batch is sent, with every
100
+ * text of the call (the kernel splits them into batches afterwards). A call with no input sends
101
+ * nothing and fires nothing. There is no conversation: the conversation fields of a chat model call
102
+ * (`accountId`, `agentId`, `agentVersion`, `conversationId`, `runId`, `parent`, `step`, `attempt`,
103
+ * `request`) are absent. A policy denial makes `embed` reject (`model.hook_denied`); nothing is sent
104
+ * to the provider and no usage is recorded.
105
+ */
106
+ export interface EmbeddingRequestHookPayload {
107
+ purpose: "embedding";
108
+ orgId: string;
109
+ /** The extension that called `ctx.models.embed`. */
110
+ extension: string;
111
+ /** The embedding purpose the extension called with (one it declared in `permissions.models`). */
112
+ embeddingPurpose: string;
113
+ provider: string;
114
+ model: string;
115
+ /** The texts of the call, in order (text only). */
116
+ input: readonly string[];
117
+ /** The dimensions the extension asked for, when it asked. */
118
+ dimensions?: number;
119
+ /** The input type the extension gave, when it gave one. */
120
+ inputType?: "query" | "document";
121
+ accountId?: undefined;
122
+ agentId?: undefined;
123
+ agentVersion?: undefined;
124
+ conversationId?: undefined;
125
+ runId?: undefined;
126
+ parent?: undefined;
127
+ }
128
+ /**
129
+ * `model.request`: before a model call is sent. A policy hook may deny it. Either a chat model call
130
+ * ({@link ModelCallRequestHookPayload}: steps, compaction, titles, `WebFetch`) or an extension's
131
+ * embedding call ({@link EmbeddingRequestHookPayload}, `purpose: "embedding"`); tell them apart by
132
+ * `purpose`. Handlers must accept the absent conversation fields of an embedding call (a policy
133
+ * hook that throws on one denies the call). Payloads carry no media bytes.
134
+ */
135
+ export type ModelRequestHookPayload = ModelCallRequestHookPayload | EmbeddingRequestHookPayload;
91
136
  /**
92
137
  * `model.response`: after a sent model call finished or failed, with its usage when known (step
93
138
  * attempts, compaction and title calls, see `purpose`). Not fired for a call the user aborted (the run was
@@ -111,6 +156,7 @@ export interface ModelResponseHookPayload extends HookScope {
111
156
  export interface ToolPreHookPayload extends HookScope {
112
157
  step: number;
113
158
  callId: string;
159
+ /** The model-visible key: a builtin name, `mcp__<slug>__<tool>` or `plugin__<plugin>__<tool>`; split it with `parseToolKey`. */
114
160
  toolKey: string;
115
161
  specHash: string;
116
162
  input: unknown;
@@ -136,12 +182,18 @@ export interface UsageReportPayload {
136
182
  */
137
183
  purpose: UsagePurpose;
138
184
  orgId: string;
139
- accountId: string;
140
- agentId: string;
141
- conversationId: string;
142
- /** A sub-agent's calls report `chat`; `parent` tells them apart. */
143
- conversationKind: "chat" | "eval";
144
- runId: string;
185
+ /** Absent for `embedding`. */
186
+ accountId?: string;
187
+ /** Absent for `embedding`. */
188
+ agentId?: string;
189
+ /** Absent for `embedding`. */
190
+ conversationId?: string;
191
+ /** A sub-agent's calls report `chat`; `parent` tells them apart. Absent for `embedding`. */
192
+ conversationKind?: "chat" | "eval";
193
+ /** Absent for `embedding`. */
194
+ runId?: string;
195
+ /** The calling extension; set for `embedding`. */
196
+ extension?: string;
145
197
  /** Set when the call belongs to a sub-agent: where it was dispatched from. */
146
198
  parent?: HookParentScope;
147
199
  provider: string;
@@ -167,9 +219,18 @@ export type HookVerdict = void | {
167
219
  };
168
220
  /**
169
221
  * A hook handler. The payload is a deep-frozen copy (mutating it throws). `signal` aborts when the
170
- * hook runs past `hooks.timeoutMs` or the call it observes is aborted.
222
+ * hook runs past `hooks.timeoutMs` or the call it observes is aborted. `call.config` is the
223
+ * extension's effective deployment config for the payload's org (the platform's config with the
224
+ * org's copy applied to the overridable fields, or `ctx.config` while the org follows it); the
225
+ * kernel always passes it, and never calls a hook for an org where that config is not valid
226
+ * (observe hooks are skipped, policy hooks deny).
171
227
  */
172
- export type HookHandler<K extends AvailableHook> = (payload: HookPayloads[K], signal: AbortSignal) => Promise<HookVerdict> | HookVerdict;
228
+ export type HookHandler<K extends AvailableHook> = (payload: HookPayloads[K], signal: AbortSignal, call?: HookCall) => Promise<HookVerdict> | HookVerdict;
229
+ /** The per-call context of a hook handler (see {@link HookHandler}). */
230
+ export interface HookCall {
231
+ /** The extension's effective deployment config for the payload's org. */
232
+ config: unknown;
233
+ }
173
234
  /**
174
235
  * - `policy` (only on {@link POLICY_HOOKS}): policy hooks run serially by plugin name (registration
175
236
  * order within a plugin) before the call; the first `{ deny }`, error or timeout blocks the call and
package/dist/index.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.0";
1
+ export declare const SDK_VERSION = "0.1.0-rc.10";
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 "./config-ui.js";
6
7
  export * from "./connector.js";
7
8
  export * from "./connector-auth.js";
8
9
  export * from "./ctx.js";
9
10
  export * from "./define-extension.js";
11
+ export * from "./device-protocol.js";
10
12
  export * from "./directory.js";
11
13
  export * from "./extension-point.js";
12
14
  export * from "./file-preview.js";
@@ -15,13 +17,26 @@ export * from "./identity.js";
15
17
  export * from "./marketplace.js";
16
18
  export * from "./model.js";
17
19
  export * from "./model-params.js";
20
+ export * from "./org-access.js";
18
21
  export * from "./permissions.js";
19
22
  export * from "./plugin-manifest.js";
20
23
  export * from "./plugin-package.js";
21
24
  export * from "./sandbox.js";
22
25
  export * from "./secret.js";
26
+ export * from "./setup-check.js";
27
+ export * from "./setup-guide.js";
28
+ export { type ParsedSetupGuide, parseSetupGuide, type SetupGuideCheckLine, type SetupGuideCodeBlock, type SetupGuideParseIssue, type SetupGuideSection, } from "./setup-guide-parse.js";
29
+ export * from "./setup-guide-render.js";
23
30
  export * from "./skill.js";
24
31
  export * from "./skill-invocation.js";
25
32
  export * from "./storage.js";
33
+ export * from "./theme.js";
34
+ export * from "./theme-assets.js";
35
+ export * from "./theme-readability.js";
36
+ export * from "./theme-tokens.generated.js";
26
37
  export * from "./tool.js";
38
+ export * from "./tool-key.js";
27
39
  export * from "./ui.js";
40
+ export * from "./ui-resolve.js";
41
+ export * from "./ui-slots.js";
42
+ export * from "./web.js";
package/dist/index.js CHANGED
@@ -1,12 +1,14 @@
1
- export const SDK_VERSION = "0.1.0-rc.0";
1
+ export const SDK_VERSION = "0.1.0-rc.10";
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 "./config-ui.js";
6
7
  export * from "./connector.js";
7
8
  export * from "./connector-auth.js";
8
9
  export * from "./ctx.js";
9
10
  export * from "./define-extension.js";
11
+ export * from "./device-protocol.js";
10
12
  export * from "./directory.js";
11
13
  export * from "./extension-point.js";
12
14
  export * from "./file-preview.js";
@@ -15,13 +17,26 @@ export * from "./identity.js";
15
17
  export * from "./marketplace.js";
16
18
  export * from "./model.js";
17
19
  export * from "./model-params.js";
20
+ export * from "./org-access.js";
18
21
  export * from "./permissions.js";
19
22
  export * from "./plugin-manifest.js";
20
23
  export * from "./plugin-package.js";
21
24
  export * from "./sandbox.js";
22
25
  export * from "./secret.js";
26
+ export * from "./setup-check.js";
27
+ export * from "./setup-guide.js";
28
+ export { parseSetupGuide, } from "./setup-guide-parse.js";
29
+ export * from "./setup-guide-render.js";
23
30
  export * from "./skill.js";
24
31
  export * from "./skill-invocation.js";
25
32
  export * from "./storage.js";
33
+ export * from "./theme.js";
34
+ export * from "./theme-assets.js";
35
+ export * from "./theme-readability.js";
36
+ export * from "./theme-tokens.generated.js";
26
37
  export * from "./tool.js";
38
+ export * from "./tool-key.js";
27
39
  export * from "./ui.js";
40
+ export * from "./ui-resolve.js";
41
+ export * from "./ui-slots.js";
42
+ 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;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Marks a deployment config field with an org access level (Zod 4 meta `{ org: access }`), merging
3
+ * with existing meta (`secret`, `hot`, `ui`), so `orgAccess(secret(x), …)` and
4
+ * `secret(orgAccess(x, …))` are the same. `configJsonSchema` publishes it as `"x-org"`.
5
+ *
6
+ * The author's promise for `override`: the extension reads the field from the per-call `config`
7
+ * the kernel passes with each request, not from `ctx.config`, and the field may be absent from
8
+ * `ctx.config` (the deployment value is the default, which an org may replace per call).
9
+ *
10
+ * The per-call config of an org that has its own copy still contains the platform's hidden
11
+ * (platform-only) secrets, which an org cannot set; it never contains an overridable platform
12
+ * secret. Never send a hidden secret to an endpoint taken from an overridable field: an org could
13
+ * point that endpoint at a server it controls.
14
+ */
15
+ export function orgAccess(schema, access) {
16
+ return schema.meta({ ...(schema.meta() ?? {}), org: access });
17
+ }
18
+ /** The wrappers a field's org level is read through, as `configJsonSchema` inherits meta. */
19
+ const WRAPPERS = new Set(["default", "prefault", "optional", "nullable", "readonly", "catch"]);
20
+ /**
21
+ * The org access level of a schema's meta, or undefined when it has none. It sees through
22
+ * `.optional()`, `.default()`, `.nullable()`, `.prefault()`, `.catch()` and `.readonly()` (the
23
+ * outermost level wins), so it agrees with the `"x-org"` that `configJsonSchema` publishes.
24
+ */
25
+ export function orgAccessOf(schema) {
26
+ let node = schema;
27
+ while (node) {
28
+ const v = node.meta()?.org;
29
+ if (v === "readonly" || v === "override")
30
+ return v;
31
+ const def = node._zod.def;
32
+ node = WRAPPERS.has(def.type) ? def.innerType : undefined;
33
+ }
34
+ return undefined;
35
+ }