@capybara-hq/testing 0.1.0-rc.2 → 0.1.0-rc.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/containers.d.ts +7 -2
- package/dist/containers.js +7 -3
- package/dist/dual-replica.d.ts +11 -2
- package/dist/dual-replica.js +48 -0
- package/dist/fake-channel.d.ts +31 -2
- package/dist/fake-channel.js +29 -2
- 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-oauth-server.d.ts +16 -2
- package/dist/fake-oauth-server.js +21 -1
- package/dist/fake-telegram.d.ts +165 -0
- package/dist/fake-telegram.js +569 -0
- package/dist/fixtures.d.ts +21 -4
- package/dist/fixtures.js +30 -4
- package/dist/index.d.ts +7 -5
- package/dist/index.js +4 -2
- package/dist/kernel-helpers.d.ts +40 -16
- package/dist/kernel-helpers.js +44 -13
- package/dist/model-conformance.d.ts +5 -0
- package/dist/model-conformance.js +33 -1
- package/dist/replica-runner.js +16 -8
- package/dist/sandbox-native-conformance.d.ts +31 -0
- package/dist/sandbox-native-conformance.js +153 -0
- 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/.capybara-plugin/plugin.json +11 -0
- package/fixtures/extensions/fake-config-form/package.json +12 -0
- package/fixtures/extensions/fake-config-form/src/index.ts +205 -0
- 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 +81 -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 +3 -1
- package/fixtures/extensions/fake-im/src/checks.ts +94 -0
- package/fixtures/extensions/fake-im/src/index.ts +36 -1
- 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-storage-user/src/index.ts +1 -1
- package/fixtures/extensions/fake-tools-ui/skills/fake-notes/SKILL.md +1 -1
- package/fixtures/extensions/fake-tools-ui/src/index.ts +62 -3
- package/fixtures/extensions/fake-web/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-web/package.json +12 -0
- package/fixtures/extensions/fake-web/src/index.ts +22 -0
- package/fixtures/extensions/fake-web/src/web.ts +183 -0
- package/fixtures/extensions/fake-web-2/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-web-2/package.json +12 -0
- package/fixtures/extensions/fake-web-2/src/index.ts +16 -0
- package/fixtures/extensions/fake-web-2/src/web.ts +183 -0
- package/fixtures/plugins/fake-theme/.capybara-plugin/plugin.json +7 -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/neon-grid.json +13 -0
- package/fixtures/plugins/fake-theme/themes/paper.json +12 -0
- package/package.json +6 -5
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"name": "fake-config-form",
|
|
4
|
+
"displayName": {
|
|
5
|
+
"zh": "表单样例",
|
|
6
|
+
"en": "Form sample"
|
|
7
|
+
},
|
|
8
|
+
"version": "0.1.0",
|
|
9
|
+
"publisher": "Capybara",
|
|
10
|
+
"description": "Test fake: an openai-compatible-shaped deployment config schema with config form hints"
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capybara-hq/test-plugin-fake-config-form",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Test fake: an openai-compatible-shaped deployment config schema with config form hints",
|
|
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
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ConfigUiHints,
|
|
3
|
+
defineExtension,
|
|
4
|
+
type LocalizedName,
|
|
5
|
+
secret,
|
|
6
|
+
ui,
|
|
7
|
+
} from "@capybara-hq/plugin-sdk";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Test fake of a hinted deployment config (extension config forms spec §6): the shape of
|
|
12
|
+
* openai-compatible's config (endpoints with models, API keys in a top-level secret record keyed by
|
|
13
|
+
* endpoint name) with the hints that plugin carries, so the web form (presets, item secrets, model
|
|
14
|
+
* rows, advanced fields, localized custom issues) is tested without an official plugin. It provides
|
|
15
|
+
* nothing and calls no service: setup only validates the config. Display name 表单样例 / Form sample.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const T = (zh: string, en: string): LocalizedName => ({ zh, en });
|
|
19
|
+
const flag = (zh: string, en: string, help?: LocalizedName) =>
|
|
20
|
+
ui(z.boolean().optional(), { label: T(zh, en), widget: "checkbox", ...(help && { help }) });
|
|
21
|
+
|
|
22
|
+
/** Whether a dialect accepts PDF documents (as in openai-compatible: generic and qwen). */
|
|
23
|
+
const acceptsPdf = (dialect: string): boolean => dialect === "generic" || dialect === "qwen";
|
|
24
|
+
|
|
25
|
+
const EndpointModelSchema = ui(
|
|
26
|
+
z.object({
|
|
27
|
+
id: ui(z.string().min(1), { label: T("模型 ID", "Model ID"), placeholder: "deepseek-chat" }),
|
|
28
|
+
contextWindow: ui(z.number().int().positive(), {
|
|
29
|
+
label: T("上下文窗口", "Context window"),
|
|
30
|
+
unit: T("tokens", "tokens"),
|
|
31
|
+
}),
|
|
32
|
+
maxOutputTokens: ui(z.number().int().positive(), {
|
|
33
|
+
label: T("最大输出", "Max output"),
|
|
34
|
+
unit: T("tokens", "tokens"),
|
|
35
|
+
}),
|
|
36
|
+
vision: flag("图片", "Images"),
|
|
37
|
+
documents: flag(
|
|
38
|
+
"PDF 文档",
|
|
39
|
+
"PDF documents",
|
|
40
|
+
T("仅通用与通义千问方言支持", "Only the generic and Qwen dialects accept PDF"),
|
|
41
|
+
),
|
|
42
|
+
reasoning: flag("推理", "Reasoning"),
|
|
43
|
+
caching: ui(z.boolean().optional(), {
|
|
44
|
+
label: T("缓存", "Caching"),
|
|
45
|
+
widget: "tristate",
|
|
46
|
+
help: T("默认按方言", "Default follows the dialect"),
|
|
47
|
+
advanced: true,
|
|
48
|
+
}),
|
|
49
|
+
streamIdleTimeoutMs: ui(z.number().int().positive().optional(), {
|
|
50
|
+
label: T("流空闲超时", "Stream idle timeout"),
|
|
51
|
+
unit: T("毫秒", "ms"),
|
|
52
|
+
advanced: true,
|
|
53
|
+
}),
|
|
54
|
+
}),
|
|
55
|
+
{ layout: "row" },
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const EndpointSchema = z.strictObject({
|
|
59
|
+
name: ui(z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/), {
|
|
60
|
+
label: T("名称", "Name"),
|
|
61
|
+
help: T("对外模型 ID 为 <名称>/<模型 ID>", "Models are exposed as <name>/<model id>"),
|
|
62
|
+
}),
|
|
63
|
+
baseUrl: ui(z.string().url(), {
|
|
64
|
+
label: T("接口地址", "Base URL"),
|
|
65
|
+
widget: "url",
|
|
66
|
+
placeholder: "https://api.example.com/v1",
|
|
67
|
+
}),
|
|
68
|
+
dialect: ui(z.enum(["generic", "deepseek", "qwen", "ark"]), {
|
|
69
|
+
label: T("方言", "Dialect"),
|
|
70
|
+
options: [
|
|
71
|
+
{ value: "generic", label: T("通用(vLLM 等)", "Generic (vLLM, …)") },
|
|
72
|
+
{ value: "deepseek", label: T("DeepSeek", "DeepSeek") },
|
|
73
|
+
{ value: "qwen", label: T("通义千问(百炼)", "Qwen (Model Studio)") },
|
|
74
|
+
{ value: "ark", label: T("火山方舟", "Volcano Ark") },
|
|
75
|
+
],
|
|
76
|
+
}),
|
|
77
|
+
midConversationSystem: ui(z.boolean().optional(), {
|
|
78
|
+
label: T("对话中途的 system 消息", "Mid-conversation system messages"),
|
|
79
|
+
widget: "tristate",
|
|
80
|
+
advanced: true,
|
|
81
|
+
}),
|
|
82
|
+
models: ui(
|
|
83
|
+
z
|
|
84
|
+
.array(EndpointModelSchema)
|
|
85
|
+
.min(1)
|
|
86
|
+
.refine((ms) => new Set(ms.map((m) => m.id)).size === ms.length, {
|
|
87
|
+
params: { ui: "duplicateModel" },
|
|
88
|
+
}),
|
|
89
|
+
{
|
|
90
|
+
label: T("模型", "Models"),
|
|
91
|
+
item: { title: "{id}", addLabel: T("添加模型", "Add model"), reorder: true },
|
|
92
|
+
},
|
|
93
|
+
),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const ENDPOINTS: ConfigUiHints = {
|
|
97
|
+
label: T("端点", "Endpoints"),
|
|
98
|
+
item: {
|
|
99
|
+
title: "{name}",
|
|
100
|
+
subtitle: "{baseUrl}",
|
|
101
|
+
addLabel: T("添加端点", "Add endpoint"),
|
|
102
|
+
reorder: true,
|
|
103
|
+
},
|
|
104
|
+
secrets: [
|
|
105
|
+
{
|
|
106
|
+
path: "apiKeys",
|
|
107
|
+
keyBy: "name",
|
|
108
|
+
after: "baseUrl",
|
|
109
|
+
label: T("API 密钥", "API key"),
|
|
110
|
+
help: T(
|
|
111
|
+
"留空则请求不带凭据(如内网 vLLM)",
|
|
112
|
+
"Leave empty for services without a key (e.g. an internal vLLM)",
|
|
113
|
+
),
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
presets: [
|
|
117
|
+
{
|
|
118
|
+
id: "deepseek",
|
|
119
|
+
label: T("DeepSeek", "DeepSeek"),
|
|
120
|
+
values: { name: "deepseek", baseUrl: "https://api.deepseek.com", dialect: "deepseek" },
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: "qwen",
|
|
124
|
+
label: T("通义千问(百炼)", "Qwen (Model Studio)"),
|
|
125
|
+
values: {
|
|
126
|
+
name: "qwen",
|
|
127
|
+
baseUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
128
|
+
dialect: "qwen",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: "ark",
|
|
133
|
+
label: T("火山方舟", "Volcano Ark"),
|
|
134
|
+
values: { name: "ark", baseUrl: "https://ark.cn-beijing.volces.com/api/v3", dialect: "ark" },
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: "generic",
|
|
138
|
+
label: T("其他兼容服务", "Other compatible service"),
|
|
139
|
+
values: { dialect: "generic" },
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/** The deployment config: endpoints, and their API keys by endpoint name. */
|
|
145
|
+
export const FakeConfigFormSchema = ui(
|
|
146
|
+
z
|
|
147
|
+
.object({
|
|
148
|
+
endpoints: ui(
|
|
149
|
+
z
|
|
150
|
+
.array(EndpointSchema)
|
|
151
|
+
.min(1)
|
|
152
|
+
.refine((es) => new Set(es.map((e) => e.name)).size === es.length, {
|
|
153
|
+
params: { ui: "duplicateEndpoint" },
|
|
154
|
+
}),
|
|
155
|
+
ENDPOINTS,
|
|
156
|
+
),
|
|
157
|
+
apiKeys: secret(z.record(z.string(), z.string().min(1))).default({}),
|
|
158
|
+
})
|
|
159
|
+
.superRefine((cfg, ctx) => {
|
|
160
|
+
cfg.endpoints.forEach((e, i) => {
|
|
161
|
+
if (acceptsPdf(e.dialect)) return;
|
|
162
|
+
e.models.forEach((m, j) => {
|
|
163
|
+
if (m.documents !== true) return;
|
|
164
|
+
ctx.addIssue({
|
|
165
|
+
code: "custom",
|
|
166
|
+
path: ["endpoints", i, "models", j, "documents"],
|
|
167
|
+
message: `dialect "${e.dialect}" does not accept PDF documents; documents must be false`,
|
|
168
|
+
params: { ui: "pdfDialect" },
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
const names = new Set(cfg.endpoints.map((e) => e.name));
|
|
173
|
+
for (const key of Object.keys(cfg.apiKeys)) {
|
|
174
|
+
if (names.has(key)) continue;
|
|
175
|
+
ctx.addIssue({
|
|
176
|
+
code: "custom",
|
|
177
|
+
path: ["apiKeys", key],
|
|
178
|
+
message: `apiKeys["${key}"] does not match any endpoint name`,
|
|
179
|
+
params: { ui: "unknownKey" },
|
|
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"),
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
export default defineExtension({
|
|
197
|
+
name: "fake-config-form",
|
|
198
|
+
version: "0.1.0",
|
|
199
|
+
sdk: "^0.1.0-rc.0",
|
|
200
|
+
provides: [],
|
|
201
|
+
config: { deployment: FakeConfigFormSchema },
|
|
202
|
+
setup(ctx) {
|
|
203
|
+
FakeConfigFormSchema.parse(ctx.config ?? {});
|
|
204
|
+
},
|
|
205
|
+
});
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ContextProvider,
|
|
3
|
+
type ContextRequest,
|
|
4
|
+
defineExtension,
|
|
5
|
+
type ToolSpec,
|
|
6
|
+
} from "@capybara-hq/plugin-sdk";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Test fake of a `context@1` provider (memory plugin spec §6.1). Its behavior follows its
|
|
11
|
+
* deployment config, which the kernel passes back as the request's effective `config`:
|
|
12
|
+
* - `mode: "ok"` (default): returns `{ text }` (`text` default "fake context");
|
|
13
|
+
* - `mode: "null"`: returns null (nothing to add);
|
|
14
|
+
* - `mode: "throw"`: throws;
|
|
15
|
+
* - `mode: "hang"`: waits until the request's signal aborts, then rejects with its reason.
|
|
16
|
+
* Every call is recorded (the request without its signal) on `globalThis.__fakeContext`
|
|
17
|
+
* ({@link fakeContextProbe}; in-process kernels only). It also registers the tool `note` (default
|
|
18
|
+
* policy allow, `sources: ["web", "channel_dm"]`), so `tools` in a request lists
|
|
19
|
+
* `plugin__fake-context__note` only in one-to-one conversations. Its org config (`label`, default
|
|
20
|
+
* "") exists only so a test can store an org copy that no longer validates.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const DeploymentConfig = z.object({
|
|
24
|
+
text: z.string().default("fake context"),
|
|
25
|
+
mode: z.enum(["ok", "null", "throw", "hang"]).default("ok"),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/** An org-only config (all defaults), so a test can make the org's stored copy invalid. */
|
|
29
|
+
const OrgConfig = z.object({ label: z.string().default("") });
|
|
30
|
+
|
|
31
|
+
/** One `provide` call: the request the kernel sent, without its signal. */
|
|
32
|
+
export type FakeContextCall = Omit<ContextRequest, "signal">;
|
|
33
|
+
|
|
34
|
+
/** The probe tests read: every `provide` call of this process. */
|
|
35
|
+
export function fakeContextProbe(): { calls: FakeContextCall[] } {
|
|
36
|
+
const g = globalThis as { __fakeContext?: { calls: FakeContextCall[] } };
|
|
37
|
+
g.__fakeContext ??= { calls: [] };
|
|
38
|
+
return g.__fakeContext;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Rejects with the signal's reason once it aborts. */
|
|
42
|
+
function hang(signal: AbortSignal): Promise<never> {
|
|
43
|
+
return new Promise((_, reject) => {
|
|
44
|
+
if (signal.aborted) reject(signal.reason);
|
|
45
|
+
else signal.addEventListener("abort", () => reject(signal.reason), { once: true });
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const NOTE: ToolSpec = {
|
|
50
|
+
name: "note",
|
|
51
|
+
description:
|
|
52
|
+
"Acknowledge a note. Offered only in web and direct-message conversations. Test fixture only.",
|
|
53
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
54
|
+
defaultPolicy: "allow",
|
|
55
|
+
sources: ["web", "channel_dm"],
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const provider: ContextProvider = {
|
|
59
|
+
async provide(req) {
|
|
60
|
+
const { signal, ...call } = req;
|
|
61
|
+
fakeContextProbe().calls.push(call);
|
|
62
|
+
const cfg = DeploymentConfig.parse(req.config ?? {});
|
|
63
|
+
if (cfg.mode === "throw") throw new Error("fake-context: scripted failure");
|
|
64
|
+
if (cfg.mode === "hang") await hang(signal);
|
|
65
|
+
if (cfg.mode === "null") return null;
|
|
66
|
+
return { text: cfg.text };
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default defineExtension({
|
|
71
|
+
name: "fake-context",
|
|
72
|
+
version: "0.1.0",
|
|
73
|
+
sdk: "^0.1.0-rc.0",
|
|
74
|
+
provides: ["context@1"],
|
|
75
|
+
config: { deployment: DeploymentConfig, org: OrgConfig },
|
|
76
|
+
permissions: { tools: ["note"] },
|
|
77
|
+
setup(ctx) {
|
|
78
|
+
ctx.provide("context@1", provider);
|
|
79
|
+
ctx.tools.register(NOTE, async () => ({ content: [{ type: "text", text: "Noted." }] }));
|
|
80
|
+
},
|
|
81
|
+
});
|
|
@@ -10,7 +10,7 @@ export default defineExtension({
|
|
|
10
10
|
version: "0.1.0",
|
|
11
11
|
sdk: "^0.1.0-rc.0",
|
|
12
12
|
provides: ["counter@1"],
|
|
13
|
-
permissions: { http: [{ method: "GET", path: "/ping" }] },
|
|
13
|
+
permissions: { http: [{ method: "GET", path: "/ping", access: "public" }] },
|
|
14
14
|
setup(ctx) {
|
|
15
15
|
const pong = "pong from fake-dep-provider";
|
|
16
16
|
ctx.provide("counter@1", { ping: () => pong });
|
|
@@ -11,7 +11,7 @@ export default defineExtension({
|
|
|
11
11
|
sdk: "^0.1.0-rc.0",
|
|
12
12
|
provides: [],
|
|
13
13
|
requires: ["counter@1"],
|
|
14
|
-
permissions: { http: [{ method: "GET", path: "/ping" }] },
|
|
14
|
+
permissions: { http: [{ method: "GET", path: "/ping", access: "public" }] },
|
|
15
15
|
setup(ctx) {
|
|
16
16
|
ctx.http.route("GET", "/ping", async () => {
|
|
17
17
|
const impl = ctx.extensionPoints.list<{ ping(): string }>("counter@1")[0]?.impl;
|