@mozaik-ai/core 3.13.0 → 3.13.1

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
@@ -471,13 +254,6 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
471
254
  this.role = "system";
472
255
  this.content = content;
473
256
  }
474
- toJSON() {
475
- return {
476
- type: this.type,
477
- role: this.role,
478
- content: this.content.toJSON()
479
- };
480
- }
481
257
  static create(text) {
482
258
  const content = InputText.create(text);
483
259
  return new _SystemMessageItem(content);
@@ -624,8 +400,10 @@ var AgenticEnvironment = class {
624
400
  src.onError(error);
625
401
  } catch (error2) {
626
402
  if (this.showLogs) {
627
- console.warn(`[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
628
- ${JSON.stringify({ error: error2 }, null, 2)}`);
403
+ console.warn(
404
+ `[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
405
+ ${JSON.stringify({ error: error2 }, null, 2)}`
406
+ );
629
407
  }
630
408
  } finally {
631
409
  src.markInactive(this);
@@ -636,8 +414,10 @@ var AgenticEnvironment = class {
636
414
  sub.onParticipantError(source, error);
637
415
  } catch (error2) {
638
416
  if (this.showLogs) {
639
- console.warn(`[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
640
- ${JSON.stringify({ error: error2 }, null, 2)}`);
417
+ console.warn(
418
+ `[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
419
+ ${JSON.stringify({ error: error2 }, null, 2)}`
420
+ );
641
421
  }
642
422
  }
643
423
  }
@@ -680,56 +460,6 @@ var AgenticEnvironment = class {
680
460
  }
681
461
  };
682
462
 
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
463
  // src/domain/model-context/semantic-event/semantic-event.ts
734
464
  var SemanticEvent = class {
735
465
  constructor(type, data) {
@@ -741,14 +471,6 @@ var SemanticEvent = class {
741
471
  }
742
472
  };
743
473
 
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
474
  // src/domain/agentic-environment/inference/response.ts
753
475
  var InferenceResponse = class {
754
476
  constructor(contextItems, tokenUsage) {
@@ -757,199 +479,204 @@ var InferenceResponse = class {
757
479
  }
758
480
  };
759
481
 
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);
772
- }
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");
777
- }
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) {
782
- break;
783
- }
784
- yield new SemanticEvent(event.type, event);
482
+ // src/application/services/inference-runner.ts
483
+ var StreamingInference = class {
484
+ async *run(request, endpoint) {
485
+ var _a;
486
+ if ((_a = request.signal) == null ? void 0 : _a.aborted) {
487
+ return;
785
488
  }
489
+ yield* endpoint.stream(request, request.signal);
786
490
  }
787
- buildRequest(inferenceRequest) {
491
+ };
492
+ var NonStreamingInference = class {
493
+ async *run(request, endpoint) {
788
494
  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
794
- };
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
- };
495
+ if ((_a = request.signal) == null ? void 0 : _a.aborted) {
496
+ return;
809
497
  }
810
- if (inferenceRequest.model.hasStructuredOutput()) {
811
- if (!specification.supportStructuredOutput) {
812
- throw new Error(`Structured output is not supported for model: ${specification.name}`);
498
+ const response = await endpoint.infer(request);
499
+ for (const item of response.contextItems) {
500
+ if ((_b = request.signal) == null ? void 0 : _b.aborted) {
501
+ break;
813
502
  }
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
- }
824
- return request;
825
- }
826
- extractTokenUsage(response) {
827
- if (!response.usage) {
828
- return void 0;
503
+ yield item;
829
504
  }
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
- );
837
- }
838
- mapContextToRequest(context) {
839
- return context.getItems().map((item) => item.toJSON());
840
- }
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
- });
857
505
  }
858
506
  };
859
507
 
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();
865
- }
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);
508
+ // src/application/use-cases/run-inference.ts
509
+ var RunInference = class {
510
+ constructor(generativeModelRepository2, requestValidator) {
511
+ this.generativeModelRepository = generativeModelRepository2;
512
+ this.requestValidator = requestValidator;
871
513
  }
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) {
514
+ async execute(inferenceParams) {
515
+ var _a;
516
+ const { caller, environment, signal } = inferenceParams;
517
+ const generativeModel = await this.generativeModelRepository.getByModelName(inferenceParams.model);
518
+ this.requestValidator.validate(inferenceParams, generativeModel.specification);
519
+ const resolvedParams = {
520
+ ...inferenceParams,
521
+ maxOutputTokens: (_a = inferenceParams.maxOutputTokens) != null ? _a : generativeModel.specification.maxOutputTokens
522
+ };
523
+ const inferenceRunner = inferenceParams.streaming ? new StreamingInference() : new NonStreamingInference();
524
+ const result = inferenceRunner.run(resolvedParams, generativeModel.endpoint);
525
+ for await (const item of result) {
878
526
  if (signal == null ? void 0 : signal.aborted) {
879
527
  break;
880
528
  }
881
- yield new SemanticEvent(event.type, event);
882
- }
883
- }
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
- };
529
+ if (item instanceof ReasoningItem) {
530
+ environment.deliverReasoning(caller, item);
531
+ } else if (item instanceof FunctionCallItem) {
532
+ environment.deliverFunctionCall(caller, item);
533
+ } else if (item instanceof ModelMessageItem) {
534
+ environment.deliverModelMessage(caller, item);
535
+ } else if (item instanceof SemanticEvent) {
536
+ environment.deliverSemanticEvent(caller, item);
913
537
  }
