@earendil-works/pi-coding-agent 0.99.1 → 0.99.2

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 (143) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/bundle/chunks/anthropic-messages-UID2PALB.js +6 -0
  3. package/dist/bundle/chunks/{azure-openai-responses-EN5WOBET.js → azure-openai-responses-TLHNIYZK.js} +1 -1
  4. package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
  5. package/dist/bundle/chunks/{chunk-IMTXZUO7.js → chunk-3KYEVQKX.js} +3 -3
  6. package/dist/bundle/chunks/{chunk-W2DOMZSC.js → chunk-3LH3ZQKY.js} +1 -1
  7. package/dist/bundle/chunks/chunk-3NVH2HQH.js +4 -0
  8. package/dist/bundle/chunks/{chunk-GUORCHFS.js → chunk-3YAHQSW6.js} +23 -20
  9. package/dist/bundle/chunks/{chunk-LLMKQWZS.js → chunk-45SXDISG.js} +5 -7
  10. package/dist/bundle/chunks/chunk-6D7LHLKG.js +2 -0
  11. package/dist/bundle/chunks/{chunk-AXPY26X7.js → chunk-7QSPBJKW.js} +3 -3
  12. package/dist/bundle/chunks/{chunk-SLDA2X2H.js → chunk-ECRK44UV.js} +1 -1
  13. package/dist/bundle/chunks/{chunk-PEHWOV5U.js → chunk-G3UZ5FWD.js} +12 -23
  14. package/dist/bundle/chunks/chunk-LD2P6SFZ.js +2 -0
  15. package/dist/bundle/chunks/{chunk-J4CWPC4N.js → chunk-OSKPX3Z5.js} +1 -1
  16. package/dist/bundle/chunks/{chunk-LRS5S6EK.js → chunk-R5J3MOBF.js} +1 -1
  17. package/dist/bundle/chunks/chunk-VIV3CWXG.js +2 -0
  18. package/dist/bundle/chunks/{cli-AZXNGIZH.js → cli-ALNBTL3U.js} +6 -4
  19. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-XJQQYGGU.js → cloudflare-workers-ai-system-one-NPQN263E.js} +1 -1
  20. package/dist/bundle/chunks/codemode-worker.js +23 -3
  21. package/dist/bundle/chunks/{execute-7XXPZAWW.js → execute-RC7W4ML3.js} +26 -6
  22. package/dist/bundle/chunks/github-copilot.js +1 -1
  23. package/dist/bundle/chunks/{google-generative-ai-CQAKKJTA.js → google-generative-ai-APTPZOQL.js} +1 -1
  24. package/dist/bundle/chunks/{google-vertex-AE36YXJU.js → google-vertex-MXCOSOY3.js} +1 -1
  25. package/dist/bundle/chunks/{llama-cpp-classify-PJJYKPLD.js → llama-cpp-classify-XT44PI3C.js} +1 -1
  26. package/dist/bundle/chunks/{mistral-conversations-KEYTXJM7.js → mistral-conversations-DKVFNQL6.js} +1 -1
  27. package/dist/bundle/chunks/{openai-codex-responses-JQTCOVEG.js → openai-codex-responses-3GKGNXC4.js} +1 -1
  28. package/dist/bundle/chunks/{openai-completions-XW2Q5HVC.js → openai-completions-JXDDPZ23.js} +1 -1
  29. package/dist/bundle/chunks/{openai-responses-6AXWFL75.js → openai-responses-S7GKCCDG.js} +1 -1
  30. package/dist/bundle/chunks/{openrouter-images-TPQ4V6OR.js → openrouter-images-ZVXWCSIM.js} +1 -1
  31. package/dist/bundle/chunks/{runtime-G5WJPRBM.js → runtime-NJPX4ID2.js} +1 -1
  32. package/dist/bundle/chunks/{typesafe-system-one-E7A4HNJI.js → typesafe-system-one-A4CZTQWZ.js} +1 -1
  33. package/dist/bundle/chunks/virtual-modules-5UGH4HRZ.js +2 -0
  34. package/dist/bundle/cli-runtime.js +1 -1
  35. package/dist/bundle/index.js +1 -1
  36. package/dist/bundle/rpc-entry.js +1 -1
  37. package/dist/config.d.ts +5 -8
  38. package/dist/config.d.ts.map +1 -1
  39. package/dist/config.js +16 -13
  40. package/dist/config.js.map +1 -1
  41. package/dist/core/agent-session.d.ts +7 -1
  42. package/dist/core/agent-session.d.ts.map +1 -1
  43. package/dist/core/agent-session.js +14 -2
  44. package/dist/core/agent-session.js.map +1 -1
  45. package/dist/core/extensions/loader.d.ts.map +1 -1
  46. package/dist/core/extensions/loader.js +13 -1
  47. package/dist/core/extensions/loader.js.map +1 -1
  48. package/dist/core/extensions/types.d.ts +6 -1
  49. package/dist/core/extensions/types.d.ts.map +1 -1
  50. package/dist/core/extensions/types.js.map +1 -1
  51. package/dist/core/mcp-servers.d.ts +28 -7
  52. package/dist/core/mcp-servers.d.ts.map +1 -1
  53. package/dist/core/mcp-servers.js +45 -11
  54. package/dist/core/mcp-servers.js.map +1 -1
  55. package/dist/core/model-runtime.d.ts +6 -0
  56. package/dist/core/model-runtime.d.ts.map +1 -1
  57. package/dist/core/model-runtime.js +22 -18
  58. package/dist/core/model-runtime.js.map +1 -1
  59. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  60. package/dist/core/remote-catalog-provider.js +4 -9
  61. package/dist/core/remote-catalog-provider.js.map +1 -1
  62. package/dist/core/sdk.d.ts.map +1 -1
  63. package/dist/core/sdk.js +1 -0
  64. package/dist/core/sdk.js.map +1 -1
  65. package/dist/core/tools/renderers/bash.d.ts.map +1 -1
  66. package/dist/core/tools/renderers/bash.js +11 -31
  67. package/dist/core/tools/renderers/bash.js.map +1 -1
  68. package/dist/core/virtual-models.d.ts +2 -0
  69. package/dist/core/virtual-models.d.ts.map +1 -1
  70. package/dist/core/virtual-models.js +19 -12
  71. package/dist/core/virtual-models.js.map +1 -1
  72. package/dist/extensions/codemode/execute.d.ts.map +1 -1
  73. package/dist/extensions/codemode/execute.js +43 -4
  74. package/dist/extensions/codemode/execute.js.map +1 -1
  75. package/dist/extensions/codemode/renderer.d.ts.map +1 -1
  76. package/dist/extensions/codemode/renderer.js +43 -25
  77. package/dist/extensions/codemode/renderer.js.map +1 -1
  78. package/dist/extensions/codemode/tool.d.ts +5 -4
  79. package/dist/extensions/codemode/tool.d.ts.map +1 -1
  80. package/dist/extensions/codemode/tool.js +22 -31
  81. package/dist/extensions/codemode/tool.js.map +1 -1
  82. package/dist/extensions/codemode/worker.d.ts +1 -1
  83. package/dist/extensions/codemode/worker.js +1 -1
  84. package/dist/extensions/codemode/worker.js.map +1 -1
  85. package/dist/extensions/mcp/cli.d.ts.map +1 -1
  86. package/dist/extensions/mcp/cli.js +18 -3
  87. package/dist/extensions/mcp/cli.js.map +1 -1
  88. package/dist/extensions/mcp/config.d.ts +4 -2
  89. package/dist/extensions/mcp/config.d.ts.map +1 -1
  90. package/dist/extensions/mcp/config.js +14 -2
  91. package/dist/extensions/mcp/config.js.map +1 -1
  92. package/dist/extensions/mcp/index.d.ts +32 -8
  93. package/dist/extensions/mcp/index.d.ts.map +1 -1
  94. package/dist/extensions/mcp/index.js +205 -52
  95. package/dist/extensions/mcp/index.js.map +1 -1
  96. package/dist/extensions/mcp/oauth.d.ts +2 -0
  97. package/dist/extensions/mcp/oauth.d.ts.map +1 -1
  98. package/dist/extensions/mcp/oauth.js +1 -1
  99. package/dist/extensions/mcp/oauth.js.map +1 -1
  100. package/dist/extensions/mcp/runtime.d.ts +2 -0
  101. package/dist/extensions/mcp/runtime.d.ts.map +1 -1
  102. package/dist/extensions/mcp/runtime.js +14 -8
  103. package/dist/extensions/mcp/runtime.js.map +1 -1
  104. package/dist/extensions/mcp/tools.d.ts +5 -4
  105. package/dist/extensions/mcp/tools.d.ts.map +1 -1
  106. package/dist/extensions/mcp/tools.js +33 -15
  107. package/dist/extensions/mcp/tools.js.map +1 -1
  108. package/dist/extensions/mcp/ui.d.ts.map +1 -1
  109. package/dist/extensions/mcp/ui.js +4 -2
  110. package/dist/extensions/mcp/ui.js.map +1 -1
  111. package/dist/extensions/tool-search/tool.d.ts +5 -4
  112. package/dist/extensions/tool-search/tool.d.ts.map +1 -1
  113. package/dist/extensions/tool-search/tool.js +7 -28
  114. package/dist/extensions/tool-search/tool.js.map +1 -1
  115. package/dist/modes/interactive/components/visual-truncate.d.ts +27 -3
  116. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  117. package/dist/modes/interactive/components/visual-truncate.js +39 -6
  118. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  119. package/docs/cli.md +3 -3
  120. package/docs/extensions.md +3 -3
  121. package/docs/mcp.md +125 -82
  122. package/docs/providers.md +2 -0
  123. package/docs/sdk.md +1 -1
  124. package/docs/settings.md +3 -1
  125. package/examples/extensions/built-in-tool-renderer.ts +16 -40
  126. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  127. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  128. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  129. package/examples/extensions/gondolin/package-lock.json +2 -2
  130. package/examples/extensions/gondolin/package.json +1 -1
  131. package/examples/extensions/minimal-mode.ts +24 -96
  132. package/examples/extensions/sandbox/package-lock.json +2 -2
  133. package/examples/extensions/sandbox/package.json +1 -1
  134. package/examples/extensions/with-deps/package-lock.json +2 -2
  135. package/examples/extensions/with-deps/package.json +1 -1
  136. package/examples/sdk/14-codemode-mcp.ts +2 -2
  137. package/npm-shrinkwrap.json +26 -26
  138. package/package.json +10 -10
  139. package/dist/bundle/chunks/anthropic-messages-A6EXUBG6.js +0 -6
  140. package/dist/bundle/chunks/chunk-GOPCREV2.js +0 -4
  141. package/dist/bundle/chunks/chunk-HSPCVFST.js +0 -2
  142. package/dist/bundle/chunks/chunk-XNGRGP62.js +0 -2
  143. package/dist/bundle/chunks/virtual-modules-CSWRO37N.js +0 -2
