@agentica/core 0.16.3 → 0.16.6

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/lib/index.mjs CHANGED
@@ -4,10 +4,10 @@ import { v4 } from "uuid";
4
4
 
5
5
  import { HttpLlm, ChatGptTypeChecker, LlmTypeCheckerV3_1, OpenApi } from "@samchon/openapi";
6
6
 
7
- import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
8
-
9
7
  import * as __typia_transform__validateReport from "typia/lib/internal/_validateReport.js";
10
8
 
9
+ import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
10
+
11
11
  import * as __typia_transform__accessExpressionAsString from "typia/lib/internal/_accessExpressionAsString.js";
12
12
 
13
13
  class AgenticaTokenUsage {
@@ -614,7 +614,8 @@ const ChatGptTokenUsageAggregator = {
614
614
 
615
615
  function transformCompletionChunk(source) {
616
616
  const str = source instanceof Uint8Array ? ByteArrayUtil.toUtf8(source) : source;
617
- return (() => {
617
+ const result = JSON.parse(str);
618
+ const valid = (() => {
618
619
  const _io0 = input => "string" === typeof input.id && (Array.isArray(input.choices) && input.choices.every((elem => "object" === typeof elem && null !== elem && _io1(elem)))) && "number" === typeof input.created && "string" === typeof input.model && "chat.completion.chunk" === input.object && (null === input.service_tier || undefined === input.service_tier || "scale" === input.service_tier || "default" === input.service_tier) && (undefined === input.system_fingerprint || "string" === typeof input.system_fingerprint) && (null === input.usage || undefined === input.usage || "object" === typeof input.usage && null !== input.usage && _io9(input.usage));
619
620
  const _io1 = input => "object" === typeof input.delta && null !== input.delta && false === Array.isArray(input.delta) && _io2(input.delta) && (null === input.finish_reason || "function_call" === input.finish_reason || "stop" === input.finish_reason || "length" === input.finish_reason || "tool_calls" === input.finish_reason || "content_filter" === input.finish_reason) && "number" === typeof input.index && (null === input.logprobs || undefined === input.logprobs || "object" === typeof input.logprobs && null !== input.logprobs && _io6(input.logprobs));
620
621
  const _io2 = input => (null === input.content || undefined === input.content || "string" === typeof input.content) && (undefined === input.function_call || "object" === typeof input.function_call && null !== input.function_call && false === Array.isArray(input.function_call) && _io3(input.function_call)) && (null === input.refusal || undefined === input.refusal || "string" === typeof input.refusal) && (undefined === input.role || "assistant" === input.role || "user" === input.role || "developer" === input.role || "system" === input.role || "tool" === input.role) && (undefined === input.tool_calls || Array.isArray(input.tool_calls) && input.tool_calls.every((elem => "object" === typeof elem && null !== elem && _io4(elem))));
@@ -627,394 +628,338 @@ function transformCompletionChunk(source) {
627
628
  const _io9 = input => "number" === typeof input.completion_tokens && "number" === typeof input.prompt_tokens && "number" === typeof input.total_tokens && (undefined === input.completion_tokens_details || "object" === typeof input.completion_tokens_details && null !== input.completion_tokens_details && false === Array.isArray(input.completion_tokens_details) && _io10(input.completion_tokens_details)) && (undefined === input.prompt_tokens_details || "object" === typeof input.prompt_tokens_details && null !== input.prompt_tokens_details && false === Array.isArray(input.prompt_tokens_details) && _io11(input.prompt_tokens_details));
628
629
  const _io10 = input => (undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens) && (undefined === input.audio_tokens || "number" === typeof input.audio_tokens) && (undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens) && (undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens);
629
630
  const _io11 = input => (undefined === input.audio_tokens || "number" === typeof input.audio_tokens) && (undefined === input.cached_tokens || "number" === typeof input.cached_tokens);
630
- const _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
631
- method: "json.assertParse",
631
+ const _vo0 = (input, _path, _exceptionable = true) => [ "string" === typeof input.id || _report(_exceptionable, {
632
632
  path: _path + ".id",
633
633
  expected: "string",
634
634
  value: input.id
635
- }, _errorFactory)) && ((Array.isArray(input.choices) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
636
- method: "json.assertParse",
635
+ }), (Array.isArray(input.choices) || _report(_exceptionable, {
637
636
  path: _path + ".choices",
638
637
  expected: "Array<ChatCompletionChunk.Choice>",
639
638
  value: input.choices
640
- }, _errorFactory)) && input.choices.every(((elem, _index8) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
641
- method: "json.assertParse",
639
+ })) && input.choices.map(((elem, _index8) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
642
640
  path: _path + ".choices[" + _index8 + "]",
643
641
  expected: "ChatCompletionChunk.Choice",
644
642
  value: elem
645
- }, _errorFactory)) && _ao1(elem, _path + ".choices[" + _index8 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
646
- method: "json.assertParse",
643
+ })) && _vo1(elem, _path + ".choices[" + _index8 + "]", _exceptionable) || _report(_exceptionable, {
647
644
  path: _path + ".choices[" + _index8 + "]",
648
645
  expected: "ChatCompletionChunk.Choice",
649
646
  value: elem
650
- }, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
651
- method: "json.assertParse",
647
+ }))).every((flag => flag)) || _report(_exceptionable, {
652
648
  path: _path + ".choices",
653
649
  expected: "Array<ChatCompletionChunk.Choice>",
654
650
  value: input.choices
655
- }, _errorFactory)) && ("number" === typeof input.created || __typia_transform__assertGuard._assertGuard(_exceptionable, {
656
- method: "json.assertParse",
651
+ }), "number" === typeof input.created || _report(_exceptionable, {
657
652
  path: _path + ".created",
658
653
  expected: "number",
659
654
  value: input.created
660
- }, _errorFactory)) && ("string" === typeof input.model || __typia_transform__assertGuard._assertGuard(_exceptionable, {
661
- method: "json.assertParse",
655
+ }), "string" === typeof input.model || _report(_exceptionable, {
662
656
  path: _path + ".model",
663
657
  expected: "string",
664
658
  value: input.model
665
- }, _errorFactory)) && ("chat.completion.chunk" === input.object || __typia_transform__assertGuard._assertGuard(_exceptionable, {
666
- method: "json.assertParse",
659
+ }), "chat.completion.chunk" === input.object || _report(_exceptionable, {
667
660
  path: _path + ".object",
668
661
  expected: '"chat.completion.chunk"',
669
662
  value: input.object
670
- }, _errorFactory)) && (null === input.service_tier || undefined === input.service_tier || "scale" === input.service_tier || "default" === input.service_tier || __typia_transform__assertGuard._assertGuard(_exceptionable, {
671
- method: "json.assertParse",
663
+ }), null === input.service_tier || undefined === input.service_tier || "scale" === input.service_tier || "default" === input.service_tier || _report(_exceptionable, {
672
664
  path: _path + ".service_tier",
673
665
  expected: '("default" | "scale" | null | undefined)',
674
666
  value: input.service_tier
675
- }, _errorFactory)) && (undefined === input.system_fingerprint || "string" === typeof input.system_fingerprint || __typia_transform__assertGuard._assertGuard(_exceptionable, {
676
- method: "json.assertParse",
667
+ }), undefined === input.system_fingerprint || "string" === typeof input.system_fingerprint || _report(_exceptionable, {
677
668
  path: _path + ".system_fingerprint",
678
669
  expected: "(string | undefined)",
679
670
  value: input.system_fingerprint
680
- }, _errorFactory)) && (null === input.usage || undefined === input.usage || ("object" === typeof input.usage && null !== input.usage || __typia_transform__assertGuard._assertGuard(_exceptionable, {
681
- method: "json.assertParse",
671
+ }), null === input.usage || undefined === input.usage || ("object" === typeof input.usage && null !== input.usage || _report(_exceptionable, {
682
672
  path: _path + ".usage",
683
673
  expected: "(CompletionUsage | null | undefined)",
684
674
  value: input.usage
685
- }, _errorFactory)) && _ao9(input.usage, _path + ".usage", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
686
- method: "json.assertParse",
675
+ })) && _vo9(input.usage, _path + ".usage", _exceptionable) || _report(_exceptionable, {
687
676
  path: _path + ".usage",
688
677
  expected: "(CompletionUsage | null | undefined)",
689
678
  value: input.usage
690
- }, _errorFactory));
691
- const _ao1 = (input, _path, _exceptionable = true) => (("object" === typeof input.delta && null !== input.delta && false === Array.isArray(input.delta) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
692
- method: "json.assertParse",
679
+ }) ].every((flag => flag));
680
+ const _vo1 = (input, _path, _exceptionable = true) => [ ("object" === typeof input.delta && null !== input.delta && false === Array.isArray(input.delta) || _report(_exceptionable, {
693
681
  path: _path + ".delta",
694
682
  expected: "ChatCompletionChunk.Choice.Delta",
695
683
  value: input.delta
696
- }, _errorFactory)) && _ao2(input.delta, _path + ".delta", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
697
- method: "json.assertParse",
684
+ })) && _vo2(input.delta, _path + ".delta", _exceptionable) || _report(_exceptionable, {
698
685
  path: _path + ".delta",
699
686
  expected: "ChatCompletionChunk.Choice.Delta",
700
687
  value: input.delta
701
- }, _errorFactory)) && (null === input.finish_reason || "function_call" === input.finish_reason || "stop" === input.finish_reason || "length" === input.finish_reason || "tool_calls" === input.finish_reason || "content_filter" === input.finish_reason || __typia_transform__assertGuard._assertGuard(_exceptionable, {
702
- method: "json.assertParse",
688
+ }), null === input.finish_reason || "function_call" === input.finish_reason || "stop" === input.finish_reason || "length" === input.finish_reason || "tool_calls" === input.finish_reason || "content_filter" === input.finish_reason || _report(_exceptionable, {
703
689
  path: _path + ".finish_reason",
704
690
  expected: '("content_filter" | "function_call" | "length" | "stop" | "tool_calls" | null)',
705
691
  value: input.finish_reason
706
- }, _errorFactory)) && ("number" === typeof input.index || __typia_transform__assertGuard._assertGuard(_exceptionable, {
707
- method: "json.assertParse",
692
+ }), "number" === typeof input.index || _report(_exceptionable, {
708
693
  path: _path + ".index",
709
694
  expected: "number",
710
695
  value: input.index
711
- }, _errorFactory)) && (null === input.logprobs || undefined === input.logprobs || ("object" === typeof input.logprobs && null !== input.logprobs || __typia_transform__assertGuard._assertGuard(_exceptionable, {
712
- method: "json.assertParse",
696
+ }), null === input.logprobs || undefined === input.logprobs || ("object" === typeof input.logprobs && null !== input.logprobs || _report(_exceptionable, {
713
697
  path: _path + ".logprobs",
714
698
  expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
715
699
  value: input.logprobs
716
- }, _errorFactory)) && _ao6(input.logprobs, _path + ".logprobs", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
717
- method: "json.assertParse",
700
+ })) && _vo6(input.logprobs, _path + ".logprobs", _exceptionable) || _report(_exceptionable, {
718
701
  path: _path + ".logprobs",
719
702
  expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
720
703
  value: input.logprobs
721
- }, _errorFactory));
722
- const _ao2 = (input, _path, _exceptionable = true) => (null === input.content || undefined === input.content || "string" === typeof input.content || __typia_transform__assertGuard._assertGuard(_exceptionable, {
723
- method: "json.assertParse",
704
+ }) ].every((flag => flag));
705
+ const _vo2 = (input, _path, _exceptionable = true) => [ null === input.content || undefined === input.content || "string" === typeof input.content || _report(_exceptionable, {
724
706
  path: _path + ".content",
725
707
  expected: "(null | string | undefined)",
726
708
  value: input.content
727
- }, _errorFactory)) && (undefined === input.function_call || ("object" === typeof input.function_call && null !== input.function_call && false === Array.isArray(input.function_call) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
728
- method: "json.assertParse",
709
+ }), undefined === input.function_call || ("object" === typeof input.function_call && null !== input.function_call && false === Array.isArray(input.function_call) || _report(_exceptionable, {
729
710
  path: _path + ".function_call",
730
711
  expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
731
712
  value: input.function_call
732
- }, _errorFactory)) && _ao3(input.function_call, _path + ".function_call", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
733
- method: "json.assertParse",
713
+ })) && _vo3(input.function_call, _path + ".function_call", _exceptionable) || _report(_exceptionable, {
734
714
  path: _path + ".function_call",
735
715
  expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
736
716
  value: input.function_call
737
- }, _errorFactory)) && (null === input.refusal || undefined === input.refusal || "string" === typeof input.refusal || __typia_transform__assertGuard._assertGuard(_exceptionable, {
738
- method: "json.assertParse",
717
+ }), null === input.refusal || undefined === input.refusal || "string" === typeof input.refusal || _report(_exceptionable, {
739
718
  path: _path + ".refusal",
740
719
  expected: "(null | string | undefined)",
741
720
  value: input.refusal
742
- }, _errorFactory)) && (undefined === input.role || "assistant" === input.role || "user" === input.role || "developer" === input.role || "system" === input.role || "tool" === input.role || __typia_transform__assertGuard._assertGuard(_exceptionable, {
743
- method: "json.assertParse",
721
+ }), undefined === input.role || "assistant" === input.role || "user" === input.role || "developer" === input.role || "system" === input.role || "tool" === input.role || _report(_exceptionable, {
744
722
  path: _path + ".role",
745
723
  expected: '("assistant" | "developer" | "system" | "tool" | "user" | undefined)',
746
724
  value: input.role
747
- }, _errorFactory)) && (undefined === input.tool_calls || (Array.isArray(input.tool_calls) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
748
- method: "json.assertParse",
725
+ }), undefined === input.tool_calls || (Array.isArray(input.tool_calls) || _report(_exceptionable, {
749
726
  path: _path + ".tool_calls",
750
727
  expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
751
728
  value: input.tool_calls
752
- }, _errorFactory)) && input.tool_calls.every(((elem, _index9) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
753
- method: "json.assertParse",
729
+ })) && input.tool_calls.map(((elem, _index9) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
754
730
  path: _path + ".tool_calls[" + _index9 + "]",
755
731
  expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
756
732
  value: elem
757
- }, _errorFactory)) && _ao4(elem, _path + ".tool_calls[" + _index9 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
758
- method: "json.assertParse",
733
+ })) && _vo4(elem, _path + ".tool_calls[" + _index9 + "]", _exceptionable) || _report(_exceptionable, {
759
734
  path: _path + ".tool_calls[" + _index9 + "]",
760
735
  expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
761
736
  value: elem
762
- }, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
763
- method: "json.assertParse",
737
+ }))).every((flag => flag)) || _report(_exceptionable, {
764
738
  path: _path + ".tool_calls",
765
739
  expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
766
740
  value: input.tool_calls
767
- }, _errorFactory));
768
- const _ao3 = (input, _path, _exceptionable = true) => (undefined === input.arguments || "string" === typeof input.arguments || __typia_transform__assertGuard._assertGuard(_exceptionable, {
769
- method: "json.assertParse",
741
+ }) ].every((flag => flag));
742
+ const _vo3 = (input, _path, _exceptionable = true) => [ undefined === input.arguments || "string" === typeof input.arguments || _report(_exceptionable, {
770
743
  path: _path + ".arguments",
771
744
  expected: "(string | undefined)",
772
745
  value: input.arguments
773
- }, _errorFactory)) && (undefined === input.name || "string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
774
- method: "json.assertParse",
746
+ }), undefined === input.name || "string" === typeof input.name || _report(_exceptionable, {
775
747
  path: _path + ".name",
776
748
  expected: "(string | undefined)",
777
749
  value: input.name
778
- }, _errorFactory));
779
- const _ao4 = (input, _path, _exceptionable = true) => ("number" === typeof input.index || __typia_transform__assertGuard._assertGuard(_exceptionable, {
780
- method: "json.assertParse",
750
+ }) ].every((flag => flag));
751
+ const _vo4 = (input, _path, _exceptionable = true) => [ "number" === typeof input.index || _report(_exceptionable, {
781
752
  path: _path + ".index",
782
753
  expected: "number",
783
754
  value: input.index
784
- }, _errorFactory)) && (undefined === input.id || "string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
785
- method: "json.assertParse",
755
+ }), undefined === input.id || "string" === typeof input.id || _report(_exceptionable, {
786
756
  path: _path + ".id",
787
757
  expected: "(string | undefined)",
788
758
  value: input.id
789
- }, _errorFactory)) && (undefined === input["function"] || ("object" === typeof input["function"] && null !== input["function"] && false === Array.isArray(input["function"]) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
790
- method: "json.assertParse",
759
+ }), undefined === input["function"] || ("object" === typeof input["function"] && null !== input["function"] && false === Array.isArray(input["function"]) || _report(_exceptionable, {
791
760
  path: _path + '["function"]',
792
761
  expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
793
762
  value: input["function"]
794
- }, _errorFactory)) && _ao5(input["function"], _path + '["function"]', _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
795
- method: "json.assertParse",
763
+ })) && _vo5(input["function"], _path + '["function"]', _exceptionable) || _report(_exceptionable, {
796
764
  path: _path + '["function"]',
797
765
  expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
798
766
  value: input["function"]
799
- }, _errorFactory)) && (undefined === input.type || "function" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
800
- method: "json.assertParse",
767
+ }), undefined === input.type || "function" === input.type || _report(_exceptionable, {
801
768
  path: _path + ".type",
802
769
  expected: '("function" | undefined)',
803
770
  value: input.type
804
- }, _errorFactory));
805
- const _ao5 = (input, _path, _exceptionable = true) => (undefined === input.arguments || "string" === typeof input.arguments || __typia_transform__assertGuard._assertGuard(_exceptionable, {
806
- method: "json.assertParse",
771
+ }) ].every((flag => flag));
772
+ const _vo5 = (input, _path, _exceptionable = true) => [ undefined === input.arguments || "string" === typeof input.arguments || _report(_exceptionable, {
807
773
  path: _path + ".arguments",
808
774
  expected: "(string | undefined)",
809
775
  value: input.arguments
810
- }, _errorFactory)) && (undefined === input.name || "string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
811
- method: "json.assertParse",
776
+ }), undefined === input.name || "string" === typeof input.name || _report(_exceptionable, {
812
777
  path: _path + ".name",
813
778
  expected: "(string | undefined)",
814
779
  value: input.name
815
- }, _errorFactory));
816
- const _ao6 = (input, _path, _exceptionable = true) => (null === input.content || (Array.isArray(input.content) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
817
- method: "json.assertParse",
780
+ }) ].every((flag => flag));
781
+ const _vo6 = (input, _path, _exceptionable = true) => [ null === input.content || (Array.isArray(input.content) || _report(_exceptionable, {
818
782
  path: _path + ".content",
819
783
  expected: "(Array<ChatCompletionTokenLogprob> | null)",
820
784
  value: input.content
821
- }, _errorFactory)) && input.content.every(((elem, _index10) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
822
- method: "json.assertParse",
785
+ })) && input.content.map(((elem, _index10) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
823
786
  path: _path + ".content[" + _index10 + "]",
824
787
  expected: "ChatCompletionTokenLogprob",
825
788
  value: elem
826
- }, _errorFactory)) && _ao7(elem, _path + ".content[" + _index10 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
827
- method: "json.assertParse",
789
+ })) && _vo7(elem, _path + ".content[" + _index10 + "]", _exceptionable) || _report(_exceptionable, {
828
790
  path: _path + ".content[" + _index10 + "]",
829
791
  expected: "ChatCompletionTokenLogprob",
830
792
  value: elem
831
- }, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
832
- method: "json.assertParse",
793
+ }))).every((flag => flag)) || _report(_exceptionable, {
833
794
  path: _path + ".content",
834
795
  expected: "(Array<ChatCompletionTokenLogprob> | null)",
835
796
  value: input.content
836
- }, _errorFactory)) && (null === input.refusal || (Array.isArray(input.refusal) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
837
- method: "json.assertParse",
797
+ }), null === input.refusal || (Array.isArray(input.refusal) || _report(_exceptionable, {
838
798
  path: _path + ".refusal",
839
799
  expected: "(Array<ChatCompletionTokenLogprob> | null)",
840
800
  value: input.refusal
841
- }, _errorFactory)) && input.refusal.every(((elem, _index11) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
842
- method: "json.assertParse",
801
+ })) && input.refusal.map(((elem, _index11) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
843
802
  path: _path + ".refusal[" + _index11 + "]",
844
803
  expected: "ChatCompletionTokenLogprob",
845
804
  value: elem
846
- }, _errorFactory)) && _ao7(elem, _path + ".refusal[" + _index11 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
847
- method: "json.assertParse",
805
+ })) && _vo7(elem, _path + ".refusal[" + _index11 + "]", _exceptionable) || _report(_exceptionable, {
848
806
  path: _path + ".refusal[" + _index11 + "]",
849
807
  expected: "ChatCompletionTokenLogprob",
850
808
  value: elem
851
- }, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
852
- method: "json.assertParse",
809
+ }))).every((flag => flag)) || _report(_exceptionable, {
853
810
  path: _path + ".refusal",
854
811
  expected: "(Array<ChatCompletionTokenLogprob> | null)",
855
812
  value: input.refusal
856
- }, _errorFactory));
857
- const _ao7 = (input, _path, _exceptionable = true) => ("string" === typeof input.token || __typia_transform__assertGuard._assertGuard(_exceptionable, {
858
- method: "json.assertParse",
813
+ }) ].every((flag => flag));
814
+ const _vo7 = (input, _path, _exceptionable = true) => [ "string" === typeof input.token || _report(_exceptionable, {
859
815
  path: _path + ".token",
860
816
  expected: "string",
861
817
  value: input.token
862
- }, _errorFactory)) && (null === input.bytes || (Array.isArray(input.bytes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
863
- method: "json.assertParse",
818
+ }), null === input.bytes || (Array.isArray(input.bytes) || _report(_exceptionable, {
864
819
  path: _path + ".bytes",
865
820
  expected: "(Array<number> | null)",
866
821
  value: input.bytes
867
- }, _errorFactory)) && input.bytes.every(((elem, _index12) => "number" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
868
- method: "json.assertParse",
822
+ })) && input.bytes.map(((elem, _index12) => "number" === typeof elem || _report(_exceptionable, {
869
823
  path: _path + ".bytes[" + _index12 + "]",
870
824
  expected: "number",
871
825
  value: elem
872
- }, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
873
- method: "json.assertParse",
826
+ }))).every((flag => flag)) || _report(_exceptionable, {
874
827
  path: _path + ".bytes",
875
828
  expected: "(Array<number> | null)",
876
829
  value: input.bytes
877
- }, _errorFactory)) && ("number" === typeof input.logprob || __typia_transform__assertGuard._assertGuard(_exceptionable, {
878
- method: "json.assertParse",
830
+ }), "number" === typeof input.logprob || _report(_exceptionable, {
879
831
  path: _path + ".logprob",
880
832
  expected: "number",
881
833
  value: input.logprob
882
- }, _errorFactory)) && ((Array.isArray(input.top_logprobs) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
883
- method: "json.assertParse",
834
+ }), (Array.isArray(input.top_logprobs) || _report(_exceptionable, {
884
835
  path: _path + ".top_logprobs",
885
836
  expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
886
837
  value: input.top_logprobs
887
- }, _errorFactory)) && input.top_logprobs.every(((elem, _index13) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
888
- method: "json.assertParse",
838
+ })) && input.top_logprobs.map(((elem, _index13) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
889
839
  path: _path + ".top_logprobs[" + _index13 + "]",
890
840
  expected: "ChatCompletionTokenLogprob.TopLogprob",
891
841
  value: elem
892
- }, _errorFactory)) && _ao8(elem, _path + ".top_logprobs[" + _index13 + "]", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
893
- method: "json.assertParse",
842
+ })) && _vo8(elem, _path + ".top_logprobs[" + _index13 + "]", _exceptionable) || _report(_exceptionable, {
894
843
  path: _path + ".top_logprobs[" + _index13 + "]",
895
844
  expected: "ChatCompletionTokenLogprob.TopLogprob",
896
845
  value: elem
897
- }, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
898
- method: "json.assertParse",
846
+ }))).every((flag => flag)) || _report(_exceptionable, {
899
847
  path: _path + ".top_logprobs",
900
848
  expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
901
849
  value: input.top_logprobs
902
- }, _errorFactory));
903
- const _ao8 = (input, _path, _exceptionable = true) => ("string" === typeof input.token || __typia_transform__assertGuard._assertGuard(_exceptionable, {
904
- method: "json.assertParse",
850
+ }) ].every((flag => flag));
851
+ const _vo8 = (input, _path, _exceptionable = true) => [ "string" === typeof input.token || _report(_exceptionable, {
905
852
  path: _path + ".token",
906
853
  expected: "string",
907
854
  value: input.token
908
- }, _errorFactory)) && (null === input.bytes || (Array.isArray(input.bytes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
909
- method: "json.assertParse",
855
+ }), null === input.bytes || (Array.isArray(input.bytes) || _report(_exceptionable, {
910
856
  path: _path + ".bytes",
911
857
  expected: "(Array<number> | null)",
912
858
  value: input.bytes
913
- }, _errorFactory)) && input.bytes.every(((elem, _index14) => "number" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
914
- method: "json.assertParse",
859
+ })) && input.bytes.map(((elem, _index14) => "number" === typeof elem || _report(_exceptionable, {
915
860
  path: _path + ".bytes[" + _index14 + "]",
916
861
  expected: "number",
917
862
  value: elem
918
- }, _errorFactory))) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
919
- method: "json.assertParse",
863
+ }))).every((flag => flag)) || _report(_exceptionable, {
920
864
  path: _path + ".bytes",
921
865
  expected: "(Array<number> | null)",
922
866
  value: input.bytes
923
- }, _errorFactory)) && ("number" === typeof input.logprob || __typia_transform__assertGuard._assertGuard(_exceptionable, {
924
- method: "json.assertParse",
867
+ }), "number" === typeof input.logprob || _report(_exceptionable, {
925
868
  path: _path + ".logprob",
926
869
  expected: "number",
927
870
  value: input.logprob
928
- }, _errorFactory));
929
- const _ao9 = (input, _path, _exceptionable = true) => ("number" === typeof input.completion_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
930
- method: "json.assertParse",
871
+ }) ].every((flag => flag));
872
+ const _vo9 = (input, _path, _exceptionable = true) => [ "number" === typeof input.completion_tokens || _report(_exceptionable, {
931
873
  path: _path + ".completion_tokens",
932
874
  expected: "number",
933
875
  value: input.completion_tokens
934
- }, _errorFactory)) && ("number" === typeof input.prompt_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
935
- method: "json.assertParse",
876
+ }), "number" === typeof input.prompt_tokens || _report(_exceptionable, {
936
877
  path: _path + ".prompt_tokens",
937
878
  expected: "number",
938
879
  value: input.prompt_tokens
939
- }, _errorFactory)) && ("number" === typeof input.total_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
940
- method: "json.assertParse",
880
+ }), "number" === typeof input.total_tokens || _report(_exceptionable, {
941
881
  path: _path + ".total_tokens",
942
882
  expected: "number",
943
883
  value: input.total_tokens
944
- }, _errorFactory)) && (undefined === input.completion_tokens_details || ("object" === typeof input.completion_tokens_details && null !== input.completion_tokens_details && false === Array.isArray(input.completion_tokens_details) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
945
- method: "json.assertParse",
884
+ }), undefined === input.completion_tokens_details || ("object" === typeof input.completion_tokens_details && null !== input.completion_tokens_details && false === Array.isArray(input.completion_tokens_details) || _report(_exceptionable, {
946
885
  path: _path + ".completion_tokens_details",
947
886
  expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
948
887
  value: input.completion_tokens_details
949
- }, _errorFactory)) && _ao10(input.completion_tokens_details, _path + ".completion_tokens_details", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
950
- method: "json.assertParse",
888
+ })) && _vo10(input.completion_tokens_details, _path + ".completion_tokens_details", _exceptionable) || _report(_exceptionable, {
951
889
  path: _path + ".completion_tokens_details",
952
890
  expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
953
891
  value: input.completion_tokens_details
954
- }, _errorFactory)) && (undefined === input.prompt_tokens_details || ("object" === typeof input.prompt_tokens_details && null !== input.prompt_tokens_details && false === Array.isArray(input.prompt_tokens_details) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
955
- method: "json.assertParse",
892
+ }), undefined === input.prompt_tokens_details || ("object" === typeof input.prompt_tokens_details && null !== input.prompt_tokens_details && false === Array.isArray(input.prompt_tokens_details) || _report(_exceptionable, {
956
893
  path: _path + ".prompt_tokens_details",
957
894
  expected: "(CompletionUsage.PromptTokensDetails | undefined)",
958
895
  value: input.prompt_tokens_details
959
- }, _errorFactory)) && _ao11(input.prompt_tokens_details, _path + ".prompt_tokens_details", _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
960
- method: "json.assertParse",
896
+ })) && _vo11(input.prompt_tokens_details, _path + ".prompt_tokens_details", _exceptionable) || _report(_exceptionable, {
961
897
  path: _path + ".prompt_tokens_details",
962
898
  expected: "(CompletionUsage.PromptTokensDetails | undefined)",
963
899
  value: input.prompt_tokens_details
964
- }, _errorFactory));
965
- const _ao10 = (input, _path, _exceptionable = true) => (undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
966
- method: "json.assertParse",
900
+ }) ].every((flag => flag));
901
+ const _vo10 = (input, _path, _exceptionable = true) => [ undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens || _report(_exceptionable, {
967
902
  path: _path + ".accepted_prediction_tokens",
968
903
  expected: "(number | undefined)",
969
904
  value: input.accepted_prediction_tokens
970
- }, _errorFactory)) && (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
971
- method: "json.assertParse",
905
+ }), undefined === input.audio_tokens || "number" === typeof input.audio_tokens || _report(_exceptionable, {
972
906
  path: _path + ".audio_tokens",
973
907
  expected: "(number | undefined)",
974
908
  value: input.audio_tokens
975
- }, _errorFactory)) && (undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
976
- method: "json.assertParse",
909
+ }), undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens || _report(_exceptionable, {
977
910
  path: _path + ".reasoning_tokens",
978
911
  expected: "(number | undefined)",
979
912
  value: input.reasoning_tokens
980
- }, _errorFactory)) && (undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
981
- method: "json.assertParse",
913
+ }), undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens || _report(_exceptionable, {
982
914
  path: _path + ".rejected_prediction_tokens",
983
915
  expected: "(number | undefined)",
984
916
  value: input.rejected_prediction_tokens
985
- }, _errorFactory));
986
- const _ao11 = (input, _path, _exceptionable = true) => (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
987
- method: "json.assertParse",
917
+ }) ].every((flag => flag));
918
+ const _vo11 = (input, _path, _exceptionable = true) => [ undefined === input.audio_tokens || "number" === typeof input.audio_tokens || _report(_exceptionable, {
988
919
  path: _path + ".audio_tokens",
989
920
  expected: "(number | undefined)",
990
921
  value: input.audio_tokens
991
- }, _errorFactory)) && (undefined === input.cached_tokens || "number" === typeof input.cached_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
992
- method: "json.assertParse",
922
+ }), undefined === input.cached_tokens || "number" === typeof input.cached_tokens || _report(_exceptionable, {
993
923
  path: _path + ".cached_tokens",
994
924
  expected: "(number | undefined)",
995
925
  value: input.cached_tokens
996
- }, _errorFactory));
926
+ }) ].every((flag => flag));
997
927
  const __is = input => "object" === typeof input && null !== input && _io0(input);