914
538
  }
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
- }
925
- };
539
+ }
540
+ };
541
+
542
+ // src/application/use-cases/execute-function-call.ts
543
+ var ExecuteFunctionCall = class {
544
+ constructor(functionCallRunner) {
545
+ this.functionCallRunner = functionCallRunner;
546
+ }
547
+ async execute(environment, functionCallItem, tool, caller, signal) {
548
+ const stream = this.functionCallRunner.run(functionCallItem, tool, signal);
549
+ for await (const item of stream) {
550
+ environment.deliverFunctionCallOutput(caller, item);
926
551
  }
927
- return request;
928
552
  }
929
- extractTokenUsage(response) {
930
- var _a, _b;
931
- if (!response.usage) {
932
- return void 0;
553
+ };
554
+
555
+ // src/application/services/function-call-runner.ts
556
+ var FunctionCallRunner = class {
557
+ async *run(call, tool, signal) {
558
+ if (signal == null ? void 0 : signal.aborted) {
559
+ return;
933
560
  }
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
- );
561
+ if (!tool) throw new Error(`Unknown tool: ${call.name}`);
562
+ const result = await tool.invoke(JSON.parse(call.args));
563
+ yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
943
564
  }
944
- mapContextToRequest(context) {
945
- const messages = [];
946
- const system = [];
947
- for (const item of context.getItems()) {
948
- if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
949
- system.push(item.content.text);
950
- continue;
951
- }
952
- if (item instanceof UserMessageItem) {
565
+ };
566
+
567
+ // src/application/participants/participant.ts
568
+ var BaseParticipant = class extends Participant {
569
+ onFunctionCall(item) {
570
+ }
571
+ onExternalFunctionCall(source, item) {
572
+ }
573
+ onFunctionCallOutput(item) {
574
+ }
575
+ onExternalFunctionCallOutput(source, item) {
576
+ }
577
+ onReasoning(item) {
578
+ }
579
+ onExternalReasoning(source, item) {
580
+ }
581
+ onModelMessage(item) {
582
+ }
583
+ onExternalModelMessage(source, item) {
584
+ }
585
+ onMessage(message) {
586
+ }
587
+ onJoined() {
588
+ }
589
+ onLeft() {
590
+ }
591
+ onParticipantJoined(participant) {
592
+ }
593
+ onParticipantLeft(participant) {
594
+ }
595
+ onInternalEvent(item) {
596
+ }
597
+ onExternalEvent(source, item) {
598
+ }
599
+ onError(error) {
600
+ }
601
+ onParticipantError(source, error) {
602
+ }
603
+ };
604
+
605
+ // src/application/use-cases/send-message.ts
606
+ var SendMessage = class {
607
+ async execute(environment, message, caller) {
608
+ if (!caller.isJoinedTo(environment)) {
609
+ throw new Error("Not joined to environment");
610
+ }
611
+ environment.deliverMessage(caller, message);
612
+ }
613
+ };
614
+
615
+ // src/infrastructure/providers/anthropic/endpoints/anthropic-messages-mapper.ts
616
+ var AnthropicMessagesMapper = class {
617
+ toRequest(inferenceParams) {
618
+ const { messages, system } = this.mapContextItems(inferenceParams);
619
+ const outputConfig = {};
620
+ const request = {
621
+ model: inferenceParams.model,
622
+ messages
623
+ };
624
+ request.max_tokens = inferenceParams.maxOutputTokens;
625
+ if (system) {
626
+ request.system = system;
627
+ }
628
+ if (inferenceParams.tools && inferenceParams.tools.length > 0) {
629
+ request.tools = inferenceParams.tools.map((tool) => ({
630
+ name: tool.name,
631
+ description: tool.description,
632
+ input_schema: tool.parameters
633
+ }));
634
+ }
635
+ if (inferenceParams.structuredOutput) {
636
+ outputConfig.format = {
637
+ type: "json_schema",
638
+ json_schema: inferenceParams.structuredOutput.schema
639
+ };
640
+ }
641
+ if (inferenceParams.reasoningEffort) {
642
+ request.thinking = { type: "adaptive" };
643
+ outputConfig.effort = inferenceParams.reasoningEffort;
644
+ }
645
+ if (Object.keys(outputConfig).length > 0) {
646
+ request.output_config = outputConfig;
647
+ }
648
+ if (inferenceParams.streaming) {
649
+ request.stream = inferenceParams.streaming;
650
+ }
651
+ return request;
652
+ }
653
+ toResponse(response) {
654
+ const contextItems = this.extractContextItems(response);
655
+ const tokenUsage = this.extractTokenUsage(response);
656
+ return new InferenceResponse(contextItems, tokenUsage);
657
+ }
658
+ addContentBlock(messages, role, block) {
659
+ const lastMessage = messages[messages.length - 1];
660
+ if ((lastMessage == null ? void 0 : lastMessage.role) === role) {
661
+ lastMessage.content.push(block);
662
+ return;
663
+ }
664
+ messages.push({
665
+ role,
666
+ content: [block]
667
+ });
668
+ }
669
+ mapContextItems(inferenceParams) {
670
+ var _a, _b, _c;
671
+ const context = inferenceParams.context;
672
+ const messages = [];
673
+ const system = [];
674
+ for (const item of context.getItems()) {
675
+ if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
676
+ system.push(item.content.text);
677
+ continue;
678
+ }
679
+ if (item instanceof UserMessageItem) {
953
680
  this.addContentBlock(messages, "user", { type: "text", text: item.content.text });
954
681
  continue;
955
682
  }
@@ -957,6 +684,14 @@ var AnthropicMessages = class {
957
684
  this.addContentBlock(messages, "assistant", { type: "text", text: item.content.text });
958
685
  continue;
959
686
  }
687
+ if (item instanceof ReasoningItem) {
688
+ this.addContentBlock(messages, "assistant", {
689
+ type: "thinking",
690
+ thinking: (_b = (_a = item.content) == null ? void 0 : _a.text) != null ? _b : "",
691
+ signature: (_c = item.encryptedContent) != null ? _c : ""
692
+ });
693
+ continue;
694
+ }
960
695
  if (item instanceof FunctionCallItem) {
961
696
  let input;
962
697
  try {
@@ -985,6 +720,21 @@ var AnthropicMessages = class {
985
720
  system: system.length > 0 ? system.join("\n\n") : void 0
986
721
  };
987
722
  }
723
+ extractTokenUsage(response) {
724
+ var _a, _b;
725
+ if (!response.usage) {
726
+ return void 0;
727
+ }
728
+ return new TokenUsage(
729
+ response.usage.input_tokens,
730
+ response.usage.output_tokens,
731
+ response.usage.input_tokens + response.usage.output_tokens,
732
+ new InputTokenDetails(
733
+ ((_a = response.usage.cache_creation_input_tokens) != null ? _a : 0) + ((_b = response.usage.cache_read_input_tokens) != null ? _b : 0)
734
+ ),
735
+ new OutputTokenDetails(0)
736
+ );
737
+ }
988
738
  extractContextItems(response) {
989
739
  var _a;
990
740
  const items = [];
@@ -1007,7 +757,7 @@ var AnthropicMessages = class {
1007
757
  items.push(
1008
758
  ReasoningItem.rehydrate({
1009
759
  content: block.thinking ? InputText.rehydrate({ text: block.thinking }) : void 0,
1010
- encryptedContent: void 0,
760
+ encryptedContent: block.signature,
1011
761
  summary: []
1012
762
  })
1013
763
  );
@@ -1015,423 +765,261 @@ var AnthropicMessages = class {
1015
765
  }
1016
766
  return items;
1017
767
  }
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
768
  };
1030
769
 
1031
- // src/infrastructure/providers/anthropic/reasoning-effort.ts
1032
- var AnthropicReasoningEffort = class {
1033
- constructor(reasoningEffort) {
1034
- this.reasoningEffort = reasoningEffort;
770
+ // src/infrastructure/providers/anthropic/endpoints/anthropic-messages.ts
771
+ import Anthropic from "@anthropic-ai/sdk";
772
+ var AnthropicMessages = class {
773
+ constructor(endpointMapper = new AnthropicMessagesMapper()) {
774
+ this.endpointMapper = endpointMapper;
775
+ this.client = new Anthropic();
1035
776
  }
1036
- setReasoningEffort(effort) {
1037
- this.reasoningEffort = effort;
777
+ async infer(inferenceParams) {
778
+ const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
779
+ const response = await this.client.messages.create(inferenceRequest);
780
+ return this.endpointMapper.toResponse(response);
1038
781
  }
1039
- getReasoningEffort() {
1040
- if (!this.reasoningEffort) {
1041
- throw new Error("Reasoning effort not supported");
782
+ async *stream(inferenceParams, signal) {
783
+ const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
784
+ const stream = await this.client.messages.create(inferenceRequest);
785
+ for await (const event of stream) {
786
+ if (signal == null ? void 0 : signal.aborted) {
787
+ break;
788
+ }
789
+ yield new SemanticEvent(event.type, event);
1042
790
  }
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
791
  }
1095
792
  };
1096
793
 
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
- };
794
+ // src/infrastructure/providers/openai/endpoints/openai-responses.ts
795
+ import OpenAI from "openai";
1146
796
 
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;
797
+ // src/domain/model-context/context-item/item-content/summary-text.ts
798
+ var SummaryText = class _SummaryText extends ItemContent {
799
+ constructor(text) {
800
+ super();
801
+ this.text = text;
802
+ this.type = "summary_text";
1191
803
  }
1192
- hasStructuredOutput() {
1193
- return this.structuredOutput !== void 0;
804
+ static rehydrate(data) {
805
+ return new _SummaryText(data.text);
1194
806
  }
1195
807
  };
1196
808
 
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
809
+ // src/infrastructure/providers/openai/endpoints/openai-responses-mapper.ts
810
+ var OpenAIResponsesMapper = class {
811
+ toRequest(inferenceParams) {
812
+ var _a, _b;
813
+ const request = {
814
+ model: inferenceParams.model,
815
+ input: this.mapContextItems(inferenceParams)
1210
816
  };
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");
817
+ if (inferenceParams.tools && inferenceParams.tools.length > 0) {
818
+ request.tools = inferenceParams.tools.map((tool) => ({
819
+ type: tool.type,
820
+ name: tool.name,
821
+ description: tool.description,
822
+ parameters: tool.parameters
823
+ }));
1258
824
  }
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;
825
+ if (inferenceParams.reasoningEffort) {
826
+ request.reasoning = {
827
+ effort: inferenceParams.reasoningEffort
828
+ };
829
+ }
830
+ if (inferenceParams.structuredOutput) {
831
+ const format = inferenceParams.structuredOutput;
832
+ request.text = {
833
+ format: {
834
+ type: "json_schema",
835
+ name: (_a = format.name) != null ? _a : "response",
836
+ schema: format.schema,
837
+ strict: (_b = format.strict) != null ? _b : true
838
+ }
839
+ };
840
+ }
841
+ if (inferenceParams.streaming) {
842
+ request.stream = inferenceParams.streaming;
843
+ }
844
+ return request;
1304
845
  }
1305
- getStructuredOutput() {
1306
- return this.structuredOutput;
846
+ toResponse(response) {
847
+ const contextItems = this.extractContextItems(response);
848
+ const tokenUsage = this.extractTokenUsage(response);
849
+ return new InferenceResponse(contextItems, tokenUsage);
1307
850
  }
1308
- hasStructuredOutput() {
1309
- return this.structuredOutput !== void 0;
851
+ mapContextItems(inferenceParams) {
852
+ const input = [];
853
+ for (const item of inferenceParams.context.getItems()) {
854
+ if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem || item instanceof UserMessageItem) {
855
+ input.push({
856
+ type: item.type,
857
+ role: item.role,
858
+ content: [{ type: "input_text", text: item.content.text }]
859
+ });
860
+ continue;
861
+ }
862
+ if (item instanceof ModelMessageItem) {
863
+ input.push({
864
+ type: item.type,
865
+ role: item.role,
866
+ content: [{ type: "output_text", text: item.content.text }]
867
+ });
868
+ continue;
869
+ }
870
+ if (item instanceof FunctionCallItem) {
871
+ input.push({
872
+ type: item.type,
873
+ call_id: item.callId,
874
+ name: item.name,
875
+ arguments: item.args
876
+ });
877
+ continue;
878
+ }
879
+ if (item instanceof FunctionCallOutputItem) {
880
+ input.push({
881
+ type: item.type,
882
+ call_id: item.callId,
883
+ output: [{ type: "input_text", text: item.output.text }]
884
+ });
885
+ continue;
886
+ }
887
+ if (item instanceof ReasoningItem) {
888
+ const reasoningInput = {
889
+ type: item.type,
890
+ summary: item.summary.map((summary) => ({ type: "summary_text", text: summary.text }))
891
+ };
892
+ if (item.encryptedContent !== void 0) {
893
+ reasoningInput.encrypted_content = item.encryptedContent;
894
+ }
895
+ input.push(reasoningInput);
896
+ }
897
+ }
898
+ return input;
1310
899
  }
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
900
+ extractTokenUsage(response) {
901
+ var _a, _b, _c, _d;
902
+ if (!response.usage) {
903
+ return void 0;
904
+ }
905
+ return new TokenUsage(
906
+ response.usage.input_tokens,
907
+ response.usage.output_tokens,
908
+ response.usage.total_tokens,
909
+ new InputTokenDetails((_b = (_a = response.usage.input_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
910
+ new OutputTokenDetails((_d = (_c = response.usage.output_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
1332
911
  );
1333
912
  }
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;
913
+ extractContextItems(response) {
914
+ var _a, _b, _c;
915
+ const items = [];
916
+ for (const item of (_a = response.output) != null ? _a : []) {
917
+ if (item.type === "message" && item.role === "assistant") {
918
+ const firstContent = (_b = item.content) == null ? void 0 : _b[0];
919
+ if (firstContent) {
920
+ items.push(ModelMessageItem.rehydrate(firstContent));
921
+ }
922
+ continue;
923
+ }
924
+ if (item.type === "function_call") {
925
+ items.push(
926
+ FunctionCallItem.rehydrate({
927
+ callId: item.call_id,
928
+ name: item.name,
929
+ args: item.arguments
930
+ })
931
+ );
932
+ continue;
933
+ }
934
+ if (item.type === "reasoning") {
935
+ items.push(
936
+ ReasoningItem.rehydrate({
937
+ content: void 0,
938
+ encryptedContent: item.encrypted_content,
939
+ summary: ((_c = item.summary) != null ? _c : []).map(
940
+ (summary) => SummaryText.rehydrate({ text: summary.text })
941
+ )
942
+ })
943
+ );
944
+ }
945
+ }
946
+ return items;
1360
947
  }
1361
948
  };
1362
949
 
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 });
950
+ // src/infrastructure/providers/openai/endpoints/openai-responses.ts
951
+ var OpenAIResponses = class {
952
+ constructor(endpointMapper = new OpenAIResponsesMapper()) {
953
+ this.endpointMapper = endpointMapper;
954
+ this.client = new OpenAI();
1368
955
  }
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);
956
+ async infer(inferenceParams) {
957
+ const request = this.endpointMapper.toRequest(inferenceParams);
958
+ const response = await this.client.responses.create(request);
959
+ return this.endpointMapper.toResponse(response);
1374
960
  }
1375
- async *stream(inferenceRequest, signal) {
1376
- const stream = await this.client.models.generateContentStream(this.buildRequest(inferenceRequest));
1377
- for await (const chunk of stream) {
961
+ async *stream(inferenceParams, signal) {
962
+ const request = this.endpointMapper.toRequest(inferenceParams);
963
+ const response = await this.client.responses.create(request);
964
+ for await (const event of response) {
1378
965
  if (signal == null ? void 0 : signal.aborted) {
1379
966
  break;
1380
967
  }
1381
- yield new SemanticEvent("generate_content_chunk", chunk);
968
+ yield new SemanticEvent(event.type, event);
1382
969
  }
1383
970
  }
1384
- buildRequest(inferenceRequest) {
1385
- const specification = inferenceRequest.model.specification;
1386
- const { contents, systemInstruction } = this.mapContextToRequest(inferenceRequest.context);
971
+ };
972
+
973
+ // src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts
974
+ import { GoogleGenAI } from "@google/genai";
975
+
976
+ // src/infrastructure/providers/gemini/endpoints/gemini-generate-content-mapper.ts
977
+ var GeminiGenerateContentMapper = class {
978
+ toRequest(inferenceParams) {
979
+ const { contents, systemInstruction } = this.mapContextItems(inferenceParams);
1387
980
  const config = {};
1388
981
  if (systemInstruction) {
1389
982
  config.systemInstruction = systemInstruction;
1390
983
  }
1391
- if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
984
+ if (inferenceParams.tools && inferenceParams.tools.length > 0) {
1392
985
  config.tools = [
1393
986
  {
1394
- functionDeclarations: inferenceRequest.model.getTools().map((tool) => {
1395
- return {
1396
- name: tool.name,
1397
- description: tool.description,
1398
- parametersJsonSchema: tool.parameters
1399
- };
1400
- })
987
+ functionDeclarations: inferenceParams.tools.map((tool) => ({
988
+ name: tool.name,
989
+ description: tool.description,
990
+ parametersJsonSchema: tool.parameters
991
+ }))
1401
992
  }
1402
993
  ];
1403
994
  }
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();
995
+ if (inferenceParams.structuredOutput) {
1414
996
  config.responseMimeType = "application/json";
1415
- config.responseSchema = format.schema;
997
+ config.responseSchema = inferenceParams.structuredOutput.schema;
1416
998
  }
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;
999
+ if (inferenceParams.reasoningEffort) {
1000
+ config.thinkingConfig = {
1001
+ thinkingLevel: inferenceParams.reasoningEffort,
1002
+ includeThoughts: true
1003
+ };
1424
1004
  }
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
- );
1005
+ const request = {
1006
+ model: inferenceParams.model,
1007
+ contents,
1008
+ config
1009
+ };
1010
+ if (inferenceParams.streaming) {
1011
+ request.stream = inferenceParams.streaming;
1012
+ }
1013
+ return request;
1432
1014
  }
1433
- mapContextToRequest(context) {
1015
+ toResponse(response) {
1016
+ const contextItems = this.extractContextItems(response);
1017
+ const tokenUsage = this.extractTokenUsage(response);
1018
+ return new InferenceResponse(contextItems, tokenUsage);
1019
+ }
1020
+ mapContextItems(inferenceParams) {
1434
1021
  var _a;
1022
+ const context = inferenceParams.context;
1435
1023
  const contents = [];
1436
1024
  const system = [];
1437
1025
  const callNames = /* @__PURE__ */ new Map();
@@ -1474,36 +1062,13 @@ var GeminiGenerateContent = class {
1474
1062
  systemInstruction: system.length > 0 ? system.join("\n\n") : void 0
1475
1063
  };
1476
1064
  }
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
- }
1065
+ addPart(contents, role, part) {
1066
+ const last = contents[contents.length - 1];
1067
+ if ((last == null ? void 0 : last.role) === role) {
1068
+ last.parts.push(part);
1069
+ return;
1505
1070
  }
1506
- return items;
1071
+ contents.push({ role, parts: [part] });
1507
1072
  }
1508
1073
  parseResponse(output) {
1509
1074
  try {
@@ -1513,203 +1078,110 @@ var GeminiGenerateContent = class {
1513
1078
  return { output };
1514
1079
  }
1515
1080
  }
1516
- addPart(contents, role, part) {
1517
- const last = contents[contents.length - 1];
1518
- if ((last == null ? void 0 : last.role) === role) {
1519
- last.parts.push(part);
1520
- return;
1521
- }
1522
- contents.push({ role, parts: [part] });
1523
- }
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");
1081
+ extractTokenUsage(response) {
1082
+ var _a, _b, _c, _d, _e;
1083
+ const usage = response.usageMetadata;
1084
+ if (!usage) {
1085
+ return void 0;
1537
1086
  }
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
1087
+ return new TokenUsage(
1088
+ (_a = usage.promptTokenCount) != null ? _a : 0,
1089
+ (_b = usage.candidatesTokenCount) != null ? _b : 0,
1090
+ (_c = usage.totalTokenCount) != null ? _c : 0,
1091
+ new InputTokenDetails((_d = usage.cachedContentTokenCount) != null ? _d : 0),
1092
+ new OutputTokenDetails((_e = usage.thoughtsTokenCount) != null ? _e : 0)
1611
1093
  );
1612
1094
  }
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;
1633
- }
1634
- getStructuredOutput() {
1635
- return this.structuredOutput;
1636
- }
1637
- hasStructuredOutput() {
1638
- return this.structuredOutput !== void 0;
1095
+ extractContextItems(response) {
1096
+ var _a, _b, _c, _d, _e, _f;
1097
+ const items = [];
1098
+ 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 : [];
1099
+ for (const part of parts) {
1100
+ if (part.thought && part.text) {
1101
+ items.push(
1102
+ ReasoningItem.rehydrate({
1103
+ content: InputText.rehydrate({ text: part.text }),
1104
+ encryptedContent: void 0,
1105
+ summary: []
1106
+ })
1107
+ );
1108
+ continue;
1109
+ }
1110
+ if (part.text) {
1111
+ items.push(ModelMessageItem.rehydrate({ text: part.text }));
1112
+ continue;
1113
+ }
1114
+ if (part.functionCall) {
1115
+ items.push(
1116
+ FunctionCallItem.rehydrate({
1117
+ callId: (_e = part.functionCall.id) != null ? _e : "",
1118
+ name: part.functionCall.name,
1119
+ args: JSON.stringify((_f = part.functionCall.args) != null ? _f : {})
1120
+ })
1121
+ );
1122
+ }
1123
+ }
1124
+ return items;
1639
1125
  }
1640
1126
  };
1641
1127
 
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 : {};
1128
+ // src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts
1129
+ var GeminiGenerateContent = class {
1130
+ constructor(endpointMapper = new GeminiGenerateContentMapper()) {
1131
+ this.endpointMapper = endpointMapper;
1132
+ this.client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
1652
1133
  }
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);
1134
+ async infer(inferenceParams) {
1135
+ const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
1136
+ const response = await this.client.models.generateContent(inferenceRequest);
1137
+ return this.endpointMapper.toResponse(response);
1658
1138
  }
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) {
1139
+ async *stream(inferenceParams, signal) {
1140
+ const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
1141
+ const stream = await this.client.models.generateContentStream(inferenceRequest);
1142
+ for await (const chunk of stream) {
1666
1143
  if (signal == null ? void 0 : signal.aborted) {
1667
1144
  break;
1668
1145
  }
1669
- yield new SemanticEvent((_a = event.object) != null ? _a : "chat.completion.chunk", event);
1146
+ yield new SemanticEvent("generate_content_chunk", chunk);
1670
1147
  }
1671
1148
  }
1672
- buildRequest(inferenceRequest) {
1673
- const specification = inferenceRequest.model.specification;
1149
+ };
1150
+
1151
+ // src/infrastructure/providers/openai/endpoints/openai-chat-completions-mapper.ts
1152
+ var OpenAIChatCompletionsMapper = class {
1153
+ toRequest(inferenceParams) {
1674
1154
  const request = {
1675
- ...this.extraBody,
1676
- model: specification.name,
1677
- messages: this.mapContextToRequest(inferenceRequest.context)
1155
+ model: inferenceParams.model,
1156
+ messages: this.mapContextItems(inferenceParams)
1678
1157
  };
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
- });
1158
+ if (inferenceParams.tools && inferenceParams.tools.length > 0) {
1159
+ request.tools = inferenceParams.tools.map((tool) => ({
1160
+ type: "function",
1161
+ function: {
1162
+ name: tool.name,
1163
+ description: tool.description,
1164
+ parameters: tool.parameters
1165
+ }
1166
+ }));
1690
1167
  }
1691
- if (specification.supportReasoningEffort) {
1692
- request.reasoning_effort = inferenceRequest.model.getReasoningEffort();
1168
+ if (inferenceParams.reasoningEffort) {
1169
+ request.reasoning_effort = inferenceParams.reasoningEffort;
1170
+ }
1171
+ if (inferenceParams.streaming) {
1172
+ request.stream = inferenceParams.streaming;
1693
1173
  }
1694
1174
  return request;
1695
1175
  }
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
- );
1176
+ toResponse(response) {
1177
+ const contextItems = this.extractContextItems(response);
1178
+ const tokenUsage = this.extractTokenUsage(response);
1179
+ return new InferenceResponse(contextItems, tokenUsage);
1708
1180
  }
1709
- mapContextToRequest(context) {
1181
+ mapContextItems(inferenceParams) {
1710
1182
  var _a;
1711
1183
  const messages = [];
1712
- for (const item of context.getItems()) {
1184
+ for (const item of inferenceParams.context.getItems()) {
1713
1185
  if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
1714
1186
  messages.push({ role: "system", content: item.content.text });
1715
1187
  continue;
@@ -1743,6 +1215,19 @@ var OpenAIChatCompletions = class {
1743
1215
  }
1744
1216
  return messages;
1745
1217
  }
1218
+ extractTokenUsage(response) {
1219
+ var _a, _b, _c, _d;
1220
+ if (!response.usage) {
1221
+ return void 0;
1222
+ }
1223
+ return new TokenUsage(
1224
+ response.usage.prompt_tokens,
1225
+ response.usage.completion_tokens,
1226
+ response.usage.total_tokens,
1227
+ new InputTokenDetails((_b = (_a = response.usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
1228
+ new OutputTokenDetails((_d = (_c = response.usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
1229
+ );
1230
+ }
1746
1231
  extractContextItems(response) {
1747
1232
  var _a, _b, _c;
1748
1233
  const items = [];
@@ -1775,179 +1260,482 @@ var OpenAIChatCompletions = class {
1775
1260
  }
1776
1261
  };
1777
1262
 
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
- }
1263
+ // src/infrastructure/providers/openai/endpoints/openai-chat-completions.ts
1264
+ import OpenAI2 from "openai";
1265
+ var OpenAIChatCompletions = class {
1266
+ constructor(endpointMapper = new OpenAIChatCompletionsMapper(), config = {}) {
1267
+ var _a;
1268
+ this.endpointMapper = endpointMapper;
1269
+ this.client = new OpenAI2({
1270
+ baseURL: config.baseURL,
1271
+ apiKey: config.apiKey
1272
+ });
1273
+ this.extraBody = (_a = config.extraBody) != null ? _a : {};
1794
1274
  }
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;
1275
+ buildRequest(inferenceParams) {
1276
+ return {
1277
+ ...this.extraBody,
1278
+ ...this.endpointMapper.toRequest(inferenceParams)
1279
+ };
1802
1280
  }
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;
1281
+ async infer(inferenceParams) {
1282
+ const response = await this.client.chat.completions.create(this.buildRequest(inferenceParams));
1283
+ return this.endpointMapper.toResponse(response);
1818
1284
  }
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) {
1285
+ async *stream(inferenceParams, signal) {
1286
+ var _a;
1287
+ const stream = await this.client.chat.completions.create(this.buildRequest(inferenceParams));
1288
+ for await (const event of stream) {
1826
1289
  if (signal == null ? void 0 : signal.aborted) {
1827
1290
  break;
1828
1291
  }
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
- }
1292
+ yield new SemanticEvent((_a = event.object) != null ? _a : "chat.completion.chunk", event);
1838
1293
  }
1839
1294
  }
1840
1295
  };
1841
1296
 
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
- }
1297
+ // src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
1298
+ var claudeSonnet46Specification = {
1299
+ name: "claude-sonnet-4-6",
1300
+ provider: "anthropic",
1301
+ supportsReasoningEffort: true,
1302
+ supportedReasoningEfforts: ["max", "high", "medium", "low"],
1303
+ supportedContextItemTypes: [
1304
+ "user_message",
1305
+ "system_message",
1306
+ "developer_message",
1307
+ "reasoning",
1308
+ "function_call",
1309
+ "function_call_output",
1310
+ "model_message"
1311
+ ],
1312
+ supportsStreaming: true,
1313
+ contextWindowSize: 2e5,
1314
+ maxOutputTokens: 64e3,
1315
+ supportsFunctionCalling: true,
1316
+ supportsStructuredOutput: true
1317
+ };
1318
+
1319
+ // src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts
1320
+ var claudeOpus48Specification = {
1321
+ name: "claude-opus-4-8",
1322
+ provider: "anthropic",
1323
+ supportsReasoningEffort: true,
1324
+ supportedReasoningEfforts: ["max", "xhigh", "high", "medium", "low"],
1325
+ supportedContextItemTypes: [
1326
+ "user_message",
1327
+ "system_message",
1328
+ "developer_message",
1329
+ "reasoning",
1330
+ "function_call",
1331
+ "function_call_output",
1332
+ "model_message"
1333
+ ],
1334
+ supportsStreaming: true,
1335
+ contextWindowSize: 2e5,
1336
+ maxOutputTokens: 32e3,
1337
+ supportsFunctionCalling: true,
1338
+ supportsStructuredOutput: true
1339
+ };
1340
+
1341
+ // src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
1342
+ var claudeOpus47Specification = {
1343
+ name: "claude-opus-4-7",
1344
+ provider: "anthropic",
1345
+ supportsReasoningEffort: true,
1346
+ supportedReasoningEfforts: ["max", "xhigh", "high", "medium", "low"],
1347
+ supportedContextItemTypes: [
1348
+ "user_message",
1349
+ "system_message",
1350
+ "developer_message",
1351
+ "reasoning",
1352
+ "function_call",
1353
+ "function_call_output",
1354
+ "model_message"
1355
+ ],
1356
+ supportsStreaming: true,
1357
+ contextWindowSize: 2e5,
1358
+ maxOutputTokens: 32e3,
1359
+ supportsFunctionCalling: true,
1360
+ supportsStructuredOutput: true
1361
+ };
1362
+
1363
+ // src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts
1364
+ var gemini35FlashSpecification = {
1365
+ name: "gemini-3.5-flash",
1366
+ provider: "google",
1367
+ supportsReasoningEffort: true,
1368
+ supportedReasoningEfforts: ["high", "medium", "low", "minimal", "none"],
1369
+ supportedContextItemTypes: [
1370
+ "user_message",
1371
+ "system_message",
1372
+ "developer_message",
1373
+ "reasoning",
1374
+ "function_call",
1375
+ "function_call_output",
1376
+ "model_message"
1377
+ ],
1378
+ supportsStreaming: true,
1379
+ contextWindowSize: 1048576,
1380
+ maxOutputTokens: 64e3,
1381
+ supportsFunctionCalling: true,
1382
+ supportsStructuredOutput: true
1383
+ };
1384
+
1385
+ // src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
1386
+ var gemini31ProSpecification = {
1387
+ name: "gemini-3.1-pro-preview",
1388
+ provider: "google",
1389
+ supportsReasoningEffort: true,
1390
+ supportedReasoningEfforts: ["high", "medium", "low", "minimal", "none"],
1391
+ supportedContextItemTypes: [
1392
+ "user_message",
1393
+ "system_message",
1394
+ "developer_message",
1395
+ "reasoning",
1396
+ "function_call",
1397
+ "function_call_output",
1398
+ "model_message"
1399
+ ],
1400
+ supportsStreaming: true,
1401
+ contextWindowSize: 1048576,
1402
+ maxOutputTokens: 64e3,
1403
+ supportsFunctionCalling: true,
1404
+ supportsStructuredOutput: true
1405
+ };
1406
+
1407
+ // src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts
1408
+ var deepSeekV4FlashSpecification = {
1409
+ name: "deepseek-v4-flash",
1410
+ provider: "deepseek",
1411
+ supportsReasoningEffort: true,
1412
+ supportedReasoningEfforts: ["max", "high", "medium", "low", "none"],
1413
+ supportedContextItemTypes: [
1414
+ "user_message",
1415
+ "system_message",
1416
+ "developer_message",
1417
+ "reasoning",
1418
+ "function_call",
1419
+ "function_call_output",
1420
+ "model_message"
1421
+ ],
1422
+ supportsStreaming: true,
1423
+ contextWindowSize: 1e6,
1424
+ maxOutputTokens: 384e3,
1425
+ supportsFunctionCalling: true,
1426
+ supportsStructuredOutput: false
1853
1427
  };
1854
1428
 
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() };
1429
+ // src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
1430
+ var deepSeekV4ProSpecification = {
1431
+ name: "deepseek-v4-pro",
1432
+ provider: "deepseek",
1433
+ supportsReasoningEffort: true,
1434
+ supportedReasoningEfforts: ["max", "high", "medium", "low", "none"],
1435
+ supportedContextItemTypes: [
1436
+ "user_message",
1437
+ "system_message",
1438
+ "developer_message",
1439
+ "reasoning",
1440
+ "function_call",
1441
+ "function_call_output",
1442
+ "model_message"
1443
+ ],
1444
+ supportsStreaming: true,
1445
+ contextWindowSize: 1e6,
1446
+ maxOutputTokens: 384e3,
1447
+ supportsFunctionCalling: true,
1448
+ supportsStructuredOutput: false
1449
+ };
1450
+
1451
+ // src/infrastructure/providers/openai/models/gpt-5-4.ts
1452
+ var gpt54Specification = {
1453
+ name: "gpt-5.4",
1454
+ provider: "openai",
1455
+ supportsReasoningEffort: true,
1456
+ supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
1457
+ supportedContextItemTypes: [
1458
+ "user_message",
1459
+ "system_message",
1460
+ "developer_message",
1461
+ "reasoning",
1462
+ "function_call",
1463
+ "function_call_output",
1464
+ "model_message"
1465
+ ],
1466
+ supportsStreaming: true,
1467
+ contextWindowSize: 105e4,
1468
+ maxOutputTokens: 128e3,
1469
+ supportsFunctionCalling: true,
1470
+ supportsStructuredOutput: true
1471
+ };
1472
+
1473
+ // src/infrastructure/providers/openai/models/gpt-5-4-mini.ts
1474
+ var gpt54MiniSpecification = {
1475
+ name: "gpt-5.4-mini",
1476
+ provider: "openai",
1477
+ supportsReasoningEffort: true,
1478
+ supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
1479
+ supportedContextItemTypes: [
1480
+ "user_message",
1481
+ "system_message",
1482
+ "developer_message",
1483
+ "reasoning",
1484
+ "function_call",
1485
+ "function_call_output",
1486
+ "model_message"
1487
+ ],
1488
+ supportsStreaming: true,
1489
+ contextWindowSize: 4e5,
1490
+ maxOutputTokens: 128e3,
1491
+ supportsFunctionCalling: true,
1492
+ supportsStructuredOutput: true
1493
+ };
1494
+
1495
+ // src/infrastructure/providers/openai/models/gpt-5-4-nano.ts
1496
+ var gpt54NanoSpecification = {
1497
+ name: "gpt-5.4-nano",
1498
+ provider: "openai",
1499
+ supportsReasoningEffort: true,
1500
+ supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
1501
+ supportedContextItemTypes: [
1502
+ "user_message",
1503
+ "system_message",
1504
+ "developer_message",
1505
+ "reasoning",
1506
+ "function_call",
1507
+ "function_call_output",
1508
+ "model_message"
1509
+ ],
1510
+ supportsStreaming: true,
1511
+ contextWindowSize: 4e5,
1512
+ maxOutputTokens: 128e3,
1513
+ supportsFunctionCalling: true,
1514
+ supportsStructuredOutput: true
1515
+ };
1516
+
1517
+ // src/infrastructure/providers/openai/models/gpt-5-5.ts
1518
+ var gpt55Specification = {
1519
+ name: "gpt-5.5",
1520
+ provider: "openai",
1521
+ supportsReasoningEffort: true,
1522
+ supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
1523
+ supportedContextItemTypes: [
1524
+ "user_message",
1525
+ "system_message",
1526
+ "developer_message",
1527
+ "reasoning",
1528
+ "function_call",
1529
+ "function_call_output",
1530
+ "model_message"
1531
+ ],
1532
+ supportsStreaming: true,
1533
+ contextWindowSize: 105e4,
1534
+ maxOutputTokens: 128e3,
1535
+ supportsFunctionCalling: true,
1536
+ supportsStructuredOutput: true
1537
+ };
1538
+
1539
+ // src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
1540
+ var claudeHaiku45Specification = {
1541
+ name: "claude-haiku-4-5",
1542
+ provider: "anthropic",
1543
+ supportsReasoningEffort: true,
1544
+ supportedReasoningEfforts: ["high", "medium", "low", "none"],
1545
+ supportedContextItemTypes: [
1546
+ "user_message",
1547
+ "system_message",
1548
+ "developer_message",
1549
+ "reasoning",
1550
+ "function_call",
1551
+ "function_call_output",
1552
+ "model_message"
1553
+ ],
1554
+ supportsStreaming: true,
1555
+ contextWindowSize: 2e5,
1556
+ maxOutputTokens: 64e3,
1557
+ supportsFunctionCalling: true,
1558
+ supportsStructuredOutput: true
1559
+ };
1560
+
1561
+ // src/infrastructure/repository/generative-model-repository.ts
1562
+ var InMemoryGenerativeModelRepository = class {
1563
+ getByModelName(modelName) {
1564
+ let generativeModel = void 0;
1565
+ switch (modelName) {
1566
+ case "gpt-5.4":
1567
+ generativeModel = {
1568
+ endpoint: new OpenAIResponses(),
1569
+ specification: gpt54Specification
1570
+ };
1571
+ break;
1572
+ case "gpt-5.4-mini":
1573
+ generativeModel = {
1574
+ endpoint: new OpenAIResponses(),
1575
+ specification: gpt54MiniSpecification
1576
+ };
1577
+ break;
1578
+ case "gpt-5.4-nano":
1579
+ generativeModel = {
1580
+ endpoint: new OpenAIResponses(),
1581
+ specification: gpt54NanoSpecification
1582
+ };
1583
+ break;
1584
+ case "gpt-5.5":
1585
+ generativeModel = {
1586
+ endpoint: new OpenAIResponses(),
1587
+ specification: gpt55Specification
1588
+ };
1589
+ break;
1590
+ case "claude-haiku-4-5":
1591
+ generativeModel = {
1592
+ endpoint: new AnthropicMessages(),
1593
+ specification: claudeHaiku45Specification
1594
+ };
1595
+ break;
1596
+ case "claude-sonnet-4-6":
1597
+ generativeModel = {
1598
+ endpoint: new AnthropicMessages(),
1599
+ specification: claudeSonnet46Specification
1600
+ };
1601
+ break;
1602
+ case "claude-opus-4-7":
1603
+ generativeModel = {
1604
+ endpoint: new AnthropicMessages(),
1605
+ specification: claudeOpus47Specification
1606
+ };
1607
+ break;
1608
+ case "claude-opus-4-8":
1609
+ generativeModel = {
1610
+ endpoint: new AnthropicMessages(),
1611
+ specification: claudeOpus48Specification
1612
+ };
1613
+ break;
1614
+ case "gemini-3.5-flash":
1615
+ generativeModel = {
1616
+ endpoint: new GeminiGenerateContent(),
1617
+ specification: gemini35FlashSpecification
1618
+ };
1619
+ break;
1620
+ case "gemini-3.1-pro-preview":
1621
+ generativeModel = {
1622
+ endpoint: new GeminiGenerateContent(),
1623
+ specification: gemini31ProSpecification
1624
+ };
1625
+ break;
1879
1626
  case "deepseek-v4-flash":
1880
- return { endpoint: new OpenAIChatCompletions(), model: new DeepSeekV4Flash() };
1627
+ generativeModel = {
1628
+ endpoint: new OpenAIChatCompletions(),
1629
+ specification: deepSeekV4FlashSpecification
1630
+ };
1631
+ break;
1881
1632
  case "deepseek-v4-pro":
1882
- return { endpoint: new OpenAIChatCompletions(), model: new DeepSeekV4Pro() };
1883
- default:
1884
- throw new Error(`Unsupported model: ${model}`);
1633
+ generativeModel = {
1634
+ endpoint: new OpenAIChatCompletions(),
1635
+ specification: deepSeekV4ProSpecification
1636
+ };
1637
+ }
1638
+ if (!generativeModel) {
1639
+ throw new Error(`Unsupported model: ${modelName}`);
1885
1640
  }
1641
+ return Promise.resolve(generativeModel);
1886
1642
  }
1887
1643
  };
1888
1644
 
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;
1645
+ // src/domain/generative-model/request-validation/reasoning-effort.ts
1646
+ var ReasoningEffortValidation = class {
1647
+ constructor() {
1648
+ this.name = "reasoning-effort";
1649
+ }
1650
+ isValid(inferenceParams, model) {
1651
+ if (inferenceParams.reasoningEffort === void 0) {
1652
+ return true;
1894
1653
  }
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));
1654
+ if (!model.supportsReasoningEffort) {
1655
+ return false;
1656
+ }
1657
+ return model.supportedReasoningEfforts.includes(inferenceParams.reasoningEffort);
1898
1658
  }
1899
1659
  };
1900
1660
 
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) {
1661
+ // src/domain/generative-model/request-validation/tool-calling.ts
1662
+ var ToolCallingValidation = class {
1663
+ constructor() {
1664
+ this.name = "tool-calling";
1918
1665
  }
1919
- onMessage(message) {
1666
+ isValid(inferenceParams, model) {
1667
+ if (inferenceParams.tools === void 0) {
1668
+ return true;
1669
+ }
1670
+ return model.supportsFunctionCalling;
1920
1671
  }
1921
- onJoined() {
1672
+ };
1673
+
1674
+ // src/domain/generative-model/request-validation/streaming.ts
1675
+ var StreamingValidation = class {
1676
+ constructor() {
1677
+ this.name = "streaming";
1922
1678
  }
1923
- onLeft() {
1679
+ isValid(inferenceParams, model) {
1680
+ if (!inferenceParams.streaming) {
1681
+ return true;
1682
+ }
1683
+ return model.supportsStreaming;
1924
1684
  }
1925
- onParticipantJoined(participant) {
1685
+ };
1686
+
1687
+ // src/domain/generative-model/request-validation/context.ts
1688
+ function getContextItemValidationKey(item) {
1689
+ if (item instanceof UserMessageItem) {
1690
+ return "user_message";
1926
1691
  }
1927
- onParticipantLeft(participant) {
1692
+ if (item instanceof SystemMessageItem) {
1693
+ return "system_message";
1928
1694
  }
1929
- onInternalEvent(item) {
1695
+ if (item instanceof DeveloperMessageItem) {
1696
+ return "developer_message";
1930
1697
  }
1931
- onExternalEvent(source, item) {
1698
+ if (item instanceof ModelMessageItem) {
1699
+ return "model_message";
1932
1700
  }
1933
- onError(error) {
1701
+ return item.getType();
1702
+ }
1703
+ var ContextValidation = class {
1704
+ constructor() {
1705
+ this.name = "context";
1934
1706
  }
1935
- onParticipantError(source, error) {
1707
+ isValid(inferenceParams, model) {
1708
+ return inferenceParams.context.items.every(
1709
+ (item) => model.supportedContextItemTypes.includes(getContextItemValidationKey(item))
1710
+ );
1936
1711
  }
1937
1712
  };
1938
1713
 
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");
1714
+ // src/domain/generative-model/request-validation/inference-request-validator.ts
1715
+ var defaultRequestValidationRules = [
1716
+ new ReasoningEffortValidation(),
1717
+ new ToolCallingValidation(),
1718
+ new StreamingValidation(),
1719
+ new StructuredOutputValidation(),
1720
+ new ContextValidation()
1721
+ ];
1722
+ var InferenceRequestValidator = class {
1723
+ constructor(rules = defaultRequestValidationRules) {
1724
+ this.rules = rules;
1725
+ }
1726
+ validate(inferenceParams, model) {
1727
+ for (const rule of this.rules) {
1728
+ if (!rule.isValid(inferenceParams, model)) {
1729
+ throw new Error(`Request validation "${rule.name}" failed for model "${model.name}"`);
1730
+ }
1944
1731
  }
1945
- environment.deliverMessage(caller, message);
1946
1732
  }
1947
1733
  };
1948
1734
 
1949
1735
  // src/index.ts
1950
- var runInferenceUseCase = new RunInference(new ModelRepository(), new InferenceRunner());
1736
+ var generativeModelRepository = new InMemoryGenerativeModelRepository();
1737
+ var inferenceRequestValidator = new InferenceRequestValidator();
1738
+ var runInferenceUseCase = new RunInference(generativeModelRepository, inferenceRequestValidator);
1951
1739
  var executeFunctionCallUseCase = new ExecuteFunctionCall(new FunctionCallRunner());
1952
1740
  var sendMessageUseCase = new SendMessage();
1953
1741
  var runInference = (inferenceParams) => {
@@ -1962,33 +1750,16 @@ var sendMessage = (environment, message, caller) => {
1962
1750
  export {
1963
1751
  AgenticEnvironment,
1964
1752
  AgenticError,
1965
- AnthropicMessages,
1966
1753
  BaseParticipant,
1967
- ClaudeHaiku45,
1968
- ClaudeOpus47,
1969
- ClaudeOpus48,
1970
- ClaudeSonnet46,
1971
1754
  ContextItem,
1972
- DeepSeekV4Flash,
1973
- DeepSeekV4Pro,
1974
1755
  DeveloperMessageItem,
1975
1756
  FunctionCallItem,
1976
1757
  FunctionCallOutputItem,
1977
- Gemini31Pro,
1978
- Gemini35Flash,
1979
- GeminiGenerateContent,
1980
- Gpt54,
1981
- Gpt54Mini,
1982
- Gpt54Nano,
1983
- Gpt55,
1984
1758
  InMemoryModelContextRepository,
1985
- InferenceRequest,
1986
1759
  InferenceResponse,
1987
1760
  InputTokenDetails,
1988
1761
  ModelContext,
1989
1762
  ModelMessageItem,
1990
- OpenAIChatCompletions,
1991
- OpenAIResponses,
1992
1763
  OutputTokenDetails,
1993
1764
  Participant,
1994
1765
  ReasoningItem,