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.
- package/dist/brands.d.ts +2 -0
- package/dist/brands.js +2 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +121 -0
- package/dist/src/ant/chat.d.ts +130 -0
- package/dist/src/ant/chat.js +467 -0
- package/dist/src/ant/format.d.ts +40 -0
- package/dist/src/ant/format.js +143 -0
- package/dist/src/ant/graph.d.ts +130 -0
- package/dist/src/ant/graph.js +449 -0
- package/dist/src/ant/index.d.ts +16 -0
- package/dist/src/ant/index.js +61 -0
- package/dist/src/ant/persona.d.ts +151 -0
- package/dist/src/ant/persona.js +136 -0
- package/dist/src/ant/timeline.d.ts +283 -0
- package/dist/src/ant/timeline.js +1025 -0
- package/dist/src/authentification.d.ts +45 -0
- package/dist/src/authentification.js +194 -0
- package/dist/src/billing.d.ts +135 -0
- package/dist/src/billing.js +128 -0
- package/dist/src/calendar.d.ts +83 -0
- package/dist/src/calendar.js +133 -0
- package/dist/src/chats.d.ts +113 -0
- package/dist/src/chats.js +100 -0
- package/dist/src/cicada/contacts.d.ts +31 -0
- package/dist/src/cicada/contacts.js +28 -0
- package/dist/src/cicada/conversations.d.ts +73 -0
- package/dist/src/cicada/conversations.js +236 -0
- package/dist/src/cicada/inboxes.d.ts +48 -0
- package/dist/src/cicada/inboxes.js +82 -0
- package/dist/src/cicada/index.d.ts +16 -0
- package/dist/src/cicada/index.js +61 -0
- package/dist/src/cicada/phone.d.ts +48 -0
- package/dist/src/cicada/phone.js +306 -0
- package/dist/src/drive.d.ts +80 -0
- package/dist/src/drive.js +472 -0
- package/dist/src/extensions/index.d.ts +4 -0
- package/dist/src/extensions/index.js +5 -0
- package/dist/src/extensions/web/index.d.ts +6 -0
- package/dist/src/extensions/web/index.js +7 -0
- package/dist/src/extensions/web/session.d.ts +108 -0
- package/dist/src/extensions/web/session.js +470 -0
- package/dist/src/extensions/web/tools.d.ts +13 -0
- package/dist/src/extensions/web/tools.js +72 -0
- package/dist/src/friends.d.ts +39 -0
- package/dist/src/friends.js +119 -0
- package/dist/src/groups.d.ts +82 -0
- package/dist/src/groups.js +269 -0
- package/dist/src/inbox.d.ts +11 -0
- package/dist/src/inbox.js +35 -0
- package/dist/src/integrations.d.ts +52 -0
- package/dist/src/integrations.js +205 -0
- package/dist/src/magpie/explorer.d.ts +14 -0
- package/dist/src/magpie/explorer.js +36 -0
- package/dist/src/magpie/index.d.ts +16 -0
- package/dist/src/magpie/index.js +61 -0
- package/dist/src/magpie/portfolio.d.ts +52 -0
- package/dist/src/magpie/portfolio.js +179 -0
- package/dist/src/magpie/quotes.d.ts +35 -0
- package/dist/src/magpie/quotes.js +47 -0
- package/dist/src/magpie/room.d.ts +61 -0
- package/dist/src/magpie/room.js +238 -0
- package/dist/src/maps.d.ts +159 -0
- package/dist/src/maps.js +171 -0
- package/dist/src/marmot/browser.d.ts +139 -0
- package/dist/src/marmot/browser.js +389 -0
- package/dist/src/marmot/index.d.ts +20 -0
- package/dist/src/marmot/index.js +65 -0
- package/dist/src/marmot/media.d.ts +56 -0
- package/dist/src/marmot/media.js +265 -0
- package/dist/src/marmot/research.d.ts +337 -0
- package/dist/src/marmot/research.js +1138 -0
- package/dist/src/marmot/scraper.d.ts +59 -0
- package/dist/src/marmot/scraper.js +94 -0
- package/dist/src/marmot/web.d.ts +402 -0
- package/dist/src/marmot/web.js +2586 -0
- package/dist/src/marmot/workspace.d.ts +81 -0
- package/dist/src/marmot/workspace.js +263 -0
- package/dist/src/parrot/agent.d.ts +53 -0
- package/dist/src/parrot/agent.js +93 -0
- package/dist/src/parrot/chat.d.ts +84 -0
- package/dist/src/parrot/chat.js +237 -0
- package/dist/src/parrot/format.d.ts +128 -0
- package/dist/src/parrot/format.js +639 -0
- package/dist/src/parrot/generative.d.ts +261 -0
- package/dist/src/parrot/generative.js +185 -0
- package/dist/src/parrot/index.d.ts +22 -0
- package/dist/src/parrot/index.js +67 -0
- package/dist/src/parrot/room.d.ts +225 -0
- package/dist/src/parrot/room.js +466 -0
- package/dist/src/parrot/routing.d.ts +90 -0
- package/dist/src/parrot/routing.js +78 -0
- package/dist/src/parrot/share.d.ts +126 -0
- package/dist/src/parrot/share.js +261 -0
- package/dist/src/parrot/socket.d.ts +41 -0
- package/dist/src/parrot/socket.js +478 -0
- package/dist/src/payments.d.ts +73 -0
- package/dist/src/payments.js +107 -0
- package/dist/src/private/cards.css +75 -0
- package/dist/src/rooms.d.ts +76 -0
- package/dist/src/rooms.js +168 -0
- package/dist/src/shared/schema.d.ts +24 -0
- package/dist/src/shared/schema.js +1 -0
- package/dist/src/shared/server.d.ts +65 -0
- package/dist/src/shared/server.js +302 -0
- package/dist/src/termite/environment.d.ts +110 -0
- package/dist/src/termite/environment.js +263 -0
- package/dist/src/termite/index.d.ts +14 -0
- package/dist/src/termite/index.js +59 -0
- package/dist/src/termite/os.d.ts +326 -0
- package/dist/src/termite/os.js +572 -0
- package/dist/src/termite/versioning.d.ts +94 -0
- package/dist/src/termite/versioning.js +217 -0
- package/dist/src/tickets.d.ts +43 -0
- package/dist/src/tickets.js +138 -0
- package/dist/src/travel.d.ts +85 -0
- package/dist/src/travel.js +44 -0
- package/dist/src/ui/authentification.d.ts +24 -0
- package/dist/src/ui/authentification.js +177 -0
- package/dist/src/ui/brands.css +11 -0
- package/dist/src/ui/brands.d.ts +7 -0
- package/dist/src/ui/brands.js +14 -0
- package/dist/src/ui/browser.d.ts +74 -0
- package/dist/src/ui/browser.js +470 -0
- package/dist/src/ui/chat.d.ts +183 -0
- package/dist/src/ui/chat.js +2379 -0
- package/dist/src/ui/chatPanel.d.ts +109 -0
- package/dist/src/ui/chatPanel.js +768 -0
- package/dist/src/ui/chatSequence.d.ts +36 -0
- package/dist/src/ui/chatSequence.js +42 -0
- package/dist/src/ui/crown.d.ts +19 -0
- package/dist/src/ui/crown.js +199 -0
- package/dist/src/ui/cursor.d.ts +73 -0
- package/dist/src/ui/cursor.js +175 -0
- package/dist/src/ui/device.d.ts +33 -0
- package/dist/src/ui/device.js +49 -0
- package/dist/src/ui/drive.d.ts +69 -0
- package/dist/src/ui/drive.js +1243 -0
- package/dist/src/ui/generative.d.ts +39 -0
- package/dist/src/ui/generative.js +313 -0
- package/dist/src/ui/hover.d.ts +6 -0
- package/dist/src/ui/hover.js +210 -0
- package/dist/src/ui/index.d.ts +42 -0
- package/dist/src/ui/index.js +87 -0
- package/dist/src/ui/integrations.d.ts +13 -0
- package/dist/src/ui/integrations.js +175 -0
- package/dist/src/ui/maps.d.ts +87 -0
- package/dist/src/ui/maps.js +547 -0
- package/dist/src/ui/roster.d.ts +32 -0
- package/dist/src/ui/roster.js +163 -0
- package/dist/src/ui/talk.d.ts +12 -0
- package/dist/src/ui/talk.js +560 -0
- package/dist/src/ui/tickets.d.ts +13 -0
- package/dist/src/ui/tickets.js +966 -0
- package/dist/src/ui/toast.d.ts +7 -0
- package/dist/src/ui/toast.js +258 -0
- package/dist/src/ui/tokenText.d.ts +18 -0
- package/dist/src/ui/tokenText.js +96 -0
- package/dist/src/ui/tokenized.d.ts +42 -0
- package/dist/src/ui/tokenized.js +622 -0
- package/dist/src/ui/ui.css +4763 -0
- package/dist/src/ui/view.d.ts +23 -0
- package/dist/src/ui/view.js +584 -0
- package/dist/src/view.d.ts +113 -0
- package/dist/src/view.js +386 -0
- package/dist/src/webhooks.d.ts +66 -0
- package/dist/src/webhooks.js +78 -0
- package/dist/ui.d.ts +1 -0
- package/dist/ui.js +1 -0
- package/package.json +87 -4
- package/README.md +0 -3
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Decision, Embedding, Image, Speech, Text, Transcription, Video, Voice } from "./generative.js";
|
|
2
|
+
import { Credentials, ApiKey } from "../authentification.js";
|
|
3
|
+
export type Garden = {
|
|
4
|
+
providers: Record<string, {
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
systemPrompt?: string;
|
|
7
|
+
temperature?: number;
|
|
8
|
+
}>;
|
|
9
|
+
memories: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function getPrice(model: Text | Embedding | Image | Video | Speech | Transcription | Voice | Decision): Promise<{
|
|
12
|
+
inputPer1M?: number;
|
|
13
|
+
outputPer1M?: number;
|
|
14
|
+
perUnit?: number;
|
|
15
|
+
unit?: string;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function getDimensions(model: Embedding): Promise<number>;
|
|
18
|
+
export type CatalogModel = {
|
|
19
|
+
model: string;
|
|
20
|
+
name: string;
|
|
21
|
+
provider: string;
|
|
22
|
+
baseURL: string;
|
|
23
|
+
icon: string;
|
|
24
|
+
inputPer1M?: number;
|
|
25
|
+
outputPer1M?: number;
|
|
26
|
+
cachedInputPer1M?: number;
|
|
27
|
+
perUnit?: number;
|
|
28
|
+
unit?: string;
|
|
29
|
+
kind?: string;
|
|
30
|
+
dimensions?: number;
|
|
31
|
+
reasoning?: string[];
|
|
32
|
+
/** Decision models: image input and the limits the model accepts. */
|
|
33
|
+
images?: boolean;
|
|
34
|
+
maxQuestions?: number;
|
|
35
|
+
maxOptions?: number;
|
|
36
|
+
inputContextWindow?: number;
|
|
37
|
+
};
|
|
38
|
+
export declare function getAll(): Promise<{
|
|
39
|
+
text: CatalogModel[];
|
|
40
|
+
embedding: CatalogModel[];
|
|
41
|
+
image: CatalogModel[];
|
|
42
|
+
video: CatalogModel[];
|
|
43
|
+
speech: CatalogModel[];
|
|
44
|
+
transcription: CatalogModel[];
|
|
45
|
+
voice: CatalogModel[];
|
|
46
|
+
decision: CatalogModel[];
|
|
47
|
+
}>;
|
|
48
|
+
export declare function getLastUsedModels(authorization: Credentials | ApiKey): Promise<{
|
|
49
|
+
text?: {
|
|
50
|
+
model: Text;
|
|
51
|
+
reasoning?: string;
|
|
52
|
+
};
|
|
53
|
+
embedding?: Embedding;
|
|
54
|
+
image?: Image;
|
|
55
|
+
video?: Video;
|
|
56
|
+
speech?: Speech;
|
|
57
|
+
transcription?: Transcription;
|
|
58
|
+
}>;
|
|
59
|
+
export declare function getUsage(authorization: Credentials | ApiKey): Promise<{
|
|
60
|
+
text: [string, string, {
|
|
61
|
+
input: number;
|
|
62
|
+
output: number;
|
|
63
|
+
}][];
|
|
64
|
+
embedding: [string, string, {
|
|
65
|
+
cost: number;
|
|
66
|
+
}][];
|
|
67
|
+
image: [string, string, {
|
|
68
|
+
cost: number;
|
|
69
|
+
}][];
|
|
70
|
+
video: [string, string, {
|
|
71
|
+
cost: number;
|
|
72
|
+
}][];
|
|
73
|
+
speech: [string, string, {
|
|
74
|
+
cost: number;
|
|
75
|
+
}][];
|
|
76
|
+
transcription: [string, string, {
|
|
77
|
+
cost: number;
|
|
78
|
+
}][];
|
|
79
|
+
voice: [string, string, {
|
|
80
|
+
cost: number;
|
|
81
|
+
}][];
|
|
82
|
+
decision: [string, string, {
|
|
83
|
+
cost: number;
|
|
84
|
+
}][];
|
|
85
|
+
}>;
|
|
86
|
+
export declare function getGarden(authorization: Credentials | ApiKey): Promise<Garden>;
|
|
87
|
+
export declare function setGarden(authorization: Credentials | ApiKey, update: Partial<Garden> & {
|
|
88
|
+
provider?: string;
|
|
89
|
+
providerConfig?: Garden['providers'][string];
|
|
90
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Parrot } from "./index.js";
|
|
2
|
+
export async function getPrice(model) {
|
|
3
|
+
const response = await fetch(`${Parrot.getURL()}/routing/price/${encodeURIComponent(model)}`, {
|
|
4
|
+
method: "GET"
|
|
5
|
+
});
|
|
6
|
+
if (!response.ok) {
|
|
7
|
+
throw new Error(await response.text());
|
|
8
|
+
}
|
|
9
|
+
return await response.json();
|
|
10
|
+
}
|
|
11
|
+
export async function getDimensions(model) {
|
|
12
|
+
const response = await fetch(`${Parrot.getURL()}/routing/dimensions/${encodeURIComponent(model)}`, {
|
|
13
|
+
method: "GET"
|
|
14
|
+
});
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
throw new Error(await response.text());
|
|
17
|
+
}
|
|
18
|
+
return Number(await response.text());
|
|
19
|
+
}
|
|
20
|
+
export async function getAll() {
|
|
21
|
+
const response = await fetch(`${Parrot.getURL()}/routing/all`, {
|
|
22
|
+
method: "GET",
|
|
23
|
+
headers: { "Content-Type": "application/json" }
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
throw new Error(await response.text());
|
|
27
|
+
}
|
|
28
|
+
return await response.json();
|
|
29
|
+
}
|
|
30
|
+
export async function getLastUsedModels(authorization) {
|
|
31
|
+
const response = await fetch(`${Parrot.getURL()}/routing/last`, {
|
|
32
|
+
method: "GET",
|
|
33
|
+
headers: {
|
|
34
|
+
"Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new Error(await response.text());
|
|
39
|
+
}
|
|
40
|
+
return await response.json();
|
|
41
|
+
}
|
|
42
|
+
export async function getUsage(authorization) {
|
|
43
|
+
const response = await fetch(`${Parrot.getURL()}/routing/usage`, {
|
|
44
|
+
method: "GET",
|
|
45
|
+
headers: {
|
|
46
|
+
"Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
throw new Error(await response.text());
|
|
51
|
+
}
|
|
52
|
+
return await response.json();
|
|
53
|
+
}
|
|
54
|
+
export async function getGarden(authorization) {
|
|
55
|
+
const response = await fetch(`${Parrot.getURL()}/routing/garden`, {
|
|
56
|
+
method: "GET",
|
|
57
|
+
headers: {
|
|
58
|
+
"Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
throw new Error(await response.text());
|
|
63
|
+
}
|
|
64
|
+
return await response.json();
|
|
65
|
+
}
|
|
66
|
+
export async function setGarden(authorization, update) {
|
|
67
|
+
const response = await fetch(`${Parrot.getURL()}/routing/garden`, {
|
|
68
|
+
method: "PUT",
|
|
69
|
+
headers: {
|
|
70
|
+
"Content-Type": "application/json",
|
|
71
|
+
"Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify(update)
|
|
74
|
+
});
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
throw new Error(await response.text());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Parrot } from "./index.js";
|
|
2
|
+
import { Credentials, ApiKey, Profile } from "../authentification.js";
|
|
3
|
+
import { Content, Function, Role } from "./generative.js";
|
|
4
|
+
import * as Drive from "../drive.js";
|
|
5
|
+
/**
|
|
6
|
+
* Address a live room by a redeemable access code or by its globally-unique
|
|
7
|
+
* reference (`parrot:chat:{chatId}` for a durable-bound room, `parrot:room:{uuid}`
|
|
8
|
+
* for an unbound ephemeral one).
|
|
9
|
+
*/
|
|
10
|
+
export type ChatTarget = {
|
|
11
|
+
code: string;
|
|
12
|
+
} | {
|
|
13
|
+
reference: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function moveChatToGroup(credentials: Credentials, chatId: string, groupId: string): Promise<{
|
|
16
|
+
chatId: string;
|
|
17
|
+
groupId: string;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Host a live room server-side. Pass `chatId` to bind the room to a durable
|
|
21
|
+
* chat (reference becomes `parrot:chat:{chatId}`, billed to the chat's
|
|
22
|
+
* balance-holder) and seed the newest window from durable; omit it for an
|
|
23
|
+
* unbound ephemeral room. `messages` seeds only ephemeral rooms. `share: true`
|
|
24
|
+
* also mints an access code. Returns the room's `reference` (+ `code` when shared).
|
|
25
|
+
*/
|
|
26
|
+
export declare function openRoom(authorization: Credentials | ApiKey, options?: {
|
|
27
|
+
chatId?: string;
|
|
28
|
+
messages?: Content[];
|
|
29
|
+
share?: boolean;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
reference: string;
|
|
32
|
+
roomId: string;
|
|
33
|
+
code?: string;
|
|
34
|
+
}>;
|
|
35
|
+
/** One transcript message on the wire (parts keep file refs as streaming
|
|
36
|
+
* `FaunaFile`s). Matches the room's live `chat-message` shape. */
|
|
37
|
+
export type WireMessage = {
|
|
38
|
+
id: string;
|
|
39
|
+
position: number;
|
|
40
|
+
role: Role;
|
|
41
|
+
parts: any[];
|
|
42
|
+
author?: Profile;
|
|
43
|
+
replyTo?: string;
|
|
44
|
+
model?: string;
|
|
45
|
+
created: number;
|
|
46
|
+
/** The name of the API key an agent posted this with, for its author. */
|
|
47
|
+
via?: string;
|
|
48
|
+
};
|
|
49
|
+
export declare const WireMessage: {
|
|
50
|
+
/** FILE parts arrive as `{ accessCode | path | ref }` and stream lazily through `FaunaFile`. */
|
|
51
|
+
fromJSON(json: any, authorization: Credentials | ApiKey, target: ChatTarget): WireMessage;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Page older room transcript messages, newest first. `cursor` is how many
|
|
55
|
+
* messages to skip from the newest.
|
|
56
|
+
*/
|
|
57
|
+
export declare function pageMessages(authorization: Credentials | ApiKey, target: ChatTarget, query: {
|
|
58
|
+
cursor: number;
|
|
59
|
+
max: number;
|
|
60
|
+
}): Promise<WireMessage[]>;
|
|
61
|
+
/** Result of appending to a live room: either the durable transcript row (when
|
|
62
|
+
* the room was idle) or a queued buffer row (when the model was mid-reply). */
|
|
63
|
+
export type AppendResult = {
|
|
64
|
+
queued: false;
|
|
65
|
+
id?: string;
|
|
66
|
+
} | {
|
|
67
|
+
queued: true;
|
|
68
|
+
queueId?: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Append one message to a live room's single transcript. Any member may append;
|
|
72
|
+
* USER messages are attributed to the caller and nudge the server's debounced
|
|
73
|
+
* model reply. If the room is currently replying the server BUFFERS the send
|
|
74
|
+
* into the shared queue (`{ queued: true, queueId }`); it drains FIFO when the
|
|
75
|
+
* reply finishes. Otherwise it lands in the transcript (`{ queued: false, id }`).
|
|
76
|
+
* File parts are already-online Drive refs (path / accessCode); the body is JSON.
|
|
77
|
+
*/
|
|
78
|
+
export declare function appendRoomMessage(authorization: Credentials | ApiKey, target: ChatTarget, message: import("./generative.js").Content, options?: {
|
|
79
|
+
replyTo?: string;
|
|
80
|
+
model?: string;
|
|
81
|
+
reasoning?: string;
|
|
82
|
+
/** Function schemas (array = available; singular = force that tool). */
|
|
83
|
+
tools?: Function | Function[];
|
|
84
|
+
}): Promise<AppendResult>;
|
|
85
|
+
/** A file in a chat: one a person attached, or one Parrot opened. */
|
|
86
|
+
export type Attachment = {
|
|
87
|
+
file: Drive.File;
|
|
88
|
+
/** The chat it's in and its name in the chat folder, so a file room can let chat members edit it. */
|
|
89
|
+
chat: string;
|
|
90
|
+
ref: string;
|
|
91
|
+
/** Position of the message it came in; unset while the reply attaching it is still being written. */
|
|
92
|
+
message?: number;
|
|
93
|
+
author?: Profile;
|
|
94
|
+
createdAt: Date;
|
|
95
|
+
};
|
|
96
|
+
export declare const Attachment: {
|
|
97
|
+
fromJSON(json: any, authorization: Credentials | ApiKey): Attachment;
|
|
98
|
+
};
|
|
99
|
+
/** Every file in the chat behind a live room, newest first. */
|
|
100
|
+
export declare function listRoomAttachments(authorization: Credentials | ApiKey, target: ChatTarget): Promise<Attachment[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Attach a repository to the chat behind a live room, or detach it with null.
|
|
103
|
+
* The repository must be the chat owner's; only the chat's members may change it.
|
|
104
|
+
*/
|
|
105
|
+
export declare function setRoomRepository(authorization: Credentials | ApiKey, target: ChatTarget, repository: number | null): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Remove a queued (buffered) message from a live room. The message was buffered
|
|
108
|
+
* while the model was mid-reply and never entered the transcript, so this is not
|
|
109
|
+
* an unsend — the server just drops the queue row and fans it out to every member.
|
|
110
|
+
*/
|
|
111
|
+
export declare function unqueueRoomMessage(authorization: Credentials | ApiKey, target: ChatTarget, queueId: string): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Steer a live room: stop the in-progress model reply and have the server
|
|
114
|
+
* re-answer after the normal debounce window. Any member may steer. `queueId`
|
|
115
|
+
* releases just that one queued row into the transcript first (per-item steer);
|
|
116
|
+
* `all` flushes the whole queue in FIFO order (steer-all). Released rows behave
|
|
117
|
+
* like idle sends — the model does NOT reply immediately.
|
|
118
|
+
* `stop` cancels the current reply without scheduling a new one.
|
|
119
|
+
*/
|
|
120
|
+
export declare function steerRoom(authorization: Credentials | ApiKey, target: ChatTarget, options?: {
|
|
121
|
+
queueId?: string;
|
|
122
|
+
all?: boolean;
|
|
123
|
+
stop?: boolean;
|
|
124
|
+
model?: string;
|
|
125
|
+
reasoning?: string;
|
|
126
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { Parrot } from "./index.js";
|
|
2
|
+
import * as Drive from "../drive.js";
|
|
3
|
+
export async function moveChatToGroup(credentials, chatId, groupId) {
|
|
4
|
+
const response = await fetch(`${Parrot.getURL()}/chat/move`, {
|
|
5
|
+
method: "POST",
|
|
6
|
+
headers: {
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
"Authorization": `Token ${credentials.token}`
|
|
9
|
+
},
|
|
10
|
+
body: JSON.stringify({ chatId, groupId })
|
|
11
|
+
});
|
|
12
|
+
if (!response.ok)
|
|
13
|
+
throw new Error(await response.text());
|
|
14
|
+
return await response.json();
|
|
15
|
+
}
|
|
16
|
+
// ─── Ephemeral live rooms (host / seed / page / append / steer) ───────────────
|
|
17
|
+
/**
|
|
18
|
+
* Host a live room server-side. Pass `chatId` to bind the room to a durable
|
|
19
|
+
* chat (reference becomes `parrot:chat:{chatId}`, billed to the chat's
|
|
20
|
+
* balance-holder) and seed the newest window from durable; omit it for an
|
|
21
|
+
* unbound ephemeral room. `messages` seeds only ephemeral rooms. `share: true`
|
|
22
|
+
* also mints an access code. Returns the room's `reference` (+ `code` when shared).
|
|
23
|
+
*/
|
|
24
|
+
export async function openRoom(authorization, options = {}) {
|
|
25
|
+
const messages = options.messages ? await serializeTranscript(options.messages) : undefined;
|
|
26
|
+
const response = await fetch(`${Parrot.getURL()}/chat/live/open`, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
"Authorization": "email" in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify({ chatId: options.chatId, messages, share: options.share }),
|
|
33
|
+
});
|
|
34
|
+
if (!response.ok)
|
|
35
|
+
throw new Error(await response.text());
|
|
36
|
+
return await response.json();
|
|
37
|
+
}
|
|
38
|
+
export const WireMessage = {
|
|
39
|
+
/** FILE parts arrive as `{ accessCode | path | ref }` and stream lazily through `FaunaFile`. */
|
|
40
|
+
fromJSON(json, authorization, target) {
|
|
41
|
+
const parts = (json.parts ?? []).map((part) => {
|
|
42
|
+
if (part.type !== "FILE")
|
|
43
|
+
return part;
|
|
44
|
+
const meta = { ...part, name: part.name ?? "file", contentType: part.contentType ?? "application/octet-stream" };
|
|
45
|
+
if (part.accessCode)
|
|
46
|
+
return { type: "FILE", file: Drive.File.fromJSON(meta, { authorization, accessCode: part.accessCode }) };
|
|
47
|
+
if (part.path)
|
|
48
|
+
return { type: "FILE", file: Drive.File.fromJSON(meta, { authorization, path: part.path, group: part.group }) };
|
|
49
|
+
if ("code" in target)
|
|
50
|
+
return { type: "FILE", file: Drive.File.fromJSON(meta, { authorization, accessCode: target.code }) };
|
|
51
|
+
if (part.ref)
|
|
52
|
+
return { type: "FILE", file: Drive.File.fromJSON(meta, { authorization, path: part.ref }) };
|
|
53
|
+
return { type: "FILE", file: Drive.File.fromJSON(meta, { authorization, accessCode: "" }) };
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
id: String(json.id ?? ""),
|
|
57
|
+
position: Number(json.position ?? 0),
|
|
58
|
+
role: json.role,
|
|
59
|
+
parts,
|
|
60
|
+
author: json.author,
|
|
61
|
+
replyTo: json.replyTo,
|
|
62
|
+
model: json.model,
|
|
63
|
+
created: Number(json.created ?? 0),
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Page older room transcript messages, newest first. `cursor` is how many
|
|
69
|
+
* messages to skip from the newest.
|
|
70
|
+
*/
|
|
71
|
+
export async function pageMessages(authorization, target, query) {
|
|
72
|
+
const params = new URLSearchParams({ cursor: String(query.cursor), max: String(query.max) });
|
|
73
|
+
const response = await fetch(`${Parrot.getURL()}/chat/live/messages?${params}`, {
|
|
74
|
+
method: "GET",
|
|
75
|
+
headers: {
|
|
76
|
+
"Authorization": "email" in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
77
|
+
...("code" in target ? { "Access-Code": target.code } : { "Server": target.reference }),
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
if (!response.ok)
|
|
81
|
+
throw new Error(await response.text());
|
|
82
|
+
const json = await response.json();
|
|
83
|
+
return (Array.isArray(json) ? json : []).map((m) => WireMessage.fromJSON(m, authorization, target));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Append one message to a live room's single transcript. Any member may append;
|
|
87
|
+
* USER messages are attributed to the caller and nudge the server's debounced
|
|
88
|
+
* model reply. If the room is currently replying the server BUFFERS the send
|
|
89
|
+
* into the shared queue (`{ queued: true, queueId }`); it drains FIFO when the
|
|
90
|
+
* reply finishes. Otherwise it lands in the transcript (`{ queued: false, id }`).
|
|
91
|
+
* File parts are already-online Drive refs (path / accessCode); the body is JSON.
|
|
92
|
+
*/
|
|
93
|
+
export async function appendRoomMessage(authorization, target, message, options = {}) {
|
|
94
|
+
const serializedParts = [];
|
|
95
|
+
for (const part of message.parts) {
|
|
96
|
+
if (part.type === "FILE") {
|
|
97
|
+
serializedParts.push(fileRef(part.file));
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
serializedParts.push(part);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const response = await fetch(`${Parrot.getURL()}/chat/live/append`, {
|
|
104
|
+
method: "POST",
|
|
105
|
+
headers: {
|
|
106
|
+
"Content-Type": "application/json",
|
|
107
|
+
"Authorization": "email" in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
108
|
+
...("code" in target ? { "Access-Code": target.code } : { "Server": target.reference }),
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify({
|
|
111
|
+
role: message.role,
|
|
112
|
+
parts: serializedParts,
|
|
113
|
+
replyTo: options.replyTo,
|
|
114
|
+
model: options.model,
|
|
115
|
+
reasoning: options.reasoning,
|
|
116
|
+
...(options.tools !== undefined ? { tools: options.tools } : {}),
|
|
117
|
+
}),
|
|
118
|
+
});
|
|
119
|
+
if (!response.ok)
|
|
120
|
+
throw new Error(await response.text());
|
|
121
|
+
const json = await response.json().catch(() => ({}));
|
|
122
|
+
return json;
|
|
123
|
+
}
|
|
124
|
+
export const Attachment = {
|
|
125
|
+
fromJSON(json, authorization) {
|
|
126
|
+
const meta = {
|
|
127
|
+
name: json.name ?? json.ref ?? "file",
|
|
128
|
+
contentType: json.contentType ?? "application/octet-stream",
|
|
129
|
+
contentLength: Number(json.contentLength ?? 0),
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
file: Drive.File.fromJSON(meta, { authorization, accessCode: String(json.accessCode ?? "") }),
|
|
133
|
+
chat: String(json.chat ?? ""),
|
|
134
|
+
ref: String(json.ref ?? ""),
|
|
135
|
+
...(typeof json.message === "number" ? { message: json.message } : {}),
|
|
136
|
+
...(json.author ? { author: json.author } : {}),
|
|
137
|
+
createdAt: new Date(json.created ?? Date.now()),
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
/** Every file in the chat behind a live room, newest first. */
|
|
142
|
+
export async function listRoomAttachments(authorization, target) {
|
|
143
|
+
const response = await fetch(`${Parrot.getURL()}/chat/live/attachments`, {
|
|
144
|
+
method: "GET",
|
|
145
|
+
headers: {
|
|
146
|
+
"Authorization": "email" in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
147
|
+
...("code" in target ? { "Access-Code": target.code } : { "Server": target.reference }),
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
if (!response.ok)
|
|
151
|
+
throw new Error(await response.text());
|
|
152
|
+
const json = await response.json();
|
|
153
|
+
return (Array.isArray(json) ? json : []).map((row) => Attachment.fromJSON(row, authorization));
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Attach a repository to the chat behind a live room, or detach it with null.
|
|
157
|
+
* The repository must be the chat owner's; only the chat's members may change it.
|
|
158
|
+
*/
|
|
159
|
+
export async function setRoomRepository(authorization, target, repository) {
|
|
160
|
+
const response = await fetch(`${Parrot.getURL()}/chat/repository`, {
|
|
161
|
+
method: "POST",
|
|
162
|
+
headers: {
|
|
163
|
+
"Content-Type": "application/json",
|
|
164
|
+
"Authorization": "email" in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
165
|
+
...("code" in target ? { "Access-Code": target.code } : { "Server": target.reference }),
|
|
166
|
+
},
|
|
167
|
+
body: JSON.stringify({ repository }),
|
|
168
|
+
});
|
|
169
|
+
if (!response.ok)
|
|
170
|
+
throw new Error(await response.text());
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Remove a queued (buffered) message from a live room. The message was buffered
|
|
174
|
+
* while the model was mid-reply and never entered the transcript, so this is not
|
|
175
|
+
* an unsend — the server just drops the queue row and fans it out to every member.
|
|
176
|
+
*/
|
|
177
|
+
export async function unqueueRoomMessage(authorization, target, queueId) {
|
|
178
|
+
const response = await fetch(`${Parrot.getURL()}/chat/live/unqueue`, {
|
|
179
|
+
method: "POST",
|
|
180
|
+
headers: {
|
|
181
|
+
"Content-Type": "application/json",
|
|
182
|
+
"Authorization": "email" in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
183
|
+
...("code" in target ? { "Access-Code": target.code } : { "Server": target.reference }),
|
|
184
|
+
},
|
|
185
|
+
body: JSON.stringify({ queueId }),
|
|
186
|
+
});
|
|
187
|
+
if (!response.ok)
|
|
188
|
+
throw new Error(await response.text());
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Steer a live room: stop the in-progress model reply and have the server
|
|
192
|
+
* re-answer after the normal debounce window. Any member may steer. `queueId`
|
|
193
|
+
* releases just that one queued row into the transcript first (per-item steer);
|
|
194
|
+
* `all` flushes the whole queue in FIFO order (steer-all). Released rows behave
|
|
195
|
+
* like idle sends — the model does NOT reply immediately.
|
|
196
|
+
* `stop` cancels the current reply without scheduling a new one.
|
|
197
|
+
*/
|
|
198
|
+
export async function steerRoom(authorization, target, options = {}) {
|
|
199
|
+
const response = await fetch(`${Parrot.getURL()}/chat/live/steer`, {
|
|
200
|
+
method: "POST",
|
|
201
|
+
headers: {
|
|
202
|
+
"Content-Type": "application/json",
|
|
203
|
+
"Authorization": "email" in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
204
|
+
...("code" in target ? { "Access-Code": target.code } : { "Server": target.reference }),
|
|
205
|
+
},
|
|
206
|
+
body: JSON.stringify({
|
|
207
|
+
queueId: options.queueId,
|
|
208
|
+
all: options.all,
|
|
209
|
+
stop: options.stop,
|
|
210
|
+
model: options.model,
|
|
211
|
+
reasoning: options.reasoning,
|
|
212
|
+
}),
|
|
213
|
+
});
|
|
214
|
+
if (!response.ok)
|
|
215
|
+
throw new Error(await response.text());
|
|
216
|
+
}
|
|
217
|
+
// ─── serialization helpers (shared by open-seed + page hydration) ─────────────
|
|
218
|
+
function fileRef(file) {
|
|
219
|
+
const authorization = file.authorization;
|
|
220
|
+
if ("accessCode" in authorization) {
|
|
221
|
+
return { type: "FILE", name: file.name, contentType: file.contentType, accessCode: authorization.accessCode };
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
type: "FILE",
|
|
225
|
+
name: file.name,
|
|
226
|
+
contentType: file.contentType,
|
|
227
|
+
path: authorization.path,
|
|
228
|
+
...(authorization.group ? { group: authorization.group } : {}),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/** Serialize a transcript for the seed body: online FILE parts are path /
|
|
232
|
+
* accessCode refs only. Offline files are uploaded to tmp/ first. */
|
|
233
|
+
async function serializeTranscript(messages) {
|
|
234
|
+
const out = [];
|
|
235
|
+
for (const message of messages) {
|
|
236
|
+
const parts = [];
|
|
237
|
+
for (const part of message.parts) {
|
|
238
|
+
if (part.type === "FILE") {
|
|
239
|
+
let file = part.file;
|
|
240
|
+
if (!file.online) {
|
|
241
|
+
const dest = `tmp/${crypto.randomUUID()}-${file.name}`;
|
|
242
|
+
const bytes = await file.download();
|
|
243
|
+
file = Drive.fromBytes(file.authorization.authorization, dest, file.contentType, bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes));
|
|
244
|
+
await file.upload();
|
|
245
|
+
}
|
|
246
|
+
parts.push(fileRef(file));
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
parts.push(part);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
out.push({
|
|
253
|
+
role: message.role,
|
|
254
|
+
parts,
|
|
255
|
+
author: message.author,
|
|
256
|
+
replyTo: message.replyTo,
|
|
257
|
+
model: message.model,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
return out;
|
|
261
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Credentials, ApiKey } from "../authentification.js";
|
|
2
|
+
import type { Group } from "../groups.js";
|
|
3
|
+
import type { Demographic } from "../ant/persona.js";
|
|
4
|
+
import { type Content, type StreamEvent, type TextResponse, type Tool, type VoiceEvent } from "./generative.js";
|
|
5
|
+
/** A Parrot socket URL; `group` adds the Group header (shared memory, group billing). */
|
|
6
|
+
export declare function socketUrl(path: string, authorization: Credentials | ApiKey, group?: Group): string;
|
|
7
|
+
/** FILE parts become path or access code refs (uploading offline files first); no binaries go up. */
|
|
8
|
+
export declare function prepareMessages(authorization: Credentials | ApiKey, messages: Content[]): Promise<unknown[]>;
|
|
9
|
+
/** One generate frame in, one TextResponse (with any files) out. */
|
|
10
|
+
export declare function generateMedia(authorization: Credentials | ApiKey, path: string, model: string, options: {
|
|
11
|
+
content?: Content[];
|
|
12
|
+
group?: Group;
|
|
13
|
+
} & Record<string, unknown>, fallbackType: string): Promise<TextResponse>;
|
|
14
|
+
type TextOptions = Partial<{
|
|
15
|
+
content: Content[];
|
|
16
|
+
tools: Tool[] | Tool;
|
|
17
|
+
maxTools: number;
|
|
18
|
+
memories: number;
|
|
19
|
+
reasoning: string;
|
|
20
|
+
group: Group;
|
|
21
|
+
signal: AbortSignal;
|
|
22
|
+
}>;
|
|
23
|
+
/** Streaming text generation on `path`. A singular Tool forces it; an array lets the model choose. */
|
|
24
|
+
export declare function streamText(authorization: Credentials | ApiKey, path: string, model: string, options?: TextOptions): AsyncGenerator<StreamEvent>;
|
|
25
|
+
/** Buffers a text stream into a TextResponse. */
|
|
26
|
+
export declare function collectText(stream: AsyncGenerator<StreamEvent>): Promise<TextResponse>;
|
|
27
|
+
type VoiceOptions = Partial<{
|
|
28
|
+
content: Content[];
|
|
29
|
+
audio: AsyncIterable<Uint8Array>;
|
|
30
|
+
tools: Tool[] | Tool;
|
|
31
|
+
maxTools: number;
|
|
32
|
+
voice: Partial<Demographic>;
|
|
33
|
+
memories: number;
|
|
34
|
+
group: Group;
|
|
35
|
+
signal: AbortSignal;
|
|
36
|
+
}>;
|
|
37
|
+
/** Realtime voice on `path`: PCM16 16 kHz in from `audio`, PCM16 24 kHz out as audio events. */
|
|
38
|
+
export declare function streamVoice(authorization: Credentials | ApiKey, path: string, model: string, options?: VoiceOptions): AsyncGenerator<VoiceEvent>;
|
|
39
|
+
/** Buffers a voice stream: the audio as one PCM file, then the input and output transcripts. */
|
|
40
|
+
export declare function collectVoice(authorization: Credentials | ApiKey, stream: AsyncGenerator<VoiceEvent>): Promise<TextResponse>;
|
|
41
|
+
export {};
|