pi2dsh 0.5.0 → 0.6.1

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 (93) hide show
  1. package/README.md +42 -14
  2. package/README.zh.md +36 -14
  3. package/cordis.patch.yml +3 -0
  4. package/dist/cli.mjs +1 -1
  5. package/dist/compat/pi-ai.mjs +1 -1
  6. package/dist/compat/pi-coding-agent.mjs +1 -1
  7. package/dist/credentials-oauth.mjs +3 -3
  8. package/dist/host.mjs +2 -2
  9. package/dist/index.d.mts +30 -1
  10. package/dist/index.d.mts.map +1 -1
  11. package/dist/index.mjs +100 -2
  12. package/dist/index.mjs.map +1 -0
  13. package/dist/{mcp-config-ByUc0jmD.mjs → mcp-config-vU1LZ7fC.mjs} +4 -4
  14. package/dist/{mcp-config-ByUc0jmD.mjs.map → mcp-config-vU1LZ7fC.mjs.map} +1 -1
  15. package/dist/{oauth-bridge-C6fL1qSv.mjs → oauth-bridge-CfyImWx4.mjs} +2 -2
  16. package/dist/{oauth-bridge-C6fL1qSv.mjs.map → oauth-bridge-CfyImWx4.mjs.map} +1 -1
  17. package/dist/{pi-ai-B_88Wb0r.mjs → pi-ai-7HR3ciAs.mjs} +4 -42
  18. package/dist/{pi-ai-B_88Wb0r.mjs.map → pi-ai-7HR3ciAs.mjs.map} +1 -1
  19. package/dist/{pi-coding-agent-C9Y9ql5E.mjs → pi-coding-agent-CznNsOnV.mjs} +2 -2
  20. package/dist/{pi-coding-agent-C9Y9ql5E.mjs.map → pi-coding-agent-CznNsOnV.mjs.map} +1 -1
  21. package/dist/{runtime-VK4eVnYa.mjs → runtime-CPvg87et.mjs} +60 -20
  22. package/dist/runtime-CPvg87et.mjs.map +1 -0
  23. package/dist/runtime.d.mts +8 -1
  24. package/dist/runtime.d.mts.map +1 -1
  25. package/dist/runtime.mjs +2 -2
  26. package/package.json +9 -2
  27. package/dist/all-DSpxKvHa.mjs +0 -28512
  28. package/dist/all-DSpxKvHa.mjs.map +0 -1
  29. package/dist/anthropic-messages-BL9N1Idv.mjs +0 -6438
  30. package/dist/anthropic-messages-BL9N1Idv.mjs.map +0 -1
  31. package/dist/azure-openai-responses-A67VbaZ1.mjs +0 -209
  32. package/dist/azure-openai-responses-A67VbaZ1.mjs.map +0 -1
  33. package/dist/deferred-tools-BD4g5QUx.mjs +0 -32
  34. package/dist/deferred-tools-BD4g5QUx.mjs.map +0 -1
  35. package/dist/diagnostics-CJye1UFh.mjs +0 -99
  36. package/dist/diagnostics-CJye1UFh.mjs.map +0 -1
  37. package/dist/dist-BYA74yh_.mjs +0 -1246
  38. package/dist/dist-BYA74yh_.mjs.map +0 -1
  39. package/dist/dist-DeonWo7m.mjs +0 -1089
  40. package/dist/dist-DeonWo7m.mjs.map +0 -1
  41. package/dist/error-body-DKA3lknR.mjs +0 -104
  42. package/dist/error-body-DKA3lknR.mjs.map +0 -1
  43. package/dist/github-copilot-headers-CZo2QHrt.mjs +0 -25
  44. package/dist/github-copilot-headers-CZo2QHrt.mjs.map +0 -1
  45. package/dist/google-generative-ai-DT5S8D8y.mjs +0 -358
  46. package/dist/google-generative-ai-DT5S8D8y.mjs.map +0 -1
  47. package/dist/google-shared-DYP_9cnK.mjs +0 -29042
  48. package/dist/google-shared-DYP_9cnK.mjs.map +0 -1
  49. package/dist/google-vertex-Dpq7O7Be.mjs +0 -402
  50. package/dist/google-vertex-Dpq7O7Be.mjs.map +0 -1
  51. package/dist/hash-Dbggamac.mjs +0 -19
  52. package/dist/hash-Dbggamac.mjs.map +0 -1
  53. package/dist/headers-CPzZhJQn.mjs +0 -17
  54. package/dist/headers-CPzZhJQn.mjs.map +0 -1
  55. package/dist/images-models-DJtHo9Rp.mjs +0 -1068
  56. package/dist/images-models-DJtHo9Rp.mjs.map +0 -1
  57. package/dist/json-parse-Dz5sKMTv.mjs +0 -384
  58. package/dist/json-parse-Dz5sKMTv.mjs.map +0 -1
  59. package/dist/mistral-conversations-BsxbCCWx.mjs +0 -42007
  60. package/dist/mistral-conversations-BsxbCCWx.mjs.map +0 -1
  61. package/dist/multipart-parser-woKCuALW.mjs +0 -301
  62. package/dist/multipart-parser-woKCuALW.mjs.map +0 -1
  63. package/dist/openai-DkzRh5_G.mjs +0 -6732
  64. package/dist/openai-DkzRh5_G.mjs.map +0 -1
  65. package/dist/openai-codex-responses-C7vviVT2.mjs +0 -1169
  66. package/dist/openai-codex-responses-C7vviVT2.mjs.map +0 -1
  67. package/dist/openai-completions-By8QNX1P.mjs +0 -947
  68. package/dist/openai-completions-By8QNX1P.mjs.map +0 -1
  69. package/dist/openai-prompt-cache-BDWtZRKh.mjs +0 -11
  70. package/dist/openai-prompt-cache-BDWtZRKh.mjs.map +0 -1
  71. package/dist/openai-responses-DboJUcFN.mjs +0 -247
  72. package/dist/openai-responses-DboJUcFN.mjs.map +0 -1
  73. package/dist/openai-responses-shared-BDzn7nJY.mjs +0 -572
  74. package/dist/openai-responses-shared-BDzn7nJY.mjs.map +0 -1
  75. package/dist/openrouter-images-fG3Aj6M4.mjs +0 -127
  76. package/dist/openrouter-images-fG3Aj6M4.mjs.map +0 -1
  77. package/dist/otel-PimLMoiV.mjs +0 -24935
  78. package/dist/otel-PimLMoiV.mjs.map +0 -1
  79. package/dist/pi-messages-B-7Xo_I0.mjs +0 -306
  80. package/dist/pi-messages-B-7Xo_I0.mjs.map +0 -1
  81. package/dist/provider-env-D-cCRWzv.mjs +0 -40
  82. package/dist/provider-env-D-cCRWzv.mjs.map +0 -1
  83. package/dist/provider-retry-Cw6YJ4cr.mjs +0 -80
  84. package/dist/provider-retry-Cw6YJ4cr.mjs.map +0 -1
  85. package/dist/runtime-VK4eVnYa.mjs.map +0 -1
  86. package/dist/sanitize-unicode-wLA11KvZ.mjs +0 -29
  87. package/dist/sanitize-unicode-wLA11KvZ.mjs.map +0 -1
  88. package/dist/src-BEl3QrGL.mjs +0 -5031
  89. package/dist/src-BEl3QrGL.mjs.map +0 -1
  90. package/dist/transform-messages-DGq9mvhA.mjs +0 -379
  91. package/dist/transform-messages-DGq9mvhA.mjs.map +0 -1
  92. package/dist/uuid-DtFT7tOE.mjs +0 -65
  93. package/dist/uuid-DtFT7tOE.mjs.map +0 -1
