@fonoster/autopilot 0.27.0 → 0.30.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.
Files changed (138) hide show
  1. package/README.md +14 -51
  2. package/dist/index.d.ts +0 -5
  3. package/dist/index.js +0 -5
  4. package/dist/knowledge/AbstractKnowledgeBase.d.ts +3 -2
  5. package/dist/knowledge/AbstractKnowledgeBase.js +2 -7
  6. package/dist/knowledge/FilesKnowledgeBase.d.ts +1 -1
  7. package/dist/knowledge/types.d.ts +1 -1
  8. package/dist/models/LanguageModelFactory.d.ts +5 -24
  9. package/dist/models/LanguageModelFactory.js +0 -1
  10. package/dist/models/createLanguageModel.d.ts +2 -2
  11. package/dist/models/evaluations/createEvalEffectiveConfig.d.ts +10 -106
  12. package/dist/models/evaluations/createEvalEffectiveConfig.js +47 -7
  13. package/dist/models/evaluations/createEvaluateIntelligence.d.ts +10 -20
  14. package/dist/models/evaluations/createEvaluateIntelligence.js +32 -23
  15. package/dist/models/evaluations/evalTestCases.d.ts +2 -2
  16. package/dist/models/evaluations/extractAiResponse.d.ts +2 -3
  17. package/dist/models/evaluations/index.d.ts +1 -0
  18. package/dist/models/evaluations/index.js +1 -0
  19. package/dist/models/evaluations/runEval.d.ts +2 -20
  20. package/dist/models/evaluations/session/EvalSession.d.ts +73 -0
  21. package/dist/models/evaluations/session/EvalSession.js +134 -0
  22. package/dist/models/evaluations/session/evaluateSessionScenario.d.ts +58 -0
  23. package/dist/models/evaluations/session/evaluateSessionScenario.js +182 -0
  24. package/dist/{vad → models/evaluations/session}/index.d.ts +3 -2
  25. package/dist/{vad → models/evaluations/session}/index.js +3 -2
  26. package/dist/models/evaluations/session/runSessionEval.d.ts +17 -0
  27. package/dist/models/evaluations/session/runSessionEval.js +59 -0
  28. package/dist/models/evaluations/types.d.ts +7 -6
  29. package/dist/models/types.d.ts +19 -1
  30. package/dist/session/Agent.d.ts +138 -0
  31. package/dist/session/Agent.js +474 -0
  32. package/dist/{loadAssistantFromAPI.d.ts → session/AsyncQueue.d.ts} +12 -7
  33. package/dist/session/AsyncQueue.js +67 -0
  34. package/dist/{machine/guards/index.d.ts → session/config.d.ts} +2 -2
  35. package/dist/session/config.js +27 -0
  36. package/dist/session/convertLegacyAssistant.d.ts +77 -0
  37. package/dist/session/convertLegacyAssistant.js +118 -0
  38. package/dist/session/createAutopilot.d.ts +47 -0
  39. package/dist/session/createAutopilot.js +119 -0
  40. package/dist/session/hosted.d.ts +456 -0
  41. package/dist/session/hosted.js +506 -0
  42. package/dist/{assistants → session}/index.d.ts +11 -2
  43. package/dist/{machine/actors → session}/index.js +11 -3
  44. package/dist/{machine/actions/appendSpeech.js → session/knowledge.d.ts} +14 -17
  45. package/dist/session/knowledge.js +10 -0
  46. package/dist/session/llm.d.ts +86 -0
  47. package/dist/session/llm.js +83 -0
  48. package/dist/session/machine.d.ts +206 -0
  49. package/dist/session/machine.js +126 -0
  50. package/dist/session/main.js +44 -0
  51. package/dist/session/sentences.d.ts +5 -0
  52. package/dist/session/sentences.js +53 -0
  53. package/dist/{machine/actors/index.d.ts → session/think.d.ts} +2 -3
  54. package/dist/{machine/actions/announceSystemError.js → session/think.js} +8 -10
  55. package/dist/session/tools.d.ts +22 -0
  56. package/dist/session/tools.js +83 -0
  57. package/dist/tools/builtin/transferToolDefinition.js +1 -1
  58. package/dist/voice/index.d.ts +0 -1
  59. package/dist/voice/index.js +0 -1
  60. package/dist/voice/types.d.ts +5 -18
  61. package/package.json +13 -14
  62. package/dist/Autopilot.d.ts +0 -14
  63. package/dist/Autopilot.js +0 -133
  64. package/dist/assistants/index.js +0 -36
  65. package/dist/assistants/loadAndValidateAssistant.d.ts +0 -3
  66. package/dist/assistants/loadAndValidateAssistant.js +0 -49
  67. package/dist/assistants/types.d.ts +0 -24
  68. package/dist/assistants/types.js +0 -2
  69. package/dist/envs.d.ts +0 -15
  70. package/dist/envs.js +0 -78
  71. package/dist/handleVoiceRequest.d.ts +0 -3
  72. package/dist/handleVoiceRequest.js +0 -167
  73. package/dist/loadAssistantConfigFromFile.d.ts +0 -3
  74. package/dist/loadAssistantConfigFromFile.js +0 -68
  75. package/dist/loadAssistantFromAPI.js +0 -98
  76. package/dist/machine/actions/announceSystemError.d.ts +0 -4
  77. package/dist/machine/actions/appendSpeech.d.ts +0 -1
  78. package/dist/machine/actions/cleanSpeech.d.ts +0 -1
  79. package/dist/machine/actions/cleanSpeech.js +0 -23
  80. package/dist/machine/actions/goodbye.d.ts +0 -4
  81. package/dist/machine/actions/goodbye.js +0 -31
  82. package/dist/machine/actions/increaseIdleTimeoutCount.d.ts +0 -1
  83. package/dist/machine/actions/increaseIdleTimeoutCount.js +0 -31
  84. package/dist/machine/actions/index.d.ts +0 -26
  85. package/dist/machine/actions/index.js +0 -37
  86. package/dist/machine/actions/interruptPlayback.d.ts +0 -4
  87. package/dist/machine/actions/interruptPlayback.js +0 -43
  88. package/dist/machine/actions/resetIdleTimeoutCount.d.ts +0 -1
  89. package/dist/machine/actions/resetIdleTimeoutCount.js +0 -31
  90. package/dist/machine/actions/resetState.d.ts +0 -1
  91. package/dist/machine/actions/resetState.js +0 -32
  92. package/dist/machine/actors/doAnnounceIdleTimeout.d.ts +0 -4
  93. package/dist/machine/actors/doAnnounceIdleTimeout.js +0 -41
  94. package/dist/machine/actors/doGreetUser.d.ts +0 -4
  95. package/dist/machine/actors/doGreetUser.js +0 -45
  96. package/dist/machine/actors/doProcessUserRequest.d.ts +0 -4
  97. package/dist/machine/actors/doProcessUserRequest.js +0 -75
  98. package/dist/machine/context.d.ts +0 -52
  99. package/dist/machine/context.js +0 -28
  100. package/dist/machine/delays.d.ts +0 -30
  101. package/dist/machine/delays.js +0 -37
  102. package/dist/machine/guards/hasSpeechResult.d.ts +0 -4
  103. package/dist/machine/guards/hasSpeechResult.js +0 -30
  104. package/dist/machine/guards/idleTimeoutCountExceedsMax.d.ts +0 -4
  105. package/dist/machine/guards/idleTimeoutCountExceedsMax.js +0 -31
  106. package/dist/machine/guards/index.js +0 -25
  107. package/dist/machine/index.d.ts +0 -19
  108. package/dist/machine/index.js +0 -23
  109. package/dist/machine/machine.d.ts +0 -408
  110. package/dist/machine/machine.js +0 -206
  111. package/dist/machine/setup.d.ts +0 -328
  112. package/dist/machine/setup.js +0 -116
  113. package/dist/machine/types.d.ts +0 -54
  114. package/dist/machine/types.js +0 -2
  115. package/dist/sendConversationEndedEvent.d.ts +0 -32
  116. package/dist/sendConversationEndedEvent.js +0 -66
  117. package/dist/sendConversationStartedEvent.d.ts +0 -6
  118. package/dist/sendConversationStartedEvent.js +0 -63
  119. package/dist/server.d.ts +0 -2
  120. package/dist/server.js +0 -25
  121. package/dist/types.d.ts +0 -40
  122. package/dist/types.js +0 -8
  123. package/dist/vad/SileroVad.d.ts +0 -18
  124. package/dist/vad/SileroVad.js +0 -40
  125. package/dist/vad/SileroVadModel.d.ts +0 -14
  126. package/dist/vad/SileroVadModel.js +0 -83
  127. package/dist/vad/chunkToFloat32Array.d.ts +0 -20
  128. package/dist/vad/chunkToFloat32Array.js +0 -34
  129. package/dist/vad/createVad.d.ts +0 -3
  130. package/dist/vad/createVad.js +0 -126
  131. package/dist/vad/types.d.ts +0 -60
  132. package/dist/vad/types.js +0 -2
  133. package/dist/vadWorker.js +0 -36
  134. package/dist/voice/Voice.d.ts +0 -61
  135. package/dist/voice/Voice.js +0 -96
  136. package/dist/voiceServerSetup.d.ts +0 -2
  137. package/dist/voiceServerSetup.js +0 -29
  138. /package/dist/{vadWorker.d.ts → session/main.d.ts} +0 -0
