@assistant-ui/core 0.3.8 → 0.3.10

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 (37) hide show
  1. package/dist/model-context/frame/provider.js +1 -3
  2. package/dist/model-context/frame/provider.js.map +1 -1
  3. package/dist/model-context/types.js +4 -2
  4. package/dist/model-context/types.js.map +1 -1
  5. package/dist/react/AssistantProvider.js +5 -4
  6. package/dist/react/AssistantProvider.js.map +1 -1
  7. package/dist/react/adapters/LocalStorageThreadListAdapter.js +2 -1
  8. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  9. package/dist/react/client/Interactables.js +12 -10
  10. package/dist/react/client/Interactables.js.map +1 -1
  11. package/dist/react/model-context/useInteractable.js.map +1 -1
  12. package/dist/react/primitives/message/MessageGroupedParts.js +11 -8
  13. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  14. package/dist/react/primitives/message/MessageParts.js +27 -22
  15. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  16. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +5 -4
  17. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
  18. package/dist/react/runtimes/external-message-converter.js +3 -1
  19. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  20. package/dist/react/runtimes/useLocalRuntime.js +2 -1
  21. package/dist/react/runtimes/useLocalRuntime.js.map +1 -1
  22. package/dist/runtime/api/message-runtime.js +4 -2
  23. package/dist/runtime/api/message-runtime.js.map +1 -1
  24. package/dist/runtime/base/base-composer-runtime-core.d.ts +1 -1
  25. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  26. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +9 -5
  27. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  28. package/dist/runtimes/local/local-thread-runtime-core.js +9 -6
  29. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  30. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +31 -28
  31. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  32. package/dist/subscribable/subscribable.js +6 -4
  33. package/dist/subscribable/subscribable.js.map +1 -1
  34. package/package.json +10 -10
  35. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +5 -1
  36. package/src/runtimes/local/local-thread-runtime-core.test.ts +18 -22
  37. package/src/tests/external-store-thread-runtime-core.test.ts +36 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/core",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "Framework-agnostic core runtime for assistant-ui",
5
5
  "keywords": [
6
6
  "assistant",
@@ -59,8 +59,8 @@
59
59
  ],
60
60
  "sideEffects": false,
61
61
  "dependencies": {
62
- "assistant-stream": "^0.3.35",
63
- "nanoid": "^6.0.0"
62
+ "assistant-stream": "^0.3.36",
63
+ "nanoid": "^6.0.1"
64
64
  },
65
65
  "optionalDevDependencies": {
66
66
  "@assistant-ui/x-generative-compiler": ">=0.0.3"
@@ -89,17 +89,17 @@
89
89
  },
90
90
  "devDependencies": {
91
91
  "@testing-library/react": "^16.3.2",
92
- "@types/react": "^19.2.17",
93
- "jsdom": "^29.1.1",
92
+ "@types/react": "^19.2.18",
93
+ "jsdom": "^30.0.1",
94
94
  "react": "^19.2.8",
95
95
  "react-dom": "^19.2.8",
96
96
  "vitest": "^4.1.10",
97
97
  "zustand": "^5.0.14",
98
- "@assistant-ui/store": "0.3.7",
99
- "@assistant-ui/tap": "0.9.10",
100
- "@assistant-ui/vite": "0.0.11",
101
- "@assistant-ui/x-buildutils": "0.0.21",
102
- "assistant-cloud": "0.1.38"
98
+ "@assistant-ui/store": "0.3.8",
99
+ "@assistant-ui/tap": "0.9.11",
100
+ "@assistant-ui/vite": "0.0.12",
101
+ "@assistant-ui/x-buildutils": "0.0.22",
102
+ "assistant-cloud": "0.1.39"
103
103
  },
104
104
  "publishConfig": {
105
105
  "access": "public",
@@ -466,7 +466,11 @@ export class ExternalStoreThreadRuntimeCore
466
466
  }
467
467
 
