@soulcraft/sdk 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/dist/client/index.d.ts +62 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +60 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/ai/index.d.ts +55 -0
- package/dist/modules/ai/index.d.ts.map +1 -0
- package/dist/modules/ai/index.js +263 -0
- package/dist/modules/ai/index.js.map +1 -0
- package/dist/modules/ai/types.d.ts +216 -0
- package/dist/modules/ai/types.d.ts.map +1 -0
- package/dist/modules/ai/types.js +30 -0
- package/dist/modules/ai/types.js.map +1 -0
- package/dist/modules/auth/backchannel.d.ts +85 -0
- package/dist/modules/auth/backchannel.d.ts.map +1 -0
- package/dist/modules/auth/backchannel.js +168 -0
- package/dist/modules/auth/backchannel.js.map +1 -0
- package/dist/modules/auth/config.d.ts +122 -0
- package/dist/modules/auth/config.d.ts.map +1 -0
- package/dist/modules/auth/config.js +158 -0
- package/dist/modules/auth/config.js.map +1 -0
- package/dist/modules/auth/middleware.d.ts +146 -0
- package/dist/modules/auth/middleware.d.ts.map +1 -0
- package/dist/modules/auth/middleware.js +204 -0
- package/dist/modules/auth/middleware.js.map +1 -0
- package/dist/modules/auth/types.d.ts +162 -0
- package/dist/modules/auth/types.d.ts.map +1 -0
- package/dist/modules/auth/types.js +14 -0
- package/dist/modules/auth/types.js.map +1 -0
- package/dist/modules/billing/types.d.ts +7 -0
- package/dist/modules/billing/types.d.ts.map +1 -0
- package/dist/modules/billing/types.js +7 -0
- package/dist/modules/billing/types.js.map +1 -0
- package/dist/modules/brainy/auth.d.ts +104 -0
- package/dist/modules/brainy/auth.d.ts.map +1 -0
- package/dist/modules/brainy/auth.js +144 -0
- package/dist/modules/brainy/auth.js.map +1 -0
- package/dist/modules/brainy/errors.d.ts +118 -0
- package/dist/modules/brainy/errors.d.ts.map +1 -0
- package/dist/modules/brainy/errors.js +142 -0
- package/dist/modules/brainy/errors.js.map +1 -0
- package/dist/modules/brainy/events.d.ts +63 -0
- package/dist/modules/brainy/events.d.ts.map +1 -0
- package/dist/modules/brainy/events.js +14 -0
- package/dist/modules/brainy/events.js.map +1 -0
- package/dist/modules/brainy/proxy.d.ts +48 -0
- package/dist/modules/brainy/proxy.d.ts.map +1 -0
- package/dist/modules/brainy/proxy.js +95 -0
- package/dist/modules/brainy/proxy.js.map +1 -0
- package/dist/modules/brainy/types.d.ts +83 -0
- package/dist/modules/brainy/types.d.ts.map +1 -0
- package/dist/modules/brainy/types.js +21 -0
- package/dist/modules/brainy/types.js.map +1 -0
- package/dist/modules/events/index.d.ts +41 -0
- package/dist/modules/events/index.d.ts.map +1 -0
- package/dist/modules/events/index.js +53 -0
- package/dist/modules/events/index.js.map +1 -0
- package/dist/modules/events/types.d.ts +129 -0
- package/dist/modules/events/types.d.ts.map +1 -0
- package/dist/modules/events/types.js +32 -0
- package/dist/modules/events/types.js.map +1 -0
- package/dist/modules/formats/types.d.ts +7 -0
- package/dist/modules/formats/types.d.ts.map +1 -0
- package/dist/modules/formats/types.js +7 -0
- package/dist/modules/formats/types.js.map +1 -0
- package/dist/modules/hall/types.d.ts +56 -0
- package/dist/modules/hall/types.d.ts.map +1 -0
- package/dist/modules/hall/types.js +16 -0
- package/dist/modules/hall/types.js.map +1 -0
- package/dist/modules/kits/types.d.ts +7 -0
- package/dist/modules/kits/types.d.ts.map +1 -0
- package/dist/modules/kits/types.js +7 -0
- package/dist/modules/kits/types.js.map +1 -0
- package/dist/modules/license/types.d.ts +7 -0
- package/dist/modules/license/types.d.ts.map +1 -0
- package/dist/modules/license/types.js +7 -0
- package/dist/modules/license/types.js.map +1 -0
- package/dist/modules/notifications/types.d.ts +7 -0
- package/dist/modules/notifications/types.d.ts.map +1 -0
- package/dist/modules/notifications/types.js +7 -0
- package/dist/modules/notifications/types.js.map +1 -0
- package/dist/modules/skills/index.d.ts +60 -0
- package/dist/modules/skills/index.d.ts.map +1 -0
- package/dist/modules/skills/index.js +253 -0
- package/dist/modules/skills/index.js.map +1 -0
- package/dist/modules/skills/types.d.ts +127 -0
- package/dist/modules/skills/types.d.ts.map +1 -0
- package/dist/modules/skills/types.js +23 -0
- package/dist/modules/skills/types.js.map +1 -0
- package/dist/modules/versions/types.d.ts +31 -0
- package/dist/modules/versions/types.d.ts.map +1 -0
- package/dist/modules/versions/types.js +9 -0
- package/dist/modules/versions/types.js.map +1 -0
- package/dist/modules/vfs/types.d.ts +26 -0
- package/dist/modules/vfs/types.d.ts.map +1 -0
- package/dist/modules/vfs/types.js +11 -0
- package/dist/modules/vfs/types.js.map +1 -0
- package/dist/server/create-sdk.d.ts +70 -0
- package/dist/server/create-sdk.d.ts.map +1 -0
- package/dist/server/create-sdk.js +125 -0
- package/dist/server/create-sdk.js.map +1 -0
- package/dist/server/hall-handlers.d.ts +195 -0
- package/dist/server/hall-handlers.d.ts.map +1 -0
- package/dist/server/hall-handlers.js +239 -0
- package/dist/server/hall-handlers.js.map +1 -0
- package/dist/server/handlers.d.ts +216 -0
- package/dist/server/handlers.d.ts.map +1 -0
- package/dist/server/handlers.js +214 -0
- package/dist/server/handlers.js.map +1 -0
- package/dist/server/index.d.ts +52 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +50 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/instance-pool.d.ts +299 -0
- package/dist/server/instance-pool.d.ts.map +1 -0
- package/dist/server/instance-pool.js +359 -0
- package/dist/server/instance-pool.js.map +1 -0
- package/dist/transports/http.d.ts +86 -0
- package/dist/transports/http.d.ts.map +1 -0
- package/dist/transports/http.js +134 -0
- package/dist/transports/http.js.map +1 -0
- package/dist/transports/local.d.ts +76 -0
- package/dist/transports/local.d.ts.map +1 -0
- package/dist/transports/local.js +101 -0
- package/dist/transports/local.js.map +1 -0
- package/dist/transports/sse.d.ts +99 -0
- package/dist/transports/sse.d.ts.map +1 -0
- package/dist/transports/sse.js +192 -0
- package/dist/transports/sse.js.map +1 -0
- package/dist/transports/transport.d.ts +68 -0
- package/dist/transports/transport.d.ts.map +1 -0
- package/dist/transports/transport.js +14 -0
- package/dist/transports/transport.js.map +1 -0
- package/dist/transports/ws.d.ts +135 -0
- package/dist/transports/ws.d.ts.map +1 -0
- package/dist/transports/ws.js +331 -0
- package/dist/transports/ws.js.map +1 -0
- package/dist/types.d.ts +152 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/docs/ADR-001-sdk-design.md +282 -0
- package/docs/IMPLEMENTATION-PLAN.md +708 -0
- package/docs/USAGE.md +646 -0
- package/docs/kit-sdk-guide.md +474 -0
- package/package.json +61 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module transports/ws
|
|
3
|
+
* @description WebSocket transport — bidirectional MessagePack RPC with push change events.
|
|
4
|
+
*
|
|
5
|
+
* ## Wire protocol
|
|
6
|
+
*
|
|
7
|
+
* **Client → Server** (binary MessagePack):
|
|
8
|
+
* ```
|
|
9
|
+
* { id: string, method: string, args: unknown[] }
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* **Server → Client** (binary MessagePack), three message kinds:
|
|
13
|
+
* 1. Ready handshake: `{ type: 'ready', scope: string }`
|
|
14
|
+
* 2. RPC response: `{ id: string, result?: unknown, error?: { code, message } }`
|
|
15
|
+
* 3. Change push: `{ type: 'change', event: 'add'|'update'|'delete'|'relate'|'unrelate', entity?, relation? }`
|
|
16
|
+
*
|
|
17
|
+
* ## Auth
|
|
18
|
+
*
|
|
19
|
+
* The capability token is sent as `Authorization: Bearer <token>` on the WebSocket
|
|
20
|
+
* upgrade request (Bun-specific header injection). The optional `scope` parameter
|
|
21
|
+
* is passed as a query string so Venue can select the correct tenant brain.
|
|
22
|
+
*
|
|
23
|
+
* ## Reconnection
|
|
24
|
+
*
|
|
25
|
+
* On unexpected disconnection the transport automatically retries with exponential
|
|
26
|
+
* backoff (1 s → 30 s cap) up to `maxReconnectAttempts` times.
|
|
27
|
+
* Auth failures (close codes 4001, 4003) do not retry.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { createSDK } from '@soulcraft/sdk/client'
|
|
32
|
+
*
|
|
33
|
+
* const sdk = createSDK({
|
|
34
|
+
* mode: 'client',
|
|
35
|
+
* product: 'workshop',
|
|
36
|
+
* transport: 'ws',
|
|
37
|
+
* baseUrl: 'wss://venue.soulcraft.com',
|
|
38
|
+
* auth: { token: capabilityToken },
|
|
39
|
+
* })
|
|
40
|
+
*
|
|
41
|
+
* await sdk.connect()
|
|
42
|
+
*
|
|
43
|
+
* sdk.brainy.onDataChange((event) => {
|
|
44
|
+
* console.log('Remote change:', event.event, event.entity?.nounType)
|
|
45
|
+
* })
|
|
46
|
+
*
|
|
47
|
+
* const results = await sdk.brainy.find({ query: 'inventory' })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
import { encode, decode } from '@msgpack/msgpack';
|
|
51
|
+
import { SDKDisconnectedError, SDKTimeoutError, SDKAuthError, SDKForbiddenError, SDKRpcError, } from '../modules/brainy/errors.js';
|
|
52
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
53
|
+
// WsTransport
|
|
54
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
55
|
+
/**
|
|
56
|
+
* Transport that communicates via MessagePack-encoded WebSocket RPC.
|
|
57
|
+
*
|
|
58
|
+
* Supports both outbound RPC calls and inbound change push events from the
|
|
59
|
+
* server. Auto-reconnects on unexpected disconnection.
|
|
60
|
+
*
|
|
61
|
+
* Call `connect()` once before making any `call()` invocations. The SDK's
|
|
62
|
+
* `createSDK` client factory calls this automatically when `sdk.connect()` is
|
|
63
|
+
* invoked.
|
|
64
|
+
*/
|
|
65
|
+
export class WsTransport {
|
|
66
|
+
ws = null;
|
|
67
|
+
wsUrl;
|
|
68
|
+
authToken;
|
|
69
|
+
scope;
|
|
70
|
+
timeoutMs;
|
|
71
|
+
maxReconnectAttempts;
|
|
72
|
+
pending = new Map();
|
|
73
|
+
nextId = 0;
|
|
74
|
+
connectionState = 'disconnected';
|
|
75
|
+
changeListeners = [];
|
|
76
|
+
connectResolve = null;
|
|
77
|
+
connectReject = null;
|
|
78
|
+
reconnectAttempts = 0;
|
|
79
|
+
reconnectTimer = null;
|
|
80
|
+
/**
|
|
81
|
+
* @param wsUrl - WebSocket endpoint URL, e.g. `'wss://venue.soulcraft.com/api/brainy/ws'`.
|
|
82
|
+
* @param authToken - HMAC-signed capability token from `createCapabilityToken()`.
|
|
83
|
+
* @param scope - Optional scope (tenant slug) passed as `?scope=` on connect.
|
|
84
|
+
* @param timeoutMs - RPC call timeout in milliseconds. Default: 30 000.
|
|
85
|
+
* @param maxReconnectAttempts - Max reconnect attempts on unexpected disconnect. Default: 10.
|
|
86
|
+
*/
|
|
87
|
+
constructor(wsUrl, authToken, scope, timeoutMs = 30_000, maxReconnectAttempts = 10) {
|
|
88
|
+
this.wsUrl = wsUrl;
|
|
89
|
+
this.authToken = authToken;
|
|
90
|
+
this.scope = scope;
|
|
91
|
+
this.timeoutMs = timeoutMs;
|
|
92
|
+
this.maxReconnectAttempts = maxReconnectAttempts;
|
|
93
|
+
}
|
|
94
|
+
// ── SDKTransport interface ───────────────────────────────────────────────
|
|
95
|
+
/**
|
|
96
|
+
* Sends a MessagePack-encoded RPC request and awaits the response.
|
|
97
|
+
*
|
|
98
|
+
* @param method - Dot-separated Brainy method name (e.g. `'vfs.readdir'`).
|
|
99
|
+
* @param args - Positional arguments to forward.
|
|
100
|
+
* @returns Whatever the server's Brainy method returns.
|
|
101
|
+
* @throws {@link SDKDisconnectedError} if not connected.
|
|
102
|
+
* @throws {@link SDKTimeoutError} after `timeoutMs` ms.
|
|
103
|
+
* @throws {@link SDKRpcError} if the server reports an error.
|
|
104
|
+
*/
|
|
105
|
+
async call(method, args) {
|
|
106
|
+
if (this.connectionState !== 'connected') {
|
|
107
|
+
throw new SDKDisconnectedError();
|
|
108
|
+
}
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
const id = String(this.nextId++);
|
|
111
|
+
const timeoutId = setTimeout(() => {
|
|
112
|
+
this.pending.delete(id);
|
|
113
|
+
reject(new SDKTimeoutError(method));
|
|
114
|
+
}, this.timeoutMs);
|
|
115
|
+
this.pending.set(id, { resolve, reject, timeoutId });
|
|
116
|
+
const request = { id, method, args };
|
|
117
|
+
this.ws.send(encode(request));
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Registers a listener for real-time change push events from the server.
|
|
122
|
+
*
|
|
123
|
+
* @param handler - Called with each {@link BrainyChangeEvent} as it arrives.
|
|
124
|
+
*/
|
|
125
|
+
onEvent(handler) {
|
|
126
|
+
this.changeListeners.push(handler);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Removes a previously registered change event listener.
|
|
130
|
+
*
|
|
131
|
+
* @param handler - The same function reference passed to {@link WsTransport.onEvent}.
|
|
132
|
+
*/
|
|
133
|
+
offEvent(handler) {
|
|
134
|
+
const idx = this.changeListeners.indexOf(handler);
|
|
135
|
+
if (idx !== -1)
|
|
136
|
+
this.changeListeners.splice(idx, 1);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns `true` when the WebSocket is in the connected state.
|
|
140
|
+
*/
|
|
141
|
+
isAlive() {
|
|
142
|
+
return this.connectionState === 'connected';
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Closes the WebSocket connection permanently.
|
|
146
|
+
*
|
|
147
|
+
* After `close()`, this transport instance cannot be reconnected.
|
|
148
|
+
* All pending RPC calls are rejected with {@link SDKDisconnectedError}.
|
|
149
|
+
*/
|
|
150
|
+
async close() {
|
|
151
|
+
this.connectionState = 'closed';
|
|
152
|
+
if (this.reconnectTimer) {
|
|
153
|
+
clearTimeout(this.reconnectTimer);
|
|
154
|
+
this.reconnectTimer = null;
|
|
155
|
+
}
|
|
156
|
+
this._rejectAllPending(new SDKDisconnectedError());
|
|
157
|
+
if (this.ws) {
|
|
158
|
+
this.ws.close(1000, 'Client disconnect');
|
|
159
|
+
this.ws = null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// ── Connection management ────────────────────────────────────────────────
|
|
163
|
+
/**
|
|
164
|
+
* Establishes the WebSocket connection and waits for the server `ready` message.
|
|
165
|
+
*
|
|
166
|
+
* Must be called once before any `call()` invocations. Resolves when the server
|
|
167
|
+
* confirms successful authentication and scope selection. The SDK's `createSDK`
|
|
168
|
+
* client factory exposes this as `sdk.connect()`.
|
|
169
|
+
*
|
|
170
|
+
* @throws Error if authentication fails (close codes 4001 / 4003).
|
|
171
|
+
* @throws Error if no `ready` message arrives within 15 seconds.
|
|
172
|
+
*/
|
|
173
|
+
async connect() {
|
|
174
|
+
if (this.connectionState === 'connected')
|
|
175
|
+
return;
|
|
176
|
+
if (this.connectionState === 'closed') {
|
|
177
|
+
throw new Error('WsTransport: cannot reconnect after explicit close()');
|
|
178
|
+
}
|
|
179
|
+
this.connectionState = 'connecting';
|
|
180
|
+
return new Promise((resolve, reject) => {
|
|
181
|
+
const readyTimeout = setTimeout(() => {
|
|
182
|
+
if (this.connectionState !== 'connected') {
|
|
183
|
+
reject(new Error(`WsTransport: timed out waiting for 'ready' from ${this.wsUrl}`));
|
|
184
|
+
}
|
|
185
|
+
}, 15_000);
|
|
186
|
+
this.connectResolve = () => {
|
|
187
|
+
clearTimeout(readyTimeout);
|
|
188
|
+
resolve();
|
|
189
|
+
};
|
|
190
|
+
this.connectReject = (e) => {
|
|
191
|
+
clearTimeout(readyTimeout);
|
|
192
|
+
reject(e);
|
|
193
|
+
};
|
|
194
|
+
this._openSocket();
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
// ── Internal ─────────────────────────────────────────────────────────────
|
|
198
|
+
_openSocket() {
|
|
199
|
+
const url = this.scope
|
|
200
|
+
? `${this.wsUrl}?scope=${encodeURIComponent(this.scope)}`
|
|
201
|
+
: this.wsUrl;
|
|
202
|
+
// Bun supports custom headers on WebSocket upgrade (non-standard extension).
|
|
203
|
+
// @ts-expect-error — Bun-specific WebSocket constructor options
|
|
204
|
+
this.ws = new WebSocket(url, { headers: { Authorization: `Bearer ${this.authToken}` } });
|
|
205
|
+
this.ws.binaryType = 'arraybuffer';
|
|
206
|
+
this.ws.onopen = () => {
|
|
207
|
+
// Connection established; waiting for server 'ready' message.
|
|
208
|
+
};
|
|
209
|
+
this.ws.onmessage = (event) => {
|
|
210
|
+
this._handleMessage(event.data);
|
|
211
|
+
};
|
|
212
|
+
this.ws.onerror = (event) => {
|
|
213
|
+
console.error('[SDK/ws] WebSocket error', event);
|
|
214
|
+
};
|
|
215
|
+
this.ws.onclose = (event) => {
|
|
216
|
+
this._handleClose(event.code, event.reason);
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
_handleMessage(data) {
|
|
220
|
+
let msg;
|
|
221
|
+
try {
|
|
222
|
+
msg = decode(new Uint8Array(data));
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
console.error('[SDK/ws] Failed to decode MessagePack message', err);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (!msg || typeof msg !== 'object')
|
|
229
|
+
return;
|
|
230
|
+
const m = msg;
|
|
231
|
+
// Ready handshake
|
|
232
|
+
if (m['type'] === 'ready') {
|
|
233
|
+
const ready = m;
|
|
234
|
+
this.connectionState = 'connected';
|
|
235
|
+
this.reconnectAttempts = 0;
|
|
236
|
+
console.log(`[SDK/ws] Ready — scope: ${ready.scope}`);
|
|
237
|
+
this.connectResolve?.();
|
|
238
|
+
this.connectResolve = null;
|
|
239
|
+
this.connectReject = null;
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
// RPC response (has an 'id' field)
|
|
243
|
+
if (typeof m['id'] === 'string') {
|
|
244
|
+
const response = m;
|
|
245
|
+
const pending = this.pending.get(response.id);
|
|
246
|
+
if (!pending)
|
|
247
|
+
return; // Response to timed-out or unknown request
|
|
248
|
+
clearTimeout(pending.timeoutId);
|
|
249
|
+
this.pending.delete(response.id);
|
|
250
|
+
if (response.error) {
|
|
251
|
+
pending.reject(new SDKRpcError(response.error.code, response.error.message));
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
pending.resolve(response.result);
|
|
255
|
+
}
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
// Change push event
|
|
259
|
+
if (m['type'] === 'change') {
|
|
260
|
+
const event = m;
|
|
261
|
+
for (const listener of this.changeListeners) {
|
|
262
|
+
try {
|
|
263
|
+
listener(event);
|
|
264
|
+
}
|
|
265
|
+
catch (err) {
|
|
266
|
+
console.error('[SDK/ws] Change listener threw', err);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
_handleClose(code, reason) {
|
|
272
|
+
const wasConnecting = this.connectionState === 'connecting';
|
|
273
|
+
// Auth failures: never retry
|
|
274
|
+
if (code === 4001) {
|
|
275
|
+
this.connectionState = 'closed';
|
|
276
|
+
const err = new SDKAuthError('WebSocket close 4001');
|
|
277
|
+
this._rejectAllPending(err);
|
|
278
|
+
this.connectReject?.(err);
|
|
279
|
+
this.connectResolve = this.connectReject = null;
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (code === 4003) {
|
|
283
|
+
this.connectionState = 'closed';
|
|
284
|
+
const err = new SDKForbiddenError('WebSocket close 4003');
|
|
285
|
+
this._rejectAllPending(err);
|
|
286
|
+
this.connectReject?.(err);
|
|
287
|
+
this.connectResolve = this.connectReject = null;
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
// Explicit disconnect
|
|
291
|
+
if (this.connectionState === 'closed') {
|
|
292
|
+
this._rejectAllPending(new SDKDisconnectedError());
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
// Unexpected disconnect while connecting
|
|
296
|
+
if (wasConnecting) {
|
|
297
|
+
this.connectionState = 'disconnected';
|
|
298
|
+
const err = new Error(`WsTransport: closed during connect (code=${code}, reason=${reason})`);
|
|
299
|
+
this._rejectAllPending(err);
|
|
300
|
+
this.connectReject?.(err);
|
|
301
|
+
this.connectResolve = this.connectReject = null;
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
// Unexpected disconnect while connected → attempt reconnect
|
|
305
|
+
this.connectionState = 'disconnected';
|
|
306
|
+
this._rejectAllPending(new SDKDisconnectedError());
|
|
307
|
+
if (this.reconnectAttempts < this.maxReconnectAttempts) {
|
|
308
|
+
const backoffMs = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30_000);
|
|
309
|
+
this.reconnectAttempts++;
|
|
310
|
+
console.log(`[SDK/ws] Reconnecting in ${backoffMs}ms ` +
|
|
311
|
+
`(attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`);
|
|
312
|
+
this.reconnectTimer = setTimeout(() => {
|
|
313
|
+
this.reconnectTimer = null;
|
|
314
|
+
this.connectionState = 'connecting';
|
|
315
|
+
this._openSocket();
|
|
316
|
+
}, backoffMs);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
console.error(`[SDK/ws] Max reconnect attempts reached for ${this.wsUrl}`);
|
|
320
|
+
this.connectionState = 'closed';
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
_rejectAllPending(error) {
|
|
324
|
+
for (const [, pending] of this.pending) {
|
|
325
|
+
clearTimeout(pending.timeoutId);
|
|
326
|
+
pending.reject(error);
|
|
327
|
+
}
|
|
328
|
+
this.pending.clear();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
//# sourceMappingURL=ws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../../src/transports/ws.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;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;QACf,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,+CAA+C,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;YAC1E,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAA;QACjC,CAAC;IACH,CAAC;IAEO,iBAAiB,CAAC,KAAY;QACpC,KAAK,MAAM,CAAC,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACvC,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;YAC/B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACvB,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module types
|
|
3
|
+
* @description Core shared types for @soulcraft/sdk. Defines the top-level SoulcraftSDK
|
|
4
|
+
* interface and configuration options for both server and client modes. All module
|
|
5
|
+
* namespaces (brainy, vfs, auth, etc.) hang off of SoulcraftSDK.
|
|
6
|
+
*/
|
|
7
|
+
/** Products that can register as OIDC clients of auth.soulcraft.com. */
|
|
8
|
+
export type SoulcraftProduct = 'workshop' | 'venue' | 'academy' | 'portal';
|
|
9
|
+
/** Brainy instance pooling strategies. */
|
|
10
|
+
export type InstanceStrategy = 'per-user' | 'per-tenant' | 'per-scope';
|
|
11
|
+
/** Transport protocols supported by the client SDK. */
|
|
12
|
+
export type Transport = 'http' | 'ws' | 'sse' | 'local';
|
|
13
|
+
/**
|
|
14
|
+
* @description The top-level SDK interface. Every module namespace is accessible
|
|
15
|
+
* as a property. Server mode additionally exposes shutdown() and flush().
|
|
16
|
+
* Client mode exposes connect() for WebSocket transports.
|
|
17
|
+
*/
|
|
18
|
+
export interface SoulcraftSDK {
|
|
19
|
+
/** Full Brainy graph API — CRUD, search, embed, cluster, migrate, neural, counts. */
|
|
20
|
+
readonly brainy: BrainyModule;
|
|
21
|
+
/** Virtual filesystem — readFile, writeFile, tree, watch, search, stat, rename. */
|
|
22
|
+
readonly vfs: VfsModule;
|
|
23
|
+
/** Entity version history — save, list, restore, compare, diff. */
|
|
24
|
+
readonly versions: VersionsModule;
|
|
25
|
+
/** Auth — OIDC session, capability tokens, middleware factories. */
|
|
26
|
+
readonly auth: AuthModule;
|
|
27
|
+
/** Licensing — Cortex activation, plan info, AI credits, BYOK. */
|
|
28
|
+
readonly license: LicenseModule;
|
|
29
|
+
/** AI — Claude model tiers, delegator, Briggy companion API, tool definitions. */
|
|
30
|
+
readonly ai: AiModule;
|
|
31
|
+
/** Platform event bus — emit and subscribe to VFS, entity, and AI activity events. */
|
|
32
|
+
readonly events: EventsModule;
|
|
33
|
+
/** Skill system — load, install, and query VFS-backed and bundled skills. */
|
|
34
|
+
readonly skills: SkillsModule;
|
|
35
|
+
/** Kit system — load kits, initialize workspaces from kit templates. */
|
|
36
|
+
readonly kits: KitsModule;
|
|
37
|
+
/** Soulcraft format types — WvizDocument, WDOC, WSLIDE, WQUIZ schemas. */
|
|
38
|
+
readonly formats: FormatsModule;
|
|
39
|
+
/** Usage metering, quota checks, top-up credits, Stripe subscriptions. */
|
|
40
|
+
readonly billing: BillingModule;
|
|
41
|
+
/** Email (Postmark) + SMS (Twilio) + dev-mode console notifications. */
|
|
42
|
+
readonly notifications: NotificationsModule;
|
|
43
|
+
/**
|
|
44
|
+
* Real-time communication — WebRTC SFU, chat, data channels, transcription, recording.
|
|
45
|
+
* Present only when @soulcraft/hall is installed and configured in ServerSDKOptions.hall.
|
|
46
|
+
*/
|
|
47
|
+
readonly hall?: HallModule;
|
|
48
|
+
/** Server-mode only: gracefully flush all Brainy instances and release resources. */
|
|
49
|
+
shutdown?(): Promise<void>;
|
|
50
|
+
/** Server-mode only: flush a specific user/tenant's Brainy instance to storage. */
|
|
51
|
+
flush?(scopeKey: string): Promise<void>;
|
|
52
|
+
/** Client-mode only: connect the WebSocket transport. */
|
|
53
|
+
connect?(): Promise<void>;
|
|
54
|
+
/** Client-mode only: disconnect and clean up. */
|
|
55
|
+
disconnect?(): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
import type { SoulcraftBrainy } from './modules/brainy/types.js';
|
|
58
|
+
import type { VfsModule as _VfsModule } from './modules/vfs/types.js';
|
|
59
|
+
import type { VersionsModule as _VersionsModule } from './modules/versions/types.js';
|
|
60
|
+
import type { HallModule as _HallModule } from './modules/hall/types.js';
|
|
61
|
+
import type { AuthModule as _AuthModule } from './modules/auth/types.js';
|
|
62
|
+
import type { AiModule as _AiModule } from './modules/ai/types.js';
|
|
63
|
+
import type { EventsModule as _EventsModule } from './modules/events/types.js';
|
|
64
|
+
import type { SkillsModule as _SkillsModule } from './modules/skills/types.js';
|
|
65
|
+
export type BrainyModule = SoulcraftBrainy;
|
|
66
|
+
export type VfsModule = _VfsModule;
|
|
67
|
+
export type VersionsModule = _VersionsModule;
|
|
68
|
+
export type HallModule = _HallModule;
|
|
69
|
+
export type AuthModule = _AuthModule;
|
|
70
|
+
export type AiModule = _AiModule;
|
|
71
|
+
export type EventsModule = _EventsModule;
|
|
72
|
+
export type SkillsModule = _SkillsModule;
|
|
73
|
+
export type LicenseModule = Record<string, unknown>;
|
|
74
|
+
export type KitsModule = Record<string, unknown>;
|
|
75
|
+
export type FormatsModule = Record<string, unknown>;
|
|
76
|
+
export type BillingModule = Record<string, unknown>;
|
|
77
|
+
export type NotificationsModule = Record<string, unknown>;
|
|
78
|
+
/**
|
|
79
|
+
* @description Base options shared by both server and client SDK modes.
|
|
80
|
+
*/
|
|
81
|
+
export interface SDKOptions {
|
|
82
|
+
/** Which Soulcraft product is this SDK instance for. */
|
|
83
|
+
product: SoulcraftProduct;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @description Options for server mode — creates and manages Brainy instances directly.
|
|
87
|
+
* Use `@soulcraft/sdk/server` entry point.
|
|
88
|
+
*/
|
|
89
|
+
export interface ServerSDKOptions extends SDKOptions {
|
|
90
|
+
mode: 'server';
|
|
91
|
+
brainy: {
|
|
92
|
+
storage: 'filesystem' | 'mmap-filesystem';
|
|
93
|
+
dataPath: string;
|
|
94
|
+
instances: {
|
|
95
|
+
strategy: InstanceStrategy;
|
|
96
|
+
/** For per-scope: custom key function called with (userId, workspaceId). */
|
|
97
|
+
scopeKey?: (userId: string, workspaceId: string) => string;
|
|
98
|
+
maxInstances?: number;
|
|
99
|
+
flushOnEvict?: boolean;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
auth: {
|
|
103
|
+
clientId: string;
|
|
104
|
+
clientSecret: string;
|
|
105
|
+
sessionCacheTtlMs?: number;
|
|
106
|
+
sessionCacheMax?: number;
|
|
107
|
+
};
|
|
108
|
+
license: {
|
|
109
|
+
/** Path to .soulcraft.json file. Defaults to ./.soulcraft.json. */
|
|
110
|
+
activationFile?: string;
|
|
111
|
+
portalUrl?: string;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Optional Hall real-time communication configuration.
|
|
115
|
+
* When present, the SDK initializes a HallServer and exposes it as sdk.hall.
|
|
116
|
+
* Requires @soulcraft/hall to be installed.
|
|
117
|
+
*/
|
|
118
|
+
hall?: {
|
|
119
|
+
/** Public IP address announced in WebRTC ICE candidates. Required in production. */
|
|
120
|
+
publicIp: string;
|
|
121
|
+
/** UDP port range start for ICE candidates (default: 40000). */
|
|
122
|
+
portMin?: number;
|
|
123
|
+
/** UDP port range end for ICE candidates (default: 49999). */
|
|
124
|
+
portMax?: number;
|
|
125
|
+
/** TURN server URL, e.g. "turn:hall.soulcraft.com:3478". */
|
|
126
|
+
turnUrl?: string;
|
|
127
|
+
/** TURN credentials username (static; use generateTurnCredentials for per-peer creds). */
|
|
128
|
+
turnUsername?: string;
|
|
129
|
+
/** TURN credentials password (static). */
|
|
130
|
+
turnPassword?: string;
|
|
131
|
+
/** S3 bucket name for recording uploads. */
|
|
132
|
+
recordingBucket?: string;
|
|
133
|
+
/** Deepgram API key for real-time transcription. */
|
|
134
|
+
deepgramApiKey?: string;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @description Options for client mode — connects to a running SDK server over a transport.
|
|
139
|
+
* Use `@soulcraft/sdk/client` entry point.
|
|
140
|
+
*/
|
|
141
|
+
export interface ClientSDKOptions extends SDKOptions {
|
|
142
|
+
mode: 'client';
|
|
143
|
+
transport: 'http' | 'ws' | 'sse';
|
|
144
|
+
baseUrl: string;
|
|
145
|
+
/** Auth strategy: session cookies (same-origin) or a Bearer capability token. */
|
|
146
|
+
auth?: 'cookie' | {
|
|
147
|
+
token: string;
|
|
148
|
+
};
|
|
149
|
+
/** Request timeout in ms. Defaults to 30 000. */
|
|
150
|
+
timeoutMs?: number;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,wEAAwE;AACxE,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAA;AAE1E,0CAA0C;AAC1C,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,YAAY,GAAG,WAAW,CAAA;AAEtE,uDAAuD;AACvD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,IAAI,GAAG,KAAK,GAAG,OAAO,CAAA;AAEvD;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,qFAAqF;IACrF,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;IAC7B,mFAAmF;IACnF,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAA;IACvB,mEAAmE;IACnE,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAA;IACjC,oEAAoE;IACpE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;IACzB,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAA;IA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|
+
* @description Core shared types for @soulcraft/sdk. Defines the top-level SoulcraftSDK
|
|
4
|
+
* interface and configuration options for both server and client modes. All module
|
|
5
|
+
* namespaces (brainy, vfs, auth, etc.) hang off of SoulcraftSDK.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|