@assistant-ui/react 0.10.44 → 0.10.46
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/model-context/frame/AssistantFrameHost.d.ts +37 -0
- package/dist/model-context/frame/AssistantFrameHost.d.ts.map +1 -0
- package/dist/model-context/frame/AssistantFrameHost.js +151 -0
- package/dist/model-context/frame/AssistantFrameHost.js.map +1 -0
- package/dist/model-context/frame/AssistantFrameProvider.d.ts +41 -0
- package/dist/model-context/frame/AssistantFrameProvider.d.ts.map +1 -0
- package/dist/model-context/frame/AssistantFrameProvider.js +142 -0
- package/dist/model-context/frame/AssistantFrameProvider.js.map +1 -0
- package/dist/model-context/frame/AssistantFrameTypes.d.ts +29 -0
- package/dist/model-context/frame/AssistantFrameTypes.d.ts.map +1 -0
- package/dist/model-context/frame/AssistantFrameTypes.js +6 -0
- package/dist/model-context/frame/AssistantFrameTypes.js.map +1 -0
- package/dist/model-context/frame/index.d.ts +5 -0
- package/dist/model-context/frame/index.d.ts.map +1 -0
- package/dist/model-context/frame/index.js +6 -0
- package/dist/model-context/frame/index.js.map +1 -0
- package/dist/model-context/frame/useAssistantFrameHost.d.ts +28 -0
- package/dist/model-context/frame/useAssistantFrameHost.d.ts.map +1 -0
- package/dist/model-context/frame/useAssistantFrameHost.js +25 -0
- package/dist/model-context/frame/useAssistantFrameHost.js.map +1 -0
- package/dist/model-context/index.d.ts +2 -0
- package/dist/model-context/index.d.ts.map +1 -1
- package/dist/model-context/index.js +2 -0
- package/dist/model-context/index.js.map +1 -1
- package/dist/model-context/registry/ModelContextRegistry.d.ts +19 -0
- package/dist/model-context/registry/ModelContextRegistry.d.ts.map +1 -0
- package/dist/model-context/registry/ModelContextRegistry.js +117 -0
- package/dist/model-context/registry/ModelContextRegistry.js.map +1 -0
- package/dist/model-context/registry/ModelContextRegistryHandles.d.ts +14 -0
- package/dist/model-context/registry/ModelContextRegistryHandles.d.ts.map +1 -0
- package/dist/model-context/registry/ModelContextRegistryHandles.js +1 -0
- package/dist/model-context/registry/ModelContextRegistryHandles.js.map +1 -0
- package/dist/model-context/registry/index.d.ts +3 -0
- package/dist/model-context/registry/index.d.ts.map +1 -0
- package/dist/model-context/registry/index.js +4 -0
- package/dist/model-context/registry/index.js.map +1 -0
- package/dist/model-context/useAssistantInstructions.d.ts +1 -2
- package/dist/model-context/useAssistantInstructions.d.ts.map +1 -1
- package/dist/model-context/useAssistantInstructions.js.map +1 -1
- package/dist/runtimes/utils/MessageRepository.d.ts.map +1 -1
- package/dist/runtimes/utils/MessageRepository.js +15 -2
- package/dist/runtimes/utils/MessageRepository.js.map +1 -1
- package/package.json +3 -3
- package/src/model-context/frame/AssistantFrame.test.ts +353 -0
- package/src/model-context/frame/AssistantFrameHost.ts +218 -0
- package/src/model-context/frame/AssistantFrameProvider.ts +225 -0
- package/src/model-context/frame/AssistantFrameTypes.ts +40 -0
- package/src/model-context/frame/SPEC_AssistantFrame.md +104 -0
- package/src/model-context/frame/index.ts +4 -0
- package/src/model-context/frame/useAssistantFrameHost.ts +48 -0
- package/src/model-context/index.ts +3 -0
- package/src/model-context/registry/ModelContextRegistry.ts +165 -0
- package/src/model-context/registry/ModelContextRegistryHandles.ts +19 -0
- package/src/model-context/registry/SPEC_ModelContextRegistry.md +40 -0
- package/src/model-context/registry/index.ts +2 -0
- package/src/model-context/useAssistantInstructions.tsx +1 -1
- package/src/runtimes/utils/MessageRepository.tsx +17 -2
- package/src/tests/MessageRepository.test.ts +45 -0
@@ -414,8 +414,7 @@ export class MessageRepository {
|
|
414
414
|
*/
|
415
415
|
resetHead(messageId: string | null) {
|
416
416
|
if (messageId === null) {
|
417
|
-
this.
|
418
|
-
this._messages.dirty();
|
417
|
+
this.clear();
|
419
418
|
return;
|
420
419
|
}
|
421
420
|
|
@@ -425,6 +424,22 @@ export class MessageRepository {
|
|
425
424
|
"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui.",
|
426
425
|
);
|
427
426
|
|
427
|
+
if (message.children.length > 0) {
|
428
|
+
const deleteDescendants = (msg: RepositoryMessage) => {
|
429
|
+
for (const childId of msg.children) {
|
430
|
+
const childMessage = this.messages.get(childId);
|
431
|
+
if (childMessage) {
|
432
|
+
deleteDescendants(childMessage);
|
433
|
+
this.messages.delete(childId);
|
434
|
+
}
|
435
|
+
}
|
436
|
+
};
|
437
|
+
deleteDescendants(message);
|
438
|
+
|
439
|
+
message.children = [];
|
440
|
+
message.next = null;
|
441
|
+
}
|
442
|
+
|
428
443
|
this.head = message;
|
429
444
|
for (
|
430
445
|
let current: RepositoryMessage | null = message;
|
@@ -308,6 +308,51 @@ describe("MessageRepository", () => {
|
|
308
308
|
expect(messages.map((m) => m.id)).toEqual(["parent-id"]);
|
309
309
|
});
|
310
310
|
|
311
|
+
/**
|
312
|
+
* Tests that resetting head to a message with children removes those children.
|
313
|
+
* All descendants should be deleted from the repository.
|
314
|
+
*/
|
315
|
+
it("should remove children when resetting head to a message with children", () => {
|
316
|
+
const parent = createTestMessage({ id: "parent-id" });
|
317
|
+
const child = createTestMessage({ id: "child-id" });
|
318
|
+
const grandchild1 = createTestMessage({ id: "grandchild1-id" });
|
319
|
+
const grandchild2 = createTestMessage({ id: "grandchild2-id" });
|
320
|
+
const greatGrandchild = createTestMessage({ id: "greatgrandchild-id" });
|
321
|
+
|
322
|
+
// Build tree: parent -> child -> grandchild1
|
323
|
+
// \-> grandchild2 -> greatGrandchild
|
324
|
+
repository.addOrUpdateMessage(null, parent);
|
325
|
+
repository.addOrUpdateMessage("parent-id", child);
|
326
|
+
repository.addOrUpdateMessage("child-id", grandchild1);
|
327
|
+
repository.addOrUpdateMessage("child-id", grandchild2);
|
328
|
+
repository.addOrUpdateMessage("grandchild2-id", greatGrandchild);
|
329
|
+
|
330
|
+
// Reset to child (which has children)
|
331
|
+
repository.resetHead("child-id");
|
332
|
+
|
333
|
+
// Head should be child
|
334
|
+
expect(repository.headId).toBe("child-id");
|
335
|
+
|
336
|
+
// Messages should only include parent and child
|
337
|
+
const messages = repository.getMessages();
|
338
|
+
expect(messages.map((m) => m.id)).toEqual(["parent-id", "child-id"]);
|
339
|
+
|
340
|
+
// Verify children are removed from repository
|
341
|
+
expect(() => repository.getMessage("grandchild1-id")).toThrow(
|
342
|
+
/Message not found/,
|
343
|
+
);
|
344
|
+
expect(() => repository.getMessage("grandchild2-id")).toThrow(
|
345
|
+
/Message not found/,
|
346
|
+
);
|
347
|
+
expect(() => repository.getMessage("greatgrandchild-id")).toThrow(
|
348
|
+
/Message not found/,
|
349
|
+
);
|
350
|
+
|
351
|
+
// Verify branches are empty for the child
|
352
|
+
const branches = repository.getBranches("child-id");
|
353
|
+
expect(branches).toEqual(["child-id"]);
|
354
|
+
});
|
355
|
+
|
311
356
|
/**
|
312
357
|
* Tests resetting the head to null.
|
313
358
|
* This should clear the active branch completely.
|