@webskill/sdk 0.0.6 → 0.1.0
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/README.md +180 -46
- package/dist/browser.d.ts +5 -1
- package/dist/browser.js +7 -2
- package/dist/{dist-nXiR40hi.js → dist-CiYRkm71.js} +16 -746
- package/dist/{dist-33_zuOCm.js → dist-DfKKj86A.js} +3 -1
- package/dist/{dist-BQruQ9Hv.js → dist-Dv4a1Jkm.js} +15 -3
- package/dist/governance.d.ts +3 -2
- package/dist/governance.js +2 -2
- package/dist/{index-vi7GPemR.d.ts → index-DuodMfQw.d.ts} +3 -1
- package/dist/{index-DCifjtJx.d.ts → index-S8uza3ld.d.ts} +19 -595
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/mcp.d.ts +3 -1
- package/dist/mcp.js +3 -1
- package/dist/memoryArtifactStore-C9lFVqPF-U8nXvqL9.js +637 -0
- package/dist/node.d.ts +4 -3
- package/dist/node.js +3 -2
- package/dist/testing-pn3NhXSV.js +117 -0
- package/dist/testing.d.ts +73 -0
- package/dist/testing.js +4 -0
- package/dist/types-CgNC-oQu-DCklnS0h.d.ts +539 -0
- package/dist/ui-react.d.ts +1 -1
- package/dist/ui-react.js +1 -1
- package/dist/ui-vue.d.ts +1 -1
- package/dist/ui-vue.js +1 -1
- package/dist/ui.d.ts +17 -4
- package/dist/ui.js +2 -2
- package/package.json +5 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { u as WebSkillError } from "./memoryArtifactStore-C9lFVqPF-U8nXvqL9.js";
|
|
2
|
+
|
|
3
|
+
//#region ../runtime/dist/testing.js
|
|
4
|
+
/**
|
|
5
|
+
* 预设响应序列的确定性 LlmClient;handler 形式可按会话状态动态应答。
|
|
6
|
+
* 默认不含 stream(存量行为);构造传 { streaming: true } 启用流式:
|
|
7
|
+
* 队列项 { stream: [...] } 按预设 delta 序列产出,LlmResponse 项自动合成增量。
|
|
8
|
+
*/
|
|
9
|
+
var MockLlmClient = class {
|
|
10
|
+
calls = [];
|
|
11
|
+
stream;
|
|
12
|
+
#queue;
|
|
13
|
+
constructor(responses, options) {
|
|
14
|
+
this.#queue = [...responses];
|
|
15
|
+
if (options?.streaming) this.stream = (input) => this.#streamImpl(input);
|
|
16
|
+
}
|
|
17
|
+
async complete(input) {
|
|
18
|
+
this.calls.push(input);
|
|
19
|
+
const next = this.#queue.shift();
|
|
20
|
+
if (!next) throw new WebSkillError("LLM_REQUEST_FAILED", "MockLlmClient: response queue exhausted");
|
|
21
|
+
if (typeof next === "function") return next(input);
|
|
22
|
+
if ("stream" in next) {
|
|
23
|
+
const events = typeof next.stream === "function" ? next.stream(input) : next.stream;
|
|
24
|
+
let content = "";
|
|
25
|
+
let toolCalls;
|
|
26
|
+
for (const event of events) if (event.type === "text-delta") content += event.delta;
|
|
27
|
+
else if (event.type === "tool-calls") toolCalls = event.toolCalls;
|
|
28
|
+
else if (event.type === "done" && event.content !== void 0) content = event.content;
|
|
29
|
+
return {
|
|
30
|
+
content,
|
|
31
|
+
toolCalls
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return next;
|
|
35
|
+
}
|
|
36
|
+
async *#streamImpl(input) {
|
|
37
|
+
this.calls.push(input);
|
|
38
|
+
const next = this.#queue.shift();
|
|
39
|
+
if (!next) throw new WebSkillError("LLM_REQUEST_FAILED", "MockLlmClient: response queue exhausted");
|
|
40
|
+
if (typeof next !== "function" && "stream" in next) {
|
|
41
|
+
const events = typeof next.stream === "function" ? next.stream(input) : next.stream;
|
|
42
|
+
for (const event of events) yield event;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const response = typeof next === "function" ? await next(input) : next;
|
|
46
|
+
if (response.content) {
|
|
47
|
+
const chunkSize = Math.max(1, Math.ceil(response.content.length / 3));
|
|
48
|
+
for (let i = 0; i < response.content.length; i += chunkSize) yield {
|
|
49
|
+
type: "text-delta",
|
|
50
|
+
delta: response.content.slice(i, i + chunkSize)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (response.toolCalls?.length) yield {
|
|
54
|
+
type: "tool-calls",
|
|
55
|
+
toolCalls: response.toolCalls
|
|
56
|
+
};
|
|
57
|
+
yield { type: "done" };
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* 测试用 UiBridge:按请求 id 或类型预设应答(永不 resolve 的 handler 可模拟超时);
|
|
62
|
+
* 记录全部请求供断言。
|
|
63
|
+
*/
|
|
64
|
+
var MockUiBridge = class {
|
|
65
|
+
requests = [];
|
|
66
|
+
#answers = /* @__PURE__ */ new Map();
|
|
67
|
+
#fallback;
|
|
68
|
+
/** key 为请求 id 或请求类型('ask' | 'confirm' | 'form' | 'select') */
|
|
69
|
+
respondTo(key, answer) {
|
|
70
|
+
this.#answers.set(key, answer);
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
setFallback(answer) {
|
|
74
|
+
this.#fallback = answer;
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
async request(input) {
|
|
78
|
+
this.requests.push(input);
|
|
79
|
+
const answer = this.#answers.get(input.id) ?? this.#answers.get(input.type) ?? this.#fallback;
|
|
80
|
+
if (!answer) return {
|
|
81
|
+
id: input.id,
|
|
82
|
+
cancelled: true
|
|
83
|
+
};
|
|
84
|
+
return typeof answer === "function" ? answer(input) : answer;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
/** 内存 MemoryStore:测试与浏览器降级用 */
|
|
88
|
+
var InMemoryStore = class {
|
|
89
|
+
#data = /* @__PURE__ */ new Map();
|
|
90
|
+
async get(scope, key) {
|
|
91
|
+
return this.#data.get(scope)?.get(key);
|
|
92
|
+
}
|
|
93
|
+
async set(scope, key, value) {
|
|
94
|
+
let bucket = this.#data.get(scope);
|
|
95
|
+
if (!bucket) {
|
|
96
|
+
bucket = /* @__PURE__ */ new Map();
|
|
97
|
+
this.#data.set(scope, bucket);
|
|
98
|
+
}
|
|
99
|
+
bucket.set(key, value);
|
|
100
|
+
}
|
|
101
|
+
async delete(scope, key) {
|
|
102
|
+
this.#data.get(scope)?.delete(key);
|
|
103
|
+
}
|
|
104
|
+
async list(scope) {
|
|
105
|
+
return [...(this.#data.get(scope) ?? /* @__PURE__ */ new Map()).entries()].map(([key, value]) => ({
|
|
106
|
+
key,
|
|
107
|
+
value
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
async clear(scope) {
|
|
111
|
+
if (scope === void 0) this.#data.clear();
|
|
112
|
+
else this.#data.delete(scope);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { MockLlmClient as n, MockUiBridge as r, InMemoryStore as t };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { c as LlmClient, d as LlmResponse, f as LlmStreamEvent, h as MemoryStore, l as LlmCompleteInput, n as ArtifactStore, o as InteractionRequest, s as InteractionResponse, t as Artifact, v as UiBridge } from "./types-CgNC-oQu-DCklnS0h.js";
|
|
2
|
+
//#region ../runtime/dist/testing.d.ts
|
|
3
|
+
//#region src/llm/mockLlmClient.d.ts
|
|
4
|
+
type MockLlmHandler = (input: LlmCompleteInput) => LlmResponse | Promise<LlmResponse>;
|
|
5
|
+
type MockLlmQueueItem = LlmResponse | MockLlmHandler | {
|
|
6
|
+
stream: LlmStreamEvent[] | ((input: LlmCompleteInput) => LlmStreamEvent[]);
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* 预设响应序列的确定性 LlmClient;handler 形式可按会话状态动态应答。
|
|
10
|
+
* 默认不含 stream(存量行为);构造传 { streaming: true } 启用流式:
|
|
11
|
+
* 队列项 { stream: [...] } 按预设 delta 序列产出,LlmResponse 项自动合成增量。
|
|
12
|
+
*/
|
|
13
|
+
declare class MockLlmClient implements LlmClient {
|
|
14
|
+
#private;
|
|
15
|
+
readonly calls: LlmCompleteInput[];
|
|
16
|
+
readonly stream?: (input: LlmCompleteInput) => AsyncIterable<LlmStreamEvent>;
|
|
17
|
+
constructor(responses: MockLlmQueueItem[], options?: {
|
|
18
|
+
streaming?: boolean;
|
|
19
|
+
});
|
|
20
|
+
complete(input: LlmCompleteInput): Promise<LlmResponse>;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/interaction/mockUiBridge.d.ts
|
|
24
|
+
type MockUiAnswer = InteractionResponse | ((request: InteractionRequest) => InteractionResponse | Promise<InteractionResponse>);
|
|
25
|
+
/**
|
|
26
|
+
* 测试用 UiBridge:按请求 id 或类型预设应答(永不 resolve 的 handler 可模拟超时);
|
|
27
|
+
* 记录全部请求供断言。
|
|
28
|
+
*/
|
|
29
|
+
declare class MockUiBridge implements UiBridge {
|
|
30
|
+
#private;
|
|
31
|
+
readonly requests: InteractionRequest[];
|
|
32
|
+
/** key 为请求 id 或请求类型('ask' | 'confirm' | 'form' | 'select') */
|
|
33
|
+
respondTo(key: string, answer: MockUiAnswer): this;
|
|
34
|
+
setFallback(answer: MockUiAnswer): this;
|
|
35
|
+
request(input: InteractionRequest): Promise<InteractionResponse>;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/memory/inMemoryStore.d.ts
|
|
39
|
+
/** 内存 MemoryStore:测试与浏览器降级用 */
|
|
40
|
+
declare class InMemoryStore implements MemoryStore {
|
|
41
|
+
#private;
|
|
42
|
+
get(scope: string, key: string): Promise<unknown>;
|
|
43
|
+
set(scope: string, key: string, value: unknown): Promise<void>;
|
|
44
|
+
delete(scope: string, key: string): Promise<void>;
|
|
45
|
+
list(scope: string): Promise<Array<{
|
|
46
|
+
key: string;
|
|
47
|
+
value: unknown;
|
|
48
|
+
}>>;
|
|
49
|
+
clear(scope?: string): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/artifacts/memoryArtifactStore.d.ts
|
|
53
|
+
/** 内存 ArtifactStore:测试与浏览器降级用;索引随进程生命周期存在 */
|
|
54
|
+
declare class MemoryArtifactStore implements ArtifactStore {
|
|
55
|
+
#private;
|
|
56
|
+
createTextArtifact(input: {
|
|
57
|
+
runId: string;
|
|
58
|
+
path: string;
|
|
59
|
+
content: string;
|
|
60
|
+
mimeType?: string;
|
|
61
|
+
metadata?: Record<string, unknown>;
|
|
62
|
+
}): Promise<Artifact>;
|
|
63
|
+
createBinaryArtifact(input: {
|
|
64
|
+
runId: string;
|
|
65
|
+
path: string;
|
|
66
|
+
content: Uint8Array;
|
|
67
|
+
mimeType?: string;
|
|
68
|
+
metadata?: Record<string, unknown>;
|
|
69
|
+
}): Promise<Artifact>;
|
|
70
|
+
listArtifacts(runId: string): Promise<Artifact[]>;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { InMemoryStore, MemoryArtifactStore, MockLlmClient, type MockLlmHandler, type MockLlmQueueItem, type MockUiAnswer, MockUiBridge };
|
package/dist/testing.js
ADDED