@aparte/core 1.12.2 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/aparte-client.d.ts +8 -1
- package/dist/client/aparte-client.d.ts.map +1 -1
- package/dist/client/wire-history.d.ts +15 -13
- package/dist/client/wire-history.d.ts.map +1 -1
- package/dist/components/bubble/aparte-chat-bubble.d.ts +31 -1
- package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -1
- package/dist/components/bubble/bubble-sync.d.ts +4 -1
- package/dist/components/bubble/bubble-sync.d.ts.map +1 -1
- package/dist/components/chat/aparte-chat.d.ts +2 -0
- package/dist/components/chat/aparte-chat.d.ts.map +1 -1
- package/dist/components/composer/aparte-composer.d.ts +4 -0
- package/dist/components/composer/aparte-composer.d.ts.map +1 -1
- package/dist/components/suggestions/aparte-suggestions.d.ts.map +1 -1
- package/dist/components/viewport/aparte-chat-viewport.d.ts +11 -2
- package/dist/components/viewport/aparte-chat-viewport.d.ts.map +1 -1
- package/dist/config/action-provider.d.ts +6 -0
- package/dist/config/action-provider.d.ts.map +1 -1
- package/dist/config/aparte-config.d.ts +31 -0
- package/dist/config/aparte-config.d.ts.map +1 -1
- package/dist/config/avatar-provider.d.ts +9 -1
- package/dist/config/avatar-provider.d.ts.map +1 -1
- package/dist/config/bubble-shell-renderer.d.ts +4 -1
- package/dist/config/bubble-shell-renderer.d.ts.map +1 -1
- package/dist/conversations/conversation-controller.d.ts +1 -0
- package/dist/conversations/conversation-controller.d.ts.map +1 -1
- package/dist/conversations/conversation-manager.d.ts.map +1 -1
- package/dist/custom-elements.json +893 -425
- package/dist/{defer-hydration-DfYJjWtk.js → defer-hydration-Dm6F4kq6.js} +335 -173
- package/dist/defer-hydration-Dm6F4kq6.js.map +1 -0
- package/dist/generated/element-attributes.d.ts +2 -0
- package/dist/generated/element-attributes.d.ts.map +1 -1
- package/dist/host/aparte-chat-host.d.ts +22 -7
- package/dist/host/aparte-chat-host.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +265 -111
- package/dist/index.js.map +1 -1
- package/dist/index.node.d.ts +2 -1
- package/dist/index.node.d.ts.map +1 -1
- package/dist/index.node.js +66 -64
- package/dist/index.node.js.map +1 -1
- package/dist/interop/element-props.d.ts +1 -1
- package/dist/interop/element-props.d.ts.map +1 -1
- package/dist/types/chat.d.ts +7 -0
- package/dist/types/chat.d.ts.map +1 -1
- package/dist/types/event-map.d.ts +2 -1
- package/dist/types/event-map.d.ts.map +1 -1
- package/dist/types/events.d.ts +26 -0
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/imperative-api.d.ts +7 -1
- package/dist/types/imperative-api.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/models.d.ts +40 -0
- package/dist/types/models.d.ts.map +1 -1
- package/dist/utils/is-awaiting-reply.d.ts +1 -1
- package/dist/utils/is-awaiting-reply.d.ts.map +1 -1
- package/dist/utils/is-model-reply.d.ts +14 -0
- package/dist/utils/is-model-reply.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/defer-hydration-DfYJjWtk.js.map +0 -1
|
@@ -5413,6 +5413,8 @@ class AparteConfig {
|
|
|
5413
5413
|
/** Opt-in: gate the composer (block send + grey out) until a model is selected. */
|
|
5414
5414
|
_requireModelSelection = false;
|
|
5415
5415
|
_queueWhileStreaming = false;
|
|
5416
|
+
_autoReply = true;
|
|
5417
|
+
_autoReplyByConversation = /* @__PURE__ */ new Map();
|
|
5416
5418
|
/** Host policy for the elicitation panel's free-text escape — see {@link setElicitationOptions}. */
|
|
5417
5419
|
_elicitationAllowOther = true;
|
|
5418
5420
|
_elicitationLayout = "stepped";
|
|
@@ -6438,6 +6440,50 @@ class AparteConfig {
|
|
|
6438
6440
|
getQueueWhileStreaming() {
|
|
6439
6441
|
return this._queueWhileStreaming;
|
|
6440
6442
|
}
|
|
6443
|
+
/**
|
|
6444
|
+
* Turn the AI's replies off, or back on — for one conversation, or for the whole chat.
|
|
6445
|
+
*
|
|
6446
|
+
* Off, a person's message is still shown, announced (`aparte-send`, with its
|
|
6447
|
+
* `messageId`) and saved, and no turn starts: whoever answers instead — an advisor, another
|
|
6448
|
+
* participant — writes into the chat through `appendMessage`. Every way a turn starts
|
|
6449
|
+
* obeys it: a send, a queued message, a regenerate, an edit, and the resume of a reply that
|
|
6450
|
+
* paused on a question. Regenerate and edit are disabled meanwhile, a model choice the
|
|
6451
|
+
* composer waits for no longer greys it out, and messages queued during a reply are all
|
|
6452
|
+
* sent when it ends, since nothing answers them. A reply already streaming is not stopped:
|
|
6453
|
+
* stop it yourself if the takeover should cut it.
|
|
6454
|
+
*
|
|
6455
|
+
* With a `conversationId` the setting is that conversation's and wins over the chat's;
|
|
6456
|
+
* without one it is the default of every conversation on this config — of every chat on
|
|
6457
|
+
* the page when they share the global config, so give a chat its own config to turn it
|
|
6458
|
+
* off alone. On by default.
|
|
6459
|
+
*
|
|
6460
|
+
* @example
|
|
6461
|
+
* ```ts
|
|
6462
|
+
* // An advisor takes the conversation over: the AI stays quiet in it.
|
|
6463
|
+
* aparteGlobalConfig.setAutoReply(false, conversationId);
|
|
6464
|
+
* ```
|
|
6465
|
+
*/
|
|
6466
|
+
setAutoReply(on, conversationId) {
|
|
6467
|
+
if (conversationId === void 0) {
|
|
6468
|
+
if (this._autoReply === on) return;
|
|
6469
|
+
this._autoReply = on;
|
|
6470
|
+
} else {
|
|
6471
|
+
if (this._autoReplyByConversation.get(conversationId) === on) return;
|
|
6472
|
+
this._autoReplyByConversation.set(conversationId, on);
|
|
6473
|
+
}
|
|
6474
|
+
this._notify();
|
|
6475
|
+
}
|
|
6476
|
+
/**
|
|
6477
|
+
* Whether the AI answers in a conversation (see {@link setAutoReply}): the conversation's
|
|
6478
|
+
* own setting when it has one, else the chat's.
|
|
6479
|
+
*/
|
|
6480
|
+
getAutoReply(conversationId) {
|
|
6481
|
+
if (conversationId !== void 0) {
|
|
6482
|
+
const own = this._autoReplyByConversation.get(conversationId);
|
|
6483
|
+
if (own !== void 0) return own;
|
|
6484
|
+
}
|
|
6485
|
+
return this._autoReply;
|
|
6486
|
+
}
|
|
6441
6487
|
/**
|
|
6442
6488
|
* Get the currently selected model object, if available synchronously.
|
|
6443
6489
|
* Returns undefined if no provider/model is selected, or if the provider's
|
|
@@ -7317,6 +7363,8 @@ class AparteConfig {
|
|
|
7317
7363
|
this._modelConfig = {};
|
|
7318
7364
|
this._requireModelSelection = false;
|
|
7319
7365
|
this._queueWhileStreaming = false;
|
|
7366
|
+
this._autoReply = true;
|
|
7367
|
+
this._autoReplyByConversation.clear();
|
|
7320
7368
|
this._elicitationAllowOther = true;
|
|
7321
7369
|
this._elicitationLayout = "stepped";
|
|
7322
7370
|
this._elicitationAnswerOnClick = true;
|
|
@@ -7532,6 +7580,8 @@ function withLastArriving(message) {
|
|
|
7532
7580
|
}
|
|
7533
7581
|
function populateBubbleFromMessage(bubble, message, siblingInfo) {
|
|
7534
7582
|
bubble.setTokens?.(message.tokens);
|
|
7583
|
+
bubble.setAuthor?.(message.author);
|
|
7584
|
+
bubble.setKind?.(message.kind);
|
|
7535
7585
|
if (message.segments && message.segments.length > 0) {
|
|
7536
7586
|
const existing = bubble.getSegments?.() ?? [];
|
|
7537
7587
|
if (existing.length === message.segments.length) {
|
|
@@ -7562,6 +7612,7 @@ function populateBubbleFromMessage(bubble, message, siblingInfo) {
|
|
|
7562
7612
|
}
|
|
7563
7613
|
bubble.setFinishReason?.(message.finishReason);
|
|
7564
7614
|
bubble.setContextSummary?.(message.contextSummary, { legacy: message.compaction === true });
|
|
7615
|
+
bubble.setNote?.(message.note);
|
|
7565
7616
|
}
|
|
7566
7617
|
const APARTE_CONVERSATION_SCHEMA_VERSION = 2;
|
|
7567
7618
|
const APARTE_DERIVED_SEGMENTS = Symbol.for("aparte.derivedSegments");
|
|
@@ -7852,9 +7903,11 @@ class AparteConversationManager {
|
|
|
7852
7903
|
const fresh = this._find(convId);
|
|
7853
7904
|
if (!fresh) return;
|
|
7854
7905
|
const present = fresh.messages.some((m) => m.id === msg.id);
|
|
7906
|
+
const tree = fresh.tree && !fresh.tree.messages.some((n) => n.message.id === msg.id) ? { headId: msg.id, messages: [...fresh.tree.messages, { message: msg, parentId: fresh.tree.headId }] } : fresh.tree;
|
|
7855
7907
|
const updated = {
|
|
7856
7908
|
...fresh,
|
|
7857
7909
|
messages: present ? fresh.messages : [...fresh.messages, msg],
|
|
7910
|
+
...tree ? { tree } : {},
|
|
7858
7911
|
updatedAt: Date.now(),
|
|
7859
7912
|
title: title ?? fresh.title
|
|
7860
7913
|
};
|
|
@@ -8118,6 +8171,7 @@ class AparteConversationController {
|
|
|
8118
8171
|
_onMessageAborted = null;
|
|
8119
8172
|
_onMessagePaused = null;
|
|
8120
8173
|
_onMessageResumed = null;
|
|
8174
|
+
_onTranscriptChange = null;
|
|
8121
8175
|
_onSelectConversation = null;
|
|
8122
8176
|
_onCompactDone = null;
|
|
8123
8177
|
_unsubscribeManager = null;
|
|
@@ -8326,6 +8380,7 @@ class AparteConversationController {
|
|
|
8326
8380
|
};
|
|
8327
8381
|
this._binding.appendMessage(userMsg);
|
|
8328
8382
|
evt.detail.echoed = true;
|
|
8383
|
+
evt.detail.messageId = userMsg.id;
|
|
8329
8384
|
void this._ensureConversationAndPersist(userMsg);
|
|
8330
8385
|
};
|
|
8331
8386
|
host2.addEventListener("aparte-send", this._onSendCapture, { capture: true });
|
|
@@ -8371,6 +8426,11 @@ class AparteConversationController {
|
|
|
8371
8426
|
host2.addEventListener("aparte-message-aborted", this._onMessageAborted);
|
|
8372
8427
|
host2.addEventListener("aparte-message-paused", this._onMessagePaused);
|
|
8373
8428
|
host2.addEventListener("aparte-message-resumed", this._onMessageResumed);
|
|
8429
|
+
this._onTranscriptChange = () => {
|
|
8430
|
+
if (this._isLoadingConversation || this._isStreaming) return;
|
|
8431
|
+
queueMicrotask(() => this._persistActive());
|
|
8432
|
+
};
|
|
8433
|
+
host2.addEventListener("aparte-transcript-change", this._onTranscriptChange);
|
|
8374
8434
|
this._onSelectConversation = (e) => {
|
|
8375
8435
|
const evt = e;
|
|
8376
8436
|
const targetId = evt.detail?.targetId;
|
|
@@ -8420,6 +8480,10 @@ class AparteConversationController {
|
|
|
8420
8480
|
host2.removeEventListener("aparte-path-changed", this._onPathChanged);
|
|
8421
8481
|
this._onPathChanged = null;
|
|
8422
8482
|
}
|
|
8483
|
+
if (this._onTranscriptChange) {
|
|
8484
|
+
host2.removeEventListener("aparte-transcript-change", this._onTranscriptChange);
|
|
8485
|
+
this._onTranscriptChange = null;
|
|
8486
|
+
}
|
|
8423
8487
|
if (this._onMessageStart) {
|
|
8424
8488
|
host2.removeEventListener("aparte-message-start", this._onMessageStart);
|
|
8425
8489
|
this._onMessageStart = null;
|
|
@@ -8775,6 +8839,16 @@ class AparteConversationController {
|
|
|
8775
8839
|
if (!this._isStreaming && this._activeId === convId) this._persistActive();
|
|
8776
8840
|
}
|
|
8777
8841
|
}
|
|
8842
|
+
function authorTypeOf(message) {
|
|
8843
|
+
return message.author?.type ?? (message.role === "user" ? "human" : "ai");
|
|
8844
|
+
}
|
|
8845
|
+
function isModelReply(message) {
|
|
8846
|
+
return message.role === "assistant" && message.kind === void 0 && authorTypeOf(message) === "ai";
|
|
8847
|
+
}
|
|
8848
|
+
function isAwaitingReply(message) {
|
|
8849
|
+
if (message.status === "streaming" || message.status === "pending") return true;
|
|
8850
|
+
return message.status === void 0 && isModelReply(message) && !message.content?.trim() && !message.segments?.length;
|
|
8851
|
+
}
|
|
8778
8852
|
function gateGlide(el2) {
|
|
8779
8853
|
if (el2.hasAttribute("data-glide")) return () => {
|
|
8780
8854
|
};
|
|
@@ -8885,7 +8959,12 @@ function sameValue(a, b) {
|
|
|
8885
8959
|
return false;
|
|
8886
8960
|
}
|
|
8887
8961
|
}
|
|
8888
|
-
const RENDERED_FIELDS = ["content", "segments", "attachments", "usage", "finishReason", "contextSummary", "compaction"];
|
|
8962
|
+
const RENDERED_FIELDS = ["content", "segments", "attachments", "usage", "finishReason", "contextSummary", "compaction", "author", "kind", "note"];
|
|
8963
|
+
function withMessageAt(messages, index, message) {
|
|
8964
|
+
const next = [...messages];
|
|
8965
|
+
next[index] = message;
|
|
8966
|
+
return next;
|
|
8967
|
+
}
|
|
8889
8968
|
class AparteChatHost {
|
|
8890
8969
|
binding;
|
|
8891
8970
|
options;
|
|
@@ -9225,6 +9304,16 @@ class AparteChatHost {
|
|
|
9225
9304
|
this._vp()?.addMessage?.(stored);
|
|
9226
9305
|
this.binding.setMessages([...this.binding.getMessages(), stored]);
|
|
9227
9306
|
this.binding.onMessageAppended?.(stored);
|
|
9307
|
+
this._announceWrite(stored, "append");
|
|
9308
|
+
}
|
|
9309
|
+
/**
|
|
9310
|
+
* Say that the app wrote into the transcript outside a turn (`aparte-transcript-change`),
|
|
9311
|
+
* so a controller saves it: during a human takeover no turn runs, and nothing else would.
|
|
9312
|
+
* Not for the AI's empty shell, not while a reply streams — the turn's end saves then.
|
|
9313
|
+
*/
|
|
9314
|
+
_announceWrite(message, change) {
|
|
9315
|
+
if (this._streamingId !== null || isAwaitingReply(message)) return;
|
|
9316
|
+
dispatchChatEvent(this.binding.host, "aparte-transcript-change", { messageId: message.id, change });
|
|
9228
9317
|
}
|
|
9229
9318
|
/** Atomic partial update of a message by id. */
|
|
9230
9319
|
updateMessage(messageId, updates) {
|
|
@@ -9253,6 +9342,7 @@ class AparteChatHost {
|
|
|
9253
9342
|
this.updateSegment(id, { isStreaming: false });
|
|
9254
9343
|
}
|
|
9255
9344
|
}
|
|
9345
|
+
this._announceWrite(merged, "update");
|
|
9256
9346
|
}
|
|
9257
9347
|
/**
|
|
9258
9348
|
* Say the step the agent is on in the reply's waiting indicator, or `null` for none. Live
|
|
@@ -9263,27 +9353,28 @@ class AparteChatHost {
|
|
|
9263
9353
|
this._step = name === null ? null : { messageId, name };
|
|
9264
9354
|
this._bubbleById(messageId)?.setStep?.(name);
|
|
9265
9355
|
}
|
|
9266
|
-
/**
|
|
9356
|
+
/**
|
|
9357
|
+
* Append/replace the content of the turn's message (streaming text): the message
|
|
9358
|
+
* being streamed while a turn runs, else the last one.
|
|
9359
|
+
*/
|
|
9267
9360
|
updateLastMessage(content, options) {
|
|
9268
9361
|
if (options?.append) this.binding.onTypingChange?.(false);
|
|
9269
|
-
const
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
if (this._isOrphan(last.id)) return;
|
|
9362
|
+
const target = this._turnTarget();
|
|
9363
|
+
if (!target) return;
|
|
9364
|
+
const { message: last, index } = target;
|
|
9273
9365
|
const newContent = options?.append ? (last.content || "") + content : content;
|
|
9274
|
-
const next =
|
|
9366
|
+
const next = withMessageAt(this.binding.getMessages(), index, { ...last, content: newContent });
|
|
9275
9367
|
this.binding.setMessages(next);
|
|
9276
9368
|
this._report(next);
|
|
9277
9369
|
}
|
|
9278
|
-
/** Add a segment to the
|
|
9370
|
+
/** Add a segment to the turn's message (immediate bubble + state sync). */
|
|
9279
9371
|
addSegment(segment) {
|
|
9280
9372
|
this._flushStreamState();
|
|
9281
|
-
const
|
|
9282
|
-
|
|
9283
|
-
if (target && this._isOrphan(target.id)) return;
|
|
9373
|
+
const target = this._turnTarget();
|
|
9374
|
+
if (!target && this._streamingId !== null) return;
|
|
9284
9375
|
this.binding.onTypingChange?.(false);
|
|
9285
|
-
const msgs =
|
|
9286
|
-
const last = target;
|
|
9376
|
+
const msgs = this.binding.getMessages();
|
|
9377
|
+
const last = target?.message;
|
|
9287
9378
|
const stamped = last ? stampSegmentOnInsert(
|
|
9288
9379
|
last.segments || [],
|
|
9289
9380
|
segment,
|
|
@@ -9294,45 +9385,47 @@ class AparteChatHost {
|
|
|
9294
9385
|
resolveConfig(this.binding.host).getSegmentDefaults(segment.type)
|
|
9295
9386
|
) : segment;
|
|
9296
9387
|
this._streamBubble(last?.id)?.addSegment?.(stamped);
|
|
9297
|
-
if (!last) return;
|
|
9388
|
+
if (!target || !last) return;
|
|
9298
9389
|
const segments = [...last.segments || [], stamped];
|
|
9299
|
-
const next =
|
|
9390
|
+
const next = withMessageAt(msgs, target.index, { ...last, segments });
|
|
9300
9391
|
this.binding.setMessages(next);
|
|
9301
9392
|
this._report(next);
|
|
9302
9393
|
}
|
|
9303
|
-
/** Update a segment in the
|
|
9394
|
+
/** Update a segment in the turn's message in place. */
|
|
9304
9395
|
updateSegment(segmentId, updates) {
|
|
9305
9396
|
this._flushStreamState();
|
|
9397
|
+
const target = this._turnTarget();
|
|
9398
|
+
if (!target && this._streamingId !== null) return;
|
|
9306
9399
|
const msgs = this.binding.getMessages();
|
|
9307
|
-
const last =
|
|
9308
|
-
if (last && this._isOrphan(last.id)) return;
|
|
9400
|
+
const last = target?.message;
|
|
9309
9401
|
const current = last?.segments?.find((s) => s.id === segmentId);
|
|
9310
9402
|
const stamped = current ? stampSegmentOnUpdate(current, updates) : updates;
|
|
9311
9403
|
this._streamBubble(last?.id)?.updateSegment?.(segmentId, stamped);
|
|
9312
|
-
if (!last || !last.segments) return;
|
|
9404
|
+
if (!target || !last || !last.segments) return;
|
|
9313
9405
|
const segments = last.segments.map(
|
|
9314
9406
|
(s) => s.id === segmentId ? mergeSegmentUpdate(s, stamped) : s
|
|
9315
9407
|
);
|
|
9316
|
-
const next =
|
|
9408
|
+
const next = withMessageAt(msgs, target.index, { ...last, segments });
|
|
9317
9409
|
this.binding.setMessages(next);
|
|
9318
9410
|
this._report(next);
|
|
9319
9411
|
}
|
|
9320
|
-
/** Remove a transient segment (a status row the host added itself). */
|
|
9412
|
+
/** Remove a transient segment (a status row the host added itself) from the turn's message. */
|
|
9321
9413
|
removeSegment(segmentId) {
|
|
9322
9414
|
this._flushStreamState();
|
|
9323
|
-
this.
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
|
|
9415
|
+
const target = this._turnTarget();
|
|
9416
|
+
if (!target && this._streamingId !== null) return;
|
|
9417
|
+
this._streamBubble(target?.message.id)?.removeSegment?.(segmentId);
|
|
9418
|
+
const last = target?.message;
|
|
9419
|
+
if (!target || !last?.segments) return;
|
|
9327
9420
|
const segments = last.segments.filter((s) => s.id !== segmentId);
|
|
9328
9421
|
if (segments.length === last.segments.length) return;
|
|
9329
9422
|
renumberSegments(segments);
|
|
9330
|
-
const next =
|
|
9423
|
+
const next = withMessageAt(this.binding.getMessages(), target.index, { ...last, segments });
|
|
9331
9424
|
this.binding.setMessages(next);
|
|
9332
9425
|
this._report(next);
|
|
9333
9426
|
}
|
|
9334
9427
|
/**
|
|
9335
|
-
* Append text to a segment's content in the
|
|
9428
|
+
* Append text to a segment's content in the turn's message — the streaming path
|
|
9336
9429
|
* for thinking blocks, tool pills and any segment that grows token by token.
|
|
9337
9430
|
*
|
|
9338
9431
|
* Two writes, deliberately asymmetric:
|
|
@@ -9347,16 +9440,16 @@ class AparteChatHost {
|
|
|
9347
9440
|
* {@link _flushStreamState}), so ordering is never observable.
|
|
9348
9441
|
*/
|
|
9349
9442
|
appendToSegment(segmentId, content) {
|
|
9350
|
-
const
|
|
9351
|
-
const last =
|
|
9443
|
+
const target = this._turnTarget();
|
|
9444
|
+
const last = target?.message;
|
|
9352
9445
|
if (!last || !last.segments) return;
|
|
9353
|
-
|
|
9354
|
-
let buffered = this._segmentBuffer.get(
|
|
9446
|
+
const key = `${last.id}\0${segmentId}`;
|
|
9447
|
+
let buffered = this._segmentBuffer.get(key);
|
|
9355
9448
|
if (!buffered) {
|
|
9356
9449
|
const segment = last.segments.find((s) => s.id === segmentId);
|
|
9357
9450
|
const base = segment && "content" in segment ? segment.content ?? "" : "";
|
|
9358
|
-
buffered = { base, text: "" };
|
|
9359
|
-
this._segmentBuffer.set(
|
|
9451
|
+
buffered = { messageId: last.id, segmentId, base, text: "" };
|
|
9452
|
+
this._segmentBuffer.set(key, buffered);
|
|
9360
9453
|
}
|
|
9361
9454
|
buffered.text += content;
|
|
9362
9455
|
this._vp()?.appendToSegment?.(last.id, segmentId, content);
|
|
@@ -9401,10 +9494,18 @@ class AparteChatHost {
|
|
|
9401
9494
|
}
|
|
9402
9495
|
}
|
|
9403
9496
|
if (pending2) {
|
|
9404
|
-
const
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9497
|
+
const byMessage = /* @__PURE__ */ new Map();
|
|
9498
|
+
for (const entry of pending2.values()) {
|
|
9499
|
+
let entries = byMessage.get(entry.messageId);
|
|
9500
|
+
if (!entries) byMessage.set(entry.messageId, entries = /* @__PURE__ */ new Map());
|
|
9501
|
+
entries.set(entry.segmentId, entry);
|
|
9502
|
+
}
|
|
9503
|
+
for (const [messageId, entries] of byMessage) {
|
|
9504
|
+
const index = msgs.findIndex((m) => m.id === messageId);
|
|
9505
|
+
const target = index === -1 ? void 0 : msgs[index];
|
|
9506
|
+
if (!target?.segments) continue;
|
|
9507
|
+
const segments = target.segments.map((s) => {
|
|
9508
|
+
const buffered = entries.get(s.id);
|
|
9408
9509
|
if (buffered === void 0 || !("content" in s)) return s;
|
|
9409
9510
|
return {
|
|
9410
9511
|
...s,
|
|
@@ -9412,7 +9513,7 @@ class AparteChatHost {
|
|
|
9412
9513
|
...stampSegmentActivity(s)
|
|
9413
9514
|
};
|
|
9414
9515
|
});
|
|
9415
|
-
msgs =
|
|
9516
|
+
msgs = withMessageAt(msgs, index, { ...target, segments });
|
|
9416
9517
|
changed = true;
|
|
9417
9518
|
}
|
|
9418
9519
|
}
|
|
@@ -9640,9 +9741,21 @@ class AparteChatHost {
|
|
|
9640
9741
|
this._siblingRetries = 0;
|
|
9641
9742
|
}
|
|
9642
9743
|
// ── internals ──────────────────────────────────────────────────────────
|
|
9643
|
-
/**
|
|
9644
|
-
|
|
9645
|
-
|
|
9744
|
+
/**
|
|
9745
|
+
* The message a turn's writes go to, and where it sits in the list. While a turn
|
|
9746
|
+
* runs, the message being streamed — never another one, not even the last: an app
|
|
9747
|
+
* may append a message mid-turn (an advisor's reply, a notice), and a list swapped
|
|
9748
|
+
* under a stream no longer holds its message, whose late writes are then dropped
|
|
9749
|
+
* rather than moved. With no turn running, the last message, as before.
|
|
9750
|
+
*/
|
|
9751
|
+
_turnTarget() {
|
|
9752
|
+
const msgs = this.binding.getMessages();
|
|
9753
|
+
if (this._streamingId !== null) {
|
|
9754
|
+
const index2 = msgs.findIndex((m) => m.id === this._streamingId);
|
|
9755
|
+
return index2 === -1 ? null : { message: msgs[index2], index: index2 };
|
|
9756
|
+
}
|
|
9757
|
+
const index = msgs.length - 1;
|
|
9758
|
+
return index === -1 ? null : { message: msgs[index], index };
|
|
9646
9759
|
}
|
|
9647
9760
|
_vp() {
|
|
9648
9761
|
return this.binding.viewport ?? null;
|
|
@@ -9792,17 +9905,27 @@ function historySummaryOf(messages) {
|
|
|
9792
9905
|
}
|
|
9793
9906
|
return void 0;
|
|
9794
9907
|
}
|
|
9795
|
-
function
|
|
9908
|
+
function mergeAdjacentMessages(messages) {
|
|
9796
9909
|
const asParts = (c) => typeof c === "string" ? [{ type: "text", text: c }] : c;
|
|
9910
|
+
const mergeable = (m) => m !== void 0 && (m.role === "user" || m.role === "assistant" && !m.toolCalls?.length);
|
|
9797
9911
|
const out = [];
|
|
9798
9912
|
for (const m of messages) {
|
|
9799
9913
|
const prev = out[out.length - 1];
|
|
9800
|
-
if (
|
|
9914
|
+
if (!prev || prev.role !== m.role || !mergeable(prev) || !mergeable(m)) {
|
|
9801
9915
|
out.push(m);
|
|
9802
9916
|
} else {
|
|
9803
|
-
const
|
|
9917
|
+
const { name: _prevName, ...base } = prev;
|
|
9918
|
+
const sameAuthor = prev.name === m.name;
|
|
9919
|
+
const said = (msg) => {
|
|
9920
|
+
if (sameAuthor || !msg.name) return msg.content;
|
|
9921
|
+
return typeof msg.content === "string" ? `${msg.name}: ${msg.content}` : [{ type: "text", text: `${msg.name}: ` }, ...msg.content];
|
|
9922
|
+
};
|
|
9923
|
+
const before = said(prev);
|
|
9924
|
+
const after = said(m);
|
|
9925
|
+
const merged = typeof before === "string" && typeof after === "string" ? { ...base, content: `${before}
|
|
9804
9926
|
|
|
9805
|
-
${
|
|
9927
|
+
${after}` } : { ...base, content: [...asParts(before), { type: "text", text: "\n\n" }, ...asParts(after)] };
|
|
9928
|
+
if (sameAuthor && prev.name !== void 0) merged.name = prev.name;
|
|
9806
9929
|
const summary = summaries.get(prev);
|
|
9807
9930
|
if (summary !== void 0) summaries.set(merged, summary);
|
|
9808
9931
|
out[out.length - 1] = merged;
|
|
@@ -9923,7 +10046,9 @@ function withoutAbandonedTurns(messages) {
|
|
|
9923
10046
|
for (const m of messages) {
|
|
9924
10047
|
if (m.role === "user") {
|
|
9925
10048
|
if (!m.compaction) asked2.push(m);
|
|
9926
|
-
} else if (m.role === "assistant") {
|
|
10049
|
+
} else if (m.role === "assistant" && !isModelReply(m)) {
|
|
10050
|
+
asked2 = [];
|
|
10051
|
+
} else if (isModelReply(m)) {
|
|
9927
10052
|
if (m.status !== "error") {
|
|
9928
10053
|
asked2 = [];
|
|
9929
10054
|
} else if (failedForGood(m, asked2)) {
|
|
@@ -9936,15 +10061,16 @@ function withoutAbandonedTurns(messages) {
|
|
|
9936
10061
|
return dropped.size === 0 ? [...messages] : messages.filter((m) => !dropped.has(m));
|
|
9937
10062
|
}
|
|
9938
10063
|
function wireMessages(messages) {
|
|
9939
|
-
return withoutAbandonedTurns(messages).filter((m) => {
|
|
10064
|
+
return withoutAbandonedTurns(messages.filter((m) => m.kind === void 0)).filter((m) => {
|
|
9940
10065
|
if (m.role !== "user" && m.role !== "assistant") return false;
|
|
9941
10066
|
return m.status !== "error" && !isInFlight(m);
|
|
9942
10067
|
}).flatMap((m) => {
|
|
10068
|
+
const named = (c) => m.author?.name && (c.role === "user" || c.role === "assistant") ? { ...c, name: m.author.name } : c;
|
|
9943
10069
|
if (m.role === "assistant" && m.segments?.some((s) => s.type === "tool_call")) {
|
|
9944
|
-
return wireTurns(m, segmentsToWireText);
|
|
10070
|
+
return wireTurns(m, segmentsToWireText).map(named);
|
|
9945
10071
|
}
|
|
9946
10072
|
const content = messageWireText(m);
|
|
9947
|
-
return content ? [{ role: m.role, content }] : [];
|
|
10073
|
+
return content ? [named({ role: m.role, content })] : [];
|
|
9948
10074
|
});
|
|
9949
10075
|
}
|
|
9950
10076
|
function estimateTokens(text) {
|
|
@@ -10588,6 +10714,10 @@ function tokensStillIn(content, tokens) {
|
|
|
10588
10714
|
}
|
|
10589
10715
|
return kept;
|
|
10590
10716
|
}
|
|
10717
|
+
function followedByAHuman(path, messageId) {
|
|
10718
|
+
const at = path.findIndex((m) => m.id === messageId);
|
|
10719
|
+
return at !== -1 && path.slice(at + 1).some((m) => m.kind !== void 0 || m.role === "assistant" && !isModelReply(m));
|
|
10720
|
+
}
|
|
10591
10721
|
class AparteClient {
|
|
10592
10722
|
_boundHandler = null;
|
|
10593
10723
|
/** Between `start()` and `stop()`: the listeners are on `window`. The send handler alone is
|
|
@@ -10996,6 +11126,8 @@ class AparteClient {
|
|
|
10996
11126
|
const compactor = opts?.rebuild ? resolveConfig(targetElement).getCompactor() ?? this._config.getCompactor() : null;
|
|
10997
11127
|
const turnIds = () => {
|
|
10998
11128
|
const path = targetElement.getMessages?.() ?? [];
|
|
11129
|
+
const askedId = opts?.userMessage?.messageId;
|
|
11130
|
+
if (askedId && path.some((m) => m.id === askedId)) return [askedId, messageId];
|
|
10999
11131
|
const at = path.findIndex((m) => m.id === messageId);
|
|
11000
11132
|
const asked2 = at > 0 ? path[at - 1] : void 0;
|
|
11001
11133
|
return asked2?.role === "user" ? [asked2.id, messageId] : [messageId];
|
|
@@ -11157,6 +11289,17 @@ class AparteClient {
|
|
|
11157
11289
|
_toolsForCurrentModel() {
|
|
11158
11290
|
return toolsForCurrentModel(this._config);
|
|
11159
11291
|
}
|
|
11292
|
+
/**
|
|
11293
|
+
* Whether the AI answers in a conversation of `target` (`setAutoReply`): the client's
|
|
11294
|
+
* config and the chat's must both say so. A chat with its own config answered by the
|
|
11295
|
+
* page's client is turned off on its own config — the one its bubbles and composer read,
|
|
11296
|
+
* so the buttons they disable and the turns refused here never disagree.
|
|
11297
|
+
*/
|
|
11298
|
+
_autoReplies(target, conversationId) {
|
|
11299
|
+
if (!this._config.getAutoReply(conversationId)) return false;
|
|
11300
|
+
const chat = resolveConfig(target);
|
|
11301
|
+
return chat === this._config || chat.getAutoReply(conversationId);
|
|
11302
|
+
}
|
|
11160
11303
|
async _handleRetry(event) {
|
|
11161
11304
|
const { messageId, targetId } = event.detail ?? {};
|
|
11162
11305
|
this._beginUserTurn();
|
|
@@ -11167,9 +11310,12 @@ class AparteClient {
|
|
|
11167
11310
|
return;
|
|
11168
11311
|
}
|
|
11169
11312
|
const conversationId = openConversationOf(targetElement) ?? void 0;
|
|
11313
|
+
if (!this._autoReplies(targetElement, conversationId)) return;
|
|
11170
11314
|
const allMessages = targetElement.getMessages?.() ?? [];
|
|
11171
11315
|
const retryIdx = allMessages.findIndex((m) => m.id === messageId);
|
|
11172
11316
|
const retryMsg = retryIdx >= 0 ? allMessages[retryIdx] : void 0;
|
|
11317
|
+
if (retryMsg && retryMsg.role === "assistant" && !isModelReply(retryMsg)) return;
|
|
11318
|
+
if (followedByAHuman(allMessages, messageId)) return;
|
|
11173
11319
|
const sliceEnd = retryMsg?.role === "user" ? retryIdx + 1 : retryIdx;
|
|
11174
11320
|
const historyMessages = retryIdx >= 0 ? allMessages.slice(0, sliceEnd) : allMessages;
|
|
11175
11321
|
const newMsg = {
|
|
@@ -11192,7 +11338,7 @@ class AparteClient {
|
|
|
11192
11338
|
targetElement,
|
|
11193
11339
|
newMessageId,
|
|
11194
11340
|
provider,
|
|
11195
|
-
[...systemMessages, ...
|
|
11341
|
+
[...systemMessages, ...mergeAdjacentMessages(chatMessages)],
|
|
11196
11342
|
config.defaultModel || "",
|
|
11197
11343
|
authConfig,
|
|
11198
11344
|
{
|
|
@@ -11202,7 +11348,7 @@ class AparteClient {
|
|
|
11202
11348
|
...asked2 ? { userMessage: { content: messageWireText(asked2), messageId: asked2.id } } : {},
|
|
11203
11349
|
rebuild: async () => [
|
|
11204
11350
|
...this._systemMessages(),
|
|
11205
|
-
...
|
|
11351
|
+
...mergeAdjacentMessages(this._messagesToChatMessages(this._current(targetElement, historyMessages)))
|
|
11206
11352
|
]
|
|
11207
11353
|
}
|
|
11208
11354
|
);
|
|
@@ -11237,6 +11383,8 @@ class AparteClient {
|
|
|
11237
11383
|
return;
|
|
11238
11384
|
}
|
|
11239
11385
|
const conversationId = openConversationOf(targetElement) ?? void 0;
|
|
11386
|
+
if (!this._autoReplies(targetElement, conversationId)) return;
|
|
11387
|
+
if (followedByAHuman(targetElement.getMessages?.() ?? [], messageId)) return;
|
|
11240
11388
|
const before = targetElement.getMessages?.().find((m) => m.id === messageId);
|
|
11241
11389
|
targetElement.updateMessage?.(messageId, {
|
|
11242
11390
|
content: newContent,
|
|
@@ -11272,7 +11420,7 @@ class AparteClient {
|
|
|
11272
11420
|
targetElement,
|
|
11273
11421
|
newMessageId,
|
|
11274
11422
|
provider,
|
|
11275
|
-
[...systemMessages, ...
|
|
11423
|
+
[...systemMessages, ...mergeAdjacentMessages(chatMessages)],
|
|
11276
11424
|
config.defaultModel || "",
|
|
11277
11425
|
authConfig,
|
|
11278
11426
|
{
|
|
@@ -11284,7 +11432,7 @@ class AparteClient {
|
|
|
11284
11432
|
},
|
|
11285
11433
|
rebuild: async () => [
|
|
11286
11434
|
...this._systemMessages(),
|
|
11287
|
-
...
|
|
11435
|
+
...mergeAdjacentMessages(this._messagesToChatMessages(this._current(targetElement, historyMessages)))
|
|
11288
11436
|
]
|
|
11289
11437
|
}
|
|
11290
11438
|
);
|
|
@@ -11432,7 +11580,7 @@ class AparteClient {
|
|
|
11432
11580
|
* What the model reads in place of everything before a checkpoint: the summary, as a
|
|
11433
11581
|
* `user` message under the same preamble a legacy compaction message gets, so it is
|
|
11434
11582
|
* context and not something the person said. It may sit right before a user turn;
|
|
11435
|
-
* `
|
|
11583
|
+
* `mergeAdjacentMessages` joins the two where the history is assembled.
|
|
11436
11584
|
*/
|
|
11437
11585
|
_summaryMessage(summary) {
|
|
11438
11586
|
return summary === void 0 ? [] : [summaryMessage(summary)];
|
|
@@ -11446,12 +11594,7 @@ class AparteClient {
|
|
|
11446
11594
|
_warnedNoModel = false;
|
|
11447
11595
|
async _handleSend(event) {
|
|
11448
11596
|
const { content, modelId, providerId: explicitProviderId } = event.detail;
|
|
11449
|
-
|
|
11450
|
-
console.warn(
|
|
11451
|
-
"[AparteClient] Send refused: requireModelSelection is on and no model is selected yet. The composer blocks this, but this send did not come from it — disable your own send affordances while `hasSelectedModel()` is false."
|
|
11452
|
-
);
|
|
11453
|
-
return;
|
|
11454
|
-
}
|
|
11597
|
+
const modelMissing = this._config.getRequireModelSelection() && !this._config.hasSelectedModel() && !modelId;
|
|
11455
11598
|
let targetElement = null;
|
|
11456
11599
|
const targetId = event.detail?.targetId;
|
|
11457
11600
|
if (targetId) {
|
|
@@ -11485,11 +11628,19 @@ class AparteClient {
|
|
|
11485
11628
|
return;
|
|
11486
11629
|
}
|
|
11487
11630
|
const conversationId = openConversationOf(targetElement) ?? void 0;
|
|
11631
|
+
const autoReply = this._autoReplies(targetElement, conversationId);
|
|
11632
|
+
if (modelMissing && autoReply) {
|
|
11633
|
+
console.warn(
|
|
11634
|
+
"[AparteClient] Send refused: requireModelSelection is on and no model is selected yet. The composer blocks this, but this send did not come from it — disable your own send affordances while `hasSelectedModel()` is false."
|
|
11635
|
+
);
|
|
11636
|
+
return;
|
|
11637
|
+
}
|
|
11488
11638
|
this._closeDeferred(targetElement);
|
|
11489
11639
|
if (this.options.echoUserMessage !== false && event.detail?.echoed !== true) {
|
|
11490
11640
|
const echoFiles = Array.isArray(event.detail?.files) ? event.detail.files : [];
|
|
11641
|
+
const echoedId = uuid();
|
|
11491
11642
|
targetElement.appendMessage?.({
|
|
11492
|
-
id:
|
|
11643
|
+
id: echoedId,
|
|
11493
11644
|
role: "user",
|
|
11494
11645
|
content,
|
|
11495
11646
|
timestamp: Date.now(),
|
|
@@ -11497,10 +11648,14 @@ class AparteClient {
|
|
|
11497
11648
|
...event.detail?.tokens?.length ? { tokens: event.detail.tokens } : {},
|
|
11498
11649
|
...event.detail?.meta ? { metadata: event.detail.meta } : {}
|
|
11499
11650
|
});
|
|
11500
|
-
if (event.detail && typeof event.detail === "object")
|
|
11651
|
+
if (event.detail && typeof event.detail === "object") {
|
|
11652
|
+
event.detail.echoed = true;
|
|
11653
|
+
event.detail.messageId = echoedId;
|
|
11654
|
+
}
|
|
11501
11655
|
}
|
|
11656
|
+
if (!autoReply) return;
|
|
11502
11657
|
const shown2 = targetElement.getMessages?.().at(-1);
|
|
11503
|
-
const sentId = shown2?.role === "user" ? shown2.id : void 0;
|
|
11658
|
+
const sentId = typeof event.detail?.messageId === "string" ? event.detail.messageId : shown2?.role === "user" ? shown2.id : void 0;
|
|
11504
11659
|
const messageId = uuid();
|
|
11505
11660
|
const config = this._config.getModelConfig();
|
|
11506
11661
|
const providerId = explicitProviderId || config.defaultProvider;
|
|
@@ -11542,7 +11697,7 @@ class AparteClient {
|
|
|
11542
11697
|
const filesToInject = this._selectFilesToInject(rawFiles);
|
|
11543
11698
|
const contentParts = filesToInject.length > 0 ? await this._filesToContentParts(filesToInject) : [];
|
|
11544
11699
|
fileParts = contentParts.length > 0 ? contentParts : void 0;
|
|
11545
|
-
messages = this._buildMessages(content, targetElement, fileParts);
|
|
11700
|
+
messages = this._buildMessages(content, targetElement, fileParts, sentId);
|
|
11546
11701
|
} catch (error) {
|
|
11547
11702
|
this._handleLifecycleError(targetElement, messageId, AparteError.from(error, AparteErrorCode.UNKNOWN_ERROR));
|
|
11548
11703
|
return;
|
|
@@ -11555,7 +11710,7 @@ class AparteClient {
|
|
|
11555
11710
|
modelId || config.defaultModel || "",
|
|
11556
11711
|
authConfig,
|
|
11557
11712
|
{
|
|
11558
|
-
rebuild: async () => this._buildMessages(content, targetElement, fileParts),
|
|
11713
|
+
rebuild: async () => this._buildMessages(content, targetElement, fileParts, sentId),
|
|
11559
11714
|
...rawFiles.length > 0 ? { files: rawFiles } : {},
|
|
11560
11715
|
...this._turnMeta(event.detail),
|
|
11561
11716
|
...conversationId ? { conversationId } : {},
|
|
@@ -11566,27 +11721,32 @@ class AparteClient {
|
|
|
11566
11721
|
/**
|
|
11567
11722
|
* Build the initial messages array, prepending system prompts and conversation history.
|
|
11568
11723
|
*/
|
|
11569
|
-
_buildMessages(userContent, target, parts) {
|
|
11724
|
+
_buildMessages(userContent, target, parts, sentId) {
|
|
11570
11725
|
const messages = this._systemMessages();
|
|
11571
11726
|
const historyOption = this.options.history ?? "viewport";
|
|
11572
11727
|
const viewportMessages = target?.getMessages?.() ?? [];
|
|
11573
11728
|
if (historyOption === "viewport") {
|
|
11574
|
-
messages.push(...this._toHistoryMessages(viewportMessages));
|
|
11729
|
+
messages.push(...this._toHistoryMessages(viewportMessages, sentId));
|
|
11575
11730
|
} else if (typeof historyOption === "function") {
|
|
11576
11731
|
messages.push(...historyOption(viewportMessages));
|
|
11577
11732
|
}
|
|
11578
11733
|
messages.push({ role: "user", content: this._userContent(userContent, parts) });
|
|
11579
|
-
return
|
|
11734
|
+
return mergeAdjacentMessages(messages);
|
|
11580
11735
|
}
|
|
11581
11736
|
/** The message being sent, as the request carries it: the text, then the files inlined as parts. */
|
|
11582
11737
|
_userContent(text, parts) {
|
|
11583
11738
|
return parts && parts.length > 0 ? [{ type: "text", text }, ...parts] : text;
|
|
11584
11739
|
}
|
|
11585
|
-
_toHistoryMessages(path) {
|
|
11740
|
+
_toHistoryMessages(path, sentId) {
|
|
11586
11741
|
const { summary, messages } = historyFromCheckpoint(path);
|
|
11742
|
+
const sentAt = sentId === void 0 ? -1 : messages.findIndex((m) => m.id === sentId);
|
|
11587
11743
|
let cutoff = messages.length;
|
|
11588
|
-
|
|
11589
|
-
|
|
11744
|
+
if (sentAt !== -1) {
|
|
11745
|
+
cutoff = sentAt;
|
|
11746
|
+
} else {
|
|
11747
|
+
while (cutoff > 0 && isInFlight(messages[cutoff - 1])) cutoff--;
|
|
11748
|
+
if (cutoff > 0 && messages[cutoff - 1].role === "user") cutoff--;
|
|
11749
|
+
}
|
|
11590
11750
|
return [...this._summaryMessage(summary), ...wireMessages(messages.slice(0, cutoff))];
|
|
11591
11751
|
}
|
|
11592
11752
|
/**
|
|
@@ -12010,7 +12170,7 @@ ${content}
|
|
|
12010
12170
|
const askedAt = before.map((m) => m.role).lastIndexOf("user");
|
|
12011
12171
|
const historyOption = this.options.history ?? "viewport";
|
|
12012
12172
|
const history = historyOption === "viewport" ? this._toHistoryMessages(before) : typeof historyOption === "function" ? historyOption(before) : [];
|
|
12013
|
-
return
|
|
12173
|
+
return mergeAdjacentMessages([
|
|
12014
12174
|
...this._systemMessages(),
|
|
12015
12175
|
...history,
|
|
12016
12176
|
...askedAt >= 0 ? wireMessages([before[askedAt]]) : []
|
|
@@ -12023,7 +12183,7 @@ ${content}
|
|
|
12023
12183
|
*/
|
|
12024
12184
|
_closeDeferred(targetElement) {
|
|
12025
12185
|
const messages = targetElement.getMessages?.() ?? [];
|
|
12026
|
-
const last = [...messages].reverse().find(
|
|
12186
|
+
const last = [...messages].reverse().find(isModelReply);
|
|
12027
12187
|
const rows = Boolean(last?.segments?.some(isOpenDeferred));
|
|
12028
12188
|
if (!last || !rows && !last.deferredCalls?.length) return;
|
|
12029
12189
|
targetElement.updateMessage?.(last.id, {
|
|
@@ -12055,8 +12215,9 @@ ${content}
|
|
|
12055
12215
|
const host2 = typeof target === "string" ? this._byId(target) : target ?? this.options.targetResolver?.() ?? null;
|
|
12056
12216
|
const targetElement = host2 ? this._asRenderTarget(host2) : this._scanForTarget();
|
|
12057
12217
|
if (!targetElement) return false;
|
|
12218
|
+
if (!this._autoReplies(targetElement, openConversationOf(targetElement) ?? void 0)) return false;
|
|
12058
12219
|
const messages = targetElement.getMessages?.() ?? [];
|
|
12059
|
-
const last = [...messages].reverse().find(
|
|
12220
|
+
const last = [...messages].reverse().find(isModelReply);
|
|
12060
12221
|
const open = (last?.segments ?? []).filter(isOpenDeferred);
|
|
12061
12222
|
const kept = last?.deferredCalls ?? [];
|
|
12062
12223
|
const ticket = open.find((s) => s.deferred?.ticket)?.deferred?.ticket ?? kept.find((c) => c.ticket)?.ticket;
|
|
@@ -12541,7 +12702,9 @@ const APARTE_DEFAULT_UI_EVENTS = [
|
|
|
12541
12702
|
"aparte-message-aborted",
|
|
12542
12703
|
"aparte-message-paused",
|
|
12543
12704
|
"aparte-message-resumed",
|
|
12544
|
-
"aparte-tool-approval-request"
|
|
12705
|
+
"aparte-tool-approval-request",
|
|
12706
|
+
// an app's write outside a turn, said by the host element or the bare viewport
|
|
12707
|
+
"aparte-transcript-change"
|
|
12545
12708
|
];
|
|
12546
12709
|
const written = /* @__PURE__ */ new WeakMap();
|
|
12547
12710
|
function writeOnce(el2, key, value, write) {
|
|
@@ -12574,10 +12737,6 @@ function applyElementProps(el2, props, transformValue = (value) => value) {
|
|
|
12574
12737
|
}
|
|
12575
12738
|
}
|
|
12576
12739
|
}
|
|
12577
|
-
function isAwaitingReply(message) {
|
|
12578
|
-
if (message.status === "streaming" || message.status === "pending") return true;
|
|
12579
|
-
return message.status === void 0 && message.role === "assistant" && !message.content?.trim() && !message.segments?.length;
|
|
12580
|
-
}
|
|
12581
12740
|
function createSegmentList(opts) {
|
|
12582
12741
|
const { messageId, config } = opts;
|
|
12583
12742
|
let segments = (opts.segments ?? []).reduce((acc, segment) => {
|
|
@@ -12777,99 +12936,102 @@ function deferHydrationOf(ctor) {
|
|
|
12777
12936
|
};
|
|
12778
12937
|
}
|
|
12779
12938
|
export {
|
|
12780
|
-
|
|
12939
|
+
historyFromCheckpoint as $,
|
|
12781
12940
|
APARTE_CONFIG_CHANGE as A,
|
|
12782
|
-
|
|
12783
|
-
|
|
12784
|
-
|
|
12785
|
-
|
|
12786
|
-
|
|
12787
|
-
|
|
12788
|
-
|
|
12789
|
-
|
|
12790
|
-
|
|
12791
|
-
|
|
12792
|
-
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
|
|
12796
|
-
|
|
12797
|
-
|
|
12798
|
-
|
|
12941
|
+
collectRendererStyles as B,
|
|
12942
|
+
contentToText as C,
|
|
12943
|
+
contextConfig as D,
|
|
12944
|
+
copyText as E,
|
|
12945
|
+
createAgentStreamRunner as F,
|
|
12946
|
+
createAparteAgentHandler as G,
|
|
12947
|
+
createAparteChatHandler as H,
|
|
12948
|
+
createModelCatalogue as I,
|
|
12949
|
+
createSegmentList as J,
|
|
12950
|
+
createStreamAdapter as K,
|
|
12951
|
+
declineDefaultRenderers as L,
|
|
12952
|
+
defaultSanitizer as M,
|
|
12953
|
+
deferHydrationOf as N,
|
|
12954
|
+
defineMountedSegmentRenderer as O,
|
|
12955
|
+
defineMountedToolRenderer as P,
|
|
12956
|
+
detachConfig as Q,
|
|
12957
|
+
dispatchChatEvent as R,
|
|
12799
12958
|
SUGGESTIONS_BLOCK_LANGUAGE as S,
|
|
12800
|
-
|
|
12801
|
-
|
|
12802
|
-
|
|
12803
|
-
|
|
12804
|
-
|
|
12805
|
-
|
|
12806
|
-
|
|
12807
|
-
|
|
12959
|
+
escapeAttr as T,
|
|
12960
|
+
escapeHtml as U,
|
|
12961
|
+
estimateTokens as V,
|
|
12962
|
+
estimateWireTokens as W,
|
|
12963
|
+
filesToAttachments as X,
|
|
12964
|
+
formatDuration as Y,
|
|
12965
|
+
getAllRenderers as Z,
|
|
12966
|
+
getSegmentRenderer as _,
|
|
12808
12967
|
APARTE_CONVERSATION_SCHEMA_VERSION as a,
|
|
12809
|
-
|
|
12810
|
-
|
|
12811
|
-
|
|
12812
|
-
|
|
12813
|
-
|
|
12814
|
-
|
|
12815
|
-
|
|
12816
|
-
|
|
12817
|
-
|
|
12818
|
-
|
|
12819
|
-
|
|
12820
|
-
|
|
12821
|
-
|
|
12822
|
-
|
|
12823
|
-
|
|
12824
|
-
|
|
12825
|
-
|
|
12826
|
-
|
|
12827
|
-
|
|
12828
|
-
|
|
12829
|
-
|
|
12830
|
-
|
|
12831
|
-
|
|
12832
|
-
|
|
12833
|
-
|
|
12834
|
-
|
|
12835
|
-
|
|
12836
|
-
|
|
12837
|
-
|
|
12838
|
-
|
|
12839
|
-
|
|
12840
|
-
|
|
12841
|
-
|
|
12842
|
-
|
|
12843
|
-
|
|
12844
|
-
|
|
12845
|
-
|
|
12846
|
-
|
|
12847
|
-
|
|
12848
|
-
|
|
12849
|
-
|
|
12850
|
-
|
|
12851
|
-
|
|
12852
|
-
|
|
12853
|
-
|
|
12854
|
-
|
|
12855
|
-
|
|
12856
|
-
|
|
12857
|
-
|
|
12858
|
-
|
|
12859
|
-
|
|
12860
|
-
|
|
12861
|
-
|
|
12862
|
-
|
|
12863
|
-
|
|
12864
|
-
|
|
12865
|
-
|
|
12866
|
-
|
|
12867
|
-
|
|
12868
|
-
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
|
|
12968
|
+
visibleReply as a$,
|
|
12969
|
+
installDefaultRenderersOnce as a0,
|
|
12970
|
+
installDialogTriggersOnce as a1,
|
|
12971
|
+
isAwaitingReply as a2,
|
|
12972
|
+
isFormatAdapter as a3,
|
|
12973
|
+
isModelReply as a4,
|
|
12974
|
+
isSafeUrl as a5,
|
|
12975
|
+
isSegmentSettled as a6,
|
|
12976
|
+
measureContext as a7,
|
|
12977
|
+
onRenderersChange as a8,
|
|
12978
|
+
overrideSegmentRenderer as a9,
|
|
12979
|
+
chatBoundaryOf as aA,
|
|
12980
|
+
relabelCodeLanguages as aB,
|
|
12981
|
+
relabelCitations as aC,
|
|
12982
|
+
toolCallRenderer as aD,
|
|
12983
|
+
activityRenderer as aE,
|
|
12984
|
+
isMountedRenderer as aF,
|
|
12985
|
+
renderingVersionOf as aG,
|
|
12986
|
+
renderSourceList as aH,
|
|
12987
|
+
mergeSegmentUpdate as aI,
|
|
12988
|
+
toolNameOf as aJ,
|
|
12989
|
+
writeStreamedMarkdown as aK,
|
|
12990
|
+
replaceHighlighted as aL,
|
|
12991
|
+
openConversationOf as aM,
|
|
12992
|
+
toolRendererThatDrew as aN,
|
|
12993
|
+
activityRendererThatDrew as aO,
|
|
12994
|
+
CheckpointStateWatcher as aP,
|
|
12995
|
+
stampSegmentActivity as aQ,
|
|
12996
|
+
stampSegmentOnInsert as aR,
|
|
12997
|
+
stampSegmentOnUpdate as aS,
|
|
12998
|
+
renumberSegments as aT,
|
|
12999
|
+
openSegmentIds as aU,
|
|
13000
|
+
isTerminalStatus as aV,
|
|
13001
|
+
adoptMessageSegments as aW,
|
|
13002
|
+
APARTE_DERIVED_SEGMENTS as aX,
|
|
13003
|
+
rememberConversationStatus as aY,
|
|
13004
|
+
tellConversationStatus as aZ,
|
|
13005
|
+
conversationStatusOf as a_,
|
|
13006
|
+
parseAparteEventStream as aa,
|
|
13007
|
+
parseMarkdownToSegments as ab,
|
|
13008
|
+
pluralize as ac,
|
|
13009
|
+
populateBubbleFromMessage as ad,
|
|
13010
|
+
readableToAsyncIterable as ae,
|
|
13011
|
+
registerDefaultRenderers as af,
|
|
13012
|
+
registerSegmentRenderer as ag,
|
|
13013
|
+
releaseDeferredHydration as ah,
|
|
13014
|
+
renderCitations as ai,
|
|
13015
|
+
renderCodeLanguages as aj,
|
|
13016
|
+
requestUserInput as ak,
|
|
13017
|
+
resolveConfig as al,
|
|
13018
|
+
revokeAttachmentUrls as am,
|
|
13019
|
+
runSubAgent as an,
|
|
13020
|
+
runWithConfig as ao,
|
|
13021
|
+
segmentDuration as ap,
|
|
13022
|
+
segmentTiming as aq,
|
|
13023
|
+
setupSuggestionBlocks as ar,
|
|
13024
|
+
startSubAgent as as,
|
|
13025
|
+
subscribeConfigChange as at,
|
|
13026
|
+
toToolCallView as au,
|
|
13027
|
+
toolRefusal as av,
|
|
13028
|
+
unregisterSegmentRenderer as aw,
|
|
13029
|
+
uuid as ax,
|
|
13030
|
+
withoutAbandonedTurns as ay,
|
|
13031
|
+
gateGlide as az,
|
|
12872
13032
|
APARTE_DEFAULT_BUBBLE_ACTIONS as b,
|
|
13033
|
+
usageTokens as b0,
|
|
13034
|
+
inRenderedContent as b1,
|
|
12873
13035
|
APARTE_DEFAULT_HOST_HANDLERS as c,
|
|
12874
13036
|
APARTE_DEFAULT_ICON_FALLBACKS as d,
|
|
12875
13037
|
APARTE_DEFAULT_LOCALE as e,
|
|
@@ -12890,9 +13052,9 @@ export {
|
|
|
12890
13052
|
aparteGlobalConfig as t,
|
|
12891
13053
|
applyElementProps as u,
|
|
12892
13054
|
attachConfig as v,
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
|
|
13055
|
+
authorTypeOf as w,
|
|
13056
|
+
buildApprovalPanel as x,
|
|
13057
|
+
buildElicitationPanel as y,
|
|
13058
|
+
chatIdOf as z
|
|
12897
13059
|
};
|
|
12898
|
-
//# sourceMappingURL=defer-hydration-
|
|
13060
|
+
//# sourceMappingURL=defer-hydration-Dm6F4kq6.js.map
|