@inkbox/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +369 -0
  2. package/dist/_http.d.ts +24 -0
  3. package/dist/_http.d.ts.map +1 -0
  4. package/dist/_http.js +90 -0
  5. package/dist/_http.js.map +1 -0
  6. package/dist/agent_identity.d.ts +184 -0
  7. package/dist/agent_identity.d.ts.map +1 -0
  8. package/dist/agent_identity.js +262 -0
  9. package/dist/agent_identity.js.map +1 -0
  10. package/dist/identities/resources/identities.d.ts +80 -0
  11. package/dist/identities/resources/identities.d.ts.map +1 -0
  12. package/dist/identities/resources/identities.js +103 -0
  13. package/dist/identities/resources/identities.js.map +1 -0
  14. package/dist/identities/types.d.ts +77 -0
  15. package/dist/identities/types.d.ts.map +1 -0
  16. package/dist/identities/types.js +44 -0
  17. package/dist/identities/types.js.map +1 -0
  18. package/dist/index.d.ts +10 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +5 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/inkbox.d.ts +92 -0
  23. package/dist/inkbox.d.ts.map +1 -0
  24. package/dist/inkbox.js +117 -0
  25. package/dist/inkbox.js.map +1 -0
  26. package/dist/mail/resources/mailboxes.d.ts +61 -0
  27. package/dist/mail/resources/mailboxes.d.ts.map +1 -0
  28. package/dist/mail/resources/mailboxes.js +83 -0
  29. package/dist/mail/resources/mailboxes.js.map +1 -0
  30. package/dist/mail/resources/messages.d.ts +100 -0
  31. package/dist/mail/resources/messages.d.ts.map +1 -0
  32. package/dist/mail/resources/messages.js +141 -0
  33. package/dist/mail/resources/messages.js.map +1 -0
  34. package/dist/mail/resources/threads.d.ts +36 -0
  35. package/dist/mail/resources/threads.d.ts.map +1 -0
  36. package/dist/mail/resources/threads.js +53 -0
  37. package/dist/mail/resources/threads.js.map +1 -0
  38. package/dist/mail/types.d.ts +113 -0
  39. package/dist/mail/types.d.ts.map +1 -0
  40. package/dist/mail/types.js +65 -0
  41. package/dist/mail/types.js.map +1 -0
  42. package/dist/phone/resources/calls.d.ts +45 -0
  43. package/dist/phone/resources/calls.d.ts.map +1 -0
  44. package/dist/phone/resources/calls.js +57 -0
  45. package/dist/phone/resources/calls.js.map +1 -0
  46. package/dist/phone/resources/numbers.d.ts +61 -0
  47. package/dist/phone/resources/numbers.d.ts.map +1 -0
  48. package/dist/phone/resources/numbers.js +85 -0
  49. package/dist/phone/resources/numbers.js.map +1 -0
  50. package/dist/phone/resources/transcripts.d.ts +19 -0
  51. package/dist/phone/resources/transcripts.d.ts.map +1 -0
  52. package/dist/phone/resources/transcripts.js +23 -0
  53. package/dist/phone/resources/transcripts.js.map +1 -0
  54. package/dist/phone/types.d.ts +108 -0
  55. package/dist/phone/types.d.ts.map +1 -0
  56. package/dist/phone/types.js +62 -0
  57. package/dist/phone/types.js.map +1 -0
  58. package/dist/signing_keys.d.ts +40 -0
  59. package/dist/signing_keys.d.ts.map +1 -0
  60. package/dist/signing_keys.js +59 -0
  61. package/dist/signing_keys.js.map +1 -0
  62. package/package.json +42 -0
