@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.js 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.js';
3
5
  import { WorktreeSchema } from './worktree.js';
4
6
  import { ModelSelectionSchema, RuntimeModeSchema } from './model.js';
@@ -80,7 +82,24 @@ export const ChatAttachmentSchema = z.object({
80
82
  mime: z.string(),
81
83
  size: z.number().int().nonnegative(),
82
84
  // Absolute, on the machine the daemon runs on.
83
- path: z.string()
85
+ path: z.string(),
86
+ width: z.number().int().positive().optional(),
87
+ height: z.number().int().positive().optional()
88
+ });
89
+ export const ChatUiChoiceOriginSchema = z.object({
90
+ itemId: z.string().min(1),
91
+ blockId: z.string().min(1),
92
+ revision: z.string().min(1),
93
+ choiceId: z.string().min(1),
94
+ label: z.string().min(1),
95
+ sourceAt: z.number().nonnegative(),
96
+ older: z.boolean(),
97
+ values: z.record(z.string(), z.unknown()).optional(),
98
+ at: z.number().nonnegative()
99
+ });
100
+ export const ChatUiAnswerSchema = ChatUiChoiceOriginSchema.extend({
101
+ queued: z.boolean(),
102
+ turnId: z.string().min(1)
84
103
  });
85
104
  // A message typed while a turn was running; the daemon sends it when that turn settles.
