@adecore/agent-contracts 0.20.1 → 0.21.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/dist/chat.d.ts +1455 -0
- package/dist/chat.js +89 -4
- package/dist/protocol.d.ts +988 -0
- package/dist/protocol.js +4 -1
- package/package.json +2 -1
- package/src/chat.ts +111 -4
- package/src/protocol.ts +8 -0
package/dist/protocol.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { ChatAddBookmarkPayloadSchema, ChatAnswerPayloadSchema, ChatApprovePayloadSchema, ChatAttachPayloadSchema, ChatAttachResultSchema, ChatBookmarksEventSchema, ChatBookmarksResultSchema, ChatCancelPayloadSchema, ChatClearPayloadSchema, ChatConfigurePayloadSchema, ChatContinueOnPayloadSchema, ChatContinueOnResultSchema, ChatCreatePayloadSchema, ChatDismissPayloadSchema, ChatEventEnvelopeSchema, ChatForkInfoPayloadSchema, ChatForkInfoResultSchema, ChatForkPayloadSchema, ChatForkResultSchema, ChatHistoryPayloadSchema, ChatHistoryResultSchema, ChatInfoSchema, ChatListResultSchema, ChatPreferencesPayloadSchema, ChatQueuePayloadSchema, ChatRemoveBookmarkPayloadSchema, ChatRemoveVisualPayloadSchema, ChatRenameBookmarkPayloadSchema, ChatSendPayloadSchema, ChatSendResultSchema, ChatStatusEventSchema, ChatStopSubagentPayloadSchema, ChatStopTaskPayloadSchema, ChatSubagentChangedEventSchema, ChatSubagentPayloadSchema, ChatSubagentResultSchema, ChatSummarizePayloadSchema, ChatSummarizeResultSchema, ChatTargetPayloadSchema, ChatTurnDiffPayloadSchema, ChatTurnDiffResultSchema, ChatUnqueueResultSchema, ChatVisualsEventSchema, ChatVisualsResultSchema, SkillsListPayloadSchema, SkillsListResultSchema } from './chat.js';
|
|
2
|
+
import { ChatAddBookmarkPayloadSchema, ChatAnswerPayloadSchema, ChatApprovePayloadSchema, ChatAttachPayloadSchema, ChatAttachResultSchema, ChatBookmarksEventSchema, ChatBookmarksResultSchema, ChatCancelPayloadSchema, ChatClearPayloadSchema, ChatConfigurePayloadSchema, ChatContinueOnPayloadSchema, ChatContinueOnResultSchema, ChatCreatePayloadSchema, ChatDismissPayloadSchema, ChatEventEnvelopeSchema, ChatForkInfoPayloadSchema, ChatForkInfoResultSchema, ChatForkPayloadSchema, ChatForkResultSchema, ChatHistoryPayloadSchema, ChatHistoryResultSchema, ChatInfoSchema, ChatListResultSchema, ChatPreferencesPayloadSchema, ChatQueuePayloadSchema, ChatRemoveBookmarkPayloadSchema, ChatRemoveVisualPayloadSchema, ChatRenameBookmarkPayloadSchema, ChatSendPayloadSchema, ChatSendResultSchema, ChatUiChoicePayloadSchema, ChatUiLinkPayloadSchema, ChatUiLinkReadingSchema, ChatUiQueryPayloadSchema, ChatUiQueryReadingSchema, ChatStatusEventSchema, ChatStopSubagentPayloadSchema, ChatStopTaskPayloadSchema, ChatSubagentChangedEventSchema, ChatSubagentPayloadSchema, ChatSubagentResultSchema, ChatSummarizePayloadSchema, ChatSummarizeResultSchema, ChatTargetPayloadSchema, ChatTurnDiffPayloadSchema, ChatTurnDiffResultSchema, ChatUnqueueResultSchema, ChatVisualsEventSchema, ChatVisualsResultSchema, SkillsListPayloadSchema, SkillsListResultSchema } from './chat.js';
|
|
3
3
|
import { ProviderListResultSchema } from './model.js';
|
|
4
4
|
import { ProviderAccountCreatePayloadSchema, ProviderAccountCreateResultSchema, ProviderAccountWatchLoginPayloadSchema, ProviderAccountsSavePayloadSchema, ProviderAccountsSchema } from './provider-accounts.js';
|
|
5
5
|
import { UsageChangedEventSchema, UsageLimitsSnapshotSchema, UsageSummaryPayloadSchema, UsageSummaryResultSchema } from './usage.js';
|
|
@@ -15,6 +15,9 @@ export const AGENT_REQUEST_SCHEMAS = {
|
|
|
15
15
|
'chat.attach': { payload: ChatAttachPayloadSchema, result: ChatAttachResultSchema },
|
|
16
16
|
'chat.detach': { payload: ChatTargetPayloadSchema, result: EmptySchema },
|
|
17
17
|
'chat.send': { payload: ChatSendPayloadSchema, result: ChatSendResultSchema },
|
|
18
|
+
'chat.uiChoice': { payload: ChatUiChoicePayloadSchema, result: ChatSendResultSchema },
|
|
19
|
+
'ui.link': { payload: ChatUiLinkPayloadSchema, result: ChatUiLinkReadingSchema },
|
|
20
|
+
'ui.query': { payload: ChatUiQueryPayloadSchema, result: ChatUiQueryReadingSchema },
|
|
18
21
|
'chat.unqueue': { payload: ChatQueuePayloadSchema, result: ChatUnqueueResultSchema },
|
|
19
22
|
'chat.sendNow': { payload: ChatQueuePayloadSchema, result: EmptySchema },
|
|
20
23
|
'chat.cancel': { payload: ChatCancelPayloadSchema, result: EmptySchema },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adecore/agent-contracts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.1",
|
|
4
4
|
"description": "Schemas and port contracts for agent chats, provider accounts, models and usage.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"test": "bun --conditions=source test"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
+
"@adecore/intelligent-ui": "0.21.1",
|
|
84
85
|
"zod": "^4.6.5"
|
|
85
86
|
},
|
|
86
87
|
"devDependencies": {
|
package/src/chat.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { UiLinkResolutionSchema } from '@adecore/intelligent-ui/links';
|
|
1
2
|
import { z } from 'zod';
|
|
3
|
+
import { UiBlocksSchema } from '@adecore/intelligent-ui/protocol';
|
|
2
4
|
import { AgentKindSchema, AgentStatusSchema, SuggestedTitleSchema } from './agent.ts';
|
|
3
5
|
import { WorktreeSchema } from './worktree.ts';
|
|
4
6
|
import { ModelSelectionSchema, RuntimeModeSchema } from './model.ts';
|
|
@@ -95,10 +97,31 @@ export const ChatAttachmentSchema = z.object({
|
|
|
95
97
|
mime: z.string(),
|
|
96
98
|
size: z.number().int().nonnegative(),
|
|
97
99
|
// Absolute, on the machine the daemon runs on.
|
|
98
|
-
path: z.string()
|
|
100
|
+
path: z.string(),
|
|
101
|
+
width: z.number().int().positive().optional(),
|
|
102
|
+
height: z.number().int().positive().optional()
|
|
99
103
|
});
|
|
100
104
|
export type ChatAttachment = z.infer<typeof ChatAttachmentSchema>;
|
|
101
105
|
|
|
106
|
+
export const ChatUiChoiceOriginSchema = z.object({
|
|
107
|
+
itemId: z.string().min(1),
|
|
108
|
+
blockId: z.string().min(1),
|
|
109
|
+
revision: z.string().min(1),
|
|
110
|
+
choiceId: z.string().min(1),
|
|
111
|
+
label: z.string().min(1),
|
|
112
|
+
sourceAt: z.number().nonnegative(),
|
|
113
|
+
older: z.boolean(),
|
|
114
|
+
values: z.record(z.string(), z.unknown()).optional(),
|
|
115
|
+
at: z.number().nonnegative()
|
|
116
|
+
});
|
|
117
|
+
export type ChatUiChoiceOrigin = z.infer<typeof ChatUiChoiceOriginSchema>;
|
|
118
|
+
|
|
119
|
+
export const ChatUiAnswerSchema = ChatUiChoiceOriginSchema.extend({
|
|
120
|
+
queued: z.boolean(),
|
|
121
|
+
turnId: z.string().min(1)
|
|
122
|
+
});
|
|
123
|
+
export type ChatUiAnswer = z.infer<typeof ChatUiAnswerSchema>;
|
|
124
|
+
|
|
102
125
|
// A message typed while a turn was running; the daemon sends it when that turn settles.
|
|
103
126
|
export const ChatQueuedMessageSchema = z.object({
|
|
104
127
|
id: z.string().min(1),
|
|
@@ -109,7 +132,8 @@ export const ChatQueuedMessageSchema = z.object({
|
|
|
109
132
|
skills: z.array(z.string()).optional(),
|
|
110
133
|
chats: z.array(z.string()).optional(),
|
|
111
134
|
attachments: z.array(ChatAttachmentSchema).optional(),
|
|
112
|
-
createdAt: z.number()
|
|
135
|
+
createdAt: z.number(),
|
|
136
|
+
uiChoice: ChatUiChoiceOriginSchema.optional()
|
|
113
137
|
});
|
|
114
138
|
export type ChatQueuedMessage = z.infer<typeof ChatQueuedMessageSchema>;
|
|
115
139
|
|
|
@@ -279,12 +303,47 @@ export const ChatUserItemSchema = z.object({
|
|
|
279
303
|
skills: z.array(z.string()).optional(),
|
|
280
304
|
// Chats of the same project the person picked with `@`. Only their ids travel; the agent reads them itself.
|
|
281
305
|
chats: z.array(z.string()).optional(),
|
|
282
|
-
attachments: z.array(ChatAttachmentSchema).optional()
|
|
306
|
+
attachments: z.array(ChatAttachmentSchema).optional(),
|
|
307
|
+
uiChoice: ChatUiChoiceOriginSchema.optional()
|
|
283
308
|
});
|
|
284
309
|
|
|
310
|
+
// `state` is a frozen set: native clients validate these payloads whole, so a new state would fail them.
|
|
311
|
+
export const ChatUiQueryReadingSchema = z.object({
|
|
312
|
+
state: z.enum(['fresh', 'failed', 'refused']),
|
|
313
|
+
value: z.unknown().optional(),
|
|
314
|
+
readId: z.string().optional(),
|
|
315
|
+
readAt: z.number().nonnegative(),
|
|
316
|
+
// A code that names the reason across versions, for a client that says it in its own words; open, so a new one fails nobody.
|
|
317
|
+
code: z.string().optional(),
|
|
318
|
+
reason: z.string().optional()
|
|
319
|
+
});
|
|
320
|
+
export type ChatUiQueryReading = z.infer<typeof ChatUiQueryReadingSchema>;
|
|
321
|
+
|
|
322
|
+
export const ChatUiLinkReadingSchema = UiLinkResolutionSchema;
|
|
323
|
+
export type ChatUiLinkReading = z.infer<typeof ChatUiLinkReadingSchema>;
|
|
324
|
+
|
|
325
|
+
// The writer's captured access stays on the daemon; a record from before that still parses and drops it.
|
|
326
|
+
export const ChatUiQueryStateSchema = z.object({
|
|
327
|
+
authorChatId: z.string(),
|
|
328
|
+
blocks: z.record(
|
|
329
|
+
z.string(),
|
|
330
|
+
z.object({
|
|
331
|
+
revision: z.string(),
|
|
332
|
+
readings: z.record(z.string(), ChatUiQueryReadingSchema),
|
|
333
|
+
fallback: z.string(),
|
|
334
|
+
links: z.record(z.string(), ChatUiLinkReadingSchema).optional()
|
|
335
|
+
})
|
|
336
|
+
)
|
|
337
|
+
});
|
|
338
|
+
export type ChatUiQueryState = z.infer<typeof ChatUiQueryStateSchema>;
|
|
339
|
+
|
|
285
340
|
export const ChatAssistantItemSchema = z.object({
|
|
286
341
|
...base,
|
|
287
342
|
kind: z.literal('assistant'),
|
|
343
|
+
ui: UiBlocksSchema.optional(),
|
|
344
|
+
uiAnswers: z.record(z.string(), ChatUiAnswerSchema).optional(),
|
|
345
|
+
uiQueries: ChatUiQueryStateSchema.optional(),
|
|
346
|
+
phase: z.string().optional(),
|
|
288
347
|
text: z.string(),
|
|
289
348
|
streaming: z.boolean(),
|
|
290
349
|
// Set for text a subagent wrote, with the id of the Agent call that spawned it.
|
|
@@ -584,7 +643,14 @@ export type ChatCompactionItem = z.infer<typeof ChatCompactionItemSchema>;
|
|
|
584
643
|
// Events apply after the `chat.attach` snapshot; item ids make upserts and streamed deltas replayable.
|
|
585
644
|
export const ChatEventSchema = z.discriminatedUnion('type', [
|
|
586
645
|
z.object({ type: z.literal('item'), item: ChatItemSchema, historyIndex: z.number().int().nonnegative().optional() }),
|
|
587
|
-
z.object({
|
|
646
|
+
z.object({
|
|
647
|
+
type: z.literal('delta'),
|
|
648
|
+
itemId: z.string(),
|
|
649
|
+
text: z.string(),
|
|
650
|
+
ui: UiBlocksSchema.optional(),
|
|
651
|
+
uiQueries: ChatUiQueryStateSchema.optional(),
|
|
652
|
+
textLength: z.number().int().nonnegative().optional()
|
|
653
|
+
}),
|
|
588
654
|
z.object({ type: z.literal('info'), info: ChatInfoSchema }),
|
|
589
655
|
z.object({ type: z.literal('reset'), info: ChatInfoSchema, items: z.array(ChatItemSchema) })
|
|
590
656
|
]);
|
|
@@ -696,6 +762,8 @@ export type ChatSubagentSource = z.infer<typeof ChatSubagentSourceSchema>;
|
|
|
696
762
|
export const ChatSubagentResultSchema = z.object({
|
|
697
763
|
items: z.array(ChatItemSchema),
|
|
698
764
|
history: ChatSubagentPageSchema,
|
|
765
|
+
// A request still waiting must remain answerable after it leaves the newest page.
|
|
766
|
+
pending: z.array(z.union([ChatApprovalItemSchema, ChatQuestionItemSchema])).optional(),
|
|
699
767
|
source: ChatSubagentSourceSchema,
|
|
700
768
|
context: z.object({ provider: AgentKindSchema, cwd: z.string(), chatId: ChatIdSchema.optional() }).optional(),
|
|
701
769
|
// Whether the subagent is still writing, so a client knows to keep reading.
|
|
@@ -809,6 +877,30 @@ export type ChatSendPayload = z.infer<typeof ChatSendPayloadSchema>;
|
|
|
809
877
|
export const ChatSendResultSchema = z.object({ queued: z.boolean(), turnId: z.string().min(1).optional() });
|
|
810
878
|
export type ChatSendResult = z.infer<typeof ChatSendResultSchema>;
|
|
811
879
|
|
|
880
|
+
export const ChatUiChoicePayloadSchema = z.object({
|
|
881
|
+
chatId: ChatIdSchema,
|
|
882
|
+
itemId: z.string().min(1).max(256),
|
|
883
|
+
blockId: z.string().min(1).max(256),
|
|
884
|
+
revision: z.string().min(1).max(128),
|
|
885
|
+
choiceId: z.string().min(1).max(256),
|
|
886
|
+
reads: z.record(z.string().max(128), z.string().max(128)).optional(),
|
|
887
|
+
values: z.record(z.string().max(128), z.unknown()).optional()
|
|
888
|
+
});
|
|
889
|
+
export type ChatUiChoicePayload = z.infer<typeof ChatUiChoicePayloadSchema>;
|
|
890
|
+
|
|
891
|
+
export const ChatUiQueryPayloadSchema = z.object({
|
|
892
|
+
chatId: ChatIdSchema,
|
|
893
|
+
itemId: z.string().min(1).max(256),
|
|
894
|
+
blockId: z.string().min(1).max(256),
|
|
895
|
+
revision: z.string().min(1).max(128),
|
|
896
|
+
query: z.string().min(1).max(128),
|
|
897
|
+
values: z.record(z.string().max(128), z.unknown()).optional()
|
|
898
|
+
});
|
|
899
|
+
export type ChatUiQueryPayload = z.infer<typeof ChatUiQueryPayloadSchema>;
|
|
900
|
+
|
|
901
|
+
export const ChatUiLinkPayloadSchema = ChatUiChoicePayloadSchema.omit({ choiceId: true }).extend({ nodeId: z.string().min(1).max(256) });
|
|
902
|
+
export type ChatUiLinkPayload = z.infer<typeof ChatUiLinkPayloadSchema>;
|
|
903
|
+
|
|
812
904
|
export const ChatQueuePayloadSchema = z.object({
|
|
813
905
|
chatId: ChatIdSchema,
|
|
814
906
|
messageId: z.string().min(1)
|
|
@@ -940,3 +1032,18 @@ export const ChatListResultSchema = z.object({
|
|
|
940
1032
|
chats: z.array(ChatInfoSchema)
|
|
941
1033
|
});
|
|
942
1034
|
export type ChatListResult = z.infer<typeof ChatListResultSchema>;
|
|
1035
|
+
|
|
1036
|
+
export const GeneratedImageInputSchema = z.object({
|
|
1037
|
+
attachment: ChatAttachmentSchema.optional(),
|
|
1038
|
+
revisedPrompt: z.string().optional(),
|
|
1039
|
+
transparentBackground: z.boolean().optional()
|
|
1040
|
+
});
|
|
1041
|
+
export type GeneratedImageInput = z.infer<typeof GeneratedImageInputSchema>;
|
|
1042
|
+
|
|
1043
|
+
export function generatedImageAttachment(item: ChatItem): ChatAttachment | null {
|
|
1044
|
+
if (item.kind !== 'tool' || item.name !== 'ImageGeneration') {
|
|
1045
|
+
return null;
|
|
1046
|
+
}
|
|
1047
|
+
const parsed = GeneratedImageInputSchema.safeParse(item.input);
|
|
1048
|
+
return parsed.success ? (parsed.data.attachment ?? null) : null;
|
|
1049
|
+
}
|
package/src/protocol.ts
CHANGED
|
@@ -30,6 +30,11 @@ import {
|
|
|
30
30
|
ChatRenameBookmarkPayloadSchema,
|
|
31
31
|
ChatSendPayloadSchema,
|
|
32
32
|
ChatSendResultSchema,
|
|
33
|
+
ChatUiChoicePayloadSchema,
|
|
34
|
+
ChatUiLinkPayloadSchema,
|
|
35
|
+
ChatUiLinkReadingSchema,
|
|
36
|
+
ChatUiQueryPayloadSchema,
|
|
37
|
+
ChatUiQueryReadingSchema,
|
|
33
38
|
ChatStatusEventSchema,
|
|
34
39
|
ChatStopSubagentPayloadSchema,
|
|
35
40
|
ChatStopTaskPayloadSchema,
|
|
@@ -70,6 +75,9 @@ export const AGENT_REQUEST_SCHEMAS = {
|
|
|
70
75
|
'chat.attach': { payload: ChatAttachPayloadSchema, result: ChatAttachResultSchema },
|
|
71
76
|
'chat.detach': { payload: ChatTargetPayloadSchema, result: EmptySchema },
|
|
72
77
|
'chat.send': { payload: ChatSendPayloadSchema, result: ChatSendResultSchema },
|
|
78
|
+
'chat.uiChoice': { payload: ChatUiChoicePayloadSchema, result: ChatSendResultSchema },
|
|
79
|
+
'ui.link': { payload: ChatUiLinkPayloadSchema, result: ChatUiLinkReadingSchema },
|
|
80
|
+
'ui.query': { payload: ChatUiQueryPayloadSchema, result: ChatUiQueryReadingSchema },
|
|
73
81
|
'chat.unqueue': { payload: ChatQueuePayloadSchema, result: ChatUnqueueResultSchema },
|
|
74
82
|
'chat.sendNow': { payload: ChatQueuePayloadSchema, result: EmptySchema },
|
|
75
83
|
'chat.cancel': { payload: ChatCancelPayloadSchema, result: EmptySchema },
|