@capybara-hq/plugin-model-fake 0.1.0-rc.0 → 0.1.0-rc.2
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/.capybara-plugin/plugin.json +86 -2
- package/dist/index.mjs +39 -12
- package/package.json +1 -1
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"name": "model-fake",
|
|
4
|
-
"version": "0.1.0-rc.
|
|
4
|
+
"version": "0.1.0-rc.2",
|
|
5
5
|
"publisher": "Capybara",
|
|
6
6
|
"description": "Deterministic scripted model provider (model-provider@2) for runtime tests, e2e tests and keyless demos",
|
|
7
|
+
"displayName": {
|
|
8
|
+
"zh": "模拟模型",
|
|
9
|
+
"en": "Fake model"
|
|
10
|
+
},
|
|
7
11
|
"homepage": "https://github.com/capybara-hq/core/tree/main/plugins/model-fake#readme",
|
|
8
12
|
"extension": {
|
|
9
13
|
"entry": "./dist/index.mjs",
|
|
10
14
|
"manifest": {
|
|
11
15
|
"name": "model-fake",
|
|
12
|
-
"version": "0.1.0-rc.
|
|
16
|
+
"version": "0.1.0-rc.2",
|
|
13
17
|
"sdk": "^0.1.0-rc.0",
|
|
14
18
|
"provides": [
|
|
15
19
|
"model-provider@2"
|
|
@@ -27,6 +31,86 @@
|
|
|
27
31
|
],
|
|
28
32
|
"org": []
|
|
29
33
|
}
|
|
34
|
+
},
|
|
35
|
+
"configSchemas": {
|
|
36
|
+
"deployment": {
|
|
37
|
+
"type": "object",
|
|
38
|
+
"properties": {
|
|
39
|
+
"models": {
|
|
40
|
+
"type": "array",
|
|
41
|
+
"items": {
|
|
42
|
+
"type": "object",
|
|
43
|
+
"properties": {
|
|
44
|
+
"id": {
|
|
45
|
+
"type": "string",
|
|
46
|
+
"minLength": 1,
|
|
47
|
+
"x-ui": {
|
|
48
|
+
"label": {
|
|
49
|
+
"zh": "模型 ID",
|
|
50
|
+
"en": "Model ID"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"title": "Model ID"
|
|
54
|
+
},
|
|
55
|
+
"contextWindow": {
|
|
56
|
+
"type": "integer",
|
|
57
|
+
"exclusiveMinimum": 0,
|
|
58
|
+
"maximum": 9007199254740991,
|
|
59
|
+
"x-ui": {
|
|
60
|
+
"label": {
|
|
61
|
+
"zh": "上下文窗口",
|
|
62
|
+
"en": "Context window"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"title": "Context window"
|
|
66
|
+
},
|
|
67
|
+
"streamIdleTimeoutMs": {
|
|
68
|
+
"type": "integer",
|
|
69
|
+
"exclusiveMinimum": 0,
|
|
70
|
+
"maximum": 9007199254740991,
|
|
71
|
+
"x-ui": {
|
|
72
|
+
"label": {
|
|
73
|
+
"zh": "流空闲超时(毫秒)",
|
|
74
|
+
"en": "Stream idle timeout (ms)"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"title": "Stream idle timeout (ms)"
|
|
78
|
+
},
|
|
79
|
+
"vision": {
|
|
80
|
+
"type": "boolean",
|
|
81
|
+
"x-ui": {
|
|
82
|
+
"label": {
|
|
83
|
+
"zh": "图片输入",
|
|
84
|
+
"en": "Image input"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"title": "Image input"
|
|
88
|
+
},
|
|
89
|
+
"documents": {
|
|
90
|
+
"type": "boolean",
|
|
91
|
+
"x-ui": {
|
|
92
|
+
"label": {
|
|
93
|
+
"zh": "文档输入",
|
|
94
|
+
"en": "Document input"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"title": "Document input"
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"required": [
|
|
101
|
+
"id"
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
"x-ui": {
|
|
105
|
+
"label": {
|
|
106
|
+
"zh": "模型",
|
|
107
|
+
"en": "Models"
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"title": "Models"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
30
114
|
}
|
|
31
115
|
}
|
|
32
116
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,10 @@ const __capybara_filename = __capybaraFileURLToPath(import.meta.url);
|
|
|
6
6
|
const __capybara_dirname = __capybaraPathDirname(__capybara_filename);
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
defineExtension,
|
|
11
|
+
MODEL_PROVIDER_EXTENSION_POINT_V2
|
|
12
|
+
} from "@capybara-hq/plugin-sdk";
|
|
10
13
|
import { z } from "zod";
|
|
11
14
|
|
|
12
15
|
// src/script.ts
|
|
@@ -170,6 +173,20 @@ function scripted(req) {
|
|
|
170
173
|
error: new ModelError(kind, `Scripted ${kind} failure`)
|
|
171
174
|
};
|
|
172
175
|
}
|
|
176
|
+
const multi = /^tools:(\[[\s\S]*\])$/.exec(text);
|
|
177
|
+
if (multi) {
|
|
178
|
+
try {
|
|
179
|
+
const calls = JSON.parse(multi[1]);
|
|
180
|
+
const [first2, ...more] = calls;
|
|
181
|
+
if (first2 === void 0) throw new Error("empty");
|
|
182
|
+
return { kind: "tool", name: first2.name, input: first2.input, more };
|
|
183
|
+
} catch {
|
|
184
|
+
return {
|
|
185
|
+
kind: "fail",
|
|
186
|
+
error: new ModelError("invalid_request", "tools directive carries invalid JSON")
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
173
190
|
const tool = /^tool:([^:]+):([\s\S]*)$/.exec(text);
|
|
174
191
|
if (tool) {
|
|
175
192
|
try {
|
|
@@ -242,13 +259,22 @@ function createFakeProvider(opts) {
|
|
|
242
259
|
cacheWriteTokens: cache.write
|
|
243
260
|
});
|
|
244
261
|
if (p.kind === "tool") {
|
|
245
|
-
const
|
|
246
|
-
const content =
|
|
262
|
+
const calls = [{ name: p.name, input: p.input }, ...p.more ?? []];
|
|
263
|
+
const content = calls.map((c, i) => ({
|
|
264
|
+
type: "tool_call",
|
|
265
|
+
id: `call_${createHash("sha256").update(
|
|
266
|
+
`${req.messages.length}:${i === 0 ? "" : `${i}:`}${c.name}:${JSON.stringify(c.input)}`
|
|
267
|
+
).digest("hex").slice(0, 12)}`,
|
|
268
|
+
name: c.name,
|
|
269
|
+
input: c.input
|
|
270
|
+
}));
|
|
247
271
|
yield {
|
|
248
272
|
type: "message_complete",
|
|
249
273
|
content,
|
|
250
274
|
stopReason: "tool_use",
|
|
251
|
-
usage: usage(
|
|
275
|
+
usage: usage(
|
|
276
|
+
calls.reduce((n, c) => n + c.name.length + JSON.stringify(c.input ?? null).length, 0)
|
|
277
|
+
)
|
|
252
278
|
};
|
|
253
279
|
return;
|
|
254
280
|
}
|
|
@@ -279,21 +305,22 @@ function createFakeProvider(opts) {
|
|
|
279
305
|
}
|
|
280
306
|
|
|
281
307
|
// src/index.ts
|
|
308
|
+
var label = (zh, en) => ({ ui: { label: { zh, en } } });
|
|
282
309
|
var DeploymentConfig = z.object({
|
|
283
310
|
models: z.array(
|
|
284
311
|
z.object({
|
|
285
|
-
id: z.string().min(1),
|
|
286
|
-
contextWindow: z.number().int().positive().optional(),
|
|
287
|
-
streamIdleTimeoutMs: z.number().int().positive().optional(),
|
|
288
|
-
/**
|
|
289
|
-
vision: z.boolean().optional(),
|
|
290
|
-
documents: z.boolean().optional()
|
|
312
|
+
id: z.string().min(1).meta(label("模型 ID", "Model ID")),
|
|
313
|
+
contextWindow: z.number().int().positive().optional().meta(label("上下文窗口", "Context window")),
|
|
314
|
+
streamIdleTimeoutMs: z.number().int().positive().optional().meta(label("流空闲超时(毫秒)", "Stream idle timeout (ms)")),
|
|
315
|
+
/** Declares image / document input support (default false). */
|
|
316
|
+
vision: z.boolean().optional().meta(label("图片输入", "Image input")),
|
|
317
|
+
documents: z.boolean().optional().meta(label("文档输入", "Document input"))
|
|
291
318
|
})
|
|
292
|
-
).optional()
|
|
319
|
+
).optional().meta(label("模型", "Models"))
|
|
293
320
|
});
|
|
294
321
|
var index_default = defineExtension({
|
|
295
322
|
name: "model-fake",
|
|
296
|
-
version: "0.1.0-rc.
|
|
323
|
+
version: "0.1.0-rc.2",
|
|
297
324
|
sdk: "^0.1.0-rc.0",
|
|
298
325
|
provides: [MODEL_PROVIDER_EXTENSION_POINT_V2],
|
|
299
326
|
config: { deployment: DeploymentConfig },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/plugin-model-fake",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Deterministic scripted model provider (model-provider@2) for runtime tests, e2e tests and keyless demos",
|