@neta-art/cohub-protocol 1.1.0 → 1.2.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.
@@ -1,3 +1,17 @@
1
+ export type SpaceFsChange = {
2
+ path?: string;
3
+ oldPath?: string;
4
+ kind: "create" | "modify" | "delete" | "rename";
5
+ nodeType?: "file" | "dir" | "unknown";
6
+ mtimeMs?: number;
7
+ size?: number;
8
+ };
9
+ export type SpaceFsChangedPayload = {
10
+ source: "sandbox-inotify" | "api-fs" | "bootstrap" | "sandbox-watch-started";
11
+ seq?: number;
12
+ resync?: boolean;
13
+ changes: SpaceFsChange[];
14
+ };
1
15
  export type SpaceFsEntry = {
2
16
  name: string;
3
17
  path: string;
@@ -31,3 +45,19 @@ export type SpaceFsMoveInput = {
31
45
  fromPath: string;
32
46
  toPath: string;
33
47
  };
48
+ export type SpaceFsUploadEntry = {
49
+ path: string;
50
+ name: string;
51
+ size: number;
52
+ mimeType: string | null;
53
+ mtimeMs: number;
54
+ };
55
+ export type SpaceFsUploadError = {
56
+ name: string;
57
+ code: "file_too_large" | "name_invalid" | "write_failed";
58
+ message: string;
59
+ };
60
+ export type SpaceFsUploadResponse = {
61
+ uploaded: SpaceFsUploadEntry[];
62
+ errors: SpaceFsUploadError[];
63
+ };
@@ -48,20 +48,42 @@ export interface GatewayInboundEvent {
48
48
  meta?: Record<string, unknown> | null;
49
49
  }
50
50
  export interface GatewaySessionOutputBase {
51
- type: "session.turn.progress" | "session.turn.final" | "session.turn.error" | "session.message.persisted";
51
+ type: "session.turn.patch" | "session.turn.error" | "session.message.persisted";
52
52
  spaceId: string;
53
53
  sessionId: string;
54
54
  }
55
- export interface GatewaySessionTurnProgressOutput extends GatewaySessionOutputBase {
56
- type: "session.turn.progress";
55
+ export type GatewaySessionPatchOperation = {
56
+ o: "append";
57
+ p: string;
58
+ v: unknown;
59
+ } | {
60
+ o: "replace";
61
+ p: string;
62
+ v: unknown;
63
+ } | {
64
+ o: "add";
65
+ p: string;
66
+ v: unknown;
67
+ } | {
68
+ o: "merge";
69
+ p: string;
70
+ v: Record<string, unknown>;
71
+ } | {
72
+ o: "remove";
73
+ p: string;
74
+ } | {
75
+ v: unknown;
76
+ o?: undefined;
77
+ p?: undefined;
78
+ };
79
+ export interface GatewaySessionTurnPatchOutput extends GatewaySessionOutputBase {
80
+ type: "session.turn.patch";
81
+ turnId: string | null;
82
+ messageId: string | null;
57
83
  anchorUserMessageId: string | null;
58
- content: ContentBlock[];
59
- }
60
- export interface GatewaySessionTurnFinalOutput extends GatewaySessionOutputBase {
61
- type: "session.turn.final";
62
- sessionMessageId: string | null;
63
- anchorUserMessageId: string | null;
64
- content: ContentBlock[];
84
+ seq: number;
85
+ baseSeq: number;
86
+ ops: GatewaySessionPatchOperation[];
65
87
  }
66
88
  export interface GatewaySessionTurnErrorOutput extends GatewaySessionOutputBase {
67
89
  type: "session.turn.error";
@@ -72,7 +94,7 @@ export interface GatewaySessionMessagePersistedOutput extends GatewaySessionOutp
72
94
  type: "session.message.persisted";
73
95
  message: MessageRecord;
74
96
  }
75
- export type GatewaySessionOutput = GatewaySessionTurnProgressOutput | GatewaySessionTurnFinalOutput | GatewaySessionTurnErrorOutput | GatewaySessionMessagePersistedOutput;
97
+ export type GatewaySessionOutput = GatewaySessionTurnPatchOutput | GatewaySessionTurnErrorOutput | GatewaySessionMessagePersistedOutput;
76
98
  export interface GatewayOutboundCommand {
77
99
  commandId: string;
78
100
  timestamp: number;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./core/content.js";
2
2
  export * from "./core/usage.js";
3
3
  export * from "./model/session.js";
4
+ export * from "./model/turn.js";
4
5
  export * from "./realtime/stream.js";
5
6
  export * from "./realtime/websocket.js";
6
7
  export * from "./gateway/index.js";
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./core/content.js";
2
2
  export * from "./core/usage.js";
3
3
  export * from "./model/session.js";
4
+ export * from "./model/turn.js";
4
5
  export * from "./realtime/stream.js";
5
6
  export * from "./realtime/websocket.js";
6
7
  export * from "./gateway/index.js";
@@ -1,5 +1,6 @@
1
1
  import type { ContentBlock } from "../core/content.js";
2
2
  import type { Usage } from "../core/usage.js";
3
+ export type { MessageToolCallsFile, SessionTurnIntent, SessionTurnIntermediateIndex, SessionTurnIntermediateSummary, SessionTurnRecord, SessionTurnStatus, SessionTurnSummary, StoredIntermediateMessage, StoredIntermediateMessageToolCallSummary, StoredToolCall, TurnIntermediateMessagesFile, } from "./turn.js";
3
4
  export type SessionPromptInput = {
4
5
  spaceId: string;
5
6
  sessionId: string;
@@ -9,9 +10,10 @@ export type SessionPromptInput = {
9
10
  };
10
11
  meta?: {
11
12
  source?: string;
12
- intent?: "auto" | "continue" | "new_session" | "fork";
13
+ intent?: "auto" | "continue" | "new_session" | "fork" | "steer" | "followup";
13
14
  model?: string;
14
15
  provider?: string;
16
+ turnId?: string;
15
17
  } | null;
16
18
  };
17
19
  export type RegisterSessionInput = {
@@ -0,0 +1,95 @@
1
+ import type { ContentBlock } from "../core/content.js";
2
+ import type { Usage } from "../core/usage.js";
3
+ export type SessionTurnStatus = "running" | "completed" | "failed" | "interrupted";
4
+ export type SessionTurnIntent = "steer" | "followup";
5
+ export type SessionTurnSummary = {
6
+ text?: string | null;
7
+ finishReason?: "completed" | "failed" | "interrupted";
8
+ interruptedByTurnId?: string | null;
9
+ };
10
+ export type SessionTurnIntermediateIndex = {
11
+ version: 1;
12
+ messagesObjectKey: string | null;
13
+ messagesSizeBytes?: number | null;
14
+ toolCallsBaseObjectKey?: string | null;
15
+ };
16
+ export type SessionTurnIntermediateSummary = {
17
+ messageCount: number;
18
+ toolCallCount: number;
19
+ usage?: Usage | null;
20
+ lastMessageText?: string | null;
21
+ hasError?: boolean;
22
+ };
23
+ export type StoredIntermediateMessageToolCallSummary = {
24
+ id: string;
25
+ name: string;
26
+ status: "running" | "done" | "failed";
27
+ input: Record<string, unknown>;
28
+ };
29
+ export type StoredIntermediateMessage = {
30
+ id: string;
31
+ sessionId: string;
32
+ role: "user" | "assistant" | "system";
33
+ content: ContentBlock[];
34
+ text: string | null;
35
+ provider: string | null;
36
+ model: string | null;
37
+ stopReason: string | null;
38
+ errorMessage: string | null;
39
+ usage: Usage | null;
40
+ toolCalls: StoredIntermediateMessageToolCallSummary[];
41
+ toolCallsObjectKey: string | null;
42
+ meta: Record<string, unknown> | null;
43
+ createdAt: string;
44
+ };
45
+ export type StoredToolCall = {
46
+ id: string;
47
+ name: string;
48
+ input: Record<string, unknown>;
49
+ result: {
50
+ content: string | ContentBlock[] | null;
51
+ isError: boolean;
52
+ } | null;
53
+ meta: Record<string, unknown> | null;
54
+ };
55
+ export type MessageToolCallsFile = {
56
+ version: 1;
57
+ spaceId: string;
58
+ sessionId: string;
59
+ turnId: string;
60
+ messageId: string;
61
+ toolCalls: StoredToolCall[];
62
+ };
63
+ export type TurnIntermediateMessagesFile = {
64
+ version: 1;
65
+ spaceId: string;
66
+ sessionId: string;
67
+ turnId: string;
68
+ summary: SessionTurnIntermediateSummary;
69
+ messages: StoredIntermediateMessage[];
70
+ };
71
+ export type SessionTurnRecord = {
72
+ id: string;
73
+ sessionId: string;
74
+ userUuid: string | null;
75
+ sequence: number;
76
+ status: SessionTurnStatus;
77
+ intent: SessionTurnIntent;
78
+ userContent: ContentBlock[];
79
+ userText: string | null;
80
+ assistantContent: ContentBlock[] | null;
81
+ assistantText: string | null;
82
+ provider: string | null;
83
+ model: string | null;
84
+ stopReason: string | null;
85
+ errorMessage: string | null;
86
+ usage: Usage | null;
87
+ summary: SessionTurnSummary | null;
88
+ intermediateIndex: SessionTurnIntermediateIndex | null;
89
+ intermediateSummary: SessionTurnIntermediateSummary | null;
90
+ meta: Record<string, unknown> | null;
91
+ startedAt: string | null;
92
+ completedAt: string | null;
93
+ createdAt: string;
94
+ updatedAt: string;
95
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -3,6 +3,9 @@ export type SessionStreamEvent = {
3
3
  type: "stream_update";
4
4
  spaceId: string;
5
5
  sessionId: string;
6
+ turnId?: string | null;
7
+ seq: number;
8
+ baseSeq: number;
6
9
  content: ContentBlock[];
7
10
  sourceMessageId: string | null;
8
11
  timestamp: number;
@@ -1,6 +1,8 @@
1
1
  import { z } from "zod";
2
2
  import type { ContentBlock } from "../core/content.js";
3
3
  import type { MessageRecord } from "../model/session.js";
4
+ import type { SpaceFsChangedPayload } from "../fs/index.js";
5
+ export declare const WS_COMPACT_STREAM_CAPABILITY = "session.compact_stream.v1";
4
6
  export declare const contentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5
7
  type: z.ZodLiteral<"text">;
6
8
  text: z.ZodString;
@@ -49,6 +51,7 @@ export declare const wsClientEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
49
51
  requestId: z.ZodOptional<z.ZodString>;
50
52
  payload: z.ZodObject<{
51
53
  token: z.ZodString;
54
+ capabilities: z.ZodOptional<z.ZodArray<z.ZodString>>;
52
55
  }, z.core.$strip>;
53
56
  }, z.core.$strip>, z.ZodObject<{
54
57
  type: z.ZodLiteral<"session.message.create">;
@@ -142,11 +145,33 @@ export declare const channelEnvelopeSchema: z.ZodObject<{
142
145
  sessionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
143
146
  payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
144
147
  }, z.core.$strip>;
148
+ export declare const realtimeCompactFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
149
+ t: z.ZodLiteral<"d">;
150
+ sid: z.ZodString;
151
+ s: z.ZodNumber;
152
+ b: z.ZodNumber;
153
+ v: z.ZodUnknown;
154
+ }, z.core.$strip>, z.ZodObject<{
155
+ t: z.ZodLiteral<"p">;
156
+ sid: z.ZodString;
157
+ s: z.ZodNumber;
158
+ b: z.ZodNumber;
159
+ o: z.ZodEnum<{
160
+ append: "append";
161
+ replace: "replace";
162
+ add: "add";
163
+ merge: "merge";
164
+ remove: "remove";
165
+ }>;
166
+ p: z.ZodString;
167
+ v: z.ZodOptional<z.ZodUnknown>;
168
+ }, z.core.$strip>], "t">;
145
169
  export type WsClientEvent = {
146
170
  type: "auth";
147
171
  requestId?: string;
148
172
  payload: {
149
173
  token: string;
174
+ capabilities?: string[];
150
175
  };
151
176
  } | {
152
177
  type: "session.message.create";
@@ -172,6 +197,7 @@ export type WsClientEvent = {
172
197
  };
173
198
  export type RealtimeEnvelope = z.output<typeof realtimeEnvelopeSchema>;
174
199
  export type ChannelEnvelope = RealtimeEnvelope;
200
+ export type RealtimeCompactFrame = z.output<typeof realtimeCompactFrameSchema>;
175
201
  export type RealtimeEnvelopeBase = RealtimeEnvelope;
176
202
  export type RealtimeDomain = RealtimeEnvelopeBase["domain"];
177
203
  export type SystemReadyEvent = {
@@ -271,18 +297,45 @@ export type SessionTurnProgressEvent = {
271
297
  content: ContentBlock[];
272
298
  };
273
299
  };
274
- export type SessionTurnFinalEvent = {
300
+ export type RealtimePatchOperation = {
301
+ o: "append";
302
+ p: string;
303
+ v: unknown;
304
+ } | {
305
+ o: "replace";
306
+ p: string;
307
+ v: unknown;
308
+ } | {
309
+ o: "add";
310
+ p: string;
311
+ v: unknown;
312
+ } | {
313
+ o: "merge";
314
+ p: string;
315
+ v: Record<string, unknown>;
316
+ } | {
317
+ o: "remove";
318
+ p: string;
319
+ } | {
320
+ v: unknown;
321
+ o?: undefined;
322
+ p?: undefined;
323
+ };
324
+ export type SessionTurnPatchEvent = {
275
325
  id: string;
276
326
  timestamp: number;
277
327
  domain: "session";
278
- type: "session.turn.final";
328
+ type: "session.turn.patch";
279
329
  requestId?: string | null;
280
330
  spaceId: string;
281
331
  sessionId: string;
282
332
  payload: {
283
- sessionMessageId: string | null;
333
+ turnId: string | null;
334
+ messageId: string | null;
284
335
  anchorUserMessageId: string | null;
285
- content: ContentBlock[];
336
+ seq: number;
337
+ baseSeq: number;
338
+ ops: RealtimePatchOperation[];
286
339
  };
287
340
  };
288
341
  export type SessionTurnErrorEvent = {
@@ -298,6 +351,7 @@ export type SessionTurnErrorEvent = {
298
351
  error: string;
299
352
  };
300
353
  };
354
+ export type RealtimeMessageRecord = Pick<MessageRecord, "id" | "sessionId" | "role" | "content" | "text" | "sequence" | "provider" | "model" | "stopReason" | "errorMessage" | "usage" | "meta" | "createdAt">;
301
355
  export type SessionMessagePersistedEvent = {
302
356
  id: string;
303
357
  timestamp: number;
@@ -307,9 +361,19 @@ export type SessionMessagePersistedEvent = {
307
361
  spaceId: string;
308
362
  sessionId: string;
309
363
  payload: {
310
- message: MessageRecord;
364
+ message: RealtimeMessageRecord;
311
365
  };
312
366
  };
313
- export type RealtimeServerEvent = SystemReadyEvent | SystemAuthOkEvent | SystemRequestErrorEvent | SystemPongEvent | SystemAckOkEvent | SessionRequestAcceptedEvent | SessionRequestErrorEvent | SessionTurnProgressEvent | SessionTurnFinalEvent | SessionTurnErrorEvent | SessionMessagePersistedEvent;
367
+ export type SpaceFsChangedEvent = {
368
+ id: string;
369
+ timestamp: number;
370
+ domain: "space";
371
+ type: "space.fs.changed";
372
+ requestId?: string | null;
373
+ spaceId: string;
374
+ sessionId?: string | null;
375
+ payload: SpaceFsChangedPayload;
376
+ };
377
+ export type RealtimeServerEvent = SystemReadyEvent | SystemAuthOkEvent | SystemRequestErrorEvent | SystemPongEvent | SystemAckOkEvent | SessionRequestAcceptedEvent | SessionRequestErrorEvent | SessionTurnProgressEvent | SessionTurnPatchEvent | SessionTurnErrorEvent | SessionMessagePersistedEvent | SpaceFsChangedEvent;
314
378
  export type WsServerEnvelope = RealtimeEnvelope;
315
379
  export type ChannelServerEnvelope = ChannelEnvelope;
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  const contentBlockMetaSchema = z.record(z.string(), z.unknown());
3
+ export const WS_COMPACT_STREAM_CAPABILITY = "session.compact_stream.v1";
3
4
  export const contentBlockSchema = z.discriminatedUnion("type", [
4
5
  z.object({
5
6
  type: z.literal("text"),
@@ -45,7 +46,10 @@ export const wsClientEventSchema = z.discriminatedUnion("type", [
45
46
  z.object({
46
47
  type: z.literal("auth"),
47
48
  requestId: z.string().optional(),
48
- payload: z.object({ token: z.string().min(1) }),
49
+ payload: z.object({
50
+ token: z.string().min(1),
51
+ capabilities: z.array(z.string().min(1)).optional(),
52
+ }),
49
53
  }),
50
54
  z.object({
51
55
  type: z.literal("session.message.create"),
@@ -83,3 +87,21 @@ export const realtimeEnvelopeSchema = z.object({
83
87
  payload: z.record(z.string(), z.unknown()),
84
88
  });
85
89
  export const channelEnvelopeSchema = realtimeEnvelopeSchema;
90
+ export const realtimeCompactFrameSchema = z.discriminatedUnion("t", [
91
+ z.object({
92
+ t: z.literal("d"),
93
+ sid: z.string().min(1),
94
+ s: z.number().int().nonnegative(),
95
+ b: z.number().int().nonnegative(),
96
+ v: z.unknown(),
97
+ }),
98
+ z.object({
99
+ t: z.literal("p"),
100
+ sid: z.string().min(1),
101
+ s: z.number().int().nonnegative(),
102
+ b: z.number().int().nonnegative(),
103
+ o: z.enum(["append", "replace", "add", "merge", "remove"]),
104
+ p: z.string().min(1),
105
+ v: z.unknown().optional(),
106
+ }),
107
+ ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neta-art/cohub-protocol",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Shared protocol definitions for the Cohub agent collaboration platform.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -59,15 +59,15 @@
59
59
  "dist",
60
60
  "README.md"
61
61
  ],
62
- "scripts": {
63
- "build": "tsc -p tsconfig.build.json",
64
- "typecheck": "tsgo --noEmit"
65
- },
66
62
  "devDependencies": {
67
63
  "@typescript/native-preview": "7.0.0-dev.20260421.1",
68
64
  "typescript": "^6.0.3"
69
65
  },
70
66
  "dependencies": {
71
67
  "zod": "^4.3.6"
68
+ },
69
+ "scripts": {
70
+ "build": "tsc -p tsconfig.build.json",
71
+ "typecheck": "tsgo --noEmit"
72
72
  }
73
- }
73
+ }