mirascope 2.0.0-alpha.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 (46) hide show
  1. package/README.md +397 -0
  2. package/dist/bun.cjs +447 -0
  3. package/dist/bun.cjs.map +1 -0
  4. package/dist/bun.d.cts +53 -0
  5. package/dist/bun.d.ts +53 -0
  6. package/dist/bun.js +94 -0
  7. package/dist/bun.js.map +1 -0
  8. package/dist/chunk-2R5IW35Y.js +116 -0
  9. package/dist/chunk-2R5IW35Y.js.map +1 -0
  10. package/dist/chunk-A6ZCB7BU.js +6826 -0
  11. package/dist/chunk-A6ZCB7BU.js.map +1 -0
  12. package/dist/chunk-NSBPE2FW.js +15 -0
  13. package/dist/chunk-NSBPE2FW.js.map +1 -0
  14. package/dist/chunk-RMNCGJYW.js +49 -0
  15. package/dist/chunk-RMNCGJYW.js.map +1 -0
  16. package/dist/chunk-U4MFJ4DP.js +358 -0
  17. package/dist/chunk-U4MFJ4DP.js.map +1 -0
  18. package/dist/index.cjs +7705 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.cts +4859 -0
  21. package/dist/index.d.ts +4859 -0
  22. package/dist/index.js +324 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/model-T6IQ7UUA.js +4 -0
  25. package/dist/model-T6IQ7UUA.js.map +1 -0
  26. package/dist/tool-schema-Dh-RLHhC.d.cts +45 -0
  27. package/dist/tool-schema-Dh-RLHhC.d.ts +45 -0
  28. package/dist/transform/index.cjs +525 -0
  29. package/dist/transform/index.cjs.map +1 -0
  30. package/dist/transform/index.d.cts +89 -0
  31. package/dist/transform/index.d.ts +89 -0
  32. package/dist/transform/index.js +6 -0
  33. package/dist/transform/index.js.map +1 -0
  34. package/dist/transform/plugins/esbuild.cjs +472 -0
  35. package/dist/transform/plugins/esbuild.cjs.map +1 -0
  36. package/dist/transform/plugins/esbuild.d.cts +46 -0
  37. package/dist/transform/plugins/esbuild.d.ts +46 -0
  38. package/dist/transform/plugins/esbuild.js +5 -0
  39. package/dist/transform/plugins/esbuild.js.map +1 -0
  40. package/dist/transform/plugins/vite.cjs +405 -0
  41. package/dist/transform/plugins/vite.cjs.map +1 -0
  42. package/dist/transform/plugins/vite.d.cts +50 -0
  43. package/dist/transform/plugins/vite.d.ts +50 -0
  44. package/dist/transform/plugins/vite.js +5 -0
  45. package/dist/transform/plugins/vite.js.map +1 -0
  46. package/package.json +127 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/transform/type-to-schema.ts","../../../src/transform/transformer.ts","../../../src/transform/plugins/esbuild.ts"],"names":["ts","path","fs","result","transformedSourceFile","printer","outputText"],"mappings":";;;;;;;;;;;;;;;AAmCA,SAAS,eAAA,CAAgB,MAAe,OAAA,EAAkC;AAExE,EAAA,IAAI,IAAA,CAAK,QAAA,EAAS,GAAIA,oBAAA,CAAG,UAAU,MAAA,EAAQ;AACzC,IAAA,MAAM,UAAA,GAAa,IAAA;AACnB,IAAA,MAAM,cAAc,UAAA,CAAW,WAAA;AAG/B,IAAA,IAAI,WAAA,GAAcA,oBAAA,CAAG,WAAA,CAAY,SAAA,EAAW;AAC1C,MAAA,MAAM,OAAA,GAAU,IAAA;AAChB,MAAA,MAAM,SAAS,OAAA,CAAQ,MAAA;AACvB,MAAA,IAAI,MAAA,IAAU,MAAA,CAAO,OAAA,EAAQ,KAAM,OAAA,EAAS;AAC1C,QAAA,OAAO,IAAA;AAAA,MACT;AAEA,MAAA,MAAM,SAAS,OAAA,CAAQ,MAAA;AACvB,MAAA,IAAI,UAAU,MAAA,CAAO,MAAA,IAAU,OAAO,MAAA,CAAO,OAAA,OAAc,OAAA,EAAS;AAClE,QAAA,OAAO,IAAA;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAGA,EAAA,MAAM,UAAA,GAAa,OAAA,CAAQ,YAAA,CAAa,IAAI,CAAA;AAC5C,EAAA,IAAI,WAAW,QAAA,CAAS,IAAI,KAAK,UAAA,CAAW,UAA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MAAA,EAAQ,QAAA,CAAS,QAAA,CAAS,MAAM,IAAI,KAAA,GAAQ;AAAA,WAC9C;AAAA,QACF;AAAA,OACF;AAAA,IACF;AAAA,GACF;AACF;AAEA,IAAO,eAAA,GAAQ","file":"esbuild.cjs","sourcesContent":["/**\n * Convert TypeScript types to JSON Schema.\n *\n * Uses the TypeScript Compiler API to introspect types and generate\n * JSON Schema representations suitable for LLM tool definitions.\n */\n\nimport ts from \"typescript\";\n\nimport type { JsonSchemaProperty, ToolParameterSchema } from \"@/llm/tools\";\n\n/**\n * Context for type-to-schema conversion.\n */\ninterface ConversionContext {\n /** The TypeScript type checker. */\n checker: ts.TypeChecker;\n /** Definitions for referenced types ($defs). */\n definitions: Map<string, JsonSchemaProperty>;\n /** Set of type names currently being processed (for cycle detection). */\n processing: Set<string>;\n}\n\n/**\n * Check if a type is an array-like type (handles cases where isArrayType doesn't work).\n *\n * This is needed because TypeScript's isArrayType requires proper lib.d.ts setup.\n * We also check for Array<T> and T[] patterns by looking at the type structure.\n *\n * Coverage ignored: This is defensive fallback code for edge cases where\n * checker.isArrayType() fails due to missing/broken lib.d.ts. In normal\n * usage with proper TypeScript setup, checker.isArrayType() succeeds and\n * this function is never called (short-circuit evaluation on line 120).\n */\n/* v8 ignore start */\nfunction isArrayLikeType(type: ts.Type, checker: ts.TypeChecker): boolean {\n // Check if it's a TypeReference with 'Array' as the symbol name\n if (type.getFlags() & ts.TypeFlags.Object) {\n const objectType = type as ts.ObjectType;\n const objectFlags = objectType.objectFlags;\n\n // Check for array reference (Array<T>)\n if (objectFlags & ts.ObjectFlags.Reference) {\n const typeRef = type as ts.TypeReference;\n const symbol = typeRef.symbol;\n if (symbol && symbol.getName() === \"Array\") {\n return true;\n }\n // Also check the target's symbol for ReadonlyArray, etc.\n const target = typeRef.target;\n if (target && target.symbol && target.symbol.getName() === \"Array\") {\n return true;\n }\n }\n }\n\n // Check the type string as a fallback\n const typeString = checker.typeToString(type);\n if (typeString.endsWith(\"[]\") || typeString.startsWith(\"Array<\")) {\n return true;\n }\n\n return false;\n}\n/* v8 ignore end */\n\n/**\n * Convert a TypeScript type to a JSON Schema property.\n *\n * @param type - The TypeScript type to convert.\n * @param ctx - The conversion context.\n * @returns The JSON Schema property.\n */\nexport function typeToJsonSchema(\n type: ts.Type,\n ctx: ConversionContext,\n): JsonSchemaProperty {\n const checker = ctx.checker;\n\n // Handle union types (including optional which is T | undefined)\n if (type.isUnion()) {\n return handleUnionType(type, ctx);\n }\n\n // Handle intersection types\n if (type.isIntersection()) {\n return handleIntersectionType(type, ctx);\n }\n\n // Handle literal types\n if (type.isLiteral()) {\n return handleLiteralType(type);\n }\n\n // Handle boolean literals (true/false) - these aren't captured by isLiteral()\n // They are intrinsic types with BooleanLiteral flag\n const flags = type.getFlags();\n if (flags & ts.TypeFlags.BooleanLiteral) {\n const intrinsicName = (type as ts.Type & { intrinsicName?: string })\n .intrinsicName;\n const isTrue = intrinsicName === \"true\";\n return { type: \"boolean\", enum: [isTrue] };\n }\n\n // Handle primitive types\n\n if (flags & ts.TypeFlags.String) {\n return { type: \"string\" };\n }\n\n if (flags & ts.TypeFlags.Number) {\n return { type: \"number\" };\n }\n\n if (flags & ts.TypeFlags.Null) {\n return { type: \"null\" };\n }\n\n if (flags & ts.TypeFlags.Undefined) {\n // undefined is typically filtered out from unions\n return {};\n }\n\n // Handle array types\n // Check both checker.isArrayType and TypeReference patterns\n if (checker.isArrayType(type) || isArrayLikeType(type, checker)) {\n const typeRef = type as ts.TypeReference;\n const typeArgs = checker.getTypeArguments(typeRef);\n if (typeArgs && typeArgs.length > 0) {\n return {\n type: \"array\",\n items: typeToJsonSchema(typeArgs[0]!, ctx),\n };\n }\n // Coverage ignored: Fallback for arrays without type arguments (e.g., broken lib.d.ts)\n /* v8 ignore next */\n return { type: \"array\" };\n }\n\n // Handle object types (interfaces, type literals, classes)\n if (flags & ts.TypeFlags.Object) {\n return handleObjectType(type as ts.ObjectType, ctx);\n }\n\n /* v8 ignore start */\n return {};\n}\n/* v8 ignore end */\n\n/**\n * Handle union types, including optional types (T | undefined).\n */\nfunction handleUnionType(\n type: ts.UnionType,\n ctx: ConversionContext,\n): JsonSchemaProperty {\n const types = type.types;\n\n // Filter out undefined (for optional properties)\n const nonUndefinedTypes = types.filter(\n (t) => !(t.getFlags() & ts.TypeFlags.Undefined),\n );\n\n // Check if this is a boolean type (union of true | false)\n if (\n nonUndefinedTypes.length === 2 &&\n nonUndefinedTypes.every((t) => t.getFlags() & ts.TypeFlags.BooleanLiteral)\n ) {\n return { type: \"boolean\" };\n }\n\n // If all non-undefined types are string/number literals, create an enum\n if (\n nonUndefinedTypes.every((t): t is ts.StringLiteralType =>\n t.isStringLiteral(),\n )\n ) {\n return {\n type: \"string\",\n enum: nonUndefinedTypes.map((t) => t.value),\n };\n }\n\n if (\n nonUndefinedTypes.every((t): t is ts.NumberLiteralType =>\n t.isNumberLiteral(),\n )\n ) {\n return {\n type: \"number\",\n enum: nonUndefinedTypes.map((t) => t.value),\n };\n }\n\n // If only one non-undefined type remains, use it directly\n if (nonUndefinedTypes.length === 1) {\n return typeToJsonSchema(nonUndefinedTypes[0]!, ctx);\n }\n\n // Otherwise, create a oneOf schema\n return {\n oneOf: nonUndefinedTypes.map((t) => typeToJsonSchema(t, ctx)),\n };\n}\n\n/**\n * Handle intersection types by merging properties.\n */\nfunction handleIntersectionType(\n type: ts.IntersectionType,\n ctx: ConversionContext,\n): JsonSchemaProperty {\n const allOf = type.types.map((t) => typeToJsonSchema(t, ctx));\n\n // If all parts are objects, try to merge them\n if (allOf.every((s) => s.type === \"object\")) {\n const merged: JsonSchemaProperty = {\n type: \"object\",\n properties: {},\n required: [],\n };\n\n for (const schema of allOf) {\n if (schema.properties) {\n merged.properties = { ...merged.properties, ...schema.properties };\n }\n if (schema.required) {\n merged.required = [\n ...(merged.required as string[]),\n ...(schema.required as string[]),\n ];\n }\n }\n\n return merged;\n }\n\n return { allOf };\n}\n\n/**\n * Handle literal types (string, number literals).\n * Note: Boolean literals (true/false) are handled earlier via BooleanLiteral flag\n * since TypeScript's isLiteral() doesn't return true for them.\n */\nfunction handleLiteralType(type: ts.Type): JsonSchemaProperty {\n if (type.isStringLiteral()) {\n return { type: \"string\", enum: [type.value] };\n }\n\n if (type.isNumberLiteral()) {\n return { type: \"number\", enum: [type.value] };\n }\n\n /* v8 ignore start */\n return {};\n}\n/* v8 ignore end */\n\n/**\n * Handle object types (interfaces, type literals, classes).\n */\nfunction handleObjectType(\n type: ts.ObjectType,\n ctx: ConversionContext,\n): JsonSchemaProperty {\n const checker = ctx.checker;\n const properties: Record<string, JsonSchemaProperty> = {};\n const required: string[] = [];\n\n // Get all properties of the type\n const props = checker.getPropertiesOfType(type);\n\n for (const prop of props) {\n const propName = prop.getName();\n const propType = checker.getTypeOfSymbol(prop);\n\n // Check if the property is optional\n const isOptional = (prop.getFlags() & ts.SymbolFlags.Optional) !== 0;\n\n // Convert the property type to schema\n const propSchema = typeToJsonSchema(propType, ctx);\n\n // Extract JSDoc description from property declaration\n const jsDocComment = prop.getDocumentationComment(checker);\n if (jsDocComment.length > 0) {\n const description = jsDocComment.map((c) => c.text).join(\"\");\n propSchema.description = description;\n }\n\n properties[propName] = propSchema;\n\n // Add to required if not optional\n if (!isOptional) {\n required.push(propName);\n }\n }\n\n return {\n type: \"object\",\n properties,\n required: required.length > 0 ? required : undefined,\n };\n}\n\n/**\n * Convert a TypeScript type to a ToolParameterSchema.\n *\n * This is the main entry point for converting tool argument types\n * to the schema format expected by LLM providers.\n *\n * @param type - The TypeScript type to convert (should be an object type).\n * @param checker - The TypeScript type checker.\n * @returns The tool parameter schema.\n */\nexport function typeToToolParameterSchema(\n type: ts.Type,\n checker: ts.TypeChecker,\n): ToolParameterSchema {\n const ctx: ConversionContext = {\n checker,\n definitions: new Map(),\n processing: new Set(),\n };\n\n const schema = typeToJsonSchema(type, ctx);\n\n // Ensure the result is an object schema\n if (schema.type !== \"object\") {\n throw new Error(\n \"Tool parameter type must be an object type, got: \" +\n JSON.stringify(schema),\n );\n }\n\n // Build a mutable result, then return as readonly\n const result: {\n type: \"object\";\n properties: Record<string, JsonSchemaProperty>;\n required: readonly string[];\n additionalProperties: false;\n $defs?: Record<string, JsonSchemaProperty>;\n } = {\n type: \"object\",\n properties: schema.properties ?? {},\n required: (schema.required as readonly string[]) ?? [],\n additionalProperties: false,\n };\n\n // Coverage ignored: $defs only populated for recursive types (not yet implemented)\n /* v8 ignore start */\n if (ctx.definitions.size > 0) {\n result.$defs = Object.fromEntries(ctx.definitions);\n }\n /* v8 ignore end */\n\n return result;\n}\n\n/**\n * Create a ConversionContext for testing or manual use.\n */\nexport function createConversionContext(\n checker: ts.TypeChecker,\n): ConversionContext {\n return {\n checker,\n definitions: new Map(),\n processing: new Set(),\n };\n}\n","/**\n * TypeScript transformer for injecting schemas into tool and format definitions.\n *\n * This transformer finds calls to `defineTool<T>()`, `defineContextTool<T, DepsT>()`,\n * and `defineFormat<T>()` and injects the `__schema` property with the JSON schema\n * generated from type T.\n */\n\nimport ts from \"typescript\";\n\nimport { typeToToolParameterSchema } from \"./type-to-schema\";\n\n/**\n * Names of functions that should have schemas injected.\n */\nconst TOOL_FUNCTION_NAMES = new Set([\"defineTool\", \"defineContextTool\"]);\n\n/**\n * Names of format functions that should have schemas injected.\n */\nconst FORMAT_FUNCTION_NAMES = new Set([\"defineFormat\"]);\n\n/**\n * Create a TypeScript transformer that injects __schema into tool definitions.\n *\n * @param program - The TypeScript program.\n * @returns A transformer factory.\n */\nexport function createToolSchemaTransformer(\n program: ts.Program,\n): ts.TransformerFactory<ts.SourceFile> {\n const checker = program.getTypeChecker();\n\n return (context: ts.TransformationContext) => {\n return (sourceFile: ts.SourceFile) => {\n const visitor = (node: ts.Node): ts.Node => {\n // Look for call expressions\n if (ts.isCallExpression(node)) {\n // Try tool transform first\n const toolTransformed = tryTransformToolCall(node, checker, context);\n if (toolTransformed) {\n return toolTransformed;\n }\n\n // Try format transform\n const formatTransformed = tryTransformFormatCall(\n node,\n checker,\n context,\n );\n if (formatTransformed) {\n return formatTransformed;\n }\n }\n\n // Continue visiting children\n return ts.visitEachChild(node, visitor, context);\n };\n\n return ts.visitNode(sourceFile, visitor) as ts.SourceFile;\n };\n };\n}\n\n/**\n * Try to transform a call expression if it's a tool definition.\n *\n * @param node - The call expression node.\n * @param checker - The type checker.\n * @param context - The transformation context.\n * @returns The transformed node, or undefined if not a tool definition.\n */\nfunction tryTransformToolCall(\n node: ts.CallExpression,\n checker: ts.TypeChecker,\n context: ts.TransformationContext,\n): ts.CallExpression | undefined {\n // Check if this is a call to defineTool or defineContextTool\n const functionName = getFunctionName(node);\n if (!functionName || !TOOL_FUNCTION_NAMES.has(functionName)) {\n return undefined;\n }\n\n // Get the type arguments (the generic parameter T)\n const typeArgs = node.typeArguments;\n if (!typeArgs || typeArgs.length === 0) {\n // No type arguments - can't generate schema\n return undefined;\n }\n\n // Get the first type argument (T for args type)\n const argsTypeNode = typeArgs[0]!;\n const argsType = checker.getTypeFromTypeNode(argsTypeNode);\n\n // Generate the schema from the type\n let schema;\n try {\n schema = typeToToolParameterSchema(argsType, checker);\n } catch {\n // If schema generation fails, leave the call unchanged\n return undefined;\n }\n\n // Get the first argument (the options object)\n const args = node.arguments;\n const firstArg = args[0];\n if (!firstArg || !ts.isObjectLiteralExpression(firstArg)) {\n return undefined;\n }\n\n const optionsObject = firstArg;\n\n // Check if __schema is already present\n const hasSchema = optionsObject.properties.some(\n (prop) =>\n ts.isPropertyAssignment(prop) &&\n ts.isIdentifier(prop.name) &&\n prop.name.text === \"__schema\",\n );\n\n if (hasSchema) {\n // Already has a schema, don't override\n return undefined;\n }\n\n // Create the __schema property\n const schemaProperty = createSchemaProperty(schema, context.factory);\n\n // Create a new options object with __schema added\n const newProperties = [...optionsObject.properties, schemaProperty];\n const newOptionsObject = context.factory.updateObjectLiteralExpression(\n optionsObject,\n newProperties,\n );\n\n // Create a new call expression with the updated options\n const newArgs = [newOptionsObject, ...args.slice(1)];\n return context.factory.updateCallExpression(\n node,\n node.expression,\n node.typeArguments,\n newArgs,\n );\n}\n\n/**\n * Try to transform a call expression if it's a format definition.\n *\n * For defineFormat<T>(options):\n * - If the options arg is an object literal, inject __schema from type T\n * - If __schema is already present, leave unchanged\n * - If options has a validator, the validator's schema is used at runtime\n *\n * @param node - The call expression node.\n * @param checker - The type checker.\n * @param context - The transformation context.\n * @returns The transformed node, or undefined if not a format definition.\n */\nfunction tryTransformFormatCall(\n node: ts.CallExpression,\n checker: ts.TypeChecker,\n context: ts.TransformationContext,\n): ts.CallExpression | undefined {\n // Check if this is a call to defineFormat\n const functionName = getFunctionName(node);\n if (!functionName || !FORMAT_FUNCTION_NAMES.has(functionName)) {\n return undefined;\n }\n\n // Get the type arguments (the generic parameter T)\n const typeArgs = node.typeArguments;\n if (!typeArgs || typeArgs.length === 0) {\n // No type arguments - can't generate schema\n return undefined;\n }\n\n // Get the first type argument (T for the output type)\n const outputTypeNode = typeArgs[0]!;\n const outputType = checker.getTypeFromTypeNode(outputTypeNode);\n\n // Get the first argument\n const args = node.arguments;\n const firstArg = args[0];\n if (!firstArg) {\n return undefined;\n }\n\n // If first arg is an object literal (FormatSpec), inject __schema\n if (ts.isObjectLiteralExpression(firstArg)) {\n const formatSpecObject = firstArg;\n\n // Check if __schema is already present\n const hasSchema = formatSpecObject.properties.some(\n (prop) =>\n ts.isPropertyAssignment(prop) &&\n ts.isIdentifier(prop.name) &&\n prop.name.text === \"__schema\",\n );\n\n if (hasSchema) {\n // Already has a schema, don't override\n return undefined;\n }\n\n // Generate the schema from the type\n let schema;\n try {\n schema = typeToToolParameterSchema(outputType, checker);\n } catch {\n // If schema generation fails, leave the call unchanged\n return undefined;\n }\n\n // Create the __schema property\n const schemaProperty = createSchemaProperty(schema, context.factory);\n\n // Create a new format spec object with __schema added\n const newProperties = [...formatSpecObject.properties, schemaProperty];\n const newFormatSpecObject = context.factory.updateObjectLiteralExpression(\n formatSpecObject,\n newProperties,\n );\n\n // Create a new call expression with the updated format spec\n const newArgs = [newFormatSpecObject, ...args.slice(1)];\n return context.factory.updateCallExpression(\n node,\n node.expression,\n node.typeArguments,\n newArgs,\n );\n }\n\n // If first arg is not an object literal (e.g., a Zod schema identifier),\n // leave unchanged - Zod schemas handle their own schema generation\n return undefined;\n}\n\n/**\n * Get the function name from a call expression.\n */\n/* v8 ignore start */\nfunction getFunctionName(node: ts.CallExpression): string | undefined {\n const expression = node.expression;\n\n // Direct call: defineTool(...)\n if (ts.isIdentifier(expression)) {\n return expression.text;\n }\n\n // Property access: llm.defineTool(...)\n if (ts.isPropertyAccessExpression(expression)) {\n return expression.name.text;\n }\n\n return undefined;\n}\n/* v8 ignore end */\n\n/**\n * Create a __schema property assignment from a schema object.\n */\nfunction createSchemaProperty(\n schema: object,\n factory: ts.NodeFactory,\n): ts.PropertyAssignment {\n return factory.createPropertyAssignment(\n factory.createIdentifier(\"__schema\"),\n jsonToAst(schema, factory),\n );\n}\n\n/**\n * Convert a JSON value to a TypeScript AST expression.\n *\n * Coverage notes: Some branches are ignored because JSON Schema values\n * are always one of: null, string, number, boolean, array, or object.\n * The ignored branches handle edge cases that can't occur with valid schemas.\n */\nfunction jsonToAst(value: unknown, factory: ts.NodeFactory): ts.Expression {\n // Coverage ignored: JSON schemas from typeToToolParameterSchema never contain\n // top-level null/undefined values, but we handle them defensively\n /* v8 ignore start */\n if (value === null) {\n return factory.createNull();\n }\n if (value === undefined) {\n return factory.createIdentifier(\"undefined\");\n }\n /* v8 ignore end */\n\n if (typeof value === \"string\") {\n return factory.createStringLiteral(value);\n }\n\n if (typeof value === \"number\") {\n return factory.createNumericLiteral(value);\n }\n\n if (typeof value === \"boolean\") {\n /* v8 ignore next */\n return value ? factory.createTrue() : factory.createFalse();\n }\n\n if (Array.isArray(value)) {\n return factory.createArrayLiteralExpression(\n value.map((item) => jsonToAst(item, factory)),\n );\n }\n\n if (typeof value === \"object\") {\n const properties = Object.entries(value).map(([key, val]) =>\n factory.createPropertyAssignment(\n factory.createIdentifier(key),\n jsonToAst(val, factory),\n ),\n );\n return factory.createObjectLiteralExpression(properties, true);\n }\n\n // Coverage ignored: After handling all JSON-valid types (null, undefined,\n // string, number, boolean, array, object), this is unreachable\n /* v8 ignore next */\n return factory.createIdentifier(\"undefined\");\n}\n\n/**\n * Default export for ts-patch and other transformer loaders.\n */\nexport default function transformer(\n program: ts.Program,\n): ts.TransformerFactory<ts.SourceFile> {\n return createToolSchemaTransformer(program);\n}\n","/**\n * esbuild plugin for Mirascope tool schema transformation.\n *\n * This plugin uses the TypeScript compiler instead of esbuild's built-in\n * TypeScript support to ensure access to type information for schema generation.\n */\n\nimport type { Plugin, OnLoadArgs, OnLoadResult, PluginBuild } from \"esbuild\";\n\nimport fs from \"fs\";\nimport path from \"path\";\nimport ts from \"typescript\";\n\nimport { createToolSchemaTransformer } from \"@/transform/transformer\";\n\nexport interface MirascopeEsbuildPluginOptions {\n /**\n * Path to tsconfig.json. Defaults to './tsconfig.json'\n */\n tsconfig?: string;\n\n /**\n * File filter pattern. Defaults to /\\.(ts|tsx)$/\n */\n filter?: RegExp;\n\n /**\n * Additional TypeScript compiler options to merge with tsconfig.\n */\n compilerOptions?: ts.CompilerOptions;\n}\n\n/**\n * esbuild plugin that applies the Mirascope tool schema transformer.\n *\n * This plugin uses the TypeScript compiler instead of esbuild's built-in\n * TypeScript support to ensure access to type information for schema generation.\n *\n * @example\n * ```typescript\n * import * as esbuild from 'esbuild';\n * import { mirascope } from 'mirascope/esbuild';\n *\n * await esbuild.build({\n * entryPoints: ['src/index.ts'],\n * bundle: true,\n * outfile: 'dist/bundle.js',\n * plugins: [mirascope()],\n * });\n * ```\n */\nexport function mirascope(options: MirascopeEsbuildPluginOptions = {}): Plugin {\n const {\n tsconfig = \"./tsconfig.json\",\n filter = /\\.(ts|tsx)$/,\n compilerOptions: extraOptions = {},\n } = options;\n\n // Cache for the TypeScript program and transformer\n let cachedProgram: ts.Program | undefined;\n let cachedTransformer: ts.TransformerFactory<ts.SourceFile> | undefined;\n let cachedConfigPath: string | undefined;\n let cachedCompilerOptions: ts.CompilerOptions | undefined;\n\n return {\n name: \"mirascope\",\n\n setup(build: PluginBuild) {\n const cwd = process.cwd();\n const configPath = path.resolve(cwd, tsconfig);\n\n // Read and parse tsconfig.json\n let parsedConfig: ts.ParsedCommandLine;\n if (fs.existsSync(configPath)) {\n const configFile = ts.readConfigFile(configPath, (path) =>\n ts.sys.readFile(path),\n );\n if (configFile.error) {\n throw new Error(\n `Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(\n configFile.error.messageText,\n \"\\n\",\n )}`,\n );\n }\n\n parsedConfig = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n path.dirname(configPath),\n );\n } else {\n // Use default config if tsconfig.json doesn't exist\n parsedConfig = ts.parseJsonConfigFileContent({}, ts.sys, cwd);\n }\n\n // Merge compiler options\n const compilerOptions: ts.CompilerOptions = {\n ...parsedConfig.options,\n ...extraOptions,\n // Required for transformation\n noEmit: false,\n sourceMap: false,\n inlineSourceMap: false,\n declaration: false,\n declarationMap: false,\n };\n\n // Handle .ts and .tsx files\n build.onLoad(\n { filter },\n async (args: OnLoadArgs): Promise<OnLoadResult> => {\n const fileName = args.path;\n\n // Read the source file\n const sourceText = await fs.promises.readFile(fileName, \"utf-8\");\n\n // Check if this file contains defineTool or defineContextTool\n // If not, we can skip the expensive transformation\n if (\n !sourceText.includes(\"defineTool\") &&\n !sourceText.includes(\"defineContextTool\")\n ) {\n return {\n contents: sourceText,\n loader: fileName.endsWith(\".tsx\") ? \"tsx\" : \"ts\",\n };\n }\n\n // Create or reuse program\n // Coverage: The caching condition is always true on first invocation since\n // cachedProgram starts as undefined. Additional checks for config/options\n // changes exist for watch mode but are hard to test in unit tests.\n /* v8 ignore next 5 */\n if (\n !cachedProgram ||\n cachedConfigPath !== configPath ||\n cachedCompilerOptions !== compilerOptions\n ) {\n // Create a new program with all files\n cachedProgram = ts.createProgram([fileName], compilerOptions);\n cachedTransformer = createToolSchemaTransformer(cachedProgram);\n cachedConfigPath = configPath;\n cachedCompilerOptions = compilerOptions;\n }\n\n const sourceFile = cachedProgram.getSourceFile(fileName);\n\n // Coverage ignored: This fallback handles edge cases where the cached program\n // doesn't have the source file (e.g., new files added during watch mode).\n // In normal builds, the program always contains the requested file.\n /* v8 ignore start */\n if (!sourceFile) {\n // File not in program, create a minimal program for just this file\n const singleFileProgram = ts.createProgram(\n [fileName],\n compilerOptions,\n );\n const transformer = createToolSchemaTransformer(singleFileProgram);\n const sf = singleFileProgram.getSourceFile(fileName);\n\n if (!sf) {\n return {\n errors: [\n {\n text: `Could not parse source file: ${fileName}`,\n location: null,\n },\n ],\n };\n }\n\n const result = ts.transform(sf, [transformer]);\n const transformedSourceFile = result.transformed[0];\n const printer = ts.createPrinter();\n const outputText = transformedSourceFile\n ? printer.printFile(transformedSourceFile)\n : sourceText;\n result.dispose();\n\n return {\n contents: outputText,\n loader: fileName.endsWith(\".tsx\") ? \"tsx\" : \"ts\",\n };\n }\n /* v8 ignore end */\n\n // Transform the source file\n const result = ts.transform(sourceFile, [cachedTransformer!]);\n const transformedSourceFile = result.transformed[0];\n\n const printer = ts.createPrinter();\n // Coverage ignored: ts.transform always returns at least one transformed file\n // when given a valid source file. The fallback is defensive.\n /* v8 ignore next 3 */\n const outputText = transformedSourceFile\n ? printer.printFile(transformedSourceFile)\n : sourceText;\n\n result.dispose();\n\n return {\n contents: outputText,\n loader: fileName.endsWith(\".tsx\") ? \"tsx\" : \"ts\",\n };\n },\n );\n },\n };\n}\n\nexport default mirascope;\n"]}
