@dexto/core 1.6.27 → 1.7.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.
Files changed (68) hide show
  1. package/dist/agent/DextoAgent.d.ts +3 -3
  2. package/dist/agent/DextoAgent.d.ts.map +1 -1
  3. package/dist/agent/schemas.cjs +5 -5
  4. package/dist/agent/schemas.d.ts +69 -980
  5. package/dist/agent/schemas.d.ts.map +1 -1
  6. package/dist/agent/schemas.js +5 -5
  7. package/dist/approval/schemas.cjs +6 -6
  8. package/dist/approval/schemas.d.ts +316 -1292
  9. package/dist/approval/schemas.d.ts.map +1 -1
  10. package/dist/approval/schemas.js +6 -6
  11. package/dist/approval/session-approval-store.cjs +1 -1
  12. package/dist/approval/session-approval-store.d.ts +12 -30
  13. package/dist/approval/session-approval-store.d.ts.map +1 -1
  14. package/dist/approval/session-approval-store.js +1 -1
  15. package/dist/llm/providers/local/schemas.d.ts +102 -262
  16. package/dist/llm/providers/local/schemas.d.ts.map +1 -1
  17. package/dist/llm/registry/index.d.ts +5 -3
  18. package/dist/llm/registry/index.d.ts.map +1 -1
  19. package/dist/llm/resolver.cjs +0 -1
  20. package/dist/llm/resolver.d.ts.map +1 -1
  21. package/dist/llm/resolver.js +0 -1
  22. package/dist/llm/schemas.d.ts +95 -199
  23. package/dist/llm/schemas.d.ts.map +1 -1
  24. package/dist/logger/default-logger-factory.d.ts +28 -256
  25. package/dist/logger/default-logger-factory.d.ts.map +1 -1
  26. package/dist/logger/v2/schemas.d.ts +18 -120
  27. package/dist/logger/v2/schemas.d.ts.map +1 -1
  28. package/dist/mcp/schemas.cjs +4 -4
  29. package/dist/mcp/schemas.d.ts +77 -270
  30. package/dist/mcp/schemas.d.ts.map +1 -1
  31. package/dist/mcp/schemas.js +4 -4
  32. package/dist/memory/schemas.d.ts +37 -117
  33. package/dist/memory/schemas.d.ts.map +1 -1
  34. package/dist/prompts/schemas.d.ts +46 -190
  35. package/dist/prompts/schemas.d.ts.map +1 -1
  36. package/dist/resources/schemas.d.ts +14 -68
  37. package/dist/resources/schemas.d.ts.map +1 -1
  38. package/dist/runtime/host-runtime.d.ts +1 -5
  39. package/dist/runtime/host-runtime.d.ts.map +1 -1
  40. package/dist/session/schemas.d.ts +1 -7
  41. package/dist/session/schemas.d.ts.map +1 -1
  42. package/dist/systemPrompt/schemas.cjs +2 -10
  43. package/dist/systemPrompt/schemas.d.ts +53 -343
  44. package/dist/systemPrompt/schemas.d.ts.map +1 -1
  45. package/dist/systemPrompt/schemas.js +2 -10
  46. package/dist/telemetry/schemas.cjs +1 -1
  47. package/dist/telemetry/schemas.d.ts +9 -44
  48. package/dist/telemetry/schemas.d.ts.map +1 -1
  49. package/dist/telemetry/schemas.js +1 -1
  50. package/dist/tools/schemas.cjs +1 -1
  51. package/dist/tools/schemas.d.ts +19 -62
  52. package/dist/tools/schemas.d.ts.map +1 -1
  53. package/dist/tools/schemas.js +1 -1
  54. package/dist/tools/session-tool-preferences-store.d.ts +3 -9
  55. package/dist/tools/session-tool-preferences-store.d.ts.map +1 -1
  56. package/dist/utils/result.cjs +11 -8
  57. package/dist/utils/result.d.ts +6 -6
  58. package/dist/utils/result.d.ts.map +1 -1
  59. package/dist/utils/result.js +12 -9
  60. package/dist/utils/schema.cjs +6 -2
  61. package/dist/utils/schema.d.ts +2 -7
  62. package/dist/utils/schema.d.ts.map +1 -1
  63. package/dist/utils/schema.js +6 -2
  64. package/dist/utils/zod-schema-converter.cjs +66 -66
  65. package/dist/utils/zod-schema-converter.d.ts +3 -2
  66. package/dist/utils/zod-schema-converter.d.ts.map +1 -1
  67. package/dist/utils/zod-schema-converter.js +66 -66
  68. package/package.json +4 -5
