@agent-native/core 0.198.8 → 0.199.0-nightly-20261001064935

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 (57) hide show
  1. package/dist/agent/actions/disconnect-chatgpt-subscription.d.ts +10 -1
  2. package/dist/agent/actions/disconnect-chatgpt-subscription.js +23 -5
  3. package/dist/agent/actions/get-chatgpt-subscription-status.d.ts +1 -6
  4. package/dist/agent/actions/get-chatgpt-subscription-status.js +1 -1
  5. package/dist/agent/actions/list-chatgpt-subscription-accounts.d.ts +5 -0
  6. package/dist/agent/actions/list-chatgpt-subscription-accounts.js +14 -0
  7. package/dist/agent/actions/select-chatgpt-subscription-account.d.ts +7 -0
  8. package/dist/agent/actions/select-chatgpt-subscription-account.js +22 -0
  9. package/dist/agent/chatgpt-subscription-contract.d.ts +14 -4
  10. package/dist/agent/chatgpt-subscription-contract.js +20 -8
  11. package/dist/agent/engine/builtin.js +10 -5
  12. package/dist/agent/engine/chatgpt-subscription-engine.d.ts +6 -0
  13. package/dist/agent/engine/chatgpt-subscription-engine.js +149 -49
  14. package/dist/agent/engine/registry.js +2 -6
  15. package/dist/client/chat-model-groups.d.ts +3 -0
  16. package/dist/client/chat-model-groups.js +12 -1
  17. package/dist/collab/awareness.d.ts +2 -2
  18. package/dist/collab/routes.d.ts +1 -1
  19. package/dist/file-upload/actions/upload-image.d.ts +2 -2
  20. package/dist/framework-tools.js +2 -0
  21. package/dist/jobs/actions/manage-recurring-job.d.ts +1 -1
  22. package/dist/labs/core-labs.js +4 -4
  23. package/dist/labs/registry.d.ts +2 -0
  24. package/dist/labs/registry.js +8 -0
  25. package/dist/localization/default-messages.d.ts +28 -0
  26. package/dist/localization/default-messages.js +28 -0
  27. package/dist/notifications/routes.d.ts +1 -1
  28. package/dist/oauth-tokens/lifecycle.d.ts +1 -0
  29. package/dist/oauth-tokens/lifecycle.js +5 -1
  30. package/dist/observability/routes.d.ts +8 -8
  31. package/dist/org/handlers.d.ts +1 -1
  32. package/dist/org/index.d.ts +1 -1
  33. package/dist/progress/routes.d.ts +1 -1
  34. package/dist/provider-api/actions/custom-provider-registration.d.ts +11 -11
  35. package/dist/provider-api/actions/provider-api.d.ts +5 -5
  36. package/dist/provider-api/corpus-jobs.d.ts +2 -2
  37. package/dist/scripts/agent-engines/list-agent-engines.js +55 -10
  38. package/dist/scripts/agent-engines/manage-agent-engine.js +20 -1
  39. package/dist/scripts/agent-engines/set-agent-engine.d.ts +3 -0
  40. package/dist/scripts/agent-engines/set-agent-engine.js +71 -9
  41. package/dist/server/action-discovery.js +8 -0
  42. package/dist/server/agent-chat-plugin.js +66 -16
  43. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  44. package/dist/server/agent-engine-default-model-route.d.ts +1 -1
  45. package/dist/server/agent-engine-ollama-models-route.d.ts +1 -1
  46. package/dist/server/chatgpt-subscription-oauth.d.ts +85 -5
  47. package/dist/server/chatgpt-subscription-oauth.js +1152 -206
  48. package/dist/server/core-routes-plugin.d.ts +1 -1
  49. package/dist/server/core-routes-plugin.js +2 -4
  50. package/dist/server/realtime-token.d.ts +1 -1
  51. package/dist/sharing/actions/list-resource-shares.d.ts +1 -1
  52. package/dist/triggers/actions/manage-automation.d.ts +5 -5
  53. package/dist/usage/actions/get-builder-credit-status.d.ts +7 -0
  54. package/dist/usage/actions/get-builder-credit-status.js +16 -4
  55. package/dist/vite/action-types-plugin.js +8 -0
  56. package/docs/content/toolkit-settings.mdx +36 -21
  57. package/package.json +6 -4
@@ -1,8 +1,8 @@
1
- import { CHATGPT_SUBSCRIPTION_LAB_KEY } from "../agent/chatgpt-subscription-contract.js";
2
1
  import { defineLab } from "./registry.js";