86
105
  export const ChatQueuedMessageSchema = z.object({
@@ -92,7 +111,8 @@ export const ChatQueuedMessageSchema = z.object({
92
111
  skills: z.array(z.string()).optional(),
93
112
  chats: z.array(z.string()).optional(),
94
113
  attachments: z.array(ChatAttachmentSchema).optional(),
95
- createdAt: z.number()
114
+ createdAt: z.number(),
115
+ uiChoice: ChatUiChoiceOriginSchema.optional()
96
116
  });
97
117
  // A command or a monitor the CLI keeps running beside its turns, until it ends or its process does.
98
118
  export const ChatBackgroundTaskSchema = z.object({
@@ -236,11 +256,37 @@ export const ChatUserItemSchema = z.object({
236
256
  skills: z.array(z.string()).optional(),
237
257
  // Chats of the same project the person picked with `@`. Only their ids travel; the agent reads them itself.
238
258
  chats: z.array(z.string()).optional(),
239
- attachments: z.array(ChatAttachmentSchema).optional()
259
+ attachments: z.array(ChatAttachmentSchema).optional(),
260
+ uiChoice: ChatUiChoiceOriginSchema.optional()
261
+ });
262
+ // `state` is a frozen set: native clients validate these payloads whole, so a new state would fail them.
263
+ export const ChatUiQueryReadingSchema = z.object({
264
+ state: z.enum(['fresh', 'failed', 'refused']),
265
+ value: z.unknown().optional(),
266
+ readId: z.string().optional(),
267
+ readAt: z.number().nonnegative(),
268
+ // 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.
269
+ code: z.string().optional(),
270
+ reason: z.string().optional()
271
+ });
272
+ export const ChatUiLinkReadingSchema = UiLinkResolutionSchema;
273
+ // The writer's captured access stays on the daemon; a record from before that still parses and drops it.
274
+ export const ChatUiQueryStateSchema = z.object({
275
+ authorChatId: z.string(),
276
+ blocks: z.record(z.string(), z.object({
277
+ revision: z.string(),
278
+ readings: z.record(z.string(), ChatUiQueryReadingSchema),
279
+ fallback: z.string(),
280
+ links: z.record(z.string(), ChatUiLinkReadingSchema).optional()
281
+ }))
240
282
  });
241
283
  export const ChatAssistantItemSchema = z.object({
242
284
  ...base,
243
285
  kind: z.literal('assistant'),
286
+ ui: UiBlocksSchema.optional(),
287
+ uiAnswers: z.record(z.string(), ChatUiAnswerSchema).optional(),
288
+ uiQueries: ChatUiQueryStateSchema.optional(),
289
+ phase: z.string().optional(),
244
290
  text: z.string(),
245
291
  streaming: z.boolean(),
246
292
  // Set for text a subagent wrote, with the id of the Agent call that spawned it.
@@ -486,7 +532,14 @@ export const ChatItemSchema = z.discriminatedUnion('kind', [
486
532
  // Events apply after the `chat.attach` snapshot; item ids make upserts and streamed deltas replayable.
487
533
  export const ChatEventSchema = z.discriminatedUnion('type', [
488
534
  z.object({ type: z.literal('item'), item: ChatItemSchema, historyIndex: z.number().int().nonnegative().optional() }),
489
- z.object({ type: z.literal('delta'), itemId: z.string(), text: z.string() }),
535
+ z.object({
536
+ type: z.literal('delta'),
537
+ itemId: z.string(),
538
+ text: z.string(),
539
+ ui: UiBlocksSchema.optional(),
540
+ uiQueries: ChatUiQueryStateSchema.optional(),
541
+ textLength: z.number().int().nonnegative().optional()
542
+ }),
490
543
  z.object({ type: z.literal('info'), info: ChatInfoSchema }),
491
544
  z.object({ type: z.literal('reset'), info: ChatInfoSchema, items: z.array(ChatItemSchema) })
492
545
  ]);
@@ -571,6 +624,8 @@ export const ChatSubagentSourceSchema = z.enum(['claude-transcript', 'codex-thre
571
624
  export const ChatSubagentResultSchema = z.object({
572
625
  items: z.array(ChatItemSchema),
573
626
  history: ChatSubagentPageSchema,
627
+ // A request still waiting must remain answerable after it leaves the newest page.
628
+ pending: z.array(z.union([ChatApprovalItemSchema, ChatQuestionItemSchema])).optional(),
574
629
  source: ChatSubagentSourceSchema,
575
630
  context: z.object({ provider: AgentKindSchema, cwd: z.string(), chatId: ChatIdSchema.optional() }).optional(),
576
631
  // Whether the subagent is still writing, so a client knows to keep reading.
@@ -650,6 +705,24 @@ export const ChatSendPayloadSchema = z
650
705
  .refine((payload) => payload.text.trim() !== '' || (payload.attachments?.length ?? 0) > 0, { message: 'A message needs text or an attachment' });
651
706
  // Daemons before completion follow-ups omit `turnId`; keeping it optional lets newer clients finish the send.
652
707
  export const ChatSendResultSchema = z.object({ queued: z.boolean(), turnId: z.string().min(1).optional() });
708
+ export const ChatUiChoicePayloadSchema = z.object({
709
+ chatId: ChatIdSchema,
710
+ itemId: z.string().min(1).max(256),
711
+ blockId: z.string().min(1).max(256),
712
+ revision: z.string().min(1).max(128),
713
+ choiceId: z.string().min(1).max(256),
714
+ reads: z.record(z.string().max(128), z.string().max(128)).optional(),
715
+ values: z.record(z.string().max(128), z.unknown()).optional()
716
+ });
717
+ export const ChatUiQueryPayloadSchema = z.object({
718
+ chatId: ChatIdSchema,
719
+ itemId: z.string().min(1).max(256),
720
+ blockId: z.string().min(1).max(256),
721
+ revision: z.string().min(1).max(128),
722
+ query: z.string().min(1).max(128),
723
+ values: z.record(z.string().max(128), z.unknown()).optional()
724
+ });
725
+ export const ChatUiLinkPayloadSchema = ChatUiChoicePayloadSchema.omit({ choiceId: true }).extend({ nodeId: z.string().min(1).max(256) });
653
726
  export const ChatQueuePayloadSchema = z.object({
654
727
  chatId: ChatIdSchema,
655
728
  messageId: z.string().min(1)
@@ -749,3 +822,15 @@ export const ChatForkInfoResultSchema = z.object({
749
822
  export const ChatListResultSchema = z.object({
750
823
  chats: z.array(ChatInfoSchema)
751
824
  });
825
+ export const GeneratedImageInputSchema = z.object({
826
+ attachment: ChatAttachmentSchema.optional(),
827
+ revisedPrompt: z.string().optional(),
828
+ transparentBackground: z.boolean().optional()
829
+ });
830
+ export function generatedImageAttachment(item) {
831
+ if (item.kind !== 'tool' || item.name !== 'ImageGeneration') {
832
+ return null;
833
+ }
834
+ const parsed = GeneratedImageInputSchema.safeParse(item.input);
835
+ return parsed.success ? (parsed.data.attachment ?? null) : null;
836
+ }