@@ -6,86 +6,43 @@ export type AllowedToolsStorageType = (typeof ALLOWED_TOOLS_STORAGE_TYPES)[numbe
6
6
  export declare const DEFAULT_PERMISSIONS_MODE: PermissionsMode;
7
7
  export declare const DEFAULT_ALLOWED_TOOLS_STORAGE: AllowedToolsStorageType;
8
8
  export declare const ToolPoliciesSchema: z.ZodDefault<z.ZodObject<{
9
- alwaysAllow: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
10
- alwaysDeny: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
11
- }, "strict", z.ZodTypeAny, {
12
- alwaysAllow: string[];
13
- alwaysDeny: string[];
14
- }, {
15
- alwaysAllow?: string[] | undefined;
16
- alwaysDeny?: string[] | undefined;
17
- }>>;
9
+ alwaysAllow: z.ZodDefault<z.ZodArray<z.ZodString>>;
10
+ alwaysDeny: z.ZodDefault<z.ZodArray<z.ZodString>>;
11
+ }, z.core.$strict>>;
18
12
  export type ToolPolicies = z.output<typeof ToolPoliciesSchema>;
19
13
  export declare const PermissionsConfigSchema: z.ZodObject<{
20
- mode: z.ZodDefault<z.ZodEnum<["manual", "auto-approve", "auto-deny"]>>;
14
+ mode: z.ZodDefault<z.ZodEnum<{
15
+ manual: "manual";
16
+ "auto-approve": "auto-approve";
17
+ "auto-deny": "auto-deny";
18
+ }>>;
21
19
  timeout: z.ZodOptional<z.ZodNumber>;
22
- allowedToolsStorage: z.ZodDefault<z.ZodEnum<["memory", "storage"]>>;
23
- toolPolicies: z.ZodDefault<z.ZodObject<{
24
- alwaysAllow: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
25
- alwaysDeny: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
26
- }, "strict", z.ZodTypeAny, {
27
- alwaysAllow: string[];
28
- alwaysDeny: string[];
29
- }, {
30
- alwaysAllow?: string[] | undefined;
31
- alwaysDeny?: string[] | undefined;
20
+ allowedToolsStorage: z.ZodDefault<z.ZodEnum<{
21
+ storage: "storage";
22
+ memory: "memory";
32
23
  }>>;
33
- }, "strict", z.ZodTypeAny, {
34
- mode: "manual" | "auto-approve" | "auto-deny";
35
- allowedToolsStorage: "storage" | "memory";
36
- toolPolicies: {
37
- alwaysAllow: string[];
38
- alwaysDeny: string[];
39
- };
40
- timeout?: number | undefined;
41
- }, {
42
- timeout?: number | undefined;
43
- mode?: "manual" | "auto-approve" | "auto-deny" | undefined;
44
- allowedToolsStorage?: "storage" | "memory" | undefined;
45
- toolPolicies?: {
46
- alwaysAllow?: string[] | undefined;
47
- alwaysDeny?: string[] | undefined;
48
- } | undefined;
49
- }>;
24
+ toolPolicies: z.ZodDefault<z.ZodObject<{
25
+ alwaysAllow: z.ZodDefault<z.ZodArray<z.ZodString>>;
26
+ alwaysDeny: z.ZodDefault<z.ZodArray<z.ZodString>>;
27
+ }, z.core.$strict>>;
28
+ }, z.core.$strict>;
50
29
  export type PermissionsConfig = z.input<typeof PermissionsConfigSchema>;
51
30
  export type ValidatedPermissionsConfig = z.output<typeof PermissionsConfigSchema>;
52
31
  export declare const ElicitationConfigSchema: z.ZodObject<{
53
32
  enabled: z.ZodDefault<z.ZodBoolean>;
54
33
  timeout: z.ZodOptional<z.ZodNumber>;
55
- }, "strict", z.ZodTypeAny, {
56
- enabled: boolean;
57
- timeout?: number | undefined;
58
- }, {
59
- timeout?: number | undefined;
60
- enabled?: boolean | undefined;
61
- }>;
34
+ }, z.core.$strict>;
62
35
  export type ElicitationConfig = z.input<typeof ElicitationConfigSchema>;
63
36
  export type ValidatedElicitationConfig = z.output<typeof ElicitationConfigSchema>;
