@code-yeongyu/senpi 2026.7.30-2 → 2026.7.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.
@@ -1 +1 @@
1
- {"version":3,"file":"speculative.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/compaction/speculative.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,iBAAiB,EACjB,yBAAyB,GAKzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAGN,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,4BAA4B,EAC5B,qCAAqC,EACrC,qCAAqC,GACrC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kDAAkD,CAAC;AAC5F,OAAO,EAAE,gCAAgC,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAsC,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,UAAU,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,sBAAsB,GAAG,OAAO,CAAC;AACvC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AACpC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAC5C,qFAAqF;AACrF,qFAAqF;AACrF,sFAAsF;AACtF,qFAAqF;AACrF,oFAAoF;AACpF,MAAM,+BAA+B,GAAG,IAAI,CAAC;AAC7C,MAAM,sBAAsB,GAAG,MAAM,CAAC;AACtC,MAAM,oCAAoC,GAAG,GAAG,CAAC;AACjD,MAAM,cAAc,GAAG,6BAA6B,CAAC;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U,0BAA0B,CAC/C,OAAqC,EACrC,QAAmD,EACnD,oBAAkC,EAClC,QAAqD;IAErD,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;IAEhE,MAAM,UAAU,GAAG,MAAM,QAAQ,EAAE,CAAC;IACpC,OAAO,MAAM,wBAAwB,CAAC,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,UAAU,CAAC,CAAC;AAC5F,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport {\n\ttype AssistantMessage,\n\tisContextOverflow,\n\tisRetryableAssistantError,\n\ttype Message,\n\ttype Model,\n\ttype TextContent,\n\ttype Tool,\n} from \"@earendil-works/pi-ai\";\nimport { stream } from \"@earendil-works/pi-ai/compat\";\nimport {\n\ttype CompactionPreparation,\n\ttype CompactionResult,\n\tDEFAULT_COMPACTION_SETTINGS,\n\testimateContextTokens,\n\testimateTokens,\n\tprepareCompaction,\n} from \"../../../compaction/index.ts\";\nimport {\n\tconsumeStreamWithIdleTimeout,\n\tDEFAULT_SUMMARIZATION_IDLE_TIMEOUT_MS,\n\tDEFAULT_SUMMARIZATION_MAX_DURATION_MS,\n} from \"../../../compaction/stream-watchdog.ts\";\nimport { convertToLlm } from \"../../../messages.ts\";\nimport type { ModelRegistry } from \"../../../model-registry.ts\";\nimport type { ReadonlySessionManager } from \"../../../session-manager.ts\";\nimport type { ApplyCompactionResult, ContextUsage, ProviderRequestPreparation } from \"../../types.ts\";\nimport { sanitizeAnthropicPayload } from \"../tool-pair-guard/sanitize-anthropic-payload.ts\";\nimport { computeEffectiveKeepRecentTokens, computeEffectiveThreshold } from \"./policy.ts\";\nimport { buildPrompt, type MergedCompactionPromptVariant } from \"./prompts.ts\";\nimport { repairOrphanedToolResults } from \"./repair-tool-pairs.ts\";\nimport * as truncation from \"./tool-truncation.ts\";\nimport { computeStructuralYield } from \"./yield.ts\";\n\nconst DEFAULT_CONTEXT_WINDOW = 200_000;\nconst COMPACTION_BUDGET_RATIO = 0.6;\nconst EMERGENCY_CONTEXT_TARGET_RATIO = 0.95;\n// Hysteresis: the emergency prune engages at EMERGENCY_CONTEXT_TARGET_RATIO but only\n// releases once the context falls below this lower ratio. A single threshold makes a\n// session parked near the limit alternate between the pruned and un-pruned history on\n// consecutive requests; because pruning rewrites old tool results, every alternation\n// invalidates the provider prompt-cache prefix and re-bills the whole conversation.\nconst EMERGENCY_CONTEXT_RELEASE_RATIO = 0.85;\nconst SUMMARY_TOKEN_HEADROOM = 32_768;\nconst SUMMARY_CONTEXT_WINDOW_RESERVE_RATIO = 0.5;\nconst SUMMARY_SCHEMA = \"senpi.compaction.summary.v1\";\ntype CompactionProgressCallback = (delta: string) => void;\ntype PruneStep = { messages: AgentMessage[]; removedTokens: number };\n\nexport interface SpeculativeCompactionContext {\n\tmodel: Model<any> | undefined;\n\tsessionManager: ReadonlySessionManager;\n\tmodelRegistry?: ModelRegistry;\n\tgetContextUsage(): ContextUsage | undefined;\n\tgetCompactionSettings?(): CompactionPreparation[\"settings\"];\n\tgetMessageRevision(): number;\n\tgetSystemPrompt?(): string;\n\tprepareProviderRequest?(messages: AgentMessage[]): Promise<ProviderRequestPreparation>;\n\tapplyCompaction(\n\t\tprecomputed: CompactionResult,\n\t\toptions: { reason: \"extension\"; expectedRevision: number; signal?: AbortSignal },\n\t): Promise<ApplyCompactionResult>;\n}\n\nexport interface SpeculativeCompactionSnapshot {\n\tgeneration: number;\n\texpectedRevision: number;\n\tmodel: Model<any>;\n\tcontextWindow: number;\n\tpreparation: CompactionPreparation;\n\tpromptVariant: MergedCompactionPromptVariant;\n\torigin?: \"speculative\" | \"blocking\" | \"core-route\";\n\tcustomInstructions?: string;\n\t/** Agent system prompt; used to make the summarization request look like normal agent traffic. */\n\tsystemPrompt?: string;\n\t/** Agent tool definitions; forwarded so the request shape matches normal agent traffic. */\n\ttools?: Tool[];\n}\n\nexport type SpeculativeCompactionResult = ApplyCompactionResult | { applied: false; reason: \"unavailable\" | \"failed\" };\n\nfunction approxTokens(text: string): number {\n\treturn Math.ceil(text.length / 4);\n}\n\n/**\n * Summary-generation failure with a user-facing diagnosis. Distinct from a\n * user abort (which resolves `undefined`): callers surface `message` on the\n * manual route and degrade to \"unavailable\" on automatic routes.\n */\n/**\n * Provider `error` stop during summarization, carrying the metadata-aware\n * transient classification from the full assistant message. A refusal whose\n * text happens to look retryable must still surface loudly; the message\n * string alone cannot encode that.\n */\nexport class SummaryRequestError extends Error {\n\treadonly transient: boolean;\n\n\tconstructor(message: string, transient: boolean) {\n\t\tsuper(message);\n\t\tthis.name = \"SummaryRequestError\";\n\t\tthis.transient = transient;\n\t}\n}\n\nexport class SummaryGenerationError extends Error {\n\treadonly kind: \"auth\" | \"empty-summary\";\n\n\tconstructor(kind: \"auth\" | \"empty-summary\", message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"SummaryGenerationError\";\n\t\tthis.kind = kind;\n\t}\n}\n\n/**\n * Output budget for one summarization request. Adaptive-thinking models emit\n * reasoning tokens before the summary text, so the legacy flat 8192 cap could\n * be consumed entirely by thinking, ending the stream with zero text blocks.\n * Grant generous headroom, clamped to what the model can actually emit and to\n * half the context window: providers that enforce input + output <= window\n * would otherwise reject the request for models advertising contextWindow ==\n * maxTokens (every summarization request also carries conversation input).\n */\nfunction summaryMaxTokens(model: Model<any>, contextWindow: number): number {\n\tconst headroom = model.maxTokens > 0 ? Math.min(SUMMARY_TOKEN_HEADROOM, model.maxTokens) : SUMMARY_TOKEN_HEADROOM;\n\tif (contextWindow > 0) {\n\t\treturn Math.min(headroom, Math.floor(contextWindow * SUMMARY_CONTEXT_WINDOW_RESERVE_RATIO));\n\t}\n\treturn headroom;\n}\n\n/**\n * Reasoning override for summarization requests. Compaction must be fast: a\n * summarization request that inherits the provider's default reasoning mode\n * burns its latency (and output budget) on invisible thinking before emitting\n * the summary. Disable or minimize reasoning per wire family; adapters ignore\n * options their provider does not support. Mirrors how OpenAI Codex keeps its\n * compaction turn cheap.\n */\nfunction summarizationReasoningOptions(model: Model<any>): Record<string, unknown> {\n\tif (!model.reasoning) return {};\n\tif (model.api === \"anthropic-messages\") return { thinkingEnabled: false };\n\tconst reasoningEffort = ([\"low\", \"medium\", \"high\"] as const).find(\n\t\t(level) => model.thinkingLevelMap?.[level] !== null,\n\t);\n\tif (!reasoningEffort) return {};\n\tswitch (model.api) {\n\t\tcase \"openai-responses\":\n\t\tcase \"openai-codex-responses\":\n\t\tcase \"azure-openai-responses\":\n\t\t\treturn { reasoningEffort, reasoningSummary: null };\n\t\tcase \"openai-completions\":\n\t\t\treturn { reasoningEffort };\n\t\tdefault:\n\t\t\treturn {};\n\t}\n}\n\nfunction getSummaryText(message: Message): string {\n\tconst content = Array.isArray(message.content)\n\t\t? message.content\n\t\t: [{ type: \"text\" as const, text: message.content }];\n\treturn content\n\t\t.filter((content): content is TextContent => content.type === \"text\")\n\t\t.map((content) => content.text)\n\t\t.join(\"\\n\")\n\t\t.trim();\n}\n\nfunction isAssistantMessage(message: Message): message is AssistantMessage {\n\treturn message.role === \"assistant\" && \"stopReason\" in message;\n}\n\nasync function generateSummaryMessage(options: {\n\tcontext: SpeculativeCompactionContext;\n\tmessages: AgentMessage[];\n\tonProgress?: CompactionProgressCallback;\n\tprompt: ReturnType<typeof buildPrompt>;\n\tsignal?: AbortSignal;\n\tsnapshot: SpeculativeCompactionSnapshot;\n\tauth: {\n\t\tapiKey: string;\n\t\theaders?: Record<string, string>;\n\t\textraBody?: Record<string, unknown>;\n\t};\n}): Promise<Message | undefined> {\n\t// Send the conversation as native LLM messages with the summarization\n\t// instruction as a trailing user message, mirroring normal agent traffic.\n\t// A single serialized `<conversation>` text dump of a large session is\n\t// deterministically refused by Anthropic's anti-distillation classifier\n\t// (\"reverse engineering or duplicating model outputs\"), while the same\n\t// content as native blocks with the agent's system prompt and tools passes.\n\t// Request-local controller: the idle watchdog must be able to tear down a\n\t// stalled summarization request without aborting the caller's own signal.\n\tconst requestController = new AbortController();\n\tconst onCallerAbort = () => requestController.abort(options.signal?.reason);\n\tif (options.signal) {\n\t\tif (options.signal.aborted) onCallerAbort();\n\t\telse options.signal.addEventListener(\"abort\", onCallerAbort, { once: true });\n\t}\n\ttry {\n\t\tconst requestMessages: AgentMessage[] = [\n\t\t\t...options.messages,\n\t\t\t{\n\t\t\t\trole: \"user\",\n\t\t\t\tcontent: [{ type: \"text\", text: options.prompt.user }],\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t},\n\t\t];\n\t\tconst providerRequest = await options.context.prepareProviderRequest?.(requestMessages);\n\t\tconst requestContext = {\n\t\t\tsystemPrompt: options.snapshot.systemPrompt ?? options.prompt.system,\n\t\t\tmessages: repairOrphanedToolResults(convertToLlm(providerRequest?.messages ?? requestMessages)),\n\t\t\t...(options.snapshot.tools && options.snapshot.tools.length > 0 ? { tools: options.snapshot.tools } : {}),\n\t\t};\n\t\tconst headers = providerRequest\n\t\t\t? await providerRequest.transformHeaders(options.auth.headers ?? {})\n\t\t\t: options.auth.headers;\n\t\tconst responseStream = stream(options.snapshot.model, requestContext, {\n\t\t\tapiKey: options.auth.apiKey,\n\t\t\theaders,\n\t\t\textraBody: options.auth.extraBody,\n\t\t\tonPayload: async (payload, model) => {\n\t\t\t\tconst sanitized = model.api === \"anthropic-messages\" ? sanitizeAnthropicPayload(payload) : payload;\n\t\t\t\treturn providerRequest ? await providerRequest.transformPayload(sanitized) : sanitized;\n\t\t\t},\n\t\t\tmaxTokens: summaryMaxTokens(options.snapshot.model, options.snapshot.contextWindow),\n\t\t\tsignal: requestController.signal,\n\t\t\t...summarizationReasoningOptions(options.snapshot.model),\n\t\t});\n\t\tawait consumeStreamWithIdleTimeout(responseStream, {\n\t\t\tidleTimeoutMs: DEFAULT_SUMMARIZATION_IDLE_TIMEOUT_MS,\n\t\t\tmaxDurationMs: DEFAULT_SUMMARIZATION_MAX_DURATION_MS,\n\t\t\tabort: () => requestController.abort(),\n\t\t\tsignal: options.signal,\n\t\t\tonEvent: (event) => {\n\t\t\t\tif (event.type === \"text_delta\" && event.delta) {\n\t\t\t\t\toptions.onProgress?.(event.delta);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t\treturn await responseStream.result();\n\t} finally {\n\t\tif (options.signal) options.signal.removeEventListener(\"abort\", onCallerAbort);\n\t}\n}\n\nfunction pruneToolResults(messages: AgentMessage[], contextWindow: number): AgentMessage[] {\n\tconst toolResults = messages\n\t\t.filter((message) => message.role === \"toolResult\")\n\t\t.map((message) => ({ content: message.content, details: undefined }));\n\tif (toolResults.length === 0) return messages;\n\n\tconst prunedResults = truncation.prePruneToolOutputsToBudget(toolResults, contextWindow * COMPACTION_BUDGET_RATIO);\n\tlet resultIndex = 0;\n\treturn messages.map((message) => {\n\t\tif (message.role !== \"toolResult\") return message;\n\t\tconst pruned = prunedResults[resultIndex];\n\t\tresultIndex++;\n\t\treturn pruned ? { ...message, content: pruned.content } : message;\n\t});\n}\n\nexport function truncateContextMessages(messages: AgentMessage[]): AgentMessage[] {\n\tconst toolResults = messages\n\t\t.filter((message) => message.role === \"toolResult\")\n\t\t.map((message) => ({ content: message.content, details: undefined }));\n\tif (toolResults.length === 0) return messages;\n\n\tconst truncatedResults = truncation.truncateOversizedToolResults(toolResults);\n\tlet resultIndex = 0;\n\treturn messages.map((message) => {\n\t\tif (message.role !== \"toolResult\") return message;\n\t\tconst truncated = truncatedResults[resultIndex];\n\t\tresultIndex++;\n\t\treturn truncated ? { ...message, content: truncated.content } : message;\n\t});\n}\n\nfunction getToolCallIds(message: AgentMessage): Set<string> {\n\tconst ids = new Set<string>();\n\tif (message.role !== \"assistant\") return ids;\n\tfor (const block of message.content) {\n\t\tif (block.type === \"toolCall\") ids.add(block.id);\n\t}\n\treturn ids;\n}\n\nfunction findLastUserLikeIndex(messages: AgentMessage[]): number {\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst role = messages[index]?.role;\n\t\tif (role === \"user\" || role === \"bashExecution\") return index;\n\t}\n\treturn messages.length;\n}\n\nfunction removeAssistantToolPair(messages: AgentMessage[], assistantIndex: number): PruneStep {\n\tconst ids = getToolCallIds(messages[assistantIndex]);\n\tlet removedTokens = 0;\n\tconst pruned = messages.filter((message, index) => {\n\t\tconst remove = index === assistantIndex || (message.role === \"toolResult\" && ids.has(message.toolCallId));\n\t\tif (remove) removedTokens += estimateTokens(message);\n\t\treturn !remove;\n\t});\n\treturn { messages: pruned, removedTokens };\n}\n\nfunction removeFirstOldToolPair(messages: AgentMessage[], boundaryIndex: number): PruneStep | undefined {\n\tfor (let index = 0; index < boundaryIndex; index++) {\n\t\tconst message = messages[index];\n\t\tif (!message) continue;\n\t\tif (message.role === \"assistant\" && getToolCallIds(message).size > 0)\n\t\t\treturn removeAssistantToolPair(messages, index);\n\t\tif (message.role === \"toolResult\") {\n\t\t\treturn {\n\t\t\t\tmessages: messages.filter((_message, candidateIndex) => candidateIndex !== index),\n\t\t\t\tremovedTokens: estimateTokens(message),\n\t\t\t};\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction removeFirstOldMessage(messages: AgentMessage[], boundaryIndex: number): PruneStep | undefined {\n\tfor (let index = 0; index < boundaryIndex; index++) {\n\t\tconst message = messages[index];\n\t\tif (!message || message.role === \"toolResult\") continue;\n\t\tif (message.role === \"assistant\" && getToolCallIds(message).size > 0)\n\t\t\treturn removeAssistantToolPair(messages, index);\n\t\treturn {\n\t\t\tmessages: messages.filter((_candidate, candidateIndex) => candidateIndex !== index),\n\t\t\tremovedTokens: estimateTokens(message),\n\t\t};\n\t}\n\treturn undefined;\n}\n\nfunction pruneOldMessagesToBudget(messages: AgentMessage[], targetTokens: number): AgentMessage[] {\n\tlet pruned = messages;\n\tlet total = estimateTotalTokens(pruned);\n\twhile (total > targetTokens) {\n\t\tconst boundaryIndex = findLastUserLikeIndex(pruned);\n\t\tconst next = removeFirstOldToolPair(pruned, boundaryIndex) ?? removeFirstOldMessage(pruned, boundaryIndex);\n\t\tif (!next || next.messages.length === pruned.length) break;\n\t\tpruned = next.messages;\n\t\ttotal -= next.removedTokens;\n\t}\n\treturn pruned;\n}\n\nfunction removeOldestHistoryItemForOverflowRetry(messages: AgentMessage[]): AgentMessage[] | undefined {\n\tif (messages.length <= 1) return undefined;\n\tconst boundaryIndex = findLastUserLikeIndex(messages);\n\treturn (\n\t\tremoveFirstOldToolPair(messages, boundaryIndex)?.messages ??\n\t\tremoveFirstOldMessage(messages, boundaryIndex)?.messages ??\n\t\t(messages.length > 1 ? messages.slice(1) : undefined)\n\t);\n}\n\nfunction estimateTotalTokens(messages: AgentMessage[]): number {\n\tlet total = 0;\n\tfor (const message of messages) total += estimateTokens(message);\n\treturn total;\n}\n\n/**\n * Sticky engage/release state for {@link hardLimitEmergencyPrune}. Callers that\n * issue many requests for one session share a single latch so the emitted context\n * shape stays stable while the estimate hovers around the engage threshold.\n */\nexport interface EmergencyPruneLatch {\n\tengaged: boolean;\n}\n\nexport function createEmergencyPruneLatch(): EmergencyPruneLatch {\n\treturn { engaged: false };\n}\n\nexport function hardLimitEmergencyPrune(\n\tmessages: AgentMessage[],\n\tcontextWindow: number,\n\tlatch?: EmergencyPruneLatch,\n): {\n\tmessages: AgentMessage[];\n\tneedsAggressiveCompaction: boolean;\n} {\n\tconst targetTokens = Math.floor(contextWindow * EMERGENCY_CONTEXT_TARGET_RATIO);\n\tconst releaseTokens = Math.floor(contextWindow * EMERGENCY_CONTEXT_RELEASE_RATIO);\n\tconst totalTokens = estimateTotalTokens(messages);\n\t// Without a latch this keeps the historical single-threshold behaviour.\n\tconst engaged = latch\n\t\t? latch.engaged\n\t\t\t? totalTokens > releaseTokens\n\t\t\t: totalTokens > targetTokens\n\t\t: totalTokens > targetTokens;\n\tif (latch) latch.engaged = engaged;\n\tif (!engaged) {\n\t\treturn { messages, needsAggressiveCompaction: false };\n\t}\n\tconst noLlmPruned = truncateContextMessages(pruneToolResults(messages, contextWindow));\n\tif (estimateTotalTokens(noLlmPruned) <= targetTokens) {\n\t\treturn { messages: noLlmPruned, needsAggressiveCompaction: false };\n\t}\n\treturn {\n\t\tmessages: pruneOldMessagesToBudget(noLlmPruned, targetTokens),\n\t\tneedsAggressiveCompaction: true,\n\t};\n}\n\nexport function getPromptVariant(options: {\n\treason: string;\n\tpreparation: { previousSummary?: string; isSplitTurn: boolean };\n}): MergedCompactionPromptVariant {\n\tif (options.reason === \"branch\") return \"branch\";\n\tif (options.preparation.previousSummary) return \"update\";\n\tif (options.preparation.isSplitTurn) return \"turn_prefix\";\n\treturn \"default\";\n}\n\nexport function createSpeculativeCompactionSnapshot(\n\tcontext: SpeculativeCompactionContext,\n\toptions: {\n\t\tcustomInstructions?: string;\n\t\tgeneration: number;\n\t\torigin?: \"speculative\" | \"blocking\" | \"core-route\";\n\t\ttools?: Tool[];\n\t},\n): SpeculativeCompactionSnapshot | undefined {\n\tconst model = context.model;\n\tif (!model) return undefined;\n\n\tconst expectedRevision = context.getMessageRevision();\n\tconst branchEntries = context.sessionManager.getBranch();\n\tconst contextWindow = context.getContextUsage()?.contextWindow ?? model.contextWindow ?? DEFAULT_CONTEXT_WINDOW;\n\tconst settings = context.getCompactionSettings?.() ?? DEFAULT_COMPACTION_SETTINGS;\n\tconst thresholdRatio = computeEffectiveThreshold(contextWindow);\n\tconst preparation = prepareCompaction(branchEntries, {\n\t\t...settings,\n\t\tkeepRecentTokens: computeEffectiveKeepRecentTokens(settings.keepRecentTokens, contextWindow, thresholdRatio),\n\t});\n\tif (!preparation) return undefined;\n\n\treturn {\n\t\tgeneration: options.generation,\n\t\texpectedRevision,\n\t\tmodel,\n\t\tcontextWindow,\n\t\tpreparation,\n\t\tpromptVariant: getPromptVariant({ reason: \"extension\", preparation }),\n\t\t...(options.origin ? { origin: options.origin } : {}),\n\t\tcustomInstructions: options.customInstructions,\n\t\tsystemPrompt: context.getSystemPrompt?.(),\n\t\ttools: options.tools,\n\t};\n}\n\n/**\n * Generate a compaction summary for the snapshot. Resolves `undefined` only\n * when the request was aborted (caller signal or an aborted stream); every\n * other failure throws — {@link SummaryGenerationError} for diagnosable\n * generation failures, the raw provider error otherwise. Abort is checked\n * before and after credential resolution so a cancelled request never\n * misreports as an auth failure.\n */\nexport async function runExtensionCompaction(\n\tcontext: SpeculativeCompactionContext,\n\tsnapshot: SpeculativeCompactionSnapshot,\n\tsignal?: AbortSignal,\n\tonProgress?: CompactionProgressCallback,\n): Promise<CompactionResult | undefined> {\n\tif (signal?.aborted) return undefined;\n\tconst auth = await context.modelRegistry?.getApiKeyAndHeaders(snapshot.model);\n\tif (signal?.aborted) return undefined;\n\tif (!auth?.ok || !auth.apiKey) {\n\t\tconst detail = auth && !auth.ok ? auth.error : `no API key resolved for provider \"${snapshot.model.provider}\"`;\n\t\tthrow new SummaryGenerationError(\"auth\", `summarization credentials unavailable: ${detail}`);\n\t}\n\n\tlet messages = pruneToolResults(\n\t\t[...snapshot.preparation.messagesToSummarize, ...snapshot.preparation.turnPrefixMessages],\n\t\tsnapshot.contextWindow,\n\t);\n\tconst prompt = buildPrompt({\n\t\tvariant: snapshot.promptVariant,\n\t\tpreviousSummary: snapshot.preparation.previousSummary,\n\t\tcustomInstructions: snapshot.customInstructions,\n\t});\n\n\twhile (true) {\n\t\tif (signal?.aborted) return undefined;\n\t\tconst response = await generateSummaryMessage({\n\t\t\tcontext,\n\t\t\tmessages,\n\t\t\tonProgress,\n\t\t\tprompt,\n\t\t\tsignal,\n\t\t\tsnapshot,\n\t\t\tauth: {\n\t\t\t\tapiKey: auth.apiKey,\n\t\t\t\theaders: auth.headers,\n\t\t\t\textraBody: auth.extraBody,\n\t\t\t},\n\t\t});\n\t\tif (!response) return undefined;\n\n\t\tif (isAssistantMessage(response) && isContextOverflow(response, snapshot.contextWindow)) {\n\t\t\tconst retryMessages = removeOldestHistoryItemForOverflowRetry(messages);\n\t\t\tif (!retryMessages || retryMessages.length === messages.length) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tmessages = retryMessages;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (isAssistantMessage(response) && response.stopReason === \"aborted\") {\n\t\t\t// A partial summary from an aborted stream must never be applied.\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (isAssistantMessage(response) && response.stopReason === \"error\") {\n\t\t\t// Surface the real provider failure instead of silently degrading\n\t\t\t// into a generic \"Compaction cancelled\".\n\t\t\tthrow new SummaryRequestError(\n\t\t\t\tresponse.errorMessage || \"Compaction summary request failed\",\n\t\t\t\tisRetryableAssistantError(response),\n\t\t\t);\n\t\t}\n\n\t\tconst summary = getSummaryText(response);\n\t\tif (!summary) {\n\t\t\tconst stopReason = isAssistantMessage(response) ? response.stopReason : \"unknown\";\n\t\t\tthrow new SummaryGenerationError(\n\t\t\t\t\"empty-summary\",\n\t\t\t\t`summarization response contained no text (stopReason: ${stopReason})`,\n\t\t\t);\n\t\t}\n\n\t\t// Informational only: the core rejects an applied compaction that would\n\t\t// still overflow (_wouldCompactionOverflow). Rejecting here based on the\n\t\t// size of the *discarded* input made large sessions uncompactable.\n\t\tconst tokenEstimate = estimateContextTokens(convertToLlm(messages)).tokens + approxTokens(summary);\n\n\t\treturn {\n\t\t\tsummary,\n\t\t\tfirstKeptEntryId: snapshot.preparation.firstKeptEntryId,\n\t\t\ttokensBefore: snapshot.preparation.tokensBefore,\n\t\t\tdetails: {\n\t\t\t\tschema: SUMMARY_SCHEMA,\n\t\t\t\tpromptVariant: snapshot.promptVariant,\n\t\t\t\ttokenEstimate,\n\t\t\t\tstructuralYield: computeStructuralYield({\n\t\t\t\t\tpreviousSummary: snapshot.preparation.previousSummary ?? \"\",\n\t\t\t\t\tmessagesToSummarize: snapshot.preparation.messagesToSummarize,\n\t\t\t\t\tturnPrefixMessages: snapshot.preparation.turnPrefixMessages,\n\t\t\t\t\tsummary,\n\t\t\t\t\ttokensBefore: snapshot.preparation.tokensBefore,\n\t\t\t\t}),\n\t\t\t\t...(snapshot.origin ? { origin: snapshot.origin } : {}),\n\t\t\t},\n\t\t};\n\t}\n\n\tthrow new Error(\"Compaction summary request exceeded the context window after retrying with a smaller input\");\n}\n\nexport async function applyGeneratedCompaction(\n\tcontext: SpeculativeCompactionContext,\n\tsnapshot: SpeculativeCompactionSnapshot | undefined,\n\tgetCurrentGeneration: () => number,\n\tcompaction: CompactionResult | undefined,\n\tsignal?: AbortSignal,\n): Promise<SpeculativeCompactionResult> {\n\tif (!snapshot || !compaction) return { applied: false, reason: \"unavailable\" };\n\n\tif (snapshot.generation !== getCurrentGeneration() || snapshot.expectedRevision !== context.getMessageRevision()) {\n\t\treturn { applied: false, reason: \"stale\" };\n\t}\n\n\treturn await context.applyCompaction(compaction, {\n\t\treason: \"extension\",\n\t\texpectedRevision: snapshot.expectedRevision,\n\t\tsignal,\n\t});\n}\n\nexport async function applySpeculativeCompaction(\n\tcontext: SpeculativeCompactionContext,\n\tsnapshot: SpeculativeCompactionSnapshot | undefined,\n\tgetCurrentGeneration: () => number,\n\tgenerate: () => Promise<CompactionResult | undefined>,\n): Promise<SpeculativeCompactionResult> {\n\tif (!snapshot) return { applied: false, reason: \"unavailable\" };\n\n\tconst compaction = await generate();\n\treturn await applyGeneratedCompaction(context, snapshot, getCurrentGeneration, compaction);\n}\n"]}
1
+ {"version":3,"file":"speculative.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/compaction/speculative.ts"],"names":[],"mappings":"AACA,OAAO,EAIN,oBAAoB,EACpB,iBAAiB,EACjB,yBAAyB,GAMzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAGN,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,4BAA4B,EAC5B,qCAAqC,EACrC,qCAAqC,GACrC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kDAAkD,C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,aAAa,EAAE,CAAC;IAEhE,MAAM,UAAU,GAAG,MAAM,QAAQ,EAAE,CAAC;IACpC,OAAO,MAAM,wBAAwB,CAAC,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,UAAU,CAAC,CAAC;AAC5F,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport {\n\ttype AssistantMessage,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\thasCredentialHeaders,\n\tisContextOverflow,\n\tisRetryableAssistantError,\n\ttype Message,\n\ttype Model,\n\ttype StreamOptions,\n\ttype TextContent,\n\ttype Tool,\n} from \"@earendil-works/pi-ai\";\nimport { stream } from \"@earendil-works/pi-ai/compat\";\nimport {\n\ttype CompactionPreparation,\n\ttype CompactionResult,\n\tDEFAULT_COMPACTION_SETTINGS,\n\testimateContextTokens,\n\testimateTokens,\n\tprepareCompaction,\n} from \"../../../compaction/index.ts\";\nimport {\n\tconsumeStreamWithIdleTimeout,\n\tDEFAULT_SUMMARIZATION_IDLE_TIMEOUT_MS,\n\tDEFAULT_SUMMARIZATION_MAX_DURATION_MS,\n} from \"../../../compaction/stream-watchdog.ts\";\nimport { convertToLlm } from \"../../../messages.ts\";\nimport type { ModelRegistry } from \"../../../model-registry.ts\";\nimport type { ReadonlySessionManager } from \"../../../session-manager.ts\";\nimport type { ApplyCompactionResult, ContextUsage, ProviderRequestPreparation } from \"../../types.ts\";\nimport { sanitizeAnthropicPayload } from \"../tool-pair-guard/sanitize-anthropic-payload.ts\";\nimport { computeEffectiveKeepRecentTokens, computeEffectiveThreshold } from \"./policy.ts\";\nimport { buildPrompt, type MergedCompactionPromptVariant } from \"./prompts.ts\";\nimport { repairOrphanedToolResults } from \"./repair-tool-pairs.ts\";\nimport * as truncation from \"./tool-truncation.ts\";\nimport { computeStructuralYield } from \"./yield.ts\";\n\nconst DEFAULT_CONTEXT_WINDOW = 200_000;\nconst COMPACTION_BUDGET_RATIO = 0.6;\nconst EMERGENCY_CONTEXT_TARGET_RATIO = 0.95;\n// Hysteresis: the emergency prune engages at EMERGENCY_CONTEXT_TARGET_RATIO but only\n// releases once the context falls below this lower ratio. A single threshold makes a\n// session parked near the limit alternate between the pruned and un-pruned history on\n// consecutive requests; because pruning rewrites old tool results, every alternation\n// invalidates the provider prompt-cache prefix and re-bills the whole conversation.\nconst EMERGENCY_CONTEXT_RELEASE_RATIO = 0.85;\nconst SUMMARY_TOKEN_HEADROOM = 32_768;\nconst SUMMARY_CONTEXT_WINDOW_RESERVE_RATIO = 0.5;\nconst SUMMARY_SCHEMA = \"senpi.compaction.summary.v1\";\ntype CompactionProgressCallback = (delta: string) => void;\ntype PruneStep = { messages: AgentMessage[]; removedTokens: number };\n\nexport interface SpeculativeCompactionContext {\n\tmodel: Model<any> | undefined;\n\tsessionManager: ReadonlySessionManager;\n\tmodelRegistry?: ModelRegistry;\n\tgetContextUsage(): ContextUsage | undefined;\n\tgetCompactionSettings?(): CompactionPreparation[\"settings\"];\n\tgetMessageRevision(): number;\n\tgetSystemPrompt?(): string;\n\tprepareProviderRequest?(messages: AgentMessage[]): Promise<ProviderRequestPreparation>;\n\tapplyCompaction(\n\t\tprecomputed: CompactionResult,\n\t\toptions: { reason: \"extension\"; expectedRevision: number; signal?: AbortSignal },\n\t): Promise<ApplyCompactionResult>;\n}\n\nexport interface SpeculativeCompactionSnapshot {\n\tgeneration: number;\n\texpectedRevision: number;\n\tmodel: Model<any>;\n\tcontextWindow: number;\n\tpreparation: CompactionPreparation;\n\tpromptVariant: MergedCompactionPromptVariant;\n\torigin?: \"speculative\" | \"blocking\" | \"core-route\";\n\tcustomInstructions?: string;\n\t/** Agent system prompt; used to make the summarization request look like normal agent traffic. */\n\tsystemPrompt?: string;\n\t/** Agent tool definitions; forwarded so the request shape matches normal agent traffic. */\n\ttools?: Tool[];\n}\n\nexport type SpeculativeCompactionResult = ApplyCompactionResult | { applied: false; reason: \"unavailable\" | \"failed\" };\n\nfunction approxTokens(text: string): number {\n\treturn Math.ceil(text.length / 4);\n}\n\n/**\n * Summary-generation failure with a user-facing diagnosis. Distinct from a\n * user abort (which resolves `undefined`): callers surface `message` on the\n * manual route and degrade to \"unavailable\" on automatic routes.\n */\n/**\n * Provider `error` stop during summarization, carrying the metadata-aware\n * transient classification from the full assistant message. A refusal whose\n * text happens to look retryable must still surface loudly; the message\n * string alone cannot encode that.\n */\nexport class SummaryRequestError extends Error {\n\treadonly transient: boolean;\n\n\tconstructor(message: string, transient: boolean) {\n\t\tsuper(message);\n\t\tthis.name = \"SummaryRequestError\";\n\t\tthis.transient = transient;\n\t}\n}\n\nexport class SummaryGenerationError extends Error {\n\treadonly kind: \"auth\" | \"empty-summary\";\n\n\tconstructor(kind: \"auth\" | \"empty-summary\", message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"SummaryGenerationError\";\n\t\tthis.kind = kind;\n\t}\n}\n\n/**\n * Output budget for one summarization request. Adaptive-thinking models emit\n * reasoning tokens before the summary text, so the legacy flat 8192 cap could\n * be consumed entirely by thinking, ending the stream with zero text blocks.\n * Grant generous headroom, clamped to what the model can actually emit and to\n * half the context window: providers that enforce input + output <= window\n * would otherwise reject the request for models advertising contextWindow ==\n * maxTokens (every summarization request also carries conversation input).\n */\nfunction summaryMaxTokens(model: Model<any>, contextWindow: number): number {\n\tconst headroom = model.maxTokens > 0 ? Math.min(SUMMARY_TOKEN_HEADROOM, model.maxTokens) : SUMMARY_TOKEN_HEADROOM;\n\tif (contextWindow > 0) {\n\t\treturn Math.min(headroom, Math.floor(contextWindow * SUMMARY_CONTEXT_WINDOW_RESERVE_RATIO));\n\t}\n\treturn headroom;\n}\n\n/**\n * Reasoning override for summarization requests. Compaction must be fast: a\n * summarization request that inherits the provider's default reasoning mode\n * burns its latency (and output budget) on invisible thinking before emitting\n * the summary. Disable or minimize reasoning per wire family; adapters ignore\n * options their provider does not support. Mirrors how OpenAI Codex keeps its\n * compaction turn cheap.\n */\nfunction summarizationReasoningOptions(model: Model<any>): Record<string, unknown> {\n\tif (!model.reasoning) return {};\n\tif (model.api === \"anthropic-messages\") return { thinkingEnabled: false };\n\tconst reasoningEffort = ([\"low\", \"medium\", \"high\"] as const).find(\n\t\t(level) => model.thinkingLevelMap?.[level] !== null,\n\t);\n\tif (!reasoningEffort) return {};\n\tswitch (model.api) {\n\t\tcase \"openai-responses\":\n\t\tcase \"openai-codex-responses\":\n\t\tcase \"azure-openai-responses\":\n\t\t\treturn { reasoningEffort, reasoningSummary: null };\n\t\tcase \"openai-completions\":\n\t\t\treturn { reasoningEffort };\n\t\tdefault:\n\t\t\treturn {};\n\t}\n}\n\nfunction getSummaryText(message: Message): string {\n\tconst content = Array.isArray(message.content)\n\t\t? message.content\n\t\t: [{ type: \"text\" as const, text: message.content }];\n\treturn content\n\t\t.filter((content): content is TextContent => content.type === \"text\")\n\t\t.map((content) => content.text)\n\t\t.join(\"\\n\")\n\t\t.trim();\n}\n\nfunction isAssistantMessage(message: Message): message is AssistantMessage {\n\treturn message.role === \"assistant\" && \"stopReason\" in message;\n}\n\n/**\n * Providers registered through `pi.registerProvider()` (claude-agent-sdk, Kiro, any\n * extension provider) exist only in Senpi's ModelRuntime, never in compat's builtin\n * api-registry, which rejects their api id outright. Dispatch through the runtime\n * whenever it is reachable and keep compat for contexts constructed without a registry.\n */\nfunction summarizationStream(\n\tcontext: SpeculativeCompactionContext,\n\tmodel: Model<any>,\n\trequestContext: Context,\n\toptions: StreamOptions & Record<string, unknown>,\n): AssistantMessageEventStream {\n\tconst runtime = context.modelRegistry?.modelRuntime;\n\treturn runtime ? runtime.stream(model, requestContext, options) : stream(model, requestContext, options);\n}\n\nasync function generateSummaryMessage(options: {\n\tcontext: SpeculativeCompactionContext;\n\tmessages: AgentMessage[];\n\tonProgress?: CompactionProgressCallback;\n\tprompt: ReturnType<typeof buildPrompt>;\n\tsignal?: AbortSignal;\n\tsnapshot: SpeculativeCompactionSnapshot;\n\tauth: {\n\t\tapiKey?: string;\n\t\theaders?: Record<string, string>;\n\t\textraBody?: Record<string, unknown>;\n\t};\n}): Promise<Message | undefined> {\n\t// Send the conversation as native LLM messages with the summarization\n\t// instruction as a trailing user message, mirroring normal agent traffic.\n\t// A single serialized `<conversation>` text dump of a large session is\n\t// deterministically refused by Anthropic's anti-distillation classifier\n\t// (\"reverse engineering or duplicating model outputs\"), while the same\n\t// content as native blocks with the agent's system prompt and tools passes.\n\t// Request-local controller: the idle watchdog must be able to tear down a\n\t// stalled summarization request without aborting the caller's own signal.\n\tconst requestController = new AbortController();\n\tconst onCallerAbort = () => requestController.abort(options.signal?.reason);\n\tif (options.signal) {\n\t\tif (options.signal.aborted) onCallerAbort();\n\t\telse options.signal.addEventListener(\"abort\", onCallerAbort, { once: true });\n\t}\n\ttry {\n\t\tconst requestMessages: AgentMessage[] = [\n\t\t\t...options.messages,\n\t\t\t{\n\t\t\t\trole: \"user\",\n\t\t\t\tcontent: [{ type: \"text\", text: options.prompt.user }],\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t},\n\t\t];\n\t\tconst providerRequest = await options.context.prepareProviderRequest?.(requestMessages);\n\t\tconst requestContext = {\n\t\t\tsystemPrompt: options.snapshot.systemPrompt ?? options.prompt.system,\n\t\t\tmessages: repairOrphanedToolResults(convertToLlm(providerRequest?.messages ?? requestMessages)),\n\t\t\t...(options.snapshot.tools && options.snapshot.tools.length > 0 ? { tools: options.snapshot.tools } : {}),\n\t\t};\n\t\tconst headers = providerRequest\n\t\t\t? await providerRequest.transformHeaders(options.auth.headers ?? {})\n\t\t\t: options.auth.headers;\n\t\tconst responseStream = summarizationStream(options.context, options.snapshot.model, requestContext, {\n\t\t\tapiKey: options.auth.apiKey,\n\t\t\theaders,\n\t\t\textraBody: options.auth.extraBody,\n\t\t\tonPayload: async (payload, model) => {\n\t\t\t\tconst sanitized = model.api === \"anthropic-messages\" ? sanitizeAnthropicPayload(payload) : payload;\n\t\t\t\treturn providerRequest ? await providerRequest.transformPayload(sanitized) : sanitized;\n\t\t\t},\n\t\t\tmaxTokens: summaryMaxTokens(options.snapshot.model, options.snapshot.contextWindow),\n\t\t\tsignal: requestController.signal,\n\t\t\t...summarizationReasoningOptions(options.snapshot.model),\n\t\t});\n\t\tawait consumeStreamWithIdleTimeout(responseStream, {\n\t\t\tidleTimeoutMs: DEFAULT_SUMMARIZATION_IDLE_TIMEOUT_MS,\n\t\t\tmaxDurationMs: DEFAULT_SUMMARIZATION_MAX_DURATION_MS,\n\t\t\tabort: () => requestController.abort(),\n\t\t\tsignal: options.signal,\n\t\t\tonEvent: (event) => {\n\t\t\t\tif (event.type === \"text_delta\" && event.delta) {\n\t\t\t\t\toptions.onProgress?.(event.delta);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t\treturn await responseStream.result();\n\t} finally {\n\t\tif (options.signal) options.signal.removeEventListener(\"abort\", onCallerAbort);\n\t}\n}\n\nfunction pruneToolResults(messages: AgentMessage[], contextWindow: number): AgentMessage[] {\n\tconst toolResults = messages\n\t\t.filter((message) => message.role === \"toolResult\")\n\t\t.map((message) => ({ content: message.content, details: undefined }));\n\tif (toolResults.length === 0) return messages;\n\n\tconst prunedResults = truncation.prePruneToolOutputsToBudget(toolResults, contextWindow * COMPACTION_BUDGET_RATIO);\n\tlet resultIndex = 0;\n\treturn messages.map((message) => {\n\t\tif (message.role !== \"toolResult\") return message;\n\t\tconst pruned = prunedResults[resultIndex];\n\t\tresultIndex++;\n\t\treturn pruned ? { ...message, content: pruned.content } : message;\n\t});\n}\n\nexport function truncateContextMessages(messages: AgentMessage[]): AgentMessage[] {\n\tconst toolResults = messages\n\t\t.filter((message) => message.role === \"toolResult\")\n\t\t.map((message) => ({ content: message.content, details: undefined }));\n\tif (toolResults.length === 0) return messages;\n\n\tconst truncatedResults = truncation.truncateOversizedToolResults(toolResults);\n\tlet resultIndex = 0;\n\treturn messages.map((message) => {\n\t\tif (message.role !== \"toolResult\") return message;\n\t\tconst truncated = truncatedResults[resultIndex];\n\t\tresultIndex++;\n\t\treturn truncated ? { ...message, content: truncated.content } : message;\n\t});\n}\n\nfunction getToolCallIds(message: AgentMessage): Set<string> {\n\tconst ids = new Set<string>();\n\tif (message.role !== \"assistant\") return ids;\n\tfor (const block of message.content) {\n\t\tif (block.type === \"toolCall\") ids.add(block.id);\n\t}\n\treturn ids;\n}\n\nfunction findLastUserLikeIndex(messages: AgentMessage[]): number {\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst role = messages[index]?.role;\n\t\tif (role === \"user\" || role === \"bashExecution\") return index;\n\t}\n\treturn messages.length;\n}\n\nfunction removeAssistantToolPair(messages: AgentMessage[], assistantIndex: number): PruneStep {\n\tconst ids = getToolCallIds(messages[assistantIndex]);\n\tlet removedTokens = 0;\n\tconst pruned = messages.filter((message, index) => {\n\t\tconst remove = index === assistantIndex || (message.role === \"toolResult\" && ids.has(message.toolCallId));\n\t\tif (remove) removedTokens += estimateTokens(message);\n\t\treturn !remove;\n\t});\n\treturn { messages: pruned, removedTokens };\n}\n\nfunction removeFirstOldToolPair(messages: AgentMessage[], boundaryIndex: number): PruneStep | undefined {\n\tfor (let index = 0; index < boundaryIndex; index++) {\n\t\tconst message = messages[index];\n\t\tif (!message) continue;\n\t\tif (message.role === \"assistant\" && getToolCallIds(message).size > 0)\n\t\t\treturn removeAssistantToolPair(messages, index);\n\t\tif (message.role === \"toolResult\") {\n\t\t\treturn {\n\t\t\t\tmessages: messages.filter((_message, candidateIndex) => candidateIndex !== index),\n\t\t\t\tremovedTokens: estimateTokens(message),\n\t\t\t};\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction removeFirstOldMessage(messages: AgentMessage[], boundaryIndex: number): PruneStep | undefined {\n\tfor (let index = 0; index < boundaryIndex; index++) {\n\t\tconst message = messages[index];\n\t\tif (!message || message.role === \"toolResult\") continue;\n\t\tif (message.role === \"assistant\" && getToolCallIds(message).size > 0)\n\t\t\treturn removeAssistantToolPair(messages, index);\n\t\treturn {\n\t\t\tmessages: messages.filter((_candidate, candidateIndex) => candidateIndex !== index),\n\t\t\tremovedTokens: estimateTokens(message),\n\t\t};\n\t}\n\treturn undefined;\n}\n\nfunction pruneOldMessagesToBudget(messages: AgentMessage[], targetTokens: number): AgentMessage[] {\n\tlet pruned = messages;\n\tlet total = estimateTotalTokens(pruned);\n\twhile (total > targetTokens) {\n\t\tconst boundaryIndex = findLastUserLikeIndex(pruned);\n\t\tconst next = removeFirstOldToolPair(pruned, boundaryIndex) ?? removeFirstOldMessage(pruned, boundaryIndex);\n\t\tif (!next || next.messages.length === pruned.length) break;\n\t\tpruned = next.messages;\n\t\ttotal -= next.removedTokens;\n\t}\n\treturn pruned;\n}\n\nfunction removeOldestHistoryItemForOverflowRetry(messages: AgentMessage[]): AgentMessage[] | undefined {\n\tif (messages.length <= 1) return undefined;\n\tconst boundaryIndex = findLastUserLikeIndex(messages);\n\treturn (\n\t\tremoveFirstOldToolPair(messages, boundaryIndex)?.messages ??\n\t\tremoveFirstOldMessage(messages, boundaryIndex)?.messages ??\n\t\t(messages.length > 1 ? messages.slice(1) : undefined)\n\t);\n}\n\nfunction estimateTotalTokens(messages: AgentMessage[]): number {\n\tlet total = 0;\n\tfor (const message of messages) total += estimateTokens(message);\n\treturn total;\n}\n\n/**\n * Sticky engage/release state for {@link hardLimitEmergencyPrune}. Callers that\n * issue many requests for one session share a single latch so the emitted context\n * shape stays stable while the estimate hovers around the engage threshold.\n */\nexport interface EmergencyPruneLatch {\n\tengaged: boolean;\n}\n\nexport function createEmergencyPruneLatch(): EmergencyPruneLatch {\n\treturn { engaged: false };\n}\n\nexport function hardLimitEmergencyPrune(\n\tmessages: AgentMessage[],\n\tcontextWindow: number,\n\tlatch?: EmergencyPruneLatch,\n): {\n\tmessages: AgentMessage[];\n\tneedsAggressiveCompaction: boolean;\n} {\n\tconst targetTokens = Math.floor(contextWindow * EMERGENCY_CONTEXT_TARGET_RATIO);\n\tconst releaseTokens = Math.floor(contextWindow * EMERGENCY_CONTEXT_RELEASE_RATIO);\n\tconst totalTokens = estimateTotalTokens(messages);\n\t// Without a latch this keeps the historical single-threshold behaviour.\n\tconst engaged = latch\n\t\t? latch.engaged\n\t\t\t? totalTokens > releaseTokens\n\t\t\t: totalTokens > targetTokens\n\t\t: totalTokens > targetTokens;\n\tif (latch) latch.engaged = engaged;\n\tif (!engaged) {\n\t\treturn { messages, needsAggressiveCompaction: false };\n\t}\n\tconst noLlmPruned = truncateContextMessages(pruneToolResults(messages, contextWindow));\n\tif (estimateTotalTokens(noLlmPruned) <= targetTokens) {\n\t\treturn { messages: noLlmPruned, needsAggressiveCompaction: false };\n\t}\n\treturn {\n\t\tmessages: pruneOldMessagesToBudget(noLlmPruned, targetTokens),\n\t\tneedsAggressiveCompaction: true,\n\t};\n}\n\nexport function getPromptVariant(options: {\n\treason: string;\n\tpreparation: { previousSummary?: string; isSplitTurn: boolean };\n}): MergedCompactionPromptVariant {\n\tif (options.reason === \"branch\") return \"branch\";\n\tif (options.preparation.previousSummary) return \"update\";\n\tif (options.preparation.isSplitTurn) return \"turn_prefix\";\n\treturn \"default\";\n}\n\nexport function createSpeculativeCompactionSnapshot(\n\tcontext: SpeculativeCompactionContext,\n\toptions: {\n\t\tcustomInstructions?: string;\n\t\tgeneration: number;\n\t\torigin?: \"speculative\" | \"blocking\" | \"core-route\";\n\t\ttools?: Tool[];\n\t},\n): SpeculativeCompactionSnapshot | undefined {\n\tconst model = context.model;\n\tif (!model) return undefined;\n\n\tconst expectedRevision = context.getMessageRevision();\n\tconst branchEntries = context.sessionManager.getBranch();\n\tconst contextWindow = context.getContextUsage()?.contextWindow ?? model.contextWindow ?? DEFAULT_CONTEXT_WINDOW;\n\tconst settings = context.getCompactionSettings?.() ?? DEFAULT_COMPACTION_SETTINGS;\n\tconst thresholdRatio = computeEffectiveThreshold(contextWindow);\n\tconst preparation = prepareCompaction(branchEntries, {\n\t\t...settings,\n\t\tkeepRecentTokens: computeEffectiveKeepRecentTokens(settings.keepRecentTokens, contextWindow, thresholdRatio),\n\t});\n\tif (!preparation) return undefined;\n\n\treturn {\n\t\tgeneration: options.generation,\n\t\texpectedRevision,\n\t\tmodel,\n\t\tcontextWindow,\n\t\tpreparation,\n\t\tpromptVariant: getPromptVariant({ reason: \"extension\", preparation }),\n\t\t...(options.origin ? { origin: options.origin } : {}),\n\t\tcustomInstructions: options.customInstructions,\n\t\tsystemPrompt: context.getSystemPrompt?.(),\n\t\ttools: options.tools,\n\t};\n}\n\n/**\n * Generate a compaction summary for the snapshot. Resolves `undefined` only\n * when the request was aborted (caller signal or an aborted stream); every\n * other failure throws — {@link SummaryGenerationError} for diagnosable\n * generation failures, the raw provider error otherwise. Abort is checked\n * before and after credential resolution so a cancelled request never\n * misreports as an auth failure.\n */\nexport async function runExtensionCompaction(\n\tcontext: SpeculativeCompactionContext,\n\tsnapshot: SpeculativeCompactionSnapshot,\n\tsignal?: AbortSignal,\n\tonProgress?: CompactionProgressCallback,\n): Promise<CompactionResult | undefined> {\n\tif (signal?.aborted) return undefined;\n\tconst auth = await context.modelRegistry?.getApiKeyAndHeaders(snapshot.model);\n\tif (signal?.aborted) return undefined;\n\t// A provider is authenticated for summarization by either a resolved key or a\n\t// credential request header: `headers`-authenticated providers (models.json and\n\t// extension providers alike) never resolve an apiKey, yet their normal agent\n\t// turns are fully authenticated.\n\tif (!auth?.ok || !(auth.apiKey || hasCredentialHeaders(auth.headers))) {\n\t\tconst detail =\n\t\t\tauth && !auth.ok ? auth.error : `no credentials resolved for provider \"${snapshot.model.provider}\"`;\n\t\tthrow new SummaryGenerationError(\"auth\", `summarization credentials unavailable: ${detail}`);\n\t}\n\n\tlet messages = pruneToolResults(\n\t\t[...snapshot.preparation.messagesToSummarize, ...snapshot.preparation.turnPrefixMessages],\n\t\tsnapshot.contextWindow,\n\t);\n\tconst prompt = buildPrompt({\n\t\tvariant: snapshot.promptVariant,\n\t\tpreviousSummary: snapshot.preparation.previousSummary,\n\t\tcustomInstructions: snapshot.customInstructions,\n\t});\n\n\twhile (true) {\n\t\tif (signal?.aborted) return undefined;\n\t\tconst response = await generateSummaryMessage({\n\t\t\tcontext,\n\t\t\tmessages,\n\t\t\tonProgress,\n\t\t\tprompt,\n\t\t\tsignal,\n\t\t\tsnapshot,\n\t\t\tauth: {\n\t\t\t\tapiKey: auth.apiKey,\n\t\t\t\theaders: auth.headers,\n\t\t\t\textraBody: auth.extraBody,\n\t\t\t},\n\t\t});\n\t\tif (!response) return undefined;\n\n\t\tif (isAssistantMessage(response) && isContextOverflow(response, snapshot.contextWindow)) {\n\t\t\tconst retryMessages = removeOldestHistoryItemForOverflowRetry(messages);\n\t\t\tif (!retryMessages || retryMessages.length === messages.length) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tmessages = retryMessages;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (isAssistantMessage(response) && response.stopReason === \"aborted\") {\n\t\t\t// A partial summary from an aborted stream must never be applied.\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (isAssistantMessage(response) && response.stopReason === \"error\") {\n\t\t\t// Surface the real provider failure instead of silently degrading\n\t\t\t// into a generic \"Compaction cancelled\".\n\t\t\tthrow new SummaryRequestError(\n\t\t\t\tresponse.errorMessage || \"Compaction summary request failed\",\n\t\t\t\tisRetryableAssistantError(response),\n\t\t\t);\n\t\t}\n\n\t\tconst summary = getSummaryText(response);\n\t\tif (!summary) {\n\t\t\tconst stopReason = isAssistantMessage(response) ? response.stopReason : \"unknown\";\n\t\t\tthrow new SummaryGenerationError(\n\t\t\t\t\"empty-summary\",\n\t\t\t\t`summarization response contained no text (stopReason: ${stopReason})`,\n\t\t\t);\n\t\t}\n\n\t\t// Informational only: the core rejects an applied compaction that would\n\t\t// still overflow (_wouldCompactionOverflow). Rejecting here based on the\n\t\t// size of the *discarded* input made large sessions uncompactable.\n\t\tconst tokenEstimate = estimateContextTokens(convertToLlm(messages)).tokens + approxTokens(summary);\n\n\t\treturn {\n\t\t\tsummary,\n\t\t\tfirstKeptEntryId: snapshot.preparation.firstKeptEntryId,\n\t\t\ttokensBefore: snapshot.preparation.tokensBefore,\n\t\t\tdetails: {\n\t\t\t\tschema: SUMMARY_SCHEMA,\n\t\t\t\tpromptVariant: snapshot.promptVariant,\n\t\t\t\ttokenEstimate,\n\t\t\t\tstructuralYield: computeStructuralYield({\n\t\t\t\t\tpreviousSummary: snapshot.preparation.previousSummary ?? \"\",\n\t\t\t\t\tmessagesToSummarize: snapshot.preparation.messagesToSummarize,\n\t\t\t\t\tturnPrefixMessages: snapshot.preparation.turnPrefixMessages,\n\t\t\t\t\tsummary,\n\t\t\t\t\ttokensBefore: snapshot.preparation.tokensBefore,\n\t\t\t\t}),\n\t\t\t\t...(snapshot.origin ? { origin: snapshot.origin } : {}),\n\t\t\t},\n\t\t};\n\t}\n\n\tthrow new Error(\"Compaction summary request exceeded the context window after retrying with a smaller input\");\n}\n\nexport async function applyGeneratedCompaction(\n\tcontext: SpeculativeCompactionContext,\n\tsnapshot: SpeculativeCompactionSnapshot | undefined,\n\tgetCurrentGeneration: () => number,\n\tcompaction: CompactionResult | undefined,\n\tsignal?: AbortSignal,\n): Promise<SpeculativeCompactionResult> {\n\tif (!snapshot || !compaction) return { applied: false, reason: \"unavailable\" };\n\n\tif (snapshot.generation !== getCurrentGeneration() || snapshot.expectedRevision !== context.getMessageRevision()) {\n\t\treturn { applied: false, reason: \"stale\" };\n\t}\n\n\treturn await context.applyCompaction(compaction, {\n\t\treason: \"extension\",\n\t\texpectedRevision: snapshot.expectedRevision,\n\t\tsignal,\n\t});\n}\n\nexport async function applySpeculativeCompaction(\n\tcontext: SpeculativeCompactionContext,\n\tsnapshot: SpeculativeCompactionSnapshot | undefined,\n\tgetCurrentGeneration: () => number,\n\tgenerate: () => Promise<CompactionResult | undefined>,\n): Promise<SpeculativeCompactionResult> {\n\tif (!snapshot) return { applied: false, reason: \"unavailable\" };\n\n\tconst compaction = await generate();\n\treturn await applyGeneratedCompaction(context, snapshot, getCurrentGeneration, compaction);\n}\n"]}
@@ -12,6 +12,18 @@
12
12
 
