@skill-tools/gen 0.2.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/openapi.ts","../src/renderer.ts","../src/generator.ts"],"sourcesContent":["import YAML from 'yaml';\nimport type {\n\tApiEndpoint,\n\tApiParameter,\n\tApiProperty,\n\tApiRequestBody,\n\tApiResponse,\n\tApiSpec,\n\tAuthScheme,\n} from './types.js';\n\n/**\n * Parse an OpenAPI 3.x specification (JSON or YAML) into an ApiSpec.\n *\n * Supports OpenAPI 3.0.x and 3.1.x. Does not support Swagger 2.0.\n * Resolves local `$ref` references within the document.\n */\nexport function parseOpenApi(content: string): ApiSpec {\n\tconst MAX_SPEC_SIZE = 10_000_000; // 10MB\n\tif (content.length > MAX_SPEC_SIZE) {\n\t\tthrow new Error(`OpenAPI spec exceeds maximum size (${MAX_SPEC_SIZE} bytes)`);\n\t}\n\n\tconst doc = parseDocument(content);\n\n\tconst version = doc.openapi;\n\tif (!version || !version.startsWith('3.')) {\n\t\tthrow new Error(\n\t\t\t`Unsupported OpenAPI version: ${version ?? 'unknown'}. Only OpenAPI 3.x is supported.`,\n\t\t);\n\t}\n\n\tconst title = doc.info?.title ?? 'Untitled API';\n\tconst description = doc.info?.description ?? '';\n\tconst apiVersion = doc.info?.version ?? '0.0.0';\n\tconst servers = extractServers(doc);\n\tconst auth = extractAuthSchemes(doc);\n\tconst endpoints = extractEndpoints(doc);\n\n\treturn {\n\t\ttitle,\n\t\tdescription,\n\t\tversion: apiVersion,\n\t\tservers,\n\t\tauth,\n\t\tendpoints,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\ninterface OpenApiDoc {\n\topenapi?: string;\n\tinfo?: { title?: string; description?: string; version?: string };\n\tservers?: Array<{ url: string }>;\n\tpaths?: Record<string, Record<string, unknown>>;\n\tcomponents?: {\n\t\tsecuritySchemes?: Record<string, Record<string, unknown>>;\n\t\tschemas?: Record<string, Record<string, unknown>>;\n\t};\n\t[key: string]: unknown;\n}\n\n/**\n * Parse the document as JSON first, falling back to YAML.\n */\nfunction parseDocument(content: string): OpenApiDoc {\n\tconst trimmed = content.trim();\n\tif (trimmed.startsWith('{')) {\n\t\ttry {\n\t\t\treturn JSON.parse(trimmed) as OpenApiDoc;\n\t\t} catch {\n\t\t\t// Fall through to YAML\n\t\t}\n\t}\n\treturn YAML.parse(content) as OpenApiDoc;\n}\n\n/**\n * Resolve a local $ref like \"#/components/schemas/Pet\".\n */\nfunction resolveRef(doc: OpenApiDoc, ref: string): Record<string, unknown> {\n\tif (!ref.startsWith('#/')) {\n\t\treturn {};\n\t}\n\tconst path = ref.slice(2).split('/');\n\tlet current: unknown = doc;\n\tfor (const segment of path) {\n\t\tif (current == null || typeof current !== 'object') return {};\n\t\tcurrent = (current as Record<string, unknown>)[segment];\n\t}\n\treturn (current as Record<string, unknown>) ?? {};\n}\n\n/**\n * If obj has a $ref, resolve it. Otherwise return obj as-is.\n */\nfunction deref(doc: OpenApiDoc, obj: Record<string, unknown>): Record<string, unknown> {\n\tif (typeof obj.$ref === 'string') {\n\t\treturn resolveRef(doc, obj.$ref);\n\t}\n\treturn obj;\n}\n\nfunction extractServers(doc: OpenApiDoc): string[] {\n\tconst servers = doc.servers;\n\tif (!Array.isArray(servers)) return [];\n\treturn servers.map((s: Record<string, unknown>) => s.url as string).filter(Boolean);\n}\n\nfunction extractAuthSchemes(doc: OpenApiDoc): AuthScheme[] {\n\tconst components = doc.components as Record<string, unknown> | undefined;\n\tconst schemes = components?.securitySchemes as\n\t\t| Record<string, Record<string, unknown>>\n\t\t| undefined;\n\tif (!schemes) return [];\n\n\treturn Object.entries(schemes).map(([name, raw]) => {\n\t\tconst scheme = deref(doc, raw);\n\t\treturn {\n\t\t\ttype: (scheme.type as AuthScheme['type']) ?? 'apiKey',\n\t\t\tname,\n\t\t\tdescription: scheme.description as string | undefined,\n\t\t\tin: scheme.in as AuthScheme['in'],\n\t\t\tscheme: scheme.scheme as string | undefined,\n\t\t};\n\t});\n}\n\nfunction extractEndpoints(doc: OpenApiDoc): ApiEndpoint[] {\n\tconst paths = doc.paths as Record<string, Record<string, unknown>> | undefined;\n\tif (!paths) return [];\n\n\tconst endpoints: ApiEndpoint[] = [];\n\tconst httpMethods = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'];\n\n\tfor (const [path, pathItem] of Object.entries(paths)) {\n\t\tconst resolved = deref(doc, pathItem);\n\t\t// Path-level parameters\n\t\tconst pathParams = Array.isArray(resolved.parameters)\n\t\t\t? (resolved.parameters as Record<string, unknown>[]).map((p) => extractParameter(doc, p))\n\t\t\t: [];\n\n\t\tfor (const method of httpMethods) {\n\t\t\tconst operation = resolved[method] as Record<string, unknown> | undefined;\n\t\t\tif (!operation) continue;\n\n\t\t\tconst opParams = Array.isArray(operation.parameters)\n\t\t\t\t? (operation.parameters as Record<string, unknown>[]).map((p) => extractParameter(doc, p))\n\t\t\t\t: [];\n\n\t\t\t// Merge path-level and operation-level params (operation wins on conflict)\n\t\t\tconst paramMap = new Map<string, ApiParameter>();\n\t\t\tfor (const p of pathParams) paramMap.set(`${p.in}:${p.name}`, p);\n\t\t\tfor (const p of opParams) paramMap.set(`${p.in}:${p.name}`, p);\n\n\t\t\tconst requestBody = operation.requestBody\n\t\t\t\t? extractRequestBody(doc, deref(doc, operation.requestBody as Record<string, unknown>))\n\t\t\t\t: undefined;\n\n\t\t\tconst responses = extractResponses(\n\t\t\t\tdoc,\n\t\t\t\toperation.responses as Record<string, unknown> | undefined,\n\t\t\t);\n\n\t\t\tendpoints.push({\n\t\t\t\tmethod: method.toUpperCase(),\n\t\t\t\tpath,\n\t\t\t\toperationId: operation.operationId as string | undefined,\n\t\t\t\tsummary: operation.summary as string | undefined,\n\t\t\t\tdescription: operation.description as string | undefined,\n\t\t\t\ttags: Array.isArray(operation.tags) ? (operation.tags as string[]) : [],\n\t\t\t\tparameters: Array.from(paramMap.values()),\n\t\t\t\trequestBody,\n\t\t\t\tresponses,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn endpoints;\n}\n\nfunction extractParameter(doc: OpenApiDoc, raw: Record<string, unknown>): ApiParameter {\n\tconst param = deref(doc, raw);\n\tconst schema = param.schema ? deref(doc, param.schema as Record<string, unknown>) : {};\n\n\treturn {\n\t\tname: (param.name as string) ?? '',\n\t\tin: (param.in as ApiParameter['in']) ?? 'query',\n\t\tdescription: param.description as string | undefined,\n\t\trequired: (param.required as boolean) ?? false,\n\t\ttype: schema.type as string | undefined,\n\t\texample: param.example,\n\t};\n}\n\nfunction extractRequestBody(\n\tdoc: OpenApiDoc,\n\tbody: Record<string, unknown>,\n): ApiRequestBody | undefined {\n\tconst content = body.content as Record<string, Record<string, unknown>> | undefined;\n\tif (!content) return undefined;\n\n\t// Prefer application/json, fall back to first content type\n\tconst contentType = 'application/json' in content ? 'application/json' : Object.keys(content)[0];\n\tif (!contentType) return undefined;\n\n\tconst mediaType = content[contentType];\n\tif (!mediaType) return undefined;\n\n\tconst schema = mediaType.schema ? deref(doc, mediaType.schema as Record<string, unknown>) : {};\n\n\treturn {\n\t\tdescription: body.description as string | undefined,\n\t\tcontentType,\n\t\trequired: (body.required as boolean) ?? false,\n\t\tproperties: extractProperties(doc, schema),\n\t\texample: mediaType.example ?? schema.example,\n\t};\n}\n\nfunction extractProperties(doc: OpenApiDoc, schema: Record<string, unknown>): ApiProperty[] {\n\tconst properties = schema.properties as Record<string, Record<string, unknown>> | undefined;\n\tif (!properties) return [];\n\n\tconst requiredFields = new Set(\n\t\tArray.isArray(schema.required) ? (schema.required as string[]) : [],\n\t);\n\n\treturn Object.entries(properties).map(([name, raw]) => {\n\t\tconst prop = deref(doc, raw);\n\t\treturn {\n\t\t\tname,\n\t\t\ttype: (prop.type as string) ?? 'unknown',\n\t\t\tdescription: prop.description as string | undefined,\n\t\t\trequired: requiredFields.has(name),\n\t\t\texample: prop.example,\n\t\t};\n\t});\n}\n\nfunction extractResponses(\n\tdoc: OpenApiDoc,\n\tresponses: Record<string, unknown> | undefined,\n): ApiResponse[] {\n\tif (!responses) return [];\n\n\treturn Object.entries(responses).map(([statusCode, raw]) => {\n\t\tconst response = deref(doc, raw as Record<string, unknown>);\n\t\tconst content = response.content as Record<string, Record<string, unknown>> | undefined;\n\n\t\tlet contentType: string | undefined;\n\t\tlet properties: ApiProperty[] = [];\n\n\t\tif (content) {\n\t\t\tcontentType = 'application/json' in content ? 'application/json' : Object.keys(content)[0];\n\n\t\t\tif (contentType && content[contentType]) {\n\t\t\t\tconst mediaType = content[contentType]!;\n\t\t\t\tconst schema = mediaType.schema\n\t\t\t\t\t? deref(doc, mediaType.schema as Record<string, unknown>)\n\t\t\t\t\t: {};\n\t\t\t\tproperties = extractProperties(doc, schema);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tstatusCode,\n\t\t\tdescription: response.description as string | undefined,\n\t\t\tcontentType,\n\t\t\tproperties,\n\t\t};\n\t});\n}\n","import type {\n\tApiEndpoint,\n\tApiProperty,\n\tApiRequestBody,\n\tApiSpec,\n\tAuthScheme,\n\tGenerateOptions,\n} from './types.js';\n\n/**\n * Render a SKILL.md file from an ApiSpec.\n *\n * In \"unified\" mode, produces a single SKILL.md covering the entire API.\n * In \"per-endpoint\" mode, produces one SKILL.md per endpoint.\n */\nexport function renderSkillMd(spec: ApiSpec, options: GenerateOptions = {}): Map<string, string> {\n\tconst mode = options.mode ?? 'unified';\n\tconst files = new Map<string, string>();\n\n\tif (mode === 'unified') {\n\t\tconst name = options.name ?? toKebabCase(spec.title);\n\t\tconst content = renderUnified(spec, { ...options, name });\n\t\tfiles.set(`${name}/SKILL.md`, content);\n\t} else {\n\t\tfor (const endpoint of spec.endpoints) {\n\t\t\tconst epName = endpoint.operationId\n\t\t\t\t? toKebabCase(endpoint.operationId)\n\t\t\t\t: toKebabCase(`${endpoint.method}-${endpoint.path}`);\n\t\t\tconst content = renderSingleEndpoint(spec, endpoint, {\n\t\t\t\t...options,\n\t\t\t\tname: epName,\n\t\t\t});\n\t\t\tfiles.set(`${epName}/SKILL.md`, content);\n\t\t}\n\t}\n\n\treturn files;\n}\n\n// ---------------------------------------------------------------------------\n// Unified mode — one SKILL.md for the entire API\n// ---------------------------------------------------------------------------\n\nfunction renderUnified(spec: ApiSpec, options: GenerateOptions): string {\n\tconst lines: string[] = [];\n\n\t// Frontmatter\n\tlines.push('---');\n\tlines.push(`name: ${options.name}`);\n\tlines.push(`description: >-`, ` ${options.description ?? buildUnifiedDescription(spec)}`);\n\tlines.push('---');\n\tlines.push('');\n\n\t// Title\n\tlines.push(`# ${spec.title}`);\n\tlines.push('');\n\n\tif (spec.description) {\n\t\tlines.push(spec.description);\n\t\tlines.push('');\n\t}\n\n\t// Base URL\n\tif (spec.servers.length > 0) {\n\t\tlines.push('## Base URL');\n\t\tlines.push('');\n\t\tfor (const server of spec.servers) {\n\t\t\tlines.push(`- \\`${server}\\``);\n\t\t}\n\t\tlines.push('');\n\t}\n\n\t// Authentication\n\tif (spec.auth.length > 0) {\n\t\tlines.push('## Authentication');\n\t\tlines.push('');\n\t\tlines.push(renderAuth(spec.auth));\n\t\tlines.push('');\n\t}\n\n\t// Endpoints\n\tlines.push('## Endpoints');\n\tlines.push('');\n\n\t// Group by tag\n\tconst grouped = groupByTag(spec.endpoints);\n\tfor (const [tag, endpoints] of grouped) {\n\t\tif (tag !== '_untagged') {\n\t\t\tlines.push(`### ${tag}`);\n\t\t\tlines.push('');\n\t\t}\n\n\t\tfor (const ep of endpoints) {\n\t\t\tlines.push(renderEndpointSection(ep));\n\t\t\tlines.push('');\n\t\t}\n\t}\n\n\t// Error handling\n\tif (options.includeErrorHandling !== false) {\n\t\tlines.push('## Error Handling');\n\t\tlines.push('');\n\t\tlines.push(renderErrorHandling(spec));\n\t\tlines.push('');\n\t}\n\n\treturn lines.join('\\n');\n}\n\n// ---------------------------------------------------------------------------\n// Per-endpoint mode — one SKILL.md per endpoint\n// ---------------------------------------------------------------------------\n\nfunction renderSingleEndpoint(\n\tspec: ApiSpec,\n\tendpoint: ApiEndpoint,\n\toptions: GenerateOptions,\n): string {\n\tconst lines: string[] = [];\n\n\tconst summary = endpoint.summary ?? endpoint.description ?? `${endpoint.method} ${endpoint.path}`;\n\n\t// Frontmatter\n\tlines.push('---');\n\tlines.push(`name: ${options.name}`);\n\tlines.push(\n\t\t`description: >-`,\n\t\t` ${options.description ?? `Use when the user wants to ${summary.toLowerCase()}. Calls ${endpoint.method} ${endpoint.path}.`}`,\n\t);\n\tlines.push('---');\n\tlines.push('');\n\n\t// Title\n\tlines.push(`# ${summary}`);\n\tlines.push('');\n\n\tif (endpoint.description && endpoint.description !== endpoint.summary) {\n\t\tlines.push(endpoint.description);\n\t\tlines.push('');\n\t}\n\n\t// Base URL\n\tif (spec.servers.length > 0) {\n\t\tlines.push(`**Base URL:** \\`${spec.servers[0]}\\``);\n\t\tlines.push('');\n\t}\n\n\t// Auth\n\tif (spec.auth.length > 0) {\n\t\tlines.push('## Authentication');\n\t\tlines.push('');\n\t\tlines.push(renderAuth(spec.auth));\n\t\tlines.push('');\n\t}\n\n\t// Endpoint details\n\tlines.push(`## ${endpoint.method} \\`${endpoint.path}\\``);\n\tlines.push('');\n\n\t// Parameters\n\tif (endpoint.parameters.length > 0) {\n\t\tlines.push('### Parameters');\n\t\tlines.push('');\n\t\tlines.push(renderParametersTable(endpoint));\n\t\tlines.push('');\n\t}\n\n\t// Request body\n\tif (endpoint.requestBody) {\n\t\tlines.push('### Request Body');\n\t\tlines.push('');\n\t\tlines.push(renderRequestBody(endpoint.requestBody, options));\n\t\tlines.push('');\n\t}\n\n\t// Responses\n\tif (endpoint.responses.length > 0) {\n\t\tlines.push('### Responses');\n\t\tlines.push('');\n\t\tlines.push(renderResponses(endpoint));\n\t\tlines.push('');\n\t}\n\n\t// Example\n\tif (options.includeExamples !== false) {\n\t\tlines.push('## Example');\n\t\tlines.push('');\n\t\tlines.push(renderExample(spec, endpoint));\n\t\tlines.push('');\n\t}\n\n\t// Error handling\n\tif (options.includeErrorHandling !== false) {\n\t\tlines.push('## Error Handling');\n\t\tlines.push('');\n\t\tlines.push(renderEndpointErrorHandling(endpoint));\n\t\tlines.push('');\n\t}\n\n\treturn lines.join('\\n');\n}\n\n// ---------------------------------------------------------------------------\n// Shared rendering helpers\n// ---------------------------------------------------------------------------\n\nfunction buildUnifiedDescription(spec: ApiSpec): string {\n\tconst endpointCount = spec.endpoints.length;\n\tconst methods = new Set(spec.endpoints.map((e) => e.method));\n\tconst methodList = Array.from(methods).join(', ');\n\n\tif (spec.description) {\n\t\treturn `${spec.description.split('.')[0]}. Use when working with the ${spec.title} (${endpointCount} endpoints, ${methodList}).`;\n\t}\n\n\treturn `Interact with the ${spec.title}. Use when the user needs to call any of the ${endpointCount} available endpoints (${methodList}).`;\n}\n\nfunction renderAuth(auth: readonly AuthScheme[]): string {\n\tconst lines: string[] = [];\n\tfor (const scheme of auth) {\n\t\tswitch (scheme.type) {\n\t\t\tcase 'http':\n\t\t\t\tif (scheme.scheme === 'bearer') {\n\t\t\t\t\tlines.push('Use Bearer token authentication:');\n\t\t\t\t\tlines.push('```');\n\t\t\t\t\tlines.push('Authorization: Bearer <token>');\n\t\t\t\t\tlines.push('```');\n\t\t\t\t} else if (scheme.scheme === 'basic') {\n\t\t\t\t\tlines.push('Use HTTP Basic authentication:');\n\t\t\t\t\tlines.push('```');\n\t\t\t\t\tlines.push('Authorization: Basic <base64(username:password)>');\n\t\t\t\t\tlines.push('```');\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'apiKey':\n\t\t\t\tlines.push(`Pass the API key via ${scheme.in ?? 'header'}:`);\n\t\t\t\tlines.push('```');\n\t\t\t\tlines.push(`${scheme.name}: <api-key>`);\n\t\t\t\tlines.push('```');\n\t\t\t\tbreak;\n\t\t\tcase 'oauth2':\n\t\t\t\tlines.push('Uses OAuth 2.0 authentication. Obtain an access token first.');\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tif (scheme.description) {\n\t\t\t\t\tlines.push(scheme.description);\n\t\t\t\t}\n\t\t}\n\t}\n\treturn lines.join('\\n');\n}\n\nfunction groupByTag(endpoints: readonly ApiEndpoint[]): Map<string, ApiEndpoint[]> {\n\tconst grouped = new Map<string, ApiEndpoint[]>();\n\n\tfor (const ep of endpoints) {\n\t\tconst tag = ep.tags.length > 0 ? ep.tags[0]! : '_untagged';\n\t\tconst list = grouped.get(tag) ?? [];\n\t\tlist.push(ep);\n\t\tgrouped.set(tag, list);\n\t}\n\n\treturn grouped;\n}\n\nfunction renderEndpointSection(ep: ApiEndpoint): string {\n\tconst lines: string[] = [];\n\tconst heading = ep.summary ?? `${ep.method} ${ep.path}`;\n\n\tlines.push(`#### ${ep.method} \\`${ep.path}\\` — ${heading}`);\n\tlines.push('');\n\n\tif (ep.description && ep.description !== ep.summary) {\n\t\tlines.push(ep.description);\n\t\tlines.push('');\n\t}\n\n\t// Parameters table\n\tif (ep.parameters.length > 0) {\n\t\tlines.push(renderParametersTable(ep));\n\t\tlines.push('');\n\t}\n\n\t// Request body\n\tif (ep.requestBody) {\n\t\tlines.push(`**Request body** (\\`${ep.requestBody.contentType}\\`):`);\n\t\tlines.push('');\n\t\tlines.push(renderPropertiesTable(ep.requestBody.properties));\n\t\tlines.push('');\n\t}\n\n\t// Compact response summary\n\tconst successResponse = ep.responses.find((r) => r.statusCode.startsWith('2'));\n\tif (successResponse) {\n\t\tlines.push(\n\t\t\t`**Response:** ${successResponse.statusCode} — ${successResponse.description ?? 'Success'}`,\n\t\t);\n\t}\n\n\treturn lines.join('\\n');\n}\n\nfunction renderParametersTable(ep: ApiEndpoint): string {\n\tconst lines: string[] = [];\n\tlines.push('| Parameter | In | Type | Required | Description |');\n\tlines.push('|-----------|-----|------|----------|-------------|');\n\tfor (const param of ep.parameters) {\n\t\tconst req = param.required ? 'Yes' : 'No';\n\t\tconst desc = param.description ?? '';\n\t\tlines.push(`| \\`${param.name}\\` | ${param.in} | ${param.type ?? '-'} | ${req} | ${desc} |`);\n\t}\n\treturn lines.join('\\n');\n}\n\nfunction renderPropertiesTable(properties: readonly ApiProperty[]): string {\n\tif (properties.length === 0) return '';\n\n\tconst lines: string[] = [];\n\tlines.push('| Property | Type | Required | Description |');\n\tlines.push('|----------|------|----------|-------------|');\n\tfor (const prop of properties) {\n\t\tconst req = prop.required ? 'Yes' : 'No';\n\t\tconst desc = prop.description ?? '';\n\t\tlines.push(`| \\`${prop.name}\\` | ${prop.type} | ${req} | ${desc} |`);\n\t}\n\treturn lines.join('\\n');\n}\n\nfunction renderRequestBody(body: ApiRequestBody, options: GenerateOptions): string {\n\tconst lines: string[] = [];\n\tif (body.description) {\n\t\tlines.push(body.description);\n\t\tlines.push('');\n\t}\n\tlines.push(`Content-Type: \\`${body.contentType}\\``);\n\tlines.push('');\n\n\tif (body.properties.length > 0) {\n\t\tlines.push(renderPropertiesTable(body.properties));\n\t}\n\n\tif (options.includeExamples !== false && body.example) {\n\t\tlines.push('');\n\t\tlines.push('**Example:**');\n\t\tlines.push('```json');\n\t\tlines.push(JSON.stringify(body.example, null, 2));\n\t\tlines.push('```');\n\t}\n\n\treturn lines.join('\\n');\n}\n\nfunction renderResponses(ep: ApiEndpoint): string {\n\tconst lines: string[] = [];\n\tfor (const resp of ep.responses) {\n\t\tlines.push(`**${resp.statusCode}** — ${resp.description ?? ''}`);\n\t\tif (resp.properties.length > 0) {\n\t\t\tlines.push('');\n\t\t\tlines.push(renderPropertiesTable(resp.properties));\n\t\t}\n\t\tlines.push('');\n\t}\n\treturn lines.join('\\n');\n}\n\nfunction renderExample(spec: ApiSpec, ep: ApiEndpoint): string {\n\tconst baseUrl = spec.servers[0] ?? 'https://api.example.com';\n\tconst lines: string[] = [];\n\n\tlines.push('```bash');\n\tlines.push(`curl -X ${ep.method} \"${baseUrl}${ep.path}\" \\\\`);\n\n\t// Add auth header hint\n\tif (spec.auth.length > 0) {\n\t\tconst authScheme = spec.auth[0]!;\n\t\tif (authScheme.type === 'http' && authScheme.scheme === 'bearer') {\n\t\t\tlines.push(' -H \"Authorization: Bearer $TOKEN\" \\\\');\n\t\t} else if (authScheme.type === 'apiKey') {\n\t\t\tlines.push(` -H \"${authScheme.name}: $API_KEY\" \\\\`);\n\t\t}\n\t}\n\n\tlines.push(' -H \"Content-Type: application/json\"');\n\n\tif (ep.requestBody?.example) {\n\t\tlines.push(` -d '${JSON.stringify(ep.requestBody.example)}'`);\n\t}\n\n\tlines.push('```');\n\treturn lines.join('\\n');\n}\n\nfunction renderErrorHandling(spec: ApiSpec): string {\n\tconst errorCodes = new Set<string>();\n\tfor (const ep of spec.endpoints) {\n\t\tfor (const resp of ep.responses) {\n\t\t\tif (resp.statusCode.startsWith('4') || resp.statusCode.startsWith('5')) {\n\t\t\t\terrorCodes.add(resp.statusCode);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst lines: string[] = [];\n\tlines.push('Common error responses:');\n\tlines.push('');\n\n\tif (errorCodes.size === 0) {\n\t\tlines.push('- **4xx**: Client error — check request parameters and authentication');\n\t\tlines.push('- **5xx**: Server error — retry with exponential backoff');\n\t} else {\n\t\tfor (const code of Array.from(errorCodes).sort()) {\n\t\t\tlines.push(`- **${code}**: ${httpStatusDescription(code)}`);\n\t\t}\n\t}\n\n\tlines.push('');\n\tlines.push('When an error occurs:');\n\tlines.push('1. Check the response body for a detailed error message');\n\tlines.push('2. Verify authentication credentials are valid');\n\tlines.push('3. For 429 (rate limit), wait and retry with exponential backoff');\n\tlines.push('4. For 5xx errors, retry up to 3 times with backoff');\n\n\treturn lines.join('\\n');\n}\n\nfunction renderEndpointErrorHandling(ep: ApiEndpoint): string {\n\tconst errorResponses = ep.responses.filter(\n\t\t(r) => r.statusCode.startsWith('4') || r.statusCode.startsWith('5'),\n\t);\n\n\tconst lines: string[] = [];\n\n\tif (errorResponses.length > 0) {\n\t\tlines.push('Possible errors:');\n\t\tlines.push('');\n\t\tfor (const resp of errorResponses) {\n\t\t\tlines.push(\n\t\t\t\t`- **${resp.statusCode}**: ${resp.description ?? httpStatusDescription(resp.statusCode)}`,\n\t\t\t);\n\t\t}\n\t} else {\n\t\tlines.push('- Check authentication credentials if you receive a 401/403');\n\t\tlines.push('- Validate request parameters for 400 errors');\n\t\tlines.push('- Retry on 5xx with exponential backoff');\n\t}\n\n\treturn lines.join('\\n');\n}\n\nfunction httpStatusDescription(code: string): string {\n\tconst descriptions: Record<string, string> = {\n\t\t'400': 'Bad Request — check request parameters',\n\t\t'401': 'Unauthorized — check authentication',\n\t\t'403': 'Forbidden — insufficient permissions',\n\t\t'404': 'Not Found — resource does not exist',\n\t\t'405': 'Method Not Allowed',\n\t\t'409': 'Conflict — resource state conflict',\n\t\t'422': 'Unprocessable Entity — validation error',\n\t\t'429': 'Too Many Requests — rate limited, retry after backoff',\n\t\t'500': 'Internal Server Error — retry with backoff',\n\t\t'502': 'Bad Gateway — upstream service error',\n\t\t'503': 'Service Unavailable — retry later',\n\t};\n\treturn descriptions[code] ?? `HTTP ${code} error`;\n}\n\n/**\n * Convert a string to kebab-case.\n */\nfunction toKebabCase(input: string): string {\n\treturn input\n\t\t.replace(/[^a-zA-Z0-9\\s-]/g, '')\n\t\t.replace(/\\s+/g, '-')\n\t\t.replace(/([a-z])([A-Z])/g, '$1-$2')\n\t\t.replace(/-+/g, '-')\n\t\t.toLowerCase()\n\t\t.replace(/^-|-$/g, '')\n\t\t.slice(0, 64);\n}\n","import { readFile } from 'node:fs/promises';\nimport { countTokens } from '@skill-tools/core';\nimport { parseOpenApi } from './openapi.js';\nimport { renderSkillMd } from './renderer.js';\nimport type { ApiSpec, GenerateError, GenerateOptions, GenerateResult } from './types.js';\n\n/**\n * Generate SKILL.md files from an OpenAPI specification file.\n *\n * @param specPath - Path to an OpenAPI 3.x spec (JSON or YAML)\n * @param options - Generation options\n * @returns Generation result with files map, or an error\n */\nexport async function generateFromOpenApi(\n\tspecPath: string,\n\toptions: GenerateOptions = {},\n): Promise<GenerateResult | GenerateError> {\n\ttry {\n\t\tconst content = await readFile(specPath, 'utf-8');\n\t\tconst spec = parseOpenApi(content);\n\t\treturn generateFromSpec(spec, options);\n\t} catch (err) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t};\n\t}\n}\n\n/**\n * Generate SKILL.md files from a pre-parsed ApiSpec.\n *\n * @param spec - The API specification\n * @param options - Generation options\n * @returns Generation result with files map\n */\nexport function generateFromSpec(\n\tspec: ApiSpec,\n\toptions: GenerateOptions = {},\n): GenerateResult | GenerateError {\n\ttry {\n\t\tconst files = renderSkillMd(spec, options);\n\n\t\t// Compute total token count\n\t\tlet totalTokens = 0;\n\t\tfor (const content of files.values()) {\n\t\t\ttotalTokens += countTokens(content);\n\t\t}\n\n\t\t// If maxTokens is set and exceeded in unified mode, warn but don't fail\n\t\tconst maxTokens = options.maxTokens ?? 4000;\n\t\tif (options.mode !== 'per-endpoint' && totalTokens > maxTokens) {\n\t\t\t// Try to truncate — for now, we just return as-is with the count.\n\t\t\t// Future: implement smart truncation.\n\t\t}\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\tfiles,\n\t\t\tendpointCount: spec.endpoints.length,\n\t\t\ttokenCount: totalTokens,\n\t\t};\n\t} catch (err) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t};\n\t}\n}\n\n/**\n * Generate a SKILL.md from a simple text description.\n *\n * This is a lightweight alternative for when you don't have an OpenAPI spec.\n * Produces a basic SKILL.md with the given name and description.\n */\nexport function generateFromText(\n\tname: string,\n\tdescription: string,\n\tinstructions: string = '',\n): GenerateResult {\n\tconst kebabName = name\n\t\t.replace(/[^a-zA-Z0-9\\s-]/g, '')\n\t\t.replace(/\\s+/g, '-')\n\t\t.toLowerCase()\n\t\t.slice(0, 64);\n\n\tconst lines: string[] = [];\n\tlines.push('---');\n\tlines.push(`name: ${kebabName}`);\n\tlines.push(`description: >-`);\n\tlines.push(` ${description}`);\n\tlines.push('---');\n\tlines.push('');\n\tlines.push(`# ${name}`);\n\tlines.push('');\n\tlines.push(description);\n\tlines.push('');\n\n\tif (instructions) {\n\t\tlines.push('## Instructions');\n\t\tlines.push('');\n\t\tlines.push(instructions);\n\t\tlines.push('');\n\t}\n\n\tconst content = lines.join('\\n');\n\tconst files = new Map<string, string>();\n\tfiles.set(`${kebabName}/SKILL.md`, content);\n\n\treturn {\n\t\tok: true,\n\t\tfiles,\n\t\tendpointCount: 0,\n\t\ttokenCount: countTokens(content),\n\t};\n}\n"],"mappings":";AAAA,OAAO,UAAU;AAiBV,SAAS,aAAa,SAA0B;AACtD,QAAM,gBAAgB;AACtB,MAAI,QAAQ,SAAS,eAAe;AACnC,UAAM,IAAI,MAAM,sCAAsC,aAAa,SAAS;AAAA,EAC7E;AAEA,QAAM,MAAM,cAAc,OAAO;AAEjC,QAAM,UAAU,IAAI;AACpB,MAAI,CAAC,WAAW,CAAC,QAAQ,WAAW,IAAI,GAAG;AAC1C,UAAM,IAAI;AAAA,MACT,gCAAgC,WAAW,SAAS;AAAA,IACrD;AAAA,EACD;AAEA,QAAM,QAAQ,IAAI,MAAM,SAAS;AACjC,QAAM,cAAc,IAAI,MAAM,eAAe;AAC7C,QAAM,aAAa,IAAI,MAAM,WAAW;AACxC,QAAM,UAAU,eAAe,GAAG;AAClC,QAAM,OAAO,mBAAmB,GAAG;AACnC,QAAM,YAAY,iBAAiB,GAAG;AAEtC,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAqBA,SAAS,cAAc,SAA6B;AACnD,QAAM,UAAU,QAAQ,KAAK;AAC7B,MAAI,QAAQ,WAAW,GAAG,GAAG;AAC5B,QAAI;AACH,aAAO,KAAK,MAAM,OAAO;AAAA,IAC1B,QAAQ;AAAA,IAER;AAAA,EACD;AACA,SAAO,KAAK,MAAM,OAAO;AAC1B;AAKA,SAAS,WAAW,KAAiB,KAAsC;A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