@aparte/core 1.4.0 → 1.6.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.map +1 -1
- package/dist/client/aparte-client.d.ts +6 -0
- package/dist/client/aparte-client.d.ts.map +1 -1
- package/dist/client/stream-adapter.d.ts +52 -2
- package/dist/client/stream-adapter.d.ts.map +1 -1
- package/dist/client/wire-history.d.ts +3 -2
- package/dist/client/wire-history.d.ts.map +1 -1
- package/dist/components/bubble/aparte-chat-bubble.d.ts +1 -1
- package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -1
- package/dist/components/conversation-list/aparte-conversation-list.d.ts +11 -0
- package/dist/components/conversation-list/aparte-conversation-list.d.ts.map +1 -1
- package/dist/components/launcher/aparte-launcher.d.ts +2 -0
- package/dist/components/launcher/aparte-launcher.d.ts.map +1 -1
- package/dist/components/sidebar/aparte-sidebar.d.ts +42 -5
- package/dist/components/sidebar/aparte-sidebar.d.ts.map +1 -1
- package/dist/components/viewport/aparte-chat-viewport.d.ts +5 -0
- package/dist/components/viewport/aparte-chat-viewport.d.ts.map +1 -1
- package/dist/config/aparte-config.d.ts +69 -4
- package/dist/config/aparte-config.d.ts.map +1 -1
- package/dist/config/locale.d.ts +9 -0
- package/dist/config/locale.d.ts.map +1 -1
- package/dist/custom-elements.json +2244 -1659
- package/dist/{defer-hydration-lK-7XQXf.js → defer-hydration-W4yhnyfc.js} +406 -143
- package/dist/defer-hydration-W4yhnyfc.js.map +1 -0
- package/dist/generated/element-attributes.d.ts +4 -2
- package/dist/generated/element-attributes.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +167 -90
- package/dist/index.js.map +1 -1
- package/dist/index.node.d.ts +6 -2
- package/dist/index.node.d.ts.map +1 -1
- package/dist/index.node.js +52 -47
- package/dist/index.node.js.map +1 -1
- package/dist/renderers/segments/tool-call.d.ts.map +1 -1
- package/dist/transport/agent-handler.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/tools.d.ts +40 -0
- package/dist/types/tools.d.ts.map +1 -1
- package/dist/utils/segment-list.d.ts +49 -0
- package/dist/utils/segment-list.d.ts.map +1 -0
- package/dist/utils/tool-line.d.ts +36 -9
- package/dist/utils/tool-line.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/defer-hydration-lK-7XQXf.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toolRefusal as toolRefusal$1, unansweredTail, runStreamAgent } from "@aparte/engine";
|
|
1
|
+
import { runSubAgent as runSubAgent$1, startSubAgent as startSubAgent$1, toolRefusal as toolRefusal$1, unansweredTail, runStreamAgent } from "@aparte/engine";
|
|
2
2
|
import { A as APARTE_ICON_GLYPHS } from "./glyphs-LolG04CC.js";
|
|
3
3
|
function contentToText(content) {
|
|
4
4
|
if (typeof content === "string") return content;
|
|
@@ -106,6 +106,7 @@ const APARTE_DEFAULT_LOCALE = {
|
|
|
106
106
|
elicitationAnswerLabel: "Your answer",
|
|
107
107
|
approvalInstructionPlaceholder: "Or tell it what to do instead…",
|
|
108
108
|
approvalAsk: "Allow {tool}?",
|
|
109
|
+
approvalAskBy: "Allow {tool} for {agent}?",
|
|
109
110
|
approvalWaiting: "Waiting",
|
|
110
111
|
scrollToBottom: "Scroll to bottom",
|
|
111
112
|
suggestionsLabel: "Suggested prompts",
|
|
@@ -3164,7 +3165,23 @@ function describeToolInput(input, format) {
|
|
|
3164
3165
|
return "";
|
|
3165
3166
|
}
|
|
3166
3167
|
}
|
|
3167
|
-
|
|
3168
|
+
const reported = /* @__PURE__ */ new WeakSet();
|
|
3169
|
+
function toolLineOf(segment, config) {
|
|
3170
|
+
const provider = config.getToolLineProvider();
|
|
3171
|
+
if (!provider) return void 0;
|
|
3172
|
+
try {
|
|
3173
|
+
const line = provider(segment);
|
|
3174
|
+
return line && typeof line === "object" ? line : void 0;
|
|
3175
|
+
} catch (err) {
|
|
3176
|
+
if (!reported.has(provider)) {
|
|
3177
|
+
reported.add(provider);
|
|
3178
|
+
console.error("[aparte] The tool-line provider threw; the row keeps its default line. Further throws from it are not reported.", err);
|
|
3179
|
+
}
|
|
3180
|
+
return void 0;
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
const textOf = (value) => typeof value === "string" ? value.trim() : "";
|
|
3184
|
+
function toolNameOf(segment, config, line = toolLineOf(segment, config)) {
|
|
3168
3185
|
const identifier = segment.toolCall?.name ?? "tool";
|
|
3169
3186
|
const label = config.getToolDisplay(identifier)?.label;
|
|
3170
3187
|
if (label !== void 0) {
|
|
@@ -3174,17 +3191,30 @@ function toolNameOf(segment, config) {
|
|
|
3174
3191
|
} catch {
|
|
3175
3192
|
}
|
|
3176
3193
|
}
|
|
3194
|
+
const provided = textOf(line?.label);
|
|
3195
|
+
if (provided) return { text: provided, isLabel: true };
|
|
3177
3196
|
return { text: identifier, isLabel: false };
|
|
3178
3197
|
}
|
|
3179
|
-
function toolTargetOf(segment, config) {
|
|
3198
|
+
function toolTargetOf(segment, config, line = toolLineOf(segment, config)) {
|
|
3199
|
+
return toolTargetPartsOf(segment, config, line).text;
|
|
3200
|
+
}
|
|
3201
|
+
function toolTargetPartsOf(segment, config, line = toolLineOf(segment, config)) {
|
|
3180
3202
|
const summary = config.getToolSummary(segment.toolCall?.name ?? "");
|
|
3181
|
-
if (
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3203
|
+
if (summary) {
|
|
3204
|
+
try {
|
|
3205
|
+
const text2 = textOf(summary(segment));
|
|
3206
|
+
if (text2) return { text: text2, isWords: false };
|
|
3207
|
+
} catch {
|
|
3208
|
+
}
|
|
3187
3209
|
}
|
|
3210
|
+
const text = textOf(line?.target);
|
|
3211
|
+
return { text, isWords: text !== "" };
|
|
3212
|
+
}
|
|
3213
|
+
function toolActivityOf(_segment, line) {
|
|
3214
|
+
return textOf(line?.activity);
|
|
3215
|
+
}
|
|
3216
|
+
function toolLineNoteOf(line) {
|
|
3217
|
+
return textOf(line?.note);
|
|
3188
3218
|
}
|
|
3189
3219
|
function describeInput(segment) {
|
|
3190
3220
|
return describeToolInput(segment.toolCall?.input, contextConfig().getToolInputFormatter(segment.toolCall?.name ?? ""));
|
|
@@ -3201,7 +3231,7 @@ function stateBadge(segment) {
|
|
|
3201
3231
|
if (status === "failed") return `${cfg.getIcon("close")}${word(cfg.t("toolFailed"))}`;
|
|
3202
3232
|
return "";
|
|
3203
3233
|
}
|
|
3204
|
-
function
|
|
3234
|
+
function reasonOf(segment) {
|
|
3205
3235
|
const cfg = contextConfig();
|
|
3206
3236
|
if (segment.status === "rejected") {
|
|
3207
3237
|
const by = segment.refusal?.by;
|
|
@@ -3226,14 +3256,18 @@ function noteOf(segment) {
|
|
|
3226
3256
|
}
|
|
3227
3257
|
return "";
|
|
3228
3258
|
}
|
|
3259
|
+
function noteOf(segment, line) {
|
|
3260
|
+
return [reasonOf(segment), toolLineNoteOf(line)].filter(Boolean).join(" · ");
|
|
3261
|
+
}
|
|
3229
3262
|
function outcomeOf(segment) {
|
|
3230
3263
|
const text = displayText(segment.result ?? "");
|
|
3231
3264
|
if (!text) return null;
|
|
3232
3265
|
if (segment.status === "rejected" && segment.refusal) return null;
|
|
3233
3266
|
return { key: "toolOutput", text };
|
|
3234
3267
|
}
|
|
3235
|
-
function behindOf(segment) {
|
|
3236
|
-
const
|
|
3268
|
+
function behindOf(segment, line) {
|
|
3269
|
+
const display = contextConfig().getToolDisplay(segment.toolCall?.name ?? "");
|
|
3270
|
+
const details = display && "details" in display ? display.details : line?.details;
|
|
3237
3271
|
if (details === false) return { kind: "none" };
|
|
3238
3272
|
if (typeof details !== "function") return { kind: "parts" };
|
|
3239
3273
|
try {
|
|
@@ -3248,6 +3282,7 @@ const appDetailOf = (element) => element.querySelector(':scope > .aparte-tool-de
|
|
|
3248
3282
|
function setBody(element, body) {
|
|
3249
3283
|
const detail = element.querySelector(".aparte-tool-detail");
|
|
3250
3284
|
if (!detail) return;
|
|
3285
|
+
if (typeof body !== "string" && body.parentNode === detail) return;
|
|
3251
3286
|
if (typeof body === "string") detail.innerHTML = body;
|
|
3252
3287
|
else detail.replaceChildren(body);
|
|
3253
3288
|
drawnBodies.set(detail, serialized(body));
|
|
@@ -3298,10 +3333,10 @@ function patchChanges(live2, prev, next) {
|
|
|
3298
3333
|
}
|
|
3299
3334
|
}
|
|
3300
3335
|
}
|
|
3301
|
-
function setNote(element, segment) {
|
|
3336
|
+
function setNote(element, segment, line) {
|
|
3302
3337
|
const el2 = element.querySelector(".aparte-tool-note");
|
|
3303
3338
|
if (!el2) return;
|
|
3304
|
-
const text = noteOf(segment);
|
|
3339
|
+
const text = noteOf(segment, line);
|
|
3305
3340
|
if (el2.textContent !== text) el2.textContent = text;
|
|
3306
3341
|
el2.toggleAttribute("hidden", !text);
|
|
3307
3342
|
if (text) el2.setAttribute("title", text);
|
|
@@ -3386,18 +3421,26 @@ function highlightParts(element) {
|
|
|
3386
3421
|
});
|
|
3387
3422
|
}
|
|
3388
3423
|
}
|
|
3389
|
-
function toolTarget(segment) {
|
|
3390
|
-
return
|
|
3424
|
+
function toolTarget(segment, line) {
|
|
3425
|
+
return toolTargetPartsOf(segment, contextConfig(), line);
|
|
3391
3426
|
}
|
|
3392
|
-
function setTarget(element, segment) {
|
|
3427
|
+
function setTarget(element, segment, line) {
|
|
3393
3428
|
const el2 = element.querySelector(".aparte-tool-target");
|
|
3394
3429
|
if (!el2) return;
|
|
3395
|
-
const text = toolTarget(segment);
|
|
3430
|
+
const { text, isWords } = toolTarget(segment, line);
|
|
3396
3431
|
if (el2.textContent !== text) el2.textContent = text;
|
|
3397
3432
|
el2.toggleAttribute("hidden", !text);
|
|
3433
|
+
el2.classList.toggle("aparte-tool-target--words", isWords);
|
|
3398
3434
|
}
|
|
3399
|
-
function
|
|
3400
|
-
|
|
3435
|
+
function setActivity(element, segment, line) {
|
|
3436
|
+
const el2 = element.querySelector(".aparte-tool-activity");
|
|
3437
|
+
if (!el2) return;
|
|
3438
|
+
const text = toolActivityOf(segment, line);
|
|
3439
|
+
if (el2.textContent !== text) el2.textContent = text;
|
|
3440
|
+
el2.toggleAttribute("hidden", !text);
|
|
3441
|
+
}
|
|
3442
|
+
function nameOf(segment, line) {
|
|
3443
|
+
return toolNameOf(segment, contextConfig(), line);
|
|
3401
3444
|
}
|
|
3402
3445
|
function iconOf(segment) {
|
|
3403
3446
|
const cfg = contextConfig();
|
|
@@ -3421,29 +3464,31 @@ function setQuiet(element, segment) {
|
|
|
3421
3464
|
element.querySelector(".aparte-tool-name")?.classList.toggle("aparte-shimmer", quiet.shimmer);
|
|
3422
3465
|
element.querySelector(".aparte-tool-state")?.classList.toggle("aparte-sr-only", quiet.stateHidden);
|
|
3423
3466
|
}
|
|
3424
|
-
function setName(element, segment) {
|
|
3467
|
+
function setName(element, segment, line) {
|
|
3425
3468
|
const el2 = element.querySelector(".aparte-tool-name");
|
|
3426
3469
|
if (!el2) return;
|
|
3427
|
-
const { text, isLabel } = nameOf(segment);
|
|
3470
|
+
const { text, isLabel } = nameOf(segment, line);
|
|
3428
3471
|
if (el2.textContent !== text) el2.textContent = text;
|
|
3429
3472
|
el2.classList.toggle("aparte-tool-name--label", isLabel);
|
|
3430
3473
|
}
|
|
3431
|
-
function pillMarkup(segment) {
|
|
3474
|
+
function pillMarkup(segment, line) {
|
|
3432
3475
|
const badge = stateBadge(segment);
|
|
3433
3476
|
const icon = iconOf(segment);
|
|
3434
|
-
const target = toolTarget(segment);
|
|
3435
|
-
const
|
|
3436
|
-
const
|
|
3477
|
+
const target = toolTarget(segment, line);
|
|
3478
|
+
const activity = toolActivityOf(segment, line);
|
|
3479
|
+
const note = noteOf(segment, line);
|
|
3480
|
+
const name = nameOf(segment, line);
|
|
3437
3481
|
const quiet = quietOf(segment);
|
|
3438
3482
|
return `
|
|
3439
3483
|
<span class="aparte-tool-label">
|
|
3440
3484
|
<span class="aparte-tool-icon">${icon}</span>
|
|
3441
3485
|
<span class="aparte-tool-name${name.isLabel ? " aparte-tool-name--label" : ""}${quiet.shimmer ? " aparte-shimmer" : ""}">${escapeHtml(name.text)}</span>
|
|
3442
|
-
<span class="aparte-tool-target"${target ? "" : " hidden"}>${escapeHtml(target)}</span>
|
|
3486
|
+
<span class="aparte-tool-target${target.isWords ? " aparte-tool-target--words" : ""}"${target.text ? "" : " hidden"}>${escapeHtml(target.text)}</span>
|
|
3443
3487
|
</span>
|
|
3444
3488
|
<span class="aparte-spinner aparte-tool-spinner" aria-hidden="true"${quiet.spinner ? "" : " hidden"}></span>
|
|
3445
3489
|
<span class="aparte-tool-state${quiet.stateHidden ? " aparte-sr-only" : ""}">${badge}</span>
|
|
3446
|
-
<span class="aparte-tool-note"${note ? ` title="${escapeAttr(note)}"` : " hidden"}>${escapeHtml(note)}</span
|
|
3490
|
+
<span class="aparte-tool-note"${note ? ` title="${escapeAttr(note)}"` : " hidden"}>${escapeHtml(note)}</span>
|
|
3491
|
+
<span class="aparte-tool-activity"${activity ? "" : " hidden"}>${escapeHtml(activity)}</span>`;
|
|
3447
3492
|
}
|
|
3448
3493
|
function placeholderMarkup(segment) {
|
|
3449
3494
|
return `<div class="aparte-segment aparte-segment-tool-call" data-segment-id="${escapeHtml(segment.id)}" data-status="${escapeAttr(segment.status ?? "pending")}" data-tool-call-id="${escapeAttr(segment.toolCall?.id ?? "")}" data-tool-name="${escapeAttr(segment.toolCall?.name ?? "tool")}" hidden></div>`;
|
|
@@ -3459,11 +3504,11 @@ function drawerOf(element, current) {
|
|
|
3459
3504
|
if (recorded) return recorded;
|
|
3460
3505
|
return element.classList.contains("aparte-segment-tool-call") ? null : current;
|
|
3461
3506
|
}
|
|
3462
|
-
function drawDefault(segment, behind2) {
|
|
3507
|
+
function drawDefault(segment, behind2, line) {
|
|
3463
3508
|
const name = segment.toolCall?.name ?? "tool";
|
|
3464
3509
|
const status = segment.status ?? "pending";
|
|
3465
3510
|
const toolCallId = segment.toolCall?.id ?? "";
|
|
3466
|
-
const pill = pillMarkup(segment);
|
|
3511
|
+
const pill = pillMarkup(segment, line);
|
|
3467
3512
|
const quiet = isQuiet(segment) ? " data-quiet" : "";
|
|
3468
3513
|
const toggle = contextConfig().getIcon("expand");
|
|
3469
3514
|
const input = behind2.kind === "parts" ? describeInput(segment) : "";
|
|
@@ -3521,7 +3566,8 @@ const toolCallRenderer = {
|
|
|
3521
3566
|
}
|
|
3522
3567
|
return out || placeholderMarkup(segment);
|
|
3523
3568
|
}
|
|
3524
|
-
|
|
3569
|
+
const line = toolLineOf(segment, contextConfig());
|
|
3570
|
+
return drawDefault(segment, behindOf(segment, line), line);
|
|
3525
3571
|
},
|
|
3526
3572
|
/**
|
|
3527
3573
|
* The pill's glyphs, and the label it wears while a person is deciding.
|
|
@@ -3541,11 +3587,13 @@ const toolCallRenderer = {
|
|
|
3541
3587
|
custom.relabel?.(element, segment);
|
|
3542
3588
|
return;
|
|
3543
3589
|
}
|
|
3590
|
+
const line = toolLineOf(segment, cfg);
|
|
3544
3591
|
const icon = element.querySelector(".aparte-tool-icon");
|
|
3545
3592
|
if (icon) icon.innerHTML = iconOf(segment);
|
|
3546
|
-
setName(element, segment);
|
|
3547
|
-
setTarget(element, segment);
|
|
3548
|
-
|
|
3593
|
+
setName(element, segment, line);
|
|
3594
|
+
setTarget(element, segment, line);
|
|
3595
|
+
setActivity(element, segment, line);
|
|
3596
|
+
setNote(element, segment, line);
|
|
3549
3597
|
const inputLabel = element.querySelector('[data-part="input"] .aparte-tool-part-label');
|
|
3550
3598
|
if (inputLabel) inputLabel.textContent = cfg.t("toolInput");
|
|
3551
3599
|
element.querySelector('[data-part="input"] .aparte-tool-part-body')?.setAttribute("aria-label", cfg.t("toolInput"));
|
|
@@ -3556,7 +3604,7 @@ const toolCallRenderer = {
|
|
|
3556
3604
|
for (const button of element.querySelectorAll(".aparte-tool-copy")) relabelCopyButton(button);
|
|
3557
3605
|
const appDetail = appDetailOf(element);
|
|
3558
3606
|
if (appDetail) {
|
|
3559
|
-
const behind2 = behindOf(segment);
|
|
3607
|
+
const behind2 = behindOf(segment, line);
|
|
3560
3608
|
if (behind2.kind === "body") relabelBody(appDetail, behind2.body);
|
|
3561
3609
|
}
|
|
3562
3610
|
const statusEl = element.querySelector(".aparte-tool-state");
|
|
@@ -3604,22 +3652,24 @@ const toolCallRenderer = {
|
|
|
3604
3652
|
rebuild(toolCallRenderer.render(segment));
|
|
3605
3653
|
return;
|
|
3606
3654
|
}
|
|
3607
|
-
const
|
|
3655
|
+
const line = toolLineOf(segment, contextConfig());
|
|
3656
|
+
const behind2 = behindOf(segment, line);
|
|
3608
3657
|
const input = behind2.kind === "parts" ? describeInput(segment) : "";
|
|
3609
3658
|
const outcome = behind2.kind === "parts" ? outcomeOf(segment) : null;
|
|
3610
3659
|
const wantsDetail = behind2.kind === "body" || !!input || !!outcome;
|
|
3611
3660
|
const holdsAppDetail = !!appDetailOf(element);
|
|
3612
3661
|
if (wantsDetail !== (element.tagName === "DETAILS") || wantsDetail && behind2.kind === "body" !== holdsAppDetail) {
|
|
3613
|
-
rebuild(drawDefault(segment, behind2));
|
|
3662
|
+
rebuild(drawDefault(segment, behind2, line));
|
|
3614
3663
|
return;
|
|
3615
3664
|
}
|
|
3616
3665
|
element.setAttribute("data-status", status);
|
|
3617
3666
|
const badge = element.querySelector(".aparte-tool-state");
|
|
3618
3667
|
if (badge) badge.innerHTML = stateBadge(segment);
|
|
3619
3668
|
setQuiet(element, segment);
|
|
3620
|
-
setName(element, segment);
|
|
3621
|
-
setTarget(element, segment);
|
|
3622
|
-
|
|
3669
|
+
setName(element, segment, line);
|
|
3670
|
+
setTarget(element, segment, line);
|
|
3671
|
+
setActivity(element, segment, line);
|
|
3672
|
+
setNote(element, segment, line);
|
|
3623
3673
|
if (behind2.kind === "body") {
|
|
3624
3674
|
setBody(element, behind2.body);
|
|
3625
3675
|
return;
|
|
@@ -3800,8 +3850,10 @@ const DEFAULT_RENDERERS = [
|
|
|
3800
3850
|
toolCallRenderer
|
|
3801
3851
|
];
|
|
3802
3852
|
const toolRefusal = toolRefusal$1;
|
|
3853
|
+
const runSubAgent = runSubAgent$1;
|
|
3854
|
+
const startSubAgent = startSubAgent$1;
|
|
3803
3855
|
function createStreamAdapter(opts) {
|
|
3804
|
-
const { target, config, messageId, targetId } = opts;
|
|
3856
|
+
const { target, config, messageId, targetId, observe: notify = true } = opts;
|
|
3805
3857
|
let parser = new AparteStreamParser({ blocks: config.getStreamBlocks() });
|
|
3806
3858
|
let streaming = /* @__PURE__ */ new Set();
|
|
3807
3859
|
let thinkingId = null;
|
|
@@ -3855,12 +3907,12 @@ function createStreamAdapter(opts) {
|
|
|
3855
3907
|
};
|
|
3856
3908
|
const settleThinking = (fold) => {
|
|
3857
3909
|
if (!thinkingId || thinkingCollapsed) return;
|
|
3858
|
-
const
|
|
3859
|
-
const keepOpen = !fold ||
|
|
3910
|
+
const chatConfig2 = typeof Element !== "undefined" && target instanceof Element ? resolveConfig(target) : config;
|
|
3911
|
+
const keepOpen = !fold || chatConfig2.getSegmentDefaults("thinking")?.collapsed === false;
|
|
3860
3912
|
target.updateSegment?.(thinkingId, keepOpen ? { isStreaming: false } : { collapsed: true, isStreaming: false });
|
|
3861
3913
|
thinkingCollapsed = true;
|
|
3862
3914
|
};
|
|
3863
|
-
|
|
3915
|
+
const handle = (e) => {
|
|
3864
3916
|
switch (e.type) {
|
|
3865
3917
|
case "run-start":
|
|
3866
3918
|
target.updateMessage?.(messageId, { status: "streaming" });
|
|
@@ -4007,6 +4059,7 @@ function createStreamAdapter(opts) {
|
|
|
4007
4059
|
case "run-suspended": {
|
|
4008
4060
|
const ticket = e.ticket;
|
|
4009
4061
|
for (const p of e.pending) {
|
|
4062
|
+
if (p.agentId != null) continue;
|
|
4010
4063
|
const id = `tool-${p.toolCallId}`;
|
|
4011
4064
|
const deferred2 = { reason: p.reason, ...typeof ticket === "string" ? { ticket } : {} };
|
|
4012
4065
|
target.updateSegment?.(id, { deferred: deferred2 });
|
|
@@ -4035,7 +4088,47 @@ function createStreamAdapter(opts) {
|
|
|
4035
4088
|
break;
|
|
4036
4089
|
}
|
|
4037
4090
|
};
|
|
4091
|
+
const chatConfig = () => typeof Element !== "undefined" && target instanceof Element ? resolveConfig(target) : config;
|
|
4092
|
+
const reported2 = /* @__PURE__ */ new Set();
|
|
4093
|
+
const observe = (e, own) => {
|
|
4094
|
+
const observers2 = /* @__PURE__ */ new Set();
|
|
4095
|
+
for (const c of /* @__PURE__ */ new Set([own, config, aparteGlobalConfig])) {
|
|
4096
|
+
for (const fn of c.getRunEventObservers()) observers2.add(fn);
|
|
4097
|
+
}
|
|
4098
|
+
if (observers2.size === 0) return false;
|
|
4099
|
+
const ctx = { messageId, target, ...targetId !== void 0 ? { targetId } : {}, config: own };
|
|
4100
|
+
for (const fn of observers2) {
|
|
4101
|
+
try {
|
|
4102
|
+
fn(e, ctx);
|
|
4103
|
+
} catch (error) {
|
|
4104
|
+
if (!reported2.has(fn)) {
|
|
4105
|
+
reported2.add(fn);
|
|
4106
|
+
console.error("[aparte] A run-event observer threw; the reply goes on without it. Further throws from it in this reply are not reported.", error);
|
|
4107
|
+
}
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
return true;
|
|
4111
|
+
};
|
|
4112
|
+
return (e) => {
|
|
4113
|
+
const own = chatConfig();
|
|
4114
|
+
const observed2 = !notify || observe(e, own);
|
|
4115
|
+
const agentId = e.agentId;
|
|
4116
|
+
if (agentId == null && e.type !== "agent-start" && e.type !== "agent-end") {
|
|
4117
|
+
handle(e);
|
|
4118
|
+
return;
|
|
4119
|
+
}
|
|
4120
|
+
if (!observed2 && !warnedConfigs.has(own)) {
|
|
4121
|
+
warnedConfigs.add(own);
|
|
4122
|
+
console.warn(
|
|
4123
|
+
`[aparte] A sub-agent's events arrived (agent "${String(agentId)}") and nothing draws them: they are kept out of the reply and not shown. Add @aparte/plugin-subagents (setupSubagents()) to show one line per sub-agent, or hear them with config.observeRunEvents().`
|
|
4124
|
+
);
|
|
4125
|
+
}
|
|
4126
|
+
if (e.type === "tool-awaiting-approval") {
|
|
4127
|
+
dispatchLifecycleEvent(target, "aparte-tool-approval-request", { toolCallId: e.toolCallId, toolName: e.name, input: e.input, agentId }, targetId);
|
|
4128
|
+
}
|
|
4129
|
+
};
|
|
4038
4130
|
}
|
|
4131
|
+
const warnedConfigs = /* @__PURE__ */ new WeakSet();
|
|
4039
4132
|
function readableToAsyncIterable(stream, signal) {
|
|
4040
4133
|
return {
|
|
4041
4134
|
[Symbol.asyncIterator]() {
|
|
@@ -4267,7 +4360,7 @@ function createAparteAgentHandler(options) {
|
|
|
4267
4360
|
},
|
|
4268
4361
|
toolLookup: (name) => {
|
|
4269
4362
|
const t = offered.has(name) ? tools.get(name) : void 0;
|
|
4270
|
-
return t ? (call, signal) => t.handler(call, signal, { request: req }) : void 0;
|
|
4363
|
+
return t ? (call, signal, run2) => t.handler(call, signal, run2 ? { request: req, run: run2 } : { request: req }) : void 0;
|
|
4271
4364
|
},
|
|
4272
4365
|
toolConfigLookup: (name) => {
|
|
4273
4366
|
if (!offered.has(name)) return void 0;
|
|
@@ -4294,7 +4387,12 @@ function createAparteAgentHandler(options) {
|
|
|
4294
4387
|
emitter,
|
|
4295
4388
|
signal: run.signal,
|
|
4296
4389
|
...options.maxTurns !== void 0 ? { maxTurns: options.maxTurns } : {},
|
|
4297
|
-
...options.toolTimeoutMs !== void 0 ? { toolTimeoutMs: options.toolTimeoutMs } : {}
|
|
4390
|
+
...options.toolTimeoutMs !== void 0 ? { toolTimeoutMs: options.toolTimeoutMs } : {},
|
|
4391
|
+
// Ids that cannot repeat from one request to the next, as the browser
|
|
4392
|
+
// client mints them. The engine's default is a counter per run, and every
|
|
4393
|
+
// request is a run: the resume of a paused reply named its first sub-agent
|
|
4394
|
+
// `agent-0` again, and the page took it for the first one resumed.
|
|
4395
|
+
idGen: (prefix) => prefix === "synthetic-tool" ? uuid() : `${prefix}-${uuid()}`
|
|
4298
4396
|
}).then(async () => {
|
|
4299
4397
|
await pendingWrite;
|
|
4300
4398
|
close();
|
|
@@ -4951,9 +5049,13 @@ class AparteConfig {
|
|
|
4951
5049
|
/** Bumped by `reset()`: a restore function from before it must not undo what came after. */
|
|
4952
5050
|
_overrideGeneration = 0;
|
|
4953
5051
|
_toolDisplays = new ToolTable();
|
|
5052
|
+
/** What a plugin says about a call, read after the app's display — see {@link setToolLineProvider}. */
|
|
5053
|
+
_toolLineProvider = null;
|
|
4954
5054
|
/** Tagged blocks the stream parser recognises in the prose — see {@link registerStreamBlock}. */
|
|
4955
5055
|
_streamBlocks = /* @__PURE__ */ new Map();
|
|
4956
5056
|
_segmentDefaults = /* @__PURE__ */ new Map();
|
|
5057
|
+
/** One entry per registration, so each remover takes back its own — see {@link observeRunEvents}. */
|
|
5058
|
+
_runEventObservers = [];
|
|
4957
5059
|
// Host handlers — what the app declares it can actually complete.
|
|
4958
5060
|
_hostHandlers = { ...APARTE_DEFAULT_HOST_HANDLERS };
|
|
4959
5061
|
// Bubble Actions — APARTE_DEFAULT_BUBBLE_ACTIONS is the single source of truth
|
|
@@ -6162,6 +6264,35 @@ class AparteConfig {
|
|
|
6162
6264
|
const rank = { exact: 2, pattern: 1, any: 0 };
|
|
6163
6265
|
return !renderer || rank[renderer.level] <= rank[display.level];
|
|
6164
6266
|
}
|
|
6267
|
+
/**
|
|
6268
|
+
* Say more about a call than its display does: what ran it, what it is doing now, a
|
|
6269
|
+
* short note after its state. For a plugin that knows a call from the inside — a
|
|
6270
|
+
* sub-agent's line is the line of the call that opened it.
|
|
6271
|
+
*
|
|
6272
|
+
* One provider per config; `null` removes it. It is consulted AFTER the app's display,
|
|
6273
|
+
* field by field, so the app always wins: `label` and `target` are read when the display
|
|
6274
|
+
* gives none, `details` when the display has no `details` key. `activity`, a second
|
|
6275
|
+
* line under the name, and `note` show in every state they are given: give `activity` for
|
|
6276
|
+
* the call's whole life, or never, or the row changes height. A function, called whenever the
|
|
6277
|
+
* row is drawn, updated or relabelled — never text stored on the segment — so its words
|
|
6278
|
+
* follow a language switch. One that throws, or returns nothing, leaves the default
|
|
6279
|
+
* line. A chat with a config of its own and no provider reads {@link aparteGlobalConfig}'s.
|
|
6280
|
+
*
|
|
6281
|
+
* @example
|
|
6282
|
+
* aparteGlobalConfig.setToolLineProvider((segment) =>
|
|
6283
|
+
* segment.toolCall.name === 'delegate' ? { activity: 'Reading the parser', note: '3 tools' } : undefined);
|
|
6284
|
+
*/
|
|
6285
|
+
setToolLineProvider(provider) {
|
|
6286
|
+
if (this._toolLineProvider === provider) return;
|
|
6287
|
+
this._toolLineProvider = provider;
|
|
6288
|
+
bumpRenderingVersion(this);
|
|
6289
|
+
this._notify();
|
|
6290
|
+
}
|
|
6291
|
+
/** The tool-line provider this config reads: its own, else the page's. */
|
|
6292
|
+
getToolLineProvider() {
|
|
6293
|
+
if (this._toolLineProvider || this === aparteGlobalConfig) return this._toolLineProvider;
|
|
6294
|
+
return aparteGlobalConfig._toolLineProvider;
|
|
6295
|
+
}
|
|
6165
6296
|
/** Drop one field of the entry under `match`, and the entry when nothing is left. */
|
|
6166
6297
|
_dropToolDisplayField(match, field) {
|
|
6167
6298
|
const entry = this._toolDisplays.get(match);
|
|
@@ -6259,6 +6390,33 @@ class AparteConfig {
|
|
|
6259
6390
|
getStreamBlocks() {
|
|
6260
6391
|
return Array.from(this._streamBlocks.values());
|
|
6261
6392
|
}
|
|
6393
|
+
/**
|
|
6394
|
+
* Hear every event of a reply's run, before the reply handles it — including the
|
|
6395
|
+
* events of its sub-agents, which the reply never draws: an event that carries an
|
|
6396
|
+
* `agentId`, and `agent-start` / `agent-end`, are kept out of the reply whether anyone
|
|
6397
|
+
* observes them or not. This is how a plugin draws a sub-agent's conversation.
|
|
6398
|
+
*
|
|
6399
|
+
* A chat hears the observers of its own config first, then those of
|
|
6400
|
+
* {@link aparteGlobalConfig}, the way a segment renderer is found: one registered once on
|
|
6401
|
+
* the page reaches a chat that carries a config of its own. An observer that throws is
|
|
6402
|
+
* reported once per reply, and the reply goes on. Returns the function that removes it.
|
|
6403
|
+
*
|
|
6404
|
+
* @example
|
|
6405
|
+
* const stop = aparteGlobalConfig.observeRunEvents((event, { messageId }) => {
|
|
6406
|
+
* if (event.type === 'agent-start') console.info(`${messageId}: ${event.name} started`);
|
|
6407
|
+
* });
|
|
6408
|
+
*/
|
|
6409
|
+
observeRunEvents(observer) {
|
|
6410
|
+
const entry = { fn: observer };
|
|
6411
|
+
this._runEventObservers.push(entry);
|
|
6412
|
+
return () => {
|
|
6413
|
+
this._runEventObservers = this._runEventObservers.filter((e) => e !== entry);
|
|
6414
|
+
};
|
|
6415
|
+
}
|
|
6416
|
+
/** The observers registered on this config, in registration order (read by the stream adapter). */
|
|
6417
|
+
getRunEventObservers() {
|
|
6418
|
+
return this._runEventObservers.map((e) => e.fn);
|
|
6419
|
+
}
|
|
6262
6420
|
// ─────────────────────────────────────────────────────────────────────────
|
|
6263
6421
|
// Conversation Manager (optional, agnostic persistence layer)
|
|
6264
6422
|
// ─────────────────────────────────────────────────────────────────────────
|
|
@@ -6404,10 +6562,10 @@ class AparteConfig {
|
|
|
6404
6562
|
}
|
|
6405
6563
|
/**
|
|
6406
6564
|
* Put the configuration back to its defaults: the providers and the selected model,
|
|
6407
|
-
* the tools with their renderers and summaries, the renderers and render hooks, the
|
|
6565
|
+
* the tools with their renderers and summaries, the tool-line provider, the renderers and render hooks, the
|
|
6408
6566
|
* Markdown and highlight providers, the code-language renderers, the sanitizer, the system prompt, the locale, icons,
|
|
6409
6567
|
* avatars, actions and host handlers, the conversation manager, the question presenters
|
|
6410
|
-
* and their queue. Three things stay: the transport, the key sources added with
|
|
6568
|
+
* and their queue, the run-event observers. Three things stay: the transport, the key sources added with
|
|
6411
6569
|
* {@link AparteConfig.registerKeyProvider | registerKeyProvider()} (an `AparteClient`'s
|
|
6412
6570
|
* `keyResolver` among them), and the {@link AparteConfig.subscribe | subscribe()} listeners.
|
|
6413
6571
|
*/
|
|
@@ -6445,7 +6603,9 @@ class AparteConfig {
|
|
|
6445
6603
|
this._overrideGeneration++;
|
|
6446
6604
|
notifyRenderersChanged(this);
|
|
6447
6605
|
this._toolDisplays.clear();
|
|
6606
|
+
this._toolLineProvider = null;
|
|
6448
6607
|
this._streamBlocks.clear();
|
|
6608
|
+
this._runEventObservers = [];
|
|
6449
6609
|
this._modelConfig = {};
|
|
6450
6610
|
this._requireModelSelection = false;
|
|
6451
6611
|
this._elicitationAllowOther = true;
|
|
@@ -8701,17 +8861,18 @@ function answerOf(segment) {
|
|
|
8701
8861
|
return STOPPED_TOOL_TEXT;
|
|
8702
8862
|
}
|
|
8703
8863
|
const isOpenDeferred = (segment) => segment.type === "tool_call" && Boolean(segment.deferred) && (segment.status === "awaiting-approval" || segment.status === "pending");
|
|
8704
|
-
|
|
8864
|
+
const isLeftOpen = (segment) => segment.type === "tool_call" && (segment.status === "pending" || segment.status === "awaiting-approval");
|
|
8865
|
+
function wireTurns(message, textOf2, options = {}) {
|
|
8705
8866
|
const segments = message.segments ?? [];
|
|
8706
8867
|
if (message.role !== "assistant" || !segments.some((s) => s.type === "tool_call")) {
|
|
8707
|
-
const content =
|
|
8868
|
+
const content = textOf2(segments) || (typeof message.content === "string" ? message.content : "");
|
|
8708
8869
|
return content ? [{ role: message.role, content }] : [];
|
|
8709
8870
|
}
|
|
8710
8871
|
const out = [];
|
|
8711
8872
|
let texts = [];
|
|
8712
8873
|
let calls = [];
|
|
8713
8874
|
const flush = () => {
|
|
8714
|
-
const content =
|
|
8875
|
+
const content = textOf2(texts);
|
|
8715
8876
|
if (calls.length === 0) {
|
|
8716
8877
|
if (content) out.push({ role: "assistant", content });
|
|
8717
8878
|
} else {
|
|
@@ -8721,7 +8882,7 @@ function wireTurns(message, textOf, options = {}) {
|
|
|
8721
8882
|
toolCalls: calls.map((c) => ({ id: c.toolCall.id, name: c.toolCall.name, input: c.toolCall.input }))
|
|
8722
8883
|
});
|
|
8723
8884
|
for (const c of calls) {
|
|
8724
|
-
if (options.openDeferred &&
|
|
8885
|
+
if (options.openDeferred && isLeftOpen(c)) continue;
|
|
8725
8886
|
out.push({ role: "tool", content: answerOf(c), toolCallId: c.toolCall.id, toolName: c.toolCall.name });
|
|
8726
8887
|
}
|
|
8727
8888
|
}
|
|
@@ -8732,7 +8893,7 @@ function wireTurns(message, textOf, options = {}) {
|
|
|
8732
8893
|
for (const segment of segments) {
|
|
8733
8894
|
if (segment.type === "tool_call") {
|
|
8734
8895
|
calls.push(segment);
|
|
8735
|
-
if (options.openDeferred &&
|
|
8896
|
+
if (options.openDeferred && isLeftOpen(segment)) open = true;
|
|
8736
8897
|
} else {
|
|
8737
8898
|
if (calls.length > 0 && !open) flush();
|
|
8738
8899
|
texts.push(segment);
|
|
@@ -9374,9 +9535,9 @@ function buildApprovalPanel(message, options, onChange, details, allowOther = tr
|
|
|
9374
9535
|
row.setAttribute("aria-describedby", ask.id);
|
|
9375
9536
|
}
|
|
9376
9537
|
const labelled = [];
|
|
9377
|
-
const
|
|
9538
|
+
const textOf2 = (option) => typeof option.label === "function" ? option.label() : option.label;
|
|
9378
9539
|
const descriptionOf = (option) => typeof option.description === "function" ? option.description() : option.description;
|
|
9379
|
-
const bodyOf = (option) => optionBody(
|
|
9540
|
+
const bodyOf = (option) => optionBody(textOf2(option), descriptionOf(option));
|
|
9380
9541
|
for (const option of options) {
|
|
9381
9542
|
const tone = option.tone ?? "affirm";
|
|
9382
9543
|
const button = el("button", `aparte-btn aparte-btn--block aparte-btn--surface aparte-approval-option aparte-approval-option--${tone}`);
|
|
@@ -9697,6 +9858,7 @@ class AparteClient {
|
|
|
9697
9858
|
* no DOM) or its own presenter, both strictly more capable than an id on an event.
|
|
9698
9859
|
*/
|
|
9699
9860
|
async _askForApproval(event, signal, target) {
|
|
9861
|
+
const agentName = event.agent?.name?.trim();
|
|
9700
9862
|
const answer = await requestUserInput({
|
|
9701
9863
|
kind: "approval",
|
|
9702
9864
|
/*
|
|
@@ -9716,7 +9878,9 @@ class AparteClient {
|
|
|
9716
9878
|
};
|
|
9717
9879
|
const name = toolNameOf(call, chat).text;
|
|
9718
9880
|
const what = toolTargetOf(call, chat);
|
|
9719
|
-
|
|
9881
|
+
const tool = what ? `${name} ${what}` : name;
|
|
9882
|
+
if (!agentName) return (loc.approvalAsk ?? "Allow {tool}?").replace("{tool}", () => tool);
|
|
9883
|
+
return (loc.approvalAskBy ?? "Allow {tool} for {agent}?").replace(/\{(agent|tool)\}/g, (_, key) => key === "agent" ? agentName : tool);
|
|
9720
9884
|
},
|
|
9721
9885
|
// A plain string, not a function: the arguments are the model's — its JSON, or
|
|
9722
9886
|
// the tool's own formatter's reading of it — and do not change with the
|
|
@@ -9827,6 +9991,7 @@ class AparteClient {
|
|
|
9827
9991
|
if (this._streamController !== streamController) this._streamController?.abort();
|
|
9828
9992
|
this._streamController = streamController;
|
|
9829
9993
|
this._turnsInFlight.add(messageId);
|
|
9994
|
+
this._agentNames.set(messageId, /* @__PURE__ */ new Map());
|
|
9830
9995
|
const compactor = opts?.rebuild ? resolveConfig(targetElement).getCompactor() ?? this._config.getCompactor() : null;
|
|
9831
9996
|
const turnIds = () => {
|
|
9832
9997
|
const path = targetElement.getMessages?.() ?? [];
|
|
@@ -9859,7 +10024,7 @@ class AparteClient {
|
|
|
9859
10024
|
break;
|
|
9860
10025
|
}
|
|
9861
10026
|
const approvedNow = /* @__PURE__ */ new Set();
|
|
9862
|
-
const outcomes = stopped ? void 0 : await this._answerDeferred(targetElement, result.suspended.pending, streamController.signal, rowEvents, approvedAtLastPause, approvedNow);
|
|
10027
|
+
const outcomes = stopped ? void 0 : await this._answerDeferred(targetElement, messageId, result.suspended.pending, streamController.signal, rowEvents, approvedAtLastPause, approvedNow);
|
|
9863
10028
|
approvedAtLastPause = approvedNow;
|
|
9864
10029
|
if (!outcomes) {
|
|
9865
10030
|
this._closeOpenCalls(targetElement, messageId);
|
|
@@ -9962,6 +10127,7 @@ class AparteClient {
|
|
|
9962
10127
|
}
|
|
9963
10128
|
} finally {
|
|
9964
10129
|
this._turnsInFlight.delete(messageId);
|
|
10130
|
+
this._agentNames.delete(messageId);
|
|
9965
10131
|
}
|
|
9966
10132
|
}
|
|
9967
10133
|
/**
|
|
@@ -9969,6 +10135,12 @@ class AparteClient {
|
|
|
9969
10135
|
* load of their conversation must not start them again (`resumeDeferred`).
|
|
9970
10136
|
*/
|
|
9971
10137
|
_turnsInFlight = /* @__PURE__ */ new Set();
|
|
10138
|
+
/**
|
|
10139
|
+
* The name of each sub-agent of a turn in flight, by reply then `agentId`, as its
|
|
10140
|
+
* `agent-start` gave it: what a paused run's question says about who asks. A pending
|
|
10141
|
+
* call carries only an `agentId`. Lives as long as the turn, never on the message.
|
|
10142
|
+
*/
|
|
10143
|
+
_agentNames = /* @__PURE__ */ new Map();
|
|
9972
10144
|
/**
|
|
9973
10145
|
* Handle aparte-retry — add a sibling branch to the assistant message and re-stream
|
|
9974
10146
|
* using the same conversation history minus the retried reply.
|
|
@@ -10515,6 +10687,8 @@ ${content}
|
|
|
10515
10687
|
let toolCrash;
|
|
10516
10688
|
const emitter = (event) => {
|
|
10517
10689
|
adapter(event);
|
|
10690
|
+
if (event.type === "agent-start" && event.name) this._agentNames.get(messageId)?.set(event.agentId, event.name);
|
|
10691
|
+
if (event.agentId != null) return;
|
|
10518
10692
|
if (event.type === "tool-failed") toolCrash = event.error;
|
|
10519
10693
|
if (event.type === "run-done") finishReason = event.finishReason;
|
|
10520
10694
|
if (event.type === "run-suspended") {
|
|
@@ -10533,7 +10707,7 @@ ${content}
|
|
|
10533
10707
|
const handler = this._config.getToolHandler(name);
|
|
10534
10708
|
if (!handler) return void 0;
|
|
10535
10709
|
const context = { target: targetElement, config: this._config };
|
|
10536
|
-
return (call, sig) => handler(call, sig, context);
|
|
10710
|
+
return (call, sig, run) => handler(call, sig, run ? { ...context, run } : context);
|
|
10537
10711
|
};
|
|
10538
10712
|
const hostOwnsDecision = Boolean(this.options.approvalResolver);
|
|
10539
10713
|
const toolConfigLookup = (name) => {
|
|
@@ -10611,7 +10785,7 @@ ${content}
|
|
|
10611
10785
|
* nobody answered — the turn was stopped, or the channel gave up — and there is no
|
|
10612
10786
|
* resume. A channel that CRASHES fails the turn, as it does for a run in the page.
|
|
10613
10787
|
*/
|
|
10614
|
-
async _answerDeferred(targetElement, pending2, signal, rowEvents, approvedBefore = /* @__PURE__ */ new Set(), approvedNow = /* @__PURE__ */ new Set()) {
|
|
10788
|
+
async _answerDeferred(targetElement, messageId, pending2, signal, rowEvents, approvedBefore = /* @__PURE__ */ new Set(), approvedNow = /* @__PURE__ */ new Set()) {
|
|
10615
10789
|
const outcomes = {};
|
|
10616
10790
|
const resolver = this._approvalResolverFor(targetElement, true);
|
|
10617
10791
|
const refuseTheRest = (after) => {
|
|
@@ -10622,10 +10796,12 @@ ${content}
|
|
|
10622
10796
|
for (const [index, p] of pending2.entries()) {
|
|
10623
10797
|
if (signal.aborted) break;
|
|
10624
10798
|
const call = { id: p.toolCallId, name: p.name, input: p.input ?? {} };
|
|
10799
|
+
const agentName = p.agentId === void 0 ? void 0 : this._agentNames.get(messageId)?.get(p.agentId);
|
|
10800
|
+
const asked2 = p.agentId === void 0 ? call : { ...call, agent: { id: p.agentId, ...agentName ? { name: agentName } : {} } };
|
|
10625
10801
|
if (p.reason === "approval") {
|
|
10626
10802
|
let decision;
|
|
10627
10803
|
try {
|
|
10628
|
-
decision = await resolver(
|
|
10804
|
+
decision = await resolver(asked2, signal);
|
|
10629
10805
|
} catch (error) {
|
|
10630
10806
|
if (!signal.aborted && error?.name !== "AbortError") throw error;
|
|
10631
10807
|
}
|
|
@@ -10641,7 +10817,7 @@ ${content}
|
|
|
10641
10817
|
const key = approvalKey(call);
|
|
10642
10818
|
if (!approvedBefore.has(key) && !approvedNow.has(key)) {
|
|
10643
10819
|
try {
|
|
10644
|
-
gate = await this._gateBrowserTool(
|
|
10820
|
+
gate = await this._gateBrowserTool(asked2, signal, targetElement, rowEvents);
|
|
10645
10821
|
} catch (error) {
|
|
10646
10822
|
if (!signal.aborted && error?.name !== "AbortError") throw error;
|
|
10647
10823
|
gate = void 0;
|
|
@@ -10682,9 +10858,20 @@ ${content}
|
|
|
10682
10858
|
async _gateBrowserTool(call, signal, targetElement, rowEvents) {
|
|
10683
10859
|
const ruling = this.options.approvalResolver ? this._config.getTools().find((t) => t.name === call.name)?.needsApproval ? "ask" : "allow" : this._config.ruleOnToolCall(call).verdict;
|
|
10684
10860
|
if (ruling === "allow") return null;
|
|
10685
|
-
if (ruling === "ask")
|
|
10861
|
+
if (ruling === "ask") {
|
|
10862
|
+
rowEvents?.({
|
|
10863
|
+
type: "tool-awaiting-approval",
|
|
10864
|
+
toolCallId: call.id,
|
|
10865
|
+
name: call.name,
|
|
10866
|
+
input: call.input,
|
|
10867
|
+
...call.agent ? { agentId: call.agent.id } : {}
|
|
10868
|
+
});
|
|
10869
|
+
}
|
|
10686
10870
|
const decision = await this._approvalResolverFor(targetElement)(call, signal) ?? void 0;
|
|
10687
|
-
if (decision?.approved && ruling === "ask")
|
|
10871
|
+
if (decision?.approved && ruling === "ask") {
|
|
10872
|
+
if (call.agent) rowEvents?.({ type: "tool-approved", toolCallId: call.id, agentId: call.agent.id });
|
|
10873
|
+
else targetElement.updateSegment?.(`tool-${call.id}`, { status: "pending" });
|
|
10874
|
+
}
|
|
10688
10875
|
return decision;
|
|
10689
10876
|
}
|
|
10690
10877
|
/**
|
|
@@ -10865,7 +11052,9 @@ ${content}
|
|
|
10865
11052
|
dispatchLifecycleEvent(target, "aparte-message-error", { messageId, error }, this._targetIdOf(target));
|
|
10866
11053
|
}
|
|
10867
11054
|
}
|
|
11055
|
+
const RUN_LEVEL = /* @__PURE__ */ new Set(["run-start", "run-done", "run-aborted", "run-suspended"]);
|
|
10868
11056
|
function createAgentStreamRunner(options) {
|
|
11057
|
+
let warnedAttributedEnd = false;
|
|
10869
11058
|
return async (opts) => {
|
|
10870
11059
|
const doFetch = options.fetch ?? fetch;
|
|
10871
11060
|
const headers = typeof options.headers === "function" ? await options.headers() : options.headers ?? {};
|
|
@@ -10902,6 +11091,15 @@ function createAgentStreamRunner(options) {
|
|
|
10902
11091
|
const known2 = Object.values(AparteErrorCode).includes(line.code ?? "") ? line.code : void 0;
|
|
10903
11092
|
throw new AparteError(line.message || "The agent run failed.", known2 ?? AparteErrorCode.PROVIDER_ERROR, line.code ? { code: line.code } : void 0);
|
|
10904
11093
|
}
|
|
11094
|
+
if (RUN_LEVEL.has(line.type) && line.agentId != null) {
|
|
11095
|
+
if (!warnedAttributedEnd) {
|
|
11096
|
+
warnedAttributedEnd = true;
|
|
11097
|
+
console.warn(
|
|
11098
|
+
`[aparte] The agent endpoint sent a "${line.type}" line carrying an agentId; it was dropped. A sub-agent never starts or ends the run: close it with "agent-end", and end the run with one "run-done" of its own.`
|
|
11099
|
+
);
|
|
11100
|
+
}
|
|
11101
|
+
continue;
|
|
11102
|
+
}
|
|
10905
11103
|
if (line.type === "run-done" || line.type === "run-suspended") {
|
|
10906
11104
|
usage = line.usage;
|
|
10907
11105
|
ended = true;
|
|
@@ -11297,6 +11495,66 @@ function placeFloating(anchor, floating, options = {}) {
|
|
|
11297
11495
|
floating.style.top = `${clamp(top, window.innerHeight, box.height)}px`;
|
|
11298
11496
|
floating.style.left = `${clamp(left, window.innerWidth, box.width)}px`;
|
|
11299
11497
|
}
|
|
11498
|
+
function createSegmentList(opts) {
|
|
11499
|
+
const { messageId, config } = opts;
|
|
11500
|
+
let segments = (opts.segments ?? []).reduce((acc, segment) => {
|
|
11501
|
+
acc.push(adoptSegment(acc, segment, messageId));
|
|
11502
|
+
return acc;
|
|
11503
|
+
}, []);
|
|
11504
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
11505
|
+
const changed = () => {
|
|
11506
|
+
for (const fn of [...listeners]) {
|
|
11507
|
+
try {
|
|
11508
|
+
fn();
|
|
11509
|
+
} catch (err) {
|
|
11510
|
+
console.error("[aparte] A segment-list listener threw", err);
|
|
11511
|
+
}
|
|
11512
|
+
}
|
|
11513
|
+
};
|
|
11514
|
+
return {
|
|
11515
|
+
get segments() {
|
|
11516
|
+
return segments;
|
|
11517
|
+
},
|
|
11518
|
+
onChange(fn) {
|
|
11519
|
+
listeners.add(fn);
|
|
11520
|
+
return () => {
|
|
11521
|
+
listeners.delete(fn);
|
|
11522
|
+
};
|
|
11523
|
+
},
|
|
11524
|
+
addSegment(segment) {
|
|
11525
|
+
const stamped = stampSegmentOnInsert(segments, segment, messageId, config?.getSegmentDefaults(segment.type));
|
|
11526
|
+
segments = [...segments, stamped];
|
|
11527
|
+
changed();
|
|
11528
|
+
},
|
|
11529
|
+
updateSegment(segmentId, updates) {
|
|
11530
|
+
const at = segments.findIndex((s) => s.id === segmentId);
|
|
11531
|
+
if (at === -1) return;
|
|
11532
|
+
const current = segments[at];
|
|
11533
|
+
const next = segments.slice();
|
|
11534
|
+
next[at] = mergeSegmentUpdate(current, stampSegmentOnUpdate(current, updates));
|
|
11535
|
+
segments = next;
|
|
11536
|
+
changed();
|
|
11537
|
+
},
|
|
11538
|
+
updateMessage() {
|
|
11539
|
+
},
|
|
11540
|
+
setUsage() {
|
|
11541
|
+
},
|
|
11542
|
+
dispatchEvent() {
|
|
11543
|
+
return true;
|
|
11544
|
+
}
|
|
11545
|
+
};
|
|
11546
|
+
}
|
|
11547
|
+
function pluralize(forms, n, tag) {
|
|
11548
|
+
let category = "other";
|
|
11549
|
+
try {
|
|
11550
|
+
category = new Intl.PluralRules(tag).select(n);
|
|
11551
|
+
} catch {
|
|
11552
|
+
}
|
|
11553
|
+
const options = forms.split("|");
|
|
11554
|
+
const named = (name) => options.find((form2) => form2.startsWith(`${name}:`));
|
|
11555
|
+
const form = named(category) ?? named("other") ?? forms;
|
|
11556
|
+
return form.slice(form.indexOf(":") + 1).replace("{n}", String(n));
|
|
11557
|
+
}
|
|
11300
11558
|
const RENDERED_CONTENT = ".aparte-message-content, .aparte-segments, .aparte-content, .aparte-checkpoint__summary";
|
|
11301
11559
|
function inRenderedContent(el2) {
|
|
11302
11560
|
return !!el2?.closest?.(RENDERED_CONTENT);
|
|
@@ -11436,93 +11694,98 @@ function deferHydrationOf(ctor) {
|
|
|
11436
11694
|
};
|
|
11437
11695
|
}
|
|
11438
11696
|
export {
|
|
11439
|
-
|
|
11697
|
+
isAwaitingReply as $,
|
|
11440
11698
|
APARTE_CONFIG_CHANGE as A,
|
|
11441
11699
|
contextConfig as B,
|
|
11442
11700
|
copyText as C,
|
|
11443
11701
|
createAgentStreamRunner as D,
|
|
11444
11702
|
createAparteAgentHandler as E,
|
|
11445
11703
|
createAparteChatHandler as F,
|
|
11446
|
-
|
|
11447
|
-
|
|
11448
|
-
|
|
11449
|
-
|
|
11450
|
-
|
|
11451
|
-
|
|
11452
|
-
|
|
11453
|
-
|
|
11454
|
-
|
|
11455
|
-
|
|
11456
|
-
|
|
11457
|
-
|
|
11704
|
+
createSegmentList as G,
|
|
11705
|
+
createStreamAdapter as H,
|
|
11706
|
+
cssEscape as I,
|
|
11707
|
+
declineDefaultRenderers as J,
|
|
11708
|
+
defaultSanitizer as K,
|
|
11709
|
+
deferHydrationOf as L,
|
|
11710
|
+
defineMountedSegmentRenderer as M,
|
|
11711
|
+
defineMountedToolRenderer as N,
|
|
11712
|
+
detachConfig as O,
|
|
11713
|
+
escapeAttr as P,
|
|
11714
|
+
escapeHtml as Q,
|
|
11715
|
+
estimateTokens as R,
|
|
11458
11716
|
SUGGESTIONS_BLOCK_LANGUAGE as S,
|
|
11459
|
-
|
|
11460
|
-
|
|
11461
|
-
|
|
11462
|
-
|
|
11463
|
-
|
|
11464
|
-
|
|
11465
|
-
|
|
11466
|
-
|
|
11717
|
+
estimateWireTokens as T,
|
|
11718
|
+
filesToAttachments as U,
|
|
11719
|
+
formatDuration as V,
|
|
11720
|
+
getAllRenderers as W,
|
|
11721
|
+
getSegmentRenderer as X,
|
|
11722
|
+
historyFromCheckpoint as Y,
|
|
11723
|
+
installDefaultRenderersOnce as Z,
|
|
11724
|
+
installDialogTriggersOnce as _,
|
|
11467
11725
|
APARTE_CONVERSATION_SCHEMA_VERSION as a,
|
|
11468
|
-
|
|
11469
|
-
|
|
11470
|
-
|
|
11471
|
-
|
|
11472
|
-
|
|
11473
|
-
|
|
11474
|
-
|
|
11475
|
-
|
|
11476
|
-
|
|
11477
|
-
|
|
11478
|
-
|
|
11479
|
-
|
|
11480
|
-
|
|
11481
|
-
|
|
11482
|
-
|
|
11483
|
-
|
|
11484
|
-
|
|
11485
|
-
|
|
11486
|
-
|
|
11487
|
-
|
|
11488
|
-
|
|
11489
|
-
|
|
11490
|
-
|
|
11491
|
-
|
|
11492
|
-
|
|
11493
|
-
|
|
11494
|
-
|
|
11495
|
-
|
|
11496
|
-
|
|
11497
|
-
|
|
11498
|
-
|
|
11499
|
-
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11505
|
-
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11509
|
-
|
|
11510
|
-
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
|
|
11516
|
-
|
|
11517
|
-
|
|
11518
|
-
|
|
11519
|
-
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
|
|
11525
|
-
|
|
11726
|
+
isFormatAdapter as a0,
|
|
11727
|
+
isSafeUrl as a1,
|
|
11728
|
+
isSegmentSettled as a2,
|
|
11729
|
+
measureContext as a3,
|
|
11730
|
+
overrideSegmentRenderer as a4,
|
|
11731
|
+
parseAparteEventStream as a5,
|
|
11732
|
+
parseMarkdownToSegments as a6,
|
|
11733
|
+
placeFloating as a7,
|
|
11734
|
+
pluralize as a8,
|
|
11735
|
+
populateBubbleFromMessage as a9,
|
|
11736
|
+
toolCallRenderer as aA,
|
|
11737
|
+
toolRendererThatDrew as aB,
|
|
11738
|
+
isMountedRenderer as aC,
|
|
11739
|
+
renderingVersionOf as aD,
|
|
11740
|
+
onRenderersChange as aE,
|
|
11741
|
+
renderSourceList as aF,
|
|
11742
|
+
mergeSegmentUpdate as aG,
|
|
11743
|
+
toolNameOf as aH,
|
|
11744
|
+
writeStreamedMarkdown as aI,
|
|
11745
|
+
replaceHighlighted as aJ,
|
|
11746
|
+
CheckpointStateWatcher as aK,
|
|
11747
|
+
chatIdOf as aL,
|
|
11748
|
+
stampSegmentActivity as aM,
|
|
11749
|
+
stampSegmentOnInsert as aN,
|
|
11750
|
+
stampSegmentOnUpdate as aO,
|
|
11751
|
+
renumberSegments as aP,
|
|
11752
|
+
openSegmentIds as aQ,
|
|
11753
|
+
isTerminalStatus as aR,
|
|
11754
|
+
adoptMessageSegments as aS,
|
|
11755
|
+
APARTE_DERIVED_SEGMENTS as aT,
|
|
11756
|
+
rememberConversationStatus as aU,
|
|
11757
|
+
tellConversationStatus as aV,
|
|
11758
|
+
conversationStatusOf as aW,
|
|
11759
|
+
visibleReply as aX,
|
|
11760
|
+
usageTokens as aY,
|
|
11761
|
+
rootOf as aZ,
|
|
11762
|
+
inRenderedContent as a_,
|
|
11763
|
+
readableToAsyncIterable as aa,
|
|
11764
|
+
registerDefaultRenderers as ab,
|
|
11765
|
+
registerSegmentRenderer as ac,
|
|
11766
|
+
releaseDeferredHydration as ad,
|
|
11767
|
+
renderCitations as ae,
|
|
11768
|
+
renderCodeLanguages as af,
|
|
11769
|
+
requestUserInput as ag,
|
|
11770
|
+
resolveConfig as ah,
|
|
11771
|
+
revokeAttachmentUrls as ai,
|
|
11772
|
+
runSubAgent as aj,
|
|
11773
|
+
runWithConfig as ak,
|
|
11774
|
+
segmentDuration as al,
|
|
11775
|
+
segmentTiming as am,
|
|
11776
|
+
setupSuggestionBlocks as an,
|
|
11777
|
+
startSubAgent as ao,
|
|
11778
|
+
subscribeConfigChange as ap,
|
|
11779
|
+
toToolCallView as aq,
|
|
11780
|
+
toolRefusal as ar,
|
|
11781
|
+
unregisterSegmentRenderer as as,
|
|
11782
|
+
uuid as at,
|
|
11783
|
+
eventOrigin as au,
|
|
11784
|
+
activeElementIn as av,
|
|
11785
|
+
gateGlide as aw,
|
|
11786
|
+
chatBoundaryOf as ax,
|
|
11787
|
+
relabelCodeLanguages as ay,
|
|
11788
|
+
relabelCitations as az,
|
|
11526
11789
|
APARTE_DEFAULT_BUBBLE_ACTIONS as b,
|
|
11527
11790
|
APARTE_DEFAULT_HOST_HANDLERS as c,
|
|
11528
11791
|
APARTE_DEFAULT_ICON_FALLBACKS as d,
|
|
@@ -11549,4 +11812,4 @@ export {
|
|
|
11549
11812
|
collectRendererStyles as y,
|
|
11550
11813
|
contentToText as z
|
|
11551
11814
|
};
|
|
11552
|
-
//# sourceMappingURL=defer-hydration-
|
|
11815
|
+
//# sourceMappingURL=defer-hydration-W4yhnyfc.js.map
|