@webskill/sdk 0.1.2 → 0.1.3
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/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/{dist-SarUS8EP.js → dist-Cm_j6Jol.js} +40 -7
- package/dist/{dist-DRsnVw6A.js → dist-DZobLFh6.js} +428 -5
- package/dist/governance.d.ts +2 -2
- package/dist/governance.js +1 -1
- package/dist/{index-DkPK44Ji.d.ts → index-CPuwsnmB.d.ts} +12 -3
- package/dist/{index-fjRF4H5o.d.ts → index-CqMuvcb2.d.ts} +47 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/mcp.d.ts +24 -2
- package/dist/mcp.js +57 -12
- package/dist/node.d.ts +3 -3
- package/dist/node.js +3 -3
- package/dist/ui.d.ts +1 -1
- package/dist/ui.js +1 -1
- package/package.json +1 -1
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { H as SkillsLockfile, L as SkillManifest, P as SkillInstallSource, S as FileSystemProvider, W as VerifyResult, _ as RenderResultRequest, a as InteractionPolicy, c as LlmClient, d as LlmResponse, f as LlmStreamEvent, o as InteractionRequest, s as InteractionResponse, v as UiBridge, x as FileStat } from "./types-CgNC-oQu-Dq_A1yA-.js";
|
|
2
|
-
import {
|
|
2
|
+
import { $ as ToolDefinition, N as NetworkPolicy, X as ScriptExecutionContext, Z as ScriptExecutor, d as BridgeCapabilities, m as BridgeResponse, p as BridgeRequest, st as WebSkillApi, tt as ToolResult, u as ApprovalScope, ut as bridgeError, v as ExternalSkillProvider, xt as parseBridgeRequest, y as ExternalToolSource } from "./index-CqMuvcb2.js";
|
|
3
3
|
//#region ../browser/dist/index.d.ts
|
|
4
4
|
//#region src/fs/featureDetection.d.ts
|
|
5
5
|
/** 检测当前环境是否可用 OPFS(navigator.storage.getDirectory) */
|
package/dist/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { E as verifyManifest, T as validateSkills, _ as isValidSkillName, b as parseSkillMarkdown, d as buildManifest, g as exportSkills, l as WebSkillError, n as SKILLS_LOCKFILE, o as SKILL_PACK_FILE, r as SKILL_MANIFEST_FILE, s as SkillDiscovery, u as buildCatalog, w as resolveInsideRoot, x as parseSkillPackManifest } from "./dist-DS1sfgHa.js";
|
|
2
|
-
import { A as
|
|
2
|
+
import { A as mergeCatalogEntries, M as normalizeToolContent, N as parseBridgeRequest, S as bridgeError, T as createWebSkillApi, c as FsArtifactStore, h as ProgressiveRouter, i as AgentLoop, j as networkUrlHost, k as isNetworkAllowed, l as FsMemoryStore, m as OpenAiCompatibleClient, o as CapabilityApproval, u as FsRunSnapshotStore, y as RUN_SNAPSHOT_SCHEMA_VERSION } from "./dist-DZobLFh6.js";
|
|
3
3
|
import { n as MockLlmClient } from "./testing-CbM6rJ-E.js";
|
|
4
4
|
import { unzipSync } from "fflate";
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { E as verifyManifest, T as validateSkills, _ as isValidSkillName, b as parseSkillMarkdown, d as buildManifest, g as exportSkills, l as WebSkillError, n as SKILLS_LOCKFILE, o as SKILL_PACK_FILE, r as SKILL_MANIFEST_FILE, w as resolveInsideRoot, x as parseSkillPackManifest } from "./dist-DS1sfgHa.js";
|
|
2
|
-
import {
|
|
2
|
+
import { M as normalizeToolContent, N as parseBridgeRequest, S as bridgeError, c as FsArtifactStore, j as networkUrlHost, k as isNetworkAllowed, l as FsMemoryStore, o as CapabilityApproval } from "./dist-DZobLFh6.js";
|
|
3
3
|
import { unzipSync, zipSync } from "fflate";
|
|
4
4
|
import { existsSync, promises, readFileSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
@@ -1328,11 +1328,8 @@ var SkillManager = class {
|
|
|
1328
1328
|
return options.outPath;
|
|
1329
1329
|
}
|
|
1330
1330
|
};
|
|
1331
|
-
/**
|
|
1332
|
-
|
|
1333
|
-
* 读取 VITE_BASE_URL / VITE_API_KEY / VITE_MODEL_NAME;缺项返回 undefined 供测试 skip 判断。
|
|
1334
|
-
*/
|
|
1335
|
-
function loadLlmConfigFromEnv(dotenvPath = ".env") {
|
|
1331
|
+
/** 解析 .env(简单 KEY=VALUE 行解析,不引依赖);文件缺失返回 undefined */
|
|
1332
|
+
function readEnvVars(dotenvPath) {
|
|
1336
1333
|
let raw;
|
|
1337
1334
|
try {
|
|
1338
1335
|
raw = readFileSync(dotenvPath, "utf8");
|
|
@@ -1350,6 +1347,14 @@ function loadLlmConfigFromEnv(dotenvPath = ".env") {
|
|
|
1350
1347
|
if (value.startsWith("\"") && value.endsWith("\"") || value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
|
|
1351
1348
|
vars.set(key, value);
|
|
1352
1349
|
}
|
|
1350
|
+
return vars;
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* 读取 VITE_BASE_URL / VITE_API_KEY / VITE_MODEL_NAME;缺项返回 undefined 供测试 skip 判断。
|
|
1354
|
+
*/
|
|
1355
|
+
function loadLlmConfigFromEnv(dotenvPath = ".env") {
|
|
1356
|
+
const vars = readEnvVars(dotenvPath);
|
|
1357
|
+
if (!vars) return void 0;
|
|
1353
1358
|
const baseUrl = vars.get("VITE_BASE_URL");
|
|
1354
1359
|
const apiKey = vars.get("VITE_API_KEY");
|
|
1355
1360
|
const model = vars.get("VITE_MODEL_NAME");
|
|
@@ -1360,6 +1365,34 @@ function loadLlmConfigFromEnv(dotenvPath = ".env") {
|
|
|
1360
1365
|
model
|
|
1361
1366
|
};
|
|
1362
1367
|
}
|
|
1368
|
+
/** ANTHROPIC_API_KEY / ANTHROPIC_MODEL(可选 ANTHROPIC_BASE_URL);缺项返回 undefined */
|
|
1369
|
+
function loadAnthropicConfigFromEnv(dotenvPath = ".env") {
|
|
1370
|
+
const vars = readEnvVars(dotenvPath);
|
|
1371
|
+
if (!vars) return void 0;
|
|
1372
|
+
const apiKey = vars.get("ANTHROPIC_API_KEY");
|
|
1373
|
+
const model = vars.get("ANTHROPIC_MODEL");
|
|
1374
|
+
if (!apiKey || !model) return void 0;
|
|
1375
|
+
const baseUrl = vars.get("ANTHROPIC_BASE_URL");
|
|
1376
|
+
return {
|
|
1377
|
+
apiKey,
|
|
1378
|
+
model,
|
|
1379
|
+
...baseUrl ? { baseUrl } : {}
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
/** GOOGLE_API_KEY / GOOGLE_MODEL(可选 GOOGLE_BASE_URL);缺项返回 undefined */
|
|
1383
|
+
function loadGoogleConfigFromEnv(dotenvPath = ".env") {
|
|
1384
|
+
const vars = readEnvVars(dotenvPath);
|
|
1385
|
+
if (!vars) return void 0;
|
|
1386
|
+
const apiKey = vars.get("GOOGLE_API_KEY");
|
|
1387
|
+
const model = vars.get("GOOGLE_MODEL");
|
|
1388
|
+
if (!apiKey || !model) return void 0;
|
|
1389
|
+
const baseUrl = vars.get("GOOGLE_BASE_URL");
|
|
1390
|
+
return {
|
|
1391
|
+
apiKey,
|
|
1392
|
+
model,
|
|
1393
|
+
...baseUrl ? { baseUrl } : {}
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1363
1396
|
let capabilitiesCache;
|
|
1364
1397
|
/**
|
|
1365
1398
|
* 探测 LLM 能力(结果模块级缓存):
|
|
@@ -1433,4 +1466,4 @@ async function doProbeLlmCapabilities(config) {
|
|
|
1433
1466
|
}
|
|
1434
1467
|
|
|
1435
1468
|
//#endregion
|
|
1436
|
-
export { NodeScriptExecutor as a, SkillManager as c,
|
|
1469
|
+
export { NodeScriptExecutor as a, SkillManager as c, loadLlmConfigFromEnv as d, probeLlmCapabilities as f, NodeFS as i, loadAnthropicConfigFromEnv as l, FileArtifactStore as n, OxcSchemaInferer as o, readArchiveManifest as p, FileMemoryStore as r, SandboxedScriptExecutor as s, CliUiBridge as t, loadGoogleConfigFromEnv as u };
|
|
@@ -33,7 +33,7 @@ const toOpenAiTools = (tools) => tools.map((tool) => ({
|
|
|
33
33
|
parameters: tool.inputSchema
|
|
34
34
|
}
|
|
35
35
|
}));
|
|
36
|
-
const errorMessage = (e) => e instanceof Error ? e.message : String(e);
|
|
36
|
+
const errorMessage$2 = (e) => e instanceof Error ? e.message : String(e);
|
|
37
37
|
/** OpenAI chat completions 协议客户端(兼容端点通用) */
|
|
38
38
|
var OpenAiCompatibleClient = class {
|
|
39
39
|
#config;
|
|
@@ -57,7 +57,7 @@ var OpenAiCompatibleClient = class {
|
|
|
57
57
|
try {
|
|
58
58
|
data = await res.json();
|
|
59
59
|
} catch (e) {
|
|
60
|
-
throw new WebSkillError("LLM_REQUEST_FAILED", `Failed to parse LLM response: ${errorMessage(e)}`, e);
|
|
60
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `Failed to parse LLM response: ${errorMessage$2(e)}`, e);
|
|
61
61
|
}
|
|
62
62
|
return this.#parseResponse(data);
|
|
63
63
|
}
|
|
@@ -79,7 +79,7 @@ var OpenAiCompatibleClient = class {
|
|
|
79
79
|
try {
|
|
80
80
|
chunk = JSON.parse(data);
|
|
81
81
|
} catch (e) {
|
|
82
|
-
throw new WebSkillError("LLM_REQUEST_FAILED", `Failed to parse LLM stream frame: ${errorMessage(e)}`, data);
|
|
82
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `Failed to parse LLM stream frame: ${errorMessage$2(e)}`, data);
|
|
83
83
|
}
|
|
84
84
|
const delta = chunk.choices?.[0]?.delta;
|
|
85
85
|
if (!delta) return;
|
|
@@ -161,7 +161,7 @@ var OpenAiCompatibleClient = class {
|
|
|
161
161
|
signal: input.signal ?? (this.#config.requestTimeoutMs ? AbortSignal.timeout(this.#config.requestTimeoutMs) : null)
|
|
162
162
|
});
|
|
163
163
|
} catch (e) {
|
|
164
|
-
throw new WebSkillError("LLM_REQUEST_FAILED", `LLM request failed: ${errorMessage(e)}`, e);
|
|
164
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `LLM request failed: ${errorMessage$2(e)}`, e);
|
|
165
165
|
}
|
|
166
166
|
if (!res.ok) {
|
|
167
167
|
const detail = await res.text().catch(() => "");
|
|
@@ -196,10 +196,433 @@ var OpenAiCompatibleClient = class {
|
|
|
196
196
|
toolCalls: toolCalls?.length ? toolCalls : void 0,
|
|
197
197
|
raw: data
|
|
198
198
|
};
|
|
199
|
+
} catch (e) {
|
|
200
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `Failed to interpret LLM response: ${errorMessage$2(e)}`, data);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
const ANTHROPIC_VERSION = "2023-06-01";
|
|
205
|
+
const errorMessage$1 = (e) => e instanceof Error ? e.message : String(e);
|
|
206
|
+
/** LlmMessage 序列 → system 独立参数 + user/assistant 消息(tool 结果合并进 user 消息 tool_result blocks) */
|
|
207
|
+
function toAnthropicMessages(messages) {
|
|
208
|
+
const system = messages.filter((m) => m.role === "system").map((m) => m.content).join("\n");
|
|
209
|
+
const out = [];
|
|
210
|
+
for (const msg of messages) {
|
|
211
|
+
if (msg.role === "system") continue;
|
|
212
|
+
if (msg.role === "tool") {
|
|
213
|
+
const block = {
|
|
214
|
+
type: "tool_result",
|
|
215
|
+
tool_use_id: msg.toolCallId ?? "",
|
|
216
|
+
content: msg.content
|
|
217
|
+
};
|
|
218
|
+
const last = out.at(-1);
|
|
219
|
+
if (last && last.role === "user" && Array.isArray(last.content)) last.content.push(block);
|
|
220
|
+
else out.push({
|
|
221
|
+
role: "user",
|
|
222
|
+
content: [block]
|
|
223
|
+
});
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (msg.role === "assistant" && msg.toolCalls?.length) {
|
|
227
|
+
const content = [];
|
|
228
|
+
if (msg.content !== "") content.push({
|
|
229
|
+
type: "text",
|
|
230
|
+
text: msg.content
|
|
231
|
+
});
|
|
232
|
+
for (const call of msg.toolCalls) content.push({
|
|
233
|
+
type: "tool_use",
|
|
234
|
+
id: call.id,
|
|
235
|
+
name: call.name,
|
|
236
|
+
input: call.arguments
|
|
237
|
+
});
|
|
238
|
+
out.push({
|
|
239
|
+
role: "assistant",
|
|
240
|
+
content
|
|
241
|
+
});
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
out.push({
|
|
245
|
+
role: msg.role,
|
|
246
|
+
content: msg.content
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return system === "" ? { messages: out } : {
|
|
250
|
+
system,
|
|
251
|
+
messages: out
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
const toAnthropicTools = (tools) => tools.map((tool) => ({
|
|
255
|
+
name: tool.name,
|
|
256
|
+
...tool.description ? { description: tool.description } : {},
|
|
257
|
+
input_schema: tool.inputSchema
|
|
258
|
+
}));
|
|
259
|
+
/** Anthropic Messages API 客户端(零依赖 fetch;Node/浏览器通用) */
|
|
260
|
+
var AnthropicClient = class {
|
|
261
|
+
#config;
|
|
262
|
+
#fetch;
|
|
263
|
+
constructor(config) {
|
|
264
|
+
this.#config = config;
|
|
265
|
+
this.#fetch = config.fetchImpl ?? fetch;
|
|
266
|
+
}
|
|
267
|
+
#baseUrl() {
|
|
268
|
+
return (this.#config.baseUrl ?? "https://api.anthropic.com").replace(/\/+$/, "");
|
|
269
|
+
}
|
|
270
|
+
#headers() {
|
|
271
|
+
return {
|
|
272
|
+
"content-type": "application/json",
|
|
273
|
+
"x-api-key": this.#config.apiKey,
|
|
274
|
+
"anthropic-version": ANTHROPIC_VERSION,
|
|
275
|
+
"anthropic-dangerous-direct-browser-access": "true"
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
async complete(input) {
|
|
279
|
+
const res = await this.#post(input, false);
|
|
280
|
+
let data;
|
|
281
|
+
try {
|
|
282
|
+
data = await res.json();
|
|
283
|
+
} catch (e) {
|
|
284
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `Failed to parse LLM response: ${errorMessage$1(e)}`, e);
|
|
285
|
+
}
|
|
286
|
+
return this.#parseResponse(data);
|
|
287
|
+
}
|
|
288
|
+
/** SSE 流式:text_delta → text-delta;input_json_delta 按 block index 聚合 → tool-calls */
|
|
289
|
+
async *stream(input) {
|
|
290
|
+
const res = await this.#post(input, true);
|
|
291
|
+
if (!res.body) throw new WebSkillError("LLM_REQUEST_FAILED", "LLM streaming response has no body");
|
|
292
|
+
const toolCallsByIndex = /* @__PURE__ */ new Map();
|
|
293
|
+
const decoder = new TextDecoder();
|
|
294
|
+
const reader = res.body.getReader();
|
|
295
|
+
let buffer = "";
|
|
296
|
+
const handleFrame = function* (data) {
|
|
297
|
+
let chunk;
|
|
298
|
+
try {
|
|
299
|
+
chunk = JSON.parse(data);
|
|
300
|
+
} catch (e) {
|
|
301
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `Failed to parse LLM stream frame: ${errorMessage$1(e)}`, data);
|
|
302
|
+
}
|
|
303
|
+
const type = chunk["type"];
|
|
304
|
+
if (type === "error") throw new WebSkillError("LLM_REQUEST_FAILED", `LLM stream error: ${chunk["error"]?.message ?? data}`);
|
|
305
|
+
if (type === "content_block_start") {
|
|
306
|
+
const block = chunk["content_block"];
|
|
307
|
+
if (block?.["type"] === "tool_use") {
|
|
308
|
+
const index = typeof chunk["index"] === "number" ? chunk["index"] : 0;
|
|
309
|
+
toolCallsByIndex.set(index, {
|
|
310
|
+
id: typeof block["id"] === "string" ? block["id"] : "",
|
|
311
|
+
name: typeof block["name"] === "string" ? block["name"] : "",
|
|
312
|
+
arguments: ""
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (type === "content_block_delta") {
|
|
318
|
+
const index = typeof chunk["index"] === "number" ? chunk["index"] : 0;
|
|
319
|
+
const delta = chunk["delta"];
|
|
320
|
+
if (delta?.["type"] === "text_delta" && typeof delta["text"] === "string" && delta["text"] !== "") {
|
|
321
|
+
yield {
|
|
322
|
+
type: "text-delta",
|
|
323
|
+
delta: delta["text"]
|
|
324
|
+
};
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (delta?.["type"] === "input_json_delta" && typeof delta["partial_json"] === "string") {
|
|
328
|
+
const acc = toolCallsByIndex.get(index) ?? {
|
|
329
|
+
id: "",
|
|
330
|
+
name: "",
|
|
331
|
+
arguments: ""
|
|
332
|
+
};
|
|
333
|
+
acc.arguments += delta["partial_json"];
|
|
334
|
+
toolCallsByIndex.set(index, acc);
|
|
335
|
+
}
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
try {
|
|
340
|
+
for (;;) {
|
|
341
|
+
const { value, done: readerDone } = await reader.read();
|
|
342
|
+
if (readerDone) break;
|
|
343
|
+
buffer += decoder.decode(value, { stream: true });
|
|
344
|
+
buffer = buffer.replace(/\r\n/g, "\n");
|
|
345
|
+
let newline;
|
|
346
|
+
while ((newline = buffer.indexOf("\n")) >= 0) {
|
|
347
|
+
const line = buffer.slice(0, newline).trim();
|
|
348
|
+
buffer = buffer.slice(newline + 1);
|
|
349
|
+
if (line === "" || line.startsWith(":") || line.startsWith("event:")) continue;
|
|
350
|
+
if (!line.startsWith("data:")) continue;
|
|
351
|
+
yield* handleFrame(line.slice(5).trim());
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
} finally {
|
|
355
|
+
reader.releaseLock();
|
|
356
|
+
}
|
|
357
|
+
if (toolCallsByIndex.size > 0) yield {
|
|
358
|
+
type: "tool-calls",
|
|
359
|
+
toolCalls: [...toolCallsByIndex.entries()].sort(([a], [b]) => a - b).map(([index, acc]) => {
|
|
360
|
+
let args = {};
|
|
361
|
+
try {
|
|
362
|
+
args = JSON.parse(acc.arguments || "{}");
|
|
363
|
+
} catch {}
|
|
364
|
+
return {
|
|
365
|
+
id: acc.id || `call-${index}`,
|
|
366
|
+
name: acc.name,
|
|
367
|
+
arguments: args
|
|
368
|
+
};
|
|
369
|
+
})
|
|
370
|
+
};
|
|
371
|
+
yield { type: "done" };
|
|
372
|
+
}
|
|
373
|
+
async #post(input, stream) {
|
|
374
|
+
const { system, messages } = toAnthropicMessages(input.messages);
|
|
375
|
+
const body = {
|
|
376
|
+
model: input.model ?? this.#config.model,
|
|
377
|
+
max_tokens: this.#config.maxTokens ?? 4096,
|
|
378
|
+
messages
|
|
379
|
+
};
|
|
380
|
+
if (system !== void 0) body["system"] = system;
|
|
381
|
+
if (input.tools?.length) body["tools"] = toAnthropicTools(input.tools);
|
|
382
|
+
if (input.temperature !== void 0) body["temperature"] = input.temperature;
|
|
383
|
+
if (stream) body["stream"] = true;
|
|
384
|
+
let res;
|
|
385
|
+
try {
|
|
386
|
+
res = await this.#fetch(`${this.#baseUrl()}/v1/messages`, {
|
|
387
|
+
method: "POST",
|
|
388
|
+
headers: this.#headers(),
|
|
389
|
+
body: JSON.stringify(body),
|
|
390
|
+
signal: input.signal ?? (this.#config.requestTimeoutMs ? AbortSignal.timeout(this.#config.requestTimeoutMs) : null)
|
|
391
|
+
});
|
|
392
|
+
} catch (e) {
|
|
393
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `LLM request failed: ${errorMessage$1(e)}`, e);
|
|
394
|
+
}
|
|
395
|
+
if (!res.ok) {
|
|
396
|
+
const detail = await res.text().catch(() => "");
|
|
397
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `LLM request failed with HTTP ${res.status}${detail ? `: ${detail.slice(0, 500)}` : ""}`);
|
|
398
|
+
}
|
|
399
|
+
return res;
|
|
400
|
+
}
|
|
401
|
+
/** 轻量探测(GET /v1/models),集成测试据此决定 skip */
|
|
402
|
+
async checkAvailability() {
|
|
403
|
+
try {
|
|
404
|
+
return (await this.#fetch(`${this.#baseUrl()}/v1/models`, { headers: this.#headers() })).ok;
|
|
405
|
+
} catch {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
#parseResponse(data) {
|
|
410
|
+
try {
|
|
411
|
+
const blocks = data.content;
|
|
412
|
+
if (!Array.isArray(blocks)) throw new Error("response has no content blocks");
|
|
413
|
+
const text = blocks.filter((b) => b["type"] === "text").map((b) => String(b["text"] ?? "")).join("");
|
|
414
|
+
const toolCalls = blocks.filter((b) => b["type"] === "tool_use").map((b) => ({
|
|
415
|
+
id: typeof b["id"] === "string" ? b["id"] : "",
|
|
416
|
+
name: typeof b["name"] === "string" ? b["name"] : "",
|
|
417
|
+
arguments: typeof b["input"] === "object" && b["input"] !== null ? b["input"] : {}
|
|
418
|
+
}));
|
|
419
|
+
return {
|
|
420
|
+
content: text === "" ? void 0 : text,
|
|
421
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
422
|
+
raw: data
|
|
423
|
+
};
|
|
424
|
+
} catch (e) {
|
|
425
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `Failed to interpret LLM response: ${errorMessage$1(e)}`, data);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
const errorMessage = (e) => e instanceof Error ? e.message : String(e);
|
|
430
|
+
/** tool 结果文本包装为 functionResponse.response 对象 */
|
|
431
|
+
function responseObject(content) {
|
|
432
|
+
try {
|
|
433
|
+
const parsed = JSON.parse(content);
|
|
434
|
+
if (typeof parsed === "object" && parsed !== null) return parsed;
|
|
435
|
+
} catch {}
|
|
436
|
+
return { result: content };
|
|
437
|
+
}
|
|
438
|
+
/** LlmMessage 序列 → systemInstruction + contents(tool 结果合并进 user 消息 functionResponse parts) */
|
|
439
|
+
function toGenAiContents(messages) {
|
|
440
|
+
const system = messages.filter((m) => m.role === "system").map((m) => m.content).join("\n");
|
|
441
|
+
const nameByCallId = /* @__PURE__ */ new Map();
|
|
442
|
+
for (const msg of messages) if (msg.role === "assistant") for (const call of msg.toolCalls ?? []) nameByCallId.set(call.id, call.name);
|
|
443
|
+
const out = [];
|
|
444
|
+
for (const msg of messages) {
|
|
445
|
+
if (msg.role === "system") continue;
|
|
446
|
+
if (msg.role === "tool") {
|
|
447
|
+
const callId = msg.toolCallId ?? "";
|
|
448
|
+
const part = { functionResponse: {
|
|
449
|
+
name: nameByCallId.get(callId) ?? callId,
|
|
450
|
+
response: responseObject(msg.content)
|
|
451
|
+
} };
|
|
452
|
+
const last = out.at(-1);
|
|
453
|
+
if (last && last.role === "user") last.parts.push(part);
|
|
454
|
+
else out.push({
|
|
455
|
+
role: "user",
|
|
456
|
+
parts: [part]
|
|
457
|
+
});
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
if (msg.role === "assistant") {
|
|
461
|
+
const parts = [];
|
|
462
|
+
if (msg.content !== "") parts.push({ text: msg.content });
|
|
463
|
+
for (const call of msg.toolCalls ?? []) parts.push({ functionCall: {
|
|
464
|
+
name: call.name,
|
|
465
|
+
args: call.arguments
|
|
466
|
+
} });
|
|
467
|
+
out.push({
|
|
468
|
+
role: "model",
|
|
469
|
+
parts: parts.length > 0 ? parts : [{ text: "" }]
|
|
470
|
+
});
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
out.push({
|
|
474
|
+
role: "user",
|
|
475
|
+
parts: [{ text: msg.content }]
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
return system === "" ? { contents: out } : {
|
|
479
|
+
systemInstruction: { parts: [{ text: system }] },
|
|
480
|
+
contents: out
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
const toGenAiTools = (tools) => [{ functionDeclarations: tools.map((tool) => ({
|
|
484
|
+
name: tool.name,
|
|
485
|
+
...tool.description ? { description: tool.description } : {},
|
|
486
|
+
parameters: tool.inputSchema
|
|
487
|
+
})) }];
|
|
488
|
+
/** Google GenAI(generateContent / streamGenerateContent)客户端(零依赖 fetch) */
|
|
489
|
+
var GoogleGenAiClient = class {
|
|
490
|
+
#config;
|
|
491
|
+
#fetch;
|
|
492
|
+
constructor(config) {
|
|
493
|
+
this.#config = config;
|
|
494
|
+
this.#fetch = config.fetchImpl ?? fetch;
|
|
495
|
+
}
|
|
496
|
+
#baseUrl() {
|
|
497
|
+
return (this.#config.baseUrl ?? "https://generativelanguage.googleapis.com").replace(/\/+$/, "");
|
|
498
|
+
}
|
|
499
|
+
async complete(input) {
|
|
500
|
+
const res = await this.#post(input, false);
|
|
501
|
+
let data;
|
|
502
|
+
try {
|
|
503
|
+
data = await res.json();
|
|
504
|
+
} catch (e) {
|
|
505
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `Failed to parse LLM response: ${errorMessage(e)}`, e);
|
|
506
|
+
}
|
|
507
|
+
const parts = this.#responseParts(data);
|
|
508
|
+
const text = parts.filter((p) => typeof p["text"] === "string").map((p) => String(p["text"])).join("");
|
|
509
|
+
const toolCalls = this.#functionCalls(parts);
|
|
510
|
+
return {
|
|
511
|
+
content: text === "" ? void 0 : text,
|
|
512
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
513
|
+
raw: data
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
/** SSE 流式:chunk.parts text → text-delta;functionCall 聚合 → tool-calls */
|
|
517
|
+
async *stream(input) {
|
|
518
|
+
const res = await this.#post(input, true);
|
|
519
|
+
if (!res.body) throw new WebSkillError("LLM_REQUEST_FAILED", "LLM streaming response has no body");
|
|
520
|
+
const toolCalls = [];
|
|
521
|
+
const decoder = new TextDecoder();
|
|
522
|
+
const reader = res.body.getReader();
|
|
523
|
+
let buffer = "";
|
|
524
|
+
const handleFrame = function* (data) {
|
|
525
|
+
let chunk;
|
|
526
|
+
try {
|
|
527
|
+
chunk = JSON.parse(data);
|
|
528
|
+
} catch (e) {
|
|
529
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `Failed to parse LLM stream frame: ${errorMessage(e)}`, data);
|
|
530
|
+
}
|
|
531
|
+
const parts = chunk.candidates?.[0]?.content?.parts;
|
|
532
|
+
for (const part of parts ?? []) {
|
|
533
|
+
if (typeof part["text"] === "string" && part["text"] !== "") {
|
|
534
|
+
yield {
|
|
535
|
+
type: "text-delta",
|
|
536
|
+
delta: part["text"]
|
|
537
|
+
};
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
const call = part["functionCall"];
|
|
541
|
+
if (call) toolCalls.push({
|
|
542
|
+
id: `call-${toolCalls.length}`,
|
|
543
|
+
name: call.name ?? "",
|
|
544
|
+
arguments: call.args ?? {}
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
try {
|
|
549
|
+
for (;;) {
|
|
550
|
+
const { value, done: readerDone } = await reader.read();
|
|
551
|
+
if (readerDone) break;
|
|
552
|
+
buffer += decoder.decode(value, { stream: true });
|
|
553
|
+
buffer = buffer.replace(/\r\n/g, "\n");
|
|
554
|
+
let newline;
|
|
555
|
+
while ((newline = buffer.indexOf("\n")) >= 0) {
|
|
556
|
+
const line = buffer.slice(0, newline).trim();
|
|
557
|
+
buffer = buffer.slice(newline + 1);
|
|
558
|
+
if (line === "" || line.startsWith(":") || line.startsWith("event:")) continue;
|
|
559
|
+
if (!line.startsWith("data:")) continue;
|
|
560
|
+
yield* handleFrame(line.slice(5).trim());
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
} finally {
|
|
564
|
+
reader.releaseLock();
|
|
565
|
+
}
|
|
566
|
+
if (toolCalls.length > 0) yield {
|
|
567
|
+
type: "tool-calls",
|
|
568
|
+
toolCalls
|
|
569
|
+
};
|
|
570
|
+
yield { type: "done" };
|
|
571
|
+
}
|
|
572
|
+
async #post(input, stream) {
|
|
573
|
+
const model = input.model ?? this.#config.model;
|
|
574
|
+
const action = stream ? `:streamGenerateContent?alt=sse&key=${encodeURIComponent(this.#config.apiKey)}` : `:generateContent?key=${encodeURIComponent(this.#config.apiKey)}`;
|
|
575
|
+
const { systemInstruction, contents } = toGenAiContents(input.messages);
|
|
576
|
+
const body = { contents };
|
|
577
|
+
if (systemInstruction) body["systemInstruction"] = systemInstruction;
|
|
578
|
+
if (input.tools?.length) body["tools"] = toGenAiTools(input.tools);
|
|
579
|
+
if (input.temperature !== void 0) body["generationConfig"] = { temperature: input.temperature };
|
|
580
|
+
let res;
|
|
581
|
+
try {
|
|
582
|
+
res = await this.#fetch(`${this.#baseUrl()}/v1beta/models/${encodeURIComponent(model)}${action}`, {
|
|
583
|
+
method: "POST",
|
|
584
|
+
headers: { "content-type": "application/json" },
|
|
585
|
+
body: JSON.stringify(body),
|
|
586
|
+
signal: input.signal ?? (this.#config.requestTimeoutMs ? AbortSignal.timeout(this.#config.requestTimeoutMs) : null)
|
|
587
|
+
});
|
|
588
|
+
} catch (e) {
|
|
589
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `LLM request failed: ${errorMessage(e)}`, e);
|
|
590
|
+
}
|
|
591
|
+
if (!res.ok) {
|
|
592
|
+
const detail = await res.text().catch(() => "");
|
|
593
|
+
throw new WebSkillError("LLM_REQUEST_FAILED", `LLM request failed with HTTP ${res.status}${detail ? `: ${detail.slice(0, 500)}` : ""}`);
|
|
594
|
+
}
|
|
595
|
+
return res;
|
|
596
|
+
}
|
|
597
|
+
/** 轻量探测(GET /v1beta/models),集成测试据此决定 skip */
|
|
598
|
+
async checkAvailability() {
|
|
599
|
+
try {
|
|
600
|
+
return (await this.#fetch(`${this.#baseUrl()}/v1beta/models?key=${encodeURIComponent(this.#config.apiKey)}`)).ok;
|
|
601
|
+
} catch {
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
#responseParts(data) {
|
|
606
|
+
try {
|
|
607
|
+
const parts = data.candidates?.[0]?.content?.parts;
|
|
608
|
+
if (!Array.isArray(parts)) throw new Error("response has no candidates[0].content.parts");
|
|
609
|
+
return parts;
|
|
199
610
|
} catch (e) {
|
|
200
611
|
throw new WebSkillError("LLM_REQUEST_FAILED", `Failed to interpret LLM response: ${errorMessage(e)}`, data);
|
|
201
612
|
}
|
|
202
613
|
}
|
|
614
|
+
#functionCalls(parts) {
|
|
615
|
+
const out = [];
|
|
616
|
+
for (const part of parts) {
|
|
617
|
+
const call = part["functionCall"];
|
|
618
|
+
if (call) out.push({
|
|
619
|
+
id: `call-${out.length}`,
|
|
620
|
+
name: call.name ?? "",
|
|
621
|
+
arguments: call.args ?? {}
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
return out;
|
|
625
|
+
}
|
|
203
626
|
};
|
|
204
627
|
function toVercelToolSpecs(tools) {
|
|
205
628
|
const out = {};
|
|
@@ -2017,4 +2440,4 @@ var CapabilityApproval = class {
|
|
|
2017
2440
|
};
|
|
2018
2441
|
|
|
2019
2442
|
//#endregion
|
|
2020
|
-
export {
|
|
2443
|
+
export { mergeCatalogEntries as A, buildRenderResult as C, fromVercelResult as D, extractChartSpec as E, schemaToForm as F, toLlmToolSpec as I, toVercelToolSpecs as L, normalizeToolContent as M, parseBridgeRequest as N, fromVercelStreamPart as O, resolveToolName as P, bridgeError as S, createWebSkillApi as T, READ_SKILL_FILE_TOOL as _, AnthropicClient as a, TraceRecorder as b, FsArtifactStore as c, FullDisclosureRouter as d, GoogleGenAiClient as f, READ_SKILL_FILE_INPUT_SCHEMA as g, ProgressiveRouter as h, AgentLoop as i, networkUrlHost as j, isNetworkAllowed as k, FsMemoryStore as l, OpenAiCompatibleClient as m, ASK_USER_TOOL as n, CapabilityApproval as o, HookRunner as p, ASK_USER_TOOL_NAME as r, EventBus as s, ASK_USER_INPUT_SCHEMA as t, FsRunSnapshotStore as u, READ_SKILL_FILE_TOOL_NAME as v, createScriptContext as w, WebSkillRuntime as x, RUN_SNAPSHOT_SCHEMA_VERSION as y };
|
package/dist/governance.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { L as SkillManifest, N as SkillDocument, S as FileSystemProvider, c as LlmClient, j as SkillCatalogEntry, u as LlmMessage, v as UiBridge } from "./types-CgNC-oQu-Dq_A1yA-.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ct as WebSkillRuntime, q as RuntimeRun } from "./index-CqMuvcb2.js";
|
|
3
|
+
import { f as SkillManager } from "./index-CPuwsnmB.js";
|
|
4
4
|
//#region ../governance/dist/index.d.ts
|
|
5
5
|
//#region src/types.d.ts
|
|
6
6
|
type CandidateStatus = 'draft' | 'pending-review' | 'approved' | 'published' | 'rejected';
|
package/dist/governance.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { T as validateSkills, _ as isValidSkillName, l as WebSkillError, w as resolveInsideRoot } from "./dist-DS1sfgHa.js";
|
|
2
|
-
import { i as NodeFS } from "./dist-
|
|
2
|
+
import { i as NodeFS } from "./dist-Cm_j6Jol.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { mkdtemp } from "node:fs/promises";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { C as JsonSchema, H as SkillsLockfile, L as SkillManifest, P as SkillInstallSource, S as FileSystemProvider, W as VerifyResult, _ as RenderResultRequest, o as InteractionRequest, s as InteractionResponse, v as UiBridge, x as FileStat } from "./types-CgNC-oQu-Dq_A1yA-.js";
|
|
2
|
-
import {
|
|
2
|
+
import { $ as ToolDefinition, N as NetworkPolicy, X as ScriptExecutionContext, Y as SchemaInferer, Z as ScriptExecutor, b as FsArtifactStore, d as BridgeCapabilities, tt as ToolResult, u as ApprovalScope, x as FsMemoryStore } from "./index-CqMuvcb2.js";
|
|
3
3
|
import { Readable, Writable } from "node:stream";
|
|
4
4
|
//#region ../node/dist/index.d.ts
|
|
5
5
|
//#region src/fs/nodeFs.d.ts
|
|
@@ -172,11 +172,20 @@ interface LlmEnvConfig {
|
|
|
172
172
|
apiKey: string;
|
|
173
173
|
model: string;
|
|
174
174
|
}
|
|
175
|
+
/** per-provider env 配置(baseUrl 可选,客户端自带默认) */
|
|
176
|
+
interface ProviderEnvConfig {
|
|
177
|
+
apiKey: string;
|
|
178
|
+
model: string;
|
|
179
|
+
baseUrl?: string;
|
|
180
|
+
}
|
|
175
181
|
/**
|
|
176
|
-
* 解析 .env(简单 KEY=VALUE 行解析,不引依赖),
|
|
177
182
|
* 读取 VITE_BASE_URL / VITE_API_KEY / VITE_MODEL_NAME;缺项返回 undefined 供测试 skip 判断。
|
|
178
183
|
*/
|
|
179
184
|
declare function loadLlmConfigFromEnv(dotenvPath?: string): LlmEnvConfig | undefined;
|
|
185
|
+
/** ANTHROPIC_API_KEY / ANTHROPIC_MODEL(可选 ANTHROPIC_BASE_URL);缺项返回 undefined */
|
|
186
|
+
declare function loadAnthropicConfigFromEnv(dotenvPath?: string): ProviderEnvConfig | undefined;
|
|
187
|
+
/** GOOGLE_API_KEY / GOOGLE_MODEL(可选 GOOGLE_BASE_URL);缺项返回 undefined */
|
|
188
|
+
declare function loadGoogleConfigFromEnv(dotenvPath?: string): ProviderEnvConfig | undefined;
|
|
180
189
|
interface LlmCapabilities {
|
|
181
190
|
available: boolean;
|
|
182
191
|
nonStreaming: boolean;
|
|
@@ -192,4 +201,4 @@ interface LlmCapabilities {
|
|
|
192
201
|
*/
|
|
193
202
|
declare function probeLlmCapabilities(config: LlmEnvConfig): Promise<LlmCapabilities>;
|
|
194
203
|
//#endregion
|
|
195
|
-
export { LlmEnvConfig as a, OxcSchemaInferer as c,
|
|
204
|
+
export { readArchiveManifest as _, LlmEnvConfig as a, OxcSchemaInferer as c, SandboxedScriptExecutor as d, SkillManager as f, probeLlmCapabilities as g, loadLlmConfigFromEnv as h, LlmCapabilities as i, ProviderEnvConfig as l, loadGoogleConfigFromEnv as m, FileArtifactStore as n, NodeFS as o, loadAnthropicConfigFromEnv as p, FileMemoryStore as r, NodeScriptExecutor as s, CliUiBridge as t, SandboxOptions as u };
|
|
@@ -21,6 +21,52 @@ declare class OpenAiCompatibleClient implements LlmClient {
|
|
|
21
21
|
checkAvailability(): Promise<boolean>;
|
|
22
22
|
}
|
|
23
23
|
//#endregion
|
|
24
|
+
//#region src/llm/anthropicClient.d.ts
|
|
25
|
+
interface AnthropicClientConfig {
|
|
26
|
+
apiKey: string;
|
|
27
|
+
model: string;
|
|
28
|
+
/** 默认 https://api.anthropic.com */
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
/** 可注入 fetch(测试用 mock);缺省用全局 fetch */
|
|
31
|
+
fetchImpl?: typeof fetch;
|
|
32
|
+
/** 单次请求超时 */
|
|
33
|
+
requestTimeoutMs?: number;
|
|
34
|
+
/** max_tokens(Messages API 必填),默认 4096 */
|
|
35
|
+
maxTokens?: number;
|
|
36
|
+
}
|
|
37
|
+
/** Anthropic Messages API 客户端(零依赖 fetch;Node/浏览器通用) */
|
|
38
|
+
declare class AnthropicClient implements LlmClient {
|
|
39
|
+
#private;
|
|
40
|
+
constructor(config: AnthropicClientConfig);
|
|
41
|
+
complete(input: LlmCompleteInput): Promise<LlmResponse>;
|
|
42
|
+
/** SSE 流式:text_delta → text-delta;input_json_delta 按 block index 聚合 → tool-calls */
|
|
43
|
+
stream(input: LlmCompleteInput): AsyncIterable<LlmStreamEvent>;
|
|
44
|
+
/** 轻量探测(GET /v1/models),集成测试据此决定 skip */
|
|
45
|
+
checkAvailability(): Promise<boolean>;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/llm/googleGenAiClient.d.ts
|
|
49
|
+
interface GoogleGenAiClientConfig {
|
|
50
|
+
apiKey: string;
|
|
51
|
+
model: string;
|
|
52
|
+
/** 默认 https://generativelanguage.googleapis.com */
|
|
53
|
+
baseUrl?: string;
|
|
54
|
+
/** 可注入 fetch(测试用 mock);缺省用全局 fetch */
|
|
55
|
+
fetchImpl?: typeof fetch;
|
|
56
|
+
/** 单次请求超时 */
|
|
57
|
+
requestTimeoutMs?: number;
|
|
58
|
+
}
|
|
59
|
+
/** Google GenAI(generateContent / streamGenerateContent)客户端(零依赖 fetch) */
|
|
60
|
+
declare class GoogleGenAiClient implements LlmClient {
|
|
61
|
+
#private;
|
|
62
|
+
constructor(config: GoogleGenAiClientConfig);
|
|
63
|
+
complete(input: LlmCompleteInput): Promise<LlmResponse>;
|
|
64
|
+
/** SSE 流式:chunk.parts text → text-delta;functionCall 聚合 → tool-calls */
|
|
65
|
+
stream(input: LlmCompleteInput): AsyncIterable<LlmStreamEvent>;
|
|
66
|
+
/** 轻量探测(GET /v1beta/models),集成测试据此决定 skip */
|
|
67
|
+
checkAvailability(): Promise<boolean>;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
24
70
|
//#region src/llm/vercelAiAdapter.d.ts
|
|
25
71
|
/**
|
|
26
72
|
* Vercel AI SDK 适配层:纯数据转换,不 import SDK。
|
|
@@ -697,4 +743,4 @@ declare class WebSkillRuntime {
|
|
|
697
743
|
resumeRun(runId: string): Promise<RunResult>;
|
|
698
744
|
}
|
|
699
745
|
//#endregion
|
|
700
|
-
export {
|
|
746
|
+
export { ToolDefinition as $, LifecycleHook as A, RUN_SNAPSHOT_SCHEMA_VERSION as B, FullDisclosureRouter as C, schemaToForm as Ct, HookRunnerOptions as D, HookRunner as E, OpenAiCompatibleClientConfig as F, RunTerminationReason as G, RunResult as H, ProgressiveRouter as I, RuntimeSession as J, RuntimePhase as K, READ_SKILL_FILE_INPUT_SCHEMA as L, LifecycleListener as M, NetworkPolicy as N, InstalledSkillManifest as O, OpenAiCompatibleClient as P, SkillRouter as Q, READ_SKILL_FILE_TOOL as R, FsRunSnapshotStore as S, resolveToolName as St, GoogleGenAiClientConfig as T, toVercelToolSpecs as Tt, RunSnapshot as U, RouteResult as V, RunSnapshotStore as W, ScriptExecutionContext as X, SchemaInferer as Y, ScriptExecutor as Z, EventBus as _, isNetworkAllowed as _t, AgentLoopConfig as a, TraceRecorder as at, FsArtifactStore as b, normalizeToolContent as bt, AnthropicClientConfig as c, WebSkillRuntime as ct, BridgeCapabilities as d, buildRenderResult as dt, ToolResolution as et, BridgeCapability as f, createScriptContext as ft, CapabilityMode as g, fromVercelStreamPart as gt, CapabilityApproval as h, fromVercelResult as ht, AgentLoop as i, TraceEventType as it, LifecycleHookContext as j, LifecycleEvent as k, ApprovalDecision as l, WebSkillRuntimeDeps as lt, BridgeResponse as m, extractChartSpec as mt, ASK_USER_TOOL as n, TraceClock as nt, AgentLoopDeps as o, VercelToolSpec as ot, BridgeRequest as p, createWebSkillApi as pt, RuntimeRun as q, ASK_USER_TOOL_NAME as r, TraceEvent as rt, AnthropicClient as s, WebSkillApi as st, ASK_USER_INPUT_SCHEMA as t, ToolResult as tt, ApprovalScope as u, bridgeError as ut, ExternalSkillProvider as v, mergeCatalogEntries as vt, GoogleGenAiClient as w, toLlmToolSpec as wt, FsMemoryStore as x, parseBridgeRequest as xt, ExternalToolSource as y, networkUrlHost as yt, READ_SKILL_FILE_TOOL_NAME as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { $ as exportSkills, A as SkillCatalog, B as SkillReader, C as JsonSchema, D as SKILL_NAME_MAX_LENGTH, E as SKILL_MANIFEST_FILE, F as SkillIssue, G as WebSkillError, H as SkillsLockfile, I as SkillLocation, J as buildManifest, K as WebSkillErrorCode, L as SkillManifest, M as SkillDiscovery, N as SkillDocument, O as SKILL_NAME_PATTERN, P as SkillInstallSource, Q as escapeXml, R as SkillMetadata, S as FileSystemProvider, T as SKILLS_LOCKFILE, U as ValidationReport, V as SkillSource, W as VerifyResult, X as checkSkillRules, Y as checkDependencyCycles, Z as computeDigest, _ as RenderResultRequest, a as InteractionPolicy, at as renderAvailableSkillsXml, b as DiscoveryResult, c as LlmClient, ct as validateSkills, d as LlmResponse, et as isValidSkillName, f as LlmStreamEvent, g as RenderBlock, h as MemoryStore, i as FormField, it as parseSkillPackManifest, j as SkillCatalogEntry, k as SKILL_PACK_FILE, l as LlmCompleteInput, lt as verifyManifest, m as LlmToolSpec, n as ArtifactStore, nt as normalizePath, o as InteractionRequest, ot as renderCatalogJson, p as LlmToolCall, q as buildCatalog, r as ChartSpec, rt as parseSkillMarkdown, s as InteractionResponse, st as resolveInsideRoot, t as Artifact, tt as jsonRenderer, u as LlmMessage, ut as xmlRenderer, v as UiBridge, w as MemoryFS, x as FileStat, y as CatalogRenderer, z as SkillPackManifest } from "./types-CgNC-oQu-Dq_A1yA-.js";
|
|
2
|
-
import { $ as
|
|
3
|
-
export { ASK_USER_INPUT_SCHEMA, ASK_USER_TOOL, ASK_USER_TOOL_NAME, AgentLoop, type AgentLoopConfig, type AgentLoopDeps, type ApprovalDecision, type ApprovalScope, type Artifact, type ArtifactStore, type BridgeCapabilities, type BridgeCapability, type BridgeRequest, type BridgeResponse, CapabilityApproval, type CapabilityMode, type CatalogRenderer, type ChartSpec, type DiscoveryResult, EventBus, type ExternalSkillProvider, type ExternalToolSource, type FileStat, type FileSystemProvider, type FormField, FsArtifactStore, FsMemoryStore, FsRunSnapshotStore, FullDisclosureRouter, HookRunner, type HookRunnerOptions, type InstalledSkillManifest, type InteractionPolicy, type InteractionRequest, type InteractionResponse, type JsonSchema, type LifecycleEvent, type LifecycleHook, type LifecycleHookContext, type LifecycleListener, type LlmClient, type LlmCompleteInput, type LlmMessage, type LlmResponse, type LlmStreamEvent, type LlmToolCall, type LlmToolSpec, MemoryFS, type MemoryStore, type NetworkPolicy, OpenAiCompatibleClient, type OpenAiCompatibleClientConfig, ProgressiveRouter, READ_SKILL_FILE_INPUT_SCHEMA, READ_SKILL_FILE_TOOL, READ_SKILL_FILE_TOOL_NAME, RUN_SNAPSHOT_SCHEMA_VERSION, type RenderBlock, type RenderResultRequest, type RouteResult, type RunResult, type RunSnapshot, type RunSnapshotStore, type RunTerminationReason, type RuntimePhase, type RuntimeRun, type RuntimeSession, SKILLS_LOCKFILE, SKILL_MANIFEST_FILE, SKILL_NAME_MAX_LENGTH, SKILL_NAME_PATTERN, SKILL_PACK_FILE, type SchemaInferer, type ScriptExecutionContext, type ScriptExecutor, type SkillCatalog, type SkillCatalogEntry, SkillDiscovery, type SkillDocument, type SkillInstallSource, type SkillIssue, type SkillLocation, type SkillManifest, type SkillMetadata, type SkillPackManifest, SkillReader, type SkillRouter, type SkillSource, type SkillsLockfile, type ToolDefinition, type ToolResolution, type ToolResult, type TraceClock, type TraceEvent, type TraceEventType, TraceRecorder, type UiBridge, type ValidationReport, type VercelToolSpec, type VerifyResult, type WebSkillApi, WebSkillError, type WebSkillErrorCode, WebSkillRuntime, type WebSkillRuntimeDeps, bridgeError, buildCatalog, buildManifest, buildRenderResult, checkDependencyCycles, checkSkillRules, computeDigest, createScriptContext, createWebSkillApi, escapeXml, exportSkills, extractChartSpec, fromVercelResult, fromVercelStreamPart, isNetworkAllowed, isValidSkillName, jsonRenderer, mergeCatalogEntries, networkUrlHost, normalizePath, normalizeToolContent, parseBridgeRequest, parseSkillMarkdown, parseSkillPackManifest, renderAvailableSkillsXml, renderCatalogJson, resolveInsideRoot, resolveToolName, schemaToForm, toLlmToolSpec, toVercelToolSpecs, validateSkills, verifyManifest, xmlRenderer };
|
|
2
|
+
import { $ as ToolDefinition, A as LifecycleHook, B as RUN_SNAPSHOT_SCHEMA_VERSION, C as FullDisclosureRouter, Ct as schemaToForm, D as HookRunnerOptions, E as HookRunner, F as OpenAiCompatibleClientConfig, G as RunTerminationReason, H as RunResult, I as ProgressiveRouter, J as RuntimeSession, K as RuntimePhase, L as READ_SKILL_FILE_INPUT_SCHEMA, M as LifecycleListener, N as NetworkPolicy, O as InstalledSkillManifest, P as OpenAiCompatibleClient, Q as SkillRouter, R as READ_SKILL_FILE_TOOL, S as FsRunSnapshotStore, St as resolveToolName, T as GoogleGenAiClientConfig, Tt as toVercelToolSpecs, U as RunSnapshot, V as RouteResult, W as RunSnapshotStore, X as ScriptExecutionContext, Y as SchemaInferer, Z as ScriptExecutor, _ as EventBus, _t as isNetworkAllowed, a as AgentLoopConfig, at as TraceRecorder, b as FsArtifactStore, bt as normalizeToolContent, c as AnthropicClientConfig, ct as WebSkillRuntime, d as BridgeCapabilities, dt as buildRenderResult, et as ToolResolution, f as BridgeCapability, ft as createScriptContext, g as CapabilityMode, gt as fromVercelStreamPart, h as CapabilityApproval, ht as fromVercelResult, i as AgentLoop, it as TraceEventType, j as LifecycleHookContext, k as LifecycleEvent, l as ApprovalDecision, lt as WebSkillRuntimeDeps, m as BridgeResponse, mt as extractChartSpec, n as ASK_USER_TOOL, nt as TraceClock, o as AgentLoopDeps, ot as VercelToolSpec, p as BridgeRequest, pt as createWebSkillApi, q as RuntimeRun, r as ASK_USER_TOOL_NAME, rt as TraceEvent, s as AnthropicClient, st as WebSkillApi, t as ASK_USER_INPUT_SCHEMA, tt as ToolResult, u as ApprovalScope, ut as bridgeError, v as ExternalSkillProvider, vt as mergeCatalogEntries, w as GoogleGenAiClient, wt as toLlmToolSpec, x as FsMemoryStore, xt as parseBridgeRequest, y as ExternalToolSource, yt as networkUrlHost, z as READ_SKILL_FILE_TOOL_NAME } from "./index-CqMuvcb2.js";
|
|
3
|
+
export { ASK_USER_INPUT_SCHEMA, ASK_USER_TOOL, ASK_USER_TOOL_NAME, AgentLoop, type AgentLoopConfig, type AgentLoopDeps, AnthropicClient, type AnthropicClientConfig, type ApprovalDecision, type ApprovalScope, type Artifact, type ArtifactStore, type BridgeCapabilities, type BridgeCapability, type BridgeRequest, type BridgeResponse, CapabilityApproval, type CapabilityMode, type CatalogRenderer, type ChartSpec, type DiscoveryResult, EventBus, type ExternalSkillProvider, type ExternalToolSource, type FileStat, type FileSystemProvider, type FormField, FsArtifactStore, FsMemoryStore, FsRunSnapshotStore, FullDisclosureRouter, GoogleGenAiClient, type GoogleGenAiClientConfig, HookRunner, type HookRunnerOptions, type InstalledSkillManifest, type InteractionPolicy, type InteractionRequest, type InteractionResponse, type JsonSchema, type LifecycleEvent, type LifecycleHook, type LifecycleHookContext, type LifecycleListener, type LlmClient, type LlmCompleteInput, type LlmMessage, type LlmResponse, type LlmStreamEvent, type LlmToolCall, type LlmToolSpec, MemoryFS, type MemoryStore, type NetworkPolicy, OpenAiCompatibleClient, type OpenAiCompatibleClientConfig, ProgressiveRouter, READ_SKILL_FILE_INPUT_SCHEMA, READ_SKILL_FILE_TOOL, READ_SKILL_FILE_TOOL_NAME, RUN_SNAPSHOT_SCHEMA_VERSION, type RenderBlock, type RenderResultRequest, type RouteResult, type RunResult, type RunSnapshot, type RunSnapshotStore, type RunTerminationReason, type RuntimePhase, type RuntimeRun, type RuntimeSession, SKILLS_LOCKFILE, SKILL_MANIFEST_FILE, SKILL_NAME_MAX_LENGTH, SKILL_NAME_PATTERN, SKILL_PACK_FILE, type SchemaInferer, type ScriptExecutionContext, type ScriptExecutor, type SkillCatalog, type SkillCatalogEntry, SkillDiscovery, type SkillDocument, type SkillInstallSource, type SkillIssue, type SkillLocation, type SkillManifest, type SkillMetadata, type SkillPackManifest, SkillReader, type SkillRouter, type SkillSource, type SkillsLockfile, type ToolDefinition, type ToolResolution, type ToolResult, type TraceClock, type TraceEvent, type TraceEventType, TraceRecorder, type UiBridge, type ValidationReport, type VercelToolSpec, type VerifyResult, type WebSkillApi, WebSkillError, type WebSkillErrorCode, WebSkillRuntime, type WebSkillRuntimeDeps, bridgeError, buildCatalog, buildManifest, buildRenderResult, checkDependencyCycles, checkSkillRules, computeDigest, createScriptContext, createWebSkillApi, escapeXml, exportSkills, extractChartSpec, fromVercelResult, fromVercelStreamPart, isNetworkAllowed, isValidSkillName, jsonRenderer, mergeCatalogEntries, networkUrlHost, normalizePath, normalizeToolContent, parseBridgeRequest, parseSkillMarkdown, parseSkillPackManifest, renderAvailableSkillsXml, renderCatalogJson, resolveInsideRoot, resolveToolName, schemaToForm, toLlmToolSpec, toVercelToolSpecs, validateSkills, verifyManifest, xmlRenderer };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { C as renderCatalogJson, D as xmlRenderer, E as verifyManifest, S as renderAvailableSkillsXml, T as validateSkills, _ as isValidSkillName, a as SKILL_NAME_PATTERN, b as parseSkillMarkdown, c as SkillReader, d as buildManifest, f as checkDependencyCycles, g as exportSkills, h as escapeXml, i as SKILL_NAME_MAX_LENGTH, l as WebSkillError, m as computeDigest, n as SKILLS_LOCKFILE, o as SKILL_PACK_FILE, p as checkSkillRules, r as SKILL_MANIFEST_FILE, s as SkillDiscovery, t as MemoryFS, u as buildCatalog, v as jsonRenderer, w as resolveInsideRoot, x as parseSkillPackManifest, y as normalizePath } from "./dist-DS1sfgHa.js";
|
|
2
|
-
import { A as
|
|
2
|
+
import { A as mergeCatalogEntries, C as buildRenderResult, D as fromVercelResult, E as extractChartSpec, F as schemaToForm, I as toLlmToolSpec, L as toVercelToolSpecs, M as normalizeToolContent, N as parseBridgeRequest, O as fromVercelStreamPart, P as resolveToolName, S as bridgeError, T as createWebSkillApi, _ as READ_SKILL_FILE_TOOL, a as AnthropicClient, b as TraceRecorder, c as FsArtifactStore, d as FullDisclosureRouter, f as GoogleGenAiClient, g as READ_SKILL_FILE_INPUT_SCHEMA, h as ProgressiveRouter, i as AgentLoop, j as networkUrlHost, k as isNetworkAllowed, l as FsMemoryStore, m as OpenAiCompatibleClient, n as ASK_USER_TOOL, o as CapabilityApproval, p as HookRunner, r as ASK_USER_TOOL_NAME, s as EventBus, t as ASK_USER_INPUT_SCHEMA, u as FsRunSnapshotStore, v as READ_SKILL_FILE_TOOL_NAME, w as createScriptContext, x as WebSkillRuntime, y as RUN_SNAPSHOT_SCHEMA_VERSION } from "./dist-DZobLFh6.js";
|
|
3
3
|
|
|
4
|
-
export { ASK_USER_INPUT_SCHEMA, ASK_USER_TOOL, ASK_USER_TOOL_NAME, AgentLoop, CapabilityApproval, EventBus, FsArtifactStore, FsMemoryStore, FsRunSnapshotStore, FullDisclosureRouter, HookRunner, MemoryFS, OpenAiCompatibleClient, ProgressiveRouter, READ_SKILL_FILE_INPUT_SCHEMA, READ_SKILL_FILE_TOOL, READ_SKILL_FILE_TOOL_NAME, RUN_SNAPSHOT_SCHEMA_VERSION, SKILLS_LOCKFILE, SKILL_MANIFEST_FILE, SKILL_NAME_MAX_LENGTH, SKILL_NAME_PATTERN, SKILL_PACK_FILE, SkillDiscovery, SkillReader, TraceRecorder, WebSkillError, WebSkillRuntime, bridgeError, buildCatalog, buildManifest, buildRenderResult, checkDependencyCycles, checkSkillRules, computeDigest, createScriptContext, createWebSkillApi, escapeXml, exportSkills, extractChartSpec, fromVercelResult, fromVercelStreamPart, isNetworkAllowed, isValidSkillName, jsonRenderer, mergeCatalogEntries, networkUrlHost, normalizePath, normalizeToolContent, parseBridgeRequest, parseSkillMarkdown, parseSkillPackManifest, renderAvailableSkillsXml, renderCatalogJson, resolveInsideRoot, resolveToolName, schemaToForm, toLlmToolSpec, toVercelToolSpecs, validateSkills, verifyManifest, xmlRenderer };
|
|
4
|
+
export { ASK_USER_INPUT_SCHEMA, ASK_USER_TOOL, ASK_USER_TOOL_NAME, AgentLoop, AnthropicClient, CapabilityApproval, EventBus, FsArtifactStore, FsMemoryStore, FsRunSnapshotStore, FullDisclosureRouter, GoogleGenAiClient, HookRunner, MemoryFS, OpenAiCompatibleClient, ProgressiveRouter, READ_SKILL_FILE_INPUT_SCHEMA, READ_SKILL_FILE_TOOL, READ_SKILL_FILE_TOOL_NAME, RUN_SNAPSHOT_SCHEMA_VERSION, SKILLS_LOCKFILE, SKILL_MANIFEST_FILE, SKILL_NAME_MAX_LENGTH, SKILL_NAME_PATTERN, SKILL_PACK_FILE, SkillDiscovery, SkillReader, TraceRecorder, WebSkillError, WebSkillRuntime, bridgeError, buildCatalog, buildManifest, buildRenderResult, checkDependencyCycles, checkSkillRules, computeDigest, createScriptContext, createWebSkillApi, escapeXml, exportSkills, extractChartSpec, fromVercelResult, fromVercelStreamPart, isNetworkAllowed, isValidSkillName, jsonRenderer, mergeCatalogEntries, networkUrlHost, normalizePath, normalizeToolContent, parseBridgeRequest, parseSkillMarkdown, parseSkillPackManifest, renderAvailableSkillsXml, renderCatalogJson, resolveInsideRoot, resolveToolName, schemaToForm, toLlmToolSpec, toVercelToolSpecs, validateSkills, verifyManifest, xmlRenderer };
|
package/dist/mcp.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { C as JsonSchema, N as SkillDocument, j as SkillCatalogEntry, m as LlmToolSpec } from "./types-CgNC-oQu-Dq_A1yA-.js";
|
|
2
|
-
import {
|
|
2
|
+
import { tt as ToolResult, v as ExternalSkillProvider, vt as mergeCatalogEntries, y as ExternalToolSource } from "./index-CqMuvcb2.js";
|
|
3
3
|
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
4
4
|
import { JSONRPCMessage } from "@modelcontextprotocol/sdk/types.js";
|
|
5
5
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
@@ -241,4 +241,26 @@ declare class McpRuntimePlugin implements ExternalToolSource {
|
|
|
241
241
|
call(llmToolName: string, args: Record<string, unknown>): Promise<ToolResult>;
|
|
242
242
|
}
|
|
243
243
|
//#endregion
|
|
244
|
-
|
|
244
|
+
//#region src/remote/connectRemoteEndpoint.d.ts
|
|
245
|
+
interface RemoteEndpointConfig {
|
|
246
|
+
/** registry 中的名字(endpoint:tool 引用) */
|
|
247
|
+
endpoint: string;
|
|
248
|
+
url: string;
|
|
249
|
+
/** 默认 'streamable-http'(现行标准);'sse' 为遗留兼容 */
|
|
250
|
+
transport?: 'streamable-http' | 'sse';
|
|
251
|
+
/** 鉴权等请求头(Bearer 等),经 transport requestInit.headers 透传 */
|
|
252
|
+
headers?: Record<string, string>;
|
|
253
|
+
/** 连接超时;0/缺省 = 不超时 */
|
|
254
|
+
timeoutMs?: number;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* 远程 MCP endpoint 装配:SDK 官方 StreamableHTTPClientTransport(默认)/
|
|
258
|
+
* SSEClientTransport(遗留)连接远端 server,注册进 EndpointRegistry——
|
|
259
|
+
* endpoint:tool 解析、TTL+版本缓存、临时技能消费自动生效。
|
|
260
|
+
* 返回 close 句柄:断开后 unregister(临时技能随既有生命周期自然消失)。
|
|
261
|
+
*/
|
|
262
|
+
declare function connectRemoteEndpoint(registry: EndpointRegistry<McpClientLike>, config: RemoteEndpointConfig): Promise<{
|
|
263
|
+
close(): Promise<void>;
|
|
264
|
+
}>;
|
|
265
|
+
//#endregion
|
|
266
|
+
export { type BrowserModelContextLike, EndpointRegistry, ExperimentalWebMcpAdapter, type McpClientLike, McpRuntimePlugin, McpToolResolver, MessageChannelTransport, type MessageChannelTransportOptions, type MessagePortLike, type RemoteEndpointConfig, type ServedSkill, TemporarySkillProvider, type TransportState, type WebMcpToolDescriptor, catalogMerge, connectRemoteEndpoint, endpointToolLlmName, parseEndpointToolLlmName, parseWebMcpToolLlmName, serveSkillAsMcp, validateJsonRpcMessage, webMcpToolLlmName };
|
package/dist/mcp.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { l as WebSkillError } from "./dist-DS1sfgHa.js";
|
|
2
|
-
import { A as
|
|
2
|
+
import { A as mergeCatalogEntries, M as normalizeToolContent } from "./dist-DZobLFh6.js";
|
|
3
3
|
import { fromJSONSchema } from "zod";
|
|
4
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
5
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
6
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
7
|
|
|
5
8
|
//#region ../mcp/dist/index.js
|
|
6
9
|
/**
|
|
@@ -166,7 +169,7 @@ var EndpointRegistry = class {
|
|
|
166
169
|
for (const resolve of queue) resolve(client);
|
|
167
170
|
}
|
|
168
171
|
};
|
|
169
|
-
const messageOf$
|
|
172
|
+
const messageOf$3 = (e) => e instanceof Error ? e.message : String(e);
|
|
170
173
|
const failure$1 = (code, message) => ({
|
|
171
174
|
ok: false,
|
|
172
175
|
content: [],
|
|
@@ -191,20 +194,20 @@ var McpToolResolver = class {
|
|
|
191
194
|
try {
|
|
192
195
|
client = this.#registry.get(endpoint);
|
|
193
196
|
} catch (e) {
|
|
194
|
-
return failure$1("MCP_ENDPOINT_UNAVAILABLE", messageOf$
|
|
197
|
+
return failure$1("MCP_ENDPOINT_UNAVAILABLE", messageOf$3(e));
|
|
195
198
|
}
|
|
196
199
|
let names;
|
|
197
200
|
try {
|
|
198
201
|
names = await this.#toolNames(endpoint, client);
|
|
199
202
|
} catch (e) {
|
|
200
|
-
return failure$1("MCP_ENDPOINT_UNAVAILABLE", `Failed to list tools: ${messageOf$
|
|
203
|
+
return failure$1("MCP_ENDPOINT_UNAVAILABLE", `Failed to list tools: ${messageOf$3(e)}`);
|
|
201
204
|
}
|
|
202
205
|
if (!names.has(toolName)) {
|
|
203
206
|
this.#cache.delete(endpoint);
|
|
204
207
|
try {
|
|
205
208
|
names = await this.#toolNames(endpoint, client);
|
|
206
209
|
} catch (e) {
|
|
207
|
-
return failure$1("MCP_ENDPOINT_UNAVAILABLE", `Failed to list tools: ${messageOf$
|
|
210
|
+
return failure$1("MCP_ENDPOINT_UNAVAILABLE", `Failed to list tools: ${messageOf$3(e)}`);
|
|
208
211
|
}
|
|
209
212
|
if (!names.has(toolName)) return failure$1("MCP_TOOL_NOT_FOUND", `Tool "${toolName}" not found on endpoint "${endpoint}"`);
|
|
210
213
|
}
|
|
@@ -215,7 +218,7 @@ var McpToolResolver = class {
|
|
|
215
218
|
});
|
|
216
219
|
return this.#normalizeCallResult(raw);
|
|
217
220
|
} catch (e) {
|
|
218
|
-
return failure$1("MCP_ENDPOINT_UNAVAILABLE", `Tool "${toolName}" on endpoint "${endpoint}" failed: ${messageOf$
|
|
221
|
+
return failure$1("MCP_ENDPOINT_UNAVAILABLE", `Tool "${toolName}" on endpoint "${endpoint}" failed: ${messageOf$3(e)}`);
|
|
219
222
|
}
|
|
220
223
|
}
|
|
221
224
|
async #toolNames(endpoint, client) {
|
|
@@ -262,7 +265,7 @@ function webMcpToolLlmName(toolName) {
|
|
|
262
265
|
function parseWebMcpToolLlmName(llmName) {
|
|
263
266
|
return llmName.startsWith("mcp__") && llmName.length > 5 ? llmName.slice(5) : void 0;
|
|
264
267
|
}
|
|
265
|
-
const messageOf$
|
|
268
|
+
const messageOf$2 = (e) => e instanceof Error ? e.message : String(e);
|
|
266
269
|
const textOfContent = (content) => {
|
|
267
270
|
if (typeof content === "string") return content;
|
|
268
271
|
if (typeof content === "object" && content !== null) {
|
|
@@ -308,7 +311,7 @@ var TemporarySkillProvider = class {
|
|
|
308
311
|
try {
|
|
309
312
|
result = await client.getPrompt({ name });
|
|
310
313
|
} catch (e) {
|
|
311
|
-
throw new WebSkillError("SKILL_NOT_FOUND", `Prompt "${name}" not found on endpoint "${this.#endpoint}": ${messageOf$
|
|
314
|
+
throw new WebSkillError("SKILL_NOT_FOUND", `Prompt "${name}" not found on endpoint "${this.#endpoint}": ${messageOf$2(e)}`, e);
|
|
312
315
|
}
|
|
313
316
|
const body = (result.messages ?? []).map((m) => textOfContent(m.content)).filter(Boolean).join("\n\n");
|
|
314
317
|
return {
|
|
@@ -333,7 +336,7 @@ var TemporarySkillProvider = class {
|
|
|
333
336
|
try {
|
|
334
337
|
return this.#registry.get(this.#endpoint);
|
|
335
338
|
} catch (e) {
|
|
336
|
-
throw new WebSkillError("MCP_ENDPOINT_UNAVAILABLE", messageOf$
|
|
339
|
+
throw new WebSkillError("MCP_ENDPOINT_UNAVAILABLE", messageOf$2(e), e);
|
|
337
340
|
}
|
|
338
341
|
}
|
|
339
342
|
};
|
|
@@ -369,7 +372,7 @@ function serveSkillAsMcp(server, skill) {
|
|
|
369
372
|
* 实现单一来源在 runtime(runtime 自身合并也用同一函数)。
|
|
370
373
|
*/
|
|
371
374
|
const catalogMerge = mergeCatalogEntries;
|
|
372
|
-
const messageOf = (e) => e instanceof Error ? e.message : String(e);
|
|
375
|
+
const messageOf$1 = (e) => e instanceof Error ? e.message : String(e);
|
|
373
376
|
const failure = (code, message) => ({
|
|
374
377
|
ok: false,
|
|
375
378
|
content: [],
|
|
@@ -432,7 +435,7 @@ var ExperimentalWebMcpAdapter = class {
|
|
|
432
435
|
content: normalizeToolContent(await api.executeTool(toolName, JSON.stringify(args)))
|
|
433
436
|
};
|
|
434
437
|
} catch (e) {
|
|
435
|
-
return failure("TOOL_EXECUTION_FAILED", `WebMCP tool "${toolName}" failed: ${messageOf(e)}`);
|
|
438
|
+
return failure("TOOL_EXECUTION_FAILED", `WebMCP tool "${toolName}" failed: ${messageOf$1(e)}`);
|
|
436
439
|
}
|
|
437
440
|
}
|
|
438
441
|
};
|
|
@@ -512,6 +515,48 @@ var McpRuntimePlugin = class {
|
|
|
512
515
|
};
|
|
513
516
|
}
|
|
514
517
|
};
|
|
518
|
+
const messageOf = (e) => e instanceof Error ? e.message : String(e);
|
|
519
|
+
/**
|
|
520
|
+
* 远程 MCP endpoint 装配:SDK 官方 StreamableHTTPClientTransport(默认)/
|
|
521
|
+
* SSEClientTransport(遗留)连接远端 server,注册进 EndpointRegistry——
|
|
522
|
+
* endpoint:tool 解析、TTL+版本缓存、临时技能消费自动生效。
|
|
523
|
+
* 返回 close 句柄:断开后 unregister(临时技能随既有生命周期自然消失)。
|
|
524
|
+
*/
|
|
525
|
+
async function connectRemoteEndpoint(registry, config) {
|
|
526
|
+
const url = new URL(config.url);
|
|
527
|
+
const requestInit = config.headers ? { headers: config.headers } : void 0;
|
|
528
|
+
const transport = config.transport === "sse" ? new SSEClientTransport(url, { ...requestInit ? { requestInit } : {} }) : new StreamableHTTPClientTransport(url, { ...requestInit ? { requestInit } : {} });
|
|
529
|
+
const client = new Client({
|
|
530
|
+
name: "webskill-remote-client",
|
|
531
|
+
version: "0.1.0"
|
|
532
|
+
});
|
|
533
|
+
const unavailable = (e) => new WebSkillError("MCP_ENDPOINT_UNAVAILABLE", `Failed to connect remote MCP endpoint "${config.endpoint}" at ${config.url}: ${messageOf(e)}`, e);
|
|
534
|
+
try {
|
|
535
|
+
let connect = client.connect(transport);
|
|
536
|
+
if (config.timeoutMs && config.timeoutMs > 0) {
|
|
537
|
+
const timeoutMs = config.timeoutMs;
|
|
538
|
+
connect = Promise.race([connect, new Promise((_resolve, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error(`Connection timed out after ${timeoutMs}ms`)), timeoutMs))]);
|
|
539
|
+
}
|
|
540
|
+
await connect;
|
|
541
|
+
} catch (e) {
|
|
542
|
+
try {
|
|
543
|
+
await client.close();
|
|
544
|
+
} catch {}
|
|
545
|
+
throw unavailable(e);
|
|
546
|
+
}
|
|
547
|
+
registry.register(config.endpoint, client);
|
|
548
|
+
let closed = false;
|
|
549
|
+
return { close: async () => {
|
|
550
|
+
if (closed) return;
|
|
551
|
+
closed = true;
|
|
552
|
+
registry.unregister(config.endpoint);
|
|
553
|
+
try {
|
|
554
|
+
await client.close();
|
|
555
|
+
} catch (e) {
|
|
556
|
+
throw new WebSkillError("MCP_ENDPOINT_UNAVAILABLE", `Failed to close remote MCP endpoint "${config.endpoint}": ${messageOf(e)}`, e);
|
|
557
|
+
}
|
|
558
|
+
} };
|
|
559
|
+
}
|
|
515
560
|
|
|
516
561
|
//#endregion
|
|
517
|
-
export { EndpointRegistry, ExperimentalWebMcpAdapter, McpRuntimePlugin, McpToolResolver, MessageChannelTransport, TemporarySkillProvider, catalogMerge, endpointToolLlmName, parseEndpointToolLlmName, parseWebMcpToolLlmName, serveSkillAsMcp, validateJsonRpcMessage, webMcpToolLlmName };
|
|
562
|
+
export { EndpointRegistry, ExperimentalWebMcpAdapter, McpRuntimePlugin, McpToolResolver, MessageChannelTransport, TemporarySkillProvider, catalogMerge, connectRemoteEndpoint, endpointToolLlmName, parseEndpointToolLlmName, parseWebMcpToolLlmName, serveSkillAsMcp, validateJsonRpcMessage, webMcpToolLlmName };
|
package/dist/node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { E as SKILL_MANIFEST_FILE, H as SkillsLockfile, L as SkillManifest, P as SkillInstallSource, T as SKILLS_LOCKFILE, W as VerifyResult } from "./types-CgNC-oQu-Dq_A1yA-.js";
|
|
2
|
-
import {
|
|
3
|
-
import { a as LlmEnvConfig, c as OxcSchemaInferer, d as
|
|
4
|
-
export { CliUiBridge, FileArtifactStore, FileMemoryStore, type LlmCapabilities, type LlmEnvConfig, NodeFS, NodeScriptExecutor, OxcSchemaInferer, SKILLS_LOCKFILE, SKILL_MANIFEST_FILE, type SandboxOptions, SandboxedScriptExecutor, type SkillInstallSource, SkillManager, type SkillManifest, type SkillsLockfile, type VerifyResult, createScriptContext, loadLlmConfigFromEnv, probeLlmCapabilities, readArchiveManifest };
|
|
2
|
+
import { ft as createScriptContext } from "./index-CqMuvcb2.js";
|
|
3
|
+
import { _ as readArchiveManifest, a as LlmEnvConfig, c as OxcSchemaInferer, d as SandboxedScriptExecutor, f as SkillManager, g as probeLlmCapabilities, h as loadLlmConfigFromEnv, i as LlmCapabilities, l as ProviderEnvConfig, m as loadGoogleConfigFromEnv, n as FileArtifactStore, o as NodeFS, p as loadAnthropicConfigFromEnv, r as FileMemoryStore, s as NodeScriptExecutor, t as CliUiBridge, u as SandboxOptions } from "./index-CPuwsnmB.js";
|
|
4
|
+
export { CliUiBridge, FileArtifactStore, FileMemoryStore, type LlmCapabilities, type LlmEnvConfig, NodeFS, NodeScriptExecutor, OxcSchemaInferer, type ProviderEnvConfig, SKILLS_LOCKFILE, SKILL_MANIFEST_FILE, type SandboxOptions, SandboxedScriptExecutor, type SkillInstallSource, SkillManager, type SkillManifest, type SkillsLockfile, type VerifyResult, createScriptContext, loadAnthropicConfigFromEnv, loadGoogleConfigFromEnv, loadLlmConfigFromEnv, probeLlmCapabilities, readArchiveManifest };
|
package/dist/node.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as SKILLS_LOCKFILE, r as SKILL_MANIFEST_FILE } from "./dist-DS1sfgHa.js";
|
|
2
|
-
import {
|
|
3
|
-
import { a as NodeScriptExecutor, c as SkillManager, d as
|
|
2
|
+
import { w as createScriptContext } from "./dist-DZobLFh6.js";
|
|
3
|
+
import { a as NodeScriptExecutor, c as SkillManager, d as loadLlmConfigFromEnv, f as probeLlmCapabilities, i as NodeFS, l as loadAnthropicConfigFromEnv, n as FileArtifactStore, o as OxcSchemaInferer, p as readArchiveManifest, r as FileMemoryStore, s as SandboxedScriptExecutor, t as CliUiBridge, u as loadGoogleConfigFromEnv } from "./dist-Cm_j6Jol.js";
|
|
4
4
|
|
|
5
|
-
export { CliUiBridge, FileArtifactStore, FileMemoryStore, NodeFS, NodeScriptExecutor, OxcSchemaInferer, SKILLS_LOCKFILE, SKILL_MANIFEST_FILE, SandboxedScriptExecutor, SkillManager, createScriptContext, loadLlmConfigFromEnv, probeLlmCapabilities, readArchiveManifest };
|
|
5
|
+
export { CliUiBridge, FileArtifactStore, FileMemoryStore, NodeFS, NodeScriptExecutor, OxcSchemaInferer, SKILLS_LOCKFILE, SKILL_MANIFEST_FILE, SandboxedScriptExecutor, SkillManager, createScriptContext, loadAnthropicConfigFromEnv, loadGoogleConfigFromEnv, loadLlmConfigFromEnv, probeLlmCapabilities, readArchiveManifest };
|
package/dist/ui.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as RenderResultRequest, g as RenderBlock, o as InteractionRequest, r as ChartSpec, s as InteractionResponse, v as UiBridge } from "./types-CgNC-oQu-Dq_A1yA-.js";
|
|
2
|
-
import {
|
|
2
|
+
import { dt as buildRenderResult } from "./index-CqMuvcb2.js";
|
|
3
3
|
//#region ../ui/dist/index.d.ts
|
|
4
4
|
//#region src/model/formModel.d.ts
|
|
5
5
|
interface FormModel {
|
package/dist/ui.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as buildRenderResult } from "./dist-DZobLFh6.js";
|
|
2
2
|
import { C as renderRenderResult, D as toVercelToolInvocation, E as toOpenUiLang, S as renderMiniMarkdown, T as toA2uiMessages, _ as fromOpenUiAction, a as CHART_PALETTE, b as renderBlocks, c as OPENUI_SUBMIT_ACTION, d as WEBSKILL_STYLES_CSS, f as WebFormBridge, g as fromA2uiAction, h as ensureStyles, i as A2UI_VERSION, l as VERCEL_INTERACTION_TOOL_NAME, m as collectValues, n as A2UI_CANCEL_ACTION, o as LitRendererBridge, p as chartToTable, r as A2UI_SUBMIT_ACTION, s as OPENUI_CANCEL_ACTION, t as A2UI_BASIC_CATALOG_ID, u as VercelUiBridge, v as fromVercelToolResult, w as shapeInteractionValue, x as renderMiniChart, y as interactionToFormModel } from "./dist-DxGyAznR.js";
|
|
3
3
|
|
|
4
4
|
export { A2UI_BASIC_CATALOG_ID, A2UI_CANCEL_ACTION, A2UI_SUBMIT_ACTION, A2UI_VERSION, CHART_PALETTE, LitRendererBridge, OPENUI_CANCEL_ACTION, OPENUI_SUBMIT_ACTION, VERCEL_INTERACTION_TOOL_NAME, VercelUiBridge, WEBSKILL_STYLES_CSS, WebFormBridge, buildRenderResult, chartToTable, collectValues, ensureStyles, fromA2uiAction, fromOpenUiAction, fromVercelToolResult, interactionToFormModel, renderBlocks, renderMiniChart, renderMiniMarkdown, renderRenderResult, shapeInteractionValue, toA2uiMessages, toOpenUiLang, toVercelToolInvocation };
|