@myagentroam/protocol 0.10.36 → 0.10.38

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.
@@ -19,6 +19,13 @@ export declare const channelOriginSchema: z.ZodObject<{
19
19
  export type ChannelOrigin = z.infer<typeof channelOriginSchema>;
20
20
  export declare function isComposerAttachmentResourcePath(value: string): boolean;
21
21
  export declare const composerTagSchemas: {
22
+ readonly mar_steer: z.ZodObject<{
23
+ message: z.ZodString;
24
+ }, "strict", z.ZodTypeAny, {
25
+ message: string;
26
+ }, {
27
+ message: string;
28
+ }>;
22
29
  readonly mar_channel: z.ZodObject<{
23
30
  source: z.ZodLiteral<"WEB_SHARE">;
24
31
  channelId: z.ZodString;
@@ -176,6 +183,7 @@ export type ComposerTagPart = {
176
183
  };
177
184
  }[ComposerTagName];
178
185
  export declare const COMPOSER_SKILL_INSTRUCTION = "Use the selected skills for this task; load them through the available skill mechanism.";
186
+ export declare function steerComposerMessage(text: string): string;
179
187
  export declare function serializeComposerTag<K extends ComposerTagName>(kind: K, payload: ComposerTagPayloads[K]): string;
180
188
  export declare function parseComposerTags(text: string): readonly ComposerTagPart[];
181
189
  export declare function composerVisibleText(text: string): string;
@@ -37,6 +37,7 @@ const attachment = z
37
37
  target.startsWith('.mar/temp-files/')));
38
38
  });
