@neta-art/cohub 1.9.0 → 1.10.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 +6 -105
- package/dist/chunks/environment.js +33 -0
- package/dist/chunks/http.d.ts +1615 -0
- package/dist/chunks/http.js +1919 -0
- package/dist/chunks/websocket.d.ts +266 -0
- package/dist/chunks/websocket.js +655 -0
- package/dist/http.d.ts +3 -32
- package/dist/http.js +2 -48
- package/dist/index.d.ts +35 -14
- package/dist/index.js +105 -8
- package/dist/websocket.d.ts +2 -141
- package/dist/websocket.js +2 -628
- package/package.json +7 -7
- package/dist/apis/channels.d.ts +0 -13
- package/dist/apis/channels.js +0 -24
- package/dist/apis/cron-jobs.d.ts +0 -18
- package/dist/apis/cron-jobs.js +0 -25
- package/dist/apis/explore.d.ts +0 -9
- package/dist/apis/explore.js +0 -9
- package/dist/apis/generations.d.ts +0 -7
- package/dist/apis/generations.js +0 -13
- package/dist/apis/invitations.d.ts +0 -20
- package/dist/apis/invitations.js +0 -36
- package/dist/apis/models.d.ts +0 -10
- package/dist/apis/models.js +0 -13
- package/dist/apis/prompts.d.ts +0 -9
- package/dist/apis/prompts.js +0 -16
- package/dist/apis/search.d.ts +0 -10
- package/dist/apis/search.js +0 -14
- package/dist/apis/session-access.d.ts +0 -13
- package/dist/apis/session-access.js +0 -19
- package/dist/apis/spaces.d.ts +0 -371
- package/dist/apis/spaces.js +0 -766
- package/dist/apis/tasks.d.ts +0 -13
- package/dist/apis/tasks.js +0 -18
- package/dist/apis/user.d.ts +0 -27
- package/dist/apis/user.js +0 -71
- package/dist/client.d.ts +0 -33
- package/dist/client.js +0 -103
- package/dist/environment.d.ts +0 -22
- package/dist/environment.js +0 -37
- package/dist/realtime.d.ts +0 -2
- package/dist/realtime.js +0 -8
- package/dist/session-generation-stream.d.ts +0 -114
- package/dist/session-generation-stream.js +0 -514
- package/dist/session-patch-reducer.d.ts +0 -61
- package/dist/session-patch-reducer.js +0 -432
- package/dist/transport.d.ts +0 -40
- package/dist/transport.js +0 -78
- package/dist/types.d.ts +0 -535
- package/dist/types.js +0 -1
package/dist/apis/tasks.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { HttpTransport } from "../transport.js";
|
|
2
|
-
import type { TaskRunDetailResponse, TaskRunRecord } from "../types.js";
|
|
3
|
-
export declare class TasksApi {
|
|
4
|
-
private readonly transport;
|
|
5
|
-
constructor(transport: HttpTransport);
|
|
6
|
-
get(taskRunId: string): Promise<TaskRunDetailResponse>;
|
|
7
|
-
list(filters?: {
|
|
8
|
-
cronJobId?: string;
|
|
9
|
-
spaceId?: string;
|
|
10
|
-
}): Promise<{
|
|
11
|
-
runs: TaskRunRecord[];
|
|
12
|
-
}>;
|
|
13
|
-
}
|
package/dist/apis/tasks.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export class TasksApi {
|
|
2
|
-
transport;
|
|
3
|
-
constructor(transport) {
|
|
4
|
-
this.transport = transport;
|
|
5
|
-
}
|
|
6
|
-
get(taskRunId) {
|
|
7
|
-
return this.transport.request(`/api/tasks/${taskRunId}`);
|
|
8
|
-
}
|
|
9
|
-
list(filters) {
|
|
10
|
-
const params = new URLSearchParams();
|
|
11
|
-
if (filters?.cronJobId)
|
|
12
|
-
params.set("cronJobId", filters.cronJobId);
|
|
13
|
-
if (filters?.spaceId)
|
|
14
|
-
params.set("spaceId", filters.spaceId);
|
|
15
|
-
const query = params.toString();
|
|
16
|
-
return this.transport.request(`/api/tasks${query ? `?${query}` : ""}`);
|
|
17
|
-
}
|
|
18
|
-
}
|
package/dist/apis/user.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type HttpTransport, type Fetch } from "../transport.js";
|
|
2
|
-
import type { MeResponse, UserProfile, UserRulesResponse, UserSshKey } from "../types.js";
|
|
3
|
-
export declare class UserApi {
|
|
4
|
-
private readonly transport;
|
|
5
|
-
private readonly transportBaseUrl;
|
|
6
|
-
private readonly setStoredAuthToken?;
|
|
7
|
-
private readonly clearStoredAuthToken?;
|
|
8
|
-
constructor(transport: HttpTransport, transportBaseUrl: string, setStoredAuthToken?: ((token: string) => void) | undefined, clearStoredAuthToken?: (() => void) | undefined);
|
|
9
|
-
getMe(customFetch?: Fetch): Promise<MeResponse>;
|
|
10
|
-
updateProfile(input: {
|
|
11
|
-
displayName?: string;
|
|
12
|
-
avatarUrl?: string | null;
|
|
13
|
-
}): Promise<{
|
|
14
|
-
profile: UserProfile;
|
|
15
|
-
}>;
|
|
16
|
-
getRules(customFetch?: Fetch): Promise<UserRulesResponse>;
|
|
17
|
-
setAuthToken(token: string): Promise<any>;
|
|
18
|
-
clearAuthToken(): Promise<null>;
|
|
19
|
-
getSshKeys(customFetch?: Fetch): Promise<UserSshKey[]>;
|
|
20
|
-
createSshKey(data: {
|
|
21
|
-
key: string;
|
|
22
|
-
title: string;
|
|
23
|
-
}): Promise<UserSshKey>;
|
|
24
|
-
deleteSshKey(id: string): Promise<{
|
|
25
|
-
ok: true;
|
|
26
|
-
}>;
|
|
27
|
-
}
|
package/dist/apis/user.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { HttpError } from "../transport.js";
|
|
2
|
-
export class UserApi {
|
|
3
|
-
transport;
|
|
4
|
-
transportBaseUrl;
|
|
5
|
-
setStoredAuthToken;
|
|
6
|
-
clearStoredAuthToken;
|
|
7
|
-
constructor(transport, transportBaseUrl, setStoredAuthToken, clearStoredAuthToken) {
|
|
8
|
-
this.transport = transport;
|
|
9
|
-
this.transportBaseUrl = transportBaseUrl;
|
|
10
|
-
this.setStoredAuthToken = setStoredAuthToken;
|
|
11
|
-
this.clearStoredAuthToken = clearStoredAuthToken;
|
|
12
|
-
}
|
|
13
|
-
getMe(customFetch) {
|
|
14
|
-
return this.transport.request("/api/me", { fetch: customFetch });
|
|
15
|
-
}
|
|
16
|
-
updateProfile(input) {
|
|
17
|
-
return this.transport.request("/api/me/profile", {
|
|
18
|
-
method: "PATCH",
|
|
19
|
-
headers: { "Content-Type": "application/json" },
|
|
20
|
-
body: JSON.stringify(input),
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
getRules(customFetch) {
|
|
24
|
-
return this.transport.request("/api/me/rules", {
|
|
25
|
-
method: "GET",
|
|
26
|
-
fetch: customFetch,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
async setAuthToken(token) {
|
|
30
|
-
const trimmedToken = token.trim();
|
|
31
|
-
const response = await fetch(this.transportBaseUrl ? `${this.transportBaseUrl}/api/me` : "/api/me", {
|
|
32
|
-
headers: {
|
|
33
|
-
Authorization: `Bearer ${trimmedToken}`,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
if (!response.ok) {
|
|
37
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
38
|
-
const body = contentType.includes("application/json")
|
|
39
|
-
? await response.json().catch(() => null)
|
|
40
|
-
: await response.text().catch(() => response.statusText);
|
|
41
|
-
const message = typeof body === "string" ? body : JSON.stringify(body ?? null);
|
|
42
|
-
throw new HttpError(message || response.statusText, response.status, body);
|
|
43
|
-
}
|
|
44
|
-
this.setStoredAuthToken?.(trimmedToken);
|
|
45
|
-
return response.json();
|
|
46
|
-
}
|
|
47
|
-
async clearAuthToken() {
|
|
48
|
-
this.clearStoredAuthToken?.();
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
getSshKeys(customFetch) {
|
|
52
|
-
return this.transport.request("/api/user/ssh-keys", {
|
|
53
|
-
method: "GET",
|
|
54
|
-
fetch: customFetch,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
createSshKey(data) {
|
|
58
|
-
return this.transport.request("/api/user/ssh-keys", {
|
|
59
|
-
method: "POST",
|
|
60
|
-
headers: {
|
|
61
|
-
"Content-Type": "application/json",
|
|
62
|
-
},
|
|
63
|
-
body: JSON.stringify(data),
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
deleteSshKey(id) {
|
|
67
|
-
return this.transport.request(`/api/user/ssh-keys/${id}`, {
|
|
68
|
-
method: "DELETE",
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
package/dist/client.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ChannelsApi } from "./apis/channels.js";
|
|
2
|
-
import { CronJobsApi } from "./apis/cron-jobs.js";
|
|
3
|
-
import { ExploreApi } from "./apis/explore.js";
|
|
4
|
-
import { GenerationsApi } from "./apis/generations.js";
|
|
5
|
-
import { ModelsApi } from "./apis/models.js";
|
|
6
|
-
import { PromptsApi } from "./apis/prompts.js";
|
|
7
|
-
import { SessionAccessApi } from "./apis/session-access.js";
|
|
8
|
-
import { SearchApi } from "./apis/search.js";
|
|
9
|
-
import { SpaceClient, SpacesApi, type WebSocketConnectionState } from "./apis/spaces.js";
|
|
10
|
-
import { TasksApi } from "./apis/tasks.js";
|
|
11
|
-
import { UserApi } from "./apis/user.js";
|
|
12
|
-
import { PublicInviteApi } from "./apis/invitations.js";
|
|
13
|
-
import { type CohubClientOptions } from "./transport.js";
|
|
14
|
-
export declare class CohubClient {
|
|
15
|
-
readonly spaces: SpacesApi;
|
|
16
|
-
readonly channels: ChannelsApi;
|
|
17
|
-
readonly user: UserApi;
|
|
18
|
-
readonly generations: GenerationsApi;
|
|
19
|
-
readonly models: ModelsApi;
|
|
20
|
-
readonly prompts: PromptsApi;
|
|
21
|
-
readonly sessionAccess: SessionAccessApi;
|
|
22
|
-
readonly search: SearchApi;
|
|
23
|
-
readonly tasks: TasksApi;
|
|
24
|
-
readonly cronJobs: CronJobsApi;
|
|
25
|
-
readonly explore: ExploreApi;
|
|
26
|
-
readonly invite: PublicInviteApi;
|
|
27
|
-
private readonly transport;
|
|
28
|
-
private readonly websocketClient;
|
|
29
|
-
constructor(options?: CohubClientOptions);
|
|
30
|
-
space(spaceId: string): SpaceClient;
|
|
31
|
-
onConnection(handler: (state: WebSocketConnectionState) => void): () => void;
|
|
32
|
-
}
|
|
33
|
-
export declare const createCohubClient: (options?: CohubClientOptions) => CohubClient;
|
package/dist/client.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { ChannelsApi } from "./apis/channels.js";
|
|
2
|
-
import { CronJobsApi } from "./apis/cron-jobs.js";
|
|
3
|
-
import { ExploreApi } from "./apis/explore.js";
|
|
4
|
-
import { GenerationsApi } from "./apis/generations.js";
|
|
5
|
-
import { ModelsApi } from "./apis/models.js";
|
|
6
|
-
import { PromptsApi } from "./apis/prompts.js";
|
|
7
|
-
import { SessionAccessApi } from "./apis/session-access.js";
|
|
8
|
-
import { SearchApi } from "./apis/search.js";
|
|
9
|
-
import { SpaceClient, SpacesApi } from "./apis/spaces.js";
|
|
10
|
-
import { TasksApi } from "./apis/tasks.js";
|
|
11
|
-
import { UserApi } from "./apis/user.js";
|
|
12
|
-
import { PublicInviteApi } from "./apis/invitations.js";
|
|
13
|
-
import { HttpTransport } from "./transport.js";
|
|
14
|
-
import { createWebsocketClient } from "./websocket.js";
|
|
15
|
-
import { resolveApiBaseUrl, resolveWebsocketUrl } from "./environment.js";
|
|
16
|
-
export class CohubClient {
|
|
17
|
-
spaces;
|
|
18
|
-
channels;
|
|
19
|
-
user;
|
|
20
|
-
generations;
|
|
21
|
-
models;
|
|
22
|
-
prompts;
|
|
23
|
-
sessionAccess;
|
|
24
|
-
search;
|
|
25
|
-
tasks;
|
|
26
|
-
cronJobs;
|
|
27
|
-
explore;
|
|
28
|
-
invite;
|
|
29
|
-
transport;
|
|
30
|
-
websocketClient;
|
|
31
|
-
constructor(options = {}) {
|
|
32
|
-
const apiBaseUrl = resolveApiBaseUrl(options);
|
|
33
|
-
this.transport = new HttpTransport(options);
|
|
34
|
-
this.websocketClient = createWebsocketClient({
|
|
35
|
-
url: resolveWebsocketUrl({
|
|
36
|
-
env: options.websocket?.env ?? options.env,
|
|
37
|
-
url: options.websocket?.url,
|
|
38
|
-
}),
|
|
39
|
-
...options.websocket,
|
|
40
|
-
getAccessToken: options.getAccessToken,
|
|
41
|
-
});
|
|
42
|
-
this.spaces = new SpacesApi(this.transport);
|
|
43
|
-
this.channels = new ChannelsApi(this.transport);
|
|
44
|
-
this.user = new UserApi(this.transport, apiBaseUrl, options.setStoredAuthToken, options.clearStoredAuthToken);
|
|
45
|
-
this.generations = new GenerationsApi(this.transport);
|
|
46
|
-
this.models = new ModelsApi(this.transport);
|
|
47
|
-
this.prompts = new PromptsApi(this.transport);
|
|
48
|
-
this.sessionAccess = new SessionAccessApi(this.transport);
|
|
49
|
-
this.search = new SearchApi(this.transport);
|
|
50
|
-
this.tasks = new TasksApi(this.transport);
|
|
51
|
-
this.cronJobs = new CronJobsApi(this.transport);
|
|
52
|
-
this.explore = new ExploreApi(this.transport);
|
|
53
|
-
this.invite = new PublicInviteApi(this.transport);
|
|
54
|
-
}
|
|
55
|
-
space(spaceId) {
|
|
56
|
-
return new SpaceClient(spaceId, this.transport, this.websocketClient);
|
|
57
|
-
}
|
|
58
|
-
onConnection(handler) {
|
|
59
|
-
const connectingCleanup = this.websocketClient.on("connecting", (payload) => {
|
|
60
|
-
handler({
|
|
61
|
-
state: payload.isReconnect ? "reconnecting" : "connecting",
|
|
62
|
-
willReconnect: payload.isReconnect,
|
|
63
|
-
attempt: payload.attempt,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
const reconnectingCleanup = this.websocketClient.on("reconnecting", (payload) => {
|
|
67
|
-
handler({
|
|
68
|
-
state: "reconnecting",
|
|
69
|
-
willReconnect: true,
|
|
70
|
-
attempt: payload.attempt,
|
|
71
|
-
delayMs: payload.delayMs,
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
const openCleanup = this.websocketClient.on("open", (payload) => {
|
|
75
|
-
handler({
|
|
76
|
-
state: "open",
|
|
77
|
-
willReconnect: false,
|
|
78
|
-
connectionId: payload.connectionId,
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
const closeCleanup = this.websocketClient.on("close", (payload) => {
|
|
82
|
-
handler({
|
|
83
|
-
state: "closed",
|
|
84
|
-
willReconnect: payload.willReconnect,
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
const errorCleanup = this.websocketClient.on("error", (payload) => {
|
|
88
|
-
handler({
|
|
89
|
-
state: "error",
|
|
90
|
-
willReconnect: payload.recoverable,
|
|
91
|
-
recoverable: payload.recoverable,
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
return () => {
|
|
95
|
-
connectingCleanup();
|
|
96
|
-
reconnectingCleanup();
|
|
97
|
-
openCleanup();
|
|
98
|
-
closeCleanup();
|
|
99
|
-
errorCleanup();
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
export const createCohubClient = (options) => new CohubClient(options);
|
package/dist/environment.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type CohubEnvironment = "prod" | "dev";
|
|
2
|
-
export declare const COHUB_ENVIRONMENTS: {
|
|
3
|
-
readonly prod: {
|
|
4
|
-
readonly apiBaseUrl: "https://api.cohub.run";
|
|
5
|
-
readonly websocketUrl: "wss://gateway.cohub.run/ws";
|
|
6
|
-
};
|
|
7
|
-
readonly dev: {
|
|
8
|
-
readonly apiBaseUrl: "https://api-dev.cohub.run";
|
|
9
|
-
readonly websocketUrl: "wss://gateway-dev.cohub.run/ws";
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
export declare const resolveCohubEnvironment: (env?: CohubEnvironment) => CohubEnvironment;
|
|
13
|
-
export declare const normalizeBaseUrl: (url: string) => string;
|
|
14
|
-
export declare const normalizeWebsocketUrl: (input: string) => string;
|
|
15
|
-
export declare const resolveApiBaseUrl: (options?: {
|
|
16
|
-
baseUrl?: string;
|
|
17
|
-
env?: CohubEnvironment;
|
|
18
|
-
}) => string;
|
|
19
|
-
export declare const resolveWebsocketUrl: (options?: {
|
|
20
|
-
url?: string;
|
|
21
|
-
env?: CohubEnvironment;
|
|
22
|
-
}) => string;
|
package/dist/environment.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export const COHUB_ENVIRONMENTS = {
|
|
2
|
-
prod: {
|
|
3
|
-
apiBaseUrl: "https://api.cohub.run",
|
|
4
|
-
websocketUrl: "wss://gateway.cohub.run/ws",
|
|
5
|
-
},
|
|
6
|
-
dev: {
|
|
7
|
-
apiBaseUrl: "https://api-dev.cohub.run",
|
|
8
|
-
websocketUrl: "wss://gateway-dev.cohub.run/ws",
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
const readRuntimeEnv = () => {
|
|
12
|
-
const runtime = globalThis;
|
|
13
|
-
return runtime.process?.env?.ENV;
|
|
14
|
-
};
|
|
15
|
-
export const resolveCohubEnvironment = (env) => {
|
|
16
|
-
if (env)
|
|
17
|
-
return env;
|
|
18
|
-
return readRuntimeEnv() === "dev" ? "dev" : "prod";
|
|
19
|
-
};
|
|
20
|
-
export const normalizeBaseUrl = (url) => url.trim().replace(/\/+$/, "");
|
|
21
|
-
export const normalizeWebsocketUrl = (input) => {
|
|
22
|
-
const trimmed = normalizeBaseUrl(input);
|
|
23
|
-
const withProtocol = trimmed
|
|
24
|
-
.replace(/^http:/, "ws:")
|
|
25
|
-
.replace(/^https:/, "wss:");
|
|
26
|
-
return withProtocol.endsWith("/ws") ? withProtocol : `${withProtocol}/ws`;
|
|
27
|
-
};
|
|
28
|
-
export const resolveApiBaseUrl = (options = {}) => {
|
|
29
|
-
if (options.baseUrl)
|
|
30
|
-
return normalizeBaseUrl(options.baseUrl);
|
|
31
|
-
return COHUB_ENVIRONMENTS[resolveCohubEnvironment(options.env)].apiBaseUrl;
|
|
32
|
-
};
|
|
33
|
-
export const resolveWebsocketUrl = (options = {}) => {
|
|
34
|
-
if (options.url)
|
|
35
|
-
return normalizeWebsocketUrl(options.url);
|
|
36
|
-
return COHUB_ENVIRONMENTS[resolveCohubEnvironment(options.env)].websocketUrl;
|
|
37
|
-
};
|
package/dist/realtime.d.ts
DELETED
package/dist/realtime.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export function ensureRealtimeConnected(websocketClient) {
|
|
2
|
-
if (websocketClient.state === "open" || websocketClient.state === "connecting" || websocketClient.state === "reconnecting") {
|
|
3
|
-
return;
|
|
4
|
-
}
|
|
5
|
-
void websocketClient.connect().catch((error) => {
|
|
6
|
-
console.error("[CohubClient] Failed to connect realtime websocket:", error);
|
|
7
|
-
});
|
|
8
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { ContentBlock, Usage } from "@neta-art/cohub-protocol/core";
|
|
2
|
-
import type { MessageRecord, SessionTurnRecord } from "@neta-art/cohub-protocol/model";
|
|
3
|
-
import { type SessionPatchState } from "./session-patch-reducer.js";
|
|
4
|
-
import type { WebsocketClient, WebsocketEventPayload } from "./websocket.js";
|
|
5
|
-
export type AssistantMessageCommit = {
|
|
6
|
-
kind: "intermediate";
|
|
7
|
-
message: MessageRecord;
|
|
8
|
-
isFinal: false;
|
|
9
|
-
} | {
|
|
10
|
-
kind: "final";
|
|
11
|
-
message: MessageRecord;
|
|
12
|
-
isFinal: true;
|
|
13
|
-
} | {
|
|
14
|
-
kind: "error";
|
|
15
|
-
message: MessageRecord;
|
|
16
|
-
isFinal: true;
|
|
17
|
-
} | {
|
|
18
|
-
kind: "ignored";
|
|
19
|
-
message: MessageRecord;
|
|
20
|
-
isFinal: false;
|
|
21
|
-
};
|
|
22
|
-
export type GenerationStreamIntermediateMessage = {
|
|
23
|
-
id?: string;
|
|
24
|
-
sessionId?: string;
|
|
25
|
-
role?: "user" | "assistant" | "system";
|
|
26
|
-
messageId: string | null;
|
|
27
|
-
messageOrdinal: number | null;
|
|
28
|
-
content: ContentBlock[];
|
|
29
|
-
text?: string | null;
|
|
30
|
-
provider?: string | null;
|
|
31
|
-
model?: string | null;
|
|
32
|
-
stopReason?: string | null;
|
|
33
|
-
errorMessage?: string | null;
|
|
34
|
-
usage?: Usage | null;
|
|
35
|
-
toolCallsObjectKey?: string | null;
|
|
36
|
-
meta?: Record<string, unknown> | null;
|
|
37
|
-
createdAt?: string;
|
|
38
|
-
};
|
|
39
|
-
export type GenerationStreamStateEvent = {
|
|
40
|
-
type: "state";
|
|
41
|
-
source: "snapshot" | "patch" | "progress";
|
|
42
|
-
state: SessionPatchState;
|
|
43
|
-
messageId: string | null;
|
|
44
|
-
messageOrdinal: number | null;
|
|
45
|
-
intermediateMessages: GenerationStreamIntermediateMessage[];
|
|
46
|
-
rawEvent: WebsocketEventPayload;
|
|
47
|
-
};
|
|
48
|
-
export type GenerationStreamCommitEvent = {
|
|
49
|
-
type: "commit";
|
|
50
|
-
commit: AssistantMessageCommit;
|
|
51
|
-
rawEvent: WebsocketEventPayload;
|
|
52
|
-
};
|
|
53
|
-
export type GenerationStreamFinalizedEvent = {
|
|
54
|
-
type: "finalized";
|
|
55
|
-
turn: SessionTurnRecord;
|
|
56
|
-
rawEvent: WebsocketEventPayload;
|
|
57
|
-
};
|
|
58
|
-
export type GenerationStreamTurnUpdatedEvent = {
|
|
59
|
-
type: "turn_updated";
|
|
60
|
-
turn: Partial<SessionTurnRecord>;
|
|
61
|
-
rawEvent: WebsocketEventPayload;
|
|
62
|
-
};
|
|
63
|
-
export type GenerationStreamErrorEvent = {
|
|
64
|
-
type: "error";
|
|
65
|
-
message: string;
|
|
66
|
-
rawEvent: WebsocketEventPayload;
|
|
67
|
-
};
|
|
68
|
-
export type GenerationStreamOutOfSyncEvent = {
|
|
69
|
-
type: "out_of_sync";
|
|
70
|
-
source: "snapshot" | "patch";
|
|
71
|
-
reason: "duplicate" | "version_mismatch" | "invalid";
|
|
72
|
-
state: SessionPatchState;
|
|
73
|
-
rawEvent: WebsocketEventPayload;
|
|
74
|
-
};
|
|
75
|
-
export type GenerationStreamEvent = GenerationStreamStateEvent | GenerationStreamCommitEvent | GenerationStreamFinalizedEvent | GenerationStreamTurnUpdatedEvent | GenerationStreamErrorEvent | GenerationStreamOutOfSyncEvent;
|
|
76
|
-
export type GenerationStreamSubscriptionHandlers = {
|
|
77
|
-
event?: (event: GenerationStreamEvent) => void;
|
|
78
|
-
state?: (event: GenerationStreamStateEvent) => void;
|
|
79
|
-
commit?: (event: GenerationStreamCommitEvent) => void;
|
|
80
|
-
finalized?: (event: GenerationStreamFinalizedEvent) => void;
|
|
81
|
-
turnUpdated?: (event: GenerationStreamTurnUpdatedEvent) => void;
|
|
82
|
-
error?: (event: GenerationStreamErrorEvent) => void;
|
|
83
|
-
outOfSync?: (event: GenerationStreamOutOfSyncEvent) => void;
|
|
84
|
-
};
|
|
85
|
-
export declare function parseAssistantMessageCommit(message: MessageRecord): AssistantMessageCommit;
|
|
86
|
-
export declare class SessionGenerationStreamClient {
|
|
87
|
-
private readonly websocketClient;
|
|
88
|
-
private readonly spaceId;
|
|
89
|
-
private readonly sessionId;
|
|
90
|
-
private readonly reducer;
|
|
91
|
-
private messageId;
|
|
92
|
-
private messageOrdinal;
|
|
93
|
-
private intermediateMessages;
|
|
94
|
-
private progressState;
|
|
95
|
-
constructor(websocketClient: WebsocketClient | null, spaceId: string, sessionId: string);
|
|
96
|
-
subscribe(handlers: GenerationStreamSubscriptionHandlers): () => void;
|
|
97
|
-
private emit;
|
|
98
|
-
private resetCurrentMessage;
|
|
99
|
-
private appendCurrentMessage;
|
|
100
|
-
private addIntermediateMessage;
|
|
101
|
-
private handleAppliedState;
|
|
102
|
-
private prepareMessageBoundary;
|
|
103
|
-
private handleSnapshot;
|
|
104
|
-
private handlePatch;
|
|
105
|
-
private handleProgress;
|
|
106
|
-
private handlePersisted;
|
|
107
|
-
private handleFinalized;
|
|
108
|
-
private handleEvent;
|
|
109
|
-
}
|
|
110
|
-
export declare function createSessionGenerationStreamClient(input: {
|
|
111
|
-
websocketClient: WebsocketClient | null;
|
|
112
|
-
spaceId: string;
|
|
113
|
-
sessionId: string;
|
|
114
|
-
}): SessionGenerationStreamClient;
|