@mozaik-ai/core 3.13.0 → 3.14.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/dist/index.mjs CHANGED
@@ -35,9 +35,6 @@ var ModelContext = class _ModelContext {
35
35
  static rehydrate(data) {
36
36
  return new _ModelContext(data.id, data.projectId, data.items);
37
37
  }
38
- toJSON() {
39
- return this.items.map((item) => item.toJSON());
40
- }
41
38
  };
42
39
 
43
40
  // src/domain/model-context/context-item/context-item.ts
@@ -64,14 +61,6 @@ var InputText = class _InputText extends ItemContent {
64
61
  static rehydrate(data) {
65
62
  return new _InputText(data.text);
66
63
  }
67
- toJSON() {
68
- return [
69
- {
70
- type: this.type,
71
- text: this.text
72
- }
73
- ];
74
- }
75
64
  };
76
65
 
77
66
  // src/domain/model-context/context-item/client-item/user-message.ts
@@ -90,13 +79,6 @@ var UserMessageItem = class _UserMessageItem extends ContextItem {
90
79
  const content = InputText.rehydrate(data);
91
80
  return new _UserMessageItem(content);
92
81
  }
93
- toJSON() {
94
- return {
95
- type: this.type,
96
- role: this.role,
97
- content: this.content.toJSON()
98
- };
99
- }
100
82
  };
101
83
 
102
84
  // src/domain/model-context/context-item/client-item/developer-message.ts
@@ -107,13 +89,6 @@ var DeveloperMessageItem = class _DeveloperMessageItem extends ContextItem {
107
89
  this.role = "developer";
108
90
  this.content = content;
109
91
  }
110
- toJSON() {
111
- return {
112
- type: this.type,
113
- role: this.role,
114
- content: this.content.toJSON()
115
- };
116
- }
117
92
  static create(text) {
118
93
  const content = InputText.create(text);
119
94
  return new _DeveloperMessageItem(content);
@@ -134,14 +109,6 @@ var OutputText = class _OutputText extends ItemContent {
134
109
  static rehydrate(data) {
135
110
  return new _OutputText(data.text);
136
111
  }
137
- toJSON() {
138
- return [
139
- {
140
- type: this.type,
141
- text: this.text
142
- }
143
- ];
144
- }
145
112
  };
146
113
 
147
114
  // src/domain/model-context/context-item/model-item/model-message.ts
@@ -156,13 +123,6 @@ var ModelMessageItem = class _ModelMessageItem extends ContextItem {
156
123
  const content = OutputText.rehydrate(data);
157
124
  return new _ModelMessageItem(content);
158
125
  }
159
- toJSON() {
160
- return {
161
- type: this.type,
162
- role: this.role,
163
- content: this.content.toJSON()
164
- };
165
- }
166
126
  };
167
127
 
168
128
  // src/domain/model-context/context-item/model-item/function-call.ts
@@ -177,14 +137,6 @@ var FunctionCallItem = class _FunctionCallItem extends ContextItem {
177
137
  static rehydrate(data) {
178
138
  return new _FunctionCallItem(data.callId, data.name, data.args);
179
139
  }
180
- toJSON() {
181
- return {
182
- type: this.type,
183
- call_id: this.callId,
184
- name: this.name,
185
- arguments: this.args
186
- };
187
- }
188
140
  };
189
141
 
190
142
  // src/domain/model-context/context-item/model-item/reasoning.ts
@@ -199,14 +151,18 @@ var ReasoningItem = class _ReasoningItem extends ContextItem {
199
151
  static rehydrate(data) {
200
152
  return new _ReasoningItem(data.content, data.encryptedContent, data.summary);
201
153
  }
202
- toJSON() {
203
- var _a;
204
- return {
205
- type: this.type,
206
- content: (_a = this.content) == null ? void 0 : _a.toJSON(),
207
- encryptedContent: this.encryptedContent,
208
- summary: this.summary.map((s) => s.toJSON())
209
- };
154
+ };
155
+
156
+ // src/domain/generative-model/request-validation/structured-output.ts
157
+ var StructuredOutputValidation = class {
158
+ constructor() {
159
+ this.name = "structured-output";
160
+ }
161
+ isValid(inferenceParams, model) {
162
+ if (inferenceParams.structuredOutput === void 0) {
163
+ return true;
164
+ }
165
+ return model.supportsStructuredOutput;
210
166
  }
211
167
  };
212
168
 
@@ -225,179 +181,6 @@ var FunctionCallOutputItem = class _FunctionCallOutputItem extends ContextItem {
225
181
  static rehydrate(data) {
226
182
  return new _FunctionCallOutputItem(data.callId, data.output);
227
183
  }
228
- toJSON() {
229
- return {
230
- type: this.type,
231
- call_id: this.callId,
232
- output: this.output.toJSON()
233
- };
234
- }
235
- };
236
-
237
- // src/infrastructure/providers/openai/reasoning-effort.ts
238
- var OpenAIReasoningEffort = class {
239
- constructor(reasoningEffort) {
240
- this.reasoningEffort = reasoningEffort;
241
- }
242
- setReasoningEffort(effort) {
243
- this.reasoningEffort = effort;
244
- }
245
- getReasoningEffort() {
246
- if (!this.reasoningEffort) {
247
- throw new Error("Reasoning effort not supported");
248
- }
249
- return this.reasoningEffort;
250
- }
251
- };
252
-
253
- // src/infrastructure/providers/openai/models/gpt-5-4-nano.ts
254
- var Gpt54Nano = class {
255
- constructor() {
256
- this.specification = {
257
- name: "gpt-5.4-nano",
258
- provider: "openai",
259
- supportReasoningEffort: true,
260
- defaultReasoningEffort: "none",
261
- supportStreaming: true,
262
- contextWindowSize: 4e5,
263
- maxOutputTokens: 128e3,
264
- supportFunctionCalling: true,
265
- supportStructuredOutput: true
266
- };
267
- this.tools = [];
268
- this.streaming = false;
269
- this.structuredOutput = void 0;
270
- this.effort = new OpenAIReasoningEffort(
271
- this.specification.defaultReasoningEffort
272
- );
273
- }
274
- setStreaming(streaming) {
275
- this.streaming = streaming;
276
- }
277
- getStreaming() {
278
- return this.streaming;
279
- }
280
- setTools(tools) {
281
- this.tools = tools;
282
- }
283
- getTools() {
284
- return this.tools;
285
- }
286
- setReasoningEffort(effort) {
287
- this.effort.setReasoningEffort(effort);
288
- }
289
- getReasoningEffort() {
290
- return this.effort.getReasoningEffort();
291
- }
292
- setStructuredOutput(format) {
293
- this.structuredOutput = format;
294
- }
295
- getStructuredOutput() {
296
- return this.structuredOutput;
297
- }
298
- hasStructuredOutput() {
299
- return this.structuredOutput !== void 0;
300
- }
301
- };
302
-
303
- // src/infrastructure/providers/openai/models/gpt-5-4.ts
304
- var Gpt54 = class {
305
- constructor() {
306
- this.specification = {
307
- name: "gpt-5.4",
308
- provider: "openai",
309
- supportReasoningEffort: true,
310
- defaultReasoningEffort: "none",
311
- supportStreaming: true,
312
- contextWindowSize: 105e4,
313
- maxOutputTokens: 128e3,
314
- supportFunctionCalling: true,
315
- supportStructuredOutput: true
316
- };
317
- this.tools = [];
318
- this.streaming = false;
319
- this.structuredOutput = void 0;
320
- this.effort = new OpenAIReasoningEffort(
321
- this.specification.defaultReasoningEffort
322
- );
323
- }
324
- setStreaming(streaming) {
325
- this.streaming = streaming;
326
- }
327
- getStreaming() {
328
- return this.streaming;
329
- }
330
- setTools(tools) {
331
- this.tools = tools;
332
- }
333
- getTools() {
334
- return this.tools;
335
- }
336
- setReasoningEffort(effort) {
337
- this.effort.setReasoningEffort(effort);
338
- }
339
- getReasoningEffort() {
340
- return this.effort.getReasoningEffort();
341
- }
342
- setStructuredOutput(format) {
343
- this.structuredOutput = format;
344
- }
345
- getStructuredOutput() {
346
- return this.structuredOutput;
347
- }
348
- hasStructuredOutput() {
349
- return this.structuredOutput !== void 0;
350
- }
351
- };
352
-
353
- // src/infrastructure/providers/openai/models/gpt-5-4-mini.ts
354
- var Gpt54Mini = class {
355
- constructor() {
356
- this.specification = {
357
- name: "gpt-5.4-mini",
358
- provider: "openai",
359
- supportReasoningEffort: true,
360
- defaultReasoningEffort: "none",
361
- supportStreaming: true,
362
- contextWindowSize: 4e5,
363
- maxOutputTokens: 128e3,
364
- supportFunctionCalling: true,
365
- supportStructuredOutput: true
366
- };
367
- this.tools = [];
368
- this.streaming = false;
369
- this.structuredOutput = void 0;
370
- this.effort = new OpenAIReasoningEffort(
371
- this.specification.defaultReasoningEffort
372
- );
373
- }
374
- setStreaming(streaming) {
375
- this.streaming = streaming;
376
- }
377
- getStreaming() {
378
- return this.streaming;
379
- }
380
- setReasoningEffort(effort) {
381
- this.effort.setReasoningEffort(effort);
382
- }
383
- getReasoningEffort() {
384
- return this.effort.getReasoningEffort();
385
- }
386
- setTools(tools) {
387
- this.tools = tools;
388
- }
389
- getTools() {
390
- return this.tools;
391
- }
392
- setStructuredOutput(format) {
393
- this.structuredOutput = format;
394
- }
395
- getStructuredOutput() {
396
- return this.structuredOutput;
397
- }
398
- hasStructuredOutput() {
399
- return this.structuredOutput !== void 0;
400
- }
401
184
  };
402
185
 
403
186
  // src/domain/generative-model/token-usage.ts
@@ -421,6 +204,98 @@ var TokenUsage = class {
421
204
  }
422
205
  };
423
206
 