64
37
  export declare const ToolLimitsSchema: z.ZodObject<{
65
38
  maxOutputChars: z.ZodOptional<z.ZodNumber>;
66
39
  maxLines: z.ZodOptional<z.ZodNumber>;
67
40
  maxLineLength: z.ZodOptional<z.ZodNumber>;
68
- }, "strict", z.ZodTypeAny, {
69
- maxOutputChars?: number | undefined;
70
- maxLines?: number | undefined;
71
- maxLineLength?: number | undefined;
72
- }, {
73
- maxOutputChars?: number | undefined;
74
- maxLines?: number | undefined;
75
- maxLineLength?: number | undefined;
76
- }>;
41
+ }, z.core.$strict>;
77
42
  export declare const ToolsConfigSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
78
43
  maxOutputChars: z.ZodOptional<z.ZodNumber>;
79
44
  maxLines: z.ZodOptional<z.ZodNumber>;
80
45
  maxLineLength: z.ZodOptional<z.ZodNumber>;
81
- }, "strict", z.ZodTypeAny, {
82
- maxOutputChars?: number | undefined;
83
- maxLines?: number | undefined;
84
- maxLineLength?: number | undefined;
85
- }, {
86
- maxOutputChars?: number | undefined;
87
- maxLines?: number | undefined;
88
- maxLineLength?: number | undefined;
89
- }>>;
46
+ }, z.core.$strict>>;
90
47
  export type ToolsConfig = z.output<typeof ToolsConfigSchema>;
91
48
  //# sourceMappingURL=schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/tools/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,iBAAiB,kDAAmD,CAAC;AAClF,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,eAAO,MAAM,2BAA2B,gCAAiC,CAAC;AAC1E,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnF,eAAO,MAAM,wBAAwB,EAAE,eAAgC,CAAC;AACxE,eAAO,MAAM,6BAA6B,EAAE,uBAAmC,CAAC;AAGhF,eAAO,MAAM,kBAAkB;;;;;;;;;GAiB2B,CAAC;AAE3D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE/D,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BwB,CAAC;AAE7D,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAGlF,eAAO,MAAM,uBAAuB;;;;;;;;;EAoB/B,CAAC;AAEN,MAAM,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iB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAGlF,eAAO,MAAM,gBAAgB;;;;kBAShB,CAAC;AAEd,eAAO,MAAM,iBAAiB;;;;mBAEgB,CAAC;AAE/C,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
@@ -41,7 +41,7 @@ const ToolLimitsSchema = z.object({
41
41
  maxLines: z.number().optional().describe("Maximum number of lines for tool output"),
42
42
  maxLineLength: z.number().optional().describe("Maximum length of a single line")
43
43
  }).strict();
44
- const ToolsConfigSchema = z.record(ToolLimitsSchema).describe("Per-tool configuration limits");
44
+ const ToolsConfigSchema = z.record(z.string(), ToolLimitsSchema).describe("Per-tool configuration limits");
45
45
  export {
46
46
  ALLOWED_TOOLS_STORAGE_TYPES,
47
47
  DEFAULT_ALLOWED_TOOLS_STORAGE,
@@ -2,15 +2,9 @@ import { z } from 'zod';
2
2
  import type { StorageManager } from '../storage/index.js';
3
3
  import type { Logger } from '../logger/v2/types.js';
4
4
  declare const SessionToolPreferencesSchema: z.ZodObject<{
5
- userAutoApproveTools: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
6
- disabledTools: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
7
- }, "strict", z.ZodTypeAny, {
8
- userAutoApproveTools: string[];
9
- disabledTools: string[];
10
- }, {
11
- userAutoApproveTools?: string[] | undefined;
12
- disabledTools?: string[] | undefined;
13
- }>;
5
+ userAutoApproveTools: z.ZodDefault<z.ZodArray<z.ZodString>>;
6
+ disabledTools: z.ZodDefault<z.ZodArray<z.ZodString>>;
7
+ }, z.core.$strict>;
14
8
  export type SessionToolPreferences = z.output<typeof SessionToolPreferencesSchema>;
