fauna-api 0.0.0-stage → 1.0.676

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 +106 -0
  42. package/dist/src/extensions/web/session.js +469 -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 +89 -6
  171. package/README.md +0 -3
@@ -0,0 +1,133 @@
1
+ import { Fauna } from "../index.js";
2
+ const Event = {
3
+ fromJSON(json) {
4
+ return {
5
+ ...json,
6
+ start: new Date(json.start),
7
+ end: new Date(json.end),
8
+ created: new Date(json.created),
9
+ updated: new Date(json.updated),
10
+ source: json.source ?? null,
11
+ attendees: json.attendees ?? [],
12
+ };
13
+ },
14
+ };
15
+ function draftJSON(draft) {
16
+ return {
17
+ ...draft,
18
+ start: draft.start?.getTime(),
19
+ end: draft.end?.getTime(),
20
+ };
21
+ }
22
+ /**
23
+ * Events between `from` and `to` (at most 400 days apart), one per occurrence,
24
+ * soonest first. With `group`, that group's calendar; otherwise yours, your
25
+ * groups' and the events you're invited to.
26
+ */
27
+ export async function list(authorization, from, to, group) {
28
+ const response = await fetch(`${Fauna.getURL()}/calendar/events?from=${from.getTime()}&to=${to.getTime()}`, {
29
+ method: "GET",
30
+ headers: {
31
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
32
+ ...(group ? { "Group": group.id } : {})
33
+ }
34
+ });
35
+ if (!response.ok)
36
+ throw new Error(await response.text());
37
+ return (await response.json()).map(Event.fromJSON);
38
+ }
39
+ /** One event on your calendar, a group's, or one you're invited to. */
40
+ export async function get(authorization, id) {
41
+ const response = await fetch(`${Fauna.getURL()}/calendar/events/${encodeURIComponent(id)}`, {
42
+ method: "GET",
43
+ headers: {
44
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
45
+ }
46
+ });
47
+ if (!response.ok)
48
+ throw new Error(await response.text());
49
+ return Event.fromJSON(await response.json());
50
+ }
51
+ /** Put an event on your calendar, or `group`'s, and email everyone it invites. */
52
+ export async function create(authorization, draft, group) {
53
+ const response = await fetch(`${Fauna.getURL()}/calendar/events`, {
54
+ method: "POST",
55
+ headers: {
56
+ "Content-Type": "application/json",
57
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
58
+ ...(group ? { "Group": group.id } : {})
59
+ },
60
+ body: JSON.stringify(draftJSON(draft))
61
+ });
62
+ if (!response.ok)
63
+ throw new Error(await response.text());
64
+ return Event.fromJSON(await response.json());
65
+ }
66
+ /**
67
+ * Change an event on your calendar or a group's. A recurring event changes as a
68
+ * whole. New invitees get invited; the rest hear about a new time or place.
69
+ */
70
+ export async function update(authorization, id, update) {
71
+ const response = await fetch(`${Fauna.getURL()}/calendar/events/${encodeURIComponent(id)}`, {
72
+ method: "PATCH",
73
+ headers: {
74
+ "Content-Type": "application/json",
75
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
76
+ },
77
+ body: JSON.stringify(draftJSON(update))
78
+ });
79
+ if (!response.ok)
80
+ throw new Error(await response.text());
81
+ return Event.fromJSON(await response.json());
82
+ }
83
+ /** Remove an event from your calendar or a group's, telling everyone it invited. */
84
+ export async function remove(authorization, id) {
85
+ const response = await fetch(`${Fauna.getURL()}/calendar/events/${encodeURIComponent(id)}`, {
86
+ method: "DELETE",
87
+ headers: {
88
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
89
+ }
90
+ });
91
+ if (!response.ok)
92
+ throw new Error(await response.text());
93
+ }
94
+ /** Answer an event you're invited to: `yes`, `no` or `maybe`. */
95
+ export async function respond(authorization, id, answer) {
96
+ const response = await fetch(`${Fauna.getURL()}/calendar/events/${encodeURIComponent(id)}/respond`, {
97
+ method: "POST",
98
+ headers: {
99
+ "Content-Type": "application/json",
100
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
101
+ },
102
+ body: JSON.stringify({ response: answer })
103
+ });
104
+ if (!response.ok)
105
+ throw new Error(await response.text());
106
+ return Event.fromJSON(await response.json());
107
+ }
108
+ /** The secret .ics link for your calendar, or `group`'s, for Google, Apple or Outlook to subscribe to. */
109
+ export async function feed(authorization, group) {
110
+ const response = await fetch(`${Fauna.getURL()}/calendar/feed`, {
111
+ method: "GET",
112
+ headers: {
113
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
114
+ ...(group ? { "Group": group.id } : {})
115
+ }
116
+ });
117
+ if (!response.ok)
118
+ throw new Error(await response.text());
119
+ return (await response.json()).url;
120
+ }
121
+ /** A new .ics link for your calendar, or `group`'s. The old one stops working. */
122
+ export async function resetFeed(credentials, group) {
123
+ const response = await fetch(`${Fauna.getURL()}/calendar/feed/reset`, {
124
+ method: "POST",
125
+ headers: {
126
+ "Authorization": `Token ${credentials.token}`,
127
+ ...(group ? { "Group": group.id } : {})
128
+ }
129
+ });
130
+ if (!response.ok)
131
+ throw new Error(await response.text());
132
+ return (await response.json()).url;
133
+ }
@@ -0,0 +1,113 @@
1
+ import { ApiKey, Credentials, Profile } from "./authentification.js";
2
+ import { LastMessage } from "./parrot/chat.js";
3
+ /** Whose chat it is: one of your groups, a friendship, or a partnership of one of your groups. */
4
+ export type OwnerKind = 'group' | 'friend' | 'partnership';
5
+ /** Who a chat belongs to, and how much you trust it. */
6
+ export type Owner = {
7
+ kind: OwnerKind;
8
+ /** The group, friendship or partnership id. */
9
+ id: string;
10
+ /** The group's name, your friend's name, or the partner group's name. */
11
+ name: string;
12
+ /** Your trust in your friend, or your group's trust in the partner group, in [0, 1). Null for your own groups, which always count. */
13
+ trust: number | null;
14
+ /** For a partnership: your group in it. */
15
+ group?: {
16
+ id: string;
17
+ name: string;
18
+ };
19
+ };
20
+ /** A chat you share with others. */
21
+ export type Chat = {
22
+ id: string;
23
+ name: string;
24
+ /** People only: sends never start a model reply. */
25
+ human: boolean;
26
+ owner: Owner;
27
+ /** Messages you haven't read. Signed in with an API key, the key keeps its own place. */
28
+ unread: number;
29
+ /** Milliseconds since the epoch. */
30
+ updated: number;
31
+ last: LastMessage | null;
32
+ };
33
+ /** A message as plain text: mentions as names, files as `[file: name]`. */
34
+ export type Message = {
35
+ position: number;
36
+ role: string;
37
+ text: string;
38
+ author?: Profile;
39
+ /** The name of the API key an agent posted it with. */
40
+ via?: string;
41
+ /** Milliseconds since the epoch. */
42
+ created: number;
43
+ };
44
+ /** What you haven't read, in chats that pass a trust threshold. */
45
+ export type Unread = {
46
+ total: number;
47
+ chats: Chat[];
48
+ };
49
+ /** A chat in a catch up, with what you hadn't read, oldest first. */
50
+ export type CaughtUpChat = {
51
+ id: string;
52
+ name: string;
53
+ human: boolean;
54
+ owner: Owner;
55
+ updated: number;
56
+ messages: Message[];
57
+ };
58
+ export type CaughtUp = {
59
+ chats: CaughtUpChat[];
60
+ /** More unread is waiting: catch up again for the next batch. */
61
+ more: boolean;
62
+ /** Unread left in chats that pass, after this batch. */
63
+ unread: number;
64
+ };
65
+ /** The chat a search found a message in. */
66
+ export type ChatReference = {
67
+ id: string;
68
+ name: string;
69
+ owner: Owner;
70
+ };
71
+ export type Found = {
72
+ chat: ChatReference;
73
+ message: Message;
74
+ };
75
+ /**
76
+ * Every chat you share with others, newest first: your groups', your friends'
77
+ * and your groups' partnerships', each with its owner, your trust in it and what
78
+ * you haven't read.
79
+ */
80
+ export declare function list(authorization: Credentials | ApiKey): Promise<Chat[]>;
81
+ /**
82
+ * What you haven't read in chats you trust at least `minTrust` (default 0.1).
83
+ * Your own groups' chats always count.
84
+ */
85
+ export declare function unread(authorization: Credentials | ApiKey, options?: {
86
+ minTrust?: number;
87
+ }): Promise<Unread>;
88
+ /**
89
+ * Everything you haven't read in chats you trust at least `minTrust` (default
90
+ * 0.1), oldest first within each chat, at most `max` messages (default 100),
91
+ * read as it's returned. Call again while `more` is true. A reader that never
92
+ * opened a chat starts with its newest 20.
93
+ */
94
+ export declare function catchUp(authorization: Credentials | ApiKey, options?: {
95
+ minTrust?: number;
96
+ max?: number;
97
+ }): Promise<CaughtUp>;
98
+ /**
99
+ * Messages holding every word of `query` across every chat you share with
100
+ * others, newest first. `cursor` skips that many matches from the newest; `max`
101
+ * is the page size (default 20).
102
+ */
103
+ export declare function search(authorization: Credentials | ApiKey, query: string, options?: {
104
+ cursor?: number;
105
+ max?: number;
106
+ }): Promise<Found[]>;
107
+ /**
108
+ * Post `text` in a chat, as you. Everyone in it sees it live, its webhooks fire
109
+ * and it counts toward memories, like any message. Signed in with an API key,
110
+ * the message records the key's name (`via`) and never moves trust. In a chat
111
+ * that isn't people only, it starts a model reply as any message does.
112
+ */
113
+ export declare function post(authorization: Credentials | ApiKey, chat: string, text: string): Promise<void>;
@@ -0,0 +1,100 @@
1
+ import { Fauna } from "../index.js";
2
+ import { Parrot } from "./parrot/index.js";
3
+ /**
4
+ * Every chat you share with others, newest first: your groups', your friends'
5
+ * and your groups' partnerships', each with its owner, your trust in it and what
6
+ * you haven't read.
7
+ */
8
+ export async function list(authorization) {
9
+ const response = await fetch(`${Fauna.getURL()}/chats/shared`, {
10
+ method: "GET",
11
+ headers: {
12
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
13
+ }
14
+ });
15
+ if (!response.ok)
16
+ throw new Error(await response.text());
17
+ return await response.json();
18
+ }
19
+ /**
20
+ * What you haven't read in chats you trust at least `minTrust` (default 0.1).
21
+ * Your own groups' chats always count.
22
+ */
23
+ export async function unread(authorization, options = {}) {
24
+ const query = options.minTrust !== undefined ? `?minTrust=${encodeURIComponent(String(options.minTrust))}` : '';
25
+ const response = await fetch(`${Fauna.getURL()}/chats/unread${query}`, {
26
+ method: "GET",
27
+ headers: {
28
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
29
+ }
30
+ });
31
+ if (!response.ok)
32
+ throw new Error(await response.text());
33
+ return await response.json();
34
+ }
35
+ /**
36
+ * Everything you haven't read in chats you trust at least `minTrust` (default
37
+ * 0.1), oldest first within each chat, at most `max` messages (default 100),
38
+ * read as it's returned. Call again while `more` is true. A reader that never
39
+ * opened a chat starts with its newest 20.
40
+ */
41
+ export async function catchUp(authorization, options = {}) {
42
+ const response = await fetch(`${Fauna.getURL()}/chats/catch-up`, {
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({ minTrust: options.minTrust, max: options.max })
49
+ });
50
+ if (!response.ok)
51
+ throw new Error(await response.text());
52
+ return await response.json();
53
+ }
54
+ /**
55
+ * Messages holding every word of `query` across every chat you share with
56
+ * others, newest first. `cursor` skips that many matches from the newest; `max`
57
+ * is the page size (default 20).
58
+ */
59
+ export async function search(authorization, query, options = {}) {
60
+ const response = await fetch(`${Fauna.getURL()}/chats/search`, {
61
+ method: "POST",
62
+ headers: {
63
+ "Content-Type": "application/json",
64
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
65
+ },
66
+ body: JSON.stringify({ query, cursor: options.cursor, max: options.max })
67
+ });
68
+ if (!response.ok)
69
+ throw new Error(await response.text());
70
+ return await response.json();
71
+ }
72
+ /**
73
+ * Post `text` in a chat, as you. Everyone in it sees it live, its webhooks fire
74
+ * and it counts toward memories, like any message. Signed in with an API key,
75
+ * the message records the key's name (`via`) and never moves trust. In a chat
76
+ * that isn't people only, it starts a model reply as any message does.
77
+ */
78
+ export async function post(authorization, chat, text) {
79
+ const opened = await fetch(`${Parrot.getURL()}/chat/live/open`, {
80
+ method: "POST",
81
+ headers: {
82
+ "Content-Type": "application/json",
83
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
84
+ },
85
+ body: JSON.stringify({ chatId: chat })
86
+ });
87
+ if (!opened.ok)
88
+ throw new Error(await opened.text());
89
+ const response = await fetch(`${Parrot.getURL()}/chat/live/append`, {
90
+ method: "POST",
91
+ headers: {
92
+ "Content-Type": "application/json",
93
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
94
+ "Server": `parrot:chat:${chat}`
95
+ },
96
+ body: JSON.stringify({ role: 'USER', parts: [{ type: 'TEXT', text }] })
97
+ });
98
+ if (!response.ok)
99
+ throw new Error(await response.text());
100
+ }
@@ -0,0 +1,31 @@
1
+ import { Platform } from "../integrations.js";
2
+ import { Profile, Credentials, ApiKey } from "../authentification.js";
3
+ export type Discord = {
4
+ displayName: string;
5
+ handle: string;
6
+ userId?: string;
7
+ };
8
+ export type Slack = {
9
+ displayName: string;
10
+ email: string;
11
+ headline: string;
12
+ };
13
+ export type Email = {
14
+ email: string;
15
+ };
16
+ export type SMS = {
17
+ phone: string;
18
+ };
19
+ export type Identity = Discord | Slack | Email | SMS;
20
+ export type Contact = {
21
+ profile: Profile;
22
+ registered: boolean;
23
+ platforms: Identity[];
24
+ };
25
+ export declare function list(authorization: Credentials | ApiKey): Promise<Contact[]>;
26
+ export declare function create(authorization: Credentials | ApiKey, params: {
27
+ email: string;
28
+ displayName?: string;
29
+ platform: Platform;
30
+ identity?: string;
31
+ }): Promise<Contact>;
@@ -0,0 +1,28 @@
1
+ import { Cicada } from "./index.js";
2
+ export async function list(authorization) {
3
+ const response = await fetch(`${Cicada.getURL()}/cicada/contacts`, {
4
+ method: "POST",
5
+ headers: {
6
+ "Content-Type": "application/json",
7
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
8
+ }
9
+ });
10
+ if (!response.ok)
11
+ throw new Error(await response.text());
12
+ return await response.json();
13
+ }
14
+ // Promote an anonymous sender into a contact. Email is mandatory; passing the
15
+ // platform + raw identity (phone / handle / email) binds existing messages to it.
16
+ export async function create(authorization, params) {
17
+ const response = await fetch(`${Cicada.getURL()}/cicada/contacts/create`, {
18
+ method: "POST",
19
+ headers: {
20
+ "Content-Type": "application/json",
21
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
22
+ },
23
+ body: JSON.stringify(params)
24
+ });
25
+ if (!response.ok)
26
+ throw new Error(await response.text());
27
+ return await response.json();
28
+ }
@@ -0,0 +1,73 @@
1
+ import { Contact } from "./contacts.js";
2
+ import { Platform } from "../integrations.js";
3
+ import { Credentials, ApiKey } from "../authentification.js";
4
+ import { File as FaunaFile } from "../drive.js";
5
+ export type Conversation = {
6
+ id: string;
7
+ inboxId?: string;
8
+ participants: (Contact | string)[];
9
+ activeAt: Date;
10
+ unread: number;
11
+ };
12
+ export type Reminder = {
13
+ conversation: Conversation;
14
+ remindAt: Date;
15
+ };
16
+ export type ScheduledSend = {
17
+ id: string;
18
+ sendAt: Date;
19
+ createdAt: Date;
20
+ message: string;
21
+ context: {
22
+ conversation: string;
23
+ platform?: Platform;
24
+ } | {
25
+ recipients: (Contact | string)[];
26
+ mode: 'broadcast' | 'group';
27
+ platform: Platform;
28
+ };
29
+ };
30
+ export type Message = {
31
+ id: string;
32
+ author: Contact | string;
33
+ platform: Platform;
34
+ createdAt: Date;
35
+ message: string;
36
+ raw?: string;
37
+ attachments: FaunaFile[];
38
+ /** Sent by the inbox agent. */
39
+ agent: boolean;
40
+ };
41
+ export declare function listInbox(authorization: Credentials | ApiKey, inboxId?: string): Promise<Conversation[]>;
42
+ export declare function listArchived(authorization: Credentials | ApiKey, inboxId?: string): Promise<Conversation[]>;
43
+ export declare function listReminders(authorization: Credentials | ApiKey, inboxId?: string): Promise<Reminder[]>;
44
+ export declare function get(authorization: Credentials | ApiKey, conversation: string): Promise<Conversation | null>;
45
+ export declare function read(authorization: Credentials | ApiKey, conversation: string): Promise<Message[]>;
46
+ export declare function autocomplete(authorization: Credentials | ApiKey, conversation: string, text: string): Promise<string>;
47
+ export declare function markRead(authorization: Credentials | ApiKey, conversation: string): Promise<void>;
48
+ export declare function remove(authorization: Credentials | ApiKey, conversation: string): Promise<void>;
49
+ export declare function compose(authorization: Credentials | ApiKey, options: {
50
+ recipients: string[];
51
+ platform: Platform;
52
+ text: string;
53
+ mode: 'broadcast' | 'group';
54
+ inboxId?: string;
55
+ accountId?: string;
56
+ }): Promise<string[]>;
57
+ export declare function send(authorization: Credentials | ApiKey, conversation: string, text: string, platform?: Platform): Promise<string>;
58
+ export declare function archive(authorization: Credentials | ApiKey, conversation: string, archived: boolean): Promise<void>;
59
+ export declare function remind(authorization: Credentials | ApiKey, conversation: string, at: Date | null): Promise<void>;
60
+ export declare function schedule(authorization: Credentials | ApiKey, options: {
61
+ sendAt: Date;
62
+ text: string;
63
+ platform?: Platform;
64
+ conversationId?: string;
65
+ compose?: {
66
+ recipients: string[];
67
+ mode: 'broadcast' | 'group';
68
+ };
69
+ inboxId?: string;
70
+ accountId?: string;
71
+ }): Promise<string>;
72
+ export declare function listScheduled(authorization: Credentials | ApiKey, inboxId?: string): Promise<ScheduledSend[]>;
73
+ export declare function cancelScheduled(authorization: Credentials | ApiKey, scheduled: string): Promise<void>;