@capybara-hq/testing 0.1.0-rc.3 → 0.1.0-rc.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/containers.d.ts +7 -2
  2. package/dist/containers.js +7 -3
  3. package/dist/dual-replica.d.ts +17 -1
  4. package/dist/dual-replica.js +52 -0
  5. package/dist/fake-channel.d.ts +51 -3
  6. package/dist/fake-channel.js +71 -3
  7. package/dist/fake-e2b.d.ts +34 -0
  8. package/dist/fake-e2b.js +95 -1
  9. package/dist/fake-git-server.d.ts +32 -4
  10. package/dist/fake-git-server.js +87 -19
  11. package/dist/fake-lark.d.ts +12 -1
  12. package/dist/fake-lark.js +63 -10
  13. package/dist/fake-oauth-server.d.ts +16 -2
  14. package/dist/fake-oauth-server.js +21 -1
  15. package/dist/fake-slack.d.ts +17 -1
  16. package/dist/fake-slack.js +98 -0
  17. package/dist/fake-telegram.d.ts +173 -0
  18. package/dist/fake-telegram.js +632 -0
  19. package/dist/fixtures.d.ts +25 -7
  20. package/dist/fixtures.js +35 -7
  21. package/dist/index.d.ts +12 -8
  22. package/dist/index.js +8 -4
  23. package/dist/kernel-helpers.d.ts +16 -4
  24. package/dist/kernel-helpers.js +39 -4
  25. package/dist/media-samples.d.ts +2 -0
  26. package/dist/media-samples.js +2 -0
  27. package/dist/model-conformance.d.ts +15 -10
  28. package/dist/model-conformance.js +87 -14
  29. package/dist/push-conformance.d.ts +31 -0
  30. package/dist/push-conformance.js +160 -0
  31. package/dist/replica-runner.js +2 -0
  32. package/dist/sandbox-native-conformance.d.ts +31 -0
  33. package/dist/sandbox-native-conformance.js +153 -0
  34. package/dist/sandbox-permission-conformance.d.ts +307 -0
  35. package/dist/sandbox-permission-conformance.js +1475 -0
  36. package/fixtures/extensions/fake-client/.capybara-plugin/plugin.json +11 -0
  37. package/fixtures/extensions/fake-client/client/styles/fake.css +11 -0
  38. package/fixtures/extensions/fake-client/package.json +12 -0
  39. package/fixtures/extensions/fake-client/src/client.tsx +51 -0
  40. package/fixtures/extensions/fake-client/src/index.ts +43 -0
  41. package/fixtures/extensions/fake-client/themes/fake.json +11 -0
  42. package/fixtures/extensions/fake-client-broken/.capybara-plugin/plugin.json +7 -0
  43. package/fixtures/extensions/fake-client-broken/package.json +12 -0
  44. package/fixtures/extensions/fake-client-broken/src/client.tsx +22 -0
  45. package/fixtures/extensions/fake-client-broken/src/index.ts +27 -0
  46. package/fixtures/extensions/fake-config-form/.capybara-plugin/plugin.json +11 -0
  47. package/fixtures/extensions/fake-config-form/package.json +12 -0
  48. package/fixtures/extensions/fake-config-form/src/index.ts +205 -0
  49. package/fixtures/extensions/fake-connector/src/index.ts +41 -21
  50. package/fixtures/extensions/fake-context/.capybara-plugin/plugin.json +7 -0
  51. package/fixtures/extensions/fake-context/package.json +12 -0
  52. package/fixtures/extensions/fake-context/src/index.ts +81 -0
  53. package/fixtures/extensions/fake-dep-provider/src/index.ts +1 -1
  54. package/fixtures/extensions/fake-dep-requirer/src/index.ts +1 -1
  55. package/fixtures/extensions/fake-embed/src/index.ts +26 -26
  56. package/fixtures/extensions/fake-im/.capybara-plugin/plugin.json +7 -1
  57. package/fixtures/extensions/fake-im/guides/fake-im-app.md +32 -0
  58. package/fixtures/extensions/fake-im/guides/fake-im-app.zh.md +32 -0
  59. package/fixtures/extensions/fake-im/src/channel.ts +22 -1
  60. package/fixtures/extensions/fake-im/src/checks.ts +94 -0
  61. package/fixtures/extensions/fake-im/src/index.ts +45 -2
  62. package/fixtures/extensions/fake-lifecycle/.capybara-plugin/plugin.json +7 -0
  63. package/fixtures/extensions/fake-lifecycle/migrations/0001_init.sql +16 -0
  64. package/fixtures/extensions/fake-lifecycle/package.json +12 -0
  65. package/fixtures/extensions/fake-lifecycle/src/index.ts +72 -0
  66. package/fixtures/extensions/fake-openapi/src/index.ts +46 -34
  67. package/fixtures/extensions/fake-push/.capybara-plugin/plugin.json +13 -0
  68. package/fixtures/extensions/fake-push/guides/fake-push-key.md +6 -0
  69. package/fixtures/extensions/fake-push/guides/fake-push-key.zh.md +6 -0
  70. package/fixtures/extensions/fake-push/migrations/0001_sends.sql +9 -0
  71. package/fixtures/extensions/fake-push/package.json +12 -0
  72. package/fixtures/extensions/fake-push/src/check.ts +40 -0
  73. package/fixtures/extensions/fake-push/src/index.ts +48 -0
  74. package/fixtures/extensions/fake-push/src/push.ts +103 -0
  75. package/fixtures/extensions/fake-storage-user/src/index.ts +1 -1
  76. package/fixtures/extensions/fake-tools-ui/skills/fake-notes/SKILL.md +1 -1
  77. package/fixtures/extensions/fake-tools-ui/src/index.ts +62 -3
  78. package/fixtures/extensions/fake-web/.capybara-plugin/plugin.json +7 -0
  79. package/fixtures/extensions/fake-web/package.json +12 -0
  80. package/fixtures/extensions/fake-web/src/index.ts +22 -0
  81. package/fixtures/extensions/fake-web/src/web.ts +183 -0
  82. package/fixtures/extensions/fake-web-2/.capybara-plugin/plugin.json +7 -0
  83. package/fixtures/extensions/fake-web-2/package.json +12 -0
  84. package/fixtures/extensions/fake-web-2/src/index.ts +16 -0
  85. package/fixtures/extensions/fake-web-2/src/web.ts +183 -0
  86. package/fixtures/plugins/fake-theme/.capybara-plugin/plugin.json +7 -0
  87. package/fixtures/plugins/fake-theme/fonts/FakeSans.woff2 +1 -0
  88. package/fixtures/plugins/fake-theme/logo.svg +1 -0
  89. package/fixtures/plugins/fake-theme/package.json +8 -0
  90. package/fixtures/plugins/fake-theme/themes/neon-grid.json +13 -0
  91. package/fixtures/plugins/fake-theme/themes/paper.json +12 -0
  92. 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,11 @@
