@absolutejs/voice 0.0.22-beta.491 → 0.0.22-beta.493

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/index.d.ts CHANGED
@@ -86,6 +86,8 @@ export type { VoiceAgentUIInput, VoiceAgentUIState, } from "./agentState";
86
86
  export { createInMemoryDNCList, isPhoneOnDNC, isWithinCampaignWindow, normalizePhoneNumber, shouldRetryCampaignAttempt, summarizeVoiceCampaignDispositions, } from "./campaignControls";
87
87
  export type { VoiceCampaignDisposition, VoiceCampaignDispositionRetryPolicy, VoiceCampaignDispositionRetryRule, VoiceCampaignDispositionSummary, VoiceCampaignWindowCheckInput, VoiceDNCList, } from "./campaignControls";
88
88
  export { createVoiceBackchannelDriver } from "./backchannel";
89
+ export { createVoiceOAuth2TokenSource } from "./oauth2TokenSource";
90
+ export type { CreateVoiceOAuth2TokenSourceOptions, VoiceOAuth2TokenResponse, VoiceOAuth2TokenSource, } from "./oauth2TokenSource";
89
91
  export type { VoiceBackchannelCue, VoiceBackchannelDriver, VoiceBackchannelDriverOptions, } from "./backchannel";
90
92
  export { createVoiceIVRSession, describeVoiceIVRPlan, evaluateVoiceIVRPlan, } from "./ivrPlan";
91
93
  export type { VoiceIVRBranch, VoiceIVRDecision, VoiceIVRInput, VoiceIVRMatch, VoiceIVRPlan, VoiceIVRSession, } from "./ivrPlan";
@@ -97,8 +99,8 @@ export type { VoiceWebhookVerificationInput, VoiceWebhookVerificationReason, Voi
97
99
  export type { CreatePunctuationSemanticTurnDetectorOptions, CreateRegexSemanticTurnDetectorOptions, VoiceSemanticTurnDetector, VoiceSemanticTurnInput, VoiceSemanticTurnVerdict, } from "./semanticTurn";
98
100
  export { createMonologueAMDDetector } from "./amdDetector";
99
101
  export type { MonologueAMDDetectorOptions, VoiceAMDDetector, VoiceAMDDetectorInput, VoiceAMDVerdict, } from "./amdDetector";
100
- export { createVoiceRAGTool } from "./ragTool";
101
- export type { VoiceRAGCollectionLike, VoiceRAGQueryResult, VoiceRAGSearchInput, VoiceRAGToolArgs, VoiceRAGToolOptions, VoiceRAGToolResult, } from "./ragTool";
102
+ export { createVoiceRAGTool, extractVoiceRAGCitations } from "./ragTool";
103
+ export type { VoiceRAGCitationSummary, VoiceRAGCollectionLike, VoiceRAGQueryResult, VoiceRAGSearchInput, VoiceRAGToolArgs, VoiceRAGToolOptions, VoiceRAGToolResult, } from "./ragTool";
102
104
  export { createVoiceApiRequestTool, createVoiceDTMFTool, createVoiceEndCallTool, createVoiceTransferCallTool, createVoiceVoicemailDetectionTool, } from "./agentTools";
103
105
  export { fromVapiAssistantConfig } from "./vapiAdapter";
104
106
  export type { VapiAssistantConfig, VapiAssistantConfigModel, VapiAssistantConfigTool, VapiAssistantConfigTranscriber, VapiAssistantConfigTransferDestination, VapiAssistantConfigVoice, VapiAssistantMessage, VoiceFromVapiAssistantOptions, VoiceFromVapiAssistantResult, VoiceFromVapiCustomToolFactory, VoiceFromVapiCustomToolInput, VoiceFromVapiDTMFFactory, VoiceFromVapiKnowledgeBase, VoiceFromVapiModelFactory, VoiceFromVapiModelFactoryInput, VoiceFromVapiRouteHints, VoiceFromVapiUnsupportedReason, } from "./vapiAdapter";
package/dist/index.js CHANGED
@@ -35663,6 +35663,66 @@ var createVoiceBackchannelDriver = (options) => {
35663
35663
  }
35664
35664
  };
35665
35665
  };
