@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.
Files changed (51) hide show
  1. package/README.md +6 -105
  2. package/dist/chunks/environment.js +33 -0
  3. package/dist/chunks/http.d.ts +1615 -0
  4. package/dist/chunks/http.js +1919 -0
  5. package/dist/chunks/websocket.d.ts +266 -0
  6. package/dist/chunks/websocket.js +655 -0
  7. package/dist/http.d.ts +3 -32
  8. package/dist/http.js +2 -48
  9. package/dist/index.d.ts +35 -14
  10. package/dist/index.js +105 -8
  11. package/dist/websocket.d.ts +2 -141
  12. package/dist/websocket.js +2 -628
  13. package/package.json +7 -7
  14. package/dist/apis/channels.d.ts +0 -13
  15. package/dist/apis/channels.js +0 -24
  16. package/dist/apis/cron-jobs.d.ts +0 -18
  17. package/dist/apis/cron-jobs.js +0 -25
  18. package/dist/apis/explore.d.ts +0 -9
  19. package/dist/apis/explore.js +0 -9
  20. package/dist/apis/generations.d.ts +0 -7
  21. package/dist/apis/generations.js +0 -13
  22. package/dist/apis/invitations.d.ts +0 -20
  23. package/dist/apis/invitations.js +0 -36
  24. package/dist/apis/models.d.ts +0 -10
  25. package/dist/apis/models.js +0 -13
  26. package/dist/apis/prompts.d.ts +0 -9
  27. package/dist/apis/prompts.js +0 -16
  28. package/dist/apis/search.d.ts +0 -10
  29. package/dist/apis/search.js +0 -14
  30. package/dist/apis/session-access.d.ts +0 -13
  31. package/dist/apis/session-access.js +0 -19
  32. package/dist/apis/spaces.d.ts +0 -371
  33. package/dist/apis/spaces.js +0 -766
  34. package/dist/apis/tasks.d.ts +0 -13
  35. package/dist/apis/tasks.js +0 -18
  36. package/dist/apis/user.d.ts +0 -27
  37. package/dist/apis/user.js +0 -71
  38. package/dist/client.d.ts +0 -33
  39. package/dist/client.js +0 -103
  40. package/dist/environment.d.ts +0 -22
  41. package/dist/environment.js +0 -37
  42. package/dist/realtime.d.ts +0 -2
  43. package/dist/realtime.js +0 -8
  44. package/dist/session-generation-stream.d.ts +0 -114
  45. package/dist/session-generation-stream.js +0 -514
  46. package/dist/session-patch-reducer.d.ts +0 -61
  47. package/dist/session-patch-reducer.js +0 -432
  48. package/dist/transport.d.ts +0 -40
  49. package/dist/transport.js +0 -78
  50. package/dist/types.d.ts +0 -535
  51. package/dist/types.js +0 -1
package/README.md CHANGED
@@ -5,17 +5,20 @@ Cohub SDK for interacting with spaces, sessions, checkpoints, and realtime agent
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- npm install @neta-art/cohub @neta-art/cohub-protocol
8
+ npm install @neta-art/cohub
9
9
  ```
10
10
 
11
11
  ## Quick start
12
12
 
13
13
  ```ts
14
14
  import { createCohubClient } from "@neta-art/cohub";
15
+ import type { ContentBlock } from "@neta-art/cohub";
15
16
 
16
17
  const client = createCohubClient({
17
18
  getAccessToken: async () => localStorage.getItem("token"),
18
19
  });
20
+
21
+ const content: ContentBlock[] = [{ type: "text", text: "Hello" }];
19
22
  ```
20
23
 
21
24
  The SDK connects to production by default:
@@ -78,112 +81,10 @@ const stop = session.subscribe({
78
81
  progress(event) {
79
82
  console.log("progress", event.payload);
80
83
  },
81
- final(event) {
82
- console.log("final", event.payload);
83
- },
84
- error(event) {
85
- console.error("error", event.payload);
86
- },
87
- persisted(event) {
88
- console.log("persisted", event.payload);
84
+ finalized(event) {
85
+ console.log("done", event.payload);
89
86
  },
90
87
  });
91
88
 
92
- // later
93
89
  stop();
94
90
  ```
