e2e 0.16.0 → 0.17.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/.build.json +1 -1
- package/dist/agent/act.js +7 -4
- package/dist/agent/action-dispatcher.js +4 -5
- package/dist/agent/actions.d.ts +32 -23
- package/dist/agent/actions.js +38 -24
- package/dist/agent/model/sdk.js +2 -0
- package/dist/agent/observation-feed.d.ts +5 -6
- package/dist/agent/observation-feed.js +5 -7
- package/dist/agent/observation.d.ts +40 -11
- package/dist/agent/observation.js +109 -59
- package/dist/agent/point-tap.d.ts +8 -8
- package/dist/agent/point-tap.js +1 -1
- package/dist/agent/replay.d.ts +19 -8
- package/dist/agent/replay.js +11 -14
- package/dist/agent/scroll-target.d.ts +2 -3
- package/dist/agent/step-cache.d.ts +41 -14
- package/dist/agent/step-cache.js +147 -62
- package/dist/agent/tool-loop.js +2 -0
- package/dist/cache/anchors.d.ts +72 -23
- package/dist/cache/anchors.js +233 -60
- package/dist/cache/context.d.ts +25 -14
- package/dist/cache/context.js +50 -8
- package/dist/cache/decide.d.ts +2 -2
- package/dist/cache/decide.js +4 -6
- package/dist/cache/identity.d.ts +18 -4
- package/dist/cache/identity.js +9 -4
- package/dist/cache/recorder.d.ts +15 -1
- package/dist/cache/recorder.js +36 -23
- package/dist/cache/rekeyed.d.ts +46 -0
- package/dist/cache/rekeyed.js +89 -0
- package/dist/cache/relocate.d.ts +14 -14
- package/dist/cache/relocate.js +33 -25
- package/dist/cache/route.d.ts +32 -33
- package/dist/cache/route.js +94 -50
- package/dist/cache/store.d.ts +6 -0
- package/dist/cache/store.js +21 -1
- package/dist/cache/trace.d.ts +53 -14
- package/dist/cache/trace.js +70 -28
- package/dist/cli/index.js +8 -8
- package/dist/cli/init/engines.d.ts +1 -3
- package/dist/cli/init/engines.js +2 -2
- package/dist/cli/init/gateways.d.ts +1 -1
- package/dist/cli/init/gateways.js +11 -1
- package/dist/cli/init/sibling-versions.json +1 -1
- package/dist/cli/init/versions.d.ts +0 -8
- package/dist/cli/init/versions.js +1 -10
- package/dist/config/resolve.d.ts +1 -0
- package/dist/config/resolve.js +33 -1
- package/dist/engine/index.d.ts +2 -2
- package/dist/expect/async.js +2 -1
- package/dist/expect/poll-scope.d.ts +52 -0
- package/dist/expect/poll-scope.js +113 -0
- package/dist/expect/poll.js +31 -4
- package/dist/expect/values.js +11 -4
- package/dist/internal/abandoned.d.ts +11 -0
- package/dist/internal/abandoned.js +23 -0
- package/dist/internal/brands.d.ts +2 -0
- package/dist/internal/brands.js +2 -0
- package/dist/internal/client-identity.d.ts +9 -0
- package/dist/internal/client-identity.js +14 -0
- package/dist/internal/redact.d.ts +7 -4
- package/dist/internal/redact.js +116 -23
- package/dist/internal/time.d.ts +6 -0
- package/dist/internal/time.js +25 -13
- package/dist/internal/urls.d.ts +9 -5
- package/dist/internal/urls.js +19 -10
- package/dist/locator/engine.d.ts +12 -2
- package/dist/locator/engine.js +8 -3
- package/dist/locator/screen.js +28 -4
- package/dist/mcp/catalog.d.ts +3 -2
- package/dist/mcp/catalog.js +6 -6
- package/dist/mcp/session.js +1 -1
- package/dist/oauth/chatgpt.js +3 -23
- package/dist/oauth/cli.js +1 -0
- package/dist/oauth/copilot.d.ts +5 -4
- package/dist/oauth/copilot.js +80 -7
- package/dist/oauth/grok.js +2 -1
- package/dist/oauth/models.js +2 -1
- package/dist/oauth/opencode-console.d.ts +10 -0
- package/dist/oauth/opencode-console.js +133 -0
- package/dist/oauth/providers/github-copilot.d.ts +12 -0
- package/dist/oauth/providers/github-copilot.js +77 -23
- package/dist/oauth/providers/opencode-console.d.ts +31 -0
- package/dist/oauth/providers/opencode-console.js +148 -0
- package/dist/oauth/providers.d.ts +2 -6
- package/dist/oauth/providers.js +3 -7
- package/dist/oauth/responses.d.ts +9 -0
- package/dist/oauth/responses.js +23 -0
- package/dist/report/build.d.ts +26 -0
- package/dist/report/build.js +16 -8
- package/dist/report/failure-text.d.ts +6 -1
- package/dist/report/failure-text.js +14 -4
- package/dist/report/format.d.ts +10 -5
- package/dist/report/format.js +12 -5
- package/dist/report/junit.js +11 -12
- package/dist/report/list.d.ts +1 -0
- package/dist/report/list.js +38 -18
- package/dist/report/markdown.d.ts +1 -1
- package/dist/report/markdown.js +37 -14
- package/dist/report/repeats.d.ts +6 -1
- package/dist/report/repeats.js +12 -3
- package/dist/run/artifacts.d.ts +18 -0
- package/dist/run/artifacts.js +68 -1
- package/dist/run/execute.d.ts +9 -0
- package/dist/run/execute.js +49 -24
- package/dist/run/extended-fixtures.js +6 -2
- package/dist/run/failure-evidence.js +4 -2
- package/dist/run/fixtures.js +6 -8
- package/dist/run/in-process.d.ts +2 -0
- package/dist/run/in-process.js +1 -0
- package/dist/run/last-run.d.ts +42 -8
- package/dist/run/last-run.js +121 -14
- package/dist/run/realm.d.ts +4 -1
- package/dist/run/realm.js +20 -6
- package/dist/run/records.d.ts +16 -0
- package/dist/run/records.js +26 -0
- package/dist/run/retry.d.ts +3 -1
- package/dist/run/retry.js +4 -2
- package/dist/run/runner.d.ts +1 -1
- package/dist/run/runner.js +69 -30
- package/dist/run/serial.d.ts +2 -0
- package/dist/run/serial.js +8 -5
- package/dist/run/steps.d.ts +0 -6
- package/dist/run/steps.js +3 -20
- package/dist/run/worker/entry.js +5 -4
- package/dist/run/worker/protocol.d.ts +2 -0
- package/dist/run/worker/session.d.ts +2 -0
- package/dist/run/worker/session.js +1 -0
- package/dist/telemetry/events.js +1 -0
- package/dist/types.d.ts +9 -3
- package/docs/agents.mdx +6 -3
- package/docs/assertions.mdx +94 -0
- package/docs/authentication.mdx +3 -1
- package/docs/browser.mdx +42 -6
- package/docs/cache.mdx +64 -18
- package/docs/ci.mdx +11 -7
- package/docs/debugging.mdx +6 -3
- package/docs/executors.mdx +4 -2
- package/docs/github.mdx +12 -4
- package/docs/{writing-tests.mdx → goals.mdx} +21 -101
- package/docs/index.mdx +4 -4
- package/docs/integrations/kernel.mdx +1 -1
- package/docs/locators.mdx +64 -0
- package/docs/migrate/cypress.mdx +2 -2
- package/docs/migrate/maestro.mdx +2 -2
- package/docs/migrate/playwright.mdx +19 -16
- package/docs/migrate/selenium.mdx +2 -2
- package/docs/mobile.mdx +21 -4
- package/docs/models.mdx +53 -7
- package/docs/physical-devices.mdx +76 -0
- package/docs/quickstart.mdx +4 -3
- package/docs/reference/app.mdx +1 -1
- package/docs/reference/cli.mdx +30 -13
- package/docs/reference/config.mdx +25 -7
- package/docs/reference/engine.mdx +3 -3
- package/docs/reference/environment.mdx +8 -1
- package/docs/reference/errors.mdx +5 -5
- package/docs/reference/expect.mdx +34 -12
- package/docs/reference/mobile.mdx +23 -13
- package/docs/reference/reporters.mdx +8 -2
- package/docs/reference/screen.mdx +30 -7
- package/docs/reference/test.mdx +11 -4
- package/docs/reference/web.mdx +125 -21
- package/docs/security.mdx +26 -16
- package/docs/subscriptions.mdx +91 -12
- package/docs/telemetry.mdx +1 -1
- package/package.json +16 -3
- package/schema/report-v1.schema.json +14 -1
- package/skills/e2e/SKILL.md +2 -2
- package/skills/e2e/references/agent.md +22 -11
- package/skills/e2e/references/debugging.md +4 -4
- package/skills/e2e/references/running.md +13 -8
- package/skills/e2e/references/setup.md +36 -15
- package/skills/e2e/references/writing-tests.md +34 -17
package/dist/oauth/copilot.js
CHANGED
|
@@ -1,26 +1,99 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `copilot('claude-sonnet-5')`: a GitHub Copilot subscription as an AI SDK
|
|
3
|
-
* model. Copilot serves
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* model. Copilot serves most of its models over the OpenAI chat protocol and
|
|
4
|
+
* some only over its Responses API; the instance asks the plan's model
|
|
5
|
+
* listing which on the first call and delegates to the matching model, so
|
|
6
|
+
* construction stays synchronous and touches the network only when a call
|
|
7
|
+
* does. An enterprise login stored by `e2e login` routes to its own host.
|
|
7
8
|
*/
|
|
8
9
|
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
10
|
+
import { OAuthError } from './errors.js';
|
|
9
11
|
import { createOAuthFetch } from './fetch.js';
|
|
10
|
-
import { USER_AGENT
|
|
11
|
-
import {
|
|
12
|
+
import { USER_AGENT } from '../internal/client-identity.js';
|
|
13
|
+
import { loginHint } from './providers.js';
|
|
14
|
+
import { COPILOT_API_URL, copilotProtocolFor, createCopilotProvider } from './providers/github-copilot.js';
|
|
15
|
+
import { withoutServerStorage } from './responses.js';
|
|
12
16
|
import { defaultCredentialStore } from './store.js';
|
|
17
|
+
/** How long the first call waits on the model listing before it calls over chat and asks again next time. */
|
|
18
|
+
const LISTING_TIMEOUT_MS = 10_000;
|
|
13
19
|
export function copilot(modelId) {
|
|
14
20
|
const fetch = createOAuthFetch(createCopilotProvider(), {
|
|
15
21
|
store: defaultCredentialStore(),
|
|
16
22
|
userAgent: USER_AGENT,
|
|
17
23
|
loginHint: loginHint('github-copilot'),
|
|
18
24
|
});
|
|
19
|
-
|
|
25
|
+
// The key header is removed per request; the value only satisfies the constructor.
|
|
26
|
+
const chat = createOpenAICompatible({
|
|
20
27
|
name: 'github-copilot',
|
|
21
28
|
baseURL: COPILOT_API_URL,
|
|
22
29
|
apiKey: 'oauth',
|
|
23
30
|
fetch,
|
|
24
31
|
includeUsage: true,
|
|
25
32
|
}).chatModel(modelId);
|
|
33
|
+
return protocolDelegate(chat, () => responsesModel(modelId, fetch), () => copilotProtocolFor(modelId, fetch, AbortSignal.timeout(LISTING_TIMEOUT_MS)));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The Responses model for `modelId`. `@ai-sdk/openai` is imported only here,
|
|
37
|
+
* so a project that calls only chat models needs no install of it.
|
|
38
|
+
*/
|
|
39
|
+
async function responsesModel(modelId, fetch) {
|
|
40
|
+
let createOpenAI;
|
|
41
|
+
try {
|
|
42
|
+
({ createOpenAI } = await import('@ai-sdk/openai'));
|
|
43
|
+
}
|
|
44
|
+
catch (cause) {
|
|
45
|
+
throw new OAuthError('MISCONFIGURED', `GitHub Copilot serves ${modelId} only over its Responses API, which copilot() calls through @ai-sdk/openai; install it beside @ai-sdk/openai-compatible`, { cause });
|
|
46
|
+
}
|
|
47
|
+
return withoutServerStorage(createOpenAI({ apiKey: 'oauth', baseURL: COPILOT_API_URL, fetch, name: 'github-copilot' }).responses(modelId));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A model that settles its Copilot protocol on the first call and delegates
|
|
51
|
+
* to the model for it. One lookup serves every concurrent call, under its
|
|
52
|
+
* own timeout, so a caller that gives up never fails the others. Only a
|
|
53
|
+
* listing that was read is remembered: when it could not be read, that call
|
|
54
|
+
* goes over chat, the endpoint most models use, and the next call asks again.
|
|
55
|
+
*/
|
|
56
|
+
function protocolDelegate(chat, responses, lookup) {
|
|
57
|
+
let resolved;
|
|
58
|
+
let pending;
|
|
59
|
+
const settle = () => {
|
|
60
|
+
if (resolved !== undefined)
|
|
61
|
+
return Promise.resolve(resolved);
|
|
62
|
+
pending ??= (async () => {
|
|
63
|
+
const protocol = await lookup();
|
|
64
|
+
if (protocol === undefined)
|
|
65
|
+
return chat;
|
|
66
|
+
resolved = protocol === 'responses' ? await responses() : chat;
|
|
67
|
+
return resolved;
|
|
68
|
+
})().finally(() => {
|
|
69
|
+
pending = undefined;
|
|
70
|
+
});
|
|
71
|
+
return pending;
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
specificationVersion: chat.specificationVersion,
|
|
75
|
+
get provider() {
|
|
76
|
+
return resolved?.provider ?? chat.provider;
|
|
77
|
+
},
|
|
78
|
+
get modelId() {
|
|
79
|
+
return resolved?.modelId ?? chat.modelId;
|
|
80
|
+
},
|
|
81
|
+
get supportedUrls() {
|
|
82
|
+
return resolved?.supportedUrls ?? chat.supportedUrls;
|
|
83
|
+
},
|
|
84
|
+
doGenerate: async (options) => (await untilAborted(settle(), options.abortSignal)).doGenerate(options),
|
|
85
|
+
doStream: async (options) => (await untilAborted(settle(), options.abortSignal)).doStream(options),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Waits for `promise` unless `signal` aborts first, leaving the shared promise running for other callers. */
|
|
89
|
+
function untilAborted(promise, signal) {
|
|
90
|
+
if (signal === undefined)
|
|
91
|
+
return promise;
|
|
92
|
+
if (signal.aborted)
|
|
93
|
+
return Promise.reject(signal.reason);
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const onAbort = () => reject(signal.reason);
|
|
96
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
97
|
+
promise.then(resolve, reject).finally(() => signal.removeEventListener('abort', onAbort));
|
|
98
|
+
});
|
|
26
99
|
}
|
package/dist/oauth/grok.js
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { createXai } from '@ai-sdk/xai';
|
|
7
7
|
import { createOAuthFetch } from './fetch.js';
|
|
8
|
-
import { USER_AGENT
|
|
8
|
+
import { USER_AGENT } from '../internal/client-identity.js';
|
|
9
|
+
import { loginHint } from './providers.js';
|
|
9
10
|
import { createXaiProvider } from './providers/xai.js';
|
|
10
11
|
import { defaultCredentialStore } from './store.js';
|
|
11
12
|
export function grok(modelId) {
|
package/dist/oauth/models.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/** Lists the models a stored subscription login serves, through the login's own fetch. */
|
|
2
2
|
import { OAuthError } from './errors.js';
|
|
3
3
|
import { createOAuthFetch } from './fetch.js';
|
|
4
|
-
import { USER_AGENT
|
|
4
|
+
import { USER_AGENT } from '../internal/client-identity.js';
|
|
5
|
+
import { getProvider, loginHint } from './providers.js';
|
|
5
6
|
import { defaultCredentialStore } from './store.js';
|
|
6
7
|
/** The models `providerId`'s stored login serves; `NOT_LOGGED_IN` without one. */
|
|
7
8
|
export async function listModels(providerId, store = defaultCredentialStore()) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `opencodeConsole('deepseek-v4.1-flash')`: an OpenCode Console workspace as
|
|
3
|
+
* an AI SDK model, Zen for a bare id and Go for a `go/` one. The first call
|
|
4
|
+
* reads the workspace config for the model's protocol and lazily loads the
|
|
5
|
+
* SDK for it. Requests get the prompt-cache hints the runner itself adds for
|
|
6
|
+
* OpenAI and Anthropic, which it cannot do here since the protocol is unknown
|
|
7
|
+
* until then. `OPENCODE_API_KEY` replaces the stored login when set.
|
|
8
|
+
*/
|
|
9
|
+
import type { LanguageModelV4 } from '@ai-sdk/provider';
|
|
10
|
+
export declare function opencodeConsole(modelId: string): LanguageModelV4;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `opencodeConsole('deepseek-v4.1-flash')`: an OpenCode Console workspace as
|
|
3
|
+
* an AI SDK model, Zen for a bare id and Go for a `go/` one. The first call
|
|
4
|
+
* reads the workspace config for the model's protocol and lazily loads the
|
|
5
|
+
* SDK for it. Requests get the prompt-cache hints the runner itself adds for
|
|
6
|
+
* OpenAI and Anthropic, which it cannot do here since the protocol is unknown
|
|
7
|
+
* until then. `OPENCODE_API_KEY` replaces the stored login when set.
|
|
8
|
+
*/
|
|
9
|
+
import { randomUUID } from 'node:crypto';
|
|
10
|
+
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
11
|
+
import { promptCacheKey } from '../agent/model/provider-hints.js';
|
|
12
|
+
import { OAuthError } from './errors.js';
|
|
13
|
+
import { createOAuthFetch } from './fetch.js';
|
|
14
|
+
import { USER_AGENT } from '../internal/client-identity.js';
|
|
15
|
+
import { loginHint } from './providers.js';
|
|
16
|
+
import { createOpencodeConsoleProvider, opencodeConsoleChatRoute, opencodeConsoleRouteFor } from './providers/opencode-console.js';
|
|
17
|
+
import { EnvCredentialStore, defaultCredentialStore } from './store.js';
|
|
18
|
+
const CONFIG_TIMEOUT_MS = 10_000;
|
|
19
|
+
const API_KEY_ENV = 'OPENCODE_API_KEY';
|
|
20
|
+
const BREAKPOINT = { cacheControl: { type: 'ephemeral' } };
|
|
21
|
+
export function opencodeConsole(modelId) {
|
|
22
|
+
const apiKey = process.env[API_KEY_ENV]?.trim();
|
|
23
|
+
const fetch = createOAuthFetch(createOpencodeConsoleProvider(), {
|
|
24
|
+
store: apiKey ? apiKeyStore(apiKey) : defaultCredentialStore(),
|
|
25
|
+
userAgent: USER_AGENT,
|
|
26
|
+
loginHint: apiKey ? `check ${API_KEY_ENV}` : loginHint('opencode-console'),
|
|
27
|
+
});
|
|
28
|
+
// One per model, so a worker's calls stay on one upstream and its cache.
|
|
29
|
+
const session = `e2e_${randomUUID()}`;
|
|
30
|
+
const chatRoute = opencodeConsoleChatRoute(modelId);
|
|
31
|
+
const chat = { npm: chatRoute.npm, model: chatModel(chatRoute, fetch, session) };
|
|
32
|
+
let resolved;
|
|
33
|
+
let pending;
|
|
34
|
+
// An unreadable config sends that call over chat and is asked again next time.
|
|
35
|
+
const served = () => {
|
|
36
|
+
if (resolved !== undefined)
|
|
37
|
+
return Promise.resolve(resolved);
|
|
38
|
+
pending ??= (async () => {
|
|
39
|
+
const route = await opencodeConsoleRouteFor(modelId, fetch, AbortSignal.timeout(CONFIG_TIMEOUT_MS));
|
|
40
|
+
if (route === undefined)
|
|
41
|
+
return chat;
|
|
42
|
+
resolved = { npm: route.npm, model: await sdkModel(route, fetch, session) };
|
|
43
|
+
return resolved;
|
|
44
|
+
})().finally(() => {
|
|
45
|
+
pending = undefined;
|
|
46
|
+
});
|
|
47
|
+
return pending;
|
|
48
|
+
};
|
|
49
|
+
// Fixed: the runner reads provider and modelId before and after the first call.
|
|
50
|
+
return {
|
|
51
|
+
specificationVersion: chat.model.specificationVersion,
|
|
52
|
+
provider: chatRoute.go ? 'opencode.go' : 'opencode',
|
|
53
|
+
modelId: chatRoute.modelId,
|
|
54
|
+
get supportedUrls() {
|
|
55
|
+
return (resolved ?? chat).model.supportedUrls;
|
|
56
|
+
},
|
|
57
|
+
async doGenerate(options) {
|
|
58
|
+
const { npm, model } = await served();
|
|
59
|
+
return model.doGenerate(requestFor(npm, options, session));
|
|
60
|
+
},
|
|
61
|
+
async doStream(options) {
|
|
62
|
+
const { npm, model } = await served();
|
|
63
|
+
return model.doStream(requestFor(npm, options, session));
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** A Console service API key as a login with nothing to refresh. */
|
|
68
|
+
function apiKeyStore(apiKey) {
|
|
69
|
+
return new EnvCredentialStore(JSON.stringify({ 'opencode-console': { access: apiKey, refresh: '', expires: 0 } }));
|
|
70
|
+
}
|
|
71
|
+
/** `opencode.go` keeps Go's provider options under `opencode`, the name up to the first dot; `apiKey` only satisfies the constructors. */
|
|
72
|
+
function settings(route, fetch, session) {
|
|
73
|
+
return { name: route.go ? 'opencode.go' : 'opencode', baseURL: route.baseURL, apiKey: 'oauth', fetch, headers: { 'x-opencode-session': session } };
|
|
74
|
+
}
|
|
75
|
+
function chatModel(route, fetch, session) {
|
|
76
|
+
return createOpenAICompatible({ ...settings(route, fetch, session), includeUsage: true }).chatModel(route.modelId);
|
|
77
|
+
}
|
|
78
|
+
async function sdkModel(route, fetch, session) {
|
|
79
|
+
switch (route.npm) {
|
|
80
|
+
case '@ai-sdk/openai': {
|
|
81
|
+
const { createOpenAI } = await load(() => import('@ai-sdk/openai'), route);
|
|
82
|
+
return createOpenAI(settings(route, fetch, session)).responses(route.modelId);
|
|
83
|
+
}
|
|
84
|
+
case '@ai-sdk/anthropic': {
|
|
85
|
+
const { createAnthropic } = await load(() => import('@ai-sdk/anthropic'), route);
|
|
86
|
+
return createAnthropic(settings(route, fetch, session))(route.modelId);
|
|
87
|
+
}
|
|
88
|
+
case '@ai-sdk/google': {
|
|
89
|
+
const { createGoogleGenerativeAI } = await load(() => import('@ai-sdk/google'), route);
|
|
90
|
+
return createGoogleGenerativeAI(settings(route, fetch, session))(route.modelId);
|
|
91
|
+
}
|
|
92
|
+
default:
|
|
93
|
+
return chatModel(route, fetch, session);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** Responses: no server storage and the runner's prompt cache key. Anthropic: cache breakpoints. */
|
|
97
|
+
function requestFor(npm, options, session) {
|
|
98
|
+
switch (npm) {
|
|
99
|
+
case '@ai-sdk/openai': {
|
|
100
|
+
const system = options.prompt.flatMap((message) => (message.role === 'system' ? [message.content] : [])).join('\n');
|
|
101
|
+
const cacheKey = system === '' ? session : promptCacheKey(system);
|
|
102
|
+
return { ...options, providerOptions: { ...options.providerOptions, openai: { promptCacheKey: cacheKey, ...options.providerOptions?.['openai'], store: false } } };
|
|
103
|
+
}
|
|
104
|
+
case '@ai-sdk/anthropic':
|
|
105
|
+
return { ...options, prompt: withBreakpoints(options.prompt, (options.tools?.length ?? 0) > 0) };
|
|
106
|
+
default:
|
|
107
|
+
return options;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The system prompt, and in a tool loop the newest message, as the runner
|
|
112
|
+
* marks them; a call without tools is a one-off judgment. A prompt that already
|
|
113
|
+
* carries a breakpoint is left as the caller placed it.
|
|
114
|
+
*/
|
|
115
|
+
function withBreakpoints(prompt, loop) {
|
|
116
|
+
if (prompt.some(hasBreakpoint))
|
|
117
|
+
return prompt;
|
|
118
|
+
const marked = new Set([prompt.findLastIndex((message) => message.role === 'system'), loop ? prompt.length - 1 : -1]);
|
|
119
|
+
return prompt.map((message, index) => marked.has(index) ? { ...message, providerOptions: { ...message.providerOptions, anthropic: { ...message.providerOptions?.['anthropic'], ...BREAKPOINT } } } : message);
|
|
120
|
+
}
|
|
121
|
+
function hasBreakpoint(message) {
|
|
122
|
+
const marked = (providerOptions) => providerOptions?.['anthropic']?.['cacheControl'] !== undefined;
|
|
123
|
+
return marked(message.providerOptions) || (Array.isArray(message.content) && message.content.some((part) => marked(part.providerOptions)));
|
|
124
|
+
}
|
|
125
|
+
/** Names the missing package when an SDK is not installed. */
|
|
126
|
+
async function load(importer, route) {
|
|
127
|
+
try {
|
|
128
|
+
return await importer();
|
|
129
|
+
}
|
|
130
|
+
catch (cause) {
|
|
131
|
+
throw new OAuthError('MISCONFIGURED', `OpenCode Console serves ${route.modelId} through ${route.npm}, which opencodeConsole() loads on demand; install it beside @ai-sdk/openai-compatible`, { cause });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -36,3 +36,15 @@ export declare function copilotBaseUrl(enterpriseUrl?: string): string;
|
|
|
36
36
|
export declare function createCopilotProvider(options?: CopilotProviderOptions): OAuthProvider<CopilotCredentials, CopilotLoginOptions>;
|
|
37
37
|
/** Routes an enterprise login at its host and adds Copilot's headers: who initiated the turn, and that images are present. */
|
|
38
38
|
export declare function sendCopilotRequest(request: Request, credentials: CopilotCredentials, upstream: FetchFunction): Promise<Response>;
|
|
39
|
+
/** The endpoint `copilot()` reaches a Copilot chat model over: chat completions or the Responses API. */
|
|
40
|
+
export type CopilotProtocol = 'chat' | 'responses';
|
|
41
|
+
/**
|
|
42
|
+
* Which endpoint `copilot()` reaches `modelId` on, read from the Copilot
|
|
43
|
+
* API's `GET /models`, or `undefined` when the listing could not be read
|
|
44
|
+
* (an error status, a body that is not JSON, the network, the signal), so
|
|
45
|
+
* the caller can ask again instead of remembering a guess. A model the
|
|
46
|
+
* listing does not name, or names with no endpoint `copilot()` speaks, is
|
|
47
|
+
* chat: the vendor's own error then explains it. A rejected login is not a
|
|
48
|
+
* missing listing and rejects.
|
|
49
|
+
*/
|
|
50
|
+
export declare function copilotProtocolFor(modelId: string, fetch: FetchFunction, signal: AbortSignal): Promise<CopilotProtocol | undefined>;
|
|
@@ -92,31 +92,46 @@ export async function sendCopilotRequest(request, credentials, upstream) {
|
|
|
92
92
|
url.host = new URL(copilotBaseUrl(credentials.enterpriseUrl)).host;
|
|
93
93
|
const headers = new Headers(request.headers);
|
|
94
94
|
headers.set('openai-intent', 'conversation-edits');
|
|
95
|
-
let initiator = 'user';
|
|
96
|
-
let vision = false;
|
|
97
95
|
const text = request.method === 'POST' ? await request.text() : undefined;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const messages = Array.isArray(body.messages) ? body.messages : [];
|
|
102
|
-
if (messages.at(-1)?.role !== 'user')
|
|
103
|
-
initiator = 'agent';
|
|
104
|
-
vision = messages.some((message) => Array.isArray(message.content) && message.content.some((part) => part?.type === 'image_url'));
|
|
105
|
-
}
|
|
106
|
-
catch {
|
|
107
|
-
// Not JSON; the headers stay at their defaults.
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
headers.set('x-initiator', initiator);
|
|
111
|
-
if (vision)
|
|
96
|
+
const turn = copilotTurn(text);
|
|
97
|
+
headers.set('x-initiator', turn.initiator);
|
|
98
|
+
if (turn.vision)
|
|
112
99
|
headers.set('copilot-vision-request', 'true');
|
|
113
100
|
return upstream(new Request(url, { method: request.method, headers, signal: request.signal, ...(text === undefined ? {} : { body: text }) }));
|
|
114
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Reads who initiated the turn and whether images are present, whichever
|
|
104
|
+
* protocol carried the body. Chat completions put turns in `messages[]` and
|
|
105
|
+
* images in `image_url` parts; the Responses API puts them in `input[]` with
|
|
106
|
+
* `input_image`. A body shaped like neither keeps the defaults.
|
|
107
|
+
*/
|
|
108
|
+
function copilotTurn(text) {
|
|
109
|
+
if (text === undefined)
|
|
110
|
+
return { initiator: 'user', vision: false };
|
|
111
|
+
try {
|
|
112
|
+
const body = JSON.parse(text);
|
|
113
|
+
// A Responses body has `input` and no `messages`; anything else stays on the chat path.
|
|
114
|
+
if (!Array.isArray(body.messages) && Array.isArray(body.input)) {
|
|
115
|
+
const input = body.input;
|
|
116
|
+
return { initiator: input.at(-1)?.role === 'user' ? 'user' : 'agent', vision: input.some((item) => hasPart(item.content, 'input_image')) };
|
|
117
|
+
}
|
|
118
|
+
const messages = Array.isArray(body.messages) ? body.messages : [];
|
|
119
|
+
return { initiator: messages.at(-1)?.role === 'user' ? 'user' : 'agent', vision: messages.some((message) => hasPart(message.content, 'image_url')) };
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// Not JSON; the headers stay at their defaults.
|
|
123
|
+
return { initiator: 'user', vision: false };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Whether a turn's content carries a part of the given type (`image_url` for chat, `input_image` for Responses). */
|
|
127
|
+
function hasPart(content, type) {
|
|
128
|
+
return Array.isArray(content) && content.some((part) => part?.type === type);
|
|
129
|
+
}
|
|
115
130
|
/**
|
|
116
131
|
* The chat models the Copilot plan serves; embeddings and other kinds are
|
|
117
|
-
* left out because only chat models fit `copilot()`. A model
|
|
118
|
-
* not enabled, or one Copilot
|
|
119
|
-
*
|
|
132
|
+
* left out because only chat models fit `copilot()`. A model it cannot call
|
|
133
|
+
* at all is listed but marked: one the plan has not enabled, or one Copilot
|
|
134
|
+
* serves only over APIs `copilot()` does not speak (such as Messages). The
|
|
120
135
|
* request goes through `send`, so an enterprise login lists its own host.
|
|
121
136
|
*/
|
|
122
137
|
async function listCopilotModels(fetch) {
|
|
@@ -135,7 +150,7 @@ async function listCopilotModels(fetch) {
|
|
|
135
150
|
supports?.vision === true ? 'vision' : undefined,
|
|
136
151
|
model.preview === true ? 'preview' : undefined,
|
|
137
152
|
typeof model.policy?.state === 'string' && model.policy.state !== 'enabled' ? 'not enabled' : undefined,
|
|
138
|
-
|
|
153
|
+
copilotProtocol(model) === undefined ? 'no chat or responses' : undefined,
|
|
139
154
|
].filter((part) => part !== undefined);
|
|
140
155
|
return {
|
|
141
156
|
id: model.id,
|
|
@@ -144,7 +159,46 @@ async function listCopilotModels(fetch) {
|
|
|
144
159
|
};
|
|
145
160
|
});
|
|
146
161
|
}
|
|
147
|
-
/**
|
|
148
|
-
|
|
149
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Which endpoint `copilot()` reaches `modelId` on, read from the Copilot
|
|
164
|
+
* API's `GET /models`, or `undefined` when the listing could not be read
|
|
165
|
+
* (an error status, a body that is not JSON, the network, the signal), so
|
|
166
|
+
* the caller can ask again instead of remembering a guess. A model the
|
|
167
|
+
* listing does not name, or names with no endpoint `copilot()` speaks, is
|
|
168
|
+
* chat: the vendor's own error then explains it. A rejected login is not a
|
|
169
|
+
* missing listing and rejects.
|
|
170
|
+
*/
|
|
171
|
+
export async function copilotProtocolFor(modelId, fetch, signal) {
|
|
172
|
+
try {
|
|
173
|
+
const response = await fetch(new Request(`${COPILOT_API_URL}/models`, { signal }));
|
|
174
|
+
if (!response.ok)
|
|
175
|
+
return undefined;
|
|
176
|
+
const payload = (await response.json());
|
|
177
|
+
if (!Array.isArray(payload.data))
|
|
178
|
+
return undefined;
|
|
179
|
+
return copilotProtocol(payload.data.find((model) => model.id === modelId)) ?? 'chat';
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
if (error instanceof OAuthError)
|
|
183
|
+
throw error;
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The protocol one `/models` entry is served on, or `undefined` when
|
|
189
|
+
* `copilot()` cannot call it. An entry that names no endpoints is chat, as
|
|
190
|
+
* Copilot's older models are; chat completions wins when both are named, so
|
|
191
|
+
* a model that worked over chat keeps doing so. Whether the plan enabled the
|
|
192
|
+
* model is a separate question: Copilot rejects a disabled model the same
|
|
193
|
+
* way on either endpoint.
|
|
194
|
+
*/
|
|
195
|
+
function copilotProtocol(model) {
|
|
196
|
+
const endpoints = model?.supported_endpoints;
|
|
197
|
+
if (model === undefined || !Array.isArray(endpoints))
|
|
198
|
+
return 'chat';
|
|
199
|
+
if (endpoints.includes('/chat/completions'))
|
|
200
|
+
return 'chat';
|
|
201
|
+
if (endpoints.includes('/responses'))
|
|
202
|
+
return 'responses';
|
|
203
|
+
return undefined;
|
|
150
204
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Zen and Go through an OpenCode Console sign-in. Console speaks RFC
|
|
3
|
+
* 8628 device authorization; approving the code binds the login to one
|
|
4
|
+
* workspace, and its token is a bearer for both the Console API and inference.
|
|
5
|
+
* Refresh tokens rotate. The workspace config says which models are served and
|
|
6
|
+
* over which protocol: Zen is its `opencode` provider, Go `opencode-go`, present
|
|
7
|
+
* only for the Go subscriber. Go ids take a `go/` prefix here.
|
|
8
|
+
*/
|
|
9
|
+
import type { FetchFunction, OAuthCredentials, OAuthProvider } from '../types.ts';
|
|
10
|
+
export interface OpencodeConsoleCredentials extends OAuthCredentials {
|
|
11
|
+
/** The workspace the login is bound to; absent for a service API key. */
|
|
12
|
+
readonly orgId?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface OpencodeConsoleProviderOptions {
|
|
15
|
+
/** Test seam. */
|
|
16
|
+
readonly consoleUrl?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function createOpencodeConsoleProvider(options?: OpencodeConsoleProviderOptions): OAuthProvider<OpencodeConsoleCredentials, Record<string, never>>;
|
|
19
|
+
export interface OpencodeConsoleRoute {
|
|
20
|
+
readonly go: boolean;
|
|
21
|
+
readonly npm: string;
|
|
22
|
+
readonly baseURL: string;
|
|
23
|
+
readonly modelId: string;
|
|
24
|
+
}
|
|
25
|
+
/** The plan's chat completions route, used until the config is read. */
|
|
26
|
+
export declare function opencodeConsoleChatRoute(modelId: string): OpencodeConsoleRoute;
|
|
27
|
+
/**
|
|
28
|
+
* The model's route from the workspace config, or `undefined` when the config
|
|
29
|
+
* could not be read, so the caller asks again rather than remembering a guess.
|
|
30
|
+
*/
|
|
31
|
+
export declare function opencodeConsoleRouteFor(modelId: string, fetch: FetchFunction, signal: AbortSignal): Promise<OpencodeConsoleRoute | undefined>;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Zen and Go through an OpenCode Console sign-in. Console speaks RFC
|
|
3
|
+
* 8628 device authorization; approving the code binds the login to one
|
|
4
|
+
* workspace, and its token is a bearer for both the Console API and inference.
|
|
5
|
+
* Refresh tokens rotate. The workspace config says which models are served and
|
|
6
|
+
* over which protocol: Zen is its `opencode` provider, Go `opencode-go`, present
|
|
7
|
+
* only for the Go subscriber. Go ids take a `go/` prefix here.
|
|
8
|
+
*/
|
|
9
|
+
import { rfc8628Flow } from '../device-code.js';
|
|
10
|
+
import { OAuthError, describeResponse } from '../errors.js';
|
|
11
|
+
import { expiryFrom, requestTokens } from '../token-endpoint.js';
|
|
12
|
+
/** Console accepts any client id. */
|
|
13
|
+
const CLIENT_ID = 'e2e';
|
|
14
|
+
const CONSOLE_URL = 'https://opencode.ai/console';
|
|
15
|
+
const INFERENCE_URL = 'https://opencode.ai/inference';
|
|
16
|
+
const GO_PREFIX = 'go/';
|
|
17
|
+
const ZEN_PROVIDER = 'opencode';
|
|
18
|
+
const GO_PROVIDER = 'opencode-go';
|
|
19
|
+
export function createOpencodeConsoleProvider(options = {}) {
|
|
20
|
+
const consoleUrl = options.consoleUrl ?? CONSOLE_URL;
|
|
21
|
+
const tokenUrl = `${consoleUrl}/auth/device/token`;
|
|
22
|
+
return {
|
|
23
|
+
id: 'opencode-console',
|
|
24
|
+
name: 'OpenCode Console',
|
|
25
|
+
async login(callbacks) {
|
|
26
|
+
const deviceCodeUrl = `${consoleUrl}/auth/device/code`;
|
|
27
|
+
const tokens = await rfc8628Flow({
|
|
28
|
+
vendor: 'OpenCode Console',
|
|
29
|
+
deviceCodeUrl,
|
|
30
|
+
tokenUrl,
|
|
31
|
+
clientId: CLIENT_ID,
|
|
32
|
+
request: { supports_org_scope: 'true' },
|
|
33
|
+
// Console answers with a relative verification URL.
|
|
34
|
+
callbacks: {
|
|
35
|
+
...callbacks,
|
|
36
|
+
onAuth: (info) => {
|
|
37
|
+
const url = new URL(info.url, deviceCodeUrl).href;
|
|
38
|
+
callbacks.onAuth({
|
|
39
|
+
...info,
|
|
40
|
+
url,
|
|
41
|
+
instructions: `Open ${url} on any device, pick the workspace to sign in to${info.userCode === undefined ? '' : `, and confirm the code ${info.userCode}`}.`,
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
return toCredentials(tokens);
|
|
47
|
+
},
|
|
48
|
+
async refresh(credentials) {
|
|
49
|
+
if (credentials.refresh === '')
|
|
50
|
+
throw new OAuthError('LOGIN_REQUIRED', 'OpenCode Console has no refresh token for this login');
|
|
51
|
+
const tokens = await requestTokens('OpenCode Console', tokenUrl, { grant_type: 'refresh_token', refresh_token: credentials.refresh, client_id: CLIENT_ID }, 'LOGIN_REQUIRED');
|
|
52
|
+
return toCredentials(tokens, credentials);
|
|
53
|
+
},
|
|
54
|
+
send(request, credentials, upstream) {
|
|
55
|
+
return sendOpencodeConsoleRequest(request, credentials, upstream, consoleUrl);
|
|
56
|
+
},
|
|
57
|
+
models(fetch) {
|
|
58
|
+
return listOpencodeConsoleModels(fetch, consoleUrl);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Names the workspace as each API expects, and drops the Google SDK's placeholder key header. */
|
|
63
|
+
async function sendOpencodeConsoleRequest(request, credentials, upstream, consoleUrl) {
|
|
64
|
+
const headers = new Headers(request.headers);
|
|
65
|
+
headers.delete('x-goog-api-key');
|
|
66
|
+
if (credentials.orgId !== undefined)
|
|
67
|
+
headers.set(request.url.startsWith(`${consoleUrl}/`) ? 'x-org-id' : 'x-opencode-org-id', credentials.orgId);
|
|
68
|
+
const body = request.method === 'GET' || request.method === 'HEAD' ? undefined : await request.arrayBuffer();
|
|
69
|
+
return upstream(new Request(request.url, { method: request.method, headers, signal: request.signal, ...(body === undefined ? {} : { body }) }));
|
|
70
|
+
}
|
|
71
|
+
async function readConfig(fetch, consoleUrl, signal) {
|
|
72
|
+
const response = await fetch(new Request(`${consoleUrl}/api/config`, signal === undefined ? {} : { signal }));
|
|
73
|
+
if (!response.ok)
|
|
74
|
+
throw new OAuthError('FLOW_FAILED', `OpenCode Console did not return the workspace config: ${await describeResponse(response)}`);
|
|
75
|
+
const payload = (await response.json());
|
|
76
|
+
const providers = payload.config?.provider;
|
|
77
|
+
return typeof providers === 'object' && providers !== null ? providers : {};
|
|
78
|
+
}
|
|
79
|
+
/** Leaves out disabled models and Zen's free ones, which only OpenCode's own clients may use. */
|
|
80
|
+
async function listOpencodeConsoleModels(fetch, consoleUrl) {
|
|
81
|
+
const providers = await readConfig(fetch, consoleUrl);
|
|
82
|
+
const listed = (key, prefix, plan) => Object.entries(providers[key]?.models ?? {})
|
|
83
|
+
.filter(([, model]) => model.disabled !== true && (key === GO_PROVIDER || !isFree(model)))
|
|
84
|
+
.map(([id, model]) => {
|
|
85
|
+
const detail = [
|
|
86
|
+
plan,
|
|
87
|
+
typeof model.cost?.input === 'number' && typeof model.cost.output === 'number' && key === ZEN_PROVIDER ? `$${model.cost.input} in, $${model.cost.output} out per 1M` : undefined,
|
|
88
|
+
Array.isArray(model.modalities?.input) && model.modalities.input.includes('image') ? 'vision' : undefined,
|
|
89
|
+
].filter((part) => part !== undefined);
|
|
90
|
+
return { id: `${prefix}${id}`, ...(typeof model.name === 'string' && model.name !== '' ? { name: model.name } : {}), detail: detail.join(', ') };
|
|
91
|
+
});
|
|
92
|
+
return [...listed(ZEN_PROVIDER, '', 'Zen'), ...listed(GO_PROVIDER, GO_PREFIX, 'Go')];
|
|
93
|
+
}
|
|
94
|
+
function isFree(model) {
|
|
95
|
+
return model.cost?.input === 0 && model.cost.output === 0;
|
|
96
|
+
}
|
|
97
|
+
const CHAT_NPM = '@ai-sdk/openai-compatible';
|
|
98
|
+
function splitModelId(modelId) {
|
|
99
|
+
const go = modelId.startsWith(GO_PREFIX);
|
|
100
|
+
return { go, id: go ? modelId.slice(GO_PREFIX.length) : modelId };
|
|
101
|
+
}
|
|
102
|
+
/** The plan's chat completions route, used until the config is read. */
|
|
103
|
+
export function opencodeConsoleChatRoute(modelId) {
|
|
104
|
+
const { go, id } = splitModelId(modelId);
|
|
105
|
+
return { go, npm: CHAT_NPM, baseURL: `${INFERENCE_URL}${go ? '/go' : ''}/openai/v1`, modelId: id };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The model's route from the workspace config, or `undefined` when the config
|
|
109
|
+
* could not be read, so the caller asks again rather than remembering a guess.
|
|
110
|
+
*/
|
|
111
|
+
export async function opencodeConsoleRouteFor(modelId, fetch, signal) {
|
|
112
|
+
let providers;
|
|
113
|
+
try {
|
|
114
|
+
providers = await readConfig(fetch, CONSOLE_URL, signal);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (error instanceof OAuthError && error.code !== 'FLOW_FAILED')
|
|
118
|
+
throw error;
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
const { go, id } = splitModelId(modelId);
|
|
122
|
+
const provider = providers[go ? GO_PROVIDER : ZEN_PROVIDER];
|
|
123
|
+
if (provider === undefined) {
|
|
124
|
+
throw new OAuthError('MISCONFIGURED', go
|
|
125
|
+
? 'OpenCode Go is not available to this login: the workspace has no Go subscription, or the signed-in user is not its subscriber; sign in to the Go workspace with `npx e2e login opencode-console`'
|
|
126
|
+
: 'OpenCode Zen is turned off for this OpenCode Console workspace');
|
|
127
|
+
}
|
|
128
|
+
const model = provider.models?.[id];
|
|
129
|
+
if (model === undefined || model.disabled === true) {
|
|
130
|
+
throw new OAuthError('MISCONFIGURED', `the OpenCode Console workspace does not serve ${modelId}; \`npx e2e models opencode-console\` lists the ids`);
|
|
131
|
+
}
|
|
132
|
+
const npm = typeof model.provider?.npm === 'string' ? model.provider.npm : provider.npm;
|
|
133
|
+
const baseURL = typeof model.provider?.api === 'string' ? model.provider.api : provider.api;
|
|
134
|
+
if (typeof npm !== 'string' || typeof baseURL !== 'string')
|
|
135
|
+
return undefined;
|
|
136
|
+
return { go, npm, baseURL, modelId: typeof model.id === 'string' && model.id !== '' ? model.id : id };
|
|
137
|
+
}
|
|
138
|
+
/** A refresh keeps the workspace and the refresh token when the grant omits them. */
|
|
139
|
+
function toCredentials(tokens, previous) {
|
|
140
|
+
const orgId = tokens.org_id;
|
|
141
|
+
const workspace = typeof orgId === 'string' && orgId !== '' ? orgId : previous?.orgId;
|
|
142
|
+
return {
|
|
143
|
+
access: tokens.access_token,
|
|
144
|
+
refresh: tokens.refresh_token ?? previous?.refresh ?? '',
|
|
145
|
+
expires: expiryFrom(tokens.expires_in),
|
|
146
|
+
...(workspace === undefined ? {} : { orgId: workspace }),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
@@ -5,16 +5,12 @@ import type { OAuthProvider } from './types.ts';
|
|
|
5
5
|
export interface LoginOptionsById {
|
|
6
6
|
readonly openai: CodexLoginOptions;
|
|
7
7
|
readonly 'github-copilot': CopilotLoginOptions;
|
|
8
|
+
readonly 'opencode-console': Record<string, never>;
|
|
8
9
|
readonly spacexai: Record<string, never>;
|
|
9
10
|
}
|
|
10
11
|
export type ProviderId = keyof LoginOptionsById;
|
|
11
|
-
export declare const PROVIDER_IDS: readonly ["openai", "github-copilot", "spacexai"];
|
|
12
|
+
export declare const PROVIDER_IDS: readonly ["openai", "github-copilot", "opencode-console", "spacexai"];
|
|
12
13
|
export declare function isProviderId(id: string): id is ProviderId;
|
|
13
14
|
export declare function getProvider(id: ProviderId): OAuthProvider;
|
|
14
|
-
/**
|
|
15
|
-
* How requests identify this harness to a vendor: `e2e/<version> (<platform>; <arch>)`,
|
|
16
|
-
* alongside the `originator` (ChatGPT) and `referrer` (SpaceXAI) the flows send. Never another client's name.
|
|
17
|
-
*/
|
|
18
|
-
export declare const USER_AGENT: string;
|
|
19
15
|
/** How a missing login is described to the user: the CLI command that fixes it. */
|
|
20
16
|
export declare function loginHint(id: ProviderId): string;
|
package/dist/oauth/providers.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/** The built-in providers by id, and the login options each one takes. */
|
|
2
|
-
import { packageVersion } from '../internal/package-version.js';
|
|
3
2
|
import { createCodexProvider } from './providers/openai.js';
|
|
4
3
|
import { createCopilotProvider } from './providers/github-copilot.js';
|
|
4
|
+
import { createOpencodeConsoleProvider } from './providers/opencode-console.js';
|
|
5
5
|
import { createXaiProvider } from './providers/xai.js';
|
|
6
|
-
export const PROVIDER_IDS = ['openai', 'github-copilot', 'spacexai'];
|
|
6
|
+
export const PROVIDER_IDS = ['openai', 'github-copilot', 'opencode-console', 'spacexai'];
|
|
7
7
|
// Method shorthand is bivariant, so each specialised provider fits the base interface without a cast.
|
|
8
8
|
const PROVIDERS = {
|
|
9
9
|
openai: createCodexProvider(),
|
|
10
10
|
'github-copilot': createCopilotProvider(),
|
|
11
|
+
'opencode-console': createOpencodeConsoleProvider(),
|
|
11
12
|
spacexai: createXaiProvider(),
|
|
12
13
|
};
|
|
13
14
|
export function isProviderId(id) {
|
|
@@ -16,11 +17,6 @@ export function isProviderId(id) {
|
|
|
16
17
|
export function getProvider(id) {
|
|
17
18
|
return PROVIDERS[id];
|
|
18
19
|
}
|
|
19
|
-
/**
|
|
20
|
-
* How requests identify this harness to a vendor: `e2e/<version> (<platform>; <arch>)`,
|
|
21
|
-
* alongside the `originator` (ChatGPT) and `referrer` (SpaceXAI) the flows send. Never another client's name.
|
|
22
|
-
*/
|
|
23
|
-
export const USER_AGENT = `e2e/${packageVersion(import.meta.url, '../../package.json', '0.0.0')} (${process.platform}; ${process.arch})`;
|
|
24
20
|
/** How a missing login is described to the user: the CLI command that fixes it. */
|
|
25
21
|
export function loginHint(id) {
|
|
26
22
|
return `run \`npx e2e login ${id}\``;
|