@langchain/core 1.1.29 → 1.1.31

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 (122) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/language_models/base.cjs +1 -1
  3. package/dist/language_models/base.cjs.map +1 -1
  4. package/dist/language_models/base.d.cts +6 -0
  5. package/dist/language_models/base.d.cts.map +1 -1
  6. package/dist/language_models/base.d.ts +6 -0
  7. package/dist/language_models/base.d.ts.map +1 -1
  8. package/dist/language_models/base.js +1 -1
  9. package/dist/language_models/base.js.map +1 -1
  10. package/dist/language_models/chat_models.cjs +8 -23
  11. package/dist/language_models/chat_models.cjs.map +1 -1
  12. package/dist/language_models/chat_models.d.cts +6 -0
  13. package/dist/language_models/chat_models.d.cts.map +1 -1
  14. package/dist/language_models/chat_models.d.ts +6 -0
  15. package/dist/language_models/chat_models.d.ts.map +1 -1
  16. package/dist/language_models/chat_models.js +9 -24
  17. package/dist/language_models/chat_models.js.map +1 -1
  18. package/dist/language_models/structured_output.cjs +88 -0
  19. package/dist/language_models/structured_output.cjs.map +1 -0
  20. package/dist/language_models/structured_output.d.cts +46 -0
  21. package/dist/language_models/structured_output.d.cts.map +1 -0
  22. package/dist/language_models/structured_output.d.ts +50 -0
  23. package/dist/language_models/structured_output.d.ts.map +1 -0
  24. package/dist/language_models/structured_output.js +79 -0
  25. package/dist/language_models/structured_output.js.map +1 -0
  26. package/dist/load/import_map.cjs +10 -4
  27. package/dist/load/import_map.cjs.map +1 -1
  28. package/dist/load/import_map.js +12 -6
  29. package/dist/load/import_map.js.map +1 -1
  30. package/dist/messages/base.cjs.map +1 -1
  31. package/dist/messages/base.d.cts +2 -2
  32. package/dist/messages/base.d.cts.map +1 -1
  33. package/dist/messages/base.d.ts +2 -2
  34. package/dist/messages/base.d.ts.map +1 -1
  35. package/dist/messages/base.js.map +1 -1
  36. package/dist/output_parsers/index.cjs +4 -1
  37. package/dist/output_parsers/index.cjs.map +1 -1
  38. package/dist/output_parsers/index.d.cts +2 -1
  39. package/dist/output_parsers/index.d.ts +2 -1
  40. package/dist/output_parsers/index.js +4 -2
  41. package/dist/output_parsers/index.js.map +1 -1
  42. package/dist/output_parsers/openai_tools/index.d.cts +2 -2
  43. package/dist/output_parsers/openai_tools/index.d.ts +2 -2
  44. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +8 -1
  45. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs.map +1 -1
  46. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts +6 -1
  47. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts.map +1 -1
  48. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +6 -1
  49. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts.map +1 -1
  50. package/dist/output_parsers/openai_tools/json_output_tools_parsers.js +8 -1
  51. package/dist/output_parsers/openai_tools/json_output_tools_parsers.js.map +1 -1
  52. package/dist/output_parsers/standard_schema.cjs +40 -0
  53. package/dist/output_parsers/standard_schema.cjs.map +1 -0
  54. package/dist/output_parsers/standard_schema.d.cts +16 -0
  55. package/dist/output_parsers/standard_schema.d.cts.map +1 -0
  56. package/dist/output_parsers/standard_schema.d.ts +16 -0
  57. package/dist/output_parsers/standard_schema.d.ts.map +1 -0
  58. package/dist/output_parsers/standard_schema.js +40 -0
  59. package/dist/output_parsers/standard_schema.js.map +1 -0
  60. package/dist/runnables/base.cjs +1 -1
  61. package/dist/runnables/base.cjs.map +1 -1
  62. package/dist/runnables/base.js +2 -2
  63. package/dist/runnables/base.js.map +1 -1
  64. package/dist/testing/fake_model_builder.cjs +174 -0
  65. package/dist/testing/fake_model_builder.cjs.map +1 -0
  66. package/dist/testing/fake_model_builder.d.cts +87 -0
  67. package/dist/testing/fake_model_builder.d.cts.map +1 -0
  68. package/dist/testing/fake_model_builder.d.ts +88 -0
  69. package/dist/testing/fake_model_builder.d.ts.map +1 -0
  70. package/dist/testing/fake_model_builder.js +174 -0
  71. package/dist/testing/fake_model_builder.js.map +1 -0
  72. package/dist/testing/index.cjs +41 -0
  73. package/dist/testing/index.cjs.map +1 -0
  74. package/dist/testing/index.d.cts +3 -0
  75. package/dist/testing/index.d.ts +3 -0
  76. package/dist/testing/index.js +23 -0
  77. package/dist/testing/index.js.map +1 -0
  78. package/dist/testing/matchers.cjs +213 -0
  79. package/dist/testing/matchers.cjs.map +1 -0
  80. package/dist/testing/matchers.d.cts +94 -0
  81. package/dist/testing/matchers.d.cts.map +1 -0
  82. package/dist/testing/matchers.d.ts +94 -0
  83. package/dist/testing/matchers.d.ts.map +1 -0
  84. package/dist/testing/matchers.js +203 -0
  85. package/dist/testing/matchers.js.map +1 -0
  86. package/dist/utils/json_schema.cjs +3 -1
  87. package/dist/utils/json_schema.cjs.map +1 -1
  88. package/dist/utils/json_schema.d.cts +3 -2
  89. package/dist/utils/json_schema.d.cts.map +1 -1
  90. package/dist/utils/json_schema.d.ts +3 -2
  91. package/dist/utils/json_schema.d.ts.map +1 -1
  92. package/dist/utils/json_schema.js +3 -1
  93. package/dist/utils/json_schema.js.map +1 -1
  94. package/dist/utils/standard_schema.cjs +43 -0
  95. package/dist/utils/standard_schema.cjs.map +1 -0
  96. package/dist/utils/standard_schema.d.cts +27 -0
  97. package/dist/utils/standard_schema.d.cts.map +1 -0
  98. package/dist/utils/standard_schema.d.ts +27 -0
  99. package/dist/utils/standard_schema.d.ts.map +1 -0
  100. package/dist/utils/standard_schema.js +34 -0
  101. package/dist/utils/standard_schema.js.map +1 -0
  102. package/dist/utils/types/zod.cjs +1 -1
  103. package/dist/utils/types/zod.cjs.map +1 -1
  104. package/dist/utils/types/zod.d.cts +3 -2
  105. package/dist/utils/types/zod.d.cts.map +1 -1
  106. package/dist/utils/types/zod.d.ts +3 -2
  107. package/dist/utils/types/zod.d.ts.map +1 -1
  108. package/dist/utils/types/zod.js +1 -1
  109. package/dist/utils/types/zod.js.map +1 -1
  110. package/errors.cjs +1 -0
  111. package/errors.d.cts +1 -0
  112. package/errors.d.ts +1 -0
  113. package/errors.js +1 -0
  114. package/language_models/structured_output.cjs +1 -0
  115. package/language_models/structured_output.d.cts +1 -0
  116. package/language_models/structured_output.d.ts +1 -0
  117. package/language_models/structured_output.js +1 -0
  118. package/package.json +42 -3
  119. package/utils/standard_schema.cjs +1 -0
  120. package/utils/standard_schema.d.cts +1 -0
  121. package/utils/standard_schema.d.ts +1 -0
  122. package/utils/standard_schema.js +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchers.js","names":[],"sources":["../../src/testing/matchers.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { BaseMessage } from \"../messages/index.js\";\nimport { HumanMessage } from \"../messages/index.js\";\nimport { AIMessage } from \"../messages/index.js\";\nimport { SystemMessage } from \"../messages/index.js\";\nimport { ToolMessage } from \"../messages/index.js\";\n\n/**\n * The `this` context that Vitest and Jest provide to custom matchers\n * via `expect.extend`.\n *\n * Compatible with both frameworks:\n * - https://vitest.dev/guide/extending-matchers.html\n * - https://jestjs.io/docs/expect#expectextendmatchers\n */\ninterface ExpectExtendThis {\n isNot?: boolean;\n equals(a: unknown, b: unknown): boolean;\n utils: {\n matcherHint(name: string, received?: string, expected?: string): string;\n printReceived(value: unknown): string;\n printExpected(value: unknown): string;\n };\n}\n\ninterface ExpectationResult {\n pass: boolean;\n message: () => string;\n actual?: unknown;\n expected?: unknown;\n}\n\nfunction getMessageTypeName(msg: unknown): string {\n if (!BaseMessage.isInstance(msg)) return typeof msg;\n return msg.constructor.name || msg.type;\n}\n\nfunction makeMessageTypeMatcher(\n typeName: string,\n isInstance: (obj: unknown) => boolean\n) {\n return function (\n this: ExpectExtendThis,\n received: unknown,\n expected?: string | Record<string, unknown>\n ): ExpectationResult {\n const { isNot, utils } = this;\n\n const instancePass = isInstance(received);\n if (!instancePass) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(`toBe${typeName}`, undefined, undefined)}\\n\\n` +\n `Expected: ${isNot ? \"not \" : \"\"}${typeName}\\n` +\n `Received: ${getMessageTypeName(received)}`,\n actual: getMessageTypeName(received),\n expected: typeName,\n };\n }\n\n if (expected === undefined) {\n return {\n pass: true,\n message: () =>\n `${utils.matcherHint(`toBe${typeName}`, undefined, undefined)}\\n\\n` +\n `Expected: not ${typeName}\\n` +\n `Received: ${typeName}`,\n };\n }\n\n const msg = received as BaseMessage;\n if (typeof expected === \"string\") {\n const contentPass = msg.content === expected;\n return {\n pass: contentPass,\n message: () =>\n `${utils.matcherHint(`toBe${typeName}`, undefined, undefined)}\\n\\n` +\n `Expected: ${typeName} with content ${utils.printExpected(expected)}\\n` +\n `Received: ${typeName} with content ${utils.printReceived(msg.content)}`,\n actual: msg.content,\n expected,\n };\n }\n\n const fieldsPass = Object.entries(expected).every(([key, value]) =>\n this.equals((msg as any)[key], value)\n );\n return {\n pass: fieldsPass,\n message: () => {\n const receivedFields: Record<string, unknown> = {};\n for (const key of Object.keys(expected)) {\n receivedFields[key] = (msg as any)[key];\n }\n return (\n `${utils.matcherHint(`toBe${typeName}`, undefined, undefined)}\\n\\n` +\n `Expected: ${typeName} matching ${utils.printExpected(expected)}\\n` +\n `Received: ${typeName} with ${utils.printReceived(receivedFields)}`\n );\n },\n actual: (() => {\n const receivedFields: Record<string, unknown> = {};\n for (const key of Object.keys(expected)) {\n receivedFields[key] = (msg as any)[key];\n }\n return receivedFields;\n })(),\n expected,\n };\n };\n}\n\nexport const toBeHumanMessage = makeMessageTypeMatcher(\n \"HumanMessage\",\n HumanMessage.isInstance\n);\n\nexport const toBeAIMessage = makeMessageTypeMatcher(\n \"AIMessage\",\n AIMessage.isInstance\n);\n\nexport const toBeSystemMessage = makeMessageTypeMatcher(\n \"SystemMessage\",\n SystemMessage.isInstance\n);\n\nexport const toBeToolMessage = makeMessageTypeMatcher(\n \"ToolMessage\",\n ToolMessage.isInstance\n);\n\nexport function toHaveToolCalls(\n this: ExpectExtendThis,\n received: unknown,\n expected: Array<Record<string, unknown>>\n): ExpectationResult {\n const { isNot, utils } = this;\n\n if (!AIMessage.isInstance(received)) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveToolCalls\")}\\n\\n` +\n `Expected: AIMessage\\n` +\n `Received: ${getMessageTypeName(received)}`,\n };\n }\n\n const actual = received.tool_calls ?? [];\n\n if (actual.length !== expected.length) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveToolCalls\")}\\n\\n` +\n `Expected ${isNot ? \"not \" : \"\"}${expected.length} tool call(s), received ${actual.length}`,\n actual: actual.length,\n expected: expected.length,\n };\n }\n\n const unmatched = expected.filter(\n (exp) =>\n !actual.some((tc) =>\n Object.entries(exp).every(([key, value]) =>\n this.equals((tc as any)[key], value)\n )\n )\n );\n\n if (unmatched.length > 0) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveToolCalls\")}\\n\\n` +\n `Could not find matching tool call(s) for:\\n` +\n `${utils.printExpected(unmatched)}\\n` +\n `Received tool calls: ${utils.printReceived(actual.map((tc) => ({ name: tc.name, id: tc.id, args: tc.args })))}`,\n actual: actual.map((tc) => ({ name: tc.name, id: tc.id, args: tc.args })),\n expected,\n };\n }\n\n return {\n pass: true,\n message: () =>\n `${utils.matcherHint(\"toHaveToolCalls\")}\\n\\n` +\n `Expected AIMessage not to have matching tool calls`,\n };\n}\n\nexport function toHaveToolCallCount(\n this: ExpectExtendThis,\n received: unknown,\n expected: number\n): ExpectationResult {\n const { isNot, utils } = this;\n\n if (!AIMessage.isInstance(received)) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveToolCallCount\")}\\n\\n` +\n `Expected: AIMessage\\n` +\n `Received: ${getMessageTypeName(received)}`,\n };\n }\n\n const actual = received.tool_calls?.length ?? 0;\n const pass = actual === expected;\n\n return {\n pass,\n message: () =>\n `${utils.matcherHint(\"toHaveToolCallCount\")}\\n\\n` +\n `Expected ${isNot ? \"not \" : \"\"}${expected} tool call(s)\\n` +\n `Received: ${actual}`,\n actual,\n expected,\n };\n}\n\nexport function toContainToolCall(\n this: ExpectExtendThis,\n received: unknown,\n expected: Record<string, unknown>\n): ExpectationResult {\n const { isNot, utils } = this;\n\n if (!AIMessage.isInstance(received)) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toContainToolCall\")}\\n\\n` +\n `Expected: AIMessage\\n` +\n `Received: ${getMessageTypeName(received)}`,\n };\n }\n\n const actual = received.tool_calls ?? [];\n const found = actual.some((tc) =>\n Object.entries(expected).every(([key, value]) =>\n this.equals((tc as any)[key], value)\n )\n );\n\n return {\n pass: found,\n message: () =>\n `${utils.matcherHint(\"toContainToolCall\")}\\n\\n` +\n `Expected AIMessage ${isNot ? \"not \" : \"\"}to contain a tool call matching ${utils.printExpected(expected)}\\n` +\n `Received tool calls: ${utils.printReceived(actual.map((tc) => ({ name: tc.name, id: tc.id })))}`,\n actual: actual.map((tc) => ({ name: tc.name, id: tc.id })),\n expected,\n };\n}\n\nexport function toHaveToolMessages(\n this: ExpectExtendThis,\n received: unknown,\n expected: Array<Record<string, unknown>>\n): ExpectationResult {\n const { isNot, utils } = this;\n\n if (!Array.isArray(received)) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveToolMessages\")}\\n\\n` +\n `Expected an array of messages\\n` +\n `Received: ${typeof received}`,\n };\n }\n\n const toolMessages = (received as BaseMessage[]).filter(\n ToolMessage.isInstance\n );\n\n if (toolMessages.length !== expected.length) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveToolMessages\")}\\n\\n` +\n `Expected ${isNot ? \"not \" : \"\"}${expected.length} tool message(s), found ${toolMessages.length}`,\n actual: toolMessages.length,\n expected: expected.length,\n };\n }\n\n for (let i = 0; i < expected.length; i++) {\n const match = Object.entries(expected[i]).every(([key, value]) =>\n this.equals((toolMessages[i] as any)[key], value)\n );\n if (!match) {\n return {\n pass: false,\n message: () => {\n const receivedFields: Record<string, unknown> = {};\n for (const key of Object.keys(expected[i])) {\n receivedFields[key] = (toolMessages[i] as any)[key];\n }\n return (\n `${utils.matcherHint(\"toHaveToolMessages\")}\\n\\n` +\n `Tool message at index ${i} did not match:\\n` +\n `Expected: ${utils.printExpected(expected[i])}\\n` +\n `Received: ${utils.printReceived(receivedFields)}`\n );\n },\n actual: toolMessages[i],\n expected: expected[i],\n };\n }\n }\n\n return {\n pass: true,\n message: () =>\n `${utils.matcherHint(\"toHaveToolMessages\")}\\n\\n` +\n `Expected messages not to contain matching tool messages`,\n };\n}\n\nexport function toHaveBeenInterrupted(\n this: ExpectExtendThis,\n received: unknown,\n expectedValue?: unknown\n): ExpectationResult {\n const { isNot, utils } = this;\n\n const result = received as Record<string, any>;\n const interrupts = result?.__interrupt__;\n const hasInterrupt = Array.isArray(interrupts) && interrupts.length > 0;\n\n if (!hasInterrupt) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveBeenInterrupted\")}\\n\\n` +\n `Expected result ${isNot ? \"not \" : \"\"}to have been interrupted\\n` +\n `Received __interrupt__: ${utils.printReceived(interrupts)}`,\n };\n }\n\n if (expectedValue === undefined) {\n return {\n pass: true,\n message: () =>\n `${utils.matcherHint(\"toHaveBeenInterrupted\")}\\n\\n` +\n `Expected result not to have been interrupted\\n` +\n `Received ${interrupts.length} interrupt(s)`,\n };\n }\n\n const actualValue = interrupts[0]?.value;\n const valuePass = this.equals(actualValue, expectedValue);\n\n return {\n pass: valuePass,\n message: () =>\n `${utils.matcherHint(\"toHaveBeenInterrupted\")}\\n\\n` +\n `Expected interrupt value: ${utils.printExpected(expectedValue)}\\n` +\n `Received interrupt value: ${utils.printReceived(actualValue)}`,\n actual: actualValue,\n expected: expectedValue,\n };\n}\n\nexport function toHaveStructuredResponse(\n this: ExpectExtendThis,\n received: unknown,\n expected?: Record<string, unknown>\n): ExpectationResult {\n const { isNot, utils } = this;\n\n const result = received as Record<string, any>;\n const structuredResponse = result?.structuredResponse;\n const isDefined = structuredResponse !== undefined;\n\n if (!isDefined) {\n return {\n pass: false,\n message: () =>\n `${utils.matcherHint(\"toHaveStructuredResponse\")}\\n\\n` +\n `Expected result ${isNot ? \"not \" : \"\"}to have a structured response\\n` +\n `Received structuredResponse: undefined`,\n };\n }\n\n if (expected === undefined) {\n return {\n pass: true,\n message: () =>\n `${utils.matcherHint(\"toHaveStructuredResponse\")}\\n\\n` +\n `Expected result not to have a structured response`,\n };\n }\n\n const fieldsPass = Object.entries(expected).every(([key, value]) =>\n this.equals(structuredResponse[key], value)\n );\n\n return {\n pass: fieldsPass,\n message: () =>\n `${utils.matcherHint(\"toHaveStructuredResponse\")}\\n\\n` +\n `Expected structured response: ${utils.printExpected(expected)}\\n` +\n `Received structured response: ${utils.printReceived(structuredResponse)}`,\n actual: structuredResponse,\n expected,\n };\n}\n\n/**\n * All matcher functions bundled for convenient use with `expect.extend()`.\n */\nexport const langchainMatchers = {\n toBeHumanMessage,\n toBeAIMessage,\n toBeSystemMessage,\n toBeToolMessage,\n toHaveToolCalls,\n toHaveToolCallCount,\n toContainToolCall,\n toHaveToolMessages,\n toHaveBeenInterrupted,\n toHaveStructuredResponse,\n};\n\nexport interface LangChainMatchers<R = unknown> {\n toBeHumanMessage(expected?: string | { content?: string; id?: string }): R;\n toBeAIMessage(expected?: string | { content?: string; name?: string }): R;\n toBeSystemMessage(\n expected?: string | { content?: string; additional_kwargs?: object }\n ): R;\n toBeToolMessage(\n expected?:\n | string\n | {\n content?: string;\n name?: string;\n status?: string;\n tool_call_id?: string;\n }\n ): R;\n toHaveToolCalls(\n expected: Array<{\n name?: string;\n id?: string;\n args?: Record<string, unknown>;\n }>\n ): R;\n toHaveToolCallCount(expected: number): R;\n toContainToolCall(expected: {\n name?: string;\n id?: string;\n args?: Record<string, unknown>;\n }): R;\n toHaveToolMessages(\n expected: Array<{\n content?: string;\n name?: string;\n status?: string;\n tool_call_id?: string;\n }>\n ): R;\n toHaveBeenInterrupted(expectedValue?: unknown): R;\n toHaveStructuredResponse(expected?: Record<string, unknown>): R;\n}\n\ndeclare module \"vitest\" {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n interface Matchers<T = any> extends LangChainMatchers<T> {}\n}\n"],"mappings":";;;;;;;;AAgCA,SAAS,mBAAmB,KAAsB;AAChD,KAAI,CAAC,YAAY,WAAW,IAAI,CAAE,QAAO,OAAO;AAChD,QAAO,IAAI,YAAY,QAAQ,IAAI;;AAGrC,SAAS,uBACP,UACA,YACA;AACA,QAAO,SAEL,UACA,UACmB;EACnB,MAAM,EAAE,OAAO,UAAU;AAGzB,MAAI,CADiB,WAAW,SAAS,CAEvC,QAAO;GACL,MAAM;GACN,eACE,GAAG,MAAM,YAAY,OAAO,YAAY,QAAW,OAAU,CAAC,gBACjD,QAAQ,SAAS,KAAK,SAAS,cAC/B,mBAAmB,SAAS;GAC3C,QAAQ,mBAAmB,SAAS;GACpC,UAAU;GACX;AAGH,MAAI,aAAa,OACf,QAAO;GACL,MAAM;GACN,eACE,GAAG,MAAM,YAAY,OAAO,YAAY,QAAW,OAAU,CAAC,oBAC7C,SAAS,cACb;GAChB;EAGH,MAAM,MAAM;AACZ,MAAI,OAAO,aAAa,SAEtB,QAAO;GACL,MAFkB,IAAI,YAAY;GAGlC,eACE,GAAG,MAAM,YAAY,OAAO,YAAY,QAAW,OAAU,CAAC,gBACjD,SAAS,gBAAgB,MAAM,cAAc,SAAS,CAAC,cACvD,SAAS,gBAAgB,MAAM,cAAc,IAAI,QAAQ;GACxE,QAAQ,IAAI;GACZ;GACD;AAMH,SAAO;GACL,MAJiB,OAAO,QAAQ,SAAS,CAAC,OAAO,CAAC,KAAK,WACvD,KAAK,OAAQ,IAAY,MAAM,MAAM,CACtC;GAGC,eAAe;IACb,MAAM,iBAA0C,EAAE;AAClD,SAAK,MAAM,OAAO,OAAO,KAAK,SAAS,CACrC,gBAAe,OAAQ,IAAY;AAErC,WACE,GAAG,MAAM,YAAY,OAAO,YAAY,QAAW,OAAU,CAAC,gBACjD,SAAS,YAAY,MAAM,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WAAW,OAAO;EACjC;CAGH,MAAM,cAAc,WAAW,IAAI;AAGnC,QAAO;EACL,MAHgB,KAAK,OAAO,aAAa,cAAc;EAIvD,eACE,GAAG,MAAM,YAAY,wBAAwB,CAAC,gCACjB,MAAM,cAAc,cAAc,CAAC,8BACnC,MAAM,cAAc,YAAY;EAC/D,QAAQ;EACR,UAAU;EACX;;AAGH,SAAgB,yBAEd,UACA,UACmB;CACnB,MAAM,EAAE,OAAO,UAAU;CAGzB,MAAM,qBADS,UACoB;AAGnC,KAAI,EAFc,uBAAuB,QAGvC,QAAO;EACL,MAAM;EACN,eACE,GAAG,MAAM,YAAY,2BAA2B,CAAC,sBAC9B,QAAQ,SAAS,GAAG;EAE1C;AAGH,KAAI,aAAa,OACf,QAAO;EACL,MAAM;EACN,eACE,GAAG,MAAM,YAAY,2BAA2B,CAAC;EAEpD;AAOH,QAAO;EACL,MALiB,OAAO,QAAQ,SAAS,CAAC,OAAO,CAAC,KAAK,WACvD,KAAK,OAAO,mBAAmB,MAAM,MAAM,CAC5C;EAIC,eACE,GAAG,MAAM,YAAY,2BAA2B,CAAC,oCAChB,MAAM,cAAc,SAAS,CAAC,kCAC9B,MAAM,cAAc,mBAAmB;EAC1E,QAAQ;EACR;EACD;;;;;AAMH,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
