@capybara-hq/testing 0.1.0-rc.4 → 0.1.0-rc.41
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/containers.d.ts +7 -2
- package/dist/containers.js +7 -3
- package/dist/device-service-conformance.d.ts +38 -0
- package/dist/device-service-conformance.js +142 -0
- package/dist/dual-replica.d.ts +23 -1
- package/dist/dual-replica.js +53 -0
- package/dist/fake-channel.d.ts +44 -5
- package/dist/fake-channel.js +63 -2
- package/dist/fake-dial-in-machine.d.ts +173 -0
- package/dist/fake-dial-in-machine.js +429 -0
- package/dist/fake-e2b.d.ts +34 -0
- package/dist/fake-e2b.js +95 -1
- package/dist/fake-git-server.d.ts +32 -4
- package/dist/fake-git-server.js +87 -19
- package/dist/fake-lark.d.ts +12 -1
- package/dist/fake-lark.js +63 -10
- package/dist/fake-oauth-server.d.ts +62 -2
- package/dist/fake-oauth-server.js +86 -5
- package/dist/fake-slack.d.ts +17 -1
- package/dist/fake-slack.js +98 -0
- package/dist/fake-telegram.d.ts +173 -0
- package/dist/fake-telegram.js +632 -0
- package/dist/fixtures.d.ts +24 -8
- package/dist/fixtures.js +31 -8
- package/dist/index.d.ts +15 -9
- package/dist/index.js +10 -4
- package/dist/kernel-helpers.d.ts +16 -4
- package/dist/kernel-helpers.js +39 -4
- package/dist/media-samples.d.ts +2 -0
- package/dist/media-samples.js +2 -0
- package/dist/model-conformance.d.ts +15 -10
- package/dist/model-conformance.js +87 -14
- package/dist/push-conformance.d.ts +31 -0
- package/dist/push-conformance.js +160 -0
- package/dist/replica-runner.js +2 -0
- package/dist/sandbox-native-conformance.d.ts +31 -0
- package/dist/sandbox-native-conformance.js +153 -0
- package/dist/sandbox-permission-conformance.d.ts +310 -0
- package/dist/sandbox-permission-conformance.js +1491 -0
- package/fixtures/extensions/fake-bootstrap-a/src/index.ts +8 -4
- package/fixtures/extensions/fake-bootstrap-b/src/index.ts +8 -4
- package/fixtures/extensions/fake-client/.capybara-plugin/plugin.json +11 -0
- package/fixtures/extensions/fake-client/client/styles/fake.css +11 -0
- package/fixtures/extensions/fake-client/package.json +12 -0
- package/fixtures/extensions/fake-client/src/client.tsx +51 -0
- package/fixtures/extensions/fake-client/src/index.ts +43 -0
- package/fixtures/extensions/fake-client/themes/fake.json +11 -0
- package/fixtures/extensions/fake-client-broken/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-client-broken/package.json +12 -0
- package/fixtures/extensions/fake-client-broken/src/client.tsx +22 -0
- package/fixtures/extensions/fake-client-broken/src/index.ts +27 -0
- package/fixtures/extensions/fake-config-form/src/index.ts +52 -46
- package/fixtures/extensions/fake-connector/src/index.ts +64 -34
- package/fixtures/extensions/fake-context/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-context/package.json +12 -0
- package/fixtures/extensions/fake-context/src/index.ts +78 -0
- package/fixtures/extensions/fake-dep-provider/src/index.ts +1 -1
- package/fixtures/extensions/fake-dep-requirer/src/index.ts +1 -1
- package/fixtures/extensions/fake-embed/src/index.ts +26 -26
- package/fixtures/extensions/fake-im/.capybara-plugin/plugin.json +7 -1
- package/fixtures/extensions/fake-im/guides/fake-im-app.md +32 -0
- package/fixtures/extensions/fake-im/guides/fake-im-app.zh.md +32 -0
- package/fixtures/extensions/fake-im/src/channel.ts +22 -1
- package/fixtures/extensions/fake-im/src/checks.ts +94 -0
- package/fixtures/extensions/fake-im/src/directory.ts +44 -20
- package/fixtures/extensions/fake-im/src/index.ts +59 -11
- package/fixtures/extensions/fake-lifecycle/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-lifecycle/migrations/0001_init.sql +16 -0
- package/fixtures/extensions/fake-lifecycle/package.json +12 -0
- package/fixtures/extensions/fake-lifecycle/src/index.ts +72 -0
- package/fixtures/extensions/fake-object-store/src/index.ts +12 -8
- package/fixtures/extensions/fake-openapi/src/index.ts +46 -34
- package/fixtures/extensions/fake-push/.capybara-plugin/plugin.json +13 -0
- package/fixtures/extensions/fake-push/guides/fake-push-key.md +6 -0
- package/fixtures/extensions/fake-push/guides/fake-push-key.zh.md +6 -0
- package/fixtures/extensions/fake-push/migrations/0001_sends.sql +9 -0
- package/fixtures/extensions/fake-push/package.json +12 -0
- package/fixtures/extensions/fake-push/src/check.ts +40 -0
- package/fixtures/extensions/fake-push/src/index.ts +56 -0
- package/fixtures/extensions/fake-push/src/push.ts +103 -0
- package/fixtures/extensions/fake-tools-ui/src/index.ts +61 -2
- package/fixtures/extensions/fake-web/src/index.ts +5 -4
- package/fixtures/extensions/fake-web/src/web.ts +11 -7
- package/fixtures/extensions/fake-web-2/src/index.ts +2 -2
- package/fixtures/extensions/fake-web-2/src/web.ts +11 -7
- package/fixtures/plugins/fake-theme/.capybara-plugin/plugin.json +7 -0
- package/fixtures/plugins/fake-theme/brand/app-512.png +0 -0
- package/fixtures/plugins/fake-theme/brand/app-mask-512.png +0 -0
- package/fixtures/plugins/fake-theme/brand/avatars/bot.svg +1 -0
- package/fixtures/plugins/fake-theme/brand/avatars/cat.png +0 -0
- package/fixtures/plugins/fake-theme/brand/illustration.svg +1 -0
- package/fixtures/plugins/fake-theme/brand/unnamed.svg +1 -0
- package/fixtures/plugins/fake-theme/fonts/FakeSans.woff2 +1 -0
- package/fixtures/plugins/fake-theme/logo.svg +1 -0
- package/fixtures/plugins/fake-theme/package.json +8 -0
- package/fixtures/plugins/fake-theme/themes/brand-kit.json +24 -0
- package/fixtures/plugins/fake-theme/themes/neon-grid.json +13 -0
- package/fixtures/plugins/fake-theme/themes/paper.json +12 -0
- package/package.json +6 -5
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
defineExtension,
|
|
3
3
|
MODEL_PROVIDER_EXTENSION_POINT_V2,
|
|
4
4
|
type ModelProvider,
|
|
5
|
+
platformOnly,
|
|
5
6
|
secret,
|
|
6
7
|
} from "@capybara-hq/plugin-sdk";
|
|
7
8
|
import { z } from "zod";
|
|
@@ -13,10 +14,13 @@ import { z } from "zod";
|
|
|
13
14
|
* every request with `fake-bootstrap-a`; it never calls a network service.
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
/** Platform-only as a whole: the platform must set the key before the extension loads. */
|
|
18
|
+
const DeploymentConfig = platformOnly(
|
|
19
|
+
z.object({
|
|
20
|
+
apiKey: secret(z.string().min(1)),
|
|
21
|
+
baseUrl: z.string().url().optional(),
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
20
24
|
|
|
21
25
|
const REPLY = "fake-bootstrap-a";
|
|
22
26
|
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
OBJECT_STORE_EXTENSION_POINT,
|
|
5
5
|
type ObjectHead,
|
|
6
6
|
type ObjectStore,
|
|
7
|
+
platformOnly,
|
|
7
8
|
secret,
|
|
8
9
|
} from "@capybara-hq/plugin-sdk";
|
|
9
10
|
import { z } from "zod";
|
|
@@ -17,10 +18,13 @@ import { z } from "zod";
|
|
|
17
18
|
* from a browser.
|
|
18
19
|
*/
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
/** Platform-only (object-store@1 is infrastructure, unified config spec §5.3). */
|
|
22
|
+
const DeploymentConfig = platformOnly(
|
|
23
|
+
z.object({
|
|
24
|
+
bucket: z.string().min(1),
|
|
25
|
+
secretKey: secret(z.string().min(1)),
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
24
28
|
|
|
25
29
|
type Db = ExtensionContext["db"];
|
|
26
30
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"name": "fake-client",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"publisher": "Capybara",
|
|
6
|
+
"description": "Test fake: client extension components in five slots, CSS decoration, an events listener and a suggested appearance",
|
|
7
|
+
"suggestedAppearance": {
|
|
8
|
+
"theme": "fake",
|
|
9
|
+
"replacements": { "shell.brand": "brand" }
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capybara-hq/test-plugin-fake-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Test fake: client extension components in five slots, CSS decoration, an events listener and a suggested appearance",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@capybara-hq/plugin-client": "^0.1.0-rc.0",
|
|
10
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.0"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineClientExtension,
|
|
3
|
+
defineComponent,
|
|
4
|
+
useClientStorage,
|
|
5
|
+
useView,
|
|
6
|
+
} from "@capybara-hq/plugin-client";
|
|
7
|
+
|
|
8
|
+
const Hud = () => {
|
|
9
|
+
// useView() is the view state ({ view, status, retry }); the server view's data is on `view`
|
|
10
|
+
const { view } = useView();
|
|
11
|
+
const data = view?.data as { n?: number } | undefined;
|
|
12
|
+
return <span data-testid="fake-client-hud">{`hud ${data?.n ?? "-"}`}</span>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const Brand = ({ builtin }: { builtin: unknown }) => (
|
|
16
|
+
<span data-testid="fake-client-brand">{builtin as never}</span>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const Empty = ({ greeting }: { greeting: string }) => (
|
|
20
|
+
<p data-testid="fake-client-empty">{greeting}</p>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const Frame = ({ children }: { children?: unknown }) => (
|
|
24
|
+
<div data-testid="fake-client-frame">{children as never}</div>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const Fx = () => {
|
|
28
|
+
const storage = useClientStorage();
|
|
29
|
+
return <i data-testid="fake-client-fx" data-last={storage.get("last") ?? ""} />;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default defineClientExtension({
|
|
33
|
+
name: "fake-client",
|
|
34
|
+
components: {
|
|
35
|
+
hud: defineComponent("conversation.properties.section", Hud),
|
|
36
|
+
brand: defineComponent("shell.brand", Brand),
|
|
37
|
+
empty: defineComponent("conversation.empty", Empty),
|
|
38
|
+
frame: defineComponent("conversation.composer.frame", Frame),
|
|
39
|
+
fx: defineComponent("shell.overlay", Fx),
|
|
40
|
+
},
|
|
41
|
+
events: {
|
|
42
|
+
"run.started": (e, api) => api.storage.set("last", e.type),
|
|
43
|
+
"run.finished": (e, api) => api.storage.set("last", e.type),
|
|
44
|
+
"run.failed": (e, api) => api.storage.set("last", e.type),
|
|
45
|
+
"message.sent": (e, api) => api.storage.set("last", e.type),
|
|
46
|
+
"message.received": (e, api) => api.storage.set("last", e.type),
|
|
47
|
+
"tool.started": (e, api) => api.storage.set("last", e.type),
|
|
48
|
+
"tool.finished": (e, api) => api.storage.set("last", e.type),
|
|
49
|
+
"approval.requested": (e, api) => api.storage.set("last", e.type),
|
|
50
|
+
},
|
|
51
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { defineExtension, type UiView } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
|
|
3
|
+
const t = (zh: string, en: string) => ({ zh, en });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Test fake of a client extension (client extensions spec §5): one component in each of
|
|
7
|
+
* `conversation.properties.section` (`hud`, server view answering `data: { n: 1 }`), `shell.brand`
|
|
8
|
+
* (`brand`), `conversation.empty` (`empty`), `conversation.composer.frame` (`frame`) and
|
|
9
|
+
* `shell.overlay` (`fx`). The browser side is `src/client.tsx` (components and an `events`
|
|
10
|
+
* listener), `client/styles/fake.css` decorates by part and state, and the theme `fake` is the
|
|
11
|
+
* plugin's `suggestedAppearance` together with `shell.brand` -> `brand`.
|
|
12
|
+
*/
|
|
13
|
+
export default defineExtension({
|
|
14
|
+
name: "fake-client",
|
|
15
|
+
version: "0.1.0",
|
|
16
|
+
sdk: "^0.1.0-rc.0",
|
|
17
|
+
provides: [],
|
|
18
|
+
ui: [
|
|
19
|
+
{
|
|
20
|
+
id: "hud",
|
|
21
|
+
title: t("状态", "Status"),
|
|
22
|
+
slot: "conversation.properties.section",
|
|
23
|
+
kind: "component",
|
|
24
|
+
},
|
|
25
|
+
{ id: "brand", title: t("品牌", "Brand"), slot: "shell.brand", kind: "component" },
|
|
26
|
+
{ id: "empty", title: t("问候", "Greeting"), slot: "conversation.empty", kind: "component" },
|
|
27
|
+
{
|
|
28
|
+
id: "frame",
|
|
29
|
+
title: t("边框", "Frame"),
|
|
30
|
+
slot: "conversation.composer.frame",
|
|
31
|
+
kind: "component",
|
|
32
|
+
},
|
|
33
|
+
{ id: "fx", title: t("特效", "Effects"), slot: "shell.overlay", kind: "component" },
|
|
34
|
+
],
|
|
35
|
+
permissions: {
|
|
36
|
+
client: true,
|
|
37
|
+
ui: { components: ["hud", "brand", "empty", "frame", "fx"] },
|
|
38
|
+
},
|
|
39
|
+
setup(ctx) {
|
|
40
|
+
const withData = (n: number): UiView => ({ blocks: [], data: { n } });
|
|
41
|
+
ctx.ui.view("hud", async () => withData(1));
|
|
42
|
+
},
|
|
43
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capybara-hq/test-plugin-fake-client-broken",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Test fake: client code that throws (a component, an events listener and a conversation.empty replacement)",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@capybara-hq/plugin-client": "^0.1.0-rc.0",
|
|
10
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.0"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineClientExtension, defineComponent } from "@capybara-hq/plugin-client";
|
|
2
|
+
|
|
3
|
+
const Boom = (): never => {
|
|
4
|
+
throw new Error("fake-client-broken: boom");
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const Empty = (): never => {
|
|
8
|
+
throw new Error("fake-client-broken: empty");
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default defineClientExtension({
|
|
12
|
+
name: "fake-client-broken",
|
|
13
|
+
components: {
|
|
14
|
+
boom: defineComponent("conversation.properties.section", Boom),
|
|
15
|
+
empty: defineComponent("conversation.empty", Empty),
|
|
16
|
+
},
|
|
17
|
+
events: {
|
|
18
|
+
"run.started": () => {
|
|
19
|
+
throw new Error("fake-client-broken: run.started");
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineExtension } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
|
|
3
|
+
const t = (zh: string, en: string) => ({ zh, en });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Test fake of a client extension whose browser code is broken, for the host's isolation (error
|
|
7
|
+
* boundaries, the crash budget, safe mode): component `boom` (`conversation.properties.section`)
|
|
8
|
+
* throws on render, the module-level `events` listener throws on `run.started`, and `empty`
|
|
9
|
+
* (`conversation.empty`) throws on render. No server side beyond the declarations.
|
|
10
|
+
*/
|
|
11
|
+
export default defineExtension({
|
|
12
|
+
name: "fake-client-broken",
|
|
13
|
+
version: "0.1.0",
|
|
14
|
+
sdk: "^0.1.0-rc.0",
|
|
15
|
+
provides: [],
|
|
16
|
+
ui: [
|
|
17
|
+
{
|
|
18
|
+
id: "boom",
|
|
19
|
+
title: t("崩溃", "Boom"),
|
|
20
|
+
slot: "conversation.properties.section",
|
|
21
|
+
kind: "component",
|
|
22
|
+
},
|
|
23
|
+
{ id: "empty", title: t("问候", "Greeting"), slot: "conversation.empty", kind: "component" },
|
|
24
|
+
],
|
|
25
|
+
permissions: { client: true, ui: { components: ["boom", "empty"] } },
|
|
26
|
+
setup() {},
|
|
27
|
+
});
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
type ConfigUiHints,
|
|
3
3
|
defineExtension,
|
|
4
4
|
type LocalizedName,
|
|
5
|
+
platformOnly,
|
|
5
6
|
secret,
|
|
6
7
|
ui,
|
|
7
8
|
} from "@capybara-hq/plugin-sdk";
|
|
@@ -141,56 +142,61 @@ const ENDPOINTS: ConfigUiHints = {
|
|
|
141
142
|
],
|
|
142
143
|
};
|
|
143
144
|
|
|
144
|
-
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
145
|
+
/**
|
|
146
|
+
* The deployment config: endpoints, and their API keys by endpoint name. Platform-only as a whole:
|
|
147
|
+
* the fixture has no org-bound entry, so an org value would never reach it.
|
|
148
|
+
*/
|
|
149
|
+
export const FakeConfigFormSchema = platformOnly(
|
|
150
|
+
ui(
|
|
151
|
+
z
|
|
152
|
+
.object({
|
|
153
|
+
endpoints: ui(
|
|
154
|
+
z
|
|
155
|
+
.array(EndpointSchema)
|
|
156
|
+
.min(1)
|
|
157
|
+
.refine((es) => new Set(es.map((e) => e.name)).size === es.length, {
|
|
158
|
+
params: { ui: "duplicateEndpoint" },
|
|
159
|
+
}),
|
|
160
|
+
ENDPOINTS,
|
|
161
|
+
),
|
|
162
|
+
apiKeys: secret(z.record(z.string(), z.string().min(1))).default({}),
|
|
163
|
+
})
|
|
164
|
+
.superRefine((cfg, ctx) => {
|
|
165
|
+
cfg.endpoints.forEach((e, i) => {
|
|
166
|
+
if (acceptsPdf(e.dialect)) return;
|
|
167
|
+
e.models.forEach((m, j) => {
|
|
168
|
+
if (m.documents !== true) return;
|
|
169
|
+
ctx.addIssue({
|
|
170
|
+
code: "custom",
|
|
171
|
+
path: ["endpoints", i, "models", j, "documents"],
|
|
172
|
+
message: `dialect "${e.dialect}" does not accept PDF documents; documents must be false`,
|
|
173
|
+
params: { ui: "pdfDialect" },
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
const names = new Set(cfg.endpoints.map((e) => e.name));
|
|
178
|
+
for (const key of Object.keys(cfg.apiKeys)) {
|
|
179
|
+
if (names.has(key)) continue;
|
|
164
180
|
ctx.addIssue({
|
|
165
181
|
code: "custom",
|
|
166
|
-
path: ["
|
|
167
|
-
message: `
|
|
168
|
-
params: { ui: "
|
|
182
|
+
path: ["apiKeys", key],
|
|
183
|
+
message: `apiKeys["${key}"] does not match any endpoint name`,
|
|
184
|
+
params: { ui: "unknownKey" },
|
|
169
185
|
});
|
|
170
|
-
}
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
}),
|
|
183
|
-
{
|
|
184
|
-
messages: {
|
|
185
|
-
duplicateEndpoint: T("端点名称重复", "Endpoint names must be unique"),
|
|
186
|
-
duplicateModel: T("模型 ID 重复", "Model ids must be unique within an endpoint"),
|
|
187
|
-
pdfDialect: T(
|
|
188
|
-
"该方言不支持 PDF,请取消勾选",
|
|
189
|
-
"This dialect does not accept PDF; clear the box",
|
|
190
|
-
),
|
|
191
|
-
unknownKey: T("密钥没有对应的端点", "This key has no endpoint"),
|
|
186
|
+
}
|
|
187
|
+
}),
|
|
188
|
+
{
|
|
189
|
+
messages: {
|
|
190
|
+
duplicateEndpoint: T("端点名称重复", "Endpoint names must be unique"),
|
|
191
|
+
duplicateModel: T("模型 ID 重复", "Model ids must be unique within an endpoint"),
|
|
192
|
+
pdfDialect: T(
|
|
193
|
+
"该方言不支持 PDF,请取消勾选",
|
|
194
|
+
"This dialect does not accept PDF; clear the box",
|
|
195
|
+
),
|
|
196
|
+
unknownKey: T("密钥没有对应的端点", "This key has no endpoint"),
|
|
197
|
+
},
|
|
192
198
|
},
|
|
193
|
-
|
|
199
|
+
),
|
|
194
200
|
);
|
|
195
201
|
|
|
196
202
|
export default defineExtension({
|
|
@@ -7,8 +7,10 @@ import {
|
|
|
7
7
|
type ConnectorSession,
|
|
8
8
|
defineExtension,
|
|
9
9
|
type ElicitationRequest,
|
|
10
|
+
type ExtensionNet,
|
|
10
11
|
type Logger,
|
|
11
12
|
type PromptInfo,
|
|
13
|
+
platformOnly,
|
|
12
14
|
type ToolContent,
|
|
13
15
|
ToolError,
|
|
14
16
|
type ToolResult,
|
|
@@ -33,8 +35,10 @@ import { z } from "zod";
|
|
|
33
35
|
* `kind` names another): a deliberately small MCP client
|
|
34
36
|
* (Streamable HTTP) meant for `startFakeMcpServer` from `@capybara-hq/testing`. It covers the
|
|
35
37
|
* kernel side of the connector contract, not MCP edge cases:
|
|
36
|
-
* - `endpointSchema`: `{ url, headers? }`, https or (
|
|
37
|
-
*
|
|
38
|
+
* - `endpointSchema`: `{ url, headers? }`, https or loopback http (the kernel's `ctx.net` decides
|
|
39
|
+
* what is reachable: test kernels set `net.allowInsecureLoopback`); credential headers are
|
|
40
|
+
* rejected;
|
|
41
|
+
* - every request goes through `ctx.net.fetch` with the session's `orgId`;
|
|
38
42
|
* - `auth()` before every request, one `onUnauthorized()` + retry on 401, redirects not followed;
|
|
39
43
|
* a 5xx answer's body is logged as the warning `fake-connector request failed` (the kernel
|
|
40
44
|
* redacts credentials in extension logs);
|
|
@@ -42,6 +46,7 @@ import { z } from "zod";
|
|
|
42
46
|
* `_meta["fake/route"]` (the name of the remote tool that serves it) or else its name; `callTool`
|
|
43
47
|
* calls the route of `ctx.spec.connectorData` when the kernel passes it, so a route change
|
|
44
48
|
* without a rename is a definition drift and calls keep the reviewed route until approval;
|
|
49
|
+
* - the endpoint's optional `apiUrl` is a second URL the connector ignores;
|
|
45
50
|
* - the endpoint's optional `notesText` is free-form text the connector ignores (a `*Text` field
|
|
46
51
|
* the kernel summarizes in connector views instead of echoing it);
|
|
47
52
|
* - the URL-mode elicitation error `-32042` goes through `onElicit` (each step accepted -> one
|
|
@@ -64,32 +69,34 @@ const CLIENT_INFO = { name: "capybara-fake-connector", version: "0.1.0" };
|
|
|
64
69
|
/** The kernel's pipeline timeout (through the signal) decides, not the SDK's default 60 s. */
|
|
65
70
|
const REQUEST_TIMEOUT_MS = 3_600_000;
|
|
66
71
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
})
|
|
72
|
+
/** Platform-only: connector@1 calls carry no org config (spec §5.3). */
|
|
73
|
+
const DeploymentConfig = platformOnly(
|
|
74
|
+
z.object({
|
|
75
|
+
/** The auth hint `inspect` reports behind a 401. */
|
|
76
|
+
inspectAuth: z.enum(["bearer", "api_key"]).default("bearer"),
|
|
77
|
+
/**
|
|
78
|
+
* The connector kind it provides (default `fake`). A deployment that loads no other connector
|
|
79
|
+
* extension can name it `mcp`, so clients that know only the official kinds (the web install
|
|
80
|
+
* wizard) drive it like an MCP connector.
|
|
81
|
+
*/
|
|
82
|
+
kind: z
|
|
83
|
+
.string()
|
|
84
|
+
.regex(/^[a-z][a-z0-9-]{0,31}$/)
|
|
85
|
+
.default("fake"),
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
82
88
|
|
|
83
89
|
/** The `_meta` key of a remote tool that names the remote tool serving it (its route). */
|
|
84
90
|
export const FAKE_ROUTE_META = "fake/route";
|
|
85
91
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
/**
|
|
93
|
+
* http or https; whether the target is reachable is `ctx.net`'s call at request time (http only for
|
|
94
|
+
* an org-allowed `http://host:port` origin, or loopback under `net.allowInsecureLoopback`).
|
|
95
|
+
*/
|
|
96
|
+
const urlAllowed = (raw: string): boolean => {
|
|
90
97
|
try {
|
|
91
98
|
const u = new URL(raw);
|
|
92
|
-
return u.protocol === "https:" ||
|
|
99
|
+
return u.protocol === "https:" || u.protocol === "http:";
|
|
93
100
|
} catch {
|
|
94
101
|
return true; // z.url() reports the format error
|
|
95
102
|
}
|
|
@@ -99,14 +106,19 @@ const isCredentialHeader = (name: string): boolean =>
|
|
|
99
106
|
["authorization", "proxy-authorization", "cookie"].includes(name.toLowerCase());
|
|
100
107
|
|
|
101
108
|
/** The endpoint: the server URL and optional non-secret fixed headers. */
|
|
102
|
-
export function fakeEndpointSchema(
|
|
109
|
+
export function fakeEndpointSchema() {
|
|
103
110
|
return z
|
|
104
111
|
.object({
|
|
105
|
-
url: z.url().refine(
|
|
106
|
-
message: "URL must use
|
|
112
|
+
url: z.url().refine(urlAllowed, {
|
|
113
|
+
message: "URL must use http or https",
|
|
107
114
|
}),
|
|
108
115
|
/** Free-form text the connector ignores (large-endpoint tests). */
|
|
109
116
|
notesText: z.string().optional(),
|
|
117
|
+
/**
|
|
118
|
+
* A second URL the connector ignores: a destination field other than `url` (as an OpenAPI
|
|
119
|
+
* base URL), for tests of endpoint edits that move where requests go.
|
|
120
|
+
*/
|
|
121
|
+
apiUrl: z.url().refine(urlAllowed, { message: "URL must use http or https" }).optional(),
|
|
110
122
|
headers: z
|
|
111
123
|
.record(z.string(), z.string())
|
|
112
124
|
.default({})
|
|
@@ -174,6 +186,8 @@ async function guarded<T>(work: () => Promise<T>): Promise<T> {
|
|
|
174
186
|
|
|
175
187
|
/** A fetch that injects `auth()` before every request and retries once after `onUnauthorized()`. */
|
|
176
188
|
function authedFetch(
|
|
189
|
+
net: ExtensionNet,
|
|
190
|
+
orgId: string,
|
|
177
191
|
endpoint: Endpoint,
|
|
178
192
|
auth: ConnectorOpenArgs["auth"] | undefined,
|
|
179
193
|
onUnauthorized: ConnectorOpenArgs["onUnauthorized"] | undefined,
|
|
@@ -190,7 +204,11 @@ function authedFetch(
|
|
|
190
204
|
for (const [k, v] of Object.entries(endpoint.headers)) if (!headers.has(k)) headers.set(k, v);
|
|
191
205
|
for (const [k, v] of Object.entries(inj.headers)) headers.set(k, v);
|
|
192
206
|
const s = init?.signal ? AbortSignal.any([init.signal, signal]) : signal;
|
|
193
|
-
return fetch(
|
|
207
|
+
return net.fetch(
|
|
208
|
+
url.toString(),
|
|
209
|
+
{ ...init, headers, signal: s, redirect: "manual" },
|
|
210
|
+
{ orgId },
|
|
211
|
+
);
|
|
194
212
|
};
|
|
195
213
|
const noRedirect = async (r: Response) => {
|
|
196
214
|
if (r.status >= 300 && r.status < 400) {
|
|
@@ -275,11 +293,20 @@ async function connect(
|
|
|
275
293
|
}
|
|
276
294
|
|
|
277
295
|
async function openSession(
|
|
296
|
+
net: ExtensionNet,
|
|
278
297
|
endpoint: Endpoint,
|
|
279
298
|
args: ConnectorOpenArgs,
|
|
280
299
|
log?: Logger,
|
|
281
300
|
): Promise<ConnectorSession> {
|
|
282
|
-
const fetchImpl = authedFetch(
|
|
301
|
+
const fetchImpl = authedFetch(
|
|
302
|
+
net,
|
|
303
|
+
args.orgId,
|
|
304
|
+
endpoint,
|
|
305
|
+
args.auth,
|
|
306
|
+
args.onUnauthorized,
|
|
307
|
+
args.signal,
|
|
308
|
+
log,
|
|
309
|
+
);
|
|
283
310
|
const { client, transport } = await connect(endpoint, fetchImpl, args);
|
|
284
311
|
const opts = (signal: AbortSignal = args.signal) => ({ signal, timeout: REQUEST_TIMEOUT_MS });
|
|
285
312
|
const session: ConnectorSession = {
|
|
@@ -412,12 +439,14 @@ const authHint = (kind: InspectAuth): AuthHint =>
|
|
|
412
439
|
|
|
413
440
|
/** Install preview without credentials: 401 -> the configured auth hint; otherwise the tools as operations. */
|
|
414
441
|
async function inspect(
|
|
442
|
+
net: ExtensionNet,
|
|
443
|
+
orgId: string,
|
|
415
444
|
endpoint: Endpoint,
|
|
416
445
|
signal: AbortSignal,
|
|
417
446
|
hint: InspectAuth,
|
|
418
447
|
): Promise<ConnectorInspection> {
|
|
419
448
|
let unauthorized = false;
|
|
420
|
-
const probe = authedFetch(endpoint, undefined, undefined, signal);
|
|
449
|
+
const probe = authedFetch(net, orgId, endpoint, undefined, undefined, signal);
|
|
421
450
|
const fetchImpl = async (input: string | URL, init?: RequestInit) => {
|
|
422
451
|
const r = await probe(input, init);
|
|
423
452
|
if (r.status === 401) unauthorized = true;
|
|
@@ -447,17 +476,18 @@ async function inspect(
|
|
|
447
476
|
|
|
448
477
|
/** Creates the fake connector (exported for unit tests that call it without a kernel). */
|
|
449
478
|
export function createFakeConnector(
|
|
450
|
-
|
|
479
|
+
net: ExtensionNet,
|
|
451
480
|
inspectAuth: InspectAuth = "bearer",
|
|
452
481
|
kind = "fake",
|
|
453
482
|
log?: Logger,
|
|
454
483
|
): Connector {
|
|
455
|
-
const schema = fakeEndpointSchema(
|
|
484
|
+
const schema = fakeEndpointSchema();
|
|
456
485
|
return {
|
|
457
486
|
kind,
|
|
458
487
|
endpointSchema: schema,
|
|
459
|
-
open: (args) => openSession(schema.parse(args.endpoint), args, log),
|
|
460
|
-
inspect: ({ endpoint, signal }) =>
|
|
488
|
+
open: (args) => openSession(net, schema.parse(args.endpoint), args, log),
|
|
489
|
+
inspect: ({ endpoint, signal, orgId }) =>
|
|
490
|
+
inspect(net, orgId, schema.parse(endpoint), signal, inspectAuth),
|
|
461
491
|
};
|
|
462
492
|
}
|
|
463
493
|
|
|
@@ -468,10 +498,10 @@ export default defineExtension({
|
|
|
468
498
|
provides: [CONNECTOR_EXTENSION_POINT],
|
|
469
499
|
config: { deployment: DeploymentConfig },
|
|
470
500
|
setup(ctx) {
|
|
471
|
-
const {
|
|
501
|
+
const { inspectAuth, kind } = DeploymentConfig.parse(ctx.config ?? {});
|
|
472
502
|
ctx.provide(
|
|
473
503
|
CONNECTOR_EXTENSION_POINT,
|
|
474
|
-
createFakeConnector(
|
|
504
|
+
createFakeConnector(ctx.net, inspectAuth, kind, ctx.log),
|
|
475
505
|
);
|
|
476
506
|
},
|
|
477
507
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capybara-hq/test-plugin-fake-context",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Test fake: a scripted context provider (context@1) and one tool limited to one-to-one conversations",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.0",
|
|
10
|
+
"zod": "^4.6.7"
|
|
11
|
+
}
|
|
12
|
+
}
|