@@ -1,13 +1,13 @@
1
1
 
2
- import { C as realBuiltinProvider, R as AssistantMessageEventStream, S as openAIResponsesApi, a as builtinProviders, i as anthropicMessagesApi, r as __setPiAiLlmBridge, x as openAICompletionsApi } from "./pi-ai-B_88Wb0r.mjs";
2
+ import { C as realBuiltinProvider, R as AssistantMessageEventStream, S as openAIResponsesApi, a as builtinProviders, i as anthropicMessagesApi, r as __setPiAiLlmBridge, x as openAICompletionsApi } from "./pi-ai-7HR3ciAs.mjs";
3
3
  import { r as normalizePath, t as getAgentDir } from "./pi-config-shim-CZ1wFzqM.mjs";
4
- import { E as __setSubagentSessionFactory, S as Theme, f as ExtensionRunner } from "./pi-coding-agent-C9Y9ql5E.mjs";
5
- import { a as resolvePiProviderAuth, n as loginPiProvider, r as providerSupportsOAuth, t as FileCredentialStore } from "./oauth-bridge-C6fL1qSv.mjs";
4
+ import { E as __setSubagentSessionFactory, S as Theme, f as ExtensionRunner } from "./pi-coding-agent-CznNsOnV.mjs";
5
+ import { a as resolvePiProviderAuth, n as loginPiProvider, r as providerSupportsOAuth, t as FileCredentialStore } from "./oauth-bridge-CfyImWx4.mjs";
6
6
  import { createRequire } from "node:module";
