@mozaik-ai/core 3.12.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.js CHANGED
@@ -30,48 +30,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- Agent: () => Agent,
34
33
  AgenticEnvironment: () => AgenticEnvironment,
35
- AnthropicMessages: () => AnthropicMessages,
36
- BaseAgent: () => BaseAgent,
37
- BaseHuman: () => BaseHuman,
38
- BaseObserver: () => BaseObserver,
39
- ClaudeHaiku45: () => ClaudeHaiku45,
40
- ClaudeOpus47: () => ClaudeOpus47,
41
- ClaudeOpus48: () => ClaudeOpus48,
42
- ClaudeSonnet46: () => ClaudeSonnet46,
34
+ AgenticError: () => AgenticError,
35
+ BaseParticipant: () => BaseParticipant,
43
36
  ContextItem: () => ContextItem,
44
- DeepSeekV4Flash: () => DeepSeekV4Flash,
45
- DeepSeekV4Pro: () => DeepSeekV4Pro,
46
- DefaultFunctionCallRunner: () => DefaultFunctionCallRunner,
47
- DefaultInferenceRunner: () => DefaultInferenceRunner,
48
37
  DeveloperMessageItem: () => DeveloperMessageItem,
49
38
  FunctionCallItem: () => FunctionCallItem,
50
39
  FunctionCallOutputItem: () => FunctionCallOutputItem,
51
- Gemini31Pro: () => Gemini31Pro,
52
- Gemini35Flash: () => Gemini35Flash,
53
- GeminiGenerateContent: () => GeminiGenerateContent,
54
- Gpt54: () => Gpt54,
55
- Gpt54Mini: () => Gpt54Mini,
56
- Gpt54Nano: () => Gpt54Nano,
57
- Gpt55: () => Gpt55,
58
- Human: () => Human,
59
40
  InMemoryModelContextRepository: () => InMemoryModelContextRepository,
60
- InferenceRequest: () => InferenceRequest,
61
41
  InferenceResponse: () => InferenceResponse,
62
42
  InputTokenDetails: () => InputTokenDetails,
63
43
  ModelContext: () => ModelContext,
64
44
  ModelMessageItem: () => ModelMessageItem,
65
- Observer: () => Observer,
66
- OpenAICompatibleChatCompletions: () => OpenAICompatibleChatCompletions,
67
- OpenAIResponses: () => OpenAIResponses,
68
45
  OutputTokenDetails: () => OutputTokenDetails,
69
46
  Participant: () => Participant,
70
47
  ReasoningItem: () => ReasoningItem,
71
48
  SemanticEvent: () => SemanticEvent,
72
49
  SystemMessageItem: () => SystemMessageItem,
73
50
  TokenUsage: () => TokenUsage,
74
- UserMessageItem: () => UserMessageItem
51
+ UserMessageItem: () => UserMessageItem,
52
+ executeFunctionCall: () => executeFunctionCall,
53
+ runInference: () => runInference,
54
+ sendMessage: () => sendMessage
75
55
  });
76
56
  module.exports = __toCommonJS(index_exports);
77
57
 
@@ -112,9 +92,6 @@ var ModelContext = class _ModelContext {
112
92
  static rehydrate(data) {
113
93
  return new _ModelContext(data.id, data.projectId, data.items);
114
94
  }
115
- toJSON() {
116
- return this.items.map((item) => item.toJSON());
117
- }
118
95
  };
119
96
 
120
97
  // src/domain/model-context/context-item/context-item.ts
@@ -141,14 +118,6 @@ var InputText = class _InputText extends ItemContent {
141
118
  static rehydrate(data) {
142
119
  return new _InputText(data.text);
143
120
  }
144
- toJSON() {
145
- return [
146
- {
147
- type: this.type,
148
- text: this.text
149
- }
150
- ];
151
- }
152
121
  };
153
122
 
154
123
  // src/domain/model-context/context-item/client-item/user-message.ts
@@ -167,13 +136,6 @@ var UserMessageItem = class _UserMessageItem extends ContextItem {
167
136
  const content = InputText.rehydrate(data);
168
137
  return new _UserMessageItem(content);
169
138
  }
170
- toJSON() {
171
- return {
172
- type: this.type,
173
- role: this.role,
174
- content: this.content.toJSON()
175
- };
176
- }
177
139
  };
178
140
 
179
141
  // src/domain/model-context/context-item/client-item/developer-message.ts
@@ -184,13 +146,6 @@ var DeveloperMessageItem = class _DeveloperMessageItem extends ContextItem {
184
146
  this.role = "developer";
185
147
  this.content = content;
186
148
  }
187
- toJSON() {
188
- return {
189
- type: this.type,
190
- role: this.role,
191
- content: this.content.toJSON()
192
- };
193
- }
194
149
  static create(text) {
195
150
  const content = InputText.create(text);
196
151
  return new _DeveloperMessageItem(content);
@@ -211,14 +166,6 @@ var OutputText = class _OutputText extends ItemContent {
211
166
  static rehydrate(data) {
212
167
  return new _OutputText(data.text);
213
168
  }
214
- toJSON() {
215
- return [
216
- {
217
- type: this.type,
218
- text: this.text
219
- }
220
- ];
221
- }
222
169
  };
223
170
 
224
171
  // src/domain/model-context/context-item/model-item/model-message.ts
@@ -233,13 +180,6 @@ var ModelMessageItem = class _ModelMessageItem extends ContextItem {
233
180
  const content = OutputText.rehydrate(data);
234
181
  return new _ModelMessageItem(content);
235
182
  }
236
- toJSON() {
237
- return {
238
- type: this.type,
239
- role: this.role,
240
- content: this.content.toJSON()
241
- };
242
- }
243
183
  };
244
184
 
245
185
  // src/domain/model-context/context-item/model-item/function-call.ts
@@ -254,14 +194,6 @@ var FunctionCallItem = class _FunctionCallItem extends ContextItem {
254
194
  static rehydrate(data) {
255
195
  return new _FunctionCallItem(data.callId, data.name, data.args);
256
196
  }
257
- toJSON() {
258
- return {
259
- type: this.type,
260
- call_id: this.callId,
261
- name: this.name,
262
- arguments: this.args
263
- };
264
- }
265
197
  };
266
198
 
267
199
  // src/domain/model-context/context-item/model-item/reasoning.ts
@@ -276,14 +208,18 @@ var ReasoningItem = class _ReasoningItem extends ContextItem {
276
208
  static rehydrate(data) {
277
209
  return new _ReasoningItem(data.content, data.encryptedContent, data.summary);
278
210
  }
279
- toJSON() {
280
- var _a;
281
- return {
282
- type: this.type,
283
- content: (_a = this.content) == null ? void 0 : _a.toJSON(),
284
- encryptedContent: this.encryptedContent,
285
- summary: this.summary.map((s) => s.toJSON())
286
- };
211
+ };
212
+
213
+ // src/domain/generative-model/request-validation/structured-output.ts
214
+ var StructuredOutputValidation = class {
215
+ constructor() {
216
+ this.name = "structured-output";
217
+ }
218
+ isValid(inferenceParams, model) {
219
+ if (inferenceParams.structuredOutput === void 0) {
220
+ return true;
221
+ }
222
+ return model.supportsStructuredOutput;
287
223
  }
288
224
  };
289
225
 
@@ -302,143 +238,6 @@ var FunctionCallOutputItem = class _FunctionCallOutputItem extends ContextItem {
302
238
  static rehydrate(data) {
303
239
  return new _FunctionCallOutputItem(data.callId, data.output);
304
240
  }
305
- toJSON() {
306
- return {
307
- type: this.type,
308
- call_id: this.callId,
309
- output: this.output.toJSON()
310
- };
311
- }
312
- };
313
-
314
- // src/infrastructure/providers/openai/reasoning-effort.ts
315
- var OpenAIReasoningEffort = class {
316
- constructor(reasoningEffort) {
317
- this.reasoningEffort = reasoningEffort;
318
- }
319
- setReasoningEffort(effort) {
320
- this.reasoningEffort = effort;
321
- }
322
- getReasoningEffort() {
323
- if (!this.reasoningEffort) {
324
- throw new Error("Reasoning effort not supported");
325
- }
326
- return this.reasoningEffort;
327
- }
328
- };
329
-
330
- // src/infrastructure/providers/openai/models/gpt-5-4-nano.ts
331
- var Gpt54Nano = class {
332
- constructor() {
333
- this.specification = {
334
- name: "gpt-5.4-nano",
335
- supportReasoningEffort: true,
336
- defaultReasoningEffort: "none",
337
- supportStreaming: true,
338
- contextWindowSize: 4e5,
339
- maxOutputTokens: 128e3,
340
- supportFunctionCalling: true
341
- };
342
- this.tools = [];
343
- this.streaming = false;
344
- this.effort = new OpenAIReasoningEffort(
345
- this.specification.defaultReasoningEffort
346
- );
347
- }
348
- setStreaming(streaming) {
349
- this.streaming = streaming;
350
- }
351
- getStreaming() {
352
- return this.streaming;
353
- }
354
- setTools(tools) {
355
- this.tools = tools;
356
- }
357
- getTools() {
358
- return this.tools;
359
- }
360
- setReasoningEffort(effort) {
361
- this.effort.setReasoningEffort(effort);
362
- }
363
- getReasoningEffort() {
364
- return this.effort.getReasoningEffort();
365
- }
366
- };
367
-
368
- // src/infrastructure/providers/openai/models/gpt-5-4.ts
369
- var Gpt54 = class {
370
- constructor() {
371
- this.specification = {
372
- name: "gpt-5.4",
373
- supportReasoningEffort: true,
374
- defaultReasoningEffort: "none",
375
- supportStreaming: true,
376
- contextWindowSize: 105e4,
377
- maxOutputTokens: 128e3,
378
- supportFunctionCalling: true
379
- };
380
- this.tools = [];
381
- this.streaming = false;
382
- this.effort = new OpenAIReasoningEffort(
383
- this.specification.defaultReasoningEffort
384
- );
385
- }
386
- setStreaming(streaming) {
387
- this.streaming = streaming;
388
- }
389
- getStreaming() {
390
- return this.streaming;
391
- }
392
- setTools(tools) {
393
- this.tools = tools;
394
- }
395
- getTools() {
396
- return this.tools;
397
- }
398
- setReasoningEffort(effort) {
399
- this.effort.setReasoningEffort(effort);
400
- }
401
- getReasoningEffort() {
402
- return this.effort.getReasoningEffort();
403
- }
404
- };
405
-
406
- // src/infrastructure/providers/openai/models/gpt-5-4-mini.ts
407
- var Gpt54Mini = class {
408
- constructor() {
409
- this.specification = {
410
- name: "gpt-5.4-mini",
411
- supportReasoningEffort: true,
412
- defaultReasoningEffort: "none",
413
- supportStreaming: true,
414
- contextWindowSize: 4e5,
415
- maxOutputTokens: 128e3,
416
- supportFunctionCalling: true
417
- };
418
- this.tools = [];
419
- this.streaming = false;
420
- this.effort = new OpenAIReasoningEffort(
421
- this.specification.defaultReasoningEffort
422
- );
423
- }
424
- setStreaming(streaming) {
425
- this.streaming = streaming;
426
- }
427
- getStreaming() {
428
- return this.streaming;
429
- }
430
- setReasoningEffort(effort) {
431
- this.effort.setReasoningEffort(effort);
432
- }
433
- getReasoningEffort() {
434
- return this.effort.getReasoningEffort();
435
- }
436
- setTools(tools) {
437
- this.tools = tools;
438
- }
439
- getTools() {
440
- return this.tools;
441
- }
442
241
  };
443
242
 
444
243
  // src/domain/generative-model/token-usage.ts
@@ -512,13 +311,6 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
512
311
  this.role = "system";
513
312
  this.content = content;
514
313
  }