3
2
  export const CHATGPT_SUBSCRIPTION_LAB = defineLab({
4
- key: CHATGPT_SUBSCRIPTION_LAB_KEY,
5
- displayName: "ChatGPT subscription",
6
- description: "Try the experimental Codex engine with your ChatGPT subscription.",
3
+ key: "chatgpt-subscription",
4
+ displayName: "ChatGPT plan access",
5
+ displayNameKey: "agentChat.settingsModel.chatgptTitle",
6
+ descriptionKey: "agentChat.settingsModel.chatgptDescription",
7
7
  keywords: "OpenAI Codex GPT Plus Pro OAuth",
8
8
  });
@@ -4,7 +4,9 @@ export interface LabDefinition {
4
4
  legacyFlagKeys?: readonly string[];
5
5
  inheritedMixedDescription?: string;
6
6
  displayName?: string;
7
+ displayNameKey?: string;
7
8
  description?: string;
9
+ descriptionKey?: string;
8
10
  keywords?: string;
9
11
  }
10
12
  export declare function defineLab(definition: LabDefinition): LabDefinition;
@@ -21,9 +21,15 @@ function normalizeDefinition(definition) {
21
21
  ...(definition.displayName?.trim() && {
22
22
  displayName: definition.displayName.trim(),
23
23
  }),
24
+ ...(definition.displayNameKey?.trim() && {
25
+ displayNameKey: definition.displayNameKey.trim(),
26
+ }),
24
27
  ...(definition.description?.trim() && {
25
28
  description: definition.description.trim(),
26
29
  }),
30
+ ...(definition.descriptionKey?.trim() && {
31
+ descriptionKey: definition.descriptionKey.trim(),
32
+ }),
27
33
  ...(definition.keywords?.trim() && {
28
34
  keywords: definition.keywords.trim(),
29
35
  }),
@@ -57,7 +63,9 @@ export function registerLabs(definitions) {
57
63
  existing.inheritedMixedDescription !==
58
64
  definition.inheritedMixedDescription ||
59
65
  existing.displayName !== definition.displayName ||
66
+ existing.displayNameKey !== definition.displayNameKey ||
60
67
  existing.description !== definition.description ||
68
+ existing.descriptionKey !== definition.descriptionKey ||
61
69
  existing.keywords !== definition.keywords) {
62
70
  throw new Error(`Lab ${definition.key} was registered with conflicting metadata.`);
63
71
  }
@@ -80,6 +80,34 @@ declare const messages: {
80
80
  flags: string;
81
81
  };
82
82
  };
83
+ agentChat: {
84
+ settingsModel: {
85
+ chatgptAddAccount: string;
86
+ chatgptConnecting: string;
87
+ chatgptContinue: string;
88
+ chatgptDescription: string;
89
+ chatgptDisconnect: string;
90
+ chatgptDisconnectDescription: string;
91
+ chatgptDisconnectTitle: string;
92
+ chatgptDisconnecting: string;
93
+ chatgptLocalOnly: string;
94
+ chatgptManageAccess: string;
95
+ chatgptNoDirectUse: string;
96
+ chatgptReconnect: string;
97
+ chatgptRemoteRevocationUnconfirmed: string;
98
+ chatgptSelectAccount: string;
99
+ chatgptTitle: string;
100
+ chatgptUsageLimit: string;
101
+ };
102
+ composer: {
103
+ chatgptManageUsage: string;
104
+ chatgptPlanUsing: string;
105
+ };
106
+ error: {
107
+ chatgptPlanUsageLimit: string;
108
+ chatgptPlanUsageUnavailable: string;
109
+ };
110
+ };
83
111
  environmentBadge: import("./environment-badge-messages.js").EnvironmentBadgeMessages;