13
13
  ### Removed
14
14
 
15
+ ## [2026.7.31] - 2026-07-31
16
+
17
+ ### Breaking Changes
18
+
19
+ ### Added
20
+
21
+ ### Changed
22
+
23
+ ### Fixed
24
+
25
+ ### Removed
26
+
15
27
  ## [2026.7.30-2] - 2026-07-30
16
28
 
17
29
  ### Breaking Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi-codemode",
3
- "version": "2026.7.30-2",
3
+ "version": "2026.7.31",
4
4
  "description": "Source-only senpi extension package for codemode evaluation tools",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -30,14 +30,14 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@babel/parser": "8.0.4",
33
- "@earendil-works/pi-ai": "^2026.7.30-2",
33
+ "@earendil-works/pi-ai": "^2026.7.31",
34
34
  "typebox": "1.3.8"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@code-yeongyu/senpi": "*"
38
38
  },
39
39
  "devDependencies": {
40
- "@code-yeongyu/senpi": "2026.7.30-2"
40
+ "@code-yeongyu/senpi": "2026.7.31"
41
41
  },
42
42
  "keywords": [
43
43
  "senpi",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@earendil-works/pi-agent-core",
3
3
  "private": true,
4
- "version": "2026.7.30-2",
4
+ "version": "2026.7.31",
5
5
  "description": "General-purpose agent with transport abstraction, state management, and attachment support",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "prepublishOnly": "npm run build"
31
31
  },
