feat: add ui/update-model-context (#125)
--------- Co-authored-by: Olivier Chafik <ochafik@anthropic.com>
This commit is contained in:
parent
9acc52cb96
commit
b273279849
1 changed files with 918 additions and 3 deletions
|
|
@ -442,6 +442,82 @@ describe("App <-> AppBridge integration", () => {
|
|||
logger: "TestApp",
|
||||
});
|
||||
});
|
||||
|
||||
it("app.updateModelContext triggers bridge.onupdatemodelcontext and returns result", async () => {
|
||||
const receivedContexts: unknown[] = [];
|
||||
bridge.onupdatemodelcontext = async (params) => {
|
||||
receivedContexts.push(params);
|
||||
return {};
|
||||
};
|
||||
|
||||
await app.connect(appTransport);
|
||||
const result = await app.updateModelContext({
|
||||
content: [{ type: "text", text: "User selected 3 items" }],
|
||||
});
|
||||
|
||||
expect(receivedContexts).toHaveLength(1);
|
||||
expect(receivedContexts[0]).toMatchObject({
|
||||
content: [{ type: "text", text: "User selected 3 items" }],
|
||||
});
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
|
||||
it("app.updateModelContext works with multiple content blocks", async () => {
|
||||
const receivedContexts: unknown[] = [];
|
||||
bridge.onupdatemodelcontext = async (params) => {
|
||||
receivedContexts.push(params);
|
||||
return {};
|
||||
};
|
||||
|
||||
await app.connect(appTransport);
|
||||
const result = await app.updateModelContext({
|
||||
content: [
|
||||
{ type: "text", text: "Filter applied" },
|
||||
{ type: "text", text: "Category: electronics" },
|
||||
],
|
||||
});
|
||||
|
||||
expect(receivedContexts).toHaveLength(1);
|
||||
expect(receivedContexts[0]).toMatchObject({
|
||||
content: [
|
||||
{ type: "text", text: "Filter applied" },
|
||||
{ type: "text", text: "Category: electronics" },
|
||||
],
|
||||
});
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
|
||||
it("app.updateModelContext works with structuredContent", async () => {
|
||||
const receivedContexts: unknown[] = [];
|
||||
bridge.onupdatemodelcontext = async (params) => {
|
||||
receivedContexts.push(params);
|
||||
return {};
|
||||
};
|
||||
|
||||
await app.connect(appTransport);
|
||||
const result = await app.updateModelContext({
|
||||
structuredContent: { selectedItems: 3, total: 150.0, currency: "USD" },
|
||||
});
|
||||
|
||||
expect(receivedContexts).toHaveLength(1);
|
||||
expect(receivedContexts[0]).toMatchObject({
|
||||
structuredContent: { selectedItems: 3, total: 150.0, currency: "USD" },
|
||||
});
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
|
||||
it("app.updateModelContext throws when handler throws", async () => {
|
||||
bridge.onupdatemodelcontext = async () => {
|
||||
throw new Error("Context update failed");
|
||||
};
|
||||
|
||||
await app.connect(appTransport);
|
||||
await expect(
|
||||
app.updateModelContext({
|
||||
content: [{ type: "text", text: "Test" }],
|
||||
}),
|
||||
).rejects.toThrow("Context update failed");
|
||||
});
|
||||
});
|
||||
|
||||
describe("App -> Host requests", () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue