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
package/hosts/web/node/serve.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { serve as oxian } from "oxianjs/adapters/node";
|
|
2
|
-
import { hostRouted } from "../routes.js";
|
|
2
|
+
import { hostRouted, routeHost } from "../routes.js";
|
|
3
3
|
import { socket, webServer } from "../server.js";
|
|
4
4
|
/**
|
|
5
5
|
* Serves the web host for a runtime that declares the `socket` transport
|
|
@@ -19,6 +19,28 @@ export async function serve(options) {
|
|
|
19
19
|
signal,
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Serves an app's routes alone (`routeHost`): its webhooks and sockets, and
|
|
24
|
+
* `/health`. Its runtime's own socket (`/oxian`, when it declares one: remote
|
|
25
|
+
* executors) goes to it, as `serve`'s does.
|
|
26
|
+
*/
|
|
27
|
+
export async function serveRoutes(options) {
|
|
28
|
+
const { runtime, front, ...address } = options;
|
|
29
|
+
const routed = hostRouted(runtime, front ? { front } : {});
|
|
30
|
+
const listener = await listen({
|
|
31
|
+
...address,
|
|
32
|
+
fetch: routeHost(runtime, front ? { front } : {}),
|
|
33
|
+
hypervisor: (request) => routed(request) ? undefined : runtime.hypervisor,
|
|
34
|
+
});
|
|
35
|
+
// Closing takes a while (the runtime's drain): asked again, it's the same close.
|
|
36
|
+
let closed;
|
|
37
|
+
// What it's given goes on to the runtime's close: how long running work may take to finish.
|
|
38
|
+
const owned = runtime;
|
|
39
|
+
return {
|
|
40
|
+
...listener,
|
|
41
|
+
close: (options) => closed ??= listener.shutdown().then(() => owned.close(options)),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
22
44
|
/** Serves a fetch handler, each socket going to the Hypervisor `hypervisor` picks for it. */
|
|
23
45
|
export async function listen(options) {
|
|
24
46
|
const { hostname = "127.0.0.1", port = 0, signal } = options;
|
package/hosts/web/routes.d.ts
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
* - `{ path, serve }`: a function that answers the request itself, here in
|
|
10
10
|
* the host's process: files as they are (downloads), or an API that must
|
|
11
11
|
* stream, choose call ids or keep a request's secrets out of the log. It's
|
|
12
|
-
* given the runtime and who the request's session signs in (`Served`).
|
|
12
|
+
* given the runtime and who the request's session signs in (`Served`). It
|
|
13
|
+
* may take a WebSocket (a voice call's relay): `host.upgrade()` accepts
|
|
14
|
+
* the request's upgrade, and it answers with the response that gives.
|
|
13
15
|
* - `{ host, serve }` (or `action`): every request to a host, whatever its
|
|
14
16
|
* path, and never the app's page, code or socket there: what a computer
|
|
15
17
|
* serves (a preview), an app of the app's own. `host` is a pattern: a host
|
|
@@ -31,6 +33,7 @@
|
|
|
31
33
|
* resources: { routes: { "whatsapp.hook": { path: "/hooks/whatsapp", action: "whatsapp.hook" } } }
|
|
32
34
|
* ```
|
|
33
35
|
*/
|
|
36
|
+
import { type RouteWebSocket } from "oxianjs/http";
|
|
34
37
|
import type { Actor, Infer, Resources, Runtime } from "../../runtime/mod.js";
|
|
35
38
|
export type Route = ({
|
|
36
39
|
path: string;
|
|
@@ -52,7 +55,21 @@ export type Served = {
|
|
|
52
55
|
runtime: Runtime;
|
|
53
56
|
whom(): Promise<Actor | null>;
|
|
54
57
|
host: string;
|
|
58
|
+
/**
|
|
59
|
+
* Accepts the request's WebSocket upgrade (a `GET` with `upgrade:
|
|
60
|
+
* websocket`; anything else throws): the socket, open once the route
|
|
61
|
+
* answers with `response`, as it is. `protocol` is one the client offered.
|
|
62
|
+
* The host's listener takes it (`copilotz/web/node`), on Node, Deno and Bun.
|
|
63
|
+
*/
|
|
64
|
+
upgrade(options?: {
|
|
65
|
+
protocol?: string;
|
|
66
|
+
}): {
|
|
67
|
+
socket: RouteSocket;
|
|
68
|
+
response: Response;
|
|
69
|
+
};
|
|
55
70
|
};
|
|
71
|
+
/** A route's WebSocket: a browser's `WebSocket`, as far as `onmessage`, `send` and `close` go. */
|
|
72
|
+
export type RouteSocket = RouteWebSocket;
|
|
56
73
|
/** The app's front (a Cloudflare worker before it): the secret it vouches for requests with. */
|
|
57
74
|
export type Front = {
|
|
58
75
|
secret: string;
|
|
@@ -144,3 +161,13 @@ export declare function hostServer(runtime: Runtime, whom: (request: Request) =>
|
|
|
144
161
|
export declare function routeServer(runtime: Runtime, whom: (request: Request) => Promise<Actor | null>, options?: {
|
|
145
162
|
front?: Front;
|
|
146
163
|
}): (request: Request) => Promise<Response> | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* A host for an app without the web app (on WhatsApp, on the phone): its
|
|
166
|
+
* routes alone, by host and then by path, their sockets included; `GET
|
|
167
|
+
* /health`, unless a route takes it; and 404 for anything else. Nobody signs
|
|
168
|
+
* in here: a route's Action is called as a visitor, and its `allow` decides.
|
|
169
|
+
* `serveRoutes` (`copilotz/web/node`) listens with it.
|
|
170
|
+
*/
|
|
171
|
+
export declare function routeHost(runtime: Runtime, options?: {
|
|
172
|
+
front?: Front;
|
|
173
|
+
}): (request: Request) => Promise<Response>;
|
package/hosts/web/routes.js
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugins' own HTTP, as the web host answers it: a `routes` resource, by name.
|
|
3
|
+
* A path ending in `/` takes everything under it; any other, itself alone.
|
|
4
|
+
*
|
|
5
|
+
* - `{ path, action }`: the request becomes a call to that Action (its input
|
|
6
|
+
* an `HttpRequest`), as the person its session cookie signs in, or else a
|
|
7
|
+
* visitor (`{ kind: "visitor", id: "" }`): the Action's `allow` decides.
|
|
8
|
+
* It answers with an `HttpAnswer`. Webhooks, OAuth callbacks, an API.
|
|
9
|
+
* - `{ path, serve }`: a function that answers the request itself, here in
|
|
10
|
+
* the host's process: files as they are (downloads), or an API that must
|
|
11
|
+
* stream, choose call ids or keep a request's secrets out of the log. It's
|
|
12
|
+
* given the runtime and who the request's session signs in (`Served`). It
|
|
13
|
+
* may take a WebSocket (a voice call's relay): `host.upgrade()` accepts
|
|
14
|
+
* the request's upgrade, and it answers with the response that gives.
|
|
15
|
+
* - `{ host, serve }` (or `action`): every request to a host, whatever its
|
|
16
|
+
* path, and never the app's page, code or socket there: what a computer
|
|
17
|
+
* serves (a preview), an app of the app's own. `host` is a pattern: a host
|
|
18
|
+
* exactly (`docs.example.com`), or `*<suffix>`, any first label ending so
|
|
19
|
+
* (`*-preview.copilotz.app` takes `abc123-preview.copilotz.app`, not
|
|
20
|
+
* `a.b-preview.copilotz.app`). It may be a function of the app's
|
|
21
|
+
* resources, for a domain its settings name, answering nothing for no
|
|
22
|
+
* route. A port in a pattern must match too; without one, any port does.
|
|
23
|
+
*
|
|
24
|
+
* `methods` limits which methods it takes (all by default). Paths the host
|
|
25
|
+
* serves itself can't be taken.
|
|
26
|
+
*
|
|
27
|
+
* The host a request is for is its own (`Host`), or, from the app's front
|
|
28
|
+
* (a Cloudflare worker before it, with `front: { secret }`), the one the
|
|
29
|
+
* front says (`x-forwarded-host`), when it carries the front's secret
|
|
30
|
+
* (`x-copilotz-front`). Anyone else's forwarded headers are ignored.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* resources: { routes: { "whatsapp.hook": { path: "/hooks/whatsapp", action: "whatsapp.hook" } } }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
import { upgradeWebSocket } from "oxianjs/http";
|
|
1
37
|
/** The header the front puts its secret in. */
|
|
2
38
|
export const FRONT = "x-copilotz-front";
|
|
3
39
|
/** Whether two strings are the same, taking as long whatever their first difference. */
|
|
@@ -197,11 +233,7 @@ export function hostServer(runtime, whom, options = {}) {
|
|
|
197
233
|
const found = hosts.find((h) => hostMatches(h.pattern, host) && (!h.route.methods || h.route.methods.includes(request.method)));
|
|
198
234
|
if (!found)
|
|
199
235
|
return undefined;
|
|
200
|
-
return answered(runtime, found.name, found.route, request, new URL(request.url),
|
|
201
|
-
runtime,
|
|
202
|
-
whom: () => whom(request),
|
|
203
|
-
host,
|
|
204
|
-
});
|
|
236
|
+
return answered(runtime, found.name, found.route, request, new URL(request.url), served(runtime, request, whom, host));
|
|
205
237
|
};
|
|
206
238
|
}
|
|
207
239
|
/**
|
|
@@ -224,10 +256,33 @@ export function routeServer(runtime, whom, options = {}) {
|
|
|
224
256
|
const found = match(url, request.method);
|
|
225
257
|
if (!found)
|
|
226
258
|
return undefined;
|
|
227
|
-
return answered(runtime, found.name, found.route, request, url,
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
259
|
+
return answered(runtime, found.name, found.route, request, url, served(runtime, request, whom, hostOf(request, options.front)));
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/** Where a host without the web app says it's up. */
|
|
263
|
+
const HEALTH = "/health";
|
|
264
|
+
/**
|
|
265
|
+
* A host for an app without the web app (on WhatsApp, on the phone): its
|
|
266
|
+
* routes alone, by host and then by path, their sockets included; `GET
|
|
267
|
+
* /health`, unless a route takes it; and 404 for anything else. Nobody signs
|
|
268
|
+
* in here: a route's Action is called as a visitor, and its `allow` decides.
|
|
269
|
+
* `serveRoutes` (`copilotz/web/node`) listens with it.
|
|
270
|
+
*/
|
|
271
|
+
export function routeHost(runtime, options = {}) {
|
|
272
|
+
const routes = routeServer(runtime, () => Promise.resolve(null), options);
|
|
273
|
+
return async (request) => {
|
|
274
|
+
const answering = routes(request);
|
|
275
|
+
if (answering)
|
|
276
|
+
return await answering;
|
|
277
|
+
const healthy = (request.method === "GET" || request.method === "HEAD") &&
|
|
278
|
+
new URL(request.url).pathname === HEALTH;
|
|
279
|
+
return healthy ? plain(200, "ok") : plain(404, "Not found");
|
|
232
280
|
};
|
|
233
281
|
}
|
|
282
|
+
/** What a `serve` route is given for a request. */
|
|
283
|
+
const served = (runtime, request, whom, host) => ({
|
|
284
|
+
runtime,
|
|
285
|
+
whom: () => whom(request),
|
|
286
|
+
host,
|
|
287
|
+
upgrade: (options) => upgradeWebSocket(request, options),
|
|
288
|
+
});
|
package/hosts/web/server.d.ts
CHANGED
|
@@ -25,9 +25,10 @@
|
|
|
25
25
|
* (chat's `file.content`), with ranges for audio; `?download=1` saves it
|
|
26
26
|
* (see `files.ts`).
|
|
27
27
|
* - Plugins' own paths, their `routes` resource: a webhook, an OAuth callback,
|
|
28
|
-
* an API, a download (see `routes.ts`). A request to
|
|
29
|
-
* (a preview's) is that route's alone, whatever its
|
|
30
|
-
* the code or the socket.
|
|
28
|
+
* an API, a download, a socket of their own (see `routes.ts`). A request to
|
|
29
|
+
* a host a route takes (a preview's) is that route's alone, whatever its
|
|
30
|
+
* path: never the page, the code or the socket. An app without the web app
|
|
31
|
+
* serves them alone (`routeHost`).
|
|
31
32
|
* - `GET /manifest.webmanifest` and `GET /sw.js`: the app, installable: its
|
|
32
33
|
* manifest (name, colours, icons drawn from the theme's mark) and its
|
|
33
34
|
* service worker, which keeps the code at hand and offers new versions
|
|
@@ -107,7 +108,7 @@ export type WebServerOptions = {
|
|
|
107
108
|
front?: Front;
|
|
108
109
|
};
|
|
109
110
|
export type { Asset };
|
|
110
|
-
export { type Front, hostMatches, hostOf, type HttpAnswer, type HttpRequest, httpRequest, type Route, type Served, VISITOR, } from "./routes.js";
|
|
111
|
+
export { type Front, hostMatches, hostOf, type HttpAnswer, type HttpRequest, httpRequest, type Route, routeHost, type RouteSocket, type Served, VISITOR, } from "./routes.js";
|
|
111
112
|
/**
|
|
112
113
|
* Bundled code: its files by name (`deno bundle --code-splitting --outdir`'s),
|
|
113
114
|
* the entry and the chunks it imports by relative path, and which one the
|
package/hosts/web/server.js
CHANGED
|
@@ -7,7 +7,7 @@ import { HOST_ASSETS, hostFiles } from "./theme/files/mod.js";
|
|
|
7
7
|
import { routeServer } from "./routes.js";
|
|
8
8
|
import { ownPath } from "./theme/own-path.js";
|
|
9
9
|
import { pictureOf } from "./theme/picture.js";
|
|
10
|
-
export { hostMatches, hostOf, httpRequest, VISITOR, } from "./routes.js";
|
|
10
|
+
export { hostMatches, hostOf, httpRequest, routeHost, VISITOR, } from "./routes.js";
|
|
11
11
|
/** Where the code is served. */
|
|
12
12
|
const CODE = "/app/";
|
|
13
13
|
const COOKIE = "session";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "copilotz",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.21",
|
|
4
4
|
"description": "Copilotz: one runtime for Node, Deno, Bun, Cloudflare Workers and the browser.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -184,7 +184,7 @@
|
|
|
184
184
|
"ink": "8.0.0",
|
|
185
185
|
"json-schema-to-ts": "3.1.1",
|
|
186
186
|
"ominipg": "0.11.2",
|
|
187
|
-
"oxianjs": "0.23.
|
|
187
|
+
"oxianjs": "0.23.3",
|
|
188
188
|
"pg": "8.23.1",
|
|
189
189
|
"temml": "0.14.0"
|
|
190
190
|
},
|
|
@@ -93,13 +93,13 @@ export declare const account: {
|
|
|
93
93
|
private?: string[];
|
|
94
94
|
queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
|
|
95
95
|
[x: string]: unknown;
|
|
96
|
-
rev?: number | undefined;
|
|
97
96
|
problem?: string | undefined;
|
|
97
|
+
rev?: number | undefined;
|
|
98
98
|
plan?: string | undefined;
|
|
99
99
|
expires?: string | undefined;
|
|
100
100
|
refreshed?: string | undefined;
|
|
101
|
-
status: "revoked" | "connected" | "needs_reconnect";
|
|
102
101
|
person: string;
|
|
102
|
+
status: "revoked" | "connected" | "needs_reconnect";
|
|
103
103
|
provider: string;
|
|
104
104
|
label: string;
|
|
105
105
|
connected: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const chatAction: import("../../../../runtime/define.js").ActionDef;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `contact.chat`: a chat for a contact, in the line's space: chat opens it
|
|
3
|
+
* (`chat.open`, answered by `agent`, else by who answers new chats there),
|
|
4
|
+
* and it's shared with the contact on its own (`member.set`, `on` the
|
|
5
|
+
* thread). They reach it, what's said in it and its files, and nothing else
|
|
6
|
+
* in the space; its members reach it as any chat there. With `thread`, that
|
|
7
|
+
* is its id (from what brought them), so a retry opens the same one. Made by
|
|
8
|
+
* trusted code, which knows who the contact is.
|
|
9
|
+
*/
|
|
10
|
+
import { defineAction } from "../../../../runtime/mod.js";
|
|
11
|
+
export const chatAction = defineAction({
|
|
12
|
+
description: "Opens a chat for a contact, shared with them",
|
|
13
|
+
input: {
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
contact: { type: "string", minLength: 1 },
|
|
17
|
+
in: { type: "string", minLength: 1 },
|
|
18
|
+
thread: { type: "string", minLength: 1, maxLength: 200 },
|
|
19
|
+
agent: { type: "string", minLength: 1 },
|
|
20
|
+
title: { type: "string", minLength: 1, maxLength: 120 },
|
|
21
|
+
},
|
|
22
|
+
required: ["contact", "in"],
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
},
|
|
25
|
+
run: async (ctx, input) => {
|
|
26
|
+
const contact = await ctx.db.collection("contact").findOne({ _id: input.contact });
|
|
27
|
+
if (!contact) {
|
|
28
|
+
throw Object.assign(new Error(`No contact "${input.contact}".`), { code: "not_found" });
|
|
29
|
+
}
|
|
30
|
+
const title = input.title ?? contact.name;
|
|
31
|
+
const { thread } = await ctx.call("chat.open", {
|
|
32
|
+
in: input.in,
|
|
33
|
+
...(input.thread ? { thread: input.thread } : {}),
|
|
34
|
+
...(input.agent ? { agents: [input.agent] } : {}),
|
|
35
|
+
...(title ? { title: title.slice(0, 120) } : {}),
|
|
36
|
+
});
|
|
37
|
+
await ctx.call("member.set", {
|
|
38
|
+
space: thread,
|
|
39
|
+
on: "thread",
|
|
40
|
+
member: { kind: "contact", id: contact._id },
|
|
41
|
+
role: "editor",
|
|
42
|
+
});
|
|
43
|
+
return { thread };
|
|
44
|
+
},
|
|
45
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const forgetAction: import("../../../../runtime/define.js").ActionDef;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `contact.forget`: a contact erased (LGPD, GDPR), by those who manage the
|
|
3
|
+
* space its record lives in. Its memberships go, which ends its access to
|
|
4
|
+
* every chat at once (`member.deleted`), and so does its record
|
|
5
|
+
* (`contact.deleted`: the WhatsApp plugin erases its phone, but not a block
|
|
6
|
+
* on it, kept by a hash). With `chats`, its chats go too, with everything
|
|
7
|
+
* chat and its plugins keep of them (`chat.erase`), each only for someone
|
|
8
|
+
* who manages that chat's space.
|
|
9
|
+
*
|
|
10
|
+
* What's not erased here: the event log, which keeps what happened (what
|
|
11
|
+
* WhatsApp delivered, with the phone and what it said; each change, with
|
|
12
|
+
* its document) until retention removes it; and what's elsewhere, such as
|
|
13
|
+
* memories learned in staff's own chats, or chats a hand-over opened in
|
|
14
|
+
* other spaces.
|
|
15
|
+
*/
|
|
16
|
+
import { defineAction, failure, inPerson } from "../../../../runtime/mod.js";
|
|
17
|
+
import { must } from "../../spaces/contract.js";
|
|
18
|
+
import { CONTACT } from "../collections/contact.js";
|
|
19
|
+
export const forgetAction = defineAction({
|
|
20
|
+
description: "Erases a contact: its access, its record, and with `chats`, its chats",
|
|
21
|
+
input: {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: { contact: { type: "string" }, chats: { type: "boolean" } },
|
|
24
|
+
required: ["contact"],
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
},
|
|
27
|
+
allow: inPerson,
|
|
28
|
+
run: async (ctx, input) => {
|
|
29
|
+
const system = ctx.as();
|
|
30
|
+
const contact = await system.db.collection("contact").findOne({ _id: input.contact });
|
|
31
|
+
if (!contact)
|
|
32
|
+
throw failure("not_found", `No contact "${input.contact}".`);
|
|
33
|
+
await must(ctx, "manage", contact.in, "Only those who manage its space erase a contact.");
|
|
34
|
+
const key = `${CONTACT}${contact._id}`;
|
|
35
|
+
const memberships = await system.db.collection("member").find({ member: key });
|
|
36
|
+
const chats = memberships.filter((m) => m.on === "thread")
|
|
37
|
+
.map((m) => m.space.slice("thread:".length));
|
|
38
|
+
if (input.chats) {
|
|
39
|
+
// Each chat's own space decides: it may have moved since the contact came.
|
|
40
|
+
const threads = await system.db.collection("thread")
|
|
41
|
+
.find({ _id: { $in: chats } });
|
|
42
|
+
for (const thread of threads) {
|
|
43
|
+
if (thread.in) {
|
|
44
|
+
await must(ctx, "manage", thread.in, "Only those who manage its chats erase them.");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const thread of threads)
|
|
48
|
+
await system.call("chat.erase", { thread: thread._id });
|
|
49
|
+
}
|
|
50
|
+
await system.transaction(async (tx) => {
|
|
51
|
+
await tx.db.collection("member").deleteMany({ member: key });
|
|
52
|
+
await tx.db.collection("contact").deleteOne({ _id: contact._id });
|
|
53
|
+
});
|
|
54
|
+
return { forgotten: contact._id, chats: input.chats ? chats.length : 0 };
|
|
55
|
+
},
|
|
56
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const startAction: import("../../../../runtime/define.js").ActionDef;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `contact.start`: someone outside the org came by a line (wrote to a
|
|
3
|
+
* WhatsApp number), and is a contact now. Made by trusted code, which
|
|
4
|
+
* proved who they are (Meta's signed webhook names the phone), with an id
|
|
5
|
+
* from what brought them (`id`), so a retry makes the same one; starting
|
|
6
|
+
* one that exists changes only its name, if that changed. Its record is
|
|
7
|
+
* shared with it on its own (it reads it, and the agent working for it does).
|
|
8
|
+
*/
|
|
9
|
+
import { defineAction } from "../../../../runtime/mod.js";
|
|
10
|
+
export const startAction = defineAction({
|
|
11
|
+
description: "Makes a contact: someone outside the org who came by a line",
|
|
12
|
+
input: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
/** Its id, from what brought it (no personal data: it ends up in events). */
|
|
16
|
+
id: { type: "string", pattern: "^c-[\\w-]{6,80}$" },
|
|
17
|
+
/** The line's space, where its record lives. */
|
|
18
|
+
in: { type: "string", minLength: 1 },
|
|
19
|
+
via: { type: "string", minLength: 1, maxLength: 40 },
|
|
20
|
+
name: { type: "string", maxLength: 120 },
|
|
21
|
+
},
|
|
22
|
+
required: ["in", "via"],
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
},
|
|
25
|
+
run: async (ctx, input) => {
|
|
26
|
+
const contacts = ctx.db.collection("contact");
|
|
27
|
+
const id = input.id ?? `c-${crypto.randomUUID()}`;
|
|
28
|
+
const name = input.name?.trim();
|
|
29
|
+
const known = await contacts.findOne({ _id: id });
|
|
30
|
+
if (known) {
|
|
31
|
+
if (name && known.name !== name)
|
|
32
|
+
await contacts.updateOne({ _id: id }, { $set: { name } });
|
|
33
|
+
return { contact: id };
|
|
34
|
+
}
|
|
35
|
+
await contacts.insertOne({
|
|
36
|
+
_id: id,
|
|
37
|
+
in: input.in,
|
|
38
|
+
via: input.via,
|
|
39
|
+
...(name ? { name } : {}),
|
|
40
|
+
at: new Date().toISOString(),
|
|
41
|
+
});
|
|
42
|
+
await ctx.call("member.set", {
|
|
43
|
+
space: id,
|
|
44
|
+
on: "contact",
|
|
45
|
+
member: { kind: "contact", id },
|
|
46
|
+
role: "viewer",
|
|
47
|
+
});
|
|
48
|
+
return { contact: id };
|
|
49
|
+
},
|
|
50
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contacts: people outside the org who talk to its agents (a WhatsApp
|
|
3
|
+
* customer), one record each, `in` the space of the line they first came
|
|
4
|
+
* by: that space's members read it, as they read the contact's chats there.
|
|
5
|
+
* Its id says nothing about them (`c-…`): it ends up in memberships, in
|
|
6
|
+
* messages' `from`, in events. The contact reads its own record, and so does
|
|
7
|
+
* the agent working for them (it's shared with them on its own, as their
|
|
8
|
+
* chats are), and no one else's.
|
|
9
|
+
*/
|
|
10
|
+
import { type Actor, type Infer } from "../../../../runtime/mod.js";
|
|
11
|
+
declare const contactSchema: {
|
|
12
|
+
readonly type: "object";
|
|
13
|
+
readonly properties: {
|
|
14
|
+
/** The space of the line it first came by. */
|
|
15
|
+
readonly in: {
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
};
|
|
18
|
+
/** Where it first came from: `whatsapp`. */
|
|
19
|
+
readonly via: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
};
|
|
22
|
+
/** What it's called: its WhatsApp profile's name. */
|
|
23
|
+
readonly name: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
};
|
|
26
|
+
readonly at: {
|
|
27
|
+
readonly type: "string";
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
readonly required: readonly ["in", "via", "at"];
|
|
31
|
+
};
|
|
32
|
+
/** How a contact shows as an actor, in a message's `from` and among names. */
|
|
33
|
+
export declare const CONTACT = "contact:";
|
|
34
|
+
export declare const contact: {
|
|
35
|
+
schema: {
|
|
36
|
+
readonly type: "object";
|
|
37
|
+
readonly properties: {
|
|
38
|
+
/** The space of the line it first came by. */
|
|
39
|
+
readonly in: {
|
|
40
|
+
readonly type: "string";
|
|
41
|
+
};
|
|
42
|
+
/** Where it first came from: `whatsapp`. */
|
|
43
|
+
readonly via: {
|
|
44
|
+
readonly type: "string";
|
|
45
|
+
};
|
|
46
|
+
/** What it's called: its WhatsApp profile's name. */
|
|
47
|
+
readonly name: {
|
|
48
|
+
readonly type: "string";
|
|
49
|
+
};
|
|
50
|
+
readonly at: {
|
|
51
|
+
readonly type: "string";
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
readonly required: readonly ["in", "via", "at"];
|
|
55
|
+
};
|
|
56
|
+
events?: boolean;
|
|
57
|
+
records?: boolean;
|
|
58
|
+
durable?: false;
|
|
59
|
+
indexes?: string[][];
|
|
60
|
+
private?: string[];
|
|
61
|
+
queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
|
|
62
|
+
[x: string]: unknown;
|
|
63
|
+
name?: string | undefined;
|
|
64
|
+
at: string;
|
|
65
|
+
via: string;
|
|
66
|
+
in: string;
|
|
67
|
+
} & {
|
|
68
|
+
_id: string;
|
|
69
|
+
}>> | undefined;
|
|
70
|
+
vectors?: string[];
|
|
71
|
+
};
|
|
72
|
+
export type Contact = Infer<typeof contactSchema> & {
|
|
73
|
+
_id: string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The contact whose work this is, if it's a contact's: an event's actor, a
|
|
77
|
+
* turn's (an agent working for them), a tool's. Undefined for a person's
|
|
78
|
+
* work, or the system's.
|
|
79
|
+
*/
|
|
80
|
+
export declare function contactOf(actor: Actor | undefined): string | undefined;
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contacts: people outside the org who talk to its agents (a WhatsApp
|
|
3
|
+
* customer), one record each, `in` the space of the line they first came
|
|
4
|
+
* by: that space's members read it, as they read the contact's chats there.
|
|
5
|
+
* Its id says nothing about them (`c-…`): it ends up in memberships, in
|
|
6
|
+
* messages' `from`, in events. The contact reads its own record, and so does
|
|
7
|
+
* the agent working for them (it's shared with them on its own, as their
|
|
8
|
+
* chats are), and no one else's.
|
|
9
|
+
*/
|
|
10
|
+
import { defineCollection, principalOf } from "../../../../runtime/mod.js";
|
|
11
|
+
import { namesOf } from "../../spaces/contract.js";
|
|
12
|
+
const contactSchema = {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
/** The space of the line it first came by. */
|
|
16
|
+
in: { type: "string" },
|
|
17
|
+
/** Where it first came from: `whatsapp`. */
|
|
18
|
+
via: { type: "string" },
|
|
19
|
+
/** What it's called: its WhatsApp profile's name. */
|
|
20
|
+
name: { type: "string" },
|
|
21
|
+
at: { type: "string" },
|
|
22
|
+
},
|
|
23
|
+
required: ["in", "via", "at"],
|
|
24
|
+
};
|
|
25
|
+
/** How a contact shows as an actor, in a message's `from` and among names. */
|
|
26
|
+
export const CONTACT = "contact:";
|
|
27
|
+
export const contact = defineCollection({
|
|
28
|
+
schema: contactSchema,
|
|
29
|
+
queries: {
|
|
30
|
+
/**
|
|
31
|
+
* Names by id (`{ ids }`, each `contact:<id>`), as the asker reads them:
|
|
32
|
+
* the spaces' `names` resource asks here for ids that start so.
|
|
33
|
+
*/
|
|
34
|
+
names: {
|
|
35
|
+
allow: (actor) => actor.kind === "person" || actor.kind === "agent",
|
|
36
|
+
run: async (contacts, params) => {
|
|
37
|
+
const given = Array.isArray(params?.ids) ? params.ids : [];
|
|
38
|
+
const ids = [
|
|
39
|
+
...new Set(given.filter((id) => typeof id === "string" && id.startsWith(CONTACT))
|
|
40
|
+
.map((id) => id.slice(CONTACT.length))),
|
|
41
|
+
].slice(0, 500);
|
|
42
|
+
if (!ids.length)
|
|
43
|
+
return {};
|
|
44
|
+
const named = namesOf(await contacts.find({ _id: { $in: ids } }));
|
|
45
|
+
return Object.fromEntries(Object.entries(named).map(([id, name]) => [`${CONTACT}${id}`, name]));
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* The contact whose work this is, if it's a contact's: an event's actor, a
|
|
52
|
+
* turn's (an agent working for them), a tool's. Undefined for a person's
|
|
53
|
+
* work, or the system's.
|
|
54
|
+
*/
|
|
55
|
+
export function contactOf(actor) {
|
|
56
|
+
const principal = principalOf(actor);
|
|
57
|
+
return principal?.kind === "contact" ? principal.id : undefined;
|
|
58
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contacts plugin's contract: what other plugins and apps may import:
|
|
3
|
+
* the shape of a contact, how one shows as an actor (`contact:<id>`, a
|
|
4
|
+
* message's `from`), and whose work an actor's is (`contactOf(event.actor)`:
|
|
5
|
+
* the contact's id, also for the agent working for them). They reach the
|
|
6
|
+
* rest by name: its collection (`contact`, and its `names` query), its
|
|
7
|
+
* Actions (`contact.start`, `contact.chat`, `contact.forget`) and the
|
|
8
|
+
* event its record's erasure is (`contact.deleted`).
|
|
9
|
+
*/
|
|
10
|
+
export { CONTACT, type Contact, contactOf } from "./collections/contact.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contacts plugin's contract: what other plugins and apps may import:
|
|
3
|
+
* the shape of a contact, how one shows as an actor (`contact:<id>`, a
|
|
4
|
+
* message's `from`), and whose work an actor's is (`contactOf(event.actor)`:
|
|
5
|
+
* the contact's id, also for the agent working for them). They reach the
|
|
6
|
+
* rest by name: its collection (`contact`, and its `names` query), its
|
|
7
|
+
* Actions (`contact.start`, `contact.chat`, `contact.forget`) and the
|
|
8
|
+
* event its record's erasure is (`contact.deleted`).
|
|
9
|
+
*/
|
|
10
|
+
export { CONTACT, contactOf } from "./collections/contact.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contacts: people outside the org who talk to its agents, such as a
|
|
3
|
+
* WhatsApp customer writing to a business's number. Each is its own kind of
|
|
4
|
+
* actor, `{ kind: "contact", id }`, never a person: every Action and query
|
|
5
|
+
* stays shut to them unless it says otherwise (`peopleOrContacts`, as
|
|
6
|
+
* `chat.send` does), and nothing that checks for a person finds one.
|
|
7
|
+
*
|
|
8
|
+
* - **A contact** is made by trusted code that proved who they are
|
|
9
|
+
* (`contact.start`; Meta's signed webhook names the phone), with its
|
|
10
|
+
* record (`contact`) `in` the line's space: its members read it.
|
|
11
|
+
* - **Their chat** (`contact.chat`) is opened in that space and shared with
|
|
12
|
+
* them on its own: they reach it, its messages and files, and nothing
|
|
13
|
+
* else; the space's members reach it as any chat there. An agent working
|
|
14
|
+
* for a contact reaches what both reach: that chat.
|
|
15
|
+
* - **Agents are told** who they're talking with (the `contact` context),
|
|
16
|
+
* and see them by name ("People here: Ana": a `names` source, `contact:`).
|
|
17
|
+
* - **Erasing one** (`contact.forget`, by its space's managers) ends its
|
|
18
|
+
* access at once and deletes its record, and with `chats` its chats.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* plugins: [models, chat, ...access] // access brings contacts
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import { type Plugin } from "../../../runtime/mod.js";
|
|
25
|
+
export * from "./contract.js";
|
|
26
|
+
export declare const contacts: Plugin;
|
|
27
|
+
export default contacts;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contacts: people outside the org who talk to its agents, such as a
|
|
3
|
+
* WhatsApp customer writing to a business's number. Each is its own kind of
|
|
4
|
+
* actor, `{ kind: "contact", id }`, never a person: every Action and query
|
|
5
|
+
* stays shut to them unless it says otherwise (`peopleOrContacts`, as
|
|
6
|
+
* `chat.send` does), and nothing that checks for a person finds one.
|
|
7
|
+
*
|
|
8
|
+
* - **A contact** is made by trusted code that proved who they are
|
|
9
|
+
* (`contact.start`; Meta's signed webhook names the phone), with its
|
|
10
|
+
* record (`contact`) `in` the line's space: its members read it.
|
|
11
|
+
* - **Their chat** (`contact.chat`) is opened in that space and shared with
|
|
12
|
+
* them on its own: they reach it, its messages and files, and nothing
|
|
13
|
+
* else; the space's members reach it as any chat there. An agent working
|
|
14
|
+
* for a contact reaches what both reach: that chat.
|
|
15
|
+
* - **Agents are told** who they're talking with (the `contact` context),
|
|
16
|
+
* and see them by name ("People here: Ana": a `names` source, `contact:`).
|
|
17
|
+
* - **Erasing one** (`contact.forget`, by its space's managers) ends its
|
|
18
|
+
* access at once and deletes its record, and with `chats` its chats.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* plugins: [models, chat, ...access] // access brings contacts
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import { definePlugin } from "../../../runtime/mod.js";
|
|
25
|
+
import { chatAction } from "./actions/chat.js";
|
|
26
|
+
import { forgetAction } from "./actions/forget.js";
|
|
27
|
+
import { startAction } from "./actions/start.js";
|
|
28
|
+
import { CONTACT, contact } from "./collections/contact.js";
|
|
29
|
+
import { contactView } from "./views/contact.js";
|
|
30
|
+
export * from "./contract.js";
|
|
31
|
+
export const contacts = definePlugin({
|
|
32
|
+
name: "contacts",
|
|
33
|
+
requires: ["spaces"],
|
|
34
|
+
collections: { contact },
|
|
35
|
+
actions: {
|
|
36
|
+
"contact.start": startAction,
|
|
37
|
+
"contact.chat": chatAction,
|
|
38
|
+
"contact.forget": forgetAction,
|
|
39
|
+
},
|
|
40
|
+
views: { "context:contact": { llm: contactView } },
|
|
41
|
+
resources: {
|
|
42
|
+
// A contact's record lives in its line's space; only trusted code changes it. A contact is a
|
|
43
|
+
// member (of its chats, and of its own record): reading it labels nothing, as for an agent.
|
|
44
|
+
shared: { contact: { write: "manage", member: "contact" } },
|
|
45
|
+
names: { contact: { collection: "contact", prefix: CONTACT } },
|
|
46
|
+
context: { contact: { place: "system" } },
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
export default contacts;
|