@absolutejs/voice 0.0.22-beta.354 → 0.0.22-beta.356

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/audit.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type VoiceAuditEventType = 'handoff' | 'operator.action' | 'provider.call' | 'retention.policy' | 'tool.call';
1
+ export type VoiceAuditEventType = 'handoff' | 'operator.action' | 'profile.switch' | 'provider.call' | 'retention.policy' | 'tool.call';
2
2
  export type VoiceAuditActor = {
3
3
  id: string;
4
4
  kind: 'agent' | 'operator' | 'system' | 'worker';
package/dist/index.d.ts CHANGED
@@ -31,8 +31,8 @@ export { assertVoiceCompetitiveCoverage, buildVoiceCompetitiveCoverageReport, cr
31
31
  export type { VoiceCompetitiveCoverageAssertionInput, VoiceCompetitiveCoverageAssertionReport, VoiceCompetitiveCoverageIssue, VoiceCompetitiveCoverageLevel, VoiceCompetitiveCoverageReport, VoiceCompetitiveCoverageReportInput, VoiceCompetitiveCoverageRoutesOptions, VoiceCompetitiveCoverageStatus, VoiceCompetitiveCoverageSummary, VoiceCompetitiveDepthLevel, VoiceCompetitiveEvidence, VoiceCompetitiveSurface } from './competitiveCoverage';
32
32
  export type { VoicePlatformCoverageAssertionInput, VoicePlatformCoverageAssertionReport, VoicePlatformCoverageEvidence, VoicePlatformCoverageRoutesOptions, VoicePlatformCoverageStatus, VoicePlatformCoverageSummary, VoicePlatformCoverageSummaryInput, VoicePlatformCoverageSurface } from './platformCoverage';
33
33
  export { assertVoiceProofTrendEvidence, buildEmptyVoiceProofTrendReport, buildVoiceProofTrendProfileSummaries, buildVoiceProofTrendRecommendationReport, buildVoiceProofTrendReportFromRealCallProfiles, buildVoiceProofTrendReport, buildVoiceRealCallProfileDefaults, buildVoiceRealCallProfileHistoryReport, createVoiceProofTrendRecommendationRoutes, createVoiceProofTrendRoutes, createVoiceRealCallProfileHistoryRoutes, DEFAULT_VOICE_PROOF_TREND_PROFILE_DEFINITIONS, DEFAULT_VOICE_PROOF_TRENDS_MAX_AGE_MS, evaluateVoiceProofTrendEvidence, formatVoiceProofTrendAge, normalizeVoiceProofTrendReport, readVoiceProofTrendReportFile, renderVoiceProofTrendRecommendationHTML, renderVoiceProofTrendRecommendationMarkdown, renderVoiceRealCallProfileHistoryHTML, renderVoiceRealCallProfileHistoryMarkdown, resolveVoiceRealCallProfileProviderRoute } from './proofTrends';
34
- export { recommendVoiceProfileSwitch } from './profileSwitchRecommendation';
35
- export type { VoiceProfileSwitchObservedSignals, VoiceProfileSwitchRecommendation, VoiceProfileSwitchRecommendationOptions } from './profileSwitchRecommendation';
34
+ export { applyVoiceProfileSwitchGuard, recommendVoiceProfileSwitch } from './profileSwitchRecommendation';
35
+ export type { VoiceProfileSwitchGuardAction, VoiceProfileSwitchGuardDecision, VoiceProfileSwitchGuardMode, VoiceProfileSwitchGuardOptions, VoiceProfileSwitchObservedSignals, VoiceProfileSwitchRecommendation, VoiceProfileSwitchRecommendationOptions } from './profileSwitchRecommendation';
36
36
  export { buildVoiceProviderDecisionTraceReport, createVoiceProviderDecisionTraceEvent, createVoiceProviderDecisionTraceRoutes, listVoiceProviderDecisionTraces, renderVoiceProviderDecisionTraceHTML, renderVoiceProviderDecisionTraceMarkdown } from './providerDecisionTraces';
37
37
  export type { VoiceProviderDecisionStatus, VoiceProviderDecisionSurfaceReport, VoiceProviderDecisionTrace, VoiceProviderDecisionTraceInput, VoiceProviderDecisionTraceIssue, VoiceProviderDecisionTraceReport, VoiceProviderDecisionTraceReportOptions, VoiceProviderDecisionTraceRoutesOptions } from './providerDecisionTraces';
38
38
  export type { VoiceProofTrendAssertionInput, VoiceProofTrendAssertionReport, VoiceProofTrendCycle, VoiceProofTrendProfileDefinition, VoiceProofTrendProfileRecommendation, VoiceProofTrendProfileSummaryOptions, VoiceProofTrendProfileSummary, VoiceProofTrendProviderRecommendation, VoiceProofTrendProviderSummary, VoiceProofTrendRecommendation, VoiceProofTrendRecommendationOptions, VoiceProofTrendRecommendationReport, VoiceProofTrendRecommendationRoutesOptions, VoiceProofTrendRecommendationStatus, VoiceProofTrendRecommendationSurface, VoiceProofTrendRealCallProfileEvidence, VoiceProofTrendRealCallProfileReportOptions, VoiceProofTrendReport, VoiceProofTrendReportInput, VoiceProofTrendRoutesOptions, VoiceProofTrendRuntimeChannelSummary, VoiceProofTrendStatus, VoiceProofTrendSummary, VoiceRealCallProfileDefault, VoiceRealCallProfileDefaultsOptions, VoiceRealCallProfileDefaultsReport, VoiceRealCallProfileHistoryOptions, VoiceRealCallProfileHistoryReport, VoiceRealCallProfileHistoryRoutesOptions, VoiceRealCallProfileProviderRouteOptions } from './proofTrends';
package/dist/index.js CHANGED
@@ -15707,6 +15707,32 @@ var scoreProfile = (profile, observed) => {
15707
15707
  const noisyBonus = (observed.fallbackUsed || (observed.turnWarnings ?? 0) > 0) && /noisy|phone/i.test(`${profile.profileId} ${profile.label ?? ""}`) ? -1000 : 0;
15708
15708
  return live + provider + turn + statusPenalty + noisyBonus;
15709
15709
  };
15710
+ var clampConfidence = (value) => Math.max(0, Math.min(0.99, Number(value.toFixed(2))));
15711
+ var estimateSwitchConfidence = (recommendation) => {
15712
+ if (!recommendation.ok || recommendation.status !== "switch") {
15713
+ return recommendation.status === "stay" && recommendation.ok ? 0.99 : 0;
15714
+ }
15715
+ const observed = recommendation.observed;
15716
+ const currentStatus = recommendation.currentProfile?.status;
15717
+ const recommendedStatus = recommendation.recommendedProfile?.status;
15718
+ let confidence = 0.58;
15719
+ if (currentStatus && currentStatus !== "pass") {
15720
+ confidence += 0.12;
15721
+ }
15722
+ if (recommendedStatus === "pass") {
15723
+ confidence += 0.1;
15724
+ }
15725
+ if (observed.fallbackUsed) {
15726
+ confidence += 0.08;
15727
+ }
15728
+ if ((observed.turnWarnings ?? 0) > 0) {
15729
+ confidence += 0.08;
15730
+ }
15731
+ if (recommendation.reasons.some((reason) => /budget|strongest measured fit/i.test(reason))) {
15732
+ confidence += 0.08;
15733
+ }
15734
+ return clampConfidence(confidence);
15735
+ };
15710
15736
  var recommendVoiceProfileSwitch = (options) => {
15711
15737
  const defaults = readDefaults(options.defaults);
15712
15738
  const observed = options.observed ?? {};
@@ -15760,6 +15786,62 @@ var recommendVoiceProfileSwitch = (options) => {
15760
15786
  status: issues.length > 0 ? "warn" : shouldSwitch ? "switch" : "stay"
15761
15787
  };
15762
15788
  };
15789
+ var applyVoiceProfileSwitchGuard = async (options) => {
15790
+ const mode = options.mode ?? "recommend";
15791
+ const minConfidence = options.minConfidence ?? 0.75;
15792
+ const recommendation = recommendVoiceProfileSwitch(options);
15793
+ const confidence = estimateSwitchConfidence(recommendation);
15794
+ const previousProfileId = recommendation.currentProfile?.profileId;
15795
+ const recommendedProfileId = recommendation.recommendedProfile?.profileId;
15796
+ const canSwitch = recommendation.status === "switch" && recommendation.ok && Boolean(recommendedProfileId) && confidence >= minConfidence;
15797
+ const action = recommendation.status === "stay" ? "stay" : canSwitch ? mode === "auto" ? "switch" : "recommend" : "blocked";
15798
+ const selectedProfileId = action === "switch" ? recommendedProfileId : previousProfileId ?? recommendedProfileId;
15799
+ const reason = action === "switch" ? `Auto-switched from ${previousProfileId ?? "unknown"} to ${recommendedProfileId}.` : action === "recommend" ? `Recommended ${recommendedProfileId} but left selection unchanged because mode is recommend.` : action === "blocked" ? `Blocked profile switch because confidence ${confidence} is below ${minConfidence} or evidence is incomplete.` : "Kept current profile because measured evidence does not require a switch.";
15800
+ const decision = {
15801
+ action,
15802
+ autoApplied: action === "switch",
15803
+ confidence,
15804
+ minConfidence,
15805
+ mode,
15806
+ previousProfileId,
15807
+ reason,
15808
+ recommendation,
15809
+ recommendedProfileId,
15810
+ selectedProfileId
15811
+ };
15812
+ if (options.audit) {
15813
+ const auditEvent = await options.audit.append(createVoiceAuditEvent({
15814
+ action: `profile.switch.${action}`,
15815
+ actor: options.actor ?? {
15816
+ id: "absolutejs-voice-profile-switch-guard",
15817
+ kind: "system",
15818
+ name: "AbsoluteJS Voice Profile Switch Guard"
15819
+ },
15820
+ metadata: options.metadata,
15821
+ outcome: action === "blocked" ? "skipped" : "success",
15822
+ payload: {
15823
+ autoApplied: decision.autoApplied,
15824
+ confidence,
15825
+ minConfidence,
15826
+ mode,
15827
+ previousProfileId,
15828
+ reasons: recommendation.reasons,
15829
+ recommendedProfileId,
15830
+ selectedProfileId,
15831
+ status: recommendation.status
15832
+ },
15833
+ resource: {
15834
+ id: selectedProfileId,
15835
+ type: "voice-profile"
15836
+ },
15837
+ sessionId: options.sessionId,
15838
+ traceId: options.traceId,
15839
+ type: "profile.switch"
15840
+ }));
15841
+ decision.auditEvent = auditEvent;
15842
+ }
15843
+ return decision;
15844
+ };
15763
15845
  // src/providerDecisionTraces.ts
15764
15846
  import { Elysia as Elysia23 } from "elysia";
15765
15847
 
@@ -37846,6 +37928,7 @@ export {
37846
37928
  assertVoiceAgentSquadContractEvidence,
37847
37929
  assertVoiceAgentSquadContract,
37848
37930
  applyVoiceTelephonyOutcome,
37931
+ applyVoiceProfileSwitchGuard,
37849
37932
  applyVoiceOpsTaskPolicy,
37850
37933
  applyVoiceOpsTaskAssignmentRule,
37851
37934
  applyVoiceHandoffDeliveryResult,
@@ -1,4 +1,5 @@
1
1
  import type { VoiceRealCallProfileDefault, VoiceRealCallProfileDefaultsReport, VoiceRealCallProfileHistoryReport } from './proofTrends';
2
+ import { type StoredVoiceAuditEvent, type VoiceAuditActor, type VoiceAuditEventStore } from './audit';
2
3
  export type VoiceProfileSwitchObservedSignals = {
3
4
  currentProfileId?: string;
4
5
  fallbackUsed?: boolean;
@@ -35,4 +36,29 @@ export type VoiceProfileSwitchRecommendationOptions = {
35
36
  minImprovementMs?: number;
36
37
  observed?: VoiceProfileSwitchObservedSignals;
37
38
  };
39
+ export type VoiceProfileSwitchGuardMode = 'auto' | 'recommend';
40
+ export type VoiceProfileSwitchGuardAction = 'blocked' | 'recommend' | 'stay' | 'switch';
41
+ export type VoiceProfileSwitchGuardDecision = {
42
+ action: VoiceProfileSwitchGuardAction;
43
+ auditEvent?: StoredVoiceAuditEvent;
44
+ autoApplied: boolean;
45
+ confidence: number;
46
+ minConfidence: number;
47
+ mode: VoiceProfileSwitchGuardMode;
48
+ previousProfileId?: string;
49
+ reason: string;
50
+ recommendation: VoiceProfileSwitchRecommendation;
51
+ recommendedProfileId?: string;
52
+ selectedProfileId?: string;
53
+ };
54
+ export type VoiceProfileSwitchGuardOptions = VoiceProfileSwitchRecommendationOptions & {
55
+ actor?: VoiceAuditActor;
56
+ audit?: VoiceAuditEventStore;
57
+ metadata?: Record<string, unknown>;
58
+ minConfidence?: number;
59
+ mode?: VoiceProfileSwitchGuardMode;
60
+ sessionId?: string;
61
+ traceId?: string;
62
+ };
38
63
  export declare const recommendVoiceProfileSwitch: (options: VoiceProfileSwitchRecommendationOptions) => VoiceProfileSwitchRecommendation;
64
+ export declare const applyVoiceProfileSwitchGuard: (options: VoiceProfileSwitchGuardOptions) => Promise<VoiceProfileSwitchGuardDecision>;
@@ -0,0 +1,6 @@
1
+ import type { VoiceProfileSwitchRecommendationWidgetOptions } from '../client/profileSwitchRecommendationWidget';
2
+ export type VoiceProfileSwitchRecommendationProps = VoiceProfileSwitchRecommendationWidgetOptions & {
3
+ className?: string;
4
+ path?: string;
5
+ };
6
+ export declare const VoiceProfileSwitchRecommendation: ({ className, path, ...options }: VoiceProfileSwitchRecommendationProps) => import("react/jsx-runtime").JSX.Element;
@@ -4,6 +4,7 @@ export { VoiceDeliveryRuntime } from './VoiceDeliveryRuntime';
4
4
  export { VoicePlatformCoverage } from './VoicePlatformCoverage';
5
5
  export { VoiceProofTrends } from './VoiceProofTrends';
6
6
  export { VoiceProfileComparison } from './VoiceProfileComparison';
7
+ export { VoiceProfileSwitchRecommendation } from './VoiceProfileSwitchRecommendation';
7
8
  export { VoiceReadinessFailures } from './VoiceReadinessFailures';
8
9
  export { VoiceProviderSimulationControls } from './VoiceProviderSimulationControls';
9
10
  export { VoiceProviderCapabilities } from './VoiceProviderCapabilities';
@@ -18,6 +19,7 @@ export { useVoiceOpsStatus } from './useVoiceOpsStatus';
18
19
  export { useVoicePlatformCoverage } from './useVoicePlatformCoverage';
19
20
  export { useVoiceProofTrends } from './useVoiceProofTrends';
20
21
  export { useVoiceProfileComparison } from './useVoiceProfileComparison';
22
+ export { useVoiceProfileSwitchRecommendation } from './useVoiceProfileSwitchRecommendation';
21
23
  export { useVoiceReadinessFailures } from './useVoiceReadinessFailures';
22
24
  export { useVoiceOpsActionCenter } from './useVoiceOpsActionCenter';
23
25
  export { useVoiceLiveOps } from './useVoiceLiveOps';