@fonoster/autopilot 0.27.0 → 0.31.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/README.md +15 -52
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -5
- package/dist/knowledge/AbstractKnowledgeBase.d.ts +3 -2
- package/dist/knowledge/AbstractKnowledgeBase.js +2 -7
- package/dist/knowledge/FilesKnowledgeBase.d.ts +1 -1
- package/dist/knowledge/MeteredEmbeddings.d.ts +47 -0
- package/dist/knowledge/MeteredEmbeddings.js +58 -0
- package/dist/knowledge/types.d.ts +1 -1
- package/dist/models/LanguageModelFactory.d.ts +5 -24
- package/dist/models/LanguageModelFactory.js +0 -1
- package/dist/models/createLanguageModel.d.ts +2 -2
- package/dist/models/createLanguageModel.js +2 -2
- package/dist/models/evaluations/createEvalEffectiveConfig.d.ts +10 -106
- package/dist/models/evaluations/createEvalEffectiveConfig.js +47 -7
- package/dist/models/evaluations/createEvaluateIntelligence.d.ts +21 -20
- package/dist/models/evaluations/createEvaluateIntelligence.js +53 -23
- package/dist/models/evaluations/createTestTextSimilarity.d.ts +7 -1
- package/dist/models/evaluations/createTestTextSimilarity.js +19 -1
- package/dist/models/evaluations/evalTestCases.d.ts +2 -2
- package/dist/models/evaluations/evalTestCases.js +7 -7
- package/dist/models/evaluations/evaluateScenario.js +2 -2
- package/dist/models/evaluations/evaluateStep.d.ts +1 -1
- package/dist/models/evaluations/evaluateStep.js +2 -2
- package/dist/models/evaluations/extractAiResponse.d.ts +2 -3
- package/dist/models/evaluations/extractAiResponse.js +3 -3
- package/dist/models/evaluations/index.d.ts +1 -0
- package/dist/models/evaluations/index.js +1 -0
- package/dist/models/evaluations/runEval.d.ts +2 -20
- package/dist/models/evaluations/runEval.js +7 -7
- package/dist/models/evaluations/session/EvalSession.d.ts +73 -0
- package/dist/models/evaluations/session/EvalSession.js +134 -0
- package/dist/models/evaluations/session/evaluateSessionScenario.d.ts +58 -0
- package/dist/models/evaluations/session/evaluateSessionScenario.js +182 -0
- package/dist/{vad → models/evaluations/session}/index.d.ts +3 -2
- package/dist/{vad → models/evaluations/session}/index.js +3 -2
- package/dist/models/evaluations/session/runSessionEval.d.ts +20 -0
- package/dist/models/evaluations/session/runSessionEval.js +59 -0
- package/dist/models/evaluations/textSimilaryPrompt.d.ts +1 -1
- package/dist/models/evaluations/textSimilaryPrompt.js +1 -1
- package/dist/models/evaluations/types.d.ts +7 -6
- package/dist/models/types.d.ts +19 -1
- package/dist/session/Agent.d.ts +173 -0
- package/dist/session/Agent.js +548 -0
- package/dist/{loadAssistantFromAPI.d.ts → session/AsyncQueue.d.ts} +12 -7
- package/dist/session/AsyncQueue.js +67 -0
- package/dist/{machine/guards/index.d.ts → session/config.d.ts} +2 -2
- package/dist/session/config.js +27 -0
- package/dist/session/createAutopilot.d.ts +48 -0
- package/dist/session/createAutopilot.js +151 -0
- package/dist/session/hosted.d.ts +454 -0
- package/dist/session/hosted.js +501 -0
- package/dist/{assistants → session}/index.d.ts +11 -2
- package/dist/{machine/actors → session}/index.js +11 -3
- package/dist/{machine/actions/appendSpeech.js → session/knowledge.d.ts} +14 -17
- package/dist/session/knowledge.js +10 -0
- package/dist/session/llm.d.ts +113 -0
- package/dist/session/llm.js +127 -0
- package/dist/session/machine.d.ts +206 -0
- package/dist/session/machine.js +126 -0
- package/dist/session/main.js +45 -0
- package/dist/session/meteredThink.d.ts +45 -0
- package/dist/session/meteredThink.js +125 -0
- package/dist/session/sentences.d.ts +5 -0
- package/dist/session/sentences.js +53 -0
- package/dist/session/telemetry.d.ts +34 -0
- package/dist/session/telemetry.js +55 -0
- package/dist/{machine/actors/index.d.ts → session/think.d.ts} +2 -3
- package/dist/{machine/actions/announceSystemError.js → session/think.js} +8 -10
- package/dist/session/tools.d.ts +22 -0
- package/dist/session/tools.js +83 -0
- package/dist/tools/builtin/transferToolDefinition.js +1 -1
- package/dist/voice/index.d.ts +0 -1
- package/dist/voice/index.js +0 -1
- package/dist/voice/types.d.ts +5 -18
- package/package.json +15 -16
- package/dist/Autopilot.d.ts +0 -14
- package/dist/Autopilot.js +0 -133
- package/dist/assistants/index.js +0 -36
- package/dist/assistants/loadAndValidateAssistant.d.ts +0 -3
- package/dist/assistants/loadAndValidateAssistant.js +0 -49
- package/dist/assistants/types.d.ts +0 -24
- package/dist/assistants/types.js +0 -2
- package/dist/envs.d.ts +0 -15
- package/dist/envs.js +0 -78
- package/dist/handleVoiceRequest.d.ts +0 -3
- package/dist/handleVoiceRequest.js +0 -167
- package/dist/loadAssistantConfigFromFile.d.ts +0 -3
- package/dist/loadAssistantConfigFromFile.js +0 -68
- package/dist/loadAssistantFromAPI.js +0 -98
- package/dist/machine/actions/announceSystemError.d.ts +0 -4
- package/dist/machine/actions/appendSpeech.d.ts +0 -1
- package/dist/machine/actions/cleanSpeech.d.ts +0 -1
- package/dist/machine/actions/cleanSpeech.js +0 -23
- package/dist/machine/actions/goodbye.d.ts +0 -4
- package/dist/machine/actions/goodbye.js +0 -31
- package/dist/machine/actions/increaseIdleTimeoutCount.d.ts +0 -1
- package/dist/machine/actions/increaseIdleTimeoutCount.js +0 -31
- package/dist/machine/actions/index.d.ts +0 -26
- package/dist/machine/actions/index.js +0 -37
- package/dist/machine/actions/interruptPlayback.d.ts +0 -4
- package/dist/machine/actions/interruptPlayback.js +0 -43
- package/dist/machine/actions/resetIdleTimeoutCount.d.ts +0 -1
- package/dist/machine/actions/resetIdleTimeoutCount.js +0 -31
- package/dist/machine/actions/resetState.d.ts +0 -1
- package/dist/machine/actions/resetState.js +0 -32
- package/dist/machine/actors/doAnnounceIdleTimeout.d.ts +0 -4
- package/dist/machine/actors/doAnnounceIdleTimeout.js +0 -41
- package/dist/machine/actors/doGreetUser.d.ts +0 -4
- package/dist/machine/actors/doGreetUser.js +0 -45
- package/dist/machine/actors/doProcessUserRequest.d.ts +0 -4
- package/dist/machine/actors/doProcessUserRequest.js +0 -75
- package/dist/machine/context.d.ts +0 -52
- package/dist/machine/context.js +0 -28
- package/dist/machine/delays.d.ts +0 -30
- package/dist/machine/delays.js +0 -37
- package/dist/machine/guards/hasSpeechResult.d.ts +0 -4
- package/dist/machine/guards/hasSpeechResult.js +0 -30
- package/dist/machine/guards/idleTimeoutCountExceedsMax.d.ts +0 -4
- package/dist/machine/guards/idleTimeoutCountExceedsMax.js +0 -31
- package/dist/machine/guards/index.js +0 -25
- package/dist/machine/index.d.ts +0 -19
- package/dist/machine/index.js +0 -23
- package/dist/machine/machine.d.ts +0 -408
- package/dist/machine/machine.js +0 -206
- package/dist/machine/setup.d.ts +0 -328
- package/dist/machine/setup.js +0 -116
- package/dist/machine/types.d.ts +0 -54
- package/dist/machine/types.js +0 -2
- package/dist/sendConversationEndedEvent.d.ts +0 -32
- package/dist/sendConversationEndedEvent.js +0 -66
- package/dist/sendConversationStartedEvent.d.ts +0 -6
- package/dist/sendConversationStartedEvent.js +0 -63
- package/dist/server.d.ts +0 -2
- package/dist/server.js +0 -25
- package/dist/types.d.ts +0 -40
- package/dist/types.js +0 -8
- package/dist/vad/SileroVad.d.ts +0 -18
- package/dist/vad/SileroVad.js +0 -40
- package/dist/vad/SileroVadModel.d.ts +0 -14
- package/dist/vad/SileroVadModel.js +0 -83
- package/dist/vad/chunkToFloat32Array.d.ts +0 -20
- package/dist/vad/chunkToFloat32Array.js +0 -34
- package/dist/vad/createVad.d.ts +0 -3
- package/dist/vad/createVad.js +0 -126
- package/dist/vad/types.d.ts +0 -60
- package/dist/vad/types.js +0 -2
- package/dist/vadWorker.js +0 -36
- package/dist/voice/Voice.d.ts +0 -61
- package/dist/voice/Voice.js +0 -96
- package/dist/voiceServerSetup.d.ts +0 -2
- package/dist/voiceServerSetup.js +0 -29
- /package/dist/{vadWorker.d.ts → session/main.d.ts} +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DRAIN_DEADLINE_MS = void 0;
|
|
4
|
+
exports.usageLines = usageLines;
|
|
5
|
+
exports.meteredThink = meteredThink;
|
|
6
|
+
/** How long an interrupted reply is read in the background for its usage report (design D6). */
|
|
7
|
+
exports.DRAIN_DEADLINE_MS = 30000;
|
|
8
|
+
const abortError = () => {
|
|
9
|
+
const e = new Error("aborted");
|
|
10
|
+
e.name = "AbortError";
|
|
11
|
+
return e;
|
|
12
|
+
};
|
|
13
|
+
/** Resolves like `p`, or rejects with an AbortError as soon as `signal` aborts. */
|
|
14
|
+
function raceAbort(p, signal) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const onAbort = () => reject(abortError());
|
|
17
|
+
if (signal.aborted)
|
|
18
|
+
return onAbort();
|
|
19
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
20
|
+
p.then((v) => {
|
|
21
|
+
signal.removeEventListener("abort", onAbort);
|
|
22
|
+
resolve(v);
|
|
23
|
+
}, (e) => {
|
|
24
|
+
signal.removeEventListener("abort", onAbort);
|
|
25
|
+
reject(e);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function usageLines(model, usage) {
|
|
30
|
+
const key = {
|
|
31
|
+
provider: model.catalogId.split("/")[0],
|
|
32
|
+
model: model.catalogId,
|
|
33
|
+
keySource: model.keySource
|
|
34
|
+
};
|
|
35
|
+
const lines = [
|
|
36
|
+
{ meter: "llm.tokens.in", quantity: usage.inputTokens, ...key },
|
|
37
|
+
{ meter: "llm.tokens.out", quantity: usage.outputTokens, ...key }
|
|
38
|
+
];
|
|
39
|
+
if (usage.cachedTokens > 0)
|
|
40
|
+
lines.push({
|
|
41
|
+
meter: "llm.tokens.cached",
|
|
42
|
+
quantity: usage.cachedTokens,
|
|
43
|
+
...key
|
|
44
|
+
});
|
|
45
|
+
return lines;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A Think that meters its model (add-usage-metering D6). Chunks pass through; the vendor's usage
|
|
49
|
+
* chunk is reported, never forwarded. When the caller stops reading (barge-in, a newer turn), the
|
|
50
|
+
* stream ends for the caller at once but keeps being read in the background, so the vendor's usage
|
|
51
|
+
* for the whole request still arrives; after the deadline, or when `closed` aborts (the session
|
|
52
|
+
* ended), the request is reported as missing usage. A request the vendor failed reports nothing.
|
|
53
|
+
*/
|
|
54
|
+
function meteredThink(inner, model, sink, options = {}) {
|
|
55
|
+
const settle = (usage) => usage
|
|
56
|
+
? sink.usage(usageLines(model, usage))
|
|
57
|
+
: sink.missing(model.catalogId);
|
|
58
|
+
return {
|
|
59
|
+
async *stream(messages, tools, signal) {
|
|
60
|
+
const request = new AbortController();
|
|
61
|
+
const stopRequest = () => request.abort();
|
|
62
|
+
options.closed?.addEventListener("abort", stopRequest, { once: true });
|
|
63
|
+
const it = inner
|
|
64
|
+
.stream(messages, tools, request.signal)[Symbol.asyncIterator]();
|
|
65
|
+
let usage;
|
|
66
|
+
let pending;
|
|
67
|
+
let state = "reading";
|
|
68
|
+
const done = () => options.closed?.removeEventListener("abort", stopRequest);
|
|
69
|
+
const drain = async () => {
|
|
70
|
+
const deadline = setTimeout(stopRequest, options.drainMs ?? exports.DRAIN_DEADLINE_MS);
|
|
71
|
+
try {
|
|
72
|
+
for (;;) {
|
|
73
|
+
const r = await (pending ?? it.next());
|
|
74
|
+
pending = undefined;
|
|
75
|
+
if (r.done)
|
|
76
|
+
break;
|
|
77
|
+
if (r.value.type === "usage")
|
|
78
|
+
usage = r.value.usage;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// Cut by the deadline or the session's end: whatever arrived is all there is.
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
clearTimeout(deadline);
|
|
86
|
+
done();
|
|
87
|
+
}
|
|
88
|
+
settle(usage);
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
for (;;) {
|
|
92
|
+
pending = it.next();
|
|
93
|
+
pending.catch(() => undefined);
|
|
94
|
+
const r = await raceAbort(pending, signal);
|
|
95
|
+
pending = undefined;
|
|
96
|
+
if (r.done) {
|
|
97
|
+
state = "done";
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (r.value.type === "usage")
|
|
101
|
+
usage = r.value.usage;
|
|
102
|
+
else
|
|
103
|
+
yield r.value;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
if (!signal.aborted)
|
|
108
|
+
state = "failed";
|
|
109
|
+
throw e;
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
if (state === "done") {
|
|
113
|
+
done();
|
|
114
|
+
settle(usage);
|
|
115
|
+
}
|
|
116
|
+
else if (state === "failed") {
|
|
117
|
+
done();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
void drain();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Groups streamed tokens into sentence-sized pieces, so each speak piece is a natural unit for TTS
|
|
3
|
+
* while the first sentence still starts before the reply is complete (rework-autopilot A5).
|
|
4
|
+
*/
|
|
5
|
+
export declare function sentences(tokens: AsyncIterable<string>): AsyncIterable<string>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sentences = sentences;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/fonoster
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Fonoster
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const SENTENCE_END = /[.!?](["')\]]*)\s+/;
|
|
23
|
+
const MAX_PIECE = 160;
|
|
24
|
+
/**
|
|
25
|
+
* Groups streamed tokens into sentence-sized pieces, so each speak piece is a natural unit for TTS
|
|
26
|
+
* while the first sentence still starts before the reply is complete (rework-autopilot A5).
|
|
27
|
+
*/
|
|
28
|
+
async function* sentences(tokens) {
|
|
29
|
+
let buffer = "";
|
|
30
|
+
for await (const token of tokens) {
|
|
31
|
+
buffer += token;
|
|
32
|
+
for (;;) {
|
|
33
|
+
const m = SENTENCE_END.exec(buffer);
|
|
34
|
+
if (m) {
|
|
35
|
+
const end = m.index + m[0].length;
|
|
36
|
+
yield buffer.slice(0, end);
|
|
37
|
+
buffer = buffer.slice(end);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (buffer.length > MAX_PIECE) {
|
|
41
|
+
const cut = buffer.lastIndexOf(" ", MAX_PIECE);
|
|
42
|
+
if (cut > 0) {
|
|
43
|
+
yield buffer.slice(0, cut + 1);
|
|
44
|
+
buffer = buffer.slice(cut + 1);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (buffer.trim())
|
|
52
|
+
yield buffer;
|
|
53
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
3
|
+
* http://github.com/fonoster/fonoster
|
|
4
|
+
*
|
|
5
|
+
* This file is part of Fonoster
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the MIT License (the "License");
|
|
8
|
+
* you may not use this file except in compliance with
|
|
9
|
+
* the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* https://opensource.org/licenses/MIT
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { Telemetry, TelemetryConfig } from "@fonoster/common";
|
|
20
|
+
/**
|
|
21
|
+
* Autopilot's telemetry: a stable handle (like AppBridge's) that delegates to what
|
|
22
|
+
* `startTelemetry`/`setTelemetry` installed. OTLP when an endpoint is configured
|
|
23
|
+
* (telemetry.otlpEndpoint or OTEL_EXPORTER_OTLP_*), a no-op otherwise.
|
|
24
|
+
*
|
|
25
|
+
* Spans: autopilot.session (child of AppBridge's call span, via session.start `traceparent`),
|
|
26
|
+
* autopilot.turn (STT final to the end of the reply) and autopilot.llm.request. Metrics:
|
|
27
|
+
* fonoster.autopilot.turns, fonoster.autopilot.llm.requests and fonoster.autopilot.llm.latency_ms
|
|
28
|
+
* (the sum of the time to the first token; divide by requests for the mean).
|
|
29
|
+
*/
|
|
30
|
+
export declare const telemetry: Telemetry;
|
|
31
|
+
/** Installs a telemetry implementation (tests). */
|
|
32
|
+
export declare function setTelemetry(t: Telemetry): void;
|
|
33
|
+
/** Starts telemetry with the config's endpoint, once the config is loaded. */
|
|
34
|
+
export declare function startTelemetry(config: TelemetryConfig): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.telemetry = void 0;
|
|
4
|
+
exports.setTelemetry = setTelemetry;
|
|
5
|
+
exports.startTelemetry = startTelemetry;
|
|
6
|
+
/**
|
|
7
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
8
|
+
* http://github.com/fonoster/fonoster
|
|
9
|
+
*
|
|
10
|
+
* This file is part of Fonoster
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the MIT License (the "License");
|
|
13
|
+
* you may not use this file except in compliance with
|
|
14
|
+
* the License. You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* https://opensource.org/licenses/MIT
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
const common_1 = require("@fonoster/common");
|
|
25
|
+
let impl = (0, common_1.initTelemetry)("fonoster-autopilot");
|
|
26
|
+
/**
|
|
27
|
+
* Autopilot's telemetry: a stable handle (like AppBridge's) that delegates to what
|
|
28
|
+
* `startTelemetry`/`setTelemetry` installed. OTLP when an endpoint is configured
|
|
29
|
+
* (telemetry.otlpEndpoint or OTEL_EXPORTER_OTLP_*), a no-op otherwise.
|
|
30
|
+
*
|
|
31
|
+
* Spans: autopilot.session (child of AppBridge's call span, via session.start `traceparent`),
|
|
32
|
+
* autopilot.turn (STT final to the end of the reply) and autopilot.llm.request. Metrics:
|
|
33
|
+
* fonoster.autopilot.turns, fonoster.autopilot.llm.requests and fonoster.autopilot.llm.latency_ms
|
|
34
|
+
* (the sum of the time to the first token; divide by requests for the mean).
|
|
35
|
+
*/
|
|
36
|
+
exports.telemetry = {
|
|
37
|
+
get enabled() {
|
|
38
|
+
return impl.enabled;
|
|
39
|
+
},
|
|
40
|
+
startCall: (...a) => impl.startCall(...a),
|
|
41
|
+
startSpan: (...a) => impl.startSpan(...a),
|
|
42
|
+
traceparent: (...a) => impl.traceparent(...a),
|
|
43
|
+
log: (...a) => impl.log(...a),
|
|
44
|
+
count: (...a) => impl.count(...a),
|
|
45
|
+
gauge: (...a) => impl.gauge(...a),
|
|
46
|
+
shutdown: () => impl.shutdown()
|
|
47
|
+
};
|
|
48
|
+
/** Installs a telemetry implementation (tests). */
|
|
49
|
+
function setTelemetry(t) {
|
|
50
|
+
impl = t;
|
|
51
|
+
}
|
|
52
|
+
/** Starts telemetry with the config's endpoint, once the config is loaded. */
|
|
53
|
+
function startTelemetry(config) {
|
|
54
|
+
impl = (0, common_1.initTelemetry)("fonoster-autopilot", undefined, (0, common_1.telemetryEnv)(config));
|
|
55
|
+
}
|
|
@@ -16,6 +16,5 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export * from "./doAnnounceIdleTimeout";
|
|
19
|
+
export { ChatMessage, Think, ThinkChunk, ThinkError, ThinkProvider, ToolCall, ToolSpec } from "@fonoster/community";
|
|
20
|
+
export { OpenAiCompatibleThink, resolveThink } from "@fonoster/community/openai";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolveThink = exports.OpenAiCompatibleThink = exports.ThinkError = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/fonoster
|
|
@@ -19,12 +19,10 @@ exports.announceSystemError = void 0;
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
exports.announceSystemError = announceSystemError;
|
|
22
|
+
// The LLM adapter interface and the OpenAI-compatible adapter live in @fonoster/community with
|
|
23
|
+
// the other vendor adapters (registry 3.1).
|
|
24
|
+
var community_1 = require("@fonoster/community");
|
|
25
|
+
Object.defineProperty(exports, "ThinkError", { enumerable: true, get: function () { return community_1.ThinkError; } });
|
|
26
|
+
var openai_1 = require("@fonoster/community/openai");
|
|
27
|
+
Object.defineProperty(exports, "OpenAiCompatibleThink", { enumerable: true, get: function () { return openai_1.OpenAiCompatibleThink; } });
|
|
28
|
+
Object.defineProperty(exports, "resolveThink", { enumerable: true, get: function () { return openai_1.resolveThink; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DestinationPolicy } from "@fonoster/common";
|
|
2
|
+
import { ToolDefinition } from "./config";
|
|
3
|
+
export type ToolOutcome = {
|
|
4
|
+
ok: boolean;
|
|
5
|
+
result?: unknown;
|
|
6
|
+
error?: string;
|
|
7
|
+
};
|
|
8
|
+
/** The tool port (rework-autopilot A7): one operation, run a tool with inputs. */
|
|
9
|
+
export interface ToolPort {
|
|
10
|
+
run(name: string, args: Record<string, unknown>, signal: AbortSignal): Promise<ToolOutcome>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* HTTP tools from the agent config (`operation.method`, `url`, `headers`). Tool URLs are
|
|
14
|
+
* tenant input: they go through safeFetch (public destinations only, redirects re-checked,
|
|
15
|
+
* 10 s timeout; RV-B2).
|
|
16
|
+
*/
|
|
17
|
+
export declare class HttpToolPort implements ToolPort {
|
|
18
|
+
private readonly tools;
|
|
19
|
+
private readonly policy?;
|
|
20
|
+
constructor(tools: ToolDefinition[], policy?: DestinationPolicy);
|
|
21
|
+
run(name: string, args: Record<string, unknown>, signal: AbortSignal): Promise<ToolOutcome>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpToolPort = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/fonoster
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Fonoster
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const url_1 = require("url");
|
|
23
|
+
const common_1 = require("@fonoster/common");
|
|
24
|
+
/**
|
|
25
|
+
* HTTP tools from the agent config (`operation.method`, `url`, `headers`). Tool URLs are
|
|
26
|
+
* tenant input: they go through safeFetch (public destinations only, redirects re-checked,
|
|
27
|
+
* 10 s timeout; RV-B2).
|
|
28
|
+
*/
|
|
29
|
+
class HttpToolPort {
|
|
30
|
+
constructor(tools, policy) {
|
|
31
|
+
this.tools = tools;
|
|
32
|
+
this.policy = policy;
|
|
33
|
+
}
|
|
34
|
+
async run(name, args, signal) {
|
|
35
|
+
const tool = this.tools.find((t) => t.name === name);
|
|
36
|
+
if (!tool)
|
|
37
|
+
return { ok: false, error: `unknown tool ${name}` };
|
|
38
|
+
const method = String(tool.operation.method ?? "get").toUpperCase();
|
|
39
|
+
const url = new url_1.URL(tool.operation.url);
|
|
40
|
+
let body;
|
|
41
|
+
if (method === "GET") {
|
|
42
|
+
for (const [k, v] of Object.entries(args))
|
|
43
|
+
url.searchParams.set(k, String(v));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
body = JSON.stringify(args);
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const request = (0, common_1.safeFetch)(url, {
|
|
50
|
+
method,
|
|
51
|
+
headers: {
|
|
52
|
+
accept: "application/json",
|
|
53
|
+
"content-type": "application/json",
|
|
54
|
+
...(tool.operation.headers ?? {})
|
|
55
|
+
},
|
|
56
|
+
body,
|
|
57
|
+
signal,
|
|
58
|
+
policy: this.policy?.allow ? this.policy : undefined
|
|
59
|
+
});
|
|
60
|
+
if (tool.operation.waitForResponse === false) {
|
|
61
|
+
request.catch(() => undefined);
|
|
62
|
+
return { ok: true, result: { status: "sent" } };
|
|
63
|
+
}
|
|
64
|
+
const res = await request;
|
|
65
|
+
const text = await res.text();
|
|
66
|
+
if (!res.ok)
|
|
67
|
+
return {
|
|
68
|
+
ok: false,
|
|
69
|
+
error: `HTTP ${res.status}: ${text.slice(0, 200)}`
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
return { ok: true, result: JSON.parse(text) };
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return { ok: true, result: text };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
return { ok: false, error: e.message };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.HttpToolPort = HttpToolPort;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transferToolDefinition = void 0;
|
|
4
4
|
const transferToolDefinition = {
|
|
5
5
|
name: "transfer",
|
|
6
|
-
description: "Transfer the call to a
|
|
6
|
+
description: "Transfer the call to an operator (a person)",
|
|
7
7
|
parameters: {
|
|
8
8
|
type: "object",
|
|
9
9
|
properties: {
|
package/dist/voice/index.d.ts
CHANGED
package/dist/voice/index.js
CHANGED
|
@@ -32,5 +32,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
* See the License for the specific language governing permissions and
|
|
33
33
|
* limitations under the License.
|
|
34
34
|
*/
|
|
35
|
-
__exportStar(require("./Voice"), exports);
|
|
36
35
|
__exportStar(require("./types"), exports);
|
package/dist/voice/types.d.ts
CHANGED
|
@@ -16,33 +16,20 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
import { AudioFilterConfig } from "@fonoster/common";
|
|
20
|
-
type GatherStream = {
|
|
21
|
-
stop: () => Promise<void>;
|
|
22
|
-
onData: (cb: (payload: {
|
|
23
|
-
speech: string;
|
|
24
|
-
responseTime: number;
|
|
25
|
-
}) => void) => void;
|
|
26
|
-
};
|
|
27
|
-
type Stream = {
|
|
28
|
-
stop: () => Promise<void>;
|
|
29
|
-
onData: (cb: (chunk: Uint8Array) => void) => void;
|
|
30
|
-
};
|
|
31
19
|
type TransferOptions = {
|
|
32
20
|
timeout?: number;
|
|
33
21
|
record?: boolean;
|
|
34
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* The call controls the LangChain models' built-in tools (hangup, transfer) use. Only the
|
|
25
|
+
* evaluations (createEvaluateIntelligence) drive these models now, with a stand-in; the hosted
|
|
26
|
+
* engine in ../session talks to the session SDK instead.
|
|
27
|
+
*/
|
|
35
28
|
type Voice = {
|
|
36
|
-
mediaSessionRef: string;
|
|
37
29
|
answer: () => Promise<void>;
|
|
38
|
-
setAudioFilters: (filters: AudioFilterConfig[]) => Promise<void>;
|
|
39
30
|
hangup: () => Promise<void>;
|
|
40
31
|
say: (text: string) => Promise<void>;
|
|
41
32
|
playDtmf: (dtmf: string) => Promise<void>;
|
|
42
|
-
sgather: () => Promise<GatherStream>;
|
|
43
33
|
transfer: (destination: string, options?: TransferOptions) => Promise<void>;
|
|
44
|
-
stream: () => Promise<Stream>;
|
|
45
|
-
stopSpeech: () => Promise<void>;
|
|
46
|
-
stopStreams: () => Promise<void>;
|
|
47
34
|
};
|
|
48
35
|
export { TransferOptions, Voice };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/autopilot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Voice AI for the Fonoster platform",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -14,13 +14,11 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
|
|
16
16
|
"build": "tsc -b tsconfig.json",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"start:dev": "nodemon --exec tsx --watch src src/server.ts"
|
|
17
|
+
"generate:readme": "fonoster-readme",
|
|
18
|
+
"start:hosted": "node dist/session/main.js"
|
|
20
19
|
},
|
|
21
20
|
"files": [
|
|
22
|
-
"dist"
|
|
23
|
-
"silero_vad.onnx"
|
|
21
|
+
"dist"
|
|
24
22
|
],
|
|
25
23
|
"publishConfig": {
|
|
26
24
|
"access": "public"
|
|
@@ -35,11 +33,12 @@
|
|
|
35
33
|
"dependencies": {
|
|
36
34
|
"@aws-sdk/client-s3": "^3.958.0",
|
|
37
35
|
"@dmitryrechkin/json-schema-to-zod": "^1.0.1",
|
|
38
|
-
"@fonoster/common": "^0.
|
|
39
|
-
"@fonoster/
|
|
40
|
-
"@fonoster/
|
|
41
|
-
"@fonoster/types": "^0.
|
|
42
|
-
"@fonoster/voice": "^0.
|
|
36
|
+
"@fonoster/common": "^0.31.0",
|
|
37
|
+
"@fonoster/community": "^0.31.0",
|
|
38
|
+
"@fonoster/logger": "^0.31.0",
|
|
39
|
+
"@fonoster/types": "^0.31.0",
|
|
40
|
+
"@fonoster/voice": "^0.31.0",
|
|
41
|
+
"@grpc/grpc-js": "~1.14.6",
|
|
43
42
|
"@langchain/anthropic": "^1.3.3",
|
|
44
43
|
"@langchain/community": "^1.1.1",
|
|
45
44
|
"@langchain/core": "^1.1.8",
|
|
@@ -49,15 +48,15 @@
|
|
|
49
48
|
"@langchain/openai": "^1.2.0",
|
|
50
49
|
"@langchain/textsplitters": "^1.0.1",
|
|
51
50
|
"cheerio": "^1.1.2",
|
|
52
|
-
"dotenv": "^16.6.1",
|
|
53
51
|
"js-yaml": "^4.1.1",
|
|
54
52
|
"langchain": "^1.2.3",
|
|
55
|
-
"moment": "^2.30.1",
|
|
56
|
-
"onnxruntime-node": "1.21.1",
|
|
57
53
|
"pdf-parse": "^1.1.1",
|
|
58
|
-
"
|
|
54
|
+
"undici": "^7.30.1",
|
|
59
55
|
"xstate": "^5.17.3",
|
|
60
56
|
"zod": "^3.25.76"
|
|
61
57
|
},
|
|
62
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "f0a5102dddeea0f70f659234108805bc10690f2e",
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"yaml": "^2.9.0"
|
|
61
|
+
}
|
|
63
62
|
}
|
package/dist/Autopilot.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AutopilotParams } from "./types";
|
|
2
|
-
declare class Autopilot {
|
|
3
|
-
private readonly params;
|
|
4
|
-
private readonly actor;
|
|
5
|
-
private vad;
|
|
6
|
-
constructor(params: AutopilotParams);
|
|
7
|
-
start(): Promise<void>;
|
|
8
|
-
stop(): void;
|
|
9
|
-
private setupAudioFilters;
|
|
10
|
-
private setupVoiceStream;
|
|
11
|
-
private handleVoicePayload;
|
|
12
|
-
private setupSpeechGathering;
|
|
13
|
-
}
|
|
14
|
-
export { Autopilot };
|