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
|
@@ -11,13 +11,18 @@
|
|
|
11
11
|
//
|
|
12
12
|
// Refresh cadence: 1 hour. New models surface within that window
|
|
13
13
|
// without an Arco restart.
|
|
14
|
+
import { loadTokens, nativeCredentialBinding } from './auth.js';
|
|
15
|
+
import { requireClaudeNativeAccount } from '../../providerAccounts.js';
|
|
14
16
|
import { ensureLiveTokens } from './oauth.js';
|
|
15
17
|
import { CLAUDE_CLI_USER_AGENT } from './wireFingerprint.js';
|
|
16
|
-
import { claudeAliasFamily, CLAUDE_ALIAS_FALLBACK, distillCatalogModel, } from '@arco/shared';
|
|
18
|
+
import { DEFAULT_CLAUDE_NATIVE_ACCOUNT, claudeAliasFamily, CLAUDE_ALIAS_FALLBACK, distillCatalogModel, } from '@arco/shared';
|
|
17
19
|
const REFRESH_INTERVAL_MS = 60 * 60 * 1000;
|
|
18
20
|
const REQUEST_TIMEOUT_MS = 15_000;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
const catalogs = new Map();
|
|
22
|
+
const cached = (accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT) => catalogs.get(accountRef)?.snapshot;
|
|
23
|
+
export function forgetCatalog(accountRef) {
|
|
24
|
+
catalogs.delete(accountRef);
|
|
25
|
+
}
|
|
21
26
|
// Phase 7c-followup — synchronous catalog-capability lookup for the Native
|
|
22
27
|
// worker's per-request beta-header construction. Returns `null` when the
|
|
23
28
|
// model isn't in the cached catalog (cold-start, fetch failure, or a
|
|
@@ -25,10 +30,8 @@ let inFlight = null;
|
|
|
25
30
|
// Worker treats `null` conservatively: skip context-management betas
|
|
26
31
|
// rather than risk a 400. The catalog refresh is async and hourly; the
|
|
27
32
|
// worker reads the in-memory cache only.
|
|
28
|
-
export function getCachedModelCapabilities(modelId) {
|
|
29
|
-
|
|
30
|
-
return null;
|
|
31
|
-
const m = cache.models.find((x) => x.id === modelId);
|
|
33
|
+
export function getCachedModelCapabilities(modelId, accountRef) {
|
|
34
|
+
const m = cached(accountRef)?.models.find((x) => x.id === modelId);
|
|
32
35
|
if (!m)
|
|
33
36
|
return null;
|
|
34
37
|
return {
|
|
@@ -38,13 +41,13 @@ export function getCachedModelCapabilities(modelId) {
|
|
|
38
41
|
};
|
|
39
42
|
}
|
|
40
43
|
// The picker uses the same cached model efforts when a catalog is available.
|
|
41
|
-
export function getCachedClaudeModelEfforts(modelId) {
|
|
42
|
-
return
|
|
44
|
+
export function getCachedClaudeModelEfforts(modelId, accountRef) {
|
|
45
|
+
return cached(accountRef)?.models.find((model) => model.id === modelId)?.supportedEfforts;
|
|
43
46
|
}
|
|
44
47
|
// True once a non-empty catalog has been fetched in this process. Callers use
|
|
45
48
|
// it to decide whether an alias resolution is catalog-backed or a static guess.
|
|
46
|
-
export function hasCatalogCache() {
|
|
47
|
-
return
|
|
49
|
+
export function hasCatalogCache(accountRef) {
|
|
50
|
+
return (cached(accountRef)?.models.length ?? 0) > 0;
|
|
48
51
|
}
|
|
49
52
|
// resolve a family alias ('opus' / 'opus[1m]' / 'sonnet' /
|
|
50
53
|
// 'haiku') to the newest concrete id in that family. The Messages API has no
|
|
@@ -54,11 +57,11 @@ export function hasCatalogCache() {
|
|
|
54
57
|
//
|
|
55
58
|
// Concrete ids pass through untouched. Falls back to CLAUDE_ALIAS_FALLBACK
|
|
56
59
|
// when the catalog is cold — a stale-but-real id beats a guaranteed 404.
|
|
57
|
-
export function resolveClaudeAliasFromCatalog(modelId) {
|
|
60
|
+
export function resolveClaudeAliasFromCatalog(modelId, accountRef) {
|
|
58
61
|
const family = claudeAliasFamily(modelId);
|
|
59
62
|
if (!family)
|
|
60
63
|
return modelId;
|
|
61
|
-
const inFamily = (
|
|
64
|
+
const inFamily = (cached(accountRef)?.models ?? []).filter((m) => m.id.includes(family));
|
|
62
65
|
if (inFamily.length === 0)
|
|
63
66
|
return CLAUDE_ALIAS_FALLBACK[family];
|
|
64
67
|
// Newest by created_at, not catalog order — /v1/models happens to sort
|
|
@@ -69,33 +72,43 @@ export function resolveClaudeAliasFromCatalog(modelId) {
|
|
|
69
72
|
// Public accessor. Returns the cached snapshot; refreshes if older than
|
|
70
73
|
// REFRESH_INTERVAL_MS, in-flight request, or never fetched. Failures
|
|
71
74
|
// degrade to the last good cache rather than throwing.
|
|
72
|
-
export async function getCatalog(force = false) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
export async function getCatalog(force = false, requestedAccount) {
|
|
76
|
+
const accountRef = await requireClaudeNativeAccount(requestedAccount);
|
|
77
|
+
const empty = { fetchedAt: Date.now(), models: [], fresh: false };
|
|
78
|
+
const tokens = await loadTokens(accountRef);
|
|
79
|
+
if (!tokens) {
|
|
80
|
+
forgetCatalog(accountRef);
|
|
81
|
+
return empty;
|
|
82
|
+
}
|
|
83
|
+
const revision = nativeCredentialBinding(tokens, accountRef).revision;
|
|
84
|
+
let entry = catalogs.get(accountRef);
|
|
85
|
+
if (!entry || entry.revision !== revision) {
|
|
86
|
+
entry = { revision };
|
|
87
|
+
catalogs.set(accountRef, entry);
|
|
88
|
+
}
|
|
89
|
+
if (!force && entry.snapshot && Date.now() - entry.snapshot.fetchedAt < REFRESH_INTERVAL_MS)
|
|
90
|
+
return entry.snapshot;
|
|
91
|
+
if (entry.inFlight)
|
|
92
|
+
return entry.inFlight;
|
|
93
|
+
const current = entry;
|
|
94
|
+
current.inFlight = (async () => {
|
|
79
95
|
try {
|
|
80
|
-
const
|
|
81
|
-
|
|
96
|
+
const live = await ensureLiveTokens(accountRef);
|
|
97
|
+
const fresh = await fetchCatalog(live);
|
|
98
|
+
const after = await loadTokens(accountRef);
|
|
99
|
+
if (catalogs.get(accountRef) !== current || nativeCredentialBinding(live, accountRef).revision !== nativeCredentialBinding(after, accountRef).revision)
|
|
100
|
+
return empty;
|
|
101
|
+
current.revision = nativeCredentialBinding(live, accountRef).revision;
|
|
102
|
+
current.snapshot = fresh;
|
|
82
103
|
return fresh;
|
|
83
104
|
}
|
|
84
|
-
catch
|
|
85
|
-
|
|
86
|
-
console.warn('[claude-native:catalog] refresh failed; serving stale cache:', err instanceof Error ? err.message : err);
|
|
87
|
-
return { ...cache, fresh: false };
|
|
88
|
-
}
|
|
89
|
-
// No cache to fall back on. Return an empty snapshot; the UI uses
|
|
90
|
-
// the compile-time CLAUDE_MODELS list as a baseline.
|
|
91
|
-
console.warn('[claude-native:catalog] no auth and no cache:', err instanceof Error ? err.message : err);
|
|
92
|
-
return { fetchedAt: now, models: [], fresh: false };
|
|
105
|
+
catch {
|
|
106
|
+
return catalogs.get(accountRef) === current && current.snapshot ? { ...current.snapshot, fresh: false } : empty;
|
|
93
107
|
}
|
|
94
|
-
})().finally(() => { inFlight =
|
|
95
|
-
return inFlight;
|
|
108
|
+
})().finally(() => { current.inFlight = undefined; });
|
|
109
|
+
return current.inFlight;
|
|
96
110
|
}
|
|
97
|
-
async function fetchCatalog() {
|
|
98
|
-
const tokens = await ensureLiveTokens();
|
|
111
|
+
async function fetchCatalog(tokens) {
|
|
99
112
|
const controller = new AbortController();
|
|
100
113
|
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
101
114
|
try {
|
|
@@ -111,10 +124,8 @@ async function fetchCatalog() {
|
|
|
111
124
|
},
|
|
112
125
|
signal: controller.signal,
|
|
113
126
|
});
|
|
114
|
-
if (!resp.ok)
|
|
115
|
-
|
|
116
|
-
throw new Error(`/v1/models ${resp.status}: ${text.slice(0, 200)}`);
|
|
117
|
-
}
|
|
127
|
+
if (!resp.ok)
|
|
128
|
+
throw new Error(`/v1/models ${resp.status}`);
|
|
118
129
|
const body = await resp.json();
|
|
119
130
|
const raw = Array.isArray(body.data) ? body.data : [];
|
|
120
131
|
// Distil into the picker shape (camelCase displayName, supportedEfforts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ClaudeCredentialBinding, type ClaudeNativeAuthFlow } from '@arco/shared';
|
|
2
2
|
import { type ClaudeNativeTokens } from './auth.js';
|
|
3
3
|
export interface BootstrapStartResult {
|
|
4
4
|
authorizationUrl: string;
|
|
@@ -7,20 +7,21 @@ export interface BootstrapStartResult {
|
|
|
7
7
|
manualReason?: string;
|
|
8
8
|
flow: ClaudeNativeAuthFlow;
|
|
9
9
|
}
|
|
10
|
-
export declare function startBootstrap(expectedBinding?: ClaudeCredentialBinding, workflowId?: string): Promise<BootstrapStartResult>;
|
|
10
|
+
export declare function startBootstrap(expectedBinding?: ClaudeCredentialBinding, workflowId?: string, requestedAccount?: string): Promise<BootstrapStartResult>;
|
|
11
11
|
export declare function getBootstrapFlow(id: string): Promise<ClaudeNativeAuthFlow | null>;
|
|
12
12
|
export declare function cancelBootstrap(id: string, reason?: 'cancelled' | 'expired'): Promise<ClaudeNativeAuthFlow | null>;
|
|
13
|
-
export declare function cancelActiveBootstrap(): Promise<void>;
|
|
13
|
+
export declare function cancelActiveBootstrap(accountRef?: string): Promise<void>;
|
|
14
|
+
export declare function logout(accountRef?: string): Promise<void>;
|
|
14
15
|
export declare function completeBootstrap(rawUrl: string, flowId?: string): Promise<{
|
|
15
16
|
ok: true;
|
|
16
17
|
flow: ClaudeNativeAuthFlow;
|
|
17
18
|
}>;
|
|
18
|
-
export declare function refreshTokens(
|
|
19
|
-
export declare function forceRefreshTokens(staleObtainedAt: number): Promise<ClaudeNativeTokens>;
|
|
19
|
+
export declare function refreshTokens(_current: ClaudeNativeTokens, accountRef?: string): Promise<ClaudeNativeTokens>;
|
|
20
|
+
export declare function forceRefreshTokens(staleObtainedAt: number, accountRef?: string): Promise<ClaudeNativeTokens>;
|
|
20
21
|
export declare function setClaudeAuthProblemNotifier(fn: (detail: string) => void): void;
|
|
21
|
-
export declare function markClaudeAuthProblem(detail: string): void;
|
|
22
|
-
export declare function clearClaudeAuthProblem(): void;
|
|
23
|
-
export declare function getClaudeAuthProblem(): {
|
|
22
|
+
export declare function markClaudeAuthProblem(detail: string, accountRef?: string): void;
|
|
23
|
+
export declare function clearClaudeAuthProblem(accountRef?: string): void;
|
|
24
|
+
export declare function getClaudeAuthProblem(accountRef?: string): {
|
|
24
25
|
since: number;
|
|
25
26
|
detail: string;
|
|
26
27
|
} | null;
|
|
@@ -28,5 +29,5 @@ export declare class ClaudeNativeNoAuthError extends Error {
|
|
|
28
29
|
readonly code: "NO_AUTH";
|
|
29
30
|
constructor();
|
|
30
31
|
}
|
|
31
|
-
export declare function ensureLiveTokens(): Promise<ClaudeNativeTokens>;
|
|
32
|
+
export declare function ensureLiveTokens(requestedAccount?: string): Promise<ClaudeNativeTokens>;
|
|
32
33
|
export declare const REFRESH_LEAD_MS_EXPORT = 30000;
|
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
// in use, sandbox refusal, headless / SSH session), we surface the
|
|
14
14
|
// authorize URL and accept a `{ url }` paste body to extract `code` +
|
|
15
15
|
// `state`.
|
|
16
|
+
import { DEFAULT_CLAUDE_NATIVE_ACCOUNT } from '@arco/shared';
|
|
17
|
+
import { requireClaudeNativeAccount } from '../../providerAccounts.js';
|
|
16
18
|
import { createServer } from 'node:http';
|
|
17
19
|
import { randomBytes, createHash, randomUUID } from 'node:crypto';
|
|
18
|
-
import { loadTokens, nativeCredentialBinding, withAuthLock, writeTokensUnlocked, readTokensUnlocked, } from './auth.js';
|
|
20
|
+
import { clearTokensUnlocked, loadTokens, nativeCredentialBinding, withAuthLock, writeTokensUnlocked, readTokensUnlocked, } from './auth.js';
|
|
19
21
|
// `9d1c250a-e61b-44d9-88ed-5944d1962f5e` (Pi-derived) — base64-encoded.
|
|
20
22
|
const CLIENT_ID_B64 = 'OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl';
|
|
21
23
|
const CLIENT_ID = Buffer.from(CLIENT_ID_B64, 'base64').toString('utf8');
|
|
@@ -37,82 +39,92 @@ const SCOPES = [
|
|
|
37
39
|
// boundary. 30s mirrors the plan-doc value.
|
|
38
40
|
const REFRESH_LEAD_MS = 30_000;
|
|
39
41
|
const FLOW_TTL_MS = 10 * 60_000;
|
|
40
|
-
|
|
42
|
+
const pendingFlows = new Map();
|
|
43
|
+
let callbackListener;
|
|
41
44
|
const flows = new Map();
|
|
42
45
|
function finishFlow(flow, status, error) {
|
|
43
46
|
flow.result = { ...flow.result, status, ...(error ? { error } : {}) };
|
|
44
47
|
if (flow.timer)
|
|
45
48
|
clearTimeout(flow.timer);
|
|
46
|
-
if (flow.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (pendingFlows.get(flow.accountRef) === flow)
|
|
50
|
+
pendingFlows.delete(flow.accountRef);
|
|
51
|
+
if (pendingFlows.size === 0) {
|
|
52
|
+
const closing = callbackListener;
|
|
53
|
+
callbackListener = undefined;
|
|
54
|
+
void closing?.then(server => server?.close());
|
|
51
55
|
}
|
|
52
|
-
if (pendingFlow === flow)
|
|
53
|
-
pendingFlow = null;
|
|
54
56
|
}
|
|
55
57
|
function currentFlow(flow) {
|
|
56
|
-
return
|
|
58
|
+
return pendingFlows.get(flow.accountRef) === flow && ['pending', 'exchanging'].includes(flow.result.status) && Date.now() < flow.result.expiresAt;
|
|
57
59
|
}
|
|
58
60
|
function sameBinding(a, b) {
|
|
59
61
|
return a.source === b.source && a.storeId === b.storeId && a.revision === b.revision;
|
|
60
62
|
}
|
|
61
|
-
//
|
|
62
|
-
// the
|
|
63
|
-
|
|
63
|
+
// The registered callback port is shared. The OAuth state identifies the
|
|
64
|
+
// flow, and the flow fixes its account before any credential exchange.
|
|
65
|
+
function listenForCallback() {
|
|
66
|
+
return callbackListener ??= new Promise(resolve => {
|
|
67
|
+
const server = createServer((req, res) => {
|
|
68
|
+
let url;
|
|
69
|
+
try {
|
|
70
|
+
url = new URL(req.url || '/', REDIRECT_URI);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
res.writeHead(400, { 'Content-Type': 'text/plain' });
|
|
74
|
+
res.end('Invalid callback request.');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (url.pathname !== CALLBACK_PATH) {
|
|
78
|
+
res.writeHead(404);
|
|
79
|
+
res.end('not found');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const flow = [...pendingFlows.values()].find(candidate => candidate.state === url.searchParams.get('state'));
|
|
83
|
+
if (!flow) {
|
|
84
|
+
res.writeHead(400);
|
|
85
|
+
res.end('Sign-in flow unavailable.');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
void completeFlow(flow, url).then(() => {
|
|
89
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store' });
|
|
90
|
+
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>');
|
|
91
|
+
}, () => { res.writeHead(400, { 'Content-Type': 'text/plain' }); res.end('Sign-in did not complete. Return to Arco to review this flow.'); });
|
|
92
|
+
});
|
|
93
|
+
server.once('error', () => resolve(null));
|
|
94
|
+
server.listen(CALLBACK_PORT, CALLBACK_HOST, () => resolve(server));
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
export async function startBootstrap(expectedBinding, workflowId, requestedAccount) {
|
|
98
|
+
const accountRef = await requireClaudeNativeAccount(requestedAccount);
|
|
64
99
|
return withAuthLock(async () => {
|
|
65
|
-
const binding = nativeCredentialBinding(await readTokensUnlocked());
|
|
100
|
+
const binding = nativeCredentialBinding(await readTokensUnlocked(accountRef), accountRef);
|
|
66
101
|
if (expectedBinding && !sameBinding(expectedBinding, binding))
|
|
67
102
|
throw new Error('Native credentials changed. Review sign-in status before starting again.');
|
|
68
|
-
|
|
69
|
-
finishFlow(pendingFlow, 'superseded');
|
|
103
|
+
const previous = pendingFlows.get(accountRef);
|
|
70
104
|
const verifier = randomBytes(32).toString('base64url');
|
|
71
105
|
const state = randomBytes(32).toString('base64url');
|
|
72
|
-
const flow = { state, codeVerifier: verifier,
|
|
106
|
+
const flow = { state, codeVerifier: verifier, accountRef, result: {
|
|
73
107
|
id: randomUUID(), status: 'pending', startedAt: Date.now(), expiresAt: Date.now() + FLOW_TTL_MS,
|
|
74
|
-
bindingBefore: binding, ...(workflowId ? { workflowId } : {}),
|
|
108
|
+
bindingBefore: binding, ...(workflowId ? { workflowId } : {}), ...(requestedAccount ? { accountRef } : {}),
|
|
75
109
|
} };
|
|
76
|
-
|
|
110
|
+
pendingFlows.set(accountRef, flow);
|
|
111
|
+
if (previous)
|
|
112
|
+
finishFlow(previous, 'superseded');
|
|
77
113
|
flows.set(flow.result.id, flow);
|
|
78
|
-
while (flows.size > 32)
|
|
79
|
-
flows.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const server = createServer((req, res) => {
|
|
84
|
-
let url;
|
|
85
|
-
try {
|
|
86
|
-
url = new URL(req.url || '/', REDIRECT_URI);
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
res.writeHead(400, { 'Content-Type': 'text/plain' });
|
|
90
|
-
res.end('Invalid callback request.');
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (url.pathname !== CALLBACK_PATH) {
|
|
94
|
-
res.writeHead(404);
|
|
95
|
-
res.end('not found');
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
void completeFlow(flow, url).then(() => {
|
|
99
|
-
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store' });
|
|
100
|
-
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>');
|
|
101
|
-
}, () => { res.writeHead(400, { 'Content-Type': 'text/plain' }); res.end('Sign-in did not complete. Return to Arco to review this flow.'); });
|
|
102
|
-
});
|
|
103
|
-
server.once('error', reject);
|
|
104
|
-
server.listen(CALLBACK_PORT, CALLBACK_HOST, () => resolve(server));
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
manualReason = 'Local callback unavailable. Approve in the browser, then paste the redirected localhost URL.';
|
|
114
|
+
while (flows.size > 32) {
|
|
115
|
+
const finished = [...flows.values()].find(candidate => !currentFlow(candidate));
|
|
116
|
+
if (!finished)
|
|
117
|
+
break;
|
|
118
|
+
flows.delete(finished.result.id);
|
|
109
119
|
}
|
|
120
|
+
const server = await listenForCallback();
|
|
121
|
+
const manualReason = server ? undefined : 'Local callback unavailable. Approve in the browser, then paste the redirected localhost URL.';
|
|
110
122
|
flow.timer = setTimeout(() => { void cancelBootstrap(flow.result.id, 'expired'); }, FLOW_TTL_MS);
|
|
111
123
|
flow.timer.unref?.();
|
|
112
124
|
const params = new URLSearchParams({ code: 'true', client_id: CLIENT_ID, response_type: 'code', redirect_uri: REDIRECT_URI,
|
|
113
125
|
scope: SCOPES, code_challenge: createHash('sha256').update(verifier).digest('base64url'), code_challenge_method: 'S256', state });
|
|
114
|
-
return { authorizationUrl: `${AUTHORIZE_URL}?${params}`, state, manualFallback: !
|
|
115
|
-
});
|
|
126
|
+
return { authorizationUrl: `${AUTHORIZE_URL}?${params}`, state, manualFallback: !server, manualReason, flow: { ...flow.result } };
|
|
127
|
+
}, accountRef);
|
|
116
128
|
}
|
|
117
129
|
export async function getBootstrapFlow(id) {
|
|
118
130
|
const flow = flows.get(id);
|
|
@@ -123,18 +135,28 @@ export async function getBootstrapFlow(id) {
|
|
|
123
135
|
return { ...flow.result };
|
|
124
136
|
}
|
|
125
137
|
export async function cancelBootstrap(id, reason = 'cancelled') {
|
|
138
|
+
const flow = flows.get(id);
|
|
139
|
+
if (!flow)
|
|
140
|
+
return null;
|
|
126
141
|
return withAuthLock(async () => {
|
|
127
|
-
const flow = flows.get(id);
|
|
128
|
-
if (!flow)
|
|
129
|
-
return null;
|
|
130
142
|
if (['pending', 'exchanging'].includes(flow.result.status))
|
|
131
143
|
finishFlow(flow, reason);
|
|
132
144
|
return { ...flow.result };
|
|
133
|
-
});
|
|
145
|
+
}, flow.accountRef);
|
|
146
|
+
}
|
|
147
|
+
export async function cancelActiveBootstrap(accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT) {
|
|
148
|
+
const flow = pendingFlows.get(accountRef);
|
|
149
|
+
if (flow)
|
|
150
|
+
await cancelBootstrap(flow.result.id);
|
|
134
151
|
}
|
|
135
|
-
export async function
|
|
136
|
-
await withAuthLock(async () => {
|
|
137
|
-
|
|
152
|
+
export async function logout(accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT) {
|
|
153
|
+
await withAuthLock(async () => {
|
|
154
|
+
const flow = pendingFlows.get(accountRef);
|
|
155
|
+
if (flow)
|
|
156
|
+
finishFlow(flow, 'cancelled');
|
|
157
|
+
await clearTokensUnlocked(accountRef);
|
|
158
|
+
clearClaudeAuthProblem(accountRef);
|
|
159
|
+
}, accountRef);
|
|
138
160
|
}
|
|
139
161
|
// Local callback and remote manual paste share the same validation, single
|
|
140
162
|
// exchange and guarded commit. A superseded response cannot replace tokens.
|
|
@@ -156,17 +178,18 @@ function completeFlow(flow, url) {
|
|
|
156
178
|
try {
|
|
157
179
|
const tokens = await exchangeCode(code, flow.state, flow.codeVerifier);
|
|
158
180
|
await withAuthLock(async () => {
|
|
181
|
+
await requireClaudeNativeAccount(flow.accountRef);
|
|
159
182
|
if (!currentFlow(flow))
|
|
160
183
|
throw new Error('Sign-in flow is no longer pending. Start again.');
|
|
161
|
-
if (!sameBinding(flow.result.bindingBefore, nativeCredentialBinding(await readTokensUnlocked()))) {
|
|
184
|
+
if (!sameBinding(flow.result.bindingBefore, nativeCredentialBinding(await readTokensUnlocked(flow.accountRef), flow.accountRef))) {
|
|
162
185
|
finishFlow(flow, 'superseded');
|
|
163
186
|
throw new Error('Native credentials changed during sign-in. Review the current credentials.');
|
|
164
187
|
}
|
|
165
|
-
await writeTokensUnlocked(tokens);
|
|
166
|
-
flow.result = { ...flow.result, binding: nativeCredentialBinding(tokens) };
|
|
167
|
-
clearClaudeAuthProblem();
|
|
188
|
+
await writeTokensUnlocked(tokens, flow.accountRef);
|
|
189
|
+
flow.result = { ...flow.result, binding: nativeCredentialBinding(tokens, flow.accountRef) };
|
|
190
|
+
clearClaudeAuthProblem(flow.accountRef);
|
|
168
191
|
finishFlow(flow, 'complete');
|
|
169
|
-
});
|
|
192
|
+
}, flow.accountRef);
|
|
170
193
|
return { ok: true, flow: { ...flow.result } };
|
|
171
194
|
}
|
|
172
195
|
catch (err) {
|
|
@@ -179,7 +202,7 @@ function completeFlow(flow, url) {
|
|
|
179
202
|
}
|
|
180
203
|
export async function completeBootstrap(rawUrl, flowId) {
|
|
181
204
|
const url = new URL(rawUrl);
|
|
182
|
-
const flow = flowId ? flows.get(flowId) :
|
|
205
|
+
const flow = flowId ? flows.get(flowId) : pendingFlows.get(DEFAULT_CLAUDE_NATIVE_ACCOUNT);
|
|
183
206
|
if (!flow)
|
|
184
207
|
throw new Error('no pending OAuth flow - start one first');
|
|
185
208
|
if (url.protocol !== 'http:' || !['localhost', '127.0.0.1'].includes(url.hostname) || url.port !== String(CALLBACK_PORT) || url.pathname !== CALLBACK_PATH)
|
|
@@ -201,10 +224,8 @@ async function exchangeCode(code, state, codeVerifier) {
|
|
|
201
224
|
code_verifier: codeVerifier,
|
|
202
225
|
}),
|
|
203
226
|
});
|
|
204
|
-
if (!res.ok)
|
|
205
|
-
|
|
206
|
-
throw new Error(`token exchange failed (${res.status}): ${txt.slice(0, 200)}`);
|
|
207
|
-
}
|
|
227
|
+
if (!res.ok)
|
|
228
|
+
throw new Error(`Native token exchange failed (${res.status}).`);
|
|
208
229
|
const data = await res.json();
|
|
209
230
|
if (typeof data.access_token !== 'string' || !data.access_token || typeof data.refresh_token !== 'string' || !data.refresh_token
|
|
210
231
|
|| !Number.isFinite(data.expires_in) || data.expires_in <= 0)
|
|
@@ -221,14 +242,16 @@ async function exchangeCode(code, state, codeVerifier) {
|
|
|
221
242
|
}
|
|
222
243
|
// Refresh under the auth-file lock so two workers refreshing the same
|
|
223
244
|
// token don't race. Returns the (possibly-new) tokens.
|
|
224
|
-
export async function refreshTokens(
|
|
245
|
+
export async function refreshTokens(_current, accountRef) {
|
|
225
246
|
return withAuthLock(async () => {
|
|
226
247
|
// Re-read inside the lock — another worker may have already refreshed.
|
|
227
|
-
const fresh = await readTokensUnlocked();
|
|
228
|
-
if (fresh
|
|
248
|
+
const fresh = await readTokensUnlocked(accountRef);
|
|
249
|
+
if (!fresh)
|
|
250
|
+
throw new ClaudeNativeNoAuthError();
|
|
251
|
+
if (fresh.expiresAt > Date.now() + REFRESH_LEAD_MS)
|
|
229
252
|
return fresh;
|
|
230
|
-
return refreshUnlocked(fresh
|
|
231
|
-
});
|
|
253
|
+
return refreshUnlocked(fresh, accountRef);
|
|
254
|
+
}, accountRef);
|
|
232
255
|
}
|
|
233
256
|
// A1 (docs/REMOTE_MANAGEMENT.md) - refresh IGNORING the local
|
|
234
257
|
// expiry check. The worker calls this when an API request 401s on a token
|
|
@@ -238,22 +261,22 @@ export async function refreshTokens(current) {
|
|
|
238
261
|
// `staleObtainedAt` guards the concurrent case: if another worker already
|
|
239
262
|
// rotated the on-disk tokens since the 401'ing client was built, return those
|
|
240
263
|
// instead of burning a second refresh against a just-rotated chain.
|
|
241
|
-
export async function forceRefreshTokens(staleObtainedAt) {
|
|
264
|
+
export async function forceRefreshTokens(staleObtainedAt, accountRef) {
|
|
242
265
|
return withAuthLock(async () => {
|
|
243
|
-
const fresh = await readTokensUnlocked();
|
|
266
|
+
const fresh = await readTokensUnlocked(accountRef);
|
|
244
267
|
if (!fresh)
|
|
245
268
|
throw new ClaudeNativeNoAuthError();
|
|
246
269
|
if (fresh.obtainedAt > staleObtainedAt)
|
|
247
270
|
return fresh;
|
|
248
|
-
return refreshUnlocked(fresh);
|
|
249
|
-
});
|
|
271
|
+
return refreshUnlocked(fresh, accountRef);
|
|
272
|
+
}, accountRef);
|
|
250
273
|
}
|
|
251
274
|
// The actual refresh POST + persist. Caller MUST hold the auth-file lock.
|
|
252
275
|
// A rejected refresh logs its own distinct line, separating
|
|
253
276
|
// "access token revoked early, chain still good" (no line ever
|
|
254
277
|
// appears; forced refresh recovers silently) from "refresh chain dead, re-auth
|
|
255
278
|
// genuinely required" (§10.2 diagnostics).
|
|
256
|
-
async function refreshUnlocked(seed) {
|
|
279
|
+
async function refreshUnlocked(seed, accountRef) {
|
|
257
280
|
const res = await fetch(TOKEN_URL, {
|
|
258
281
|
method: 'POST',
|
|
259
282
|
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
@@ -264,9 +287,8 @@ async function refreshUnlocked(seed) {
|
|
|
264
287
|
}),
|
|
265
288
|
});
|
|
266
289
|
if (!res.ok) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const err = new Error(`refresh failed (${res.status}): ${txt.slice(0, 200)}`);
|
|
290
|
+
console.error(`[claude-native] refresh rejected (${res.status})`);
|
|
291
|
+
const err = new Error(`Native refresh failed (${res.status})`);
|
|
270
292
|
err.httpStatus = res.status;
|
|
271
293
|
throw err;
|
|
272
294
|
}
|
|
@@ -280,8 +302,8 @@ async function refreshUnlocked(seed) {
|
|
|
280
302
|
scope: data.scope ?? seed.scope,
|
|
281
303
|
obtainedAt: now,
|
|
282
304
|
};
|
|
283
|
-
await writeTokensUnlocked(next);
|
|
284
|
-
clearClaudeAuthProblem(); // a fresh grant is proof the chain works again
|
|
305
|
+
await writeTokensUnlocked(next, accountRef);
|
|
306
|
+
clearClaudeAuthProblem(accountRef); // a fresh grant is proof the chain works again
|
|
285
307
|
return next;
|
|
286
308
|
}
|
|
287
309
|
// -- A2 (docs/REMOTE_MANAGEMENT.md) - live auth-problem state -----
|
|
@@ -293,29 +315,30 @@ async function refreshUnlocked(seed) {
|
|
|
293
315
|
// clears it until the next failed turn re-reports, which is the honest state.
|
|
294
316
|
// The transition into "problem" emits ONE auth-expired workbench notice (J1 →
|
|
295
317
|
// ntfy), so the phone learns without polling.
|
|
296
|
-
|
|
318
|
+
const claudeAuthProblems = new Map();
|
|
297
319
|
let authProblemNotify = null;
|
|
298
320
|
// Wired by the server bootstrap (initHubLink) to the J1 emit() — injected so
|
|
299
321
|
// this module stays free of a notifications import (and smoke-testable).
|
|
300
322
|
export function setClaudeAuthProblemNotifier(fn) {
|
|
301
323
|
authProblemNotify = fn;
|
|
302
324
|
}
|
|
303
|
-
export function markClaudeAuthProblem(detail) {
|
|
304
|
-
if (
|
|
325
|
+
export function markClaudeAuthProblem(detail, accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT) {
|
|
326
|
+
if (claudeAuthProblems.has(accountRef))
|
|
305
327
|
return; // already alerted — don't re-notify per turn
|
|
306
|
-
|
|
328
|
+
claudeAuthProblems.set(accountRef, { since: Date.now(), detail });
|
|
307
329
|
try {
|
|
308
|
-
|
|
330
|
+
if (accountRef === DEFAULT_CLAUDE_NATIVE_ACCOUNT)
|
|
331
|
+
authProblemNotify?.(detail);
|
|
309
332
|
}
|
|
310
333
|
catch {
|
|
311
334
|
/* notifier must never break the auth path */
|
|
312
335
|
}
|
|
313
336
|
}
|
|
314
|
-
export function clearClaudeAuthProblem() {
|
|
315
|
-
|
|
337
|
+
export function clearClaudeAuthProblem(accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT) {
|
|
338
|
+
claudeAuthProblems.delete(accountRef);
|
|
316
339
|
}
|
|
317
|
-
export function getClaudeAuthProblem() {
|
|
318
|
-
return
|
|
340
|
+
export function getClaudeAuthProblem(accountRef = DEFAULT_CLAUDE_NATIVE_ACCOUNT) {
|
|
341
|
+
return claudeAuthProblems.get(accountRef) ?? null;
|
|
319
342
|
}
|
|
320
343
|
// Thrown when ~/.arco/auth.json has no claude.native key. The worker
|
|
321
344
|
// catches `code === 'NO_AUTH'` and surfaces the [AUTH:claude] system_notice
|
|
@@ -330,13 +353,14 @@ export class ClaudeNativeNoAuthError extends Error {
|
|
|
330
353
|
// Public wrapper — load tokens, refresh if expired, return the live set.
|
|
331
354
|
// Throws ClaudeNativeNoAuthError on no-auth or a generic Error on refresh
|
|
332
355
|
// failure (caller surfaces [AUTH:claude]).
|
|
333
|
-
export async function ensureLiveTokens() {
|
|
334
|
-
const
|
|
356
|
+
export async function ensureLiveTokens(requestedAccount) {
|
|
357
|
+
const accountRef = await requireClaudeNativeAccount(requestedAccount);
|
|
358
|
+
const tokens = await loadTokens(accountRef);
|
|
335
359
|
if (!tokens)
|
|
336
360
|
throw new ClaudeNativeNoAuthError();
|
|
337
361
|
if (tokens.expiresAt > Date.now() + REFRESH_LEAD_MS)
|
|
338
362
|
return tokens;
|
|
339
|
-
return refreshTokens(tokens);
|
|
363
|
+
return refreshTokens(tokens, accountRef);
|
|
340
364
|
}
|
|
341
365
|
export const REFRESH_LEAD_MS_EXPORT = REFRESH_LEAD_MS;
|
|
342
366
|
//# sourceMappingURL=oauth.js.map
|