@axiom-lattice/protocols 3.0.4 → 4.0.1
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +47 -0
- package/dist/index.d.mts +424 -150
- package/dist/index.d.ts +424 -150
- package/dist/index.js +266 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +261 -12
- package/dist/index.mjs.map +1 -1
- package/jest.config.js +19 -0
- package/package.json +5 -1
- package/src/A2AApiKeyStoreProtocol.ts +13 -5
- package/src/A2AProtocol.ts +34 -174
- package/src/AgentWebAppRuntimeProtocol.ts +168 -0
- package/src/AgentWebAppStoreProtocol.ts +104 -0
- package/src/SkillStoreProtocol.ts +21 -0
- package/src/TaskBeliefProtocol.ts +324 -0
- package/src/TaskStoreProtocol.ts +94 -3
- package/src/TaskWorkItemProtocol.ts +32 -0
- package/src/WorkspaceStoreProtocol.ts +21 -1
- package/src/__tests__/TaskBeliefProtocol.test.ts +421 -0
- package/src/__tests__/a2a-types.test.ts +30 -0
- package/src/__tests__/agent-web-app-types.test.ts +323 -0
- package/src/index.ts +3 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AgentWebApp,
|
|
3
|
+
AgentWebAppBootstrap,
|
|
4
|
+
AgentWebAppError,
|
|
5
|
+
AgentWebAppErrorCode,
|
|
6
|
+
AgentWebAppFeatures,
|
|
7
|
+
AgentWebAppRuntimeThread,
|
|
8
|
+
AgentWebAppScope,
|
|
9
|
+
AgentWebAppStore,
|
|
10
|
+
AgentWebAppStorePatch,
|
|
11
|
+
AgentWebAppStreamEvent,
|
|
12
|
+
AgentWebAppThreadMetadata,
|
|
13
|
+
CreateAgentWebAppInput,
|
|
14
|
+
UpdateAgentWebAppInput,
|
|
15
|
+
} from "../index";
|
|
16
|
+
|
|
17
|
+
type Equal<Left, Right> =
|
|
18
|
+
(<Value>() => Value extends Left ? 1 : 2) extends
|
|
19
|
+
(<Value>() => Value extends Right ? 1 : 2)
|
|
20
|
+
? (<Value>() => Value extends Right ? 1 : 2) extends
|
|
21
|
+
(<Value>() => Value extends Left ? 1 : 2)
|
|
22
|
+
? true
|
|
23
|
+
: false
|
|
24
|
+
: false;
|
|
25
|
+
|
|
26
|
+
type Expect<Value extends true> = Value;
|
|
27
|
+
|
|
28
|
+
type CreateAgentWebAppInputKeys =
|
|
29
|
+
| "assistantId"
|
|
30
|
+
| "name"
|
|
31
|
+
| "description"
|
|
32
|
+
| "integration"
|
|
33
|
+
| "scope"
|
|
34
|
+
| "features"
|
|
35
|
+
| "appearance";
|
|
36
|
+
type UpdateAgentWebAppInputKeys =
|
|
37
|
+
| "name"
|
|
38
|
+
| "description"
|
|
39
|
+
| "scope"
|
|
40
|
+
| "features"
|
|
41
|
+
| "appearance";
|
|
42
|
+
type AgentWebAppStorePatchKeys = UpdateAgentWebAppInputKeys | "status";
|
|
43
|
+
|
|
44
|
+
type _CreateInputHasExactKeys = Expect<
|
|
45
|
+
Equal<keyof CreateAgentWebAppInput, CreateAgentWebAppInputKeys>
|
|
46
|
+
>;
|
|
47
|
+
type _UpdateInputHasExactKeys = Expect<
|
|
48
|
+
Equal<keyof UpdateAgentWebAppInput, UpdateAgentWebAppInputKeys>
|
|
49
|
+
>;
|
|
50
|
+
type _StorePatchHasExactKeys = Expect<
|
|
51
|
+
Equal<keyof AgentWebAppStorePatch, AgentWebAppStorePatchKeys>
|
|
52
|
+
>;
|
|
53
|
+
type _UpdateScopeIsPartial = Expect<
|
|
54
|
+
Equal<UpdateAgentWebAppInput["scope"], Partial<AgentWebAppScope> | undefined>
|
|
55
|
+
>;
|
|
56
|
+
type _UpdateFeaturesArePartial = Expect<
|
|
57
|
+
Equal<UpdateAgentWebAppInput["features"], Partial<AgentWebAppFeatures> | undefined>
|
|
58
|
+
>;
|
|
59
|
+
type _StoreScopeIsComplete = Expect<
|
|
60
|
+
Equal<AgentWebAppStorePatch["scope"], AgentWebAppScope | undefined>
|
|
61
|
+
>;
|
|
62
|
+
type _StoreFeaturesAreComplete = Expect<
|
|
63
|
+
Equal<AgentWebAppStorePatch["features"], AgentWebAppFeatures | undefined>
|
|
64
|
+
>;
|
|
65
|
+
|
|
66
|
+
type AgentWebAppBootstrapKeys = "webApp" | "projects" | "models" | "thread";
|
|
67
|
+
type AgentWebAppBootstrapWebAppKeys =
|
|
68
|
+
| "id"
|
|
69
|
+
| "name"
|
|
70
|
+
| "description"
|
|
71
|
+
| "assistant"
|
|
72
|
+
| "defaultProjectId"
|
|
73
|
+
| "defaultModelKey"
|
|
74
|
+
| "features"
|
|
75
|
+
| "appearance"
|
|
76
|
+
| "identityAssurance";
|
|
77
|
+
type AgentWebAppBootstrapAssistantKeys = "id" | "name" | "description";
|
|
78
|
+
type AgentWebAppBootstrapProjectKeys = "id" | "name";
|
|
79
|
+
type AgentWebAppBootstrapModelKeys = "key" | "label";
|
|
80
|
+
type AgentWebAppBootstrapFeatureKeys =
|
|
81
|
+
| "projectSelector"
|
|
82
|
+
| "modelSelector"
|
|
83
|
+
| "threadManagement"
|
|
84
|
+
| "attachments"
|
|
85
|
+
| "hitl"
|
|
86
|
+
| "genUI";
|
|
87
|
+
type AgentWebAppBootstrapAppearanceKeys = "title" | "welcomeMessage" | "primaryColor";
|
|
88
|
+
|
|
89
|
+
type _BootstrapHasExactTopLevelKeys = Expect<
|
|
90
|
+
Equal<keyof AgentWebAppBootstrap, AgentWebAppBootstrapKeys>
|
|
91
|
+
>;
|
|
92
|
+
type _BootstrapWebAppHasExactKeys = Expect<
|
|
93
|
+
Equal<keyof AgentWebAppBootstrap["webApp"], AgentWebAppBootstrapWebAppKeys>
|
|
94
|
+
>;
|
|
95
|
+
type _BootstrapAssistantHasExactKeys = Expect<
|
|
96
|
+
Equal<
|
|
97
|
+
keyof AgentWebAppBootstrap["webApp"]["assistant"],
|
|
98
|
+
AgentWebAppBootstrapAssistantKeys
|
|
99
|
+
>
|
|
100
|
+
>;
|
|
101
|
+
type _BootstrapProjectHasExactKeys = Expect<
|
|
102
|
+
Equal<keyof AgentWebAppBootstrap["projects"][number], AgentWebAppBootstrapProjectKeys>
|
|
103
|
+
>;
|
|
104
|
+
type _BootstrapModelHasExactKeys = Expect<
|
|
105
|
+
Equal<keyof AgentWebAppBootstrap["models"][number], AgentWebAppBootstrapModelKeys>
|
|
106
|
+
>;
|
|
107
|
+
type _BootstrapThreadIsNarrowAndOptional = Expect<
|
|
108
|
+
Equal<AgentWebAppBootstrap["thread"], AgentWebAppRuntimeThread | undefined>
|
|
109
|
+
>;
|
|
110
|
+
type _BootstrapFeaturesHaveExactKeys = Expect<
|
|
111
|
+
Equal<
|
|
112
|
+
keyof AgentWebAppBootstrap["webApp"]["features"],
|
|
113
|
+
AgentWebAppBootstrapFeatureKeys
|
|
114
|
+
>
|
|
115
|
+
>;
|
|
116
|
+
type _BootstrapAppearanceHasExactKeys = Expect<
|
|
117
|
+
Equal<
|
|
118
|
+
keyof AgentWebAppBootstrap["webApp"]["appearance"],
|
|
119
|
+
AgentWebAppBootstrapAppearanceKeys
|
|
120
|
+
>
|
|
121
|
+
>;
|
|
122
|
+
|
|
123
|
+
const errorCodes = [
|
|
124
|
+
"WEB_APP_NOT_FOUND",
|
|
125
|
+
"WEB_APP_DISABLED",
|
|
126
|
+
"USER_ID_REQUIRED",
|
|
127
|
+
"INVALID_USER_ID",
|
|
128
|
+
"PROJECT_NOT_ALLOWED",
|
|
129
|
+
"PROJECT_SELECTOR_DISABLED",
|
|
130
|
+
"MODEL_NOT_ALLOWED",
|
|
131
|
+
"FEATURE_DISABLED",
|
|
132
|
+
"THREAD_NOT_FOUND",
|
|
133
|
+
"STREAM_CONFLICT",
|
|
134
|
+
"STREAM_FAILED",
|
|
135
|
+
"INVALID_REQUEST",
|
|
136
|
+
"INTERNAL_ERROR",
|
|
137
|
+
] as const satisfies readonly AgentWebAppErrorCode[];
|
|
138
|
+
|
|
139
|
+
type _ErrorCodesAreExact = Expect<
|
|
140
|
+
Equal<AgentWebAppErrorCode, (typeof errorCodes)[number]>
|
|
141
|
+
>;
|
|
142
|
+
|
|
143
|
+
const streamEventTypes = [
|
|
144
|
+
"message.delta",
|
|
145
|
+
"message.completed",
|
|
146
|
+
"tool.started",
|
|
147
|
+
"tool.completed",
|
|
148
|
+
"interrupt.created",
|
|
149
|
+
"genui.render",
|
|
150
|
+
"error",
|
|
151
|
+
"stream.completed",
|
|
152
|
+
] as const satisfies readonly AgentWebAppStreamEvent["type"][];
|
|
153
|
+
|
|
154
|
+
type _StreamEventTypesAreExact = Expect<
|
|
155
|
+
Equal<AgentWebAppStreamEvent["type"], (typeof streamEventTypes)[number]>
|
|
156
|
+
>;
|
|
157
|
+
|
|
158
|
+
const features = {
|
|
159
|
+
projectSelector: true,
|
|
160
|
+
modelSelector: true,
|
|
161
|
+
threadManagement: true,
|
|
162
|
+
attachments: true,
|
|
163
|
+
hitl: true,
|
|
164
|
+
genUI: true,
|
|
165
|
+
} satisfies CreateAgentWebAppInput["features"];
|
|
166
|
+
|
|
167
|
+
const createInput = {
|
|
168
|
+
assistantId: "assistant-1",
|
|
169
|
+
name: "Customer portal",
|
|
170
|
+
description: "Customer-facing support agent",
|
|
171
|
+
integration: { type: "react_sdk" },
|
|
172
|
+
scope: {
|
|
173
|
+
defaultProjectId: "project-1",
|
|
174
|
+
allowedProjectIds: ["project-1", "project-2"],
|
|
175
|
+
defaultModelKey: "model-1",
|
|
176
|
+
allowedModelKeys: ["model-1", "model-2"],
|
|
177
|
+
},
|
|
178
|
+
features,
|
|
179
|
+
appearance: { title: "Support", primaryColor: "#123456" },
|
|
180
|
+
} satisfies CreateAgentWebAppInput;
|
|
181
|
+
|
|
182
|
+
const webApp = {
|
|
183
|
+
id: "web-app-1",
|
|
184
|
+
tenantId: "tenant-1",
|
|
185
|
+
...createInput,
|
|
186
|
+
status: "draft",
|
|
187
|
+
createdAt: new Date("2026-08-24T00:00:00.000Z"),
|
|
188
|
+
updatedAt: new Date("2026-08-24T00:00:00.000Z"),
|
|
189
|
+
} satisfies AgentWebApp;
|
|
190
|
+
|
|
191
|
+
const updateInput = {
|
|
192
|
+
name: "Updated portal",
|
|
193
|
+
scope: { defaultProjectId: "project-2" },
|
|
194
|
+
features: { modelSelector: false },
|
|
195
|
+
} satisfies UpdateAgentWebAppInput;
|
|
196
|
+
|
|
197
|
+
const storePatch = {
|
|
198
|
+
scope: createInput.scope,
|
|
199
|
+
features,
|
|
200
|
+
} satisfies AgentWebAppStorePatch;
|
|
201
|
+
|
|
202
|
+
// @ts-expect-error Persistence patches replace scope and must be complete.
|
|
203
|
+
const incompleteStoreScope: AgentWebAppStorePatch = { scope: { defaultProjectId: "project-2" } };
|
|
204
|
+
|
|
205
|
+
const threadMetadata = {
|
|
206
|
+
source: "web_app",
|
|
207
|
+
webAppId: webApp.id,
|
|
208
|
+
userId: "external-user-1",
|
|
209
|
+
projectId: "project-1",
|
|
210
|
+
label: "Support request",
|
|
211
|
+
} satisfies AgentWebAppThreadMetadata;
|
|
212
|
+
|
|
213
|
+
const bootstrap = {
|
|
214
|
+
webApp: {
|
|
215
|
+
id: webApp.id,
|
|
216
|
+
name: webApp.name,
|
|
217
|
+
description: webApp.description,
|
|
218
|
+
assistant: {
|
|
219
|
+
id: webApp.assistantId,
|
|
220
|
+
name: "Support agent",
|
|
221
|
+
description: "Answers support questions",
|
|
222
|
+
},
|
|
223
|
+
defaultProjectId: "project-1",
|
|
224
|
+
defaultModelKey: "model-1",
|
|
225
|
+
features,
|
|
226
|
+
appearance: webApp.appearance,
|
|
227
|
+
identityAssurance: "unverified",
|
|
228
|
+
},
|
|
229
|
+
projects: [
|
|
230
|
+
{ id: "project-1", name: "General" },
|
|
231
|
+
{ id: "project-2", name: "Enterprise" },
|
|
232
|
+
],
|
|
233
|
+
models: [
|
|
234
|
+
{ key: "model-1", label: "Fast" },
|
|
235
|
+
{ key: "model-2", label: "Accurate" },
|
|
236
|
+
],
|
|
237
|
+
} satisfies AgentWebAppBootstrap;
|
|
238
|
+
|
|
239
|
+
const error = {
|
|
240
|
+
code: "STREAM_FAILED",
|
|
241
|
+
message: "The stream failed",
|
|
242
|
+
retryable: true,
|
|
243
|
+
} satisfies AgentWebAppError;
|
|
244
|
+
|
|
245
|
+
const events = [
|
|
246
|
+
{ type: "message.delta", text: "Hello" },
|
|
247
|
+
{ type: "message.completed", messageId: "message-1" },
|
|
248
|
+
{ type: "tool.started", id: "tool-1", name: "search" },
|
|
249
|
+
{ type: "tool.completed", id: "tool-1" },
|
|
250
|
+
{
|
|
251
|
+
type: "interrupt.created",
|
|
252
|
+
interrupt: { id: "interrupt-1", type: "approval", prompt: "Continue?" },
|
|
253
|
+
},
|
|
254
|
+
{ type: "genui.render", block: { type: "widget", widget: { kind: "callout", text: "Notice" } } },
|
|
255
|
+
{ type: "error", error },
|
|
256
|
+
{ type: "stream.completed" },
|
|
257
|
+
] satisfies AgentWebAppStreamEvent[];
|
|
258
|
+
|
|
259
|
+
const store = {
|
|
260
|
+
async list(_tenantId: string, _assistantId?: string) {
|
|
261
|
+
return [];
|
|
262
|
+
},
|
|
263
|
+
async getById(_tenantId: string, _webAppId: string) {
|
|
264
|
+
return null;
|
|
265
|
+
},
|
|
266
|
+
async findById(_webAppId: string) {
|
|
267
|
+
return null;
|
|
268
|
+
},
|
|
269
|
+
async create(tenantId: string, input: CreateAgentWebAppInput) {
|
|
270
|
+
return { ...webApp, ...input, tenantId };
|
|
271
|
+
},
|
|
272
|
+
async update(
|
|
273
|
+
_tenantId: string,
|
|
274
|
+
_webAppId: string,
|
|
275
|
+
_patch: AgentWebAppStorePatch,
|
|
276
|
+
_options?: { expectedUpdatedAt?: Date },
|
|
277
|
+
) {
|
|
278
|
+
return null;
|
|
279
|
+
},
|
|
280
|
+
async delete(_tenantId: string, _webAppId: string) {
|
|
281
|
+
return false;
|
|
282
|
+
},
|
|
283
|
+
} satisfies AgentWebAppStore;
|
|
284
|
+
|
|
285
|
+
describe("Agent Web App protocol types", () => {
|
|
286
|
+
it("keeps stable public error code discriminants", () => {
|
|
287
|
+
expect(errorCodes).toEqual([
|
|
288
|
+
"WEB_APP_NOT_FOUND",
|
|
289
|
+
"WEB_APP_DISABLED",
|
|
290
|
+
"USER_ID_REQUIRED",
|
|
291
|
+
"INVALID_USER_ID",
|
|
292
|
+
"PROJECT_NOT_ALLOWED",
|
|
293
|
+
"PROJECT_SELECTOR_DISABLED",
|
|
294
|
+
"MODEL_NOT_ALLOWED",
|
|
295
|
+
"FEATURE_DISABLED",
|
|
296
|
+
"THREAD_NOT_FOUND",
|
|
297
|
+
"STREAM_CONFLICT",
|
|
298
|
+
"STREAM_FAILED",
|
|
299
|
+
"INVALID_REQUEST",
|
|
300
|
+
"INTERNAL_ERROR",
|
|
301
|
+
]);
|
|
302
|
+
expect(error.code).toBe("STREAM_FAILED");
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("keeps stable public stream event discriminants", () => {
|
|
306
|
+
expect(streamEventTypes).toEqual([
|
|
307
|
+
"message.delta",
|
|
308
|
+
"message.completed",
|
|
309
|
+
"tool.started",
|
|
310
|
+
"tool.completed",
|
|
311
|
+
"interrupt.created",
|
|
312
|
+
"genui.render",
|
|
313
|
+
"error",
|
|
314
|
+
"stream.completed",
|
|
315
|
+
]);
|
|
316
|
+
expect(events.map((event) => event.type)).toEqual(streamEventTypes);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
void updateInput;
|
|
321
|
+
void threadMetadata;
|
|
322
|
+
void bootstrap;
|
|
323
|
+
void store;
|
package/src/index.ts
CHANGED
|
@@ -39,12 +39,15 @@ export * from "./MenuProtocol";
|
|
|
39
39
|
export * from "./EvalStoreProtocol";
|
|
40
40
|
export * from "./TaskStoreProtocol";
|
|
41
41
|
export * from "./TaskWorkItemProtocol";
|
|
42
|
+
export * from "./TaskBeliefProtocol";
|
|
42
43
|
|
|
43
44
|
export * from "./LocalA2ATemplateConfig";
|
|
44
45
|
export * from "./ChannelAdapterProtocol";
|
|
45
46
|
export * from "./A2AProtocol";
|
|
46
47
|
export * from "./A2AApiKeyStoreProtocol";
|
|
47
48
|
export * from "./ConversationStoreProtocol";
|
|
49
|
+
export * from "./AgentWebAppStoreProtocol";
|
|
50
|
+
export * from "./AgentWebAppRuntimeProtocol";
|
|
48
51
|
|
|
49
52
|
// Workflow DSL (concise, public API)
|
|
50
53
|
export * from "./WorkflowDSL";
|