@anvia/core 0.26.0 → 1.0.0-rc.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/README.md +21 -11
- package/dist/agent/index.d.ts +26 -68
- package/dist/agent/index.js +20 -17
- package/dist/agent-DGYY_onS.d.ts +145 -0
- package/dist/audio-generation/index.d.ts +12 -14
- package/dist/audio-generation/index.js +5 -39
- package/dist/audio-generation/index.js.map +1 -1
- package/dist/{chunk-MRQLEK2B.js → chunk-5XKDW36Z.js} +30 -7
- package/dist/chunk-5XKDW36Z.js.map +1 -0
- package/dist/chunk-6WGGTJE6.js +139 -0
- package/dist/chunk-6WGGTJE6.js.map +1 -0
- package/dist/chunk-A3UBYTJT.js +157 -0
- package/dist/chunk-A3UBYTJT.js.map +1 -0
- package/dist/{chunk-NCPN4SJR.js → chunk-DMPUP4R3.js} +10 -10
- package/dist/chunk-DMPUP4R3.js.map +1 -0
- package/dist/{chunk-MNWK2USR.js → chunk-DZ3CKYTH.js} +29 -5
- package/dist/chunk-DZ3CKYTH.js.map +1 -0
- package/dist/{chunk-CWUJUSOS.js → chunk-FNQB2JEH.js} +1 -1
- package/dist/chunk-FNQB2JEH.js.map +1 -0
- package/dist/chunk-I6G7BC42.js +41 -0
- package/dist/chunk-I6G7BC42.js.map +1 -0
- package/dist/{chunk-BALBBVI3.js → chunk-IL3ZSNJI.js} +2720 -1704
- package/dist/chunk-IL3ZSNJI.js.map +1 -0
- package/dist/chunk-J6GNQART.js +122 -0
- package/dist/chunk-J6GNQART.js.map +1 -0
- package/dist/{chunk-MC3CCKEB.js → chunk-M3IOWB4Y.js} +124 -65
- package/dist/chunk-M3IOWB4Y.js.map +1 -0
- package/dist/chunk-QY5GZ7HR.js +39 -0
- package/dist/chunk-QY5GZ7HR.js.map +1 -0
- package/dist/{chunk-MELYDKWQ.js → chunk-R2LJSQUW.js} +190 -20
- package/dist/chunk-R2LJSQUW.js.map +1 -0
- package/dist/{chunk-WQKHFADH.js → chunk-RFDVKCIE.js} +3 -3
- package/dist/chunk-RFDVKCIE.js.map +1 -0
- package/dist/chunk-RMUBRRSK.js +34 -0
- package/dist/chunk-RMUBRRSK.js.map +1 -0
- package/dist/{chunk-I6XOQ4LK.js → chunk-RXKHOYEH.js} +1 -1
- package/dist/chunk-RXKHOYEH.js.map +1 -0
- package/dist/chunk-XDRSPSR7.js +38 -0
- package/dist/chunk-XDRSPSR7.js.map +1 -0
- package/dist/completion/index.d.ts +5 -36
- package/dist/completion/index.js +4 -5
- package/dist/dynamic-tools-i9woysFa.d.ts +33 -0
- package/dist/embeddings/index.d.ts +2 -2
- package/dist/embeddings/index.js +1 -2
- package/dist/{errors-2moLDuuN.d.ts → errors-CYKUcU89.d.ts} +2 -2
- package/dist/evals/index.d.ts +22 -15
- package/dist/evals/index.js +57 -35
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +23 -35
- package/dist/extractor/index.js +7 -21
- package/dist/guardrails/index.d.ts +2 -2
- package/dist/guardrails/index.js +1 -1
- package/dist/image-generation/index.d.ts +12 -14
- package/dist/image-generation/index.js +5 -39
- package/dist/image-generation/index.js.map +1 -1
- package/dist/index-DxB74ybJ.d.ts +349 -0
- package/dist/index.d.ts +20 -17
- package/dist/index.js +31 -36
- package/dist/internal/agent.d.ts +152 -9
- package/dist/internal/agent.js +22 -17
- package/dist/{json-BVPssigK.d.ts → json-Zo7K3xmt.d.ts} +12 -11
- package/dist/loaders/index.d.ts +5 -10
- package/dist/loaders/index.js.map +1 -1
- package/dist/mcp/index.d.ts +4 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/memory/index.d.ts +4 -4
- package/dist/memory/index.js +6 -7
- package/dist/middleware-KynLg_RW.d.ts +56 -0
- package/dist/observability/index.d.ts +6 -3
- package/dist/observability/index.js.map +1 -1
- package/dist/pipeline/index.d.ts +40 -47
- package/dist/pipeline/index.js +99 -99
- package/dist/pipeline/index.js.map +1 -1
- package/dist/retry-D3Ruy-ba.d.ts +15 -0
- package/dist/skills/index.d.ts +4 -4
- package/dist/skills/index.js +5 -6
- package/dist/streaming/index.js +37 -3
- package/dist/streaming/index.js.map +1 -1
- package/dist/{think-tool-DfCMuO8e.d.ts → think-tool-DZqZj2LV.d.ts} +5 -5
- package/dist/tool/index.d.ts +8 -6
- package/dist/tool/index.js +12 -15
- package/dist/tool-C_8GudXn.d.ts +49 -0
- package/dist/transcription/index.d.ts +14 -16
- package/dist/transcription/index.js +5 -57
- package/dist/transcription/index.js.map +1 -1
- package/dist/type-utils-CtHVDRn_.d.ts +6 -0
- package/dist/{types-G12i56s2.d.ts → types-B3A4YxaA.d.ts} +1 -1
- package/dist/{types-BrLbKnEz.d.ts → types-BBEGKB9m.d.ts} +1 -1
- package/dist/{types-O-abTIin.d.ts → types-DT3nEemY.d.ts} +3 -3
- package/dist/{types-04LqWrmy.d.ts → types-DhQfwiZn.d.ts} +1 -1
- package/dist/{types-JJCxRnaZ.d.ts → types-DulRCYdB.d.ts} +2 -2
- package/dist/{types-BCTRUGex.d.ts → types-p55Jc-sr.d.ts} +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +1 -1
- package/dist/vector-store/index.d.ts +5 -5
- package/dist/vector-store/index.js +4 -4
- package/package.json +2 -10
- package/dist/agent-x3YTyv5i.d.ts +0 -222
- package/dist/chunk-2ODTMRHP.js +0 -54
- package/dist/chunk-2ODTMRHP.js.map +0 -1
- package/dist/chunk-BALBBVI3.js.map +0 -1
- package/dist/chunk-CWUJUSOS.js.map +0 -1
- package/dist/chunk-DALYP4PX.js +0 -225
- package/dist/chunk-DALYP4PX.js.map +0 -1
- package/dist/chunk-HYUYZEAJ.js +0 -223
- package/dist/chunk-HYUYZEAJ.js.map +0 -1
- package/dist/chunk-I6XOQ4LK.js.map +0 -1
- package/dist/chunk-JI5YZWNT.js +0 -220
- package/dist/chunk-JI5YZWNT.js.map +0 -1
- package/dist/chunk-MC3CCKEB.js.map +0 -1
- package/dist/chunk-MELYDKWQ.js.map +0 -1
- package/dist/chunk-MNWK2USR.js.map +0 -1
- package/dist/chunk-MRQLEK2B.js.map +0 -1
- package/dist/chunk-NCPN4SJR.js.map +0 -1
- package/dist/chunk-OIMLU4SF.js +0 -20
- package/dist/chunk-OIMLU4SF.js.map +0 -1
- package/dist/chunk-Q25IWLBT.js +0 -138
- package/dist/chunk-Q25IWLBT.js.map +0 -1
- package/dist/chunk-UQX6EXWG.js +0 -33
- package/dist/chunk-UQX6EXWG.js.map +0 -1
- package/dist/chunk-WQKHFADH.js.map +0 -1
- package/dist/chunk-XUUY2L2D.js +0 -42
- package/dist/chunk-XUUY2L2D.js.map +0 -1
- package/dist/chunk-YLMDBQO4.js +0 -141
- package/dist/chunk-YLMDBQO4.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -12
- package/dist/hooks/index.js +0 -17
- package/dist/hooks/index.js.map +0 -1
- package/dist/index-BxSbmOMr.d.ts +0 -257
- package/dist/middleware-Dp3d_pxi.d.ts +0 -90
- package/dist/request/index.d.ts +0 -28
- package/dist/request/index.js +0 -25
- package/dist/request/index.js.map +0 -1
- package/dist/tool-Cohdv5GC.d.ts +0 -65
- package/dist/types-D9JpeAPF.d.ts +0 -114
|
@@ -1,38 +1,198 @@
|
|
|
1
1
|
import {
|
|
2
2
|
cosineSimilarity,
|
|
3
3
|
embedText
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-DZ3CKYTH.js";
|
|
5
5
|
import {
|
|
6
6
|
toProviderJsonSchema
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-RFDVKCIE.js";
|
|
8
|
+
import {
|
|
9
|
+
isToolResultContentArray,
|
|
10
|
+
serializeToolResultOutput
|
|
11
|
+
} from "./chunk-ADH7NNCS.js";
|
|
8
12
|
|
|
9
13
|
// src/vector-store/index.ts
|
|
10
14
|
import { z } from "zod";
|
|
11
15
|
|
|
16
|
+
// src/internal/agent-runtime/approval-requirement.ts
|
|
17
|
+
function toolMayRequireApproval(requirement) {
|
|
18
|
+
return requirement !== void 0 && requirement !== false;
|
|
19
|
+
}
|
|
20
|
+
function assertToolApprovalRequirement(requirement, options) {
|
|
21
|
+
if (typeof requirement === "boolean") {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (options.allowFunction && typeof requirement === "function") {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (typeof requirement !== "object" || requirement === null || Array.isArray(requirement)) {
|
|
28
|
+
throw new TypeError(
|
|
29
|
+
'Tool "requiresApproval" must be a boolean, a function, or an object with an optional string reason.'
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
const reason = requirement.reason;
|
|
33
|
+
if (reason !== void 0 && typeof reason !== "string") {
|
|
34
|
+
throw new TypeError('Tool "requiresApproval.reason" must be a string.');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/tool/errors.ts
|
|
39
|
+
var ToolCallError = class extends Error {
|
|
40
|
+
constructor(message, cause) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.cause = cause;
|
|
43
|
+
this.name = "ToolCallError";
|
|
44
|
+
}
|
|
45
|
+
cause;
|
|
46
|
+
};
|
|
47
|
+
var ToolNotFoundError = class extends Error {
|
|
48
|
+
constructor(toolName) {
|
|
49
|
+
super(`Tool not found: ${toolName}`);
|
|
50
|
+
this.toolName = toolName;
|
|
51
|
+
this.name = "ToolNotFoundError";
|
|
52
|
+
}
|
|
53
|
+
toolName;
|
|
54
|
+
};
|
|
55
|
+
var ToolJsonError = class extends Error {
|
|
56
|
+
constructor(message, cause) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.cause = cause;
|
|
59
|
+
this.name = "ToolJsonError";
|
|
60
|
+
}
|
|
61
|
+
cause;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/tool/tool.ts
|
|
65
|
+
var ToolOutput = {
|
|
66
|
+
content(content) {
|
|
67
|
+
return content;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
function normalizeToolResultOutput(output) {
|
|
71
|
+
return isToolResultContentArray(output) ? output : serializeToolResultOutput(output);
|
|
72
|
+
}
|
|
73
|
+
function toolResultContentToText(content) {
|
|
74
|
+
return content.map((item) => item.type === "text" ? item.text : `[image:${item.mediaType ?? "image/png"}]`).join("\n");
|
|
75
|
+
}
|
|
76
|
+
function parseToolArgs(args) {
|
|
77
|
+
if (args.trim() === "") {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
return JSON.parse(args);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/internal/agent-runtime/prepared-tool-call.ts
|
|
84
|
+
var preparedToolInputSymbol = /* @__PURE__ */ Symbol("preparedToolInput");
|
|
85
|
+
var preparedToolOwnerSymbol = /* @__PURE__ */ Symbol("preparedToolOwner");
|
|
86
|
+
function attachPreparedToolOwner(tool, owner) {
|
|
87
|
+
Object.defineProperty(tool, preparedToolOwnerSymbol, {
|
|
88
|
+
configurable: false,
|
|
89
|
+
enumerable: true,
|
|
90
|
+
value: owner,
|
|
91
|
+
writable: false
|
|
92
|
+
});
|
|
93
|
+
return tool;
|
|
94
|
+
}
|
|
95
|
+
function preparedToolInput(context, owner) {
|
|
96
|
+
if (context === void 0 || !(preparedToolInputSymbol in context)) {
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
const prepared = context[preparedToolInputSymbol];
|
|
100
|
+
return prepared?.owner === owner ? { input: prepared.input } : void 0;
|
|
101
|
+
}
|
|
102
|
+
function withoutPreparedToolInput(context) {
|
|
103
|
+
if (!(preparedToolInputSymbol in context)) {
|
|
104
|
+
return context;
|
|
105
|
+
}
|
|
106
|
+
const { [preparedToolInputSymbol]: _prepared, ...publicContext } = context;
|
|
107
|
+
return publicContext;
|
|
108
|
+
}
|
|
109
|
+
function prepareToolCall(tool, args) {
|
|
110
|
+
let rawInput;
|
|
111
|
+
try {
|
|
112
|
+
rawInput = parseToolArgs(args);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw new ToolJsonError(`Invalid JSON arguments for tool ${tool.name}`, error);
|
|
115
|
+
}
|
|
116
|
+
let input;
|
|
117
|
+
try {
|
|
118
|
+
input = tool.parseInput === void 0 ? rawInput : tool.parseInput(rawInput);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
throw asToolCallError(tool.name, error);
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
input,
|
|
124
|
+
async call(context) {
|
|
125
|
+
try {
|
|
126
|
+
const owner = tool[preparedToolOwnerSymbol];
|
|
127
|
+
return normalizeToolResultOutput(
|
|
128
|
+
await tool.call(
|
|
129
|
+
input,
|
|
130
|
+
owner === void 0 ? context : withPreparedToolInput(context, owner, input)
|
|
131
|
+
)
|
|
132
|
+
);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
throw asToolCallError(tool.name, error);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function withPreparedToolInput(context, owner, input) {
|
|
140
|
+
const preparedContext = { ...context };
|
|
141
|
+
Object.defineProperty(preparedContext, preparedToolInputSymbol, {
|
|
142
|
+
configurable: false,
|
|
143
|
+
enumerable: true,
|
|
144
|
+
value: { owner, input },
|
|
145
|
+
writable: false
|
|
146
|
+
});
|
|
147
|
+
return preparedContext;
|
|
148
|
+
}
|
|
149
|
+
function asToolCallError(toolName, error) {
|
|
150
|
+
if (error instanceof ToolCallError) {
|
|
151
|
+
return error;
|
|
152
|
+
}
|
|
153
|
+
return error instanceof Error ? new ToolCallError(error.message, error) : new ToolCallError(`Tool ${toolName} failed`, error);
|
|
154
|
+
}
|
|
155
|
+
|
|
12
156
|
// src/tool/create-tool.ts
|
|
13
157
|
function createTool(options) {
|
|
14
|
-
const
|
|
158
|
+
const { name, description, inputSchema, outputSchema, execute } = options;
|
|
159
|
+
const requiresApproval = snapshotApprovalRequirement(options.requiresApproval);
|
|
160
|
+
if (requiresApproval !== void 0) {
|
|
161
|
+
assertToolApprovalRequirement(requiresApproval, { allowFunction: true });
|
|
162
|
+
}
|
|
163
|
+
const parameters = toProviderJsonSchema(inputSchema);
|
|
164
|
+
const preparedInputOwner = {};
|
|
15
165
|
const definition = () => ({
|
|
16
|
-
name
|
|
17
|
-
description
|
|
18
|
-
parameters
|
|
166
|
+
name,
|
|
167
|
+
description,
|
|
168
|
+
parameters: globalThis.structuredClone(parameters)
|
|
19
169
|
});
|
|
20
170
|
const call = async (args, context = {}) => {
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
171
|
+
const prepared = preparedToolInput(context, preparedInputOwner);
|
|
172
|
+
const parsedArgs = prepared === void 0 ? inputSchema.parse(args) : prepared.input;
|
|
173
|
+
const executionContext = prepared === void 0 ? context : withoutPreparedToolInput(context);
|
|
174
|
+
const result = await execute(parsedArgs, executionContext);
|
|
175
|
+
return outputSchema === void 0 ? result : outputSchema.parse(result);
|
|
24
176
|
};
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
name: options.name,
|
|
31
|
-
approval: options.approval,
|
|
177
|
+
const parseInput = (args) => inputSchema.parse(args);
|
|
178
|
+
const tool = {
|
|
179
|
+
name,
|
|
32
180
|
definition,
|
|
33
181
|
call,
|
|
34
|
-
|
|
182
|
+
parseInput
|
|
35
183
|
};
|
|
184
|
+
if (requiresApproval !== void 0) {
|
|
185
|
+
Object.defineProperty(tool, "requiresApproval", {
|
|
186
|
+
configurable: false,
|
|
187
|
+
enumerable: true,
|
|
188
|
+
value: requiresApproval,
|
|
189
|
+
writable: false
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return attachPreparedToolOwner(tool, preparedInputOwner);
|
|
193
|
+
}
|
|
194
|
+
function snapshotApprovalRequirement(requirement) {
|
|
195
|
+
return typeof requirement === "object" && requirement !== null ? Object.freeze({ ...requirement }) : requirement;
|
|
36
196
|
}
|
|
37
197
|
|
|
38
198
|
// src/vector-store/filter.ts
|
|
@@ -287,11 +447,11 @@ function createVectorSearchTool(index, options) {
|
|
|
287
447
|
return createTool({
|
|
288
448
|
name: options.name,
|
|
289
449
|
description: options.description ?? "Search a vector store for documents relevant to the provided query.",
|
|
290
|
-
|
|
450
|
+
inputSchema: z.object({
|
|
291
451
|
query: z.string().describe("The query string to search for relevant documents."),
|
|
292
452
|
topK: z.number().int().positive().optional().describe("The maximum number of results.")
|
|
293
453
|
}),
|
|
294
|
-
|
|
454
|
+
outputSchema: z.array(
|
|
295
455
|
z.object({
|
|
296
456
|
score: z.number(),
|
|
297
457
|
id: z.string(),
|
|
@@ -328,10 +488,20 @@ function validateEmbeddingDimension(expectedDimension, embedding, id) {
|
|
|
328
488
|
}
|
|
329
489
|
|
|
330
490
|
export {
|
|
491
|
+
toolMayRequireApproval,
|
|
492
|
+
assertToolApprovalRequirement,
|
|
493
|
+
ToolCallError,
|
|
494
|
+
ToolNotFoundError,
|
|
495
|
+
ToolJsonError,
|
|
496
|
+
ToolOutput,
|
|
497
|
+
normalizeToolResultOutput,
|
|
498
|
+
toolResultContentToText,
|
|
499
|
+
parseToolArgs,
|
|
500
|
+
prepareToolCall,
|
|
331
501
|
createTool,
|
|
332
502
|
vectorFilter,
|
|
333
503
|
InMemoryVectorStore,
|
|
334
504
|
InMemoryVectorIndex,
|
|
335
505
|
createVectorSearchTool
|
|
336
506
|
};
|
|
337
|
-
//# sourceMappingURL=chunk-
|
|
507
|
+
//# sourceMappingURL=chunk-R2LJSQUW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vector-store/index.ts","../src/internal/agent-runtime/approval-requirement.ts","../src/tool/errors.ts","../src/tool/tool.ts","../src/internal/agent-runtime/prepared-tool-call.ts","../src/tool/create-tool.ts","../src/vector-store/filter.ts","../src/vector-store/lsh.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {\n cosineSimilarity,\n type EmbeddedDocument,\n type Embedding,\n type EmbeddingModel,\n embedText,\n type VectorMetadata,\n} from \"../embeddings\";\nimport { createTool } from \"../tool/create-tool\";\nimport type { Tool } from \"../tool/tool\";\nimport { matchesVectorFilter } from \"./filter\";\nimport { LshIndex } from \"./lsh\";\nimport type {\n IndexStrategy,\n VectorInspectItem,\n VectorInspectPage,\n VectorInspectRequest,\n VectorSearchIndex,\n VectorSearchRequest,\n VectorSearchResult,\n VectorSearchToolOptions,\n} from \"./types\";\n\nexport { vectorFilter } from \"./filter\";\nexport type * from \"./types\";\n\ntype StoredDocument<T, Metadata extends VectorMetadata> = EmbeddedDocument<T, Metadata>;\n\nexport class InMemoryVectorStore<T, Metadata extends VectorMetadata = VectorMetadata> {\n private readonly documents = new Map<string, StoredDocument<T, Metadata>>();\n private indexStrategy: IndexStrategy;\n private lshIndex: LshIndex | undefined;\n private embeddingDimension: number | undefined;\n\n constructor(options: { index?: IndexStrategy } = {}) {\n this.indexStrategy = options.index ?? { type: \"bruteForce\" };\n }\n\n static fromDocuments<T, Metadata extends VectorMetadata = VectorMetadata>(\n documents: Array<EmbeddedDocument<T, Metadata>>,\n options: { index?: IndexStrategy } = {},\n ): InMemoryVectorStore<T, Metadata> {\n const store = new InMemoryVectorStore<T, Metadata>(options);\n store.addDocuments(documents);\n return store;\n }\n\n addDocuments(documents: Array<EmbeddedDocument<T, Metadata>>): this {\n this.validateDocumentDimensions(documents);\n for (const document of documents) {\n this.documents.set(document.id, document);\n }\n this.rebuildLshIndex();\n return this;\n }\n\n get(id: string): StoredDocument<T, Metadata> | undefined {\n return this.documents.get(id);\n }\n\n values(): Array<StoredDocument<T, Metadata>> {\n return [...this.documents.values()];\n }\n\n len(): number {\n return this.documents.size;\n }\n\n isEmpty(): boolean {\n return this.documents.size === 0;\n }\n\n index(model: EmbeddingModel): InMemoryVectorIndex<T, Metadata> {\n return new InMemoryVectorIndex(model, this);\n }\n\n candidates(queryEmbedding: Embedding): Array<StoredDocument<T, Metadata>> {\n this.validateQueryDimension(queryEmbedding);\n if (this.indexStrategy.type !== \"lsh\" || this.lshIndex === undefined) {\n return this.values();\n }\n\n const candidateIds = this.lshIndex.query(queryEmbedding.vector);\n if (candidateIds.size === 0) {\n return this.values();\n }\n\n return [...candidateIds].flatMap((id) => {\n const document = this.documents.get(id);\n return document === undefined ? [] : [document];\n });\n }\n\n private rebuildLshIndex(): void {\n if (this.indexStrategy.type !== \"lsh\") {\n this.lshIndex = undefined;\n return;\n }\n\n const firstEmbedding = this.values().flatMap((document) => document.embeddings)[0];\n if (firstEmbedding === undefined) {\n this.lshIndex = undefined;\n return;\n }\n\n const index = new LshIndex(firstEmbedding.vector.length, this.indexStrategy);\n for (const document of this.documents.values()) {\n for (const embedding of document.embeddings) {\n index.insert(document.id, embedding.vector);\n }\n }\n this.lshIndex = index;\n }\n\n private validateDocumentDimensions(documents: Array<EmbeddedDocument<T, Metadata>>): void {\n let dimension = this.embeddingDimension;\n for (const document of documents) {\n for (const embedding of document.embeddings) {\n dimension = validateEmbeddingDimension(dimension, embedding, document.id);\n }\n }\n this.embeddingDimension = dimension;\n }\n\n private validateQueryDimension(queryEmbedding: Embedding): void {\n if (this.embeddingDimension === undefined) {\n return;\n }\n validateEmbeddingDimension(this.embeddingDimension, queryEmbedding, \"query\");\n }\n}\n\nexport class InMemoryVectorIndex<T, Metadata extends VectorMetadata = VectorMetadata>\n implements VectorSearchIndex<T, Metadata>\n{\n constructor(\n private readonly model: EmbeddingModel,\n private readonly store: InMemoryVectorStore<T, Metadata>,\n ) {}\n\n async search(request: VectorSearchRequest): Promise<Array<VectorSearchResult<T, Metadata>>> {\n const queryEmbedding = await embedText(this.model, request.query);\n return this.store\n .candidates(queryEmbedding)\n .filter((document) => matchesVectorFilter(document.metadata, request.filter))\n .flatMap((document) => {\n const score = bestScore(queryEmbedding, document.embeddings);\n if (score === undefined) {\n return [];\n }\n if (request.threshold !== undefined && score < request.threshold) {\n return [];\n }\n const result: VectorSearchResult<T, Metadata> = {\n score,\n id: document.id,\n document: document.document,\n };\n if (document.metadata !== undefined) {\n result.metadata = document.metadata;\n }\n return [result];\n })\n .sort((left, right) => right.score - left.score)\n .slice(0, Math.max(0, Math.trunc(request.topK)));\n }\n\n async searchIds(request: VectorSearchRequest): Promise<Array<{ score: number; id: string }>> {\n return (await this.search(request)).map(({ score, id }) => ({ score, id }));\n }\n\n async inspect(request: VectorInspectRequest): Promise<VectorInspectPage<T, Metadata>> {\n const limit = Math.max(0, Math.trunc(request.limit));\n const start = Math.max(0, Math.trunc(Number(request.cursor ?? \"0\")));\n const documents = this.store\n .values()\n .filter((document) => matchesVectorFilter(document.metadata, request.filter));\n const page = documents.slice(start, start + limit);\n const nextOffset = start + page.length;\n const result: VectorInspectPage<T, Metadata> = {\n items: page.map((document) => {\n const item: VectorInspectItem<T, Metadata> = {\n id: document.id,\n document: document.document,\n };\n if (document.metadata !== undefined) {\n item.metadata = document.metadata;\n }\n return item;\n }),\n };\n if (nextOffset < documents.length) {\n result.nextCursor = String(nextOffset);\n }\n result.totalCount = documents.length;\n return result;\n }\n\n asTool(options: VectorSearchToolOptions): Tool<{ query: string; topK?: number }, unknown> {\n return createVectorSearchTool(this, options);\n }\n}\n\nexport function createVectorSearchTool<T, Metadata extends VectorMetadata>(\n index: VectorSearchIndex<T, Metadata>,\n options: VectorSearchToolOptions,\n): Tool<{ query: string; topK?: number }, Array<VectorSearchResult<T, Metadata>>> {\n return createTool({\n name: options.name,\n description:\n options.description ?? \"Search a vector store for documents relevant to the provided query.\",\n inputSchema: z.object({\n query: z.string().describe(\"The query string to search for relevant documents.\"),\n topK: z.number().int().positive().optional().describe(\"The maximum number of results.\"),\n }),\n outputSchema: z.array(\n z.object({\n score: z.number(),\n id: z.string(),\n document: z.any(),\n metadata: z\n .record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.null()]))\n .optional(),\n }),\n ),\n execute: ({ query, topK }) =>\n index.search({\n query,\n topK: topK ?? options.topK ?? 5,\n threshold: options.threshold,\n filter: options.filter,\n }),\n }) as Tool<{ query: string; topK?: number }, Array<VectorSearchResult<T, Metadata>>>;\n}\n\nfunction bestScore(queryEmbedding: Embedding, embeddings: Embedding[]): number | undefined {\n let best: number | undefined;\n for (const embedding of embeddings) {\n const score = cosineSimilarity(queryEmbedding.vector, embedding.vector);\n best = best === undefined ? score : Math.max(best, score);\n }\n return best;\n}\n\nfunction validateEmbeddingDimension(\n expectedDimension: number | undefined,\n embedding: Embedding,\n id: string,\n): number {\n if (expectedDimension === undefined) {\n return embedding.vector.length;\n }\n if (embedding.vector.length !== expectedDimension) {\n throw new Error(\n `Vector dimension mismatch: expected ${expectedDimension} dimensions but received ${embedding.vector.length} for ${id}`,\n );\n }\n return expectedDimension;\n}\n","import type { ToolApprovalRequirement } from \"../../tool/tool\";\n\nexport function toolMayRequireApproval(requirement: unknown): boolean {\n return requirement !== undefined && requirement !== false;\n}\n\nexport function assertToolApprovalRequirement(\n requirement: unknown,\n options: { allowFunction: boolean },\n): asserts requirement is boolean | ToolApprovalRequirement | ((...args: never[]) => unknown) {\n if (typeof requirement === \"boolean\") {\n return;\n }\n if (options.allowFunction && typeof requirement === \"function\") {\n return;\n }\n if (typeof requirement !== \"object\" || requirement === null || Array.isArray(requirement)) {\n throw new TypeError(\n 'Tool \"requiresApproval\" must be a boolean, a function, or an object with an optional string reason.',\n );\n }\n const reason = (requirement as { reason?: unknown }).reason;\n if (reason !== undefined && typeof reason !== \"string\") {\n throw new TypeError('Tool \"requiresApproval.reason\" must be a string.');\n }\n}\n","export class ToolCallError extends Error {\n constructor(\n message: string,\n readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"ToolCallError\";\n }\n}\n\nexport class ToolNotFoundError extends Error {\n constructor(readonly toolName: string) {\n super(`Tool not found: ${toolName}`);\n this.name = \"ToolNotFoundError\";\n }\n}\n\nexport class ToolJsonError extends Error {\n constructor(\n message: string,\n readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"ToolJsonError\";\n }\n}\n","import type { JsonObject, JsonValue, ToolDefinition, ToolResultContent } from \"../completion/types\";\nimport {\n isToolResultContentArray,\n serializeToolResultOutput as serializeToolOutput,\n} from \"../completion/types\";\n\nexport type ToolApprovalRunContext = {\n agentId: string;\n runId: string;\n sessionId?: string;\n metadata?: JsonObject;\n};\n\nexport type ToolApprovalContext<Args = unknown> = {\n toolName: string;\n args: Args;\n rawArgs: string;\n toolCallId?: string;\n internalCallId: string;\n run: ToolApprovalRunContext;\n};\n\nexport type ToolApprovalRequirement = {\n reason?: string | undefined;\n};\n\nexport type ToolRequiresApproval<Args = unknown> =\n | boolean\n | ToolApprovalRequirement\n | ((\n args: Args,\n context: ToolApprovalContext<Args>,\n ) => boolean | ToolApprovalRequirement | Promise<boolean | ToolApprovalRequirement>);\n\nexport type ToolCallStreamEvent = {\n agentId: string;\n agentName?: string | undefined;\n event: unknown;\n};\n\nexport type ToolCallContext = {\n emitStreamEvent?(event: ToolCallStreamEvent): void | Promise<void>;\n includeToolCallDeltas?: boolean;\n};\n\nexport interface Tool<Args = unknown, Output = unknown> {\n readonly name: string;\n readonly requiresApproval?: ToolRequiresApproval<Args>;\n definition(prompt: string): ToolDefinition | Promise<ToolDefinition>;\n call(args: Args, context?: ToolCallContext): Output | Promise<Output>;\n parseInput?(args: JsonValue): Args;\n}\n\nexport type AnyTool = Omit<Tool<unknown, unknown>, \"requiresApproval\"> & {\n readonly requiresApproval?: unknown;\n};\n\nexport type NormalizedToolOutput = string | ToolResultContent[];\n\nexport const ToolOutput = {\n content(content: ToolResultContent[]): ToolResultContent[] {\n return content;\n },\n};\n\nexport { isToolResultContentArray, serializeToolOutput };\n\nexport function normalizeToolResultOutput(output: unknown): NormalizedToolOutput {\n return isToolResultContentArray(output) ? output : serializeToolOutput(output);\n}\n\nexport function toolResultContentToText(content: ToolResultContent[]): string {\n return content\n .map((item) => (item.type === \"text\" ? item.text : `[image:${item.mediaType ?? \"image/png\"}]`))\n .join(\"\\n\");\n}\n\nexport function parseToolArgs(args: string): JsonValue {\n if (args.trim() === \"\") {\n return {};\n }\n\n return JSON.parse(args) as JsonValue;\n}\n","import { ToolCallError, ToolJsonError } from \"../../tool/errors\";\nimport {\n type AnyTool,\n type NormalizedToolOutput,\n normalizeToolResultOutput,\n parseToolArgs,\n type ToolCallContext,\n} from \"../../tool/tool\";\n\nconst preparedToolInputSymbol = Symbol(\"preparedToolInput\");\nconst preparedToolOwnerSymbol = Symbol(\"preparedToolOwner\");\n\nexport type PreparedToolCall = {\n input: unknown;\n call(context: ToolCallContext): Promise<NormalizedToolOutput>;\n};\n\ntype PreparedToolCallContext = ToolCallContext & {\n [preparedToolInputSymbol]?: { owner: object; input: unknown };\n};\n\ntype ToolWithPreparedOwner = AnyTool & {\n [preparedToolOwnerSymbol]?: object;\n};\n\nexport function attachPreparedToolOwner<T extends AnyTool>(tool: T, owner: object): T {\n Object.defineProperty(tool, preparedToolOwnerSymbol, {\n configurable: false,\n enumerable: true,\n value: owner,\n writable: false,\n });\n return tool;\n}\n\nexport function preparedToolInput(\n context: ToolCallContext | undefined,\n owner: object,\n): { input: unknown } | undefined {\n if (context === undefined || !(preparedToolInputSymbol in context)) {\n return undefined;\n }\n const prepared = (context as PreparedToolCallContext)[preparedToolInputSymbol];\n return prepared?.owner === owner ? { input: prepared.input } : undefined;\n}\n\nexport function withoutPreparedToolInput(context: ToolCallContext): ToolCallContext {\n if (!(preparedToolInputSymbol in context)) {\n return context;\n }\n const { [preparedToolInputSymbol]: _prepared, ...publicContext } =\n context as PreparedToolCallContext;\n return publicContext;\n}\n\nexport function prepareToolCall(tool: AnyTool, args: string): PreparedToolCall {\n let rawInput: ReturnType<typeof parseToolArgs>;\n try {\n rawInput = parseToolArgs(args);\n } catch (error) {\n throw new ToolJsonError(`Invalid JSON arguments for tool ${tool.name}`, error);\n }\n\n let input: unknown;\n try {\n input = tool.parseInput === undefined ? rawInput : tool.parseInput(rawInput);\n } catch (error) {\n throw asToolCallError(tool.name, error);\n }\n\n return {\n input,\n async call(context) {\n try {\n const owner = (tool as ToolWithPreparedOwner)[preparedToolOwnerSymbol];\n return normalizeToolResultOutput(\n await tool.call(\n input,\n owner === undefined ? context : withPreparedToolInput(context, owner, input),\n ),\n );\n } catch (error) {\n throw asToolCallError(tool.name, error);\n }\n },\n };\n}\n\nfunction withPreparedToolInput(\n context: ToolCallContext,\n owner: object,\n input: unknown,\n): ToolCallContext {\n const preparedContext: PreparedToolCallContext = { ...context };\n Object.defineProperty(preparedContext, preparedToolInputSymbol, {\n configurable: false,\n enumerable: true,\n value: { owner, input },\n writable: false,\n });\n return preparedContext;\n}\n\nfunction asToolCallError(toolName: string, error: unknown): ToolCallError {\n if (error instanceof ToolCallError) {\n return error;\n }\n return error instanceof Error\n ? new ToolCallError(error.message, error)\n : new ToolCallError(`Tool ${toolName} failed`, error);\n}\n","import type { z } from \"zod\";\nimport { assertToolApprovalRequirement } from \"../internal/agent-runtime/approval-requirement\";\nimport {\n attachPreparedToolOwner,\n preparedToolInput,\n withoutPreparedToolInput,\n} from \"../internal/agent-runtime/prepared-tool-call\";\nimport { toProviderJsonSchema, type ZodSchema } from \"../schema/zod-schema\";\nimport type { Tool, ToolCallContext, ToolRequiresApproval } from \"./tool\";\n\nexport type CreateToolOptions<\n InputSchema extends ZodSchema,\n OutputSchema extends ZodSchema | undefined = undefined,\n Output = unknown,\n> = {\n name: string;\n description: string;\n inputSchema: InputSchema;\n outputSchema?: OutputSchema;\n requiresApproval?: ToolRequiresApproval<z.output<InputSchema>>;\n execute(\n args: z.output<InputSchema>,\n context: ToolCallContext,\n ): OutputSchema extends ZodSchema\n ? z.input<OutputSchema> | Promise<z.input<OutputSchema>>\n : Output | Promise<Output>;\n};\n\ntype CreateToolOutput<\n OutputSchema extends ZodSchema | undefined,\n Output,\n> = OutputSchema extends ZodSchema ? z.output<OutputSchema> : Output;\n\nexport function createTool<InputSchema extends ZodSchema, Output = unknown>(\n options: CreateToolOptions<InputSchema, undefined, Output> & { outputSchema?: undefined },\n): Tool<z.output<InputSchema>, Output>;\n\nexport function createTool<InputSchema extends ZodSchema, OutputSchema extends ZodSchema>(\n options: CreateToolOptions<InputSchema, OutputSchema>,\n): Tool<z.output<InputSchema>, z.output<OutputSchema>>;\n\nexport function createTool<\n InputSchema extends ZodSchema,\n OutputSchema extends ZodSchema | undefined = undefined,\n Output = unknown,\n>(\n options: CreateToolOptions<InputSchema, OutputSchema, Output>,\n): Tool<z.output<InputSchema>, CreateToolOutput<OutputSchema, Output>> {\n const { name, description, inputSchema, outputSchema, execute } = options;\n const requiresApproval = snapshotApprovalRequirement(options.requiresApproval);\n if (requiresApproval !== undefined) {\n assertToolApprovalRequirement(requiresApproval, { allowFunction: true });\n }\n const parameters = toProviderJsonSchema(inputSchema);\n const preparedInputOwner = {};\n const definition = () => ({\n name,\n description,\n parameters: globalThis.structuredClone(parameters),\n });\n const call = async (\n args: z.output<InputSchema>,\n context: ToolCallContext = {},\n ): Promise<CreateToolOutput<OutputSchema, Output>> => {\n const prepared = preparedToolInput(context, preparedInputOwner);\n const parsedArgs =\n prepared === undefined ? inputSchema.parse(args) : (prepared.input as z.output<InputSchema>);\n const executionContext = prepared === undefined ? context : withoutPreparedToolInput(context);\n const result = await execute(parsedArgs, executionContext);\n return (outputSchema === undefined ? result : outputSchema.parse(result)) as CreateToolOutput<\n OutputSchema,\n Output\n >;\n };\n const parseInput = (args: unknown): z.output<InputSchema> => inputSchema.parse(args);\n\n const tool: Tool<z.output<InputSchema>, CreateToolOutput<OutputSchema, Output>> = {\n name,\n definition,\n call,\n parseInput,\n };\n if (requiresApproval !== undefined) {\n Object.defineProperty(tool, \"requiresApproval\", {\n configurable: false,\n enumerable: true,\n value: requiresApproval,\n writable: false,\n });\n }\n return attachPreparedToolOwner(tool, preparedInputOwner);\n}\n\nfunction snapshotApprovalRequirement<Args>(\n requirement: ToolRequiresApproval<Args> | undefined,\n): ToolRequiresApproval<Args> | undefined {\n return typeof requirement === \"object\" && requirement !== null\n ? Object.freeze({ ...requirement })\n : requirement;\n}\n","import type { VectorMetadata, VectorMetadataValue } from \"../embeddings\";\nimport type { VectorFilter } from \"./types\";\n\nexport type { VectorFilter } from \"./types\";\n\nexport const vectorFilter = {\n eq(key: string, value: VectorMetadataValue): VectorFilter {\n return { type: \"eq\", key, value };\n },\n gt(key: string, value: VectorMetadataValue): VectorFilter {\n return { type: \"gt\", key, value };\n },\n lt(key: string, value: VectorMetadataValue): VectorFilter {\n return { type: \"lt\", key, value };\n },\n and(left: VectorFilter, right: VectorFilter): VectorFilter {\n return { type: \"and\", filters: [left, right] };\n },\n or(left: VectorFilter, right: VectorFilter): VectorFilter {\n return { type: \"or\", filters: [left, right] };\n },\n};\n\nexport function matchesVectorFilter(\n metadata: VectorMetadata | undefined,\n filter: VectorFilter | undefined,\n): boolean {\n if (filter === undefined) {\n return true;\n }\n if (metadata === undefined) {\n return false;\n }\n\n switch (filter.type) {\n case \"eq\":\n return metadata[filter.key] === filter.value;\n case \"gt\":\n return compare(metadata[filter.key], filter.value) > 0;\n case \"lt\":\n return compare(metadata[filter.key], filter.value) < 0;\n case \"and\":\n return (\n matchesVectorFilter(metadata, filter.filters[0]) &&\n matchesVectorFilter(metadata, filter.filters[1])\n );\n case \"or\":\n return (\n matchesVectorFilter(metadata, filter.filters[0]) ||\n matchesVectorFilter(metadata, filter.filters[1])\n );\n }\n}\n\nfunction compare(left: VectorMetadataValue | undefined, right: VectorMetadataValue): number {\n if (typeof left === \"number\" && typeof right === \"number\") {\n return left - right;\n }\n if (typeof left === \"string\" && typeof right === \"string\") {\n return left.localeCompare(right);\n }\n if (typeof left === \"boolean\" && typeof right === \"boolean\") {\n return Number(left) - Number(right);\n }\n return 0;\n}\n","import type { LshOptions } from \"./types\";\n\nexport type { LshOptions } from \"./types\";\n\nexport class LshIndex {\n private readonly hyperplanes: number[][];\n private readonly tables: Array<Map<string, Set<string>>>;\n\n constructor(\n dimensions: number,\n private readonly options: LshOptions,\n ) {\n const rng = seededRandom(options.seed ?? 42);\n this.hyperplanes = [];\n for (let index = 0; index < options.numTables * options.numHyperplanes; index += 1) {\n const plane = Array.from({ length: dimensions }, () => rng() * 2 - 1);\n const norm = Math.sqrt(plane.reduce((sum, value) => sum + value ** 2, 0));\n this.hyperplanes.push(norm === 0 ? plane : plane.map((value) => value / norm));\n }\n this.tables = Array.from({ length: options.numTables }, () => new Map());\n }\n\n insert(id: string, vector: number[]): void {\n for (let table = 0; table < this.options.numTables; table += 1) {\n const hash = this.hash(vector, table);\n const bucket = this.tables[table]?.get(hash) ?? new Set<string>();\n bucket.add(id);\n this.tables[table]?.set(hash, bucket);\n }\n }\n\n query(vector: number[]): Set<string> {\n const candidates = new Set<string>();\n for (let table = 0; table < this.options.numTables; table += 1) {\n const hash = this.hash(vector, table);\n for (const id of this.tables[table]?.get(hash) ?? []) {\n candidates.add(id);\n }\n }\n return candidates;\n }\n\n private hash(vector: number[], table: number): string {\n let hash = \"\";\n const start = table * this.options.numHyperplanes;\n for (let offset = 0; offset < this.options.numHyperplanes; offset += 1) {\n const plane = this.hyperplanes[start + offset] as number[];\n const dot = vector.reduce((sum, value, index) => sum + value * (plane[index] ?? 0), 0);\n hash += dot >= 0 ? \"1\" : \"0\";\n }\n return hash;\n }\n}\n\nfunction seededRandom(seed: number): () => number {\n let state = seed >>> 0;\n return () => {\n state = (state * 1664525 + 1013904223) >>> 0;\n return state / 0x100000000;\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAS,SAAS;;;ACEX,SAAS,uBAAuB,aAA+B;AACpE,SAAO,gBAAgB,UAAa,gBAAgB;AACtD;AAEO,SAAS,8BACd,aACA,SAC4F;AAC5F,MAAI,OAAO,gBAAgB,WAAW;AACpC;AAAA,EACF;AACA,MAAI,QAAQ,iBAAiB,OAAO,gBAAgB,YAAY;AAC9D;AAAA,EACF;AACA,MAAI,OAAO,gBAAgB,YAAY,gBAAgB,QAAQ,MAAM,QAAQ,WAAW,GAAG;AACzF,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,SAAU,YAAqC;AACrD,MAAI,WAAW,UAAa,OAAO,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ACD,cAAc,EAAE;AAAA,MACd,EAAE,OAAO;AAAA,QACP,OAAO,EAAE,OAAO;AAAA,QAChB,IAAI,EAAE,OAAO;AAAA,QACb,UAAU,EAAE,IAAI;AAAA,QAChB,UAAU,EACP,OAAO,EAAE,OAAO,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EAC3E,SAAS;AAAA,MACd,CAAC;AAAA,IACH;AAAA,IACA,SAAS,CAAC,EAAE,OAAO,KAAK,MACtB,MAAM,OAAO;AAAA,MACX;AAAA,MACA,MAAM,QAAQ,QAAQ,QAAQ;AAAA,MAC9B,WAAW,QAAQ;AAAA,MACnB,QAAQ,QAAQ;AAAA,IAClB,CAAC;AAAA,EACL,CAAC;AACH;AAEA,SAAS,UAAU,gBAA2B,YAA6C;AACzF,MAAI;AACJ,aAAW,aAAa,YAAY;AAClC,UAAM,QAAQ,iBAAiB,eAAe,QAAQ,UAAU,MAAM;AACtE,WAAO,SAAS,SAAY,QAAQ,KAAK,IAAI,MAAM,KAAK;AAAA,EAC1D;AACA,SAAO;AACT;AAEA,SAAS,2BACP,mBACA,WACA,IACQ;AACR,MAAI,sBAAsB,QAAW;AACnC,WAAO,UAAU,OAAO;AAAA,EAC1B;AACA,MAAI,UAAU,OAAO,WAAW,mBAAmB;AACjD,UAAM,IAAI;AAAA,MACR,uCAAuC,iBAAiB,4BAA4B,UAAU,OAAO,MAAM,QAAQ,EAAE;AAAA,IACvH;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/schema/zod-schema.ts
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
function toProviderJsonSchema(schema) {
|
|
4
|
-
const jsonSchema = z.toJSONSchema(schema);
|
|
3
|
+
function toProviderJsonSchema(schema, options = {}) {
|
|
4
|
+
const jsonSchema = z.toJSONSchema(schema, options);
|
|
5
5
|
const { $schema: _schema, ...providerSchema } = jsonSchema;
|
|
6
6
|
return providerSchema;
|
|
7
7
|
}
|
|
@@ -9,4 +9,4 @@ function toProviderJsonSchema(schema) {
|
|
|
9
9
|
export {
|
|
10
10
|
toProviderJsonSchema
|
|
11
11
|
};
|
|
12
|
-
//# sourceMappingURL=chunk-
|
|
12
|
+
//# sourceMappingURL=chunk-RFDVKCIE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema/zod-schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { JsonObject } from \"../completion/index\";\n\nexport type ZodSchema<T = unknown> = z.ZodType<T>;\n\nexport function toProviderJsonSchema(\n schema: z.ZodType,\n options: { io?: \"input\" | \"output\" } = {},\n): JsonObject {\n const jsonSchema = z.toJSONSchema(schema, options) as JsonObject;\n const { $schema: _schema, ...providerSchema } = jsonSchema;\n return providerSchema;\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAKX,SAAS,qBACd,QACA,UAAuC,CAAC,GAC5B;AACZ,QAAM,aAAa,EAAE,aAAa,QAAQ,OAAO;AACjD,QAAM,EAAE,SAAS,SAAS,GAAG,eAAe,IAAI;AAChD,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveRetryOptions,
|
|
3
|
+
runWithRetries
|
|
4
|
+
} from "./chunk-A3UBYTJT.js";
|
|
5
|
+
|
|
6
|
+
// src/audio-generation/generate-speech.ts
|
|
7
|
+
function generateSpeech(text, options) {
|
|
8
|
+
assertNonEmptyString(text, "Speech text");
|
|
9
|
+
assertNonEmptyString(options.voice, "Speech voice");
|
|
10
|
+
const speed = options.speed ?? 1;
|
|
11
|
+
if (!Number.isFinite(speed) || speed <= 0) {
|
|
12
|
+
throw new RangeError("Speech speed must be a positive finite number.");
|
|
13
|
+
}
|
|
14
|
+
const request = { text, voice: options.voice, speed };
|
|
15
|
+
if (options.additionalParams !== void 0) {
|
|
16
|
+
request.additionalParams = options.additionalParams;
|
|
17
|
+
}
|
|
18
|
+
const retries = options.retries === void 0 ? void 0 : resolveRetryOptions(options.retries);
|
|
19
|
+
return runWithRetries(
|
|
20
|
+
() => options.model.audioGeneration(request),
|
|
21
|
+
retries,
|
|
22
|
+
{ streaming: false }
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
function assertNonEmptyString(value, name) {
|
|
26
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
27
|
+
throw new TypeError(`${name} must be a non-empty string.`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
generateSpeech
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=chunk-RMUBRRSK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/audio-generation/generate-speech.ts"],"sourcesContent":["import type { JsonValue } from \"../completion/types\";\nimport { type RetryOptions, resolveRetryOptions, runWithRetries } from \"../retry\";\nimport type { AudioGenerationModel, AudioGenerationRequest } from \"./types\";\n\nexport type GenerateSpeechOptions<Model extends AudioGenerationModel = AudioGenerationModel> = {\n model: Model;\n voice: string;\n speed?: number | undefined;\n additionalParams?: JsonValue | undefined;\n retries?: RetryOptions | undefined;\n};\n\nexport function generateSpeech<Model extends AudioGenerationModel>(\n text: string,\n options: GenerateSpeechOptions<Model>,\n): Promise<Awaited<ReturnType<Model[\"audioGeneration\"]>>> {\n assertNonEmptyString(text, \"Speech text\");\n assertNonEmptyString(options.voice, \"Speech voice\");\n const speed = options.speed ?? 1;\n if (!Number.isFinite(speed) || speed <= 0) {\n throw new RangeError(\"Speech speed must be a positive finite number.\");\n }\n\n const request: AudioGenerationRequest = { text, voice: options.voice, speed };\n if (options.additionalParams !== undefined) {\n request.additionalParams = options.additionalParams;\n }\n const retries = options.retries === undefined ? undefined : resolveRetryOptions(options.retries);\n return runWithRetries<Awaited<ReturnType<Model[\"audioGeneration\"]>>>(\n () =>\n options.model.audioGeneration(request) as Promise<\n Awaited<ReturnType<Model[\"audioGeneration\"]>>\n >,\n retries,\n { streaming: false },\n );\n}\n\nfunction assertNonEmptyString(value: string, name: string): void {\n if (typeof value !== \"string\" || value.trim().length === 0) {\n throw new TypeError(`${name} must be a non-empty string.`);\n }\n}\n"],"mappings":";;;;;;AAYO,SAAS,eACd,MACA,SACwD;AACxD,uBAAqB,MAAM,aAAa;AACxC,uBAAqB,QAAQ,OAAO,cAAc;AAClD,QAAM,QAAQ,QAAQ,SAAS;AAC/B,MAAI,CAAC,OAAO,SAAS,KAAK,KAAK,SAAS,GAAG;AACzC,UAAM,IAAI,WAAW,gDAAgD;AAAA,EACvE;AAEA,QAAM,UAAkC,EAAE,MAAM,OAAO,QAAQ,OAAO,MAAM;AAC5E,MAAI,QAAQ,qBAAqB,QAAW;AAC1C,YAAQ,mBAAmB,QAAQ;AAAA,EACrC;AACA,QAAM,UAAU,QAAQ,YAAY,SAAY,SAAY,oBAAoB,QAAQ,OAAO;AAC/F,SAAO;AAAA,IACL,MACE,QAAQ,MAAM,gBAAgB,OAAO;AAAA,IAGvC;AAAA,IACA,EAAE,WAAW,MAAM;AAAA,EACrB;AACF;AAEA,SAAS,qBAAqB,OAAe,MAAoB;AAC/D,MAAI,OAAO,UAAU,YAAY,MAAM,KAAK,EAAE,WAAW,GAAG;AAC1D,UAAM,IAAI,UAAU,GAAG,IAAI,8BAA8B;AAAA,EAC3D;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ui/messages.ts"],"sourcesContent":["import { isJsonValue } from \"../completion/json\";\nimport {\n AssistantContent,\n type AssistantContent as AssistantContentType,\n type Message as CoreMessage,\n type DocumentContent,\n type ImageContent,\n type ImageDetail,\n type JsonValue,\n Message,\n reasoningDisplayText,\n serializeToolResultOutput,\n ToolContent,\n type ToolContent as ToolContentType,\n type ToolResultContent,\n UserContent,\n type UserContent as UserContentType,\n} from \"../completion/types\";\nimport type { UIAttachment, UIMessage, UIMessagePart, UIToolMessagePart } from \"./types\";\n\ntype UIToolPartLocation = {\n messageIndex: number;\n partIndex: number;\n};\n\ntype UIToolPartLocations = {\n byToolCallId: Map<string, UIToolPartLocation>;\n byCallId: Map<string, UIToolPartLocation>;\n};\n\nexport function uiMessagesToCoreMessages(messages: UIMessage[]): CoreMessage[] {\n const coreMessages: CoreMessage[] = [];\n\n for (const message of messages) {\n const text = textFromUIParts(message.parts);\n\n if (message.role === \"system\") {\n if (text.length > 0) {\n coreMessages.push(Message.system(text, metadataOptions(message.metadata)));\n }\n continue;\n }\n\n if (message.role === \"user\") {\n const content: UserContentType[] = [];\n for (const part of message.parts) {\n if (part.type === \"text\") {\n content.push(UserContent.text(part.text));\n continue;\n }\n if (part.type === \"attachment\") {\n content.push(attachmentToUserContent(part.attachment));\n continue;\n }\n if (part.type === \"data\" && isUserContent(part.data)) {\n content.push(part.data);\n continue;\n }\n throw new TypeError(\n \"User UI messages can only be converted from text, attachment, or image/document data parts.\",\n );\n }\n if (content.length > 0) {\n coreMessages.push(Message.user(content, metadataOptions(message.metadata)));\n }\n continue;\n }\n\n if (message.role === \"assistant\") {\n const content: AssistantContentType[] = [];\n const toolResults: ToolContentType[] = [];\n for (const part of message.parts) {\n if (part.type === \"text\" && part.text.length > 0) {\n content.push(AssistantContent.text(part.text));\n continue;\n }\n if (part.type === \"reasoning\" && part.text.length > 0) {\n content.push(AssistantContent.reasoning(part.text, part.reasoningId));\n continue;\n }\n if (\n part.type === \"tool\" &&\n (part.state === \"input-streaming\" ||\n part.state === \"input-available\" ||\n part.state === \"output-available\")\n ) {\n content.push(\n AssistantContent.toolCall(\n part.toolCallId,\n part.toolName,\n part.input ?? {},\n part.callId,\n ),\n );\n if (part.state === \"output-available\") {\n toolResults.push(\n ToolContent.toolResult(part.toolCallId, outputToToolResultContent(part.output), {\n callId: part.callId,\n toolName: part.toolName,\n }),\n );\n }\n }\n }\n if (content.length > 0) {\n coreMessages.push(\n Message.assistant(content, {\n id: message.id,\n ...metadataOptions(message.metadata),\n }),\n );\n }\n if (toolResults.length > 0) {\n coreMessages.push(Message.tool(toolResults));\n }\n continue;\n }\n\n const toolResults: ToolContentType[] = [];\n for (const part of message.parts) {\n if (part.type !== \"tool\" || part.state !== \"output-available\") {\n continue;\n }\n toolResults.push(\n ToolContent.toolResult(part.toolCallId, outputToToolResultContent(part.output), {\n callId: part.callId,\n toolName: part.toolName,\n }),\n );\n }\n if (toolResults.length > 0) {\n coreMessages.push(Message.tool(toolResults, metadataOptions(message.metadata)));\n }\n }\n\n return coreMessages;\n}\n\nexport function coreMessagesToUIMessages(messages: CoreMessage[]): UIMessage[] {\n const uiMessages: UIMessage[] = [];\n const toolPartLocations: UIToolPartLocations = {\n byToolCallId: new Map(),\n byCallId: new Map(),\n };\n\n for (const message of messages) {\n if (message.role === \"system\") {\n uiMessages.push({\n id: createId(\"msg\"),\n role: \"system\",\n parts: [{ id: createId(\"part\"), type: \"text\", text: message.content }],\n ...uiMetadata(message.metadata),\n });\n continue;\n }\n\n if (message.role === \"user\") {\n const parts: UIMessagePart[] = [];\n for (const content of message.content) {\n if (content.type === \"text\") {\n parts.push({ id: createId(\"part\"), type: \"text\", text: content.text });\n } else {\n parts.push({\n id: createId(\"part\"),\n type: \"attachment\",\n attachment: userContentToAttachment(content),\n });\n }\n }\n uiMessages.push({\n id: createId(\"msg\"),\n role: \"user\",\n parts,\n ...uiMetadata(message.metadata),\n });\n continue;\n }\n\n if (message.role === \"assistant\") {\n const parts: UIMessagePart[] = [];\n for (const content of message.content) {\n if (content.type === \"text\") {\n parts.push({ id: createId(\"part\"), type: \"text\", text: content.text });\n continue;\n }\n if (content.type === \"reasoning\") {\n const part: UIMessagePart = {\n id: createId(\"part\"),\n type: \"reasoning\",\n text: reasoningDisplayText(content),\n };\n if (content.id !== undefined) {\n part.reasoningId = content.id;\n }\n parts.push(part);\n continue;\n }\n if (content.type === \"tool_call\") {\n const part: UIMessagePart = {\n id: toolPartId(content.id),\n type: \"tool\",\n toolName: content.function.name,\n toolCallId: content.id,\n state: \"input-available\",\n input: content.function.arguments,\n };\n if (content.callId !== undefined) {\n part.callId = content.callId;\n }\n parts.push(part);\n continue;\n }\n parts.push({\n id: createId(\"part\"),\n type: \"data\",\n name: content.type,\n data: content as JsonValue,\n });\n }\n const messageIndex = uiMessages.length;\n uiMessages.push({\n id: message.id ?? createId(\"msg\"),\n role: \"assistant\",\n parts,\n ...uiMetadata(message.metadata),\n });\n registerToolPartLocations(parts, messageIndex, toolPartLocations);\n continue;\n }\n\n const parts: UIMessagePart[] = [];\n for (const content of message.content) {\n const part: UIToolMessagePart = {\n id: toolPartId(content.id),\n type: \"tool\",\n toolName: toolNameForResult(content, uiMessages, toolPartLocations),\n toolCallId: content.id,\n state: \"output-available\",\n output: toolResultContentToJson(content.content),\n };\n if (content.callId !== undefined) {\n part.callId = content.callId;\n }\n if (\n message.metadata === undefined &&\n mergeToolResultPart(uiMessages, toolPartLocations, part)\n ) {\n continue;\n }\n parts.push(part);\n }\n if (parts.length > 0) {\n uiMessages.push({\n id: createId(\"msg\"),\n role: \"tool\",\n parts,\n ...uiMetadata(message.metadata),\n });\n }\n }\n\n return uiMessages;\n}\n\nfunction metadataOptions(metadata: UIMessage[\"metadata\"]): { metadata?: JsonValue } {\n if (metadata === undefined) {\n return {};\n }\n if (!isJsonValue(metadata)) {\n throw new TypeError(\"UI message metadata must be a strict JSON value.\");\n }\n return { metadata };\n}\n\nfunction uiMetadata(metadata: JsonValue | undefined): { metadata?: JsonValue } {\n if (metadata === undefined) {\n return {};\n }\n if (!isJsonValue(metadata)) {\n throw new TypeError(\"Core message metadata must be a strict JSON value.\");\n }\n return { metadata };\n}\n\nfunction registerToolPartLocations(\n parts: UIMessagePart[],\n messageIndex: number,\n toolPartLocations: UIToolPartLocations,\n): void {\n for (const [partIndex, part] of parts.entries()) {\n if (part.type !== \"tool\") {\n continue;\n }\n const location = { messageIndex, partIndex };\n toolPartLocations.byToolCallId.set(part.toolCallId, location);\n if (part.callId !== undefined) {\n toolPartLocations.byCallId.set(part.callId, location);\n }\n }\n}\n\nfunction mergeToolResultPart(\n uiMessages: UIMessage[],\n toolPartLocations: UIToolPartLocations,\n resultPart: UIMessagePart,\n): boolean {\n if (resultPart.type !== \"tool\") {\n return false;\n }\n\n const location = findToolPartLocation(\n resultPart.toolCallId,\n resultPart.callId,\n toolPartLocations,\n );\n if (location === undefined) {\n return false;\n }\n\n const message = uiMessages[location.messageIndex];\n const currentPart = message?.parts[location.partIndex];\n if (message === undefined || currentPart?.type !== \"tool\") {\n return false;\n }\n\n const mergedPart: UIToolMessagePart = {\n ...currentPart,\n toolName: resultPart.toolName === \"tool\" ? currentPart.toolName : resultPart.toolName,\n state: \"output-available\",\n };\n if (resultPart.output !== undefined) {\n mergedPart.output = resultPart.output;\n }\n if (currentPart.callId === undefined && resultPart.callId !== undefined) {\n mergedPart.callId = resultPart.callId;\n toolPartLocations.byCallId.set(resultPart.callId, location);\n }\n\n const nextParts = [...message.parts];\n nextParts[location.partIndex] = mergedPart;\n uiMessages[location.messageIndex] = { ...message, parts: nextParts };\n return true;\n}\n\nfunction findToolPartLocation(\n toolCallId: string,\n callId: string | undefined,\n toolPartLocations: UIToolPartLocations,\n): UIToolPartLocation | undefined {\n return (\n (callId === undefined ? undefined : toolPartLocations.byCallId.get(callId)) ??\n toolPartLocations.byToolCallId.get(toolCallId)\n );\n}\n\nfunction toolNameForResult(\n content: ToolContentType,\n uiMessages: UIMessage[],\n toolPartLocations: UIToolPartLocations,\n): string {\n if (content.toolName !== undefined) {\n return content.toolName;\n }\n\n const location = findToolPartLocation(content.id, content.callId, toolPartLocations);\n const part =\n location === undefined\n ? undefined\n : uiMessages[location.messageIndex]?.parts[location.partIndex];\n return part?.type === \"tool\" ? part.toolName : \"tool\";\n}\n\nfunction textFromUIParts(parts: UIMessagePart[]): string {\n return parts.flatMap((part) => (part.type === \"text\" ? [part.text] : [])).join(\"\");\n}\n\nfunction outputToToolResultContent(output: JsonValue | undefined): ToolResultContent[] {\n return [{ type: \"text\", text: serializeToolResultOutput(output ?? null) }];\n}\n\nfunction attachmentToUserContent(attachment: UIAttachment): UserContentType {\n if (attachment.type === \"image\" || isImageFileAttachment(attachment)) {\n if (attachment.url !== undefined) {\n return UserContent.imageUrl(attachment.url, imageOptions(attachment));\n }\n if (attachment.data !== undefined && attachment.mediaType !== undefined) {\n return UserContent.imageBase64(\n attachment.data,\n attachment.mediaType,\n imageOptions(attachment),\n );\n }\n throw new TypeError(\"Image attachments require a url or base64 data with mediaType.\");\n }\n\n if (attachment.text !== undefined) {\n const source: Extract<DocumentContent[\"source\"], { type: \"text\" }> = {\n type: \"text\",\n text: attachment.text,\n };\n if (attachment.mediaType !== undefined) {\n source.mediaType = attachment.mediaType;\n }\n if (attachment.name !== undefined) {\n source.filename = attachment.name;\n }\n return {\n type: \"document\",\n source,\n };\n }\n\n const mediaType = attachment.mediaType ?? \"application/octet-stream\";\n if (attachment.url !== undefined) {\n return UserContent.documentUrl(attachment.url, mediaType, documentOptions(attachment));\n }\n if (attachment.data !== undefined) {\n return UserContent.documentBase64(attachment.data, mediaType, documentOptions(attachment));\n }\n\n throw new TypeError(\"Document attachments require a url, base64 data, or text.\");\n}\n\nfunction userContentToAttachment(content: ImageContent | DocumentContent): UIAttachment {\n if (content.type === \"image\") {\n const attachment: UIAttachment = {\n id: createId(\"attachment\"),\n type: \"image\",\n };\n if (content.detail !== undefined) {\n attachment.detail = content.detail;\n }\n if (content.source.type === \"url\") {\n attachment.url = content.source.url;\n } else {\n attachment.data = content.source.data;\n attachment.mediaType = content.source.mediaType;\n }\n return attachment;\n }\n\n const attachment: UIAttachment = {\n id: createId(\"attachment\"),\n type: \"document\",\n };\n if (content.source.type === \"url\") {\n attachment.url = content.source.url;\n attachment.mediaType = content.source.mediaType;\n if (content.source.filename !== undefined) {\n attachment.name = content.source.filename;\n }\n } else if (content.source.type === \"base64\") {\n attachment.data = content.source.data;\n attachment.mediaType = content.source.mediaType;\n if (content.source.filename !== undefined) {\n attachment.name = content.source.filename;\n }\n } else {\n attachment.text = content.source.text;\n if (content.source.mediaType !== undefined) {\n attachment.mediaType = content.source.mediaType;\n }\n if (content.source.filename !== undefined) {\n attachment.name = content.source.filename;\n }\n }\n return attachment;\n}\n\nfunction isImageFileAttachment(attachment: UIAttachment): boolean {\n return attachment.type === \"file\" && attachment.mediaType?.startsWith(\"image/\") === true;\n}\n\nfunction imageOptions(attachment: UIAttachment): { detail?: ImageDetail } {\n return attachment.detail === undefined ? {} : { detail: attachment.detail };\n}\n\nfunction documentOptions(attachment: UIAttachment): { filename?: string } {\n return attachment.name === undefined ? {} : { filename: attachment.name };\n}\n\nfunction toolResultContentToJson(content: ToolResultContent[]): JsonValue {\n if (content.length === 1 && content[0]?.type === \"text\") {\n return content[0].text;\n }\n return content as JsonValue;\n}\n\nfunction isUserContent(value: unknown): value is UserContentType {\n if (!isRecord(value)) {\n return false;\n }\n\n if (value.type === \"text\") {\n return typeof value.text === \"string\";\n }\n\n if (value.type === \"image\") {\n return isImageContent(value);\n }\n\n if (value.type === \"document\") {\n return isDocumentContent(value);\n }\n\n return false;\n}\n\nfunction isImageContent(value: Record<string, unknown>): boolean {\n if (!isRecord(value.source)) {\n return false;\n }\n\n if (value.source.type === \"url\") {\n return typeof value.source.url === \"string\";\n }\n\n if (value.source.type === \"base64\") {\n return typeof value.source.data === \"string\" && typeof value.source.mediaType === \"string\";\n }\n\n return false;\n}\n\nfunction isDocumentContent(value: Record<string, unknown>): boolean {\n if (!isRecord(value.source)) {\n return false;\n }\n\n if (value.source.type === \"url\") {\n return typeof value.source.url === \"string\" && typeof value.source.mediaType === \"string\";\n }\n\n if (value.source.type === \"base64\") {\n return typeof value.source.data === \"string\" && typeof value.source.mediaType === \"string\";\n }\n\n if (value.source.type === \"text\") {\n return (\n typeof value.source.text === \"string\" &&\n (value.source.mediaType === undefined || typeof value.source.mediaType === \"string\")\n );\n }\n\n return false;\n}\n\nfunction toolPartId(toolCallId: string): string {\n return `tool_${toolCallId}`;\n}\n\nlet nextId = 0;\n\nfunction createId(prefix: string): string {\n const random = globalThis.crypto?.randomUUID?.();\n if (random !== undefined) {\n return `${prefix}_${random}`;\n }\n nextId += 1;\n return `${prefix}_${nextId.toString(36)}`;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n"],"mappings":";;;;;;;;;;;AA8BO,SAAS,yBAAyB,UAAsC;AAC7E,QAAM,eAA8B,CAAC;AAErC,aAAW,WAAW,UAAU;AAC9B,UAAM,OAAO,gBAAgB,QAAQ,KAAK;AAE1C,QAAI,QAAQ,SAAS,UAAU;AAC7B,UAAI,KAAK,SAAS,GAAG;AACnB,qBAAa,KAAK,QAAQ,OAAO,MAAM,gBAAgB,QAAQ,QAAQ,CAAC,CAAC;AAAA,MAC3E;AACA;AAAA,IACF;AAEA,QAAI,QAAQ,SAAS,QAAQ;AAC3B,YAAM,UAA6B,CAAC;AACpC,iBAAW,QAAQ,QAAQ,OAAO;AAChC,YAAI,KAAK,SAAS,QAAQ;AACxB,kBAAQ,KAAK,YAAY,KAAK,KAAK,IAAI,CAAC;AACxC;AAAA,QACF;AACA,YAAI,KAAK,SAAS,cAAc;AAC9B,kBAAQ,KAAK,wBAAwB,KAAK,UAAU,CAAC;AACrD;AAAA,QACF;AACA,YAAI,KAAK,SAAS,UAAU,cAAc,KAAK,IAAI,GAAG;AACpD,kBAAQ,KAAK,KAAK,IAAI;AACtB;AAAA,QACF;AACA,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AACA,UAAI,QAAQ,SAAS,GAAG;AACtB,qBAAa,KAAK,QAAQ,KAAK,SAAS,gBAAgB,QAAQ,QAAQ,CAAC,CAAC;AAAA,MAC5E;AACA;AAAA,IACF;AAEA,QAAI,QAAQ,SAAS,aAAa;AAChC,YAAM,UAAkC,CAAC;AACzC,YAAMA,eAAiC,CAAC;AACxC,iBAAW,QAAQ,QAAQ,OAAO;A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AAM,OAAO,cAAc;AAAA,EACpF;AAEA,MAAI,MAAM,OAAO,SAAS,QAAQ;AAChC,WACE,OAAO,MAAM,OAAO,SAAS,aAC5B,MAAM,OAAO,cAAc,UAAa,OAAO,MAAM,OAAO,cAAc;AAAA,EAE/E;AAEA,SAAO;AACT;AAEA,SAAS,WAAW,YAA4B;AAC9C,SAAO,QAAQ,UAAU;AAC3B;AAEA,IAAI,SAAS;AAEb,SAAS,SAAS,QAAwB;AACxC,QAAM,SAAS,WAAW,QAAQ,aAAa;AAC/C,MAAI,WAAW,QAAW;AACxB,WAAO,GAAG,MAAM,IAAI,MAAM;AAAA,EAC5B;AACA,YAAU;AACV,SAAO,GAAG,MAAM,IAAI,OAAO,SAAS,EAAE,CAAC;AACzC;AAEA,SAAS,SAAS,OAAkD;AAClE,SAAO,OAAO,UAAU,YAAY,UAAU;AAChD;","names":["toolResults","parts","attachment"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveRetryOptions,
|
|
3
|
+
runWithRetries
|
|
4
|
+
} from "./chunk-A3UBYTJT.js";
|
|
5
|
+
|
|
6
|
+
// src/image-generation/generate-image.ts
|
|
7
|
+
function generateImage(prompt, options) {
|
|
8
|
+
assertNonEmptyString(prompt, "Image prompt");
|
|
9
|
+
const width = options.width ?? 1024;
|
|
10
|
+
const height = options.height ?? 1024;
|
|
11
|
+
assertPositiveInteger(width, "Image width");
|
|
12
|
+
assertPositiveInteger(height, "Image height");
|
|
13
|
+
const request = { prompt, width, height };
|
|
14
|
+
if (options.additionalParams !== void 0) {
|
|
15
|
+
request.additionalParams = options.additionalParams;
|
|
16
|
+
}
|
|
17
|
+
const retries = options.retries === void 0 ? void 0 : resolveRetryOptions(options.retries);
|
|
18
|
+
return runWithRetries(
|
|
19
|
+
() => options.model.imageGeneration(request),
|
|
20
|
+
retries,
|
|
21
|
+
{ streaming: false }
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
function assertNonEmptyString(value, name) {
|
|
25
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
26
|
+
throw new TypeError(`${name} must be a non-empty string.`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function assertPositiveInteger(value, name) {
|
|
30
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
31
|
+
throw new RangeError(`${name} must be a positive integer.`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
generateImage
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=chunk-XDRSPSR7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/image-generation/generate-image.ts"],"sourcesContent":["import type { JsonValue } from \"../completion/types\";\nimport { type RetryOptions, resolveRetryOptions, runWithRetries } from \"../retry\";\nimport type { ImageGenerationModel, ImageGenerationRequest } from \"./types\";\n\nexport type GenerateImageOptions<Model extends ImageGenerationModel = ImageGenerationModel> = {\n model: Model;\n width?: number | undefined;\n height?: number | undefined;\n additionalParams?: JsonValue | undefined;\n retries?: RetryOptions | undefined;\n};\n\nexport function generateImage<Model extends ImageGenerationModel>(\n prompt: string,\n options: GenerateImageOptions<Model>,\n): Promise<Awaited<ReturnType<Model[\"imageGeneration\"]>>> {\n assertNonEmptyString(prompt, \"Image prompt\");\n const width = options.width ?? 1024;\n const height = options.height ?? 1024;\n assertPositiveInteger(width, \"Image width\");\n assertPositiveInteger(height, \"Image height\");\n\n const request: ImageGenerationRequest = { prompt, width, height };\n if (options.additionalParams !== undefined) {\n request.additionalParams = options.additionalParams;\n }\n const retries = options.retries === undefined ? undefined : resolveRetryOptions(options.retries);\n return runWithRetries<Awaited<ReturnType<Model[\"imageGeneration\"]>>>(\n () =>\n options.model.imageGeneration(request) as Promise<\n Awaited<ReturnType<Model[\"imageGeneration\"]>>\n >,\n retries,\n { streaming: false },\n );\n}\n\nfunction assertNonEmptyString(value: string, name: string): void {\n if (typeof value !== \"string\" || value.trim().length === 0) {\n throw new TypeError(`${name} must be a non-empty string.`);\n }\n}\n\nfunction assertPositiveInteger(value: number, name: string): void {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new RangeError(`${name} must be a positive integer.`);\n }\n}\n"],"mappings":";;;;;;AAYO,SAAS,cACd,QACA,SACwD;AACxD,uBAAqB,QAAQ,cAAc;AAC3C,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,SAAS,QAAQ,UAAU;AACjC,wBAAsB,OAAO,aAAa;AAC1C,wBAAsB,QAAQ,cAAc;AAE5C,QAAM,UAAkC,EAAE,QAAQ,OAAO,OAAO;AAChE,MAAI,QAAQ,qBAAqB,QAAW;AAC1C,YAAQ,mBAAmB,QAAQ;AAAA,EACrC;AACA,QAAM,UAAU,QAAQ,YAAY,SAAY,SAAY,oBAAoB,QAAQ,OAAO;AAC/F,SAAO;AAAA,IACL,MACE,QAAQ,MAAM,gBAAgB,OAAO;AAAA,IAGvC;AAAA,IACA,EAAE,WAAW,MAAM;AAAA,EACrB;AACF;AAEA,SAAS,qBAAqB,OAAe,MAAoB;AAC/D,MAAI,OAAO,UAAU,YAAY,MAAM,KAAK,EAAE,WAAW,GAAG;AAC1D,UAAM,IAAI,UAAU,GAAG,IAAI,8BAA8B;AAAA,EAC3D;AACF;AAEA,SAAS,sBAAsB,OAAe,MAAoB;AAChE,MAAI,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,GAAG;AAC7C,UAAM,IAAI,WAAW,GAAG,IAAI,8BAA8B;AAAA,EAC5D;AACF;","names":[]}
|
|
@@ -1,42 +1,11 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export { R as RetryContext, a as RetryOptions } from '../retry-D3Ruy-ba.js';
|
|
2
|
+
export { C as CreateCompletionBaseOptions, a as CreateCompletionInput, b as CreateCompletionOptions, c as CreateCompletionResult, d as CreateCompletionStreamOptions, e as CreateParsedCompletionOptions, f as CreateParsedCompletionResult, g as createCompletion, h as createCompletionStream, i as createParsedCompletion, j as isJsonValue, k as isStreamingCompletionModel } from '../json-Zo7K3xmt.js';
|
|
3
|
+
import { D as Document, M as Message } from '../types-B3A4YxaA.js';
|
|
4
|
+
export { A as AssistantContent, a as AssistantGenerationMetadata, b as AssistantMessage, c as AssistantMessageOptions, H as CompletionCapabilityError, C as CompletionModel, K as CompletionModelCapabilities, d as CompletionModelInfo, e as CompletionModelMetadataOptions, f as CompletionRequest, g as CompletionResponse, h as CompletionSource, L as CompletionStreamEvent, i as CompletionTool, j as ContextUsage, N as DocumentContent, I as ImageContent, O as ImageDetail, J as JsonObject, k as JsonPrimitive, l as JsonValue, m as MessageOptions, n as ModelContextLimits, P as ProviderTool, o as ProviderToolCall, R as Reasoning, Q as ReasoningContent, V as ReasoningContentType, W as StreamingCompletionModel, S as SystemMessage, T as Text, p as ToolCall, X as ToolCallArgumentsMode, Y as ToolChoice, q as ToolContent, r as ToolDefinition, Z as ToolFunction, s as ToolMessage, t as ToolResult, u as ToolResultContent, v as ToolResultMessageOptions, w as ToolResultOptions, U as Usage, _ as UsageDetails, x as UserContent, y as UserMessage, $ as assertCompletionRequestSupported, z as calculateContextUsage, B as getAssistantGenerationMetadata, E as isProviderTool, a0 as isToolResultContentArray, a1 as reasoningDisplayText, F as resolveCompletionModelInfo, a2 as serializeToolResultOutput, a3 as textFromAssistantContent, G as withContextUsage } from '../types-B3A4YxaA.js';
|
|
4
5
|
import '../zod-schema-C7F4clpm.js';
|
|
5
6
|
import 'zod';
|
|
6
7
|
|
|
7
8
|
declare function normalizeDocuments(documents: Document[]): Message | undefined;
|
|
8
9
|
declare function formatDocument(document: Document): string;
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
type RawResponseOf<M extends CompletionModel> = M extends CompletionModel<infer RawResponse, infer _ModelName> ? RawResponse : unknown;
|
|
12
|
-
declare class CompletionRequestBuilder<M extends CompletionModel = CompletionModel> {
|
|
13
|
-
private readonly model;
|
|
14
|
-
private readonly promptMessage;
|
|
15
|
-
private requestModel;
|
|
16
|
-
private instructionBlocks;
|
|
17
|
-
private history;
|
|
18
|
-
private docs;
|
|
19
|
-
private toolDefs;
|
|
20
|
-
private providerToolDefs;
|
|
21
|
-
private temp;
|
|
22
|
-
private maxTokenCount;
|
|
23
|
-
private choice;
|
|
24
|
-
private params;
|
|
25
|
-
private schema;
|
|
26
|
-
constructor(model: M, promptMessage: Message);
|
|
27
|
-
modelOverride(model: ModelNameOf<M> | undefined): this;
|
|
28
|
-
instructions(instructions: string | undefined): this;
|
|
29
|
-
messages(messages: Message[]): this;
|
|
30
|
-
documents(documents: Document[]): this;
|
|
31
|
-
tools(tools: CompletionTool[]): this;
|
|
32
|
-
temperature(temperature: number | undefined): this;
|
|
33
|
-
maxTokens(maxTokens: number | undefined): this;
|
|
34
|
-
toolChoice(toolChoice: ToolChoice | undefined): this;
|
|
35
|
-
additionalParams(additionalParams: JsonValue | undefined): this;
|
|
36
|
-
outputSchema(outputSchema: JsonObject | undefined): this;
|
|
37
|
-
build(): CompletionRequest<ModelNameOf<M>>;
|
|
38
|
-
send(): Promise<CompletionResponse<RawResponseOf<M>>>;
|
|
39
|
-
private buildInstructions;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { CompletionModel, CompletionRequest, CompletionRequestBuilder, CompletionResponse, CompletionTool, Document, JsonObject, JsonValue, Message, ToolChoice, formatDocument, normalizeDocuments };
|
|
11
|
+
export { Document, Message, formatDocument, normalizeDocuments };
|
package/dist/completion/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CompletionRequestBuilder,
|
|
3
2
|
formatDocument,
|
|
4
3
|
normalizeDocuments
|
|
5
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-I6G7BC42.js";
|
|
6
5
|
import {
|
|
7
6
|
createCompletion,
|
|
8
7
|
createCompletionStream,
|
|
9
8
|
createParsedCompletion,
|
|
10
9
|
isStreamingCompletionModel
|
|
11
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-M3IOWB4Y.js";
|
|
11
|
+
import "../chunk-RFDVKCIE.js";
|
|
12
12
|
import {
|
|
13
13
|
AssistantContent,
|
|
14
14
|
CompletionCapabilityError,
|
|
@@ -28,11 +28,10 @@ import {
|
|
|
28
28
|
textFromAssistantContent,
|
|
29
29
|
withContextUsage
|
|
30
30
|
} from "../chunk-ADH7NNCS.js";
|
|
31
|
-
import "../chunk-
|
|
31
|
+
import "../chunk-A3UBYTJT.js";
|
|
32
32
|
export {
|
|
33
33
|
AssistantContent,
|
|
34
34
|
CompletionCapabilityError,
|
|
35
|
-
CompletionRequestBuilder,
|
|
36
35
|
Message,
|
|
37
36
|
ToolContent,
|
|
38
37
|
Usage,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { r as ToolDefinition } from './types-B3A4YxaA.js';
|
|
2
|
+
import { V as VectorMetadata, E as EmbeddingModel, a as EmbeddedDocument } from './types-p55Jc-sr.js';
|
|
3
|
+
import { A as AnyTool } from './tool-C_8GudXn.js';
|
|
4
|
+
import { V as VectorSearchIndex, a as VectorFilter } from './types-DT3nEemY.js';
|
|
5
|
+
|
|
6
|
+
type ToolSearchDocument<Metadata extends VectorMetadata = VectorMetadata> = {
|
|
7
|
+
toolName: string;
|
|
8
|
+
definition: ToolDefinition;
|
|
9
|
+
text: string;
|
|
10
|
+
metadata?: Metadata | undefined;
|
|
11
|
+
};
|
|
12
|
+
type EmbedToolsOptions<Metadata extends VectorMetadata = VectorMetadata> = {
|
|
13
|
+
content?: ((tool: AnyTool, definition: ToolDefinition) => string | string[]) | undefined;
|
|
14
|
+
metadata?: ((tool: AnyTool, definition: ToolDefinition) => Metadata | undefined) | undefined;
|
|
15
|
+
concurrency?: number | undefined;
|
|
16
|
+
};
|
|
17
|
+
type CreateToolIndexOptions<Metadata extends VectorMetadata = VectorMetadata> = EmbedToolsOptions<Metadata> & {
|
|
18
|
+
topK: number;
|
|
19
|
+
threshold?: number | undefined;
|
|
20
|
+
filter?: VectorFilter | undefined;
|
|
21
|
+
};
|
|
22
|
+
interface ToolIndex<Metadata extends VectorMetadata = VectorMetadata> extends VectorSearchIndex<ToolSearchDocument<Metadata>, Metadata> {
|
|
23
|
+
readonly kind: "tool-index";
|
|
24
|
+
readonly tools: readonly AnyTool[];
|
|
25
|
+
readonly topK: number;
|
|
26
|
+
readonly threshold?: number | undefined;
|
|
27
|
+
readonly filter?: VectorFilter | undefined;
|
|
28
|
+
}
|
|
29
|
+
declare function embedTools<Metadata extends VectorMetadata = VectorMetadata>(model: EmbeddingModel, tools: readonly AnyTool[], options?: EmbedToolsOptions<Metadata>): Promise<Array<EmbeddedDocument<ToolSearchDocument<Metadata>, Metadata>>>;
|
|
30
|
+
declare function createToolIndex<Metadata extends VectorMetadata = VectorMetadata>(model: EmbeddingModel, tools: readonly AnyTool[], options: CreateToolIndexOptions<Metadata>): Promise<ToolIndex<Metadata>>;
|
|
31
|
+
declare function isToolIndex(value: unknown): value is ToolIndex;
|
|
32
|
+
|
|
33
|
+
export { type CreateToolIndexOptions as C, type EmbedToolsOptions as E, type ToolIndex as T, type ToolSearchDocument as a, createToolIndex as c, embedTools as e, isToolIndex as i };
|