@pinecall/agents 0.9.20
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/LICENSE +202 -0
- package/README.md +121 -0
- package/dist/agent/accepts.d.ts +31 -0
- package/dist/agent/accepts.d.ts.map +1 -0
- package/dist/agent/accepts.js +27 -0
- package/dist/agent/accepts.js.map +1 -0
- package/dist/agent/agent.d.ts +151 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +240 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/authors.d.ts +12 -0
- package/dist/agent/authors.d.ts.map +1 -0
- package/dist/agent/authors.js +26 -0
- package/dist/agent/authors.js.map +1 -0
- package/dist/agent/decorators.d.ts +16 -0
- package/dist/agent/decorators.d.ts.map +1 -0
- package/dist/agent/decorators.js +43 -0
- package/dist/agent/decorators.js.map +1 -0
- package/dist/agent/docstrings.d.ts +35 -0
- package/dist/agent/docstrings.d.ts.map +1 -0
- package/dist/agent/docstrings.js +301 -0
- package/dist/agent/docstrings.js.map +1 -0
- package/dist/agent/knowledge.d.ts +9 -0
- package/dist/agent/knowledge.d.ts.map +1 -0
- package/dist/agent/knowledge.js +3 -0
- package/dist/agent/knowledge.js.map +1 -0
- package/dist/agent/lifecycle.d.ts +29 -0
- package/dist/agent/lifecycle.d.ts.map +1 -0
- package/dist/agent/lifecycle.js +9 -0
- package/dist/agent/lifecycle.js.map +1 -0
- package/dist/agent/searching.d.ts +7 -0
- package/dist/agent/searching.d.ts.map +1 -0
- package/dist/agent/searching.js +35 -0
- package/dist/agent/searching.js.map +1 -0
- package/dist/agent/stages.d.ts +23 -0
- package/dist/agent/stages.d.ts.map +1 -0
- package/dist/agent/stages.js +29 -0
- package/dist/agent/stages.js.map +1 -0
- package/dist/agent/state.d.ts +36 -0
- package/dist/agent/state.d.ts.map +1 -0
- package/dist/agent/state.js +93 -0
- package/dist/agent/state.js.map +1 -0
- package/dist/agent/tools.d.ts +61 -0
- package/dist/agent/tools.d.ts.map +1 -0
- package/dist/agent/tools.js +145 -0
- package/dist/agent/tools.js.map +1 -0
- package/dist/agent/view.d.ts +29 -0
- package/dist/agent/view.d.ts.map +1 -0
- package/dist/agent/view.js +29 -0
- package/dist/agent/view.js.map +1 -0
- package/dist/agent/visibility.d.ts +32 -0
- package/dist/agent/visibility.d.ts.map +1 -0
- package/dist/agent/visibility.js +77 -0
- package/dist/agent/visibility.js.map +1 -0
- package/dist/call/call.d.ts +137 -0
- package/dist/call/call.d.ts.map +1 -0
- package/dist/call/call.js +228 -0
- package/dist/call/call.js.map +1 -0
- package/dist/call/history.d.ts +28 -0
- package/dist/call/history.d.ts.map +1 -0
- package/dist/call/history.js +32 -0
- package/dist/call/history.js.map +1 -0
- package/dist/call/room.d.ts +56 -0
- package/dist/call/room.d.ts.map +1 -0
- package/dist/call/room.js +66 -0
- package/dist/call/room.js.map +1 -0
- package/dist/client/agent.d.ts +93 -0
- package/dist/client/agent.d.ts.map +1 -0
- package/dist/client/agent.js +230 -0
- package/dist/client/agent.js.map +1 -0
- package/dist/client/calls.d.ts +87 -0
- package/dist/client/calls.d.ts.map +1 -0
- package/dist/client/calls.js +180 -0
- package/dist/client/calls.js.map +1 -0
- package/dist/client/client.d.ts +112 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +284 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/connection.d.ts +52 -0
- package/dist/client/connection.d.ts.map +1 -0
- package/dist/client/connection.js +157 -0
- package/dist/client/connection.js.map +1 -0
- package/dist/client/endpoints.d.ts +9 -0
- package/dist/client/endpoints.d.ts.map +1 -0
- package/dist/client/endpoints.js +25 -0
- package/dist/client/endpoints.js.map +1 -0
- package/dist/client/frames.d.ts +29 -0
- package/dist/client/frames.d.ts.map +1 -0
- package/dist/client/frames.js +51 -0
- package/dist/client/frames.js.map +1 -0
- package/dist/client/index.d.ts +18 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +13 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/listeners.d.ts +35 -0
- package/dist/client/listeners.d.ts.map +1 -0
- package/dist/client/listeners.js +60 -0
- package/dist/client/listeners.js.map +1 -0
- package/dist/client/lost.d.ts +4 -0
- package/dist/client/lost.d.ts.map +1 -0
- package/dist/client/lost.js +8 -0
- package/dist/client/lost.js.map +1 -0
- package/dist/client/observe.d.ts +50 -0
- package/dist/client/observe.d.ts.map +1 -0
- package/dist/client/observe.js +125 -0
- package/dist/client/observe.js.map +1 -0
- package/dist/client/signed.d.ts +14 -0
- package/dist/client/signed.d.ts.map +1 -0
- package/dist/client/signed.js +18 -0
- package/dist/client/signed.js.map +1 -0
- package/dist/client/testing/gateway.d.ts +58 -0
- package/dist/client/testing/gateway.d.ts.map +1 -0
- package/dist/client/testing/gateway.js +175 -0
- package/dist/client/testing/gateway.js.map +1 -0
- package/dist/client/testing/index.d.ts +4 -0
- package/dist/client/testing/index.d.ts.map +1 -0
- package/dist/client/testing/index.js +4 -0
- package/dist/client/testing/index.js.map +1 -0
- package/dist/client/testing/log.d.ts +24 -0
- package/dist/client/testing/log.d.ts.map +1 -0
- package/dist/client/testing/log.js +106 -0
- package/dist/client/testing/log.js.map +1 -0
- package/dist/client/testing/loopback.d.ts +3 -0
- package/dist/client/testing/loopback.d.ts.map +1 -0
- package/dist/client/testing/loopback.js +3 -0
- package/dist/client/testing/loopback.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/connect.d.ts +42 -0
- package/dist/runtime/connect.d.ts.map +1 -0
- package/dist/runtime/connect.js +234 -0
- package/dist/runtime/connect.js.map +1 -0
- package/dist/runtime/dispatch.d.ts +32 -0
- package/dist/runtime/dispatch.d.ts.map +1 -0
- package/dist/runtime/dispatch.js +46 -0
- package/dist/runtime/dispatch.js.map +1 -0
- package/dist/runtime/environment.d.ts +7 -0
- package/dist/runtime/environment.d.ts.map +1 -0
- package/dist/runtime/environment.js +30 -0
- package/dist/runtime/environment.js.map +1 -0
- package/dist/runtime/recall.d.ts +9 -0
- package/dist/runtime/recall.d.ts.map +1 -0
- package/dist/runtime/recall.js +13 -0
- package/dist/runtime/recall.js.map +1 -0
- package/dist/runtime/run-tool.d.ts +18 -0
- package/dist/runtime/run-tool.d.ts.map +1 -0
- package/dist/runtime/run-tool.js +70 -0
- package/dist/runtime/run-tool.js.map +1 -0
- package/dist/serve/index.d.ts +5 -0
- package/dist/serve/index.d.ts.map +1 -0
- package/dist/serve/index.js +50 -0
- package/dist/serve/index.js.map +1 -0
- package/dist/serve/io.d.ts +14 -0
- package/dist/serve/io.d.ts.map +1 -0
- package/dist/serve/io.js +6 -0
- package/dist/serve/io.js.map +1 -0
- package/dist/serve/leaving.d.ts +12 -0
- package/dist/serve/leaving.d.ts.map +1 -0
- package/dist/serve/leaving.js +61 -0
- package/dist/serve/leaving.js.map +1 -0
- package/dist/serve/lines.d.ts +7 -0
- package/dist/serve/lines.d.ts.map +1 -0
- package/dist/serve/lines.js +25 -0
- package/dist/serve/lines.js.map +1 -0
- package/dist/serve/load.d.ts +26 -0
- package/dist/serve/load.d.ts.map +1 -0
- package/dist/serve/load.js +61 -0
- package/dist/serve/load.js.map +1 -0
- package/dist/serve/machine.d.ts +4 -0
- package/dist/serve/machine.d.ts.map +1 -0
- package/dist/serve/machine.js +33 -0
- package/dist/serve/machine.js.map +1 -0
- package/dist/serve/prompt.d.ts +7 -0
- package/dist/serve/prompt.d.ts.map +1 -0
- package/dist/serve/prompt.js +51 -0
- package/dist/serve/prompt.js.map +1 -0
- package/dist/serve/start.d.ts +7 -0
- package/dist/serve/start.d.ts.map +1 -0
- package/dist/serve/start.js +95 -0
- package/dist/serve/start.js.map +1 -0
- package/dist/serve/viewing.d.ts +17 -0
- package/dist/serve/viewing.d.ts.map +1 -0
- package/dist/serve/viewing.js +42 -0
- package/dist/serve/viewing.js.map +1 -0
- package/dist/views/built-in-rules.d.ts +9 -0
- package/dist/views/built-in-rules.d.ts.map +1 -0
- package/dist/views/built-in-rules.js +28 -0
- package/dist/views/built-in-rules.js.map +1 -0
- package/dist/views/components.d.ts +17 -0
- package/dist/views/components.d.ts.map +1 -0
- package/dist/views/components.js +33 -0
- package/dist/views/components.js.map +1 -0
- package/dist/views/jsx-dev-runtime.d.ts +3 -0
- package/dist/views/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/views/jsx-dev-runtime.js +4 -0
- package/dist/views/jsx-dev-runtime.js.map +1 -0
- package/dist/views/jsx-runtime.d.ts +46 -0
- package/dist/views/jsx-runtime.d.ts.map +1 -0
- package/dist/views/jsx-runtime.js +63 -0
- package/dist/views/jsx-runtime.js.map +1 -0
- package/dist/views/layout.d.ts +19 -0
- package/dist/views/layout.d.ts.map +1 -0
- package/dist/views/layout.js +58 -0
- package/dist/views/layout.js.map +1 -0
- package/dist/views/nodes.d.ts +48 -0
- package/dist/views/nodes.d.ts.map +1 -0
- package/dist/views/nodes.js +45 -0
- package/dist/views/nodes.js.map +1 -0
- package/dist/views/panels.d.ts +17 -0
- package/dist/views/panels.d.ts.map +1 -0
- package/dist/views/panels.js +62 -0
- package/dist/views/panels.js.map +1 -0
- package/dist/views/render.d.ts +11 -0
- package/dist/views/render.d.ts.map +1 -0
- package/dist/views/render.js +19 -0
- package/dist/views/render.js.map +1 -0
- package/dist/wire/agent-config.d.ts +213 -0
- package/dist/wire/agent-config.d.ts.map +1 -0
- package/dist/wire/agent-config.js +126 -0
- package/dist/wire/agent-config.js.map +1 -0
- package/dist/wire/codec.d.ts +43 -0
- package/dist/wire/codec.d.ts.map +1 -0
- package/dist/wire/codec.js +51 -0
- package/dist/wire/codec.js.map +1 -0
- package/dist/wire/commands.d.ts +443 -0
- package/dist/wire/commands.d.ts.map +1 -0
- package/dist/wire/commands.js +203 -0
- package/dist/wire/commands.js.map +1 -0
- package/dist/wire/defs.d.ts +373 -0
- package/dist/wire/defs.d.ts.map +1 -0
- package/dist/wire/defs.js +212 -0
- package/dist/wire/defs.js.map +1 -0
- package/dist/wire/envelope.d.ts +29 -0
- package/dist/wire/envelope.d.ts.map +1 -0
- package/dist/wire/envelope.js +27 -0
- package/dist/wire/envelope.js.map +1 -0
- package/dist/wire/events-call.d.ts +446 -0
- package/dist/wire/events-call.d.ts.map +1 -0
- package/dist/wire/events-call.js +196 -0
- package/dist/wire/events-call.js.map +1 -0
- package/dist/wire/events.d.ts +946 -0
- package/dist/wire/events.d.ts.map +1 -0
- package/dist/wire/events.js +309 -0
- package/dist/wire/events.js.map +1 -0
- package/dist/wire/index.d.ts +19 -0
- package/dist/wire/index.d.ts.map +1 -0
- package/dist/wire/index.js +19 -0
- package/dist/wire/index.js.map +1 -0
- package/dist/wire/metrics.d.ts +366 -0
- package/dist/wire/metrics.d.ts.map +1 -0
- package/dist/wire/metrics.js +269 -0
- package/dist/wire/metrics.js.map +1 -0
- package/dist/wire/reduce.d.ts +10 -0
- package/dist/wire/reduce.d.ts.map +1 -0
- package/dist/wire/reduce.js +367 -0
- package/dist/wire/reduce.js.map +1 -0
- package/dist/wire/registry.d.ts +1789 -0
- package/dist/wire/registry.d.ts.map +1 -0
- package/dist/wire/registry.js +118 -0
- package/dist/wire/registry.js.map +1 -0
- package/dist/wire/rest-data.d.ts +170 -0
- package/dist/wire/rest-data.d.ts.map +1 -0
- package/dist/wire/rest-data.js +78 -0
- package/dist/wire/rest-data.js.map +1 -0
- package/dist/wire/rest-hosting.d.ts +74 -0
- package/dist/wire/rest-hosting.d.ts.map +1 -0
- package/dist/wire/rest-hosting.js +38 -0
- package/dist/wire/rest-hosting.js.map +1 -0
- package/dist/wire/rest-retrieval.d.ts +214 -0
- package/dist/wire/rest-retrieval.d.ts.map +1 -0
- package/dist/wire/rest-retrieval.js +161 -0
- package/dist/wire/rest-retrieval.js.map +1 -0
- package/dist/wire/rest.d.ts +786 -0
- package/dist/wire/rest.d.ts.map +1 -0
- package/dist/wire/rest.js +238 -0
- package/dist/wire/rest.js.map +1 -0
- package/dist/wire/room.d.ts +106 -0
- package/dist/wire/room.d.ts.map +1 -0
- package/dist/wire/room.js +73 -0
- package/dist/wire/room.js.map +1 -0
- package/dist/wire/state.d.ts +915 -0
- package/dist/wire/state.d.ts.map +1 -0
- package/dist/wire/state.js +189 -0
- package/dist/wire/state.js.map +1 -0
- package/dist/wire/verbs.d.ts +73 -0
- package/dist/wire/verbs.d.ts.map +1 -0
- package/dist/wire/verbs.js +50 -0
- package/dist/wire/verbs.js.map +1 -0
- package/package.json +74 -0
- package/tsconfig.tenant.json +24 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/** `this.call`: the live call an agent instance serves — its room, turns and verbs. */
|
|
2
|
+
import {} from "../wire/defs.js";
|
|
3
|
+
import { History } from "./history.js";
|
|
4
|
+
import { ParticipantHandle, Room } from "./room.js";
|
|
5
|
+
/** How long `say`/`reply` wait for their `turn.agent` before resolving false. */
|
|
6
|
+
const ACK_MS = 30_000;
|
|
7
|
+
/** Transfer timeout: the far end may ring for 25s before it fails. */
|
|
8
|
+
const TRANSFER_MS = 90_000;
|
|
9
|
+
/** Extra time `attention()` waits beyond `waitS` for the answer entry to arrive. */
|
|
10
|
+
const A_MOMENT_MS = 15_000;
|
|
11
|
+
/** Error when no answer came back: the gateway, not the far end, went quiet. */
|
|
12
|
+
const NO_ANSWER = "the runtime never said how it went";
|
|
13
|
+
/** Error for a pending verb when the call ends first. */
|
|
14
|
+
const THE_CALL_ENDED = "the call ended before it was answered";
|
|
15
|
+
/** Error for `search()` on a call with no gateway (an offline prompt, a test). */
|
|
16
|
+
export const NO_GATEWAY_TO_SEARCH = "this call cannot search: no gateway is serving it";
|
|
17
|
+
/**
|
|
18
|
+
* One live call. State is reduced from log entries; every verb sends one wire command.
|
|
19
|
+
* There is no direct LiveKit access.
|
|
20
|
+
*/
|
|
21
|
+
export class CallWorld {
|
|
22
|
+
out;
|
|
23
|
+
searching;
|
|
24
|
+
ackMs;
|
|
25
|
+
id;
|
|
26
|
+
contact;
|
|
27
|
+
from;
|
|
28
|
+
channel;
|
|
29
|
+
/** Spoken (`voice`) or written (`text`). A gateway that does not say gets it from the channel. */
|
|
30
|
+
medium;
|
|
31
|
+
/** The day this call opened, `YYYY-MM-DD`. */
|
|
32
|
+
today;
|
|
33
|
+
/** The page code this call claimed, or null. */
|
|
34
|
+
claimed = null;
|
|
35
|
+
room;
|
|
36
|
+
history = new History();
|
|
37
|
+
// say/reply settle on the next turn.agent: commands are fire-and-forget, so that entry is the only ack.
|
|
38
|
+
#speaking = [];
|
|
39
|
+
// Settled by call.transferred and attention.answered.
|
|
40
|
+
#transfers = [];
|
|
41
|
+
#asks = [];
|
|
42
|
+
/** The event being dispatched, so a write inside onEvent can name its cause. */
|
|
43
|
+
cause = null;
|
|
44
|
+
#events = 0;
|
|
45
|
+
constructor(line, out, searching = null, ackMs = ACK_MS) {
|
|
46
|
+
this.out = out;
|
|
47
|
+
this.searching = searching;
|
|
48
|
+
this.ackMs = ackMs;
|
|
49
|
+
this.id = line.id;
|
|
50
|
+
this.contact = line.contact;
|
|
51
|
+
if (line.from !== undefined)
|
|
52
|
+
this.from = line.from;
|
|
53
|
+
if (line.channel !== undefined)
|
|
54
|
+
this.channel = line.channel;
|
|
55
|
+
this.medium = line.medium ?? (line.channel === "whatsapp" ? "text" : "voice");
|
|
56
|
+
if (line.today !== undefined)
|
|
57
|
+
this.today = line.today;
|
|
58
|
+
if (line.claimed !== undefined)
|
|
59
|
+
this.claimed = line.claimed;
|
|
60
|
+
this.room = new Room(out);
|
|
61
|
+
}
|
|
62
|
+
/** Next sequence number for this call's events (independent of the wire's seq). */
|
|
63
|
+
numbered() {
|
|
64
|
+
return (this.#events += 1);
|
|
65
|
+
}
|
|
66
|
+
/** A handle to one participant, e.g. `call.participant(id).mute()`. */
|
|
67
|
+
participant(identity) {
|
|
68
|
+
return new ParticipantHandle(identity, this.out);
|
|
69
|
+
}
|
|
70
|
+
/** Send a payload to browsers in the room. The log records its size, not its content. */
|
|
71
|
+
send(topic, data, options = {}) {
|
|
72
|
+
this.out("room.send", options.to === undefined ? { topic, data } : { topic, data, to: options.to });
|
|
73
|
+
}
|
|
74
|
+
/** Speak this text verbatim. Resolves true once the turn lands, false on timeout. */
|
|
75
|
+
say(text, options = {}) {
|
|
76
|
+
this.out("agent.say", { text, ...options });
|
|
77
|
+
return this.#spoken();
|
|
78
|
+
}
|
|
79
|
+
/** Have the model speak, guided by instructions the caller never hears. Resolves like `say`. */
|
|
80
|
+
reply(instructions, options = {}) {
|
|
81
|
+
this.out("agent.reply", { instructions, ...options });
|
|
82
|
+
return this.#spoken();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Search the knowledge bases attached to this agent. The gateway runs the search and logs the
|
|
86
|
+
* results. `k` defaults to each base's own setting.
|
|
87
|
+
*/
|
|
88
|
+
search(query, options = {}) {
|
|
89
|
+
if (this.searching === null)
|
|
90
|
+
return Promise.reject(new Error(NO_GATEWAY_TO_SEARCH));
|
|
91
|
+
return this.searching(query, options.k);
|
|
92
|
+
}
|
|
93
|
+
/** Invite someone into the room. Same as `room.invite`. */
|
|
94
|
+
invite(to, options) {
|
|
95
|
+
this.room.invite(to, options);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Transfer the caller to a number. On a phone call the line is sent on (cold); in a browser the
|
|
99
|
+
* number is dialled into the call (warm) and the agent goes silent once it answers. `mode`
|
|
100
|
+
* forces one. `ok: false` means the caller is still with the agent.
|
|
101
|
+
*/
|
|
102
|
+
transfer(to, options = {}) {
|
|
103
|
+
this.out("call.transfer", options.mode === undefined ? { to } : { to, mode: options.mode });
|
|
104
|
+
return this.#answered(this.#transfers, TRANSFER_MS, { to, mode: null, ok: false, error: NO_ANSWER });
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Ask for a supervisor. The caller waits (on hold, or unanswered in a thread) until someone takes
|
|
108
|
+
* the line or `waitS` passes. `reason` is shown to the supervisor. The calling tool runs the
|
|
109
|
+
* whole time, so give it a `timeout` longer than `waitS`.
|
|
110
|
+
*/
|
|
111
|
+
attention(reason, options) {
|
|
112
|
+
this.out("call.attention", { reason, waitS: options.waitS });
|
|
113
|
+
const lapsed = { ok: false, by: null, error: NO_ANSWER };
|
|
114
|
+
return this.#answered(this.#asks, options.waitS * 1000 + A_MOMENT_MS, lapsed);
|
|
115
|
+
}
|
|
116
|
+
/** Put the caller on hold: they hear hold music and the agent neither speaks nor listens. */
|
|
117
|
+
hold() {
|
|
118
|
+
this.out("call.hold", {});
|
|
119
|
+
}
|
|
120
|
+
/** Take the caller off hold. */
|
|
121
|
+
unhold() {
|
|
122
|
+
this.out("call.unhold", {});
|
|
123
|
+
}
|
|
124
|
+
/** Send DTMF tones: `0-9`, `*`, `#`, and `,` for a pause. */
|
|
125
|
+
dtmf(digits) {
|
|
126
|
+
this.out("call.dtmf", { digits });
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Bind this call to the code shown on the caller's page, so the page follows the call. Sets
|
|
130
|
+
* `claimed` on `call.claimed`; an unknown, expired or taken code is refused with `no_code`.
|
|
131
|
+
*/
|
|
132
|
+
claim(code) {
|
|
133
|
+
this.out("call.claim", { code });
|
|
134
|
+
}
|
|
135
|
+
/** Record a callback request in the call log for your backend to dial. */
|
|
136
|
+
callback(number, options = {}) {
|
|
137
|
+
this.out("call.callback", { number, ...options });
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The caller asked never to be called again: their number joins the org's do-not-call list, and
|
|
141
|
+
* no call of the org reaches it until a consent is recorded. Tell them it is done.
|
|
142
|
+
*/
|
|
143
|
+
optOut(note) {
|
|
144
|
+
this.out("call.opt_out", note === undefined ? {} : { note });
|
|
145
|
+
}
|
|
146
|
+
/** End the call. Say goodbye before calling this; nothing after it is heard. */
|
|
147
|
+
hangup(reason) {
|
|
148
|
+
this.out("call.hangup", reason === undefined ? {} : { reason });
|
|
149
|
+
}
|
|
150
|
+
/** Fold one log entry into the room and history. Unknown types are ignored. */
|
|
151
|
+
take(type, data, at) {
|
|
152
|
+
switch (type) {
|
|
153
|
+
case "participant.joined":
|
|
154
|
+
return this.room.joined({
|
|
155
|
+
identity: String(data["identity"]),
|
|
156
|
+
kind: data["kind"],
|
|
157
|
+
...(typeof data["name"] === "string" ? { name: data["name"] } : {}),
|
|
158
|
+
}, at);
|
|
159
|
+
case "call.claimed":
|
|
160
|
+
this.claimed = String(data["code"]);
|
|
161
|
+
return;
|
|
162
|
+
case "participant.left":
|
|
163
|
+
return this.room.left(String(data["identity"]));
|
|
164
|
+
case "participant.speaking":
|
|
165
|
+
return this.room.speaking(String(data["identity"]), data["speaking"] === true);
|
|
166
|
+
case "turn.user":
|
|
167
|
+
return this.history.took({ who: "user", text: String(data["text"] ?? ""), speechId: String(data["speech_id"] ?? data["speechId"] ?? ""), interrupted: false, at });
|
|
168
|
+
case "turn.agent":
|
|
169
|
+
this.history.took({ who: "agent", text: String(data["text"] ?? ""), speechId: String(data["speech_id"] ?? data["speechId"] ?? ""), interrupted: data["interrupted"] === true, at });
|
|
170
|
+
return this.#settle(true);
|
|
171
|
+
case "call.transferred":
|
|
172
|
+
return settle(this.#transfers, {
|
|
173
|
+
to: String(data["to"] ?? ""),
|
|
174
|
+
mode: (data["mode"] ?? null),
|
|
175
|
+
ok: data["ok"] === true,
|
|
176
|
+
...(typeof data["error"] === "string" ? { error: data["error"] } : {}),
|
|
177
|
+
});
|
|
178
|
+
case "attention.answered":
|
|
179
|
+
return settle(this.#asks, {
|
|
180
|
+
ok: data["ok"] === true,
|
|
181
|
+
by: (data["by"] ?? null),
|
|
182
|
+
...(typeof data["error"] === "string" ? { error: data["error"] } : {}),
|
|
183
|
+
});
|
|
184
|
+
// Settle every pending verb now instead of waiting for its timeout.
|
|
185
|
+
case "call.ended":
|
|
186
|
+
this.#settle(false);
|
|
187
|
+
settle(this.#transfers, { to: "", mode: null, ok: false, error: THE_CALL_ENDED });
|
|
188
|
+
settle(this.#asks, { ok: false, by: null, error: THE_CALL_ENDED });
|
|
189
|
+
return;
|
|
190
|
+
default:
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
#spoken() {
|
|
195
|
+
return new Promise((resolve) => {
|
|
196
|
+
this.#speaking.push(resolve);
|
|
197
|
+
// Resolve false rather than reject: a hang-up mid-sentence is not an error the tool can handle.
|
|
198
|
+
setTimeout(() => {
|
|
199
|
+
this.#speaking = this.#speaking.filter((waiting) => waiting !== resolve);
|
|
200
|
+
resolve(false);
|
|
201
|
+
}, this.ackMs).unref?.();
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
#settle(spoken) {
|
|
205
|
+
const waiting = this.#speaking;
|
|
206
|
+
this.#speaking = [];
|
|
207
|
+
for (const resolve of waiting)
|
|
208
|
+
resolve(spoken);
|
|
209
|
+
}
|
|
210
|
+
// The runtime always answers via a log entry; the ceiling only guards against a gateway that went away.
|
|
211
|
+
#answered(waiting, ceiling, lapsed) {
|
|
212
|
+
return new Promise((resolve) => {
|
|
213
|
+
waiting.push(resolve);
|
|
214
|
+
setTimeout(() => {
|
|
215
|
+
const index = waiting.indexOf(resolve);
|
|
216
|
+
if (index >= 0)
|
|
217
|
+
waiting.splice(index, 1);
|
|
218
|
+
resolve(lapsed);
|
|
219
|
+
}, ceiling).unref?.();
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function settle(waiting, answer) {
|
|
224
|
+
const resolvers = waiting.splice(0, waiting.length);
|
|
225
|
+
for (const resolve of resolvers)
|
|
226
|
+
resolve(answer);
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=call.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../src/call/call.ts"],"names":[],"mappings":"AAAA,uFAAuF;AAEvF,OAAO,EAAe,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO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,OAAO,CAAC,OAAO,CAAC,CAAC;gBACvC,IAAI,KAAK,IAAI,CAAC;oBAAE,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBACzC,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,SAAS,MAAM,CAAI,OAAgC,EAAE,MAAS;IAC5D,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,KAAK,MAAM,OAAO,IAAI,SAAS;QAAE,OAAO,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** The call's finished turns, and an optional summary that replaces older ones. */
|
|
2
|
+
/** One finished turn from `turn.user` or `turn.agent`. Metrics stay in the log. */
|
|
3
|
+
export interface Turn {
|
|
4
|
+
who: "user" | "agent";
|
|
5
|
+
text: string;
|
|
6
|
+
/** Links a caller's turn to the reply it triggered. */
|
|
7
|
+
speechId: string;
|
|
8
|
+
/** True when the caller interrupted the agent; always false for user turns. */
|
|
9
|
+
interrupted: boolean;
|
|
10
|
+
at: number;
|
|
11
|
+
}
|
|
12
|
+
/** The call's finished turns, oldest first. A turn still being spoken is not included. */
|
|
13
|
+
export declare class History {
|
|
14
|
+
#private;
|
|
15
|
+
/** Every finished turn, oldest first. */
|
|
16
|
+
get turns(): readonly Turn[];
|
|
17
|
+
/** Number of turns kept. */
|
|
18
|
+
get length(): number;
|
|
19
|
+
/** The summary left by `collapse()`, or null. */
|
|
20
|
+
get summary(): string | null;
|
|
21
|
+
/** The most recent turn. */
|
|
22
|
+
get last(): Turn | undefined;
|
|
23
|
+
/** Append a finished turn. Called by the bridge only. */
|
|
24
|
+
took(turn: Turn): void;
|
|
25
|
+
/** Replace all turns with a summary. Affects the view only; the call log keeps every turn. */
|
|
26
|
+
collapse(summary: string): void;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/call/history.ts"],"names":[],"mappings":"AAAA,mFAAmF;AAEnF,mFAAmF;AACnF,MAAM,WAAW,IAAI;IACnB,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,WAAW,EAAE,OAAO,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,0FAA0F;AAC1F,qBAAa,OAAO;;IAIlB,yCAAyC;IACzC,IAAI,KAAK,IAAI,SAAS,IAAI,EAAE,CAE3B;IAED,4BAA4B;IAC5B,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,iDAAiD;IACjD,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAED,4BAA4B;IAC5B,IAAI,IAAI,IAAI,IAAI,GAAG,SAAS,CAE3B;IAED,yDAAyD;IACzD,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAErB;IAED,8FAA8F;IAC9F,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAG9B;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** The call's finished turns, and an optional summary that replaces older ones. */
|
|
2
|
+
/** The call's finished turns, oldest first. A turn still being spoken is not included. */
|
|
3
|
+
export class History {
|
|
4
|
+
#turns = [];
|
|
5
|
+
#summary = null;
|
|
6
|
+
/** Every finished turn, oldest first. */
|
|
7
|
+
get turns() {
|
|
8
|
+
return this.#turns;
|
|
9
|
+
}
|
|
10
|
+
/** Number of turns kept. */
|
|
11
|
+
get length() {
|
|
12
|
+
return this.#turns.length;
|
|
13
|
+
}
|
|
14
|
+
/** The summary left by `collapse()`, or null. */
|
|
15
|
+
get summary() {
|
|
16
|
+
return this.#summary;
|
|
17
|
+
}
|
|
18
|
+
/** The most recent turn. */
|
|
19
|
+
get last() {
|
|
20
|
+
return this.#turns[this.#turns.length - 1];
|
|
21
|
+
}
|
|
22
|
+
/** Append a finished turn. Called by the bridge only. */
|
|
23
|
+
took(turn) {
|
|
24
|
+
this.#turns.push(turn);
|
|
25
|
+
}
|
|
26
|
+
/** Replace all turns with a summary. Affects the view only; the call log keeps every turn. */
|
|
27
|
+
collapse(summary) {
|
|
28
|
+
this.#turns.length = 0;
|
|
29
|
+
this.#summary = summary;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/call/history.ts"],"names":[],"mappings":"AAAA,mFAAmF;AAanF,0FAA0F;AAC1F,MAAM,OAAO,OAAO;IACT,MAAM,GAAW,EAAE,CAAC;IAC7B,QAAQ,GAAkB,IAAI,CAAC;IAE/B,yCAAyC;IACzC,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,4BAA4B;IAC5B,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,iDAAiD;IACjD,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,4BAA4B;IAC5B,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED,yDAAyD;IACzD,IAAI,CAAC,IAAU;QACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,8FAA8F;IAC9F,QAAQ,CAAC,OAAe;QACtB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** The call's room: its participants and the commands that act on them. */
|
|
2
|
+
import { type Camel, type CommandData } from "../wire/codec.js";
|
|
3
|
+
import { type CommandType } from "../wire/registry.js";
|
|
4
|
+
/** A participant's role in the call (protocol/schema/defs.json). */
|
|
5
|
+
export type ParticipantKind = "caller" | "agent" | "supervisor" | "listener" | "sip";
|
|
6
|
+
/** One participant in the room. */
|
|
7
|
+
export interface Participant {
|
|
8
|
+
identity: string;
|
|
9
|
+
kind: ParticipantKind;
|
|
10
|
+
name?: string;
|
|
11
|
+
/** Join time from `participant.joined`, in ms. */
|
|
12
|
+
joinedAt: number;
|
|
13
|
+
/** Current voice activity, from `participant.speaking`. */
|
|
14
|
+
speaking: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Sends one command on the wire, bound to its call. */
|
|
17
|
+
export type Commander = <K extends CommandType>(type: K, data: Camel<CommandData<K>>) => void;
|
|
18
|
+
/** Commands for one participant. Returned by `call.participant(identity)`. */
|
|
19
|
+
export declare class ParticipantHandle {
|
|
20
|
+
readonly identity: string;
|
|
21
|
+
private readonly send;
|
|
22
|
+
constructor(identity: string, send: Commander);
|
|
23
|
+
/** Mute for the rest of the call. There is no unmute; invite the leg again instead. */
|
|
24
|
+
mute(): void;
|
|
25
|
+
/** Remove from the room. Removing the caller ends the call. */
|
|
26
|
+
remove(): void;
|
|
27
|
+
}
|
|
28
|
+
/** Current participants, reduced from the room's log entries. Reads are local; verbs send commands. */
|
|
29
|
+
export declare class Room {
|
|
30
|
+
#private;
|
|
31
|
+
private readonly send;
|
|
32
|
+
constructor(send: Commander);
|
|
33
|
+
/** Participants in join order. */
|
|
34
|
+
get participants(): Participant[];
|
|
35
|
+
/** The caller, if one has joined. */
|
|
36
|
+
get caller(): Participant | undefined;
|
|
37
|
+
/** Whether a participant of this kind is present, e.g. `has("supervisor")`. */
|
|
38
|
+
has(kind: ParticipantKind): boolean;
|
|
39
|
+
/** A participant by identity. */
|
|
40
|
+
get(identity: string): Participant | undefined;
|
|
41
|
+
/** Invite a number as a SIP leg, or an identity as a participant. */
|
|
42
|
+
invite(to: string, options: {
|
|
43
|
+
kind: "sip" | "participant";
|
|
44
|
+
}): void;
|
|
45
|
+
/** Record a join. Re-joining under the same identity replaces the entry. */
|
|
46
|
+
joined(data: {
|
|
47
|
+
identity: string;
|
|
48
|
+
kind: ParticipantKind;
|
|
49
|
+
name?: string;
|
|
50
|
+
}, at: number): void;
|
|
51
|
+
/** Record a departure. */
|
|
52
|
+
left(identity: string): void;
|
|
53
|
+
/** Update voice activity. Unknown identities are ignored. */
|
|
54
|
+
speaking(identity: string, speaking: boolean): void;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=room.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room.d.ts","sourceRoot":"","sources":["../../src/call/room.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAE3E,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,oEAAoE;AACpE,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,OAAO,GAAG,YAAY,GAAG,UAAU,GAAG,KAAK,CAAC;AAErF,mCAAmC;AACnC,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,wDAAwD;AACxD,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI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0,0 +1,66 @@
|
|
|
1
|
+
/** The call's room: its participants and the commands that act on them. */
|
|
2
|
+
import {} from "../wire/codec.js";
|
|
3
|
+
import {} from "../wire/registry.js";
|
|
4
|
+
/** Commands for one participant. Returned by `call.participant(identity)`. */
|
|
5
|
+
export class ParticipantHandle {
|
|
6
|
+
identity;
|
|
7
|
+
send;
|
|
8
|
+
constructor(identity, send) {
|
|
9
|
+
this.identity = identity;
|
|
10
|
+
this.send = send;
|
|
11
|
+
}
|
|
12
|
+
/** Mute for the rest of the call. There is no unmute; invite the leg again instead. */
|
|
13
|
+
mute() {
|
|
14
|
+
this.send("participant.mute", { identity: this.identity });
|
|
15
|
+
}
|
|
16
|
+
/** Remove from the room. Removing the caller ends the call. */
|
|
17
|
+
remove() {
|
|
18
|
+
this.send("participant.remove", { identity: this.identity });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Current participants, reduced from the room's log entries. Reads are local; verbs send commands. */
|
|
22
|
+
export class Room {
|
|
23
|
+
send;
|
|
24
|
+
#participants = new Map();
|
|
25
|
+
constructor(send) {
|
|
26
|
+
this.send = send;
|
|
27
|
+
}
|
|
28
|
+
/** Participants in join order. */
|
|
29
|
+
get participants() {
|
|
30
|
+
return [...this.#participants.values()];
|
|
31
|
+
}
|
|
32
|
+
/** The caller, if one has joined. */
|
|
33
|
+
get caller() {
|
|
34
|
+
return this.participants.find((one) => one.kind === "caller");
|
|
35
|
+
}
|
|
36
|
+
/** Whether a participant of this kind is present, e.g. `has("supervisor")`. */
|
|
37
|
+
has(kind) {
|
|
38
|
+
return this.participants.some((one) => one.kind === kind);
|
|
39
|
+
}
|
|
40
|
+
/** A participant by identity. */
|
|
41
|
+
get(identity) {
|
|
42
|
+
return this.#participants.get(identity);
|
|
43
|
+
}
|
|
44
|
+
/** Invite a number as a SIP leg, or an identity as a participant. */
|
|
45
|
+
invite(to, options) {
|
|
46
|
+
this.send("room.invite", { to, kind: options.kind });
|
|
47
|
+
}
|
|
48
|
+
/** Record a join. Re-joining under the same identity replaces the entry. */
|
|
49
|
+
joined(data, at) {
|
|
50
|
+
const one = { identity: data.identity, kind: data.kind, joinedAt: at, speaking: false };
|
|
51
|
+
if (data.name !== undefined)
|
|
52
|
+
one.name = data.name;
|
|
53
|
+
this.#participants.set(data.identity, one);
|
|
54
|
+
}
|
|
55
|
+
/** Record a departure. */
|
|
56
|
+
left(identity) {
|
|
57
|
+
this.#participants.delete(identity);
|
|
58
|
+
}
|
|
59
|
+
/** Update voice activity. Unknown identities are ignored. */
|
|
60
|
+
speaking(identity, speaking) {
|
|
61
|
+
const one = this.#participants.get(identity);
|
|
62
|
+
if (one !== undefined)
|
|
63
|
+
one.speaking = speaking;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=room.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room.js","sourceRoot":"","sources":["../../src/call/room.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAE3E,OAAO,EAAgC,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAoB,MAAM,qBAAqB,CAAC;AAmBvD,8EAA8E;AAC9E,MAAM,OAAO,iBAAiB;IAEjB,QAAQ;IACA,IAAI;IAFvB,YACW,QAAgB,EACR,IAAe;wBADvB,QAAQ;oBACA,IAAI;IACpB,CAAC;IAEJ,uFAAuF;IACvF,IAAI;QACF,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,+DAA+D;IAC/D,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF;AAED,uGAAuG;AACvG,MAAM,OAAO,IAAI;IAGc,IAAI;IAFxB,aAAa,GAAG,IAAI,GAAG,EAAuB,CAAC;IAExD,YAA6B,IAAe;oBAAf,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Aa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IAED,6DAA6D;IAC7D,QAAQ,CAAC,QAAgB,EAAE,QAAiB;QAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7C,IAAI,GAAG,KAAK,SAAS;YAAE,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type AgentConfig } from "../wire/agent-config.js";
|
|
2
|
+
import { type Camel, type CommandData } from "../wire/codec.js";
|
|
3
|
+
import { type DevVerb, type ToolSpec } from "../wire/defs.js";
|
|
4
|
+
import { type Entry } from "../wire/envelope.js";
|
|
5
|
+
import { type CommandType, type EventType } from "../wire/registry.js";
|
|
6
|
+
import { Call, CallBook, type CallGateway } from "./calls.js";
|
|
7
|
+
import { type AnyListener, type CamelEvent, type Listener, type Payload } from "./listeners.js";
|
|
8
|
+
/** A tool: the spec the model sees and the function that runs when it is called. */
|
|
9
|
+
export interface Tool extends Camel<ToolSpec> {
|
|
10
|
+
run: (args: Record<string, unknown>, call: Call) => unknown;
|
|
11
|
+
}
|
|
12
|
+
/** An agent's declaration plus its tools' code. */
|
|
13
|
+
export interface AgentOptions extends Omit<Camel<AgentConfig>, "tools"> {
|
|
14
|
+
tools?: Tool[];
|
|
15
|
+
/**
|
|
16
|
+
* Whether the gateway may route calls that name no app (phone calls, most web calls) to this
|
|
17
|
+
* socket. Defaults to true; a console such as `pinecall chat` passes false.
|
|
18
|
+
*/
|
|
19
|
+
takesUnclaimed?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether this socket answers the console's dev verbs for the agent, beside the process serving
|
|
22
|
+
* its calls. Such a socket declares nothing: it never sends `agent.configure`.
|
|
23
|
+
*/
|
|
24
|
+
answersDev?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** The client-side socket an agent sends frames through. */
|
|
27
|
+
export interface AgentGateway {
|
|
28
|
+
send<K extends CommandType>(type: K, agent: string, call: string | null, data: Camel<CommandData<K>>, id: string): void;
|
|
29
|
+
seen(event: CamelEvent, call: Call | null): void;
|
|
30
|
+
onError(error: Error): void;
|
|
31
|
+
readonly sdk: string;
|
|
32
|
+
readonly host: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Handles a console's `dev.request`. Resolve with the answer, or throw `DevRefused` to refuse with
|
|
36
|
+
* a status; any other error reaches the console as a 500.
|
|
37
|
+
*/
|
|
38
|
+
export type DevHandler = (verb: DevVerb, data: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
39
|
+
/**
|
|
40
|
+
* An agent, from the app's side.
|
|
41
|
+
*
|
|
42
|
+
* The gateway's registry is in memory, so the declaration is re-sent on every reconnect. Several
|
|
43
|
+
* sockets may hold one agent; unclaimed calls go to the newest one that takes them, so a rolling
|
|
44
|
+
* deploy serves as soon as the new process registers. Call `drain()` before exiting to hand live
|
|
45
|
+
* calls over instead of cutting them.
|
|
46
|
+
*/
|
|
47
|
+
export declare class Agent implements CallGateway {
|
|
48
|
+
#private;
|
|
49
|
+
readonly slug: string;
|
|
50
|
+
private readonly gateway;
|
|
51
|
+
readonly calls: CallBook;
|
|
52
|
+
constructor(slug: string, options: AgentOptions, gateway: AgentGateway);
|
|
53
|
+
/** The agent's current declaration, in wire shape. */
|
|
54
|
+
get config(): Camel<AgentConfig>;
|
|
55
|
+
/**
|
|
56
|
+
* This socket's app id as minted by the gateway, or undefined before the first register. A call
|
|
57
|
+
* that names it (`WS /v1/chat?app=<id>`, `app` in `POST /v1/calls`) is served by this process.
|
|
58
|
+
*/
|
|
59
|
+
get app(): string | undefined;
|
|
60
|
+
/** Listen for one event type across every call of this agent. `null` for the agent's own log. */
|
|
61
|
+
on<K extends EventType>(type: K, listener: Listener<K, Call | null>): () => void;
|
|
62
|
+
/** Listen for every event of this agent. The returned function stops listening. */
|
|
63
|
+
onAny(listener: AnyListener<Call | null>): () => void;
|
|
64
|
+
/**
|
|
65
|
+
* Handle `dev.request` asks relayed from a console. `pinecall start` registers one; without it
|
|
66
|
+
* every ask is refused with 501.
|
|
67
|
+
*/
|
|
68
|
+
onDev(handler: DevHandler): void;
|
|
69
|
+
/** Replace the tools. The next `configure` sends the new declaration. */
|
|
70
|
+
declare(tools: Tool[]): void;
|
|
71
|
+
/** Update the declaration. Only the given fields change; live calls keep their session. */
|
|
72
|
+
configure(changes?: Partial<Camel<AgentConfig>>): Promise<Payload<"agent.configured">>;
|
|
73
|
+
/** Register the slug, then send the declaration. Runs again on every reconnect. */
|
|
74
|
+
open(): Promise<void>;
|
|
75
|
+
/** Fold one entry into its call and dispatch it to listeners. */
|
|
76
|
+
take(entry: Entry): void;
|
|
77
|
+
/** Send one command on this agent's behalf. */
|
|
78
|
+
command<K extends CommandType>(type: K, call: string | null, data: Camel<CommandData<K>>): void;
|
|
79
|
+
/** Report an error no caller is waiting on. */
|
|
80
|
+
onError(error: Error): void;
|
|
81
|
+
/**
|
|
82
|
+
* Stop receiving new calls and hand live ones to another holder (or park them for the next).
|
|
83
|
+
* Running tools still answer. Resolves with where the calls went.
|
|
84
|
+
*/
|
|
85
|
+
drain(answerMs?: number): Promise<Payload<"agent.draining">>;
|
|
86
|
+
/** Number of tool runs in progress. */
|
|
87
|
+
get inFlight(): number;
|
|
88
|
+
/** Resolve once every running tool has sent its tool.result. */
|
|
89
|
+
settled(): Promise<void>;
|
|
90
|
+
/** Send `ping`; the gateway answers with `pong`. */
|
|
91
|
+
ping(): void;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/client/agent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAW,MAAM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