@pyai/sdk 0.12.0 → 0.14.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.
- package/CLI.schema.json +2 -1
- package/README.md +58 -6
- package/dist/cli-omni-template.d.ts +2 -2
- package/dist/cli-omni-template.js +2 -2
- package/dist/cli-web-auth.d.ts +2 -0
- package/dist/cli-web-auth.js +2 -0
- package/dist/cli.js +2 -2
- package/dist/dialer/appServer.d.ts +4 -0
- package/dist/dialer/appServer.js +84 -4
- package/dist/dialer/dialerElement.js +28 -6
- package/dist/dialer/dialingQueue.d.ts +33 -10
- package/dist/dialer/dialingQueue.js +124 -41
- package/dist/dialer/fileMeetingIntelligenceJournal.d.ts +14 -0
- package/dist/dialer/fileMeetingIntelligenceJournal.js +147 -0
- package/dist/dialer/index.d.ts +1 -0
- package/dist/dialer/index.js +1 -0
- package/dist/dialer/indexedDbJournal.d.ts +9 -0
- package/dist/dialer/indexedDbJournal.js +62 -1
- package/dist/dialer/managedDialer.d.ts +40 -2
- package/dist/dialer/managedDialer.js +137 -10
- package/dist/dialer/meetingIntelligence.d.ts +28 -0
- package/dist/dialer/meetingIntelligence.js +3 -0
- package/dist/dialer/meetingIntelligenceElement.d.ts +21 -0
- package/dist/dialer/meetingIntelligenceElement.js +112 -0
- package/dist/dialer/serverBroker.js +19 -2
- package/dist/dialer/serverMeetingIntelligence.d.ts +60 -0
- package/dist/dialer/serverMeetingIntelligence.js +207 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +24 -0
- package/package.json +9 -1
- package/src/cli-omni-template.ts +2 -2
- package/src/cli-web-auth.ts +3 -0
- package/src/cli.ts +2 -2
- package/src/dialer/MEETING_INTELLIGENCE.md +76 -0
- package/src/dialer/app/app.html +3 -3
- package/src/dialer/app/app.js +45 -16
- package/src/dialer/appServer.ts +63 -5
- package/src/dialer/dialerElement.ts +24 -5
- package/src/dialer/dialingQueue.ts +108 -45
- package/src/dialer/fileMeetingIntelligenceJournal.ts +77 -0
- package/src/dialer/index.ts +2 -0
- package/src/dialer/indexedDbJournal.ts +58 -1
- package/src/dialer/managedDialer.ts +115 -9
- package/src/dialer/meetingIntelligence.ts +21 -0
- package/src/dialer/meetingIntelligenceElement.ts +65 -0
- package/src/dialer/serverBroker.ts +17 -2
- package/src/dialer/serverMeetingIntelligence.ts +148 -0
- package/src/index.ts +37 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const terminal = (call) => ["completed", "failed", "canceled"].includes(call.status);
|
|
2
|
+
/** A durable handoff keeps its original room after the browser goes away. */
|
|
3
|
+
export const dialerCallHandedOff = (call) => call.transfer_enabled === true && Boolean(call.transfers?.some(transfer => transfer.status === "completed" || transfer.mode === "cold" && ["dialing", "ready", "completing"].includes(transfer.status)));
|
|
2
4
|
/** One immutable workspace/user scope per instance. Setup and stop retain the
|
|
3
5
|
* original intent through lost acknowledgments, reloads and audio failures. */
|
|
4
6
|
export class ManagedDialer {
|
|
@@ -7,6 +9,7 @@ export class ManagedDialer {
|
|
|
7
9
|
listeners = new Set();
|
|
8
10
|
operation = null;
|
|
9
11
|
initialized = false;
|
|
12
|
+
stopBeforeIntent = false;
|
|
10
13
|
scope;
|
|
11
14
|
broker;
|
|
12
15
|
journal;
|
|
@@ -24,6 +27,10 @@ export class ManagedDialer {
|
|
|
24
27
|
this.now = now;
|
|
25
28
|
}
|
|
26
29
|
get current() { return structuredClone(this.snapshot); }
|
|
30
|
+
get restored() { return this.initialized; }
|
|
31
|
+
get recoveryScope() { return this.scope; }
|
|
32
|
+
/** Durable queue ownership only; never contains a browser capability. */
|
|
33
|
+
get queueContext() { return this.intent?.queue ? structuredClone(this.intent.queue) : null; }
|
|
27
34
|
subscribe(listener) {
|
|
28
35
|
this.listeners.add(listener);
|
|
29
36
|
listener(this.current);
|
|
@@ -61,14 +68,14 @@ export class ManagedDialer {
|
|
|
61
68
|
this.intent = saved ? structuredClone(saved) : null;
|
|
62
69
|
this.initialized = true;
|
|
63
70
|
if (saved) {
|
|
64
|
-
this.update({ state: "unconfirmed", callId: saved.callId ?? null, error: "Recover the previous call before starting another." });
|
|
71
|
+
this.update({ state: "unconfirmed", callId: saved.callId ?? null, transferPending: Boolean(saved.transfer), error: "Recover the previous call before starting another." });
|
|
65
72
|
// Reload never consumes a new browser capability automatically.
|
|
66
73
|
if (saved.callId)
|
|
67
74
|
await this.readStatus();
|
|
68
75
|
}
|
|
69
76
|
});
|
|
70
77
|
}
|
|
71
|
-
async start(input) {
|
|
78
|
+
async start(input, queue) {
|
|
72
79
|
if (!this.initialized)
|
|
73
80
|
throw new Error("Restore the calling journal before dialing.");
|
|
74
81
|
if (this.intent)
|
|
@@ -78,10 +85,15 @@ export class ManagedDialer {
|
|
|
78
85
|
new Set(destinations).size !== destinations.length || destinations.some(to => typeof to !== "string" || !/^\+[1-9]\d{6,14}$/.test(to)))
|
|
79
86
|
throw new Error("Choose one destination or two to four distinct parallel destinations with country codes.");
|
|
80
87
|
return this.exclusive(async () => {
|
|
81
|
-
|
|
88
|
+
this.stopBeforeIntent = false;
|
|
89
|
+
const intent = { scope: this.scope, key: this.newKey(), input: structuredClone(input), stopping: false, ...(queue ? { queue: structuredClone(queue) } : {}) };
|
|
82
90
|
// Persist before the first network request. A storage failure cannot dial.
|
|
83
91
|
await this.journal.write(structuredClone(intent));
|
|
84
92
|
this.intent = intent;
|
|
93
|
+
if (this.stopBeforeIntent) {
|
|
94
|
+
intent.stopping = true;
|
|
95
|
+
await this.journal.write(structuredClone(intent));
|
|
96
|
+
}
|
|
85
97
|
await this.setup();
|
|
86
98
|
});
|
|
87
99
|
}
|
|
@@ -112,7 +124,7 @@ export class ManagedDialer {
|
|
|
112
124
|
if (saved.stopping)
|
|
113
125
|
intent.stopping = true;
|
|
114
126
|
this.update({ callId: session.call_id, call: session.call });
|
|
115
|
-
if (terminal(session.call)) {
|
|
127
|
+
if (terminal(session.call) || dialerCallHandedOff(session.call)) {
|
|
116
128
|
await this.acceptStatus(session.call);
|
|
117
129
|
return;
|
|
118
130
|
}
|
|
@@ -125,7 +137,7 @@ export class ManagedDialer {
|
|
|
125
137
|
return;
|
|
126
138
|
}
|
|
127
139
|
await this.audio.connect(session, state => {
|
|
128
|
-
if (this.intent !== intent || intent.stopping || this.snapshot.state
|
|
140
|
+
if (this.intent?.key !== intent.key || this.intent.stopping || ["wrapup", "handing_off", "transferred"].includes(this.snapshot.state))
|
|
129
141
|
return;
|
|
130
142
|
if (state === "disconnected") {
|
|
131
143
|
this.audio.disconnect();
|
|
@@ -160,16 +172,46 @@ export class ManagedDialer {
|
|
|
160
172
|
throw new Error("Calling status identity changed.");
|
|
161
173
|
if (this.snapshot.call && call.version < this.snapshot.call.version)
|
|
162
174
|
return;
|
|
175
|
+
const transfer = this.intent.transfer;
|
|
176
|
+
if (transfer) {
|
|
177
|
+
const observed = call.transfers?.slice().reverse().find(item => transfer.id ? item.id === transfer.id : !transfer.priorIds?.includes(item.id) && item.to === transfer.to && item.mode === transfer.mode);
|
|
178
|
+
if (observed && observed.to === transfer.to && observed.mode === transfer.mode) {
|
|
179
|
+
const next = structuredClone(this.intent);
|
|
180
|
+
if (["canceled", "failed"].includes(observed.status)) {
|
|
181
|
+
next.retiredTransferKeys = [...new Set([...(next.retiredTransferKeys ?? []), transfer.key])];
|
|
182
|
+
delete next.transfer;
|
|
183
|
+
}
|
|
184
|
+
else
|
|
185
|
+
next.transfer.id = observed.id;
|
|
186
|
+
await this.journal.write(next);
|
|
187
|
+
this.intent = next;
|
|
188
|
+
this.update({ transferPending: Boolean(transfer.command && !["completed", "canceled", "failed"].includes(observed.status)) });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
163
191
|
if (terminal(call)) {
|
|
164
192
|
this.audio.disconnect();
|
|
165
193
|
this.update({ call, state: "wrapup", muted: false, error: null });
|
|
166
194
|
}
|
|
195
|
+
else if (dialerCallHandedOff(call)) {
|
|
196
|
+
this.audio.disconnect();
|
|
197
|
+
this.update({ call, state: call.transfers?.some(item => item.status === "completed") ? "transferred" : "handing_off", muted: false, error: null });
|
|
198
|
+
}
|
|
167
199
|
else
|
|
168
200
|
this.update({ call });
|
|
169
201
|
}
|
|
170
202
|
async stop() {
|
|
171
|
-
|
|
172
|
-
|
|
203
|
+
// The first durable write may still be pending, before intent is installed.
|
|
204
|
+
// Preserve a close/stop request so setup cannot open late browser audio.
|
|
205
|
+
if (!this.intent) {
|
|
206
|
+
if (!this.operation)
|
|
207
|
+
return;
|
|
208
|
+
this.stopBeforeIntent = true;
|
|
209
|
+
await this.operation;
|
|
210
|
+
if (!this.intent)
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (this.snapshot.call && dialerCallHandedOff(this.snapshot.call))
|
|
214
|
+
throw new Error("The transferred conversation continues independently. Check its status instead of ending the caller's conversation.");
|
|
173
215
|
// Mark immediately so a late create acknowledgment cannot connect audio.
|
|
174
216
|
this.intent.stopping = true;
|
|
175
217
|
this.audio.disconnect();
|
|
@@ -178,6 +220,11 @@ export class ManagedDialer {
|
|
|
178
220
|
if (this.operation)
|
|
179
221
|
await this.operation;
|
|
180
222
|
return this.exclusive(async () => {
|
|
223
|
+
if (this.snapshot.call && dialerCallHandedOff(this.snapshot.call)) {
|
|
224
|
+
this.intent.stopping = false;
|
|
225
|
+
await this.journal.write(structuredClone(this.intent));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
181
228
|
await this.journal.write(structuredClone(this.intent));
|
|
182
229
|
if (!this.intent.callId)
|
|
183
230
|
await this.setup();
|
|
@@ -187,6 +234,13 @@ export class ManagedDialer {
|
|
|
187
234
|
}
|
|
188
235
|
async stopKnown() {
|
|
189
236
|
try {
|
|
237
|
+
const current = await this.broker.get(this.intent.callId);
|
|
238
|
+
if (dialerCallHandedOff(current)) {
|
|
239
|
+
this.intent.stopping = false;
|
|
240
|
+
await this.journal.write(structuredClone(this.intent));
|
|
241
|
+
await this.acceptStatus(current);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
190
244
|
const call = await this.broker.hangup(this.intent.callId);
|
|
191
245
|
await this.acceptStatus(call);
|
|
192
246
|
if (!terminal(call))
|
|
@@ -198,13 +252,86 @@ export class ManagedDialer {
|
|
|
198
252
|
}
|
|
199
253
|
async finishWrapup() {
|
|
200
254
|
return this.exclusive(async () => {
|
|
201
|
-
if (!this.intent || this.snapshot.
|
|
202
|
-
|
|
255
|
+
if (!this.intent || !this.snapshot.call || !(this.snapshot.state === "wrapup" && terminal(this.snapshot.call) ||
|
|
256
|
+
this.snapshot.state === "transferred" && this.snapshot.call.transfers?.some(item => item.status === "completed")))
|
|
257
|
+
throw new Error("Confirmed call completion or successful transfer is required.");
|
|
203
258
|
await this.journal.clear(this.scope, this.intent.key);
|
|
204
259
|
this.intent = null;
|
|
205
|
-
this.update({ state: "idle", callId: null, call: null, muted: false, error: null });
|
|
260
|
+
this.update({ state: "idle", callId: null, call: null, muted: false, error: null, transferPending: false });
|
|
206
261
|
});
|
|
207
262
|
}
|
|
263
|
+
async transfer(to, mode) {
|
|
264
|
+
if (!/^\+[1-9]\d{6,14}$/.test(to) || !["warm", "cold"].includes(mode))
|
|
265
|
+
throw new Error("Choose a transfer destination with its country code and a transfer mode.");
|
|
266
|
+
return this.exclusive(async () => {
|
|
267
|
+
if (!this.intent?.callId || this.snapshot.state !== "active" || !this.snapshot.call?.transfer_enabled || !this.broker.transfers)
|
|
268
|
+
throw new Error("Transfers require a connected call started with transfers enabled.");
|
|
269
|
+
if (this.intent.transfer || this.snapshot.call.transfers?.some(item => !["completed", "canceled", "failed"].includes(item.status)))
|
|
270
|
+
throw new Error("Recover or finish the current transfer before starting another.");
|
|
271
|
+
const next = structuredClone(this.intent);
|
|
272
|
+
next.transfer = { key: this.newKey(), to, mode, priorIds: this.snapshot.call.transfers?.map(item => item.id) ?? [] };
|
|
273
|
+
await this.journal.write(next);
|
|
274
|
+
this.intent = next;
|
|
275
|
+
await this.transferKnown();
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
async retryTransfer() {
|
|
279
|
+
return this.exclusive(async () => {
|
|
280
|
+
if (!this.intent?.transfer)
|
|
281
|
+
throw new Error("No transfer to recover.");
|
|
282
|
+
await this.transferKnown();
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
async completeTransfer() { return this.transferCommand("complete"); }
|
|
286
|
+
async cancelTransfer() { return this.transferCommand("cancel"); }
|
|
287
|
+
async transferCommand(command) {
|
|
288
|
+
return this.exclusive(async () => {
|
|
289
|
+
if (!this.intent?.transfer?.id || !this.broker.transfers)
|
|
290
|
+
throw new Error("Recover the transfer identity first.");
|
|
291
|
+
const transfer = this.snapshot.call?.transfers?.find(item => item.id === this.intent.transfer.id);
|
|
292
|
+
if (command === "complete" && transfer?.status !== "ready")
|
|
293
|
+
throw new Error("Wait until the transfer target has joined.");
|
|
294
|
+
if (this.intent.transfer.mode !== "warm")
|
|
295
|
+
throw new Error("Cold transfers complete automatically.");
|
|
296
|
+
if (this.intent.transfer.command && this.intent.transfer.command !== command)
|
|
297
|
+
throw new Error("Recover the saved transfer command first.");
|
|
298
|
+
const next = structuredClone(this.intent);
|
|
299
|
+
next.transfer.command = command;
|
|
300
|
+
await this.journal.write(next);
|
|
301
|
+
this.intent = next;
|
|
302
|
+
await this.transferKnown();
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
async transferKnown() {
|
|
306
|
+
this.update({ transferPending: true, error: null });
|
|
307
|
+
try {
|
|
308
|
+
const original = this.intent, saved = await this.journal.read(this.scope);
|
|
309
|
+
if (!saved || saved.scope !== this.scope || saved.key !== original.key || saved.callId !== original.callId ||
|
|
310
|
+
saved.transfer?.key !== original.transfer?.key || saved.transfer?.to !== original.transfer?.to || saved.transfer?.mode !== original.transfer?.mode)
|
|
311
|
+
throw new Error("Saved transfer intent changed.");
|
|
312
|
+
this.intent = saved;
|
|
313
|
+
if (saved.stopping) {
|
|
314
|
+
await this.stopKnown();
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const intent = saved, transfer = saved.transfer, broker = this.broker.transfers;
|
|
318
|
+
const call = transfer.command && transfer.id ? await broker[transfer.command](intent.callId, transfer.id)
|
|
319
|
+
: await broker.create(intent.callId, { to: transfer.to, mode: transfer.mode }, transfer.key);
|
|
320
|
+
if (call.id !== intent.callId)
|
|
321
|
+
throw new Error("Transfer call identity changed.");
|
|
322
|
+
const observed = transfer.id ? call.transfers?.find(item => item.id === transfer.id)
|
|
323
|
+
: call.transfers?.slice().reverse().find(item => !transfer.priorIds?.includes(item.id) && item.to === transfer.to && item.mode === transfer.mode);
|
|
324
|
+
if (!observed || observed.to !== transfer.to || observed.mode !== transfer.mode)
|
|
325
|
+
throw new Error("Transfer identity is unavailable.");
|
|
326
|
+
transfer.id = observed.id;
|
|
327
|
+
await this.journal.write(structuredClone(intent));
|
|
328
|
+
await this.acceptStatus(call);
|
|
329
|
+
this.update({ transferPending: false });
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
this.update({ transferPending: true, error: "Transfer is unconfirmed. Recover this same transfer before trying another." });
|
|
333
|
+
}
|
|
334
|
+
}
|
|
208
335
|
mute(value) {
|
|
209
336
|
if (this.snapshot.state !== "active")
|
|
210
337
|
throw new Error("No active audio call.");
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Browser-safe meeting intelligence contract. All methods belong to the
|
|
2
|
+
* authenticated host; project credentials and private audio URLs stay there. */
|
|
3
|
+
export declare const MEETING_UPLOAD_NOTICE = "Send this recording to PyAI Hear and Recap for a transcript, notes and action items. Uploaded audio may remain for up to 7 days and job results for up to 30 days; Recap follows your workspace retention policy. Removing the meeting from this app clears cached notes and requests cancellation, not cloud erasure. The browser recording remains saved. Continue only after informing everyone and accepting this policy.";
|
|
4
|
+
export interface MeetingIntelligenceView {
|
|
5
|
+
recordingId: string;
|
|
6
|
+
state: "submitting" | "transcribing" | "summarizing" | "complete" | "failed" | "removed";
|
|
7
|
+
transcript: string | null;
|
|
8
|
+
notes: string | null;
|
|
9
|
+
actionItems: Array<{
|
|
10
|
+
task: string;
|
|
11
|
+
owner?: string | null;
|
|
12
|
+
due?: string | null;
|
|
13
|
+
}>;
|
|
14
|
+
error: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface MeetingIntelligenceAvailability {
|
|
17
|
+
available: boolean;
|
|
18
|
+
reason: string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface MeetingIntelligenceBroker {
|
|
21
|
+
availability(): Promise<MeetingIntelligenceAvailability>;
|
|
22
|
+
/** Must be a foreground action with the upload/retention notice accepted. */
|
|
23
|
+
submit(recordingId: string, audio: Blob, noticeAccepted: boolean): Promise<MeetingIntelligenceView>;
|
|
24
|
+
get(recordingId: string): Promise<MeetingIntelligenceView>;
|
|
25
|
+
/** Clears cached notes, cancels known unfinished Hear work, and keeps an
|
|
26
|
+
* opaque tombstone. Public job cancellation does not erase cloud artifacts. */
|
|
27
|
+
remove(recordingId: string): Promise<MeetingIntelligenceView>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Browser-safe meeting intelligence contract. All methods belong to the
|
|
2
|
+
* authenticated host; project credentials and private audio URLs stay there. */
|
|
3
|
+
export const MEETING_UPLOAD_NOTICE = "Send this recording to PyAI Hear and Recap for a transcript, notes and action items. Uploaded audio may remain for up to 7 days and job results for up to 30 days; Recap follows your workspace retention policy. Removing the meeting from this app clears cached notes and requests cancellation, not cloud erasure. The browser recording remains saved. Continue only after informing everyone and accepting this policy.";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type MeetingIntelligenceBroker } from "./meetingIntelligence.ts";
|
|
2
|
+
import type { MeetingRecordingStore } from "./meetingRecorder.ts";
|
|
3
|
+
/** Optional companion to pyai-meeting-recorder. Bind the trusted current
|
|
4
|
+
* org/user scope and authenticated host broker; never pass a project API key. */
|
|
5
|
+
export declare class PyaiMeetingIntelligenceElement extends HTMLElement {
|
|
6
|
+
private root;
|
|
7
|
+
private scope;
|
|
8
|
+
private store;
|
|
9
|
+
private broker;
|
|
10
|
+
private generation;
|
|
11
|
+
private busy;
|
|
12
|
+
constructor();
|
|
13
|
+
bind(scope: string, store: MeetingRecordingStore, broker: MeetingIntelligenceBroker): void;
|
|
14
|
+
disconnectedCallback(): void;
|
|
15
|
+
private selected;
|
|
16
|
+
private clear;
|
|
17
|
+
private buttons;
|
|
18
|
+
private refreshRecordings;
|
|
19
|
+
private render;
|
|
20
|
+
private run;
|
|
21
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { MEETING_UPLOAD_NOTICE } from "./meetingIntelligence.js";
|
|
2
|
+
/** Optional companion to pyai-meeting-recorder. Bind the trusted current
|
|
3
|
+
* org/user scope and authenticated host broker; never pass a project API key. */
|
|
4
|
+
export class PyaiMeetingIntelligenceElement extends HTMLElement {
|
|
5
|
+
root;
|
|
6
|
+
scope = "";
|
|
7
|
+
store = null;
|
|
8
|
+
broker = null;
|
|
9
|
+
generation = 0;
|
|
10
|
+
busy = false;
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this.root = this.attachShadow({ mode: "open" });
|
|
14
|
+
this.root.innerHTML = `<style>:host{display:block;font:14px/1.5 system-ui;color:#202332;max-width:600px}section{border:1px solid #e7e8ef;border-radius:20px;padding:24px;background:white}label{display:block;margin:12px 0}select,button{font:inherit;padding:10px;border:1px solid #ddd;border-radius:10px;margin:4px}button:disabled{opacity:.5}pre{white-space:pre-wrap;font:inherit;overflow-wrap:anywhere}.notice{font-size:12px;color:#667085}h3{margin-top:0}[role=alert]{color:#b42338}</style><section><h3>Meeting transcript & notes</h3><p data-availability role="status"></p><select aria-label="Saved meeting" data-recording></select><button data-list>Refresh recordings</button><label class="notice"><input type="checkbox" data-notice> <span data-notice-text></span></label><button data-send disabled>Send for transcription</button><button data-refresh disabled>Refresh transcript & notes</button><button data-remove disabled>Remove meeting from app</button><p data-status role="status" aria-live="polite"></p><p role="alert" data-error></p><h4>Transcript</h4><pre data-transcript></pre><h4>Notes</h4><pre data-notes></pre><h4>Action items</h4><ul data-actions></ul></section>`;
|
|
15
|
+
this.root.querySelector("[data-notice-text]").textContent = MEETING_UPLOAD_NOTICE;
|
|
16
|
+
this.root.querySelector("[data-list]").addEventListener("click", () => void this.run(() => this.refreshRecordings()));
|
|
17
|
+
this.root.querySelector("[data-notice]").addEventListener("change", () => this.buttons());
|
|
18
|
+
this.root.querySelector("[data-recording]").addEventListener("change", () => { this.clear(); this.buttons(); });
|
|
19
|
+
this.root.querySelector("[data-send]").addEventListener("click", () => void this.run(async () => {
|
|
20
|
+
const id = this.selected(), scope = this.scope, store = this.store, broker = this.broker, generation = this.generation;
|
|
21
|
+
if (!this.root.querySelector("[data-notice]").checked)
|
|
22
|
+
throw new Error("Accept the upload and retention notice first.");
|
|
23
|
+
const recording = await store.get(scope, id);
|
|
24
|
+
if (!recording || recording.scope !== scope || recording.state !== "ready")
|
|
25
|
+
throw new Error("Stop the recording and review any interrupted capture before submitting it through your app.");
|
|
26
|
+
const audio = await store.audio(scope, id);
|
|
27
|
+
// A workspace change cannot submit the former workspace's audio.
|
|
28
|
+
if (generation !== this.generation)
|
|
29
|
+
return;
|
|
30
|
+
const result = await broker.submit(id, audio, true);
|
|
31
|
+
if (generation === this.generation)
|
|
32
|
+
this.render(result);
|
|
33
|
+
}));
|
|
34
|
+
for (const [selector, operation] of [["[data-refresh]", "get"], ["[data-remove]", "remove"]])
|
|
35
|
+
this.root.querySelector(selector).addEventListener("click", () => void this.run(async () => {
|
|
36
|
+
const generation = this.generation, result = await this.broker[operation](this.selected());
|
|
37
|
+
if (generation === this.generation)
|
|
38
|
+
this.render(result);
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
bind(scope, store, broker) {
|
|
42
|
+
if (this.busy)
|
|
43
|
+
throw new Error("Wait for the current meeting action before switching workspaces.");
|
|
44
|
+
if (!scope.trim())
|
|
45
|
+
throw new Error("An authenticated workspace/user scope is required.");
|
|
46
|
+
++this.generation;
|
|
47
|
+
this.scope = scope;
|
|
48
|
+
this.store = store;
|
|
49
|
+
this.broker = broker;
|
|
50
|
+
this.clear();
|
|
51
|
+
this.root.querySelector("[data-notice]").checked = false;
|
|
52
|
+
void this.run(() => this.refreshRecordings());
|
|
53
|
+
}
|
|
54
|
+
disconnectedCallback() { ++this.generation; }
|
|
55
|
+
selected() { const id = this.root.querySelector("[data-recording]").value; if (!id)
|
|
56
|
+
throw new Error("Choose a saved meeting."); return id; }
|
|
57
|
+
clear() { for (const selector of ["[data-status]", "[data-error]", "[data-transcript]", "[data-notes]", "[data-actions]"])
|
|
58
|
+
this.root.querySelector(selector).textContent = ""; }
|
|
59
|
+
buttons() {
|
|
60
|
+
const selected = !!this.root.querySelector("[data-recording]").value;
|
|
61
|
+
for (const selector of ["[data-send]", "[data-refresh]", "[data-remove]"])
|
|
62
|
+
this.root.querySelector(selector).disabled = this.busy || !this.broker || !selected || selector === "[data-send]" && !this.root.querySelector("[data-notice]").checked || selector === "[data-send]" && this.root.querySelector("[data-availability]").getAttribute("data-available") !== "true";
|
|
63
|
+
this.root.querySelector("[data-recording]").disabled = this.busy;
|
|
64
|
+
}
|
|
65
|
+
async refreshRecordings() {
|
|
66
|
+
if (!this.store || !this.broker)
|
|
67
|
+
return;
|
|
68
|
+
const generation = this.generation, [records, availability] = await Promise.all([this.store.list(this.scope), this.broker.availability()]);
|
|
69
|
+
if (generation !== this.generation)
|
|
70
|
+
return;
|
|
71
|
+
const status = this.root.querySelector("[data-availability]");
|
|
72
|
+
status.textContent = availability.reason ?? "Choose a saved recording, then explicitly send it for transcription.";
|
|
73
|
+
status.setAttribute("data-available", String(availability.available));
|
|
74
|
+
const select = this.root.querySelector("[data-recording]"), previous = select.value;
|
|
75
|
+
select.replaceChildren();
|
|
76
|
+
for (const recording of records.filter(recording => recording.state === "ready").slice(0, 40)) {
|
|
77
|
+
const option = document.createElement("option");
|
|
78
|
+
option.value = recording.id;
|
|
79
|
+
option.textContent = new Date(recording.createdAt).toLocaleString();
|
|
80
|
+
select.append(option);
|
|
81
|
+
}
|
|
82
|
+
if (Array.from(select.options).some(option => option.value === previous))
|
|
83
|
+
select.value = previous;
|
|
84
|
+
this.buttons();
|
|
85
|
+
}
|
|
86
|
+
render(view) {
|
|
87
|
+
this.root.querySelector("[data-status]").textContent = ({ submitting: "Sending recording…", transcribing: "Transcribing… Refresh to check progress.", summarizing: "Transcript ready. Preparing notes… Refresh to check progress.", complete: "Transcript and notes ready.", failed: "Meeting needs attention.", removed: "Cached notes removed. The browser recording remains saved; cloud retention still applies." })[view.state];
|
|
88
|
+
this.root.querySelector("[data-error]").textContent = view.error ?? "";
|
|
89
|
+
this.root.querySelector("[data-transcript]").textContent = view.transcript ?? "";
|
|
90
|
+
this.root.querySelector("[data-notes]").textContent = view.notes ?? "";
|
|
91
|
+
const list = this.root.querySelector("[data-actions]");
|
|
92
|
+
list.replaceChildren();
|
|
93
|
+
for (const action of view.actionItems) {
|
|
94
|
+
const item = document.createElement("li");
|
|
95
|
+
item.textContent = [action.task, action.owner, action.due].filter(Boolean).join(" · ");
|
|
96
|
+
list.append(item);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async run(action) { if (this.busy)
|
|
100
|
+
return; this.busy = true; this.buttons(); try {
|
|
101
|
+
await action();
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
this.root.querySelector("[data-error]").textContent = error instanceof Error ? error.message : "Meeting action failed. Recover the same recording before sending another.";
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
this.busy = false;
|
|
108
|
+
this.buttons();
|
|
109
|
+
} }
|
|
110
|
+
}
|
|
111
|
+
if (!customElements.get("pyai-meeting-intelligence"))
|
|
112
|
+
customElements.define("pyai-meeting-intelligence", PyaiMeetingIntelligenceElement);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/** Server-only broker. Never import this module into a browser bundle. */
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
|
+
import { dialerCallHandedOff } from "./managedDialer.js";
|
|
3
4
|
export function createServerDialerBroker(sdk, authenticatedUserId) {
|
|
4
5
|
if (!authenticatedUserId.trim())
|
|
5
6
|
throw new Error("An authenticated user is required.");
|
|
6
7
|
const ownedCall = async (id) => {
|
|
7
8
|
const call = await sdk.telephony.calls.get(id);
|
|
8
|
-
if (call.call_type !== "human" || call.user_id !== authenticatedUserId)
|
|
9
|
+
if (call.id !== id || call.call_type !== "human" || call.user_id !== authenticatedUserId)
|
|
9
10
|
throw new Error("No such call.");
|
|
10
11
|
return call;
|
|
11
12
|
};
|
|
@@ -18,6 +19,22 @@ export function createServerDialerBroker(sdk, authenticatedUserId) {
|
|
|
18
19
|
return sdk.telephony.browserSessions.create({ ...input, user_id: authenticatedUserId }, { idempotencyKey: scopedKey });
|
|
19
20
|
},
|
|
20
21
|
get: ownedCall,
|
|
21
|
-
async hangup(id) {
|
|
22
|
+
async hangup(id) {
|
|
23
|
+
const call = await ownedCall(id);
|
|
24
|
+
if (dialerCallHandedOff(call))
|
|
25
|
+
return call;
|
|
26
|
+
return sdk.telephony.calls.hangup(id);
|
|
27
|
+
},
|
|
28
|
+
transfers: {
|
|
29
|
+
async create(id, input, key) {
|
|
30
|
+
await ownedCall(id);
|
|
31
|
+
if (!key || key.length > 255 || /[\r\n]/.test(key))
|
|
32
|
+
throw new Error("A valid transfer retry key is required.");
|
|
33
|
+
const scopedKey = "dialer-transfer:" + createHash("sha256").update(authenticatedUserId).update("\0").update(id).update("\0").update(key).digest("hex");
|
|
34
|
+
return sdk.telephony.calls.transfers.create(id, { ...input, user_id: authenticatedUserId }, { idempotencyKey: scopedKey });
|
|
35
|
+
},
|
|
36
|
+
async complete(id, transferId) { await ownedCall(id); return sdk.telephony.calls.transfers.complete(id, transferId, authenticatedUserId); },
|
|
37
|
+
async cancel(id, transferId) { await ownedCall(id); return sdk.telephony.calls.transfers.cancel(id, transferId, authenticatedUserId); },
|
|
38
|
+
},
|
|
22
39
|
};
|
|
23
40
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { MeResponse, PyAI, RecapCall, TranscriptionJob } from "../index.ts";
|
|
2
|
+
import type { MeetingIntelligenceBroker, MeetingIntelligenceView } from "./meetingIntelligence.ts";
|
|
3
|
+
export interface MeetingIntelligenceApi {
|
|
4
|
+
me(): Promise<MeResponse>;
|
|
5
|
+
recapEnabled(): Promise<boolean>;
|
|
6
|
+
upload(audio: Blob, filename: string, callId: string, key: string): Promise<TranscriptionJob>;
|
|
7
|
+
job(id: string): Promise<TranscriptionJob>;
|
|
8
|
+
recap(id: string): Promise<RecapCall | null>;
|
|
9
|
+
cancel(id: string): Promise<TranscriptionJob>;
|
|
10
|
+
}
|
|
11
|
+
export declare class MeetingApiError extends Error {
|
|
12
|
+
readonly status: number;
|
|
13
|
+
constructor(status: number);
|
|
14
|
+
}
|
|
15
|
+
/** Uses only public routes. Keyed multipart requires the durable job retry contract; no public bucket,
|
|
16
|
+
* arbitrary result_url fetch, or browser-held key is involved. */
|
|
17
|
+
export declare function createPyaiMeetingApi(options: {
|
|
18
|
+
apiKey: string;
|
|
19
|
+
baseURL?: string;
|
|
20
|
+
fetch?: typeof fetch;
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
}): MeetingIntelligenceApi;
|
|
23
|
+
export interface MeetingIntelligenceEntry {
|
|
24
|
+
key: string;
|
|
25
|
+
recordingId: string;
|
|
26
|
+
owner: string;
|
|
27
|
+
digest: string;
|
|
28
|
+
mimeType: string;
|
|
29
|
+
bytes: number;
|
|
30
|
+
createdAt: number;
|
|
31
|
+
expiresAt: number;
|
|
32
|
+
jobId: string | null;
|
|
33
|
+
state: MeetingIntelligenceView["state"];
|
|
34
|
+
transcript: string | null;
|
|
35
|
+
notes: string | null;
|
|
36
|
+
actionItems: MeetingIntelligenceView["actionItems"];
|
|
37
|
+
error: string | null;
|
|
38
|
+
}
|
|
39
|
+
/** Host-owned persistent store. run must serialize across ALL host instances,
|
|
40
|
+
* including erase vs submit/get. Save must durably commit before resolving.
|
|
41
|
+
* Reuse the host's existing ownership journal/transaction facility. */
|
|
42
|
+
export interface MeetingIntelligenceJournal {
|
|
43
|
+
run<T>(key: string, action: () => Promise<T>): Promise<T>;
|
|
44
|
+
get(key: string): Promise<MeetingIntelligenceEntry | null>;
|
|
45
|
+
save(entry: MeetingIntelligenceEntry): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export declare function createServerMeetingIntelligence(options: {
|
|
48
|
+
api: MeetingIntelligenceApi;
|
|
49
|
+
orgId: string;
|
|
50
|
+
projectId: string;
|
|
51
|
+
userId: string;
|
|
52
|
+
keyId: string;
|
|
53
|
+
journal: MeetingIntelligenceJournal;
|
|
54
|
+
now?: () => number;
|
|
55
|
+
maxBytes?: number;
|
|
56
|
+
retentionMs?: number;
|
|
57
|
+
}): MeetingIntelligenceBroker;
|
|
58
|
+
/** Reuses the host's already selected SDK instance and its normal transport.
|
|
59
|
+
* The SDK never exposes the key to the renderer. */
|
|
60
|
+
export declare function createSdkMeetingApi(sdk: PyAI): MeetingIntelligenceApi;
|