@pinecall/protocol 0.1.0

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.
@@ -0,0 +1,388 @@
1
+ // Generated from schema/events/: one schema per event. Never edited by hand.
2
+ import { z } from "zod";
3
+ import { AgentStateSchema, ChannelSchema, ContactSchema, CostSchema, DevVerbSchema, DirectionSchema, DocSourceSchema, EndedBySchema, EndReasonSchema, EnvSchema, MemoryOpSchema, RouteSchema, ScoreVerdictSchema, SupervisorSchema, TransferModeSchema, UserStateSchema, } from "./defs.js";
4
+ import { AgentTurnMetricsSchema, ModelUsageSchema, UserTurnMetricsSchema } from "./metrics.js";
5
+ import { StateSchema } from "./state.js";
6
+ /**
7
+ * The gateway applied an agent.configure. Live calls keep their session; the next call starts with
8
+ * the new config.
9
+ */
10
+ export const AgentConfiguredSchema = z.strictObject({
11
+ changed: z.array(z.string()),
12
+ });
13
+ /** One socket stopped holding the agent. */
14
+ export const AgentDetachedSchema = z.strictObject({
15
+ app: z.string(),
16
+ env: EnvSchema,
17
+ left: z.boolean(),
18
+ });
19
+ /**
20
+ * The gateway accepted an agent.register: this socket now speaks for the agent and answers its
21
+ * routes. Many sockets may hold one agent at once — a new call takes the newest of them, unless
22
+ * the caller names one by its `app` id.
23
+ */
24
+ export const AgentRegisteredSchema = z.strictObject({
25
+ routes: z.array(RouteSchema),
26
+ app: z.string(),
27
+ sdk: z.string().nullish(),
28
+ env: EnvSchema.nullish(),
29
+ });
30
+ /** The agent's state changed, in the session's own words. */
31
+ export const AgentStateChangedSchema = z.strictObject({
32
+ state: AgentStateSchema,
33
+ });
34
+ /**
35
+ * Words from the agent as they are played, synced to the audio. Interim while final is false; the
36
+ * whole reply becomes turn.agent. Interim entries are ephemeral.
37
+ */
38
+ export const AgentTranscriptSchema = z.strictObject({
39
+ speech_id: z.string(),
40
+ text: z.string(),
41
+ final: z.boolean(),
42
+ start: z.number().nullish(),
43
+ end: z.number().nullish(),
44
+ });
45
+ /**
46
+ * The platform is placing an outbound call and the far end has not answered yet. The first entry
47
+ * of an outbound call's log.
48
+ */
49
+ export const CallDialingSchema = z.strictObject({
50
+ channel: ChannelSchema,
51
+ from: z.string(),
52
+ to: z.string(),
53
+ run: z.string().nullable().nullish(),
54
+ caller: ContactSchema.nullable(),
55
+ external_id: z.string().nullish(),
56
+ });
57
+ /** The call is over. Nothing about the conversation follows; call.summary still does. */
58
+ export const CallEndedSchema = z.strictObject({
59
+ reason: EndReasonSchema,
60
+ ended_by: EndedBySchema,
61
+ ended_at: z.number(),
62
+ duration_s: z.number(),
63
+ });
64
+ /**
65
+ * The line's hold and mute flags after one of them changed. Both are stated so a reader never has
66
+ * to remember the other.
67
+ */
68
+ export const CallLineSchema = z.strictObject({
69
+ held: z.boolean(),
70
+ muted: z.boolean(),
71
+ });
72
+ /**
73
+ * An inbound call is offered to this agent and has not been answered yet. The first entry of an
74
+ * inbound call's log.
75
+ */
76
+ export const CallRingingSchema = z.strictObject({
77
+ channel: ChannelSchema,
78
+ from: z.string(),
79
+ to: z.string(),
80
+ route: RouteSchema,
81
+ run: z.string().nullable().nullish(),
82
+ caller: ContactSchema.nullable(),
83
+ external_id: z.string().nullish(),
84
+ });
85
+ /**
86
+ * Where in the call's own log a judgment is about. A reader who disagrees with a verdict opens the
87
+ * log at those lines.
88
+ */
89
+ export const JudgmentEvidenceSchema = z.strictObject({
90
+ seqs: z.array(z.int()),
91
+ said: z.string().nullish(),
92
+ });
93
+ /**
94
+ * One judge's answer about one call: the question it was asked, the word it answered and the
95
+ * sentence that says why.
96
+ */
97
+ export const JudgmentSchema = z.strictObject({
98
+ name: z.string(),
99
+ verdict: ScoreVerdictSchema,
100
+ criteria: z.string(),
101
+ reason: z.string(),
102
+ evidence: JudgmentEvidenceSchema,
103
+ });
104
+ /**
105
+ * The last entry of a call: what the judges said about it at hang-up, one row per judge. Written
106
+ * after call.summary, and the entry the log seals on.
107
+ */
108
+ export const CallScoreSchema = z.strictObject({
109
+ passed: z.boolean().nullish(),
110
+ not_judged: z.string().nullish(),
111
+ judges: z.array(JudgmentSchema),
112
+ panel: z.array(z.string()).nullish(),
113
+ judge_calls: z.int(),
114
+ judge_cost_eur: z.number().nullish(),
115
+ });
116
+ /**
117
+ * Media is up: the caller and the agent can hear each other, or the text session is open.
118
+ * Everything the agent says and hears comes after this.
119
+ */
120
+ export const CallStartedSchema = z.strictObject({
121
+ channel: ChannelSchema,
122
+ direction: DirectionSchema,
123
+ from: z.string(),
124
+ to: z.string(),
125
+ run: z.string().nullable().nullish(),
126
+ caller: ContactSchema.nullable(),
127
+ started_at: z.number(),
128
+ env: EnvSchema.nullish(),
129
+ });
130
+ /**
131
+ * What the call was about, how it went, what it consumed and what that cost. Written after
132
+ * call.ended, once memory and pricing are done; call.score follows it and seals the log.
133
+ */
134
+ export const CallSummarySchema = z.strictObject({
135
+ reason: EndReasonSchema,
136
+ outcome: z.string(),
137
+ duration_s: z.number(),
138
+ turns: z.int(),
139
+ usage: z.array(ModelUsageSchema),
140
+ cost: CostSchema,
141
+ recording: z.string().nullish(),
142
+ });
143
+ /** A transfer asked for by the agent or a supervisor finished, one way or the other. */
144
+ export const CallTransferredSchema = z.strictObject({
145
+ to: z.string(),
146
+ mode: TransferModeSchema,
147
+ ok: z.boolean(),
148
+ error: z.string().nullish(),
149
+ });
150
+ /**
151
+ * Somebody asked to be called back because no seat was free: a phone caller the overflow agent
152
+ * answered, or a web visitor who left a number at the widget. Written into the agent's own log;
153
+ * the tenant's app reads it and places the call.
154
+ */
155
+ export const CallbackRequestedSchema = z.strictObject({
156
+ channel: ChannelSchema,
157
+ number: z.string(),
158
+ via: z.enum(["overflow", "widget"]),
159
+ call: z.string().nullable(),
160
+ contact: ContactSchema.nullable(),
161
+ });
162
+ /** The caller did not say yes, or the request lapsed. The tool does not run; the model is told. */
163
+ export const ConfirmDeclinedSchema = z.strictObject({
164
+ tool: z.string(),
165
+ call_id: z.string(),
166
+ audience: z.string(),
167
+ said: z.string().nullish(),
168
+ reason: z.enum(["no", "timeout", "changed", "cancelled"]),
169
+ });
170
+ /**
171
+ * The caller said yes. The platform minted a one-shot token bound to the audience and the tool now
172
+ * runs. The token itself never enters the log.
173
+ */
174
+ export const ConfirmGrantedSchema = z.strictObject({
175
+ tool: z.string(),
176
+ call_id: z.string(),
177
+ audience: z.string(),
178
+ said: z.string(),
179
+ ttl_s: z.int(),
180
+ });
181
+ /**
182
+ * A tool with confirm set is about to run and the platform is asking the caller. The agent reads
183
+ * the phrase; nothing runs until confirm.granted.
184
+ */
185
+ export const ConfirmRequestSchema = z.strictObject({
186
+ tool: z.string(),
187
+ call_id: z.string(),
188
+ arguments: z.record(z.string(), z.unknown()),
189
+ audience: z.string(),
190
+ phrase: z.string(),
191
+ ttl_s: z.int(),
192
+ });
193
+ /**
194
+ * The gateway refused a call or a register because one of the org's quotas ran out. Written into
195
+ * the agent's own log, which is the org's, before the door says no.
196
+ */
197
+ export const CreditsExhaustedSchema = z.strictObject({
198
+ org: z.string(),
199
+ quota: z.enum(["minutes", "messages", "agents", "concurrent_calls", "memory_facts", "knowledge_chunks", "numbers", "seats"]),
200
+ used: z.number(),
201
+ limit: z.int(),
202
+ });
203
+ /**
204
+ * A line the app wrote into the log with call.log. The platform never reads it; the console shows
205
+ * it and evals may.
206
+ */
207
+ export const CustomSchema = z.strictObject({
208
+ name: z.string(),
209
+ data: z.record(z.string(), z.unknown()),
210
+ });
211
+ /** One ask of the process in the agent's directory, on a console's behalf. */
212
+ export const DevRequestSchema = z.strictObject({
213
+ id: z.string(),
214
+ verb: DevVerbSchema,
215
+ data: z.record(z.string(), z.unknown()),
216
+ });
217
+ /**
218
+ * What retrieval put in front of the model for this turn. An answer can be traced back to its
219
+ * chunks.
220
+ */
221
+ export const DocsSourcesSchema = z.strictObject({
222
+ query: z.string(),
223
+ sources: z.array(DocSourceSchema),
224
+ took_ms: z.number(),
225
+ speech_id: z.string().nullish(),
226
+ });
227
+ /**
228
+ * Something went wrong. Inside a call it says what failed; outside a call it says which command
229
+ * the gateway refused.
230
+ */
231
+ export const ErrorEventSchema = z.strictObject({
232
+ code: z.string(),
233
+ message: z.string(),
234
+ command: z.string().nullish(),
235
+ id: z.string().nullish(),
236
+ recoverable: z.boolean(),
237
+ });
238
+ /**
239
+ * The gateway refused to open a call because every worker of the fleet was full. Written into the
240
+ * agent's own log, which is the org's, before the door says no — the caller was offered a call
241
+ * back instead of a room.
242
+ */
243
+ export const FleetFullSchema = z.strictObject({
244
+ channel: ChannelSchema,
245
+ workers: z.int(),
246
+ active: z.int(),
247
+ });
248
+ /**
249
+ * The replay is done: everything up to seq has been sent and what follows is live. Never stored;
250
+ * sent to the reader.
251
+ */
252
+ export const LogCaughtUpSchema = z.strictObject({
253
+ seq: z.int(),
254
+ });
255
+ /**
256
+ * This reader missed a stretch: it reconnected too late for the store, or fell behind and the
257
+ * fanout dropped ephemeral entries. When the platform has a snapshot, it is here so the reader can
258
+ * catch up in one step. Never stored; sent to the reader.
259
+ */
260
+ export const LogGapSchema = z.strictObject({
261
+ from_seq: z.int(),
262
+ to_seq: z.int(),
263
+ snapshot: StateSchema.nullable(),
264
+ });
265
+ /**
266
+ * What memory did for this turn or at hangup: a recall before the reply, a remember after the
267
+ * call, a forget on request.
268
+ */
269
+ export const MemoryOpsSchema = z.strictObject({
270
+ ops: z.array(MemoryOpSchema),
271
+ speech_id: z.string().nullish(),
272
+ });
273
+ /** The answer to ping. Ephemeral: it proves the socket is alive and says nothing else. */
274
+ export const PongSchema = z.strictObject({
275
+ ts: z.number(),
276
+ });
277
+ /**
278
+ * A block of the prompt was rewritten. The text stays out of the log; its hash and length let two
279
+ * states be compared.
280
+ */
281
+ export const PromptChangedSchema = z.strictObject({
282
+ name: z.string(),
283
+ hash: z.string(),
284
+ chars: z.int(),
285
+ });
286
+ /** A tool call's result changed the state. */
287
+ export const StateCauseToolSchema = z.strictObject({
288
+ kind: z.literal("tool"),
289
+ tool: z.string(),
290
+ call_id: z.string(),
291
+ });
292
+ /** A fact from outside changed the state: the app's handler for an event.received moved a field. */
293
+ export const StateCauseEventSchema = z.strictObject({
294
+ kind: z.literal("event"),
295
+ name: z.string(),
296
+ seq: z.int(),
297
+ });
298
+ /** What changed the state: a tool's result, or a fact from outside. Told apart by kind. */
299
+ export const StateCauseSchema = z.discriminatedUnion("kind", [StateCauseToolSchema, StateCauseEventSchema]);
300
+ /**
301
+ * The app's declared state changed. A tool's result or an outside fact caused it, and the cause
302
+ * says which; the whole state travels so a reader never needs the previous entry.
303
+ */
304
+ export const StateChangedSchema = z.strictObject({
305
+ state: z.record(z.string(), z.unknown()),
306
+ changed: z.array(z.string()),
307
+ cause: StateCauseSchema.nullish(),
308
+ });
309
+ /** A supervisor hung up the call. call.ended follows with reason supervisor_ended. */
310
+ export const SupervisorEndedSchema = z.strictObject({
311
+ by: SupervisorSchema,
312
+ reason: z.string().nullish(),
313
+ });
314
+ /** The supervisor gave the line back; the agent resumes with the history intact. */
315
+ export const SupervisorReleasedSchema = z.strictObject({
316
+ by: SupervisorSchema,
317
+ });
318
+ /** A supervisor made the agent say this to the caller. */
319
+ export const SupervisorSaidSchema = z.strictObject({
320
+ by: SupervisorSchema,
321
+ text: z.string(),
322
+ });
323
+ /** A supervisor took the line; the agent is quiet until supervisor.released. */
324
+ export const SupervisorTookOverSchema = z.strictObject({
325
+ by: SupervisorSchema,
326
+ });
327
+ /** A supervisor asked for a transfer. call.transferred says how it went. */
328
+ export const SupervisorTransferredSchema = z.strictObject({
329
+ by: SupervisorSchema,
330
+ to: z.string(),
331
+ mode: TransferModeSchema,
332
+ });
333
+ /** A supervisor told the agent something the caller never heard. */
334
+ export const SupervisorWhisperedSchema = z.strictObject({
335
+ by: SupervisorSchema,
336
+ text: z.string(),
337
+ });
338
+ /**
339
+ * The model called a tool. The platform sends this to the app and the app's method runs in the
340
+ * app's own process; tool.result closes it.
341
+ */
342
+ export const ToolCallSchema = z.strictObject({
343
+ call_id: z.string(),
344
+ name: z.string(),
345
+ arguments: z.record(z.string(), z.unknown()),
346
+ speech_id: z.string().nullish(),
347
+ });
348
+ /** The tools the model can see changed. The app's state moved and each tool's when was recomputed. */
349
+ export const ToolsChangedSchema = z.strictObject({
350
+ visible: z.array(z.string()),
351
+ });
352
+ /**
353
+ * The agent's reply is over and this is what was said. With it, everything the session measured
354
+ * about the reply.
355
+ */
356
+ export const AgentTurnEndedSchema = z.strictObject({
357
+ speech_id: z.string(),
358
+ item_id: z.string().nullish(),
359
+ text: z.string(),
360
+ interrupted: z.boolean(),
361
+ metrics: AgentTurnMetricsSchema,
362
+ });
363
+ /**
364
+ * The caller's turn is over and this is what they said. With it, everything the session measured
365
+ * about the turn.
366
+ */
367
+ export const UserTurnEndedSchema = z.strictObject({
368
+ speech_id: z.string(),
369
+ item_id: z.string().nullish(),
370
+ text: z.string(),
371
+ language: z.string().nullish(),
372
+ transcript_confidence: z.number().nullish(),
373
+ metrics: UserTurnMetricsSchema,
374
+ });
375
+ /** The caller's state changed, in the session's own words. */
376
+ export const UserStateChangedSchema = z.strictObject({
377
+ state: UserStateSchema,
378
+ });
379
+ /**
380
+ * Words from the caller as the recognizer hears them. Interim while final is false; the final one
381
+ * becomes turn.user. Interim entries are ephemeral.
382
+ */
383
+ export const UserTranscriptSchema = z.strictObject({
384
+ text: z.string(),
385
+ final: z.boolean(),
386
+ language: z.string().nullish(),
387
+ confidence: z.number().nullish(),
388
+ });
@@ -0,0 +1,12 @@
1
+ export * from "./codec.js";
2
+ export * from "./commands.js";
3
+ export * from "./defs.js";
4
+ export * from "./envelope.js";
5
+ export * from "./events.js";
6
+ export * from "./metrics.js";
7
+ export * from "./registry.js";
8
+ export * from "./rest.js";
9
+ export * from "./units.js";
10
+ export * from "./room.js";
11
+ export * from "./state.js";
12
+ export * from "./verbs.js";
@@ -0,0 +1,13 @@
1
+ // Generated: everything the wire defines, from one door. Never edited by hand.
2
+ export * from "./codec.js";
3
+ export * from "./commands.js";
4
+ export * from "./defs.js";
5
+ export * from "./envelope.js";
6
+ export * from "./events.js";
7
+ export * from "./metrics.js";
8
+ export * from "./registry.js";
9
+ export * from "./rest.js";
10
+ export * from "./units.js";
11
+ export * from "./room.js";
12
+ export * from "./state.js";
13
+ export * from "./verbs.js";