@craftedxp/sdk-node 0.9.0 → 0.10.1

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 CHANGED
@@ -24,16 +24,24 @@ const client = new PlatformClient({
24
24
  baseUrl: 'https://api.your-server.com', // or http://localhost:8080 for dev
25
25
  })
26
26
 
27
- // In your "/voice-token" route handler — called by the RN SDK's fetchToken:
27
+ // In your "/voice-token" route handler — called by the client SDK's fetchToken:
28
28
  async function mintForCall({ agentId, userId, context, metadata }) {
29
- const { token } = await client.callTokens.mint({
29
+ const result = await client.callTokens.mint({
30
30
  agentId,
31
31
  ttlSeconds: 600, // 10 min default; up to 3600 (60 min)
32
32
  contactId: userId, // optional → cross-call memory
33
33
  context, // optional arbitrary JSON, lowered into agent's system prompt
34
34
  metadata, // optional opaque keys round-tripped on call.ended webhook (≤1 KB)
35
35
  })
36
- return { token } // hand to the RN SDK
36
+ // Forward `transport` + `webrtcGatewayBase` so the client SDK can
37
+ // dispatch WS vs WebRTC based on the agent's configuration. New agents
38
+ // default to `transport: 'webrtc'` (2026-05-16); WS stays as the
39
+ // back-compat fallback for legacy agents and older client builds.
40
+ return {
41
+ token: result.token,
42
+ transport: result.transport,
43
+ webrtcGatewayBase: result.webrtcGatewayBase,
44
+ }
37
45
  }
38
46
  ```
39
47
 
@@ -72,6 +80,57 @@ client.credits.getBalance() // billing
72
80
  client.credits.getLedger({ limit, cursor })
73
81
 
74
82
  client.webhooks.deliveries({ agentId, callId, webhookId }) // org-wide delivery log
83
+
84
+ client.rooms.create({ agentId, durationMin }) // multi-party video rooms
85
+ client.rooms.list({ status, limit, cursor })
86
+ client.rooms.get(roomId)
87
+ client.rooms.transcript(roomId, { cursor, limit })
88
+ client.rooms.end(roomId)
89
+ ```
90
+
91
+ ## Multi-party video rooms
92
+
93
+ Provision a hosted room from your backend; share the single returned link;
94
+ participants join with **video** in the browser via `@craftedxp/voice-js`
95
+ (`joinRoom`). The room always includes a silent AI notetaker that transcribes
96
+ per speaker — the human-to-human video call works regardless.
97
+
98
+ ```ts
99
+ // Backend — the agent must be allowed to host rooms. Enable it from code
100
+ // (since 0.10.1) instead of the dashboard:
101
+ await client.agents.update(agentId, { canHostRooms: true, roomMode: 'notes-only' })
102
+ // (you can also pass canHostRooms/roomMode to `agents.create`.)
103
+
104
+ // Mint a room. Returns ONE shared joinToken + a joinUrl; the raw token is
105
+ // returned once and never stored.
106
+ const room = await client.rooms.create({ agentId, durationMin: 30 })
107
+ // → { roomId, status: 'provisioning', joinToken, joinUrl, expiresAt }
108
+
109
+ // Hand `roomId` + `joinToken` to the browser. There, with @craftedxp/voice-js:
110
+ // const session = await configureVoiceClient({ apiBase }).joinRoom({
111
+ // roomId, joinCode: joinToken, name,
112
+ // })
113
+ // await session.publishMic(); await session.publishCamera()
114
+ // session.on('track.subscribed', ({ kind, track }) => kind === 'video' && track.attach(el))
115
+
116
+ // Read the transcript (cursor-paginated, oldest first) or end the room early:
117
+ const page = await client.rooms.transcript(room.roomId, { limit: 100 })
118
+ await client.rooms.end(room.roomId)
119
+ ```
120
+
121
+ A complete, runnable consumer app (backend + browser video UI) lives in
122
+ [`examples/video-call`](../../examples/video-call).
123
+
124
+ ### Transcribe-only agents
125
+
126
+ Set `transcribeOnly: true` (on `agents.create` or `agents.update`, since 0.10.1)
127
+ for an agent that **listens but never speaks** — no TTS/LLM, no greeting; user
128
+ turns stream back as `transcript` data-messages over the existing call/WebRTC
129
+ transport. Useful for note-taking / dictation surfaces that reuse the agent +
130
+ call-mint plumbing but want the agent silent.
131
+
132
+ ```ts
133
+ await client.agents.create({ name: 'Scribe', systemPrompt: 'n/a', transcribeOnly: true })
75
134
  ```
76
135
 
77
136
  ## Webhook signature verification
package/dist/index.d.mts CHANGED
@@ -26,7 +26,7 @@ declare const createHttpClient: (opts: HttpClientOptions) => {
26
26
  };
27
27
  type HttpClient = ReturnType<typeof createHttpClient>;
28
28
 
29
- type TtsProvider = 'pockettts' | 'cartesia' | 'fish-audio' | 'gemini';
29
+ type TtsProvider = 'pockettts' | 'cartesia' | 'fish-audio' | 'gemini' | 'kokoro' | 'hume' | 'omnivoice' | 'chatterbox' | 'tada';
30
30
  type SttProvider = 'deepgram';
31
31
  type LlmProvider = 'gemini' | 'openai' | 'anthropic';
32
32
  type EndpointingMode = 'smart' | 'simple';
@@ -34,6 +34,20 @@ interface AgentVoice {
34
34
  provider: TtsProvider;
35
35
  voiceId?: string;
36
36
  language?: string;
37
+ /**
38
+ * Secondary language for bilingual agents. When set, the agent supports
39
+ * mid-utterance code-switching via the `[lang=xx]...[/lang]` tag contract.
40
+ * Requires a multilingual-capable TTS provider (cartesia, kokoro,
41
+ * fish-audio, hume, omnivoice, gemini). See docs/sdks.md "Bilingual
42
+ * agents" section.
43
+ */
44
+ secondaryLanguage?: string;
45
+ /**
46
+ * Second-language voice ID for voice-pinned providers (kokoro). Stays
47
+ * unset for providers whose voices handle multiple languages natively
48
+ * (cartesia, hume, omnivoice).
49
+ */
50
+ secondaryVoiceId?: string;
37
51
  /**
38
52
  * Per-utterance variation, 0.0–1.0. Honoured by Fish Audio and
39
53
  * Chatterbox (passed through to each provider's synthesis API).
@@ -54,6 +68,13 @@ interface AgentTranscriber {
54
68
  provider: SttProvider;
55
69
  model: string;
56
70
  language?: string;
71
+ /**
72
+ * Secondary language for bilingual agents. When set, the STT provider
73
+ * auto-flips to multi-language mode (Deepgram `multi`, Whisper
74
+ * auto-detect). Other STT providers reject bilingual config at agent
75
+ * create time.
76
+ */
77
+ secondaryLanguage?: string;
57
78
  }
58
79
  interface AgentModel {
59
80
  provider: LlmProvider;
@@ -122,6 +143,19 @@ interface Agent {
122
143
  * cache-buster so browser/CDN caches refresh on replace.
123
144
  */
124
145
  avatarUrl?: string;
146
+ /**
147
+ * Transport the agent's live calls use. `'webrtc'` (the platform default
148
+ * for new agents) or `'ws'` (legacy). Forwarded on the mint result and
149
+ * needed by the agent-initiated push payload so the app dispatches to the
150
+ * right gateway.
151
+ */
152
+ transport?: 'ws' | 'webrtc';
153
+ /** Whether this agent may host multi-party video rooms. */
154
+ canHostRooms?: boolean;
155
+ /** Room operating mode (`'notes-only'` today). */
156
+ roomMode?: 'notes-only';
157
+ /** Transcribe-only mode — the agent listens but never speaks. */
158
+ transcribeOnly?: boolean;
125
159
  createdAt: number;
126
160
  updatedAt: number;
127
161
  }
@@ -140,6 +174,8 @@ interface AgentCreateInput {
140
174
  recording?: AgentRecording;
141
175
  structuredDataSchema?: Record<string, unknown>;
142
176
  allowedUserTags?: string[];
177
+ /** See Agent.transport. Defaults to the platform default when omitted. */
178
+ transport?: 'ws' | 'webrtc';
143
179
  /**
144
180
  * Server-managed. Don't set this directly via create/update — use
145
181
  * `agents.uploadAvatar(agentId, file)` instead. Sending it raw is
@@ -147,6 +183,25 @@ interface AgentCreateInput {
147
183
  * actually changes.
148
184
  */
149
185
  avatarUrl?: string;
186
+ /**
187
+ * Let this agent host multi-party video rooms. Off by default. Required
188
+ * (`true`) before `client.rooms.create({ agentId })` will accept the agent.
189
+ */
190
+ canHostRooms?: boolean;
191
+ /**
192
+ * Room operating mode. Today only `'notes-only'` exists — the agent listens
193
+ * and takes structured notes without speaking. A literal union so future
194
+ * modes can be added without breaking the wire.
195
+ */
196
+ roomMode?: 'notes-only';
197
+ /**
198
+ * Transcribe-only mode. When `true`, the agent listens but never speaks: no
199
+ * TTS/LLM, no greeting, idle nudges suppressed, user turns are not routed
200
+ * through the LLM — an STT-only loop that streams `transcript` data-messages
201
+ * back to the caller. `voice` stays required by the schema (defaults apply)
202
+ * but is never read at runtime.
203
+ */
204
+ transcribeOnly?: boolean;
150
205
  }
151
206
  type AgentUpdateInput = Partial<AgentCreateInput>;
152
207
  /**
@@ -323,6 +378,13 @@ interface CallTokenMintInput {
323
378
  * if you blindly accept client-asserted tier the gate is theatre.
324
379
  */
325
380
  userTags?: string[];
381
+ /**
382
+ * Mark this token as agent-initiated. When 'agent', the tenant's server
383
+ * is ringing the end-user (push → app connects) and the resulting
384
+ * CallRecord is tagged `direction: 'outbound'`. Omit / 'user' for the
385
+ * default user-initiated connect. See docs/sdks.md "Agent-initiated calls".
386
+ */
387
+ initiatedBy?: 'user' | 'agent';
326
388
  }
327
389
  interface CallTokenMintResult {
328
390
  tokenId: string;
@@ -400,6 +462,81 @@ interface MeResponse {
400
462
  plan: 'free' | 'paid';
401
463
  creditBalance: number;
402
464
  }
465
+ type RoomStatus = 'provisioning' | 'active' | 'ended';
466
+ type RoomEndReason = 'duration_reached' | 'empty' | 'manual' | 'expired';
467
+ type GuestRole = 'host' | 'participant';
468
+ type WorkerStatus = 'pending' | 'up' | 'down' | 'exited';
469
+ interface CreateRoomInput {
470
+ agentId: string;
471
+ /** 1..240 — enforced by the server. */
472
+ durationMin: number;
473
+ }
474
+ interface CreateRoomResponse {
475
+ roomId: string;
476
+ status: 'provisioning';
477
+ expiresAt: string;
478
+ /** The shareable room-level secret — returned once, never persisted raw.
479
+ * Anyone with this token + a display name joins as a fresh participant. */
480
+ joinToken: string;
481
+ /** `${APP_ORIGIN}/rooms/${roomId}/join?t=${joinToken}` — the single link to
482
+ * share with everyone you want in the room. */
483
+ joinUrl: string;
484
+ }
485
+ interface RoomMetricsWire {
486
+ droppedUtterances: number;
487
+ deepgramReconnects: number;
488
+ }
489
+ interface RoomDoc {
490
+ roomId: string;
491
+ orgId: string;
492
+ agentId: string;
493
+ status: RoomStatus;
494
+ livekitSid: string | null;
495
+ durationMin: number;
496
+ /** sha256 of the shared room join token. The raw token is never persisted. */
497
+ joinTokenJti?: string;
498
+ createdByApiKeyId?: string;
499
+ createdAt?: string;
500
+ startedAt: string | null;
501
+ endedAt: string | null;
502
+ expiresAt: string;
503
+ endReason: RoomEndReason | null;
504
+ workerStatus?: WorkerStatus;
505
+ metrics?: RoomMetricsWire | null;
506
+ }
507
+ interface RoomListFilters {
508
+ status?: RoomStatus;
509
+ /** Server clamps to 100 max; default 20. */
510
+ limit?: number;
511
+ cursor?: string;
512
+ }
513
+ interface ListRoomsResponse {
514
+ rooms: RoomDoc[];
515
+ nextCursor: string | null;
516
+ }
517
+ interface RoomTranscriptOptions {
518
+ cursor?: string;
519
+ /** Server clamps to 1000 max; default 200. */
520
+ limit?: number;
521
+ }
522
+ interface UtteranceWire {
523
+ utteranceId: string;
524
+ participantId: string;
525
+ speakerName: string;
526
+ text: string;
527
+ startedAt: string;
528
+ endedAt: string;
529
+ sttConfidence: number;
530
+ }
531
+ interface ListUtterancesResponse {
532
+ utterances: UtteranceWire[];
533
+ nextCursor: string | null;
534
+ }
535
+ /** Returned by host-action endpoints (`/end` and friends) — 202 + eventId so
536
+ * callers can correlate the async system-message broadcast that follows. */
537
+ interface RoomEventAck {
538
+ eventId: string;
539
+ }
403
540
 
404
541
  declare const createMeResource: (http: HttpClient) => {
405
542
  get: () => Promise<MeResponse>;
@@ -536,6 +673,15 @@ declare const createOrgsResource: (http: HttpClient) => {
536
673
  };
537
674
  type OrgsResource = ReturnType<typeof createOrgsResource>;
538
675
 
676
+ declare const createRoomsResource: (http: HttpClient) => {
677
+ create: (input: CreateRoomInput) => Promise<CreateRoomResponse>;
678
+ list: (filters?: RoomListFilters) => Promise<ListRoomsResponse>;
679
+ get: (roomId: string) => Promise<RoomDoc>;
680
+ transcript: (roomId: string, opts?: RoomTranscriptOptions) => Promise<ListUtterancesResponse>;
681
+ end: (roomId: string) => Promise<RoomEventAck>;
682
+ };
683
+ type RoomsResource = ReturnType<typeof createRoomsResource>;
684
+
539
685
  interface PlatformClientOptions {
540
686
  apiKey: string;
541
687
  baseUrl?: string;
@@ -553,6 +699,7 @@ declare class PlatformClient {
553
699
  readonly callTokens: CallTokensResource;
554
700
  readonly webhooks: WebhooksResource;
555
701
  readonly orgs: OrgsResource;
702
+ readonly rooms: RoomsResource;
556
703
  constructor(options: PlatformClientOptions);
557
704
  }
558
705
 
@@ -576,4 +723,4 @@ declare class PlatformError extends Error {
576
723
 
577
724
  declare const verifyWebhookSignature: (rawBody: Buffer | string, signatureHeader: string, secret: string) => boolean;
578
725
 
579
- export { type Agent, type AgentCreateInput, type AgentEndpointing, type AgentHttpTool, type AgentModel, type AgentRecording, type AgentTool, type AgentTranscriber, type AgentUpdateInput, type AgentVoice, type AgentWebhooksResource, type AgentsResource, type ApiErrorCode, type CallListFilters, type CallRecord, type CallRecordingUrlResponse, type CallStatus, type CallSummary, type CallTokenMintInput, type CallTokenMintResult, type CallTokenSummary, type CallTokensResource, type CallsResource, type CatalogAgent, type CatalogListInput, type CostBreakdown, type CreditsResource, type EndReason, type EndpointingMode, type KnowledgeBase, type KnowledgeBaseFile, type KnowledgeBasesResource, type LedgerEntry, type LlmProvider, type MeResource, type MeResponse, type OrgsResource, PlatformClient, type PlatformClientOptions, PlatformError, type PlatformEventName, type RecordingMeta, type SttProvider, type TranscriptTurn, type TtsProvider, type WebhookConfig, type WebhookCreateInput, type WebhookDelivery, type WebhookUpdateInput, type WebhooksResource, verifyWebhookSignature };
726
+ export { type Agent, type AgentCreateInput, type AgentEndpointing, type AgentHttpTool, type AgentModel, type AgentRecording, type AgentTool, type AgentTranscriber, type AgentUpdateInput, type AgentVoice, type AgentWebhooksResource, type AgentsResource, type ApiErrorCode, type CallListFilters, type CallRecord, type CallRecordingUrlResponse, type CallStatus, type CallSummary, type CallTokenMintInput, type CallTokenMintResult, type CallTokenSummary, type CallTokensResource, type CallsResource, type CatalogAgent, type CatalogListInput, type CostBreakdown, type CreateRoomInput, type CreateRoomResponse, type CreditsResource, type EndReason, type EndpointingMode, type GuestRole, type KnowledgeBase, type KnowledgeBaseFile, type KnowledgeBasesResource, type LedgerEntry, type ListRoomsResponse, type ListUtterancesResponse, type LlmProvider, type MeResource, type MeResponse, type OrgsResource, PlatformClient, type PlatformClientOptions, PlatformError, type PlatformEventName, type RecordingMeta, type RoomDoc, type RoomEndReason, type RoomEventAck, type RoomListFilters, type RoomMetricsWire, type RoomStatus, type RoomTranscriptOptions, type RoomsResource, type SttProvider, type TranscriptTurn, type TtsProvider, type UtteranceWire, type WebhookConfig, type WebhookCreateInput, type WebhookDelivery, type WebhookUpdateInput, type WebhooksResource, type WorkerStatus, verifyWebhookSignature };
package/dist/index.d.ts CHANGED
@@ -26,7 +26,7 @@ declare const createHttpClient: (opts: HttpClientOptions) => {
26
26
  };
27
27
  type HttpClient = ReturnType<typeof createHttpClient>;
28
28
 
29
- type TtsProvider = 'pockettts' | 'cartesia' | 'fish-audio' | 'gemini';
29
+ type TtsProvider = 'pockettts' | 'cartesia' | 'fish-audio' | 'gemini' | 'kokoro' | 'hume' | 'omnivoice' | 'chatterbox' | 'tada';
30
30
  type SttProvider = 'deepgram';
31
31
  type LlmProvider = 'gemini' | 'openai' | 'anthropic';
32
32
  type EndpointingMode = 'smart' | 'simple';
@@ -34,6 +34,20 @@ interface AgentVoice {
34
34
  provider: TtsProvider;
35
35
  voiceId?: string;
36
36
  language?: string;
37
+ /**
38
+ * Secondary language for bilingual agents. When set, the agent supports
39
+ * mid-utterance code-switching via the `[lang=xx]...[/lang]` tag contract.
40
+ * Requires a multilingual-capable TTS provider (cartesia, kokoro,
41
+ * fish-audio, hume, omnivoice, gemini). See docs/sdks.md "Bilingual
42
+ * agents" section.
43
+ */
44
+ secondaryLanguage?: string;
45
+ /**
46
+ * Second-language voice ID for voice-pinned providers (kokoro). Stays
47
+ * unset for providers whose voices handle multiple languages natively
48
+ * (cartesia, hume, omnivoice).
49
+ */
50
+ secondaryVoiceId?: string;
37
51
  /**
38
52
  * Per-utterance variation, 0.0–1.0. Honoured by Fish Audio and
39
53
  * Chatterbox (passed through to each provider's synthesis API).
@@ -54,6 +68,13 @@ interface AgentTranscriber {
54
68
  provider: SttProvider;
55
69
  model: string;
56
70
  language?: string;
71
+ /**
72
+ * Secondary language for bilingual agents. When set, the STT provider
73
+ * auto-flips to multi-language mode (Deepgram `multi`, Whisper
74
+ * auto-detect). Other STT providers reject bilingual config at agent
75
+ * create time.
76
+ */
77
+ secondaryLanguage?: string;
57
78
  }
58
79
  interface AgentModel {
59
80
  provider: LlmProvider;
@@ -122,6 +143,19 @@ interface Agent {
122
143
  * cache-buster so browser/CDN caches refresh on replace.
123
144
  */
124
145
  avatarUrl?: string;
146
+ /**
147
+ * Transport the agent's live calls use. `'webrtc'` (the platform default
148
+ * for new agents) or `'ws'` (legacy). Forwarded on the mint result and
149
+ * needed by the agent-initiated push payload so the app dispatches to the
150
+ * right gateway.
151
+ */
152
+ transport?: 'ws' | 'webrtc';
153
+ /** Whether this agent may host multi-party video rooms. */
154
+ canHostRooms?: boolean;
155
+ /** Room operating mode (`'notes-only'` today). */
156
+ roomMode?: 'notes-only';
157
+ /** Transcribe-only mode — the agent listens but never speaks. */
158
+ transcribeOnly?: boolean;
125
159
  createdAt: number;
126
160
  updatedAt: number;
127
161
  }
@@ -140,6 +174,8 @@ interface AgentCreateInput {
140
174
  recording?: AgentRecording;
141
175
  structuredDataSchema?: Record<string, unknown>;
142
176
  allowedUserTags?: string[];
177
+ /** See Agent.transport. Defaults to the platform default when omitted. */
178
+ transport?: 'ws' | 'webrtc';
143
179
  /**
144
180
  * Server-managed. Don't set this directly via create/update — use
145
181
  * `agents.uploadAvatar(agentId, file)` instead. Sending it raw is
@@ -147,6 +183,25 @@ interface AgentCreateInput {
147
183
  * actually changes.
148
184
  */
149
185
  avatarUrl?: string;
186
+ /**
187
+ * Let this agent host multi-party video rooms. Off by default. Required
188
+ * (`true`) before `client.rooms.create({ agentId })` will accept the agent.
189
+ */
190
+ canHostRooms?: boolean;
191
+ /**
192
+ * Room operating mode. Today only `'notes-only'` exists — the agent listens
193
+ * and takes structured notes without speaking. A literal union so future
194
+ * modes can be added without breaking the wire.
195
+ */
196
+ roomMode?: 'notes-only';
197
+ /**
198
+ * Transcribe-only mode. When `true`, the agent listens but never speaks: no
199
+ * TTS/LLM, no greeting, idle nudges suppressed, user turns are not routed
200
+ * through the LLM — an STT-only loop that streams `transcript` data-messages
201
+ * back to the caller. `voice` stays required by the schema (defaults apply)
202
+ * but is never read at runtime.
203
+ */
204
+ transcribeOnly?: boolean;
150
205
  }
151
206
  type AgentUpdateInput = Partial<AgentCreateInput>;
152
207
  /**
@@ -323,6 +378,13 @@ interface CallTokenMintInput {
323
378
  * if you blindly accept client-asserted tier the gate is theatre.
324
379
  */
325
380
  userTags?: string[];
381
+ /**
382
+ * Mark this token as agent-initiated. When 'agent', the tenant's server
383
+ * is ringing the end-user (push → app connects) and the resulting
384
+ * CallRecord is tagged `direction: 'outbound'`. Omit / 'user' for the
385
+ * default user-initiated connect. See docs/sdks.md "Agent-initiated calls".
386
+ */
387
+ initiatedBy?: 'user' | 'agent';
326
388
  }
327
389
  interface CallTokenMintResult {
328
390
  tokenId: string;
@@ -400,6 +462,81 @@ interface MeResponse {
400
462
  plan: 'free' | 'paid';
401
463
  creditBalance: number;
402
464
  }
465
+ type RoomStatus = 'provisioning' | 'active' | 'ended';
466
+ type RoomEndReason = 'duration_reached' | 'empty' | 'manual' | 'expired';
467
+ type GuestRole = 'host' | 'participant';
468
+ type WorkerStatus = 'pending' | 'up' | 'down' | 'exited';
469
+ interface CreateRoomInput {
470
+ agentId: string;
471
+ /** 1..240 — enforced by the server. */
472
+ durationMin: number;
473
+ }
474
+ interface CreateRoomResponse {
475
+ roomId: string;
476
+ status: 'provisioning';
477
+ expiresAt: string;
478
+ /** The shareable room-level secret — returned once, never persisted raw.
479
+ * Anyone with this token + a display name joins as a fresh participant. */
480
+ joinToken: string;
481
+ /** `${APP_ORIGIN}/rooms/${roomId}/join?t=${joinToken}` — the single link to
482
+ * share with everyone you want in the room. */
483
+ joinUrl: string;
484
+ }
485
+ interface RoomMetricsWire {
486
+ droppedUtterances: number;
487
+ deepgramReconnects: number;
488
+ }
489
+ interface RoomDoc {
490
+ roomId: string;
491
+ orgId: string;
492
+ agentId: string;
493
+ status: RoomStatus;
494
+ livekitSid: string | null;
495
+ durationMin: number;
496
+ /** sha256 of the shared room join token. The raw token is never persisted. */
497
+ joinTokenJti?: string;
498
+ createdByApiKeyId?: string;
499
+ createdAt?: string;
500
+ startedAt: string | null;
501
+ endedAt: string | null;
502
+ expiresAt: string;
503
+ endReason: RoomEndReason | null;
504
+ workerStatus?: WorkerStatus;
505
+ metrics?: RoomMetricsWire | null;
506
+ }
507
+ interface RoomListFilters {
508
+ status?: RoomStatus;
509
+ /** Server clamps to 100 max; default 20. */
510
+ limit?: number;
511
+ cursor?: string;
512
+ }
513
+ interface ListRoomsResponse {
514
+ rooms: RoomDoc[];
515
+ nextCursor: string | null;
516
+ }
517
+ interface RoomTranscriptOptions {
518
+ cursor?: string;
519
+ /** Server clamps to 1000 max; default 200. */
520
+ limit?: number;
521
+ }
522
+ interface UtteranceWire {
523
+ utteranceId: string;
524
+ participantId: string;
525
+ speakerName: string;
526
+ text: string;
527
+ startedAt: string;
528
+ endedAt: string;
529
+ sttConfidence: number;
530
+ }
531
+ interface ListUtterancesResponse {
532
+ utterances: UtteranceWire[];
533
+ nextCursor: string | null;
534
+ }
535
+ /** Returned by host-action endpoints (`/end` and friends) — 202 + eventId so
536
+ * callers can correlate the async system-message broadcast that follows. */
537
+ interface RoomEventAck {
538
+ eventId: string;
539
+ }
403
540
 
404
541
  declare const createMeResource: (http: HttpClient) => {
405
542
  get: () => Promise<MeResponse>;
@@ -536,6 +673,15 @@ declare const createOrgsResource: (http: HttpClient) => {
536
673
  };
537
674
  type OrgsResource = ReturnType<typeof createOrgsResource>;
538
675
 
676
+ declare const createRoomsResource: (http: HttpClient) => {
677
+ create: (input: CreateRoomInput) => Promise<CreateRoomResponse>;
678
+ list: (filters?: RoomListFilters) => Promise<ListRoomsResponse>;
679
+ get: (roomId: string) => Promise<RoomDoc>;
680
+ transcript: (roomId: string, opts?: RoomTranscriptOptions) => Promise<ListUtterancesResponse>;
681
+ end: (roomId: string) => Promise<RoomEventAck>;
682
+ };
683
+ type RoomsResource = ReturnType<typeof createRoomsResource>;
684
+
539
685
  interface PlatformClientOptions {
540
686
  apiKey: string;
541
687
  baseUrl?: string;
@@ -553,6 +699,7 @@ declare class PlatformClient {
553
699
  readonly callTokens: CallTokensResource;
554
700
  readonly webhooks: WebhooksResource;
555
701
  readonly orgs: OrgsResource;
702
+ readonly rooms: RoomsResource;
556
703
  constructor(options: PlatformClientOptions);
557
704
  }
558
705
 
@@ -576,4 +723,4 @@ declare class PlatformError extends Error {
576
723
 
577
724
  declare const verifyWebhookSignature: (rawBody: Buffer | string, signatureHeader: string, secret: string) => boolean;
578
725
 
579
- export { type Agent, type AgentCreateInput, type AgentEndpointing, type AgentHttpTool, type AgentModel, type AgentRecording, type AgentTool, type AgentTranscriber, type AgentUpdateInput, type AgentVoice, type AgentWebhooksResource, type AgentsResource, type ApiErrorCode, type CallListFilters, type CallRecord, type CallRecordingUrlResponse, type CallStatus, type CallSummary, type CallTokenMintInput, type CallTokenMintResult, type CallTokenSummary, type CallTokensResource, type CallsResource, type CatalogAgent, type CatalogListInput, type CostBreakdown, type CreditsResource, type EndReason, type EndpointingMode, type KnowledgeBase, type KnowledgeBaseFile, type KnowledgeBasesResource, type LedgerEntry, type LlmProvider, type MeResource, type MeResponse, type OrgsResource, PlatformClient, type PlatformClientOptions, PlatformError, type PlatformEventName, type RecordingMeta, type SttProvider, type TranscriptTurn, type TtsProvider, type WebhookConfig, type WebhookCreateInput, type WebhookDelivery, type WebhookUpdateInput, type WebhooksResource, verifyWebhookSignature };
726
+ export { type Agent, type AgentCreateInput, type AgentEndpointing, type AgentHttpTool, type AgentModel, type AgentRecording, type AgentTool, type AgentTranscriber, type AgentUpdateInput, type AgentVoice, type AgentWebhooksResource, type AgentsResource, type ApiErrorCode, type CallListFilters, type CallRecord, type CallRecordingUrlResponse, type CallStatus, type CallSummary, type CallTokenMintInput, type CallTokenMintResult, type CallTokenSummary, type CallTokensResource, type CallsResource, type CatalogAgent, type CatalogListInput, type CostBreakdown, type CreateRoomInput, type CreateRoomResponse, type CreditsResource, type EndReason, type EndpointingMode, type GuestRole, type KnowledgeBase, type KnowledgeBaseFile, type KnowledgeBasesResource, type LedgerEntry, type ListRoomsResponse, type ListUtterancesResponse, type LlmProvider, type MeResource, type MeResponse, type OrgsResource, PlatformClient, type PlatformClientOptions, PlatformError, type PlatformEventName, type RecordingMeta, type RoomDoc, type RoomEndReason, type RoomEventAck, type RoomListFilters, type RoomMetricsWire, type RoomStatus, type RoomTranscriptOptions, type RoomsResource, type SttProvider, type TranscriptTurn, type TtsProvider, type UtteranceWire, type WebhookConfig, type WebhookCreateInput, type WebhookDelivery, type WebhookUpdateInput, type WebhooksResource, type WorkerStatus, verifyWebhookSignature };
package/dist/index.js CHANGED
@@ -482,6 +482,57 @@ var createOrgsResource = (http) => ({
482
482
  }
483
483
  });
484
484
 
485
+ // src/resources/rooms.ts
486
+ var createRoomsResource = (http) => ({
487
+ // Provision a new room. Server returns 201 with ONE shared room-level
488
+ // `joinToken` + `joinUrl`. Share the single link with everyone you want in
489
+ // the room — each visitor supplies their own display name at join time and
490
+ // becomes a fresh, distinct participant. The server persists only the
491
+ // token's sha256 hash; the raw token is returned here once and never stored.
492
+ create: async (input) => http.request({
493
+ method: "POST",
494
+ path: "/v1/rooms",
495
+ body: input
496
+ }),
497
+ // Listing — opaque cursor pagination (`nextCursor` returned by the server
498
+ // is whatever startAfter() needs, don't parse client-side).
499
+ list: async (filters = {}) => {
500
+ const query = {};
501
+ if (filters.status) query.status = filters.status;
502
+ if (filters.limit !== void 0) query.limit = filters.limit;
503
+ if (filters.cursor) query.cursor = filters.cursor;
504
+ return http.request({
505
+ method: "GET",
506
+ path: "/v1/rooms",
507
+ query
508
+ });
509
+ },
510
+ // Fetch a single room. 404s are surfaced as PlatformError('not_found').
511
+ get: async (roomId) => http.request({
512
+ method: "GET",
513
+ path: `/v1/rooms/${roomId}`
514
+ }),
515
+ // Transcript pages — utterances are ordered by `startedAt asc`. Cursor is
516
+ // an ISO timestamp (server enforces, don't construct yourself).
517
+ transcript: async (roomId, opts = {}) => {
518
+ const query = {};
519
+ if (opts.cursor) query.cursor = opts.cursor;
520
+ if (opts.limit !== void 0) query.limit = opts.limit;
521
+ return http.request({
522
+ method: "GET",
523
+ path: `/v1/rooms/${roomId}/transcript`,
524
+ query
525
+ });
526
+ },
527
+ // End a room — async on the server: returns 202 + eventId once the
528
+ // controlEvents entry is written. The room-worker observes the entry,
529
+ // broadcasts the system message, and tears down LiveKit shortly after.
530
+ end: async (roomId) => http.request({
531
+ method: "POST",
532
+ path: `/v1/rooms/${roomId}/end`
533
+ })
534
+ });
535
+
485
536
  // src/PlatformClient.ts
486
537
  var PlatformClient = class {
487
538
  me;
@@ -492,6 +543,7 @@ var PlatformClient = class {
492
543
  callTokens;
493
544
  webhooks;
494
545
  orgs;
546
+ rooms;
495
547
  constructor(options) {
496
548
  if (!options.apiKey) {
497
549
  throw new Error("PlatformClient: `apiKey` is required");
@@ -512,6 +564,7 @@ var PlatformClient = class {
512
564
  this.callTokens = createCallTokensResource(http);
513
565
  this.webhooks = createWebhooksResource(http);
514
566
  this.orgs = createOrgsResource(http);
567
+ this.rooms = createRoomsResource(http);
515
568
  }
516
569
  };
517
570
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/http.ts","../src/resources/me.ts","../src/resources/agentWebhooks.ts","../src/resources/agents.ts","../src/resources/calls.ts","../src/resources/knowledgeBases.ts","../src/resources/credits.ts","../src/resources/callTokens.ts","../src/resources/webhooks.ts","../src/resources/orgs.ts","../src/PlatformClient.ts","../src/verify.ts"],"sourcesContent":["// Public API of @craftedxp/sdk-node.\n\nexport { PlatformClient } from './PlatformClient'\nexport type { PlatformClientOptions } from './PlatformClient'\n\n// Error class for `instanceof` checks in consumer code.\nexport { PlatformError } from './errors'\nexport type { ApiErrorCode } from './errors'\n\n// Webhook signature verification helper — standalone so frameworks\n// (Express, Koa, Next.js route handlers) can use it without instantiating\n// a PlatformClient.\nexport { verifyWebhookSignature } from './verify'\n\n// Re-export DTO types. Consumers often type their own storage models\n// against these — re-exporting avoids `import type` gymnastics.\nexport type * from './types'\n\n// Advanced: expose the resource types for consumers subclassing / wrapping\n// the client. 99% of users don't need these.\nexport type { MeResource } from './resources/me'\nexport type { AgentsResource } from './resources/agents'\nexport type { AgentWebhooksResource } from './resources/agentWebhooks'\nexport type { CallsResource } from './resources/calls'\nexport type { KnowledgeBasesResource } from './resources/knowledgeBases'\nexport type { CreditsResource } from './resources/credits'\nexport type { CallTokensResource } from './resources/callTokens'\nexport type { WebhooksResource } from './resources/webhooks'\nexport type { OrgsResource } from './resources/orgs'\n","// Typed error class mirroring the server's ErrorV1 shape:\n// { error: { code, message, field?, docs_url? } }\n//\n// Consumers do `err instanceof PlatformError` to branch on code without\n// parsing string messages. `status` carries the HTTP code for the 1% of\n// cases where the code field isn't enough (e.g. rate-limit → retry-after\n// header correlation).\n\nexport type ApiErrorCode =\n | 'unauthorized'\n | 'forbidden'\n | 'not_found'\n | 'bad_request'\n | 'conflict'\n | 'rate_limited'\n | 'payment_required'\n | 'internal_error'\n | 'unknown'\n\nexport class PlatformError extends Error {\n readonly code: ApiErrorCode\n readonly status: number\n readonly field?: string\n readonly docsUrl?: string\n // The raw response body for debugging. Intentionally optional — we clear\n // it on `error.toJSON()` so logging libraries don't dump the whole\n // server response into production logs.\n readonly body?: unknown\n\n constructor(params: {\n code: ApiErrorCode\n message: string\n status: number\n field?: string\n docsUrl?: string\n body?: unknown\n }) {\n super(params.message)\n this.name = 'PlatformError'\n this.code = params.code\n this.status = params.status\n this.field = params.field\n this.docsUrl = params.docsUrl\n this.body = params.body\n // Preserve the stack trace — Node's Error doesn't capture it\n // automatically when subclassing in some older runtimes.\n if (\n typeof (Error as typeof Error & { captureStackTrace?: unknown }).captureStackTrace ===\n 'function'\n ) {\n ;(\n Error as typeof Error & { captureStackTrace: (target: unknown, ctor: unknown) => void }\n ).captureStackTrace(this, PlatformError)\n }\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n status: this.status,\n field: this.field,\n docsUrl: this.docsUrl,\n }\n }\n}\n","import { PlatformError, type ApiErrorCode } from './errors'\n\n// Low-level HTTP wrapper around `fetch` (native in Node 18+). Every resource\n// method routes through here for consistent auth + error handling + retries.\n//\n// v1 scope: JSON-in / JSON-out + multipart for file uploads. No streaming —\n// call WebSockets go through @craftedxp/voice-rn (the React Native client)\n// or a web equivalent, not this server-side SDK.\n\nexport interface HttpClientOptions {\n apiKey: string\n baseUrl: string\n // Default 30s. File uploads can override per-request.\n timeoutMs?: number\n // 429 + 5xx retries. Defaults to 3 attempts (original + 2 retries) with\n // exponential backoff (250ms, 1s). Set to 0 to disable.\n maxRetries?: number\n // Optional — lets consumers swap in a test/mock fetch (or a custom one\n // with instrumentation). Defaults to the global.\n fetch?: typeof fetch\n // Optional — a callback that fires per-request with the final status and\n // duration. Handy for dropping traces into the consumer's observability\n // stack without wrapping each call.\n onRequest?: (info: {\n method: string\n url: string\n status: number\n durationMs: number\n attempt: number\n }) => void\n}\n\nexport interface HttpRequest {\n method: 'GET' | 'POST' | 'PATCH' | 'DELETE'\n path: string // starts with `/`, e.g. `/v1/agents/123`\n query?: Record<string, string | number | boolean | undefined>\n body?: unknown // JSON-serialised — for multipart use `formData`\n formData?: FormData\n timeoutMs?: number\n // Exposed for edge cases where a resource wants to tack on extra\n // headers (we don't have any today but leave the hook).\n headers?: Record<string, string>\n}\n\nconst DEFAULT_TIMEOUT_MS = 30_000\nconst DEFAULT_MAX_RETRIES = 2 // total attempts = 3\n\nconst buildUrl = (baseUrl: string, path: string, query?: HttpRequest['query']): string => {\n const u = new URL(path, baseUrl)\n if (query) {\n for (const [k, v] of Object.entries(query)) {\n if (v === undefined) continue\n u.searchParams.set(k, String(v))\n }\n }\n return u.toString()\n}\n\nconst sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms))\n\nconst isRetryable = (status: number): boolean => status === 429 || (status >= 500 && status < 600)\n\n// Parse whatever the server returned into a PlatformError. Falls back to\n// synthesising a sensible error for non-JSON responses.\nconst errorFromResponse = async (res: Response): Promise<PlatformError> => {\n const bodyText = await res.text().catch(() => '')\n let parsed: unknown = undefined\n try {\n parsed = bodyText ? JSON.parse(bodyText) : undefined\n } catch {\n // non-JSON response (e.g. an HTML error page from a proxy). Fall\n // through with parsed = undefined.\n }\n const errObj = (\n parsed as { error?: { code?: string; message?: string; field?: string; docs_url?: string } }\n )?.error\n return new PlatformError({\n code: (errObj?.code as ApiErrorCode) ?? 'unknown',\n message: errObj?.message ?? res.statusText ?? `HTTP ${res.status}`,\n status: res.status,\n field: errObj?.field,\n docsUrl: errObj?.docs_url,\n body: parsed ?? bodyText,\n })\n}\n\nexport const createHttpClient = (opts: HttpClientOptions) => {\n const fetchImpl = opts.fetch ?? globalThis.fetch\n const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS\n const maxRetries = opts.maxRetries ?? DEFAULT_MAX_RETRIES\n\n if (!fetchImpl) {\n throw new Error('No global fetch available. @craftedxp/sdk-node requires Node >= 18.')\n }\n\n const request = async <T>(req: HttpRequest): Promise<T> => {\n const url = buildUrl(opts.baseUrl, req.path, req.query)\n const headers: Record<string, string> = {\n Authorization: `Bearer ${opts.apiKey}`,\n Accept: 'application/json',\n ...(req.headers ?? {}),\n }\n\n // Body shaping: prefer formData when provided; otherwise JSON.\n // `FormData` sets its own Content-Type with boundary — don't preempt it.\n // Typed as `string | FormData | undefined` (a subset of the global\n // BodyInit) so we don't need DOM lib types in this server-side SDK.\n let body: string | FormData | undefined\n if (req.formData) {\n body = req.formData\n } else if (req.body !== undefined) {\n headers['Content-Type'] = 'application/json'\n body = JSON.stringify(req.body)\n }\n\n const reqTimeout = req.timeoutMs ?? timeoutMs\n let lastErr: unknown\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), reqTimeout)\n const started = Date.now()\n try {\n const res = await fetchImpl(url, {\n method: req.method,\n headers,\n body,\n signal: controller.signal,\n })\n const durationMs = Date.now() - started\n opts.onRequest?.({\n method: req.method,\n url,\n status: res.status,\n durationMs,\n attempt: attempt + 1,\n })\n\n if (res.ok) {\n // 204 No Content — some endpoints (DELETE webhooks) return nothing.\n if (res.status === 204) return undefined as T\n const ct = res.headers.get('content-type') ?? ''\n if (ct.includes('application/json')) {\n return (await res.json()) as T\n }\n // Non-JSON 2xx — rare. Return raw text cast as T.\n return (await res.text()) as unknown as T\n }\n\n // Retryable error: back off + retry up to maxRetries.\n if (isRetryable(res.status) && attempt < maxRetries) {\n const retryAfter = res.headers.get('Retry-After')\n const backoff = retryAfter ? Number(retryAfter) * 1000 : 250 * Math.pow(2, attempt)\n await sleep(backoff)\n continue\n }\n\n throw await errorFromResponse(res)\n } catch (err) {\n if (err instanceof PlatformError) throw err\n // AbortError / network / DNS failures — retry up to maxRetries.\n if (attempt < maxRetries) {\n lastErr = err\n await sleep(250 * Math.pow(2, attempt))\n continue\n }\n const msg = err instanceof Error ? err.message : 'network error'\n throw new PlatformError({\n code: 'unknown',\n message: `Network error: ${msg}`,\n status: 0,\n })\n } finally {\n clearTimeout(timer)\n }\n }\n\n // Should be unreachable — the loop either returns, throws, or continues.\n throw lastErr instanceof Error ? lastErr : new Error('request exhausted retries')\n }\n\n return { request }\n}\n\nexport type HttpClient = ReturnType<typeof createHttpClient>\n","import type { HttpClient } from '../http'\nimport type { MeResponse } from '../types'\n\nexport const createMeResource = (http: HttpClient) => ({\n // Smoke test — confirms the API key is valid and returns the org + balance.\n // Most consumers use this as a ping on startup.\n get: async (): Promise<MeResponse> => http.request<MeResponse>({ method: 'GET', path: '/v1/me' }),\n})\n\nexport type MeResource = ReturnType<typeof createMeResource>\n","import type { HttpClient } from '../http'\nimport type {\n WebhookConfig,\n WebhookCreateInput,\n WebhookDelivery,\n WebhookUpdateInput,\n} from '../types'\n\n// Per-agent webhook resource, scoped at factory time to a specific agentId.\n// All endpoints mirror /v1/agents/:agentId/webhooks[/:id].\n\nexport const createAgentWebhooksResource = (http: HttpClient, agentId: string) => ({\n // Returns the webhook + its signing secret. The secret is only present in\n // this response — persist immediately, subsequent GETs omit it. Use the\n // secret to verify `X-Platform-Signature-256` (sha256=hex HMAC over body).\n create: async (input: WebhookCreateInput): Promise<WebhookConfig> =>\n http.request<WebhookConfig>({\n method: 'POST',\n path: `/v1/agents/${agentId}/webhooks`,\n body: input,\n }),\n\n list: async (): Promise<WebhookConfig[]> => {\n const res = await http.request<{ data: WebhookConfig[] }>({\n method: 'GET',\n path: `/v1/agents/${agentId}/webhooks`,\n })\n return res.data\n },\n\n get: async (webhookId: string): Promise<WebhookConfig> =>\n http.request<WebhookConfig>({\n method: 'GET',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}`,\n }),\n\n update: async (webhookId: string, patch: WebhookUpdateInput): Promise<WebhookConfig> =>\n http.request<WebhookConfig>({\n method: 'PATCH',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}`,\n body: patch,\n }),\n\n delete: async (webhookId: string): Promise<void> =>\n http.request<void>({\n method: 'DELETE',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}`,\n }),\n\n // Fires a synthetic call.started against this webhook and returns the\n // full delivery record (including attempt status codes) once the retry\n // sequence has finished. Useful during setup to verify receiver wiring.\n test: async (webhookId: string): Promise<WebhookDelivery> =>\n http.request<WebhookDelivery>({\n method: 'POST',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}/test`,\n }),\n})\n\nexport type AgentWebhooksResource = ReturnType<typeof createAgentWebhooksResource>\n","import type { HttpClient } from '../http'\nimport type { Agent, AgentCreateInput, AgentUpdateInput } from '../types'\nimport { createAgentWebhooksResource, type AgentWebhooksResource } from './agentWebhooks'\n\n// The server returns Agent with `apiKey` stripped and `hasApiKey: boolean`\n// on the model. We type the happy path but keep our input type permissive\n// so consumers can POST a plaintext `apiKey` that the server encrypts +\n// swaps for `apiKeySecret` on persistence.\n\nexport const createAgentsResource = (http: HttpClient) => {\n const agents = {\n create: async (input: AgentCreateInput): Promise<Agent> =>\n http.request<Agent>({ method: 'POST', path: '/v1/agents', body: input }),\n\n list: async (): Promise<Agent[]> => {\n const res = await http.request<{ data: Agent[] }>({ method: 'GET', path: '/v1/agents' })\n return res.data\n },\n\n // Async iterator for \"give me every agent\" — v1 server returns the full\n // list in one page, so this is just a thin convenience. When the server\n // picks up cursor pagination, this is the method that papers over that\n // migration without consumer changes.\n listAll: async function* (): AsyncIterable<Agent> {\n const page = await agents.list()\n for (const a of page) yield a\n },\n\n get: async (agentId: string): Promise<Agent> =>\n http.request<Agent>({ method: 'GET', path: `/v1/agents/${agentId}` }),\n\n update: async (agentId: string, patch: AgentUpdateInput): Promise<Agent> =>\n http.request<Agent>({ method: 'PATCH', path: `/v1/agents/${agentId}`, body: patch }),\n\n delete: async (agentId: string): Promise<void> =>\n http.request<void>({ method: 'DELETE', path: `/v1/agents/${agentId}` }),\n\n /**\n * Upload an avatar image for the agent. Server re-encodes to a 512×512\n * WebP and stores it in the public-read avatars bucket; the returned\n * `Agent` has `avatarUrl` set to the canonical public URL with a\n * `?v=` cache-buster.\n *\n * `file` accepts a Node Buffer / Uint8Array / Blob / typed-array.\n * `filename` and `contentType` are optional but help the server log\n * meaningful errors when something rejects.\n */\n uploadAvatar: async (\n agentId: string,\n file: Buffer | Uint8Array | Blob | ArrayBuffer,\n opts: { filename?: string; contentType?: string } = {},\n ): Promise<Agent> => {\n const fd = new FormData()\n const blob =\n file instanceof Blob\n ? file\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new Blob([file as any], { type: opts.contentType ?? 'application/octet-stream' })\n fd.append('file', blob, opts.filename ?? 'avatar')\n return http.request<Agent>({\n method: 'POST',\n path: `/v1/agents/${agentId}/avatar`,\n formData: fd,\n })\n },\n\n /**\n * Remove the agent's avatar — both the GCS object and the `avatarUrl`\n * field. Idempotent: calling on an agent without an avatar still\n * returns the agent.\n */\n removeAvatar: async (agentId: string): Promise<Agent> =>\n http.request<Agent>({ method: 'DELETE', path: `/v1/agents/${agentId}/avatar` }),\n\n // Nested resource. Per-agent webhook CRUD lives at\n // /v1/agents/:agentId/webhooks/* — we expose it as a factory keyed on\n // agentId so consumers can bind once and reuse:\n //\n // const hooks = client.agents.webhooks(myAgentId)\n // await hooks.create({ url, events })\n // await hooks.list()\n webhooks: (agentId: string): AgentWebhooksResource =>\n createAgentWebhooksResource(http, agentId),\n }\n return agents\n}\n\nexport type AgentsResource = ReturnType<typeof createAgentsResource>\n","import type { HttpClient } from '../http'\nimport type {\n CallListFilters,\n CallRecord,\n CallRecordingUrlResponse,\n CallSummary,\n TranscriptTurn,\n} from '../types'\n\nexport const createCallsResource = (http: HttpClient) => {\n const calls = {\n list: async (filters: CallListFilters = {}): Promise<CallSummary[]> => {\n const res = await http.request<{ data: CallSummary[] }>({\n method: 'GET',\n path: '/v1/calls',\n query: filters as Record<string, string | number | undefined>,\n })\n return res.data\n },\n\n // Auto-pagination helper. v1 server caps at limit (max 200) in a single\n // page — consumers who ask for \"every call since X\" get that page, the\n // iterator ends. This is the shape we'd extend with cursor support\n // without breaking callers.\n listAll: async function* (filters: CallListFilters = {}): AsyncIterable<CallSummary> {\n const page = await calls.list(filters)\n for (const c of page) yield c\n },\n\n get: async (callId: string): Promise<CallRecord> =>\n http.request<CallRecord>({ method: 'GET', path: `/v1/calls/${callId}` }),\n\n transcript: async (callId: string): Promise<{ callId: string; transcript: TranscriptTurn[] }> =>\n http.request<{ callId: string; transcript: TranscriptTurn[] }>({\n method: 'GET',\n path: `/v1/calls/${callId}/transcript`,\n }),\n\n // Returns a V4 signed URL (1-hour TTL). `ready: false` + `artifact:\n // 'caller-raw'` means the async mix job hasn't finished — the URL still\n // points at a playable file (raw caller PCM).\n recording: async (callId: string): Promise<CallRecordingUrlResponse> =>\n http.request<CallRecordingUrlResponse>({\n method: 'GET',\n path: `/v1/calls/${callId}/recording`,\n }),\n\n // Outbound dialling (POST /v1/calls) + in-call control are Phase 1.4.4 /\n // 1.4.5 respectively — blocked on telephony. Surface clear \"not built\n // yet\" errors here if consumers guess those method names, so they don't\n // silently hit a non-existent endpoint and wonder why it 404s.\n }\n return calls\n}\n\nexport type CallsResource = ReturnType<typeof createCallsResource>\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { HttpClient } from '../http'\nimport type { KnowledgeBase, KnowledgeBaseFile } from '../types'\n\nexport const createKnowledgeBasesResource = (http: HttpClient) => ({\n create: async (name: string): Promise<KnowledgeBase> =>\n http.request<KnowledgeBase>({\n method: 'POST',\n path: '/v1/knowledge-bases',\n body: { name },\n }),\n\n list: async (): Promise<KnowledgeBase[]> => {\n const res = await http.request<{ data: KnowledgeBase[] }>({\n method: 'GET',\n path: '/v1/knowledge-bases',\n })\n return res.data\n },\n\n get: async (kbId: string): Promise<KnowledgeBase> =>\n http.request<KnowledgeBase>({ method: 'GET', path: `/v1/knowledge-bases/${kbId}` }),\n\n delete: async (kbId: string): Promise<void> =>\n http.request<void>({ method: 'DELETE', path: `/v1/knowledge-bases/${kbId}` }),\n\n // File upload — accepts either a local file path OR raw bytes + filename.\n // The server ingests synchronously today (Phase 3.1.4 Cloud Tasks is a\n // followup), so the returned file has status='ready' in most cases.\n uploadFile: async (\n kbId: string,\n source:\n | { path: string; filename?: string; mimeType?: string }\n | { data: Buffer | Uint8Array; filename: string; mimeType?: string },\n ): Promise<KnowledgeBaseFile> => {\n const form = new FormData()\n let blob: Blob\n let filename: string\n let mime: string\n\n if ('path' in source) {\n const buf = await fs.promises.readFile(source.path)\n filename = source.filename ?? path.basename(source.path)\n mime = source.mimeType ?? 'application/octet-stream'\n blob = new Blob([new Uint8Array(buf)], { type: mime })\n } else {\n filename = source.filename\n mime = source.mimeType ?? 'application/octet-stream'\n const bytes = source.data instanceof Buffer ? new Uint8Array(source.data) : source.data\n blob = new Blob([bytes], { type: mime })\n }\n form.append('file', blob, filename)\n\n // File uploads can take a while (OCR, chunking, embedding) — give them\n // room before timing out. 5 min cap matches the server's own\n // processing budget.\n return http.request<KnowledgeBaseFile>({\n method: 'POST',\n path: `/v1/knowledge-bases/${kbId}/files`,\n formData: form,\n timeoutMs: 5 * 60 * 1000,\n })\n },\n\n listFiles: async (kbId: string): Promise<KnowledgeBaseFile[]> => {\n const res = await http.request<{ data: KnowledgeBaseFile[] }>({\n method: 'GET',\n path: `/v1/knowledge-bases/${kbId}/files`,\n })\n return res.data\n },\n\n deleteFile: async (kbId: string, fileId: string): Promise<void> =>\n http.request<void>({\n method: 'DELETE',\n path: `/v1/knowledge-bases/${kbId}/files/${fileId}`,\n }),\n})\n\nexport type KnowledgeBasesResource = ReturnType<typeof createKnowledgeBasesResource>\n","import type { HttpClient } from '../http'\nimport type { LedgerEntry } from '../types'\n\nexport const createCreditsResource = (http: HttpClient) => {\n const credits = {\n getBalance: async (): Promise<{ orgId: string; balanceCents: number }> =>\n http.request<{ orgId: string; balanceCents: number }>({\n method: 'GET',\n path: '/v1/credits/balance',\n }),\n\n // Returns ledger entries newest-first. `limit` is capped at 500 server-side.\n getLedger: async (opts: { limit?: number } = {}): Promise<LedgerEntry[]> => {\n const res = await http.request<{ data: LedgerEntry[] }>({\n method: 'GET',\n path: '/v1/credits/ledger',\n query: opts as Record<string, string | number | undefined>,\n })\n return res.data\n },\n\n // Auto-pagination scaffold — v1 server returns a single page up to\n // limit=500. When cursor pagination lands this is where it gets wired.\n getLedgerAll: async function* (opts: { limit?: number } = {}): AsyncIterable<LedgerEntry> {\n const page = await credits.getLedger(opts)\n for (const e of page) yield e\n },\n }\n return credits\n}\n\nexport type CreditsResource = ReturnType<typeof createCreditsResource>\n","import type { HttpClient } from '../http'\nimport type { CallTokenMintInput, CallTokenMintResult, CallTokenSummary } from '../types'\n\n// Short-lived, agent-scoped `ct_` tokens. Mint one per user session on your\n// backend, hand the raw value to the browser; let this SDK handle lifecycle\n// (revoke on sign-out, list active tokens for an admin panel).\n\nexport const createCallTokensResource = (http: HttpClient) => ({\n // Returns the RAW token value once. Don't log it; pass it straight to the\n // browser + discard server-side. `tokenId` is the stable public handle\n // used for revocation later.\n mint: async (input: CallTokenMintInput): Promise<CallTokenMintResult> =>\n http.request<CallTokenMintResult>({\n method: 'POST',\n path: '/v1/call-tokens',\n body: input,\n }),\n\n // Live tokens only by default. Pass includeRevoked/includeExpired when\n // debugging \"why did my token stop working\".\n list: async (\n opts: { includeRevoked?: boolean; includeExpired?: boolean; limit?: number } = {},\n ): Promise<CallTokenSummary[]> => {\n const query: Record<string, string | number | undefined> = {}\n if (opts.includeRevoked) query.includeRevoked = '1'\n if (opts.includeExpired) query.includeExpired = '1'\n if (opts.limit !== undefined) query.limit = opts.limit\n const res = await http.request<{ data: CallTokenSummary[] }>({\n method: 'GET',\n path: '/v1/call-tokens',\n query,\n })\n return res.data\n },\n\n // Idempotent — re-revoking a revoked token returns `alreadyRevoked: true`.\n revoke: async (\n tokenId: string,\n ): Promise<{ tokenId: string; revoked: boolean; alreadyRevoked?: boolean }> =>\n http.request<{ tokenId: string; revoked: boolean; alreadyRevoked?: boolean }>({\n method: 'DELETE',\n path: `/v1/call-tokens/${tokenId}`,\n }),\n})\n\nexport type CallTokensResource = ReturnType<typeof createCallTokensResource>\n","import type { HttpClient } from '../http'\nimport type { WebhookDelivery } from '../types'\n\n// Org-wide webhook delivery log. Per-agent CRUD lives on\n// `client.agents.webhooks(agentId)` — this namespace is just the\n// read-only deliveries surface that spans all agents.\n\nexport const createWebhooksResource = (http: HttpClient) => ({\n deliveries: async (\n filters: {\n agentId?: string\n webhookId?: string\n callId?: string\n limit?: number\n } = {},\n ): Promise<WebhookDelivery[]> => {\n const res = await http.request<{ data: WebhookDelivery[] }>({\n method: 'GET',\n path: '/v1/webhooks/deliveries',\n query: filters as Record<string, string | number | undefined>,\n })\n return res.data\n },\n})\n\nexport type WebhooksResource = ReturnType<typeof createWebhooksResource>\n","import type { HttpClient } from '../http'\nimport type { CatalogAgent, CatalogListInput } from '../types'\n\n// Org-scoped consumer endpoints. Today this is just the agent catalog —\n// the trimmed shape your mobile app picks an agent from. Lives at\n// `/v1/orgs/:orgId/agents` rather than reusing the admin `/v1/agents/*`\n// tree on purpose: the catalog response intentionally excludes the\n// operator-only fields (system prompt, tools, KB IDs) so a leaked\n// consumer-backend `sk_` can't lift the operator config out of it.\n//\n// Pattern from your backend:\n//\n// const client = new PlatformClient({ apiKey: process.env.SK })\n// const visible = await client.orgs.listAgents({\n// orgId: process.env.ORG_ID!,\n// userTags: ['tier1'], // omit to get the unfiltered admin view\n// })\n// res.json(visible)\n\nexport const createOrgsResource = (http: HttpClient) => ({\n /**\n * Fetch the agent catalog for an org. Returns the consumer-trimmed shape;\n * no system prompt, tools, or KB info. Use `client.agents.get(agentId)`\n * with the same `sk_` if you need the full admin shape.\n *\n * `userTags`: end-user entitlement tags. When supplied, hides agents\n * whose `allowedUserTags` is non-empty and doesn't intersect with the\n * supplied list. Omit to get the unfiltered admin view.\n *\n * Persona / category filtering is intentionally not a server param —\n * filter the returned list client-side over `name`s if you need it.\n *\n * Throws `403 forbidden` if `orgId` doesn't match the key's org.\n */\n listAgents: async (input: CatalogListInput): Promise<CatalogAgent[]> => {\n const query: Record<string, string | undefined> = {}\n if (input.userTags && input.userTags.length > 0) query.userTags = input.userTags.join(',')\n const res = await http.request<{ data: CatalogAgent[] }>({\n method: 'GET',\n path: `/v1/orgs/${input.orgId}/agents`,\n query,\n })\n return res.data\n },\n})\n\nexport type OrgsResource = ReturnType<typeof createOrgsResource>\n","import { createHttpClient, type HttpClientOptions } from './http'\nimport { createMeResource, type MeResource } from './resources/me'\nimport { createAgentsResource, type AgentsResource } from './resources/agents'\nimport { createCallsResource, type CallsResource } from './resources/calls'\nimport {\n createKnowledgeBasesResource,\n type KnowledgeBasesResource,\n} from './resources/knowledgeBases'\nimport { createCreditsResource, type CreditsResource } from './resources/credits'\nimport { createCallTokensResource, type CallTokensResource } from './resources/callTokens'\nimport { createWebhooksResource, type WebhooksResource } from './resources/webhooks'\nimport { createOrgsResource, type OrgsResource } from './resources/orgs'\n\nexport interface PlatformClientOptions {\n // Full-org API key minted from the dashboard or bootstrap CLI. Start with\n // `sk_`. Never ship to a browser — use `client.callTokens.mint(...)` to\n // generate a narrow `ct_` token for client-side use instead.\n apiKey: string\n // Defaults to the hosted platform. Point at `http://localhost:8080` for\n // local dev or at a self-hosted deployment.\n baseUrl?: string\n // Passthrough tuning for the HTTP layer.\n timeoutMs?: number\n maxRetries?: number\n fetch?: HttpClientOptions['fetch']\n onRequest?: HttpClientOptions['onRequest']\n}\n\n// Single entry point. All resources are lazy-constructed in the constructor\n// so their refs don't incur any per-call allocation. Shape mirrors Stripe /\n// Twilio / Vapi's `resource.method()` convention for familiarity.\nexport class PlatformClient {\n readonly me: MeResource\n readonly agents: AgentsResource\n readonly calls: CallsResource\n readonly knowledgeBases: KnowledgeBasesResource\n readonly credits: CreditsResource\n readonly callTokens: CallTokensResource\n readonly webhooks: WebhooksResource\n readonly orgs: OrgsResource\n\n constructor(options: PlatformClientOptions) {\n if (!options.apiKey) {\n throw new Error('PlatformClient: `apiKey` is required')\n }\n const http = createHttpClient({\n apiKey: options.apiKey,\n baseUrl: options.baseUrl ?? 'https://api.example.com',\n timeoutMs: options.timeoutMs,\n maxRetries: options.maxRetries,\n fetch: options.fetch,\n onRequest: options.onRequest,\n })\n\n this.me = createMeResource(http)\n this.agents = createAgentsResource(http)\n this.calls = createCallsResource(http)\n this.knowledgeBases = createKnowledgeBasesResource(http)\n this.credits = createCreditsResource(http)\n this.callTokens = createCallTokensResource(http)\n this.webhooks = createWebhooksResource(http)\n this.orgs = createOrgsResource(http)\n }\n}\n","import crypto from 'node:crypto'\n\n// Helper for consumers receiving webhooks: verify the `X-Platform-Signature-256`\n// header against the raw body + secret. Plain function (not tied to\n// PlatformClient) so Express/Koa/Next.js middleware can use it without\n// instantiating a client.\n//\n// import { verifyWebhookSignature } from '@craftedxp/sdk-node'\n// app.post('/webhooks/voice-agent', express.raw({ type: 'application/json' }), (req, res) => {\n// const sig = req.header('X-Platform-Signature-256') ?? ''\n// if (!verifyWebhookSignature(req.body, sig, process.env.VOICE_AGENT_WEBHOOK_SECRET!)) {\n// return res.status(401).send('invalid signature')\n// }\n// const event = JSON.parse(req.body.toString('utf8'))\n// // ...handle event\n// })\n//\n// The signature is `sha256=<hex HMAC-SHA256 of rawBody with secret>`.\n// Timing-safe compare to avoid microtiming side channels.\n\nexport const verifyWebhookSignature = (\n rawBody: Buffer | string,\n signatureHeader: string,\n secret: string,\n): boolean => {\n if (!signatureHeader || !secret) return false\n const [algo, provided] = signatureHeader.split('=')\n if (algo !== 'sha256' || !provided) return false\n\n const expected = crypto\n .createHmac('sha256', secret)\n .update(typeof rawBody === 'string' ? rawBody : rawBody)\n .digest('hex')\n\n // Buffers must match in length for timingSafeEqual.\n const a = Buffer.from(expected, 'hex')\n const b = Buffer.from(provided, 'hex')\n if (a.length !== b.length) return false\n return crypto.timingSafeEqual(a, b)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBO,IAAM,gBAAN,MAAM,uBAAsB,MAAM;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA,EAET,YAAY,QAOT;AACD,UAAM,OAAO,OAAO;AACpB,SAAK,OAAO;AACZ,SAAK,OAAO,OAAO;AACnB,SAAK,SAAS,OAAO;AACrB,SAAK,QAAQ,OAAO;AACpB,SAAK,UAAU,OAAO;AACtB,SAAK,OAAO,OAAO;AAGnB,QACE,OAAQ,MAAyD,sBACjE,YACA;AACA;AAAC,MACC,MACA,kBAAkB,MAAM,cAAa;AAAA,IACzC;AAAA,EACF;AAAA,EAEA,SAAkC;AAChC,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,QAAQ,KAAK;AAAA,MACb,OAAO,KAAK;AAAA,MACZ,SAAS,KAAK;AAAA,IAChB;AAAA,EACF;AACF;;;ACtBA,IAAM,qBAAqB;AAC3B,IAAM,sBAAsB;AAE5B,IAAM,WAAW,CAAC,SAAiB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A,MACf,WAAW,QAAQ;AAAA,IACrB,CAAC;AAED,SAAK,KAAK,iBAAiB,IAAI;AAC/B,SAAK,SAAS,qBAAqB,IAAI;AACvC,SAAK,QAAQ,oBAAoB,IAAI;AACrC,SAAK,iBAAiB,6BAA6B,IAAI;AACvD,SAAK,UAAU,sBAAsB,IAAI;AACzC,SAAK,aAAa,yBAAyB,IAAI;AAC/C,SAAK,WAAW,uBAAuB,IAAI;AAC3C,SAAK,OAAO,mBAAmB,IAAI;AAAA,EACrC;AACF;;;AC/DA,yBAAmB;AAoBZ,IAAM,yBAAyB,CACpC,SACA,iBACA,WACY;AACZ,MAAI,CAAC,mBAAmB,CAAC,OAAQ,QAAO;AACxC,QAAM,CAAC,MAAM,QAAQ,IAAI,gBAAgB,MAAM,GAAG;AAClD,MAAI,SAAS,YAAY,CAAC,SAAU,QAAO;AAE3C,QAAM,WAAW,mBAAAC,QACd,WAAW,UAAU,MAAM,EAC3B,OAAO,OAAO,YAAY,WAAW,UAAU,OAAO,EACtD,OAAO,KAAK;AAGf,QAAM,IAAI,OAAO,KAAK,UAAU,KAAK;AACrC,QAAM,IAAI,OAAO,KAAK,UAAU,KAAK;AACrC,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,SAAO,mBAAAA,QAAO,gBAAgB,GAAG,CAAC;AACpC;","names":["path","fs","path","crypto"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/http.ts","../src/resources/me.ts","../src/resources/agentWebhooks.ts","../src/resources/agents.ts","../src/resources/calls.ts","../src/resources/knowledgeBases.ts","../src/resources/credits.ts","../src/resources/callTokens.ts","../src/resources/webhooks.ts","../src/resources/orgs.ts","../src/resources/rooms.ts","../src/PlatformClient.ts","../src/verify.ts"],"sourcesContent":["// Public API of @craftedxp/sdk-node.\n\nexport { PlatformClient } from './PlatformClient'\nexport type { PlatformClientOptions } from './PlatformClient'\n\n// Error class for `instanceof` checks in consumer code.\nexport { PlatformError } from './errors'\nexport type { ApiErrorCode } from './errors'\n\n// Webhook signature verification helper — standalone so frameworks\n// (Express, Koa, Next.js route handlers) can use it without instantiating\n// a PlatformClient.\nexport { verifyWebhookSignature } from './verify'\n\n// Re-export DTO types. Consumers often type their own storage models\n// against these — re-exporting avoids `import type` gymnastics.\nexport type * from './types'\n\n// Advanced: expose the resource types for consumers subclassing / wrapping\n// the client. 99% of users don't need these.\nexport type { MeResource } from './resources/me'\nexport type { AgentsResource } from './resources/agents'\nexport type { AgentWebhooksResource } from './resources/agentWebhooks'\nexport type { CallsResource } from './resources/calls'\nexport type { KnowledgeBasesResource } from './resources/knowledgeBases'\nexport type { CreditsResource } from './resources/credits'\nexport type { CallTokensResource } from './resources/callTokens'\nexport type { WebhooksResource } from './resources/webhooks'\nexport type { OrgsResource } from './resources/orgs'\nexport type { RoomsResource } from './resources/rooms'\n","// Typed error class mirroring the server's ErrorV1 shape:\n// { error: { code, message, field?, docs_url? } }\n//\n// Consumers do `err instanceof PlatformError` to branch on code without\n// parsing string messages. `status` carries the HTTP code for the 1% of\n// cases where the code field isn't enough (e.g. rate-limit → retry-after\n// header correlation).\n\nexport type ApiErrorCode =\n | 'unauthorized'\n | 'forbidden'\n | 'not_found'\n | 'bad_request'\n | 'conflict'\n | 'rate_limited'\n | 'payment_required'\n | 'internal_error'\n | 'unknown'\n\nexport class PlatformError extends Error {\n readonly code: ApiErrorCode\n readonly status: number\n readonly field?: string\n readonly docsUrl?: string\n // The raw response body for debugging. Intentionally optional — we clear\n // it on `error.toJSON()` so logging libraries don't dump the whole\n // server response into production logs.\n readonly body?: unknown\n\n constructor(params: {\n code: ApiErrorCode\n message: string\n status: number\n field?: string\n docsUrl?: string\n body?: unknown\n }) {\n super(params.message)\n this.name = 'PlatformError'\n this.code = params.code\n this.status = params.status\n this.field = params.field\n this.docsUrl = params.docsUrl\n this.body = params.body\n // Preserve the stack trace — Node's Error doesn't capture it\n // automatically when subclassing in some older runtimes.\n if (\n typeof (Error as typeof Error & { captureStackTrace?: unknown }).captureStackTrace ===\n 'function'\n ) {\n ;(\n Error as typeof Error & { captureStackTrace: (target: unknown, ctor: unknown) => void }\n ).captureStackTrace(this, PlatformError)\n }\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n status: this.status,\n field: this.field,\n docsUrl: this.docsUrl,\n }\n }\n}\n","import { PlatformError, type ApiErrorCode } from './errors'\n\n// Low-level HTTP wrapper around `fetch` (native in Node 18+). Every resource\n// method routes through here for consistent auth + error handling + retries.\n//\n// v1 scope: JSON-in / JSON-out + multipart for file uploads. No streaming —\n// call WebSockets go through @craftedxp/voice-rn (the React Native client)\n// or a web equivalent, not this server-side SDK.\n\nexport interface HttpClientOptions {\n apiKey: string\n baseUrl: string\n // Default 30s. File uploads can override per-request.\n timeoutMs?: number\n // 429 + 5xx retries. Defaults to 3 attempts (original + 2 retries) with\n // exponential backoff (250ms, 1s). Set to 0 to disable.\n maxRetries?: number\n // Optional — lets consumers swap in a test/mock fetch (or a custom one\n // with instrumentation). Defaults to the global.\n fetch?: typeof fetch\n // Optional — a callback that fires per-request with the final status and\n // duration. Handy for dropping traces into the consumer's observability\n // stack without wrapping each call.\n onRequest?: (info: {\n method: string\n url: string\n status: number\n durationMs: number\n attempt: number\n }) => void\n}\n\nexport interface HttpRequest {\n method: 'GET' | 'POST' | 'PATCH' | 'DELETE'\n path: string // starts with `/`, e.g. `/v1/agents/123`\n query?: Record<string, string | number | boolean | undefined>\n body?: unknown // JSON-serialised — for multipart use `formData`\n formData?: FormData\n timeoutMs?: number\n // Exposed for edge cases where a resource wants to tack on extra\n // headers (we don't have any today but leave the hook).\n headers?: Record<string, string>\n}\n\nconst DEFAULT_TIMEOUT_MS = 30_000\nconst DEFAULT_MAX_RETRIES = 2 // total attempts = 3\n\nconst buildUrl = (baseUrl: string, path: string, query?: HttpRequest['query']): string => {\n const u = new URL(path, baseUrl)\n if (query) {\n for (const [k, v] of Object.entries(query)) {\n if (v === undefined) continue\n u.searchParams.set(k, String(v))\n }\n }\n return u.toString()\n}\n\nconst sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms))\n\nconst isRetryable = (status: number): boolean => status === 429 || (status >= 500 && status < 600)\n\n// Parse whatever the server returned into a PlatformError. Falls back to\n// synthesising a sensible error for non-JSON responses.\nconst errorFromResponse = async (res: Response): Promise<PlatformError> => {\n const bodyText = await res.text().catch(() => '')\n let parsed: unknown = undefined\n try {\n parsed = bodyText ? JSON.parse(bodyText) : undefined\n } catch {\n // non-JSON response (e.g. an HTML error page from a proxy). Fall\n // through with parsed = undefined.\n }\n const errObj = (\n parsed as { error?: { code?: string; message?: string; field?: string; docs_url?: string } }\n )?.error\n return new PlatformError({\n code: (errObj?.code as ApiErrorCode) ?? 'unknown',\n message: errObj?.message ?? res.statusText ?? `HTTP ${res.status}`,\n status: res.status,\n field: errObj?.field,\n docsUrl: errObj?.docs_url,\n body: parsed ?? bodyText,\n })\n}\n\nexport const createHttpClient = (opts: HttpClientOptions) => {\n const fetchImpl = opts.fetch ?? globalThis.fetch\n const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS\n const maxRetries = opts.maxRetries ?? DEFAULT_MAX_RETRIES\n\n if (!fetchImpl) {\n throw new Error('No global fetch available. @craftedxp/sdk-node requires Node >= 18.')\n }\n\n const request = async <T>(req: HttpRequest): Promise<T> => {\n const url = buildUrl(opts.baseUrl, req.path, req.query)\n const headers: Record<string, string> = {\n Authorization: `Bearer ${opts.apiKey}`,\n Accept: 'application/json',\n ...(req.headers ?? {}),\n }\n\n // Body shaping: prefer formData when provided; otherwise JSON.\n // `FormData` sets its own Content-Type with boundary — don't preempt it.\n // Typed as `string | FormData | undefined` (a subset of the global\n // BodyInit) so we don't need DOM lib types in this server-side SDK.\n let body: string | FormData | undefined\n if (req.formData) {\n body = req.formData\n } else if (req.body !== undefined) {\n headers['Content-Type'] = 'application/json'\n body = JSON.stringify(req.body)\n }\n\n const reqTimeout = req.timeoutMs ?? timeoutMs\n let lastErr: unknown\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), reqTimeout)\n const started = Date.now()\n try {\n const res = await fetchImpl(url, {\n method: req.method,\n headers,\n body,\n signal: controller.signal,\n })\n const durationMs = Date.now() - started\n opts.onRequest?.({\n method: req.method,\n url,\n status: res.status,\n durationMs,\n attempt: attempt + 1,\n })\n\n if (res.ok) {\n // 204 No Content — some endpoints (DELETE webhooks) return nothing.\n if (res.status === 204) return undefined as T\n const ct = res.headers.get('content-type') ?? ''\n if (ct.includes('application/json')) {\n return (await res.json()) as T\n }\n // Non-JSON 2xx — rare. Return raw text cast as T.\n return (await res.text()) as unknown as T\n }\n\n // Retryable error: back off + retry up to maxRetries.\n if (isRetryable(res.status) && attempt < maxRetries) {\n const retryAfter = res.headers.get('Retry-After')\n const backoff = retryAfter ? Number(retryAfter) * 1000 : 250 * Math.pow(2, attempt)\n await sleep(backoff)\n continue\n }\n\n throw await errorFromResponse(res)\n } catch (err) {\n if (err instanceof PlatformError) throw err\n // AbortError / network / DNS failures — retry up to maxRetries.\n if (attempt < maxRetries) {\n lastErr = err\n await sleep(250 * Math.pow(2, attempt))\n continue\n }\n const msg = err instanceof Error ? err.message : 'network error'\n throw new PlatformError({\n code: 'unknown',\n message: `Network error: ${msg}`,\n status: 0,\n })\n } finally {\n clearTimeout(timer)\n }\n }\n\n // Should be unreachable — the loop either returns, throws, or continues.\n throw lastErr instanceof Error ? lastErr : new Error('request exhausted retries')\n }\n\n return { request }\n}\n\nexport type HttpClient = ReturnType<typeof createHttpClient>\n","import type { HttpClient } from '../http'\nimport type { MeResponse } from '../types'\n\nexport const createMeResource = (http: HttpClient) => ({\n // Smoke test — confirms the API key is valid and returns the org + balance.\n // Most consumers use this as a ping on startup.\n get: async (): Promise<MeResponse> => http.request<MeResponse>({ method: 'GET', path: '/v1/me' }),\n})\n\nexport type MeResource = ReturnType<typeof createMeResource>\n","import type { HttpClient } from '../http'\nimport type {\n WebhookConfig,\n WebhookCreateInput,\n WebhookDelivery,\n WebhookUpdateInput,\n} from '../types'\n\n// Per-agent webhook resource, scoped at factory time to a specific agentId.\n// All endpoints mirror /v1/agents/:agentId/webhooks[/:id].\n\nexport const createAgentWebhooksResource = (http: HttpClient, agentId: string) => ({\n // Returns the webhook + its signing secret. The secret is only present in\n // this response — persist immediately, subsequent GETs omit it. Use the\n // secret to verify `X-Platform-Signature-256` (sha256=hex HMAC over body).\n create: async (input: WebhookCreateInput): Promise<WebhookConfig> =>\n http.request<WebhookConfig>({\n method: 'POST',\n path: `/v1/agents/${agentId}/webhooks`,\n body: input,\n }),\n\n list: async (): Promise<WebhookConfig[]> => {\n const res = await http.request<{ data: WebhookConfig[] }>({\n method: 'GET',\n path: `/v1/agents/${agentId}/webhooks`,\n })\n return res.data\n },\n\n get: async (webhookId: string): Promise<WebhookConfig> =>\n http.request<WebhookConfig>({\n method: 'GET',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}`,\n }),\n\n update: async (webhookId: string, patch: WebhookUpdateInput): Promise<WebhookConfig> =>\n http.request<WebhookConfig>({\n method: 'PATCH',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}`,\n body: patch,\n }),\n\n delete: async (webhookId: string): Promise<void> =>\n http.request<void>({\n method: 'DELETE',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}`,\n }),\n\n // Fires a synthetic call.started against this webhook and returns the\n // full delivery record (including attempt status codes) once the retry\n // sequence has finished. Useful during setup to verify receiver wiring.\n test: async (webhookId: string): Promise<WebhookDelivery> =>\n http.request<WebhookDelivery>({\n method: 'POST',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}/test`,\n }),\n})\n\nexport type AgentWebhooksResource = ReturnType<typeof createAgentWebhooksResource>\n","import type { HttpClient } from '../http'\nimport type { Agent, AgentCreateInput, AgentUpdateInput } from '../types'\nimport { createAgentWebhooksResource, type AgentWebhooksResource } from './agentWebhooks'\n\n// The server returns Agent with `apiKey` stripped and `hasApiKey: boolean`\n// on the model. We type the happy path but keep our input type permissive\n// so consumers can POST a plaintext `apiKey` that the server encrypts +\n// swaps for `apiKeySecret` on persistence.\n\nexport const createAgentsResource = (http: HttpClient) => {\n const agents = {\n create: async (input: AgentCreateInput): Promise<Agent> =>\n http.request<Agent>({ method: 'POST', path: '/v1/agents', body: input }),\n\n list: async (): Promise<Agent[]> => {\n const res = await http.request<{ data: Agent[] }>({ method: 'GET', path: '/v1/agents' })\n return res.data\n },\n\n // Async iterator for \"give me every agent\" — v1 server returns the full\n // list in one page, so this is just a thin convenience. When the server\n // picks up cursor pagination, this is the method that papers over that\n // migration without consumer changes.\n listAll: async function* (): AsyncIterable<Agent> {\n const page = await agents.list()\n for (const a of page) yield a\n },\n\n get: async (agentId: string): Promise<Agent> =>\n http.request<Agent>({ method: 'GET', path: `/v1/agents/${agentId}` }),\n\n update: async (agentId: string, patch: AgentUpdateInput): Promise<Agent> =>\n http.request<Agent>({ method: 'PATCH', path: `/v1/agents/${agentId}`, body: patch }),\n\n delete: async (agentId: string): Promise<void> =>\n http.request<void>({ method: 'DELETE', path: `/v1/agents/${agentId}` }),\n\n /**\n * Upload an avatar image for the agent. Server re-encodes to a 512×512\n * WebP and stores it in the public-read avatars bucket; the returned\n * `Agent` has `avatarUrl` set to the canonical public URL with a\n * `?v=` cache-buster.\n *\n * `file` accepts a Node Buffer / Uint8Array / Blob / typed-array.\n * `filename` and `contentType` are optional but help the server log\n * meaningful errors when something rejects.\n */\n uploadAvatar: async (\n agentId: string,\n file: Buffer | Uint8Array | Blob | ArrayBuffer,\n opts: { filename?: string; contentType?: string } = {},\n ): Promise<Agent> => {\n const fd = new FormData()\n const blob =\n file instanceof Blob\n ? file\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new Blob([file as any], { type: opts.contentType ?? 'application/octet-stream' })\n fd.append('file', blob, opts.filename ?? 'avatar')\n return http.request<Agent>({\n method: 'POST',\n path: `/v1/agents/${agentId}/avatar`,\n formData: fd,\n })\n },\n\n /**\n * Remove the agent's avatar — both the GCS object and the `avatarUrl`\n * field. Idempotent: calling on an agent without an avatar still\n * returns the agent.\n */\n removeAvatar: async (agentId: string): Promise<Agent> =>\n http.request<Agent>({ method: 'DELETE', path: `/v1/agents/${agentId}/avatar` }),\n\n // Nested resource. Per-agent webhook CRUD lives at\n // /v1/agents/:agentId/webhooks/* — we expose it as a factory keyed on\n // agentId so consumers can bind once and reuse:\n //\n // const hooks = client.agents.webhooks(myAgentId)\n // await hooks.create({ url, events })\n // await hooks.list()\n webhooks: (agentId: string): AgentWebhooksResource =>\n createAgentWebhooksResource(http, agentId),\n }\n return agents\n}\n\nexport type AgentsResource = ReturnType<typeof createAgentsResource>\n","import type { HttpClient } from '../http'\nimport type {\n CallListFilters,\n CallRecord,\n CallRecordingUrlResponse,\n CallSummary,\n TranscriptTurn,\n} from '../types'\n\nexport const createCallsResource = (http: HttpClient) => {\n const calls = {\n list: async (filters: CallListFilters = {}): Promise<CallSummary[]> => {\n const res = await http.request<{ data: CallSummary[] }>({\n method: 'GET',\n path: '/v1/calls',\n query: filters as Record<string, string | number | undefined>,\n })\n return res.data\n },\n\n // Auto-pagination helper. v1 server caps at limit (max 200) in a single\n // page — consumers who ask for \"every call since X\" get that page, the\n // iterator ends. This is the shape we'd extend with cursor support\n // without breaking callers.\n listAll: async function* (filters: CallListFilters = {}): AsyncIterable<CallSummary> {\n const page = await calls.list(filters)\n for (const c of page) yield c\n },\n\n get: async (callId: string): Promise<CallRecord> =>\n http.request<CallRecord>({ method: 'GET', path: `/v1/calls/${callId}` }),\n\n transcript: async (callId: string): Promise<{ callId: string; transcript: TranscriptTurn[] }> =>\n http.request<{ callId: string; transcript: TranscriptTurn[] }>({\n method: 'GET',\n path: `/v1/calls/${callId}/transcript`,\n }),\n\n // Returns a V4 signed URL (1-hour TTL). `ready: false` + `artifact:\n // 'caller-raw'` means the async mix job hasn't finished — the URL still\n // points at a playable file (raw caller PCM).\n recording: async (callId: string): Promise<CallRecordingUrlResponse> =>\n http.request<CallRecordingUrlResponse>({\n method: 'GET',\n path: `/v1/calls/${callId}/recording`,\n }),\n\n // Outbound dialling (POST /v1/calls) + in-call control are Phase 1.4.4 /\n // 1.4.5 respectively — blocked on telephony. Surface clear \"not built\n // yet\" errors here if consumers guess those method names, so they don't\n // silently hit a non-existent endpoint and wonder why it 404s.\n }\n return calls\n}\n\nexport type CallsResource = ReturnType<typeof createCallsResource>\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { HttpClient } from '../http'\nimport type { KnowledgeBase, KnowledgeBaseFile } from '../types'\n\nexport const createKnowledgeBasesResource = (http: HttpClient) => ({\n create: async (name: string): Promise<KnowledgeBase> =>\n http.request<KnowledgeBase>({\n method: 'POST',\n path: '/v1/knowledge-bases',\n body: { name },\n }),\n\n list: async (): Promise<KnowledgeBase[]> => {\n const res = await http.request<{ data: KnowledgeBase[] }>({\n method: 'GET',\n path: '/v1/knowledge-bases',\n })\n return res.data\n },\n\n get: async (kbId: string): Promise<KnowledgeBase> =>\n http.request<KnowledgeBase>({ method: 'GET', path: `/v1/knowledge-bases/${kbId}` }),\n\n delete: async (kbId: string): Promise<void> =>\n http.request<void>({ method: 'DELETE', path: `/v1/knowledge-bases/${kbId}` }),\n\n // File upload — accepts either a local file path OR raw bytes + filename.\n // The server ingests synchronously today (Phase 3.1.4 Cloud Tasks is a\n // followup), so the returned file has status='ready' in most cases.\n uploadFile: async (\n kbId: string,\n source:\n | { path: string; filename?: string; mimeType?: string }\n | { data: Buffer | Uint8Array; filename: string; mimeType?: string },\n ): Promise<KnowledgeBaseFile> => {\n const form = new FormData()\n let blob: Blob\n let filename: string\n let mime: string\n\n if ('path' in source) {\n const buf = await fs.promises.readFile(source.path)\n filename = source.filename ?? path.basename(source.path)\n mime = source.mimeType ?? 'application/octet-stream'\n blob = new Blob([new Uint8Array(buf)], { type: mime })\n } else {\n filename = source.filename\n mime = source.mimeType ?? 'application/octet-stream'\n const bytes = source.data instanceof Buffer ? new Uint8Array(source.data) : source.data\n blob = new Blob([bytes], { type: mime })\n }\n form.append('file', blob, filename)\n\n // File uploads can take a while (OCR, chunking, embedding) — give them\n // room before timing out. 5 min cap matches the server's own\n // processing budget.\n return http.request<KnowledgeBaseFile>({\n method: 'POST',\n path: `/v1/knowledge-bases/${kbId}/files`,\n formData: form,\n timeoutMs: 5 * 60 * 1000,\n })\n },\n\n listFiles: async (kbId: string): Promise<KnowledgeBaseFile[]> => {\n const res = await http.request<{ data: KnowledgeBaseFile[] }>({\n method: 'GET',\n path: `/v1/knowledge-bases/${kbId}/files`,\n })\n return res.data\n },\n\n deleteFile: async (kbId: string, fileId: string): Promise<void> =>\n http.request<void>({\n method: 'DELETE',\n path: `/v1/knowledge-bases/${kbId}/files/${fileId}`,\n }),\n})\n\nexport type KnowledgeBasesResource = ReturnType<typeof createKnowledgeBasesResource>\n","import type { HttpClient } from '../http'\nimport type { LedgerEntry } from '../types'\n\nexport const createCreditsResource = (http: HttpClient) => {\n const credits = {\n getBalance: async (): Promise<{ orgId: string; balanceCents: number }> =>\n http.request<{ orgId: string; balanceCents: number }>({\n method: 'GET',\n path: '/v1/credits/balance',\n }),\n\n // Returns ledger entries newest-first. `limit` is capped at 500 server-side.\n getLedger: async (opts: { limit?: number } = {}): Promise<LedgerEntry[]> => {\n const res = await http.request<{ data: LedgerEntry[] }>({\n method: 'GET',\n path: '/v1/credits/ledger',\n query: opts as Record<string, string | number | undefined>,\n })\n return res.data\n },\n\n // Auto-pagination scaffold — v1 server returns a single page up to\n // limit=500. When cursor pagination lands this is where it gets wired.\n getLedgerAll: async function* (opts: { limit?: number } = {}): AsyncIterable<LedgerEntry> {\n const page = await credits.getLedger(opts)\n for (const e of page) yield e\n },\n }\n return credits\n}\n\nexport type CreditsResource = ReturnType<typeof createCreditsResource>\n","import type { HttpClient } from '../http'\nimport type { CallTokenMintInput, CallTokenMintResult, CallTokenSummary } from '../types'\n\n// Short-lived, agent-scoped `ct_` tokens. Mint one per user session on your\n// backend, hand the raw value to the browser; let this SDK handle lifecycle\n// (revoke on sign-out, list active tokens for an admin panel).\n\nexport const createCallTokensResource = (http: HttpClient) => ({\n // Returns the RAW token value once. Don't log it; pass it straight to the\n // browser + discard server-side. `tokenId` is the stable public handle\n // used for revocation later.\n mint: async (input: CallTokenMintInput): Promise<CallTokenMintResult> =>\n http.request<CallTokenMintResult>({\n method: 'POST',\n path: '/v1/call-tokens',\n body: input,\n }),\n\n // Live tokens only by default. Pass includeRevoked/includeExpired when\n // debugging \"why did my token stop working\".\n list: async (\n opts: { includeRevoked?: boolean; includeExpired?: boolean; limit?: number } = {},\n ): Promise<CallTokenSummary[]> => {\n const query: Record<string, string | number | undefined> = {}\n if (opts.includeRevoked) query.includeRevoked = '1'\n if (opts.includeExpired) query.includeExpired = '1'\n if (opts.limit !== undefined) query.limit = opts.limit\n const res = await http.request<{ data: CallTokenSummary[] }>({\n method: 'GET',\n path: '/v1/call-tokens',\n query,\n })\n return res.data\n },\n\n // Idempotent — re-revoking a revoked token returns `alreadyRevoked: true`.\n revoke: async (\n tokenId: string,\n ): Promise<{ tokenId: string; revoked: boolean; alreadyRevoked?: boolean }> =>\n http.request<{ tokenId: string; revoked: boolean; alreadyRevoked?: boolean }>({\n method: 'DELETE',\n path: `/v1/call-tokens/${tokenId}`,\n }),\n})\n\nexport type CallTokensResource = ReturnType<typeof createCallTokensResource>\n","import type { HttpClient } from '../http'\nimport type { WebhookDelivery } from '../types'\n\n// Org-wide webhook delivery log. Per-agent CRUD lives on\n// `client.agents.webhooks(agentId)` — this namespace is just the\n// read-only deliveries surface that spans all agents.\n\nexport const createWebhooksResource = (http: HttpClient) => ({\n deliveries: async (\n filters: {\n agentId?: string\n webhookId?: string\n callId?: string\n limit?: number\n } = {},\n ): Promise<WebhookDelivery[]> => {\n const res = await http.request<{ data: WebhookDelivery[] }>({\n method: 'GET',\n path: '/v1/webhooks/deliveries',\n query: filters as Record<string, string | number | undefined>,\n })\n return res.data\n },\n})\n\nexport type WebhooksResource = ReturnType<typeof createWebhooksResource>\n","import type { HttpClient } from '../http'\nimport type { CatalogAgent, CatalogListInput } from '../types'\n\n// Org-scoped consumer endpoints. Today this is just the agent catalog —\n// the trimmed shape your mobile app picks an agent from. Lives at\n// `/v1/orgs/:orgId/agents` rather than reusing the admin `/v1/agents/*`\n// tree on purpose: the catalog response intentionally excludes the\n// operator-only fields (system prompt, tools, KB IDs) so a leaked\n// consumer-backend `sk_` can't lift the operator config out of it.\n//\n// Pattern from your backend:\n//\n// const client = new PlatformClient({ apiKey: process.env.SK })\n// const visible = await client.orgs.listAgents({\n// orgId: process.env.ORG_ID!,\n// userTags: ['tier1'], // omit to get the unfiltered admin view\n// })\n// res.json(visible)\n\nexport const createOrgsResource = (http: HttpClient) => ({\n /**\n * Fetch the agent catalog for an org. Returns the consumer-trimmed shape;\n * no system prompt, tools, or KB info. Use `client.agents.get(agentId)`\n * with the same `sk_` if you need the full admin shape.\n *\n * `userTags`: end-user entitlement tags. When supplied, hides agents\n * whose `allowedUserTags` is non-empty and doesn't intersect with the\n * supplied list. Omit to get the unfiltered admin view.\n *\n * Persona / category filtering is intentionally not a server param —\n * filter the returned list client-side over `name`s if you need it.\n *\n * Throws `403 forbidden` if `orgId` doesn't match the key's org.\n */\n listAgents: async (input: CatalogListInput): Promise<CatalogAgent[]> => {\n const query: Record<string, string | undefined> = {}\n if (input.userTags && input.userTags.length > 0) query.userTags = input.userTags.join(',')\n const res = await http.request<{ data: CatalogAgent[] }>({\n method: 'GET',\n path: `/v1/orgs/${input.orgId}/agents`,\n query,\n })\n return res.data\n },\n})\n\nexport type OrgsResource = ReturnType<typeof createOrgsResource>\n","import type { HttpClient } from '../http'\nimport type {\n CreateRoomInput,\n CreateRoomResponse,\n ListRoomsResponse,\n ListUtterancesResponse,\n RoomDoc,\n RoomEventAck,\n RoomListFilters,\n RoomTranscriptOptions,\n} from '../types'\n\n// REST wrappers for /v1/rooms — the multi-party video room surface (see\n// docs/superpowers/specs/2026-05-18-multiparty-rooms-design.md). Lets\n// server-side code mint rooms, fetch state, list transcript pages, and end\n// rooms programmatically.\n//\n// Auth model: same Bearer `sk_` flow as every other resource — the server\n// derives `orgId` from the API key, so the SDK never sets a tenant header.\n//\n// Host actions beyond `end` (promote/demote/kick) and observer-token mint\n// live in the server but aren't surfaced here yet — they're operator-side\n// flows that the dashboard hits directly. Re-add here if a programmatic\n// use-case shows up (CI tests, integration harnesses).\n\nexport const createRoomsResource = (http: HttpClient) => ({\n // Provision a new room. Server returns 201 with ONE shared room-level\n // `joinToken` + `joinUrl`. Share the single link with everyone you want in\n // the room — each visitor supplies their own display name at join time and\n // becomes a fresh, distinct participant. The server persists only the\n // token's sha256 hash; the raw token is returned here once and never stored.\n create: async (input: CreateRoomInput): Promise<CreateRoomResponse> =>\n http.request<CreateRoomResponse>({\n method: 'POST',\n path: '/v1/rooms',\n body: input,\n }),\n\n // Listing — opaque cursor pagination (`nextCursor` returned by the server\n // is whatever startAfter() needs, don't parse client-side).\n list: async (filters: RoomListFilters = {}): Promise<ListRoomsResponse> => {\n const query: Record<string, string | number | undefined> = {}\n if (filters.status) query.status = filters.status\n if (filters.limit !== undefined) query.limit = filters.limit\n if (filters.cursor) query.cursor = filters.cursor\n return http.request<ListRoomsResponse>({\n method: 'GET',\n path: '/v1/rooms',\n query,\n })\n },\n\n // Fetch a single room. 404s are surfaced as PlatformError('not_found').\n get: async (roomId: string): Promise<RoomDoc> =>\n http.request<RoomDoc>({\n method: 'GET',\n path: `/v1/rooms/${roomId}`,\n }),\n\n // Transcript pages — utterances are ordered by `startedAt asc`. Cursor is\n // an ISO timestamp (server enforces, don't construct yourself).\n transcript: async (\n roomId: string,\n opts: RoomTranscriptOptions = {},\n ): Promise<ListUtterancesResponse> => {\n const query: Record<string, string | number | undefined> = {}\n if (opts.cursor) query.cursor = opts.cursor\n if (opts.limit !== undefined) query.limit = opts.limit\n return http.request<ListUtterancesResponse>({\n method: 'GET',\n path: `/v1/rooms/${roomId}/transcript`,\n query,\n })\n },\n\n // End a room — async on the server: returns 202 + eventId once the\n // controlEvents entry is written. The room-worker observes the entry,\n // broadcasts the system message, and tears down LiveKit shortly after.\n end: async (roomId: string): Promise<RoomEventAck> =>\n http.request<RoomEventAck>({\n method: 'POST',\n path: `/v1/rooms/${roomId}/end`,\n }),\n})\n\nexport type RoomsResource = ReturnType<typeof createRoomsResource>\n","import { createHttpClient, type HttpClientOptions } from './http'\nimport { createMeResource, type MeResource } from './resources/me'\nimport { createAgentsResource, type AgentsResource } from './resources/agents'\nimport { createCallsResource, type CallsResource } from './resources/calls'\nimport {\n createKnowledgeBasesResource,\n type KnowledgeBasesResource,\n} from './resources/knowledgeBases'\nimport { createCreditsResource, type CreditsResource } from './resources/credits'\nimport { createCallTokensResource, type CallTokensResource } from './resources/callTokens'\nimport { createWebhooksResource, type WebhooksResource } from './resources/webhooks'\nimport { createOrgsResource, type OrgsResource } from './resources/orgs'\nimport { createRoomsResource, type RoomsResource } from './resources/rooms'\n\nexport interface PlatformClientOptions {\n // Full-org API key minted from the dashboard or bootstrap CLI. Start with\n // `sk_`. Never ship to a browser — use `client.callTokens.mint(...)` to\n // generate a narrow `ct_` token for client-side use instead.\n apiKey: string\n // Defaults to the hosted platform. Point at `http://localhost:8080` for\n // local dev or at a self-hosted deployment.\n baseUrl?: string\n // Passthrough tuning for the HTTP layer.\n timeoutMs?: number\n maxRetries?: number\n fetch?: HttpClientOptions['fetch']\n onRequest?: HttpClientOptions['onRequest']\n}\n\n// Single entry point. All resources are lazy-constructed in the constructor\n// so their refs don't incur any per-call allocation. Shape mirrors Stripe /\n// Twilio / Vapi's `resource.method()` convention for familiarity.\nexport class PlatformClient {\n readonly me: MeResource\n readonly agents: AgentsResource\n readonly calls: CallsResource\n readonly knowledgeBases: KnowledgeBasesResource\n readonly credits: CreditsResource\n readonly callTokens: CallTokensResource\n readonly webhooks: WebhooksResource\n readonly orgs: OrgsResource\n readonly rooms: RoomsResource\n\n constructor(options: PlatformClientOptions) {\n if (!options.apiKey) {\n throw new Error('PlatformClient: `apiKey` is required')\n }\n const http = createHttpClient({\n apiKey: options.apiKey,\n baseUrl: options.baseUrl ?? 'https://api.example.com',\n timeoutMs: options.timeoutMs,\n maxRetries: options.maxRetries,\n fetch: options.fetch,\n onRequest: options.onRequest,\n })\n\n this.me = createMeResource(http)\n this.agents = createAgentsResource(http)\n this.calls = createCallsResource(http)\n this.knowledgeBases = createKnowledgeBasesResource(http)\n this.credits = createCreditsResource(http)\n this.callTokens = createCallTokensResource(http)\n this.webhooks = createWebhooksResource(http)\n this.orgs = createOrgsResource(http)\n this.rooms = createRoomsResource(http)\n }\n}\n","import crypto from 'node:crypto'\n\n// Helper for consumers receiving webhooks: verify the `X-Platform-Signature-256`\n// header against the raw body + secret. Plain function (not tied to\n// PlatformClient) so Express/Koa/Next.js middleware can use it without\n// instantiating a client.\n//\n// import { verifyWebhookSignature } from '@craftedxp/sdk-node'\n// app.post('/webhooks/voice-agent', express.raw({ type: 'application/json' }), (req, res) => {\n// const sig = req.header('X-Platform-Signature-256') ?? ''\n// if (!verifyWebhookSignature(req.body, sig, process.env.VOICE_AGENT_WEBHOOK_SECRET!)) {\n// return res.status(401).send('invalid signature')\n// }\n// const event = JSON.parse(req.body.toString('utf8'))\n// // ...handle event\n// })\n//\n// The signature is `sha256=<hex HMAC-SHA256 of rawBody with secret>`.\n// Timing-safe compare to avoid microtiming side channels.\n\nexport const verifyWebhookSignature = (\n rawBody: Buffer | string,\n signatureHeader: string,\n secret: string,\n): boolean => {\n if (!signatureHeader || !secret) return false\n const [algo, provided] = signatureHeader.split('=')\n if (algo !== 'sha256' || !provided) return false\n\n const expected = crypto\n .createHmac('sha256', secret)\n .update(typeof rawBody === 'string' ? rawBody : rawBody)\n .digest('hex')\n\n // Buffers must match in length for timingSafeEqual.\n const a = Buffer.from(expected, 'hex')\n const b = Buffer.from(provided, 'hex')\n if (a.length !== b.length) return false\n return crypto.timingSafeEqual(a, b)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;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OAAO,KAAK;AAGf,QAAM,IAAI,OAAO,KAAK,UAAU,KAAK;AACrC,QAAM,IAAI,OAAO,KAAK,UAAU,KAAK;AACrC,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,SAAO,mBAAAA,QAAO,gBAAgB,GAAG,CAAC;AACpC;","names":["path","fs","path","crypto"]}
package/dist/index.mjs CHANGED
@@ -444,6 +444,57 @@ var createOrgsResource = (http) => ({
444
444
  }
445
445
  });
446
446
 
447
+ // src/resources/rooms.ts
448
+ var createRoomsResource = (http) => ({
449
+ // Provision a new room. Server returns 201 with ONE shared room-level
450
+ // `joinToken` + `joinUrl`. Share the single link with everyone you want in
451
+ // the room — each visitor supplies their own display name at join time and
452
+ // becomes a fresh, distinct participant. The server persists only the
453
+ // token's sha256 hash; the raw token is returned here once and never stored.
454
+ create: async (input) => http.request({
455
+ method: "POST",
456
+ path: "/v1/rooms",
457
+ body: input
458
+ }),
459
+ // Listing — opaque cursor pagination (`nextCursor` returned by the server
460
+ // is whatever startAfter() needs, don't parse client-side).
461
+ list: async (filters = {}) => {
462
+ const query = {};
463
+ if (filters.status) query.status = filters.status;
464
+ if (filters.limit !== void 0) query.limit = filters.limit;
465
+ if (filters.cursor) query.cursor = filters.cursor;
466
+ return http.request({
467
+ method: "GET",
468
+ path: "/v1/rooms",
469
+ query
470
+ });
471
+ },
472
+ // Fetch a single room. 404s are surfaced as PlatformError('not_found').
473
+ get: async (roomId) => http.request({
474
+ method: "GET",
475
+ path: `/v1/rooms/${roomId}`
476
+ }),
477
+ // Transcript pages — utterances are ordered by `startedAt asc`. Cursor is
478
+ // an ISO timestamp (server enforces, don't construct yourself).
479
+ transcript: async (roomId, opts = {}) => {
480
+ const query = {};
481
+ if (opts.cursor) query.cursor = opts.cursor;
482
+ if (opts.limit !== void 0) query.limit = opts.limit;
483
+ return http.request({
484
+ method: "GET",
485
+ path: `/v1/rooms/${roomId}/transcript`,
486
+ query
487
+ });
488
+ },
489
+ // End a room — async on the server: returns 202 + eventId once the
490
+ // controlEvents entry is written. The room-worker observes the entry,
491
+ // broadcasts the system message, and tears down LiveKit shortly after.
492
+ end: async (roomId) => http.request({
493
+ method: "POST",
494
+ path: `/v1/rooms/${roomId}/end`
495
+ })
496
+ });
497
+
447
498
  // src/PlatformClient.ts
448
499
  var PlatformClient = class {
449
500
  me;
@@ -454,6 +505,7 @@ var PlatformClient = class {
454
505
  callTokens;
455
506
  webhooks;
456
507
  orgs;
508
+ rooms;
457
509
  constructor(options) {
458
510
  if (!options.apiKey) {
459
511
  throw new Error("PlatformClient: `apiKey` is required");
@@ -474,6 +526,7 @@ var PlatformClient = class {
474
526
  this.callTokens = createCallTokensResource(http);
475
527
  this.webhooks = createWebhooksResource(http);
476
528
  this.orgs = createOrgsResource(http);
529
+ this.rooms = createRoomsResource(http);
477
530
  }
478
531
  };
479
532
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/resources/me.ts","../src/resources/agentWebhooks.ts","../src/resources/agents.ts","../src/resources/calls.ts","../src/resources/knowledgeBases.ts","../src/resources/credits.ts","../src/resources/callTokens.ts","../src/resources/webhooks.ts","../src/resources/orgs.ts","../src/PlatformClient.ts","../src/verify.ts"],"sourcesContent":["// Typed error class mirroring the server's ErrorV1 shape:\n// { error: { code, message, field?, docs_url? } }\n//\n// Consumers do `err instanceof PlatformError` to branch on code without\n// parsing string messages. `status` carries the HTTP code for the 1% of\n// cases where the code field isn't enough (e.g. rate-limit → retry-after\n// header correlation).\n\nexport type ApiErrorCode =\n | 'unauthorized'\n | 'forbidden'\n | 'not_found'\n | 'bad_request'\n | 'conflict'\n | 'rate_limited'\n | 'payment_required'\n | 'internal_error'\n | 'unknown'\n\nexport class PlatformError extends Error {\n readonly code: ApiErrorCode\n readonly status: number\n readonly field?: string\n readonly docsUrl?: string\n // The raw response body for debugging. Intentionally optional — we clear\n // it on `error.toJSON()` so logging libraries don't dump the whole\n // server response into production logs.\n readonly body?: unknown\n\n constructor(params: {\n code: ApiErrorCode\n message: string\n status: number\n field?: string\n docsUrl?: string\n body?: unknown\n }) {\n super(params.message)\n this.name = 'PlatformError'\n this.code = params.code\n this.status = params.status\n this.field = params.field\n this.docsUrl = params.docsUrl\n this.body = params.body\n // Preserve the stack trace — Node's Error doesn't capture it\n // automatically when subclassing in some older runtimes.\n if (\n typeof (Error as typeof Error & { captureStackTrace?: unknown }).captureStackTrace ===\n 'function'\n ) {\n ;(\n Error as typeof Error & { captureStackTrace: (target: unknown, ctor: unknown) => void }\n ).captureStackTrace(this, PlatformError)\n }\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n status: this.status,\n field: this.field,\n docsUrl: this.docsUrl,\n }\n }\n}\n","import { PlatformError, type ApiErrorCode } from './errors'\n\n// Low-level HTTP wrapper around `fetch` (native in Node 18+). Every resource\n// method routes through here for consistent auth + error handling + retries.\n//\n// v1 scope: JSON-in / JSON-out + multipart for file uploads. No streaming —\n// call WebSockets go through @craftedxp/voice-rn (the React Native client)\n// or a web equivalent, not this server-side SDK.\n\nexport interface HttpClientOptions {\n apiKey: string\n baseUrl: string\n // Default 30s. File uploads can override per-request.\n timeoutMs?: number\n // 429 + 5xx retries. Defaults to 3 attempts (original + 2 retries) with\n // exponential backoff (250ms, 1s). Set to 0 to disable.\n maxRetries?: number\n // Optional — lets consumers swap in a test/mock fetch (or a custom one\n // with instrumentation). Defaults to the global.\n fetch?: typeof fetch\n // Optional — a callback that fires per-request with the final status and\n // duration. Handy for dropping traces into the consumer's observability\n // stack without wrapping each call.\n onRequest?: (info: {\n method: string\n url: string\n status: number\n durationMs: number\n attempt: number\n }) => void\n}\n\nexport interface HttpRequest {\n method: 'GET' | 'POST' | 'PATCH' | 'DELETE'\n path: string // starts with `/`, e.g. `/v1/agents/123`\n query?: Record<string, string | number | boolean | undefined>\n body?: unknown // JSON-serialised — for multipart use `formData`\n formData?: FormData\n timeoutMs?: number\n // Exposed for edge cases where a resource wants to tack on extra\n // headers (we don't have any today but leave the hook).\n headers?: Record<string, string>\n}\n\nconst DEFAULT_TIMEOUT_MS = 30_000\nconst DEFAULT_MAX_RETRIES = 2 // total attempts = 3\n\nconst buildUrl = (baseUrl: string, path: string, query?: HttpRequest['query']): string => {\n const u = new URL(path, baseUrl)\n if (query) {\n for (const [k, v] of Object.entries(query)) {\n if (v === undefined) continue\n u.searchParams.set(k, String(v))\n }\n }\n return u.toString()\n}\n\nconst sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms))\n\nconst isRetryable = (status: number): boolean => status === 429 || (status >= 500 && status < 600)\n\n// Parse whatever the server returned into a PlatformError. Falls back to\n// synthesising a sensible error for non-JSON responses.\nconst errorFromResponse = async (res: Response): Promise<PlatformError> => {\n const bodyText = await res.text().catch(() => '')\n let parsed: unknown = undefined\n try {\n parsed = bodyText ? JSON.parse(bodyText) : undefined\n } catch {\n // non-JSON response (e.g. an HTML error page from a proxy). Fall\n // through with parsed = undefined.\n }\n const errObj = (\n parsed as { error?: { code?: string; message?: string; field?: string; docs_url?: string } }\n )?.error\n return new PlatformError({\n code: (errObj?.code as ApiErrorCode) ?? 'unknown',\n message: errObj?.message ?? res.statusText ?? `HTTP ${res.status}`,\n status: res.status,\n field: errObj?.field,\n docsUrl: errObj?.docs_url,\n body: parsed ?? bodyText,\n })\n}\n\nexport const createHttpClient = (opts: HttpClientOptions) => {\n const fetchImpl = opts.fetch ?? globalThis.fetch\n const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS\n const maxRetries = opts.maxRetries ?? DEFAULT_MAX_RETRIES\n\n if (!fetchImpl) {\n throw new Error('No global fetch available. @craftedxp/sdk-node requires Node >= 18.')\n }\n\n const request = async <T>(req: HttpRequest): Promise<T> => {\n const url = buildUrl(opts.baseUrl, req.path, req.query)\n const headers: Record<string, string> = {\n Authorization: `Bearer ${opts.apiKey}`,\n Accept: 'application/json',\n ...(req.headers ?? {}),\n }\n\n // Body shaping: prefer formData when provided; otherwise JSON.\n // `FormData` sets its own Content-Type with boundary — don't preempt it.\n // Typed as `string | FormData | undefined` (a subset of the global\n // BodyInit) so we don't need DOM lib types in this server-side SDK.\n let body: string | FormData | undefined\n if (req.formData) {\n body = req.formData\n } else if (req.body !== undefined) {\n headers['Content-Type'] = 'application/json'\n body = JSON.stringify(req.body)\n }\n\n const reqTimeout = req.timeoutMs ?? timeoutMs\n let lastErr: unknown\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), reqTimeout)\n const started = Date.now()\n try {\n const res = await fetchImpl(url, {\n method: req.method,\n headers,\n body,\n signal: controller.signal,\n })\n const durationMs = Date.now() - started\n opts.onRequest?.({\n method: req.method,\n url,\n status: res.status,\n durationMs,\n attempt: attempt + 1,\n })\n\n if (res.ok) {\n // 204 No Content — some endpoints (DELETE webhooks) return nothing.\n if (res.status === 204) return undefined as T\n const ct = res.headers.get('content-type') ?? ''\n if (ct.includes('application/json')) {\n return (await res.json()) as T\n }\n // Non-JSON 2xx — rare. Return raw text cast as T.\n return (await res.text()) as unknown as T\n }\n\n // Retryable error: back off + retry up to maxRetries.\n if (isRetryable(res.status) && attempt < maxRetries) {\n const retryAfter = res.headers.get('Retry-After')\n const backoff = retryAfter ? Number(retryAfter) * 1000 : 250 * Math.pow(2, attempt)\n await sleep(backoff)\n continue\n }\n\n throw await errorFromResponse(res)\n } catch (err) {\n if (err instanceof PlatformError) throw err\n // AbortError / network / DNS failures — retry up to maxRetries.\n if (attempt < maxRetries) {\n lastErr = err\n await sleep(250 * Math.pow(2, attempt))\n continue\n }\n const msg = err instanceof Error ? err.message : 'network error'\n throw new PlatformError({\n code: 'unknown',\n message: `Network error: ${msg}`,\n status: 0,\n })\n } finally {\n clearTimeout(timer)\n }\n }\n\n // Should be unreachable — the loop either returns, throws, or continues.\n throw lastErr instanceof Error ? lastErr : new Error('request exhausted retries')\n }\n\n return { request }\n}\n\nexport type HttpClient = ReturnType<typeof createHttpClient>\n","import type { HttpClient } from '../http'\nimport type { MeResponse } from '../types'\n\nexport const createMeResource = (http: HttpClient) => ({\n // Smoke test — confirms the API key is valid and returns the org + balance.\n // Most consumers use this as a ping on startup.\n get: async (): Promise<MeResponse> => http.request<MeResponse>({ method: 'GET', path: '/v1/me' }),\n})\n\nexport type MeResource = ReturnType<typeof createMeResource>\n","import type { HttpClient } from '../http'\nimport type {\n WebhookConfig,\n WebhookCreateInput,\n WebhookDelivery,\n WebhookUpdateInput,\n} from '../types'\n\n// Per-agent webhook resource, scoped at factory time to a specific agentId.\n// All endpoints mirror /v1/agents/:agentId/webhooks[/:id].\n\nexport const createAgentWebhooksResource = (http: HttpClient, agentId: string) => ({\n // Returns the webhook + its signing secret. The secret is only present in\n // this response — persist immediately, subsequent GETs omit it. Use the\n // secret to verify `X-Platform-Signature-256` (sha256=hex HMAC over body).\n create: async (input: WebhookCreateInput): Promise<WebhookConfig> =>\n http.request<WebhookConfig>({\n method: 'POST',\n path: `/v1/agents/${agentId}/webhooks`,\n body: input,\n }),\n\n list: async (): Promise<WebhookConfig[]> => {\n const res = await http.request<{ data: WebhookConfig[] }>({\n method: 'GET',\n path: `/v1/agents/${agentId}/webhooks`,\n })\n return res.data\n },\n\n get: async (webhookId: string): Promise<WebhookConfig> =>\n http.request<WebhookConfig>({\n method: 'GET',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}`,\n }),\n\n update: async (webhookId: string, patch: WebhookUpdateInput): Promise<WebhookConfig> =>\n http.request<WebhookConfig>({\n method: 'PATCH',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}`,\n body: patch,\n }),\n\n delete: async (webhookId: string): Promise<void> =>\n http.request<void>({\n method: 'DELETE',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}`,\n }),\n\n // Fires a synthetic call.started against this webhook and returns the\n // full delivery record (including attempt status codes) once the retry\n // sequence has finished. Useful during setup to verify receiver wiring.\n test: async (webhookId: string): Promise<WebhookDelivery> =>\n http.request<WebhookDelivery>({\n method: 'POST',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}/test`,\n }),\n})\n\nexport type AgentWebhooksResource = ReturnType<typeof createAgentWebhooksResource>\n","import type { HttpClient } from '../http'\nimport type { Agent, AgentCreateInput, AgentUpdateInput } from '../types'\nimport { createAgentWebhooksResource, type AgentWebhooksResource } from './agentWebhooks'\n\n// The server returns Agent with `apiKey` stripped and `hasApiKey: boolean`\n// on the model. We type the happy path but keep our input type permissive\n// so consumers can POST a plaintext `apiKey` that the server encrypts +\n// swaps for `apiKeySecret` on persistence.\n\nexport const createAgentsResource = (http: HttpClient) => {\n const agents = {\n create: async (input: AgentCreateInput): Promise<Agent> =>\n http.request<Agent>({ method: 'POST', path: '/v1/agents', body: input }),\n\n list: async (): Promise<Agent[]> => {\n const res = await http.request<{ data: Agent[] }>({ method: 'GET', path: '/v1/agents' })\n return res.data\n },\n\n // Async iterator for \"give me every agent\" — v1 server returns the full\n // list in one page, so this is just a thin convenience. When the server\n // picks up cursor pagination, this is the method that papers over that\n // migration without consumer changes.\n listAll: async function* (): AsyncIterable<Agent> {\n const page = await agents.list()\n for (const a of page) yield a\n },\n\n get: async (agentId: string): Promise<Agent> =>\n http.request<Agent>({ method: 'GET', path: `/v1/agents/${agentId}` }),\n\n update: async (agentId: string, patch: AgentUpdateInput): Promise<Agent> =>\n http.request<Agent>({ method: 'PATCH', path: `/v1/agents/${agentId}`, body: patch }),\n\n delete: async (agentId: string): Promise<void> =>\n http.request<void>({ method: 'DELETE', path: `/v1/agents/${agentId}` }),\n\n /**\n * Upload an avatar image for the agent. Server re-encodes to a 512×512\n * WebP and stores it in the public-read avatars bucket; the returned\n * `Agent` has `avatarUrl` set to the canonical public URL with a\n * `?v=` cache-buster.\n *\n * `file` accepts a Node Buffer / Uint8Array / Blob / typed-array.\n * `filename` and `contentType` are optional but help the server log\n * meaningful errors when something rejects.\n */\n uploadAvatar: async (\n agentId: string,\n file: Buffer | Uint8Array | Blob | ArrayBuffer,\n opts: { filename?: string; contentType?: string } = {},\n ): Promise<Agent> => {\n const fd = new FormData()\n const blob =\n file instanceof Blob\n ? file\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new Blob([file as any], { type: opts.contentType ?? 'application/octet-stream' })\n fd.append('file', blob, opts.filename ?? 'avatar')\n return http.request<Agent>({\n method: 'POST',\n path: `/v1/agents/${agentId}/avatar`,\n formData: fd,\n })\n },\n\n /**\n * Remove the agent's avatar — both the GCS object and the `avatarUrl`\n * field. Idempotent: calling on an agent without an avatar still\n * returns the agent.\n */\n removeAvatar: async (agentId: string): Promise<Agent> =>\n http.request<Agent>({ method: 'DELETE', path: `/v1/agents/${agentId}/avatar` }),\n\n // Nested resource. Per-agent webhook CRUD lives at\n // /v1/agents/:agentId/webhooks/* — we expose it as a factory keyed on\n // agentId so consumers can bind once and reuse:\n //\n // const hooks = client.agents.webhooks(myAgentId)\n // await hooks.create({ url, events })\n // await hooks.list()\n webhooks: (agentId: string): AgentWebhooksResource =>\n createAgentWebhooksResource(http, agentId),\n }\n return agents\n}\n\nexport type AgentsResource = ReturnType<typeof createAgentsResource>\n","import type { HttpClient } from '../http'\nimport type {\n CallListFilters,\n CallRecord,\n CallRecordingUrlResponse,\n CallSummary,\n TranscriptTurn,\n} from '../types'\n\nexport const createCallsResource = (http: HttpClient) => {\n const calls = {\n list: async (filters: CallListFilters = {}): Promise<CallSummary[]> => {\n const res = await http.request<{ data: CallSummary[] }>({\n method: 'GET',\n path: '/v1/calls',\n query: filters as Record<string, string | number | undefined>,\n })\n return res.data\n },\n\n // Auto-pagination helper. v1 server caps at limit (max 200) in a single\n // page — consumers who ask for \"every call since X\" get that page, the\n // iterator ends. This is the shape we'd extend with cursor support\n // without breaking callers.\n listAll: async function* (filters: CallListFilters = {}): AsyncIterable<CallSummary> {\n const page = await calls.list(filters)\n for (const c of page) yield c\n },\n\n get: async (callId: string): Promise<CallRecord> =>\n http.request<CallRecord>({ method: 'GET', path: `/v1/calls/${callId}` }),\n\n transcript: async (callId: string): Promise<{ callId: string; transcript: TranscriptTurn[] }> =>\n http.request<{ callId: string; transcript: TranscriptTurn[] }>({\n method: 'GET',\n path: `/v1/calls/${callId}/transcript`,\n }),\n\n // Returns a V4 signed URL (1-hour TTL). `ready: false` + `artifact:\n // 'caller-raw'` means the async mix job hasn't finished — the URL still\n // points at a playable file (raw caller PCM).\n recording: async (callId: string): Promise<CallRecordingUrlResponse> =>\n http.request<CallRecordingUrlResponse>({\n method: 'GET',\n path: `/v1/calls/${callId}/recording`,\n }),\n\n // Outbound dialling (POST /v1/calls) + in-call control are Phase 1.4.4 /\n // 1.4.5 respectively — blocked on telephony. Surface clear \"not built\n // yet\" errors here if consumers guess those method names, so they don't\n // silently hit a non-existent endpoint and wonder why it 404s.\n }\n return calls\n}\n\nexport type CallsResource = ReturnType<typeof createCallsResource>\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { HttpClient } from '../http'\nimport type { KnowledgeBase, KnowledgeBaseFile } from '../types'\n\nexport const createKnowledgeBasesResource = (http: HttpClient) => ({\n create: async (name: string): Promise<KnowledgeBase> =>\n http.request<KnowledgeBase>({\n method: 'POST',\n path: '/v1/knowledge-bases',\n body: { name },\n }),\n\n list: async (): Promise<KnowledgeBase[]> => {\n const res = await http.request<{ data: KnowledgeBase[] }>({\n method: 'GET',\n path: '/v1/knowledge-bases',\n })\n return res.data\n },\n\n get: async (kbId: string): Promise<KnowledgeBase> =>\n http.request<KnowledgeBase>({ method: 'GET', path: `/v1/knowledge-bases/${kbId}` }),\n\n delete: async (kbId: string): Promise<void> =>\n http.request<void>({ method: 'DELETE', path: `/v1/knowledge-bases/${kbId}` }),\n\n // File upload — accepts either a local file path OR raw bytes + filename.\n // The server ingests synchronously today (Phase 3.1.4 Cloud Tasks is a\n // followup), so the returned file has status='ready' in most cases.\n uploadFile: async (\n kbId: string,\n source:\n | { path: string; filename?: string; mimeType?: string }\n | { data: Buffer | Uint8Array; filename: string; mimeType?: string },\n ): Promise<KnowledgeBaseFile> => {\n const form = new FormData()\n let blob: Blob\n let filename: string\n let mime: string\n\n if ('path' in source) {\n const buf = await fs.promises.readFile(source.path)\n filename = source.filename ?? path.basename(source.path)\n mime = source.mimeType ?? 'application/octet-stream'\n blob = new Blob([new Uint8Array(buf)], { type: mime })\n } else {\n filename = source.filename\n mime = source.mimeType ?? 'application/octet-stream'\n const bytes = source.data instanceof Buffer ? new Uint8Array(source.data) : source.data\n blob = new Blob([bytes], { type: mime })\n }\n form.append('file', blob, filename)\n\n // File uploads can take a while (OCR, chunking, embedding) — give them\n // room before timing out. 5 min cap matches the server's own\n // processing budget.\n return http.request<KnowledgeBaseFile>({\n method: 'POST',\n path: `/v1/knowledge-bases/${kbId}/files`,\n formData: form,\n timeoutMs: 5 * 60 * 1000,\n })\n },\n\n listFiles: async (kbId: string): Promise<KnowledgeBaseFile[]> => {\n const res = await http.request<{ data: KnowledgeBaseFile[] }>({\n method: 'GET',\n path: `/v1/knowledge-bases/${kbId}/files`,\n })\n return res.data\n },\n\n deleteFile: async (kbId: string, fileId: string): Promise<void> =>\n http.request<void>({\n method: 'DELETE',\n path: `/v1/knowledge-bases/${kbId}/files/${fileId}`,\n }),\n})\n\nexport type KnowledgeBasesResource = ReturnType<typeof createKnowledgeBasesResource>\n","import type { HttpClient } from '../http'\nimport type { LedgerEntry } from '../types'\n\nexport const createCreditsResource = (http: HttpClient) => {\n const credits = {\n getBalance: async (): Promise<{ orgId: string; balanceCents: number }> =>\n http.request<{ orgId: string; balanceCents: number }>({\n method: 'GET',\n path: '/v1/credits/balance',\n }),\n\n // Returns ledger entries newest-first. `limit` is capped at 500 server-side.\n getLedger: async (opts: { limit?: number } = {}): Promise<LedgerEntry[]> => {\n const res = await http.request<{ data: LedgerEntry[] }>({\n method: 'GET',\n path: '/v1/credits/ledger',\n query: opts as Record<string, string | number | undefined>,\n })\n return res.data\n },\n\n // Auto-pagination scaffold — v1 server returns a single page up to\n // limit=500. When cursor pagination lands this is where it gets wired.\n getLedgerAll: async function* (opts: { limit?: number } = {}): AsyncIterable<LedgerEntry> {\n const page = await credits.getLedger(opts)\n for (const e of page) yield e\n },\n }\n return credits\n}\n\nexport type CreditsResource = ReturnType<typeof createCreditsResource>\n","import type { HttpClient } from '../http'\nimport type { CallTokenMintInput, CallTokenMintResult, CallTokenSummary } from '../types'\n\n// Short-lived, agent-scoped `ct_` tokens. Mint one per user session on your\n// backend, hand the raw value to the browser; let this SDK handle lifecycle\n// (revoke on sign-out, list active tokens for an admin panel).\n\nexport const createCallTokensResource = (http: HttpClient) => ({\n // Returns the RAW token value once. Don't log it; pass it straight to the\n // browser + discard server-side. `tokenId` is the stable public handle\n // used for revocation later.\n mint: async (input: CallTokenMintInput): Promise<CallTokenMintResult> =>\n http.request<CallTokenMintResult>({\n method: 'POST',\n path: '/v1/call-tokens',\n body: input,\n }),\n\n // Live tokens only by default. Pass includeRevoked/includeExpired when\n // debugging \"why did my token stop working\".\n list: async (\n opts: { includeRevoked?: boolean; includeExpired?: boolean; limit?: number } = {},\n ): Promise<CallTokenSummary[]> => {\n const query: Record<string, string | number | undefined> = {}\n if (opts.includeRevoked) query.includeRevoked = '1'\n if (opts.includeExpired) query.includeExpired = '1'\n if (opts.limit !== undefined) query.limit = opts.limit\n const res = await http.request<{ data: CallTokenSummary[] }>({\n method: 'GET',\n path: '/v1/call-tokens',\n query,\n })\n return res.data\n },\n\n // Idempotent — re-revoking a revoked token returns `alreadyRevoked: true`.\n revoke: async (\n tokenId: string,\n ): Promise<{ tokenId: string; revoked: boolean; alreadyRevoked?: boolean }> =>\n http.request<{ tokenId: string; revoked: boolean; alreadyRevoked?: boolean }>({\n method: 'DELETE',\n path: `/v1/call-tokens/${tokenId}`,\n }),\n})\n\nexport type CallTokensResource = ReturnType<typeof createCallTokensResource>\n","import type { HttpClient } from '../http'\nimport type { WebhookDelivery } from '../types'\n\n// Org-wide webhook delivery log. Per-agent CRUD lives on\n// `client.agents.webhooks(agentId)` — this namespace is just the\n// read-only deliveries surface that spans all agents.\n\nexport const createWebhooksResource = (http: HttpClient) => ({\n deliveries: async (\n filters: {\n agentId?: string\n webhookId?: string\n callId?: string\n limit?: number\n } = {},\n ): Promise<WebhookDelivery[]> => {\n const res = await http.request<{ data: WebhookDelivery[] }>({\n method: 'GET',\n path: '/v1/webhooks/deliveries',\n query: filters as Record<string, string | number | undefined>,\n })\n return res.data\n },\n})\n\nexport type WebhooksResource = ReturnType<typeof createWebhooksResource>\n","import type { HttpClient } from '../http'\nimport type { CatalogAgent, CatalogListInput } from '../types'\n\n// Org-scoped consumer endpoints. Today this is just the agent catalog —\n// the trimmed shape your mobile app picks an agent from. Lives at\n// `/v1/orgs/:orgId/agents` rather than reusing the admin `/v1/agents/*`\n// tree on purpose: the catalog response intentionally excludes the\n// operator-only fields (system prompt, tools, KB IDs) so a leaked\n// consumer-backend `sk_` can't lift the operator config out of it.\n//\n// Pattern from your backend:\n//\n// const client = new PlatformClient({ apiKey: process.env.SK })\n// const visible = await client.orgs.listAgents({\n// orgId: process.env.ORG_ID!,\n// userTags: ['tier1'], // omit to get the unfiltered admin view\n// })\n// res.json(visible)\n\nexport const createOrgsResource = (http: HttpClient) => ({\n /**\n * Fetch the agent catalog for an org. Returns the consumer-trimmed shape;\n * no system prompt, tools, or KB info. Use `client.agents.get(agentId)`\n * with the same `sk_` if you need the full admin shape.\n *\n * `userTags`: end-user entitlement tags. When supplied, hides agents\n * whose `allowedUserTags` is non-empty and doesn't intersect with the\n * supplied list. Omit to get the unfiltered admin view.\n *\n * Persona / category filtering is intentionally not a server param —\n * filter the returned list client-side over `name`s if you need it.\n *\n * Throws `403 forbidden` if `orgId` doesn't match the key's org.\n */\n listAgents: async (input: CatalogListInput): Promise<CatalogAgent[]> => {\n const query: Record<string, string | undefined> = {}\n if (input.userTags && input.userTags.length > 0) query.userTags = input.userTags.join(',')\n const res = await http.request<{ data: CatalogAgent[] }>({\n method: 'GET',\n path: `/v1/orgs/${input.orgId}/agents`,\n query,\n })\n return res.data\n },\n})\n\nexport type OrgsResource = ReturnType<typeof createOrgsResource>\n","import { createHttpClient, type HttpClientOptions } from './http'\nimport { createMeResource, type MeResource } from './resources/me'\nimport { createAgentsResource, type AgentsResource } from './resources/agents'\nimport { createCallsResource, type CallsResource } from './resources/calls'\nimport {\n createKnowledgeBasesResource,\n type KnowledgeBasesResource,\n} from './resources/knowledgeBases'\nimport { createCreditsResource, type CreditsResource } from './resources/credits'\nimport { createCallTokensResource, type CallTokensResource } from './resources/callTokens'\nimport { createWebhooksResource, type WebhooksResource } from './resources/webhooks'\nimport { createOrgsResource, type OrgsResource } from './resources/orgs'\n\nexport interface PlatformClientOptions {\n // Full-org API key minted from the dashboard or bootstrap CLI. Start with\n // `sk_`. Never ship to a browser — use `client.callTokens.mint(...)` to\n // generate a narrow `ct_` token for client-side use instead.\n apiKey: string\n // Defaults to the hosted platform. Point at `http://localhost:8080` for\n // local dev or at a self-hosted deployment.\n baseUrl?: string\n // Passthrough tuning for the HTTP layer.\n timeoutMs?: number\n maxRetries?: number\n fetch?: HttpClientOptions['fetch']\n onRequest?: HttpClientOptions['onRequest']\n}\n\n// Single entry point. All resources are lazy-constructed in the constructor\n// so their refs don't incur any per-call allocation. Shape mirrors Stripe /\n// Twilio / Vapi's `resource.method()` convention for familiarity.\nexport class PlatformClient {\n readonly me: MeResource\n readonly agents: AgentsResource\n readonly calls: CallsResource\n readonly knowledgeBases: KnowledgeBasesResource\n readonly credits: CreditsResource\n readonly callTokens: CallTokensResource\n readonly webhooks: WebhooksResource\n readonly orgs: OrgsResource\n\n constructor(options: PlatformClientOptions) {\n if (!options.apiKey) {\n throw new Error('PlatformClient: `apiKey` is required')\n }\n const http = createHttpClient({\n apiKey: options.apiKey,\n baseUrl: options.baseUrl ?? 'https://api.example.com',\n timeoutMs: options.timeoutMs,\n maxRetries: options.maxRetries,\n fetch: options.fetch,\n onRequest: options.onRequest,\n })\n\n this.me = createMeResource(http)\n this.agents = createAgentsResource(http)\n this.calls = createCallsResource(http)\n this.knowledgeBases = createKnowledgeBasesResource(http)\n this.credits = createCreditsResource(http)\n this.callTokens = createCallTokensResource(http)\n this.webhooks = createWebhooksResource(http)\n this.orgs = createOrgsResource(http)\n }\n}\n","import crypto from 'node:crypto'\n\n// Helper for consumers receiving webhooks: verify the `X-Platform-Signature-256`\n// header against the raw body + secret. Plain function (not tied to\n// PlatformClient) so Express/Koa/Next.js middleware can use it without\n// instantiating a client.\n//\n// import { verifyWebhookSignature } from '@craftedxp/sdk-node'\n// app.post('/webhooks/voice-agent', express.raw({ type: 'application/json' }), (req, res) => {\n// const sig = req.header('X-Platform-Signature-256') ?? ''\n// if (!verifyWebhookSignature(req.body, sig, process.env.VOICE_AGENT_WEBHOOK_SECRET!)) {\n// return res.status(401).send('invalid signature')\n// }\n// const event = JSON.parse(req.body.toString('utf8'))\n// // ...handle event\n// })\n//\n// The signature is `sha256=<hex HMAC-SHA256 of rawBody with secret>`.\n// Timing-safe compare to avoid microtiming side channels.\n\nexport const verifyWebhookSignature = (\n rawBody: Buffer | string,\n signatureHeader: string,\n secret: string,\n): boolean => {\n if (!signatureHeader || !secret) return false\n const [algo, provided] = signatureHeader.split('=')\n if (algo !== 'sha256' || !provided) return false\n\n const expected = crypto\n .createHmac('sha256', secret)\n .update(typeof rawBody === 'string' ? rawBody : rawBody)\n .digest('hex')\n\n // Buffers must match in length for timingSafeEqual.\n const a = Buffer.from(expected, 'hex')\n const b = Buffer.from(provided, 'hex')\n if (a.length !== b.length) return false\n return crypto.timingSafeEqual(a, b)\n}\n"],"mappings":";AAmBO,IAAM,gBAAN,MAAM,uBAAsB,MAAM;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA,EAET,YAAY,QAOT;AACD,UAAM,OAAO,OAAO;AACpB,SAAK,OAAO;AACZ,SAAK,OAAO,OAAO;AACnB,SAAK,SAAS,OAAO;AACrB,SAAK,QAAQ,OAAO;AACpB,SAAK,UAAU,OAAO;AACtB,SAAK,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../src/http.ts","../src/resources/me.ts","../src/resources/agentWebhooks.ts","../src/resources/agents.ts","../src/resources/calls.ts","../src/resources/knowledgeBases.ts","../src/resources/credits.ts","../src/resources/callTokens.ts","../src/resources/webhooks.ts","../src/resources/orgs.ts","../src/resources/rooms.ts","../src/PlatformClient.ts","../src/verify.ts"],"sourcesContent":["// Typed error class mirroring the server's ErrorV1 shape:\n// { error: { code, message, field?, docs_url? } }\n//\n// Consumers do `err instanceof PlatformError` to branch on code without\n// parsing string messages. `status` carries the HTTP code for the 1% of\n// cases where the code field isn't enough (e.g. rate-limit → retry-after\n// header correlation).\n\nexport type ApiErrorCode =\n | 'unauthorized'\n | 'forbidden'\n | 'not_found'\n | 'bad_request'\n | 'conflict'\n | 'rate_limited'\n | 'payment_required'\n | 'internal_error'\n | 'unknown'\n\nexport class PlatformError extends Error {\n readonly code: ApiErrorCode\n readonly status: number\n readonly field?: string\n readonly docsUrl?: string\n // The raw response body for debugging. Intentionally optional — we clear\n // it on `error.toJSON()` so logging libraries don't dump the whole\n // server response into production logs.\n readonly body?: unknown\n\n constructor(params: {\n code: ApiErrorCode\n message: string\n status: number\n field?: string\n docsUrl?: string\n body?: unknown\n }) {\n super(params.message)\n this.name = 'PlatformError'\n this.code = params.code\n this.status = params.status\n this.field = params.field\n this.docsUrl = params.docsUrl\n this.body = params.body\n // Preserve the stack trace — Node's Error doesn't capture it\n // automatically when subclassing in some older runtimes.\n if (\n typeof (Error as typeof Error & { captureStackTrace?: unknown }).captureStackTrace ===\n 'function'\n ) {\n ;(\n Error as typeof Error & { captureStackTrace: (target: unknown, ctor: unknown) => void }\n ).captureStackTrace(this, PlatformError)\n }\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n status: this.status,\n field: this.field,\n docsUrl: this.docsUrl,\n }\n }\n}\n","import { PlatformError, type ApiErrorCode } from './errors'\n\n// Low-level HTTP wrapper around `fetch` (native in Node 18+). Every resource\n// method routes through here for consistent auth + error handling + retries.\n//\n// v1 scope: JSON-in / JSON-out + multipart for file uploads. No streaming —\n// call WebSockets go through @craftedxp/voice-rn (the React Native client)\n// or a web equivalent, not this server-side SDK.\n\nexport interface HttpClientOptions {\n apiKey: string\n baseUrl: string\n // Default 30s. File uploads can override per-request.\n timeoutMs?: number\n // 429 + 5xx retries. Defaults to 3 attempts (original + 2 retries) with\n // exponential backoff (250ms, 1s). Set to 0 to disable.\n maxRetries?: number\n // Optional — lets consumers swap in a test/mock fetch (or a custom one\n // with instrumentation). Defaults to the global.\n fetch?: typeof fetch\n // Optional — a callback that fires per-request with the final status and\n // duration. Handy for dropping traces into the consumer's observability\n // stack without wrapping each call.\n onRequest?: (info: {\n method: string\n url: string\n status: number\n durationMs: number\n attempt: number\n }) => void\n}\n\nexport interface HttpRequest {\n method: 'GET' | 'POST' | 'PATCH' | 'DELETE'\n path: string // starts with `/`, e.g. `/v1/agents/123`\n query?: Record<string, string | number | boolean | undefined>\n body?: unknown // JSON-serialised — for multipart use `formData`\n formData?: FormData\n timeoutMs?: number\n // Exposed for edge cases where a resource wants to tack on extra\n // headers (we don't have any today but leave the hook).\n headers?: Record<string, string>\n}\n\nconst DEFAULT_TIMEOUT_MS = 30_000\nconst DEFAULT_MAX_RETRIES = 2 // total attempts = 3\n\nconst buildUrl = (baseUrl: string, path: string, query?: HttpRequest['query']): string => {\n const u = new URL(path, baseUrl)\n if (query) {\n for (const [k, v] of Object.entries(query)) {\n if (v === undefined) continue\n u.searchParams.set(k, String(v))\n }\n }\n return u.toString()\n}\n\nconst sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms))\n\nconst isRetryable = (status: number): boolean => status === 429 || (status >= 500 && status < 600)\n\n// Parse whatever the server returned into a PlatformError. Falls back to\n// synthesising a sensible error for non-JSON responses.\nconst errorFromResponse = async (res: Response): Promise<PlatformError> => {\n const bodyText = await res.text().catch(() => '')\n let parsed: unknown = undefined\n try {\n parsed = bodyText ? JSON.parse(bodyText) : undefined\n } catch {\n // non-JSON response (e.g. an HTML error page from a proxy). Fall\n // through with parsed = undefined.\n }\n const errObj = (\n parsed as { error?: { code?: string; message?: string; field?: string; docs_url?: string } }\n )?.error\n return new PlatformError({\n code: (errObj?.code as ApiErrorCode) ?? 'unknown',\n message: errObj?.message ?? res.statusText ?? `HTTP ${res.status}`,\n status: res.status,\n field: errObj?.field,\n docsUrl: errObj?.docs_url,\n body: parsed ?? bodyText,\n })\n}\n\nexport const createHttpClient = (opts: HttpClientOptions) => {\n const fetchImpl = opts.fetch ?? globalThis.fetch\n const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS\n const maxRetries = opts.maxRetries ?? DEFAULT_MAX_RETRIES\n\n if (!fetchImpl) {\n throw new Error('No global fetch available. @craftedxp/sdk-node requires Node >= 18.')\n }\n\n const request = async <T>(req: HttpRequest): Promise<T> => {\n const url = buildUrl(opts.baseUrl, req.path, req.query)\n const headers: Record<string, string> = {\n Authorization: `Bearer ${opts.apiKey}`,\n Accept: 'application/json',\n ...(req.headers ?? {}),\n }\n\n // Body shaping: prefer formData when provided; otherwise JSON.\n // `FormData` sets its own Content-Type with boundary — don't preempt it.\n // Typed as `string | FormData | undefined` (a subset of the global\n // BodyInit) so we don't need DOM lib types in this server-side SDK.\n let body: string | FormData | undefined\n if (req.formData) {\n body = req.formData\n } else if (req.body !== undefined) {\n headers['Content-Type'] = 'application/json'\n body = JSON.stringify(req.body)\n }\n\n const reqTimeout = req.timeoutMs ?? timeoutMs\n let lastErr: unknown\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), reqTimeout)\n const started = Date.now()\n try {\n const res = await fetchImpl(url, {\n method: req.method,\n headers,\n body,\n signal: controller.signal,\n })\n const durationMs = Date.now() - started\n opts.onRequest?.({\n method: req.method,\n url,\n status: res.status,\n durationMs,\n attempt: attempt + 1,\n })\n\n if (res.ok) {\n // 204 No Content — some endpoints (DELETE webhooks) return nothing.\n if (res.status === 204) return undefined as T\n const ct = res.headers.get('content-type') ?? ''\n if (ct.includes('application/json')) {\n return (await res.json()) as T\n }\n // Non-JSON 2xx — rare. Return raw text cast as T.\n return (await res.text()) as unknown as T\n }\n\n // Retryable error: back off + retry up to maxRetries.\n if (isRetryable(res.status) && attempt < maxRetries) {\n const retryAfter = res.headers.get('Retry-After')\n const backoff = retryAfter ? Number(retryAfter) * 1000 : 250 * Math.pow(2, attempt)\n await sleep(backoff)\n continue\n }\n\n throw await errorFromResponse(res)\n } catch (err) {\n if (err instanceof PlatformError) throw err\n // AbortError / network / DNS failures — retry up to maxRetries.\n if (attempt < maxRetries) {\n lastErr = err\n await sleep(250 * Math.pow(2, attempt))\n continue\n }\n const msg = err instanceof Error ? err.message : 'network error'\n throw new PlatformError({\n code: 'unknown',\n message: `Network error: ${msg}`,\n status: 0,\n })\n } finally {\n clearTimeout(timer)\n }\n }\n\n // Should be unreachable — the loop either returns, throws, or continues.\n throw lastErr instanceof Error ? lastErr : new Error('request exhausted retries')\n }\n\n return { request }\n}\n\nexport type HttpClient = ReturnType<typeof createHttpClient>\n","import type { HttpClient } from '../http'\nimport type { MeResponse } from '../types'\n\nexport const createMeResource = (http: HttpClient) => ({\n // Smoke test — confirms the API key is valid and returns the org + balance.\n // Most consumers use this as a ping on startup.\n get: async (): Promise<MeResponse> => http.request<MeResponse>({ method: 'GET', path: '/v1/me' }),\n})\n\nexport type MeResource = ReturnType<typeof createMeResource>\n","import type { HttpClient } from '../http'\nimport type {\n WebhookConfig,\n WebhookCreateInput,\n WebhookDelivery,\n WebhookUpdateInput,\n} from '../types'\n\n// Per-agent webhook resource, scoped at factory time to a specific agentId.\n// All endpoints mirror /v1/agents/:agentId/webhooks[/:id].\n\nexport const createAgentWebhooksResource = (http: HttpClient, agentId: string) => ({\n // Returns the webhook + its signing secret. The secret is only present in\n // this response — persist immediately, subsequent GETs omit it. Use the\n // secret to verify `X-Platform-Signature-256` (sha256=hex HMAC over body).\n create: async (input: WebhookCreateInput): Promise<WebhookConfig> =>\n http.request<WebhookConfig>({\n method: 'POST',\n path: `/v1/agents/${agentId}/webhooks`,\n body: input,\n }),\n\n list: async (): Promise<WebhookConfig[]> => {\n const res = await http.request<{ data: WebhookConfig[] }>({\n method: 'GET',\n path: `/v1/agents/${agentId}/webhooks`,\n })\n return res.data\n },\n\n get: async (webhookId: string): Promise<WebhookConfig> =>\n http.request<WebhookConfig>({\n method: 'GET',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}`,\n }),\n\n update: async (webhookId: string, patch: WebhookUpdateInput): Promise<WebhookConfig> =>\n http.request<WebhookConfig>({\n method: 'PATCH',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}`,\n body: patch,\n }),\n\n delete: async (webhookId: string): Promise<void> =>\n http.request<void>({\n method: 'DELETE',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}`,\n }),\n\n // Fires a synthetic call.started against this webhook and returns the\n // full delivery record (including attempt status codes) once the retry\n // sequence has finished. Useful during setup to verify receiver wiring.\n test: async (webhookId: string): Promise<WebhookDelivery> =>\n http.request<WebhookDelivery>({\n method: 'POST',\n path: `/v1/agents/${agentId}/webhooks/${webhookId}/test`,\n }),\n})\n\nexport type AgentWebhooksResource = ReturnType<typeof createAgentWebhooksResource>\n","import type { HttpClient } from '../http'\nimport type { Agent, AgentCreateInput, AgentUpdateInput } from '../types'\nimport { createAgentWebhooksResource, type AgentWebhooksResource } from './agentWebhooks'\n\n// The server returns Agent with `apiKey` stripped and `hasApiKey: boolean`\n// on the model. We type the happy path but keep our input type permissive\n// so consumers can POST a plaintext `apiKey` that the server encrypts +\n// swaps for `apiKeySecret` on persistence.\n\nexport const createAgentsResource = (http: HttpClient) => {\n const agents = {\n create: async (input: AgentCreateInput): Promise<Agent> =>\n http.request<Agent>({ method: 'POST', path: '/v1/agents', body: input }),\n\n list: async (): Promise<Agent[]> => {\n const res = await http.request<{ data: Agent[] }>({ method: 'GET', path: '/v1/agents' })\n return res.data\n },\n\n // Async iterator for \"give me every agent\" — v1 server returns the full\n // list in one page, so this is just a thin convenience. When the server\n // picks up cursor pagination, this is the method that papers over that\n // migration without consumer changes.\n listAll: async function* (): AsyncIterable<Agent> {\n const page = await agents.list()\n for (const a of page) yield a\n },\n\n get: async (agentId: string): Promise<Agent> =>\n http.request<Agent>({ method: 'GET', path: `/v1/agents/${agentId}` }),\n\n update: async (agentId: string, patch: AgentUpdateInput): Promise<Agent> =>\n http.request<Agent>({ method: 'PATCH', path: `/v1/agents/${agentId}`, body: patch }),\n\n delete: async (agentId: string): Promise<void> =>\n http.request<void>({ method: 'DELETE', path: `/v1/agents/${agentId}` }),\n\n /**\n * Upload an avatar image for the agent. Server re-encodes to a 512×512\n * WebP and stores it in the public-read avatars bucket; the returned\n * `Agent` has `avatarUrl` set to the canonical public URL with a\n * `?v=` cache-buster.\n *\n * `file` accepts a Node Buffer / Uint8Array / Blob / typed-array.\n * `filename` and `contentType` are optional but help the server log\n * meaningful errors when something rejects.\n */\n uploadAvatar: async (\n agentId: string,\n file: Buffer | Uint8Array | Blob | ArrayBuffer,\n opts: { filename?: string; contentType?: string } = {},\n ): Promise<Agent> => {\n const fd = new FormData()\n const blob =\n file instanceof Blob\n ? file\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new Blob([file as any], { type: opts.contentType ?? 'application/octet-stream' })\n fd.append('file', blob, opts.filename ?? 'avatar')\n return http.request<Agent>({\n method: 'POST',\n path: `/v1/agents/${agentId}/avatar`,\n formData: fd,\n })\n },\n\n /**\n * Remove the agent's avatar — both the GCS object and the `avatarUrl`\n * field. Idempotent: calling on an agent without an avatar still\n * returns the agent.\n */\n removeAvatar: async (agentId: string): Promise<Agent> =>\n http.request<Agent>({ method: 'DELETE', path: `/v1/agents/${agentId}/avatar` }),\n\n // Nested resource. Per-agent webhook CRUD lives at\n // /v1/agents/:agentId/webhooks/* — we expose it as a factory keyed on\n // agentId so consumers can bind once and reuse:\n //\n // const hooks = client.agents.webhooks(myAgentId)\n // await hooks.create({ url, events })\n // await hooks.list()\n webhooks: (agentId: string): AgentWebhooksResource =>\n createAgentWebhooksResource(http, agentId),\n }\n return agents\n}\n\nexport type AgentsResource = ReturnType<typeof createAgentsResource>\n","import type { HttpClient } from '../http'\nimport type {\n CallListFilters,\n CallRecord,\n CallRecordingUrlResponse,\n CallSummary,\n TranscriptTurn,\n} from '../types'\n\nexport const createCallsResource = (http: HttpClient) => {\n const calls = {\n list: async (filters: CallListFilters = {}): Promise<CallSummary[]> => {\n const res = await http.request<{ data: CallSummary[] }>({\n method: 'GET',\n path: '/v1/calls',\n query: filters as Record<string, string | number | undefined>,\n })\n return res.data\n },\n\n // Auto-pagination helper. v1 server caps at limit (max 200) in a single\n // page — consumers who ask for \"every call since X\" get that page, the\n // iterator ends. This is the shape we'd extend with cursor support\n // without breaking callers.\n listAll: async function* (filters: CallListFilters = {}): AsyncIterable<CallSummary> {\n const page = await calls.list(filters)\n for (const c of page) yield c\n },\n\n get: async (callId: string): Promise<CallRecord> =>\n http.request<CallRecord>({ method: 'GET', path: `/v1/calls/${callId}` }),\n\n transcript: async (callId: string): Promise<{ callId: string; transcript: TranscriptTurn[] }> =>\n http.request<{ callId: string; transcript: TranscriptTurn[] }>({\n method: 'GET',\n path: `/v1/calls/${callId}/transcript`,\n }),\n\n // Returns a V4 signed URL (1-hour TTL). `ready: false` + `artifact:\n // 'caller-raw'` means the async mix job hasn't finished — the URL still\n // points at a playable file (raw caller PCM).\n recording: async (callId: string): Promise<CallRecordingUrlResponse> =>\n http.request<CallRecordingUrlResponse>({\n method: 'GET',\n path: `/v1/calls/${callId}/recording`,\n }),\n\n // Outbound dialling (POST /v1/calls) + in-call control are Phase 1.4.4 /\n // 1.4.5 respectively — blocked on telephony. Surface clear \"not built\n // yet\" errors here if consumers guess those method names, so they don't\n // silently hit a non-existent endpoint and wonder why it 404s.\n }\n return calls\n}\n\nexport type CallsResource = ReturnType<typeof createCallsResource>\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { HttpClient } from '../http'\nimport type { KnowledgeBase, KnowledgeBaseFile } from '../types'\n\nexport const createKnowledgeBasesResource = (http: HttpClient) => ({\n create: async (name: string): Promise<KnowledgeBase> =>\n http.request<KnowledgeBase>({\n method: 'POST',\n path: '/v1/knowledge-bases',\n body: { name },\n }),\n\n list: async (): Promise<KnowledgeBase[]> => {\n const res = await http.request<{ data: KnowledgeBase[] }>({\n method: 'GET',\n path: '/v1/knowledge-bases',\n })\n return res.data\n },\n\n get: async (kbId: string): Promise<KnowledgeBase> =>\n http.request<KnowledgeBase>({ method: 'GET', path: `/v1/knowledge-bases/${kbId}` }),\n\n delete: async (kbId: string): Promise<void> =>\n http.request<void>({ method: 'DELETE', path: `/v1/knowledge-bases/${kbId}` }),\n\n // File upload — accepts either a local file path OR raw bytes + filename.\n // The server ingests synchronously today (Phase 3.1.4 Cloud Tasks is a\n // followup), so the returned file has status='ready' in most cases.\n uploadFile: async (\n kbId: string,\n source:\n | { path: string; filename?: string; mimeType?: string }\n | { data: Buffer | Uint8Array; filename: string; mimeType?: string },\n ): Promise<KnowledgeBaseFile> => {\n const form = new FormData()\n let blob: Blob\n let filename: string\n let mime: string\n\n if ('path' in source) {\n const buf = await fs.promises.readFile(source.path)\n filename = source.filename ?? path.basename(source.path)\n mime = source.mimeType ?? 'application/octet-stream'\n blob = new Blob([new Uint8Array(buf)], { type: mime })\n } else {\n filename = source.filename\n mime = source.mimeType ?? 'application/octet-stream'\n const bytes = source.data instanceof Buffer ? new Uint8Array(source.data) : source.data\n blob = new Blob([bytes], { type: mime })\n }\n form.append('file', blob, filename)\n\n // File uploads can take a while (OCR, chunking, embedding) — give them\n // room before timing out. 5 min cap matches the server's own\n // processing budget.\n return http.request<KnowledgeBaseFile>({\n method: 'POST',\n path: `/v1/knowledge-bases/${kbId}/files`,\n formData: form,\n timeoutMs: 5 * 60 * 1000,\n })\n },\n\n listFiles: async (kbId: string): Promise<KnowledgeBaseFile[]> => {\n const res = await http.request<{ data: KnowledgeBaseFile[] }>({\n method: 'GET',\n path: `/v1/knowledge-bases/${kbId}/files`,\n })\n return res.data\n },\n\n deleteFile: async (kbId: string, fileId: string): Promise<void> =>\n http.request<void>({\n method: 'DELETE',\n path: `/v1/knowledge-bases/${kbId}/files/${fileId}`,\n }),\n})\n\nexport type KnowledgeBasesResource = ReturnType<typeof createKnowledgeBasesResource>\n","import type { HttpClient } from '../http'\nimport type { LedgerEntry } from '../types'\n\nexport const createCreditsResource = (http: HttpClient) => {\n const credits = {\n getBalance: async (): Promise<{ orgId: string; balanceCents: number }> =>\n http.request<{ orgId: string; balanceCents: number }>({\n method: 'GET',\n path: '/v1/credits/balance',\n }),\n\n // Returns ledger entries newest-first. `limit` is capped at 500 server-side.\n getLedger: async (opts: { limit?: number } = {}): Promise<LedgerEntry[]> => {\n const res = await http.request<{ data: LedgerEntry[] }>({\n method: 'GET',\n path: '/v1/credits/ledger',\n query: opts as Record<string, string | number | undefined>,\n })\n return res.data\n },\n\n // Auto-pagination scaffold — v1 server returns a single page up to\n // limit=500. When cursor pagination lands this is where it gets wired.\n getLedgerAll: async function* (opts: { limit?: number } = {}): AsyncIterable<LedgerEntry> {\n const page = await credits.getLedger(opts)\n for (const e of page) yield e\n },\n }\n return credits\n}\n\nexport type CreditsResource = ReturnType<typeof createCreditsResource>\n","import type { HttpClient } from '../http'\nimport type { CallTokenMintInput, CallTokenMintResult, CallTokenSummary } from '../types'\n\n// Short-lived, agent-scoped `ct_` tokens. Mint one per user session on your\n// backend, hand the raw value to the browser; let this SDK handle lifecycle\n// (revoke on sign-out, list active tokens for an admin panel).\n\nexport const createCallTokensResource = (http: HttpClient) => ({\n // Returns the RAW token value once. Don't log it; pass it straight to the\n // browser + discard server-side. `tokenId` is the stable public handle\n // used for revocation later.\n mint: async (input: CallTokenMintInput): Promise<CallTokenMintResult> =>\n http.request<CallTokenMintResult>({\n method: 'POST',\n path: '/v1/call-tokens',\n body: input,\n }),\n\n // Live tokens only by default. Pass includeRevoked/includeExpired when\n // debugging \"why did my token stop working\".\n list: async (\n opts: { includeRevoked?: boolean; includeExpired?: boolean; limit?: number } = {},\n ): Promise<CallTokenSummary[]> => {\n const query: Record<string, string | number | undefined> = {}\n if (opts.includeRevoked) query.includeRevoked = '1'\n if (opts.includeExpired) query.includeExpired = '1'\n if (opts.limit !== undefined) query.limit = opts.limit\n const res = await http.request<{ data: CallTokenSummary[] }>({\n method: 'GET',\n path: '/v1/call-tokens',\n query,\n })\n return res.data\n },\n\n // Idempotent — re-revoking a revoked token returns `alreadyRevoked: true`.\n revoke: async (\n tokenId: string,\n ): Promise<{ tokenId: string; revoked: boolean; alreadyRevoked?: boolean }> =>\n http.request<{ tokenId: string; revoked: boolean; alreadyRevoked?: boolean }>({\n method: 'DELETE',\n path: `/v1/call-tokens/${tokenId}`,\n }),\n})\n\nexport type CallTokensResource = ReturnType<typeof createCallTokensResource>\n","import type { HttpClient } from '../http'\nimport type { WebhookDelivery } from '../types'\n\n// Org-wide webhook delivery log. Per-agent CRUD lives on\n// `client.agents.webhooks(agentId)` — this namespace is just the\n// read-only deliveries surface that spans all agents.\n\nexport const createWebhooksResource = (http: HttpClient) => ({\n deliveries: async (\n filters: {\n agentId?: string\n webhookId?: string\n callId?: string\n limit?: number\n } = {},\n ): Promise<WebhookDelivery[]> => {\n const res = await http.request<{ data: WebhookDelivery[] }>({\n method: 'GET',\n path: '/v1/webhooks/deliveries',\n query: filters as Record<string, string | number | undefined>,\n })\n return res.data\n },\n})\n\nexport type WebhooksResource = ReturnType<typeof createWebhooksResource>\n","import type { HttpClient } from '../http'\nimport type { CatalogAgent, CatalogListInput } from '../types'\n\n// Org-scoped consumer endpoints. Today this is just the agent catalog —\n// the trimmed shape your mobile app picks an agent from. Lives at\n// `/v1/orgs/:orgId/agents` rather than reusing the admin `/v1/agents/*`\n// tree on purpose: the catalog response intentionally excludes the\n// operator-only fields (system prompt, tools, KB IDs) so a leaked\n// consumer-backend `sk_` can't lift the operator config out of it.\n//\n// Pattern from your backend:\n//\n// const client = new PlatformClient({ apiKey: process.env.SK })\n// const visible = await client.orgs.listAgents({\n// orgId: process.env.ORG_ID!,\n// userTags: ['tier1'], // omit to get the unfiltered admin view\n// })\n// res.json(visible)\n\nexport const createOrgsResource = (http: HttpClient) => ({\n /**\n * Fetch the agent catalog for an org. Returns the consumer-trimmed shape;\n * no system prompt, tools, or KB info. Use `client.agents.get(agentId)`\n * with the same `sk_` if you need the full admin shape.\n *\n * `userTags`: end-user entitlement tags. When supplied, hides agents\n * whose `allowedUserTags` is non-empty and doesn't intersect with the\n * supplied list. Omit to get the unfiltered admin view.\n *\n * Persona / category filtering is intentionally not a server param —\n * filter the returned list client-side over `name`s if you need it.\n *\n * Throws `403 forbidden` if `orgId` doesn't match the key's org.\n */\n listAgents: async (input: CatalogListInput): Promise<CatalogAgent[]> => {\n const query: Record<string, string | undefined> = {}\n if (input.userTags && input.userTags.length > 0) query.userTags = input.userTags.join(',')\n const res = await http.request<{ data: CatalogAgent[] }>({\n method: 'GET',\n path: `/v1/orgs/${input.orgId}/agents`,\n query,\n })\n return res.data\n },\n})\n\nexport type OrgsResource = ReturnType<typeof createOrgsResource>\n","import type { HttpClient } from '../http'\nimport type {\n CreateRoomInput,\n CreateRoomResponse,\n ListRoomsResponse,\n ListUtterancesResponse,\n RoomDoc,\n RoomEventAck,\n RoomListFilters,\n RoomTranscriptOptions,\n} from '../types'\n\n// REST wrappers for /v1/rooms — the multi-party video room surface (see\n// docs/superpowers/specs/2026-05-18-multiparty-rooms-design.md). Lets\n// server-side code mint rooms, fetch state, list transcript pages, and end\n// rooms programmatically.\n//\n// Auth model: same Bearer `sk_` flow as every other resource — the server\n// derives `orgId` from the API key, so the SDK never sets a tenant header.\n//\n// Host actions beyond `end` (promote/demote/kick) and observer-token mint\n// live in the server but aren't surfaced here yet — they're operator-side\n// flows that the dashboard hits directly. Re-add here if a programmatic\n// use-case shows up (CI tests, integration harnesses).\n\nexport const createRoomsResource = (http: HttpClient) => ({\n // Provision a new room. Server returns 201 with ONE shared room-level\n // `joinToken` + `joinUrl`. Share the single link with everyone you want in\n // the room — each visitor supplies their own display name at join time and\n // becomes a fresh, distinct participant. The server persists only the\n // token's sha256 hash; the raw token is returned here once and never stored.\n create: async (input: CreateRoomInput): Promise<CreateRoomResponse> =>\n http.request<CreateRoomResponse>({\n method: 'POST',\n path: '/v1/rooms',\n body: input,\n }),\n\n // Listing — opaque cursor pagination (`nextCursor` returned by the server\n // is whatever startAfter() needs, don't parse client-side).\n list: async (filters: RoomListFilters = {}): Promise<ListRoomsResponse> => {\n const query: Record<string, string | number | undefined> = {}\n if (filters.status) query.status = filters.status\n if (filters.limit !== undefined) query.limit = filters.limit\n if (filters.cursor) query.cursor = filters.cursor\n return http.request<ListRoomsResponse>({\n method: 'GET',\n path: '/v1/rooms',\n query,\n })\n },\n\n // Fetch a single room. 404s are surfaced as PlatformError('not_found').\n get: async (roomId: string): Promise<RoomDoc> =>\n http.request<RoomDoc>({\n method: 'GET',\n path: `/v1/rooms/${roomId}`,\n }),\n\n // Transcript pages — utterances are ordered by `startedAt asc`. Cursor is\n // an ISO timestamp (server enforces, don't construct yourself).\n transcript: async (\n roomId: string,\n opts: RoomTranscriptOptions = {},\n ): Promise<ListUtterancesResponse> => {\n const query: Record<string, string | number | undefined> = {}\n if (opts.cursor) query.cursor = opts.cursor\n if (opts.limit !== undefined) query.limit = opts.limit\n return http.request<ListUtterancesResponse>({\n method: 'GET',\n path: `/v1/rooms/${roomId}/transcript`,\n query,\n })\n },\n\n // End a room — async on the server: returns 202 + eventId once the\n // controlEvents entry is written. The room-worker observes the entry,\n // broadcasts the system message, and tears down LiveKit shortly after.\n end: async (roomId: string): Promise<RoomEventAck> =>\n http.request<RoomEventAck>({\n method: 'POST',\n path: `/v1/rooms/${roomId}/end`,\n }),\n})\n\nexport type RoomsResource = ReturnType<typeof createRoomsResource>\n","import { createHttpClient, type HttpClientOptions } from './http'\nimport { createMeResource, type MeResource } from './resources/me'\nimport { createAgentsResource, type AgentsResource } from './resources/agents'\nimport { createCallsResource, type CallsResource } from './resources/calls'\nimport {\n createKnowledgeBasesResource,\n type KnowledgeBasesResource,\n} from './resources/knowledgeBases'\nimport { createCreditsResource, type CreditsResource } from './resources/credits'\nimport { createCallTokensResource, type CallTokensResource } from './resources/callTokens'\nimport { createWebhooksResource, type WebhooksResource } from './resources/webhooks'\nimport { createOrgsResource, type OrgsResource } from './resources/orgs'\nimport { createRoomsResource, type RoomsResource } from './resources/rooms'\n\nexport interface PlatformClientOptions {\n // Full-org API key minted from the dashboard or bootstrap CLI. Start with\n // `sk_`. Never ship to a browser — use `client.callTokens.mint(...)` to\n // generate a narrow `ct_` token for client-side use instead.\n apiKey: string\n // Defaults to the hosted platform. Point at `http://localhost:8080` for\n // local dev or at a self-hosted deployment.\n baseUrl?: string\n // Passthrough tuning for the HTTP layer.\n timeoutMs?: number\n maxRetries?: number\n fetch?: HttpClientOptions['fetch']\n onRequest?: HttpClientOptions['onRequest']\n}\n\n// Single entry point. All resources are lazy-constructed in the constructor\n// so their refs don't incur any per-call allocation. Shape mirrors Stripe /\n// Twilio / Vapi's `resource.method()` convention for familiarity.\nexport class PlatformClient {\n readonly me: MeResource\n readonly agents: AgentsResource\n readonly calls: CallsResource\n readonly knowledgeBases: KnowledgeBasesResource\n readonly credits: CreditsResource\n readonly callTokens: CallTokensResource\n readonly webhooks: WebhooksResource\n readonly orgs: OrgsResource\n readonly rooms: RoomsResource\n\n constructor(options: PlatformClientOptions) {\n if (!options.apiKey) {\n throw new Error('PlatformClient: `apiKey` is required')\n }\n const http = createHttpClient({\n apiKey: options.apiKey,\n baseUrl: options.baseUrl ?? 'https://api.example.com',\n timeoutMs: options.timeoutMs,\n maxRetries: options.maxRetries,\n fetch: options.fetch,\n onRequest: options.onRequest,\n })\n\n this.me = createMeResource(http)\n this.agents = createAgentsResource(http)\n this.calls = createCallsResource(http)\n this.knowledgeBases = createKnowledgeBasesResource(http)\n this.credits = createCreditsResource(http)\n this.callTokens = createCallTokensResource(http)\n this.webhooks = createWebhooksResource(http)\n this.orgs = createOrgsResource(http)\n this.rooms = createRoomsResource(http)\n }\n}\n","import crypto from 'node:crypto'\n\n// Helper for consumers receiving webhooks: verify the `X-Platform-Signature-256`\n// header against the raw body + secret. Plain function (not tied to\n// PlatformClient) so Express/Koa/Next.js middleware can use it without\n// instantiating a client.\n//\n// import { verifyWebhookSignature } from '@craftedxp/sdk-node'\n// app.post('/webhooks/voice-agent', express.raw({ type: 'application/json' }), (req, res) => {\n// const sig = req.header('X-Platform-Signature-256') ?? ''\n// if (!verifyWebhookSignature(req.body, sig, process.env.VOICE_AGENT_WEBHOOK_SECRET!)) {\n// return res.status(401).send('invalid signature')\n// }\n// const event = JSON.parse(req.body.toString('utf8'))\n// // ...handle event\n// })\n//\n// The signature is `sha256=<hex HMAC-SHA256 of rawBody with secret>`.\n// Timing-safe compare to avoid microtiming side channels.\n\nexport const verifyWebhookSignature = (\n rawBody: Buffer | string,\n signatureHeader: string,\n secret: string,\n): boolean => {\n if (!signatureHeader || !secret) return false\n const [algo, provided] = signatureHeader.split('=')\n if (algo !== 'sha256' || !provided) return false\n\n const expected = crypto\n .createHmac('sha256', secret)\n .update(typeof rawBody === 'string' ? rawBody : rawBody)\n .digest('hex')\n\n // Buffers must match in length for timingSafeEqual.\n const a = Buffer.from(expected, 'hex')\n const b = Buffer.from(provided, 'hex')\n if (a.length !== b.length) return false\n return crypto.timingSafeEqual(a, b)\n}\n"],"mappings":";AAmBO,IAAM,gBAAN,MAAM,uBAAsB,MAAM;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA,EAET,YAAY,QAOT;AACD,UAAM,OAAO,OAAO;AACpB,SAAK,OAAO;AACZ,SAAK,OAAO,OAAO;AACnB,SAAK,SAAS,OAAO;AACrB,SAAK,QAAQ,OAAO;AACpB,SAAK,UAAU,OAAO;AACtB,SAAK,OAAO,OAAO;AAGnB,QACE,OAAQ,MAAyD,s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AA,IACxD;AACA,UAAM,OAAO,iBAAiB;AAAA,MAC5B,QAAQ,QAAQ;AAAA,MAChB,SAAS,QAAQ,WAAW;AAAA,MAC5B,WAAW,QAAQ;AAAA,MACnB,YAAY,QAAQ;AAAA,MACpB,OAAO,QAAQ;AAAA,MACf,WAAW,QAAQ;AAAA,IACrB,CAAC;AAED,SAAK,KAAK,iBAAiB,IAAI;AAC/B,SAAK,SAAS,qBAAqB,IAAI;AACvC,SAAK,QAAQ,oBAAoB,IAAI;AACrC,SAAK,iBAAiB,6BAA6B,IAAI;AACvD,SAAK,UAAU,sBAAsB,IAAI;AACzC,SAAK,aAAa,yBAAyB,IAAI;AAC/C,SAAK,WAAW,uBAAuB,IAAI;AAC3C,SAAK,OAAO,mBAAmB,IAAI;AACnC,SAAK,QAAQ,oBAAoB,IAAI;AAAA,EACvC;AACF;;;AClEA,OAAO,YAAY;AAoBZ,IAAM,yBAAyB,CACpC,SACA,iBACA,WACY;AACZ,MAAI,CAAC,mBAAmB,CAAC,OAAQ,QAAO;AACxC,QAAM,CAAC,MAAM,QAAQ,IAAI,gBAAgB,MAAM,GAAG;AAClD,MAAI,SAAS,YAAY,CAAC,SAAU,QAAO;AAE3C,QAAM,WAAW,OACd,WAAW,UAAU,MAAM,EAC3B,OAAO,OAAO,YAAY,WAAW,UAAU,OAAO,EACtD,OAAO,KAAK;AAGf,QAAM,IAAI,OAAO,KAAK,UAAU,KAAK;AACrC,QAAM,IAAI,OAAO,KAAK,UAAU,KAAK;AACrC,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,SAAO,OAAO,gBAAgB,GAAG,CAAC;AACpC;","names":["path"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@craftedxp/sdk-node",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "Node.js / TypeScript SDK for the voice agent platform. Server-side API client — mint call tokens, manage agents, query calls, upload knowledge-base docs.",
5
5
  "author": "Crafted XP",
6
6
  "license": "MIT",
@@ -33,6 +33,7 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "tsup": "^8.3.5",
36
+ "tsx": "^4.19.0",
36
37
  "typescript": "^5.3.3",
37
38
  "@types/node": "^20.10.0"
38
39
  },
@@ -41,6 +42,7 @@
41
42
  "build": "npm run clean && tsup",
42
43
  "dev": "tsup --watch",
43
44
  "typecheck": "tsc --noEmit",
45
+ "test": "node --test --import tsx 'src/**/__tests__/*.test.ts'",
44
46
  "prepare": "npm run build"
45
47
  }
46
48
  }