@myagentroam/protocol 0.11.43 → 0.11.45

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +2313 -343
  2. package/dist/index.js +101 -64
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1886,6 +1886,19 @@ const reasoningItemSchema = conversationItemBaseSchema.extend({
1886
1886
  })
1887
1887
  });
1888
1888
  export const subagentOperationSchema = z.enum(['START', 'STATUS', 'CANCEL', 'MESSAGE', 'RESUME']);
1889
+ /** Agent operations describe calls, not the lifecycle of their target Sessions. */
1890
+ export const agentOperationPresentationSchema = z.object({
1891
+ action: z.enum(['START', 'SEND', 'WAIT', 'STOP', 'LIST', 'VIEW']),
1892
+ targets: z
1893
+ .array(z.object({
1894
+ agentId: z.string().min(1).max(128),
1895
+ sessionId: z.string().min(1).max(128).optional(),
1896
+ title: z.string().min(1).max(500).optional()
1897
+ }))
1898
+ .max(100),
1899
+ targetsTruncated: z.literal(true).optional(),
1900
+ scope: z.string().min(1).max(32).optional()
1901
+ });
1889
1902
  export const subagentLatestMessageSchema = z.object({
1890
1903
  itemId: z.string().min(1).max(128),
1891
1904
  turnId: z.string().min(1).max(128),
@@ -1947,65 +1960,6 @@ export const executionPresentationSchema = z
1947
1960
  })
1948
1961
  .strict()
1949
1962
  .refine((value) => new TextEncoder().encode(JSON.stringify(value)).length <= 128 * 1024, 'Execution presentation exceeds 128 KiB');