15
9
  export declare class SessionToolPreferencesStore {
16
10
  private readonly storageManager;
@@ -1 +1 @@
1
- {"version":3,"file":"session-tool-preferences-store.d.ts","sourceRoot":"","sources":["../../src/tools/session-tool-preferences-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,QAAA,MAAM,4BAA4B;;;;;;;;;EAKrB,CAAC;AAEd,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAOnF,qBAAa,2BAA2B;IAIhC,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJ3B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAGpB,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,MAAM,EAC/B,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAO;IAMzC,OAAO,CAAC,QAAQ;IAIV,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAiBxD,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3E,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ9C,OAAO,CAAC,gBAAgB;CAY3B"}
1
+ {"version":3,"file":"session-tool-preferences-store.d.ts","sourceRoot":"","sources":["../../src/tools/session-tool-preferences-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,QAAA,MAAM,4BAA4B;;;kBAKrB,CAAC;AAEd,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAOnF,qBAAa,2BAA2B;IAIhC,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJ3B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAGpB,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,MAAM,EAC/B,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAO;IAMzC,OAAO,CAAC,QAAQ;IAIV,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAiBxD,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3E,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ9C,OAAO,CAAC,gBAAgB;CAY3B"}
@@ -87,13 +87,16 @@ function splitIssues(issues) {
87
87
  }
88
88
  function zodToIssues(err, severity = "error") {
89
89
  const issues = [];
90
- for (const e of err.errors) {
91
- if (e.code === "invalid_union" && e.unionErrors) {
92
- const unionErrors = e.unionErrors;
90
+ const normalizePath = (path) => path.filter((segment) => {
91
+ return typeof segment === "string" || typeof segment === "number";
92
+ });
93
+ for (const e of err.issues) {
94
+ if (e.code === "invalid_union" && "errors" in e) {
95
+ const unionErrors = e.errors;
93
96
  let hasCollectedErrors = false;
94
- for (const unionError of unionErrors) {
95
- if (unionError && unionError.errors && unionError.errors.length > 0) {
96
- issues.push(...zodToIssues(unionError, severity));
97
+ for (const unionIssueSet of unionErrors) {
98
+ if (unionIssueSet.length > 0) {
99
+ issues.push(...zodToIssues(new import_zod.ZodError(unionIssueSet), severity));
97
100
  hasCollectedErrors = true;
98
101
  }
99
102
  }
@@ -104,7 +107,7 @@ function zodToIssues(err, severity = "error") {
104
107
  message: e.message,
105
108
  scope: params.scope ?? import_types.ErrorScope.AGENT,
106
109
  type: params.type ?? import_types.ErrorType.USER,
107
- path: e.path,
110
+ path: normalizePath(e.path),
108
111
  severity,
109
112
  context: params
110
113
  });
@@ -116,7 +119,7 @@ function zodToIssues(err, severity = "error") {
116
119
  message: e.message,
117
120
  scope: params.scope ?? import_types.ErrorScope.AGENT,
118
121
  type: params.type ?? import_types.ErrorType.USER,
119
- path: e.path,
122
+ path: normalizePath(e.path),
120
123
  severity,
121
124
  context: params
122
125
  });
@@ -1,11 +1,11 @@
1
- import { z, type ZodError } from 'zod';
1
+ import { z, ZodError } from 'zod';
2
2
  import type { Issue } from '../errors/types.js';
3
3
  /** Trim and require non-empty after trim */
4
- export declare const NonEmptyTrimmed: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
5
- export declare const OptionalURL: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>, string | undefined, string>>;
6
- export declare const EnvExpandedString: (env?: Record<string, string | undefined>) => z.ZodEffects<z.ZodString, string, string>;
7
- export declare const NonEmptyEnvExpandedString: (env?: Record<string, string | undefined>) => z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
8
- export declare const RequiredEnvURL: (env?: Record<string, string | undefined>) => z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
4
+ export declare const NonEmptyTrimmed: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
5
+ export declare const OptionalURL: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<string | undefined, string>>>;
6
+ export declare const EnvExpandedString: (env?: Record<string, string | undefined>) => z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
7
+ export declare const NonEmptyEnvExpandedString: (env?: Record<string, string | undefined>) => z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
8
+ export declare const RequiredEnvURL: (env?: Record<string, string | undefined>) => z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
9
9
  /**
10
10
  * A discriminated union result type that can be either successful or failed
11
11
  * Provides type safety by ensuring data is only available on success
@@ -1 +1 @@
1
- {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/utils/result.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,KAAK,QAAQ,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,KAAK,EAAkB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAGhE,4CAA4C;AAC5C,eAAO,MAAM,eAAe,yEAG6B,CAAC;AAc1D,eAAO,MAAM,WAAW,kIAKT,CAAC;AAGhB,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,8CAUpE,CAAC;AAGP,eAAO,MAAM,yBAAyB,GAAI,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,4EAG5E,CAAC;AAGP,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,4EAWlE,CAAC;AAEN;;;;;GAKG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,IAC3B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;CAAE,GACzC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;CAAE,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,EAAE,GAAI,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,MAAM,CAAC,EAAE,SAAQ,KAAK,CAAC,CAAC,CAAC,EAAO,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAI/E,CAAC;AAEH;;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YTZNU.js";
2
- import { z } from "zod";
2
+ import { z, ZodError } from "zod";
3
3
  import { ErrorScope, ErrorType } from "../errors/types.js";
4
4
  const NonEmptyTrimmed = z.string().transform((s) => s.trim()).refine((s) => s.length > 0, { message: "Required" });
5
5
  const ALLOWED_URL_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "codex:"]);
@@ -56,13 +56,16 @@ function splitIssues(issues) {
56
56
  }
57
57
  function zodToIssues(err, severity = "error") {
58
58
  const issues = [];
59
- for (const e of err.errors) {
60
- if (e.code === "invalid_union" && e.unionErrors) {
61
- const unionErrors = e.unionErrors;
59
+ const normalizePath = (path) => path.filter((segment) => {
60
+ return typeof segment === "string" || typeof segment === "number";
61
+ });
62
+ for (const e of err.issues) {
63
+ if (e.code === "invalid_union" && "errors" in e) {
64
+ const unionErrors = e.errors;
62
65
  let hasCollectedErrors = false;
63
- for (const unionError of unionErrors) {
64
- if (unionError && unionError.errors && unionError.errors.length > 0) {
65
- issues.push(...zodToIssues(unionError, severity));
66
+ for (const unionIssueSet of unionErrors) {
67
+ if (unionIssueSet.length > 0) {
68
+ issues.push(...zodToIssues(new ZodError(unionIssueSet), severity));
66
69
  hasCollectedErrors = true;
67
70
  }
68
71
  }
@@ -73,7 +76,7 @@ function zodToIssues(err, severity = "error") {
73
76
  message: e.message,
74
77
  scope: params.scope ?? ErrorScope.AGENT,
75
78
  type: params.type ?? ErrorType.USER,
76
- path: e.path,
79
+ path: normalizePath(e.path),
77
80
  severity,
78
81
  context: params
79
82
  });
@@ -85,7 +88,7 @@ function zodToIssues(err, severity = "error") {
85
88
  message: e.message,
86
89
  scope: params.scope ?? ErrorScope.AGENT,
87
90
  type: params.type ?? ErrorType.USER,
88
- path: e.path,
91
+ path: normalizePath(e.path),
89
92
  severity,
90
93
  context: params
91
94
  });
@@ -21,10 +21,14 @@ __export(schema_exports, {
21
21
  convertZodSchemaToJsonSchema: () => convertZodSchemaToJsonSchema
22
22
  });
23
23
  module.exports = __toCommonJS(schema_exports);
24
- var import_zod_to_json_schema = require("zod-to-json-schema");
24
+ var import_zod = require("zod");
25
25
  function convertZodSchemaToJsonSchema(zodSchema, logger) {
26
26
  try {
27
- const converted = (0, import_zod_to_json_schema.zodToJsonSchema)(zodSchema);
27
+ const converted = import_zod.z.toJSONSchema(zodSchema, {
28
+ io: "input",
29
+ target: "draft-07",
30
+ unrepresentable: "any"
31
+ });
28
32
  if (converted && typeof converted === "object") {
29
33
  return converted;
30
34
  }
@@ -1,14 +1,9 @@
1
+ import { z } from 'zod';
1
2
  import type { JSONSchema7 } from 'json-schema';
2
- import type { ZodSchema } from 'zod';
3
3
  import type { Logger } from '../logger/v2/types.js';
4
4
  /**
5
5
  * Convert Zod schema to JSON Schema format for tool parameters
6
6
  *
7
- * TODO: Replace zod-to-json-schema with Zod v4 native JSON schema support
8
- * The zod-to-json-schema package is deprecated and adds ~19MB due to a packaging bug
9
- * (includes test files with full Zod copies in dist-test-v3 and dist-test-v4 folders).
10
- * Zod v4 has native toJsonSchema() support - migrate when upgrading to Zod v4.
11
- * See: https://github.com/StefanTerdell/zod-to-json-schema
12
7
  */
13
- export declare function convertZodSchemaToJsonSchema(zodSchema: ZodSchema, logger: Logger): JSONSchema7;
8
+ export declare function convertZodSchemaToJsonSchema(zodSchema: z.ZodType, logger: Logger): JSONSchema7;
14
9
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/utils/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAoB9F"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAuB9F"}
@@ -1,8 +1,12 @@
1
1
  import "../chunk-PTJYTZNU.js";
2
- import { zodToJsonSchema } from "zod-to-json-schema";
2
+ import { z } from "zod";
3
3
  function convertZodSchemaToJsonSchema(zodSchema, logger) {
4
4
  try {
5
- const converted = zodToJsonSchema(zodSchema);
5
+ const converted = z.toJSONSchema(zodSchema, {
6
+ io: "input",
7
+ target: "draft-07",
8
+ unrepresentable: "any"
9
+ });
6
10
  if (converted && typeof converted === "object") {
7
11
  return converted;
8
12
  }
@@ -23,84 +23,84 @@ __export(zod_schema_converter_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(zod_schema_converter_exports);
25
25
  var import_zod = require("zod");
26
+ function isJsonSchemaObject(schema) {
27
+ return !!schema && typeof schema === "object" && !Array.isArray(schema);
28
+ }
29
+ function getJsonSchemaTypes(schema) {
30
+ const { type } = schema;
31
+ if (Array.isArray(type)) {
32
+ return type;
33
+ }
34
+ return type ? [type] : [];
35
+ }
36
+ function getJsonSchemaType(schema) {
37
+ const types = getJsonSchemaTypes(schema);
38
+ return types.find((type) => type !== "null") ?? types[0];
39
+ }
40
+ function hasNullableJsonSchemaType(schema) {
41
+ return getJsonSchemaTypes(schema).includes("null");
42
+ }
43
+ function getZodTypeForJsonSchemaType(propSchema, type) {
44
+ switch (type) {
45
+ case "string":
46
+ return import_zod.z.string();
47
+ case "number":
48
+ return import_zod.z.number();
49
+ case "integer":
50
+ return import_zod.z.number().int();
51
+ case "boolean":
52
+ return import_zod.z.boolean();
53
+ case "object":
54
+ return import_zod.z.object(jsonSchemaToZodShape(propSchema));
55
+ case "array": {
56
+ const itemSchema = getPropertySchema(propSchema.items);
57
+ return import_zod.z.array(itemSchema ? getZodTypeFromProperty(itemSchema) : import_zod.z.unknown());
58
+ }
59
+ case "null":
60
+ return import_zod.z.null();
61
+ default:
62
+ return import_zod.z.unknown();
63
+ }
64
+ }
65
+ function getPropertySchema(schema) {
66
+ return isJsonSchemaObject(schema) ? schema : null;
67
+ }
26
68
  function jsonSchemaToZodShape(jsonSchema) {
27
- if (!jsonSchema || typeof jsonSchema !== "object" || jsonSchema.type !== "object") {
69
+ if (!isJsonSchemaObject(jsonSchema) || getJsonSchemaType(jsonSchema) !== "object") {
28
70
  return {};
29
71
  }
30
72
  const shape = {};
31
- if (jsonSchema.properties) {
32
- for (const [key, property] of Object.entries(jsonSchema.properties)) {
33
- const propSchema = property;
34
- let zodType;
35
- switch (propSchema.type) {
36
- case "string":
37
- zodType = import_zod.z.string();
38
- break;
39
- case "number":
40
- zodType = import_zod.z.number();
41
- break;
42
- case "integer":
43
- zodType = import_zod.z.number().int();
44
- break;
45
- case "boolean":
46
- zodType = import_zod.z.boolean();
47
- break;
48
- case "array":
49
- if (propSchema.items) {
50
- const itemType = getZodTypeFromProperty(propSchema.items);
51
- zodType = import_zod.z.array(itemType);
52
- } else {
53
- zodType = import_zod.z.array(import_zod.z.any());
54
- }
55
- break;
56
- case "object":
57
- zodType = import_zod.z.object(jsonSchemaToZodShape(propSchema));
58
- break;
59
- default:
60
- zodType = import_zod.z.any();
61
- }
62
- if (propSchema.description) {
63
- zodType._def.description = propSchema.description;
64
- zodType = zodType.describe(propSchema.description);
65
- }
66
- if (!jsonSchema.required || !jsonSchema.required.includes(key)) {
67
- zodType = zodType.optional();
68
- }
69
- shape[key] = zodType;
73
+ const properties = jsonSchema.properties ?? {};
74
+ for (const [key, property] of Object.entries(properties)) {
75
+ const propSchema = getPropertySchema(property);
76
+ let zodType = propSchema ? getZodTypeFromProperty(propSchema) : import_zod.z.unknown();
77
+ if (!Array.isArray(jsonSchema.required) || !jsonSchema.required.includes(key)) {
78
+ zodType = zodType.optional();
70
79
  }
80
+ shape[key] = zodType;
71
81
  }
72
82
  return shape;
73
83
  }
74
84
  function getZodTypeFromProperty(propSchema) {
85
+ const nonNullTypes = getJsonSchemaTypes(propSchema).filter(
86
+ (type) => type !== "null"
87
+ );
75
88
  let zodType;
76
- switch (propSchema.type) {
77
- case "string":
78
- zodType = import_zod.z.string();
79
- break;
80
- case "number":
81
- zodType = import_zod.z.number();
82
- break;
83
- case "integer":
84
- zodType = import_zod.z.number().int();
85
- break;
86
- case "boolean":
87
- zodType = import_zod.z.boolean();
88
- break;
89
- case "object":
90
- zodType = import_zod.z.object(jsonSchemaToZodShape(propSchema));
91
- break;
92
- case "array":
93
- if (propSchema.items) {
94
- zodType = import_zod.z.array(getZodTypeFromProperty(propSchema.items));
95
- } else {
96
- zodType = import_zod.z.array(import_zod.z.any());
97
- }
98
- break;
99
- default:
100
- zodType = import_zod.z.any();
89
+ if (nonNullTypes.length === 0) {
90
+ zodType = hasNullableJsonSchemaType(propSchema) ? import_zod.z.null() : import_zod.z.unknown();
91
+ } else {
92
+ const zodTypes = nonNullTypes.map((type) => getZodTypeForJsonSchemaType(propSchema, type));
93
+ const [firstType, secondType, ...restTypes] = zodTypes;
94
+ if (!firstType) {
95
+ zodType = import_zod.z.unknown();
96
+ } else {
97
+ zodType = secondType ? import_zod.z.union([firstType, secondType, ...restTypes]) : firstType;
98
+ }
99
+ }
100
+ if (hasNullableJsonSchemaType(propSchema) && nonNullTypes.length > 0) {
101
+ zodType = zodType.nullable();
101
102
  }
102
103
  if (propSchema.description) {
103
- zodType._def.description = propSchema.description;
104
104
  zodType = zodType.describe(propSchema.description);
105
105
  }
106
106
  return zodType;
@@ -1,11 +1,12 @@
1
1
  import { z } from 'zod';
2
+ import type { JSONSchema7 } from 'json-schema';
2
3
  /**
3
4
  * Converts a JSON Schema object to a Zod raw shape.
4
5
  * This is a simplified converter that handles common MCP tool schemas.
5
6
  */
6
- export declare function jsonSchemaToZodShape(jsonSchema: any): z.ZodRawShape;
7
+ export declare function jsonSchemaToZodShape(jsonSchema: unknown): z.ZodRawShape;
7
8
  /**
8
9
  * Helper function to get a Zod type from a property schema
9
10
  */
10
- export declare function getZodTypeFromProperty(propSchema: any): z.ZodTypeAny;
11
+ export declare function getZodTypeFromProperty(propSchema: JSONSchema7): z.ZodType;
11
12
  //# sourceMappingURL=zod-schema-converter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"zod-schema-converter.d.ts","sourceRoot":"","sources":["../../src/utils/zod-schema-converter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,GAAG,GAAG,CAAC,CAAC,WAAW,CAwDnE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,GAAG,GAAG,CAAC,CAAC,UAAU,CAsCpE"}
1
+ {"version":3,"file":"zod-schema-converter.d.ts","sourceRoot":"","sources":["../../src/utils/zod-schema-converter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAA8C,MAAM,aAAa,CAAC;AAuD3F;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,OAAO,GAAG,CAAC,CAAC,WAAW,CAoBvE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,WAAW,GAAG,CAAC,CAAC,OAAO,CA2BzE"}
@@ -1,83 +1,83 @@
1
1
  import "../chunk-PTJYTZNU.js";
2
2
  import { z } from "zod";
3
+ function isJsonSchemaObject(schema) {
4
+ return !!schema && typeof schema === "object" && !Array.isArray(schema);
5
+ }
6
+ function getJsonSchemaTypes(schema) {
7
+ const { type } = schema;
8
+ if (Array.isArray(type)) {
9
+ return type;
10
+ }
11
+ return type ? [type] : [];
12
+ }
13
+ function getJsonSchemaType(schema) {
14
+ const types = getJsonSchemaTypes(schema);
15
+ return types.find((type) => type !== "null") ?? types[0];
16
+ }
17
+ function hasNullableJsonSchemaType(schema) {
18
+ return getJsonSchemaTypes(schema).includes("null");
19
+ }
20
+ function getZodTypeForJsonSchemaType(propSchema, type) {
21
+ switch (type) {
22
+ case "string":
23
+ return z.string();
24
+ case "number":
25
+ return z.number();
26
+ case "integer":
27
+ return z.number().int();
28
+ case "boolean":
29
+ return z.boolean();
30
+ case "object":
31
+ return z.object(jsonSchemaToZodShape(propSchema));
32
+ case "array": {
33
+ const itemSchema = getPropertySchema(propSchema.items);
34
+ return z.array(itemSchema ? getZodTypeFromProperty(itemSchema) : z.unknown());
35
+ }
36
+ case "null":
37
+ return z.null();
38
+ default:
39
+ return z.unknown();
40
+ }
41
+ }
42
+ function getPropertySchema(schema) {
43
+ return isJsonSchemaObject(schema) ? schema : null;
44
+ }
3
45
  function jsonSchemaToZodShape(jsonSchema) {
4
- if (!jsonSchema || typeof jsonSchema !== "object" || jsonSchema.type !== "object") {
46
+ if (!isJsonSchemaObject(jsonSchema) || getJsonSchemaType(jsonSchema) !== "object") {
5
47
  return {};
6
48
  }
7
49
  const shape = {};
8
- if (jsonSchema.properties) {
9
- for (const [key, property] of Object.entries(jsonSchema.properties)) {
10
- const propSchema = property;
11
- let zodType;
12
- switch (propSchema.type) {
13
- case "string":
14
- zodType = z.string();
15
- break;
16
- case "number":
17
- zodType = z.number();
18
- break;
19
- case "integer":
20
- zodType = z.number().int();
21
- break;
22
- case "boolean":
23
- zodType = z.boolean();
24
- break;
25
- case "array":
26
- if (propSchema.items) {
27
- const itemType = getZodTypeFromProperty(propSchema.items);
28
- zodType = z.array(itemType);
29
- } else {
30
- zodType = z.array(z.any());
31
- }
32
- break;
33
- case "object":
34
- zodType = z.object(jsonSchemaToZodShape(propSchema));
35
- break;
36
- default:
37
- zodType = z.any();
38
- }
39
- if (propSchema.description) {
40
- zodType._def.description = propSchema.description;
41
- zodType = zodType.describe(propSchema.description);
42
- }
43
- if (!jsonSchema.required || !jsonSchema.required.includes(key)) {
44
- zodType = zodType.optional();
45
- }
46
- shape[key] = zodType;
50
+ const properties = jsonSchema.properties ?? {};
51
+ for (const [key, property] of Object.entries(properties)) {
52
+ const propSchema = getPropertySchema(property);
53
+ let zodType = propSchema ? getZodTypeFromProperty(propSchema) : z.unknown();
54
+ if (!Array.isArray(jsonSchema.required) || !jsonSchema.required.includes(key)) {
55
+ zodType = zodType.optional();
47
56
  }
57
+ shape[key] = zodType;
48
58
  }
49
59
  return shape;
50
60
  }
51
61
  function getZodTypeFromProperty(propSchema) {
62
+ const nonNullTypes = getJsonSchemaTypes(propSchema).filter(
63
+ (type) => type !== "null"
64
+ );
52
65
  let zodType;
53
- switch (propSchema.type) {
54
- case "string":
55
- zodType = z.string();
56
- break;
57
- case "number":
58
- zodType = z.number();
59
- break;
60
- case "integer":
61
- zodType = z.number().int();
62
- break;
63
- case "boolean":
64
- zodType = z.boolean();
65
- break;
66
- case "object":
67
- zodType = z.object(jsonSchemaToZodShape(propSchema));
68
- break;
69
- case "array":
70
- if (propSchema.items) {
71
- zodType = z.array(getZodTypeFromProperty(propSchema.items));
72
- } else {
73
- zodType = z.array(z.any());
74
- }
75
- break;
76
- default:
77
- zodType = z.any();
66
+ if (nonNullTypes.length === 0) {
67
+ zodType = hasNullableJsonSchemaType(propSchema) ? z.null() : z.unknown();
68
+ } else {
69
+ const zodTypes = nonNullTypes.map((type) => getZodTypeForJsonSchemaType(propSchema, type));
70
+ const [firstType, secondType, ...restTypes] = zodTypes;
71
+ if (!firstType) {
72
+ zodType = z.unknown();
73
+ } else {
74
+ zodType = secondType ? z.union([firstType, secondType, ...restTypes]) : firstType;
75
+ }
76
+ }
77
+ if (hasNullableJsonSchemaType(propSchema) && nonNullTypes.length > 0) {
78
+ zodType = zodType.nullable();
78
79
  }
79
80
  if (propSchema.description) {
80
- zodType._def.description = propSchema.description;
81
81
  zodType = zodType.describe(propSchema.description);
82
82
  }
83
83
  return zodType;