pi2dsh 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/{all-Rt4K68QA.mjs → all-DSpxKvHa.mjs} +10 -10
  2. package/dist/{all-Rt4K68QA.mjs.map → all-DSpxKvHa.mjs.map} +1 -1
  3. package/dist/{anthropic-messages-Beym0_aC.mjs → anthropic-messages-BL9N1Idv.mjs} +3 -3
  4. package/dist/{anthropic-messages-Beym0_aC.mjs.map → anthropic-messages-BL9N1Idv.mjs.map} +1 -1
  5. package/dist/{azure-openai-responses-cHqZTgLD.mjs → azure-openai-responses-A67VbaZ1.mjs} +3 -3
  6. package/dist/{azure-openai-responses-cHqZTgLD.mjs.map → azure-openai-responses-A67VbaZ1.mjs.map} +1 -1
  7. package/dist/cli.mjs +1 -1
  8. package/dist/compat/pi-ai.d.mts +3 -38
  9. package/dist/compat/pi-ai.d.mts.map +1 -1
  10. package/dist/compat/pi-ai.mjs +3 -3
  11. package/dist/compat/pi-coding-agent.d.mts +71 -32
  12. package/dist/compat/pi-coding-agent.d.mts.map +1 -1
  13. package/dist/compat/pi-coding-agent.mjs +2 -2
  14. package/dist/credentials-oauth.mjs +2 -2
  15. package/dist/{dist-QBBA-dL_.mjs → dist-BYA74yh_.mjs} +2 -2
  16. package/dist/{dist-QBBA-dL_.mjs.map → dist-BYA74yh_.mjs.map} +1 -1
  17. package/dist/dist-DeonWo7m.mjs +1089 -0
  18. package/dist/dist-DeonWo7m.mjs.map +1 -0
  19. package/dist/{google-generative-ai-B7OZs5lu.mjs → google-generative-ai-DT5S8D8y.mjs} +2 -2
  20. package/dist/{google-generative-ai-B7OZs5lu.mjs.map → google-generative-ai-DT5S8D8y.mjs.map} +1 -1
  21. package/dist/{google-shared-CRsAUItF.mjs → google-shared-DYP_9cnK.mjs} +4 -4
  22. package/dist/{google-shared-CRsAUItF.mjs.map → google-shared-DYP_9cnK.mjs.map} +1 -1
  23. package/dist/{google-vertex-DmdaHQtB.mjs → google-vertex-Dpq7O7Be.mjs} +3 -3
  24. package/dist/{google-vertex-DmdaHQtB.mjs.map → google-vertex-Dpq7O7Be.mjs.map} +1 -1
  25. package/dist/host.mjs +1 -1
  26. package/dist/index.d.mts.map +1 -1
  27. package/dist/index.mjs +1 -1
  28. package/dist/{json-parse-CFyFZSLJ.mjs → json-parse-Dz5sKMTv.mjs} +2 -2
  29. package/dist/{json-parse-CFyFZSLJ.mjs.map → json-parse-Dz5sKMTv.mjs.map} +1 -1
  30. package/dist/{mcp-config-D2B3kv-Z.mjs → mcp-config-B3h5jTBb.mjs} +9 -8
  31. package/dist/mcp-config-B3h5jTBb.mjs.map +1 -0
  32. package/dist/{mistral-conversations-HHZCcFv_.mjs → mistral-conversations-BsxbCCWx.mjs} +4 -4
  33. package/dist/{mistral-conversations-HHZCcFv_.mjs.map → mistral-conversations-BsxbCCWx.mjs.map} +1 -1
  34. package/dist/{multipart-parser-CIa5BbwO.mjs → multipart-parser-woKCuALW.mjs} +3 -3
  35. package/dist/{multipart-parser-CIa5BbwO.mjs.map → multipart-parser-woKCuALW.mjs.map} +1 -1
  36. package/dist/{openai-codex-responses-vmovNu-q.mjs → openai-codex-responses-C7vviVT2.mjs} +3 -3
  37. package/dist/{openai-codex-responses-vmovNu-q.mjs.map → openai-codex-responses-C7vviVT2.mjs.map} +1 -1
  38. package/dist/{openai-completions-fXHhRolF.mjs → openai-completions-By8QNX1P.mjs} +3 -3
  39. package/dist/{openai-completions-fXHhRolF.mjs.map → openai-completions-By8QNX1P.mjs.map} +1 -1
  40. package/dist/{openai-responses-DKdCYf3h.mjs → openai-responses-DboJUcFN.mjs} +3 -3
  41. package/dist/{openai-responses-DKdCYf3h.mjs.map → openai-responses-DboJUcFN.mjs.map} +1 -1
  42. package/dist/{openai-responses-shared-D0Jq7yVP.mjs → openai-responses-shared-BDzn7nJY.mjs} +2 -2
  43. package/dist/{openai-responses-shared-D0Jq7yVP.mjs.map → openai-responses-shared-BDzn7nJY.mjs.map} +1 -1
  44. package/dist/{otel-BQSQRBLF.mjs → otel-PimLMoiV.mjs} +3 -3
  45. package/dist/{otel-BQSQRBLF.mjs.map → otel-PimLMoiV.mjs.map} +1 -1
  46. package/dist/{pi-ai-DhYGgq4Y.mjs → pi-ai-B_88Wb0r.mjs} +49 -6
  47. package/dist/{pi-ai-DhYGgq4Y.mjs.map → pi-ai-B_88Wb0r.mjs.map} +1 -1
  48. package/dist/{pi-coding-agent-fPHwKP4d.mjs → pi-coding-agent-COMX0KHL.mjs} +109 -34
  49. package/dist/pi-coding-agent-COMX0KHL.mjs.map +1 -0
  50. package/dist/{pi-messages-CV-Ts8An.mjs → pi-messages-B-7Xo_I0.mjs} +3 -3
  51. package/dist/{pi-messages-CV-Ts8An.mjs.map → pi-messages-B-7Xo_I0.mjs.map} +1 -1
  52. package/dist/pi-types-KazmR2O5.d.mts +62 -0
  53. package/dist/pi-types-KazmR2O5.d.mts.map +1 -0
  54. package/dist/pi-uuid-Db8ShZsK.mjs +47 -0
  55. package/dist/pi-uuid-Db8ShZsK.mjs.map +1 -0
  56. package/dist/{provider-env-C72pF4vP.mjs → provider-env-D-cCRWzv.mjs} +2 -2
  57. package/dist/{provider-env-C72pF4vP.mjs.map → provider-env-D-cCRWzv.mjs.map} +1 -1
  58. package/dist/{runtime-B9R7bDWT.mjs → runtime-B7mEIRf-.mjs} +1183 -52
  59. package/dist/runtime-B7mEIRf-.mjs.map +1 -0
  60. package/dist/runtime.d.mts.map +1 -1
  61. package/dist/runtime.mjs +1 -1
  62. package/dist/{src-C3WBfOks.mjs → src-BEl3QrGL.mjs} +3 -3
  63. package/dist/{src-C3WBfOks.mjs.map → src-BEl3QrGL.mjs.map} +1 -1
  64. package/package.json +2 -2
  65. package/dist/build-BG7p2Lbr.mjs +0 -4416
  66. package/dist/build-BG7p2Lbr.mjs.map +0 -1
  67. package/dist/dist-IQKOgQyt.mjs +0 -10035
  68. package/dist/dist-IQKOgQyt.mjs.map +0 -1
  69. package/dist/mcp-config-D2B3kv-Z.mjs.map +0 -1
  70. package/dist/pi-coding-agent-fPHwKP4d.mjs.map +0 -1
  71. package/dist/pi-types-BLt46jaf.d.mts +0 -2494
  72. package/dist/pi-types-BLt46jaf.d.mts.map +0 -1
  73. package/dist/rolldown-runtime-CTfmNlz1.mjs +0 -44
  74. package/dist/runtime-B9R7bDWT.mjs.map +0 -1
@@ -2,11 +2,11 @@
2
2
  import { a as AssistantMessageEventStream } from "./diagnostics-CJye1UFh.mjs";
3
3
  import { a as calculateCost, o as clampThinkingLevel } from "./images-models-DJtHo9Rp.mjs";
4
4
  import { n as providerHeadersToRecord } from "./headers-CPzZhJQn.mjs";
5
- import { t as getProviderEnvValue } from "./provider-env-C72pF4vP.mjs";
5
+ import { t as getProviderEnvValue } from "./provider-env-D-cCRWzv.mjs";
6
6
  import { t as sanitizeSurrogates } from "./sanitize-unicode-wLA11KvZ.mjs";
7
7
  import { i as buildBaseOptions } from "./transform-messages-DGq9mvhA.mjs";
8
8
  import { n as normalizeProviderError, t as formatProviderError } from "./error-body-DKA3lknR.mjs";
9
- import { a as resolveGoogleFunctionCallingMode, c as supportsGoogleStrictToolSampling, d as ThinkingLevel, i as mapStopReason, l as GoogleGenAI, n as convertTools, o as retainThoughtSignature, r as isThinkingPart, s as retryGoogleRequest, t as convertMessages, u as ResourceScope } from "./google-shared-CRsAUItF.mjs";
9
+ import { a as resolveGoogleFunctionCallingMode, c as supportsGoogleStrictToolSampling, d as ThinkingLevel, i as mapStopReason, l as GoogleGenAI, n as convertTools, o as retainThoughtSignature, r as isThinkingPart, s as retryGoogleRequest, t as convertMessages, u as ResourceScope } from "./google-shared-DYP_9cnK.mjs";
10
10
  //#region node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js
11
11
  const API_VERSION = "v1";
12
12
  const GCP_VERTEX_CREDENTIALS_MARKER = "gcp-vertex-credentials";