515
- toJSON() {
516
- return {
517
- type: this.type,
518
- role: this.role,
519
- content: this.content.toJSON()
520
- };
521
- }
522
314
  static create(text) {
523
315
  const content = InputText.create(text);
524
316
  return new _SystemMessageItem(content);
@@ -529,11 +321,12 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
529
321
  }
530
322
  };
531
323
 
532
- // src/domain/agentic-environment/participants/participant.ts
324
+ // src/domain/agentic-environment/participant.ts
533
325
  var Participant = class {
534
326
  constructor() {
535
327
  this.environments = [];
536
328
  this.listens = [];
329
+ this.active = /* @__PURE__ */ new Map();
537
330
  }
538
331
  join(environment) {
539
332
  if (this.isJoinedTo(environment)) {
@@ -541,6 +334,7 @@ var Participant = class {
541
334
  }
542
335
  environment.subscribe(this);
543
336
  this.environments.push(environment);
337
+ this.active.set(environment, true);
544
338
  }
545
339
  leave(environment) {
546
340
  if (!this.isJoinedTo(environment)) {
@@ -548,6 +342,7 @@ var Participant = class {
548
342
  }
549
343
  environment.unsubscribe(this);
550
344
  this.environments = this.environments.filter((e) => e !== environment);
345
+ this.active.delete(environment);
551
346
  }
552
347
  isJoinedTo(environment) {
553
348
  return this.environments.includes(environment);
@@ -558,14 +353,46 @@ var Participant = class {
558
353
  getListeners() {
559
354
  return this.listens;
560
355
  }
356
+ getEnvironmentState(environment) {
357
+ return this.active.get(environment);
358
+ }
359
+ markInactive(environment) {
360
+ if (this.active.has(environment)) {
361
+ this.active.set(environment, false);
362
+ }
363
+ }
364
+ markActive(environment) {
365
+ if (this.active.has(environment)) {
366
+ this.active.set(environment, true);
367
+ }
368
+ }
369
+ };
370
+
371
+ // src/domain/agentic-environment/errors/base-error.ts
372
+ var AgenticError = class extends Error {
373
+ constructor({ message, stack, source, enviornment }) {
374
+ super();
375
+ this.message = message;
376
+ this.stack = stack;
377
+ this.source = source;
378
+ this.environment = enviornment;
379
+ }
380
+ getSource() {
381
+ return this.source;
382
+ }
383
+ getEnvironment() {
384
+ return this.environment;
385
+ }
561
386
  };
562
387
 
563
388
  // src/domain/agentic-environment/agentic-environment.ts
564
389
  var AgenticEnvironment = class {
565
- constructor(name) {
390
+ constructor(name, opts) {
566
391
  this.subscribers = [];
567
- this.isActive = false;
392
+ var _a;
568
393
  this.name = name;
394
+ this.options = opts;
395
+ this.showLogs = ((_a = this.options) == null ? void 0 : _a.silent) !== false;
569
396
  }
570
397
  subscribe(participant) {
571
398
  this.subscribers.push(participant);
@@ -623,6 +450,36 @@ var AgenticEnvironment = class {
623
450
  external: (sub) => sub.onExternalEvent(source, item)
624
451
  });
625
452
  }
453
+ deliverError(source, error) {
454
+ this.deliverToSubscribers(source, {
455
+ internal: (src) => {
456
+ try {
457
+ src.onError(error);
458
+ } catch (error2) {
459
+ if (this.showLogs) {
460
+ console.warn(
461
+ `[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
462
+ ${JSON.stringify({ error: error2 }, null, 2)}`
463
+ );
464
+ }
465
+ } finally {
466
+ src.markInactive(this);
467
+ }
468
+ },
469
+ external: (sub) => {
470
+ try {
471
+ sub.onParticipantError(source, error);
472
+ } catch (error2) {
473
+ if (this.showLogs) {
474
+ console.warn(
475
+ `[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
476
+ ${JSON.stringify({ error: error2 }, null, 2)}`
477
+ );
478
+ }
479
+ }
480
+ }
481
+ });
482
+ }
626
483
  getListeningParticipants(source) {
627
484
  return this.subscribers.filter(
628
485
  (sub) => sub !== source && (sub.getListeners().length === 0 || sub.getListeners().some((listener) => source instanceof listener))
@@ -632,26 +489,32 @@ var AgenticEnvironment = class {
632
489
  var _a, _b;
633
490
  const authorizedListeners = this.getListeningParticipants(source);
634
491
  for (const subscriber of this.subscribers) {
635
- if (subscriber === source) {
636
- (_a = handlers == null ? void 0 : handlers.internal) == null ? void 0 : _a.call(handlers, subscriber);
637
- } else if (authorizedListeners.includes(subscriber)) {
638
- (_b = handlers == null ? void 0 : handlers.external) == null ? void 0 : _b.call(handlers, subscriber);
492
+ const isActive = subscriber.getEnvironmentState(this);
493
+ if (isActive) {
494
+ try {
495
+ if (subscriber === source) {
496
+ (_a = handlers == null ? void 0 : handlers.internal) == null ? void 0 : _a.call(handlers, subscriber);
497
+ } else if (authorizedListeners.includes(subscriber)) {
498
+ (_b = handlers == null ? void 0 : handlers.external) == null ? void 0 : _b.call(handlers, subscriber);
499
+ }
500
+ } catch (error) {
501
+ this.handleError(subscriber, error);
502
+ }
639
503
  }
640
504
  }
641
505
  }
642
- async start() {
643
- this.isActive = true;
644
- while (this.isActive) {
645
- await new Promise((resolve) => setTimeout(resolve, 100));
506
+ handleError(subscriber, error) {
507
+ if (error instanceof AgenticError) {
508
+ return this.deliverError(subscriber, error);
646
509
  }
510
+ const agenticError = new AgenticError({
511
+ message: error.message,
512
+ stack: error.stack,
513
+ enviornment: this,
514
+ source: subscriber
515
+ });
516
+ return this.deliverError(subscriber, agenticError);
647
517
  }
648
- stop() {
649
- this.isActive = false;
650
- }
651
- };
652
-
653
- // src/domain/agentic-environment/participants/agent.ts
654
- var Agent = class extends Participant {
655
518
  };
656
519
 
657
520
  // src/domain/model-context/semantic-event/semantic-event.ts
@@ -665,198 +528,101 @@ var SemanticEvent = class {
665
528
  }
666
529
  };
667
530
 
668
- // src/application/participants/agent.ts
669
- var BaseAgent = class extends Agent {
670
- constructor(inferenceRunner, functionCallRunner) {
671
- super();
672
- this.inferenceRunner = inferenceRunner;
673
- this.functionCallRunner = functionCallRunner;
674
- }
675
- onJoined() {
676
- }
677
- onLeft() {
678
- }
679
- onParticipantJoined(participant) {
680
- }
681
- onParticipantLeft(participant) {
682
- }
683
- onFunctionCall(item) {
684
- }
685
- onExternalFunctionCall(source, item) {
686
- }
687
- onFunctionCallOutput(item) {
688
- }
689
- onExternalFunctionCallOutput(source, item) {
690
- }
691
- onReasoning(item) {
692
- }
693
- onExternalReasoning(source, item) {
694
- }
695
- onModelMessage(item) {
696
- }
697
- onExternalModelMessage(source, item) {
698
- }
699
- onMessage(message) {
700
- }
701
- onInternalEvent(item) {
702
- }
703
- onExternalEvent(source, item) {
704
- }
705
- async executeFunctionCall(environment, functionCallItem, signal) {
706
- if (!this.isJoinedTo(environment)) return;
707
- const stream = this.functionCallRunner.run(functionCallItem, signal);
708
- for await (const item of stream) {
709
- environment.deliverFunctionCallOutput(this, item);
710
- }
711
- }
712
- async runInference(environment, context, model, signal) {
713
- if (!this.isJoinedTo(environment)) return;
714
- const stream = this.inferenceRunner.run(context, model, signal);
715
- for await (const item of stream) {
716
- if (item instanceof ReasoningItem) {
717
- environment.deliverReasoning(this, item);
718
- } else if (item instanceof FunctionCallItem) {
719
- environment.deliverFunctionCall(this, item);
720
- } else if (item instanceof ModelMessageItem) {
721
- environment.deliverModelMessage(this, item);
722
- } else if (item instanceof SemanticEvent) {
723
- environment.deliverSemanticEvent(this, item);
724
- }
725
- }
726
- }
727
- };
728
-
729
- // src/domain/agentic-environment/participants/human.ts
730
- var Human = class extends Participant {
731
- sendMessage(environment, message) {
732
- if (!this.isJoinedTo(environment)) throw new Error("Not joined to environment");
733
- environment.deliverMessage(this, message);
734
- }
735
- };
736
-
737
- // src/application/participants/human.ts
738
- var BaseHuman = class extends Human {
739
- onJoined() {
740
- }
741
- onLeft() {
742
- }
743
- onParticipantJoined(participant) {
744
- }
745
- onParticipantLeft(participant) {
746
- }
747
- onMessage(message) {
748
- }
749
- onFunctionCall(item) {
750
- }
751
- onFunctionCallOutput(item) {
752
- }
753
- onReasoning(item) {
754
- }
755
- onModelMessage(item) {
756
- }
757
- onExternalFunctionCall(source, item) {
758
- }
759
- onExternalFunctionCallOutput(source, item) {
760
- }
761
- onExternalReasoning(source, item) {
762
- }
763
- onExternalModelMessage(source, item) {
764
- }
765
- onInternalEvent(item) {
766
- }
767
- onExternalEvent(source, item) {
531
+ // src/domain/agentic-environment/inference/response.ts
532
+ var InferenceResponse = class {
533
+ constructor(contextItems, tokenUsage) {
534
+ this.contextItems = contextItems;
535
+ this.tokenUsage = tokenUsage;
768
536
  }
769
537
  };
770
538
 
771
- // src/domain/generative-model/inference-request.ts
772
- var InferenceRequest = class {
773
- constructor(model, context) {
774
- this.model = model;
775
- this.context = context;
539
+ // src/application/services/inference-runner.ts
540
+ var StreamingInference = class {
541
+ async *run(request, endpoint) {
542
+ var _a;
543
+ if ((_a = request.signal) == null ? void 0 : _a.aborted) {
544
+ return;
545
+ }
546
+ yield* endpoint.stream(request, request.signal);
776
547
  }
777
548
  };
778
-
779
- // src/application/runners/inference-runner.ts
780
- var DefaultInferenceRunner = class {
781
- constructor(runtime) {
782
- this.runtime = runtime;
783
- }
784
- async *run(context, model, signal) {
785
- const request = new InferenceRequest(model, context);
786
- if (model.getStreaming() && this.isStreamingRuntime(this.runtime)) {
787
- yield* this.runtime.stream(request, signal);
549
+ var NonStreamingInference = class {
550
+ async *run(request, endpoint) {
551
+ var _a, _b;
552
+ if ((_a = request.signal) == null ? void 0 : _a.aborted) {
788
553
  return;
789
554
  }
790
- const response = await this.runtime.infer(request);
555
+ const response = await endpoint.infer(request);
791
556
  for (const item of response.contextItems) {
792
- if (signal == null ? void 0 : signal.aborted) {
557
+ if ((_b = request.signal) == null ? void 0 : _b.aborted) {
793
558
  break;
794
559
  }
795
560
  yield item;
796
561
  }
797
562
  }
798
- isStreamingRuntime(runtime) {
799
- return typeof runtime.stream === "function";
800
- }
801
563
  };
802
564
 
803
- // src/application/runners/function-call-runner.ts
804
- var DefaultFunctionCallRunner = class {
805
- constructor(tools) {
806
- this.tools = tools;
565
+ // src/application/use-cases/run-inference.ts
566
+ var RunInference = class {
567
+ constructor(generativeModelRepository2, requestValidator) {
568
+ this.generativeModelRepository = generativeModelRepository2;
569
+ this.requestValidator = requestValidator;
807
570
  }
808
- async *run(call, signal) {
809
- const tool = this.tools.find((t) => t.name === call.name);
810
- if (!tool) throw new Error(`Unknown tool: ${call.name}`);
811
- const result = await tool.invoke(JSON.parse(call.args));
812
- yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
571
+ async execute(inferenceParams) {
572
+ var _a;
573
+ const { caller, environment, signal } = inferenceParams;
574
+ const generativeModel = await this.generativeModelRepository.getByModelName(inferenceParams.model);
575
+ this.requestValidator.validate(inferenceParams, generativeModel.specification);
576
+ const resolvedParams = {
577
+ ...inferenceParams,
578
+ maxOutputTokens: (_a = inferenceParams.maxOutputTokens) != null ? _a : generativeModel.specification.maxOutputTokens
579
+ };
580
+ const inferenceRunner = inferenceParams.streaming ? new StreamingInference() : new NonStreamingInference();
581
+ const result = inferenceRunner.run(resolvedParams, generativeModel.endpoint);
582
+ for await (const item of result) {
583
+ if (signal == null ? void 0 : signal.aborted) {
584
+ break;
585
+ }
586
+ if (item instanceof ReasoningItem) {
587
+ environment.deliverReasoning(caller, item);
588
+ } else if (item instanceof FunctionCallItem) {
589
+ environment.deliverFunctionCall(caller, item);
590
+ } else if (item instanceof ModelMessageItem) {
591
+ environment.deliverModelMessage(caller, item);
592
+ } else if (item instanceof SemanticEvent) {
593
+ environment.deliverSemanticEvent(caller, item);
594
+ }
595
+ }
813
596
  }
814
597
  };
815
598
 
816
- // src/infrastructure/providers/openai/models/gpt-5-5.ts
817
- var Gpt55 = class {
818
- constructor() {
819
- this.specification = {
820
- name: "gpt-5.5",
821
- supportReasoningEffort: true,
822
- defaultReasoningEffort: "none",
823
- supportStreaming: true,
824
- contextWindowSize: 105e4,
825
- maxOutputTokens: 128e3,
826
- supportFunctionCalling: true
827
- };
828
- this.tools = [];
829
- this.streaming = false;
830
- this.effort = new OpenAIReasoningEffort(
831
- this.specification.defaultReasoningEffort
832
- );
833
- }
834
- setStreaming(streaming) {
835
- this.streaming = streaming;
836
- }
837
- getStreaming() {
838
- return this.streaming;
839
- }
840
- setTools(tools) {
841
- this.tools = tools;
842
- }
843
- getTools() {
844
- return this.tools;
845
- }
846
- setReasoningEffort(effort) {
847
- this.effort.setReasoningEffort(effort);
599
+ // src/application/use-cases/execute-function-call.ts
600
+ var ExecuteFunctionCall = class {
601
+ constructor(functionCallRunner) {
602
+ this.functionCallRunner = functionCallRunner;
848
603
  }
849
- getReasoningEffort() {
850
- return this.effort.getReasoningEffort();
604
+ async execute(environment, functionCallItem, tool, caller, signal) {
605
+ const stream = this.functionCallRunner.run(functionCallItem, tool, signal);
606
+ for await (const item of stream) {
607
+ environment.deliverFunctionCallOutput(caller, item);
608
+ }
851
609
  }
852
610
  };
853
611
 
854
- // src/domain/agentic-environment/participants/observer.ts
855
- var Observer = class extends Participant {
612
+ // src/application/services/function-call-runner.ts
613
+ var FunctionCallRunner = class {
614
+ async *run(call, tool, signal) {
615
+ if (signal == null ? void 0 : signal.aborted) {
616
+ return;
617
+ }
618
+ if (!tool) throw new Error(`Unknown tool: ${call.name}`);
619
+ const result = await tool.invoke(JSON.parse(call.args));
620
+ yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
621
+ }
856
622
  };
857
623
 
858
- // src/application/participants/observer.ts
859
- var BaseObserver = class extends Observer {
624
+ // src/application/participants/participant.ts
625
+ var BaseParticipant = class extends Participant {
860
626
  onFunctionCall(item) {
861
627
  }
862
628
  onExternalFunctionCall(source, item) {
@@ -887,310 +653,79 @@ var BaseObserver = class extends Observer {
887
653
  }
888
654
  onExternalEvent(source, item) {
889
655
  }
656
+ onError(error) {
657
+ }
658
+ onParticipantError(source, error) {
659
+ }
890
660
  };
891
661
 
892
- // src/domain/generative-model/inference-response.ts
893
- var InferenceResponse = class {
894
- constructor(contextItems, tokenUsage) {
895
- this.contextItems = contextItems;
896
- this.tokenUsage = tokenUsage;
662
+ // src/application/use-cases/send-message.ts
663
+ var SendMessage = class {
664
+ async execute(environment, message, caller) {
665
+ if (!caller.isJoinedTo(environment)) {
666
+ throw new Error("Not joined to environment");
667
+ }
668
+ environment.deliverMessage(caller, message);
897
669
  }
898
670
  };
899
671
 
900
- // src/infrastructure/providers/openai/runtime/openai-responses.ts
901
- var import_openai = __toESM(require("openai"));
902
- var OpenAIResponses = class {
903
- constructor() {
904
- this.client = new import_openai.default();
672
+ // src/infrastructure/providers/anthropic/endpoints/anthropic-messages-mapper.ts
673
+ var AnthropicMessagesMapper = class {
674
+ toRequest(inferenceParams) {
675
+ const { messages, system } = this.mapContextItems(inferenceParams);
676
+ const outputConfig = {};
677
+ const request = {
678
+ model: inferenceParams.model,
679
+ messages
680
+ };
681
+ request.max_tokens = inferenceParams.maxOutputTokens;
682
+ if (system) {
683
+ request.system = system;
684
+ }
685
+ if (inferenceParams.tools && inferenceParams.tools.length > 0) {
686
+ request.tools = inferenceParams.tools.map((tool) => ({
687
+ name: tool.name,
688
+ description: tool.description,
689
+ input_schema: tool.parameters
690
+ }));
691
+ }
692
+ if (inferenceParams.structuredOutput) {
693
+ outputConfig.format = {
694
+ type: "json_schema",
695
+ json_schema: inferenceParams.structuredOutput.schema
696
+ };
697
+ }
698
+ if (inferenceParams.reasoningEffort) {
699
+ request.thinking = { type: "adaptive" };
700
+ outputConfig.effort = inferenceParams.reasoningEffort;
701
+ }
702
+ if (Object.keys(outputConfig).length > 0) {
703
+ request.output_config = outputConfig;
704
+ }
705
+ if (inferenceParams.streaming) {
706
+ request.stream = inferenceParams.streaming;
707
+ }
708
+ return request;
905
709
  }
906
- async infer(inferenceRequest) {
907
- const request = this.buildRequest(inferenceRequest);
908
- const response = await this.client.responses.create(request);
710
+ toResponse(response) {
909
711
  const contextItems = this.extractContextItems(response);
910
712
  const tokenUsage = this.extractTokenUsage(response);
911
713
  return new InferenceResponse(contextItems, tokenUsage);
912
714
  }
913
- async *stream(inferenceRequest, signal) {
914
- const specification = inferenceRequest.model.specification;
915
- if (!specification.supportStreaming) {
916
- throw new Error("Streaming is not supported for this model");
715
+ addContentBlock(messages, role, block) {
716
+ const lastMessage = messages[messages.length - 1];
717
+ if ((lastMessage == null ? void 0 : lastMessage.role) === role) {
718
+ lastMessage.content.push(block);
719
+ return;
917
720
  }
918
- const request = { ...this.buildRequest(inferenceRequest), stream: true };
919
- const response = await this.client.responses.create(request);
920
- for await (const event of response) {
921
- if (signal == null ? void 0 : signal.aborted) {
922
- break;
923
- }
924
- yield new SemanticEvent(event.type, event);
925
- }
926
- }
927
- buildRequest(inferenceRequest) {
928
- const specification = inferenceRequest.model.specification;
929
- const input = this.mapContextToRequest(inferenceRequest.context);
930
- const request = {
931
- model: specification.name,
932
- input
933
- };
934
- if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
935
- request.tools = inferenceRequest.model.getTools().map((tool) => {
936
- return {
937
- type: tool.type,
938
- name: tool.name,
939
- description: tool.description,
940
- parameters: tool.parameters
941
- };
942
- });
943
- }
944
- if (specification.supportReasoningEffort) {
945
- request.reasoning = {
946
- effort: inferenceRequest.model.getReasoningEffort()
947
- };
948
- }
949
- return request;
950
- }
951
- extractTokenUsage(response) {
952
- if (!response.usage) {
953
- return void 0;
954
- }
955
- return new TokenUsage(
956
- response.usage.input_tokens,
957
- response.usage.output_tokens,
958
- response.usage.total_tokens,
959
- new InputTokenDetails(response.usage.input_tokens_details.cached_tokens),
960
- new OutputTokenDetails(response.usage.output_tokens_details.reasoning_tokens)
961
- );
962
- }
963
- mapContextToRequest(context) {
964
- return context.getItems().map((item) => item.toJSON());
965
- }
966
- extractContextItems(response) {
967
- return response.output.map((item) => {
968
- if (item.type === "message" && item.role === "assistant") {
969
- return ModelMessageItem.rehydrate(item.content[0]);
970
- }
971
- if (item.type === "function_call") {
972
- return FunctionCallItem.rehydrate({
973
- callId: item.call_id,
974
- name: item.name,
975
- args: item.arguments
976
- });
977
- }
978
- if (item.type === "reasoning") {
979
- return ReasoningItem.rehydrate(item);
980
- }
981
- });
982
- }
983
- };
984
-
985
- // src/infrastructure/providers/openai/runtime/openai-compatible-chat-completions.ts
986
- var import_openai2 = __toESM(require("openai"));
987
- var OpenAICompatibleChatCompletions = class {
988
- constructor(config = {}) {
989
- var _a;
990
- this.client = new import_openai2.default({
991
- baseURL: config.baseURL,
992
- apiKey: config.apiKey
993
- });
994
- this.extraBody = (_a = config.extraBody) != null ? _a : {};
995
- }
996
- async infer(inferenceRequest) {
997
- const response = await this.client.chat.completions.create(this.buildRequest(inferenceRequest));
998
- const contextItems = this.extractContextItems(response);
999
- const tokenUsage = this.extractTokenUsage(response);
1000
- return new InferenceResponse(contextItems, tokenUsage);
1001
- }
1002
- async *stream(inferenceRequest, signal) {
1003
- var _a;
1004
- const stream = await this.client.chat.completions.create({
1005
- ...this.buildRequest(inferenceRequest),
1006
- stream: true
721
+ messages.push({
722
+ role,
723
+ content: [block]
1007
724
  });
1008
- for await (const event of stream) {
1009
- if (signal == null ? void 0 : signal.aborted) {
1010
- break;
1011
- }
1012
- yield new SemanticEvent((_a = event.object) != null ? _a : "chat.completion.chunk", event);
1013
- }
1014
725
  }
1015
- buildRequest(inferenceRequest) {
1016
- const specification = inferenceRequest.model.specification;
1017
- const request = {
1018
- ...this.extraBody,
1019
- model: specification.name,
1020
- messages: this.mapContextToRequest(inferenceRequest.context)
1021
- };
1022
- if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
1023
- request.tools = inferenceRequest.model.getTools().map((tool) => {
1024
- return {
1025
- type: "function",
1026
- function: {
1027
- name: tool.name,
1028
- description: tool.description,
1029
- parameters: tool.parameters
1030
- }
1031
- };
1032
- });
1033
- }
1034
- if (specification.supportReasoningEffort) {
1035
- request.reasoning_effort = inferenceRequest.model.getReasoningEffort();
1036
- }
1037
- return request;
1038
- }
1039
- extractTokenUsage(response) {
1040
- var _a, _b, _c, _d;
1041
- if (!response.usage) {
1042
- return void 0;
1043
- }
1044
- return new TokenUsage(
1045
- response.usage.prompt_tokens,
1046
- response.usage.completion_tokens,
1047
- response.usage.total_tokens,
1048
- new InputTokenDetails((_b = (_a = response.usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
1049
- new OutputTokenDetails((_d = (_c = response.usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
1050
- );
1051
- }
1052
- mapContextToRequest(context) {
1053
- var _a;
1054
- const messages = [];
1055
- for (const item of context.getItems()) {
1056
- if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
1057
- messages.push({ role: "system", content: item.content.text });
1058
- continue;
1059
- }
1060
- if (item instanceof UserMessageItem) {
1061
- messages.push({ role: "user", content: item.content.text });
1062
- continue;
1063
- }
1064
- if (item instanceof ModelMessageItem) {
1065
- messages.push({ role: "assistant", content: item.content.text });
1066
- continue;
1067
- }
1068
- if (item instanceof FunctionCallItem) {
1069
- const toolCall = {
1070
- id: item.callId,
1071
- type: "function",
1072
- function: { name: item.name, arguments: item.args }
1073
- };
1074
- const last = messages[messages.length - 1];
1075
- if ((last == null ? void 0 : last.role) === "assistant") {
1076
- last.tool_calls = (_a = last.tool_calls) != null ? _a : [];
1077
- last.tool_calls.push(toolCall);
1078
- } else {
1079
- messages.push({ role: "assistant", content: null, tool_calls: [toolCall] });
1080
- }
1081
- continue;
1082
- }
1083
- if (item instanceof FunctionCallOutputItem) {
1084
- messages.push({ role: "tool", tool_call_id: item.callId, content: item.output.text });
1085
- }
1086
- }
1087
- return messages;
1088
- }
1089
- extractContextItems(response) {
726
+ mapContextItems(inferenceParams) {
1090
727
  var _a, _b, _c;
1091
- const items = [];
1092
- const message = (_b = (_a = response.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.message;
1093
- if (!message) {
1094
- return items;
1095
- }
1096
- if (message.reasoning_content) {
1097
- items.push(
1098
- ReasoningItem.rehydrate({
1099
- content: InputText.rehydrate({ text: message.reasoning_content }),
1100
- encryptedContent: void 0,
1101
- summary: []
1102
- })
1103
- );
1104
- }
1105
- if (message.content) {
1106
- items.push(ModelMessageItem.rehydrate({ text: message.content }));
1107
- }
1108
- for (const toolCall of (_c = message.tool_calls) != null ? _c : []) {
1109
- items.push(
1110
- FunctionCallItem.rehydrate({
1111
- callId: toolCall.id,
1112
- name: toolCall.function.name,
1113
- args: toolCall.function.arguments
1114
- })
1115
- );
1116
- }
1117
- return items;
1118
- }
1119
- };
1120
-
1121
- // src/infrastructure/providers/anthropic/runtime/anthropic-messages.ts
1122
- var import_sdk = __toESM(require("@anthropic-ai/sdk"));
1123
- var AnthropicMessages = class {
1124
- constructor() {
1125
- this.client = new import_sdk.default();
1126
- }
1127
- async infer(inferenceRequest) {
1128
- const response = await this.client.messages.create(this.buildRequest(inferenceRequest));
1129
- const contextItems = this.extractContextItems(response);
1130
- const tokenUsage = this.extractTokenUsage(response);
1131
- return new InferenceResponse(contextItems, tokenUsage);
1132
- }
1133
- async *stream(inferenceRequest, signal) {
1134
- const stream = await this.client.messages.create({
1135
- ...this.buildRequest(inferenceRequest),
1136
- stream: true
1137
- });
1138
- for await (const event of stream) {
1139
- if (signal == null ? void 0 : signal.aborted) {
1140
- break;
1141
- }
1142
- yield new SemanticEvent(event.type, event);
1143
- }
1144
- }
1145
- buildRequest(inferenceRequest) {
1146
- const { messages, system } = this.mapContextToRequest(inferenceRequest.context);
1147
- const specification = inferenceRequest.model.specification;
1148
- const request = {
1149
- model: specification.name,
1150
- max_tokens: specification.maxOutputTokens,
1151
- messages
1152
- };
1153
- if (system) {
1154
- request.system = system;
1155
- }
1156
- if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
1157
- request.tools = inferenceRequest.model.getTools().map((tool) => {
1158
- return {
1159
- name: tool.name,
1160
- description: tool.description,
1161
- input_schema: tool.parameters
1162
- };
1163
- });
1164
- }
1165
- if (specification.supportReasoningEffort) {
1166
- const effort = inferenceRequest.model.getReasoningEffort();
1167
- const budgets = { low: 1024, medium: 4096, high: 8192 };
1168
- const budget = budgets[effort];
1169
- if (budget !== void 0) {
1170
- request.thinking = {
1171
- type: "enabled",
1172
- budget_tokens: Math.min(budget, specification.maxOutputTokens - 1)
1173
- };
1174
- }
1175
- }
1176
- return request;
1177
- }
1178
- extractTokenUsage(response) {
1179
- var _a, _b;
1180
- if (!response.usage) {
1181
- return void 0;
1182
- }
1183
- return new TokenUsage(
1184
- response.usage.input_tokens,
1185
- response.usage.output_tokens,
1186
- response.usage.input_tokens + response.usage.output_tokens,
1187
- new InputTokenDetails(
1188
- ((_a = response.usage.cache_creation_input_tokens) != null ? _a : 0) + ((_b = response.usage.cache_read_input_tokens) != null ? _b : 0)
1189
- ),
1190
- new OutputTokenDetails(0)
1191
- );
1192
- }
1193
- mapContextToRequest(context) {
728
+ const context = inferenceParams.context;
1194
729
  const messages = [];
1195
730
  const system = [];
1196
731
  for (const item of context.getItems()) {
@@ -1206,6 +741,14 @@ var AnthropicMessages = class {
1206
741
  this.addContentBlock(messages, "assistant", { type: "text", text: item.content.text });
1207
742
  continue;
1208
743
  }
744
+ if (item instanceof ReasoningItem) {
745
+ this.addContentBlock(messages, "assistant", {
746
+ type: "thinking",
747
+ thinking: (_b = (_a = item.content) == null ? void 0 : _a.text) != null ? _b : "",
748
+ signature: (_c = item.encryptedContent) != null ? _c : ""
749
+ });
750
+ continue;
751
+ }
1209
752
  if (item instanceof FunctionCallItem) {
1210
753
  let input;
1211
754
  try {
@@ -1234,6 +777,21 @@ var AnthropicMessages = class {
1234
777
  system: system.length > 0 ? system.join("\n\n") : void 0
1235
778
  };
1236
779
  }
780
+ extractTokenUsage(response) {
781
+ var _a, _b;
782
+ if (!response.usage) {
783
+ return void 0;
784
+ }
785
+ return new TokenUsage(
786
+ response.usage.input_tokens,
787
+ response.usage.output_tokens,
788
+ response.usage.input_tokens + response.usage.output_tokens,
789
+ new InputTokenDetails(
790
+ ((_a = response.usage.cache_creation_input_tokens) != null ? _a : 0) + ((_b = response.usage.cache_read_input_tokens) != null ? _b : 0)
791
+ ),
792
+ new OutputTokenDetails(0)
793
+ );
794
+ }
1237
795
  extractContextItems(response) {
1238
796
  var _a;
1239
797
  const items = [];
@@ -1256,7 +814,7 @@ var AnthropicMessages = class {
1256
814
  items.push(
1257
815
  ReasoningItem.rehydrate({
1258
816
  content: block.thinking ? InputText.rehydrate({ text: block.thinking }) : void 0,
1259
- encryptedContent: void 0,
817
+ encryptedContent: block.signature,
1260
818
  summary: []
1261
819
  })
1262
820
  );
@@ -1264,343 +822,261 @@ var AnthropicMessages = class {
1264
822
  }
1265
823
  return items;
1266
824
  }
1267
- addContentBlock(messages, role, block) {
1268
- const lastMessage = messages[messages.length - 1];
1269
- if ((lastMessage == null ? void 0 : lastMessage.role) === role) {
1270
- lastMessage.content.push(block);
1271
- return;
1272
- }
1273
- messages.push({
1274
- role,
1275
- content: [block]
1276
- });
1277
- }
1278
825
  };
1279
826
 
1280
- // src/infrastructure/providers/anthropic/reasoning-effort.ts
1281
- var AnthropicReasoningEffort = class {
1282
- constructor(reasoningEffort) {
1283
- this.reasoningEffort = reasoningEffort;
827
+ // src/infrastructure/providers/anthropic/endpoints/anthropic-messages.ts
828
+ var import_sdk = __toESM(require("@anthropic-ai/sdk"));
829
+ var AnthropicMessages = class {
830
+ constructor(endpointMapper = new AnthropicMessagesMapper()) {
831
+ this.endpointMapper = endpointMapper;
832
+ this.client = new import_sdk.default();
1284
833
  }
1285
- setReasoningEffort(effort) {
1286
- this.reasoningEffort = effort;
834
+ async infer(inferenceParams) {
835
+ const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
836
+ const response = await this.client.messages.create(inferenceRequest);
837
+ return this.endpointMapper.toResponse(response);
1287
838
  }
1288
- getReasoningEffort() {
1289
- if (!this.reasoningEffort) {
1290
- throw new Error("Reasoning effort not supported");
839
+ async *stream(inferenceParams, signal) {
840
+ const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
841
+ const stream = await this.client.messages.create(inferenceRequest);
842
+ for await (const event of stream) {
843
+ if (signal == null ? void 0 : signal.aborted) {
844
+ break;
845
+ }
846
+ yield new SemanticEvent(event.type, event);
1291
847
  }
1292
- return this.reasoningEffort;
1293
848
  }
1294
849
  };
1295
850
 
1296
- // src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts
1297
- var ClaudeOpus48 = class {
1298
- constructor() {
1299
- this.specification = {
1300
- name: "claude-opus-4-8",
1301
- supportReasoningEffort: true,
1302
- defaultReasoningEffort: "none",
1303
- supportStreaming: true,
1304
- contextWindowSize: 2e5,
1305
- maxOutputTokens: 32e3,
1306
- supportFunctionCalling: true
1307
- };
1308
- this.tools = [];
1309
- this.streaming = false;
1310
- this.effort = new AnthropicReasoningEffort(
1311
- this.specification.defaultReasoningEffort
1312
- );
1313
- }
1314
- setStreaming(streaming) {
1315
- this.streaming = streaming;
1316
- }
1317
- getStreaming() {
1318
- return this.streaming;
1319
- }
1320
- setTools(tools) {
1321
- this.tools = tools;
1322
- }
1323
- getTools() {
1324
- return this.tools;
1325
- }
1326
- setReasoningEffort(effort) {
1327
- this.effort.setReasoningEffort(effort);
1328
- }
1329
- getReasoningEffort() {
1330
- return this.effort.getReasoningEffort();
1331
- }
1332
- };
1333
-
1334
- // src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
1335
- var ClaudeOpus47 = class {
1336
- constructor() {
1337
- this.specification = {
1338
- name: "claude-opus-4-7",
1339
- supportReasoningEffort: true,
1340
- defaultReasoningEffort: "none",
1341
- supportStreaming: true,
1342
- contextWindowSize: 2e5,
1343
- maxOutputTokens: 32e3,
1344
- supportFunctionCalling: true
1345
- };
1346
- this.tools = [];
1347
- this.streaming = false;
1348
- this.effort = new AnthropicReasoningEffort(
1349
- this.specification.defaultReasoningEffort
1350
- );
1351
- }
1352
- setStreaming(streaming) {
1353
- this.streaming = streaming;
1354
- }
1355
- getStreaming() {
1356
- return this.streaming;
1357
- }
1358
- setTools(tools) {
1359
- this.tools = tools;
1360
- }
1361
- getTools() {
1362
- return this.tools;
1363
- }
1364
- setReasoningEffort(effort) {
1365
- this.effort.setReasoningEffort(effort);
1366
- }
1367
- getReasoningEffort() {
1368
- return this.effort.getReasoningEffort();
1369
- }
1370
- };
851
+ // src/infrastructure/providers/openai/endpoints/openai-responses.ts
852
+ var import_openai = __toESM(require("openai"));
1371
853
 
1372
- // src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
1373
- var ClaudeSonnet46 = class {
1374
- constructor() {
1375
- this.specification = {
1376
- name: "claude-sonnet-4-6",
1377
- supportReasoningEffort: true,
1378
- defaultReasoningEffort: "none",
1379
- supportStreaming: true,
1380
- contextWindowSize: 2e5,
1381
- maxOutputTokens: 64e3,
1382
- supportFunctionCalling: true
1383
- };
1384
- this.tools = [];
1385
- this.streaming = false;
1386
- this.effort = new AnthropicReasoningEffort(
1387
- this.specification.defaultReasoningEffort
1388
- );
1389
- }
1390
- setStreaming(streaming) {
1391
- this.streaming = streaming;
1392
- }
1393
- getStreaming() {
1394
- return this.streaming;
1395
- }
1396
- setTools(tools) {
1397
- this.tools = tools;
1398
- }
1399
- getTools() {
1400
- return this.tools;
1401
- }
1402
- setReasoningEffort(effort) {
1403
- this.effort.setReasoningEffort(effort);
854
+ // src/domain/model-context/context-item/item-content/summary-text.ts
855
+ var SummaryText = class _SummaryText extends ItemContent {
856
+ constructor(text) {
857
+ super();
858
+ this.text = text;
859
+ this.type = "summary_text";
1404
860
  }
1405
- getReasoningEffort() {
1406
- return this.effort.getReasoningEffort();
861
+ static rehydrate(data) {
862
+ return new _SummaryText(data.text);
1407
863
  }
1408
864
  };
1409
865
 
1410
- // src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
1411
- var ClaudeHaiku45 = class {
1412
- constructor() {
1413
- this.specification = {
1414
- name: "claude-haiku-4-5",
1415
- supportReasoningEffort: true,
1416
- defaultReasoningEffort: "none",
1417
- supportStreaming: true,
1418
- contextWindowSize: 2e5,
1419
- maxOutputTokens: 64e3,
1420
- supportFunctionCalling: true
866
+ // src/infrastructure/providers/openai/endpoints/openai-responses-mapper.ts
867
+ var OpenAIResponsesMapper = class {
868
+ toRequest(inferenceParams) {
869
+ var _a, _b;
870
+ const request = {
871
+ model: inferenceParams.model,
872
+ input: this.mapContextItems(inferenceParams)
1421
873
  };
1422
- this.tools = [];
1423
- this.streaming = false;
1424
- this.effort = new AnthropicReasoningEffort(
1425
- this.specification.defaultReasoningEffort
1426
- );
1427
- }
1428
- setStreaming(streaming) {
1429
- this.streaming = streaming;
1430
- }
1431
- getStreaming() {
1432
- return this.streaming;
1433
- }
1434
- setTools(tools) {
1435
- this.tools = tools;
1436
- }
1437
- getTools() {
1438
- return this.tools;
1439
- }
1440
- setReasoningEffort(effort) {
1441
- this.effort.setReasoningEffort(effort);
1442
- }
1443
- getReasoningEffort() {
1444
- return this.effort.getReasoningEffort();
1445
- }
1446
- };
1447
-
1448
- // src/infrastructure/providers/deepseek/reasoning-effort.ts
1449
- var DeepSeekReasoningEffort = class {
1450
- constructor(reasoningEffort) {
1451
- this.reasoningEffort = reasoningEffort;
1452
- }
1453
- setReasoningEffort(effort) {
1454
- this.reasoningEffort = effort;
1455
- }
1456
- getReasoningEffort() {
1457
- if (!this.reasoningEffort) {
1458
- throw new Error("Reasoning effort not supported");
874
+ if (inferenceParams.tools && inferenceParams.tools.length > 0) {
875
+ request.tools = inferenceParams.tools.map((tool) => ({
876
+ type: tool.type,
877
+ name: tool.name,
878
+ description: tool.description,
879
+ parameters: tool.parameters
880
+ }));
1459
881
  }
1460
- return this.reasoningEffort;
1461
- }
1462
- };
1463
-
1464
- // src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts
1465
- var DeepSeekV4Flash = class {
1466
- constructor() {
1467
- this.specification = {
1468
- name: "deepseek-v4-flash",
1469
- supportReasoningEffort: true,
1470
- defaultReasoningEffort: "high",
1471
- supportStreaming: true,
1472
- contextWindowSize: 1e6,
1473
- maxOutputTokens: 384e3,
1474
- supportFunctionCalling: true
1475
- };
1476
- this.tools = [];
1477
- this.streaming = false;
1478
- this.effort = new DeepSeekReasoningEffort(
1479
- this.specification.defaultReasoningEffort
1480
- );
1481
- }
1482
- setStreaming(streaming) {
1483
- this.streaming = streaming;
1484
- }
1485
- getStreaming() {
1486
- return this.streaming;
1487
- }
1488
- setTools(tools) {
1489
- this.tools = tools;
1490
- }
1491
- getTools() {
1492
- return this.tools;
882
+ if (inferenceParams.reasoningEffort) {
883
+ request.reasoning = {
884
+ effort: inferenceParams.reasoningEffort
885
+ };
886
+ }
887
+ if (inferenceParams.structuredOutput) {
888
+ const format = inferenceParams.structuredOutput;
889
+ request.text = {
890
+ format: {
891
+ type: "json_schema",
892
+ name: (_a = format.name) != null ? _a : "response",
893
+ schema: format.schema,
894
+ strict: (_b = format.strict) != null ? _b : true
895
+ }
896
+ };
897
+ }
898
+ if (inferenceParams.streaming) {
899
+ request.stream = inferenceParams.streaming;
900
+ }
901
+ return request;
1493
902
  }
1494
- setReasoningEffort(effort) {
1495
- this.effort.setReasoningEffort(effort);
903
+ toResponse(response) {
904
+ const contextItems = this.extractContextItems(response);
905
+ const tokenUsage = this.extractTokenUsage(response);
906
+ return new InferenceResponse(contextItems, tokenUsage);
1496
907
  }
1497
- getReasoningEffort() {
1498
- return this.effort.getReasoningEffort();
908
+ mapContextItems(inferenceParams) {
909
+ const input = [];
910
+ for (const item of inferenceParams.context.getItems()) {
911
+ if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem || item instanceof UserMessageItem) {
912
+ input.push({
913
+ type: item.type,
914
+ role: item.role,
915
+ content: [{ type: "input_text", text: item.content.text }]
916
+ });
917
+ continue;
918
+ }
919
+ if (item instanceof ModelMessageItem) {
920
+ input.push({
921
+ type: item.type,
922
+ role: item.role,
923
+ content: [{ type: "output_text", text: item.content.text }]
924
+ });
925
+ continue;
926
+ }
927
+ if (item instanceof FunctionCallItem) {
928
+ input.push({
929
+ type: item.type,
930
+ call_id: item.callId,
931
+ name: item.name,
932
+ arguments: item.args
933
+ });
934
+ continue;
935
+ }
936
+ if (item instanceof FunctionCallOutputItem) {
937
+ input.push({
938
+ type: item.type,
939
+ call_id: item.callId,
940
+ output: [{ type: "input_text", text: item.output.text }]
941
+ });
942
+ continue;
943
+ }
944
+ if (item instanceof ReasoningItem) {
945
+ const reasoningInput = {
946
+ type: item.type,
947
+ summary: item.summary.map((summary) => ({ type: "summary_text", text: summary.text }))
948
+ };
949
+ if (item.encryptedContent !== void 0) {
950
+ reasoningInput.encrypted_content = item.encryptedContent;
951
+ }
952
+ input.push(reasoningInput);
953
+ }
954
+ }
955
+ return input;
1499
956
  }
1500
- };
1501
-
1502
- // src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
1503
- var DeepSeekV4Pro = class {
1504
- constructor() {
1505
- this.specification = {
1506
- name: "deepseek-v4-pro",
1507
- supportReasoningEffort: true,
1508
- defaultReasoningEffort: "high",
1509
- supportStreaming: true,
1510
- contextWindowSize: 1e6,
1511
- maxOutputTokens: 384e3,
1512
- supportFunctionCalling: true
1513
- };
1514
- this.tools = [];
1515
- this.streaming = false;
1516
- this.effort = new DeepSeekReasoningEffort(
1517
- this.specification.defaultReasoningEffort
957
+ extractTokenUsage(response) {
958
+ var _a, _b, _c, _d;
959
+ if (!response.usage) {
960
+ return void 0;
961
+ }
962
+ return new TokenUsage(
963
+ response.usage.input_tokens,
964
+ response.usage.output_tokens,
965
+ response.usage.total_tokens,
966
+ new InputTokenDetails((_b = (_a = response.usage.input_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
967
+ new OutputTokenDetails((_d = (_c = response.usage.output_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
1518
968
  );
1519
969
  }
1520
- setStreaming(streaming) {
1521
- this.streaming = streaming;
1522
- }
1523
- getStreaming() {
1524
- return this.streaming;
1525
- }
1526
- setTools(tools) {
1527
- this.tools = tools;
1528
- }
1529
- getTools() {
1530
- return this.tools;
1531
- }
1532
- setReasoningEffort(effort) {
1533
- this.effort.setReasoningEffort(effort);
1534
- }
1535
- getReasoningEffort() {
1536
- return this.effort.getReasoningEffort();
970
+ extractContextItems(response) {
971
+ var _a, _b, _c;
972
+ const items = [];
973
+ for (const item of (_a = response.output) != null ? _a : []) {
974
+ if (item.type === "message" && item.role === "assistant") {
975
+ const firstContent = (_b = item.content) == null ? void 0 : _b[0];
976
+ if (firstContent) {
977
+ items.push(ModelMessageItem.rehydrate(firstContent));
978
+ }
979
+ continue;
980
+ }
981
+ if (item.type === "function_call") {
982
+ items.push(
983
+ FunctionCallItem.rehydrate({
984
+ callId: item.call_id,
985
+ name: item.name,
986
+ args: item.arguments
987
+ })
988
+ );
989
+ continue;
990
+ }
991
+ if (item.type === "reasoning") {
992
+ items.push(
993
+ ReasoningItem.rehydrate({
994
+ content: void 0,
995
+ encryptedContent: item.encrypted_content,
996
+ summary: ((_c = item.summary) != null ? _c : []).map(
997
+ (summary) => SummaryText.rehydrate({ text: summary.text })
998
+ )
999
+ })
1000
+ );
1001
+ }
1002
+ }
1003
+ return items;
1537
1004
  }
1538
1005
  };
1539
1006
 
1540
- // src/infrastructure/providers/gemini/runtime/gemini-generate-content.ts
1541
- var import_genai = require("@google/genai");
1542
- var GeminiGenerateContent = class {
1543
- constructor() {
1544
- this.client = new import_genai.GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
1007
+ // src/infrastructure/providers/openai/endpoints/openai-responses.ts
1008
+ var OpenAIResponses = class {
1009
+ constructor(endpointMapper = new OpenAIResponsesMapper()) {
1010
+ this.endpointMapper = endpointMapper;
1011
+ this.client = new import_openai.default();
1545
1012
  }
1546
- async infer(inferenceRequest) {
1547
- const response = await this.client.models.generateContent(this.buildRequest(inferenceRequest));
1548
- const contextItems = this.extractContextItems(response);
1549
- const tokenUsage = this.extractTokenUsage(response);
1550
- return new InferenceResponse(contextItems, tokenUsage);
1013
+ async infer(inferenceParams) {
1014
+ const request = this.endpointMapper.toRequest(inferenceParams);
1015
+ const response = await this.client.responses.create(request);
1016
+ return this.endpointMapper.toResponse(response);
1551
1017
  }
1552
- async *stream(inferenceRequest, signal) {
1553
- const stream = await this.client.models.generateContentStream(this.buildRequest(inferenceRequest));
1554
- for await (const chunk of stream) {
1018
+ async *stream(inferenceParams, signal) {
1019
+ const request = this.endpointMapper.toRequest(inferenceParams);
1020
+ const response = await this.client.responses.create(request);
1021
+ for await (const event of response) {
1555
1022
  if (signal == null ? void 0 : signal.aborted) {
1556
1023
  break;
1557
1024
  }
1558
- yield new SemanticEvent("generate_content_chunk", chunk);
1025
+ yield new SemanticEvent(event.type, event);
1559
1026
  }
1560
1027
  }
1561
- buildRequest(inferenceRequest) {
1562
- const specification = inferenceRequest.model.specification;
1563
- const { contents, systemInstruction } = this.mapContextToRequest(inferenceRequest.context);
1028
+ };
1029
+
1030
+ // src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts
1031
+ var import_genai = require("@google/genai");
1032
+
1033
+ // src/infrastructure/providers/gemini/endpoints/gemini-generate-content-mapper.ts
1034
+ var GeminiGenerateContentMapper = class {
1035
+ toRequest(inferenceParams) {
1036
+ const { contents, systemInstruction } = this.mapContextItems(inferenceParams);
1564
1037
  const config = {};
1565
1038
  if (systemInstruction) {
1566
1039
  config.systemInstruction = systemInstruction;
1567
1040
  }
1568
- if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
1041
+ if (inferenceParams.tools && inferenceParams.tools.length > 0) {
1569
1042
  config.tools = [
1570
1043
  {
1571
- functionDeclarations: inferenceRequest.model.getTools().map((tool) => {
1572
- return {
1573
- name: tool.name,
1574
- description: tool.description,
1575
- parametersJsonSchema: tool.parameters
1576
- };
1577
- })
1044
+ functionDeclarations: inferenceParams.tools.map((tool) => ({
1045
+ name: tool.name,
1046
+ description: tool.description,
1047
+ parametersJsonSchema: tool.parameters
1048
+ }))
1578
1049
  }
1579
1050
  ];
1580
1051
  }
1581
- if (specification.supportReasoningEffort) {
1582
- const effort = inferenceRequest.model.getReasoningEffort();
1583
- const thinkingLevel = effort === "none" ? "minimal" : effort;
1584
- config.thinkingConfig = { thinkingLevel, includeThoughts: true };
1052
+ if (inferenceParams.structuredOutput) {
1053
+ config.responseMimeType = "application/json";
1054
+ config.responseSchema = inferenceParams.structuredOutput.schema;
1585
1055
  }
1586
- return { model: specification.name, contents, config };
1587
- }
1588
- extractTokenUsage(response) {
1589
- var _a, _b, _c, _d, _e;
1590
- const usage = response.usageMetadata;
1591
- if (!usage) {
1592
- return void 0;
1056
+ if (inferenceParams.reasoningEffort) {
1057
+ config.thinkingConfig = {
1058
+ thinkingLevel: inferenceParams.reasoningEffort,
1059
+ includeThoughts: true
1060
+ };
1593
1061
  }
1594
- return new TokenUsage(
1595
- (_a = usage.promptTokenCount) != null ? _a : 0,
1596
- (_b = usage.candidatesTokenCount) != null ? _b : 0,
1597
- (_c = usage.totalTokenCount) != null ? _c : 0,
1598
- new InputTokenDetails((_d = usage.cachedContentTokenCount) != null ? _d : 0),
1599
- new OutputTokenDetails((_e = usage.thoughtsTokenCount) != null ? _e : 0)
1600
- );
1062
+ const request = {
1063
+ model: inferenceParams.model,
1064
+ contents,
1065
+ config
1066
+ };
1067
+ if (inferenceParams.streaming) {
1068
+ request.stream = inferenceParams.streaming;
1069
+ }
1070
+ return request;
1071
+ }
1072
+ toResponse(response) {
1073
+ const contextItems = this.extractContextItems(response);
1074
+ const tokenUsage = this.extractTokenUsage(response);
1075
+ return new InferenceResponse(contextItems, tokenUsage);
1601
1076
  }
1602
- mapContextToRequest(context) {
1077
+ mapContextItems(inferenceParams) {
1603
1078
  var _a;
1079
+ const context = inferenceParams.context;
1604
1080
  const contents = [];
1605
1081
  const system = [];
1606
1082
  const callNames = /* @__PURE__ */ new Map();
@@ -1643,6 +1119,36 @@ var GeminiGenerateContent = class {
1643
1119
  systemInstruction: system.length > 0 ? system.join("\n\n") : void 0
1644
1120
  };
1645
1121
  }
1122
+ addPart(contents, role, part) {
1123
+ const last = contents[contents.length - 1];
1124
+ if ((last == null ? void 0 : last.role) === role) {
1125
+ last.parts.push(part);
1126
+ return;
1127
+ }
1128
+ contents.push({ role, parts: [part] });
1129
+ }
1130
+ parseResponse(output) {
1131
+ try {
1132
+ const parsed = JSON.parse(output);
1133
+ return parsed && typeof parsed === "object" ? parsed : { output };
1134
+ } catch (e) {
1135
+ return { output };
1136
+ }
1137
+ }
1138
+ extractTokenUsage(response) {
1139
+ var _a, _b, _c, _d, _e;
1140
+ const usage = response.usageMetadata;
1141
+ if (!usage) {
1142
+ return void 0;
1143
+ }
1144
+ return new TokenUsage(
1145
+ (_a = usage.promptTokenCount) != null ? _a : 0,
1146
+ (_b = usage.candidatesTokenCount) != null ? _b : 0,
1147
+ (_c = usage.totalTokenCount) != null ? _c : 0,
1148
+ new InputTokenDetails((_d = usage.cachedContentTokenCount) != null ? _d : 0),
1149
+ new OutputTokenDetails((_e = usage.thoughtsTokenCount) != null ? _e : 0)
1150
+ );
1151
+ }
1646
1152
  extractContextItems(response) {
1647
1153
  var _a, _b, _c, _d, _e, _f;
1648
1154
  const items = [];
@@ -1674,158 +1180,653 @@ var GeminiGenerateContent = class {
1674
1180
  }
1675
1181
  return items;
1676
1182
  }
1677
- parseResponse(output) {
1678
- try {
1679
- const parsed = JSON.parse(output);
1680
- return parsed && typeof parsed === "object" ? parsed : { output };
1681
- } catch (e) {
1682
- return { output };
1683
- }
1183
+ };
1184
+
1185
+ // src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts
1186
+ var GeminiGenerateContent = class {
1187
+ constructor(endpointMapper = new GeminiGenerateContentMapper()) {
1188
+ this.endpointMapper = endpointMapper;
1189
+ this.client = new import_genai.GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
1684
1190
  }
1685
- addPart(contents, role, part) {
1686
- const last = contents[contents.length - 1];
1687
- if ((last == null ? void 0 : last.role) === role) {
1688
- last.parts.push(part);
1689
- return;
1191
+ async infer(inferenceParams) {
1192
+ const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
1193
+ const response = await this.client.models.generateContent(inferenceRequest);
1194
+ return this.endpointMapper.toResponse(response);
1195
+ }
1196
+ async *stream(inferenceParams, signal) {
1197
+ const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
1198
+ const stream = await this.client.models.generateContentStream(inferenceRequest);
1199
+ for await (const chunk of stream) {
1200
+ if (signal == null ? void 0 : signal.aborted) {
1201
+ break;
1202
+ }
1203
+ yield new SemanticEvent("generate_content_chunk", chunk);
1690
1204
  }
1691
- contents.push({ role, parts: [part] });
1692
1205
  }
1693
1206
  };
1694
1207
 
1695
- // src/infrastructure/providers/gemini/reasoning-effort.ts
1696
- var GeminiReasoningEffort = class {
1697
- constructor(reasoningEffort) {
1698
- this.reasoningEffort = reasoningEffort;
1208
+ // src/infrastructure/providers/openai/endpoints/openai-chat-completions-mapper.ts
1209
+ var OpenAIChatCompletionsMapper = class {
1210
+ toRequest(inferenceParams) {
1211
+ const request = {
1212
+ model: inferenceParams.model,
1213
+ messages: this.mapContextItems(inferenceParams)
1214
+ };
1215
+ if (inferenceParams.tools && inferenceParams.tools.length > 0) {
1216
+ request.tools = inferenceParams.tools.map((tool) => ({
1217
+ type: "function",
1218
+ function: {
1219
+ name: tool.name,
1220
+ description: tool.description,
1221
+ parameters: tool.parameters
1222
+ }
1223
+ }));
1224
+ }
1225
+ if (inferenceParams.reasoningEffort) {
1226
+ request.reasoning_effort = inferenceParams.reasoningEffort;
1227
+ }
1228
+ if (inferenceParams.streaming) {
1229
+ request.stream = inferenceParams.streaming;
1230
+ }
1231
+ return request;
1232
+ }
1233
+ toResponse(response) {
1234
+ const contextItems = this.extractContextItems(response);
1235
+ const tokenUsage = this.extractTokenUsage(response);
1236
+ return new InferenceResponse(contextItems, tokenUsage);
1237
+ }
1238
+ mapContextItems(inferenceParams) {
1239
+ var _a;
1240
+ const messages = [];
1241
+ for (const item of inferenceParams.context.getItems()) {
1242
+ if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
1243
+ messages.push({ role: "system", content: item.content.text });
1244
+ continue;
1245
+ }
1246
+ if (item instanceof UserMessageItem) {
1247
+ messages.push({ role: "user", content: item.content.text });
1248
+ continue;
1249
+ }
1250
+ if (item instanceof ModelMessageItem) {
1251
+ messages.push({ role: "assistant", content: item.content.text });
1252
+ continue;
1253
+ }
1254
+ if (item instanceof FunctionCallItem) {
1255
+ const toolCall = {
1256
+ id: item.callId,
1257
+ type: "function",
1258
+ function: { name: item.name, arguments: item.args }
1259
+ };
1260
+ const last = messages[messages.length - 1];
1261
+ if ((last == null ? void 0 : last.role) === "assistant") {
1262
+ last.tool_calls = (_a = last.tool_calls) != null ? _a : [];
1263
+ last.tool_calls.push(toolCall);
1264
+ } else {
1265
+ messages.push({ role: "assistant", content: null, tool_calls: [toolCall] });
1266
+ }
1267
+ continue;
1268
+ }
1269
+ if (item instanceof FunctionCallOutputItem) {
1270
+ messages.push({ role: "tool", tool_call_id: item.callId, content: item.output.text });
1271
+ }
1272
+ }
1273
+ return messages;
1699
1274
  }
1700
- setReasoningEffort(effort) {
1701
- this.reasoningEffort = effort;
1275
+ extractTokenUsage(response) {
1276
+ var _a, _b, _c, _d;
1277
+ if (!response.usage) {
1278
+ return void 0;
1279
+ }
1280
+ return new TokenUsage(
1281
+ response.usage.prompt_tokens,
1282
+ response.usage.completion_tokens,
1283
+ response.usage.total_tokens,
1284
+ new InputTokenDetails((_b = (_a = response.usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
1285
+ new OutputTokenDetails((_d = (_c = response.usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
1286
+ );
1702
1287
  }
1703
- getReasoningEffort() {
1704
- if (!this.reasoningEffort) {
1705
- throw new Error("Reasoning effort not supported");
1288
+ extractContextItems(response) {
1289
+ var _a, _b, _c;
1290
+ const items = [];
1291
+ const message = (_b = (_a = response.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.message;
1292
+ if (!message) {
1293
+ return items;
1294
+ }
1295
+ if (message.reasoning_content) {
1296
+ items.push(
1297
+ ReasoningItem.rehydrate({
1298
+ content: InputText.rehydrate({ text: message.reasoning_content }),
1299
+ encryptedContent: void 0,
1300
+ summary: []
1301
+ })
1302
+ );
1303
+ }
1304
+ if (message.content) {
1305
+ items.push(ModelMessageItem.rehydrate({ text: message.content }));
1306
+ }
1307
+ for (const toolCall of (_c = message.tool_calls) != null ? _c : []) {
1308
+ items.push(
1309
+ FunctionCallItem.rehydrate({
1310
+ callId: toolCall.id,
1311
+ name: toolCall.function.name,
1312
+ args: toolCall.function.arguments
1313
+ })
1314
+ );
1706
1315
  }
1707
- return this.reasoningEffort;
1316
+ return items;
1708
1317
  }
1709
1318
  };
1710
1319
 
1711
- // src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts
1712
- var Gemini35Flash = class {
1713
- constructor() {
1714
- this.specification = {
1715
- name: "gemini-3.5-flash",
1716
- supportReasoningEffort: true,
1717
- defaultReasoningEffort: "medium",
1718
- supportStreaming: true,
1719
- contextWindowSize: 1048576,
1720
- maxOutputTokens: 64e3,
1721
- supportFunctionCalling: true
1320
+ // src/infrastructure/providers/openai/endpoints/openai-chat-completions.ts
1321
+ var import_openai2 = __toESM(require("openai"));
1322
+ var OpenAIChatCompletions = class {
1323
+ constructor(endpointMapper = new OpenAIChatCompletionsMapper(), config = {}) {
1324
+ var _a;
1325
+ this.endpointMapper = endpointMapper;
1326
+ this.client = new import_openai2.default({
1327
+ baseURL: config.baseURL,
1328
+ apiKey: config.apiKey
1329
+ });
1330
+ this.extraBody = (_a = config.extraBody) != null ? _a : {};
1331
+ }
1332
+ buildRequest(inferenceParams) {
1333
+ return {
1334
+ ...this.extraBody,
1335
+ ...this.endpointMapper.toRequest(inferenceParams)
1722
1336
  };
1723
- this.tools = [];
1724
- this.streaming = false;
1725
- this.effort = new GeminiReasoningEffort(
1726
- this.specification.defaultReasoningEffort
1727
- );
1728
1337
  }
1729
- setStreaming(streaming) {
1730
- this.streaming = streaming;
1338
+ async infer(inferenceParams) {
1339
+ const response = await this.client.chat.completions.create(this.buildRequest(inferenceParams));
1340
+ return this.endpointMapper.toResponse(response);
1341
+ }
1342
+ async *stream(inferenceParams, signal) {
1343
+ var _a;
1344
+ const stream = await this.client.chat.completions.create(this.buildRequest(inferenceParams));
1345
+ for await (const event of stream) {
1346
+ if (signal == null ? void 0 : signal.aborted) {
1347
+ break;
1348
+ }
1349
+ yield new SemanticEvent((_a = event.object) != null ? _a : "chat.completion.chunk", event);
1350
+ }
1731
1351
  }
1732
- getStreaming() {
1733
- return this.streaming;
1352
+ };
1353
+
1354
+ // src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
1355
+ var claudeSonnet46Specification = {
1356
+ name: "claude-sonnet-4-6",
1357
+ provider: "anthropic",
1358
+ supportsReasoningEffort: true,
1359
+ supportedReasoningEfforts: ["max", "high", "medium", "low"],
1360
+ supportedContextItemTypes: [
1361
+ "user_message",
1362
+ "system_message",
1363
+ "developer_message",
1364
+ "reasoning",
1365
+ "function_call",
1366
+ "function_call_output",
1367
+ "model_message"
1368
+ ],
1369
+ supportsStreaming: true,
1370
+ contextWindowSize: 2e5,
1371
+ maxOutputTokens: 64e3,
1372
+ supportsFunctionCalling: true,
1373
+ supportsStructuredOutput: true
1374
+ };
1375
+
1376
+ // src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts
1377
+ var claudeOpus48Specification = {
1378
+ name: "claude-opus-4-8",
1379
+ provider: "anthropic",
1380
+ supportsReasoningEffort: true,
1381
+ supportedReasoningEfforts: ["max", "xhigh", "high", "medium", "low"],
1382
+ supportedContextItemTypes: [
1383
+ "user_message",
1384
+ "system_message",
1385
+ "developer_message",
1386
+ "reasoning",
1387
+ "function_call",
1388
+ "function_call_output",
1389
+ "model_message"
1390
+ ],
1391
+ supportsStreaming: true,
1392
+ contextWindowSize: 2e5,
1393
+ maxOutputTokens: 32e3,
1394
+ supportsFunctionCalling: true,
1395
+ supportsStructuredOutput: true
1396
+ };
1397
+
1398
+ // src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
1399
+ var claudeOpus47Specification = {
1400
+ name: "claude-opus-4-7",
1401
+ provider: "anthropic",
1402
+ supportsReasoningEffort: true,
1403
+ supportedReasoningEfforts: ["max", "xhigh", "high", "medium", "low"],
1404
+ supportedContextItemTypes: [
1405
+ "user_message",
1406
+ "system_message",
1407
+ "developer_message",
1408
+ "reasoning",
1409
+ "function_call",
1410
+ "function_call_output",
1411
+ "model_message"
1412
+ ],
1413
+ supportsStreaming: true,
1414
+ contextWindowSize: 2e5,
1415
+ maxOutputTokens: 32e3,
1416
+ supportsFunctionCalling: true,
1417
+ supportsStructuredOutput: true
1418
+ };
1419
+
1420
+ // src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts
1421
+ var gemini35FlashSpecification = {
1422
+ name: "gemini-3.5-flash",
1423
+ provider: "google",
1424
+ supportsReasoningEffort: true,
1425
+ supportedReasoningEfforts: ["high", "medium", "low", "minimal", "none"],
1426
+ supportedContextItemTypes: [
1427
+ "user_message",
1428
+ "system_message",
1429
+ "developer_message",
1430
+ "reasoning",
1431
+ "function_call",
1432
+ "function_call_output",
1433
+ "model_message"
1434
+ ],
1435
+ supportsStreaming: true,
1436
+ contextWindowSize: 1048576,
1437
+ maxOutputTokens: 64e3,
1438
+ supportsFunctionCalling: true,
1439
+ supportsStructuredOutput: true
1440
+ };
1441
+
1442
+ // src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
1443
+ var gemini31ProSpecification = {
1444
+ name: "gemini-3.1-pro-preview",
1445
+ provider: "google",
1446
+ supportsReasoningEffort: true,
1447
+ supportedReasoningEfforts: ["high", "medium", "low", "minimal", "none"],
1448
+ supportedContextItemTypes: [
1449
+ "user_message",
1450
+ "system_message",
1451
+ "developer_message",
1452
+ "reasoning",
1453
+ "function_call",
1454
+ "function_call_output",
1455
+ "model_message"
1456
+ ],
1457
+ supportsStreaming: true,
1458
+ contextWindowSize: 1048576,
1459
+ maxOutputTokens: 64e3,
1460
+ supportsFunctionCalling: true,
1461
+ supportsStructuredOutput: true
1462
+ };
1463
+
1464
+ // src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts
1465
+ var deepSeekV4FlashSpecification = {
1466
+ name: "deepseek-v4-flash",
1467
+ provider: "deepseek",
1468
+ supportsReasoningEffort: true,
1469
+ supportedReasoningEfforts: ["max", "high", "medium", "low", "none"],
1470
+ supportedContextItemTypes: [
1471
+ "user_message",
1472
+ "system_message",
1473
+ "developer_message",
1474
+ "reasoning",
1475
+ "function_call",
1476
+ "function_call_output",
1477
+ "model_message"
1478
+ ],
1479
+ supportsStreaming: true,
1480
+ contextWindowSize: 1e6,
1481
+ maxOutputTokens: 384e3,
1482
+ supportsFunctionCalling: true,
1483
+ supportsStructuredOutput: false
1484
+ };
1485
+
1486
+ // src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
1487
+ var deepSeekV4ProSpecification = {
1488
+ name: "deepseek-v4-pro",
1489
+ provider: "deepseek",
1490
+ supportsReasoningEffort: true,
1491
+ supportedReasoningEfforts: ["max", "high", "medium", "low", "none"],
1492
+ supportedContextItemTypes: [
1493
+ "user_message",
1494
+ "system_message",
1495
+ "developer_message",
1496
+ "reasoning",
1497
+ "function_call",
1498
+ "function_call_output",
1499
+ "model_message"
1500
+ ],
1501
+ supportsStreaming: true,
1502
+ contextWindowSize: 1e6,
1503
+ maxOutputTokens: 384e3,
1504
+ supportsFunctionCalling: true,
1505
+ supportsStructuredOutput: false
1506
+ };
1507
+
1508
+ // src/infrastructure/providers/openai/models/gpt-5-4.ts
1509
+ var gpt54Specification = {
1510
+ name: "gpt-5.4",
1511
+ provider: "openai",
1512
+ supportsReasoningEffort: true,
1513
+ supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
1514
+ supportedContextItemTypes: [
1515
+ "user_message",
1516
+ "system_message",
1517
+ "developer_message",
1518
+ "reasoning",
1519
+ "function_call",
1520
+ "function_call_output",
1521
+ "model_message"
1522
+ ],
1523
+ supportsStreaming: true,
1524
+ contextWindowSize: 105e4,
1525
+ maxOutputTokens: 128e3,
1526
+ supportsFunctionCalling: true,
1527
+ supportsStructuredOutput: true
1528
+ };
1529
+
1530
+ // src/infrastructure/providers/openai/models/gpt-5-4-mini.ts
1531
+ var gpt54MiniSpecification = {
1532
+ name: "gpt-5.4-mini",
1533
+ provider: "openai",
1534
+ supportsReasoningEffort: true,
1535
+ supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
1536
+ supportedContextItemTypes: [
1537
+ "user_message",
1538
+ "system_message",
1539
+ "developer_message",
1540
+ "reasoning",
1541
+ "function_call",
1542
+ "function_call_output",
1543
+ "model_message"
1544
+ ],
1545
+ supportsStreaming: true,
1546
+ contextWindowSize: 4e5,
1547
+ maxOutputTokens: 128e3,
1548
+ supportsFunctionCalling: true,
1549
+ supportsStructuredOutput: true
1550
+ };
1551
+
1552
+ // src/infrastructure/providers/openai/models/gpt-5-4-nano.ts
1553
+ var gpt54NanoSpecification = {
1554
+ name: "gpt-5.4-nano",
1555
+ provider: "openai",
1556
+ supportsReasoningEffort: true,
1557
+ supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
1558
+ supportedContextItemTypes: [
1559
+ "user_message",
1560
+ "system_message",
1561
+ "developer_message",
1562
+ "reasoning",
1563
+ "function_call",
1564
+ "function_call_output",
1565
+ "model_message"
1566
+ ],
1567
+ supportsStreaming: true,
1568
+ contextWindowSize: 4e5,
1569
+ maxOutputTokens: 128e3,
1570
+ supportsFunctionCalling: true,
1571
+ supportsStructuredOutput: true
1572
+ };
1573
+
1574
+ // src/infrastructure/providers/openai/models/gpt-5-5.ts
1575
+ var gpt55Specification = {
1576
+ name: "gpt-5.5",
1577
+ provider: "openai",
1578
+ supportsReasoningEffort: true,
1579
+ supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
1580
+ supportedContextItemTypes: [
1581
+ "user_message",
1582
+ "system_message",
1583
+ "developer_message",
1584
+ "reasoning",
1585
+ "function_call",
1586
+ "function_call_output",
1587
+ "model_message"
1588
+ ],
1589
+ supportsStreaming: true,
1590
+ contextWindowSize: 105e4,
1591
+ maxOutputTokens: 128e3,
1592
+ supportsFunctionCalling: true,
1593
+ supportsStructuredOutput: true
1594
+ };
1595
+
1596
+ // src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
1597
+ var claudeHaiku45Specification = {
1598
+ name: "claude-haiku-4-5",
1599
+ provider: "anthropic",
1600
+ supportsReasoningEffort: true,
1601
+ supportedReasoningEfforts: ["high", "medium", "low", "none"],
1602
+ supportedContextItemTypes: [
1603
+ "user_message",
1604
+ "system_message",
1605
+ "developer_message",
1606
+ "reasoning",
1607
+ "function_call",
1608
+ "function_call_output",
1609
+ "model_message"
1610
+ ],
1611
+ supportsStreaming: true,
1612
+ contextWindowSize: 2e5,
1613
+ maxOutputTokens: 64e3,
1614
+ supportsFunctionCalling: true,
1615
+ supportsStructuredOutput: true
1616
+ };
1617
+
1618
+ // src/infrastructure/repository/generative-model-repository.ts
1619
+ var InMemoryGenerativeModelRepository = class {
1620
+ getByModelName(modelName) {
1621
+ let generativeModel = void 0;
1622
+ switch (modelName) {
1623
+ case "gpt-5.4":
1624
+ generativeModel = {
1625
+ endpoint: new OpenAIResponses(),
1626
+ specification: gpt54Specification
1627
+ };
1628
+ break;
1629
+ case "gpt-5.4-mini":
1630
+ generativeModel = {
1631
+ endpoint: new OpenAIResponses(),
1632
+ specification: gpt54MiniSpecification
1633
+ };
1634
+ break;
1635
+ case "gpt-5.4-nano":
1636
+ generativeModel = {
1637
+ endpoint: new OpenAIResponses(),
1638
+ specification: gpt54NanoSpecification
1639
+ };
1640
+ break;
1641
+ case "gpt-5.5":
1642
+ generativeModel = {
1643
+ endpoint: new OpenAIResponses(),
1644
+ specification: gpt55Specification
1645
+ };
1646
+ break;
1647
+ case "claude-haiku-4-5":
1648
+ generativeModel = {
1649
+ endpoint: new AnthropicMessages(),
1650
+ specification: claudeHaiku45Specification
1651
+ };
1652
+ break;
1653
+ case "claude-sonnet-4-6":
1654
+ generativeModel = {
1655
+ endpoint: new AnthropicMessages(),
1656
+ specification: claudeSonnet46Specification
1657
+ };
1658
+ break;
1659
+ case "claude-opus-4-7":
1660
+ generativeModel = {
1661
+ endpoint: new AnthropicMessages(),
1662
+ specification: claudeOpus47Specification
1663
+ };
1664
+ break;
1665
+ case "claude-opus-4-8":
1666
+ generativeModel = {
1667
+ endpoint: new AnthropicMessages(),
1668
+ specification: claudeOpus48Specification
1669
+ };
1670
+ break;
1671
+ case "gemini-3.5-flash":
1672
+ generativeModel = {
1673
+ endpoint: new GeminiGenerateContent(),
1674
+ specification: gemini35FlashSpecification
1675
+ };
1676
+ break;
1677
+ case "gemini-3.1-pro-preview":
1678
+ generativeModel = {
1679
+ endpoint: new GeminiGenerateContent(),
1680
+ specification: gemini31ProSpecification
1681
+ };
1682
+ break;
1683
+ case "deepseek-v4-flash":
1684
+ generativeModel = {
1685
+ endpoint: new OpenAIChatCompletions(),
1686
+ specification: deepSeekV4FlashSpecification
1687
+ };
1688
+ break;
1689
+ case "deepseek-v4-pro":
1690
+ generativeModel = {
1691
+ endpoint: new OpenAIChatCompletions(),
1692
+ specification: deepSeekV4ProSpecification
1693
+ };
1694
+ }
1695
+ if (!generativeModel) {
1696
+ throw new Error(`Unsupported model: ${modelName}`);
1697
+ }
1698
+ return Promise.resolve(generativeModel);
1734
1699
  }
1735
- setTools(tools) {
1736
- this.tools = tools;
1700
+ };
1701
+
1702
+ // src/domain/generative-model/request-validation/reasoning-effort.ts
1703
+ var ReasoningEffortValidation = class {
1704
+ constructor() {
1705
+ this.name = "reasoning-effort";
1737
1706
  }
1738
- getTools() {
1739
- return this.tools;
1707
+ isValid(inferenceParams, model) {
1708
+ if (inferenceParams.reasoningEffort === void 0) {
1709
+ return true;
1710
+ }
1711
+ if (!model.supportsReasoningEffort) {
1712
+ return false;
1713
+ }
1714
+ return model.supportedReasoningEfforts.includes(inferenceParams.reasoningEffort);
1740
1715
  }
1741
- setReasoningEffort(effort) {
1742
- this.effort.setReasoningEffort(effort);
1716
+ };
1717
+
1718
+ // src/domain/generative-model/request-validation/tool-calling.ts
1719
+ var ToolCallingValidation = class {
1720
+ constructor() {
1721
+ this.name = "tool-calling";
1743
1722
  }
1744
- getReasoningEffort() {
1745
- return this.effort.getReasoningEffort();
1723
+ isValid(inferenceParams, model) {
1724
+ if (inferenceParams.tools === void 0) {
1725
+ return true;
1726
+ }
1727
+ return model.supportsFunctionCalling;
1746
1728
  }
1747
1729
  };
1748
1730
 
1749
- // src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
1750
- var Gemini31Pro = class {
1731
+ // src/domain/generative-model/request-validation/streaming.ts
1732
+ var StreamingValidation = class {
1751
1733
  constructor() {
1752
- this.specification = {
1753
- name: "gemini-3.1-pro-preview",
1754
- supportReasoningEffort: true,
1755
- defaultReasoningEffort: "high",
1756
- supportStreaming: true,
1757
- contextWindowSize: 1048576,
1758
- maxOutputTokens: 64e3,
1759
- supportFunctionCalling: true
1760
- };
1761
- this.tools = [];
1762
- this.streaming = false;
1763
- this.effort = new GeminiReasoningEffort(
1764
- this.specification.defaultReasoningEffort
1765
- );
1734
+ this.name = "streaming";
1766
1735
  }
1767
- setStreaming(streaming) {
1768
- this.streaming = streaming;
1736
+ isValid(inferenceParams, model) {
1737
+ if (!inferenceParams.streaming) {
1738
+ return true;
1739
+ }
1740
+ return model.supportsStreaming;
1741
+ }
1742
+ };
1743
+
1744
+ // src/domain/generative-model/request-validation/context.ts
1745
+ function getContextItemValidationKey(item) {
1746
+ if (item instanceof UserMessageItem) {
1747
+ return "user_message";
1769
1748
  }
1770
- getStreaming() {
1771
- return this.streaming;
1749
+ if (item instanceof SystemMessageItem) {
1750
+ return "system_message";
1772
1751
  }
1773
- setTools(tools) {
1774
- this.tools = tools;
1752
+ if (item instanceof DeveloperMessageItem) {
1753
+ return "developer_message";
1775
1754
  }
1776
- getTools() {
1777
- return this.tools;
1755
+ if (item instanceof ModelMessageItem) {
1756
+ return "model_message";
1778
1757
  }
1779
- setReasoningEffort(effort) {
1780
- this.effort.setReasoningEffort(effort);
1758
+ return item.getType();
1759
+ }
1760
+ var ContextValidation = class {
1761
+ constructor() {
1762
+ this.name = "context";
1763
+ }
1764
+ isValid(inferenceParams, model) {
1765
+ return inferenceParams.context.items.every(
1766
+ (item) => model.supportedContextItemTypes.includes(getContextItemValidationKey(item))
1767
+ );
1781
1768
  }
1782
- getReasoningEffort() {
1783
- return this.effort.getReasoningEffort();
1769
+ };
1770
+
1771
+ // src/domain/generative-model/request-validation/inference-request-validator.ts
1772
+ var defaultRequestValidationRules = [
1773
+ new ReasoningEffortValidation(),
1774
+ new ToolCallingValidation(),
1775
+ new StreamingValidation(),
1776
+ new StructuredOutputValidation(),
1777
+ new ContextValidation()
1778
+ ];
1779
+ var InferenceRequestValidator = class {
1780
+ constructor(rules = defaultRequestValidationRules) {
1781
+ this.rules = rules;
1782
+ }
1783
+ validate(inferenceParams, model) {
1784
+ for (const rule of this.rules) {
1785
+ if (!rule.isValid(inferenceParams, model)) {
1786
+ throw new Error(`Request validation "${rule.name}" failed for model "${model.name}"`);
1787
+ }
1788
+ }
1784
1789
  }
1785
1790
  };
1791
+
1792
+ // src/index.ts
1793
+ var generativeModelRepository = new InMemoryGenerativeModelRepository();
1794
+ var inferenceRequestValidator = new InferenceRequestValidator();
1795
+ var runInferenceUseCase = new RunInference(generativeModelRepository, inferenceRequestValidator);
1796
+ var executeFunctionCallUseCase = new ExecuteFunctionCall(new FunctionCallRunner());
1797
+ var sendMessageUseCase = new SendMessage();
1798
+ var runInference = (inferenceParams) => {
1799
+ runInferenceUseCase.execute(inferenceParams);
1800
+ };
1801
+ var executeFunctionCall = (environment, functionCallItem, tool, caller) => {
1802
+ executeFunctionCallUseCase.execute(environment, functionCallItem, tool, caller);
1803
+ };
1804
+ var sendMessage = (environment, message, caller) => {
1805
+ sendMessageUseCase.execute(environment, message, caller);
1806
+ };
1786
1807
  // Annotate the CommonJS export names for ESM import in node:
1787
1808
  0 && (module.exports = {
1788
- Agent,
1789
1809
  AgenticEnvironment,
1790
- AnthropicMessages,
1791
- BaseAgent,
1792
- BaseHuman,
1793
- BaseObserver,
1794
- ClaudeHaiku45,
1795
- ClaudeOpus47,
1796
- ClaudeOpus48,
1797
- ClaudeSonnet46,
1810
+ AgenticError,
1811
+ BaseParticipant,
1798
1812
  ContextItem,
1799
- DeepSeekV4Flash,
1800
- DeepSeekV4Pro,
1801
- DefaultFunctionCallRunner,
1802
- DefaultInferenceRunner,
1803
1813
  DeveloperMessageItem,
1804
1814
  FunctionCallItem,
1805
1815
  FunctionCallOutputItem,
1806
- Gemini31Pro,
1807
- Gemini35Flash,
1808
- GeminiGenerateContent,
1809
- Gpt54,
1810
- Gpt54Mini,
1811
- Gpt54Nano,
1812
- Gpt55,
1813
- Human,
1814
1816
  InMemoryModelContextRepository,
1815
- InferenceRequest,
1816
1817
  InferenceResponse,
1817
1818
  InputTokenDetails,
1818
1819
  ModelContext,
1819
1820
  ModelMessageItem,
1820
- Observer,
1821
- OpenAICompatibleChatCompletions,
1822
- OpenAIResponses,
1823
1821
  OutputTokenDetails,
1824
1822
  Participant,
1825
1823
  ReasoningItem,
1826
1824
  SemanticEvent,
1827
1825
  SystemMessageItem,
1828
1826
  TokenUsage,
1829
- UserMessageItem
1827
+ UserMessageItem,
1828
+ executeFunctionCall,
1829
+ runInference,
1830
+ sendMessage
1830
1831
  });
1831
1832
  //# sourceMappingURL=index.js.map