35666
+ // src/oauth2TokenSource.ts
35667
+ var createVoiceOAuth2TokenSource = (options) => {
35668
+ const fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
35669
+ const refreshSkewMs = (options.refreshSkewSeconds ?? 60) * 1000;
35670
+ let cached;
35671
+ let pending;
35672
+ const fetchToken = async () => {
35673
+ const body = new URLSearchParams;
35674
+ body.set("grant_type", options.grantType ?? "client_credentials");
35675
+ body.set("client_id", options.clientId);
35676
+ body.set("client_secret", options.clientSecret);
35677
+ if (options.scope) {
35678
+ body.set("scope", options.scope);
35679
+ }
35680
+ if (options.audience) {
35681
+ body.set("audience", options.audience);
35682
+ }
35683
+ const response = await fetchImpl(options.tokenUrl, {
35684
+ body: body.toString(),
35685
+ headers: {
35686
+ accept: "application/json",
35687
+ "content-type": "application/x-www-form-urlencoded"
35688
+ },
35689
+ method: "POST"
35690
+ });
35691
+ if (!response.ok) {
35692
+ const text = await response.text().catch(() => "");
35693
+ throw new Error(`OAuth2 token request failed: ${response.status} ${response.statusText}${text ? ` \u2014 ${text.slice(0, 200)}` : ""}`);
35694
+ }
35695
+ const json = await response.json();
35696
+ if (!json.access_token) {
35697
+ throw new Error("OAuth2 token response missing access_token");
35698
+ }
35699
+ const ttlMs = typeof json.expires_in === "number" && json.expires_in > 0 ? json.expires_in * 1000 : 5 * 60 * 1000;
35700
+ cached = {
35701
+ expiresAt: Date.now() + ttlMs,
35702
+ value: json.access_token
35703
+ };
35704
+ return json.access_token;
35705
+ };
35706
+ return {
35707
+ invalidate: () => {
35708
+ cached = undefined;
35709
+ pending = undefined;
35710
+ },
35711
+ token: async () => {
35712
+ const now = Date.now();
35713
+ if (cached && cached.expiresAt - refreshSkewMs > now) {
35714
+ return cached.value;
35715
+ }
35716
+ if (pending) {
35717
+ return pending;
35718
+ }
35719
+ pending = fetchToken().finally(() => {
35720
+ pending = undefined;
35721
+ });
35722
+ return pending;
35723
+ }
35724
+ };
35725
+ };
35666
35726
  // src/ivrPlan.ts
35667
35727
  var speechMatchesPattern = (pattern, speech) => {
35668
35728
  const normalized = speech.toLowerCase().trim();
@@ -36006,6 +36066,28 @@ var createMonologueAMDDetector = (options = {}) => {
36006
36066
  };
36007
36067
  };
36008
36068
  // src/ragTool.ts
36069
+ var extractVoiceRAGCitations = (toolResults, toolName = "searchKnowledgeBase") => {
36070
+ const out = [];
36071
+ for (const entry of toolResults) {
36072
+ if (entry.toolName !== toolName) {
36073
+ continue;
36074
+ }
36075
+ const result = entry.result;
36076
+ const citations = result?.citations;
36077
+ if (!Array.isArray(citations)) {
36078
+ continue;
36079
+ }
36080
+ for (const citation of citations) {
36081
+ out.push({
36082
+ chunkId: citation.chunkId,
36083
+ score: citation.score,
36084
+ source: citation.source,
36085
+ title: citation.title
36086
+ });
36087
+ }
36088
+ }
36089
+ return out;
36090
+ };
36009
36091
  var DEFAULT_TOOL_NAME = "searchKnowledgeBase";
36010
36092
  var DEFAULT_DESCRIPTION = "Search the knowledge base and return short grounded citations. Use this whenever the caller asks a question that may be answered by indexed reference material.";
36011
36093
  var DEFAULT_TOP_K = 6;
@@ -46800,6 +46882,7 @@ export {
46800
46882
  fetchVoiceProofTarget,
46801
46883
  failVoiceOpsTask,
46802
46884
  extractVoiceWebhookSignatureFromHeaders,
46885
+ extractVoiceRAGCitations,
46803
46886
  extractVoiceMediaPipelineIssueEntries,
46804
46887
  exportVoiceTrace,
46805
46888
  exportVoiceAuditTrail,
@@ -47052,6 +47135,7 @@ export {
47052
47135
  createVoiceObservabilityExportRoutes,
47053
47136
  createVoiceObservabilityExportReplayRoutes,
47054
47137
  createVoiceOTELHTTPExporter,
47138
+ createVoiceOAuth2TokenSource,
47055
47139
  createVoiceMonitorWebhookNotifier,
47056
47140
  createVoiceMonitorSession,
47057
47141
  createVoiceMonitorRuntimeBinding,
@@ -0,0 +1,21 @@
1
+ export type VoiceOAuth2TokenResponse = {
2
+ access_token: string;
3
+ expires_in?: number;
4
+ token_type?: string;
5
+ };
6
+ export type VoiceOAuth2TokenSource = {
7
+ invalidate: () => void;
8
+ token: () => Promise<string>;
9
+ };
10
+ export type CreateVoiceOAuth2TokenSourceOptions = {
11
+ audience?: string;
12
+ clientId: string;
13
+ clientSecret: string;
14
+ fetch?: typeof fetch;
15
+ grantType?: "client_credentials";
16
+ /** seconds remaining before expiry to refresh proactively, default 60 */
17
+ refreshSkewSeconds?: number;
18
+ scope?: string;
19
+ tokenUrl: string;
20
+ };
21
+ export declare const createVoiceOAuth2TokenSource: (options: CreateVoiceOAuth2TokenSourceOptions) => VoiceOAuth2TokenSource;
package/dist/ragTool.d.ts CHANGED
@@ -29,6 +29,16 @@ export type VoiceRAGToolResult = {
29
29
  query: string;
30
30
  topK: number;
31
31
  };
32
+ export type VoiceRAGCitationSummary = {
33
+ chunkId: string;
34
+ score: number;
35
+ source?: string;
36
+ title?: string;
37
+ };
38
+ export declare const extractVoiceRAGCitations: (toolResults: ReadonlyArray<{
39
+ result?: unknown;
40
+ toolName: string;
41
+ }>, toolName?: string) => VoiceRAGCitationSummary[];
32
42
  export type VoiceRAGToolOptions<TContext = unknown> = {
33
43
  allowedFilterKeys?: readonly string[];
34
44
  description?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.491",
3
+ "version": "0.0.22-beta.493",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",