copilotz 1.0.0-rc.20 → 1.0.0-rc.21
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 +417 -0
- package/README.md +295 -19
- package/hosts/orgs/mod.d.ts +4 -1
- package/hosts/orgs/mod.js +2 -2
- package/hosts/web/files.d.ts +6 -2
- package/hosts/web/files.js +36 -3
- package/hosts/web/node/mod.d.ts +1 -1
- package/hosts/web/node/mod.js +1 -1
- package/hosts/web/node/serve.d.ts +26 -0
- package/hosts/web/node/serve.js +23 -1
- package/hosts/web/routes.d.ts +28 -1
- package/hosts/web/routes.js +65 -10
- package/hosts/web/server.d.ts +5 -4
- package/hosts/web/server.js +1 -1
- package/package.json +2 -2
- package/plugins/access/accounts/collections/account.d.ts +2 -2
- package/plugins/access/contacts/actions/chat.d.ts +1 -0
- package/plugins/access/contacts/actions/chat.js +45 -0
- package/plugins/access/contacts/actions/forget.d.ts +1 -0
- package/plugins/access/contacts/actions/forget.js +56 -0
- package/plugins/access/contacts/actions/start.d.ts +1 -0
- package/plugins/access/contacts/actions/start.js +50 -0
- package/plugins/access/contacts/collections/contact.d.ts +81 -0
- package/plugins/access/contacts/collections/contact.js +58 -0
- package/plugins/access/contacts/contract.d.ts +10 -0
- package/plugins/access/contacts/contract.js +10 -0
- package/plugins/access/contacts/mod.d.ts +27 -0
- package/plugins/access/contacts/mod.js +49 -0
- package/plugins/access/contacts/views/contact.d.ts +8 -0
- package/plugins/access/contacts/views/contact.js +25 -0
- package/plugins/access/contacts/web.d.ts +7 -0
- package/plugins/access/contacts/web.js +11 -0
- package/plugins/access/directory/collections/credit-code.d.ts +1 -1
- package/plugins/access/directory/collections/invite.d.ts +1 -1
- package/plugins/access/identity/mod.js +8 -6
- package/plugins/access/mod.d.ts +7 -1
- package/plugins/access/mod.js +7 -2
- package/plugins/access/spaces/actions/agents.js +12 -6
- package/plugins/access/spaces/actions/create.js +10 -1
- package/plugins/access/spaces/actions/invitation.js +5 -2
- package/plugins/access/spaces/actions/keep.d.ts +1 -0
- package/plugins/access/spaces/actions/keep.js +55 -0
- package/plugins/access/spaces/actions/member.js +17 -4
- package/plugins/access/spaces/actions/rename.js +4 -0
- package/plugins/access/spaces/collections/member.d.ts +1 -1
- package/plugins/access/spaces/collections/request.d.ts +1 -1
- package/plugins/access/spaces/collections/space.d.ts +9 -0
- package/plugins/access/spaces/collections/space.js +2 -0
- package/plugins/access/spaces/contract.d.ts +4 -3
- package/plugins/access/spaces/contract.js +1 -1
- package/plugins/access/spaces/mod.d.ts +7 -1
- package/plugins/access/spaces/mod.js +8 -1
- package/plugins/access/spaces/resources/tools.d.ts +0 -5
- package/plugins/access/spaces/resources/tools.js +11 -1
- package/plugins/access/spaces/shared/agents.js +2 -2
- package/plugins/access/spaces/shared/can.d.ts +18 -3
- package/plugins/access/spaces/shared/can.js +32 -5
- package/plugins/access/spaces/shared/declared.d.ts +21 -0
- package/plugins/access/spaces/shared/declared.js +8 -0
- package/plugins/access/spaces/shared/labels.d.ts +7 -1
- package/plugins/access/spaces/shared/labels.js +56 -8
- package/plugins/access/spaces/shared/managers.js +2 -2
- package/plugins/access/spaces/shared/names.d.ts +9 -5
- package/plugins/access/spaces/shared/names.js +36 -19
- package/plugins/access/spaces/shared/reach.d.ts +20 -6
- package/plugins/access/spaces/shared/reach.js +62 -20
- package/plugins/access/spaces/shared/rules.d.ts +10 -5
- package/plugins/access/spaces/shared/rules.js +35 -10
- package/plugins/access/spaces/shared/seat.d.ts +3 -2
- package/plugins/access/spaces/shared/seat.js +9 -2
- package/plugins/access/spaces/views/where.d.ts +4 -2
- package/plugins/access/spaces/views/where.js +9 -0
- package/plugins/access/spaces/web.js +1 -1
- package/plugins/access/web.d.ts +1 -0
- package/plugins/access/web.js +1 -0
- package/plugins/agents/chat/actions/erase.d.ts +1 -0
- package/plugins/agents/chat/actions/erase.js +51 -0
- package/plugins/agents/chat/actions/open.d.ts +1 -0
- package/plugins/agents/chat/actions/open.js +49 -0
- package/plugins/agents/chat/actions/quiet.d.ts +1 -0
- package/plugins/agents/chat/actions/quiet.js +33 -0
- package/plugins/agents/chat/actions/say.d.ts +1 -0
- package/plugins/agents/chat/actions/say.js +82 -0
- package/plugins/agents/chat/actions/send.js +57 -19
- package/plugins/agents/chat/actions/shown.d.ts +1 -0
- package/plugins/agents/chat/actions/shown.js +35 -0
- package/plugins/agents/chat/collections/intent.d.ts +124 -0
- package/plugins/agents/chat/collections/intent.js +52 -0
- package/plugins/agents/chat/collections/message.d.ts +74 -1
- package/plugins/agents/chat/collections/message.js +23 -1
- package/plugins/agents/chat/collections/shown.d.ts +105 -0
- package/plugins/agents/chat/collections/shown.js +34 -0
- package/plugins/agents/chat/contract.d.ts +15 -7
- package/plugins/agents/chat/contract.js +7 -1
- package/plugins/agents/chat/mod.d.ts +20 -2
- package/plugins/agents/chat/mod.js +43 -4
- package/plugins/agents/chat/processors/failed.js +15 -5
- package/plugins/agents/chat/processors/turn.d.ts +1 -1
- package/plugins/agents/chat/processors/turn.js +95 -35
- package/plugins/agents/chat/shared/delivery.d.ts +16 -2
- package/plugins/agents/chat/shared/delivery.js +62 -7
- package/plugins/agents/chat/shared/send.d.ts +1 -3
- package/plugins/agents/chat/shared/send.js +2 -9
- package/plugins/agents/chat/shared/tools.d.ts +33 -0
- package/plugins/agents/chat/shared/tools.js +28 -0
- package/plugins/agents/chat/shared/types.d.ts +59 -1
- package/plugins/agents/chat/views/message.d.ts +4 -2
- package/plugins/agents/chat/views/message.js +22 -4
- package/plugins/agents/chat/views/prompt.js +38 -4
- package/plugins/agents/history/collections/outline.d.ts +1 -1
- package/plugins/agents/history/collections/summary.d.ts +1 -1
- package/plugins/agents/history/mod.js +2 -1
- package/plugins/agents/history/processors/erase.d.ts +3 -0
- package/plugins/agents/history/processors/erase.js +11 -0
- package/plugins/agents/memory/mod.js +2 -1
- package/plugins/agents/memory/processors/extract.d.ts +1 -1
- package/plugins/agents/memory/processors/extract.js +5 -0
- package/plugins/agents/memory/resources/tools.js +1 -1
- package/plugins/agents/memory/shared/settings.d.ts +7 -2
- package/plugins/agents/memory/shared/settings.js +9 -1
- package/plugins/agents/routines/collections/routine.d.ts +1 -1
- package/plugins/agents/routines/collections/run.d.ts +1 -1
- package/plugins/compute/apps/collections/app.d.ts +2 -2
- package/plugins/compute/cloud/resources/tools.js +3 -3
- package/plugins/compute/computers/collections/approval.d.ts +2 -2
- package/plugins/compute/computers/collections/grant.d.ts +1 -1
- package/plugins/compute/computers/collections/preview.d.ts +2 -2
- 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/compute/computers/shared/wake.d.ts +1 -1
- package/plugins/compute/computers/shared/wake.js +17 -0
- package/plugins/interfaces/api/collections/key.d.ts +1 -1
- package/plugins/interfaces/api/shared/events.js +5 -4
- package/plugins/interfaces/maintenance/actions/read.d.ts +4 -0
- package/plugins/interfaces/maintenance/actions/read.js +76 -0
- package/plugins/interfaces/maintenance/actions/write.d.ts +4 -0
- package/plugins/interfaces/maintenance/actions/write.js +64 -0
- package/plugins/interfaces/maintenance/contract.d.ts +60 -0
- package/plugins/interfaces/maintenance/contract.js +2 -0
- package/plugins/interfaces/maintenance/mod.d.ts +52 -0
- package/plugins/interfaces/maintenance/mod.js +66 -0
- package/plugins/interfaces/maintenance/resources/routes.d.ts +71 -0
- package/plugins/interfaces/maintenance/resources/routes.js +457 -0
- package/plugins/interfaces/maintenance/shared/ops.d.ts +4 -0
- package/plugins/interfaces/maintenance/shared/ops.js +19 -0
- package/plugins/interfaces/mcp/actions/call.d.ts +11 -0
- package/plugins/interfaces/mcp/actions/call.js +304 -0
- package/plugins/interfaces/mcp/actions/prune.d.ts +1 -0
- package/plugins/interfaces/mcp/actions/prune.js +18 -0
- package/plugins/interfaces/mcp/collections/closed.d.ts +23 -0
- package/plugins/interfaces/mcp/collections/closed.js +17 -0
- package/plugins/interfaces/mcp/collections/rate.d.ts +27 -0
- package/plugins/interfaces/mcp/collections/rate.js +18 -0
- package/plugins/interfaces/mcp/collections/receipt.d.ts +46 -0
- package/plugins/interfaces/mcp/collections/receipt.js +46 -0
- package/plugins/interfaces/mcp/contract.d.ts +9 -0
- package/plugins/interfaces/mcp/contract.js +9 -0
- package/plugins/interfaces/mcp/mod.d.ts +84 -0
- package/plugins/interfaces/mcp/mod.js +122 -0
- package/plugins/interfaces/mcp/processors/closed.d.ts +13 -0
- package/plugins/interfaces/mcp/processors/closed.js +16 -0
- package/plugins/interfaces/mcp/resources/running.d.ts +21 -0
- package/plugins/interfaces/mcp/resources/running.js +36 -0
- package/plugins/interfaces/mcp/resources/server.d.ts +54 -0
- package/plugins/interfaces/mcp/resources/server.js +423 -0
- package/plugins/interfaces/mcp/resources/tools.d.ts +114 -0
- package/plugins/interfaces/mcp/resources/tools.js +324 -0
- package/plugins/interfaces/mcp/shared/caller.d.ts +45 -0
- package/plugins/interfaces/mcp/shared/caller.js +99 -0
- package/plugins/interfaces/mcp/shared/keys.d.ts +50 -0
- package/plugins/interfaces/mcp/shared/keys.js +53 -0
- package/plugins/interfaces/mcp/shared/settings.d.ts +187 -0
- package/plugins/interfaces/mcp/shared/settings.js +176 -0
- package/plugins/interfaces/mcp/views/offered.d.ts +20 -0
- package/plugins/interfaces/mcp/views/offered.js +20 -0
- package/plugins/interfaces/mod.d.ts +5 -1
- package/plugins/interfaces/mod.js +5 -1
- package/plugins/interfaces/terminal/actions/print.js +1 -1
- package/plugins/interfaces/terminal/actions/set.js +1 -1
- package/plugins/interfaces/terminal/collections/output.d.ts +1 -1
- package/plugins/interfaces/terminal/collections/shell.js +1 -1
- package/plugins/interfaces/voice/actions/block.d.ts +2 -0
- package/plugins/interfaces/voice/actions/block.js +74 -0
- package/plugins/interfaces/voice/actions/call.d.ts +19 -0
- package/plugins/interfaces/voice/actions/call.js +253 -0
- package/plugins/interfaces/voice/actions/hook.d.ts +5 -0
- package/plugins/interfaces/voice/actions/hook.js +225 -0
- package/plugins/interfaces/voice/actions/prune.d.ts +1 -0
- package/plugins/interfaces/voice/actions/prune.js +35 -0
- package/plugins/interfaces/voice/collections/blocked.d.ts +87 -0
- package/plugins/interfaces/voice/collections/blocked.js +34 -0
- package/plugins/interfaces/voice/collections/call.d.ts +279 -0
- package/plugins/interfaces/voice/collections/call.js +77 -0
- package/plugins/interfaces/voice/collections/phone.d.ts +74 -0
- package/plugins/interfaces/voice/collections/phone.js +26 -0
- package/plugins/interfaces/voice/contract.d.ts +14 -0
- package/plugins/interfaces/voice/contract.js +2 -0
- package/plugins/interfaces/voice/mod.d.ts +57 -0
- package/plugins/interfaces/voice/mod.js +118 -0
- package/plugins/interfaces/voice/processors/forget.d.ts +13 -0
- package/plugins/interfaces/voice/processors/forget.js +27 -0
- package/plugins/interfaces/voice/resources/relay.d.ts +77 -0
- package/plugins/interfaces/voice/resources/relay.js +428 -0
- package/plugins/interfaces/voice/resources/tools.d.ts +1 -0
- package/plugins/interfaces/voice/resources/tools.js +25 -0
- package/plugins/interfaces/voice/shared/caller.d.ts +27 -0
- package/plugins/interfaces/voice/shared/caller.js +38 -0
- package/plugins/interfaces/voice/shared/settings.d.ts +136 -0
- package/plugins/interfaces/voice/shared/settings.js +121 -0
- package/plugins/interfaces/voice/shared/signature.d.ts +11 -0
- package/plugins/interfaces/voice/shared/signature.js +34 -0
- package/plugins/interfaces/voice/views/call.d.ts +41 -0
- package/plugins/interfaces/voice/views/call.js +30 -0
- package/plugins/interfaces/voice/views/context.d.ts +9 -0
- package/plugins/interfaces/voice/views/context.js +14 -0
- package/plugins/interfaces/voice/views/message.d.ts +17 -0
- package/plugins/interfaces/voice/views/message.js +41 -0
- package/plugins/interfaces/whatsapp/actions/connect.js +3 -0
- package/plugins/interfaces/whatsapp/actions/disconnect.js +4 -1
- package/plugins/interfaces/whatsapp/actions/hook.js +27 -11
- package/plugins/interfaces/whatsapp/actions/set.d.ts +8 -0
- package/plugins/interfaces/whatsapp/actions/set.js +121 -0
- package/plugins/interfaces/whatsapp/collections/blocked.d.ts +29 -0
- package/plugins/interfaces/whatsapp/collections/blocked.js +22 -0
- package/plugins/interfaces/whatsapp/collections/code.d.ts +1 -1
- package/plugins/interfaces/whatsapp/collections/number.d.ts +90 -4
- package/plugins/interfaces/whatsapp/collections/number.js +36 -4
- package/plugins/interfaces/whatsapp/collections/phone.d.ts +13 -3
- package/plugins/interfaces/whatsapp/collections/phone.js +9 -3
- package/plugins/interfaces/whatsapp/collections/rate.d.ts +27 -0
- package/plugins/interfaces/whatsapp/collections/rate.js +13 -0
- package/plugins/interfaces/whatsapp/collections/sent.d.ts +24 -12
- package/plugins/interfaces/whatsapp/collections/sent.js +11 -7
- package/plugins/interfaces/whatsapp/collections/thread.d.ts +14 -6
- package/plugins/interfaces/whatsapp/collections/thread.js +7 -5
- package/plugins/interfaces/whatsapp/collections/typing.d.ts +70 -0
- package/plugins/interfaces/whatsapp/collections/typing.js +21 -0
- package/plugins/interfaces/whatsapp/contract.d.ts +27 -4
- package/plugins/interfaces/whatsapp/contract.js +34 -1
- package/plugins/interfaces/whatsapp/events/undelivered.d.ts +8 -0
- package/plugins/interfaces/whatsapp/events/undelivered.js +17 -0
- package/plugins/interfaces/whatsapp/mod.d.ts +28 -2
- package/plugins/interfaces/whatsapp/mod.js +65 -6
- package/plugins/interfaces/whatsapp/processors/forget.d.ts +6 -0
- package/plugins/interfaces/whatsapp/processors/forget.js +11 -0
- package/plugins/interfaces/whatsapp/processors/receive.d.ts +17 -3
- package/plugins/interfaces/whatsapp/processors/receive.js +264 -81
- package/plugins/interfaces/whatsapp/processors/reply.d.ts +25 -5
- package/plugins/interfaces/whatsapp/processors/reply.js +216 -20
- package/plugins/interfaces/whatsapp/processors/typing.d.ts +8 -0
- package/plugins/interfaces/whatsapp/processors/typing.js +25 -0
- package/plugins/interfaces/whatsapp/shared/customers.d.ts +13 -0
- package/plugins/interfaces/whatsapp/shared/customers.js +16 -0
- package/plugins/interfaces/whatsapp/shared/graph.d.ts +31 -6
- package/plugins/interfaces/whatsapp/shared/graph.js +117 -10
- package/plugins/interfaces/whatsapp/shared/media.d.ts +23 -0
- package/plugins/interfaces/whatsapp/shared/media.js +46 -0
- package/plugins/interfaces/whatsapp/shared/number.d.ts +19 -8
- package/plugins/interfaces/whatsapp/shared/number.js +64 -7
- package/plugins/interfaces/whatsapp/shared/parts.d.ts +94 -0
- package/plugins/interfaces/whatsapp/shared/parts.js +184 -0
- package/plugins/interfaces/whatsapp/shared/payload.d.ts +27 -1
- package/plugins/interfaces/whatsapp/shared/payload.js +36 -1
- package/plugins/interfaces/whatsapp/shared/settings.d.ts +49 -1
- package/plugins/interfaces/whatsapp/shared/settings.js +11 -0
- package/plugins/interfaces/whatsapp/views/message.d.ts +13 -0
- package/plugins/interfaces/whatsapp/views/message.js +13 -0
- package/plugins/interfaces/whatsapp/views/web/line.d.ts +24 -0
- package/plugins/interfaces/whatsapp/views/web/line.js +44 -0
- package/plugins/interfaces/whatsapp/views/web/space.d.ts +7 -5
- package/plugins/interfaces/whatsapp/views/web/space.js +17 -10
- package/plugins/interfaces/whatsapp/views/web/style.d.ts +1 -1
- package/plugins/interfaces/whatsapp/views/web/style.js +8 -0
- package/plugins/models/adapters/llm/anthropic.d.ts +1 -1
- package/plugins/models/adapters/llm/anthropic.js +28 -15
- package/plugins/models/adapters/llm/gemini.d.ts +1 -1
- package/plugins/models/adapters/llm/gemini.js +2 -1
- package/plugins/models/adapters/llm/openai-compatible.d.ts +1 -1
- package/plugins/models/adapters/llm/openai-compatible.js +2 -1
- package/plugins/models/adapters/llm/openai.d.ts +1 -1
- package/plugins/models/adapters/llm/openai.js +16 -4
- package/plugins/models/shared/types.d.ts +8 -0
- package/plugins/models/shared/types.js +10 -0
- package/runtime/actor.d.ts +6 -0
- package/runtime/actor.js +9 -4
- package/runtime/aggregate.js +8 -2
- package/runtime/blobs.d.ts +15 -12
- package/runtime/blobs.js +58 -11
- package/runtime/cache.d.ts +6 -0
- package/runtime/cache.js +19 -1
- package/runtime/define.d.ts +10 -0
- package/runtime/errors.d.ts +20 -2
- package/runtime/errors.js +7 -1
- package/runtime/executor.js +27 -11
- package/runtime/links.d.ts +31 -0
- package/runtime/links.js +60 -0
- package/runtime/maintain.d.ts +88 -0
- package/runtime/maintain.js +120 -0
- package/runtime/memory.js +7 -4
- package/runtime/mod.d.ts +6 -4
- package/runtime/mod.js +5 -2
- package/runtime/mongo.d.ts +13 -0
- package/runtime/mongo.js +39 -8
- package/runtime/observe.d.ts +2 -0
- package/runtime/observe.js +14 -10
- package/runtime/ops.d.ts +5 -0
- package/runtime/ops.js +10 -1
- package/runtime/owner.d.ts +18 -1
- package/runtime/owner.js +127 -61
- package/runtime/presence.d.ts +18 -0
- package/runtime/presence.js +25 -0
- package/runtime/registry.d.ts +5 -0
- package/runtime/registry.js +18 -0
- package/runtime/runtime.js +9 -3
- package/runtime/store.d.ts +48 -1
- package/runtime/wire.d.ts +1 -0
- package/runtime/wire.js +3 -1
- package/stores/blobs/files/mod.js +4 -2
- package/stores/blobs/gcs/mod.d.ts +3 -0
- package/stores/blobs/gcs/mod.js +6 -5
- package/stores/blobs/http/mod.d.ts +1 -1
- package/stores/blobs/http/mod.js +2 -1
- package/stores/latency/mod.js +5 -1
- package/stores/sql/postgres/maintenance.d.ts +24 -0
- package/stores/sql/postgres/maintenance.js +258 -0
- package/stores/sql/postgres/mod.d.ts +20 -4
- package/stores/sql/postgres/mod.js +363 -96
- package/stores/sql/postgres/update.js +3 -1
- package/stores/sql/shared/capped.d.ts +2 -0
- package/stores/sql/shared/capped.js +22 -0
- package/stores/sql/shared/rows.d.ts +14 -0
- package/stores/sql/shared/rows.js +29 -0
- package/stores/sql/shared/statement.d.ts +12 -0
- package/stores/sql/shared/statement.js +244 -0
- package/stores/sql/sqlite/apart.d.ts +11 -0
- package/stores/sql/sqlite/apart.js +219 -0
- package/stores/sql/sqlite/mod.d.ts +16 -2
- package/stores/sql/sqlite/mod.js +246 -51
- package/testing/mod.js +1 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A space's WhatsApp (kind `whatsapp.space`: its WhatsApp tab, item
|
|
3
3
|
* `{ _id }`, the space; spaces' `spaceTabs`): the number connected to it,
|
|
4
|
-
* what Meta knows it as and whether its answers can go out;
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* what Meta knows it as and whether its answers can go out; whether it's
|
|
5
|
+
* open to customers (see line.tsx); then your phone (linking it, or,
|
|
6
|
+
* linked, where your messages go). Those who manage the space connect a
|
|
7
|
+
* number (by hand, with what Meta's dashboard gives), see its webhook
|
|
8
|
+
* again, replace its token, open it to customers and disconnect it (but the
|
|
9
|
+
* app's own lines, which its settings keep). With
|
|
10
|
+
* none, it says what it's for, and who can connect one. In a side panel
|
|
9
11
|
* (`hints.mode: "panel"`), the same, compact.
|
|
10
12
|
*/
|
|
11
13
|
import { type ReactNode } from "react";
|
|
@@ -2,16 +2,19 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
/**
|
|
3
3
|
* A space's WhatsApp (kind `whatsapp.space`: its WhatsApp tab, item
|
|
4
4
|
* `{ _id }`, the space; spaces' `spaceTabs`): the number connected to it,
|
|
5
|
-
* what Meta knows it as and whether its answers can go out;
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* what Meta knows it as and whether its answers can go out; whether it's
|
|
6
|
+
* open to customers (see line.tsx); then your phone (linking it, or,
|
|
7
|
+
* linked, where your messages go). Those who manage the space connect a
|
|
8
|
+
* number (by hand, with what Meta's dashboard gives), see its webhook
|
|
9
|
+
* again, replace its token, open it to customers and disconnect it (but the
|
|
10
|
+
* app's own lines, which its settings keep). With
|
|
11
|
+
* none, it says what it's for, and who can connect one. In a side panel
|
|
10
12
|
* (`hints.mode: "panel"`), the same, compact.
|
|
11
13
|
*/
|
|
12
14
|
import { useState } from "react";
|
|
13
15
|
import { Badge, Button, Card, EmptyState, Icon, Menu, Notice, Skeleton, Time, } from "../../../../../hosts/web/mod.js";
|
|
14
16
|
import { ConnectDialog, DisconnectDialog, ReplaceDialog, WebhookDialog } from "./connect.js";
|
|
17
|
+
import { CustomerLine } from "./line.js";
|
|
15
18
|
import { YourPhone } from "./phone.js";
|
|
16
19
|
import { STYLE } from "./style.js";
|
|
17
20
|
export const whatsappView = (item, ctx) => {
|
|
@@ -22,9 +25,11 @@ export const whatsappView = (item, ctx) => {
|
|
|
22
25
|
const phones = ctx.db.collection("whatsapp_phone").find({}).value;
|
|
23
26
|
const codes = ctx.db.collection("whatsapp_code").find({}).value;
|
|
24
27
|
const spaces = ctx.db.collection("space").query("reached", {}).value;
|
|
28
|
+
// Who answers there: who a customer line's chats may go to.
|
|
29
|
+
const team = ctx.db.collection("thread").query("agents", { in: id }).value;
|
|
25
30
|
const compact = ctx.hints.mode === "panel";
|
|
26
31
|
const style = _jsx("style", { href: "whatsapp-web", precedence: "copilotz", children: STYLE });
|
|
27
|
-
if (!numbers || !phones || !codes || !spaces) {
|
|
32
|
+
if (!numbers || !phones || !codes || !spaces || !team) {
|
|
28
33
|
return (_jsxs("div", { className: "wa-tab", "aria-busy": "true", children: [style, _jsx(Skeleton, { height: compact ? 160 : 210, radius: "xl" })] }));
|
|
29
34
|
}
|
|
30
35
|
const space = spaces.find((s) => s._id === id);
|
|
@@ -38,9 +43,9 @@ export const whatsappView = (item, ctx) => {
|
|
|
38
43
|
.filter((s) => s.kind !== "personal" && !s.archived && s.can.includes("write"))
|
|
39
44
|
.map((s) => ({ _id: s._id, name: s.name })),
|
|
40
45
|
];
|
|
41
|
-
return (_jsxs(_Fragment, { children: [style, _jsx(WhatsApp, { space: space, numbers: numbers, phones: phones, codes: codes, places: places, personal: personal?._id, compact: compact, call: ctx.call }, space._id)] }));
|
|
46
|
+
return (_jsxs(_Fragment, { children: [style, _jsx(WhatsApp, { space: space, numbers: numbers, phones: phones, codes: codes, places: places, personal: personal?._id, team: team, compact: compact, call: ctx.call }, space._id)] }));
|
|
42
47
|
};
|
|
43
|
-
function WhatsApp({ space, numbers, phones, codes, places, personal, compact, call }) {
|
|
48
|
+
function WhatsApp({ space, numbers, phones, codes, places, personal, team, compact, call }) {
|
|
44
49
|
const [connecting, setConnecting] = useState(false);
|
|
45
50
|
const [hooked, setHooked] = useState();
|
|
46
51
|
const [replacing, setReplacing] = useState();
|
|
@@ -60,7 +65,7 @@ function WhatsApp({ space, numbers, phones, codes, places, personal, compact, ca
|
|
|
60
65
|
return (_jsxs("div", { className: `wa-tab${compact ? " wa-tab-compact" : ""}`, children: [numbers.length
|
|
61
66
|
? numbers.map((number) => (_jsxs(Card, { as: "section", padding: "none", className: "wa-number", children: [_jsxs("header", { className: "wa-number-head", children: [_jsx("span", { className: "wa-mark", "aria-hidden": "true", children: _jsx(Icon, { name: "chat", size: 20 }) }), _jsxs("div", { className: "wa-number-text", children: [_jsxs("h3", { className: "wa-number-phone", children: [number.phone, number.problem
|
|
62
67
|
? _jsx(Badge, { tone: "warning", children: "Needs attention" })
|
|
63
|
-
: _jsx(Badge, { tone: "success", children: "Connected" })] }), _jsxs("p", { className: "wa-number-meta", children: [number.name ? _jsx("span", { children: number.name }) : null, number.name ? _jsx("span", { "aria-hidden": "true", children: "\u00B7" }) : null, _jsxs("span", { children: ["WhatsApp, for everyone in ", space.kind === "personal" ? "Personal" : space.name] }), _jsx("span", { "aria-hidden": "true", children: "\u00B7" }), _jsxs("span", { children: ["connected ", _jsx(Time, { at: number.at })] })] })] }), manage
|
|
68
|
+
: _jsx(Badge, { tone: "success", children: "Connected" }), number.open ? _jsx(Badge, { tone: "info", children: "Open to customers" }) : null] }), _jsxs("p", { className: "wa-number-meta", children: [number.name ? _jsx("span", { children: number.name }) : null, number.name ? _jsx("span", { "aria-hidden": "true", children: "\u00B7" }) : null, _jsxs("span", { children: ["WhatsApp, for everyone in ", space.kind === "personal" ? "Personal" : space.name] }), _jsx("span", { "aria-hidden": "true", children: "\u00B7" }), _jsxs("span", { children: ["connected ", _jsx(Time, { at: number.at })] })] })] }), manage && !number.declared
|
|
64
69
|
? (_jsx(Menu, { label: `${number.phone}: settings`, align: "end", items: [
|
|
65
70
|
{
|
|
66
71
|
label: "Webhook",
|
|
@@ -84,7 +89,9 @@ function WhatsApp({ space, numbers, phones, codes, places, personal, compact, ca
|
|
|
84
89
|
? (_jsx(Notice, { className: "wa-problem", tone: "warning", title: "Agents' answers can't go out", action: manage
|
|
85
90
|
? (_jsx(Button, { size: "sm", onClick: () => setReplacing(number), children: "Replace its token" }))
|
|
86
91
|
: undefined, children: manage ? number.problem : "Those who manage this space have been told." }))
|
|
87
|
-
: null,
|
|
92
|
+
: null, space.kind === "personal" || (compact && !number.open)
|
|
93
|
+
? null
|
|
94
|
+
: (_jsxs("div", { className: "wa-customers", children: [_jsx("h4", { className: "wa-you-title", children: "Customers" }), _jsx(CustomerLine, { number: number, where: space.name, manage: manage && !compact && !number.declared, here: team.here, agents: team.agents, fallback: team.default[0], call: call })] })), _jsxs("div", { className: "wa-you", children: [_jsx("h4", { className: "wa-you-title", children: "Your phone" }), _jsx(YourPhone, { number: number, phone: phones.find((p) => p.number === number._id), code: codes.find((c) => c.number === number._id), places: places, personal: personal, call: call })] })] }, number._id)))
|
|
88
95
|
: empty, manage && !compact && numbers.length
|
|
89
96
|
? (_jsx("div", { children: _jsx(Button, { variant: "ghost", icon: "plus", onClick: () => setConnecting(true), children: "Connect another number" }) }))
|
|
90
97
|
: null, connect, _jsx(WebhookDialog, { number: hooked, onClose: () => setHooked(undefined), call: call }), _jsx(ReplaceDialog, { number: replacing, onClose: () => setReplacing(undefined), call: call }), _jsx(DisconnectDialog, { number: leaving, onClose: () => setLeaving(undefined), call: call })] }));
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* and connecting a number (what Meta gives, then its webhook). Only layout:
|
|
5
5
|
* the pieces are the toolkit's.
|
|
6
6
|
*/
|
|
7
|
-
export declare const STYLE = "\n.wa-tab { container: wa-tab / inline-size; display: grid; gap: 18px; }\n.wa-tab-compact { gap: 14px; }\n.wa-note { margin: 0; color: var(--muted-foreground); font-size: 13.5px; line-height: 1.55; }\n.wa-note code, .wa-tips code { font-size: .92em; }\n\n/* A number */\n.wa-number { display: grid; overflow: hidden; }\n.wa-number-head { display: flex; align-items: center; gap: 14px; padding: 16px 14px 16px 18px; min-width: 0; }\n.wa-mark { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: var(--radius-xl);\n background: var(--success-soft); color: var(--success-text); }\n.wa-number-text { display: grid; gap: 2px; flex: 1; min-width: 0; }\n.wa-number-phone { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0;\n font-family: var(--font-display); font-size: 17px; font-weight: 650; letter-spacing: -.01em;\n font-variant-numeric: tabular-nums; }\n.wa-number-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; margin: 0;\n color: var(--muted-foreground); font-size: 13px; }\n.wa-number-meta .copilotz-time { font-size: 13px; }\n.wa-problem { margin: 0 16px 14px; }\n.wa-you { display: grid; gap: 14px; padding: 16px 18px 18px; border-top: 1px solid var(--border);\n background: color-mix(in oklab, var(--muted) 28%, var(--card)); }\n.wa-you-title { margin: 0; color: var(--muted-foreground); font-size: 11.5px; font-weight: 650; letter-spacing: .05em;\n text-transform: uppercase; }\n\n/* Linking your phone */\n.wa-offer { display: flex; align-items: center; justify-content: space-between; gap: 14px; }\n.wa-offer-text { display: grid; gap: 2px; min-width: 0; }\n.wa-offer-text b { font-size: 14.5px; font-weight: 620; }\n.wa-steps { list-style: none; display: grid; gap: 18px; margin: 0; padding: 0; }\n.wa-steps > li { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 12px; }\n.wa-step-number { display: grid; place-items: center; width: 26px; height: 26px; border-radius: var(--radius-full);\n background: var(--primary-soft); color: var(--primary-text); font-size: 13px; font-weight: 700; }\n.wa-step { display: grid; gap: 10px; min-width: 0; padding-top: 2px; }\n.wa-step p { margin: 0; line-height: 1.55; }\n.wa-code { display: inline-flex; align-items: center; gap: 6px; justify-self: start; padding: 8px 10px 8px 16px;\n border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); }\n.wa-code-digits { font: 600 26px/1.2 var(--font-mono); letter-spacing: .12em; font-variant-numeric: tabular-nums; }\n.wa-code[data-spent] .wa-code-digits { color: var(--muted-foreground); text-decoration: line-through; }\n.wa-expiry { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; color: var(--muted-foreground);\n font-size: 13px; }\n.wa-left { color: var(--foreground); font-variant-numeric: tabular-nums; }\n.wa-waiting { display: flex; align-items: center; gap: 10px; color: var(--secondary-foreground); font-size: 13.5px; }\n.wa-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }\n\n/* Linked */\n.wa-linked { display: grid; gap: 12px; }\n.wa-linked-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }\n.wa-linked-head > .copilotz-icon { color: var(--success-text); }\n.wa-linked-head b { font-weight: 620; }\n.wa-linked-phone { color: var(--muted-foreground); font-size: 13.5px; font-variant-numeric: tabular-nums; }\n.wa-where { display: grid; grid-template-columns: max-content minmax(0, 320px); align-items: center; gap: 12px; }\n.wa-where label { font-size: 13.5px; font-weight: 560; }\n.wa-tips { margin: 0; color: var(--muted-foreground); font-size: 13px; line-height: 1.6; }\n\n/* Connecting one */\n.wa-form { display: grid; gap: 16px; }\n.wa-need { display: grid; gap: 6px; margin: 0; padding-left: 20px; color: var(--secondary-foreground); font-size: 13.5px;\n line-height: 1.5; }\n.wa-need code { font-size: .92em; }\n.wa-hook { display: grid; gap: 14px; }\n.wa-hook-field { display: grid; gap: 6px; }\n.wa-hook-field > span { font-size: 13px; font-weight: 600; }\n.wa-hook .copilotz-code-body { font-size: 13px; }\n\n@container wa-tab (max-width: 560px) {\n .wa-offer { flex-direction: column; align-items: stretch; }\n .wa-where { grid-template-columns: minmax(0, 1fr); gap: 6px; }\n .wa-number-head { align-items: flex-start; }\n}\n";
|
|
7
|
+
export declare const STYLE = "\n.wa-tab { container: wa-tab / inline-size; display: grid; gap: 18px; }\n.wa-tab-compact { gap: 14px; }\n.wa-note { margin: 0; color: var(--muted-foreground); font-size: 13.5px; line-height: 1.55; }\n.wa-note code, .wa-tips code { font-size: .92em; }\n\n/* A number */\n.wa-number { display: grid; overflow: hidden; }\n.wa-number-head { display: flex; align-items: center; gap: 14px; padding: 16px 14px 16px 18px; min-width: 0; }\n.wa-mark { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: var(--radius-xl);\n background: var(--success-soft); color: var(--success-text); }\n.wa-number-text { display: grid; gap: 2px; flex: 1; min-width: 0; }\n.wa-number-phone { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0;\n font-family: var(--font-display); font-size: 17px; font-weight: 650; letter-spacing: -.01em;\n font-variant-numeric: tabular-nums; }\n.wa-number-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; margin: 0;\n color: var(--muted-foreground); font-size: 13px; }\n.wa-number-meta .copilotz-time { font-size: 13px; }\n.wa-problem { margin: 0 16px 14px; }\n.wa-you { display: grid; gap: 14px; padding: 16px 18px 18px; border-top: 1px solid var(--border);\n background: color-mix(in oklab, var(--muted) 28%, var(--card)); }\n.wa-you-title { margin: 0; color: var(--muted-foreground); font-size: 11.5px; font-weight: 650; letter-spacing: .05em;\n text-transform: uppercase; }\n\n/* Open to customers */\n.wa-customers { display: grid; gap: 12px; padding: 16px 18px; border-top: 1px solid var(--border); }\n.wa-line { display: grid; gap: 12px; }\n.wa-line-head { display: flex; align-items: center; gap: 8px; }\n.wa-line-head > .copilotz-icon { color: var(--info-text); }\n.wa-line-head b { font-weight: 620; }\n.wa-line-fields { display: grid; gap: 10px; }\n\n/* Linking your phone */\n.wa-offer { display: flex; align-items: center; justify-content: space-between; gap: 14px; }\n.wa-offer-text { display: grid; gap: 2px; min-width: 0; }\n.wa-offer-text b { font-size: 14.5px; font-weight: 620; }\n.wa-steps { list-style: none; display: grid; gap: 18px; margin: 0; padding: 0; }\n.wa-steps > li { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 12px; }\n.wa-step-number { display: grid; place-items: center; width: 26px; height: 26px; border-radius: var(--radius-full);\n background: var(--primary-soft); color: var(--primary-text); font-size: 13px; font-weight: 700; }\n.wa-step { display: grid; gap: 10px; min-width: 0; padding-top: 2px; }\n.wa-step p { margin: 0; line-height: 1.55; }\n.wa-code { display: inline-flex; align-items: center; gap: 6px; justify-self: start; padding: 8px 10px 8px 16px;\n border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); }\n.wa-code-digits { font: 600 26px/1.2 var(--font-mono); letter-spacing: .12em; font-variant-numeric: tabular-nums; }\n.wa-code[data-spent] .wa-code-digits { color: var(--muted-foreground); text-decoration: line-through; }\n.wa-expiry { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; color: var(--muted-foreground);\n font-size: 13px; }\n.wa-left { color: var(--foreground); font-variant-numeric: tabular-nums; }\n.wa-waiting { display: flex; align-items: center; gap: 10px; color: var(--secondary-foreground); font-size: 13.5px; }\n.wa-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }\n\n/* Linked */\n.wa-linked { display: grid; gap: 12px; }\n.wa-linked-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }\n.wa-linked-head > .copilotz-icon { color: var(--success-text); }\n.wa-linked-head b { font-weight: 620; }\n.wa-linked-phone { color: var(--muted-foreground); font-size: 13.5px; font-variant-numeric: tabular-nums; }\n.wa-where { display: grid; grid-template-columns: max-content minmax(0, 320px); align-items: center; gap: 12px; }\n.wa-where label { font-size: 13.5px; font-weight: 560; }\n.wa-tips { margin: 0; color: var(--muted-foreground); font-size: 13px; line-height: 1.6; }\n\n/* Connecting one */\n.wa-form { display: grid; gap: 16px; }\n.wa-need { display: grid; gap: 6px; margin: 0; padding-left: 20px; color: var(--secondary-foreground); font-size: 13.5px;\n line-height: 1.5; }\n.wa-need code { font-size: .92em; }\n.wa-hook { display: grid; gap: 14px; }\n.wa-hook-field { display: grid; gap: 6px; }\n.wa-hook-field > span { font-size: 13px; font-weight: 600; }\n.wa-hook .copilotz-code-body { font-size: 13px; }\n\n@container wa-tab (max-width: 560px) {\n .wa-offer { flex-direction: column; align-items: stretch; }\n .wa-where { grid-template-columns: minmax(0, 1fr); gap: 6px; }\n .wa-number-head { align-items: flex-start; }\n}\n";
|
|
@@ -28,6 +28,14 @@ export const STYLE = `
|
|
|
28
28
|
.wa-you-title { margin: 0; color: var(--muted-foreground); font-size: 11.5px; font-weight: 650; letter-spacing: .05em;
|
|
29
29
|
text-transform: uppercase; }
|
|
30
30
|
|
|
31
|
+
/* Open to customers */
|
|
32
|
+
.wa-customers { display: grid; gap: 12px; padding: 16px 18px; border-top: 1px solid var(--border); }
|
|
33
|
+
.wa-line { display: grid; gap: 12px; }
|
|
34
|
+
.wa-line-head { display: flex; align-items: center; gap: 8px; }
|
|
35
|
+
.wa-line-head > .copilotz-icon { color: var(--info-text); }
|
|
36
|
+
.wa-line-head b { font-weight: 620; }
|
|
37
|
+
.wa-line-fields { display: grid; gap: 10px; }
|
|
38
|
+
|
|
31
39
|
/* Linking your phone */
|
|
32
40
|
.wa-offer { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
|
|
33
41
|
.wa-offer-text { display: grid; gap: 2px; min-width: 0; }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Anthropic Messages API, streaming. */
|
|
2
2
|
import { alive, post, sse, usageOf } from "../../shared/provider.js";
|
|
3
|
+
import { answerable, } from "../../shared/types.js";
|
|
3
4
|
export const ANTHROPIC = {
|
|
4
5
|
name: "Anthropic",
|
|
5
6
|
baseURL: "https://api.anthropic.com/v1",
|
|
@@ -58,6 +59,20 @@ const messagesOf = (messages) => {
|
|
|
58
59
|
return { turns, points: points.filter((block) => Boolean(block)) };
|
|
59
60
|
};
|
|
60
61
|
const EPHEMERAL = { type: "ephemeral" };
|
|
62
|
+
const COUNTS = [
|
|
63
|
+
"input_tokens",
|
|
64
|
+
"output_tokens",
|
|
65
|
+
"cache_read_input_tokens",
|
|
66
|
+
"cache_creation_input_tokens",
|
|
67
|
+
];
|
|
68
|
+
/** Usage from its counts: Anthropic's input_tokens leave out the cache's reads and writes. */
|
|
69
|
+
const usageFrom = (c) => ({
|
|
70
|
+
input: (c.input_tokens ?? 0) + (c.cache_read_input_tokens ?? 0) +
|
|
71
|
+
(c.cache_creation_input_tokens ?? 0),
|
|
72
|
+
output: c.output_tokens ?? 0,
|
|
73
|
+
cached: c.cache_read_input_tokens,
|
|
74
|
+
cacheWrite: c.cache_creation_input_tokens,
|
|
75
|
+
});
|
|
61
76
|
/** Anthropic requires a limit: the model's, up to this, unless asked for more. */
|
|
62
77
|
const MAX_TOKENS = 32_000;
|
|
63
78
|
/** Thinking budgets for models that take one rather than an effort level. */
|
|
@@ -107,7 +122,7 @@ export const anthropic = {
|
|
|
107
122
|
// Anthropic caches only up to marked blocks (at most 4): the tools, the
|
|
108
123
|
// system text, the caller's cache points, and the end of the request, so
|
|
109
124
|
// the next call finds this one's prefix.
|
|
110
|
-
const { turns, points } = messagesOf(messages);
|
|
125
|
+
const { turns, points } = messagesOf(answerable(messages));
|
|
111
126
|
const last = turns.at(-1)?.content.at(-1);
|
|
112
127
|
for (const block of [...points.slice(-1), last])
|
|
113
128
|
if (block)
|
|
@@ -136,7 +151,14 @@ export const anthropic = {
|
|
|
136
151
|
// Tool input arrives as JSON in pieces, per content block; so does thinking, with its signature.
|
|
137
152
|
const blocks = new Map();
|
|
138
153
|
const thoughts = new Map();
|
|
139
|
-
|
|
154
|
+
// What it used, as each event says it so far: the greatest of each count.
|
|
155
|
+
const counts = {};
|
|
156
|
+
const counted = (said = {}) => {
|
|
157
|
+
for (const field of COUNTS) {
|
|
158
|
+
if ((said[field] ?? 0) > (counts[field] ?? 0))
|
|
159
|
+
counts[field] = said[field];
|
|
160
|
+
}
|
|
161
|
+
};
|
|
140
162
|
// Its thinking comes in pieces long before it writes: alive all the same.
|
|
141
163
|
const beat = alive();
|
|
142
164
|
for await (const { data } of sse(response.body)) {
|
|
@@ -144,18 +166,9 @@ export const anthropic = {
|
|
|
144
166
|
if (beat())
|
|
145
167
|
yield { type: "thinking" };
|
|
146
168
|
switch (event.type) {
|
|
147
|
-
case "message_start":
|
|
148
|
-
|
|
149
|
-
const u = event.message?.usage ?? {};
|
|
150
|
-
usage = {
|
|
151
|
-
input: (u.input_tokens ?? 0) + (u.cache_read_input_tokens ?? 0) +
|
|
152
|
-
(u.cache_creation_input_tokens ?? 0),
|
|
153
|
-
output: u.output_tokens ?? 0,
|
|
154
|
-
cached: u.cache_read_input_tokens,
|
|
155
|
-
cacheWrite: u.cache_creation_input_tokens,
|
|
156
|
-
};
|
|
169
|
+
case "message_start":
|
|
170
|
+
counted(event.message?.usage);
|
|
157
171
|
break;
|
|
158
|
-
}
|
|
159
172
|
case "content_block_start":
|
|
160
173
|
if (event.content_block?.type === "thinking" ||
|
|
161
174
|
event.content_block?.type === "redacted_thinking") {
|
|
@@ -203,7 +216,7 @@ export const anthropic = {
|
|
|
203
216
|
break;
|
|
204
217
|
}
|
|
205
218
|
case "message_delta":
|
|
206
|
-
|
|
219
|
+
counted(event.usage);
|
|
207
220
|
break;
|
|
208
221
|
case "message_stop":
|
|
209
222
|
// Its thinking goes back with this answer when tools continue it.
|
|
@@ -214,7 +227,7 @@ export const anthropic = {
|
|
|
214
227
|
Math.ceil(String(t.data ?? "").length / 12), 0);
|
|
215
228
|
yield { type: "state", state: { data, ...(tokens ? { tokens } : {}) } };
|
|
216
229
|
}
|
|
217
|
-
yield { type: "usage", ...usageOf(
|
|
230
|
+
yield { type: "usage", ...usageOf(usageFrom(counts)) };
|
|
218
231
|
break;
|
|
219
232
|
case "error":
|
|
220
233
|
throw new Error(`Anthropic: ${event.error?.message ?? JSON.stringify(event.error)}`);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { alive, post, sse, usageOf } from "../../shared/provider.js";
|
|
2
|
+
import { answerable } from "../../shared/types.js";
|
|
2
3
|
export const GEMINI = {
|
|
3
4
|
name: "Gemini",
|
|
4
5
|
baseURL: "https://generativelanguage.googleapis.com/v1beta",
|
|
@@ -134,7 +135,7 @@ export const gemini = {
|
|
|
134
135
|
...(temperature !== undefined ? { temperature } : {}),
|
|
135
136
|
};
|
|
136
137
|
const response = await post(connection, GEMINI, `/models/${encodeURIComponent(connection.model)}:streamGenerateContent?alt=sse`, {
|
|
137
|
-
contents: contentsOf(messages),
|
|
138
|
+
contents: contentsOf(answerable(messages)),
|
|
138
139
|
...(instructions ? { systemInstruction: { parts: [{ text: instructions }] } } : {}),
|
|
139
140
|
...(tools.length ? { tools: [{ functionDeclarations: tools.map(declaration) }] } : {}),
|
|
140
141
|
...(Object.keys(generationConfig).length ? { generationConfig } : {}),
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* back on its answer (its state), as DeepSeek requires once tools are given.
|
|
7
7
|
*/
|
|
8
8
|
import { alive, post, sse, usageOf } from "../../shared/provider.js";
|
|
9
|
+
import { answerable } from "../../shared/types.js";
|
|
9
10
|
export const OPENAI = {
|
|
10
11
|
name: "OpenAI",
|
|
11
12
|
baseURL: "https://api.openai.com/v1",
|
|
@@ -57,7 +58,7 @@ export const openaiCompletions = {
|
|
|
57
58
|
const own = (connection.baseURL ?? OPENAI.baseURL).startsWith(OPENAI.baseURL);
|
|
58
59
|
const response = await post(connection, OPENAI, "/chat/completions", {
|
|
59
60
|
model: connection.model,
|
|
60
|
-
messages: messagesOf(instructions, messages),
|
|
61
|
+
messages: messagesOf(instructions, answerable(messages)),
|
|
61
62
|
...(tools.length
|
|
62
63
|
? {
|
|
63
64
|
tools: tools.map((tool) => ({
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LlmAdapter } from "../../shared/types.js";
|
|
2
2
|
export declare const openaiResponses: LlmAdapter;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
* OpenAI Responses API, streaming. A reasoning model's reasoning comes back
|
|
3
3
|
* encrypted, as its answer's state, and goes back with its answer in the next
|
|
4
4
|
* calls: between tool steps it carries on from it instead of thinking again.
|
|
5
|
+
* So OpenAI keeps nothing (`store: false`): each call brings what it needs.
|
|
5
6
|
*/
|
|
6
7
|
import { alive, post, sse, usageOf } from "../../shared/provider.js";
|
|
8
|
+
import { answerable } from "../../shared/types.js";
|
|
7
9
|
import { OPENAI } from "./openai-compatible.js";
|
|
8
10
|
/** A file as the Responses API takes it: an image, or a PDF. */
|
|
9
11
|
const part = (file) => file.type === "application/pdf"
|
|
@@ -94,21 +96,26 @@ const inputOf = (messages, points) => messages.flatMap((message, i) => {
|
|
|
94
96
|
const pointless = new Set();
|
|
95
97
|
/** Servers that refused to send reasoning back encrypted: not asked again. */
|
|
96
98
|
const unreasoned = new Set();
|
|
99
|
+
/** Servers that refused to be told not to store: not told again. */
|
|
100
|
+
const storing = new Set();
|
|
97
101
|
/** Whether a refusal is of this part of the request, as its message names it. */
|
|
98
102
|
const refusedFor = (named) => (error) => error.status === 400 && named.test(String(error.message));
|
|
99
103
|
const refusedPoints = refusedFor(/prompt_cache_breakpoint/);
|
|
100
104
|
// The parameter itself (`"param": "include"`, "Unrecognized … argument: include"), not what's in it.
|
|
101
105
|
const refusedInclude = refusedFor(/"param":\s*"include|['"]include['"]|argument[^.]*\binclude\b/i);
|
|
106
|
+
const refusedStore = refusedFor(/"param":\s*"store|['"]store['"]|argument[^.]*\bstore\b/i);
|
|
102
107
|
/** What's asked to come back with the answer: its reasoning, encrypted, to go back to it. */
|
|
103
108
|
const REASONING = ["reasoning.encrypted_content"];
|
|
104
109
|
export const openaiResponses = {
|
|
105
110
|
media: ["image", "pdf"],
|
|
106
111
|
async *generate({ connection, effort, maxTokens, temperature, options, info, instructions, messages, tools = [], signal, }) {
|
|
107
112
|
const where = `${connection.baseURL ?? OPENAI.baseURL} ${connection.model}`;
|
|
108
|
-
|
|
109
|
-
//
|
|
110
|
-
|
|
113
|
+
const asked = answerable(messages);
|
|
114
|
+
// Breakpoints, its reasoning back (from a model that reasons), and nothing stored, unless this
|
|
115
|
+
// server refused them once: then it's asked again without, from then on.
|
|
116
|
+
let points = pointless.has(where) ? new Set() : pointsOf(asked);
|
|
111
117
|
let include = info?.reasoning !== false && !unreasoned.has(where);
|
|
118
|
+
let unstored = !storing.has(where);
|
|
112
119
|
const body = (input) => ({
|
|
113
120
|
model: connection.model,
|
|
114
121
|
...(instructions ? { instructions } : {}),
|
|
@@ -131,12 +138,13 @@ export const openaiResponses = {
|
|
|
131
138
|
...(maxTokens ? { max_output_tokens: maxTokens } : {}),
|
|
132
139
|
...(temperature !== undefined ? { temperature } : {}),
|
|
133
140
|
...(include ? { include: REASONING } : {}),
|
|
141
|
+
...(unstored ? { store: false } : {}),
|
|
134
142
|
...options,
|
|
135
143
|
});
|
|
136
144
|
let response;
|
|
137
145
|
for (;;) {
|
|
138
146
|
try {
|
|
139
|
-
response = await post(connection, OPENAI, "/responses", body(inputOf(
|
|
147
|
+
response = await post(connection, OPENAI, "/responses", body(inputOf(asked, points)), signal);
|
|
140
148
|
break;
|
|
141
149
|
}
|
|
142
150
|
catch (error) {
|
|
@@ -148,6 +156,10 @@ export const openaiResponses = {
|
|
|
148
156
|
unreasoned.add(where);
|
|
149
157
|
include = false;
|
|
150
158
|
}
|
|
159
|
+
else if (unstored && refusedStore(error)) {
|
|
160
|
+
storing.add(where);
|
|
161
|
+
unstored = false;
|
|
162
|
+
}
|
|
151
163
|
else
|
|
152
164
|
throw error;
|
|
153
165
|
}
|
|
@@ -53,6 +53,14 @@ export type LlmMessage = {
|
|
|
53
53
|
text: string;
|
|
54
54
|
cache?: true;
|
|
55
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* A call asks for the model's next message, never for the rest of its last
|
|
58
|
+
* one: a conversation that ends with the model's own message goes with a
|
|
59
|
+
* user turn after it. Anthropic's newer models refuse an assistant message
|
|
60
|
+
* last ("prefill"), Gemini and some servers would carry it on; every adapter
|
|
61
|
+
* sends this, so every provider reads the same.
|
|
62
|
+
*/
|
|
63
|
+
export declare const answerable: (messages: LlmMessage[]) => LlmMessage[];
|
|
56
64
|
export type LlmTool = {
|
|
57
65
|
name: string;
|
|
58
66
|
description: string;
|
|
@@ -1 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A call asks for the model's next message, never for the rest of its last
|
|
3
|
+
* one: a conversation that ends with the model's own message goes with a
|
|
4
|
+
* user turn after it. Anthropic's newer models refuse an assistant message
|
|
5
|
+
* last ("prefill"), Gemini and some servers would carry it on; every adapter
|
|
6
|
+
* sends this, so every provider reads the same.
|
|
7
|
+
*/
|
|
8
|
+
export const answerable = (messages) => messages.at(-1)?.role === "assistant"
|
|
9
|
+
? [...messages, { role: "user", text: "Continue." }]
|
|
10
|
+
: messages;
|
|
1
11
|
export const EFFORTS = ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
package/runtime/actor.d.ts
CHANGED
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
* a contact), an agent working for someone (`for`), or trusted code acting
|
|
4
4
|
* for whoever called it (`via`, set by `ctx.as`). Everyone who needs the person
|
|
5
5
|
* behind an actor asks here.
|
|
6
|
+
*
|
|
7
|
+
* A contact is someone outside the org who talks to an app's agents (a
|
|
8
|
+
* WhatsApp customer): `{ kind: "contact", id }`. Work can be for them, but
|
|
9
|
+
* they are never a person: nothing that checks a person sees one.
|
|
6
10
|
*/
|
|
7
11
|
import type { Actor } from "./store.js";
|
|
12
|
+
/** Whom work is for: the person or the contact found along `for`, then `via`, as they act. */
|
|
13
|
+
export declare function principalOf(actor: Actor | undefined): Actor | undefined;
|
|
8
14
|
/** The person whose work this is: the one acting, or the one found along `for`, then `via`. */
|
|
9
15
|
export declare function personOf(actor: Actor | undefined): string | undefined;
|
package/runtime/actor.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export function
|
|
1
|
+
/** Whom work is for: the person or the contact found along `for`, then `via`, as they act. */
|
|
2
|
+
export function principalOf(actor) {
|
|
3
3
|
for (let a = actor, hops = 0; a && hops < 4; hops++) {
|
|
4
|
-
if (a.kind === "person")
|
|
5
|
-
return a
|
|
4
|
+
if (a.kind === "person" || a.kind === "contact")
|
|
5
|
+
return a;
|
|
6
6
|
a = (a.for ?? a.via);
|
|
7
7
|
}
|
|
8
8
|
return undefined;
|
|
9
9
|
}
|
|
10
|
+
/** The person whose work this is: the one acting, or the one found along `for`, then `via`. */
|
|
11
|
+
export function personOf(actor) {
|
|
12
|
+
const principal = principalOf(actor);
|
|
13
|
+
return principal?.kind === "person" ? principal.id : undefined;
|
|
14
|
+
}
|
package/runtime/aggregate.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* strings, as MongoDB orders them; other types are left out).
|
|
15
15
|
* - Groups come out ordered by `_id`, unless `$sort` says otherwise.
|
|
16
16
|
*/
|
|
17
|
-
import { get, matches, sortAndPage } from "./mongo.js";
|
|
17
|
+
import { checkName, get, matches, sortAndPage } from "./mongo.js";
|
|
18
18
|
import { check } from "./mongo.js";
|
|
19
19
|
const invalid = (message) => Object.assign(new Error(message), { code: "invalid" });
|
|
20
20
|
const isField = (expr) => typeof expr === "string" && expr.startsWith("$");
|
|
@@ -51,10 +51,16 @@ export function plan(pipeline) {
|
|
|
51
51
|
const { _id, ...rest } = (arg ?? {});
|
|
52
52
|
if (!("_id" in arg))
|
|
53
53
|
throw invalid("$group needs an _id (null for one group)");
|
|
54
|
+
// The fields it names, it makes: never a `$…` one (a blob reference's `$blob`, say).
|
|
55
|
+
const named = ([k, e]) => {
|
|
56
|
+
checkName(k, `_id.${k}`);
|
|
57
|
+
return [k, checkExpr(e)];
|
|
58
|
+
};
|
|
54
59
|
const key = _id !== null && typeof _id === "object" && !("$substr" in _id)
|
|
55
|
-
? { fields: Object.entries(_id).map(
|
|
60
|
+
? { fields: Object.entries(_id).map(named) }
|
|
56
61
|
: { expr: checkExpr(_id) };
|
|
57
62
|
const fields = Object.entries(rest).map(([field, acc]) => {
|
|
63
|
+
checkName(field);
|
|
58
64
|
const [op, ...more] = Object.keys(acc ?? {});
|
|
59
65
|
if (!OPERATORS.has(op) || more.length) {
|
|
60
66
|
throw invalid(`Unsupported accumulator for "${field}": $sum, $count, $avg, $min, $max`);
|
package/runtime/blobs.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Large values live once, as blobs named by the hash of their content. A
|
|
3
|
-
* document or event holds a small reference in their place:
|
|
4
|
-
* `{ $blob: "sha256-…", size, type }`. The owner moves large values out on
|
|
5
|
-
* write and back in on read, so plugin code never sees a reference, and the
|
|
6
|
-
* same content written twice (a document and its event, or two equal tool
|
|
7
|
-
* results) is stored once.
|
|
8
|
-
*/
|
|
9
1
|
export type BlobRef = {
|
|
10
2
|
$blob: string;
|
|
11
3
|
size: number;
|
|
@@ -13,7 +5,8 @@ export type BlobRef = {
|
|
|
13
5
|
};
|
|
14
6
|
/**
|
|
15
7
|
* Where blobs live when not in the store itself (a directory, a bucket).
|
|
16
|
-
* Content-addressed: putting an id that exists is a no-op.
|
|
8
|
+
* Content-addressed: putting an id that exists is a no-op. An id is only ever
|
|
9
|
+
* a blob's: refuse any other (`checkBlobId`) before it becomes a path or a name.
|
|
17
10
|
*/
|
|
18
11
|
export type Blobs = {
|
|
19
12
|
put(blob: {
|
|
@@ -28,15 +21,25 @@ export type Blobs = {
|
|
|
28
21
|
};
|
|
29
22
|
/** Strings larger than this many UTF-8 bytes become blobs (default 16 KiB). */
|
|
30
23
|
export declare const BLOB_THRESHOLD: number;
|
|
24
|
+
export declare const isBlobId: (id: unknown) => id is string;
|
|
25
|
+
/** The id, when it is a blob's; else `invalid`. Stores check it before they look anything up. */
|
|
26
|
+
export declare function checkBlobId(id: unknown): string;
|
|
27
|
+
/** Exactly what `offload` makes: these three keys, a blob id, a numeric size and a type. */
|
|
31
28
|
export declare const isBlobRef: (value: unknown) => value is BlobRef;
|
|
32
29
|
export declare function blobId(data: Uint8Array): Promise<string>;
|
|
33
|
-
/**
|
|
30
|
+
/** Refuses (`invalid`) a value of plugin code's that holds an object with a `$blob` key. */
|
|
31
|
+
export declare function refuseBlobKeys(value: unknown): void;
|
|
32
|
+
/**
|
|
33
|
+
* Replaces strings over the threshold with blob references, storing each with `put`.
|
|
34
|
+
* `foreign`: the value is plugin code's, and may hold no `$blob` key (see
|
|
35
|
+
* `large`); otherwise it's the owner's, and its references stay as they are.
|
|
36
|
+
*/
|
|
34
37
|
export declare function offload<T>(value: T, put: (blob: {
|
|
35
38
|
id: string;
|
|
36
39
|
data: Uint8Array;
|
|
37
40
|
type: string;
|
|
38
|
-
}) => Promise<void>, threshold?: number): Promise<T>;
|
|
39
|
-
/** Replaces blob references with their content. */
|
|
41
|
+
}) => Promise<void>, threshold?: number, foreign?: boolean): Promise<T>;
|
|
42
|
+
/** Replaces blob references with their content; one whose blob is gone fails (`missing_blob`). */
|
|
40
43
|
export declare function hydrate<T>(value: T, get: (id: string) => Promise<{
|
|
41
44
|
data: Uint8Array;
|
|
42
45
|
} | null>): Promise<T>;
|
package/runtime/blobs.js
CHANGED
|
@@ -5,25 +5,67 @@
|
|
|
5
5
|
* write and back in on read, so plugin code never sees a reference, and the
|
|
6
6
|
* same content written twice (a document and its event, or two equal tool
|
|
7
7
|
* results) is stored once.
|
|
8
|
+
*
|
|
9
|
+
* Only the owner makes references. What plugin code writes (documents,
|
|
10
|
+
* updates, edges, events) and what Actions are called with may hold no
|
|
11
|
+
* `$blob` key at all: one there is forged, and refused. On read, only an
|
|
12
|
+
* exact reference is loaded (see `isBlobRef`); anything else is data.
|
|
8
13
|
*/
|
|
14
|
+
import { invalid } from "./errors.js";
|
|
9
15
|
/** Strings larger than this many UTF-8 bytes become blobs (default 16 KiB). */
|
|
10
16
|
export const BLOB_THRESHOLD = 16 * 1024;
|
|
11
17
|
const TEXT = "text/plain; charset=utf-8";
|
|
12
18
|
const encoder = new TextEncoder();
|
|
13
19
|
const decoder = new TextDecoder();
|
|
14
|
-
|
|
20
|
+
/** A blob's id: `sha256-` and the hex of its content's hash. Never a path or a name. */
|
|
21
|
+
const ID = /^sha256-[0-9a-f]{64}$/;
|
|
22
|
+
export const isBlobId = (id) => typeof id === "string" && ID.test(id);
|
|
23
|
+
/** The id, when it is a blob's; else `invalid`. Stores check it before they look anything up. */
|
|
24
|
+
export function checkBlobId(id) {
|
|
25
|
+
if (isBlobId(id))
|
|
26
|
+
return id;
|
|
27
|
+
throw invalid(`Not a blob id: ${JSON.stringify(String(id).slice(0, 80))}`);
|
|
28
|
+
}
|
|
29
|
+
/** Exactly what `offload` makes: these three keys, a blob id, a numeric size and a type. */
|
|
30
|
+
export const isBlobRef = (value) => {
|
|
31
|
+
// Most objects have no `$blob`: one look is all they cost.
|
|
32
|
+
if (value === null || typeof value !== "object" || !isBlobId(value.$blob)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const { size, type } = value;
|
|
36
|
+
return typeof size === "number" && typeof type === "string" &&
|
|
37
|
+
Object.keys(value).length === 3 && Object.hasOwn(value, "$blob") &&
|
|
38
|
+
Object.hasOwn(value, "size") && Object.hasOwn(value, "type");
|
|
39
|
+
};
|
|
15
40
|
export async function blobId(data) {
|
|
16
41
|
const hash = new Uint8Array(await crypto.subtle.digest("SHA-256", data));
|
|
17
42
|
return "sha256-" + Array.from(hash, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
18
43
|
}
|
|
19
|
-
|
|
20
|
-
|
|
44
|
+
const forged = () => invalid("\"$blob\" is reserved for the runtime's blob references: data can't hold that key.");
|
|
45
|
+
/**
|
|
46
|
+
* Whether `value` holds a string that may exceed the threshold (cheap, synchronous).
|
|
47
|
+
* `foreign`: the value is plugin code's, so an object with a `$blob` key is
|
|
48
|
+
* refused on the way. Every object gets that look: this walk stops early
|
|
49
|
+
* only at a large string, and `offload` then walks each part of the value.
|
|
50
|
+
*/
|
|
51
|
+
function large(value, threshold, foreign) {
|
|
21
52
|
// A UTF-16 code unit is at most 3 UTF-8 bytes, so shorter strings always fit.
|
|
22
53
|
if (typeof value === "string")
|
|
23
54
|
return value.length * 3 > threshold;
|
|
24
|
-
if (value === null || typeof value !== "object"
|
|
55
|
+
if (value === null || typeof value !== "object")
|
|
25
56
|
return false;
|
|
26
|
-
|
|
57
|
+
if (foreign) {
|
|
58
|
+
if (Object.hasOwn(value, "$blob"))
|
|
59
|
+
throw forged();
|
|
60
|
+
}
|
|
61
|
+
else if (isBlobRef(value))
|
|
62
|
+
return false;
|
|
63
|
+
return (Array.isArray(value) ? value : Object.values(value)).some((v) => large(v, threshold, foreign));
|
|
64
|
+
}
|
|
65
|
+
/** Refuses (`invalid`) a value of plugin code's that holds an object with a `$blob` key. */
|
|
66
|
+
export function refuseBlobKeys(value) {
|
|
67
|
+
// No string is over an infinite threshold: the walk looks at everything.
|
|
68
|
+
large(value, Infinity, true);
|
|
27
69
|
}
|
|
28
70
|
function holdsRef(value) {
|
|
29
71
|
if (value === null || typeof value !== "object")
|
|
@@ -32,9 +74,13 @@ function holdsRef(value) {
|
|
|
32
74
|
return true;
|
|
33
75
|
return (Array.isArray(value) ? value : Object.values(value)).some(holdsRef);
|
|
34
76
|
}
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Replaces strings over the threshold with blob references, storing each with `put`.
|
|
79
|
+
* `foreign`: the value is plugin code's, and may hold no `$blob` key (see
|
|
80
|
+
* `large`); otherwise it's the owner's, and its references stay as they are.
|
|
81
|
+
*/
|
|
82
|
+
export async function offload(value, put, threshold = BLOB_THRESHOLD, foreign = false) {
|
|
83
|
+
if (!large(value, threshold, foreign))
|
|
38
84
|
return value;
|
|
39
85
|
if (typeof value === "string") {
|
|
40
86
|
const data = encoder.encode(value);
|
|
@@ -45,11 +91,12 @@ export async function offload(value, put, threshold = BLOB_THRESHOLD) {
|
|
|
45
91
|
return { $blob: id, size: data.length, type: TEXT };
|
|
46
92
|
}
|
|
47
93
|
const copy = (Array.isArray(value) ? [...value] : { ...value });
|
|
48
|
-
for (const [key, item] of Object.entries(copy))
|
|
49
|
-
copy[key] = await offload(item, put, threshold);
|
|
94
|
+
for (const [key, item] of Object.entries(copy)) {
|
|
95
|
+
copy[key] = await offload(item, put, threshold, foreign);
|
|
96
|
+
}
|
|
50
97
|
return copy;
|
|
51
98
|
}
|
|
52
|
-
/** Replaces blob references with their content. */
|
|
99
|
+
/** Replaces blob references with their content; one whose blob is gone fails (`missing_blob`). */
|
|
53
100
|
export async function hydrate(value, get) {
|
|
54
101
|
if (!holdsRef(value))
|
|
55
102
|
return value;
|
package/runtime/cache.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ export declare function createCache(options?: {
|
|
|
11
11
|
aggregate(collection: string, pipeline: unknown, load: () => Promise<Doc[]>): Promise<Doc[]>;
|
|
12
12
|
/** Applies committed changes to everything cached for the collection. */
|
|
13
13
|
apply(collection: string, changes: Change[]): void;
|
|
14
|
+
/**
|
|
15
|
+
* Forgets everything: for a change it can't follow (maintenance SQL,
|
|
16
|
+
* which may have changed any document). Reads in flight across it don't
|
|
17
|
+
* fill the cache; the next read of anything goes to the store.
|
|
18
|
+
*/
|
|
19
|
+
clear(): void;
|
|
14
20
|
stats: () => {
|
|
15
21
|
hits: number;
|
|
16
22
|
misses: number;
|