@myagentroam/protocol 0.13.7 → 0.13.9

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.
@@ -1,4 +1,185 @@
1
1
  import { z } from 'zod';
2
+ export declare const MAX_COMPOSER_QUOTE_CHARACTERS = 8000;
3
+ export declare const MAX_COMPOSER_MESSAGE_CHARACTERS = 100000;
4
+ /** Explicit snapshots describe a source; they never grant access to a live resource. */
5
+ export declare const composerQuoteSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"source", [z.ZodObject<{
6
+ source: z.ZodLiteral<"file">;
7
+ path: z.ZodString;
8
+ origin: z.ZodEnum<["WORKING_TREE", "HISTORY"]>;
9
+ startLine: z.ZodNumber;
10
+ endLine: z.ZodNumber;
11
+ revision: z.ZodOptional<z.ZodString>;
12
+ unsaved: z.ZodOptional<z.ZodBoolean>;
13
+ type: z.ZodLiteral<"quote">;
14
+ id: z.ZodString;
15
+ label: z.ZodString;
16
+ text: z.ZodEffects<z.ZodString, string, string>;
17
+ }, "strict", z.ZodTypeAny, {
18
+ path: string;
19
+ type: "quote";
20
+ source: "file";
21
+ origin: "WORKING_TREE" | "HISTORY";
22
+ startLine: number;
23
+ endLine: number;
24
+ id: string;
25
+ label: string;
26
+ text: string;
27
+ revision?: string | undefined;
28
+ unsaved?: boolean | undefined;
29
+ }, {
30
+ path: string;
31
+ type: "quote";
32
+ source: "file";
33
+ origin: "WORKING_TREE" | "HISTORY";
34
+ startLine: number;
35
+ endLine: number;
36
+ id: string;
37
+ label: string;
38
+ text: string;
39
+ revision?: string | undefined;
40
+ unsaved?: boolean | undefined;
41
+ }>, z.ZodObject<{
42
+ source: z.ZodLiteral<"diff">;
43
+ path: z.ZodString;
44
+ origin: z.ZodEnum<["WORKING_TREE", "HISTORY", "TOOL_CHANGE"]>;
45
+ revision: z.ZodOptional<z.ZodString>;
46
+ side: z.ZodOptional<z.ZodEnum<["old", "new", "mixed"]>>;
47
+ startLine: z.ZodOptional<z.ZodNumber>;
48
+ endLine: z.ZodOptional<z.ZodNumber>;
49
+ oldStartLine: z.ZodOptional<z.ZodNumber>;
50
+ oldEndLine: z.ZodOptional<z.ZodNumber>;
51
+ type: z.ZodLiteral<"quote">;
52
+ id: z.ZodString;
53
+ label: z.ZodString;
54
+ text: z.ZodEffects<z.ZodString, string, string>;
55
+ }, "strict", z.ZodTypeAny, {
56
+ path: string;
57
+ type: "quote";
58
+ source: "diff";
59
+ origin: "WORKING_TREE" | "HISTORY" | "TOOL_CHANGE";
60
+ id: string;
61
+ label: string;
62
+ text: string;
63
+ startLine?: number | undefined;
64
+ endLine?: number | undefined;
65
+ revision?: string | undefined;
66
+ side?: "old" | "new" | "mixed" | undefined;
67
+ oldStartLine?: number | undefined;
68
+ oldEndLine?: number | undefined;
69
+ }, {
70
+ path: string;
71
+ type: "quote";
72
+ source: "diff";
73
+ origin: "WORKING_TREE" | "HISTORY" | "TOOL_CHANGE";
74
+ id: string;
75
+ label: string;
76
+ text: string;
77
+ startLine?: number | undefined;
78
+ endLine?: number | undefined;
79
+ revision?: string | undefined;
80
+ side?: "old" | "new" | "mixed" | undefined;
81
+ oldStartLine?: number | undefined;
82
+ oldEndLine?: number | undefined;
83
+ }>, z.ZodObject<{
84
+ source: z.ZodLiteral<"assistant">;
85
+ messageId: z.ZodString;
86
+ timestamp: z.ZodOptional<z.ZodString>;
87
+ streaming: z.ZodOptional<z.ZodBoolean>;
88
+ type: z.ZodLiteral<"quote">;
89
+ id: z.ZodString;
90
+ label: z.ZodString;
91
+ text: z.ZodEffects<z.ZodString, string, string>;
92
+ }, "strict", z.ZodTypeAny, {
93
+ type: "quote";
94
+ source: "assistant";
95
+ id: string;
96
+ label: string;
97
+ text: string;
98
+ messageId: string;
99
+ timestamp?: string | undefined;
100
+ streaming?: boolean | undefined;
101
+ }, {
102
+ type: "quote";
103
+ source: "assistant";
104
+ id: string;
105
+ label: string;
106
+ text: string;
107
+ messageId: string;
108
+ timestamp?: string | undefined;
109
+ streaming?: boolean | undefined;
110
+ }>]>, {
111
+ path: string;
112
+ type: "quote";
113
+ source: "file";
114
+ origin: "WORKING_TREE" | "HISTORY";
115
+ startLine: number;
116
+ endLine: number;
117
+ id: string;
118
+ label: string;
119
+ text: string;
120
+ revision?: string | undefined;
121
+ unsaved?: boolean | undefined;
122
+ } | {
123
+ path: string;
124
+ type: "quote";
125
+ source: "diff";
126
+ origin: "WORKING_TREE" | "HISTORY" | "TOOL_CHANGE";
127
+ id: string;
128
+ label: string;
129
+ text: string;
130
+ startLine?: number | undefined;
131
+ endLine?: number | undefined;
132
+ revision?: string | undefined;
133
+ side?: "old" | "new" | "mixed" | undefined;
134
+ oldStartLine?: number | undefined;
135
+ oldEndLine?: number | undefined;
136
+ } | {
137
+ type: "quote";
138
+ source: "assistant";
139
+ id: string;
140
+ label: string;
141
+ text: string;
142
+ messageId: string;
143
+ timestamp?: string | undefined;
144
+ streaming?: boolean | undefined;
145
+ }, {
146
+ path: string;
147
+ type: "quote";
148
+ source: "file";
149
+ origin: "WORKING_TREE" | "HISTORY";
150
+ startLine: number;
151
+ endLine: number;
152
+ id: string;
153
+ label: string;
154
+ text: string;
155
+ revision?: string | undefined;
156
+ unsaved?: boolean | undefined;
157
+ } | {
158
+ path: string;
159
+ type: "quote";
160
+ source: "diff";
161
+ origin: "WORKING_TREE" | "HISTORY" | "TOOL_CHANGE";
162
+ id: string;
163
+ label: string;
164
+ text: string;
165
+ startLine?: number | undefined;
166
+ endLine?: number | undefined;
167
+ revision?: string | undefined;
168
+ side?: "old" | "new" | "mixed" | undefined;
169
+ oldStartLine?: number | undefined;
170
+ oldEndLine?: number | undefined;
171
+ } | {
172
+ type: "quote";
173
+ source: "assistant";
174
+ id: string;
175
+ label: string;
176
+ text: string;
177
+ messageId: string;
178
+ timestamp?: string | undefined;
179
+ streaming?: boolean | undefined;
180
+ }>;
181
+ export type ComposerQuote = z.infer<typeof composerQuoteSchema>;
182
+ export type ComposerQuoteDraft = ComposerQuote extends infer Q ? Q extends ComposerQuote ? Omit<Q, 'id'> : never : never;
2
183
  export declare const channelDisplayNameSchema: z.ZodEffects<z.ZodString, string, string>;