@@ -3,6 +3,7 @@ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
3
  const require_zod = require('./types/zod.cjs');
4
4
  const require_zodToJsonSchema = require('./zod-to-json-schema/zodToJsonSchema.cjs');
5
5
  require('./zod-to-json-schema/index.cjs');
6
+ const require_utils_standard_schema = require('./standard_schema.cjs');
6
7
  let zod_v4_core = require("zod/v4/core");
7
8
  let _cfworker_json_schema = require("@cfworker/json-schema");
8
9
 
@@ -14,12 +15,13 @@ var json_schema_exports = /* @__PURE__ */ require_runtime.__exportAll({
14
15
  validatesOnlyStrings: () => validatesOnlyStrings
15
16
  });
16
17
  /**
17
- * Converts a Zod schema or JSON schema to a JSON schema.
18
+ * Converts a Standard JSON schema, Zod schema or JSON schema to a JSON schema.
18
19
  * @param schema - The schema to convert.
19
20
  * @param params - The parameters to pass to the toJSONSchema function.
20
21
  * @returns The converted schema.
21
22
  */
22
23
  function toJsonSchema(schema, params) {
24
+ if (require_utils_standard_schema.isStandardJsonSchema(schema) && !require_zod.isZodSchemaV4(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-07" });
23
25
  if (require_zod.isZodSchemaV4(schema)) {
24
26
  const inputSchema = require_zod.interopZodTransformInputSchema(schema, true);
25
27
  if (require_zod.isZodObjectV4(inputSchema)) return (0, zod_v4_core.toJSONSchema)(require_zod.interopZodObjectStrict(inputSchema, true), params);
@@ -1 +1 @@
1
- {"version":3,"file":"json_schema.cjs","names":["isZodSchemaV4","interopZodTransformInputSchema","isZodObjectV4","interopZodObjectStrict","isZodSchemaV3","zodToJsonSchema"],"sources":["../../src/utils/json_schema.ts"],"sourcesContent":["import { toJSONSchema } from \"zod/v4/core\";\nimport { dereference, type Schema } from \"@cfworker/json-schema\";\nimport {\n isZodSchemaV3,\n isZodSchemaV4,\n InteropZodType,\n interopZodObjectStrict,\n isZodObjectV4,\n ZodObjectV4,\n interopZodTransformInputSchema,\n} from \"./types/zod.js\";\nimport {\n type JsonSchema7Type as JSONSchema,\n zodToJsonSchema,\n} from \"./zod-to-json-schema/index.js\";\n\nexport { deepCompareStrict, Validator } from \"@cfworker/json-schema\";\n\nexport type ToJSONSchemaParams = NonNullable<\n Parameters<typeof toJSONSchema>[1]\n>;\n\n/**\n * Converts a Zod schema or JSON schema to a JSON schema.\n * @param schema - The schema to convert.\n * @param params - The parameters to pass to the toJSONSchema function.\n * @returns The converted schema.\n */\nexport function toJsonSchema(\n schema: InteropZodType | JSONSchema,\n params?: ToJSONSchemaParams\n): JSONSchema {\n if (isZodSchemaV4(schema)) {\n const inputSchema = interopZodTransformInputSchema(schema, true);\n if (isZodObjectV4(inputSchema)) {\n const strictSchema = interopZodObjectStrict(\n inputSchema,\n true\n ) as ZodObjectV4;\n return toJSONSchema(strictSchema, params);\n } else {\n return toJSONSchema(schema, params);\n }\n }\n if (isZodSchemaV3(schema)) {\n return zodToJsonSchema(schema);\n }\n return schema as JSONSchema;\n}\n\n/**\n * Validates if a JSON schema validates only strings. May return false negatives in some edge cases\n * (like recursive or unresolvable refs).\n *\n * @param schema - The schema to validate.\n * @returns `true` if the schema validates only strings, `false` otherwise.\n */\nexport function validatesOnlyStrings(schema: unknown): boolean {\n // Null, undefined, or empty schema\n if (\n !schema ||\n typeof schema !== \"object\" ||\n Object.keys(schema).length === 0 ||\n Array.isArray(schema)\n ) {\n return false; // Validates anything, not just strings\n }\n\n // Explicit type constraint\n if (\"type\" in schema) {\n if (typeof schema.type === \"string\") {\n return schema.type === \"string\";\n }\n\n if (Array.isArray(schema.type)) {\n // not sure why someone would do `\"type\": [\"string\"]` or especially `\"type\": [\"string\",\n // \"string\", \"string\", ...]` but we're not here to judge\n return schema.type.every((t) => t === \"string\");\n }\n return false; // Invalid or non-string type\n }\n\n // Enum with only string values\n if (\"enum\" in schema) {\n return (\n Array.isArray(schema.enum) &&\n schema.enum.length > 0 &&\n schema.enum.every((val) => typeof val === \"string\")\n );\n }\n\n // String constant\n if (\"const\" in schema) {\n return typeof schema.const === \"string\";\n }\n\n // Schema combinations\n if (\"allOf\" in schema && Array.isArray(schema.allOf)) {\n // If any subschema validates only strings, then the overall schema validates only strings\n return schema.allOf.some((subschema) => validatesOnlyStrings(subschema));\n }\n\n if (\n (\"anyOf\" in schema && Array.isArray(schema.anyOf)) ||\n (\"oneOf\" in schema && Array.isArray(schema.oneOf))\n ) {\n const subschemas = (\n \"anyOf\" in schema ? schema.anyOf : schema.oneOf\n ) as unknown[];\n\n // All subschemas must validate only strings\n return (\n subschemas.length > 0 &&\n subschemas.every((subschema) => validatesOnlyStrings(subschema))\n );\n }\n\n // We're not going to try on this one, it's too complex - we just assume if it has a \"not\" key and hasn't matched one of the above checks, it's not a string schema.\n if (\"not\" in schema) {\n return false; // The not case can validate non-strings\n }\n\n if (\"$ref\" in schema && typeof schema.$ref === \"string\") {\n const ref = schema.$ref as string;\n const resolved = dereference(schema as Schema);\n if (resolved[ref]) {\n return validatesOnlyStrings(resolved[ref]);\n }\n return false;\n }\n\n // ignore recursive refs and other cases where type is omitted for now\n // ignore other cases for now where type is omitted\n\n return false;\n}\n\n// Re-export of the types used throughout langchain for json schema serialization.\n// The plan is to eventually nix zod-to-json-schema altogether in place for\n// zod v4 / a more standardized way of serializing validated inputs, so its re-exported\n// here to remove the dependency on zod-to-json-schema in downstream packages until\n// a determination is made.\n\nexport {\n type JsonSchema7Type,\n type JsonSchema7Type as JSONSchema,\n type JsonSchema7ArrayType,\n type JsonSchema7ObjectType,\n type JsonSchema7StringType,\n type JsonSchema7NumberType,\n type JsonSchema7NullableType,\n} from \"./zod-to-json-schema/index.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,aACd,QACA,QACY;AACZ,KAAIA,0BAAc,OAAO,EAAE;EACzB,MAAM,cAAcC,2CAA+B,QAAQ,KAAK;AAChE,MAAIC,0BAAc,YAAY,CAK5B,sCAJqBC,mCACnB,aACA,KACD,EACiC,OAAO;MAEzC,sCAAoB,QAAQ,OAAO;;AAGvC,KAAIC,0BAAc,OAAO,CACvB,QAAOC,wCAAgB,OAAO;AAEhC,QAAO;;;;;;;;;AAUT,SAAgB,qBAAqB,QAA0B;AAE7D,KACE,CAAC,UACD,OAAO,WAAW,YAClB,OAAO,KAAK,OAAO,CAAC,WAAW,KAC/B,MAAM,QAAQ,OAAO,CAErB,QAAO;AAIT,KAAI,UAAU,QAAQ;AACpB,MAAI,OAAO,OAAO,SAAS,SACzB,QAAO,OAAO,SAAS;AAGzB,MAAI,MAAM,QAAQ,OAAO,KAAK,CAG5B,QAAO,OAAO,KAAK,OAAO,MAAM,MAAM,SAAS;AAEjD,SAAO;;AAIT,KAAI,UAAU,OACZ,QACE,MAAM,QAAQ,OAAO,KAAK,IAC1B,OAAO,KAAK,SAAS,KACrB,OAAO,KAAK,OAAO,QAAQ,OAAO,QAAQ,SAAS;AAKvD,KAAI,WAAW,OACb,QAAO,OAAO,OAAO,UAAU;AAIjC,KAAI,WAAW,UAAU,MAAM,QAAQ,OAAO,MAAM,CAElD,QAAO,OAAO,MAAM,MAAM,cAAc,qBAAqB,UAAU,CAAC;AAG1E,KACG,WAAW,UAAU,MAAM,QAAQ,OAAO,MAAM,IAChD,WAAW,UAAU,MAAM,QAAQ,OAAO,MAAM,EACjD;EACA,MAAM,aACJ,WAAW,SAAS,OAAO,QAAQ,OAAO;AAI5C,SACE,WAAW,SAAS,KACpB,WAAW,OAAO,cAAc,qBAAqB,UAAU,CAAC;;AAKpE,KAAI,SAAS,OACX,QAAO;AAGT,KAAI,UAAU,UAAU,OAAO,OAAO,SAAS,UAAU;EACvD,MAAM,MAAM,OAAO;EACnB,MAAM,kDAAuB,OAAiB;AAC9C,MAAI,SAAS,KACX,QAAO,qBAAqB,SAAS,KAAK;AAE5C,SAAO;;AAMT,QAAO"}
1
+ {"version":3,"file":"json_schema.cjs","names":["isStandardJsonSchema","isZodSchemaV4","interopZodTransformInputSchema","isZodObjectV4","interopZodObjectStrict","isZodSchemaV3","zodToJsonSchema"],"sources":["../../src/utils/json_schema.ts"],"sourcesContent":["import { toJSONSchema } from \"zod/v4/core\";\nimport { dereference, type Schema } from \"@cfworker/json-schema\";\nimport {\n isZodSchemaV3,\n isZodSchemaV4,\n InteropZodType,\n interopZodObjectStrict,\n isZodObjectV4,\n ZodObjectV4,\n interopZodTransformInputSchema,\n} from \"./types/zod.js\";\nimport {\n type JsonSchema7Type as JSONSchema,\n zodToJsonSchema,\n} from \"./zod-to-json-schema/index.js\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { isStandardJsonSchema } from \"./standard_schema.js\";\n\nexport { deepCompareStrict, Validator } from \"@cfworker/json-schema\";\n\nexport type ToJSONSchemaParams = NonNullable<\n Parameters<typeof toJSONSchema>[1]\n>;\n\n/**\n * Converts a Standard JSON schema, Zod schema or JSON schema to a JSON schema.\n * @param schema - The schema to convert.\n * @param params - The parameters to pass to the toJSONSchema function.\n * @returns The converted schema.\n */\nexport function toJsonSchema(\n schema: StandardJSONSchemaV1 | InteropZodType | JSONSchema,\n params?: ToJSONSchemaParams\n): JSONSchema {\n if (isStandardJsonSchema(schema) && !isZodSchemaV4(schema)) {\n return schema[\"~standard\"].jsonSchema.input({\n target: \"draft-07\",\n }) as JSONSchema;\n }\n if (isZodSchemaV4(schema)) {\n const inputSchema = interopZodTransformInputSchema(schema, true);\n if (isZodObjectV4(inputSchema)) {\n const strictSchema = interopZodObjectStrict(\n inputSchema,\n true\n ) as ZodObjectV4;\n return toJSONSchema(strictSchema, params);\n } else {\n return toJSONSchema(schema, params);\n }\n }\n if (isZodSchemaV3(schema)) {\n return zodToJsonSchema(schema);\n }\n return schema as JSONSchema;\n}\n\n/**\n * Validates if a JSON schema validates only strings. May return false negatives in some edge cases\n * (like recursive or unresolvable refs).\n *\n * @param schema - The schema to validate.\n * @returns `true` if the schema validates only strings, `false` otherwise.\n */\nexport function validatesOnlyStrings(schema: unknown): boolean {\n // Null, undefined, or empty schema\n if (\n !schema ||\n typeof schema !== \"object\" ||\n Object.keys(schema).length === 0 ||\n Array.isArray(schema)\n ) {\n return false; // Validates anything, not just strings\n }\n\n // Explicit type constraint\n if (\"type\" in schema) {\n if (typeof schema.type === \"string\") {\n return schema.type === \"string\";\n }\n\n if (Array.isArray(schema.type)) {\n // not sure why someone would do `\"type\": [\"string\"]` or especially `\"type\": [\"string\",\n // \"string\", \"string\", ...]` but we're not here to judge\n return schema.type.every((t) => t === \"string\");\n }\n return false; // Invalid or non-string type\n }\n\n // Enum with only string values\n if (\"enum\" in schema) {\n return (\n Array.isArray(schema.enum) &&\n schema.enum.length > 0 &&\n schema.enum.every((val) => typeof val === \"string\")\n );\n }\n\n // String constant\n if (\"const\" in schema) {\n return typeof schema.const === \"string\";\n }\n\n // Schema combinations\n if (\"allOf\" in schema && Array.isArray(schema.allOf)) {\n // If any subschema validates only strings, then the overall schema validates only strings\n return schema.allOf.some((subschema) => validatesOnlyStrings(subschema));\n }\n\n if (\n (\"anyOf\" in schema && Array.isArray(schema.anyOf)) ||\n (\"oneOf\" in schema && Array.isArray(schema.oneOf))\n ) {\n const subschemas = (\n \"anyOf\" in schema ? schema.anyOf : schema.oneOf\n ) as unknown[];\n\n // All subschemas must validate only strings\n return (\n subschemas.length > 0 &&\n subschemas.every((subschema) => validatesOnlyStrings(subschema))\n );\n }\n\n // We're not going to try on this one, it's too complex - we just assume if it has a \"not\" key and hasn't matched one of the above checks, it's not a string schema.\n if (\"not\" in schema) {\n return false; // The not case can validate non-strings\n }\n\n if (\"$ref\" in schema && typeof schema.$ref === \"string\") {\n const ref = schema.$ref as string;\n const resolved = dereference(schema as Schema);\n if (resolved[ref]) {\n return validatesOnlyStrings(resolved[ref]);\n }\n return false;\n }\n\n // ignore recursive refs and other cases where type is omitted for now\n // ignore other cases for now where type is omitted\n\n return false;\n}\n\n// Re-export of the types used throughout langchain for json schema serialization.\n// The plan is to eventually nix zod-to-json-schema altogether in place for\n// zod v4 / a more standardized way of serializing validated inputs, so its re-exported\n// here to remove the dependency on zod-to-json-schema in downstream packages until\n// a determination is made.\n\nexport {\n type JsonSchema7Type,\n type JsonSchema7Type as JSONSchema,\n type JsonSchema7ArrayType,\n type JsonSchema7ObjectType,\n type JsonSchema7StringType,\n type JsonSchema7NumberType,\n type JsonSchema7NullableType,\n} from \"./zod-to-json-schema/index.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,aACd,QACA,QACY;AACZ,KAAIA,mDAAqB,OAAO,IAAI,CAACC,0BAAc,OAAO,CACxD,QAAO,OAAO,aAAa,WAAW,MAAM,EAC1C,QAAQ,YACT,CAAC;AAEJ,KAAIA,0BAAc,OAAO,EAAE;E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AO;;AAMT,QAAO"}
@@ -6,17 +6,18 @@ import { JsonSchema7NullableType } from "./zod-to-json-schema/parsers/nullable.c
6
6
  import { JsonSchema7ObjectType } from "./zod-to-json-schema/parsers/object.cjs";
7
7
  import { JsonSchema7Type } from "./zod-to-json-schema/parseTypes.cjs";
8
8
  import { toJSONSchema } from "zod/v4/core";
9
+ import { StandardJSONSchemaV1 } from "@standard-schema/spec";
9
10
  import { Validator, deepCompareStrict } from "@cfworker/json-schema";
10
11
 
11
12
  //#region src/utils/json_schema.d.ts
12
13
  type ToJSONSchemaParams = NonNullable<Parameters<typeof toJSONSchema>[1]>;
13
14
  /**
14
- * Converts a Zod schema or JSON schema to a JSON schema.
15
+ * Converts a Standard JSON schema, Zod schema or JSON schema to a JSON schema.
15
16
  * @param schema - The schema to convert.
16
17
  * @param params - The parameters to pass to the toJSONSchema function.
17
18
  * @returns The converted schema.
18
19
  */
19
- declare function toJsonSchema(schema: InteropZodType | JsonSchema7Type, params?: ToJSONSchemaParams): JsonSchema7Type;
20
+ declare function toJsonSchema(schema: StandardJSONSchemaV1 | InteropZodType | JsonSchema7Type, params?: ToJSONSchemaParams): JsonSchema7Type;
20
21
  /**
21
22
  * Validates if a JSON schema validates only strings. May return false negatives in some edge cases
22
23
  * (like recursive or unresolvable refs).
@@ -1 +1 @@
1
- {"version":3,"file":"json_schema.d.cts","names":[],"sources":["../../src/utils/json_schema.ts"],"mappings":";;;;;;;;;;;KAkBY,kBAAA,GAAqB,WAAA,CAC/B,UAAA,QAAkB,YAAA;;;;;;;iBASJ,YAAA,CACd,MAAA,EAAQ,cAAA,GAAiB,eAAA,EACzB,MAAA,GAAS,kBAAA,GACR,eAAA;;;;;;;;iBA0Ba,oBAAA,CAAqB,MAAA"}
1
+ {"version":3,"file":"json_schema.d.cts","names":[],"sources":["../../src/utils/json_schema.ts"],"mappings":";;;;;;;;;;;;KAoBY,kBAAA,GAAqB,WAAA,CAC/B,UAAA,QAAkB,YAAA;;;;;;;iBASJ,YAAA,CACd,MAAA,EAAQ,oBAAA,GAAuB,cAAA,GAAiB,eAAA,EAChD,MAAA,GAAS,kBAAA,GACR,eAAA;;;;;;;;iBA+Ba,oBAAA,CAAqB,MAAA"}
@@ -8,16 +8,17 @@ import { JsonSchema7Type } from "./zod-to-json-schema/parseTypes.js";
8
8
  import "./zod-to-json-schema/index.js";
9
9
  import { toJSONSchema } from "zod/v4/core";
10
10
  import { Validator, deepCompareStrict } from "@cfworker/json-schema";
11
+ import { StandardJSONSchemaV1 } from "@standard-schema/spec";
11
12
 
12
13
  //#region src/utils/json_schema.d.ts
13
14
  type ToJSONSchemaParams = NonNullable<Parameters<typeof toJSONSchema>[1]>;
14
15
  /**
15
- * Converts a Zod schema or JSON schema to a JSON schema.
16
+ * Converts a Standard JSON schema, Zod schema or JSON schema to a JSON schema.
16
17
  * @param schema - The schema to convert.
17
18
  * @param params - The parameters to pass to the toJSONSchema function.
18
19
  * @returns The converted schema.
19
20
  */
20
- declare function toJsonSchema(schema: InteropZodType | JsonSchema7Type, params?: ToJSONSchemaParams): JsonSchema7Type;
21
+ declare function toJsonSchema(schema: StandardJSONSchemaV1 | InteropZodType | JsonSchema7Type, params?: ToJSONSchemaParams): JsonSchema7Type;
21
22
  /**
22
23
  * Validates if a JSON schema validates only strings. May return false negatives in some edge cases
23
24
  * (like recursive or unresolvable refs).
@@ -1 +1 @@
1
- {"version":3,"file":"json_schema.d.ts","names":[],"sources":["../../src/utils/json_schema.ts"],"mappings":";;;;;;;;;;;;KAkBY,kBAAA,GAAqB,WAAA,CAC/B,UAAA,QAAkB,YAAA;;;;;;;iBASJ,YAAA,CACd,MAAA,EAAQ,cAAA,GAAiB,eAAA,EACzB,MAAA,GAAS,kBAAA,GACR,eAAA;AAbH;;;;;;;AAAA,iBAuCgB,oBAAA,CAAqB,MAAA"}
1
+ {"version":3,"file":"json_schema.d.ts","names":[],"sources":["../../src/utils/json_schema.ts"],"mappings":";;;;;;;;;;;;;KAoBY,kBAAA,GAAqB,WAAA,CAC/B,UAAA,QAAkB,YAAA;;;;;;;iBASJ,YAAA,CACd,MAAA,EAAQ,oBAAA,GAAuB,cAAA,GAAiB,eAAA,EAChD,MAAA,GAAS,kBAAA,GACR,eAAA;AAbH;;;;;;;AAAA,iBA4CgB,oBAAA,CAAqB,MAAA"}
@@ -2,6 +2,7 @@ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { interopZodObjectStrict, interopZodTransformInputSchema, isZodObjectV4, isZodSchemaV3, isZodSchemaV4 } from "./types/zod.js";
3
3
  import { zodToJsonSchema } from "./zod-to-json-schema/zodToJsonSchema.js";
4
4
  import "./zod-to-json-schema/index.js";
5
+ import { isStandardJsonSchema } from "./standard_schema.js";
5
6
  import { toJSONSchema } from "zod/v4/core";
6
7
  import { Validator, deepCompareStrict, dereference } from "@cfworker/json-schema";
7
8
 
@@ -13,12 +14,13 @@ var json_schema_exports = /* @__PURE__ */ __exportAll({
13
14
  validatesOnlyStrings: () => validatesOnlyStrings
14
15
  });
15
16
  /**
16
- * Converts a Zod schema or JSON schema to a JSON schema.
17
+ * Converts a Standard JSON schema, Zod schema or JSON schema to a JSON schema.
17
18
  * @param schema - The schema to convert.
18
19
  * @param params - The parameters to pass to the toJSONSchema function.
19
20
  * @returns The converted schema.
20
21
  */
21
22
  function toJsonSchema(schema, params) {
23
+ if (isStandardJsonSchema(schema) && !isZodSchemaV4(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-07" });
22
24
  if (isZodSchemaV4(schema)) {
23
25
  const inputSchema = interopZodTransformInputSchema(schema, true);
24
26
  if (isZodObjectV4(inputSchema)) return toJSONSchema(interopZodObjectStrict(inputSchema, true), params);
@@ -1 +1 @@
1
- {"version":3,"file":"json_schema.js","names":[],"sources":["../../src/utils/json_schema.ts"],"sourcesContent":["import { toJSONSchema } from \"zod/v4/core\";\nimport { dereference, type Schema } from \"@cfworker/json-schema\";\nimport {\n isZodSchemaV3,\n isZodSchemaV4,\n InteropZodType,\n interopZodObjectStrict,\n isZodObjectV4,\n ZodObjectV4,\n interopZodTransformInputSchema,\n} from \"./types/zod.js\";\nimport {\n type JsonSchema7Type as JSONSchema,\n zodToJsonSchema,\n} from \"./zod-to-json-schema/index.js\";\n\nexport { deepCompareStrict, Validator } from \"@cfworker/json-schema\";\n\nexport type ToJSONSchemaParams = NonNullable<\n Parameters<typeof toJSONSchema>[1]\n>;\n\n/**\n * Converts a Zod schema or JSON schema to a JSON schema.\n * @param schema - The schema to convert.\n * @param params - The parameters to pass to the toJSONSchema function.\n * @returns The converted schema.\n */\nexport function toJsonSchema(\n schema: InteropZodType | JSONSchema,\n params?: ToJSONSchemaParams\n): JSONSchema {\n if (isZodSchemaV4(schema)) {\n const inputSchema = interopZodTransformInputSchema(schema, true);\n if (isZodObjectV4(inputSchema)) {\n const strictSchema = interopZodObjectStrict(\n inputSchema,\n true\n ) as ZodObjectV4;\n return toJSONSchema(strictSchema, params);\n } else {\n return toJSONSchema(schema, params);\n }\n }\n if (isZodSchemaV3(schema)) {\n return zodToJsonSchema(schema);\n }\n return schema as JSONSchema;\n}\n\n/**\n * Validates if a JSON schema validates only strings. May return false negatives in some edge cases\n * (like recursive or unresolvable refs).\n *\n * @param schema - The schema to validate.\n * @returns `true` if the schema validates only strings, `false` otherwise.\n */\nexport function validatesOnlyStrings(schema: unknown): boolean {\n // Null, undefined, or empty schema\n if (\n !schema ||\n typeof schema !== \"object\" ||\n Object.keys(schema).length === 0 ||\n Array.isArray(schema)\n ) {\n return false; // Validates anything, not just strings\n }\n\n // Explicit type constraint\n if (\"type\" in schema) {\n if (typeof schema.type === \"string\") {\n return schema.type === \"string\";\n }\n\n if (Array.isArray(schema.type)) {\n // not sure why someone would do `\"type\": [\"string\"]` or especially `\"type\": [\"string\",\n // \"string\", \"string\", ...]` but we're not here to judge\n return schema.type.every((t) => t === \"string\");\n }\n return false; // Invalid or non-string type\n }\n\n // Enum with only string values\n if (\"enum\" in schema) {\n return (\n Array.isArray(schema.enum) &&\n schema.enum.length > 0 &&\n schema.enum.every((val) => typeof val === \"string\")\n );\n }\n\n // String constant\n if (\"const\" in schema) {\n return typeof schema.const === \"string\";\n }\n\n // Schema combinations\n if (\"allOf\" in schema && Array.isArray(schema.allOf)) {\n // If any subschema validates only strings, then the overall schema validates only strings\n return schema.allOf.some((subschema) => validatesOnlyStrings(subschema));\n }\n\n if (\n (\"anyOf\" in schema && Array.isArray(schema.anyOf)) ||\n (\"oneOf\" in schema && Array.isArray(schema.oneOf))\n ) {\n const subschemas = (\n \"anyOf\" in schema ? schema.anyOf : schema.oneOf\n ) as unknown[];\n\n // All subschemas must validate only strings\n return (\n subschemas.length > 0 &&\n subschemas.every((subschema) => validatesOnlyStrings(subschema))\n );\n }\n\n // We're not going to try on this one, it's too complex - we just assume if it has a \"not\" key and hasn't matched one of the above checks, it's not a string schema.\n if (\"not\" in schema) {\n return false; // The not case can validate non-strings\n }\n\n if (\"$ref\" in schema && typeof schema.$ref === \"string\") {\n const ref = schema.$ref as string;\n const resolved = dereference(schema as Schema);\n if (resolved[ref]) {\n return validatesOnlyStrings(resolved[ref]);\n }\n return false;\n }\n\n // ignore recursive refs and other cases where type is omitted for now\n // ignore other cases for now where type is omitted\n\n return false;\n}\n\n// Re-export of the types used throughout langchain for json schema serialization.\n// The plan is to eventually nix zod-to-json-schema altogether in place for\n// zod v4 / a more standardized way of serializing validated inputs, so its re-exported\n// here to remove the dependency on zod-to-json-schema in downstream packages until\n// a determination is made.\n\nexport {\n type JsonSchema7Type,\n type JsonSchema7Type as JSONSchema,\n type JsonSchema7ArrayType,\n type JsonSchema7ObjectType,\n type JsonSchema7StringType,\n type JsonSchema7NumberType,\n type JsonSchema7NullableType,\n} from \"./zod-to-json-schema/index.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,aACd,QACA,QACY;AACZ,KAAI,cAAc,OAAO,EAAE;EACzB,MAAM,cAAc,+BAA+B,QAAQ,KAAK;AAChE,MAAI,cAAc,YAAY,CAK5B,Q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.ts"],"sourcesContent":["import { toJSONSchema } from \"zod/v4/core\";\nimport { dereference, type Schema } from \"@cfworker/json-schema\";\nimport {\n isZodSchemaV3,\n isZodSchemaV4,\n InteropZodType,\n interopZodObjectStrict,\n isZodObjectV4,\n ZodObjectV4,\n interopZodTransformInputSchema,\n} from \"./types/zod.js\";\nimport {\n type JsonSchema7Type as JSONSchema,\n zodToJsonSchema,\n} from \"./zod-to-json-schema/index.js\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { isStandardJsonSchema } from \"./standard_schema.js\";\n\nexport { deepCompareStrict, Validator } from \"@cfworker/json-schema\";\n\nexport type ToJSONSchemaParams = NonNullable<\n Parameters<typeof toJSONSchema>[1]\n>;\n\n/**\n * Converts a Standard JSON schema, Zod schema or JSON schema to a JSON schema.\n * @param schema - The schema to convert.\n * @param params - The parameters to pass to the toJSONSchema function.\n * @returns The converted schema.\n */\nexport function toJsonSchema(\n schema: StandardJSONSchemaV1 | InteropZodType | JSONSchema,\n params?: ToJSONSchemaParams\n): JSONSchema {\n if (isStandardJsonSchema(schema) && !isZodSchemaV4(schema)) {\n return schema[\"~standard\"].jsonSchema.input({\n target: \"draft-07\",\n }) as JSONSchema;\n }\n if (isZodSchemaV4(schema)) {\n const inputSchema = interopZodTransformInputSchema(schema, true);\n if (isZodObjectV4(inputSchema)) {\n const strictSchema = interopZodObjectStrict(\n inputSchema,\n true\n ) as ZodObjectV4;\n return toJSONSchema(strictSchema, params);\n } else {\n return toJSONSchema(schema, params);\n }\n }\n if (isZodSchemaV3(schema)) {\n return zodToJsonSchema(schema);\n }\n return schema as JSONSchema;\n}\n\n/**\n * Validates if a JSON schema validates only strings. May return false negatives in some edge cases\n * (like recursive or unresolvable refs).\n *\n * @param schema - The schema to validate.\n * @returns `true` if the schema validates only strings, `false` otherwise.\n */\nexport function validatesOnlyStrings(schema: unknown): boolean {\n // Null, undefined, or empty schema\n if (\n !schema ||\n typeof schema !== \"object\" ||\n Object.keys(schema).length === 0 ||\n Array.isArray(schema)\n ) {\n return false; // Validates anything, not just strings\n }\n\n // Explicit type constraint\n if (\"type\" in schema) {\n if (typeof schema.type === \"string\") {\n return schema.type === \"string\";\n }\n\n if (Array.isArray(schema.type)) {\n // not sure why someone would do `\"type\": [\"string\"]` or especially `\"type\": [\"string\",\n // \"string\", \"string\", ...]` but we're not here to judge\n return schema.type.every((t) => t === \"string\");\n }\n return false; // Invalid or non-string type\n }\n\n // Enum with only string values\n if (\"enum\" in schema) {\n return (\n Array.isArray(schema.enum) &&\n schema.enum.length > 0 &&\n schema.enum.every((val) => typeof val === \"string\")\n );\n }\n\n // String constant\n if (\"const\" in schema) {\n return typeof schema.const === \"string\";\n }\n\n // Schema combinations\n if (\"allOf\" in schema && Array.isArray(schema.allOf)) {\n // If any subschema validates only strings, then the overall schema validates only strings\n return schema.allOf.some((subschema) => validatesOnlyStrings(subschema));\n }\n\n if (\n (\"anyOf\" in schema && Array.isArray(schema.anyOf)) ||\n (\"oneOf\" in schema && Array.isArray(schema.oneOf))\n ) {\n const subschemas = (\n \"anyOf\" in schema ? schema.anyOf : schema.oneOf\n ) as unknown[];\n\n // All subschemas must validate only strings\n return (\n subschemas.length > 0 &&\n subschemas.every((subschema) => validatesOnlyStrings(subschema))\n );\n }\n\n // We're not going to try on this one, it's too complex - we just assume if it has a \"not\" key and hasn't matched one of the above checks, it's not a string schema.\n if (\"not\" in schema) {\n return false; // The not case can validate non-strings\n }\n\n if (\"$ref\" in schema && typeof schema.$ref === \"string\") {\n const ref = schema.$ref as string;\n const resolved = dereference(schema as Schema);\n if (resolved[ref]) {\n return validatesOnlyStrings(resolved[ref]);\n }\n return false;\n }\n\n // ignore recursive refs and other cases where type is omitted for now\n // ignore other cases for now where type is omitted\n\n return false;\n}\n\n// Re-export of the types used throughout langchain for json schema serialization.\n// The plan is to eventually nix zod-to-json-schema altogether in place for\n// zod v4 / a more standardized way of serializing validated inputs, so its re-exported\n// here to remove the dependency on zod-to-json-schema in downstream packages until\n// a determination is made.\n\nexport {\n type JsonSchema7Type,\n type JsonSchema7Type as JSONSchema,\n type JsonSchema7ArrayType,\n type JsonSchema7ObjectType,\n type JsonSchema7StringType,\n type JsonSchema7NumberType,\n type JsonSchema7NullableType,\n} from \"./zod-to-json-schema/index.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,aACd,QACA,QACY;AACZ,KAAI,qBAAqB,OAAO,IAAI,CAAC,cAAc,OAAO,CACxD,QAAO,OAAO,aAAa,WAAW,MAAM,EAC1C,QAAQ,YACT,CAAC;AAEJ,KAAI,cAAc,OAAO,EAAE;EACzB,MAAM,cAAc,+BAA+B,QAAQ,KAAK;AAChE,MAAI,cAAc,YAAY,CAK5B,QAAO,aAJc,uBACnB,aACA,KACD,EACiC,OAAO;MAEzC,QAAO,aAAa,QAAQ,OAAO;;AAGvC,KAAI,cAAc,OAAO,CACvB,QAAO,gBAAgB,OAAO;AAEhC,QAAO;;;;;;;;;AAUT,SAAgB,qBAAqB,QAA0B;AAE7D,KACE,CAAC,UACD,OAAO,WAAW,YAClB,OAAO,KAAK,OAAO,CAAC,WAAW,KAC/B,MAAM,QAAQ,OAAO,CAErB,QAAO;AAIT,KAAI,UAAU,QAAQ;AACpB,MAAI,OAAO,OAAO,SAAS,SACzB,QAAO,OAAO,SAAS;AAGzB,MAAI,MAAM,QAAQ,OAAO,KAAK,CAG5B,QAAO,OAAO,KAAK,OAAO,MAAM,MAAM,SAAS;AAEjD,SAAO;;AAIT,KAAI,UAAU,OACZ,QACE,MAAM,QAAQ,OAAO,KAAK,IAC1B,OAAO,KAAK,SAAS,KACrB,OAAO,KAAK,OAAO,QAAQ,OAAO,QAAQ,SAAS;AAKvD,KAAI,WAAW,OACb,QAAO,OAAO,OAAO,UAAU;AAIjC,KAAI,WAAW,UAAU,MAAM,QAAQ,OAAO,MAAM,CAElD,QAAO,OAAO,MAAM,MAAM,cAAc,qBAAqB,UAAU,CAAC;AAG1E,KACG,WAAW,UAAU,MAAM,QAAQ,OAAO,MAAM,IAChD,WAAW,UAAU,MAAM,QAAQ,OAAO,MAAM,EACjD;EACA,MAAM,aACJ,WAAW,SAAS,OAAO,QAAQ,OAAO;AAI5C,SACE,WAAW,SAAS,KACpB,WAAW,OAAO,cAAc,qBAAqB,UAAU,CAAC;;AAKpE,KAAI,SAAS,OACX,QAAO;AAGT,KAAI,UAAU,UAAU,OAAO,OAAO,SAAS,UAAU;EACvD,MAAM,MAAM,OAAO;EACnB,MAAM,WAAW,YAAY,OAAiB;AAC9C,MAAI,SAAS,KACX,QAAO,qBAAqB,SAAS,KAAK;AAE5C,SAAO;;AAMT,QAAO"}
@@ -0,0 +1,43 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+
4
+ //#region src/utils/standard_schema.ts
5
+ var standard_schema_exports = /* @__PURE__ */ require_runtime.__exportAll({
6
+ isSerializableSchema: () => isSerializableSchema,
7
+ isStandardJsonSchema: () => isStandardJsonSchema,
8
+ isStandardSchema: () => isStandardSchema
9
+ });
10
+ /**
11
+ * Type guard for Standard Schema V1. Returns true if the value has a `~standard.validate`
12
+ * interface, indicating it can validate unknown values at runtime (e.g. for parsing LLM output).
13
+ */
14
+ function isStandardSchema(schema) {
15
+ return (typeof schema === "object" || typeof schema === "function") && schema !== null && "~standard" in schema && typeof schema["~standard"] === "object" && schema["~standard"] !== null && "validate" in schema["~standard"];
16
+ }
17
+ /**
18
+ * Type guard for Standard JSON Schema V1. Returns true if the value has a `~standard.jsonSchema`
19
+ * interface, indicating it can be converted to a JSON Schema object (e.g. for sending as a tool
20
+ * definition to an LLM).
21
+ */
22
+ function isStandardJsonSchema(schema) {
23
+ return (typeof schema === "object" || typeof schema === "function") && schema !== null && "~standard" in schema && typeof schema["~standard"] === "object" && schema["~standard"] !== null && "jsonSchema" in schema["~standard"];
24
+ }
25
+ /**
26
+ * Type guard for Standard Schema V1. Returns true if the value has a `~standard.validate` interface,
27
+ * indicating it can validate unknown values at runtime (e.g. for parsing LLM output).
28
+ */
29
+ function isSerializableSchema(schema) {
30
+ return isStandardSchema(schema) && isStandardJsonSchema(schema);
31
+ }
32
+
33
+ //#endregion
34
+ exports.isSerializableSchema = isSerializableSchema;
35
+ exports.isStandardJsonSchema = isStandardJsonSchema;
36
+ exports.isStandardSchema = isStandardSchema;
37
+ Object.defineProperty(exports, 'standard_schema_exports', {
38
+ enumerable: true,
39
+ get: function () {
40
+ return standard_schema_exports;
41
+ }
42
+ });
43
+ //# sourceMappingURL=standard_schema.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard_schema.cjs","names":[],"sources":["../../src/utils/standard_schema.ts"],"sourcesContent":["import { StandardJSONSchemaV1, StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * A schema that supports both runtime validation and JSON Schema generation. Any schema passed\n * to withStructuredOutput must satisfy both interfaces.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type SerializableSchema<Input = any, Output = Input> = StandardSchemaV1<\n Input,\n Output\n> &\n StandardJSONSchemaV1<Input, Output>;\n\n/**\n * Type guard for Standard Schema V1. Returns true if the value has a `~standard.validate`\n * interface, indicating it can validate unknown values at runtime (e.g. for parsing LLM output).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isStandardSchema<Input = any, Output = Input>(\n schema: unknown\n): schema is StandardSchemaV1<Input, Output> {\n return (\n (typeof schema === \"object\" || typeof schema === \"function\") &&\n schema !== null &&\n \"~standard\" in schema &&\n typeof schema[\"~standard\"] === \"object\" &&\n schema[\"~standard\"] !== null &&\n \"validate\" in schema[\"~standard\"]\n );\n}\n\n/**\n * Type guard for Standard JSON Schema V1. Returns true if the value has a `~standard.jsonSchema`\n * interface, indicating it can be converted to a JSON Schema object (e.g. for sending as a tool\n * definition to an LLM).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isStandardJsonSchema<Input = any, Output = Input>(\n schema: unknown\n): schema is StandardJSONSchemaV1<Input, Output> {\n return (\n (typeof schema === \"object\" || typeof schema === \"function\") &&\n schema !== null &&\n \"~standard\" in schema &&\n typeof schema[\"~standard\"] === \"object\" &&\n schema[\"~standard\"] !== null &&\n \"jsonSchema\" in schema[\"~standard\"]\n );\n}\n\n/**\n * Type guard for Standard Schema V1. Returns true if the value has a `~standard.validate` interface,\n * indicating it can validate unknown values at runtime (e.g. for parsing LLM output).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isSerializableSchema<Input = any, Output = Input>(\n schema: unknown\n): schema is SerializableSchema<Input, Output> {\n return isStandardSchema(schema) && isStandardJsonSchema(schema);\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,SAAgB,iBACd,QAC2C;AAC3C,SACG,OAAO,WAAW,YAAY,OAAO,WAAW,eACjD,WAAW,QACX,eAAe,UACf,OAAO,OAAO,iBAAiB,YAC/B,OAAO,iBAAiB,QACxB,cAAc,OAAO;;;;;;;AAUzB,SAAgB,qBACd,QAC+C;AAC/C,SACG,OAAO,WAAW,YAAY,OAAO,WAAW,eACjD,WAAW,QACX,eAAe,UACf,OAAO,OAAO,iBAAiB,YAC/B,OAAO,iBAAiB,QACxB,gBAAgB,OAAO;;;;;;AAS3B,SAAgB,qBACd,QAC6C;AAC7C,QAAO,iBAAiB,OAAO,IAAI,qBAAqB,OAAO"}
@@ -0,0 +1,27 @@
1
+ import { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec";
2
+
3
+ //#region src/utils/standard_schema.d.ts
4
+ /**
5
+ * A schema that supports both runtime validation and JSON Schema generation. Any schema passed
6
+ * to withStructuredOutput must satisfy both interfaces.
7
+ */
8
+ type SerializableSchema<Input = any, Output = Input> = StandardSchemaV1<Input, Output> & StandardJSONSchemaV1<Input, Output>;
9
+ /**
10
+ * Type guard for Standard Schema V1. Returns true if the value has a `~standard.validate`
11
+ * interface, indicating it can validate unknown values at runtime (e.g. for parsing LLM output).
12
+ */
13
+ declare function isStandardSchema<Input = any, Output = Input>(schema: unknown): schema is StandardSchemaV1<Input, Output>;
14
+ /**
15
+ * Type guard for Standard JSON Schema V1. Returns true if the value has a `~standard.jsonSchema`
16
+ * interface, indicating it can be converted to a JSON Schema object (e.g. for sending as a tool
17
+ * definition to an LLM).
18
+ */
19
+ declare function isStandardJsonSchema<Input = any, Output = Input>(schema: unknown): schema is StandardJSONSchemaV1<Input, Output>;
20
+ /**
21
+ * Type guard for Standard Schema V1. Returns true if the value has a `~standard.validate` interface,
22
+ * indicating it can validate unknown values at runtime (e.g. for parsing LLM output).
23
+ */
24
+ declare function isSerializableSchema<Input = any, Output = Input>(schema: unknown): schema is SerializableSchema<Input, Output>;
25
+ //#endregion
26
+ export { SerializableSchema, isSerializableSchema, isStandardJsonSchema, isStandardSchema };
27
+ //# sourceMappingURL=standard_schema.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard_schema.d.cts","names":[],"sources":["../../src/utils/standard_schema.ts"],"mappings":";;;;;AAOA;;KAAY,kBAAA,uBAAyC,KAAA,IAAS,gBAAA,CAC5D,KAAA,EACA,MAAA,IAEA,oBAAA,CAAqB,KAAA,EAAO,MAAA;;;;;iBAOd,gBAAA,uBAAuC,KAAA,CAAA,CACrD,MAAA,YACC,MAAA,IAAU,gBAAA,CAAiB,KAAA,EAAO,MAAA;;;;;;iBAiBrB,oBAAA,uBAA2C,KAAA,CAAA,CACzD,MAAA,YACC,MAAA,IAAU,oBAAA,CAAqB,KAAA,EAAO,MAAA;;;;;iBAgBzB,oBAAA,uBAA2C,KAAA,CAAA,CACzD,MAAA,YACC,MAAA,IAAU,kBAAA,CAAmB,KAAA,EAAO,MAAA"}
@@ -0,0 +1,27 @@
1
+ import { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec";
2
+
3
+ //#region src/utils/standard_schema.d.ts
4
+ /**
5
+ * A schema that supports both runtime validation and JSON Schema generation. Any schema passed
6
+ * to withStructuredOutput must satisfy both interfaces.
7
+ */
8
+ type SerializableSchema<Input = any, Output = Input> = StandardSchemaV1<Input, Output> & StandardJSONSchemaV1<Input, Output>;
9
+ /**
10
+ * Type guard for Standard Schema V1. Returns true if the value has a `~standard.validate`
11
+ * interface, indicating it can validate unknown values at runtime (e.g. for parsing LLM output).
12
+ */
13
+ declare function isStandardSchema<Input = any, Output = Input>(schema: unknown): schema is StandardSchemaV1<Input, Output>;
14
+ /**
15
+ * Type guard for Standard JSON Schema V1. Returns true if the value has a `~standard.jsonSchema`
16
+ * interface, indicating it can be converted to a JSON Schema object (e.g. for sending as a tool
17
+ * definition to an LLM).
18
+ */
19
+ declare function isStandardJsonSchema<Input = any, Output = Input>(schema: unknown): schema is StandardJSONSchemaV1<Input, Output>;
20
+ /**
21
+ * Type guard for Standard Schema V1. Returns true if the value has a `~standard.validate` interface,
22
+ * indicating it can validate unknown values at runtime (e.g. for parsing LLM output).
23
+ */
24
+ declare function isSerializableSchema<Input = any, Output = Input>(schema: unknown): schema is SerializableSchema<Input, Output>;
25
+ //#endregion
26
+ export { SerializableSchema, isSerializableSchema, isStandardJsonSchema, isStandardSchema };
27
+ //# sourceMappingURL=standard_schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard_schema.d.ts","names":[],"sources":["../../src/utils/standard_schema.ts"],"mappings":";;;;;AAOA;;KAAY,kBAAA,uBAAyC,KAAA,IAAS,gBAAA,CAC5D,KAAA,EACA,MAAA,IAEA,oBAAA,CAAqB,KAAA,EAAO,MAAA;;;;;iBAOd,gBAAA,uBAAuC,KAAA,CAAA,CACrD,MAAA,YACC,MAAA,IAAU,gBAAA,CAAiB,KAAA,EAAO,MAAA;;;;;;iBAiBrB,oBAAA,uBAA2C,KAAA,CAAA,CACzD,MAAA,YACC,MAAA,IAAU,oBAAA,CAAqB,KAAA,EAAO,MAAA;;;;;iBAgBzB,oBAAA,uBAA2C,KAAA,CAAA,CACzD,MAAA,YACC,MAAA,IAAU,kBAAA,CAAmB,KAAA,EAAO,MAAA"}
@@ -0,0 +1,34 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+
3
+ //#region src/utils/standard_schema.ts
4
+ var standard_schema_exports = /* @__PURE__ */ __exportAll({
5
+ isSerializableSchema: () => isSerializableSchema,
6
+ isStandardJsonSchema: () => isStandardJsonSchema,
7
+ isStandardSchema: () => isStandardSchema
8
+ });
9
+ /**
10
+ * Type guard for Standard Schema V1. Returns true if the value has a `~standard.validate`
11
+ * interface, indicating it can validate unknown values at runtime (e.g. for parsing LLM output).
12
+ */
13
+ function isStandardSchema(schema) {
14
+ return (typeof schema === "object" || typeof schema === "function") && schema !== null && "~standard" in schema && typeof schema["~standard"] === "object" && schema["~standard"] !== null && "validate" in schema["~standard"];
15
+ }
16
+ /**
17
+ * Type guard for Standard JSON Schema V1. Returns true if the value has a `~standard.jsonSchema`
18
+ * interface, indicating it can be converted to a JSON Schema object (e.g. for sending as a tool
19
+ * definition to an LLM).
20
+ */
21
+ function isStandardJsonSchema(schema) {
22
+ return (typeof schema === "object" || typeof schema === "function") && schema !== null && "~standard" in schema && typeof schema["~standard"] === "object" && schema["~standard"] !== null && "jsonSchema" in schema["~standard"];
23
+ }
24
+ /**
25
+ * Type guard for Standard Schema V1. Returns true if the value has a `~standard.validate` interface,
26
+ * indicating it can validate unknown values at runtime (e.g. for parsing LLM output).
27
+ */
28
+ function isSerializableSchema(schema) {
29
+ return isStandardSchema(schema) && isStandardJsonSchema(schema);
30
+ }
31
+
32
+ //#endregion
33
+ export { isSerializableSchema, isStandardJsonSchema, isStandardSchema, standard_schema_exports };
34
+ //# sourceMappingURL=standard_schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard_schema.js","names":[],"sources":["../../src/utils/standard_schema.ts"],"sourcesContent":["import { StandardJSONSchemaV1, StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * A schema that supports both runtime validation and JSON Schema generation. Any schema passed\n * to withStructuredOutput must satisfy both interfaces.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type SerializableSchema<Input = any, Output = Input> = StandardSchemaV1<\n Input,\n Output\n> &\n StandardJSONSchemaV1<Input, Output>;\n\n/**\n * Type guard for Standard Schema V1. Returns true if the value has a `~standard.validate`\n * interface, indicating it can validate unknown values at runtime (e.g. for parsing LLM output).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isStandardSchema<Input = any, Output = Input>(\n schema: unknown\n): schema is StandardSchemaV1<Input, Output> {\n return (\n (typeof schema === \"object\" || typeof schema === \"function\") &&\n schema !== null &&\n \"~standard\" in schema &&\n typeof schema[\"~standard\"] === \"object\" &&\n schema[\"~standard\"] !== null &&\n \"validate\" in schema[\"~standard\"]\n );\n}\n\n/**\n * Type guard for Standard JSON Schema V1. Returns true if the value has a `~standard.jsonSchema`\n * interface, indicating it can be converted to a JSON Schema object (e.g. for sending as a tool\n * definition to an LLM).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isStandardJsonSchema<Input = any, Output = Input>(\n schema: unknown\n): schema is StandardJSONSchemaV1<Input, Output> {\n return (\n (typeof schema === \"object\" || typeof schema === \"function\") &&\n schema !== null &&\n \"~standard\" in schema &&\n typeof schema[\"~standard\"] === \"object\" &&\n schema[\"~standard\"] !== null &&\n \"jsonSchema\" in schema[\"~standard\"]\n );\n}\n\n/**\n * Type guard for Standard Schema V1. Returns true if the value has a `~standard.validate` interface,\n * indicating it can validate unknown values at runtime (e.g. for parsing LLM output).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isSerializableSchema<Input = any, Output = Input>(\n schema: unknown\n): schema is SerializableSchema<Input, Output> {\n return isStandardSchema(schema) && isStandardJsonSchema(schema);\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,SAAgB,iBACd,QAC2C;AAC3C,SACG,OAAO,WAAW,YAAY,OAAO,WAAW,eACjD,WAAW,QACX,eAAe,UACf,OAAO,OAAO,iBAAiB,YAC/B,OAAO,iBAAiB,QACxB,cAAc,OAAO;;;;;;;AAUzB,SAAgB,qBACd,QAC+C;AAC/C,SACG,OAAO,WAAW,YAAY,OAAO,WAAW,eACjD,WAAW,QACX,eAAe,UACf,OAAO,OAAO,iBAAiB,YAC/B,OAAO,iBAAiB,QACxB,gBAAgB,OAAO;;;;;;AAS3B,SAAgB,qBACd,QAC6C;AAC7C,QAAO,iBAAiB,OAAO,IAAI,qBAAqB,OAAO"}
@@ -136,7 +136,7 @@ function interopParse(schema, input) {
136
136
  throw new Error("Schema must be an instance of z3.ZodType or z4.$ZodType");
137
137
  }
138
138
  /**
139
- * Retrieves the description from a schema definition (v3, v4, or plain object), if available.
139
+ * Retrieves the description from a schema definition (v3, v4, standard schema, or plain object), if available.
140
140
  *
141
141
  * @param {unknown} schema - The schema to extract the description from.
142
142
  * @returns {string | undefined} The description of the schema, or undefined if not present.