fauna-api 0.0.0-stage → 1.0.679

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 (171) hide show
  1. package/dist/brands.d.ts +2 -0
  2. package/dist/brands.js +2 -0
  3. package/dist/index.d.ts +64 -0
  4. package/dist/index.js +121 -0
  5. package/dist/src/ant/chat.d.ts +130 -0
  6. package/dist/src/ant/chat.js +467 -0
  7. package/dist/src/ant/format.d.ts +40 -0
  8. package/dist/src/ant/format.js +143 -0
  9. package/dist/src/ant/graph.d.ts +130 -0
  10. package/dist/src/ant/graph.js +449 -0
  11. package/dist/src/ant/index.d.ts +16 -0
  12. package/dist/src/ant/index.js +61 -0
  13. package/dist/src/ant/persona.d.ts +151 -0
  14. package/dist/src/ant/persona.js +136 -0
  15. package/dist/src/ant/timeline.d.ts +283 -0
  16. package/dist/src/ant/timeline.js +1025 -0
  17. package/dist/src/authentification.d.ts +45 -0
  18. package/dist/src/authentification.js +194 -0
  19. package/dist/src/billing.d.ts +135 -0
  20. package/dist/src/billing.js +128 -0
  21. package/dist/src/calendar.d.ts +83 -0
  22. package/dist/src/calendar.js +133 -0
  23. package/dist/src/chats.d.ts +113 -0
  24. package/dist/src/chats.js +100 -0
  25. package/dist/src/cicada/contacts.d.ts +31 -0
  26. package/dist/src/cicada/contacts.js +28 -0
  27. package/dist/src/cicada/conversations.d.ts +73 -0
  28. package/dist/src/cicada/conversations.js +236 -0
  29. package/dist/src/cicada/inboxes.d.ts +48 -0
  30. package/dist/src/cicada/inboxes.js +82 -0
  31. package/dist/src/cicada/index.d.ts +16 -0
  32. package/dist/src/cicada/index.js +61 -0
  33. package/dist/src/cicada/phone.d.ts +48 -0
  34. package/dist/src/cicada/phone.js +306 -0
  35. package/dist/src/drive.d.ts +80 -0
  36. package/dist/src/drive.js +472 -0
  37. package/dist/src/extensions/index.d.ts +4 -0
  38. package/dist/src/extensions/index.js +5 -0
  39. package/dist/src/extensions/web/index.d.ts +6 -0
  40. package/dist/src/extensions/web/index.js +7 -0
  41. package/dist/src/extensions/web/session.d.ts +108 -0
  42. package/dist/src/extensions/web/session.js +470 -0
  43. package/dist/src/extensions/web/tools.d.ts +13 -0
  44. package/dist/src/extensions/web/tools.js +72 -0
  45. package/dist/src/friends.d.ts +39 -0
  46. package/dist/src/friends.js +119 -0
  47. package/dist/src/groups.d.ts +82 -0
  48. package/dist/src/groups.js +269 -0
  49. package/dist/src/inbox.d.ts +11 -0
  50. package/dist/src/inbox.js +35 -0
  51. package/dist/src/integrations.d.ts +52 -0
  52. package/dist/src/integrations.js +205 -0
  53. package/dist/src/magpie/explorer.d.ts +14 -0
  54. package/dist/src/magpie/explorer.js +36 -0
  55. package/dist/src/magpie/index.d.ts +16 -0
  56. package/dist/src/magpie/index.js +61 -0
  57. package/dist/src/magpie/portfolio.d.ts +52 -0
  58. package/dist/src/magpie/portfolio.js +179 -0
  59. package/dist/src/magpie/quotes.d.ts +35 -0
  60. package/dist/src/magpie/quotes.js +47 -0
  61. package/dist/src/magpie/room.d.ts +61 -0
  62. package/dist/src/magpie/room.js +238 -0
  63. package/dist/src/maps.d.ts +159 -0
  64. package/dist/src/maps.js +171 -0
  65. package/dist/src/marmot/browser.d.ts +139 -0
  66. package/dist/src/marmot/browser.js +389 -0
  67. package/dist/src/marmot/index.d.ts +20 -0
  68. package/dist/src/marmot/index.js +65 -0
  69. package/dist/src/marmot/media.d.ts +56 -0
  70. package/dist/src/marmot/media.js +265 -0
  71. package/dist/src/marmot/research.d.ts +337 -0
  72. package/dist/src/marmot/research.js +1138 -0
  73. package/dist/src/marmot/scraper.d.ts +59 -0
  74. package/dist/src/marmot/scraper.js +94 -0
  75. package/dist/src/marmot/web.d.ts +402 -0
  76. package/dist/src/marmot/web.js +2586 -0
  77. package/dist/src/marmot/workspace.d.ts +81 -0
  78. package/dist/src/marmot/workspace.js +263 -0
  79. package/dist/src/parrot/agent.d.ts +53 -0
  80. package/dist/src/parrot/agent.js +93 -0
  81. package/dist/src/parrot/chat.d.ts +84 -0
  82. package/dist/src/parrot/chat.js +237 -0
  83. package/dist/src/parrot/format.d.ts +128 -0
  84. package/dist/src/parrot/format.js +639 -0
  85. package/dist/src/parrot/generative.d.ts +261 -0
  86. package/dist/src/parrot/generative.js +185 -0
  87. package/dist/src/parrot/index.d.ts +22 -0
  88. package/dist/src/parrot/index.js +67 -0
  89. package/dist/src/parrot/room.d.ts +225 -0
  90. package/dist/src/parrot/room.js +466 -0
  91. package/dist/src/parrot/routing.d.ts +90 -0
  92. package/dist/src/parrot/routing.js +78 -0
  93. package/dist/src/parrot/share.d.ts +126 -0
  94. package/dist/src/parrot/share.js +261 -0
  95. package/dist/src/parrot/socket.d.ts +41 -0
  96. package/dist/src/parrot/socket.js +478 -0
  97. package/dist/src/payments.d.ts +73 -0
  98. package/dist/src/payments.js +107 -0
  99. package/dist/src/private/cards.css +75 -0
  100. package/dist/src/rooms.d.ts +76 -0
  101. package/dist/src/rooms.js +168 -0
  102. package/dist/src/shared/schema.d.ts +24 -0
  103. package/dist/src/shared/schema.js +1 -0
  104. package/dist/src/shared/server.d.ts +65 -0
  105. package/dist/src/shared/server.js +302 -0
  106. package/dist/src/termite/environment.d.ts +110 -0
  107. package/dist/src/termite/environment.js +263 -0
  108. package/dist/src/termite/index.d.ts +14 -0
  109. package/dist/src/termite/index.js +59 -0
  110. package/dist/src/termite/os.d.ts +326 -0
  111. package/dist/src/termite/os.js +572 -0
  112. package/dist/src/termite/versioning.d.ts +94 -0
  113. package/dist/src/termite/versioning.js +217 -0
  114. package/dist/src/tickets.d.ts +43 -0
  115. package/dist/src/tickets.js +138 -0
  116. package/dist/src/travel.d.ts +85 -0
  117. package/dist/src/travel.js +44 -0
  118. package/dist/src/ui/authentification.d.ts +24 -0
  119. package/dist/src/ui/authentification.js +177 -0
  120. package/dist/src/ui/brands.css +11 -0
  121. package/dist/src/ui/brands.d.ts +7 -0
  122. package/dist/src/ui/brands.js +14 -0
  123. package/dist/src/ui/browser.d.ts +74 -0
  124. package/dist/src/ui/browser.js +470 -0
  125. package/dist/src/ui/chat.d.ts +183 -0
  126. package/dist/src/ui/chat.js +2379 -0
  127. package/dist/src/ui/chatPanel.d.ts +109 -0
  128. package/dist/src/ui/chatPanel.js +768 -0
  129. package/dist/src/ui/chatSequence.d.ts +36 -0
  130. package/dist/src/ui/chatSequence.js +42 -0
  131. package/dist/src/ui/crown.d.ts +19 -0
  132. package/dist/src/ui/crown.js +199 -0
  133. package/dist/src/ui/cursor.d.ts +73 -0
  134. package/dist/src/ui/cursor.js +175 -0
  135. package/dist/src/ui/device.d.ts +33 -0
  136. package/dist/src/ui/device.js +49 -0
  137. package/dist/src/ui/drive.d.ts +69 -0
  138. package/dist/src/ui/drive.js +1243 -0
  139. package/dist/src/ui/generative.d.ts +39 -0
  140. package/dist/src/ui/generative.js +313 -0
  141. package/dist/src/ui/hover.d.ts +6 -0
  142. package/dist/src/ui/hover.js +210 -0
  143. package/dist/src/ui/index.d.ts +42 -0
  144. package/dist/src/ui/index.js +87 -0
  145. package/dist/src/ui/integrations.d.ts +13 -0
  146. package/dist/src/ui/integrations.js +175 -0
  147. package/dist/src/ui/maps.d.ts +87 -0
  148. package/dist/src/ui/maps.js +547 -0
  149. package/dist/src/ui/roster.d.ts +32 -0
  150. package/dist/src/ui/roster.js +163 -0
  151. package/dist/src/ui/talk.d.ts +12 -0
  152. package/dist/src/ui/talk.js +560 -0
  153. package/dist/src/ui/tickets.d.ts +13 -0
  154. package/dist/src/ui/tickets.js +966 -0
  155. package/dist/src/ui/toast.d.ts +7 -0
  156. package/dist/src/ui/toast.js +258 -0
  157. package/dist/src/ui/tokenText.d.ts +18 -0
  158. package/dist/src/ui/tokenText.js +96 -0
  159. package/dist/src/ui/tokenized.d.ts +42 -0
  160. package/dist/src/ui/tokenized.js +622 -0
  161. package/dist/src/ui/ui.css +4763 -0
  162. package/dist/src/ui/view.d.ts +23 -0
  163. package/dist/src/ui/view.js +584 -0
  164. package/dist/src/view.d.ts +113 -0
  165. package/dist/src/view.js +386 -0
  166. package/dist/src/webhooks.d.ts +66 -0
  167. package/dist/src/webhooks.js +78 -0
  168. package/dist/ui.d.ts +1 -0
  169. package/dist/ui.js +1 -0
  170. package/package.json +87 -4
  171. package/README.md +0 -3