207
+ // src/infrastructure/mcp/mcp-client.ts
208
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
209
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
210
+ var McpClient = class {
211
+ constructor(config) {
212
+ this.config = config;
213
+ this.connected = false;
214
+ var _a, _b;
215
+ const headers = { ...(_a = config.headers) != null ? _a : {} };
216
+ if (config.authToken) headers.Authorization = `Bearer ${config.authToken}`;
217
+ this.transport = new StreamableHTTPClientTransport(
218
+ new URL(config.url),
219
+ Object.keys(headers).length > 0 ? { requestInit: { headers } } : void 0
220
+ );
221
+ this.client = new Client({ name: (_b = config.name) != null ? _b : "mozaik", version: "1.0.0" }, { capabilities: {} });
222
+ }
223
+ async connect() {
224
+ if (this.connected) return;
225
+ await this.client.connect(this.transport);
226
+ this.connected = true;
227
+ }
228
+ /** The tools this server exposes. */
229
+ async listTools() {
230
+ var _a;
231
+ await this.connect();
232
+ const res = await this.client.listTools();
233
+ return ((_a = res.tools) != null ? _a : []).map((t) => {
234
+ var _a2, _b;
235
+ return {
236
+ name: t.name,
237
+ description: (_a2 = t.description) != null ? _a2 : "",
238
+ inputSchema: (_b = t.inputSchema) != null ? _b : { type: "object", properties: {} }
239
+ };
240
+ });
241
+ }
242
+ /** Call a tool by name; returns its text output. Throws if the server flags an error. */
243
+ async callTool(name, args) {
244
+ await this.connect();
245
+ const res = await this.client.callTool({ name, arguments: args != null ? args : {} });
246
+ const text = extractText(res);
247
+ if (res.isError) {
248
+ throw new Error(`MCP tool "${name}" failed: ${text || "unknown error"}`);
249
+ }
250
+ return text;
251
+ }
252
+ async close() {
253
+ if (!this.connected) return;
254
+ try {
255
+ await this.client.close();
256
+ } catch (e) {
257
+ }
258
+ this.connected = false;
259
+ }
260
+ };
261
+ function extractText(res) {
262
+ const content = res.content;
263
+ if (!Array.isArray(content)) return "";
264
+ return content.filter((c) => (c == null ? void 0 : c.type) === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
265
+ }
266
+
267
+ // src/infrastructure/mcp/mcp-tool-registry.ts
268
+ var McpToolRegistry = class {
269
+ constructor(servers, createClient = (config) => new McpClient(config)) {
270
+ this.servers = servers;
271
+ this.createClient = createClient;
272
+ this.clients = [];
273
+ }
274
+ /** Discover every tool across the configured servers, as FunctionTools ready to pass to a model. */
275
+ async discoverTools() {
276
+ const tools = [];
277
+ for (const server of this.servers) {
278
+ const client = this.createClient(server);
279
+ this.clients.push(client);
280
+ for (const spec of await client.listTools()) {
281
+ tools.push({
282
+ type: "function",
283
+ name: spec.name,
284
+ description: spec.description,
285
+ parameters: spec.inputSchema,
286
+ strict: false,
287
+ invoke: (args) => client.callTool(spec.name, args != null ? args : {})
288
+ });
289
+ }
290
+ }
291
+ return tools;
292
+ }
293
+ /** Close all underlying MCP connections. */
294
+ async close() {
295
+ await Promise.all(this.clients.map((c) => c.close()));
296
+ }
297
+ };
298
+
424
299
  // src/infrastructure/repository/in-memory-model-context-repository.ts
425
300
  var InMemoryModelContextRepository = class {
426
301
  constructor() {
@@ -471,13 +346,6 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
471
346
  this.role = "system";
472
347
  this.content = content;
473
348
  }
474
- toJSON() {
475
- return {
476
- type: this.type,
477
- role: this.role,
478
- content: this.content.toJSON()
479
- };
480
- }
481
349
  static create(text) {
482
350
  const content = InputText.create(text);
483
351
  return new _SystemMessageItem(content);
@@ -624,8 +492,10 @@ var AgenticEnvironment = class {
624
492
  src.onError(error);
625
493
  } catch (error2) {
626
494
  if (this.showLogs) {
627
- console.warn(`[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
628
- ${JSON.stringify({ error: error2 }, null, 2)}`);
495
+ console.warn(
496
+ `[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
497
+ ${JSON.stringify({ error: error2 }, null, 2)}`
498
+ );
629
499
  }
630
500
  } finally {
631
501
  src.markInactive(this);
@@ -636,8 +506,10 @@ var AgenticEnvironment = class {
636
506
  sub.onParticipantError(source, error);
637
507
  } catch (error2) {
638
508
  if (this.showLogs) {
639
- console.warn(`[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
640
- ${JSON.stringify({ error: error2 }, null, 2)}`);
509
+ console.warn(
510
+ `[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
511
+ ${JSON.stringify({ error: error2 }, null, 2)}`
512
+ );
641
513
  }
642
514
  }
643
515
  }
@@ -680,56 +552,6 @@ var AgenticEnvironment = class {
680
552
  }
681
553
  };
682
554
 
683
- // src/infrastructure/providers/openai/models/gpt-5-5.ts
684
- var Gpt55 = class {
685
- constructor() {
686
- this.specification = {
687
- name: "gpt-5.5",
688
- provider: "openai",
689
- supportReasoningEffort: true,
690
- defaultReasoningEffort: "none",
691
- supportStreaming: true,
692
- contextWindowSize: 105e4,
693
- maxOutputTokens: 128e3,
694
- supportFunctionCalling: true,
695
- supportStructuredOutput: true
696
- };
697
- this.tools = [];
698
- this.streaming = false;
699
- this.structuredOutput = void 0;
700
- this.effort = new OpenAIReasoningEffort(
701
- this.specification.defaultReasoningEffort
702
- );
703
- }
704
- setStreaming(streaming) {
705
- this.streaming = streaming;
706
- }
707
- getStreaming() {
708
- return this.streaming;
709
- }
710
- setTools(tools) {
711
- this.tools = tools;
712
- }
713
- getTools() {
714
- return this.tools;
715
- }
716
- setReasoningEffort(effort) {
717
- this.effort.setReasoningEffort(effort);
718
- }
719
- getReasoningEffort() {
720
- return this.effort.getReasoningEffort();
721
- }
722
- setStructuredOutput(format) {
723
- this.structuredOutput = format;
724
- }
725
- getStructuredOutput() {
726
- return this.structuredOutput;
727
- }
728
- hasStructuredOutput() {
729
- return this.structuredOutput !== void 0;
730
- }
731
- };
732
-
733
555
  // src/domain/model-context/semantic-event/semantic-event.ts
734
556
  var SemanticEvent = class {
735
557
  constructor(type, data) {
@@ -741,14 +563,6 @@ var SemanticEvent = class {
741
563
  }
742
564
  };
743
565
 
744
- // src/domain/agentic-environment/inference/request.ts
745
- var InferenceRequest = class {
746
- constructor(model, context) {
747
- this.model = model;
748
- this.context = context;
749
- }
750
- };
751
-
752
566
  // src/domain/agentic-environment/inference/response.ts
753
567
  var InferenceResponse = class {
754
568
  constructor(contextItems, tokenUsage) {
@@ -757,191 +571,196 @@ var InferenceResponse = class {
757
571
  }
758
572
  };
759
573
 
760
- // src/infrastructure/providers/openai/runtime/openai-responses.ts
761
- import OpenAI from "openai";
762
- var OpenAIResponses = class {
763
- constructor() {
764
- this.client = new OpenAI();
765
- }
766
- async infer(inferenceRequest) {
767
- const request = this.buildRequest(inferenceRequest);
768
- const response = await this.client.responses.create(request);
769
- const contextItems = this.extractContextItems(response);
770
- const tokenUsage = this.extractTokenUsage(response);
771
- return new InferenceResponse(contextItems, tokenUsage);
574
+ // src/application/services/inference-runner.ts
575
+ var StreamingInference = class {
576
+ async *run(request, endpoint) {
577
+ var _a;
578
+ if ((_a = request.signal) == null ? void 0 : _a.aborted) {
579
+ return;
580
+ }
581
+ yield* endpoint.stream(request, request.signal);
772
582
  }
773
- async *stream(inferenceRequest, signal) {
774
- const specification = inferenceRequest.model.specification;
775
- if (!specification.supportStreaming) {
776
- throw new Error("Streaming is not supported for this model");
583
+ };
584
+ var NonStreamingInference = class {
585
+ async *run(request, endpoint) {
586
+ var _a, _b;
587
+ if ((_a = request.signal) == null ? void 0 : _a.aborted) {
588
+ return;
777
589
  }
778
- const request = { ...this.buildRequest(inferenceRequest), stream: true };
779
- const response = await this.client.responses.create(request);
780
- for await (const event of response) {
781
- if (signal == null ? void 0 : signal.aborted) {
590
+ const response = await endpoint.infer(request);
591
+ for (const item of response.contextItems) {
592
+ if ((_b = request.signal) == null ? void 0 : _b.aborted) {
782
593
  break;
783
594
  }
784
- yield new SemanticEvent(event.type, event);
595
+ yield item;
785
596
  }
786
597
  }
787
- buildRequest(inferenceRequest) {
788
- var _a, _b;
789
- const specification = inferenceRequest.model.specification;
790
- const input = this.mapContextToRequest(inferenceRequest.context);
791
- const request = {
792
- model: specification.name,
793
- input
598
+ };
599
+
600
+ // src/application/use-cases/run-inference.ts
601
+ var RunInference = class {
602
+ constructor(generativeModelRepository2, requestValidator) {
603
+ this.generativeModelRepository = generativeModelRepository2;
604
+ this.requestValidator = requestValidator;
605
+ }
606
+ async execute(inferenceParams) {
607
+ var _a;
608
+ const { caller, environment, signal } = inferenceParams;
609
+ const generativeModel = await this.generativeModelRepository.getByModelName(inferenceParams.model);
610
+ this.requestValidator.validate(inferenceParams, generativeModel.specification);
611
+ const resolvedParams = {
612
+ ...inferenceParams,
613
+ maxOutputTokens: (_a = inferenceParams.maxOutputTokens) != null ? _a : generativeModel.specification.maxOutputTokens
794
614
  };
795
- if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
796
- request.tools = inferenceRequest.model.getTools().map((tool) => {
797
- return {
798
- type: tool.type,
799
- name: tool.name,
800
- description: tool.description,
801
- parameters: tool.parameters
802
- };
803
- });
804
- }
805
- if (specification.supportReasoningEffort) {
806
- request.reasoning = {
807
- effort: inferenceRequest.model.getReasoningEffort()
808
- };
809
- }
810
- if (inferenceRequest.model.hasStructuredOutput()) {
811
- if (!specification.supportStructuredOutput) {
812
- throw new Error(`Structured output is not supported for model: ${specification.name}`);
615
+ const inferenceRunner = inferenceParams.streaming ? new StreamingInference() : new NonStreamingInference();
616
+ const result = inferenceRunner.run(resolvedParams, generativeModel.endpoint);
617
+ for await (const item of result) {
618
+ if (signal == null ? void 0 : signal.aborted) {
619
+ break;
620
+ }
621
+ if (item instanceof ReasoningItem) {
622
+ environment.deliverReasoning(caller, item);
623
+ } else if (item instanceof FunctionCallItem) {
624
+ environment.deliverFunctionCall(caller, item);
625
+ } else if (item instanceof ModelMessageItem) {
626
+ environment.deliverModelMessage(caller, item);
627
+ } else if (item instanceof SemanticEvent) {
628
+ environment.deliverSemanticEvent(caller, item);
813
629
  }
814
- const format = inferenceRequest.model.getStructuredOutput();
815
- request.text = {
816
- format: {
817
- type: "json_schema",
818
- name: (_a = format.name) != null ? _a : "response",
819
- schema: format.schema,
820
- strict: (_b = format.strict) != null ? _b : true
821
- }
822
- };
823
630
  }
824
- return request;
825
631
  }
826
- extractTokenUsage(response) {
827
- if (!response.usage) {
828
- return void 0;
829
- }
830
- return new TokenUsage(
831
- response.usage.input_tokens,
832
- response.usage.output_tokens,
833
- response.usage.total_tokens,
834
- new InputTokenDetails(response.usage.input_tokens_details.cached_tokens),
835
- new OutputTokenDetails(response.usage.output_tokens_details.reasoning_tokens)
836
- );
632
+ };
633
+
634
+ // src/application/use-cases/execute-function-call.ts
635
+ var ExecuteFunctionCall = class {
636
+ constructor(functionCallRunner) {
637
+ this.functionCallRunner = functionCallRunner;
837
638
  }
838
- mapContextToRequest(context) {
839
- return context.getItems().map((item) => item.toJSON());
639
+ async execute(environment, functionCallItem, tool, caller, signal) {
640
+ const stream = this.functionCallRunner.run(functionCallItem, tool, signal);
641
+ for await (const item of stream) {
642
+ environment.deliverFunctionCallOutput(caller, item);
643
+ }
840
644
  }
841
- extractContextItems(response) {
842
- return response.output.map((item) => {
843
- if (item.type === "message" && item.role === "assistant") {
844
- return ModelMessageItem.rehydrate(item.content[0]);
845
- }
846
- if (item.type === "function_call") {
847
- return FunctionCallItem.rehydrate({
848
- callId: item.call_id,
849
- name: item.name,
850
- args: item.arguments
851
- });
852
- }
853
- if (item.type === "reasoning") {
854
- return ReasoningItem.rehydrate(item);
855
- }
856
- });
645
+ };
646
+
647
+ // src/application/services/function-call-runner.ts
648
+ var FunctionCallRunner = class {
649
+ async *run(call, tool, signal) {
650
+ if (signal == null ? void 0 : signal.aborted) {
651
+ return;
652
+ }
653
+ if (!tool) throw new Error(`Unknown tool: ${call.name}`);
654
+ const result = await tool.invoke(JSON.parse(call.args));
655
+ yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
857
656
  }
858
657
  };
859
658
 
860
- // src/infrastructure/providers/anthropic/runtime/anthropic-messages.ts
861
- import Anthropic from "@anthropic-ai/sdk";
862
- var AnthropicMessages = class {
863
- constructor() {
864
- this.client = new Anthropic();
659
+ // src/application/participants/participant.ts
660
+ var BaseParticipant = class extends Participant {
661
+ onFunctionCall(_item) {
865
662
  }
866
- async infer(inferenceRequest) {
867
- const response = await this.client.messages.create(this.buildRequest(inferenceRequest));
868
- const contextItems = this.extractContextItems(response);
869
- const tokenUsage = this.extractTokenUsage(response);
870
- return new InferenceResponse(contextItems, tokenUsage);
663
+ onExternalFunctionCall(_source, _item) {
871
664
  }
872
- async *stream(inferenceRequest, signal) {
873
- const stream = await this.client.messages.create({
874
- ...this.buildRequest(inferenceRequest),
875
- stream: true
876
- });
877
- for await (const event of stream) {
878
- if (signal == null ? void 0 : signal.aborted) {
879
- break;
880
- }
881
- yield new SemanticEvent(event.type, event);
882
- }
665
+ onFunctionCallOutput(_item) {
883
666
  }
884
- buildRequest(inferenceRequest) {
885
- const { messages, system } = this.mapContextToRequest(inferenceRequest.context);
886
- const specification = inferenceRequest.model.specification;
887
- const request = {
888
- model: specification.name,
889
- max_tokens: specification.maxOutputTokens,
890
- messages
891
- };
892
- if (system) {
893
- request.system = system;
894
- }
895
- if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
896
- request.tools = inferenceRequest.model.getTools().map((tool) => {
897
- return {
898
- name: tool.name,
899
- description: tool.description,
900
- input_schema: tool.parameters
901
- };
902
- });
903
- }
904
- if (specification.supportReasoningEffort) {
905
- const effort = inferenceRequest.model.getReasoningEffort();
906
- const budgets = { low: 1024, medium: 4096, high: 8192 };
907
- const budget = budgets[effort];
908
- if (budget !== void 0) {
909
- request.thinking = {
910
- type: "enabled",
911
- budget_tokens: Math.min(budget, specification.maxOutputTokens - 1)
912
- };
913
- }
667
+ onExternalFunctionCallOutput(_source, _item) {
668
+ }
669
+ onReasoning(_item) {
670
+ }
671
+ onExternalReasoning(_source, _item) {
672
+ }
673
+ onModelMessage(_item) {
674
+ }
675
+ onExternalModelMessage(_source, _item) {
676
+ }
677
+ onMessage(_message) {
678
+ }
679
+ onJoined() {
680
+ }
681
+ onLeft() {
682
+ }
683
+ onParticipantJoined(_participant) {
684
+ }
685
+ onParticipantLeft(_participant) {
686
+ }
687
+ onInternalEvent(_item) {
688
+ }
689
+ onExternalEvent(_source, _item) {
690
+ }
691
+ onError(_error) {
692
+ }
693
+ onParticipantError(_source, _error) {
694
+ }
695
+ };
696
+
697
+ // src/application/use-cases/send-message.ts
698
+ var SendMessage = class {
699
+ async execute(environment, message, caller) {
700
+ if (!caller.isJoinedTo(environment)) {
701
+ throw new Error("Not joined to environment");
914
702
  }
915
- if (inferenceRequest.model.hasStructuredOutput()) {
916
- if (!specification.supportStructuredOutput) {
917
- throw new Error(`Structured output is not supported for model: ${specification.name}`);
918
- }
919
- const format = inferenceRequest.model.getStructuredOutput();
920
- request.output_config = {
921
- format: {
922
- type: "json_schema",
923
- json_schema: format.schema
924
- }
703
+ environment.deliverMessage(caller, message);
704
+ }
705
+ };
706
+
707
+ // src/infrastructure/providers/anthropic/endpoints/anthropic-messages-mapper.ts
708
+ var AnthropicMessagesMapper = class {
709
+ toRequest(inferenceParams) {
710
+ const { messages, system } = this.mapContextItems(inferenceParams);
711
+ const outputConfig = {};
712
+ const request = {
713
+ model: inferenceParams.model,
714
+ messages
715
+ };
716
+ request.max_tokens = inferenceParams.maxOutputTokens;
717
+ if (system) {
718
+ request.system = system;
719
+ }
720
+ if (inferenceParams.tools && inferenceParams.tools.length > 0) {
721
+ request.tools = inferenceParams.tools.map((tool) => ({
722
+ name: tool.name,
723
+ description: tool.description,
724
+ input_schema: tool.parameters
725
+ }));
726
+ }
727
+ if (inferenceParams.structuredOutput) {
728
+ outputConfig.format = {
729
+ type: "json_schema",
730
+ json_schema: inferenceParams.structuredOutput.schema
925
731
  };
926
732
  }
733
+ if (inferenceParams.reasoningEffort) {
734
+ request.thinking = { type: "adaptive" };
735
+ outputConfig.effort = inferenceParams.reasoningEffort;
736
+ }
737
+ if (Object.keys(outputConfig).length > 0) {
738
+ request.output_config = outputConfig;
739
+ }
740
+ if (inferenceParams.streaming) {
741
+ request.stream = inferenceParams.streaming;
742
+ }
927
743
  return request;
928
744
  }
929
- extractTokenUsage(response) {
930
- var _a, _b;
931
- if (!response.usage) {
932
- return void 0;
745
+ toResponse(response) {
746
+ const contextItems = this.extractContextItems(response);
747
+ const tokenUsage = this.extractTokenUsage(response);
748
+ return new InferenceResponse(contextItems, tokenUsage);
749
+ }
750
+ addContentBlock(messages, role, block) {
751
+ const lastMessage = messages[messages.length - 1];
752
+ if ((lastMessage == null ? void 0 : lastMessage.role) === role) {
753
+ lastMessage.content.push(block);
754
+ return;
933
755
  }
934
- return new TokenUsage(
935
- response.usage.input_tokens,
936
- response.usage.output_tokens,
937
- response.usage.input_tokens + response.usage.output_tokens,
938
- new InputTokenDetails(
939
- ((_a = response.usage.cache_creation_input_tokens) != null ? _a : 0) + ((_b = response.usage.cache_read_input_tokens) != null ? _b : 0)
940
- ),
941
- new OutputTokenDetails(0)
942
- );
756
+ messages.push({
757
+ role,
758
+ content: [block]
759
+ });
943
760
  }
944
- mapContextToRequest(context) {
761
+ mapContextItems(inferenceParams) {
762
+ var _a, _b, _c;
763
+ const context = inferenceParams.context;
945
764
  const messages = [];
946
765
  const system = [];
947
766
  for (const item of context.getItems()) {
@@ -957,6 +776,14 @@ var AnthropicMessages = class {
957
776
  this.addContentBlock(messages, "assistant", { type: "text", text: item.content.text });
958
777
  continue;
959
778
  }
779
+ if (item instanceof ReasoningItem) {
780
+ this.addContentBlock(messages, "assistant", {
781
+ type: "thinking",
782
+ thinking: (_b = (_a = item.content) == null ? void 0 : _a.text) != null ? _b : "",
783
+ signature: (_c = item.encryptedContent) != null ? _c : ""
784
+ });
785
+ continue;
786
+ }
960
787
  if (item instanceof FunctionCallItem) {
961
788
  let input;
962
789
  try {
@@ -985,6 +812,21 @@ var AnthropicMessages = class {
985
812
  system: system.length > 0 ? system.join("\n\n") : void 0
986
813
  };
987
814
  }
815
+ extractTokenUsage(response) {
816
+ var _a, _b;
817
+ if (!response.usage) {
818
+ return void 0;
819
+ }
820
+ return new TokenUsage(
821
+ response.usage.input_tokens,
822
+ response.usage.output_tokens,
823
+ response.usage.input_tokens + response.usage.output_tokens,
824
+ new InputTokenDetails(
825
+ ((_a = response.usage.cache_creation_input_tokens) != null ? _a : 0) + ((_b = response.usage.cache_read_input_tokens) != null ? _b : 0)
826
+ ),
827
+ new OutputTokenDetails(0)
828
+ );
829
+ }
988
830
  extractContextItems(response) {
989
831
  var _a;
990
832
  const items = [];
@@ -1007,7 +849,7 @@ var AnthropicMessages = class {
1007
849
  items.push(
1008
850
  ReasoningItem.rehydrate({
1009
851
  content: block.thinking ? InputText.rehydrate({ text: block.thinking }) : void 0,
1010
- encryptedContent: void 0,
852
+ encryptedContent: block.signature,
1011
853
  summary: []
1012
854
  })
1013
855
  );
@@ -1015,423 +857,261 @@ var AnthropicMessages = class {
1015
857
  }
1016
858
  return items;
1017
859
  }
1018
- addContentBlock(messages, role, block) {
1019
- const lastMessage = messages[messages.length - 1];
1020
- if ((lastMessage == null ? void 0 : lastMessage.role) === role) {
1021
- lastMessage.content.push(block);
1022
- return;
1023
- }
1024
- messages.push({
1025
- role,
1026
- content: [block]
1027
- });
1028
- }
1029
860
  };
1030
861
 
1031
- // src/infrastructure/providers/anthropic/reasoning-effort.ts
1032
- var AnthropicReasoningEffort = class {
1033
- constructor(reasoningEffort) {
1034
- this.reasoningEffort = reasoningEffort;
862
+ // src/infrastructure/providers/anthropic/endpoints/anthropic-messages.ts
863
+ import Anthropic from "@anthropic-ai/sdk";
864
+ var AnthropicMessages = class {
865
+ constructor(endpointMapper = new AnthropicMessagesMapper()) {
866
+ this.endpointMapper = endpointMapper;
867
+ this.client = new Anthropic();
1035
868
  }
1036
- setReasoningEffort(effort) {
1037
- this.reasoningEffort = effort;
869
+ async infer(inferenceParams) {
870
+ const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
871
+ const response = await this.client.messages.create(inferenceRequest);
872
+ return this.endpointMapper.toResponse(response);
1038
873
  }
1039
- getReasoningEffort() {
1040
- if (!this.reasoningEffort) {
1041
- throw new Error("Reasoning effort not supported");
874
+ async *stream(inferenceParams, signal) {
875
+ const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
876
+ const stream = await this.client.messages.create(inferenceRequest);
877
+ for await (const event of stream) {
878
+ if (signal == null ? void 0 : signal.aborted) {
879
+ break;
880
+ }
881
+ yield new SemanticEvent(event.type, event);
1042
882
  }
1043
- return this.reasoningEffort;
1044
- }
1045
- };
1046
-
1047
- // src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts
1048
- var ClaudeOpus48 = class {
1049
- constructor() {
1050
- this.specification = {
1051
- name: "claude-opus-4-8",
1052
- provider: "anthropic",
1053
- supportReasoningEffort: true,
1054
- defaultReasoningEffort: "none",
1055
- supportStreaming: true,
1056
- contextWindowSize: 2e5,
1057
- maxOutputTokens: 32e3,
1058
- supportFunctionCalling: true,
1059
- supportStructuredOutput: true
1060
- };
1061
- this.tools = [];
1062
- this.streaming = false;
1063
- this.structuredOutput = void 0;
1064
- this.effort = new AnthropicReasoningEffort(
1065
- this.specification.defaultReasoningEffort
1066
- );
1067
- }
1068
- setStreaming(streaming) {
1069
- this.streaming = streaming;
1070
- }
1071
- getStreaming() {
1072
- return this.streaming;
1073
- }
1074
- setTools(tools) {
1075
- this.tools = tools;
1076
- }
1077
- getTools() {
1078
- return this.tools;
1079
- }
1080
- setReasoningEffort(effort) {
1081
- this.effort.setReasoningEffort(effort);
1082
- }
1083
- getReasoningEffort() {
1084
- return this.effort.getReasoningEffort();
1085
- }
1086
- setStructuredOutput(format) {
1087
- this.structuredOutput = format;
1088
- }
1089
- getStructuredOutput() {
1090
- return this.structuredOutput;
1091
- }
1092
- hasStructuredOutput() {
1093
- return this.structuredOutput !== void 0;
1094
883
  }
1095
884
  };
1096
885
 
1097
- // src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
1098
- var ClaudeOpus47 = class {
1099
- constructor() {
1100
- this.specification = {
1101
- name: "claude-opus-4-7",
1102
- provider: "anthropic",
1103
- supportReasoningEffort: true,
1104
- defaultReasoningEffort: "none",
1105
- supportStreaming: true,
1106
- contextWindowSize: 2e5,
1107
- maxOutputTokens: 32e3,
1108
- supportFunctionCalling: true,
1109
- supportStructuredOutput: true
1110
- };
1111
- this.tools = [];
1112
- this.streaming = false;
1113
- this.structuredOutput = void 0;
1114
- this.effort = new AnthropicReasoningEffort(
1115
- this.specification.defaultReasoningEffort
1116
- );
1117
- }
1118
- setStreaming(streaming) {
1119
- this.streaming = streaming;
1120
- }
1121
- getStreaming() {
1122
- return this.streaming;
1123
- }
1124
- setTools(tools) {
1125
- this.tools = tools;
1126
- }
1127
- getTools() {
1128
- return this.tools;
1129
- }
1130
- setReasoningEffort(effort) {
1131
- this.effort.setReasoningEffort(effort);
1132
- }
1133
- getReasoningEffort() {
1134
- return this.effort.getReasoningEffort();
1135
- }
1136
- setStructuredOutput(format) {
1137
- this.structuredOutput = format;
1138
- }
1139
- getStructuredOutput() {
1140
- return this.structuredOutput;
1141
- }
1142
- hasStructuredOutput() {
1143
- return this.structuredOutput !== void 0;
1144
- }
1145
- };
886
+ // src/infrastructure/providers/openai/endpoints/openai-responses.ts
887
+ import OpenAI from "openai";
1146
888
 
1147
- // src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
1148
- var ClaudeSonnet46 = class {
1149
- constructor() {
1150
- this.specification = {
1151
- name: "claude-sonnet-4-6",
1152
- provider: "anthropic",
1153
- supportReasoningEffort: true,
1154
- defaultReasoningEffort: "none",
1155
- supportStreaming: true,
1156
- contextWindowSize: 2e5,
1157
- maxOutputTokens: 64e3,
1158
- supportFunctionCalling: true,
1159
- supportStructuredOutput: true
1160
- };
1161
- this.tools = [];
1162
- this.streaming = false;
1163
- this.structuredOutput = void 0;
1164
- this.effort = new AnthropicReasoningEffort(
1165
- this.specification.defaultReasoningEffort
1166
- );
1167
- }
1168
- setStreaming(streaming) {
1169
- this.streaming = streaming;
1170
- }
1171
- getStreaming() {
1172
- return this.streaming;
1173
- }
1174
- setTools(tools) {
1175
- this.tools = tools;
1176
- }
1177
- getTools() {
1178
- return this.tools;
1179
- }
1180
- setReasoningEffort(effort) {
1181
- this.effort.setReasoningEffort(effort);
1182
- }
1183
- getReasoningEffort() {
1184
- return this.effort.getReasoningEffort();
1185
- }
1186
- setStructuredOutput(format) {
1187
- this.structuredOutput = format;
1188
- }
1189
- getStructuredOutput() {
1190
- return this.structuredOutput;
889
+ // src/domain/model-context/context-item/item-content/summary-text.ts
890
+ var SummaryText = class _SummaryText extends ItemContent {
891
+ constructor(text) {
892
+ super();
893
+ this.text = text;
894
+ this.type = "summary_text";
1191
895
  }
1192
- hasStructuredOutput() {
1193
- return this.structuredOutput !== void 0;
896
+ static rehydrate(data) {
897
+ return new _SummaryText(data.text);
1194
898
  }
1195
899
  };
1196
900
 
1197
- // src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
1198
- var ClaudeHaiku45 = class {
1199
- constructor() {
1200
- this.specification = {
1201
- name: "claude-haiku-4-5",
1202
- provider: "anthropic",
1203
- supportReasoningEffort: true,
1204
- defaultReasoningEffort: "none",
1205
- supportStreaming: true,
1206
- contextWindowSize: 2e5,
1207
- maxOutputTokens: 64e3,
1208
- supportFunctionCalling: true,
1209
- supportStructuredOutput: true
901
+ // src/infrastructure/providers/openai/endpoints/openai-responses-mapper.ts
902
+ var OpenAIResponsesMapper = class {
903
+ toRequest(inferenceParams) {
904
+ var _a, _b;
905
+ const request = {
906
+ model: inferenceParams.model,
907
+ input: this.mapContextItems(inferenceParams)
1210
908
  };
1211
- this.tools = [];
1212
- this.streaming = false;
1213
- this.structuredOutput = void 0;
1214
- this.effort = new AnthropicReasoningEffort(
1215
- this.specification.defaultReasoningEffort
1216
- );
1217
- }
1218
- setStreaming(streaming) {
1219
- this.streaming = streaming;
1220
- }
1221
- getStreaming() {
1222
- return this.streaming;
1223
- }
1224
- setTools(tools) {
1225
- this.tools = tools;
1226
- }
1227
- getTools() {
1228
- return this.tools;
1229
- }
1230
- setReasoningEffort(effort) {
1231
- this.effort.setReasoningEffort(effort);
1232
- }
1233
- getReasoningEffort() {
1234
- return this.effort.getReasoningEffort();
1235
- }
1236
- setStructuredOutput(format) {
1237
- this.structuredOutput = format;
1238
- }
1239
- getStructuredOutput() {
1240
- return this.structuredOutput;
1241
- }
1242
- hasStructuredOutput() {
1243
- return this.structuredOutput !== void 0;
1244
- }
1245
- };
1246
-
1247
- // src/infrastructure/providers/deepseek/reasoning-effort.ts
1248
- var DeepSeekReasoningEffort = class {
1249
- constructor(reasoningEffort) {
1250
- this.reasoningEffort = reasoningEffort;
1251
- }
1252
- setReasoningEffort(effort) {
1253
- this.reasoningEffort = effort;
1254
- }
1255
- getReasoningEffort() {
1256
- if (!this.reasoningEffort) {
1257
- throw new Error("Reasoning effort not supported");
909
+ if (inferenceParams.tools && inferenceParams.tools.length > 0) {
910
+ request.tools = inferenceParams.tools.map((tool) => ({
911
+ type: tool.type,
912
+ name: tool.name,
913
+ description: tool.description,
914
+ parameters: tool.parameters
915
+ }));
1258
916
  }
1259
- return this.reasoningEffort;
1260
- }
1261
- };
1262
-
1263
- // src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts
1264
- var DeepSeekV4Flash = class {
1265
- constructor() {
1266
- this.specification = {
1267
- name: "deepseek-v4-flash",
1268
- provider: "deepseek",
1269
- supportReasoningEffort: true,
1270
- defaultReasoningEffort: "high",
1271
- supportStreaming: true,
1272
- contextWindowSize: 1e6,
1273
- maxOutputTokens: 384e3,
1274
- supportFunctionCalling: true,
1275
- supportStructuredOutput: false
1276
- };
1277
- this.tools = [];
1278
- this.streaming = false;
1279
- this.structuredOutput = void 0;
1280
- this.effort = new DeepSeekReasoningEffort(
1281
- this.specification.defaultReasoningEffort
1282
- );
1283
- }
1284
- setStreaming(streaming) {
1285
- this.streaming = streaming;
1286
- }
1287
- getStreaming() {
1288
- return this.streaming;
1289
- }
1290
- setTools(tools) {
1291
- this.tools = tools;
1292
- }
1293
- getTools() {
1294
- return this.tools;
1295
- }
1296
- setReasoningEffort(effort) {
1297
- this.effort.setReasoningEffort(effort);
1298
- }
1299
- getReasoningEffort() {
1300
- return this.effort.getReasoningEffort();
1301
- }
1302
- setStructuredOutput(format) {
1303
- this.structuredOutput = format;
917
+ if (inferenceParams.reasoningEffort) {
918
+ request.reasoning = {
919
+ effort: inferenceParams.reasoningEffort
920
+ };
921
+ }
922
+ if (inferenceParams.structuredOutput) {
923
+ const format = inferenceParams.structuredOutput;
924
+ request.text = {
925
+ format: {
926
+ type: "json_schema",
927
+ name: (_a = format.name) != null ? _a : "response",
928
+ schema: format.schema,
929
+ strict: (_b = format.strict) != null ? _b : true
930
+ }
931
+ };
932
+ }
933
+ if (inferenceParams.streaming) {
934
+ request.stream = inferenceParams.streaming;
935
+ }
936
+ return request;
1304
937
  }
1305
- getStructuredOutput() {
1306
- return this.structuredOutput;
938
+ toResponse(response) {
939
+ const contextItems = this.extractContextItems(response);
940
+ const tokenUsage = this.extractTokenUsage(response);
941
+ return new InferenceResponse(contextItems, tokenUsage);
1307
942
  }
1308
- hasStructuredOutput() {
1309
- return this.structuredOutput !== void 0;
943
+ mapContextItems(inferenceParams) {
944
+ const input = [];
945
+ for (const item of inferenceParams.context.getItems()) {
946
+ if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem || item instanceof UserMessageItem) {
947
+ input.push({
948
+ type: item.type,
949
+ role: item.role,
950
+ content: [{ type: "input_text", text: item.content.text }]
951
+ });
952
+ continue;
953
+ }
954
+ if (item instanceof ModelMessageItem) {
955
+ input.push({
956
+ type: item.type,
957
+ role: item.role,
958
+ content: [{ type: "output_text", text: item.content.text }]
959
+ });
960
+ continue;
961
+ }
962
+ if (item instanceof FunctionCallItem) {
963
+ input.push({
964
+ type: item.type,
965
+ call_id: item.callId,
966
+ name: item.name,
967
+ arguments: item.args
968
+ });
969
+ continue;
970
+ }
971
+ if (item instanceof FunctionCallOutputItem) {
972
+ input.push({
973
+ type: item.type,
974
+ call_id: item.callId,
975
+ output: [{ type: "input_text", text: item.output.text }]
976
+ });
977
+ continue;
978
+ }
979
+ if (item instanceof ReasoningItem) {
980
+ const reasoningInput = {
981
+ type: item.type,
982
+ summary: item.summary.map((summary) => ({ type: "summary_text", text: summary.text }))
983
+ };
984
+ if (item.encryptedContent !== void 0) {
985
+ reasoningInput.encrypted_content = item.encryptedContent;
986
+ }
987
+ input.push(reasoningInput);
988
+ }
989
+ }
990
+ return input;
1310
991
  }
1311
- };
1312
-
1313
- // src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
1314
- var DeepSeekV4Pro = class {
1315
- constructor() {
1316
- this.specification = {
1317
- name: "deepseek-v4-pro",
1318
- provider: "deepseek",
1319
- supportReasoningEffort: true,
1320
- defaultReasoningEffort: "high",
1321
- supportStreaming: true,
1322
- contextWindowSize: 1e6,
1323
- maxOutputTokens: 384e3,
1324
- supportFunctionCalling: true,
1325
- supportStructuredOutput: false
1326
- };
1327
- this.tools = [];
1328
- this.streaming = false;
1329
- this.structuredOutput = void 0;
1330
- this.effort = new DeepSeekReasoningEffort(
1331
- this.specification.defaultReasoningEffort
992
+ extractTokenUsage(response) {
993
+ var _a, _b, _c, _d;
994
+ if (!response.usage) {
995
+ return void 0;
996
+ }
997
+ return new TokenUsage(
998
+ response.usage.input_tokens,
999
+ response.usage.output_tokens,
1000
+ response.usage.total_tokens,
1001
+ new InputTokenDetails((_b = (_a = response.usage.input_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
1002
+ new OutputTokenDetails((_d = (_c = response.usage.output_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
1332
1003
  );
1333
1004
  }
1334
- setStreaming(streaming) {
1335
- this.streaming = streaming;
1336
- }
1337
- getStreaming() {
1338
- return this.streaming;
1339
- }
1340
- setTools(tools) {
1341
- this.tools = tools;
1342
- }
1343
- getTools() {
1344
- return this.tools;
1345
- }
1346
- setReasoningEffort(effort) {
1347
- this.effort.setReasoningEffort(effort);
1348
- }
1349
- getReasoningEffort() {
1350
- return this.effort.getReasoningEffort();
1351
- }
1352
- setStructuredOutput(format) {
1353
- this.structuredOutput = format;
1354
- }
1355
- getStructuredOutput() {
1356
- return this.structuredOutput;
1357
- }
1358
- hasStructuredOutput() {
1359
- return this.structuredOutput !== void 0;
1005
+ extractContextItems(response) {
1006
+ var _a, _b, _c;
1007
+ const items = [];
1008
+ for (const item of (_a = response.output) != null ? _a : []) {
1009
+ if (item.type === "message" && item.role === "assistant") {
1010
+ const firstContent = (_b = item.content) == null ? void 0 : _b[0];
1011
+ if (firstContent) {
1012
+ items.push(ModelMessageItem.rehydrate(firstContent));
1013
+ }
1014
+ continue;
1015
+ }
1016
+ if (item.type === "function_call") {
1017
+ items.push(
1018
+ FunctionCallItem.rehydrate({
1019
+ callId: item.call_id,
1020
+ name: item.name,
1021
+ args: item.arguments
1022
+ })
1023
+ );
1024
+ continue;
1025
+ }
1026
+ if (item.type === "reasoning") {
1027
+ items.push(
1028
+ ReasoningItem.rehydrate({
1029
+ content: void 0,
1030
+ encryptedContent: item.encrypted_content,
1031
+ summary: ((_c = item.summary) != null ? _c : []).map(
1032
+ (summary) => SummaryText.rehydrate({ text: summary.text })
1033
+ )
1034
+ })
1035
+ );
1036
+ }
1037
+ }
1038
+ return items;
1360
1039
  }
1361
1040
  };
1362
1041
 
1363
- // src/infrastructure/providers/gemini/runtime/gemini-generate-content.ts
1364
- import { GoogleGenAI } from "@google/genai";
1365
- var GeminiGenerateContent = class {
1366
- constructor() {
1367
- this.client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
1042
+ // src/infrastructure/providers/openai/endpoints/openai-responses.ts
1043
+ var OpenAIResponses = class {
1044
+ constructor(endpointMapper = new OpenAIResponsesMapper()) {
1045
+ this.endpointMapper = endpointMapper;
1046
+ this.client = new OpenAI();
1368
1047
  }
1369
- async infer(inferenceRequest) {
1370
- const response = await this.client.models.generateContent(this.buildRequest(inferenceRequest));
1371
- const contextItems = this.extractContextItems(response);
1372
- const tokenUsage = this.extractTokenUsage(response);
1373
- return new InferenceResponse(contextItems, tokenUsage);
1048
+ async infer(inferenceParams) {
1049
+ const request = this.endpointMapper.toRequest(inferenceParams);
1050
+ const response = await this.client.responses.create(request);
1051
+ return this.endpointMapper.toResponse(response);
1374
1052
  }
1375
- async *stream(inferenceRequest, signal) {
1376
- const stream = await this.client.models.generateContentStream(this.buildRequest(inferenceRequest));
1377
- for await (const chunk of stream) {
1053
+ async *stream(inferenceParams, signal) {
1054
+ const request = this.endpointMapper.toRequest(inferenceParams);
1055
+ const response = await this.client.responses.create(request);
1056
+ for await (const event of response) {
1378
1057
  if (signal == null ? void 0 : signal.aborted) {
1379
1058
  break;
1380
1059
  }
1381
- yield new SemanticEvent("generate_content_chunk", chunk);
1060
+ yield new SemanticEvent(event.type, event);
1382
1061
  }
1383
1062
  }
1384
- buildRequest(inferenceRequest) {
1385
- const specification = inferenceRequest.model.specification;
1386
- const { contents, systemInstruction } = this.mapContextToRequest(inferenceRequest.context);
1063
+ };
1064
+
1065
+ // src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts
1066
+ import { GoogleGenAI } from "@google/genai";
1067
+
1068
+ // src/infrastructure/providers/gemini/endpoints/gemini-generate-content-mapper.ts
1069
+ var GeminiGenerateContentMapper = class {
1070
+ toRequest(inferenceParams) {
1071
+ const { contents, systemInstruction } = this.mapContextItems(inferenceParams);
1387
1072
  const config = {};
1388
1073
  if (systemInstruction) {
1389
1074
  config.systemInstruction = systemInstruction;
1390
1075
  }
1391
- if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
1076
+ if (inferenceParams.tools && inferenceParams.tools.length > 0) {
1392
1077
  config.tools = [
1393
1078
  {
1394
- functionDeclarations: inferenceRequest.model.getTools().map((tool) => {
1395
- return {
1396
- name: tool.name,
1397
- description: tool.description,
1398
- parametersJsonSchema: tool.parameters
1399
- };
1400
- })
1079
+ functionDeclarations: inferenceParams.tools.map((tool) => ({
1080
+ name: tool.name,
1081
+ description: tool.description,
1082
+ parametersJsonSchema: tool.parameters
1083
+ }))
1401
1084
  }
1402
1085
  ];
1403
1086
  }
1404
- if (specification.supportReasoningEffort) {
1405
- const effort = inferenceRequest.model.getReasoningEffort();
1406
- const thinkingLevel = effort === "none" ? "minimal" : effort;
1407
- config.thinkingConfig = { thinkingLevel, includeThoughts: true };
1408
- }
1409
- if (inferenceRequest.model.hasStructuredOutput()) {
1410
- if (!specification.supportStructuredOutput) {
1411
- throw new Error(`Structured output is not supported for model: ${specification.name}`);
1412
- }
1413
- const format = inferenceRequest.model.getStructuredOutput();
1087
+ if (inferenceParams.structuredOutput) {
1414
1088
  config.responseMimeType = "application/json";
1415
- config.responseSchema = format.schema;
1089
+ config.responseSchema = inferenceParams.structuredOutput.schema;
1416
1090
  }
1417
- return { model: specification.name, contents, config };
1418
- }
1419
- extractTokenUsage(response) {
1420
- var _a, _b, _c, _d, _e;
1421
- const usage = response.usageMetadata;
1422
- if (!usage) {
1423
- return void 0;
1091
+ if (inferenceParams.reasoningEffort) {
1092
+ config.thinkingConfig = {
1093
+ thinkingLevel: inferenceParams.reasoningEffort,
1094
+ includeThoughts: true
1095
+ };
1424
1096
  }
1425
- return new TokenUsage(
1426
- (_a = usage.promptTokenCount) != null ? _a : 0,
1427
- (_b = usage.candidatesTokenCount) != null ? _b : 0,
1428
- (_c = usage.totalTokenCount) != null ? _c : 0,
1429
- new InputTokenDetails((_d = usage.cachedContentTokenCount) != null ? _d : 0),
1430
- new OutputTokenDetails((_e = usage.thoughtsTokenCount) != null ? _e : 0)
1431
- );
1097
+ const request = {
1098
+ model: inferenceParams.model,
1099
+ contents,
1100
+ config
1101
+ };
1102
+ if (inferenceParams.streaming) {
1103
+ request.stream = inferenceParams.streaming;
1104
+ }
1105
+ return request;
1106
+ }
1107
+ toResponse(response) {
1108
+ const contextItems = this.extractContextItems(response);
1109
+ const tokenUsage = this.extractTokenUsage(response);
1110
+ return new InferenceResponse(contextItems, tokenUsage);
1432
1111
  }
1433
- mapContextToRequest(context) {
1112
+ mapContextItems(inferenceParams) {
1434
1113
  var _a;
1114
+ const context = inferenceParams.context;
1435
1115
  const contents = [];
1436
1116
  const system = [];
1437
1117
  const callNames = /* @__PURE__ */ new Map();
@@ -1474,45 +1154,6 @@ var GeminiGenerateContent = class {
1474
1154
  systemInstruction: system.length > 0 ? system.join("\n\n") : void 0
1475
1155
  };
1476
1156
  }
1477
- extractContextItems(response) {
1478
- var _a, _b, _c, _d, _e, _f;
1479
- const items = [];
1480
- const parts = (_d = (_c = (_b = (_a = response.candidates) == null ? void 0 : _a[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts) != null ? _d : [];
1481
- for (const part of parts) {
1482
- if (part.thought && part.text) {
1483
- items.push(
1484
- ReasoningItem.rehydrate({
1485
- content: InputText.rehydrate({ text: part.text }),
1486
- encryptedContent: void 0,
1487
- summary: []
1488
- })
1489
- );
1490
- continue;
1491
- }
1492
- if (part.text) {
1493
- items.push(ModelMessageItem.rehydrate({ text: part.text }));
1494
- continue;
1495
- }
1496
- if (part.functionCall) {
1497
- items.push(
1498
- FunctionCallItem.rehydrate({
1499
- callId: (_e = part.functionCall.id) != null ? _e : "",
1500
- name: part.functionCall.name,
1501
- args: JSON.stringify((_f = part.functionCall.args) != null ? _f : {})
1502
- })
1503
- );
1504
- }
1505
- }
1506
- return items;
1507
- }
1508
- parseResponse(output) {
1509
- try {
1510
- const parsed = JSON.parse(output);
1511
- return parsed && typeof parsed === "object" ? parsed : { output };
1512
- } catch (e) {
1513
- return { output };
1514
- }
1515
- }
1516
1157
  addPart(contents, role, part) {
1517
1158
  const last = contents[contents.length - 1];
1518
1159
  if ((last == null ? void 0 : last.role) === role) {
@@ -1521,195 +1162,118 @@ var GeminiGenerateContent = class {
1521
1162
  }
1522
1163
  contents.push({ role, parts: [part] });
1523
1164
  }
1524
- };
1525
-
1526
- // src/infrastructure/providers/gemini/reasoning-effort.ts
1527
- var GeminiReasoningEffort = class {
1528
- constructor(reasoningEffort) {
1529
- this.reasoningEffort = reasoningEffort;
1530
- }
1531
- setReasoningEffort(effort) {
1532
- this.reasoningEffort = effort;
1533
- }
1534
- getReasoningEffort() {
1535
- if (!this.reasoningEffort) {
1536
- throw new Error("Reasoning effort not supported");
1537
- }
1538
- return this.reasoningEffort;
1539
- }
1540
- };
1541
-
1542
- // src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts
1543
- var Gemini35Flash = class {
1544
- constructor() {
1545
- this.specification = {
1546
- name: "gemini-3.5-flash",
1547
- provider: "google",
1548
- supportReasoningEffort: true,
1549
- defaultReasoningEffort: "medium",
1550
- supportStreaming: true,
1551
- contextWindowSize: 1048576,
1552
- maxOutputTokens: 64e3,
1553
- supportFunctionCalling: true,
1554
- supportStructuredOutput: true
1555
- };
1556
- this.tools = [];
1557
- this.streaming = false;
1558
- this.structuredOutput = void 0;
1559
- this.effort = new GeminiReasoningEffort(
1560
- this.specification.defaultReasoningEffort
1561
- );
1562
- }
1563
- setStreaming(streaming) {
1564
- this.streaming = streaming;
1565
- }
1566
- getStreaming() {
1567
- return this.streaming;
1568
- }
1569
- setTools(tools) {
1570
- this.tools = tools;
1571
- }
1572
- getTools() {
1573
- return this.tools;
1574
- }
1575
- setReasoningEffort(effort) {
1576
- this.effort.setReasoningEffort(effort);
1577
- }
1578
- getReasoningEffort() {
1579
- return this.effort.getReasoningEffort();
1580
- }
1581
- setStructuredOutput(format) {
1582
- this.structuredOutput = format;
1583
- }
1584
- getStructuredOutput() {
1585
- return this.structuredOutput;
1586
- }
1587
- hasStructuredOutput() {
1588
- return this.structuredOutput !== void 0;
1589
- }
1590
- };
1591
-
1592
- // src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
1593
- var Gemini31Pro = class {
1594
- constructor() {
1595
- this.specification = {
1596
- name: "gemini-3.1-pro-preview",
1597
- provider: "google",
1598
- supportReasoningEffort: true,
1599
- defaultReasoningEffort: "high",
1600
- supportStreaming: true,
1601
- contextWindowSize: 1048576,
1602
- maxOutputTokens: 64e3,
1603
- supportFunctionCalling: true,
1604
- supportStructuredOutput: true
1605
- };
1606
- this.tools = [];
1607
- this.streaming = false;
1608
- this.structuredOutput = void 0;
1609
- this.effort = new GeminiReasoningEffort(
1610
- this.specification.defaultReasoningEffort
1611
- );
1612
- }
1613
- setStreaming(streaming) {
1614
- this.streaming = streaming;
1615
- }
1616
- getStreaming() {
1617
- return this.streaming;
1618
- }
1619
- setTools(tools) {
1620
- this.tools = tools;
1621
- }
1622
- getTools() {
1623
- return this.tools;
1624
- }
1625
- setReasoningEffort(effort) {
1626
- this.effort.setReasoningEffort(effort);
1627
- }
1628
- getReasoningEffort() {
1629
- return this.effort.getReasoningEffort();
1630
- }
1631
- setStructuredOutput(format) {
1632
- this.structuredOutput = format;
1165
+ parseResponse(output) {
1166
+ try {
1167
+ const parsed = JSON.parse(output);
1168
+ return parsed && typeof parsed === "object" ? parsed : { output };
1169
+ } catch (e) {
1170
+ return { output };
1171
+ }
1633
1172
  }
1634
- getStructuredOutput() {
1635
- return this.structuredOutput;
1173
+ extractTokenUsage(response) {
1174
+ var _a, _b, _c, _d, _e;
1175
+ const usage = response.usageMetadata;
1176
+ if (!usage) {
1177
+ return void 0;
1178
+ }
1179
+ return new TokenUsage(
1180
+ (_a = usage.promptTokenCount) != null ? _a : 0,
1181
+ (_b = usage.candidatesTokenCount) != null ? _b : 0,
1182
+ (_c = usage.totalTokenCount) != null ? _c : 0,
1183
+ new InputTokenDetails((_d = usage.cachedContentTokenCount) != null ? _d : 0),
1184
+ new OutputTokenDetails((_e = usage.thoughtsTokenCount) != null ? _e : 0)
1185
+ );
1636
1186
  }
1637
- hasStructuredOutput() {
1638
- return this.structuredOutput !== void 0;
1187
+ extractContextItems(response) {
1188
+ var _a, _b, _c, _d, _e, _f;
1189
+ const items = [];
1190
+ const parts = (_d = (_c = (_b = (_a = response.candidates) == null ? void 0 : _a[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts) != null ? _d : [];
1191
+ for (const part of parts) {
1192
+ if (part.thought && part.text) {
1193
+ items.push(
1194
+ ReasoningItem.rehydrate({
1195
+ content: InputText.rehydrate({ text: part.text }),
1196
+ encryptedContent: void 0,
1197
+ summary: []
1198
+ })
1199
+ );
1200
+ continue;
1201
+ }
1202
+ if (part.text) {
1203
+ items.push(ModelMessageItem.rehydrate({ text: part.text }));
1204
+ continue;
1205
+ }
1206
+ if (part.functionCall) {
1207
+ items.push(
1208
+ FunctionCallItem.rehydrate({
1209
+ callId: (_e = part.functionCall.id) != null ? _e : "",
1210
+ name: part.functionCall.name,
1211
+ args: JSON.stringify((_f = part.functionCall.args) != null ? _f : {})
1212
+ })
1213
+ );
1214
+ }
1215
+ }
1216
+ return items;
1639
1217
  }
1640
1218
  };
1641
1219
 
1642
- // src/infrastructure/providers/openai/runtime/openai-chat-completions.ts
1643
- import OpenAI2 from "openai";
1644
- var OpenAIChatCompletions = class {
1645
- constructor(config = {}) {
1646
- var _a;
1647
- this.client = new OpenAI2({
1648
- baseURL: config.baseURL,
1649
- apiKey: config.apiKey
1650
- });
1651
- this.extraBody = (_a = config.extraBody) != null ? _a : {};
1220
+ // src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts
1221
+ var GeminiGenerateContent = class {
1222
+ constructor(endpointMapper = new GeminiGenerateContentMapper()) {
1223
+ this.endpointMapper = endpointMapper;
1224
+ this.client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
1652
1225
  }
1653
- async infer(inferenceRequest) {
1654
- const response = await this.client.chat.completions.create(this.buildRequest(inferenceRequest));
1655
- const contextItems = this.extractContextItems(response);
1656
- const tokenUsage = this.extractTokenUsage(response);
1657
- return new InferenceResponse(contextItems, tokenUsage);
1226
+ async infer(inferenceParams) {
1227
+ const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
1228
+ const response = await this.client.models.generateContent(inferenceRequest);
1229
+ return this.endpointMapper.toResponse(response);
1658
1230
  }
1659
- async *stream(inferenceRequest, signal) {
1660
- var _a;
1661
- const stream = await this.client.chat.completions.create({
1662
- ...this.buildRequest(inferenceRequest),
1663
- stream: true
1664
- });
1665
- for await (const event of stream) {
1231
+ async *stream(inferenceParams, signal) {
1232
+ const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
1233
+ const stream = await this.client.models.generateContentStream(inferenceRequest);
1234
+ for await (const chunk of stream) {
1666
1235
  if (signal == null ? void 0 : signal.aborted) {
1667
1236
  break;
1668
1237
  }
1669
- yield new SemanticEvent((_a = event.object) != null ? _a : "chat.completion.chunk", event);
1238
+ yield new SemanticEvent("generate_content_chunk", chunk);
1670
1239
  }
1671
1240
  }
1672
- buildRequest(inferenceRequest) {
1673
- const specification = inferenceRequest.model.specification;
1241
+ };
1242
+
1243
+ // src/infrastructure/providers/openai/endpoints/openai-chat-completions-mapper.ts
1244
+ var OpenAIChatCompletionsMapper = class {
1245
+ toRequest(inferenceParams) {
1674
1246
  const request = {
1675
- ...this.extraBody,
1676
- model: specification.name,
1677
- messages: this.mapContextToRequest(inferenceRequest.context)
1247
+ model: inferenceParams.model,
1248
+ messages: this.mapContextItems(inferenceParams)
1678
1249
  };
1679
- if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
1680
- request.tools = inferenceRequest.model.getTools().map((tool) => {
1681
- return {
1682
- type: "function",
1683
- function: {
1684
- name: tool.name,
1685
- description: tool.description,
1686
- parameters: tool.parameters
1687
- }
1688
- };
1689
- });
1250
+ if (inferenceParams.tools && inferenceParams.tools.length > 0) {
1251
+ request.tools = inferenceParams.tools.map((tool) => ({
1252
+ type: "function",
1253
+ function: {
1254
+ name: tool.name,
1255
+ description: tool.description,
1256
+ parameters: tool.parameters
1257
+ }
1258
+ }));
1259
+ }
1260
+ if (inferenceParams.reasoningEffort) {
1261
+ request.reasoning_effort = inferenceParams.reasoningEffort;
1690
1262
  }
1691
- if (specification.supportReasoningEffort) {
1692
- request.reasoning_effort = inferenceRequest.model.getReasoningEffort();
1263
+ if (inferenceParams.streaming) {
1264
+ request.stream = inferenceParams.streaming;
1693
1265
  }
1694
1266
  return request;
1695
1267
  }
1696
- extractTokenUsage(response) {
1697
- var _a, _b, _c, _d;
1698
- if (!response.usage) {
1699
- return void 0;
1700
- }
1701
- return new TokenUsage(
1702
- response.usage.prompt_tokens,
1703
- response.usage.completion_tokens,
1704
- response.usage.total_tokens,
1705
- new InputTokenDetails((_b = (_a = response.usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
1706
- new OutputTokenDetails((_d = (_c = response.usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
1707
- );
1268
+ toResponse(response) {
1269
+ const contextItems = this.extractContextItems(response);
1270
+ const tokenUsage = this.extractTokenUsage(response);
1271
+ return new InferenceResponse(contextItems, tokenUsage);
1708
1272
  }
1709
- mapContextToRequest(context) {
1273
+ mapContextItems(inferenceParams) {
1710
1274
  var _a;
1711
1275
  const messages = [];
1712
- for (const item of context.getItems()) {
1276
+ for (const item of inferenceParams.context.getItems()) {
1713
1277
  if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
1714
1278
  messages.push({ role: "system", content: item.content.text });
1715
1279
  continue;
@@ -1743,6 +1307,19 @@ var OpenAIChatCompletions = class {
1743
1307
  }
1744
1308
  return messages;
1745
1309
  }
1310
+ extractTokenUsage(response) {
1311
+ var _a, _b, _c, _d;
1312
+ if (!response.usage) {
1313
+ return void 0;
1314
+ }
1315
+ return new TokenUsage(
1316
+ response.usage.prompt_tokens,
1317
+ response.usage.completion_tokens,
1318
+ response.usage.total_tokens,
1319
+ new InputTokenDetails((_b = (_a = response.usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
1320
+ new OutputTokenDetails((_d = (_c = response.usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
1321
+ );
1322
+ }
1746
1323
  extractContextItems(response) {
1747
1324
  var _a, _b, _c;
1748
1325
  const items = [];
@@ -1775,179 +1352,482 @@ var OpenAIChatCompletions = class {
1775
1352
  }
1776
1353
  };
1777
1354
 
1778
- // src/application/services/inference-runner.ts
1779
- var InferenceRunner = class {
1780
- async *run(context, modelInfo, signal) {
1781
- const { model, endpoint } = modelInfo;
1782
- const request = new InferenceRequest(model, context);
1783
- if (model.getStreaming()) {
1784
- yield* endpoint.stream(request);
1785
- return;
1786
- }
1787
- const response = await endpoint.infer(request);
1788
- for (const item of response.contextItems) {
1789
- if (signal == null ? void 0 : signal.aborted) {
1790
- break;
1791
- }
1792
- yield item;
1793
- }
1355
+ // src/infrastructure/providers/openai/endpoints/openai-chat-completions.ts
1356
+ import OpenAI2 from "openai";
1357
+ var OpenAIChatCompletions = class {
1358
+ constructor(endpointMapper = new OpenAIChatCompletionsMapper(), config = {}) {
1359
+ var _a;
1360
+ this.endpointMapper = endpointMapper;
1361
+ this.client = new OpenAI2({
1362
+ baseURL: config.baseURL,
1363
+ apiKey: config.apiKey
1364
+ });
1365
+ this.extraBody = (_a = config.extraBody) != null ? _a : {};
1794
1366
  }
1795
- };
1796
-
1797
- // src/application/use-cases/run-inference.ts
1798
- var RunInference = class {
1799
- constructor(modelRepository, inferenceRunner) {
1800
- this.modelRepository = modelRepository;
1801
- this.inferenceRunner = inferenceRunner;
1367
+ buildRequest(inferenceParams) {
1368
+ return {
1369
+ ...this.extraBody,
1370
+ ...this.endpointMapper.toRequest(inferenceParams)
1371
+ };
1802
1372
  }
1803
- setModelCapabilities(model, inferenceParams) {
1804
- const { streaming, tools, reasoningEffort, structuredOutput } = inferenceParams;
1805
- if (streaming) {
1806
- model.setStreaming(true);
1807
- }
1808
- if (tools) {
1809
- model.setTools(tools);
1810
- }
1811
- if (reasoningEffort) {
1812
- model.setReasoningEffort(reasoningEffort);
1813
- }
1814
- if (structuredOutput) {
1815
- model.setStructuredOutput(structuredOutput);
1816
- }
1817
- return model;
1373
+ async infer(inferenceParams) {
1374
+ const response = await this.client.chat.completions.create(this.buildRequest(inferenceParams));
1375
+ return this.endpointMapper.toResponse(response);
1818
1376
  }
1819
- async execute(inferenceParams) {
1820
- const { model, context, caller, environment, signal } = inferenceParams;
1821
- const modelInfo = this.modelRepository.getModelInfo(model);
1822
- const generativeModel = this.setModelCapabilities(modelInfo.model, inferenceParams);
1823
- modelInfo.model = generativeModel;
1824
- const result = this.inferenceRunner.run(context, modelInfo, signal);
1825
- for await (const item of result) {
1377
+ async *stream(inferenceParams, signal) {
1378
+ var _a;
1379
+ const stream = await this.client.chat.completions.create(this.buildRequest(inferenceParams));
1380
+ for await (const event of stream) {
1826
1381
  if (signal == null ? void 0 : signal.aborted) {
1827
1382
  break;
1828
1383
  }
1829
- if (item instanceof ReasoningItem) {
1830
- environment.deliverReasoning(caller, item);
1831
- } else if (item instanceof FunctionCallItem) {
1832
- environment.deliverFunctionCall(caller, item);
1833
- } else if (item instanceof ModelMessageItem) {
1834
- environment.deliverModelMessage(caller, item);
1835
- } else if (item instanceof SemanticEvent) {
1836
- environment.deliverSemanticEvent(caller, item);
1837
- }
1384
+ yield new SemanticEvent((_a = event.object) != null ? _a : "chat.completion.chunk", event);
1838
1385
  }
1839
1386
  }
1840
1387
  };
1841
1388
 
1842
- // src/application/use-cases/execute-function-call.ts
1843
- var ExecuteFunctionCall = class {
1844
- constructor(functionCallRunner) {
1845
- this.functionCallRunner = functionCallRunner;
1846
- }
1847
- async execute(environment, functionCallItem, tool, caller, signal) {
1848
- const stream = this.functionCallRunner.run(functionCallItem, tool, signal);
1849
- for await (const item of stream) {
1850
- environment.deliverFunctionCallOutput(caller, item);
1851
- }
1852
- }
1389
+ // src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
1390
+ var claudeSonnet46Specification = {
1391
+ name: "claude-sonnet-4-6",
1392
+ provider: "anthropic",
1393
+ supportsReasoningEffort: true,
1394
+ supportedReasoningEfforts: ["max", "high", "medium", "low"],
1395
+ supportedContextItemTypes: [
1396
+ "user_message",
1397
+ "system_message",
1398
+ "developer_message",
1399
+ "reasoning",
1400
+ "function_call",
1401
+ "function_call_output",
1402
+ "model_message"
1403
+ ],
1404
+ supportsStreaming: true,
1405
+ contextWindowSize: 2e5,
1406
+ maxOutputTokens: 64e3,
1407
+ supportsFunctionCalling: true,
1408
+ supportsStructuredOutput: true
1409
+ };
1410
+
1411
+ // src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts
1412
+ var claudeOpus48Specification = {
1413
+ name: "claude-opus-4-8",
1414
+ provider: "anthropic",
1415
+ supportsReasoningEffort: true,
1416
+ supportedReasoningEfforts: ["max", "xhigh", "high", "medium", "low"],
1417
+ supportedContextItemTypes: [
1418
+ "user_message",
1419
+ "system_message",
1420
+ "developer_message",
1421
+ "reasoning",
1422
+ "function_call",
1423
+ "function_call_output",
1424
+ "model_message"
1425
+ ],
1426
+ supportsStreaming: true,
1427
+ contextWindowSize: 2e5,
1428
+ maxOutputTokens: 32e3,
1429
+ supportsFunctionCalling: true,
1430
+ supportsStructuredOutput: true
1431
+ };
1432
+
1433
+ // src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
1434
+ var claudeOpus47Specification = {
1435
+ name: "claude-opus-4-7",
1436
+ provider: "anthropic",
1437
+ supportsReasoningEffort: true,
1438
+ supportedReasoningEfforts: ["max", "xhigh", "high", "medium", "low"],
1439
+ supportedContextItemTypes: [
1440
+ "user_message",
1441
+ "system_message",
1442
+ "developer_message",
1443
+ "reasoning",
1444
+ "function_call",
1445
+ "function_call_output",
1446
+ "model_message"
1447
+ ],
1448
+ supportsStreaming: true,
1449
+ contextWindowSize: 2e5,
1450
+ maxOutputTokens: 32e3,
1451
+ supportsFunctionCalling: true,
1452
+ supportsStructuredOutput: true
1453
+ };
1454
+
1455
+ // src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts
1456
+ var gemini35FlashSpecification = {
1457
+ name: "gemini-3.5-flash",
1458
+ provider: "google",
1459
+ supportsReasoningEffort: true,
1460
+ supportedReasoningEfforts: ["high", "medium", "low", "minimal", "none"],
1461
+ supportedContextItemTypes: [
1462
+ "user_message",
1463
+ "system_message",
1464
+ "developer_message",
1465
+ "reasoning",
1466
+ "function_call",
1467
+ "function_call_output",
1468
+ "model_message"
1469
+ ],
1470
+ supportsStreaming: true,
1471
+ contextWindowSize: 1048576,
1472
+ maxOutputTokens: 64e3,
1473
+ supportsFunctionCalling: true,
1474
+ supportsStructuredOutput: true
1475
+ };
1476
+
1477
+ // src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
1478
+ var gemini31ProSpecification = {
1479
+ name: "gemini-3.1-pro-preview",
1480
+ provider: "google",
1481
+ supportsReasoningEffort: true,
1482
+ supportedReasoningEfforts: ["high", "medium", "low", "minimal", "none"],
1483
+ supportedContextItemTypes: [
1484
+ "user_message",
1485
+ "system_message",
1486
+ "developer_message",
1487
+ "reasoning",
1488
+ "function_call",
1489
+ "function_call_output",
1490
+ "model_message"
1491
+ ],
1492
+ supportsStreaming: true,
1493
+ contextWindowSize: 1048576,
1494
+ maxOutputTokens: 64e3,
1495
+ supportsFunctionCalling: true,
1496
+ supportsStructuredOutput: true
1497
+ };
1498
+
1499
+ // src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts
1500
+ var deepSeekV4FlashSpecification = {
1501
+ name: "deepseek-v4-flash",
1502
+ provider: "deepseek",
1503
+ supportsReasoningEffort: true,
1504
+ supportedReasoningEfforts: ["max", "high", "medium", "low", "none"],
1505
+ supportedContextItemTypes: [
1506
+ "user_message",
1507
+ "system_message",
1508
+ "developer_message",
1509
+ "reasoning",
1510
+ "function_call",
1511
+ "function_call_output",
1512
+ "model_message"
1513
+ ],
1514
+ supportsStreaming: true,
1515
+ contextWindowSize: 1e6,
1516
+ maxOutputTokens: 384e3,
1517
+ supportsFunctionCalling: true,
1518
+ supportsStructuredOutput: false
1519
+ };
1520
+
1521
+ // src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
1522
+ var deepSeekV4ProSpecification = {
1523
+ name: "deepseek-v4-pro",
1524
+ provider: "deepseek",
1525
+ supportsReasoningEffort: true,
1526
+ supportedReasoningEfforts: ["max", "high", "medium", "low", "none"],
1527
+ supportedContextItemTypes: [
1528
+ "user_message",
1529
+ "system_message",
1530
+ "developer_message",
1531
+ "reasoning",
1532
+ "function_call",
1533
+ "function_call_output",
1534
+ "model_message"
1535
+ ],
1536
+ supportsStreaming: true,
1537
+ contextWindowSize: 1e6,
1538
+ maxOutputTokens: 384e3,
1539
+ supportsFunctionCalling: true,
1540
+ supportsStructuredOutput: false
1541
+ };
1542
+
1543
+ // src/infrastructure/providers/openai/models/gpt-5-4.ts
1544
+ var gpt54Specification = {
1545
+ name: "gpt-5.4",
1546
+ provider: "openai",
1547
+ supportsReasoningEffort: true,
1548
+ supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
1549
+ supportedContextItemTypes: [
1550
+ "user_message",
1551
+ "system_message",
1552
+ "developer_message",
1553
+ "reasoning",
1554
+ "function_call",
1555
+ "function_call_output",
1556
+ "model_message"
1557
+ ],
1558
+ supportsStreaming: true,
1559
+ contextWindowSize: 105e4,
1560
+ maxOutputTokens: 128e3,
1561
+ supportsFunctionCalling: true,
1562
+ supportsStructuredOutput: true
1563
+ };
1564
+
1565
+ // src/infrastructure/providers/openai/models/gpt-5-4-mini.ts
1566
+ var gpt54MiniSpecification = {
1567
+ name: "gpt-5.4-mini",
1568
+ provider: "openai",
1569
+ supportsReasoningEffort: true,
1570
+ supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
1571
+ supportedContextItemTypes: [
1572
+ "user_message",
1573
+ "system_message",
1574
+ "developer_message",
1575
+ "reasoning",
1576
+ "function_call",
1577
+ "function_call_output",
1578
+ "model_message"
1579
+ ],
1580
+ supportsStreaming: true,
1581
+ contextWindowSize: 4e5,
1582
+ maxOutputTokens: 128e3,
1583
+ supportsFunctionCalling: true,
1584
+ supportsStructuredOutput: true
1585
+ };
1586
+
1587
+ // src/infrastructure/providers/openai/models/gpt-5-4-nano.ts
1588
+ var gpt54NanoSpecification = {
1589
+ name: "gpt-5.4-nano",
1590
+ provider: "openai",
1591
+ supportsReasoningEffort: true,
1592
+ supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
1593
+ supportedContextItemTypes: [
1594
+ "user_message",
1595
+ "system_message",
1596
+ "developer_message",
1597
+ "reasoning",
1598
+ "function_call",
1599
+ "function_call_output",
1600
+ "model_message"
1601
+ ],
1602
+ supportsStreaming: true,
1603
+ contextWindowSize: 4e5,
1604
+ maxOutputTokens: 128e3,
1605
+ supportsFunctionCalling: true,
1606
+ supportsStructuredOutput: true
1607
+ };
1608
+
1609
+ // src/infrastructure/providers/openai/models/gpt-5-5.ts
1610
+ var gpt55Specification = {
1611
+ name: "gpt-5.5",
1612
+ provider: "openai",
1613
+ supportsReasoningEffort: true,
1614
+ supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
1615
+ supportedContextItemTypes: [
1616
+ "user_message",
1617
+ "system_message",
1618
+ "developer_message",
1619
+ "reasoning",
1620
+ "function_call",
1621
+ "function_call_output",
1622
+ "model_message"
1623
+ ],
1624
+ supportsStreaming: true,
1625
+ contextWindowSize: 105e4,
1626
+ maxOutputTokens: 128e3,
1627
+ supportsFunctionCalling: true,
1628
+ supportsStructuredOutput: true
1629
+ };
1630
+
1631
+ // src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
1632
+ var claudeHaiku45Specification = {
1633
+ name: "claude-haiku-4-5",
1634
+ provider: "anthropic",
1635
+ supportsReasoningEffort: true,
1636
+ supportedReasoningEfforts: ["high", "medium", "low", "none"],
1637
+ supportedContextItemTypes: [
1638
+ "user_message",
1639
+ "system_message",
1640
+ "developer_message",
1641
+ "reasoning",
1642
+ "function_call",
1643
+ "function_call_output",
1644
+ "model_message"
1645
+ ],
1646
+ supportsStreaming: true,
1647
+ contextWindowSize: 2e5,
1648
+ maxOutputTokens: 64e3,
1649
+ supportsFunctionCalling: true,
1650
+ supportsStructuredOutput: true
1853
1651
  };
1854
1652
 
1855
- // src/application/services/model-repository.ts
1856
- var ModelRepository = class {
1857
- getModelInfo(model) {
1858
- switch (model) {
1859
- case "gpt-5-4":
1860
- return { endpoint: new OpenAIResponses(), model: new Gpt54() };
1861
- case "gpt-5-4-mini":
1862
- return { endpoint: new OpenAIResponses(), model: new Gpt54Mini() };
1863
- case "gpt-5-4-nano":
1864
- return { endpoint: new OpenAIResponses(), model: new Gpt54Nano() };
1865
- case "gpt-5-5":
1866
- return { endpoint: new OpenAIResponses(), model: new Gpt55() };
1867
- case "claude-4-5-haiku":
1868
- return { endpoint: new AnthropicMessages(), model: new ClaudeHaiku45() };
1869
- case "claude-4-6-sonnet":
1870
- return { endpoint: new AnthropicMessages(), model: new ClaudeSonnet46() };
1871
- case "claude-4-7-opus":
1872
- return { endpoint: new AnthropicMessages(), model: new ClaudeOpus47() };
1873
- case "claude-4-8-opus":
1874
- return { endpoint: new AnthropicMessages(), model: new ClaudeOpus48() };
1875
- case "gemini-3-5-flash":
1876
- return { endpoint: new GeminiGenerateContent(), model: new Gemini35Flash() };
1877
- case "gemini-3-1-pro":
1878
- return { endpoint: new GeminiGenerateContent(), model: new Gemini31Pro() };
1653
+ // src/infrastructure/repository/generative-model-repository.ts
1654
+ var InMemoryGenerativeModelRepository = class {
1655
+ getByModelName(modelName) {
1656
+ let generativeModel = void 0;
1657
+ switch (modelName) {
1658
+ case "gpt-5.4":
1659
+ generativeModel = {
1660
+ endpoint: new OpenAIResponses(),
1661
+ specification: gpt54Specification
1662
+ };
1663
+ break;
1664
+ case "gpt-5.4-mini":
1665
+ generativeModel = {
1666
+ endpoint: new OpenAIResponses(),
1667
+ specification: gpt54MiniSpecification
1668
+ };
1669
+ break;
1670
+ case "gpt-5.4-nano":
1671
+ generativeModel = {
1672
+ endpoint: new OpenAIResponses(),
1673
+ specification: gpt54NanoSpecification
1674
+ };
1675
+ break;
1676
+ case "gpt-5.5":
1677
+ generativeModel = {
1678
+ endpoint: new OpenAIResponses(),
1679
+ specification: gpt55Specification
1680
+ };
1681
+ break;
1682
+ case "claude-haiku-4-5":
1683
+ generativeModel = {
1684
+ endpoint: new AnthropicMessages(),
1685
+ specification: claudeHaiku45Specification
1686
+ };
1687
+ break;
1688
+ case "claude-sonnet-4-6":
1689
+ generativeModel = {
1690
+ endpoint: new AnthropicMessages(),
1691
+ specification: claudeSonnet46Specification
1692
+ };
1693
+ break;
1694
+ case "claude-opus-4-7":
1695
+ generativeModel = {
1696
+ endpoint: new AnthropicMessages(),
1697
+ specification: claudeOpus47Specification
1698
+ };
1699
+ break;
1700
+ case "claude-opus-4-8":
1701
+ generativeModel = {
1702
+ endpoint: new AnthropicMessages(),
1703
+ specification: claudeOpus48Specification
1704
+ };
1705
+ break;
1706
+ case "gemini-3.5-flash":
1707
+ generativeModel = {
1708
+ endpoint: new GeminiGenerateContent(),
1709
+ specification: gemini35FlashSpecification
1710
+ };
1711
+ break;
1712
+ case "gemini-3.1-pro-preview":
1713
+ generativeModel = {
1714
+ endpoint: new GeminiGenerateContent(),
1715
+ specification: gemini31ProSpecification
1716
+ };
1717
+ break;
1879
1718
  case "deepseek-v4-flash":
1880
- return { endpoint: new OpenAIChatCompletions(), model: new DeepSeekV4Flash() };
1719
+ generativeModel = {
1720
+ endpoint: new OpenAIChatCompletions(),
1721
+ specification: deepSeekV4FlashSpecification
1722
+ };
1723
+ break;
1881
1724
  case "deepseek-v4-pro":
1882
- return { endpoint: new OpenAIChatCompletions(), model: new DeepSeekV4Pro() };
1883
- default:
1884
- throw new Error(`Unsupported model: ${model}`);
1725
+ generativeModel = {
1726
+ endpoint: new OpenAIChatCompletions(),
1727
+ specification: deepSeekV4ProSpecification
1728
+ };
1885
1729
  }
1730
+ if (!generativeModel) {
1731
+ throw new Error(`Unsupported model: ${modelName}`);
1732
+ }
1733
+ return Promise.resolve(generativeModel);
1886
1734
  }
1887
1735
  };
1888
1736
 
1889
- // src/application/services/function-call-runner.ts
1890
- var FunctionCallRunner = class {
1891
- async *run(call, tool, signal) {
1892
- if (signal == null ? void 0 : signal.aborted) {
1893
- return;
1737
+ // src/domain/generative-model/request-validation/reasoning-effort.ts
1738
+ var ReasoningEffortValidation = class {
1739
+ constructor() {
1740
+ this.name = "reasoning-effort";
1741
+ }
1742
+ isValid(inferenceParams, model) {
1743
+ if (inferenceParams.reasoningEffort === void 0) {
1744
+ return true;
1894
1745
  }
1895
- if (!tool) throw new Error(`Unknown tool: ${call.name}`);
1896
- const result = await tool.invoke(JSON.parse(call.args));
1897
- yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
1746
+ if (!model.supportsReasoningEffort) {
1747
+ return false;
1748
+ }
1749
+ return model.supportedReasoningEfforts.includes(inferenceParams.reasoningEffort);
1898
1750
  }
1899
1751
  };
1900
1752
 
1901
- // src/application/participants/participant.ts
1902
- var BaseParticipant = class extends Participant {
1903
- onFunctionCall(item) {
1904
- }
1905
- onExternalFunctionCall(source, item) {
1906
- }
1907
- onFunctionCallOutput(item) {
1908
- }
1909
- onExternalFunctionCallOutput(source, item) {
1910
- }
1911
- onReasoning(item) {
1912
- }
1913
- onExternalReasoning(source, item) {
1914
- }
1915
- onModelMessage(item) {
1916
- }
1917
- onExternalModelMessage(source, item) {
1753
+ // src/domain/generative-model/request-validation/tool-calling.ts
1754
+ var ToolCallingValidation = class {
1755
+ constructor() {
1756
+ this.name = "tool-calling";
1918
1757
  }
1919
- onMessage(message) {
1758
+ isValid(inferenceParams, model) {
1759
+ if (inferenceParams.tools === void 0) {
1760
+ return true;
1761
+ }
1762
+ return model.supportsFunctionCalling;
1920
1763
  }
1921
- onJoined() {
1764
+ };
1765
+
1766
+ // src/domain/generative-model/request-validation/streaming.ts
1767
+ var StreamingValidation = class {
1768
+ constructor() {
1769
+ this.name = "streaming";
1922
1770
  }
1923
- onLeft() {
1771
+ isValid(inferenceParams, model) {
1772
+ if (!inferenceParams.streaming) {
1773
+ return true;
1774
+ }
1775
+ return model.supportsStreaming;
1924
1776
  }
1925
- onParticipantJoined(participant) {
1777
+ };
1778
+
1779
+ // src/domain/generative-model/request-validation/context.ts
1780
+ function getContextItemValidationKey(item) {
1781
+ if (item instanceof UserMessageItem) {
1782
+ return "user_message";
1926
1783
  }
1927
- onParticipantLeft(participant) {
1784
+ if (item instanceof SystemMessageItem) {
1785
+ return "system_message";
1928
1786
  }
1929
- onInternalEvent(item) {
1787
+ if (item instanceof DeveloperMessageItem) {
1788
+ return "developer_message";
1930
1789
  }
1931
- onExternalEvent(source, item) {
1790
+ if (item instanceof ModelMessageItem) {
1791
+ return "model_message";
1932
1792
  }
1933
- onError(error) {
1793
+ return item.getType();
1794
+ }
1795
+ var ContextValidation = class {
1796
+ constructor() {
1797
+ this.name = "context";
1934
1798
  }
1935
- onParticipantError(source, error) {
1799
+ isValid(inferenceParams, model) {
1800
+ return inferenceParams.context.items.every(
1801
+ (item) => model.supportedContextItemTypes.includes(getContextItemValidationKey(item))
1802
+ );
1936
1803
  }
1937
1804
  };
1938
1805
 
1939
- // src/application/use-cases/send-message.ts
1940
- var SendMessage = class {
1941
- async execute(environment, message, caller) {
1942
- if (!caller.isJoinedTo(environment)) {
1943
- throw new Error("Not joined to environment");
1806
+ // src/domain/generative-model/request-validation/inference-request-validator.ts
1807
+ var defaultRequestValidationRules = [
1808
+ new ReasoningEffortValidation(),
1809
+ new ToolCallingValidation(),
1810
+ new StreamingValidation(),
1811
+ new StructuredOutputValidation(),
1812
+ new ContextValidation()
1813
+ ];
1814
+ var InferenceRequestValidator = class {
1815
+ constructor(rules = defaultRequestValidationRules) {
1816
+ this.rules = rules;
1817
+ }
1818
+ validate(inferenceParams, model) {
1819
+ for (const rule of this.rules) {
1820
+ if (!rule.isValid(inferenceParams, model)) {
1821
+ throw new Error(`Request validation "${rule.name}" failed for model "${model.name}"`);
1822
+ }
1944
1823
  }
1945
- environment.deliverMessage(caller, message);
1946
1824
  }
1947
1825
  };
1948
1826
 
1949
1827
  // src/index.ts
1950
- var runInferenceUseCase = new RunInference(new ModelRepository(), new InferenceRunner());
1828
+ var generativeModelRepository = new InMemoryGenerativeModelRepository();
1829
+ var inferenceRequestValidator = new InferenceRequestValidator();
1830
+ var runInferenceUseCase = new RunInference(generativeModelRepository, inferenceRequestValidator);
1951
1831
  var executeFunctionCallUseCase = new ExecuteFunctionCall(new FunctionCallRunner());
1952
1832
  var sendMessageUseCase = new SendMessage();
1953
1833
  var runInference = (inferenceParams) => {
@@ -1962,33 +1842,18 @@ var sendMessage = (environment, message, caller) => {
1962
1842
  export {
1963
1843
  AgenticEnvironment,
1964
1844
  AgenticError,
1965
- AnthropicMessages,
1966
1845
  BaseParticipant,
1967
- ClaudeHaiku45,
1968
- ClaudeOpus47,
1969
- ClaudeOpus48,
1970
- ClaudeSonnet46,
1971
1846
  ContextItem,
1972
- DeepSeekV4Flash,
1973
- DeepSeekV4Pro,
1974
1847
  DeveloperMessageItem,
1975
1848
  FunctionCallItem,
1976
1849
  FunctionCallOutputItem,
1977
- Gemini31Pro,
1978
- Gemini35Flash,
1979
- GeminiGenerateContent,
1980
- Gpt54,
1981
- Gpt54Mini,
1982
- Gpt54Nano,
1983
- Gpt55,
1984
1850
  InMemoryModelContextRepository,
1985
- InferenceRequest,
1986
1851
  InferenceResponse,
1987
1852
  InputTokenDetails,
1853
+ McpClient,
1854
+ McpToolRegistry,
1988
1855
  ModelContext,
1989
1856
  ModelMessageItem,
1990
- OpenAIChatCompletions,
1991
- OpenAIResponses,
1992
1857
  OutputTokenDetails,
1993
1858
  Participant,
1994
1859
  ReasoningItem,