@@ -4,13 +4,9 @@
4
4
  * The core only validates and stores registrations. The MCP extension (built in, or another
5
5
  * extension that handles `mcp_servers_change`) connects them next to the servers from `mcp.json`.
6
6
  */
7
- const MCP_EXPOSURES = [
8
- "codemode",
9
- "codemode-deferred",
10
- "deferred",
11
- "direct",
12
- "hidden",
13
- ];
7
+ const MCP_EXPOSURES = ["codemode", "deferred", "direct", "hidden"];
8
+ /** Older exposure names, accepted in configs and replaced by their current name when validated. */
9
+ const MCP_EXPOSURE_ALIASES = { "codemode-deferred": "codemode" };
14
10
  const LOOPBACK_HOSTS = ["localhost", "127.0.0.1", "[::1]"];
15
11
  /** Whether a redirect URI can be served by pi's loopback callback server. */
16
12
  export function isLoopbackRedirectUri(value) {
@@ -20,6 +16,10 @@ export function isLoopbackRedirectUri(value) {
20
16
  return url.protocol === "http:" && LOOPBACK_HOSTS.includes(url.hostname) && url.search === "" && url.hash === "";
21
17
  }
22
18
  const SERVER_NAME = /^[A-Za-z0-9_-]+$/;
19
+ /** Namespace of a server's tools: `mcp__<server>` with `-` replaced by `_`, like the tool names. */
20
+ export function mcpNamespace(server) {
21
+ return `mcp__${server.replace(/-/g, "_")}`;
22
+ }
23
23
  function isRecord(value) {
24
24
  return typeof value === "object" && value !== null && !Array.isArray(value);
25
25
  }
@@ -51,11 +51,29 @@ function validateOAuth(value) {
51
51
  }
52
52
  if (value.scope !== undefined && typeof value.scope !== "string")
53
53
  return "oauth.scope must be a string";
54
+ if (value.clientName !== undefined && (typeof value.clientName !== "string" || !value.clientName.trim())) {
55
+ return "oauth.clientName must be a non-empty string";
56
+ }
54
57
  return undefined;
55
58
  }