1
+ [data-cap-part~="button.primary"] {
2
+ outline-color: rgb(1, 2, 3);
3
+ }
4
+
5
+ [data-cap-part~="composer"] [data-cap-part~="button"] {
6
+ outline-color: rgb(1, 2, 3);
7
+ }
8
+
9
+ [data-cap-state~="run=running"] {
10
+ --cx-fake-client-run: 1;
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,11 @@
1
+ {
2
+ "name": { "en": "Fake client", "zh": "客户端样例" },
3
+ "schemes": {
4
+ "light": {
5
+ "color": { "accent": "#1F5FBF", "on-accent": "#FFFFFF" }
6
+ },
7
+ "dark": {
8
+ "color": { "accent": "#8FB8FF", "on-accent": "#0B1220" }
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "name": "fake-client-broken",
4
+ "version": "0.1.0",
5
+ "publisher": "Capybara",
6
+ "description": "Test fake: client code that throws (a component, an events listener and a conversation.empty replacement)"
7
+ }
@@ -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
+ });
@@ -7,6 +7,7 @@ import {
7
7
  type ConnectorSession,
8
8
  defineExtension,
9
9
  type ElicitationRequest,
10
+ type ExtensionNet,
10
11
  type Logger,
11
12
  type PromptInfo,
12
13
  type ToolContent,
@@ -33,8 +34,10 @@ import { z } from "zod";
33
34
  * `kind` names another): a deliberately small MCP client
34
35
  * (Streamable HTTP) meant for `startFakeMcpServer` from `@capybara-hq/testing`. It covers the
35
36
  * kernel side of the connector contract, not MCP edge cases:
36
- * - `endpointSchema`: `{ url, headers? }`, https or (with `allowInsecureLoopback`, default on)
37
- * loopback http; credential headers are rejected;
37
+ * - `endpointSchema`: `{ url, headers? }`, https or loopback http (the kernel's `ctx.net` decides
38
+ * what is reachable: test kernels set `net.allowInsecureLoopback`); credential headers are
39
+ * rejected;
40
+ * - every request goes through `ctx.net.fetch` with the session's `orgId`;
38
41
  * - `auth()` before every request, one `onUnauthorized()` + retry on 401, redirects not followed;
39
42
  * a 5xx answer's body is logged as the warning `fake-connector request failed` (the kernel
40
43
  * redacts credentials in extension logs);
