@rkat/web 0.6.33 → 0.7.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 (40) hide show
  1. package/dist/generated/auth.d.ts +1 -1
  2. package/dist/generated/auth.d.ts.map +1 -1
  3. package/dist/generated/auth.js +3 -1
  4. package/dist/generated/auth.js.map +1 -1
  5. package/dist/generated/events.d.ts +84 -29
  6. package/dist/generated/events.d.ts.map +1 -1
  7. package/dist/generated/events.js.map +1 -1
  8. package/dist/generated/mob.d.ts +12 -5
  9. package/dist/generated/mob.d.ts.map +1 -1
  10. package/dist/generated/runtime.d.ts +85 -0
  11. package/dist/generated/runtime.d.ts.map +1 -0
  12. package/dist/generated/runtime.js +40 -0
  13. package/dist/generated/runtime.js.map +1 -0
  14. package/dist/generated/session.d.ts +42 -0
  15. package/dist/generated/session.d.ts.map +1 -0
  16. package/dist/generated/session.js +2 -0
  17. package/dist/generated/session.js.map +1 -0
  18. package/dist/mob.d.ts +34 -19
  19. package/dist/mob.d.ts.map +1 -1
  20. package/dist/mob.js +144 -81
  21. package/dist/mob.js.map +1 -1
  22. package/dist/runtime.d.ts +16 -20
  23. package/dist/runtime.d.ts.map +1 -1
  24. package/dist/runtime.js +26 -16
  25. package/dist/runtime.js.map +1 -1
  26. package/dist/session.d.ts +44 -2
  27. package/dist/session.d.ts.map +1 -1
  28. package/dist/session.js +132 -34
  29. package/dist/session.js.map +1 -1
  30. package/dist/types.d.ts +92 -104
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/types.js +1 -3
  33. package/dist/types.js.map +1 -1
  34. package/package.json +1 -1
  35. package/wasm/.meerkat-wasm-build.json +3 -3
  36. package/wasm/meerkat_web_runtime.d.ts +114 -67
  37. package/wasm/meerkat_web_runtime.js +114 -125
  38. package/wasm/meerkat_web_runtime_bg.wasm +0 -0
  39. package/wasm/meerkat_web_runtime_bg.wasm.d.ts +41 -24
  40. package/wasm/package.json +1 -1
@@ -0,0 +1,40 @@
1
+ // Generated runtime bootstrap contracts for @rkat/web
2
+ // Source: tools/sdk-codegen/generate.py (generate_web_runtime_types)
3
+ /** Fail-closed parse guard for WASM `init_runtime*` output (K19/K21).
4
+ *
5
+ * Throws on anything that is not the `InitResult` contract — malformed init
6
+ * output must never be blind-cast into a success shape.
7
+ */
8
+ export function parseInitResult(json) {
9
+ let value;
10
+ try {
11
+ value = JSON.parse(json);
12
+ }
13
+ catch (err) {
14
+ throw new Error(`invalid InitResult: not JSON: ${String(err)}`);
15
+ }
16
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
17
+ throw new Error(`invalid InitResult: expected object, got: ${json}`);
18
+ }
19
+ const record = value;
20
+ if (record.status !== 'initialized') {
21
+ throw new Error(`invalid InitResult: status must be 'initialized': ${json}`);
22
+ }
23
+ if (typeof record.model !== 'string') {
24
+ throw new Error(`invalid InitResult: model must be a string: ${json}`);
25
+ }
26
+ if (!Array.isArray(record.providers) ||
27
+ !record.providers.every((provider) => typeof provider === 'string')) {
28
+ throw new Error(`invalid InitResult: providers must be a string array: ${json}`);
29
+ }
30
+ if (record.max_sessions !== undefined && typeof record.max_sessions !== 'number') {
31
+ throw new Error(`invalid InitResult: max_sessions must be a number: ${json}`);
32
+ }
33
+ return {
34
+ status: 'initialized',
35
+ model: record.model,
36
+ providers: record.providers,
37
+ max_sessions: record.max_sessions,
38
+ };
39
+ }
40
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/generated/runtime.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,qEAAqE;AAsFrE;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC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 /**
3
+ * Canonical run-result wire envelope (mirrors `meerkat_contracts::WireRunResult`,
4
+ * the same shape RPC's `turn/start` returns and the WASM `start_turn` export
5
+ * resolves with).
6
+ */
7
+ export interface WireRunResult {
8
+ session_id: SessionId;
9
+ session_ref?: string | null;
10
+ text: string;
11
+ turns: number;
12
+ tool_calls: number;
13
+ usage: Usage;
14
+ structured_output?: unknown;
15
+ extraction_error?: {
16
+ last_output: string;
17
+ attempts: number;
18
+ reason: string;
19
+ } | null;
20
+ schema_warnings?: SchemaWarning[] | null;
21
+ skill_diagnostics?: unknown;
22
+ /**
23
+ * Runtime-owned terminal cause for this turn (e.g. `budget_exhausted`).
24
+ * Present only when the turn terminated on a typed terminal condition.
25
+ */
26
+ terminal_cause_kind?: TurnTerminalCauseKind | null;
27
+ }
28
+ /**
29
+ * Runtime-backed state for a direct browser session façade. Mirrors the JSON
30
+ * envelope produced by the WASM `get_session_state` export.
31
+ */
32
+ export interface SessionState {
33
+ handle: number;
34
+ session_id: SessionId;
35
+ mob_id: string;
36
+ model: string;
37
+ usage: Usage;
38
+ message_count: number;
39
+ is_active: boolean;
40
+ last_assistant_text?: string | null;
41
+ }
42
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/generated/session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE1F;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,SAAS,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACpF,eAAe,CAAC,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;IACzC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACpD;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,SAAS,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/generated/session.ts"],"names":[],"mappings":""}
package/dist/mob.d.ts CHANGED
@@ -1,14 +1,13 @@
1
1
  import { EventSubscription } from './events.js';