998
- let _errorFactory;
999
- const __assert = (input, errorFactory) => {
928
+ let errors;
929
+ let _report;
930
+ return input => {
1000
931
  if (false === __is(input)) {
1001
- _errorFactory = errorFactory;
1002
- ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
1003
- method: "json.assertParse",
932
+ errors = [];
933
+ _report = __typia_transform__validateReport._validateReport(errors);
934
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
1004
935
  path: _path + "",
1005
- expected: "ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",
936
+ expected: "ChatCompletionChunk",
1006
937
  value: input
1007
- }, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
1008
- method: "json.assertParse",
938
+ })) && _vo0(input, _path + "", true) || _report(true, {
1009
939
  path: _path + "",
1010
- expected: "ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",
940
+ expected: "ChatCompletionChunk",
1011
941
  value: input
1012
- }, _errorFactory))(input, "$input", true);
942
+ }))(input, "$input", true);
943
+ const success = 0 === errors.length;
944
+ return success ? {
945
+ success,
946
+ data: input
947
+ } : {
948
+ success,
949
+ errors,
950
+ data: input
951
+ };
1013
952
  }
1014
- return input;
953
+ return {
954
+ success: true,
955
+ data: input
956
+ };
1015
957
  };
1016
- return (input, errorFactory) => __assert(JSON.parse(input), errorFactory);
1017
- })()(str);
958
+ })()(result);
959
+ if (valid.success === false) {
960
+ console.error("Invalid ChatCompletionChunk", valid.errors);
961
+ }
962
+ return result;
1018
963
  }