84
112
  workspaceFile: {
85
113
  download: string;
@@ -3,6 +3,34 @@ import { environmentBadgeMessages } from "./core-messages/supplemental/en-US.js"
3
3
  import { ICON_PICKER_MESSAGES } from "./icon-picker-messages.js";
4
4
  const messages = {
5
5
  iconPicker: ICON_PICKER_MESSAGES["en-US"],
6
+ agentChat: {
7
+ settingsModel: {
8
+ chatgptAddAccount: "Add another account",
9
+ chatgptConnecting: "Connecting…",
10
+ chatgptContinue: "Continue with ChatGPT",
11
+ chatgptDescription: "Use eligible OpenAI models through your ChatGPT plan.",
12
+ chatgptDisconnect: "Disconnect",
13
+ chatgptDisconnectDescription: "{{account}} will be signed out of this app and the agent will stop using your ChatGPT plan. You can sign in again anytime.",
14
+ chatgptDisconnectTitle: "Disconnect ChatGPT?",
15
+ chatgptDisconnecting: "Disconnecting…",
16
+ chatgptLocalOnly: "Open-source apps are self-serve when run locally with a loopback callback; no partner application is needed. Hosted apps on *.agent-native.com need operator approval and a hosted callback.",
17
+ chatgptManageAccess: "Manage in ChatGPT",
18
+ chatgptNoDirectUse: "Reconnect and allow direct model access to use this ChatGPT account.",
19
+ chatgptReconnect: "Reconnect",
20
+ chatgptRemoteRevocationUnconfirmed: "Disconnected here. Access may remain active in ChatGPT.",
21
+ chatgptSelectAccount: "ChatGPT account",
22
+ chatgptTitle: "ChatGPT plan access",
23
+ chatgptUsageLimit: "Your ChatGPT plan usage limit has been reached.",
24
+ },
25
+ composer: {
26
+ chatgptManageUsage: "Manage usage",
27
+ chatgptPlanUsing: "Using ChatGPT plan",
28
+ },
29
+ error: {
30
+ chatgptPlanUsageLimit: "Your ChatGPT plan usage limit has been reached.",
31
+ chatgptPlanUsageUnavailable: "OpenAI couldn’t check this ChatGPT plan’s usage limit. Check ChatGPT usage or try another model.",
32
+ },
33
+ },
6
34
  environmentBadge: environmentBadgeMessages,
7
35
  workspaceFile: {
8
36
  download: "Download",
@@ -16,6 +16,6 @@ export declare function createNotificationsHandler(): import("h3").EventHandlerW
16
16
  } | {
17
17
  count?: undefined;
18
18
  updated?: undefined;
19
- ok: boolean;
20
19
  error?: undefined;
20
+ ok: boolean;
21
21
  }>>;
@@ -77,6 +77,7 @@ export declare function resolveOAuthCredentialAccess<T extends OAuthCredential =
77
77
  allowLegacy?: boolean;
78
78
  legacyAccountKey?: boolean;
79
79
  validateCredential?: (credential: T) => boolean;
80
+ shouldMarkReconnectRequiredOnRefreshFailure?: (error: unknown) => boolean;
80
81
  expirySkewMs?: number;
81
82
  leaseMs?: number;
82
83
  waitMs?: number;
@@ -362,7 +362,7 @@ export async function resolveOAuthCredentialAccess(identity, options) {
362
362
  : null,
363
363
  };
364
364
  }
365
- catch {
365
+ catch (error) {
366
366
  const stillOwnsLease = await acquireLease(identity, holder, state.revision, !state.credential.oauthLifecycle, leaseMs, dependencies.now());
367
367
  if (stillOwnsLease !== "acquired") {
368
368
  await dependencies.sleep(waitMs);
@@ -381,6 +381,10 @@ export async function resolveOAuthCredentialAccess(identity, options) {
381
381
  };
382
382
  }
383
383
  if (latest.kind === "expired") {
384
+ if (options.shouldMarkReconnectRequiredOnRefreshFailure?.(error) ===
385
+ false) {
386
+ return { state: latest, accessToken: null };
387
+ }
384
388
  await markReconnectRequired(identity, latest, options.legacyAccountKey === true);
385
389
  const reconnect = await readStoredOAuthCredentialState(identity, {
386
390
  allowLegacy: options.allowLegacy,
@@ -27,38 +27,38 @@ export declare function createObservabilityHandler(): import("h3").EventHandlerW
27
27
  thumbsUpRate: number;
28
28
  avgEvalScore: number;
29
29
  } | {
30
- id?: undefined;
30
+ ok?: undefined;
31
31
  error: string;
32
32
  message: string;
33
33
  summary?: undefined;
34
34
  spans?: undefined;
35
- ok?: undefined;
36
- } | {
37
35
  id?: undefined;
36
+ } | {
38
37
  error?: undefined;
38
+ ok?: undefined;
39
39
  message?: undefined;
40
40
  summary: import("./types.js").TraceSummary;
41
41
  spans: import("./types.js").TraceSpan[];
42
- ok?: undefined;
42
+ id?: undefined;
43
43
  } | {
44
44
  error?: undefined;
45
+ ok?: undefined;
45
46
  message?: undefined;
46
47
  summary?: undefined;
47
48
  spans?: undefined;
48
49
  id: string;
49
- ok?: undefined;
50
50
  } | {
51
- id?: undefined;
51
+ ok?: undefined;
52
52
  message?: undefined;
53
53
  summary?: undefined;
54
54
  spans?: undefined;
55
+ id?: undefined;
55
56
  error: any;
56
- ok?: undefined;
57
57
  } | {
58
- id?: undefined;
59
58
  error?: undefined;
60
59
  message?: undefined;
61
60
  summary?: undefined;
62
61
  spans?: undefined;
62
+ id?: undefined;
63
63
  ok: boolean;
64
64
  }>>;
@@ -72,9 +72,9 @@ export declare const setWorkspaceAppDefaultVisibilityHandler: import("h3").Event
72
72
  }>>;
73
73
  export declare const createOrgHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
74
74
  success: boolean;
75
+ id?: undefined;
75
76
  name?: undefined;
76
77
  role?: undefined;
77
- id?: undefined;
78
78
  } | {
79
79
  success?: undefined;
80
80
  id: string;
@@ -177,10 +177,10 @@ export declare const getMyOrgHandler: import("h3").EventHandlerWithFetch<import(
177
177
  soloDeploymentAdmin: boolean | undefined;
178
178
  }>>;
179
179
  export declare const createOrgHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
180
+ id?: undefined;
180
181
  name?: undefined;
181
182
  success: boolean;
182
183
  role?: undefined;
183
- id?: undefined;
184
184
  } | {
185
185
  success?: undefined;
186
186
  id: string;
@@ -2,6 +2,6 @@ export declare function createProgressHandler(): import("h3").EventHandlerWithFe
2
2
  error: string;
3
3
  ok?: undefined;
4
4
  } | {
5
- ok: boolean;
6
5
  error?: undefined;
6
+ ok: boolean;
7
7
  }>>;
@@ -75,11 +75,9 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
75
75
  user: "user";
76
76
  }>>;
77
77
  }, z.core.$strip>>, {
78
- message?: undefined;
79
- deleted?: undefined;
80
78
  id?: undefined;
81
- provider?: undefined;
82
79
  found?: undefined;
80
+ deleted?: undefined;
83
81
  providers: {
84
82
  id: string;
85
83
  label: string;
@@ -90,44 +88,46 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
90
88
  updatedAt: number;
91
89
  }[];
92
90
  count: number;
91
+ provider?: undefined;
93
92
  registered?: undefined;
94
93
  label?: undefined;
95
- } | {
96
94
  message?: undefined;
97
- deleted?: undefined;
95
+ } | {
98
96
  id?: undefined;
97
+ deleted?: undefined;
99
98
  providers?: undefined;
100
99
  count?: undefined;
101
100
  found: boolean;
102
101
  provider: import("../custom-registry.js").CustomProviderConfig;
103
102
  registered?: undefined;
104
103
  label?: undefined;
105
- } | {
106
104
  message?: undefined;
105
+ } | {
107
106
  deleted?: undefined;
108
- provider?: undefined;
109
107
  providers?: undefined;
110
108
  count?: undefined;
109
+ provider?: undefined;
111
110
  found: boolean;
112
111
  id: string;
113
112
  registered?: undefined;
114
113
  label?: undefined;
115
- } | {
116
114
  message?: undefined;
117
- provider?: undefined;
115
+ } | {
118
116
  found?: undefined;
119
117
  providers?: undefined;
120
118
  count?: undefined;
119
+ provider?: undefined;
121
120
  deleted: boolean;
122
121
  id: string;
123
122
  registered?: undefined;
124
123
  label?: undefined;
124
+ message?: undefined;
125
125
  } | {
126
- deleted?: undefined;
127
- provider?: undefined;
128
126
  found?: undefined;
127
+ deleted?: undefined;
129
128
  providers?: undefined;
130
129
  count?: undefined;
130
+ provider?: undefined;
131
131
  registered: boolean;
132
132
  id: string;
133
133
  label: string;
@@ -311,9 +311,9 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
311
311
  notes?: string | undefined;
312
312
  scope?: "org" | "user" | undefined;
313
313
  }, {
314
+ message?: undefined;
314
315
  provider?: undefined;
315
316
  id?: undefined;
316
- message?: undefined;
317
317
  deleted?: undefined;
318
318
  found?: undefined;
319
319
  providers: {
@@ -329,9 +329,9 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
329
329
  registered?: undefined;
330
330
  label?: undefined;
331
331
  } | {
332
- id?: undefined;
333
- count?: undefined;
334
332
  message?: undefined;
333
+ count?: undefined;
334
+ id?: undefined;
335
335
  deleted?: undefined;
336
336
  providers?: undefined;
337
337
  found: boolean;
@@ -339,9 +339,9 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
339
339
  registered?: undefined;
340
340
  label?: undefined;
341
341
  } | {
342
+ message?: undefined;
342
343
  provider?: undefined;
343
344
  count?: undefined;
344
- message?: undefined;
345
345
  deleted?: undefined;
346
346
  providers?: undefined;
347
347
  found: boolean;
@@ -349,9 +349,9 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
349
349
  registered?: undefined;
350
350
  label?: undefined;
351
351
  } | {
352
+ message?: undefined;
352
353
  provider?: undefined;
353
354
  count?: undefined;
354
- message?: undefined;
355
355
  found?: undefined;
356
356
  providers?: undefined;
357
357
  deleted: boolean;
@@ -73,7 +73,6 @@ export declare function createProviderCorpusJobAction(options: CreateProviderCor
73
73
  offset?: unknown;
74
74
  limit?: unknown;
75
75
  }, {
76
- deleted?: undefined;
77
76
  jobs: {
78
77
  id: string;
79
78
  name: string;
@@ -84,6 +83,7 @@ export declare function createProviderCorpusJobAction(options: CreateProviderCor
84
83
  updatedAt: string;
85
84
  }[];
86
85
  total: number;
86
+ deleted?: undefined;
87
87
  jobId?: undefined;
88
88
  } | {
89
89
  jobs?: undefined;
@@ -91,9 +91,9 @@ export declare function createProviderCorpusJobAction(options: CreateProviderCor
91
91
  deleted: boolean;
92
92
  jobId: string;
93
93
  } | {
94
- deleted?: undefined;
95
94
  jobs?: undefined;
96
95
  total?: undefined;
96
+ deleted?: undefined;
97
97
  jobId?: undefined;
98
98
  hits: Record<string, unknown>[];
99
99
  offset: number;
@@ -1,9 +1,14 @@
1
1
  import { getAgentAppModelDefaultForCurrentRequest } from "../../agent/app-model-defaults.js";
2
+ import { CHATGPT_SUBSCRIPTION_ENGINE_NAME } from "../../agent/chatgpt-subscription-contract.js";
2
3
  import { readDefaultAgentEngineSettingDetailed, resolveDefaultAgentEngineAuthority, } from "../../agent/default-agent-engine.js";
4
+ import { listChatGPTSubscriptionModels } from "../../agent/engine/chatgpt-subscription-engine.js";
3
5
  import { listAgentEngines, registerBuiltinEngines, detectEngineFromEnv, detectEngineFromUserSecrets, getAgentEngineEntry, isAgentEnginePackageInstalled, isStoredEngineUsableForRequest, normalizeModelForEngine, resolveEngineAcceptsCustomModels, resolveEnginePreservesCustomModels, } from "../../agent/engine/index.js";
4
6
  import { applyProviderModelSelection, providerForEngineName, resolveEffectiveProviderModelSelection, } from "../../agent/provider-model-selection.js";
5
7
  import { getAppConfig } from "../../app-config/index.js";
8
+ import { CHATGPT_SUBSCRIPTION_LAB } from "../../labs/core-labs.js";
9
+ import { getUserLabEnabled } from "../../labs/store.js";
6
10
  import { prefetchSecrets, readProviderCredentialRejections, resolveSecretDetailed, } from "../../server/credential-provider.js";
11
+ import { getRequestUserEmail } from "../../server/request-context.js";
7
12
  export const tool = {
8
13
  description: 'List all available AI agent engines (Anthropic, OpenAI, Gemini, Groq, etc.), the currently selected engine, and whether the caller can change the organization default (canUpdateDefault). supportedModels is what the model picker shows: the models checked for that provider (modelSelection.state "selected") or its recommendedModels. credentialRejected marks an engine whose saved key its provider rejected; chats with it stop until the key is replaced. Use this to check what engines are available before calling manage-agent-engine with action="set".',
9
14
  parameters: {
@@ -42,7 +47,41 @@ async function readSavedKeyRejections(keys) {
42
47
  }
43
48
  export async function run(args = {}) {
44
49
  registerBuiltinEngines();
45
- const engines = listAgentEngines();
50
+ const availableEngines = listAgentEngines();
51
+ const requestEmail = getRequestUserEmail();
52
+ const chatGPTLabEnabled = requestEmail &&
53
+ availableEngines.some((entry) => entry.name === CHATGPT_SUBSCRIPTION_ENGINE_NAME)
54
+ ? await getUserLabEnabled(requestEmail, CHATGPT_SUBSCRIPTION_LAB)
55
+ : false;
56
+ const registeredEngines = availableEngines.filter((entry) => entry.name !== CHATGPT_SUBSCRIPTION_ENGINE_NAME || chatGPTLabEnabled);
57
+ const chatGPTEntry = registeredEngines.find((entry) => entry.name === CHATGPT_SUBSCRIPTION_ENGINE_NAME);
58
+ let chatGPTCatalog;
59
+ let chatGPTCatalogError;
60
+ if (chatGPTEntry &&
61
+ requestEmail &&
62
+ (await isStoredEngineUsableForRequest({ engine: chatGPTEntry.name }, chatGPTEntry))) {
63
+ try {
64
+ chatGPTCatalog = await listChatGPTSubscriptionModels(requestEmail);
65
+ }
66
+ catch (error) {
67
+ chatGPTCatalogError =
68
+ error instanceof Error ? error.message : String(error);
69
+ }
70
+ }
71
+ const withChatGPTModels = (entry) => entry.name === CHATGPT_SUBSCRIPTION_ENGINE_NAME && chatGPTCatalog
72
+ ? {
73
+ ...entry,
74
+ defaultModel: chatGPTCatalog.models[0] ?? "",
75
+ supportedModels: chatGPTCatalog.models,
76
+ modelDisplayNames: chatGPTCatalog.modelDisplayNames,
77
+ }
78
+ : entry;
79
+ const engines = registeredEngines.map(withChatGPTModels);
80
+ const engineFor = (name) => {
81
+ const entry = engines.find((candidate) => candidate.name === name) ??
82
+ getAgentEngineEntry(name);
83
+ return entry ? withChatGPTModels(entry) : undefined;
84
+ };
46
85
  const providerKeys = [
47
86
  ...new Set(engines
48
87
  .filter((entry) => entry.name !== "builder" && isAgentEnginePackageInstalled(entry))
@@ -69,23 +108,19 @@ export async function run(args = {}) {
69
108
  const current = defaultSetting.value
70
109
  ? defaultSetting.value
71
110
  : null;
72
- const storedEntry = typeof current?.engine === "string"
73
- ? getAgentEngineEntry(current.engine)
74
- : undefined;
111
+ const storedEntry = typeof current?.engine === "string" ? engineFor(current.engine) : undefined;
75
112
  const storedUsable = !!storedEntry &&
76
113
  (await isStoredEngineUsableForRequest(current, storedEntry));
77
114
  const appDefault = await getAgentAppModelDefaultForCurrentRequest(args.appId);
78
115
  const appDefaultEntry = typeof appDefault?.engine === "string"
79
- ? getAgentEngineEntry(appDefault.engine)
116
+ ? engineFor(appDefault.engine)
80
117
  : undefined;
81
118
  const appDefaultUsable = !!appDefault &&
82
119
  !!appDefaultEntry &&
83
120
  (await isStoredEngineUsableForRequest(appDefault, appDefaultEntry));
84
121
  const detectedFromUser = await detectEngineFromUserSecrets();
85
122
  const configuredEngine = getAppConfig().agent.engine;
86
- const envEntry = configuredEngine
87
- ? getAgentEngineEntry(configuredEngine)
88
- : undefined;
123
+ const envEntry = configuredEngine ? engineFor(configuredEngine) : undefined;
89
124
  const envUsable = !!envEntry &&
90
125
  (await isStoredEngineUsableForRequest({ engine: envEntry.name }, envEntry));
91
126
  const envUnavailable = !!envEntry && !envUsable;
@@ -142,6 +177,9 @@ export async function run(args = {}) {
142
177
  configuredError =
143
178
  error instanceof Error ? error.message : String(error);
144
179
  }
180
+ if (e.name === CHATGPT_SUBSCRIPTION_ENGINE_NAME && chatGPTCatalogError) {
181
+ configuredError = chatGPTCatalogError;
182
+ }
145
183
  // Builder's credentials carry their own markers and reconnect flow.
146
184
  const rejectionStates = e.name === "builder" || !isAgentEnginePackageInstalled(e)
147
185
  ? []
@@ -160,8 +198,15 @@ export async function run(args = {}) {
160
198
  label: e.label,
161
199
  description: e.description,
162
200
  defaultModel: e.defaultModel,
163
- supportedModels: applyProviderModelSelection(e.supportedModels, modelSelection),
164
- recommendedModels: e.supportedModels,
201
+ supportedModels: e.name === CHATGPT_SUBSCRIPTION_ENGINE_NAME
202
+ ? (chatGPTCatalog?.models ?? [])
203
+ : applyProviderModelSelection(e.supportedModels, modelSelection),
204
+ ...(e.name === CHATGPT_SUBSCRIPTION_ENGINE_NAME && chatGPTCatalog
205
+ ? { modelDisplayNames: chatGPTCatalog.modelDisplayNames }
206
+ : {}),
207
+ recommendedModels: e.name === CHATGPT_SUBSCRIPTION_ENGINE_NAME
208
+ ? (chatGPTCatalog?.models ?? [])
209
+ : e.supportedModels,
165
210
  ...(modelSelection
166
211
  ? {
167
212
  modelSelection: modelSelection.state === "unreadable"
@@ -1,4 +1,6 @@
1
1
  import { canUpdateAgentAppModelDefaultSettings, normalizeAgentAppModelDefaultAppId, readAgentAppModelDefaultSettings, resetAgentAppModelDefaultSettings, writeAgentAppModelDefaultSettings, } from "../../agent/app-model-defaults.js";
2
+ import { CHATGPT_SUBSCRIPTION_ENGINE_NAME } from "../../agent/chatgpt-subscription-contract.js";
3
+ import { listChatGPTSubscriptionModels } from "../../agent/engine/chatgpt-subscription-engine.js";
2
4
  import { getAgentEngineEntry, isAgentEnginePackageInstalled, normalizeModelForEngine, resolveEngineAcceptsCustomModels, resolveEnginePreservesCustomModels, registerBuiltinEngines, } from "../../agent/engine/index.js";
3
5
  import { getRequestOrgId, getRequestUserEmail, } from "../../server/request-context.js";
4
6
  import { run as runList } from "./list-agent-engines.js";
@@ -75,6 +77,24 @@ async function runSetAppDefault(args) {
75
77
  return "Error: engine is required";
76
78
  if (!model)
77
79
  return "Error: model is required";
80
+ const ctx = currentContext();
81
+ if (engine === CHATGPT_SUBSCRIPTION_ENGINE_NAME) {
82
+ if (ctx.orgId) {
83
+ return "Error: ChatGPT plan access is personal and cannot be selected as an organization default.";
84
+ }
85
+ const email = ctx.userEmail;
86
+ if (!email)
87
+ return "Error: Sign in before selecting ChatGPT plan access.";
88
+ try {
89
+ const catalog = await listChatGPTSubscriptionModels(email);
90
+ if (!catalog.models.includes(model)) {
91
+ return "Error: Choose a visible model from the selected ChatGPT account's model list.";
92
+ }
93
+ }
94
+ catch (error) {
95
+ return `Error: ${error instanceof Error ? error.message : "Unable to load the ChatGPT account's model list."}`;
96
+ }
97
+ }
78
98
  const entry = getAgentEngineEntry(engine);
79
99
  if (!entry)
80
100
  return `Error: Unknown engine "${engine}"`;
@@ -87,7 +107,6 @@ async function runSetAppDefault(args) {
87
107
  acceptsCustomModels,
88
108
  preserveCustomModels,
89
109
  });
90
- const ctx = currentContext();
91
110
  const canUpdate = await canUpdateAgentAppModelDefaultSettings(ctx.userEmail, ctx.orgId);
92
111
  if (!canUpdate) {
93
112
  return ctx.orgId
@@ -22,6 +22,9 @@ export type SelectDefaultAgentEngineResult = {
22
22
  } | {
23
23
  status: "missing-credentials";
24
24
  message: string;
25
+ } | {
26
+ status: "unavailable";
27
+ message: string;
25
28
  };
26
29
  /**
27
30
  * Validate an engine/model pair and save it as the default for the caller's
@@ -3,8 +3,12 @@
3
3
  * `agent-engine` setting) for the caller's organization.
4
4
  */
5
5
  import { ActionContractError } from "../../action.js";
6
+ import { CHATGPT_SUBSCRIPTION_ENGINE_NAME } from "../../agent/chatgpt-subscription-contract.js";
6
7
  import { recordDefaultAgentEngineRefusal, resolveDefaultAgentEngineAuthority, writeDefaultAgentEngineSelection, } from "../../agent/default-agent-engine.js";
8
+ import { listChatGPTSubscriptionModels } from "../../agent/engine/chatgpt-subscription-engine.js";
7
9
  import { listAgentEngines, getAgentEngineEntry, isAgentEnginePackageInstalled, isStoredEngineUsableForRequest, normalizeModelForEngine, resolveEngineAcceptsCustomModels, resolveEnginePreservesCustomModels, registerBuiltinEngines, } from "../../agent/engine/index.js";
10
+ import { CHATGPT_SUBSCRIPTION_LAB } from "../../labs/core-labs.js";
11
+ import { getUserLabEnabled } from "../../labs/store.js";
8
12
  import { getRequestOrgId, getRequestUserEmail, } from "../../server/request-context.js";
9
13
  export const tool = {
10
14
  description: 'Set the organization\'s default AI engine and model. Only organization owners and admins can change it; a user with no organization sets their own. Changes take effect on the next conversation. Use manage-agent-engine with action="list" first to see available options and whether you can change the default (canUpdateDefault).',
@@ -45,6 +49,13 @@ export async function selectDefaultAgentEngine(input, meta, ctx = {
45
49
  });
46
50
  return { status: "refused", message: authority.message };
47
51
  }
52
+ if (engineName === CHATGPT_SUBSCRIPTION_ENGINE_NAME &&
53
+ authority.scope === "org") {
54
+ return {
55
+ status: "invalid",
56
+ message: "ChatGPT plan access is personal and cannot be selected as an organization default.",
57
+ };
58
+ }
48
59
  const entry = getAgentEngineEntry(engineName);
49
60
  if (!entry) {
50
61
  const available = listAgentEngines()
@@ -61,21 +72,69 @@ export async function selectDefaultAgentEngine(input, meta, ctx = {
61
72
  message: `Engine "${engineName}" requires optional packages that are not installed in this app. Run: pnpm add ${entry.installPackage}`,
62
73
  };
63
74
  }
64
- const requestedModel = input.model?.trim() || entry.defaultModel;
75
+ const chatGPTEmail = entry.name === CHATGPT_SUBSCRIPTION_ENGINE_NAME
76
+ ? (ctx.userEmail ?? getRequestUserEmail())
77
+ : undefined;
78
+ if (entry.name === CHATGPT_SUBSCRIPTION_ENGINE_NAME) {
79
+ if (!chatGPTEmail) {
80
+ return {
81
+ status: "missing-credentials",
82
+ message: "A signed-in user is required to use ChatGPT plan access.",
83
+ };
84
+ }
85
+ if (!(await getUserLabEnabled(chatGPTEmail, CHATGPT_SUBSCRIPTION_LAB))) {
86
+ return {
87
+ status: "unavailable",
88
+ message: "Enable ChatGPT plan access in Settings → Labs before selecting this engine.",
89
+ };
90
+ }
91
+ }
92
+ const credentialEmail = chatGPTEmail ?? ctx.userEmail;
93
+ const credentialIdentity = credentialEmail
94
+ ? { userEmail: credentialEmail }
95
+ : undefined;
96
+ const needsCredentialIdentity = entry.name === "builder" || entry.name === CHATGPT_SUBSCRIPTION_ENGINE_NAME;
97
+ const usable = credentialIdentity && needsCredentialIdentity
98
+ ? await isStoredEngineUsableForRequest({ engine: engineName }, entry, {
99
+ credentialIdentity,
100
+ })
101
+ : await isStoredEngineUsableForRequest({ engine: engineName }, entry);
102
+ if (!usable) {
103
+ return {
104
+ status: "missing-credentials",
105
+ message: engineName === CHATGPT_SUBSCRIPTION_ENGINE_NAME
106
+ ? "Connect a ChatGPT account with direct model access before selecting this engine."
107
+ : `Engine "${engineName}" requires the following credentials which are not configured for this request: ${entry.requiredEnvVars.join(", ")}. The engine will fail at runtime without them.`,
108
+ };
109
+ }
110
+ let requestedModel = input.model?.trim() || entry.defaultModel;
111
+ if (engineName === CHATGPT_SUBSCRIPTION_ENGINE_NAME) {
112
+ try {
113
+ const catalog = await listChatGPTSubscriptionModels(chatGPTEmail);
114
+ if (!requestedModel)
115
+ requestedModel = catalog.models[0] ?? "";
116
+ if (!requestedModel || !catalog.models.includes(requestedModel)) {
117
+ return {
118
+ status: "invalid",
119
+ message: "Choose a visible model from the selected ChatGPT account's model list.",
120
+ };
121
+ }
122
+ }
123
+ catch (error) {
124
+ return {
125
+ status: "unavailable",
126
+ message: error instanceof Error
127
+ ? error.message
128
+ : "Unable to load the ChatGPT account's model list.",
129
+ };
130
+ }
131
+ }
65
132
  const acceptsCustomModels = await resolveEngineAcceptsCustomModels(entry);
66
133
  const preserveCustomModels = await resolveEnginePreservesCustomModels(entry);
67
134
  const resolvedModel = normalizeModelForEngine(entry, requestedModel, {
68
135
  acceptsCustomModels,
69
136
  preserveCustomModels,
70
137
  });
71
- const usable = await isStoredEngineUsableForRequest({ engine: engineName }, entry);
72
- if (!usable) {
73
- const missingEnvVars = entry.requiredEnvVars.join(", ");
74
- return {
75
- status: "missing-credentials",
76
- message: `Engine "${engineName}" requires the following credentials which are not configured for this request: ${missingEnvVars}. The engine will fail at runtime without them.`,
77
- };
78
- }
79
138
  await writeDefaultAgentEngineSelection(authority, { engine: engineName, model: resolvedModel }, meta);
80
139
  return {
81
140
  status: "selected",
@@ -104,6 +163,9 @@ export async function run(args, context) {
104
163
  if (result.status === "missing-credentials") {
105
164
  return `Warning: ${result.message}`;
106
165
  }
166
+ if (result.status === "unavailable") {
167
+ return `Error: ${result.message}`;
168
+ }
107
169
  const normalizedNote = result.model === result.requestedModel
108
170
  ? ""
109
171
  : ` Requested model "${result.requestedModel}" is no longer supported, so "${result.model}" was saved instead.`;