@rkat/web 0.4.13 → 0.5.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.
@@ -112,7 +112,7 @@ export class IntoUnderlyingSource {
112
112
  if (Symbol.dispose) IntoUnderlyingSource.prototype[Symbol.dispose] = IntoUnderlyingSource.prototype.free;
113
113
 
114
114
  /**
115
- * Append runtime system context to a direct session handle.
115
+ * Append runtime system context to a browser session handle.
116
116
  * @param {number} handle
117
117
  * @param {string} request_json
118
118
  * @returns {any}
@@ -148,11 +148,8 @@ export function close_subscription(handle) {
148
148
  /**
149
149
  * Create a session from a mobpack + config.
150
150
  *
151
- * Routes through `AgentFactory::build_agent()` with override-first
152
- * resource injection same pipeline as all other meerkat surfaces.
153
- *
154
- * `config_json`: `{ "model": "...", "api_key": "sk-...", "max_tokens"?: N,
155
- * "comms_name"?: "...", "host_mode"?: true }`
151
+ * Allocates a real session through the initialized runtime-backed session
152
+ * service, then returns a browser-local session handle for convenience.
156
153
  * @param {Uint8Array} mobpack_bytes
157
154
  * @param {string} config_json
158
155
  * @returns {number}
@@ -170,12 +167,7 @@ export function create_session(mobpack_bytes, config_json) {
170
167
  }
171
168
 
172
169
  /**
173
- * Create a session without a mobpack — for standalone agent use.
174
- *
175
- * `config_json`: `{ "model": "...", "api_key": "sk-...", "system_prompt"?: "...",
176
- * "max_tokens"?: N, "additional_instructions"?: ["..."] }`
177
- *
178
- * Uses `register_tool_callback` tools if any were registered before this call.
170
+ * Create a standalone session through initialized runtime state.
179
171
  * @param {string} config_json
180
172
  * @returns {number}
181
173
  */
@@ -189,6 +181,19 @@ export function create_session_simple(config_json) {
189
181
  return ret[0] >>> 0;
190
182
  }
191
183
 
184
+ /**
185
+ * Tear down the embedded runtime and release all local handles/subscriptions.
186
+ *
187
+ * Existing `Session`, `Mob`, and subscription handles become invalid after
188
+ * this call.
189
+ */
190
+ export function destroy_runtime() {
191
+ const ret = wasm.destroy_runtime();
192
+ if (ret[1]) {
193
+ throw takeFromExternrefTable0(ret[0]);
194
+ }
195
+ }
196
+
192
197
  /**
193
198
  * Remove a session.
194
199
  * @param {number} handle
@@ -374,10 +379,40 @@ export function mob_flow_status(mob_id, run_id) {
374
379
  return ret;
375
380
  }
376
381
 
382
+ /**
383
+ * Force-cancel an active mob member turn.
384
+ * @param {string} mob_id
385
+ * @param {string} meerkat_id
386
+ * @returns {Promise<void>}
387
+ */
388
+ export function mob_force_cancel(mob_id, meerkat_id) {
389
+ const ptr0 = passStringToWasm0(mob_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
390
+ const len0 = WASM_VECTOR_LEN;
391
+ const ptr1 = passStringToWasm0(meerkat_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
392
+ const len1 = WASM_VECTOR_LEN;
393
+ const ret = wasm.mob_force_cancel(ptr0, len0, ptr1, len1);
394
+ return ret;
395
+ }
396
+
397
+ /**
398
+ * Fork a short-lived helper from an existing member and return its terminal result.
399
+ * @param {string} mob_id
400
+ * @param {string} request_json
401
+ * @returns {Promise<any>}
402
+ */
403
+ export function mob_fork_helper(mob_id, request_json) {
404
+ const ptr0 = passStringToWasm0(mob_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
405
+ const len0 = WASM_VECTOR_LEN;
406
+ const ptr1 = passStringToWasm0(request_json, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
407
+ const len1 = WASM_VECTOR_LEN;
408
+ const ret = wasm.mob_fork_helper(ptr0, len0, ptr1, len1);
409
+ return ret;
410
+ }
411
+
377
412
  /**
378
413
  * Perform a lifecycle action on a mob.
379
414
  *
380
- * `action`: one of "stop", "resume", "complete", "destroy".
415
+ * `action`: one of "stop", "resume", "complete", "reset", "destroy".
381
416
  * @param {string} mob_id
382
417
  * @param {string} action
383
418
  * @returns {Promise<void>}
@@ -416,6 +451,41 @@ export function mob_list_members(mob_id) {
416
451
  return ret;
417
452
  }
418
453
 
454
+ /**
455
+ * Send external work to a spawned meerkat through the canonical member path.
456
+ *
457
+ * Returns a JSON-encoded delivery receipt.
458
+ * @param {string} mob_id
459
+ * @param {string} meerkat_id
460
+ * @param {string} request_json
461
+ * @returns {Promise<string>}
462
+ */
463
+ export function mob_member_send(mob_id, meerkat_id, request_json) {
464
+ const ptr0 = passStringToWasm0(mob_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
465
+ const len0 = WASM_VECTOR_LEN;
466
+ const ptr1 = passStringToWasm0(meerkat_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
467
+ const len1 = WASM_VECTOR_LEN;
468
+ const ptr2 = passStringToWasm0(request_json, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
469
+ const len2 = WASM_VECTOR_LEN;
470
+ const ret = wasm.mob_member_send(ptr0, len0, ptr1, len1, ptr2, len2);
471
+ return ret;
472
+ }
473
+
474
+ /**
475
+ * Read the current execution snapshot for a mob member.
476
+ * @param {string} mob_id
477
+ * @param {string} meerkat_id
478
+ * @returns {Promise<any>}
479
+ */
480
+ export function mob_member_status(mob_id, meerkat_id) {
481
+ const ptr0 = passStringToWasm0(mob_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
482
+ const len0 = WASM_VECTOR_LEN;
483
+ const ptr1 = passStringToWasm0(meerkat_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
484
+ const len1 = WASM_VECTOR_LEN;
485
+ const ret = wasm.mob_member_status(ptr0, len0, ptr1, len1);
486
+ return ret;
487
+ }
488
+
419
489
  /**
420
490
  * Subscribe to a mob member's session event stream.
421
491
  *
@@ -440,7 +510,7 @@ export function mob_member_subscribe(mob_id, meerkat_id) {
440
510
  /**
441
511
  * Retire and re-spawn a meerkat with the same profile.
442
512
  *
443
- * Returns JSON: `{ "meerkat_id", "status": "respawn_enqueued" }`
513
+ * Returns JSON result envelope with receipt.
444
514
  * @param {string} mob_id
445
515
  * @param {string} meerkat_id
446
516
  * @param {string | null} [initial_message]
@@ -493,42 +563,37 @@ export function mob_run_flow(mob_id, flow_id, params_json) {
493
563
  }
494
564
 
495
565
  /**
496
- * Send an external message to a spawned meerkat.
566
+ * Spawn one or more meerkats in a mob.
567
+ *
568
+ * `specs_json`: JSON array of `{ "profile": "...", "meerkat_id": "...", "initial_message"?: "...",
569
+ * "runtime_mode"?: "autonomous_host"|"turn_driven", "backend"?: "session"|"external" }`
497
570
  *
498
- * Returns the session ID of the session that handled the turn.
571
+ * Returns JSON array of results per spec.
499
572
  * @param {string} mob_id
500
- * @param {string} meerkat_id
501
- * @param {string} message
502
- * @returns {Promise<string>}
573
+ * @param {string} specs_json
574
+ * @returns {Promise<any>}
503
575
  */
504
- export function mob_send_message(mob_id, meerkat_id, message) {
576
+ export function mob_spawn(mob_id, specs_json) {
505
577
  const ptr0 = passStringToWasm0(mob_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
506
578
  const len0 = WASM_VECTOR_LEN;
507
- const ptr1 = passStringToWasm0(meerkat_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
579
+ const ptr1 = passStringToWasm0(specs_json, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
508
580
  const len1 = WASM_VECTOR_LEN;
509
- const ptr2 = passStringToWasm0(message, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
510
- const len2 = WASM_VECTOR_LEN;
511
- const ret = wasm.mob_send_message(ptr0, len0, ptr1, len1, ptr2, len2);
581
+ const ret = wasm.mob_spawn(ptr0, len0, ptr1, len1);
512
582
  return ret;
513
583
  }
514
584
 
515
585
  /**
516
- * Spawn one or more meerkats in a mob.
517
- *
518
- * `specs_json`: JSON array of `{ "profile": "...", "meerkat_id": "...", "initial_message"?: "...",
519
- * "runtime_mode"?: "autonomous_host"|"turn_driven", "backend"?: "subagent"|"external" }`
520
- *
521
- * Returns JSON array of results per spec.
586
+ * Spawn a short-lived helper and return its terminal result.
522
587
  * @param {string} mob_id
523
- * @param {string} specs_json
588
+ * @param {string} request_json
524
589
  * @returns {Promise<any>}
525
590
  */
526
- export function mob_spawn(mob_id, specs_json) {
591
+ export function mob_spawn_helper(mob_id, request_json) {
527
592
  const ptr0 = passStringToWasm0(mob_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
528
593
  const len0 = WASM_VECTOR_LEN;
529
- const ptr1 = passStringToWasm0(specs_json, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
594
+ const ptr1 = passStringToWasm0(request_json, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
530
595
  const len1 = WASM_VECTOR_LEN;
531
- const ret = wasm.mob_spawn(ptr0, len0, ptr1, len1);
596
+ const ret = wasm.mob_spawn_helper(ptr0, len0, ptr1, len1);
532
597
  return ret;
533
598
  }
534
599
 
@@ -583,6 +648,42 @@ export function mob_unwire(mob_id, a, b) {
583
648
  return ret;
584
649
  }
585
650
 
651
+ /**
652
+ * Unwire a local member from a local or external peer target.
653
+ * @param {string} mob_id
654
+ * @param {string} member
655
+ * @param {string} peer_json
656
+ * @returns {Promise<void>}
657
+ */
658
+ export function mob_unwire_peer(mob_id, member, peer_json) {
659
+ const ptr0 = passStringToWasm0(mob_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
660
+ const len0 = WASM_VECTOR_LEN;
661
+ const ptr1 = passStringToWasm0(member, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
662
+ const len1 = WASM_VECTOR_LEN;
663
+ const ptr2 = passStringToWasm0(peer_json, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
664
+ const len2 = WASM_VECTOR_LEN;
665
+ const ret = wasm.mob_unwire_peer(ptr0, len0, ptr1, len1, ptr2, len2);
666
+ return ret;
667
+ }
668
+
669
+ /**
670
+ * Unwire a local meerkat from a local or external peer target.
671
+ * @param {string} mob_id
672
+ * @param {string} local
673
+ * @param {string} target_json
674
+ * @returns {Promise<void>}
675
+ */
676
+ export function mob_unwire_target(mob_id, local, target_json) {
677
+ const ptr0 = passStringToWasm0(mob_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
678
+ const len0 = WASM_VECTOR_LEN;
679
+ const ptr1 = passStringToWasm0(local, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
680
+ const len1 = WASM_VECTOR_LEN;
681
+ const ptr2 = passStringToWasm0(target_json, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
682
+ const len2 = WASM_VECTOR_LEN;
683
+ const ret = wasm.mob_unwire_target(ptr0, len0, ptr1, len1, ptr2, len2);
684
+ return ret;
685
+ }
686
+
586
687
  /**
587
688
  * Wire bidirectional trust between two meerkats.
588
689
  * @param {string} mob_id
@@ -601,6 +702,42 @@ export function mob_wire(mob_id, a, b) {
601
702
  return ret;
602
703
  }
603
704
 
705
+ /**
706
+ * Wire a local member to a local or external peer target.
707
+ * @param {string} mob_id
708
+ * @param {string} member
709
+ * @param {string} peer_json
710
+ * @returns {Promise<void>}
711
+ */
712
+ export function mob_wire_peer(mob_id, member, peer_json) {
713
+ const ptr0 = passStringToWasm0(mob_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
714
+ const len0 = WASM_VECTOR_LEN;
715
+ const ptr1 = passStringToWasm0(member, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
716
+ const len1 = WASM_VECTOR_LEN;
717
+ const ptr2 = passStringToWasm0(peer_json, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
718
+ const len2 = WASM_VECTOR_LEN;
719
+ const ret = wasm.mob_wire_peer(ptr0, len0, ptr1, len1, ptr2, len2);
720
+ return ret;
721
+ }
722
+
723
+ /**
724
+ * Wire a local meerkat to a local or external peer target.
725
+ * @param {string} mob_id
726
+ * @param {string} local
727
+ * @param {string} target_json
728
+ * @returns {Promise<void>}
729
+ */
730
+ export function mob_wire_target(mob_id, local, target_json) {
731
+ const ptr0 = passStringToWasm0(mob_id, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
732
+ const len0 = WASM_VECTOR_LEN;
733
+ const ptr1 = passStringToWasm0(local, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
734
+ const len1 = WASM_VECTOR_LEN;
735
+ const ptr2 = passStringToWasm0(target_json, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
736
+ const len2 = WASM_VECTOR_LEN;
737
+ const ret = wasm.mob_wire_target(ptr0, len0, ptr1, len1, ptr2, len2);
738
+ return ret;
739
+ }
740
+
604
741
  /**
605
742
  * Drain and return all pending agent events from the last turn(s).
606
743
  *
@@ -663,13 +800,13 @@ export function poll_subscription(handle) {
663
800
  /**
664
801
  * Register a fire-and-forget tool from JavaScript.
665
802
  *
666
- * Call this BEFORE `init_runtime` or `init_runtime_from_config`.
803
+ * Requires initialized runtime state.
667
804
  * When the agent calls this tool, `dispatch()` returns `"acknowledged"`
668
805
  * immediately and the agent loop continues without waiting.
669
806
  *
670
807
  * The host should watch `ToolCallRequested` events in the event stream to
671
808
  * capture the tool call arguments and act on them asynchronously. Any
672
- * response (e.g. human approval) should be sent back via `mob_send_message`.
809
+ * response (e.g. human approval) should be sent back via `mob_member_send`.
673
810
  *
674
811
  * Example (JS):
675
812
  * ```js
@@ -706,7 +843,7 @@ export function register_js_tool(name, description, schema_json) {
706
843
  /**
707
844
  * Register a tool implementation from JavaScript.
708
845
  *
709
- * Call this BEFORE `init_runtime` or `init_runtime_from_config`.
846
+ * Requires initialized runtime state.
710
847
  * The `callback` receives a JSON string of tool arguments and must return
711
848
  * a `Promise<string>` resolving to JSON `{"content": "...", "is_error": false}`.
712
849
  *
@@ -753,12 +890,12 @@ export function runtime_version() {
753
890
  }
754
891
 
755
892
  /**
756
- * Run a turn through the real meerkat agent loop via AgentFactory::build_agent().
893
+ * Run a turn through the runtime-backed session service.
757
894
  *
758
895
  * Returns JSON: `{ "text", "usage", "status", "session_id", "turns", "tool_calls" }`
759
896
  *
760
897
  * Convention: always resolves (Ok). Check `status` field for "completed" vs "failed".
761
- * Only rejects (Err) for infrastructure errors (session not found, build failure).
898
+ * Only rejects (Err) for infrastructure errors (session not found, busy, etc).
762
899
  * Agent-level errors (LLM failure, timeout) resolve with `status: "failed"` + `error` field.
763
900
  * @param {number} handle
764
901
  * @param {string} prompt
@@ -1262,17 +1399,17 @@ function __wbg_get_imports() {
1262
1399
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1263
1400
  },
1264
1401
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1265
- // Cast intrinsic for `Closure(Closure { dtor_idx: 1677, function: Function { arguments: [], shim_idx: 1678, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1402
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 1883, function: Function { arguments: [], shim_idx: 1884, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1266
1403
  const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__hd784b404a9939abd, wasm_bindgen__convert__closures_____invoke__ha3daf52f0a255ec1);
1267
1404
  return ret;
1268
1405
  },
1269
1406
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1270
- // Cast intrinsic for `Closure(Closure { dtor_idx: 4002, function: Function { arguments: [], shim_idx: 4003, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
1407
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 4227, function: Function { arguments: [], shim_idx: 4228, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
1271
1408
  const ret = makeClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h017fc47e7d3e6c2d, wasm_bindgen__convert__closures_____invoke__h33aeef803f4d26ad);
1272
1409
  return ret;
1273
1410
  },
1274
1411
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
1275
- // Cast intrinsic for `Closure(Closure { dtor_idx: 4018, function: Function { arguments: [Externref], shim_idx: 4019, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1412
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 4243, function: Function { arguments: [Externref], shim_idx: 4244, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1276
1413
  const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__hbb4473811cf816f9, wasm_bindgen__convert__closures_____invoke__hbef0706bd8d01ba3);
1277
1414
  return ret;
1278
1415
  },
Binary file
@@ -5,6 +5,7 @@ export const append_system_context: (a: number, b: number, c: number) => [number
5
5
  export const close_subscription: (a: number) => [number, number];
6
6
  export const create_session: (a: number, b: number, c: number, d: number) => [number, number, number];
7
7
  export const create_session_simple: (a: number, b: number) => [number, number, number];
8
+ export const destroy_runtime: () => [number, number];
8
9
  export const destroy_session: (a: number) => [number, number];
9
10
  export const get_session_state: (a: number) => [number, number, number, number];
10
11
  export const init_runtime: (a: number, b: number, c: number, d: number) => [number, number, number];
@@ -15,19 +16,27 @@ export const mob_cancel_flow: (a: number, b: number, c: number, d: number) => an
15
16
  export const mob_create: (a: number, b: number) => any;
16
17
  export const mob_events: (a: number, b: number, c: number, d: number) => any;
17
18
  export const mob_flow_status: (a: number, b: number, c: number, d: number) => any;
19
+ export const mob_force_cancel: (a: number, b: number, c: number, d: number) => any;
20
+ export const mob_fork_helper: (a: number, b: number, c: number, d: number) => any;
18
21
  export const mob_lifecycle: (a: number, b: number, c: number, d: number) => any;
19
22
  export const mob_list: () => any;
20
23
  export const mob_list_members: (a: number, b: number) => any;
24
+ export const mob_member_send: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
25
+ export const mob_member_status: (a: number, b: number, c: number, d: number) => any;
21
26
  export const mob_member_subscribe: (a: number, b: number, c: number, d: number) => any;
22
27
  export const mob_respawn: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
23
28
  export const mob_retire: (a: number, b: number, c: number, d: number) => any;
24
29
  export const mob_run_flow: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
25
- export const mob_send_message: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
26
30
  export const mob_spawn: (a: number, b: number, c: number, d: number) => any;
31
+ export const mob_spawn_helper: (a: number, b: number, c: number, d: number) => any;
27
32
  export const mob_status: (a: number, b: number) => any;
28
33
  export const mob_subscribe_events: (a: number, b: number) => any;
29
34
  export const mob_unwire: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
35
+ export const mob_unwire_peer: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
36
+ export const mob_unwire_target: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
30
37
  export const mob_wire: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
38
+ export const mob_wire_peer: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
39
+ export const mob_wire_target: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
31
40
  export const poll_events: (a: number) => [number, number, number, number];
32
41
  export const poll_subscription: (a: number) => [number, number, number, number];
33
42
  export const register_js_tool: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
package/wasm/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "collaborators": [
5
5
  "Luka Crnkovic-Friis"
6
6
  ],
7
- "version": "0.4.13",
7
+ "version": "0.5.0",
8
8
  "license": "MIT OR Apache-2.0",
9
9
  "repository": {
10
10
  "type": "git",