@assistant-ui/core 0.2.21 → 0.2.22
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/adapters/attachment.d.ts.map +1 -1
- package/dist/adapters/speech.d.ts.map +1 -1
- package/dist/adapters/speech.js +9 -2
- package/dist/adapters/speech.js.map +1 -1
- package/dist/adapters/voice.d.ts.map +1 -1
- package/dist/adapters/voice.js +13 -5
- package/dist/adapters/voice.js.map +1 -1
- package/dist/internal.d.ts +3 -1
- package/dist/internal.js +3 -1
- package/dist/model-context/frame/host.d.ts +1 -0
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +5 -0
- package/dist/model-context/frame/host.js.map +1 -1
- package/dist/model-context/frame/provider.d.ts.map +1 -1
- package/dist/model-context/frame/provider.js +1 -0
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/model-context/interactable-composer-metadata.js.map +1 -1
- package/dist/react/AssistantProvider.js.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +77 -50
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/interactable-model-context.d.ts.map +1 -1
- package/dist/react/model-context/useInteractable.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.js +13 -13
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerAddAttachment.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useComposerSend.d.ts.map +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.d.ts.map +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
- package/dist/react/primitives/generativeUI/GenerativeUI.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.d.ts +2 -1
- package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +46 -36
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/primitives/part/PartMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +18 -30
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
- package/dist/react/providers/PartByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/PartByIndexProvider.js +18 -30
- package/dist/react/providers/PartByIndexProvider.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +1 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +9 -2
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +49 -8
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +2 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
- package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +1 -1
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useLocalRuntime.d.ts +1 -0
- package/dist/react/runtimes/useLocalRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useLocalRuntime.js +9 -1
- package/dist/react/runtimes/useLocalRuntime.js.map +1 -1
- package/dist/runtime/api/assistant-runtime.d.ts.map +1 -1
- package/dist/runtime/api/attachment-runtime.d.ts.map +1 -1
- package/dist/runtime/api/composer-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.js +4 -4
- package/dist/runtime/api/message-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.js +2 -1
- package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts +4 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +41 -14
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +2 -1
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.js +4 -2
- package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js +2 -2
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/utils/message-repository.d.ts.map +1 -1
- package/dist/runtime/utils/thread-message-like.js +4 -1
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtimes/external-store/external-store-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/local/local-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +5 -2
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/optimistic-state.d.ts +4 -4
- package/dist/runtimes/remote-thread-list/optimistic-state.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/optimistic-state.js +22 -9
- package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +1 -2
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
- package/dist/store/clients/no-op-composer-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
- package/dist/subscribable/subscribable.d.ts +1 -1
- package/dist/subscribable/subscribable.d.ts.map +1 -1
- package/dist/subscribable/subscribable.js +11 -3
- package/dist/subscribable/subscribable.js.map +1 -1
- package/dist/tests/remote-thread-list-test-helpers.d.ts +2 -1
- package/dist/tests/remote-thread-list-test-helpers.d.ts.map +1 -1
- package/dist/tests/remote-thread-list-test-helpers.js +5 -2
- package/dist/tests/remote-thread-list-test-helpers.js.map +1 -1
- package/dist/types/attachment.d.ts +2 -1
- package/dist/types/attachment.d.ts.map +1 -1
- package/dist/types/attachment.js +6 -0
- package/dist/types/attachment.js.map +1 -0
- package/dist/types/message.d.ts +1 -0
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/data-url.d.ts +9 -0
- package/dist/utils/data-url.d.ts.map +1 -0
- package/dist/utils/data-url.js +14 -0
- package/dist/utils/data-url.js.map +1 -0
- package/dist/utils/notify-event-listeners.d.ts +6 -0
- package/dist/utils/notify-event-listeners.d.ts.map +1 -0
- package/dist/utils/notify-event-listeners.js +16 -0
- package/dist/utils/notify-event-listeners.js.map +1 -0
- package/package.json +10 -9
- package/src/adapters/speech.test.ts +88 -0
- package/src/adapters/speech.ts +17 -2
- package/src/adapters/voice.test.ts +130 -0
- package/src/adapters/voice.ts +26 -6
- package/src/internal.ts +5 -0
- package/src/model-context/frame/host.test.ts +100 -0
- package/src/model-context/frame/host.ts +10 -0
- package/src/model-context/frame/provider.test.ts +83 -0
- package/src/model-context/frame/provider.ts +1 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.test.ts +82 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +94 -54
- package/src/react/primitive-hooks/useActionBarCopy.test.ts +79 -0
- package/src/react/primitive-hooks/useActionBarCopy.ts +4 -3
- package/src/react/primitives/chainOfThought/ChainOfThoughtParts.tsx +1 -3
- package/src/react/primitives/message/MessageParts.tsx +48 -35
- package/src/react/providers/ChainOfThoughtPartByIndexProvider.tsx +19 -2
- package/src/react/providers/PartByIndexProvider.tsx +16 -2
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +18 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +1 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +48 -7
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +69 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +1 -1
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.test.ts +16 -0
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +2 -1
- package/src/react/runtimes/external-message-converter.test.tsx +21 -0
- package/src/react/runtimes/external-message-converter.ts +1 -1
- package/src/react/runtimes/useLocalRuntime.test.tsx +56 -0
- package/src/react/runtimes/useLocalRuntime.ts +13 -1
- package/src/runtime/api/message-runtime.test.ts +81 -0
- package/src/runtime/api/message-runtime.ts +4 -6
- package/src/runtime/api/thread-list-item-runtime.ts +6 -1
- package/src/runtime/base/base-composer-runtime-core.ts +77 -31
- package/src/runtime/base/base-thread-runtime-core.ts +2 -1
- package/src/runtime/base/default-edit-composer-runtime-core.ts +4 -2
- package/src/runtime/base/default-thread-composer-runtime-core.ts +2 -2
- package/src/runtime/utils/thread-message-like.ts +1 -0
- package/src/runtimes/local/local-thread-runtime-core.test.ts +150 -1
- package/src/runtimes/local/local-thread-runtime-core.ts +4 -2
- package/src/runtimes/remote-thread-list/optimistic-state.test.ts +63 -0
- package/src/runtimes/remote-thread-list/optimistic-state.ts +49 -17
- package/src/runtimes/remote-thread-list/types.ts +1 -1
- package/src/runtimes/tool-invocations/EDGE_CASES.md +13 -19
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +127 -6
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +4 -2
- package/src/subscribable/subscribable.test.ts +58 -0
- package/src/subscribable/subscribable.ts +13 -3
- package/src/tests/OptimisticState-list-race.test.ts +33 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-order.test.ts +223 -0
- package/src/tests/base-composer-runtime-core-addAttachment.test.ts +44 -0
- package/src/tests/base-composer-runtime-core-send.test.ts +433 -5
- package/src/tests/default-edit-composer-runtime-core.test.ts +43 -5
- package/src/tests/event-subscription-listener-errors.test.ts +205 -0
- package/src/tests/remote-thread-list-test-helpers.ts +14 -7
- package/src/tests/thread-message-like.test.ts +57 -0
- package/src/types/attachment.ts +5 -0
- package/src/types/message.ts +1 -0
- package/src/utils/data-url.test.ts +50 -0
- package/src/utils/data-url.ts +9 -0
- package/src/utils/notify-event-listeners.ts +30 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/attachment-runtime-client.ts"],"mappings":";;;cAmBa,qDAAuB,SAAA;
|
|
1
|
+
{"version":3,"file":"attachment-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/attachment-runtime-client.ts"],"mappings":";;;cAmBa,qDAAuB,SAAA;EAXzB,SAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composer-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/composer-runtime-client.ts"],"mappings":";;;cAkLa,4CAAc,SAAA;;
|
|
1
|
+
{"version":3,"file":"composer-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/composer-runtime-client.ts"],"mappings":";;;cAkLa,4CAAc,SAAA;EAnHZ;IAAE;;EACA;IAAE;;EACR,SAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-part-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/message-part-runtime-client.ts"],"mappings":";;;cAsBa,+CAAiB,SAAA;
|
|
1
|
+
{"version":3,"file":"message-part-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/message-part-runtime-client.ts"],"mappings":";;;cAsBa,+CAAiB,SAAA;EAdnB,SAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/message-runtime-client.ts"],"mappings":";;;cAoJa,2CAAa,SAAA;
|
|
1
|
+
{"version":3,"file":"message-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/message-runtime-client.ts"],"mappings":";;;cAoJa,2CAAa,SAAA;EA/Ff,SAAA;EACI;IAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-list-item-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/thread-list-item-runtime-client.ts"],"mappings":";;;cAyDa,kDAAoB,SAAA;
|
|
1
|
+
{"version":3,"file":"thread-list-item-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/thread-list-item-runtime-client.ts"],"mappings":";;;cAyDa,kDAAoB,SAAA;EA5CtB,SAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-list-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/thread-list-runtime-client.ts"],"mappings":";;;;cAoGa,8CAAgB,SAAA;
|
|
1
|
+
{"version":3,"file":"thread-list-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/thread-list-runtime-client.ts"],"mappings":";;;;cAoGa,8CAAgB,SAAA;EA9DlB,SAAA;EACoB,6BAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/thread-runtime-client.ts"],"mappings":";;;cA0Ia,0CAAY,SAAA;
|
|
1
|
+
{"version":3,"file":"thread-runtime-client.d.ts","names":[],"sources":["../../../src/store/runtime-clients/thread-runtime-client.ts"],"mappings":";;;cA0Ia,0CAAY,SAAA;EAnGd,SAAA"}
|
|
@@ -27,7 +27,7 @@ declare abstract class BaseSubject {
|
|
|
27
27
|
private _connection;
|
|
28
28
|
protected get isConnected(): boolean;
|
|
29
29
|
protected abstract _connect(): Unsubscribe;
|
|
30
|
-
protected notifySubscribers(payload?: unknown): void;
|
|
30
|
+
protected notifySubscribers(payload?: unknown, errorContext?: string): void;
|
|
31
31
|
private _updateConnection;
|
|
32
32
|
subscribe(callback: (payload?: unknown) => void): () => void;
|
|
33
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribable.d.ts","names":[],"sources":["../../src/subscribable/subscribable.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"subscribable.d.ts","names":[],"sources":["../../src/subscribable/subscribable.ts"],"mappings":";;cAGa;KACD,qBAAqB;KAErB;EACV,YAAY,yBAAyB;;KAG3B,sBAAsB,QAAQ,SAAS;EACjD,MAAM;EACN,gBAAgB;;KAGN,mBACV,eAAe,0BACf,SACE,sBAAsB,QAAQ;KAEtB,kBAAkB;EAC5B,OAAO;EACP,SAAS;IAEH,cACE,OAAO,QACP,WAAW,+BACR;;;cA2BA;UACH;EAED,UAAU,uBAAuB;EAKjC,iBAAa;YASV;;uBAwBU;UACZ;UACA;gBAEM;qBAIK,YAAY;YAErB,kBAAkB,mBAAmB;UASvC;EAUD,UAAU,WAAW;;cAWjB,sBAAsB,uBAAuB,eAChD,uBACG,sBAAsB,QAAQ;UAO/B;MALC,QAAI;EAKL,YAAA,SAAS,sBAAsB,SAAS,aAAa;UASvD;EACD,gBAAQ;UAKP;YAQE,YAAQ;;cAWP,mBAAmB,uBAAuB,eAC7C,uBACG,sBAAsB,QAAQ;UAO/B;MALC,QAAI;EAKL,YAAA,SAAS,sBAAsB,SAAS,aAAa;UAKvD;UACA;EACD,gBAAQ;YAaL,YAAQ;;cAUP,0BACX,eAAe,0BACf,eAEQ,uBAEN,sBAAsB,QAAQ,QAC9B,mBAAmB,QAAQ;UAMT;MAJT,QAAI;EAIK,YAAA,SAAS,mBAAmB,QAAQ;EAIjD,YAAQ;EAIR,eAAe,uBAAoB;YAIhC,YAAY;;cA0BX,yBACX,+BACQ;UACY;EAAA,YAAA,QAAQ,kBAAkB;EAIvC;IAzPW,cAAA,OAAA,QAAA,WAAC,+BACR;;EA4PJ,eAAe,uBAAoB;YAIhC,YAAY"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { notifyEventListeners } from "../utils/notify-event-listeners.js";
|
|
1
2
|
//#region src/subscribable/subscribable.ts
|
|
2
3
|
const SKIP_UPDATE = Symbol("skip-update");
|
|
3
4
|
function shallowEqual(objA, objB) {
|
|
4
5
|
if (objA === void 0 && objB === void 0) return true;
|
|
5
6
|
if (objA === void 0) return false;
|
|
6
7
|
if (objB === void 0) return false;
|
|
7
|
-
|
|
8
|
+
const keysA = Object.keys(objA);
|
|
9
|
+
if (keysA.length !== Object.keys(objB).length) return false;
|
|
10
|
+
for (const key of keysA) {
|
|
8
11
|
const valueA = objA[key];
|
|
9
12
|
const valueB = objB[key];
|
|
10
13
|
if (!Object.is(valueA, valueB)) return false;
|
|
@@ -45,7 +48,11 @@ var BaseSubject = class {
|
|
|
45
48
|
get isConnected() {
|
|
46
49
|
return !!this._connection;
|
|
47
50
|
}
|
|
48
|
-
notifySubscribers(payload) {
|
|
51
|
+
notifySubscribers(payload, errorContext) {
|
|
52
|
+
if (errorContext) {
|
|
53
|
+
notifyEventListeners(this._subscriptions, payload, errorContext);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
49
56
|
for (const callback of this._subscriptions) callback(payload);
|
|
50
57
|
}
|
|
51
58
|
_updateConnection() {
|
|
@@ -174,8 +181,9 @@ var EventSubscriptionSubject = class extends BaseSubject {
|
|
|
174
181
|
return this.config.binding.subscribe(callback);
|
|
175
182
|
}
|
|
176
183
|
_connect() {
|
|
184
|
+
const errorContext = `Runtime event "${this.config.event}"`;
|
|
177
185
|
const callback = (payload) => {
|
|
178
|
-
this.notifySubscribers(payload);
|
|
186
|
+
this.notifySubscribers(payload, errorContext);
|
|
179
187
|
};
|
|
180
188
|
let lastState = this.config.binding.getState();
|
|
181
189
|
let innerUnsubscribe = lastState?.unstable_on(this.config.event, callback);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribable.js","names":["Unsubscribe","SKIP_UPDATE","Symbol","Subscribable","subscribe","callback","SubscribableWithState","path","TPath","getState","TState","NestedSubscribable","EventSubscribable","event","TEvent","binding","unstable_on","payload","shallowEqual","objA","T","objB","undefined","key","Object","keys","valueA","valueB","is","BaseSubscribable","_subscribers","Set","add","delete","waitForUpdate","Promise","resolve","unsubscribe","_notifySubscribers","errors","error","push","length","console","AggregateError","BaseSubject","_subscriptions","_connection","isConnected","_connect","notifySubscribers","_updateConnection","size","ShallowMemoizeSubject","constructor","state","Error","_previousState","_syncState","LazyMemoizeSubject","_previousStateDirty","newState","NestedSubscriptionSubject","outerSubscribe","lastState","innerUnsubscribe","onRuntimeUpdate","outerUnsubscribe","EventSubscriptionSubject","config"],"sources":["../../src/subscribable/subscribable.ts"],"sourcesContent":["import type { Unsubscribe } from \"../types/unsubscribe\";\n\nexport const SKIP_UPDATE = Symbol(\"skip-update\");\nexport type SKIP_UPDATE = typeof SKIP_UPDATE;\n\nexport type Subscribable = {\n subscribe: (callback: () => void) => Unsubscribe;\n};\n\nexport type SubscribableWithState<TState, TPath> = Subscribable & {\n path: TPath;\n getState: () => TState;\n};\n\nexport type NestedSubscribable<\n TState extends Subscribable | undefined,\n TPath,\n> = SubscribableWithState<TState, TPath>;\n\nexport type EventSubscribable<TEvent extends string> = {\n event: TEvent;\n binding: SubscribableWithState<\n | {\n unstable_on: (\n event: TEvent,\n callback: (payload?: unknown) => void,\n ) => Unsubscribe;\n }\n | undefined,\n unknown\n >;\n};\n\nfunction shallowEqual<T extends object>(\n objA: T | undefined,\n objB: T | undefined,\n) {\n if (objA === undefined && objB === undefined) return true;\n if (objA === undefined) return false;\n if (objB === undefined) return false;\n\n for (const key of Object.keys(objA)) {\n const valueA = objA[key as keyof T];\n const valueB = objB[key as keyof T];\n if (!Object.is(valueA, valueB)) return false;\n }\n\n return true;\n}\n\nexport class BaseSubscribable {\n private _subscribers = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscribers.add(callback);\n return () => this._subscribers.delete(callback);\n }\n\n public waitForUpdate() {\n return new Promise<void>((resolve) => {\n const unsubscribe = this.subscribe(() => {\n unsubscribe();\n resolve();\n });\n });\n }\n\n protected _notifySubscribers() {\n const errors = [];\n for (const callback of this._subscribers) {\n try {\n callback();\n } catch (error) {\n errors.push(error);\n }\n }\n\n if (errors.length > 0) {\n if (errors.length === 1) {\n throw errors[0];\n } else {\n for (const error of errors) {\n console.error(error);\n }\n throw new AggregateError(errors);\n }\n }\n }\n}\n\n// lazy connect/disconnect: only opens upstream subscription while it has subscribers\nexport abstract class BaseSubject {\n private _subscriptions = new Set<(payload?: unknown) => void>();\n private _connection: Unsubscribe | undefined;\n\n protected get isConnected() {\n return !!this._connection;\n }\n\n protected abstract _connect(): Unsubscribe;\n\n protected notifySubscribers(payload?: unknown) {\n for (const callback of this._subscriptions) callback(payload);\n }\n\n private _updateConnection() {\n if (this._subscriptions.size > 0) {\n if (this._connection) return;\n this._connection = this._connect();\n } else {\n this._connection?.();\n this._connection = undefined;\n }\n }\n\n public subscribe(callback: (payload?: unknown) => void) {\n this._subscriptions.add(callback);\n this._updateConnection();\n\n return () => {\n this._subscriptions.delete(callback);\n this._updateConnection();\n };\n }\n}\n\nexport class ShallowMemoizeSubject<TState extends object, TPath>\n extends BaseSubject\n implements SubscribableWithState<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n constructor(\n private binding: SubscribableWithState<TState | SKIP_UPDATE, TPath>,\n ) {\n super();\n const state = binding.getState();\n if (state === SKIP_UPDATE)\n throw new Error(\"Entry not available in the store\");\n this._previousState = state;\n }\n\n private _previousState: TState;\n public getState = () => {\n if (!this.isConnected) this._syncState();\n return this._previousState;\n };\n\n private _syncState() {\n const state = this.binding.getState();\n if (state === SKIP_UPDATE) return false;\n if (shallowEqual(state, this._previousState)) return false;\n this._previousState = state;\n return true;\n }\n\n protected _connect() {\n const callback = () => {\n if (this._syncState()) {\n this.notifySubscribers();\n }\n };\n\n return this.binding.subscribe(callback);\n }\n}\n\nexport class LazyMemoizeSubject<TState extends object, TPath>\n extends BaseSubject\n implements SubscribableWithState<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n constructor(\n private binding: SubscribableWithState<TState | SKIP_UPDATE, TPath>,\n ) {\n super();\n }\n\n private _previousStateDirty = true;\n private _previousState: TState | undefined;\n public getState = () => {\n if (!this.isConnected || this._previousStateDirty) {\n const newState = this.binding.getState();\n if (newState !== SKIP_UPDATE) {\n this._previousState = newState;\n }\n this._previousStateDirty = false;\n }\n if (this._previousState === undefined)\n throw new Error(\"Entry not available in the store\");\n return this._previousState;\n };\n\n protected _connect() {\n const callback = () => {\n this._previousStateDirty = true;\n this.notifySubscribers();\n };\n\n return this.binding.subscribe(callback);\n }\n}\n\nexport class NestedSubscriptionSubject<\n TState extends Subscribable | undefined,\n TPath,\n>\n extends BaseSubject\n implements\n SubscribableWithState<TState, TPath>,\n NestedSubscribable<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n constructor(private binding: NestedSubscribable<TState, TPath>) {\n super();\n }\n\n public getState() {\n return this.binding.getState();\n }\n\n public outerSubscribe(callback: () => void) {\n return this.binding.subscribe(callback);\n }\n\n protected _connect(): Unsubscribe {\n const callback = () => {\n this.notifySubscribers();\n };\n\n let lastState = this.binding.getState();\n let innerUnsubscribe = lastState?.subscribe(callback);\n const onRuntimeUpdate = () => {\n const newState = this.binding.getState();\n if (newState === lastState) return;\n lastState = newState;\n\n innerUnsubscribe?.();\n innerUnsubscribe = newState?.subscribe(callback);\n\n callback();\n };\n\n const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);\n return () => {\n outerUnsubscribe?.();\n innerUnsubscribe?.();\n };\n }\n}\n\nexport class EventSubscriptionSubject<\n TEvent extends string,\n> extends BaseSubject {\n constructor(private config: EventSubscribable<TEvent>) {\n super();\n }\n\n public getState() {\n return this.config.binding.getState();\n }\n\n public outerSubscribe(callback: () => void) {\n return this.config.binding.subscribe(callback);\n }\n\n protected _connect(): Unsubscribe {\n const callback = (payload?: unknown) => {\n this.notifySubscribers(payload);\n };\n\n let lastState = this.config.binding.getState();\n let innerUnsubscribe = lastState?.unstable_on(this.config.event, callback);\n const onRuntimeUpdate = () => {\n const newState = this.config.binding.getState();\n if (newState === lastState) return;\n lastState = newState;\n\n innerUnsubscribe?.();\n innerUnsubscribe = newState?.unstable_on(this.config.event, callback);\n };\n\n const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);\n return () => {\n outerUnsubscribe?.();\n innerUnsubscribe?.();\n };\n }\n}\n"],"mappings":";AAEA,MAAaC,cAAcC,OAAO,aAAa;AA+B/C,SAASgB,aACPC,MACAE,MACA;CACA,IAAIF,SAASG,KAAAA,KAAaD,SAASC,KAAAA,GAAW,OAAO;CACrD,IAAIH,SAASG,KAAAA,GAAW,OAAO;CAC/B,IAAID,SAASC,KAAAA,GAAW,OAAO;CAE/B,KAAK,MAAMC,OAAOC,OAAOC,KAAKN,IAAI,GAAG;EACnC,MAAMO,SAASP,KAAKI;EACpB,MAAMI,SAASN,KAAKE;EACpB,IAAI,CAACC,OAAOI,GAAGF,QAAQC,MAAM,GAAG,OAAO;CACzC;CAEA,OAAO;AACT;AAEA,IAAaE,mBAAb,MAA8B;CAC5B,+BAAuB,IAAIE,IAAgB;CAE3C,UAAiB1B,UAAmC;EAClD,KAAKyB,aAAaE,IAAI3B,QAAQ;EAC9B,aAAa,KAAKyB,aAAaG,OAAO5B,QAAQ;CAChD;CAEA,gBAAuB;EACrB,OAAO,IAAI8B,SAAeC,YAAY;GACpC,MAAMC,cAAc,K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F;AACF"}
|
|
1
|
+
{"version":3,"file":"subscribable.js","names":["Unsubscribe","notifyEventListeners","SKIP_UPDATE","Symbol","Subscribable","subscribe","callback","SubscribableWithState","path","TPath","getState","TState","NestedSubscribable","EventSubscribable","event","TEvent","binding","unstable_on","payload","shallowEqual","objA","T","objB","undefined","keysA","Object","keys","length","key","valueA","valueB","is","BaseSubscribable","_subscribers","Set","add","delete","waitForUpdate","Promise","resolve","unsubscribe","_notifySubscribers","errors","error","push","console","AggregateError","BaseSubject","_subscriptions","_connection","isConnected","_connect","notifySubscribers","errorContext","_updateConnection","size","ShallowMemoizeSubject","constructor","state","Error","_previousState","_syncState","LazyMemoizeSubject","_previousStateDirty","newState","NestedSubscriptionSubject","outerSubscribe","lastState","innerUnsubscribe","onRuntimeUpdate","outerUnsubscribe","EventSubscriptionSubject","config"],"sources":["../../src/subscribable/subscribable.ts"],"sourcesContent":["import type { Unsubscribe } from \"../types/unsubscribe\";\nimport { notifyEventListeners } from \"../utils/notify-event-listeners\";\n\nexport const SKIP_UPDATE = Symbol(\"skip-update\");\nexport type SKIP_UPDATE = typeof SKIP_UPDATE;\n\nexport type Subscribable = {\n subscribe: (callback: () => void) => Unsubscribe;\n};\n\nexport type SubscribableWithState<TState, TPath> = Subscribable & {\n path: TPath;\n getState: () => TState;\n};\n\nexport type NestedSubscribable<\n TState extends Subscribable | undefined,\n TPath,\n> = SubscribableWithState<TState, TPath>;\n\nexport type EventSubscribable<TEvent extends string> = {\n event: TEvent;\n binding: SubscribableWithState<\n | {\n unstable_on: (\n event: TEvent,\n callback: (payload?: unknown) => void,\n ) => Unsubscribe;\n }\n | undefined,\n unknown\n >;\n};\n\nfunction shallowEqual<T extends object>(\n objA: T | undefined,\n objB: T | undefined,\n) {\n if (objA === undefined && objB === undefined) return true;\n if (objA === undefined) return false;\n if (objB === undefined) return false;\n\n const keysA = Object.keys(objA);\n if (keysA.length !== Object.keys(objB).length) return false;\n\n for (const key of keysA) {\n const valueA = objA[key as keyof T];\n const valueB = objB[key as keyof T];\n if (!Object.is(valueA, valueB)) return false;\n }\n\n return true;\n}\n\nexport class BaseSubscribable {\n private _subscribers = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscribers.add(callback);\n return () => this._subscribers.delete(callback);\n }\n\n public waitForUpdate() {\n return new Promise<void>((resolve) => {\n const unsubscribe = this.subscribe(() => {\n unsubscribe();\n resolve();\n });\n });\n }\n\n protected _notifySubscribers() {\n const errors = [];\n for (const callback of this._subscribers) {\n try {\n callback();\n } catch (error) {\n errors.push(error);\n }\n }\n\n if (errors.length > 0) {\n if (errors.length === 1) {\n throw errors[0];\n } else {\n for (const error of errors) {\n console.error(error);\n }\n throw new AggregateError(errors);\n }\n }\n }\n}\n\n// lazy connect/disconnect: only opens upstream subscription while it has subscribers\nexport abstract class BaseSubject {\n private _subscriptions = new Set<(payload?: unknown) => void>();\n private _connection: Unsubscribe | undefined;\n\n protected get isConnected() {\n return !!this._connection;\n }\n\n protected abstract _connect(): Unsubscribe;\n\n protected notifySubscribers(payload?: unknown, errorContext?: string) {\n if (errorContext) {\n notifyEventListeners(this._subscriptions, payload, errorContext);\n return;\n }\n\n for (const callback of this._subscriptions) callback(payload);\n }\n\n private _updateConnection() {\n if (this._subscriptions.size > 0) {\n if (this._connection) return;\n this._connection = this._connect();\n } else {\n this._connection?.();\n this._connection = undefined;\n }\n }\n\n public subscribe(callback: (payload?: unknown) => void) {\n this._subscriptions.add(callback);\n this._updateConnection();\n\n return () => {\n this._subscriptions.delete(callback);\n this._updateConnection();\n };\n }\n}\n\nexport class ShallowMemoizeSubject<TState extends object, TPath>\n extends BaseSubject\n implements SubscribableWithState<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n constructor(\n private binding: SubscribableWithState<TState | SKIP_UPDATE, TPath>,\n ) {\n super();\n const state = binding.getState();\n if (state === SKIP_UPDATE)\n throw new Error(\"Entry not available in the store\");\n this._previousState = state;\n }\n\n private _previousState: TState;\n public getState = () => {\n if (!this.isConnected) this._syncState();\n return this._previousState;\n };\n\n private _syncState() {\n const state = this.binding.getState();\n if (state === SKIP_UPDATE) return false;\n if (shallowEqual(state, this._previousState)) return false;\n this._previousState = state;\n return true;\n }\n\n protected _connect() {\n const callback = () => {\n if (this._syncState()) {\n this.notifySubscribers();\n }\n };\n\n return this.binding.subscribe(callback);\n }\n}\n\nexport class LazyMemoizeSubject<TState extends object, TPath>\n extends BaseSubject\n implements SubscribableWithState<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n constructor(\n private binding: SubscribableWithState<TState | SKIP_UPDATE, TPath>,\n ) {\n super();\n }\n\n private _previousStateDirty = true;\n private _previousState: TState | undefined;\n public getState = () => {\n if (!this.isConnected || this._previousStateDirty) {\n const newState = this.binding.getState();\n if (newState !== SKIP_UPDATE) {\n this._previousState = newState;\n }\n this._previousStateDirty = false;\n }\n if (this._previousState === undefined)\n throw new Error(\"Entry not available in the store\");\n return this._previousState;\n };\n\n protected _connect() {\n const callback = () => {\n this._previousStateDirty = true;\n this.notifySubscribers();\n };\n\n return this.binding.subscribe(callback);\n }\n}\n\nexport class NestedSubscriptionSubject<\n TState extends Subscribable | undefined,\n TPath,\n>\n extends BaseSubject\n implements\n SubscribableWithState<TState, TPath>,\n NestedSubscribable<TState, TPath>\n{\n public get path() {\n return this.binding.path;\n }\n\n constructor(private binding: NestedSubscribable<TState, TPath>) {\n super();\n }\n\n public getState() {\n return this.binding.getState();\n }\n\n public outerSubscribe(callback: () => void) {\n return this.binding.subscribe(callback);\n }\n\n protected _connect(): Unsubscribe {\n const callback = () => {\n this.notifySubscribers();\n };\n\n let lastState = this.binding.getState();\n let innerUnsubscribe = lastState?.subscribe(callback);\n const onRuntimeUpdate = () => {\n const newState = this.binding.getState();\n if (newState === lastState) return;\n lastState = newState;\n\n innerUnsubscribe?.();\n innerUnsubscribe = newState?.subscribe(callback);\n\n callback();\n };\n\n const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);\n return () => {\n outerUnsubscribe?.();\n innerUnsubscribe?.();\n };\n }\n}\n\nexport class EventSubscriptionSubject<\n TEvent extends string,\n> extends BaseSubject {\n constructor(private config: EventSubscribable<TEvent>) {\n super();\n }\n\n public getState() {\n return this.config.binding.getState();\n }\n\n public outerSubscribe(callback: () => void) {\n return this.config.binding.subscribe(callback);\n }\n\n protected _connect(): Unsubscribe {\n const errorContext = `Runtime event \"${this.config.event}\"`;\n const callback = (payload?: unknown) => {\n this.notifySubscribers(payload, errorContext);\n };\n\n let lastState = this.config.binding.getState();\n let innerUnsubscribe = lastState?.unstable_on(this.config.event, callback);\n const onRuntimeUpdate = () => {\n const newState = this.config.binding.getState();\n if (newState === lastState) return;\n lastState = newState;\n\n innerUnsubscribe?.();\n innerUnsubscribe = newState?.unstable_on(this.config.event, callback);\n };\n\n const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);\n return () => {\n outerUnsubscribe?.();\n innerUnsubscribe?.();\n };\n }\n}\n"],"mappings":";;AAGA,MAAaE,cAAcC,OAAO,aAAa;AA+B/C,SAASgB,aACPC,MACAE,MACA;CACA,IAAIF,SAASG,KAAAA,KAAaD,SAASC,KAAAA,GAAW,OAAO;CACrD,IAAIH,SAASG,KAAAA,GAAW,OAAO;CAC/B,IAAID,SAASC,KAAAA,GAAW,OAAO;CAE/B,MAAMC,QAAQC,OAAOC,KAAKN,IAAI;CAC9B,IAAII,MAAMG,WAAWF,OAAOC,KAAKJ,IAAI,CAAC,CAACK,QAAQ,OAAO;CAEtD,KAAK,MAAMC,OAAOJ,OAAO;EACvB,MAAMK,SAAST,KAAKQ;EACpB,MAAME,SAASR,KAAKM;EACpB,IAAI,CAACH,OAAOM,GAAGF,QAAQC,MAAM,GAAG,OAAO;CACzC;CAEA,OAAO;AACT;AAEA,IAAaE,mBAAb,MAA8B;CAC5B,+BAAuB,IAAIE,IAAgB;CAE3C,UAAiB5B,UAAmC;EAClD,KAAK2B,aAAaE,IAAI7B,QAAQ;EAC9B,aAAa,KAAK2B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KAAKQ,OAAOxD,QAAQN,SAAS;GAC9C,IAAIsD,aAAaG,WAAW;GAC5BA,YAAYH;GAEZI,mBAAmB;GACnBA,mBAAmBJ,UAAU/C,YAAY,KAAKuD,OAAO1D,OAAOR,QAAQ;EACtE;EAEA,MAAMgE,mBAAmB,KAAKJ,eAAeG,eAAe;EAC5D,aAAa;GACXC,mBAAmB;GACnBF,mBAAmB;EACrB;CACF;AACF"}
|
|
@@ -8,8 +8,9 @@ declare function deferred<T>(): {
|
|
|
8
8
|
reject: (reason?: unknown) => void;
|
|
9
9
|
};
|
|
10
10
|
declare const contextProvider: ModelContextProvider;
|
|
11
|
+
declare function setStartThreadRuntime(core: RemoteThreadListThreadListRuntimeCore, startThreadRuntime: (id: string) => Promise<unknown>): void;
|
|
11
12
|
declare function makeAdapter(overrides?: Partial<RemoteThreadListAdapter>): RemoteThreadListAdapter;
|
|
12
13
|
declare function createCore(adapter: RemoteThreadListAdapter, threadId?: string, onThreadIdChange?: (threadId: string | undefined) => void): RemoteThreadListThreadListRuntimeCore;
|
|
13
14
|
//#endregion
|
|
14
|
-
export { contextProvider, createCore, deferred, makeAdapter };
|
|
15
|
+
export { contextProvider, createCore, deferred, makeAdapter, setStartThreadRuntime };
|
|
15
16
|
//# sourceMappingURL=remote-thread-list-test-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-thread-list-test-helpers.d.ts","names":[],"sources":["../../src/tests/remote-thread-list-test-helpers.ts"],"mappings":";;;;iBAKgB,SAAS;;
|
|
1
|
+
{"version":3,"file":"remote-thread-list-test-helpers.d.ts","names":[],"sources":["../../src/tests/remote-thread-list-test-helpers.ts"],"mappings":";;;;iBAKgB,SAAS;;EACD,UAAA,OAAA;EACC,SAAA;;cAQZ,iBAAiB;iBAKd,sBACd,MAAM,uCACN,qBAAqB,eAAe;iBAWtB,YACd,YAAW,QAAQ,2BAClB;iBA6Ba,WACd,SAAS,yBACT,mBACA,oBAAoB,wCACnB"}
|
|
@@ -17,6 +17,9 @@ const contextProvider = {
|
|
|
17
17
|
getModelContext: () => ({}),
|
|
18
18
|
subscribe: () => () => {}
|
|
19
19
|
};
|
|
20
|
+
function setStartThreadRuntime(core, startThreadRuntime) {
|
|
21
|
+
core._hookManager.startThreadRuntime = startThreadRuntime;
|
|
22
|
+
}
|
|
20
23
|
function makeAdapter(overrides = {}) {
|
|
21
24
|
return {
|
|
22
25
|
list: vi.fn(async () => ({ threads: [] })),
|
|
@@ -47,10 +50,10 @@ function createCore(adapter, threadId, onThreadIdChange) {
|
|
|
47
50
|
threadId,
|
|
48
51
|
onThreadIdChange
|
|
49
52
|
}, contextProvider);
|
|
50
|
-
core
|
|
53
|
+
setStartThreadRuntime(core, async () => ({}));
|
|
51
54
|
return core;
|
|
52
55
|
}
|
|
53
56
|
//#endregion
|
|
54
|
-
export { contextProvider, createCore, deferred, makeAdapter };
|
|
57
|
+
export { contextProvider, createCore, deferred, makeAdapter, setStartThreadRuntime };
|
|
55
58
|
|
|
56
59
|
//# sourceMappingURL=remote-thread-list-test-helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-thread-list-test-helpers.js","names":["vi","RemoteThreadListThreadListRuntimeCore","RemoteThreadListAdapter","ModelContextProvider","deferred","resolve","value","T","reject","reason","promise","Promise","res","rej","contextProvider","getModelContext","subscribe","makeAdapter","overrides","Partial","list","fn","threads","initialize","threadId","remoteId","externalId","rename","archive","unarchive","delete","generateTitle","ReadableStream","start","c","close","fetch","
|
|
1
|
+
{"version":3,"file":"remote-thread-list-test-helpers.js","names":["vi","RemoteThreadListThreadListRuntimeCore","RemoteThreadListAdapter","ModelContextProvider","deferred","resolve","value","T","reject","reason","promise","Promise","res","rej","contextProvider","getModelContext","subscribe","setStartThreadRuntime","core","startThreadRuntime","id","_hookManager","makeAdapter","overrides","Partial","list","fn","threads","initialize","threadId","remoteId","externalId","rename","archive","unarchive","delete","generateTitle","ReadableStream","start","c","close","fetch","status","const","title","createCore","adapter","onThreadIdChange","runtimeHook"],"sources":["../../src/tests/remote-thread-list-test-helpers.ts"],"sourcesContent":["import { vi } from \"vitest\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"../react/runtimes/RemoteThreadListThreadListRuntimeCore\";\nimport type { RemoteThreadListAdapter } from \"../runtimes/remote-thread-list/types\";\nimport type { ModelContextProvider } from \"../model-context/types\";\n\nexport function deferred<T>() {\n let resolve!: (value: T) => void;\n let reject!: (reason?: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n return { promise, resolve, reject };\n}\n\nexport const contextProvider: ModelContextProvider = {\n getModelContext: () => ({}),\n subscribe: () => () => {},\n};\n\nexport function setStartThreadRuntime(\n core: RemoteThreadListThreadListRuntimeCore,\n startThreadRuntime: (id: string) => Promise<unknown>,\n) {\n (\n core as unknown as {\n _hookManager: {\n startThreadRuntime: (id: string) => Promise<unknown>;\n };\n }\n )._hookManager.startThreadRuntime = startThreadRuntime;\n}\n\nexport function makeAdapter(\n overrides: Partial<RemoteThreadListAdapter> = {},\n): RemoteThreadListAdapter {\n return {\n list: vi.fn(async () => ({ threads: [] })),\n initialize: vi.fn(async (threadId: string) => ({\n remoteId: threadId,\n externalId: threadId,\n })),\n rename: vi.fn(async () => {}),\n archive: vi.fn(async () => {}),\n unarchive: vi.fn(async () => {}),\n delete: vi.fn(async () => {}),\n generateTitle: vi.fn(\n async () =>\n new ReadableStream({\n start(c) {\n c.close();\n },\n }) as never,\n ),\n fetch: vi.fn(async (id: string) => ({\n status: \"regular\" as const,\n remoteId: id,\n externalId: id,\n title: \"Test\",\n })),\n ...overrides,\n };\n}\n\nexport function createCore(\n adapter: RemoteThreadListAdapter,\n threadId?: string,\n onThreadIdChange?: (threadId: string | undefined) => void,\n): RemoteThreadListThreadListRuntimeCore {\n const core = new RemoteThreadListThreadListRuntimeCore(\n { adapter, runtimeHook: () => ({}) as never, threadId, onThreadIdChange },\n contextProvider,\n );\n // `startThreadRuntime` blocks until a React component attaches a runtime;\n // stub it so non-React unit tests don't hang.\n setStartThreadRuntime(core, async () => ({}));\n return core;\n}\n"],"mappings":";;;AAKA,SAAgBI,WAAc;CAC5B,IAAIC;CACJ,IAAIG;CAKJ,OAAO;EAAEE,SAAAA,IAJWC,SAAYC,KAAKC,QAAQ;GAC3CR,UAAUO;GACVJ,SAASK;EACX,CACSH;EAASL;EAASG;CAAO;AACpC;AAEA,MAAaM,kBAAwC;CACnDC,wBAAwB,CAAC;CACzBC,uBAAuB,CAAC;AAC1B;AAEA,SAAgBC,sBACdC,MACAC,oBACA;CACA,KAMEE,aAAaF,qBAAqBA;AACtC;AAEA,SAAgBG,YACdC,YAA8C,CAAC,GACtB;CACzB,OAAO;EACLE,MAAMzB,GAAG0B,GAAG,aAAa,EAAEC,SAAS,CAAA,EAAG,EAAE;EACzCC,YAAY5B,GAAG0B,GAAG,OAAOG,cAAsB;GAC7CC,UAAUD;GACVE,YAAYF;EACd,EAAE;EACFG,QAAQhC,GAAG0B,GAAG,YAAY,CAAC,CAAC;EAC5BO,SAASjC,GAAG0B,GAAG,YAAY,CAAC,CAAC;EAC7BQ,WAAWlC,GAAG0B,GAAG,YAAY,CAAC,CAAC;EAC/BS,QAAQnC,GAAG0B,GAAG,YAAY,CAAC,CAAC;EAC5BU,eAAepC,GAAG0B,GAChB,YACE,IAAIW,eAAe,EACjBC,MAAMC,GAAG;GACPA,EAAEC,MAAM;EACV,EACF,CAAC,CACL;EACAC,OAAOzC,GAAG0B,GAAG,OAAON,QAAgB;GAClCsB,QAAQ;GACRZ,UAAUV;GACVW,YAAYX;GACZwB,OAAO;EACT,EAAE;EACF,GAAGrB;CACL;AACF;AAEA,SAAgBsB,WACdC,SACAjB,UACAkB,kBACuC;CACvC,MAAM7B,OAAO,IAAIjB,sCACf;EAAE6C;EAASE,oBAAoB,CAAC;EAAanB;EAAUkB;CAAiB,GACxEjC,eACF;CAGAG,sBAAsBC,MAAM,aAAa,CAAC,EAAE;CAC5C,OAAOA;AACT"}
|
|
@@ -40,6 +40,7 @@ type CreateAttachment = {
|
|
|
40
40
|
contentType?: string;
|
|
41
41
|
content: ThreadUserMessagePart[];
|
|
42
42
|
};
|
|
43
|
+
declare const isCreateAttachment: (attachment: File | CreateAttachment) => attachment is CreateAttachment;
|
|
43
44
|
//#endregion
|
|
44
|
-
export { Attachment, AttachmentStatus, CompleteAttachment, CompleteAttachmentStatus, CreateAttachment, PendingAttachment, PendingAttachmentStatus };
|
|
45
|
+
export { Attachment, AttachmentStatus, CompleteAttachment, CompleteAttachmentStatus, CreateAttachment, PendingAttachment, PendingAttachmentStatus, isCreateAttachment };
|
|
45
46
|
//# sourceMappingURL=attachment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment.d.ts","names":[],"sources":["../../src/types/attachment.ts"],"mappings":";;KAEY;EAEN;EACA;EACA;;EAGA;EACA;;EAGA;EACA;EACA;;KAGM;EACV;;KAGU,mBACR,0BACA;KAEC;EACH;EACA;EACA;EACA;EACA,OAAO;EACP,UAAU;;KAGA,oBAAoB;EAC9B,QAAQ;EACR,MAAM;;KAGI,qBAAqB;EAC/B,QAAQ;EACR,SAAS;;KAGC,aAAa,oBAAoB;KAEjC;EACV;EACA;EACA;EACA;EACA,SAAS"}
|
|
1
|
+
{"version":3,"file":"attachment.d.ts","names":[],"sources":["../../src/types/attachment.ts"],"mappings":";;KAEY;EAEN;EACA;EACA;;EAGA;EACA;;EAGA;EACA;EACA;;KAGM;EACV;;KAGU,mBACR,0BACA;KAEC;EACH;EACA;EACA;EACA;EACA,OAAO;EACP,UAAU;;KAGA,oBAAoB;EAC9B,QAAQ;EACR,MAAM;;KAGI,qBAAqB;EAC/B,QAAQ;EACR,SAAS;;KAGC,aAAa,oBAAoB;KAEjC;EACV;EACA;EACA;EACA;EACA,SAAS;;cAGE,qBACX,YAAY,OAAO,qBAClB,cAAc"}
|
package/dist/types/attachment.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment.js","names":["ThreadUserMessagePart","PendingAttachmentStatus","type","reason","progress","message","CompleteAttachmentStatus","AttachmentStatus","BaseAttachment","id","name","contentType","file","File","content","PendingAttachment","status","CompleteAttachment","Attachment","CreateAttachment","isCreateAttachment","attachment"],"sources":["../../src/types/attachment.ts"],"sourcesContent":["import type { ThreadUserMessagePart } from \"./message\";\n\nexport type PendingAttachmentStatus =\n | {\n type: \"running\";\n reason: \"uploading\";\n progress: number;\n }\n | {\n type: \"requires-action\";\n reason: \"composer-send\";\n }\n | {\n type: \"incomplete\";\n reason: \"error\" | \"upload-paused\";\n message?: string;\n };\n\nexport type CompleteAttachmentStatus = {\n type: \"complete\";\n};\n\nexport type AttachmentStatus =\n | PendingAttachmentStatus\n | CompleteAttachmentStatus;\n\ntype BaseAttachment = {\n id: string;\n type: \"image\" | \"document\" | \"file\" | (string & {});\n name: string;\n contentType?: string | undefined;\n file?: File;\n content?: ThreadUserMessagePart[];\n};\n\nexport type PendingAttachment = BaseAttachment & {\n status: PendingAttachmentStatus;\n file: File;\n};\n\nexport type CompleteAttachment = BaseAttachment & {\n status: CompleteAttachmentStatus;\n content: ThreadUserMessagePart[];\n};\n\nexport type Attachment = PendingAttachment | CompleteAttachment;\n\nexport type CreateAttachment = {\n id?: string;\n type?: \"image\" | \"document\" | \"file\" | (string & {});\n name: string;\n contentType?: string;\n content: ThreadUserMessagePart[];\n};\n\nexport const isCreateAttachment = (\n attachment: File | CreateAttachment,\n): attachment is CreateAttachment =>\n \"content\" in attachment && !(\"lastModified\" in attachment);\n"],"mappings":";AAuDA,MAAaoB,sBACXC,eAEA,aAAaA,cAAc,EAAE,kBAAkBA"}
|
package/dist/types/message.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","names":[],"sources":["../../src/types/message.ts"],"mappings":";;;;KASY;YACA,uBAAuB;;KAGvB;WACD;WACA;WACA,mBAAmB;WACnB;;KAGC;WACD;W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aACA;aACA;aACA;aACA;aACA;aACA,QAAQ;;;KAIT,oBAAoB;WACrB;WACA,kBAAkB;WAClB,sBAAsB;WACtB;aACE;aACA;aACA;aACA;aACA;aACA;aACA,QAAQ;;;KAIT,yBAAyB;WAC1B;WACA,kBAAkB;WAClB,QAAQ;WACR;aACE,gBAAgB;aAChB,+BAA+B;aAC/B,wBAAwB;aACxB,gBAAgB;aAChB;eAA+B;;aAC/B,SAAS;;;;;aAKT;aACA,QAAQ;;;KAIhB;WACM,SAAS;WACT;aACE,iBAAiB;aACjB,gCAAgC;aAChC,yBAAyB;aACzB,iBAAiB;aACjB;eAA+B;;aAC/B,SAAS;aACT;aACA,QAAQ;;WAEV,cAAc;;KAGb,gBAAgB,qBACzB,sBAAsB,oBAAoB;KAEjC,cAAc;KAEd;WACD,SAAS;;KAGR,gBAAgB,KAAK;EAC/B;;EAGA;EACA,WAAW;EACX;;EAEA"}
|
|
1
|
+
{"version":3,"file":"message.d.ts","names":[],"sources":["../../src/types/message.ts"],"mappings":";;;;KASY;YACA,uBAAuB;;KAGvB;WACD;WACA;WACA,mBAAmB;WACnB;;KAGC;WACD;WACA;WACA,mBAAmB;WACnB;;KAGC,yBAAyB;KAEzB;WAEG;WACA;WACA;WACA;WACA;WACA,mBAAmB;WACnB;;WAGA;WACA;WACA;WACA;WACA;WACA;WACA;WACA,mBAAmB;WACnB;;KAGH;WACD;WACA;WACA;;KAGC;WACD;WACA;WACA;WACA;WACA;;KAGC;WACD;WACA;aACE;aACA;;;KAID,gBAAgB;WACjB;WACA;WACA,MAAM;;;;;;;;;;;KAYL;;WAIG;;WAEA,QAAQ;;WAER,oBAAoB;;WAEpB;;;;;KAMH;;WAED,MAAM,4BAA4B;;;;;;;;;;KAWjC;WACD;;WAEA,MAAM;;WAEN;WACA;;KAGC;WACD;WACA;WACA;;WAEA;;cAGE;cAEA,cAAe;KAGhB;WACD,MAAM;;KAGL;KAMA;;WAED;;;;;;;WAOA,MAAM;;WAEN;WACA;;WAEA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KAAK;EAC/B;;EAGA;EACA,WAAW;EACX;;EAEA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","names":["ReadonlyJSONObject","ReadonlyJSONValue","ToolCallTiming","ToolModelContentPart","CompleteAttachment","PartProviderMetadata","providerName","TextMessagePart","type","text","providerMetadata","parentId","ReasoningMessagePart","SourceProviderMetadata","SourceMessagePart","sourceType","id","url","title","mediaType","filename","ImageMessagePart","image","FileMessagePart","data","mimeType","Unstable_AudioMessagePart","audio","format","DataMessagePart","name","T","GenerativeUINode","component","props","Record","children","key","GenerativeUISpec","root","GenerativeUIMessagePart","spec","McpAppMetadata","resourceUri","visibility","serverId","MCP_APP_URI_SCHEME","isMcpAppUri","uri","startsWith","ToolCallMessagePartMcpMetadata","app","ToolApprovalOptionKind","ToolApprovalOption","kind","label","description","grants","confirm","ToolApprovalResponse","approved","reason","optionId","ToolCallMessagePart","toolCallId","toolName","args","TArgs","result","TResult","isError","argsText","artifact","timing","mcp","modelContent","interrupt","payload","approval","isAutomatic","options","resolution","messages","ThreadMessage","ThreadUserMessagePart","ThreadAssistantMessagePart","MessagePartStatus","error","ToolCallMessagePartStatus","MessageStatus","MessageTiming","streamStartTime","firstTokenTime","totalStreamTime","tokenCount","tokensPerSecond","totalChunks","toolCallCount","ThreadStep","messageId","usage","inputTokens","outputTokens","MessageCommonProps","createdAt","Date","ThreadSystemMessage","role","content","metadata","unstable_state","unstable_annotations","unstable_data","steps","submittedFeedback","custom","ThreadUserMessage","attachments","ThreadAssistantMessage","status","isOptimistic","BaseThreadMessage","MessageRole","RunConfig","AppendMessage","Omit","sourceId","runConfig","startRun","steer"],"sources":["../../src/types/message.ts"],"sourcesContent":["import type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ToolCallTiming, ToolModelContentPart } from \"assistant-stream\";\nimport type { CompleteAttachment } from \"./attachment\";\n\nexport type { ToolCallTiming, ToolModelContentPart };\n\nexport type PartProviderMetadata = {\n readonly [providerName: string]: ReadonlyJSONObject;\n};\n\nexport type TextMessagePart = {\n readonly type: \"text\";\n readonly text: string;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type ReasoningMessagePart = {\n readonly type: \"reasoning\";\n readonly text: string;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type SourceProviderMetadata = PartProviderMetadata;\n\nexport type SourceMessagePart =\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly url?: undefined;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n };\n\nexport type ImageMessagePart = {\n readonly type: \"image\";\n readonly image: string;\n readonly filename?: string;\n};\n\nexport type FileMessagePart = {\n readonly type: \"file\";\n readonly filename?: string;\n readonly data: string;\n readonly mimeType: string;\n readonly parentId?: string;\n};\n\nexport type Unstable_AudioMessagePart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\nexport type DataMessagePart<T = any> = {\n readonly type: \"data\";\n readonly name: string;\n readonly data: T;\n};\n\n/**\n * A JSON spec describing a tree of UI components to render.\n *\n * The agent emits a {@link GenerativeUIMessagePart} containing this spec, and\n * the consumer-provided component allowlist is used to resolve `component`\n * names. Any component referenced that is not present in the allowlist is\n * rejected with a typed error — the allowlist is the security boundary in the\n * default same-realm rendering path.\n */\nexport type GenerativeUINode =\n | string\n | {\n /** Allowlisted component name (resolved against the consumer registry). */\n readonly component: string;\n /** Props passed to the resolved component (must be JSON-serializable). */\n readonly props?: Record<string, unknown>;\n /** Optional children — strings render as text, objects recurse. */\n readonly children?: readonly GenerativeUINode[];\n /** Optional stable key for React reconciliation. */\n readonly key?: string;\n };\n\n/**\n * The root spec for a generative UI tree.\n */\nexport type GenerativeUISpec = {\n /** Root node(s) to render. */\n readonly root: GenerativeUINode | readonly GenerativeUINode[];\n};\n\n/**\n * A message part that carries a JSON spec describing UI to render.\n *\n * Render with `<MessagePrimitive.GenerativeUI components={...} />`. The\n * primitive resolves component names against the consumer-provided allowlist\n * — any unknown name throws a typed error rather than rendering. Stream-\n * friendly: a partially-streamed spec renders progressively.\n */\nexport type GenerativeUIMessagePart = {\n readonly type: \"generative-ui\";\n /** The JSON spec describing the UI tree. */\n readonly spec: GenerativeUISpec;\n /** Optional id (useful for replays / stable keys). */\n readonly id?: string;\n readonly parentId?: string;\n};\n\nexport type McpAppMetadata = {\n readonly resourceUri: string;\n readonly mimeType?: string;\n readonly visibility?: readonly (\"model\" | \"app\")[];\n /** Routable server identity emitted by the agent stack when multiple MCP servers back one agent; for @ag-ui/mcp-apps-middleware this is the configured serverId, falling back to its serverHash. */\n readonly serverId?: string;\n};\n\nexport const MCP_APP_URI_SCHEME = \"ui://\";\n\nexport const isMcpAppUri = (uri: string | undefined): boolean =>\n !!uri?.startsWith(MCP_APP_URI_SCHEME);\n\nexport type ToolCallMessagePartMcpMetadata = {\n readonly app?: McpAppMetadata;\n};\n\nexport type ToolApprovalOptionKind =\n | \"allow-once\"\n | \"allow-always\"\n | \"reject-once\"\n | \"reject-always\";\n\nexport type ToolApprovalOption = {\n /** Opaque, host-defined identifier. Scope semantics (session vs project vs global) belong to the option supplier. */\n readonly id: string;\n /**\n * Decision class. Drives approved-resolution and default rendering.\n * Open union: `_`-prefixed custom kinds are never auto-resolved and the\n * default kit skips them; they must be answered with an explicit\n * `approved` value (optionally alongside the `optionId`).\n */\n readonly kind: ToolApprovalOptionKind | (string & {});\n /** Human label. Renderers supply defaults per kind when omitted. */\n readonly label?: string;\n readonly description?: string;\n /** Patterns or rules this option would persist, shown before the user commits. Supplied by the host; never derived by the library. */\n readonly grants?: readonly string[];\n /** Opt-in confirmation step before this option resolves. */\n readonly confirm?: boolean | { title?: string; description?: string };\n};\n\nexport type ToolApprovalResponse =\n | { readonly approved: boolean; readonly reason?: string }\n | { readonly optionId: string; readonly reason?: string }\n | {\n readonly approved: boolean;\n readonly optionId: string;\n readonly reason?: string;\n };\n\nexport type ToolCallMessagePart<\n TArgs = ReadonlyJSONObject,\n TResult = unknown,\n> = {\n /** Identifies this part as a tool call. */\n readonly type: \"tool-call\";\n /** Stable identifier for this invocation of the tool. */\n readonly toolCallId: string;\n /** Name of the tool requested by the model. */\n readonly toolName: string;\n /**\n * Arguments supplied by the model. During streaming this is a partial parse:\n * fields may be missing or incomplete. From a tool-call renderer, use\n * `useToolArgsStatus` to detect which fields are still arriving.\n */\n readonly args: TArgs;\n /** Result returned by the tool, if it has completed. */\n readonly result?: TResult | undefined;\n /** Whether the result represents a tool execution error. */\n readonly isError?: boolean | undefined;\n /** Raw JSON argument text streamed by the model. */\n readonly argsText: string;\n /** UI-only artifact associated with the tool result. */\n readonly artifact?: unknown;\n /** Wall-clock timing for this call, when the runtime or host tracks it. */\n readonly timing?: ToolCallTiming;\n /** MCP app metadata associated with this tool call, when present. */\n readonly mcp?: ToolCallMessagePartMcpMetadata;\n /** Provider metadata associated with this tool call, when present. */\n readonly providerMetadata?: PartProviderMetadata;\n /** Content returned to the model for this tool result. */\n readonly modelContent?: readonly ToolModelContentPart[] | undefined;\n /** Human-input request that must be resolved before the run can continue. */\n readonly interrupt?: { type: \"human\"; payload: unknown };\n /** Server-side approval gate. `respondToApproval` may only be called while `approved` is undefined and no `resolution` is recorded. */\n readonly approval?: {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n /** Available decisions for this call. Absent: a plain allow / deny pair. */\n readonly options?: readonly ToolApprovalOption[];\n /** The option chosen at resolution, when options were present. */\n readonly optionId?: string;\n /** Terminal non-decision state: the request was cancelled or expired without a user decision. Set by the host. */\n readonly resolution?: \"cancelled\" | \"expired\";\n };\n /** Parent message-part ID when this part belongs to a nested structure. */\n readonly parentId?: string;\n /**\n * Nested thread messages produced by this tool call, for example a sub-agent\n * conversation.\n */\n readonly messages?: readonly ThreadMessage[];\n};\n\nexport type ThreadUserMessagePart =\n | TextMessagePart\n | ImageMessagePart\n | FileMessagePart\n | DataMessagePart\n | Unstable_AudioMessagePart;\n\nexport type ThreadAssistantMessagePart =\n | TextMessagePart\n | ReasoningMessagePart\n | ToolCallMessagePart\n | SourceMessagePart\n | FileMessagePart\n | ImageMessagePart\n | DataMessagePart\n | GenerativeUIMessagePart;\n\nexport type MessagePartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type ToolCallMessagePartStatus =\n | {\n /** The tool call is waiting for UI or human input before continuing. */\n readonly type: \"requires-action\";\n /** Reason the tool call requires action. */\n readonly reason: \"interrupt\";\n }\n | MessagePartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\" | \"interrupt\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: ReadonlyJSONValue;\n };\n\nexport type MessageTiming = {\n readonly streamStartTime: number;\n readonly firstTokenTime?: number;\n readonly totalStreamTime?: number;\n readonly tokenCount?: number;\n readonly tokensPerSecond?: number;\n readonly totalChunks: number;\n readonly toolCallCount: number;\n};\n\nexport type ThreadStep = {\n readonly messageId?: string;\n readonly usage?:\n | {\n readonly inputTokens: number;\n readonly outputTokens: number;\n }\n | undefined;\n};\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: readonly [TextMessagePart];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: readonly ThreadUserMessagePart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: readonly ThreadAssistantMessagePart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly unstable_state: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n /**\n * Marks a client-side optimistic placeholder. Such messages are evicted\n * once off the head branch and are never persisted.\n */\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations?: readonly ReadonlyJSONValue[];\n readonly unstable_data?: readonly ReadonlyJSONValue[];\n readonly steps?: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\nexport type MessageRole = ThreadMessage[\"role\"];\n\nexport type RunConfig = {\n readonly custom?: Record<string, unknown>;\n};\n\nexport type AppendMessage = Omit<ThreadMessage, \"id\"> & {\n parentId: string | null;\n\n /** The ID of the message that was edited or undefined. */\n sourceId: string | null;\n runConfig: RunConfig | undefined;\n startRun?: boolean | undefined;\n /** Process this message next; only meaningful for queue-capable runtimes. */\n steer?: boolean | undefined;\n};\n"],"mappings":";AAsIA,MAAa8C,qBAAqB;AAElC,MAAaC,eAAeC,QAC1B,CAAC,CAACA,KAAKC,WAAWH,kBAAkB"}
|
|
1
|
+
{"version":3,"file":"message.js","names":["ReadonlyJSONObject","ReadonlyJSONValue","ToolCallTiming","ToolModelContentPart","CompleteAttachment","PartProviderMetadata","providerName","TextMessagePart","type","text","providerMetadata","parentId","ReasoningMessagePart","SourceProviderMetadata","SourceMessagePart","sourceType","id","url","title","mediaType","filename","ImageMessagePart","image","FileMessagePart","data","mimeType","Unstable_AudioMessagePart","audio","format","DataMessagePart","name","T","GenerativeUINode","component","props","Record","children","key","GenerativeUISpec","root","GenerativeUIMessagePart","spec","McpAppMetadata","resourceUri","visibility","serverId","MCP_APP_URI_SCHEME","isMcpAppUri","uri","startsWith","ToolCallMessagePartMcpMetadata","app","ToolApprovalOptionKind","ToolApprovalOption","kind","label","description","grants","confirm","ToolApprovalResponse","approved","reason","optionId","ToolCallMessagePart","toolCallId","toolName","args","TArgs","result","TResult","isError","argsText","artifact","timing","mcp","modelContent","interrupt","payload","approval","isAutomatic","options","resolution","messages","ThreadMessage","ThreadUserMessagePart","ThreadAssistantMessagePart","MessagePartStatus","error","ToolCallMessagePartStatus","MessageStatus","MessageTiming","streamStartTime","firstTokenTime","totalStreamTime","tokenCount","tokensPerSecond","totalChunks","toolCallCount","ThreadStep","messageId","usage","inputTokens","outputTokens","MessageCommonProps","createdAt","Date","ThreadSystemMessage","role","content","metadata","unstable_state","unstable_annotations","unstable_data","steps","submittedFeedback","custom","ThreadUserMessage","attachments","isOptimistic","ThreadAssistantMessage","status","BaseThreadMessage","MessageRole","RunConfig","AppendMessage","Omit","sourceId","runConfig","startRun","steer"],"sources":["../../src/types/message.ts"],"sourcesContent":["import type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ToolCallTiming, ToolModelContentPart } from \"assistant-stream\";\nimport type { CompleteAttachment } from \"./attachment\";\n\nexport type { ToolCallTiming, ToolModelContentPart };\n\nexport type PartProviderMetadata = {\n readonly [providerName: string]: ReadonlyJSONObject;\n};\n\nexport type TextMessagePart = {\n readonly type: \"text\";\n readonly text: string;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type ReasoningMessagePart = {\n readonly type: \"reasoning\";\n readonly text: string;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type SourceProviderMetadata = PartProviderMetadata;\n\nexport type SourceMessagePart =\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly url?: undefined;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n };\n\nexport type ImageMessagePart = {\n readonly type: \"image\";\n readonly image: string;\n readonly filename?: string;\n};\n\nexport type FileMessagePart = {\n readonly type: \"file\";\n readonly filename?: string;\n readonly data: string;\n readonly mimeType: string;\n readonly parentId?: string;\n};\n\nexport type Unstable_AudioMessagePart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\nexport type DataMessagePart<T = any> = {\n readonly type: \"data\";\n readonly name: string;\n readonly data: T;\n};\n\n/**\n * A JSON spec describing a tree of UI components to render.\n *\n * The agent emits a {@link GenerativeUIMessagePart} containing this spec, and\n * the consumer-provided component allowlist is used to resolve `component`\n * names. Any component referenced that is not present in the allowlist is\n * rejected with a typed error — the allowlist is the security boundary in the\n * default same-realm rendering path.\n */\nexport type GenerativeUINode =\n | string\n | {\n /** Allowlisted component name (resolved against the consumer registry). */\n readonly component: string;\n /** Props passed to the resolved component (must be JSON-serializable). */\n readonly props?: Record<string, unknown>;\n /** Optional children — strings render as text, objects recurse. */\n readonly children?: readonly GenerativeUINode[];\n /** Optional stable key for React reconciliation. */\n readonly key?: string;\n };\n\n/**\n * The root spec for a generative UI tree.\n */\nexport type GenerativeUISpec = {\n /** Root node(s) to render. */\n readonly root: GenerativeUINode | readonly GenerativeUINode[];\n};\n\n/**\n * A message part that carries a JSON spec describing UI to render.\n *\n * Render with `<MessagePrimitive.GenerativeUI components={...} />`. The\n * primitive resolves component names against the consumer-provided allowlist\n * — any unknown name throws a typed error rather than rendering. Stream-\n * friendly: a partially-streamed spec renders progressively.\n */\nexport type GenerativeUIMessagePart = {\n readonly type: \"generative-ui\";\n /** The JSON spec describing the UI tree. */\n readonly spec: GenerativeUISpec;\n /** Optional id (useful for replays / stable keys). */\n readonly id?: string;\n readonly parentId?: string;\n};\n\nexport type McpAppMetadata = {\n readonly resourceUri: string;\n readonly mimeType?: string;\n readonly visibility?: readonly (\"model\" | \"app\")[];\n /** Routable server identity emitted by the agent stack when multiple MCP servers back one agent; for @ag-ui/mcp-apps-middleware this is the configured serverId, falling back to its serverHash. */\n readonly serverId?: string;\n};\n\nexport const MCP_APP_URI_SCHEME = \"ui://\";\n\nexport const isMcpAppUri = (uri: string | undefined): boolean =>\n !!uri?.startsWith(MCP_APP_URI_SCHEME);\n\nexport type ToolCallMessagePartMcpMetadata = {\n readonly app?: McpAppMetadata;\n};\n\nexport type ToolApprovalOptionKind =\n | \"allow-once\"\n | \"allow-always\"\n | \"reject-once\"\n | \"reject-always\";\n\nexport type ToolApprovalOption = {\n /** Opaque, host-defined identifier. Scope semantics (session vs project vs global) belong to the option supplier. */\n readonly id: string;\n /**\n * Decision class. Drives approved-resolution and default rendering.\n * Open union: `_`-prefixed custom kinds are never auto-resolved and the\n * default kit skips them; they must be answered with an explicit\n * `approved` value (optionally alongside the `optionId`).\n */\n readonly kind: ToolApprovalOptionKind | (string & {});\n /** Human label. Renderers supply defaults per kind when omitted. */\n readonly label?: string;\n readonly description?: string;\n /** Patterns or rules this option would persist, shown before the user commits. Supplied by the host; never derived by the library. */\n readonly grants?: readonly string[];\n /** Opt-in confirmation step before this option resolves. */\n readonly confirm?: boolean | { title?: string; description?: string };\n};\n\nexport type ToolApprovalResponse =\n | { readonly approved: boolean; readonly reason?: string }\n | { readonly optionId: string; readonly reason?: string }\n | {\n readonly approved: boolean;\n readonly optionId: string;\n readonly reason?: string;\n };\n\nexport type ToolCallMessagePart<\n TArgs = ReadonlyJSONObject,\n TResult = unknown,\n> = {\n /** Identifies this part as a tool call. */\n readonly type: \"tool-call\";\n /** Stable identifier for this invocation of the tool. */\n readonly toolCallId: string;\n /** Name of the tool requested by the model. */\n readonly toolName: string;\n /**\n * Arguments supplied by the model. During streaming this is a partial parse:\n * fields may be missing or incomplete. From a tool-call renderer, use\n * `useToolArgsStatus` to detect which fields are still arriving.\n */\n readonly args: TArgs;\n /** Result returned by the tool, if it has completed. */\n readonly result?: TResult | undefined;\n /** Whether the result represents a tool execution error. */\n readonly isError?: boolean | undefined;\n /** Raw JSON argument text streamed by the model. */\n readonly argsText: string;\n /** UI-only artifact associated with the tool result. */\n readonly artifact?: unknown;\n /** Wall-clock timing for this call, when the runtime or host tracks it. */\n readonly timing?: ToolCallTiming;\n /** MCP app metadata associated with this tool call, when present. */\n readonly mcp?: ToolCallMessagePartMcpMetadata;\n /** Provider metadata associated with this tool call, when present. */\n readonly providerMetadata?: PartProviderMetadata;\n /** Content returned to the model for this tool result. */\n readonly modelContent?: readonly ToolModelContentPart[] | undefined;\n /** Human-input request that must be resolved before the run can continue. */\n readonly interrupt?: { type: \"human\"; payload: unknown };\n /** Server-side approval gate. `respondToApproval` may only be called while `approved` is undefined and no `resolution` is recorded. */\n readonly approval?: {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n /** Available decisions for this call. Absent: a plain allow / deny pair. */\n readonly options?: readonly ToolApprovalOption[];\n /** The option chosen at resolution, when options were present. */\n readonly optionId?: string;\n /** Terminal non-decision state: the request was cancelled or expired without a user decision. Set by the host. */\n readonly resolution?: \"cancelled\" | \"expired\";\n };\n /** Parent message-part ID when this part belongs to a nested structure. */\n readonly parentId?: string;\n /**\n * Nested thread messages produced by this tool call, for example a sub-agent\n * conversation.\n */\n readonly messages?: readonly ThreadMessage[];\n};\n\nexport type ThreadUserMessagePart =\n | TextMessagePart\n | ImageMessagePart\n | FileMessagePart\n | DataMessagePart\n | Unstable_AudioMessagePart;\n\nexport type ThreadAssistantMessagePart =\n | TextMessagePart\n | ReasoningMessagePart\n | ToolCallMessagePart\n | SourceMessagePart\n | FileMessagePart\n | ImageMessagePart\n | DataMessagePart\n | GenerativeUIMessagePart;\n\nexport type MessagePartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type ToolCallMessagePartStatus =\n | {\n /** The tool call is waiting for UI or human input before continuing. */\n readonly type: \"requires-action\";\n /** Reason the tool call requires action. */\n readonly reason: \"interrupt\";\n }\n | MessagePartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\" | \"interrupt\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: ReadonlyJSONValue;\n };\n\nexport type MessageTiming = {\n readonly streamStartTime: number;\n readonly firstTokenTime?: number;\n readonly totalStreamTime?: number;\n readonly tokenCount?: number;\n readonly tokensPerSecond?: number;\n readonly totalChunks: number;\n readonly toolCallCount: number;\n};\n\nexport type ThreadStep = {\n readonly messageId?: string;\n readonly usage?:\n | {\n readonly inputTokens: number;\n readonly outputTokens: number;\n }\n | undefined;\n};\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: readonly [TextMessagePart];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: readonly ThreadUserMessagePart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: readonly ThreadAssistantMessagePart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly unstable_state: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n /**\n * Marks a client-side optimistic placeholder. Such messages are evicted\n * once off the head branch and are never persisted.\n */\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations?: readonly ReadonlyJSONValue[];\n readonly unstable_data?: readonly ReadonlyJSONValue[];\n readonly steps?: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\nexport type MessageRole = ThreadMessage[\"role\"];\n\nexport type RunConfig = {\n readonly custom?: Record<string, unknown>;\n};\n\nexport type AppendMessage = Omit<ThreadMessage, \"id\"> & {\n parentId: string | null;\n\n /** The ID of the message that was edited or undefined. */\n sourceId: string | null;\n runConfig: RunConfig | undefined;\n startRun?: boolean | undefined;\n /** Process this message next; only meaningful for queue-capable runtimes. */\n steer?: boolean | undefined;\n};\n"],"mappings":";AAsIA,MAAa8C,qBAAqB;AAElC,MAAaC,eAAeC,QAC1B,CAAC,CAACA,KAAKC,WAAWH,kBAAkB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/utils/data-url.d.ts
|
|
2
|
+
declare const httpUrlPattern: RegExp;
|
|
3
|
+
declare function parseDataUrl(value: string): {
|
|
4
|
+
mimeType: string;
|
|
5
|
+
data: string;
|
|
6
|
+
} | null;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { httpUrlPattern, parseDataUrl };
|
|
9
|
+
//# sourceMappingURL=data-url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-url.d.ts","names":[],"sources":["../../src/utils/data-url.ts"],"mappings":";cAAa,gBAAc;iBAEX,aACd;EACG;EAAkB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/utils/data-url.ts
|
|
2
|
+
const httpUrlPattern = /^https?:\/\//i;
|
|
3
|
+
function parseDataUrl(value) {
|
|
4
|
+
const match = value.match(/^data:([^;,]+)(?:;[^;,]+)*;base64,(.+)$/);
|
|
5
|
+
if (!match) return null;
|
|
6
|
+
return {
|
|
7
|
+
mimeType: match[1],
|
|
8
|
+
data: match[2]
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { httpUrlPattern, parseDataUrl };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=data-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-url.js","names":["httpUrlPattern","parseDataUrl","value","mimeType","data","match"],"sources":["../../src/utils/data-url.ts"],"sourcesContent":["export const httpUrlPattern = /^https?:\\/\\//i;\n\nexport function parseDataUrl(\n value: string,\n): { mimeType: string; data: string } | null {\n const match = value.match(/^data:([^;,]+)(?:;[^;,]+)*;base64,(.+)$/);\n if (!match) return null;\n return { mimeType: match[1]!, data: match[2]! };\n}\n"],"mappings":";AAAA,MAAaA,iBAAiB;AAE9B,SAAgBC,aACdC,OAC2C;CAC3C,MAAMG,QAAQH,MAAMG,MAAM,yCAAyC;CACnE,IAAI,CAACA,OAAO,OAAO;CACnB,OAAO;EAAEF,UAAUE,MAAM;EAAKD,MAAMC,MAAM;CAAI;AAChD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/utils/notify-event-listeners.d.ts
|
|
2
|
+
type EventListener = (payload?: unknown) => void;
|
|
3
|
+
declare const notifyEventListeners: (listeners: Iterable<EventListener>, payload: unknown, errorContext: string) => void;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { notifyEventListeners };
|
|
6
|
+
//# sourceMappingURL=notify-event-listeners.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notify-event-listeners.d.ts","names":[],"sources":["../../src/utils/notify-event-listeners.ts"],"mappings":";KAAK,iBAAiB;cAET,uBACX,WAAW,SAAS,gBACpB,kBACA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/utils/notify-event-listeners.ts
|
|
2
|
+
const notifyEventListeners = (listeners, payload, errorContext) => {
|
|
3
|
+
const reportError = (error) => {
|
|
4
|
+
console.error(`[assistant-ui] ${errorContext} listener threw an error`, error);
|
|
5
|
+
};
|
|
6
|
+
for (const listener of listeners) try {
|
|
7
|
+
const result = listener(payload);
|
|
8
|
+
if (result !== null && (typeof result === "object" || typeof result === "function") && "then" in result && typeof result.then === "function") Promise.resolve(result).catch(reportError);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
reportError(error);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { notifyEventListeners };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=notify-event-listeners.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notify-event-listeners.js","names":["EventListener","payload","notifyEventListeners","listeners","Iterable","errorContext","reportError","error","console","listener","result","then","Promise","resolve","catch"],"sources":["../../src/utils/notify-event-listeners.ts"],"sourcesContent":["type EventListener = (payload?: unknown) => void;\n\nexport const notifyEventListeners = (\n listeners: Iterable<EventListener>,\n payload: unknown,\n errorContext: string,\n) => {\n const reportError = (error: unknown) => {\n console.error(\n `[assistant-ui] ${errorContext} listener threw an error`,\n error,\n );\n };\n\n for (const listener of listeners) {\n try {\n const result = listener(payload) as unknown;\n if (\n result !== null &&\n (typeof result === \"object\" || typeof result === \"function\") &&\n \"then\" in result &&\n typeof result.then === \"function\"\n ) {\n void Promise.resolve(result).catch(reportError);\n }\n } catch (error) {\n reportError(error);\n }\n }\n};\n"],"mappings":";AAEA,MAAaE,wBACXC,WACAF,SACAI,iBACG;CACH,MAAMC,eAAeC,UAAmB;EACtCC,QAAQD,MACN,kBAAkBF,aAAY,2BAC9BE,KACF;CACF;CAEA,KAAK,MAAME,YAAYN,WACrB,IAAI;EACF,MAAMO,SAASD,SAASR,OAAO;EAC/B,IACES,WAAW,SACV,OAAOA,WAAW,YAAY,OAAOA,WAAW,eACjD,UAAUA,UACV,OAAOA,OAAOC,SAAS,YAEvB,QAAaE,QAAQH,MAAM,CAAC,CAACI,MAAMR,WAAW;CAElD,SAASC,OAAO;EACdD,YAAYC,KAAK;CACnB;AAEJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.22",
|
|
4
4
|
"description": "Framework-agnostic core runtime for assistant-ui",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"assistant",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
],
|
|
60
60
|
"sideEffects": false,
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"assistant-stream": "^0.3.
|
|
62
|
+
"assistant-stream": "^0.3.27",
|
|
63
63
|
"nanoid": "^6.0.0"
|
|
64
64
|
},
|
|
65
65
|
"optionalDevDependencies": {
|
|
@@ -91,15 +91,15 @@
|
|
|
91
91
|
"@testing-library/react": "^16.3.2",
|
|
92
92
|
"@types/react": "^19.2.17",
|
|
93
93
|
"jsdom": "^29.1.1",
|
|
94
|
-
"react": "^19.2.
|
|
95
|
-
"react-dom": "^19.2.
|
|
94
|
+
"react": "^19.2.8",
|
|
95
|
+
"react-dom": "^19.2.8",
|
|
96
96
|
"vitest": "^4.1.10",
|
|
97
97
|
"zustand": "^5.0.14",
|
|
98
|
-
"@assistant-ui/store": "0.2.
|
|
99
|
-
"@assistant-ui/tap": "0.9.
|
|
100
|
-
"@assistant-ui/vite": "0.0.
|
|
101
|
-
"@assistant-ui/x-buildutils": "0.0.
|
|
102
|
-
"assistant-cloud": "0.1.
|
|
98
|
+
"@assistant-ui/store": "0.2.21",
|
|
99
|
+
"@assistant-ui/tap": "0.9.5",
|
|
100
|
+
"@assistant-ui/vite": "0.0.10",
|
|
101
|
+
"@assistant-ui/x-buildutils": "0.0.19",
|
|
102
|
+
"assistant-cloud": "0.1.36"
|
|
103
103
|
},
|
|
104
104
|
"publishConfig": {
|
|
105
105
|
"access": "public",
|
|
@@ -117,6 +117,7 @@
|
|
|
117
117
|
"scripts": {
|
|
118
118
|
"build": "aui-build",
|
|
119
119
|
"test": "vitest run",
|
|
120
|
+
"test:react-compiler": "vitest run --config vitest.react-compiler.config.ts",
|
|
120
121
|
"test:watch": "vitest"
|
|
121
122
|
}
|
|
122
123
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { WebSpeechSynthesisAdapter } from "./speech";
|
|
3
|
+
|
|
4
|
+
afterEach(() => {
|
|
5
|
+
vi.restoreAllMocks();
|
|
6
|
+
vi.unstubAllGlobals();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
describe("WebSpeechSynthesisAdapter", () => {
|
|
10
|
+
it("isolates a late subscriber that throws after the utterance ended", async () => {
|
|
11
|
+
const listeners = new Map<string, EventListener>();
|
|
12
|
+
class MockSpeechSynthesisUtterance {
|
|
13
|
+
addEventListener(type: string, listener: EventListener) {
|
|
14
|
+
listeners.set(type, listener);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
vi.stubGlobal("SpeechSynthesisUtterance", MockSpeechSynthesisUtterance);
|
|
18
|
+
vi.stubGlobal("window", {
|
|
19
|
+
speechSynthesis: {
|
|
20
|
+
speak: vi.fn(),
|
|
21
|
+
cancel: vi.fn(),
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
const listenerError = new Error("late listener failed");
|
|
25
|
+
const consoleError = vi
|
|
26
|
+
.spyOn(console, "error")
|
|
27
|
+
.mockImplementation(() => {});
|
|
28
|
+
|
|
29
|
+
const result = new WebSpeechSynthesisAdapter().speak("Hello");
|
|
30
|
+
listeners.get("end")!(new Event("end"));
|
|
31
|
+
|
|
32
|
+
const lateListener = vi.fn();
|
|
33
|
+
result.subscribe(() => {
|
|
34
|
+
throw listenerError;
|
|
35
|
+
});
|
|
36
|
+
result.subscribe(lateListener);
|
|
37
|
+
await Promise.resolve();
|
|
38
|
+
|
|
39
|
+
expect(consoleError).toHaveBeenCalledWith(
|
|
40
|
+
"[assistant-ui] Speech synthesis listener threw an error",
|
|
41
|
+
listenerError,
|
|
42
|
+
);
|
|
43
|
+
expect(lateListener).toHaveBeenCalledOnce();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("continues notifying listeners when one throws", () => {
|
|
47
|
+
const listeners = new Map<string, EventListener>();
|
|
48
|
+
class MockSpeechSynthesisUtterance {
|
|
49
|
+
addEventListener(type: string, listener: EventListener) {
|
|
50
|
+
listeners.set(type, listener);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const speak = vi.fn();
|
|
54
|
+
vi.stubGlobal("SpeechSynthesisUtterance", MockSpeechSynthesisUtterance);
|
|
55
|
+
vi.stubGlobal("window", {
|
|
56
|
+
speechSynthesis: {
|
|
57
|
+
speak,
|
|
58
|
+
cancel: vi.fn(),
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
const listenerError = new Error("listener failed");
|
|
62
|
+
const consoleError = vi
|
|
63
|
+
.spyOn(console, "error")
|
|
64
|
+
.mockImplementation(() => {});
|
|
65
|
+
const result = new WebSpeechSynthesisAdapter().speak("Hello");
|
|
66
|
+
const laterListener = vi.fn();
|
|
67
|
+
|
|
68
|
+
result.subscribe(() => {
|
|
69
|
+
throw listenerError;
|
|
70
|
+
});
|
|
71
|
+
result.subscribe(laterListener);
|
|
72
|
+
listeners.get("end")?.({} as Event);
|
|
73
|
+
|
|
74
|
+
expect(speak).toHaveBeenCalledWith(
|
|
75
|
+
expect.any(MockSpeechSynthesisUtterance),
|
|
76
|
+
);
|
|
77
|
+
expect(laterListener).toHaveBeenCalledOnce();
|
|
78
|
+
expect(result.status).toEqual({
|
|
79
|
+
type: "ended",
|
|
80
|
+
reason: "finished",
|
|
81
|
+
error: undefined,
|
|
82
|
+
});
|
|
83
|
+
expect(consoleError).toHaveBeenCalledWith(
|
|
84
|
+
"[assistant-ui] Speech synthesis listener threw an error",
|
|
85
|
+
listenerError,
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
});
|
package/src/adapters/speech.ts
CHANGED
|
@@ -22,6 +22,21 @@ export type SpeechSynthesisAdapter = {
|
|
|
22
22
|
speak: (text: string) => SpeechSynthesisAdapter.Utterance;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
const notifySpeechSynthesisListeners = (
|
|
26
|
+
listeners: Iterable<() => void>,
|
|
27
|
+
): void => {
|
|
28
|
+
for (const listener of listeners) {
|
|
29
|
+
try {
|
|
30
|
+
listener();
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error(
|
|
33
|
+
"[assistant-ui] Speech synthesis listener threw an error",
|
|
34
|
+
error,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
25
40
|
export namespace DictationAdapter {
|
|
26
41
|
export type Status =
|
|
27
42
|
| {
|
|
@@ -64,7 +79,7 @@ export class WebSpeechSynthesisAdapter implements SpeechSynthesisAdapter {
|
|
|
64
79
|
if (res.status.type === "ended") return;
|
|
65
80
|
|
|
66
81
|
res.status = { type: "ended", reason, error };
|
|
67
|
-
subscribers
|
|
82
|
+
notifySpeechSynthesisListeners(subscribers);
|
|
68
83
|
};
|
|
69
84
|
|
|
70
85
|
utterance.addEventListener("end", () => handleEnd("finished"));
|
|
@@ -82,7 +97,7 @@ export class WebSpeechSynthesisAdapter implements SpeechSynthesisAdapter {
|
|
|
82
97
|
if (res.status.type === "ended") {
|
|
83
98
|
let cancelled = false;
|
|
84
99
|
queueMicrotask(() => {
|
|
85
|
-
if (!cancelled) callback
|
|
100
|
+
if (!cancelled) notifySpeechSynthesisListeners([callback]);
|
|
86
101
|
});
|
|
87
102
|
return () => {
|
|
88
103
|
cancelled = true;
|