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,cAAc,CAgDxG;AAMD,uEAAuE;AACvE,wBAAgB,wBAAwB,CACvC,MAAM,EAAE,mBAAmB,EAC3B,kBAAkB,GAAE,MAAM,GAAG,QAAQ,GAAG,SAAqB,EAC7D,YAAY,CAAC,EAAE,OAAO,uCAGtB;AAED,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,CAAC","sourcesContent":["import { canonicalizeSchema, validateAgainstSchema } from \"./canonicalize.js\";\nimport { normalizeToolCall } from \"./repair.js\";\nimport { type ScavengeOrigin, scavengeToolCall } from \"./scavenge.js\";\nimport { applyProviderSchemaCompatibility } from \"./schema-flatten.js\";\nimport type { CanonicalJsonSchema, NormalizedToolCall, RepairOptions, SchemaCompatibilityRecord } from \"./types.js\";\n\nexport interface RawToolCallShape {\n\tname: string;\n\ttoolCallId: string;\n\t/** Provider-native args (already parsed object). */\n\targuments?: Record<string, unknown>;\n\t/** Provider-native args as a raw JSON string (possibly truncated). */\n\targumentsString?: string;\n\t/** When a provider wraps args in an envelope, the envelope payload. */\n\twrapped?: unknown;\n}\n\nexport interface ToolCallPipelineOptions {\n\tschemaById: Record<string, CanonicalJsonSchema>;\n\taliasMap?: Record<string, string>;\n\trepair?: RepairOptions;\n\t/** Provider capability for schema flattening. */\n\tproviderCapability?: \"flat\" | \"nested\" | \"unknown\";\n\tforceFlatten?: boolean;\n\t/** Whether aggressive scavenging of designated tool channels is allowed. */\n\tallowScavenge?: boolean;\n\tensureToolExists?: (name: string) => boolean;\n}\n\nexport interface PipelineResult {\n\tnormalized: NormalizedToolCall | null;\n\tcompatibility?: SchemaCompatibilityRecord;\n\tscavenged?: boolean;\n\tblockedReason?: string;\n}\n\n/**\n * Full provider-independent canonical pipeline for a single raw tool call.\n * Policy/effect evaluation is deliberately NOT performed here (it is the\n * caller's responsibility, before execution), keeping this layer pure.\n */\nexport function runToolCallPipeline(raw: RawToolCallShape, opts: ToolCallPipelineOptions): PipelineResult {\n\tconst canonicalName = normalizeName(raw.name, opts.aliasMap);\n\tconst schema = opts.schemaById[canonicalName] ?? opts.schemaById[raw.name];\n\tif (!schema) {\n\t\treturn { normalized: null, blockedReason: `unknown tool '${raw.name}'` };\n\t}\n\n\t// Provider-native structured arguments.\n\tconst parsedArgs = raw.arguments;\n\tconst rawArgsString = raw.argumentsString;\n\n\tconst normalized = normalizeToolCall({\n\t\tname: canonicalName,\n\t\trawName: raw.name,\n\t\ttoolCallId: raw.toolCallId,\n\t\trawArgs: rawArgsString,\n\t\tparsedArgs,\n\t\tschema,\n\t\tcanonicalName,\n\t\taliasMap: opts.aliasMap,\n\t\toptions: opts.repair,\n\t});\n\n\t// Compatibility envelope handling only when explicitly allowed and when the\n\t// provider tagged the content as a tool channel (origin-dependent).\n\tif (\n\t\topts.allowScavenge === true &&\n\t\traw.wrapped !== undefined &&\n\t\t(normalized.outcome === \"invalid_schema\" || normalized.outcome === \"ambiguous\")\n\t) {\n\t\tfor (const origin of [\n\t\t\t\"documented_compat_envelope\",\n\t\t\t\"provider_escaped_json\",\n\t\t\t\"provider_tool_channel\",\n\t\t] as ScavengeOrigin[]) {\n\t\t\tconst scavenged = scavengeToolCall(raw.wrapped, {\n\t\t\t\torigin,\n\t\t\t\tschemaById: opts.schemaById,\n\t\t\t\taliasMap: opts.aliasMap,\n\t\t\t\tensureToolExists: opts.ensureToolExists,\n\t\t\t});\n\t\t\tif (scavenged) {\n\t\t\t\treturn { normalized: scavenged.normalized, scavenged: true };\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { normalized };\n}\n\nfunction normalizeName(name: string, aliasMap?: Record<string, string>): string {\n\treturn aliasMap?.[name] ?? name;\n}\n\n/** Convenience: canonical validation + schema envelope in one step. */\nexport function prepareSchemaForProvider(\n\tschema: CanonicalJsonSchema,\n\tproviderCapability: \"flat\" | \"nested\" | \"unknown\" = \"unknown\",\n\tforceFlatten?: boolean,\n) {\n\treturn applyProviderSchemaCompatibility(schema, providerCapability, forceFlatten);\n}\n\nexport { canonicalizeSchema, validateAgainstSchema };\n"]}