468
468
  public async append(message: AppendMessage): Promise<void> {
469
- const isEdit = message.parentId !== (this.messages.at(-1)?.id ?? null);
469
+ // sourceId marks an edit send; the parent may coincide with the head
470
+ // after a resync (e.g. cancelRun dropped the edited message).
471
+ const isEdit =
472
+ message.sourceId != null ||
473
+ message.parentId !== (this.messages.at(-1)?.id ?? null);
470
474
 
471
475
  // Buffering does not start a run, so the tool-abort below must wait until
472
476
  // the queue flushes. By then the prior run (and its tools) has settled.
@@ -1186,12 +1186,10 @@ describe("LocalThreadRuntimeCore runs", () => {
1186
1186
  };
1187
1187
 
1188
1188
  it("appends the user message and the adapter result", async () => {
1189
- const run = vi.fn(
1190
- async (): Promise<ChatModelRunResult> => ({
1191
- content: [{ type: "text", text: "Hello!" }],
1192
- status: { type: "complete", reason: "stop" },
1193
- }),
1194
- );
1189
+ const run = vi.fn(async (): Promise<ChatModelRunResult> => ({
1190
+ content: [{ type: "text", text: "Hello!" }],
1191
+ status: { type: "complete", reason: "stop" },
1192
+ }));
1195
1193
  const thread = createPlainThread({ run });
1196
1194
 
1197
1195
  await thread.append(userMessage("Hi"));
@@ -1247,23 +1245,21 @@ describe("LocalThreadRuntimeCore runs", () => {
1247
1245
  });
1248
1246
 
1249
1247
  it("does not run again after a tool result once maxSteps is reached", async () => {
1250
- const run = vi.fn(
1251
- async (): Promise<ChatModelRunResult> => ({
1252
- content: [
1253
- {
1254
- type: "tool-call",
1255
- toolCallId: "tc1",
1256
- toolName: "myTool",
1257
- args: {},
1258
- argsText: "{}",
1259
- },
1260
- ],
1261
- status: { type: "requires-action", reason: "tool-calls" },
1262
- metadata: {
1263
- steps: [{ usage: { promptTokens: 10, completionTokens: 5 } }],
1248
+ const run = vi.fn(async (): Promise<ChatModelRunResult> => ({
1249
+ content: [
1250
+ {
1251
+ type: "tool-call",
1252
+ toolCallId: "tc1",
1253
+ toolName: "myTool",
1254
+ args: {},
1255
+ argsText: "{}",
1264
1256
  },
1265
- }),
1266
- );
1257
+ ],
1258
+ status: { type: "requires-action", reason: "tool-calls" },
1259
+ metadata: {
1260
+ steps: [{ usage: { promptTokens: 10, completionTokens: 5 } }],
1261
+ },
1262
+ }));
1267
1263
  const thread = createPlainThread({ run }, { maxSteps: 1 });
1268
1264
 
1269
1265
  await thread.append(userMessage("Tool call"));
@@ -883,6 +883,42 @@ describe("ExternalStoreThreadRuntimeCore - message queue", () => {
883
883
  expect(queue.steer).toHaveBeenCalledTimes(1);
884
884
  });
885
885
 
886
+ it("routes an edit send to onEdit even when anchored at the head", async () => {
887
+ const queue = makeQueue();
888
+ const onNew = vi.fn();
889
+ const onEdit = vi.fn();
890
+ const runtime = new ExternalStoreThreadRuntimeCore(
891
+ mockContextProvider,
892
+ makeStore({ queue, onNew, onEdit }),
893
+ );
894
+
895
+ await runtime.append(appendMessage({ sourceId: "u1" }));
896
+
897
+ expect(onEdit).toHaveBeenCalledTimes(1);
898
+ expect(onEdit.mock.calls[0]![0]).toMatchObject({
899
+ sourceId: "u1",
900
+ parentId: null,
901
+ });
902
+ expect(onNew).not.toHaveBeenCalled();
903
+ expect(queue.enqueue).not.toHaveBeenCalled();
904
+ expect(queue.steer).not.toHaveBeenCalled();
905
+ });
906
+
907
+ it("throws the edit capability error for an edit send instead of queueing it", async () => {
908
+ const queue = makeQueue();
909
+ const onNew = vi.fn();
910
+ const runtime = new ExternalStoreThreadRuntimeCore(
911
+ mockContextProvider,
912
+ makeStore({ queue, onNew }),
913
+ );
914
+
915
+ await expect(
916
+ runtime.append(appendMessage({ sourceId: "u1" })),
917
+ ).rejects.toThrow("Runtime does not support editing messages.");
918
+ expect(onNew).not.toHaveBeenCalled();
919
+ expect(queue.enqueue).not.toHaveBeenCalled();
920
+ });
921
+
886
922
  it("defaults a mid-run send to steer and an idle send to enqueue", async () => {
887
923
  const queue = makeQueue();
888
924
  const running = new ExternalStoreThreadRuntimeCore(