@dsh-ray/coding-subscription-provider 0.0.1-seed.0 → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +98 -1
- package/cordis.patch.yml +8 -0
- package/lib/adapter.d.ts +120 -0
- package/lib/adapter.d.ts.map +1 -0
- package/lib/adapter.js +742 -0
- package/lib/adapter.js.map +1 -0
- package/lib/auth.d.ts +33 -0
- package/lib/auth.d.ts.map +1 -0
- package/lib/auth.js +101 -0
- package/lib/auth.js.map +1 -0
- package/lib/codex-catalog.d.ts +57 -0
- package/lib/codex-catalog.d.ts.map +1 -0
- package/lib/codex-catalog.js +369 -0
- package/lib/codex-catalog.js.map +1 -0
- package/lib/codex-direct-auth.d.ts +35 -0
- package/lib/codex-direct-auth.d.ts.map +1 -0
- package/lib/codex-direct-auth.js +626 -0
- package/lib/codex-direct-auth.js.map +1 -0
- package/lib/codex-direct-responses.d.ts +57 -0
- package/lib/codex-direct-responses.d.ts.map +1 -0
- package/lib/codex-direct-responses.js +1759 -0
- package/lib/codex-direct-responses.js.map +1 -0
- package/lib/config.d.ts +65 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +105 -0
- package/lib/config.js.map +1 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +70 -0
- package/lib/index.js.map +1 -0
- package/lib/process.d.ts +131 -0
- package/lib/process.d.ts.map +1 -0
- package/lib/process.js +1131 -0
- package/lib/process.js.map +1 -0
- package/lib/prompt.d.ts +15 -0
- package/lib/prompt.d.ts.map +1 -0
- package/lib/prompt.js +299 -0
- package/lib/prompt.js.map +1 -0
- package/lib/providers.d.ts +43 -0
- package/lib/providers.d.ts.map +1 -0
- package/lib/providers.js +179 -0
- package/lib/providers.js.map +1 -0
- package/lib/session-cwd.d.ts +26 -0
- package/lib/session-cwd.d.ts.map +1 -0
- package/lib/session-cwd.js +57 -0
- package/lib/session-cwd.js.map +1 -0
- package/lib/subscription-catalog.d.ts +51 -0
- package/lib/subscription-catalog.d.ts.map +1 -0
- package/lib/subscription-catalog.js +290 -0
- package/lib/subscription-catalog.js.map +1 -0
- package/lib/version.d.ts +2 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +2 -0
- package/lib/version.js.map +1 -0
- package/package.json +82 -4
package/lib/adapter.js
ADDED
|
@@ -0,0 +1,742 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { ToolCallId, CONTEXT_WINDOW_EXCEEDED_CODE, EMPTY_RESPONSE_CODE, LlmAdapter, LlmError, QUOTA_EXCEEDED_CODE, ReasoningEffortId, } from '@deepseek-ai/dsh-llm';
|
|
4
|
+
import { verifySubscriptionAuth } from './auth.js';
|
|
5
|
+
import { discoverCodexModels, } from './codex-catalog.js';
|
|
6
|
+
import { CodexCredentialStore } from './codex-direct-auth.js';
|
|
7
|
+
import { runCodexDirectResponses, } from './codex-direct-responses.js';
|
|
8
|
+
import { configForProvider, } from './config.js';
|
|
9
|
+
import { buildPrompt, CLI_PROMPT_LIMIT_CAUSE, parseDelegatedToolCalls } from './prompt.js';
|
|
10
|
+
import { runCliText } from './process.js';
|
|
11
|
+
import { buildInvocation } from './providers.js';
|
|
12
|
+
import { resolveTrustedSessionCwd, TrustedSessionCwdError } from './session-cwd.js';
|
|
13
|
+
import { discoverClaudeModels, discoverCursorModels, discoverGrokModels, } from './subscription-catalog.js';
|
|
14
|
+
export const routeDefinitions = [
|
|
15
|
+
{ route: 'codex-subscription', cli: 'codex', name: 'Codex Subscription (local CLI)', maturity: 'stable' },
|
|
16
|
+
{ route: 'claude-subscription', cli: 'claude', name: 'Claude Subscription (local Claude Code)', maturity: 'experimental' },
|
|
17
|
+
{ route: 'cursor-subscription', cli: 'cursor', name: 'Cursor Subscription (local Agent CLI)', maturity: 'experimental' },
|
|
18
|
+
{ route: 'grok-subscription', cli: 'grok', name: 'Grok Subscription (local Grok Build)', maturity: 'beta' },
|
|
19
|
+
];
|
|
20
|
+
const CATALOG_TTL_MS = 5 * 60_000;
|
|
21
|
+
const CATALOG_STDERR_DIAGNOSTIC = 'model catalog probe wrote to stderr; content withheld';
|
|
22
|
+
const noAutomaticRetry = Object.freeze({
|
|
23
|
+
mode: 'normal',
|
|
24
|
+
maxRetries: 0,
|
|
25
|
+
retryableCodes: Object.freeze([]),
|
|
26
|
+
initialDelayMs: 500,
|
|
27
|
+
maxDelayMs: 10_000,
|
|
28
|
+
jitterRatio: 0.1,
|
|
29
|
+
});
|
|
30
|
+
function definitionFor(route) {
|
|
31
|
+
const definition = routeDefinitions.find(candidate => candidate.route === route);
|
|
32
|
+
if (definition === undefined)
|
|
33
|
+
throw LlmError.fromFailure({ message: `unknown coding subscription provider: ${route}`, code: 'INVALID_PROVIDER' });
|
|
34
|
+
return definition;
|
|
35
|
+
}
|
|
36
|
+
function abortReason(signal) {
|
|
37
|
+
return signal.reason instanceof Error ? signal.reason : new Error('model resolution aborted');
|
|
38
|
+
}
|
|
39
|
+
function cliFailure(definition, command, error) {
|
|
40
|
+
if (error instanceof Error && error.cause === 'abort')
|
|
41
|
+
return error;
|
|
42
|
+
if (error instanceof TrustedSessionCwdError) {
|
|
43
|
+
return LlmError.fromFailure({ message: `${definition.name} requires a live loop-owned session whose canonical cwd matches the configured local workspace`, code: 'LOCAL_SESSION_CWD_REQUIRED' }, { cause: error });
|
|
44
|
+
}
|
|
45
|
+
if (error instanceof Error && error.cause === 'subscription-auth') {
|
|
46
|
+
return LlmError.fromFailure({ message: `${definition.name} refused the request because a subscription-compatible login could not be verified`, code: 'SUBSCRIPTION_AUTH_REQUIRED' }, { cause: error });
|
|
47
|
+
}
|
|
48
|
+
if (error instanceof Error && error.cause === 'working-directory') {
|
|
49
|
+
return LlmError.fromFailure({ message: `${definition.name} refused the configured working directory; set config.cwd to a Git repository (relative paths resolve from the DSH process directory) and restart DSH`, code: 'CLI_WORKING_DIRECTORY' }, { cause: error });
|
|
50
|
+
}
|
|
51
|
+
if (error instanceof Error && error.cause === 'protocol') {
|
|
52
|
+
return LlmError.fromFailure({ message: `${definition.name} returned an unrecognized or incomplete event stream`, code: 'CLI_PROTOCOL_ERROR' }, { cause: error });
|
|
53
|
+
}
|
|
54
|
+
const code = error?.code;
|
|
55
|
+
if (code === 'ENOENT') {
|
|
56
|
+
return LlmError.fromFailure({ message: `${definition.name} executable was not found: ${command}`, code: 'CLI_NOT_FOUND' }, { cause: error });
|
|
57
|
+
}
|
|
58
|
+
if (error instanceof Error && error.cause === 'timeout') {
|
|
59
|
+
return LlmError.fromFailure({ message: `${definition.name} timed out`, code: 'CLI_TIMEOUT' }, { cause: error });
|
|
60
|
+
}
|
|
61
|
+
return LlmError.fromFailure({ message: `${definition.name} failed; verify that the official CLI is installed and logged in with the intended subscription`, code: 'CLI_FAILED' }, { cause: error });
|
|
62
|
+
}
|
|
63
|
+
export const CODEX_DIRECT_PROVIDER_HTTP_CODE = 'CODEX_DIRECT_PROVIDER_HTTP';
|
|
64
|
+
export const CODEX_DIRECT_PROVIDER_FAILURE_CODE = 'CODEX_DIRECT_PROVIDER_FAILURE';
|
|
65
|
+
export const CODEX_DIRECT_CONTENT_FILTER_CODE = 'CODEX_DIRECT_CONTENT_FILTER';
|
|
66
|
+
export const CODEX_DIRECT_TRANSPORT_ERROR_CODE = 'CODEX_DIRECT_TRANSPORT_ERROR';
|
|
67
|
+
export const CLI_PROMPT_LIMIT_CODE = 'CLI_PROMPT_LIMIT';
|
|
68
|
+
function directFailure(definition, error) {
|
|
69
|
+
if (error instanceof LlmError)
|
|
70
|
+
return error;
|
|
71
|
+
if (error instanceof Error && error.cause === 'abort')
|
|
72
|
+
return error;
|
|
73
|
+
if (error instanceof TrustedSessionCwdError) {
|
|
74
|
+
return LlmError.fromFailure({ message: `${definition.name} requires a live loop-owned session whose canonical cwd matches the configured local workspace`, code: 'LOCAL_SESSION_CWD_REQUIRED' }, { cause: error });
|
|
75
|
+
}
|
|
76
|
+
const cause = error instanceof Error ? error.cause : undefined;
|
|
77
|
+
const status = validHttpStatus(error);
|
|
78
|
+
if (cause === 'subscription-auth') {
|
|
79
|
+
return LlmError.fromFailure({ message: 'Codex private Responses could not use the local ChatGPT session', code: 'SUBSCRIPTION_AUTH_REQUIRED', ...(status === undefined ? {} : { status }) });
|
|
80
|
+
}
|
|
81
|
+
if (cause === 'timeout') {
|
|
82
|
+
return LlmError.fromFailure({ message: 'Codex private Responses request timed out', code: 'CLI_TIMEOUT' });
|
|
83
|
+
}
|
|
84
|
+
if (cause === 'protocol') {
|
|
85
|
+
return LlmError.fromFailure({ message: 'Codex private Responses returned an unrecognized or incomplete stream', code: 'CLI_PROTOCOL_ERROR' });
|
|
86
|
+
}
|
|
87
|
+
if (cause === 'provider-http') {
|
|
88
|
+
return LlmError.fromFailure({ message: 'Codex private Responses provider request failed', code: CODEX_DIRECT_PROVIDER_HTTP_CODE, ...(status === undefined ? {} : { status }) });
|
|
89
|
+
}
|
|
90
|
+
if (cause === 'context-window') {
|
|
91
|
+
return LlmError.fromFailure({ message: 'Codex private Responses exceeded the model context window', code: CONTEXT_WINDOW_EXCEEDED_CODE });
|
|
92
|
+
}
|
|
93
|
+
if (cause === 'quota') {
|
|
94
|
+
return LlmError.fromFailure({ message: 'Codex private Responses account quota was exhausted', code: QUOTA_EXCEEDED_CODE });
|
|
95
|
+
}
|
|
96
|
+
if (cause === 'provider-failure') {
|
|
97
|
+
return LlmError.fromFailure({ message: 'Codex private Responses reported a provider failure', code: CODEX_DIRECT_PROVIDER_FAILURE_CODE });
|
|
98
|
+
}
|
|
99
|
+
if (cause === 'content-filter') {
|
|
100
|
+
return LlmError.fromFailure({ message: 'Codex private Responses output was filtered', code: CODEX_DIRECT_CONTENT_FILTER_CODE });
|
|
101
|
+
}
|
|
102
|
+
if (cause === 'empty-response') {
|
|
103
|
+
return LlmError.fromFailure({ message: 'Codex private Responses returned no visible output', code: EMPTY_RESPONSE_CODE });
|
|
104
|
+
}
|
|
105
|
+
if (cause === 'transport') {
|
|
106
|
+
return LlmError.fromFailure({ message: 'Codex private Responses transport failed', code: CODEX_DIRECT_TRANSPORT_ERROR_CODE });
|
|
107
|
+
}
|
|
108
|
+
return LlmError.fromFailure({ message: 'Codex private Responses request failed', code: 'CODEX_DIRECT_RESPONSES_FAILED' }, { cause: error });
|
|
109
|
+
}
|
|
110
|
+
function validHttpStatus(error) {
|
|
111
|
+
if (typeof error !== 'object' || error === null)
|
|
112
|
+
return undefined;
|
|
113
|
+
const status = error.status;
|
|
114
|
+
return typeof status === 'number' && Number.isInteger(status) && status >= 100 && status <= 599
|
|
115
|
+
? status
|
|
116
|
+
: undefined;
|
|
117
|
+
}
|
|
118
|
+
/** Keep local serialization safety limits distinct from a model context refusal. */
|
|
119
|
+
function preflightFailure(error) {
|
|
120
|
+
if (error instanceof Error && error.cause === CLI_PROMPT_LIMIT_CAUSE) {
|
|
121
|
+
return LlmError.fromFailure({ message: error.message, code: CLI_PROMPT_LIMIT_CODE }, { cause: error });
|
|
122
|
+
}
|
|
123
|
+
if (error instanceof Error && error.cause === 'prompt-limit') {
|
|
124
|
+
return LlmError.fromFailure({ message: error.message, code: CONTEXT_WINDOW_EXCEEDED_CODE }, { cause: error });
|
|
125
|
+
}
|
|
126
|
+
return error instanceof Error ? error : new Error('coding subscription provider could not serialize the DSH request');
|
|
127
|
+
}
|
|
128
|
+
/** Classify the original transport error into a stable, credential-free outcome for diagnostics. */
|
|
129
|
+
function outcomeFor(error) {
|
|
130
|
+
if (error instanceof TrustedSessionCwdError)
|
|
131
|
+
return 'working-directory';
|
|
132
|
+
const cause = error instanceof Error ? error.cause : undefined;
|
|
133
|
+
if (cause === 'abort')
|
|
134
|
+
return 'aborted';
|
|
135
|
+
if (cause === 'timeout')
|
|
136
|
+
return 'timeout';
|
|
137
|
+
if (cause === 'subscription-auth')
|
|
138
|
+
return 'auth-required';
|
|
139
|
+
if (cause === 'working-directory')
|
|
140
|
+
return 'working-directory';
|
|
141
|
+
if (cause === 'protocol')
|
|
142
|
+
return 'protocol';
|
|
143
|
+
if (cause === 'process-exit')
|
|
144
|
+
return 'process';
|
|
145
|
+
if (cause === 'output-limit')
|
|
146
|
+
return 'output-limit';
|
|
147
|
+
if (cause === 'line-limit')
|
|
148
|
+
return 'line-limit';
|
|
149
|
+
if (error?.code === 'ENOENT')
|
|
150
|
+
return 'not-found';
|
|
151
|
+
// A bare stream error carries no recognized cause but is a local I/O fault, not a model failure.
|
|
152
|
+
if (error instanceof Error && cause === undefined && !(error instanceof LlmError))
|
|
153
|
+
return 'io';
|
|
154
|
+
return 'failed';
|
|
155
|
+
}
|
|
156
|
+
function reasoningInfo(model) {
|
|
157
|
+
if (model?.reasoning === undefined)
|
|
158
|
+
return {};
|
|
159
|
+
return {
|
|
160
|
+
reasoning: {
|
|
161
|
+
efforts: model.reasoning.efforts.map(effort => ({
|
|
162
|
+
id: ReasoningEffortId(effort.id),
|
|
163
|
+
name: effort.name,
|
|
164
|
+
...(effort.description === undefined ? {} : { description: effort.description }),
|
|
165
|
+
})),
|
|
166
|
+
...(model.reasoning.defaultEffort === undefined
|
|
167
|
+
? {}
|
|
168
|
+
: { defaultEffort: ReasoningEffortId(model.reasoning.defaultEffort) }),
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function directReasoningInfo(profile) {
|
|
173
|
+
return {
|
|
174
|
+
reasoning: {
|
|
175
|
+
efforts: profile.directReasoningEfforts.map(effort => ({
|
|
176
|
+
id: ReasoningEffortId(effort),
|
|
177
|
+
name: effort,
|
|
178
|
+
})),
|
|
179
|
+
defaultEffort: ReasoningEffortId(profile.directDefaultReasoningEffort),
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** Experimental LLM-compatible facade over local, already-authenticated coding agents. */
|
|
184
|
+
export class CodingSubscriptionAdapter extends LlmAdapter {
|
|
185
|
+
config;
|
|
186
|
+
cwd;
|
|
187
|
+
runText;
|
|
188
|
+
discoverCodexModels;
|
|
189
|
+
discoverClaudeModels;
|
|
190
|
+
discoverCursorModels;
|
|
191
|
+
discoverGrokModels;
|
|
192
|
+
runCodexDirect;
|
|
193
|
+
codexCredentials;
|
|
194
|
+
getAttachments;
|
|
195
|
+
verifyAuth;
|
|
196
|
+
onDiagnostic;
|
|
197
|
+
onSettled;
|
|
198
|
+
liveSessions;
|
|
199
|
+
requestAttestor;
|
|
200
|
+
now;
|
|
201
|
+
lifecycle = new AbortController();
|
|
202
|
+
codexCatalogCache;
|
|
203
|
+
subscriptionCatalogCache = new Map();
|
|
204
|
+
catalogRefreshes = new Map();
|
|
205
|
+
constructor(config, dependencies = {}) {
|
|
206
|
+
super();
|
|
207
|
+
this.config = config;
|
|
208
|
+
this.cwd = resolve(config.cwd);
|
|
209
|
+
this.runText = dependencies.runText ?? runCliText;
|
|
210
|
+
this.discoverCodexModels = dependencies.discoverCodexModels ?? discoverCodexModels;
|
|
211
|
+
this.discoverClaudeModels = dependencies.discoverClaudeModels ?? discoverClaudeModels;
|
|
212
|
+
this.discoverCursorModels = dependencies.discoverCursorModels ?? discoverCursorModels;
|
|
213
|
+
this.discoverGrokModels = dependencies.discoverGrokModels ?? discoverGrokModels;
|
|
214
|
+
this.runCodexDirect = dependencies.runCodexDirect ?? runCodexDirectResponses;
|
|
215
|
+
this.codexCredentials = dependencies.codexCredentials ?? new CodexCredentialStore();
|
|
216
|
+
this.getAttachments = dependencies.getAttachments ?? (() => dependencies.attachments);
|
|
217
|
+
this.verifyAuth = dependencies.verifyAuth ?? verifySubscriptionAuth;
|
|
218
|
+
this.onDiagnostic = dependencies.onDiagnostic;
|
|
219
|
+
this.onSettled = dependencies.onSettled;
|
|
220
|
+
this.liveSessions = dependencies.liveSessions;
|
|
221
|
+
this.requestAttestor = dependencies.requestAttestor;
|
|
222
|
+
this.now = dependencies.now ?? Date.now;
|
|
223
|
+
}
|
|
224
|
+
trustedCwd(request) {
|
|
225
|
+
return resolveTrustedSessionCwd({
|
|
226
|
+
request,
|
|
227
|
+
configuredCwd: this.cwd,
|
|
228
|
+
sessions: this.liveSessions,
|
|
229
|
+
...(this.requestAttestor === undefined ? {} : { attestor: this.requestAttestor }),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
reportSettled(context) {
|
|
233
|
+
if (this.onSettled === undefined)
|
|
234
|
+
return;
|
|
235
|
+
try {
|
|
236
|
+
this.onSettled(context);
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
// A diagnostic sink must never change model-call settlement.
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
providerInfo(provider) {
|
|
243
|
+
const definition = definitionFor(provider);
|
|
244
|
+
return {
|
|
245
|
+
id: provider,
|
|
246
|
+
name: definition.cli === 'codex' && this.config.codex.transport === 'direct-responses'
|
|
247
|
+
? 'Codex Subscription (private Responses, experimental)'
|
|
248
|
+
: definition.name,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
providerRetryPolicy(_provider) {
|
|
252
|
+
return noAutomaticRetry;
|
|
253
|
+
}
|
|
254
|
+
peekCodexCatalog() {
|
|
255
|
+
const cached = this.codexCatalogCache;
|
|
256
|
+
if (cached !== undefined && cached.expiresAt > this.now())
|
|
257
|
+
return cached.catalog;
|
|
258
|
+
this.codexCatalogCache = undefined;
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
peekSubscriptionCatalog(provider) {
|
|
262
|
+
const cached = this.subscriptionCatalogCache.get(provider);
|
|
263
|
+
if (cached !== undefined && cached.expiresAt > this.now())
|
|
264
|
+
return cached.catalog;
|
|
265
|
+
this.subscriptionCatalogCache.delete(provider);
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Observe the advisory Codex CLI catalog with bounded, prompt-free control-plane I/O.
|
|
270
|
+
* Authentication is owned by `refreshCatalog`; this method only performs discovery.
|
|
271
|
+
*/
|
|
272
|
+
async observeCodexCatalog(cwd, signal) {
|
|
273
|
+
if (signal.aborted)
|
|
274
|
+
throw abortReason(signal);
|
|
275
|
+
const cached = this.peekCodexCatalog();
|
|
276
|
+
if (cached !== undefined)
|
|
277
|
+
return cached;
|
|
278
|
+
const definition = definitionFor('codex-subscription');
|
|
279
|
+
const profile = this.config.codex;
|
|
280
|
+
try {
|
|
281
|
+
const catalog = await this.discoverCodexModels({ command: profile.command, cwd }, {
|
|
282
|
+
signal,
|
|
283
|
+
timeoutMs: this.config.authProbeTimeoutMs,
|
|
284
|
+
killGraceMs: this.config.killGraceMs,
|
|
285
|
+
maxLineBytes: this.config.maxLineBytes,
|
|
286
|
+
maxOutputBytes: this.config.maxOutputBytes,
|
|
287
|
+
maxStderrBytes: this.config.maxStderrBytes,
|
|
288
|
+
extraEnvNames: this.config.extraEnvNames,
|
|
289
|
+
onDiagnostic: () => {
|
|
290
|
+
try {
|
|
291
|
+
this.onDiagnostic?.(definition.route, CATALOG_STDERR_DIAGNOSTIC);
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
// A diagnostic sink must never affect catalog discovery.
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
if (signal.aborted)
|
|
299
|
+
throw abortReason(signal);
|
|
300
|
+
this.codexCatalogCache = { catalog, expiresAt: this.now() + CATALOG_TTL_MS };
|
|
301
|
+
return catalog;
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
this.codexCatalogCache = undefined;
|
|
305
|
+
throw error;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async observeSubscriptionCatalog(provider, cwd, signal) {
|
|
309
|
+
if (signal.aborted)
|
|
310
|
+
throw abortReason(signal);
|
|
311
|
+
const cached = this.peekSubscriptionCatalog(provider);
|
|
312
|
+
if (cached !== undefined)
|
|
313
|
+
return cached;
|
|
314
|
+
const profile = configForProvider(this.config, provider);
|
|
315
|
+
const discoverer = provider === 'claude'
|
|
316
|
+
? this.discoverClaudeModels
|
|
317
|
+
: provider === 'cursor'
|
|
318
|
+
? this.discoverCursorModels
|
|
319
|
+
: this.discoverGrokModels;
|
|
320
|
+
try {
|
|
321
|
+
const catalog = await discoverer({ command: profile.command, cwd }, {
|
|
322
|
+
signal,
|
|
323
|
+
timeoutMs: this.config.authProbeTimeoutMs,
|
|
324
|
+
maxOutputBytes: this.config.maxAuthProbeBytes,
|
|
325
|
+
extraEnvNames: this.config.extraEnvNames,
|
|
326
|
+
});
|
|
327
|
+
if (signal.aborted)
|
|
328
|
+
throw abortReason(signal);
|
|
329
|
+
this.subscriptionCatalogCache.set(provider, { catalog, expiresAt: this.now() + CATALOG_TTL_MS });
|
|
330
|
+
return catalog;
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
this.subscriptionCatalogCache.delete(provider);
|
|
334
|
+
throw error;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
observedCatalog(provider) {
|
|
338
|
+
return provider === 'codex'
|
|
339
|
+
? this.peekCodexCatalog()
|
|
340
|
+
: this.peekSubscriptionCatalog(provider);
|
|
341
|
+
}
|
|
342
|
+
observeCatalog(provider, cwd, signal) {
|
|
343
|
+
return provider === 'codex'
|
|
344
|
+
? this.observeCodexCatalog(cwd, signal)
|
|
345
|
+
: this.observeSubscriptionCatalog(provider, cwd, signal);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Refresh one CLI catalog after the existing subscription-auth gate. Concurrent
|
|
349
|
+
* list callers share the complete auth + discovery operation, so a cold picker
|
|
350
|
+
* cannot fan out local probes. Generation never enters or waits on this path.
|
|
351
|
+
*/
|
|
352
|
+
refreshCatalog(provider, cwd) {
|
|
353
|
+
const refreshSignal = this.lifecycle.signal;
|
|
354
|
+
if (refreshSignal.aborted)
|
|
355
|
+
return Promise.reject(abortReason(refreshSignal));
|
|
356
|
+
const cached = this.observedCatalog(provider);
|
|
357
|
+
if (cached !== undefined)
|
|
358
|
+
return Promise.resolve(cached);
|
|
359
|
+
const active = this.catalogRefreshes.get(provider);
|
|
360
|
+
if (active !== undefined)
|
|
361
|
+
return active;
|
|
362
|
+
const profile = configForProvider(this.config, provider);
|
|
363
|
+
let refresh;
|
|
364
|
+
refresh = (async () => {
|
|
365
|
+
await this.verifyAuth(provider, {
|
|
366
|
+
command: profile.command,
|
|
367
|
+
cwd,
|
|
368
|
+
timeoutMs: this.config.authProbeTimeoutMs,
|
|
369
|
+
maxOutputBytes: this.config.maxAuthProbeBytes,
|
|
370
|
+
extraEnvNames: this.config.extraEnvNames,
|
|
371
|
+
signal: refreshSignal,
|
|
372
|
+
...(provider === 'grok'
|
|
373
|
+
? { userVerifiedSubscription: this.config.grok.userVerifiedSubscription }
|
|
374
|
+
: {}),
|
|
375
|
+
});
|
|
376
|
+
if (refreshSignal.aborted)
|
|
377
|
+
throw abortReason(refreshSignal);
|
|
378
|
+
return this.observeCatalog(provider, cwd, refreshSignal);
|
|
379
|
+
})().finally(() => {
|
|
380
|
+
if (this.catalogRefreshes.get(provider) === refresh)
|
|
381
|
+
this.catalogRefreshes.delete(provider);
|
|
382
|
+
});
|
|
383
|
+
this.catalogRefreshes.set(provider, refresh);
|
|
384
|
+
return refresh;
|
|
385
|
+
}
|
|
386
|
+
reportCatalogRefreshFailure(definition, error) {
|
|
387
|
+
if (this.lifecycle.signal.aborted)
|
|
388
|
+
return;
|
|
389
|
+
const diagnostic = `model catalog refresh failed; outcome=${outcomeFor(error)}; using configured models`;
|
|
390
|
+
try {
|
|
391
|
+
this.onDiagnostic?.(definition.route, diagnostic);
|
|
392
|
+
}
|
|
393
|
+
catch {
|
|
394
|
+
// A diagnostic sink must never turn advisory catalog failure into listModels failure.
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
async listModels(provider) {
|
|
398
|
+
const definition = definitionFor(provider);
|
|
399
|
+
const profile = configForProvider(this.config, definition.cli);
|
|
400
|
+
const directCodex = definition.cli === 'codex' && this.config.codex.transport === 'direct-responses';
|
|
401
|
+
let catalog;
|
|
402
|
+
if (!directCodex && !this.lifecycle.signal.aborted) {
|
|
403
|
+
try {
|
|
404
|
+
catalog = await this.refreshCatalog(definition.cli, this.cwd);
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
this.reportCatalogRefreshFailure(definition, error);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const attachments = directCodex ? this.getAttachments() : undefined;
|
|
411
|
+
const inputModalities = directCodex && attachments !== undefined
|
|
412
|
+
? ['text', 'image']
|
|
413
|
+
: ['text'];
|
|
414
|
+
const defaultModel = catalog?.models.find(model => model.id === catalog.defaultModel);
|
|
415
|
+
const entries = new Map();
|
|
416
|
+
for (const model of profile.models) {
|
|
417
|
+
entries.set(model, {
|
|
418
|
+
provider,
|
|
419
|
+
id: model,
|
|
420
|
+
name: directCodex && model === 'default'
|
|
421
|
+
? `Codex Subscription (private Responses) default (${this.config.codex.directModel})`
|
|
422
|
+
: model === 'default'
|
|
423
|
+
? `${definition.name} default${defaultModel === undefined ? '' : ` (${defaultModel.name})`}`
|
|
424
|
+
: model,
|
|
425
|
+
description: directCodex
|
|
426
|
+
? 'experimental direct private Codex Responses transport using the local ChatGPT session'
|
|
427
|
+
: `${definition.maturity} local coding-agent delegation; authentication and billing remain in the official CLI`,
|
|
428
|
+
inputModalities,
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
for (const model of catalog?.models ?? []) {
|
|
432
|
+
entries.set(model.id, {
|
|
433
|
+
provider,
|
|
434
|
+
id: model.id,
|
|
435
|
+
name: model.name,
|
|
436
|
+
...(model.description === undefined ? {} : { description: model.description }),
|
|
437
|
+
inputModalities: ['text'],
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
return [...entries.values()];
|
|
441
|
+
}
|
|
442
|
+
async resolveModel(provider, model, signal) {
|
|
443
|
+
const effectiveSignal = signal === undefined
|
|
444
|
+
? this.lifecycle.signal
|
|
445
|
+
: AbortSignal.any([signal, this.lifecycle.signal]);
|
|
446
|
+
if (effectiveSignal.aborted)
|
|
447
|
+
throw abortReason(effectiveSignal);
|
|
448
|
+
const definition = definitionFor(provider);
|
|
449
|
+
const profile = configForProvider(this.config, definition.cli);
|
|
450
|
+
const directCodex = definition.cli === 'codex' && this.config.codex.transport === 'direct-responses';
|
|
451
|
+
const catalog = directCodex ? undefined : this.observedCatalog(definition.cli);
|
|
452
|
+
const catalogModel = model === 'default'
|
|
453
|
+
? catalog?.models.find(candidate => candidate.id === catalog.defaultModel)
|
|
454
|
+
: catalog?.models.find(candidate => candidate.id === model);
|
|
455
|
+
const attachments = directCodex ? this.getAttachments() : undefined;
|
|
456
|
+
return {
|
|
457
|
+
provider,
|
|
458
|
+
id: model,
|
|
459
|
+
name: directCodex && model === 'default'
|
|
460
|
+
? `Codex Subscription (private Responses) default (${this.config.codex.directModel})`
|
|
461
|
+
: model === 'default'
|
|
462
|
+
? `${definition.name} default${catalogModel === undefined ? '' : ` (${catalogModel.name})`}`
|
|
463
|
+
: (catalogModel?.name ?? model),
|
|
464
|
+
description: catalogModel?.description ?? (directCodex
|
|
465
|
+
? 'experimental direct private Codex Responses transport using the local ChatGPT session'
|
|
466
|
+
: `${definition.maturity} local coding-agent delegation`),
|
|
467
|
+
inputModalities: directCodex && attachments !== undefined ? ['text', 'image'] : ['text'],
|
|
468
|
+
context: { contextWindow: profile.contextWindow },
|
|
469
|
+
...(directCodex ? directReasoningInfo(this.config.codex) : reasoningInfo(catalogModel)),
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
async *stream(options) {
|
|
473
|
+
const definition = definitionFor(options.provider);
|
|
474
|
+
const profile = configForProvider(this.config, definition.cli);
|
|
475
|
+
const signal = options.signal === undefined
|
|
476
|
+
? this.lifecycle.signal
|
|
477
|
+
: AbortSignal.any([options.signal, this.lifecycle.signal]);
|
|
478
|
+
let assistantTextForwarded = false;
|
|
479
|
+
let transportContext;
|
|
480
|
+
// Track the best-known lifecycle facts so a single settled report fires on ANY exit,
|
|
481
|
+
// including a consumer that returns early after block-start or a text delta.
|
|
482
|
+
let phase = 'preflight';
|
|
483
|
+
let promptSubmissionState = 'not-submitted';
|
|
484
|
+
let outcome = 'aborted';
|
|
485
|
+
let reported = false;
|
|
486
|
+
const settle = () => {
|
|
487
|
+
if (reported)
|
|
488
|
+
return;
|
|
489
|
+
reported = true;
|
|
490
|
+
this.reportSettled({
|
|
491
|
+
route: definition.route,
|
|
492
|
+
phase: transportContext?.phase ?? phase,
|
|
493
|
+
promptSubmissionState: transportContext?.promptSubmissionState ?? promptSubmissionState,
|
|
494
|
+
assistantTextObserved: transportContext?.assistantTextObserved ?? assistantTextForwarded,
|
|
495
|
+
assistantTextForwarded,
|
|
496
|
+
outcome,
|
|
497
|
+
teardownState: transportContext?.teardownState ?? 'not-started',
|
|
498
|
+
...(transportContext?.terminalReason !== undefined ? { terminalReason: transportContext.terminalReason } : {}),
|
|
499
|
+
...(transportContext?.exitCode !== undefined ? { exitCode: transportContext.exitCode } : {}),
|
|
500
|
+
...(transportContext?.signal !== undefined ? { signal: transportContext.signal } : {}),
|
|
501
|
+
...(transportContext?.metrics !== undefined ? { metrics: transportContext.metrics } : {}),
|
|
502
|
+
});
|
|
503
|
+
};
|
|
504
|
+
try {
|
|
505
|
+
if (signal.aborted)
|
|
506
|
+
throw abortReason(signal);
|
|
507
|
+
const directCodex = definition.cli === 'codex' && this.config.codex.transport === 'direct-responses';
|
|
508
|
+
let cwd;
|
|
509
|
+
try {
|
|
510
|
+
cwd = this.trustedCwd(options);
|
|
511
|
+
}
|
|
512
|
+
catch (error) {
|
|
513
|
+
outcome = outcomeFor(error);
|
|
514
|
+
throw cliFailure(definition, profile.command, error);
|
|
515
|
+
}
|
|
516
|
+
if (directCodex) {
|
|
517
|
+
const timeoutSignal = AbortSignal.timeout(this.config.timeoutMs);
|
|
518
|
+
const directSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
519
|
+
try {
|
|
520
|
+
// Revalidate immediately before the first credential/file/network seam.
|
|
521
|
+
this.trustedCwd(options);
|
|
522
|
+
// `maxTokens` is a host-local Agent Loop budget. The private Codex
|
|
523
|
+
// request has no max_output_tokens field, so do not hand this hint to
|
|
524
|
+
// the direct runner (which deliberately rejects unsupported controls).
|
|
525
|
+
const { maxTokens: hostMaxTokens, ...directInput } = options;
|
|
526
|
+
void hostMaxTokens;
|
|
527
|
+
const directOptions = {
|
|
528
|
+
...directInput,
|
|
529
|
+
model: options.model === 'default' ? this.config.codex.directModel : options.model,
|
|
530
|
+
signal: directSignal,
|
|
531
|
+
};
|
|
532
|
+
const attachments = this.getAttachments();
|
|
533
|
+
const chunks = this.runCodexDirect(directOptions, {
|
|
534
|
+
request: (body, requestSignal, routing) => {
|
|
535
|
+
phase = 'stream';
|
|
536
|
+
promptSubmissionState = 'unknown';
|
|
537
|
+
return this.codexCredentials.requestResponses(body, requestSignal, routing);
|
|
538
|
+
},
|
|
539
|
+
maxRequestBytes: this.config.codex.maxRequestBytes,
|
|
540
|
+
maxRequestImageBytes: this.config.codex.maxRequestImageBytes,
|
|
541
|
+
...(attachments === undefined ? {} : { attachments }),
|
|
542
|
+
});
|
|
543
|
+
for await (const chunk of chunks) {
|
|
544
|
+
if (chunk.type === 'text-delta' && chunk.text.length > 0)
|
|
545
|
+
assistantTextForwarded = true;
|
|
546
|
+
yield chunk;
|
|
547
|
+
}
|
|
548
|
+
outcome = 'ok';
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
catch (error) {
|
|
552
|
+
if (signal.aborted) {
|
|
553
|
+
outcome = 'aborted';
|
|
554
|
+
throw abortReason(signal);
|
|
555
|
+
}
|
|
556
|
+
if (error instanceof Error && error.cause === 'prompt-limit') {
|
|
557
|
+
phase = 'preflight';
|
|
558
|
+
promptSubmissionState = 'not-submitted';
|
|
559
|
+
outcome = 'preflight';
|
|
560
|
+
throw preflightFailure(error);
|
|
561
|
+
}
|
|
562
|
+
const failure = timeoutSignal.aborted && !signal.aborted
|
|
563
|
+
? new Error('Codex direct Responses request timed out', { cause: 'timeout' })
|
|
564
|
+
: error;
|
|
565
|
+
outcome = outcomeFor(failure);
|
|
566
|
+
throw directFailure(definition, failure);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
// Build and bound the argv locally before any auth probe or generation subprocess starts.
|
|
570
|
+
let invocation;
|
|
571
|
+
try {
|
|
572
|
+
invocation = buildInvocation(definition.cli, {
|
|
573
|
+
cwd,
|
|
574
|
+
prompt: buildPrompt(options, this.config.maxPromptBytes),
|
|
575
|
+
model: options.model,
|
|
576
|
+
...(definition.cli !== 'cursor' && options.reasoningEffort !== undefined
|
|
577
|
+
? { reasoningEffort: String(options.reasoningEffort) }
|
|
578
|
+
: {}),
|
|
579
|
+
maxTurns: profile.maxTurns,
|
|
580
|
+
command: profile.command,
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
catch (error) {
|
|
584
|
+
outcome = 'preflight';
|
|
585
|
+
throw preflightFailure(error);
|
|
586
|
+
}
|
|
587
|
+
phase = 'auth';
|
|
588
|
+
try {
|
|
589
|
+
await this.verifyAuth(definition.cli, {
|
|
590
|
+
command: profile.command,
|
|
591
|
+
cwd,
|
|
592
|
+
timeoutMs: this.config.authProbeTimeoutMs,
|
|
593
|
+
maxOutputBytes: this.config.maxAuthProbeBytes,
|
|
594
|
+
extraEnvNames: this.config.extraEnvNames,
|
|
595
|
+
signal,
|
|
596
|
+
...(definition.cli === 'grok'
|
|
597
|
+
? { userVerifiedSubscription: this.config.grok.userVerifiedSubscription }
|
|
598
|
+
: {}),
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
catch (error) {
|
|
602
|
+
// Auth precedes spawn, so the prompt argv was never handed to the OS.
|
|
603
|
+
if (definition.cli === 'codex')
|
|
604
|
+
this.codexCatalogCache = undefined;
|
|
605
|
+
else
|
|
606
|
+
this.subscriptionCatalogCache.delete(definition.cli);
|
|
607
|
+
outcome = outcomeFor(error);
|
|
608
|
+
throw cliFailure(definition, profile.command, error);
|
|
609
|
+
}
|
|
610
|
+
// Revalidate the authority boundary after auth so a stale/replaced session
|
|
611
|
+
// cannot reach the generation process. Catalog discovery belongs exclusively
|
|
612
|
+
// to listModels and never delays a generation request.
|
|
613
|
+
phase = 'preflight';
|
|
614
|
+
try {
|
|
615
|
+
cwd = this.trustedCwd(options);
|
|
616
|
+
}
|
|
617
|
+
catch (error) {
|
|
618
|
+
outcome = outcomeFor(error);
|
|
619
|
+
throw cliFailure(definition, profile.command, error);
|
|
620
|
+
}
|
|
621
|
+
const runnerOptions = {
|
|
622
|
+
timeoutMs: this.config.timeoutMs,
|
|
623
|
+
killGraceMs: this.config.killGraceMs,
|
|
624
|
+
maxLineBytes: this.config.maxLineBytes,
|
|
625
|
+
maxOutputBytes: this.config.maxOutputBytes,
|
|
626
|
+
maxStderrBytes: this.config.maxStderrBytes,
|
|
627
|
+
extraEnvNames: this.config.extraEnvNames,
|
|
628
|
+
onDiagnostic: diagnostic => this.onDiagnostic?.(definition.route, redactDiagnostic(diagnostic)),
|
|
629
|
+
onSettled: context => { transportContext = context; },
|
|
630
|
+
signal,
|
|
631
|
+
};
|
|
632
|
+
// block-start alone runs nothing: prompt stays provably not-submitted until execution
|
|
633
|
+
// resumes toward the transport. Once iteration begins the transport owns the state and
|
|
634
|
+
// reports it via onSettled; if it never reports (early return mid-stream) we say unknown.
|
|
635
|
+
phase = 'stream';
|
|
636
|
+
let text = '';
|
|
637
|
+
const bufferForToolDelegation = (options.tools?.length ?? 0) > 0;
|
|
638
|
+
if (!bufferForToolDelegation)
|
|
639
|
+
yield { type: 'block-start', index: 0, blockType: 'text' };
|
|
640
|
+
try {
|
|
641
|
+
// Calling an injected runner may itself perform work or throw synchronously, so
|
|
642
|
+
// stop claiming not-submitted immediately before control crosses that boundary.
|
|
643
|
+
promptSubmissionState = 'unknown';
|
|
644
|
+
invocation = { ...invocation, cwd: this.trustedCwd(options) };
|
|
645
|
+
const deltas = this.runText(invocation, runnerOptions);
|
|
646
|
+
for await (const delta of deltas) {
|
|
647
|
+
if (delta.length === 0)
|
|
648
|
+
continue;
|
|
649
|
+
text += delta;
|
|
650
|
+
if (!bufferForToolDelegation) {
|
|
651
|
+
assistantTextForwarded = true;
|
|
652
|
+
yield { type: 'text-delta', index: 0, text: delta };
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
catch (error) {
|
|
657
|
+
outcome = outcomeFor(error);
|
|
658
|
+
throw cliFailure(definition, profile.command, error);
|
|
659
|
+
}
|
|
660
|
+
const ensureProjectionActive = () => {
|
|
661
|
+
if (!signal.aborted)
|
|
662
|
+
return;
|
|
663
|
+
outcome = 'aborted';
|
|
664
|
+
throw abortReason(signal);
|
|
665
|
+
};
|
|
666
|
+
// The child may settle successfully in the same turn that the Agent is
|
|
667
|
+
// cancelled. Never parse or project its buffered response after that
|
|
668
|
+
// cancellation has won the race.
|
|
669
|
+
ensureProjectionActive();
|
|
670
|
+
if (bufferForToolDelegation) {
|
|
671
|
+
let calls;
|
|
672
|
+
try {
|
|
673
|
+
calls = parseDelegatedToolCalls(text, options.tools ?? []);
|
|
674
|
+
}
|
|
675
|
+
catch (error) {
|
|
676
|
+
outcome = 'protocol';
|
|
677
|
+
throw cliFailure(definition, profile.command, error);
|
|
678
|
+
}
|
|
679
|
+
ensureProjectionActive();
|
|
680
|
+
if (calls !== undefined) {
|
|
681
|
+
for (const [index, call] of calls.entries()) {
|
|
682
|
+
ensureProjectionActive();
|
|
683
|
+
const id = ToolCallId(`${definition.cli}-${randomUUID()}`);
|
|
684
|
+
yield { type: 'block-start', index, blockType: 'tool-call' };
|
|
685
|
+
ensureProjectionActive();
|
|
686
|
+
yield { type: 'tool-call-delta', index, id, name: call.name, argumentsDelta: call.arguments };
|
|
687
|
+
ensureProjectionActive();
|
|
688
|
+
yield {
|
|
689
|
+
type: 'block-end',
|
|
690
|
+
index,
|
|
691
|
+
block: { type: 'tool-call', id, name: call.name, arguments: call.arguments },
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
ensureProjectionActive();
|
|
695
|
+
outcome = 'ok';
|
|
696
|
+
yield { type: 'finish', reason: { kind: 'tool-calls' } };
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
ensureProjectionActive();
|
|
700
|
+
yield { type: 'block-start', index: 0, blockType: 'text' };
|
|
701
|
+
ensureProjectionActive();
|
|
702
|
+
assistantTextForwarded = true;
|
|
703
|
+
yield { type: 'text-delta', index: 0, text };
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
outcome = 'ok';
|
|
707
|
+
}
|
|
708
|
+
ensureProjectionActive();
|
|
709
|
+
yield { type: 'block-end', index: 0, block: { type: 'text', text } };
|
|
710
|
+
ensureProjectionActive();
|
|
711
|
+
outcome = 'ok';
|
|
712
|
+
yield { type: 'finish', reason: { kind: 'stop' } };
|
|
713
|
+
}
|
|
714
|
+
finally {
|
|
715
|
+
settle();
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
/** Abort every active/future subprocess when the owning Cordis fiber unloads. */
|
|
719
|
+
shutdown() {
|
|
720
|
+
if (!this.lifecycle.signal.aborted) {
|
|
721
|
+
this.lifecycle.abort(new Error('coding subscription provider unloaded', { cause: 'abort' }));
|
|
722
|
+
}
|
|
723
|
+
this.codexCatalogCache = undefined;
|
|
724
|
+
this.subscriptionCatalogCache.clear();
|
|
725
|
+
this.catalogRefreshes.clear();
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
export function enabledRoutes(config) {
|
|
729
|
+
return routeDefinitions
|
|
730
|
+
.filter(definition => configForProvider(config, definition.cli).enabled)
|
|
731
|
+
.map(definition => definition.route);
|
|
732
|
+
}
|
|
733
|
+
/** Redact common credential/email shapes before a bounded CLI diagnostic reaches host logs. */
|
|
734
|
+
export function redactDiagnostic(value) {
|
|
735
|
+
return value
|
|
736
|
+
.replace(/(bearer\s+)[^\s]+/gi, '$1[redacted]')
|
|
737
|
+
.replace(/((?:api[_-]?key|auth(?:orization)?|token)\s*[:=]\s*)[^\s]+/gi, '$1[redacted]')
|
|
738
|
+
.replace(/\b(?:sk|xai)-[A-Za-z0-9_-]{8,}\b/g, '[redacted-key]')
|
|
739
|
+
.replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi, '[redacted-email]')
|
|
740
|
+
.slice(-2_000);
|
|
741
|
+
}
|
|
742
|
+
//# sourceMappingURL=adapter.js.map
|