@voicelayer/sdk 0.6.2 → 0.7.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/dist/brain/index.d.ts +2 -2
- package/dist/brain/index.js +226 -9
- package/dist/index.d.ts +259 -254
- package/dist/index.js +1643 -491
- package/dist/runtime/text-session.d.ts +1 -1
- package/dist/runtime/text-session.js +1214 -183
- package/dist/{text-session-B-T33y5P.d.ts → text-session-BI5A-gxI.d.ts} +132 -110
- package/package.json +2 -2
package/dist/brain/index.d.ts
CHANGED
|
@@ -81,14 +81,14 @@ declare const ConnectorUpFrame: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
|
|
|
81
81
|
code: z.ZodEnum<["upstream_timeout", "upstream_error", "bad_response", "normalize_failed", "unreachable"]>;
|
|
82
82
|
message: z.ZodString;
|
|
83
83
|
}, "strip", z.ZodTypeAny, {
|
|
84
|
+
kind: "brain.error";
|
|
84
85
|
code: "upstream_timeout" | "upstream_error" | "bad_response" | "normalize_failed" | "unreachable";
|
|
85
86
|
message: string;
|
|
86
|
-
kind: "brain.error";
|
|
87
87
|
streamId: string;
|
|
88
88
|
}, {
|
|
89
|
+
kind: "brain.error";
|
|
89
90
|
code: "upstream_timeout" | "upstream_error" | "bad_response" | "normalize_failed" | "unreachable";
|
|
90
91
|
message: string;
|
|
91
|
-
kind: "brain.error";
|
|
92
92
|
streamId: string;
|
|
93
93
|
}>]>;
|
|
94
94
|
type ConnectorUpFrame = z.infer<typeof ConnectorUpFrame>;
|
package/dist/brain/index.js
CHANGED
|
@@ -1209,11 +1209,10 @@ var AgentConfig = z.object({
|
|
|
1209
1209
|
projectId: z.string().min(1),
|
|
1210
1210
|
// Human-readable label. No `agentType` enum on purpose.
|
|
1211
1211
|
name: z.string().min(1).max(128),
|
|
1212
|
-
//
|
|
1213
|
-
//
|
|
1214
|
-
//
|
|
1215
|
-
//
|
|
1216
|
-
// honoured. Per-call override at call_start time is also allowed.
|
|
1212
|
+
// The agent's persona (the Behaviour page). For a FLOW agent the PUBLISHED value is the flow persona on every
|
|
1213
|
+
// transport (flowPersonaOf — voice boot and text replies alike; absent → DEFAULT_FLOW_PERSONA), read at call start as
|
|
1214
|
+
// a snapshot decision; mid-call edits are not honoured (burn-down G-46). A coded SDK agent's prompt is its code: this
|
|
1215
|
+
// field doesn't reach it. A call plan may still override the prompt per call.
|
|
1217
1216
|
systemPrompt: z.string().max(64e3).optional(),
|
|
1218
1217
|
// Routing/decision layer (Voiceflow "Instructions"): plain-language guidance the
|
|
1219
1218
|
// agent reads to decide WHEN to do things (vs systemPrompt = WHO it is). Injected
|
|
@@ -2004,7 +2003,134 @@ z.object({
|
|
|
2004
2003
|
toolCalls: z.array(ToolCallAudit),
|
|
2005
2004
|
mcpInteractions: z.array(McpInteractionAudit)
|
|
2006
2005
|
});
|
|
2007
|
-
var
|
|
2006
|
+
var BUDGET_SCOPE_KINDS = ["workspace", "agent", "api_key", "channel"];
|
|
2007
|
+
var BudgetScopeKind = z.enum(BUDGET_SCOPE_KINDS);
|
|
2008
|
+
var CREATABLE_BUDGET_SCOPE_KINDS = ["workspace", "api_key", "channel"];
|
|
2009
|
+
var BUDGET_CHANNELS = ["voice", "sms", "email", "chat", "discord"];
|
|
2010
|
+
z.enum(BUDGET_CHANNELS);
|
|
2011
|
+
var BudgetScope = z.object({
|
|
2012
|
+
kind: BudgetScopeKind,
|
|
2013
|
+
// null for the workspace; the API key's id, or the channel name.
|
|
2014
|
+
id: z.string().min(1).nullable()
|
|
2015
|
+
});
|
|
2016
|
+
var BudgetPeriodKind = z.enum(["day", "month", "billing_period"]);
|
|
2017
|
+
var BudgetEnforcement = z.enum(["soft", "hard"]);
|
|
2018
|
+
var BudgetInbound = z.enum(["refuse", "answer"]);
|
|
2019
|
+
var BudgetOwner = z.enum(["customer", "operator"]);
|
|
2020
|
+
var DEFAULT_BUDGET_THRESHOLDS = [50, 80, 100];
|
|
2021
|
+
var BUDGET_MAX_USD = 1e6;
|
|
2022
|
+
var Thresholds = z.array(z.number().int().min(1).max(100)).max(5).refine((t) => new Set(t).size === t.length, "thresholds must be distinct").transform((t) => [...t].sort((a, b) => a - b));
|
|
2023
|
+
var IANA_NAME = /^[A-Za-z]+(?:\/[A-Za-z0-9_+-]+)+$/;
|
|
2024
|
+
var SUPPORTED_ZONES = null;
|
|
2025
|
+
function supportedZones() {
|
|
2026
|
+
if (!SUPPORTED_ZONES) {
|
|
2027
|
+
const intl = Intl;
|
|
2028
|
+
SUPPORTED_ZONES = new Set(intl.supportedValuesOf?.("timeZone") ?? []);
|
|
2029
|
+
}
|
|
2030
|
+
return SUPPORTED_ZONES;
|
|
2031
|
+
}
|
|
2032
|
+
function isIanaTimezone(tz) {
|
|
2033
|
+
if (tz === "UTC" || supportedZones().has(tz)) return true;
|
|
2034
|
+
if (!IANA_NAME.test(tz)) return false;
|
|
2035
|
+
try {
|
|
2036
|
+
new Intl.DateTimeFormat("en-US", { timeZone: tz });
|
|
2037
|
+
return true;
|
|
2038
|
+
} catch {
|
|
2039
|
+
return false;
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
var Timezone = z.string().min(1).max(64).refine(isIanaTimezone, "use an IANA time zone name, like America/New_York or UTC");
|
|
2043
|
+
var BudgetPeriodStatus = z.object({
|
|
2044
|
+
periodStart: z.string(),
|
|
2045
|
+
// When the budget resets.
|
|
2046
|
+
periodEnd: z.string(),
|
|
2047
|
+
// Charged usage this period.
|
|
2048
|
+
settledUsd: z.string(),
|
|
2049
|
+
// Reserved for calls in progress.
|
|
2050
|
+
inProgressUsd: z.string(),
|
|
2051
|
+
// settled + in progress — what the budget compares with its amount.
|
|
2052
|
+
spentUsd: z.string(),
|
|
2053
|
+
// spent ÷ amount, as a whole percent (may pass 100: calls in progress finish).
|
|
2054
|
+
percent: z.number().int().min(0),
|
|
2055
|
+
// A hard budget at its limit: new actions in its scope are refused until periodEnd.
|
|
2056
|
+
reached: z.boolean()
|
|
2057
|
+
});
|
|
2058
|
+
var Budget = z.object({
|
|
2059
|
+
id: z.string(),
|
|
2060
|
+
scope: BudgetScope,
|
|
2061
|
+
period: BudgetPeriodKind,
|
|
2062
|
+
timezone: z.string(),
|
|
2063
|
+
amountUsd: z.string(),
|
|
2064
|
+
enforcement: BudgetEnforcement,
|
|
2065
|
+
thresholds: z.array(z.number().int()),
|
|
2066
|
+
notifyEmail: z.boolean(),
|
|
2067
|
+
notifyWebhook: z.boolean(),
|
|
2068
|
+
// Operator budgets are VoiceLayer's own safety limits: shown to the customer, read-only.
|
|
2069
|
+
owner: BudgetOwner,
|
|
2070
|
+
inbound: BudgetInbound,
|
|
2071
|
+
createdAt: z.string(),
|
|
2072
|
+
current: BudgetPeriodStatus
|
|
2073
|
+
});
|
|
2074
|
+
z.object({ budgets: z.array(Budget) });
|
|
2075
|
+
z.object({
|
|
2076
|
+
scope: z.object({ kind: z.enum(CREATABLE_BUDGET_SCOPE_KINDS), id: z.string().min(1).max(200).nullable().optional() }),
|
|
2077
|
+
period: BudgetPeriodKind,
|
|
2078
|
+
timezone: Timezone.default("UTC"),
|
|
2079
|
+
amountUsd: z.number().positive().max(BUDGET_MAX_USD),
|
|
2080
|
+
enforcement: BudgetEnforcement,
|
|
2081
|
+
thresholds: Thresholds.default([...DEFAULT_BUDGET_THRESHOLDS]),
|
|
2082
|
+
notifyEmail: z.boolean().default(true),
|
|
2083
|
+
notifyWebhook: z.boolean().default(true),
|
|
2084
|
+
// Hard budgets only; a customer budget refuses incoming calls unless told to answer them (MON-9).
|
|
2085
|
+
inbound: BudgetInbound.default("refuse")
|
|
2086
|
+
}).superRefine((b, ctx) => {
|
|
2087
|
+
const id = b.scope.id ?? null;
|
|
2088
|
+
if (b.scope.kind === "workspace" && id !== null) ctx.addIssue({ code: "custom", path: ["scope", "id"], message: "a workspace budget names no scope id" });
|
|
2089
|
+
if (b.scope.kind !== "workspace" && id === null) ctx.addIssue({ code: "custom", path: ["scope", "id"], message: "name the API key or channel" });
|
|
2090
|
+
if (b.scope.kind === "channel" && id !== null && !BUDGET_CHANNELS.includes(id)) {
|
|
2091
|
+
ctx.addIssue({ code: "custom", path: ["scope", "id"], message: `channel is one of ${BUDGET_CHANNELS.join(", ")}` });
|
|
2092
|
+
}
|
|
2093
|
+
});
|
|
2094
|
+
z.object({
|
|
2095
|
+
amountUsd: z.number().positive().max(BUDGET_MAX_USD),
|
|
2096
|
+
enforcement: BudgetEnforcement,
|
|
2097
|
+
thresholds: Thresholds,
|
|
2098
|
+
notifyEmail: z.boolean(),
|
|
2099
|
+
notifyWebhook: z.boolean(),
|
|
2100
|
+
inbound: BudgetInbound
|
|
2101
|
+
}).partial().refine((b) => Object.keys(b).length > 0, "nothing to change");
|
|
2102
|
+
var BudgetRefusalDetail = z.object({
|
|
2103
|
+
budgetId: z.string(),
|
|
2104
|
+
scope: BudgetScope,
|
|
2105
|
+
period: BudgetPeriodKind,
|
|
2106
|
+
resetsAt: z.string()
|
|
2107
|
+
});
|
|
2108
|
+
var BillingNoticeKind = z.enum([
|
|
2109
|
+
"balance_empty",
|
|
2110
|
+
"credit_limit_reached",
|
|
2111
|
+
"auto_topup_off",
|
|
2112
|
+
"wallet_frozen",
|
|
2113
|
+
"invoice_issued",
|
|
2114
|
+
"invoice_overdue",
|
|
2115
|
+
"workspace_paused",
|
|
2116
|
+
"workspace_restored",
|
|
2117
|
+
"budget_threshold",
|
|
2118
|
+
"budget_reached"
|
|
2119
|
+
]);
|
|
2120
|
+
var BillingNotice = z.object({
|
|
2121
|
+
id: z.string(),
|
|
2122
|
+
kind: BillingNoticeKind,
|
|
2123
|
+
// The same words as the email's subject and first paragraph.
|
|
2124
|
+
title: z.string(),
|
|
2125
|
+
body: z.string(),
|
|
2126
|
+
// The budget a budget notice is about.
|
|
2127
|
+
budgetId: z.string().nullable(),
|
|
2128
|
+
createdAt: z.string()
|
|
2129
|
+
});
|
|
2130
|
+
z.object({ notices: z.array(BillingNotice) });
|
|
2131
|
+
|
|
2132
|
+
// ../contracts/src/webhook-events.ts
|
|
2133
|
+
var WEBHOOK_EVENT_TYPES = ["call.started", "call.ended", "recording.ready", "billing.budget_threshold", "billing.budget_reached"];
|
|
2008
2134
|
z.enum(WEBHOOK_EVENT_TYPES);
|
|
2009
2135
|
var CallWebhookDirection = z.enum(["inbound", "outbound", "web"]);
|
|
2010
2136
|
var CallWebhookOutcome = z.enum(["completed", "dropped", "failed", "no_answer", "other"]);
|
|
@@ -2063,6 +2189,19 @@ z.object({
|
|
|
2063
2189
|
recordingUrl: z.string().url(),
|
|
2064
2190
|
status: z.enum(["starting", "active", "completed", "failed", "aborted"])
|
|
2065
2191
|
});
|
|
2192
|
+
z.object({
|
|
2193
|
+
budgetId: z.string(),
|
|
2194
|
+
scope: BudgetScope,
|
|
2195
|
+
period: BudgetPeriodKind,
|
|
2196
|
+
periodStart: z.string().datetime({ offset: true }),
|
|
2197
|
+
periodEnd: z.string().datetime({ offset: true }),
|
|
2198
|
+
amountUsd: z.string(),
|
|
2199
|
+
spentUsd: z.string(),
|
|
2200
|
+
inProgressUsd: z.string(),
|
|
2201
|
+
// The threshold passed (budget_reached: 100).
|
|
2202
|
+
thresholdPct: z.number().int().min(1).max(100),
|
|
2203
|
+
enforcement: BudgetEnforcement
|
|
2204
|
+
});
|
|
2066
2205
|
var PhoneNumberStatus = z.enum([
|
|
2067
2206
|
"pending",
|
|
2068
2207
|
"active",
|
|
@@ -2125,6 +2264,10 @@ z.object({
|
|
|
2125
2264
|
})
|
|
2126
2265
|
});
|
|
2127
2266
|
|
|
2267
|
+
// ../contracts/src/flow-ask-lines.ts
|
|
2268
|
+
BigInt("0xcbf29ce484222325");
|
|
2269
|
+
BigInt("0x100000001b3");
|
|
2270
|
+
|
|
2128
2271
|
// ../contracts/src/dispatch-metadata.ts
|
|
2129
2272
|
var IDENTITY_DISPATCH_METADATA_KEYS = [
|
|
2130
2273
|
"projectId",
|
|
@@ -3511,14 +3654,18 @@ var WalletRefusalCode = z.enum([
|
|
|
3511
3654
|
// still answered. Paying the invoice restores the workspace.
|
|
3512
3655
|
"account_suspended",
|
|
3513
3656
|
// The action's reservation already closed (e.g. a call ended or expired) — it cannot be re-admitted.
|
|
3514
|
-
"hold_closed"
|
|
3657
|
+
"hold_closed",
|
|
3658
|
+
// A hard budget (docs/specs/monetization LLD §8a) would be passed: new actions in its scope wait for its reset.
|
|
3659
|
+
"budget_exceeded"
|
|
3515
3660
|
]);
|
|
3516
3661
|
z.object({
|
|
3517
3662
|
error: WalletRefusalCode,
|
|
3518
3663
|
code: WalletRefusalCode,
|
|
3519
3664
|
availableUsd: z.string(),
|
|
3520
3665
|
needUsd: z.string(),
|
|
3521
|
-
message: z.string()
|
|
3666
|
+
message: z.string(),
|
|
3667
|
+
// budget_exceeded only: which budget, and when it resets.
|
|
3668
|
+
budget: BudgetRefusalDetail.optional()
|
|
3522
3669
|
});
|
|
3523
3670
|
var WalletMode = z.enum(["prepaid", "invoiced"]);
|
|
3524
3671
|
z.object({
|
|
@@ -3559,7 +3706,7 @@ var WalletInvoice = z.object({
|
|
|
3559
3706
|
payUrl: z.string().nullable()
|
|
3560
3707
|
});
|
|
3561
3708
|
z.object({ invoices: z.array(WalletInvoice) });
|
|
3562
|
-
var WalletEntryKind = z.enum(["grant", "topup", "usage", "refund", "refund_reversal", "dispute", "dispute_reinstated", "adjustment", "invoice_payment"]);
|
|
3709
|
+
var WalletEntryKind = z.enum(["grant", "topup", "usage", "usage_correction", "refund", "refund_reversal", "dispute", "dispute_reinstated", "adjustment", "invoice_payment"]);
|
|
3563
3710
|
var WalletEntry = z.object({
|
|
3564
3711
|
id: z.string(),
|
|
3565
3712
|
kind: WalletEntryKind,
|
|
@@ -3596,6 +3743,76 @@ z.object({
|
|
|
3596
3743
|
tts: PipelineSlotKey.optional(),
|
|
3597
3744
|
realtime: PipelineSlotKey.optional()
|
|
3598
3745
|
});
|
|
3746
|
+
var METERING_SCHEMA_VERSION = 2;
|
|
3747
|
+
var METER_IDS = [
|
|
3748
|
+
// A model's prompt tokens as the provider counts them (cached ones included); `cached_input_tokens` is the cached
|
|
3749
|
+
// subset and `reasoning_tokens` the reasoning subset of `output_tokens`. Rating prices the totals until it prices the
|
|
3750
|
+
// subsets on their own (monetization MON-14).
|
|
3751
|
+
"llm.input_tokens",
|
|
3752
|
+
"llm.cached_input_tokens",
|
|
3753
|
+
"llm.output_tokens",
|
|
3754
|
+
"llm.reasoning_tokens",
|
|
3755
|
+
"embedding.input_tokens",
|
|
3756
|
+
"realtime.audio_input_tokens",
|
|
3757
|
+
"realtime.audio_output_tokens",
|
|
3758
|
+
"realtime.text_input_tokens",
|
|
3759
|
+
"realtime.cached_input_tokens",
|
|
3760
|
+
"realtime.text_output_tokens",
|
|
3761
|
+
"stt.billed_seconds",
|
|
3762
|
+
"tts.characters",
|
|
3763
|
+
"call.connected_seconds",
|
|
3764
|
+
"telephony.carrier_seconds",
|
|
3765
|
+
"media.participant_seconds",
|
|
3766
|
+
"media.sip_seconds",
|
|
3767
|
+
"recording.seconds",
|
|
3768
|
+
"storage.byte_days",
|
|
3769
|
+
"message.segments",
|
|
3770
|
+
"email.messages",
|
|
3771
|
+
// One per billable text action — a text turn, or a single model action the API takes for a workspace (a QA review,
|
|
3772
|
+
// an evaluation, a planner call, a knowledge ingest): the per-message fee's basis.
|
|
3773
|
+
"text.turns",
|
|
3774
|
+
// Informational: number rental is a recurring fee on charge_cycles (🔒 B-21).
|
|
3775
|
+
"number.held_days",
|
|
3776
|
+
"provider_fee.micros"
|
|
3777
|
+
];
|
|
3778
|
+
var MeterId = z.enum(METER_IDS);
|
|
3779
|
+
var KEY_OWNERS = ["platform", "workspace_key", "workspace_plan", "workspace_brain", "self_hosted"];
|
|
3780
|
+
z.enum(KEY_OWNERS);
|
|
3781
|
+
var READING_SOURCES = ["server_observed", "platform_wire", "platform_estimate", "customer_report"];
|
|
3782
|
+
z.enum(READING_SOURCES);
|
|
3783
|
+
var SUBJECT_KINDS = ["call", "turn", "job", "message", "email", "number"];
|
|
3784
|
+
var SubjectKind = z.enum(SUBJECT_KINDS);
|
|
3785
|
+
var MeteringSubject = z.object({ kind: SubjectKind, id: z.string().min(1).max(200) });
|
|
3786
|
+
var DimValue = z.string().max(200).nullable();
|
|
3787
|
+
var IdentityDims = z.record(z.string(), DimValue);
|
|
3788
|
+
var Attributes = z.object({
|
|
3789
|
+
served_model: z.string().max(200).nullable(),
|
|
3790
|
+
channel: z.string().max(64).nullable(),
|
|
3791
|
+
direction: z.string().max(32).nullable(),
|
|
3792
|
+
leg_kind: z.string().max(64).nullable(),
|
|
3793
|
+
country: z.string().max(8).nullable(),
|
|
3794
|
+
worker_owner: z.enum(["platform", "self_hosted", "unknown"]).nullable()
|
|
3795
|
+
});
|
|
3796
|
+
var SERIES_PATTERN = /^(req|ws|srv):[A-Za-z0-9._:-]{1,60}$/;
|
|
3797
|
+
var SeriesName = z.string().max(64).regex(SERIES_PATTERN);
|
|
3798
|
+
var Quantity = z.string().regex(/^\d{1,14}(\.\d{1,6})?$/);
|
|
3799
|
+
var MeterReadingInput = z.object({
|
|
3800
|
+
schemaVersion: z.literal(METERING_SCHEMA_VERSION),
|
|
3801
|
+
subject: MeteringSubject,
|
|
3802
|
+
meter: MeterId,
|
|
3803
|
+
identity: IdentityDims,
|
|
3804
|
+
series: SeriesName,
|
|
3805
|
+
quantity: Quantity,
|
|
3806
|
+
final: z.boolean(),
|
|
3807
|
+
void: z.literal(true).optional(),
|
|
3808
|
+
// The pre-send input estimate of a request that may never answer (LLD §4.1). A client never names a source: the
|
|
3809
|
+
// server derives it from the principal (§4.4), and this flag is the one thing only the producer knows. Honoured
|
|
3810
|
+
// only from the call's own worker token; it ranks below the request's wire count, which supersedes it.
|
|
3811
|
+
estimate: z.literal(true).optional(),
|
|
3812
|
+
occurredAt: z.string().datetime({ offset: true }),
|
|
3813
|
+
attributes: Attributes.partial().optional()
|
|
3814
|
+
}).strict();
|
|
3815
|
+
z.object({ readings: z.array(MeterReadingInput).min(1).max(200) }).strict();
|
|
3599
3816
|
|
|
3600
3817
|
// src/brain/transport-tunnel.ts
|
|
3601
3818
|
var AsyncQueue = class {
|