arco-workbench 0.2.2 → 0.2.5
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/CONTRIBUTING.md +1 -1
- package/THIRD_PARTY_NOTICES +2 -2
- package/client/dist/assets/{PhosphorBackdrop-BbR3xmfD.js → PhosphorBackdrop-CLILIwOQ.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-UMjbs9ZN.js → ThemedBackgroundShaderImpl-B87chcb5.js} +1 -1
- package/client/dist/assets/{XtermView-n135qz-f.js → XtermView-BP_j7WSN.js} +1 -1
- package/client/dist/assets/{galleryEditor-CFSke4by.js → galleryEditor-B90phoBI.js} +1 -1
- package/client/dist/assets/{index-DeoJbjI3.js → index-BfPp1Oup.js} +270 -270
- package/client/dist/index.html +1 -1
- package/client/dist/manifest-mobile.webmanifest +1 -0
- package/client/src/App.tsx +2 -2
- package/client/src/components/AuthReloginNotice.tsx +7 -6
- package/client/src/components/ChatMessage.tsx +41 -29
- package/client/src/components/ChatPanel.tsx +17 -4
- package/client/src/components/ClaudeNativeAccountPicker.tsx +32 -0
- package/client/src/components/ClaudeNativeAuthRow.tsx +71 -19
- package/client/src/components/ClusterRightPanel/AddWorkerSection.tsx +11 -281
- package/client/src/components/ClusterRightPanel/AutoPickupControl.tsx +1 -1
- package/client/src/components/ClusterRightPanel/FreshMemberForm.tsx +315 -0
- package/client/src/components/ClusterRightPanel/ReplaceMemberDialog.tsx +17 -7
- package/client/src/components/ClusterRightPanel/index.tsx +1 -1
- package/client/src/components/ClusterRightPanel/useFreshMemberPicker.ts +6 -4
- package/client/src/components/ClusterTab.tsx +2 -2
- package/client/src/components/Connections/Connections.tsx +7 -11
- package/client/src/components/Connections/model.ts +3 -1
- package/client/src/components/FileViewerModal.tsx +54 -17
- package/client/src/components/GitHubPanel/index.tsx +9 -5
- package/client/src/components/HandoffDialog.tsx +5 -3
- package/client/src/components/MobileShell.tsx +1 -33
- package/client/src/components/OperatorQuestionNotice.tsx +5 -4
- package/client/src/components/ProvidersPopover.tsx +6 -2
- package/client/src/components/RightPanel/ActivityTab.tsx +2 -1
- package/client/src/components/RightPanel/ConfigTab.tsx +23 -5
- package/client/src/components/RightPanel/OutputsPanel.tsx +21 -9
- package/client/src/components/RightPanel/outputsReconcile.ts +31 -0
- package/client/src/components/SettingsPanel.tsx +7 -10
- package/client/src/components/SpawnDialog.tsx +14 -3
- package/client/src/components/TabBar.tsx +2 -2
- package/client/src/components/TabContextMenu.tsx +73 -133
- package/client/src/components/TerminalInput.tsx +4 -3
- package/client/src/components/TranscriptWorkerDialog.tsx +14 -4
- package/client/src/components/UsageBar.tsx +37 -18
- package/client/src/components/WorkflowCreator/ClusterMembersSection.tsx +29 -3
- package/client/src/components/WorkflowCreator/index.tsx +29 -15
- package/client/src/components/WorkflowView.tsx +1 -1
- package/client/src/components/providerIndicator.ts +7 -3
- package/client/src/components/research/QuickResearchOverview.tsx +7 -3
- package/client/src/components/research/SavedQuickKeep.tsx +7 -3
- package/client/src/components/settings/GitHubAuthRow.tsx +34 -0
- package/client/src/explorer/ArtifactsLens.tsx +17 -8
- package/client/src/explorer/ExplorerApp.tsx +3 -3
- package/client/src/explorer/types.ts +3 -1
- package/client/src/help/content/cluster.tsx +10 -4
- package/client/src/help/content/composer.tsx +3 -2
- package/client/src/help/content/header.tsx +6 -3
- package/client/src/help/content/misc.tsx +9 -7
- package/client/src/help/content/rightPanel.tsx +11 -6
- package/client/src/help/content/settings.tsx +14 -3
- package/client/src/help/content/tabbar.tsx +1 -1
- package/client/src/help/manualSections/actions.tsx +5 -1
- package/client/src/help/manualSections/clusters.tsx +21 -15
- package/client/src/help/manualSections/configuration.tsx +6 -4
- package/client/src/help/manualSections/gettingStarted.tsx +4 -2
- package/client/src/help/manualSections/maintenance.tsx +24 -0
- package/client/src/help/manualSections/powerFeatures.tsx +4 -2
- package/client/src/help/manualSections/providers.tsx +11 -4
- package/client/src/help/manualSections/workspace.tsx +3 -3
- package/client/src/hooks/useClaudeNativeCatalog.ts +26 -0
- package/client/src/hooks/useClaudeNativeLogin.ts +16 -11
- package/client/src/hooks/useWebSocket.ts +4 -2
- package/client/src/layout/layoutRange.ts +14 -5
- package/client/src/main.tsx +2 -0
- package/client/src/questions/waitingQuestion.ts +2 -0
- package/client/src/stores/appStore.ts +5 -1
- package/client/src/stores/appStore.types.ts +2 -0
- package/client/src/stores/replayContext.ts +20 -0
- package/client/src/utils/chatFileLinks.ts +34 -3
- package/client/src/utils/claudeAuth.ts +9 -1
- package/client/src/ws/handleServerMessage.ts +11 -3
- package/docs/ARCHITECTURE.md +3 -3
- package/docs/BACKUP.md +1 -1
- package/docs/CHECKPOINTS.md +67 -3
- package/docs/CLIENT.md +11 -6
- package/docs/EXTENDING.md +1 -1
- package/docs/FEATURES.md +3 -3
- package/docs/GETTING_STARTED.md +5 -4
- package/docs/GIT_WORKBENCH.md +8 -0
- package/docs/GLOSSARY.md +2 -2
- package/docs/GOTCHAS.md +4 -4
- package/docs/HTTP_API.md +63 -30
- package/docs/OPERATIONS.md +11 -0
- package/docs/OPERATOR_ACTIONS.md +2 -2
- package/docs/OUTPUTS.md +48 -6
- package/docs/PERSISTENCE.md +1 -1
- package/docs/PRIMITIVES.md +4 -2
- package/docs/PROTOCOL_CLUSTER.md +12 -6
- package/docs/PROTOCOL_PRIMITIVES.md +1 -1
- package/docs/PROVIDERS.md +47 -10
- package/docs/RESEARCH.md +3 -3
- package/docs/SETTINGS.md +9 -4
- package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +15 -3
- package/node_modules/@arco/shared/dist/protocol/clusters.js +1 -1
- package/node_modules/@arco/shared/dist/protocol/models.d.ts +6 -1
- package/node_modules/@arco/shared/dist/protocol/operatorQuestions.d.ts +2 -1
- package/node_modules/@arco/shared/dist/protocol/settings.d.ts +3 -0
- package/node_modules/@arco/shared/dist/protocol/settings.js +5 -0
- package/node_modules/@arco/shared/dist/protocol/workflows.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/workflows.js +0 -2
- package/node_modules/@arco/shared/package.json +1 -1
- package/package.json +2 -2
- package/scripts/packaging/services.mjs +20 -1
- package/scripts/packaging/update.mjs +37 -2
- package/server/dist/attention.d.ts +6 -0
- package/server/dist/attention.js +6 -0
- package/server/dist/auth.d.ts +5 -0
- package/server/dist/auth.js +31 -20
- package/server/dist/clusterAutoTurn.d.ts +5 -1
- package/server/dist/clusterAutoTurn.js +31 -9
- package/server/dist/clusterPresets.js +3 -3
- package/server/dist/effortValidation.d.ts +2 -2
- package/server/dist/effortValidation.js +4 -4
- package/server/dist/explorerArtifacts.d.ts +1 -0
- package/server/dist/explorerArtifacts.js +12 -1
- package/server/dist/explorerDocs.d.ts +1 -0
- package/server/dist/explorerDocs.js +4 -4
- package/server/dist/geminiMembers.d.ts +7 -1
- package/server/dist/geminiMembers.js +28 -14
- package/server/dist/gitSnapshots.d.ts +1 -0
- package/server/dist/gitSnapshots.js +547 -83
- package/server/dist/http/clusterRoutes.js +9 -3
- package/server/dist/http/conversationFiles.d.ts +36 -0
- package/server/dist/http/conversationFiles.js +222 -0
- package/server/dist/http/fileBytes.d.ts +3 -0
- package/server/dist/http/fileBytes.js +33 -0
- package/server/dist/http/fileContentRoute.d.ts +2 -0
- package/server/dist/http/fileContentRoute.js +139 -0
- package/server/dist/http/fileRead.d.ts +54 -2
- package/server/dist/http/fileRead.js +31 -24
- package/server/dist/http/outputRoutes.js +14 -21
- package/server/dist/http/readConfinement.d.ts +0 -11
- package/server/dist/http/readConfinement.js +4 -30
- package/server/dist/http/router.js +41 -66
- package/server/dist/index.js +26 -12
- package/server/dist/management/initHubLink.js +1 -1
- package/server/dist/outputs.js +8 -0
- package/server/dist/primitives/exportContext.d.ts +2 -0
- package/server/dist/primitives/exportContext.js +13 -2
- package/server/dist/primitives/runCompare.d.ts +7 -1
- package/server/dist/primitives/runCompare.js +44 -20
- package/server/dist/project/taskLedger.js +46 -34
- package/server/dist/providerAccounts.d.ts +4 -0
- package/server/dist/providerAccounts.js +20 -1
- package/server/dist/providers/antigravity/artifacts.d.ts +23 -0
- package/server/dist/providers/antigravity/artifacts.js +140 -0
- package/server/dist/providers/antigravity/index.js +85 -7
- package/server/dist/providers/antigravity/questions.d.ts +2 -0
- package/server/dist/providers/antigravity/questions.js +58 -0
- package/server/dist/providers/claude-native/auth.d.ts +9 -8
- package/server/dist/providers/claude-native/auth.js +50 -58
- package/server/dist/providers/claude-native/authStatus.d.ts +2 -2
- package/server/dist/providers/claude-native/authStatus.js +9 -7
- package/server/dist/providers/claude-native/catalog.d.ts +6 -5
- package/server/dist/providers/claude-native/catalog.js +50 -39
- package/server/dist/providers/claude-native/oauth.d.ts +10 -9
- package/server/dist/providers/claude-native/oauth.js +120 -96
- package/server/dist/providers/claude-native/worker.d.ts +1 -0
- package/server/dist/providers/claude-native/worker.js +38 -23
- package/server/dist/providers/codex-appserver/operatorQuestions.d.ts +5 -3
- package/server/dist/providers/codex-appserver/operatorQuestions.js +27 -13
- package/server/dist/providers/codexChatBoundary.js +6 -1
- package/server/dist/research/quickPromotion.d.ts +3 -0
- package/server/dist/research/quickPromotion.js +26 -9
- package/server/dist/research/savedQuickPromotion.js +2 -11
- package/server/dist/server/broadcast.js +6 -0
- package/server/dist/settings.d.ts +1 -0
- package/server/dist/settings.js +39 -7
- package/server/dist/skills.js +1 -1
- package/server/dist/smartPickupAdapters.d.ts +1 -0
- package/server/dist/smartPickupAdapters.js +2 -2
- package/server/dist/smartPickupObserver.js +8 -5
- package/server/dist/thirdPartySkills.js +11 -5
- package/server/dist/turnChanges.d.ts +1 -1
- package/server/dist/turnChanges.js +5 -4
- package/server/dist/usage.d.ts +1 -1
- package/server/dist/usage.js +39 -27
- package/server/dist/workers/WorkerManager.d.ts +1 -0
- package/server/dist/workers/WorkerManager.js +1 -0
- package/server/dist/workers/processKill.js +37 -24
- package/server/dist/workflowMeta.js +2 -2
- package/server/dist/ws/clusterHandlers.d.ts +2 -2
- package/server/dist/ws/clusterHandlers.js +127 -113
- package/server/dist/ws/clusterMembers.d.ts +1 -1
- package/server/dist/ws/clusterMembers.js +34 -4
- package/server/dist/ws/compactHandlers.js +30 -14
- package/server/dist/ws/compareHandlers.js +53 -21
- package/server/dist/ws/gateHandlers.js +2 -0
- package/server/dist/ws/genesisHandlers.js +5 -3
- package/server/dist/ws/handoffHandlers.d.ts +1 -1
- package/server/dist/ws/handoffHandlers.js +115 -39
- package/server/dist/ws/transcriptWorkerHandlers.js +7 -2
- package/server/dist/ws/turnEngine.js +37 -19
- package/server/dist/ws/updatePrimaryConfig.d.ts +3 -2
- package/server/dist/ws/updatePrimaryConfig.js +236 -133
- package/server/dist/ws/workflowHandlers.js +21 -4
- package/server/package.json +1 -1
- package/server/src/attention.ts +7 -0
- package/server/src/auth.ts +33 -20
- package/server/src/clusterAutoTurn.ts +31 -11
- package/server/src/clusterPresets.ts +2 -2
- package/server/src/effortValidation.ts +4 -4
- package/server/src/explorerArtifacts.ts +12 -1
- package/server/src/explorerDocs.ts +5 -5
- package/server/src/geminiMembers.ts +26 -15
- package/server/src/gitSnapshots.ts +538 -82
- package/server/src/http/clusterRoutes.ts +10 -3
- package/server/src/http/conversationFiles.ts +231 -0
- package/server/src/http/fileBytes.ts +34 -0
- package/server/src/http/fileContentRoute.ts +123 -0
- package/server/src/http/fileRead.ts +30 -25
- package/server/src/http/outputRoutes.ts +13 -13
- package/server/src/http/readConfinement.ts +3 -30
- package/server/src/http/router.ts +39 -62
- package/server/src/index.ts +27 -18
- package/server/src/management/initHubLink.ts +1 -1
- package/server/src/outputs.ts +8 -0
- package/server/src/primitives/exportContext.ts +14 -2
- package/server/src/primitives/runCompare.ts +73 -46
- package/server/src/project/taskLedger.ts +47 -30
- package/server/src/providerAccounts.ts +20 -1
- package/server/src/providers/antigravity/artifacts.ts +121 -0
- package/server/src/providers/antigravity/index.ts +64 -6
- package/server/src/providers/antigravity/questions.ts +52 -0
- package/server/src/providers/claude-native/auth.ts +45 -60
- package/server/src/providers/claude-native/authStatus.ts +9 -8
- package/server/src/providers/claude-native/catalog.ts +52 -35
- package/server/src/providers/claude-native/oauth.ts +101 -77
- package/server/src/providers/claude-native/worker.ts +38 -22
- package/server/src/providers/codex-appserver/operatorQuestions.ts +26 -12
- package/server/src/providers/codexChatBoundary.ts +6 -1
- package/server/src/research/quickPromotion.ts +24 -6
- package/server/src/research/savedQuickPromotion.ts +2 -8
- package/server/src/server/broadcast.ts +4 -0
- package/server/src/settings.ts +36 -8
- package/server/src/skills.ts +1 -1
- package/server/src/smartPickupAdapters.ts +3 -2
- package/server/src/smartPickupObserver.ts +8 -5
- package/server/src/thirdPartySkills.ts +11 -5
- package/server/src/turnChanges.ts +5 -4
- package/server/src/usage.ts +30 -22
- package/server/src/workers/WorkerManager.ts +2 -0
- package/server/src/workers/processKill.ts +37 -23
- package/server/src/workflowMeta.ts +2 -2
- package/server/src/ws/clusterHandlers.ts +107 -104
- package/server/src/ws/clusterMembers.ts +25 -6
- package/server/src/ws/compactHandlers.ts +29 -15
- package/server/src/ws/compareHandlers.ts +59 -25
- package/server/src/ws/gateHandlers.ts +2 -0
- package/server/src/ws/genesisHandlers.ts +5 -4
- package/server/src/ws/handoffHandlers.ts +105 -37
- package/server/src/ws/transcriptWorkerHandlers.ts +6 -2
- package/server/src/ws/turnEngine.ts +36 -18
- package/server/src/ws/updatePrimaryConfig.ts +230 -132
- package/server/src/ws/workflowHandlers.ts +20 -4
- package/shared/dist/protocol/clusters.d.ts +15 -3
- package/shared/dist/protocol/clusters.js +1 -1
- package/shared/dist/protocol/models.d.ts +6 -1
- package/shared/dist/protocol/operatorQuestions.d.ts +2 -1
- package/shared/dist/protocol/settings.d.ts +3 -0
- package/shared/dist/protocol/settings.js +5 -0
- package/shared/dist/protocol/workflows.d.ts +1 -0
- package/shared/dist/protocol/workflows.js +0 -2
- package/shared/src/protocol/clusters.ts +23 -5
- package/shared/src/protocol/compare.ts +2 -2
- package/shared/src/protocol/models.ts +8 -4
- package/shared/src/protocol/operatorQuestions.ts +2 -1
- package/shared/src/protocol/settings.ts +8 -1
- package/shared/src/protocol/workflows.ts +1 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
import { promises as fs } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { homedir } from 'node:os';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
5
4
|
import * as lockfile from 'proper-lockfile';
|
|
6
5
|
import { atomicWriteFile } from '../../atomicFile.js';
|
|
7
|
-
import { arcoHome } from '../../arcoHome.js';
|
|
6
|
+
import { arcoHome, assertTestHomeSafe } from '../../arcoHome.js';
|
|
8
7
|
import { createHash } from 'node:crypto';
|
|
9
|
-
import type
|
|
8
|
+
import { DEFAULT_CLAUDE_NATIVE_ACCOUNT, isClaudeNativeProfileId, type ClaudeCredentialBinding } from '@arco/shared';
|
|
10
9
|
|
|
11
10
|
// Store Native OAuth credentials in the `claude.native` namespace so other
|
|
12
11
|
// authentication modes can coexist without overwriting them. Restrictive file
|
|
@@ -24,9 +23,9 @@ export interface ClaudeNativeTokens {
|
|
|
24
23
|
|
|
25
24
|
// The stamp changes with the actual credential material, including rotations.
|
|
26
25
|
// It exposes no token bytes and is not proof of account identity or execution.
|
|
27
|
-
export function nativeCredentialBinding(tokens?: ClaudeNativeTokens | null): ClaudeCredentialBinding {
|
|
26
|
+
export function nativeCredentialBinding(tokens?: ClaudeNativeTokens | null, accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT): ClaudeCredentialBinding {
|
|
28
27
|
return {
|
|
29
|
-
source: 'claude-native', storeId: 'claude.native'
|
|
28
|
+
source: 'claude-native', storeId: accountRef === DEFAULT_CLAUDE_NATIVE_ACCOUNT ? 'claude.native' : `claude.native:${accountRef}`,
|
|
30
29
|
...(tokens ? { revision: createHash('sha256').update(JSON.stringify([
|
|
31
30
|
tokens.accessToken, tokens.refreshToken, tokens.expiresAt, tokens.obtainedAt, tokens.tokenType, tokens.scope,
|
|
32
31
|
])).digest('hex') } : {}),
|
|
@@ -40,15 +39,15 @@ interface AuthFileShape {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
const ARCO_DIR = arcoHome();
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
function authPath(accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT): string {
|
|
43
|
+
if (accountRef === DEFAULT_CLAUDE_NATIVE_ACCOUNT) return join(ARCO_DIR, 'auth.json');
|
|
44
|
+
if (!isClaudeNativeProfileId(accountRef)) throw new Error('Invalid Claude Native account ID.');
|
|
45
|
+
return join(ARCO_DIR, 'provider-accounts', `claude-${accountRef}`, 'auth.json');
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
async function readRaw(): Promise<AuthFileShape> {
|
|
48
|
+
async function readRaw(path: string): Promise<AuthFileShape> {
|
|
50
49
|
try {
|
|
51
|
-
const buf = await fs.readFile(
|
|
50
|
+
const buf = await fs.readFile(path, 'utf8');
|
|
52
51
|
const parsed = JSON.parse(buf) as AuthFileShape;
|
|
53
52
|
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
54
53
|
} catch (err) {
|
|
@@ -57,25 +56,26 @@ async function readRaw(): Promise<AuthFileShape> {
|
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
async function writeRaw(data: AuthFileShape): Promise<void> {
|
|
61
|
-
await
|
|
62
|
-
await atomicWriteFile(AUTH_PATH, JSON.stringify(data, null, 2), { mode: 0o600 });
|
|
59
|
+
async function writeRaw(path: string, data: AuthFileShape): Promise<void> {
|
|
60
|
+
await atomicWriteFile(path, JSON.stringify(data, null, 2), { mode: 0o600 });
|
|
63
61
|
}
|
|
64
62
|
|
|
65
|
-
// proper-lockfile requires
|
|
66
|
-
//
|
|
67
|
-
async function ensureFile(): Promise<void> {
|
|
63
|
+
// proper-lockfile requires an existing target. Exclusive creation prevents a
|
|
64
|
+
// concurrent first login from being overwritten by the initial empty file.
|
|
65
|
+
async function ensureFile(path: string): Promise<void> {
|
|
66
|
+
assertTestHomeSafe(path);
|
|
67
|
+
await fs.mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
68
68
|
try {
|
|
69
|
-
await fs.
|
|
70
|
-
} catch {
|
|
71
|
-
|
|
72
|
-
await fs.writeFile(AUTH_PATH, '{}\n', { encoding: 'utf8', mode: 0o600 });
|
|
69
|
+
await fs.writeFile(path, '{}\n', { encoding: 'utf8', mode: 0o600, flag: 'wx' });
|
|
70
|
+
} catch (err) {
|
|
71
|
+
if ((err as NodeJS.ErrnoException).code !== 'EEXIST') throw err;
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
|
|
76
|
-
async function
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
export async function withAuthLock<T>(fn: () => Promise<T>, accountRef?: string): Promise<T> {
|
|
76
|
+
const path = authPath(accountRef);
|
|
77
|
+
await ensureFile(path);
|
|
78
|
+
const release = await lockfile.lock(path, {
|
|
79
79
|
retries: { retries: 10, minTimeout: 50, maxTimeout: 500 },
|
|
80
80
|
stale: 30_000,
|
|
81
81
|
});
|
|
@@ -86,49 +86,34 @@ async function withLock<T>(fn: () => Promise<T>): Promise<T> {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
export async function loadTokens(): Promise<ClaudeNativeTokens | null> {
|
|
90
|
-
const data = await readRaw();
|
|
89
|
+
export async function loadTokens(accountRef?: string): Promise<ClaudeNativeTokens | null> {
|
|
90
|
+
const data = await readRaw(authPath(accountRef));
|
|
91
91
|
return data.claude?.native ?? null;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
export async function saveTokens(next: ClaudeNativeTokens): Promise<void> {
|
|
95
|
-
await
|
|
96
|
-
const data = await readRaw();
|
|
97
|
-
const merged: AuthFileShape = {
|
|
98
|
-
...data,
|
|
99
|
-
claude: { ...(data.claude ?? {}), native: next },
|
|
100
|
-
};
|
|
101
|
-
await writeRaw(merged);
|
|
102
|
-
});
|
|
94
|
+
export async function saveTokens(next: ClaudeNativeTokens, accountRef?: string): Promise<void> {
|
|
95
|
+
await withAuthLock(() => writeTokensUnlocked(next, accountRef), accountRef);
|
|
103
96
|
}
|
|
104
97
|
|
|
105
|
-
export async function clearTokens(): Promise<void> {
|
|
106
|
-
await
|
|
107
|
-
const data = await readRaw();
|
|
108
|
-
if (data.claude?.native) {
|
|
109
|
-
delete data.claude.native;
|
|
110
|
-
if (Object.keys(data.claude).length === 0) delete data.claude;
|
|
111
|
-
}
|
|
112
|
-
await writeRaw(data);
|
|
113
|
-
});
|
|
98
|
+
export async function clearTokens(accountRef?: string): Promise<void> {
|
|
99
|
+
await withAuthLock(() => clearTokensUnlocked(accountRef), accountRef);
|
|
114
100
|
}
|
|
115
101
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
102
|
+
export async function clearTokensUnlocked(accountRef?: string): Promise<void> {
|
|
103
|
+
const path = authPath(accountRef);
|
|
104
|
+
const data = await readRaw(path);
|
|
105
|
+
if (!data.claude?.native) return;
|
|
106
|
+
delete data.claude.native;
|
|
107
|
+
if (Object.keys(data.claude).length === 0) delete data.claude;
|
|
108
|
+
await writeRaw(path, data);
|
|
120
109
|
}
|
|
121
110
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
111
|
+
// OAuth holds the profile lock while reading a refresh grant and writing its
|
|
112
|
+
// replacement. Reads outside the lock observe one complete file version.
|
|
113
|
+
export const readTokensUnlocked = loadTokens;
|
|
126
114
|
|
|
127
|
-
export async function writeTokensUnlocked(next: ClaudeNativeTokens): Promise<void> {
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
claude: { ...(data.claude ?? {}), native: next },
|
|
132
|
-
};
|
|
133
|
-
await writeRaw(merged);
|
|
115
|
+
export async function writeTokensUnlocked(next: ClaudeNativeTokens, accountRef?: string): Promise<void> {
|
|
116
|
+
const path = authPath(accountRef);
|
|
117
|
+
const data = await readRaw(path);
|
|
118
|
+
await writeRaw(path, { ...data, claude: { ...(data.claude ?? {}), native: next } });
|
|
134
119
|
}
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { DEFAULT_CLAUDE_NATIVE_ACCOUNT, type ClaudeNativeAuthStatus } from '@arco/shared';
|
|
2
2
|
import { loadTokens, nativeCredentialBinding } from './auth.js';
|
|
3
3
|
import { getClaudeAuthProblem, REFRESH_LEAD_MS_EXPORT } from './oauth.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const statuses = new Map<string, ClaudeNativeAuthStatus>();
|
|
6
6
|
|
|
7
7
|
// Metadata only: never refresh, start OAuth, query allowance or send inference.
|
|
8
|
-
export async function getClaudeNativeAuthStatus(): Promise<ClaudeNativeAuthStatus> {
|
|
8
|
+
export async function getClaudeNativeAuthStatus(accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT): Promise<ClaudeNativeAuthStatus> {
|
|
9
|
+
const lastStatus = statuses.get(accountRef);
|
|
9
10
|
try {
|
|
10
|
-
const tokens = await loadTokens();
|
|
11
|
+
const tokens = await loadTokens(accountRef);
|
|
11
12
|
if (tokens && (typeof tokens.accessToken !== 'string' || !tokens.accessToken
|
|
12
13
|
|| typeof tokens.refreshToken !== 'string' || !tokens.refreshToken
|
|
13
14
|
|| !Number.isFinite(tokens.expiresAt))) throw new Error('Invalid Native credential metadata');
|
|
14
|
-
const problem = getClaudeAuthProblem();
|
|
15
|
+
const problem = getClaudeAuthProblem(accountRef);
|
|
15
16
|
const status: ClaudeNativeAuthStatus = {
|
|
16
17
|
state: !tokens ? 'missing' : problem ? 'needs-attention' : tokens.expiresAt <= Date.now() + REFRESH_LEAD_MS_EXPORT ? 'refresh-needed' : 'present',
|
|
17
18
|
credentialsPresent: !!tokens,
|
|
18
19
|
execution: 'unverified',
|
|
19
|
-
binding: nativeCredentialBinding(tokens),
|
|
20
|
+
binding: nativeCredentialBinding(tokens, accountRef),
|
|
20
21
|
checkedAt: Date.now(),
|
|
21
22
|
...(tokens ? { expiresAt: tokens.expiresAt, scopes: typeof tokens.scope === 'string' ? tokens.scope.split(/\s+/).filter(Boolean) : [] } : {}),
|
|
22
23
|
...(tokens && problem ? { problemSince: problem.since, error: 'Native authentication reported a problem. Open Native settings to recover.' } : {}),
|
|
23
24
|
};
|
|
24
|
-
|
|
25
|
+
statuses.set(accountRef, status);
|
|
25
26
|
return status;
|
|
26
27
|
} catch {
|
|
27
28
|
return {
|
|
28
|
-
...(lastStatus ?? { credentialsPresent: false, execution: 'unverified', binding: nativeCredentialBinding(), checkedAt: Date.now() }),
|
|
29
|
+
...(lastStatus ?? { credentialsPresent: false, execution: 'unverified', binding: nativeCredentialBinding(null, accountRef), checkedAt: Date.now() }),
|
|
29
30
|
state: 'unknown', probeFailed: true, stale: !!lastStatus,
|
|
30
31
|
error: 'Native credential status could not be read. The previous result may be out of date.',
|
|
31
32
|
};
|
|
@@ -12,9 +12,12 @@
|
|
|
12
12
|
// Refresh cadence: 1 hour. New models surface within that window
|
|
13
13
|
// without an Arco restart.
|
|
14
14
|
|
|
15
|
+
import { loadTokens, nativeCredentialBinding, type ClaudeNativeTokens } from './auth.js';
|
|
16
|
+
import { requireClaudeNativeAccount } from '../../providerAccounts.js';
|
|
15
17
|
import { ensureLiveTokens } from './oauth.js';
|
|
16
18
|
import { CLAUDE_CLI_USER_AGENT } from './wireFingerprint.js';
|
|
17
19
|
import {
|
|
20
|
+
DEFAULT_CLAUDE_NATIVE_ACCOUNT,
|
|
18
21
|
claudeAliasFamily,
|
|
19
22
|
CLAUDE_ALIAS_FALLBACK,
|
|
20
23
|
distillCatalogModel,
|
|
@@ -63,8 +66,17 @@ export interface AnthropicModel {
|
|
|
63
66
|
};
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
interface CatalogEntry {
|
|
70
|
+
revision?: string;
|
|
71
|
+
snapshot?: ClaudeCatalogSnapshot;
|
|
72
|
+
inFlight?: Promise<ClaudeCatalogSnapshot>;
|
|
73
|
+
}
|
|
74
|
+
const catalogs = new Map<string, CatalogEntry>();
|
|
75
|
+
const cached = (accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT) => catalogs.get(accountRef)?.snapshot;
|
|
76
|
+
|
|
77
|
+
export function forgetCatalog(accountRef: string): void {
|
|
78
|
+
catalogs.delete(accountRef);
|
|
79
|
+
}
|
|
68
80
|
|
|
69
81
|
// Phase 7c-followup — synchronous catalog-capability lookup for the Native
|
|
70
82
|
// worker's per-request beta-header construction. Returns `null` when the
|
|
@@ -73,13 +85,12 @@ let inFlight: Promise<ClaudeCatalogSnapshot> | null = null;
|
|
|
73
85
|
// Worker treats `null` conservatively: skip context-management betas
|
|
74
86
|
// rather than risk a 400. The catalog refresh is async and hourly; the
|
|
75
87
|
// worker reads the in-memory cache only.
|
|
76
|
-
export function getCachedModelCapabilities(modelId: string): {
|
|
88
|
+
export function getCachedModelCapabilities(modelId: string, accountRef?: string): {
|
|
77
89
|
supportsClearThinking: boolean;
|
|
78
90
|
supportsClearToolUses: boolean;
|
|
79
91
|
supportsCompact: boolean;
|
|
80
92
|
} | null {
|
|
81
|
-
|
|
82
|
-
const m = cache.models.find((x) => x.id === modelId);
|
|
93
|
+
const m = cached(accountRef)?.models.find((x) => x.id === modelId);
|
|
83
94
|
if (!m) return null;
|
|
84
95
|
return {
|
|
85
96
|
supportsClearThinking: m.supportsClearThinking,
|
|
@@ -89,14 +100,14 @@ export function getCachedModelCapabilities(modelId: string): {
|
|
|
89
100
|
}
|
|
90
101
|
|
|
91
102
|
// The picker uses the same cached model efforts when a catalog is available.
|
|
92
|
-
export function getCachedClaudeModelEfforts(modelId: string): ClaudeCatalogModel['supportedEfforts'] | undefined {
|
|
93
|
-
return
|
|
103
|
+
export function getCachedClaudeModelEfforts(modelId: string, accountRef?: string): ClaudeCatalogModel['supportedEfforts'] | undefined {
|
|
104
|
+
return cached(accountRef)?.models.find((model) => model.id === modelId)?.supportedEfforts;
|
|
94
105
|
}
|
|
95
106
|
|
|
96
107
|
// True once a non-empty catalog has been fetched in this process. Callers use
|
|
97
108
|
// it to decide whether an alias resolution is catalog-backed or a static guess.
|
|
98
|
-
export function hasCatalogCache(): boolean {
|
|
99
|
-
return
|
|
109
|
+
export function hasCatalogCache(accountRef?: string): boolean {
|
|
110
|
+
return (cached(accountRef)?.models.length ?? 0) > 0;
|
|
100
111
|
}
|
|
101
112
|
|
|
102
113
|
// resolve a family alias ('opus' / 'opus[1m]' / 'sonnet' /
|
|
@@ -107,10 +118,10 @@ export function hasCatalogCache(): boolean {
|
|
|
107
118
|
//
|
|
108
119
|
// Concrete ids pass through untouched. Falls back to CLAUDE_ALIAS_FALLBACK
|
|
109
120
|
// when the catalog is cold — a stale-but-real id beats a guaranteed 404.
|
|
110
|
-
export function resolveClaudeAliasFromCatalog(modelId: string): string {
|
|
121
|
+
export function resolveClaudeAliasFromCatalog(modelId: string, accountRef?: string): string {
|
|
111
122
|
const family = claudeAliasFamily(modelId);
|
|
112
123
|
if (!family) return modelId;
|
|
113
|
-
const inFamily = (
|
|
124
|
+
const inFamily = (cached(accountRef)?.models ?? []).filter((m) => m.id.includes(family));
|
|
114
125
|
if (inFamily.length === 0) return CLAUDE_ALIAS_FALLBACK[family];
|
|
115
126
|
// Newest by created_at, not catalog order — /v1/models happens to sort
|
|
116
127
|
// newest-first today, but nothing in the contract promises it.
|
|
@@ -122,31 +133,40 @@ export function resolveClaudeAliasFromCatalog(modelId: string): string {
|
|
|
122
133
|
// Public accessor. Returns the cached snapshot; refreshes if older than
|
|
123
134
|
// REFRESH_INTERVAL_MS, in-flight request, or never fetched. Failures
|
|
124
135
|
// degrade to the last good cache rather than throwing.
|
|
125
|
-
export async function getCatalog(force = false): Promise<ClaudeCatalogSnapshot> {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
136
|
+
export async function getCatalog(force = false, requestedAccount?: string): Promise<ClaudeCatalogSnapshot> {
|
|
137
|
+
const accountRef = await requireClaudeNativeAccount(requestedAccount);
|
|
138
|
+
const empty = { fetchedAt: Date.now(), models: [], fresh: false };
|
|
139
|
+
const tokens = await loadTokens(accountRef);
|
|
140
|
+
if (!tokens) {
|
|
141
|
+
forgetCatalog(accountRef);
|
|
142
|
+
return empty;
|
|
143
|
+
}
|
|
144
|
+
const revision = nativeCredentialBinding(tokens, accountRef).revision;
|
|
145
|
+
let entry = catalogs.get(accountRef);
|
|
146
|
+
if (!entry || entry.revision !== revision) {
|
|
147
|
+
entry = { revision };
|
|
148
|
+
catalogs.set(accountRef, entry);
|
|
149
|
+
}
|
|
150
|
+
if (!force && entry.snapshot && Date.now() - entry.snapshot.fetchedAt < REFRESH_INTERVAL_MS) return entry.snapshot;
|
|
151
|
+
if (entry.inFlight) return entry.inFlight;
|
|
152
|
+
const current = entry;
|
|
153
|
+
current.inFlight = (async () => {
|
|
130
154
|
try {
|
|
131
|
-
const
|
|
132
|
-
|
|
155
|
+
const live = await ensureLiveTokens(accountRef);
|
|
156
|
+
const fresh = await fetchCatalog(live);
|
|
157
|
+
const after = await loadTokens(accountRef);
|
|
158
|
+
if (catalogs.get(accountRef) !== current || nativeCredentialBinding(live, accountRef).revision !== nativeCredentialBinding(after, accountRef).revision) return empty;
|
|
159
|
+
current.revision = nativeCredentialBinding(live, accountRef).revision;
|
|
160
|
+
current.snapshot = fresh;
|
|
133
161
|
return fresh;
|
|
134
|
-
} catch
|
|
135
|
-
|
|
136
|
-
console.warn('[claude-native:catalog] refresh failed; serving stale cache:', err instanceof Error ? err.message : err);
|
|
137
|
-
return { ...cache, fresh: false };
|
|
138
|
-
}
|
|
139
|
-
// No cache to fall back on. Return an empty snapshot; the UI uses
|
|
140
|
-
// the compile-time CLAUDE_MODELS list as a baseline.
|
|
141
|
-
console.warn('[claude-native:catalog] no auth and no cache:', err instanceof Error ? err.message : err);
|
|
142
|
-
return { fetchedAt: now, models: [], fresh: false };
|
|
162
|
+
} catch {
|
|
163
|
+
return catalogs.get(accountRef) === current && current.snapshot ? { ...current.snapshot, fresh: false } : empty;
|
|
143
164
|
}
|
|
144
|
-
})().finally(() => { inFlight =
|
|
145
|
-
return inFlight;
|
|
165
|
+
})().finally(() => { current.inFlight = undefined; });
|
|
166
|
+
return current.inFlight;
|
|
146
167
|
}
|
|
147
168
|
|
|
148
|
-
async function fetchCatalog(): Promise<ClaudeCatalogSnapshot> {
|
|
149
|
-
const tokens = await ensureLiveTokens();
|
|
169
|
+
async function fetchCatalog(tokens: ClaudeNativeTokens): Promise<ClaudeCatalogSnapshot> {
|
|
150
170
|
const controller = new AbortController();
|
|
151
171
|
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
152
172
|
try {
|
|
@@ -162,10 +182,7 @@ async function fetchCatalog(): Promise<ClaudeCatalogSnapshot> {
|
|
|
162
182
|
},
|
|
163
183
|
signal: controller.signal,
|
|
164
184
|
});
|
|
165
|
-
if (!resp.ok) {
|
|
166
|
-
const text = await resp.text().catch(() => '');
|
|
167
|
-
throw new Error(`/v1/models ${resp.status}: ${text.slice(0, 200)}`);
|
|
168
|
-
}
|
|
185
|
+
if (!resp.ok) throw new Error(`/v1/models ${resp.status}`);
|
|
169
186
|
const body = await resp.json() as { data?: AnthropicModel[] };
|
|
170
187
|
const raw = Array.isArray(body.data) ? body.data : [];
|
|
171
188
|
// Distil into the picker shape (camelCase displayName, supportedEfforts
|