@neta-art/cohub-protocol 1.2.0 → 1.2.2
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.
- package/dist/gateway/index.d.ts +33 -11
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/model/session.d.ts +3 -1
- package/dist/model/turn.d.ts +95 -0
- package/dist/model/turn.js +1 -0
- package/dist/realtime/stream.d.ts +4 -0
- package/dist/realtime/websocket.d.ts +59 -6
- package/dist/realtime/websocket.js +23 -1
- package/package.json +1 -1
package/dist/gateway/index.d.ts
CHANGED
|
@@ -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.
|
|
51
|
+
type: "session.turn.patch" | "session.turn.error" | "session.message.persisted";
|
|
52
52
|
spaceId: string;
|
|
53
53
|
sessionId: string;
|
|
54
54
|
}
|
|
55
|
-
export
|
|
56
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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 =
|
|
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
package/dist/index.js
CHANGED
package/dist/model/session.d.ts
CHANGED
|
@@ -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,7 +3,11 @@ 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[];
|
|
10
|
+
snapshotContent?: ContentBlock[];
|
|
7
11
|
sourceMessageId: string | null;
|
|
8
12
|
timestamp: number;
|
|
9
13
|
turnEnd?: boolean;
|
|
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import type { ContentBlock } from "../core/content.js";
|
|
3
3
|
import type { MessageRecord } from "../model/session.js";
|
|
4
4
|
import type { SpaceFsChangedPayload } from "../fs/index.js";
|
|
5
|
+
export declare const WS_COMPACT_STREAM_CAPABILITY = "session.compact_stream.v1";
|
|
5
6
|
export declare const contentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
6
7
|
type: z.ZodLiteral<"text">;
|
|
7
8
|
text: z.ZodString;
|
|
@@ -50,6 +51,7 @@ export declare const wsClientEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
50
51
|
requestId: z.ZodOptional<z.ZodString>;
|
|
51
52
|
payload: z.ZodObject<{
|
|
52
53
|
token: z.ZodString;
|
|
54
|
+
capabilities: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
53
55
|
}, z.core.$strip>;
|
|
54
56
|
}, z.core.$strip>, z.ZodObject<{
|
|
55
57
|
type: z.ZodLiteral<"session.message.create">;
|
|
@@ -143,11 +145,33 @@ export declare const channelEnvelopeSchema: z.ZodObject<{
|
|
|
143
145
|
sessionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
144
146
|
payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
145
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">;
|
|
146
169
|
export type WsClientEvent = {
|
|
147
170
|
type: "auth";
|
|
148
171
|
requestId?: string;
|
|
149
172
|
payload: {
|
|
150
173
|
token: string;
|
|
174
|
+
capabilities?: string[];
|
|
151
175
|
};
|
|
152
176
|
} | {
|
|
153
177
|
type: "session.message.create";
|
|
@@ -173,6 +197,7 @@ export type WsClientEvent = {
|
|
|
173
197
|
};
|
|
174
198
|
export type RealtimeEnvelope = z.output<typeof realtimeEnvelopeSchema>;
|
|
175
199
|
export type ChannelEnvelope = RealtimeEnvelope;
|
|
200
|
+
export type RealtimeCompactFrame = z.output<typeof realtimeCompactFrameSchema>;
|
|
176
201
|
export type RealtimeEnvelopeBase = RealtimeEnvelope;
|
|
177
202
|
export type RealtimeDomain = RealtimeEnvelopeBase["domain"];
|
|
178
203
|
export type SystemReadyEvent = {
|
|
@@ -272,18 +297,45 @@ export type SessionTurnProgressEvent = {
|
|
|
272
297
|
content: ContentBlock[];
|
|
273
298
|
};
|
|
274
299
|
};
|
|
275
|
-
export type
|
|
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 = {
|
|
276
325
|
id: string;
|
|
277
326
|
timestamp: number;
|
|
278
327
|
domain: "session";
|
|
279
|
-
type: "session.turn.
|
|
328
|
+
type: "session.turn.patch";
|
|
280
329
|
requestId?: string | null;
|
|
281
330
|
spaceId: string;
|
|
282
331
|
sessionId: string;
|
|
283
332
|
payload: {
|
|
284
|
-
|
|
333
|
+
turnId: string | null;
|
|
334
|
+
messageId: string | null;
|
|
285
335
|
anchorUserMessageId: string | null;
|
|
286
|
-
|
|
336
|
+
seq: number;
|
|
337
|
+
baseSeq: number;
|
|
338
|
+
ops: RealtimePatchOperation[];
|
|
287
339
|
};
|
|
288
340
|
};
|
|
289
341
|
export type SessionTurnErrorEvent = {
|
|
@@ -299,6 +351,7 @@ export type SessionTurnErrorEvent = {
|
|
|
299
351
|
error: string;
|
|
300
352
|
};
|
|
301
353
|
};
|
|
354
|
+
export type RealtimeMessageRecord = Pick<MessageRecord, "id" | "sessionId" | "role" | "content" | "text" | "sequence" | "provider" | "model" | "stopReason" | "errorMessage" | "usage" | "meta" | "createdAt">;
|
|
302
355
|
export type SessionMessagePersistedEvent = {
|
|
303
356
|
id: string;
|
|
304
357
|
timestamp: number;
|
|
@@ -308,7 +361,7 @@ export type SessionMessagePersistedEvent = {
|
|
|
308
361
|
spaceId: string;
|
|
309
362
|
sessionId: string;
|
|
310
363
|
payload: {
|
|
311
|
-
message:
|
|
364
|
+
message: RealtimeMessageRecord;
|
|
312
365
|
};
|
|
313
366
|
};
|
|
314
367
|
export type SpaceFsChangedEvent = {
|
|
@@ -321,6 +374,6 @@ export type SpaceFsChangedEvent = {
|
|
|
321
374
|
sessionId?: string | null;
|
|
322
375
|
payload: SpaceFsChangedPayload;
|
|
323
376
|
};
|
|
324
|
-
export type RealtimeServerEvent = SystemReadyEvent | SystemAuthOkEvent | SystemRequestErrorEvent | SystemPongEvent | SystemAckOkEvent | SessionRequestAcceptedEvent | SessionRequestErrorEvent | SessionTurnProgressEvent |
|
|
377
|
+
export type RealtimeServerEvent = SystemReadyEvent | SystemAuthOkEvent | SystemRequestErrorEvent | SystemPongEvent | SystemAckOkEvent | SessionRequestAcceptedEvent | SessionRequestErrorEvent | SessionTurnProgressEvent | SessionTurnPatchEvent | SessionTurnErrorEvent | SessionMessagePersistedEvent | SpaceFsChangedEvent;
|
|
325
378
|
export type WsServerEnvelope = RealtimeEnvelope;
|
|
326
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({
|
|
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
|
+
]);
|