@capybara-hq/plugin-sdk 0.1.0-rc.6 → 0.1.0-rc.8
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.
- package/agent-docs/connector-templates.md +1 -0
- package/agent-docs/plugin-format.md +17 -2
- package/dist/cards.d.ts +7 -0
- package/dist/cards.js +4 -4
- package/dist/channel.d.ts +20 -1
- package/dist/connector-auth.d.ts +2 -0
- package/dist/connector-auth.js +15 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +6 -1
- package/dist/marketplace.d.ts +26 -0
- package/dist/marketplace.js +43 -1
- package/dist/plugin-manifest.d.ts +22 -3
- package/dist/plugin-manifest.js +85 -5
- package/dist/setup-guide.d.ts +94 -0
- package/dist/setup-guide.js +135 -0
- package/dist/theme-assets.d.ts +39 -0
- package/dist/theme-assets.js +449 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +275 -0
- package/dist/theme-tokens.generated.js +167 -0
- package/dist/theme.d.ts +152 -0
- package/dist/theme.js +392 -0
- package/package.json +2 -1
- package/schemas/connector-template.v1.schema.json +3 -0
- package/schemas/marketplace.v1.schema.json +14 -0
- package/schemas/plugin.v1.schema.json +155 -0
- package/schemas/theme.v1.schema.json +225 -0
|
@@ -10,11 +10,12 @@ A plugin is a directory, packed into a `.tgz` with `capybara-plugin pack` (the p
|
|
|
10
10
|
skills/<name>/SKILL.md skills (scanned unless plugin.json lists them)
|
|
11
11
|
connectors/<id>.json connector templates (scanned unless listed)
|
|
12
12
|
agents/<name>.md agent templates (scanned unless listed)
|
|
13
|
+
themes/<id>.json themes (scanned unless listed)
|
|
13
14
|
src/index.ts the extension (optional; bundled by the packer)
|
|
14
15
|
migrations/*.sql, ui/** extension migrations and UI files (optional)
|
|
15
16
|
```
|
|
16
17
|
|
|
17
|
-
A plugin without `src/index.ts` is declarative: skills and
|
|
18
|
+
A plugin without `src/index.ts` is declarative: skills, templates and themes only, no code runs.
|
|
18
19
|
|
|
19
20
|
## plugin.json
|
|
20
21
|
|
|
@@ -37,6 +38,8 @@ file is strict: an unknown key is an error. Fields (agent templates are listed u
|
|
|
37
38
|
| `skills` | array of object | no |
|
|
38
39
|
| `connectorTemplates` | array of object | no |
|
|
39
40
|
| `agents` | array of object | no |
|
|
41
|
+
| `themes` | array of object | no |
|
|
42
|
+
| `setupGuides` | array of object | no |
|
|
40
43
|
| `extension` | object | no |
|
|
41
44
|
<!-- /generated -->
|
|
42
45
|
|
|
@@ -47,10 +50,22 @@ Rules that the schema cannot show:
|
|
|
47
50
|
release candidates, ranges on official packages are written `^0.1.0-rc.0`.
|
|
48
51
|
- `description` is a string or `{ en, zh? }`; `displayName` is `{ zh, en }`.
|
|
49
52
|
- `icon` is a `./` path to an `.svg` or `.png` inside the plugin.
|
|
50
|
-
- `skills`, `connectorTemplates`, `agents` list paths starting with `./` that stay inside the plugin.
|
|
53
|
+
- `skills`, `connectorTemplates`, `agents`, `themes` list paths starting with `./` that stay inside the plugin.
|
|
51
54
|
Omit them to scan the default folders. Names and ids are unique within the plugin.
|
|
52
55
|
- `dependencies`: plugin name plus semver range; no self-dependency.
|
|
53
56
|
- `agents`: at most 64 templates (see `agent-templates`).
|
|
57
|
+
- `themes`: at most 10 `<id>.json` files; the id is the file's base name. A theme file is checked
|
|
58
|
+
by `parseThemeFile` (schema `https://capybarahq.com/schemas/theme.v1.schema.json`).
|
|
59
|
+
- `setupGuides` (at most 8): setup material shown where a person configures what the plugin
|
|
60
|
+
brings. Each guide has an `id`, a `place` (`channel-connection`: 新建渠道 and the channel detail;
|
|
61
|
+
the plugin's extension must provide `channel@1`), a `title` and `steps` (`{ en, zh? }`, plain
|
|
62
|
+
text, a backtick pair shows as inline code) and `files` (`./` paths ending in `.tmpl`, `.yaml`,
|
|
63
|
+
`.yml`, `.json` or `.txt`, at most 64 KiB of text, with a `title` and a `language` of `yaml`,
|
|
64
|
+
`json` or `text`). A step or file may carry `mode` (`long_connection` or `webhook`) to apply to
|
|
65
|
+
that inbound mode only; ship one file per mode instead of conditionals. The kernel fills
|
|
66
|
+
`{{publicUrl}}`, `{{webhookUrl}}`, `{{signInCallbackUrl}}`, `{{connectionName}}`, `{{orgName}}`,
|
|
67
|
+
`{{pluginName}}`, `{{pluginVersion}}` and `{{mode}}` (never a secret); in YAML and JSON put a
|
|
68
|
+
placeholder inside double quotes. `capybara-plugin pack` refuses any other placeholder.
|
|
54
69
|
- `extension` is written by the packer; never write it by hand.
|
|
55
70
|
|
|
56
71
|
## Importing
|
package/dist/cards.d.ts
CHANGED
|
@@ -10,6 +10,13 @@ export type ChannelCard = {
|
|
|
10
10
|
toolName: string;
|
|
11
11
|
appName?: string;
|
|
12
12
|
agentName: string;
|
|
13
|
+
/**
|
|
14
|
+
* One line saying what the call does, as the web shows it: the tool's confirmation summary
|
|
15
|
+
* (e.g. a Platform operation's), else the tool's title and key argument; may be empty.
|
|
16
|
+
* Never the raw call input (it may hold a whole prompt, and a group sees the card); the
|
|
17
|
+
* full input is behind `webUrl`. Plain text written by the kernel from model-controlled
|
|
18
|
+
* values: render it as text, never as markup. The name is kept from when it held the input.
|
|
19
|
+
*/
|
|
13
20
|
inputPreview: string;
|
|
14
21
|
scopes: ("once" | "session" | "always")[];
|
|
15
22
|
expiresAt: string;
|
package/dist/cards.js
CHANGED
|
@@ -92,7 +92,7 @@ export function validateChannelCard(card) {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
95
|
+
* 把模型可控的值(审批标题、调用摘要、提问标题、回答摘要)放进代码里,退回文本里它们不会变成链接、强调或 HTML:
|
|
96
96
|
* 单行用行内代码,多行用围栏代码块(以换行开头),分隔符都比值里最长的反引号串更长(CommonMark 6.1 / 4.5)。
|
|
97
97
|
* 选代码而不是给标点加反斜杠:代码是 CommonMark / GFM 里唯一保证内容按原样显示的写法(反斜杠挡不住 GFM 的裸网址
|
|
98
98
|
* 自动链接,各渠道转换器对反斜杠的处理也不一致)。
|
|
@@ -119,7 +119,7 @@ const TEXT = {
|
|
|
119
119
|
connect: (app) => `[Connect] ${app} needs to be connected.`,
|
|
120
120
|
tool: "Tool",
|
|
121
121
|
agent: "Agent",
|
|
122
|
-
|
|
122
|
+
summary: "Summary",
|
|
123
123
|
status: "Status",
|
|
124
124
|
reason: "Reason",
|
|
125
125
|
expires: "Expires",
|
|
@@ -149,7 +149,7 @@ const TEXT = {
|
|
|
149
149
|
connect: (app) => `【连接】需要连接 ${app}。`,
|
|
150
150
|
tool: "工具",
|
|
151
151
|
agent: "Agent",
|
|
152
|
-
|
|
152
|
+
summary: "摘要",
|
|
153
153
|
status: "状态",
|
|
154
154
|
reason: "原因",
|
|
155
155
|
expires: "过期时间",
|
|
@@ -187,7 +187,7 @@ export function renderCardAsText(card, locale) {
|
|
|
187
187
|
withCode(t.approval, asCode(card.title)),
|
|
188
188
|
line(t.tool, card.appName ? `${card.appName} / ${card.toolName}` : card.toolName),
|
|
189
189
|
line(t.agent, card.agentName),
|
|
190
|
-
line(t.
|
|
190
|
+
...(card.inputPreview !== "" ? [line(t.summary, asCode(card.inputPreview))] : []),
|
|
191
191
|
line(t.status, card.decidedBy ? `${state} (${card.decidedBy})` : state),
|
|
192
192
|
];
|
|
193
193
|
if (card.state === "denied" && card.denyReason)
|
package/dist/channel.d.ts
CHANGED
|
@@ -21,6 +21,21 @@ export interface InboundSender {
|
|
|
21
21
|
tenantId: string;
|
|
22
22
|
displayName?: string;
|
|
23
23
|
avatarUrl?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The sender's time zone on the platform, an IANA name (`Asia/Shanghai`; Slack `users.info`
|
|
26
|
+
* `user.tz`), when the platform gives one. Include it on `message` events when you can get it
|
|
27
|
+
* within the acknowledgement deadline (cache it per user); leave it out otherwise. It wins over
|
|
28
|
+
* the person's account setting and the org default for the run's date and zone (run context
|
|
29
|
+
* spec §3.4); a name the kernel does not know is ignored.
|
|
30
|
+
*/
|
|
31
|
+
timeZone?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The sender's language on the platform: `zh` / `en` or a BCP 47 tag (`zh-CN`, `en-US`; Slack
|
|
34
|
+
* `users.info` with `include_locale=true`, `user.locale`), when the platform gives one. The
|
|
35
|
+
* kernel normalizes it (`zh` and `zh-*` are Chinese, any other tag English); it wins over the
|
|
36
|
+
* person's latest web UI language and the org default (run context spec §3.4).
|
|
37
|
+
*/
|
|
38
|
+
locale?: string;
|
|
24
39
|
}
|
|
25
40
|
/**
|
|
26
41
|
* 渠道交给内核的入站事件。插件的约定:
|
|
@@ -76,7 +91,11 @@ export interface ChannelSendArgs {
|
|
|
76
91
|
*/
|
|
77
92
|
message: OutboundMessage;
|
|
78
93
|
signal: AbortSignal;
|
|
79
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* The recipient's language (the sender's platform language, else their latest web language,
|
|
96
|
+
* else the org's): the wording the extension renders itself (card buttons, fixed words in the
|
|
97
|
+
* text fallback) follows it.
|
|
98
|
+
*/
|
|
80
99
|
locale: Locale;
|
|
81
100
|
/**
|
|
82
101
|
* 幂等键(可选):不超过 40 个 `[A-Za-z0-9_-]` 字符,同一条逻辑消息的每次重试(崩溃后其他副本续投、
|
package/dist/connector-auth.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export declare const ConnectorAuthSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
50
50
|
client_secret_basic: "client_secret_basic";
|
|
51
51
|
client_secret_post: "client_secret_post";
|
|
52
52
|
}>>;
|
|
53
|
+
tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
53
54
|
}, z.core.$strict>, z.ZodObject<{
|
|
54
55
|
type: z.ZodLiteral<"oauth_client">;
|
|
55
56
|
ownership: z.ZodLiteral<"org">;
|
|
@@ -59,6 +60,7 @@ export declare const ConnectorAuthSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
59
60
|
client_secret_basic: "client_secret_basic";
|
|
60
61
|
client_secret_post: "client_secret_post";
|
|
61
62
|
}>>;
|
|
63
|
+
tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
62
64
|
}, z.core.$strict>], "type">;
|
|
63
65
|
/** 认证预设({@link ConnectorAuthSchema} 的输出)。 */
|
|
64
66
|
export type ConnectorAuthPreset = z.infer<typeof ConnectorAuthSchema>;
|
package/dist/connector-auth.js
CHANGED
|
@@ -23,6 +23,19 @@ const Scopes = z
|
|
|
23
23
|
.max(200)
|
|
24
24
|
.regex(/^[\x21\x23-\x5B\x5D-\x7E]+$/, "Invalid scope"))
|
|
25
25
|
.max(50);
|
|
26
|
+
/**
|
|
27
|
+
* More `token_type` values the token endpoint may return for a bearer token (case-insensitive;
|
|
28
|
+
* `Bearer` and Slack's `user` are always accepted). The token is still sent as
|
|
29
|
+
* `Authorization: Bearer`. Never `DPoP`: such a token is bound to a key the kernel does not hold.
|
|
30
|
+
*/
|
|
31
|
+
const TokenTypes = z
|
|
32
|
+
.array(z
|
|
33
|
+
.string()
|
|
34
|
+
.min(1)
|
|
35
|
+
.max(32)
|
|
36
|
+
.regex(/^[A-Za-z][A-Za-z0-9_.-]*$/, "Invalid token type")
|
|
37
|
+
.refine((t) => t.toLowerCase() !== "dpop", "DPoP tokens are not bearer tokens"))
|
|
38
|
+
.max(5);
|
|
26
39
|
/** 认证方式:只有类型与非密钥字段;凭据值走内核的 `credential` / 凭据接口。 */
|
|
27
40
|
export const ConnectorAuthSchema = z.discriminatedUnion("type", [
|
|
28
41
|
z.object({ type: z.literal("none") }).strict(),
|
|
@@ -57,6 +70,7 @@ export const ConnectorAuthSchema = z.discriminatedUnion("type", [
|
|
|
57
70
|
scopes: Scopes.optional(),
|
|
58
71
|
client: z.enum(["dcr", "manual"]),
|
|
59
72
|
tokenAuthMethod: TokenAuthMethod.optional(),
|
|
73
|
+
tokenTypes: TokenTypes.optional(),
|
|
60
74
|
})
|
|
61
75
|
.strict()
|
|
62
76
|
.superRefine((a, ctx) => {
|
|
@@ -91,6 +105,7 @@ export const ConnectorAuthSchema = z.discriminatedUnion("type", [
|
|
|
91
105
|
tokenUrl: OAuthUrl,
|
|
92
106
|
scopes: Scopes.optional(),
|
|
93
107
|
tokenAuthMethod: TokenAuthMethod.optional(),
|
|
108
|
+
tokenTypes: TokenTypes.optional(),
|
|
94
109
|
})
|
|
95
110
|
.strict(),
|
|
96
111
|
]);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.1.0-rc.
|
|
1
|
+
export declare const SDK_VERSION = "0.1.0-rc.8";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
@@ -23,9 +23,14 @@ export * from "./plugin-manifest.js";
|
|
|
23
23
|
export * from "./plugin-package.js";
|
|
24
24
|
export * from "./sandbox.js";
|
|
25
25
|
export * from "./secret.js";
|
|
26
|
+
export * from "./setup-guide.js";
|
|
26
27
|
export * from "./skill.js";
|
|
27
28
|
export * from "./skill-invocation.js";
|
|
28
29
|
export * from "./storage.js";
|
|
30
|
+
export * from "./theme.js";
|
|
31
|
+
export * from "./theme-assets.js";
|
|
32
|
+
export * from "./theme-readability.js";
|
|
33
|
+
export * from "./theme-tokens.generated.js";
|
|
29
34
|
export * from "./tool.js";
|
|
30
35
|
export * from "./tool-key.js";
|
|
31
36
|
export * from "./ui.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.1.0-rc.
|
|
1
|
+
export const SDK_VERSION = "0.1.0-rc.8";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
@@ -23,9 +23,14 @@ export * from "./plugin-manifest.js";
|
|
|
23
23
|
export * from "./plugin-package.js";
|
|
24
24
|
export * from "./sandbox.js";
|
|
25
25
|
export * from "./secret.js";
|
|
26
|
+
export * from "./setup-guide.js";
|
|
26
27
|
export * from "./skill.js";
|
|
27
28
|
export * from "./skill-invocation.js";
|
|
28
29
|
export * from "./storage.js";
|
|
30
|
+
export * from "./theme.js";
|
|
31
|
+
export * from "./theme-assets.js";
|
|
32
|
+
export * from "./theme-readability.js";
|
|
33
|
+
export * from "./theme-tokens.generated.js";
|
|
29
34
|
export * from "./tool.js";
|
|
30
35
|
export * from "./tool-key.js";
|
|
31
36
|
export * from "./ui.js";
|
package/dist/marketplace.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export declare const MARKETPLACE_LIMITS: {
|
|
|
28
28
|
readonly plugins: 5000;
|
|
29
29
|
readonly permissionKeys: 500;
|
|
30
30
|
readonly urlChars: 2000;
|
|
31
|
+
/** Bytes of an entry icon (the plugin icon limit, {@link CONNECTOR_TEMPLATE_LIMITS}). */
|
|
32
|
+
readonly iconBytes: number;
|
|
31
33
|
};
|
|
32
34
|
/** Where a marketplace entry's plugin comes from. */
|
|
33
35
|
export type MarketplaceSource = {
|
|
@@ -75,6 +77,18 @@ export interface MarketplaceEntry {
|
|
|
75
77
|
};
|
|
76
78
|
/** https URL. */
|
|
77
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;
|
|
78
92
|
/**
|
|
79
93
|
* This version is deprecated (`true`, or with a reason shown to admins): browsing lists it under
|
|
80
94
|
* the plugin's other versions, never as the one to import, and the kernel refuses importing it
|
|
@@ -103,6 +117,8 @@ export interface MarketplaceParseOptions {
|
|
|
103
117
|
/** Tests only: allow http on loopback addresses for `git` / `archive` URLs. */
|
|
104
118
|
allowInsecureLoopback?: boolean;
|
|
105
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;
|
|
106
122
|
/**
|
|
107
123
|
* The zod schema of `marketplace.json` (https only; non-strict: unknown fields dropped). The JSON
|
|
108
124
|
* Schema is generated with `z.toJSONSchema(MarketplaceManifestSchema, { io: "input" })`.
|
|
@@ -117,6 +133,16 @@ export declare function parseMarketplaceManifest(json: unknown, opts?: Marketpla
|
|
|
117
133
|
};
|
|
118
134
|
/** The entry's version: `version`, else the npm source's version, else `null` (the plugin's own). */
|
|
119
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;
|
|
120
146
|
/**
|
|
121
147
|
* The entry's deprecation (see {@link MarketplaceEntry.deprecated}): `null` when it is not
|
|
122
148
|
* deprecated (absent or `false`), else its reason (`null` without one).
|
package/dist/marketplace.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
5
|
* each with one source. One entry is one version. `capybara-plugin marketplace --write` lists one
|
|
@@ -29,6 +29,8 @@ export const MARKETPLACE_LIMITS = {
|
|
|
29
29
|
plugins: 5000,
|
|
30
30
|
permissionKeys: 500,
|
|
31
31
|
urlChars: 2000,
|
|
32
|
+
/** Bytes of an entry icon (the plugin icon limit, {@link CONNECTOR_TEMPLATE_LIMITS}). */
|
|
33
|
+
iconBytes: CONNECTOR_TEMPLATE_LIMITS.iconBytes,
|
|
32
34
|
};
|
|
33
35
|
const M = MARKETPLACE_LIMITS;
|
|
34
36
|
const MAX_ERRORS = 50;
|
|
@@ -37,6 +39,13 @@ const PERMISSION_KEY_RE = /^[a-z][a-z.]{0,62}(?::[^\r\n]{1,256})?$/;
|
|
|
37
39
|
const SHA256_INTEGRITY_RE = /^sha256-[A-Za-z0-9+/]{43}=$/;
|
|
38
40
|
const COMMIT_RE = /^[0-9a-f]{40}$/;
|
|
39
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}$`);
|
|
40
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*)?)$/;
|
|
41
50
|
const urlString = (re) => z
|
|
42
51
|
.string()
|
|
@@ -55,6 +64,15 @@ const exactVersion = (what) => z
|
|
|
55
64
|
.string()
|
|
56
65
|
.max(256)
|
|
57
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
|
+
};
|
|
58
76
|
/** `./<safe path>` inside the marketplace repo. */
|
|
59
77
|
const repoPath = z
|
|
60
78
|
.string()
|
|
@@ -144,6 +162,12 @@ function buildSchema(opts) {
|
|
|
144
162
|
})
|
|
145
163
|
.optional(),
|
|
146
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(),
|
|
147
171
|
deprecated: z
|
|
148
172
|
.union([
|
|
149
173
|
z.boolean(),
|
|
@@ -248,6 +272,14 @@ const SOURCE_FORMS = ["path", "git", "npm", "archive"];
|
|
|
248
272
|
* form the source uses instead, or that it must use exactly one form.
|
|
249
273
|
*/
|
|
250
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
|
+
}
|
|
251
283
|
if (issue.code !== "invalid_union" || issue.path[issue.path.length - 1] !== "source") {
|
|
252
284
|
return [issue];
|
|
253
285
|
}
|
|
@@ -272,6 +304,16 @@ export function marketplaceEntryVersion(e) {
|
|
|
272
304
|
return e.source.npm.version;
|
|
273
305
|
return null;
|
|
274
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
|
+
}
|
|
275
317
|
/**
|
|
276
318
|
* The entry's deprecation (see {@link MarketplaceEntry.deprecated}): `null` when it is not
|
|
277
319
|
* deprecated (absent or `false`), else its reason (`null` without one).
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { type JsonSchema } from "./config-ui.js";
|
|
3
3
|
import { type ConnectorTemplateSpec, type LocalizedName, type StaticExtensionManifest } from "./plugin-package.js";
|
|
4
|
+
import { type PluginSetupGuide } from "./setup-guide.js";
|
|
5
|
+
import { type PluginThemeRef } from "./theme.js";
|
|
4
6
|
/**
|
|
5
7
|
* The plugin manifest `.capybara-plugin/plugin.json` (package ecosystem spec §4.1). A plugin is a
|
|
6
|
-
* bundle of at most one extension, skills
|
|
8
|
+
* bundle of at most one extension, skills, connector templates, agent templates and themes, packed as
|
|
9
|
+
* an npm-pack tgz:
|
|
7
10
|
*
|
|
8
11
|
* ```
|
|
9
12
|
* package/package.json npm metadata; version equals plugin.json version
|
|
@@ -11,13 +14,14 @@ import { type ConnectorTemplateSpec, type LocalizedName, type StaticExtensionMan
|
|
|
11
14
|
* package/skills/<name>/SKILL.md skills
|
|
12
15
|
* package/connectors/<id>.json connector templates ({@link ConnectorTemplateFile})
|
|
13
16
|
* package/agents/<name>.md agent templates (parsed by `parseAgentTemplate`)
|
|
17
|
+
* package/themes/<id>.json themes (parsed by `parseThemeFile`)
|
|
14
18
|
* package/dist/index.mjs extension entry (only with an extension)
|
|
15
19
|
* package/migrations/*.sql, package/ui/**
|
|
16
20
|
* ```
|
|
17
21
|
*
|
|
18
22
|
* Paths start with `./` and stay inside the plugin root. Omitting `skills` / `connectorTemplates`
|
|
19
|
-
* / `agents` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md`
|
|
20
|
-
* kernel when it reads the package). `extension` is written by the packer, never by hand.
|
|
23
|
+
* / `agents` / `themes` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md` /
|
|
24
|
+
* `themes/*.json`" (done by the kernel when it reads the package). `extension` is written by the packer, never by hand.
|
|
21
25
|
*
|
|
22
26
|
* The committed JSON Schema (`schemas/plugin.v1.schema.json`) is generated from
|
|
23
27
|
* {@link PluginManifestSchema} by `pnpm gen:package-schemas` and drift-checked by
|
|
@@ -39,6 +43,8 @@ export declare const PLUGIN_MANIFEST_LIMITS: {
|
|
|
39
43
|
readonly connectorTemplates: 20;
|
|
40
44
|
/** Agent templates ({@link AGENT_TEMPLATE_LIMITS}`.perPlugin`). */
|
|
41
45
|
readonly agents: 64;
|
|
46
|
+
/** Themes ({@link THEME_LIMITS}`.perPlugin`). */
|
|
47
|
+
readonly themes: 10;
|
|
42
48
|
readonly descriptionChars: 1024;
|
|
43
49
|
readonly publisherChars: 100;
|
|
44
50
|
readonly displayNameChars: 100;
|
|
@@ -123,6 +129,13 @@ export interface PluginManifest {
|
|
|
123
129
|
connectorTemplates?: PluginConnectorTemplateRef[];
|
|
124
130
|
/** Agent templates; omitted = scan `agents/*.md`. */
|
|
125
131
|
agents?: PluginAgentRef[];
|
|
132
|
+
/** Themes; omitted = scan `themes/*.json`. */
|
|
133
|
+
themes?: PluginThemeRef[];
|
|
134
|
+
/**
|
|
135
|
+
* Setup guides (spec `2026-11-08-plugin-setup-guides-design.md`): steps and template files the
|
|
136
|
+
* kernel renders for a place (`channel-connection`); see {@link PluginSetupGuide}.
|
|
137
|
+
*/
|
|
138
|
+
setupGuides?: PluginSetupGuide[];
|
|
126
139
|
extension?: PluginExtensionSection;
|
|
127
140
|
}
|
|
128
141
|
/** A connector template file `connectors/<id>.json`; the template id is the file's base name. */
|
|
@@ -131,6 +144,12 @@ export interface ConnectorTemplateFile {
|
|
|
131
144
|
description?: string;
|
|
132
145
|
/** Safe path relative to the plugin root (an optional leading `./`), .svg / .png. */
|
|
133
146
|
icon?: string;
|
|
147
|
+
/**
|
|
148
|
+
* `false`: the template starts switched off in every org, even where its plugin is on, until an
|
|
149
|
+
* org admin switches it on (it then needs no org input while off). Default `true`: on wherever
|
|
150
|
+
* its plugin is. Ignored for a builtin plugin.
|
|
151
|
+
*/
|
|
152
|
+
defaultEnabled?: boolean;
|
|
134
153
|
/** Validated by {@link validateConnectorTemplate}. */
|
|
135
154
|
template: ConnectorTemplateSpec;
|
|
136
155
|
}
|
package/dist/plugin-manifest.js
CHANGED
|
@@ -5,9 +5,12 @@ import { CONFIG_UI_LIMITS } from "./config-ui.js";
|
|
|
5
5
|
import { defineExtension, EXTENSION_NAME_RE } from "./define-extension.js";
|
|
6
6
|
import { CATALOG_ITEM_NAME_RE, CONNECTOR_TEMPLATE_LIMITS, isSafePackagePath, SEMVER_VERSION_RE, validateConnectorTemplate, } from "./plugin-package.js";
|
|
7
7
|
import { hasUpperBound } from "./semver-range.js";
|
|
8
|
+
import { SETUP_GUIDE_FILE_RE, SETUP_GUIDE_LANGUAGES, SETUP_GUIDE_LIMITS, SETUP_GUIDE_MODES, SETUP_GUIDE_PLACES, } from "./setup-guide.js";
|
|
9
|
+
import { THEME_LIMITS, themeIdOf } from "./theme.js";
|
|
8
10
|
/**
|
|
9
11
|
* The plugin manifest `.capybara-plugin/plugin.json` (package ecosystem spec §4.1). A plugin is a
|
|
10
|
-
* bundle of at most one extension, skills
|
|
12
|
+
* bundle of at most one extension, skills, connector templates, agent templates and themes, packed as
|
|
13
|
+
* an npm-pack tgz:
|
|
11
14
|
*
|
|
12
15
|
* ```
|
|
13
16
|
* package/package.json npm metadata; version equals plugin.json version
|
|
@@ -15,13 +18,14 @@ import { hasUpperBound } from "./semver-range.js";
|
|
|
15
18
|
* package/skills/<name>/SKILL.md skills
|
|
16
19
|
* package/connectors/<id>.json connector templates ({@link ConnectorTemplateFile})
|
|
17
20
|
* package/agents/<name>.md agent templates (parsed by `parseAgentTemplate`)
|
|
21
|
+
* package/themes/<id>.json themes (parsed by `parseThemeFile`)
|
|
18
22
|
* package/dist/index.mjs extension entry (only with an extension)
|
|
19
23
|
* package/migrations/*.sql, package/ui/**
|
|
20
24
|
* ```
|
|
21
25
|
*
|
|
22
26
|
* Paths start with `./` and stay inside the plugin root. Omitting `skills` / `connectorTemplates`
|
|
23
|
-
* / `agents` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md`
|
|
24
|
-
* kernel when it reads the package). `extension` is written by the packer, never by hand.
|
|
27
|
+
* / `agents` / `themes` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md` /
|
|
28
|
+
* `themes/*.json`" (done by the kernel when it reads the package). `extension` is written by the packer, never by hand.
|
|
25
29
|
*
|
|
26
30
|
* The committed JSON Schema (`schemas/plugin.v1.schema.json`) is generated from
|
|
27
31
|
* {@link PluginManifestSchema} by `pnpm gen:package-schemas` and drift-checked by
|
|
@@ -43,6 +47,8 @@ export const PLUGIN_MANIFEST_LIMITS = {
|
|
|
43
47
|
connectorTemplates: 20,
|
|
44
48
|
/** Agent templates ({@link AGENT_TEMPLATE_LIMITS}`.perPlugin`). */
|
|
45
49
|
agents: AGENT_TEMPLATE_LIMITS.perPlugin,
|
|
50
|
+
/** Themes ({@link THEME_LIMITS}`.perPlugin`). */
|
|
51
|
+
themes: THEME_LIMITS.perPlugin,
|
|
46
52
|
descriptionChars: 1024,
|
|
47
53
|
publisherChars: 100,
|
|
48
54
|
displayNameChars: 100,
|
|
@@ -97,6 +103,33 @@ const configSchemaJson = z
|
|
|
97
103
|
.refine((v) => new TextEncoder().encode(JSON.stringify(v)).length <= CONFIG_UI_LIMITS.configSchemaBytes, {
|
|
98
104
|
message: `must be at most ${CONFIG_UI_LIMITS.configSchemaBytes} bytes of JSON (${CONFIG_UI_LIMITS.configSchemaBytes / 1024} KiB)`,
|
|
99
105
|
});
|
|
106
|
+
const guideText = (max, what) => z.strictObject({ en: text(max, `${what}.en`), zh: text(max, `${what}.zh`).optional() });
|
|
107
|
+
const setupGuide = z.strictObject({
|
|
108
|
+
id: z.string().regex(CATALOG_ITEM_NAME_RE, {
|
|
109
|
+
message: "id must match ^[a-z0-9][a-z0-9-]{0,63}$",
|
|
110
|
+
}),
|
|
111
|
+
place: z.enum(SETUP_GUIDE_PLACES),
|
|
112
|
+
title: guideText(SETUP_GUIDE_LIMITS.titleChars, "title"),
|
|
113
|
+
steps: z
|
|
114
|
+
.array(z.strictObject({
|
|
115
|
+
en: text(SETUP_GUIDE_LIMITS.stepChars, "en"),
|
|
116
|
+
zh: text(SETUP_GUIDE_LIMITS.stepChars, "zh").optional(),
|
|
117
|
+
mode: z.string().max(64).optional(),
|
|
118
|
+
}))
|
|
119
|
+
.max(SETUP_GUIDE_LIMITS.steps)
|
|
120
|
+
.optional(),
|
|
121
|
+
files: z
|
|
122
|
+
.array(z.strictObject({
|
|
123
|
+
path: dotPath("path").regex(SETUP_GUIDE_FILE_RE, {
|
|
124
|
+
message: "path must be a .tmpl, .yaml, .yml, .json or .txt file",
|
|
125
|
+
}),
|
|
126
|
+
title: guideText(SETUP_GUIDE_LIMITS.titleChars, "title"),
|
|
127
|
+
language: z.enum(SETUP_GUIDE_LANGUAGES),
|
|
128
|
+
mode: z.string().max(64).optional(),
|
|
129
|
+
}))
|
|
130
|
+
.max(SETUP_GUIDE_LIMITS.files)
|
|
131
|
+
.optional(),
|
|
132
|
+
});
|
|
100
133
|
const extensionSection = z.strictObject({
|
|
101
134
|
entry: dotPath("entry").refine((p) => p.endsWith(".mjs"), {
|
|
102
135
|
message: "entry must be a .mjs file",
|
|
@@ -168,6 +201,13 @@ const schema = z
|
|
|
168
201
|
}))
|
|
169
202
|
.max(L.agents)
|
|
170
203
|
.optional(),
|
|
204
|
+
themes: z
|
|
205
|
+
.array(z.strictObject({
|
|
206
|
+
path: dotPath("path").refine((p) => p.endsWith(".json") && CATALOG_ITEM_NAME_RE.test(themeIdOf(p)), { message: "path must be a <id>.json file with id matching ^[a-z0-9][a-z0-9-]{0,63}$" }),
|
|
207
|
+
}))
|
|
208
|
+
.max(L.themes)
|
|
209
|
+
.optional(),
|
|
210
|
+
setupGuides: z.array(setupGuide).max(SETUP_GUIDE_LIMITS.guides).optional(),
|
|
171
211
|
extension: extensionSection.optional(),
|
|
172
212
|
})
|
|
173
213
|
.superRefine((m, ctx) => {
|
|
@@ -206,11 +246,50 @@ const schema = z
|
|
|
206
246
|
issue(["agents", i, "path"], `duplicate agent template path ${a.path}`);
|
|
207
247
|
agentPaths.add(a.path);
|
|
208
248
|
});
|
|
249
|
+
const themeIds = new Set();
|
|
250
|
+
m.themes?.forEach((t, i) => {
|
|
251
|
+
const id = themeIdOf(t.path);
|
|
252
|
+
if (themeIds.has(id))
|
|
253
|
+
issue(["themes", i, "path"], `duplicate theme id ${id}`);
|
|
254
|
+
themeIds.add(id);
|
|
255
|
+
});
|
|
256
|
+
const guideIds = new Set();
|
|
257
|
+
m.setupGuides?.forEach((g, i) => {
|
|
258
|
+
if (guideIds.has(g.id))
|
|
259
|
+
issue(["setupGuides", i, "id"], `duplicate setup guide id ${g.id}`);
|
|
260
|
+
guideIds.add(g.id);
|
|
261
|
+
if ((g.steps?.length ?? 0) === 0 && (g.files?.length ?? 0) === 0) {
|
|
262
|
+
issue(["setupGuides", i], "a setup guide needs at least one step or file");
|
|
263
|
+
}
|
|
264
|
+
const modes = SETUP_GUIDE_MODES[g.place];
|
|
265
|
+
const badMode = (mode, path) => {
|
|
266
|
+
if (mode !== undefined && !modes.includes(mode)) {
|
|
267
|
+
issue(path, `mode must be one of ${modes.join(", ")} for place ${g.place}`);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
g.steps?.forEach((s, j) => {
|
|
271
|
+
badMode(s.mode, ["setupGuides", i, "steps", j, "mode"]);
|
|
272
|
+
});
|
|
273
|
+
const paths = new Set();
|
|
274
|
+
g.files?.forEach((f, j) => {
|
|
275
|
+
badMode(f.mode, ["setupGuides", i, "files", j, "mode"]);
|
|
276
|
+
if (paths.has(f.path)) {
|
|
277
|
+
issue(["setupGuides", i, "files", j, "path"], `duplicate file ${f.path} in the guide`);
|
|
278
|
+
}
|
|
279
|
+
paths.add(f.path);
|
|
280
|
+
});
|
|
281
|
+
if (g.place === "channel-connection" &&
|
|
282
|
+
m.extension !== undefined &&
|
|
283
|
+
!m.extension.manifest.provides.some((p) => p.startsWith("channel@"))) {
|
|
284
|
+
issue(["setupGuides", i, "place"], "a channel-connection guide needs the plugin's extension to provide channel@1");
|
|
285
|
+
}
|
|
286
|
+
});
|
|
209
287
|
if (m.extension === undefined &&
|
|
210
288
|
m.skills?.length === 0 &&
|
|
211
289
|
m.connectorTemplates?.length === 0 &&
|
|
212
|
-
(m.agents === undefined || m.agents.length === 0)
|
|
213
|
-
|
|
290
|
+
(m.agents === undefined || m.agents.length === 0) &&
|
|
291
|
+
(m.themes === undefined || m.themes.length === 0)) {
|
|
292
|
+
issue([], "a plugin must contain an extension, a skill, a connector template, an agent template or a theme");
|
|
214
293
|
}
|
|
215
294
|
const ext = m.extension;
|
|
216
295
|
if (ext === undefined)
|
|
@@ -281,6 +360,7 @@ const templateFile = z
|
|
|
281
360
|
message: "icon must be a relative .svg or .png path inside the plugin",
|
|
282
361
|
})
|
|
283
362
|
.optional(),
|
|
363
|
+
defaultEnabled: z.boolean().optional(),
|
|
284
364
|
template,
|
|
285
365
|
})
|
|
286
366
|
// Field rules (no credentials, auth presets, editableEndpoint, ...) belong to validateConnectorTemplate.
|