@@ -399,4 +399,4 @@ function getGoogleBudget(model, effort, customBudgets) {
399
399
  //#endregion
400
400
  export { stream, streamSimple };
401
401
 
402
- //# sourceMappingURL=google-vertex-DmdaHQtB.mjs.map
402
+ //# sourceMappingURL=google-vertex-Dpq7O7Be.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"google-vertex-DmdaHQtB.mjs","names":[],"sources":["../node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js"],"sourcesContent":["import { GoogleGenAI, ResourceScope, ThinkingLevel, } from \"@google/genai\";\nimport { calculateCost, clampThinkingLevel } from \"../models.js\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.js\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.js\";\nimport { providerHeadersToRecord } from \"../utils/headers.js\";\nimport { getProviderEnvValue } from \"../utils/provider-env.js\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.js\";\nimport { convertMessages, convertTools, isThinkingPart, mapStopReason, resolveGoogleFunctionCallingMode, retainThoughtSignature, retryGoogleRequest, supportsGoogleStrictToolSampling, } from \"./google-shared.js\";\nimport { buildBaseOptions } from \"./simple-options.js\";\nconst API_VERSION = \"v1\";\nconst GCP_VERTEX_CREDENTIALS_MARKER = \"gcp-vertex-credentials\";\nconst THINKING_LEVEL_MAP = {\n THINKING_LEVEL_UNSPECIFIED: ThinkingLevel.THINKING_LEVEL_UNSPECIFIED,\n MINIMAL: ThinkingLevel.MINIMAL,\n LOW: ThinkingLevel.LOW,\n MEDIUM: ThinkingLevel.MEDIUM,\n HIGH: ThinkingLevel.HIGH,\n};\n// Counter for generating unique tool call IDs\nlet toolCallCounter = 0;\nexport const stream = (model, context, options) => {\n const stream = new AssistantMessageEventStream();\n (async () => {\n const output = {\n role: \"assistant\",\n content: [],\n api: \"google-vertex\",\n provider: model.provider,\n model: model.id,\n usage: {\n input: 0,\n output: 0,\n cacheRead: 0,\n cacheWrite: 0,\n totalTokens: 0,\n cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n },\n stopReason: \"pending\",\n timestamp: Date.now(),\n };\n try {\n if (options?.fetch && options.fetch !== globalThis.fetch) {\n throw new Error(\"Custom fetch is not supported by the Google Vertex adapter\");\n }\n const apiKey = resolveApiKey(options);\n // Create the client using either a Vertex API key, if provided, or ADC with project and location\n const client = apiKey\n ? createClientWithApiKey(model, apiKey, options?.headers)\n : createClient(model, resolveProject(options), resolveLocation(options), options?.headers, options?.env);\n let params = buildParams(model, context, options);\n const nextParams = await options?.onPayload?.(params, model);\n if (nextParams !== undefined) {\n params = nextParams;\n }\n const googleStream = await retryGoogleRequest(() => client.models.generateContentStream(params), options);\n stream.push({ type: \"start\", partial: output });\n let currentBlock = null;\n const blocks = output.content;\n const blockIndex = () => blocks.length - 1;\n for await (const chunk of googleStream) {\n // Vertex uses the same @google/genai GenerateContentResponse type as Gemini.\n // responseId is documented there as an output-only identifier for each response.\n output.responseId ||= chunk.responseId;\n const candidate = chunk.candidates?.[0];\n if (candidate?.content?.parts) {\n for (const part of candidate.content.parts) {\n if (part.text !== undefined) {\n const isThinking = isThinkingPart(part);\n if (!currentBlock ||\n (isThinking && currentBlock.type !== \"thinking\") ||\n (!isThinking && currentBlock.type !== \"text\")) {\n if (currentBlock) {\n if (currentBlock.type === \"text\") {\n stream.push({\n type: \"text_end\",\n contentIndex: blocks.length - 1,\n content: currentBlock.text,\n partial: output,\n });\n }\n else {\n stream.push({\n type: \"thinking_end\",\n contentIndex: blockIndex(),\n content: currentBlock.thinking,\n partial: output,\n });\n }\n }\n if (isThinking) {\n currentBlock = { type: \"thinking\", thinking: \"\", thinkingSignature: undefined };\n output.content.push(currentBlock);\n stream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n }\n else {\n currentBlock = { type: \"text\", text: \"\" };\n output.content.push(currentBlock);\n stream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n }\n }\n if (currentBlock.type === \"thinking\") {\n currentBlock.thinking += part.text;\n currentBlock.thinkingSignature = retainThoughtSignature(currentBlock.thinkingSignature, part.thoughtSignature);\n stream.push({\n type: \"thinking_delta\",\n contentIndex: blockIndex(),\n delta: part.text,\n partial: output,\n });\n }\n else {\n currentBlock.text += part.text;\n currentBlock.textSignature = retainThoughtSignature(currentBlock.textSignature, part.thoughtSignature);\n stream.push({\n type: \"text_delta\",\n contentIndex: blockIndex(),\n delta: part.text,\n partial: output,\n });\n }\n }\n if (part.functionCall) {\n if (currentBlock) {\n if (currentBlock.type === \"text\") {\n stream.push({\n type: \"text_end\",\n contentIndex: blockIndex(),\n content: currentBlock.text,\n partial: output,\n });\n }\n else {\n stream.push({\n type: \"thinking_end\",\n contentIndex: blockIndex(),\n content: currentBlock.thinking,\n partial: output,\n });\n }\n currentBlock = null;\n }\n const providedId = part.functionCall.id;\n const needsNewId = !providedId || output.content.some((b) => b.type === \"toolCall\" && b.id === providedId);\n const toolCallId = needsNewId\n ? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`\n : providedId;\n const toolCall = {\n type: \"toolCall\",\n id: toolCallId,\n name: part.functionCall.name || \"\",\n arguments: part.functionCall.args ?? {},\n ...(part.thoughtSignature && { thoughtSignature: part.thoughtSignature }),\n };\n output.content.push(toolCall);\n stream.push({ type: \"toolcall_start\", contentIndex: blockIndex(), partial: output });\n stream.push({\n type: \"toolcall_delta\",\n contentIndex: blockIndex(),\n delta: JSON.stringify(toolCall.arguments),\n partial: output,\n });\n stream.push({ type: \"toolcall_end\", contentIndex: blockIndex(), toolCall, partial: output });\n }\n }\n }\n if (candidate?.finishReason) {\n output.rawStopReason = candidate.finishReason;\n output.stopReason = mapStopReason(candidate.finishReason);\n if (output.content.some((b) => b.type === \"toolCall\")) {\n output.stopReason = \"toolUse\";\n }\n }\n if (chunk.usageMetadata) {\n output.usage = {\n input: (chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),\n output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),\n cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,\n cacheWrite: 0,\n reasoning: chunk.usageMetadata.thoughtsTokenCount || 0,\n totalTokens: chunk.usageMetadata.totalTokenCount || 0,\n cost: {\n input: 0,\n output: 0,\n cacheRead: 0,\n cacheWrite: 0,\n total: 0,\n },\n };\n calculateCost(model, output.usage);\n }\n }\n if (currentBlock) {\n if (currentBlock.type === \"text\") {\n stream.push({\n type: \"text_end\",\n contentIndex: blockIndex(),\n content: currentBlock.text,\n partial: output,\n });\n }\n else {\n stream.push({\n type: \"thinking_end\",\n contentIndex: blockIndex(),\n content: currentBlock.thinking,\n partial: output,\n });\n }\n }\n if (options?.signal?.aborted) {\n throw new Error(\"Request was aborted\");\n }\n if (output.stopReason === \"pending\") {\n throw new Error(\"Google Vertex stream ended without a finish reason\");\n }\n if (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n const errorMessage = output.rawStopReason\n ? `Provider stopped with: ${output.rawStopReason}`\n : \"An unknown error occurred\";\n throw new Error(errorMessage);\n }\n stream.push({ type: \"done\", reason: output.stopReason, message: output });\n stream.end();\n }\n catch (error) {\n // Remove internal index property used during streaming\n for (const block of output.content) {\n if (\"index\" in block) {\n delete block.index;\n }\n }\n output.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n output.errorMessage = formatProviderError(normalizeProviderError(error));\n stream.push({ type: \"error\", reason: output.stopReason, error: output });\n stream.end();\n }\n })();\n return stream;\n};\nexport const streamSimple = (model, context, options) => {\n const base = buildBaseOptions(model, context, options, undefined);\n if (!options?.reasoning) {\n return stream(model, context, {\n ...base,\n thinking: { enabled: false },\n });\n }\n const clampedReasoning = clampThinkingLevel(model, options.reasoning);\n const effort = (clampedReasoning === \"off\" ? \"high\" : clampedReasoning);\n const geminiModel = model;\n if (isGemini3ProModel(geminiModel) || isGemini3FlashModel(geminiModel)) {\n return stream(model, context, {\n ...base,\n thinking: {\n enabled: true,\n level: getGemini3ThinkingLevel(effort, geminiModel),\n },\n });\n }\n return stream(model, context, {\n ...base,\n thinking: {\n enabled: true,\n budgetTokens: getGoogleBudget(geminiModel, effort, options.thinkingBudgets),\n },\n });\n};\nfunction createClient(model, project, location, optionsHeaders, env) {\n const googleAuthOptions = buildGoogleAuthOptions(env);\n return new GoogleGenAI({\n vertexai: true,\n project,\n location,\n apiVersion: API_VERSION,\n ...(googleAuthOptions ? { googleAuthOptions } : {}),\n httpOptions: buildHttpOptions(model, optionsHeaders),\n });\n}\nfunction createClientWithApiKey(model, apiKey, optionsHeaders) {\n return new GoogleGenAI({\n vertexai: true,\n apiKey,\n apiVersion: API_VERSION,\n httpOptions: buildHttpOptions(model, optionsHeaders),\n });\n}\nfunction buildHttpOptions(model, optionsHeaders) {\n const httpOptions = {};\n const baseUrl = resolveCustomBaseUrl(model.baseUrl);\n if (baseUrl) {\n httpOptions.baseUrl = baseUrl;\n httpOptions.baseUrlResourceScope = ResourceScope.COLLECTION;\n if (baseUrlIncludesApiVersion(baseUrl)) {\n httpOptions.apiVersion = \"\";\n }\n }\n const headers = providerHeadersToRecord({ ...model.headers, ...optionsHeaders });\n if (headers) {\n httpOptions.headers = headers;\n }\n return Object.keys(httpOptions).length > 0 ? httpOptions : undefined;\n}\nfunction resolveCustomBaseUrl(baseUrl) {\n const trimmed = baseUrl.trim();\n if (!trimmed || trimmed.includes(\"{location}\")) {\n return undefined;\n }\n return trimmed;\n}\nfunction baseUrlIncludesApiVersion(baseUrl) {\n try {\n const url = new URL(baseUrl);\n return url.pathname.split(\"/\").some((part) => /^v\\d+(?:beta\\d*)?$/.test(part));\n }\n catch {\n return /(?:^|\\/)v\\d+(?:beta\\d*)?(?:\\/|$)/.test(baseUrl);\n }\n}\nfunction buildGoogleAuthOptions(env) {\n const keyFilename = getProviderEnvValue(\"GOOGLE_APPLICATION_CREDENTIALS\", env);\n return keyFilename ? { keyFilename } : undefined;\n}\nfunction resolveApiKey(options) {\n const apiKey = options?.apiKey?.trim();\n if (!apiKey || apiKey === GCP_VERTEX_CREDENTIALS_MARKER || isPlaceholderApiKey(apiKey)) {\n return undefined;\n }\n return apiKey;\n}\nfunction isPlaceholderApiKey(apiKey) {\n return /^<[^>]+>$/.test(apiKey);\n}\nfunction resolveProject(options) {\n const project = options?.project ||\n getProviderEnvValue(\"GOOGLE_CLOUD_PROJECT\", options?.env) ||\n getProviderEnvValue(\"GCLOUD_PROJECT\", options?.env);\n if (!project) {\n throw new Error(\"Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.\");\n }\n return project;\n}\nfunction resolveLocation(options) {\n const location = options?.location || getProviderEnvValue(\"GOOGLE_CLOUD_LOCATION\", options?.env);\n if (!location) {\n throw new Error(\"Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.\");\n }\n return location;\n}\nfunction buildParams(model, context, options = {}) {\n const contents = convertMessages(model, context);\n const generationConfig = {};\n if (options.temperature !== undefined) {\n generationConfig.temperature = options.temperature;\n }\n if (options.maxTokens !== undefined) {\n generationConfig.maxOutputTokens = options.maxTokens;\n }\n const functionCallingMode = context.tools?.length\n ? resolveGoogleFunctionCallingMode(context.tools, options.toolChoice, supportsGoogleStrictToolSampling(model.id))\n : undefined;\n const config = {\n ...(Object.keys(generationConfig).length > 0 && generationConfig),\n ...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),\n ...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }),\n ...(functionCallingMode !== undefined && {\n toolConfig: { functionCallingConfig: { mode: functionCallingMode } },\n }),\n };\n if (options.thinking?.enabled && model.reasoning) {\n const thinkingConfig = { includeThoughts: true };\n if (options.thinking.level !== undefined) {\n thinkingConfig.thinkingLevel = THINKING_LEVEL_MAP[options.thinking.level];\n }\n else if (options.thinking.budgetTokens !== undefined) {\n thinkingConfig.thinkingBudget = options.thinking.budgetTokens;\n }\n config.thinkingConfig = thinkingConfig;\n }\n else if (model.reasoning && options.thinking && !options.thinking.enabled) {\n config.thinkingConfig = getDisabledThinkingConfig(model);\n }\n if (options.signal) {\n if (options.signal.aborted) {\n throw new Error(\"Request aborted\");\n }\n config.abortSignal = options.signal;\n }\n const params = {\n model: model.id,\n contents,\n config,\n };\n return params;\n}\nfunction isGemini3ProModel(model) {\n return /gemini-3(?:\\.\\d+)?-pro/.test(model.id.toLowerCase());\n}\nfunction isGemini3FlashModel(model) {\n const id = model.id.toLowerCase();\n return /gemini-3(?:\\.\\d+)?-flash/.test(id) || id === \"gemini-flash-latest\" || id === \"gemini-flash-lite-latest\";\n}\nfunction getDisabledThinkingConfig(model) {\n // Google docs: Gemini 3.1 Pro cannot disable thinking, and Gemini 3 Flash / Flash-Lite\n // do not support full thinking-off either. For Gemini 3 models, use the lowest supported\n // thinkingLevel without includeThoughts so hidden thinking remains invisible to pi.\n const geminiModel = model;\n if (isGemini3ProModel(geminiModel)) {\n return { thinkingLevel: ThinkingLevel.LOW };\n }\n if (isGemini3FlashModel(geminiModel)) {\n return { thinkingLevel: ThinkingLevel.MINIMAL };\n }\n // Gemini 2.x supports disabling via thinkingBudget = 0.\n return { thinkingBudget: 0 };\n}\nfunction getGemini3ThinkingLevel(effort, model) {\n if (isGemini3ProModel(model)) {\n switch (effort) {\n case \"minimal\":\n case \"low\":\n return \"LOW\";\n case \"medium\":\n case \"high\":\n return \"HIGH\";\n }\n }\n switch (effort) {\n case \"minimal\":\n return \"MINIMAL\";\n case \"low\":\n return \"LOW\";\n case \"medium\":\n return \"MEDIUM\";\n case \"high\":\n return \"HIGH\";\n }\n}\nfunction getGoogleBudget(model, effort, customBudgets) {\n if (customBudgets?.[effort] !== undefined) {\n return customBudgets[effort];\n }\n if (model.id.includes(\"2.5-pro\")) {\n const budgets = {\n minimal: 128,\n low: 2048,\n medium: 8192,\n high: 32768,\n };\n return budgets[effort];\n }\n if (model.id.includes(\"2.5-flash\")) {\n const budgets = {\n minimal: 128,\n low: 2048,\n medium: 8192,\n high: 24576,\n };\n return budgets[effort];\n }\n return -1;\n}\n//# sourceMappingURL=google-vertex.js.map"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;AASA,MAAM,cAAc;AACpB,MAAM,gCAAgC;AACtC,MAAM,qBAAqB;CACvB,4BAA4B,cAAc;CAC1C,SAAS,cAAc;CACvB,KAAK,cAAc;CACnB,QAAQ,cAAc;CACtB,MAAM,cAAc;AACxB;AAEA,IAAI,kBAAkB;AACtB,MAAa,UAAU,OAAO,SAAS,YAAY;CAC/C,MAAM,SAAS,IAAI,4BAA4B;CAC/C,CAAC,YAAY;EACT,MAAM,SAAS;GACX,MAAM;GACN,SAAS,CAAC;GACV,KAAK;GACL,UAAU,MAAM;GAChB,OAAO,MAAM;GACb,OAAO;IACH,OAAO;IACP,QAAQ;IACR,WAAW;IACX,YAAY;IACZ,aAAa;IACb,MAAM;KAAE,OAAO;KAAG,QAAQ;KAAG,WAAW;KAAG,YAAY;KAAG,OAAO;IAAE;GACvE;GACA,YAAY;GACZ,WAAW,KAAK,IAAI;EACxB;EACA,IAAI;GACA,IAAI,SAAS,SAAS,QAAQ,UAAU,WAAW,OAC/C,MAAM,IAAI,MAAM,4DAA4D;GAEhF,MAAM,SAAS,cAAc,OAAO;GAEpC,MAAM,SAAS,SACT,uBAAuB,OAAO,QAAQ,SAAS,OAAO,IACtD,aAAa,OAAO,eAAe,OAAO,GAAG,gBAAgB,OAAO,GAAG,SAAS,SAAS,SAAS,GAAG;GAC3G,IAAI,SAAS,YAAY,OAAO,SAAS,OAAO;GAChD,MAAM,aAAa,MAAM,SAAS,YAAY,QAAQ,KAAK;GAC3D,IAAI,eAAe,KAAA,GACf,SAAS;GAEb,MAAM,eAAe,MAAM,yBAAyB,OAAO,OAAO,sBAAsB,MAAM,GAAG,OAAO;GACxG,OAAO,KAAK;IAAE,MAAM;IAAS,SAAS;GAAO,CAAC;GAC9C,IAAI,eAAe;GACnB,MAAM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,yBAAyB,OAAO;AACzF;AACA,SAAS,0BAA0B,OAAO;CAItC,MAAM,cAAc;CACpB,IAAI,kBAAkB,WAAW,GAC7B,OAAO,EAAE,eAAe,cAAc,IAAI;CAE9C,IAAI,oBAAoB,WAAW,GAC/B,OAAO,EAAE,eAAe,cAAc,QAAQ;CAGlD,OAAO,EAAE,gBAAgB,EAAE;AAC/B;AACA,SAAS,wBAAwB,QAAQ,OAAO;CAC5C,IAAI,kBAAkB,KAAK,GACvB,QAAQ,QAAR;EACI,KAAK;EACL,KAAK,OACD,OAAO;EACX,KAAK;EACL,KAAK,QACD,OAAO;CACf;CAEJ,QAAQ,QAAR;EACI,KAAK,WACD,OAAO;EACX,KAAK,OACD,OAAO;EACX,KAAK,UACD,OAAO;EACX,KAAK,QACD,OAAO;CACf;AACJ;AACA,SAAS,gBAAgB,OAAO,QAAQ,eAAe;CACnD,IAAI,gBAAgB,YAAY,KAAA,GAC5B,OAAO,cAAc;CAEzB,IAAI,MAAM,GAAG,SAAS,SAAS,GAO3B,OAAO;EALH,SAAS;EACT,KAAK;EACL,QAAQ;EACR,MAAM;CAEG,EAAE;CAEnB,IAAI,MAAM,GAAG,SAAS,WAAW,GAO7B,OAAO;EALH,SAAS;EACT,KAAK;EACL,QAAQ;EACR,MAAM;CAEG,EAAE;CAEnB,OAAO;AACX"}
1
+ {"version":3,"file":"google-vertex-Dpq7O7Be.mjs","names":[],"sources":["../node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js"],"sourcesContent":["import { GoogleGenAI, ResourceScope, ThinkingLevel, } from \"@google/genai\";\nimport { calculateCost, clampThinkingLevel } from \"../models.js\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.js\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.js\";\nimport { providerHeadersToRecord } from \"../utils/headers.js\";\nimport { getProviderEnvValue } from \"../utils/provider-env.js\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.js\";\nimport { convertMessages, convertTools, isThinkingPart, mapStopReason, resolveGoogleFunctionCallingMode, retainThoughtSignature, retryGoogleRequest, supportsGoogleStrictToolSampling, } from \"./google-shared.js\";\nimport { buildBaseOptions } from \"./simple-options.js\";\nconst API_VERSION = \"v1\";\nconst GCP_VERTEX_CREDENTIALS_MARKER = \"gcp-vertex-credentials\";\nconst THINKING_LEVEL_MAP = {\n THINKING_LEVEL_UNSPECIFIED: ThinkingLevel.THINKING_LEVEL_UNSPECIFIED,\n MINIMAL: ThinkingLevel.MINIMAL,\n LOW: ThinkingLevel.LOW,\n MEDIUM: ThinkingLevel.MEDIUM,\n HIGH: ThinkingLevel.HIGH,\n};\n// Counter for generating unique tool call IDs\nlet toolCallCounter = 0;\nexport const stream = (model, context, options) => {\n const stream = new AssistantMessageEventStream();\n (async () => {\n const output = {\n role: \"assistant\",\n content: [],\n api: \"google-vertex\",\n provider: model.provider,\n model: model.id,\n usage: {\n input: 0,\n output: 0,\n cacheRead: 0,\n cacheWrite: 0,\n totalTokens: 0,\n cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n },\n stopReason: \"pending\",\n timestamp: Date.now(),\n };\n try {\n if (options?.fetch && options.fetch !== globalThis.fetch) {\n throw new Error(\"Custom fetch is not supported by the Google Vertex adapter\");\n }\n const apiKey = resolveApiKey(options);\n // Create the client using either a Vertex API key, if provided, or ADC with project and location\n const client = apiKey\n ? createClientWithApiKey(model, apiKey, options?.headers)\n : createClient(model, resolveProject(options), resolveLocation(options), options?.headers, options?.env);\n let params = buildParams(model, context, options);\n const nextParams = await options?.onPayload?.(params, model);\n if (nextParams !== undefined) {\n params = nextParams;\n }\n const googleStream = await retryGoogleRequest(() => client.models.generateContentStream(params), options);\n stream.push({ type: \"start\", partial: output });\n let currentBlock = null;\n const blocks = output.content;\n const blockIndex = () => blocks.length - 1;\n for await (const chunk of googleStream) {\n // Vertex uses the same @google/genai GenerateContentResponse type as Gemini.\n // responseId is documented there as an output-only identifier for each response.\n output.responseId ||= chunk.responseId;\n const candidate = chunk.candidates?.[0];\n if (candidate?.content?.parts) {\n for (const part of candidate.content.parts) {\n if (part.text !== undefined) {\n const isThinking = isThinkingPart(part);\n if (!currentBlock ||\n (isThinking && currentBlock.type !== \"thinking\") ||\n (!isThinking && currentBlock.type !== \"text\")) {\n if (currentBlock) {\n if (currentBlock.type === \"text\") {\n stream.push({\n type: \"text_end\",\n contentIndex: blocks.length - 1,\n content: currentBlock.text,\n partial: output,\n });\n }\n else {\n stream.push({\n type: \"thinking_end\",\n contentIndex: blockIndex(),\n content: currentBlock.thinking,\n partial: output,\n });\n }\n }\n if (isThinking) {\n currentBlock = { type: \"thinking\", thinking: \"\", thinkingSignature: undefined };\n output.content.push(currentBlock);\n stream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n }\n else {\n currentBlock = { type: \"text\", text: \"\" };\n output.content.push(currentBlock);\n stream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n }\n }\n if (currentBlock.type === \"thinking\") {\n currentBlock.thinking += part.text;\n currentBlock.thinkingSignature = retainThoughtSignature(currentBlock.thinkingSignature, part.thoughtSignature);\n stream.push({\n type: \"thinking_delta\",\n contentIndex: blockIndex(),\n delta: part.text,\n partial: output,\n });\n }\n else {\n currentBlock.text += part.text;\n currentBlock.textSignature = retainThoughtSignature(currentBlock.textSignature, part.thoughtSignature);\n stream.push({\n type: \"text_delta\",\n contentIndex: blockIndex(),\n delta: part.text,\n partial: output,\n });\n }\n }\n if (part.functionCall) {\n if (currentBlock) {\n if (currentBlock.type === \"text\") {\n stream.push({\n type: \"text_end\",\n contentIndex: blockIndex(),\n content: currentBlock.text,\n partial: output,\n });\n }\n else {\n stream.push({\n type: \"thinking_end\",\n contentIndex: blockIndex(),\n content: currentBlock.thinking,\n partial: output,\n });\n }\n currentBlock = null;\n }\n const providedId = part.functionCall.id;\n const needsNewId = !providedId || output.content.some((b) => b.type === \"toolCall\" && b.id === providedId);\n const toolCallId = needsNewId\n ? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`\n : providedId;\n const toolCall = {\n type: \"toolCall\",\n id: toolCallId,\n name: part.functionCall.name || \"\",\n arguments: part.functionCall.args ?? {},\n ...(part.thoughtSignature && { thoughtSignature: part.thoughtSignature }),\n };\n output.content.push(toolCall);\n stream.push({ type: \"toolcall_start\", contentIndex: blockIndex(), partial: output });\n stream.push({\n type: \"toolcall_delta\",\n contentIndex: blockIndex(),\n delta: JSON.stringify(toolCall.arguments),\n partial: output,\n });\n stream.push({ type: \"toolcall_end\", contentIndex: blockIndex(), toolCall, partial: output });\n }\n }\n }\n if (candidate?.finishReason) {\n output.rawStopReason = candidate.finishReason;\n output.stopReason = mapStopReason(candidate.finishReason);\n if (output.content.some((b) => b.type === \"toolCall\")) {\n output.stopReason = \"toolUse\";\n }\n }\n if (chunk.usageMetadata) {\n output.usage = {\n input: (chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),\n output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),\n cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,\n cacheWrite: 0,\n reasoning: chunk.usageMetadata.thoughtsTokenCount || 0,\n totalTokens: chunk.usageMetadata.totalTokenCount || 0,\n cost: {\n input: 0,\n output: 0,\n cacheRead: 0,\n cacheWrite: 0,\n total: 0,\n },\n };\n calculateCost(model, output.usage);\n }\n }\n if (currentBlock) {\n if (currentBlock.type === \"text\") {\n stream.push({\n type: \"text_end\",\n contentIndex: blockIndex(),\n content: currentBlock.text,\n partial: output,\n });\n }\n else {\n stream.push({\n type: \"thinking_end\",\n contentIndex: blockIndex(),\n content: currentBlock.thinking,\n partial: output,\n });\n }\n }\n if (options?.signal?.aborted) {\n throw new Error(\"Request was aborted\");\n }\n if (output.stopReason === \"pending\") {\n throw new Error(\"Google Vertex stream ended without a finish reason\");\n }\n if (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n const errorMessage = output.rawStopReason\n ? `Provider stopped with: ${output.rawStopReason}`\n : \"An unknown error occurred\";\n throw new Error(errorMessage);\n }\n stream.push({ type: \"done\", reason: output.stopReason, message: output });\n stream.end();\n }\n catch (error) {\n // Remove internal index property used during streaming\n for (const block of output.content) {\n if (\"index\" in block) {\n delete block.index;\n }\n }\n output.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n output.errorMessage = formatProviderError(normalizeProviderError(error));\n stream.push({ type: \"error\", reason: output.stopReason, error: output });\n stream.end();\n }\n })();\n return stream;\n};\nexport const streamSimple = (model, context, options) => {\n const base = buildBaseOptions(model, context, options, undefined);\n if (!options?.reasoning) {\n return stream(model, context, {\n ...base,\n thinking: { enabled: false },\n });\n }\n const clampedReasoning = clampThinkingLevel(model, options.reasoning);\n const effort = (clampedReasoning === \"off\" ? \"high\" : clampedReasoning);\n const geminiModel = model;\n if (isGemini3ProModel(geminiModel) || isGemini3FlashModel(geminiModel)) {\n return stream(model, context, {\n ...base,\n thinking: {\n enabled: true,\n level: getGemini3ThinkingLevel(effort, geminiModel),\n },\n });\n }\n return stream(model, context, {\n ...base,\n thinking: {\n enabled: true,\n budgetTokens: getGoogleBudget(geminiModel, effort, options.thinkingBudgets),\n },\n });\n};\nfunction createClient(model, project, location, optionsHeaders, env) {\n const googleAuthOptions = buildGoogleAuthOptions(env);\n return new GoogleGenAI({\n vertexai: true,\n project,\n location,\n apiVersion: API_VERSION,\n ...(googleAuthOptions ? { googleAuthOptions } : {}),\n httpOptions: buildHttpOptions(model, optionsHeaders),\n });\n}\nfunction createClientWithApiKey(model, apiKey, optionsHeaders) {\n return new GoogleGenAI({\n vertexai: true,\n apiKey,\n apiVersion: API_VERSION,\n httpOptions: buildHttpOptions(model, optionsHeaders),\n });\n}\nfunction buildHttpOptions(model, optionsHeaders) {\n const httpOptions = {};\n const baseUrl = resolveCustomBaseUrl(model.baseUrl);\n if (baseUrl) {\n httpOptions.baseUrl = baseUrl;\n httpOptions.baseUrlResourceScope = ResourceScope.COLLECTION;\n if (baseUrlIncludesApiVersion(baseUrl)) {\n httpOptions.apiVersion = \"\";\n }\n }\n const headers = providerHeadersToRecord({ ...model.headers, ...optionsHeaders });\n if (headers) {\n httpOptions.headers = headers;\n }\n return Object.keys(httpOptions).length > 0 ? httpOptions : undefined;\n}\nfunction resolveCustomBaseUrl(baseUrl) {\n const trimmed = baseUrl.trim();\n if (!trimmed || trimmed.includes(\"{location}\")) {\n return undefined;\n }\n return trimmed;\n}\nfunction baseUrlIncludesApiVersion(baseUrl) {\n try {\n const url = new URL(baseUrl);\n return url.pathname.split(\"/\").some((part) => /^v\\d+(?:beta\\d*)?$/.test(part));\n }\n catch {\n return /(?:^|\\/)v\\d+(?:beta\\d*)?(?:\\/|$)/.test(baseUrl);\n }\n}\nfunction buildGoogleAuthOptions(env) {\n const keyFilename = getProviderEnvValue(\"GOOGLE_APPLICATION_CREDENTIALS\", env);\n return keyFilename ? { keyFilename } : undefined;\n}\nfunction resolveApiKey(options) {\n const apiKey = options?.apiKey?.trim();\n if (!apiKey || apiKey === GCP_VERTEX_CREDENTIALS_MARKER || isPlaceholderApiKey(apiKey)) {\n return undefined;\n }\n return apiKey;\n}\nfunction isPlaceholderApiKey(apiKey) {\n return /^<[^>]+>$/.test(apiKey);\n}\nfunction resolveProject(options) {\n const project = options?.project ||\n getProviderEnvValue(\"GOOGLE_CLOUD_PROJECT\", options?.env) ||\n getProviderEnvValue(\"GCLOUD_PROJECT\", options?.env);\n if (!project) {\n throw new Error(\"Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.\");\n }\n return project;\n}\nfunction resolveLocation(options) {\n const location = options?.location || getProviderEnvValue(\"GOOGLE_CLOUD_LOCATION\", options?.env);\n if (!location) {\n throw new Error(\"Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.\");\n }\n return location;\n}\nfunction buildParams(model, context, options = {}) {\n const contents = convertMessages(model, context);\n const generationConfig = {};\n if (options.temperature !== undefined) {\n generationConfig.temperature = options.temperature;\n }\n if (options.maxTokens !== undefined) {\n generationConfig.maxOutputTokens = options.maxTokens;\n }\n const functionCallingMode = context.tools?.length\n ? resolveGoogleFunctionCallingMode(context.tools, options.toolChoice, supportsGoogleStrictToolSampling(model.id))\n : undefined;\n const config = {\n ...(Object.keys(generationConfig).length > 0 && generationConfig),\n ...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),\n ...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }),\n ...(functionCallingMode !== undefined && {\n toolConfig: { functionCallingConfig: { mode: functionCallingMode } },\n }),\n };\n if (options.thinking?.enabled && model.reasoning) {\n const thinkingConfig = { includeThoughts: true };\n if (options.thinking.level !== undefined) {\n thinkingConfig.thinkingLevel = THINKING_LEVEL_MAP[options.thinking.level];\n }\n else if (options.thinking.budgetTokens !== undefined) {\n thinkingConfig.thinkingBudget = options.thinking.budgetTokens;\n }\n config.thinkingConfig = thinkingConfig;\n }\n else if (model.reasoning && options.thinking && !options.thinking.enabled) {\n config.thinkingConfig = getDisabledThinkingConfig(model);\n }\n if (options.signal) {\n if (options.signal.aborted) {\n throw new Error(\"Request aborted\");\n }\n config.abortSignal = options.signal;\n }\n const params = {\n model: model.id,\n contents,\n config,\n };\n return params;\n}\nfunction isGemini3ProModel(model) {\n return /gemini-3(?:\\.\\d+)?-pro/.test(model.id.toLowerCase());\n}\nfunction isGemini3FlashModel(model) {\n const id = model.id.toLowerCase();\n return /gemini-3(?:\\.\\d+)?-flash/.test(id) || id === \"gemini-flash-latest\" || id === \"gemini-flash-lite-latest\";\n}\nfunction getDisabledThinkingConfig(model) {\n // Google docs: Gemini 3.1 Pro cannot disable thinking, and Gemini 3 Flash / Flash-Lite\n // do not support full thinking-off either. For Gemini 3 models, use the lowest supported\n // thinkingLevel without includeThoughts so hidden thinking remains invisible to pi.\n const geminiModel = model;\n if (isGemini3ProModel(geminiModel)) {\n return { thinkingLevel: ThinkingLevel.LOW };\n }\n if (isGemini3FlashModel(geminiModel)) {\n return { thinkingLevel: ThinkingLevel.MINIMAL };\n }\n // Gemini 2.x supports disabling via thinkingBudget = 0.\n return { thinkingBudget: 0 };\n}\nfunction getGemini3ThinkingLevel(effort, model) {\n if (isGemini3ProModel(model)) {\n switch (effort) {\n case \"minimal\":\n case \"low\":\n return \"LOW\";\n case \"medium\":\n case \"high\":\n return \"HIGH\";\n }\n }\n switch (effort) {\n case \"minimal\":\n return \"MINIMAL\";\n case \"low\":\n return \"LOW\";\n case \"medium\":\n return \"MEDIUM\";\n case \"high\":\n return \"HIGH\";\n }\n}\nfunction getGoogleBudget(model, effort, customBudgets) {\n if (customBudgets?.[effort] !== undefined) {\n return customBudgets[effort];\n }\n if (model.id.includes(\"2.5-pro\")) {\n const budgets = {\n minimal: 128,\n low: 2048,\n medium: 8192,\n high: 32768,\n };\n return budgets[effort];\n }\n if (model.id.includes(\"2.5-flash\")) {\n const budgets = {\n minimal: 128,\n low: 2048,\n medium: 8192,\n high: 24576,\n };\n return budgets[effort];\n }\n return -1;\n}\n//# sourceMappingURL=google-vertex.js.map"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;AASA,MAAM,cAAc;AACpB,MAAM,gCAAgC;AACtC,MAAM,qBAAqB;CACvB,4BAA4B,cAAc;CAC1C,SAAS,cAAc;CACvB,KAAK,cAAc;CACnB,QAAQ,cAAc;CACtB,MAAM,cAAc;AACxB;AAEA,IAAI,kBAAkB;AACtB,MAAa,UAAU,OAAO,SAAS,YAAY;CAC/C,MAAM,SAAS,IAAI,4BAA4B;CAC/C,CAAC,YAAY;EACT,MAAM,SAAS;GACX,MAAM;GACN,SAAS,CAAC;GACV,KAAK;GACL,UAAU,MAAM;GAChB,OAAO,MAAM;GACb,OAAO;IACH,OAAO;IACP,QAAQ;IACR,WAAW;IACX,YAAY;IACZ,aAAa;IACb,MAAM;KAAE,OAAO;KAAG,QAAQ;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AI,MAAM,GAAG,SAAS,SAAS,GAO3B,OAAO;EALH,SAAS;EACT,KAAK;EACL,QAAQ;EACR,MAAM;CAEG,EAAE;CAEnB,IAAI,MAAM,GAAG,SAAS,WAAW,GAO7B,OAAO;EALH,SAAS;EACT,KAAK;EACL,QAAQ;EACR,MAAM;CAEG,EAAE;CAEnB,OAAO;AACX"}
package/dist/host.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- import { t as applyPiPackage } from "./runtime-B9R7bDWT.mjs";
2
+ import { t as applyPiPackage } from "./runtime-B7mEIRf-.mjs";
3
3
  import { t as resolvePiPackage } from "./source-0sA5z08z.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { cp, mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/analyzer.ts","../src/compatibility.ts","../src/generator.ts","../src/mcp-config.ts","../src/source.ts"],"mappings":";;;;iBAgbsB,eAAe,KAAK,oBAAoB,QAAQ;;;UC9a5D;EACR,OAAO;EACP;;cAKW;cAKA;cAKA;cAWA,mBAAmB,SAAS,eAAe,SAAS,eAAe;cAmNnE,eAAe,SAAS,eAAe;cA4BvC,kBAAkB,SAAS,eAAe;cA+B1C,WAAW,SAAS,eAAe;cAgHnC,aAAa,SAAS,eAAe;iBA6FlC,WAAW,iBAAiB;iBAI5B,aAAa,gBAAgB;iBAO7B,kBAAkB,qBAAqB,uBAAuB;iBAS9D,uBAAuB,mBAAmB;iBAI1C,yBAAyB,mBAAmB;;;iBCjMtC,eACpB,KAAK,mBACL,SAAS,kBACR;EAAU;EAAgB,QAAQ;EAAqB;;;;KCtUrD,gBAAgB;UAEJ;EACf;EACA;EACA;EACA;EACA;EACA,MAAM;EACN;EACA;EACA,UAAU;EACV;;UAGe;EACf;EACA;;UAGe;EACf,SAAS;EACT,SAAS;EACT,UAAU;EACV;;iBA6Cc,oBAAoB,aAAa;EAA8B,SAAS,YAAY;EAAc;;iBAoElG,mBAAmB,aAAa,wBAA4B;;iBAsD5D,eAAe,QAAQ;;;iBC5EjB,iBAAiB,gBAAgB,eAAsB,QAAQ"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/analyzer.ts","../src/compatibility.ts","../src/generator.ts","../src/mcp-config.ts","../src/source.ts"],"mappings":";;;;iBAgbsB,eAAe,KAAK,oBAAoB,QAAQ;;;UC9a5D;EACR,OAAO;EACP;;cAKW;cAKA;cAKA;cAWA,mBAAmB,SAAS,eAAe,SAAS,eAAe;cAmNnE,eAAe,SAAS,eAAe;cA4BvC,kBAAkB,SAAS,eAAe;cA+B1C,WAAW,SAAS,eAAe;cAgHnC,aAAa,SAAS,eAAe;iBA6FlC,WAAW,iBAAiB;iBAI5B,aAAa,gBAAgB;iBAO7B,kBAAkB,qBAAqB,uBAAuB;iBAS9D,uBAAuB,mBAAmB;iBAI1C,yBAAyB,mBAAmB;;;iBC3LtC,eACpB,KAAK,mBACL,SAAS,kBACR;EAAU;EAAgB,QAAQ;EAAqB;;;;KC5UrD,gBAAgB;UAEJ;EACf;EACA;EACA;EACA;EACA;EACA,MAAM;EACN;EACA;EACA,UAAU;EACV;;UAGe;EACf;EACA;;UAGe;EACf,SAAS;EACT,SAAS;EACT,UAAU;EACV;;iBA6Cc,oBAAoB,aAAa;EAA8B,SAAS,YAAY;EAAc;;iBAoElG,mBAAmB,aAAa,wBAA4B;;iBAsD5D,eAAe,QAAQ;;;iBC5EjB,iBAAiB,gBAAgB,eAAsB,QAAQ"}
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- import { _ as ruleForHostImport, a as analyzePackage, c as EVENT_RULES, d as PI_CODING_AGENT_PACKAGES, f as PI_TUI_PACKAGES, g as ruleForEvent, h as ruleForContextProperty, i as generateBundle, l as HOST_IMPORT_RULES, m as ruleForApi, n as convertPiMcpConfig, o as API_RULES, p as UI_CONTEXT_RULES, r as renderMcpPatch, s as CONTEXT_RULES, t as collectPiMcpServers, u as PI_AI_PACKAGES, v as ruleForUiContextProperty } from "./mcp-config-D2B3kv-Z.mjs";
2
+ import { _ as ruleForHostImport, a as analyzePackage, c as EVENT_RULES, d as PI_CODING_AGENT_PACKAGES, f as PI_TUI_PACKAGES, g as ruleForEvent, h as ruleForContextProperty, i as generateBundle, l as HOST_IMPORT_RULES, m as ruleForApi, n as convertPiMcpConfig, o as API_RULES, p as UI_CONTEXT_RULES, r as renderMcpPatch, s as CONTEXT_RULES, t as collectPiMcpServers, u as PI_AI_PACKAGES, v as ruleForUiContextProperty } from "./mcp-config-B3h5jTBb.mjs";
3
3
  import { t as resolvePiPackage } from "./source-0sA5z08z.mjs";
4
4
  import { applyPiHost, generateHostBundle, manifestForInstalled } from "./host.mjs";
5
5
  export { API_RULES, CONTEXT_RULES, EVENT_RULES, HOST_IMPORT_RULES, PI_AI_PACKAGES, PI_CODING_AGENT_PACKAGES, PI_TUI_PACKAGES, UI_CONTEXT_RULES, analyzePackage, applyPiHost, collectPiMcpServers, convertPiMcpConfig, generateBundle, generateHostBundle, manifestForInstalled, renderMcpPatch, resolvePiPackage, ruleForApi, ruleForContextProperty, ruleForEvent, ruleForHostImport, ruleForUiContextProperty };
@@ -1,5 +1,5 @@
1
1
 
2
- import { t as __commonJSMin } from "./rolldown-runtime-CTfmNlz1.mjs";
2
+ import { H as __commonJSMin } from "./pi-ai-B_88Wb0r.mjs";
3
3
  //#region node_modules/.pnpm/partial-json@0.1.7/node_modules/partial-json/dist/options.js
4
4
  var require_options = /* @__PURE__ */ __commonJSMin(((exports) => {
5
5
  /**
@@ -381,4 +381,4 @@ function parseStreamingJson(partialJson) {
381
381
  //#endregion
382
382
  export { parseStreamingJson as n, repairJson as r, parseJsonWithRepair as t };
383
383
 
384
- //# sourceMappingURL=json-parse-CFyFZSLJ.mjs.map
384
+ //# sourceMappingURL=json-parse-Dz5sKMTv.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"json-parse-CFyFZSLJ.mjs","names":["exports","partialParse"],"sources":["../node_modules/.pnpm/partial-json@0.1.7/node_modules/partial-json/dist/options.js","../node_modules/.pnpm/partial-json@0.1.7/node_modules/partial-json/dist/index.js","../node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/utils/json-parse.js"],"sourcesContent":["\"use strict\";\n/**\n * Sometimes you don't allow every type to be partially parsed.\n * For example, you may not want a partial number because it may increase its size gradually before it's complete.\n * In this case, you can use the `Allow` object to control what types you allow to be partially parsed.\n * @module\n */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Allow = exports.ALL = exports.COLLECTION = exports.ATOM = exports.SPECIAL = exports.INF = exports._INFINITY = exports.INFINITY = exports.NAN = exports.BOOL = exports.NULL = exports.OBJ = exports.ARR = exports.NUM = exports.STR = void 0;\n/**\n * allow partial strings like `\"hello \\u12` to be parsed as `\"hello \"`\n */\nexports.STR = 0b000000001;\n/**\n * allow partial numbers like `123.` to be parsed as `123`\n */\nexports.NUM = 0b000000010;\n/**\n * allow partial arrays like `[1, 2,` to be parsed as `[1, 2]`\n */\nexports.ARR = 0b000000100;\n/**\n * allow partial objects like `{\"a\": 1, \"b\":` to be parsed as `{\"a\": 1}`\n */\nexports.OBJ = 0b000001000;\n/**\n * allow `nu` to be parsed as `null`\n */\nexports.NULL = 0b000010000;\n/**\n * allow `tr` to be parsed as `true`, and `fa` to be parsed as `false`\n */\nexports.BOOL = 0b000100000;\n/**\n * allow `Na` to be parsed as `NaN`\n */\nexports.NAN = 0b001000000;\n/**\n * allow `Inf` to be parsed as `Infinity`\n */\nexports.INFINITY = 0b010000000;\n/**\n * allow `-Inf` to be parsed as `-Infinity`\n */\nexports._INFINITY = 0b100000000;\nexports.INF = exports.INFINITY | exports._INFINITY;\nexports.SPECIAL = exports.NULL | exports.BOOL | exports.INF | exports.NAN;\nexports.ATOM = exports.STR | exports.NUM | exports.SPECIAL;\nexports.COLLECTION = exports.ARR | exports.OBJ;\nexports.ALL = exports.ATOM | exports.COLLECTION;\n/**\n * Control what types you allow to be partially parsed.\n * The default is to allow all types to be partially parsed, which in most casees is the best option.\n * @example\n * If you don't want to allow partial objects, you can use the following code:\n * ```ts\n * import { Allow, parse } from \"partial-json\";\n * parse(`[{\"a\": 1, \"b\": 2}, {\"a\": 3,`, Allow.ARR); // [ { a: 1, b: 2 } ]\n * ```\n * Or you can use `~` to disallow a type:\n * ```ts\n * parse(`[{\"a\": 1, \"b\": 2}, {\"a\": 3,`, ~Allow.OBJ); // [ { a: 1, b: 2 } ]\n * ```\n * @example\n * If you don't want to allow partial strings, you can use the following code:\n * ```ts\n * import { Allow, parse } from \"partial-json\";\n * parse(`[\"complete string\", \"incompl`, ~Allow.STR); // [ 'complete string' ]\n * ```\n */\nexports.Allow = { STR: exports.STR, NUM: exports.NUM, ARR: exports.ARR, OBJ: exports.OBJ, NULL: exports.NULL, BOOL: exports.BOOL, NAN: exports.NAN, INFINITY: exports.INFINITY, _INFINITY: exports._INFINITY, INF: exports.INF, SPECIAL: exports.SPECIAL, ATOM: exports.ATOM, COLLECTION: exports.COLLECTION, ALL: exports.ALL };\nexports.default = exports.Allow;\n","\"use strict\";\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Allow = exports.MalformedJSON = exports.PartialJSON = exports.parseJSON = exports.parse = void 0;\nconst options_1 = require(\"./options\");\nObject.defineProperty(exports, \"Allow\", { enumerable: true, get: function () { return options_1.Allow; } });\n__exportStar(require(\"./options\"), exports);\nclass PartialJSON extends Error {\n}\nexports.PartialJSON = PartialJSON;\nclass MalformedJSON extends Error {\n}\nexports.MalformedJSON = MalformedJSON;\n/**\n * Parse incomplete JSON\n * @param {string} jsonString Partial JSON to be parsed\n * @param {number} allowPartial Specify what types are allowed to be partial, see {@link Allow} for details\n * @returns The parsed JSON\n * @throws {PartialJSON} If the JSON is incomplete (related to the `allow` parameter)\n * @throws {MalformedJSON} If the JSON is malformed\n */\nfunction parseJSON(jsonString, allowPartial = options_1.Allow.ALL) {\n if (typeof jsonString !== \"string\") {\n throw new TypeError(`expecting str, got ${typeof jsonString}`);\n }\n if (!jsonString.trim()) {\n throw new Error(`${jsonString} is empty`);\n }\n return _parseJSON(jsonString.trim(), allowPartial);\n}\nexports.parseJSON = parseJSON;\n;\nconst _parseJSON = (jsonString, allow) => {\n const length = jsonString.length;\n let index = 0;\n const markPartialJSON = (msg) => {\n throw new PartialJSON(`${msg} at position ${index}`);\n };\n const throwMalformedError = (msg) => {\n throw new MalformedJSON(`${msg} at position ${index}`);\n };\n const parseAny = () => {\n skipBlank();\n if (index >= length)\n markPartialJSON(\"Unexpected end of input\");\n if (jsonString[index] === '\"')\n return parseStr();\n if (jsonString[index] === \"{\")\n return parseObj();\n if (jsonString[index] === \"[\")\n return parseArr();\n if (jsonString.substring(index, index + 4) === \"null\" || (options_1.Allow.NULL & allow && length - index < 4 && \"null\".startsWith(jsonString.substring(index)))) {\n index += 4;\n return null;\n }\n if (jsonString.substring(index, index + 4) === \"true\" || (options_1.Allow.BOOL & allow && length - index < 4 && \"true\".startsWith(jsonString.substring(index)))) {\n index += 4;\n return true;\n }\n if (jsonString.substring(index, index + 5) === \"false\" || (options_1.Allow.BOOL & allow && length - index < 5 && \"false\".startsWith(jsonString.substring(index)))) {\n index += 5;\n return false;\n }\n if (jsonString.substring(index, index + 8) === \"Infinity\" || (options_1.Allow.INFINITY & allow && length - index < 8 && \"Infinity\".startsWith(jsonString.substring(index)))) {\n index += 8;\n return Infinity;\n }\n if (jsonString.substring(index, index + 9) === \"-Infinity\" || (options_1.Allow._INFINITY & allow && 1 < length - index && length - index < 9 && \"-Infinity\".startsWith(jsonString.substring(index)))) {\n index += 9;\n return -Infinity;\n }\n if (jsonString.substring(index, index + 3) === \"NaN\" || (options_1.Allow.NAN & allow && length - index < 3 && \"NaN\".startsWith(jsonString.substring(index)))) {\n index += 3;\n return NaN;\n }\n return parseNum();\n };\n const parseStr = () => {\n const start = index;\n let escape = false;\n index++; // skip initial quote\n while (index < length && (jsonString[index] !== '\"' || (escape && jsonString[index - 1] === \"\\\\\"))) {\n escape = jsonString[index] === \"\\\\\" ? !escape : false;\n index++;\n }\n if (jsonString.charAt(index) == '\"') {\n try {\n return JSON.parse(jsonString.substring(start, ++index - Number(escape)));\n }\n catch (e) {\n throwMalformedError(String(e));\n }\n }\n else if (options_1.Allow.STR & allow) {\n try {\n return JSON.parse(jsonString.substring(start, index - Number(escape)) + '\"');\n }\n catch (e) {\n // SyntaxError: Invalid escape sequence\n return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf(\"\\\\\")) + '\"');\n }\n }\n markPartialJSON(\"Unterminated string literal\");\n };\n const parseObj = () => {\n index++; // skip initial brace\n skipBlank();\n const obj = {};\n try {\n while (jsonString[index] !== \"}\") {\n skipBlank();\n if (index >= length && options_1.Allow.OBJ & allow)\n return obj;\n const key = parseStr();\n skipBlank();\n index++; // skip colon\n try {\n const value = parseAny();\n obj[key] = value;\n }\n catch (e) {\n if (options_1.Allow.OBJ & allow)\n return obj;\n else\n throw e;\n }\n skipBlank();\n if (jsonString[index] === \",\")\n index++; // skip comma\n }\n }\n catch (e) {\n if (options_1.Allow.OBJ & allow)\n return obj;\n else\n markPartialJSON(\"Expected '}' at end of object\");\n }\n index++; // skip final brace\n return obj;\n };\n const parseArr = () => {\n index++; // skip initial bracket\n const arr = [];\n try {\n while (jsonString[index] !== \"]\") {\n arr.push(parseAny());\n skipBlank();\n if (jsonString[index] === \",\") {\n index++; // skip comma\n }\n }\n }\n catch (e) {\n if (options_1.Allow.ARR & allow) {\n return arr;\n }\n markPartialJSON(\"Expected ']' at end of array\");\n }\n index++; // skip final bracket\n return arr;\n };\n const parseNum = () => {\n if (index === 0) {\n if (jsonString === \"-\")\n throwMalformedError(\"Not sure what '-' is\");\n try {\n return JSON.parse(jsonString);\n }\n catch (e) {\n if (options_1.Allow.NUM & allow)\n try {\n return JSON.parse(jsonString.substring(0, jsonString.lastIndexOf(\"e\")));\n }\n catch (e) { }\n throwMalformedError(String(e));\n }\n }\n const start = index;\n if (jsonString[index] === \"-\")\n index++;\n while (jsonString[index] && \",]}\".indexOf(jsonString[index]) === -1)\n index++;\n if (index == length && !(options_1.Allow.NUM & allow))\n markPartialJSON(\"Unterminated number literal\");\n try {\n return JSON.parse(jsonString.substring(start, index));\n }\n catch (e) {\n if (jsonString.substring(start, index) === \"-\")\n markPartialJSON(\"Not sure what '-' is\");\n try {\n return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf(\"e\")));\n }\n catch (e) {\n throwMalformedError(String(e));\n }\n }\n };\n const skipBlank = () => {\n while (index < length && \" \\n\\r\\t\".includes(jsonString[index])) {\n index++;\n }\n };\n return parseAny();\n};\nconst parse = parseJSON;\nexports.parse = parse;\n","import { parse as partialParse } from \"partial-json\";\nconst VALID_JSON_ESCAPES = new Set(['\"', \"\\\\\", \"/\", \"b\", \"f\", \"n\", \"r\", \"t\", \"u\"]);\nfunction isControlCharacter(char) {\n const codePoint = char.codePointAt(0);\n return codePoint !== undefined && codePoint >= 0x00 && codePoint <= 0x1f;\n}\nfunction escapeControlCharacter(char) {\n switch (char) {\n case \"\\b\":\n return \"\\\\b\";\n case \"\\f\":\n return \"\\\\f\";\n case \"\\n\":\n return \"\\\\n\";\n case \"\\r\":\n return \"\\\\r\";\n case \"\\t\":\n return \"\\\\t\";\n default:\n return `\\\\u${char.codePointAt(0)?.toString(16).padStart(4, \"0\") ?? \"0000\"}`;\n }\n}\n/**\n * Repairs malformed JSON string literals by:\n * - escaping raw control characters inside strings\n * - doubling backslashes before invalid escape characters\n */\nexport function repairJson(json) {\n let repaired = \"\";\n let inString = false;\n for (let index = 0; index < json.length; index++) {\n const char = json[index];\n if (!inString) {\n repaired += char;\n if (char === '\"') {\n inString = true;\n }\n continue;\n }\n if (char === '\"') {\n repaired += char;\n inString = false;\n continue;\n }\n if (char === \"\\\\\") {\n const nextChar = json[index + 1];\n if (nextChar === undefined) {\n repaired += \"\\\\\\\\\";\n continue;\n }\n if (nextChar === \"u\") {\n const unicodeDigits = json.slice(index + 2, index + 6);\n if (/^[0-9a-fA-F]{4}$/.test(unicodeDigits)) {\n repaired += `\\\\u${unicodeDigits}`;\n index += 5;\n continue;\n }\n }\n if (VALID_JSON_ESCAPES.has(nextChar)) {\n repaired += `\\\\${nextChar}`;\n index += 1;\n continue;\n }\n repaired += \"\\\\\\\\\";\n continue;\n }\n repaired += isControlCharacter(char) ? escapeControlCharacter(char) : char;\n }\n return repaired;\n}\nexport function parseJsonWithRepair(json) {\n try {\n return JSON.parse(json);\n }\n catch (error) {\n const repairedJson = repairJson(json);\n if (repairedJson !== json) {\n return JSON.parse(repairedJson);\n }\n throw error;\n }\n}\n/**\n * Attempts to parse potentially incomplete JSON during streaming.\n * Always returns a valid object, even if the JSON is incomplete.\n *\n * @param partialJson The partial JSON string from streaming\n * @returns Parsed object or empty object if parsing fails\n */\nexport function parseStreamingJson(partialJson) {\n if (!partialJson || partialJson.trim() === \"\") {\n return {};\n }\n try {\n return parseJsonWithRepair(partialJson);\n }\n catch {\n try {\n const result = partialParse(partialJson);\n return (result ?? {});\n }\n catch {\n try {\n const result = partialParse(repairJson(partialJson));\n return (result ?? {});\n }\n catch {\n return {};\n }\n }\n }\n}\n//# sourceMappingURL=json-parse.js.map"],"x_google_ignoreList":[0,1,2],"mappings":";;;;;;;;;;CAOA,OAAO,eAAe,SAAS,cAAc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A,OAAO,KAAK,MAAM,IAAI;CAC1B,SACO,OAAO;EACV,MAAM,eAAe,WAAW,IAAI;EACpC,IAAI,iBAAiB,MACjB,OAAO,KAAK,MAAM,YAAY;EAElC,MAAM;CACV;AACJ;;;;;;;;AAQA,SAAgB,mBAAmB,aAAa;CAC5C,IAAI,CAAC,eAAe,YAAY,KAAK,MAAM,IACvC,OAAO,CAAC;CAEZ,IAAI;EACA,OAAO,oBAAoB,WAAW;CAC1C,QACM;EACF,IAAI;GAEA,QAAA,GADeC,YAAAA,MAAAA,CAAa,WACf,KAAK,CAAC;EACvB,QACM;GACF,IAAI;IAEA,QAAA,GADeA,YAAAA,MAAAA,CAAa,WAAW,WAAW,CACrC,KAAK,CAAC;GACvB,QACM;IACF,OAAO,CAAC;GACZ;EACJ;CACJ;AACJ"}
1
+ {"version":3,"file":"json-parse-Dz5sKMTv.mjs","names":["exports","partialParse"],"sources":["../node_modules/.pnpm/partial-json@0.1.7/node_modules/partial-json/dist/options.js","../node_modules/.pnpm/partial-json@0.1.7/node_modules/partial-json/dist/index.js","../node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/utils/json-parse.js"],"sourcesContent":["\"use strict\";\n/**\n * Sometimes you don't allow every type to be partially parsed.\n * For example, you may not want a partial number because it may increase its size gradually before it's complete.\n * In this case, you can use the `Allow` object to control what types you allow to be partially parsed.\n * @module\n */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Allow = exports.ALL = exports.COLLECTION = exports.ATOM = exports.SPECIAL = exports.INF = exports._INFINITY = exports.INFINITY = exports.NAN = exports.BOOL = exports.NULL = exports.OBJ = exports.ARR = exports.NUM = exports.STR = void 0;\n/**\n * allow partial strings like `\"hello \\u12` to be parsed as `\"hello \"`\n */\nexports.STR = 0b000000001;\n/**\n * allow partial numbers like `123.` to be parsed as `123`\n */\nexports.NUM = 0b000000010;\n/**\n * allow partial arrays like `[1, 2,` to be parsed as `[1, 2]`\n */\nexports.ARR = 0b000000100;\n/**\n * allow partial objects like `{\"a\": 1, \"b\":` to be parsed as `{\"a\": 1}`\n */\nexports.OBJ = 0b000001000;\n/**\n * allow `nu` to be parsed as `null`\n */\nexports.NULL = 0b000010000;\n/**\n * allow `tr` to be parsed as `true`, and `fa` to be parsed as `false`\n */\nexports.BOOL = 0b000100000;\n/**\n * allow `Na` to be parsed as `NaN`\n */\nexports.NAN = 0b001000000;\n/**\n * allow `Inf` to be parsed as `Infinity`\n */\nexports.INFINITY = 0b010000000;\n/**\n * allow `-Inf` to be parsed as `-Infinity`\n */\nexports._INFINITY = 0b100000000;\nexports.INF = exports.INFINITY | exports._INFINITY;\nexports.SPECIAL = exports.NULL | exports.BOOL | exports.INF | exports.NAN;\nexports.ATOM = exports.STR | exports.NUM | exports.SPECIAL;\nexports.COLLECTION = exports.ARR | exports.OBJ;\nexports.ALL = exports.ATOM | exports.COLLECTION;\n/**\n * Control what types you allow to be partially parsed.\n * The default is to allow all types to be partially parsed, which in most casees is the best option.\n * @example\n * If you don't want to allow partial objects, you can use the following code:\n * ```ts\n * import { Allow, parse } from \"partial-json\";\n * parse(`[{\"a\": 1, \"b\": 2}, {\"a\": 3,`, Allow.ARR); // [ { a: 1, b: 2 } ]\n * ```\n * Or you can use `~` to disallow a type:\n * ```ts\n * parse(`[{\"a\": 1, \"b\": 2}, {\"a\": 3,`, ~Allow.OBJ); // [ { a: 1, b: 2 } ]\n * ```\n * @example\n * If you don't want to allow partial strings, you can use the following code:\n * ```ts\n * import { Allow, parse } from \"partial-json\";\n * parse(`[\"complete string\", \"incompl`, ~Allow.STR); // [ 'complete string' ]\n * ```\n */\nexports.Allow = { STR: exports.STR, NUM: exports.NUM, ARR: exports.ARR, OBJ: exports.OBJ, NULL: exports.NULL, BOOL: exports.BOOL, NAN: exports.NAN, INFINITY: exports.INFINITY, _INFINITY: exports._INFINITY, INF: exports.INF, SPECIAL: exports.SPECIAL, ATOM: exports.ATOM, COLLECTION: exports.COLLECTION, ALL: exports.ALL };\nexports.default = exports.Allow;\n","\"use strict\";\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Allow = exports.MalformedJSON = exports.PartialJSON = exports.parseJSON = exports.parse = void 0;\nconst options_1 = require(\"./options\");\nObject.defineProperty(exports, \"Allow\", { enumerable: true, get: function () { return options_1.Allow; } });\n__exportStar(require(\"./options\"), exports);\nclass PartialJSON extends Error {\n}\nexports.PartialJSON = PartialJSON;\nclass MalformedJSON extends Error {\n}\nexports.MalformedJSON = MalformedJSON;\n/**\n * Parse incomplete JSON\n * @param {string} jsonString Partial JSON to be parsed\n * @param {number} allowPartial Specify what types are allowed to be partial, see {@link Allow} for details\n * @returns The parsed JSON\n * @throws {PartialJSON} If the JSON is incomplete (related to the `allow` parameter)\n * @throws {MalformedJSON} If the JSON is malformed\n */\nfunction parseJSON(jsonString, allowPartial = options_1.Allow.ALL) {\n if (typeof jsonString !== \"string\") {\n throw new TypeError(`expecting str, got ${typeof jsonString}`);\n }\n if (!jsonString.trim()) {\n throw new Error(`${jsonString} is empty`);\n }\n return _parseJSON(jsonString.trim(), allowPartial);\n}\nexports.parseJSON = parseJSON;\n;\nconst _parseJSON = (jsonString, allow) => {\n const length = jsonString.length;\n let index = 0;\n const markPartialJSON = (msg) => {\n throw new PartialJSON(`${msg} at position ${index}`);\n };\n const throwMalformedError = (msg) => {\n throw new MalformedJSON(`${msg} at position ${index}`);\n };\n const parseAny = () => {\n skipBlank();\n if (index >= length)\n markPartialJSON(\"Unexpected end of input\");\n if (jsonString[index] === '\"')\n return parseStr();\n if (jsonString[index] === \"{\")\n return parseObj();\n if (jsonString[index] === \"[\")\n return parseArr();\n if (jsonString.substring(index, index + 4) === \"null\" || (options_1.Allow.NULL & allow && length - index < 4 && \"null\".startsWith(jsonString.substring(index)))) {\n index += 4;\n return null;\n }\n if (jsonString.substring(index, index + 4) === \"true\" || (options_1.Allow.BOOL & allow && length - index < 4 && \"true\".startsWith(jsonString.substring(index)))) {\n index += 4;\n return true;\n }\n if (jsonString.substring(index, index + 5) === \"false\" || (options_1.Allow.BOOL & allow && length - index < 5 && \"false\".startsWith(jsonString.substring(index)))) {\n index += 5;\n return false;\n }\n if (jsonString.substring(index, index + 8) === \"Infinity\" || (options_1.Allow.INFINITY & allow && length - index < 8 && \"Infinity\".startsWith(jsonString.substring(index)))) {\n index += 8;\n return Infinity;\n }\n if (jsonString.substring(index, index + 9) === \"-Infinity\" || (options_1.Allow._INFINITY & allow && 1 < length - index && length - index < 9 && \"-Infinity\".startsWith(jsonString.substring(index)))) {\n index += 9;\n return -Infinity;\n }\n if (jsonString.substring(index, index + 3) === \"NaN\" || (options_1.Allow.NAN & allow && length - index < 3 && \"NaN\".startsWith(jsonString.substring(index)))) {\n index += 3;\n return NaN;\n }\n return parseNum();\n };\n const parseStr = () => {\n const start = index;\n let escape = false;\n index++; // skip initial quote\n while (index < length && (jsonString[index] !== '\"' || (escape && jsonString[index - 1] === \"\\\\\"))) {\n escape = jsonString[index] === \"\\\\\" ? !escape : false;\n index++;\n }\n if (jsonString.charAt(index) == '\"') {\n try {\n return JSON.parse(jsonString.substring(start, ++index - Number(escape)));\n }\n catch (e) {\n throwMalformedError(String(e));\n }\n }\n else if (options_1.Allow.STR & allow) {\n try {\n return JSON.parse(jsonString.substring(start, index - Number(escape)) + '\"');\n }\n catch (e) {\n // SyntaxError: Invalid escape sequence\n return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf(\"\\\\\")) + '\"');\n }\n }\n markPartialJSON(\"Unterminated string literal\");\n };\n const parseObj = () => {\n index++; // skip initial brace\n skipBlank();\n const obj = {};\n try {\n while (jsonString[index] !== \"}\") {\n skipBlank();\n if (index >= length && options_1.Allow.OBJ & allow)\n return obj;\n const key = parseStr();\n skipBlank();\n index++; // skip colon\n try {\n const value = parseAny();\n obj[key] = value;\n }\n catch (e) {\n if (options_1.Allow.OBJ & allow)\n return obj;\n else\n throw e;\n }\n skipBlank();\n if (jsonString[index] === \",\")\n index++; // skip comma\n }\n }\n catch (e) {\n if (options_1.Allow.OBJ & allow)\n return obj;\n else\n markPartialJSON(\"Expected '}' at end of object\");\n }\n index++; // skip final brace\n return obj;\n };\n const parseArr = () => {\n index++; // skip initial bracket\n const arr = [];\n try {\n while (jsonString[index] !== \"]\") {\n arr.push(parseAny());\n skipBlank();\n if (jsonString[index] === \",\") {\n index++; // skip comma\n }\n }\n }\n catch (e) {\n if (options_1.Allow.ARR & allow) {\n return arr;\n }\n markPartialJSON(\"Expected ']' at end of array\");\n }\n index++; // skip final bracket\n return arr;\n };\n const parseNum = () => {\n if (index === 0) {\n if (jsonString === \"-\")\n throwMalformedError(\"Not sure what '-' is\");\n try {\n return JSON.parse(jsonString);\n }\n catch (e) {\n if (options_1.Allow.NUM & allow)\n try {\n return JSON.parse(jsonString.substring(0, jsonString.lastIndexOf(\"e\")));\n }\n catch (e) { }\n throwMalformedError(String(e));\n }\n }\n const start = index;\n if (jsonString[index] === \"-\")\n index++;\n while (jsonString[index] && \",]}\".indexOf(jsonString[index]) === -1)\n index++;\n if (index == length && !(options_1.Allow.NUM & allow))\n markPartialJSON(\"Unterminated number literal\");\n try {\n return JSON.parse(jsonString.substring(start, index));\n }\n catch (e) {\n if (jsonString.substring(start, index) === \"-\")\n markPartialJSON(\"Not sure what '-' is\");\n try {\n return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf(\"e\")));\n }\n catch (e) {\n throwMalformedError(String(e));\n }\n }\n };\n const skipBlank = () => {\n while (index < length && \" \\n\\r\\t\".includes(jsonString[index])) {\n index++;\n }\n };\n return parseAny();\n};\nconst parse = parseJSON;\nexports.parse = parse;\n","import { parse as partialParse } from \"partial-json\";\nconst VALID_JSON_ESCAPES = new Set(['\"', \"\\\\\", \"/\", \"b\", \"f\", \"n\", \"r\", \"t\", \"u\"]);\nfunction isControlCharacter(char) {\n const codePoint = char.codePointAt(0);\n return codePoint !== undefined && codePoint >= 0x00 && codePoint <= 0x1f;\n}\nfunction escapeControlCharacter(char) {\n switch (char) {\n case \"\\b\":\n return \"\\\\b\";\n case \"\\f\":\n return \"\\\\f\";\n case \"\\n\":\n return \"\\\\n\";\n case \"\\r\":\n return \"\\\\r\";\n case \"\\t\":\n return \"\\\\t\";\n default:\n return `\\\\u${char.codePointAt(0)?.toString(16).padStart(4, \"0\") ?? \"0000\"}`;\n }\n}\n/**\n * Repairs malformed JSON string literals by:\n * - escaping raw control characters inside strings\n * - doubling backslashes before invalid escape characters\n */\nexport function repairJson(json) {\n let repaired = \"\";\n let inString = false;\n for (let index = 0; index < json.length; index++) {\n const char = json[index];\n if (!inString) {\n repaired += char;\n if (char === '\"') {\n inString = true;\n }\n continue;\n }\n if (char === '\"') {\n repaired += char;\n inString = false;\n continue;\n }\n if (char === \"\\\\\") {\n const nextChar = json[index + 1];\n if (nextChar === undefined) {\n repaired += \"\\\\\\\\\";\n continue;\n }\n if (nextChar === \"u\") {\n const unicodeDigits = json.slice(index + 2, index + 6);\n if (/^[0-9a-fA-F]{4}$/.test(unicodeDigits)) {\n repaired += `\\\\u${unicodeDigits}`;\n index += 5;\n continue;\n }\n }\n if (VALID_JSON_ESCAPES.has(nextChar)) {\n repaired += `\\\\${nextChar}`;\n index += 1;\n continue;\n }\n repaired += \"\\\\\\\\\";\n continue;\n }\n repaired += isControlCharacter(char) ? escapeControlCharacter(char) : char;\n }\n return repaired;\n}\nexport function parseJsonWithRepair(json) {\n try {\n return JSON.parse(json);\n }\n catch (error) {\n const repairedJson = repairJson(json);\n if (repairedJson !== json) {\n return JSON.parse(repairedJson);\n }\n throw error;\n }\n}\n/**\n * Attempts to parse potentially incomplete JSON during streaming.\n * Always returns a valid object, even if the JSON is incomplete.\n *\n * @param partialJson The partial JSON string from streaming\n * @returns Parsed object or empty object if parsing fails\n */\nexport function parseStreamingJson(partialJson) {\n if (!partialJson || partialJson.trim() === \"\") {\n return {};\n }\n try {\n return parseJsonWithRepair(partialJson);\n }\n catch {\n try {\n const result = partialParse(partialJson);\n return (result ?? {});\n }\n catch {\n try {\n const result = partialParse(repairJson(partialJson));\n return (result ?? {});\n }\n catch {\n return {};\n }\n }\n }\n}\n//# sourceMappingURL=json-parse.js.map"],"x_google_ignoreList":[0,1,2],"mappings":";;;;;;;;;;CAOA,OAAO,eAAe,SAAS,cAAc,EAAE,OAAO,KAAK,CAAC;CAC5D,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,aAAa,QAAQ,OAAO,QAAQ,UAAU,QAAQ,MAAM,QAAQ,YAAY,QAAQ,WAAW,QAAQ,MAAM,QAAQ,OAAO,QAAQ,OAAO,QAAQ,MAAM,QAAQ,MAAM,QAAQ,MAAM,QAAQ,MAAM,KAAK;;;;CAIlP,QAAQ,MAAM;;;;CAId,QAAQ,MAAM;;;;CAId,QAAQ,MAAM;;;;CAId,QAAQ,MAAM;;;;CAId,QAAQ,OAAO;;;;CAIf,QAAQ,OAAO;;;;CAIf,QAAQ,MAAM;;;;CAId,QAAQ,WAAW;;;;CAInB,QAAQ,YAAY;CACpB,QAAQ,MAAM,QAAQ,WAAW,QAAQ;CACzC,QAAQ,UAAU,QAAQ,OAAO,QAAQ,OAAO,QAAQ,MAAM,QAAQ;CACtE,QAAQ,OAAO,QAAQ,MAAM,QAAQ,MAAM,QAAQ;CACnD,QAAQ,aAAa,QAAQ,MAAM,QAAQ;CAC3C,QAAQ,MAAM,QAAQ,OAAO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GAEf;EACJ;EACA,IAAI,SAAS,MAAK;GACd,YAAY;GACZ,WAAW;GACX;EACJ;EACA,IAAI,SAAS,MAAM;GACf,MAAM,WAAW,KAAK,QAAQ;GAC9B,IAAI,aAAa,KAAA,GAAW;IACxB,YAAY;IACZ;GACJ;GACA,IAAI,aAAa,KAAK;IAClB,MAAM,gBAAgB,KAAK,MAAM,QAAQ,GAAG,QAAQ,CAAC;IACrD,IAAI,mBAAmB,KAAK,aAAa,GAAG;KACxC,YAAY,MAAM;KAClB,SAAS;KACT;IACJ;GACJ;GACA,IAAI,mBAAmB,IAAI,QAAQ,GAAG;IAClC,YAAY,KAAK;IACjB,SAAS;IACT;GACJ;GACA,YAAY;GACZ;EACJ;EACA,YAAY,mBAAmB,IAAI,IAAI,uBAAuB,IAAI,IAAI;CAC1E;CACA,OAAO;AACX;AACA,SAAgB,oBAAoB,MAAM;CACtC,IAAI;EACA,OAAO,KAAK,MAAM,IAAI;CAC1B,SACO,OAAO;EACV,MAAM,eAAe,WAAW,IAAI;EACpC,IAAI,iBAAiB,MACjB,OAAO,KAAK,MAAM,YAAY;EAElC,MAAM;CACV;AACJ;;;;;;;;AAQA,SAAgB,mBAAmB,aAAa;CAC5C,IAAI,CAAC,eAAe,YAAY,KAAK,MAAM,IACvC,OAAO,CAAC;CAEZ,IAAI;EACA,OAAO,oBAAoB,WAAW;CAC1C,QACM;EACF,IAAI;GAEA,QAAA,GADeC,YAAAA,MAAAA,CAAa,WACf,KAAK,CAAC;EACvB,QACM;GACF,IAAI;IAEA,QAAA,GADeA,YAAAA,MAAAA,CAAa,WAAW,WAAW,CACrC,KAAK,CAAC;GACvB,QACM;IACF,OAAO,CAAC;GACZ;EACJ;CACJ;AACJ"}
@@ -244,7 +244,7 @@ const CONTEXT_RULES = Object.freeze({
244
244
  getSystemPromptOptions: rule("partial", "Returns an empty Pi option projection in command contexts."),
245
245
  waitForIdle: rule("partial", "Mapped to the DSH agent idle boundary when available."),
246
246
  sessionManager: rule("partial", "A real read-only projection: DSH durable messages plus pi2dsh sidecar entries, exposed through Pi's exact 14-method surface as a single-branch tree."),
247
- modelRegistry: rule("partial", "A live registry: the DSH llm directory plus package-registered providers project as Pi Models; getProviderAuth/getApiKeyAndHeaders run Pi's full credential chain. DSH-route credentials stay inside DSH adapters by design."),
247
+ modelRegistry: rule("partial", "A live registry over the ONE model directory: every Pi provider (package-registered or ~/.pi/agent/models.json) is a DSH llm route, and the registry is that directory's exact Pi projection — Pi-native entries keep api/baseUrl and the full Model shape. getProviderAuth/getApiKeyAndHeaders run Pi's full credential chain (models.json keys resolve with Pi's $ENV/!command semantics); DSH-owned routes keep their credentials inside their adapters by design."),
248
248
  model: rule("partial", "The agent's real provider/model route (a setModel() override wins), enriched from the projected catalog."),
249
249
  scopedModels: rule("partial", "The projected model catalog (DSH llm directory plus package-registered providers)."),
250
250
  hasConfiguredAuth: rule("partial", "Configuration check on the projected registry: true when the model's provider has a live route or package registration (not a key-liveness probe)."),
@@ -299,7 +299,7 @@ const API_RULES = Object.freeze({
299
299
  },
300
300
  registerCommand: {
301
301
  level: "partial",
302
- detail: "Registered in ctx.commands; ui.notify becomes the result, while interactive Pi TUI methods fail explicitly in headless DSH."
302
+ detail: "Registered in ctx.commands with Pi's never-throw collision semantics: a package re-registering its own name replaces it, and cross-source collisions mount under Pi's numbered scheme (/name-2 — the earlier registration keeps the bare name, where Pi renumbers both). ui.notify becomes the result, while interactive Pi TUI methods fail explicitly in headless DSH."
303
303
  },
304
304
  registerShortcut: {
305
305
  level: "partial",
@@ -444,8 +444,8 @@ const EVENT_RULES = Object.freeze({
444
444
  detail: "Text replacement and success-to-error blocking are supported; arbitrary details and error recovery are not."
445
445
  },
446
446
  before_agent_start: {
447
- level: "partial",
448
- detail: "System-prompt replacement is supported; Pi raw prompt and custom-message injection are unavailable at DSH assembly time."
447
+ level: "full",
448
+ detail: "Fires at the turn's first pre-step with the real prompt text and image attachments; returned custom messages enter the turn beside the user message, and a returned systemPrompt overrides this turn's assembly."
449
449
  },
450
450
  agent_end: {
451
451
  level: "partial",
@@ -484,8 +484,8 @@ const EVENT_RULES = Object.freeze({
484
484
  detail: "Fired by setThinkingLevel(); DSH-side reasoning changes surface through request/header projection."
485
485
  },
486
486
  context: {
487
- level: "unsupported",
488
- detail: "Pi context-list replacement conflicts with DSH append-only request reconstruction; the handler is accepted but never fires."
487
+ level: "partial",
488
+ detail: "Fires before each step with the full message projection; the transform applies to the step's not-yet-entered messages (the slice packages rewrite), while already-entered history stays read-only under DSH's append-only log."
489
489
  },
490
490
  before_provider_request: {
491
491
  level: "unsupported",
@@ -1312,6 +1312,7 @@ function generatedPackageJson(pkg, generatedName, runtimeSpec, runtimePackages,
1312
1312
  "cross-spawn": "^7.0.6",
1313
1313
  diff: "^9.0.0"
1314
1314
  } : {},
1315
+ "@earendil-works/pi-ai": "^0.84.1",
1315
1316
  ...hasSkills ? { "@deepseek-ai/dsh-skill-filesystem": "^0.1.0-rc.6" } : {},
1316
1317
  ...runtimeSpec !== void 0 ? { pi2dsh: runtimeSpec } : {}
1317
1318
  };
@@ -1359,7 +1360,7 @@ function generatedPackageJson(pkg, generatedName, runtimeSpec, runtimePackages,
1359
1360
  };
1360
1361
  }
1361
1362
  function generatedReadme(pkg, packageName, report) {
1362
- return `# ${packageName}\n\nGenerated by [pi2dsh](https://github.com/weijiafu14/pi2dsh) from \`${pkg.identity.name}@${pkg.identity.version}\`.\n\nCompatibility verdict: **${report.verdict}** (full ${report.summary.full}, partial ${report.summary.partial}, unsupported ${report.summary.unsupported}).\n\nReview \`pi2dsh.report.json\` before installation. This bundle executes the original Pi extension source and should only be installed when that source is trusted.\n\nInstall with DeepSeek Harness (keep the \`file:\` prefix so pnpm installs this bundle's dependencies instead of creating a bare link):\n\n\`\`\`sh\ndsh plugin --profile headless add file:$PWD\ndsh --profile headless --dump-config\n\`\`\`\n`;
1363
+ return `# ${packageName}\n\nGenerated by [pi2dsh](https://github.com/weijiafu14/pi2dsh) from \`${pkg.identity.name}@${pkg.identity.version}\`.\n\nCompatibility verdict: **${report.verdict}** (full ${report.summary.full}, partial ${report.summary.partial}, unsupported ${report.summary.unsupported}).\n\nReview \`pi2dsh.report.json\` before installation. This bundle executes the original Pi extension source and should only be installed when that source is trusted.\n\nInstall with DeepSeek Harness (keep the \`file:\` prefix so pnpm installs this bundle's dependencies instead of creating a bare link):\n\n\`\`\`sh\ndsh plugin --profile headless add file:$PWD\ndsh --profile headless --dump-config\n\`\`\`\n\nIf the install stops with \`ERR_PNPM_IGNORED_BUILDS\` (pnpm 10+ blocks dependency build scripts by default), approve the listed packages — either run \`pnpm approve-builds\` inside the profile directory, or set them to \`true\` under \`allowBuilds\` in the profile's \`pnpm-workspace.yaml\` — then re-run the add command.\n`;
1363
1364
  }
1364
1365
  function pluginSource(manifest, runtimeImport) {
1365
1366
  const injections = ["tools", "systemPrompt"];
@@ -1614,4 +1615,4 @@ function renderMcpPatch(result) {
1614
1615
  //#endregion
1615
1616
  export { ruleForHostImport as _, analyzePackage as a, EVENT_RULES as c, PI_CODING_AGENT_PACKAGES as d, PI_TUI_PACKAGES as f, ruleForEvent as g, ruleForContextProperty as h, generateBundle as i, HOST_IMPORT_RULES as l, ruleForApi as m, convertPiMcpConfig as n, API_RULES as o, UI_CONTEXT_RULES as p, renderMcpPatch as r, CONTEXT_RULES as s, collectPiMcpServers as t, PI_AI_PACKAGES as u, ruleForUiContextProperty as v };
1616
1617
 
1617
- //# sourceMappingURL=mcp-config-D2B3kv-Z.mjs.map
1618
+ //# sourceMappingURL=mcp-config-B3h5jTBb.mjs.map