@ykurilov/agent-chat-core 0.109.0 → 0.110.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/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/dist/{chunk-2MVJW2PT.js → chunk-WMVDYLNE.js} +341 -216
- package/dist/chunk-WMVDYLNE.js.map +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/storage-contract.js +1 -1
- package/dist/types/agent-run/run-agent-turn.d.ts +2 -0
- package/dist/types/agent-run/sealed-answer.d.ts +37 -0
- package/dist/types/chat-service.d.ts +7 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/chunk-2MVJW2PT.js.map +0 -1
|
@@ -3455,6 +3455,299 @@ function isToolPart3(part) {
|
|
|
3455
3455
|
return part.type.startsWith("tool-") || part.type === "dynamic-tool";
|
|
3456
3456
|
}
|
|
3457
3457
|
|
|
3458
|
+
// src/widgets/basic-widgets.ts
|
|
3459
|
+
import { tool as tool2 } from "ai";
|
|
3460
|
+
import { z as z2 } from "zod";
|
|
3461
|
+
var BASIC_WIDGET_NAMES = ["ask_choice", "ask_form", "ask_multi_choice", "ask_rating", "suggest_replies"];
|
|
3462
|
+
var SUGGESTIONS_SHOWN = "\u043F\u043E\u043A\u0430\u0437\u0430\u043D\u043E";
|
|
3463
|
+
var FORM_TEXT_MAX = 2e3;
|
|
3464
|
+
var question = z2.string().min(1).max(300);
|
|
3465
|
+
var options = z2.array(z2.string().min(1).max(80)).min(2).max(8).refine((values) => new Set(values).size === values.length, "\u0412\u0430\u0440\u0438\u0430\u043D\u0442\u044B \u043D\u0435 \u0434\u043E\u043B\u0436\u043D\u044B \u043F\u043E\u0432\u0442\u043E\u0440\u044F\u0442\u044C\u0441\u044F");
|
|
3466
|
+
var choiceInput = z2.object({ question, options });
|
|
3467
|
+
var multiChoiceInput = z2.object({ question, options, min: z2.number().int().optional(), max: z2.number().int().optional() }).superRefine((input, context) => {
|
|
3468
|
+
const { min, max } = multiChoiceLimits(input);
|
|
3469
|
+
if (min < 1 || min > max || max > input.options.length) {
|
|
3470
|
+
context.addIssue({ code: "custom", message: "\u041D\u0443\u0436\u043D\u043E 1 \u2264 min \u2264 max \u2264 \u0447\u0438\u0441\u043B\u0430 \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u043E\u0432", path: ["min"] });
|
|
3471
|
+
}
|
|
3472
|
+
});
|
|
3473
|
+
var ratingInput = z2.object({
|
|
3474
|
+
question,
|
|
3475
|
+
scale: z2.enum(["stars", "range"]),
|
|
3476
|
+
from: z2.union([z2.literal(0), z2.literal(1)]).optional(),
|
|
3477
|
+
to: z2.number().int().min(2).max(10).optional(),
|
|
3478
|
+
fromLabel: z2.string().min(1).max(40).optional(),
|
|
3479
|
+
toLabel: z2.string().min(1).max(40).optional()
|
|
3480
|
+
}).superRefine((input, context) => {
|
|
3481
|
+
const rangeFields = [input.from, input.to, input.fromLabel, input.toLabel].some((value) => value !== void 0);
|
|
3482
|
+
if (input.scale === "stars" && rangeFields) context.addIssue({ code: "custom", message: "\u0423 \u0437\u0432\u0451\u0437\u0434 \u043D\u0435\u0442 from, to \u0438 \u043F\u043E\u0434\u043F\u0438\u0441\u0435\u0439", path: ["scale"] });
|
|
3483
|
+
if (input.scale === "range" && (input.from === void 0 || input.to === void 0)) {
|
|
3484
|
+
context.addIssue({ code: "custom", message: "\u0423 \u0448\u043A\u0430\u043B\u044B range \u043D\u0443\u0436\u043D\u044B from (0 \u0438\u043B\u0438 1) \u0438 to (2\u201310)", path: ["from"] });
|
|
3485
|
+
}
|
|
3486
|
+
});
|
|
3487
|
+
var formField = z2.object({
|
|
3488
|
+
name: z2.string().regex(/^[A-Za-z0-9_]+$/, "name \u2014 \u043B\u0430\u0442\u0438\u043D\u0438\u0446\u0430, \u0446\u0438\u0444\u0440\u044B \u0438 _").max(64),
|
|
3489
|
+
label: z2.string().min(1).max(80),
|
|
3490
|
+
kind: z2.enum(["text", "number", "date", "select"]),
|
|
3491
|
+
required: z2.boolean().optional(),
|
|
3492
|
+
min: z2.union([z2.number(), z2.string()]).optional(),
|
|
3493
|
+
max: z2.union([z2.number(), z2.string()]).optional(),
|
|
3494
|
+
options: options.optional(),
|
|
3495
|
+
multiline: z2.boolean().optional()
|
|
3496
|
+
}).superRefine((field, context) => {
|
|
3497
|
+
const issue = (message) => context.addIssue({ code: "custom", message, path: [field.name] });
|
|
3498
|
+
if (field.kind === "select" && !field.options) issue("\u0423 select \u043D\u0443\u0436\u043D\u044B options: 2\u20138 \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u043E\u0432");
|
|
3499
|
+
if (field.kind !== "select" && field.options) issue("options \u2014 \u0442\u043E\u043B\u044C\u043A\u043E \u0443 select");
|
|
3500
|
+
if (field.kind === "number") {
|
|
3501
|
+
if (field.min !== void 0 && typeof field.min !== "number" || field.max !== void 0 && typeof field.max !== "number") issue("\u0423 number min \u0438 max \u2014 \u0447\u0438\u0441\u043B\u0430");
|
|
3502
|
+
else if (field.min !== void 0 && field.max !== void 0 && field.min > field.max) issue("\u0423 number \u043D\u0443\u0436\u043D\u043E min \u2264 max");
|
|
3503
|
+
} else if (field.kind === "date") {
|
|
3504
|
+
const dates = [field.min, field.max].filter((value) => value !== void 0);
|
|
3505
|
+
if (dates.some((value) => typeof value !== "string" || !isCalendarDate(value))) issue("\u0423 date min \u0438 max \u2014 \u0434\u0430\u0442\u044B YYYY-MM-DD");
|
|
3506
|
+
else if (field.min !== void 0 && field.max !== void 0 && field.min > field.max) issue("\u0423 date \u043D\u0443\u0436\u043D\u043E min \u2264 max");
|
|
3507
|
+
} else if (field.min !== void 0 || field.max !== void 0) {
|
|
3508
|
+
issue("min \u0438 max \u2014 \u0442\u043E\u043B\u044C\u043A\u043E \u0443 number \u0438 date");
|
|
3509
|
+
}
|
|
3510
|
+
});
|
|
3511
|
+
var formInput = z2.object({
|
|
3512
|
+
title: z2.string().min(1).max(300),
|
|
3513
|
+
fields: z2.array(formField).min(1).max(5).refine((fields) => new Set(fields.map((field) => field.name)).size === fields.length, "\u0418\u043C\u0435\u043D\u0430 \u043F\u043E\u043B\u0435\u0439 \u043D\u0435 \u0434\u043E\u043B\u0436\u043D\u044B \u043F\u043E\u0432\u0442\u043E\u0440\u044F\u0442\u044C\u0441\u044F")
|
|
3514
|
+
});
|
|
3515
|
+
var suggestInput = z2.object({ replies: z2.array(z2.string().min(1).max(60)).min(1).max(4) });
|
|
3516
|
+
var ANSWERED_BY_MESSAGE_NOTE = '\u0415\u0441\u043B\u0438 \u0447\u0435\u043B\u043E\u0432\u0435\u043A \u043E\u0442\u0432\u0435\u0442\u0438\u0442 \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435\u043C, \u0430 \u043D\u0435 \u0432 \u0432\u0438\u0434\u0436\u0435\u0442\u0435, \u0440\u0435\u0437\u0443\u043B\u044C\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 {"\u043E\u0442\u0432\u0435\u0442":"\u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435\u043C"}, \u0430 \u0435\u0433\u043E \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435 \u043F\u0440\u0438\u0434\u0451\u0442 \u0441\u043B\u0435\u0434\u043E\u043C.';
|
|
3517
|
+
var ONE_QUESTION_NOTE = "\u0417\u0430\u0434\u0430\u0432\u0430\u0439 \u043E\u0434\u0438\u043D \u0432\u043E\u043F\u0440\u043E\u0441 \u0437\u0430 \u0440\u0430\u0437: \u043D\u0435 \u0431\u043E\u043B\u044C\u0448\u0435 \u043E\u0434\u043D\u043E\u0433\u043E \u0442\u0430\u043A\u043E\u0433\u043E \u0432\u044B\u0437\u043E\u0432\u0430 \u0432 \u0448\u0430\u0433\u0435.";
|
|
3518
|
+
var TOOLS = {
|
|
3519
|
+
ask_choice: tool2({
|
|
3520
|
+
description: `\u0421\u043F\u0440\u043E\u0441\u0438\u0442\u044C \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 \u0438 \u0434\u0430\u0442\u044C \u0432\u044B\u0431\u0440\u0430\u0442\u044C \u043E\u0434\u0438\u043D \u0432\u0430\u0440\u0438\u0430\u043D\u0442 \u0438\u0437 2\u20138 \u043A\u043D\u043E\u043F\u043E\u043A. \u041E\u0442\u0432\u0435\u0442 \u0436\u0434\u0451\u0442 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 \u0438 \u043F\u0440\u0438\u0445\u043E\u0434\u0438\u0442 \u043A\u0430\u043A {"\u0432\u044B\u0431\u0440\u0430\u043D\u043E":"<\u0432\u0430\u0440\u0438\u0430\u043D\u0442>"}. ${ONE_QUESTION_NOTE} ${ANSWERED_BY_MESSAGE_NOTE}`,
|
|
3521
|
+
inputSchema: choiceInput
|
|
3522
|
+
}),
|
|
3523
|
+
ask_multi_choice: tool2({
|
|
3524
|
+
description: `\u0421\u043F\u0440\u043E\u0441\u0438\u0442\u044C \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 \u0438 \u0434\u0430\u0442\u044C \u0432\u044B\u0431\u0440\u0430\u0442\u044C \u043D\u0435\u0441\u043A\u043E\u043B\u044C\u043A\u043E \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u043E\u0432 \u0438\u0437 2\u20138 (min \u0438 max \u2014 \u0441\u043A\u043E\u043B\u044C\u043A\u043E \u043C\u043E\u0436\u043D\u043E \u0432\u044B\u0431\u0440\u0430\u0442\u044C). \u041E\u0442\u0432\u0435\u0442 \u043F\u0440\u0438\u0445\u043E\u0434\u0438\u0442 \u043A\u0430\u043A {"\u0432\u044B\u0431\u0440\u0430\u043D\u043E":["<\u0432\u0430\u0440\u0438\u0430\u043D\u0442>",\u2026]} \u0432 \u043F\u043E\u0440\u044F\u0434\u043A\u0435 \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u043E\u0432. ${ONE_QUESTION_NOTE} ${ANSWERED_BY_MESSAGE_NOTE}`,
|
|
3525
|
+
inputSchema: multiChoiceInput
|
|
3526
|
+
}),
|
|
3527
|
+
ask_rating: tool2({
|
|
3528
|
+
description: `\u041F\u043E\u043F\u0440\u043E\u0441\u0438\u0442\u044C \u043E\u0446\u0435\u043D\u043A\u0443: \u0437\u0432\u0451\u0437\u0434\u044B 1\u20135 (scale "stars") \u0438\u043B\u0438 \u0448\u043A\u0430\u043B\u0430 \u043E\u0442 from (0 \u0438\u043B\u0438 1) \u0434\u043E to (2\u201310) \u0441 \u043F\u043E\u0434\u043F\u0438\u0441\u044F\u043C\u0438 \u043A\u0440\u0430\u0451\u0432 (scale "range"). \u041E\u0442\u0432\u0435\u0442 \u043F\u0440\u0438\u0445\u043E\u0434\u0438\u0442 \u043A\u0430\u043A {"\u043E\u0446\u0435\u043D\u043A\u0430":<\u0446\u0435\u043B\u043E\u0435>}. ${ONE_QUESTION_NOTE} ${ANSWERED_BY_MESSAGE_NOTE}`,
|
|
3529
|
+
inputSchema: ratingInput
|
|
3530
|
+
}),
|
|
3531
|
+
ask_form: tool2({
|
|
3532
|
+
description: `\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u043A\u043E\u0440\u043E\u0442\u043A\u0443\u044E \u0444\u043E\u0440\u043C\u0443 \u0438\u0437 1\u20135 \u043F\u043E\u043B\u0435\u0439: text, number (min, max), date (YYYY-MM-DD), select (2\u20138 \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u043E\u0432). \u041E\u0442\u0432\u0435\u0442 \u043F\u0440\u0438\u0445\u043E\u0434\u0438\u0442 \u043A\u0430\u043A {"\u043F\u043E\u043B\u044F":{"<name>":<\u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435>}}; \u043F\u0443\u0441\u0442\u044B\u0435 \u043D\u0435\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u044B\u0435 \u043F\u043E\u043B\u044F \u043D\u0435 \u043F\u0440\u0438\u0445\u043E\u0434\u044F\u0442. ${ONE_QUESTION_NOTE} ${ANSWERED_BY_MESSAGE_NOTE}`,
|
|
3533
|
+
inputSchema: formInput
|
|
3534
|
+
}),
|
|
3535
|
+
suggest_replies: tool2({
|
|
3536
|
+
description: `\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u043F\u043E\u0434 \u043E\u0442\u0432\u0435\u0442\u043E\u043C 1\u20134 \u043A\u043E\u0440\u043E\u0442\u043A\u0438\u0445 \u043F\u043E\u0434\u0441\u043A\u0430\u0437\u043A\u0438, \u043A\u043E\u0442\u043E\u0440\u044B\u0435 \u0447\u0435\u043B\u043E\u0432\u0435\u043A \u043C\u043E\u0436\u0435\u0442 \u043E\u0442\u043F\u0440\u0430\u0432\u0438\u0442\u044C \u043E\u0434\u043D\u0438\u043C \u043D\u0430\u0436\u0430\u0442\u0438\u0435\u043C. \u0425\u043E\u0434 \u043D\u0435 \u0436\u0434\u0451\u0442: \u0440\u0435\u0437\u0443\u043B\u044C\u0442\u0430\u0442 \u0441\u0440\u0430\u0437\u0443 "${SUGGESTIONS_SHOWN}". \u041D\u0430\u0436\u0430\u0442\u0430\u044F \u043F\u043E\u0434\u0441\u043A\u0430\u0437\u043A\u0430 \u043F\u0440\u0438\u0434\u0451\u0442 \u043E\u0431\u044B\u0447\u043D\u044B\u043C \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435\u043C.`,
|
|
3537
|
+
inputSchema: suggestInput,
|
|
3538
|
+
execute: () => SUGGESTIONS_SHOWN
|
|
3539
|
+
})
|
|
3540
|
+
};
|
|
3541
|
+
function basicWidgetTool(name) {
|
|
3542
|
+
return TOOLS[name];
|
|
3543
|
+
}
|
|
3544
|
+
function checkBasicWidgetAnswer(name, input, answer) {
|
|
3545
|
+
switch (name) {
|
|
3546
|
+
case "ask_choice":
|
|
3547
|
+
return checkChoice(input, answer);
|
|
3548
|
+
case "ask_multi_choice":
|
|
3549
|
+
return checkMultiChoice(input, answer);
|
|
3550
|
+
case "ask_rating":
|
|
3551
|
+
return checkRating(input, answer);
|
|
3552
|
+
case "ask_form":
|
|
3553
|
+
return checkForm(input, answer);
|
|
3554
|
+
case "suggest_replies":
|
|
3555
|
+
return REJECTED;
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
var REJECTED = { ok: false };
|
|
3559
|
+
function checkChoice(input, answer) {
|
|
3560
|
+
const call = choiceInput.safeParse(input);
|
|
3561
|
+
const value = onlyField(answer, "\u0432\u044B\u0431\u0440\u0430\u043D\u043E");
|
|
3562
|
+
if (!call.success || typeof value !== "string" || !call.data.options.includes(value)) return REJECTED;
|
|
3563
|
+
return { ok: true, output: { \u0432\u044B\u0431\u0440\u0430\u043D\u043E: value } };
|
|
3564
|
+
}
|
|
3565
|
+
function checkMultiChoice(input, answer) {
|
|
3566
|
+
const call = multiChoiceInput.safeParse(input);
|
|
3567
|
+
const value = onlyField(answer, "\u0432\u044B\u0431\u0440\u0430\u043D\u043E");
|
|
3568
|
+
if (!call.success || !Array.isArray(value)) return REJECTED;
|
|
3569
|
+
const chosen = new Set(value);
|
|
3570
|
+
const { min, max } = multiChoiceLimits(call.data);
|
|
3571
|
+
const known = value.every((option) => typeof option === "string" && call.data.options.includes(option));
|
|
3572
|
+
if (!known || chosen.size !== value.length || value.length < min || value.length > max) return REJECTED;
|
|
3573
|
+
return { ok: true, output: { \u0432\u044B\u0431\u0440\u0430\u043D\u043E: call.data.options.filter((option) => chosen.has(option)) } };
|
|
3574
|
+
}
|
|
3575
|
+
function checkRating(input, answer) {
|
|
3576
|
+
const call = ratingInput.safeParse(input);
|
|
3577
|
+
const value = onlyField(answer, "\u043E\u0446\u0435\u043D\u043A\u0430");
|
|
3578
|
+
if (!call.success || typeof value !== "number" || !Number.isInteger(value)) return REJECTED;
|
|
3579
|
+
const { from, to } = ratingLimits(call.data);
|
|
3580
|
+
if (value < from || value > to) return REJECTED;
|
|
3581
|
+
return { ok: true, output: { \u043E\u0446\u0435\u043D\u043A\u0430: value } };
|
|
3582
|
+
}
|
|
3583
|
+
function checkForm(input, answer) {
|
|
3584
|
+
const call = formInput.safeParse(input);
|
|
3585
|
+
const values = onlyField(answer, "\u043F\u043E\u043B\u044F");
|
|
3586
|
+
if (!call.success || !isPlainObject(values)) return REJECTED;
|
|
3587
|
+
const fields = call.data.fields;
|
|
3588
|
+
if (Object.keys(values).some((key) => !fields.some((field) => field.name === key))) return REJECTED;
|
|
3589
|
+
const output = {};
|
|
3590
|
+
for (const field of fields) {
|
|
3591
|
+
const value = values[field.name];
|
|
3592
|
+
if (isEmptyValue(value)) {
|
|
3593
|
+
if (field.required) return REJECTED;
|
|
3594
|
+
continue;
|
|
3595
|
+
}
|
|
3596
|
+
if (!fieldValueFits(field, value)) return REJECTED;
|
|
3597
|
+
output[field.name] = value;
|
|
3598
|
+
}
|
|
3599
|
+
return { ok: true, output: { \u043F\u043E\u043B\u044F: output } };
|
|
3600
|
+
}
|
|
3601
|
+
function fieldValueFits(field, value) {
|
|
3602
|
+
switch (field.kind) {
|
|
3603
|
+
case "text":
|
|
3604
|
+
return typeof value === "string" && value.length <= FORM_TEXT_MAX;
|
|
3605
|
+
case "number":
|
|
3606
|
+
return typeof value === "number" && Number.isFinite(value) && (typeof field.min !== "number" || value >= field.min) && (typeof field.max !== "number" || value <= field.max);
|
|
3607
|
+
case "date":
|
|
3608
|
+
return typeof value === "string" && isCalendarDate(value) && (typeof field.min !== "string" || value >= field.min) && (typeof field.max !== "string" || value <= field.max);
|
|
3609
|
+
case "select":
|
|
3610
|
+
return typeof value === "string" && (field.options ?? []).includes(value);
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
function isEmptyValue(value) {
|
|
3614
|
+
return value === void 0 || value === null || typeof value === "string" && value.trim() === "";
|
|
3615
|
+
}
|
|
3616
|
+
function multiChoiceLimits(input) {
|
|
3617
|
+
return { min: input.min ?? 1, max: input.max ?? input.options.length };
|
|
3618
|
+
}
|
|
3619
|
+
function ratingLimits(input) {
|
|
3620
|
+
return input.scale === "stars" ? { from: 1, to: 5 } : { from: input.from ?? 0, to: input.to ?? 10 };
|
|
3621
|
+
}
|
|
3622
|
+
function onlyField(answer, key) {
|
|
3623
|
+
if (!isPlainObject(answer)) return void 0;
|
|
3624
|
+
const keys = Object.keys(answer);
|
|
3625
|
+
return keys.length === 1 && keys[0] === key ? answer[key] : void 0;
|
|
3626
|
+
}
|
|
3627
|
+
function isPlainObject(value) {
|
|
3628
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3629
|
+
}
|
|
3630
|
+
function isCalendarDate(value) {
|
|
3631
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
|
|
3632
|
+
const date = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
|
|
3633
|
+
return !Number.isNaN(date.getTime()) && date.toISOString().slice(0, 10) === value;
|
|
3634
|
+
}
|
|
3635
|
+
|
|
3636
|
+
// src/agent-run/sealed-answer.ts
|
|
3637
|
+
import { wrapLanguageModel as wrapLanguageModel4 } from "ai";
|
|
3638
|
+
var SUGGESTIONS_TOOL = "suggest_replies";
|
|
3639
|
+
var SUGGESTIONS_SHOWN_AFTER_ANSWER = `${SUGGESTIONS_SHOWN}. \u041E\u0442\u0432\u0435\u0442 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0443 \u043D\u0430 \u044D\u0442\u043E\u043C \u0437\u0430\u043A\u043E\u043D\u0447\u0435\u043D: \u043D\u043E\u0432\u044B\u0439 \u0442\u0435\u043A\u0441\u0442 \u0432 \u044D\u0442\u043E\u043C \u0445\u043E\u0434\u0435 \u043E\u043D \u043D\u0435 \u0443\u0432\u0438\u0434\u0438\u0442. \u041D\u0443\u0436\u043D\u044B\u0435 \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u044B \u0432\u044B\u0437\u044B\u0432\u0430\u0439 \u043A\u0430\u043A \u043E\u0431\u044B\u0447\u043D\u043E.`;
|
|
3640
|
+
function newStep() {
|
|
3641
|
+
let end;
|
|
3642
|
+
const ended = new Promise((resolve) => {
|
|
3643
|
+
end = resolve;
|
|
3644
|
+
});
|
|
3645
|
+
return { text: false, calls: [], shown: false, ended, end };
|
|
3646
|
+
}
|
|
3647
|
+
function createSealedAnswerGuard(serviceTools = /* @__PURE__ */ new Set()) {
|
|
3648
|
+
let sealed = false;
|
|
3649
|
+
let droppedChars = 0;
|
|
3650
|
+
let step;
|
|
3651
|
+
const closes = (candidate) => candidate !== void 0 && candidate.text && candidate.shown && candidate.calls.every((name) => name === SUGGESTIONS_TOOL || serviceTools.has(name));
|
|
3652
|
+
return {
|
|
3653
|
+
/** Новая попытка хода: закрыт ли ответ, решают части, уже написанные этим ответом. */
|
|
3654
|
+
reset(parts) {
|
|
3655
|
+
sealed = sealedByParts(parts, closes);
|
|
3656
|
+
step = void 0;
|
|
3657
|
+
},
|
|
3658
|
+
/** Ответ закрыт подсказками (с учётом последнего шага). */
|
|
3659
|
+
sealed: () => sealed || closes(step),
|
|
3660
|
+
/** Сколько знаков текста не показано после закрытия ответа (за весь ход). */
|
|
3661
|
+
droppedChars: () => droppedChars,
|
|
3662
|
+
/**
|
|
3663
|
+
* Подсказки отмечают шаг показанными. Когда шаг закрывает ответ (или ответ уже закрыт), модель получает
|
|
3664
|
+
* `SUGGESTIONS_SHOWN_AFTER_ANSWER`: результат ждёт конца потока шага, чтобы знать все его вызовы.
|
|
3665
|
+
*/
|
|
3666
|
+
tools(tools) {
|
|
3667
|
+
const original = tools?.[SUGGESTIONS_TOOL];
|
|
3668
|
+
const execute = original?.execute;
|
|
3669
|
+
if (!tools || !original || !execute) return tools;
|
|
3670
|
+
return {
|
|
3671
|
+
...tools,
|
|
3672
|
+
[SUGGESTIONS_TOOL]: {
|
|
3673
|
+
...original,
|
|
3674
|
+
execute: async (input, options2) => {
|
|
3675
|
+
const own = step;
|
|
3676
|
+
const output = await execute(input, options2);
|
|
3677
|
+
if (!own) return output;
|
|
3678
|
+
own.shown = true;
|
|
3679
|
+
if (output !== SUGGESTIONS_SHOWN) return output;
|
|
3680
|
+
await Promise.race([own.ended, aborted(options2.abortSignal)]);
|
|
3681
|
+
return sealed || closes(own) ? SUGGESTIONS_SHOWN_AFTER_ANSWER : output;
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3684
|
+
};
|
|
3685
|
+
},
|
|
3686
|
+
wrap(model) {
|
|
3687
|
+
if (typeof model === "string") return model;
|
|
3688
|
+
return wrapLanguageModel4({
|
|
3689
|
+
model,
|
|
3690
|
+
middleware: {
|
|
3691
|
+
specificationVersion: "v4",
|
|
3692
|
+
wrapStream: async ({ doStream }) => {
|
|
3693
|
+
if (closes(step)) sealed = true;
|
|
3694
|
+
step?.end();
|
|
3695
|
+
const current = newStep();
|
|
3696
|
+
step = current;
|
|
3697
|
+
const result = await doStream();
|
|
3698
|
+
const transform = (part, controller) => {
|
|
3699
|
+
if (part.type === "text-start" || part.type === "text-delta" || part.type === "text-end") {
|
|
3700
|
+
if (sealed) {
|
|
3701
|
+
if (part.type === "text-delta") droppedChars += part.delta.length;
|
|
3702
|
+
return;
|
|
3703
|
+
}
|
|
3704
|
+
if (part.type === "text-delta" && hasText2(part.delta)) current.text = true;
|
|
3705
|
+
} else if (part.type === "tool-call") {
|
|
3706
|
+
current.calls.push(part.toolName);
|
|
3707
|
+
} else if (part.type === "finish" || part.type === "error") {
|
|
3708
|
+
current.end();
|
|
3709
|
+
}
|
|
3710
|
+
controller.enqueue(part);
|
|
3711
|
+
};
|
|
3712
|
+
return { ...result, stream: result.stream.pipeThrough(new TransformStream({ transform, flush: () => current.end() })) };
|
|
3713
|
+
}
|
|
3714
|
+
}
|
|
3715
|
+
});
|
|
3716
|
+
}
|
|
3717
|
+
};
|
|
3718
|
+
}
|
|
3719
|
+
function sealedByParts(parts, closes) {
|
|
3720
|
+
let current = newStep();
|
|
3721
|
+
for (const part of parts) {
|
|
3722
|
+
if (part.type === "step-start") {
|
|
3723
|
+
if (closes(current)) return true;
|
|
3724
|
+
current = newStep();
|
|
3725
|
+
} else if (part.type === "text" && hasText2(part.text)) current.text = true;
|
|
3726
|
+
else if (isToolPart4(part)) {
|
|
3727
|
+
const name = part.type === "dynamic-tool" ? part.toolName : part.type.slice("tool-".length);
|
|
3728
|
+
current.calls.push(name);
|
|
3729
|
+
if (name === SUGGESTIONS_TOOL && part.state === "output-available") current.shown = true;
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
return closes(current);
|
|
3733
|
+
}
|
|
3734
|
+
function sealedAnswerEndsOnTool(parts) {
|
|
3735
|
+
const lastCall = parts.findLastIndex(isToolPart4);
|
|
3736
|
+
return lastCall !== -1 && !parts.slice(lastCall + 1).some((part) => part.type === "text" && hasText2(part.text));
|
|
3737
|
+
}
|
|
3738
|
+
function isToolPart4(part) {
|
|
3739
|
+
return part.type.startsWith("tool-") || part.type === "dynamic-tool";
|
|
3740
|
+
}
|
|
3741
|
+
function hasText2(text) {
|
|
3742
|
+
return text.replace(/[\s\p{Cf}\p{Default_Ignorable_Code_Point}]/gu, "").length > 0;
|
|
3743
|
+
}
|
|
3744
|
+
function aborted(signal) {
|
|
3745
|
+
if (!signal) return new Promise(() => {
|
|
3746
|
+
});
|
|
3747
|
+
if (signal.aborted) return Promise.resolve();
|
|
3748
|
+
return new Promise((resolve) => signal.addEventListener("abort", () => resolve(), { once: true }));
|
|
3749
|
+
}
|
|
3750
|
+
|
|
3458
3751
|
// src/agent-run/tool-timeout.ts
|
|
3459
3752
|
var DEFAULT_TOOL_TIMEOUT_MS = 12e4;
|
|
3460
3753
|
var TOOL_TIMEOUT_HINT = /* @__PURE__ */ Symbol.for("@ykurilov/agent-chat.toolTimeoutMs");
|
|
@@ -3472,8 +3765,8 @@ function resolveToolTimeout(setting) {
|
|
|
3472
3765
|
const all = resolveTimeoutMs(setting, DEFAULT_TOOL_TIMEOUT_MS, "agent.toolTimeoutMs");
|
|
3473
3766
|
return { forTool: (_toolName, declaredMs) => atLeastDeclared(all, declaredMs) };
|
|
3474
3767
|
}
|
|
3475
|
-
if (!
|
|
3476
|
-
if (setting.byTool !== void 0 && !
|
|
3768
|
+
if (!isPlainObject2(setting)) throw new TypeError("agent.toolTimeoutMs: \u0436\u0434\u0451\u043C \u0447\u0438\u0441\u043B\u043E \u043C\u0441 \u0438\u043B\u0438 \u043E\u0431\u044A\u0435\u043A\u0442 { default?, byTool? }");
|
|
3769
|
+
if (setting.byTool !== void 0 && !isPlainObject2(setting.byTool)) {
|
|
3477
3770
|
throw new TypeError("agent.toolTimeoutMs.byTool: \u0436\u0434\u0451\u043C \u043E\u0431\u044A\u0435\u043A\u0442 \xAB\u0438\u043C\u044F \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u0430 \u2192 \u0441\u0440\u043E\u043A, \u043C\u0441\xBB");
|
|
3478
3771
|
}
|
|
3479
3772
|
const fallback = resolveTimeoutMs(setting.default, DEFAULT_TOOL_TIMEOUT_MS, "agent.toolTimeoutMs.default");
|
|
@@ -3485,7 +3778,7 @@ function resolveToolTimeout(setting) {
|
|
|
3485
3778
|
);
|
|
3486
3779
|
return { forTool: (toolName, declaredMs) => byTool.get(toolName) ?? atLeastDeclared(fallback, declaredMs) };
|
|
3487
3780
|
}
|
|
3488
|
-
function
|
|
3781
|
+
function isPlainObject2(value) {
|
|
3489
3782
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3490
3783
|
}
|
|
3491
3784
|
var toolTimeoutMessage = (timeoutMs) => `\u0418\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442 \u043D\u0435 \u043E\u0442\u0432\u0435\u0442\u0438\u043B \u0437\u0430 ${Math.max(1, Math.round(timeoutMs / 1e3))} \u0441 \u0438 \u043E\u0442\u043C\u0435\u043D\u0451\u043D. \u0412\u044B\u043F\u043E\u043B\u043D\u0435\u043D\u043E \u043B\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u043E; \u043D\u0435 \u043F\u043E\u0432\u0442\u043E\u0440\u044F\u0439 \u0435\u0433\u043E, \u043D\u0435 \u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0432`;
|
|
@@ -4302,13 +4595,13 @@ function usageMinusJournaled(usage, journaled) {
|
|
|
4302
4595
|
}
|
|
4303
4596
|
|
|
4304
4597
|
// src/agent-run/build-model-request.ts
|
|
4305
|
-
import { convertToModelMessages, wrapLanguageModel as
|
|
4598
|
+
import { convertToModelMessages, wrapLanguageModel as wrapLanguageModel7 } from "ai";
|
|
4306
4599
|
|
|
4307
4600
|
// src/conversation/hanging-tool-calls.ts
|
|
4308
4601
|
var PRELIMINARY_OUTPUT_MAX_LENGTH = 2e3;
|
|
4309
|
-
var
|
|
4602
|
+
var isToolPart5 = (part) => part.type.startsWith("tool-") || part.type === "dynamic-tool";
|
|
4310
4603
|
var isHangingToolCall = (part) => {
|
|
4311
|
-
if (!
|
|
4604
|
+
if (!isToolPart5(part)) return false;
|
|
4312
4605
|
const { state, preliminary } = part;
|
|
4313
4606
|
return state === "input-available" || state === "output-available" && preliminary === true;
|
|
4314
4607
|
};
|
|
@@ -4331,11 +4624,11 @@ function closeHangingToolCalls(parts, options2 = {}) {
|
|
|
4331
4624
|
});
|
|
4332
4625
|
}
|
|
4333
4626
|
var isFinished = (part) => {
|
|
4334
|
-
if (!
|
|
4627
|
+
if (!isToolPart5(part)) return false;
|
|
4335
4628
|
const { state, preliminary } = part;
|
|
4336
4629
|
return state === "output-available" && preliminary !== true || state === "output-error" || state === "output-denied";
|
|
4337
4630
|
};
|
|
4338
|
-
var isStreamingInput = (part) =>
|
|
4631
|
+
var isStreamingInput = (part) => isToolPart5(part) && part.state === "input-streaming";
|
|
4339
4632
|
function withoutProviderData(part) {
|
|
4340
4633
|
const { providerMetadata: _provider, callProviderMetadata: _call, resultProviderMetadata: _result, ...rest } = part;
|
|
4341
4634
|
return rest;
|
|
@@ -4410,10 +4703,10 @@ function autoContinuePauseMs(input) {
|
|
|
4410
4703
|
const requested = requestedRetryMs(input.error, (input.now ?? Date.now)()) ?? 0;
|
|
4411
4704
|
return Math.min(Math.max(requested, scheduled), MAX_REQUESTED_PAUSE_MS);
|
|
4412
4705
|
}
|
|
4413
|
-
var
|
|
4706
|
+
var isToolPart6 = (part) => part.type.startsWith("tool-") || part.type === "dynamic-tool";
|
|
4414
4707
|
function isFinished2(part) {
|
|
4415
4708
|
const { state, preliminary } = part;
|
|
4416
|
-
if (
|
|
4709
|
+
if (isToolPart6(part)) return state === "output-available" && preliminary !== true || state === "output-error" || state === "output-denied";
|
|
4417
4710
|
return state === "done";
|
|
4418
4711
|
}
|
|
4419
4712
|
function partsLeftOutOfAutoContinue(parts) {
|
|
@@ -4421,7 +4714,7 @@ function partsLeftOutOfAutoContinue(parts) {
|
|
|
4421
4714
|
const left = [];
|
|
4422
4715
|
parts.forEach((part, index) => {
|
|
4423
4716
|
const { state } = part;
|
|
4424
|
-
if (
|
|
4717
|
+
if (isToolPart6(part) && state === "input-streaming") left.push(index);
|
|
4425
4718
|
else if (part.type === "reasoning" && state === "streaming" && index > lastFinished) left.push(index);
|
|
4426
4719
|
});
|
|
4427
4720
|
return left;
|
|
@@ -4452,7 +4745,7 @@ var UNSENT_TOOL_CALL_REASON = "\u0412\u044B\u0437\u043E\u0432 \u043E\u0431\u043E
|
|
|
4452
4745
|
function closingChunksForHangingCalls(parts) {
|
|
4453
4746
|
const lastStep = parts.findLastIndex((part) => part.type === "step-start");
|
|
4454
4747
|
return parts.slice(lastStep + 1).flatMap((part) => {
|
|
4455
|
-
if (!
|
|
4748
|
+
if (!isToolPart6(part)) return [];
|
|
4456
4749
|
const { toolCallId, state, toolName } = part;
|
|
4457
4750
|
if (isHangingToolCall(part)) return [{ type: "tool-output-error", toolCallId, errorText: hangingToolCallText(part) }];
|
|
4458
4751
|
if (state !== "input-streaming") return [];
|
|
@@ -4522,7 +4815,7 @@ ${chunk.delta}` } : chunk];
|
|
|
4522
4815
|
}
|
|
4523
4816
|
|
|
4524
4817
|
// src/agent-run/observe-model-calls.ts
|
|
4525
|
-
import { wrapLanguageModel as
|
|
4818
|
+
import { wrapLanguageModel as wrapLanguageModel5 } from "ai";
|
|
4526
4819
|
function observeModelCalls(model, context) {
|
|
4527
4820
|
if (typeof model === "string") return model;
|
|
4528
4821
|
const now = context.now ?? Date.now;
|
|
@@ -4532,7 +4825,7 @@ function observeModelCalls(model, context) {
|
|
|
4532
4825
|
attempts.set(params.prompt, attempt);
|
|
4533
4826
|
return attempt;
|
|
4534
4827
|
};
|
|
4535
|
-
return
|
|
4828
|
+
return wrapLanguageModel5({
|
|
4536
4829
|
model,
|
|
4537
4830
|
middleware: {
|
|
4538
4831
|
specificationVersion: "v4",
|
|
@@ -4929,7 +5222,7 @@ function withoutUndelivered(history) {
|
|
|
4929
5222
|
}
|
|
4930
5223
|
|
|
4931
5224
|
// src/agent-run/garbled-tail.ts
|
|
4932
|
-
import { wrapLanguageModel as
|
|
5225
|
+
import { wrapLanguageModel as wrapLanguageModel6 } from "ai";
|
|
4933
5226
|
var SIGN_ORDER = ["think", "role", "restart", "tool"];
|
|
4934
5227
|
var TOKEN_SOURCE = String.raw`<\/?think>|<\|[^|\n<>]{1,40}\|>|<|[^|\n<>]{1,40}|>`;
|
|
4935
5228
|
var TEMPLATE_TOKEN = new RegExp(TOKEN_SOURCE, "g");
|
|
@@ -5101,7 +5394,7 @@ function createGarbledTailGuard() {
|
|
|
5101
5394
|
/** Модель попытки под присмотром: каждый запрос — новый шаг. */
|
|
5102
5395
|
wrap(model) {
|
|
5103
5396
|
if (typeof model === "string") return model;
|
|
5104
|
-
return
|
|
5397
|
+
return wrapLanguageModel6({
|
|
5105
5398
|
model,
|
|
5106
5399
|
middleware: {
|
|
5107
5400
|
specificationVersion: "v4",
|
|
@@ -5123,7 +5416,7 @@ function createGarbledTailGuard() {
|
|
|
5123
5416
|
isDroppedCall: (part) => part === DROPPED_CALL
|
|
5124
5417
|
};
|
|
5125
5418
|
}
|
|
5126
|
-
var
|
|
5419
|
+
var isToolPart7 = (part) => part.type.startsWith("tool-") || part.type === "dynamic-tool";
|
|
5127
5420
|
function stepsOf(parts) {
|
|
5128
5421
|
const steps = [];
|
|
5129
5422
|
let current = { from: 0, to: 0, texts: [] };
|
|
@@ -5154,7 +5447,7 @@ function garbleInStep(parts, step, markers) {
|
|
|
5154
5447
|
if (roles.some(after)) others.add("restart");
|
|
5155
5448
|
if (role.bareRole.glued) {
|
|
5156
5449
|
if (gluedAfter()) others.add("restart");
|
|
5157
|
-
if (parts.slice(role.partIndex + 1, step.to).some(
|
|
5450
|
+
if (parts.slice(role.partIndex + 1, step.to).some(isToolPart7)) others.add("tool");
|
|
5158
5451
|
}
|
|
5159
5452
|
}
|
|
5160
5453
|
if (others.size === 0) return null;
|
|
@@ -5339,7 +5632,7 @@ function withoutLoneSurrogatesDeep(value) {
|
|
|
5339
5632
|
}
|
|
5340
5633
|
function withRequestWatch(model, provider, watch) {
|
|
5341
5634
|
if (!watch || typeof model === "string") return model;
|
|
5342
|
-
return
|
|
5635
|
+
return wrapLanguageModel7({
|
|
5343
5636
|
model,
|
|
5344
5637
|
middleware: {
|
|
5345
5638
|
specificationVersion: "v4",
|
|
@@ -5359,7 +5652,7 @@ function withRequestWatch(model, provider, watch) {
|
|
|
5359
5652
|
});
|
|
5360
5653
|
}
|
|
5361
5654
|
function withTransientRetries(model, context) {
|
|
5362
|
-
return typeof model === "string" ? model :
|
|
5655
|
+
return typeof model === "string" ? model : wrapLanguageModel7({ model, middleware: createTransientRetryMiddleware(context) });
|
|
5363
5656
|
}
|
|
5364
5657
|
function withLastMessageMark(messages, options2) {
|
|
5365
5658
|
if (!options2 || messages.length === 0) return messages;
|
|
@@ -7251,6 +7544,7 @@ async function runTurn(turnInput, emitRaw) {
|
|
|
7251
7544
|
const turnUsage = createTurnUsage();
|
|
7252
7545
|
const garbledTail = createGarbledTailGuard();
|
|
7253
7546
|
const forgedBlocks = createForgedBlockGuard(turnInput.serviceBlocks ?? CORE_SERVICE_BLOCKS);
|
|
7547
|
+
const sealedAnswer = createSealedAnswerGuard(turnInput.serviceTools);
|
|
7254
7548
|
const turnBudget = createTurnBudget(input.turnRules, { catalog: input.catalog, modelId: input.modelId, turnUsage });
|
|
7255
7549
|
const messageUsage = () => {
|
|
7256
7550
|
const spent = turnUsage.total();
|
|
@@ -7467,6 +7761,7 @@ async function runTurn(turnInput, emitRaw) {
|
|
|
7467
7761
|
}
|
|
7468
7762
|
attemptAllowed = false;
|
|
7469
7763
|
if (attemptsOpened > 1) endTurns.nextAttempt(await saver.snapshot());
|
|
7764
|
+
sealedAnswer.reset((attemptsOpened > 1 ? await saver.snapshot() : resume?.message.parts ?? []).slice(resume && !resume.replay ? resume.message.parts.length : 0));
|
|
7470
7765
|
let provider;
|
|
7471
7766
|
const classify = (error2) => classifyProviderError(error2, provider);
|
|
7472
7767
|
let attempt;
|
|
@@ -7493,6 +7788,7 @@ async function runTurn(turnInput, emitRaw) {
|
|
|
7493
7788
|
turnBudget,
|
|
7494
7789
|
garbledTail,
|
|
7495
7790
|
forgedBlocks,
|
|
7791
|
+
sealedAnswer,
|
|
7496
7792
|
// Есть куда перейти при молчании — у того же провайдера оно не повторяется.
|
|
7497
7793
|
repeatSilence: () => silenceTarget() === void 0,
|
|
7498
7794
|
retryDelaysMs: () => !contentSeen && !fallbackUsed && remainingFallbacks().length > 0 && stepsDone < maxSteps ? (input.providerFallback || {}).retryDelaysMs ?? FALLBACK_RETRY_DELAYS_MS : void 0,
|
|
@@ -7701,7 +7997,9 @@ async function runTurn(turnInput, emitRaw) {
|
|
|
7701
7997
|
emitNow({ type: "tool-output-error", toolCallId, errorText: ONE_QUESTION_AT_A_TIME });
|
|
7702
7998
|
}
|
|
7703
7999
|
}
|
|
7704
|
-
if (
|
|
8000
|
+
if (sealedAnswer.droppedChars() > 0) logError(`[\u0434\u043E\u043F\u0438\u0441\u043A\u0430 \u043F\u043E\u0441\u043B\u0435 \u043F\u043E\u0434\u0441\u043A\u0430\u0437\u043E\u043A \u043D\u0435 \u043F\u043E\u043A\u0430\u0437\u0430\u043D\u0430] \u0447\u0430\u0442=${input.chatId} \u043C\u043E\u0434\u0435\u043B\u044C=${modelId} \u0437\u043D\u0430\u043A\u043E\u0432=${sealedAnswer.droppedChars()}`);
|
|
8001
|
+
const sealedOnTool = sealedAnswer.sealed() && sealedAnswerEndsOnTool(await saver.snapshot());
|
|
8002
|
+
if ((endTurns.endedWithoutText() || sealedOnTool) && !input.abortSignal.aborted && errors.length === 0) {
|
|
7705
8003
|
const parts2 = await saver.snapshot();
|
|
7706
8004
|
if (pendingHumanInput(parts2, input.waitingWidgets).length === 0) {
|
|
7707
8005
|
if (parts2.at(-1)?.type !== "step-start") saver.observe({ type: "start-step" });
|
|
@@ -7982,7 +8280,7 @@ async function openAttempt(input, attempt, attemptSignal) {
|
|
|
7982
8280
|
const providerId = found.provider.id;
|
|
7983
8281
|
const limit = input.toolResultLimit ?? DEFAULT_TOOL_RESULT_LIMIT;
|
|
7984
8282
|
const toolsModel = turnToolsModel(input, found, attempt);
|
|
7985
|
-
const appTools = attempt.endTurns.tools(onlyAllowedTools(typeof input.tools === "function" ? input.tools(toolsModel) : input.tools, input.group));
|
|
8283
|
+
const appTools = attempt.endTurns.tools(attempt.sealedAnswer.tools(onlyAllowedTools(typeof input.tools === "function" ? input.tools(toolsModel) : input.tools, input.group)));
|
|
7986
8284
|
const toolTimeout = input.toolTimeout ?? DEFAULT_TOOL_TIMEOUT;
|
|
7987
8285
|
const serverTools = withSequentialTools(
|
|
7988
8286
|
withToolTimeout(appTools, {
|
|
@@ -8028,6 +8326,7 @@ async function openAttempt(input, attempt, attemptSignal) {
|
|
|
8028
8326
|
toolTimeout: _toolTimeout,
|
|
8029
8327
|
repairToolInput: _repairToolInput,
|
|
8030
8328
|
sequentialTools: _sequentialTools,
|
|
8329
|
+
serviceTools: _serviceTools,
|
|
8031
8330
|
now: _now,
|
|
8032
8331
|
usageSource: _usageSource,
|
|
8033
8332
|
replyChecks: _replyChecks,
|
|
@@ -8093,8 +8392,8 @@ async function openAttempt(input, attempt, attemptSignal) {
|
|
|
8093
8392
|
attempt.forgedBlocks.reset(lastQuestionOf(attempt.history));
|
|
8094
8393
|
const result = streamText({
|
|
8095
8394
|
...modelRequest,
|
|
8096
|
-
// Сначала вырезка блоков, потом проверка на кашу: каша судит уже чистый текст.
|
|
8097
|
-
model: attempt.garbledTail.wrap(attempt.forgedBlocks.wrap(modelRequest.model)),
|
|
8395
|
+
// Сначала вырезка блоков, потом дописка после закрытого ответа, потом проверка на кашу: каша судит уже чистый текст.
|
|
8396
|
+
model: attempt.garbledTail.wrap(attempt.sealedAnswer.wrap(attempt.forgedBlocks.wrap(modelRequest.model))),
|
|
8098
8397
|
...approval.toolApproval && { toolApproval: gateToolApproval(approval.toolApproval, () => toolsClosed) },
|
|
8099
8398
|
// Попытке — остаток шагов хода.
|
|
8100
8399
|
// Помощник встал на подтверждении человека — ход ждёт, модель основного агента его незаконченным не видит.
|
|
@@ -8917,9 +9216,9 @@ function editAnswerParts(parts, edit, uneditable) {
|
|
|
8917
9216
|
return { ok: true, parts: textPlaced ? edited : [...edited, textPart] };
|
|
8918
9217
|
}
|
|
8919
9218
|
function toolCallIdOf(part) {
|
|
8920
|
-
return
|
|
9219
|
+
return isToolPart8(part) ? part.toolCallId : void 0;
|
|
8921
9220
|
}
|
|
8922
|
-
var
|
|
9221
|
+
var isToolPart8 = (part) => part.type.startsWith("tool-") || part.type === "dynamic-tool";
|
|
8923
9222
|
function toolNameOf2(part) {
|
|
8924
9223
|
return part.type === "dynamic-tool" ? part.toolName : part.type.slice("tool-".length);
|
|
8925
9224
|
}
|
|
@@ -9324,7 +9623,7 @@ var fireworksProvider = createFireworksProvider();
|
|
|
9324
9623
|
|
|
9325
9624
|
// src/models/providers/openrouter.ts
|
|
9326
9625
|
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
|
|
9327
|
-
import { wrapLanguageModel as
|
|
9626
|
+
import { wrapLanguageModel as wrapLanguageModel8 } from "ai";
|
|
9328
9627
|
|
|
9329
9628
|
// src/models/providers/openrouter-cache-mark-limit.ts
|
|
9330
9629
|
function openrouterCacheMarkLimit(providerModelId) {
|
|
@@ -9575,7 +9874,7 @@ function createOpenRouterProvider(options2 = {}) {
|
|
|
9575
9874
|
createLanguageModel: (providerModelId, apiKey, requestOptions) => {
|
|
9576
9875
|
const markLimit = openrouterCacheMarkLimit(providerModelId);
|
|
9577
9876
|
const fetch = markLimit === void 0 ? requestOptions?.fetch : fetchWithCacheMarkLimit(requestOptions?.fetch, markLimit);
|
|
9578
|
-
return
|
|
9877
|
+
return wrapLanguageModel8({
|
|
9579
9878
|
model: createOpenRouter({ apiKey, fetch, ...connection }).chat(providerModelId, routingOptions),
|
|
9580
9879
|
middleware: [
|
|
9581
9880
|
openrouterRoutingMiddleware(routing),
|
|
@@ -10204,15 +10503,15 @@ async function closeState(storage, messageId, state, appendParts, logError, wher
|
|
|
10204
10503
|
}
|
|
10205
10504
|
}
|
|
10206
10505
|
function pause(ms, signal) {
|
|
10207
|
-
const
|
|
10506
|
+
const aborted2 = whenAborted(signal);
|
|
10208
10507
|
return new Promise((resolve) => {
|
|
10209
10508
|
const timer = setTimeout(resolve, ms);
|
|
10210
10509
|
timer.unref?.();
|
|
10211
|
-
void
|
|
10510
|
+
void aborted2.promise.then(() => {
|
|
10212
10511
|
clearTimeout(timer);
|
|
10213
10512
|
resolve();
|
|
10214
10513
|
});
|
|
10215
|
-
}).finally(
|
|
10514
|
+
}).finally(aborted2.dispose);
|
|
10216
10515
|
}
|
|
10217
10516
|
function whenAborted(signal) {
|
|
10218
10517
|
let onAbort = () => {
|
|
@@ -11371,184 +11670,6 @@ function isHiddenChoice(catalog, choice) {
|
|
|
11371
11670
|
return catalog.providers.some((provider) => provider.id === choice.providerId && provider.hiddenFromMenu === true);
|
|
11372
11671
|
}
|
|
11373
11672
|
|
|
11374
|
-
// src/widgets/basic-widgets.ts
|
|
11375
|
-
import { tool as tool2 } from "ai";
|
|
11376
|
-
import { z as z2 } from "zod";
|
|
11377
|
-
var BASIC_WIDGET_NAMES = ["ask_choice", "ask_form", "ask_multi_choice", "ask_rating", "suggest_replies"];
|
|
11378
|
-
var SUGGESTIONS_SHOWN = "\u043F\u043E\u043A\u0430\u0437\u0430\u043D\u043E";
|
|
11379
|
-
var FORM_TEXT_MAX = 2e3;
|
|
11380
|
-
var question = z2.string().min(1).max(300);
|
|
11381
|
-
var options = z2.array(z2.string().min(1).max(80)).min(2).max(8).refine((values) => new Set(values).size === values.length, "\u0412\u0430\u0440\u0438\u0430\u043D\u0442\u044B \u043D\u0435 \u0434\u043E\u043B\u0436\u043D\u044B \u043F\u043E\u0432\u0442\u043E\u0440\u044F\u0442\u044C\u0441\u044F");
|
|
11382
|
-
var choiceInput = z2.object({ question, options });
|
|
11383
|
-
var multiChoiceInput = z2.object({ question, options, min: z2.number().int().optional(), max: z2.number().int().optional() }).superRefine((input, context) => {
|
|
11384
|
-
const { min, max } = multiChoiceLimits(input);
|
|
11385
|
-
if (min < 1 || min > max || max > input.options.length) {
|
|
11386
|
-
context.addIssue({ code: "custom", message: "\u041D\u0443\u0436\u043D\u043E 1 \u2264 min \u2264 max \u2264 \u0447\u0438\u0441\u043B\u0430 \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u043E\u0432", path: ["min"] });
|
|
11387
|
-
}
|
|
11388
|
-
});
|
|
11389
|
-
var ratingInput = z2.object({
|
|
11390
|
-
question,
|
|
11391
|
-
scale: z2.enum(["stars", "range"]),
|
|
11392
|
-
from: z2.union([z2.literal(0), z2.literal(1)]).optional(),
|
|
11393
|
-
to: z2.number().int().min(2).max(10).optional(),
|
|
11394
|
-
fromLabel: z2.string().min(1).max(40).optional(),
|
|
11395
|
-
toLabel: z2.string().min(1).max(40).optional()
|
|
11396
|
-
}).superRefine((input, context) => {
|
|
11397
|
-
const rangeFields = [input.from, input.to, input.fromLabel, input.toLabel].some((value) => value !== void 0);
|
|
11398
|
-
if (input.scale === "stars" && rangeFields) context.addIssue({ code: "custom", message: "\u0423 \u0437\u0432\u0451\u0437\u0434 \u043D\u0435\u0442 from, to \u0438 \u043F\u043E\u0434\u043F\u0438\u0441\u0435\u0439", path: ["scale"] });
|
|
11399
|
-
if (input.scale === "range" && (input.from === void 0 || input.to === void 0)) {
|
|
11400
|
-
context.addIssue({ code: "custom", message: "\u0423 \u0448\u043A\u0430\u043B\u044B range \u043D\u0443\u0436\u043D\u044B from (0 \u0438\u043B\u0438 1) \u0438 to (2\u201310)", path: ["from"] });
|
|
11401
|
-
}
|
|
11402
|
-
});
|
|
11403
|
-
var formField = z2.object({
|
|
11404
|
-
name: z2.string().regex(/^[A-Za-z0-9_]+$/, "name \u2014 \u043B\u0430\u0442\u0438\u043D\u0438\u0446\u0430, \u0446\u0438\u0444\u0440\u044B \u0438 _").max(64),
|
|
11405
|
-
label: z2.string().min(1).max(80),
|
|
11406
|
-
kind: z2.enum(["text", "number", "date", "select"]),
|
|
11407
|
-
required: z2.boolean().optional(),
|
|
11408
|
-
min: z2.union([z2.number(), z2.string()]).optional(),
|
|
11409
|
-
max: z2.union([z2.number(), z2.string()]).optional(),
|
|
11410
|
-
options: options.optional(),
|
|
11411
|
-
multiline: z2.boolean().optional()
|
|
11412
|
-
}).superRefine((field, context) => {
|
|
11413
|
-
const issue = (message) => context.addIssue({ code: "custom", message, path: [field.name] });
|
|
11414
|
-
if (field.kind === "select" && !field.options) issue("\u0423 select \u043D\u0443\u0436\u043D\u044B options: 2\u20138 \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u043E\u0432");
|
|
11415
|
-
if (field.kind !== "select" && field.options) issue("options \u2014 \u0442\u043E\u043B\u044C\u043A\u043E \u0443 select");
|
|
11416
|
-
if (field.kind === "number") {
|
|
11417
|
-
if (field.min !== void 0 && typeof field.min !== "number" || field.max !== void 0 && typeof field.max !== "number") issue("\u0423 number min \u0438 max \u2014 \u0447\u0438\u0441\u043B\u0430");
|
|
11418
|
-
else if (field.min !== void 0 && field.max !== void 0 && field.min > field.max) issue("\u0423 number \u043D\u0443\u0436\u043D\u043E min \u2264 max");
|
|
11419
|
-
} else if (field.kind === "date") {
|
|
11420
|
-
const dates = [field.min, field.max].filter((value) => value !== void 0);
|
|
11421
|
-
if (dates.some((value) => typeof value !== "string" || !isCalendarDate(value))) issue("\u0423 date min \u0438 max \u2014 \u0434\u0430\u0442\u044B YYYY-MM-DD");
|
|
11422
|
-
else if (field.min !== void 0 && field.max !== void 0 && field.min > field.max) issue("\u0423 date \u043D\u0443\u0436\u043D\u043E min \u2264 max");
|
|
11423
|
-
} else if (field.min !== void 0 || field.max !== void 0) {
|
|
11424
|
-
issue("min \u0438 max \u2014 \u0442\u043E\u043B\u044C\u043A\u043E \u0443 number \u0438 date");
|
|
11425
|
-
}
|
|
11426
|
-
});
|
|
11427
|
-
var formInput = z2.object({
|
|
11428
|
-
title: z2.string().min(1).max(300),
|
|
11429
|
-
fields: z2.array(formField).min(1).max(5).refine((fields) => new Set(fields.map((field) => field.name)).size === fields.length, "\u0418\u043C\u0435\u043D\u0430 \u043F\u043E\u043B\u0435\u0439 \u043D\u0435 \u0434\u043E\u043B\u0436\u043D\u044B \u043F\u043E\u0432\u0442\u043E\u0440\u044F\u0442\u044C\u0441\u044F")
|
|
11430
|
-
});
|
|
11431
|
-
var suggestInput = z2.object({ replies: z2.array(z2.string().min(1).max(60)).min(1).max(4) });
|
|
11432
|
-
var ANSWERED_BY_MESSAGE_NOTE = '\u0415\u0441\u043B\u0438 \u0447\u0435\u043B\u043E\u0432\u0435\u043A \u043E\u0442\u0432\u0435\u0442\u0438\u0442 \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435\u043C, \u0430 \u043D\u0435 \u0432 \u0432\u0438\u0434\u0436\u0435\u0442\u0435, \u0440\u0435\u0437\u0443\u043B\u044C\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 {"\u043E\u0442\u0432\u0435\u0442":"\u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435\u043C"}, \u0430 \u0435\u0433\u043E \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435 \u043F\u0440\u0438\u0434\u0451\u0442 \u0441\u043B\u0435\u0434\u043E\u043C.';
|
|
11433
|
-
var ONE_QUESTION_NOTE = "\u0417\u0430\u0434\u0430\u0432\u0430\u0439 \u043E\u0434\u0438\u043D \u0432\u043E\u043F\u0440\u043E\u0441 \u0437\u0430 \u0440\u0430\u0437: \u043D\u0435 \u0431\u043E\u043B\u044C\u0448\u0435 \u043E\u0434\u043D\u043E\u0433\u043E \u0442\u0430\u043A\u043E\u0433\u043E \u0432\u044B\u0437\u043E\u0432\u0430 \u0432 \u0448\u0430\u0433\u0435.";
|
|
11434
|
-
var TOOLS = {
|
|
11435
|
-
ask_choice: tool2({
|
|
11436
|
-
description: `\u0421\u043F\u0440\u043E\u0441\u0438\u0442\u044C \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 \u0438 \u0434\u0430\u0442\u044C \u0432\u044B\u0431\u0440\u0430\u0442\u044C \u043E\u0434\u0438\u043D \u0432\u0430\u0440\u0438\u0430\u043D\u0442 \u0438\u0437 2\u20138 \u043A\u043D\u043E\u043F\u043E\u043A. \u041E\u0442\u0432\u0435\u0442 \u0436\u0434\u0451\u0442 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 \u0438 \u043F\u0440\u0438\u0445\u043E\u0434\u0438\u0442 \u043A\u0430\u043A {"\u0432\u044B\u0431\u0440\u0430\u043D\u043E":"<\u0432\u0430\u0440\u0438\u0430\u043D\u0442>"}. ${ONE_QUESTION_NOTE} ${ANSWERED_BY_MESSAGE_NOTE}`,
|
|
11437
|
-
inputSchema: choiceInput
|
|
11438
|
-
}),
|
|
11439
|
-
ask_multi_choice: tool2({
|
|
11440
|
-
description: `\u0421\u043F\u0440\u043E\u0441\u0438\u0442\u044C \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 \u0438 \u0434\u0430\u0442\u044C \u0432\u044B\u0431\u0440\u0430\u0442\u044C \u043D\u0435\u0441\u043A\u043E\u043B\u044C\u043A\u043E \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u043E\u0432 \u0438\u0437 2\u20138 (min \u0438 max \u2014 \u0441\u043A\u043E\u043B\u044C\u043A\u043E \u043C\u043E\u0436\u043D\u043E \u0432\u044B\u0431\u0440\u0430\u0442\u044C). \u041E\u0442\u0432\u0435\u0442 \u043F\u0440\u0438\u0445\u043E\u0434\u0438\u0442 \u043A\u0430\u043A {"\u0432\u044B\u0431\u0440\u0430\u043D\u043E":["<\u0432\u0430\u0440\u0438\u0430\u043D\u0442>",\u2026]} \u0432 \u043F\u043E\u0440\u044F\u0434\u043A\u0435 \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u043E\u0432. ${ONE_QUESTION_NOTE} ${ANSWERED_BY_MESSAGE_NOTE}`,
|
|
11441
|
-
inputSchema: multiChoiceInput
|
|
11442
|
-
}),
|
|
11443
|
-
ask_rating: tool2({
|
|
11444
|
-
description: `\u041F\u043E\u043F\u0440\u043E\u0441\u0438\u0442\u044C \u043E\u0446\u0435\u043D\u043A\u0443: \u0437\u0432\u0451\u0437\u0434\u044B 1\u20135 (scale "stars") \u0438\u043B\u0438 \u0448\u043A\u0430\u043B\u0430 \u043E\u0442 from (0 \u0438\u043B\u0438 1) \u0434\u043E to (2\u201310) \u0441 \u043F\u043E\u0434\u043F\u0438\u0441\u044F\u043C\u0438 \u043A\u0440\u0430\u0451\u0432 (scale "range"). \u041E\u0442\u0432\u0435\u0442 \u043F\u0440\u0438\u0445\u043E\u0434\u0438\u0442 \u043A\u0430\u043A {"\u043E\u0446\u0435\u043D\u043A\u0430":<\u0446\u0435\u043B\u043E\u0435>}. ${ONE_QUESTION_NOTE} ${ANSWERED_BY_MESSAGE_NOTE}`,
|
|
11445
|
-
inputSchema: ratingInput
|
|
11446
|
-
}),
|
|
11447
|
-
ask_form: tool2({
|
|
11448
|
-
description: `\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u043A\u043E\u0440\u043E\u0442\u043A\u0443\u044E \u0444\u043E\u0440\u043C\u0443 \u0438\u0437 1\u20135 \u043F\u043E\u043B\u0435\u0439: text, number (min, max), date (YYYY-MM-DD), select (2\u20138 \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u043E\u0432). \u041E\u0442\u0432\u0435\u0442 \u043F\u0440\u0438\u0445\u043E\u0434\u0438\u0442 \u043A\u0430\u043A {"\u043F\u043E\u043B\u044F":{"<name>":<\u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435>}}; \u043F\u0443\u0441\u0442\u044B\u0435 \u043D\u0435\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u044B\u0435 \u043F\u043E\u043B\u044F \u043D\u0435 \u043F\u0440\u0438\u0445\u043E\u0434\u044F\u0442. ${ONE_QUESTION_NOTE} ${ANSWERED_BY_MESSAGE_NOTE}`,
|
|
11449
|
-
inputSchema: formInput
|
|
11450
|
-
}),
|
|
11451
|
-
suggest_replies: tool2({
|
|
11452
|
-
description: `\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u043F\u043E\u0434 \u043E\u0442\u0432\u0435\u0442\u043E\u043C 1\u20134 \u043A\u043E\u0440\u043E\u0442\u043A\u0438\u0445 \u043F\u043E\u0434\u0441\u043A\u0430\u0437\u043A\u0438, \u043A\u043E\u0442\u043E\u0440\u044B\u0435 \u0447\u0435\u043B\u043E\u0432\u0435\u043A \u043C\u043E\u0436\u0435\u0442 \u043E\u0442\u043F\u0440\u0430\u0432\u0438\u0442\u044C \u043E\u0434\u043D\u0438\u043C \u043D\u0430\u0436\u0430\u0442\u0438\u0435\u043C. \u0425\u043E\u0434 \u043D\u0435 \u0436\u0434\u0451\u0442: \u0440\u0435\u0437\u0443\u043B\u044C\u0442\u0430\u0442 \u0441\u0440\u0430\u0437\u0443 "${SUGGESTIONS_SHOWN}". \u041D\u0430\u0436\u0430\u0442\u0430\u044F \u043F\u043E\u0434\u0441\u043A\u0430\u0437\u043A\u0430 \u043F\u0440\u0438\u0434\u0451\u0442 \u043E\u0431\u044B\u0447\u043D\u044B\u043C \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435\u043C.`,
|
|
11453
|
-
inputSchema: suggestInput,
|
|
11454
|
-
execute: () => SUGGESTIONS_SHOWN
|
|
11455
|
-
})
|
|
11456
|
-
};
|
|
11457
|
-
function basicWidgetTool(name) {
|
|
11458
|
-
return TOOLS[name];
|
|
11459
|
-
}
|
|
11460
|
-
function checkBasicWidgetAnswer(name, input, answer) {
|
|
11461
|
-
switch (name) {
|
|
11462
|
-
case "ask_choice":
|
|
11463
|
-
return checkChoice(input, answer);
|
|
11464
|
-
case "ask_multi_choice":
|
|
11465
|
-
return checkMultiChoice(input, answer);
|
|
11466
|
-
case "ask_rating":
|
|
11467
|
-
return checkRating(input, answer);
|
|
11468
|
-
case "ask_form":
|
|
11469
|
-
return checkForm(input, answer);
|
|
11470
|
-
case "suggest_replies":
|
|
11471
|
-
return REJECTED;
|
|
11472
|
-
}
|
|
11473
|
-
}
|
|
11474
|
-
var REJECTED = { ok: false };
|
|
11475
|
-
function checkChoice(input, answer) {
|
|
11476
|
-
const call = choiceInput.safeParse(input);
|
|
11477
|
-
const value = onlyField(answer, "\u0432\u044B\u0431\u0440\u0430\u043D\u043E");
|
|
11478
|
-
if (!call.success || typeof value !== "string" || !call.data.options.includes(value)) return REJECTED;
|
|
11479
|
-
return { ok: true, output: { \u0432\u044B\u0431\u0440\u0430\u043D\u043E: value } };
|
|
11480
|
-
}
|
|
11481
|
-
function checkMultiChoice(input, answer) {
|
|
11482
|
-
const call = multiChoiceInput.safeParse(input);
|
|
11483
|
-
const value = onlyField(answer, "\u0432\u044B\u0431\u0440\u0430\u043D\u043E");
|
|
11484
|
-
if (!call.success || !Array.isArray(value)) return REJECTED;
|
|
11485
|
-
const chosen = new Set(value);
|
|
11486
|
-
const { min, max } = multiChoiceLimits(call.data);
|
|
11487
|
-
const known = value.every((option) => typeof option === "string" && call.data.options.includes(option));
|
|
11488
|
-
if (!known || chosen.size !== value.length || value.length < min || value.length > max) return REJECTED;
|
|
11489
|
-
return { ok: true, output: { \u0432\u044B\u0431\u0440\u0430\u043D\u043E: call.data.options.filter((option) => chosen.has(option)) } };
|
|
11490
|
-
}
|
|
11491
|
-
function checkRating(input, answer) {
|
|
11492
|
-
const call = ratingInput.safeParse(input);
|
|
11493
|
-
const value = onlyField(answer, "\u043E\u0446\u0435\u043D\u043A\u0430");
|
|
11494
|
-
if (!call.success || typeof value !== "number" || !Number.isInteger(value)) return REJECTED;
|
|
11495
|
-
const { from, to } = ratingLimits(call.data);
|
|
11496
|
-
if (value < from || value > to) return REJECTED;
|
|
11497
|
-
return { ok: true, output: { \u043E\u0446\u0435\u043D\u043A\u0430: value } };
|
|
11498
|
-
}
|
|
11499
|
-
function checkForm(input, answer) {
|
|
11500
|
-
const call = formInput.safeParse(input);
|
|
11501
|
-
const values = onlyField(answer, "\u043F\u043E\u043B\u044F");
|
|
11502
|
-
if (!call.success || !isPlainObject2(values)) return REJECTED;
|
|
11503
|
-
const fields = call.data.fields;
|
|
11504
|
-
if (Object.keys(values).some((key) => !fields.some((field) => field.name === key))) return REJECTED;
|
|
11505
|
-
const output = {};
|
|
11506
|
-
for (const field of fields) {
|
|
11507
|
-
const value = values[field.name];
|
|
11508
|
-
if (isEmptyValue(value)) {
|
|
11509
|
-
if (field.required) return REJECTED;
|
|
11510
|
-
continue;
|
|
11511
|
-
}
|
|
11512
|
-
if (!fieldValueFits(field, value)) return REJECTED;
|
|
11513
|
-
output[field.name] = value;
|
|
11514
|
-
}
|
|
11515
|
-
return { ok: true, output: { \u043F\u043E\u043B\u044F: output } };
|
|
11516
|
-
}
|
|
11517
|
-
function fieldValueFits(field, value) {
|
|
11518
|
-
switch (field.kind) {
|
|
11519
|
-
case "text":
|
|
11520
|
-
return typeof value === "string" && value.length <= FORM_TEXT_MAX;
|
|
11521
|
-
case "number":
|
|
11522
|
-
return typeof value === "number" && Number.isFinite(value) && (typeof field.min !== "number" || value >= field.min) && (typeof field.max !== "number" || value <= field.max);
|
|
11523
|
-
case "date":
|
|
11524
|
-
return typeof value === "string" && isCalendarDate(value) && (typeof field.min !== "string" || value >= field.min) && (typeof field.max !== "string" || value <= field.max);
|
|
11525
|
-
case "select":
|
|
11526
|
-
return typeof value === "string" && (field.options ?? []).includes(value);
|
|
11527
|
-
}
|
|
11528
|
-
}
|
|
11529
|
-
function isEmptyValue(value) {
|
|
11530
|
-
return value === void 0 || value === null || typeof value === "string" && value.trim() === "";
|
|
11531
|
-
}
|
|
11532
|
-
function multiChoiceLimits(input) {
|
|
11533
|
-
return { min: input.min ?? 1, max: input.max ?? input.options.length };
|
|
11534
|
-
}
|
|
11535
|
-
function ratingLimits(input) {
|
|
11536
|
-
return input.scale === "stars" ? { from: 1, to: 5 } : { from: input.from ?? 0, to: input.to ?? 10 };
|
|
11537
|
-
}
|
|
11538
|
-
function onlyField(answer, key) {
|
|
11539
|
-
if (!isPlainObject2(answer)) return void 0;
|
|
11540
|
-
const keys = Object.keys(answer);
|
|
11541
|
-
return keys.length === 1 && keys[0] === key ? answer[key] : void 0;
|
|
11542
|
-
}
|
|
11543
|
-
function isPlainObject2(value) {
|
|
11544
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11545
|
-
}
|
|
11546
|
-
function isCalendarDate(value) {
|
|
11547
|
-
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
|
|
11548
|
-
const date = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
|
|
11549
|
-
return !Number.isNaN(date.getTime()) && date.toISOString().slice(0, 10) === value;
|
|
11550
|
-
}
|
|
11551
|
-
|
|
11552
11673
|
// src/widgets/define-widget.ts
|
|
11553
11674
|
var WIDGET_NAME = /^[a-z][a-z0-9_]{0,63}$/;
|
|
11554
11675
|
var RESERVED_PREFIXES = ["ask_", "suggest_"];
|
|
@@ -11880,7 +12001,7 @@ function isPlainObject3(value) {
|
|
|
11880
12001
|
}
|
|
11881
12002
|
|
|
11882
12003
|
// src/memory/memory-after-answer.ts
|
|
11883
|
-
import { wrapLanguageModel as
|
|
12004
|
+
import { wrapLanguageModel as wrapLanguageModel9 } from "ai";
|
|
11884
12005
|
var DRAIN_WAIT_MS = 5e3;
|
|
11885
12006
|
function createMemoryAfterAnswer({ memory, storage, catalog, env, logError, turnObserver }) {
|
|
11886
12007
|
const running = /* @__PURE__ */ new Set();
|
|
@@ -11925,7 +12046,7 @@ function createMemoryAfterAnswer({ memory, storage, catalog, env, logError, turn
|
|
|
11925
12046
|
};
|
|
11926
12047
|
}
|
|
11927
12048
|
function withRetries(model, context) {
|
|
11928
|
-
return typeof model === "string" ? model :
|
|
12049
|
+
return typeof model === "string" ? model : wrapLanguageModel9({ model, middleware: createTransientRetryMiddleware(context) });
|
|
11929
12050
|
}
|
|
11930
12051
|
|
|
11931
12052
|
// src/conversation/to-agent-chat-message.ts
|
|
@@ -13198,10 +13319,10 @@ async function prepareTurnSafely(input) {
|
|
|
13198
13319
|
}, timeoutMs);
|
|
13199
13320
|
const fail = (reason) => logError(`[prepareTurn] \u0447\u0430\u0442=${context.chatId} \u0445\u043E\u0434 \u0431\u0435\u0437 \u0437\u0430\u043F\u0438\u0441\u0435\u0439: ${reason}`);
|
|
13200
13321
|
try {
|
|
13201
|
-
const
|
|
13322
|
+
const aborted2 = new Promise((resolve) => controller.signal.addEventListener("abort", () => resolve("aborted"), { once: true }));
|
|
13202
13323
|
const result = await Promise.race([
|
|
13203
13324
|
Promise.resolve().then(() => input.prepareTurn({ ...context, state: publicAppState(input.state), abortSignal: controller.signal })),
|
|
13204
|
-
|
|
13325
|
+
aborted2
|
|
13205
13326
|
]);
|
|
13206
13327
|
if (result === "aborted") {
|
|
13207
13328
|
if (timedOut) fail(`\u043D\u0435 \u0443\u043B\u043E\u0436\u0438\u043B\u0441\u044F \u0432 ${timeoutMs} \u043C\u0441`);
|
|
@@ -13498,6 +13619,7 @@ function createChatService(input) {
|
|
|
13498
13619
|
toolTimeoutMs: toolTimeoutSetting,
|
|
13499
13620
|
repairToolInput,
|
|
13500
13621
|
sequentialTools: sequentialToolsSetting,
|
|
13622
|
+
serviceTools: serviceToolsSetting,
|
|
13501
13623
|
timeZone: timeZoneSetting,
|
|
13502
13624
|
modelSilenceTimeout,
|
|
13503
13625
|
widgets: _widgets,
|
|
@@ -13521,6 +13643,7 @@ function createChatService(input) {
|
|
|
13521
13643
|
const toolResultLimit = resolveToolResultLimit(toolResultMaxLength);
|
|
13522
13644
|
const toolTimeout = resolveToolTimeout(toolTimeoutSetting);
|
|
13523
13645
|
const sequentialTools = resolveSequentialTools(sequentialToolsSetting);
|
|
13646
|
+
const serviceTools = new Set(serviceToolsSetting ?? []);
|
|
13524
13647
|
const sdkScreenToolNames = /* @__PURE__ */ new Set([...Object.keys(widgets.tools), ...Object.keys(browserToolDescriptions ?? {})]);
|
|
13525
13648
|
const isScreenTool = (toolName) => sdkScreenToolNames.has(toolName);
|
|
13526
13649
|
const hiddenStateKey = hiddenStateKeyOf(options2.privateStateKeys);
|
|
@@ -14315,6 +14438,7 @@ function createChatService(input) {
|
|
|
14315
14438
|
toolTimeout,
|
|
14316
14439
|
...repairToolInput && { repairToolInput },
|
|
14317
14440
|
sequentialTools,
|
|
14441
|
+
serviceTools,
|
|
14318
14442
|
toolQueue,
|
|
14319
14443
|
stepContextTimeoutMs,
|
|
14320
14444
|
contextBlocksTimeoutMs,
|
|
@@ -15990,6 +16114,9 @@ export {
|
|
|
15990
16114
|
STEP_RESET_PART_TYPE,
|
|
15991
16115
|
STEPS_MAY_RESET_PART_TYPE,
|
|
15992
16116
|
withoutResetSteps,
|
|
16117
|
+
BASIC_WIDGET_NAMES,
|
|
16118
|
+
SUGGESTIONS_SHOWN,
|
|
16119
|
+
SUGGESTIONS_SHOWN_AFTER_ANSWER,
|
|
15993
16120
|
DEFAULT_TOOL_TIMEOUT_MS,
|
|
15994
16121
|
TOOL_TIMEOUT_HINT,
|
|
15995
16122
|
declareToolTimeout,
|
|
@@ -16067,8 +16194,6 @@ export {
|
|
|
16067
16194
|
IMPORT_MAX_IMAGE_BYTES,
|
|
16068
16195
|
InvalidModelChoiceError,
|
|
16069
16196
|
buildModelMenu,
|
|
16070
|
-
BASIC_WIDGET_NAMES,
|
|
16071
|
-
SUGGESTIONS_SHOWN,
|
|
16072
16197
|
defineWidget,
|
|
16073
16198
|
WIDGET_ANSWER_MAX_BYTES,
|
|
16074
16199
|
WidgetAnswerRefusedError,
|
|
@@ -16084,4 +16209,4 @@ export {
|
|
|
16084
16209
|
InvalidWidgetAnswerError,
|
|
16085
16210
|
createChatService
|
|
16086
16211
|
};
|
|
16087
|
-
//# sourceMappingURL=chunk-
|
|
16212
|
+
//# sourceMappingURL=chunk-WMVDYLNE.js.map
|