95
-
96
- You can also listen with business-oriented event names:
97
-
98
- ```ts
99
- session.on("turn.patch", (event) => {
100
- // Streaming state-machine patch: { turnId, seq, baseSeq, ops }.
101
- // Consecutive append ops may be compacted to { v }.
102
- console.log(event.payload.ops);
103
- });
104
-
105
- session.subscribe({
106
- patchState: (result) => {
107
- if (result.applied) {
108
- console.log(result.state.contentBlocks);
109
- }
110
- },
111
- });
112
-
113
- session.on("turn.final", (event) => {
114
- // Fired when an assistant_final message.persisted event arrives.
115
- console.log(event.payload.message);
116
- });
117
-
118
- space.on("message.persisted", (event) => {
119
- console.log(event.payload);
120
- });
121
- ```
122
-
123
- For product UIs, prefer the normalized generation stream. It folds
124
- `session.turn.snapshot`, `session.turn.patch`, legacy `session.turn.progress`,
125
- persisted assistant messages, finalized turns, and turn errors into stable
126
- semantic events.
127
-
128
- ```ts
129
- const stop = session.subscribeGeneration({
130
- state(event) {
131
- console.log(event.source, event.state.contentBlocks);
132
- },
133
- commit(event) {
134
- if (event.commit.kind === "final") {
135
- console.log("assistant final", event.commit.message);
136
- }
137
- },
138
- outOfSync() {
139
- // Fetch `session.turns.streamSnapshot()` or reconcile persisted turns.
140
- },
141
- });
142
- ```
143
-
144
- Supported business event names:
145
-
146
- - `turn.patch`
147
- - `turn.progress` (legacy compatibility)
148
- - `turn.final`
149
- - `turn.error`
150
- - `message.persisted`
151
-
152
- ## HTTP-only usage
153
-
154
- If you only want HTTP transport, use the dedicated entry:
155
-
156
- ```ts
157
- import { createHttpClient } from "@neta-art/cohub/http";
158
-
159
- const http = createHttpClient({
160
- getAccessToken: async () => localStorage.getItem("token"),
161
- });
162
-
163
- const spaces = await http.spaces.list();
164
- ```
165
-
166
- Note: realtime methods like `space.subscribe(...)` or `session.subscribe(...)` require the main client with websocket configuration.
167
-
168
- ## Low-level websocket usage
169
-
170
- If you need direct realtime transport access, use the websocket entry:
171
-
172
- ```ts
173
- import { createWebsocketClient } from "@neta-art/cohub/websocket";
174
-
175
- const ws = createWebsocketClient({
176
- getAccessToken: async () => localStorage.getItem("token"),
177
- });
178
-
179
- await ws.connect();
180
- ```
181
-
182
- ## Design principles
183
-
184
- This SDK is intentionally built around Cohub's co-creation model:
185
-
186
- - work with `space(...)` and `session(...)` as the primary creative surface
187
- - send messages through `session.messages.send(...)`
188
- - subscribe through `space.subscribe(...)` and `session.subscribe(...)`
189
- - keep HTTP and realtime transports separate but coordinated
@@ -0,0 +1,33 @@
1
+ //#region src/environment.ts
2
+ const COHUB_ENVIRONMENTS = {
3
+ prod: {
4
+ apiBaseUrl: "https://api.cohub.run",
5
+ websocketUrl: "wss://gateway.cohub.run/ws"
6
+ },
7
+ dev: {
8
+ apiBaseUrl: "https://api-dev.cohub.run",
9
+ websocketUrl: "wss://gateway-dev.cohub.run/ws"
10
+ }
11
+ };
12
+ const readRuntimeEnv = () => {
13
+ return globalThis.process?.env?.ENV;
14
+ };
15
+ const resolveCohubEnvironment = (env) => {
16
+ if (env) return env;
17
+ return readRuntimeEnv() === "dev" ? "dev" : "prod";
18
+ };
19
+ const normalizeBaseUrl = (url) => url.trim().replace(/\/+$/, "");
20
+ const normalizeWebsocketUrl = (input) => {
21
+ const withProtocol = normalizeBaseUrl(input).replace(/^http:/, "ws:").replace(/^https:/, "wss:");
22
+ return withProtocol.endsWith("/ws") ? withProtocol : `${withProtocol}/ws`;
23
+ };
24
+ const resolveApiBaseUrl = (options = {}) => {
25
+ if (options.baseUrl) return normalizeBaseUrl(options.baseUrl);
26
+ return COHUB_ENVIRONMENTS[resolveCohubEnvironment(options.env)].apiBaseUrl;
27
+ };
28
+ const resolveWebsocketUrl = (options = {}) => {
29
+ if (options.url) return normalizeWebsocketUrl(options.url);
30
+ return COHUB_ENVIRONMENTS[resolveCohubEnvironment(options.env)].websocketUrl;
31
+ };
32
+ //#endregion
33
+ export { resolveCohubEnvironment as a, resolveApiBaseUrl as i, normalizeBaseUrl as n, resolveWebsocketUrl as o, normalizeWebsocketUrl as r, COHUB_ENVIRONMENTS as t };