39
39
  export const composerTagSchemas = {
40
+ mar_steer: z.object({ message: z.string().max(100_000) }).strict(),
40
41
  mar_channel: channelOriginSchema,
41
42
  mar_goal_start: z.object({ objective: z.string().max(100_000) }).strict(),
42
43
  mar_goal_continue: z.object({}).strict(),
@@ -70,10 +71,34 @@ export const composerTagSchemas = {
70
71
  .strict()
71
72
  };
72
73
  export const COMPOSER_SKILL_INSTRUCTION = 'Use the selected skills for this task; load them through the available skill mechanism.';
74
+ const STEER_PREFIX = '\nAdditional information received while you were working. Continue the current task and consider it where relevant.\n<message>\n';
75
+ const STEER_SUFFIX = '\n</message>\n';
76
+ function encodeSteerText(text) {
77
+ return text.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
78
+ }
79
+ export function steerComposerMessage(text) {
80
+ const parts = parseComposerTags(text);
81
+ const message = parts
82
+ .map((part) => (part.kind === 'text' ? part.text : part.kind === 'mar_steer' ? part.raw : ''))
83
+ .join('')
84
+ .trim();
85
+ const tags = parts
86
+ .filter((part) => part.kind !== 'text' && part.kind !== 'mar_steer')
87
+ .map((part) => part.raw);
88
+ return [serializeComposerTag('mar_steer', { message }), ...tags].join('\n');
89
+ }
73
90
  export function serializeComposerTag(kind, payload) {
74
91
  const parsed = composerTagSchemas[kind].safeParse(payload);
75
92
  if (!parsed.success)
76
93
  throw new Error('COMPOSER_TAG_INVALID');
94
+ if (kind === 'mar_steer') {
95
+ const encoded = STEER_PREFIX +
96
+ encodeSteerText(parsed.data.message) +
97
+ STEER_SUFFIX;
98
+ if (new TextEncoder().encode(encoded).byteLength > MAX_COMPOSER_TAG_BYTES)
99
+ throw new Error('COMPOSER_TAG_INVALID');
100
+ return `<mar_steer>${encoded}</mar_steer>`;
101
+ }
77
102
  const encoded = JSON.stringify(parsed.data).replaceAll('<', '\\u003c');
78
103
  if (new TextEncoder().encode(encoded).byteLength > MAX_COMPOSER_TAG_BYTES)
79
104
  throw new Error('COMPOSER_TAG_INVALID');
@@ -81,19 +106,46 @@ export function serializeComposerTag(kind, payload) {
81
106
  }
82
107
  export function parseComposerTags(text) {
83
108
  const parts = [];
84
- const pattern = /<(mar_goal_start|mar_goal_continue|mar_restart|mar_attachments|mar_schedule|mar_skills|mar_references|mar_channel)>([\s\S]*?)<\/\1>/gu;
109
+ const pattern = /(^ {0,3}(`{3,}|~{3,})([^\n]*)(?:\n|$))|<(mar_steer|mar_goal_start|mar_goal_continue|mar_restart|mar_attachments|mar_schedule|mar_skills|mar_references|mar_channel)>([\s\S]*?)<\/\4>/gmu;
110
+ let fence;
85
111
  let offset = 0;
86
112
  for (const match of text.matchAll(pattern)) {
87
- const kind = match[1];
88
- const encoded = match[2];
113
+ if (match[1] !== undefined) {
114
+ const marker = match[2];
115
+ if (fence === undefined) {
116
+ if (marker[0] !== '`' || !match[3].includes('`'))
117
+ fence = marker;
118
+ }
119
+ else if (marker[0] === fence[0] &&
120
+ marker.length >= fence.length &&
121
+ /^[ \t\r]*$/u.test(match[3]))
122
+ fence = undefined;
123
+ continue;
124
+ }
125
+ const kind = match[4];
126
+ const encoded = match[5];
89
127
  if (new TextEncoder().encode(encoded).byteLength > MAX_COMPOSER_TAG_BYTES)
90
128
  continue;
91
129
  let payload;
92
- try {
93
- payload = JSON.parse(encoded);
130
+ if (kind === 'mar_steer') {
131
+ if (fence !== undefined)
132
+ continue;
133
+ if (!encoded.startsWith(STEER_PREFIX) || !encoded.endsWith(STEER_SUFFIX))
134
+ continue;
135
+ const message = encoded.slice(STEER_PREFIX.length, -STEER_SUFFIX.length);
136
+ if (/[<>]|&(?!amp;|lt;|gt;)/u.test(message))
137
+ continue;
138
+ payload = {
139
+ message: message.replace(/&(amp|lt|gt);/gu, (_, entity) => entity === 'amp' ? '&' : entity === 'lt' ? '<' : '>')
140
+ };
94
141
  }
95
- catch {
96
- continue;
142
+ else {
143
+ try {
144
+ payload = JSON.parse(encoded);
145
+ }
146
+ catch {
147
+ continue;
148
+ }
97
149
  }
98
150
  const result = composerTagSchemas[kind].safeParse(payload);
99
151
  if (!result.success)
@@ -112,6 +164,8 @@ export function composerVisibleText(text) {
112
164
  .map((part) => {
113
165
  if (part.kind === 'text')
114
166
  return part.text;
167
+ if (part.kind === 'mar_steer')
168
+ return part.payload.message;
115
169
  if (part.kind === 'mar_goal_start')
116
170
  return part.payload.objective;
117
171
  if (part.kind === 'mar_schedule')
@@ -91,6 +91,7 @@ export declare const sessionShareAuthResultSchema: z.ZodObject<{
91
91
  }>;
92
92
  credential: z.ZodString;
93
93
  sharerName: z.ZodString;
94
+ workspaceName: z.ZodOptional<z.ZodString>;
94
95
  }, "strip", z.ZodTypeAny, {
95
96
  credential: string;
96
97
  share: {
@@ -102,6 +103,7 @@ export declare const sessionShareAuthResultSchema: z.ZodObject<{
102
103
  sessionId: string;
103
104
  };
104
105
  sharerName: string;
106
+ workspaceName?: string | undefined;
105
107
  }, {
106
108
  credential: string;
107
109
  share: {
@@ -113,6 +115,7 @@ export declare const sessionShareAuthResultSchema: z.ZodObject<{
113
115
  sessionId: string;
114
116
  };
115
117
  sharerName: string;
118
+ workspaceName?: string | undefined;
116
119
  }>;
117
120
  export type SessionShareAuthResult = z.infer<typeof sessionShareAuthResultSchema>;
118
121
  export declare const sessionShareVisitorSchema: z.ZodObject<{
@@ -28,7 +28,8 @@ export const sessionShareAuthInputSchema = z.union([
28
28
  export const sessionShareAuthResultSchema = z.object({
29
29
  share: sessionShareSchema,
30
30
  credential: sessionShareCredentialSchema,
31
- sharerName: z.string().min(1).max(512)
31
+ sharerName: z.string().min(1).max(512),
32
+ workspaceName: z.string().min(1).max(255).optional()
32
33
  });
33
34
  export const sessionShareVisitorSchema = z
34
35
  .object({ visitorId: id, name: channelDisplayNameSchema.optional() })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/protocol",
3
- "version": "0.10.36",
3
+ "version": "0.10.38",
4
4
  "description": "Shared runtime protocol schemas for MyAgentRoam.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",