1950
- /** Append output channels of the same call; snapshots and terminal items replace normally. */
1951
- export function appendExecutionPresentation(previous, incoming) {
1952
- const before = executionPresentationSchema.safeParse(previous);
1953
- const update = executionPresentationSchema.safeParse(incoming);
1954
- if (!update.success || !update.data.execution.output)
1955
- return incoming;
1956
- const prior = before.success ? before.data.execution : undefined;
1957
- const next = update.data.execution;
1958
- const channels = new Map((prior?.output ?? []).map((block) => [block.channel, block.text]));
1959
- let clipped = false;
1960
- for (const block of next.output ?? []) {
1961
- const text = (channels.get(block.channel) ?? '') + block.text;
1962
- let tail = text.slice(-10_000);
1963
- if (tail.length < text.length) {
1964
- clipped = true;
1965
- if (/^[\uDC00-\uDFFF]/u.test(tail))
1966
- tail = tail.slice(1);
1967
- }
1968
- channels.set(block.channel, tail);
1969
- }
1970
- const output = [...channels].map(([channel, text]) => ({ channel, text }));
1971
- let head = clipped || prior?.truncation?.output === 'HEAD' || next.truncation?.output === 'HEAD';
1972
- const make = () => ({
1973
- kind: 'EXECUTION',
1974
- execution: {
1975
- ...prior,
1976
- ...next,
1977
- output,
1978
- ...(head || prior?.truncation || next.truncation
1979
- ? {
1980
- truncation: {
1981
- ...prior?.truncation,
1982
- ...next.truncation,
1983
- ...(head ? { output: 'HEAD' } : {})
1984
- }
1985
- }
1986
- : {})
1987
- }
1988
- });
1989
- const size = () => new TextEncoder().encode(JSON.stringify(make())).length;
1990
- for (const block of output) {
1991
- if (size() <= 128 * 1024)
1992
- break;
1993
- head = true;
1994
- const original = block.text;
1995
- let low = 0;
1996
- let high = original.length;
1997
- while (low < high) {
1998
- const middle = Math.floor((low + high) / 2);
1999
- block.text = original.slice(middle).replace(/^[\uDC00-\uDFFF]/u, '');
2000
- if (size() <= 128 * 1024)
2001
- high = middle;
2002
- else
2003
- low = middle + 1;
2004
- }
2005
- block.text = original.slice(low).replace(/^[\uDC00-\uDFFF]/u, '');
2006
- }
2007
- return make();
2008
- }
2009
1963
  const toolCallPresentationSchema = z.discriminatedUnion('kind', [
2010
1964
  z.object({
2011
1965
  kind: z.literal('READ'),
@@ -2051,9 +2005,85 @@ export const toolPresentationSchema = z.union([
2051
2005
  toolCallPresentationSchema,
2052
2006
  executionPresentationSchema
2053
2007
  ]);
2008
+ export const toolOutputSchema = z
2009
+ .object({
2010
+ blocks: executionOutputSchema,
2011
+ truncation: z.enum(['HEAD', 'SOURCE']).optional()
2012
+ })
2013
+ .strict()
2014
+ .refine((value) => new TextEncoder().encode(JSON.stringify(value)).length <= 128 * 1024, 'Tool output exceeds 128 KiB');
2015
+ /** Bound public channel tails before serialization, retaining SOURCE when its direction is unknown. */
2016
+ export function boundToolOutput(blocks, truncation) {
2017
+ let clipped = false;
2018
+ const bounded = [];
2019
+ for (const { channel, text } of blocks) {
2020
+ const existing = bounded.find((block) => block.channel === channel);
2021
+ const tail = text.slice(-10_000);
2022
+ const joined = (existing?.text ?? '') + tail;
2023
+ const value = joined.slice(-10_000).replace(/^[\uDC00-\uDFFF]/u, '');
2024
+ clipped ||= tail.length < text.length || value.length < joined.length;
2025
+ if (existing)
2026
+ existing.text = value;
2027
+ else
2028
+ bounded.push({ channel, text: value });
2029
+ }
2030
+ const make = () => ({
2031
+ blocks: bounded,
2032
+ ...(truncation === 'SOURCE'
2033
+ ? { truncation: 'SOURCE' }
2034
+ : clipped || truncation === 'HEAD'
2035
+ ? { truncation: 'HEAD' }
2036
+ : {})
2037
+ });
2038
+ const size = () => new TextEncoder().encode(JSON.stringify(make())).length;
2039
+ for (const block of bounded) {
2040
+ if (size() <= 128 * 1024)
2041
+ break;
2042
+ clipped = true;
2043
+ const original = block.text;
2044
+ let low = 0;
2045
+ let high = original.length;
2046
+ while (low < high) {
2047
+ const middle = Math.floor((low + high) / 2);
2048
+ block.text = original.slice(middle).replace(/^[\uDC00-\uDFFF]/u, '');
2049
+ if (size() <= 128 * 1024)
2050
+ high = middle;
2051
+ else
2052
+ low = middle + 1;
2053
+ }
2054
+ block.text = original.slice(low).replace(/^[\uDC00-\uDFFF]/u, '');
2055
+ }
2056
+ return toolOutputSchema.parse(make());
2057
+ }
2058
+ /** Append only true deltas; incompatible channel representations require a real snapshot. */
2059
+ export function appendToolOutput(previous, incoming) {
2060
+ const channels = new Map((previous?.blocks ?? []).map(({ channel, text }) => [channel, text]));
2061
+ for (const block of incoming.blocks)
2062
+ channels.set(block.channel, (channels.get(block.channel) ?? '') + block.text);
2063
+ const source = previous?.truncation === 'SOURCE' || incoming.truncation === 'SOURCE';
2064
+ return boundToolOutput([...channels].map(([channel, text]) => ({ channel, text })), source ? 'SOURCE' : (previous?.truncation ?? incoming.truncation));
2065
+ }
2066
+ /** An output delta must not erase independent input clipping facts. */
2067
+ export function retainExecutionInputTruncation(previous, incoming) {
2068
+ const before = executionPresentationSchema.safeParse(previous);
2069
+ const after = executionPresentationSchema.safeParse(incoming);
2070
+ if (!before.success ||
2071
+ !after.success ||
2072
+ before.data.execution.truncation?.input !== true ||
2073
+ after.data.execution.truncation?.input !== undefined)
2074
+ return incoming;
2075
+ return {
2076
+ ...after.data,
2077
+ execution: {
2078
+ ...after.data.execution,
2079
+ truncation: { ...after.data.execution.truncation, input: true }
2080
+ }
2081
+ };
2082
+ }
2054
2083
  const toolOutputSnapshotSchema = z
2055
2084
  .object({ text: z.string().max(10000), truncated: z.boolean() })
2056
2085
  .strict();
2086
+ const readableToolOutputSchema = z.union([toolOutputSchema, toolOutputSnapshotSchema]);
2057
2087
  const toolCallItemSchema = conversationItemBaseSchema.extend({
2058
2088
  kind: z.literal('tool_call'),
2059
2089
  payload: z.object({
@@ -2064,10 +2094,14 @@ const toolCallItemSchema = conversationItemBaseSchema.extend({
2064
2094
  outputSummary: z.string().max(10000).nullable(),
2065
2095
  progressLabel: z.string().max(500).nullable(),
2066
2096
  errorCode: z.string().max(80).nullable(),
2067
- truncated: z.boolean(),
2068
- output: toolOutputSnapshotSchema.optional(),
2097
+ errorMessage: z.string().max(1000).optional(),
2098
+ truncated: z.boolean().optional(),
2099
+ inputTruncated: z.literal(true).optional(),
2100
+ outputSummaryTruncated: z.literal(true).optional(),
2101
+ output: readableToolOutputSchema.optional(),
2069
2102
  toolCategory: z.enum(['IMAGE_GENERATION']).optional(),
2070
2103
  toolPresentation: toolCallPresentationSchema.optional(),
2104
+ agentOperation: agentOperationPresentationSchema.optional(),
2071
2105
  subagentOperation: subagentOperationSchema.optional(),
2072
2106
  subagentWait: z.boolean().optional(),
2073
2107
  subagentId: z.string().min(1).max(128).nullable().optional(),
@@ -2086,11 +2120,13 @@ const commandExecutionItemSchema = conversationItemBaseSchema.extend({
2086
2120
  title: z.string().min(1).max(128).optional(),
2087
2121
  command: z.string().max(10000),
2088
2122
  cwd: z.string().max(4096).nullable(),
2089
- outputPreview: z.string().max(10000),
2123
+ outputPreview: z.string().max(10000).optional(),
2124
+ outputSummary: z.string().max(10000).nullable().optional(),
2125
+ outputSummaryTruncated: z.literal(true).optional(),
2090
2126
  exitCode: z.number().int().nullable(),
2091
2127
  durationMs: z.number().int().nonnegative().nullable(),
2092
- truncated: z.boolean(),
2093
- output: toolOutputSnapshotSchema.optional(),
2128
+ truncated: z.boolean().optional(),
2129
+ output: readableToolOutputSchema.optional(),
2094
2130
  toolPresentation: executionPresentationSchema.optional()
2095
2131
  })
2096
2132
  });
@@ -3261,6 +3297,7 @@ export const workbenchNodeOperationSchema = z.enum([
3261
3297
  'workspace.changes.current',
3262
3298
  'workspace.change.diff',
3263
3299
  'workspace.change.restore',
3300
+ 'workspace.git.fetch',
3264
3301
  'workspace.git.refs.list',
3265
3302
  'workspace.git.history.list',
3266
3303
  'workspace.git.commit.files',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/protocol",
3
- "version": "0.11.43",
3
+ "version": "0.11.45",
4
4
  "description": "Shared runtime protocol schemas for MyAgentRoam.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",