copilotz 1.0.0-rc.29 → 1.0.0-rc.30
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/CHANGELOG.md +31 -0
- package/README.md +9 -4
- package/package.json +1 -1
- package/plugins/agents/chat/actions/attach.d.ts +3 -0
- package/plugins/agents/chat/actions/attach.js +92 -0
- package/plugins/agents/chat/actions/prune.d.ts +3 -0
- package/plugins/agents/chat/actions/prune.js +20 -0
- package/plugins/agents/chat/actions/send.d.ts +0 -12
- package/plugins/agents/chat/actions/send.js +61 -69
- package/plugins/agents/chat/collections/file.d.ts +38 -5
- package/plugins/agents/chat/collections/file.js +26 -1
- package/plugins/agents/chat/collections/message.d.ts +1 -1
- package/plugins/agents/chat/contract.d.ts +2 -1
- package/plugins/agents/chat/mod.d.ts +8 -2
- package/plugins/agents/chat/mod.js +24 -6
- package/plugins/agents/chat/resources/commands.js +7 -1
- package/plugins/agents/chat/shared/contact-send.d.ts +32 -0
- package/plugins/agents/chat/shared/contact-send.js +18 -0
- package/plugins/agents/chat/views/web/attach.d.ts +9 -3
- package/plugins/agents/chat/views/web/attach.js +5 -1
- package/plugins/agents/chat/views/web/composer.d.ts +13 -2
- package/plugins/agents/chat/views/web/composer.js +40 -16
- package/plugins/agents/chat/views/web/conversation.js +1 -1
- package/plugins/agents/chat/views/web/home.js +1 -1
- package/plugins/agents/chat/views/web/words.d.ts +1 -1
- package/plugins/agents/chat/views/web/words.js +2 -0
- package/plugins/compute/computers/program/version.d.ts +1 -1
- package/plugins/compute/computers/program/version.js +1 -1
- package/plugins/compute/computers/resources/downloads.js +1 -1
- package/plugins/interfaces/api/resources/presets.js +2 -2
- package/plugins/interfaces/whatsapp/processors/receive.d.ts +2 -1
- package/plugins/interfaces/whatsapp/processors/receive.js +20 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
## Unreleased
|
|
2
2
|
|
|
3
|
+
## 1.0.0-rc.30 — 2026-11-08
|
|
4
|
+
|
|
5
|
+
**Upgrading.** `chat.send` no longer takes a file's content. Upload each file first with
|
|
6
|
+
`chat.attach` (`{ name, type, data, voice? }`, as `files` took it), and send what it answers by id:
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
const { id } = await runtime.call("chat.attach", {
|
|
10
|
+
name: "plan.pdf",
|
|
11
|
+
type: "application/pdf",
|
|
12
|
+
data,
|
|
13
|
+
});
|
|
14
|
+
await runtime.call("chat.send", { text: "The plan", files: [{ id }] });
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Call both as the same sender: a draft is sent only by its uploader's message. An API key that sends
|
|
18
|
+
files needs `chat.attach` in its scope: the "Chat" preset has it now, and a key made with it before
|
|
19
|
+
is made again (or given `chat.attach`).
|
|
20
|
+
|
|
21
|
+
- **Files of about 10 MB go, ten to a message.** `chat.send` carried every file's content, on record
|
|
22
|
+
with what it wrote too, in one call, and a call carries at most 16 MiB to the owner: a file past
|
|
23
|
+
about 6 MB was refused (`payload_too_large`). Now each file is its own call (`chat.attach`,
|
|
24
|
+
unrecorded), kept as its sender's draft (`draft`, in no conversation: nobody else reads it, a rule
|
|
25
|
+
of chat's own), and the message names it: its commit makes it the conversation's, under the rules
|
|
26
|
+
as the message is. The web composer uploads each file as it's chosen (reading, uploading, its
|
|
27
|
+
size, or why it couldn't), so sending is instant; a voice message uploads once, also when it's
|
|
28
|
+
sent again without a transcript. WhatsApp uploads what a phone sends the same way.
|
|
29
|
+
- **Drafts are bounded:** a sender holds 20 at most (the oldest go past them), and `chat.prune`
|
|
30
|
+
(chat's schedule, every hour) drops those not sent within a day. A contact's upload is let in by
|
|
31
|
+
the `contactSend` hooks as a message to nobody carrying it: a web line's file rules apply as it's
|
|
32
|
+
uploaded, and it counts against the visitor's limits.
|
|
33
|
+
|
|
3
34
|
## 1.0.0-rc.29 — 2026-11-07
|
|
4
35
|
|
|
5
36
|
- **An agent waiting on your yes waits within its turn.** A command, job or file write that needs a
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ bun add copilotz # Bun
|
|
|
22
22
|
deno add jsr:@copilotz/copilotz # Deno (or `deno add npm:copilotz`)
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
On Deno, name it `copilotz` in `deno.json` (`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.
|
|
25
|
+
On Deno, name it `copilotz` in `deno.json` (`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.30"`),
|
|
26
26
|
and the imports below are the same everywhere. Some pieces need a package of their own, installed
|
|
27
27
|
beside it: `esbuild` to bundle the page's code on Node (`bundle`), `@electric-sql/pglite` for
|
|
28
28
|
PostgreSQL in the process, and `@types/react` for the front ends' types.
|
|
@@ -631,7 +631,7 @@ and an app serves it from there by default:
|
|
|
631
631
|
import { computerDownloads } from "copilotz/plugins/compute/downloads";
|
|
632
632
|
|
|
633
633
|
plugins: [...plugins, await computerDownloads()], // this Copilotz's release
|
|
634
|
-
plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.
|
|
634
|
+
plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.30" })], // its own: /computer/download/
|
|
635
635
|
plugins: [...plugins, await computerDownloads({ url: "https://downloads.example.com/computer/" })], // or elsewhere
|
|
636
636
|
```
|
|
637
637
|
|
|
@@ -788,8 +788,13 @@ name, never by importing its code.
|
|
|
788
788
|
`runtime.query("thread.prompt", { thread, agent })` and `/prompt` show exactly what an agent
|
|
789
789
|
gets.
|
|
790
790
|
- **Files:** a message's files ride on it by name, type and size; their content is a `file`
|
|
791
|
-
document whose data (plain base64) the owner keeps as a blob.
|
|
792
|
-
|
|
791
|
+
document whose data (plain base64) the owner keeps as a blob. Each is uploaded on its own first
|
|
792
|
+
(`chat.attach`, one file a call, about 10 MB at most), as its sender's draft, which nobody else
|
|
793
|
+
reads; `chat.send` then names them (`files: [{ id }]`) and they join its conversation in its
|
|
794
|
+
commit. The web composer uploads each file as it's chosen. A sender holds 20 drafts at most, and
|
|
795
|
+
those not sent within a day go (`chat.prune`, every hour). A contact's upload is let in by the
|
|
796
|
+
`contactSend` hooks as a message to nobody carrying it. `file.about` says what a file is, as its
|
|
797
|
+
reader reaches it, without its content; `/files/<id>` streams the content, of any size, in
|
|
793
798
|
parts, with ranges. Agents read a text file's content, are shown images and PDFs when their
|
|
794
799
|
model reads them (the latest 8; the catalog says which models do, or the model choice's
|
|
795
800
|
`input: ["image"]`, and the others are told what they can't see), and see anything else by name.
|
package/package.json
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chat.attach`: a file to send, uploaded on its own before the message
|
|
3
|
+
* that sends it (`chat.send`, which names it by id). It's kept as a draft:
|
|
4
|
+
* its sender's (`draft`), read by nobody else, in no conversation yet. A
|
|
5
|
+
* composer uploads each file as it's chosen, so sending is instant and a
|
|
6
|
+
* file that can't go says so alone.
|
|
7
|
+
*
|
|
8
|
+
* One file a call, and unrecorded (its content isn't kept again as what
|
|
9
|
+
* the call was given): a call carries at most 16 MiB to the owner, so a
|
|
10
|
+
* file of about 10 MB fits, and a message of ten of them goes in ten calls.
|
|
11
|
+
*
|
|
12
|
+
* A contact's upload is let in by the app's `contactSend` hooks first, as a
|
|
13
|
+
* message to nobody carrying it (a web line's file rules and limits). A
|
|
14
|
+
* sender holds `MOST_DRAFTS` drafts at most: the oldest beyond go. What
|
|
15
|
+
* isn't sent within a day goes too (`chat.prune`).
|
|
16
|
+
*/
|
|
17
|
+
import { defineAction, failure, peopleOrContacts } from "../../../../runtime/mod.js";
|
|
18
|
+
import { BASE64, drafter, FILE_DATA, sizeOf } from "../collections/file.js";
|
|
19
|
+
import { letIn } from "../shared/contact-send.js";
|
|
20
|
+
import { now } from "../shared/agents.js";
|
|
21
|
+
import { MEDIA_TYPE, MEDIA_TYPE_LENGTH } from "./send.js";
|
|
22
|
+
/** The most drafts a sender holds: two messages' worth (a file taken out and another put in). */
|
|
23
|
+
export const MOST_DRAFTS = 20;
|
|
24
|
+
export const attachAction = defineAction({
|
|
25
|
+
description: "Uploads a file to send: a draft that a message of yours sends, by its id",
|
|
26
|
+
record: false,
|
|
27
|
+
input: {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: {
|
|
30
|
+
name: { type: "string", minLength: 1, maxLength: 255 },
|
|
31
|
+
// A media type, as the model is told it: `type/subtype`, with parameters at most.
|
|
32
|
+
type: { type: "string", maxLength: MEDIA_TYPE_LENGTH, pattern: MEDIA_TYPE.source },
|
|
33
|
+
/** Its content, plain base64. */
|
|
34
|
+
data: { type: "string", maxLength: FILE_DATA, pattern: BASE64 },
|
|
35
|
+
/** A recording's length (ms) and its loudness over time, for its player. */
|
|
36
|
+
voice: {
|
|
37
|
+
type: "object",
|
|
38
|
+
properties: {
|
|
39
|
+
duration: { type: "number", minimum: 0 },
|
|
40
|
+
peaks: {
|
|
41
|
+
type: "array",
|
|
42
|
+
maxItems: 64,
|
|
43
|
+
items: { type: "number", minimum: 0, maximum: 1 },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
required: ["duration"],
|
|
47
|
+
additionalProperties: false,
|
|
48
|
+
},
|
|
49
|
+
/** The chat it's for, when there's one: a contact's hooks are told. */
|
|
50
|
+
thread: { type: "string" },
|
|
51
|
+
},
|
|
52
|
+
required: ["name", "data"],
|
|
53
|
+
additionalProperties: false,
|
|
54
|
+
},
|
|
55
|
+
allow: peopleOrContacts,
|
|
56
|
+
run: async (ctx, input) => {
|
|
57
|
+
const by = drafter(ctx.actor);
|
|
58
|
+
if (!by)
|
|
59
|
+
throw failure("forbidden", "Only people and contacts send files.");
|
|
60
|
+
const type = input.type ?? "application/octet-stream";
|
|
61
|
+
const size = sizeOf(input.data);
|
|
62
|
+
if (ctx.actor?.kind === "contact") {
|
|
63
|
+
await letIn(ctx, {
|
|
64
|
+
...(input.thread ? { thread: input.thread } : {}),
|
|
65
|
+
files: [{ name: input.name, type, size }],
|
|
66
|
+
to: [],
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const id = `file-${crypto.randomUUID()}`;
|
|
70
|
+
// Written by the system, for its sender: in no conversation yet, nobody's rules place it.
|
|
71
|
+
const files = ctx.as().db.collection("file");
|
|
72
|
+
await files.insertOne({
|
|
73
|
+
_id: id,
|
|
74
|
+
name: input.name,
|
|
75
|
+
type,
|
|
76
|
+
size,
|
|
77
|
+
data: input.data,
|
|
78
|
+
...(input.voice ? { voice: input.voice } : {}),
|
|
79
|
+
draft: by,
|
|
80
|
+
at: now(),
|
|
81
|
+
});
|
|
82
|
+
// Their oldest past the most they hold go.
|
|
83
|
+
const kept = await files.find({ draft: by }, {
|
|
84
|
+
sort: { at: -1, _id: -1 },
|
|
85
|
+
skip: MOST_DRAFTS,
|
|
86
|
+
projection: { _id: 1 },
|
|
87
|
+
});
|
|
88
|
+
if (kept.length)
|
|
89
|
+
await files.deleteMany({ _id: { $in: kept.map((f) => f._id) } });
|
|
90
|
+
return { id, size };
|
|
91
|
+
},
|
|
92
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chat.prune`: files uploaded to send (`chat.attach`) that no message sent
|
|
3
|
+
* within a day go. Chat's schedule calls it every hour; nobody outside may.
|
|
4
|
+
*/
|
|
5
|
+
import { defineAction } from "../../../../runtime/mod.js";
|
|
6
|
+
/** How long a draft waits to be sent. */
|
|
7
|
+
export const DRAFT_MS = 86_400_000;
|
|
8
|
+
export const pruneAction = defineAction({
|
|
9
|
+
description: "Drops files uploaded to send that no message sent within a day",
|
|
10
|
+
input: { type: "object", additionalProperties: false },
|
|
11
|
+
record: false,
|
|
12
|
+
run: async (ctx) => {
|
|
13
|
+
const before = new Date(Date.now() - DRAFT_MS).toISOString();
|
|
14
|
+
const { deletedCount } = await ctx.as().db.collection("file").deleteMany({
|
|
15
|
+
draft: { $exists: true },
|
|
16
|
+
at: { $lt: before },
|
|
17
|
+
});
|
|
18
|
+
return { gone: deletedCount };
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -8,16 +8,4 @@ export declare const MEDIA_TYPE_LENGTH = 127;
|
|
|
8
8
|
* an agent is told it (`[file a.bin: <type>, …]`).
|
|
9
9
|
*/
|
|
10
10
|
export declare const MEDIA_TYPE: RegExp;
|
|
11
|
-
/**
|
|
12
|
-
* A `contactSend` resource: the Action that lets a contact's message in,
|
|
13
|
-
* asked as the contact before anything's sent, with where it goes (`thread`,
|
|
14
|
-
* when it names one), what it carries (each file's name, media type and
|
|
15
|
-
* size), and `to: []` when it goes to nobody (no agent answers it: no turn
|
|
16
|
-
* to pay for). It refuses it (a limit), or answers where it goes when it names no
|
|
17
|
-
* chat (`thread`: the contact's own) and `transcribe: false` when its audio
|
|
18
|
-
* goes untranscribed.
|
|
19
|
-
*/
|
|
20
|
-
export type ContactSend = {
|
|
21
|
-
action: string;
|
|
22
|
-
};
|
|
23
11
|
export declare const sendAction: import("../../../../runtime/define.js").ActionDef;
|
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
* to, else the thread's agents: never whom it names, though it too may say
|
|
10
10
|
* something to nobody (`to: []`). It replies only to a message of the same conversation that its
|
|
11
11
|
* sender reads. Only agents answering in
|
|
12
|
-
* its space answer there: naming one that doesn't fails (`not_here`).
|
|
12
|
+
* its space answer there: naming one that doesn't fails (`not_here`). Its
|
|
13
|
+
* files are the sender's own uploads (`chat.attach`), named by id: a call
|
|
14
|
+
* carries no file's content, so a message of ten large ones goes as quickly
|
|
15
|
+
* as one of words. They join its conversation in its own commit. Audio
|
|
13
16
|
* sent with it is transcribed first (what agents read): if that fails,
|
|
14
17
|
* nothing is sent and the call fails with `transcription_failed`;
|
|
15
18
|
* `transcribe: false` sends it as it is. `via` says what sent it for the
|
|
@@ -29,8 +32,9 @@
|
|
|
29
32
|
* People's messages go as ever.
|
|
30
33
|
*/
|
|
31
34
|
import { defineAction, failure, peopleOrContacts, } from "../../../../runtime/mod.js";
|
|
32
|
-
import {
|
|
35
|
+
import { drafter, MOST_FILES } from "../collections/file.js";
|
|
33
36
|
import { agentsNamed, handles, mentions, NO_ANSWER, now, rosterOf, } from "../shared/agents.js";
|
|
37
|
+
import { letIn } from "../shared/contact-send.js";
|
|
34
38
|
import { delivery } from "../shared/delivery.js";
|
|
35
39
|
import { movedBy, startedWith } from "../shared/summary.js";
|
|
36
40
|
import { settingsOf } from "../shared/types.js";
|
|
@@ -45,24 +49,6 @@ export const MEDIA_TYPE_LENGTH = 127;
|
|
|
45
49
|
* an agent is told it (`[file a.bin: <type>, …]`).
|
|
46
50
|
*/
|
|
47
51
|
export const MEDIA_TYPE = /^[A-Za-z0-9][\w!#$&^.+-]*\/[A-Za-z0-9][\w!#$&^.+-]*(?: *; *[\w!#$&^.+-]+=(?:[\w!#$&^.+-]+|"[ !#-\[\]-~]*"))* *$/;
|
|
48
|
-
/** What the app's `contactSend` hooks say of a contact's message, each in turn. */
|
|
49
|
-
async function letIn(ctx, asked) {
|
|
50
|
-
const hooks = Object.values((ctx.resources.contactSend ?? {}));
|
|
51
|
-
let said = {};
|
|
52
|
-
for (const hook of hooks) {
|
|
53
|
-
const answer = await ctx.call(hook.action, {
|
|
54
|
-
...(asked.thread ? { thread: asked.thread } : {}),
|
|
55
|
-
files: asked.files,
|
|
56
|
-
...(asked.to ? { to: asked.to } : {}),
|
|
57
|
-
});
|
|
58
|
-
said = {
|
|
59
|
-
...said,
|
|
60
|
-
...(typeof answer?.thread === "string" && !said.thread ? { thread: answer.thread } : {}),
|
|
61
|
-
...(answer?.transcribe === false ? { transcribe: false } : {}),
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
return said;
|
|
65
|
-
}
|
|
66
52
|
/**
|
|
67
53
|
* The `@word`s in `text` that name someone who can be addressed: an agent
|
|
68
54
|
* (the app's, a source's, or one answering here), one of the thread's agents,
|
|
@@ -102,33 +88,14 @@ export const sendAction = defineAction({
|
|
|
102
88
|
replyTo: { type: "string" },
|
|
103
89
|
/** Where a new thread goes (a space); an existing one stays where it is. */
|
|
104
90
|
in: { type: "string" },
|
|
105
|
-
/** Files
|
|
91
|
+
/** Files it sends: the sender's own uploads (`chat.attach`), by id, in the order shown. */
|
|
106
92
|
files: {
|
|
107
93
|
type: "array",
|
|
108
|
-
maxItems:
|
|
94
|
+
maxItems: MOST_FILES,
|
|
109
95
|
items: {
|
|
110
96
|
type: "object",
|
|
111
|
-
properties: {
|
|
112
|
-
|
|
113
|
-
// A media type, as the model is told it: `type/subtype`, with parameters at most.
|
|
114
|
-
type: { type: "string", maxLength: MEDIA_TYPE_LENGTH, pattern: MEDIA_TYPE.source },
|
|
115
|
-
data: { type: "string", maxLength: FILE_DATA, pattern: BASE64 },
|
|
116
|
-
/** A recording's length (ms) and its loudness over time, for its player. */
|
|
117
|
-
voice: {
|
|
118
|
-
type: "object",
|
|
119
|
-
properties: {
|
|
120
|
-
duration: { type: "number", minimum: 0 },
|
|
121
|
-
peaks: {
|
|
122
|
-
type: "array",
|
|
123
|
-
maxItems: 64,
|
|
124
|
-
items: { type: "number", minimum: 0, maximum: 1 },
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
required: ["duration"],
|
|
128
|
-
additionalProperties: false,
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
required: ["name", "data"],
|
|
97
|
+
properties: { id: { type: "string", minLength: 1 } },
|
|
98
|
+
required: ["id"],
|
|
132
99
|
additionalProperties: false,
|
|
133
100
|
},
|
|
134
101
|
},
|
|
@@ -182,6 +149,21 @@ export const sendAction = defineAction({
|
|
|
182
149
|
code: "invalid",
|
|
183
150
|
});
|
|
184
151
|
}
|
|
152
|
+
// Its files: the sender's drafts, which only the system reads before they're sent.
|
|
153
|
+
const by = drafter(ctx.actor);
|
|
154
|
+
const drafts = ctx.as().db.collection("file");
|
|
155
|
+
const ids = (input.files ?? []).map((f) => f.id);
|
|
156
|
+
if (new Set(ids).size < ids.length) {
|
|
157
|
+
throw failure("invalid", "A message sends each file once.", { public: true });
|
|
158
|
+
}
|
|
159
|
+
const mine = ids.length
|
|
160
|
+
? await drafts.find({ _id: { $in: ids }, draft: by }, { projection: { data: 0 } })
|
|
161
|
+
: [];
|
|
162
|
+
const unsent = ids.find((id) => !mine.some((f) => f._id === id));
|
|
163
|
+
if (unsent) {
|
|
164
|
+
throw failure("not_found", `No file "${unsent}" of yours to send: upload it first (chat.attach).`, { public: true });
|
|
165
|
+
}
|
|
166
|
+
const attached = ids.map((id) => mine.find((f) => f._id === id));
|
|
185
167
|
// A contact talks with whom its chat is with: what it says names nobody else, and the app
|
|
186
168
|
// lets it in first (its line's limits, the files it takes, its own chat).
|
|
187
169
|
const contact = ctx.actor?.kind === "contact";
|
|
@@ -195,11 +177,7 @@ export const sendAction = defineAction({
|
|
|
195
177
|
const allowed = contact
|
|
196
178
|
? await letIn(ctx, {
|
|
197
179
|
...(input.thread ? { thread: input.thread } : {}),
|
|
198
|
-
files:
|
|
199
|
-
name: f.name,
|
|
200
|
-
...(f.type ? { type: f.type } : {}),
|
|
201
|
-
size: sizeOf(f.data),
|
|
202
|
-
})),
|
|
180
|
+
files: attached.map((f) => ({ name: f.name, type: f.type, size: f.size })),
|
|
203
181
|
...(nobody ? { to: [] } : {}),
|
|
204
182
|
})
|
|
205
183
|
: {};
|
|
@@ -231,16 +209,17 @@ export const sendAction = defineAction({
|
|
|
231
209
|
const chosen = to.filter((name) => agents[name]);
|
|
232
210
|
const joined = existing ? members : chosen.length ? chosen : members;
|
|
233
211
|
const id = crypto.randomUUID();
|
|
234
|
-
// What audio says, before anything is sent: agents read it.
|
|
235
|
-
const transcripts = await Promise.all(
|
|
212
|
+
// What audio says, before anything is sent: agents read it. Each recording read on its own.
|
|
213
|
+
const transcripts = await Promise.all(attached.map(async (f) => {
|
|
236
214
|
if (input.transcribe === false || allowed.transcribe === false)
|
|
237
215
|
return undefined;
|
|
238
|
-
if (!f.type
|
|
216
|
+
if (!f.type.startsWith("audio/"))
|
|
239
217
|
return undefined;
|
|
218
|
+
const audio = (await drafts.findOne({ _id: f._id, draft: by }))?.data ?? "";
|
|
240
219
|
try {
|
|
241
220
|
const heard = await ctx.call("transcription.transcribe", {
|
|
242
221
|
model: settingsOf(ctx).transcriber ?? "transcribe",
|
|
243
|
-
audio
|
|
222
|
+
audio,
|
|
244
223
|
type: f.type,
|
|
245
224
|
filename: f.name,
|
|
246
225
|
tags: { thread: threadId, purpose: "transcription", ...(where ? { space: where } : {}) },
|
|
@@ -251,29 +230,36 @@ export const sendAction = defineAction({
|
|
|
251
230
|
throw Object.assign(new Error(`Couldn't transcribe ${f.name}: ${error.message}`), { code: "transcription_failed" });
|
|
252
231
|
}
|
|
253
232
|
}));
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
233
|
+
// The drafts go where the message goes, with what their audio says, drafts still: nobody
|
|
234
|
+
// else reads them yet. Only the system reaches a draft in no conversation; once there, its
|
|
235
|
+
// sender's commit below sends it, under the rules as the message is.
|
|
236
|
+
// One an earlier send placed and didn't send loses what that send gave it.
|
|
237
|
+
for (const [i, f] of attached.entries()) {
|
|
238
|
+
const heard = transcripts[i];
|
|
239
|
+
const unset = {
|
|
240
|
+
...(where ? {} : { in: "" }),
|
|
241
|
+
...(heard === undefined ? { transcript: "" } : {}),
|
|
242
|
+
};
|
|
243
|
+
await drafts.updateOne({ _id: f._id, draft: by }, {
|
|
244
|
+
$set: {
|
|
245
|
+
thread: threadId,
|
|
246
|
+
...(where ? { in: where } : {}),
|
|
247
|
+
...(heard !== undefined ? { transcript: heard } : {}),
|
|
248
|
+
},
|
|
249
|
+
...(Object.keys(unset).length ? { $unset: unset } : {}),
|
|
250
|
+
});
|
|
251
|
+
}
|
|
266
252
|
const sent = {
|
|
267
253
|
_id: id,
|
|
268
|
-
...(
|
|
254
|
+
...(attached.length
|
|
269
255
|
? {
|
|
270
|
-
files:
|
|
256
|
+
files: attached.map((f, i) => ({
|
|
271
257
|
id: f._id,
|
|
272
258
|
name: f.name,
|
|
273
259
|
type: f.type,
|
|
274
260
|
size: f.size,
|
|
275
261
|
...(f.voice ? { voice: f.voice } : {}),
|
|
276
|
-
...(
|
|
262
|
+
...(transcripts[i] !== undefined ? { transcript: transcripts[i] } : {}),
|
|
277
263
|
})),
|
|
278
264
|
}
|
|
279
265
|
: {}),
|
|
@@ -305,8 +291,14 @@ export const sendAction = defineAction({
|
|
|
305
291
|
at: sent.at,
|
|
306
292
|
});
|
|
307
293
|
}
|
|
308
|
-
if (
|
|
309
|
-
await tx.db.collection("file").
|
|
294
|
+
if (ids.length) {
|
|
295
|
+
const { matchedCount } = await tx.db.collection("file").updateMany({ _id: { $in: ids }, draft: by }, { $unset: { draft: "" } });
|
|
296
|
+
if (matchedCount < ids.length) {
|
|
297
|
+
throw failure("not_found", "A file of this message is gone: upload it again.", {
|
|
298
|
+
public: true,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
310
302
|
await tx.db.collection("message").insertOne(sent);
|
|
311
303
|
await deliver(tx);
|
|
312
304
|
});
|
|
@@ -6,6 +6,11 @@
|
|
|
6
6
|
* Nothing answers a file whole: a query's answer comes from an executor in
|
|
7
7
|
* one piece, which is no way to move megabytes. `file.about` says what a
|
|
8
8
|
* file is, and `/files/<id>` (routes/files.ts) streams its content.
|
|
9
|
+
*
|
|
10
|
+
* Nor does a call carry more than one: a file comes in on its own
|
|
11
|
+
* (`chat.attach`), as a draft (`draft`: whose it is, nobody else reads it;
|
|
12
|
+
* no `thread` yet), and the message that sends it (`chat.send`) names it by
|
|
13
|
+
* id. Drafts never sent go after a day (`chat.prune`).
|
|
9
14
|
*/
|
|
10
15
|
import { type Infer } from "../../../../runtime/mod.js";
|
|
11
16
|
/**
|
|
@@ -33,6 +38,13 @@ declare const fileSchema: {
|
|
|
33
38
|
readonly type: "string";
|
|
34
39
|
readonly pattern: "^[A-Za-z0-9+/]*={0,2}$";
|
|
35
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Not sent yet: whose it is (a person's id, `contact:<id>`, or `system`).
|
|
43
|
+
* Only they reach it, and only a message of theirs sends it.
|
|
44
|
+
*/
|
|
45
|
+
readonly draft: {
|
|
46
|
+
readonly type: "string";
|
|
47
|
+
};
|
|
36
48
|
/** A recording's length (ms) and its loudness over time (up to 64 values, 0–1), for its player. */
|
|
37
49
|
readonly voice: {
|
|
38
50
|
readonly type: "object";
|
|
@@ -54,6 +66,7 @@ declare const fileSchema: {
|
|
|
54
66
|
readonly transcript: {
|
|
55
67
|
readonly type: "string";
|
|
56
68
|
};
|
|
69
|
+
/** Its conversation, once a message sends it. */
|
|
57
70
|
readonly thread: {
|
|
58
71
|
readonly type: "string";
|
|
59
72
|
};
|
|
@@ -72,7 +85,7 @@ declare const fileSchema: {
|
|
|
72
85
|
readonly type: "string";
|
|
73
86
|
};
|
|
74
87
|
};
|
|
75
|
-
readonly required: readonly ["name", "type", "size", "data", "
|
|
88
|
+
readonly required: readonly ["name", "type", "size", "data", "at"];
|
|
76
89
|
};
|
|
77
90
|
export declare const file: {
|
|
78
91
|
schema: {
|
|
@@ -94,6 +107,13 @@ export declare const file: {
|
|
|
94
107
|
readonly type: "string";
|
|
95
108
|
readonly pattern: "^[A-Za-z0-9+/]*={0,2}$";
|
|
96
109
|
};
|
|
110
|
+
/**
|
|
111
|
+
* Not sent yet: whose it is (a person's id, `contact:<id>`, or `system`).
|
|
112
|
+
* Only they reach it, and only a message of theirs sends it.
|
|
113
|
+
*/
|
|
114
|
+
readonly draft: {
|
|
115
|
+
readonly type: "string";
|
|
116
|
+
};
|
|
97
117
|
/** A recording's length (ms) and its loudness over time (up to 64 values, 0–1), for its player. */
|
|
98
118
|
readonly voice: {
|
|
99
119
|
readonly type: "object";
|
|
@@ -115,6 +135,7 @@ export declare const file: {
|
|
|
115
135
|
readonly transcript: {
|
|
116
136
|
readonly type: "string";
|
|
117
137
|
};
|
|
138
|
+
/** Its conversation, once a message sends it. */
|
|
118
139
|
readonly thread: {
|
|
119
140
|
readonly type: "string";
|
|
120
141
|
};
|
|
@@ -133,7 +154,7 @@ export declare const file: {
|
|
|
133
154
|
readonly type: "string";
|
|
134
155
|
};
|
|
135
156
|
};
|
|
136
|
-
readonly required: readonly ["name", "type", "size", "data", "
|
|
157
|
+
readonly required: readonly ["name", "type", "size", "data", "at"];
|
|
137
158
|
};
|
|
138
159
|
events?: boolean;
|
|
139
160
|
records?: boolean;
|
|
@@ -143,19 +164,20 @@ export declare const file: {
|
|
|
143
164
|
queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
|
|
144
165
|
[x: string]: unknown;
|
|
145
166
|
private?: boolean | undefined;
|
|
146
|
-
|
|
167
|
+
draft?: string | undefined;
|
|
147
168
|
voice?: {
|
|
148
169
|
[x: string]: unknown;
|
|
149
170
|
peaks?: number[] | undefined;
|
|
150
171
|
duration: number;
|
|
151
172
|
} | undefined;
|
|
152
173
|
transcript?: string | undefined;
|
|
174
|
+
thread?: string | undefined;
|
|
175
|
+
in?: string | undefined;
|
|
153
176
|
data: string;
|
|
154
177
|
type: string;
|
|
155
178
|
at: string;
|
|
156
179
|
name: string;
|
|
157
180
|
size: number;
|
|
158
|
-
thread: string;
|
|
159
181
|
} & {
|
|
160
182
|
_id: string;
|
|
161
183
|
}>> | undefined;
|
|
@@ -165,7 +187,7 @@ export type File = Infer<typeof fileSchema> & {
|
|
|
165
187
|
_id: string;
|
|
166
188
|
};
|
|
167
189
|
/** A file as `file.about` answers it: everything but its content. */
|
|
168
|
-
export type FileAbout = Pick<File, "_id" | "name" | "type" | "size" | "voice" | "transcript" | "thread" | "in" | "private" | "at">;
|
|
190
|
+
export type FileAbout = Pick<File, "_id" | "name" | "type" | "size" | "voice" | "transcript" | "thread" | "in" | "private" | "draft" | "at">;
|
|
169
191
|
/** Media types read as text: what agents get the content of. */
|
|
170
192
|
/** How much of a text file an agent is sent. */
|
|
171
193
|
export declare const FILE_CHARS = 20000;
|
|
@@ -174,6 +196,17 @@ export declare const textual: (type: string) => boolean;
|
|
|
174
196
|
export declare const sizeOf: (data: string) => number;
|
|
175
197
|
/** The most a file's content may be, as base64 (about 10 MB): people's and agents' alike. */
|
|
176
198
|
export declare const FILE_DATA = 14000000;
|
|
199
|
+
/** The most files a message carries. */
|
|
200
|
+
export declare const MOST_FILES = 10;
|
|
201
|
+
/**
|
|
202
|
+
* Whose drafts are whose: a person by id, a contact as `contact:<id>`
|
|
203
|
+
* (as messages name their sender), the system as `system`; anyone else
|
|
204
|
+
* (an agent) has none.
|
|
205
|
+
*/
|
|
206
|
+
export declare const drafter: (actor?: {
|
|
207
|
+
kind: string;
|
|
208
|
+
id: string;
|
|
209
|
+
}) => string | undefined;
|
|
177
210
|
/** A base64 file's content as text. */
|
|
178
211
|
export declare const text: (data: string) => string;
|
|
179
212
|
export {};
|
|
@@ -6,6 +6,11 @@
|
|
|
6
6
|
* Nothing answers a file whole: a query's answer comes from an executor in
|
|
7
7
|
* one piece, which is no way to move megabytes. `file.about` says what a
|
|
8
8
|
* file is, and `/files/<id>` (routes/files.ts) streams its content.
|
|
9
|
+
*
|
|
10
|
+
* Nor does a call carry more than one: a file comes in on its own
|
|
11
|
+
* (`chat.attach`), as a draft (`draft`: whose it is, nobody else reads it;
|
|
12
|
+
* no `thread` yet), and the message that sends it (`chat.send`) names it by
|
|
13
|
+
* id. Drafts never sent go after a day (`chat.prune`).
|
|
9
14
|
*/
|
|
10
15
|
import { defineCollection, peopleOrContacts } from "../../../../runtime/mod.js";
|
|
11
16
|
/**
|
|
@@ -24,6 +29,11 @@ const fileSchema = {
|
|
|
24
29
|
size: { type: "integer" },
|
|
25
30
|
/** The content, base64. */
|
|
26
31
|
data: { type: "string", pattern: BASE64 },
|
|
32
|
+
/**
|
|
33
|
+
* Not sent yet: whose it is (a person's id, `contact:<id>`, or `system`).
|
|
34
|
+
* Only they reach it, and only a message of theirs sends it.
|
|
35
|
+
*/
|
|
36
|
+
draft: { type: "string" },
|
|
27
37
|
/** A recording's length (ms) and its loudness over time (up to 64 values, 0–1), for its player. */
|
|
28
38
|
voice: {
|
|
29
39
|
type: "object",
|
|
@@ -35,6 +45,7 @@ const fileSchema = {
|
|
|
35
45
|
},
|
|
36
46
|
/** What an audio file says, transcribed when it was sent: what agents read. */
|
|
37
47
|
transcript: { type: "string" },
|
|
48
|
+
/** Its conversation, once a message sends it. */
|
|
38
49
|
thread: { type: "string" },
|
|
39
50
|
/** The space its thread is in. */
|
|
40
51
|
in: { type: "string" },
|
|
@@ -45,7 +56,7 @@ const fileSchema = {
|
|
|
45
56
|
private: { type: "boolean" },
|
|
46
57
|
at: { type: "string" },
|
|
47
58
|
},
|
|
48
|
-
required: ["name", "type", "size", "data", "
|
|
59
|
+
required: ["name", "type", "size", "data", "at"],
|
|
49
60
|
};
|
|
50
61
|
export const file = defineCollection({
|
|
51
62
|
schema: fileSchema,
|
|
@@ -70,5 +81,19 @@ export const textual = (type) => type.startsWith("text/") || /json|xml|yaml|csv|
|
|
|
70
81
|
export const sizeOf = (data) => Math.floor(data.replace(/=+$/, "").length * 3 / 4);
|
|
71
82
|
/** The most a file's content may be, as base64 (about 10 MB): people's and agents' alike. */
|
|
72
83
|
export const FILE_DATA = 14_000_000;
|
|
84
|
+
/** The most files a message carries. */
|
|
85
|
+
export const MOST_FILES = 10;
|
|
86
|
+
/**
|
|
87
|
+
* Whose drafts are whose: a person by id, a contact as `contact:<id>`
|
|
88
|
+
* (as messages name their sender), the system as `system`; anyone else
|
|
89
|
+
* (an agent) has none.
|
|
90
|
+
*/
|
|
91
|
+
export const drafter = (actor) => !actor || actor.kind === "system"
|
|
92
|
+
? "system"
|
|
93
|
+
: actor.kind === "person"
|
|
94
|
+
? actor.id
|
|
95
|
+
: actor.kind === "contact"
|
|
96
|
+
? `contact:${actor.id}`
|
|
97
|
+
: undefined;
|
|
73
98
|
/** A base64 file's content as text. */
|
|
74
99
|
export const text = (data) => new TextDecoder().decode(Uint8Array.from(atob(data), (c) => c.charCodeAt(0)));
|
|
@@ -468,11 +468,11 @@ export declare const message: {
|
|
|
468
468
|
size: number;
|
|
469
469
|
}[] | undefined;
|
|
470
470
|
toolCalls?: unknown[] | undefined;
|
|
471
|
+
in?: string | undefined;
|
|
471
472
|
replyTo?: string | undefined;
|
|
472
473
|
expectReply?: boolean | undefined;
|
|
473
474
|
subthread?: string | undefined;
|
|
474
475
|
turn?: string | undefined;
|
|
475
|
-
in?: string | undefined;
|
|
476
476
|
sources?: string[] | undefined;
|
|
477
477
|
tap?: {
|
|
478
478
|
[x: string]: unknown;
|
|
@@ -30,7 +30,8 @@ export { tool } from "./shared/types.js";
|
|
|
30
30
|
export { runTool, type ToolAt, type ToolRun, toolText } from "./shared/tools.js";
|
|
31
31
|
export { type Origin, originKey, originOf } from "./shared/origin.js";
|
|
32
32
|
export type { AgentModel, AgentSource, Roster, RosterSource, Team } from "./shared/agents.js";
|
|
33
|
-
export { CONTACT_TEXT,
|
|
33
|
+
export { CONTACT_TEXT, MEDIA_TYPE, MEDIA_TYPE_LENGTH } from "./actions/send.js";
|
|
34
|
+
export type { ContactSend } from "./shared/contact-send.js";
|
|
34
35
|
/**
|
|
35
36
|
* The app's agents (`agentsOf`), who of them answer new conversations
|
|
36
37
|
* (`defaults`), an agent's model (`modelOf`), which names are agents and
|
|
@@ -26,6 +26,11 @@
|
|
|
26
26
|
* instead of asking its model again, so a call that returned never runs
|
|
27
27
|
* twice, and one cut short runs again as itself (`ctx.callId`, the key for
|
|
28
28
|
* what it does outside).
|
|
29
|
+
* - A file goes in on its own before the message that sends it
|
|
30
|
+
* (`chat.attach`: one a call, kept as its sender's draft, which nobody
|
|
31
|
+
* else reads), and the message names it by id (`chat.send`): no call
|
|
32
|
+
* carries more than one file. Drafts not sent within a day go
|
|
33
|
+
* (`chat.prune`, hourly).
|
|
29
34
|
* - A person moves a conversation to another space (`chat.move`), with
|
|
30
35
|
* everything in it; not while an agent is writing in it.
|
|
31
36
|
* - A chat can be opened empty (`chat.open`), to share it with a contact
|
|
@@ -70,8 +75,9 @@
|
|
|
70
75
|
* - `roster`: { action }: `{ space }` in, `{ agents, default? }` out;
|
|
71
76
|
* - `agentModel`: { action }: `{ agent, space? }` in, a model or null out;
|
|
72
77
|
* - `contactSend`: { action }: asked as a contact about to send, `{ thread?,
|
|
73
|
-
* files }` in (each file's name, type and size)
|
|
74
|
-
*
|
|
78
|
+
* files }` in (each file's name, type and size), and for each file it
|
|
79
|
+
* uploads, as a message to nobody (`to: []`) carrying it; it refuses, or
|
|
80
|
+
* answers `{ thread?, transcribe?: false }` (see shared/contact-send.ts);
|
|
75
81
|
* - `additions`: { order?, agents? }, each with an `addition:<name>` View in
|
|
76
82
|
* the place that shows it, given `{ thread, answer }` (see `Addition`).
|
|
77
83
|
*/
|
|
@@ -26,6 +26,11 @@
|
|
|
26
26
|
* instead of asking its model again, so a call that returned never runs
|
|
27
27
|
* twice, and one cut short runs again as itself (`ctx.callId`, the key for
|
|
28
28
|
* what it does outside).
|
|
29
|
+
* - A file goes in on its own before the message that sends it
|
|
30
|
+
* (`chat.attach`: one a call, kept as its sender's draft, which nobody
|
|
31
|
+
* else reads), and the message names it by id (`chat.send`): no call
|
|
32
|
+
* carries more than one file. Drafts not sent within a day go
|
|
33
|
+
* (`chat.prune`, hourly).
|
|
29
34
|
* - A person moves a conversation to another space (`chat.move`), with
|
|
30
35
|
* everything in it; not while an agent is writing in it.
|
|
31
36
|
* - A chat can be opened empty (`chat.open`), to share it with a contact
|
|
@@ -70,23 +75,26 @@
|
|
|
70
75
|
* - `roster`: { action }: `{ space }` in, `{ agents, default? }` out;
|
|
71
76
|
* - `agentModel`: { action }: `{ agent, space? }` in, a model or null out;
|
|
72
77
|
* - `contactSend`: { action }: asked as a contact about to send, `{ thread?,
|
|
73
|
-
* files }` in (each file's name, type and size)
|
|
74
|
-
*
|
|
78
|
+
* files }` in (each file's name, type and size), and for each file it
|
|
79
|
+
* uploads, as a message to nobody (`to: []`) carrying it; it refuses, or
|
|
80
|
+
* answers `{ thread?, transcribe?: false }` (see shared/contact-send.ts);
|
|
75
81
|
* - `additions`: { order?, agents? }, each with an `addition:<name>` View in
|
|
76
82
|
* the place that shows it, given `{ thread, answer }` (see `Addition`).
|
|
77
83
|
*/
|
|
78
84
|
import { definePlugin, failure } from "../../../runtime/mod.js";
|
|
85
|
+
import { attachAction } from "./actions/attach.js";
|
|
79
86
|
import { eraseAction } from "./actions/erase.js";
|
|
80
87
|
import { forkAction } from "./actions/fork.js";
|
|
81
88
|
import { importAction } from "./actions/import.js";
|
|
82
89
|
import { moveAction } from "./actions/move.js";
|
|
83
90
|
import { openAction } from "./actions/open.js";
|
|
91
|
+
import { pruneAction } from "./actions/prune.js";
|
|
84
92
|
import { quietAction } from "./actions/quiet.js";
|
|
85
93
|
import { sayAction } from "./actions/say.js";
|
|
86
94
|
import { sendAction } from "./actions/send.js";
|
|
87
95
|
import { shownAction } from "./actions/shown.js";
|
|
88
96
|
import { stopAction } from "./actions/stop.js";
|
|
89
|
-
import { file } from "./collections/file.js";
|
|
97
|
+
import { drafter, file } from "./collections/file.js";
|
|
90
98
|
import { serveFile } from "./routes/files.js";
|
|
91
99
|
import { intent } from "./collections/intent.js";
|
|
92
100
|
import { live } from "./collections/live.js";
|
|
@@ -138,6 +146,8 @@ export const chat = definePlugin({
|
|
|
138
146
|
},
|
|
139
147
|
actions: {
|
|
140
148
|
"chat.send": sendAction,
|
|
149
|
+
"chat.attach": attachAction,
|
|
150
|
+
"chat.prune": pruneAction,
|
|
141
151
|
"chat.open": openAction,
|
|
142
152
|
"chat.say": sayAction,
|
|
143
153
|
"chat.quiet": quietAction,
|
|
@@ -149,6 +159,8 @@ export const chat = definePlugin({
|
|
|
149
159
|
"chat.import": importAction,
|
|
150
160
|
},
|
|
151
161
|
events: { "turn.requested": turnRequested },
|
|
162
|
+
// Files uploaded to send that no message sent within a day go.
|
|
163
|
+
schedules: { "chat.prune": { every: "1h", call: "chat.prune", input: {} } },
|
|
152
164
|
resources: {
|
|
153
165
|
// Conversations by title on Usage.
|
|
154
166
|
usageNames: { thread: { tag: "tags.thread", collection: "thread", field: "title" } },
|
|
@@ -182,14 +194,20 @@ export const chat = definePlugin({
|
|
|
182
194
|
"chat.failed": failedProcessor,
|
|
183
195
|
},
|
|
184
196
|
// Chat's records change through its Actions, never written directly from outside: what's said
|
|
185
|
-
// (who said it), what a turn is doing, a conversation's state, its files, what was shown.
|
|
186
|
-
|
|
197
|
+
// (who said it), what a turn is doing, a conversation's state, its files, what was shown. A file
|
|
198
|
+
// not sent yet (a draft) is its sender's alone, wherever it is: a rule on every read and write
|
|
199
|
+
// of files, that never lets anyone read them directly where no other rule does (`direct`).
|
|
200
|
+
guard: (actor, { collection, access, direct }) => {
|
|
187
201
|
if (direct && access === "write" && CHAT_RECORDS.includes(collection)) {
|
|
188
202
|
throw failure("forbidden", `"${collection}" changes through chat's Actions (chat.send…).`, {
|
|
189
203
|
public: true,
|
|
190
204
|
});
|
|
191
205
|
}
|
|
192
|
-
|
|
206
|
+
if (direct || collection !== "file")
|
|
207
|
+
return undefined;
|
|
208
|
+
const by = drafter(actor);
|
|
209
|
+
const sent = { draft: { $exists: false } };
|
|
210
|
+
return by ? { $or: [sent, { draft: by }] } : sent;
|
|
193
211
|
},
|
|
194
212
|
// Files people sent, as whoever asks reaches them (or by a link signed for one).
|
|
195
213
|
routes: { "/files/*": serveFile },
|
|
@@ -109,10 +109,16 @@ export const commands = {
|
|
|
109
109
|
const name = path.split("/").at(-1);
|
|
110
110
|
const state = await term.state();
|
|
111
111
|
const here = state.open?.kind === "thread" ? state.open.item._id : undefined;
|
|
112
|
+
// Uploaded first, on its own; the message sends it by id.
|
|
113
|
+
const { id } = await term.runtime.call("chat.attach", {
|
|
114
|
+
name,
|
|
115
|
+
type: typeOf(name),
|
|
116
|
+
data: btoa(binary),
|
|
117
|
+
});
|
|
112
118
|
const sent = await send(term, {
|
|
113
119
|
text: words.join(" ") || `Here's ${name}.`,
|
|
114
120
|
from: term.me,
|
|
115
|
-
files: [{
|
|
121
|
+
files: [{ id }],
|
|
116
122
|
...(here ? { thread: here } : state.space ? { in: state.space } : {}),
|
|
117
123
|
});
|
|
118
124
|
if (sent.thread !== here)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app's `contactSend` hooks: what lets a contact's message in (a web
|
|
3
|
+
* line's limits, the files it takes, its visitor's own chat), and each file
|
|
4
|
+
* it uploads to send (`chat.attach`), counted as a message to nobody.
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from "../../../../runtime/mod.js";
|
|
7
|
+
/**
|
|
8
|
+
* A `contactSend` resource: the Action that lets a contact's message in,
|
|
9
|
+
* asked as the contact before anything's sent, with where it goes (`thread`,
|
|
10
|
+
* when it names one), what it carries (each file's name, media type and
|
|
11
|
+
* size), and `to: []` when it goes to nobody (no agent answers it: no turn
|
|
12
|
+
* to pay for). Each file a contact uploads to send is asked first too, as a
|
|
13
|
+
* message to nobody carrying it. It refuses it (a limit), or answers where it goes when it names no
|
|
14
|
+
* chat (`thread`: the contact's own) and `transcribe: false` when its audio
|
|
15
|
+
* goes untranscribed.
|
|
16
|
+
*/
|
|
17
|
+
export type ContactSend = {
|
|
18
|
+
action: string;
|
|
19
|
+
};
|
|
20
|
+
/** What the app's `contactSend` hooks say of a contact's message, each in turn. */
|
|
21
|
+
export declare function letIn(ctx: Pick<Context, "resources" | "call">, asked: {
|
|
22
|
+
thread?: string;
|
|
23
|
+
files: {
|
|
24
|
+
name: string;
|
|
25
|
+
type?: string;
|
|
26
|
+
size: number;
|
|
27
|
+
}[];
|
|
28
|
+
to?: [];
|
|
29
|
+
}): Promise<{
|
|
30
|
+
thread?: string;
|
|
31
|
+
transcribe?: false;
|
|
32
|
+
}>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** What the app's `contactSend` hooks say of a contact's message, each in turn. */
|
|
2
|
+
export async function letIn(ctx, asked) {
|
|
3
|
+
const hooks = Object.values((ctx.resources.contactSend ?? {}));
|
|
4
|
+
let said = {};
|
|
5
|
+
for (const hook of hooks) {
|
|
6
|
+
const answer = await ctx.call(hook.action, {
|
|
7
|
+
...(asked.thread ? { thread: asked.thread } : {}),
|
|
8
|
+
files: asked.files,
|
|
9
|
+
...(asked.to ? { to: asked.to } : {}),
|
|
10
|
+
});
|
|
11
|
+
said = {
|
|
12
|
+
...said,
|
|
13
|
+
...(typeof answer?.thread === "string" && !said.thread ? { thread: answer.thread } : {}),
|
|
14
|
+
...(answer?.transcribe === false ? { transcribe: false } : {}),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return said;
|
|
18
|
+
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Files chosen to send: each read (base64) and uploaded on its own
|
|
3
|
+
* (`chat.attach`) as it's chosen, with a preview for images; the message
|
|
4
|
+
* sends them by their uploads' ids.
|
|
5
|
+
*/
|
|
2
6
|
export type Attached = {
|
|
3
7
|
id: string;
|
|
4
8
|
name: string;
|
|
5
9
|
type: string;
|
|
6
10
|
size: number;
|
|
7
|
-
/**
|
|
8
|
-
|
|
11
|
+
/** Read, and being uploaded. */
|
|
12
|
+
read?: true;
|
|
13
|
+
/** Uploaded: the id the message sends it by. */
|
|
14
|
+
uploaded?: string;
|
|
9
15
|
/** An image's preview (an object URL), until it's sent or removed. */
|
|
10
16
|
preview?: string;
|
|
11
17
|
/** Why it can't go. */
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Files chosen to send: each read (base64) and uploaded on its own
|
|
3
|
+
* (`chat.attach`) as it's chosen, with a preview for images; the message
|
|
4
|
+
* sends them by their uploads' ids.
|
|
5
|
+
*/
|
|
2
6
|
import { formatNumber } from "../../../../../hosts/web/words.js";
|
|
3
7
|
import { say } from "./words.js";
|
|
4
8
|
/** How many files a message takes, and how large each may be. */
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
import { type ReactNode } from "react";
|
|
22
22
|
import type { ComposerNote, RefusalView } from "../../shared/types.js";
|
|
23
23
|
import { type Mentionable } from "./agents.js";
|
|
24
|
-
/** A file
|
|
25
|
-
export type
|
|
24
|
+
/** A file to upload (`chat.attach`); a voice message's says how long it runs, and its peaks. */
|
|
25
|
+
export type Upload = {
|
|
26
26
|
name: string;
|
|
27
27
|
type: string;
|
|
28
28
|
data: string;
|
|
@@ -31,11 +31,22 @@ export type Sent = {
|
|
|
31
31
|
peaks?: number[];
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
|
+
/** A file as `chat.send` takes it: one uploaded, by id. */
|
|
35
|
+
export type Sent = {
|
|
36
|
+
id: string;
|
|
37
|
+
};
|
|
34
38
|
/** How it's sent: `transcribe: false` sends audio without a transcript. */
|
|
35
39
|
export type SendOptions = {
|
|
36
40
|
transcribe?: boolean;
|
|
37
41
|
};
|
|
38
42
|
export declare function Composer(props: {
|
|
43
|
+
/**
|
|
44
|
+
* Uploads a file to send (`chat.attach`), on its own: each as it's chosen,
|
|
45
|
+
* so sending is instant and a file that can't go says so alone.
|
|
46
|
+
*/
|
|
47
|
+
attach(file: Upload): Promise<{
|
|
48
|
+
id: string;
|
|
49
|
+
}>;
|
|
39
50
|
send(text: string, files: Sent[], options: SendOptions): Promise<void>;
|
|
40
51
|
/** Agents writing right now. */
|
|
41
52
|
working?: string[];
|
|
@@ -58,6 +58,8 @@ export function Composer(props) {
|
|
|
58
58
|
const picker = useRef(null);
|
|
59
59
|
const mic = useRef(null);
|
|
60
60
|
const previews = useRef(new Set());
|
|
61
|
+
/** Each recording's upload, once: sending it again (without a transcript) sends the same one. */
|
|
62
|
+
const voices = useRef(new WeakMap());
|
|
61
63
|
const id = useId();
|
|
62
64
|
const working = props.working ?? [];
|
|
63
65
|
const phase = recording?.phase;
|
|
@@ -94,12 +96,42 @@ export function Composer(props) {
|
|
|
94
96
|
if (f.preview)
|
|
95
97
|
previews.current.add(f.preview);
|
|
96
98
|
setFiles((now) => [...now, ...fresh]);
|
|
99
|
+
const change = (id, to) => setFiles((now) => now.map((x) => x.id === id ? { ...x, ...to } : x));
|
|
97
100
|
fresh.forEach((f, i) => {
|
|
98
101
|
if (f.error)
|
|
99
102
|
return;
|
|
100
|
-
|
|
103
|
+
// Read, then uploaded at once: what's sent later is its id.
|
|
104
|
+
read(picked[i]).then(async (data) => {
|
|
105
|
+
change(f.id, { read: true });
|
|
106
|
+
try {
|
|
107
|
+
const { id } = await props.attach({ name: f.name, type: f.type, data });
|
|
108
|
+
change(f.id, { uploaded: id });
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
change(f.id, { error: message(e) || say("couldntUpload") });
|
|
112
|
+
}
|
|
113
|
+
}, () => change(f.id, { error: say("couldntRead") }));
|
|
101
114
|
});
|
|
102
115
|
};
|
|
116
|
+
/** A recording, uploaded once (see `voices`). */
|
|
117
|
+
const upload = (voice) => {
|
|
118
|
+
let uploaded = voices.current.get(voice.blob);
|
|
119
|
+
if (!uploaded) {
|
|
120
|
+
uploaded = read(voice.blob).then((data) => props.attach({
|
|
121
|
+
name: voice.name,
|
|
122
|
+
type: voice.type,
|
|
123
|
+
data,
|
|
124
|
+
voice: {
|
|
125
|
+
duration: voice.duration,
|
|
126
|
+
...(voice.peaks.length ? { peaks: voice.peaks } : {}),
|
|
127
|
+
},
|
|
128
|
+
})).then(({ id }) => id);
|
|
129
|
+
voices.current.set(voice.blob, uploaded);
|
|
130
|
+
// One that failed is tried again next time.
|
|
131
|
+
uploaded.catch(() => voices.current.delete(voice.blob));
|
|
132
|
+
}
|
|
133
|
+
return uploaded;
|
|
134
|
+
};
|
|
103
135
|
const typeOn = () => requestAnimationFrame(() => fine() && area.current?.focus());
|
|
104
136
|
const remove = (gone) => {
|
|
105
137
|
if (gone.preview)
|
|
@@ -119,8 +151,8 @@ export function Composer(props) {
|
|
|
119
151
|
setFailed(undefined);
|
|
120
152
|
requestAnimationFrame(() => fine() ? area.current?.focus() : mic.current?.querySelector("button")?.focus());
|
|
121
153
|
};
|
|
122
|
-
const
|
|
123
|
-
const blocked = !!sending ||
|
|
154
|
+
const uploading = files.some((f) => !f.uploaded && !f.error);
|
|
155
|
+
const blocked = !!sending || uploading || files.some((f) => f.error);
|
|
124
156
|
const ready = !blocked && !live && (!!text.trim() || files.length > 0 || !!take);
|
|
125
157
|
// The `@name` being typed, and the agents it could be.
|
|
126
158
|
const typing = props.agents?.length && !live && !sending ? typingAt(text, caret) : undefined;
|
|
@@ -162,18 +194,9 @@ export function Composer(props) {
|
|
|
162
194
|
setFailed(undefined);
|
|
163
195
|
setRefused(undefined);
|
|
164
196
|
try {
|
|
165
|
-
const sent = files.map((f) => ({
|
|
166
|
-
if (voice)
|
|
167
|
-
sent.unshift({
|
|
168
|
-
name: voice.name,
|
|
169
|
-
type: voice.type,
|
|
170
|
-
data: await read(voice.blob),
|
|
171
|
-
voice: {
|
|
172
|
-
duration: voice.duration,
|
|
173
|
-
...(voice.peaks.length ? { peaks: voice.peaks } : {}),
|
|
174
|
-
},
|
|
175
|
-
});
|
|
176
|
-
}
|
|
197
|
+
const sent = files.map((f) => ({ id: f.uploaded }));
|
|
198
|
+
if (voice)
|
|
199
|
+
sent.unshift({ id: await upload(voice) });
|
|
177
200
|
await props.send(text.trim(), sent, options);
|
|
178
201
|
for (const f of files)
|
|
179
202
|
if (f.preview)
|
|
@@ -325,7 +348,8 @@ export function Composer(props) {
|
|
|
325
348
|
}, onDrop: drop, children: [files.length
|
|
326
349
|
? (_jsx("ul", { className: "chat-attached", "aria-label": say("filesToSend"), children: files.map((f) => (_jsxs("li", { className: `chat-attached-file${f.error ? " chat-attached-bad" : ""}`, children: [f.preview
|
|
327
350
|
? _jsx("img", { src: f.preview, alt: "" })
|
|
328
|
-
: (_jsx("span", { className: "chat-attached-icon", children: _jsx(Icon, { name: audio(f.type) ? "waveform" : "file", size: 16 }) })), _jsxs("span", { className: "chat-attached-name", children: [_jsx("span", { children: f.name }), _jsx("small", { children: f.error ??
|
|
351
|
+
: (_jsx("span", { className: "chat-attached-icon", children: _jsx(Icon, { name: audio(f.type) ? "waveform" : "file", size: 16 }) })), _jsxs("span", { className: "chat-attached-name", children: [_jsx("span", { children: f.name }), _jsx("small", { children: f.error ??
|
|
352
|
+
(f.uploaded ? size(f.size) : f.read ? say("uploading") : say("reading")) })] }), _jsx(IconButton, { icon: "close", size: "sm", label: say("remove", { name: f.name }), onClick: () => remove(f), disabled: !!sending })] }, f.id))) }))
|
|
329
353
|
: null, recording
|
|
330
354
|
? (_jsx(Recorder, { state: recording, busy: !!sending, focus: true, onStop: () => void recorder?.stop(), onSend: () => void submit(), onDelete: dropRecording, onRestart: startRecording }))
|
|
331
355
|
: null, _jsxs("div", { className: "chat-box-text", hidden: live, children: [_jsx("label", { className: "copilotz-sr", htmlFor: id, children: say("message") }), _jsx(Textarea, { id: id, ref: area, rows: 1, bare: true, autoGrow: true, className: "chat-input", value: text, placeholder: take ? say("addMessage") : props.placeholder ?? say("message"), enterKeyHint: "send", readOnly: !!sending, "aria-autocomplete": props.agents?.length ? "list" : undefined, "aria-controls": props.agents?.length ? list : undefined, "aria-activedescendant": listing ? optionId(list, active) : undefined, onChange: (event) => {
|
|
@@ -119,7 +119,7 @@ export const conversationView = (t, ctx) => {
|
|
|
119
119
|
});
|
|
120
120
|
}), live.map((l) => ctx.show("web.live", l, { thread: t._id, who }))] }), over.length
|
|
121
121
|
? (_jsx("div", { className: "chat-asks", children: _jsx(Over, { entries: over, thread: t._id, space: thread.in, side: subthreads, live: working }) }))
|
|
122
|
-
: null, _jsx(Composer, { send: async (text, files, options) => {
|
|
122
|
+
: null, _jsx(Composer, { attach: (file) => ctx.call("chat.attach", { ...file, thread: t._id }), send: async (text, files, options) => {
|
|
123
123
|
await ctx.call("chat.send", {
|
|
124
124
|
thread: t._id,
|
|
125
125
|
...(text ? { text } : {}),
|
|
@@ -28,7 +28,7 @@ export const homeView = (_, ctx) => {
|
|
|
28
28
|
if (here && space === null) {
|
|
29
29
|
return (_jsxs("section", { className: "chat chat-missing", "aria-labelledby": "chat-home-title", children: [_jsx("style", { href: "chat-web", precedence: "copilotz", children: STYLE }), _jsx(Title, { text: say("notYourSpaceTitle") }), _jsx(EmptyState, { icon: "lock", heading: "h1", id: "chat-home-title", title: say("notInSpace"), children: say("notInSpaceBody") })] }));
|
|
30
30
|
}
|
|
31
|
-
return (_jsxs("section", { className: "chat chat-home", "aria-labelledby": "chat-home-title", children: [_jsx("style", { href: "chat-web", precedence: "copilotz", children: STYLE }), _jsx(Title, { text: shared ? space.name : say("newChat") }), _jsxs("div", { className: "chat-home-body", children: [tops.length ? _jsx("div", { className: "chat-home-top", children: tops }) : null, _jsxs("div", { className: "chat-home-hero", children: [_jsx(Logo, { size: 56 }), _jsx("h1", { id: "chat-home-title", children: greeting(new Date().getHours(), name) }), _jsx("p", { children: shared ? say.nodes("workingIn", { space: _jsx("b", { children: space.name }) }) : say("helpWith") })] }), _jsx(Composer, { initial: to && team?.here.includes(to) ? `@${to} ` : undefined, agents: team ? mentionable(team) : undefined, where: space ? space.kind === "personal" ? say("personal") : space.name : undefined, refusals: ctx.resources.refusals, notes: ctx.resources.composerNotes, place: here ? { in: here } : {}, send: async (text, files, options) => {
|
|
31
|
+
return (_jsxs("section", { className: "chat chat-home", "aria-labelledby": "chat-home-title", children: [_jsx("style", { href: "chat-web", precedence: "copilotz", children: STYLE }), _jsx(Title, { text: shared ? space.name : say("newChat") }), _jsxs("div", { className: "chat-home-body", children: [tops.length ? _jsx("div", { className: "chat-home-top", children: tops }) : null, _jsxs("div", { className: "chat-home-hero", children: [_jsx(Logo, { size: 56 }), _jsx("h1", { id: "chat-home-title", children: greeting(new Date().getHours(), name) }), _jsx("p", { children: shared ? say.nodes("workingIn", { space: _jsx("b", { children: space.name }) }) : say("helpWith") })] }), _jsx(Composer, { initial: to && team?.here.includes(to) ? `@${to} ` : undefined, agents: team ? mentionable(team) : undefined, where: space ? space.kind === "personal" ? say("personal") : space.name : undefined, refusals: ctx.resources.refusals, notes: ctx.resources.composerNotes, place: here ? { in: here } : {}, attach: (file) => ctx.call("chat.attach", file), send: async (text, files, options) => {
|
|
32
32
|
const sent = await ctx.call("chat.send", {
|
|
33
33
|
...(text ? { text } : {}),
|
|
34
34
|
...(here ? { in: here } : {}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const say: import("../../../../../hosts/web/words.js").Say<"to" | "cancel" | "result" | "close" | "input" | "retry" | "used" | "bytes" | "open" | "send" | "message" | "recorded" | "stop" | "writing" | "stopped" | "why" | "thinking" | "messages" | "transcript" | "conversation" | "download" | "share" | "couldntRead" | "tooShort" | "personal" | "tryAgain" | "yesterday" | "newChat" | "newChatHere" | "you" | "notInSpace" | "findSpace" | "create" | "remove" | "youLabel" | "namesAnd" | "greetingMorning" | "greetingMorningNamed" | "greetingAfternoon" | "greetingAfternoonNamed" | "greetingEvening" | "greetingEveningNamed" | "workingIn" | "helpWith" | "homePlaceholder" | "startsInSpace" | "startsInPersonal" | "notYourSpaceTitle" | "notInSpaceBody" | "notFoundTitle" | "missingTitle" | "missingBody" | "startNewChat" | "messageAgents" | "messageTheAgents" | "openSpace" | "inThisChat" | "chatMore" | "moveToSpace" | "sideThread" | "messageByTo" | "viaRoutine" | "viaAnswer" | "viaDelegated" | "viaOther" | "couldntAnswer" | "askedInSideThread" | "waitingOnAnswer" | "usesSources" | "copyReply" | "messaging" | "messaged" | "using" | "writingLabel" | "reconnecting" | "working" | "thinkingLabel" | "goesTo" | "stopToSendNow" | "connectionLostSr" | "retryingIn" | "retrying" | "retryNumber" | "newMessages" | "jumpToLatest" | "downloadFile" | "voiceMessage" | "showTranscript" | "noSpeech" | "pastedFile" | "overLimit" | "kilobytes" | "megabytes" | "sendMessage" | "addMessage" | "filesToSend" | "reading" | "agentsIn" | "agentsHere" | "attachFiles" | "recordVoice" | "suggestions" | "transcribingRecording" | "transcribingAudio" | "areWorking" | "stopping" | "keyEsc" | "keyEnter" | "keyShift" | "keysHint" | "yourRecording" | "recordAgain" | "deleteRecording" | "recordingsStopAt" | "recordingAria" | "timeLeft" | "ofMinutes" | "startingMic" | "sendNow" | "startingMicSr" | "recordingSr" | "micBlocked" | "micNotFound" | "micBusy" | "micCouldntStart" | "cantRecord" | "recordingStopped" | "cantRecordHere" | "couldntTranscribeRecording" | "couldntTranscribeAudio" | "sendAudioOnly" | "noChatsTitle" | "noChatsBody" | "searchChats" | "searchChatsLabel" | "noChatsMatch" | "latestAreHere" | "messageCount" | "rowMore" | "earlier" | "today" | "thisWeek" | "thisMonth" | "noChatsYet" | "latestChats" | "allChats" | "thisChat" | "thisChatGroup" | "moveThisChat" | "chats" | "inSpace" | "newChatIn" | "keywordSpace" | "keywordStart" | "keywordConversation" | "moveTitle" | "moveNote">;
|
|
1
|
+
export declare const say: import("../../../../../hosts/web/words.js").Say<"to" | "cancel" | "result" | "close" | "input" | "retry" | "used" | "bytes" | "open" | "send" | "message" | "recorded" | "stop" | "writing" | "stopped" | "why" | "thinking" | "messages" | "transcript" | "conversation" | "download" | "share" | "couldntRead" | "tooShort" | "personal" | "tryAgain" | "yesterday" | "newChat" | "newChatHere" | "you" | "notInSpace" | "findSpace" | "create" | "remove" | "youLabel" | "namesAnd" | "greetingMorning" | "greetingMorningNamed" | "greetingAfternoon" | "greetingAfternoonNamed" | "greetingEvening" | "greetingEveningNamed" | "workingIn" | "helpWith" | "homePlaceholder" | "startsInSpace" | "startsInPersonal" | "notYourSpaceTitle" | "notInSpaceBody" | "notFoundTitle" | "missingTitle" | "missingBody" | "startNewChat" | "messageAgents" | "messageTheAgents" | "openSpace" | "inThisChat" | "chatMore" | "moveToSpace" | "sideThread" | "messageByTo" | "viaRoutine" | "viaAnswer" | "viaDelegated" | "viaOther" | "couldntAnswer" | "askedInSideThread" | "waitingOnAnswer" | "usesSources" | "copyReply" | "messaging" | "messaged" | "using" | "writingLabel" | "reconnecting" | "working" | "thinkingLabel" | "goesTo" | "stopToSendNow" | "connectionLostSr" | "retryingIn" | "retrying" | "retryNumber" | "newMessages" | "jumpToLatest" | "downloadFile" | "voiceMessage" | "showTranscript" | "noSpeech" | "pastedFile" | "overLimit" | "kilobytes" | "megabytes" | "sendMessage" | "addMessage" | "filesToSend" | "reading" | "uploading" | "couldntUpload" | "agentsIn" | "agentsHere" | "attachFiles" | "recordVoice" | "suggestions" | "transcribingRecording" | "transcribingAudio" | "areWorking" | "stopping" | "keyEsc" | "keyEnter" | "keyShift" | "keysHint" | "yourRecording" | "recordAgain" | "deleteRecording" | "recordingsStopAt" | "recordingAria" | "timeLeft" | "ofMinutes" | "startingMic" | "sendNow" | "startingMicSr" | "recordingSr" | "micBlocked" | "micNotFound" | "micBusy" | "micCouldntStart" | "cantRecord" | "recordingStopped" | "cantRecordHere" | "couldntTranscribeRecording" | "couldntTranscribeAudio" | "sendAudioOnly" | "noChatsTitle" | "noChatsBody" | "searchChats" | "searchChatsLabel" | "noChatsMatch" | "latestAreHere" | "messageCount" | "rowMore" | "earlier" | "today" | "thisWeek" | "thisMonth" | "noChatsYet" | "latestChats" | "allChats" | "thisChat" | "thisChatGroup" | "moveThisChat" | "chats" | "inSpace" | "newChatIn" | "keywordSpace" | "keywordStart" | "keywordConversation" | "moveTitle" | "moveNote">;
|
|
@@ -100,7 +100,9 @@ export const say = defineWords("chat", {
|
|
|
100
100
|
addMessage: "Add a message, or just send it",
|
|
101
101
|
filesToSend: "Files to send",
|
|
102
102
|
reading: "Reading…",
|
|
103
|
+
uploading: "Uploading…",
|
|
103
104
|
couldntRead: "Couldn't read it",
|
|
105
|
+
couldntUpload: "Couldn't upload it",
|
|
104
106
|
remove: "Remove {name}",
|
|
105
107
|
agentsIn: "Agents in {space}",
|
|
106
108
|
agentsHere: "Agents here",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The computer program's version, as `computer.info` and `--version` say it, and its builds are named. */
|
|
2
|
-
export declare const VERSION = "1.0.0-rc.
|
|
2
|
+
export declare const VERSION = "1.0.0-rc.30";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The computer program's version, as `computer.info` and `--version` say it, and its builds are named. */
|
|
2
|
-
export const VERSION = "1.0.0-rc.
|
|
2
|
+
export const VERSION = "1.0.0-rc.30";
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* ```ts
|
|
16
16
|
* plugins: [...plugins, await computerDownloads()]
|
|
17
|
-
* plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.
|
|
17
|
+
* plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.30" })]
|
|
18
18
|
* plugins: [...plugins, await computerDownloads({ url: "https://downloads.example.com/computer/" })]
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export const presets = {
|
|
2
2
|
chat: {
|
|
3
3
|
title: "Chat",
|
|
4
|
-
description: "Send messages to the agents here, stop a reply, and read the conversations.",
|
|
4
|
+
description: "Send messages (and files) to the agents here, stop a reply, and read the conversations.",
|
|
5
5
|
scope: {
|
|
6
|
-
call: ["chat.send", "chat.stop"],
|
|
6
|
+
call: ["chat.send", "chat.attach", "chat.stop"],
|
|
7
7
|
query: ["thread.recent", "message.conversation"],
|
|
8
8
|
},
|
|
9
9
|
order: 10,
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
* marked read (with "typing…") and becomes `chat.send`, as them, in
|
|
20
20
|
* their WhatsApp conversation, in the space they chose (their Personal
|
|
21
21
|
* space unless they said otherwise). Photos, documents, video and voice
|
|
22
|
-
* notes come as its files
|
|
22
|
+
* notes come as its files, each uploaded as them first (`chat.attach`;
|
|
23
|
+
* chat transcribes audio as it's sent). A reply
|
|
23
24
|
* quoting an agent's message, or one sent while an agent waits on their
|
|
24
25
|
* answer there, answers it. `/new`, `/space` and `/help` are commands
|
|
25
26
|
* (see shared/commands.ts).
|
|
@@ -111,10 +111,10 @@ async function customer(ctx, on, received, phone, event) {
|
|
|
111
111
|
const contact = await contactOf(ctx, on, received, phone, event);
|
|
112
112
|
await markRead(on.graph, message.id, true).catch(() => { });
|
|
113
113
|
const lines = CUSTOMERS[on.number.language ?? "en"];
|
|
114
|
-
const
|
|
114
|
+
const as = ctx.as({ kind: "contact", id: contact });
|
|
115
|
+
const brings = await broughtBy(ctx, on, from, message, as, lines);
|
|
115
116
|
if (!brings)
|
|
116
117
|
return;
|
|
117
|
-
const as = ctx.as({ kind: "contact", id: contact });
|
|
118
118
|
// Answered once they've been quiet a moment: a burst of short messages gets one answer.
|
|
119
119
|
const quiet = Math.round((on.number.quiet ?? QUIET) * 1000);
|
|
120
120
|
const sending = (thread) => written(ctx, on, as, `${CONTACT}${contact}`, thread, message, {
|
|
@@ -220,23 +220,32 @@ async function chatFor(ctx, on, { from, name, contact }, event) {
|
|
|
220
220
|
}
|
|
221
221
|
/**
|
|
222
222
|
* What a message brings to say: its words, and its file (fetched from
|
|
223
|
-
* Meta
|
|
224
|
-
*
|
|
223
|
+
* Meta, and uploaded to send as whoever says it, `as`). Undefined when
|
|
224
|
+
* there's nothing to pass on, once the phone was told why (a file too
|
|
225
|
+
* large, a kind of message agents can't read).
|
|
225
226
|
*/
|
|
226
|
-
async function broughtBy(ctx, on, from, message, lines) {
|
|
227
|
+
async function broughtBy(ctx, on, from, message, as, lines) {
|
|
227
228
|
const words = wordsOf(message).trim();
|
|
228
229
|
const media = mediaOf(message);
|
|
229
230
|
const files = [];
|
|
230
231
|
if (media) {
|
|
231
232
|
try {
|
|
232
233
|
const got = await fetchMedia(on.graph, media.id, MAX_FILE_BYTES);
|
|
233
|
-
|
|
234
|
+
const { id } = await as.call("chat.attach", {
|
|
235
|
+
name: media.name,
|
|
236
|
+
type: got.type || media.type,
|
|
237
|
+
data: got.data,
|
|
238
|
+
});
|
|
239
|
+
files.push({ id });
|
|
234
240
|
}
|
|
235
241
|
catch (error) {
|
|
236
|
-
if (error.code
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
242
|
+
if (error.code === "too_large") {
|
|
243
|
+
await say(ctx, on, from, lines?.large ?? `${error.message} Send a smaller one, or a link to it.`);
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
if (await told(ctx, on, from, error, lines))
|
|
247
|
+
return undefined;
|
|
248
|
+
throw error;
|
|
240
249
|
}
|
|
241
250
|
}
|
|
242
251
|
if (!words && !files.length) {
|
|
@@ -292,7 +301,7 @@ async function linked(ctx, on, { from, message }, phone, event) {
|
|
|
292
301
|
const command = message.type === "text" ? commandOf(wordsOf(message).trim()) : undefined;
|
|
293
302
|
if (command)
|
|
294
303
|
return await commanded(ctx, on, from, phone, command);
|
|
295
|
-
const brings = await broughtBy(ctx, on, from, message);
|
|
304
|
+
const brings = await broughtBy(ctx, on, from, message, as);
|
|
296
305
|
if (!brings)
|
|
297
306
|
return;
|
|
298
307
|
const space = await spaceOf(ctx, person, phone.space);
|