@rpcbase/agents-sdk 0.9.0 → 0.11.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/dist/agents-sdk.css +1 -1
- package/dist/api/apiErrors.d.ts.map +1 -1
- package/dist/api/chat/handler.d.ts.map +1 -1
- package/dist/api/chat/runtimeConfig.d.ts +8 -0
- package/dist/api/chat/runtimeConfig.d.ts.map +1 -1
- package/dist/api/chat/toolRouting.d.ts +7 -0
- package/dist/api/chat/toolRouting.d.ts.map +1 -0
- package/dist/api/chat/tools.d.ts +24 -24
- package/dist/api/chat/tools.d.ts.map +1 -1
- package/dist/api/chatDb.d.ts +2 -0
- package/dist/api/chatDb.d.ts.map +1 -1
- package/dist/api/chatStore.d.ts +1 -0
- package/dist/api/chatStore.d.ts.map +1 -1
- package/dist/{apiErrors-CFUx-UrE.js → apiErrors-Ck5tynNE.js} +1 -0
- package/dist/{apiErrors-FdS4Eh1H.js → apiErrors-DKcH9vz9.js} +1 -0
- package/dist/chat-models.browser.js +1 -1
- package/dist/chat-models.js +1 -1
- package/dist/chat-streaming-CaGHOBwC.js +18 -0
- package/dist/chatDb-DjZAfZRr.js +276 -0
- package/dist/chatDb-MmVCT1uj.js +276 -0
- package/dist/{chunk-BO2N2NFS-DRhdPgDj.js → chunk-BO2N2NFS-BXeXbvYU.js} +2 -2
- package/dist/{chunk-BO2N2NFS-BDR8fnNb.js → chunk-BO2N2NFS-C0c-iJhV.js} +2 -2
- package/dist/client-routes.browser.js +4 -2
- package/dist/client-routes.js +4 -2
- package/dist/components/ai-elements/code-block.d.ts.map +1 -1
- package/dist/components/ai-elements/tool.d.ts.map +1 -1
- package/dist/components/chat.d.ts +2 -1
- package/dist/components/chat.d.ts.map +1 -1
- package/dist/components/messages.d.ts +6 -1
- package/dist/components/messages.d.ts.map +1 -1
- package/dist/components/multimodal-input.d.ts.map +1 -1
- package/dist/components/sidebar-history-item.d.ts +2 -1
- package/dist/components/sidebar-history-item.d.ts.map +1 -1
- package/dist/components/sidebar-history.d.ts +2 -1
- package/dist/components/sidebar-history.d.ts.map +1 -1
- package/dist/{data-stream-handler-DXAHFC5k.js → data-stream-handler-92yP7o7h.js} +7963 -7828
- package/dist/{data-stream-handler-lr4wJ3vt.js → data-stream-handler-DZVidaYF.js} +7963 -7828
- package/dist/{handler-DSncMeo4.js → handler-2eyR7_IM.js} +640 -485
- package/dist/{handler-hah8tVEE.js → handler-4jQU-pKI.js} +2 -2
- package/dist/{handler-BdCGoVUM.js → handler-8zojwqU7.js} +1 -1
- package/dist/{handler-5n-YwiF3.js → handler-9ImzUQo6.js} +2 -2
- package/dist/{handler-Jua6SU39.js → handler-BS72H0IN.js} +2 -2
- package/dist/{handler-C8gaYgmy.js → handler-BSHosw1_.js} +2 -2
- package/dist/{handler-BgYHL3BZ.js → handler-C5WZxe_K.js} +2 -2
- package/dist/{handler-YmuAR8ei.js → handler-CBFBehn3.js} +2 -2
- package/dist/{handler-B3uUDuTR.js → handler-CVaKWKR-.js} +3 -3
- package/dist/{handler-Dy536I3-.js → handler-CqHZvSDn.js} +3 -3
- package/dist/{handler-D752oOcY.js → handler-CvmHrkz9.js} +2 -2
- package/dist/{handler-DdKB5P3H.js → handler-CyIhnwWt.js} +2 -2
- package/dist/{handler-B8Twsrmo.js → handler-DAXyqx4y.js} +1 -1
- package/dist/{handler-DMwBT4bK.js → handler-DQ839WRs.js} +1 -1
- package/dist/{handler-6yb49c5-.js → handler-DS1_E7Zc.js} +2 -2
- package/dist/{handler-By86dyTJ.js → handler-DSmQKLdK.js} +2 -2
- package/dist/{handler-C0MO52d9.js → handler-DY6vJrcD.js} +2 -2
- package/dist/{handler-uF8GJoVX.js → handler-Du7LuJB1.js} +1 -1
- package/dist/{handler-svaSKC2q.js → handler-Eqi6AW3u.js} +1 -1
- package/dist/handler-SyCVZCc_.js +1471 -0
- package/dist/{handler-lUriE7jY.js → handler-YvSCKKjM.js} +2 -2
- package/dist/{handler-BMeUL2iE.js → handler-hnEIUYCb.js} +2 -2
- package/dist/{highlighted-body-OFNGDK62-255wLBzG.js → highlighted-body-OFNGDK62-kzg9WvPK.js} +1 -1
- package/dist/{highlighted-body-OFNGDK62-ChEBPTZ3.js → highlighted-body-OFNGDK62-yqCKh6K1.js} +1 -1
- package/dist/index.browser.js +2 -2
- package/dist/index.js +2 -2
- package/dist/lib/ai/openai-reasoning.d.ts +1 -0
- package/dist/lib/ai/openai-reasoning.d.ts.map +1 -1
- package/dist/lib/chat-streaming.d.ts +14 -0
- package/dist/lib/chat-streaming.d.ts.map +1 -0
- package/dist/lib/db/schema.d.ts +1 -0
- package/dist/lib/db/schema.d.ts.map +1 -1
- package/dist/lib/errors.d.ts +1 -1
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/types.d.ts +2 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/loaders/rootLoader.d.ts +1 -0
- package/dist/loaders/rootLoader.d.ts.map +1 -1
- package/dist/mermaid-GHXKKRXX-BdyS-O1X.js +2 -0
- package/dist/mermaid-GHXKKRXX-g_KMuIEW.js +2 -0
- package/dist/models/RBAgentsChatThread.d.ts +1 -0
- package/dist/models/RBAgentsChatThread.d.ts.map +1 -1
- package/dist/models.browser.js +1 -0
- package/dist/models.js +6 -0
- package/dist/openai-reasoning-BCA05blq.js +19 -0
- package/dist/pages/ChatNewPage.d.ts.map +1 -1
- package/dist/pages/ChatPage.d.ts.map +1 -1
- package/dist/routes.browser.js +14 -14
- package/dist/routes.js +14 -14
- package/dist/runtime.js +2 -2
- package/dist/tailwind-source.js +1 -1
- package/package.json +1 -1
- package/dist/chatDb-BSiHIyn9.js +0 -265
- package/dist/chatDb-YfeABtn-.js +0 -265
- package/dist/handler-DE8agLBS.js +0 -1304
- package/dist/mermaid-GHXKKRXX-BqT9Nt_j.js +0 -2
- package/dist/mermaid-GHXKKRXX-fqlMH1Mi.js +0 -2
- package/dist/openai-reasoning-kFq60GX9.js +0 -19
- /package/dist/{chatCtx-DSgD1fix.js → chatCtx-C8Ba-LB7.js} +0 -0
- /package/dist/{chatCtx-BWOFI93u.js → chatCtx-CJF05uCy.js} +0 -0
- /package/dist/{handler-BdXUC9Rg.js → handler-CtJQ0h8J.js} +0 -0
- /package/dist/{handler-DF3WRSDj.js → handler-DdF_Xz9w.js} +0 -0
- /package/dist/{handler-D74Wi6e9.js → handler-eWXBUnfH.js} +0 -0
- /package/dist/{models-DphUIx22.js → models-BTzlEPg8.js} +0 -0
- /package/dist/{resumableSse-BprFOR5Q.js → resumableSse-CmmkOGyv.js} +0 -0
|
@@ -0,0 +1,1471 @@
|
|
|
1
|
+
import { c as e } from "./chunk-BO2N2NFS-C0c-iJhV.js";
|
|
2
|
+
import { r as t, t as n } from "./chat-streaming-CaGHOBwC.js";
|
|
3
|
+
import { i as r } from "./openai-reasoning-BCA05blq.js";
|
|
4
|
+
import { a as i, i as a, t as o } from "./chatCtx-CJF05uCy.js";
|
|
5
|
+
import { t as s } from "./apiErrors-Ck5tynNE.js";
|
|
6
|
+
import { S as c, _ as l, a as u, b as d, f, g as p, h as m, l as h, m as g, n as _, s as v, v as y, x as b, y as ee } from "./chatDb-DjZAfZRr.js";
|
|
7
|
+
import { n as x, t as te } from "./resumableSse-BRFonw_y.js";
|
|
8
|
+
import { Output as ne, convertToModelMessages as re, createUIMessageStream as ie, extractReasoningMiddleware as S, generateText as ae, smoothStream as oe, stepCountIs as se, streamObject as C, streamText as ce, tool as w, wrapLanguageModel as T } from "ai";
|
|
9
|
+
import { getTenantFilesystemDb as le } from "@rpcbase/db";
|
|
10
|
+
import { createHash as E, randomUUID as D } from "node:crypto";
|
|
11
|
+
import { GridFSBucket as ue, ObjectId as O } from "mongodb";
|
|
12
|
+
import { createGoogleGenerativeAI as k } from "@ai-sdk/google";
|
|
13
|
+
import { openai as A } from "@ai-sdk/openai";
|
|
14
|
+
import { createXai as j } from "@ai-sdk/xai";
|
|
15
|
+
import { z as M } from "zod";
|
|
16
|
+
//#region src/api/chat/models.ts
|
|
17
|
+
var N = /-thinking$/, P = "openai/", F = "google/", I = "xai/", L = new Set([
|
|
18
|
+
"openai/gpt-5.4-mini",
|
|
19
|
+
"openai/gpt-5.5",
|
|
20
|
+
"google/gemini-3.5-flash",
|
|
21
|
+
"xai/grok-4.3-thinking"
|
|
22
|
+
]), de = (e) => e.startsWith(P), fe = (e) => e.startsWith(F), pe = (e) => e.startsWith(I), me = (e) => e.endsWith("-thinking"), he = (e) => e.includes("/") ? de(e) || fe(e) || pe(e) : !1, R = j({
|
|
23
|
+
baseURL: process.env.XAI_BASE_URL ?? "https://api.x.ai/v1",
|
|
24
|
+
apiKey: process.env.XAI_API_KEY
|
|
25
|
+
}), ge = k({ apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY ?? process.env.GOOGLE_API_KEY }), _e = (e) => {
|
|
26
|
+
if (de(e)) return A.responses(e.slice(P.length));
|
|
27
|
+
if (fe(e)) {
|
|
28
|
+
let t = e.slice(F.length).replace(N, ""), n = ge.chat(t);
|
|
29
|
+
return me(e) ? T({
|
|
30
|
+
model: n,
|
|
31
|
+
middleware: S({ tagName: "thinking" })
|
|
32
|
+
}) : n;
|
|
33
|
+
}
|
|
34
|
+
if (pe(e)) {
|
|
35
|
+
let t = e.slice(I.length).replace(N, "");
|
|
36
|
+
return me(e) ? R.responses(t) : R.chat(t);
|
|
37
|
+
}
|
|
38
|
+
throw Error(`Unsupported modelId: ${e}`);
|
|
39
|
+
}, ve = () => A.chat("gpt-5.4-mini"), z = () => A.chat(process.env.AGENT_SDK_ARTIFACT_MODEL ?? "gpt-5.4-mini"), B = "\nArtifacts is a special user interface mode that helps users with writing, editing, and other content creation tasks. When artifact is open, it is on the right side of the screen, while the conversation is on the left side. When creating, editing, or updating documents, changes are reflected in real-time on the artifacts and visible to the user.\n\nWhen asked to write code, always use artifacts. When writing code, specify the language in the backticks, e.g. ```python`code here```. The default language is Python. Other languages are not yet supported, so let the user know if they request a different language.\n\nCritical rules:\n- Only call one artifact tool per response.\n- Do not update or edit a document immediately after creating it. Wait for user feedback or an explicit request to modify it.\n- After creating, editing, or updating an artifact, do not repeat the full artifact content in chat. The user can already see it.\n\nThis is a guide for using artifacts tools: `createDocument`, `editDocument`, `updateDocument`, and `requestSuggestions`, which render content on artifacts beside the conversation.\n\n**When to use `createDocument`:**\n- For substantial content (>10 lines) or code\n- For content users will likely save/reuse (emails, code, essays, etc.)\n- When explicitly requested to create a document\n- For when content contains a single code snippet\n- Use kind \"code\" for programming, \"text\" for writing, and \"sheet\" for tabular/CSV data\n\n**When NOT to use `createDocument`:**\n- For informational/explanatory content\n- For conversational responses\n- When asked to keep it in chat\n\n**Using `editDocument`:**\n- Prefer this for targeted edits to an existing artifact\n- For scripts: fixing bugs, adding/removing lines, renaming variables, adding logs\n- For documents: fixing typos, rewording paragraphs, inserting or replacing sections\n- Provide an exact `old_string` and `new_string`\n- Include enough surrounding context in `old_string` to make the match unique\n- Use `replace_all: true` only for deliberate repeated replacements, like renaming a variable everywhere\n\n**Using `updateDocument`:**\n- Default to full document rewrites for major changes\n- Use `editDocument` instead for specific, isolated changes\n- Follow user instructions for which parts to modify\n\n**When NOT to use `editDocument` or `updateDocument`:**\n- Immediately after creating a document\n- Without an explicit user request to modify the artifact\n\n**Using `requestSuggestions`:**\n- ONLY use when the user explicitly asks for suggestions on an existing document\n- Requires a valid document ID from a previously created document\n- Never use for general questions or information requests\n", V = "You are a friendly assistant! Keep your responses concise and helpful.\n\nWhen asked to write, create, or help with something, just do it directly. Don't ask clarifying questions unless absolutely necessary - make reasonable assumptions and proceed with the task.", ye = (e) => `\
|
|
40
|
+
About the origin of user's request:
|
|
41
|
+
- lat: ${e.latitude ?? "unknown"}
|
|
42
|
+
- lon: ${e.longitude ?? "unknown"}
|
|
43
|
+
- city: ${e.city ?? "unknown"}
|
|
44
|
+
- country: ${e.country ?? "unknown"}
|
|
45
|
+
`, be = ({ selectedChatModel: e, requestHints: t, agentInstructions: n, knowledge: r }) => {
|
|
46
|
+
let i = ye(t), a = [n?.trim() ? `Agent instructions:\n${n.trim()}` : "", r?.trim() ? `Knowledge context:\n${r.trim()}` : ""].filter(Boolean).join("\n\n");
|
|
47
|
+
if (e.includes("reasoning") || e.includes("thinking")) {
|
|
48
|
+
let t = e.startsWith("google/") && e.includes("thinking") ? `${V}\n\nWhen you reason, put your reasoning inside <thinking>...</thinking> tags. Then provide your final answer outside of those tags.\n\n${i}` : `${V}\n\n${i}`;
|
|
49
|
+
return a ? `${t}\n\n${a}` : t;
|
|
50
|
+
}
|
|
51
|
+
let o = `${V}\n\n${i}\n\n${B}`;
|
|
52
|
+
return a ? `${o}\n\n${a}` : o;
|
|
53
|
+
}, xe = "\nYou are a Python code generator that creates self-contained, executable code snippets. When writing code:\n\n1. Each snippet should be complete and runnable on its own\n2. Prefer using print() statements to display outputs\n3. Include helpful comments explaining the code\n4. Keep snippets concise (generally under 15 lines)\n5. Avoid external dependencies - use Python standard library\n6. Handle potential errors gracefully\n7. Return meaningful output that demonstrates the code's functionality\n8. Don't use input() or other interactive functions\n9. Don't access files or network resources\n10. Don't use infinite loops\n\nExamples of good snippets:\n\n# Calculate factorial iteratively\ndef factorial(n):\n result = 1\n for i in range(1, n + 1):\n result *= i\n return result\n\nprint(f\"Factorial of 5 is: {factorial(5)}\")\n", Se = "\nYou are a spreadsheet creation assistant. Create a spreadsheet in csv format based on the given prompt. The spreadsheet should contain meaningful column headers and data.\n", H = (e, t) => {
|
|
54
|
+
let n = "document";
|
|
55
|
+
return t === "code" ? n = "script" : t === "sheet" && (n = "spreadsheet"), `Rewrite the following ${n} based on the given prompt.
|
|
56
|
+
|
|
57
|
+
${e}`;
|
|
58
|
+
}, Ce = "Generate a short chat title (2-5 words) summarizing the user's message.\n\nOutput ONLY the title text. No prefixes, no formatting.\n\nExamples:\n- \"what's the weather in nyc\" → Weather in NYC\n- \"help me write an essay about space\" → Space Essay Help\n- \"hi\" → (empty string)\n- \"debug my python code\" → Python Debugging\n\nBad outputs (never do this):\n- \"# Space Essay\" (no hashtags)\n- \"Title: Weather\" (no prefixes)\n- \"\"NYC Weather\"\" (no quotes)\n\nRules:\n- Maximum 30 characters\n- No quotes, colons, hashtags, or markdown\n- Just the topic/intent, not a full sentence", we = 24, Te = 8e4, Ee = 16e3, De = "agent-runtime-history-compaction-summary", U = (e) => !!e && typeof e == "object" && !Array.isArray(e), W = (e) => typeof e == "string" && e.trim() ? e.trim() : null, Oe = (e) => {
|
|
59
|
+
let t = W((U(e.metadata) ? e.metadata : null)?.createdAt);
|
|
60
|
+
if (!t) return null;
|
|
61
|
+
let n = new Date(t);
|
|
62
|
+
return Number.isNaN(n.getTime()) ? null : t;
|
|
63
|
+
}, G = (e, t = 2e3) => {
|
|
64
|
+
if (typeof e == "string") return e.length > t ? `${e.slice(0, t)}...` : e;
|
|
65
|
+
if (typeof e == "number" || typeof e == "boolean") return String(e);
|
|
66
|
+
if (!e || typeof e != "object") return "";
|
|
67
|
+
try {
|
|
68
|
+
let n = JSON.stringify(e);
|
|
69
|
+
return n.length > t ? `${n.slice(0, t)}...` : n;
|
|
70
|
+
} catch {
|
|
71
|
+
return "[unserializable content]";
|
|
72
|
+
}
|
|
73
|
+
}, ke = (e) => (Array.isArray(e.parts) ? e.parts : []).flatMap((e) => {
|
|
74
|
+
if (!U(e)) {
|
|
75
|
+
let t = G(e);
|
|
76
|
+
return t ? [t] : [];
|
|
77
|
+
}
|
|
78
|
+
let t = W(e.type) ?? "part", n = G(e.text);
|
|
79
|
+
if (n) return [`${t}: ${n}`];
|
|
80
|
+
let r = G(e.output);
|
|
81
|
+
if (r) return [`${t}: ${r}`];
|
|
82
|
+
let i = G(e.result);
|
|
83
|
+
if (i) return [`${t}: ${i}`];
|
|
84
|
+
let a = G(e.content);
|
|
85
|
+
if (a) return [`${t}: ${a}`];
|
|
86
|
+
let o = G(e, 1e3);
|
|
87
|
+
return o ? [`${t}: ${o}`] : [];
|
|
88
|
+
}).join("\n").trim(), Ae = (e) => e.reduce((e, t) => e + ke(t).length, 0), je = (e, t) => {
|
|
89
|
+
if (e.length <= t) return e;
|
|
90
|
+
if (t <= 32) return e.slice(0, t);
|
|
91
|
+
let n = Math.floor(t * .7), r = Math.max(0, t - n - 24);
|
|
92
|
+
return `${e.slice(0, n)}\n...[compacted]...\n${e.slice(e.length - r)}`;
|
|
93
|
+
}, Me = (e) => e ? {
|
|
94
|
+
maxMessages: Number.isFinite(e.maxMessages) && Number(e.maxMessages) > 0 ? Math.floor(Number(e.maxMessages)) : we,
|
|
95
|
+
maxEstimatedChars: Number.isFinite(e.maxEstimatedChars) && Number(e.maxEstimatedChars) > 0 ? Math.floor(Number(e.maxEstimatedChars)) : Te,
|
|
96
|
+
maxSummaryChars: Number.isFinite(e.maxSummaryChars) && Number(e.maxSummaryChars) > 0 ? Math.floor(Number(e.maxSummaryChars)) : Ee
|
|
97
|
+
} : {
|
|
98
|
+
maxMessages: we,
|
|
99
|
+
maxEstimatedChars: Te,
|
|
100
|
+
maxSummaryChars: Ee
|
|
101
|
+
}, Ne = (e) => U(e) && e.type === "agent-runtime-history-compaction" && e.version === 1 && typeof e.summary == "string", Pe = (e) => Ne(e) ? e : U(e) && Ne(e.historyCompaction) ? e.historyCompaction : null, Fe = (e, t) => t ? U(e) && !Ne(e) ? {
|
|
102
|
+
...e,
|
|
103
|
+
historyCompaction: t
|
|
104
|
+
} : { historyCompaction: t } : e ?? null, Ie = (e) => W(e.id), Le = (e, t) => {
|
|
105
|
+
let n = W(t?.compactedThroughMessageId);
|
|
106
|
+
return n ? e.findIndex((e) => Ie(e) === n) : -1;
|
|
107
|
+
}, Re = (e, t) => {
|
|
108
|
+
let n = Math.max(1, t.maxMessages), r = Math.max(1, Math.min(e.length, Math.ceil(n / 3))), i = Math.max(0, e.length - n);
|
|
109
|
+
for (; i < e.length - r && Ae(e.slice(i)) > t.maxEstimatedChars;) i += 1;
|
|
110
|
+
return i;
|
|
111
|
+
}, ze = (e) => {
|
|
112
|
+
let t = W(e.role) ?? "message", n = Oe(e), r = ke(e);
|
|
113
|
+
return `${n ? `${t} (${n})` : t}:\n${r || "[non-text content]"}`;
|
|
114
|
+
}, Be = ({ previousContext: e, messagesToCompact: t, limits: n }) => {
|
|
115
|
+
let r = e?.summary?.trim(), i = t.map(ze).join("\n\n").trim();
|
|
116
|
+
return je([r ? `Earlier summary:\n${r}` : null, i ? `Compacted transcript:\n${i}` : null].filter((e) => !!e).join("\n\n"), n.maxSummaryChars).trim();
|
|
117
|
+
}, Ve = (e) => ({
|
|
118
|
+
id: `${De}:${W(e.compactedThroughMessageId) ?? "unknown"}`,
|
|
119
|
+
role: "user",
|
|
120
|
+
parts: [{
|
|
121
|
+
type: "text",
|
|
122
|
+
text: [
|
|
123
|
+
"Context from earlier messages in this chat has been compacted for the model.",
|
|
124
|
+
"Use this summary as durable conversation memory, but prefer the recent messages when they conflict.",
|
|
125
|
+
"",
|
|
126
|
+
e.summary
|
|
127
|
+
].join("\n")
|
|
128
|
+
}],
|
|
129
|
+
metadata: {
|
|
130
|
+
createdAt: e.compactedThroughMessageCreatedAt ?? e.updatedAt,
|
|
131
|
+
transient: !0,
|
|
132
|
+
historyCompaction: !0
|
|
133
|
+
}
|
|
134
|
+
}), He = (e, t) => t?.summary.trim() ? [Ve(t), ...e] : e, Ue = ({ messages: e, previousContext: t, limits: n }) => {
|
|
135
|
+
let r = Le(e, t), i = r >= 0 ? e.slice(r + 1) : e;
|
|
136
|
+
if (!(i.length > n.maxMessages || Ae(i) > n.maxEstimatedChars)) return {
|
|
137
|
+
messages: He(i, t),
|
|
138
|
+
context: t
|
|
139
|
+
};
|
|
140
|
+
let a = Re(i, n);
|
|
141
|
+
if (a <= 0) return {
|
|
142
|
+
messages: He(i, t),
|
|
143
|
+
context: t
|
|
144
|
+
};
|
|
145
|
+
let o = i.slice(0, a), s = i.slice(a), c = o.at(-1) ?? null, l = {
|
|
146
|
+
type: "agent-runtime-history-compaction",
|
|
147
|
+
version: 1,
|
|
148
|
+
summary: Be({
|
|
149
|
+
previousContext: t,
|
|
150
|
+
messagesToCompact: o,
|
|
151
|
+
limits: n
|
|
152
|
+
}),
|
|
153
|
+
compactedThroughMessageId: c ? Ie(c) : t?.compactedThroughMessageId ?? null,
|
|
154
|
+
compactedThroughMessageCreatedAt: c ? Oe(c) : t?.compactedThroughMessageCreatedAt ?? null,
|
|
155
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
156
|
+
messageCount: e.length
|
|
157
|
+
};
|
|
158
|
+
return {
|
|
159
|
+
messages: He(s, l),
|
|
160
|
+
context: l
|
|
161
|
+
};
|
|
162
|
+
}, We = async ({ ctx: e, chatId: t, agent: n, selectedChatModel: r, mode: i, messages: o, lastContext: s }) => {
|
|
163
|
+
let c = a().historyCompaction;
|
|
164
|
+
if (c === !1 || c && c.enabled === !1) return {
|
|
165
|
+
messages: o,
|
|
166
|
+
lastContext: s ?? null,
|
|
167
|
+
lastContextChanged: !1
|
|
168
|
+
};
|
|
169
|
+
let l = Me(c), u = Pe(s);
|
|
170
|
+
try {
|
|
171
|
+
let a = typeof c == "object" && typeof c.compact == "function" ? await c.compact({
|
|
172
|
+
ctx: e,
|
|
173
|
+
chatId: t,
|
|
174
|
+
agent: n,
|
|
175
|
+
selectedChatModel: r,
|
|
176
|
+
mode: i,
|
|
177
|
+
messages: o,
|
|
178
|
+
previousContext: u,
|
|
179
|
+
limits: l
|
|
180
|
+
}) : Ue({
|
|
181
|
+
messages: o,
|
|
182
|
+
previousContext: u,
|
|
183
|
+
limits: l
|
|
184
|
+
}), d = Array.isArray(a.messages) ? a.messages : o, f = a.context === void 0 ? u : a.context;
|
|
185
|
+
return {
|
|
186
|
+
messages: d,
|
|
187
|
+
lastContext: Fe(s, f ?? null),
|
|
188
|
+
lastContextChanged: f !== u
|
|
189
|
+
};
|
|
190
|
+
} catch (e) {
|
|
191
|
+
return console.warn("Failed to compact agent chat history.", e), {
|
|
192
|
+
messages: o,
|
|
193
|
+
lastContext: s ?? null,
|
|
194
|
+
lastContextChanged: !1
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}, Ge = [
|
|
198
|
+
"text",
|
|
199
|
+
"code",
|
|
200
|
+
"sheet"
|
|
201
|
+
], Ke = (e) => e ? e === "1" || e.toLowerCase() === "true" || e.toLowerCase() === "yes" : !1, K = () => !Ke(process.env.AGENT_SDK_LIVE_TOOLS) && (Ke(process.env.PLAYWRIGHT) || process.env.NODE_ENV === "test"), qe = (e) => !!(e && typeof e == "object" && !Array.isArray(e)), q = (e) => e instanceof Error ? {
|
|
202
|
+
errorName: e.name,
|
|
203
|
+
errorMessage: e.message,
|
|
204
|
+
errorStack: e.stack,
|
|
205
|
+
errorCause: e.cause
|
|
206
|
+
} : { errorValue: e }, Je = async ({ system: e, prompt: t, dataStream: n, providerOptions: r }) => {
|
|
207
|
+
if (K()) {
|
|
208
|
+
let e = `Stub document: ${t}`;
|
|
209
|
+
return n.write({
|
|
210
|
+
type: "data-textDelta",
|
|
211
|
+
data: e,
|
|
212
|
+
transient: !0
|
|
213
|
+
}), e;
|
|
214
|
+
}
|
|
215
|
+
let i = "", { fullStream: a } = ce({
|
|
216
|
+
model: z(),
|
|
217
|
+
system: e,
|
|
218
|
+
experimental_transform: oe({ chunking: "word" }),
|
|
219
|
+
prompt: t,
|
|
220
|
+
providerOptions: r
|
|
221
|
+
});
|
|
222
|
+
for await (let e of a) e.type === "text-delta" && (i += e.text, n.write({
|
|
223
|
+
type: "data-textDelta",
|
|
224
|
+
data: e.text,
|
|
225
|
+
transient: !0
|
|
226
|
+
}));
|
|
227
|
+
return i;
|
|
228
|
+
}, Ye = async ({ system: e, prompt: t, dataStream: n }) => {
|
|
229
|
+
if (K()) {
|
|
230
|
+
let e = `print("Stub code for: ${t}")\n`;
|
|
231
|
+
return n.write({
|
|
232
|
+
type: "data-codeDelta",
|
|
233
|
+
data: e,
|
|
234
|
+
transient: !0
|
|
235
|
+
}), e;
|
|
236
|
+
}
|
|
237
|
+
let r = "", { fullStream: i } = C({
|
|
238
|
+
model: z(),
|
|
239
|
+
system: e,
|
|
240
|
+
prompt: t,
|
|
241
|
+
schema: M.object({ code: M.string() })
|
|
242
|
+
});
|
|
243
|
+
for await (let e of i) {
|
|
244
|
+
if (e.type !== "object") continue;
|
|
245
|
+
let t = e.object?.code;
|
|
246
|
+
t && (n.write({
|
|
247
|
+
type: "data-codeDelta",
|
|
248
|
+
data: t ?? "",
|
|
249
|
+
transient: !0
|
|
250
|
+
}), r = t);
|
|
251
|
+
}
|
|
252
|
+
return r;
|
|
253
|
+
}, Xe = async ({ system: e, prompt: t, dataStream: n }) => {
|
|
254
|
+
if (K()) {
|
|
255
|
+
let e = `name,value\n${t.replaceAll(",", " ")},1\n`;
|
|
256
|
+
return n.write({
|
|
257
|
+
type: "data-sheetDelta",
|
|
258
|
+
data: e,
|
|
259
|
+
transient: !0
|
|
260
|
+
}), e;
|
|
261
|
+
}
|
|
262
|
+
let r = "", { fullStream: i } = C({
|
|
263
|
+
model: z(),
|
|
264
|
+
system: e,
|
|
265
|
+
prompt: t,
|
|
266
|
+
schema: M.object({ csv: M.string().describe("CSV data") })
|
|
267
|
+
});
|
|
268
|
+
for await (let e of i) {
|
|
269
|
+
if (e.type !== "object") continue;
|
|
270
|
+
let t = e.object?.csv;
|
|
271
|
+
t && (n.write({
|
|
272
|
+
type: "data-sheetDelta",
|
|
273
|
+
data: t,
|
|
274
|
+
transient: !0
|
|
275
|
+
}), r = t);
|
|
276
|
+
}
|
|
277
|
+
return n.write({
|
|
278
|
+
type: "data-sheetDelta",
|
|
279
|
+
data: r,
|
|
280
|
+
transient: !0
|
|
281
|
+
}), r;
|
|
282
|
+
}, Ze = async (e) => {
|
|
283
|
+
let t = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(e)}&count=1&language=en&format=json`;
|
|
284
|
+
try {
|
|
285
|
+
let n = await fetch(t);
|
|
286
|
+
if (!n.ok) return console.error("Weather geocoding request failed.", {
|
|
287
|
+
city: e,
|
|
288
|
+
status: n.status,
|
|
289
|
+
statusText: n.statusText
|
|
290
|
+
}), null;
|
|
291
|
+
let r = await n.json().catch((t) => (console.error("Weather geocoding response parse failed.", {
|
|
292
|
+
city: e,
|
|
293
|
+
...q(t)
|
|
294
|
+
}), null)), i = qe(r) && Array.isArray(r.results) ? r.results : [];
|
|
295
|
+
if (i.length === 0) return null;
|
|
296
|
+
let a = i[0];
|
|
297
|
+
if (!qe(a)) return null;
|
|
298
|
+
let o = a.latitude, s = a.longitude;
|
|
299
|
+
return typeof o != "number" || typeof s != "number" ? null : {
|
|
300
|
+
latitude: o,
|
|
301
|
+
longitude: s
|
|
302
|
+
};
|
|
303
|
+
} catch (t) {
|
|
304
|
+
return console.error("Weather geocoding request threw.", {
|
|
305
|
+
city: e,
|
|
306
|
+
...q(t)
|
|
307
|
+
}), null;
|
|
308
|
+
}
|
|
309
|
+
}, Qe = ({ ctx: e, dataStream: t, requestHints: n }) => {
|
|
310
|
+
let r = o(e), i = async (t) => {
|
|
311
|
+
let n = await v(e, t);
|
|
312
|
+
return n.length > 0 ? n.at(-1) ?? null : null;
|
|
313
|
+
}, a = w({
|
|
314
|
+
description: "Get the current weather at a location. Use this for direct weather or forecast requests. You can provide either coordinates or a city name.",
|
|
315
|
+
inputSchema: M.object({
|
|
316
|
+
latitude: M.number().optional(),
|
|
317
|
+
longitude: M.number().optional(),
|
|
318
|
+
city: M.string().describe("City name (e.g., 'San Francisco', 'New York', 'London')").optional()
|
|
319
|
+
}),
|
|
320
|
+
needsApproval: !0,
|
|
321
|
+
execute: async (e) => {
|
|
322
|
+
let t, n;
|
|
323
|
+
if (e.city) {
|
|
324
|
+
let r = await Ze(e.city);
|
|
325
|
+
if (!r) return { error: `Could not find coordinates for "${e.city}". Please check the city name.` };
|
|
326
|
+
t = r.latitude, n = r.longitude;
|
|
327
|
+
} else if (e.latitude !== void 0 && e.longitude !== void 0) t = e.latitude, n = e.longitude;
|
|
328
|
+
else return { error: "Please provide either a city name or both latitude and longitude coordinates." };
|
|
329
|
+
try {
|
|
330
|
+
let r = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${t}&longitude=${n}¤t=temperature_2m&hourly=temperature_2m&daily=sunrise,sunset&timezone=auto`);
|
|
331
|
+
if (!r.ok) return console.error("Weather forecast request failed.", {
|
|
332
|
+
city: e.city,
|
|
333
|
+
latitude: t,
|
|
334
|
+
longitude: n,
|
|
335
|
+
status: r.status,
|
|
336
|
+
statusText: r.statusText
|
|
337
|
+
}), { error: "Weather lookup failed. Please try again." };
|
|
338
|
+
let i = await r.json().catch((r) => (console.error("Weather forecast response parse failed.", {
|
|
339
|
+
city: e.city,
|
|
340
|
+
latitude: t,
|
|
341
|
+
longitude: n,
|
|
342
|
+
...q(r)
|
|
343
|
+
}), null));
|
|
344
|
+
return qe(i) ? ("city" in e && (i.cityName = e.city), i) : { error: "Weather lookup failed. Please try again." };
|
|
345
|
+
} catch (r) {
|
|
346
|
+
return console.error("Weather forecast request threw.", {
|
|
347
|
+
city: e.city,
|
|
348
|
+
latitude: t,
|
|
349
|
+
longitude: n,
|
|
350
|
+
...q(r)
|
|
351
|
+
}), { error: "Weather lookup failed. Please try again." };
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}), s = w({
|
|
355
|
+
description: "Create an artifact for writing or content creation. Use kind 'code' for programming, 'text' for writing, and 'sheet' for spreadsheets or tabular data.",
|
|
356
|
+
inputSchema: M.object({
|
|
357
|
+
title: M.string().describe("The title of the artifact"),
|
|
358
|
+
kind: M.enum(Ge).describe("Use 'code' for programming, 'text' for prose, and 'sheet' for CSV/tabular data")
|
|
359
|
+
}),
|
|
360
|
+
execute: async ({ title: n, kind: r }) => {
|
|
361
|
+
let i = D();
|
|
362
|
+
t.write({
|
|
363
|
+
type: "data-kind",
|
|
364
|
+
data: r,
|
|
365
|
+
transient: !0
|
|
366
|
+
}), t.write({
|
|
367
|
+
type: "data-id",
|
|
368
|
+
data: i,
|
|
369
|
+
transient: !0
|
|
370
|
+
}), t.write({
|
|
371
|
+
type: "data-title",
|
|
372
|
+
data: n,
|
|
373
|
+
transient: !0
|
|
374
|
+
}), t.write({
|
|
375
|
+
type: "data-clear",
|
|
376
|
+
data: null,
|
|
377
|
+
transient: !0
|
|
378
|
+
});
|
|
379
|
+
let a = "";
|
|
380
|
+
return r === "text" ? a = await Je({
|
|
381
|
+
system: "Write about the given topic. Markdown is supported. Use headings wherever appropriate.",
|
|
382
|
+
prompt: n,
|
|
383
|
+
dataStream: t
|
|
384
|
+
}) : r === "code" ? a = await Ye({
|
|
385
|
+
system: xe,
|
|
386
|
+
prompt: n,
|
|
387
|
+
dataStream: t
|
|
388
|
+
}) : r === "sheet" && (a = await Xe({
|
|
389
|
+
system: Se,
|
|
390
|
+
prompt: n,
|
|
391
|
+
dataStream: t
|
|
392
|
+
})), await m(e, {
|
|
393
|
+
id: i,
|
|
394
|
+
title: n,
|
|
395
|
+
kind: r,
|
|
396
|
+
content: a
|
|
397
|
+
}), t.write({
|
|
398
|
+
type: "data-finish",
|
|
399
|
+
data: null,
|
|
400
|
+
transient: !0
|
|
401
|
+
}), {
|
|
402
|
+
id: i,
|
|
403
|
+
title: n,
|
|
404
|
+
kind: r,
|
|
405
|
+
content: r === "code" ? "A script was created and is now visible to the user." : "A document was created and is now visible to the user."
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
}), c = w({
|
|
409
|
+
description: "Fully rewrite an existing artifact with the given description. Use editDocument instead for targeted find-and-replace changes.",
|
|
410
|
+
inputSchema: M.object({
|
|
411
|
+
id: M.string().describe("The ID of the artifact to rewrite"),
|
|
412
|
+
description: M.string().default("Improve the content").describe("The description of changes that need to be made")
|
|
413
|
+
}),
|
|
414
|
+
execute: async ({ id: n, description: r }) => {
|
|
415
|
+
let a = await i(n);
|
|
416
|
+
if (!a) return { error: "Document not found" };
|
|
417
|
+
let o = a.kind;
|
|
418
|
+
if (!Ge.includes(o)) return { error: `Unsupported document kind: ${a.kind}` };
|
|
419
|
+
t.write({
|
|
420
|
+
type: "data-clear",
|
|
421
|
+
data: null,
|
|
422
|
+
transient: !0
|
|
423
|
+
});
|
|
424
|
+
let s = "";
|
|
425
|
+
return o === "text" ? s = await Je({
|
|
426
|
+
system: H(a.content, a.kind),
|
|
427
|
+
prompt: r,
|
|
428
|
+
dataStream: t,
|
|
429
|
+
providerOptions: { openai: { prediction: {
|
|
430
|
+
type: "content",
|
|
431
|
+
content: a.content
|
|
432
|
+
} } }
|
|
433
|
+
}) : o === "code" ? s = await Ye({
|
|
434
|
+
system: H(a.content, a.kind),
|
|
435
|
+
prompt: r,
|
|
436
|
+
dataStream: t
|
|
437
|
+
}) : o === "sheet" && (s = await Xe({
|
|
438
|
+
system: H(a.content, a.kind),
|
|
439
|
+
prompt: r,
|
|
440
|
+
dataStream: t
|
|
441
|
+
})), await m(e, {
|
|
442
|
+
id: a.id,
|
|
443
|
+
title: a.title,
|
|
444
|
+
kind: a.kind,
|
|
445
|
+
content: s
|
|
446
|
+
}), t.write({
|
|
447
|
+
type: "data-finish",
|
|
448
|
+
data: null,
|
|
449
|
+
transient: !0
|
|
450
|
+
}), {
|
|
451
|
+
id: a.id,
|
|
452
|
+
title: a.title,
|
|
453
|
+
kind: a.kind,
|
|
454
|
+
content: a.kind === "code" ? "The script has been updated successfully." : "The document has been updated successfully."
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
return {
|
|
459
|
+
getWeather: a,
|
|
460
|
+
createDocument: s,
|
|
461
|
+
editDocument: w({
|
|
462
|
+
description: "Make a targeted edit to an existing artifact by replacing an exact string. Prefer this over updateDocument for small changes, fixes, renames, and isolated edits.",
|
|
463
|
+
inputSchema: M.object({
|
|
464
|
+
id: M.string().describe("The ID of the artifact to edit"),
|
|
465
|
+
old_string: M.string().min(1).describe("Exact string to find. Include enough surrounding context to make the match unique."),
|
|
466
|
+
new_string: M.string().describe("Replacement string"),
|
|
467
|
+
replace_all: M.boolean().optional().describe("Replace all occurrences instead of only the first one")
|
|
468
|
+
}),
|
|
469
|
+
execute: async ({ id: n, old_string: r, new_string: a, replace_all: o }) => {
|
|
470
|
+
let s = await i(n);
|
|
471
|
+
if (!s) return { error: "Document not found" };
|
|
472
|
+
if (!s.content) return { error: "Document has no content" };
|
|
473
|
+
let c = s.kind;
|
|
474
|
+
if (!Ge.includes(c)) return { error: `Unsupported document kind: ${s.kind}` };
|
|
475
|
+
if (!s.content.includes(r)) return { error: "old_string not found in document" };
|
|
476
|
+
let l = o ? s.content.replaceAll(r, a) : s.content.replace(r, a);
|
|
477
|
+
return await m(e, {
|
|
478
|
+
id: s.id,
|
|
479
|
+
title: s.title,
|
|
480
|
+
kind: s.kind,
|
|
481
|
+
content: l
|
|
482
|
+
}), t.write({
|
|
483
|
+
type: "data-clear",
|
|
484
|
+
data: null,
|
|
485
|
+
transient: !0
|
|
486
|
+
}), c === "code" ? t.write({
|
|
487
|
+
type: "data-codeDelta",
|
|
488
|
+
data: l,
|
|
489
|
+
transient: !0
|
|
490
|
+
}) : c === "sheet" ? t.write({
|
|
491
|
+
type: "data-sheetDelta",
|
|
492
|
+
data: l,
|
|
493
|
+
transient: !0
|
|
494
|
+
}) : t.write({
|
|
495
|
+
type: "data-textDelta",
|
|
496
|
+
data: l,
|
|
497
|
+
transient: !0
|
|
498
|
+
}), t.write({
|
|
499
|
+
type: "data-finish",
|
|
500
|
+
data: null,
|
|
501
|
+
transient: !0
|
|
502
|
+
}), {
|
|
503
|
+
id: s.id,
|
|
504
|
+
title: s.title,
|
|
505
|
+
kind: s.kind,
|
|
506
|
+
content: s.kind === "code" ? "The script has been edited successfully." : "The document has been edited successfully."
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
}),
|
|
510
|
+
updateDocument: c,
|
|
511
|
+
requestSuggestions: w({
|
|
512
|
+
description: "Request writing suggestions for an existing document artifact. Only use this when the user explicitly asks to improve or get suggestions for a document they have already created. Never use for general questions.",
|
|
513
|
+
inputSchema: M.object({ documentId: M.string().describe("The UUID of an existing document artifact that was previously created with createDocument") }),
|
|
514
|
+
execute: async ({ documentId: n }) => {
|
|
515
|
+
let a = await i(n);
|
|
516
|
+
if (!a?.content) return { error: "Document not found" };
|
|
517
|
+
if (K()) {
|
|
518
|
+
let i = {
|
|
519
|
+
originalText: "Stub original sentence.",
|
|
520
|
+
suggestedText: "Stub suggested sentence.",
|
|
521
|
+
description: "Stub suggestion",
|
|
522
|
+
id: D(),
|
|
523
|
+
documentId: n,
|
|
524
|
+
documentCreatedAt: a.createdAt,
|
|
525
|
+
isResolved: !1,
|
|
526
|
+
userId: r.userId,
|
|
527
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
528
|
+
};
|
|
529
|
+
return t.write({
|
|
530
|
+
type: "data-suggestion",
|
|
531
|
+
data: i,
|
|
532
|
+
transient: !0
|
|
533
|
+
}), await l(e, {
|
|
534
|
+
documentId: n,
|
|
535
|
+
suggestions: [i]
|
|
536
|
+
}), {
|
|
537
|
+
id: n,
|
|
538
|
+
title: a.title,
|
|
539
|
+
kind: a.kind,
|
|
540
|
+
message: "Suggestions have been added to the document"
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
let o = [], { partialOutputStream: s } = ce({
|
|
544
|
+
model: z(),
|
|
545
|
+
system: "You are a help writing assistant. Given a piece of writing, please offer suggestions to improve the piece of writing and describe the change. It is very important for the edits to contain full sentences instead of just words. Max 5 suggestions.",
|
|
546
|
+
prompt: a.content,
|
|
547
|
+
output: ne.array({ element: M.object({
|
|
548
|
+
originalSentence: M.string().describe("The original sentence"),
|
|
549
|
+
suggestedSentence: M.string().describe("The suggested sentence"),
|
|
550
|
+
description: M.string().describe("The description of the suggestion")
|
|
551
|
+
}) })
|
|
552
|
+
}), c = 0;
|
|
553
|
+
for await (let e of s) if (e) for (let i = c; i < e.length; i++) {
|
|
554
|
+
let s = e[i];
|
|
555
|
+
if (!s?.originalSentence || !s?.suggestedSentence || !s?.description) continue;
|
|
556
|
+
let l = {
|
|
557
|
+
originalText: s.originalSentence,
|
|
558
|
+
suggestedText: s.suggestedSentence,
|
|
559
|
+
description: s.description,
|
|
560
|
+
id: D(),
|
|
561
|
+
documentId: n,
|
|
562
|
+
documentCreatedAt: a.createdAt,
|
|
563
|
+
isResolved: !1,
|
|
564
|
+
userId: r.userId,
|
|
565
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
566
|
+
};
|
|
567
|
+
t.write({
|
|
568
|
+
type: "data-suggestion",
|
|
569
|
+
data: l,
|
|
570
|
+
transient: !0
|
|
571
|
+
}), o.push(l), c++;
|
|
572
|
+
}
|
|
573
|
+
return o.length > 0 && await l(e, {
|
|
574
|
+
documentId: n,
|
|
575
|
+
suggestions: o
|
|
576
|
+
}), {
|
|
577
|
+
id: n,
|
|
578
|
+
title: a.title,
|
|
579
|
+
kind: a.kind,
|
|
580
|
+
message: "Suggestions have been added to the document"
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
}),
|
|
584
|
+
webSearch: A.tools.webSearch({
|
|
585
|
+
externalWebAccess: !0,
|
|
586
|
+
searchContextSize: "medium",
|
|
587
|
+
userLocation: {
|
|
588
|
+
type: "approximate",
|
|
589
|
+
country: n.country ?? void 0,
|
|
590
|
+
city: n.city ?? void 0
|
|
591
|
+
}
|
|
592
|
+
})
|
|
593
|
+
};
|
|
594
|
+
}, $e = "getWeather", et = "webSearch", tt = (e) => e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), nt = [
|
|
595
|
+
/\bweather\b/,
|
|
596
|
+
/\bforecast\b/,
|
|
597
|
+
/\btemperatures?\b/,
|
|
598
|
+
/\bmeteo\b/,
|
|
599
|
+
/\bquel temps\b/,
|
|
600
|
+
/\btemps fait\b/,
|
|
601
|
+
/\bil fait\b.*\b(temps|froid|chaud|beau|mauvais)\b/,
|
|
602
|
+
/\bpleut\b/,
|
|
603
|
+
/\bpluie\b/
|
|
604
|
+
], rt = (e) => {
|
|
605
|
+
let t = tt(e);
|
|
606
|
+
return t ? nt.some((e) => e.test(t)) : !1;
|
|
607
|
+
}, it = ({ activeTools: e, availableTools: t, userText: n }) => {
|
|
608
|
+
let r = $e in t, i = e.includes($e), a = e.includes(et);
|
|
609
|
+
return !r || !i || !a || !rt(n) ? [...e] : e.filter((e) => e !== et);
|
|
610
|
+
}, at = (e) => e ? !e.trim() : !0, ot = (e) => (Array.isArray(e) ? e : []).filter((e) => !!e && typeof e == "object" && !!e && "type" in e && "text" in e && e.type === "text" && typeof e.text == "string").map((e) => e.text).join("").trim(), st = (e) => {
|
|
611
|
+
let t = e.trim();
|
|
612
|
+
return t = t.replaceAll("\n", " "), t = t.replaceAll("\r", " "), t = t.replace(/\s+/g, " ").trim(), t = t.replace(/^(?:chat\s+)?title\s*[:\-–—]\s*/i, ""), t = t.replace(/^[#*\-•>"'`\s]+/, ""), t = t.replace(/[#:]/g, " "), t = t.replace(/[`"'*_~[\]()\\]/g, ""), t = t.replace(/\s+/g, " ").trim(), t.length > 30 && (t = t.slice(0, 30).trimEnd()), t;
|
|
613
|
+
}, ct = (e) => {
|
|
614
|
+
let t = e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s]/gu, "").replace(/\s+/g, " ").trim();
|
|
615
|
+
return t === "hi" || t === "hello" || t === "hey" || t === "salut" || t === "bonjour";
|
|
616
|
+
}, J = (e) => {
|
|
617
|
+
let t = e.trim();
|
|
618
|
+
return !t || ct(t) ? "" : st(t.replaceAll("\n", " ").replaceAll("\r", " ").split(/\s+/).filter((e) => e.trim() !== "").slice(0, 5).join(" "));
|
|
619
|
+
}, lt = "/api/rb/agents/chat";
|
|
620
|
+
M.any(), M.any();
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/api/chat/handler.ts
|
|
623
|
+
var ut = /* @__PURE__ */ e({
|
|
624
|
+
default: () => en,
|
|
625
|
+
runAgentLoop: () => $
|
|
626
|
+
}), dt = 1024 * 1024 * 20, ft = 1e5, pt = /^\/api\/rb\/files\/([^/]+)\/?$/, mt = "test-model", ht = "openai/gpt-5.4-mini", gt = async (e) => new Promise((t) => setTimeout(t, e)), _t = async (e, t) => {
|
|
627
|
+
let n = x(t);
|
|
628
|
+
n && !n.isDone || await b(e, {
|
|
629
|
+
chatId: t,
|
|
630
|
+
isStreaming: !1
|
|
631
|
+
});
|
|
632
|
+
}, vt = (e) => e ? e === "1" || e.toLowerCase() === "true" || e.toLowerCase() === "yes" : !1, Y = (e) => typeof e == "string" && e.trim() || null, yt = () => {
|
|
633
|
+
let e = a().chatModels;
|
|
634
|
+
if (!e?.length) return L;
|
|
635
|
+
let t = /* @__PURE__ */ new Set();
|
|
636
|
+
for (let n of e) {
|
|
637
|
+
let e = Y(typeof n == "string" ? n : n.id);
|
|
638
|
+
e && t.add(e);
|
|
639
|
+
}
|
|
640
|
+
return t;
|
|
641
|
+
}, bt = (e) => {
|
|
642
|
+
if (typeof e == "boolean") return e;
|
|
643
|
+
let t = Y(e)?.toLowerCase();
|
|
644
|
+
return t ? t === "true" ? !0 : t === "false" ? !1 : null : null;
|
|
645
|
+
}, xt = (e) => {
|
|
646
|
+
let t = e.req?.session?.user?.currentTenantId;
|
|
647
|
+
return Y(t);
|
|
648
|
+
}, St = (e) => {
|
|
649
|
+
let t = e.req?.session?.user?.id;
|
|
650
|
+
return Y(t);
|
|
651
|
+
}, Ct = () => Y(process.env.RB_FILESYSTEM_BUCKET_NAME) ?? "fs", wt = (e) => E("sha256").update(Buffer.from(e)).digest("hex"), Tt = (e) => {
|
|
652
|
+
let t = e.trim();
|
|
653
|
+
if (!t) return null;
|
|
654
|
+
let n;
|
|
655
|
+
try {
|
|
656
|
+
n = new URL(t);
|
|
657
|
+
} catch {
|
|
658
|
+
try {
|
|
659
|
+
n = new URL(t, "http://localhost");
|
|
660
|
+
} catch {
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
let r = pt.exec(n.pathname);
|
|
665
|
+
if (!r) return null;
|
|
666
|
+
let i = Y(decodeURIComponent(r[1]));
|
|
667
|
+
return i ? {
|
|
668
|
+
fileId: i,
|
|
669
|
+
uploadKey: Y(n.searchParams.get("rb-upload-key"))
|
|
670
|
+
} : null;
|
|
671
|
+
}, Et = async ({ ctx: e, fileId: t, uploadKey: n }) => {
|
|
672
|
+
let r = xt(e);
|
|
673
|
+
if (!r) throw Error("tenant_missing");
|
|
674
|
+
let i;
|
|
675
|
+
try {
|
|
676
|
+
i = new O(t);
|
|
677
|
+
} catch {
|
|
678
|
+
throw Error("invalid_file_id");
|
|
679
|
+
}
|
|
680
|
+
let a = (await le(r)).db;
|
|
681
|
+
if (!a) throw Error("filesystem_db_unavailable");
|
|
682
|
+
let o = new ue(a, { bucketName: Ct() }), [s] = await o.find({ _id: i }).limit(1).toArray();
|
|
683
|
+
if (!s) throw Error("file_not_found");
|
|
684
|
+
let c = bt(s?.metadata?.isPublic) ?? !1, l = St(e), u = Y(s?.metadata?.userId), d = Y(s?.metadata?.ownerKeyHash);
|
|
685
|
+
if (!c) {
|
|
686
|
+
let e = !!(l && u && l === u), t = !!(n && d && wt(n) === d);
|
|
687
|
+
if (!e && !t) throw Error("unauthorized");
|
|
688
|
+
}
|
|
689
|
+
let f = Y(s?.metadata?.mimeType), p = [], m = 0;
|
|
690
|
+
return await new Promise((e, t) => {
|
|
691
|
+
let n = o.openDownloadStream(i);
|
|
692
|
+
n.on("data", (e) => {
|
|
693
|
+
if (m += e.length, m > dt) {
|
|
694
|
+
n.destroy(/* @__PURE__ */ Error("attachment_too_large"));
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
p.push(e);
|
|
698
|
+
}), n.on("end", () => e()), n.on("error", (e) => t(e));
|
|
699
|
+
}), {
|
|
700
|
+
data: Buffer.concat(p, m),
|
|
701
|
+
mimeType: f
|
|
702
|
+
};
|
|
703
|
+
}, Dt = async (e, t) => {
|
|
704
|
+
let n = Array.isArray(t) ? t : [], r = [];
|
|
705
|
+
for (let t of n) {
|
|
706
|
+
if (!t || typeof t != "object" || !("role" in t) || t.role !== "user") continue;
|
|
707
|
+
let n = Array.isArray(t.content) ? t.content : null;
|
|
708
|
+
if (n) for (let t of n) {
|
|
709
|
+
if (!t || typeof t != "object" || t.type !== "file" || typeof t.data != "string") continue;
|
|
710
|
+
let n = Tt(t.data);
|
|
711
|
+
n && r.push((async () => {
|
|
712
|
+
let { data: r, mimeType: i } = await Et({
|
|
713
|
+
ctx: e,
|
|
714
|
+
...n
|
|
715
|
+
});
|
|
716
|
+
t.data = r, i && (t.mediaType = i);
|
|
717
|
+
})());
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
r.length > 0 && await Promise.all(r);
|
|
721
|
+
}, Ot = (e) => {
|
|
722
|
+
let t = Array.isArray(e) ? e : [];
|
|
723
|
+
for (let e of t) {
|
|
724
|
+
if (!e || typeof e != "object" || !("role" in e) || e.role !== "user") continue;
|
|
725
|
+
let t = Array.isArray(e.content) ? e.content : null;
|
|
726
|
+
if (t) for (let e = 0; e < t.length; e += 1) {
|
|
727
|
+
let n = t[e];
|
|
728
|
+
if (!n || typeof n != "object" || n.type !== "file") continue;
|
|
729
|
+
let r = Y(n.mediaType);
|
|
730
|
+
if (r?.startsWith("image/") || r === "application/pdf") continue;
|
|
731
|
+
let i = Y(n.filename) ?? Y(n.name) ?? `attachment-${e + 1}`, a = n.data;
|
|
732
|
+
if (r?.startsWith("text/") && a instanceof Uint8Array) {
|
|
733
|
+
let n = (Buffer.isBuffer(a) ? a : Buffer.from(a)).toString("utf8");
|
|
734
|
+
n.length > ft && (n = `${n.slice(0, ft)}\n\n[Truncated]`);
|
|
735
|
+
let o = r === "text/csv" || i.toLowerCase().endsWith(".csv") ? "csv" : "";
|
|
736
|
+
t[e] = {
|
|
737
|
+
type: "text",
|
|
738
|
+
text: `${`Attached file "${i}" (${r}):`}${o ? `\n\n\`\`\`${o}\n${n}\n\`\`\`` : `\n\n\`\`\`\n${n}\n\`\`\``}`
|
|
739
|
+
};
|
|
740
|
+
continue;
|
|
741
|
+
}
|
|
742
|
+
let o = typeof a == "string" && a.trim() ? `\nURL: ${a}` : "";
|
|
743
|
+
t[e] = {
|
|
744
|
+
type: "text",
|
|
745
|
+
text: `Attached file "${i}" (${r ?? "unknown"}) cannot be sent as a file to this OpenAI model (only images and PDFs are supported).${o}`
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}, kt = async (e, t, n) => {
|
|
750
|
+
if (e.message?.role === "user") return ot(e.message.parts);
|
|
751
|
+
if (Array.isArray(e.messages)) {
|
|
752
|
+
let t = null;
|
|
753
|
+
for (let n = e.messages.length - 1; n >= 0; --n) {
|
|
754
|
+
let r = e.messages[n];
|
|
755
|
+
if (r?.role !== "user") continue;
|
|
756
|
+
let i = ot(r.parts);
|
|
757
|
+
if (i) {
|
|
758
|
+
if (J(i)) return i;
|
|
759
|
+
t ??= i;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
if (t) return t;
|
|
763
|
+
}
|
|
764
|
+
let r = await h(t, n), i = null;
|
|
765
|
+
for (let e = r.length - 1; e >= 0; --e) {
|
|
766
|
+
let t = r[e];
|
|
767
|
+
if (t.role !== "user") continue;
|
|
768
|
+
let n = ot(t.parts);
|
|
769
|
+
if (n) {
|
|
770
|
+
if (J(n)) return n;
|
|
771
|
+
i ??= n;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return i ?? "";
|
|
775
|
+
}, At = (e) => {
|
|
776
|
+
let t = Array.isArray(e.messages) && e.messages.length > 0 ? e.messages.at(-1) : e.message;
|
|
777
|
+
return !t || t.role !== "user" ? "" : (Array.isArray(t.parts) ? t.parts : []).filter((e) => !!e && typeof e == "object" && !!e && "type" in e && "text" in e && e.type === "text" && typeof e.text == "string").map((e) => e.text).join("\n").trim();
|
|
778
|
+
}, jt = (e) => {
|
|
779
|
+
let t = e.id;
|
|
780
|
+
return typeof t == "string" && t.trim() !== "" ? t : null;
|
|
781
|
+
}, Mt = (e) => {
|
|
782
|
+
let t = e.selectedChatModel;
|
|
783
|
+
return typeof t == "string" && t.trim() !== "" ? t : null;
|
|
784
|
+
}, Nt = (e) => {
|
|
785
|
+
let t = e.openaiReasoningEffort;
|
|
786
|
+
return typeof t == "string" && t.trim() !== "" ? t.trim() : null;
|
|
787
|
+
}, Pt = (e) => {
|
|
788
|
+
if (!e || typeof e != "object") return !1;
|
|
789
|
+
let t = e.state, n = e.toolCallId;
|
|
790
|
+
return typeof n == "string" && n.trim() !== "" && (t === "approval-responded" || t === "output-denied");
|
|
791
|
+
}, Ft = (e) => {
|
|
792
|
+
let t = Array.isArray(e.messages) ? e.messages : [];
|
|
793
|
+
return t.length === 0 || t.at(-1)?.role === "user" ? !1 : t.some((e) => (Array.isArray(e?.parts) ? e.parts : []).some((e) => Pt(e)));
|
|
794
|
+
}, It = (e) => {
|
|
795
|
+
let t = /* @__PURE__ */ new Map();
|
|
796
|
+
for (let n of e) {
|
|
797
|
+
let e = Array.isArray(n?.parts) ? n.parts : [];
|
|
798
|
+
for (let n of e) Pt(n) && t.set(n.toolCallId, n);
|
|
799
|
+
}
|
|
800
|
+
return t;
|
|
801
|
+
}, Lt = (e, t) => {
|
|
802
|
+
let n = [];
|
|
803
|
+
return {
|
|
804
|
+
changedMessages: n,
|
|
805
|
+
updatedMessages: e.map((e) => {
|
|
806
|
+
let r = !1, i = e.parts.map((e) => {
|
|
807
|
+
if (!e || typeof e != "object") return e;
|
|
808
|
+
let n = Y(e.toolCallId);
|
|
809
|
+
if (!n) return e;
|
|
810
|
+
let i = t.get(n);
|
|
811
|
+
return i ? (r = !0, {
|
|
812
|
+
...e,
|
|
813
|
+
...i
|
|
814
|
+
}) : e;
|
|
815
|
+
});
|
|
816
|
+
if (!r) return e;
|
|
817
|
+
let a = {
|
|
818
|
+
...e,
|
|
819
|
+
parts: i
|
|
820
|
+
};
|
|
821
|
+
return n.push(a), a;
|
|
822
|
+
})
|
|
823
|
+
};
|
|
824
|
+
}, Rt = (e) => {
|
|
825
|
+
if (!e || typeof e != "object" || !("createdAt" in e)) return null;
|
|
826
|
+
let t = e.createdAt;
|
|
827
|
+
if (typeof t != "string") return null;
|
|
828
|
+
let n = new Date(t);
|
|
829
|
+
return Number.isNaN(n.getTime()) ? null : n;
|
|
830
|
+
}, zt = (e) => ({
|
|
831
|
+
latitude: null,
|
|
832
|
+
longitude: null,
|
|
833
|
+
city: null,
|
|
834
|
+
country: null
|
|
835
|
+
}), Bt = (e) => {
|
|
836
|
+
let [t] = e.split("/");
|
|
837
|
+
return t && t !== e ? t : "unknown";
|
|
838
|
+
}, X = (e) => typeof e == "number" && Number.isFinite(e) ? e : void 0, Vt = (e) => e instanceof Error && e.message.trim() ? e.message : "Unknown error", Ht = (e) => e instanceof Error ? {
|
|
839
|
+
errorName: e.name,
|
|
840
|
+
errorMessage: e.message,
|
|
841
|
+
errorStack: e.stack,
|
|
842
|
+
errorCause: e.cause
|
|
843
|
+
} : { errorValue: e }, Z = (e, t, n) => {
|
|
844
|
+
console.error(e, {
|
|
845
|
+
...n,
|
|
846
|
+
...Ht(t)
|
|
847
|
+
});
|
|
848
|
+
}, Ut = (e) => ({
|
|
849
|
+
chatId: jt(e),
|
|
850
|
+
selectedChatModel: Mt(e)
|
|
851
|
+
}), Wt = (e) => {
|
|
852
|
+
let t = e && typeof e == "object" ? e : {}, n = t.inputTokenDetails && typeof t.inputTokenDetails == "object" ? t.inputTokenDetails : {}, r = t.outputTokenDetails && typeof t.outputTokenDetails == "object" ? t.outputTokenDetails : {};
|
|
853
|
+
return {
|
|
854
|
+
inputTokens: X(t.inputTokens),
|
|
855
|
+
outputTokens: X(t.outputTokens),
|
|
856
|
+
totalTokens: X(t.totalTokens),
|
|
857
|
+
cachedInputTokens: X(n.cacheReadTokens) ?? X(t.cachedInputTokens),
|
|
858
|
+
reasoningTokens: X(r.reasoningTokens) ?? X(t.reasoningTokens),
|
|
859
|
+
rawUsage: Object.keys(t).length > 0 ? t.raw ?? t : void 0
|
|
860
|
+
};
|
|
861
|
+
}, Gt = () => ({
|
|
862
|
+
inputTokens: 0,
|
|
863
|
+
outputTokens: 0,
|
|
864
|
+
totalTokens: 0,
|
|
865
|
+
cachedInputTokens: 0,
|
|
866
|
+
reasoningTokens: 0
|
|
867
|
+
}), Kt = async ({ ctx: e, chatId: t, agent: n, selectedChatModel: r, mode: i }) => {
|
|
868
|
+
try {
|
|
869
|
+
return { workspaceId: Y((await a().resolveUsageContext?.({
|
|
870
|
+
ctx: e,
|
|
871
|
+
chatId: t,
|
|
872
|
+
agent: n,
|
|
873
|
+
selectedChatModel: r,
|
|
874
|
+
mode: i
|
|
875
|
+
}))?.workspaceId) ?? void 0 };
|
|
876
|
+
} catch (e) {
|
|
877
|
+
return console.warn("Failed to resolve agent usage context.", e), { workspaceId: void 0 };
|
|
878
|
+
}
|
|
879
|
+
}, qt = async ({ ctx: e, chatId: t, agent: n, selectedChatModel: r, mode: i }) => {
|
|
880
|
+
let o = a().shouldGenerateChatTitle;
|
|
881
|
+
if (!o) return !0;
|
|
882
|
+
try {
|
|
883
|
+
return await o({
|
|
884
|
+
ctx: e,
|
|
885
|
+
chatId: t,
|
|
886
|
+
agent: n,
|
|
887
|
+
selectedChatModel: r,
|
|
888
|
+
mode: i
|
|
889
|
+
});
|
|
890
|
+
} catch (e) {
|
|
891
|
+
return console.warn("Failed to resolve chat title generation setting.", e), !0;
|
|
892
|
+
}
|
|
893
|
+
}, Q = async ({ ctx: e, usageContext: t, agent: n, chatId: r, mode: i, feature: a, modelId: o, status: s, billable: c, usage: l, finishReason: u, error: d, startedAt: f, finishedAt: p = /* @__PURE__ */ new Date() }) => {
|
|
894
|
+
let m = l ? Wt(l) : {}, h = {
|
|
895
|
+
id: D(),
|
|
896
|
+
workspaceId: t.workspaceId,
|
|
897
|
+
agentId: n.id,
|
|
898
|
+
chatId: r,
|
|
899
|
+
mode: i,
|
|
900
|
+
feature: a,
|
|
901
|
+
provider: Bt(o),
|
|
902
|
+
model: o,
|
|
903
|
+
billable: c,
|
|
904
|
+
status: s,
|
|
905
|
+
finishReason: Y(u) ?? void 0,
|
|
906
|
+
errorMessage: d ? Vt(d) : void 0,
|
|
907
|
+
...m,
|
|
908
|
+
startedAt: f,
|
|
909
|
+
finishedAt: p,
|
|
910
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
911
|
+
};
|
|
912
|
+
try {
|
|
913
|
+
await y(e, h);
|
|
914
|
+
} catch (e) {
|
|
915
|
+
console.error("Failed to save agents usage event.", e);
|
|
916
|
+
}
|
|
917
|
+
}, Jt = (e) => `agents-sdk:chat:${e}:stream`, Yt = async ({ ctx: e, chatId: t, selectedChatModel: n }) => await a().resolveAgent?.({
|
|
918
|
+
ctx: e,
|
|
919
|
+
chatId: t,
|
|
920
|
+
selectedChatModel: n
|
|
921
|
+
}) ?? i(), Xt = ({ ctx: e, chatId: t, mode: n, streamTransport: r }) => {
|
|
922
|
+
let i = o(e), a = Jt(t), s = te({
|
|
923
|
+
chatId: t,
|
|
924
|
+
abortWhenNoSubscribersMs: n === "headless" || r ? 0 : void 0
|
|
925
|
+
});
|
|
926
|
+
n === "interactive" && s.subscribe(e);
|
|
927
|
+
let c = (e) => {
|
|
928
|
+
r && r.publish({
|
|
929
|
+
tenantId: i.tenantId,
|
|
930
|
+
userId: i.userId,
|
|
931
|
+
channel: a,
|
|
932
|
+
payload: e
|
|
933
|
+
});
|
|
934
|
+
};
|
|
935
|
+
return {
|
|
936
|
+
abortController: s.abortController,
|
|
937
|
+
publishJson: (e) => {
|
|
938
|
+
s.publishJson(e), c({
|
|
939
|
+
chatId: t,
|
|
940
|
+
part: e
|
|
941
|
+
});
|
|
942
|
+
},
|
|
943
|
+
publishDone: () => {
|
|
944
|
+
s.publishDone(), c({
|
|
945
|
+
chatId: t,
|
|
946
|
+
done: !0
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
}, Zt = ({ ctx: e, chatId: t, streamTransport: n, message: r }) => {
|
|
951
|
+
if (!n) return;
|
|
952
|
+
let i = o(e);
|
|
953
|
+
n.publish({
|
|
954
|
+
tenantId: i.tenantId,
|
|
955
|
+
userId: i.userId,
|
|
956
|
+
channel: Jt(t),
|
|
957
|
+
payload: {
|
|
958
|
+
chatId: t,
|
|
959
|
+
message: r
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
}, $ = async ({ payload: e, ctx: t, mode: i = "interactive", streamTransport: l = null }) => {
|
|
963
|
+
let f = jt(e);
|
|
964
|
+
if (!f) return s(t, "bad_request:api", "Parameter id is required.");
|
|
965
|
+
let m = e, _ = Mt(m), v = vt(process.env.PLAYWRIGHT), y = !vt(process.env.AGENT_SDK_LIVE_CHAT) && v || process.env.NODE_ENV === "test";
|
|
966
|
+
if (!_) return s(t, "bad_request:api", "Parameter selectedChatModel is required.");
|
|
967
|
+
if (_ === mt && (y = !0), _ !== mt && (!yt().has(_) || !he(_))) return s(t, "bad_request:api", `Unsupported selectedChatModel: "${_}".`);
|
|
968
|
+
let x = process.env.OPENAI_API_KEY, te = process.env.GOOGLE_GENERATIVE_AI_API_KEY ?? process.env.GOOGLE_API_KEY, ne = process.env.XAI_API_KEY, S = de(_), oe = fe(_), C = pe(_), w = Nt(m), T = w && w !== "default" && w !== "off" ? w : null, le = r(_);
|
|
969
|
+
if (T && !le.some((e) => e === T)) return s(t, "bad_request:api", `Unsupported reasoning effort "${T}" for selectedChatModel: "${_}".`);
|
|
970
|
+
if (!y && S && !x) return s(t, "bad_request:provider", "Missing OPENAI_API_KEY.");
|
|
971
|
+
if (!y && oe && !te) return s(t, "bad_request:provider", "Missing GOOGLE_GENERATIVE_AI_API_KEY (or GOOGLE_API_KEY).");
|
|
972
|
+
if (!y && C && !ne) return s(t, "bad_request:provider", "Missing XAI_API_KEY.");
|
|
973
|
+
if (!y && !S && !oe && !C) return s(t, "bad_request:provider", `Unsupported selectedChatModel: "${_}".`);
|
|
974
|
+
let E = await Yt({
|
|
975
|
+
ctx: t,
|
|
976
|
+
chatId: f,
|
|
977
|
+
selectedChatModel: _
|
|
978
|
+
}), ue = await a().resolveKnowledge?.({
|
|
979
|
+
ctx: t,
|
|
980
|
+
chatId: f,
|
|
981
|
+
agent: E,
|
|
982
|
+
selectedChatModel: _
|
|
983
|
+
}) ?? null, O = await Kt({
|
|
984
|
+
ctx: t,
|
|
985
|
+
chatId: f,
|
|
986
|
+
agent: E,
|
|
987
|
+
selectedChatModel: _,
|
|
988
|
+
mode: i
|
|
989
|
+
}), k = await qt({
|
|
990
|
+
ctx: t,
|
|
991
|
+
chatId: f,
|
|
992
|
+
agent: E,
|
|
993
|
+
selectedChatModel: _,
|
|
994
|
+
mode: i
|
|
995
|
+
}), A = o(t), j = await u(t, f, { includeDeleted: !0 });
|
|
996
|
+
if (j?.deletedAt) return s(t, "not_found:chat");
|
|
997
|
+
j ? j.selectedChatModel !== _ && await d(t, {
|
|
998
|
+
chatId: f,
|
|
999
|
+
selectedChatModel: _
|
|
1000
|
+
}) : await g(t, {
|
|
1001
|
+
id: f,
|
|
1002
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1003
|
+
userId: A.userId,
|
|
1004
|
+
title: "",
|
|
1005
|
+
isStreaming: !1,
|
|
1006
|
+
selectedChatModel: _,
|
|
1007
|
+
lastContext: null
|
|
1008
|
+
});
|
|
1009
|
+
let M = m.message, N = typeof M?.id == "string" ? M.id : D(), P = Array.isArray(M?.parts) ? M?.parts : [];
|
|
1010
|
+
if ((typeof M?.role == "string" ? M.role : null) === "user") {
|
|
1011
|
+
let e = /* @__PURE__ */ new Date();
|
|
1012
|
+
await p(t, [{
|
|
1013
|
+
id: N,
|
|
1014
|
+
chatId: f,
|
|
1015
|
+
role: "user",
|
|
1016
|
+
parts: P,
|
|
1017
|
+
attachments: [],
|
|
1018
|
+
createdAt: e
|
|
1019
|
+
}]), Zt({
|
|
1020
|
+
ctx: t,
|
|
1021
|
+
chatId: f,
|
|
1022
|
+
streamTransport: l,
|
|
1023
|
+
message: {
|
|
1024
|
+
id: N,
|
|
1025
|
+
role: "user",
|
|
1026
|
+
parts: P,
|
|
1027
|
+
metadata: { createdAt: e.toISOString() }
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
if (y) {
|
|
1032
|
+
await b(t, {
|
|
1033
|
+
chatId: f,
|
|
1034
|
+
isStreaming: !0
|
|
1035
|
+
});
|
|
1036
|
+
let e = Xt({
|
|
1037
|
+
ctx: t,
|
|
1038
|
+
chatId: f,
|
|
1039
|
+
mode: i,
|
|
1040
|
+
streamTransport: l
|
|
1041
|
+
});
|
|
1042
|
+
try {
|
|
1043
|
+
if (k) {
|
|
1044
|
+
let n = J(await kt(m, t, f)), r = await u(t, f);
|
|
1045
|
+
r && at(r.title) && n && n !== r.title && (await c(t, {
|
|
1046
|
+
chatId: f,
|
|
1047
|
+
title: n
|
|
1048
|
+
}), e.publishJson({
|
|
1049
|
+
type: "data-chat-title",
|
|
1050
|
+
data: n,
|
|
1051
|
+
transient: !0
|
|
1052
|
+
}));
|
|
1053
|
+
}
|
|
1054
|
+
let n = D();
|
|
1055
|
+
v && !e.abortController.signal.aborted && await gt(600), e.publishJson({
|
|
1056
|
+
type: "start",
|
|
1057
|
+
messageId: n
|
|
1058
|
+
});
|
|
1059
|
+
let r = "text-1";
|
|
1060
|
+
e.publishJson({
|
|
1061
|
+
type: "text-start",
|
|
1062
|
+
id: r
|
|
1063
|
+
});
|
|
1064
|
+
let a = At(m), o = a ? `Echo: ${a}` : "Hello from agents-sdk", s = Date.now(), l = o.split(/(\s+)/).filter((e) => e.length > 0);
|
|
1065
|
+
for (let t of l) {
|
|
1066
|
+
if (e.abortController.signal.aborted) break;
|
|
1067
|
+
e.publishJson({
|
|
1068
|
+
type: "text-delta",
|
|
1069
|
+
id: r,
|
|
1070
|
+
delta: t
|
|
1071
|
+
}), await gt(v ? 120 : 80);
|
|
1072
|
+
}
|
|
1073
|
+
if (v && !e.abortController.signal.aborted) {
|
|
1074
|
+
let e = Date.now() - s, t = 1200;
|
|
1075
|
+
e < t && await gt(t - e);
|
|
1076
|
+
}
|
|
1077
|
+
return e.abortController.signal.aborted ? {} : (e.publishJson({
|
|
1078
|
+
type: "text-end",
|
|
1079
|
+
id: r
|
|
1080
|
+
}), e.publishJson({
|
|
1081
|
+
type: "finish",
|
|
1082
|
+
finishReason: "stop"
|
|
1083
|
+
}), e.publishDone(), await p(t, [{
|
|
1084
|
+
id: n,
|
|
1085
|
+
chatId: f,
|
|
1086
|
+
role: "assistant",
|
|
1087
|
+
parts: [{
|
|
1088
|
+
type: "text",
|
|
1089
|
+
text: o
|
|
1090
|
+
}],
|
|
1091
|
+
attachments: [],
|
|
1092
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
1093
|
+
}]), await Q({
|
|
1094
|
+
ctx: t,
|
|
1095
|
+
usageContext: O,
|
|
1096
|
+
agent: E,
|
|
1097
|
+
chatId: f,
|
|
1098
|
+
mode: i,
|
|
1099
|
+
feature: "chat",
|
|
1100
|
+
modelId: _,
|
|
1101
|
+
status: "success",
|
|
1102
|
+
billable: !1,
|
|
1103
|
+
usage: Gt(),
|
|
1104
|
+
finishReason: "stop",
|
|
1105
|
+
startedAt: new Date(s)
|
|
1106
|
+
}), {});
|
|
1107
|
+
} finally {
|
|
1108
|
+
await _t(t, f);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
let F = zt(t), I = Ft(m);
|
|
1112
|
+
if (Array.isArray(m.messages) && !I) {
|
|
1113
|
+
let e = m.messages.flatMap((e) => {
|
|
1114
|
+
let t = typeof e?.id == "string" ? e.id : null, n = typeof e?.role == "string" ? e.role : null, r = Array.isArray(e?.parts) ? e.parts : [];
|
|
1115
|
+
return !t || !n ? [] : [{
|
|
1116
|
+
id: t,
|
|
1117
|
+
chatId: f,
|
|
1118
|
+
role: n,
|
|
1119
|
+
parts: r,
|
|
1120
|
+
attachments: [],
|
|
1121
|
+
createdAt: Rt(e?.metadata) ?? /* @__PURE__ */ new Date()
|
|
1122
|
+
}];
|
|
1123
|
+
});
|
|
1124
|
+
e.length > 0 && await p(t, e);
|
|
1125
|
+
}
|
|
1126
|
+
let L;
|
|
1127
|
+
if (Array.isArray(m.messages) && m.messages.length > 0 && I) {
|
|
1128
|
+
let e = await h(t, f);
|
|
1129
|
+
if (e.length === 0) L = m.messages;
|
|
1130
|
+
else {
|
|
1131
|
+
let { changedMessages: n, updatedMessages: r } = Lt(e, It(m.messages));
|
|
1132
|
+
n.length > 0 && await p(t, n), L = r.map((e) => ({
|
|
1133
|
+
id: e.id,
|
|
1134
|
+
role: e.role,
|
|
1135
|
+
parts: e.parts,
|
|
1136
|
+
metadata: { createdAt: e.createdAt.toISOString() }
|
|
1137
|
+
}));
|
|
1138
|
+
}
|
|
1139
|
+
} else L = Array.isArray(m.messages) && m.messages.length > 0 ? m.messages : (await h(t, f)).map((e) => ({
|
|
1140
|
+
id: e.id,
|
|
1141
|
+
role: e.role,
|
|
1142
|
+
parts: e.parts,
|
|
1143
|
+
metadata: { createdAt: e.createdAt.toISOString() }
|
|
1144
|
+
}));
|
|
1145
|
+
let R = I ? {
|
|
1146
|
+
messages: L,
|
|
1147
|
+
lastContext: j?.lastContext ?? null,
|
|
1148
|
+
lastContextChanged: !1
|
|
1149
|
+
} : await We({
|
|
1150
|
+
ctx: t,
|
|
1151
|
+
chatId: f,
|
|
1152
|
+
agent: E,
|
|
1153
|
+
selectedChatModel: _,
|
|
1154
|
+
mode: i,
|
|
1155
|
+
messages: L,
|
|
1156
|
+
lastContext: j?.lastContext ?? null
|
|
1157
|
+
});
|
|
1158
|
+
if (!I && R.lastContextChanged) try {
|
|
1159
|
+
await ee(t, {
|
|
1160
|
+
chatId: f,
|
|
1161
|
+
lastContext: R.lastContext
|
|
1162
|
+
});
|
|
1163
|
+
} catch (e) {
|
|
1164
|
+
console.warn("Failed to save compacted agent chat history context.", e);
|
|
1165
|
+
}
|
|
1166
|
+
let ge = R.messages;
|
|
1167
|
+
await b(t, {
|
|
1168
|
+
chatId: f,
|
|
1169
|
+
isStreaming: !0
|
|
1170
|
+
});
|
|
1171
|
+
let z = Xt({
|
|
1172
|
+
ctx: t,
|
|
1173
|
+
chatId: f,
|
|
1174
|
+
mode: i,
|
|
1175
|
+
streamTransport: l
|
|
1176
|
+
}), B = "", V = "";
|
|
1177
|
+
if (k) try {
|
|
1178
|
+
B = await kt(m, t, f), V = J(B);
|
|
1179
|
+
let e = await u(t, f);
|
|
1180
|
+
e && at(e.title) && V && V !== e.title && (await c(t, {
|
|
1181
|
+
chatId: f,
|
|
1182
|
+
title: V
|
|
1183
|
+
}), z.publishJson({
|
|
1184
|
+
type: "data-chat-title",
|
|
1185
|
+
data: V,
|
|
1186
|
+
transient: !0
|
|
1187
|
+
}));
|
|
1188
|
+
} catch (e) {
|
|
1189
|
+
Z("Failed to prepare agent chat title.", e, {
|
|
1190
|
+
chatId: f,
|
|
1191
|
+
selectedChatModel: _,
|
|
1192
|
+
agentId: E.id,
|
|
1193
|
+
mode: i
|
|
1194
|
+
}), z.publishJson({
|
|
1195
|
+
type: "error",
|
|
1196
|
+
errorText: "Something went wrong."
|
|
1197
|
+
}), z.publishDone();
|
|
1198
|
+
try {
|
|
1199
|
+
await _t(t, f);
|
|
1200
|
+
} catch (e) {
|
|
1201
|
+
Z("Failed to update chat streaming state.", e, {
|
|
1202
|
+
chatId: f,
|
|
1203
|
+
selectedChatModel: _,
|
|
1204
|
+
agentId: E.id,
|
|
1205
|
+
mode: i
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
return {};
|
|
1209
|
+
}
|
|
1210
|
+
k && B && V && x && (async () => {
|
|
1211
|
+
let e = /* @__PURE__ */ new Date();
|
|
1212
|
+
try {
|
|
1213
|
+
let { text: n } = await ae({
|
|
1214
|
+
model: ve(),
|
|
1215
|
+
system: Ce,
|
|
1216
|
+
prompt: B,
|
|
1217
|
+
onFinish: async (n) => {
|
|
1218
|
+
await Q({
|
|
1219
|
+
ctx: t,
|
|
1220
|
+
usageContext: O,
|
|
1221
|
+
agent: E,
|
|
1222
|
+
chatId: f,
|
|
1223
|
+
mode: i,
|
|
1224
|
+
feature: "title",
|
|
1225
|
+
modelId: ht,
|
|
1226
|
+
status: "success",
|
|
1227
|
+
billable: !0,
|
|
1228
|
+
usage: n.totalUsage ?? n.usage,
|
|
1229
|
+
finishReason: n.finishReason,
|
|
1230
|
+
startedAt: e
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
}), r = st(n);
|
|
1234
|
+
if (!r) return;
|
|
1235
|
+
let a = await u(t, f);
|
|
1236
|
+
if (!a) return;
|
|
1237
|
+
a.title !== r && (await c(t, {
|
|
1238
|
+
chatId: f,
|
|
1239
|
+
title: r
|
|
1240
|
+
}), z.publishJson({
|
|
1241
|
+
type: "data-chat-title",
|
|
1242
|
+
data: r,
|
|
1243
|
+
transient: !0
|
|
1244
|
+
}));
|
|
1245
|
+
} catch (n) {
|
|
1246
|
+
await Q({
|
|
1247
|
+
ctx: t,
|
|
1248
|
+
usageContext: O,
|
|
1249
|
+
agent: E,
|
|
1250
|
+
chatId: f,
|
|
1251
|
+
mode: i,
|
|
1252
|
+
feature: "title",
|
|
1253
|
+
modelId: ht,
|
|
1254
|
+
status: "error",
|
|
1255
|
+
billable: !1,
|
|
1256
|
+
error: n,
|
|
1257
|
+
startedAt: e
|
|
1258
|
+
}), console.warn("Failed to generate chat title.", n);
|
|
1259
|
+
}
|
|
1260
|
+
})();
|
|
1261
|
+
let ye = ie({
|
|
1262
|
+
originalMessages: L,
|
|
1263
|
+
onError: (e) => (Z("Agent chat stream failed.", e, {
|
|
1264
|
+
chatId: f,
|
|
1265
|
+
selectedChatModel: _,
|
|
1266
|
+
agentId: E.id,
|
|
1267
|
+
mode: i
|
|
1268
|
+
}), "Something went wrong."),
|
|
1269
|
+
onFinish: async ({ responseMessage: e }) => {
|
|
1270
|
+
let n = Array.isArray(e.parts) ? e.parts : [];
|
|
1271
|
+
await p(t, [{
|
|
1272
|
+
id: e.id ?? D(),
|
|
1273
|
+
chatId: f,
|
|
1274
|
+
role: e.role ?? "assistant",
|
|
1275
|
+
parts: n,
|
|
1276
|
+
attachments: [],
|
|
1277
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
1278
|
+
}]);
|
|
1279
|
+
},
|
|
1280
|
+
execute: async ({ writer: e }) => {
|
|
1281
|
+
let n = Qe({
|
|
1282
|
+
ctx: t,
|
|
1283
|
+
dataStream: e,
|
|
1284
|
+
requestHints: F
|
|
1285
|
+
}), r = [
|
|
1286
|
+
"getWeather",
|
|
1287
|
+
"createDocument",
|
|
1288
|
+
"editDocument",
|
|
1289
|
+
"updateDocument",
|
|
1290
|
+
"requestSuggestions",
|
|
1291
|
+
"webSearch"
|
|
1292
|
+
], o = [
|
|
1293
|
+
"getWeather",
|
|
1294
|
+
"createDocument",
|
|
1295
|
+
"editDocument",
|
|
1296
|
+
"updateDocument",
|
|
1297
|
+
"requestSuggestions"
|
|
1298
|
+
], s = me(_), c = s ? [] : S ? r : o, l = n, u = c, d = await a().resolveTools?.({
|
|
1299
|
+
ctx: t,
|
|
1300
|
+
dataStream: e,
|
|
1301
|
+
requestHints: F,
|
|
1302
|
+
agent: E,
|
|
1303
|
+
selectedChatModel: _,
|
|
1304
|
+
availableTools: n,
|
|
1305
|
+
defaultActiveTools: c
|
|
1306
|
+
});
|
|
1307
|
+
d && (l = d.tools, u = d.activeTools ?? Object.keys(d.tools)), u = it({
|
|
1308
|
+
activeTools: u,
|
|
1309
|
+
availableTools: l,
|
|
1310
|
+
userText: At(m)
|
|
1311
|
+
});
|
|
1312
|
+
let p = await re(ge.map((e) => ({
|
|
1313
|
+
role: e?.role,
|
|
1314
|
+
parts: e?.parts,
|
|
1315
|
+
metadata: e?.metadata
|
|
1316
|
+
})), {
|
|
1317
|
+
tools: l,
|
|
1318
|
+
ignoreIncompleteToolCalls: !0
|
|
1319
|
+
});
|
|
1320
|
+
await Dt(t, p), S && Ot(p);
|
|
1321
|
+
let h = typeof m.openaiReasoningSummary == "string" ? m.openaiReasoningSummary : null, g;
|
|
1322
|
+
S && T ? g = { openai: {
|
|
1323
|
+
reasoningEffort: T,
|
|
1324
|
+
reasoningSummary: h ?? void 0
|
|
1325
|
+
} } : C && s && T && (g = { xai: { reasoningEffort: T } });
|
|
1326
|
+
let v = !1, y = /* @__PURE__ */ new Date(), b = async ({ status: e, usage: n, finishReason: r, error: a }) => {
|
|
1327
|
+
v || (v = !0, await Q({
|
|
1328
|
+
ctx: t,
|
|
1329
|
+
usageContext: O,
|
|
1330
|
+
agent: E,
|
|
1331
|
+
chatId: f,
|
|
1332
|
+
mode: i,
|
|
1333
|
+
feature: "chat",
|
|
1334
|
+
modelId: _,
|
|
1335
|
+
status: e,
|
|
1336
|
+
billable: e === "success",
|
|
1337
|
+
usage: n,
|
|
1338
|
+
finishReason: r,
|
|
1339
|
+
error: a,
|
|
1340
|
+
startedAt: y
|
|
1341
|
+
}));
|
|
1342
|
+
}, ee = ce({
|
|
1343
|
+
model: _e(_),
|
|
1344
|
+
system: be({
|
|
1345
|
+
selectedChatModel: _,
|
|
1346
|
+
requestHints: F,
|
|
1347
|
+
agentInstructions: E.instructions,
|
|
1348
|
+
knowledge: ue
|
|
1349
|
+
}),
|
|
1350
|
+
messages: p,
|
|
1351
|
+
tools: l,
|
|
1352
|
+
stopWhen: se(5),
|
|
1353
|
+
abortSignal: z.abortController.signal,
|
|
1354
|
+
providerOptions: g,
|
|
1355
|
+
activeTools: u,
|
|
1356
|
+
onFinish: async (e) => {
|
|
1357
|
+
await b({
|
|
1358
|
+
status: "success",
|
|
1359
|
+
usage: e.totalUsage ?? e.usage,
|
|
1360
|
+
finishReason: e.finishReason
|
|
1361
|
+
});
|
|
1362
|
+
},
|
|
1363
|
+
onError: async (e) => {
|
|
1364
|
+
await b({
|
|
1365
|
+
status: "error",
|
|
1366
|
+
error: e?.error ?? e
|
|
1367
|
+
});
|
|
1368
|
+
},
|
|
1369
|
+
onAbort: async (e) => {
|
|
1370
|
+
await b({
|
|
1371
|
+
status: "aborted",
|
|
1372
|
+
usage: e?.totalUsage ?? e?.usage,
|
|
1373
|
+
finishReason: e?.finishReason
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
});
|
|
1377
|
+
e.merge(ee.toUIMessageStream({
|
|
1378
|
+
originalMessages: L,
|
|
1379
|
+
sendReasoning: s || !!(S && T)
|
|
1380
|
+
}));
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
return (async () => {
|
|
1384
|
+
let e = null, r = null, a = Date.now(), o = !1, s = null, c = async () => {
|
|
1385
|
+
let e = Date.now();
|
|
1386
|
+
if (!(e - a < 6e4)) {
|
|
1387
|
+
a = e;
|
|
1388
|
+
try {
|
|
1389
|
+
await b(t, {
|
|
1390
|
+
chatId: f,
|
|
1391
|
+
isStreaming: !0
|
|
1392
|
+
});
|
|
1393
|
+
} catch (e) {
|
|
1394
|
+
console.warn("Failed to refresh chat streaming heartbeat.", e);
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
}, l = () => {
|
|
1398
|
+
if (!o || s) return;
|
|
1399
|
+
let e = c().finally(() => {
|
|
1400
|
+
s === e && (s = null);
|
|
1401
|
+
});
|
|
1402
|
+
s = e;
|
|
1403
|
+
}, u = () => {
|
|
1404
|
+
o = !0;
|
|
1405
|
+
let e = setInterval(() => {
|
|
1406
|
+
l();
|
|
1407
|
+
}, n);
|
|
1408
|
+
return async () => {
|
|
1409
|
+
o = !1, clearInterval(e), await s;
|
|
1410
|
+
};
|
|
1411
|
+
};
|
|
1412
|
+
try {
|
|
1413
|
+
let t = ye.getReader();
|
|
1414
|
+
for (e = () => t.releaseLock(), r = u();;) {
|
|
1415
|
+
let { value: e, done: n } = await t.read();
|
|
1416
|
+
if (n) break;
|
|
1417
|
+
z.publishJson(e), await c();
|
|
1418
|
+
}
|
|
1419
|
+
z.publishDone();
|
|
1420
|
+
} catch (e) {
|
|
1421
|
+
Z("Agent chat runtime stream failed.", e, {
|
|
1422
|
+
chatId: f,
|
|
1423
|
+
selectedChatModel: _,
|
|
1424
|
+
agentId: E.id,
|
|
1425
|
+
mode: i
|
|
1426
|
+
}), z.publishJson({
|
|
1427
|
+
type: "error",
|
|
1428
|
+
errorText: "Something went wrong."
|
|
1429
|
+
}), z.publishDone();
|
|
1430
|
+
} finally {
|
|
1431
|
+
await r?.(), e?.();
|
|
1432
|
+
try {
|
|
1433
|
+
await _t(t, f);
|
|
1434
|
+
} catch (e) {
|
|
1435
|
+
Z("Failed to update chat streaming state.", e, {
|
|
1436
|
+
chatId: f,
|
|
1437
|
+
selectedChatModel: _,
|
|
1438
|
+
agentId: E.id,
|
|
1439
|
+
mode: i
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
})(), {};
|
|
1444
|
+
}, Qt = async (e, t) => {
|
|
1445
|
+
try {
|
|
1446
|
+
return await $({
|
|
1447
|
+
payload: e,
|
|
1448
|
+
ctx: t,
|
|
1449
|
+
mode: "interactive"
|
|
1450
|
+
});
|
|
1451
|
+
} catch (n) {
|
|
1452
|
+
return Z("Agent chat request failed.", n, {
|
|
1453
|
+
...Ut(e),
|
|
1454
|
+
mode: "interactive"
|
|
1455
|
+
}), s(t, "internal:api");
|
|
1456
|
+
}
|
|
1457
|
+
}, $t = async (e, t) => {
|
|
1458
|
+
let n = t.req.query.id, r = Array.isArray(n) ? n[0] : n;
|
|
1459
|
+
return typeof r != "string" || r.trim() === "" ? s(t, "bad_request:api") : _(t, r);
|
|
1460
|
+
}, en = (e) => {
|
|
1461
|
+
e.get(lt, (async (e, n) => {
|
|
1462
|
+
let r = n.req.query.id, i = Array.isArray(r) ? r[0] : r;
|
|
1463
|
+
if (typeof i != "string" || i.trim() === "") return s(n, "bad_request:api", "Parameter id is required.");
|
|
1464
|
+
let a = await u(n, i);
|
|
1465
|
+
if (!a) return s(n, "not_found:chat");
|
|
1466
|
+
let o = x(i);
|
|
1467
|
+
return t(a) && (!o || o.isDone) && (a = await f(n, a)), a;
|
|
1468
|
+
})), e.post(lt, Qt), e.delete(lt, $t);
|
|
1469
|
+
};
|
|
1470
|
+
//#endregion
|
|
1471
|
+
export { $ as n, ut as t };
|