1019
964
 
1020
965
  function accumulate(origin, chunk) {
@@ -1202,19 +1147,19 @@ const StreamUtil = {
1202
1147
  transform: transform$1
1203
1148
  };
1204
1149
 
1205
- async function cancelFunction(ctx, reference) {
1150
+ function cancelFunction(ctx, reference) {
1206
1151
  const index = ctx.stack.findIndex((item => item.operation.name === reference.name));
1207
1152
  if (index === -1) {
1208
1153
  return null;
1209
1154
  }
1210
1155
  const item = ctx.stack[index];
1211
1156
  ctx.stack.splice(index, 1);
1212
- await ctx.dispatch(createCancelEvent({
1157
+ ctx.dispatch(createCancelEvent({
1213
1158
  selection: createOperationSelection({
1214
1159
  operation: item.operation,
1215
1160
  reason: reference.reason
1216
1161
  })
1217
- }));
1162
+ })).catch((() => {}));
1218
1163
  return item;
1219
1164
  }
1220
1165
 
@@ -1278,24 +1223,19 @@ async function call(ctx, operations) {
1278
1223
  value: execute.value
1279
1224
  })).catch((() => {}));
1280
1225
  if (isAgenticaContext(ctx)) {
1281
- await cancelFunction(ctx, {
1226
+ cancelFunction(ctx, {
1282
1227
  name: call.operation.name,
1283
1228
  reason: "completed"
1284
1229
  });
1285
- ctx.dispatch(createCancelEvent({
1286
- selection: createOperationSelection({
1230
+ return [ execute, createCancelHistory({
1231
+ id: call.id,
1232
+ selections: [ createOperationSelection({
1287
1233
  operation: call.operation,
1288
1234
  reason: "complete"
1289
- })
1290
- })).catch((() => {}));
1235
+ }) ]
1236
+ }) ];
1291
1237
  }
1292
- return [ execute, createCancelHistory({
1293
- id: call.id,
1294
- selections: [ createOperationSelection({
1295
- operation: call.operation,
1296
- reason: "complete"
1297
- }) ]
1298
- }) ];
1238
+ return [ execute ];
1299
1239
  }));
