@aparte/core 1.11.0 → 1.12.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.
Files changed (57) hide show
  1. package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -1
  2. package/dist/components/chat/aparte-chat.d.ts +4 -0
  3. package/dist/components/chat/aparte-chat.d.ts.map +1 -1
  4. package/dist/components/composer/aparte-composer-cancel.d.ts.map +1 -1
  5. package/dist/components/composer/aparte-composer-input.d.ts.map +1 -1
  6. package/dist/components/composer/aparte-composer-send.d.ts.map +1 -1
  7. package/dist/components/composer/aparte-composer.d.ts +82 -0
  8. package/dist/components/composer/aparte-composer.d.ts.map +1 -1
  9. package/dist/components/composer/index.d.ts +1 -1
  10. package/dist/components/composer/index.d.ts.map +1 -1
  11. package/dist/components/conversation-list/aparte-conversation-list.d.ts +10 -0
  12. package/dist/components/conversation-list/aparte-conversation-list.d.ts.map +1 -1
  13. package/dist/components/index.d.ts +1 -1
  14. package/dist/components/index.d.ts.map +1 -1
  15. package/dist/config/aparte-config.d.ts +55 -1
  16. package/dist/config/aparte-config.d.ts.map +1 -1
  17. package/dist/config/index.d.ts +2 -0
  18. package/dist/config/index.d.ts.map +1 -1
  19. package/dist/config/locale.d.ts +10 -0
  20. package/dist/config/locale.d.ts.map +1 -1
  21. package/dist/config/model-catalogue.d.ts +35 -0
  22. package/dist/config/model-catalogue.d.ts.map +1 -0
  23. package/dist/context/checkpoint.d.ts +4 -0
  24. package/dist/context/checkpoint.d.ts.map +1 -1
  25. package/dist/conversations/conversation-manager.d.ts.map +1 -1
  26. package/dist/custom-elements.json +5849 -5387
  27. package/dist/{defer-hydration-2oPv7cU0.js → defer-hydration-DfYJjWtk.js} +214 -86
  28. package/dist/defer-hydration-DfYJjWtk.js.map +1 -0
  29. package/dist/elicitation/index.d.ts +1 -1
  30. package/dist/elicitation/index.d.ts.map +1 -1
  31. package/dist/elicitation/types.d.ts +18 -0
  32. package/dist/elicitation/types.d.ts.map +1 -1
  33. package/dist/generated/element-attributes.d.ts +2 -0
  34. package/dist/generated/element-attributes.d.ts.map +1 -1
  35. package/dist/index.css +1 -1
  36. package/dist/index.d.ts +5 -3
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +302 -82
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.node.d.ts +5 -3
  41. package/dist/index.node.d.ts.map +1 -1
  42. package/dist/index.node.js +54 -53
  43. package/dist/index.node.js.map +1 -1
  44. package/dist/interop/element-props.d.ts +1 -1
  45. package/dist/interop/element-props.d.ts.map +1 -1
  46. package/dist/types/event-map.d.ts +1 -0
  47. package/dist/types/event-map.d.ts.map +1 -1
  48. package/dist/types/events.d.ts +7 -0
  49. package/dist/types/events.d.ts.map +1 -1
  50. package/dist/types/imperative-api.d.ts +6 -1
  51. package/dist/types/imperative-api.d.ts.map +1 -1
  52. package/dist/types/index.d.ts +1 -1
  53. package/dist/types/index.d.ts.map +1 -1
  54. package/dist/types/models.d.ts +24 -0
  55. package/dist/types/models.d.ts.map +1 -1
  56. package/package.json +2 -2
  57. package/dist/defer-hydration-2oPv7cU0.js.map +0 -1