3
184
  export declare const channelOriginSchema: z.ZodObject<{
4
185
  source: z.ZodLiteral<"WEB_SHARE">;
@@ -229,34 +410,279 @@ export declare const composerTagSchemas: {
229
410
  label: z.ZodString;
230
411
  }, "strict", z.ZodTypeAny, {
231
412
  type: "session";
232
- sessionId: string;
233
413
  label: string;
414
+ sessionId: string;
234
415
  }, {
235
416
  type: "session";
417
+ label: string;
236
418
  sessionId: string;
419
+ }>, z.ZodEffects<z.ZodDiscriminatedUnion<"source", [z.ZodObject<{
420
+ source: z.ZodLiteral<"file">;
421
+ path: z.ZodString;
422
+ origin: z.ZodEnum<["WORKING_TREE", "HISTORY"]>;
423
+ startLine: z.ZodNumber;
424
+ endLine: z.ZodNumber;
425
+ revision: z.ZodOptional<z.ZodString>;
426
+ unsaved: z.ZodOptional<z.ZodBoolean>;
427
+ type: z.ZodLiteral<"quote">;
428
+ id: z.ZodString;
429
+ label: z.ZodString;
430
+ text: z.ZodEffects<z.ZodString, string, string>;
431
+ }, "strict", z.ZodTypeAny, {
432
+ path: string;
433
+ type: "quote";
434
+ source: "file";
435
+ origin: "WORKING_TREE" | "HISTORY";
436
+ startLine: number;
437
+ endLine: number;
438
+ id: string;
439
+ label: string;
440
+ text: string;
441
+ revision?: string | undefined;
442
+ unsaved?: boolean | undefined;
443
+ }, {
444
+ path: string;
445
+ type: "quote";
446
+ source: "file";
447
+ origin: "WORKING_TREE" | "HISTORY";
448
+ startLine: number;
449
+ endLine: number;
450
+ id: string;
451
+ label: string;
452
+ text: string;
453
+ revision?: string | undefined;
454
+ unsaved?: boolean | undefined;
455
+ }>, z.ZodObject<{
456
+ source: z.ZodLiteral<"diff">;
457
+ path: z.ZodString;
458
+ origin: z.ZodEnum<["WORKING_TREE", "HISTORY", "TOOL_CHANGE"]>;
459
+ revision: z.ZodOptional<z.ZodString>;
460
+ side: z.ZodOptional<z.ZodEnum<["old", "new", "mixed"]>>;
461
+ startLine: z.ZodOptional<z.ZodNumber>;
462
+ endLine: z.ZodOptional<z.ZodNumber>;
463
+ oldStartLine: z.ZodOptional<z.ZodNumber>;
464
+ oldEndLine: z.ZodOptional<z.ZodNumber>;
465
+ type: z.ZodLiteral<"quote">;
466
+ id: z.ZodString;
467
+ label: z.ZodString;
468
+ text: z.ZodEffects<z.ZodString, string, string>;
469
+ }, "strict", z.ZodTypeAny, {
470
+ path: string;
471
+ type: "quote";
472
+ source: "diff";
473
+ origin: "WORKING_TREE" | "HISTORY" | "TOOL_CHANGE";
474
+ id: string;
475
+ label: string;
476
+ text: string;
477
+ startLine?: number | undefined;
478
+ endLine?: number | undefined;
479
+ revision?: string | undefined;
480
+ side?: "old" | "new" | "mixed" | undefined;
481
+ oldStartLine?: number | undefined;
482
+ oldEndLine?: number | undefined;
483
+ }, {
484
+ path: string;
485
+ type: "quote";
486
+ source: "diff";
487
+ origin: "WORKING_TREE" | "HISTORY" | "TOOL_CHANGE";
488
+ id: string;
489
+ label: string;
490
+ text: string;
491
+ startLine?: number | undefined;
492
+ endLine?: number | undefined;
493
+ revision?: string | undefined;
494
+ side?: "old" | "new" | "mixed" | undefined;
495
+ oldStartLine?: number | undefined;
496
+ oldEndLine?: number | undefined;
497
+ }>, z.ZodObject<{
498
+ source: z.ZodLiteral<"assistant">;
499
+ messageId: z.ZodString;
500
+ timestamp: z.ZodOptional<z.ZodString>;
501
+ streaming: z.ZodOptional<z.ZodBoolean>;
502
+ type: z.ZodLiteral<"quote">;
503
+ id: z.ZodString;
504
+ label: z.ZodString;
505
+ text: z.ZodEffects<z.ZodString, string, string>;
506
+ }, "strict", z.ZodTypeAny, {
507
+ type: "quote";
508
+ source: "assistant";
509
+ id: string;
510
+ label: string;
511
+ text: string;
512
+ messageId: string;
513
+ timestamp?: string | undefined;
514
+ streaming?: boolean | undefined;
515
+ }, {
516
+ type: "quote";
517
+ source: "assistant";
518
+ id: string;
519
+ label: string;
520
+ text: string;
521
+ messageId: string;
522
+ timestamp?: string | undefined;
523
+ streaming?: boolean | undefined;
524
+ }>]>, {
525
+ path: string;
526
+ type: "quote";
527
+ source: "file";
528
+ origin: "WORKING_TREE" | "HISTORY";
529
+ startLine: number;
530
+ endLine: number;
531
+ id: string;
532
+ label: string;
533
+ text: string;
534
+ revision?: string | undefined;
535
+ unsaved?: boolean | undefined;
536
+ } | {
537
+ path: string;
538
+ type: "quote";
539
+ source: "diff";
540
+ origin: "WORKING_TREE" | "HISTORY" | "TOOL_CHANGE";
541
+ id: string;
542
+ label: string;
543
+ text: string;
544
+ startLine?: number | undefined;
545
+ endLine?: number | undefined;
546
+ revision?: string | undefined;
547
+ side?: "old" | "new" | "mixed" | undefined;
548
+ oldStartLine?: number | undefined;
549
+ oldEndLine?: number | undefined;
550
+ } | {
551
+ type: "quote";
552
+ source: "assistant";
553
+ id: string;
554
+ label: string;
555
+ text: string;
556
+ messageId: string;
557
+ timestamp?: string | undefined;
558
+ streaming?: boolean | undefined;
559
+ }, {
560
+ path: string;
561
+ type: "quote";
562
+ source: "file";
563
+ origin: "WORKING_TREE" | "HISTORY";
564
+ startLine: number;
565
+ endLine: number;
566
+ id: string;
567
+ label: string;
568
+ text: string;
569
+ revision?: string | undefined;
570
+ unsaved?: boolean | undefined;
571
+ } | {
572
+ path: string;
573
+ type: "quote";
574
+ source: "diff";
575
+ origin: "WORKING_TREE" | "HISTORY" | "TOOL_CHANGE";
576
+ id: string;
237
577
  label: string;
578
+ text: string;
579
+ startLine?: number | undefined;
580
+ endLine?: number | undefined;
581
+ revision?: string | undefined;
582
+ side?: "old" | "new" | "mixed" | undefined;
583
+ oldStartLine?: number | undefined;
584
+ oldEndLine?: number | undefined;
585
+ } | {
586
+ type: "quote";
587
+ source: "assistant";
588
+ id: string;
589
+ label: string;
590
+ text: string;
591
+ messageId: string;
592
+ timestamp?: string | undefined;
593
+ streaming?: boolean | undefined;
238
594
  }>]>, "many">;
