@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.
@@ -20,12 +20,6 @@ export type SessionTurnIntermediateSummary = {
20
20
  lastMessageText?: string | null;
21
21
  hasError?: boolean;
22
22
  };
23
- export type StoredIntermediateMessageToolCallSummary = {
24
- id: string;
25
- name: string;
26
- status: "running" | "done" | "failed";
27
- input: Record<string, unknown>;
28
- };
29
23
  export type StoredIntermediateMessage = {
30
24
  id: string;
31
25
  sessionId: string;
@@ -37,7 +31,6 @@ export type StoredIntermediateMessage = {
37
31
  stopReason: string | null;
38
32
  errorMessage: string | null;
39
33
  usage: Usage | null;
40
- toolCalls: StoredIntermediateMessageToolCallSummary[];
41
34
  toolCallsObjectKey: string | null;
42
35
  meta: Record<string, unknown> | null;
43
36
  createdAt: string;
@@ -46,11 +39,12 @@ export type StoredToolCall = {
46
39
  id: string;
47
40
  name: string;
48
41
  input: Record<string, unknown>;
42
+ meta: Record<string, unknown> | null;
49
43
  result: {
50
44
  content: string | ContentBlock[] | null;
51
45
  isError: boolean;
46
+ meta: Record<string, unknown> | null;
52
47
  } | null;
53
- meta: Record<string, unknown> | null;
54
48
  };
55
49
  export type MessageToolCallsFile = {
56
50
  version: 1;
@@ -68,6 +62,22 @@ export type TurnIntermediateMessagesFile = {
68
62
  summary: SessionTurnIntermediateSummary;
69
63
  messages: StoredIntermediateMessage[];
70
64
  };
65
+ export type SessionTurnIndexItem = {
66
+ id: string;
67
+ sessionId: string;
68
+ sequence: number;
69
+ status: SessionTurnStatus;
70
+ startedAt: string | null;
71
+ completedAt: string | null;
72
+ createdAt: string;
73
+ updatedAt: string;
74
+ userPreview: string | null;
75
+ assistantPreview: string | null;
76
+ provider: string | null;
77
+ model: string | null;
78
+ usage: Usage | null;
79
+ errorMessage: string | null;
80
+ };
71
81
  export type SessionTurnRecord = {
72
82
  id: string;
73
83
  sessionId: string;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Permission level for space / session resources.
3
+ *
4
+ * - `read` — anyone can read (including anonymous users)
5
+ * - `write` — anyone can read and write
6
+ * - `private` — explicitly deny access (no fallback to parent)
7
+ */
8
+ export type ResourcePermissionLevel = "read" | "write" | "private";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ export declare const SANDBOX_PUBLIC_PORTS: readonly [3000, 5173];
2
+ export type SandboxPublicPort = (typeof SANDBOX_PUBLIC_PORTS)[number];
3
+ export type SpacePortStatus = "listening" | "closed";
4
+ export type SpacePortChange = {
5
+ port: SandboxPublicPort | number;
6
+ protocol: "tcp";
7
+ status: SpacePortStatus;
8
+ observedAt: number;
9
+ };
10
+ export type SpacePortsChangedPayload = {
11
+ source: "sandbox-port-watch" | "sandbox-port-watch-started";
12
+ seq?: number;
13
+ resync?: boolean;
14
+ ports: SpacePortChange[];
15
+ };
16
+ export type SpacePublicEndpoint = {
17
+ url: string;
18
+ status?: SpacePortStatus | "unknown";
19
+ observedAt?: number;
20
+ };
21
+ export type SpacePublicEndpoints = Record<string, SpacePublicEndpoint>;
@@ -0,0 +1 @@
1
+ export const SANDBOX_PUBLIC_PORTS = [3000, 5173];
@@ -8,6 +8,8 @@ export type SessionStreamEvent = {
8
8
  baseSeq: number;
9
9
  content: ContentBlock[];
10
10
  snapshotContent?: ContentBlock[];
11
+ messageId?: string | null;
12
+ messageOrdinal?: number | null;
11
13
  sourceMessageId: string | null;
12
14
  timestamp: number;
13
15
  turnEnd?: boolean;
@@ -1,7 +1,8 @@
1
1
  import { z } from "zod";
2
2
  import type { ContentBlock } from "../core/content.js";
3
- import type { MessageRecord } from "../model/session.js";
3
+ import type { MessageRecord, SessionTurnRecord } from "../model/session.js";
4
4
  import type { SpaceFsChangedPayload } from "../fs/index.js";
5
+ import type { SpacePortsChangedPayload } from "../ports/index.js";
5
6
  export declare const WS_COMPACT_STREAM_CAPABILITY = "session.compact_stream.v1";
6
7
  export declare const contentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
7
8
  type: z.ZodLiteral<"text">;
@@ -293,6 +294,8 @@ export type SessionTurnProgressEvent = {
293
294
  spaceId: string;
294
295
  sessionId: string;
295
296
  payload: {
297
+ messageId: string | null;
298
+ messageOrdinal?: number | null;
296
299
  anchorUserMessageId: string | null;
297
300
  content: ContentBlock[];
298
301
  };
@@ -332,12 +335,36 @@ export type SessionTurnPatchEvent = {
332
335
  payload: {
333
336
  turnId: string | null;
334
337
  messageId: string | null;
338
+ messageOrdinal?: number | null;
335
339
  anchorUserMessageId: string | null;
336
340
  seq: number;
337
341
  baseSeq: number;
338
342
  ops: RealtimePatchOperation[];
339
343
  };
340
344
  };
345
+ export type SessionTurnSnapshotMessage = {
346
+ messageId: string | null;
347
+ messageOrdinal: number | null;
348
+ content: ContentBlock[];
349
+ };
350
+ export type SessionTurnSnapshotEvent = {
351
+ id: string;
352
+ timestamp: number;
353
+ domain: "session";
354
+ type: "session.turn.snapshot";
355
+ requestId?: string | null;
356
+ spaceId: string;
357
+ sessionId: string;
358
+ payload: {
359
+ turnId: string | null;
360
+ anchorUserMessageId: string | null;
361
+ seq: number;
362
+ current: SessionTurnSnapshotMessage & {
363
+ appendPath: string | null;
364
+ };
365
+ intermediateMessages: SessionTurnSnapshotMessage[];
366
+ };
367
+ };
341
368
  export type SessionTurnErrorEvent = {
342
369
  id: string;
343
370
  timestamp: number;
@@ -351,6 +378,31 @@ export type SessionTurnErrorEvent = {
351
378
  error: string;
352
379
  };
353
380
  };
381
+ export type RealtimeTurnRecord = Partial<Pick<SessionTurnRecord, "id" | "sessionId" | "sequence" | "status" | "intent" | "userUuid" | "userText" | "assistantText" | "provider" | "model" | "stopReason" | "errorMessage" | "usage" | "summary" | "intermediateIndex" | "intermediateSummary" | "startedAt" | "completedAt" | "createdAt" | "updatedAt">>;
382
+ export type SessionTurnUpdatedEvent = {
383
+ id: string;
384
+ timestamp: number;
385
+ domain: "session";
386
+ type: "session.turn.updated";
387
+ requestId?: string | null;
388
+ spaceId: string;
389
+ sessionId: string;
390
+ payload: {
391
+ turn: RealtimeTurnRecord;
392
+ };
393
+ };
394
+ export type SessionTurnFinalizedEvent = {
395
+ id: string;
396
+ timestamp: number;
397
+ domain: "session";
398
+ type: "session.turn.finalized";
399
+ requestId?: string | null;
400
+ spaceId: string;
401
+ sessionId: string;
402
+ payload: {
403
+ turn: RealtimeTurnRecord;
404
+ };
405
+ };
354
406
  export type RealtimeMessageRecord = Pick<MessageRecord, "id" | "sessionId" | "role" | "content" | "text" | "sequence" | "provider" | "model" | "stopReason" | "errorMessage" | "usage" | "meta" | "createdAt">;
355
407
  export type SessionMessagePersistedEvent = {
356
408
  id: string;
@@ -374,6 +426,16 @@ export type SpaceFsChangedEvent = {
374
426
  sessionId?: string | null;
375
427
  payload: SpaceFsChangedPayload;
376
428
  };
377
- export type RealtimeServerEvent = SystemReadyEvent | SystemAuthOkEvent | SystemRequestErrorEvent | SystemPongEvent | SystemAckOkEvent | SessionRequestAcceptedEvent | SessionRequestErrorEvent | SessionTurnProgressEvent | SessionTurnPatchEvent | SessionTurnErrorEvent | SessionMessagePersistedEvent | SpaceFsChangedEvent;
429
+ export type SpacePortsChangedEvent = {
430
+ id: string;
431
+ timestamp: number;
432
+ domain: "space";
433
+ type: "space.ports.changed";
434
+ requestId?: string | null;
435
+ spaceId: string;
436
+ sessionId?: string | null;
437
+ payload: SpacePortsChangedPayload;
438
+ };
439
+ export type RealtimeServerEvent = SystemReadyEvent | SystemAuthOkEvent | SystemRequestErrorEvent | SystemPongEvent | SystemAckOkEvent | SessionRequestAcceptedEvent | SessionRequestErrorEvent | SessionTurnProgressEvent | SessionTurnPatchEvent | SessionTurnSnapshotEvent | SessionTurnErrorEvent | SessionTurnUpdatedEvent | SessionTurnFinalizedEvent | SessionMessagePersistedEvent | SpaceFsChangedEvent | SpacePortsChangedEvent;
378
440
  export type WsServerEnvelope = RealtimeEnvelope;
379
441
  export type ChannelServerEnvelope = ChannelEnvelope;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export {};
2
+ // Responses API has been removed.
3
+ // Sessions now work via simple POST /sessions/:id/messages.
4
+ // Frontend live updates are delivered via Gateway WebSocket.
@@ -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,2 @@
1
+ // ─── Content Block — Anthropic-style, single source of truth ───
2
+ export {};
@@ -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
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Space sandbox lifecycle status.
3
+ *
4
+ * Internal infrastructure state only.
5
+ * Not intended as a primary user-facing concept.
6
+ */
7
+ export type SpaceSandboxStatus = "pending" | "provisioning" | "ready" | "stopped" | "error" | "terminated";
@@ -0,0 +1 @@
1
+ export {};
@@ -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
+ }
package/dist/tasks.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Task system protocol definitions.
3
+ * Shared between API (scheduler) and Worker (executor).
4
+ */
5
+ export {};