@rkat/sdk 0.3.4

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/README.md ADDED
@@ -0,0 +1,593 @@
1
+ # Meerkat TypeScript SDK
2
+
3
+ TypeScript client for the [Meerkat](https://github.com/lukacf/raik) agent runtime. Communicates with a local `rkat-rpc` subprocess over JSON-RPC 2.0 (newline-delimited JSON on stdin/stdout).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @meerkat/sdk
9
+ ```
10
+
11
+ ## Prerequisites
12
+
13
+ - **`rkat-rpc` binary on PATH** -- build it from the Meerkat repo with `cargo build -p meerkat-rpc`, then ensure the resulting `rkat-rpc` binary is in your `$PATH`.
14
+ - **Node.js >= 18** (uses `node:child_process`, `node:readline`, `node:test`).
15
+ - **API key** for at least one LLM provider set in your environment (e.g. `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, or `GOOGLE_API_KEY`).
16
+
17
+ ## tsconfig Requirements
18
+
19
+ The SDK is published as ESM (`"type": "module"` in package.json). Your project's `tsconfig.json` must use Node16 module resolution:
20
+
21
+ ```json
22
+ {
23
+ "compilerOptions": {
24
+ "target": "ES2022",
25
+ "module": "Node16",
26
+ "moduleResolution": "Node16",
27
+ "lib": ["ES2022"],
28
+ "strict": true,
29
+ "esModuleInterop": true
30
+ }
31
+ }
32
+ ```
33
+
34
+ ## Quick Start
35
+
36
+ ```ts
37
+ import { MeerkatClient } from "@meerkat/sdk";
38
+
39
+ const client = new MeerkatClient();
40
+
41
+ // Connect spawns `rkat-rpc`, performs the initialize handshake,
42
+ // and fetches runtime capabilities.
43
+ await client.connect();
44
+
45
+ // Create a session (runs the first turn immediately).
46
+ const result = await client.createSession({
47
+ prompt: "What is the capital of Sweden?",
48
+ });
49
+
50
+ console.log(result.text); // "Stockholm..."
51
+ console.log(result.session_id); // UUID of the new session
52
+ console.log(result.usage); // { input_tokens, output_tokens, total_tokens, ... }
53
+
54
+ // Multi-turn: send a follow-up in the same session.
55
+ const followUp = await client.startTurn(
56
+ result.session_id,
57
+ "And what is its population?",
58
+ );
59
+ console.log(followUp.text);
60
+
61
+ // Clean up.
62
+ await client.archiveSession(result.session_id);
63
+ await client.close();
64
+ ```
65
+
66
+ ## API Reference: MeerkatClient
67
+
68
+ ### Constructor
69
+
70
+ ```ts
71
+ new MeerkatClient(rkatPath?: string)
72
+ ```
73
+
74
+ | Parameter | Type | Default | Description |
75
+ |-----------|------|---------|-------------|
76
+ | `rkatPath` | `string` | `"rkat-rpc"` | Path to the RPC binary. |
77
+
78
+ ### connect()
79
+
80
+ ```ts
81
+ async connect(): Promise<this>
82
+ ```
83
+
84
+ Spawns `rkat-rpc` as a child process, performs the `initialize` handshake, checks contract version compatibility, and fetches runtime capabilities via `capabilities/get`. Returns `this` for chaining.
85
+
86
+ Throws `MeerkatError` with code `"VERSION_MISMATCH"` if the server's contract version is incompatible with the SDK's `CONTRACT_VERSION`.
87
+
88
+ ### close()
89
+
90
+ ```ts
91
+ async close(): Promise<void>
92
+ ```
93
+
94
+ Kills the `rkat-rpc` subprocess and cleans up resources.
95
+
96
+ ### createSession(params)
97
+
98
+ ```ts
99
+ async createSession(params: {
100
+ prompt: string;
101
+ model?: string;
102
+ provider?: string;
103
+ system_prompt?: string;
104
+ max_tokens?: number;
105
+ output_schema?: Record<string, unknown>;
106
+ structured_output_retries?: number;
107
+ hooks_override?: Record<string, unknown>;
108
+ enable_builtins?: boolean;
109
+ enable_shell?: boolean;
110
+ enable_subagents?: boolean;
111
+ enable_memory?: boolean;
112
+ host_mode?: boolean;
113
+ comms_name?: string;
114
+ provider_params?: Record<string, unknown>;
115
+ }): Promise<WireRunResult>
116
+ ```
117
+
118
+ Creates a new session and immediately runs the first turn with the given prompt. Returns a `WireRunResult`.
119
+
120
+ **Parameters:**
121
+
122
+ | Parameter | Type | Default | Description |
123
+ |-----------|------|---------|-------------|
124
+ | `prompt` | `string` | **(required)** | The user prompt for the first turn. |
125
+ | `model` | `string` | Server default (typically `claude-sonnet-4-5`) | LLM model name (e.g. `"gpt-5.2"`, `"gemini-3-flash-preview"`, `"claude-opus-4-6"`). |
126
+ | `provider` | `string` | Auto-detected from model | Force a specific provider (`"anthropic"`, `"openai"`, `"gemini"`). |
127
+ | `system_prompt` | `string` | `undefined` | Override the default system prompt. |
128
+ | `max_tokens` | `number` | `undefined` | Maximum output tokens for the LLM response. |
129
+ | `output_schema` | `Record<string, unknown>` | `undefined` | JSON Schema for structured output extraction. |
130
+ | `structured_output_retries` | `number` | `2` (server default) | Max retries for structured output validation. |
131
+ | `hooks_override` | `Record<string, unknown>` | `undefined` | Run-scoped hook overrides. |
132
+ | `enable_builtins` | `boolean` | `false` | Enable built-in tools (task management, etc.). |
133
+ | `enable_shell` | `boolean` | `false` | Enable the shell tool (requires `enable_builtins`). |
134
+ | `enable_subagents` | `boolean` | `false` | Enable sub-agent tools (fork, spawn). |
135
+ | `enable_memory` | `boolean` | `false` | Enable semantic memory (memory_search tool + compaction indexing). |
136
+ | `host_mode` | `boolean` | `false` | Run in host mode for inter-agent comms. |
137
+ | `comms_name` | `string` | `undefined` | Agent name for comms (required when `host_mode` is `true`). |
138
+ | `provider_params` | `Record<string, unknown>` | `undefined` | Provider-specific parameters (e.g. thinking config). |
139
+
140
+ ### startTurn(sessionId, prompt)
141
+
142
+ ```ts
143
+ async startTurn(sessionId: string, prompt: string): Promise<WireRunResult>
144
+ ```
145
+
146
+ Starts a new turn on an existing session. Returns a `WireRunResult`.
147
+
148
+ | Parameter | Type | Description |
149
+ |-----------|------|-------------|
150
+ | `sessionId` | `string` | UUID of an existing session. |
151
+ | `prompt` | `string` | The user prompt for this turn. |
152
+
153
+ ### interrupt(sessionId)
154
+
155
+ ```ts
156
+ async interrupt(sessionId: string): Promise<void>
157
+ ```
158
+
159
+ Cancels an in-flight turn on the specified session. No-op if the session is idle.
160
+
161
+ ### listSessions()
162
+
163
+ ```ts
164
+ async listSessions(): Promise<unknown[]>
165
+ ```
166
+
167
+ Returns an array of session info objects (each containing `session_id` and `state`).
168
+
169
+ ### readSession(sessionId)
170
+
171
+ ```ts
172
+ async readSession(sessionId: string): Promise<Record<string, unknown>>
173
+ ```
174
+
175
+ Returns the current state of a session (contains `session_id` and `state`).
176
+
177
+ ### archiveSession(sessionId)
178
+
179
+ ```ts
180
+ async archiveSession(sessionId: string): Promise<void>
181
+ ```
182
+
183
+ Removes a session from the runtime. The session will no longer appear in `listSessions()`.
184
+
185
+ ### getCapabilities()
186
+
187
+ ```ts
188
+ async getCapabilities(): Promise<CapabilitiesResponse>
189
+ ```
190
+
191
+ Returns the cached capabilities response. If capabilities were not yet fetched (e.g. `connect()` was not called), fetches them from the server.
192
+
193
+ ### hasCapability(capabilityId)
194
+
195
+ ```ts
196
+ hasCapability(capabilityId: string): boolean
197
+ ```
198
+
199
+ Returns `true` if the given capability is `"Available"` in the runtime. Known capability IDs:
200
+
201
+ | Capability ID | Description |
202
+ |---------------|-------------|
203
+ | `"sessions"` | Session lifecycle (create/turn/list/read/archive) |
204
+ | `"streaming"` | Real-time event streaming |
205
+ | `"structured_output"` | JSON schema-based structured output extraction |
206
+ | `"hooks"` | Lifecycle hooks |
207
+ | `"builtins"` | Built-in tools |
208
+ | `"shell"` | Shell tool |
209
+ | `"comms"` | Inter-agent communication |
210
+ | `"sub_agents"` | Sub-agent tools (fork, spawn) |
211
+ | `"memory_store"` | Semantic memory |
212
+ | `"session_store"` | Session persistence |
213
+ | `"session_compaction"` | Context compaction |
214
+ | `"skills"` | Skill loading and invocation |
215
+
216
+ ### requireCapability(capabilityId)
217
+
218
+ ```ts
219
+ requireCapability(capabilityId: string): void
220
+ ```
221
+
222
+ Throws `MeerkatError` with code `"CAPABILITY_UNAVAILABLE"` if the capability is not available.
223
+
224
+ ### getConfig()
225
+
226
+ ```ts
227
+ async getConfig(): Promise<Record<string, unknown>>
228
+ ```
229
+
230
+ Returns the current Meerkat configuration as a JSON object.
231
+
232
+ ### setConfig(config)
233
+
234
+ ```ts
235
+ async setConfig(config: Record<string, unknown>): Promise<void>
236
+ ```
237
+
238
+ Replaces the entire runtime configuration.
239
+
240
+ ### patchConfig(patch)
241
+
242
+ ```ts
243
+ async patchConfig(patch: Record<string, unknown>): Promise<Record<string, unknown>>
244
+ ```
245
+
246
+ Merge-patches the runtime configuration and returns the resulting config.
247
+
248
+ ## Wire Types
249
+
250
+ ### WireRunResult
251
+
252
+ Returned by `createSession()` and `startTurn()`.
253
+
254
+ ```ts
255
+ interface WireRunResult {
256
+ session_id: string;
257
+ text: string;
258
+ turns: number;
259
+ tool_calls: number;
260
+ usage: WireUsage;
261
+ structured_output?: unknown;
262
+ schema_warnings?: Array<{
263
+ provider: string;
264
+ path: string;
265
+ message: string;
266
+ }>;
267
+ }
268
+ ```
269
+
270
+ ### WireUsage
271
+
272
+ Token usage statistics.
273
+
274
+ ```ts
275
+ interface WireUsage {
276
+ input_tokens: number;
277
+ output_tokens: number;
278
+ total_tokens: number;
279
+ cache_creation_tokens?: number;
280
+ cache_read_tokens?: number;
281
+ }
282
+ ```
283
+
284
+ ### WireEvent
285
+
286
+ Event emitted as a JSON-RPC notification during a turn.
287
+
288
+ ```ts
289
+ interface WireEvent {
290
+ session_id: string;
291
+ sequence: number;
292
+ event: Record<string, unknown>;
293
+ contract_version: string;
294
+ }
295
+ ```
296
+
297
+ ### CapabilitiesResponse
298
+
299
+ ```ts
300
+ interface CapabilitiesResponse {
301
+ contract_version: string;
302
+ capabilities: CapabilityEntry[];
303
+ }
304
+ ```
305
+
306
+ ### CapabilityEntry
307
+
308
+ ```ts
309
+ interface CapabilityEntry {
310
+ id: string;
311
+ description: string;
312
+ status: string; // "Available", "DisabledByPolicy", "NotCompiled", etc.
313
+ }
314
+ ```
315
+
316
+ ## CapabilityChecker
317
+
318
+ Standalone helper for checking runtime capabilities. Useful when you want to gate entire code paths based on what the server supports.
319
+
320
+ ```ts
321
+ import { MeerkatClient, CapabilityChecker } from "@meerkat/sdk";
322
+
323
+ const client = new MeerkatClient();
324
+ await client.connect();
325
+
326
+ const caps = await client.getCapabilities();
327
+ const checker = new CapabilityChecker(caps);
328
+
329
+ // Check if a capability is available.
330
+ if (checker.has("comms")) {
331
+ console.log("Comms is available");
332
+ }
333
+
334
+ // Throw if a capability is missing.
335
+ checker.require("skills"); // throws CapabilityUnavailableError if unavailable
336
+
337
+ // List all available capability IDs.
338
+ console.log(checker.available); // ["sessions", "streaming", ...]
339
+ ```
340
+
341
+ ### Methods
342
+
343
+ | Method | Signature | Description |
344
+ |--------|-----------|-------------|
345
+ | `has` | `has(capabilityId: string): boolean` | Returns `true` if the capability status is `"Available"`. |
346
+ | `require` | `require(capabilityId: string): void` | Throws `CapabilityUnavailableError` if the capability is not available. |
347
+ | `available` | `get available(): string[]` | Getter that returns all capability IDs with status `"Available"`. |
348
+
349
+ ## SkillHelper
350
+
351
+ Convenience wrapper for invoking Meerkat skills. Skills are loaded by the agent from filesystem and embedded sources. To invoke a skill, include its reference (e.g. `/shell-patterns`) in the user prompt.
352
+
353
+ ```ts
354
+ import { MeerkatClient, SkillHelper } from "@meerkat/sdk";
355
+
356
+ const client = new MeerkatClient();
357
+ await client.connect();
358
+
359
+ const helper = new SkillHelper(client);
360
+
361
+ // Check if skills are available in this runtime.
362
+ if (helper.isAvailable()) {
363
+ // Invoke a skill in an existing session.
364
+ const result = await helper.invoke(
365
+ sessionId,
366
+ "/shell-patterns",
367
+ "How do I run a background job?",
368
+ );
369
+ console.log(result.text);
370
+ }
371
+
372
+ // Or create a new session and invoke a skill in one call.
373
+ const result = await helper.invokeNewSession(
374
+ "/code-review",
375
+ "Review this function for performance issues",
376
+ "claude-opus-4-6", // optional model override
377
+ );
378
+ ```
379
+
380
+ ### Methods
381
+
382
+ | Method | Signature | Description |
383
+ |--------|-----------|-------------|
384
+ | `isAvailable` | `isAvailable(): boolean` | Returns `true` if the `"skills"` capability is available. |
385
+ | `requireSkills` | `requireSkills(): void` | Throws `CapabilityUnavailableError` if skills are not available. |
386
+ | `invoke` | `invoke(sessionId: string, skillReference: string, prompt: string): Promise<WireRunResult>` | Invokes a skill in an existing session. Prepends the skill reference to the prompt and calls `startTurn`. |
387
+ | `invokeNewSession` | `invokeNewSession(skillReference: string, prompt: string, model?: string): Promise<WireRunResult>` | Creates a new session and invokes a skill in the first turn. |
388
+
389
+ ## EventStream
390
+
391
+ Async iterator that yields `WireEvent` objects from JSON-RPC notifications emitted by `rkat-rpc` during a turn. Filters out response messages (which have an `id` field) and only yields notification payloads.
392
+
393
+ ```ts
394
+ import { createInterface } from "node:readline";
395
+ import { EventStream } from "@meerkat/sdk";
396
+ import type { Interface } from "node:readline";
397
+
398
+ // The EventStream wraps a readline interface attached to the RPC process stdout.
399
+ // In practice you would get the readline from the child process:
400
+ const rl: Interface = createInterface({ input: process.stdin });
401
+ const stream = new EventStream(rl);
402
+
403
+ for await (const event of stream) {
404
+ console.log(event.session_id, event.sequence, event.event);
405
+ }
406
+ ```
407
+
408
+ The `EventStream` class implements `AsyncIterable<WireEvent>`. It buffers events internally and resolves waiting consumers as events arrive. When the underlying readline interface closes, the iterator completes.
409
+
410
+ > **Note:** `MeerkatClient` handles the JSON-RPC response/notification multiplexing internally. `EventStream` is a lower-level primitive for advanced use cases where you manage the `rkat-rpc` subprocess yourself.
411
+
412
+ ## Error Handling
413
+
414
+ The SDK provides a hierarchy of error classes, all extending the base `MeerkatError`:
415
+
416
+ ### MeerkatError
417
+
418
+ ```ts
419
+ class MeerkatError extends Error {
420
+ readonly code: string;
421
+ readonly details?: unknown;
422
+ readonly capabilityHint?: {
423
+ capability_id: string;
424
+ message: string;
425
+ };
426
+
427
+ constructor(
428
+ code: string,
429
+ message: string,
430
+ details?: unknown,
431
+ capabilityHint?: { capability_id: string; message: string },
432
+ );
433
+ }
434
+ ```
435
+
436
+ Base error class. The `code` field contains a machine-readable error code (e.g. `"VERSION_MISMATCH"`, `"NOT_CONNECTED"`, `"CAPABILITY_UNAVAILABLE"`). The optional `capabilityHint` suggests which capability needs to be enabled.
437
+
438
+ ### CapabilityUnavailableError
439
+
440
+ ```ts
441
+ class CapabilityUnavailableError extends MeerkatError {}
442
+ ```
443
+
444
+ Thrown when a required capability is not available in the runtime (e.g. feature not compiled in, disabled by policy).
445
+
446
+ ### SessionNotFoundError
447
+
448
+ ```ts
449
+ class SessionNotFoundError extends MeerkatError {}
450
+ ```
451
+
452
+ Thrown when a session ID does not exist in the runtime.
453
+
454
+ ### SkillNotFoundError
455
+
456
+ ```ts
457
+ class SkillNotFoundError extends MeerkatError {}
458
+ ```
459
+
460
+ Thrown when a referenced skill cannot be found.
461
+
462
+ ### Error handling example
463
+
464
+ ```ts
465
+ import {
466
+ MeerkatClient,
467
+ MeerkatError,
468
+ CapabilityUnavailableError,
469
+ } from "@meerkat/sdk";
470
+
471
+ const client = new MeerkatClient();
472
+
473
+ try {
474
+ await client.connect();
475
+ const result = await client.createSession({ prompt: "Hello" });
476
+ console.log(result.text);
477
+ } catch (err) {
478
+ if (err instanceof CapabilityUnavailableError) {
479
+ console.error("Missing capability:", err.message);
480
+ if (err.capabilityHint) {
481
+ console.error("Hint:", err.capabilityHint.message);
482
+ }
483
+ } else if (err instanceof MeerkatError) {
484
+ console.error(`Meerkat error [${err.code}]: ${err.message}`);
485
+ } else {
486
+ throw err;
487
+ }
488
+ } finally {
489
+ await client.close();
490
+ }
491
+ ```
492
+
493
+ ## Version Compatibility
494
+
495
+ The SDK exports `CONTRACT_VERSION` (currently `"0.2.0"`). During `connect()`, the SDK checks that the server's contract version is compatible:
496
+
497
+ - While the major version is `0`, minor versions must match exactly (e.g. SDK `0.1.x` requires server `0.1.x`).
498
+ - Once `1.0.0` is reached, major versions must match (standard semver).
499
+
500
+ ```ts
501
+ import { CONTRACT_VERSION } from "@meerkat/sdk";
502
+ console.log(CONTRACT_VERSION); // "0.2.0"
503
+ ```
504
+
505
+ If the versions are incompatible, `connect()` throws a `MeerkatError` with code `"VERSION_MISMATCH"`.
506
+
507
+ ## Config Management Example
508
+
509
+ ```ts
510
+ const client = new MeerkatClient();
511
+ await client.connect();
512
+
513
+ // Read the current config.
514
+ const config = await client.getConfig();
515
+ console.log(config);
516
+
517
+ // Replace the entire config.
518
+ await client.setConfig({ ...config, max_tokens: 4096 });
519
+
520
+ // Or merge-patch specific fields.
521
+ const updated = await client.patchConfig({ max_tokens: 8192 });
522
+ console.log(updated.max_tokens); // 8192
523
+
524
+ await client.close();
525
+ ```
526
+
527
+ ## Structured Output Example
528
+
529
+ ```ts
530
+ const client = new MeerkatClient();
531
+ await client.connect();
532
+
533
+ const result = await client.createSession({
534
+ prompt: "List three European capitals",
535
+ output_schema: {
536
+ type: "object",
537
+ properties: {
538
+ capitals: {
539
+ type: "array",
540
+ items: { type: "string" },
541
+ },
542
+ },
543
+ required: ["capitals"],
544
+ },
545
+ structured_output_retries: 3,
546
+ });
547
+
548
+ // Parsed structured output (matches the schema).
549
+ console.log(result.structured_output);
550
+ // { capitals: ["Paris", "Berlin", "Madrid"] }
551
+
552
+ // Schema warnings from provider-specific validation issues.
553
+ if (result.schema_warnings) {
554
+ for (const w of result.schema_warnings) {
555
+ console.warn(`[${w.provider}] ${w.path}: ${w.message}`);
556
+ }
557
+ }
558
+
559
+ await client.close();
560
+ ```
561
+
562
+ ## Multi-turn Conversation Example
563
+
564
+ ```ts
565
+ const client = new MeerkatClient();
566
+ await client.connect();
567
+
568
+ // Create session with first turn.
569
+ const session = await client.createSession({
570
+ prompt: "My name is Alice.",
571
+ model: "claude-sonnet-4-5",
572
+ });
573
+
574
+ // Follow-up turns reuse the session_id.
575
+ const turn2 = await client.startTurn(session.session_id, "What is my name?");
576
+ console.log(turn2.text); // Should mention "Alice"
577
+
578
+ // Check session state.
579
+ const state = await client.readSession(session.session_id);
580
+ console.log(state);
581
+
582
+ // List all active sessions.
583
+ const sessions = await client.listSessions();
584
+ console.log(`Active sessions: ${sessions.length}`);
585
+
586
+ // Clean up.
587
+ await client.archiveSession(session.session_id);
588
+ await client.close();
589
+ ```
590
+
591
+ ## License
592
+
593
+ MIT OR Apache-2.0
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Capability checking and method gating for the Meerkat SDK.
3
+ */
4
+ import type { CapabilitiesResponse } from "./generated/types.js";
5
+ /**
6
+ * Gates method calls by checking runtime capabilities.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const checker = new CapabilityChecker(capabilitiesResponse);
11
+ * checker.require("comms"); // throws if comms not available
12
+ * ```
13
+ */
14
+ export declare class CapabilityChecker {
15
+ private capabilities;
16
+ constructor(response: CapabilitiesResponse);
17
+ /** Check if a capability is available. */
18
+ has(capabilityId: string): boolean;
19
+ /** Throw CapabilityUnavailableError if capability is not available. */
20
+ require(capabilityId: string): void;
21
+ /** List all available capability IDs. */
22
+ get available(): string[];
23
+ }
24
+ //# sourceMappingURL=capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGjE;;;;;;;;GAQG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,YAAY,CAAsB;gBAE9B,QAAQ,EAAE,oBAAoB;IAM1C,0CAA0C;IAC1C,GAAG,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAIlC,uEAAuE;IACvE,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IASnC,yCAAyC;IACzC,IAAI,SAAS,IAAI,MAAM,EAAE,CAIxB;CACF"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Capability checking and method gating for the Meerkat SDK.
3
+ */
4
+ import { CapabilityUnavailableError } from "./generated/errors.js";
5
+ /**
6
+ * Gates method calls by checking runtime capabilities.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const checker = new CapabilityChecker(capabilitiesResponse);
11
+ * checker.require("comms"); // throws if comms not available
12
+ * ```
13
+ */
14
+ export class CapabilityChecker {
15
+ capabilities;
16
+ constructor(response) {
17
+ this.capabilities = new Map(response.capabilities.map((c) => [c.id, c.status]));
18
+ }
19
+ /** Check if a capability is available. */
20
+ has(capabilityId) {
21
+ return this.capabilities.get(capabilityId) === "Available";
22
+ }
23
+ /** Throw CapabilityUnavailableError if capability is not available. */
24
+ require(capabilityId) {
25
+ if (!this.has(capabilityId)) {
26
+ throw new CapabilityUnavailableError("CAPABILITY_UNAVAILABLE", `Capability '${capabilityId}' is not available in this runtime`);
27
+ }
28
+ }
29
+ /** List all available capability IDs. */
30
+ get available() {
31
+ return [...this.capabilities.entries()]
32
+ .filter(([, status]) => status === "Available")
33
+ .map(([id]) => id);
34
+ }
35
+ }
36
+ //# sourceMappingURL=capabilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAEnE;;;;;;;;GAQG;AACH,MAAM,OAAO,iBAAiB;IACpB,YAAY,CAAsB;IAE1C,YAAY,QAA8B;QACxC,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,CACzB,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CACnD,CAAC;IACJ,CAAC;IAED,0CAA0C;IAC1C,GAAG,CAAC,YAAoB;QACtB,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,KAAK,WAAW,CAAC;IAC7D,CAAC;IAED,uEAAuE;IACvE,OAAO,CAAC,YAAoB;QAC1B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,0BAA0B,CAClC,wBAAwB,EACxB,eAAe,YAAY,oCAAoC,CAChE,CAAC;QACJ,CAAC;IACH,CAAC;IAED,yCAAyC;IACzC,IAAI,SAAS;QACX,OAAO,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;aACpC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,KAAK,WAAW,CAAC;aAC9C,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;IACvB,CAAC;CACF"}