56
59
  function isExposure(value) {
57
60
  return typeof value === "string" && MCP_EXPOSURES.includes(value);
58
61
  }
62
+ /** The exposure an alias stands for; other values are returned unchanged. */
63
+ function resolveExposureAlias(value) {
64
+ return typeof value === "string" ? (MCP_EXPOSURE_ALIASES[value] ?? value) : value;
65
+ }
66
+ /** A copy of the server entry with exposure aliases replaced by their current names. */
67
+ function resolveExposureAliases(value) {
68
+ const { exposure, toolExposure } = value;
69
+ const resolved = { ...value };
70
+ if (exposure !== undefined)
71
+ resolved.exposure = resolveExposureAlias(exposure);
72
+ if (isRecord(toolExposure)) {
73
+ resolved.toolExposure = Object.fromEntries(Object.entries(toolExposure).map(([tool, entry]) => [tool, resolveExposureAlias(entry)]));
74
+ }
75
+ return resolved;
76
+ }
59
77
  function toolPatternRegExp(pattern) {
60
78
  const source = pattern
61
79
  .split("*")
@@ -75,13 +93,17 @@ export function getMcpToolExposure(config, toolName) {
75
93
  }
76
94
  return config.exposure ?? "codemode";
77
95
  }
78
- /** Validate one server entry of the `mcpServers` shape. Returns the config or an error message. */
79
- export function validateMcpServerConfig(name, value) {
96
+ /**
97
+ * Validate one server entry of the `mcpServers` shape. Returns a copy of the config with exposure
98
+ * aliases resolved, or an error message.
99
+ */
100
+ export function validateMcpServerConfig(name, raw) {
80
101
  if (!SERVER_NAME.test(name))
81
102
  return `invalid server name "${name}" (use letters, digits, "_" and "-")`;
82
- if (!isRecord(value))
103
+ if (!isRecord(raw))
83
104
  return `server "${name}" must be an object`;
84
- const { type, exposure, enabled, timeout, toolExposure } = value;
105
+ const value = resolveExposureAliases(raw);
106
+ const { type, exposure, enabled, timeout, toolExposure, description } = value;
85
107
  const exposures = MCP_EXPOSURES.map((value) => `"${value}"`).join(", ");
86
108
  if (exposure !== undefined && !isExposure(exposure)) {
87
109
  return `server "${name}": exposure must be one of ${exposures}`;
@@ -96,6 +118,9 @@ export function validateMcpServerConfig(name, value) {
96
118
  }
97
119
  if (enabled !== undefined && typeof enabled !== "boolean")
98
120
  return `server "${name}": enabled must be a boolean`;
121
+ if (description !== undefined && typeof description !== "string") {
122
+ return `server "${name}": description must be a string`;
123
+ }
99
124
  if (timeout !== undefined && (typeof timeout !== "number" || !(timeout > 0))) {
100
125
  return `server "${name}": timeout must be a positive number of seconds`;
101
126
  }
@@ -111,6 +136,15 @@ export function validateMcpServerConfig(name, value) {
111
136
  const oauthError = validateOAuth(value.oauth);
112
137
  if (oauthError)
113
138
  return `server "${name}": ${oauthError}`;
139
+ if (value.auth !== undefined) {
140
+ if (!isRecord(value.auth) || typeof value.auth.provider !== "string" || !value.auth.provider) {
141
+ return `server "${name}": auth.provider must be a provider name`;
142
+ }
143
+ const url = new URL(value.url);
144
+ if (url.protocol !== "https:" && !LOOPBACK_HOSTS.includes(url.hostname)) {
145
+ return `server "${name}": auth requires an https URL, or http on localhost, 127.0.0.1, or [::1]`;
146
+ }
147
+ }
114
148
  return value;
115
149
  }
116
150
  if (typeof value.command === "string" && (type === undefined || type === "stdio")) {
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-servers.js","sour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AQ,CAAC,MAA2B;QACnC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,iGAAiG;IACjG,UAAU,CAAC,IAAY,EAAE,aAAqB;QAC7C,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,aAAa,KAAK,aAAa;YAAE,OAAO;QACpE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,GAAG,CAAC,IAAY;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,+DAA+D;IAC/D,IAAI;QACH,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5G,CAAC;IAED,iGAAiG;IACjG,iBAAiB,CAAC,QAAkC;QACnD,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;IAChC,CAAC;CACD","sourcesContent":["/**\n * MCP server configuration and the servers extensions register with `pi.registerMcpServer()`.\n *\n * The core only validates and stores registrations. The MCP extension (built in, or another\n * extension that handles `mcp_servers_change`) connects them next to the servers from `mcp.json`.\n */\n\n/**\n * - `codemode`: tools are callable from codemode scripts and listed in its description, but not\n * declared to the model.\n * - `codemode-deferred`: like `codemode`, but not listed in the codemode description. Scripts find\n * them with `searchTools()`.\n * - `deferred`: not declared to the model until the `tool_search` tool loads them; the model then\n * calls them directly. Does not need codemode.\n * - `direct`: tools are declared to the model like any other tool (and callable from codemode).\n * - `hidden`: tools are registered but unreachable.\n */\nexport type McpExposure = \"codemode\" | \"codemode-deferred\" | \"deferred\" | \"direct\" | \"hidden\";\n\nconst MCP_EXPOSURES: readonly string[] = [\n\t\"codemode\",\n\t\"codemode-deferred\",\n\t\"deferred\",\n\t\"direct\",\n\t\"hidden\",\n] satisfies McpExposure[];\n\ninterface McpServerConfigBase {\n\t/** Default: `codemode`. */\n\texposure?: McpExposure;\n\t/**\n\t * Exposure of single tools, overriding `exposure`. Keys are tool names as the server offers them,\n\t * or patterns where `*` matches any characters. An exact name wins over patterns; among patterns\n\t * the first match in the object wins. `hidden` removes tools, so `\"exposure\": \"hidden\"` with\n\t * overrides for a few tools exposes only those.\n\t */\n\ttoolExposure?: Record<string, McpExposure>;\n\t/** Set to false to keep the entry without connecting. Default: true. */\n\tenabled?: boolean;\n\t/** Per-request timeout in seconds. Progress notifications from the server reset it. Default: 60. */\n\ttimeout?: number;\n}\n\nexport interface McpStdioServerConfig extends McpServerConfigBase {\n\ttype?: \"stdio\";\n\tcommand: string;\n\targs?: string[];\n\t/** Values may reference environment variables (`${NAME}`) or commands (`!cmd`). */\n\tenv?: Record<string, string>;\n\t/** Relative paths resolve against the session working directory. */\n\tcwd?: string;\n}\n\n/** OAuth client settings for servers that do not support dynamic client registration. */\nexport interface McpOAuthConfig {\n\t/** Pre-registered client id. Without it, pi registers a client with the authorization server. */\n\tclientId?: string;\n\t/** May reference environment variables (`${NAME}`) or commands (`!cmd`). */\n\tclientSecret?: string;\n\t/**\n\t * Port of the loopback callback server, for clients registered with a fixed redirect URI. Without\n\t * `callbackUrl`, the redirect URI is `http://127.0.0.1:<port>/callback`.\n\t */\n\tcallbackPort?: number;\n\t/**\n\t * Redirect URI registered for `clientId`, for example `http://localhost:8080/oauth/callback`. It must\n\t * be an `http` URI on `localhost`, `127.0.0.1`, or `[::1]`. Without a port, the callback server\n\t * listens on `callbackPort` or a free port, which is added to the URI (RFC 8252).\n\t */\n\tcallbackUrl?: string;\n\t/** Scopes to request, separated by spaces. Default: the scopes the server advertises. */\n\tscope?: string;\n}\n\nconst LOOPBACK_HOSTS = [\"localhost\", \"127.0.0.1\", \"[::1]\"];\n\n/** Whether a redirect URI can be served by pi's loopback callback server. */\nexport function isLoopbackRedirectUri(value: string): boolean {\n\tif (!URL.canParse(value)) return false;\n\tconst url = new URL(value);\n\treturn url.protocol === \"http:\" && LOOPBACK_HOSTS.includes(url.hostname) && url.search === \"\" && url.hash === \"\";\n}\n\nexport interface McpHttpServerConfig extends McpServerConfigBase {\n\ttype?: \"http\";\n\turl: string;\n\t/** Values may reference environment variables (`${NAME}`) or commands (`!cmd`). */\n\theaders?: Record<string, string>;\n\toauth?: McpOAuthConfig;\n}\n\nexport type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;\n\nconst SERVER_NAME = /^[A-Za-z0-9_-]+$/;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n\treturn isRecord(value) && Object.values(value).every((entry) => typeof entry === \"string\");\n}\n\nfunction validateOAuth(value: unknown): string | undefined {\n\tif (value === undefined) return undefined;\n\tif (!isRecord(value)) return \"oauth must be an object\";\n\tif (value.clientId !== undefined && typeof value.clientId !== \"string\") return \"oauth.clientId must be a string\";\n\tif (value.clientSecret !== undefined && typeof value.clientSecret !== \"string\") {\n\t\treturn \"oauth.clientSecret must be a string\";\n\t}\n\tconst port = value.callbackPort;\n\tif (port !== undefined && (typeof port !== \"number\" || !Number.isInteger(port) || port < 1 || port > 65535)) {\n\t\treturn \"oauth.callbackPort must be a port number\";\n\t}\n\tif (value.callbackUrl !== undefined) {\n\t\tif (typeof value.callbackUrl !== \"string\" || !isLoopbackRedirectUri(value.callbackUrl)) {\n\t\t\treturn \"oauth.callbackUrl must be an http URI on localhost, 127.0.0.1, or [::1] without query or fragment\";\n\t\t}\n\t\tconst urlPort = new URL(value.callbackUrl).port;\n\t\tif (urlPort && port !== undefined && Number(urlPort) !== port) {\n\t\t\treturn \"oauth.callbackUrl and oauth.callbackPort name different ports\";\n\t\t}\n\t}\n\tif (value.scope !== undefined && typeof value.scope !== \"string\") return \"oauth.scope must be a string\";\n\treturn undefined;\n}\n\nfunction isExposure(value: unknown): value is McpExposure {\n\treturn typeof value === \"string\" && MCP_EXPOSURES.includes(value);\n}\n\nfunction toolPatternRegExp(pattern: string): RegExp {\n\tconst source = pattern\n\t\t.split(\"*\")\n\t\t.map((part) => part.replace(/[.+?^${}()|[\\]\\\\]/g, \"\\\\$&\"))\n\t\t.join(\".*\");\n\treturn new RegExp(`^${source}$`);\n}\n\n/** Exposure of one tool of a server: its `toolExposure` entry, else the server's `exposure`. */\nexport function getMcpToolExposure(config: McpServerConfig, toolName: string): McpExposure {\n\tconst overrides = config.toolExposure ?? {};\n\tconst exact = overrides[toolName];\n\tif (exact !== undefined) return exact;\n\tfor (const [pattern, exposure] of Object.entries(overrides)) {\n\t\tif (pattern.includes(\"*\") && toolPatternRegExp(pattern).test(toolName)) return exposure;\n\t}\n\treturn config.exposure ?? \"codemode\";\n}\n\n/** Validate one server entry of the `mcpServers` shape. Returns the config or an error message. */\nexport function validateMcpServerConfig(name: string, value: unknown): McpServerConfig | string {\n\tif (!SERVER_NAME.test(name)) return `invalid server name \"${name}\" (use letters, digits, \"_\" and \"-\")`;\n\tif (!isRecord(value)) return `server \"${name}\" must be an object`;\n\tconst { type, exposure, enabled, timeout, toolExposure } = value;\n\tconst exposures = MCP_EXPOSURES.map((value) => `\"${value}\"`).join(\", \");\n\tif (exposure !== undefined && !isExposure(exposure)) {\n\t\treturn `server \"${name}\": exposure must be one of ${exposures}`;\n\t}\n\tif (toolExposure !== undefined) {\n\t\tif (!isRecord(toolExposure)) return `server \"${name}\": toolExposure must map tool names to exposures`;\n\t\tfor (const [tool, value] of Object.entries(toolExposure)) {\n\t\t\tif (!isExposure(value)) return `server \"${name}\": toolExposure \"${tool}\" must be one of ${exposures}`;\n\t\t}\n\t}\n\tif (enabled !== undefined && typeof enabled !== \"boolean\") return `server \"${name}\": enabled must be a boolean`;\n\tif (timeout !== undefined && (typeof timeout !== \"number\" || !(timeout > 0))) {\n\t\treturn `server \"${name}\": timeout must be a positive number of seconds`;\n\t}\n\tif (type === \"sse\") return `server \"${name}\": legacy SSE transport is not supported; use the streamable HTTP URL`;\n\n\tif (typeof value.url === \"string\" && (type === undefined || type === \"http\" || type === \"streamable-http\")) {\n\t\tif (!URL.canParse(value.url) || !/^https?:$/.test(new URL(value.url).protocol)) {\n\t\t\treturn `server \"${name}\": url must be an http or https URL`;\n\t\t}\n\t\tif (value.headers !== undefined && !isStringRecord(value.headers)) {\n\t\t\treturn `server \"${name}\": headers must map names to strings`;\n\t\t}\n\t\tconst oauthError = validateOAuth(value.oauth);\n\t\tif (oauthError) return `server \"${name}\": ${oauthError}`;\n\t\treturn value as unknown as McpHttpServerConfig;\n\t}\n\tif (typeof value.command === \"string\" && (type === undefined || type === \"stdio\")) {\n\t\tif (\n\t\t\tvalue.args !== undefined &&\n\t\t\t!(Array.isArray(value.args) && value.args.every((arg) => typeof arg === \"string\"))\n\t\t) {\n\t\t\treturn `server \"${name}\": args must be an array of strings`;\n\t\t}\n\t\tif (value.env !== undefined && !isStringRecord(value.env))\n\t\t\treturn `server \"${name}\": env must map names to strings`;\n\t\tif (value.cwd !== undefined && typeof value.cwd !== \"string\") return `server \"${name}\": cwd must be a string`;\n\t\treturn value as unknown as McpStdioServerConfig;\n\t}\n\treturn `server \"${name}\" needs either \"command\" (stdio) or \"url\" (streamable HTTP)`;\n}\n\n/** A server an extension registered with `pi.registerMcpServer()`. */\nexport interface RegisteredMcpServer {\n\tname: string;\n\tconfig: McpServerConfig;\n\t/** Path of the extension that registered the server. */\n\textensionPath: string;\n}\n\n/** Servers registered by the extensions of one runtime. */\nexport class McpServerRegistry {\n\tprivate readonly servers = new Map<string, RegisteredMcpServer>();\n\tprivate changeListener: (() => void) | undefined;\n\n\t/** Register or replace a server. The caller checks ownership. */\n\tregister(server: RegisteredMcpServer): void {\n\t\tthis.servers.set(server.name, server);\n\t\tthis.changeListener?.();\n\t}\n\n\t/** Remove a server registered by `extensionPath`. Servers of other extensions are left alone. */\n\tunregister(name: string, extensionPath: string): void {\n\t\tif (this.servers.get(name)?.extensionPath !== extensionPath) return;\n\t\tthis.servers.delete(name);\n\t\tthis.changeListener?.();\n\t}\n\n\tget(name: string): RegisteredMcpServer | undefined {\n\t\treturn this.servers.get(name);\n\t}\n\n\t/** Copies of the registered servers, in registration order. */\n\tlist(): RegisteredMcpServer[] {\n\t\treturn [...this.servers.values()].map((server) => ({ ...server, config: structuredClone(server.config) }));\n\t}\n\n\t/** Called after every change. The runner sets it when it binds, to emit `mcp_servers_change`. */\n\tsetChangeListener(listener: (() => void) | undefined): void {\n\t\tthis.changeListener = listener;\n\t}\n}\n"]}
1
+ {"version":3,"file":"mcp-servers.js","sourceRoot":"","sources":["../../src/core/mcp-servers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,MAAM,aAAa,GAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAyB,CAAC;AAE9G,mGAAmG;AACnG,MAAM,oBAAoB,GAA0C,EAAE,mBAAmB,EAAE,UAAU,EAAE,CAAC;AA2DxG,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AAE3D,6EAA6E;AAC7E,MAAM,UAAU,qBAAqB,CAAC,KAAa;IAClD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3B,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,IAAI,GAAG,CAAC,I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CAA2B;IAEjD,iEAAiE;IACjE,QAAQ,CAAC,MAA2B;QACnC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,iGAAiG;IACjG,UAAU,CAAC,IAAY,EAAE,aAAqB;QAC7C,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,aAAa,KAAK,aAAa;YAAE,OAAO;QACpE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,GAAG,CAAC,IAAY;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,+DAA+D;IAC/D,IAAI;QACH,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5G,CAAC;IAED,iGAAiG;IACjG,iBAAiB,CAAC,QAAkC;QACnD,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;IAChC,CAAC;CACD","sourcesContent":["/**\n * MCP server configuration and the servers extensions register with `pi.registerMcpServer()`.\n *\n * The core only validates and stores registrations. The MCP extension (built in, or another\n * extension that handles `mcp_servers_change`) connects them next to the servers from `mcp.json`.\n */\n\n/**\n * - `codemode`: tools are callable from codemode scripts but neither declared to the model nor\n * listed in the codemode description, which lists only the server's namespace. Scripts find them\n * with `searchTools()`. `codemode-deferred` is accepted as an alias.\n * - `deferred`: not declared to the model until the `tool_search` tool loads them; the model then\n * calls them directly. Does not need codemode.\n * - `direct`: tools are declared to the model like any other tool (and callable from codemode).\n * - `hidden`: tools are registered but unreachable.\n */\nexport type McpExposure = \"codemode\" | \"deferred\" | \"direct\" | \"hidden\";\n\nconst MCP_EXPOSURES: readonly string[] = [\"codemode\", \"deferred\", \"direct\", \"hidden\"] satisfies McpExposure[];\n\n/** Older exposure names, accepted in configs and replaced by their current name when validated. */\nconst MCP_EXPOSURE_ALIASES: Readonly<Record<string, McpExposure>> = { \"codemode-deferred\": \"codemode\" };\n\ninterface McpServerConfigBase {\n\t/** Default: `codemode`. */\n\texposure?: McpExposure;\n\t/**\n\t * What the server offers, in a sentence. The `mcp_servers` system prompt section lists the server\n\t * with it, tool search ranks the server's tools by it, and codemode's `describeNamespace()` returns it.\n\t */\n\tdescription?: string;\n\t/**\n\t * Exposure of single tools, overriding `exposure`. Keys are tool names as the server offers them,\n\t * or patterns where `*` matches any characters. An exact name wins over patterns; among patterns\n\t * the first match in the object wins. `hidden` removes tools, so `\"exposure\": \"hidden\"` with\n\t * overrides for a few tools exposes only those.\n\t */\n\ttoolExposure?: Record<string, McpExposure>;\n\t/** Set to false to keep the entry without connecting. Default: true. */\n\tenabled?: boolean;\n\t/** Per-request timeout in seconds. Progress notifications from the server reset it. Default: 60. */\n\ttimeout?: number;\n}\n\nexport interface McpStdioServerConfig extends McpServerConfigBase {\n\ttype?: \"stdio\";\n\tcommand: string;\n\targs?: string[];\n\t/** Values may reference environment variables (`${NAME}`) or commands (`!cmd`). */\n\tenv?: Record<string, string>;\n\t/** Relative paths resolve against the session working directory. */\n\tcwd?: string;\n}\n\n/** OAuth client settings for servers that do not support dynamic client registration. */\nexport interface McpOAuthConfig {\n\t/** Pre-registered client id. Without it, pi registers a client with the authorization server. */\n\tclientId?: string;\n\t/** May reference environment variables (`${NAME}`) or commands (`!cmd`). */\n\tclientSecret?: string;\n\t/**\n\t * Port of the loopback callback server, for clients registered with a fixed redirect URI. Without\n\t * `callbackUrl`, the redirect URI is `http://127.0.0.1:<port>/callback`.\n\t */\n\tcallbackPort?: number;\n\t/**\n\t * Redirect URI registered for `clientId`, for example `http://localhost:8080/oauth/callback`. It must\n\t * be an `http` URI on `localhost`, `127.0.0.1`, or `[::1]`. Without a port, the callback server\n\t * listens on `callbackPort` or a free port, which is added to the URI (RFC 8252).\n\t */\n\tcallbackUrl?: string;\n\t/** Scopes to request, separated by spaces. Default: the scopes the server advertises. */\n\tscope?: string;\n\t/**\n\t * `client_name` sent with dynamic client registration, for servers that only accept known clients.\n\t * Default: `pi`.\n\t */\n\tclientName?: string;\n}\n\nconst LOOPBACK_HOSTS = [\"localhost\", \"127.0.0.1\", \"[::1]\"];\n\n/** Whether a redirect URI can be served by pi's loopback callback server. */\nexport function isLoopbackRedirectUri(value: string): boolean {\n\tif (!URL.canParse(value)) return false;\n\tconst url = new URL(value);\n\treturn url.protocol === \"http:\" && LOOPBACK_HOSTS.includes(url.hostname) && url.search === \"\" && url.hash === \"\";\n}\n\nexport interface McpHttpServerConfig extends McpServerConfigBase {\n\ttype?: \"http\";\n\turl: string;\n\t/** Values may reference environment variables (`${NAME}`) or commands (`!cmd`). */\n\theaders?: Record<string, string>;\n\toauth?: McpOAuthConfig;\n\t/**\n\t * Send the token of a pi provider (`/login <provider>`) instead of using OAuth. Not allowed in project\n\t * `mcp.json` files, and requires https except on loopback hosts, since it sends the credential to `url`.\n\t */\n\tauth?: { provider: string };\n}\n\nexport type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;\n\nconst SERVER_NAME = /^[A-Za-z0-9_-]+$/;\n\n/** Namespace of a server's tools: `mcp__<server>` with `-` replaced by `_`, like the tool names. */\nexport function mcpNamespace(server: string): string {\n\treturn `mcp__${server.replace(/-/g, \"_\")}`;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n\treturn isRecord(value) && Object.values(value).every((entry) => typeof entry === \"string\");\n}\n\nfunction validateOAuth(value: unknown): string | undefined {\n\tif (value === undefined) return undefined;\n\tif (!isRecord(value)) return \"oauth must be an object\";\n\tif (value.clientId !== undefined && typeof value.clientId !== \"string\") return \"oauth.clientId must be a string\";\n\tif (value.clientSecret !== undefined && typeof value.clientSecret !== \"string\") {\n\t\treturn \"oauth.clientSecret must be a string\";\n\t}\n\tconst port = value.callbackPort;\n\tif (port !== undefined && (typeof port !== \"number\" || !Number.isInteger(port) || port < 1 || port > 65535)) {\n\t\treturn \"oauth.callbackPort must be a port number\";\n\t}\n\tif (value.callbackUrl !== undefined) {\n\t\tif (typeof value.callbackUrl !== \"string\" || !isLoopbackRedirectUri(value.callbackUrl)) {\n\t\t\treturn \"oauth.callbackUrl must be an http URI on localhost, 127.0.0.1, or [::1] without query or fragment\";\n\t\t}\n\t\tconst urlPort = new URL(value.callbackUrl).port;\n\t\tif (urlPort && port !== undefined && Number(urlPort) !== port) {\n\t\t\treturn \"oauth.callbackUrl and oauth.callbackPort name different ports\";\n\t\t}\n\t}\n\tif (value.scope !== undefined && typeof value.scope !== \"string\") return \"oauth.scope must be a string\";\n\tif (value.clientName !== undefined && (typeof value.clientName !== \"string\" || !value.clientName.trim())) {\n\t\treturn \"oauth.clientName must be a non-empty string\";\n\t}\n\treturn undefined;\n}\n\nfunction isExposure(value: unknown): value is McpExposure {\n\treturn typeof value === \"string\" && MCP_EXPOSURES.includes(value);\n}\n\n/** The exposure an alias stands for; other values are returned unchanged. */\nfunction resolveExposureAlias(value: unknown): unknown {\n\treturn typeof value === \"string\" ? (MCP_EXPOSURE_ALIASES[value] ?? value) : value;\n}\n\n/** A copy of the server entry with exposure aliases replaced by their current names. */\nfunction resolveExposureAliases(value: Record<string, unknown>): Record<string, unknown> {\n\tconst { exposure, toolExposure } = value;\n\tconst resolved: Record<string, unknown> = { ...value };\n\tif (exposure !== undefined) resolved.exposure = resolveExposureAlias(exposure);\n\tif (isRecord(toolExposure)) {\n\t\tresolved.toolExposure = Object.fromEntries(\n\t\t\tObject.entries(toolExposure).map(([tool, entry]) => [tool, resolveExposureAlias(entry)]),\n\t\t);\n\t}\n\treturn resolved;\n}\n\nfunction toolPatternRegExp(pattern: string): RegExp {\n\tconst source = pattern\n\t\t.split(\"*\")\n\t\t.map((part) => part.replace(/[.+?^${}()|[\\]\\\\]/g, \"\\\\$&\"))\n\t\t.join(\".*\");\n\treturn new RegExp(`^${source}$`);\n}\n\n/** Exposure of one tool of a server: its `toolExposure` entry, else the server's `exposure`. */\nexport function getMcpToolExposure(config: McpServerConfig, toolName: string): McpExposure {\n\tconst overrides = config.toolExposure ?? {};\n\tconst exact = overrides[toolName];\n\tif (exact !== undefined) return exact;\n\tfor (const [pattern, exposure] of Object.entries(overrides)) {\n\t\tif (pattern.includes(\"*\") && toolPatternRegExp(pattern).test(toolName)) return exposure;\n\t}\n\treturn config.exposure ?? \"codemode\";\n}\n\n/**\n * Validate one server entry of the `mcpServers` shape. Returns a copy of the config with exposure\n * aliases resolved, or an error message.\n */\nexport function validateMcpServerConfig(name: string, raw: unknown): McpServerConfig | string {\n\tif (!SERVER_NAME.test(name)) return `invalid server name \"${name}\" (use letters, digits, \"_\" and \"-\")`;\n\tif (!isRecord(raw)) return `server \"${name}\" must be an object`;\n\tconst value = resolveExposureAliases(raw);\n\tconst { type, exposure, enabled, timeout, toolExposure, description } = value;\n\tconst exposures = MCP_EXPOSURES.map((value) => `\"${value}\"`).join(\", \");\n\tif (exposure !== undefined && !isExposure(exposure)) {\n\t\treturn `server \"${name}\": exposure must be one of ${exposures}`;\n\t}\n\tif (toolExposure !== undefined) {\n\t\tif (!isRecord(toolExposure)) return `server \"${name}\": toolExposure must map tool names to exposures`;\n\t\tfor (const [tool, value] of Object.entries(toolExposure)) {\n\t\t\tif (!isExposure(value)) return `server \"${name}\": toolExposure \"${tool}\" must be one of ${exposures}`;\n\t\t}\n\t}\n\tif (enabled !== undefined && typeof enabled !== \"boolean\") return `server \"${name}\": enabled must be a boolean`;\n\tif (description !== undefined && typeof description !== \"string\") {\n\t\treturn `server \"${name}\": description must be a string`;\n\t}\n\tif (timeout !== undefined && (typeof timeout !== \"number\" || !(timeout > 0))) {\n\t\treturn `server \"${name}\": timeout must be a positive number of seconds`;\n\t}\n\tif (type === \"sse\") return `server \"${name}\": legacy SSE transport is not supported; use the streamable HTTP URL`;\n\n\tif (typeof value.url === \"string\" && (type === undefined || type === \"http\" || type === \"streamable-http\")) {\n\t\tif (!URL.canParse(value.url) || !/^https?:$/.test(new URL(value.url).protocol)) {\n\t\t\treturn `server \"${name}\": url must be an http or https URL`;\n\t\t}\n\t\tif (value.headers !== undefined && !isStringRecord(value.headers)) {\n\t\t\treturn `server \"${name}\": headers must map names to strings`;\n\t\t}\n\t\tconst oauthError = validateOAuth(value.oauth);\n\t\tif (oauthError) return `server \"${name}\": ${oauthError}`;\n\t\tif (value.auth !== undefined) {\n\t\t\tif (!isRecord(value.auth) || typeof value.auth.provider !== \"string\" || !value.auth.provider) {\n\t\t\t\treturn `server \"${name}\": auth.provider must be a provider name`;\n\t\t\t}\n\t\t\tconst url = new URL(value.url);\n\t\t\tif (url.protocol !== \"https:\" && !LOOPBACK_HOSTS.includes(url.hostname)) {\n\t\t\t\treturn `server \"${name}\": auth requires an https URL, or http on localhost, 127.0.0.1, or [::1]`;\n\t\t\t}\n\t\t}\n\t\treturn value as unknown as McpHttpServerConfig;\n\t}\n\tif (typeof value.command === \"string\" && (type === undefined || type === \"stdio\")) {\n\t\tif (\n\t\t\tvalue.args !== undefined &&\n\t\t\t!(Array.isArray(value.args) && value.args.every((arg) => typeof arg === \"string\"))\n\t\t) {\n\t\t\treturn `server \"${name}\": args must be an array of strings`;\n\t\t}\n\t\tif (value.env !== undefined && !isStringRecord(value.env))\n\t\t\treturn `server \"${name}\": env must map names to strings`;\n\t\tif (value.cwd !== undefined && typeof value.cwd !== \"string\") return `server \"${name}\": cwd must be a string`;\n\t\treturn value as unknown as McpStdioServerConfig;\n\t}\n\treturn `server \"${name}\" needs either \"command\" (stdio) or \"url\" (streamable HTTP)`;\n}\n\n/** A server an extension registered with `pi.registerMcpServer()`. */\nexport interface RegisteredMcpServer {\n\tname: string;\n\tconfig: McpServerConfig;\n\t/** Path of the extension that registered the server. */\n\textensionPath: string;\n}\n\n/** Servers registered by the extensions of one runtime. */\nexport class McpServerRegistry {\n\tprivate readonly servers = new Map<string, RegisteredMcpServer>();\n\tprivate changeListener: (() => void) | undefined;\n\n\t/** Register or replace a server. The caller checks ownership. */\n\tregister(server: RegisteredMcpServer): void {\n\t\tthis.servers.set(server.name, server);\n\t\tthis.changeListener?.();\n\t}\n\n\t/** Remove a server registered by `extensionPath`. Servers of other extensions are left alone. */\n\tunregister(name: string, extensionPath: string): void {\n\t\tif (this.servers.get(name)?.extensionPath !== extensionPath) return;\n\t\tthis.servers.delete(name);\n\t\tthis.changeListener?.();\n\t}\n\n\tget(name: string): RegisteredMcpServer | undefined {\n\t\treturn this.servers.get(name);\n\t}\n\n\t/** Copies of the registered servers, in registration order. */\n\tlist(): RegisteredMcpServer[] {\n\t\treturn [...this.servers.values()].map((server) => ({ ...server, config: structuredClone(server.config) }));\n\t}\n\n\t/** Called after every change. The runner sets it when it binds, to emit `mcp_servers_change`. */\n\tsetChangeListener(listener: (() => void) | undefined): void {\n\t\tthis.changeListener = listener;\n\t}\n}\n"]}
@@ -108,6 +108,12 @@ export declare class ModelRuntime implements Models {
108
108
  logout(providerId: string, options?: AuthOperationOptions): Promise<void>;
109
109
  refresh(options?: ModelsRefreshOptions): Promise<ModelsRefreshResult>;
110
110
  registerNativeProvider(provider: Provider): void;
111
+ /**
112
+ * Mark a newly registered provider as configured when it has a stored credential or a configured
113
+ * API key. Availability checks run asynchronously, and callers such as initial model selection
114
+ * read the snapshot before they finish. The next availability pass replaces this entry.
115
+ */
116
+ private markProvisionallyConfigured;
111
117
  registerProvider(providerId: string, config: ProviderConfigInput): void;
112
118
  unregisterProvider(providerId: string): void;
113
119
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"model-runtime.d.ts","sour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,UAAU,EAAE,sBAAsB,GAAG,IAAI,CAmB7D;IAED,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAO3D;IAED;;;;;;;;OAQG;IACG,YAAY,CACjB,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,OAAO,EAAE;QACR,MAAM,EAAE,gBAAgB,CAAC;QACzB,aAAa,EAAE,kBAAkB,CAAC;QAClC,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,MAAM,CAAC,EAAE,gBAAgB,CAAC;QAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;KAChB,GACC,OAAO,CAAC,UAAU,CAAC,CAqBrB;IAED,gDAAgD;IAChD,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAG5E;CACD"}
@@ -630,8 +630,29 @@ export class ModelRuntime {
630
630
  this.nativeExtensionProviders.set(provider.id, provider);
631
631
  this.recomposeProvider(provider.id);
632
632
  this.updateModelSnapshot();
633
+ this.markProvisionallyConfigured(provider.id, configuredRequestAuthStatus(this.config.getProvider(provider.id), undefined), provider.auth.oauth && !provider.auth.apiKey ? "oauth" : "api_key");
633
634
  void this.refresh({ allowNetwork: false });
634
635
  }
636
+ /**
637
+ * Mark a newly registered provider as configured when it has a stored credential or a configured
638
+ * API key. Availability checks run asynchronously, and callers such as initial model selection
639
+ * read the snapshot before they finish. The next availability pass replaces this entry.
640
+ */
641
+ markProvisionallyConfigured(providerId, configuredStatus, type) {
642
+ if (!this.snapshot.storedProviders.has(providerId) && !configuredStatus?.configured)
643
+ return;
644
+ const configuredProviders = new Set(this.snapshot.configuredProviders).add(providerId);
645
+ const auth = new Map(this.snapshot.auth);
646
+ // Never clobber a real check result.
647
+ if (!auth.get(providerId))
648
+ auth.set(providerId, { type, source: "configured provider" });
649
+ this.snapshot = {
650
+ ...this.snapshot,
651
+ auth,
652
+ configuredProviders,
653
+ available: this.snapshot.all.filter((model) => configuredProviders.has(model.provider)),
654
+ };
655
+ }
635
656
  registerProvider(providerId, config) {
636
657
  // Validate the incoming registration on its own, like the legacy registry:
637
658
  // a broken re-registration must throw without touching the stored config.
@@ -648,24 +669,7 @@ export class ModelRuntime {
648
669
  this.extensionProviders.set(providerId, effective);
649
670
  this.recomposeProvider(providerId);
650
671
  this.updateModelSnapshot();
651
- if (this.snapshot.storedProviders.has(providerId) ||
652
- configuredRequestAuthStatus(this.config.getProvider(providerId), effective)?.configured) {
653
- const configuredProviders = new Set(this.snapshot.configuredProviders).add(providerId);
654
- const auth = new Map(this.snapshot.auth);
655
- // Provisional entry until the async refresh lands; never clobber a real check result.
656
- if (!auth.get(providerId)) {
657
- auth.set(providerId, {
658
- type: effective.oauth && !effective.apiKey ? "oauth" : "api_key",
659
- source: "configured provider",
660
- });
661
- }
662
- this.snapshot = {
663
- ...this.snapshot,
664
- auth,
665
- configuredProviders,
666
- available: this.snapshot.all.filter((model) => configuredProviders.has(model.provider)),
667
- };
668
- }
672
+ this.markProvisionallyConfigured(providerId, configuredRequestAuthStatus(this.config.getProvider(providerId), effective), effective.oauth && !effective.apiKey ? "oauth" : "api_key");
669
673
  void this.refresh({ allowNetwork: false });
670
674
  }
671
675
  unregisterProvider(providerId) {