@junctionpanel/server 0.1.74 → 0.1.75

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.
@@ -9,6 +9,7 @@ import { z } from "zod";
9
9
  import { loadCodexPersistedTimeline } from "./codex-rollout-timeline.js";
10
10
  import { mapCodexRolloutToolCall, mapCodexToolCallFromThreadItem, } from "./codex/tool-call-mapper.js";
11
11
  import { applyProviderEnv, isProviderCommandAvailable, resolveProviderCommandPrefix, } from "../provider-launch-config.js";
12
+ import { getCachedProviderModels } from "../provider-model-cache.js";
12
13
  import { resolveCommandPathWithFallback } from "../../provider-command-resolution.js";
13
14
  import { buildCodexRuntimeExtra, DEFAULT_CODEX_MODE_ID, isCodexPlanModeEnabled, normalizeCodexModeId, setCodexPlanModeEnabled, } from "../codex-config.js";
14
15
  import { writeImageAttachment } from "./image-attachments.js";
@@ -4256,80 +4257,98 @@ export class CodexAppServerAgentClient {
4256
4257
  }
4257
4258
  }
4258
4259
  async listModels(_options) {
4259
- const child = this.spawnAppServer();
4260
- const client = new CodexAppServerClient(child, this.logger);
4261
- try {
4262
- await client.request("initialize", {
4263
- clientInfo: {
4264
- name: "junction",
4265
- title: "Junction",
4266
- version: "0.0.0",
4267
- },
4268
- });
4269
- client.notify("initialized", {});
4270
- const response = (await client.request("model/list", {}));
4271
- const models = Array.isArray(response?.data) ? response.data : [];
4272
- const configuredDefaults = await readCodexConfiguredDefaults(client, this.logger);
4273
- const configuredDefaultModelId = configuredDefaults.model;
4274
- const configuredDefaultThinkingOptionId = configuredDefaults.thinkingOptionId;
4275
- const hasConfiguredDefaultModel = typeof configuredDefaultModelId === "string"
4276
- ? models.some((model) => model?.id === configuredDefaultModelId)
4277
- : false;
4278
- return models.map((model) => {
4279
- const defaultReasoningEffort = normalizeCodexThinkingOptionId(typeof model.defaultReasoningEffort === "string"
4280
- ? model.defaultReasoningEffort
4281
- : null);
4282
- const resolvedDefaultReasoningEffort = configuredDefaultThinkingOptionId ?? defaultReasoningEffort;
4283
- const thinkingById = new Map();
4284
- if (Array.isArray(model.supportedReasoningEfforts)) {
4285
- for (const entry of model.supportedReasoningEfforts) {
4286
- const id = normalizeCodexThinkingOptionId(typeof entry?.reasoningEffort === "string" ? entry.reasoningEffort : null);
4287
- if (!id)
4288
- continue;
4289
- const description = typeof entry?.description === "string" && entry.description.trim().length > 0
4290
- ? entry.description
4291
- : undefined;
4292
- thinkingById.set(id, { id, label: id, description });
4293
- }
4294
- }
4295
- if (resolvedDefaultReasoningEffort && !thinkingById.has(resolvedDefaultReasoningEffort)) {
4296
- thinkingById.set(resolvedDefaultReasoningEffort, {
4297
- id: resolvedDefaultReasoningEffort,
4298
- label: resolvedDefaultReasoningEffort,
4299
- description: configuredDefaultThinkingOptionId === resolvedDefaultReasoningEffort
4300
- ? "Configured default reasoning effort"
4301
- : "Model default reasoning effort",
4260
+ const cacheKey = JSON.stringify({
4261
+ provider: CODEX_PROVIDER,
4262
+ runtime: this.runtimeSettings ?? null,
4263
+ });
4264
+ return getCachedProviderModels({
4265
+ cacheKey,
4266
+ provider: CODEX_PROVIDER,
4267
+ logger: this.logger,
4268
+ load: async () => {
4269
+ const child = this.spawnAppServer();
4270
+ const client = new CodexAppServerClient(child, this.logger);
4271
+ try {
4272
+ await client.request("initialize", {
4273
+ clientInfo: {
4274
+ name: "junction",
4275
+ title: "Junction",
4276
+ version: "0.0.0",
4277
+ },
4278
+ });
4279
+ client.notify("initialized", {});
4280
+ const response = (await client.request("model/list", {}));
4281
+ const models = Array.isArray(response?.data) ? response.data : [];
4282
+ const configuredDefaults = await readCodexConfiguredDefaults(client, this.logger);
4283
+ const configuredDefaultModelId = configuredDefaults.model;
4284
+ const configuredDefaultThinkingOptionId = configuredDefaults.thinkingOptionId;
4285
+ const hasConfiguredDefaultModel = typeof configuredDefaultModelId === "string"
4286
+ ? models.some((model) => model?.id === configuredDefaultModelId)
4287
+ : false;
4288
+ return models.map((model) => {
4289
+ const defaultReasoningEffort = normalizeCodexThinkingOptionId(typeof model.defaultReasoningEffort === "string"
4290
+ ? model.defaultReasoningEffort
4291
+ : null);
4292
+ const resolvedDefaultReasoningEffort = configuredDefaultThinkingOptionId ?? defaultReasoningEffort;
4293
+ const thinkingById = new Map();
4294
+ if (Array.isArray(model.supportedReasoningEfforts)) {
4295
+ for (const entry of model.supportedReasoningEfforts) {
4296
+ const id = normalizeCodexThinkingOptionId(typeof entry === "string"
4297
+ ? entry
4298
+ : typeof entry?.reasoningEffort === "string"
4299
+ ? entry.reasoningEffort
4300
+ : null);
4301
+ if (!id)
4302
+ continue;
4303
+ const description = typeof entry === "object" &&
4304
+ entry !== null &&
4305
+ typeof entry.description === "string" &&
4306
+ entry.description.trim().length > 0
4307
+ ? entry.description
4308
+ : undefined;
4309
+ thinkingById.set(id, { id, label: id, description });
4310
+ }
4311
+ }
4312
+ if (resolvedDefaultReasoningEffort && !thinkingById.has(resolvedDefaultReasoningEffort)) {
4313
+ thinkingById.set(resolvedDefaultReasoningEffort, {
4314
+ id: resolvedDefaultReasoningEffort,
4315
+ label: resolvedDefaultReasoningEffort,
4316
+ description: configuredDefaultThinkingOptionId === resolvedDefaultReasoningEffort
4317
+ ? "Configured default reasoning effort"
4318
+ : "Model default reasoning effort",
4319
+ });
4320
+ }
4321
+ const thinkingOptions = Array.from(thinkingById.values()).map((option) => ({
4322
+ ...option,
4323
+ isDefault: option.id === resolvedDefaultReasoningEffort,
4324
+ }));
4325
+ const defaultThinkingOptionId = resolvedDefaultReasoningEffort ??
4326
+ thinkingOptions.find((option) => option.isDefault)?.id ??
4327
+ thinkingOptions[0]?.id;
4328
+ const isDefaultModel = hasConfiguredDefaultModel
4329
+ ? model.id === configuredDefaultModelId
4330
+ : model.isDefault;
4331
+ return {
4332
+ provider: CODEX_PROVIDER,
4333
+ id: model.id,
4334
+ label: model.displayName,
4335
+ description: model.description,
4336
+ isDefault: isDefaultModel,
4337
+ thinkingOptions: thinkingOptions.length > 0 ? thinkingOptions : undefined,
4338
+ defaultThinkingOptionId,
4339
+ metadata: {
4340
+ model: model.model,
4341
+ defaultReasoningEffort: model.defaultReasoningEffort,
4342
+ supportedReasoningEfforts: model.supportedReasoningEfforts,
4343
+ },
4344
+ };
4302
4345
  });
4303
4346
  }
4304
- const thinkingOptions = Array.from(thinkingById.values()).map((option) => ({
4305
- ...option,
4306
- isDefault: option.id === resolvedDefaultReasoningEffort,
4307
- }));
4308
- const defaultThinkingOptionId = resolvedDefaultReasoningEffort ??
4309
- thinkingOptions.find((option) => option.isDefault)?.id ??
4310
- thinkingOptions[0]?.id;
4311
- const isDefaultModel = hasConfiguredDefaultModel
4312
- ? model.id === configuredDefaultModelId
4313
- : model.isDefault;
4314
- return {
4315
- provider: CODEX_PROVIDER,
4316
- id: model.id,
4317
- label: model.displayName,
4318
- description: model.description,
4319
- isDefault: isDefaultModel,
4320
- thinkingOptions: thinkingOptions.length > 0 ? thinkingOptions : undefined,
4321
- defaultThinkingOptionId,
4322
- metadata: {
4323
- model: model.model,
4324
- defaultReasoningEffort: model.defaultReasoningEffort,
4325
- supportedReasoningEfforts: model.supportedReasoningEfforts,
4326
- },
4327
- };
4328
- });
4329
- }
4330
- finally {
4331
- await client.dispose();
4332
- }
4347
+ finally {
4348
+ await client.dispose();
4349
+ }
4350
+ },
4351
+ });
4333
4352
  }
4334
4353
  async isAvailable() {
4335
4354
  return isProviderCommandAvailable(this.runtimeSettings?.command, () => resolveCodexBinary(this.runtimeSettings), applyProviderEnv(process.env, this.runtimeSettings));