arco-workbench 0.2.4 → 0.2.6
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-CHXVFLGT.js → PhosphorBackdrop-YsHTmZJh.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-Bhs4I9jA.js → ThemedBackgroundShaderImpl-BEjpgoBW.js} +1 -1
- package/client/dist/assets/{XtermView-CdfurwFx.js → XtermView-wh7jNKvk.js} +1 -1
- package/client/dist/assets/{galleryEditor-DYjZZ4cf.js → galleryEditor-CaOS2mmM.js} +1 -1
- package/client/dist/assets/{index-BjDmFvqG.js → index-j68SfA-l.js} +271 -271
- package/client/dist/index.html +1 -1
- 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 +5 -9
- 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/UpdateAction.tsx +30 -7
- 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/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 +11 -4
- package/client/src/help/content/misc.tsx +7 -5
- package/client/src/help/content/rightPanel.tsx +8 -4
- package/client/src/help/content/settings.tsx +15 -4
- 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 +20 -14
- 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 +31 -0
- package/client/src/help/manualSections/powerFeatures.tsx +1 -0
- 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 +4 -5
- 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/CLIENT.md +10 -5
- 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 +54 -23
- package/docs/OPERATIONS.md +17 -1
- 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 +46 -9
- package/docs/RESEARCH.md +1 -1
- 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/geminiMembers.d.ts +7 -1
- package/server/dist/geminiMembers.js +28 -14
- 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 +40 -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/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/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 +33 -18
- 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/geminiMembers.ts +26 -15
- 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 +38 -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/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/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 +32 -17
- 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
|
@@ -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
|
|
@@ -14,10 +14,12 @@
|
|
|
14
14
|
// authorize URL and accept a `{ url }` paste body to extract `code` +
|
|
15
15
|
// `state`.
|
|
16
16
|
|
|
17
|
-
import type
|
|
17
|
+
import { DEFAULT_CLAUDE_NATIVE_ACCOUNT, type ClaudeCredentialBinding, type ClaudeNativeAuthFlow } from '@arco/shared';
|
|
18
|
+
import { requireClaudeNativeAccount } from '../../providerAccounts.js';
|
|
18
19
|
import { createServer, type Server } from 'node:http';
|
|
19
20
|
import { randomBytes, createHash, randomUUID } from 'node:crypto';
|
|
20
21
|
import {
|
|
22
|
+
clearTokensUnlocked,
|
|
21
23
|
loadTokens,
|
|
22
24
|
nativeCredentialBinding,
|
|
23
25
|
withAuthLock,
|
|
@@ -53,22 +55,27 @@ const FLOW_TTL_MS = 10 * 60_000;
|
|
|
53
55
|
interface PendingFlow {
|
|
54
56
|
state: string;
|
|
55
57
|
codeVerifier: string;
|
|
56
|
-
|
|
58
|
+
accountRef: string;
|
|
57
59
|
timer?: ReturnType<typeof setTimeout>;
|
|
58
60
|
result: ClaudeNativeAuthFlow;
|
|
59
61
|
completion?: Promise<{ ok: true; flow: ClaudeNativeAuthFlow }>;
|
|
60
62
|
}
|
|
61
|
-
|
|
63
|
+
const pendingFlows = new Map<string, PendingFlow>();
|
|
64
|
+
let callbackListener: Promise<Server | null> | undefined;
|
|
62
65
|
const flows = new Map<string, PendingFlow>();
|
|
63
66
|
|
|
64
67
|
function finishFlow(flow: PendingFlow, status: ClaudeNativeAuthFlow['status'], error?: string): void {
|
|
65
68
|
flow.result = { ...flow.result, status, ...(error ? { error } : {}) };
|
|
66
69
|
if (flow.timer) clearTimeout(flow.timer);
|
|
67
|
-
if (flow.
|
|
68
|
-
if (
|
|
70
|
+
if (pendingFlows.get(flow.accountRef) === flow) pendingFlows.delete(flow.accountRef);
|
|
71
|
+
if (pendingFlows.size === 0) {
|
|
72
|
+
const closing = callbackListener;
|
|
73
|
+
callbackListener = undefined;
|
|
74
|
+
void closing?.then(server => server?.close());
|
|
75
|
+
}
|
|
69
76
|
}
|
|
70
77
|
function currentFlow(flow: PendingFlow): boolean {
|
|
71
|
-
return
|
|
78
|
+
return pendingFlows.get(flow.accountRef) === flow && ['pending', 'exchanging'].includes(flow.result.status) && Date.now() < flow.result.expiresAt;
|
|
72
79
|
}
|
|
73
80
|
function sameBinding(a: ClaudeCredentialBinding, b: ClaudeCredentialBinding): boolean {
|
|
74
81
|
return a.source === b.source && a.storeId === b.storeId && a.revision === b.revision;
|
|
@@ -82,47 +89,55 @@ export interface BootstrapStartResult {
|
|
|
82
89
|
flow: ClaudeNativeAuthFlow;
|
|
83
90
|
}
|
|
84
91
|
|
|
85
|
-
//
|
|
86
|
-
// the
|
|
87
|
-
|
|
92
|
+
// The registered callback port is shared. The OAuth state identifies the
|
|
93
|
+
// flow, and the flow fixes its account before any credential exchange.
|
|
94
|
+
function listenForCallback(): Promise<Server | null> {
|
|
95
|
+
return callbackListener ??= new Promise(resolve => {
|
|
96
|
+
const server = createServer((req, res) => {
|
|
97
|
+
let url: URL;
|
|
98
|
+
try { url = new URL(req.url || '/', REDIRECT_URI); }
|
|
99
|
+
catch { res.writeHead(400, { 'Content-Type': 'text/plain' }); res.end('Invalid callback request.'); return; }
|
|
100
|
+
if (url.pathname !== CALLBACK_PATH) { res.writeHead(404); res.end('not found'); return; }
|
|
101
|
+
const flow = [...pendingFlows.values()].find(candidate => candidate.state === url.searchParams.get('state'));
|
|
102
|
+
if (!flow) { res.writeHead(400); res.end('Sign-in flow unavailable.'); return; }
|
|
103
|
+
void completeFlow(flow, url).then(() => {
|
|
104
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store' });
|
|
105
|
+
res.end('<!doctype html><meta charset="utf-8"><title>Arco Native sign-in</title><h1>Native sign-in completed.</h1><p>Return to Arco and review the originating workflow. No work was replayed.</p>');
|
|
106
|
+
}, () => { res.writeHead(400, { 'Content-Type': 'text/plain' }); res.end('Sign-in did not complete. Return to Arco to review this flow.'); });
|
|
107
|
+
});
|
|
108
|
+
server.once('error', () => resolve(null));
|
|
109
|
+
server.listen(CALLBACK_PORT, CALLBACK_HOST, () => resolve(server));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function startBootstrap(expectedBinding?: ClaudeCredentialBinding, workflowId?: string, requestedAccount?: string): Promise<BootstrapStartResult> {
|
|
114
|
+
const accountRef = await requireClaudeNativeAccount(requestedAccount);
|
|
88
115
|
return withAuthLock(async () => {
|
|
89
|
-
const binding = nativeCredentialBinding(await readTokensUnlocked());
|
|
116
|
+
const binding = nativeCredentialBinding(await readTokensUnlocked(accountRef), accountRef);
|
|
90
117
|
if (expectedBinding && !sameBinding(expectedBinding, binding)) throw new Error('Native credentials changed. Review sign-in status before starting again.');
|
|
91
|
-
|
|
118
|
+
const previous = pendingFlows.get(accountRef);
|
|
92
119
|
const verifier = randomBytes(32).toString('base64url');
|
|
93
120
|
const state = randomBytes(32).toString('base64url');
|
|
94
|
-
const flow: PendingFlow = { state, codeVerifier: verifier,
|
|
121
|
+
const flow: PendingFlow = { state, codeVerifier: verifier, accountRef, result: {
|
|
95
122
|
id: randomUUID(), status: 'pending', startedAt: Date.now(), expiresAt: Date.now() + FLOW_TTL_MS,
|
|
96
|
-
bindingBefore: binding, ...(workflowId ? { workflowId } : {}),
|
|
123
|
+
bindingBefore: binding, ...(workflowId ? { workflowId } : {}), ...(requestedAccount ? { accountRef } : {}),
|
|
97
124
|
} };
|
|
98
|
-
|
|
125
|
+
pendingFlows.set(accountRef, flow);
|
|
126
|
+
if (previous) finishFlow(previous, 'superseded');
|
|
99
127
|
flows.set(flow.result.id, flow);
|
|
100
|
-
while (flows.size > 32)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const server = createServer((req, res) => {
|
|
105
|
-
let url: URL;
|
|
106
|
-
try { url = new URL(req.url || '/', REDIRECT_URI); }
|
|
107
|
-
catch { res.writeHead(400, { 'Content-Type': 'text/plain' }); res.end('Invalid callback request.'); return; }
|
|
108
|
-
if (url.pathname !== CALLBACK_PATH) { res.writeHead(404); res.end('not found'); return; }
|
|
109
|
-
void completeFlow(flow, url).then(() => {
|
|
110
|
-
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store' });
|
|
111
|
-
res.end('<!doctype html><meta charset="utf-8"><title>Arco Native sign-in</title><h1>Native sign-in completed.</h1><p>Return to Arco and review the originating workflow. No work was replayed.</p>');
|
|
112
|
-
}, () => { res.writeHead(400, { 'Content-Type': 'text/plain' }); res.end('Sign-in did not complete. Return to Arco to review this flow.'); });
|
|
113
|
-
});
|
|
114
|
-
server.once('error', reject);
|
|
115
|
-
server.listen(CALLBACK_PORT, CALLBACK_HOST, () => resolve(server));
|
|
116
|
-
});
|
|
117
|
-
} catch {
|
|
118
|
-
manualReason = 'Local callback unavailable. Approve in the browser, then paste the redirected localhost URL.';
|
|
128
|
+
while (flows.size > 32) {
|
|
129
|
+
const finished = [...flows.values()].find(candidate => !currentFlow(candidate));
|
|
130
|
+
if (!finished) break;
|
|
131
|
+
flows.delete(finished.result.id);
|
|
119
132
|
}
|
|
133
|
+
const server = await listenForCallback();
|
|
134
|
+
const manualReason = server ? undefined : 'Local callback unavailable. Approve in the browser, then paste the redirected localhost URL.';
|
|
120
135
|
flow.timer = setTimeout(() => { void cancelBootstrap(flow.result.id, 'expired'); }, FLOW_TTL_MS);
|
|
121
136
|
flow.timer.unref?.();
|
|
122
137
|
const params = new URLSearchParams({ code: 'true', client_id: CLIENT_ID, response_type: 'code', redirect_uri: REDIRECT_URI,
|
|
123
138
|
scope: SCOPES, code_challenge: createHash('sha256').update(verifier).digest('base64url'), code_challenge_method: 'S256', state });
|
|
124
|
-
return { authorizationUrl: `${AUTHORIZE_URL}?${params}`, state, manualFallback: !
|
|
125
|
-
});
|
|
139
|
+
return { authorizationUrl: `${AUTHORIZE_URL}?${params}`, state, manualFallback: !server, manualReason, flow: { ...flow.result } };
|
|
140
|
+
}, accountRef);
|
|
126
141
|
}
|
|
127
142
|
|
|
128
143
|
export async function getBootstrapFlow(id: string): Promise<ClaudeNativeAuthFlow | null> {
|
|
@@ -133,16 +148,26 @@ export async function getBootstrapFlow(id: string): Promise<ClaudeNativeAuthFlow
|
|
|
133
148
|
}
|
|
134
149
|
|
|
135
150
|
export async function cancelBootstrap(id: string, reason: 'cancelled' | 'expired' = 'cancelled'): Promise<ClaudeNativeAuthFlow | null> {
|
|
151
|
+
const flow = flows.get(id);
|
|
152
|
+
if (!flow) return null;
|
|
136
153
|
return withAuthLock(async () => {
|
|
137
|
-
const flow = flows.get(id);
|
|
138
|
-
if (!flow) return null;
|
|
139
154
|
if (['pending', 'exchanging'].includes(flow.result.status)) finishFlow(flow, reason);
|
|
140
155
|
return { ...flow.result };
|
|
141
|
-
});
|
|
156
|
+
}, flow.accountRef);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export async function cancelActiveBootstrap(accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT): Promise<void> {
|
|
160
|
+
const flow = pendingFlows.get(accountRef);
|
|
161
|
+
if (flow) await cancelBootstrap(flow.result.id);
|
|
142
162
|
}
|
|
143
163
|
|
|
144
|
-
export async function
|
|
145
|
-
await withAuthLock(async () => {
|
|
164
|
+
export async function logout(accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT): Promise<void> {
|
|
165
|
+
await withAuthLock(async () => {
|
|
166
|
+
const flow = pendingFlows.get(accountRef);
|
|
167
|
+
if (flow) finishFlow(flow, 'cancelled');
|
|
168
|
+
await clearTokensUnlocked(accountRef);
|
|
169
|
+
clearClaudeAuthProblem(accountRef);
|
|
170
|
+
}, accountRef);
|
|
146
171
|
}
|
|
147
172
|
|
|
148
173
|
// Local callback and remote manual paste share the same validation, single
|
|
@@ -161,16 +186,17 @@ function completeFlow(flow: PendingFlow, url: URL): Promise<{ ok: true; flow: Cl
|
|
|
161
186
|
try {
|
|
162
187
|
const tokens = await exchangeCode(code, flow.state, flow.codeVerifier);
|
|
163
188
|
await withAuthLock(async () => {
|
|
189
|
+
await requireClaudeNativeAccount(flow.accountRef);
|
|
164
190
|
if (!currentFlow(flow)) throw new Error('Sign-in flow is no longer pending. Start again.');
|
|
165
|
-
if (!sameBinding(flow.result.bindingBefore, nativeCredentialBinding(await readTokensUnlocked()))) {
|
|
191
|
+
if (!sameBinding(flow.result.bindingBefore, nativeCredentialBinding(await readTokensUnlocked(flow.accountRef), flow.accountRef))) {
|
|
166
192
|
finishFlow(flow, 'superseded');
|
|
167
193
|
throw new Error('Native credentials changed during sign-in. Review the current credentials.');
|
|
168
194
|
}
|
|
169
|
-
await writeTokensUnlocked(tokens);
|
|
170
|
-
flow.result = { ...flow.result, binding: nativeCredentialBinding(tokens) };
|
|
171
|
-
clearClaudeAuthProblem();
|
|
195
|
+
await writeTokensUnlocked(tokens, flow.accountRef);
|
|
196
|
+
flow.result = { ...flow.result, binding: nativeCredentialBinding(tokens, flow.accountRef) };
|
|
197
|
+
clearClaudeAuthProblem(flow.accountRef);
|
|
172
198
|
finishFlow(flow, 'complete');
|
|
173
|
-
});
|
|
199
|
+
}, flow.accountRef);
|
|
174
200
|
return { ok: true as const, flow: { ...flow.result } };
|
|
175
201
|
} catch (err) {
|
|
176
202
|
if (currentFlow(flow)) finishFlow(flow, 'failed', 'Native sign-in failed. Start a new flow to try again.');
|
|
@@ -182,7 +208,7 @@ function completeFlow(flow: PendingFlow, url: URL): Promise<{ ok: true; flow: Cl
|
|
|
182
208
|
|
|
183
209
|
export async function completeBootstrap(rawUrl: string, flowId?: string): Promise<{ ok: true; flow: ClaudeNativeAuthFlow }> {
|
|
184
210
|
const url = new URL(rawUrl);
|
|
185
|
-
const flow = flowId ? flows.get(flowId) :
|
|
211
|
+
const flow = flowId ? flows.get(flowId) : pendingFlows.get(DEFAULT_CLAUDE_NATIVE_ACCOUNT);
|
|
186
212
|
if (!flow) throw new Error('no pending OAuth flow - start one first');
|
|
187
213
|
if (url.protocol !== 'http:' || !['localhost', '127.0.0.1'].includes(url.hostname) || url.port !== String(CALLBACK_PORT) || url.pathname !== CALLBACK_PATH) throw new Error('Expected the redirected localhost callback URL.');
|
|
188
214
|
return completeFlow(flow, url);
|
|
@@ -203,10 +229,7 @@ async function exchangeCode(code: string, state: string, codeVerifier: string):
|
|
|
203
229
|
code_verifier: codeVerifier,
|
|
204
230
|
}),
|
|
205
231
|
});
|
|
206
|
-
if (!res.ok) {
|
|
207
|
-
const txt = await res.text().catch(() => '');
|
|
208
|
-
throw new Error(`token exchange failed (${res.status}): ${txt.slice(0, 200)}`);
|
|
209
|
-
}
|
|
232
|
+
if (!res.ok) throw new Error(`Native token exchange failed (${res.status}).`);
|
|
210
233
|
const data = await res.json() as {
|
|
211
234
|
access_token: string;
|
|
212
235
|
refresh_token: string;
|
|
@@ -229,13 +252,14 @@ async function exchangeCode(code: string, state: string, codeVerifier: string):
|
|
|
229
252
|
|
|
230
253
|
// Refresh under the auth-file lock so two workers refreshing the same
|
|
231
254
|
// token don't race. Returns the (possibly-new) tokens.
|
|
232
|
-
export async function refreshTokens(
|
|
255
|
+
export async function refreshTokens(_current: ClaudeNativeTokens, accountRef?: string): Promise<ClaudeNativeTokens> {
|
|
233
256
|
return withAuthLock(async () => {
|
|
234
257
|
// Re-read inside the lock — another worker may have already refreshed.
|
|
235
|
-
const fresh = await readTokensUnlocked();
|
|
236
|
-
if (fresh
|
|
237
|
-
|
|
238
|
-
|
|
258
|
+
const fresh = await readTokensUnlocked(accountRef);
|
|
259
|
+
if (!fresh) throw new ClaudeNativeNoAuthError();
|
|
260
|
+
if (fresh.expiresAt > Date.now() + REFRESH_LEAD_MS) return fresh;
|
|
261
|
+
return refreshUnlocked(fresh, accountRef);
|
|
262
|
+
}, accountRef);
|
|
239
263
|
}
|
|
240
264
|
|
|
241
265
|
// A1 (docs/REMOTE_MANAGEMENT.md) - refresh IGNORING the local
|
|
@@ -246,13 +270,13 @@ export async function refreshTokens(current: ClaudeNativeTokens): Promise<Claude
|
|
|
246
270
|
// `staleObtainedAt` guards the concurrent case: if another worker already
|
|
247
271
|
// rotated the on-disk tokens since the 401'ing client was built, return those
|
|
248
272
|
// instead of burning a second refresh against a just-rotated chain.
|
|
249
|
-
export async function forceRefreshTokens(staleObtainedAt: number): Promise<ClaudeNativeTokens> {
|
|
273
|
+
export async function forceRefreshTokens(staleObtainedAt: number, accountRef?: string): Promise<ClaudeNativeTokens> {
|
|
250
274
|
return withAuthLock(async () => {
|
|
251
|
-
const fresh = await readTokensUnlocked();
|
|
275
|
+
const fresh = await readTokensUnlocked(accountRef);
|
|
252
276
|
if (!fresh) throw new ClaudeNativeNoAuthError();
|
|
253
277
|
if (fresh.obtainedAt > staleObtainedAt) return fresh;
|
|
254
|
-
return refreshUnlocked(fresh);
|
|
255
|
-
});
|
|
278
|
+
return refreshUnlocked(fresh, accountRef);
|
|
279
|
+
}, accountRef);
|
|
256
280
|
}
|
|
257
281
|
|
|
258
282
|
// The actual refresh POST + persist. Caller MUST hold the auth-file lock.
|
|
@@ -260,7 +284,7 @@ export async function forceRefreshTokens(staleObtainedAt: number): Promise<Claud
|
|
|
260
284
|
// "access token revoked early, chain still good" (no line ever
|
|
261
285
|
// appears; forced refresh recovers silently) from "refresh chain dead, re-auth
|
|
262
286
|
// genuinely required" (§10.2 diagnostics).
|
|
263
|
-
async function refreshUnlocked(seed: ClaudeNativeTokens): Promise<ClaudeNativeTokens> {
|
|
287
|
+
async function refreshUnlocked(seed: ClaudeNativeTokens, accountRef?: string): Promise<ClaudeNativeTokens> {
|
|
264
288
|
const res = await fetch(TOKEN_URL, {
|
|
265
289
|
method: 'POST',
|
|
266
290
|
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
@@ -271,9 +295,8 @@ async function refreshUnlocked(seed: ClaudeNativeTokens): Promise<ClaudeNativeTo
|
|
|
271
295
|
}),
|
|
272
296
|
});
|
|
273
297
|
if (!res.ok) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const err = new Error(`refresh failed (${res.status}): ${txt.slice(0, 200)}`);
|
|
298
|
+
console.error(`[claude-native] refresh rejected (${res.status})`);
|
|
299
|
+
const err = new Error(`Native refresh failed (${res.status})`);
|
|
277
300
|
(err as Error & { httpStatus?: number }).httpStatus = res.status;
|
|
278
301
|
throw err;
|
|
279
302
|
}
|
|
@@ -293,8 +316,8 @@ async function refreshUnlocked(seed: ClaudeNativeTokens): Promise<ClaudeNativeTo
|
|
|
293
316
|
scope: data.scope ?? seed.scope,
|
|
294
317
|
obtainedAt: now,
|
|
295
318
|
};
|
|
296
|
-
await writeTokensUnlocked(next);
|
|
297
|
-
clearClaudeAuthProblem(); // a fresh grant is proof the chain works again
|
|
319
|
+
await writeTokensUnlocked(next, accountRef);
|
|
320
|
+
clearClaudeAuthProblem(accountRef); // a fresh grant is proof the chain works again
|
|
298
321
|
return next;
|
|
299
322
|
}
|
|
300
323
|
|
|
@@ -307,7 +330,7 @@ async function refreshUnlocked(seed: ClaudeNativeTokens): Promise<ClaudeNativeTo
|
|
|
307
330
|
// clears it until the next failed turn re-reports, which is the honest state.
|
|
308
331
|
// The transition into "problem" emits ONE auth-expired workbench notice (J1 →
|
|
309
332
|
// ntfy), so the phone learns without polling.
|
|
310
|
-
|
|
333
|
+
const claudeAuthProblems = new Map<string, { since: number; detail: string }>();
|
|
311
334
|
let authProblemNotify: ((detail: string) => void) | null = null;
|
|
312
335
|
|
|
313
336
|
// Wired by the server bootstrap (initHubLink) to the J1 emit() — injected so
|
|
@@ -316,22 +339,22 @@ export function setClaudeAuthProblemNotifier(fn: (detail: string) => void): void
|
|
|
316
339
|
authProblemNotify = fn;
|
|
317
340
|
}
|
|
318
341
|
|
|
319
|
-
export function markClaudeAuthProblem(detail: string): void {
|
|
320
|
-
if (
|
|
321
|
-
|
|
342
|
+
export function markClaudeAuthProblem(detail: string, accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT): void {
|
|
343
|
+
if (claudeAuthProblems.has(accountRef)) return; // already alerted — don't re-notify per turn
|
|
344
|
+
claudeAuthProblems.set(accountRef, { since: Date.now(), detail });
|
|
322
345
|
try {
|
|
323
|
-
authProblemNotify?.(detail);
|
|
346
|
+
if (accountRef === DEFAULT_CLAUDE_NATIVE_ACCOUNT) authProblemNotify?.(detail);
|
|
324
347
|
} catch {
|
|
325
348
|
/* notifier must never break the auth path */
|
|
326
349
|
}
|
|
327
350
|
}
|
|
328
351
|
|
|
329
|
-
export function clearClaudeAuthProblem(): void {
|
|
330
|
-
|
|
352
|
+
export function clearClaudeAuthProblem(accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT): void {
|
|
353
|
+
claudeAuthProblems.delete(accountRef);
|
|
331
354
|
}
|
|
332
355
|
|
|
333
|
-
export function getClaudeAuthProblem(): { since: number; detail: string } | null {
|
|
334
|
-
return
|
|
356
|
+
export function getClaudeAuthProblem(accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT): { since: number; detail: string } | null {
|
|
357
|
+
return claudeAuthProblems.get(accountRef) ?? null;
|
|
335
358
|
}
|
|
336
359
|
|
|
337
360
|
// Thrown when ~/.arco/auth.json has no claude.native key. The worker
|
|
@@ -348,11 +371,12 @@ export class ClaudeNativeNoAuthError extends Error {
|
|
|
348
371
|
// Public wrapper — load tokens, refresh if expired, return the live set.
|
|
349
372
|
// Throws ClaudeNativeNoAuthError on no-auth or a generic Error on refresh
|
|
350
373
|
// failure (caller surfaces [AUTH:claude]).
|
|
351
|
-
export async function ensureLiveTokens(): Promise<ClaudeNativeTokens> {
|
|
352
|
-
const
|
|
374
|
+
export async function ensureLiveTokens(requestedAccount?: string): Promise<ClaudeNativeTokens> {
|
|
375
|
+
const accountRef = await requireClaudeNativeAccount(requestedAccount);
|
|
376
|
+
const tokens = await loadTokens(accountRef);
|
|
353
377
|
if (!tokens) throw new ClaudeNativeNoAuthError();
|
|
354
378
|
if (tokens.expiresAt > Date.now() + REFRESH_LEAD_MS) return tokens;
|
|
355
|
-
return refreshTokens(tokens);
|
|
379
|
+
return refreshTokens(tokens, accountRef);
|
|
356
380
|
}
|
|
357
381
|
|
|
358
382
|
export const REFRESH_LEAD_MS_EXPORT = REFRESH_LEAD_MS;
|