@pyai/sdk 0.17.0 → 0.18.1
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/AGENT_GUIDE.md +4 -4
- package/CLI.md +24 -4
- package/CLI.schema.json +2 -1
- package/README.md +3 -3
- package/dist/cli-dx.js +3 -1
- package/dist/cli-init.js +4 -3
- package/dist/cli-omni-template.d.ts +2 -2
- package/dist/cli-omni-template.js +2 -2
- package/dist/cli.js +10 -8
- package/dist/dialer/appServer.d.ts +11 -1
- package/dist/dialer/appServer.js +224 -28
- package/dist/dialer/dialerElement.d.ts +2 -0
- package/dist/dialer/dialerElement.js +12 -3
- package/dist/dialer/dialingQueue.d.ts +3 -0
- package/dist/dialer/dialingQueue.js +63 -47
- package/dist/dialer/indexedDbJournal.d.ts +2 -0
- package/dist/dialer/indexedDbJournal.js +8 -0
- package/dist/dialer/managedDialer.js +3 -1
- package/dist/dialer/presentation.d.ts +19 -0
- package/dist/dialer/presentation.js +37 -0
- package/dist/index.d.ts +88 -3
- package/dist/index.js +16 -2
- package/package.json +1 -1
- package/src/cli-dx.ts +5 -1
- package/src/cli-init.ts +5 -3
- package/src/cli-omni-template.ts +2 -2
- package/src/cli.ts +9 -7
- package/src/dialer/app/app.css +6 -1
- package/src/dialer/app/app.html +4 -4
- package/src/dialer/app/app.js +92 -12
- package/src/dialer/app/incoming.js +107 -0
- package/src/dialer/appServer.ts +159 -27
- package/src/dialer/dialerElement.ts +13 -3
- package/src/dialer/dialingQueue.ts +51 -35
- package/src/dialer/indexedDbJournal.ts +6 -1
- package/src/dialer/managedDialer.ts +3 -1
- package/src/dialer/presentation.ts +38 -0
- package/src/index.ts +39 -5
|
@@ -60,7 +60,9 @@ export class ManagedDialer {
|
|
|
60
60
|
}
|
|
61
61
|
async restore() {
|
|
62
62
|
return this.exclusive(async () => {
|
|
63
|
-
|
|
63
|
+
// Queue recovery may have waited for another tab to save an admission
|
|
64
|
+
// after this instance first loaded an empty journal.
|
|
65
|
+
if (this.initialized && this.intent)
|
|
64
66
|
return;
|
|
65
67
|
const saved = await this.journal.read(this.scope);
|
|
66
68
|
if (saved && saved.scope !== this.scope)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Presentation metadata only. No credentials, network origins or calling policy. */
|
|
2
|
+
export interface DialerPresentation {
|
|
3
|
+
name: string;
|
|
4
|
+
white_label: boolean;
|
|
5
|
+
primary_color: string;
|
|
6
|
+
logo_png: string | null;
|
|
7
|
+
layout: "compact" | "comfortable";
|
|
8
|
+
features: {
|
|
9
|
+
calls: boolean;
|
|
10
|
+
incoming: boolean;
|
|
11
|
+
meetings: boolean;
|
|
12
|
+
power_queue: boolean;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export type DialerPresentationInput = Partial<Omit<DialerPresentation, "features">> & {
|
|
16
|
+
features?: Partial<DialerPresentation["features"]>;
|
|
17
|
+
};
|
|
18
|
+
export declare const defaultPresentation: DialerPresentation;
|
|
19
|
+
export declare function validatePresentation(value: unknown, defaults?: DialerPresentation): DialerPresentation;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const featureNames = ["calls", "incoming", "meetings", "power_queue"];
|
|
2
|
+
export const defaultPresentation = {
|
|
3
|
+
name: "PyAI Phone", white_label: false, primary_color: "#5C4DE4", logo_png: null,
|
|
4
|
+
layout: "compact", features: { calls: true, incoming: true, meetings: true, power_queue: true },
|
|
5
|
+
};
|
|
6
|
+
const record = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
export function validatePresentation(value, defaults = defaultPresentation) {
|
|
8
|
+
if (!record(value) || Object.keys(value).some(key => !["name", "white_label", "primary_color", "logo_png", "layout", "features"].includes(key)))
|
|
9
|
+
throw Error("Use only the app appearance settings.");
|
|
10
|
+
const result = { ...defaults, ...value, features: { ...defaults.features } };
|
|
11
|
+
if (typeof result.name !== "string" || !result.name.trim() || result.name.trim().length > 60 || /[\x00-\x1f\x7f]/.test(result.name))
|
|
12
|
+
throw Error("Use an app name of 1–60 characters.");
|
|
13
|
+
result.name = result.name.trim();
|
|
14
|
+
if (result.white_label && result.name === "PyAI Phone")
|
|
15
|
+
result.name = "Phone";
|
|
16
|
+
if (typeof result.white_label !== "boolean" || typeof result.primary_color !== "string" || !/^#[0-9a-f]{6}$/i.test(result.primary_color) || !["compact", "comfortable"].includes(result.layout))
|
|
17
|
+
throw Error("Choose a valid app color, layout and branding setting.");
|
|
18
|
+
result.primary_color = result.primary_color.toUpperCase();
|
|
19
|
+
if (result.logo_png !== null) {
|
|
20
|
+
if (typeof result.logo_png !== "string" || !/^data:image\/png;base64,[A-Za-z0-9+/]+={0,2}$/.test(result.logo_png))
|
|
21
|
+
throw Error("Choose a PNG logo, not a URL or an SVG.");
|
|
22
|
+
const encoded = result.logo_png.slice(22), bytes = Buffer.from(encoded, "base64");
|
|
23
|
+
if (bytes.length > 8192 || bytes.length < 33 || bytes.toString("base64") !== encoded || !bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) || bytes.toString("ascii", 12, 16) !== "IHDR" || bytes.readUInt32BE(8) !== 13 || bytes.readUInt32BE(16) < 1 || bytes.readUInt32BE(20) < 1 || bytes.readUInt32BE(16) > 512 || bytes.readUInt32BE(20) > 512)
|
|
24
|
+
throw Error("Choose a PNG logo up to 8 KB and 512×512 pixels.");
|
|
25
|
+
}
|
|
26
|
+
if (value.features !== undefined) {
|
|
27
|
+
if (!record(value.features) || Object.keys(value.features).some(key => !featureNames.includes(key)))
|
|
28
|
+
throw Error("Choose only the supported app sections.");
|
|
29
|
+
for (const key of featureNames)
|
|
30
|
+
if (key in value.features) {
|
|
31
|
+
if (typeof value.features[key] !== "boolean")
|
|
32
|
+
throw Error("App section visibility must be on or off.");
|
|
33
|
+
result.features[key] = value.features[key];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -102,10 +102,13 @@ export type SpeechSampleRate = (typeof SPEECH_SAMPLE_RATES)[number];
|
|
|
102
102
|
export type SpeakModel = "pyai-speak" | "tts-1" | "tts-1-hd";
|
|
103
103
|
export interface SpeechParams {
|
|
104
104
|
input: string;
|
|
105
|
+
/** Reuse one unique call ID across utterances for enabled call-stable voice recovery. */
|
|
106
|
+
speech_session_id?: string;
|
|
105
107
|
voice?: string;
|
|
106
108
|
model?: SpeakModel;
|
|
107
109
|
/**
|
|
108
|
-
* Delivery mode.
|
|
110
|
+
* Delivery mode. `speech` defaults to false; `speechStream` always uses true.
|
|
111
|
+
* The API itself defaults to true and every catalog voice accepts
|
|
109
112
|
* both values. Set false when you want one complete buffered body with a
|
|
110
113
|
* `Content-Length`. A voice whose serving fleet has no streaming lane is
|
|
111
114
|
* rendered buffered either way and says so with `x-pyai-stream: buffered`.
|
|
@@ -154,6 +157,10 @@ export type CreateJobParams = CreateJobOptions & ({
|
|
|
154
157
|
audio_url?: never;
|
|
155
158
|
});
|
|
156
159
|
export interface CreateJobOptions {
|
|
160
|
+
/** Spoken-language hint for every audio chunk; omit for automatic detection. */
|
|
161
|
+
transcription_language?: string;
|
|
162
|
+
/** Original script (default), or Roman letters preserving the spoken language; no translation. */
|
|
163
|
+
output_script?: "original" | "latin";
|
|
157
164
|
/** Requires Trace entitlement; incompatible with channel/diarize. */
|
|
158
165
|
trace?: boolean;
|
|
159
166
|
rule_pack?: Record<string, unknown>;
|
|
@@ -431,7 +438,7 @@ export interface HearStreamOptions {
|
|
|
431
438
|
/** Streaming STT model. Server default `pyai-hear`. */
|
|
432
439
|
model?: string;
|
|
433
440
|
/** Omit or use auto for automatic detection; an explicit code pins recognition. */
|
|
434
|
-
language?: "auto" | "en" | "es" | "fr" | "de" | "hi" | "it" | "pt" | "nl" | "zh" | "yue" | "ar" | "id" | "ko" | "th" | "vi" | "ja" | "tr" | "ms" | "sv" | "da" | "fi" | "pl" | "cs" | "fil" | "fa" | "el" | "hu" | "mk" | "ro";
|
|
441
|
+
language?: "auto" | "en" | "es" | "fr" | "de" | "hi" | "it" | "pt" | "nl" | "zh" | "yue" | "ar" | "id" | "ko" | "th" | "vi" | "ja" | "tr" | "ms" | "sv" | "da" | "fi" | "pl" | "cs" | "fil" | "fa" | "el" | "hu" | "mk" | "ro" | "ru";
|
|
435
442
|
/** Input PCM sample rate in Hz. Default 16000 server-side. */
|
|
436
443
|
sampleRate?: number;
|
|
437
444
|
/** Audio frame encoding. Default "pcm16". */
|
|
@@ -1022,6 +1029,61 @@ export interface TelephonyNumberPurchase {
|
|
|
1022
1029
|
compliance_case_id?: string;
|
|
1023
1030
|
max_monthly_cost_cents?: number;
|
|
1024
1031
|
}
|
|
1032
|
+
export interface TelephonyDesktopEndpoint {
|
|
1033
|
+
object: 'telephony.desktop_endpoint';
|
|
1034
|
+
id: string;
|
|
1035
|
+
project_id: string;
|
|
1036
|
+
user_id: string;
|
|
1037
|
+
actor_type: 'application';
|
|
1038
|
+
label: string;
|
|
1039
|
+
registered: boolean;
|
|
1040
|
+
available: boolean;
|
|
1041
|
+
number_id: string;
|
|
1042
|
+
status: 'active' | 'revoked';
|
|
1043
|
+
}
|
|
1044
|
+
export interface TelephonyDesktopEnrollment {
|
|
1045
|
+
object: 'telephony.desktop_enrollment';
|
|
1046
|
+
version: 1;
|
|
1047
|
+
endpoint_id: string;
|
|
1048
|
+
enrollment_token: string;
|
|
1049
|
+
expires_at: number;
|
|
1050
|
+
redeem_path: string;
|
|
1051
|
+
}
|
|
1052
|
+
export interface TelephonyDesktopCredentials {
|
|
1053
|
+
endpoint_id: string;
|
|
1054
|
+
org_id: string;
|
|
1055
|
+
project_id: string;
|
|
1056
|
+
user_id: string;
|
|
1057
|
+
label: string;
|
|
1058
|
+
refresh_token: string;
|
|
1059
|
+
refresh_expires_at: number;
|
|
1060
|
+
access_token: string;
|
|
1061
|
+
expires_at: number;
|
|
1062
|
+
presence_token: string;
|
|
1063
|
+
heartbeat_interval_seconds: 15;
|
|
1064
|
+
}
|
|
1065
|
+
export interface TelephonyInboundRingGroup {
|
|
1066
|
+
mode: 'simultaneous' | 'desktop_first';
|
|
1067
|
+
desktop_endpoint_ids: [string];
|
|
1068
|
+
external_to: string;
|
|
1069
|
+
desktop_timeout_seconds: number;
|
|
1070
|
+
ring_timeout_seconds: number;
|
|
1071
|
+
on_no_answer: 'hangup';
|
|
1072
|
+
max_duration_seconds: number;
|
|
1073
|
+
recording: boolean;
|
|
1074
|
+
}
|
|
1075
|
+
export interface TelephonyInboundCapabilities {
|
|
1076
|
+
object: 'telephony.inbound_capabilities';
|
|
1077
|
+
number_id: string;
|
|
1078
|
+
binding_version: number;
|
|
1079
|
+
ring_group: {
|
|
1080
|
+
supported: boolean;
|
|
1081
|
+
modes: Array<'simultaneous' | 'desktop_first'>;
|
|
1082
|
+
max_desktop_endpoints: 1;
|
|
1083
|
+
on_no_answer: ['hangup'];
|
|
1084
|
+
desktop_registration_required: true;
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1025
1087
|
export interface TelephonyInboundBinding {
|
|
1026
1088
|
object: "telephony.inbound_binding";
|
|
1027
1089
|
number_id: string;
|
|
@@ -1033,6 +1095,7 @@ export interface TelephonyInboundBinding {
|
|
|
1033
1095
|
agent_profile_sha256?: string;
|
|
1034
1096
|
admission_mode?: "client" | "platform";
|
|
1035
1097
|
forward?: TelephonyInboundForward | null;
|
|
1098
|
+
ring_group?: TelephonyInboundRingGroup | null;
|
|
1036
1099
|
carrier_operation?: {
|
|
1037
1100
|
id: string;
|
|
1038
1101
|
phase: "pending" | "unknown" | "active" | "rollback_pending" | "rolled_back";
|
|
@@ -1079,6 +1142,7 @@ export type TelephonyInboundBindingUpdate = {
|
|
|
1079
1142
|
admission_mode?: "client" | "platform";
|
|
1080
1143
|
agent_knowledge_receipt?: Record<string, unknown>;
|
|
1081
1144
|
forward?: TelephonyInboundForward | null;
|
|
1145
|
+
ring_group?: TelephonyInboundRingGroup | null;
|
|
1082
1146
|
});
|
|
1083
1147
|
export type TraceVerdict = "PASS" | "WARN" | "FAIL";
|
|
1084
1148
|
export type TraceSeverity = "low" | "medium" | "high" | "critical";
|
|
@@ -1527,7 +1591,7 @@ export declare class PyAI {
|
|
|
1527
1591
|
}>;
|
|
1528
1592
|
};
|
|
1529
1593
|
audio: {
|
|
1530
|
-
/** Text-to-speech. Returns
|
|
1594
|
+
/** Text-to-speech. Returns complete audio bytes (default WAV, stream:false). */
|
|
1531
1595
|
speech: (params: SpeechParams) => Promise<ArrayBuffer>;
|
|
1532
1596
|
/**
|
|
1533
1597
|
* Text-to-speech, streamed. Resolves as soon as the response headers arrive
|
|
@@ -1583,6 +1647,10 @@ export declare class PyAI {
|
|
|
1583
1647
|
filename: string;
|
|
1584
1648
|
call_id?: string;
|
|
1585
1649
|
diarize?: boolean;
|
|
1650
|
+
channel?: boolean;
|
|
1651
|
+
transcription_language?: string;
|
|
1652
|
+
output_script?: "original" | "latin";
|
|
1653
|
+
webhook_url?: string;
|
|
1586
1654
|
output_formats?: Array<"json" | "srt" | "vtt">;
|
|
1587
1655
|
}, opts: {
|
|
1588
1656
|
idempotencyKey: string;
|
|
@@ -1620,6 +1688,22 @@ export declare class PyAI {
|
|
|
1620
1688
|
};
|
|
1621
1689
|
telephony: {
|
|
1622
1690
|
/** Server-side methods. Keep the PyAI key in your backend. */
|
|
1691
|
+
desktopEndpoints: {
|
|
1692
|
+
list: (input?: {
|
|
1693
|
+
number_id?: string;
|
|
1694
|
+
}) => Promise<ListResponse<TelephonyDesktopEndpoint>>;
|
|
1695
|
+
create: (input: {
|
|
1696
|
+
number_id: string;
|
|
1697
|
+
user_id: string;
|
|
1698
|
+
client_reference: string;
|
|
1699
|
+
label: string;
|
|
1700
|
+
}) => Promise<TelephonyDesktopEndpoint>;
|
|
1701
|
+
enroll: (id: string, input: {
|
|
1702
|
+
user_id: string;
|
|
1703
|
+
}, options: {
|
|
1704
|
+
idempotencyKey: string;
|
|
1705
|
+
}) => Promise<TelephonyDesktopEnrollment>;
|
|
1706
|
+
};
|
|
1623
1707
|
calls: {
|
|
1624
1708
|
create: (input: TelephonyCallCreate, options: {
|
|
1625
1709
|
idempotencyKey: string;
|
|
@@ -1700,6 +1784,7 @@ export declare class PyAI {
|
|
|
1700
1784
|
}) => Promise<TelephonyNumber | TelephonyNumberOrder>;
|
|
1701
1785
|
/** Route a number to an agent (`agentId: null` to unassign). */
|
|
1702
1786
|
assign: (id: string, agentId: string | null) => Promise<TelephonyNumber>;
|
|
1787
|
+
getInboundCapabilities: (id: string) => Promise<TelephonyInboundCapabilities>;
|
|
1703
1788
|
getInboundBinding: (id: string) => Promise<TelephonyInboundBinding>;
|
|
1704
1789
|
/** Save the profile and stable operation first; after uncertainty read the
|
|
1705
1790
|
* binding before explicitly recovering that same operation. */
|
package/dist/index.js
CHANGED
|
@@ -1029,13 +1029,13 @@ export class PyAI {
|
|
|
1029
1029
|
};
|
|
1030
1030
|
// --- audio --------------------------------------------------------------
|
|
1031
1031
|
audio = {
|
|
1032
|
-
/** Text-to-speech. Returns
|
|
1032
|
+
/** Text-to-speech. Returns complete audio bytes (default WAV, stream:false). */
|
|
1033
1033
|
speech: async (params) => {
|
|
1034
1034
|
assertActiveSpeechParams(params);
|
|
1035
1035
|
const res = await this.request("/v1/audio/speech", {
|
|
1036
1036
|
method: "POST",
|
|
1037
1037
|
headers: this.authHeaders({ "Content-Type": "application/json" }),
|
|
1038
|
-
body: JSON.stringify({ model: "pyai-speak", ...params }),
|
|
1038
|
+
body: JSON.stringify({ model: "pyai-speak", ...params, stream: params.stream ?? false }),
|
|
1039
1039
|
});
|
|
1040
1040
|
await validateSpeechResponse(res, params);
|
|
1041
1041
|
return res.arrayBuffer();
|
|
@@ -1123,6 +1123,14 @@ export class PyAI {
|
|
|
1123
1123
|
form.set("call_id", params.call_id);
|
|
1124
1124
|
if (params.diarize !== undefined)
|
|
1125
1125
|
form.set("diarize", String(params.diarize));
|
|
1126
|
+
if (params.channel !== undefined)
|
|
1127
|
+
form.set("channel", String(params.channel));
|
|
1128
|
+
if (params.transcription_language)
|
|
1129
|
+
form.set("transcription_language", params.transcription_language);
|
|
1130
|
+
if (params.output_script)
|
|
1131
|
+
form.set("output_script", params.output_script);
|
|
1132
|
+
if (params.webhook_url)
|
|
1133
|
+
form.set("webhook_url", params.webhook_url);
|
|
1126
1134
|
if (params.output_formats)
|
|
1127
1135
|
form.set("output_formats", params.output_formats.join(","));
|
|
1128
1136
|
form.set("audio", params.file, params.filename);
|
|
@@ -1180,6 +1188,11 @@ export class PyAI {
|
|
|
1180
1188
|
// --- telephony (managed numbers) ---------------------------------------
|
|
1181
1189
|
telephony = {
|
|
1182
1190
|
/** Server-side methods. Keep the PyAI key in your backend. */
|
|
1191
|
+
desktopEndpoints: {
|
|
1192
|
+
list: (input = {}) => this.getJson('/v1/telephony/desktop-endpoints' + (input.number_id ? '?' + new URLSearchParams({ number_id: input.number_id }) : '')),
|
|
1193
|
+
create: (input) => this.postJson('/v1/telephony/desktop-endpoints', input),
|
|
1194
|
+
enroll: (id, input, options) => this.postJson(`/v1/telephony/desktop-endpoints/${encodeURIComponent(id)}/enrollment`, input, telephonyIdempotencyHeader(options.idempotencyKey)),
|
|
1195
|
+
},
|
|
1183
1196
|
calls: {
|
|
1184
1197
|
create: (input, options) => this.postJson("/v1/telephony/calls", input, telephonyIdempotencyHeader(options.idempotencyKey)),
|
|
1185
1198
|
get: (id) => this.getJson(`/v1/telephony/calls/${encodeURIComponent(id)}`),
|
|
@@ -1241,6 +1254,7 @@ export class PyAI {
|
|
|
1241
1254
|
buy: (params, options) => this.postJson("/v1/telephony/numbers", params, telephonyIdempotencyHeader(options.idempotencyKey)),
|
|
1242
1255
|
/** Route a number to an agent (`agentId: null` to unassign). */
|
|
1243
1256
|
assign: (id, agentId) => this.postJson(`/v1/telephony/numbers/${encodeURIComponent(id)}/assign`, { agent_id: agentId }),
|
|
1257
|
+
getInboundCapabilities: (id) => this.getJson(`/v1/telephony/numbers/${encodeURIComponent(id)}/inbound-capabilities`),
|
|
1244
1258
|
getInboundBinding: (id) => this.getJson(`/v1/telephony/numbers/${encodeURIComponent(id)}/inbound-binding`),
|
|
1245
1259
|
/** Save the profile and stable operation first; after uncertainty read the
|
|
1246
1260
|
* binding before explicitly recovering that same operation. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pyai/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "Official TypeScript/JavaScript SDK for PyAI, speech-to-text (Hear), text-to-speech (Speak), realtime voice agents (Omni), and call compliance (Trace).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
package/src/cli-dx.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
const sdkVersion: string = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
4
|
+
|
|
1
5
|
/** Offline discovery and copyable workflows; recipes never execute commands. */
|
|
2
6
|
export const aliases: Record<string, string> = Object.assign(Object.create(null), {
|
|
3
7
|
login: "auth login", logout: "auth logout", whoami: "auth status", use: "profiles use",
|
|
@@ -35,5 +39,5 @@ export const recipes: Recipe[] = [
|
|
|
35
39
|
notes: ["Local schema and recipes work without credentials. Live OpenAPI needs a network connection but no API key.", "The CLI manages Agent profiles; use the SDK or WebSocket API for a live Omni audio session."] },
|
|
36
40
|
{ name: "ci", title: "Use PyAI in a build", description: "Check access and produce an audio artifact with machine-readable output.",
|
|
37
41
|
commands: ["pyai whoami --json", 'pyai speak "Your build is ready" -o build.wav --json', "pyai doctor --json"],
|
|
38
|
-
notes: ["Set PYAI_API_KEY through the CI secret store; do not put it in source or shell arguments.", "doctor synthesizes and transcribes a sample, which consumes usage. Use whoami for an authentication-only check.",
|
|
42
|
+
notes: ["Set PYAI_API_KEY through the CI secret store; do not put it in source or shell arguments.", "doctor synthesizes and transcribes a sample, which consumes usage. Use whoami for an authentication-only check.", `Install the CLI with npm install -g @pyai/sdk@${sdkVersion} and pin that version in repeatable builds.`] },
|
|
39
43
|
].map(recipe => ({ ...recipe, docs_url: "https://pyai.com/agents/speech-calling.md" }));
|
package/src/cli-init.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { constants, type Stats } from "node:fs";
|
|
1
|
+
import { constants, readFileSync, type Stats } from "node:fs";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import { basename, dirname, isAbsolute, join, parse, resolve } from "node:path";
|
|
4
4
|
|
|
@@ -32,6 +32,8 @@ export class CliInitError extends Error {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
const sdkVersion: string = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
36
|
+
|
|
35
37
|
const context = `# Build with PyAI
|
|
36
38
|
|
|
37
39
|
This file is a project-local API integration guide for engineers and coding agents.
|
|
@@ -151,7 +153,7 @@ const install = `## Install the CLI
|
|
|
151
153
|
Install the published CLI with Node.js 22 or newer recommended:
|
|
152
154
|
|
|
153
155
|
\`\`\`bash
|
|
154
|
-
npm install -g @pyai/sdk
|
|
156
|
+
npm install -g @pyai/sdk@${sdkVersion}
|
|
155
157
|
pyai --version
|
|
156
158
|
\`\`\`
|
|
157
159
|
|
|
@@ -244,7 +246,7 @@ and product calls below are separate explicit steps. Read \`PYAI.md\` first.
|
|
|
244
246
|
Install the official SDK:
|
|
245
247
|
|
|
246
248
|
\`\`\`bash
|
|
247
|
-
npm install @pyai/sdk
|
|
249
|
+
npm install @pyai/sdk@${sdkVersion}
|
|
248
250
|
cp .env.example .env
|
|
249
251
|
\`\`\`
|
|
250
252
|
|
package/src/cli-omni-template.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated by scripts/generate-omni-starter.mjs; edit examples/omni-starter instead.
|
|
2
2
|
export const omniTemplate = Object.freeze({
|
|
3
|
-
"README.md": "# Runnable Omni starter\n\nRequires Node 20.19+ and ESM. Node 20 uses the included `ws` transport;\nNode 22 also works. The separate MCP server requires Node 22+.\nThis server-side example uses a synthetic read-only office-hours tool. Read\n`PYAI.md` when generating the project through the CLI.\n\n<!-- omni-install:start -->\n```sh\nnpm install @pyai/sdk@0.
|
|
4
|
-
"package.json": "{\n \"name\": \"pyai-omni-starter\",\n \"version\": \"0.0.0\",\n \"private\": true,\n \"type\": \"module\",\n \"engines\": {\n \"node\": \">=20.19.0\"\n },\n \"scripts\": {\n \"start\": \"node main.mjs\"\n },\n \"dependencies\": {\n \"@pyai/sdk\": \"0.
|
|
3
|
+
"README.md": "# Runnable Omni starter\n\nRequires Node 20.19+ and ESM. Node 20 uses the included `ws` transport;\nNode 22 also works. The separate MCP server requires Node 22+.\nThis server-side example uses a synthetic read-only office-hours tool. Read\n`PYAI.md` when generating the project through the CLI.\n\n<!-- omni-install:start -->\n```sh\nnpm install @pyai/sdk@0.18.1\nnpx pyai init voice-demo --template omni\ncd voice-demo\nnpm install\n```\n\nInitialization is offline; installing dependencies and running `main.mjs` are\nseparate steps. For an existing checkout of this example, run `npm install`\nin its directory instead.\n<!-- omni-install:end -->\n\nInject `PYAI_API_KEY` through your secret manager or shell environment. Do not\npaste a real key into source, a prompt, or shell history. `.env.example` documents\nthe variable; this program does not load `.env` or saved CLI profiles.\n\nPrepare a 24 kHz PCM16 mono WAV, at most 20 seconds, saying “Please look up the\noffice opening time.” Then run:\n\n```sh\nnode main.mjs caller.wav\n```\n\nRunning the program explicitly opens one bounded Omni session and uploads its\ncaptured reply to Hear. Both consume your key's allowed usage. Automatic retries\nare disabled. No managed number is bought and no phone call is placed.\n\n`session.mjs` waits for configuration and the greeting to drain, sends exactly\none paced input stream (caller PCM or silence), returns the read tool's result,\nand captures output using the rate from `hello.audio_out`. Never run a separate\nsilence timer alongside caller audio. `timing.mjs` is generated from the existing\nOmni evaluation harness's timing utilities.\n\nThe new private `omni-run-*` folder contains `session.wav`, `reply.wav`, and\n`report.json`. The report separates received audio, an office-hours answer\nrecovered by Hear from captured audio, and physical playback (not tested).\nThe office-hours check accepts formatting such as `opens@9a.m`, `9 a.m.` and\n`nine in the morning` in a complete affirmative opening-time sentence. Wrong\ntimes, negation, conflicting or truncated text remain unverified. This is a\nconservative check for the example fact, not a general answer-quality score.\nA synthesis transcript is advisory; it is not evidence that speech arrived.\nThis starter does not negotiate playback receipts. Capture ends after the\nsimulated queue drains and two seconds of quiet, a bounded capture heuristic.\nListen to the saved file when qualifying actual sound quality or completeness.\n\nTo exercise interruption, supply a second WAV saying “Stop speaking now”:\n\n```sh\nnode main.mjs caller.wav interruption.wav\n```\n\nThe second clip starts while reply audio is queued. `onBargeIn` clears that\nsimulated queue, and capture observes at least five seconds after that clip ends.\nAn interrupted answer can correctly fail the full-answer check;\ninspect the separate interruption evidence. This is not a physical speaker test.\nFor a real playback adapter, cancel both queued and currently playing audio.\nReplace the example lookup with authorized application data before product use.\n\nOn a session error, the program exits with JSON containing a recognized machine\n`code` (for example `media_dead` or `invalid_configure`). Unknown server codes\nbecome `unrecognized_server_error`; transport or decoding errors without a\nrecognized transport code become `transport_or_protocol_error`. Raw error text,\ncall IDs and unknown code values are omitted. No automatic retry is attempted;\ninspect the code and your authorized diagnostics before deciding to retry.\n",
|
|
4
|
+
"package.json": "{\n \"name\": \"pyai-omni-starter\",\n \"version\": \"0.0.0\",\n \"private\": true,\n \"type\": \"module\",\n \"engines\": {\n \"node\": \">=20.19.0\"\n },\n \"scripts\": {\n \"start\": \"node main.mjs\"\n },\n \"dependencies\": {\n \"@pyai/sdk\": \"0.18.1\",\n \"ws\": \"^8.18.3\"\n }\n}\n",
|
|
5
5
|
"timing.mjs": "// Monotonic capture timing. Arrival time is distinct from queued playback:\n// a single packet may contain seconds of audio and must finish before settling.\nexport const FRAME_MS = 20;\nexport const REALTIME_GAP_LIMIT_MS = 100;\n// Interruption tests need an observation window after caller transmission,\n// even when an earlier cue/response already finished. These are test bounds,\n// not an inferred engine reply-end or a naturalness threshold.\nexport const INTERRUPTION_OBSERVATION = Object.freeze({\n minimumAfterCallerStreamMs: 5000, quietMs: 2000, maximumAfterCallerStreamMs: 25000,\n});\n\n/** Approximate audible bounds; this is energy detection, not a speech/VAD claim. */\nexport function audibleBounds(pcm, rate, rmsFloor = 160) {\n const window = Math.max(1, Math.round(rate / 100)); // 10 ms windows\n let first = null;\n let last = null;\n for (let off = 0; off < pcm.length; off += window) {\n const end = Math.min(pcm.length, off + window);\n let energy = 0;\n for (let i = off; i < end; i++) energy += pcm[i] * pcm[i];\n if (Math.sqrt(energy / (end - off)) >= rmsFloor) {\n first ??= off;\n last = end;\n }\n }\n return { first, last };\n}\n\nexport function newAudioCapture(started) {\n return {\n started, firstPacketAt: null, lastPacketAt: null,\n firstAudioAt: null, lastAudioAt: null, playbackEndAt: null,\n samples: 0, pcm: [], turnBeginAt: null, eouMs: null,\n latestTurnBeginAt: null, postTurnBeginFirstPacketAt: null,\n postTurnBeginFirstAudioAt: null, lastAssistantTranscriptAt: null, lastCallerTranscriptAt: null,\n callerTranscriptEvents: [], assistantTranscriptEvents: [],\n turnBegins: [], unheardCancellations: [], unheardSupersededTurns: [], tools: [], toolResults: [], kb: null, events: [],\n };\n}\n\nexport function recordTurnBegin(ctx, at, turn, origin = 0) {\n const prior = ctx.turnBegins.at(-1);\n const cancellation = ctx.unheardCancellations.at(-1);\n if (prior && cancellation && !cancellation.admitted\n && cancellation.turn === prior.turn && cancellation.turnBeginIndex === ctx.turnBegins.length - 1\n && Number.isSafeInteger(turn) && turn > prior.turn && at > cancellation.at\n && ctx.samples === 0 && ctx.assistantTranscriptEvents.length === 0\n && ctx.tools.length === 0 && ctx.toolResults.length === 0) {\n cancellation.admitted = true;\n ctx.unheardSupersededTurns.push({ turn: prior.turn, beginAtMs: prior.atMs,\n cancelledAtMs: cancellation.atMs, cancellationEventIndex: cancellation.eventIndex,\n replacementTurn: turn, outputPacketsBeforeReplacement: 0 });\n }\n ctx.turnBeginAt ??= at;\n ctx.latestTurnBeginAt = at;\n // Earlier PCM can be a listening cue. A new reply is still pending even\n // when that cue has already finished playing; retain all of its PCM.\n ctx.postTurnBeginFirstPacketAt = null;\n ctx.postTurnBeginFirstAudioAt = null;\n ctx.turnBegins.push({ atMs: Math.round(at - origin), turn: turn ?? null });\n}\n\nexport function recordUnheardCancellation(ctx, event, at, origin, eventIndex) {\n const prior = ctx.turnBegins.at(-1);\n if (event.event !== \"flush\" || event.reason !== \"turn_merge\"\n || !Number.isSafeInteger(event.cancelled_turn) || event.cancelled_turn <= 0\n || prior?.turn !== event.cancelled_turn || at < ctx.latestTurnBeginAt\n || ctx.samples !== 0 || ctx.assistantTranscriptEvents.length\n || ctx.tools.length || ctx.toolResults.length\n || ctx.unheardCancellations.some(c => c.turnBeginIndex === ctx.turnBegins.length - 1)) return;\n ctx.unheardCancellations.push({ turn: event.cancelled_turn, at,\n atMs: Math.round(at - origin), eventIndex, turnBeginIndex: ctx.turnBegins.length - 1,\n admitted: false });\n}\n\nexport function recordAudio(ctx, pcm, at, rate) {\n if (!(pcm instanceof Int16Array) || !pcm.length) return null;\n const copy = pcm.slice(); // Some transports reuse callback buffers.\n const playbackAt = Math.max(at, ctx.playbackEndAt ?? at);\n const endAt = playbackAt + (copy.length / rate) * 1000;\n const bounds = audibleBounds(copy, rate);\n ctx.firstPacketAt ??= at;\n ctx.lastPacketAt = at;\n ctx.playbackEndAt = endAt;\n const afterTurnBegin = ctx.latestTurnBeginAt != null && at >= ctx.latestTurnBeginAt;\n if (afterTurnBegin) ctx.postTurnBeginFirstPacketAt ??= at;\n if (bounds.first != null) {\n ctx.firstAudioAt ??= playbackAt + (bounds.first / rate) * 1000;\n ctx.lastAudioAt = playbackAt + (bounds.last / rate) * 1000;\n if (afterTurnBegin) ctx.postTurnBeginFirstAudioAt ??= playbackAt + (bounds.first / rate) * 1000;\n }\n ctx.samples += copy.length;\n ctx.pcm.push(copy);\n return { playbackAt, endAt, pcm: copy };\n}\n\n/** Preserve negative gaps: they are overlaps, never missing measurements. */\nexport function captureTiming(ctx, caller, origin = 0) {\n const relative = (at) => at == null ? null : Math.round(at - origin);\n const gap = (at) => at == null || caller.speechOffsetAt == null\n ? null : Math.round(at - caller.speechOffsetAt);\n return {\n ttfbMs: gap(ctx.firstAudioAt),\n anyAudioTtfbMs: gap(ctx.firstAudioAt),\n postTurnBeginTtfbMs: gap(ctx.postTurnBeginFirstAudioAt),\n turnMs: gap(ctx.lastAudioAt),\n packetTtfbMs: gap(ctx.firstPacketAt),\n callerStartMs: relative(caller.startedAt),\n callerSpeechOnsetMs: relative(caller.speechOnsetAt),\n callerSpeechOffsetMs: relative(caller.speechOffsetAt),\n callerStreamEndMs: relative(caller.streamEndAt),\n agentFirstPacketMs: relative(ctx.firstPacketAt),\n agentLastPacketMs: relative(ctx.lastPacketAt),\n agentSpeechOnsetMs: relative(ctx.firstAudioAt),\n agentSpeechOffsetMs: relative(ctx.lastAudioAt),\n agentPlaybackEndMs: relative(ctx.playbackEndAt),\n latestTurnBeginMs: relative(ctx.latestTurnBeginAt),\n postTurnBeginFirstPacketMs: relative(ctx.postTurnBeginFirstPacketAt),\n postTurnBeginSpeechOnsetMs: relative(ctx.postTurnBeginFirstAudioAt),\n lastAssistantTranscriptMs: relative(ctx.lastAssistantTranscriptAt),\n callerMaxFrameGapMs: Math.round(caller.maxFrameGapMs ?? 0),\n method: \"client-monotonic-queued-playback-energy-bounds\",\n };\n}\n\nexport async function streamPcmRealtime(omni, pcm, rate, clock, onFrame = () => {}) {\n const frameSize = Math.max(1, Math.round((rate * FRAME_MS) / 1000));\n const bounds = audibleBounds(pcm, rate);\n const startedAt = clock.now();\n let speechOnsetAt = null;\n let speechOffsetAt = null;\n let previousFrameEnd = startedAt;\n let maxFrameGapMs = 0;\n for (let off = 0; off < pcm.length; off += frameSize) {\n const frame = pcm.subarray(off, Math.min(off + frameSize, pcm.length));\n const at = clock.now();\n maxFrameGapMs = Math.max(maxFrameGapMs, at - previousFrameEnd);\n const durationMs = (frame.length / rate) * 1000;\n omni.sendAudio(frame);\n onFrame(frame, at);\n if (bounds.first != null && bounds.first >= off && bounds.first < off + frame.length) {\n speechOnsetAt = at + ((bounds.first - off) / rate) * 1000;\n }\n if (bounds.last != null && bounds.last > off && bounds.last <= off + frame.length) {\n speechOffsetAt = at + ((bounds.last - off) / rate) * 1000;\n }\n previousFrameEnd = at + durationMs;\n // Pace from the actual send. Never burst late frames to \"catch up\".\n await clock.sleep(Math.max(0, previousFrameEnd - clock.now()));\n }\n return { startedAt, speechOnsetAt, speechOffsetAt,\n streamEndAt: clock.now(), maxFrameGapMs };\n}\n\nexport async function streamSilenceWhile(omni, rate, shouldContinue, clock, onFrame = () => {}) {\n const silence = new Int16Array(Math.max(1, Math.round((rate * FRAME_MS) / 1000)));\n while (shouldContinue()) {\n const at = clock.now();\n omni.sendAudio(silence);\n onFrame(silence, at);\n await clock.sleep(FRAME_MS);\n }\n}\n\nexport async function waitForAgentSettle(getCtx, clock, opts = {}) {\n const started = clock.now();\n const observation = opts.callerStreamEndAt != null;\n if (observation && (!Number.isFinite(opts.callerStreamEndAt)\n || opts.callerStreamEndAt < 0 || opts.callerStreamEndAt > started)) {\n throw new Error(\"Invalid caller observation boundary\");\n }\n const timeoutMs = observation ? INTERRUPTION_OBSERVATION.maximumAfterCallerStreamMs : opts.timeoutMs ?? 25000;\n const settleMs = observation ? INTERRUPTION_OBSERVATION.quietMs : opts.settleMs ?? 2000;\n const deadlineAt = (observation ? opts.callerStreamEndAt : started) + timeoutMs;\n const minimumAt = observation ? opts.callerStreamEndAt + INTERRUPTION_OBSERVATION.minimumAfterCallerStreamMs : -Infinity;\n while (true) {\n const ctx = getCtx();\n const at = clock.now();\n if (opts.isClosed?.()) return { reason: \"closed\", at };\n if (observation && at >= deadlineAt) return { reason: \"timeout\", at };\n const hasResponseAudio = !opts.requireTurnBegin || (ctx.latestTurnBeginAt != null\n && ctx.postTurnBeginFirstAudioAt != null);\n // Synthesis text is progress, not a completion event. It can arrive after\n // early/final audio, so extend the quiet floor without demanding another\n // packet after every advisory. The protocol still has no reply-end marker.\n const activityEnd = Math.max(ctx.playbackEndAt ?? -Infinity,\n ctx.latestTurnBeginAt ?? -Infinity, ctx.lastAssistantTranscriptAt ?? -Infinity,\n observation ? ctx.lastCallerTranscriptAt ?? -Infinity : -Infinity);\n // Do not demand a new post-caller turn_begin: an earlier turn can be\n // coalesced and speak later. This records a bounded quiet observation;\n // downstream response-timing checks can impose a stricter begin boundary.\n if (ctx.firstPacketAt != null && hasResponseAudio && at >= minimumAt && at >= activityEnd + settleMs) {\n return { reason: \"settled\", at };\n }\n if (opts.allowEmpty && ctx.firstPacketAt == null && at >= minimumAt && at - started >= (opts.emptyWaitMs ?? 800)) {\n return { reason: \"empty\", at };\n }\n if (at - started >= timeoutMs) return { reason: \"timeout\", at };\n await clock.sleep(observation ? Math.min(20, deadlineAt - at) : 20);\n }\n}\n\nexport async function withTimeout(promise, ms, message, clock) {\n let timer;\n try {\n return await Promise.race([\n promise,\n new Promise((_, reject) => {\n timer = clock.setTimeout(() => reject(new Error(message)), ms);\n }),\n ]);\n } finally {\n clock.clearTimeout(timer);\n }\n}\n",
|
|
6
6
|
"main.mjs": "import PyAI from \"@pyai/sdk\";\nimport WebSocket from \"ws\"; // Explicit transport makes this work on Node 20 too.\nimport { readFile, writeFile, mkdtemp } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { runSession } from \"./session.mjs\";\nimport { readWav, writeWav, assessAnswer } from \"./audio.mjs\";\n\nasync function main() {\n const [callerPath, interruptionPath, extra] = process.argv.slice(2);\n if (!callerPath || extra) throw new Error(\"Usage: node main.mjs caller.wav [interruption.wav]\");\n if (!process.env.PYAI_API_KEY) throw new Error(\"Inject PYAI_API_KEY through your environment first\");\n const caller = readWav(await readFile(callerPath));\n const interruption = interruptionPath ? readWav(await readFile(interruptionPath)) : undefined;\n const pyai = new PyAI({ apiKey: process.env.PYAI_API_KEY, maxRetries: 0,\n fetch: (url, options) => fetch(url, { ...options, signal: AbortSignal.timeout(30000) }),\n });\n const { report, audio, replyAudio } = await runSession({ pyai, webSocket: WebSocket, caller, interruption });\n const directory = await mkdtemp(join(process.cwd(), \"omni-run-\"));\n const save = (name, data) => writeFile(join(directory, name), data, { mode: 0o600, flag: \"wx\" });\n await save(\"session.wav\", writeWav(audio, report.output_rate ?? 24000));\n const reply = writeWav(replyAudio, report.output_rate ?? 24000);\n await save(\"reply.wav\", reply);\n // Hear the captured bytes, rather than trusting synthesis-advisory text.\n let capturedTranscript = \"\";\n if (report.reply_audio_bytes) {\n try {\n const heard = await pyai.audio.transcriptions.create({ file: new File([reply], \"reply.wav\", { type: \"audio/wav\" }), model: \"pyai-hear\" });\n capturedTranscript = heard.text;\n } catch { report.hear_error = \"Captured audio saved; Hear verification failed\"; }\n }\n const result = { ...report, captured_transcript: capturedTranscript, evidence: assessAnswer(report, capturedTranscript) };\n await save(\"report.json\", JSON.stringify(result, null, 2) + \"\\n\");\n console.log(JSON.stringify({ directory, ...result }, null, 2));\n if (result.evidence.captured_answer !== \"verified_by_hear\" || (interruption && result.evidence.interruption !== \"simulated_queue_cleared\")) process.exitCode = 1;\n}\n\nmain().catch(error => {\n const message = String(error.message).replaceAll(process.env.PYAI_API_KEY || \"\\0\", \"[REDACTED]\");\n console.error(JSON.stringify({ error: message, ...(error.omni_code ? { code: error.omni_code } : {}) })); process.exitCode = 1;\n});\n",
|
|
7
7
|
"session.mjs": "import { newAudioCapture, recordAudio, recordTurnBegin, streamPcmRealtime, INTERRUPTION_OBSERVATION } from \"./timing.mjs\";\n\nexport const realClock = {\n now: () => performance.now(),\n sleep: ms => new Promise(resolve => setTimeout(resolve, ms)),\n};\n\n// Only recognized machine codes may leave the example. Error messages, call\n// IDs and arbitrary code values can contain credentials or customer content.\nconst publicErrorCodes = new Set([\n \"invalid_configure\", \"unsupported_tool_transport\", \"tool_configuration_locked\",\n \"media_dead\", \"unauthorized\", \"insufficient_scope\", \"rate_limit_exceeded\",\n \"concurrency_limit_exceeded\", \"daily_cap_exceeded\", \"credit_exhausted\",\n]);\nconst transportErrorCodes = new Set([\"ECONNRESET\", \"ECONNREFUSED\", \"ETIMEDOUT\", \"ENOTFOUND\", \"EAI_AGAIN\"]);\nexport function omniFailure(error) {\n const code = error instanceof Error\n ? (transportErrorCodes.has(error.code) ? error.code : \"transport_or_protocol_error\")\n : (publicErrorCodes.has(error?.code) ? error.code : \"unrecognized_server_error\");\n return Object.assign(new Error(`Omni failed (${code}); no automatic retry was attempted`), { omni_code: code });\n}\n\n/** One bounded, server-side example. Its playback queue is simulated. */\nexport async function runSession({ pyai, webSocket, caller, interruption, clock = realClock, timeoutMs = 60000 }) {\n const rate = 24000, frameSize = 480, silence = new Int16Array(frameSize);\n if (!(caller instanceof Int16Array) || !caller.length || caller.length > rate * 20) throw new Error(\"Provide 1–20 seconds of caller PCM16 at 24 kHz\");\n if (interruption && (!(interruption instanceof Int16Array) || !interruption.length || interruption.length > rate * 20)) throw new Error(\"Invalid interruption PCM\");\n const started = clock.now(), all = newAudioCapture(started), reply = newAudioCapture(started);\n const report = { input_rate: rate, output_rate: null, playback_sink: \"simulated\", tool_calls: 0, tool_executions: 0, duplicate_tool_calls: 0, flushes_after_interruption: 0, cleared_queue_ms: 0, interruption_requested: !!interruption, caller_started_ms: null, interruption_started_ms: null, advisory_transcripts: [], end_reason: \"timeout\" };\n let session, configuredAt = null, closed = false, failure = null, phase = \"greeting\", offset = 0, queueEnd = started, interruptionSent = false, inputEndAt = started;\n const handled = new Set();\n const fail = message => { failure ??= new Error(message); };\n try {\n session = pyai.omni.connect({\n webSocket, rate,\n configure: {\n voice_id: \"stock_amos_en_us\", language: \"en\", greeting: \"Hello. How can I help?\",\n persona: \"When asked about office hours, call lookup_office_hours. Never guess. After the result, say one short sentence giving its opening_time.\",\n tools: [{ name: \"lookup_office_hours\", description: \"Read the synthetic example office opening time.\", side_effect: \"read\", parameters: { type: \"object\", properties: {}, required: [], additionalProperties: false } }],\n },\n onHello: frame => {\n const match = /^pcm16@(8000|24000)$/.exec(frame.audio_out ?? \"\");\n if (!match) return fail(\"Unsupported Omni output format\");\n report.output_rate = Number(match[1]);\n },\n onConfigured: () => { configuredAt ??= clock.now(); },\n onAudio: chunk => {\n if (!report.output_rate) return fail(\"Audio arrived before its output format\");\n const bytes = chunk instanceof ArrayBuffer ? new Uint8Array(chunk) : new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);\n if (bytes.byteLength % 2) return fail(\"Invalid PCM16 output\");\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n const pcm = Int16Array.from({ length: bytes.length / 2 }, (_, i) => view.getInt16(i * 2, true));\n const now = clock.now();\n recordAudio(all, pcm, now, report.output_rate);\n queueEnd = Math.max(now, queueEnd) + pcm.length / report.output_rate * 1000;\n if (report.tool_executions) recordAudio(reply, pcm, now, report.output_rate);\n },\n onEvent: frame => {\n if (frame.event === \"turn_begin\") recordTurnBegin(all, clock.now(), frame.turn);\n },\n onTranscript: frame => {\n // An assistant advisory is progress; never treat it as received speech.\n if (report.advisory_transcripts.length < 100) report.advisory_transcripts.push({ role: frame.role, text: frame.text });\n if (frame.role === \"assistant\") all.lastAssistantTranscriptAt = clock.now();\n },\n onToolCall: frame => {\n report.tool_calls++;\n if (handled.has(frame.call_id)) { report.duplicate_tool_calls++; return; }\n handled.add(frame.call_id);\n if (frame.name !== \"lookup_office_hours\") { session.toolResult(frame.call_id, { error: \"Unknown example tool\" }); return; }\n // Replace this read-only fixture with your authorized data lookup.\n report.tool_executions++;\n session.toolResult(frame.call_id, { result: { opening_time: \"9 a.m.\", source: \"synthetic example office\" } });\n },\n onBargeIn: () => {\n const now = clock.now(), queued = Math.max(0, queueEnd - now);\n if (report.interruption_started_ms != null) { report.flushes_after_interruption++; report.cleared_queue_ms += queued; }\n // A real speaker adapter must cancel scheduled and currently playing audio.\n queueEnd = now; all.playbackEndAt = now; reply.playbackEndAt = now;\n },\n onError: error => { failure ??= omniFailure(error); },\n onClose: () => { closed = true; },\n });\n while (clock.now() - started < timeoutMs) {\n if (failure) throw failure;\n if (closed) { report.end_reason = \"closed\"; break; }\n const now = clock.now();\n if (configuredAt == null || !report.output_rate) {\n if (now - started >= 10000) throw new Error(\"Omni connection/configuration timed out\");\n await clock.sleep(20); continue;\n }\n const quietAt = Math.max(queueEnd, all.lastPacketAt ?? now, all.lastAssistantTranscriptAt ?? 0, inputEndAt);\n if (phase === \"greeting\") {\n if (all.firstPacketAt != null && now - configuredAt >= 2000 && now >= quietAt + 800) {\n phase = \"caller\"; report.caller_started_ms = now - started;\n } else if (now - configuredAt > 15000) throw new Error(\"Greeting did not drain within 15 seconds\");\n }\n if (phase === \"reply\" && interruption && !interruptionSent && reply.samples && queueEnd - now >= 200) {\n phase = \"interruption\"; offset = 0; interruptionSent = true; report.interruption_started_ms = now - started;\n }\n const observationEnd = inputEndAt + (interruptionSent ? INTERRUPTION_OBSERVATION.minimumAfterCallerStreamMs : 0);\n if (phase === \"reply\" && reply.samples && now >= quietAt + 2000 && now >= observationEnd && (!interruption || interruptionSent)) {\n report.end_reason = \"quiet_window\"; break;\n }\n // Exactly one producer: each 20 ms slot contains caller PCM OR silence.\n let pcm = silence;\n if (phase === \"caller\" || phase === \"interruption\") {\n const source = phase === \"caller\" ? caller : interruption;\n pcm = source.subarray(offset, offset + frameSize); offset += pcm.length;\n if (offset >= source.length) {\n inputEndAt = now + pcm.length / rate * 1000;\n report[phase === \"caller\" ? \"caller_completed_ms\" : \"interruption_completed_ms\"] = inputEndAt - started;\n phase = \"reply\"; offset = 0;\n }\n }\n await streamPcmRealtime(session, pcm, rate, clock);\n }\n report.audio_bytes = all.samples * 2;\n report.reply_audio_bytes = reply.samples * 2;\n report.elapsed_ms = Math.round(clock.now() - started);\n return { report, audio: all.pcm, replyAudio: reply.pcm };\n } finally { session?.close(); }\n}\n",
|
package/src/cli.ts
CHANGED
|
@@ -46,7 +46,7 @@ const commands: Command[] = [
|
|
|
46
46
|
{ command: "init", description: "Create a new project with API context and request examples offline", args: ["directory"], flags: { template: "string" }, example: "pyai init voice-demo --template typescript" },
|
|
47
47
|
{ command: "smoke", description: "Check models, voices, and speech synthesis", flags: { "tolerate-upstream": "boolean" } },
|
|
48
48
|
{ command: "doctor", description: "Diagnose key, catalogs, and a Speak to Hear round-trip" },
|
|
49
|
-
{ command: "dialer", description: "Open the private desktop calling and meeting-recording app", flags: { port: "string", "no-browser": "boolean", name: "string", "white-label": "boolean", transfers: "boolean" }, example: "pyai dialer --profile production" },
|
|
49
|
+
{ command: "dialer", description: "Open the private desktop calling and meeting-recording app", flags: { port: "string", "no-browser": "boolean", name: "string", "white-label": "boolean", transfers: "boolean", receive: "boolean" }, example: "pyai dialer --profile production" },
|
|
50
50
|
...routes.map((r): Command => ({ command: r.command, description: r.description, args: r.id ? ["id"] : [], flags: {
|
|
51
51
|
...(r.body ? bodyFlags : {}), ...(r.binary ? outputFlags : {}), ...(r.wait ? waitFlags : {}),
|
|
52
52
|
...(r.query ?? {}), ...(r.confirm ? { confirm: "boolean" as const } : {}),
|
|
@@ -331,18 +331,19 @@ async function main(): Promise<void> {
|
|
|
331
331
|
}
|
|
332
332
|
const sandbox = cmd === "auth sandbox";
|
|
333
333
|
const sandboxProfile = sandbox ? validateProfileName(value(flags, "profile") ?? process.env.PYAI_PROFILE ?? "sandbox") : undefined;
|
|
334
|
-
const config = await resolveConfig({ apiKey: value(flags, "api-key"), baseURL: value(flags, "base-url"), profile: sandboxProfile ?? value(flags, "profile"), allowMissingProfile: sandbox });
|
|
334
|
+
const config = cmd === "dialer" && flags.receive === true ? { baseURL: value(flags,"base-url") ?? "https://api.pyai.com", apiKey: undefined, profile: "receive" } : await resolveConfig({ apiKey: value(flags, "api-key"), baseURL: value(flags, "base-url"), profile: sandboxProfile ?? value(flags, "profile"), allowMissingProfile: sandbox });
|
|
335
335
|
if (config.apiKey) secrets.add(config.apiKey);
|
|
336
336
|
const retries = number(flags, "retries", 2, 0, 5); if (!Number.isInteger(retries)) usage("--retries must be an integer");
|
|
337
337
|
const http = new CliHttp({ baseURL: config.baseURL, apiKey: config.apiKey, timeoutMs: number(flags, "timeout", 30, 0.001) * 1000, maxRetries: retries });
|
|
338
338
|
if (cmd === "dialer") {
|
|
339
339
|
const port = number(flags, "port", 43117, 0, 65535); if (!Number.isInteger(port)) usage("--port must be an integer");
|
|
340
340
|
if (flags["dry-run"]) { output({ dry_run: true, command: cmd, bind: "127.0.0.1", port, browser: !flags["no-browser"], calls: "Only after a foreground Call or Start calling action; no number is dialed at startup" }, flags); return; }
|
|
341
|
-
|
|
341
|
+
const receiveOnly=flags.receive===true;
|
|
342
|
+
if (!receiveOnly&&!config.apiKey) throw new CliError("authentication_required", "Run pyai login or use pyai dialer --receive for incoming calls.", 3);
|
|
342
343
|
const { startDialerApp } = await import("./dialer/appServer.ts");
|
|
343
|
-
const fingerprint = createHash("sha256").update(config.baseURL).update("\0").update(config.apiKey).digest("hex");
|
|
344
|
-
const sdk = new PyAI({ apiKey: config.apiKey
|
|
345
|
-
const app = await startDialerApp({ sdk, userId: `desktop_${fingerprint.slice(0,40)}`, scope: `desktop:${fingerprint}`, port, name: value(flags, "name"), whiteLabel: flags["white-label"] === true, allowTransfers: flags.transfers === true });
|
|
344
|
+
const fingerprint = createHash("sha256").update(config.baseURL).update("\0").update(config.apiKey ?? "receive-only").digest("hex");
|
|
345
|
+
const sdk = receiveOnly ? undefined : new PyAI({ apiKey: config.apiKey!, baseURL: config.baseURL, fetch: (url, init) => fetch(url, { ...init, redirect: "error", signal: init?.signal ?? AbortSignal.timeout(15000) }) });
|
|
346
|
+
const app = await startDialerApp({ sdk, receiveOnly, incomingApiOrigin: config.baseURL, userId: `desktop_${fingerprint.slice(0,40)}`, scope: `desktop:${fingerprint}`, port, name: value(flags, "name"), whiteLabel: flags["white-label"] === true, allowTransfers: flags.transfers === true });
|
|
346
347
|
output({ url: app.url, local_only: true }, flags, `PyAI Phone is ready at ${app.url}\nKeep this window open. Press Ctrl+C to stop the app and end its owned calls.`);
|
|
347
348
|
if (flags["no-browser"] || !(await openBrowser(app.launchUrl))) process.stderr.write(`Private one-use launch link (valid for 60 seconds): ${app.launchUrl}\n`);
|
|
348
349
|
await new Promise<void>(resolve => {
|
|
@@ -380,8 +381,9 @@ async function main(): Promise<void> {
|
|
|
380
381
|
const sampleRate = value(flags, "sample-rate") === undefined ? undefined : number(flags, "sample-rate", 24000, 8000, 48000);
|
|
381
382
|
if (sampleRate !== undefined && !(SPEECH_SAMPLE_RATES as readonly number[]).includes(sampleRate)) usage(`--sample-rate must be one of ${SPEECH_SAMPLE_RATES.join(", ")}`);
|
|
382
383
|
if (format.startsWith("g711_") && sampleRate !== undefined && sampleRate !== 8000) usage("G.711 audio requires --sample-rate 8000");
|
|
383
|
-
const payload = { input: text, model: value(flags, "model") ?? "pyai-speak", voice: value(flags, "voice"), response_format: format, sample_rate: sampleRate };
|
|
384
384
|
const path = value(flags, "out") ?? `pyai-speak.${format.startsWith("g711_") ? "raw" : format}`;
|
|
385
|
+
// Files need finalized container headers; stdout remains an incremental stream.
|
|
386
|
+
const payload = { input: text, model: value(flags, "model") ?? "pyai-speak", voice: value(flags, "voice"), response_format: format, sample_rate: sampleRate, stream: path === "-" };
|
|
385
387
|
await checkOutput(path, flags);
|
|
386
388
|
if (preview(flags, config.baseURL, "POST", "/v1/audio/speech", payload)) return;
|
|
387
389
|
await writeAudio(await http.request("POST", "/v1/audio/speech", { json: payload }), path, flags); return;
|
package/src/dialer/app/app.css
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
:root{font:13px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#282936;background:#f3f4f8;--accent:#5c4de4;--line:#e9eaf0}*{box-sizing:border-box}html{min-height:100%;background:radial-gradient(ellipse at 50% 0,#eae7fa,transparent 55%),#f3f4f8}body{margin:28px auto;display:flex;flex-direction:column;width:min(460px,calc(100% - 32px));max-height:calc(100dvh - 56px);min-height:0;background:#fff;border:1px solid #e3e4ec;border-radius:23px;box-shadow:0 18px 60px #25234412,0 2px 8px #25234406;overflow:hidden}aside{padding:17px 18px 12px;display:flex;flex-wrap:wrap;align-items:center;gap:14px;flex-shrink:0;border-bottom:1px solid var(--line);background:#fff}.brand{font-size:15px;font-weight:700;display:flex;align-items:center;gap:9px;color:inherit;text-decoration:none;letter-spacing:-.45px}.logo{display:grid;place-items:center;border-radius:10px;width:29px;height:29px;color:#fff;background:var(--accent);font-size:25px;line-height:1;box-shadow:0 3px 8px #5c4de422}.aside-foot{margin-left:auto;display:flex;align-items:center;gap:5px;font-size:0;color:#9295a5}.aside-foot:after{content:"On this device";font-size:10px}.aside-foot small,.aside-foot br{display:none}.online{width:5px;height:5px;border-radius:50%;background:#b7b8c5}nav{display:flex;gap:3px;width:100%;padding:3px;background:#f4f4f8;border-radius:11px}button,input,select,textarea{font:inherit}button{cursor:pointer}nav button{flex:1;min-height:34px;padding:7px 9px;border:0;border-radius:8px;background:transparent;font-size:11px;font-weight:600;color:#777b8c;white-space:nowrap}nav button span{display:none}nav button.selected{background:#fff;color:#5044ce;box-shadow:0 1px 4px #24273513}nav[data-single="true"]{display:none}main{padding:17px 18px 15px;width:100%;margin:0;overflow-y:auto;overscroll-behavior:contain}main>header{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-bottom:15px}h1{font-size:17px;font-weight:650;letter-spacing:-.55px;line-height:1.2;margin:0}.subtitle,header .eyebrow{display:none}.local-badge{font-size:9px;font-weight:550;background:#f5f4fc;color:#817b9d;padding:4px 7px;border-radius:6px;white-space:nowrap}.eyebrow{font-size:9px;letter-spacing:1.2px;font-weight:650;color:#8b8b9e;margin:0 0 6px}.calling-grid{display:grid;grid-template-columns:minmax(0,1fr);gap:13px;align-items:start}.calling-grid>div{min-width:0}.source-label,.queue-card label{display:block;font-size:11px;font-weight:600;color:#686f82;margin-bottom:6px}select,input:not([type="checkbox"]):not([type="file"]){width:100%;padding:8px 10px;border:1px solid #e2e4ed;border-radius:9px;background:#fafafd;color:#343a4d;min-height:36px}.recording-choice{display:flex;align-items:center;gap:6px;font-size:10px;color:#7c8293;margin:9px 0 12px}.recording-choice input{accent-color:var(--accent);margin:0}.queue-card{background:#fff;padding:16px;border:1px solid var(--line);border-radius:15px;margin:0}.queue-card h2{font-size:18px;letter-spacing:-.55px;font-weight:650;line-height:1.25;margin:0 0 8px}.queue-card>p{font-size:12px;color:#7b7f91;margin:0 0 15px}.card-top,.quiet-icon{display:none}.queue-card textarea{border:1px solid #e2e4ed;border-radius:10px;background:#fafafd;width:100%;height:86px;resize:vertical;padding:10px;font-size:12px;line-height:1.5;margin-bottom:12px;color:#3a4052}.queue-card textarea::placeholder{color:#a1a5b4}.queue-actions{display:flex;gap:7px;flex-wrap:wrap;margin-top:12px}.queue-actions button,#incoming-send{border:1px solid #e7e8ef;border-radius:9px;background:#f7f7fa;color:#626b7e;padding:8px 11px;min-height:35px;font-size:11px;font-weight:600}.queue-actions button:hover:enabled,#incoming-send:hover:enabled{background:#efedf9}.queue-actions button.primary{background:var(--accent);border-color:var(--accent);color:#fff;box-shadow:0 2px 5px #5c4de41c}.queue-actions button:disabled{opacity:.4;cursor:default;box-shadow:none}#queue-status{font-size:10px;color:#83899b;margin:12px 0 0}.power-queue{padding:0;background:#fafafd}.power-queue>summary{display:flex;align-items:center;gap:10px;cursor:pointer;list-style:none;padding:13px 14px}.power-queue>summary::-webkit-details-marker{display:none}.queue-mark{width:29px;height:29px;border:1px solid #e5e1fa;border-radius:9px;background:#eeebfc;color:#7463d9;display:grid;place-items:center;font-size:17px}.power-queue summary strong{display:block;font-size:12px;font-weight:650;color:#49445f}.power-queue summary small{display:block;font-size:10px;color:#9090a1;margin-top:1px}.queue-chevron{margin-left:auto;color:#9997ab}.power-queue[open] .queue-chevron{transform:rotate(180deg)}.queue-content{border-top:1px solid var(--line);padding:14px;background:#fff;border-radius:0 0 15px 15px}.queue-content>p{font-size:11px;color:#7b7f91;margin:0 0 14px}.incoming-card{padding:17px;border-color:#e9e6f2;background:linear-gradient(180deg,#fcfbff,#fff)}.receiver-hero{text-align:center;padding:3px 0 17px}.receiver-icon{width:45px;height:45px;border:1px solid #e5dff9;background:#eee9fc;color:#7761db;display:grid;place-items:center;border-radius:15px;margin:0 auto 12px}.receiver-hero h2{font-size:20px;letter-spacing:-.65px;margin-bottom:7px}.receiver-hero p{font-size:12px;line-height:1.5;color:#838397;max-width:270px;margin:0 auto}.incoming-card #incoming-handoff{height:76px;min-height:60px;font-size:11px}.incoming-card input[type="file"]{font-size:10px;color:#9394a4;width:100%;margin:0 0 4px}.incoming-card input[type="file"]::file-selector-button{font:600 10px system-ui;border:1px solid #e3e2eb;border-radius:7px;color:#6b657f;background:#fff;padding:7px 9px;margin-right:8px;cursor:pointer}.pairing-fields .queue-actions button{width:100%}#incoming-enroll{background:var(--accent);color:#fff;border-color:var(--accent)}#incoming-binding{font-size:11px;font-weight:600;color:#57516f;text-align:center;overflow-wrap:anywhere;margin:13px 0 7px}#incoming-binding:empty{display:none}#incoming-status{display:flex;align-items:center;justify-content:center;gap:6px;background:#f3f3f8;border:1px solid #e9e8ef;border-radius:8px;padding:9px 10px;font-size:11px;color:#818193;margin:12px 0}#incoming-status:before{content:"";width:6px;height:6px;flex-shrink:0;background:#b8b7c7;border-radius:50%}#incoming-status[data-phase="ready"]{background:#eff8f3;border-color:#dceddf;color:#3e7b5b}#incoming-status[data-phase="ready"]:before{background:#60a57e}.receiver-controls{justify-content:center}.receiver-controls button{flex:1}.receiver-note{font-size:10px!important;line-height:1.55!important;color:#9593a5!important;text-align:center;margin:13px 0 0!important}.incoming-card:has(#incoming-status[data-phase]:not([data-phase="offline"])) .pairing-fields{display:none}.incoming-card:has(#incoming-status[data-phase="offline"]) .receiver-controls{display:none}#incoming-call{padding:14px;margin-top:12px;background:#fff;border:1px solid #e6e2f4;border-radius:11px;text-align:center}#incoming-caller{font-size:18px;font-weight:600;letter-spacing:-.4px}#incoming-call .queue-actions{justify-content:center}#incoming-call button:disabled{display:none}#incoming-answer{background:#248865;border-color:#248865;color:white}#incoming-end{background:#fceef0;color:#b74458;border-color:#f5dce1}#incoming-call label{margin-top:15px;text-align:left}#incoming-digits{margin-bottom:8px}#incoming-call:has(#incoming-answer:enabled) label,#incoming-call:has(#incoming-answer:enabled) #incoming-digits,#incoming-call:has(#incoming-answer:enabled) #incoming-send{display:none}.meeting-grid{display:grid;grid-template-columns:minmax(0,1fr);gap:13px}.meeting-copy{display:none}pyai-dialer,pyai-meeting-recorder,pyai-meeting-intelligence{display:block;width:100%;max-width:none}footer{font-size:9px;line-height:1.55;color:#a0a3b0;margin-top:15px;padding-top:12px;border-top:1px solid #f0f0f5}#error{color:#b54b5c;font-size:11px;min-height:0;margin:0}#error:not(:empty){padding:9px 11px;background:#fdf1f3;border:1px solid #f7dfe4;border-radius:8px;margin:0 0 12px}#retry{font-size:11px;padding:7px 10px;margin:0 0 12px;border:1px solid #e3e1ee;border-radius:8px;color:#625c79;background:#f6f5fa}button:focus-visible,select:focus-visible,textarea:focus-visible,input:focus-visible,summary:focus-visible{outline:3px solid #bcb4fa;outline-offset:2px}[hidden]{display:none!important}@media(max-width:520px){html{background:#fff}body{width:100%;margin:0;border:0;border-radius:0;box-shadow:none;max-height:100dvh;min-height:100dvh}aside{padding:16px 17px 11px}main{padding:15px 17px;flex:1}}
|
|
3
|
+
|
|
4
|
+
.local-badge{display:none}body[data-receive-only="true"] footer{display:none}
|
|
5
|
+
|
|
6
|
+
body[data-layout="comfortable"]{width:min(680px,calc(100% - 32px))}nav button.selected{color:var(--accent)}.logo{color:var(--accent-ink,#fff);overflow:hidden}.logo img{display:block;width:100%;height:100%;object-fit:contain;background:#fff}.queue-actions button.primary,#incoming-enroll{color:var(--accent-ink,#fff)}.appearance-toggle{margin-left:auto;width:29px;height:29px;border:1px solid var(--line);border-radius:9px;background:#fafafd;color:#7a778c;font-size:16px;display:grid;place-items:center}.appearance-settings{border:1px solid var(--line);border-radius:13px;padding:14px;margin-bottom:15px;background:#fafafd}.settings-heading{display:flex;align-items:center;justify-content:space-between}.settings-heading h2{font-size:15px;margin:0}.settings-heading button{border:0;background:transparent;color:#858392;font-size:21px}.appearance-settings p,.connection-help{font-size:11px;line-height:1.6;color:#7d8091}.appearance-settings label{display:block;font-size:11px;font-weight:550;margin:11px 0 5px}.settings-row{display:grid;grid-template-columns:1fr 2fr;gap:12px}.appearance-settings input[type="color"]{padding:3px;width:100%;height:36px}.appearance-settings input[type="file"]{font-size:11px;width:100%}.appearance-settings small{display:block;font-size:10px;color:#8b8d9d;margin:6px 0;line-height:1.55}.appearance-settings .settings-check,.appearance-settings fieldset label{display:flex;align-items:center;gap:7px;font-weight:400}.appearance-settings fieldset{border:1px solid var(--line);border-radius:9px;margin:14px 0 9px;padding:6px 10px 10px;display:grid;grid-template-columns:1fr 1fr}.appearance-settings legend{font-size:11px;font-weight:600;color:#696e80}.appearance-settings fieldset label{margin:5px 0;font-size:11px}.appearance-settings input[type="checkbox"]{accent-color:var(--accent)}#appearance-clear-logo{margin-top:5px;border:0;background:transparent;color:#777287;font-size:10px;padding:2px 0}.connection-help{padding:10px 12px;background:#f7f7fb;border:1px solid var(--line);border-radius:9px}#appearance-result:empty{display:none}@media(max-width:520px){body[data-layout="comfortable"]{width:100%}}
|
package/src/dialer/app/app.html
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="theme-color" content="#5b55e7"><title>PyAI Phone</title><link rel="icon" href="/icon.svg"><link rel="manifest" href="/manifest.webmanifest"><link rel="stylesheet" href="/app.css"><script type="module" src="/app.js"></script></head><body>
|
|
2
|
-
<aside><a class="brand" href="/" aria-label="PyAI Phone"><span class="logo">p</span> <span data-brand>PyAI Phone</span></a><nav aria-label="Workspace"><button class="selected" data-tab="calls">Phone <span>↗</span></button><button data-tab="meetings">Meeting recorder <span>◉</span></button></nav><div class="aside-foot"><span class="online"></span> Private workspace<br><small>Powered by PyAI</small></div></aside>
|
|
2
|
+
<aside><a class="brand" href="/" aria-label="PyAI Phone"><span class="logo">p</span> <span data-brand>PyAI Phone</span></a><button id="appearance-toggle" class="appearance-toggle" aria-label="Customize app" aria-expanded="false" title="Customize app">⚙</button><nav aria-label="Workspace"><button class="selected" data-tab="calls">Phone <span>↗</span></button><button data-tab="incoming">Receive calls <span>↓</span></button><button data-tab="meetings">Meeting recorder <span>◉</span></button></nav><div class="aside-foot"><span class="online"></span> Private workspace<br><small>Powered by PyAI</small></div></aside>
|
|
3
3
|
<main><header><div><p class="eyebrow">YOUR CONVERSATIONS, TOGETHER</p><h1 data-heading>Make the next connection.</h1><p class="subtitle" data-subtitle>A clear line. A little less busywork.</p></div><span class="local-badge">On this device</span></header>
|
|
4
|
-
<div id="error" role="alert"></div><button id="retry" hidden>Retry connection</button><section data-panel="calls"><div class="calling-grid"><div><label class="source-label" for="source">Calling from</label><select id="source" disabled><option>Loading workspace numbers…</option></select><label class="recording-choice"><input id="record-calls" type="checkbox">Record calls · tell the other person before recording</label><label class="recording-choice" id="transfer-choice" hidden><input id="allow-transfers" type="checkbox">Allow transfers · single-line calls</label><pyai-dialer></pyai-dialer></div>
|
|
5
|
-
<
|
|
6
|
-
<section data-panel="meetings" hidden><div class="meeting-grid"><div class="meeting-copy"><span class="eyebrow">LESS DISTRACTION, MORE PRESENCE</span><h2>Stay in the<br>conversation.</h2><p>Choose the audio you want to keep. Record your meeting and microphone together, pause when you need to, and save a private audio file. When you choose, send it for a transcript, notes and action items.</p><div class="feature"><b>◉</b><span><strong>Your choice of audio</strong>Choose a supported meeting tab or system source in the browser picker.</span></div><div class="feature"><b>▦</b><span><strong>Saved as you go</strong>Committed audio can be recovered after an interrupted tab.</span></div><div class="feature"><b>↧</b><span><strong>Yours to keep</strong>Download your recording. No automatic uploads or hidden capture.</span></div></div><pyai-meeting-recorder></pyai-meeting-recorder><pyai-meeting-intelligence></pyai-meeting-intelligence></div></section>
|
|
4
|
+
<section id="appearance-settings" class="appearance-settings" hidden aria-label="App appearance"><div class="settings-heading"><h2>Make it yours</h2><button id="appearance-close" aria-label="Close appearance">×</button></div><p id="appearance-context">Changes preview on this device. Connect a workspace to save them.</p><form id="appearance-form"><label for="appearance-name">App name</label><input id="appearance-name" maxlength="60" required><div class="settings-row"><div><label for="appearance-color">Main color</label><input id="appearance-color" type="color"></div><div><label for="appearance-layout">Layout</label><select id="appearance-layout"><option value="compact">Compact</option><option value="comfortable">Roomier</option></select></div></div><label for="appearance-logo">Your logo</label><input id="appearance-logo" type="file" accept="image/png,.png"><small>PNG, up to 8 KB and 512 × 512 pixels.</small><button type="button" id="appearance-clear-logo">Use initials instead</button><label class="settings-check"><input id="appearance-white-label" type="checkbox">Use my brand only</label><fieldset><legend>App sections</legend><label><input type="checkbox" data-appearance-feature="calls">Phone</label><label><input type="checkbox" data-appearance-feature="incoming">Incoming calls</label><label><input type="checkbox" data-appearance-feature="meetings">Meetings</label><label><input type="checkbox" data-appearance-feature="power_queue">Power queue</label></fieldset><small>These choices change visibility. Workspace permissions still apply, and active work stays accessible.</small><div class="queue-actions"><button id="appearance-save" class="primary" type="submit">Apply preview</button></div><p id="appearance-result" role="status" aria-live="polite"></p></form></section><div id="error" role="alert"></div><p id="connection-help" class="connection-help" hidden></p><p id="sections-hidden" class="connection-help" hidden>All app sections are hidden. Bring them back in Customize.</p><button id="retry" hidden>Retry connection</button><section data-panel="calls"><div class="calling-grid"><div><label class="source-label" for="source">Calling from</label><select id="source" disabled><option>Loading workspace numbers…</option></select><label class="recording-choice"><input id="record-calls" type="checkbox">Record calls · tell the other person before recording</label><label class="recording-choice" id="transfer-choice" hidden><input id="allow-transfers" type="checkbox">Allow transfers · single-line calls</label><pyai-dialer compact></pyai-dialer></div>
|
|
5
|
+
<details class="queue-card power-queue"><summary><span class="queue-mark" aria-hidden="true">≋</span><span><strong>Power queue</strong><small>Contacts, priority & parallel lines</small></span><span class="queue-chevron" aria-hidden="true">⌄</span></summary><div class="queue-content"><div class="card-top"><span class="eyebrow">STAY IN YOUR FLOW</span><span class="quiet-icon">≋</span></div><p>Add a list and work through it at your own pace. Each call waits for your wrap-up.</p><label for="contacts">Phone numbers, one per line</label><textarea id="contacts" placeholder="+61 2 5550 0100 +1 415 555 0100" spellcheck="false"></textarea><label for="mode">Calling order</label><select id="mode"><option value="auto">In list order</option><option value="dynamic">Highest priority first · number, priority</option><option value="parallel">Parallel lines · first answer connects</option></select><div id="parallel-choice" hidden><label for="parallel-lines">Parallel lines</label><select id="parallel-lines"><option value="2">2 lines</option><option value="3">3 lines</option><option value="4">4 lines</option></select></div><div class="queue-actions"><button id="queue-start" class="primary" disabled>Start calling</button><button id="queue-pause" disabled>Pause queue</button><button id="queue-resume" disabled>Resume queue</button><button id="queue-clear" disabled>Clear queue</button></div><p id="queue-status" role="status" aria-live="polite">You choose when to start. Your workspace calling rules apply to every call.</p></div></details></div></section>
|
|
6
|
+
<section data-panel="incoming" hidden><div class="queue-card incoming-card"><div class="receiver-hero"><span class="receiver-icon" aria-hidden="true"><svg width="23" height="23" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2c0 8.8 7.2 16 16 16a2 2 0 0 0 2-2v-3l-5-2-2 2a13 13 0 0 1-6-6l2-2-2-5Z"/><path d="M15 3v5m0 0 3-3m-3 3-3-3"/></svg></span><h2>Your desk. Your calls.</h2><p>Connect your workspace and answer calls right here.</p></div><div class="pairing-fields"><label for="incoming-handoff">Workspace connection</label><textarea id="incoming-handoff" autocomplete="off" spellcheck="false" placeholder="Paste your workspace connection"></textarea><input id="incoming-file" type="file" accept="application/json,.json"><div class="queue-actions"><button id="incoming-enroll">Connect workspace</button></div></div><div class="queue-actions receiver-controls"><button id="incoming-enable" class="primary" disabled>Enable incoming calls</button><button id="incoming-logout" disabled>Disconnect receiver</button></div><p id="incoming-binding"></p><p id="incoming-status" data-phase="offline" role="status" aria-live="polite">Incoming calls are off.</p><div id="incoming-call" hidden><strong id="incoming-caller"></strong><div class="queue-actions"><button id="incoming-answer" class="primary">Answer</button><button id="incoming-reject">Decline</button><button id="incoming-end">End call</button><button id="incoming-mute">Mute</button></div><label for="incoming-digits">Keypad</label><input id="incoming-digits" inputmode="tel" maxlength="32"><button id="incoming-send">Send digits</button></div><p class="receiver-note">Keep this window open to receive calls.<br>Your microphone starts only when you answer.</p></div></section><section data-panel="meetings" hidden><div class="meeting-grid"><div class="meeting-copy"><span class="eyebrow">LESS DISTRACTION, MORE PRESENCE</span><h2>Stay in the<br>conversation.</h2><p>Choose the audio you want to keep. Record your meeting and microphone together, pause when you need to, and save a private audio file. When you choose, send it for a transcript, notes and action items.</p><div class="feature"><b>◉</b><span><strong>Your choice of audio</strong>Choose a supported meeting tab or system source in the browser picker.</span></div><div class="feature"><b>▦</b><span><strong>Saved as you go</strong>Committed audio can be recovered after an interrupted tab.</span></div><div class="feature"><b>↧</b><span><strong>Yours to keep</strong>Download your recording. No automatic uploads or hidden capture.</span></div></div><pyai-meeting-recorder></pyai-meeting-recorder><pyai-meeting-intelligence></pyai-meeting-intelligence></div></section>
|
|
7
7
|
<footer>Call history and call recordings are stored in your PyAI workspace. Meeting audio stays in this browser until you save or submit it.</footer></main></body></html>
|