@@ -98,6 +98,9 @@ const APARTE_DEFAULT_LOCALE = {
98
98
  elicitationOtherLabel: "Custom answer",
99
99
  submitButton: "Submit",
100
100
  stopButton: "Stop",
101
+ queueLabel: "Sent when the reply ends",
102
+ queueEdit: "Edit",
103
+ queueRemove: "Remove",
101
104
  elicitationRecommended: "Recommended",
102
105
  elicitationSkip: "Skip",
103
106
  elicitationHide: "Hide for now",
@@ -5409,6 +5412,7 @@ class AparteConfig {
5409
5412
  _modelConfig = {};
5410
5413
  /** Opt-in: gate the composer (block send + grey out) until a model is selected. */
5411
5414
  _requireModelSelection = false;
5415
+ _queueWhileStreaming = false;
5412
5416
  /** Host policy for the elicitation panel's free-text escape — see {@link setElicitationOptions}. */
5413
5417
  _elicitationAllowOther = true;
5414
5418
  _elicitationLayout = "stepped";
@@ -5444,6 +5448,8 @@ class AparteConfig {
5444
5448
  * documents ("used to resolve WHICH instance presents").
5445
5449
  */
5446
5450
  _elicitationPresenters = [];
5451
+ /** See {@link observeElicitations}. */
5452
+ _elicitationObservers = /* @__PURE__ */ new Set();
5447
5453
  /** Warn once per config, not once per request — a tool loop can ask repeatedly. */
5448
5454
  _warnedNoPresenter = false;
5449
5455
  /**
@@ -6406,6 +6412,32 @@ class AparteConfig {
6406
6412
  getRequireModelSelection() {
6407
6413
  return this._requireModelSelection;
6408
6414
  }
6415
+ /**
6416
+ * Opt-in: a message written while a reply streams waits for it instead of being refused.
6417
+ *
6418
+ * Enter in the composer's field puts the draft in a queue shown above the field, each entry
6419
+ * with a button to take it back into the field and one to remove it. When the reply ends
6420
+ * well (`aparte-message-done`) the first queued message is sent, through the same
6421
+ * `aparte-before-send` and `aparte-send` as one sent by hand, and the next one waits for the
6422
+ * reply to it. After a Stop or an error nothing is sent: what was queued comes back into
6423
+ * the field. The composer's `queue()` does the same for a button of your own.
6424
+ *
6425
+ * Off by default: Enter during a reply then does nothing, and the button stays Stop.
6426
+ *
6427
+ * @example
6428
+ * ```ts
6429
+ * aparteGlobalConfig.setQueueWhileStreaming(true);
6430
+ * ```
6431
+ */
6432
+ setQueueWhileStreaming(on) {
6433
+ if (this._queueWhileStreaming === on) return;
6434
+ this._queueWhileStreaming = on;
6435
+ this._notify();
6436
+ }
6437
+ /** Whether a message written during a reply waits for it (see {@link setQueueWhileStreaming}). */
6438
+ getQueueWhileStreaming() {
6439
+ return this._queueWhileStreaming;
6440
+ }
6409
6441
  /**
6410
6442
  * Get the currently selected model object, if available synchronously.
6411
6443
  * Returns undefined if no provider/model is selected, or if the provider's
@@ -7149,6 +7181,7 @@ class AparteConfig {
7149
7181
  return Promise.reject(new AparteElicitationAbortError("no-presenter"));
7150
7182
  }
7151
7183
  if (request.signal?.aborted) return Promise.reject(new AparteElicitationAbortError("aborted"));
7184
+ if (this._elicitationObservers.size > 0) return this._presentObserved(presenter, request);
7152
7185
  const answer = presenter(request);
7153
7186
  const signal = request.signal;
7154
7187
  if (!signal) return answer;
@@ -7158,6 +7191,78 @@ class AparteConfig {
7158
7191
  answer.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
7159
7192
  });
7160
7193
  }
7194
+ /**
7195
+ * Be handed every question and approval a chat of this config asks, as it is put on screen,
7196
+ * with a way to answer it from anywhere: an inbox of what waits for the person across
7197
+ * conversations, a notification with its own buttons.
7198
+ *
7199
+ * The chat still asks: its panel is up as usual, and the person can answer there.
7200
+ * `respond(result)` answers in its place, with what the panel would have resolved (see
7201
+ * {@link AparteElicitationPending}); the request resolves with it and the panel is taken
7202
+ * down. Whichever answers first is the answer. `settled` tells when it no longer waits,
7203
+ * however it ended, so the app takes its own copy down. `request.conversationId` says which
7204
+ * conversation asked. A question waiting behind another in the same chat reaches you when
7205
+ * its turn comes; an approval a client's `approvalResolver` decides never reaches the chat,
7206
+ * so never here either. A listener that throws is reported at the console and harms no one.
7207
+ *
7208
+ * Returns the function that stops it.
7209
+ *
7210
+ * @example
7211
+ * ```ts
7212
+ * aparteGlobalConfig.observeElicitations((pending) => {
7213
+ * inbox.add(pending.request, (answer) => pending.respond(answer));
7214
+ * void pending.settled.then(() => inbox.remove(pending.request));
7215
+ * });
7216
+ * ```
7217
+ */
7218
+ observeElicitations(listener) {
7219
+ this._elicitationObservers.add(listener);
7220
+ return () => {
7221
+ this._elicitationObservers.delete(listener);
7222
+ };
7223
+ }
7224
+ /**
7225
+ * {@link _present} with someone outside the chat able to answer: the presenter is handed a
7226
+ * signal of its own, fired by a stop of the request as before and by an answer from outside,
7227
+ * so its panel goes away whichever way the request ends.
7228
+ */
7229
+ _presentObserved(presenter, request) {
7230
+ const takeDown = new AbortController();
7231
+ let resolveSettled;
7232
+ const settled2 = new Promise((resolve) => {
7233
+ resolveSettled = resolve;
7234
+ });
7235
+ return new Promise((resolve, reject) => {
7236
+ let done = false;
7237
+ const stop = request.signal;
7238
+ const finish = (settle2) => {
7239
+ if (done) return;
7240
+ done = true;
7241
+ stop?.removeEventListener("abort", onStop);
7242
+ settle2();
7243
+ if (!takeDown.signal.aborted) takeDown.abort();
7244
+ resolveSettled();
7245
+ };
7246
+ const onStop = () => finish(() => reject(new AparteElicitationAbortError("aborted")));
7247
+ stop?.addEventListener("abort", onStop, { once: true });
7248
+ presenter({ ...request, signal: takeDown.signal }).then(
7249
+ (answer) => finish(() => resolve(answer)),
7250
+ (error) => finish(() => reject(error))
7251
+ );
7252
+ const pending2 = {
7253
+ request,
7254
+ respond: (answer) => finish(() => resolve(answer)),
7255
+ settled: settled2
7256
+ };
7257
+ for (const listener of [...this._elicitationObservers]) {
7258
+ try {
7259
+ listener(pending2);
7260
+ } catch (error) {
7261
+ console.error("[aparte] an observeElicitations listener threw; the question is still asked.", error);
7262
+ }
7263
+ }
7264
+ });
7265
+ }
7161
7266
  /**
7162
7267
  * Put the configuration back to its defaults: the providers and the selected model,
7163
7268
  * the tools with their renderers and summaries, the tool-line provider, the step labels, the renderers and render hooks, the
@@ -7186,6 +7291,7 @@ class AparteConfig {
7186
7291
  this._conversationManager = void 0;
7187
7292
  this._elicitationPresenters = [];
7188
7293
  this._elicitationQueue.clear();
7294
+ this._elicitationObservers.clear();
7189
7295
  this._locale = APARTE_DEFAULT_LOCALE;
7190
7296
  this._actions = [];
7191
7297
  this._sanitizer = defaultSanitizer;
@@ -7210,6 +7316,7 @@ class AparteConfig {
7210
7316
  this._runEventObservers = [];
7211
7317
  this._modelConfig = {};
7212
7318
  this._requireModelSelection = false;
7319
+ this._queueWhileStreaming = false;
7213
7320
  this._elicitationAllowOther = true;
7214
7321
  this._elicitationLayout = "stepped";
7215
7322
  this._elicitationAnswerOnClick = true;
@@ -7256,6 +7363,19 @@ function subscribeConfigChange(el2, handler) {
7256
7363
  window.addEventListener(APARTE_CONFIG_CHANGE, listener);
7257
7364
  return () => window.removeEventListener(APARTE_CONFIG_CHANGE, listener);
7258
7365
  }
7366
+ function createModelCatalogue(options) {
7367
+ const { models, ...metadata } = options;
7368
+ return {
7369
+ id: metadata.id,
7370
+ getMetadata: () => ({ ...metadata }),
7371
+ getModels: () => [...models],
7372
+ chat: () => Promise.reject(new AparteError(
7373
+ `"${metadata.id}" is a model catalogue: it lists models and runs none. The turns of this chat have to run elsewhere, through a stream runner (createAgentStreamRunner for a server loop).`,
7374
+ AparteErrorCode.PROVIDER_MISCONFIGURED,
7375
+ { providerId: metadata.id }
7376
+ ))
7377
+ };
7378
+ }
7259
7379
  const SUGGESTIONS_BLOCK_LANGUAGE = "suggestions";
7260
7380
  const SPACES = /[\p{Z}\s]+/gu;
7261
7381
  const DRAWS_NOTHING = /[\p{Cc}\p{Co}\p{Cn}\p{Cs}\u2800]|(?!(?:\u200C|\u200D|\uFE0E|\uFE0F))\p{Default_Ignorable_Code_Point}/u;
@@ -7455,7 +7575,10 @@ function applyRetention(messages, tree, maxMessages) {
7455
7575
  for (let i = messages.length - 1; i >= 0; i--) {
7456
7576
  const own = messages[i].contextSummary;
7457
7577
  if (!own) continue;
7458
- if (i < cutIndex) inherited = { ...own, count: own.count + (cutIndex - i) };
7578
+ if (i < cutIndex) {
7579
+ const { includesSelf, ...rest } = own;
7580
+ inherited = { ...rest, count: own.count + (cutIndex - i) - (includesSelf ? 1 : 0) };
7581
+ }
7459
7582
  break;
7460
7583
  }
7461
7584
  if (first && inherited) trimmedFlat[0] = { ...first, contextSummary: inherited };
@@ -9644,8 +9767,11 @@ class AparteChatHost {
9644
9767
  }
9645
9768
  function historyFromCheckpoint(path) {
9646
9769
  for (let i = path.length - 1; i >= 0; i--) {
9647
- const summary = path[i].contextSummary?.summary;
9648
- if (summary !== void 0) return { summary, messages: path.slice(i) };
9770
+ const checkpoint = path[i].contextSummary;
9771
+ if (checkpoint?.summary === void 0) continue;
9772
+ const question = i === path.length - 1 && path[i].role === "user";
9773
+ const from = checkpoint.includesSelf === true && !question ? i + 1 : i;
9774
+ return { summary: checkpoint.summary, messages: path.slice(from) };
9649
9775
  }
9650
9776
  return { messages: path };
9651
9777
  }
@@ -12366,6 +12492,7 @@ function isDefaultOn(el2, name) {
12366
12492
  }
12367
12493
  const APARTE_DEFAULT_UI_EVENTS = [
12368
12494
  // <aparte-composer> and its parts
12495
+ "aparte-before-send",
12369
12496
  "aparte-send",
12370
12497
  "aparte-cancel",
12371
12498
  "aparte-composer-change",
@@ -12650,7 +12777,7 @@ function deferHydrationOf(ctor) {
12650
12777
  };
12651
12778
  }
12652
12779
  export {
12653
- installDialogTriggersOnce as $,
12780
+ installDefaultRenderersOnce as $,
12654
12781
  APARTE_CONFIG_CHANGE as A,
12655
12782
  contentToText as B,
12656
12783
  contextConfig as C,
@@ -12658,89 +12785,90 @@ export {
12658
12785
  createAgentStreamRunner as E,
12659
12786
  createAparteAgentHandler as F,
12660
12787
  createAparteChatHandler as G,
12661
- createSegmentList as H,
12662
- createStreamAdapter as I,
12663
- declineDefaultRenderers as J,
12664
- defaultSanitizer as K,
12665
- deferHydrationOf as L,
12666
- defineMountedSegmentRenderer as M,
12667
- defineMountedToolRenderer as N,
12668
- detachConfig as O,
12669
- dispatchChatEvent as P,
12670
- escapeAttr as Q,
12671
- escapeHtml as R,
12788
+ createModelCatalogue as H,
12789
+ createSegmentList as I,
12790
+ createStreamAdapter as J,
12791
+ declineDefaultRenderers as K,
12792
+ defaultSanitizer as L,
12793
+ deferHydrationOf as M,
12794
+ defineMountedSegmentRenderer as N,
12795
+ defineMountedToolRenderer as O,
12796
+ detachConfig as P,
12797
+ dispatchChatEvent as Q,
12798
+ escapeAttr as R,
12672
12799
  SUGGESTIONS_BLOCK_LANGUAGE as S,
12673
- estimateTokens as T,
12674
- estimateWireTokens as U,
12675
- filesToAttachments as V,
12676
- formatDuration as W,
12677
- getAllRenderers as X,
12678
- getSegmentRenderer as Y,
12679
- historyFromCheckpoint as Z,
12680
- installDefaultRenderersOnce as _,
12800
+ escapeHtml as T,
12801
+ estimateTokens as U,
12802
+ estimateWireTokens as V,
12803
+ filesToAttachments as W,
12804
+ formatDuration as X,
12805
+ getAllRenderers as Y,
12806
+ getSegmentRenderer as Z,
12807
+ historyFromCheckpoint as _,
12681
12808
  APARTE_CONVERSATION_SCHEMA_VERSION as a,
12682
- isAwaitingReply as a0,
12683
- isFormatAdapter as a1,
12684
- isSafeUrl as a2,
12685
- isSegmentSettled as a3,
12686
- measureContext as a4,
12687
- onRenderersChange as a5,
12688
- overrideSegmentRenderer as a6,
12689
- parseAparteEventStream as a7,
12690
- parseMarkdownToSegments as a8,
12691
- pluralize as a9,
12692
- toolCallRenderer as aA,
12693
- activityRenderer as aB,
12694
- isMountedRenderer as aC,
12695
- renderingVersionOf as aD,
12696
- renderSourceList as aE,
12697
- mergeSegmentUpdate as aF,
12698
- toolNameOf as aG,
12699
- writeStreamedMarkdown as aH,
12700
- replaceHighlighted as aI,
12701
- toolRendererThatDrew as aJ,
12702
- activityRendererThatDrew as aK,
12703
- CheckpointStateWatcher as aL,
12704
- stampSegmentActivity as aM,
12705
- stampSegmentOnInsert as aN,
12706
- stampSegmentOnUpdate as aO,
12707
- renumberSegments as aP,
12708
- openSegmentIds as aQ,
12709
- isTerminalStatus as aR,
12710
- adoptMessageSegments as aS,
12711
- APARTE_DERIVED_SEGMENTS as aT,
12712
- rememberConversationStatus as aU,
12713
- tellConversationStatus as aV,
12714
- conversationStatusOf as aW,
12715
- visibleReply as aX,
12716
- usageTokens as aY,
12717
- inRenderedContent as aZ,
12718
- populateBubbleFromMessage as aa,
12719
- readableToAsyncIterable as ab,
12720
- registerDefaultRenderers as ac,
12721
- registerSegmentRenderer as ad,
12722
- releaseDeferredHydration as ae,
12723
- renderCitations as af,
12724
- renderCodeLanguages as ag,
12725
- requestUserInput as ah,
12726
- resolveConfig as ai,
12727
- revokeAttachmentUrls as aj,
12728
- runSubAgent as ak,
12729
- runWithConfig as al,
12730
- segmentDuration as am,
12731
- segmentTiming as an,
12732
- setupSuggestionBlocks as ao,
12733
- startSubAgent as ap,
12734
- subscribeConfigChange as aq,
12735
- toToolCallView as ar,
12736
- toolRefusal as as,
12737
- unregisterSegmentRenderer as at,
12738
- uuid as au,
12739
- withoutAbandonedTurns as av,
12740
- gateGlide as aw,
12741
- chatBoundaryOf as ax,
12742
- relabelCodeLanguages as ay,
12743
- relabelCitations as az,
12809
+ installDialogTriggersOnce as a0,
12810
+ isAwaitingReply as a1,
12811
+ isFormatAdapter as a2,
12812
+ isSafeUrl as a3,
12813
+ isSegmentSettled as a4,
12814
+ measureContext as a5,
12815
+ onRenderersChange as a6,
12816
+ overrideSegmentRenderer as a7,
12817
+ parseAparteEventStream as a8,
12818
+ parseMarkdownToSegments as a9,
12819
+ relabelCitations as aA,
12820
+ toolCallRenderer as aB,
12821
+ activityRenderer as aC,
12822
+ isMountedRenderer as aD,
12823
+ renderingVersionOf as aE,
12824
+ renderSourceList as aF,
12825
+ mergeSegmentUpdate as aG,
12826
+ toolNameOf as aH,
12827
+ writeStreamedMarkdown as aI,
12828
+ replaceHighlighted as aJ,
12829
+ toolRendererThatDrew as aK,
12830
+ activityRendererThatDrew as aL,
12831
+ CheckpointStateWatcher as aM,
12832
+ stampSegmentActivity as aN,
12833
+ stampSegmentOnInsert as aO,
12834
+ stampSegmentOnUpdate as aP,
12835
+ renumberSegments as aQ,
12836
+ openSegmentIds as aR,
12837
+ isTerminalStatus as aS,
12838
+ adoptMessageSegments as aT,
12839
+ APARTE_DERIVED_SEGMENTS as aU,
12840
+ rememberConversationStatus as aV,
12841
+ tellConversationStatus as aW,
12842
+ conversationStatusOf as aX,
12843
+ visibleReply as aY,
12844
+ usageTokens as aZ,
12845
+ inRenderedContent as a_,
12846
+ pluralize as aa,
12847
+ populateBubbleFromMessage as ab,
12848
+ readableToAsyncIterable as ac,
12849
+ registerDefaultRenderers as ad,
12850
+ registerSegmentRenderer as ae,
12851
+ releaseDeferredHydration as af,
12852
+ renderCitations as ag,
12853
+ renderCodeLanguages as ah,
12854
+ requestUserInput as ai,
12855
+ resolveConfig as aj,
12856
+ revokeAttachmentUrls as ak,
12857
+ runSubAgent as al,
12858
+ runWithConfig as am,
12859
+ segmentDuration as an,
12860
+ segmentTiming as ao,
12861
+ setupSuggestionBlocks as ap,
12862
+ startSubAgent as aq,
12863
+ subscribeConfigChange as ar,
12864
+ toToolCallView as as,
12865
+ toolRefusal as at,
12866
+ unregisterSegmentRenderer as au,
12867
+ uuid as av,
12868
+ withoutAbandonedTurns as aw,
12869
+ gateGlide as ax,
12870
+ chatBoundaryOf as ay,
12871
+ relabelCodeLanguages as az,
12744
12872
  APARTE_DEFAULT_BUBBLE_ACTIONS as b,
12745
12873
  APARTE_DEFAULT_HOST_HANDLERS as c,
12746
12874
  APARTE_DEFAULT_ICON_FALLBACKS as d,
@@ -12767,4 +12895,4 @@ export {
12767
12895
  chatIdOf as y,
12768
12896
  collectRendererStyles as z
12769
12897
  };
12770
- //# sourceMappingURL=defer-hydration-2oPv7cU0.js.map
12898
+ //# sourceMappingURL=defer-hydration-DfYJjWtk.js.map