agents 0.30.1 → 0.32.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 +2 -1
- package/dist/{agent-routing-CDbpVjYq.d.ts → agent-routing-vVMA7m8Y.d.ts} +69 -608
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-C8DH8Yii.d.ts → agent-tools-gGXXkf1z.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/agent-tools.js +0 -1
- package/dist/agent-tools.js.map +1 -1
- package/dist/{ai-iXw0uOGj.d.ts → ai-CDn3Abax.d.ts} +30 -4
- package/dist/{ai-sdk-DRPh2rRa.js → ai-sdk-Kon40i0q.js} +2 -36
- package/dist/ai-sdk-Kon40i0q.js.map +1 -0
- package/dist/browser/ai.d.ts +1 -1
- package/dist/browser/ai.js +16 -3
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/index.d.ts +64 -16
- package/dist/browser/index.js +4 -4
- package/dist/browser/tools/ai-sdk.d.ts +7 -5
- package/dist/browser/tools/ai-sdk.js +4 -4
- package/dist/browser/tools/ai-sdk.js.map +1 -1
- package/dist/browser/tools/pi.d.ts +9 -15
- package/dist/browser/tools/pi.js +6 -14
- package/dist/browser/tools/pi.js.map +1 -1
- package/dist/browser/tools/tanstack-ai.d.ts +48 -25
- package/dist/browser/tools/tanstack-ai.js +8 -4
- package/dist/browser/tools/tanstack-ai.js.map +1 -1
- package/dist/{browser-DccPw_wW.js → browser-1eUbPvC2.js} +413 -14
- package/dist/browser-1eUbPvC2.js.map +1 -0
- package/dist/{browser-DlXhSAdf.d.ts → browser-D9RNpJuT.d.ts} +254 -20
- package/dist/browser-tool-BhjCcNVE.d.ts +71 -0
- package/dist/browser-tool-DRan7Lk6.js +497 -0
- package/dist/browser-tool-DRan7Lk6.js.map +1 -0
- package/dist/capability-id-B3J8Nok_.js +13 -0
- package/dist/capability-id-B3J8Nok_.js.map +1 -0
- package/dist/catalog-BpOejOsE.js +239 -0
- package/dist/catalog-BpOejOsE.js.map +1 -0
- package/dist/catalog-BpiVV1OF.d.ts +173 -0
- package/dist/chat/index.d.ts +2 -2
- package/dist/chat-sdk/index.d.ts +3 -3
- package/dist/chat-sdk/index.js +1 -1
- package/dist/client-4OlMIJx-.js.map +1 -1
- package/dist/{client-BnYbNT3z.js → client-DMWujQJ1.js} +68 -244
- package/dist/client-DMWujQJ1.js.map +1 -0
- package/dist/{client-C27CtRZr.d.ts → client-eSfgYvd3.d.ts} +9 -7
- package/dist/client.d.ts +1 -1
- package/dist/{cloudflare-Dzvc7V2N.js → cloudflare-CUUm_9q9.js} +26 -4
- package/dist/cloudflare-CUUm_9q9.js.map +1 -0
- package/dist/{connector-DAXBOIIi.js → connector-CM-uuxKM.js} +96 -8
- package/dist/connector-CM-uuxKM.js.map +1 -0
- package/dist/{connector-20DJ6p4k.d.ts → connector-DZ71EjE-.d.ts} +109 -9
- package/dist/{do-oauth-client-provider-DfsUcpc3.d.ts → do-oauth-client-provider-DtNqv7oj.d.ts} +26 -2
- package/dist/{index-YSKgfgg9.d.ts → emitter-BJZtCVjQ.d.ts} +6 -140
- package/dist/emitter-DPOVcCln.js +15 -0
- package/dist/emitter-DPOVcCln.js.map +1 -0
- package/dist/experimental/channels/web/index.js +1 -1
- package/dist/experimental/webmcp.js +1 -1
- package/dist/{handler-stateless-Bly_nSH3.js → handler-stateless-B5hU3dxK.js} +35 -2
- package/dist/handler-stateless-B5hU3dxK.js.map +1 -0
- package/dist/{handler-stateless-DxYpJ_XF.d.ts → handler-stateless-C90kD5_R.d.ts} +3 -47
- package/dist/harness/container/index.d.ts +15 -15
- package/dist/harness/container/index.js +0 -1
- package/dist/harness/container/index.js.map +1 -1
- package/dist/harness/container/runtime/index.js +2 -2
- package/dist/harness/opencode/index.js +0 -1
- package/dist/harness/opencode/index.js.map +1 -1
- package/dist/harness/pi/index.d.ts +15 -7
- package/dist/harness/pi/index.js +74 -151
- package/dist/harness/pi/index.js.map +1 -1
- package/dist/harness/think/index.d.ts +2 -1
- package/dist/{images-xaDv2Fqe.js → images-CfuRCjwq.js} +1 -5
- package/dist/images-CfuRCjwq.js.map +1 -0
- package/dist/{index-DCxk3OSJ.d.ts → index-8k4qsX1T.d.ts} +2 -28
- package/dist/index.d.ts +15 -16
- package/dist/index.js +3 -3
- package/dist/internal-hosts-Kfp5A392.d.ts +230 -0
- package/dist/internal-kmw70xwR.js.map +1 -1
- package/dist/invoker-BC1SZ3q1.js +26 -0
- package/dist/invoker-BC1SZ3q1.js.map +1 -0
- package/dist/invoker-DoLFPJZV.d.ts +21 -0
- package/dist/markdown-BZ-VLtA1.js +86 -0
- package/dist/markdown-BZ-VLtA1.js.map +1 -0
- package/dist/mcp/client/do-oauth-client-provider.d.ts +4 -2
- package/dist/mcp/client/do-oauth-client-provider.js +15 -1
- package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/client/index.d.ts +15 -1
- package/dist/mcp/client/index.js +2 -2
- package/dist/mcp/client/x402.d.ts +7 -5
- package/dist/mcp/client/x402.js +34 -1
- package/dist/mcp/client/x402.js.map +1 -1
- package/dist/mcp/index.d.ts +561 -27
- package/dist/mcp/index.js +180 -3
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/server/index.d.ts +1 -1
- package/dist/mcp/server/index.js +1 -1
- package/dist/models/ai-sdk/index.d.ts +2 -2
- package/dist/models/ai-sdk/index.js +1 -1
- package/dist/models/opencode/index.d.ts +2 -2
- package/dist/models/opencode/index.js +1 -1
- package/dist/models/pi-ai/index.d.ts +3 -28
- package/dist/models/pi-ai/index.js +160 -18
- package/dist/models/pi-ai/index.js.map +1 -1
- package/dist/observability/ai/index.js +1 -2
- package/dist/observability/ai/index.js.map +1 -1
- package/dist/observability/index.d.ts +170 -9
- package/dist/observability/index.js +386 -11
- package/dist/observability/index.js.map +1 -1
- package/dist/protocol-BEgrJYC5.d.ts +29 -29
- package/dist/react.d.ts +2 -2
- package/dist/resource-B59OV2a2.js +325 -0
- package/dist/resource-B59OV2a2.js.map +1 -0
- package/dist/routing/index.d.ts +1 -1
- package/dist/script-CFDLTk5b.d.ts +91 -0
- package/dist/script-workspace-BpdAYq1R.d.ts +41 -0
- package/dist/serializable.d.ts +1 -1
- package/dist/{session-store-yvwq1f9x.js → session-7CDgVE0z.js} +455 -33
- package/dist/session-7CDgVE0z.js.map +1 -0
- package/dist/{session-store-_IK6dV-w.d.ts → session-store-B7Ca-u1t.d.ts} +8 -1
- package/dist/settings-Dk2il2Hf.js.map +1 -1
- package/dist/skill-DRBcIBjC.d.ts +221 -0
- package/dist/skills/index.d.ts +275 -36
- package/dist/skills/index.js +265 -1534
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/runner.d.ts +37 -0
- package/dist/skills/runner.js +912 -0
- package/dist/skills/runner.js.map +1 -0
- package/dist/skills/tools/ai-sdk.d.ts +36 -0
- package/dist/skills/tools/ai-sdk.js +94 -0
- package/dist/skills/tools/ai-sdk.js.map +1 -0
- package/dist/source-9RQzlEhM.d.ts +112 -0
- package/dist/{src-DfLzdwlK.js → src-DoGNJ4Ud.js} +21 -6
- package/dist/src-DoGNJ4Ud.js.map +1 -0
- package/dist/sub-routing.d.ts +12 -12
- package/dist/tool-CTp72Jb_.d.ts +10 -10
- package/dist/tool-CxKsvxjm.js.map +1 -1
- package/dist/tool-DkT_DJBm.js.map +1 -1
- package/dist/tool-DoVberpN.d.ts +22 -22
- package/dist/tool-helpers-BI7ifO2S.js +255 -0
- package/dist/tool-helpers-BI7ifO2S.js.map +1 -0
- package/dist/{transport-CPh7YGiw.d.ts → transport-5moD2pW5.d.ts} +1 -43
- package/dist/types-D2naO3rA.d.ts +49 -0
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +10 -258
- package/dist/vite.js.map +1 -1
- package/dist/voice/index.d.ts +1 -1
- package/dist/websockets/index.js +1 -1
- package/dist/{websockets-CyoeosdO.js → websockets-C6SJtWCJ.js} +1 -2
- package/dist/{websockets-CyoeosdO.js.map → websockets-C6SJtWCJ.js.map} +1 -1
- package/dist/workflow-types.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/dist/workflows.js +0 -1
- package/dist/workflows.js.map +1 -1
- package/docs/browse-the-web.md +247 -413
- package/docs/harnesses/pi.md +36 -30
- package/docs/index.md +4 -4
- package/docs/mcp-client.md +25 -1
- package/docs/mcp-servers.md +26 -7
- package/docs/models-pi-ai.md +9 -11
- package/docs/models.md +1 -8
- package/docs/observability.md +5 -3
- package/docs/securing-mcp-servers.md +113 -302
- package/package.json +31 -17
- package/dist/ai-sdk-DRPh2rRa.js.map +0 -1
- package/dist/browser-DccPw_wW.js.map +0 -1
- package/dist/browser-tool-B1mhifin.js +0 -616
- package/dist/browser-tool-B1mhifin.js.map +0 -1
- package/dist/browser-tool-Cxjk5sgG.d.ts +0 -92
- package/dist/client-BnYbNT3z.js.map +0 -1
- package/dist/cloudflare-Dzvc7V2N.js.map +0 -1
- package/dist/connector-DAXBOIIi.js.map +0 -1
- package/dist/handler-stateless-Bly_nSH3.js.map +0 -1
- package/dist/images-xaDv2Fqe.js.map +0 -1
- package/dist/index-iv9FTXX9.d.ts +0 -311
- package/dist/invoker-CG0_p_Wq.d.ts +0 -20
- package/dist/invoker-CHMnoxIA.js +0 -57
- package/dist/invoker-CHMnoxIA.js.map +0 -1
- package/dist/session-store-yvwq1f9x.js.map +0 -1
- package/dist/skills/compile.d.ts +0 -40
- package/dist/skills/compile.js +0 -65
- package/dist/skills/compile.js.map +0 -1
- package/dist/src-DfLzdwlK.js.map +0 -1
- package/dist/tool-helpers-O5BDVEAY.js +0 -58
- package/dist/tool-helpers-O5BDVEAY.js.map +0 -1
- package/skills-module.d.ts +0 -22
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { c as isModelInvocable, d as err, f as ok, o as parseSkillResourcePath, t as InvalidSkillResourcePathError } from "./resource-B59OV2a2.js";
|
|
2
|
+
//#region src/skills/source.ts
|
|
3
|
+
/** A source's backing store failed. */
|
|
4
|
+
var SkillSourceError = class extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* @param sourceId - The source that failed.
|
|
7
|
+
* @param operation - What the source was doing.
|
|
8
|
+
* @param cause - The underlying store error.
|
|
9
|
+
*/
|
|
10
|
+
constructor(sourceId, operation, cause) {
|
|
11
|
+
super(`Skill source "${sourceId}" failed to ${operation === "list" ? "list skills" : "read a resource"}: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
12
|
+
this.sourceId = sourceId;
|
|
13
|
+
this.operation = operation;
|
|
14
|
+
this._tag = "SkillSourceError";
|
|
15
|
+
this.name = "SkillSourceError";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/** A skill has no file at the requested path. */
|
|
19
|
+
var SkillResourceNotFoundError = class extends Error {
|
|
20
|
+
/**
|
|
21
|
+
* @param skill - The skill that was searched.
|
|
22
|
+
* @param path - The missing path.
|
|
23
|
+
*/
|
|
24
|
+
constructor(skill, path) {
|
|
25
|
+
super(`Resource not found: ${skill}/${path}`);
|
|
26
|
+
this.skill = skill;
|
|
27
|
+
this.path = path;
|
|
28
|
+
this._tag = "SkillResourceNotFoundError";
|
|
29
|
+
this.name = "SkillResourceNotFoundError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/skills/catalog.ts
|
|
34
|
+
/** The catalog has no skill with the requested name. */
|
|
35
|
+
var UnknownSkillError = class extends Error {
|
|
36
|
+
/** @param skill - The requested name. */
|
|
37
|
+
constructor(skill) {
|
|
38
|
+
super(`Skill not found: ${skill}`);
|
|
39
|
+
this.skill = skill;
|
|
40
|
+
this._tag = "UnknownSkillError";
|
|
41
|
+
this.name = "UnknownSkillError";
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Successful listings behind each catalog, by source object. Lets a later
|
|
46
|
+
* load fall back to the last good listing of a failing source without
|
|
47
|
+
* putting listings on the public catalog shape.
|
|
48
|
+
*/
|
|
49
|
+
const catalogListings = /* @__PURE__ */ new WeakMap();
|
|
50
|
+
/**
|
|
51
|
+
* Load every source and merge them into a catalog.
|
|
52
|
+
*
|
|
53
|
+
* Sources apply in order: the first source to list a name wins. A failing
|
|
54
|
+
* source or an invalid skill becomes a diagnostic instead of an error, so
|
|
55
|
+
* one bad source never hides the others. Skills that set
|
|
56
|
+
* `disable-model-invocation: true` are left out.
|
|
57
|
+
*
|
|
58
|
+
* @param sources - Skill sources in priority order.
|
|
59
|
+
* @param options - Pass `previous` to keep a failing source's last skills.
|
|
60
|
+
* @returns The merged catalog.
|
|
61
|
+
*/
|
|
62
|
+
async function loadSkillCatalog(sources, options = {}) {
|
|
63
|
+
const previousListings = options.previous ? catalogListings.get(options.previous) : void 0;
|
|
64
|
+
const listings = await Promise.all(sources.map(async (source) => ({
|
|
65
|
+
source,
|
|
66
|
+
listed: await source.list().catch((cause) => err(new SkillSourceError(source.id, "list", cause)))
|
|
67
|
+
})));
|
|
68
|
+
const diagnostics = [];
|
|
69
|
+
const entries = /* @__PURE__ */ new Map();
|
|
70
|
+
const sourceBySkill = /* @__PURE__ */ new Map();
|
|
71
|
+
const goodListings = /* @__PURE__ */ new Map();
|
|
72
|
+
for (const { source, listed } of listings) {
|
|
73
|
+
let listing;
|
|
74
|
+
if (listed.ok) listing = listed.value;
|
|
75
|
+
else {
|
|
76
|
+
const fallback = previousListings?.get(source);
|
|
77
|
+
diagnostics.push({
|
|
78
|
+
_tag: "SourceFailed",
|
|
79
|
+
sourceId: source.id,
|
|
80
|
+
error: listed.error,
|
|
81
|
+
keptPrevious: fallback !== void 0
|
|
82
|
+
});
|
|
83
|
+
if (!fallback) continue;
|
|
84
|
+
listing = fallback;
|
|
85
|
+
}
|
|
86
|
+
goodListings.set(source, listing);
|
|
87
|
+
for (const invalid of listing.invalid) diagnostics.push({
|
|
88
|
+
_tag: "InvalidSkill",
|
|
89
|
+
sourceId: source.id,
|
|
90
|
+
location: invalid.location,
|
|
91
|
+
error: invalid.error
|
|
92
|
+
});
|
|
93
|
+
for (const { skill, resources, location, warnings } of listing.skills) {
|
|
94
|
+
const existing = entries.get(skill.name);
|
|
95
|
+
if (existing) {
|
|
96
|
+
diagnostics.push({
|
|
97
|
+
_tag: "DuplicateSkill",
|
|
98
|
+
name: skill.name,
|
|
99
|
+
sourceId: source.id,
|
|
100
|
+
keptSourceId: existing.sourceId
|
|
101
|
+
});
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
entries.set(skill.name, {
|
|
105
|
+
skill,
|
|
106
|
+
sourceId: source.id,
|
|
107
|
+
resources,
|
|
108
|
+
...location === void 0 ? {} : { location }
|
|
109
|
+
});
|
|
110
|
+
sourceBySkill.set(skill.name, source);
|
|
111
|
+
for (const warning of warnings ?? []) diagnostics.push({
|
|
112
|
+
_tag: "SkillWarning",
|
|
113
|
+
sourceId: source.id,
|
|
114
|
+
name: skill.name,
|
|
115
|
+
error: warning
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const skills = [...entries.values()].filter((entry) => isModelInvocable(entry.skill));
|
|
120
|
+
const visible = new Map(skills.map((entry) => [entry.skill.name, entry]));
|
|
121
|
+
const prompt = renderCatalogPrompt(skills);
|
|
122
|
+
const catalog = {
|
|
123
|
+
fingerprint: fingerprintOf(prompt ?? ""),
|
|
124
|
+
skills,
|
|
125
|
+
diagnostics,
|
|
126
|
+
prompt: () => prompt,
|
|
127
|
+
find: (name) => visible.get(name),
|
|
128
|
+
activate(name) {
|
|
129
|
+
const entry = visible.get(name);
|
|
130
|
+
return entry ? ok(renderSkillActivation(entry)) : err(new UnknownSkillError(name));
|
|
131
|
+
},
|
|
132
|
+
async readResource(request) {
|
|
133
|
+
const target = resolveResourceTarget(visible, request);
|
|
134
|
+
if (!target.ok) return target;
|
|
135
|
+
const { entry, path } = target.value;
|
|
136
|
+
const source = sourceBySkill.get(entry.skill.name);
|
|
137
|
+
if (!source) return err(new UnknownSkillError(entry.skill.name));
|
|
138
|
+
const read = await source.readResource(entry.skill.name, path).catch((cause) => err(new SkillSourceError(source.id, "read-resource", cause)));
|
|
139
|
+
if (!read.ok) return read;
|
|
140
|
+
return ok({
|
|
141
|
+
entry,
|
|
142
|
+
resource: read.value
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
catalogListings.set(catalog, goodListings);
|
|
147
|
+
return catalog;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Describe a diagnostic in one line, for logs.
|
|
151
|
+
*
|
|
152
|
+
* @param diagnostic - A diagnostic from {@link SkillCatalog.diagnostics}.
|
|
153
|
+
*/
|
|
154
|
+
function formatSkillDiagnostic(diagnostic) {
|
|
155
|
+
switch (diagnostic._tag) {
|
|
156
|
+
case "InvalidSkill": return `Skipped invalid skill ${diagnostic.location} from source "${diagnostic.sourceId}": ${diagnostic.error.message}`;
|
|
157
|
+
case "SkillWarning": return `Skill "${diagnostic.name}" from source "${diagnostic.sourceId}" breaks the Agent Skills spec but was loaded: ${diagnostic.error.message}`;
|
|
158
|
+
case "SourceFailed": return `${diagnostic.error.message}. ${diagnostic.keptPrevious ? "Its last listed skills were kept." : "Its skills were skipped."}`;
|
|
159
|
+
case "DuplicateSkill": return `Duplicate skill "${diagnostic.name}" from source "${diagnostic.sourceId}" ignored; already provided by "${diagnostic.keptSourceId}".`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Render a resource read for the model.
|
|
164
|
+
*
|
|
165
|
+
* @param read - A resource returned by {@link SkillCatalog.readResource}.
|
|
166
|
+
*/
|
|
167
|
+
function renderSkillResource(read) {
|
|
168
|
+
const { entry, resource } = read;
|
|
169
|
+
return [
|
|
170
|
+
`<skill_resource${attributes([
|
|
171
|
+
["name", entry.skill.name],
|
|
172
|
+
["path", resource.path],
|
|
173
|
+
["kind", resource.kind],
|
|
174
|
+
["encoding", resource.encoding],
|
|
175
|
+
["mimeType", resource.mimeType]
|
|
176
|
+
])}>`,
|
|
177
|
+
resource.content,
|
|
178
|
+
"</skill_resource>"
|
|
179
|
+
].join("\n");
|
|
180
|
+
}
|
|
181
|
+
function renderCatalogPrompt(skills) {
|
|
182
|
+
if (skills.length === 0) return null;
|
|
183
|
+
return [
|
|
184
|
+
"Available skills. When a task matches a skill, use activate_skill with its name before proceeding.",
|
|
185
|
+
"",
|
|
186
|
+
...skills.map(({ skill }) => `- ${skill.name}: ${skill.description.replace(/\s+/g, " ")}`)
|
|
187
|
+
].join("\n");
|
|
188
|
+
}
|
|
189
|
+
function renderSkillActivation(entry) {
|
|
190
|
+
const lines = [`<skill_content${attributes([["name", entry.skill.name], ["location", entry.location]])}>`, entry.skill.body.trim()];
|
|
191
|
+
if (entry.resources.length > 0) {
|
|
192
|
+
lines.push("", "<skill_resources>");
|
|
193
|
+
for (const resource of entry.resources) lines.push(` <file${attributes([
|
|
194
|
+
["kind", resource.kind],
|
|
195
|
+
["encoding", resource.encoding],
|
|
196
|
+
["size", resource.size === void 0 ? void 0 : String(resource.size)]
|
|
197
|
+
])}>${resource.path}</file>`);
|
|
198
|
+
lines.push("</skill_resources>");
|
|
199
|
+
}
|
|
200
|
+
lines.push("</skill_content>");
|
|
201
|
+
return lines.join("\n");
|
|
202
|
+
}
|
|
203
|
+
function resolveResourceTarget(skills, request) {
|
|
204
|
+
let name = request.name;
|
|
205
|
+
let relative = request.path;
|
|
206
|
+
if (name === void 0) {
|
|
207
|
+
const slash = relative.indexOf("/");
|
|
208
|
+
if (slash <= 0) return err(new InvalidSkillResourcePathError(relative));
|
|
209
|
+
name = relative.slice(0, slash);
|
|
210
|
+
relative = relative.slice(slash + 1);
|
|
211
|
+
}
|
|
212
|
+
const entry = skills.get(name);
|
|
213
|
+
if (!entry) return err(new UnknownSkillError(name));
|
|
214
|
+
const path = parseSkillResourcePath(relative);
|
|
215
|
+
if (!path.ok) return path;
|
|
216
|
+
if (!entry.resources.some((resource) => resource.path === path.value)) return err(new SkillResourceNotFoundError(entry.skill.name, path.value));
|
|
217
|
+
return ok({
|
|
218
|
+
entry,
|
|
219
|
+
path: path.value
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
function attributes(pairs) {
|
|
223
|
+
return pairs.filter((pair) => pair[1] !== void 0).map(([key, value]) => ` ${key}="${value.replace(/"/g, """)}"`).join("");
|
|
224
|
+
}
|
|
225
|
+
/** Two FNV-1a passes with different seeds: cheap and stable across isolates. */
|
|
226
|
+
function fingerprintOf(text) {
|
|
227
|
+
let a = 2166136261;
|
|
228
|
+
let b = 16777619;
|
|
229
|
+
for (let index = 0; index < text.length; index++) {
|
|
230
|
+
const code = text.charCodeAt(index);
|
|
231
|
+
a = Math.imul(a ^ code, 16777619);
|
|
232
|
+
b = Math.imul(b ^ code, 2166136261);
|
|
233
|
+
}
|
|
234
|
+
return `${(a >>> 0).toString(16).padStart(8, "0")}${(b >>> 0).toString(16).padStart(8, "0")}`;
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
export { SkillResourceNotFoundError as a, renderSkillResource as i, formatSkillDiagnostic as n, SkillSourceError as o, loadSkillCatalog as r, UnknownSkillError as t };
|
|
238
|
+
|
|
239
|
+
//# sourceMappingURL=catalog-BpOejOsE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog-BpOejOsE.js","names":[],"sources":["../src/skills/source.ts","../src/skills/catalog.ts"],"sourcesContent":["import type { SkillResult } from \"./result\";\nimport type {\n SkillResource,\n SkillResourceInfo,\n SkillResourcePath\n} from \"./resource\";\nimport type { Skill, SkillName, SkillParseError } from \"./skill\";\n\n/**\n * Where skills are loaded from: a Computer Workspace, an R2 bucket, an\n * in-memory manifest, or a custom store.\n *\n * A source lists every skill it holds on each call, so changes show up the\n * next time a catalog is loaded. Expected failures are returned, not thrown.\n */\nexport interface SkillSource {\n /** Stable identifier used in diagnostics and duplicate-name warnings. */\n readonly id: string;\n /**\n * List the skills this source holds.\n *\n * @returns Valid skills and the skills that failed to parse, or\n * `SkillSourceError` when the store could not be read.\n */\n list(): Promise<SkillResult<SkillListing, SkillSourceError>>;\n /**\n * Read one file bundled with a skill.\n *\n * @param skill - The skill that owns the file.\n * @param path - Path relative to the skill directory.\n */\n readResource(\n skill: SkillName,\n path: SkillResourcePath\n ): Promise<\n SkillResult<SkillResource, SkillResourceNotFoundError | SkillSourceError>\n >;\n}\n\n/** Everything a source found in one {@link SkillSource.list} call. */\nexport interface SkillListing {\n /** Skills that parsed, in a stable order. */\n readonly skills: readonly ListedSkill[];\n /** Skills that did not follow the spec and were left out. */\n readonly invalid: readonly InvalidSkill[];\n}\n\n/** A valid skill and the files bundled with it. */\nexport interface ListedSkill {\n /** The parsed `SKILL.md`. */\n readonly skill: Skill;\n /** Files in the skill directory other than `SKILL.md`. */\n readonly resources: readonly SkillResourceInfo[];\n /**\n * Absolute directory of the skill in the agent's filesystem, when the\n * source stores skills there. Agents with a shell can run scripts from it.\n */\n readonly location?: string;\n /**\n * Spec rules the skill breaks but was loaded anyway, for example a name\n * that does not match its directory, as the spec's guide for agents\n * recommends.\n */\n readonly warnings?: readonly SkillParseError[];\n}\n\n/** A skill that failed to parse. */\nexport interface InvalidSkill {\n /** Where the broken skill lives, such as `my-skill/SKILL.md`. */\n readonly location: string;\n /** Which spec rule it broke. */\n readonly error: SkillParseError;\n}\n\n/** A source's backing store failed. */\nexport class SkillSourceError extends Error {\n /** Stable tag for narrowing. */\n readonly _tag = \"SkillSourceError\" as const;\n\n /**\n * @param sourceId - The source that failed.\n * @param operation - What the source was doing.\n * @param cause - The underlying store error.\n */\n constructor(\n readonly sourceId: string,\n readonly operation: \"list\" | \"read-resource\",\n cause: unknown\n ) {\n super(\n `Skill source \"${sourceId}\" failed to ${operation === \"list\" ? \"list skills\" : \"read a resource\"}: ${cause instanceof Error ? cause.message : String(cause)}`,\n { cause }\n );\n this.name = \"SkillSourceError\";\n }\n}\n\n/** A skill has no file at the requested path. */\nexport class SkillResourceNotFoundError extends Error {\n /** Stable tag for narrowing. */\n readonly _tag = \"SkillResourceNotFoundError\" as const;\n\n /**\n * @param skill - The skill that was searched.\n * @param path - The missing path.\n */\n constructor(\n readonly skill: SkillName,\n readonly path: string\n ) {\n super(`Resource not found: ${skill}/${path}`);\n this.name = \"SkillResourceNotFoundError\";\n }\n}\n","import { err, ok, type SkillResult } from \"./result\";\nimport {\n InvalidSkillResourcePathError,\n parseSkillResourcePath,\n type SkillResource,\n type SkillResourceInfo\n} from \"./resource\";\nimport { isModelInvocable, type Skill, type SkillParseError } from \"./skill\";\nimport {\n SkillResourceNotFoundError,\n SkillSourceError,\n type SkillListing,\n type SkillSource\n} from \"./source\";\n\n/**\n * The skills an agent can use right now, merged from its sources.\n *\n * Load one with {@link loadSkillCatalog}; load it again to pick up changes.\n * Framework adapters (Think's AI SDK tools, the pi `skills()` extension)\n * wrap a catalog so every framework shows the model the same catalog text,\n * activation output, and resource output.\n */\nexport interface SkillCatalog {\n /** Changes whenever {@link prompt} would change. */\n readonly fingerprint: string;\n /** Skills the model may activate, in source priority order. */\n readonly skills: readonly SkillCatalogEntry[];\n /** Problems found while loading: invalid skills, failed sources, duplicates. */\n readonly diagnostics: readonly SkillDiagnostic[];\n /**\n * System-prompt text listing each skill's name and description.\n *\n * @returns The catalog prompt, or `null` when there are no skills.\n */\n prompt(): string | null;\n /**\n * Find a skill by name.\n *\n * @param name - Skill name.\n * @returns The entry, or `undefined` when the catalog has no such skill.\n */\n find(name: string): SkillCatalogEntry | undefined;\n /**\n * Render a skill's instructions and resource list for the model.\n *\n * @param name - Skill name.\n */\n activate(name: string): SkillResult<string, UnknownSkillError>;\n /**\n * Read a bundled file.\n *\n * @param request - Either `name` and a skill-relative `path`, or a\n * qualified `path` such as `my-skill/references/guide.md`.\n */\n readResource(request: {\n readonly name?: string;\n readonly path: string;\n }): Promise<SkillResult<SkillCatalogResource, SkillResourceError>>;\n}\n\n/** A skill in a {@link SkillCatalog}. */\nexport interface SkillCatalogEntry {\n /** The parsed skill. */\n readonly skill: Skill;\n /** Id of the source that provided it. */\n readonly sourceId: string;\n /** Files bundled with the skill. */\n readonly resources: readonly SkillResourceInfo[];\n /** Absolute directory in the agent's filesystem, when the source has one. */\n readonly location?: string;\n}\n\n/** A resource read through a {@link SkillCatalog}. */\nexport interface SkillCatalogResource {\n /** The skill that owns the resource. */\n readonly entry: SkillCatalogEntry;\n /** The resource and its content. */\n readonly resource: SkillResource;\n}\n\n/** Why {@link SkillCatalog.readResource} failed. */\nexport type SkillResourceError =\n | UnknownSkillError\n | InvalidSkillResourcePathError\n | SkillResourceNotFoundError\n | SkillSourceError;\n\n/** A problem found while loading a catalog. Never fatal. */\nexport type SkillDiagnostic =\n | {\n /** A `SKILL.md` broke a spec rule and was skipped. */\n readonly _tag: \"InvalidSkill\";\n readonly sourceId: string;\n readonly location: string;\n readonly error: SkillParseError;\n }\n | {\n /**\n * A source could not be listed. With `previous`, its skills from the\n * previous catalog are kept (`keptPrevious`); otherwise it is skipped.\n */\n readonly _tag: \"SourceFailed\";\n readonly sourceId: string;\n readonly error: SkillSourceError;\n readonly keptPrevious: boolean;\n }\n | {\n /** A skill breaks a spec rule but was loaded anyway. */\n readonly _tag: \"SkillWarning\";\n readonly sourceId: string;\n readonly name: string;\n readonly error: SkillParseError;\n }\n | {\n /** A later source listed a name an earlier source already provided. */\n readonly _tag: \"DuplicateSkill\";\n readonly name: string;\n readonly sourceId: string;\n readonly keptSourceId: string;\n };\n\n/** The catalog has no skill with the requested name. */\nexport class UnknownSkillError extends Error {\n /** Stable tag for narrowing. */\n readonly _tag = \"UnknownSkillError\" as const;\n\n /** @param skill - The requested name. */\n constructor(readonly skill: string) {\n super(`Skill not found: ${skill}`);\n this.name = \"UnknownSkillError\";\n }\n}\n\n/** Options for {@link loadSkillCatalog}. */\nexport interface LoadSkillCatalogOptions {\n /**\n * The catalog this load replaces. When a source fails to list, its skills\n * from `previous` are kept, so a transient outage does not remove working\n * skills from the prompt and tools. Sources are matched by identity.\n */\n readonly previous?: SkillCatalog;\n}\n\n/**\n * Successful listings behind each catalog, by source object. Lets a later\n * load fall back to the last good listing of a failing source without\n * putting listings on the public catalog shape.\n */\nconst catalogListings = new WeakMap<\n SkillCatalog,\n ReadonlyMap<SkillSource, SkillListing>\n>();\n\n/**\n * Load every source and merge them into a catalog.\n *\n * Sources apply in order: the first source to list a name wins. A failing\n * source or an invalid skill becomes a diagnostic instead of an error, so\n * one bad source never hides the others. Skills that set\n * `disable-model-invocation: true` are left out.\n *\n * @param sources - Skill sources in priority order.\n * @param options - Pass `previous` to keep a failing source's last skills.\n * @returns The merged catalog.\n */\nexport async function loadSkillCatalog(\n sources: readonly SkillSource[],\n options: LoadSkillCatalogOptions = {}\n): Promise<SkillCatalog> {\n const previousListings = options.previous\n ? catalogListings.get(options.previous)\n : undefined;\n // Custom sources should return failures, but one that throws must still\n // not hide the others.\n const listings = await Promise.all(\n sources.map(async (source) => ({\n source,\n listed: await source\n .list()\n .catch((cause: unknown) =>\n err(new SkillSourceError(source.id, \"list\", cause))\n )\n }))\n );\n\n const diagnostics: SkillDiagnostic[] = [];\n const entries = new Map<string, SkillCatalogEntry>();\n // Resources are read from the source object that listed the skill, not\n // looked up by id, because two sources may share an id.\n const sourceBySkill = new Map<string, SkillSource>();\n const goodListings = new Map<SkillSource, SkillListing>();\n\n for (const { source, listed } of listings) {\n let listing: SkillListing;\n if (listed.ok) {\n listing = listed.value;\n } else {\n const fallback = previousListings?.get(source);\n diagnostics.push({\n _tag: \"SourceFailed\",\n sourceId: source.id,\n error: listed.error,\n keptPrevious: fallback !== undefined\n });\n if (!fallback) continue;\n listing = fallback;\n }\n goodListings.set(source, listing);\n for (const invalid of listing.invalid) {\n diagnostics.push({\n _tag: \"InvalidSkill\",\n sourceId: source.id,\n location: invalid.location,\n error: invalid.error\n });\n }\n for (const { skill, resources, location, warnings } of listing.skills) {\n const existing = entries.get(skill.name);\n if (existing) {\n diagnostics.push({\n _tag: \"DuplicateSkill\",\n name: skill.name,\n sourceId: source.id,\n keptSourceId: existing.sourceId\n });\n continue;\n }\n entries.set(skill.name, {\n skill,\n sourceId: source.id,\n resources,\n ...(location === undefined ? {} : { location })\n });\n sourceBySkill.set(skill.name, source);\n // Only for the copy the catalog keeps: a skipped duplicate already has\n // its own diagnostic, and \"was loaded\" would be false for it.\n for (const warning of warnings ?? []) {\n diagnostics.push({\n _tag: \"SkillWarning\",\n sourceId: source.id,\n name: skill.name,\n error: warning\n });\n }\n }\n }\n\n const skills = [...entries.values()].filter((entry) =>\n isModelInvocable(entry.skill)\n );\n const visible = new Map<string, SkillCatalogEntry>(\n skills.map((entry) => [entry.skill.name, entry])\n );\n const prompt = renderCatalogPrompt(skills);\n\n const catalog: SkillCatalog = {\n fingerprint: fingerprintOf(prompt ?? \"\"),\n skills,\n diagnostics,\n prompt: () => prompt,\n find: (name) => visible.get(name),\n activate(name) {\n const entry = visible.get(name);\n return entry\n ? ok(renderSkillActivation(entry))\n : err(new UnknownSkillError(name));\n },\n async readResource(request) {\n const target = resolveResourceTarget(visible, request);\n if (!target.ok) return target;\n const { entry, path } = target.value;\n const source = sourceBySkill.get(entry.skill.name);\n if (!source) return err(new UnknownSkillError(entry.skill.name));\n const read = await source\n .readResource(entry.skill.name, path)\n .catch((cause: unknown) =>\n err(new SkillSourceError(source.id, \"read-resource\", cause))\n );\n if (!read.ok) return read;\n return ok({ entry, resource: read.value });\n }\n };\n catalogListings.set(catalog, goodListings);\n return catalog;\n}\n\n/**\n * Describe a diagnostic in one line, for logs.\n *\n * @param diagnostic - A diagnostic from {@link SkillCatalog.diagnostics}.\n */\nexport function formatSkillDiagnostic(diagnostic: SkillDiagnostic): string {\n switch (diagnostic._tag) {\n case \"InvalidSkill\":\n return `Skipped invalid skill ${diagnostic.location} from source \"${diagnostic.sourceId}\": ${diagnostic.error.message}`;\n case \"SkillWarning\":\n return `Skill \"${diagnostic.name}\" from source \"${diagnostic.sourceId}\" breaks the Agent Skills spec but was loaded: ${diagnostic.error.message}`;\n case \"SourceFailed\":\n return `${diagnostic.error.message}. ${diagnostic.keptPrevious ? \"Its last listed skills were kept.\" : \"Its skills were skipped.\"}`;\n case \"DuplicateSkill\":\n return `Duplicate skill \"${diagnostic.name}\" from source \"${diagnostic.sourceId}\" ignored; already provided by \"${diagnostic.keptSourceId}\".`;\n }\n}\n\n/**\n * Render a resource read for the model.\n *\n * @param read - A resource returned by {@link SkillCatalog.readResource}.\n */\nexport function renderSkillResource(read: SkillCatalogResource): string {\n const { entry, resource } = read;\n return [\n `<skill_resource${attributes([\n [\"name\", entry.skill.name],\n [\"path\", resource.path],\n [\"kind\", resource.kind],\n [\"encoding\", resource.encoding],\n [\"mimeType\", resource.mimeType]\n ])}>`,\n resource.content,\n \"</skill_resource>\"\n ].join(\"\\n\");\n}\n\nfunction renderCatalogPrompt(\n skills: readonly SkillCatalogEntry[]\n): string | null {\n if (skills.length === 0) return null;\n return [\n \"Available skills. When a task matches a skill, use activate_skill with its name before proceeding.\",\n \"\",\n ...skills.map(\n ({ skill }) =>\n `- ${skill.name}: ${skill.description.replace(/\\s+/g, \" \")}`\n )\n ].join(\"\\n\");\n}\n\nfunction renderSkillActivation(entry: SkillCatalogEntry): string {\n const lines = [\n `<skill_content${attributes([\n [\"name\", entry.skill.name],\n [\"location\", entry.location]\n ])}>`,\n entry.skill.body.trim()\n ];\n if (entry.resources.length > 0) {\n lines.push(\"\", \"<skill_resources>\");\n for (const resource of entry.resources) {\n lines.push(\n ` <file${attributes([\n [\"kind\", resource.kind],\n [\"encoding\", resource.encoding],\n [\n \"size\",\n resource.size === undefined ? undefined : String(resource.size)\n ]\n ])}>${resource.path}</file>`\n );\n }\n lines.push(\"</skill_resources>\");\n }\n lines.push(\"</skill_content>\");\n return lines.join(\"\\n\");\n}\n\nfunction resolveResourceTarget(\n skills: ReadonlyMap<string, SkillCatalogEntry>,\n request: { readonly name?: string; readonly path: string }\n): SkillResult<\n {\n entry: SkillCatalogEntry;\n path: SkillResourceInfo[\"path\"];\n },\n UnknownSkillError | InvalidSkillResourcePathError | SkillResourceNotFoundError\n> {\n let name = request.name;\n let relative = request.path;\n if (name === undefined) {\n const slash = relative.indexOf(\"/\");\n if (slash <= 0) return err(new InvalidSkillResourcePathError(relative));\n name = relative.slice(0, slash);\n relative = relative.slice(slash + 1);\n }\n const entry = skills.get(name);\n if (!entry) return err(new UnknownSkillError(name));\n const path = parseSkillResourcePath(relative);\n if (!path.ok) return path;\n // Only files the source listed are readable, whatever the source's store\n // holds beside them.\n if (!entry.resources.some((resource) => resource.path === path.value)) {\n return err(new SkillResourceNotFoundError(entry.skill.name, path.value));\n }\n return ok({ entry, path: path.value });\n}\n\nfunction attributes(\n pairs: ReadonlyArray<readonly [string, string | undefined]>\n): string {\n return pairs\n .filter((pair): pair is readonly [string, string] => pair[1] !== undefined)\n .map(([key, value]) => ` ${key}=\"${value.replace(/\"/g, \""\")}\"`)\n .join(\"\");\n}\n\n/** Two FNV-1a passes with different seeds: cheap and stable across isolates. */\nfunction fingerprintOf(text: string): string {\n let a = 0x811c9dc5;\n let b = 0x01000193;\n for (let index = 0; index < text.length; index++) {\n const code = text.charCodeAt(index);\n a = Math.imul(a ^ code, 0x01000193);\n b = Math.imul(b ^ code, 0x811c9dc5);\n }\n return `${(a >>> 0).toString(16).padStart(8, \"0\")}${(b >>> 0).toString(16).padStart(8, \"0\")}`;\n}\n"],"mappings":";;;AA2EA,IAAa,mBAAb,cAAsC,MAAM;;;;;;CAS1C,YACE,UACA,WACA,OACA;EACA,MACE,iBAAiB,SAAS,cAAc,cAAc,SAAS,gBAAgB,kBAAkB,IAAI,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,KAC1J,EAAE,MAAM,CACV;EAPS,KAAA,WAAA;EACA,KAAA,YAAA;EATX,KAAS,OAAO;EAgBd,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,6BAAb,cAAgD,MAAM;;;;;CAQpD,YACE,OACA,MACA;EACA,MAAM,uBAAuB,MAAM,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,SAAS,WACP,OACQ;CACR,OAAO,MACJ,QAAQ,SAA4C,KAAK,OAAO,KAAA,CAAS,CAAC,CAC1E,KAAK,CAAC,KAAK,WAAW,IAAI,IAAI,IAAI,MAAM,QAAQ,MAAM,QAAQ,EAAE,EAAE,CAAC,CACnE,KAAK,EAAE;AACZ;;AAGA,SAAS,cAAc,MAAsB;CAC3C,IAAI,IAAI;CACR,IAAI,IAAI;CACR,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS;EAChD,MAAM,OAAO,KAAK,WAAW,KAAK;EAClC,IAAI,KAAK,KAAK,IAAI,MAAM,QAAU;EAClC,IAAI,KAAK,KAAK,IAAI,MAAM,UAAU;CACpC;CACA,OAAO,IAAI,MAAM,EAAA,CAAG,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,KAAK,MAAM,EAAA,CAAG,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG;AAC5F"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import {
|
|
2
|
+
d as SkillResourceInfo,
|
|
3
|
+
h as SkillResult,
|
|
4
|
+
i as SkillParseError,
|
|
5
|
+
l as InvalidSkillResourcePathError,
|
|
6
|
+
n as Skill,
|
|
7
|
+
u as SkillResource
|
|
8
|
+
} from "./skill-DRBcIBjC.js";
|
|
9
|
+
import {
|
|
10
|
+
a as SkillSource,
|
|
11
|
+
i as SkillResourceNotFoundError,
|
|
12
|
+
o as SkillSourceError
|
|
13
|
+
} from "./source-9RQzlEhM.js";
|
|
14
|
+
|
|
15
|
+
//#region src/skills/catalog.d.ts
|
|
16
|
+
/**
|
|
17
|
+
* The skills an agent can use right now, merged from its sources.
|
|
18
|
+
*
|
|
19
|
+
* Load one with {@link loadSkillCatalog}; load it again to pick up changes.
|
|
20
|
+
* Framework adapters (Think's AI SDK tools, the pi `skills()` extension)
|
|
21
|
+
* wrap a catalog so every framework shows the model the same catalog text,
|
|
22
|
+
* activation output, and resource output.
|
|
23
|
+
*/
|
|
24
|
+
interface SkillCatalog {
|
|
25
|
+
/** Changes whenever {@link prompt} would change. */
|
|
26
|
+
readonly fingerprint: string;
|
|
27
|
+
/** Skills the model may activate, in source priority order. */
|
|
28
|
+
readonly skills: readonly SkillCatalogEntry[];
|
|
29
|
+
/** Problems found while loading: invalid skills, failed sources, duplicates. */
|
|
30
|
+
readonly diagnostics: readonly SkillDiagnostic[];
|
|
31
|
+
/**
|
|
32
|
+
* System-prompt text listing each skill's name and description.
|
|
33
|
+
*
|
|
34
|
+
* @returns The catalog prompt, or `null` when there are no skills.
|
|
35
|
+
*/
|
|
36
|
+
prompt(): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Find a skill by name.
|
|
39
|
+
*
|
|
40
|
+
* @param name - Skill name.
|
|
41
|
+
* @returns The entry, or `undefined` when the catalog has no such skill.
|
|
42
|
+
*/
|
|
43
|
+
find(name: string): SkillCatalogEntry | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Render a skill's instructions and resource list for the model.
|
|
46
|
+
*
|
|
47
|
+
* @param name - Skill name.
|
|
48
|
+
*/
|
|
49
|
+
activate(name: string): SkillResult<string, UnknownSkillError>;
|
|
50
|
+
/**
|
|
51
|
+
* Read a bundled file.
|
|
52
|
+
*
|
|
53
|
+
* @param request - Either `name` and a skill-relative `path`, or a
|
|
54
|
+
* qualified `path` such as `my-skill/references/guide.md`.
|
|
55
|
+
*/
|
|
56
|
+
readResource(request: {
|
|
57
|
+
readonly name?: string;
|
|
58
|
+
readonly path: string;
|
|
59
|
+
}): Promise<SkillResult<SkillCatalogResource, SkillResourceError>>;
|
|
60
|
+
}
|
|
61
|
+
/** A skill in a {@link SkillCatalog}. */
|
|
62
|
+
interface SkillCatalogEntry {
|
|
63
|
+
/** The parsed skill. */
|
|
64
|
+
readonly skill: Skill;
|
|
65
|
+
/** Id of the source that provided it. */
|
|
66
|
+
readonly sourceId: string;
|
|
67
|
+
/** Files bundled with the skill. */
|
|
68
|
+
readonly resources: readonly SkillResourceInfo[];
|
|
69
|
+
/** Absolute directory in the agent's filesystem, when the source has one. */
|
|
70
|
+
readonly location?: string;
|
|
71
|
+
}
|
|
72
|
+
/** A resource read through a {@link SkillCatalog}. */
|
|
73
|
+
interface SkillCatalogResource {
|
|
74
|
+
/** The skill that owns the resource. */
|
|
75
|
+
readonly entry: SkillCatalogEntry;
|
|
76
|
+
/** The resource and its content. */
|
|
77
|
+
readonly resource: SkillResource;
|
|
78
|
+
}
|
|
79
|
+
/** Why {@link SkillCatalog.readResource} failed. */
|
|
80
|
+
type SkillResourceError =
|
|
81
|
+
| UnknownSkillError
|
|
82
|
+
| InvalidSkillResourcePathError
|
|
83
|
+
| SkillResourceNotFoundError
|
|
84
|
+
| SkillSourceError;
|
|
85
|
+
/** A problem found while loading a catalog. Never fatal. */
|
|
86
|
+
type SkillDiagnostic =
|
|
87
|
+
| {
|
|
88
|
+
/** A `SKILL.md` broke a spec rule and was skipped. */ readonly _tag: "InvalidSkill";
|
|
89
|
+
readonly sourceId: string;
|
|
90
|
+
readonly location: string;
|
|
91
|
+
readonly error: SkillParseError;
|
|
92
|
+
}
|
|
93
|
+
| {
|
|
94
|
+
/**
|
|
95
|
+
* A source could not be listed. With `previous`, its skills from the
|
|
96
|
+
* previous catalog are kept (`keptPrevious`); otherwise it is skipped.
|
|
97
|
+
*/
|
|
98
|
+
readonly _tag: "SourceFailed";
|
|
99
|
+
readonly sourceId: string;
|
|
100
|
+
readonly error: SkillSourceError;
|
|
101
|
+
readonly keptPrevious: boolean;
|
|
102
|
+
}
|
|
103
|
+
| {
|
|
104
|
+
/** A skill breaks a spec rule but was loaded anyway. */ readonly _tag: "SkillWarning";
|
|
105
|
+
readonly sourceId: string;
|
|
106
|
+
readonly name: string;
|
|
107
|
+
readonly error: SkillParseError;
|
|
108
|
+
}
|
|
109
|
+
| {
|
|
110
|
+
/** A later source listed a name an earlier source already provided. */ readonly _tag: "DuplicateSkill";
|
|
111
|
+
readonly name: string;
|
|
112
|
+
readonly sourceId: string;
|
|
113
|
+
readonly keptSourceId: string;
|
|
114
|
+
};
|
|
115
|
+
/** The catalog has no skill with the requested name. */
|
|
116
|
+
declare class UnknownSkillError extends Error {
|
|
117
|
+
readonly skill: string;
|
|
118
|
+
/** Stable tag for narrowing. */
|
|
119
|
+
readonly _tag: "UnknownSkillError";
|
|
120
|
+
/** @param skill - The requested name. */
|
|
121
|
+
constructor(skill: string);
|
|
122
|
+
}
|
|
123
|
+
/** Options for {@link loadSkillCatalog}. */
|
|
124
|
+
interface LoadSkillCatalogOptions {
|
|
125
|
+
/**
|
|
126
|
+
* The catalog this load replaces. When a source fails to list, its skills
|
|
127
|
+
* from `previous` are kept, so a transient outage does not remove working
|
|
128
|
+
* skills from the prompt and tools. Sources are matched by identity.
|
|
129
|
+
*/
|
|
130
|
+
readonly previous?: SkillCatalog;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Load every source and merge them into a catalog.
|
|
134
|
+
*
|
|
135
|
+
* Sources apply in order: the first source to list a name wins. A failing
|
|
136
|
+
* source or an invalid skill becomes a diagnostic instead of an error, so
|
|
137
|
+
* one bad source never hides the others. Skills that set
|
|
138
|
+
* `disable-model-invocation: true` are left out.
|
|
139
|
+
*
|
|
140
|
+
* @param sources - Skill sources in priority order.
|
|
141
|
+
* @param options - Pass `previous` to keep a failing source's last skills.
|
|
142
|
+
* @returns The merged catalog.
|
|
143
|
+
*/
|
|
144
|
+
declare function loadSkillCatalog(
|
|
145
|
+
sources: readonly SkillSource[],
|
|
146
|
+
options?: LoadSkillCatalogOptions
|
|
147
|
+
): Promise<SkillCatalog>;
|
|
148
|
+
/**
|
|
149
|
+
* Describe a diagnostic in one line, for logs.
|
|
150
|
+
*
|
|
151
|
+
* @param diagnostic - A diagnostic from {@link SkillCatalog.diagnostics}.
|
|
152
|
+
*/
|
|
153
|
+
declare function formatSkillDiagnostic(diagnostic: SkillDiagnostic): string;
|
|
154
|
+
/**
|
|
155
|
+
* Render a resource read for the model.
|
|
156
|
+
*
|
|
157
|
+
* @param read - A resource returned by {@link SkillCatalog.readResource}.
|
|
158
|
+
*/
|
|
159
|
+
declare function renderSkillResource(read: SkillCatalogResource): string;
|
|
160
|
+
//#endregion
|
|
161
|
+
export {
|
|
162
|
+
SkillDiagnostic as a,
|
|
163
|
+
formatSkillDiagnostic as c,
|
|
164
|
+
SkillCatalogResource as i,
|
|
165
|
+
loadSkillCatalog as l,
|
|
166
|
+
SkillCatalog as n,
|
|
167
|
+
SkillResourceError as o,
|
|
168
|
+
SkillCatalogEntry as r,
|
|
169
|
+
UnknownSkillError as s,
|
|
170
|
+
LoadSkillCatalogOptions as t,
|
|
171
|
+
renderSkillResource as u
|
|
172
|
+
};
|
|
173
|
+
//# sourceMappingURL=catalog-BpiVV1OF.d.ts.map
|
package/dist/chat/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
_ as FiberRecoveryContext$1,
|
|
10
10
|
at as isPositionlessAgentToolChunk,
|
|
11
11
|
z as AgentToolEventState
|
|
12
|
-
} from "../agent-routing-
|
|
12
|
+
} from "../agent-routing-vVMA7m8Y.js";
|
|
13
13
|
import { _ as TaskStep, m as TaskRunOptions } from "../tasks-E89KdwkS.js";
|
|
14
14
|
import {
|
|
15
15
|
n as ClientToolSchema,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
r as AgentToolProgressEmitResult,
|
|
35
35
|
s as interceptAgentToolBroadcast,
|
|
36
36
|
t as AgentToolBroadcastHooks
|
|
37
|
-
} from "../agent-tools-
|
|
37
|
+
} from "../agent-tools-gGXXkf1z.js";
|
|
38
38
|
import { l as SessionMessage } from "../types-B7LojTe4.js";
|
|
39
39
|
import { ModelMessage, UIMessage } from "ai";
|
|
40
40
|
import { Connection, FiberRecoveryContext } from "agents";
|
package/dist/chat-sdk/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
bn as DynamicAgentClass,
|
|
3
2
|
c as Agent,
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
nn as DynamicAgentStub,
|
|
4
|
+
tn as DynamicAgentClass
|
|
5
|
+
} from "../agent-routing-vVMA7m8Y.js";
|
|
6
6
|
import { Lock, QueueEntry, StateAdapter } from "chat";
|
|
7
7
|
|
|
8
8
|
//#region src/chat-sdk/agent.d.ts
|
package/dist/chat-sdk/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as getCurrentAgent, t as Agent } from "../src-
|
|
1
|
+
import { i as getCurrentAgent, t as Agent } from "../src-DoGNJ4Ud.js";
|
|
2
2
|
//#region src/chat-sdk/agent.ts
|
|
3
3
|
const NEXT_CLEANUP_AT_KEY = "next_cleanup_at";
|
|
4
4
|
const CLEANUP_SCHEDULE_ID_KEY = "cleanup_schedule_id";
|