@@ -0,0 +1,46 @@
1
+ import { Plugin } from 'esbuild';
2
+ import ts from 'typescript';
3
+
4
+ /**
5
+ * esbuild plugin for Mirascope tool schema transformation.
6
+ *
7
+ * This plugin uses the TypeScript compiler instead of esbuild's built-in
8
+ * TypeScript support to ensure access to type information for schema generation.
9
+ */
10
+
11
+ interface MirascopeEsbuildPluginOptions {
12
+ /**
13
+ * Path to tsconfig.json. Defaults to './tsconfig.json'
14
+ */
15
+ tsconfig?: string;
16
+ /**
17
+ * File filter pattern. Defaults to /\.(ts|tsx)$/
18
+ */
19
+ filter?: RegExp;
20
+ /**
21
+ * Additional TypeScript compiler options to merge with tsconfig.
22
+ */
23
+ compilerOptions?: ts.CompilerOptions;
24
+ }
25
+ /**
26
+ * esbuild plugin that applies the Mirascope tool schema transformer.
27
+ *
28
+ * This plugin uses the TypeScript compiler instead of esbuild's built-in
29
+ * TypeScript support to ensure access to type information for schema generation.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import * as esbuild from 'esbuild';
34
+ * import { mirascope } from 'mirascope/esbuild';
35
+ *
36
+ * await esbuild.build({
37
+ * entryPoints: ['src/index.ts'],
38
+ * bundle: true,
39
+ * outfile: 'dist/bundle.js',
40
+ * plugins: [mirascope()],
41
+ * });
42
+ * ```
43
+ */
44
+ declare function mirascope(options?: MirascopeEsbuildPluginOptions): Plugin;
45
+
46
+ export { type MirascopeEsbuildPluginOptions, mirascope as default, mirascope };
@@ -0,0 +1,46 @@
1
+ import { Plugin } from 'esbuild';
2
+ import ts from 'typescript';
3
+
4
+ /**
5
+ * esbuild plugin for Mirascope tool schema transformation.
6
+ *
7
+ * This plugin uses the TypeScript compiler instead of esbuild's built-in
8
+ * TypeScript support to ensure access to type information for schema generation.
9
+ */
10
+
11
+ interface MirascopeEsbuildPluginOptions {
12
+ /**
13
+ * Path to tsconfig.json. Defaults to './tsconfig.json'
14
+ */
15
+ tsconfig?: string;
16
+ /**
17
+ * File filter pattern. Defaults to /\.(ts|tsx)$/
18
+ */
19
+ filter?: RegExp;
20
+ /**
21
+ * Additional TypeScript compiler options to merge with tsconfig.
22
+ */
23
+ compilerOptions?: ts.CompilerOptions;
24
+ }
25
+ /**
26
+ * esbuild plugin that applies the Mirascope tool schema transformer.
27
+ *
28
+ * This plugin uses the TypeScript compiler instead of esbuild's built-in
29
+ * TypeScript support to ensure access to type information for schema generation.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import * as esbuild from 'esbuild';
34
+ * import { mirascope } from 'mirascope/esbuild';
35
+ *
36
+ * await esbuild.build({
37
+ * entryPoints: ['src/index.ts'],
38
+ * bundle: true,
39
+ * outfile: 'dist/bundle.js',
40
+ * plugins: [mirascope()],
41
+ * });
42
+ * ```
43
+ */
44
+ declare function mirascope(options?: MirascopeEsbuildPluginOptions): Plugin;
45
+
46
+ export { type MirascopeEsbuildPluginOptions, mirascope as default, mirascope };
@@ -0,0 +1,5 @@
1
+ export { esbuild_default as default, mirascope } from '../../chunk-2R5IW35Y.js';
2
+ import '../../chunk-U4MFJ4DP.js';
3
+ import '../../chunk-NSBPE2FW.js';
4
+ //# sourceMappingURL=esbuild.js.map
5
+ //# sourceMappingURL=esbuild.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"esbuild.js"}
@@ -0,0 +1,405 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var typescript = require('@rollup/plugin-typescript');
6
+ var ts = require('typescript');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var typescript__default = /*#__PURE__*/_interopDefault(typescript);
11
+ var ts__default = /*#__PURE__*/_interopDefault(ts);
12
+
13
+ // src/transform/plugins/vite.ts
14
+ function isArrayLikeType(type, checker) {
15
+ if (type.getFlags() & ts__default.default.TypeFlags.Object) {
16
+ const objectType = type;
17
+ const objectFlags = objectType.objectFlags;
18
+ if (objectFlags & ts__default.default.ObjectFlags.Reference) {
19
+ const typeRef = type;
20
+ const symbol = typeRef.symbol;
21
+ if (symbol && symbol.getName() === "Array") {
22
+ return true;
23
+ }
24
+ const target = typeRef.target;
25
+ if (target && target.symbol && target.symbol.getName() === "Array") {
26
+ return true;
27
+ }
28
+ }
29
+ }
30
+ const typeString = checker.typeToString(type);
31
+ if (typeString.endsWith("[]") || typeString.startsWith("Array<")) {
32
+ return true;
33
+ }
34
+ return false;
35
+ }
36
+ function typeToJsonSchema(type, ctx) {
37
+ const checker = ctx.checker;
38
+ if (type.isUnion()) {
39
+ return handleUnionType(type, ctx);
40
+ }
41
+ if (type.isIntersection()) {
42
+ return handleIntersectionType(type, ctx);
43
+ }
44
+ if (type.isLiteral()) {
45
+ return handleLiteralType(type);
46
+ }
47
+ const flags = type.getFlags();
48
+ if (flags & ts__default.default.TypeFlags.BooleanLiteral) {
49
+ const intrinsicName = type.intrinsicName;
50
+ const isTrue = intrinsicName === "true";
51
+ return { type: "boolean", enum: [isTrue] };
52
+ }
53
+ if (flags & ts__default.default.TypeFlags.String) {
54
+ return { type: "string" };
55
+ }
56
+ if (flags & ts__default.default.TypeFlags.Number) {
57
+ return { type: "number" };
58
+ }
59
+ if (flags & ts__default.default.TypeFlags.Null) {
60
+ return { type: "null" };
61
+ }
62
+ if (flags & ts__default.default.TypeFlags.Undefined) {
63
+ return {};
64
+ }
65
+ if (checker.isArrayType(type) || isArrayLikeType(type, checker)) {
66
+ const typeRef = type;
67
+ const typeArgs = checker.getTypeArguments(typeRef);
68
+ if (typeArgs && typeArgs.length > 0) {
69
+ return {
70
+ type: "array",
71
+ items: typeToJsonSchema(typeArgs[0], ctx)
72
+ };
73
+ }
74
+ return { type: "array" };
75
+ }
76
+ if (flags & ts__default.default.TypeFlags.Object) {
77
+ return handleObjectType(type, ctx);
78
+ }
79
+ return {};
80
+ }
81
+ function handleUnionType(type, ctx) {
82
+ const types = type.types;
83
+ const nonUndefinedTypes = types.filter(
84
+ (t) => !(t.getFlags() & ts__default.default.TypeFlags.Undefined)
85
+ );
86
+ if (nonUndefinedTypes.length === 2 && nonUndefinedTypes.every((t) => t.getFlags() & ts__default.default.TypeFlags.BooleanLiteral)) {
87
+ return { type: "boolean" };
88
+ }
89
+ if (nonUndefinedTypes.every(
90
+ (t) => t.isStringLiteral()
91
+ )) {
92
+ return {
93
+ type: "string",
94
+ enum: nonUndefinedTypes.map((t) => t.value)
95
+ };
96
+ }
97
+ if (nonUndefinedTypes.every(
98
+ (t) => t.isNumberLiteral()
99
+ )) {
100
+ return {
101
+ type: "number",
102
+ enum: nonUndefinedTypes.map((t) => t.value)
103
+ };
104
+ }
105
+ if (nonUndefinedTypes.length === 1) {
106
+ return typeToJsonSchema(nonUndefinedTypes[0], ctx);
107
+ }
108
+ return {
109
+ oneOf: nonUndefinedTypes.map((t) => typeToJsonSchema(t, ctx))
110
+ };
111
+ }
112
+ function handleIntersectionType(type, ctx) {
113
+ const allOf = type.types.map((t) => typeToJsonSchema(t, ctx));
114
+ if (allOf.every((s) => s.type === "object")) {
115
+ const merged = {
116
+ type: "object",
117
+ properties: {},
118
+ required: []
119
+ };
120
+ for (const schema of allOf) {
121
+ if (schema.properties) {
122
+ merged.properties = { ...merged.properties, ...schema.properties };
123
+ }
124
+ if (schema.required) {
125
+ merged.required = [
126
+ ...merged.required,
127
+ ...schema.required
128
+ ];
129
+ }
130
+ }
131
+ return merged;
132
+ }
133
+ return { allOf };
134
+ }
135
+ function handleLiteralType(type) {
136
+ if (type.isStringLiteral()) {
137
+ return { type: "string", enum: [type.value] };
138
+ }
139
+ if (type.isNumberLiteral()) {
140
+ return { type: "number", enum: [type.value] };
141
+ }
142
+ return {};
143
+ }
144
+ function handleObjectType(type, ctx) {
145
+ const checker = ctx.checker;
146
+ const properties = {};
147
+ const required = [];
148
+ const props = checker.getPropertiesOfType(type);
149
+ for (const prop of props) {
150
+ const propName = prop.getName();
151
+ const propType = checker.getTypeOfSymbol(prop);
152
+ const isOptional = (prop.getFlags() & ts__default.default.SymbolFlags.Optional) !== 0;
153
+ const propSchema = typeToJsonSchema(propType, ctx);
154
+ const jsDocComment = prop.getDocumentationComment(checker);
155
+ if (jsDocComment.length > 0) {
156
+ const description = jsDocComment.map((c) => c.text).join("");
157
+ propSchema.description = description;
158
+ }
159
+ properties[propName] = propSchema;
160
+ if (!isOptional) {
161
+ required.push(propName);
162
+ }
163
+ }
164
+ return {
165
+ type: "object",
166
+ properties,
167
+ required: required.length > 0 ? required : void 0
168
+ };
169
+ }
170
+ function typeToToolParameterSchema(type, checker) {
171
+ const ctx = {
172
+ checker,
173
+ definitions: /* @__PURE__ */ new Map()};
174
+ const schema = typeToJsonSchema(type, ctx);
175
+ if (schema.type !== "object") {
176
+ throw new Error(
177
+ "Tool parameter type must be an object type, got: " + JSON.stringify(schema)
178
+ );
179
+ }
180
+ const result = {
181
+ type: "object",
182
+ properties: schema.properties ?? {},
183
+ required: schema.required ?? [],
184
+ additionalProperties: false
185
+ };
186
+ if (ctx.definitions.size > 0) {
187
+ result.$defs = Object.fromEntries(ctx.definitions);
188
+ }
189
+ return result;
190
+ }
191
+
192
+ // src/transform/transformer.ts
193
+ var TOOL_FUNCTION_NAMES = /* @__PURE__ */ new Set(["defineTool", "defineContextTool"]);
194
+ var FORMAT_FUNCTION_NAMES = /* @__PURE__ */ new Set(["defineFormat"]);
195
+ function createToolSchemaTransformer(program) {
196
+ const checker = program.getTypeChecker();
197
+ return (context) => {
198
+ return (sourceFile) => {
199
+ const visitor = (node) => {
200
+ if (ts__default.default.isCallExpression(node)) {
201
+ const toolTransformed = tryTransformToolCall(node, checker, context);
202
+ if (toolTransformed) {
203
+ return toolTransformed;
204
+ }
205
+ const formatTransformed = tryTransformFormatCall(
206
+ node,
207
+ checker,
208
+ context
209
+ );
210
+ if (formatTransformed) {
211
+ return formatTransformed;
212
+ }
213
+ }
214
+ return ts__default.default.visitEachChild(node, visitor, context);
215
+ };
216
+ return ts__default.default.visitNode(sourceFile, visitor);
217
+ };
218
+ };
219
+ }
220
+ function tryTransformToolCall(node, checker, context) {
221
+ const functionName = getFunctionName(node);
222
+ if (!functionName || !TOOL_FUNCTION_NAMES.has(functionName)) {
223
+ return void 0;
224
+ }
225
+ const typeArgs = node.typeArguments;
226
+ if (!typeArgs || typeArgs.length === 0) {
227
+ return void 0;
228
+ }
229
+ const argsTypeNode = typeArgs[0];
230
+ const argsType = checker.getTypeFromTypeNode(argsTypeNode);
231
+ let schema;
232
+ try {
233
+ schema = typeToToolParameterSchema(argsType, checker);
234
+ } catch {
235
+ return void 0;
236
+ }
237
+ const args = node.arguments;
238
+ const firstArg = args[0];
239
+ if (!firstArg || !ts__default.default.isObjectLiteralExpression(firstArg)) {
240
+ return void 0;
241
+ }
242
+ const optionsObject = firstArg;
243
+ const hasSchema = optionsObject.properties.some(
244
+ (prop) => ts__default.default.isPropertyAssignment(prop) && ts__default.default.isIdentifier(prop.name) && prop.name.text === "__schema"
245
+ );
246
+ if (hasSchema) {
247
+ return void 0;
248
+ }
249
+ const schemaProperty = createSchemaProperty(schema, context.factory);
250
+ const newProperties = [...optionsObject.properties, schemaProperty];
251
+ const newOptionsObject = context.factory.updateObjectLiteralExpression(
252
+ optionsObject,
253
+ newProperties
254
+ );
255
+ const newArgs = [newOptionsObject, ...args.slice(1)];
256
+ return context.factory.updateCallExpression(
257
+ node,
258
+ node.expression,
259
+ node.typeArguments,
260
+ newArgs
261
+ );
262
+ }
263
+ function tryTransformFormatCall(node, checker, context) {
264
+ const functionName = getFunctionName(node);
265
+ if (!functionName || !FORMAT_FUNCTION_NAMES.has(functionName)) {
266
+ return void 0;
267
+ }
268
+ const typeArgs = node.typeArguments;
269
+ if (!typeArgs || typeArgs.length === 0) {
270
+ return void 0;
271
+ }
272
+ const outputTypeNode = typeArgs[0];
273
+ const outputType = checker.getTypeFromTypeNode(outputTypeNode);
274
+ const args = node.arguments;
275
+ const firstArg = args[0];
276
+ if (!firstArg) {
277
+ return void 0;
278
+ }
279
+ if (ts__default.default.isObjectLiteralExpression(firstArg)) {
280
+ const formatSpecObject = firstArg;
281
+ const hasSchema = formatSpecObject.properties.some(
282
+ (prop) => ts__default.default.isPropertyAssignment(prop) && ts__default.default.isIdentifier(prop.name) && prop.name.text === "__schema"
283
+ );
284
+ if (hasSchema) {
285
+ return void 0;
286
+ }
287
+ let schema;
288
+ try {
289
+ schema = typeToToolParameterSchema(outputType, checker);
290
+ } catch {
291
+ return void 0;
292
+ }
293
+ const schemaProperty = createSchemaProperty(schema, context.factory);
294
+ const newProperties = [...formatSpecObject.properties, schemaProperty];
295
+ const newFormatSpecObject = context.factory.updateObjectLiteralExpression(
296
+ formatSpecObject,
297
+ newProperties
298
+ );
299
+ const newArgs = [newFormatSpecObject, ...args.slice(1)];
300
+ return context.factory.updateCallExpression(
301
+ node,
302
+ node.expression,
303
+ node.typeArguments,
304
+ newArgs
305
+ );
306
+ }
307
+ return void 0;
308
+ }
309
+ function getFunctionName(node) {
310
+ const expression = node.expression;
311
+ if (ts__default.default.isIdentifier(expression)) {
312
+ return expression.text;
313
+ }
314
+ if (ts__default.default.isPropertyAccessExpression(expression)) {
315
+ return expression.name.text;
316
+ }
317
+ return void 0;
318
+ }
319
+ function createSchemaProperty(schema, factory) {
320
+ return factory.createPropertyAssignment(
321
+ factory.createIdentifier("__schema"),
322
+ jsonToAst(schema, factory)
323
+ );
324
+ }
325
+ function jsonToAst(value, factory) {
326
+ if (value === null) {
327
+ return factory.createNull();
328
+ }
329
+ if (value === void 0) {
330
+ return factory.createIdentifier("undefined");
331
+ }
332
+ if (typeof value === "string") {
333
+ return factory.createStringLiteral(value);
334
+ }
335
+ if (typeof value === "number") {
336
+ return factory.createNumericLiteral(value);
337
+ }
338
+ if (typeof value === "boolean") {
339
+ return value ? factory.createTrue() : factory.createFalse();
340
+ }
341
+ if (Array.isArray(value)) {
342
+ return factory.createArrayLiteralExpression(
343
+ value.map((item) => jsonToAst(item, factory))
344
+ );
345
+ }
346
+ if (typeof value === "object") {
347
+ const properties = Object.entries(value).map(
348
+ ([key, val]) => factory.createPropertyAssignment(
349
+ factory.createIdentifier(key),
350
+ jsonToAst(val, factory)
351
+ )
352
+ );
353
+ return factory.createObjectLiteralExpression(properties, true);
354
+ }
355
+ return factory.createIdentifier("undefined");
356
+ }
357
+
358
+ // src/transform/plugins/vite.ts
359
+ function mirascope(options = {}) {
360
+ const {
361
+ typescript: tsOptions = {},
362
+ additionalTransformers,
363
+ include = /\.(ts|tsx)$/,
364
+ exclude = /node_modules/
365
+ } = options;
366
+ const transformers = (program) => {
367
+ const mirascopeTransformer = createToolSchemaTransformer(program);
368
+ return {
369
+ before: [mirascopeTransformer, ...additionalTransformers?.before ?? []],
370
+ after: additionalTransformers?.after,
371
+ afterDeclarations: additionalTransformers?.afterDeclarations
372
+ };
373
+ };
374
+ return [
375
+ {
376
+ name: "mirascope:pre",
377
+ enforce: "pre",
378
+ config() {
379
+ return {
380
+ esbuild: {
381
+ // Disable esbuild's TypeScript handling for matched files
382
+ // We'll handle them with @rollup/plugin-typescript instead
383
+ include: exclude,
384
+ // Only let esbuild handle excluded files
385
+ exclude: include
386
+ // Exclude our target files from esbuild
387
+ }
388
+ };
389
+ }
390
+ },
391
+ // Cast needed because @rollup/plugin-typescript returns Rollup plugin
392
+ typescript__default.default({
393
+ ...tsOptions,
394
+ transformers,
395
+ include,
396
+ exclude
397
+ })
398
+ ];
399
+ }
400
+ var vite_default = mirascope;
401
+
402
+ exports.default = vite_default;
403
+ exports.mirascope = mirascope;
404
+ //# sourceMappingURL=vite.cjs.map
405
+ //# sourceMappingURL=vite.cjs.map