239
595
  }, "strict", z.ZodTypeAny, {
240
596
  references: ({
597
+ path: string;
598
+ type: "quote";
599
+ source: "file";
600
+ origin: "WORKING_TREE" | "HISTORY";
601
+ startLine: number;
602
+ endLine: number;
603
+ id: string;
604
+ label: string;
605
+ text: string;
606
+ revision?: string | undefined;
607
+ unsaved?: boolean | undefined;
608
+ } | {
609
+ path: string;
610
+ type: "quote";
611
+ source: "diff";
612
+ origin: "WORKING_TREE" | "HISTORY" | "TOOL_CHANGE";
613
+ id: string;
614
+ label: string;
615
+ text: string;
616
+ startLine?: number | undefined;
617
+ endLine?: number | undefined;
618
+ revision?: string | undefined;
619
+ side?: "old" | "new" | "mixed" | undefined;
620
+ oldStartLine?: number | undefined;
621
+ oldEndLine?: number | undefined;
622
+ } | {
623
+ type: "quote";
624
+ source: "assistant";
625
+ id: string;
626
+ label: string;
627
+ text: string;
628
+ messageId: string;
629
+ timestamp?: string | undefined;
630
+ streaming?: boolean | undefined;
631
+ } | {
241
632
  path: string;
242
633
  type: "file" | "directory";
243
634
  label: string;
244
635
  runnerPath?: string | undefined;
245
636
  } | {
246
637
  type: "session";
247
- sessionId: string;
248
638
  label: string;
639
+ sessionId: string;
249
640
  })[];
250
641
  }, {
251
642
  references: ({
643
+ path: string;
644
+ type: "quote";
645
+ source: "file";
646
+ origin: "WORKING_TREE" | "HISTORY";
647
+ startLine: number;
648
+ endLine: number;
649
+ id: string;
650
+ label: string;
651
+ text: string;
652
+ revision?: string | undefined;
653
+ unsaved?: boolean | undefined;
654
+ } | {
655
+ path: string;
656
+ type: "quote";
657
+ source: "diff";
658
+ origin: "WORKING_TREE" | "HISTORY" | "TOOL_CHANGE";
659
+ id: string;
660
+ label: string;
661
+ text: string;
662
+ startLine?: number | undefined;
663
+ endLine?: number | undefined;
664
+ revision?: string | undefined;
665
+ side?: "old" | "new" | "mixed" | undefined;
666
+ oldStartLine?: number | undefined;
667
+ oldEndLine?: number | undefined;
668
+ } | {
669
+ type: "quote";
670
+ source: "assistant";
671
+ id: string;
672
+ label: string;
673
+ text: string;
674
+ messageId: string;
675
+ timestamp?: string | undefined;
676
+ streaming?: boolean | undefined;
677
+ } | {
252
678
  path: string;
253
679
  type: "file" | "directory";
254
680
  label: string;
255
681
  runnerPath?: string | undefined;
256
682
  } | {
257
683
  type: "session";
258
- sessionId: string;
259
684
  label: string;
685
+ sessionId: string;
260
686
  })[];
261
687
  }>;
