veryfront 0.1.292 → 0.1.293
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/esm/deno.js +1 -1
- package/esm/src/chat/conversation.d.ts +4 -0
- package/esm/src/chat/conversation.d.ts.map +1 -1
- package/esm/src/chat/conversation.js +123 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
- package/src/deno.js +1 -1
- package/src/src/chat/conversation.ts +151 -0
- package/src/src/utils/version-constant.ts +1 -1
package/esm/deno.js
CHANGED
|
@@ -226,6 +226,10 @@ export declare function pushToolParts(parts: MessagePart[], toolName: string, to
|
|
|
226
226
|
output?: unknown;
|
|
227
227
|
errorText?: unknown;
|
|
228
228
|
}): void;
|
|
229
|
+
export declare function toConversationPartsFromUiMessage(message: ChatUiMessage): MessagePart[];
|
|
230
|
+
export declare function hasIncompleteToolParts(message: ChatUiMessage): boolean;
|
|
231
|
+
export declare function markIncompleteToolPartsAsStopped(message: ChatUiMessage): ChatUiMessage;
|
|
232
|
+
export declare function markIncompleteToolPartsAsErrored(message: ChatUiMessage, errorText: string): ChatUiMessage;
|
|
229
233
|
export declare function isToolCallPart(value: unknown): value is ToolCallLike;
|
|
230
234
|
export declare function isToolResultPart(value: unknown): value is ToolResultLike;
|
|
231
235
|
export declare function isTextPart(value: unknown): value is TextPartLike;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../src/src/chat/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAiDrF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,OAAO,EAAE,aAAa,GAAG,aAAa,CAEtF;AAED,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,MAAM,GAChB,aAAa,CAaf;AA8BD,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAOpE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAOxE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEhE;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAE1E;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAoBxE;AAyaD,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,gBAAgB,EAAE,CAa9F"}
|
|
@@ -214,6 +214,129 @@ export function pushToolParts(parts, toolName, toolCallId, state, part) {
|
|
|
214
214
|
state: mapToolState(state),
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
|
+
function pushFileConversationPart(parts, part) {
|
|
218
|
+
const uploadId = part.uploadId ?? extractUploadId(part.url);
|
|
219
|
+
if (!uploadId)
|
|
220
|
+
return;
|
|
221
|
+
if (part.mediaType.startsWith("image/")) {
|
|
222
|
+
parts.push({
|
|
223
|
+
type: "image",
|
|
224
|
+
upload_id: uploadId,
|
|
225
|
+
media_type: part.mediaType,
|
|
226
|
+
...(part.url ? { url: part.url } : {}),
|
|
227
|
+
});
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
parts.push({
|
|
231
|
+
type: "file",
|
|
232
|
+
upload_id: uploadId,
|
|
233
|
+
media_type: part.mediaType,
|
|
234
|
+
...(part.url ? { url: part.url } : {}),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
export function toConversationPartsFromUiMessage(message) {
|
|
238
|
+
const parts = [];
|
|
239
|
+
for (const part of message.parts) {
|
|
240
|
+
if (part.type === "text") {
|
|
241
|
+
parts.push({ type: "text", text: part.text });
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (part.type === "reasoning") {
|
|
245
|
+
parts.push({ type: "reasoning", text: part.text });
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (part.type === "step-start") {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (part.type === "source-url") {
|
|
252
|
+
parts.push({
|
|
253
|
+
type: "citation",
|
|
254
|
+
source_id: part.sourceId,
|
|
255
|
+
title: part.title,
|
|
256
|
+
url: part.url,
|
|
257
|
+
});
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (part.type === "source-document") {
|
|
261
|
+
parts.push({
|
|
262
|
+
type: "citation",
|
|
263
|
+
source_id: part.sourceId,
|
|
264
|
+
title: part.title,
|
|
265
|
+
});
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (part.type === "file") {
|
|
269
|
+
pushFileConversationPart(parts, part);
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (isDataUiPart(part)) {
|
|
273
|
+
const name = part.type.replace(/^data-/, "");
|
|
274
|
+
if (name.length > 0) {
|
|
275
|
+
parts.push({
|
|
276
|
+
type: "data",
|
|
277
|
+
name,
|
|
278
|
+
value: part.data,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (isToolUiPart(part)) {
|
|
284
|
+
const toolName = getUiToolName(part);
|
|
285
|
+
if (!toolName) {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
pushToolParts(parts, toolName, part.toolCallId, part.state, part);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return parts.filter((part) => messagePartSchema.safeParse(part).success);
|
|
292
|
+
}
|
|
293
|
+
function isToolComplete(part) {
|
|
294
|
+
return part.state === "output-available" || part.state === "output-error" ||
|
|
295
|
+
part.state === "output-denied";
|
|
296
|
+
}
|
|
297
|
+
export function hasIncompleteToolParts(message) {
|
|
298
|
+
return message.parts.some((part) => isToolUiPart(part) && !isToolComplete(part));
|
|
299
|
+
}
|
|
300
|
+
export function markIncompleteToolPartsAsStopped(message) {
|
|
301
|
+
return markIncompleteToolPartsAsErrored(message, "Stopped by user");
|
|
302
|
+
}
|
|
303
|
+
export function markIncompleteToolPartsAsErrored(message, errorText) {
|
|
304
|
+
let mutated = false;
|
|
305
|
+
const parts = message.parts.map((part) => {
|
|
306
|
+
if (!isToolUiPart(part) || isToolComplete(part)) {
|
|
307
|
+
return part;
|
|
308
|
+
}
|
|
309
|
+
mutated = true;
|
|
310
|
+
return markToolPartAsErrored(part, errorText);
|
|
311
|
+
});
|
|
312
|
+
return mutated ? { ...message, parts } : message;
|
|
313
|
+
}
|
|
314
|
+
function markToolPartAsErrored(part, errorText) {
|
|
315
|
+
if (part.type === "dynamic-tool") {
|
|
316
|
+
return {
|
|
317
|
+
type: "dynamic-tool",
|
|
318
|
+
toolName: part.toolName,
|
|
319
|
+
toolCallId: part.toolCallId,
|
|
320
|
+
...(part.title ? { title: part.title } : {}),
|
|
321
|
+
...(part.providerExecuted !== undefined ? { providerExecuted: part.providerExecuted } : {}),
|
|
322
|
+
...(part.callProviderMetadata ? { callProviderMetadata: part.callProviderMetadata } : {}),
|
|
323
|
+
input: part.input,
|
|
324
|
+
state: "output-error",
|
|
325
|
+
errorText,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
type: part.type,
|
|
330
|
+
toolCallId: part.toolCallId,
|
|
331
|
+
...(part.toolName ? { toolName: part.toolName } : {}),
|
|
332
|
+
...(part.title ? { title: part.title } : {}),
|
|
333
|
+
...(part.providerExecuted !== undefined ? { providerExecuted: part.providerExecuted } : {}),
|
|
334
|
+
...(part.callProviderMetadata ? { callProviderMetadata: part.callProviderMetadata } : {}),
|
|
335
|
+
input: part.input,
|
|
336
|
+
state: "output-error",
|
|
337
|
+
errorText,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
217
340
|
export function isToolCallPart(value) {
|
|
218
341
|
return (isRecord(value) &&
|
|
219
342
|
value.type === "tool-call" &&
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.293";
|
|
2
2
|
//# sourceMappingURL=version-constant.d.ts.map
|
package/package.json
CHANGED
package/src/deno.js
CHANGED
|
@@ -293,6 +293,157 @@ export function pushToolParts(
|
|
|
293
293
|
});
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
+
function pushFileConversationPart(
|
|
297
|
+
parts: MessagePart[],
|
|
298
|
+
part: Extract<ChatUiMessagePart, { type: "file" }>,
|
|
299
|
+
): void {
|
|
300
|
+
const uploadId = part.uploadId ?? extractUploadId(part.url);
|
|
301
|
+
if (!uploadId) return;
|
|
302
|
+
|
|
303
|
+
if (part.mediaType.startsWith("image/")) {
|
|
304
|
+
parts.push({
|
|
305
|
+
type: "image",
|
|
306
|
+
upload_id: uploadId,
|
|
307
|
+
media_type: part.mediaType,
|
|
308
|
+
...(part.url ? { url: part.url } : {}),
|
|
309
|
+
});
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
parts.push({
|
|
314
|
+
type: "file",
|
|
315
|
+
upload_id: uploadId,
|
|
316
|
+
media_type: part.mediaType,
|
|
317
|
+
...(part.url ? { url: part.url } : {}),
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export function toConversationPartsFromUiMessage(message: ChatUiMessage): MessagePart[] {
|
|
322
|
+
const parts: MessagePart[] = [];
|
|
323
|
+
|
|
324
|
+
for (const part of message.parts) {
|
|
325
|
+
if (part.type === "text") {
|
|
326
|
+
parts.push({ type: "text", text: part.text });
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (part.type === "reasoning") {
|
|
331
|
+
parts.push({ type: "reasoning", text: part.text });
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (part.type === "step-start") {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (part.type === "source-url") {
|
|
340
|
+
parts.push({
|
|
341
|
+
type: "citation",
|
|
342
|
+
source_id: part.sourceId,
|
|
343
|
+
title: part.title,
|
|
344
|
+
url: part.url,
|
|
345
|
+
});
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (part.type === "source-document") {
|
|
350
|
+
parts.push({
|
|
351
|
+
type: "citation",
|
|
352
|
+
source_id: part.sourceId,
|
|
353
|
+
title: part.title,
|
|
354
|
+
});
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (part.type === "file") {
|
|
359
|
+
pushFileConversationPart(parts, part);
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (isDataUiPart(part)) {
|
|
364
|
+
const name = part.type.replace(/^data-/, "");
|
|
365
|
+
if (name.length > 0) {
|
|
366
|
+
parts.push({
|
|
367
|
+
type: "data",
|
|
368
|
+
name,
|
|
369
|
+
value: part.data,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (isToolUiPart(part)) {
|
|
376
|
+
const toolName = getUiToolName(part);
|
|
377
|
+
if (!toolName) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
pushToolParts(parts, toolName, part.toolCallId, part.state, part);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return parts.filter((part) => messagePartSchema.safeParse(part).success);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function isToolComplete(part: ToolUiPart): boolean {
|
|
389
|
+
return part.state === "output-available" || part.state === "output-error" ||
|
|
390
|
+
part.state === "output-denied";
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export function hasIncompleteToolParts(message: ChatUiMessage): boolean {
|
|
394
|
+
return message.parts.some((part) => isToolUiPart(part) && !isToolComplete(part));
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export function markIncompleteToolPartsAsStopped(message: ChatUiMessage): ChatUiMessage {
|
|
398
|
+
return markIncompleteToolPartsAsErrored(message, "Stopped by user");
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export function markIncompleteToolPartsAsErrored(
|
|
402
|
+
message: ChatUiMessage,
|
|
403
|
+
errorText: string,
|
|
404
|
+
): ChatUiMessage {
|
|
405
|
+
let mutated = false;
|
|
406
|
+
|
|
407
|
+
const parts = message.parts.map((part) => {
|
|
408
|
+
if (!isToolUiPart(part) || isToolComplete(part)) {
|
|
409
|
+
return part;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
mutated = true;
|
|
413
|
+
return markToolPartAsErrored(part, errorText);
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
return mutated ? { ...message, parts } : message;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function markToolPartAsErrored(part: ToolUiPart, errorText: string): ChatUiMessagePart {
|
|
420
|
+
if (part.type === "dynamic-tool") {
|
|
421
|
+
return {
|
|
422
|
+
type: "dynamic-tool",
|
|
423
|
+
toolName: part.toolName,
|
|
424
|
+
toolCallId: part.toolCallId,
|
|
425
|
+
...(part.title ? { title: part.title } : {}),
|
|
426
|
+
...(part.providerExecuted !== undefined ? { providerExecuted: part.providerExecuted } : {}),
|
|
427
|
+
...(part.callProviderMetadata ? { callProviderMetadata: part.callProviderMetadata } : {}),
|
|
428
|
+
input: part.input,
|
|
429
|
+
state: "output-error",
|
|
430
|
+
errorText,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return {
|
|
435
|
+
type: part.type,
|
|
436
|
+
toolCallId: part.toolCallId,
|
|
437
|
+
...(part.toolName ? { toolName: part.toolName } : {}),
|
|
438
|
+
...(part.title ? { title: part.title } : {}),
|
|
439
|
+
...(part.providerExecuted !== undefined ? { providerExecuted: part.providerExecuted } : {}),
|
|
440
|
+
...(part.callProviderMetadata ? { callProviderMetadata: part.callProviderMetadata } : {}),
|
|
441
|
+
input: part.input,
|
|
442
|
+
state: "output-error",
|
|
443
|
+
errorText,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
|
|
296
447
|
export function isToolCallPart(value: unknown): value is ToolCallLike {
|
|
297
448
|
return (
|
|
298
449
|
isRecord(value) &&
|