@@ -0,0 +1,236 @@
1
+ import { Cicada } from "./index.js";
2
+ function wrapConversation(raw) {
3
+ return {
4
+ ...raw,
5
+ inboxId: raw.inboxId !== undefined ? String(raw.inboxId) : undefined,
6
+ activeAt: new Date(raw.activeAt)
7
+ };
8
+ }
9
+ function wrapMessage(raw) {
10
+ return {
11
+ ...raw,
12
+ createdAt: new Date(raw.createdAt),
13
+ attachments: raw.attachments ?? [],
14
+ agent: raw.agent === true,
15
+ };
16
+ }
17
+ async function listView(authorization, path, inboxId) {
18
+ const response = await fetch(`${Cicada.getURL()}${path}`, {
19
+ method: "POST",
20
+ headers: {
21
+ "Content-Type": "application/json",
22
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
23
+ },
24
+ body: JSON.stringify(inboxId ? { inboxId } : {})
25
+ });
26
+ if (!response.ok)
27
+ throw new Error(await response.text());
28
+ const json = await response.json();
29
+ return json.map(wrapConversation);
30
+ }
31
+ // The inbox working set: everything except archived threads and conversations
32
+ // parked for a future reminder.
33
+ export async function listInbox(authorization, inboxId) {
34
+ return listView(authorization, '/cicada/inbox', inboxId);
35
+ }
36
+ // The archive.
37
+ export async function listArchived(authorization, inboxId) {
38
+ return listView(authorization, '/cicada/archived', inboxId);
39
+ }
40
+ // Threads with a pending (future) remindAt, each paired with its due time.
41
+ export async function listReminders(authorization, inboxId) {
42
+ const response = await fetch(`${Cicada.getURL()}/cicada/reminders`, {
43
+ method: "POST",
44
+ headers: {
45
+ "Content-Type": "application/json",
46
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
47
+ },
48
+ body: JSON.stringify(inboxId ? { inboxId } : {})
49
+ });
50
+ if (!response.ok)
51
+ throw new Error(await response.text());
52
+ const json = await response.json();
53
+ return json.map((raw) => ({
54
+ conversation: wrapConversation(raw.conversation),
55
+ remindAt: new Date(raw.remindAt)
56
+ }));
57
+ }
58
+ // Fetch a single conversation's metadata by id (hydrated participants), or null
59
+ // if it no longer exists.
60
+ export async function get(authorization, conversation) {
61
+ const response = await fetch(`${Cicada.getURL()}/cicada/conversation/get`, {
62
+ method: "POST",
63
+ headers: {
64
+ "Content-Type": "application/json",
65
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
66
+ },
67
+ body: JSON.stringify({ conversation })
68
+ });
69
+ if (!response.ok)
70
+ throw new Error(await response.text());
71
+ const json = await response.json();
72
+ return json ? wrapConversation(json) : null;
73
+ }
74
+ export async function read(authorization, conversation) {
75
+ const response = await fetch(`${Cicada.getURL()}/cicada/conversation`, {
76
+ method: "POST",
77
+ headers: {
78
+ "Content-Type": "application/json",
79
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
80
+ },
81
+ body: JSON.stringify({ conversation })
82
+ });
83
+ if (!response.ok)
84
+ throw new Error(await response.text());
85
+ const json = await response.json();
86
+ return json.map(wrapMessage);
87
+ }
88
+ // Suggest a continuation of an in-progress reply for a conversation. Returns
89
+ // the raw completion text (the part that should follow the current draft); an
90
+ // empty string means no suggestion.
91
+ export async function autocomplete(authorization, conversation, text) {
92
+ const response = await fetch(`${Cicada.getURL()}/cicada/autocomplete`, {
93
+ method: "POST",
94
+ headers: {
95
+ "Content-Type": "application/json",
96
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
97
+ },
98
+ body: JSON.stringify({ conversation, text })
99
+ });
100
+ if (!response.ok)
101
+ throw new Error(await response.text());
102
+ return await response.text();
103
+ }
104
+ export async function markRead(authorization, conversation) {
105
+ const response = await fetch(`${Cicada.getURL()}/cicada/conversation/mark-read`, {
106
+ method: "POST",
107
+ headers: {
108
+ "Content-Type": "application/json",
109
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
110
+ },
111
+ body: JSON.stringify({ conversation })
112
+ });
113
+ if (!response.ok)
114
+ throw new Error(await response.text());
115
+ }
116
+ // Permanently delete a conversation (index entry + stored messages). Backfill
117
+ // won't repopulate it — it only runs on account link, and polling fetches
118
+ // deltas, so old messages never re-arrive.
119
+ export async function remove(authorization, conversation) {
120
+ const response = await fetch(`${Cicada.getURL()}/cicada/conversation/delete`, {
121
+ method: "POST",
122
+ headers: {
123
+ "Content-Type": "application/json",
124
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
125
+ },
126
+ body: JSON.stringify({ conversation })
127
+ });
128
+ if (!response.ok)
129
+ throw new Error(await response.text());
130
+ }
131
+ // Start (or append to) conversations with picked contacts on a platform.
132
+ // `recipients` are contact keys (email/handle/phone). `broadcast` sends a
133
+ // separate 1:1 to each; `group` sends one shared thread (collapsing to
134
+ // broadcast on platforms without a real group path). Returns the affected
135
+ // conversation ids — open the first to show the resulting thread.
136
+ export async function compose(authorization, options) {
137
+ const response = await fetch(`${Cicada.getURL()}/cicada/compose`, {
138
+ method: "POST",
139
+ headers: {
140
+ "Content-Type": "application/json",
141
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
142
+ },
143
+ body: JSON.stringify(options)
144
+ });
145
+ if (!response.ok)
146
+ throw new Error(await response.text());
147
+ const json = await response.json();
148
+ return json.conversationIds;
149
+ }
150
+ export async function send(authorization, conversation, text, platform) {
151
+ const response = await fetch(`${Cicada.getURL()}/cicada/send`, {
152
+ method: "POST",
153
+ headers: {
154
+ "Content-Type": "application/json",
155
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
156
+ },
157
+ body: JSON.stringify({ conversation, text, platform })
158
+ });
159
+ if (!response.ok)
160
+ throw new Error(await response.text());
161
+ const json = await response.json();
162
+ return json.id;
163
+ }
164
+ // Move a conversation in/out of the archive.
165
+ export async function archive(authorization, conversation, archived) {
166
+ const response = await fetch(`${Cicada.getURL()}/cicada/conversation/archive`, {
167
+ method: "POST",
168
+ headers: {
169
+ "Content-Type": "application/json",
170
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
171
+ },
172
+ body: JSON.stringify({ conversation, archived })
173
+ });
174
+ if (!response.ok)
175
+ throw new Error(await response.text());
176
+ }
177
+ // Set (or clear, with `at = null`) a reminder on a conversation. When the time
178
+ // arrives the server re-surfaces the thread at the top of the inbox.
179
+ export async function remind(authorization, conversation, at) {
180
+ const response = await fetch(`${Cicada.getURL()}/cicada/conversation/remind`, {
181
+ method: "POST",
182
+ headers: {
183
+ "Content-Type": "application/json",
184
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
185
+ },
186
+ body: JSON.stringify({ conversation, at: at ? at.toISOString() : null })
187
+ });
188
+ if (!response.ok)
189
+ throw new Error(await response.text());
190
+ }
191
+ // Queue an outbound message for later. Provide `conversationId` to reply into an
192
+ // existing thread, or `compose` to start a fresh one. Returns the queue id.
193
+ export async function schedule(authorization, options) {
194
+ const response = await fetch(`${Cicada.getURL()}/cicada/schedule`, {
195
+ method: "POST",
196
+ headers: {
197
+ "Content-Type": "application/json",
198
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
199
+ },
200
+ body: JSON.stringify({ ...options, sendAt: options.sendAt.toISOString() })
201
+ });
202
+ if (!response.ok)
203
+ throw new Error(await response.text());
204
+ const json = await response.json();
205
+ return json.id;
206
+ }
207
+ export async function listScheduled(authorization, inboxId) {
208
+ const response = await fetch(`${Cicada.getURL()}/cicada/scheduled/list`, {
209
+ method: "POST",
210
+ headers: {
211
+ "Content-Type": "application/json",
212
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
213
+ },
214
+ body: JSON.stringify(inboxId ? { inboxId } : {})
215
+ });
216
+ if (!response.ok)
217
+ throw new Error(await response.text());
218
+ const json = await response.json();
219
+ return json.map((raw) => ({
220
+ ...raw,
221
+ sendAt: new Date(raw.sendAt),
222
+ createdAt: new Date(raw.createdAt)
223
+ }));
224
+ }
225
+ export async function cancelScheduled(authorization, scheduled) {
226
+ const response = await fetch(`${Cicada.getURL()}/cicada/scheduled/cancel`, {
227
+ method: "POST",
228
+ headers: {
229
+ "Content-Type": "application/json",
230
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
231
+ },
232
+ body: JSON.stringify({ scheduled })
233
+ });
234
+ if (!response.ok)
235
+ throw new Error(await response.text());
236
+ }
@@ -0,0 +1,48 @@
1
+ import { Cicada } from "./index.js";
2
+ import { Platform } from "../integrations.js";
3
+ import { Credentials, ApiKey } from "../authentification.js";
4
+ import type { Text } from "../parrot/generative.js";
5
+ export type InboxGroup = {
6
+ id: string;
7
+ name: string;
8
+ icon?: string;
9
+ };
10
+ export type Inbox = {
11
+ id: string;
12
+ name: string;
13
+ createdAt: Date;
14
+ group?: InboxGroup;
15
+ };
16
+ export type InboxAccount = {
17
+ platform: Platform;
18
+ accountId: string;
19
+ };
20
+ export declare function list(authorization: Credentials | ApiKey): Promise<Inbox[]>;
21
+ export declare function create(authorization: Credentials | ApiKey, name: string): Promise<Inbox>;
22
+ export declare function rename(authorization: Credentials | ApiKey, inboxId: string, name: string): Promise<Inbox>;
23
+ export declare function remove(authorization: Credentials | ApiKey, inboxId: string): Promise<void>;
24
+ export declare function moveToGroup(authorization: Credentials | ApiKey, inboxId: string, groupId: string): Promise<Inbox>;
25
+ export declare function assign(authorization: Credentials | ApiKey, inboxId: string, account: {
26
+ platform: Platform;
27
+ accountId: string;
28
+ }): Promise<void>;
29
+ export declare function listAccounts(authorization: Credentials | ApiKey, inboxId: string): Promise<InboxAccount[]>;
30
+ /** `dailyLimit` and `spentToday` are dollars per UTC day; at the limit the agent pauses until midnight UTC. */
31
+ export type AgentSettings = {
32
+ model: Text;
33
+ instructions: string;
34
+ dailyLimit: number;
35
+ spentToday: number;
36
+ enabledAt: Date;
37
+ };
38
+ export declare const AgentSettings: {
39
+ fromJSON(json: any): AgentSettings;
40
+ };
41
+ export declare function getAgent(authorization: Credentials | ApiKey, inbox: string): Promise<AgentSettings | undefined>;
42
+ /** Turns the agent on (it answers messages sent from now on) or updates it. */
43
+ export declare function setAgent(authorization: Credentials | ApiKey, inbox: string, settings: {
44
+ model: Text;
45
+ instructions: string;
46
+ dailyLimit: number;
47
+ }): Promise<AgentSettings>;
48
+ export declare function clearAgent(authorization: Credentials | ApiKey, inbox: string): Promise<void>;
@@ -0,0 +1,82 @@
1
+ import { Cicada } from "./index.js";
2
+ async function post(authorization, path, body) {
3
+ const response = await fetch(`${Cicada.getURL()}${path}`, {
4
+ method: 'POST',
5
+ headers: {
6
+ 'Content-Type': 'application/json',
7
+ Authorization: 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
8
+ },
9
+ body: JSON.stringify(body ?? {})
10
+ });
11
+ if (!response.ok)
12
+ throw new Error(await response.text());
13
+ return response;
14
+ }
15
+ function wrapInbox(raw) {
16
+ const group = raw.group && typeof raw.group === 'object'
17
+ ? {
18
+ id: String(raw.group.id),
19
+ name: String(raw.group.name ?? ''),
20
+ ...(raw.group.icon ? { icon: String(raw.group.icon) } : {}),
21
+ }
22
+ : undefined;
23
+ return {
24
+ id: String(raw.id),
25
+ name: raw.name,
26
+ createdAt: new Date(raw.createdAt),
27
+ ...(group ? { group } : {}),
28
+ };
29
+ }
30
+ export async function list(authorization) {
31
+ const response = await post(authorization, '/cicada/inboxes');
32
+ return (await response.json()).map(wrapInbox);
33
+ }
34
+ export async function create(authorization, name) {
35
+ const response = await post(authorization, '/cicada/inboxes/create', { name });
36
+ return wrapInbox(await response.json());
37
+ }
38
+ export async function rename(authorization, inboxId, name) {
39
+ const response = await post(authorization, '/cicada/inboxes/rename', { inbox: inboxId, name });
40
+ return wrapInbox(await response.json());
41
+ }
42
+ export async function remove(authorization, inboxId) {
43
+ await post(authorization, '/cicada/inboxes/delete', { inbox: inboxId });
44
+ }
45
+ export async function moveToGroup(authorization, inboxId, groupId) {
46
+ const response = await post(authorization, '/cicada/inboxes/move', { inbox: inboxId, group: groupId });
47
+ return wrapInbox(await response.json());
48
+ }
49
+ export async function assign(authorization, inboxId, account) {
50
+ await post(authorization, '/cicada/inboxes/accounts', { inbox: inboxId, ...account });
51
+ }
52
+ export async function listAccounts(authorization, inboxId) {
53
+ const response = await post(authorization, '/cicada/inboxes/accounts/list', { inbox: inboxId });
54
+ return (await response.json()).map((raw) => ({
55
+ platform: raw.platform,
56
+ accountId: raw.accountId
57
+ }));
58
+ }
59
+ export const AgentSettings = {
60
+ fromJSON(json) {
61
+ return {
62
+ model: json.model,
63
+ instructions: String(json.instructions ?? ''),
64
+ dailyLimit: Number(json.dailyLimit ?? 0),
65
+ spentToday: Number(json.spentToday ?? 0),
66
+ enabledAt: new Date(json.enabledAt),
67
+ };
68
+ },
69
+ };
70
+ export async function getAgent(authorization, inbox) {
71
+ const response = await post(authorization, '/cicada/inboxes/agent', { inbox });
72
+ const text = await response.text();
73
+ return text.trim() ? AgentSettings.fromJSON(JSON.parse(text)) : undefined;
74
+ }
75
+ /** Turns the agent on (it answers messages sent from now on) or updates it. */
76
+ export async function setAgent(authorization, inbox, settings) {
77
+ const response = await post(authorization, '/cicada/inboxes/agent/set', { inbox, ...settings });
78
+ return AgentSettings.fromJSON(await response.json());
79
+ }
80
+ export async function clearAgent(authorization, inbox) {
81
+ await post(authorization, '/cicada/inboxes/agent/clear', { inbox });
82
+ }
@@ -0,0 +1,16 @@
1
+ import * as ContactsAPI from "./contacts.js";
2
+ import * as ConversationsAPI from "./conversations.js";
3
+ import * as InboxesAPI from "./inboxes.js";
4
+ import * as PhoneAPI from "./phone.js";
5
+ export declare namespace Cicada {
6
+ function setRoute(route: string): void;
7
+ function getIP(): string;
8
+ function getPort(): number;
9
+ function getRoute(): string;
10
+ function getURL(): string;
11
+ function ping(): Promise<number>;
12
+ export import Contacts = ContactsAPI;
13
+ export import Conversations = ConversationsAPI;
14
+ export import Inboxes = InboxesAPI;
15
+ export import Phone = PhoneAPI;
16
+ }
@@ -0,0 +1,61 @@
1
+ import * as ContactsAPI from "./contacts.js";
2
+ import * as ConversationsAPI from "./conversations.js";
3
+ import * as InboxesAPI from "./inboxes.js";
4
+ import * as PhoneAPI from "./phone.js";
5
+ export var Cicada;
6
+ (function (Cicada) {
7
+ var PREFIX = 'https://';
8
+ var IP = 'api.faunakit.com';
9
+ var PORT = 443;
10
+ function setRoute(route) {
11
+ const parts_0 = route.split('//');
12
+ if (parts_0.length > 1) {
13
+ PREFIX = parts_0[0] + '//';
14
+ const parts_1 = parts_0[1].split(':');
15
+ if (parts_1.length > 1) {
16
+ IP = parts_1[0];
17
+ PORT = Number(parts_1[1]);
18
+ }
19
+ else {
20
+ IP = parts_1[0];
21
+ }
22
+ }
23
+ else {
24
+ const parts_1 = parts_0[0].split(':');
25
+ if (parts_1.length > 1) {
26
+ IP = parts_1[0];
27
+ PORT = Number(parts_1[1]);
28
+ }
29
+ else {
30
+ IP = parts_1[0];
31
+ }
32
+ }
33
+ }
34
+ Cicada.setRoute = setRoute;
35
+ function getIP() {
36
+ return IP;
37
+ }
38
+ Cicada.getIP = getIP;
39
+ function getPort() {
40
+ return PORT;
41
+ }
42
+ Cicada.getPort = getPort;
43
+ function getRoute() {
44
+ return IP + ':' + PORT;
45
+ }
46
+ Cicada.getRoute = getRoute;
47
+ function getURL() {
48
+ return PREFIX + IP + ':' + PORT;
49
+ }
50
+ Cicada.getURL = getURL;
51
+ async function ping() {
52
+ const start = Date.now();
53
+ await fetch(`${getURL()}/`);
54
+ return Date.now() - start;
55
+ }
56
+ Cicada.ping = ping;
57
+ Cicada.Contacts = ContactsAPI;
58
+ Cicada.Conversations = ConversationsAPI;
59
+ Cicada.Inboxes = InboxesAPI;
60
+ Cicada.Phone = PhoneAPI;
61
+ })(Cicada || (Cicada = {}));
@@ -0,0 +1,48 @@
1
+ import { Credentials, ApiKey } from "../authentification.js";
2
+ import WebSocket from "isomorphic-ws";
3
+ export type CallEnd = {
4
+ status: 'COMPLETED' | 'NO_ANSWER' | 'BUSY' | 'FAILED' | 'CANCELED';
5
+ duration: number;
6
+ };
7
+ export type RingEnd = 'ACCEPTED' | 'TAKEN' | 'VOICEMAIL' | 'HUNG_UP';
8
+ export declare class PhoneCall {
9
+ #private;
10
+ readonly id: string;
11
+ readonly direction: 'IN' | 'OUT';
12
+ /** The linked Twilio number, E.164. */
13
+ readonly line: string;
14
+ /** The other party, E.164. */
15
+ readonly peer: string;
16
+ status: 'RINGING' | 'ACTIVE' | 'ENDED';
17
+ private constructor();
18
+ /** Calls `listener` when the call is answered (ACTIVE) and when it ends (ENDED). */
19
+ onStatus(listener: (status: PhoneCall['status']) => void): () => void;
20
+ /** The other party's audio: PCM16 mono 16 kHz, the same as generateVoice's audio input. */
21
+ audio(): AsyncIterable<Uint8Array>;
22
+ /** Audio to the other party: PCM16 mono 24 kHz, the same as generateVoice's audio output. */
23
+ send(pcm: Uint8Array): void;
24
+ hangup(): Promise<void>;
25
+ /** Resolves once the call is over. duration is seconds of talk, 0 when never answered. */
26
+ ended(): Promise<CallEnd>;
27
+ static fromJSON(json: any, ws: WebSocket): PhoneCall;
28
+ }
29
+ export declare class IncomingCall {
30
+ #private;
31
+ readonly id: string;
32
+ /** The inbox's number that was called. */
33
+ readonly line: string;
34
+ /** Who is calling. */
35
+ readonly peer: string;
36
+ private constructor();
37
+ /** Rejects with "Someone else took the call." when another listener won. */
38
+ accept(): Promise<PhoneCall>;
39
+ /** Resolves when it stops ringing for you. */
40
+ ringing(): Promise<RingEnd>;
41
+ static fromJSON(json: any, authorization: Credentials | ApiKey): IncomingCall;
42
+ }
43
+ /** Rings for calls to any Twilio number linked to the inbox, until close(). */
44
+ export declare function listen(authorization: Credentials | ApiKey, inbox: string, onIncoming: (call: IncomingCall) => void): Promise<{
45
+ close(): void;
46
+ }>;
47
+ /** Calls `to` from one of the inbox's phone lines: `from`, or its first line. */
48
+ export declare function call(authorization: Credentials | ApiKey, inbox: string, to: string, from?: string): Promise<PhoneCall>;