@anvia/core 0.12.8 → 0.13.1
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/agent/index.d.ts +11 -11
- package/dist/agent/index.js +10 -11
- package/dist/{agent-BB9vVH6P.d.ts → agent-3qSfIKIj.d.ts} +8 -7
- package/dist/audio-generation/index.d.ts +1 -1
- package/dist/{chunk-NPZDYOE6.js → chunk-2ODTMRHP.js} +11 -10
- package/dist/chunk-2ODTMRHP.js.map +1 -0
- package/dist/{chunk-IN5NPAWL.js → chunk-CLFDBOH3.js} +6 -6
- package/dist/{chunk-QVFOCNF6.js → chunk-CNTGKNZ3.js} +99 -10
- package/dist/chunk-CNTGKNZ3.js.map +1 -0
- package/dist/chunk-CQNNSZPG.js +9 -0
- package/dist/chunk-CQNNSZPG.js.map +1 -0
- package/dist/{chunk-HF4KHHNM.js → chunk-DC2GJDPR.js} +5 -5
- package/dist/chunk-DC2GJDPR.js.map +1 -0
- package/dist/{chunk-IZM6FNCT.js → chunk-I7TM7TKX.js} +48 -42
- package/dist/chunk-I7TM7TKX.js.map +1 -0
- package/dist/{chunk-WRNPY5C6.js → chunk-KXXFWLKP.js} +3 -3
- package/dist/{chunk-2STANSN6.js → chunk-L52YHJ5L.js} +23 -20
- package/dist/chunk-L52YHJ5L.js.map +1 -0
- package/dist/{chunk-UDISNNKR.js → chunk-NS7W4G26.js} +70 -21
- package/dist/chunk-NS7W4G26.js.map +1 -0
- package/dist/{chunk-SHORX7TZ.js → chunk-WHHQWT7D.js} +12 -13
- package/dist/chunk-WHHQWT7D.js.map +1 -0
- package/dist/{chunk-EGZCTSEW.js → chunk-WWNXZWST.js} +208 -132
- package/dist/chunk-WWNXZWST.js.map +1 -0
- package/dist/{chunk-JS5MGVNM.js → chunk-YBBD4HZ3.js} +8 -7
- package/dist/{chunk-JS5MGVNM.js.map → chunk-YBBD4HZ3.js.map} +1 -1
- package/dist/{chunk-FUJ3POKH.js → chunk-YTF65GYU.js} +2 -2
- package/dist/completion/index.d.ts +3 -3
- package/dist/completion/index.js +4 -2
- package/dist/embeddings/index.js +1 -1
- package/dist/evals/index.d.ts +8 -8
- package/dist/evals/index.js +59 -36
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +8 -8
- package/dist/extractor/index.js +11 -12
- package/dist/guardrails/index.d.ts +1 -1
- package/dist/hooks/index.d.ts +3 -3
- package/dist/hooks/index.js +1 -2
- package/dist/image-generation/index.d.ts +1 -1
- package/dist/{index-CM-V4LS3.d.ts → index-ZQAiHW5Q.d.ts} +2 -2
- package/dist/index.d.ts +12 -12
- package/dist/index.js +16 -14
- package/dist/internal/agent.d.ts +8 -8
- package/dist/internal/agent.js +9 -10
- package/dist/{create-completion-CC8-Ep3w.d.ts → json-C5a6auAm.d.ts} +4 -2
- package/dist/loaders/index.d.ts +1 -1
- package/dist/mcp/index.d.ts +4 -4
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/memory/index.d.ts +3 -3
- package/dist/{middleware-i-jLsLom.d.ts → middleware-Cc_-sosu.d.ts} +3 -3
- package/dist/observability/index.d.ts +3 -3
- package/dist/pipeline/index.d.ts +8 -8
- package/dist/pipeline/index.js +34 -19
- package/dist/pipeline/index.js.map +1 -1
- package/dist/request/index.d.ts +8 -8
- package/dist/request/index.js +8 -9
- package/dist/skills/index.d.ts +4 -4
- package/dist/skills/index.js +7 -7
- package/dist/{think-tool-BKDCOJh5.d.ts → think-tool-DvhOlrL8.d.ts} +1 -1
- package/dist/tool/index.d.ts +5 -5
- package/dist/tool/index.js +5 -6
- package/dist/{tool-f2stpvUP.d.ts → tool-6f9bK92X.d.ts} +1 -1
- package/dist/transcription/index.d.ts +1 -1
- package/dist/{types-5JgWDgaM.d.ts → types-BG3s2WzI.d.ts} +2 -2
- package/dist/{types-b6fOVoW1.d.ts → types-BZQlZ4Vs.d.ts} +1 -1
- package/dist/{types-Dh7gfoGw.d.ts → types-BaYwqozV.d.ts} +1 -1
- package/dist/{types-DmvXANwl.d.ts → types-C708DOhL.d.ts} +1 -1
- package/dist/{types-bNDxj4Tt.d.ts → types-CNeDsGjw.d.ts} +1 -1
- package/dist/{types-C15r7N_4.d.ts → types-DzdJOf35.d.ts} +17 -6
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +2 -2
- package/dist/vector-store/index.d.ts +4 -4
- package/dist/vector-store/index.js +3 -4
- package/package.json +1 -1
- package/dist/chunk-2STANSN6.js.map +0 -1
- package/dist/chunk-EGZCTSEW.js.map +0 -1
- package/dist/chunk-HF4KHHNM.js.map +0 -1
- package/dist/chunk-IZM6FNCT.js.map +0 -1
- package/dist/chunk-MMHG7WAM.js +0 -19
- package/dist/chunk-MMHG7WAM.js.map +0 -1
- package/dist/chunk-NPZDYOE6.js.map +0 -1
- package/dist/chunk-QVFOCNF6.js.map +0 -1
- package/dist/chunk-SHORX7TZ.js.map +0 -1
- package/dist/chunk-UDISNNKR.js.map +0 -1
- /package/dist/{chunk-IN5NPAWL.js.map → chunk-CLFDBOH3.js.map} +0 -0
- /package/dist/{chunk-WRNPY5C6.js.map → chunk-KXXFWLKP.js.map} +0 -0
- /package/dist/{chunk-FUJ3POKH.js.map → chunk-YTF65GYU.js.map} +0 -0
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { D as DynamicContextOptions, a as DynamicToolOptions, b as AgentEventStore, c as AgentEventStoreOptions, A as Agent } from '../agent-
|
|
2
|
-
export { d as AgentEventAppendInput, e as AgentEventRecord, f as AgentEventStoreInclude, g as AgentSession, h as AgentToolOptions } from '../agent-
|
|
1
|
+
import { D as DynamicContextOptions, a as DynamicToolOptions, b as AgentEventStore, c as AgentEventStoreOptions, A as Agent } from '../agent-3qSfIKIj.js';
|
|
2
|
+
export { d as AgentEventAppendInput, e as AgentEventRecord, f as AgentEventStoreInclude, g as AgentSession, h as AgentToolOptions } from '../agent-3qSfIKIj.js';
|
|
3
3
|
import { Z as ZodSchema } from '../zod-schema-C7F4clpm.js';
|
|
4
|
-
import { C as CompletionModel,
|
|
4
|
+
import { C as CompletionModel, f as JsonValue, t as ToolChoice } from '../types-DzdJOf35.js';
|
|
5
5
|
import { GuardrailPolicyInput } from '../guardrails/index.js';
|
|
6
|
-
import { P as PromptHook } from '../types-
|
|
7
|
-
import { a as McpServer } from '../types-
|
|
8
|
-
import { M as MemoryStore, a as MemoryOptions } from '../types-
|
|
9
|
-
import { b as AgentObserver, O as ObserveOptions } from '../index-
|
|
10
|
-
import { a as SkillSet } from '../types-
|
|
11
|
-
import { k as ToolSearchDocument, l as ToolSet, A as AgentMiddleware, e as ToolMiddleware } from '../middleware-
|
|
12
|
-
import { A as AnyTool, e as ToolApprovalsOptions } from '../tool-
|
|
13
|
-
import { a as VectorSearchIndex } from '../types-
|
|
6
|
+
import { P as PromptHook } from '../types-BaYwqozV.js';
|
|
7
|
+
import { a as McpServer } from '../types-BG3s2WzI.js';
|
|
8
|
+
import { M as MemoryStore, a as MemoryOptions } from '../types-CNeDsGjw.js';
|
|
9
|
+
import { b as AgentObserver, O as ObserveOptions } from '../index-ZQAiHW5Q.js';
|
|
10
|
+
import { a as SkillSet } from '../types-BZQlZ4Vs.js';
|
|
11
|
+
import { k as ToolSearchDocument, l as ToolSet, A as AgentMiddleware, e as ToolMiddleware } from '../middleware-Cc_-sosu.js';
|
|
12
|
+
import { A as AnyTool, e as ToolApprovalsOptions } from '../tool-6f9bK92X.js';
|
|
13
|
+
import { a as VectorSearchIndex } from '../types-C708DOhL.js';
|
|
14
14
|
import 'zod';
|
|
15
15
|
import '@modelcontextprotocol/sdk/client/sse.js';
|
|
16
16
|
import '@modelcontextprotocol/sdk/client/stdio.js';
|
package/dist/agent/index.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentBuilder
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-KXXFWLKP.js";
|
|
4
|
+
import "../chunk-L52YHJ5L.js";
|
|
5
|
+
import "../chunk-WWNXZWST.js";
|
|
6
6
|
import "../chunk-YK4WAAS4.js";
|
|
7
7
|
import "../chunk-XUUY2L2D.js";
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-MMHG7WAM.js";
|
|
8
|
+
import "../chunk-WHHQWT7D.js";
|
|
9
|
+
import "../chunk-I7TM7TKX.js";
|
|
10
|
+
import "../chunk-2ODTMRHP.js";
|
|
12
11
|
import "../chunk-M6RPFHG7.js";
|
|
13
|
-
import "../chunk-
|
|
14
|
-
import "../chunk-
|
|
15
|
-
import "../chunk-FUJ3POKH.js";
|
|
16
|
-
import "../chunk-QVFOCNF6.js";
|
|
12
|
+
import "../chunk-YTF65GYU.js";
|
|
13
|
+
import "../chunk-CNTGKNZ3.js";
|
|
17
14
|
import "../chunk-WQKHFADH.js";
|
|
15
|
+
import "../chunk-YBBD4HZ3.js";
|
|
16
|
+
import "../chunk-OIMLU4SF.js";
|
|
18
17
|
import "../chunk-CWUJUSOS.js";
|
|
19
18
|
export {
|
|
20
19
|
AgentBuilder
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { C as CompletionModel, M as Message, D as Document,
|
|
1
|
+
import { C as CompletionModel, M as Message, D as Document, f as JsonValue, t as ToolChoice, J as JsonObject } from './types-DzdJOf35.js';
|
|
2
2
|
import { GuardrailPolicyInput, GuardrailPolicy } from './guardrails/index.js';
|
|
3
|
-
import { P as PromptHook } from './types-
|
|
4
|
-
import { c as MemoryContext, e as MemoryRegistration, S as SessionOptions } from './types-
|
|
5
|
-
import { c as AgentTraceOptions, P as PromptResponse, a as AgentStreamEvent, d as AgentObserverRegistration } from './index-
|
|
6
|
-
import { e as ToolApprovalsOptions, T as Tool, A as AnyTool, f as ToolCallContext, N as NormalizedToolOutput } from './tool-
|
|
7
|
-
import { A as AgentMiddleware, e as ToolMiddleware, k as ToolSearchDocument, l as ToolSet } from './middleware-
|
|
8
|
-
import { V as VectorFilter, c as VectorSearchResult, a as VectorSearchIndex } from './types-
|
|
3
|
+
import { P as PromptHook } from './types-BaYwqozV.js';
|
|
4
|
+
import { c as MemoryContext, e as MemoryRegistration, S as SessionOptions } from './types-CNeDsGjw.js';
|
|
5
|
+
import { c as AgentTraceOptions, P as PromptResponse, a as AgentStreamEvent, d as AgentObserverRegistration } from './index-ZQAiHW5Q.js';
|
|
6
|
+
import { e as ToolApprovalsOptions, T as Tool, A as AnyTool, f as ToolCallContext, N as NormalizedToolOutput } from './tool-6f9bK92X.js';
|
|
7
|
+
import { A as AgentMiddleware, e as ToolMiddleware, k as ToolSearchDocument, l as ToolSet } from './middleware-Cc_-sosu.js';
|
|
8
|
+
import { V as VectorFilter, c as VectorSearchResult, a as VectorSearchIndex } from './types-C708DOhL.js';
|
|
9
9
|
|
|
10
10
|
declare class PromptRequest<M extends CompletionModel = CompletionModel> {
|
|
11
11
|
private readonly agent;
|
|
@@ -53,6 +53,7 @@ declare class PromptRequest<M extends CompletionModel = CompletionModel> {
|
|
|
53
53
|
readableStream(): ReadableStream<Uint8Array>;
|
|
54
54
|
private runCompletion;
|
|
55
55
|
private providerTraceRequest;
|
|
56
|
+
private generationStartArgs;
|
|
56
57
|
private executeToolCalls;
|
|
57
58
|
private runOutputGuardrailsForResponse;
|
|
58
59
|
private recordGuardrailDecision;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
compact
|
|
3
|
-
} from "./chunk-MMHG7WAM.js";
|
|
4
|
-
|
|
5
1
|
// src/hooks/control.ts
|
|
6
2
|
function createHook(hook) {
|
|
7
3
|
return hook;
|
|
@@ -13,11 +9,16 @@ function skipTool(reason) {
|
|
|
13
9
|
return { type: "skip", reason };
|
|
14
10
|
}
|
|
15
11
|
function requestToolApproval(options = {}) {
|
|
16
|
-
|
|
17
|
-
type: "approval_request"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
const action = {
|
|
13
|
+
type: "approval_request"
|
|
14
|
+
};
|
|
15
|
+
if (options.reason !== void 0) {
|
|
16
|
+
action.reason = options.reason;
|
|
17
|
+
}
|
|
18
|
+
if (options.rejectMessage !== void 0) {
|
|
19
|
+
action.rejectMessage = options.rejectMessage;
|
|
20
|
+
}
|
|
21
|
+
return action;
|
|
21
22
|
}
|
|
22
23
|
var runControl = {
|
|
23
24
|
continue() {
|
|
@@ -50,4 +51,4 @@ export {
|
|
|
50
51
|
runControl,
|
|
51
52
|
toolCallControl
|
|
52
53
|
};
|
|
53
|
-
//# sourceMappingURL=chunk-
|
|
54
|
+
//# sourceMappingURL=chunk-2ODTMRHP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/control.ts"],"sourcesContent":["import type {\n HookAction,\n PromptHook,\n RunControl,\n ToolApprovalRequestOptions,\n ToolCallControl,\n ToolCallHookAction,\n} from \"./types\";\n\nexport function createHook<RawResponse = unknown>(\n hook: PromptHook<RawResponse>,\n): PromptHook<RawResponse> {\n return hook;\n}\n\nexport function cancelPrompt(reason: string): HookAction {\n return { type: \"terminate\", reason };\n}\n\nexport function skipTool(reason: string): ToolCallHookAction {\n return { type: \"skip\", reason };\n}\n\nexport function requestToolApproval(options: ToolApprovalRequestOptions = {}): ToolCallHookAction {\n const action: ToolCallHookAction = {\n type: \"approval_request\" as const,\n };\n if (options.reason !== undefined) {\n action.reason = options.reason;\n }\n if (options.rejectMessage !== undefined) {\n action.rejectMessage = options.rejectMessage;\n }\n return action;\n}\n\nexport const runControl: RunControl = {\n continue() {\n return { type: \"continue\" };\n },\n cancel(reason: string) {\n return cancelPrompt(reason);\n },\n};\n\nexport const toolCallControl: ToolCallControl = {\n run() {\n return { type: \"continue\" };\n },\n skip(reason: string) {\n return skipTool(reason);\n },\n cancel(reason: string) {\n return { type: \"terminate\", reason };\n },\n requestApproval(options) {\n return requestToolApproval(options);\n },\n};\n"],"mappings":";AASO,SAAS,WACd,MACyB;AACzB,SAAO;AACT;AAEO,SAAS,aAAa,QAA4B;AACvD,SAAO,EAAE,MAAM,aAAa,OAAO;AACrC;AAEO,SAAS,SAAS,QAAoC;AAC3D,SAAO,EAAE,MAAM,QAAQ,OAAO;AAChC;AAEO,SAAS,oBAAoB,UAAsC,CAAC,GAAuB;AAChG,QAAM,SAA6B;AAAA,IACjC,MAAM;AAAA,EACR;AACA,MAAI,QAAQ,WAAW,QAAW;AAChC,WAAO,SAAS,QAAQ;AAAA,EAC1B;AACA,MAAI,QAAQ,kBAAkB,QAAW;AACvC,WAAO,gBAAgB,QAAQ;AAAA,EACjC;AACA,SAAO;AACT;AAEO,IAAM,aAAyB;AAAA,EACpC,WAAW;AACT,WAAO,EAAE,MAAM,WAAW;AAAA,EAC5B;AAAA,EACA,OAAO,QAAgB;AACrB,WAAO,aAAa,MAAM;AAAA,EAC5B;AACF;AAEO,IAAM,kBAAmC;AAAA,EAC9C,MAAM;AACJ,WAAO,EAAE,MAAM,WAAW;AAAA,EAC5B;AAAA,EACA,KAAK,QAAgB;AACnB,WAAO,SAAS,MAAM;AAAA,EACxB;AAAA,EACA,OAAO,QAAgB;AACrB,WAAO,EAAE,MAAM,aAAa,OAAO;AAAA,EACrC;AAAA,EACA,gBAAgB,SAAS;AACvB,WAAO,oBAAoB,OAAO;AAAA,EACpC;AACF;","names":[]}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentBuilder
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KXXFWLKP.js";
|
|
4
4
|
import {
|
|
5
5
|
extractRagText
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-WWNXZWST.js";
|
|
7
7
|
import {
|
|
8
8
|
createTool
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-I7TM7TKX.js";
|
|
10
10
|
import {
|
|
11
11
|
CompletionRequestBuilder
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-YTF65GYU.js";
|
|
13
13
|
import {
|
|
14
14
|
CompletionCapabilityError,
|
|
15
15
|
Message,
|
|
16
16
|
Usage
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-CNTGKNZ3.js";
|
|
18
18
|
|
|
19
19
|
// src/extractor/extractor.ts
|
|
20
20
|
var SUBMIT_TOOL_NAME = "submit";
|
|
@@ -138,4 +138,4 @@ export {
|
|
|
138
138
|
Extractor,
|
|
139
139
|
ExtractorBuilder
|
|
140
140
|
};
|
|
141
|
-
//# sourceMappingURL=chunk-
|
|
141
|
+
//# sourceMappingURL=chunk-CLFDBOH3.js.map
|
|
@@ -1,3 +1,68 @@
|
|
|
1
|
+
// src/completion/json.ts
|
|
2
|
+
function isJsonValue(value) {
|
|
3
|
+
return isJsonValueWithAncestors(value, /* @__PURE__ */ new WeakSet());
|
|
4
|
+
}
|
|
5
|
+
function isJsonValueWithAncestors(value, ancestors) {
|
|
6
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (typeof value === "number") {
|
|
10
|
+
return Number.isFinite(value);
|
|
11
|
+
}
|
|
12
|
+
if (typeof value !== "object" || ancestors.has(value)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
ancestors.add(value);
|
|
16
|
+
try {
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
if (!hasOnlyDenseArrayProperties(value)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
22
|
+
if (!isJsonValueWithAncestors(value[index], ancestors)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
const prototype = Object.getPrototypeOf(value);
|
|
29
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
33
|
+
if (typeof key !== "string") {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
37
|
+
if (descriptor === void 0 || !descriptor.enumerable || !("value" in descriptor) || !isJsonValueWithAncestors(descriptor.value, ancestors)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
} finally {
|
|
45
|
+
ancestors.delete(value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function hasOnlyDenseArrayProperties(value) {
|
|
49
|
+
const keys = Reflect.ownKeys(value);
|
|
50
|
+
if (keys.length !== value.length + 1 || keys.at(-1) !== "length") {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
54
|
+
const key = String(index);
|
|
55
|
+
if (keys[index] !== key) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
59
|
+
if (descriptor === void 0 || !descriptor.enumerable || !("value" in descriptor)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
1
66
|
// src/completion/types.ts
|
|
2
67
|
var UserContent = {
|
|
3
68
|
text(text) {
|
|
@@ -147,30 +212,53 @@ function reasoningDisplayText(reasoning) {
|
|
|
147
212
|
}).join("");
|
|
148
213
|
}
|
|
149
214
|
var Message = {
|
|
150
|
-
system(content) {
|
|
151
|
-
return { role: "system", content };
|
|
215
|
+
system(content, options = {}) {
|
|
216
|
+
return { role: "system", content, ...messageMetadata(options) };
|
|
152
217
|
},
|
|
153
|
-
user(content) {
|
|
218
|
+
user(content, options = {}) {
|
|
154
219
|
return {
|
|
155
220
|
role: "user",
|
|
156
|
-
content: typeof content === "string" ? [UserContent.text(content)] : content
|
|
221
|
+
content: typeof content === "string" ? [UserContent.text(content)] : content,
|
|
222
|
+
...messageMetadata(options)
|
|
157
223
|
};
|
|
158
224
|
},
|
|
159
|
-
assistant(content,
|
|
225
|
+
assistant(content, idOrOptions) {
|
|
160
226
|
const normalized = typeof content === "string" ? [AssistantContent.text(content)] : content;
|
|
161
|
-
|
|
227
|
+
const options = typeof idOrOptions === "string" ? { id: idOrOptions } : idOrOptions ?? {};
|
|
228
|
+
const metadata = messageMetadata(options).metadata;
|
|
229
|
+
const message = options.id === void 0 ? { role: "assistant", content: normalized } : { role: "assistant", id: options.id, content: normalized };
|
|
230
|
+
if (metadata !== void 0) {
|
|
231
|
+
message.metadata = metadata;
|
|
232
|
+
}
|
|
233
|
+
return message;
|
|
162
234
|
},
|
|
163
|
-
tool(content) {
|
|
235
|
+
tool(content, options = {}) {
|
|
164
236
|
return {
|
|
165
237
|
role: "tool",
|
|
166
|
-
content: Array.isArray(content) ? content : [content]
|
|
238
|
+
content: Array.isArray(content) ? content : [content],
|
|
239
|
+
...messageMetadata(options)
|
|
167
240
|
};
|
|
168
241
|
},
|
|
169
242
|
toolResult(id, output, options = {}) {
|
|
170
243
|
const content = isToolResultContentArray(output) ? output : serializeToolResultOutput(output);
|
|
171
|
-
return Message.tool(
|
|
244
|
+
return Message.tool(
|
|
245
|
+
ToolContent.toolResult(id, content, {
|
|
246
|
+
callId: options.callId,
|
|
247
|
+
toolName: options.toolName
|
|
248
|
+
}),
|
|
249
|
+
{ metadata: options.metadata }
|
|
250
|
+
);
|
|
172
251
|
}
|
|
173
252
|
};
|
|
253
|
+
function messageMetadata(options) {
|
|
254
|
+
if (options.metadata === void 0) {
|
|
255
|
+
return {};
|
|
256
|
+
}
|
|
257
|
+
if (!isJsonValue(options.metadata)) {
|
|
258
|
+
throw new TypeError("Message metadata must be a strict JSON value.");
|
|
259
|
+
}
|
|
260
|
+
return { metadata: options.metadata };
|
|
261
|
+
}
|
|
174
262
|
var Usage = {
|
|
175
263
|
empty() {
|
|
176
264
|
return {
|
|
@@ -236,6 +324,7 @@ function requestHasFileDocumentInput(request) {
|
|
|
236
324
|
}
|
|
237
325
|
|
|
238
326
|
export {
|
|
327
|
+
isJsonValue,
|
|
239
328
|
UserContent,
|
|
240
329
|
ToolContent,
|
|
241
330
|
serializeToolResultOutput,
|
|
@@ -248,4 +337,4 @@ export {
|
|
|
248
337
|
assertCompletionRequestSupported,
|
|
249
338
|
textFromAssistantContent
|
|
250
339
|
};
|
|
251
|
-
//# sourceMappingURL=chunk-
|
|
340
|
+
//# sourceMappingURL=chunk-CNTGKNZ3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/completion/json.ts","../src/completion/types.ts"],"sourcesContent":["import type { JsonValue } from \"./types\";\n\nexport function isJsonValue(value: unknown): value is JsonValue {\n return isJsonValueWithAncestors(value, new WeakSet<object>());\n}\n\nfunction isJsonValueWithAncestors(value: unknown, ancestors: WeakSet<object>): value is JsonValue {\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") {\n return true;\n }\n if (typeof value === \"number\") {\n return Number.isFinite(value);\n }\n if (typeof value !== \"object\" || ancestors.has(value)) {\n return false;\n }\n\n ancestors.add(value);\n try {\n if (Array.isArray(value)) {\n if (!hasOnlyDenseArrayProperties(value)) {\n return false;\n }\n for (let index = 0; index < value.length; index += 1) {\n if (!isJsonValueWithAncestors(value[index], ancestors)) {\n return false;\n }\n }\n return true;\n }\n\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n return false;\n }\n for (const key of Reflect.ownKeys(value)) {\n if (typeof key !== \"string\") {\n return false;\n }\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n if (\n descriptor === undefined ||\n !descriptor.enumerable ||\n !(\"value\" in descriptor) ||\n !isJsonValueWithAncestors(descriptor.value, ancestors)\n ) {\n return false;\n }\n }\n return true;\n } catch {\n return false;\n } finally {\n ancestors.delete(value);\n }\n}\n\nfunction hasOnlyDenseArrayProperties(value: unknown[]): boolean {\n const keys = Reflect.ownKeys(value);\n if (keys.length !== value.length + 1 || keys.at(-1) !== \"length\") {\n return false;\n }\n for (let index = 0; index < value.length; index += 1) {\n const key = String(index);\n if (keys[index] !== key) {\n return false;\n }\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n if (descriptor === undefined || !descriptor.enumerable || !(\"value\" in descriptor)) {\n return false;\n }\n }\n return true;\n}\n","import { isJsonValue } from \"./json\";\n\nexport type JsonPrimitive = string | number | boolean | null;\nexport type JsonValue = JsonPrimitive | JsonObject | JsonValue[];\nexport type JsonObject = { [key: string]: JsonValue | undefined };\n\nexport type Document = {\n id: string;\n text: string;\n additionalProps?: Record<string, string>;\n};\n\nexport type Text = {\n type: \"text\";\n text: string;\n signature?: string;\n};\n\nexport type ImageDetail = \"auto\" | \"low\" | \"high\";\n\nexport type ImageContent = {\n type: \"image\";\n source:\n | {\n type: \"url\";\n url: string;\n }\n | {\n type: \"base64\";\n data: string;\n mediaType: string;\n };\n detail?: ImageDetail;\n};\n\nexport type DocumentContent = {\n type: \"document\";\n source:\n | {\n type: \"url\";\n url: string;\n mediaType: string;\n filename?: string;\n }\n | {\n type: \"base64\";\n data: string;\n mediaType: string;\n filename?: string;\n }\n | {\n type: \"text\";\n text: string;\n mediaType?: string;\n filename?: string;\n };\n};\n\nexport type Reasoning = {\n type: \"reasoning\";\n text: string;\n id?: string;\n content?: ReasoningContent[];\n};\n\nexport type ReasoningContent =\n | {\n type: \"text\";\n text: string;\n signature?: string;\n }\n | {\n type: \"summary\";\n text: string;\n }\n | {\n type: \"encrypted\";\n data: string;\n }\n | {\n type: \"redacted\";\n data: string;\n };\n\nexport type ReasoningContentType = ReasoningContent[\"type\"];\n\nexport type ToolFunction = {\n name: string;\n arguments: JsonValue;\n};\n\nexport type ToolCall = {\n type: \"tool_call\";\n id: string;\n callId?: string;\n function: ToolFunction;\n signature?: string;\n additionalParams?: JsonValue;\n};\n\nexport type ToolResultContent =\n | { type: \"text\"; text: string }\n | { type: \"image\"; data: string; mediaType?: string };\n\nexport type ToolResult = {\n type: \"tool_result\";\n id: string;\n callId?: string;\n toolName?: string;\n content: ToolResultContent[];\n};\n\nexport type MessageOptions = {\n metadata?: JsonValue | undefined;\n};\n\nexport type AssistantMessageOptions = MessageOptions & {\n id?: string | undefined;\n};\n\nexport type ToolResultOptions = {\n callId?: string | undefined;\n toolName?: string | undefined;\n};\n\nexport type ToolResultMessageOptions = ToolResultOptions & MessageOptions;\n\nexport type UserContent = Text | ImageContent | DocumentContent;\nexport type AssistantContent = Text | ToolCall | Reasoning | ImageContent;\nexport type ToolContent = ToolResult;\n\nexport type SystemMessage = {\n role: \"system\";\n content: string;\n metadata?: JsonValue;\n};\n\nexport type UserMessage = {\n role: \"user\";\n content: UserContent[];\n metadata?: JsonValue;\n};\n\nexport type AssistantMessage = {\n role: \"assistant\";\n id?: string;\n content: AssistantContent[];\n metadata?: JsonValue;\n};\n\nexport type ToolMessage = {\n role: \"tool\";\n content: ToolContent[];\n metadata?: JsonValue;\n};\n\nexport type Message = SystemMessage | UserMessage | AssistantMessage | ToolMessage;\n\nexport const UserContent = {\n text(text: string): Text {\n return { type: \"text\", text };\n },\n imageUrl(url: string, options: { detail?: ImageDetail } = {}): ImageContent {\n const image: ImageContent = { type: \"image\", source: { type: \"url\", url } };\n if (options.detail !== undefined) {\n image.detail = options.detail;\n }\n return image;\n },\n imageBase64(\n data: string,\n mediaType: string,\n options: { detail?: ImageDetail } = {},\n ): ImageContent {\n const image: ImageContent = {\n type: \"image\",\n source: { type: \"base64\", data, mediaType },\n };\n if (options.detail !== undefined) {\n image.detail = options.detail;\n }\n return image;\n },\n documentUrl(\n url: string,\n mediaType: string,\n options: { filename?: string | undefined } = {},\n ): DocumentContent {\n return {\n type: \"document\",\n source:\n options.filename === undefined\n ? { type: \"url\", url, mediaType }\n : { type: \"url\", url, mediaType, filename: options.filename },\n };\n },\n documentBase64(\n data: string,\n mediaType: string,\n options: { filename?: string | undefined } = {},\n ): DocumentContent {\n return {\n type: \"document\",\n source:\n options.filename === undefined\n ? { type: \"base64\", data, mediaType }\n : { type: \"base64\", data, mediaType, filename: options.filename },\n };\n },\n documentText(text: string): Text {\n return { type: \"text\", text };\n },\n};\n\nexport const ToolContent = {\n toolResult(\n id: string,\n content: string | ToolResultContent[],\n callIdOrOptions?: string | ToolResultOptions,\n toolName?: string,\n ): ToolResult {\n const normalized =\n typeof content === \"string\" ? [{ type: \"text\" as const, text: content }] : content;\n const options = normalizeToolResultOptions(callIdOrOptions, toolName);\n const result: ToolResult = { type: \"tool_result\", id, content: normalized };\n if (options.callId !== undefined) {\n result.callId = options.callId;\n }\n if (options.toolName !== undefined) {\n result.toolName = options.toolName;\n }\n return result;\n },\n};\n\nfunction normalizeToolResultOptions(\n callIdOrOptions?: string | ToolResultOptions,\n toolName?: string,\n): ToolResultOptions {\n if (callIdOrOptions === undefined) {\n return toolName === undefined ? {} : { toolName };\n }\n if (typeof callIdOrOptions === \"string\") {\n return toolName === undefined\n ? { callId: callIdOrOptions }\n : { callId: callIdOrOptions, toolName };\n }\n return toolName === undefined ? callIdOrOptions : { ...callIdOrOptions, toolName };\n}\n\nexport function serializeToolResultOutput(output: unknown): string {\n if (typeof output === \"string\") {\n return output;\n }\n\n try {\n const serialized = JSON.stringify(output);\n return serialized === undefined ? String(output) : serialized;\n } catch {\n return String(output);\n }\n}\n\nexport function isToolResultContentArray(value: unknown): value is ToolResultContent[] {\n return (\n Array.isArray(value) &&\n value.length > 0 &&\n value.every((item) => {\n if (typeof item !== \"object\" || item === null || !(\"type\" in item)) {\n return false;\n }\n if (item.type === \"text\") {\n return \"text\" in item && typeof item.text === \"string\";\n }\n if (item.type === \"image\") {\n return (\n \"data\" in item &&\n typeof item.data === \"string\" &&\n (!(\"mediaType\" in item) ||\n item.mediaType === undefined ||\n typeof item.mediaType === \"string\")\n );\n }\n return false;\n })\n );\n}\n\nexport const AssistantContent = {\n text(text: string): Text {\n return { type: \"text\", text };\n },\n imageUrl(url: string, options: { detail?: ImageDetail } = {}): ImageContent {\n const image: ImageContent = { type: \"image\", source: { type: \"url\", url } };\n if (options.detail !== undefined) {\n image.detail = options.detail;\n }\n return image;\n },\n imageBase64(\n data: string,\n mediaType: string,\n options: { detail?: ImageDetail } = {},\n ): ImageContent {\n const image: ImageContent = {\n type: \"image\",\n source: { type: \"base64\", data, mediaType },\n };\n if (options.detail !== undefined) {\n image.detail = options.detail;\n }\n return image;\n },\n reasoning(text: string, id?: string): Reasoning {\n return id === undefined ? { type: \"reasoning\", text } : { type: \"reasoning\", text, id };\n },\n reasoningFromContent(content: ReasoningContent[], id?: string): Reasoning {\n const text = reasoningDisplayText(content);\n const reasoning: Reasoning = { type: \"reasoning\", text, content };\n return id === undefined ? reasoning : { ...reasoning, id };\n },\n reasoningSummary(text: string, id?: string): Reasoning {\n return AssistantContent.reasoningFromContent([{ type: \"summary\", text }], id);\n },\n reasoningEncrypted(data: string, id?: string): Reasoning {\n return AssistantContent.reasoningFromContent([{ type: \"encrypted\", data }], id);\n },\n reasoningRedacted(data: string, id?: string): Reasoning {\n return AssistantContent.reasoningFromContent([{ type: \"redacted\", data }], id);\n },\n toolCall(id: string, name: string, args: JsonValue, callId?: string): ToolCall {\n const base: ToolCall = {\n type: \"tool_call\",\n id,\n function: {\n name,\n arguments: args,\n },\n };\n return callId === undefined ? base : { ...base, callId };\n },\n};\n\nexport function reasoningDisplayText(reasoning: Reasoning | ReasoningContent[]): string {\n const content = Array.isArray(reasoning) ? reasoning : reasoning.content;\n if (content === undefined) {\n return Array.isArray(reasoning) ? \"\" : reasoning.text;\n }\n return content\n .flatMap((item) => {\n if (item.type === \"text\" || item.type === \"summary\") {\n return [item.text];\n }\n return [];\n })\n .join(\"\");\n}\n\nexport const Message = {\n system(content: string, options: MessageOptions = {}): Message {\n return { role: \"system\", content, ...messageMetadata(options) };\n },\n user(content: string | UserContent[], options: MessageOptions = {}): Message {\n return {\n role: \"user\",\n content: typeof content === \"string\" ? [UserContent.text(content)] : content,\n ...messageMetadata(options),\n };\n },\n assistant(\n content: string | AssistantContent[],\n idOrOptions?: string | AssistantMessageOptions,\n ): Message {\n const normalized = typeof content === \"string\" ? [AssistantContent.text(content)] : content;\n const options = typeof idOrOptions === \"string\" ? { id: idOrOptions } : (idOrOptions ?? {});\n const metadata = messageMetadata(options).metadata;\n const message: AssistantMessage =\n options.id === undefined\n ? { role: \"assistant\", content: normalized }\n : { role: \"assistant\", id: options.id, content: normalized };\n if (metadata !== undefined) {\n message.metadata = metadata;\n }\n return message;\n },\n tool(content: ToolContent | ToolContent[], options: MessageOptions = {}): Message {\n return {\n role: \"tool\",\n content: Array.isArray(content) ? content : [content],\n ...messageMetadata(options),\n };\n },\n toolResult(id: string, output: unknown, options: ToolResultMessageOptions = {}): Message {\n const content = isToolResultContentArray(output) ? output : serializeToolResultOutput(output);\n return Message.tool(\n ToolContent.toolResult(id, content, {\n callId: options.callId,\n toolName: options.toolName,\n }),\n { metadata: options.metadata },\n );\n },\n};\n\nfunction messageMetadata(options: MessageOptions): { metadata?: JsonValue } {\n if (options.metadata === undefined) {\n return {};\n }\n if (!isJsonValue(options.metadata)) {\n throw new TypeError(\"Message metadata must be a strict JSON value.\");\n }\n return { metadata: options.metadata };\n}\n\nexport type ToolChoice =\n | \"auto\"\n | \"required\"\n | \"none\"\n | {\n type: \"function\";\n name: string;\n };\n\nexport type ToolDefinition = {\n name: string;\n description: string;\n parameters: JsonObject;\n};\n\nexport type Usage = {\n inputTokens: number;\n outputTokens: number;\n totalTokens: number;\n cachedInputTokens: number;\n cacheCreationInputTokens: number;\n};\n\nexport const Usage = {\n empty(): Usage {\n return {\n inputTokens: 0,\n outputTokens: 0,\n totalTokens: 0,\n cachedInputTokens: 0,\n cacheCreationInputTokens: 0,\n };\n },\n add(left: Usage, right: Usage): Usage {\n return {\n inputTokens: left.inputTokens + right.inputTokens,\n outputTokens: left.outputTokens + right.outputTokens,\n totalTokens: left.totalTokens + right.totalTokens,\n cachedInputTokens: left.cachedInputTokens + right.cachedInputTokens,\n cacheCreationInputTokens: left.cacheCreationInputTokens + right.cacheCreationInputTokens,\n };\n },\n};\n\nexport type CompletionRequest<ModelName extends string = string> = {\n model?: ModelName;\n instructions?: string;\n chatHistory: Message[];\n documents: Document[];\n tools: ToolDefinition[];\n temperature?: number;\n maxTokens?: number;\n toolChoice?: ToolChoice;\n additionalParams?: JsonValue;\n outputSchema?: JsonObject;\n};\n\nexport type CompletionResponse<RawResponse = unknown> = {\n choice: AssistantContent[];\n usage: Usage;\n rawResponse: RawResponse;\n messageId?: string;\n};\n\nexport type CompletionModelCapabilities = {\n streaming: boolean;\n tools: boolean;\n toolChoice: boolean;\n imageInput: boolean;\n documentInput: boolean;\n outputSchema: boolean;\n reasoning: boolean;\n};\n\nexport interface CompletionModel<RawResponse = unknown, ModelName extends string = string> {\n readonly provider: string;\n readonly defaultModel: ModelName;\n readonly capabilities: CompletionModelCapabilities;\n traceRequest?(\n request: CompletionRequest<ModelName>,\n options?: { stream?: boolean | undefined },\n ): JsonObject | undefined;\n completion(request: CompletionRequest<ModelName>): Promise<CompletionResponse<RawResponse>>;\n}\n\nexport type CompletionStreamEvent<RawResponse = unknown> =\n | {\n type: \"text_delta\";\n delta: string;\n }\n | {\n type: \"reasoning_delta\";\n delta: string;\n id?: string;\n contentType?: ReasoningContentType;\n signature?: string;\n }\n | {\n type: \"tool_call_delta\";\n id: string;\n callId?: string;\n name?: string;\n argumentsDelta?: string;\n signature?: string;\n }\n | {\n type: \"tool_call\";\n toolCall: ToolCall;\n }\n | {\n type: \"message_id\";\n id: string;\n }\n | {\n type: \"final\";\n response: CompletionResponse<RawResponse>;\n }\n | {\n type: \"error\";\n error: unknown;\n };\n\nexport interface StreamingCompletionModel<RawResponse = unknown, ModelName extends string = string>\n extends CompletionModel<RawResponse, ModelName> {\n streamCompletion(\n request: CompletionRequest<ModelName>,\n ): AsyncIterable<CompletionStreamEvent<RawResponse>>;\n}\n\nexport class CompletionCapabilityError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"CompletionCapabilityError\";\n }\n}\n\nexport function assertCompletionRequestSupported(\n model: CompletionModel,\n request: CompletionRequest,\n options: { streaming?: boolean | undefined } = {},\n): void {\n const modelLabel = `${model.provider}:${request.model ?? model.defaultModel}`;\n const capabilities = model.capabilities;\n\n if (options.streaming === true && !capabilities.streaming) {\n throw new CompletionCapabilityError(`${modelLabel} does not support streaming completions.`);\n }\n\n if (request.tools.length > 0 && !capabilities.tools) {\n throw new CompletionCapabilityError(`${modelLabel} does not support tool definitions.`);\n }\n\n if (request.toolChoice !== undefined && !capabilities.toolChoice) {\n throw new CompletionCapabilityError(`${modelLabel} does not support tool choice.`);\n }\n\n if (request.outputSchema !== undefined && !capabilities.outputSchema) {\n throw new CompletionCapabilityError(`${modelLabel} does not support output schemas.`);\n }\n\n if (!capabilities.imageInput && requestHasImageInput(request)) {\n throw new CompletionCapabilityError(`${modelLabel} does not support image input.`);\n }\n\n if (!capabilities.documentInput && requestHasFileDocumentInput(request)) {\n throw new CompletionCapabilityError(`${modelLabel} does not support document file input.`);\n }\n}\n\nexport function textFromAssistantContent(content: AssistantContent[]): string {\n return content.flatMap((item) => (item.type === \"text\" ? [item.text] : [])).join(\"\\n\");\n}\n\nfunction requestHasImageInput(request: CompletionRequest): boolean {\n return request.chatHistory.some((message) =>\n message.role === \"system\" ? false : message.content.some((content) => content.type === \"image\"),\n );\n}\n\nfunction requestHasFileDocumentInput(request: CompletionRequest): boolean {\n return request.chatHistory.some((message) =>\n message.role === \"user\"\n ? message.content.some(\n (content) => content.type === \"document\" && content.source.type !== \"text\",\n )\n : false,\n );\n}\n"],"mappings":";AAEO,SAAS,YAAY,OAAoC;AAC9D,SAAO,yBAAyB,OAAO,oBAAI,QAAgB,CAAC;AAC9D;AAEA,SAAS,yBAAyB,OAAgB,WAAgD;AAChG,MAAI,UAAU,QAAQ,OAA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AAK,IAAI;AACvF;AAEA,SAAS,qBAAqB,SAAqC;AACjE,SAAO,QAAQ,YAAY;AAAA,IAAK,CAAC,YAC/B,QAAQ,SAAS,WAAW,QAAQ,QAAQ,QAAQ,KAAK,CAAC,YAAY,QAAQ,SAAS,OAAO;AAAA,EAChG;AACF;AAEA,SAAS,4BAA4B,SAAqC;AACxE,SAAO,QAAQ,YAAY;AAAA,IAAK,CAAC,YAC/B,QAAQ,SAAS,SACb,QAAQ,QAAQ;AAAA,MACd,CAAC,YAAY,QAAQ,SAAS,cAAc,QAAQ,OAAO,SAAS;AAAA,IACtE,IACA;AAAA,EACN;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/record.ts"],"sourcesContent":["export function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":";AAAO,SAAS,SAAS,OAAkD;AACzE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isRecord
|
|
3
|
+
} from "./chunk-CQNNSZPG.js";
|
|
1
4
|
import {
|
|
2
5
|
markSkillTool
|
|
3
6
|
} from "./chunk-YK4WAAS4.js";
|
|
4
7
|
import {
|
|
5
8
|
createTool
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import {
|
|
8
|
-
isRecord
|
|
9
|
-
} from "./chunk-MMHG7WAM.js";
|
|
9
|
+
} from "./chunk-I7TM7TKX.js";
|
|
10
10
|
|
|
11
11
|
// src/skills/instructions.ts
|
|
12
12
|
function skillInstructions(skills) {
|
|
@@ -395,4 +395,4 @@ export {
|
|
|
395
395
|
SkillValidationError,
|
|
396
396
|
skill
|
|
397
397
|
};
|
|
398
|
-
//# sourceMappingURL=chunk-
|
|
398
|
+
//# sourceMappingURL=chunk-DC2GJDPR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/skills/instructions.ts","../src/skills/tools.ts","../src/skills/load.ts","../src/skills/local.ts","../src/skills/types.ts"],"sourcesContent":["import type { Skill } from \"./types\";\n\nexport function skillInstructions(skills: Skill[]): string {\n if (skills.length === 0) {\n return \"\";\n }\n\n return [\n \"You have access to Agent Skills.\",\n \"Skills are compact capability packages. Use the skill tools to load full instructions, references, or scripts only when a skill is relevant.\",\n \"\",\n \"Available skills:\",\n ...skills.map(formatSkill),\n \"\",\n \"Skill tools:\",\n \"- get_skill_instructions: load full SKILL.md guidance for a skill.\",\n \"- get_skill_reference: read a reference file from a skill.\",\n \"- get_skill_script: read a script file from a skill.\",\n \"- run_skill_script: execute a script from a skill with arguments.\",\n ].join(\"\\n\");\n}\n\nfunction formatSkill(skill: Skill): string {\n const lines = [`- ${skill.name}: ${skill.description}`];\n if (skill.references.length > 0) {\n lines.push(` references: ${skill.references.join(\", \")}`);\n }\n if (skill.scripts.length > 0) {\n lines.push(` scripts: ${skill.scripts.join(\", \")}`);\n }\n return lines.join(\"\\n\");\n}\n","import { spawn } from \"node:child_process\";\nimport { readFile } from \"node:fs/promises\";\nimport { isAbsolute, relative, resolve } from \"node:path\";\nimport { z } from \"zod\";\nimport { type AnyTool, createTool } from \"../tool\";\nimport { markSkillTool } from \"../tool/skill-tool-marker\";\nimport type { Skill } from \"./types\";\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\nconst MAX_OUTPUT_CHARS = 20_000;\n\nexport function createSkillTools(skills: Skill[]): AnyTool[] {\n const registry = new SkillRegistry(skills);\n\n return [\n markSkillTool(\n createTool({\n name: \"get_skill_instructions\",\n description: \"Load the full SKILL.md instructions for an Agent Skill.\",\n input: z.object({\n skillName: z.string().describe(\"The name of the skill to load.\"),\n }),\n output: z.string(),\n execute: ({ skillName }) => registry.get(skillName).instructions,\n }),\n ),\n markSkillTool(\n createTool({\n name: \"get_skill_reference\",\n description: \"Read a reference file from an Agent Skill.\",\n input: z.object({\n skillName: z.string().describe(\"The name of the skill.\"),\n referencePath: z.string().describe(\"A path listed in the skill references.\"),\n }),\n output: z.string(),\n execute: ({ skillName, referencePath }) => registry.readReference(skillName, referencePath),\n }),\n ),\n markSkillTool(\n createTool({\n name: \"get_skill_script\",\n description: \"Read a script file from an Agent Skill.\",\n input: z.object({\n skillName: z.string().describe(\"The name of the skill.\"),\n scriptPath: z.string().describe(\"A path listed in the skill scripts.\"),\n }),\n output: z.string(),\n execute: ({ skillName, scriptPath }) => registry.readScript(skillName, scriptPath),\n }),\n ),\n markSkillTool(\n createTool({\n name: \"run_skill_script\",\n description: \"Execute a script from an Agent Skill with optional arguments.\",\n input: z.object({\n skillName: z.string().describe(\"The name of the skill.\"),\n scriptPath: z.string().describe(\"A path listed in the skill scripts.\"),\n args: z.array(z.string()).optional().describe(\"Arguments passed to the script.\"),\n timeoutMs: z.number().int().positive().optional().describe(\"Execution timeout in ms.\"),\n }),\n output: z.string(),\n execute: ({ skillName, scriptPath, args = [], timeoutMs = DEFAULT_TIMEOUT_MS }) =>\n registry.runScript(skillName, scriptPath, args, timeoutMs),\n }),\n ),\n ];\n}\n\nclass SkillRegistry {\n private readonly skills = new Map<string, Skill>();\n\n constructor(skills: Skill[]) {\n for (const skill of skills) {\n this.skills.set(skill.name, skill);\n }\n }\n\n get(skillName: string): Skill {\n const skill = this.skills.get(skillName);\n if (skill === undefined) {\n throw new Error(`Skill not found: ${skillName}`);\n }\n return skill;\n }\n\n async readReference(skillName: string, referencePath: string): Promise<string> {\n const skill = this.get(skillName);\n const path = this.resolveContainedPath(skill, \"references\", referencePath);\n if (!skill.references.includes(referencePath)) {\n throw new Error(`Skill reference not found: ${skillName}/${referencePath}`);\n }\n return readFile(path, \"utf8\");\n }\n\n async readScript(skillName: string, scriptPath: string): Promise<string> {\n const skill = this.get(skillName);\n const path = this.resolveContainedPath(skill, \"scripts\", scriptPath);\n if (!skill.scripts.includes(scriptPath)) {\n throw new Error(`Skill script not found: ${skillName}/${scriptPath}`);\n }\n return readFile(path, \"utf8\");\n }\n\n async runScript(\n skillName: string,\n scriptPath: string,\n args: string[],\n timeoutMs: number,\n ): Promise<string> {\n const skill = this.get(skillName);\n const script = this.resolveContainedPath(skill, \"scripts\", scriptPath);\n if (!skill.scripts.includes(scriptPath)) {\n throw new Error(`Skill script not found: ${skillName}/${scriptPath}`);\n }\n return runExecutable(script, args, skill.directory, timeoutMs);\n }\n\n private resolveContainedPath(\n skill: Skill,\n section: \"references\" | \"scripts\",\n requestedPath: string,\n ): string {\n if (requestedPath.length === 0 || isAbsolute(requestedPath)) {\n throw new Error(`Invalid skill path: ${requestedPath}`);\n }\n\n const root = resolve(skill.directory, section);\n const resolved = resolve(root, requestedPath);\n const rel = relative(root, resolved);\n if (rel === \"..\" || rel.startsWith(`..${\"/\"}`) || rel.startsWith(`..${\"\\\\\"}`)) {\n throw new Error(`Invalid skill path: ${requestedPath}`);\n }\n\n return resolved;\n }\n}\n\nfunction runExecutable(\n command: string,\n args: string[],\n cwd: string,\n timeoutMs: number,\n): Promise<string> {\n return new Promise((resolvePromise, reject) => {\n const child = spawn(command, args, {\n cwd,\n shell: false,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n\n let stdout = \"\";\n let stderr = \"\";\n let timedOut = false;\n const timeout = setTimeout(() => {\n timedOut = true;\n child.kill();\n }, timeoutMs);\n\n child.stdout.setEncoding(\"utf8\");\n child.stderr.setEncoding(\"utf8\");\n child.stdout.on(\"data\", (chunk) => {\n stdout = appendLimited(stdout, chunk);\n });\n child.stderr.on(\"data\", (chunk) => {\n stderr = appendLimited(stderr, chunk);\n });\n child.on(\"error\", (error) => {\n clearTimeout(timeout);\n reject(error);\n });\n child.on(\"close\", (code, signal) => {\n clearTimeout(timeout);\n if (timedOut) {\n reject(new Error(`Skill script timed out after ${timeoutMs}ms`));\n return;\n }\n\n const output = formatProcessOutput(stdout, stderr);\n if (code !== 0) {\n reject(new Error(`Skill script exited with code ${code ?? \"unknown\"}: ${output}`));\n return;\n }\n if (signal !== null) {\n reject(new Error(`Skill script exited with signal ${signal}: ${output}`));\n return;\n }\n\n resolvePromise(output);\n });\n });\n}\n\nfunction formatProcessOutput(stdout: string, stderr: string): string {\n const parts: string[] = [];\n if (stdout.length > 0) {\n parts.push(`stdout:\\n${stdout}`);\n }\n if (stderr.length > 0) {\n parts.push(`stderr:\\n${stderr}`);\n }\n return parts.length === 0 ? \"\" : parts.join(\"\\n\\n\");\n}\n\nfunction appendLimited(current: string, chunk: string): string {\n const next = current + chunk;\n if (next.length <= MAX_OUTPUT_CHARS) {\n return next;\n }\n return `${next.slice(0, MAX_OUTPUT_CHARS)}\\n[truncated]`;\n}\n","import { skillInstructions } from \"./instructions\";\nimport { createSkillTools } from \"./tools\";\nimport type { Skill, SkillLoader, SkillSet } from \"./types\";\n\nexport async function loadSkills(loaders: SkillLoader | SkillLoader[]): Promise<SkillSet> {\n const ordered = Array.isArray(loaders) ? loaders : [loaders];\n const byName = new Map<string, Skill>();\n\n for (const loader of ordered) {\n for (const loaded of await loader.load()) {\n byName.delete(loaded.name);\n byName.set(loaded.name, loaded);\n }\n }\n\n const skills = [...byName.values()];\n return {\n skills,\n instructions: skillInstructions(skills),\n tools: skills.length === 0 ? [] : createSkillTools(skills),\n };\n}\n","import { readdir, readFile, stat } from \"node:fs/promises\";\nimport { basename, join, relative, resolve, sep } from \"node:path\";\nimport { parse as parseYaml } from \"yaml\";\nimport { isRecord } from \"../internal/record\";\nimport type { Skill, SkillLoader, SkillValidationIssue } from \"./types\";\nimport { SkillValidationError } from \"./types\";\n\ntype SkillFrontmatter = {\n name?: unknown;\n description?: unknown;\n license?: unknown;\n metadata?: unknown;\n};\n\nconst NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\nconst MAX_NAME_LENGTH = 64;\nconst MAX_DESCRIPTION_LENGTH = 1024;\n\nexport const skill = {\n local(path: string): SkillLoader {\n return {\n load: () => loadLocalSkills(path),\n };\n },\n};\n\nasync function loadLocalSkills(path: string): Promise<Skill[]> {\n const root = resolve(path);\n if (await hasSkillFile(root)) {\n return [await readSkill(root)];\n }\n\n const entries = await readdir(root, { withFileTypes: true });\n const skills: Skill[] = [];\n for (const entry of entries) {\n if (!entry.isDirectory()) {\n continue;\n }\n const directory = join(root, entry.name);\n if (await hasSkillFile(directory)) {\n skills.push(await readSkill(directory));\n }\n }\n return skills;\n}\n\nasync function hasSkillFile(directory: string): Promise<boolean> {\n try {\n const info = await stat(join(directory, \"SKILL.md\"));\n return info.isFile();\n } catch {\n return false;\n }\n}\n\nasync function readSkill(directory: string): Promise<Skill> {\n const skillPath = join(directory, \"SKILL.md\");\n const markdown = await readFile(skillPath, \"utf8\");\n const parsed = parseSkillMarkdown(markdown, skillPath);\n validateSkillFrontmatter(parsed.frontmatter, directory, skillPath);\n\n const name = parsed.frontmatter.name as string;\n const description = parsed.frontmatter.description as string;\n const license =\n typeof parsed.frontmatter.license === \"string\" ? parsed.frontmatter.license : undefined;\n const metadata = isRecord(parsed.frontmatter.metadata) ? parsed.frontmatter.metadata : undefined;\n\n return {\n name,\n description,\n instructions: parsed.body.trim(),\n directory,\n references: await listRelativeFiles(join(directory, \"references\")),\n scripts: await listRelativeFiles(join(directory, \"scripts\")),\n license,\n metadata,\n };\n}\n\nfunction parseSkillMarkdown(\n markdown: string,\n path: string,\n): { frontmatter: SkillFrontmatter; body: string } {\n if (!markdown.startsWith(\"---\\n\") && !markdown.startsWith(\"---\\r\\n\")) {\n throw new SkillValidationError(\"Skill validation failed\", [\n { path, message: \"SKILL.md must start with YAML frontmatter\" },\n ]);\n }\n\n const newline = markdown.startsWith(\"---\\r\\n\") ? \"\\r\\n\" : \"\\n\";\n const marker = `${newline}---${newline}`;\n const end = markdown.indexOf(marker, 3);\n if (end === -1) {\n throw new SkillValidationError(\"Skill validation failed\", [\n { path, message: \"SKILL.md frontmatter must end with ---\" },\n ]);\n }\n\n const rawFrontmatter = markdown.slice(3 + newline.length, end);\n const body = markdown.slice(end + marker.length);\n const parsed = parseYaml(rawFrontmatter);\n if (!isRecord(parsed)) {\n throw new SkillValidationError(\"Skill validation failed\", [\n { path, message: \"SKILL.md frontmatter must be a YAML object\" },\n ]);\n }\n\n return { frontmatter: parsed, body };\n}\n\nfunction validateSkillFrontmatter(\n frontmatter: SkillFrontmatter,\n directory: string,\n path: string,\n): void {\n const issues: SkillValidationIssue[] = [];\n const name = frontmatter.name;\n const description = frontmatter.description;\n\n if (typeof name !== \"string\" || name.length === 0) {\n issues.push({ path, message: \"name is required\" });\n } else {\n if (name.length > MAX_NAME_LENGTH) {\n issues.push({ path, message: `name must be at most ${MAX_NAME_LENGTH} characters` });\n }\n if (!NAME_PATTERN.test(name)) {\n issues.push({\n path,\n message: \"name must contain lowercase letters, numbers, and hyphens only\",\n });\n }\n if (basename(directory) !== name) {\n issues.push({ path, message: \"name must match the skill directory name\" });\n }\n }\n\n if (typeof description !== \"string\" || description.length === 0) {\n issues.push({ path, message: \"description is required\" });\n } else if (description.length > MAX_DESCRIPTION_LENGTH) {\n issues.push({\n path,\n message: `description must be at most ${MAX_DESCRIPTION_LENGTH} characters`,\n });\n }\n\n if (issues.length > 0) {\n throw new SkillValidationError(\"Skill validation failed\", issues);\n }\n}\n\nasync function listRelativeFiles(directory: string): Promise<string[]> {\n try {\n const info = await stat(directory);\n if (!info.isDirectory()) {\n return [];\n }\n } catch {\n return [];\n }\n\n const files: string[] = [];\n await collectFiles(directory, directory, files);\n return files.sort();\n}\n\nasync function collectFiles(root: string, directory: string, files: string[]): Promise<void> {\n const entries = await readdir(directory, { withFileTypes: true });\n for (const entry of entries) {\n const path = join(directory, entry.name);\n if (entry.isDirectory()) {\n await collectFiles(root, path, files);\n } else if (entry.isFile()) {\n files.push(toPortablePath(relative(root, path)));\n }\n }\n}\n\nfunction toPortablePath(path: string): string {\n return sep === \"/\" ? path : path.split(sep).join(\"/\");\n}\n","import type { AnyTool } from \"../tool\";\n\nexport type Skill = {\n readonly name: string;\n readonly description: string;\n readonly instructions: string;\n readonly directory: string;\n readonly references: string[];\n readonly scripts: string[];\n readonly license?: string | undefined;\n readonly metadata?: Record<string, unknown> | undefined;\n};\n\nexport type SkillLoader = {\n load(): Promise<Skill[]>;\n};\n\nexport type SkillSet = {\n readonly skills: Skill[];\n readonly tools: AnyTool[];\n readonly instructions: string;\n};\n\nexport type SkillValidationIssue = {\n path: string;\n message: string;\n};\n\nexport class SkillValidationError extends Error {\n readonly issues: SkillValidationIssue[];\n\n constructor(message: string, issues: SkillValidationIssue[]) {\n super(message);\n this.name = \"SkillValidationError\";\n this.issues = issues;\n }\n}\n"],"mappings":";;;;;;;;;;;AAEO,SAAS,kBAAkB,QAAyB;AACzD,MAAI,OAAO,WAAW,GAAG;AACvB,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG,OAAO,IAAI,WAAW;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAAE,KAAK,IAAI;AACb;AAEA,SAAS,YAAYA,QAAsB;AACzC,QAAM,QAAQ,CAAC,KAAKA,OAAM,IAAI,KAAKA,OAAM,WAAW,EAAE;AACtD,MAAIA,OAAM,WAAW,SAAS,GAAG;AAC/B,UAAM,KAAK,iBAAiBA,OAAM,WAAW,KAAK,IAAI,CAAC,EAAE;AAAA,EAC3D;AACA,MAAIA,OAAM,QAAQ,SAAS,GAAG;AAC5B,UAAM,KAAK,cAAcA,OAAM,QAAQ,KAAK,IAAI,CAAC,EAAE;AAAA,EACrD;AACA,SAAO,MAAM,KAAK,IAAI;AACxB;;;AC/BA,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,SAAS,YAAY,UAAU,eAAe;AAC9C,SAAS,SAAS;AAKlB,IAAM,qBAAqB;AAC3B,IAAM,mBAAmB;AAElB,SAAS,iBAAiB,QAA4B;AAC3D,QAAM,WAAW,IAAI,cAAc,MAAM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,GAAG;AACrB,UAAM,IAAI,qBAAqB,2BAA2B,MAAM;AAAA,EAClE;AACF;AAEA,eAAe,kBAAkB,WAAsC;AACrE,MAAI;AACF,UAAM,OAAO,MAAM,KAAK,SAAS;AACjC,QAAI,CAAC,KAAK,YAAY,GAAG;AACvB,aAAO,CAAC;AAAA,IACV;AAAA,EACF,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,QAAkB,CAAC;AACzB,QAAM,aAAa,WAAW,WAAW,KAAK;AAC9C,SAAO,MAAM,KAAK;AACpB;AAEA,eAAe,aAAa,MAAc,WAAmB,OAAgC;AAC3F,QAAM,UAAU,MAAM,QAAQ,WAAW,EAAE,eAAe,KAAK,CAAC;AAChE,aAAW,SAAS,SAAS;AAC3B,UAAM,OAAO,KAAK,WAAW,MAAM,IAAI;AACvC,QAAI,MAAM,YAAY,GAAG;AACvB,YAAM,aAAa,MAAM,MAAM,KAAK;AAAA,IACtC,WAAW,MAAM,OAAO,GAAG;AACzB,YAAM,KAAK,eAAeC,UAAS,MAAM,IAAI,CAAC,CAAC;AAAA,IACjD;AAAA,EACF;AACF;AAEA,SAAS,eAAe,MAAsB;AAC5C,SAAO,QAAQ,MAAM,OAAO,KAAK,MAAM,GAAG,EAAE,KAAK,GAAG;AACtD;","names":["skill","skill","readFile","relative","resolve","resolve","readFile","relative"]}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
toProviderJsonSchema
|
|
3
|
+
} from "./chunk-WQKHFADH.js";
|
|
4
4
|
import {
|
|
5
5
|
cosineSimilarity,
|
|
6
6
|
embedText
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import {
|
|
9
|
-
toProviderJsonSchema
|
|
10
|
-
} from "./chunk-WQKHFADH.js";
|
|
7
|
+
} from "./chunk-YBBD4HZ3.js";
|
|
11
8
|
|
|
12
9
|
// src/vector-store/index.ts
|
|
13
10
|
import { z } from "zod";
|
|
@@ -15,26 +12,26 @@ import { z } from "zod";
|
|
|
15
12
|
// src/tool/create-tool.ts
|
|
16
13
|
function createTool(options) {
|
|
17
14
|
const parameters = toProviderJsonSchema(options.input);
|
|
15
|
+
const definition = () => ({
|
|
16
|
+
name: options.name,
|
|
17
|
+
description: options.description,
|
|
18
|
+
parameters
|
|
19
|
+
});
|
|
20
|
+
const call = async (args, context = {}) => {
|
|
21
|
+
const parsedArgs = options.input.parse(args);
|
|
22
|
+
const result = await options.execute(parsedArgs, context);
|
|
23
|
+
return options.output === void 0 ? result : options.output.parse(result);
|
|
24
|
+
};
|
|
25
|
+
const parseApprovalArgs = (args) => options.input.parse(args);
|
|
26
|
+
if (options.approval === void 0) {
|
|
27
|
+
return { name: options.name, definition, call, parseApprovalArgs };
|
|
28
|
+
}
|
|
18
29
|
return {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
name: options.name,
|
|
26
|
-
description: options.description,
|
|
27
|
-
parameters
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
async call(args, context = {}) {
|
|
31
|
-
const parsedArgs = options.input.parse(args);
|
|
32
|
-
const result = await options.execute(parsedArgs, context);
|
|
33
|
-
return options.output === void 0 ? result : options.output.parse(result);
|
|
34
|
-
},
|
|
35
|
-
parseApprovalArgs(args) {
|
|
36
|
-
return options.input.parse(args);
|
|
37
|
-
}
|
|
30
|
+
name: options.name,
|
|
31
|
+
approval: options.approval,
|
|
32
|
+
definition,
|
|
33
|
+
call,
|
|
34
|
+
parseApprovalArgs
|
|
38
35
|
};
|
|
39
36
|
}
|
|
40
37
|
|
|
@@ -244,14 +241,15 @@ var InMemoryVectorIndex = class {
|
|
|
244
241
|
if (request.threshold !== void 0 && score < request.threshold) {
|
|
245
242
|
return [];
|
|
246
243
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
244
|
+
const result = {
|
|
245
|
+
score,
|
|
246
|
+
id: document.id,
|
|
247
|
+
document: document.document
|
|
248
|
+
};
|
|
249
|
+
if (document.metadata !== void 0) {
|
|
250
|
+
result.metadata = document.metadata;
|
|
251
|
+
}
|
|
252
|
+
return [result];
|
|
255
253
|
}).sort((left, right) => right.score - left.score).slice(0, Math.max(0, Math.trunc(request.topK)));
|
|
256
254
|
}
|
|
257
255
|
async searchIds(request) {
|
|
@@ -263,15 +261,23 @@ var InMemoryVectorIndex = class {
|
|
|
263
261
|
const documents = this.store.values().filter((document) => matchesVectorFilter(document.metadata, request.filter));
|
|
264
262
|
const page = documents.slice(start, start + limit);
|
|
265
263
|
const nextOffset = start + page.length;
|
|
266
|
-
|
|
267
|
-
items: page.map((document) =>
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
264
|
+
const result = {
|
|
265
|
+
items: page.map((document) => {
|
|
266
|
+
const item = {
|
|
267
|
+
id: document.id,
|
|
268
|
+
document: document.document
|
|
269
|
+
};
|
|
270
|
+
if (document.metadata !== void 0) {
|
|
271
|
+
item.metadata = document.metadata;
|
|
272
|
+
}
|
|
273
|
+
return item;
|
|
274
|
+
})
|
|
274
275
|
};
|
|
276
|
+
if (nextOffset < documents.length) {
|
|
277
|
+
result.nextCursor = String(nextOffset);
|
|
278
|
+
}
|
|
279
|
+
result.totalCount = documents.length;
|
|
280
|
+
return result;
|
|
275
281
|
}
|
|
276
282
|
asTool(options) {
|
|
277
283
|
return createVectorSearchTool(this, options);
|
|
@@ -328,4 +334,4 @@ export {
|
|
|
328
334
|
InMemoryVectorIndex,
|
|
329
335
|
createVectorSearchTool
|
|
330
336
|
};
|
|
331
|
-
//# sourceMappingURL=chunk-
|
|
337
|
+
//# sourceMappingURL=chunk-I7TM7TKX.js.map
|