@capybara-hq/plugin-sdk 0.1.0-rc.20 → 0.1.0-rc.21
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/dist/git-hosts.d.ts +44 -0
- package/dist/git-hosts.js +81 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/plugin-manifest.js +2 -0
- package/dist/plugin-package.d.ts +3 -0
- package/dist/plugin-package.js +4 -0
- package/package.json +1 -1
- package/schemas/connector-template.v1.schema.json +32 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The git source of a connector: the git hosts a connector's credential may be used for, and the
|
|
4
|
+
* HTTP basic username to present for each (spec 2026-11-12-sandbox-git-credentials §6.1). Pure
|
|
5
|
+
* validation; the kernel reuses {@link GitSourceSchema} for its connector create body.
|
|
6
|
+
*/
|
|
7
|
+
/** Limits of {@link GitSourceSchema}. */
|
|
8
|
+
export declare const GIT_HOSTS_LIMITS: {
|
|
9
|
+
/** Hosts per connector. */
|
|
10
|
+
readonly hosts: 8;
|
|
11
|
+
/** Characters of a username. */
|
|
12
|
+
readonly usernameChars: 64;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The basic-auth usernames of well-known git hosts: a GitHub token (a PAT or an app installation
|
|
16
|
+
* token) is presented with the fixed username `x-access-token`. Documentation for template authors;
|
|
17
|
+
* a connector still states its username explicitly.
|
|
18
|
+
*/
|
|
19
|
+
export declare const GIT_HOST_USERNAMES: {
|
|
20
|
+
readonly "github.com": "x-access-token";
|
|
21
|
+
readonly "*.ghe.com": "x-access-token";
|
|
22
|
+
};
|
|
23
|
+
/** One git host and the username its credential is presented with. */
|
|
24
|
+
export interface GitHostEntry {
|
|
25
|
+
/** Lower-case hostname with no scheme, port, path, wildcard or userinfo. */
|
|
26
|
+
host: string;
|
|
27
|
+
/** HTTP basic username, `^[A-Za-z0-9._-]{1,64}$`. */
|
|
28
|
+
username: string;
|
|
29
|
+
}
|
|
30
|
+
/** The git source of a connector (`git` on a connector template and on a custom connector). */
|
|
31
|
+
export interface GitSource {
|
|
32
|
+
hosts: GitHostEntry[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The zod schema of {@link GitSource} (strict objects, 1 to {@link GIT_HOSTS_LIMITS}`.hosts` hosts,
|
|
36
|
+
* no duplicate host). Error messages never echo the offending value.
|
|
37
|
+
*/
|
|
38
|
+
export declare const GitSourceSchema: z.ZodType<GitSource>;
|
|
39
|
+
/** Validates a `git` value; returns problems as `<path>: <message>` (empty means valid). */
|
|
40
|
+
export declare function validateGitSource(git: unknown, at?: string): string[];
|
|
41
|
+
/** Parses a `git` value: the value, or `{ errors }`. */
|
|
42
|
+
export declare function parseGitSource(git: unknown): GitSource | {
|
|
43
|
+
errors: string[];
|
|
44
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { validateAllowHost } from "./sandbox.js";
|
|
3
|
+
/**
|
|
4
|
+
* The git source of a connector: the git hosts a connector's credential may be used for, and the
|
|
5
|
+
* HTTP basic username to present for each (spec 2026-11-12-sandbox-git-credentials §6.1). Pure
|
|
6
|
+
* validation; the kernel reuses {@link GitSourceSchema} for its connector create body.
|
|
7
|
+
*/
|
|
8
|
+
/** Limits of {@link GitSourceSchema}. */
|
|
9
|
+
export const GIT_HOSTS_LIMITS = {
|
|
10
|
+
/** Hosts per connector. */
|
|
11
|
+
hosts: 8,
|
|
12
|
+
/** Characters of a username. */
|
|
13
|
+
usernameChars: 64,
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The basic-auth usernames of well-known git hosts: a GitHub token (a PAT or an app installation
|
|
17
|
+
* token) is presented with the fixed username `x-access-token`. Documentation for template authors;
|
|
18
|
+
* a connector still states its username explicitly.
|
|
19
|
+
*/
|
|
20
|
+
export const GIT_HOST_USERNAMES = {
|
|
21
|
+
"github.com": "x-access-token",
|
|
22
|
+
"*.ghe.com": "x-access-token",
|
|
23
|
+
};
|
|
24
|
+
const USERNAME_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
25
|
+
/** Why a host is refused; never echoes the value (it may be a pasted credential or URL). */
|
|
26
|
+
function hostProblems(h) {
|
|
27
|
+
if (/[@:/?#\s]/.test(h))
|
|
28
|
+
return ["host must be a bare hostname (no userinfo, port or path)"];
|
|
29
|
+
if (h.includes("*"))
|
|
30
|
+
return ["host must not contain a wildcard"];
|
|
31
|
+
if (h !== h.toLowerCase())
|
|
32
|
+
return ["host must be lower-case"];
|
|
33
|
+
return validateAllowHost(h);
|
|
34
|
+
}
|
|
35
|
+
const GitHostEntrySchema = z.strictObject({
|
|
36
|
+
host: z
|
|
37
|
+
.string()
|
|
38
|
+
.max(253, "host must be at most 253 characters")
|
|
39
|
+
.superRefine((h, ctx) => {
|
|
40
|
+
for (const message of hostProblems(h))
|
|
41
|
+
ctx.addIssue({ code: "custom", message });
|
|
42
|
+
}),
|
|
43
|
+
username: z
|
|
44
|
+
.string()
|
|
45
|
+
.regex(USERNAME_RE, "username must match ^[A-Za-z0-9._-]{1,64}$ (letters, digits, '.', '_', '-')"),
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* The zod schema of {@link GitSource} (strict objects, 1 to {@link GIT_HOSTS_LIMITS}`.hosts` hosts,
|
|
49
|
+
* no duplicate host). Error messages never echo the offending value.
|
|
50
|
+
*/
|
|
51
|
+
export const GitSourceSchema = z
|
|
52
|
+
.strictObject({
|
|
53
|
+
hosts: z
|
|
54
|
+
.array(GitHostEntrySchema)
|
|
55
|
+
.min(1, "hosts must not be empty")
|
|
56
|
+
.max(GIT_HOSTS_LIMITS.hosts),
|
|
57
|
+
})
|
|
58
|
+
.superRefine((g, ctx) => {
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
g.hosts.forEach((e, i) => {
|
|
61
|
+
if (seen.has(e.host)) {
|
|
62
|
+
ctx.addIssue({ code: "custom", path: ["hosts", i, "host"], message: "duplicate host" });
|
|
63
|
+
}
|
|
64
|
+
seen.add(e.host);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
/** Validates a `git` value; returns problems as `<path>: <message>` (empty means valid). */
|
|
68
|
+
export function validateGitSource(git, at = "git") {
|
|
69
|
+
const r = GitSourceSchema.safeParse(git);
|
|
70
|
+
if (r.success)
|
|
71
|
+
return [];
|
|
72
|
+
return r.error.issues.map((i) => {
|
|
73
|
+
const path = i.path.map(String).join(".");
|
|
74
|
+
return `${path === "" ? at : `${at}.${path}`}: ${i.message}`;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** Parses a `git` value: the value, or `{ errors }`. */
|
|
78
|
+
export function parseGitSource(git) {
|
|
79
|
+
const errors = validateGitSource(git);
|
|
80
|
+
return errors.length > 0 ? { errors } : GitSourceSchema.parse(git);
|
|
81
|
+
}
|
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.21";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
@@ -16,6 +16,7 @@ export * from "./device-protocol.js";
|
|
|
16
16
|
export * from "./directory.js";
|
|
17
17
|
export * from "./extension-point.js";
|
|
18
18
|
export * from "./file-preview.js";
|
|
19
|
+
export * from "./git-hosts.js";
|
|
19
20
|
export * from "./hooks.js";
|
|
20
21
|
export * from "./identity.js";
|
|
21
22
|
export * from "./marketplace.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.21";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
@@ -16,6 +16,7 @@ export * from "./device-protocol.js";
|
|
|
16
16
|
export * from "./directory.js";
|
|
17
17
|
export * from "./extension-point.js";
|
|
18
18
|
export * from "./file-preview.js";
|
|
19
|
+
export * from "./git-hosts.js";
|
|
19
20
|
export * from "./hooks.js";
|
|
20
21
|
export * from "./identity.js";
|
|
21
22
|
export * from "./marketplace.js";
|
package/dist/plugin-manifest.js
CHANGED
|
@@ -4,6 +4,7 @@ import { AGENT_TEMPLATE_LIMITS } from "./agent-template.js";
|
|
|
4
4
|
import { validateClientSection } from "./client-section.js";
|
|
5
5
|
import { CONFIG_UI_LIMITS } from "./config-ui.js";
|
|
6
6
|
import { defineExtension, EXTENSION_NAME_RE } from "./define-extension.js";
|
|
7
|
+
import { GitSourceSchema } from "./git-hosts.js";
|
|
7
8
|
import { CATALOG_ITEM_NAME_RE, CONNECTOR_TEMPLATE_LIMITS, isSafePackagePath, SEMVER_VERSION_RE, validateConnectorTemplate, } from "./plugin-package.js";
|
|
8
9
|
import { hasUpperBound } from "./semver-range.js";
|
|
9
10
|
import { SETUP_GUIDE_LIMITS, SETUP_GUIDE_PLACES } from "./setup-guide.js";
|
|
@@ -418,6 +419,7 @@ const template = z.strictObject({
|
|
|
418
419
|
auth: z.record(z.string(), z.unknown()),
|
|
419
420
|
ownership: z.enum(["org", "personal"]).optional(),
|
|
420
421
|
defaultToolPolicies: z.record(z.string(), z.enum(["allow", "ask", "deny"])).optional(),
|
|
422
|
+
git: GitSourceSchema.optional(),
|
|
421
423
|
icon: z.string().max(L.pathChars).optional(),
|
|
422
424
|
});
|
|
423
425
|
const templateFile = z
|
package/dist/plugin-package.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ExtensionManifest } from "./define-extension.js";
|
|
2
|
+
import { type GitSource } from "./git-hosts.js";
|
|
2
3
|
import type { ExtensionPermissions } from "./permissions.js";
|
|
3
4
|
import type { PluginManifest } from "./plugin-manifest.js";
|
|
4
5
|
/**
|
|
@@ -98,6 +99,8 @@ export interface ConnectorTemplateSpec {
|
|
|
98
99
|
ownership?: "org" | "personal";
|
|
99
100
|
/** 工具名 → 默认策略(安装后记 `policy_source 'template'`)。 */
|
|
100
101
|
defaultToolPolicies?: Record<string, "allow" | "ask" | "deny">;
|
|
102
|
+
/** Git hosts this connector's credential serves in sandboxes ({@link GitSource}). */
|
|
103
|
+
git?: GitSource;
|
|
101
104
|
/** 包内路径,svg / png,≤ {@link CONNECTOR_TEMPLATE_LIMITS}`.iconBytes`。 */
|
|
102
105
|
icon?: string;
|
|
103
106
|
}
|
package/dist/plugin-package.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import semver from "semver";
|
|
2
2
|
import { ConnectorAuthSchema } from "./connector-auth.js";
|
|
3
3
|
import { EXTENSION_NAME_RE } from "./define-extension.js";
|
|
4
|
+
import { validateGitSource } from "./git-hosts.js";
|
|
4
5
|
/**
|
|
5
6
|
* Plugin package (npm-pack tgz) rules shared by the SDK, the packer and the kernel (spec §4.1). Pure
|
|
6
7
|
* functions only: the kernel reads the tgz and scans imports, `packages/plugin-tools` packs it. The
|
|
@@ -333,6 +334,7 @@ const TEMPLATE_KEYS = new Set([
|
|
|
333
334
|
"auth",
|
|
334
335
|
"ownership",
|
|
335
336
|
"defaultToolPolicies",
|
|
337
|
+
"git",
|
|
336
338
|
"icon",
|
|
337
339
|
]);
|
|
338
340
|
/**
|
|
@@ -439,6 +441,8 @@ export function validateConnectorTemplate(t) {
|
|
|
439
441
|
}
|
|
440
442
|
}
|
|
441
443
|
}
|
|
444
|
+
if (t.git !== undefined)
|
|
445
|
+
errs.push(...validateGitSource(t.git, "template.git"));
|
|
442
446
|
if (t.icon !== undefined) {
|
|
443
447
|
if (typeof t.icon !== "string" || !isSafePackagePath(t.icon) || !/\.(svg|png)$/i.test(t.icon)) {
|
|
444
448
|
errs.push("template.icon must be a relative .svg or .png path inside the package");
|
package/package.json
CHANGED
|
@@ -97,6 +97,38 @@
|
|
|
97
97
|
]
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
|
+
"git": {
|
|
101
|
+
"type": "object",
|
|
102
|
+
"properties": {
|
|
103
|
+
"hosts": {
|
|
104
|
+
"minItems": 1,
|
|
105
|
+
"maxItems": 8,
|
|
106
|
+
"type": "array",
|
|
107
|
+
"items": {
|
|
108
|
+
"type": "object",
|
|
109
|
+
"properties": {
|
|
110
|
+
"host": {
|
|
111
|
+
"type": "string",
|
|
112
|
+
"maxLength": 253
|
|
113
|
+
},
|
|
114
|
+
"username": {
|
|
115
|
+
"type": "string",
|
|
116
|
+
"pattern": "^[A-Za-z0-9._-]{1,64}$"
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"required": [
|
|
120
|
+
"host",
|
|
121
|
+
"username"
|
|
122
|
+
],
|
|
123
|
+
"additionalProperties": false
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
"required": [
|
|
128
|
+
"hosts"
|
|
129
|
+
],
|
|
130
|
+
"additionalProperties": false
|
|
131
|
+
},
|
|
100
132
|
"icon": {
|
|
101
133
|
"type": "string",
|
|
102
134
|
"maxLength": 512
|