UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

83 lines • 3.14 kB
const API_KEY_CREDENTIAL_FIELDS = { type: "public", key: "sealed", env: "forces-device", loginId: "device-only", }; const OAUTH_CREDENTIAL_FIELDS = { type: "public", access: "sealed", refresh: "device-only", expires: "public", idToken: "device-only", subject: "device-only", email: "device-only", issuer: "device-only", clientId: "device-only", scopes: "device-only", planUsageEnabled: "public", // The ChatGPT sign-in route: a two-value protocol selector ("siwc" | "codex") the request needs, no secret material. route: "public", loginId: "device-only", }; export const CREDENTIAL_SLOT_FIELDS = { name: "public", displayName: "device-only", source: "public", key: "sealed", access: "sealed", refresh: "device-only", expires: "public", // The slot's ChatGPT sign-in route: a two-value protocol selector ("siwc" | "codex"), no secret material. route: "public", env: "forces-device", }; const POOLED_CREDENTIAL_FIELDS = { accounts: CREDENTIAL_SLOT_FIELDS, pinned: "public", order: "public", }; /** A stored credential key outside the declared fields (OAuth flows may add any) keeps the credential on the device. */ export function classifyCredentialField(type, key) { const table = type === "api_key" ? API_KEY_CREDENTIAL_FIELDS : OAUTH_CREDENTIAL_FIELDS; return (Object.hasOwn(table, key) ? table[key] : undefined) ?? "forces-device"; } function forcesDevice(table, key, value) { const fieldClass = Object.hasOwn(table, key) ? table[key] : undefined; if (fieldClass === undefined) return ["undeclared-field"]; if (fieldClass !== "forces-device") return []; return typeof value === "object" && value !== null && Object.keys(value).length === 0 ? [] : ["env"]; } /** Why a stored auth.json credential must be used on the device; empty when sealed custody can compose its requests. */ export function credentialDeviceReasons(credential) { const reasons = new Set(); const typeTable = credential.type === "api_key" ? API_KEY_CREDENTIAL_FIELDS : credential.type === "oauth" ? OAUTH_CREDENTIAL_FIELDS : undefined; if (typeTable === undefined) return ["undeclared-field"]; const table = { ...typeTable, ...POOLED_CREDENTIAL_FIELDS }; for (const [key, value] of Object.entries(credential)) { for (const reason of forcesDevice(table, key, value)) reasons.add(reason); } const accounts = credential.accounts; if (accounts !== undefined && !Array.isArray(accounts)) reasons.add("undeclared-field"); for (const account of Array.isArray(accounts) ? accounts : []) { if (typeof account !== "object" || account === null) { reasons.add("undeclared-field"); continue; } for (const [key, value] of Object.entries(account)) { for (const reason of forcesDevice(CREDENTIAL_SLOT_FIELDS, key, value)) reasons.add(reason); } } return [...reasons]; } //# sourceMappingURL=credential-fields.js.map