@x12i/ai 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +515 -24
- package/dist/chunk-RP5SPJKM.js +1179 -0
- package/dist/chunk-RP5SPJKM.js.map +1 -0
- package/dist/index.d.ts +273 -72
- package/dist/index.js +510 -9
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +906 -0
- package/dist/react.js +3067 -0
- package/dist/react.js.map +1 -0
- package/dist/stream-C2tzoSII.d.ts +482 -0
- package/dist/styles.css +1225 -0
- package/package.json +48 -4
package/dist/index.js
CHANGED
|
@@ -1,13 +1,514 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
SAFE_IMAGE_PROTOCOLS,
|
|
3
|
+
SAFE_LINK_PROTOCOLS,
|
|
4
|
+
applyStreamEvent,
|
|
5
|
+
applyStreamEvents,
|
|
6
|
+
citedNumbers,
|
|
7
|
+
createAbortableStream,
|
|
8
|
+
createThreadState,
|
|
9
|
+
errorEvent,
|
|
10
|
+
findToolCall,
|
|
11
|
+
formatBytes,
|
|
12
|
+
formatDuration,
|
|
13
|
+
formatTokenCount,
|
|
14
|
+
formatUsage,
|
|
15
|
+
getBranchInfo,
|
|
16
|
+
getBranchInfoMap,
|
|
17
|
+
getUrlHostname,
|
|
18
|
+
isAbortError,
|
|
19
|
+
isBusy,
|
|
20
|
+
isExternalUrl,
|
|
21
|
+
isSafeUrl,
|
|
22
|
+
isStreaming,
|
|
23
|
+
isTerminalStreamEvent,
|
|
24
|
+
isTerminalToolState,
|
|
25
|
+
lastMessageWithRole,
|
|
26
|
+
lastUserMessage,
|
|
27
|
+
markdownToPlainText,
|
|
28
|
+
mergeUsage,
|
|
29
|
+
messageData,
|
|
30
|
+
messageFiles,
|
|
31
|
+
messageReasoning,
|
|
32
|
+
messageSources,
|
|
33
|
+
messageText,
|
|
34
|
+
messageToolCalls,
|
|
35
|
+
parseCitations,
|
|
36
|
+
pendingApprovals,
|
|
37
|
+
sanitizeImageUrl,
|
|
38
|
+
sanitizeUrl,
|
|
39
|
+
splitCompletedSentences,
|
|
40
|
+
splitMarkdownBlocks,
|
|
41
|
+
streamEventToAction,
|
|
42
|
+
threadPendingApprovals,
|
|
43
|
+
threadReducer,
|
|
44
|
+
toThreadError,
|
|
45
|
+
totalTokens
|
|
46
|
+
} from "./chunk-RP5SPJKM.js";
|
|
47
|
+
|
|
48
|
+
// src/adapters.ts
|
|
49
|
+
function isRecord(value) {
|
|
50
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
51
|
+
}
|
|
52
|
+
function str(value) {
|
|
53
|
+
return typeof value === "string" ? value : void 0;
|
|
54
|
+
}
|
|
55
|
+
function num(value) {
|
|
56
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
57
|
+
}
|
|
58
|
+
function parseMaybeJson(value) {
|
|
59
|
+
const trimmed = value.trim();
|
|
60
|
+
if (trimmed === "") return value;
|
|
61
|
+
try {
|
|
62
|
+
return JSON.parse(trimmed);
|
|
63
|
+
} catch {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function toIso(value) {
|
|
68
|
+
if (value === void 0 || value === null) return void 0;
|
|
69
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
70
|
+
return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
|
|
71
|
+
}
|
|
72
|
+
function mediaTypeOfDataUrl(url) {
|
|
73
|
+
return /^data:([^;,]+)[;,]/i.exec(url)?.[1];
|
|
74
|
+
}
|
|
75
|
+
function addUniqueSource(parts, source) {
|
|
76
|
+
if (parts.some((part) => part.type === "source" && (part.id === source.id || source.url !== "" && part.url === source.url))) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
parts.push(source);
|
|
80
|
+
}
|
|
81
|
+
function makeId(prefix, index, explicit) {
|
|
82
|
+
return str(explicit) && str(explicit) !== "" ? str(explicit) : `${prefix ?? "msg-"}${index + 1}`;
|
|
83
|
+
}
|
|
84
|
+
function aiSdkToolState(state, approved) {
|
|
85
|
+
switch (state) {
|
|
86
|
+
case "input-streaming":
|
|
87
|
+
case "partial-call":
|
|
88
|
+
return "queued";
|
|
89
|
+
case "input-available":
|
|
90
|
+
case "call":
|
|
91
|
+
return "running";
|
|
92
|
+
case "approval-requested":
|
|
93
|
+
return "needs-approval";
|
|
94
|
+
case "approval-responded":
|
|
95
|
+
return approved === false ? "denied" : "approved";
|
|
96
|
+
case "output-available":
|
|
97
|
+
case "result":
|
|
98
|
+
return "succeeded";
|
|
99
|
+
case "output-error":
|
|
100
|
+
return "failed";
|
|
101
|
+
case "output-denied":
|
|
102
|
+
return "denied";
|
|
103
|
+
default:
|
|
104
|
+
return "running";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function aiSdkTool(source, name, id) {
|
|
108
|
+
const approval = isRecord(source.approval) ? source.approval : void 0;
|
|
109
|
+
const state = aiSdkToolState(source.state, approval?.approved);
|
|
110
|
+
const part = { type: "tool", id, name, state };
|
|
111
|
+
const input = source.input ?? source.args;
|
|
112
|
+
const output = source.output ?? source.result;
|
|
113
|
+
if (input !== void 0) part.input = input;
|
|
114
|
+
if (output !== void 0) part.output = output;
|
|
115
|
+
const error = str(source.errorText);
|
|
116
|
+
if (error !== void 0) part.error = error;
|
|
117
|
+
const reason = approval ? str(approval.reason) : void 0;
|
|
118
|
+
if (reason !== void 0) part.approval = { reason };
|
|
119
|
+
return part;
|
|
4
120
|
}
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
121
|
+
function aiSdkPart(part, index) {
|
|
122
|
+
const type = part.type;
|
|
123
|
+
if (type === "text") {
|
|
124
|
+
const text = str(part.text);
|
|
125
|
+
return text === void 0 || text === "" ? null : { type: "text", text };
|
|
126
|
+
}
|
|
127
|
+
if (type === "reasoning") {
|
|
128
|
+
const text = str(part.text) ?? str(part.reasoning);
|
|
129
|
+
return text === void 0 ? null : { type: "reasoning", text };
|
|
130
|
+
}
|
|
131
|
+
if (type === "dynamic-tool") {
|
|
132
|
+
const id = str(part.toolCallId) ?? `tool-${index + 1}`;
|
|
133
|
+
return aiSdkTool(part, str(part.toolName) ?? "tool", id);
|
|
134
|
+
}
|
|
135
|
+
if (type.startsWith("tool-") && type !== "tool-invocation") {
|
|
136
|
+
const id = str(part.toolCallId) ?? `tool-${index + 1}`;
|
|
137
|
+
return aiSdkTool(part, type.slice("tool-".length), id);
|
|
138
|
+
}
|
|
139
|
+
if (type === "tool-invocation" && isRecord(part.toolInvocation)) {
|
|
140
|
+
const invocation = part.toolInvocation;
|
|
141
|
+
const id = str(invocation.toolCallId) ?? `tool-${index + 1}`;
|
|
142
|
+
return aiSdkTool(invocation, str(invocation.toolName) ?? "tool", id);
|
|
143
|
+
}
|
|
144
|
+
if (type === "source-url") {
|
|
145
|
+
const url = str(part.url);
|
|
146
|
+
if (url === void 0) return null;
|
|
147
|
+
return { type: "source", id: str(part.sourceId) ?? url, title: str(part.title) ?? url, url };
|
|
148
|
+
}
|
|
149
|
+
if (type === "source-document") {
|
|
150
|
+
const title = str(part.title) ?? str(part.filename) ?? str(part.sourceId) ?? `source-${index + 1}`;
|
|
151
|
+
return { type: "source", id: str(part.sourceId) ?? `source-${index + 1}`, title, url: "" };
|
|
152
|
+
}
|
|
153
|
+
if (type === "source" && isRecord(part.source)) {
|
|
154
|
+
const url = str(part.source.url);
|
|
155
|
+
if (url === void 0) return null;
|
|
156
|
+
return { type: "source", id: str(part.source.id) ?? url, title: str(part.source.title) ?? url, url };
|
|
157
|
+
}
|
|
158
|
+
if (type === "file") {
|
|
159
|
+
const mediaType = str(part.mediaType) ?? str(part.mimeType) ?? "application/octet-stream";
|
|
160
|
+
const data = str(part.data);
|
|
161
|
+
const url = str(part.url) ?? (data === void 0 ? void 0 : `data:${mediaType};base64,${data}`);
|
|
162
|
+
if (url === void 0) return null;
|
|
163
|
+
const file = { type: "file", name: str(part.filename) ?? "file", mediaType, url };
|
|
164
|
+
return file;
|
|
165
|
+
}
|
|
166
|
+
if (type.startsWith("data-")) {
|
|
167
|
+
return { type: "data", kind: type.slice("data-".length), data: part.data };
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
function aiSdkStreaming(parts) {
|
|
172
|
+
return parts.some(
|
|
173
|
+
(part) => (part.type === "text" || part.type === "reasoning") && part.state === "streaming" || part.state === "input-streaming"
|
|
8
174
|
);
|
|
9
175
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
176
|
+
function fromAiSdkMessages(messages, options = {}) {
|
|
177
|
+
const result = [];
|
|
178
|
+
messages.forEach((source, index) => {
|
|
179
|
+
if (!isRecord(source)) return;
|
|
180
|
+
const role = source.role === "user" || source.role === "assistant" || source.role === "system" ? source.role : null;
|
|
181
|
+
if (role === null) return;
|
|
182
|
+
const sourceParts = Array.isArray(source.parts) ? source.parts : typeof source.content === "string" && source.content !== "" ? [{ type: "text", text: source.content }] : [];
|
|
183
|
+
const parts = [];
|
|
184
|
+
sourceParts.forEach((part, partIndex) => {
|
|
185
|
+
if (!isRecord(part) || typeof part.type !== "string") return;
|
|
186
|
+
const mapped = aiSdkPart(part, partIndex);
|
|
187
|
+
if (!mapped) return;
|
|
188
|
+
if (mapped.type === "source") addUniqueSource(parts, mapped);
|
|
189
|
+
else parts.push(mapped);
|
|
190
|
+
});
|
|
191
|
+
const metadata = isRecord(source.metadata) ? source.metadata : void 0;
|
|
192
|
+
const message = {
|
|
193
|
+
id: makeId(options.idPrefix, index, source.id),
|
|
194
|
+
role,
|
|
195
|
+
parts
|
|
196
|
+
};
|
|
197
|
+
if (role === "assistant") message.status = aiSdkStreaming(sourceParts) ? "streaming" : "complete";
|
|
198
|
+
const createdAt = toIso(source.createdAt) ?? toIso(metadata?.createdAt);
|
|
199
|
+
if (createdAt !== void 0) message.createdAt = createdAt;
|
|
200
|
+
if (metadata !== void 0) message.metadata = { ...metadata };
|
|
201
|
+
result.push(message);
|
|
202
|
+
});
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
function openAiContentParts(content) {
|
|
206
|
+
if (typeof content === "string") return content === "" ? [] : [{ type: "text", text: content }];
|
|
207
|
+
if (!Array.isArray(content)) return [];
|
|
208
|
+
const parts = [];
|
|
209
|
+
content.forEach((entry, index) => {
|
|
210
|
+
if (!isRecord(entry)) return;
|
|
211
|
+
if (entry.type === "text" || entry.type === "input_text" || entry.type === "output_text") {
|
|
212
|
+
const text = str(entry.text);
|
|
213
|
+
if (text) parts.push({ type: "text", text });
|
|
214
|
+
} else if (entry.type === "image_url" || entry.type === "input_image") {
|
|
215
|
+
const raw = entry.image_url;
|
|
216
|
+
const url = typeof raw === "string" ? raw : isRecord(raw) ? str(raw.url) : void 0;
|
|
217
|
+
if (url) {
|
|
218
|
+
parts.push({
|
|
219
|
+
type: "file",
|
|
220
|
+
name: `image-${index + 1}`,
|
|
221
|
+
mediaType: mediaTypeOfDataUrl(url) ?? "image/*",
|
|
222
|
+
url
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
} else if (entry.type === "file" && isRecord(entry.file)) {
|
|
226
|
+
const url = str(entry.file.file_data);
|
|
227
|
+
if (url) {
|
|
228
|
+
parts.push({
|
|
229
|
+
type: "file",
|
|
230
|
+
name: str(entry.file.filename) ?? "file",
|
|
231
|
+
mediaType: mediaTypeOfDataUrl(url) ?? "application/octet-stream",
|
|
232
|
+
url
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
return parts;
|
|
238
|
+
}
|
|
239
|
+
function fromOpenAIChatMessages(messages, options = {}) {
|
|
240
|
+
const result = [];
|
|
241
|
+
const calls = /* @__PURE__ */ new Map();
|
|
242
|
+
messages.forEach((source, index) => {
|
|
243
|
+
if (!isRecord(source)) return;
|
|
244
|
+
const id = makeId(options.idPrefix, index, source.id);
|
|
245
|
+
if (source.role === "tool" || source.role === "function") {
|
|
246
|
+
const callId = str(source.tool_call_id) ?? (source.role === "function" ? `fn-${index + 1}` : `tool-${index + 1}`);
|
|
247
|
+
const raw = typeof source.content === "string" ? source.content : openAiContentParts(source.content).map((p) => p.type === "text" ? p.text : "").join("");
|
|
248
|
+
const output = parseMaybeJson(raw);
|
|
249
|
+
const call = calls.get(callId);
|
|
250
|
+
if (call) {
|
|
251
|
+
call.state = "succeeded";
|
|
252
|
+
call.output = output;
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
result.push({
|
|
256
|
+
id,
|
|
257
|
+
role: "tool",
|
|
258
|
+
parts: [{ type: "tool", id: callId, name: str(source.name) ?? "tool", state: "succeeded", output }],
|
|
259
|
+
status: "complete"
|
|
260
|
+
});
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const role = source.role === "user" ? "user" : source.role === "assistant" ? "assistant" : source.role === "system" || source.role === "developer" ? "system" : null;
|
|
264
|
+
if (role === null) return;
|
|
265
|
+
const parts = [];
|
|
266
|
+
const reasoning = str(source.reasoning_content);
|
|
267
|
+
if (reasoning) parts.push({ type: "reasoning", text: reasoning });
|
|
268
|
+
parts.push(...openAiContentParts(source.content));
|
|
269
|
+
const refusal = str(source.refusal);
|
|
270
|
+
if (refusal) parts.push({ type: "text", text: refusal });
|
|
271
|
+
if (role === "assistant" && Array.isArray(source.tool_calls)) {
|
|
272
|
+
source.tool_calls.forEach((call, callIndex) => {
|
|
273
|
+
if (!isRecord(call)) return;
|
|
274
|
+
const callId = str(call.id) ?? `${id}-call-${callIndex + 1}`;
|
|
275
|
+
const fn = isRecord(call.function) ? call.function : {};
|
|
276
|
+
const args = str(fn.arguments);
|
|
277
|
+
const part = { type: "tool", id: callId, name: str(fn.name) ?? "tool", state: "running" };
|
|
278
|
+
if (args !== void 0 && args !== "") part.input = parseMaybeJson(args);
|
|
279
|
+
parts.push(part);
|
|
280
|
+
calls.set(callId, part);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
const message = { id, role, parts };
|
|
284
|
+
if (role === "assistant") message.status = "complete";
|
|
285
|
+
result.push(message);
|
|
286
|
+
});
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
function anthropicToolResultOutput(content) {
|
|
290
|
+
if (typeof content === "string") return parseMaybeJson(content);
|
|
291
|
+
if (!Array.isArray(content)) return content;
|
|
292
|
+
const texts = content.filter((block) => isRecord(block) && block.type === "text" && typeof block.text === "string").map((block) => block.text);
|
|
293
|
+
if (texts.length === content.length) return parseMaybeJson(texts.join("\n"));
|
|
294
|
+
return content;
|
|
295
|
+
}
|
|
296
|
+
function anthropicMedia(source, fallbackName) {
|
|
297
|
+
if (!isRecord(source)) return null;
|
|
298
|
+
if (source.type === "base64") {
|
|
299
|
+
const mediaType = str(source.media_type) ?? "application/octet-stream";
|
|
300
|
+
const data = str(source.data);
|
|
301
|
+
return data === void 0 ? null : { type: "file", name: fallbackName, mediaType, url: `data:${mediaType};base64,${data}` };
|
|
302
|
+
}
|
|
303
|
+
if (source.type === "url") {
|
|
304
|
+
const url = str(source.url);
|
|
305
|
+
return url === void 0 ? null : { type: "file", name: fallbackName, mediaType: mediaTypeOfDataUrl(url) ?? "application/octet-stream", url };
|
|
306
|
+
}
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
function fromAnthropicMessages(messages, options = {}) {
|
|
310
|
+
const result = [];
|
|
311
|
+
const calls = /* @__PURE__ */ new Map();
|
|
312
|
+
const prefix = options.idPrefix ?? "msg-";
|
|
313
|
+
const system = typeof options.system === "string" ? options.system : Array.isArray(options.system) ? options.system.map((block) => block?.text ?? "").join("\n") : "";
|
|
314
|
+
if (system !== "") {
|
|
315
|
+
result.push({ id: `${prefix}system`, role: "system", parts: [{ type: "text", text: system }] });
|
|
316
|
+
}
|
|
317
|
+
messages.forEach((source, index) => {
|
|
318
|
+
if (!isRecord(source)) return;
|
|
319
|
+
const role = source.role === "user" || source.role === "assistant" ? source.role : null;
|
|
320
|
+
if (role === null) return;
|
|
321
|
+
const id = makeId(options.idPrefix, index, source.id);
|
|
322
|
+
const blocks = typeof source.content === "string" ? source.content === "" ? [] : [{ type: "text", text: source.content }] : Array.isArray(source.content) ? source.content : [];
|
|
323
|
+
const parts = [];
|
|
324
|
+
let carriedResults = 0;
|
|
325
|
+
blocks.forEach((block, blockIndex) => {
|
|
326
|
+
if (!isRecord(block) || typeof block.type !== "string") return;
|
|
327
|
+
switch (block.type) {
|
|
328
|
+
case "text": {
|
|
329
|
+
const text = str(block.text);
|
|
330
|
+
if (text) parts.push({ type: "text", text });
|
|
331
|
+
if (Array.isArray(block.citations)) {
|
|
332
|
+
for (const citation of block.citations) {
|
|
333
|
+
if (!isRecord(citation)) continue;
|
|
334
|
+
const url = str(citation.url);
|
|
335
|
+
if (url) {
|
|
336
|
+
const cited = { type: "source", id: url, title: str(citation.title) ?? url, url };
|
|
337
|
+
const snippet = str(citation.cited_text);
|
|
338
|
+
if (snippet) cited.snippet = snippet;
|
|
339
|
+
addUniqueSource(parts, cited);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
case "thinking": {
|
|
346
|
+
const text = str(block.thinking);
|
|
347
|
+
if (text) parts.push({ type: "reasoning", text });
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
case "tool_use":
|
|
351
|
+
case "server_tool_use": {
|
|
352
|
+
const callId = str(block.id) ?? `${id}-tool-${blockIndex + 1}`;
|
|
353
|
+
const part = { type: "tool", id: callId, name: str(block.name) ?? "tool", state: "running" };
|
|
354
|
+
if (block.input !== void 0) part.input = block.input;
|
|
355
|
+
parts.push(part);
|
|
356
|
+
calls.set(callId, part);
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
case "tool_result": {
|
|
360
|
+
const callId = str(block.tool_use_id);
|
|
361
|
+
const output = anthropicToolResultOutput(block.content);
|
|
362
|
+
const failed = block.is_error === true;
|
|
363
|
+
const call = callId === void 0 ? void 0 : calls.get(callId);
|
|
364
|
+
if (call) {
|
|
365
|
+
call.state = failed ? "failed" : "succeeded";
|
|
366
|
+
if (failed) call.error = typeof output === "string" ? output : JSON.stringify(output);
|
|
367
|
+
else call.output = output;
|
|
368
|
+
carriedResults += 1;
|
|
369
|
+
} else {
|
|
370
|
+
const orphan = {
|
|
371
|
+
type: "tool",
|
|
372
|
+
id: callId ?? `${id}-result-${blockIndex + 1}`,
|
|
373
|
+
name: "tool",
|
|
374
|
+
state: failed ? "failed" : "succeeded"
|
|
375
|
+
};
|
|
376
|
+
if (failed) orphan.error = typeof output === "string" ? output : JSON.stringify(output);
|
|
377
|
+
else orphan.output = output;
|
|
378
|
+
parts.push(orphan);
|
|
379
|
+
}
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
case "web_search_tool_result": {
|
|
383
|
+
const callId = str(block.tool_use_id);
|
|
384
|
+
const call = callId === void 0 ? void 0 : calls.get(callId);
|
|
385
|
+
const entries = Array.isArray(block.content) ? block.content : [];
|
|
386
|
+
const found = entries.filter(
|
|
387
|
+
(entry) => isRecord(entry) && entry.type === "web_search_result" && typeof entry.url === "string"
|
|
388
|
+
);
|
|
389
|
+
if (call) {
|
|
390
|
+
call.state = Array.isArray(block.content) ? "succeeded" : "failed";
|
|
391
|
+
if (found.length > 0) call.output = found.map((entry) => ({ title: entry.title, url: entry.url }));
|
|
392
|
+
else if (!Array.isArray(block.content)) call.errorCode = str(isRecord(block.content) ? block.content.error_code : void 0) ?? "search-failed";
|
|
393
|
+
}
|
|
394
|
+
for (const entry of found) {
|
|
395
|
+
const url = entry.url;
|
|
396
|
+
addUniqueSource(parts, { type: "source", id: url, title: str(entry.title) ?? url, url });
|
|
397
|
+
}
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
case "image": {
|
|
401
|
+
const file = anthropicMedia(block.source, `image-${blockIndex + 1}`);
|
|
402
|
+
if (file) parts.push(file);
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
case "document": {
|
|
406
|
+
const file = anthropicMedia(block.source, str(block.title) ?? `document-${blockIndex + 1}`);
|
|
407
|
+
if (file) parts.push(file);
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
default:
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
if (role === "user" && parts.length === 0 && carriedResults > 0) return;
|
|
415
|
+
const message = { id, role, parts };
|
|
416
|
+
if (role === "assistant") message.status = "complete";
|
|
417
|
+
result.push(message);
|
|
418
|
+
});
|
|
419
|
+
return result;
|
|
420
|
+
}
|
|
421
|
+
function normalizeFinishReason(reason) {
|
|
422
|
+
const value = str(reason);
|
|
423
|
+
if (value === void 0) return void 0;
|
|
424
|
+
switch (value.toLowerCase().replace(/_/g, "-")) {
|
|
425
|
+
case "stop":
|
|
426
|
+
case "end-turn":
|
|
427
|
+
case "stop-sequence":
|
|
428
|
+
case "complete":
|
|
429
|
+
return "stop";
|
|
430
|
+
case "length":
|
|
431
|
+
case "max-tokens":
|
|
432
|
+
case "max-output-tokens":
|
|
433
|
+
return "length";
|
|
434
|
+
case "tool-calls":
|
|
435
|
+
case "tool-use":
|
|
436
|
+
case "function-call":
|
|
437
|
+
return "tool-calls";
|
|
438
|
+
case "content-filter":
|
|
439
|
+
case "refusal":
|
|
440
|
+
case "safety":
|
|
441
|
+
return "content-filter";
|
|
442
|
+
case "error":
|
|
443
|
+
return "error";
|
|
444
|
+
default:
|
|
445
|
+
return "other";
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function normalizeUsage(usage) {
|
|
449
|
+
if (!isRecord(usage)) return void 0;
|
|
450
|
+
const input = num(usage.inputTokens) ?? num(usage.input_tokens) ?? num(usage.prompt_tokens);
|
|
451
|
+
const output = num(usage.outputTokens) ?? num(usage.output_tokens) ?? num(usage.completion_tokens);
|
|
452
|
+
const total = num(usage.totalTokens) ?? num(usage.total_tokens);
|
|
453
|
+
const reasoning = num(usage.reasoningTokens);
|
|
454
|
+
const cached = num(usage.cachedInputTokens) ?? num(usage.cache_read_input_tokens);
|
|
455
|
+
const result = {};
|
|
456
|
+
if (input !== void 0) result.inputTokens = input;
|
|
457
|
+
if (output !== void 0) result.outputTokens = output;
|
|
458
|
+
if (total !== void 0) result.totalTokens = total;
|
|
459
|
+
if (reasoning !== void 0) result.reasoningTokens = reasoning;
|
|
460
|
+
if (cached !== void 0) result.cachedInputTokens = cached;
|
|
461
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
462
|
+
}
|
|
463
|
+
export {
|
|
464
|
+
SAFE_IMAGE_PROTOCOLS,
|
|
465
|
+
SAFE_LINK_PROTOCOLS,
|
|
466
|
+
applyStreamEvent,
|
|
467
|
+
applyStreamEvents,
|
|
468
|
+
citedNumbers,
|
|
469
|
+
createAbortableStream,
|
|
470
|
+
createThreadState,
|
|
471
|
+
errorEvent,
|
|
472
|
+
findToolCall,
|
|
473
|
+
formatBytes,
|
|
474
|
+
formatDuration,
|
|
475
|
+
formatTokenCount,
|
|
476
|
+
formatUsage,
|
|
477
|
+
fromAiSdkMessages,
|
|
478
|
+
fromAnthropicMessages,
|
|
479
|
+
fromOpenAIChatMessages,
|
|
480
|
+
getBranchInfo,
|
|
481
|
+
getBranchInfoMap,
|
|
482
|
+
getUrlHostname,
|
|
483
|
+
isAbortError,
|
|
484
|
+
isBusy,
|
|
485
|
+
isExternalUrl,
|
|
486
|
+
isSafeUrl,
|
|
487
|
+
isStreaming,
|
|
488
|
+
isTerminalStreamEvent,
|
|
489
|
+
isTerminalToolState,
|
|
490
|
+
lastMessageWithRole,
|
|
491
|
+
lastUserMessage,
|
|
492
|
+
markdownToPlainText,
|
|
493
|
+
mergeUsage,
|
|
494
|
+
messageData,
|
|
495
|
+
messageFiles,
|
|
496
|
+
messageReasoning,
|
|
497
|
+
messageSources,
|
|
498
|
+
messageText,
|
|
499
|
+
messageToolCalls,
|
|
500
|
+
normalizeFinishReason,
|
|
501
|
+
normalizeUsage,
|
|
502
|
+
parseCitations,
|
|
503
|
+
pendingApprovals,
|
|
504
|
+
sanitizeImageUrl,
|
|
505
|
+
sanitizeUrl,
|
|
506
|
+
splitCompletedSentences,
|
|
507
|
+
splitMarkdownBlocks,
|
|
508
|
+
streamEventToAction,
|
|
509
|
+
threadPendingApprovals,
|
|
510
|
+
threadReducer,
|
|
511
|
+
toThreadError,
|
|
512
|
+
totalTokens
|
|
513
|
+
};
|
|
13
514
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAgGO,SAAS,YAAY,OAAA,EAA0B;AACpD,EAAA,OAAO,QAAQ,KAAA,CACZ,MAAA,CAAO,CAAC,IAAA,KAA2B,KAAK,IAAA,KAAS,MAAM,CAAA,CACvD,GAAA,CAAI,CAAC,IAAA,KAAS,IAAA,CAAK,IAAI,CAAA,CACvB,KAAK,EAAE,CAAA;AACZ;AAGO,SAAS,iBAAiB,OAAA,EAA8B;AAC7D,EAAA,OAAO,QAAQ,KAAA,CAAM,MAAA;AAAA,IACnB,CAAC,IAAA,KAA2B,IAAA,CAAK,IAAA,KAAS,MAAA,IAAU,KAAK,KAAA,KAAU;AAAA,GACrE;AACF","file":"index.js","sourcesContent":["/**\r\n * The neutral message shape (spec section 6). Components read typed parts and\r\n * never import a provider SDK; adapters convert provider formats into this\r\n * shape.\r\n */\r\n\r\nexport type MessageRole = \"user\" | \"assistant\" | \"system\";\r\n\r\nexport interface TextPart {\r\n type: \"text\";\r\n text: string;\r\n}\r\n\r\nexport interface ReasoningPart {\r\n type: \"reasoning\";\r\n text: string;\r\n /** How long the model thought, for the \"Thought for 4s\" line. */\r\n durationMs?: number;\r\n}\r\n\r\nexport type ToolState = \"queued\" | \"running\" | \"succeeded\" | \"failed\" | \"needs-approval\";\r\n\r\nexport interface ToolPart {\r\n type: \"tool\";\r\n id: string;\r\n name: string;\r\n state: ToolState;\r\n input?: unknown;\r\n output?: unknown;\r\n /** A human-readable cause when `state` is `failed`. */\r\n error?: string;\r\n durationMs?: number;\r\n}\r\n\r\nexport interface SourcePart {\r\n type: \"source\";\r\n id: string;\r\n title: string;\r\n url: string;\r\n /** Shown in the source list next to the title and domain. */\r\n snippet?: string;\r\n}\r\n\r\nexport interface FilePart {\r\n type: \"file\";\r\n name: string;\r\n mediaType: string;\r\n url: string;\r\n size?: number;\r\n}\r\n\r\n/** Structured data a component can render, for example an artifact or a chart spec. */\r\nexport interface DataPart {\r\n type: \"data\";\r\n /** Identifies the shape of `data`, such as `chart` or `diagram`. */\r\n kind: string;\r\n data: unknown;\r\n}\r\n\r\nexport type MessagePart = TextPart | ReasoningPart | ToolPart | SourcePart | FilePart | DataPart;\r\n\r\nexport type MessageStatus = \"streaming\" | \"complete\" | \"error\" | \"stopped\";\r\n\r\nexport interface Message {\r\n id: string;\r\n role: MessageRole;\r\n parts: MessagePart[];\r\n status?: MessageStatus;\r\n createdAt?: string;\r\n /** The message this one replaces or follows, for branches between versions. */\r\n parentId?: string;\r\n metadata?: Record<string, unknown>;\r\n}\r\n\r\nexport interface Thread {\r\n id: string;\r\n title?: string;\r\n messages: Message[];\r\n updatedAt?: string;\r\n}\r\n\r\n/** Converts a provider's message format into the neutral shape. */\r\nexport type MessageAdapter<Input> = (input: Input) => Message;\r\n\r\n/**\r\n * The thread component is stateless. Storage and history belong to the app,\r\n * through this small interface.\r\n */\r\nexport interface ThreadStore {\r\n load(threadId: string): Promise<Thread | null>;\r\n save(thread: Thread): Promise<void>;\r\n list?(): Promise<Array<Pick<Thread, \"id\" | \"title\" | \"updatedAt\">>>;\r\n delete?(threadId: string): Promise<void>;\r\n}\r\n\r\n/** The text of a message: its text parts, joined. Reasoning and tool output are left out. */\r\nexport function messageText(message: Message): string {\r\n return message.parts\r\n .filter((part): part is TextPart => part.type === \"text\")\r\n .map((part) => part.text)\r\n .join(\"\");\r\n}\r\n\r\n/** Tool calls that are waiting for a human decision. */\r\nexport function pendingApprovals(message: Message): ToolPart[] {\r\n return message.parts.filter(\r\n (part): part is ToolPart => part.type === \"tool\" && part.state === \"needs-approval\",\r\n );\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/adapters.ts"],"sourcesContent":["import type {\n FilePart,\n FinishReason,\n Message,\n MessagePart,\n SourcePart,\n ToolPart,\n ToolState,\n Usage,\n} from \"./types\";\n\n/**\n * Provider adapters: pure functions from a provider's message shapes to\n * kit messages. They import no SDK. The input types below describe, loosely\n * and structurally, the fields each adapter reads, so you can pass your SDK's\n * own message objects without casting. Fields an adapter does not know are\n * ignored.\n *\n * Adapters never mutate their input and never throw on odd input: a part they\n * do not understand is skipped.\n */\n\ntype Json = Record<string, unknown>;\n\nfunction isRecord(value: unknown): value is Json {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction str(value: unknown): string | undefined {\n return typeof value === \"string\" ? value : undefined;\n}\n\nfunction num(value: unknown): number | undefined {\n return typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\n/** Parses a JSON string, or returns the string itself when it is not JSON. */\nfunction parseMaybeJson(value: string): unknown {\n const trimmed = value.trim();\n if (trimmed === \"\") return value;\n try {\n return JSON.parse(trimmed);\n } catch {\n return value;\n }\n}\n\nfunction toIso(value: unknown): string | undefined {\n if (value === undefined || value === null) return undefined;\n const date = value instanceof Date ? value : new Date(value as string | number);\n return Number.isNaN(date.getTime()) ? undefined : date.toISOString();\n}\n\nfunction mediaTypeOfDataUrl(url: string): string | undefined {\n return /^data:([^;,]+)[;,]/i.exec(url)?.[1];\n}\n\nfunction addUniqueSource(parts: MessagePart[], source: SourcePart): void {\n if (parts.some((part) => part.type === \"source\" && (part.id === source.id || (source.url !== \"\" && part.url === source.url)))) {\n return;\n }\n parts.push(source);\n}\n\nexport interface AdapterOptions {\n /** Prefix for ids made for messages that have none. Default `msg-`. */\n idPrefix?: string;\n}\n\nfunction makeId(prefix: string | undefined, index: number, explicit?: unknown): string {\n return str(explicit) && str(explicit) !== \"\" ? (str(explicit) as string) : `${prefix ?? \"msg-\"}${index + 1}`;\n}\n\n// ------------------------------------------------------------- AI SDK\n\n/**\n * One part of a Vercel AI SDK `UIMessage` (v4 and v5 shapes). The adapter reads:\n * `text`, `reasoning`, `tool-<name>` and `dynamic-tool` (with `toolCallId`,\n * `state`, `input`, `output`, `errorText`), v4 `tool-invocation`, `source-url`,\n * `source-document`, v4 `source`, `file` and `data-<name>`. `step-start` and\n * unknown parts are skipped.\n */\nexport interface AiSdkPart {\n type: string;\n [key: string]: unknown;\n}\n\nexport interface AiSdkMessage {\n id?: string;\n role: string;\n /** The message parts. When absent, `content` (a string) is used. */\n parts?: ReadonlyArray<AiSdkPart>;\n content?: unknown;\n createdAt?: Date | string | number;\n metadata?: unknown;\n}\n\nfunction aiSdkToolState(state: unknown, approved: unknown): ToolState {\n switch (state) {\n case \"input-streaming\":\n case \"partial-call\":\n return \"queued\";\n case \"input-available\":\n case \"call\":\n return \"running\";\n case \"approval-requested\":\n return \"needs-approval\";\n case \"approval-responded\":\n return approved === false ? \"denied\" : \"approved\";\n case \"output-available\":\n case \"result\":\n return \"succeeded\";\n case \"output-error\":\n return \"failed\";\n case \"output-denied\":\n return \"denied\";\n default:\n return \"running\";\n }\n}\n\nfunction aiSdkTool(source: Json, name: string, id: string): ToolPart {\n const approval = isRecord(source.approval) ? source.approval : undefined;\n const state = aiSdkToolState(source.state, approval?.approved);\n const part: ToolPart = { type: \"tool\", id, name, state };\n const input = source.input ?? source.args;\n const output = source.output ?? source.result;\n if (input !== undefined) part.input = input;\n if (output !== undefined) part.output = output;\n const error = str(source.errorText);\n if (error !== undefined) part.error = error;\n const reason = approval ? str(approval.reason) : undefined;\n if (reason !== undefined) part.approval = { reason };\n return part;\n}\n\nfunction aiSdkPart(part: AiSdkPart, index: number): MessagePart | null {\n const type = part.type;\n\n if (type === \"text\") {\n const text = str(part.text);\n return text === undefined || text === \"\" ? null : { type: \"text\", text };\n }\n if (type === \"reasoning\") {\n const text = str(part.text) ?? str(part.reasoning);\n return text === undefined ? null : { type: \"reasoning\", text };\n }\n if (type === \"dynamic-tool\") {\n const id = str(part.toolCallId) ?? `tool-${index + 1}`;\n return aiSdkTool(part, str(part.toolName) ?? \"tool\", id);\n }\n if (type.startsWith(\"tool-\") && type !== \"tool-invocation\") {\n const id = str(part.toolCallId) ?? `tool-${index + 1}`;\n return aiSdkTool(part, type.slice(\"tool-\".length), id);\n }\n if (type === \"tool-invocation\" && isRecord(part.toolInvocation)) {\n const invocation = part.toolInvocation;\n const id = str(invocation.toolCallId) ?? `tool-${index + 1}`;\n return aiSdkTool(invocation, str(invocation.toolName) ?? \"tool\", id);\n }\n if (type === \"source-url\") {\n const url = str(part.url);\n if (url === undefined) return null;\n return { type: \"source\", id: str(part.sourceId) ?? url, title: str(part.title) ?? url, url };\n }\n if (type === \"source-document\") {\n const title = str(part.title) ?? str(part.filename) ?? str(part.sourceId) ?? `source-${index + 1}`;\n return { type: \"source\", id: str(part.sourceId) ?? `source-${index + 1}`, title, url: \"\" };\n }\n if (type === \"source\" && isRecord(part.source)) {\n const url = str(part.source.url);\n if (url === undefined) return null;\n return { type: \"source\", id: str(part.source.id) ?? url, title: str(part.source.title) ?? url, url };\n }\n if (type === \"file\") {\n const mediaType = str(part.mediaType) ?? str(part.mimeType) ?? \"application/octet-stream\";\n const data = str(part.data);\n const url = str(part.url) ?? (data === undefined ? undefined : `data:${mediaType};base64,${data}`);\n if (url === undefined) return null;\n const file: FilePart = { type: \"file\", name: str(part.filename) ?? \"file\", mediaType, url };\n return file;\n }\n if (type.startsWith(\"data-\")) {\n return { type: \"data\", kind: type.slice(\"data-\".length), data: part.data };\n }\n return null;\n}\n\nfunction aiSdkStreaming(parts: ReadonlyArray<AiSdkPart>): boolean {\n return parts.some(\n (part) =>\n ((part.type === \"text\" || part.type === \"reasoning\") && part.state === \"streaming\") ||\n part.state === \"input-streaming\",\n );\n}\n\n/**\n * Converts Vercel AI SDK `UIMessage`s (the `messages` of `useChat`) into kit\n * messages. Roles other than user, assistant and system are skipped.\n */\nexport function fromAiSdkMessages(messages: readonly AiSdkMessage[], options: AdapterOptions = {}): Message[] {\n const result: Message[] = [];\n\n messages.forEach((source, index) => {\n if (!isRecord(source)) return;\n const role = source.role === \"user\" || source.role === \"assistant\" || source.role === \"system\" ? source.role : null;\n if (role === null) return;\n\n const sourceParts: ReadonlyArray<AiSdkPart> = Array.isArray(source.parts)\n ? source.parts\n : typeof source.content === \"string\" && source.content !== \"\"\n ? [{ type: \"text\", text: source.content }]\n : [];\n\n const parts: MessagePart[] = [];\n sourceParts.forEach((part, partIndex) => {\n if (!isRecord(part) || typeof part.type !== \"string\") return;\n const mapped = aiSdkPart(part, partIndex);\n if (!mapped) return;\n if (mapped.type === \"source\") addUniqueSource(parts, mapped);\n else parts.push(mapped);\n });\n\n const metadata = isRecord(source.metadata) ? source.metadata : undefined;\n const message: Message = {\n id: makeId(options.idPrefix, index, source.id),\n role,\n parts,\n };\n if (role === \"assistant\") message.status = aiSdkStreaming(sourceParts) ? \"streaming\" : \"complete\";\n const createdAt = toIso(source.createdAt) ?? toIso(metadata?.createdAt);\n if (createdAt !== undefined) message.createdAt = createdAt;\n if (metadata !== undefined) message.metadata = { ...metadata };\n result.push(message);\n });\n\n return result;\n}\n\n// ------------------------------------------------------------- OpenAI\n\n/** A content part of an OpenAI chat message. */\nexport interface OpenAIContentPart {\n type: string;\n text?: string;\n image_url?: string | { url: string };\n file?: { filename?: string; file_data?: string };\n [key: string]: unknown;\n}\n\nexport interface OpenAIToolCall {\n id: string;\n type?: string;\n function?: { name?: string; arguments?: string };\n}\n\n/**\n * An OpenAI Chat Completions message. `developer` is treated as `system`.\n * `tool` messages are merged into the assistant tool call they answer.\n * `reasoning_content`, used by some OpenAI-compatible providers, becomes a\n * reasoning part.\n */\nexport interface OpenAIChatMessage {\n id?: string;\n role: string;\n content?: string | null | ReadonlyArray<OpenAIContentPart>;\n name?: string;\n tool_calls?: ReadonlyArray<OpenAIToolCall>;\n tool_call_id?: string;\n refusal?: string | null;\n reasoning_content?: string | null;\n}\n\nfunction openAiContentParts(content: OpenAIChatMessage[\"content\"]): MessagePart[] {\n if (typeof content === \"string\") return content === \"\" ? [] : [{ type: \"text\", text: content }];\n if (!Array.isArray(content)) return [];\n const parts: MessagePart[] = [];\n content.forEach((entry: unknown, index) => {\n if (!isRecord(entry)) return;\n if (entry.type === \"text\" || entry.type === \"input_text\" || entry.type === \"output_text\") {\n const text = str(entry.text);\n if (text) parts.push({ type: \"text\", text });\n } else if (entry.type === \"image_url\" || entry.type === \"input_image\") {\n const raw = entry.image_url;\n const url = typeof raw === \"string\" ? raw : isRecord(raw) ? str(raw.url) : undefined;\n if (url) {\n parts.push({\n type: \"file\",\n name: `image-${index + 1}`,\n mediaType: mediaTypeOfDataUrl(url) ?? \"image/*\",\n url,\n });\n }\n } else if (entry.type === \"file\" && isRecord(entry.file)) {\n const url = str(entry.file.file_data);\n if (url) {\n parts.push({\n type: \"file\",\n name: str(entry.file.filename) ?? \"file\",\n mediaType: mediaTypeOfDataUrl(url) ?? \"application/octet-stream\",\n url,\n });\n }\n }\n });\n return parts;\n}\n\n/**\n * Converts OpenAI Chat Completions messages into kit messages.\n *\n * - An assistant `tool_calls` entry becomes a tool part, `running` until a\n * `tool` message with the same `tool_call_id` finishes it as `succeeded` with\n * the parsed JSON (or the raw string) as `output`.\n * - A `tool` message that answers no known call becomes its own `tool` message.\n */\nexport function fromOpenAIChatMessages(\n messages: readonly OpenAIChatMessage[],\n options: AdapterOptions = {},\n): Message[] {\n const result: Message[] = [];\n const calls = new Map<string, ToolPart>();\n\n messages.forEach((source, index) => {\n if (!isRecord(source)) return;\n const id = makeId(options.idPrefix, index, source.id);\n\n if (source.role === \"tool\" || source.role === \"function\") {\n const callId = str(source.tool_call_id) ?? (source.role === \"function\" ? `fn-${index + 1}` : `tool-${index + 1}`);\n const raw = typeof source.content === \"string\" ? source.content : openAiContentParts(source.content).map((p) => (p.type === \"text\" ? p.text : \"\")).join(\"\");\n const output = parseMaybeJson(raw);\n const call = calls.get(callId);\n if (call) {\n call.state = \"succeeded\";\n call.output = output;\n return;\n }\n result.push({\n id,\n role: \"tool\",\n parts: [{ type: \"tool\", id: callId, name: str(source.name) ?? \"tool\", state: \"succeeded\", output }],\n status: \"complete\",\n });\n return;\n }\n\n const role = source.role === \"user\" ? \"user\" : source.role === \"assistant\" ? \"assistant\" : source.role === \"system\" || source.role === \"developer\" ? \"system\" : null;\n if (role === null) return;\n\n const parts: MessagePart[] = [];\n const reasoning = str(source.reasoning_content);\n if (reasoning) parts.push({ type: \"reasoning\", text: reasoning });\n parts.push(...openAiContentParts(source.content));\n const refusal = str(source.refusal);\n if (refusal) parts.push({ type: \"text\", text: refusal });\n\n if (role === \"assistant\" && Array.isArray(source.tool_calls)) {\n source.tool_calls.forEach((call: unknown, callIndex) => {\n if (!isRecord(call)) return;\n const callId = str(call.id) ?? `${id}-call-${callIndex + 1}`;\n const fn = isRecord(call.function) ? call.function : {};\n const args = str(fn.arguments);\n const part: ToolPart = { type: \"tool\", id: callId, name: str(fn.name) ?? \"tool\", state: \"running\" };\n if (args !== undefined && args !== \"\") part.input = parseMaybeJson(args);\n parts.push(part);\n calls.set(callId, part);\n });\n }\n\n const message: Message = { id, role, parts };\n if (role === \"assistant\") message.status = \"complete\";\n result.push(message);\n });\n\n return result;\n}\n\n// ---------------------------------------------------------- Anthropic\n\n/** A content block of an Anthropic Messages API message. */\nexport interface AnthropicBlock {\n type: string;\n [key: string]: unknown;\n}\n\n/**\n * An Anthropic Messages API message. Reads `text` (with web-search\n * `citations`), `thinking`, `tool_use`, `server_tool_use`, `tool_result`,\n * `web_search_tool_result`, `image` and `document` blocks. A user message that\n * holds only `tool_result` blocks is merged into the assistant tool calls\n * they answer and produces no message of its own.\n */\nexport interface AnthropicMessage {\n id?: string;\n role: string;\n content: string | ReadonlyArray<AnthropicBlock>;\n}\n\nexport interface AnthropicAdapterOptions extends AdapterOptions {\n /** The request's top-level `system` prompt, shown as a system message first. */\n system?: string | ReadonlyArray<{ type?: string; text?: string }>;\n}\n\nfunction anthropicToolResultOutput(content: unknown): unknown {\n if (typeof content === \"string\") return parseMaybeJson(content);\n if (!Array.isArray(content)) return content;\n const texts = content\n .filter((block): block is Json => isRecord(block) && block.type === \"text\" && typeof block.text === \"string\")\n .map((block) => block.text as string);\n if (texts.length === content.length) return parseMaybeJson(texts.join(\"\\n\"));\n return content;\n}\n\nfunction anthropicMedia(source: unknown, fallbackName: string): FilePart | null {\n if (!isRecord(source)) return null;\n if (source.type === \"base64\") {\n const mediaType = str(source.media_type) ?? \"application/octet-stream\";\n const data = str(source.data);\n return data === undefined ? null : { type: \"file\", name: fallbackName, mediaType, url: `data:${mediaType};base64,${data}` };\n }\n if (source.type === \"url\") {\n const url = str(source.url);\n return url === undefined ? null : { type: \"file\", name: fallbackName, mediaType: mediaTypeOfDataUrl(url) ?? \"application/octet-stream\", url };\n }\n return null;\n}\n\n/**\n * Converts Anthropic Messages API messages into kit messages.\n */\nexport function fromAnthropicMessages(\n messages: readonly AnthropicMessage[],\n options: AnthropicAdapterOptions = {},\n): Message[] {\n const result: Message[] = [];\n const calls = new Map<string, ToolPart>();\n const prefix = options.idPrefix ?? \"msg-\";\n\n const system =\n typeof options.system === \"string\"\n ? options.system\n : Array.isArray(options.system)\n ? options.system.map((block) => block?.text ?? \"\").join(\"\\n\")\n : \"\";\n if (system !== \"\") {\n result.push({ id: `${prefix}system`, role: \"system\", parts: [{ type: \"text\", text: system }] });\n }\n\n messages.forEach((source, index) => {\n if (!isRecord(source)) return;\n const role = source.role === \"user\" || source.role === \"assistant\" ? source.role : null;\n if (role === null) return;\n const id = makeId(options.idPrefix, index, source.id);\n\n const blocks: ReadonlyArray<AnthropicBlock> =\n typeof source.content === \"string\"\n ? source.content === \"\"\n ? []\n : [{ type: \"text\", text: source.content }]\n : Array.isArray(source.content)\n ? source.content\n : [];\n\n const parts: MessagePart[] = [];\n let carriedResults = 0;\n\n blocks.forEach((block, blockIndex) => {\n if (!isRecord(block) || typeof block.type !== \"string\") return;\n switch (block.type) {\n case \"text\": {\n const text = str(block.text);\n if (text) parts.push({ type: \"text\", text });\n if (Array.isArray(block.citations)) {\n for (const citation of block.citations) {\n if (!isRecord(citation)) continue;\n const url = str(citation.url);\n if (url) {\n const cited: SourcePart = { type: \"source\", id: url, title: str(citation.title) ?? url, url };\n const snippet = str(citation.cited_text);\n if (snippet) cited.snippet = snippet;\n addUniqueSource(parts, cited);\n }\n }\n }\n break;\n }\n case \"thinking\": {\n const text = str(block.thinking);\n if (text) parts.push({ type: \"reasoning\", text });\n break;\n }\n case \"tool_use\":\n case \"server_tool_use\": {\n const callId = str(block.id) ?? `${id}-tool-${blockIndex + 1}`;\n const part: ToolPart = { type: \"tool\", id: callId, name: str(block.name) ?? \"tool\", state: \"running\" };\n if (block.input !== undefined) part.input = block.input;\n parts.push(part);\n calls.set(callId, part);\n break;\n }\n case \"tool_result\": {\n const callId = str(block.tool_use_id);\n const output = anthropicToolResultOutput(block.content);\n const failed = block.is_error === true;\n const call = callId === undefined ? undefined : calls.get(callId);\n if (call) {\n call.state = failed ? \"failed\" : \"succeeded\";\n if (failed) call.error = typeof output === \"string\" ? output : JSON.stringify(output);\n else call.output = output;\n carriedResults += 1;\n } else {\n const orphan: ToolPart = {\n type: \"tool\",\n id: callId ?? `${id}-result-${blockIndex + 1}`,\n name: \"tool\",\n state: failed ? \"failed\" : \"succeeded\",\n };\n if (failed) orphan.error = typeof output === \"string\" ? output : JSON.stringify(output);\n else orphan.output = output;\n parts.push(orphan);\n }\n break;\n }\n case \"web_search_tool_result\": {\n const callId = str(block.tool_use_id);\n const call = callId === undefined ? undefined : calls.get(callId);\n const entries = Array.isArray(block.content) ? block.content : [];\n const found: Json[] = entries.filter(\n (entry): entry is Json => isRecord(entry) && entry.type === \"web_search_result\" && typeof entry.url === \"string\",\n );\n if (call) {\n call.state = Array.isArray(block.content) ? \"succeeded\" : \"failed\";\n if (found.length > 0) call.output = found.map((entry) => ({ title: entry.title, url: entry.url }));\n else if (!Array.isArray(block.content)) call.errorCode = str(isRecord(block.content) ? block.content.error_code : undefined) ?? \"search-failed\";\n }\n for (const entry of found) {\n const url = entry.url as string;\n addUniqueSource(parts, { type: \"source\", id: url, title: str(entry.title) ?? url, url });\n }\n break;\n }\n case \"image\": {\n const file = anthropicMedia(block.source, `image-${blockIndex + 1}`);\n if (file) parts.push(file);\n break;\n }\n case \"document\": {\n const file = anthropicMedia(block.source, str(block.title) ?? `document-${blockIndex + 1}`);\n if (file) parts.push(file);\n break;\n }\n default:\n break;\n }\n });\n\n // A user turn that only carries tool results belongs to the assistant message before it.\n if (role === \"user\" && parts.length === 0 && carriedResults > 0) return;\n\n const message: Message = { id, role, parts };\n if (role === \"assistant\") message.status = \"complete\";\n result.push(message);\n });\n\n return result;\n}\n\n/** Reads a `finish_reason` or `stop_reason` from any provider into the kit's vocabulary. */\nexport function normalizeFinishReason(reason: unknown): FinishReason | undefined {\n const value = str(reason);\n if (value === undefined) return undefined;\n switch (value.toLowerCase().replace(/_/g, \"-\")) {\n case \"stop\":\n case \"end-turn\":\n case \"stop-sequence\":\n case \"complete\":\n return \"stop\";\n case \"length\":\n case \"max-tokens\":\n case \"max-output-tokens\":\n return \"length\";\n case \"tool-calls\":\n case \"tool-use\":\n case \"function-call\":\n return \"tool-calls\";\n case \"content-filter\":\n case \"refusal\":\n case \"safety\":\n return \"content-filter\";\n case \"error\":\n return \"error\";\n default:\n return \"other\";\n }\n}\n\n/** Reads token usage from OpenAI (`prompt_tokens`), Anthropic (`input_tokens`) or AI SDK (`inputTokens`) shapes. */\nexport function normalizeUsage(usage: unknown): Usage | undefined {\n if (!isRecord(usage)) return undefined;\n const input = num(usage.inputTokens) ?? num(usage.input_tokens) ?? num(usage.prompt_tokens);\n const output = num(usage.outputTokens) ?? num(usage.output_tokens) ?? num(usage.completion_tokens);\n const total = num(usage.totalTokens) ?? num(usage.total_tokens);\n const reasoning = num(usage.reasoningTokens);\n const cached = num(usage.cachedInputTokens) ?? num(usage.cache_read_input_tokens);\n const result: Usage = {};\n if (input !== undefined) result.inputTokens = input;\n if (output !== undefined) result.outputTokens = output;\n if (total !== undefined) result.totalTokens = total;\n if (reasoning !== undefined) result.reasoningTokens = reasoning;\n if (cached !== undefined) result.cachedInputTokens = cached;\n return Object.keys(result).length > 0 ? result : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAS,SAAS,OAA+B;AAC/C,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,IAAI,OAAoC;AAC/C,SAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,IAAI,OAAoC;AAC/C,SAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ;AACvE;AAGA,SAAS,eAAe,OAAwB;AAC9C,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,YAAY,GAAI,QAAO;AAC3B,MAAI;AACF,WAAO,KAAK,MAAM,OAAO;AAAA,EAC3B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,MAAM,OAAoC;AACjD,MAAI,UAAU,UAAa,UAAU,KAAM,QAAO;AAClD,QAAM,OAAO,iBAAiB,OAAO,QAAQ,IAAI,KAAK,KAAwB;AAC9E,SAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,IAAI,SAAY,KAAK,YAAY;AACrE;AAEA,SAAS,mBAAmB,KAAiC;AAC3D,SAAO,sBAAsB,KAAK,GAAG,IAAI,CAAC;AAC5C;AAEA,SAAS,gBAAgB,OAAsB,QAA0B;AACvE,MAAI,MAAM,KAAK,CAAC,SAAS,KAAK,SAAS,aAAa,KAAK,OAAO,OAAO,MAAO,OAAO,QAAQ,MAAM,KAAK,QAAQ,OAAO,IAAK,GAAG;AAC7H;AAAA,EACF;AACA,QAAM,KAAK,M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