@@ -65,8 +68,6 @@ const CLIENT_INFO = { name: "capybara-fake-connector", version: "0.1.0" };
65
68
  const REQUEST_TIMEOUT_MS = 3_600_000;
66
69
 
67
70
  const DeploymentConfig = z.object({
68
- /** Accept http://127.0.0.1 / localhost / [::1] endpoints (on by default: this is a test fake). */
69
- allowInsecureLoopback: z.boolean().default(true),
70
71
  /** The auth hint `inspect` reports behind a 401. */
71
72
  inspectAuth: z.enum(["bearer", "api_key"]).default("bearer"),
72
73
  /**
@@ -83,13 +84,14 @@ const DeploymentConfig = z.object({
83
84
  /** The `_meta` key of a remote tool that names the remote tool serving it (its route). */
84
85
  export const FAKE_ROUTE_META = "fake/route";
85
86
 
86
- const isLoopbackHttp = (u: URL): boolean =>
87
- u.protocol === "http:" && ["127.0.0.1", "localhost", "[::1]"].includes(u.hostname);
88
-
89
- const urlAllowed = (raw: string, loopback: boolean): boolean => {
87
+ /**
88
+ * http or https; whether the target is reachable is `ctx.net`'s call at request time (http only for
89
+ * an org-allowed `http://host:port` origin, or loopback under `net.allowInsecureLoopback`).
90
+ */
91
+ const urlAllowed = (raw: string): boolean => {
90
92
  try {
91
93
  const u = new URL(raw);
92
- return u.protocol === "https:" || (loopback && isLoopbackHttp(u));
94
+ return u.protocol === "https:" || u.protocol === "http:";
93
95
  } catch {
94
96
  return true; // z.url() reports the format error
95
97
  }
@@ -99,11 +101,11 @@ const isCredentialHeader = (name: string): boolean =>
99
101
  ["authorization", "proxy-authorization", "cookie"].includes(name.toLowerCase());
100
102
 
101
103
  /** The endpoint: the server URL and optional non-secret fixed headers. */
102
- export function fakeEndpointSchema(allowInsecureLoopback: boolean) {
104
+ export function fakeEndpointSchema() {
103
105
  return z
104
106
  .object({
105
- url: z.url().refine((v) => urlAllowed(v, allowInsecureLoopback), {
106
- message: "URL must use https (plain http only for loopback hosts)",
107
+ url: z.url().refine(urlAllowed, {
108
+ message: "URL must use http or https",
107
109
  }),
108
110
  /** Free-form text the connector ignores (large-endpoint tests). */
109
111
  notesText: z.string().optional(),
@@ -174,6 +176,8 @@ async function guarded<T>(work: () => Promise<T>): Promise<T> {
174
176
 
175
177
  /** A fetch that injects `auth()` before every request and retries once after `onUnauthorized()`. */
176
178
  function authedFetch(
179
+ net: ExtensionNet,
180
+ orgId: string,
177
181
  endpoint: Endpoint,
178
182
  auth: ConnectorOpenArgs["auth"] | undefined,
179
183
  onUnauthorized: ConnectorOpenArgs["onUnauthorized"] | undefined,
@@ -190,7 +194,11 @@ function authedFetch(
190
194
  for (const [k, v] of Object.entries(endpoint.headers)) if (!headers.has(k)) headers.set(k, v);
191
195
  for (const [k, v] of Object.entries(inj.headers)) headers.set(k, v);
192
196
  const s = init?.signal ? AbortSignal.any([init.signal, signal]) : signal;
193
- return fetch(url, { ...init, headers, signal: s, redirect: "manual" });
197
+ return net.fetch(
198
+ url.toString(),
199
+ { ...init, headers, signal: s, redirect: "manual" },
200
+ { orgId },
201
+ );
194
202
  };
195
203
  const noRedirect = async (r: Response) => {
196
204
  if (r.status >= 300 && r.status < 400) {
@@ -275,11 +283,20 @@ async function connect(
275
283
  }
276
284
 
277
285
  async function openSession(
286
+ net: ExtensionNet,
278
287
  endpoint: Endpoint,
279
288
  args: ConnectorOpenArgs,
280
289
  log?: Logger,
281
290
  ): Promise<ConnectorSession> {
282
- const fetchImpl = authedFetch(endpoint, args.auth, args.onUnauthorized, args.signal, log);
291
+ const fetchImpl = authedFetch(
292
+ net,
293
+ args.orgId,
294
+ endpoint,
295
+ args.auth,
296
+ args.onUnauthorized,
297
+ args.signal,
298
+ log,
299
+ );
283
300
  const { client, transport } = await connect(endpoint, fetchImpl, args);
284
301
  const opts = (signal: AbortSignal = args.signal) => ({ signal, timeout: REQUEST_TIMEOUT_MS });
285
302
  const session: ConnectorSession = {
@@ -412,12 +429,14 @@ const authHint = (kind: InspectAuth): AuthHint =>
412
429
 
413
430
  /** Install preview without credentials: 401 -> the configured auth hint; otherwise the tools as operations. */
414
431
  async function inspect(
432
+ net: ExtensionNet,
433
+ orgId: string,
415
434
  endpoint: Endpoint,
416
435
  signal: AbortSignal,
417
436
  hint: InspectAuth,
418
437
  ): Promise<ConnectorInspection> {
419
438
  let unauthorized = false;
420
- const probe = authedFetch(endpoint, undefined, undefined, signal);
439
+ const probe = authedFetch(net, orgId, endpoint, undefined, undefined, signal);
421
440
  const fetchImpl = async (input: string | URL, init?: RequestInit) => {
422
441
  const r = await probe(input, init);
423
442
  if (r.status === 401) unauthorized = true;
@@ -447,17 +466,18 @@ async function inspect(
447
466
 
448
467
  /** Creates the fake connector (exported for unit tests that call it without a kernel). */
449
468
  export function createFakeConnector(
450
- allowInsecureLoopback: boolean,
469
+ net: ExtensionNet,
451
470
  inspectAuth: InspectAuth = "bearer",
452
471
  kind = "fake",
453
472
  log?: Logger,
454
473
  ): Connector {
455
- const schema = fakeEndpointSchema(allowInsecureLoopback);
474
+ const schema = fakeEndpointSchema();
456
475
  return {
457
476
  kind,
458
477
  endpointSchema: schema,
459
- open: (args) => openSession(schema.parse(args.endpoint), args, log),
460
- inspect: ({ endpoint, signal }) => inspect(schema.parse(endpoint), signal, inspectAuth),
478
+ open: (args) => openSession(net, schema.parse(args.endpoint), args, log),
479
+ inspect: ({ endpoint, signal, orgId }) =>
480
+ inspect(net, orgId, schema.parse(endpoint), signal, inspectAuth),
461
481
  };
462
482
  }
463
483
 
@@ -468,10 +488,10 @@ export default defineExtension({
468
488
  provides: [CONNECTOR_EXTENSION_POINT],
469
489
  config: { deployment: DeploymentConfig },
470
490
  setup(ctx) {
471
- const { allowInsecureLoopback, inspectAuth, kind } = DeploymentConfig.parse(ctx.config ?? {});
491
+ const { inspectAuth, kind } = DeploymentConfig.parse(ctx.config ?? {});
472
492
  ctx.provide(
473
493
  CONNECTOR_EXTENSION_POINT,
474
- createFakeConnector(allowInsecureLoopback, inspectAuth, kind, ctx.log),
494
+ createFakeConnector(ctx.net, inspectAuth, kind, ctx.log),
475
495
  );
476
496
  },
477
497
  });
@@ -0,0 +1,7 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "name": "fake-context",
4
+ "version": "0.1.0",
5
+ "publisher": "Capybara",
6
+ "description": "Test fake: a scripted context provider (context@1) and one tool limited to one-to-one conversations"
7
+ }
@@ -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
+ }