@rkat/web 0.4.1 → 0.4.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.
package/dist/runtime.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Mob } from './mob.js';
2
2
  import { Session } from './session.js';
3
3
  /** Expected WASM runtime version — must match the compiled binary. */
4
- const EXPECTED_VERSION = '0.4.1';
4
+ const EXPECTED_VERSION = '0.4.2';
5
5
  /**
6
6
  * Convert a camelCase config object to the snake_case expected by WASM.
7
7
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rkat/web",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Browser SDK for Meerkat agent runtime (WASM)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/proxy/index.mjs CHANGED
@@ -107,8 +107,8 @@ export function createProxyHandler(provider, opts = {}) {
107
107
  // Copy headers, inject auth
108
108
  const headers = new Headers();
109
109
  for (const [key, value] of req.headers) {
110
- // Skip hop-by-hop and host headers
111
- if (['host', 'connection', 'keep-alive', 'transfer-encoding'].includes(key.toLowerCase())) continue;
110
+ // Skip hop-by-hop, host, encoding, and browser-origin headers
111
+ if (['host', 'connection', 'keep-alive', 'transfer-encoding', 'accept-encoding', 'origin', 'referer'].includes(key.toLowerCase())) continue;
112
112
  headers.set(key, value);
113
113
  }
114
114
  config.injectAuth(headers, apiKey);
@@ -129,6 +129,8 @@ export function createProxyHandler(provider, opts = {}) {
129
129
  // Build response headers: upstream headers + CORS
130
130
  const respHeaders = new Headers();
131
131
  for (const [key, value] of upstream.headers) {
132
+ // Strip encoding headers — we don't forward compression negotiation
133
+ if (['content-encoding', 'transfer-encoding'].includes(key.toLowerCase())) continue;
132
134
  respHeaders.set(key, value);
133
135
  }
134
136
  for (const [key, value] of Object.entries(cors)) {
@@ -0,0 +1,390 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * The `ReadableStreamType` enum.
5
+ *
6
+ * *This API requires the following crate features to be activated: `ReadableStreamType`*
7
+ */
8
+
9
+ type ReadableStreamType = "bytes";
10
+
11
+ export class IntoUnderlyingByteSource {
12
+ private constructor();
13
+ free(): void;
14
+ [Symbol.dispose](): void;
15
+ cancel(): void;
16
+ pull(controller: ReadableByteStreamController): Promise<any>;
17
+ start(controller: ReadableByteStreamController): void;
18
+ readonly autoAllocateChunkSize: number;
19
+ readonly type: ReadableStreamType;
20
+ }
21
+
22
+ export class IntoUnderlyingSink {
23
+ private constructor();
24
+ free(): void;
25
+ [Symbol.dispose](): void;
26
+ abort(reason: any): Promise<any>;
27
+ close(): Promise<any>;
28
+ write(chunk: any): Promise<any>;
29
+ }
30
+
31
+ export class IntoUnderlyingSource {
32
+ private constructor();
33
+ free(): void;
34
+ [Symbol.dispose](): void;
35
+ cancel(): void;
36
+ pull(controller: ReadableStreamDefaultController): Promise<any>;
37
+ }
38
+
39
+ /**
40
+ * Clear all registered tool callbacks.
41
+ */
42
+ export function clear_tool_callbacks(): void;
43
+
44
+ /**
45
+ * Close a subscription and free resources.
46
+ */
47
+ export function close_subscription(handle: number): void;
48
+
49
+ /**
50
+ * Create a session from a mobpack + config.
51
+ *
52
+ * Routes through `AgentFactory::build_agent()` with override-first
53
+ * resource injection — same pipeline as all other meerkat surfaces.
54
+ *
55
+ * `config_json`: `{ "model": "...", "api_key": "sk-...", "max_tokens"?: N,
56
+ * "comms_name"?: "...", "host_mode"?: true }`
57
+ */
58
+ export function create_session(mobpack_bytes: Uint8Array, config_json: string): number;
59
+
60
+ /**
61
+ * Create a session without a mobpack — for standalone agent use.
62
+ *
63
+ * `config_json`: `{ "model": "...", "api_key": "sk-...", "system_prompt"?: "...",
64
+ * "max_tokens"?: N, "additional_instructions"?: ["..."] }`
65
+ *
66
+ * Uses `register_tool_callback` tools if any were registered before this call.
67
+ */
68
+ export function create_session_simple(config_json: string): number;
69
+
70
+ /**
71
+ * Remove a session.
72
+ */
73
+ export function destroy_session(handle: number): void;
74
+
75
+ /**
76
+ * Get current session state.
77
+ */
78
+ export function get_session_state(handle: number): string;
79
+
80
+ /**
81
+ * Primary bootstrap: parse a mobpack and create service infrastructure.
82
+ *
83
+ * `mobpack_bytes`: tar.gz mobpack archive.
84
+ * `credentials_json`: `{ "api_key": "sk-...", "anthropic_api_key"?: "...", "openai_api_key"?: "...", "gemini_api_key"?: "...", "model"?: "claude-sonnet-4-5" }`
85
+ *
86
+ * Stores an `EphemeralSessionService<FactoryAgentBuilder>` and a `MobMcpState`
87
+ * in a `thread_local! RuntimeState` for subsequent mob/comms calls.
88
+ */
89
+ export function init_runtime(mobpack_bytes: Uint8Array, credentials_json: string): any;
90
+
91
+ /**
92
+ * Advanced bare-bones bootstrap without a mobpack.
93
+ *
94
+ * `config_json`: `{ "api_key"?: "sk-...", "anthropic_api_key"?: "...", "openai_api_key"?: "...", "gemini_api_key"?: "...", "model"?: "claude-sonnet-4-5", "max_sessions"?: 64 }`
95
+ */
96
+ export function init_runtime_from_config(config_json: string): any;
97
+
98
+ /**
99
+ * Inspect a mobpack without creating a session.
100
+ */
101
+ export function inspect_mobpack(mobpack_bytes: Uint8Array): string;
102
+
103
+ /**
104
+ * Cancel an in-flight flow run.
105
+ */
106
+ export function mob_cancel_flow(mob_id: string, run_id: string): Promise<void>;
107
+
108
+ /**
109
+ * Create a new mob from a definition JSON.
110
+ *
111
+ * Returns the mob_id as a string.
112
+ */
113
+ export function mob_create(definition_json: string): Promise<any>;
114
+
115
+ /**
116
+ * Fetch mob events.
117
+ *
118
+ * Returns JSON array of mob events.
119
+ *
120
+ * Note: `after_cursor` is u32 at the JS boundary (wasm_bindgen limitation),
121
+ * internally widened to u64. Cursors beyond 4B are not supported via this export.
122
+ */
123
+ export function mob_events(mob_id: string, after_cursor: number, limit: number): Promise<any>;
124
+
125
+ /**
126
+ * Read flow run status.
127
+ *
128
+ * Returns JSON with run state and ledgers, or null if not found.
129
+ */
130
+ export function mob_flow_status(mob_id: string, run_id: string): Promise<any>;
131
+
132
+ /**
133
+ * Inject a message and subscribe for interaction-scoped events.
134
+ *
135
+ * Returns JSON: `{ "interaction_id": "..." }`
136
+ */
137
+ export function mob_inject_and_subscribe(mob_id: string, meerkat_id: string, message: string): Promise<any>;
138
+
139
+ /**
140
+ * Perform a lifecycle action on a mob.
141
+ *
142
+ * `action`: one of "stop", "resume", "complete", "destroy".
143
+ */
144
+ export function mob_lifecycle(mob_id: string, action: string): Promise<void>;
145
+
146
+ /**
147
+ * List all mobs.
148
+ *
149
+ * Returns JSON array of `{ mob_id, state }`.
150
+ */
151
+ export function mob_list(): Promise<any>;
152
+
153
+ /**
154
+ * List all members in a mob.
155
+ *
156
+ * Returns JSON array of roster entries.
157
+ */
158
+ export function mob_list_members(mob_id: string): Promise<any>;
159
+
160
+ /**
161
+ * Subscribe to a mob member's session event stream.
162
+ *
163
+ * Returns a subscription handle. Use `poll_subscription(handle)` to drain
164
+ * buffered events. Each call returns all events since the last poll.
165
+ *
166
+ * The subscription captures ALL agent activity: text deltas, tool calls
167
+ * (including comms send_message/peers), turn completions, etc.
168
+ */
169
+ export function mob_member_subscribe(mob_id: string, meerkat_id: string): Promise<number>;
170
+
171
+ /**
172
+ * Retire and re-spawn a meerkat with the same profile.
173
+ *
174
+ * Returns JSON: `{ "meerkat_id", "status": "respawn_enqueued" }`
175
+ */
176
+ export function mob_respawn(mob_id: string, meerkat_id: string, initial_message?: string | null): Promise<any>;
177
+
178
+ /**
179
+ * Retire a meerkat from a mob.
180
+ */
181
+ export function mob_retire(mob_id: string, meerkat_id: string): Promise<void>;
182
+
183
+ /**
184
+ * Start a configured flow run.
185
+ *
186
+ * Returns the run_id as a string.
187
+ */
188
+ export function mob_run_flow(mob_id: string, flow_id: string, params_json: string): Promise<any>;
189
+
190
+ /**
191
+ * Send an external message to a spawned meerkat.
192
+ */
193
+ export function mob_send_message(mob_id: string, meerkat_id: string, message: string): Promise<void>;
194
+
195
+ /**
196
+ * Spawn one or more meerkats in a mob.
197
+ *
198
+ * `specs_json`: JSON array of `{ "profile": "...", "meerkat_id": "...", "initial_message"?: "...",
199
+ * "runtime_mode"?: "autonomous_host"|"turn_driven", "backend"?: "subagent"|"external" }`
200
+ *
201
+ * Returns JSON array of results per spec.
202
+ */
203
+ export function mob_spawn(mob_id: string, specs_json: string): Promise<any>;
204
+
205
+ /**
206
+ * Get the status of a mob.
207
+ *
208
+ * Returns JSON with the mob state.
209
+ */
210
+ export function mob_status(mob_id: string): Promise<any>;
211
+
212
+ /**
213
+ * Subscribe to mob-wide events (all members, continuously updated).
214
+ *
215
+ * Returns a subscription handle. Use `poll_subscription(handle)` to drain
216
+ * buffered events. Each call returns all events since the last poll.
217
+ *
218
+ * Unlike `mob_member_subscribe` which streams a single member's agent events,
219
+ * this streams [`AttributedEvent`]s tagged with source meerkat_id and profile
220
+ * for every member in the mob, automatically tracking roster changes.
221
+ */
222
+ export function mob_subscribe_events(mob_id: string): Promise<number>;
223
+
224
+ /**
225
+ * Unwire bidirectional trust between two meerkats.
226
+ */
227
+ export function mob_unwire(mob_id: string, a: string, b: string): Promise<void>;
228
+
229
+ /**
230
+ * Wire bidirectional trust between two meerkats.
231
+ */
232
+ export function mob_wire(mob_id: string, a: string, b: string): Promise<void>;
233
+
234
+ /**
235
+ * Drain and return all pending agent events from the last turn(s).
236
+ *
237
+ * Returns a JSON array of `AgentEvent` objects. Each call drains the buffer;
238
+ * subsequent calls return `[]` until the next `start_turn` produces more events.
239
+ */
240
+ export function poll_events(handle: number): string;
241
+
242
+ /**
243
+ * Poll a subscription for new events.
244
+ *
245
+ * Returns a JSON array of event objects. Drains all buffered events
246
+ * since the last poll. Non-blocking: returns `[]` if no new events.
247
+ *
248
+ * For per-member subscriptions (`mob_member_subscribe`), returns
249
+ * `EventEnvelope<AgentEvent>` objects. For mob-wide subscriptions
250
+ * (`mob_subscribe_events`), returns `AttributedEvent` objects with
251
+ * `source`, `profile`, and `envelope` fields.
252
+ */
253
+ export function poll_subscription(handle: number): string;
254
+
255
+ /**
256
+ * Register a tool implementation from JavaScript.
257
+ *
258
+ * Call this BEFORE `init_runtime` or `init_runtime_from_config`.
259
+ * The `callback` receives a JSON string of tool arguments and must return
260
+ * a `Promise<string>` resolving to JSON `{"content": "...", "is_error": false}`.
261
+ *
262
+ * Example (JS):
263
+ * ```js
264
+ * register_tool_callback("shell", '{"type":"object","properties":{"command":{"type":"string"}},"required":["command"]}', shellFn);
265
+ * ```
266
+ */
267
+ export function register_tool_callback(name: string, description: string, schema_json: string, callback: any): void;
268
+
269
+ /**
270
+ * Return the crate version embedded at compile time.
271
+ *
272
+ * Used by the `@rkat/web` TypeScript wrapper to validate that the JS glue
273
+ * and the WASM binary were built from the same version.
274
+ */
275
+ export function runtime_version(): string;
276
+
277
+ /**
278
+ * Run a turn through the real meerkat agent loop via AgentFactory::build_agent().
279
+ *
280
+ * Returns JSON: `{ "text", "usage", "status", "session_id", "turns", "tool_calls" }`
281
+ *
282
+ * Convention: always resolves (Ok). Check `status` field for "completed" vs "failed".
283
+ * Only rejects (Err) for infrastructure errors (session not found, build failure).
284
+ * Agent-level errors (LLM failure, timeout) resolve with `status: "failed"` + `error` field.
285
+ */
286
+ export function start_turn(handle: number, prompt: string, options_json: string): Promise<any>;
287
+
288
+ /**
289
+ * Entry point invoked by JavaScript in a worker.
290
+ */
291
+ export function task_worker_entry_point(ptr: number): void;
292
+
293
+ /**
294
+ * Wire bidirectional comms trust between meerkats in DIFFERENT mobs.
295
+ *
296
+ * Unlike `mob_wire` (which is intra-mob), this establishes peer trust across
297
+ * mob boundaries by accessing each member's comms runtime through the shared
298
+ * session service. Both members must have comms enabled.
299
+ */
300
+ export function wire_cross_mob(mob_a: string, meerkat_a: string, mob_b: string, meerkat_b: string): Promise<void>;
301
+
302
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
303
+
304
+ export interface InitOutput {
305
+ readonly memory: WebAssembly.Memory;
306
+ readonly close_subscription: (a: number) => [number, number];
307
+ readonly create_session: (a: number, b: number, c: number, d: number) => [number, number, number];
308
+ readonly create_session_simple: (a: number, b: number) => [number, number, number];
309
+ readonly destroy_session: (a: number) => [number, number];
310
+ readonly get_session_state: (a: number) => [number, number, number, number];
311
+ readonly init_runtime: (a: number, b: number, c: number, d: number) => [number, number, number];
312
+ readonly init_runtime_from_config: (a: number, b: number) => [number, number, number];
313
+ readonly inspect_mobpack: (a: number, b: number) => [number, number, number, number];
314
+ readonly mob_cancel_flow: (a: number, b: number, c: number, d: number) => any;
315
+ readonly mob_create: (a: number, b: number) => any;
316
+ readonly mob_events: (a: number, b: number, c: number, d: number) => any;
317
+ readonly mob_flow_status: (a: number, b: number, c: number, d: number) => any;
318
+ readonly mob_inject_and_subscribe: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
319
+ readonly mob_lifecycle: (a: number, b: number, c: number, d: number) => any;
320
+ readonly mob_list: () => any;
321
+ readonly mob_list_members: (a: number, b: number) => any;
322
+ readonly mob_member_subscribe: (a: number, b: number, c: number, d: number) => any;
323
+ readonly mob_respawn: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
324
+ readonly mob_retire: (a: number, b: number, c: number, d: number) => any;
325
+ readonly mob_run_flow: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
326
+ readonly mob_send_message: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
327
+ readonly mob_spawn: (a: number, b: number, c: number, d: number) => any;
328
+ readonly mob_status: (a: number, b: number) => any;
329
+ readonly mob_subscribe_events: (a: number, b: number) => any;
330
+ readonly mob_unwire: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
331
+ readonly mob_wire: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
332
+ readonly poll_events: (a: number) => [number, number, number, number];
333
+ readonly poll_subscription: (a: number) => [number, number, number, number];
334
+ readonly register_tool_callback: (a: number, b: number, c: number, d: number, e: number, f: number, g: any) => [number, number];
335
+ readonly runtime_version: () => [number, number];
336
+ readonly start_turn: (a: number, b: number, c: number, d: number, e: number) => any;
337
+ readonly wire_cross_mob: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => any;
338
+ readonly clear_tool_callbacks: () => void;
339
+ readonly __wbg_intounderlyingsource_free: (a: number, b: number) => void;
340
+ readonly intounderlyingsource_cancel: (a: number) => void;
341
+ readonly intounderlyingsource_pull: (a: number, b: any) => any;
342
+ readonly __wbg_intounderlyingsink_free: (a: number, b: number) => void;
343
+ readonly intounderlyingsink_abort: (a: number, b: any) => any;
344
+ readonly intounderlyingsink_close: (a: number) => any;
345
+ readonly intounderlyingsink_write: (a: number, b: any) => any;
346
+ readonly __wbg_intounderlyingbytesource_free: (a: number, b: number) => void;
347
+ readonly intounderlyingbytesource_autoAllocateChunkSize: (a: number) => number;
348
+ readonly intounderlyingbytesource_cancel: (a: number) => void;
349
+ readonly intounderlyingbytesource_pull: (a: number, b: any) => any;
350
+ readonly intounderlyingbytesource_start: (a: number, b: any) => void;
351
+ readonly intounderlyingbytesource_type: (a: number) => number;
352
+ readonly task_worker_entry_point: (a: number) => [number, number];
353
+ readonly wasm_bindgen__closure__destroy__hb87c6a2b7693073e: (a: number, b: number) => void;
354
+ readonly wasm_bindgen__closure__destroy__h17256c949385a6eb: (a: number, b: number) => void;
355
+ readonly wasm_bindgen__closure__destroy__h824973ba58a55617: (a: number, b: number) => void;
356
+ readonly wasm_bindgen__convert__closures_____invoke__h4c4b72406261edf7: (a: number, b: number, c: any, d: any) => void;
357
+ readonly wasm_bindgen__convert__closures_____invoke__hf6fd50a67b85890f: (a: number, b: number, c: any) => void;
358
+ readonly wasm_bindgen__convert__closures_____invoke__hc484b96269102350: (a: number, b: number) => void;
359
+ readonly wasm_bindgen__convert__closures_____invoke__h308d3c0b30a9202d: (a: number, b: number) => void;
360
+ readonly __wbindgen_malloc_command_export: (a: number, b: number) => number;
361
+ readonly __wbindgen_realloc_command_export: (a: number, b: number, c: number, d: number) => number;
362
+ readonly __wbindgen_exn_store_command_export: (a: number) => void;
363
+ readonly __externref_table_alloc_command_export: () => number;
364
+ readonly __wbindgen_externrefs: WebAssembly.Table;
365
+ readonly __wbindgen_free_command_export: (a: number, b: number, c: number) => void;
366
+ readonly __externref_table_dealloc_command_export: (a: number) => void;
367
+ readonly __wbindgen_start: () => void;
368
+ }
369
+
370
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
371
+
372
+ /**
373
+ * Instantiates the given `module`, which can either be bytes or
374
+ * a precompiled `WebAssembly.Module`.
375
+ *
376
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
377
+ *
378
+ * @returns {InitOutput}
379
+ */
380
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
381
+
382
+ /**
383
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
384
+ * for everything else, calls `WebAssembly.instantiate` directly.
385
+ *
386
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
387
+ *
388
+ * @returns {Promise<InitOutput>}
389
+ */
390
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;