@neta-art/cohub-protocol 1.0.0
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/README.md +30 -0
- package/dist/core/content.d.ts +39 -0
- package/dist/core/content.js +1 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +2 -0
- package/dist/core/usage.d.ts +14 -0
- package/dist/core/usage.js +1 -0
- package/dist/fs/index.d.ts +33 -0
- package/dist/fs/index.js +1 -0
- package/dist/gateway/index.d.ts +114 -0
- package/dist/gateway/index.js +1 -0
- package/dist/gateway.d.ts +136 -0
- package/dist/gateway.js +48 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/model/session.d.ts +98 -0
- package/dist/model/session.js +1 -0
- package/dist/permissions.d.ts +8 -0
- package/dist/permissions.js +1 -0
- package/dist/realtime/index.d.ts +2 -0
- package/dist/realtime/index.js +2 -0
- package/dist/realtime/stream.d.ts +17 -0
- package/dist/realtime/stream.js +1 -0
- package/dist/realtime/websocket.d.ts +315 -0
- package/dist/realtime/websocket.js +85 -0
- package/dist/responses.d.ts +1 -0
- package/dist/responses.js +4 -0
- package/dist/session-ingestion.d.ts +158 -0
- package/dist/session-ingestion.js +2 -0
- package/dist/space-fs.d.ts +33 -0
- package/dist/space-fs.js +1 -0
- package/dist/space-sandbox.d.ts +7 -0
- package/dist/space-sandbox.js +1 -0
- package/dist/task/index.d.ts +14 -0
- package/dist/task/index.js +1 -0
- package/dist/tasks.d.ts +45 -0
- package/dist/tasks.js +5 -0
- package/dist/websocket.d.ts +299 -0
- package/dist/websocket.js +85 -0
- package/package.json +73 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ContentBlock } from "../core/content.js";
|
|
3
|
+
import type { MessageRecord } from "../model/session.js";
|
|
4
|
+
export declare const contentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
5
|
+
type: z.ZodLiteral<"text">;
|
|
6
|
+
text: z.ZodString;
|
|
7
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
8
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
9
|
+
type: z.ZodLiteral<"thinking">;
|
|
10
|
+
thinking: z.ZodString;
|
|
11
|
+
signature: z.ZodOptional<z.ZodString>;
|
|
12
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
13
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
14
|
+
type: z.ZodLiteral<"image">;
|
|
15
|
+
source: z.ZodUnion<readonly [z.ZodObject<{
|
|
16
|
+
type: z.ZodLiteral<"url">;
|
|
17
|
+
url: z.ZodString;
|
|
18
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
19
|
+
type: z.ZodLiteral<"base64">;
|
|
20
|
+
media_type: z.ZodString;
|
|
21
|
+
data: z.ZodString;
|
|
22
|
+
}, z.core.$strip>]>;
|
|
23
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
24
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
25
|
+
type: z.ZodLiteral<"tool_use">;
|
|
26
|
+
id: z.ZodString;
|
|
27
|
+
name: z.ZodString;
|
|
28
|
+
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
29
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
30
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
31
|
+
type: z.ZodLiteral<"tool_result">;
|
|
32
|
+
tool_use_id: z.ZodString;
|
|
33
|
+
content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodUnknown>]>;
|
|
34
|
+
is_error: z.ZodOptional<z.ZodBoolean>;
|
|
35
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
36
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
37
|
+
type: z.ZodLiteral<"system_note">;
|
|
38
|
+
note_type: z.ZodEnum<{
|
|
39
|
+
session_created: "session_created";
|
|
40
|
+
forked: "forked";
|
|
41
|
+
compacted: "compacted";
|
|
42
|
+
info: "info";
|
|
43
|
+
}>;
|
|
44
|
+
text: z.ZodString;
|
|
45
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
46
|
+
}, z.core.$strip>], "type">;
|
|
47
|
+
export declare const wsClientEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
48
|
+
type: z.ZodLiteral<"auth">;
|
|
49
|
+
requestId: z.ZodOptional<z.ZodString>;
|
|
50
|
+
payload: z.ZodObject<{
|
|
51
|
+
token: z.ZodString;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
54
|
+
type: z.ZodLiteral<"session.message.create">;
|
|
55
|
+
requestId: z.ZodOptional<z.ZodString>;
|
|
56
|
+
payload: z.ZodObject<{
|
|
57
|
+
spaceId: z.ZodString;
|
|
58
|
+
sessionId: z.ZodString;
|
|
59
|
+
clientMessageId: z.ZodOptional<z.ZodString>;
|
|
60
|
+
content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
61
|
+
type: z.ZodLiteral<"text">;
|
|
62
|
+
text: z.ZodString;
|
|
63
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
64
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
65
|
+
type: z.ZodLiteral<"thinking">;
|
|
66
|
+
thinking: z.ZodString;
|
|
67
|
+
signature: z.ZodOptional<z.ZodString>;
|
|
68
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
69
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
70
|
+
type: z.ZodLiteral<"image">;
|
|
71
|
+
source: z.ZodUnion<readonly [z.ZodObject<{
|
|
72
|
+
type: z.ZodLiteral<"url">;
|
|
73
|
+
url: z.ZodString;
|
|
74
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
75
|
+
type: z.ZodLiteral<"base64">;
|
|
76
|
+
media_type: z.ZodString;
|
|
77
|
+
data: z.ZodString;
|
|
78
|
+
}, z.core.$strip>]>;
|
|
79
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
80
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
81
|
+
type: z.ZodLiteral<"tool_use">;
|
|
82
|
+
id: z.ZodString;
|
|
83
|
+
name: z.ZodString;
|
|
84
|
+
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
85
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
86
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
87
|
+
type: z.ZodLiteral<"tool_result">;
|
|
88
|
+
tool_use_id: z.ZodString;
|
|
89
|
+
content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodUnknown>]>;
|
|
90
|
+
is_error: z.ZodOptional<z.ZodBoolean>;
|
|
91
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
92
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
93
|
+
type: z.ZodLiteral<"system_note">;
|
|
94
|
+
note_type: z.ZodEnum<{
|
|
95
|
+
session_created: "session_created";
|
|
96
|
+
forked: "forked";
|
|
97
|
+
compacted: "compacted";
|
|
98
|
+
info: "info";
|
|
99
|
+
}>;
|
|
100
|
+
text: z.ZodString;
|
|
101
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
102
|
+
}, z.core.$strip>], "type">>;
|
|
103
|
+
model: z.ZodOptional<z.ZodString>;
|
|
104
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
105
|
+
}, z.core.$strip>;
|
|
106
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
107
|
+
type: z.ZodLiteral<"ping">;
|
|
108
|
+
requestId: z.ZodOptional<z.ZodString>;
|
|
109
|
+
payload: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
110
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
111
|
+
type: z.ZodLiteral<"ack">;
|
|
112
|
+
requestId: z.ZodOptional<z.ZodString>;
|
|
113
|
+
payload: z.ZodOptional<z.ZodObject<{
|
|
114
|
+
eventId: z.ZodOptional<z.ZodString>;
|
|
115
|
+
}, z.core.$strip>>;
|
|
116
|
+
}, z.core.$strip>], "type">;
|
|
117
|
+
export declare const realtimeEnvelopeSchema: z.ZodObject<{
|
|
118
|
+
id: z.ZodString;
|
|
119
|
+
timestamp: z.ZodNumber;
|
|
120
|
+
domain: z.ZodEnum<{
|
|
121
|
+
system: "system";
|
|
122
|
+
session: "session";
|
|
123
|
+
space: "space";
|
|
124
|
+
}>;
|
|
125
|
+
type: z.ZodString;
|
|
126
|
+
requestId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
127
|
+
spaceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
128
|
+
sessionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
129
|
+
payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
130
|
+
}, z.core.$strip>;
|
|
131
|
+
export declare const channelEnvelopeSchema: z.ZodObject<{
|
|
132
|
+
id: z.ZodString;
|
|
133
|
+
timestamp: z.ZodNumber;
|
|
134
|
+
domain: z.ZodEnum<{
|
|
135
|
+
system: "system";
|
|
136
|
+
session: "session";
|
|
137
|
+
space: "space";
|
|
138
|
+
}>;
|
|
139
|
+
type: z.ZodString;
|
|
140
|
+
requestId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
141
|
+
spaceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
142
|
+
sessionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
143
|
+
payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
144
|
+
}, z.core.$strip>;
|
|
145
|
+
export type WsClientEvent = {
|
|
146
|
+
type: "auth";
|
|
147
|
+
requestId?: string;
|
|
148
|
+
payload: {
|
|
149
|
+
token: string;
|
|
150
|
+
};
|
|
151
|
+
} | {
|
|
152
|
+
type: "session.message.create";
|
|
153
|
+
requestId?: string;
|
|
154
|
+
payload: {
|
|
155
|
+
spaceId: string;
|
|
156
|
+
sessionId: string;
|
|
157
|
+
clientMessageId?: string;
|
|
158
|
+
content: ContentBlock[];
|
|
159
|
+
model?: string;
|
|
160
|
+
provider?: string;
|
|
161
|
+
};
|
|
162
|
+
} | {
|
|
163
|
+
type: "ping";
|
|
164
|
+
requestId?: string;
|
|
165
|
+
payload?: Record<string, unknown>;
|
|
166
|
+
} | {
|
|
167
|
+
type: "ack";
|
|
168
|
+
requestId?: string;
|
|
169
|
+
payload?: {
|
|
170
|
+
eventId?: string;
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
export type RealtimeEnvelope = z.output<typeof realtimeEnvelopeSchema>;
|
|
174
|
+
export type ChannelEnvelope = RealtimeEnvelope;
|
|
175
|
+
export type RealtimeEnvelopeBase = RealtimeEnvelope;
|
|
176
|
+
export type RealtimeDomain = RealtimeEnvelopeBase["domain"];
|
|
177
|
+
export type SystemReadyEvent = {
|
|
178
|
+
id: string;
|
|
179
|
+
timestamp: number;
|
|
180
|
+
domain: "system";
|
|
181
|
+
type: "system.ready";
|
|
182
|
+
requestId?: string | null;
|
|
183
|
+
spaceId?: string | null;
|
|
184
|
+
sessionId?: string | null;
|
|
185
|
+
payload: {
|
|
186
|
+
connectionId: string;
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
export type SystemAuthOkEvent = {
|
|
190
|
+
id: string;
|
|
191
|
+
timestamp: number;
|
|
192
|
+
domain: "system";
|
|
193
|
+
type: "system.auth.ok";
|
|
194
|
+
requestId?: string | null;
|
|
195
|
+
spaceId?: string | null;
|
|
196
|
+
sessionId?: string | null;
|
|
197
|
+
payload: {
|
|
198
|
+
connectionId: string;
|
|
199
|
+
user: Record<string, unknown>;
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
export type SystemRequestErrorEvent = {
|
|
203
|
+
id: string;
|
|
204
|
+
timestamp: number;
|
|
205
|
+
domain: "system";
|
|
206
|
+
type: "system.request.error";
|
|
207
|
+
requestId?: string | null;
|
|
208
|
+
spaceId?: string | null;
|
|
209
|
+
sessionId?: string | null;
|
|
210
|
+
payload: {
|
|
211
|
+
code: string;
|
|
212
|
+
message: string;
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
export type SystemPongEvent = {
|
|
216
|
+
id: string;
|
|
217
|
+
timestamp: number;
|
|
218
|
+
domain: "system";
|
|
219
|
+
type: "system.pong";
|
|
220
|
+
requestId?: string | null;
|
|
221
|
+
spaceId?: string | null;
|
|
222
|
+
sessionId?: string | null;
|
|
223
|
+
payload: Record<string, never>;
|
|
224
|
+
};
|
|
225
|
+
export type SystemAckOkEvent = {
|
|
226
|
+
id: string;
|
|
227
|
+
timestamp: number;
|
|
228
|
+
domain: "system";
|
|
229
|
+
type: "system.ack.ok";
|
|
230
|
+
requestId?: string | null;
|
|
231
|
+
spaceId?: string | null;
|
|
232
|
+
sessionId?: string | null;
|
|
233
|
+
payload: Record<string, never>;
|
|
234
|
+
};
|
|
235
|
+
export type SessionRequestAcceptedEvent = {
|
|
236
|
+
id: string;
|
|
237
|
+
timestamp: number;
|
|
238
|
+
domain: "session";
|
|
239
|
+
type: "session.request.accepted";
|
|
240
|
+
requestId?: string | null;
|
|
241
|
+
spaceId: string;
|
|
242
|
+
sessionId: string;
|
|
243
|
+
payload: {
|
|
244
|
+
clientMessageId?: string | null;
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
export type SessionRequestErrorEvent = {
|
|
248
|
+
id: string;
|
|
249
|
+
timestamp: number;
|
|
250
|
+
domain: "session";
|
|
251
|
+
type: "session.request.error";
|
|
252
|
+
requestId?: string | null;
|
|
253
|
+
spaceId?: string | null;
|
|
254
|
+
sessionId?: string | null;
|
|
255
|
+
payload: {
|
|
256
|
+
code: string;
|
|
257
|
+
message: string;
|
|
258
|
+
clientMessageId?: string | null;
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
export type SessionTurnProgressEvent = {
|
|
262
|
+
id: string;
|
|
263
|
+
timestamp: number;
|
|
264
|
+
domain: "session";
|
|
265
|
+
type: "session.turn.progress";
|
|
266
|
+
requestId?: string | null;
|
|
267
|
+
spaceId: string;
|
|
268
|
+
sessionId: string;
|
|
269
|
+
payload: {
|
|
270
|
+
anchorUserMessageId: string | null;
|
|
271
|
+
content: ContentBlock[];
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
export type SessionTurnFinalEvent = {
|
|
275
|
+
id: string;
|
|
276
|
+
timestamp: number;
|
|
277
|
+
domain: "session";
|
|
278
|
+
type: "session.turn.final";
|
|
279
|
+
requestId?: string | null;
|
|
280
|
+
spaceId: string;
|
|
281
|
+
sessionId: string;
|
|
282
|
+
payload: {
|
|
283
|
+
sessionMessageId: string | null;
|
|
284
|
+
anchorUserMessageId: string | null;
|
|
285
|
+
content: ContentBlock[];
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
export type SessionTurnErrorEvent = {
|
|
289
|
+
id: string;
|
|
290
|
+
timestamp: number;
|
|
291
|
+
domain: "session";
|
|
292
|
+
type: "session.turn.error";
|
|
293
|
+
requestId?: string | null;
|
|
294
|
+
spaceId: string;
|
|
295
|
+
sessionId: string;
|
|
296
|
+
payload: {
|
|
297
|
+
anchorUserMessageId: string | null;
|
|
298
|
+
error: string;
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
export type SessionMessagePersistedEvent = {
|
|
302
|
+
id: string;
|
|
303
|
+
timestamp: number;
|
|
304
|
+
domain: "session";
|
|
305
|
+
type: "session.message.persisted";
|
|
306
|
+
requestId?: string | null;
|
|
307
|
+
spaceId: string;
|
|
308
|
+
sessionId: string;
|
|
309
|
+
payload: {
|
|
310
|
+
message: MessageRecord;
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
export type RealtimeServerEvent = SystemReadyEvent | SystemAuthOkEvent | SystemRequestErrorEvent | SystemPongEvent | SystemAckOkEvent | SessionRequestAcceptedEvent | SessionRequestErrorEvent | SessionTurnProgressEvent | SessionTurnFinalEvent | SessionTurnErrorEvent | SessionMessagePersistedEvent;
|
|
314
|
+
export type WsServerEnvelope = RealtimeEnvelope;
|
|
315
|
+
export type ChannelServerEnvelope = ChannelEnvelope;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const contentBlockMetaSchema = z.record(z.string(), z.unknown());
|
|
3
|
+
export const contentBlockSchema = z.discriminatedUnion("type", [
|
|
4
|
+
z.object({
|
|
5
|
+
type: z.literal("text"),
|
|
6
|
+
text: z.string(),
|
|
7
|
+
_meta: contentBlockMetaSchema.optional(),
|
|
8
|
+
}),
|
|
9
|
+
z.object({
|
|
10
|
+
type: z.literal("thinking"),
|
|
11
|
+
thinking: z.string(),
|
|
12
|
+
signature: z.string().optional(),
|
|
13
|
+
_meta: contentBlockMetaSchema.optional(),
|
|
14
|
+
}),
|
|
15
|
+
z.object({
|
|
16
|
+
type: z.literal("image"),
|
|
17
|
+
source: z.union([
|
|
18
|
+
z.object({ type: z.literal("url"), url: z.string().url() }),
|
|
19
|
+
z.object({ type: z.literal("base64"), media_type: z.string(), data: z.string() }),
|
|
20
|
+
]),
|
|
21
|
+
_meta: contentBlockMetaSchema.optional(),
|
|
22
|
+
}),
|
|
23
|
+
z.object({
|
|
24
|
+
type: z.literal("tool_use"),
|
|
25
|
+
id: z.string(),
|
|
26
|
+
name: z.string(),
|
|
27
|
+
input: z.record(z.string(), z.unknown()),
|
|
28
|
+
_meta: contentBlockMetaSchema.optional(),
|
|
29
|
+
}),
|
|
30
|
+
z.object({
|
|
31
|
+
type: z.literal("tool_result"),
|
|
32
|
+
tool_use_id: z.string(),
|
|
33
|
+
content: z.union([z.string(), z.array(z.unknown())]),
|
|
34
|
+
is_error: z.boolean().optional(),
|
|
35
|
+
_meta: contentBlockMetaSchema.optional(),
|
|
36
|
+
}),
|
|
37
|
+
z.object({
|
|
38
|
+
type: z.literal("system_note"),
|
|
39
|
+
note_type: z.enum(["session_created", "forked", "compacted", "info"]),
|
|
40
|
+
text: z.string(),
|
|
41
|
+
_meta: contentBlockMetaSchema.optional(),
|
|
42
|
+
}),
|
|
43
|
+
]);
|
|
44
|
+
export const wsClientEventSchema = z.discriminatedUnion("type", [
|
|
45
|
+
z.object({
|
|
46
|
+
type: z.literal("auth"),
|
|
47
|
+
requestId: z.string().optional(),
|
|
48
|
+
payload: z.object({ token: z.string().min(1) }),
|
|
49
|
+
}),
|
|
50
|
+
z.object({
|
|
51
|
+
type: z.literal("session.message.create"),
|
|
52
|
+
requestId: z.string().optional(),
|
|
53
|
+
payload: z.object({
|
|
54
|
+
spaceId: z.string().uuid(),
|
|
55
|
+
sessionId: z.string().uuid(),
|
|
56
|
+
clientMessageId: z.string().optional(),
|
|
57
|
+
content: z.array(contentBlockSchema).min(1),
|
|
58
|
+
model: z.string().optional(),
|
|
59
|
+
provider: z.string().optional(),
|
|
60
|
+
}),
|
|
61
|
+
}),
|
|
62
|
+
z.object({
|
|
63
|
+
type: z.literal("ping"),
|
|
64
|
+
requestId: z.string().optional(),
|
|
65
|
+
payload: z.record(z.string(), z.unknown()).optional(),
|
|
66
|
+
}),
|
|
67
|
+
z.object({
|
|
68
|
+
type: z.literal("ack"),
|
|
69
|
+
requestId: z.string().optional(),
|
|
70
|
+
payload: z.object({
|
|
71
|
+
eventId: z.string().optional(),
|
|
72
|
+
}).optional(),
|
|
73
|
+
}),
|
|
74
|
+
]);
|
|
75
|
+
export const realtimeEnvelopeSchema = z.object({
|
|
76
|
+
id: z.string(),
|
|
77
|
+
timestamp: z.number(),
|
|
78
|
+
domain: z.enum(["system", "session", "space"]),
|
|
79
|
+
type: z.string(),
|
|
80
|
+
requestId: z.string().nullable().optional(),
|
|
81
|
+
spaceId: z.string().nullable().optional(),
|
|
82
|
+
sessionId: z.string().nullable().optional(),
|
|
83
|
+
payload: z.record(z.string(), z.unknown()),
|
|
84
|
+
});
|
|
85
|
+
export const channelEnvelopeSchema = realtimeEnvelopeSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
export type ContentBlockMeta = Record<string, unknown>;
|
|
2
|
+
export type ContentBlock = {
|
|
3
|
+
type: "text";
|
|
4
|
+
text: string;
|
|
5
|
+
_meta?: ContentBlockMeta;
|
|
6
|
+
} | {
|
|
7
|
+
type: "thinking";
|
|
8
|
+
thinking: string;
|
|
9
|
+
signature?: string;
|
|
10
|
+
_meta?: ContentBlockMeta;
|
|
11
|
+
} | {
|
|
12
|
+
type: "image";
|
|
13
|
+
source: {
|
|
14
|
+
type: "url";
|
|
15
|
+
url: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: "base64";
|
|
18
|
+
media_type: string;
|
|
19
|
+
data: string;
|
|
20
|
+
};
|
|
21
|
+
_meta?: ContentBlockMeta;
|
|
22
|
+
} | {
|
|
23
|
+
type: "tool_use";
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
input: Record<string, unknown>;
|
|
27
|
+
_meta?: ContentBlockMeta;
|
|
28
|
+
} | {
|
|
29
|
+
type: "tool_result";
|
|
30
|
+
tool_use_id: string;
|
|
31
|
+
content: string | ContentBlock[];
|
|
32
|
+
is_error?: boolean;
|
|
33
|
+
_meta?: ContentBlockMeta;
|
|
34
|
+
} | {
|
|
35
|
+
type: "system_note";
|
|
36
|
+
note_type: "session_created" | "forked" | "compacted" | "info";
|
|
37
|
+
text: string;
|
|
38
|
+
_meta?: ContentBlockMeta;
|
|
39
|
+
};
|
|
40
|
+
export type SessionPromptInput = {
|
|
41
|
+
spaceId: string;
|
|
42
|
+
sessionId: string;
|
|
43
|
+
userMessageId?: string | null;
|
|
44
|
+
message: {
|
|
45
|
+
content: ContentBlock[];
|
|
46
|
+
};
|
|
47
|
+
meta?: {
|
|
48
|
+
source?: string;
|
|
49
|
+
intent?: "auto" | "continue" | "new_session" | "fork";
|
|
50
|
+
model?: string;
|
|
51
|
+
provider?: string;
|
|
52
|
+
} | null;
|
|
53
|
+
};
|
|
54
|
+
export type RegisterSessionInput = {
|
|
55
|
+
spaceId: string;
|
|
56
|
+
sessionId: string;
|
|
57
|
+
title?: string | null;
|
|
58
|
+
source?: string | null;
|
|
59
|
+
externalSessionId?: string | null;
|
|
60
|
+
meta?: Record<string, unknown> | null;
|
|
61
|
+
};
|
|
62
|
+
export type PersistMessageInput = {
|
|
63
|
+
spaceId: string;
|
|
64
|
+
sessionId: string;
|
|
65
|
+
previousMessageId?: string | null;
|
|
66
|
+
anchorUserMessageId?: string | null;
|
|
67
|
+
idempotencyKey: string;
|
|
68
|
+
message: {
|
|
69
|
+
role?: "user" | "assistant" | "system";
|
|
70
|
+
externalMessageId?: string | null;
|
|
71
|
+
protocolMessageId?: string | null;
|
|
72
|
+
content: ContentBlock[];
|
|
73
|
+
text?: string | null;
|
|
74
|
+
provider?: string | null;
|
|
75
|
+
model?: string | null;
|
|
76
|
+
stopReason?: string | null;
|
|
77
|
+
errorMessage?: string | null;
|
|
78
|
+
meta?: Record<string, unknown> | null;
|
|
79
|
+
usage?: {
|
|
80
|
+
input?: number;
|
|
81
|
+
output?: number;
|
|
82
|
+
costTotal?: number;
|
|
83
|
+
} | null;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
export type UpdateSessionInfoInput = {
|
|
87
|
+
spaceId: string;
|
|
88
|
+
sessionId: string;
|
|
89
|
+
title?: string | null;
|
|
90
|
+
updatedAt?: string | null;
|
|
91
|
+
meta?: Record<string, unknown> | null;
|
|
92
|
+
};
|
|
93
|
+
export type SessionStreamEvent = {
|
|
94
|
+
type: "stream_update";
|
|
95
|
+
spaceId: string;
|
|
96
|
+
sessionId: string;
|
|
97
|
+
/** `content` always contains delta blocks to be merged into the current streaming state. */
|
|
98
|
+
content: ContentBlock[];
|
|
99
|
+
sourceMessageId: string | null;
|
|
100
|
+
timestamp: number;
|
|
101
|
+
turnEnd?: boolean;
|
|
102
|
+
anchorUserMessageId?: string | null;
|
|
103
|
+
};
|
|
104
|
+
export type SessionStreamError = {
|
|
105
|
+
type: "error";
|
|
106
|
+
spaceId: string;
|
|
107
|
+
sessionId: string | null;
|
|
108
|
+
error: string;
|
|
109
|
+
};
|
|
110
|
+
export type SessionBindingRecord = {
|
|
111
|
+
id: string;
|
|
112
|
+
spaceId: string;
|
|
113
|
+
spaceSessionId: string;
|
|
114
|
+
spaceChannelId: string;
|
|
115
|
+
provider: string;
|
|
116
|
+
bindingKey: string;
|
|
117
|
+
externalChatId: string;
|
|
118
|
+
status: string | null;
|
|
119
|
+
meta: Record<string, unknown> | null;
|
|
120
|
+
createdAt: string;
|
|
121
|
+
updatedAt: string;
|
|
122
|
+
lastMessageAt: string | null;
|
|
123
|
+
};
|
|
124
|
+
export type SessionRecord = {
|
|
125
|
+
id: string;
|
|
126
|
+
spaceId: string;
|
|
127
|
+
title: string | null;
|
|
128
|
+
source: string | null;
|
|
129
|
+
status: string | null;
|
|
130
|
+
externalSessionId: string | null;
|
|
131
|
+
meta: Record<string, unknown> | null;
|
|
132
|
+
parentSessionId: string | null;
|
|
133
|
+
forkedFromMessageId: string | null;
|
|
134
|
+
lineageRootSessionId: string | null;
|
|
135
|
+
forkDepth: number;
|
|
136
|
+
latestMessageText: string | null;
|
|
137
|
+
lastMessageAt: string | null;
|
|
138
|
+
lastMessageId: string | null;
|
|
139
|
+
createdAt: string;
|
|
140
|
+
updatedAt: string;
|
|
141
|
+
};
|
|
142
|
+
export type MessageRecord = {
|
|
143
|
+
id: string;
|
|
144
|
+
sessionId: string;
|
|
145
|
+
role: "user" | "assistant" | "system";
|
|
146
|
+
content: ContentBlock[];
|
|
147
|
+
text: string | null;
|
|
148
|
+
sequence: number;
|
|
149
|
+
provider: string | null;
|
|
150
|
+
model: string | null;
|
|
151
|
+
stopReason: string | null;
|
|
152
|
+
errorMessage: string | null;
|
|
153
|
+
usageInput: number | null;
|
|
154
|
+
usageOutput: number | null;
|
|
155
|
+
costTotal: string | null;
|
|
156
|
+
meta: Record<string, unknown> | null;
|
|
157
|
+
createdAt: string;
|
|
158
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type SpaceFsEntry = {
|
|
2
|
+
name: string;
|
|
3
|
+
path: string;
|
|
4
|
+
type: "file" | "dir" | "symlink";
|
|
5
|
+
size: number;
|
|
6
|
+
mimeType: string | null;
|
|
7
|
+
mtimeMs: number;
|
|
8
|
+
};
|
|
9
|
+
export type SpaceFsTreeResponse = {
|
|
10
|
+
path: string;
|
|
11
|
+
entries: SpaceFsEntry[];
|
|
12
|
+
};
|
|
13
|
+
export type SpaceFsFileKind = "text" | "binary";
|
|
14
|
+
export type SpaceFsEncoding = "utf-8" | "base64";
|
|
15
|
+
export type SpaceFsFileResponse = {
|
|
16
|
+
path: string;
|
|
17
|
+
name: string;
|
|
18
|
+
size: number;
|
|
19
|
+
mimeType: string | null;
|
|
20
|
+
mtimeMs: number;
|
|
21
|
+
kind: SpaceFsFileKind;
|
|
22
|
+
encoding: SpaceFsEncoding;
|
|
23
|
+
content: string;
|
|
24
|
+
};
|
|
25
|
+
export type SpaceFsWriteFileInput = {
|
|
26
|
+
path: string;
|
|
27
|
+
content: string;
|
|
28
|
+
encoding: SpaceFsEncoding;
|
|
29
|
+
};
|
|
30
|
+
export type SpaceFsMoveInput = {
|
|
31
|
+
fromPath: string;
|
|
32
|
+
toPath: string;
|
|
33
|
+
};
|
package/dist/space-fs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type TaskType = string;
|
|
2
|
+
export interface TaskPayload {
|
|
3
|
+
type: TaskType;
|
|
4
|
+
spaceId?: string;
|
|
5
|
+
sessionId?: string;
|
|
6
|
+
userId?: string;
|
|
7
|
+
cronJobId?: string;
|
|
8
|
+
data?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export type TaskRunStatus = "pending" | "running" | "completed" | "failed";
|
|
11
|
+
export interface TaskScheduleConfig {
|
|
12
|
+
pattern: string;
|
|
13
|
+
timezone?: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/tasks.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task system protocol definitions.
|
|
3
|
+
* Shared between API (scheduler) and Worker (executor).
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Task type identifier.
|
|
7
|
+
* Open-ended — add new types as needed.
|
|
8
|
+
*/
|
|
9
|
+
export type TaskType = string;
|
|
10
|
+
/**
|
|
11
|
+
* Universal task payload carried by every BullMQ job.
|
|
12
|
+
* Fields like spaceId / sessionId are optional
|
|
13
|
+
* so tasks can be scoped or global.
|
|
14
|
+
*/
|
|
15
|
+
export interface TaskPayload {
|
|
16
|
+
type: TaskType;
|
|
17
|
+
/** Optional: which space this task relates to */
|
|
18
|
+
spaceId?: string;
|
|
19
|
+
/** Optional: which session this task relates to */
|
|
20
|
+
sessionId?: string;
|
|
21
|
+
/** Optional: the user who owns / triggered this task */
|
|
22
|
+
userId?: string;
|
|
23
|
+
/** Optional: cron job that spawned this execution (set by API on enqueue) */
|
|
24
|
+
cronJobId?: string;
|
|
25
|
+
/** Task-specific parameters */
|
|
26
|
+
data?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Task run status in the database.
|
|
30
|
+
*
|
|
31
|
+
* Flow:
|
|
32
|
+
* pending (API-enqueued only)
|
|
33
|
+
* → running (worker picked up)
|
|
34
|
+
* → completed | failed
|
|
35
|
+
*/
|
|
36
|
+
export type TaskRunStatus = "pending" | "running" | "completed" | "failed";
|
|
37
|
+
/**
|
|
38
|
+
* Cron schedule configuration passed from the client.
|
|
39
|
+
*/
|
|
40
|
+
export interface TaskScheduleConfig {
|
|
41
|
+
/** Cron expression, e.g. "0 10 * * *" */
|
|
42
|
+
pattern: string;
|
|
43
|
+
/** IANA timezone, defaults to "Asia/Shanghai" */
|
|
44
|
+
timezone?: string;
|
|
45
|
+
}
|