(schema: Schema.Top)
| 6 | const cache = new WeakMap<Schema.Top, JSONSchema7>() |
| 7 | |
| 8 | export function fromSchema(schema: Schema.Top): JSONSchema7 { |
| 9 | const cached = cache.get(schema) |
| 10 | if (cached) return cached |
| 11 | |
| 12 | const document = Schema.toJsonSchemaDocument(schema, { additionalProperties: true }) |
| 13 | const result = normalize({ |
| 14 | $schema: JsonSchema.META_SCHEMA_URI_DRAFT_2020_12, |
| 15 | ...document.schema, |
| 16 | ...(Object.keys(document.definitions).length > 0 ? { $defs: document.definitions } : {}), |
| 17 | }) |
| 18 | const inlined = dropDefinitionsIfResolved(inlineLocalReferences(result)) |
| 19 | if (!isJsonSchema(inlined)) throw new Error("tool JSON Schema helper produced a non-schema value") |
| 20 | cache.set(schema, inlined) |
| 21 | return inlined |
| 22 | } |
| 23 | |
| 24 | export function fromTool(tool: Tool.Def): JSONSchema7 { |
| 25 | return tool.jsonSchema ?? fromSchema(tool.parameters as Schema.Top) |
no test coverage detected