@memberjunction/telephony-adapters 6.2.0-edge.1 → 6.2.0-edge.3

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.
Files changed (157) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +10 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/resolvers/LiveKitSipResolver.d.ts +21 -0
  6. package/dist/resolvers/LiveKitSipResolver.d.ts.map +1 -0
  7. package/dist/resolvers/LiveKitSipResolver.js +87 -0
  8. package/dist/resolvers/LiveKitSipResolver.js.map +1 -0
  9. package/dist/resolvers/RingCentralTelephonyResolver.d.ts.map +1 -1
  10. package/dist/resolvers/RingCentralTelephonyResolver.js +4 -1
  11. package/dist/resolvers/RingCentralTelephonyResolver.js.map +1 -1
  12. package/dist/resolvers/TelephonyResolver.d.ts.map +1 -1
  13. package/dist/resolvers/TelephonyResolver.js +4 -1
  14. package/dist/resolvers/TelephonyResolver.js.map +1 -1
  15. package/dist/resolvers/VonageTelephonyResolver.d.ts.map +1 -1
  16. package/dist/resolvers/VonageTelephonyResolver.js +4 -1
  17. package/dist/resolvers/VonageTelephonyResolver.js.map +1 -1
  18. package/dist/resolvers/index.d.ts +1 -0
  19. package/dist/resolvers/index.d.ts.map +1 -1
  20. package/dist/resolvers/index.js +1 -0
  21. package/dist/resolvers/index.js.map +1 -1
  22. package/dist/server-extensions/LiveKitSipExtension.d.ts +14 -0
  23. package/dist/server-extensions/LiveKitSipExtension.d.ts.map +1 -0
  24. package/dist/server-extensions/LiveKitSipExtension.js +93 -0
  25. package/dist/server-extensions/LiveKitSipExtension.js.map +1 -0
  26. package/dist/server-extensions/RingCentralTelephonyExtension.d.ts.map +1 -1
  27. package/dist/server-extensions/RingCentralTelephonyExtension.js +8 -2
  28. package/dist/server-extensions/RingCentralTelephonyExtension.js.map +1 -1
  29. package/dist/server-extensions/TwilioTelephonyExtension.d.ts.map +1 -1
  30. package/dist/server-extensions/TwilioTelephonyExtension.js +10 -4
  31. package/dist/server-extensions/TwilioTelephonyExtension.js.map +1 -1
  32. package/dist/server-extensions/VonageTelephonyExtension.d.ts.map +1 -1
  33. package/dist/server-extensions/VonageTelephonyExtension.js +8 -4
  34. package/dist/server-extensions/VonageTelephonyExtension.js.map +1 -1
  35. package/dist/telephony/LiveKitSipRouter.d.ts +26 -0
  36. package/dist/telephony/LiveKitSipRouter.d.ts.map +1 -0
  37. package/dist/telephony/LiveKitSipRouter.js +62 -0
  38. package/dist/telephony/LiveKitSipRouter.js.map +1 -0
  39. package/dist/telephony/LiveKitSipTelephonyService.d.ts +130 -0
  40. package/dist/telephony/LiveKitSipTelephonyService.d.ts.map +1 -0
  41. package/dist/telephony/LiveKitSipTelephonyService.js +453 -0
  42. package/dist/telephony/LiveKitSipTelephonyService.js.map +1 -0
  43. package/dist/telephony/RingCentralTelephonyService.d.ts +57 -8
  44. package/dist/telephony/RingCentralTelephonyService.d.ts.map +1 -1
  45. package/dist/telephony/RingCentralTelephonyService.js +137 -77
  46. package/dist/telephony/RingCentralTelephonyService.js.map +1 -1
  47. package/dist/telephony/TwilioTelephonyRouter.d.ts +36 -6
  48. package/dist/telephony/TwilioTelephonyRouter.d.ts.map +1 -1
  49. package/dist/telephony/TwilioTelephonyRouter.js +150 -54
  50. package/dist/telephony/TwilioTelephonyRouter.js.map +1 -1
  51. package/dist/telephony/TwilioTelephonyService.d.ts +64 -16
  52. package/dist/telephony/TwilioTelephonyService.d.ts.map +1 -1
  53. package/dist/telephony/TwilioTelephonyService.js +151 -77
  54. package/dist/telephony/TwilioTelephonyService.js.map +1 -1
  55. package/dist/telephony/VonageTelephonyRouter.d.ts +29 -1
  56. package/dist/telephony/VonageTelephonyRouter.d.ts.map +1 -1
  57. package/dist/telephony/VonageTelephonyRouter.js +84 -72
  58. package/dist/telephony/VonageTelephonyRouter.js.map +1 -1
  59. package/dist/telephony/VonageTelephonyService.d.ts +66 -8
  60. package/dist/telephony/VonageTelephonyService.d.ts.map +1 -1
  61. package/dist/telephony/VonageTelephonyService.js +152 -67
  62. package/dist/telephony/VonageTelephonyService.js.map +1 -1
  63. package/dist/telephony/agentIdentityLookup.d.ts +30 -0
  64. package/dist/telephony/agentIdentityLookup.d.ts.map +1 -0
  65. package/dist/telephony/agentIdentityLookup.js +129 -0
  66. package/dist/telephony/agentIdentityLookup.js.map +1 -0
  67. package/dist/telephony/callEndObserver.d.ts +47 -0
  68. package/dist/telephony/callEndObserver.d.ts.map +1 -0
  69. package/dist/telephony/callEndObserver.js +95 -0
  70. package/dist/telephony/callEndObserver.js.map +1 -0
  71. package/dist/telephony/callLifecycleTracker.d.ts +83 -0
  72. package/dist/telephony/callLifecycleTracker.d.ts.map +1 -0
  73. package/dist/telephony/callLifecycleTracker.js +155 -0
  74. package/dist/telephony/callLifecycleTracker.js.map +1 -0
  75. package/dist/telephony/callerIdentity.d.ts +65 -0
  76. package/dist/telephony/callerIdentity.d.ts.map +1 -0
  77. package/dist/telephony/callerIdentity.js +72 -0
  78. package/dist/telephony/callerIdentity.js.map +1 -0
  79. package/dist/telephony/handoffDestinations.d.ts +57 -0
  80. package/dist/telephony/handoffDestinations.d.ts.map +1 -0
  81. package/dist/telephony/handoffDestinations.js +78 -0
  82. package/dist/telephony/handoffDestinations.js.map +1 -0
  83. package/dist/telephony/index.d.ts +21 -0
  84. package/dist/telephony/index.d.ts.map +1 -1
  85. package/dist/telephony/index.js +23 -0
  86. package/dist/telephony/index.js.map +1 -1
  87. package/dist/telephony/interactionLifecycle.d.ts +100 -0
  88. package/dist/telephony/interactionLifecycle.d.ts.map +1 -0
  89. package/dist/telephony/interactionLifecycle.js +338 -0
  90. package/dist/telephony/interactionLifecycle.js.map +1 -0
  91. package/dist/telephony/livekit-sip-runtime.d.ts +12 -0
  92. package/dist/telephony/livekit-sip-runtime.d.ts.map +1 -0
  93. package/dist/telephony/livekit-sip-runtime.js +21 -0
  94. package/dist/telephony/livekit-sip-runtime.js.map +1 -0
  95. package/dist/telephony/mediaSocketAuth.d.ts +77 -0
  96. package/dist/telephony/mediaSocketAuth.d.ts.map +1 -0
  97. package/dist/telephony/mediaSocketAuth.js +136 -0
  98. package/dist/telephony/mediaSocketAuth.js.map +1 -0
  99. package/dist/telephony/numberPoolSelector.d.ts +62 -0
  100. package/dist/telephony/numberPoolSelector.d.ts.map +1 -0
  101. package/dist/telephony/numberPoolSelector.js +201 -0
  102. package/dist/telephony/numberPoolSelector.js.map +1 -0
  103. package/dist/telephony/outboundCallPolicy.d.ts +226 -0
  104. package/dist/telephony/outboundCallPolicy.d.ts.map +1 -0
  105. package/dist/telephony/outboundCallPolicy.js +364 -0
  106. package/dist/telephony/outboundCallPolicy.js.map +1 -0
  107. package/dist/telephony/roomCallSession.d.ts +136 -0
  108. package/dist/telephony/roomCallSession.d.ts.map +1 -0
  109. package/dist/telephony/roomCallSession.js +359 -0
  110. package/dist/telephony/roomCallSession.js.map +1 -0
  111. package/dist/telephony/roomCallTools.d.ts +99 -0
  112. package/dist/telephony/roomCallTools.d.ts.map +1 -0
  113. package/dist/telephony/roomCallTools.js +255 -0
  114. package/dist/telephony/roomCallTools.js.map +1 -0
  115. package/dist/telephony/runAsIdentity.d.ts +62 -0
  116. package/dist/telephony/runAsIdentity.d.ts.map +1 -0
  117. package/dist/telephony/runAsIdentity.js +89 -0
  118. package/dist/telephony/runAsIdentity.js.map +1 -0
  119. package/dist/telephony/sipTrunkCarrier.d.ts +100 -0
  120. package/dist/telephony/sipTrunkCarrier.d.ts.map +1 -0
  121. package/dist/telephony/sipTrunkCarrier.js +118 -0
  122. package/dist/telephony/sipTrunkCarrier.js.map +1 -0
  123. package/dist/telephony/teamsAcsMediaRegistry.d.ts.map +1 -1
  124. package/dist/telephony/teamsAcsMediaRegistry.js +3 -2
  125. package/dist/telephony/teamsAcsMediaRegistry.js.map +1 -1
  126. package/dist/telephony/telephonyCallSession.d.ts +130 -0
  127. package/dist/telephony/telephonyCallSession.d.ts.map +1 -0
  128. package/dist/telephony/telephonyCallSession.js +315 -0
  129. package/dist/telephony/telephonyCallSession.js.map +1 -0
  130. package/dist/telephony/telephonyCallTools.d.ts +112 -0
  131. package/dist/telephony/telephonyCallTools.d.ts.map +1 -0
  132. package/dist/telephony/telephonyCallTools.js +269 -0
  133. package/dist/telephony/telephonyCallTools.js.map +1 -0
  134. package/dist/telephony/telephonyCapacity.d.ts +63 -0
  135. package/dist/telephony/telephonyCapacity.d.ts.map +1 -0
  136. package/dist/telephony/telephonyCapacity.js +94 -0
  137. package/dist/telephony/telephonyCapacity.js.map +1 -0
  138. package/dist/telephony/telephonySettings.d.ts +40 -0
  139. package/dist/telephony/telephonySettings.d.ts.map +1 -0
  140. package/dist/telephony/telephonySettings.js +69 -0
  141. package/dist/telephony/telephonySettings.js.map +1 -0
  142. package/dist/telephony/twilioMediaRegistry.d.ts +83 -11
  143. package/dist/telephony/twilioMediaRegistry.d.ts.map +1 -1
  144. package/dist/telephony/twilioMediaRegistry.js +145 -22
  145. package/dist/telephony/twilioMediaRegistry.js.map +1 -1
  146. package/dist/telephony/vonageMediaRegistry.d.ts +96 -2
  147. package/dist/telephony/vonageMediaRegistry.d.ts.map +1 -1
  148. package/dist/telephony/vonageMediaRegistry.js +227 -26
  149. package/dist/telephony/vonageMediaRegistry.js.map +1 -1
  150. package/dist/telephony/webhookParams.d.ts +21 -0
  151. package/dist/telephony/webhookParams.d.ts.map +1 -0
  152. package/dist/telephony/webhookParams.js +45 -0
  153. package/dist/telephony/webhookParams.js.map +1 -0
  154. package/dist/types.d.ts +90 -7
  155. package/dist/types.d.ts.map +1 -1
  156. package/dist/types.js.map +1 -1
  157. package/package.json +16 -13
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @fileoverview What a phone-voiced agent is told about the call, and the call-control tools it can use.
3
+ *
4
+ * A model that does not know it is on a phone talks like a chat window: markdown, lists, long paragraphs. This
5
+ * module supplies the framing that fixes that (plus who is calling), and four tools the model can call on the
6
+ * live call — `transfer_call`, `send_dtmf`, `end_call` and `cancel_pending_work`.
7
+ *
8
+ * The tools are executed here, by the host, not by the delegation path: they act on the call itself (the
9
+ * telephony bridge), which only the host holds. Every argument comes from the model — and so, indirectly, from an
10
+ * unverified caller — so each is validated before it touches the carrier:
11
+ * - `transfer_call` takes the NAME of an entry in the operator's transfer directory (`telephony.transferTargets`),
12
+ * never a number. A free-form destination, even one that passes the outbound allow/block lists, would let any
13
+ * caller get free call forwarding to any allowed number at the operator's expense. The tool is not offered at
14
+ * all when the directory is empty or the carrier cannot transfer. The resolved number is still checked against
15
+ * the outbound policy (defence in depth). Later routing work (queues, human-agent targets) adds kinds of target
16
+ * to this directory; it does not reintroduce free-form numbers.
17
+ * - DTMF is limited to the keypad alphabet and a length cap.
18
+ * - `cancel_pending_work` is the phone's explicit cancel: barge-in does not abort delegated work (the user keeps
19
+ * talking while it runs), and a phone has no per-job cancel button, so the agent cancels on the caller's word.
20
+ *
21
+ * @module @memberjunction/telephony-adapters
22
+ */
23
+ import type { RealtimeToolCall, RealtimeToolDefinition } from '@memberjunction/ai';
24
+ import type { BridgeLocalToolHandler } from '@memberjunction/ai-agents';
25
+ import type { CallerIdentity } from './callerIdentity.js';
26
+ import { type OutboundCallPolicy, type TransferTarget } from './outboundCallPolicy.js';
27
+ /** The tool names the host executes itself. */
28
+ export declare const TRANSFER_CALL_TOOL = "transfer_call";
29
+ export declare const SEND_DTMF_TOOL = "send_dtmf";
30
+ export declare const END_CALL_TOOL = "end_call";
31
+ export declare const CANCEL_PENDING_WORK_TOOL = "cancel_pending_work";
32
+ /**
33
+ * How long to let the agent's goodbye finish before a transfer or hang-up takes effect. The model usually speaks
34
+ * and calls the tool in the same breath; acting at once would cut its last sentence off.
35
+ */
36
+ export declare const CALL_CONTROL_SETTLE_MS = 3000;
37
+ /** The longest end-of-call reason kept (it is logged, never spoken). */
38
+ export declare const END_CALL_REASON_MAX_CHARS = 200;
39
+ /** Which call-control features the carrier supports (from the provider's `SupportedFeatures`). */
40
+ export interface TelephonyToolFeatures {
41
+ /** The carrier can transfer a live call. */
42
+ CallTransfer: boolean;
43
+ /** The carrier can send DTMF tones. */
44
+ DTMF: boolean;
45
+ }
46
+ /**
47
+ * The tools to offer for a carrier. `end_call` and `cancel_pending_work` always; `send_dtmf` when the carrier does
48
+ * DTMF; `transfer_call` only when the carrier can transfer AND the transfer directory is non-empty.
49
+ */
50
+ export declare function BuildTelephonyTools(features: TelephonyToolFeatures, transferTargets?: readonly TransferTarget[]): RealtimeToolDefinition[];
51
+ /** What the framing needs to know about the call. */
52
+ export interface PhoneFramingInput {
53
+ Direction: 'Inbound' | 'Outbound';
54
+ /** The other party's number (inbound: the caller's caller ID; outbound: the number dialled). */
55
+ RemoteNumber: string;
56
+ /** What the host knows about an inbound caller (absent for outbound calls). */
57
+ Caller?: CallerIdentity;
58
+ /** The call-control features offered. */
59
+ Features: TelephonyToolFeatures;
60
+ /** The transfer directory; transfer is not mentioned when it is empty. */
61
+ TransferTargets?: readonly TransferTarget[];
62
+ }
63
+ /**
64
+ * The instructions that make the model behave like a phone agent: voice-only etiquette, who is on the line (and
65
+ * how much of that is verified), and when to use the call-control tools. Appended to the agent's own prompt.
66
+ */
67
+ export declare function BuildPhoneFraming(input: PhoneFramingInput): string;
68
+ /** Executes the host-side call-control tools. */
69
+ export interface TelephonyCallControls {
70
+ /** Transfers the live call to a number. */
71
+ TransferCall(target: string): Promise<void>;
72
+ /** Presses keypad digits on the live call. */
73
+ SendDTMF(digits: string): Promise<void>;
74
+ }
75
+ /** What the executor needs. */
76
+ export interface TelephonyToolExecutorDeps {
77
+ /** The call's controls — resolved lazily because the bridge does not exist until the bridge engine has started. */
78
+ Controls: () => TelephonyCallControls | undefined;
79
+ /** The outbound policy a transfer destination is checked against. */
80
+ Policy: OutboundCallPolicy;
81
+ /** The features the carrier supports (a tool for an unsupported one is refused even if the model invents the call). */
82
+ Features: TelephonyToolFeatures;
83
+ /** The transfer directory — the only destinations `transfer_call` can reach. */
84
+ TransferTargets: readonly TransferTarget[];
85
+ /** Ends the call (stops the bridge session). */
86
+ EndCall: (reason: string) => Promise<void>;
87
+ /** Aborts the delegated work in flight; returns how many runs were aborted. */
88
+ CancelPendingWork: () => number;
89
+ /** Tells the model something happened out-of-band (a failed transfer) so it can tell the caller. */
90
+ NotifyModel: (note: string) => void;
91
+ /** Override for the goodbye settle delay (tests). */
92
+ SettleMs?: number;
93
+ }
94
+ /** Runs `transfer_call`, `send_dtmf` and `end_call` against the live call. */
95
+ export declare class TelephonyCallToolExecutor implements BridgeLocalToolHandler {
96
+ private readonly deps;
97
+ private ending;
98
+ private transferring;
99
+ constructor(deps: TelephonyToolExecutorDeps);
100
+ /** Whether `toolName` is one of the call-control tools. */
101
+ Handles(toolName: string): boolean;
102
+ /** Runs one tool call and returns the JSON the model is handed back. Never throws. */
103
+ Execute(call: RealtimeToolCall): Promise<string>;
104
+ private transfer;
105
+ private performTransfer;
106
+ private sendDtmf;
107
+ private cancelPendingWork;
108
+ private endCall;
109
+ /** Runs `work` after the goodbye has had time to play, on an unref'd timer; failures are logged, never thrown. */
110
+ private afterSettle;
111
+ }
112
+ //# sourceMappingURL=telephonyCallTools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telephonyCallTools.d.ts","sourceRoot":"","sources":["../../src/telephony/telephonyCallTools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,KAAK,EAAc,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE/F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAmF,KAAK,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAExK,+CAA+C;AAC/C,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAClD,eAAO,MAAM,cAAc,cAAc,CAAC;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QAAQ,EAAE,qBAAqB,CAAC;IAChC,gFAAgF;IAChF,eAAe,EAAE,SAAS,cAAc,EAAE,CAAC;IAC3C,gDAAgD;IAChD,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,+EAA+E;IAC/E,iBAAiB,EAAE,MAAM,MAAM,CAAC;IAChC,oGAAoG;IACpG,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,8EAA8E;AAC9E,qBAAa,yBAA0B,YAAW,sBAAsB;IAIxD,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAS;gBAEA,IAAI,EAAE,yBAAyB;IAE5D,2DAA2D;IACpD,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIzC,sFAAsF;IACzE,OAAO,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;IAoB7D,OAAO,CAAC,QAAQ;YAsBF,eAAe;YAef,QAAQ;IAgBtB,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,OAAO;IAUf,kHAAkH;IAClH,OAAO,CAAC,WAAW;CAMtB"}
@@ -0,0 +1,269 @@
1
+ /**
2
+ * @fileoverview What a phone-voiced agent is told about the call, and the call-control tools it can use.
3
+ *
4
+ * A model that does not know it is on a phone talks like a chat window: markdown, lists, long paragraphs. This
5
+ * module supplies the framing that fixes that (plus who is calling), and four tools the model can call on the
6
+ * live call — `transfer_call`, `send_dtmf`, `end_call` and `cancel_pending_work`.
7
+ *
8
+ * The tools are executed here, by the host, not by the delegation path: they act on the call itself (the
9
+ * telephony bridge), which only the host holds. Every argument comes from the model — and so, indirectly, from an
10
+ * unverified caller — so each is validated before it touches the carrier:
11
+ * - `transfer_call` takes the NAME of an entry in the operator's transfer directory (`telephony.transferTargets`),
12
+ * never a number. A free-form destination, even one that passes the outbound allow/block lists, would let any
13
+ * caller get free call forwarding to any allowed number at the operator's expense. The tool is not offered at
14
+ * all when the directory is empty or the carrier cannot transfer. The resolved number is still checked against
15
+ * the outbound policy (defence in depth). Later routing work (queues, human-agent targets) adds kinds of target
16
+ * to this directory; it does not reintroduce free-form numbers.
17
+ * - DTMF is limited to the keypad alphabet and a length cap.
18
+ * - `cancel_pending_work` is the phone's explicit cancel: barge-in does not abort delegated work (the user keeps
19
+ * talking while it runs), and a phone has no per-job cancel button, so the agent cancels on the caller's word.
20
+ *
21
+ * @module @memberjunction/telephony-adapters
22
+ */
23
+ import { LogError, LogStatus } from '@memberjunction/core';
24
+ import { IsValidDtmfDigits, MAX_DTMF_DIGITS } from '@memberjunction/ai-bridge-base';
25
+ import { CheckTransferDestination, FindTransferTarget, MaskNumber, NumberTransferTargets } from './outboundCallPolicy.js';
26
+ /** The tool names the host executes itself. */
27
+ export const TRANSFER_CALL_TOOL = 'transfer_call';
28
+ export const SEND_DTMF_TOOL = 'send_dtmf';
29
+ export const END_CALL_TOOL = 'end_call';
30
+ export const CANCEL_PENDING_WORK_TOOL = 'cancel_pending_work';
31
+ /**
32
+ * How long to let the agent's goodbye finish before a transfer or hang-up takes effect. The model usually speaks
33
+ * and calls the tool in the same breath; acting at once would cut its last sentence off.
34
+ */
35
+ export const CALL_CONTROL_SETTLE_MS = 3000;
36
+ /** The longest end-of-call reason kept (it is logged, never spoken). */
37
+ export const END_CALL_REASON_MAX_CHARS = 200;
38
+ /** The longest caller number put into the prompt. */
39
+ const PROMPT_NUMBER_MAX_CHARS = 20;
40
+ /**
41
+ * Whether the agent may transfer: the carrier supports it AND the operator configured a phone number to send calls to.
42
+ * A carrier call has no room to bring a person or another agent into, so only `number` entries of the directory count
43
+ * here; the `user` and `agent` kinds belong to room calls (see `roomCallTools.ts`).
44
+ */
45
+ function canTransfer(features, targets) {
46
+ return features.CallTransfer && NumberTransferTargets(targets).length > 0;
47
+ }
48
+ /**
49
+ * The tools to offer for a carrier. `end_call` and `cancel_pending_work` always; `send_dtmf` when the carrier does
50
+ * DTMF; `transfer_call` only when the carrier can transfer AND the transfer directory is non-empty.
51
+ */
52
+ export function BuildTelephonyTools(features, transferTargets = []) {
53
+ const tools = [];
54
+ const numberTargets = NumberTransferTargets(transferTargets);
55
+ if (canTransfer(features, transferTargets)) {
56
+ tools.push({
57
+ Name: TRANSFER_CALL_TOOL,
58
+ Description: 'Transfer this call to one of the configured destinations. Say a short goodbye first; the call leaves you when the ' +
59
+ `transfer completes. Only call it when the caller asks for it or you cannot help. Destinations: ${describeTransferTargets(numberTargets)}`,
60
+ ParametersSchema: objectSchema({ target: { type: 'string', enum: numberTargets.map((t) => t.Name), description: 'The name of the place to transfer to, exactly as listed.' } }, ['target']),
61
+ });
62
+ }
63
+ if (features.DTMF) {
64
+ tools.push({
65
+ Name: SEND_DTMF_TOOL,
66
+ Description: 'Press keypad digits on the call, for example to navigate a phone menu or enter an extension. ' +
67
+ `Digits are 0-9, * and # (at most ${MAX_DTMF_DIGITS}).`,
68
+ ParametersSchema: objectSchema({ digits: stringProperty('The digits to press, such as "1" or "4021#".') }, ['digits']),
69
+ });
70
+ }
71
+ tools.push({
72
+ Name: CANCEL_PENDING_WORK_TOOL,
73
+ Description: 'Cancel the lookups or tasks you started on the caller\'s behalf. Use ONLY when the caller says never mind, stop that or cancel. ' +
74
+ 'The caller talking, or saying "mm-hm", while you work does not mean cancel.',
75
+ ParametersSchema: objectSchema({}, []),
76
+ });
77
+ tools.push({
78
+ Name: END_CALL_TOOL,
79
+ Description: 'Hang up when the conversation is finished. Say goodbye first; the call ends a few seconds after you call this. ' +
80
+ 'Never end the call while the caller still has an open question.',
81
+ ParametersSchema: objectSchema({ reason: stringProperty('A short reason the call is ending.') }, []),
82
+ });
83
+ return tools;
84
+ }
85
+ /**
86
+ * The instructions that make the model behave like a phone agent: voice-only etiquette, who is on the line (and
87
+ * how much of that is verified), and when to use the call-control tools. Appended to the agent's own prompt.
88
+ */
89
+ export function BuildPhoneFraming(input) {
90
+ const lines = [
91
+ 'You are speaking with the caller on a live telephone call. They can only hear you; there is no screen.',
92
+ '- Speak naturally in short sentences. No markdown, bullet lists, headings or URLs; spell out anything the caller must write down, slowly.',
93
+ '- Do not read out long identifiers or codes unless asked. Confirm important details back to the caller.',
94
+ '- If you did not hear something clearly, ask the caller to repeat it.',
95
+ ];
96
+ lines.push(...describeRemoteParty(input));
97
+ lines.push(...describeTools(input.Features, input.TransferTargets ?? []));
98
+ return lines.join('\n');
99
+ }
100
+ /** Runs `transfer_call`, `send_dtmf` and `end_call` against the live call. */
101
+ export class TelephonyCallToolExecutor {
102
+ constructor(deps) {
103
+ this.deps = deps;
104
+ this.ending = false;
105
+ this.transferring = false;
106
+ }
107
+ /** Whether `toolName` is one of the call-control tools. */
108
+ Handles(toolName) {
109
+ return toolName === TRANSFER_CALL_TOOL || toolName === SEND_DTMF_TOOL || toolName === END_CALL_TOOL || toolName === CANCEL_PENDING_WORK_TOOL;
110
+ }
111
+ /** Runs one tool call and returns the JSON the model is handed back. Never throws. */
112
+ async Execute(call) {
113
+ try {
114
+ switch (call.ToolName) {
115
+ case TRANSFER_CALL_TOOL:
116
+ return this.transfer(call);
117
+ case SEND_DTMF_TOOL:
118
+ return await this.sendDtmf(call);
119
+ case END_CALL_TOOL:
120
+ return this.endCall(call);
121
+ case CANCEL_PENDING_WORK_TOOL:
122
+ return this.cancelPendingWork();
123
+ default:
124
+ return fail(`Unknown call-control tool '${call.ToolName}'.`);
125
+ }
126
+ }
127
+ catch (e) {
128
+ LogError(`[Telephony] call-control tool ${call.ToolName} failed: ${e instanceof Error ? e.message : String(e)}`);
129
+ return fail('The call-control action failed.');
130
+ }
131
+ }
132
+ transfer(call) {
133
+ if (!canTransfer(this.deps.Features, this.deps.TransferTargets)) {
134
+ return fail('Transferring is not available on this line.');
135
+ }
136
+ if (this.ending || this.transferring) {
137
+ return fail('The call is already ending or being transferred.');
138
+ }
139
+ const numberTargets = NumberTransferTargets(this.deps.TransferTargets);
140
+ const entry = FindTransferTarget(numberTargets, readString(call.Arguments, 'target'));
141
+ if (!entry || entry.Kind !== 'number') {
142
+ return fail(`Unknown transfer destination. Choose one of: ${numberTargets.map((t) => t.Name).join(', ')}.`);
143
+ }
144
+ // Defence in depth: the directory was validated at startup, but the policy is checked again on the resolved number.
145
+ const verdict = CheckTransferDestination(this.deps.Policy, entry.Number);
146
+ if (!verdict.Allowed) {
147
+ return fail(verdict.Reason);
148
+ }
149
+ this.transferring = true;
150
+ this.afterSettle(() => this.performTransfer(verdict.Number));
151
+ return JSON.stringify({ ok: true, status: 'transferring', note: 'Say a brief goodbye now; the call will be handed over in a few seconds.' });
152
+ }
153
+ async performTransfer(destination) {
154
+ try {
155
+ const controls = this.deps.Controls();
156
+ if (!controls) {
157
+ throw new Error('the call is not connected yet');
158
+ }
159
+ await controls.TransferCall(destination);
160
+ LogStatus(`[Telephony] call transferred to ${MaskNumber(destination)}.`);
161
+ }
162
+ catch (e) {
163
+ this.transferring = false;
164
+ LogError(`[Telephony] transfer to ${MaskNumber(destination)} failed: ${e instanceof Error ? e.message : String(e)}`);
165
+ this.deps.NotifyModel('[call control] The transfer failed and the caller is still on the line. Apologise briefly and offer another way to help.');
166
+ }
167
+ }
168
+ async sendDtmf(call) {
169
+ if (!this.deps.Features.DTMF) {
170
+ return fail('Keypad tones are not available on this line.');
171
+ }
172
+ const digits = readString(call.Arguments, 'digits').trim();
173
+ if (!IsValidDtmfDigits(digits)) {
174
+ return fail(`Digits must be 1 to ${MAX_DTMF_DIGITS} characters from 0-9, * and #.`);
175
+ }
176
+ const controls = this.deps.Controls();
177
+ if (!controls) {
178
+ return fail('The call is not connected yet.');
179
+ }
180
+ await controls.SendDTMF(digits);
181
+ return JSON.stringify({ ok: true, status: 'sent' });
182
+ }
183
+ cancelPendingWork() {
184
+ const cancelled = this.deps.CancelPendingWork();
185
+ LogStatus(`[Telephony] agent cancelled ${cancelled} pending run(s) at the caller's request.`);
186
+ return JSON.stringify({ ok: true, cancelled });
187
+ }
188
+ endCall(call) {
189
+ if (this.ending) {
190
+ return JSON.stringify({ ok: true, status: 'ending' });
191
+ }
192
+ this.ending = true;
193
+ const reason = readString(call.Arguments, 'reason').trim().slice(0, END_CALL_REASON_MAX_CHARS);
194
+ this.afterSettle(() => this.deps.EndCall(reason || 'agent ended the call'));
195
+ return JSON.stringify({ ok: true, status: 'ending', note: 'The call ends in a few seconds; finish your goodbye.' });
196
+ }
197
+ /** Runs `work` after the goodbye has had time to play, on an unref'd timer; failures are logged, never thrown. */
198
+ afterSettle(work) {
199
+ const timer = setTimeout(() => {
200
+ void work().catch((e) => LogError(`[Telephony] deferred call control failed: ${e instanceof Error ? e.message : String(e)}`));
201
+ }, this.deps.SettleMs ?? CALL_CONTROL_SETTLE_MS);
202
+ timer.unref?.();
203
+ }
204
+ }
205
+ // ── helpers ──────────────────────────────────────────────────────────────────────
206
+ function describeRemoteParty(input) {
207
+ const number = sanitizeNumberForPrompt(input.RemoteNumber);
208
+ if (input.Direction === 'Outbound') {
209
+ return [`You placed this call to ${number || 'the number'}. Introduce yourself and say why you are calling.`];
210
+ }
211
+ const lines = [`This is an inbound call. The caller's number (caller ID) is ${number || 'unavailable'}.`];
212
+ const caller = input.Caller;
213
+ if (caller?.Verified && caller.DisplayName) {
214
+ lines.push(`The caller has been verified as ${caller.DisplayName}.`);
215
+ }
216
+ else {
217
+ lines.push('The caller is UNVERIFIED. Caller ID can be faked, so do not treat the number as proof of who they are; ' +
218
+ 'do not reveal account details or take sensitive actions on the strength of it alone.');
219
+ if (caller?.DisplayName) {
220
+ lines.push(`The number matches ${caller.DisplayName}, but that is not verification.`);
221
+ }
222
+ }
223
+ if (caller?.ContextNotes?.trim()) {
224
+ lines.push(`About the caller: ${caller.ContextNotes.trim()}`);
225
+ }
226
+ return lines;
227
+ }
228
+ /** `Name (description); Name2` — what the agent is told each transfer destination is for. */
229
+ function describeTransferTargets(targets) {
230
+ return targets.map((t) => (t.Description ? `${t.Name} (${t.Description})` : t.Name)).join('; ');
231
+ }
232
+ function describeTools(features, targets) {
233
+ const lines = [];
234
+ if (canTransfer(features, targets)) {
235
+ lines.push(`- Use ${TRANSFER_CALL_TOOL} to hand the call over when the caller asks or you cannot help. You can only transfer to: ${describeTransferTargets(NumberTransferTargets(targets))}.`);
236
+ }
237
+ if (features.DTMF) {
238
+ lines.push(`- Use ${SEND_DTMF_TOOL} to press keys, for example in an automated menu. When the caller presses keys you will be told what they pressed.`);
239
+ }
240
+ lines.push(`- Use ${CANCEL_PENDING_WORK_TOOL} only when the caller says never mind, stop that or cancel. Talking while you work is normal and does not cancel anything.`);
241
+ lines.push(`- When the conversation is complete, say goodbye and then use ${END_CALL_TOOL}.`);
242
+ return lines;
243
+ }
244
+ /** Keeps only the characters a phone number can contain, capped, so a hostile caller ID cannot inject prompt text. */
245
+ function sanitizeNumberForPrompt(value) {
246
+ return (value ?? '').replace(/[^0-9+*#]/g, '').slice(0, PROMPT_NUMBER_MAX_CHARS);
247
+ }
248
+ /** Reads one string argument from the model's JSON arguments; anything else yields `''`. */
249
+ function readString(argumentsJson, name) {
250
+ try {
251
+ const parsed = JSON.parse(argumentsJson || '{}');
252
+ const value = parsed?.[name];
253
+ return typeof value === 'string' ? value : '';
254
+ }
255
+ catch (err) {
256
+ LogError(`[telephonyCallTools] Failed to parse arguments JSON: ${argumentsJson}`, undefined, err);
257
+ return '';
258
+ }
259
+ }
260
+ function fail(error) {
261
+ return JSON.stringify({ ok: false, error });
262
+ }
263
+ function stringProperty(description) {
264
+ return { type: 'string', description };
265
+ }
266
+ function objectSchema(properties, required) {
267
+ return { type: 'object', properties, required };
268
+ }
269
+ //# sourceMappingURL=telephonyCallTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telephonyCallTools.js","sourceRoot":"","sources":["../../src/telephony/telephonyCallTools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;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AC;QACrH,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;QAC7B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAClD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,QAAQ,CAAC,wDAAwD,aAAa,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;QAClG,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC;AAED,SAAS,IAAI,CAAC,KAAa;IACvB,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,cAAc,CAAC,WAAmB;IACvC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AAC3C,CAAC;AAED,SAAS,YAAY,CAAC,UAAsC,EAAE,QAAkB;IAC5E,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;AACpD,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @fileoverview The server-wide cap on simultaneous phone calls.
3
+ *
4
+ * Every realtime call holds a live model session, and the model plan has its own concurrent-session limit.
5
+ * Past that limit, new calls do not queue politely — they fail or degrade every call in progress. The cap makes
6
+ * the refusal explicit and early: an inbound caller hears "all agents are busy" and an outbound request is
7
+ * refused with a clear message, instead of a call that connects and then goes silent. (Queuing is a later
8
+ * feature; today the answer is a refusal.)
9
+ *
10
+ * The cap is shared by every carrier — it counts calls, not calls per carrier — so it is a process singleton.
11
+ * A call holds a {@link CallCapacityLease} from admission until its session ends (or fails to start); releasing
12
+ * a lease twice is harmless.
13
+ *
14
+ * @module @memberjunction/telephony-adapters
15
+ */
16
+ import { BaseSingleton } from '@memberjunction/global';
17
+ /** Default most simultaneous calls. Keep `telephony.maxConcurrentCalls` at or below the model plan's limit. */
18
+ export declare const DEFAULT_MAX_CONCURRENT_CALLS = 25;
19
+ /** A held slot. Release it exactly when the call is over; extra releases are ignored. */
20
+ export declare class CallCapacityLease {
21
+ private readonly onRelease;
22
+ private released;
23
+ constructor(onRelease: () => void);
24
+ /** Gives the slot back. Idempotent. */
25
+ Release(): void;
26
+ }
27
+ /** What the services need from the gate (an interface so tests can inject a fake). */
28
+ export interface ICallCapacity {
29
+ /** Takes a slot, or returns `null` when the server is at its cap. */
30
+ TryAcquire(): CallCapacityLease | null;
31
+ }
32
+ /** A counting gate over a fixed number of slots. */
33
+ export declare class CallCapacityGate implements ICallCapacity {
34
+ private maxCalls;
35
+ private active;
36
+ constructor(maxConcurrentCalls?: number | undefined);
37
+ /** A missing, non-finite or non-positive value uses the default, so a typo can neither remove the limit nor lock every caller out. */
38
+ private static normalize;
39
+ /** The configured cap. */
40
+ get Max(): number;
41
+ /** How many calls currently hold a slot. */
42
+ get Active(): number;
43
+ /** Changes the cap. Lowering it never drops a live call; it only refuses new ones until enough calls end. */
44
+ Configure(maxConcurrentCalls: number | undefined): void;
45
+ /** Takes a slot, or returns `null` when the gate is at its cap. */
46
+ TryAcquire(): CallCapacityLease | null;
47
+ }
48
+ /** The process-wide concurrent-call gate every carrier service shares (the cap counts calls, not calls per carrier). */
49
+ export declare class TelephonyCapacity extends BaseSingleton<TelephonyCapacity> implements ICallCapacity {
50
+ private readonly gate;
51
+ protected constructor();
52
+ /** The singleton accessor. */
53
+ static get Instance(): TelephonyCapacity;
54
+ /** The configured cap. */
55
+ get Max(): number;
56
+ /** How many calls currently hold a slot. */
57
+ get Active(): number;
58
+ /** Sets the cap (see {@link CallCapacityGate.Configure}). */
59
+ Configure(maxConcurrentCalls: number | undefined): void;
60
+ /** Takes a slot, or returns `null` when the server is at its cap. */
61
+ TryAcquire(): CallCapacityLease | null;
62
+ }
63
+ //# sourceMappingURL=telephonyCapacity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telephonyCapacity.d.ts","sourceRoot":"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AAS,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAI9D,qEAAqE;IAC9D,UAAU,IAAI,iBAAiB,GAAG,IAAI;CAGhD"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @fileoverview The server-wide cap on simultaneous phone calls.
3
+ *
4
+ * Every realtime call holds a live model session, and the model plan has its own concurrent-session limit.
5
+ * Past that limit, new calls do not queue politely — they fail or degrade every call in progress. The cap makes
6
+ * the refusal explicit and early: an inbound caller hears "all agents are busy" and an outbound request is
7
+ * refused with a clear message, instead of a call that connects and then goes silent. (Queuing is a later
8
+ * feature; today the answer is a refusal.)
9
+ *
10
+ * The cap is shared by every carrier — it counts calls, not calls per carrier — so it is a process singleton.
11
+ * A call holds a {@link CallCapacityLease} from admission until its session ends (or fails to start); releasing
12
+ * a lease twice is harmless.
13
+ *
14
+ * @module @memberjunction/telephony-adapters
15
+ */
16
+ import { BaseSingleton } from '@memberjunction/global';
17
+ /** Default most simultaneous calls. Keep `telephony.maxConcurrentCalls` at or below the model plan's limit. */
18
+ export const DEFAULT_MAX_CONCURRENT_CALLS = 25;
19
+ /** A held slot. Release it exactly when the call is over; extra releases are ignored. */
20
+ export class CallCapacityLease {
21
+ constructor(onRelease) {
22
+ this.onRelease = onRelease;
23
+ this.released = false;
24
+ }
25
+ /** Gives the slot back. Idempotent. */
26
+ Release() {
27
+ if (this.released) {
28
+ return;
29
+ }
30
+ this.released = true;
31
+ this.onRelease();
32
+ }
33
+ }
34
+ /** A counting gate over a fixed number of slots. */
35
+ export class CallCapacityGate {
36
+ constructor(maxConcurrentCalls = DEFAULT_MAX_CONCURRENT_CALLS) {
37
+ this.active = 0;
38
+ this.maxCalls = CallCapacityGate.normalize(maxConcurrentCalls);
39
+ }
40
+ /** A missing, non-finite or non-positive value uses the default, so a typo can neither remove the limit nor lock every caller out. */
41
+ static normalize(value) {
42
+ return typeof value === 'number' && Number.isFinite(value) && value >= 1 ? Math.floor(value) : DEFAULT_MAX_CONCURRENT_CALLS;
43
+ }
44
+ /** The configured cap. */
45
+ get Max() {
46
+ return this.maxCalls;
47
+ }
48
+ /** How many calls currently hold a slot. */
49
+ get Active() {
50
+ return this.active;
51
+ }
52
+ /** Changes the cap. Lowering it never drops a live call; it only refuses new ones until enough calls end. */
53
+ Configure(maxConcurrentCalls) {
54
+ this.maxCalls = CallCapacityGate.normalize(maxConcurrentCalls);
55
+ }
56
+ /** Takes a slot, or returns `null` when the gate is at its cap. */
57
+ TryAcquire() {
58
+ if (this.active >= this.maxCalls) {
59
+ return null;
60
+ }
61
+ this.active++;
62
+ return new CallCapacityLease(() => {
63
+ this.active = Math.max(0, this.active - 1);
64
+ });
65
+ }
66
+ }
67
+ /** The process-wide concurrent-call gate every carrier service shares (the cap counts calls, not calls per carrier). */
68
+ export class TelephonyCapacity extends BaseSingleton {
69
+ constructor() {
70
+ super();
71
+ this.gate = new CallCapacityGate();
72
+ }
73
+ /** The singleton accessor. */
74
+ static get Instance() {
75
+ return super.getInstance();
76
+ }
77
+ /** The configured cap. */
78
+ get Max() {
79
+ return this.gate.Max;
80
+ }
81
+ /** How many calls currently hold a slot. */
82
+ get Active() {
83
+ return this.gate.Active;
84
+ }
85
+ /** Sets the cap (see {@link CallCapacityGate.Configure}). */
86
+ Configure(maxConcurrentCalls) {
87
+ this.gate.Configure(maxConcurrentCalls);
88
+ }
89
+ /** Takes a slot, or returns `null` when the server is at its cap. */
90
+ TryAcquire() {
91
+ return this.gate.TryAcquire();
92
+ }
93
+ }
94
+ //# sourceMappingURL=telephonyCapacity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telephonyCapacity.js","sourceRoot":"","sources":["../../src/telephony/telephonyCapacity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,+GAA+G;AAC/G,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAE/C,yFAAyF;AAC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BAAiB,CAAC,GAAG,EAAE;YAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,wHAAwH;AACxH,MAAM,OAAO,iBAAkB,SAAQ,aAAgC;IAGnE;QACI,KAAK,EAAE,CAAC;QAHK,SAAI,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAI/C,CAAC;IAED,8BAA8B;IACvB,MAAM,KAAK,QAAQ;QACtB,OAAO,KAAK,CAAC,WAAW,EAAqB,CAAC;IAClD,CAAC;IAED,0BAA0B;IAC1B,IAAW,GAAG;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IACzB,CAAC;IAED,4CAA4C;IAC5C,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,6DAA6D;IACtD,SAAS,CAAC,kBAAsC;QACnD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC5C,CAAC;IAED,qEAAqE;IAC9D,UAAU;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;CACJ"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @fileoverview Normalizes the settings every carrier extension shares (run-as user, call cap, outbound
3
+ * policy) and the carrier-specific URL / machine-detection defaults the extensions derive.
4
+ *
5
+ * The host merges `telephony.{inboundRunAsUserEmail,maxCallSeconds,outbound}` into each carrier's extension
6
+ * settings, and an operator configuring `serverExtensions` directly supplies them the same way — so both
7
+ * paths arrive here as a loosely typed settings bag.
8
+ *
9
+ * @module @memberjunction/telephony-adapters
10
+ */
11
+ import type { OnMachineAction, TelephonySharedSettings } from '../types.js';
12
+ /**
13
+ * Picks the shared settings out of an extension's raw settings bag. Anything not set stays `undefined` so the
14
+ * consuming service applies its own default (and, for the run-as user, refuses inbound calls).
15
+ */
16
+ export declare function ReadSharedTelephonySettings(raw: Partial<TelephonySharedSettings> | undefined): TelephonySharedSettings;
17
+ /** Maps a raw `onMachine` value to its action, defaulting (and treating anything unknown) to `'hangup'`. */
18
+ export declare function ResolveOnMachine(raw: string | undefined): OnMachineAction;
19
+ /**
20
+ * Joins the public base URL, the extension's mount path and a route into the absolute URL a carrier should
21
+ * call back (e.g. `https://api.example.com` + `/telephony/twilio` + `/status`).
22
+ */
23
+ export declare function BuildCallbackUrl(publicUrl: string, rootPath: string, route: string): string;
24
+ /**
25
+ * The scheme + host (+ port) of the host's public URL, with any path dropped.
26
+ *
27
+ * The host's public URL is typically the GraphQL endpoint (`https://api.example.com/graphql`), but extension
28
+ * routes are mounted at the application root, so the URL a carrier calls — and signs — is the ORIGIN plus the
29
+ * route's own path. Appending the route to the full public URL double-counts the GraphQL path
30
+ * (`/graphql/telephony/twilio/voice`), which breaks both the callback URLs we hand the carrier and the
31
+ * signature check. An unparseable value falls back to a trailing-slash trim so a misconfiguration surfaces as
32
+ * a plainly wrong URL rather than an exception on the request path.
33
+ */
34
+ export declare function PublicOrigin(publicUrl: string): string;
35
+ /**
36
+ * Removes every trailing `/` from a string in a single linear scan. Used on operator- and request-supplied
37
+ * URLs instead of a `/\/+$/` regex, whose backtracking is polynomial on inputs with many slashes.
38
+ */
39
+ export declare function TrimTrailingSlashes(value: string): string;
40
+ //# sourceMappingURL=telephonySettings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telephonySettings.d.ts","sourceRoot":"","sources":["../../src/telephony/telephonySettings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE5E;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,SAAS,GAAG,uBAAuB,CAStH;AAED,4GAA4G;AAC5G,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,eAAe,CAEzE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAI3F;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAOtD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMzD"}