package/README.md ADDED
@@ -0,0 +1,369 @@
1
+ # @inkbox/sdk
2
+
3
+ TypeScript SDK for the [Inkbox API](https://www.inkbox.ai/docs) — API-first communication infrastructure for AI agents (email, phone, identities).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @inkbox/sdk
9
+ ```
10
+
11
+ Requires Node.js ≥ 18.
12
+
13
+ ## Authentication
14
+
15
+ You'll need an API key to use this SDK. Get one at [console.inkbox.ai](https://console.inkbox.ai/).
16
+
17
+ ## Quick start
18
+
19
+ ```ts
20
+ import { Inkbox } from "@inkbox/sdk";
21
+
22
+ const inkbox = new Inkbox({ apiKey: process.env.INKBOX_API_KEY! });
23
+
24
+ // Create an agent identity
25
+ const identity = await inkbox.createIdentity("support-bot");
26
+
27
+ // Create and link new channels
28
+ const mailbox = await identity.createMailbox({ displayName: "Support Bot" });
29
+ const phone = await identity.provisionPhoneNumber({ type: "toll_free" });
30
+
31
+ // Send email directly from the identity
32
+ await identity.sendEmail({
33
+ to: ["customer@example.com"],
34
+ subject: "Your order has shipped",
35
+ bodyText: "Tracking number: 1Z999AA10123456784",
36
+ });
37
+
38
+ // Place an outbound call
39
+ await identity.placeCall({
40
+ toNumber: "+18005559999",
41
+ clientWebsocketUrl: "wss://my-app.com/voice",
42
+ });
43
+
44
+ // Read inbox
45
+ for await (const message of identity.iterEmails()) {
46
+ console.log(message.subject);
47
+ }
48
+
49
+ // List calls
50
+ const calls = await identity.listCalls();
51
+ ```
52
+
53
+ ## Authentication
54
+
55
+ | Option | Type | Default | Description |
56
+ |---|---|---|---|
57
+ | `apiKey` | `string` | required | Your `ApiKey_...` token |
58
+ | `baseUrl` | `string` | API default | Override for self-hosting or testing |
59
+ | `timeoutMs` | `number` | `30000` | Request timeout in milliseconds |
60
+
61
+ ---
62
+
63
+ ## Identities
64
+
65
+ `inkbox.createIdentity()` and `inkbox.getIdentity()` return an `AgentIdentity` object that holds the identity's channels and exposes convenience methods scoped to those channels.
66
+
67
+ ```ts
68
+ // Create and fully provision an identity
69
+ const identity = await inkbox.createIdentity("sales-bot");
70
+ const mailbox = await identity.createMailbox({ displayName: "Sales Bot" }); // creates + links
71
+ const phone = await identity.provisionPhoneNumber({ type: "toll_free" }); // provisions + links
72
+
73
+ console.log(mailbox.emailAddress);
74
+ console.log(phone.number);
75
+
76
+ // Link an existing mailbox or phone number instead of creating new ones
77
+ await identity.assignMailbox("mailbox-uuid-here");
78
+ await identity.assignPhoneNumber("phone-number-uuid-here");
79
+
80
+ // Get an existing identity (returned with current channel state)
81
+ const identity2 = await inkbox.getIdentity("sales-bot");
82
+ await identity2.refresh(); // re-fetch channels from API
83
+
84
+ // List all identities for your org
85
+ const allIdentities = await inkbox.listIdentities();
86
+
87
+ // Update status or handle
88
+ await identity.update({ status: "paused" });
89
+ await identity.update({ newHandle: "sales-bot-v2" });
90
+
91
+ // Unlink channels (without deleting them)
92
+ await identity.unlinkMailbox();
93
+ await identity.unlinkPhoneNumber();
94
+
95
+ // Delete
96
+ await identity.delete();
97
+ ```
98
+
99
+ ---
100
+
101
+ ## Mail
102
+
103
+ ```ts
104
+ // Send an email (plain text and/or HTML)
105
+ const sent = await identity.sendEmail({
106
+ to: ["user@example.com"],
107
+ subject: "Hello from Inkbox",
108
+ bodyText: "Hi there!",
109
+ bodyHtml: "<p>Hi there!</p>",
110
+ cc: ["manager@example.com"],
111
+ bcc: ["archive@example.com"],
112
+ });
113
+
114
+ // Send a threaded reply
115
+ await identity.sendEmail({
116
+ to: ["user@example.com"],
117
+ subject: `Re: ${sent.subject}`,
118
+ bodyText: "Following up!",
119
+ inReplyToMessageId: sent.id,
120
+ });
121
+
122
+ // Send with attachments
123
+ await identity.sendEmail({
124
+ to: ["user@example.com"],
125
+ subject: "See attached",
126
+ bodyText: "Please find the file attached.",
127
+ attachments: [{
128
+ filename: "report.pdf",
129
+ contentType: "application/pdf",
130
+ contentBase64: "<base64-encoded-content>",
131
+ }],
132
+ });
133
+
134
+ // Iterate inbox (paginated automatically)
135
+ for await (const msg of identity.iterEmails()) {
136
+ console.log(msg.subject, msg.fromAddress, msg.isRead);
137
+ }
138
+
139
+ // Filter by direction: "inbound" or "outbound"
140
+ for await (const msg of identity.iterEmails({ direction: "inbound" })) {
141
+ console.log(msg.subject);
142
+ }
143
+
144
+ // Iterate only unread emails
145
+ for await (const msg of identity.iterUnreadEmails()) {
146
+ console.log(msg.subject);
147
+ }
148
+
149
+ // Mark messages as read
150
+ const unread: string[] = [];
151
+ for await (const msg of identity.iterUnreadEmails()) unread.push(msg.id);
152
+ await identity.markEmailsRead(unread);
153
+
154
+ // Get all emails in a thread (threadId comes from msg.threadId)
155
+ const thread = await identity.getThread(msg.threadId!);
156
+ for (const m of thread.messages) {
157
+ console.log(m.subject, m.fromAddress);
158
+ }
159
+ ```
160
+
161
+ ---
162
+
163
+ ## Phone
164
+
165
+ ```ts
166
+ // Place an outbound call — stream audio over WebSocket
167
+ const call = await identity.placeCall({
168
+ toNumber: "+15167251294",
169
+ clientWebsocketUrl: "wss://your-agent.example.com/ws",
170
+ });
171
+ console.log(call.status, call.rateLimit.callsRemaining);
172
+
173
+ // Or receive call events via webhook instead
174
+ const call2 = await identity.placeCall({
175
+ toNumber: "+15167251294",
176
+ webhookUrl: "https://your-agent.example.com/call-events",
177
+ });
178
+
179
+ // List calls (paginated)
180
+ const calls = await identity.listCalls({ limit: 10, offset: 0 });
181
+ for (const c of calls) {
182
+ console.log(c.id, c.direction, c.remotePhoneNumber, c.status);
183
+ }
184
+
185
+ // Fetch transcript segments for a call
186
+ const segments = await identity.listTranscripts(calls[0].id);
187
+ for (const t of segments) {
188
+ console.log(`[${t.party}] ${t.text}`); // party: "local" or "remote"
189
+ }
190
+
191
+ // Read transcripts across all recent calls
192
+ const recentCalls = await identity.listCalls({ limit: 10 });
193
+ for (const call of recentCalls) {
194
+ const segs = await identity.listTranscripts(call.id);
195
+ if (!segs.length) continue;
196
+ console.log(`\n--- Call ${call.id} (${call.direction}) ---`);
197
+ for (const t of segs) {
198
+ console.log(` [${t.party.padEnd(6)}] ${t.text}`);
199
+ }
200
+ }
201
+
202
+ // Filter to only the remote party's speech
203
+ const remoteOnly = segments.filter(t => t.party === "remote");
204
+ for (const t of remoteOnly) console.log(t.text);
205
+
206
+ // Search transcripts across a phone number (org-level)
207
+ const hits = await inkbox.phoneNumbers.searchTranscripts(phone.id, { q: "refund", party: "remote" });
208
+ for (const t of hits) {
209
+ console.log(`[${t.party}] ${t.text}`);
210
+ }
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Org-level Mailboxes
216
+
217
+ Manage mailboxes directly without going through an identity. Access via `inkbox.mailboxes`.
218
+
219
+ ```ts
220
+ // List all mailboxes in the organisation
221
+ const mailboxes = await inkbox.mailboxes.list();
222
+
223
+ // Get a specific mailbox
224
+ const mailbox = await inkbox.mailboxes.get("abc-xyz@inkboxmail.com");
225
+
226
+ // Create a standalone mailbox
227
+ const mb = await inkbox.mailboxes.create({ displayName: "Support Inbox" });
228
+ console.log(mb.emailAddress);
229
+
230
+ // Update display name or webhook URL
231
+ await inkbox.mailboxes.update(mb.emailAddress, { displayName: "New Name" });
232
+ await inkbox.mailboxes.update(mb.emailAddress, { webhookUrl: "https://example.com/hook" });
233
+ await inkbox.mailboxes.update(mb.emailAddress, { webhookUrl: null }); // remove webhook
234
+
235
+ // Full-text search across messages in a mailbox
236
+ const results = await inkbox.mailboxes.search(mb.emailAddress, { q: "invoice", limit: 20 });
237
+ for (const msg of results) {
238
+ console.log(msg.subject, msg.fromAddress);
239
+ }
240
+
241
+ // Delete a mailbox
242
+ await inkbox.mailboxes.delete(mb.emailAddress);
243
+ ```
244
+
245
+ ---
246
+
247
+ ## Org-level Phone Numbers
248
+
249
+ Manage phone numbers directly without going through an identity. Access via `inkbox.phoneNumbers`.
250
+
251
+ ```ts
252
+ // List all phone numbers in the organisation
253
+ const numbers = await inkbox.phoneNumbers.list();
254
+
255
+ // Get a specific phone number by ID
256
+ const number = await inkbox.phoneNumbers.get("phone-number-uuid");
257
+
258
+ // Provision a new number
259
+ const num = await inkbox.phoneNumbers.provision({ type: "toll_free" });
260
+ const local = await inkbox.phoneNumbers.provision({ type: "local", state: "NY" });
261
+
262
+ // Update incoming call behaviour
263
+ await inkbox.phoneNumbers.update(num.id, {
264
+ incomingCallAction: "webhook",
265
+ incomingCallWebhookUrl: "https://example.com/calls",
266
+ });
267
+ await inkbox.phoneNumbers.update(num.id, {
268
+ incomingCallAction: "auto_accept",
269
+ clientWebsocketUrl: "wss://example.com/ws",
270
+ });
271
+
272
+ // Full-text search across transcripts
273
+ const hits = await inkbox.phoneNumbers.searchTranscripts(num.id, { q: "refund", party: "remote" });
274
+ for (const t of hits) {
275
+ console.log(`[${t.party}] ${t.text}`);
276
+ }
277
+
278
+ // Release a number
279
+ await inkbox.phoneNumbers.release({ number: num.number });
280
+ ```
281
+
282
+ ---
283
+
284
+ ## Webhooks
285
+
286
+ Webhooks are configured on the mailbox or phone number resource — no separate registration step.
287
+
288
+ ### Mailbox webhooks
289
+
290
+ Set a URL on a mailbox to receive `message.received` and `message.sent` events.
291
+
292
+ ```ts
293
+ // Set webhook
294
+ await inkbox.mailboxes.update("abc@inkboxmail.com", { webhookUrl: "https://example.com/hook" });
295
+
296
+ // Remove webhook
297
+ await inkbox.mailboxes.update("abc@inkboxmail.com", { webhookUrl: null });
298
+ ```
299
+
300
+ ### Phone webhooks
301
+
302
+ Set an incoming call webhook URL and action on a phone number.
303
+
304
+ ```ts
305
+ // Route incoming calls to a webhook
306
+ await inkbox.phoneNumbers.update(number.id, {
307
+ incomingCallAction: "webhook",
308
+ incomingCallWebhookUrl: "https://example.com/calls",
309
+ });
310
+ ```
311
+
312
+ You can also supply a per-call webhook URL when placing a call:
313
+
314
+ ```ts
315
+ await identity.placeCall({ toNumber: "+15005550006", webhookUrl: "https://example.com/call-events" });
316
+ ```
317
+
318
+ ---
319
+
320
+ ## Signing Keys
321
+
322
+ ```ts
323
+ // Create or rotate the org-level webhook signing key (plaintext returned once)
324
+ const key = await inkbox.createSigningKey();
325
+ console.log(key.signingKey); // save this immediately
326
+ ```
327
+
328
+ ---
329
+
330
+ ## Verifying Webhook Signatures
331
+
332
+ Use `verifyWebhook` to confirm that an incoming request was sent by Inkbox.
333
+
334
+ ```typescript
335
+ import { verifyWebhook } from "@inkbox/sdk";
336
+
337
+ // Express — use express.raw() to get the raw body Buffer
338
+ app.post("/hooks/mail", express.raw({ type: "*/*" }), (req, res) => {
339
+ const valid = verifyWebhook({
340
+ payload: req.body,
341
+ headers: req.headers,
342
+ secret: "whsec_...",
343
+ });
344
+ if (!valid) return res.status(403).end();
345
+ // handle event ...
346
+ });
347
+ ```
348
+
349
+ ---
350
+
351
+ ## Examples
352
+
353
+ Runnable example scripts are available in the [examples/typescript](https://github.com/vectorlyapp/inkbox/tree/main/inkbox/examples/typescript) directory:
354
+
355
+ | Script | What it demonstrates |
356
+ |---|---|
357
+ | `register-agent-identity.ts` | Create an identity, assign mailbox + phone number |
358
+ | `agent-send-email.ts` | Send an email and a threaded reply |
359
+ | `read-agent-messages.ts` | List messages and threads |
360
+ | `create-agent-mailbox.ts` | Create, update, search, and delete a mailbox |
361
+ | `create-agent-phone-number.ts` | Provision, update, and release a number |
362
+ | `list-agent-phone-numbers.ts` | List all phone numbers in the org |
363
+ | `read-agent-calls.ts` | List calls and print transcripts |
364
+ | `receive-agent-email-webhook.ts` | Register and delete a mailbox webhook |
365
+ | `receive-agent-call-webhook.ts` | Register, update, and delete a phone webhook |
366
+
367
+ ## License
368
+
369
+ MIT
@@ -0,0 +1,24 @@
1
+ /**
2
+ * inkbox-mail/_http.ts
3
+ *
4
+ * Async HTTP transport (internal). Zero runtime dependencies — uses native fetch.
5
+ */
6
+ export declare class InkboxAPIError extends Error {
7
+ readonly statusCode: number;
8
+ readonly detail: string;
9
+ constructor(statusCode: number, detail: string);
10
+ }
11
+ type Params = Record<string, string | number | boolean | undefined | null>;
12
+ export declare class HttpTransport {
13
+ private readonly apiKey;
14
+ private readonly baseUrl;
15
+ private readonly timeoutMs;
16
+ constructor(apiKey: string, baseUrl: string, timeoutMs?: number);
17
+ get<T>(path: string, params?: Params): Promise<T>;
18
+ post<T>(path: string, body?: unknown): Promise<T>;
19
+ patch<T>(path: string, body: unknown): Promise<T>;
20
+ delete(path: string): Promise<void>;
21
+ private request;
22
+ }
23
+ export {};
24
+ //# sourceMappingURL=_http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_http.d.ts","sourceRoot":"","sources":["../src/_http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAM/C;AAED,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;AAE3E,qBAAa,aAAa;IAEtB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAFT,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,MAAe;IAGvC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIjD,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAIjD,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAIjD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAI3B,OAAO;CA6DtB"}
package/dist/_http.js ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * inkbox-mail/_http.ts
3
+ *
4
+ * Async HTTP transport (internal). Zero runtime dependencies — uses native fetch.
5
+ */
6
+ export class InkboxAPIError extends Error {
7
+ statusCode;
8
+ detail;
9
+ constructor(statusCode, detail) {
10
+ super(`HTTP ${statusCode}: ${detail}`);
11
+ this.name = "InkboxAPIError";
12
+ this.statusCode = statusCode;
13
+ this.detail = detail;
14
+ }
15
+ }
16
+ export class HttpTransport {
17
+ apiKey;
18
+ baseUrl;
19
+ timeoutMs;
20
+ constructor(apiKey, baseUrl, timeoutMs = 30_000) {
21
+ this.apiKey = apiKey;
22
+ this.baseUrl = baseUrl;
23
+ this.timeoutMs = timeoutMs;
24
+ }
25
+ async get(path, params) {
26
+ return this.request("GET", path, { params });
27
+ }
28
+ async post(path, body) {
29
+ return this.request("POST", path, { body });
30
+ }
31
+ async patch(path, body) {
32
+ return this.request("PATCH", path, { body });
33
+ }
34
+ async delete(path) {
35
+ await this.request("DELETE", path);
36
+ }
37
+ async request(method, path, opts = {}) {
38
+ let url = `${this.baseUrl}${path}`;
39
+ if (opts.params) {
40
+ const qs = new URLSearchParams();
41
+ for (const [k, v] of Object.entries(opts.params)) {
42
+ if (v !== undefined && v !== null) {
43
+ qs.set(k, String(v));
44
+ }
45
+ }
46
+ const s = qs.toString();
47
+ if (s)
48
+ url += `?${s}`;
49
+ }
50
+ const headers = {
51
+ "X-Service-Token": this.apiKey,
52
+ Accept: "application/json",
53
+ };
54
+ let bodyStr;
55
+ if (opts.body !== undefined) {
56
+ headers["Content-Type"] = "application/json";
57
+ bodyStr = JSON.stringify(opts.body);
58
+ }
59
+ const controller = new AbortController();
60
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
61
+ let resp;
62
+ try {
63
+ resp = await fetch(url, {
64
+ method,
65
+ headers,
66
+ body: bodyStr,
67
+ signal: controller.signal,
68
+ });
69
+ }
70
+ finally {
71
+ clearTimeout(timer);
72
+ }
73
+ if (!resp.ok) {
74
+ let detail;
75
+ try {
76
+ const err = (await resp.json());
77
+ detail = err.detail ?? resp.statusText;
78
+ }
79
+ catch {
80
+ detail = resp.statusText;
81
+ }
82
+ throw new InkboxAPIError(resp.status, detail);
83
+ }
84
+ if (resp.status === 204) {
85
+ return undefined;
86
+ }
87
+ return resp.json();
88
+ }
89
+ }
90
+ //# sourceMappingURL=_http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_http.js","sourceRoot":"","sources":["../src/_http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,UAAU,CAAS;IACnB,MAAM,CAAS;IAExB,YAAY,UAAkB,EAAE,MAAc;QAC5C,KAAK,CAAC,QAAQ,UAAU,KAAK,MAAM,EAAE,CAAC,CAAC;QACvC,IAAI,CA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AAG,CAAC,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC;YACzC,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;YAC3B,CAAC;YACD,MAAM,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACxB,OAAO,SAAc,CAAC;QACxB,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,EAAgB,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1,184 @@
1
+ /**
2
+ * inkbox/src/agent.ts
3
+ *
4
+ * AgentIdentity — a domain object representing one agent identity.
5
+ * Returned by inkbox.createIdentity() and inkbox.getIdentity().
6
+ *
7
+ * Convenience methods (sendEmail, placeCall, etc.) are scoped to this
8
+ * identity's assigned channels so callers never need to pass an email
9
+ * address or phone number ID explicitly.
10
+ */
11
+ import type { Message, ThreadDetail } from "./mail/types.js";
12
+ import type { PhoneCall, PhoneCallWithRateLimit, PhoneTranscript } from "./phone/types.js";
13
+ import type { _AgentIdentityData, IdentityMailbox, IdentityPhoneNumber } from "./identities/types.js";
14
+ import type { Inkbox } from "./inkbox.js";
15
+ export declare class AgentIdentity {
16
+ private _data;
17
+ private readonly _inkbox;
18
+ private _mailbox;
19
+ private _phoneNumber;
20
+ constructor(data: _AgentIdentityData, inkbox: Inkbox);
21
+ get agentHandle(): string;
22
+ get id(): string;
23
+ get status(): string;
24
+ /** The mailbox currently assigned to this identity, or `null` if none. */
25
+ get mailbox(): IdentityMailbox | null;
26
+ /** The phone number currently assigned to this identity, or `null` if none. */
27
+ get phoneNumber(): IdentityPhoneNumber | null;
28
+ /**
29
+ * Create a new mailbox and link it to this identity.
30
+ *
31
+ * @param options.displayName - Optional human-readable sender name.
32
+ * @returns The newly created and linked {@link IdentityMailbox}.
33
+ */
34
+ createMailbox(options?: {
35
+ displayName?: string;
36
+ }): Promise<IdentityMailbox>;
37
+ /**
38
+ * Link an existing mailbox to this identity.
39
+ *
40
+ * @param mailboxId - UUID of the mailbox to link. Obtain via
41
+ * `inkbox.mailboxes.list()` or `inkbox.mailboxes.get()`.
42
+ * @returns The linked {@link IdentityMailbox}.
43
+ */
44
+ assignMailbox(mailboxId: string): Promise<IdentityMailbox>;
45
+ /**
46
+ * Unlink this identity's mailbox (does not delete the mailbox).
47
+ */
48
+ unlinkMailbox(): Promise<void>;
49
+ /**
50
+ * Provision a new phone number and link it to this identity.
51
+ *
52
+ * @param options.type - `"toll_free"` (default) or `"local"`.
53
+ * @param options.state - US state abbreviation (e.g. `"NY"`), valid for local numbers only.
54
+ * @returns The newly provisioned and linked {@link IdentityPhoneNumber}.
55
+ */
56
+ provisionPhoneNumber(options?: {
57
+ type?: string;
58
+ state?: string;
59
+ }): Promise<IdentityPhoneNumber>;
60
+ /**
61
+ * Link an existing phone number to this identity.
62
+ *
63
+ * @param phoneNumberId - UUID of the phone number to link. Obtain via
64
+ * `inkbox.phoneNumbers.list()` or `inkbox.phoneNumbers.get()`.
65
+ * @returns The linked {@link IdentityPhoneNumber}.
66
+ */
67
+ assignPhoneNumber(phoneNumberId: string): Promise<IdentityPhoneNumber>;
68
+ /**
69
+ * Unlink this identity's phone number (does not release the number).
70
+ */
71
+ unlinkPhoneNumber(): Promise<void>;
72
+ /**
73
+ * Send an email from this identity's mailbox.
74
+ *
75
+ * @param options.to - Primary recipient addresses (at least one required).
76
+ * @param options.subject - Email subject line.
77
+ * @param options.bodyText - Plain-text body.
78
+ * @param options.bodyHtml - HTML body.
79
+ * @param options.cc - Carbon-copy recipients.
80
+ * @param options.bcc - Blind carbon-copy recipients.
81
+ * @param options.inReplyToMessageId - RFC 5322 Message-ID to thread a reply.
82
+ * @param options.attachments - File attachments.
83
+ */
84
+ sendEmail(options: {
85
+ to: string[];
86
+ subject: string;
87
+ bodyText?: string;
88
+ bodyHtml?: string;
89
+ cc?: string[];
90
+ bcc?: string[];
91
+ inReplyToMessageId?: string;
92
+ attachments?: Array<{
93
+ filename: string;
94
+ contentType: string;
95
+ contentBase64: string;
96
+ }>;
97
+ }): Promise<Message>;
98
+ /**
99
+ * Iterate over emails in this identity's inbox, newest first.
100
+ *
101
+ * Pagination is handled automatically.
102
+ *
103
+ * @param options.pageSize - Messages fetched per API call (1–100). Defaults to 50.
104
+ * @param options.direction - Filter by `"inbound"` or `"outbound"`.
105
+ */
106
+ iterEmails(options?: {
107
+ pageSize?: number;
108
+ direction?: "inbound" | "outbound";
109
+ }): AsyncGenerator<Message>;
110
+ /**
111
+ * Iterate over unread emails in this identity's inbox, newest first.
112
+ *
113
+ * Fetches all messages and filters client-side. Pagination is handled automatically.
114
+ *
115
+ * @param options.pageSize - Messages fetched per API call (1–100). Defaults to 50.
116
+ * @param options.direction - Filter by `"inbound"` or `"outbound"`.
117
+ */
118
+ iterUnreadEmails(options?: {
119
+ pageSize?: number;
120
+ direction?: "inbound" | "outbound";
121
+ }): AsyncGenerator<Message>;
122
+ /**
123
+ * Mark a list of messages as read.
124
+ *
125
+ * @param messageIds - IDs of the messages to mark as read.
126
+ */
127
+ markEmailsRead(messageIds: string[]): Promise<void>;
128
+ /**
129
+ * Get a thread with all its messages inlined (oldest-first).
130
+ *
131
+ * @param threadId - UUID of the thread to fetch. Obtain via `msg.threadId`
132
+ * on any {@link Message}.
133
+ */
134
+ getThread(threadId: string): Promise<ThreadDetail>;
135
+ /**
136
+ * Place an outbound call from this identity's phone number.
137
+ *
138
+ * @param options.toNumber - E.164 destination number.
139
+ * @param options.clientWebsocketUrl - WebSocket URL (wss://) for audio bridging.
140
+ * @param options.webhookUrl - Custom webhook URL for call lifecycle events.
141
+ */
142
+ placeCall(options: {
143
+ toNumber: string;
144
+ clientWebsocketUrl?: string;
145
+ webhookUrl?: string;
146
+ }): Promise<PhoneCallWithRateLimit>;
147
+ /**
148
+ * List calls made to/from this identity's phone number.
149
+ *
150
+ * @param options.limit - Maximum number of results. Defaults to 50.
151
+ * @param options.offset - Pagination offset. Defaults to 0.
152
+ */
153
+ listCalls(options?: {
154
+ limit?: number;
155
+ offset?: number;
156
+ }): Promise<PhoneCall[]>;
157
+ /**
158
+ * List transcript segments for a specific call.
159
+ *
160
+ * @param callId - ID of the call to fetch transcripts for.
161
+ */
162
+ listTranscripts(callId: string): Promise<PhoneTranscript[]>;
163
+ /**
164
+ * Update this identity's handle or status.
165
+ *
166
+ * @param options.newHandle - New agent handle.
167
+ * @param options.status - New lifecycle status: `"active"` or `"paused"`.
168
+ */
169
+ update(options: {
170
+ newHandle?: string;
171
+ status?: string;
172
+ }): Promise<void>;
173
+ /**
174
+ * Re-fetch this identity from the API and update cached channels.
175
+ *
176
+ * @returns `this` for chaining.
177
+ */
178
+ refresh(): Promise<AgentIdentity>;
179
+ /** Soft-delete this identity (unlinks channels without deleting them). */
180
+ delete(): Promise<void>;
181
+ private _requireMailbox;
182
+ private _requirePhone;
183
+ }
184
+ //# sourceMappingURL=agent_identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent_identity.d.ts","sourceRoot":"","sources":["../src/agent_identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,KAAK,EAEV,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAAqB;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,YAAY,CAA6B;gBAErC,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM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