32
32
  "dependencies": {
33
- "@earendil-works/pi-ai": "^2026.7.30-2",
33
+ "@earendil-works/pi-ai": "^2026.7.31",
34
34
  "diff": "9.0.0",
35
35
  "ignore": "7.0.6",
36
36
  "typebox": "1.3.8",
@@ -1 +1 @@
1
- {"schemaVersion":3,"generatedAt":"2026-07-30T13:13:04.958Z","structureHash":"b5dbf1be4a068c44378ff8d83933d7687dd578dfb665397ecffb89eece418cdb","files":{"alibaba-token-plan.json":"035d203854e829da426a10815b6584f993afe02e5a6e6ced3691af8ac7fee34f","amazon-bedrock.json":"c708d628e0cbfbe019a5a6bd8dce5f2a8935435b7d84e88e6c04c99e1da50966","ant-ling.json":"4979fe79d99ed97382d7ce40170c6132e932e77906de1eb54464c042e7d63633","anthropic.json":"507e001822a65921f50e3d355545435a6427ed079dc1ca91028a448f62d37c5c","azure-openai-responses.json":"2d13ecc23826b5be73f3628fca5f70cc2c5c15ff609b41e4acba8167cd40934b","cerebras.json":"3fd3e19b83ab4be07d27817e25e5be0ffe4158b1394f0311d6a22d9f03847728","cloudflare-ai-gateway.json":"0d51c8703213e583906369957ccf9302b4822859ad08771ac84207c2d5b9b0ca","cloudflare-workers-ai.json":"03b19d69433c843512e953390d51d4578e9b91f19098a9b14ff820c001623598","deepseek.json":"0dcc807a4e5827b488c6ceac87884ff6e735e01cf4f2ddfec9dd812e6fde041b","fireworks.json":"befd3127f292d32e62306da05469e93e10d8b0e6572dbc2df991e3f9671e12f2","github-copilot.json":"c2bd7951844e5aef1c186aec482b99954cfd02f89416de4fda94203cd6f43e11","google-vertex.json":"99d0b89ac9d8dc460ed922236abffbe88c9381af4d35046d2ad3a8f08fa2560c","google.json":"bcf8a8d59ccbb75bc6fb4a261a37ac4b7c806f40ee7313b4411178964be5fa37","groq.json":"868c90a897f75f866e09a585f6aee5cb991e40a9c3281497b5842a23de7d9add","huggingface.json":"d1952ba962c983a9f52a50323cf2475081a69b26b79467b3a9a9a06f8ab68899","kimi-coding.json":"9d73ca15313628bb8cf80c21e6466164e350d68471e2d7205b5e21bcd2c141f3","minimax-cn.json":"8ccd71ff838f4b78bb88809babb0dc32a4fcfaec2bc4f4083841000428df4f77","minimax.json":"253edd4c910a41c8bb252400ba099f3a4de0a8900ce154319288ab091b372987","mistral.json":"44531201e872713923b7544a1f75a048d31fa25292e3e1f9f896f608a52e412d","moonshotai-cn.json":"1e6146ff3477883636448c0f44222f0a52b3c4562ef8f4eecf7e941cdd59d12e","moonshotai.json":"d8d5209873058ddccd37c1f026833e2ea3f9476c3dc9628b4a940d407acc0b2e","nvidia.json":"33c498ab62940fe9ca659826c35cc922a77938a5f7edbe4443c10d9133323e87","openai-codex.json":"c3313710bc6910e6bbcb06d5867247e97ec3fa6c2af9bc780f8a3eefb03e32e1","openai.json":"7f0ec20441abeb6448162581294a5c8a7eb8d1e1ad672a9e13f601483a4f395a","opencode-go.json":"57a677764bc885c83fbbba46ad5d418baabe012a062424a0f6d8d488352102ce","opencode.json":"2cb45e5daef984d1af2c9a9e1306bf4eda6da6b642dc40e67d96e9159afb4405","openrouter.json":"2f35a87725f351c0ccbacc38f6be83743ade79dda63c7e9076a83f9982f41f92","qwen-token-plan-cn.json":"a1495ccc21835c51d438207652f948aa9ecf4a3d784e81deaf313e484bdab1ec","qwen-token-plan.json":"597fae649f549a8ffb0b6a28426ea6761b7ece41a78b6fdef49ca970ac029970","together.json":"7192caa28dc8b59bca1d62d291708903413aac63e44d7b76362294171f2df018","vercel-ai-gateway.json":"a80a831a480e42ef520706a4a900859330ca97712a69c345c8a743bd9ffa6931","xai.json":"4cbdbfbbf915246369b9bacbc6f1feeb56accdac9f3444456343f750547f2f38","xiaomi-token-plan-ams.json":"b1886b741867c90a838c377e86ad64b26ca6b0e349f1a75bc5fd4ed99df03c21","xiaomi-token-plan-cn.json":"11f459b794eddd64a9d9d102f2799c364732b7f0d562e22573f4995a5d1e1a30","xiaomi-token-plan-sgp.json":"0b9953d03b75260aba0ad604cc76d7ed26d6841448819e8c7488bf0d90948d2c","xiaomi.json":"edf39e0edd9dcae23e669635ea782e5870c0b9663d4b918b8ff9bd307cfe35f8","zai-coding-cn.json":"28fcb04ce65b4c6612a6b866902e0c832e18b685e5374578c4e2872569131d39","zai.json":"474670a0cf1109f4c296ea93d2c5c6eb8f53541dc9c0bddbb0e6cb054b971ebe"}}
1
+ {"schemaVersion":3,"generatedAt":"2026-07-31T02:01:36.696Z","structureHash":"dcd22ecec3154a7e4ed6a195d2609d8d8474c8af415f9e6e0b75bbe3971bc8d2","files":{"alibaba-token-plan.json":"035d203854e829da426a10815b6584f993afe02e5a6e6ced3691af8ac7fee34f","amazon-bedrock.json":"c708d628e0cbfbe019a5a6bd8dce5f2a8935435b7d84e88e6c04c99e1da50966","ant-ling.json":"4979fe79d99ed97382d7ce40170c6132e932e77906de1eb54464c042e7d63633","anthropic.json":"507e001822a65921f50e3d355545435a6427ed079dc1ca91028a448f62d37c5c","azure-openai-responses.json":"2d13ecc23826b5be73f3628fca5f70cc2c5c15ff609b41e4acba8167cd40934b","cerebras.json":"3fd3e19b83ab4be07d27817e25e5be0ffe4158b1394f0311d6a22d9f03847728","cloudflare-ai-gateway.json":"0d51c8703213e583906369957ccf9302b4822859ad08771ac84207c2d5b9b0ca","cloudflare-workers-ai.json":"03b19d69433c843512e953390d51d4578e9b91f19098a9b14ff820c001623598","deepseek.json":"0dcc807a4e5827b488c6ceac87884ff6e735e01cf4f2ddfec9dd812e6fde041b","fireworks.json":"befd3127f292d32e62306da05469e93e10d8b0e6572dbc2df991e3f9671e12f2","github-copilot.json":"c2bd7951844e5aef1c186aec482b99954cfd02f89416de4fda94203cd6f43e11","google-vertex.json":"99d0b89ac9d8dc460ed922236abffbe88c9381af4d35046d2ad3a8f08fa2560c","google.json":"bcf8a8d59ccbb75bc6fb4a261a37ac4b7c806f40ee7313b4411178964be5fa37","groq.json":"868c90a897f75f866e09a585f6aee5cb991e40a9c3281497b5842a23de7d9add","huggingface.json":"b978ff2ffbed09ea3a69eaa430249948256d6c0f999665bee2f403249a89bbf7","kimi-coding.json":"9d73ca15313628bb8cf80c21e6466164e350d68471e2d7205b5e21bcd2c141f3","minimax-cn.json":"8ccd71ff838f4b78bb88809babb0dc32a4fcfaec2bc4f4083841000428df4f77","minimax.json":"253edd4c910a41c8bb252400ba099f3a4de0a8900ce154319288ab091b372987","mistral.json":"44531201e872713923b7544a1f75a048d31fa25292e3e1f9f896f608a52e412d","moonshotai-cn.json":"1e6146ff3477883636448c0f44222f0a52b3c4562ef8f4eecf7e941cdd59d12e","moonshotai.json":"d8d5209873058ddccd37c1f026833e2ea3f9476c3dc9628b4a940d407acc0b2e","nvidia.json":"33c498ab62940fe9ca659826c35cc922a77938a5f7edbe4443c10d9133323e87","openai-codex.json":"c3313710bc6910e6bbcb06d5867247e97ec3fa6c2af9bc780f8a3eefb03e32e1","openai.json":"7f0ec20441abeb6448162581294a5c8a7eb8d1e1ad672a9e13f601483a4f395a","opencode-go.json":"57a677764bc885c83fbbba46ad5d418baabe012a062424a0f6d8d488352102ce","opencode.json":"2cb45e5daef984d1af2c9a9e1306bf4eda6da6b642dc40e67d96e9159afb4405","openrouter.json":"269c2f46e131000c68a2352d3f674a65cebfea85722a5086d4c654833e0ae6a1","qwen-token-plan-cn.json":"a1495ccc21835c51d438207652f948aa9ecf4a3d784e81deaf313e484bdab1ec","qwen-token-plan.json":"597fae649f549a8ffb0b6a28426ea6761b7ece41a78b6fdef49ca970ac029970","together.json":"7192caa28dc8b59bca1d62d291708903413aac63e44d7b76362294171f2df018","vercel-ai-gateway.json":"c3af9f7f9d9a4f479f16c8b1f4776f0c2acb2d1988bf17091f1b0490e7e3c3d2","xai.json":"4cbdbfbbf915246369b9bacbc6f1feeb56accdac9f3444456343f750547f2f38","xiaomi-token-plan-ams.json":"b1886b741867c90a838c377e86ad64b26ca6b0e349f1a75bc5fd4ed99df03c21","xiaomi-token-plan-cn.json":"11f459b794eddd64a9d9d102f2799c364732b7f0d562e22573f4995a5d1e1a30","xiaomi-token-plan-sgp.json":"0b9953d03b75260aba0ad604cc76d7ed26d6841448819e8c7488bf0d90948d2c","xiaomi.json":"edf39e0edd9dcae23e669635ea782e5870c0b9663d4b918b8ff9bd307cfe35f8","zai-coding-cn.json":"28fcb04ce65b4c6612a6b866902e0c832e18b685e5374578c4e2872569131d39","zai.json":"474670a0cf1109f4c296ea93d2c5c6eb8f53541dc9c0bddbb0e6cb054b971ebe"}}
@@ -1 +1 @@
1
- {"openai-completions":{"MiniMaxAI/MiniMax-M2":{"id":"MiniMaxAI/MiniMax-M2","name":"MiniMax-M2","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.3,"output":1.2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":204800,"maxTokens":128000},"MiniMaxAI/MiniMax-M2.1":{"id":"MiniMaxAI/MiniMax-M2.1","name":"MiniMax-M2.1","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.3,"output":1.2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":204800,"maxTokens":131072},"MiniMaxAI/MiniMax-M2.5":{"id":"MiniMaxAI/MiniMax-M2.5","name":"MiniMax-M2.5","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.3,"output":1.2,"cacheRead":0.03,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":204800,"maxTokens":131072},"MiniMaxAI/MiniMax-M2.7":{"id":"MiniMaxAI/MiniMax-M2.7","name":"MiniMax-M2.7","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.3,"output":1.2,"cacheRead":0.06,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":204800,"maxTokens":131072},"MiniMaxAI/MiniMax-M3":{"id":"MiniMaxAI/MiniMax-M3","name":"MiniMax-M3","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.3,"output":1.2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":524288,"maxTokens":128000},"Qwen/Qwen3-235B-A22B":{"id":"Qwen/Qwen3-235B-A22B","name":"Qwen3 235B-A22B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.2,"output":0.8,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":40960,"maxTokens":16384},"Qwen/Qwen3-235B-A22B-Thinking-2507":{"id":"Qwen/Qwen3-235B-A22B-Thinking-2507","name":"Qwen3-235B-A22B-Thinking-2507","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.3,"output":3,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":131072},"Qwen/Qwen3-32B":{"id":"Qwen/Qwen3-32B","name":"Qwen3 32B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.29,"output":0.59,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":16384},"Qwen/Qwen3-Coder-30B-A3B-Instruct":{"id":"Qwen/Qwen3-Coder-30B-A3B-Instruct","name":"Qwen3-Coder 30B-A3B Instruct","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":0.07,"output":0.26,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3-Coder-480B-A35B-Instruct":{"id":"Qwen/Qwen3-Coder-480B-A35B-Instruct","name":"Qwen3-Coder-480B-A35B-Instruct","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":2,"output":2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":66536},"Qwen/Qwen3-Coder-Next":{"id":"Qwen/Qwen3-Coder-Next","name":"Qwen3-Coder-Next","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":0.2,"output":1.5,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3-Next-80B-A3B-Instruct":{"id":"Qwen/Qwen3-Next-80B-A3B-Instruct","name":"Qwen3-Next-80B-A3B-Instruct","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":0.25,"output":1,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":66536},"Qwen/Qwen3-Next-80B-A3B-Thinking":{"id":"Qwen/Qwen3-Next-80B-A3B-Thinking","name":"Qwen3-Next-80B-A3B-Thinking","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":0.3,"output":2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":131072},"Qwen/Qwen3.5-122B-A10B":{"id":"Qwen/Qwen3.5-122B-A10B","name":"Qwen3.5 122B-A10B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.4,"output":3.2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3.5-27B":{"id":"Qwen/Qwen3.5-27B","name":"Qwen3.5 27B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.3,"output":2.4,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3.5-35B-A3B":{"id":"Qwen/Qwen3.5-35B-A3B","name":"Qwen3.5 35B-A3B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.25,"output":2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3.5-397B-A17B":{"id":"Qwen/Qwen3.5-397B-A17B","name":"Qwen3.5-397B-A17B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.6,"output":3.6,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":32768,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":null,"max":null}},"Qwen/Qwen3.5-9B":{"id":"Qwen/Qwen3.5-9B","name":"Qwen3.5 9B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.17,"output":0.25,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3.6-27B":{"id":"Qwen/Qwen3.6-27B","name":"Qwen3.6 27B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.47,"output":3.19,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3.6-35B-A3B":{"id":"Qwen/Qwen3.6-35B-A3B","name":"Qwen3.6 35B-A3B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.15,"output":0.95,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"XiaomiMiMo/MiMo-V2-Flash":{"id":"XiaomiMiMo/MiMo-V2-Flash","name":"MiMo-V2-Flash","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.1,"output":0.3,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":4096},"XiaomiMiMo/MiMo-V2.5":{"id":"XiaomiMiMo/MiMo-V2.5","name":"MiMo-V2.5","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.4,"output":2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":131072,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null}},"XiaomiMiMo/MiMo-V2.5-Pro":{"id":"XiaomiMiMo/MiMo-V2.5-Pro","name":"MiMo-V2.5-Pro","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":1,"output":3,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":1048576,"maxTokens":131072,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null}},"deepseek-ai/DeepSeek-R1":{"id":"deepseek-ai/DeepSeek-R1","name":"DeepSeek-R1","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.7,"output":2.5,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":64000,"maxTokens":32768},"deepseek-ai/DeepSeek-R1-0528":{"id":"deepseek-ai/DeepSeek-R1-0528","name":"DeepSeek-R1-0528","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":3,"output":5,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":163840,"maxTokens":163840},"deepseek-ai/DeepSeek-V3.2":{"id":"deepseek-ai/DeepSeek-V3.2","name":"DeepSeek-V3.2","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.28,"output":0.4,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":163840,"maxTokens":65536},"deepseek-ai/DeepSeek-V4-Flash":{"id":"deepseek-ai/DeepSeek-V4-Flash","name":"DeepSeek V4 Flash","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.14,"output":0.28,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":1048576,"maxTokens":384000},"deepseek-ai/DeepSeek-V4-Pro":{"id":"deepseek-ai/DeepSeek-V4-Pro","name":"DeepSeek V4 Pro","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.435,"output":0.87,"cacheRead":0.003625,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":1048576,"maxTokens":393216,"thinkingLevelMap":{"off":null,"minimal":null,"low":null,"medium":null,"high":"high","xhigh":null,"max":null}},"google/gemma-4-26B-A4B-it":{"id":"google/gemma-4-26B-A4B-it","name":"Gemma 4 26B A4B IT","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.13,"output":0.4,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":32768},"google/gemma-4-31B-it":{"id":"google/gemma-4-31B-it","name":"Gemma 4 31B IT","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.14,"output":0.4,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":32768},"meta-llama/Llama-3.3-70B-Instruct":{"id":"meta-llama/Llama-3.3-70B-Instruct","name":"Llama-3.3-70B-Instruct","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":0.59,"output":0.79,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":4096},"moonshotai/Kimi-K2-Instruct":{"id":"moonshotai/Kimi-K2-Instruct","name":"Kimi-K2-Instruct","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":1,"output":3,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":16384},"moonshotai/Kimi-K2-Instruct-0905":{"id":"moonshotai/Kimi-K2-Instruct-0905","name":"Kimi-K2-Instruct-0905","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":1,"output":3,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":16384},"moonshotai/Kimi-K2-Thinking":{"id":"moonshotai/Kimi-K2-Thinking","name":"Kimi-K2-Thinking","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.6,"output":2.5,"cacheRead":0.15,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":262144},"moonshotai/Kimi-K2.5":{"id":"moonshotai/Kimi-K2.5","name":"Kimi-K2.5","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.6,"output":3,"cacheRead":0.1,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":262144},"moonshotai/Kimi-K2.6":{"id":"moonshotai/Kimi-K2.6","name":"Kimi-K2.6","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.95,"output":4,"cacheRead":0.16,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":262144},"moonshotai/Kimi-K2.7-Code":{"id":"moonshotai/Kimi-K2.7-Code","name":"Kimi K2.7 Code","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.95,"output":4,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":262144},"moonshotai/Kimi-K3":{"id":"moonshotai/Kimi-K3","name":"Kimi K3","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":1000000,"maxTokens":131072,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":"max"}},"openai/gpt-oss-120b":{"id":"openai/gpt-oss-120b","name":"GPT OSS 120B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.25,"output":0.69,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":32768,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":null,"max":null}},"openai/gpt-oss-20b":{"id":"openai/gpt-oss-20b","name":"GPT OSS 20B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.1,"output":0.5,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":32768,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":null,"max":null}},"stepfun-ai/Step-3.5-Flash":{"id":"stepfun-ai/Step-3.5-Flash","name":"Step 3.5 Flash","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.1,"output":0.3,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":256000},"stepfun-ai/Step-3.7-Flash":{"id":"stepfun-ai/Step-3.7-Flash","name":"Step 3.7 Flash","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.2,"output":1.15,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":256000,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":null,"max":null}},"zai-org/GLM-4.5":{"id":"zai-org/GLM-4.5","name":"GLM-4.5","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.6,"output":2.2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":98304},"zai-org/GLM-4.5-Air":{"id":"zai-org/GLM-4.5-Air","name":"GLM-4.5-Air","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.13,"output":0.85,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":98304},"zai-org/GLM-4.5V":{"id":"zai-org/GLM-4.5V","name":"GLM-4.5V","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.6,"output":1.8,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":65536,"maxTokens":16384},"zai-org/GLM-4.6":{"id":"zai-org/GLM-4.6","name":"GLM-4.6","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.55,"output":2.2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":204800,"maxTokens":131072},"zai-org/GLM-4.7":{"id":"zai-org/GLM-4.7","name":"GLM-4.7","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.6,"output":2.2,"cacheRead":0.11,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":204800,"maxTokens":131072},"zai-org/GLM-4.7-Flash":{"id":"zai-org/GLM-4.7-Flash","name":"GLM-4.7-Flash","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":200000,"maxTokens":128000},"zai-org/GLM-5":{"id":"zai-org/GLM-5","name":"GLM-5","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":1,"output":3.2,"cacheRead":0.2,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":202752,"maxTokens":131072},"zai-org/GLM-5.1":{"id":"zai-org/GLM-5.1","name":"GLM-5.1","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":1,"output":3.2,"cacheRead":0.2,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":202752,"maxTokens":131072},"zai-org/GLM-5.2":{"id":"zai-org/GLM-5.2","name":"GLM-5.2","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":1.4,"output":4.4,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":131072}}}
1
+ {"openai-completions":{"MiniMaxAI/MiniMax-M2":{"id":"MiniMaxAI/MiniMax-M2","name":"MiniMax-M2","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.3,"output":1.2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":204800,"maxTokens":128000},"MiniMaxAI/MiniMax-M2.1":{"id":"MiniMaxAI/MiniMax-M2.1","name":"MiniMax-M2.1","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.3,"output":1.2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":204800,"maxTokens":131072},"MiniMaxAI/MiniMax-M2.5":{"id":"MiniMaxAI/MiniMax-M2.5","name":"MiniMax-M2.5","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.3,"output":1.2,"cacheRead":0.03,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":204800,"maxTokens":131072},"MiniMaxAI/MiniMax-M2.7":{"id":"MiniMaxAI/MiniMax-M2.7","name":"MiniMax-M2.7","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.3,"output":1.2,"cacheRead":0.06,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":204800,"maxTokens":131072},"MiniMaxAI/MiniMax-M3":{"id":"MiniMaxAI/MiniMax-M3","name":"MiniMax-M3","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.3,"output":1.2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":524288,"maxTokens":128000},"Qwen/Qwen3-235B-A22B":{"id":"Qwen/Qwen3-235B-A22B","name":"Qwen3 235B-A22B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.2,"output":0.8,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":40960,"maxTokens":16384},"Qwen/Qwen3-235B-A22B-Thinking-2507":{"id":"Qwen/Qwen3-235B-A22B-Thinking-2507","name":"Qwen3-235B-A22B-Thinking-2507","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.3,"output":3,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":131072},"Qwen/Qwen3-32B":{"id":"Qwen/Qwen3-32B","name":"Qwen3 32B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.29,"output":0.59,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":16384},"Qwen/Qwen3-Coder-30B-A3B-Instruct":{"id":"Qwen/Qwen3-Coder-30B-A3B-Instruct","name":"Qwen3-Coder 30B-A3B Instruct","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":0.07,"output":0.26,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3-Coder-480B-A35B-Instruct":{"id":"Qwen/Qwen3-Coder-480B-A35B-Instruct","name":"Qwen3-Coder-480B-A35B-Instruct","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":2,"output":2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":66536},"Qwen/Qwen3-Coder-Next":{"id":"Qwen/Qwen3-Coder-Next","name":"Qwen3-Coder-Next","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":0.2,"output":1.5,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3-Next-80B-A3B-Instruct":{"id":"Qwen/Qwen3-Next-80B-A3B-Instruct","name":"Qwen3-Next-80B-A3B-Instruct","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":0.25,"output":1,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":66536},"Qwen/Qwen3-Next-80B-A3B-Thinking":{"id":"Qwen/Qwen3-Next-80B-A3B-Thinking","name":"Qwen3-Next-80B-A3B-Thinking","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":0.3,"output":2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":131072},"Qwen/Qwen3.5-122B-A10B":{"id":"Qwen/Qwen3.5-122B-A10B","name":"Qwen3.5 122B-A10B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.4,"output":3.2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3.5-27B":{"id":"Qwen/Qwen3.5-27B","name":"Qwen3.5 27B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.3,"output":2.4,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3.5-35B-A3B":{"id":"Qwen/Qwen3.5-35B-A3B","name":"Qwen3.5 35B-A3B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.25,"output":2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3.5-397B-A17B":{"id":"Qwen/Qwen3.5-397B-A17B","name":"Qwen3.5-397B-A17B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.6,"output":3.6,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":32768,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":null,"max":null}},"Qwen/Qwen3.5-9B":{"id":"Qwen/Qwen3.5-9B","name":"Qwen3.5 9B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.17,"output":0.25,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3.6-27B":{"id":"Qwen/Qwen3.6-27B","name":"Qwen3.6 27B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.47,"output":3.19,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"Qwen/Qwen3.6-35B-A3B":{"id":"Qwen/Qwen3.6-35B-A3B","name":"Qwen3.6 35B-A3B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.15,"output":0.95,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":65536},"XiaomiMiMo/MiMo-V2-Flash":{"id":"XiaomiMiMo/MiMo-V2-Flash","name":"MiMo-V2-Flash","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.1,"output":0.3,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":4096},"XiaomiMiMo/MiMo-V2.5":{"id":"XiaomiMiMo/MiMo-V2.5","name":"MiMo-V2.5","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.4,"output":2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":131072,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null}},"XiaomiMiMo/MiMo-V2.5-Pro":{"id":"XiaomiMiMo/MiMo-V2.5-Pro","name":"MiMo-V2.5-Pro","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":1,"output":3,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":1048576,"maxTokens":131072,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null}},"deepseek-ai/DeepSeek-R1":{"id":"deepseek-ai/DeepSeek-R1","name":"DeepSeek-R1","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.7,"output":2.5,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":64000,"maxTokens":32768},"deepseek-ai/DeepSeek-R1-0528":{"id":"deepseek-ai/DeepSeek-R1-0528","name":"DeepSeek-R1-0528","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":3,"output":5,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":163840,"maxTokens":163840},"deepseek-ai/DeepSeek-V3.2":{"id":"deepseek-ai/DeepSeek-V3.2","name":"DeepSeek-V3.2","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.28,"output":0.4,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":163840,"maxTokens":65536},"deepseek-ai/DeepSeek-V4-Flash":{"id":"deepseek-ai/DeepSeek-V4-Flash","name":"DeepSeek V4 Flash","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.14,"output":0.28,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":1048576,"maxTokens":384000},"deepseek-ai/DeepSeek-V4-Pro":{"id":"deepseek-ai/DeepSeek-V4-Pro","name":"DeepSeek V4 Pro","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.435,"output":0.87,"cacheRead":0.003625,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":1048576,"maxTokens":393216,"thinkingLevelMap":{"off":null,"minimal":null,"low":null,"medium":null,"high":"high","xhigh":null,"max":null}},"google/gemma-4-26B-A4B-it":{"id":"google/gemma-4-26B-A4B-it","name":"Gemma 4 26B A4B IT","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.13,"output":0.4,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":32768},"google/gemma-4-31B-it":{"id":"google/gemma-4-31B-it","name":"Gemma 4 31B IT","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.14,"output":0.4,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":32768},"meta-llama/Llama-3.3-70B-Instruct":{"id":"meta-llama/Llama-3.3-70B-Instruct","name":"Llama-3.3-70B-Instruct","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":0.59,"output":0.79,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":4096},"moonshotai/Kimi-K2-Instruct":{"id":"moonshotai/Kimi-K2-Instruct","name":"Kimi-K2-Instruct","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":1,"output":3,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":16384},"moonshotai/Kimi-K2-Instruct-0905":{"id":"moonshotai/Kimi-K2-Instruct-0905","name":"Kimi-K2-Instruct-0905","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":false,"input":["text"],"cost":{"input":1,"output":3,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":16384},"moonshotai/Kimi-K2-Thinking":{"id":"moonshotai/Kimi-K2-Thinking","name":"Kimi-K2-Thinking","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.6,"output":2.5,"cacheRead":0.15,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":262144},"moonshotai/Kimi-K2.5":{"id":"moonshotai/Kimi-K2.5","name":"Kimi-K2.5","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.6,"output":3,"cacheRead":0.1,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":262144},"moonshotai/Kimi-K2.6":{"id":"moonshotai/Kimi-K2.6","name":"Kimi-K2.6","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.95,"output":4,"cacheRead":0.16,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":262144},"moonshotai/Kimi-K2.7-Code":{"id":"moonshotai/Kimi-K2.7-Code","name":"Kimi K2.7 Code","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.95,"output":4,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":262144},"moonshotai/Kimi-K3":{"id":"moonshotai/Kimi-K3","name":"Kimi K3","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":1000000,"maxTokens":131072,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":"max"}},"openai/gpt-oss-120b":{"id":"openai/gpt-oss-120b","name":"GPT OSS 120B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.25,"output":0.69,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":32768,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":null,"max":null}},"openai/gpt-oss-20b":{"id":"openai/gpt-oss-20b","name":"GPT OSS 20B","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.1,"output":0.5,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":32768,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":null,"max":null}},"stepfun-ai/Step-3.5-Flash":{"id":"stepfun-ai/Step-3.5-Flash","name":"Step 3.5 Flash","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.1,"output":0.3,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":256000},"stepfun-ai/Step-3.7-Flash":{"id":"stepfun-ai/Step-3.7-Flash","name":"Step 3.7 Flash","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.2,"output":1.15,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":256000,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":null,"max":null}},"tencent/Hy3":{"id":"tencent/Hy3","name":"Hy3","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.14,"output":0.58,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":64000,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":null}},"thinkingmachines/Inkling":{"id":"thinkingmachines/Inkling","name":"Inkling","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":1,"output":4.05,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":1048576,"maxTokens":1048576,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":null,"max":null}},"zai-org/GLM-4.5":{"id":"zai-org/GLM-4.5","name":"GLM-4.5","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.6,"output":2.2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":98304},"zai-org/GLM-4.5-Air":{"id":"zai-org/GLM-4.5-Air","name":"GLM-4.5-Air","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.13,"output":0.85,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":131072,"maxTokens":98304},"zai-org/GLM-4.5V":{"id":"zai-org/GLM-4.5V","name":"GLM-4.5V","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text","image"],"cost":{"input":0.6,"output":1.8,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":65536,"maxTokens":16384},"zai-org/GLM-4.6":{"id":"zai-org/GLM-4.6","name":"GLM-4.6","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.55,"output":2.2,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":204800,"maxTokens":131072},"zai-org/GLM-4.7":{"id":"zai-org/GLM-4.7","name":"GLM-4.7","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0.6,"output":2.2,"cacheRead":0.11,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":204800,"maxTokens":131072},"zai-org/GLM-4.7-Flash":{"id":"zai-org/GLM-4.7-Flash","name":"GLM-4.7-Flash","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":200000,"maxTokens":128000},"zai-org/GLM-5":{"id":"zai-org/GLM-5","name":"GLM-5","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":1,"output":3.2,"cacheRead":0.2,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":202752,"maxTokens":131072},"zai-org/GLM-5.1":{"id":"zai-org/GLM-5.1","name":"GLM-5.1","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":1,"output":3.2,"cacheRead":0.2,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":202752,"maxTokens":131072},"zai-org/GLM-5.2":{"id":"zai-org/GLM-5.2","name":"GLM-5.2","api":"openai-completions","provider":"huggingface","baseUrl":"https://router.huggingface.co/v1","reasoning":true,"input":["text"],"cost":{"input":1.4,"output":4.4,"cacheRead":0,"cacheWrite":0},"compat":{"supportsDeveloperRole":false},"contextWindow":262144,"maxTokens":131072}}}