@slashfi/agents-sdk 0.33.1 → 0.34.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/call-agent-schema.d.ts +327 -13
- package/dist/call-agent-schema.d.ts.map +1 -1
- package/dist/call-agent-schema.js +68 -7
- package/dist/call-agent-schema.js.map +1 -1
- package/dist/cjs/call-agent-schema.js +72 -8
- package/dist/cjs/call-agent-schema.js.map +1 -1
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/registry-consumer.js +2 -1
- package/dist/cjs/registry-consumer.js.map +1 -1
- package/dist/cjs/server.js +22 -6
- package/dist/cjs/server.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/registry-consumer.d.ts.map +1 -1
- package/dist/registry-consumer.js +2 -1
- package/dist/registry-consumer.js.map +1 -1
- package/dist/server.d.ts +18 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +23 -7
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
- package/src/call-agent-schema.test.ts +306 -0
- package/src/call-agent-schema.ts +92 -17
- package/src/index.ts +6 -0
- package/src/registry-consumer.ts +10 -3
- package/src/server.ts +45 -7
|
@@ -11,7 +11,39 @@
|
|
|
11
11
|
*
|
|
12
12
|
* Response types live in types.ts (they're output shapes, not validated input).
|
|
13
13
|
*/
|
|
14
|
-
import { z } from "zod";
|
|
14
|
+
import { z, type ZodTypeAny } from "zod";
|
|
15
|
+
/**
|
|
16
|
+
* Recursively strip null values from an object, converting them to undefined.
|
|
17
|
+
* This is the inverse of zod-to-json-schema's openAi target behavior, which
|
|
18
|
+
* converts .optional() fields to nullable+required in JSON Schema.
|
|
19
|
+
*
|
|
20
|
+
* Used as a z.preprocess() step so that Zod's .optional() (which accepts
|
|
21
|
+
* undefined but not null) works correctly with LLM outputs that send null
|
|
22
|
+
* for "no value" per the OpenAI function calling convention.
|
|
23
|
+
*/
|
|
24
|
+
export declare function stripNulls(obj: unknown): unknown;
|
|
25
|
+
/**
|
|
26
|
+
* Wrap a Zod schema with a preprocess step that converts null → undefined.
|
|
27
|
+
* This makes the schema "null-tolerant" — matching what the OpenAI JSON Schema
|
|
28
|
+
* target promises to LLMs (nullable fields) while keeping Zod's .optional()
|
|
29
|
+
* semantics internally.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const schema = z.object({ name: z.string().optional() });
|
|
34
|
+
* const tolerant = nullTolerant(schema);
|
|
35
|
+
* tolerant.parse({ name: null }); // { name: undefined } — no error
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function nullTolerant<T extends ZodTypeAny>(schema: T): T;
|
|
39
|
+
/**
|
|
40
|
+
* Convert a Zod schema to JSON Schema using the OpenAI target,
|
|
41
|
+
* which makes all optional fields nullable+required.
|
|
42
|
+
*
|
|
43
|
+
* This is the standard way to generate input schemas for MCP tools
|
|
44
|
+
* that will be called by LLMs.
|
|
45
|
+
*/
|
|
46
|
+
export declare function zodToOpenAiJsonSchema(schema: ZodTypeAny): Record<string, unknown>;
|
|
15
47
|
export declare const callerTypeSchema: z.ZodEnum<["agent", "user", "system"]>;
|
|
16
48
|
/** Invoke: fire-and-forget */
|
|
17
49
|
export declare const invokeActionSchema: z.ZodObject<{
|
|
@@ -652,12 +684,286 @@ export declare const callAgentToolInputSchema: z.ZodObject<{
|
|
|
652
684
|
*
|
|
653
685
|
* Fully derived from the zod schemas — no hand-written JSON Schema.
|
|
654
686
|
*/
|
|
655
|
-
export declare const callAgentInputSchema:
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
687
|
+
export declare const callAgentInputSchema: Record<string, unknown>;
|
|
688
|
+
/**
|
|
689
|
+
* Null-tolerant validation schema for `call_agent`.
|
|
690
|
+
* Accepts null values where the JSON Schema promises nullable,
|
|
691
|
+
* converting them to undefined before Zod validation.
|
|
692
|
+
*/
|
|
693
|
+
export declare const callAgentValidationSchema: z.ZodObject<{
|
|
694
|
+
request: z.ZodDiscriminatedUnion<"action", [z.ZodObject<{
|
|
695
|
+
path: z.ZodString;
|
|
696
|
+
callerId: z.ZodOptional<z.ZodString>;
|
|
697
|
+
callerType: z.ZodOptional<z.ZodEnum<["agent", "user", "system"]>>;
|
|
698
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
699
|
+
} & {
|
|
700
|
+
action: z.ZodLiteral<"invoke">;
|
|
701
|
+
prompt: z.ZodString;
|
|
702
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
703
|
+
branchAttributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
704
|
+
}, "strip", z.ZodTypeAny, {
|
|
705
|
+
action: "invoke";
|
|
706
|
+
path: string;
|
|
707
|
+
prompt: string;
|
|
708
|
+
callerId?: string | undefined;
|
|
709
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
710
|
+
metadata?: Record<string, unknown> | undefined;
|
|
711
|
+
sessionId?: string | undefined;
|
|
712
|
+
branchAttributes?: Record<string, string> | undefined;
|
|
713
|
+
}, {
|
|
714
|
+
action: "invoke";
|
|
715
|
+
path: string;
|
|
716
|
+
prompt: string;
|
|
717
|
+
callerId?: string | undefined;
|
|
718
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
719
|
+
metadata?: Record<string, unknown> | undefined;
|
|
720
|
+
sessionId?: string | undefined;
|
|
721
|
+
branchAttributes?: Record<string, string> | undefined;
|
|
722
|
+
}>, z.ZodObject<{
|
|
723
|
+
path: z.ZodString;
|
|
724
|
+
callerId: z.ZodOptional<z.ZodString>;
|
|
725
|
+
callerType: z.ZodOptional<z.ZodEnum<["agent", "user", "system"]>>;
|
|
726
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
727
|
+
} & {
|
|
728
|
+
action: z.ZodLiteral<"ask">;
|
|
729
|
+
prompt: z.ZodString;
|
|
730
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
731
|
+
branchAttributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
732
|
+
}, "strip", z.ZodTypeAny, {
|
|
733
|
+
action: "ask";
|
|
734
|
+
path: string;
|
|
735
|
+
prompt: string;
|
|
736
|
+
callerId?: string | undefined;
|
|
737
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
738
|
+
metadata?: Record<string, unknown> | undefined;
|
|
739
|
+
sessionId?: string | undefined;
|
|
740
|
+
branchAttributes?: Record<string, string> | undefined;
|
|
741
|
+
}, {
|
|
742
|
+
action: "ask";
|
|
743
|
+
path: string;
|
|
744
|
+
prompt: string;
|
|
745
|
+
callerId?: string | undefined;
|
|
746
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
747
|
+
metadata?: Record<string, unknown> | undefined;
|
|
748
|
+
sessionId?: string | undefined;
|
|
749
|
+
branchAttributes?: Record<string, string> | undefined;
|
|
750
|
+
}>, z.ZodObject<{
|
|
751
|
+
path: z.ZodString;
|
|
752
|
+
callerId: z.ZodOptional<z.ZodString>;
|
|
753
|
+
callerType: z.ZodOptional<z.ZodEnum<["agent", "user", "system"]>>;
|
|
754
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
755
|
+
} & {
|
|
756
|
+
action: z.ZodLiteral<"execute_tool">;
|
|
757
|
+
tool: z.ZodString;
|
|
758
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
759
|
+
}, "strip", z.ZodTypeAny, {
|
|
760
|
+
action: "execute_tool";
|
|
761
|
+
path: string;
|
|
762
|
+
tool: string;
|
|
763
|
+
callerId?: string | undefined;
|
|
764
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
765
|
+
params?: Record<string, unknown> | undefined;
|
|
766
|
+
metadata?: Record<string, unknown> | undefined;
|
|
767
|
+
}, {
|
|
768
|
+
action: "execute_tool";
|
|
769
|
+
path: string;
|
|
770
|
+
tool: string;
|
|
771
|
+
callerId?: string | undefined;
|
|
772
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
773
|
+
params?: Record<string, unknown> | undefined;
|
|
774
|
+
metadata?: Record<string, unknown> | undefined;
|
|
775
|
+
}>, z.ZodObject<{
|
|
776
|
+
path: z.ZodString;
|
|
777
|
+
callerId: z.ZodOptional<z.ZodString>;
|
|
778
|
+
callerType: z.ZodOptional<z.ZodEnum<["agent", "user", "system"]>>;
|
|
779
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
780
|
+
} & {
|
|
781
|
+
action: z.ZodLiteral<"describe_tools">;
|
|
782
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
783
|
+
}, "strip", z.ZodTypeAny, {
|
|
784
|
+
action: "describe_tools";
|
|
785
|
+
path: string;
|
|
786
|
+
callerId?: string | undefined;
|
|
787
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
788
|
+
metadata?: Record<string, unknown> | undefined;
|
|
789
|
+
tools?: string[] | undefined;
|
|
790
|
+
}, {
|
|
791
|
+
action: "describe_tools";
|
|
792
|
+
path: string;
|
|
793
|
+
callerId?: string | undefined;
|
|
794
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
795
|
+
metadata?: Record<string, unknown> | undefined;
|
|
796
|
+
tools?: string[] | undefined;
|
|
797
|
+
}>, z.ZodObject<{
|
|
798
|
+
path: z.ZodString;
|
|
799
|
+
callerId: z.ZodOptional<z.ZodString>;
|
|
800
|
+
callerType: z.ZodOptional<z.ZodEnum<["agent", "user", "system"]>>;
|
|
801
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
802
|
+
} & {
|
|
803
|
+
action: z.ZodLiteral<"load">;
|
|
804
|
+
}, "strip", z.ZodTypeAny, {
|
|
805
|
+
action: "load";
|
|
806
|
+
path: string;
|
|
807
|
+
callerId?: string | undefined;
|
|
808
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
809
|
+
metadata?: Record<string, unknown> | undefined;
|
|
810
|
+
}, {
|
|
811
|
+
action: "load";
|
|
812
|
+
path: string;
|
|
813
|
+
callerId?: string | undefined;
|
|
814
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
815
|
+
metadata?: Record<string, unknown> | undefined;
|
|
816
|
+
}>, z.ZodObject<{
|
|
817
|
+
path: z.ZodString;
|
|
818
|
+
callerId: z.ZodOptional<z.ZodString>;
|
|
819
|
+
callerType: z.ZodOptional<z.ZodEnum<["agent", "user", "system"]>>;
|
|
820
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
821
|
+
} & {
|
|
822
|
+
action: z.ZodLiteral<"list_resources">;
|
|
823
|
+
}, "strip", z.ZodTypeAny, {
|
|
824
|
+
action: "list_resources";
|
|
825
|
+
path: string;
|
|
826
|
+
callerId?: string | undefined;
|
|
827
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
828
|
+
metadata?: Record<string, unknown> | undefined;
|
|
829
|
+
}, {
|
|
830
|
+
action: "list_resources";
|
|
831
|
+
path: string;
|
|
832
|
+
callerId?: string | undefined;
|
|
833
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
834
|
+
metadata?: Record<string, unknown> | undefined;
|
|
835
|
+
}>, z.ZodObject<{
|
|
836
|
+
path: z.ZodString;
|
|
837
|
+
callerId: z.ZodOptional<z.ZodString>;
|
|
838
|
+
callerType: z.ZodOptional<z.ZodEnum<["agent", "user", "system"]>>;
|
|
839
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
840
|
+
} & {
|
|
841
|
+
action: z.ZodLiteral<"read_resources">;
|
|
842
|
+
uris: z.ZodArray<z.ZodString, "many">;
|
|
843
|
+
}, "strip", z.ZodTypeAny, {
|
|
844
|
+
action: "read_resources";
|
|
845
|
+
path: string;
|
|
846
|
+
uris: string[];
|
|
847
|
+
callerId?: string | undefined;
|
|
848
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
849
|
+
metadata?: Record<string, unknown> | undefined;
|
|
850
|
+
}, {
|
|
851
|
+
action: "read_resources";
|
|
852
|
+
path: string;
|
|
853
|
+
uris: string[];
|
|
854
|
+
callerId?: string | undefined;
|
|
855
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
856
|
+
metadata?: Record<string, unknown> | undefined;
|
|
857
|
+
}>]>;
|
|
858
|
+
}, "strip", z.ZodTypeAny, {
|
|
859
|
+
request: {
|
|
860
|
+
action: "invoke";
|
|
861
|
+
path: string;
|
|
862
|
+
prompt: string;
|
|
863
|
+
callerId?: string | undefined;
|
|
864
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
865
|
+
metadata?: Record<string, unknown> | undefined;
|
|
866
|
+
sessionId?: string | undefined;
|
|
867
|
+
branchAttributes?: Record<string, string> | undefined;
|
|
868
|
+
} | {
|
|
869
|
+
action: "ask";
|
|
870
|
+
path: string;
|
|
871
|
+
prompt: string;
|
|
872
|
+
callerId?: string | undefined;
|
|
873
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
874
|
+
metadata?: Record<string, unknown> | undefined;
|
|
875
|
+
sessionId?: string | undefined;
|
|
876
|
+
branchAttributes?: Record<string, string> | undefined;
|
|
877
|
+
} | {
|
|
878
|
+
action: "execute_tool";
|
|
879
|
+
path: string;
|
|
880
|
+
tool: string;
|
|
881
|
+
callerId?: string | undefined;
|
|
882
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
883
|
+
params?: Record<string, unknown> | undefined;
|
|
884
|
+
metadata?: Record<string, unknown> | undefined;
|
|
885
|
+
} | {
|
|
886
|
+
action: "describe_tools";
|
|
887
|
+
path: string;
|
|
888
|
+
callerId?: string | undefined;
|
|
889
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
890
|
+
metadata?: Record<string, unknown> | undefined;
|
|
891
|
+
tools?: string[] | undefined;
|
|
892
|
+
} | {
|
|
893
|
+
action: "load";
|
|
894
|
+
path: string;
|
|
895
|
+
callerId?: string | undefined;
|
|
896
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
897
|
+
metadata?: Record<string, unknown> | undefined;
|
|
898
|
+
} | {
|
|
899
|
+
action: "list_resources";
|
|
900
|
+
path: string;
|
|
901
|
+
callerId?: string | undefined;
|
|
902
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
903
|
+
metadata?: Record<string, unknown> | undefined;
|
|
904
|
+
} | {
|
|
905
|
+
action: "read_resources";
|
|
906
|
+
path: string;
|
|
907
|
+
uris: string[];
|
|
908
|
+
callerId?: string | undefined;
|
|
909
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
910
|
+
metadata?: Record<string, unknown> | undefined;
|
|
911
|
+
};
|
|
912
|
+
}, {
|
|
913
|
+
request: {
|
|
914
|
+
action: "invoke";
|
|
915
|
+
path: string;
|
|
916
|
+
prompt: string;
|
|
917
|
+
callerId?: string | undefined;
|
|
918
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
919
|
+
metadata?: Record<string, unknown> | undefined;
|
|
920
|
+
sessionId?: string | undefined;
|
|
921
|
+
branchAttributes?: Record<string, string> | undefined;
|
|
922
|
+
} | {
|
|
923
|
+
action: "ask";
|
|
924
|
+
path: string;
|
|
925
|
+
prompt: string;
|
|
926
|
+
callerId?: string | undefined;
|
|
927
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
928
|
+
metadata?: Record<string, unknown> | undefined;
|
|
929
|
+
sessionId?: string | undefined;
|
|
930
|
+
branchAttributes?: Record<string, string> | undefined;
|
|
931
|
+
} | {
|
|
932
|
+
action: "execute_tool";
|
|
933
|
+
path: string;
|
|
934
|
+
tool: string;
|
|
935
|
+
callerId?: string | undefined;
|
|
936
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
937
|
+
params?: Record<string, unknown> | undefined;
|
|
938
|
+
metadata?: Record<string, unknown> | undefined;
|
|
939
|
+
} | {
|
|
940
|
+
action: "describe_tools";
|
|
941
|
+
path: string;
|
|
942
|
+
callerId?: string | undefined;
|
|
943
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
944
|
+
metadata?: Record<string, unknown> | undefined;
|
|
945
|
+
tools?: string[] | undefined;
|
|
946
|
+
} | {
|
|
947
|
+
action: "load";
|
|
948
|
+
path: string;
|
|
949
|
+
callerId?: string | undefined;
|
|
950
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
951
|
+
metadata?: Record<string, unknown> | undefined;
|
|
952
|
+
} | {
|
|
953
|
+
action: "list_resources";
|
|
954
|
+
path: string;
|
|
955
|
+
callerId?: string | undefined;
|
|
956
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
957
|
+
metadata?: Record<string, unknown> | undefined;
|
|
958
|
+
} | {
|
|
959
|
+
action: "read_resources";
|
|
960
|
+
path: string;
|
|
961
|
+
uris: string[];
|
|
962
|
+
callerId?: string | undefined;
|
|
963
|
+
callerType?: "agent" | "user" | "system" | undefined;
|
|
964
|
+
metadata?: Record<string, unknown> | undefined;
|
|
965
|
+
};
|
|
966
|
+
}>;
|
|
661
967
|
export declare const listAgentsToolInputSchema: z.ZodObject<{
|
|
662
968
|
query: z.ZodOptional<z.ZodString>;
|
|
663
969
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
@@ -672,10 +978,18 @@ export declare const listAgentsToolInputSchema: z.ZodObject<{
|
|
|
672
978
|
cursor?: string | undefined;
|
|
673
979
|
}>;
|
|
674
980
|
export type ListAgentsInput = z.infer<typeof listAgentsToolInputSchema>;
|
|
675
|
-
export declare const listAgentsInputSchema:
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
}
|
|
981
|
+
export declare const listAgentsInputSchema: Record<string, unknown>;
|
|
982
|
+
export declare const listAgentsValidationSchema: z.ZodObject<{
|
|
983
|
+
query: z.ZodOptional<z.ZodString>;
|
|
984
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
985
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
986
|
+
}, "strip", z.ZodTypeAny, {
|
|
987
|
+
query?: string | undefined;
|
|
988
|
+
limit?: number | undefined;
|
|
989
|
+
cursor?: string | undefined;
|
|
990
|
+
}, {
|
|
991
|
+
query?: string | undefined;
|
|
992
|
+
limit?: number | undefined;
|
|
993
|
+
cursor?: string | undefined;
|
|
994
|
+
}>;
|
|
681
995
|
//# sourceMappingURL=call-agent-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-agent-schema.d.ts","sourceRoot":"","sources":["../src/call-agent-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"call-agent-schema.d.ts","sourceRoot":"","sources":["../src/call-agent-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAOzC;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAYhD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,GACJ,CAAC,CACxD;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,UAAU,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMzB;AAMD,eAAO,MAAM,gBAAgB,wCAAsC,CAAC;AAapE,8BAA8B;AAC9B,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW7B,CAAC;AAEH,wCAAwC;AACxC,eAAO,MAAM,eAAe;;;;;;;;;;;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AAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAExE,eAAO,MAAM,qBAAqB,yBAEjC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;EAEtC,CAAC"}
|
|
@@ -12,6 +12,59 @@
|
|
|
12
12
|
* Response types live in types.ts (they're output shapes, not validated input).
|
|
13
13
|
*/
|
|
14
14
|
import { z } from "zod";
|
|
15
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
16
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
17
|
+
// OpenAI null-tolerance transform
|
|
18
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
19
|
+
/**
|
|
20
|
+
* Recursively strip null values from an object, converting them to undefined.
|
|
21
|
+
* This is the inverse of zod-to-json-schema's openAi target behavior, which
|
|
22
|
+
* converts .optional() fields to nullable+required in JSON Schema.
|
|
23
|
+
*
|
|
24
|
+
* Used as a z.preprocess() step so that Zod's .optional() (which accepts
|
|
25
|
+
* undefined but not null) works correctly with LLM outputs that send null
|
|
26
|
+
* for "no value" per the OpenAI function calling convention.
|
|
27
|
+
*/
|
|
28
|
+
export function stripNulls(obj) {
|
|
29
|
+
if (obj === null)
|
|
30
|
+
return undefined;
|
|
31
|
+
if (Array.isArray(obj))
|
|
32
|
+
return obj.map(stripNulls);
|
|
33
|
+
if (typeof obj === "object") {
|
|
34
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [
|
|
35
|
+
k,
|
|
36
|
+
stripNulls(v),
|
|
37
|
+
]));
|
|
38
|
+
}
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Wrap a Zod schema with a preprocess step that converts null → undefined.
|
|
43
|
+
* This makes the schema "null-tolerant" — matching what the OpenAI JSON Schema
|
|
44
|
+
* target promises to LLMs (nullable fields) while keeping Zod's .optional()
|
|
45
|
+
* semantics internally.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const schema = z.object({ name: z.string().optional() });
|
|
50
|
+
* const tolerant = nullTolerant(schema);
|
|
51
|
+
* tolerant.parse({ name: null }); // { name: undefined } — no error
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function nullTolerant(schema) {
|
|
55
|
+
return z.preprocess(stripNulls, schema);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Convert a Zod schema to JSON Schema using the OpenAI target,
|
|
59
|
+
* which makes all optional fields nullable+required.
|
|
60
|
+
*
|
|
61
|
+
* This is the standard way to generate input schemas for MCP tools
|
|
62
|
+
* that will be called by LLMs.
|
|
63
|
+
*/
|
|
64
|
+
export function zodToOpenAiJsonSchema(schema) {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
+
return zodToJsonSchema(schema, { target: "openAi" });
|
|
67
|
+
}
|
|
15
68
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
16
69
|
// Base schemas
|
|
17
70
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -74,11 +127,15 @@ export const loadActionSchema = callAgentBaseSchema.extend({
|
|
|
74
127
|
});
|
|
75
128
|
/** List resources: discover available resources on an agent */
|
|
76
129
|
export const listResourcesActionSchema = callAgentBaseSchema.extend({
|
|
77
|
-
action: z
|
|
130
|
+
action: z
|
|
131
|
+
.literal("list_resources")
|
|
132
|
+
.describe("List all resources available on an agent — docs, auth instructions, config schemas, etc."),
|
|
78
133
|
});
|
|
79
134
|
/** Read resources: fetch one or more resources by URI */
|
|
80
135
|
export const readResourcesActionSchema = callAgentBaseSchema.extend({
|
|
81
|
-
action: z
|
|
136
|
+
action: z
|
|
137
|
+
.literal("read_resources")
|
|
138
|
+
.describe("Fetch one or more resources by URI. Use list_resources first to discover available URIs."),
|
|
82
139
|
uris: z
|
|
83
140
|
.array(z.string())
|
|
84
141
|
.describe("Resource URIs to read (e.g., ['AUTH.md'])"),
|
|
@@ -100,7 +157,6 @@ export const CALL_AGENT_ACTIONS = callAgentRequestSchema.options.map((s) => s.sh
|
|
|
100
157
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
101
158
|
// JSON Schema for MCP (derived from zod)
|
|
102
159
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
103
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
104
160
|
/**
|
|
105
161
|
* Zod schema for the full MCP tool input (wraps request in an outer object).
|
|
106
162
|
* This is the schema that gets converted to JSON Schema for the LLM.
|
|
@@ -114,8 +170,13 @@ export const callAgentToolInputSchema = z.object({
|
|
|
114
170
|
*
|
|
115
171
|
* Fully derived from the zod schemas — no hand-written JSON Schema.
|
|
116
172
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
173
|
+
export const callAgentInputSchema = zodToOpenAiJsonSchema(callAgentToolInputSchema);
|
|
174
|
+
/**
|
|
175
|
+
* Null-tolerant validation schema for `call_agent`.
|
|
176
|
+
* Accepts null values where the JSON Schema promises nullable,
|
|
177
|
+
* converting them to undefined before Zod validation.
|
|
178
|
+
*/
|
|
179
|
+
export const callAgentValidationSchema = nullTolerant(callAgentToolInputSchema);
|
|
119
180
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
120
181
|
// list_agents schema
|
|
121
182
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -133,6 +194,6 @@ export const listAgentsToolInputSchema = z.object({
|
|
|
133
194
|
.optional()
|
|
134
195
|
.describe("Pagination cursor from a previous response's nextCursor field."),
|
|
135
196
|
});
|
|
136
|
-
|
|
137
|
-
export const
|
|
197
|
+
export const listAgentsInputSchema = zodToOpenAiJsonSchema(listAgentsToolInputSchema);
|
|
198
|
+
export const listAgentsValidationSchema = nullTolerant(listAgentsToolInputSchema);
|
|
138
199
|
//# sourceMappingURL=call-agent-schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-agent-schema.js","sourceRoot":"","sources":["../src/call-agent-schema.ts"],"names":[],"mappings":"AAAA;;;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P,uHAAuH,CACxH;IACH,KAAK,EAAE,CAAC;SACL,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CAAC,kDAAkD,CAAC;IAC/D,MAAM,EAAE,CAAC;SACN,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,gEAAgE,CACjE;CACJ,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,qBAAqB,GAAG,qBAAqB,CACxD,yBAAyB,CAC1B,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,YAAY,CACpD,yBAAyB,CAC1B,CAAC"}
|
|
@@ -13,8 +13,64 @@
|
|
|
13
13
|
* Response types live in types.ts (they're output shapes, not validated input).
|
|
14
14
|
*/
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.listAgentsInputSchema = exports.listAgentsToolInputSchema = exports.callAgentInputSchema = exports.callAgentToolInputSchema = exports.CALL_AGENT_ACTIONS = exports.callAgentRequestSchema = exports.readResourcesActionSchema = exports.listResourcesActionSchema = exports.loadActionSchema = exports.describeToolsActionSchema = exports.executeToolActionSchema = exports.askActionSchema = exports.invokeActionSchema = exports.callerTypeSchema = void 0;
|
|
16
|
+
exports.listAgentsValidationSchema = exports.listAgentsInputSchema = exports.listAgentsToolInputSchema = exports.callAgentValidationSchema = exports.callAgentInputSchema = exports.callAgentToolInputSchema = exports.CALL_AGENT_ACTIONS = exports.callAgentRequestSchema = exports.readResourcesActionSchema = exports.listResourcesActionSchema = exports.loadActionSchema = exports.describeToolsActionSchema = exports.executeToolActionSchema = exports.askActionSchema = exports.invokeActionSchema = exports.callerTypeSchema = void 0;
|
|
17
|
+
exports.stripNulls = stripNulls;
|
|
18
|
+
exports.nullTolerant = nullTolerant;
|
|
19
|
+
exports.zodToOpenAiJsonSchema = zodToOpenAiJsonSchema;
|
|
17
20
|
const zod_1 = require("zod");
|
|
21
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
22
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
23
|
+
// OpenAI null-tolerance transform
|
|
24
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
25
|
+
/**
|
|
26
|
+
* Recursively strip null values from an object, converting them to undefined.
|
|
27
|
+
* This is the inverse of zod-to-json-schema's openAi target behavior, which
|
|
28
|
+
* converts .optional() fields to nullable+required in JSON Schema.
|
|
29
|
+
*
|
|
30
|
+
* Used as a z.preprocess() step so that Zod's .optional() (which accepts
|
|
31
|
+
* undefined but not null) works correctly with LLM outputs that send null
|
|
32
|
+
* for "no value" per the OpenAI function calling convention.
|
|
33
|
+
*/
|
|
34
|
+
function stripNulls(obj) {
|
|
35
|
+
if (obj === null)
|
|
36
|
+
return undefined;
|
|
37
|
+
if (Array.isArray(obj))
|
|
38
|
+
return obj.map(stripNulls);
|
|
39
|
+
if (typeof obj === "object") {
|
|
40
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [
|
|
41
|
+
k,
|
|
42
|
+
stripNulls(v),
|
|
43
|
+
]));
|
|
44
|
+
}
|
|
45
|
+
return obj;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Wrap a Zod schema with a preprocess step that converts null → undefined.
|
|
49
|
+
* This makes the schema "null-tolerant" — matching what the OpenAI JSON Schema
|
|
50
|
+
* target promises to LLMs (nullable fields) while keeping Zod's .optional()
|
|
51
|
+
* semantics internally.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const schema = z.object({ name: z.string().optional() });
|
|
56
|
+
* const tolerant = nullTolerant(schema);
|
|
57
|
+
* tolerant.parse({ name: null }); // { name: undefined } — no error
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
function nullTolerant(schema) {
|
|
61
|
+
return zod_1.z.preprocess(stripNulls, schema);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Convert a Zod schema to JSON Schema using the OpenAI target,
|
|
65
|
+
* which makes all optional fields nullable+required.
|
|
66
|
+
*
|
|
67
|
+
* This is the standard way to generate input schemas for MCP tools
|
|
68
|
+
* that will be called by LLMs.
|
|
69
|
+
*/
|
|
70
|
+
function zodToOpenAiJsonSchema(schema) {
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
|
+
return (0, zod_to_json_schema_1.zodToJsonSchema)(schema, { target: "openAi" });
|
|
73
|
+
}
|
|
18
74
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
19
75
|
// Base schemas
|
|
20
76
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -77,11 +133,15 @@ exports.loadActionSchema = callAgentBaseSchema.extend({
|
|
|
77
133
|
});
|
|
78
134
|
/** List resources: discover available resources on an agent */
|
|
79
135
|
exports.listResourcesActionSchema = callAgentBaseSchema.extend({
|
|
80
|
-
action: zod_1.z
|
|
136
|
+
action: zod_1.z
|
|
137
|
+
.literal("list_resources")
|
|
138
|
+
.describe("List all resources available on an agent — docs, auth instructions, config schemas, etc."),
|
|
81
139
|
});
|
|
82
140
|
/** Read resources: fetch one or more resources by URI */
|
|
83
141
|
exports.readResourcesActionSchema = callAgentBaseSchema.extend({
|
|
84
|
-
action: zod_1.z
|
|
142
|
+
action: zod_1.z
|
|
143
|
+
.literal("read_resources")
|
|
144
|
+
.describe("Fetch one or more resources by URI. Use list_resources first to discover available URIs."),
|
|
85
145
|
uris: zod_1.z
|
|
86
146
|
.array(zod_1.z.string())
|
|
87
147
|
.describe("Resource URIs to read (e.g., ['AUTH.md'])"),
|
|
@@ -103,7 +163,6 @@ exports.CALL_AGENT_ACTIONS = exports.callAgentRequestSchema.options.map((s) => s
|
|
|
103
163
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
104
164
|
// JSON Schema for MCP (derived from zod)
|
|
105
165
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
106
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
107
166
|
/**
|
|
108
167
|
* Zod schema for the full MCP tool input (wraps request in an outer object).
|
|
109
168
|
* This is the schema that gets converted to JSON Schema for the LLM.
|
|
@@ -117,8 +176,13 @@ exports.callAgentToolInputSchema = zod_1.z.object({
|
|
|
117
176
|
*
|
|
118
177
|
* Fully derived from the zod schemas — no hand-written JSON Schema.
|
|
119
178
|
*/
|
|
120
|
-
|
|
121
|
-
|
|
179
|
+
exports.callAgentInputSchema = zodToOpenAiJsonSchema(exports.callAgentToolInputSchema);
|
|
180
|
+
/**
|
|
181
|
+
* Null-tolerant validation schema for `call_agent`.
|
|
182
|
+
* Accepts null values where the JSON Schema promises nullable,
|
|
183
|
+
* converting them to undefined before Zod validation.
|
|
184
|
+
*/
|
|
185
|
+
exports.callAgentValidationSchema = nullTolerant(exports.callAgentToolInputSchema);
|
|
122
186
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
123
187
|
// list_agents schema
|
|
124
188
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -136,6 +200,6 @@ exports.listAgentsToolInputSchema = zod_1.z.object({
|
|
|
136
200
|
.optional()
|
|
137
201
|
.describe("Pagination cursor from a previous response's nextCursor field."),
|
|
138
202
|
});
|
|
139
|
-
|
|
140
|
-
exports.
|
|
203
|
+
exports.listAgentsInputSchema = zodToOpenAiJsonSchema(exports.listAgentsToolInputSchema);
|
|
204
|
+
exports.listAgentsValidationSchema = nullTolerant(exports.listAgentsToolInputSchema);
|
|
141
205
|
//# sourceMappingURL=call-agent-schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-agent-schema.js","sourceRoot":"","sources":["../../src/call-agent-schema.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;
|
|
1
|
+
{"version":3,"file":"call-agent-schema.js","sourceRoot":"","sources":["../../src/call-agent-schema.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAkBH,gCAYC;AAeD,oCAEC;AASD,sDAQC;AA9DD,6BAAyC;AACzC,2DAAqD;AAErD,gFAAgF;AAChF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