262
688
  };
@@ -266,8 +692,8 @@ export type ComposerTagPayloads = {
266
692
  };
267
693
  export type ComposerAttachmentFile = ComposerTagPayloads['mar_attachments']['files'][number];
268
694
  export type ComposerReference = ComposerTagPayloads['mar_references']['references'][number];
269
- export type ComposerFileReference = Exclude<ComposerReference, {
270
- type: 'session';
695
+ export type ComposerFileReference = Extract<ComposerReference, {
696
+ type: 'file' | 'directory';
271
697
  }>;
272
698
  export type ComposerTagPart = {
273
699
  readonly kind: 'text';
@@ -3,6 +3,69 @@ import { composerMarkupEnd, escapeMarkup, markupAttributes, parseComposerMarkup
3
3
  const path = z.string().min(1).max(4096);
4
4
  const name = z.string().min(1).max(512);
5
5
  const MAX_COMPOSER_TAG_BYTES = 128 * 1024;
6
+ export const MAX_COMPOSER_QUOTE_CHARACTERS = 8000;
7
+ export const MAX_COMPOSER_MESSAGE_CHARACTERS = 100_000;
8
+ const quoteFields = {
9
+ type: z.literal('quote'),
10
+ id: z.string().min(1).max(128),
11
+ label: name,
12
+ text: z
13
+ .string()
14
+ .min(1)
15
+ .max(MAX_COMPOSER_QUOTE_CHARACTERS)
16
+ .refine((value) => value.trim().length > 0)
17
+ };
18
+ const quoteLine = z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
19
+ /** Explicit snapshots describe a source; they never grant access to a live resource. */
20
+ export const composerQuoteSchema = z
21
+ .discriminatedUnion('source', [
22
+ z
23
+ .object({
24
+ ...quoteFields,
25
+ source: z.literal('file'),
26
+ path,
27
+ origin: z.enum(['WORKING_TREE', 'HISTORY']),
28
+ startLine: quoteLine,
29
+ endLine: quoteLine,
30
+ revision: name.optional(),
31
+ unsaved: z.boolean().optional()
32
+ })
33
+ .strict(),
34
+ z
35
+ .object({
36
+ ...quoteFields,
37
+ source: z.literal('diff'),
38
+ path,
39
+ origin: z.enum(['WORKING_TREE', 'HISTORY', 'TOOL_CHANGE']),
40
+ revision: name.optional(),
41
+ side: z.enum(['old', 'new', 'mixed']).optional(),
42
+ startLine: quoteLine.optional(),
43
+ endLine: quoteLine.optional(),
44
+ oldStartLine: quoteLine.optional(),
45
+ oldEndLine: quoteLine.optional()
46
+ })
47
+ .strict(),
48
+ z
49
+ .object({
50
+ ...quoteFields,
51
+ source: z.literal('assistant'),
52
+ messageId: z.string().min(1).max(512),
53
+ timestamp: name.optional(),
54
+ streaming: z.boolean().optional()
55
+ })
56
+ .strict()
57
+ ])
58
+ .refine((quote) => {
59
+ if (quote.source === 'assistant')
60
+ return true;
61
+ if ((quote.startLine === undefined) !== (quote.endLine === undefined))
62
+ return false;
63
+ if (quote.startLine !== undefined && quote.endLine < quote.startLine)
64
+ return false;
65
+ return (quote.source !== 'diff' ||
66
+ ((quote.oldStartLine === undefined) === (quote.oldEndLine === undefined) &&
67
+ (quote.oldStartLine === undefined || quote.oldEndLine >= quote.oldStartLine)));
68
+ });
6
69
  export const channelDisplayNameSchema = z
7
70
  .string()
8
71
  .trim()
@@ -95,7 +158,8 @@ export const composerTagSchemas = {
95
158
  sessionId: z.string().min(1).max(512),
96
159
  label: name
97
160
  })
98
- .strict()
161
+ .strict(),
162
+ composerQuoteSchema
99
163
  ]))
