@adecore/agent-contracts 0.20.1 → 0.21.0
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 +1437 -0
- package/dist/chat.js +86 -4
- package/dist/protocol.d.ts +976 -0
- package/dist/protocol.js +4 -1
- package/package.json +2 -1
- package/src/chat.ts +108 -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.0",
|
|
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.0",
|
|
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,44 @@ 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
|
+
export const ChatUiQueryReadingSchema = z.object({
|
|
311
|
+
state: z.enum(['fresh', 'failed', 'refused']),
|
|
312
|
+
value: z.unknown().optional(),
|
|
313
|
+
readId: z.string().optional(),
|
|
314
|
+
readAt: z.number().nonnegative(),
|
|
315
|
+
reason: z.string().optional()
|
|
316
|
+
});
|
|
317
|
+
export type ChatUiQueryReading = z.infer<typeof ChatUiQueryReadingSchema>;
|
|
318
|
+
|
|
319
|
+
export const ChatUiLinkReadingSchema = UiLinkResolutionSchema;
|
|
320
|
+
export type ChatUiLinkReading = z.infer<typeof ChatUiLinkReadingSchema>;
|
|
321
|
+
|
|
322
|
+
export const ChatUiQueryStateSchema = z.object({
|
|
323
|
+
authorChatId: z.string(),
|
|
324
|
+
access: z.unknown(),
|
|
325
|
+
blocks: z.record(
|
|
326
|
+
z.string(),
|
|
327
|
+
z.object({
|
|
328
|
+
revision: z.string(),
|
|
329
|
+
readings: z.record(z.string(), ChatUiQueryReadingSchema),
|
|
330
|
+
fallback: z.string(),
|
|
331
|
+
links: z.record(z.string(), ChatUiLinkReadingSchema).optional()
|
|
332
|
+
})
|
|
333
|
+
)
|
|
334
|
+
});
|
|
335
|
+
export type ChatUiQueryState = z.infer<typeof ChatUiQueryStateSchema>;
|
|
336
|
+
|
|
285
337
|
export const ChatAssistantItemSchema = z.object({
|
|
286
338
|
...base,
|
|
287
339
|
kind: z.literal('assistant'),
|
|
340
|
+
ui: UiBlocksSchema.optional(),
|
|
341
|
+
uiAnswers: z.record(z.string(), ChatUiAnswerSchema).optional(),
|
|
342
|
+
uiQueries: ChatUiQueryStateSchema.optional(),
|
|
343
|
+
phase: z.string().optional(),
|
|
288
344
|
text: z.string(),
|
|
289
345
|
streaming: z.boolean(),
|
|
290
346
|
// Set for text a subagent wrote, with the id of the Agent call that spawned it.
|
|
@@ -584,7 +640,14 @@ export type ChatCompactionItem = z.infer<typeof ChatCompactionItemSchema>;
|
|
|
584
640
|
// Events apply after the `chat.attach` snapshot; item ids make upserts and streamed deltas replayable.
|
|
585
641
|
export const ChatEventSchema = z.discriminatedUnion('type', [
|
|
586
642
|
z.object({ type: z.literal('item'), item: ChatItemSchema, historyIndex: z.number().int().nonnegative().optional() }),
|
|
587
|
-
z.object({
|
|
643
|
+
z.object({
|
|
644
|
+
type: z.literal('delta'),
|
|
645
|
+
itemId: z.string(),
|
|
646
|
+
text: z.string(),
|
|
647
|
+
ui: UiBlocksSchema.optional(),
|
|
648
|
+
uiQueries: ChatUiQueryStateSchema.optional(),
|
|
649
|
+
textLength: z.number().int().nonnegative().optional()
|
|
650
|
+
}),
|
|
588
651
|
z.object({ type: z.literal('info'), info: ChatInfoSchema }),
|
|
589
652
|
z.object({ type: z.literal('reset'), info: ChatInfoSchema, items: z.array(ChatItemSchema) })
|
|
590
653
|
]);
|
|
@@ -696,6 +759,8 @@ export type ChatSubagentSource = z.infer<typeof ChatSubagentSourceSchema>;
|
|
|
696
759
|
export const ChatSubagentResultSchema = z.object({
|
|
697
760
|
items: z.array(ChatItemSchema),
|
|
698
761
|
history: ChatSubagentPageSchema,
|
|
762
|
+
// A request still waiting must remain answerable after it leaves the newest page.
|
|
763
|
+
pending: z.array(z.union([ChatApprovalItemSchema, ChatQuestionItemSchema])).optional(),
|
|
699
764
|
source: ChatSubagentSourceSchema,
|
|
700
765
|
context: z.object({ provider: AgentKindSchema, cwd: z.string(), chatId: ChatIdSchema.optional() }).optional(),
|
|
701
766
|
// Whether the subagent is still writing, so a client knows to keep reading.
|
|
@@ -809,6 +874,30 @@ export type ChatSendPayload = z.infer<typeof ChatSendPayloadSchema>;
|
|
|
809
874
|
export const ChatSendResultSchema = z.object({ queued: z.boolean(), turnId: z.string().min(1).optional() });
|
|
810
875
|
export type ChatSendResult = z.infer<typeof ChatSendResultSchema>;
|
|
811
876
|
|
|
877
|
+
export const ChatUiChoicePayloadSchema = z.object({
|
|
878
|
+
chatId: ChatIdSchema,
|
|
879
|
+
itemId: z.string().min(1).max(256),
|
|
880
|
+
blockId: z.string().min(1).max(256),
|
|
881
|
+
revision: z.string().min(1).max(128),
|
|
882
|
+
choiceId: z.string().min(1).max(256),
|
|
883
|
+
reads: z.record(z.string().max(128), z.string().max(128)).optional(),
|
|
884
|
+
values: z.record(z.string().max(128), z.unknown()).optional()
|
|
885
|
+
});
|
|
886
|
+
export type ChatUiChoicePayload = z.infer<typeof ChatUiChoicePayloadSchema>;
|
|
887
|
+
|
|
888
|
+
export const ChatUiQueryPayloadSchema = z.object({
|
|
889
|
+
chatId: ChatIdSchema,
|
|
890
|
+
itemId: z.string().min(1).max(256),
|
|
891
|
+
blockId: z.string().min(1).max(256),
|
|
892
|
+
revision: z.string().min(1).max(128),
|
|
893
|
+
query: z.string().min(1).max(128),
|
|
894
|
+
values: z.record(z.string().max(128), z.unknown()).optional()
|
|
895
|
+
});
|
|
896
|
+
export type ChatUiQueryPayload = z.infer<typeof ChatUiQueryPayloadSchema>;
|
|
897
|
+
|
|
898
|
+
export const ChatUiLinkPayloadSchema = ChatUiChoicePayloadSchema.omit({ choiceId: true }).extend({ nodeId: z.string().min(1).max(256) });
|
|
899
|
+
export type ChatUiLinkPayload = z.infer<typeof ChatUiLinkPayloadSchema>;
|
|
900
|
+
|
|
812
901
|
export const ChatQueuePayloadSchema = z.object({
|
|
813
902
|
chatId: ChatIdSchema,
|
|
814
903
|
messageId: z.string().min(1)
|
|
@@ -940,3 +1029,18 @@ export const ChatListResultSchema = z.object({
|
|
|
940
1029
|
chats: z.array(ChatInfoSchema)
|
|
941
1030
|
});
|
|
942
1031
|
export type ChatListResult = z.infer<typeof ChatListResultSchema>;
|
|
1032
|
+
|
|
1033
|
+
export const GeneratedImageInputSchema = z.object({
|
|
1034
|
+
attachment: ChatAttachmentSchema.optional(),
|
|
1035
|
+
revisedPrompt: z.string().optional(),
|
|
1036
|
+
transparentBackground: z.boolean().optional()
|
|
1037
|
+
});
|
|
1038
|
+
export type GeneratedImageInput = z.infer<typeof GeneratedImageInputSchema>;
|
|
1039
|
+
|
|
1040
|
+
export function generatedImageAttachment(item: ChatItem): ChatAttachment | null {
|
|
1041
|
+
if (item.kind !== 'tool' || item.name !== 'ImageGeneration') {
|
|
1042
|
+
return null;
|
|
1043
|
+
}
|
|
1044
|
+
const parsed = GeneratedImageInputSchema.safeParse(item.input);
|
|
1045
|
+
return parsed.success ? (parsed.data.attachment ?? null) : null;
|
|
1046
|
+
}
|
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 },
|