mirror of
http://192.168.0.88:13333/lywsvip/openclaw-zero-token.git
synced 2026-06-08 15:22:23 +08:00
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
80 lines
2.0 KiB
TypeScript
80 lines
2.0 KiB
TypeScript
import {
|
|
type DeviceAuthEntry,
|
|
type DeviceAuthStore,
|
|
normalizeDeviceAuthRole,
|
|
normalizeDeviceAuthScopes,
|
|
} from "./device-auth.js";
|
|
export type { DeviceAuthEntry, DeviceAuthStore } from "./device-auth.js";
|
|
|
|
export type DeviceAuthStoreAdapter = {
|
|
readStore: () => DeviceAuthStore | null;
|
|
writeStore: (store: DeviceAuthStore) => void;
|
|
};
|
|
|
|
export function loadDeviceAuthTokenFromStore(params: {
|
|
adapter: DeviceAuthStoreAdapter;
|
|
deviceId: string;
|
|
role: string;
|
|
}): DeviceAuthEntry | null {
|
|
const store = params.adapter.readStore();
|
|
if (!store || store.deviceId !== params.deviceId) {
|
|
return null;
|
|
}
|
|
const role = normalizeDeviceAuthRole(params.role);
|
|
const entry = store.tokens[role];
|
|
if (!entry || typeof entry.token !== "string") {
|
|
return null;
|
|
}
|
|
return entry;
|
|
}
|
|
|
|
export function storeDeviceAuthTokenInStore(params: {
|
|
adapter: DeviceAuthStoreAdapter;
|
|
deviceId: string;
|
|
role: string;
|
|
token: string;
|
|
scopes?: string[];
|
|
}): DeviceAuthEntry {
|
|
const role = normalizeDeviceAuthRole(params.role);
|
|
const existing = params.adapter.readStore();
|
|
const next: DeviceAuthStore = {
|
|
version: 1,
|
|
deviceId: params.deviceId,
|
|
tokens:
|
|
existing && existing.deviceId === params.deviceId && existing.tokens
|
|
? { ...existing.tokens }
|
|
: {},
|
|
};
|
|
const entry: DeviceAuthEntry = {
|
|
token: params.token,
|
|
role,
|
|
scopes: normalizeDeviceAuthScopes(params.scopes),
|
|
updatedAtMs: Date.now(),
|
|
};
|
|
next.tokens[role] = entry;
|
|
params.adapter.writeStore(next);
|
|
return entry;
|
|
}
|
|
|
|
export function clearDeviceAuthTokenFromStore(params: {
|
|
adapter: DeviceAuthStoreAdapter;
|
|
deviceId: string;
|
|
role: string;
|
|
}): void {
|
|
const store = params.adapter.readStore();
|
|
if (!store || store.deviceId !== params.deviceId) {
|
|
return;
|
|
}
|
|
const role = normalizeDeviceAuthRole(params.role);
|
|
if (!store.tokens[role]) {
|
|
return;
|
|
}
|
|
const next: DeviceAuthStore = {
|
|
version: 1,
|
|
deviceId: store.deviceId,
|
|
tokens: { ...store.tokens },
|
|
};
|
|
delete next.tokens[role];
|
|
params.adapter.writeStore(next);
|
|
}
|