feat: add ui/update-model-context (#125)

---------

Co-authored-by: Olivier Chafik <ochafik@anthropic.com>
This commit is contained in:
Ido Salomon 2026-01-12 17:21:45 +02:00 • committed by GitHub
commit b273279849
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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", () => {