package/README.md CHANGED
@@ -12,15 +12,19 @@ The autopilot module provides a way to create Voice AI applications in Fonoster.
12
12
  * [Example](#example)
13
13
  * [Adding Knowledge Base](#configuring-the-knowledge-base)
14
14
  * [Adding Tools](#configuring-the-tools)
15
- * [What's Next](#whats-next)
16
15
 
17
16
  ## Installation
18
17
 
18
+ Autopilot is an ordinary session app that the VoiceSessionGateway dials. Run the
19
+ `fonoster/autopilot` image (built from `mods/autopilot/Dockerfile`), or from the repository:
20
+
19
21
  ```sh-session
20
- $ npm install -g @fonoster/autopilot
22
+ $ cp config/autopilot-session.example.yaml config/autopilot-session.yaml
23
+ $ node mods/autopilot/dist/session/main.js --config config/autopilot-session.yaml
21
24
  ```
22
25
 
23
- The previous command will install the module globally.
26
+ See [docs/autopilot.md](../../docs/autopilot.md) for the engine, pacing and the assistant
27
+ schema.
24
28
 
25
29
  ## Example
26
30
 
@@ -179,53 +183,12 @@ For example:
179
183
  { "result": "The available appointment times are 9:00 AM, 10:00 AM, and 11:00 AM." }
180
184
  ```
181
185
 
182
- ## Environment Variables
183
-
184
- Please use the following environment variables to configure the Autopilot:
185
-
186
- - `AUTOPILOT_AWS_S3_ACCESS_KEY_ID`: The AWS S3 access key.
187
- - `AUTOPILOT_AWS_S3_ENDPOINT`: The AWS S3 endpoint.
188
- - `AUTOPILOT_AWS_S3_REGION`: The AWS S3 region.
189
- - `AUTOPILOT_AWS_S3_SECRET_ACCESS_KEY`: The AWS S3 secret access key.
190
- - `AUTOPILOT_CONVERSATION_PROVIDER`: The conversation provider.
191
- - `AUTOPILOT_KNOWLEDGE_BASE_ENABLED`: Enable knowledge base powered by AWS S3 and Unstructured API.
192
- - `AUTOPILOT_LOGS_FORMAT`: The logs format.
193
- - `AUTOPILOT_LOGS_LEVEL`: The logs level.
194
- - `AUTOPILOT_LOGS_TRANSPORT`: The logs transport.
195
- - `AUTOPILOT_OPENAI_API_KEY`: The OpenAI API key needed for embeddings support.
196
- - `AUTOPILOT_UNSTRUCTURED_API_KEY`: The Unstructured API key.
197
- - `AUTOPILOT_UNSTRUCTURED_API_URL`: The Unstructured API URL. Default is `https://api.unstructured.com`.
198
- - `AUTOPILOT_RECORDING_BASE_URL`: The recording base URL. Default is `http://localhost:9876/api/recordings`.
199
-
200
- ## What's Next
201
-
202
- The Autopilot is still under heavy development. The next steps are to add support for Retrieval-Augmented Generation(RAG), improve the language model integration, and improve the Finite State Machine (FSM) that powers the conversations. If you have any suggestions or feedback, please let us know.
203
-
204
- ## Audio filters
205
-
206
- Background voices reach speech recognition and the voice activity detector, and the assistant
207
- answers them. An assistant can ask the Media Server to filter the caller's audio first, by adding
208
- `audioFilters` to its configuration — the same block whether the assistant comes from a file or
209
- from an Application:
210
-
211
- ```yaml
212
- audioFilters:
213
- - name: aiCoustics
214
- options:
215
- enhancementLevel: 0.8 # 0 to 1; higher also suppresses competing voices
216
-
217
- conversationSettings:
218
- firstMessage: "Hola, ¿en qué puedo ayudarte?"
219
- # ...
220
- ```
221
-
222
- For an Application, the same block goes inside `intelligence.config`, and is applied with:
186
+ ## Configuration
223
187
 
224
- ```sh
225
- fonoster applications:create -f app.yaml
226
- ```
188
+ Autopilot reads `autopilot-session.yaml`, found via `--config <path>`, the
189
+ `AUTOPILOT_SESSION_CONFIG` variable or `./config/autopilot-session.yaml`. It names the signing
190
+ secret the gateway uses for Autopilot apps, where apps and assistants come from, the registry
191
+ catalog, platform keys by credential ref and the knowledge settings. See
192
+ `config/autopilot-session.example.yaml` for every key.
227
193
 
228
- Assistant files may be YAML or JSON. Filtering needs the optional `@ai-coustics/aic-sdk` package
229
- and an `AIC_SDK_LICENSE` key on the apiserver; the key never appears in assistant configuration,
230
- so these files stay safe to commit. If the filter cannot be applied, the call continues with
231
- unfiltered audio and the reason is logged.
194
+ Audio filters are part of the app's configuration (the gateway runs them), not the assistant's.
package/dist/index.d.ts CHANGED
@@ -16,12 +16,7 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
- import { Autopilot } from "./Autopilot";
20
- export default Autopilot;
21
- export * from "./assistants";
22
19
  export * from "./knowledge";
23
20
  export * from "./models";
24
21
  export * from "./tools";
25
- export * from "./types";
26
- export * from "./vad";
27
22
  export * from "./voice";
package/dist/index.js CHANGED
@@ -32,12 +32,7 @@ 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
- const Autopilot_1 = require("./Autopilot");
36
- exports.default = Autopilot_1.Autopilot;
37
- __exportStar(require("./assistants"), exports);
38
35
  __exportStar(require("./knowledge"), exports);
39
36
  __exportStar(require("./models"), exports);
40
37
  __exportStar(require("./tools"), exports);
41
- __exportStar(require("./types"), exports);
42
- __exportStar(require("./vad"), exports);
43
38
  __exportStar(require("./voice"), exports);
@@ -4,8 +4,9 @@ import { KnowledgeBase } from "./types";
4
4
  declare abstract class AbstractKnowledgeBase implements KnowledgeBase {
5
5
  protected embeddings: Embeddings;
6
6
  protected vectorStore: VectorStore;
7
- constructor(params?: {
8
- embeddings?: Embeddings;
7
+ /** The embeddings come from the caller (the hosted Autopilot resolves their key by credentialRef). */
8
+ constructor(params: {
9
+ embeddings: Embeddings;
9
10
  });
10
11
  abstract getLoaders(): Promise<unknown>;
11
12
  load(): Promise<void>;
@@ -21,17 +21,12 @@ exports.AbstractKnowledgeBase = void 0;
21
21
  */
22
22
  const logger_1 = require("@fonoster/logger");
23
23
  const memory_1 = require("@langchain/classic/vectorstores/memory");
24
- const openai_1 = require("@langchain/openai");
25
24
  const textsplitters_1 = require("@langchain/textsplitters");
26
- const envs_1 = require("../envs");
27
25
  const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
28
26
  class AbstractKnowledgeBase {
27
+ /** The embeddings come from the caller (the hosted Autopilot resolves their key by credentialRef). */
29
28
  constructor(params) {
30
- this.embeddings =
31
- params?.embeddings ||
32
- new openai_1.OpenAIEmbeddings({
33
- apiKey: envs_1.OPENAI_API_KEY
34
- });
29
+ this.embeddings = params.embeddings;
35
30
  }
36
31
  async load() {
37
32
  const loaders = (await this.getLoaders());
@@ -22,7 +22,7 @@ import { AbstractKnowledgeBase } from "./AbstractKnowledgeBase";
22
22
  declare class FilesKnowledgeBase extends AbstractKnowledgeBase {
23
23
  private params;
24
24
  constructor(params: {
25
- embeddings?: Embeddings;
25
+ embeddings: Embeddings;
26
26
  files: string[];
27
27
  });
28
28
  getLoaders(): Promise<PDFLoader[]>;
@@ -22,7 +22,7 @@ type KnowledgeBase = {
22
22
  queryKnowledgeBase: (query: string, k?: number) => Promise<string>;
23
23
  };
24
24
  type S3KnowledgeBaseParams = {
25
- embeddings?: Embeddings;
25
+ embeddings: Embeddings;
26
26
  bucket: string;
27
27
  documents: string[];
28
28
  s3Config: {
@@ -1,22 +1,3 @@
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 { LanguageModelProvider } from "@fonoster/common";
20
1
  import { Voice } from "../voice";
21
2
  import { AbstractLanguageModel } from "./AbstractLanguageModel";
22
3
  import { AnthropicParams } from "./anthropic";
@@ -27,11 +8,11 @@ import { OpenAIParams } from "./openai";
27
8
  import { BaseModelParams, TelephonyContext } from "./types";
28
9
  type LanguageModelConstructor<T extends BaseModelParams = BaseModelParams> = new (options: T, voice: Voice, telephonyContext: TelephonyContext) => AbstractLanguageModel;
29
10
  type LanguageModelConfigMap = {
30
- [LanguageModelProvider.OPENAI]: OpenAIParams;
31
- [LanguageModelProvider.GROQ]: GroqParams;
32
- [LanguageModelProvider.OLLAMA]: OllamaParams;
33
- [LanguageModelProvider.GOOGLE]: GoogleParams;
34
- [LanguageModelProvider.ANTHROPIC]: AnthropicParams;
11
+ openai: OpenAIParams;
12
+ groq: GroqParams;
13
+ ollama: OllamaParams;
14
+ google: GoogleParams;
15
+ anthropic: AnthropicParams;
35
16
  };
36
17
  declare class LanguageModelFactory {
37
18
  private static readonly languageModels;
@@ -19,7 +19,6 @@ exports.LanguageModelFactory = void 0;
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
- const common_1 = require("@fonoster/common");
23
22
  const logger_1 = require("@fonoster/logger");
24
23
  const anthropic_1 = require("./anthropic");
25
24
  const google_1 = require("./google");
@@ -16,10 +16,10 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
- import { AssistantConfig, KnowledgeBase, TelephonyContext, Voice } from "..";
19
+ import { EvalAssistant, KnowledgeBase, TelephonyContext, Voice } from "..";
20
20
  declare function createLanguageModel(params: {
21
21
  voice: Voice;
22
- assistantConfig: AssistantConfig;
22
+ assistantConfig: EvalAssistant;
23
23
  knowledgeBase: KnowledgeBase;
24
24
  telephonyContext: TelephonyContext;
25
25
  }): import("./AbstractLanguageModel").AbstractLanguageModel;
@@ -16,109 +16,13 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
- import { AssistantConfig } from "../../assistants";
20
- export declare function createEvalEffectiveConfig(config: AssistantConfig, credentials: {
21
- apiKey: string;
22
- }, evaluationApiKey: {
23
- apiKey: string;
24
- }): {
25
- languageModel: {
26
- apiKey: string;
27
- provider?: import("@fonoster/common").LanguageModelProvider;
28
- model?: string;
29
- temperature?: number;
30
- maxTokens?: number;
31
- baseUrl?: string;
32
- knowledgeBase?: {
33
- type?: "s3";
34
- title?: string;
35
- document?: string;
36
- }[];
37
- tools?: {
38
- name?: string;
39
- description?: string;
40
- parameters?: {
41
- type?: "object" | "array";
42
- properties?: Record<string, {
43
- type?: string;
44
- format?: "enum" | "date-time";
45
- pattern?: string;
46
- }>;
47
- required?: string[];
48
- };
49
- requestStartMessage?: string;
50
- operation?: {
51
- url?: string;
52
- method?: import("@fonoster/common").AllowedHttpMethod;
53
- headers?: Record<string, string>;
54
- waitForResponse?: boolean;
55
- };
56
- }[];
57
- };
58
- testCases: {
59
- evalsLanguageModel: {
60
- apiKey: string;
61
- provider?: "openai";
62
- model?: string;
63
- };
64
- evalsSystemPrompt?: string;
65
- scenarios?: {
66
- description?: string;
67
- ref?: string;
68
- telephonyContext?: {
69
- callDirection?: import("@fonoster/types").CallDirection;
70
- ingressNumber?: string;
71
- callerNumber?: string;
72
- metadata?: Record<string, string>;
73
- };
74
- conversation?: {
75
- expected?: {
76
- tools?: {
77
- parameters?: Record<string, any>;
78
- tool?: string;
79
- }[];
80
- text?: {
81
- type?: "EXACT" | "SIMILAR";
82
- response?: string;
83
- };
84
- };
85
- userInput?: string;
86
- }[];
87
- }[];
88
- };
89
- audioFilters?: {
90
- options?: Record<string, unknown>;
91
- name?: string;
92
- }[];
93
- conversationSettings?: {
94
- firstMessage?: string;
95
- systemPrompt?: string;
96
- goodbyeMessage?: string;
97
- systemErrorMessage?: string;
98
- initialDtmf?: string;
99
- maxSessionDuration?: number;
100
- maxSpeechWaitTimeout?: number;
101
- transferOptions?: {
102
- message?: string;
103
- phoneNumber?: string;
104
- timeout?: number;
105
- };
106
- idleOptions?: {
107
- message?: string;
108
- timeout?: number;
109
- maxTimeoutCount?: number;
110
- };
111
- allowUserBargeIn?: boolean;
112
- vad?: {
113
- pathToModel?: string;
114
- activationThreshold?: number;
115
- deactivationThreshold?: number;
116
- debounceFrames?: number;
117
- };
118
- };
119
- eventsHook?: {
120
- url?: string;
121
- headers?: Record<string, string>;
122
- events?: import("@fonoster/common").EventsHookAllowedEvents[];
123
- };
124
- };
19
+ import { SessionAssistant } from "@fonoster/common";
20
+ import { EvalAssistant } from "../types";
21
+ /**
22
+ * The session assistant as the evaluations run it: the catalog id split into provider and model,
23
+ * with the keys the caller resolved (never stored in the assistant).
24
+ */
25
+ export declare function createEvalEffectiveConfig(assistant: SessionAssistant, keys: {
26
+ apiKey?: string;
27
+ evaluationApiKey?: string;
28
+ }): EvalAssistant;
@@ -1,18 +1,58 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createEvalEffectiveConfig = createEvalEffectiveConfig;
4
- function createEvalEffectiveConfig(config, credentials, evaluationApiKey) {
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 common_1 = require("@fonoster/common");
23
+ const LLM_PROVIDERS = [
24
+ "openai",
25
+ "groq",
26
+ "ollama",
27
+ "google",
28
+ "anthropic"
29
+ ];
30
+ /**
31
+ * The session assistant as the evaluations run it: the catalog id split into provider and model,
32
+ * with the keys the caller resolved (never stored in the assistant).
33
+ */
34
+ function createEvalEffectiveConfig(assistant, keys) {
35
+ const [provider, ...rest] = assistant.languageModel.model.split("/");
36
+ if (!LLM_PROVIDERS.includes(provider))
37
+ throw new Error(`evaluations do not support ${provider} models`);
38
+ const testCases = common_1.testCasesSchema.parse(assistant.testCases);
39
+ const { provider: _p, apiKey: _k, baseUrl: _b, ...languageModel } = assistant.languageModel;
40
+ void _p;
41
+ void _k;
42
+ void _b;
5
43
  return {
6
- ...config,
44
+ conversationSettings: assistant.conversationSettings,
7
45
  languageModel: {
8
- ...config.languageModel,
9
- apiKey: credentials.apiKey
46
+ ...languageModel,
47
+ provider: provider,
48
+ model: rest.join("/"),
49
+ apiKey: keys.apiKey
10
50
  },
11
51
  testCases: {
12
- ...config.testCases,
52
+ ...testCases,
13
53
  evalsLanguageModel: {
14
- ...config.testCases.evalsLanguageModel,
15
- apiKey: evaluationApiKey.apiKey
54
+ ...testCases.evalsLanguageModel,
55
+ apiKey: keys.evaluationApiKey
16
56
  }
17
57
  }
18
58
  };
@@ -1,27 +1,17 @@
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 { IntegrationConfig } from "@fonoster/common";
20
1
  import { EvaluateIntelligenceRequest } from "./types";
21
2
  type ServerStreamCall = {
22
3
  request: EvaluateIntelligenceRequest;
23
4
  write: (chunk: Record<string, unknown>) => void;
24
5
  end: () => void;
25
6
  };
26
- declare function createEvaluateIntelligence(integrations: IntegrationConfig[]): (call: ServerStreamCall) => Promise<void>;
7
+ /**
8
+ * A model provider's key for a workspace: the workspace's own vendor key, else the platform key
9
+ * by the provider's credentialRef (the control plane decides; integrations.json is gone).
10
+ */
11
+ export type EvalKeySource = (providerId: string, workspaceRef: string) => Promise<string | undefined>;
12
+ /**
13
+ * Runs an assistant's test cases (rework-autopilot 8.2: the assistant is a session assistant; its
14
+ * catalog id picks the provider, and keys come from `keys`, never from the assistant).
15
+ */
16
+ declare function createEvaluateIntelligence(keys: EvalKeySource): (call: ServerStreamCall) => Promise<void>;
27
17
  export { createEvaluateIntelligence };
@@ -22,45 +22,54 @@ exports.createEvaluateIntelligence = createEvaluateIntelligence;
22
22
  const common_1 = require("@fonoster/common");
23
23
  const logger_1 = require("@fonoster/logger");
24
24
  const pb_util_1 = require("pb-util");
25
- const zod_1 = require("zod");
26
25
  const createEvalEffectiveConfig_1 = require("./createEvalEffectiveConfig");
27
26
  const runEval_1 = require("./runEval");
27
+ const session_1 = require("./session");
28
28
  const stepReportToEventPayload_1 = require("./stepReportToEventPayload");
29
29
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
30
- function createEvaluateIntelligence(integrations) {
30
+ /**
31
+ * Runs an assistant's test cases (rework-autopilot 8.2: the assistant is a session assistant; its
32
+ * catalog id picks the provider, and keys come from `keys`, never from the assistant).
33
+ */
34
+ function createEvaluateIntelligence(keys) {
31
35
  const evaluateIntelligence = async (call) => {
32
36
  const { request } = call;
33
37
  const { intelligence } = request;
34
38
  const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
35
- logger.verbose("call to evaluateIntelligence", {
36
- accessKeyId,
37
- llmProductRef: intelligence.productRef,
38
- evalLlmProductRef: "llm.openai"
39
- });
40
39
  try {
41
40
  const config = pb_util_1.struct.decode(intelligence.config);
42
- const parsedIntelligence = zod_1.z
43
- .object({
44
- productRef: zod_1.z.string(),
45
- config: common_1.assistantSchema
46
- })
47
- .parse({
48
- productRef: intelligence.productRef,
49
- config
41
+ const assistant = common_1.sessionAssistantSchema.parse(config);
42
+ const provider = assistant.languageModel.model.split("/")[0];
43
+ logger.verbose("call to evaluateIntelligence", {
44
+ accessKeyId,
45
+ model: assistant.languageModel.model
50
46
  });
51
- const credentials = (0, common_1.findIntegrationsCredentials)(integrations, intelligence.productRef);
52
- const evaluationApiKey = (0, common_1.findIntegrationsCredentials)(integrations, "llm.openai");
53
- const effectiveConfig = (0, createEvalEffectiveConfig_1.createEvalEffectiveConfig)(parsedIntelligence.config, credentials, evaluationApiKey);
54
- await (0, runEval_1.runEval)({ intelligence: { config: effectiveConfig } }, {
47
+ const apiKey = await keys(provider, accessKeyId);
48
+ const evaluationApiKey = await keys("openai", accessKeyId);
49
+ if (!apiKey && provider !== "ollama")
50
+ throw new Error(`no ${provider} key for this workspace or platform`);
51
+ if (!evaluationApiKey)
52
+ throw new Error("no openai key for the evaluation model (workspace or platform)");
53
+ const callbacks = {
55
54
  onStepResult: (scenarioRef, stepReport) => {
56
- const payload = (0, stepReportToEventPayload_1.stepReportToEventPayload)(scenarioRef, stepReport);
57
- call.write(payload);
55
+ call.write((0, stepReportToEventPayload_1.stepReportToEventPayload)(scenarioRef, stepReport));
58
56
  },
59
57
  onScenarioComplete: (scenarioRef, overallPassed) => {
60
- const payload = (0, stepReportToEventPayload_1.scenarioSummaryToEventPayload)(scenarioRef, overallPassed);
61
- call.write(payload);
58
+ call.write((0, stepReportToEventPayload_1.scenarioSummaryToEventPayload)(scenarioRef, overallPassed));
62
59
  }
60
+ };
61
+ // The session engine (streaming replies, structured tool messages) for OpenAI-compatible
62
+ // providers; the LangChain path stays for the rest until their adapters land (EV-B1).
63
+ const think = (0, session_1.sessionThinkFor)(assistant, apiKey);
64
+ if (think) {
65
+ await (0, session_1.runSessionEval)({ assistant, think, evaluationApiKey }, callbacks);
66
+ return;
67
+ }
68
+ const effectiveConfig = (0, createEvalEffectiveConfig_1.createEvalEffectiveConfig)(assistant, {
69
+ apiKey,
70
+ evaluationApiKey
63
71
  });
72
+ await (0, runEval_1.runEval)({ intelligence: { config: effectiveConfig } }, callbacks);
64
73
  }
65
74
  catch (error) {
66
75
  const message = error instanceof Error ? error.message : String(error);
@@ -17,9 +17,9 @@
17
17
  * limitations under the License.
18
18
  */
19
19
  import { ScenarioEvaluationReport } from "@fonoster/types";
20
- import { AssistantConfig } from "../../assistants";
20
+ import { EvalAssistant } from "../types";
21
21
  export declare function evalTestCases(autopilotApplication: {
22
22
  intelligence: {
23
- config: AssistantConfig;
23
+ config: EvalAssistant;
24
24
  };
25
25
  }): Promise<ScenarioEvaluationReport[]>;
@@ -16,10 +16,9 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
- import { AssistantConfig } from "../../assistants";
20
- import { InvocationResult } from "../types";
19
+ import { EvalAssistant, InvocationResult } from "../types";
21
20
  /**
22
21
  * Maps language model invocation result to the text that should be compared
23
22
  * in eval (hangup/transfer use config messages).
24
23
  */
25
- export declare function extractAiResponse(response: InvocationResult, assistantConfig: AssistantConfig): string;
24
+ export declare function extractAiResponse(response: InvocationResult, assistantConfig: EvalAssistant): string;
@@ -28,3 +28,4 @@ export * from "./extractAiResponse";
28
28
  export * from "./isValidIso8601Date";
29
29
  export * from "./runEval";
30
30
  export * from "./types";
31
+ export * from "./session";
@@ -44,3 +44,4 @@ __exportStar(require("./extractAiResponse"), exports);
44
44
  __exportStar(require("./isValidIso8601Date"), exports);
45
45
  __exportStar(require("./runEval"), exports);
46
46
  __exportStar(require("./types"), exports);
47
+ __exportStar(require("./session"), exports);
@@ -1,26 +1,8 @@
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 { AssistantConfig } from "../../assistants";
1
+ import { EvalAssistant } from "../types";
20
2
  import { RunEvalCallbacks } from "./types";
21
3
  export type RunEvalConfig = {
22
4
  intelligence: {
23
- config: AssistantConfig;
5
+ config: EvalAssistant;
24
6
  };
25
7
  };
26
8
  export declare function runEval(autopilotApplication: RunEvalConfig, callbacks: RunEvalCallbacks): Promise<void>;