2
2
  import type { AuthBindingRef, ContentInput, HandlingMode, SpawnSpec, SpawnResult, MobMember, MobPeerTarget, MobStatus, MobLifecycleAction, FlowStatus, AttributedEventItem, MemberEventItem, MobEvent, AppendSystemContextOptions, MobAppendSystemContextResult, RenderMetadata, ContentBlock, MemberDeliveryReceipt, MobRespawnResult, MobMemberSnapshot, MobHelperResult } from './types.js';
3
+ import type { MobLifecycleResult } from './generated/mob.js';
3
4
  interface MobWasmBindings {
4
5
  mob_spawn: (mobId: string, specs: string) => Promise<string>;
5
6
  mob_retire: (mobId: string, agentIdentity: string) => Promise<void>;
6
7
  mob_wire: (mobId: string, a: string, b: string) => Promise<void>;
7
8
  mob_unwire: (mobId: string, a: string, b: string) => Promise<void>;
8
- mob_wire_peer?: (mobId: string, member: string, peerJson: string) => Promise<void>;
9
- mob_unwire_peer?: (mobId: string, member: string, peerJson: string) => Promise<void>;
10
- mob_wire_target?: (mobId: string, member: string, peerJson: string) => Promise<void>;
11
- mob_unwire_target?: (mobId: string, member: string, peerJson: string) => Promise<void>;
9
+ mob_wire_peer: (mobId: string, member: string, peerJson: string) => Promise<void>;
10
+ mob_unwire_peer: (mobId: string, member: string, peerJson: string) => Promise<void>;
12
11
  mob_list_members: (mobId: string) => Promise<string>;
13
12
  mob_append_system_context: (mobId: string, agentIdentity: string, requestJson: string) => Promise<string>;
14
13
  mob_member_send: (mobId: string, agentIdentity: string, requestJson: string) => Promise<string>;
@@ -18,15 +17,15 @@ interface MobWasmBindings {
18
17
  mob_spawn_helper: (mobId: string, requestJson: string) => Promise<string>;
19
18
  mob_fork_helper: (mobId: string, requestJson: string) => Promise<string>;
20
19
  mob_status: (mobId: string) => Promise<string>;
21
- mob_lifecycle: (mobId: string, action: string) => Promise<void>;
22
- mob_events: (mobId: string, afterCursor: number, limit: number) => Promise<string>;
20
+ mob_lifecycle: (mobId: string, action: string) => Promise<string>;
21
+ mob_events: (mobId: string, afterCursor: string, limit: number) => Promise<string>;
23
22
  mob_run_flow: (mobId: string, flowId: string, params: string) => Promise<string>;
24
23
  mob_flow_status: (mobId: string, runId: string) => Promise<string>;
25
24
  mob_cancel_flow: (mobId: string, runId: string) => Promise<void>;
26
- mob_member_subscribe: (mobId: string, agentIdentity: string) => Promise<number>;
27
- mob_subscribe_events: (mobId: string) => Promise<number>;
28
- poll_subscription: (handle: number) => string;
29
- close_subscription: (handle: number) => void;
25
+ mob_member_subscribe: (mobId: string, agentIdentity: string) => Promise<string>;
26
+ mob_subscribe_events: (mobId: string) => Promise<string>;
27
+ poll_subscription: (streamId: string) => string;
28
+ close_subscription: (streamId: string) => void;
30
29
  }
31
30
  export declare function parseMobStatusResult(raw: unknown, context?: string): MobStatus;
32
31
  /** Capability-bearing handle for one mob member. */
@@ -65,17 +64,27 @@ export declare class Mob {
65
64
  forceCancel(agentIdentity: string): Promise<void>;
66
65
  /** Read the current execution snapshot for a member. */
67
66
  memberStatus(agentIdentity: string): Promise<MobMemberSnapshot>;
68
- /** Spawn a short-lived helper and return its terminal result. */
69
- spawnHelper(prompt: string, options?: {
70
- agentIdentity?: string;
67
+ /**
68
+ * Spawn a short-lived helper and return its terminal result.
69
+ *
70
+ * `agentIdentity` is required: the surface does not allocate member
71
+ * identity (#115) — the runtime fails closed without it.
72
+ */
73
+ spawnHelper(prompt: string, options: {
74
+ agentIdentity: string;
71
75
  profileName?: string;
72
76
  authBinding?: AuthBindingRef;
73
77
  runtimeMode?: string;
74
78
  backend?: string;
75
79
  }): Promise<MobHelperResult>;
76
- /** Fork a helper from an existing member and return its terminal result. */
77
- forkHelper(sourceMemberId: string, prompt: string, options?: {
78
- agentIdentity?: string;
80
+ /**
81
+ * Fork a helper from an existing member and return its terminal result.
82
+ *
83
+ * `agentIdentity` is required: the surface does not allocate member
84
+ * identity (#115) — the runtime fails closed without it.
85
+ */
86
+ forkHelper(sourceMemberId: string, prompt: string, options: {
87
+ agentIdentity: string;
79
88
  profileName?: string;
80
89
  authBinding?: AuthBindingRef;
81
90
  forkContext?: Record<string, unknown>;
@@ -84,9 +93,15 @@ export declare class Mob {
84
93
  }): Promise<MobHelperResult>;
85
94
  /** Get mob status. */
86
95
  status(): Promise<MobStatus>;
87
- /** Perform a lifecycle action (stop, resume, complete, destroy). */
88
- lifecycle(action: MobLifecycleAction): Promise<void>;
89
- /** Get mob events after a cursor. */
96
+ /** Perform a lifecycle action (stop, resume, complete, destroy).
97
+ *
98
+ * Returns the typed {@link MobLifecycleResult} from the WASM boundary
99
+ * (carrying the typed destroy_report for a destroy action), parsed
100
+ * fail-closed — a malformed payload throws instead of being dropped. */
101
+ lifecycle(action: MobLifecycleAction): Promise<MobLifecycleResult>;
102
+ /** Get mob events after a cursor. The cursor is an opaque u64-backed string
103
+ * forwarded verbatim — it MUST NOT be narrowed through Number() (which both
104
+ * caps it at u32 range and silently resets a non-finite value to 0). */
90
105
  events(afterCursor?: string, limit?: number): Promise<MobEvent[]>;
91
106
  /** Run a flow. Returns the run ID. */
92
107
  runFlow(flowId: string, params?: Record<string, unknown>): Promise<string>;
package/dist/mob.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mob.d.ts","sourceRoot":"","sources":["../src/mob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,WAAW,EACX,SAAS,EACT,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,QAAQ,EACR,0BAA0B,EAC1B,4BAA4B,EAC5B,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EAEjB,eAAe,EAKhB,MAAM,YAAY,CAAC;AAapB,UAAU,eAAe;IACvB,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7D,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,C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AAI,CAAC;IAK3D,6BAA6B;IACvB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,iDAAiD;IAC3C,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAU/F,mDAAmD;IAC7C,eAAe,IAAI,OAAO,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;CAUzE"}
package/dist/mob.js CHANGED
@@ -1,16 +1,6 @@
1
1
  import { EventSubscription } from './events.js';
2
- function encodeBase64UrlJson(payload) {
3
- const bytes = new TextEncoder().encode(JSON.stringify(payload));
4
- let binary = '';
5
- for (let i = 0; i < bytes.length; i += 1) {
6
- binary += String.fromCharCode(bytes[i]);
7
- }
8
- const b64 = btoa(binary);
9
- return b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
10
- }
11
- function encodeMemberRef(mobId, agentIdentity) {
12
- return encodeBase64UrlJson({ m: mobId, a: agentIdentity });
13
- }
2
+ import { serializePromptContentInput } from './session.js';
3
+ import { isKnownEvent } from './types.js';
14
4
  function spawnSpecPayload(spec) {
15
5
  return {
16
6
  profile: spec.profile,
@@ -117,14 +107,18 @@ function parseResolvedModelCapabilities(raw) {
117
107
  return undefined;
118
108
  }
119
109
  const record = requireRecord(raw, 'Invalid mob member_status response: resolved_capabilities must be object');
110
+ // Strict consumption of the generated WireResolvedModelCapabilities: every
111
+ // capability flag must arrive as a real boolean. We fail closed on
112
+ // absent/malformed booleans rather than coercing with Boolean(...), which
113
+ // would silently project `undefined`/`null`/non-booleans into `false`.
120
114
  return {
121
- vision: Boolean(record.vision),
122
- image_input: Boolean(record.image_input),
123
- image_tool_results: Boolean(record.image_tool_results),
124
- inline_video: Boolean(record.inline_video),
125
- realtime: Boolean(record.realtime),
126
- web_search: Boolean(record.web_search),
127
- image_generation: Boolean(record.image_generation),
115
+ vision: requireBooleanField(record, 'vision', 'Invalid mob member_status response: resolved_capabilities.vision must be boolean'),
116
+ image_input: requireBooleanField(record, 'image_input', 'Invalid mob member_status response: resolved_capabilities.image_input must be boolean'),
117
+ image_tool_results: requireBooleanField(record, 'image_tool_results', 'Invalid mob member_status response: resolved_capabilities.image_tool_results must be boolean'),
118
+ inline_video: requireBooleanField(record, 'inline_video', 'Invalid mob member_status response: resolved_capabilities.inline_video must be boolean'),
119
+ realtime: requireBooleanField(record, 'realtime', 'Invalid mob member_status response: resolved_capabilities.realtime must be boolean'),
120
+ web_search: requireBooleanField(record, 'web_search', 'Invalid mob member_status response: resolved_capabilities.web_search must be boolean'),
121
+ image_generation: requireBooleanField(record, 'image_generation', 'Invalid mob member_status response: resolved_capabilities.image_generation must be boolean'),
128
122
  };
129
123
  }
130
124
  function optionalStringArrayField(value, field, message) {
@@ -158,6 +152,54 @@ function parseWireHandlingMode(raw, message) {
158
152
  }
159
153
  throw new Error(message);
160
154
  }
155
+ function parseMobUnreachablePeer(raw) {
156
+ const record = requireRecord(raw, 'Invalid mob member_status response: peer_connectivity.unreachable_peers entry must be object');
157
+ const peer = requireStringField(record, 'peer', 'Invalid mob member_status response: peer_connectivity.unreachable_peers entry missing peer');
158
+ const reason = optionalStringField(record, 'reason', 'Invalid mob member_status response: peer_connectivity.unreachable_peers entry reason must be string');
159
+ return reason === undefined ? { peer } : { peer, reason };
160
+ }
161
+ function parseMobPeerConnectivitySnapshot(raw) {
162
+ const record = requireRecord(raw, 'Invalid mob member_status response: peer_connectivity.snapshot must be object');
163
+ const unreachableRaw = record.unreachable_peers;
164
+ const unreachable_peers = unreachableRaw === undefined
165
+ ? []
166
+ : Array.isArray(unreachableRaw)
167
+ ? unreachableRaw.map(parseMobUnreachablePeer)
168
+ : (() => {
169
+ throw new Error('Invalid mob member_status response: peer_connectivity.snapshot.unreachable_peers must be array');
170
+ })();
171
+ return {
172
+ reachable_peer_count: requireNonNegativeIntegerField(record, 'reachable_peer_count', 'Invalid mob member_status response: peer_connectivity.snapshot.reachable_peer_count must be number'),
173
+ unknown_peer_count: requireNonNegativeIntegerField(record, 'unknown_peer_count', 'Invalid mob member_status response: peer_connectivity.snapshot.unknown_peer_count must be number'),
174
+ unreachable_peers,
175
+ };
176
+ }
177
+ /**
178
+ * Fail-closed parser for the tri-state `peer_connectivity` projection. Mirrors
179
+ * `parseWireHandlingMode`: switch on the variant `status` tag and THROW on any
180
+ * unknown tag rather than coalescing it into a permissive default. Absent
181
+ * connectivity (the field was omitted) returns `undefined`.
182
+ */
183
+ function parseMobPeerConnectivity(raw) {
184
+ if (raw == null) {
185
+ return undefined;
186
+ }
187
+ const record = requireRecord(raw, 'Invalid mob member_status response: peer_connectivity must be object');
188
+ const status = record.status;
189
+ switch (status) {
190
+ case 'not_applicable':
191
+ return { status: 'not_applicable' };
192
+ case 'probe_timed_out':
193
+ return { status: 'probe_timed_out' };
194
+ case 'known':
195
+ return {
196
+ status: 'known',
197
+ snapshot: parseMobPeerConnectivitySnapshot(record.snapshot),
198
+ };
199
+ default:
200
+ throw new Error(`Invalid mob member_status response: unknown peer_connectivity status ${JSON.stringify(status)}`);
201
+ }
202
+ }
161
203
  export function parseMobStatusResult(raw, context = 'Invalid mob/status response') {
162
204
  const record = requireRecord(raw, `${context}: malformed envelope`);
163
205
  const mobId = requireStringField(record, 'mob_id', `${context}: missing mob_id`);
@@ -165,7 +207,6 @@ export function parseMobStatusResult(raw, context = 'Invalid mob/status response
165
207
  return {
166
208
  mob_id: mobId,
167
209
  status,
168
- state: status,
169
210
  };
170
211
  }
171
212
  function parseMobAppendSystemContextResult(raw) {
@@ -218,12 +259,6 @@ function normalizeSpawnManyEntry(raw, mobId) {
218
259
  member_ref: memberRef,
219
260
  };
220
261
  }
221
- function parseSubscriptionLaggedEvent(record, context) {
222
- return {
223
- type: 'lagged',
224
- skipped: requireNumberField(record, 'skipped', `${context}: lagged skipped must be number`),
225
- };
226
- }
227
262
  function normalizeEventSourceIdentity(raw, context) {
228
263
  const source = requireRecord(raw, `${context}: missing source`);
229
264
  const sourceType = requireStringField(source, 'type', `${context}: source missing type`);
@@ -269,7 +304,15 @@ function normalizeEventSourceIdentity(raw, context) {
269
304
  }
270
305
  function parseEventPayload(raw, context) {
271
306
  const payload = requireRecord(raw, `${context}: missing payload`);
272
- requireStringField(payload, 'type', `${context}: payload missing type`);
307
+ const type = requireStringField(payload, 'type', `${context}: payload missing type`);
308
+ // Fail closed on an unrecognized event type: validate the full record
309
+ // against the generated `AgentEvent` inventory via `isKnownEvent` instead
310
+ // of blindly casting an arbitrary record. An unknown discriminant is a
311
+ // malformed/forward-incompatible wire shape — mirroring session.ts and the
312
+ // TS SDK's parseCoreEvent policy.
313
+ if (!isKnownEvent(payload)) {
314
+ throw new Error(`${context}: unknown event type "${type}"`);
315
+ }
273
316
  return payload;
274
317
  }
275
318
  function parseEventEnvelope(raw, context) {
@@ -278,7 +321,6 @@ function parseEventEnvelope(raw, context) {
278
321
  const envelope = {
279
322
  event_id: requireStringField(record, 'event_id', `${context}: missing event_id`),
280
323
  source: normalizeEventSourceIdentity(record.source, context),
281
- source_id: requireStringField(record, 'source_id', `${context}: missing source_id`),
282
324
  seq: requireNumberField(record, 'seq', `${context}: missing seq`),
283
325
  timestamp_ms: requireNumberField(record, 'timestamp_ms', `${context}: missing timestamp_ms`),
284
326
  payload,
@@ -302,11 +344,9 @@ function parseEventEnvelope(raw, context) {
302
344
  return envelope;
303
345
  }
304
346
  function parseMemberEventItem(raw, context) {
305
- const record = requireRecord(raw, `${context}: malformed event item`);
306
- if (record.type === 'lagged') {
307
- return parseSubscriptionLaggedEvent(record, context);
308
- }
309
- return parseEventEnvelope(record, context);
347
+ // K19: a lagged receiver arrives as the generated `stream_truncated`
348
+ // envelope; every item is a full EventEnvelope, parsed fail-closed.
349
+ return parseEventEnvelope(raw, context);
310
350
  }
311
351
  function parseAttributedSource(raw, context) {
312
352
  const source = requireRecord(raw, `${context}: missing source`);
@@ -316,9 +356,6 @@ function parseAttributedSource(raw, context) {
316
356
  }
317
357
  function parseAttributedEventItem(raw, context) {
318
358
  const record = requireRecord(raw, `${context}: malformed attributed event`);
319
- if (record.type === 'lagged') {
320
- return parseSubscriptionLaggedEvent(record, context);
321
- }
322
359
  const source = parseAttributedSource(record.source, context);
323
360
  const role = requireStringField(record, 'role', `${context}: missing role`);
324
361
  const attributed = {
@@ -349,22 +386,27 @@ function parseMobEvent(raw, context) {
349
386
  function parseMobEvents(raw) {
350
387
  return parseEventItems(raw, 'Invalid mob/events response', parseMobEvent);
351
388
  }
352
- function parseMobMemberSnapshot(raw, mobId, agentIdentity) {
389
+ function parseMobMemberSnapshot(raw) {
353
390
  const snapshot = requireRecord(raw, 'Invalid mob member_status response: malformed envelope');
354
391
  const currentSessionId = optionalStringField(snapshot, 'current_session_id', 'Invalid mob member_status response: current_session_id must be string');
355
392
  const result = {
356
393
  status: parseWireMobMemberStatus(snapshot.status, 'Invalid mob member_status response: missing status'),
357
- member_ref: encodeMemberRef(mobId, agentIdentity),
394
+ // The opaque member handle is runtime-owned: read it from the payload
395
+ // rather than synthesizing it client-side from {mobId, agentIdentity}.
396
+ member_ref: requireStringField(snapshot, 'member_ref', 'Invalid mob member_status response: missing member_ref'),
358
397
  output_preview: optionalStringField(snapshot, 'output_preview', 'Invalid mob member_status response: output_preview must be string'),
359
398
  error: optionalStringField(snapshot, 'error', 'Invalid mob member_status response: error must be string'),
360
399
  tokens_used: requireNonNegativeIntegerField(snapshot, 'tokens_used', 'Invalid mob member_status response: tokens_used must be number'),
361
400
  is_final: requireBooleanField(snapshot, 'is_final', 'Invalid mob member_status response: is_final must be boolean'),
362
401
  kickoff: optionalRecordField(snapshot, 'kickoff', 'Invalid mob member_status response: kickoff must be object'),
363
- peer_connectivity: optionalRecordField(snapshot, 'peer_connectivity', 'Invalid mob member_status response: peer_connectivity must be object'),
364
402
  };
365
403
  if (currentSessionId !== undefined) {
366
404
  result.current_session_id = currentSessionId;
367
405
  }
406
+ const peerConnectivity = parseMobPeerConnectivity(snapshot.peer_connectivity);
407
+ if (peerConnectivity !== undefined) {
408
+ result.peer_connectivity = peerConnectivity;
409
+ }
368
410
  const resolvedCapabilities = parseResolvedModelCapabilities(snapshot.resolved_capabilities);
369
411
  if (resolvedCapabilities !== undefined) {
370
412
  result.resolved_capabilities = resolvedCapabilities;
@@ -374,17 +416,22 @@ function parseMobMemberSnapshot(raw, mobId, agentIdentity) {
374
416
  }
375
417
  return result;
376
418
  }
419
+ const WIRE_MOB_RESPAWN_OUTCOMES = [
420
+ 'completed',
421
+ 'topology_restore_failed',
422
+ ];
377
423
  function parseMobRespawnResult(raw) {
378
424
  const result = requireRecord(raw, 'Invalid mob respawn response: malformed envelope');
379
425
  const status = requireStringField(result, 'status', 'Invalid mob respawn response: missing status');
380
- if (status !== 'completed' && status !== 'topology_restore_failed') {
426
+ if (!WIRE_MOB_RESPAWN_OUTCOMES.includes(status)) {
381
427
  throw new Error('Invalid mob respawn response: invalid status');
382
428
  }
429
+ const respawnStatus = status;
383
430
  const receipt = requireRecord(result.receipt, 'Invalid mob respawn response: missing receipt');
384
431
  const memberRef = requireStringField(receipt, 'member_ref', 'Invalid mob respawn response: receipt missing member_ref');
385
432
  const identity = requireStringField(receipt, 'identity', 'Invalid mob respawn response: receipt missing identity');
386
433
  return {
387
- status,
434
+ status: respawnStatus,
388
435
  receipt: {
389
436
  agent_identity: identity,
390
437
  member_ref: memberRef,
@@ -452,8 +499,8 @@ export class Member {
452
499
  return parseMemberDeliveryReceipt(parseJsonPayload(json, 'Invalid mob member delivery response'), this.mobId, this.agentIdentity);
453
500
  }
454
501
  async subscribe() {
455
- const handle = await this.bindings.mob_member_subscribe(this.mobId, this.agentIdentity);
456
- return new EventSubscription(() => this.bindings.poll_subscription(handle), (raw) => parseEventItems(raw, 'Invalid mob member subscription event', parseMemberEventItem), () => this.bindings.close_subscription(handle));
502
+ const streamId = await this.bindings.mob_member_subscribe(this.mobId, this.agentIdentity);
503
+ return new EventSubscription(() => this.bindings.poll_subscription(streamId), (raw) => parseEventItems(raw, 'Invalid mob member subscription event', parseMemberEventItem), () => this.bindings.close_subscription(streamId));
457
504
  }
458
505
  }
459
506
  /** A mob instance — a group of agents with shared orchestration. */
@@ -485,11 +532,7 @@ export class Mob {
485
532
  await this.bindings.mob_wire(this.mobId, member, peer);
486
533
  return;
487
534
  }
488
- const wirePeer = this.bindings.mob_wire_peer ?? this.bindings.mob_wire_target;
489
- if (!wirePeer) {
490
- throw new Error('This runtime does not support external peer wiring');
491
- }
492
- await wirePeer(this.mobId, member, JSON.stringify(peer));
535
+ await this.bindings.mob_wire_peer(this.mobId, member, JSON.stringify(peer));
493
536
  }
494
537
  /** Remove comms trust between two agents. */
495
538
  async unwire(member, peer) {
@@ -497,11 +540,7 @@ export class Mob {
497
540
  await this.bindings.mob_unwire(this.mobId, member, peer);
498
541
  return;
499
542
  }
500
- const unwirePeer = this.bindings.mob_unwire_peer ?? this.bindings.mob_unwire_target;
501
- if (!unwirePeer) {
502
- throw new Error('This runtime does not support external peer unwiring');
503
- }
504
- await unwirePeer(this.mobId, member, JSON.stringify(peer));
543
+ await this.bindings.mob_unwire_peer(this.mobId, member, JSON.stringify(peer));
505
544
  }
506
545
  /** List all members in the mob. */
507
546
  async listMembers() {
@@ -541,7 +580,6 @@ export class Mob {
541
580
  ? Object.fromEntries(Object.entries(member.external_peer_specs).map(([key, value]) => [key, (value ?? {})]))
542
581
  : undefined,
543
582
  runtime_mode: member.runtime_mode != null ? String(member.runtime_mode) : undefined,
544
- state: member.state != null ? String(member.state) : undefined,
545
583
  wired_to: Array.isArray(member.wired_to)
546
584
  ? member.wired_to.map((peer) => String(peer))
547
585
  : undefined,
@@ -572,10 +610,11 @@ export class Mob {
572
610
  }
573
611
  /** Retire and re-spawn an agent with the same profile. Returns a result envelope with receipt. */
574
612
  async respawn(agentIdentity, initialMessage) {
613
+ // K19: the initial message crosses the WASM boundary as the tagged
614
+ // content-input wire shape — the tag is the discriminator, never JSON
615
+ // shape-sniffing of a raw string.
575
616
  const payload = initialMessage != null
576
- ? typeof initialMessage === 'string'
577
- ? initialMessage
578
- : JSON.stringify(initialMessage)
617
+ ? serializePromptContentInput(initialMessage)
579
618
  : undefined;
580
619
  const json = await this.bindings.mob_respawn(this.mobId, agentIdentity, payload);
581
620
  return parseMobRespawnResult(parseJsonPayload(json, 'Invalid mob respawn response'));
@@ -587,31 +626,41 @@ export class Mob {
587
626
  /** Read the current execution snapshot for a member. */
588
627
  async memberStatus(agentIdentity) {
589
628
  const json = await this.bindings.mob_member_status(this.mobId, agentIdentity);
590
- return parseMobMemberSnapshot(parseJsonPayload(json, 'Invalid mob member_status response'), this.mobId, agentIdentity);
591
- }
592
- /** Spawn a short-lived helper and return its terminal result. */
629
+ return parseMobMemberSnapshot(parseJsonPayload(json, 'Invalid mob member_status response'));
630
+ }
631
+ /**
632
+ * Spawn a short-lived helper and return its terminal result.
633
+ *
634
+ * `agentIdentity` is required: the surface does not allocate member
635
+ * identity (#115) — the runtime fails closed without it.
636
+ */
593
637
  async spawnHelper(prompt, options) {
594
638
  const json = await this.bindings.mob_spawn_helper(this.mobId, JSON.stringify({
595
639
  prompt,
596
- agent_identity: options?.agentIdentity,
597
- profile_name: options?.profileName,
598
- auth_binding: options?.authBinding,
599
- runtime_mode: options?.runtimeMode,
600
- backend: options?.backend,
640
+ agent_identity: options.agentIdentity,
641
+ profile_name: options.profileName,
642
+ auth_binding: options.authBinding,
643
+ runtime_mode: options.runtimeMode,
644
+ backend: options.backend,
601
645
  }));
602
646
  return parseMobHelperResult(parseJsonPayload(json, 'Invalid mob spawn_helper response'), 'Invalid mob spawn_helper response');
603
647
  }
604
- /** Fork a helper from an existing member and return its terminal result. */
648
+ /**
649
+ * Fork a helper from an existing member and return its terminal result.
650
+ *
651
+ * `agentIdentity` is required: the surface does not allocate member
652
+ * identity (#115) — the runtime fails closed without it.
653
+ */
605
654
  async forkHelper(sourceMemberId, prompt, options) {
606
655
  const json = await this.bindings.mob_fork_helper(this.mobId, JSON.stringify({
607
656
  source_member_id: sourceMemberId,
608
657
  prompt,
609
- agent_identity: options?.agentIdentity,
610
- profile_name: options?.profileName,
611
- auth_binding: options?.authBinding,
612
- fork_context: options?.forkContext,
613
- runtime_mode: options?.runtimeMode,
614
- backend: options?.backend,
658
+ agent_identity: options.agentIdentity,
659
+ profile_name: options.profileName,
660
+ auth_binding: options.authBinding,
661
+ fork_context: options.forkContext,
662
+ runtime_mode: options.runtimeMode,
663
+ backend: options.backend,
615
664
  }));
616
665
  return parseMobHelperResult(parseJsonPayload(json, 'Invalid mob fork_helper response'), 'Invalid mob fork_helper response');
617
666
  }
@@ -620,14 +669,28 @@ export class Mob {
620
669
  const json = await this.bindings.mob_status(this.mobId);
621
670
  return parseMobStatusResult(parseJsonPayload(json, 'Invalid mob/status response'));
622
671
  }
623
- /** Perform a lifecycle action (stop, resume, complete, destroy). */
672
+ /** Perform a lifecycle action (stop, resume, complete, destroy).
673
+ *
674
+ * Returns the typed {@link MobLifecycleResult} from the WASM boundary
675
+ * (carrying the typed destroy_report for a destroy action), parsed
676
+ * fail-closed — a malformed payload throws instead of being dropped. */
624
677
  async lifecycle(action) {
625
- await this.bindings.mob_lifecycle(this.mobId, action);
678
+ const json = await this.bindings.mob_lifecycle(this.mobId, action);
679
+ const raw = parseJsonPayload(json, 'Invalid mob/lifecycle response');
680
+ if (typeof raw !== 'object' ||
681
+ raw === null ||
682
+ typeof raw.ok !== 'boolean' ||
683
+ typeof raw.mob_id !== 'string' ||
684
+ typeof raw.action !== 'string') {
685
+ throw new Error('Invalid mob/lifecycle response: missing typed fields');
686
+ }
687
+ return raw;
626
688
  }
627
- /** Get mob events after a cursor. */
689
+ /** Get mob events after a cursor. The cursor is an opaque u64-backed string
690
+ * forwarded verbatim — it MUST NOT be narrowed through Number() (which both
691
+ * caps it at u32 range and silently resets a non-finite value to 0). */
628
692
  async events(afterCursor = '', limit = 100) {
629
- const numericCursor = afterCursor === '' ? 0 : Number(afterCursor);
630
- const json = await this.bindings.mob_events(this.mobId, Number.isFinite(numericCursor) ? numericCursor : 0, limit);
693
+ const json = await this.bindings.mob_events(this.mobId, afterCursor, limit);
631
694
  return parseMobEvents(parseJsonPayload(json, 'Invalid mob/events response'));
632
695
  }
633
696
  /** Run a flow. Returns the run ID. */
@@ -645,13 +708,13 @@ export class Mob {
645
708
  }
646
709
  /** Subscribe to events for a specific member. */
647
710
  async subscribeMemberEvents(agentIdentity) {
648
- const handle = await this.bindings.mob_member_subscribe(this.mobId, agentIdentity);
649
- return new EventSubscription(() => this.bindings.poll_subscription(handle), (raw) => parseEventItems(raw, 'Invalid mob member subscription event', parseMemberEventItem), () => this.bindings.close_subscription(handle));
711
+ const streamId = await this.bindings.mob_member_subscribe(this.mobId, agentIdentity);
712
+ return new EventSubscription(() => this.bindings.poll_subscription(streamId), (raw) => parseEventItems(raw, 'Invalid mob member subscription event', parseMemberEventItem), () => this.bindings.close_subscription(streamId));
650
713
  }
651
714
  /** Subscribe to all mob-wide attributed events. */
652
715
  async subscribeEvents() {
653
- const handle = await this.bindings.mob_subscribe_events(this.mobId);
654
- return new EventSubscription(() => this.bindings.poll_subscription(handle), (raw) => parseEventItems(raw, 'Invalid mob attributed subscription event', parseAttributedEventItem), () => this.bindings.close_subscription(handle));
716
+ const streamId = await this.bindings.mob_subscribe_events(this.mobId);
717
+ return new EventSubscription(() => this.bindings.poll_subscription(streamId), (raw) => parseEventItems(raw, 'Invalid mob attributed subscription event', parseAttributedEventItem), () => this.bindings.close_subscription(streamId));
655
718
  }
656
719
  }
657
720
  //# sourceMappingURL=mob.js.map