@aparte/core 1.7.0 → 1.9.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/client/agent-runner.d.ts +8 -3
- package/dist/client/agent-runner.d.ts.map +1 -1
- package/dist/client/aparte-client.d.ts +8 -0
- package/dist/client/aparte-client.d.ts.map +1 -1
- package/dist/client/stream-adapter.d.ts.map +1 -1
- package/dist/components/bubble/aparte-chat-bubble.d.ts +13 -3
- package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -1
- package/dist/components/chat/aparte-chat.d.ts +64 -0
- package/dist/components/chat/aparte-chat.d.ts.map +1 -1
- package/dist/components/composer/aparte-composer-input.d.ts +3 -1
- package/dist/components/composer/aparte-composer-input.d.ts.map +1 -1
- package/dist/components/composer/aparte-composer-send.d.ts +11 -0
- package/dist/components/composer/aparte-composer-send.d.ts.map +1 -1
- package/dist/config/aparte-config.d.ts +84 -10
- package/dist/config/aparte-config.d.ts.map +1 -1
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/link-target.d.ts +39 -0
- package/dist/config/link-target.d.ts.map +1 -0
- package/dist/config/locale.d.ts +7 -0
- package/dist/config/locale.d.ts.map +1 -1
- package/dist/config/sanitize.d.ts +22 -3
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/step-label.d.ts +22 -0
- package/dist/config/step-label.d.ts.map +1 -0
- package/dist/conversations/conversation-controller.d.ts +14 -0
- package/dist/conversations/conversation-controller.d.ts.map +1 -1
- package/dist/conversations/open-conversation.d.ts +28 -0
- package/dist/conversations/open-conversation.d.ts.map +1 -0
- package/dist/custom-elements.json +1275 -523
- package/dist/{defer-hydration-o5MFsc_Z.js → defer-hydration-Ch3TOEJC.js} +401 -88
- package/dist/defer-hydration-Ch3TOEJC.js.map +1 -0
- package/dist/generated/element-attributes.d.ts +11 -4
- package/dist/generated/element-attributes.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -11
- package/dist/index.js.map +1 -1
- package/dist/index.node.d.ts +2 -2
- package/dist/index.node.d.ts.map +1 -1
- package/dist/index.node.js +1 -1
- package/dist/index.node.js.map +1 -1
- package/dist/renderers/citations.d.ts.map +1 -1
- package/dist/renderers/segments/tool-call.d.ts.map +1 -1
- package/dist/transport/agent-handler.d.ts +13 -0
- package/dist/transport/agent-handler.d.ts.map +1 -1
- package/dist/types/element-attributes.d.ts +5 -2
- package/dist/types/element-attributes.d.ts.map +1 -1
- package/dist/types/events.d.ts +4 -3
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/imperative-api.d.ts +15 -0
- package/dist/types/imperative-api.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/segments.d.ts +9 -0
- package/dist/types/segments.d.ts.map +1 -1
- package/dist/types/tools.d.ts +28 -0
- package/dist/types/tools.d.ts.map +1 -1
- package/dist/utils/segments.d.ts +2 -0
- package/dist/utils/segments.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/defer-hydration-o5MFsc_Z.js.map +0 -1
|
@@ -132,6 +132,7 @@ const APARTE_DEFAULT_LOCALE = {
|
|
|
132
132
|
checkpointPending: "Summarising the context…",
|
|
133
133
|
checkpointFailed: "Couldn't summarise the context",
|
|
134
134
|
toolRunning: "Running",
|
|
135
|
+
toolQueued: "Queued",
|
|
135
136
|
toolCompleted: "Done",
|
|
136
137
|
toolRejected: "Rejected",
|
|
137
138
|
toolStopped: "Stopped",
|
|
@@ -1103,8 +1104,9 @@ function stampSegmentOnInsert(segments, segment, messageId, defaults) {
|
|
|
1103
1104
|
};
|
|
1104
1105
|
}
|
|
1105
1106
|
function adoptSegment(segments, segment, messageId, live2 = false) {
|
|
1107
|
+
const { queued: _live, ...rest } = segment;
|
|
1106
1108
|
return {
|
|
1107
|
-
...
|
|
1109
|
+
...rest,
|
|
1108
1110
|
messageId,
|
|
1109
1111
|
index: segments.length,
|
|
1110
1112
|
isStreaming: false,
|
|
@@ -1983,8 +1985,8 @@ function endTag(tag) {
|
|
|
1983
1985
|
}
|
|
1984
1986
|
return re;
|
|
1985
1987
|
}
|
|
1986
|
-
const COMMENT_END = /--!?>/g;
|
|
1987
|
-
const ASCII_LETTER$
|
|
1988
|
+
const COMMENT_END$1 = /--!?>/g;
|
|
1989
|
+
const ASCII_LETTER$2 = /[A-Za-z]/;
|
|
1988
1990
|
const SPACE = /\s/;
|
|
1989
1991
|
const NAME_END = /[\s/>]/;
|
|
1990
1992
|
const ATTR_NAME_END = /[\s/>=]/;
|
|
@@ -2097,8 +2099,8 @@ function rewriteTags(html) {
|
|
|
2097
2099
|
if (html[at] === ">") i = at + 1;
|
|
2098
2100
|
else if (html.startsWith("->", at)) i = at + 2;
|
|
2099
2101
|
else {
|
|
2100
|
-
COMMENT_END.lastIndex = at;
|
|
2101
|
-
const m = COMMENT_END.exec(html);
|
|
2102
|
+
COMMENT_END$1.lastIndex = at;
|
|
2103
|
+
const m = COMMENT_END$1.exec(html);
|
|
2102
2104
|
if (!m) break;
|
|
2103
2105
|
i = m.index + m[0].length;
|
|
2104
2106
|
}
|
|
@@ -2106,7 +2108,7 @@ function rewriteTags(html) {
|
|
|
2106
2108
|
}
|
|
2107
2109
|
const closing = html[lt + 1] === "/";
|
|
2108
2110
|
const nameAt = lt + (closing ? 2 : 1);
|
|
2109
|
-
if (!ASCII_LETTER$
|
|
2111
|
+
if (!ASCII_LETTER$2.test(html[nameAt] ?? "")) {
|
|
2110
2112
|
if (html[lt + 1] === "!" || html[lt + 1] === "?" || closing) {
|
|
2111
2113
|
const end2 = html.indexOf(">", lt + 1);
|
|
2112
2114
|
i = end2 < 0 ? n : end2 + 1;
|
|
@@ -2163,6 +2165,22 @@ function webUrl(source) {
|
|
|
2163
2165
|
const url = source.url?.trim();
|
|
2164
2166
|
return url && /^https?:\/\//i.test(url) && isSafeUrl(url, "a") ? url : void 0;
|
|
2165
2167
|
}
|
|
2168
|
+
function sourceLink(url, title, config, newTabWords) {
|
|
2169
|
+
const link = document.createElement("a");
|
|
2170
|
+
link.href = url;
|
|
2171
|
+
const opens2 = config.decideLink(url);
|
|
2172
|
+
if (opens2.target) link.target = opens2.target;
|
|
2173
|
+
if (opens2.rel) link.rel = opens2.rel;
|
|
2174
|
+
link.textContent = title;
|
|
2175
|
+
link.dir = "auto";
|
|
2176
|
+
if (opens2.target === "_blank") {
|
|
2177
|
+
const hint = document.createElement("span");
|
|
2178
|
+
hint.className = "aparte-sr-only";
|
|
2179
|
+
hint.textContent = ` ${newTabWords}`;
|
|
2180
|
+
link.append(hint);
|
|
2181
|
+
}
|
|
2182
|
+
return link;
|
|
2183
|
+
}
|
|
2166
2184
|
function sourceDomain(source) {
|
|
2167
2185
|
const url = webUrl(source);
|
|
2168
2186
|
if (url) {
|
|
@@ -2556,18 +2574,10 @@ function drawCard() {
|
|
|
2556
2574
|
const url = webUrl(source);
|
|
2557
2575
|
const title = source.title || sourceDomain(source) || source.url || "";
|
|
2558
2576
|
if (url) {
|
|
2559
|
-
const link =
|
|
2577
|
+
const link = sourceLink(url, title, config, locale.opensInNewTab ?? "(opens in a new tab)");
|
|
2560
2578
|
link.className = "aparte-citation-card__title";
|
|
2561
|
-
link.href = url;
|
|
2562
|
-
link.target = "_blank";
|
|
2563
|
-
link.rel = "noopener noreferrer";
|
|
2564
2579
|
link.dataset.aparteCardPart = "link";
|
|
2565
|
-
link.
|
|
2566
|
-
link.dir = "auto";
|
|
2567
|
-
const hint = document.createElement("span");
|
|
2568
|
-
hint.className = "aparte-sr-only";
|
|
2569
|
-
hint.textContent = ` ${locale.opensInNewTab ?? "(opens in a new tab)"}`;
|
|
2570
|
-
link.append(hint);
|
|
2580
|
+
link.addEventListener("click", announceLink);
|
|
2571
2581
|
body.append(link);
|
|
2572
2582
|
} else {
|
|
2573
2583
|
const plain = document.createElement("p");
|
|
@@ -2600,6 +2610,23 @@ function drawCard() {
|
|
|
2600
2610
|
else (el2.querySelector(".aparte-citation-card__pager button:not([disabled])") ?? el2.querySelector("a"))?.focus();
|
|
2601
2611
|
}
|
|
2602
2612
|
}
|
|
2613
|
+
function announceLink(event) {
|
|
2614
|
+
const chip = card?.chip;
|
|
2615
|
+
const anchor = event.currentTarget;
|
|
2616
|
+
if (!chip?.isConnected) return;
|
|
2617
|
+
const detail = {
|
|
2618
|
+
href: anchor.getAttribute("href") ?? "",
|
|
2619
|
+
anchor,
|
|
2620
|
+
messageId: chip.closest("aparte-chat-bubble")?.getAttribute("message-id") ?? null
|
|
2621
|
+
};
|
|
2622
|
+
const announced = chip.dispatchEvent(new CustomEvent("aparte-link-click", {
|
|
2623
|
+
bubbles: true,
|
|
2624
|
+
composed: true,
|
|
2625
|
+
cancelable: true,
|
|
2626
|
+
detail
|
|
2627
|
+
}));
|
|
2628
|
+
if (!announced) event.preventDefault();
|
|
2629
|
+
}
|
|
2603
2630
|
function pagerButton(label, icon, part, disabled, act) {
|
|
2604
2631
|
const button = document.createElement("button");
|
|
2605
2632
|
button.type = "button";
|
|
@@ -2654,17 +2681,7 @@ function renderSourceList(container, after, sources2, config) {
|
|
|
2654
2681
|
const title = s.title || domain || s.url || "";
|
|
2655
2682
|
const url = webUrl(s);
|
|
2656
2683
|
if (url) {
|
|
2657
|
-
|
|
2658
|
-
link.href = url;
|
|
2659
|
-
link.target = "_blank";
|
|
2660
|
-
link.rel = "noopener noreferrer";
|
|
2661
|
-
link.textContent = title;
|
|
2662
|
-
link.dir = "auto";
|
|
2663
|
-
const hint = document.createElement("span");
|
|
2664
|
-
hint.className = "aparte-sr-only";
|
|
2665
|
-
hint.textContent = ` ${hintText}`;
|
|
2666
|
-
link.append(hint);
|
|
2667
|
-
item.append(link);
|
|
2684
|
+
item.append(sourceLink(url, title, config, hintText));
|
|
2668
2685
|
} else {
|
|
2669
2686
|
item.append(Object.assign(document.createElement("span"), { textContent: title, dir: "auto" }));
|
|
2670
2687
|
}
|
|
@@ -3225,6 +3242,7 @@ function stateBadge(segment) {
|
|
|
3225
3242
|
const status = segment.status ?? "pending";
|
|
3226
3243
|
const word = (text) => escapeHtml(text);
|
|
3227
3244
|
if (status === "awaiting-approval") return `${cfg.getIcon("pause")}${word(cfg.t("approvalWaiting"))}`;
|
|
3245
|
+
if (isQueued(segment)) return word(cfg.t("toolQueued"));
|
|
3228
3246
|
if (status === "pending") return word(cfg.t("toolRunning"));
|
|
3229
3247
|
if (status === "resolved") return `${cfg.getIcon("check")}${word(cfg.t("toolCompleted"))}`;
|
|
3230
3248
|
if (status === "rejected") return `${cfg.getIcon("close")}${word(cfg.t("toolRejected"))}`;
|
|
@@ -3468,18 +3486,21 @@ function iconOf(segment) {
|
|
|
3468
3486
|
return (key ? cfg.getIcon(key) : void 0) || cfg.getIcon("tool");
|
|
3469
3487
|
}
|
|
3470
3488
|
const isQuiet = (segment) => contextConfig().getToolDisplay(segment.toolCall?.name ?? "")?.quiet ?? true;
|
|
3489
|
+
const isQueued = (segment) => (segment.status ?? "pending") === "pending" && (segment.queued === true || segment.deferred?.reason === "queued");
|
|
3471
3490
|
function quietOf(segment) {
|
|
3472
3491
|
const status = segment.status ?? "pending";
|
|
3473
3492
|
const quiet = isQuiet(segment);
|
|
3493
|
+
const running = status === "pending" && !isQueued(segment);
|
|
3474
3494
|
return {
|
|
3475
|
-
shimmer: quiet &&
|
|
3476
|
-
spinner: !quiet &&
|
|
3477
|
-
stateHidden: quiet && (
|
|
3495
|
+
shimmer: quiet && running,
|
|
3496
|
+
spinner: !quiet && running,
|
|
3497
|
+
stateHidden: quiet && (running || status === "resolved")
|
|
3478
3498
|
};
|
|
3479
3499
|
}
|
|
3480
3500
|
function setQuiet(element, segment) {
|
|
3481
3501
|
const quiet = quietOf(segment);
|
|
3482
3502
|
element.toggleAttribute("data-quiet", isQuiet(segment));
|
|
3503
|
+
element.toggleAttribute("data-queued", isQueued(segment));
|
|
3483
3504
|
element.querySelector(".aparte-tool-spinner")?.toggleAttribute("hidden", !quiet.spinner);
|
|
3484
3505
|
element.querySelector(".aparte-tool-name")?.classList.toggle("aparte-shimmer", quiet.shimmer);
|
|
3485
3506
|
element.querySelector(".aparte-tool-state")?.classList.toggle("aparte-sr-only", quiet.stateHidden);
|
|
@@ -3593,7 +3614,7 @@ function drawDefault(segment, behind2, line) {
|
|
|
3593
3614
|
const status = segment.status ?? "pending";
|
|
3594
3615
|
const toolCallId = segment.toolCall?.id ?? "";
|
|
3595
3616
|
const pill = pillMarkup(segment, line);
|
|
3596
|
-
const quiet = isQuiet(segment) ? " data-quiet" : "";
|
|
3617
|
+
const quiet = (isQuiet(segment) ? " data-quiet" : "") + (isQueued(segment) ? " data-queued" : "");
|
|
3597
3618
|
const opensAt = openAttrs(line);
|
|
3598
3619
|
const toggle = contextConfig().getIcon("expand");
|
|
3599
3620
|
const input = behind2.kind === "parts" ? describeInput(segment) : "";
|
|
@@ -4043,9 +4064,11 @@ function createStreamAdapter(opts) {
|
|
|
4043
4064
|
let streaming = /* @__PURE__ */ new Set();
|
|
4044
4065
|
let thinkingId = null;
|
|
4045
4066
|
const toolSegments = /* @__PURE__ */ new Map();
|
|
4046
|
-
const
|
|
4067
|
+
const queued = /* @__PURE__ */ new Set();
|
|
4068
|
+
const unqueued = (id, update) => queued.delete(id) ? { ...update, queued: void 0 } : update;
|
|
4069
|
+
const settle2 = (toolCallId, update) => {
|
|
4047
4070
|
const id = `tool-${toolCallId}`;
|
|
4048
|
-
target.updateSegment?.(id, toolSegments.has(id) ? update : { ...update, deferred: void 0 });
|
|
4071
|
+
target.updateSegment?.(id, unqueued(id, toolSegments.has(id) ? update : { ...update, deferred: void 0 }));
|
|
4049
4072
|
};
|
|
4050
4073
|
let thinkingContent = "";
|
|
4051
4074
|
let thinkingCollapsed = false;
|
|
@@ -4232,40 +4255,48 @@ function createStreamAdapter(opts) {
|
|
|
4232
4255
|
id: `tool-${e.toolCallId}`,
|
|
4233
4256
|
type: "tool_call",
|
|
4234
4257
|
toolCall: { id: e.toolCallId, name: e.name, input: e.input },
|
|
4235
|
-
status: "pending"
|
|
4258
|
+
status: "pending",
|
|
4259
|
+
// Read while it cannot go on yet: its row now, where the model wrote it.
|
|
4260
|
+
...e.queued ? { queued: true } : {}
|
|
4236
4261
|
};
|
|
4237
4262
|
toolSegments.set(toolSeg.id, toolSeg);
|
|
4263
|
+
if (e.queued) queued.add(toolSeg.id);
|
|
4238
4264
|
const renderer = config.getToolRenderer(e.name);
|
|
4239
4265
|
if (renderer) injectToolRendererStyles(e.name, renderer);
|
|
4240
4266
|
target.addSegment?.(toolSeg);
|
|
4241
4267
|
break;
|
|
4242
4268
|
}
|
|
4269
|
+
case "tool-running": {
|
|
4270
|
+
const id = `tool-${e.toolCallId}`;
|
|
4271
|
+
if (queued.delete(id)) target.updateSegment?.(id, { queued: void 0 });
|
|
4272
|
+
break;
|
|
4273
|
+
}
|
|
4243
4274
|
case "tool-awaiting-approval":
|
|
4244
|
-
target.updateSegment?.(`tool-${e.toolCallId}`, { status: "awaiting-approval" });
|
|
4275
|
+
target.updateSegment?.(`tool-${e.toolCallId}`, unqueued(`tool-${e.toolCallId}`, { status: "awaiting-approval" }));
|
|
4245
4276
|
dispatchLifecycleEvent(target, "aparte-tool-approval-request", { toolCallId: e.toolCallId, toolName: e.name, input: e.input }, targetId);
|
|
4246
4277
|
break;
|
|
4247
4278
|
case "tool-approved":
|
|
4248
|
-
|
|
4279
|
+
settle2(e.toolCallId, { status: "pending" });
|
|
4249
4280
|
break;
|
|
4250
4281
|
case "tool-rejected":
|
|
4251
|
-
|
|
4282
|
+
settle2(e.toolCallId, {
|
|
4252
4283
|
status: "rejected",
|
|
4253
4284
|
result: e.reason,
|
|
4254
4285
|
...e.by ? { refusal: e.instruction ? { by: e.by, instruction: e.instruction } : { by: e.by } } : {}
|
|
4255
4286
|
});
|
|
4256
4287
|
break;
|
|
4257
4288
|
case "tool-resolved":
|
|
4258
|
-
|
|
4289
|
+
settle2(e.toolCallId, {
|
|
4259
4290
|
status: "resolved",
|
|
4260
4291
|
result: e.result,
|
|
4261
4292
|
...e.structuredResult !== void 0 ? { structuredResult: e.structuredResult } : {}
|
|
4262
4293
|
});
|
|
4263
4294
|
break;
|
|
4264
4295
|
case "tool-aborted":
|
|
4265
|
-
|
|
4296
|
+
settle2(e.toolCallId, e.cause ? { status: "aborted", abortCause: e.cause } : { status: "aborted" });
|
|
4266
4297
|
break;
|
|
4267
4298
|
case "tool-failed":
|
|
4268
|
-
|
|
4299
|
+
settle2(e.toolCallId, { status: "failed", result: e.error });
|
|
4269
4300
|
break;
|
|
4270
4301
|
case "turn-limit-exceeded":
|
|
4271
4302
|
if (e.scope === "global") {
|
|
@@ -4279,7 +4310,7 @@ function createStreamAdapter(opts) {
|
|
|
4279
4310
|
code: AparteErrorCode.MAX_TURNS_EXCEEDED
|
|
4280
4311
|
});
|
|
4281
4312
|
} else if (e.toolCallId) {
|
|
4282
|
-
|
|
4313
|
+
settle2(e.toolCallId, { status: "aborted", abortCause: "turn-limit" });
|
|
4283
4314
|
}
|
|
4284
4315
|
break;
|
|
4285
4316
|
case "run-aborted":
|
|
@@ -4293,7 +4324,7 @@ function createStreamAdapter(opts) {
|
|
|
4293
4324
|
if (p.agentId != null) continue;
|
|
4294
4325
|
const id = `tool-${p.toolCallId}`;
|
|
4295
4326
|
const deferred2 = { reason: p.reason, ...typeof ticket === "string" ? { ticket } : {} };
|
|
4296
|
-
target.updateSegment?.(id, { deferred: deferred2 });
|
|
4327
|
+
target.updateSegment?.(id, unqueued(id, { deferred: deferred2 }));
|
|
4297
4328
|
}
|
|
4298
4329
|
target.updateMessage?.(messageId, { status: "completed" });
|
|
4299
4330
|
if (e.usage) {
|
|
@@ -4488,9 +4519,10 @@ function createAparteAgentHandler(options) {
|
|
|
4488
4519
|
return jsonError(400, "Invalid JSON body.");
|
|
4489
4520
|
}
|
|
4490
4521
|
if (body?.v !== 1) return jsonError(400, "Unsupported agent wire version: expected v 1.");
|
|
4491
|
-
if (body.providerId !== void 0 && typeof body.providerId !== "string" || typeof body.messageId !== "string" || !Array.isArray(body.request?.messages)) {
|
|
4492
|
-
return jsonError(400, "Body must be { v: 1, providerId?, messageId, request: { messages } }.");
|
|
4522
|
+
if (body.providerId !== void 0 && typeof body.providerId !== "string" || body.conversationId !== void 0 && typeof body.conversationId !== "string" || typeof body.messageId !== "string" || !Array.isArray(body.request?.messages)) {
|
|
4523
|
+
return jsonError(400, "Body must be { v: 1, providerId?, messageId, conversationId?, request: { messages } }.");
|
|
4493
4524
|
}
|
|
4525
|
+
const conversationId = body.conversationId || void 0;
|
|
4494
4526
|
if (body.request.toolChoice && typeof body.request.toolChoice === "object") {
|
|
4495
4527
|
return jsonError(400, "A forced tool call cannot come from the browser.");
|
|
4496
4528
|
}
|
|
@@ -4592,7 +4624,11 @@ function createAparteAgentHandler(options) {
|
|
|
4592
4624
|
},
|
|
4593
4625
|
toolLookup: (name) => {
|
|
4594
4626
|
const t = offered.has(name) ? tools.get(name) : void 0;
|
|
4595
|
-
return t ? (call, signal, run2) => t.handler(call, signal,
|
|
4627
|
+
return t ? (call, signal, run2) => t.handler(call, signal, {
|
|
4628
|
+
request: req,
|
|
4629
|
+
...conversationId ? { conversationId } : {},
|
|
4630
|
+
...run2 ? { run: run2 } : {}
|
|
4631
|
+
}) : void 0;
|
|
4596
4632
|
},
|
|
4597
4633
|
toolConfigLookup: (name) => {
|
|
4598
4634
|
if (!offered.has(name)) return void 0;
|
|
@@ -4601,6 +4637,7 @@ function createAparteAgentHandler(options) {
|
|
|
4601
4637
|
if (!t) return void 0;
|
|
4602
4638
|
return {
|
|
4603
4639
|
...t.tool.maxTurns !== void 0 ? { maxTurns: t.tool.maxTurns } : {},
|
|
4640
|
+
...t.tool.parallel !== void 0 ? { parallel: t.tool.parallel } : {},
|
|
4604
4641
|
needsApproval: (call) => {
|
|
4605
4642
|
const ruling = rule(call);
|
|
4606
4643
|
if (ruling?.verdict === "allow") return false;
|
|
@@ -4620,6 +4657,7 @@ function createAparteAgentHandler(options) {
|
|
|
4620
4657
|
signal: run.signal,
|
|
4621
4658
|
...options.maxTurns !== void 0 ? { maxTurns: options.maxTurns } : {},
|
|
4622
4659
|
...options.toolTimeoutMs !== void 0 ? { toolTimeoutMs: options.toolTimeoutMs } : {},
|
|
4660
|
+
...options.parallelTools !== void 0 ? { parallelTools: options.parallelTools } : {},
|
|
4623
4661
|
// Ids that cannot repeat from one request to the next, as the browser
|
|
4624
4662
|
// client mints them. The engine's default is a counter per run, and every
|
|
4625
4663
|
// request is a run: the resume of a paused reply named its first sub-agent
|
|
@@ -4836,7 +4874,7 @@ const MAY_HOLD = /<(?:img|source)\b|data-aparte-image/i;
|
|
|
4836
4874
|
const HELD = "a[data-aparte-image], span[data-aparte-image]";
|
|
4837
4875
|
function applyImagePolicy(html, decide, words) {
|
|
4838
4876
|
if (!html || !MAY_HOLD.test(html)) return html;
|
|
4839
|
-
return typeof document === "undefined" ? applyImagePolicyWithoutDom(html, decide, words) : applyInTemplate(html, decide, words);
|
|
4877
|
+
return typeof document === "undefined" ? applyImagePolicyWithoutDom(html, decide, words) : applyInTemplate$1(html, decide, words);
|
|
4840
4878
|
}
|
|
4841
4879
|
function judgeImage(src, srcset, decide) {
|
|
4842
4880
|
const candidates = srcset === void 0 ? [] : parseSrcset(srcset);
|
|
@@ -4854,7 +4892,7 @@ function judgeSource(src, srcset, decide) {
|
|
|
4854
4892
|
if (kept.length) return writeSrcset(kept);
|
|
4855
4893
|
return NO_ADDRESS.test(src) ? false : null;
|
|
4856
4894
|
}
|
|
4857
|
-
function applyInTemplate(html, decide, words) {
|
|
4895
|
+
function applyInTemplate$1(html, decide, words) {
|
|
4858
4896
|
const template = document.createElement("template");
|
|
4859
4897
|
template.innerHTML = html;
|
|
4860
4898
|
const root = template.content;
|
|
@@ -4918,12 +4956,12 @@ function applyInTemplate(html, decide, words) {
|
|
|
4918
4956
|
}
|
|
4919
4957
|
return changed ? template.innerHTML : html;
|
|
4920
4958
|
}
|
|
4921
|
-
const RAW_TEXT = /* @__PURE__ */ new Set(["script", "style", "textarea", "title", "xmp", "iframe", "noembed", "noframes", "noscript", "plaintext"]);
|
|
4959
|
+
const RAW_TEXT$1 = /* @__PURE__ */ new Set(["script", "style", "textarea", "title", "xmp", "iframe", "noembed", "noframes", "noscript", "plaintext"]);
|
|
4922
4960
|
const VOID = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr"]);
|
|
4923
|
-
const ASCII_LETTER = /[A-Za-z]/;
|
|
4924
|
-
const SAFE_NAME = /^[a-z][a-z0-9_.:-]*$/;
|
|
4961
|
+
const ASCII_LETTER$1 = /[A-Za-z]/;
|
|
4962
|
+
const SAFE_NAME$1 = /^[a-z][a-z0-9_.:-]*$/;
|
|
4925
4963
|
function writeTag(tag, attrs, replace) {
|
|
4926
|
-
const kept = attrs.filter(([name]) => !(name in replace) && SAFE_NAME.test(name));
|
|
4964
|
+
const kept = attrs.filter(([name]) => !(name in replace) && SAFE_NAME$1.test(name));
|
|
4927
4965
|
const added = Object.entries(replace).filter((entry) => entry[1] !== null);
|
|
4928
4966
|
return `<${tag}${[...kept, ...added].map(([name, value]) => ` ${name}="${escapeAttr(value)}"`).join("")}>`;
|
|
4929
4967
|
}
|
|
@@ -4965,7 +5003,7 @@ function applyImagePolicyWithoutDom(html, decide, words) {
|
|
|
4965
5003
|
}
|
|
4966
5004
|
const closing = html[lt + 1] === "/";
|
|
4967
5005
|
const nameAt = lt + (closing ? 2 : 1);
|
|
4968
|
-
if (!ASCII_LETTER.test(html[nameAt] ?? "")) {
|
|
5006
|
+
if (!ASCII_LETTER$1.test(html[nameAt] ?? "")) {
|
|
4969
5007
|
out += "<";
|
|
4970
5008
|
i = lt + 1;
|
|
4971
5009
|
continue;
|
|
@@ -4985,7 +5023,7 @@ function applyImagePolicyWithoutDom(html, decide, words) {
|
|
|
4985
5023
|
continue;
|
|
4986
5024
|
}
|
|
4987
5025
|
const attr = (name) => attrs.find(([key]) => key === name)?.[1];
|
|
4988
|
-
if (RAW_TEXT.has(tag)) {
|
|
5026
|
+
if (RAW_TEXT$1.has(tag)) {
|
|
4989
5027
|
const close = lower.indexOf(`</${tag}`, end);
|
|
4990
5028
|
const stop = close < 0 ? n : close;
|
|
4991
5029
|
out += written + html.slice(end, stop);
|
|
@@ -5027,6 +5065,125 @@ function applyImagePolicyWithoutDom(html, decide, words) {
|
|
|
5027
5065
|
}
|
|
5028
5066
|
return out;
|
|
5029
5067
|
}
|
|
5068
|
+
const STAYS = /^(?:#|mailto:|tel:|sms:)/i;
|
|
5069
|
+
const NEW_TAB = [["target", "_blank"], ["rel", "noopener noreferrer"]];
|
|
5070
|
+
const NEW_TAB_DECISION = Object.freeze({ target: "_blank", rel: "noopener noreferrer" });
|
|
5071
|
+
const IN_PLACE = Object.freeze({});
|
|
5072
|
+
function linkTargetAttributes(mode, href, wish) {
|
|
5073
|
+
if (mode !== "external-only" && !STAYS.test(href.replace(CONTROL_WS, ""))) return NEW_TAB;
|
|
5074
|
+
return linkAttributes(href, wish);
|
|
5075
|
+
}
|
|
5076
|
+
function linkDecision(mode, href) {
|
|
5077
|
+
return linkTargetAttributes(mode, href, "").length ? NEW_TAB_DECISION : IN_PLACE;
|
|
5078
|
+
}
|
|
5079
|
+
const MAY_LINK = /<a[\s/>]/i;
|
|
5080
|
+
function applyLinkTarget(html, mode) {
|
|
5081
|
+
if (!html || !MAY_LINK.test(html)) return html;
|
|
5082
|
+
return typeof document === "undefined" ? applyLinkTargetWithoutDom(html, mode) : applyInTemplate(html, mode);
|
|
5083
|
+
}
|
|
5084
|
+
function relForNewTab(rel) {
|
|
5085
|
+
const tokens = (rel ?? "").split(/[ \t\n\f\r]+/).filter((token) => token && token.toLowerCase() !== "opener");
|
|
5086
|
+
for (const needed of ["noopener", "noreferrer"]) {
|
|
5087
|
+
if (!tokens.some((token) => token.toLowerCase() === needed)) tokens.push(needed);
|
|
5088
|
+
}
|
|
5089
|
+
return tokens.join(" ");
|
|
5090
|
+
}
|
|
5091
|
+
function settle(decided, target, rel) {
|
|
5092
|
+
const wantedTarget = decided.find(([key]) => key === "target")?.[1];
|
|
5093
|
+
if (wantedTarget !== "_blank") return (target ?? void 0) === wantedTarget ? null : { target: wantedTarget, rel: void 0 };
|
|
5094
|
+
const wantedRel = relForNewTab(rel);
|
|
5095
|
+
return (target ?? void 0) === wantedTarget && (rel ?? void 0) === wantedRel ? null : { target: wantedTarget, rel: wantedRel };
|
|
5096
|
+
}
|
|
5097
|
+
function applyInTemplate(html, mode) {
|
|
5098
|
+
const template = document.createElement("template");
|
|
5099
|
+
template.innerHTML = html;
|
|
5100
|
+
let changed = false;
|
|
5101
|
+
for (const anchor of Array.from(template.content.querySelectorAll("a[href]"))) {
|
|
5102
|
+
const decided = linkTargetAttributes(mode, anchor.getAttribute("href") ?? "", anchor.getAttribute("target") ?? "");
|
|
5103
|
+
const settled2 = settle(decided, anchor.getAttribute("target"), anchor.getAttribute("rel"));
|
|
5104
|
+
if (!settled2) continue;
|
|
5105
|
+
anchor.removeAttribute("target");
|
|
5106
|
+
if (settled2.target !== void 0) anchor.setAttribute("target", settled2.target);
|
|
5107
|
+
if (settled2.rel !== void 0) {
|
|
5108
|
+
anchor.removeAttribute("rel");
|
|
5109
|
+
anchor.setAttribute("rel", settled2.rel);
|
|
5110
|
+
}
|
|
5111
|
+
changed = true;
|
|
5112
|
+
}
|
|
5113
|
+
return changed ? template.innerHTML : html;
|
|
5114
|
+
}
|
|
5115
|
+
const RAW_TEXT = /* @__PURE__ */ new Set(["script", "style", "textarea", "title", "xmp", "iframe", "noembed", "noframes", "noscript", "plaintext"]);
|
|
5116
|
+
const ASCII_LETTER = /[A-Za-z]/;
|
|
5117
|
+
const SAFE_NAME = /^[a-z][a-z0-9_.:-]*$/;
|
|
5118
|
+
const COMMENT_END = /--!?>/g;
|
|
5119
|
+
function commentEnd(html, at) {
|
|
5120
|
+
if (html[at] === ">") return at + 1;
|
|
5121
|
+
if (html.startsWith("->", at)) return at + 2;
|
|
5122
|
+
COMMENT_END.lastIndex = at;
|
|
5123
|
+
const m = COMMENT_END.exec(html);
|
|
5124
|
+
return m ? m.index + m[0].length : html.length;
|
|
5125
|
+
}
|
|
5126
|
+
function linkTag(written, attrs, mode) {
|
|
5127
|
+
const attr = (name) => attrs.find(([key]) => key === name)?.[1];
|
|
5128
|
+
const href = attr("href");
|
|
5129
|
+
if (href === void 0) return written;
|
|
5130
|
+
const decided = linkTargetAttributes(mode, href, attr("target") ?? "");
|
|
5131
|
+
const settled2 = settle(decided, attr("target"), attr("rel"));
|
|
5132
|
+
if (!settled2) return written;
|
|
5133
|
+
const kept = attrs.filter(([name]) => name !== "target" && (settled2.rel === void 0 || name !== "rel") && SAFE_NAME.test(name));
|
|
5134
|
+
const added = [];
|
|
5135
|
+
if (settled2.target !== void 0) added.push(["target", settled2.target]);
|
|
5136
|
+
if (settled2.rel !== void 0) added.push(["rel", settled2.rel]);
|
|
5137
|
+
return `<a${[...kept, ...added].map(([name, value]) => ` ${name}="${escapeAttr(value)}"`).join("")}>`;
|
|
5138
|
+
}
|
|
5139
|
+
function applyLinkTargetWithoutDom(html, mode) {
|
|
5140
|
+
if (!html || !MAY_LINK.test(html)) return html;
|
|
5141
|
+
const lower = html.toLowerCase();
|
|
5142
|
+
const n = html.length;
|
|
5143
|
+
let out = "";
|
|
5144
|
+
let i = 0;
|
|
5145
|
+
while (i < n) {
|
|
5146
|
+
const lt = html.indexOf("<", i);
|
|
5147
|
+
if (lt < 0) {
|
|
5148
|
+
out += html.slice(i);
|
|
5149
|
+
break;
|
|
5150
|
+
}
|
|
5151
|
+
out += html.slice(i, lt);
|
|
5152
|
+
if (html.startsWith("<!--", lt)) {
|
|
5153
|
+
const stop = commentEnd(html, lt + 4);
|
|
5154
|
+
out += html.slice(lt, stop);
|
|
5155
|
+
i = stop;
|
|
5156
|
+
continue;
|
|
5157
|
+
}
|
|
5158
|
+
const closing = html[lt + 1] === "/";
|
|
5159
|
+
const nameAt = lt + (closing ? 2 : 1);
|
|
5160
|
+
if (!ASCII_LETTER.test(html[nameAt] ?? "")) {
|
|
5161
|
+
out += "<";
|
|
5162
|
+
i = lt + 1;
|
|
5163
|
+
continue;
|
|
5164
|
+
}
|
|
5165
|
+
const { tag, attrs, end } = readTag(html, nameAt);
|
|
5166
|
+
if (end < 0) {
|
|
5167
|
+
out += html.slice(lt);
|
|
5168
|
+
break;
|
|
5169
|
+
}
|
|
5170
|
+
i = end;
|
|
5171
|
+
const written = html.slice(lt, end);
|
|
5172
|
+
if (closing) {
|
|
5173
|
+
out += written;
|
|
5174
|
+
continue;
|
|
5175
|
+
}
|
|
5176
|
+
if (RAW_TEXT.has(tag)) {
|
|
5177
|
+
const close = lower.indexOf(`</${tag}`, end);
|
|
5178
|
+
const stop = close < 0 ? n : close;
|
|
5179
|
+
out += written + html.slice(end, stop);
|
|
5180
|
+
i = stop;
|
|
5181
|
+
continue;
|
|
5182
|
+
}
|
|
5183
|
+
out += tag === "a" ? linkTag(written, attrs, mode) : written;
|
|
5184
|
+
}
|
|
5185
|
+
return out;
|
|
5186
|
+
}
|
|
5030
5187
|
class AparteElicitationAbortError extends DOMException {
|
|
5031
5188
|
/**
|
|
5032
5189
|
* Which of the two ways it ended.
|
|
@@ -5184,6 +5341,8 @@ class AparteConfig {
|
|
|
5184
5341
|
_imageDecider = compileImagePolicy([]);
|
|
5185
5342
|
/** Whether the app named an image policy, the default included; see `decideImage`. */
|
|
5186
5343
|
_imagePolicyNamed = false;
|
|
5344
|
+
// Where the links a reply holds open (`link-target.ts`): by default every one in a new tab.
|
|
5345
|
+
_linkTarget = "new-tab";
|
|
5187
5346
|
_systemPromptTemplate;
|
|
5188
5347
|
_systemPromptVarsProvider;
|
|
5189
5348
|
_statusRenderer;
|
|
@@ -5285,6 +5444,8 @@ class AparteConfig {
|
|
|
5285
5444
|
_activityRenderers = /* @__PURE__ */ new Map();
|
|
5286
5445
|
/** What a plugin says about a call, read after the app's display — see {@link setToolLineProvider}. */
|
|
5287
5446
|
_toolLineProvider = null;
|
|
5447
|
+
/** What a step is called on screen, by the name the run announces — see {@link registerStepLabel}. One entry per registration, so each remover takes back its own. */
|
|
5448
|
+
_stepLabels = /* @__PURE__ */ new Map();
|
|
5288
5449
|
/** Tagged blocks the stream parser recognises in the prose — see {@link registerStreamBlock}. */
|
|
5289
5450
|
_streamBlocks = /* @__PURE__ */ new Map();
|
|
5290
5451
|
_segmentDefaults = /* @__PURE__ */ new Map();
|
|
@@ -5501,9 +5662,11 @@ class AparteConfig {
|
|
|
5501
5662
|
* zero-dependency allowlist sanitizer.
|
|
5502
5663
|
*
|
|
5503
5664
|
* The function you pass REPLACES the built-in one, chat rules included: no
|
|
5504
|
-
* `aparte-` classes, no layout styles, no form controls
|
|
5505
|
-
*
|
|
5506
|
-
*
|
|
5665
|
+
* `aparte-` classes, no layout styles, no form controls. DOMPurify's defaults hold
|
|
5666
|
+
* none of the three, so chain it in front of `defaultSanitizer` rather than in its
|
|
5667
|
+
* place (the example below). Where a link opens ({@link AparteConfig.setLinkTarget | setLinkTarget})
|
|
5668
|
+
* and which pictures load ({@link AparteConfig.setImagePolicy | setImagePolicy}) are
|
|
5669
|
+
* applied after it, whichever it is.
|
|
5507
5670
|
*
|
|
5508
5671
|
* @param sanitizer A sanitizer function, or `null` to DISABLE sanitization.
|
|
5509
5672
|
* Disabling exposes you to XSS from LLM-authored content — only do so for
|
|
@@ -5523,16 +5686,19 @@ class AparteConfig {
|
|
|
5523
5686
|
this._notify();
|
|
5524
5687
|
}
|
|
5525
5688
|
/**
|
|
5526
|
-
* Run the active sanitizer over provider-produced HTML, then the
|
|
5527
|
-
* ({@link AparteConfig.
|
|
5528
|
-
*
|
|
5529
|
-
*
|
|
5530
|
-
*
|
|
5531
|
-
*
|
|
5689
|
+
* Run the active sanitizer over provider-produced HTML, then the link target
|
|
5690
|
+
* ({@link AparteConfig.setLinkTarget | setLinkTarget}): every link gets the `target` and
|
|
5691
|
+
* `rel` it opens with; then the image policy ({@link AparteConfig.setImagePolicy | setImagePolicy}):
|
|
5692
|
+
* a picture the policy does not let load comes back as a link that loads it on a click.
|
|
5693
|
+
* Public so a streaming-markdown provider (which appends DOM directly, bypassing
|
|
5694
|
+
* `renderMarkdown`) can apply the same rules. Both run whichever sanitizer is set, none
|
|
5695
|
+
* included, so replacing it does not send a reply's links back into the chat's own frame,
|
|
5696
|
+
* nor turn its pictures back into requests the reader never made.
|
|
5532
5697
|
*/
|
|
5533
5698
|
sanitizeHtml(html) {
|
|
5534
5699
|
const clean = this._sanitizer ? this._sanitizer(html) : html;
|
|
5535
|
-
|
|
5700
|
+
const linked = applyLinkTarget(clean, this._linkTarget);
|
|
5701
|
+
return applyImagePolicy(linked, (url) => this.decideImage(url), () => this._heldImageWords());
|
|
5536
5702
|
}
|
|
5537
5703
|
/**
|
|
5538
5704
|
* Which pictures a model or a tool chose load before the reader asks — in a reply's
|
|
@@ -5604,6 +5770,45 @@ class AparteConfig {
|
|
|
5604
5770
|
icon: this.getIcon("image")
|
|
5605
5771
|
};
|
|
5606
5772
|
}
|
|
5773
|
+
/**
|
|
5774
|
+
* Where the links a reply holds open — in its Markdown, its sources, a document it wrote.
|
|
5775
|
+
* `'new-tab'`, the default, opens every one in a new tab, same-site ones included;
|
|
5776
|
+
* `'external-only'` opens a link to another site in a new tab and keeps a same-site one in
|
|
5777
|
+
* the page, as before 1.9. Either way a link to `#…`, `mailto:`, `tel:` or `sms:` is left as
|
|
5778
|
+
* written, a new tab goes with `rel="noopener noreferrer"`, and the `target` the model wrote
|
|
5779
|
+
* does not choose. What is on screen is drawn again.
|
|
5780
|
+
*
|
|
5781
|
+
* In a single-page app or an Electron window, a same-site link followed in place replaces
|
|
5782
|
+
* the whole app, the conversation with it. To route a link yourself — your router, a pane,
|
|
5783
|
+
* the system browser — cancel the chat's `aparte-link-click`, whichever mode is set.
|
|
5784
|
+
*
|
|
5785
|
+
* @example aparteGlobalConfig.setLinkTarget('external-only');
|
|
5786
|
+
*/
|
|
5787
|
+
setLinkTarget(mode) {
|
|
5788
|
+
if (mode === this._linkTarget) return;
|
|
5789
|
+
this._linkTarget = mode;
|
|
5790
|
+
bumpRenderingVersion(this);
|
|
5791
|
+
this._notify();
|
|
5792
|
+
}
|
|
5793
|
+
/** Where the links a reply holds open: {@link AparteConfig.setLinkTarget | setLinkTarget}'s mode, `'new-tab'` by default. */
|
|
5794
|
+
getLinkTarget() {
|
|
5795
|
+
return this._linkTarget;
|
|
5796
|
+
}
|
|
5797
|
+
/**
|
|
5798
|
+
* Where a link to `href` opens under this config's link target: `{ target: '_blank', rel:
|
|
5799
|
+
* 'noopener noreferrer' }` for a new tab, `{}` for the page itself. For a plugin that draws
|
|
5800
|
+
* links itself, as `@aparte/plugin-streaming-markdown` does: set what it returns, and no
|
|
5801
|
+
* `target` of your own. It does not judge whether the address is safe to link —
|
|
5802
|
+
* `isSafeUrl` does.
|
|
5803
|
+
*
|
|
5804
|
+
* @example
|
|
5805
|
+
* const link = document.createElement('a');
|
|
5806
|
+
* link.href = url;
|
|
5807
|
+
* Object.assign(link, aparteGlobalConfig.decideLink(url));
|
|
5808
|
+
*/
|
|
5809
|
+
decideLink(href) {
|
|
5810
|
+
return linkDecision(this._linkTarget, href);
|
|
5811
|
+
}
|
|
5607
5812
|
/**
|
|
5608
5813
|
* Set the system prompt template. Supports `{{key}}` placeholders resolved via setSystemPromptVarsProvider.
|
|
5609
5814
|
* Pass undefined to clear.
|
|
@@ -6631,6 +6836,59 @@ class AparteConfig {
|
|
|
6631
6836
|
getToolInputFormatter(toolName) {
|
|
6632
6837
|
return this.getToolDisplay(toolName)?.formatInput;
|
|
6633
6838
|
}
|
|
6839
|
+
/**
|
|
6840
|
+
* Say how a step is called on screen, in place of the name a run announced. A server that
|
|
6841
|
+
* streams `step-start { name }` sends a stable key — `slot-wait`, `restore`, `reread` —
|
|
6842
|
+
* and the page knows the person's language: this maps one to the other, wherever a step is
|
|
6843
|
+
* shown (the waiting indicator, which a screen reader reads in place of "Typing", and a
|
|
6844
|
+
* sub-agent's line). A name nobody labelled shows as it always did: itself, because core
|
|
6845
|
+
* never makes a label up.
|
|
6846
|
+
*
|
|
6847
|
+
* The label is text, never HTML, or a function of the locale, asked at every draw and on
|
|
6848
|
+
* every config change — so a language switch changes the words of a step that is open.
|
|
6849
|
+
* One that throws, or says nothing, leaves the name. One label per name, per config:
|
|
6850
|
+
* registering a name again replaces its label, and a chat with a config of its own reads
|
|
6851
|
+
* that config's labels, as it reads its tool displays.
|
|
6852
|
+
*
|
|
6853
|
+
* Only what is shown is labelled. The step keeps the name the run announced — for
|
|
6854
|
+
* {@link observeRunEvents}, for the target, for everything an app stores — and is never
|
|
6855
|
+
* saved with the reply. Registering tells the chats on the page, so a label reaches a step
|
|
6856
|
+
* that is open. Returns the function that takes the label off again (it changes nothing
|
|
6857
|
+
* once another registration has replaced it).
|
|
6858
|
+
*
|
|
6859
|
+
* @example
|
|
6860
|
+
* aparteGlobalConfig.registerStepLabel('slot-wait', 'Waiting for a free slot…');
|
|
6861
|
+
*
|
|
6862
|
+
* @example
|
|
6863
|
+
* // In the person's language, and live: a switch of the locale relabels a step that is open.
|
|
6864
|
+
* aparteGlobalConfig.registerStepLabel('reread', ({ locale }) =>
|
|
6865
|
+
* locale.tag?.startsWith('fr') ? 'Relecture de la conversation…' : 'Re-reading the conversation…');
|
|
6866
|
+
*/
|
|
6867
|
+
registerStepLabel(name, label) {
|
|
6868
|
+
const entry = { label };
|
|
6869
|
+
this._stepLabels.set(name, entry);
|
|
6870
|
+
this._notify();
|
|
6871
|
+
return () => {
|
|
6872
|
+
if (this._stepLabels.get(name) !== entry) return;
|
|
6873
|
+
this._stepLabels.delete(name);
|
|
6874
|
+
this._notify();
|
|
6875
|
+
};
|
|
6876
|
+
}
|
|
6877
|
+
/**
|
|
6878
|
+
* The words shown for a step named `name`, or `undefined` when none are registered, they
|
|
6879
|
+
* say nothing, or the function that gives them throws — then the name itself is shown. A
|
|
6880
|
+
* function label is asked here, with the locale as it is now.
|
|
6881
|
+
*/
|
|
6882
|
+
getStepLabel(name) {
|
|
6883
|
+
const entry = this._stepLabels.get(name);
|
|
6884
|
+
if (!entry) return void 0;
|
|
6885
|
+
try {
|
|
6886
|
+
const text = typeof entry.label === "function" ? entry.label({ name, locale: this._locale }) : entry.label;
|
|
6887
|
+
return typeof text === "string" && text.trim() ? text.trim() : void 0;
|
|
6888
|
+
} catch {
|
|
6889
|
+
return void 0;
|
|
6890
|
+
}
|
|
6891
|
+
}
|
|
6634
6892
|
/**
|
|
6635
6893
|
* Teach the stream parser a tagged block: `<tag attr="…">…</tag>` in the model's
|
|
6636
6894
|
* prose becomes the segment `toSegment` builds, streamed delta by delta.
|
|
@@ -6835,7 +7093,7 @@ class AparteConfig {
|
|
|
6835
7093
|
}
|
|
6836
7094
|
/**
|
|
6837
7095
|
* Put the configuration back to its defaults: the providers and the selected model,
|
|
6838
|
-
* the tools with their renderers and summaries, the tool-line provider, the renderers and render hooks, the
|
|
7096
|
+
* the tools with their renderers and summaries, the tool-line provider, the step labels, the renderers and render hooks, the
|
|
6839
7097
|
* Markdown and highlight providers, the code-language renderers, the sanitizer, the system prompt, the locale, icons,
|
|
6840
7098
|
* avatars, actions and host handlers, the conversation manager, the question presenters
|
|
6841
7099
|
* and their queue, the run-event observers. Three things stay: the transport, the key sources added with
|
|
@@ -6868,6 +7126,7 @@ class AparteConfig {
|
|
|
6868
7126
|
this._imageDecider = compileImagePolicy([]);
|
|
6869
7127
|
this._imagePolicyNamed = false;
|
|
6870
7128
|
forgetShownImages(this);
|
|
7129
|
+
this._linkTarget = "new-tab";
|
|
6871
7130
|
this._aiProviders.clear();
|
|
6872
7131
|
this._fetchedModels.clear();
|
|
6873
7132
|
this._tools.clear();
|
|
@@ -6878,6 +7137,7 @@ class AparteConfig {
|
|
|
6878
7137
|
notifyRenderersChanged(this);
|
|
6879
7138
|
this._toolDisplays.clear();
|
|
6880
7139
|
this._toolLineProvider = null;
|
|
7140
|
+
this._stepLabels.clear();
|
|
6881
7141
|
this._streamBlocks.clear();
|
|
6882
7142
|
this._runEventObservers = [];
|
|
6883
7143
|
this._modelConfig = {};
|
|
@@ -7616,6 +7876,21 @@ function tellConversationStatus(id, status) {
|
|
|
7616
7876
|
function conversationStatusOf(id) {
|
|
7617
7877
|
return known.get(id) ?? null;
|
|
7618
7878
|
}
|
|
7879
|
+
const OPEN_CONVERSATION = Symbol.for("aparte.openConversation");
|
|
7880
|
+
function offerOpenConversation(host2, read) {
|
|
7881
|
+
const slot = host2;
|
|
7882
|
+
slot[OPEN_CONVERSATION] = read;
|
|
7883
|
+
return () => {
|
|
7884
|
+
if (slot[OPEN_CONVERSATION] === read) delete slot[OPEN_CONVERSATION];
|
|
7885
|
+
};
|
|
7886
|
+
}
|
|
7887
|
+
function openConversationOf(el2) {
|
|
7888
|
+
for (let node = el2; node; node = node.parentElement) {
|
|
7889
|
+
const read = node[OPEN_CONVERSATION];
|
|
7890
|
+
if (read) return read();
|
|
7891
|
+
}
|
|
7892
|
+
return null;
|
|
7893
|
+
}
|
|
7619
7894
|
const MAX_COMPACTION_SAVE_WAITS = 6;
|
|
7620
7895
|
class AparteConversationController {
|
|
7621
7896
|
_binding;
|
|
@@ -7676,6 +7951,18 @@ class AparteConversationController {
|
|
|
7676
7951
|
get activeId() {
|
|
7677
7952
|
return this._activeId;
|
|
7678
7953
|
}
|
|
7954
|
+
/**
|
|
7955
|
+
* The conversation a message sent now belongs to: the open one, or — for the first
|
|
7956
|
+
* message of a chat — the one that send is creating. `createNew()` makes it the
|
|
7957
|
+
* manager's active conversation synchronously, so the client, which hears the send
|
|
7958
|
+
* right after this controller does, already finds it there; this controller's own id
|
|
7959
|
+
* follows once the conversation is saved. `_ensureConversationAndPersist` reads the
|
|
7960
|
+
* same two places to decide where the message is saved, so a turn is carried to the
|
|
7961
|
+
* conversation its message was written in.
|
|
7962
|
+
*/
|
|
7963
|
+
_openId() {
|
|
7964
|
+
return this._activeId ?? this._manager()?.activeId ?? null;
|
|
7965
|
+
}
|
|
7679
7966
|
/**
|
|
7680
7967
|
* Lazily resolve the conversation manager. Returns `undefined` if none is
|
|
7681
7968
|
* registered — the controller then runs in degraded mode: optimistic UI
|
|
@@ -7829,12 +8116,17 @@ class AparteConversationController {
|
|
|
7829
8116
|
}
|
|
7830
8117
|
this._bound = true;
|
|
7831
8118
|
this._manager();
|
|
8119
|
+
this._withdrawOpenConversation = offerOpenConversation(host2, () => this._openId());
|
|
7832
8120
|
return () => this.unbind();
|
|
7833
8121
|
}
|
|
8122
|
+
/** Takes the open-conversation reader off the host (see `bind`). */
|
|
8123
|
+
_withdrawOpenConversation = null;
|
|
7834
8124
|
/** Detach event listeners. */
|
|
7835
8125
|
/** Release handle for the hydration-retry subscription (see setConversationId). */
|
|
7836
8126
|
_stopHydrationRetry = null;
|
|
7837
8127
|
unbind() {
|
|
8128
|
+
this._withdrawOpenConversation?.();
|
|
8129
|
+
this._withdrawOpenConversation = null;
|
|
7838
8130
|
this._bound = false;
|
|
7839
8131
|
this._subscribedTo = null;
|
|
7840
8132
|
this._persistActive();
|
|
@@ -9374,7 +9666,7 @@ function labelGroup(list, opts) {
|
|
|
9374
9666
|
if (opts.titleId) list.setAttribute("aria-labelledby", opts.titleId);
|
|
9375
9667
|
else if (opts.fallbackLabel) list.setAttribute("aria-label", opts.fallbackLabel);
|
|
9376
9668
|
}
|
|
9377
|
-
function buildEnumField(field, onChange, fallbackLabel,
|
|
9669
|
+
function buildEnumField(field, onChange, fallbackLabel, settle2) {
|
|
9378
9670
|
const wrap = el$1("div", "aparte-elic-field aparte-elic-enum");
|
|
9379
9671
|
const titleId = fieldHeader(wrap, field, fallbackLabel);
|
|
9380
9672
|
const list = el$1("div", "aparte-elic-options");
|
|
@@ -9383,12 +9675,12 @@ function buildEnumField(field, onChange, fallbackLabel, settle) {
|
|
|
9383
9675
|
const controlRecipe = type === "checkbox" ? "aparte-checkbox" : "aparte-radio";
|
|
9384
9676
|
const allowOther = field.allowOther ?? contextConfig().getElicitationOptions().allowOther;
|
|
9385
9677
|
const defaults = new Set(Array.isArray(field.default) ? field.default : field.default != null ? [field.default] : []);
|
|
9386
|
-
const settling =
|
|
9678
|
+
const settling = settle2 != null && !field.multiple && defaults.size === 0;
|
|
9387
9679
|
labelGroup(list, { multiple: field.multiple, commands: settling, titleId, fallbackLabel });
|
|
9388
9680
|
const buildOption = (value, label, description, recommended) => {
|
|
9389
9681
|
if (settling) {
|
|
9390
9682
|
const button = commandOption(label, description, recommended);
|
|
9391
|
-
button.addEventListener("click", () =>
|
|
9683
|
+
button.addEventListener("click", () => settle2?.(value));
|
|
9392
9684
|
return button;
|
|
9393
9685
|
}
|
|
9394
9686
|
const row = el$1("label", "aparte-field-choice aparte-elic-option" + (recommended ? " aparte-elic-option--recommended" : ""));
|
|
@@ -9503,18 +9795,18 @@ function buildEnumField(field, onChange, fallbackLabel, settle) {
|
|
|
9503
9795
|
focus: () => controls()[0]?.focus()
|
|
9504
9796
|
};
|
|
9505
9797
|
}
|
|
9506
|
-
function buildBooleanField(field, onChange, fallbackLabel,
|
|
9798
|
+
function buildBooleanField(field, onChange, fallbackLabel, settle2) {
|
|
9507
9799
|
const wrap = el$1("div", "aparte-elic-field aparte-elic-boolean");
|
|
9508
9800
|
const titleId = fieldHeader(wrap, field, fallbackLabel);
|
|
9509
9801
|
const list = el$1("div", "aparte-elic-options");
|
|
9510
9802
|
const name = `elic-${uuid()}`;
|
|
9511
|
-
const settling =
|
|
9803
|
+
const settling = settle2 != null && field.default == null;
|
|
9512
9804
|
labelGroup(list, { commands: settling, titleId, fallbackLabel });
|
|
9513
9805
|
if (settling) {
|
|
9514
9806
|
const t2 = contextConfig();
|
|
9515
9807
|
const mkCommand = (val, label, defaulted) => {
|
|
9516
9808
|
const button = commandOption(label);
|
|
9517
|
-
button.addEventListener("click", () =>
|
|
9809
|
+
button.addEventListener("click", () => settle2?.(val));
|
|
9518
9810
|
if (defaulted) {
|
|
9519
9811
|
const title = button.querySelector(".aparte-elic-option-title");
|
|
9520
9812
|
onRelabel(() => {
|
|
@@ -9597,7 +9889,7 @@ function buildStringField(field, onChange, fallbackLabel) {
|
|
|
9597
9889
|
focus: () => input.focus()
|
|
9598
9890
|
};
|
|
9599
9891
|
}
|
|
9600
|
-
function buildField(field, onChange, fallbackLabel, key,
|
|
9892
|
+
function buildField(field, onChange, fallbackLabel, key, settle2) {
|
|
9601
9893
|
const custom = contextConfig().getElicitationFieldRenderer()?.(field, { key, notifyChange: onChange });
|
|
9602
9894
|
if (custom) {
|
|
9603
9895
|
return {
|
|
@@ -9609,9 +9901,9 @@ function buildField(field, onChange, fallbackLabel, key, settle) {
|
|
|
9609
9901
|
}
|
|
9610
9902
|
switch (field.type) {
|
|
9611
9903
|
case "enum":
|
|
9612
|
-
return buildEnumField(field, onChange, fallbackLabel,
|
|
9904
|
+
return buildEnumField(field, onChange, fallbackLabel, settle2);
|
|
9613
9905
|
case "boolean":
|
|
9614
|
-
return buildBooleanField(field, onChange, fallbackLabel,
|
|
9906
|
+
return buildBooleanField(field, onChange, fallbackLabel, settle2);
|
|
9615
9907
|
// No `settle`: text is written, not chosen, so it always needs a commit.
|
|
9616
9908
|
case "string":
|
|
9617
9909
|
return buildStringField(field, onChange, fallbackLabel);
|
|
@@ -9636,7 +9928,7 @@ function buildPanel(message, schema, onChange) {
|
|
|
9636
9928
|
if (asked2) panel.appendChild(Object.assign(el$1("p", "aparte-elic-message", asked2), { dir: "auto" }));
|
|
9637
9929
|
let settleCb = null;
|
|
9638
9930
|
let settled2 = false;
|
|
9639
|
-
const
|
|
9931
|
+
const settle2 = (content) => {
|
|
9640
9932
|
if (settled2) return;
|
|
9641
9933
|
settled2 = true;
|
|
9642
9934
|
settleCb?.(content);
|
|
@@ -9734,7 +10026,7 @@ function buildPanel(message, schema, onChange) {
|
|
|
9734
10026
|
};
|
|
9735
10027
|
}
|
|
9736
10028
|
const answerOnClick = contextConfig().getElicitationOptions().answerOnClick;
|
|
9737
|
-
const field = buildField(schema, onChange, asked2, void 0, answerOnClick ?
|
|
10029
|
+
const field = buildField(schema, onChange, asked2, void 0, answerOnClick ? settle2 : void 0);
|
|
9738
10030
|
body.appendChild(field.el);
|
|
9739
10031
|
return {
|
|
9740
10032
|
el: panel,
|
|
@@ -9778,12 +10070,12 @@ function buildApprovalPanel(message, options, onChange, details, allowOther = tr
|
|
|
9778
10070
|
}
|
|
9779
10071
|
const dismiss = el("div", "aparte-elic-dismiss");
|
|
9780
10072
|
panel.appendChild(dismiss);
|
|
9781
|
-
let
|
|
10073
|
+
let settle2 = null;
|
|
9782
10074
|
let done = false;
|
|
9783
10075
|
const fire = (answer) => {
|
|
9784
10076
|
if (done) return;
|
|
9785
10077
|
done = true;
|
|
9786
|
-
|
|
10078
|
+
settle2?.(answer);
|
|
9787
10079
|
};
|
|
9788
10080
|
const row = el("div", "aparte-approval-options");
|
|
9789
10081
|
row.setAttribute("role", "group");
|
|
@@ -9819,7 +10111,7 @@ function buildApprovalPanel(message, options, onChange, details, allowOther = tr
|
|
|
9819
10111
|
el: panel,
|
|
9820
10112
|
dismiss,
|
|
9821
10113
|
onSettle: (cb) => {
|
|
9822
|
-
|
|
10114
|
+
settle2 = cb;
|
|
9823
10115
|
},
|
|
9824
10116
|
getContent: () => ({ instruction: typed() }),
|
|
9825
10117
|
isComplete: () => typed().length > 0,
|
|
@@ -10267,7 +10559,7 @@ class AparteClient {
|
|
|
10267
10559
|
};
|
|
10268
10560
|
const isStopped = () => this._isAborted || streamController.signal.aborted;
|
|
10269
10561
|
const runOnce = async () => {
|
|
10270
|
-
let result = opts?.resume ? { usage: void 0, suspended: opts.resume } : await this._streamLoop(targetElement, messageId, provider, baseRequest, authConfig, streamController, void 0, opts?.files);
|
|
10562
|
+
let result = opts?.resume ? { usage: void 0, suspended: opts.resume } : await this._streamLoop(targetElement, messageId, provider, baseRequest, authConfig, streamController, void 0, opts?.files, opts?.conversationId);
|
|
10271
10563
|
const maxResumes = this.options.maxTurns ?? 10;
|
|
10272
10564
|
let resumes = 0;
|
|
10273
10565
|
let approvedAtLastPause = /* @__PURE__ */ new Set();
|
|
@@ -10305,7 +10597,9 @@ class AparteClient {
|
|
|
10305
10597
|
{ ...baseRequest, messages: messages2 },
|
|
10306
10598
|
authConfig,
|
|
10307
10599
|
streamController,
|
|
10308
|
-
deferral
|
|
10600
|
+
deferral,
|
|
10601
|
+
void 0,
|
|
10602
|
+
opts?.conversationId
|
|
10309
10603
|
);
|
|
10310
10604
|
}
|
|
10311
10605
|
const usage = result.usage;
|
|
@@ -10420,6 +10714,7 @@ class AparteClient {
|
|
|
10420
10714
|
console.warn("[AparteClient] aparte-retry — no target found");
|
|
10421
10715
|
return;
|
|
10422
10716
|
}
|
|
10717
|
+
const conversationId = openConversationOf(targetElement) ?? void 0;
|
|
10423
10718
|
const allMessages = targetElement.getMessages?.() ?? [];
|
|
10424
10719
|
const retryIdx = allMessages.findIndex((m) => m.id === messageId);
|
|
10425
10720
|
const retryMsg = retryIdx >= 0 ? allMessages[retryIdx] : void 0;
|
|
@@ -10450,6 +10745,7 @@ class AparteClient {
|
|
|
10450
10745
|
{
|
|
10451
10746
|
...provider.retryTemperature !== void 0 ? { temperature: provider.retryTemperature } : {},
|
|
10452
10747
|
...this._turnMeta([...historyMessages].reverse().find((m) => m.role === "user")),
|
|
10748
|
+
...conversationId ? { conversationId } : {},
|
|
10453
10749
|
rebuild: async () => [
|
|
10454
10750
|
...this._systemMessages(),
|
|
10455
10751
|
...mergeAdjacentUserMessages(this._messagesToChatMessages(this._current(targetElement, historyMessages)))
|
|
@@ -10486,6 +10782,7 @@ class AparteClient {
|
|
|
10486
10782
|
console.warn("[AparteClient] aparte-edit — no target found");
|
|
10487
10783
|
return;
|
|
10488
10784
|
}
|
|
10785
|
+
const conversationId = openConversationOf(targetElement) ?? void 0;
|
|
10489
10786
|
const before = targetElement.getMessages?.().find((m) => m.id === messageId);
|
|
10490
10787
|
targetElement.updateMessage?.(messageId, {
|
|
10491
10788
|
content: newContent,
|
|
@@ -10526,6 +10823,7 @@ class AparteClient {
|
|
|
10526
10823
|
authConfig,
|
|
10527
10824
|
{
|
|
10528
10825
|
...this._turnMeta(editIdx >= 0 ? allMessages[editIdx] : void 0),
|
|
10826
|
+
...conversationId ? { conversationId } : {},
|
|
10529
10827
|
rebuild: async () => [
|
|
10530
10828
|
...this._systemMessages(),
|
|
10531
10829
|
...mergeAdjacentUserMessages(this._messagesToChatMessages(this._current(targetElement, historyMessages)))
|
|
@@ -10735,6 +11033,7 @@ class AparteClient {
|
|
|
10735
11033
|
console.warn("[AparteClient] ⚠️ No target element found with appendMessage support. Provide a targetResolver in AparteClientOptions or ensure the composer has a `target` attribute.");
|
|
10736
11034
|
return;
|
|
10737
11035
|
}
|
|
11036
|
+
const conversationId = openConversationOf(targetElement) ?? void 0;
|
|
10738
11037
|
this._closeDeferred(targetElement);
|
|
10739
11038
|
if (this.options.echoUserMessage !== false && event.detail?.echoed !== true) {
|
|
10740
11039
|
const echoFiles = Array.isArray(event.detail?.files) ? event.detail.files : [];
|
|
@@ -10805,7 +11104,8 @@ class AparteClient {
|
|
|
10805
11104
|
{
|
|
10806
11105
|
rebuild: async () => this._buildMessages(content, targetElement, fileParts),
|
|
10807
11106
|
...rawFiles.length > 0 ? { files: rawFiles } : {},
|
|
10808
|
-
...this._turnMeta(event.detail)
|
|
11107
|
+
...this._turnMeta(event.detail),
|
|
11108
|
+
...conversationId ? { conversationId } : {}
|
|
10809
11109
|
}
|
|
10810
11110
|
);
|
|
10811
11111
|
}
|
|
@@ -10915,11 +11215,11 @@ ${content}
|
|
|
10915
11215
|
* adapter, or the runner a host injected — after the fetch-level abort bookkeeping.
|
|
10916
11216
|
*/
|
|
10917
11217
|
/** One run of the loop: its usage, and whether it paused (a server loop). */
|
|
10918
|
-
async _streamLoop(targetElement, messageId, provider, baseRequest, authConfig, streamController = new AbortController(), deferral, files) {
|
|
11218
|
+
async _streamLoop(targetElement, messageId, provider, baseRequest, authConfig, streamController = new AbortController(), deferral, files, conversationId) {
|
|
10919
11219
|
if (this._streamController !== streamController) this._streamController?.abort();
|
|
10920
11220
|
this._streamController = streamController;
|
|
10921
11221
|
const runner = this.options.streamRunner ?? runStreamAgent;
|
|
10922
|
-
return this._runViaStreamRunner(runner, targetElement, messageId, provider, baseRequest, authConfig, streamController, deferral, files);
|
|
11222
|
+
return this._runViaStreamRunner(runner, targetElement, messageId, provider, baseRequest, authConfig, streamController, deferral, files, conversationId);
|
|
10923
11223
|
}
|
|
10924
11224
|
/**
|
|
10925
11225
|
* Run the loop through a {@link AparteStreamRunner} — the engine's by default —
|
|
@@ -10930,7 +11230,7 @@ ${content}
|
|
|
10930
11230
|
* produces is pinned by the `stream-parity` suite's snapshots, recorded while
|
|
10931
11231
|
* the inline loop it replaced still ran beside it.
|
|
10932
11232
|
*/
|
|
10933
|
-
async _runViaStreamRunner(streamRunner, targetElement, messageId, provider, baseRequest, authConfig, streamController, deferral, files) {
|
|
11233
|
+
async _runViaStreamRunner(streamRunner, targetElement, messageId, provider, baseRequest, authConfig, streamController, deferral, files, conversationId) {
|
|
10934
11234
|
const signal = streamController.signal;
|
|
10935
11235
|
const chatId = this._targetIdOf(targetElement);
|
|
10936
11236
|
const adapter = createStreamAdapter({
|
|
@@ -10964,7 +11264,13 @@ ${content}
|
|
|
10964
11264
|
const toolLookup = (name) => {
|
|
10965
11265
|
const handler = this._config.getToolHandler(name);
|
|
10966
11266
|
if (!handler) return void 0;
|
|
10967
|
-
const context = {
|
|
11267
|
+
const context = {
|
|
11268
|
+
target: targetElement,
|
|
11269
|
+
config: this._config,
|
|
11270
|
+
// The same id a server tool is handed (`createAparteAgentHandler`), so a
|
|
11271
|
+
// handler behaves the same whichever loop runs it.
|
|
11272
|
+
...conversationId ? { conversationId } : {}
|
|
11273
|
+
};
|
|
10968
11274
|
return (call, sig, run) => handler(call, sig, run ? { ...context, run } : context);
|
|
10969
11275
|
};
|
|
10970
11276
|
const hostOwnsDecision = Boolean(this.options.approvalResolver);
|
|
@@ -10973,6 +11279,7 @@ ${content}
|
|
|
10973
11279
|
if (!tool) return void 0;
|
|
10974
11280
|
return {
|
|
10975
11281
|
maxTurns: tool.maxTurns,
|
|
11282
|
+
parallel: tool.parallel,
|
|
10976
11283
|
needsApproval: hostOwnsDecision ? tool.needsApproval : (call) => {
|
|
10977
11284
|
const verdict = this._config.ruleOnToolCall(call).verdict;
|
|
10978
11285
|
return verdict === "allow" ? false : verdict;
|
|
@@ -10990,6 +11297,7 @@ ${content}
|
|
|
10990
11297
|
...provider.id ? { providerId: provider.id } : {},
|
|
10991
11298
|
...deferral ? { deferral } : {},
|
|
10992
11299
|
...files && files.length > 0 ? { files } : {},
|
|
11300
|
+
...conversationId ? { conversationId } : {},
|
|
10993
11301
|
baseRequest,
|
|
10994
11302
|
transportCall,
|
|
10995
11303
|
toolLookup,
|
|
@@ -11003,6 +11311,7 @@ ${content}
|
|
|
11003
11311
|
// inline path, so setting it was silently ignored here. Exactly the
|
|
11004
11312
|
// asymmetry the option was added to remove.
|
|
11005
11313
|
toolTimeoutMs: this.options.toolTimeoutMs,
|
|
11314
|
+
...this.options.parallelTools !== void 0 ? { parallelTools: this.options.parallelTools } : {},
|
|
11006
11315
|
// The id conventions the loop always had: prefixed artifact ids, but a
|
|
11007
11316
|
// BARE uuid for the synthetic tool (the adapter renders `tool-<id>`).
|
|
11008
11317
|
idGen: (prefix) => prefix === "synthetic-tool" ? uuid() : `${prefix}-${uuid()}`
|
|
@@ -11245,6 +11554,7 @@ ${content}
|
|
|
11245
11554
|
return false;
|
|
11246
11555
|
}
|
|
11247
11556
|
this._beginUserTurn();
|
|
11557
|
+
const conversationId = openConversationOf(targetElement) ?? void 0;
|
|
11248
11558
|
this._resuming.add(last.id);
|
|
11249
11559
|
try {
|
|
11250
11560
|
const authConfig = provider.id ? await this._resolveAuth(provider.id) : void 0;
|
|
@@ -11262,7 +11572,8 @@ ${content}
|
|
|
11262
11572
|
const at = now.findIndex((m) => m.id === last.id);
|
|
11263
11573
|
return at >= 0 ? this._resumeBase(now, at) : base;
|
|
11264
11574
|
},
|
|
11265
|
-
...recorded?.temperature !== void 0 ? { temperature: recorded.temperature } : {}
|
|
11575
|
+
...recorded?.temperature !== void 0 ? { temperature: recorded.temperature } : {},
|
|
11576
|
+
...conversationId ? { conversationId } : {}
|
|
11266
11577
|
});
|
|
11267
11578
|
} finally {
|
|
11268
11579
|
this._resuming.delete(last.id);
|
|
@@ -11314,6 +11625,7 @@ const RUN_LEVEL = /* @__PURE__ */ new Set(["run-start", "run-done", "run-aborted
|
|
|
11314
11625
|
function createAgentStreamRunner(options) {
|
|
11315
11626
|
let warnedAttributedEnd = false;
|
|
11316
11627
|
return async (opts) => {
|
|
11628
|
+
const endpoint = typeof options.endpoint === "function" ? options.endpoint(opts) : options.endpoint;
|
|
11317
11629
|
const doFetch = options.fetch ?? fetch;
|
|
11318
11630
|
const headers = typeof options.headers === "function" ? await options.headers() : options.headers ?? {};
|
|
11319
11631
|
const { tools, ...request } = opts.baseRequest;
|
|
@@ -11321,11 +11633,12 @@ function createAgentStreamRunner(options) {
|
|
|
11321
11633
|
v: 1,
|
|
11322
11634
|
...opts.providerId ? { providerId: opts.providerId } : {},
|
|
11323
11635
|
messageId: opts.messageId,
|
|
11636
|
+
...opts.conversationId ? { conversationId: opts.conversationId } : {},
|
|
11324
11637
|
request,
|
|
11325
11638
|
clientTools: tools ?? [],
|
|
11326
11639
|
...opts.deferral?.token ? { resume: { ticket: opts.deferral.token, outcomes: opts.deferral.outcomes ?? {} } } : {}
|
|
11327
11640
|
};
|
|
11328
|
-
const response = await doFetch(
|
|
11641
|
+
const response = await doFetch(endpoint, {
|
|
11329
11642
|
method: "POST",
|
|
11330
11643
|
headers: jsonHeaders(headers),
|
|
11331
11644
|
body: JSON.stringify(body),
|
|
@@ -12042,4 +12355,4 @@ export {
|
|
|
12042
12355
|
collectRendererStyles as y,
|
|
12043
12356
|
contentToText as z
|
|
12044
12357
|
};
|
|
12045
|
-
//# sourceMappingURL=defer-hydration-
|
|
12358
|
+
//# sourceMappingURL=defer-hydration-Ch3TOEJC.js.map
|