7
7
  import { access, mkdir, readFile, writeFile } from "node:fs/promises";
8
+ import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
8
9
  import { join } from "node:path";
9
10
  import { fileURLToPath } from "node:url";
10
- import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
11
11
  import { tmpdir } from "node:os";
12
12
  import { EventEmitter } from "node:events";
13
13
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -2629,7 +2629,7 @@ function contextFor(ctx, state, agent, signal, command = false) {
2629
2629
  return provider.length > 0 && providerSupportsOAuth(providerConfig(provider));
2630
2630
  },
2631
2631
  refresh: async () => {
2632
- await reloadModelsJson(ctx, state);
2632
+ await reloadModelsJson(ctx, state, true);
2633
2633
  await catalog?.refresh();
2634
2634
  return {
2635
2635
  models: allModels(),
@@ -3167,11 +3167,45 @@ async function collectPiImages(ctx, messages) {
3167
3167
  return images;
3168
3168
  }
3169
3169
  function oauthStoreOf(state) {
3170
- state.oauthStore ??= new FileCredentialStore(join(getAgentDir(), "auth.json"));
3171
- return state.oauthStore;
3170
+ state.shared.oauthStore ??= new FileCredentialStore(join(getAgentDir(), "auth.json"));
3171
+ return state.shared.oauthStore;
3172
3172
  }
3173
3173
  const MODELS_JSON_ROUTE_PREFIX = "models.json/";
3174
- async function reloadModelsJson(ctx, state) {
3174
+ const SHARED_HOST_STATE = /* @__PURE__ */ new WeakMap();
3175
+ function sharedHostStateOf(ctx) {
3176
+ const key = ctx.root ?? ctx;
3177
+ let shared = SHARED_HOST_STATE.get(key);
3178
+ if (shared === void 0) {
3179
+ shared = {
3180
+ modelsJsonProviders: /* @__PURE__ */ new Map(),
3181
+ companionRoutes: /* @__PURE__ */ new Map(),
3182
+ providerRouteDisposers: /* @__PURE__ */ new Map(),
3183
+ providers: /* @__PURE__ */ new Map()
3184
+ };
3185
+ SHARED_HOST_STATE.set(key, shared);
3186
+ }
3187
+ return shared;
3188
+ }
3189
+ /**
3190
+ * Load models.json routes for a host with NO mounted Pi package yet — the
3191
+ * single-directory capability (custom providers + image-admission
3192
+ * companions in the DSH picker) is the bridge's own, not any plugin's.
3193
+ * A later package mount adopts the same shared snapshot.
3194
+ */
3195
+ async function ensureModelsJsonRoutes(ctx) {
3196
+ const shared = sharedHostStateOf(ctx);
3197
+ await reloadModelsJson(ctx, {
3198
+ shared,
3199
+ modelsJsonProviders: shared.modelsJsonProviders,
3200
+ companionRoutes: shared.companionRoutes,
3201
+ providerRouteDisposers: shared.providerRouteDisposers
3202
+ });
3203
+ }
3204
+ async function reloadModelsJson(ctx, state, force = false) {
3205
+ if (!force && state.shared.modelsJson !== void 0) {
3206
+ state.modelsJson = state.shared.modelsJson;
3207
+ return;
3208
+ }
3175
3209
  for (const [key, dispose] of state.providerRouteDisposers) {
3176
3210
  if (!key.startsWith(MODELS_JSON_ROUTE_PREFIX)) continue;
3177
3211
  state.providerRouteDisposers.delete(key);
@@ -3180,6 +3214,7 @@ async function reloadModelsJson(ctx, state) {
3180
3214
  state.modelsJsonProviders.clear();
3181
3215
  state.companionRoutes.clear();
3182
3216
  state.modelsJson = await loadModelsJsonSnapshot(realBuiltinProvider);
3217
+ state.shared.modelsJson = state.modelsJson;
3183
3218
  for (const problem of state.modelsJson.errors) logger(ctx).warn(`[pi2dsh] models.json: ${problem}`);
3184
3219
  for (const [providerId, providerConfig] of state.modelsJson.providers) {
3185
3220
  const models = state.modelsJson.models.filter((model) => model.provider === providerId);
@@ -3260,8 +3295,8 @@ async function materializeAttachmentImage(ctx, attachment) {
3260
3295
  }
3261
3296
  }
3262
3297
  function ensureLoginCommand(ctx, state) {
3263
- if (state.loginCommandRegistered === true) return;
3264
- state.loginCommandRegistered = true;
3298
+ if (state.shared.loginRegistered === true) return;
3299
+ state.shared.loginRegistered = true;
3265
3300
  try {
3266
3301
  registerLoginCommand(ctx, state);
3267
3302
  } catch (error) {
@@ -3829,7 +3864,9 @@ async function applyPiPackage(ctx, options) {
3829
3864
  origin: "package"
3830
3865
  }
3831
3866
  }));
3867
+ const shared = sharedHostStateOf(ctx);
3832
3868
  const state = {
3869
+ shared,
3833
3870
  handlers: /* @__PURE__ */ new Map(),
3834
3871
  tools: runtimeTools,
3835
3872
  runner: new ExtensionRunner(piToolRecords),
@@ -3837,8 +3874,8 @@ async function applyPiPackage(ctx, options) {
3837
3874
  toolRestrictions: /* @__PURE__ */ new WeakMap(),
3838
3875
  commands: /* @__PURE__ */ new Map(),
3839
3876
  commandDisposers: /* @__PURE__ */ new Map(),
3840
- modelsJsonProviders: /* @__PURE__ */ new Map(),
3841
- companionRoutes: /* @__PURE__ */ new Map(),
3877
+ modelsJsonProviders: shared.modelsJsonProviders,
3878
+ companionRoutes: shared.companionRoutes,
3842
3879
  flags: /* @__PURE__ */ new Map(),
3843
3880
  notifications: [],
3844
3881
  activeAgents: /* @__PURE__ */ new Set(),
@@ -3852,7 +3889,7 @@ async function applyPiPackage(ctx, options) {
3852
3889
  shortcuts: /* @__PURE__ */ new Map(),
3853
3890
  messageRenderers: /* @__PURE__ */ new Map(),
3854
3891
  entryRenderers: /* @__PURE__ */ new Map(),
3855
- providers: /* @__PURE__ */ new Map(),
3892
+ providers: shared.providers,
3856
3893
  autocompleteProviders: [],
3857
3894
  editorBuffers: /* @__PURE__ */ new WeakMap(),
3858
3895
  toolsExpanded: false,
@@ -3863,7 +3900,7 @@ async function applyPiPackage(ctx, options) {
3863
3900
  argMutations: /* @__PURE__ */ new WeakMap(),
3864
3901
  streamingTexts: /* @__PURE__ */ new Map(),
3865
3902
  lastLoggedModels: /* @__PURE__ */ new WeakMap(),
3866
- providerRouteDisposers: /* @__PURE__ */ new Map()
3903
+ providerRouteDisposers: shared.providerRouteDisposers
3867
3904
  };
3868
3905
  subscribeLifecycle(ctx, state);
3869
3906
  subscribeInterceptors(ctx, state);
@@ -3886,12 +3923,15 @@ async function applyPiPackage(ctx, options) {
3886
3923
  }
3887
3924
  }
3888
3925
  const llm = llmOf(ctx);
3889
- state.modelCatalog = new ModelCatalog(llm);
3926
+ state.modelCatalog = shared.modelCatalog ??= new ModelCatalog(llm);
3890
3927
  await reloadModelsJson(ctx, state);
3891
3928
  if (llm !== void 0) {
3892
- ctx.on("llm/adapters-updated", () => {
3893
- state.modelCatalog?.refresh();
3894
- });
3929
+ if (shared.catalogSubscribed !== true) {
3930
+ shared.catalogSubscribed = true;
3931
+ ctx.on("llm/adapters-updated", () => {
3932
+ shared.modelCatalog?.refresh();
3933
+ });
3934
+ }
3895
3935
  await state.modelCatalog.refresh();
3896
3936
  __setPiAiLlmBridge((model, context, callOptions) => streamViaDshLlm(llm, {
3897
3937
  model,
@@ -3931,6 +3971,6 @@ const runtimeInternals = {
3931
3971
  textBlocks
3932
3972
  };
3933
3973
  //#endregion
3934
- export { normalizeToolSchema as n, runtimeInternals as r, applyPiPackage as t };
3974
+ export { runtimeInternals as i, ensureModelsJsonRoutes as n, normalizeToolSchema as r, applyPiPackage as t };
3935
3975
 
3936
- //# sourceMappingURL=runtime-VK4eVnYa.mjs.map
3976
+ //# sourceMappingURL=runtime-CPvg87et.mjs.map