1300
1240
  }
1301
1241
  }
@@ -1605,6 +1545,7 @@ const CONTAINER$1 = {
1605
1545
  };
1606
1546
 
1607
1547
  async function cancel(ctx) {
1548
+ console.error("orchestrate.cancel");
1608
1549
  if (ctx.operations.divided === undefined) {
1609
1550
  return step$1(ctx, ctx.operations.array, 0);
1610
1551
  }
@@ -1629,7 +1570,7 @@ async function cancel(ctx) {
1629
1570
  for (const e of events) {
1630
1571
  if (e.type === "select") {
1631
1572
  collection.selections.push(e.selection);
1632
- await cancelFunction(ctx, {
1573
+ cancelFunction(ctx, {
1633
1574
  name: e.selection.operation.name,
1634
1575
  reason: e.selection.reason
1635
1576
  });
@@ -1794,7 +1735,7 @@ async function step$1(ctx, operations, retry, failures) {
1794
1735
  selections: []
1795
1736
  });
1796
1737
  for (const reference of input.functions) {
1797
- const operation = await cancelFunction(ctx, reference);
1738
+ const operation = cancelFunction(ctx, reference);
1798
1739
  if (operation !== null) {
1799
1740
  collection.selections.push(operation);
1800
1741
  }
@@ -4105,12 +4046,6 @@ function execute(executor) {
4105
4046
  const prompts = await (executor?.call ?? call)(ctx, ctx.stack.map((s => s.operation)));
4106
4047
  histories.push(...prompts);
4107
4048
  const executes = prompts.filter((prompt => prompt.type === "execute"));
4108
- for (const e of executes) {
4109
- await cancelFunction(ctx, {
4110
- reason: "completed",
4111
- name: e.operation.name
4112
- });
4113
- }
4114
4049
  histories.push(...await (executor?.describe ?? describe)(ctx, executes));
4115
4050
  if (executes.length === 0 || ctx.stack.length === 0) {
4116
4051
  break;