@opengeni/api-router 6.7.0 → 6.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +1 -1
- package/dist/{chunk-WXI5VFFM.js → chunk-A2VKA7K3.js} +111 -25
- package/dist/{chunk-WXI5VFFM.js.map → chunk-A2VKA7K3.js.map} +1 -1
- package/dist/http/api-error.d.ts +6 -0
- package/dist/http/rejection-telemetry.d.ts +12 -2
- package/dist/index.js +1 -1
- package/dist/routes/codex-connect-models.d.ts +33 -0
- package/dist/routes/codex-core.d.ts +7 -0
- package/package.json +26 -26
- package/src/app.ts +2 -0
- package/src/http/api-error.ts +23 -0
- package/src/http/rejection-telemetry.ts +26 -6
- package/src/mcp/secret-tools.ts +1 -1
- package/src/routes/codex-connect-models.ts +64 -0
- package/src/routes/codex-core.ts +7 -0
- package/src/routes/codex.ts +24 -15
- package/src/routes/sessions.ts +35 -0
package/dist/http/api-error.d.ts
CHANGED
|
@@ -94,6 +94,12 @@ export declare function regionRestrictedHttpError(error: unknown): ApiHttpError
|
|
|
94
94
|
* another model rather than offer a retry that cannot succeed.
|
|
95
95
|
*/
|
|
96
96
|
export declare function modelUnavailableHttpError(error: unknown): ApiHttpError | null;
|
|
97
|
+
/**
|
|
98
|
+
* A model the workspace's model policy refuses. The same request is refused
|
|
99
|
+
* again until someone changes the model or the policy, so clients get
|
|
100
|
+
* `details.code: "model_policy"` with the rule (`reason`) instead of a retry.
|
|
101
|
+
*/
|
|
102
|
+
export declare function modelPolicyRefusedHttpError(error: unknown): ApiHttpError | null;
|
|
97
103
|
/** Keep a rejected credential selection actionable without changing its authority. */
|
|
98
104
|
export declare function connectionAccountSelectionHttpError(error: unknown): ApiHttpError | null;
|
|
99
105
|
export {};
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
* from the closed permission catalog (as `details.permission`, or in a
|
|
9
9
|
* legacy "missing permission: <name>" message), else the envelope's typed
|
|
10
10
|
* `details.code` when it is a short identifier, else `control:<code>` for a
|
|
11
|
-
* Connected Machine control failure, else
|
|
11
|
+
* Connected Machine control failure, else (for a route's own top-level
|
|
12
|
+
* `{ code, message, details }` body, such as session create) its
|
|
13
|
+
* UPPER_SNAKE route code, else `unclassified`.
|
|
12
14
|
* - `fingerprint` is a one-way hash of the message with identifiers and
|
|
13
15
|
* numbers normalized away. It groups identical refusals in logs; resolve it
|
|
14
16
|
* back to source text with `bun run scripts/resolve-rejection-fingerprint.ts`.
|
|
@@ -24,7 +26,15 @@ export declare function rejectionFingerprint(message: string): string;
|
|
|
24
26
|
/** Identifiers, quoted values, and numbers never distinguish two fingerprints. */
|
|
25
27
|
export declare function normalizeRejectionMessage(message: string): string;
|
|
26
28
|
export declare function rejectionReasonFromMessage(message: string | undefined): string | null;
|
|
27
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Classify a parsed `ErrorEnvelope`-shaped body. Unknown shapes still get a code.
|
|
31
|
+
* A route that answers with its own top-level `{ code, message, details }`
|
|
32
|
+
* (session create) is read the same way, so its refusals are not all
|
|
33
|
+
* "unclassified": the reason is its typed `details.code`, else its own route
|
|
34
|
+
* code, and the message is fingerprinted. Only a body whose top-level code is
|
|
35
|
+
* one of our authored UPPER_SNAKE route codes counts, so a passed-through
|
|
36
|
+
* upstream body can never add reason values.
|
|
37
|
+
*/
|
|
28
38
|
export declare function httpRejectionFactsFromEnvelope(envelope: unknown, fallbackCode: string): HttpRejectionFacts;
|
|
29
39
|
/** Classify a thrown error that escaped the central error handler. */
|
|
30
40
|
export declare function httpRejectionFactsFromError(error: unknown, fallbackCode: string): HttpRejectionFacts;
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type CodexFetch } from "@opengeni/codex";
|
|
2
|
+
import { type Settings } from "@opengeni/config";
|
|
3
|
+
/** A Codex model the just-connected account offers, as Opengeni names it. */
|
|
4
|
+
export type CodexConnectOfferedModel = {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Opengeni's Codex models, optionally only those whose upstream slug is in
|
|
10
|
+
* `supportedSlugs`. The one filter the picker (`codexModelsForPicker`) and the
|
|
11
|
+
* connect result share, so both always name the same models.
|
|
12
|
+
*/
|
|
13
|
+
export declare function codexCatalogModels(settings: Settings, supportedSlugs?: readonly string[]): import("@opengeni/config").ConfiguredModel[];
|
|
14
|
+
/**
|
|
15
|
+
* Which of Opengeni's Codex models a just-connected ChatGPT account offers,
|
|
16
|
+
* read once from its live /models list with the tokens the sign-in returned
|
|
17
|
+
* (nothing is stored). A Free plan offers GPT-6 Luna only; an account that
|
|
18
|
+
* offers none of them is told so at connect time instead of at Send.
|
|
19
|
+
*
|
|
20
|
+
* The list is taken as the backend returns it for this client version: the
|
|
21
|
+
* Codex CLI shows every listed model to ChatGPT sign-ins (`supported_in_api`
|
|
22
|
+
* only filters API-key sign-ins) and the backend applies
|
|
23
|
+
* `minimal_client_version` itself from the `client_version` query.
|
|
24
|
+
*
|
|
25
|
+
* Null when the read fails: the connection still succeeded.
|
|
26
|
+
*/
|
|
27
|
+
export declare function codexConnectOfferedModels(input: {
|
|
28
|
+
settings: Settings;
|
|
29
|
+
accessToken: string;
|
|
30
|
+
chatgptAccountId: string | null;
|
|
31
|
+
isFedramp: boolean;
|
|
32
|
+
fetchImpl?: CodexFetch | undefined;
|
|
33
|
+
}): Promise<CodexConnectOfferedModel[] | null>;
|
|
@@ -2,6 +2,7 @@ import type { Context } from "hono";
|
|
|
2
2
|
import { requireAccessGrant, type ApiRouteDeps } from "@opengeni/core";
|
|
3
3
|
import { type SubscriptionCoreCodexCredentialInput, type DisconnectAuditActor } from "@opengeni/db";
|
|
4
4
|
import type { CodexUsagePayload } from "@opengeni/codex";
|
|
5
|
+
import type { CodexConnectOfferedModel } from "./codex-connect-models.js";
|
|
5
6
|
import { codexModelsForPicker, requireCodexAppsHuman } from "./codex.js";
|
|
6
7
|
import { SUBSCRIPTION_CORE_CUTOVER_DISABLED, typedHttpError } from "./subscription-core-http.js";
|
|
7
8
|
export { SUBSCRIPTION_CORE_CUTOVER_DISABLED, typedHttpError };
|
|
@@ -18,11 +19,17 @@ export declare function coreCodexConnected(c: Context, deps: ApiRouteDeps, input
|
|
|
18
19
|
/** The shared workspace the person added their own subscription from (D-53). */
|
|
19
20
|
addedFrom?: string | undefined;
|
|
20
21
|
credential: SubscriptionCoreCodexCredentialInput;
|
|
22
|
+
/** The account's offered Codex models, read once after it connects. */
|
|
23
|
+
offeredModels?: (() => Promise<CodexConnectOfferedModel[] | null>) | undefined;
|
|
21
24
|
}): Promise<Response & import("hono").TypedResponse<{
|
|
22
25
|
status: string;
|
|
23
26
|
plan: string | null;
|
|
24
27
|
accountId: string;
|
|
25
28
|
isActive: boolean;
|
|
29
|
+
models?: {
|
|
30
|
+
id: string;
|
|
31
|
+
label: string;
|
|
32
|
+
}[] | undefined;
|
|
26
33
|
}, import("hono/utils/http-status").ContentfulStatusCode, "json">>;
|
|
27
34
|
/** Disconnect one account on the core: the legacy `{ disconnected, newActiveId }`. */
|
|
28
35
|
export declare function coreCodexDisconnect(c: Context, deps: ApiRouteDeps, input: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeni/api-router",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.0",
|
|
4
4
|
"description": "Opengeni HTTP surface: the Hono adapter/router (createApp), routes, MCP HTTP transport, and HTTP access adapters over @opengeni/core. An engine-distribution surface — its runtime closure includes engine-internal packages.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -46,34 +46,34 @@
|
|
|
46
46
|
"@llamaindex/liteparse": "2.14.2",
|
|
47
47
|
"@microsoft/teams.apps": "2.1.1",
|
|
48
48
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
49
|
-
"@opengeni/agent-proto": "6.
|
|
50
|
-
"@opengeni/artifact-tool": "6.
|
|
51
|
-
"@opengeni/capabilities": "6.
|
|
52
|
-
"@opengeni/codemode": "6.
|
|
53
|
-
"@opengeni/codex": "6.
|
|
54
|
-
"@opengeni/config": "6.
|
|
55
|
-
"@opengeni/contracts": "6.
|
|
56
|
-
"@opengeni/core": "6.
|
|
57
|
-
"@opengeni/db": "6.
|
|
58
|
-
"@opengeni/documents": "6.
|
|
59
|
-
"@opengeni/events": "6.
|
|
60
|
-
"@opengeni/github": "6.
|
|
61
|
-
"@opengeni/interaction": "6.
|
|
62
|
-
"@opengeni/network": "6.
|
|
63
|
-
"@opengeni/observability": "6.
|
|
64
|
-
"@opengeni/runtime": "6.
|
|
65
|
-
"@opengeni/storage": "6.
|
|
66
|
-
"@opengeni/tool-gateway": "6.
|
|
67
|
-
"@opengeni/vaults": "6.
|
|
68
|
-
"@opengeni/vaults-bitwarden": "6.
|
|
69
|
-
"@opengeni/vaults-keeper": "6.
|
|
70
|
-
"@opengeni/vaults-onepassword": "6.
|
|
71
|
-
"@opengeni/vaults-protonpass": "6.
|
|
72
|
-
"@opengeni/xai-subscription": "6.
|
|
49
|
+
"@opengeni/agent-proto": "6.8.0",
|
|
50
|
+
"@opengeni/artifact-tool": "6.8.0",
|
|
51
|
+
"@opengeni/capabilities": "6.8.0",
|
|
52
|
+
"@opengeni/codemode": "6.8.0",
|
|
53
|
+
"@opengeni/codex": "6.8.0",
|
|
54
|
+
"@opengeni/config": "6.8.0",
|
|
55
|
+
"@opengeni/contracts": "6.8.0",
|
|
56
|
+
"@opengeni/core": "6.8.0",
|
|
57
|
+
"@opengeni/db": "6.8.0",
|
|
58
|
+
"@opengeni/documents": "6.8.0",
|
|
59
|
+
"@opengeni/events": "6.8.0",
|
|
60
|
+
"@opengeni/github": "6.8.0",
|
|
61
|
+
"@opengeni/interaction": "6.8.0",
|
|
62
|
+
"@opengeni/network": "6.8.0",
|
|
63
|
+
"@opengeni/observability": "6.8.0",
|
|
64
|
+
"@opengeni/runtime": "6.8.0",
|
|
65
|
+
"@opengeni/storage": "6.8.0",
|
|
66
|
+
"@opengeni/tool-gateway": "6.8.0",
|
|
67
|
+
"@opengeni/vaults": "6.8.0",
|
|
68
|
+
"@opengeni/vaults-bitwarden": "6.8.0",
|
|
69
|
+
"@opengeni/vaults-keeper": "6.8.0",
|
|
70
|
+
"@opengeni/vaults-onepassword": "6.8.0",
|
|
71
|
+
"@opengeni/vaults-protonpass": "6.8.0",
|
|
72
|
+
"@opengeni/xai-subscription": "6.8.0",
|
|
73
73
|
"@simplewebauthn/server": "14.0.3",
|
|
74
74
|
"@temporalio/client": "^1.17.0",
|
|
75
75
|
"ajv": "^8.20.0",
|
|
76
|
-
"better-auth": "^1.7.
|
|
76
|
+
"better-auth": "^1.7.16",
|
|
77
77
|
"hono": "^4.12.18",
|
|
78
78
|
"jose": "^6.1.3",
|
|
79
79
|
"json-bigint": "^1.0.0",
|
package/src/app.ts
CHANGED
|
@@ -165,6 +165,7 @@ import {
|
|
|
165
165
|
DATABASE_UNAVAILABLE_ERROR_DETAIL_CODE,
|
|
166
166
|
databaseContentionHttpError,
|
|
167
167
|
databaseUnavailableHttpError,
|
|
168
|
+
modelPolicyRefusedHttpError,
|
|
168
169
|
modelUnavailableHttpError,
|
|
169
170
|
connectionAccountSelectionHttpError,
|
|
170
171
|
regionRestrictedHttpError,
|
|
@@ -2647,6 +2648,7 @@ export function createAppComposition(deps: AppDependencies): {
|
|
|
2647
2648
|
scheduledTaskTargetAccessHttpError(rawError) ??
|
|
2648
2649
|
agentConfigHttpError(rawError) ??
|
|
2649
2650
|
modelUnavailableHttpError(rawError) ??
|
|
2651
|
+
modelPolicyRefusedHttpError(rawError) ??
|
|
2650
2652
|
connectionAccountSelectionHttpError(rawError) ??
|
|
2651
2653
|
(rawError instanceof UnsupportedLatencyModeError
|
|
2652
2654
|
? new ApiHttpError(422, {
|
package/src/http/api-error.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
UPGRADE_PLAN_ACTION,
|
|
8
8
|
byokRefusalAction,
|
|
9
9
|
AllowanceExhaustedRefusal,
|
|
10
|
+
ModelPolicyRefusedError,
|
|
10
11
|
ModelUnavailableError,
|
|
11
12
|
ScheduledTaskTargetAccessChange,
|
|
12
13
|
type ErrorCode,
|
|
@@ -373,6 +374,28 @@ export function modelUnavailableHttpError(error: unknown): ApiHttpError | null {
|
|
|
373
374
|
});
|
|
374
375
|
}
|
|
375
376
|
|
|
377
|
+
/**
|
|
378
|
+
* A model the workspace's model policy refuses. The same request is refused
|
|
379
|
+
* again until someone changes the model or the policy, so clients get
|
|
380
|
+
* `details.code: "model_policy"` with the rule (`reason`) instead of a retry.
|
|
381
|
+
*/
|
|
382
|
+
export function modelPolicyRefusedHttpError(error: unknown): ApiHttpError | null {
|
|
383
|
+
const cause =
|
|
384
|
+
error instanceof ModelPolicyRefusedError
|
|
385
|
+
? error
|
|
386
|
+
: error instanceof HTTPException && error.cause instanceof ModelPolicyRefusedError
|
|
387
|
+
? error.cause
|
|
388
|
+
: null;
|
|
389
|
+
if (!cause) return null;
|
|
390
|
+
return new ApiHttpError(422, {
|
|
391
|
+
code: "validation_failed",
|
|
392
|
+
message: cause.message,
|
|
393
|
+
retryable: false,
|
|
394
|
+
outcomeUnknown: false,
|
|
395
|
+
details: { code: cause.code, modelId: cause.modelId, reason: cause.reason },
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
|
|
376
399
|
/** Keep a rejected credential selection actionable without changing its authority. */
|
|
377
400
|
export function connectionAccountSelectionHttpError(error: unknown): ApiHttpError | null {
|
|
378
401
|
if (!(error instanceof ConnectionAccountSelectionError)) return null;
|
|
@@ -11,7 +11,9 @@ import { ErrorCode, Permission } from "@opengeni/contracts";
|
|
|
11
11
|
* from the closed permission catalog (as `details.permission`, or in a
|
|
12
12
|
* legacy "missing permission: <name>" message), else the envelope's typed
|
|
13
13
|
* `details.code` when it is a short identifier, else `control:<code>` for a
|
|
14
|
-
* Connected Machine control failure, else
|
|
14
|
+
* Connected Machine control failure, else (for a route's own top-level
|
|
15
|
+
* `{ code, message, details }` body, such as session create) its
|
|
16
|
+
* UPPER_SNAKE route code, else `unclassified`.
|
|
15
17
|
* - `fingerprint` is a one-way hash of the message with identifiers and
|
|
16
18
|
* numbers normalized away. It groups identical refusals in logs; resolve it
|
|
17
19
|
* back to source text with `bun run scripts/resolve-rejection-fingerprint.ts`.
|
|
@@ -28,6 +30,8 @@ const PERMISSIONS: ReadonlySet<string> = new Set(Permission.options);
|
|
|
28
30
|
const DETAIL_CODE = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;
|
|
29
31
|
const MISSING_PERMISSION = /^missing (?:literal )?permission: ([a-z][a-z0-9-]*:[a-z][a-z0-9-]*)/;
|
|
30
32
|
const CONTROL_CODE = /^[a-z][a-z0-9_]{0,31}$/;
|
|
33
|
+
/** A route's own authored top-level code, such as `SESSION_CREATE_REJECTED`. */
|
|
34
|
+
const ROUTE_CODE = /^[A-Z][A-Z0-9_]{2,63}$/;
|
|
31
35
|
const MAX_ENVELOPE_BYTES = 32 * 1024;
|
|
32
36
|
|
|
33
37
|
export const UNCLASSIFIED_REJECTION_REASON = "unclassified";
|
|
@@ -59,15 +63,26 @@ function permissionReason(permission: unknown): string | null {
|
|
|
59
63
|
: null;
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Classify a parsed `ErrorEnvelope`-shaped body. Unknown shapes still get a code.
|
|
68
|
+
* A route that answers with its own top-level `{ code, message, details }`
|
|
69
|
+
* (session create) is read the same way, so its refusals are not all
|
|
70
|
+
* "unclassified": the reason is its typed `details.code`, else its own route
|
|
71
|
+
* code, and the message is fingerprinted. Only a body whose top-level code is
|
|
72
|
+
* one of our authored UPPER_SNAKE route codes counts, so a passed-through
|
|
73
|
+
* upstream body can never add reason values.
|
|
74
|
+
*/
|
|
63
75
|
export function httpRejectionFactsFromEnvelope(
|
|
64
76
|
envelope: unknown,
|
|
65
77
|
fallbackCode: string,
|
|
66
78
|
): HttpRejectionFacts {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
const body = envelope && typeof envelope === "object" ? envelope : undefined;
|
|
80
|
+
const routeShaped =
|
|
81
|
+
body !== undefined &&
|
|
82
|
+
!("error" in body) &&
|
|
83
|
+
typeof (body as { code?: unknown }).code === "string" &&
|
|
84
|
+
ROUTE_CODE.test((body as { code: string }).code);
|
|
85
|
+
const error = routeShaped ? body : (body as { error?: unknown } | undefined)?.error;
|
|
71
86
|
const record = error && typeof error === "object" ? (error as Record<string, unknown>) : {};
|
|
72
87
|
const code =
|
|
73
88
|
typeof record.code === "string" && ERROR_CODES.has(record.code) ? record.code : fallbackCode;
|
|
@@ -82,6 +97,10 @@ export function httpRejectionFactsFromEnvelope(
|
|
|
82
97
|
typeof details?.controlFailureCode === "string" && CONTROL_CODE.test(details.controlFailureCode)
|
|
83
98
|
? `control:${details.controlFailureCode}`
|
|
84
99
|
: null;
|
|
100
|
+
const routeCode =
|
|
101
|
+
routeShaped && typeof record.code === "string" && !ERROR_CODES.has(record.code)
|
|
102
|
+
? record.code
|
|
103
|
+
: null;
|
|
85
104
|
return {
|
|
86
105
|
code,
|
|
87
106
|
reason:
|
|
@@ -89,6 +108,7 @@ export function httpRejectionFactsFromEnvelope(
|
|
|
89
108
|
rejectionReasonFromMessage(message) ??
|
|
90
109
|
detailCode ??
|
|
91
110
|
controlCode ??
|
|
111
|
+
routeCode ??
|
|
92
112
|
UNCLASSIFIED_REJECTION_REASON,
|
|
93
113
|
...(message ? { fingerprint: rejectionFingerprint(message) } : {}),
|
|
94
114
|
};
|
package/src/mcp/secret-tools.ts
CHANGED
|
@@ -134,7 +134,7 @@ export function registerSecretTools(
|
|
|
134
134
|
"secret_save",
|
|
135
135
|
{
|
|
136
136
|
description:
|
|
137
|
-
'Save or update a secret item (login, API key, note) and get its references back. For a new password use a field with `generate` (for example {name: "password", generate: {length: 24}}) and save it before typing it anywhere; copy an existing secret with `fromReference`. Put a username in `username
|
|
137
|
+
'Save or update a secret item (login, API key, note) and get its references back. For a new password use a field with `generate` (for example {name: "password", generate: {length: 24}}) and save it before typing it anywhere; copy an existing secret with `fromReference`. Put a username in `username`; keys, tokens and passwords belong in concealed fields (a new plain field whose value looks like one is saved as concealed, reported in `fieldNotes`). saveTo picks the vault: user (Only me), task (this task) or workspace; it defaults to Only me when a person started this work, otherwise the workspace. Values are never echoed; avoid putting a literal `value` here unless the task gave you that exact value.',
|
|
138
138
|
inputSchema: SecretSaveInput.shape,
|
|
139
139
|
},
|
|
140
140
|
(input) =>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CODEX_CLIENT_VERSION,
|
|
3
|
+
CODEX_PROVIDER_ID,
|
|
4
|
+
fetchCodexModels,
|
|
5
|
+
type CodexFetch,
|
|
6
|
+
} from "@opengeni/codex";
|
|
7
|
+
import { configuredModels, withCodexCatalogProvider, type Settings } from "@opengeni/config";
|
|
8
|
+
|
|
9
|
+
/** A Codex model the just-connected account offers, as Opengeni names it. */
|
|
10
|
+
export type CodexConnectOfferedModel = { id: string; label: string };
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Opengeni's Codex models, optionally only those whose upstream slug is in
|
|
14
|
+
* `supportedSlugs`. The one filter the picker (`codexModelsForPicker`) and the
|
|
15
|
+
* connect result share, so both always name the same models.
|
|
16
|
+
*/
|
|
17
|
+
export function codexCatalogModels(settings: Settings, supportedSlugs?: readonly string[]) {
|
|
18
|
+
return configuredModels(withCodexCatalogProvider(settings)).filter(
|
|
19
|
+
(model) =>
|
|
20
|
+
model.providerId === CODEX_PROVIDER_ID &&
|
|
21
|
+
(supportedSlugs === undefined || supportedSlugs.includes(model.upstreamModelId)),
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Which of Opengeni's Codex models a just-connected ChatGPT account offers,
|
|
27
|
+
* read once from its live /models list with the tokens the sign-in returned
|
|
28
|
+
* (nothing is stored). A Free plan offers GPT-6 Luna only; an account that
|
|
29
|
+
* offers none of them is told so at connect time instead of at Send.
|
|
30
|
+
*
|
|
31
|
+
* The list is taken as the backend returns it for this client version: the
|
|
32
|
+
* Codex CLI shows every listed model to ChatGPT sign-ins (`supported_in_api`
|
|
33
|
+
* only filters API-key sign-ins) and the backend applies
|
|
34
|
+
* `minimal_client_version` itself from the `client_version` query.
|
|
35
|
+
*
|
|
36
|
+
* Null when the read fails: the connection still succeeded.
|
|
37
|
+
*/
|
|
38
|
+
export async function codexConnectOfferedModels(input: {
|
|
39
|
+
settings: Settings;
|
|
40
|
+
accessToken: string;
|
|
41
|
+
chatgptAccountId: string | null;
|
|
42
|
+
isFedramp: boolean;
|
|
43
|
+
fetchImpl?: CodexFetch | undefined;
|
|
44
|
+
}): Promise<CodexConnectOfferedModel[] | null> {
|
|
45
|
+
try {
|
|
46
|
+
const read = await fetchCodexModels(
|
|
47
|
+
{
|
|
48
|
+
accessToken: input.accessToken,
|
|
49
|
+
chatgptAccountId: input.chatgptAccountId,
|
|
50
|
+
isFedramp: input.isFedramp,
|
|
51
|
+
clientVersion: CODEX_CLIENT_VERSION,
|
|
52
|
+
},
|
|
53
|
+
input.fetchImpl,
|
|
54
|
+
);
|
|
55
|
+
if (!read.ok) return null;
|
|
56
|
+
// The same models, filter and labels as the picker (codexModelsForPicker).
|
|
57
|
+
return codexCatalogModels(input.settings, read.slugs).map((model) => ({
|
|
58
|
+
id: model.id,
|
|
59
|
+
label: model.label,
|
|
60
|
+
}));
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/routes/codex-core.ts
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
type DisconnectAuditActor,
|
|
34
34
|
} from "@opengeni/db";
|
|
35
35
|
import type { CodexFetch, CodexUsagePayload } from "@opengeni/codex";
|
|
36
|
+
import type { CodexConnectOfferedModel } from "./codex-connect-models";
|
|
36
37
|
import {
|
|
37
38
|
codexAccountJson,
|
|
38
39
|
codexModelsForPicker,
|
|
@@ -76,6 +77,8 @@ export async function coreCodexConnected(
|
|
|
76
77
|
/** The shared workspace the person added their own subscription from (D-53). */
|
|
77
78
|
addedFrom?: string | undefined;
|
|
78
79
|
credential: SubscriptionCoreCodexCredentialInput;
|
|
80
|
+
/** The account's offered Codex models, read once after it connects. */
|
|
81
|
+
offeredModels?: (() => Promise<CodexConnectOfferedModel[] | null>) | undefined;
|
|
79
82
|
},
|
|
80
83
|
) {
|
|
81
84
|
const result = await connectSubscriptionCoreCodexConnection(deps.db, {
|
|
@@ -138,11 +141,15 @@ export async function coreCodexConnected(
|
|
|
138
141
|
).rotation.activeCredentialId
|
|
139
142
|
: (await projection(deps, input.accountId, input.workspaceId, input.subjectId)).rotation
|
|
140
143
|
.activeCredentialId;
|
|
144
|
+
// Which Opengeni models it offers, so connecting an account whose plan
|
|
145
|
+
// offers none (or only some) says so now rather than at Send.
|
|
146
|
+
const models = input.offeredModels ? await input.offeredModels().catch(() => null) : null;
|
|
141
147
|
return c.json({
|
|
142
148
|
status: "connected",
|
|
143
149
|
plan: input.credential.planType,
|
|
144
150
|
accountId: result.id,
|
|
145
151
|
isActive: activeCredentialId === result.id,
|
|
152
|
+
...(models ? { models } : {}),
|
|
146
153
|
});
|
|
147
154
|
}
|
|
148
155
|
|
package/src/routes/codex.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CodexRateLimitResetCreditsAccountResult } from "@opengeni/db";
|
|
2
2
|
import type { CodexResetRedemptionRecovery } from "@opengeni/db";
|
|
3
3
|
import { codexOverviewProviderCall, type CodexProviderCall } from "./codex-overview-budget";
|
|
4
|
+
import { codexCatalogModels, codexConnectOfferedModels } from "./codex-connect-models";
|
|
4
5
|
// Codex (ChatGPT) subscription connect / status / usage routes.
|
|
5
6
|
//
|
|
6
7
|
// Connect uses the device-code flow split into two stateless calls: `start`
|
|
@@ -12,10 +13,8 @@ import { codexOverviewProviderCall, type CodexProviderCall } from "./codex-overv
|
|
|
12
13
|
|
|
13
14
|
import {
|
|
14
15
|
environmentsEncryptionKeyBytes,
|
|
15
|
-
configuredModels,
|
|
16
16
|
getSettings,
|
|
17
17
|
productLabelForModelId,
|
|
18
|
-
withCodexCatalogProvider,
|
|
19
18
|
type Settings,
|
|
20
19
|
} from "@opengeni/config";
|
|
21
20
|
import {
|
|
@@ -216,19 +215,13 @@ export function codexModelsForPicker(
|
|
|
216
215
|
providerLabel: string;
|
|
217
216
|
api: "responses";
|
|
218
217
|
}> {
|
|
219
|
-
return
|
|
220
|
-
.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
id: model.id,
|
|
227
|
-
label: model.label,
|
|
228
|
-
provider: CODEX_PROVIDER_ID,
|
|
229
|
-
providerLabel: CODEX_PROVIDER_LABEL,
|
|
230
|
-
api: "responses" as const,
|
|
231
|
-
}));
|
|
218
|
+
return codexCatalogModels(settings, supportedSlugs).map((model) => ({
|
|
219
|
+
id: model.id,
|
|
220
|
+
label: model.label,
|
|
221
|
+
provider: CODEX_PROVIDER_ID,
|
|
222
|
+
providerLabel: CODEX_PROVIDER_LABEL,
|
|
223
|
+
api: "responses" as const,
|
|
224
|
+
}));
|
|
232
225
|
}
|
|
233
226
|
import { createSignedState, readSignedState } from "@opengeni/github";
|
|
234
227
|
import {
|
|
@@ -1030,6 +1023,14 @@ export function registerCodexRoutes(app: Hono, deps: ApiRouteDeps): void {
|
|
|
1030
1023
|
label: id.email ?? id.chatgptAccountId ?? null,
|
|
1031
1024
|
connectedBySubjectId: (await managedCookieHuman(c, deps))?.subjectId ?? null,
|
|
1032
1025
|
},
|
|
1026
|
+
offeredModels: async () =>
|
|
1027
|
+
await codexConnectOfferedModels({
|
|
1028
|
+
settings: (await resolveCatalogSettings(db, settings)).settings,
|
|
1029
|
+
accessToken: tokens.accessToken,
|
|
1030
|
+
chatgptAccountId: id.chatgptAccountId,
|
|
1031
|
+
isFedramp: id.isFedramp,
|
|
1032
|
+
fetchImpl: deps.codexFetch as CodexFetch | undefined,
|
|
1033
|
+
}),
|
|
1033
1034
|
});
|
|
1034
1035
|
});
|
|
1035
1036
|
|
|
@@ -1290,6 +1291,14 @@ export function registerCodexRoutes(app: Hono, deps: ApiRouteDeps): void {
|
|
|
1290
1291
|
label: id.email ?? id.chatgptAccountId ?? null,
|
|
1291
1292
|
connectedBySubjectId: connectingHuman?.subjectId ?? null,
|
|
1292
1293
|
},
|
|
1294
|
+
offeredModels: async () =>
|
|
1295
|
+
await codexConnectOfferedModels({
|
|
1296
|
+
settings: (await resolveCatalogSettings(db, settings)).settings,
|
|
1297
|
+
accessToken: tokens.accessToken,
|
|
1298
|
+
chatgptAccountId: id.chatgptAccountId,
|
|
1299
|
+
isFedramp: id.isFedramp,
|
|
1300
|
+
fetchImpl: deps.codexFetch as CodexFetch | undefined,
|
|
1301
|
+
}),
|
|
1293
1302
|
});
|
|
1294
1303
|
});
|
|
1295
1304
|
|
package/src/routes/sessions.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { listSessionEventSlices } from "@opengeni/db/session-event-slices";
|
|
|
15
15
|
import * as sessionPreviewSchema from "@opengeni/db/schema";
|
|
16
16
|
import { and, eq, sql } from "drizzle-orm";
|
|
17
17
|
import { SessionMessageSearchRequest } from "@opengeni/contracts";
|
|
18
|
+
import { ModelPolicyRefusedError, ModelUnavailableError } from "@opengeni/contracts";
|
|
18
19
|
import { ContinueAfterCapabilitySetupRequest } from "@opengeni/contracts";
|
|
19
20
|
import type { ContinueAfterCapabilitySetupResponse } from "@opengeni/contracts";
|
|
20
21
|
import {
|
|
@@ -7110,6 +7111,40 @@ export function sessionCreateErrorResponse(c: Context, error: unknown): Response
|
|
|
7110
7111
|
422,
|
|
7111
7112
|
);
|
|
7112
7113
|
}
|
|
7114
|
+
if (
|
|
7115
|
+
error instanceof HTTPException &&
|
|
7116
|
+
error.status === 422 &&
|
|
7117
|
+
error.cause instanceof ModelUnavailableError
|
|
7118
|
+
) {
|
|
7119
|
+
// Typed like every other route's refusal, so the composer can say the
|
|
7120
|
+
// model is unavailable instead of "check your input".
|
|
7121
|
+
return c.json(
|
|
7122
|
+
{
|
|
7123
|
+
code: "SESSION_CREATE_REJECTED",
|
|
7124
|
+
message: error.message,
|
|
7125
|
+
details: { code: error.cause.code, modelId: error.cause.modelId },
|
|
7126
|
+
},
|
|
7127
|
+
422,
|
|
7128
|
+
);
|
|
7129
|
+
}
|
|
7130
|
+
if (
|
|
7131
|
+
error instanceof HTTPException &&
|
|
7132
|
+
error.status === 422 &&
|
|
7133
|
+
error.cause instanceof ModelPolicyRefusedError
|
|
7134
|
+
) {
|
|
7135
|
+
return c.json(
|
|
7136
|
+
{
|
|
7137
|
+
code: "SESSION_CREATE_REJECTED",
|
|
7138
|
+
message: error.message,
|
|
7139
|
+
details: {
|
|
7140
|
+
code: error.cause.code,
|
|
7141
|
+
modelId: error.cause.modelId,
|
|
7142
|
+
reason: error.cause.reason,
|
|
7143
|
+
},
|
|
7144
|
+
},
|
|
7145
|
+
422,
|
|
7146
|
+
);
|
|
7147
|
+
}
|
|
7113
7148
|
if (error instanceof HTTPException && error.status === 422) {
|
|
7114
7149
|
return c.json(
|
|
7115
7150
|
{
|