@neta-art/cohub-protocol 1.2.2 → 1.2.3

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.
@@ -0,0 +1,299 @@
1
+ import { z } from "zod";
2
+ import type { ContentBlock, MessageRecord } from "./session-ingestion.js";
3
+ export declare const contentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
4
+ type: z.ZodLiteral<"text">;
5
+ text: z.ZodString;
6
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
7
+ }, z.core.$strip>, z.ZodObject<{
8
+ type: z.ZodLiteral<"thinking">;
9
+ thinking: z.ZodString;
10
+ signature: z.ZodOptional<z.ZodString>;
11
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
12
+ }, z.core.$strip>, z.ZodObject<{
13
+ type: z.ZodLiteral<"image">;
14
+ source: z.ZodUnion<readonly [z.ZodObject<{
15
+ type: z.ZodLiteral<"url">;
16
+ url: z.ZodString;
17
+ }, z.core.$strip>, z.ZodObject<{
18
+ type: z.ZodLiteral<"base64">;
19
+ media_type: z.ZodString;
20
+ data: z.ZodString;
21
+ }, z.core.$strip>]>;
22
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
23
+ }, z.core.$strip>, z.ZodObject<{
24
+ type: z.ZodLiteral<"tool_use">;
25
+ id: z.ZodString;
26
+ name: z.ZodString;
27
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
28
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
29
+ }, z.core.$strip>, z.ZodObject<{
30
+ type: z.ZodLiteral<"tool_result">;
31
+ tool_use_id: z.ZodString;
32
+ content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodUnknown>]>;
33
+ is_error: z.ZodOptional<z.ZodBoolean>;
34
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
35
+ }, z.core.$strip>, z.ZodObject<{
36
+ type: z.ZodLiteral<"system_note">;
37
+ note_type: z.ZodEnum<{
38
+ session_created: "session_created";
39
+ forked: "forked";
40
+ compacted: "compacted";
41
+ info: "info";
42
+ }>;
43
+ text: z.ZodString;
44
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
45
+ }, z.core.$strip>], "type">;
46
+ export declare const wsClientEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
47
+ type: z.ZodLiteral<"auth">;
48
+ requestId: z.ZodOptional<z.ZodString>;
49
+ payload: z.ZodObject<{
50
+ token: z.ZodString;
51
+ }, z.core.$strip>;
52
+ }, z.core.$strip>, z.ZodObject<{
53
+ type: z.ZodLiteral<"session.message.create">;
54
+ requestId: z.ZodOptional<z.ZodString>;
55
+ payload: z.ZodObject<{
56
+ spaceId: z.ZodString;
57
+ sessionId: z.ZodString;
58
+ clientMessageId: z.ZodOptional<z.ZodString>;
59
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
60
+ type: z.ZodLiteral<"text">;
61
+ text: z.ZodString;
62
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
63
+ }, z.core.$strip>, z.ZodObject<{
64
+ type: z.ZodLiteral<"thinking">;
65
+ thinking: z.ZodString;
66
+ signature: z.ZodOptional<z.ZodString>;
67
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
68
+ }, z.core.$strip>, z.ZodObject<{
69
+ type: z.ZodLiteral<"image">;
70
+ source: z.ZodUnion<readonly [z.ZodObject<{
71
+ type: z.ZodLiteral<"url">;
72
+ url: z.ZodString;
73
+ }, z.core.$strip>, z.ZodObject<{
74
+ type: z.ZodLiteral<"base64">;
75
+ media_type: z.ZodString;
76
+ data: z.ZodString;
77
+ }, z.core.$strip>]>;
78
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
79
+ }, z.core.$strip>, z.ZodObject<{
80
+ type: z.ZodLiteral<"tool_use">;
81
+ id: z.ZodString;
82
+ name: z.ZodString;
83
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
84
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
85
+ }, z.core.$strip>, z.ZodObject<{
86
+ type: z.ZodLiteral<"tool_result">;
87
+ tool_use_id: z.ZodString;
88
+ content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodUnknown>]>;
89
+ is_error: z.ZodOptional<z.ZodBoolean>;
90
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
91
+ }, z.core.$strip>, z.ZodObject<{
92
+ type: z.ZodLiteral<"system_note">;
93
+ note_type: z.ZodEnum<{
94
+ session_created: "session_created";
95
+ forked: "forked";
96
+ compacted: "compacted";
97
+ info: "info";
98
+ }>;
99
+ text: z.ZodString;
100
+ _meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
101
+ }, z.core.$strip>], "type">>;
102
+ model: z.ZodOptional<z.ZodString>;
103
+ provider: z.ZodOptional<z.ZodString>;
104
+ }, z.core.$strip>;
105
+ }, z.core.$strip>, z.ZodObject<{
106
+ type: z.ZodLiteral<"ping">;
107
+ requestId: z.ZodOptional<z.ZodString>;
108
+ payload: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
109
+ }, z.core.$strip>, z.ZodObject<{
110
+ type: z.ZodLiteral<"ack">;
111
+ requestId: z.ZodOptional<z.ZodString>;
112
+ payload: z.ZodOptional<z.ZodObject<{
113
+ eventId: z.ZodOptional<z.ZodString>;
114
+ }, z.core.$strip>>;
115
+ }, z.core.$strip>], "type">;
116
+ export declare const realtimeEnvelopeSchema: z.ZodObject<{
117
+ id: z.ZodString;
118
+ timestamp: z.ZodNumber;
119
+ domain: z.ZodEnum<{
120
+ system: "system";
121
+ session: "session";
122
+ space: "space";
123
+ }>;
124
+ type: z.ZodString;
125
+ requestId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
126
+ spaceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
127
+ sessionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
128
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
129
+ }, z.core.$strip>;
130
+ export type { ContentBlock };
131
+ export type WsClientEvent = {
132
+ type: "auth";
133
+ requestId?: string;
134
+ payload: {
135
+ token: string;
136
+ };
137
+ } | {
138
+ type: "session.message.create";
139
+ requestId?: string;
140
+ payload: {
141
+ spaceId: string;
142
+ sessionId: string;
143
+ clientMessageId?: string;
144
+ content: ContentBlock[];
145
+ model?: string;
146
+ provider?: string;
147
+ };
148
+ } | {
149
+ type: "ping";
150
+ requestId?: string;
151
+ payload?: Record<string, unknown>;
152
+ } | {
153
+ type: "ack";
154
+ requestId?: string;
155
+ payload?: {
156
+ eventId?: string;
157
+ };
158
+ };
159
+ export type RealtimeEnvelope = z.output<typeof realtimeEnvelopeSchema>;
160
+ export type RealtimeEnvelopeBase = RealtimeEnvelope;
161
+ export type RealtimeDomain = RealtimeEnvelopeBase["domain"];
162
+ export type SystemReadyEvent = {
163
+ id: string;
164
+ timestamp: number;
165
+ domain: "system";
166
+ type: "system.ready";
167
+ requestId?: string | null;
168
+ spaceId?: string | null;
169
+ sessionId?: string | null;
170
+ payload: {
171
+ connectionId: string;
172
+ };
173
+ };
174
+ export type SystemAuthOkEvent = {
175
+ id: string;
176
+ timestamp: number;
177
+ domain: "system";
178
+ type: "system.auth.ok";
179
+ requestId?: string | null;
180
+ spaceId?: string | null;
181
+ sessionId?: string | null;
182
+ payload: {
183
+ connectionId: string;
184
+ user: Record<string, unknown>;
185
+ };
186
+ };
187
+ export type SystemRequestErrorEvent = {
188
+ id: string;
189
+ timestamp: number;
190
+ domain: "system";
191
+ type: "system.request.error";
192
+ requestId?: string | null;
193
+ spaceId?: string | null;
194
+ sessionId?: string | null;
195
+ payload: {
196
+ code: string;
197
+ message: string;
198
+ };
199
+ };
200
+ export type SystemPongEvent = {
201
+ id: string;
202
+ timestamp: number;
203
+ domain: "system";
204
+ type: "system.pong";
205
+ requestId?: string | null;
206
+ spaceId?: string | null;
207
+ sessionId?: string | null;
208
+ payload: Record<string, never>;
209
+ };
210
+ export type SystemAckOkEvent = {
211
+ id: string;
212
+ timestamp: number;
213
+ domain: "system";
214
+ type: "system.ack.ok";
215
+ requestId?: string | null;
216
+ spaceId?: string | null;
217
+ sessionId?: string | null;
218
+ payload: Record<string, never>;
219
+ };
220
+ export type SessionRequestAcceptedEvent = {
221
+ id: string;
222
+ timestamp: number;
223
+ domain: "session";
224
+ type: "session.request.accepted";
225
+ requestId?: string | null;
226
+ spaceId: string;
227
+ sessionId: string;
228
+ payload: {
229
+ clientMessageId?: string | null;
230
+ };
231
+ };
232
+ export type SessionRequestErrorEvent = {
233
+ id: string;
234
+ timestamp: number;
235
+ domain: "session";
236
+ type: "session.request.error";
237
+ requestId?: string | null;
238
+ spaceId?: string | null;
239
+ sessionId?: string | null;
240
+ payload: {
241
+ code: string;
242
+ message: string;
243
+ clientMessageId?: string | null;
244
+ };
245
+ };
246
+ export type SessionTurnProgressEvent = {
247
+ id: string;
248
+ timestamp: number;
249
+ domain: "session";
250
+ type: "session.turn.progress";
251
+ requestId?: string | null;
252
+ spaceId: string;
253
+ sessionId: string;
254
+ payload: {
255
+ anchorUserMessageId: string | null;
256
+ content: ContentBlock[];
257
+ };
258
+ };
259
+ export type SessionTurnFinalEvent = {
260
+ id: string;
261
+ timestamp: number;
262
+ domain: "session";
263
+ type: "session.turn.final";
264
+ requestId?: string | null;
265
+ spaceId: string;
266
+ sessionId: string;
267
+ payload: {
268
+ sessionMessageId: string | null;
269
+ anchorUserMessageId: string | null;
270
+ content: ContentBlock[];
271
+ };
272
+ };
273
+ export type SessionTurnErrorEvent = {
274
+ id: string;
275
+ timestamp: number;
276
+ domain: "session";
277
+ type: "session.turn.error";
278
+ requestId?: string | null;
279
+ spaceId: string;
280
+ sessionId: string;
281
+ payload: {
282
+ anchorUserMessageId: string | null;
283
+ error: string;
284
+ };
285
+ };
286
+ export type SessionMessagePersistedEvent = {
287
+ id: string;
288
+ timestamp: number;
289
+ domain: "session";
290
+ type: "session.message.persisted";
291
+ requestId?: string | null;
292
+ spaceId: string;
293
+ sessionId: string;
294
+ payload: {
295
+ message: MessageRecord;
296
+ };
297
+ };
298
+ export type RealtimeServerEvent = SystemReadyEvent | SystemAuthOkEvent | SystemRequestErrorEvent | SystemPongEvent | SystemAckOkEvent | SessionRequestAcceptedEvent | SessionRequestErrorEvent | SessionTurnProgressEvent | SessionTurnFinalEvent | SessionTurnErrorEvent | SessionMessagePersistedEvent;
299
+ export type WsServerEnvelope = RealtimeEnvelope;
@@ -0,0 +1,85 @@
1
+ import { z } from "zod";
2
+ const contentBlockMetaSchema = z.record(z.string(), z.unknown());
3
+ // ── Schemas ──
4
+ export const contentBlockSchema = z.discriminatedUnion("type", [
5
+ z.object({
6
+ type: z.literal("text"),
7
+ text: z.string(),
8
+ _meta: contentBlockMetaSchema.optional(),
9
+ }),
10
+ z.object({
11
+ type: z.literal("thinking"),
12
+ thinking: z.string(),
13
+ signature: z.string().optional(),
14
+ _meta: contentBlockMetaSchema.optional(),
15
+ }),
16
+ z.object({
17
+ type: z.literal("image"),
18
+ source: z.union([
19
+ z.object({ type: z.literal("url"), url: z.string().url() }),
20
+ z.object({ type: z.literal("base64"), media_type: z.string(), data: z.string() }),
21
+ ]),
22
+ _meta: contentBlockMetaSchema.optional(),
23
+ }),
24
+ z.object({
25
+ type: z.literal("tool_use"),
26
+ id: z.string(),
27
+ name: z.string(),
28
+ input: z.record(z.string(), z.unknown()),
29
+ _meta: contentBlockMetaSchema.optional(),
30
+ }),
31
+ z.object({
32
+ type: z.literal("tool_result"),
33
+ tool_use_id: z.string(),
34
+ content: z.union([z.string(), z.array(z.unknown())]),
35
+ is_error: z.boolean().optional(),
36
+ _meta: contentBlockMetaSchema.optional(),
37
+ }),
38
+ z.object({
39
+ type: z.literal("system_note"),
40
+ note_type: z.enum(["session_created", "forked", "compacted", "info"]),
41
+ text: z.string(),
42
+ _meta: contentBlockMetaSchema.optional(),
43
+ }),
44
+ ]);
45
+ export const wsClientEventSchema = z.discriminatedUnion("type", [
46
+ z.object({
47
+ type: z.literal("auth"),
48
+ requestId: z.string().optional(),
49
+ payload: z.object({ token: z.string().min(1) }),
50
+ }),
51
+ z.object({
52
+ type: z.literal("session.message.create"),
53
+ requestId: z.string().optional(),
54
+ payload: z.object({
55
+ spaceId: z.string().uuid(),
56
+ sessionId: z.string().uuid(),
57
+ clientMessageId: z.string().optional(),
58
+ content: z.array(contentBlockSchema).min(1),
59
+ model: z.string().optional(),
60
+ provider: z.string().optional(),
61
+ }),
62
+ }),
63
+ z.object({
64
+ type: z.literal("ping"),
65
+ requestId: z.string().optional(),
66
+ payload: z.record(z.string(), z.unknown()).optional(),
67
+ }),
68
+ z.object({
69
+ type: z.literal("ack"),
70
+ requestId: z.string().optional(),
71
+ payload: z.object({
72
+ eventId: z.string().optional(),
73
+ }).optional(),
74
+ }),
75
+ ]);
76
+ export const realtimeEnvelopeSchema = z.object({
77
+ id: z.string(),
78
+ timestamp: z.number(),
79
+ domain: z.enum(["system", "session", "space"]),
80
+ type: z.string(),
81
+ requestId: z.string().nullable().optional(),
82
+ spaceId: z.string().nullable().optional(),
83
+ sessionId: z.string().nullable().optional(),
84
+ payload: z.record(z.string(), z.unknown()),
85
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neta-art/cohub-protocol",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Shared protocol definitions for the Cohub agent collaboration platform.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -52,6 +52,10 @@
52
52
  "./fs": {
53
53
  "types": "./dist/fs/index.d.ts",
54
54
  "default": "./dist/fs/index.js"
55
+ },
56
+ "./ports": {
57
+ "types": "./dist/ports/index.d.ts",
58
+ "default": "./dist/ports/index.js"
55
59
  }
56
60
  },
57
61
  "types": "./dist/index.d.ts",