100
164
  .min(1)
101
165
  .max(128)
@@ -129,8 +193,14 @@ export function serializeComposerTag(kind, payload) {
129
193
  attributes[key] = item;
130
194
  else if (Array.isArray(item)) {
131
195
  const leaf = key === 'files' ? 'file' : key === 'skills' ? 'skill' : 'reference';
132
- for (const entry of item)
133
- children.push(` <${leaf}${markupAttributes(entry)} />`);
196
+ for (const entry of item) {
197
+ if (kind === 'mar_references' && entry.type === 'quote') {
198
+ const { text, ...attributes } = entry;
199
+ children.push(` <${leaf}${markupAttributes(attributes)}>${escapeMarkup(text)}</${leaf}>`);
200
+ }
201
+ else
202
+ children.push(` <${leaf}${markupAttributes(entry)} />`);
203
+ }
134
204
  }
135
205
  else
136
206
  children.push(item === '' ? ` <${key} />` : ` <${key}>${escapeMarkup(String(item))}</${key}>`);
@@ -176,12 +246,25 @@ function parseComposerPayload(raw) {
176
246
  : [];
177
247
  for (const field of root.fields) {
178
248
  if (list && field.name === list[0]) {
179
- if (field.text !== '')
249
+ const quote = kind === 'mar_references' && field.attributes.type === 'quote';
250
+ if (!quote && field.text !== '')
180
251
  return undefined;
181
252
  const values = (payload[list[1]] ??= []);
182
253
  if (!Array.isArray(values))
183
254
  return undefined;
184
- values.push({ ...field.attributes });
255
+ const entry = { ...field.attributes };
256
+ if (quote) {
257
+ entry.text = field.text;
258
+ for (const key of ['startLine', 'endLine', 'oldStartLine', 'oldEndLine']) {
259
+ if (typeof entry[key] === 'string' && /^[1-9]\d*$/u.test(entry[key]))
260
+ entry[key] = Number(entry[key]);
261
+ }
262
+ for (const key of ['unsaved', 'streaming']) {
263
+ if (entry[key] === 'true' || entry[key] === 'false')
264
+ entry[key] = entry[key] === 'true';
265
+ }
266
+ }
267
+ values.push(entry);
185
268
  }
186
269
  else {
187
270
  if (!scalar.includes(field.name) ||