@mozaik-ai/core 3.9.5 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +75 -72
- package/dist/index.d.ts +75 -72
- package/dist/index.js +202 -156
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +196 -150
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -234,110 +234,6 @@ var FunctionCallOutputItem = class _FunctionCallOutputItem extends ContextItem {
|
|
|
234
234
|
}
|
|
235
235
|
};
|
|
236
236
|
|
|
237
|
-
// src/domain/generative-model/inference-response.ts
|
|
238
|
-
var InferenceResponse = class {
|
|
239
|
-
constructor(contextItems, tokenUsage) {
|
|
240
|
-
this.contextItems = contextItems;
|
|
241
|
-
this.tokenUsage = tokenUsage;
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
// src/domain/generative-model/token-usage.ts
|
|
246
|
-
var InputTokenDetails = class {
|
|
247
|
-
constructor(cached_tokens) {
|
|
248
|
-
this.cached_tokens = cached_tokens;
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
var OutputTokenDetails = class {
|
|
252
|
-
constructor(reasoning_tokens) {
|
|
253
|
-
this.reasoning_tokens = reasoning_tokens;
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
var TokenUsage = class {
|
|
257
|
-
constructor(inputTokens, outputTokens, totalTokens, inputTokenDetails, outputTokenDetails) {
|
|
258
|
-
this.inputTokens = inputTokens;
|
|
259
|
-
this.outputTokens = outputTokens;
|
|
260
|
-
this.totalTokens = totalTokens;
|
|
261
|
-
this.inputTokenDetails = inputTokenDetails;
|
|
262
|
-
this.outputTokenDetails = outputTokenDetails;
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
// src/infrastructure/providers/openai/runtime/openai-responses.ts
|
|
267
|
-
import OpenAI from "openai";
|
|
268
|
-
var OpenAIResponses = class {
|
|
269
|
-
constructor() {
|
|
270
|
-
this.client = new OpenAI();
|
|
271
|
-
}
|
|
272
|
-
async infer(inferenceRequest) {
|
|
273
|
-
const input = this.mapContextToRequest(inferenceRequest.context);
|
|
274
|
-
const specification = inferenceRequest.model.specification;
|
|
275
|
-
let request = {
|
|
276
|
-
model: specification.name,
|
|
277
|
-
input
|
|
278
|
-
};
|
|
279
|
-
if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
|
|
280
|
-
request.tools = inferenceRequest.model.getTools().map((tool) => {
|
|
281
|
-
return {
|
|
282
|
-
type: tool.type,
|
|
283
|
-
name: tool.name,
|
|
284
|
-
description: tool.description,
|
|
285
|
-
parameters: tool.parameters
|
|
286
|
-
};
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
if (specification.supportReasoningEffort) {
|
|
290
|
-
request.reasoning = {
|
|
291
|
-
effort: inferenceRequest.model.getReasoningEffort()
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
const response = await this.client.responses.create(request);
|
|
295
|
-
const contextItems = this.extractContextItems(response);
|
|
296
|
-
const tokenUsage = this.extractTokenUsage(response);
|
|
297
|
-
return new InferenceResponse(contextItems, tokenUsage);
|
|
298
|
-
}
|
|
299
|
-
extractTokenUsage(response) {
|
|
300
|
-
if (!response.usage) {
|
|
301
|
-
return void 0;
|
|
302
|
-
}
|
|
303
|
-
return new TokenUsage(
|
|
304
|
-
response.usage.input_tokens,
|
|
305
|
-
response.usage.output_tokens,
|
|
306
|
-
response.usage.total_tokens,
|
|
307
|
-
new InputTokenDetails(response.usage.input_tokens_details.cached_tokens),
|
|
308
|
-
new OutputTokenDetails(response.usage.output_tokens_details.reasoning_tokens)
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
mapContextToRequest(context) {
|
|
312
|
-
return context.getItems().map((item) => item.toJSON());
|
|
313
|
-
}
|
|
314
|
-
extractContextItems(response) {
|
|
315
|
-
return response.output.map((item) => {
|
|
316
|
-
if (item.type === "message" && item.role === "assistant") {
|
|
317
|
-
return ModelMessageItem.rehydrate(item.content[0]);
|
|
318
|
-
}
|
|
319
|
-
if (item.type === "function_call") {
|
|
320
|
-
return FunctionCallItem.rehydrate({
|
|
321
|
-
callId: item.call_id,
|
|
322
|
-
name: item.name,
|
|
323
|
-
args: item.arguments
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
if (item.type === "reasoning") {
|
|
327
|
-
return ReasoningItem.rehydrate(item);
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
// src/domain/generative-model/inference-request.ts
|
|
334
|
-
var InferenceRequest = class {
|
|
335
|
-
constructor(model, context) {
|
|
336
|
-
this.model = model;
|
|
337
|
-
this.context = context;
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
|
|
341
237
|
// src/infrastructure/providers/openai/reasoning-effort.ts
|
|
342
238
|
var OpenAIReasoningEffort = class {
|
|
343
239
|
constructor(reasoningEffort) {
|
|
@@ -370,6 +266,13 @@ var Gpt54Nano = class {
|
|
|
370
266
|
this.effort = new OpenAIReasoningEffort(
|
|
371
267
|
this.specification.defaultReasoningEffort
|
|
372
268
|
);
|
|
269
|
+
this.streaming = false;
|
|
270
|
+
}
|
|
271
|
+
setStreaming(streaming) {
|
|
272
|
+
this.streaming = streaming;
|
|
273
|
+
}
|
|
274
|
+
getStreaming() {
|
|
275
|
+
return this.streaming;
|
|
373
276
|
}
|
|
374
277
|
setTools(tools) {
|
|
375
278
|
this.tools = tools;
|
|
@@ -398,10 +301,17 @@ var Gpt54 = class {
|
|
|
398
301
|
supportFunctionCalling: true
|
|
399
302
|
};
|
|
400
303
|
this.tools = [];
|
|
304
|
+
this.streaming = false;
|
|
401
305
|
this.effort = new OpenAIReasoningEffort(
|
|
402
306
|
this.specification.defaultReasoningEffort
|
|
403
307
|
);
|
|
404
308
|
}
|
|
309
|
+
setStreaming(streaming) {
|
|
310
|
+
this.streaming = streaming;
|
|
311
|
+
}
|
|
312
|
+
getStreaming() {
|
|
313
|
+
return this.streaming;
|
|
314
|
+
}
|
|
405
315
|
setTools(tools) {
|
|
406
316
|
this.tools = tools;
|
|
407
317
|
}
|
|
@@ -432,6 +342,13 @@ var Gpt54Mini = class {
|
|
|
432
342
|
this.effort = new OpenAIReasoningEffort(
|
|
433
343
|
this.specification.defaultReasoningEffort
|
|
434
344
|
);
|
|
345
|
+
this.streaming = false;
|
|
346
|
+
}
|
|
347
|
+
setStreaming(streaming) {
|
|
348
|
+
this.streaming = streaming;
|
|
349
|
+
}
|
|
350
|
+
getStreaming() {
|
|
351
|
+
return this.streaming;
|
|
435
352
|
}
|
|
436
353
|
setReasoningEffort(effort) {
|
|
437
354
|
this.effort.setReasoningEffort(effort);
|
|
@@ -447,6 +364,27 @@ var Gpt54Mini = class {
|
|
|
447
364
|
}
|
|
448
365
|
};
|
|
449
366
|
|
|
367
|
+
// src/domain/generative-model/token-usage.ts
|
|
368
|
+
var InputTokenDetails = class {
|
|
369
|
+
constructor(cached_tokens) {
|
|
370
|
+
this.cached_tokens = cached_tokens;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
var OutputTokenDetails = class {
|
|
374
|
+
constructor(reasoning_tokens) {
|
|
375
|
+
this.reasoning_tokens = reasoning_tokens;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
var TokenUsage = class {
|
|
379
|
+
constructor(inputTokens, outputTokens, totalTokens, inputTokenDetails, outputTokenDetails) {
|
|
380
|
+
this.inputTokens = inputTokens;
|
|
381
|
+
this.outputTokens = outputTokens;
|
|
382
|
+
this.totalTokens = totalTokens;
|
|
383
|
+
this.inputTokenDetails = inputTokenDetails;
|
|
384
|
+
this.outputTokenDetails = outputTokenDetails;
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
|
|
450
388
|
// src/infrastructure/repository/in-memory-model-context-repository.ts
|
|
451
389
|
var InMemoryModelContextRepository = class {
|
|
452
390
|
constructor() {
|
|
@@ -514,7 +452,7 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
|
|
|
514
452
|
}
|
|
515
453
|
};
|
|
516
454
|
|
|
517
|
-
// src/domain/agentic-environment/participant.ts
|
|
455
|
+
// src/domain/agentic-environment/participants/participant.ts
|
|
518
456
|
var Participant = class {
|
|
519
457
|
constructor() {
|
|
520
458
|
this.environments = [];
|
|
@@ -609,6 +547,15 @@ var AgenticEnvironment = class {
|
|
|
609
547
|
subscriber.onMessage(message);
|
|
610
548
|
}
|
|
611
549
|
}
|
|
550
|
+
deliverSemanticEvent(source, item) {
|
|
551
|
+
for (const subscriber of this.subscribers) {
|
|
552
|
+
if (subscriber === source) {
|
|
553
|
+
subscriber.onInternalEvent(item);
|
|
554
|
+
} else {
|
|
555
|
+
subscriber.onExternalEvent(source, item);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
612
559
|
async start() {
|
|
613
560
|
this.isActive = true;
|
|
614
561
|
while (this.isActive) {
|
|
@@ -620,11 +567,25 @@ var AgenticEnvironment = class {
|
|
|
620
567
|
}
|
|
621
568
|
};
|
|
622
569
|
|
|
623
|
-
// src/
|
|
624
|
-
var
|
|
625
|
-
|
|
570
|
+
// src/domain/agentic-environment/participants/agent.ts
|
|
571
|
+
var Agent = class extends Participant {
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
// src/domain/model-context/semantic-event/semantic-event.ts
|
|
575
|
+
var SemanticEvent = class {
|
|
576
|
+
constructor(type, data) {
|
|
577
|
+
this.type = type;
|
|
578
|
+
this.data = data;
|
|
579
|
+
}
|
|
580
|
+
getType() {
|
|
581
|
+
return this.type;
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// src/application/participants/agent.ts
|
|
586
|
+
var BaseAgent = class extends Agent {
|
|
587
|
+
constructor(inferenceRunner, functionCallRunner) {
|
|
626
588
|
super();
|
|
627
|
-
this.inputSource = inputSource;
|
|
628
589
|
this.inferenceRunner = inferenceRunner;
|
|
629
590
|
this.functionCallRunner = functionCallRunner;
|
|
630
591
|
}
|
|
@@ -654,41 +615,44 @@ var BaseAgentParticipant = class extends Participant {
|
|
|
654
615
|
}
|
|
655
616
|
onMessage(message) {
|
|
656
617
|
}
|
|
618
|
+
onInternalEvent(item) {
|
|
619
|
+
}
|
|
620
|
+
onExternalEvent(source, item) {
|
|
621
|
+
}
|
|
657
622
|
async executeFunctionCall(environment, functionCallItem, signal) {
|
|
658
623
|
if (!this.isJoinedTo(environment)) return;
|
|
659
624
|
const stream = this.functionCallRunner.run(functionCallItem, signal);
|
|
660
625
|
for await (const item of stream) {
|
|
661
|
-
|
|
626
|
+
environment.deliverFunctionCallOutput(this, item);
|
|
662
627
|
}
|
|
663
628
|
}
|
|
664
629
|
async runInference(environment, context, model, signal) {
|
|
665
630
|
if (!this.isJoinedTo(environment)) return;
|
|
666
631
|
const stream = this.inferenceRunner.run(context, model, signal);
|
|
667
632
|
for await (const item of stream) {
|
|
668
|
-
if (item
|
|
669
|
-
|
|
670
|
-
} else if (item
|
|
671
|
-
|
|
672
|
-
} else if (item
|
|
673
|
-
|
|
633
|
+
if (item instanceof ReasoningItem) {
|
|
634
|
+
environment.deliverReasoning(this, item);
|
|
635
|
+
} else if (item instanceof FunctionCallItem) {
|
|
636
|
+
environment.deliverFunctionCall(this, item);
|
|
637
|
+
} else if (item instanceof ModelMessageItem) {
|
|
638
|
+
environment.deliverModelMessage(this, item);
|
|
639
|
+
} else if (item instanceof SemanticEvent) {
|
|
640
|
+
environment.deliverSemanticEvent(this, item);
|
|
674
641
|
}
|
|
675
642
|
}
|
|
676
643
|
}
|
|
677
|
-
async streamInput(environment) {
|
|
678
|
-
if (!this.isJoinedTo(environment)) return;
|
|
679
|
-
const stream = this.inputSource.stream();
|
|
680
|
-
for await (const message of stream) {
|
|
681
|
-
await environment.deliverMessage(this, message);
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
644
|
};
|
|
685
645
|
|
|
686
|
-
// src/
|
|
687
|
-
var
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
this
|
|
646
|
+
// src/domain/agentic-environment/participants/human.ts
|
|
647
|
+
var Human = class extends Participant {
|
|
648
|
+
sendMessage(environment, message) {
|
|
649
|
+
if (!this.isJoinedTo(environment)) throw new Error("Not joined to environment");
|
|
650
|
+
environment.deliverMessage(this, message);
|
|
691
651
|
}
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
// src/application/participants/human.ts
|
|
655
|
+
var BaseHuman = class extends Human {
|
|
692
656
|
onJoined() {
|
|
693
657
|
}
|
|
694
658
|
onLeft() {
|
|
@@ -715,29 +679,96 @@ var BaseHumanParticipant = class extends Participant {
|
|
|
715
679
|
}
|
|
716
680
|
onExternalModelMessage(source, item) {
|
|
717
681
|
}
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
for await (const message of stream) {
|
|
722
|
-
await environment.deliverMessage(this, message);
|
|
723
|
-
}
|
|
682
|
+
onInternalEvent(item) {
|
|
683
|
+
}
|
|
684
|
+
onExternalEvent(source, item) {
|
|
724
685
|
}
|
|
725
686
|
};
|
|
726
687
|
|
|
727
|
-
// src/application/openai-inference-runner.ts
|
|
688
|
+
// src/application/runners/openai-inference-runner.ts
|
|
689
|
+
import OpenAI from "openai";
|
|
728
690
|
var OpenAIInferenceRunner = class {
|
|
729
|
-
constructor() {
|
|
730
|
-
this.runtime = new OpenAIResponses();
|
|
731
|
-
}
|
|
732
691
|
async *run(context, model, signal) {
|
|
733
|
-
const
|
|
734
|
-
|
|
735
|
-
|
|
692
|
+
const input = this.mapContextToRequest(context);
|
|
693
|
+
const specification = model.specification;
|
|
694
|
+
let request = {
|
|
695
|
+
model: specification.name,
|
|
696
|
+
input,
|
|
697
|
+
stream: model.getStreaming()
|
|
698
|
+
};
|
|
699
|
+
if (specification.supportFunctionCalling && model.getTools().length > 0) {
|
|
700
|
+
request.tools = model.getTools().map((tool) => {
|
|
701
|
+
return {
|
|
702
|
+
type: tool.type,
|
|
703
|
+
name: tool.name,
|
|
704
|
+
description: tool.description,
|
|
705
|
+
parameters: tool.parameters
|
|
706
|
+
};
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
if (specification.supportReasoningEffort) {
|
|
710
|
+
request.reasoning = {
|
|
711
|
+
effort: model.getReasoningEffort()
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
if (!specification.supportStreaming && model.getStreaming()) {
|
|
715
|
+
throw new Error("Streaming is not supported for this model");
|
|
716
|
+
}
|
|
717
|
+
const openai = new OpenAI();
|
|
718
|
+
const response = await openai.responses.create(request);
|
|
719
|
+
if (specification.supportStreaming && model.getStreaming()) {
|
|
720
|
+
for await (const event of response) {
|
|
721
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
722
|
+
break;
|
|
723
|
+
}
|
|
724
|
+
yield new SemanticEvent(event.type, event);
|
|
725
|
+
}
|
|
726
|
+
} else {
|
|
727
|
+
const contextItems = this.extractContextItems(response);
|
|
728
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
729
|
+
for (const item of contextItems) {
|
|
730
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
731
|
+
break;
|
|
732
|
+
}
|
|
733
|
+
yield item;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
extractTokenUsage(response) {
|
|
738
|
+
if (!response.usage) {
|
|
739
|
+
return void 0;
|
|
736
740
|
}
|
|
741
|
+
return new TokenUsage(
|
|
742
|
+
response.usage.input_tokens,
|
|
743
|
+
response.usage.output_tokens,
|
|
744
|
+
response.usage.total_tokens,
|
|
745
|
+
new InputTokenDetails(response.usage.input_tokens_details.cached_tokens),
|
|
746
|
+
new OutputTokenDetails(response.usage.output_tokens_details.reasoning_tokens)
|
|
747
|
+
);
|
|
748
|
+
}
|
|
749
|
+
mapContextToRequest(context) {
|
|
750
|
+
return context.getItems().map((item) => item.toJSON());
|
|
751
|
+
}
|
|
752
|
+
extractContextItems(response) {
|
|
753
|
+
return response.output.map((item) => {
|
|
754
|
+
if (item.type === "message" && item.role === "assistant") {
|
|
755
|
+
return ModelMessageItem.rehydrate(item.content[0]);
|
|
756
|
+
}
|
|
757
|
+
if (item.type === "function_call") {
|
|
758
|
+
return FunctionCallItem.rehydrate({
|
|
759
|
+
callId: item.call_id,
|
|
760
|
+
name: item.name,
|
|
761
|
+
args: item.arguments
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
if (item.type === "reasoning") {
|
|
765
|
+
return ReasoningItem.rehydrate(item);
|
|
766
|
+
}
|
|
767
|
+
});
|
|
737
768
|
}
|
|
738
769
|
};
|
|
739
770
|
|
|
740
|
-
// src/application/function-call-runner.ts
|
|
771
|
+
// src/application/runners/function-call-runner.ts
|
|
741
772
|
var DefaultFunctionCallRunner = class {
|
|
742
773
|
constructor(tools) {
|
|
743
774
|
this.tools = tools;
|
|
@@ -763,10 +794,17 @@ var Gpt55 = class {
|
|
|
763
794
|
supportFunctionCalling: true
|
|
764
795
|
};
|
|
765
796
|
this.tools = [];
|
|
797
|
+
this.streaming = false;
|
|
766
798
|
this.effort = new OpenAIReasoningEffort(
|
|
767
799
|
this.specification.defaultReasoningEffort
|
|
768
800
|
);
|
|
769
801
|
}
|
|
802
|
+
setStreaming(streaming) {
|
|
803
|
+
this.streaming = streaming;
|
|
804
|
+
}
|
|
805
|
+
getStreaming() {
|
|
806
|
+
return this.streaming;
|
|
807
|
+
}
|
|
770
808
|
setTools(tools) {
|
|
771
809
|
this.tools = tools;
|
|
772
810
|
}
|
|
@@ -781,8 +819,12 @@ var Gpt55 = class {
|
|
|
781
819
|
}
|
|
782
820
|
};
|
|
783
821
|
|
|
784
|
-
// src/
|
|
785
|
-
var
|
|
822
|
+
// src/domain/agentic-environment/participants/observer.ts
|
|
823
|
+
var Observer = class extends Participant {
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
// src/application/participants/observer.ts
|
|
827
|
+
var BaseObserver = class extends Observer {
|
|
786
828
|
onFunctionCall(item) {
|
|
787
829
|
}
|
|
788
830
|
onExternalFunctionCall(source, item) {
|
|
@@ -809,12 +851,17 @@ var BaseObserverParticipant = class extends Participant {
|
|
|
809
851
|
}
|
|
810
852
|
onParticipantLeft(participant) {
|
|
811
853
|
}
|
|
854
|
+
onInternalEvent(item) {
|
|
855
|
+
}
|
|
856
|
+
onExternalEvent(source, item) {
|
|
857
|
+
}
|
|
812
858
|
};
|
|
813
859
|
export {
|
|
860
|
+
Agent,
|
|
814
861
|
AgenticEnvironment,
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
862
|
+
BaseAgent,
|
|
863
|
+
BaseHuman,
|
|
864
|
+
BaseObserver,
|
|
818
865
|
ContextItem,
|
|
819
866
|
DefaultFunctionCallRunner,
|
|
820
867
|
DeveloperMessageItem,
|
|
@@ -824,14 +871,13 @@ export {
|
|
|
824
871
|
Gpt54Mini,
|
|
825
872
|
Gpt54Nano,
|
|
826
873
|
Gpt55,
|
|
874
|
+
Human,
|
|
827
875
|
InMemoryModelContextRepository,
|
|
828
|
-
InferenceRequest,
|
|
829
|
-
InferenceResponse,
|
|
830
876
|
InputTokenDetails,
|
|
831
877
|
ModelContext,
|
|
832
878
|
ModelMessageItem,
|
|
879
|
+
Observer,
|
|
833
880
|
OpenAIInferenceRunner,
|
|
834
|
-
OpenAIResponses,
|
|
835
881
|
OutputTokenDetails,
|
|
836
882
|
Participant,
|
|
837
883
|
ReasoningItem,
|