openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
728 lines (727 loc) • 25.2 kB
JavaScript
import { g as readStringValue } from "../../string-coerce-CCIiB4H7.mjs";
import { l as isRecord, o as asRecord, p as readStringField, t as asNonArrayRecord } from "../../record-coerce-CVPuDqcc.mjs";
import { a as extractErrorCode } from "../../error-coercion-hDrHOSGy.mjs";
import { n as canAccessSync, t as canAccess } from "../../path-existence-Co7-GyVr.mjs";
import { n as sha256Hex } from "../../node-crypto-B6yuTjmm.mjs";
import { f as resolveEffectiveEnableState, n as createNormalizedPluginsConfig } from "../../config-state-B1JlHgba.mjs";
import { n as runExec } from "../../exec-aRIvS9s4.mjs";
import { n as jsonResult } from "../../tool-results-CcV0sxnb.mjs";
import "../../path-existence-runtime-LOpU--Vt.mjs";
import "../../string-coerce-runtime-BwAZZDf5.mjs";
import "../../process-runtime-DcBPEA8Y.mjs";
import { c as tryReadSecretFileSync } from "../../secret-file-Cb7D2VFr.mjs";
import "../../error-runtime-BM740gJj.mjs";
import "../../secret-file-runtime-BxkfVa_y.mjs";
import { t as definePluginEntry } from "../../plugin-entry-CiJdaHtx.mjs";
import { r as resolveLivePluginConfigObject } from "../../plugin-config-runtime-CFUaG6iN.mjs";
import { t as resolveTrustedOnePasswordCli } from "../../onepassword-op-path-DuUKocPF.mjs";
import fs from "node:fs";
import path from "node:path";
import { randomUUID } from "node:crypto";
import fs$1 from "node:fs/promises";
import os from "node:os";
//#region extensions/onepassword/src/config.ts
const SLUG_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/;
const MAX_REGISTERED_ITEMS = 32;
const MAX_DESCRIPTION_LENGTH = 200;
function requiredString(e, t) {
const n = e[t];
if (typeof n !== "string" || !n.trim()) throw new Error(`1Password config ${t} must be a non-empty string`);
return n.trim();
}
function readOptionalOnePasswordString(e, t) {
return e[t] === void 0 ? void 0 : requiredString(e, t);
}
function readPolicy(e, t, n) {
if (e === void 0) return n;
if (e === "auto" || e === "approve" || e === "deny") return e;
throw new Error(`1Password config ${t} must be auto, approve, or deny`);
}
function readOnePasswordNumber(e, t, n, r) {
const i = e[t] ?? n;
if (typeof i !== "number" || !Number.isFinite(i) || r.integer && !Number.isInteger(i) || (r.allowZero ? i < 0 : i <= 0)) throw new Error(`1Password config ${t} must be a valid positive number`);
return i;
}
function parseOnePasswordConfig(e) {
if (!isRecord(e) || Object.keys(e).length === 0) return;
if (!Object.hasOwn(e, "vault") && !Object.hasOwn(e, "items")) return;
const t = requiredString(e, "vault");
if (t.startsWith("-")) throw new Error("1Password config vault must not start with a hyphen");
const n = readPolicy(e.defaultPolicy, "defaultPolicy", "approve");
if (!isRecord(e.items) || Object.keys(e.items).length === 0) throw new Error("1Password config items must contain at least one registered slug");
if (Object.keys(e.items).length > 32) throw new Error(`1Password config items must contain at most ${32} registered slugs`);
const r = Object.create(null);
for (const [i, a] of Object.entries(e.items)) {
if (!SLUG_PATTERN.test(i)) throw new Error(`Invalid 1Password item slug: ${i}`);
if (!isRecord(a)) throw new Error(`1Password config item ${i} must be an object`);
const e = requiredString(a, "item");
if (e.startsWith("-")) throw new Error(`1Password config item ${i} item must not start with a hyphen`);
const o = readOptionalOnePasswordString(a, "vault") ?? t;
if (o.startsWith("-")) throw new Error(`1Password config item ${i} vault must not start with a hyphen`);
const s = readOptionalOnePasswordString(a, "description");
if (s && s.length > MAX_DESCRIPTION_LENGTH) throw new Error(`1Password config item ${i} description must be at most ${MAX_DESCRIPTION_LENGTH} characters`);
const c = readOptionalOnePasswordString(a, "field") ?? "credential";
if (c.includes(",")) throw new Error(`1Password config item ${i} field must not contain commas`);
r[i] = {
item: e,
vault: o,
field: c,
policy: readPolicy(a.policy, `items.${i}.policy`, n),
...s ? { description: s } : {}
};
}
const i = readOptionalOnePasswordString(e, "opBin");
if (i && !path.isAbsolute(i)) throw new Error("1Password config opBin must be an absolute path");
return {
vault: t,
...i ? { opBin: i } : {},
defaultPolicy: n,
cacheTtlSeconds: readOnePasswordNumber(e, "cacheTtlSeconds", 300, {
integer: true,
allowZero: true
}),
grantTtlHours: readOnePasswordNumber(e, "grantTtlHours", 720, {
integer: false,
allowZero: false
}),
opTimeoutMs: readOnePasswordNumber(e, "opTimeoutMs", 15e3, {
integer: true,
allowZero: false
}),
items: r
};
}
//#endregion
//#region extensions/onepassword/src/errors.ts
var OnePasswordError = class extends Error {
constructor(e, t, n) {
super(t, n);
this.name = "OnePasswordError";
this.code = e;
}
};
//#endregion
//#region extensions/onepassword/src/pending-authorization.ts
const AUTHORIZATION_NONCE_PARAM = "authorizationNonce";
const pendingWrites = /* @__PURE__ */ new Map();
function matchesRequest(e, t) {
return e.agentId === t.agentId && e.toolCallId === t.toolCallId && e.slug === t.slug && e.reason === t.reason;
}
async function registerPendingAuthorization(e, t, n, r) {
const i = e.register(t, n, { ttlMs: r });
const { agentId: a, toolCallId: o, slug: s, reason: c } = n;
pendingWrites.set(t, {
request: {
agentId: a,
toolCallId: o,
slug: s,
reason: c
},
completion: i
});
try {
await i;
} finally {
pendingWrites.delete(t);
}
}
async function consumePendingAuthorization(e, t, n) {
const r = n !== void 0 ? pendingWrites.get(n) : void 0;
const i = n !== void 0 ? r ? [r.completion] : [] : [...pendingWrites.values()].filter((e) => matchesRequest(e.request, t)).map((e) => e.completion);
const a = await Promise.allSettled(i);
for (const e of a) if (e.status === "rejected") throw e.reason;
return n !== void 0 ? await e.consume(n) : await consumeUniquePendingAuthorization(e, t);
}
async function consumeUniquePendingAuthorization(e, t) {
let n;
for (const r of await e.entries()) {
const e = r.value;
if (!matchesRequest(e, t)) continue;
if (n !== void 0) return;
n = r.key;
}
const r = n === void 0 ? void 0 : await e.consume(n);
return r && matchesRequest(r, t) ? r : void 0;
}
//#endregion
//#region extensions/onepassword/src/broker.ts
const APPROVAL_TIMEOUT_MS = 6e5;
const PENDING_AUTHORIZATION_TTL_MS = APPROVAL_TIMEOUT_MS;
var BrokerError = class extends Error {
constructor(e, t) {
super(t);
this.name = "BrokerError";
this.code = e;
}
};
function fingerprintOnePasswordTarget(e) {
return sha256Hex(JSON.stringify([
e.vault,
e.item,
e.field
]));
}
function standingGrantKey(e, t) {
return sha256Hex(JSON.stringify([e, t]));
}
function parseToolInput(e) {
if (e.action === "list") return { action: "list" };
if (e.action !== "get") throw new BrokerError("INVALID_ACTION", "action must be list or get");
const t = readStringValue(e.reason)?.trim();
if (!t || t.length > 300) throw new BrokerError("INVALID_REASON", "reason is required and must be at most 300 characters");
const n = readStringValue(e.slug)?.trim();
if (!n || !SLUG_PATTERN.test(n)) throw new BrokerError("INVALID_SLUG", "slug must match ^[a-z0-9][a-z0-9-]{0,63}$");
return {
action: "get",
slug: n,
reason: t
};
}
function errorCode(e) {
if (e instanceof OnePasswordError || e instanceof BrokerError) return e.code;
}
var OnePasswordBroker = class {
constructor(e) {
this.cache = /* @__PURE__ */ new Map();
this.resolveConfig = e.resolveConfig;
this.opClient = e.opClient;
this.stores = e.stores;
}
observeConfigFingerprint(e) {
if (this.lastConfigFingerprint !== void 0 && this.lastConfigFingerprint !== e) this.cache.clear();
this.lastConfigFingerprint = e;
}
currentConfig() {
const e = this.resolveConfig();
if (!e) {
this.observeConfigFingerprint(null);
throw new BrokerError("POLICY_CHANGED", "1Password broker is no longer configured");
}
const t = sha256Hex(JSON.stringify(e));
this.observeConfigFingerprint(t);
return {
config: e,
fingerprint: t
};
}
context(e, t, n) {
return {
agentId: t.agentId ?? "unknown",
sessionKey: t.sessionKey ?? "unknown",
sessionId: t.sessionId ?? "unknown",
toolCallId: e.toolCallId ?? t.toolCallId ?? "unknown",
slug: n.slug ?? "unknown",
reason: n.reason ?? ""
};
}
async audit(e, t, n = {}) {
const r = Date.now();
const i = `${String(r).padStart(16, "0")}:${e.toolCallId}:${randomUUID()}`;
await this.stores.audit.register(i, {
timestampMs: r,
agentId: e.agentId,
sessionKey: e.sessionKey,
toolCallId: e.toolCallId,
slug: e.slug,
reason: e.reason,
outcome: t,
...n.errorCode ? { errorCode: n.errorCode } : {}
});
}
async pruneStaleGrants(e) {
const t = Date.now();
for (const n of await this.stores.grants.entries()) {
const r = Object.hasOwn(e.items, n.value.slug) ? e.items[n.value.slug] : void 0;
if (!r || n.key !== standingGrantKey(n.value.agentId, n.value.slug) || n.value.expiresAtMs <= t || n.value.targetFingerprint !== fingerprintOnePasswordTarget(r)) await this.stores.grants.delete(n.key);
}
}
async beforeToolCall(e, t) {
if (e.toolName !== "onepassword") return;
let n;
try {
n = parseToolInput(e.params);
} catch (n) {
const r = this.context(e, t, {
slug: readStringValue(e.params.slug)?.trim(),
reason: readStringValue(e.params.reason)?.trim()
});
await this.audit(r, "error", { errorCode: errorCode(n) ?? "INVALID_ACTION" });
return {
block: true,
blockReason: n instanceof Error ? n.message : "Invalid request"
};
}
if (n.action === "list") return;
const r = this.context(e, t, n);
let i;
let a;
try {
({config: i, fingerprint: a} = this.currentConfig());
} catch (e) {
await this.audit(r, "error", { errorCode: errorCode(e) });
return {
block: true,
blockReason: e instanceof Error ? e.message : "1Password broker is unavailable"
};
}
if (!Object.hasOwn(i.items, n.slug)) {
await this.audit(r, "error", { errorCode: "UNKNOWN_SLUG" });
return {
block: true,
blockReason: `Unknown 1Password slug: ${n.slug}`
};
}
const o = i.items[n.slug];
if (!o) throw new Error(`Missing 1Password config for registered slug: ${n.slug}`);
if (!e.toolCallId && !t.toolCallId) {
await this.audit(r, "error", { errorCode: "TOOL_CALL_ID_MISSING" });
return {
block: true,
blockReason: "1Password request is missing a tool call id"
};
}
if (o.policy === "deny") {
await this.audit(r, "policy-denied");
return {
block: true,
blockReason: `1Password access denied by policy for ${n.slug}`
};
}
const s = randomUUID();
const c = {
...e.params,
[AUTHORIZATION_NONCE_PARAM]: s
};
const authorize = (e, t = false) => registerPendingAuthorization(this.stores.pending, s, {
...r,
outcome: e,
persistGrant: t,
configFingerprint: a,
targetFingerprint: fingerprintOnePasswordTarget(o)
}, PENDING_AUTHORIZATION_TTL_MS);
if (o.policy === "auto") {
await authorize("auto");
return { params: c };
}
const l = r.agentId === "unknown" ? void 0 : standingGrantKey(r.agentId, n.slug);
const u = l ? await this.stores.grants.lookup(l) : void 0;
if (u && u.agentId === r.agentId && u.slug === n.slug && u.expiresAtMs > Date.now() && u.targetFingerprint === fingerprintOnePasswordTarget(o)) {
await authorize("grant");
return { params: c };
}
if (u && l) await this.stores.grants.delete(l);
return {
params: c,
requireApproval: {
title: `1Password: ${n.slug}`,
description: `Agent ${r.agentId} requests ${n.slug}. Reason: ${n.reason}`,
severity: "warning",
timeoutMs: APPROVAL_TIMEOUT_MS,
allowedDecisions: r.agentId === "unknown" ? ["allow-once", "deny"] : [
"allow-once",
"allow-always",
"deny"
],
onResolution: async (e) => {
if (e === "allow-once" || e === "allow-always") {
await authorize("approved", e === "allow-always" && r.agentId !== "unknown");
return;
}
if (e === "deny") {
await this.audit(r, "denied");
return;
}
if (e === "timeout") {
await this.audit(r, "timeout");
return;
}
await this.audit(r, "error", { errorCode: "APPROVAL_CANCELLED" });
}
}
};
}
async list(e) {
const { config: t } = this.currentConfig();
const n = Object.entries(t.items).toSorted(([e], [t]) => e.localeCompare(t));
const r = e.agentId;
let i = [];
if (r) {
const e = n.map(([e]) => standingGrantKey(r, e));
i = (await this.stores.grants.lookupMany(e)).map((e) => {
if (!e.ok) throw e.error;
return e.value;
});
}
const a = Date.now();
return n.map(([e, t], n) => {
const o = i[n];
return {
slug: e,
description: t.description ?? "",
policy: t.policy,
standingGrantActive: Boolean(o && o.agentId === r && o.slug === e && o.expiresAtMs > a && o.targetFingerprint === fingerprintOnePasswordTarget(t))
};
});
}
async get(e, t, n, r) {
const i = {
agentId: n.agentId ?? "unknown",
sessionKey: n.sessionKey ?? "unknown",
sessionId: n.sessionId ?? "unknown",
toolCallId: e,
slug: t.slug,
reason: t.reason
};
let a;
try {
a = await consumePendingAuthorization(this.stores.pending, i, r);
} catch (e) {
await this.audit(i, "error", { errorCode: errorCode(e) });
throw e;
}
if (!a || a.slug !== t.slug || a.reason !== t.reason) {
await this.audit(i, "error", { errorCode: "POLICY_NOT_EVALUATED" });
throw new BrokerError("POLICY_NOT_EVALUATED", "1Password policy was not evaluated for this request");
}
let o;
let s;
try {
({config: o, fingerprint: s} = this.currentConfig());
} catch (e) {
await this.audit(a, "error", { errorCode: errorCode(e) });
throw e;
}
if (!Object.hasOwn(o.items, t.slug)) {
await this.audit(a, "error", { errorCode: "UNKNOWN_SLUG" });
throw new BrokerError("UNKNOWN_SLUG", `Unknown 1Password slug: ${t.slug}`);
}
const c = o.items[t.slug];
if (!c) throw new Error(`Missing 1Password config for registered slug: ${t.slug}`);
if (c.policy === "deny") {
await this.audit(a, "policy-denied");
throw new BrokerError("POLICY_CHANGED", `1Password access denied by policy for ${t.slug}`);
}
if (a.outcome === "auto" && c.policy !== "auto" || a.outcome !== "auto" && c.policy !== "approve" || a.configFingerprint !== s || a.targetFingerprint !== fingerprintOnePasswordTarget(c)) {
await this.audit(a, "error", { errorCode: "POLICY_CHANGED" });
throw new BrokerError("POLICY_CHANGED", "1Password policy changed before tool execution");
}
if (a.outcome === "grant") {
const e = await this.stores.grants.lookup(standingGrantKey(a.agentId, t.slug));
if (!e || e.agentId !== a.agentId || e.slug !== t.slug || e.expiresAtMs <= Date.now() || e.targetFingerprint !== fingerprintOnePasswordTarget(c)) {
await this.audit(a, "error", { errorCode: "GRANT_EXPIRED" });
throw new BrokerError("GRANT_EXPIRED", "1Password standing grant expired before tool execution");
}
}
if (a.persistGrant) {
const e = Date.now();
const n = Math.round(o.grantTtlHours * 60 * 60 * 1e3);
try {
await this.pruneStaleGrants(o);
await this.stores.grants.register(standingGrantKey(a.agentId, t.slug), {
agentId: a.agentId,
slug: t.slug,
grantedAtMs: e,
expiresAtMs: e + n,
targetFingerprint: fingerprintOnePasswordTarget(c)
}, { ttlMs: n });
} catch (e) {
await this.audit(a, "error", { errorCode: errorCode(e) });
throw e;
}
}
const l = this.cache.get(t.slug);
const u = fingerprintOnePasswordTarget(c);
if (l && l.expiresAtMs > Date.now() && l.targetFingerprint === u) {
await this.audit(a, "cache-hit");
return {
slug: t.slug,
value: l.value,
itemTitle: l.itemTitle,
fieldLabel: l.fieldLabel
};
}
this.cache.delete(t.slug);
try {
const e = await this.opClient.getItem(c);
await this.audit(a, a.outcome);
if (o.cacheTtlSeconds > 0) this.cache.set(t.slug, {
...e,
targetFingerprint: u,
expiresAtMs: Date.now() + o.cacheTtlSeconds * 1e3
});
return {
slug: t.slug,
...e
};
} catch (e) {
await this.audit(a, "error", { errorCode: errorCode(e) });
throw e;
}
}
};
//#endregion
//#region extensions/onepassword/src/op-client.ts
const MAX_STDOUT_BYTES = 1048576;
function resolveOpBinary(e) {
if (e) return canAccessSync(e, fs.constants.X_OK) ? e : void 0;
const t = process.platform === "win32" ? "op.exe" : "op";
for (const e of (process.env.PATH ?? "").split(path.delimiter)) {
if (!e) continue;
const n = path.resolve(e, t);
if (canAccessSync(n, fs.constants.X_OK)) return n;
}
}
function classifyOpError(e) {
if (e instanceof OnePasswordError) return e;
const t = asRecord(e);
const n = (typeof t.stderr === "string" ? t.stderr : "").toLowerCase();
if (t.code === "ENOENT") return new OnePasswordError("OP_NOT_FOUND", "1Password CLI executable was not found");
if (t.killed === true || t.timedOut === true || t.code === "ETIMEDOUT" || t.signal === "SIGTERM") return new OnePasswordError("TIMEOUT", "1Password CLI request timed out");
if (/item.+(is not found|isn't found|not found|does not exist)|could not find.+item|isn't an item\b/u.test(n)) return new OnePasswordError("ITEM_NOT_FOUND", "1Password item was not found");
if (/isn't a field\b|field.+(?:is not found|isn't found|not found|does not exist)/u.test(n)) return new OnePasswordError("FIELD_NOT_FOUND", "1Password field was not found");
if (/unauthorized|authentication|not signed in|invalid service account|permission denied/u.test(n)) return new OnePasswordError("AUTH_FAILED", "1Password service account authentication failed");
if (/\b429\b|rate[ -]?limit|too many requests/u.test(n)) return new OnePasswordError("RATE_LIMITED", "1Password rate limit reached");
return new OnePasswordError("OP_ERROR", "1Password CLI request failed");
}
function parseField(e, t, n) {
let r;
try {
const t = JSON.parse(e);
if (!isRecord(t)) throw new Error("field response is not an object");
r = t;
} catch (e) {
throw new OnePasswordError("OP_ERROR", "1Password CLI returned invalid JSON", { cause: e });
}
if (r.label !== t && r.id !== t || typeof r.value !== "string") throw new OnePasswordError("FIELD_NOT_FOUND", `1Password field ${t} was not found`);
return {
value: r.value,
itemTitle: n,
fieldLabel: typeof r.label === "string" ? r.label : t
};
}
var OpClient = class {
constructor(e) {
this.permissionWarningEmitted = false;
this.opBin = resolveOpBinary(e.opBin);
this.tokenFile = e.tokenFile;
this.timeoutMs = e.timeoutMs;
this.home = os.homedir();
this.warn = e.warn ?? (() => void 0);
}
async tokenFilePresent() {
return canAccess(this.tokenFile, fs.constants.R_OK);
}
async readToken() {
let e;
try {
e = tryReadSecretFileSync(this.tokenFile, "1Password service account token", { rejectHardlinks: false });
const t = await fs$1.stat(this.tokenFile);
if (!this.permissionWarningEmitted && process.platform !== "win32" && (t.mode & 63) !== 0) {
this.permissionWarningEmitted = true;
this.warn("1Password service account token file permissions are broader than 0600");
}
} catch (e) {
const t = e instanceof Error && extractErrorCode(e) === "too-large" ? e.message : "1Password service account token file is missing";
throw new OnePasswordError("TOKEN_MISSING", t, { cause: e });
}
if (!e) throw new OnePasswordError("TOKEN_MISSING", "1Password service account token file is empty");
return e;
}
async getItem(e) {
if (!this.opBin) throw new OnePasswordError("OP_NOT_FOUND", "1Password CLI executable was not found");
let t;
try {
const e = await resolveTrustedOnePasswordCli({ configuredPath: this.opBin });
if (!e) throw new OnePasswordError("OP_NOT_FOUND", "1Password CLI executable was not found");
t = e;
} catch (e) {
if (e instanceof OnePasswordError) throw e;
throw new OnePasswordError("OP_NOT_FOUND", "1Password CLI executable is not trusted", { cause: e });
}
const n = await this.readToken();
const r = [
"item",
"get",
e.item,
"--vault",
e.vault,
"--fields",
e.field,
"--format",
"json",
"--cache=false"
];
try {
return parseField((await runExec(t, r, {
baseEnv: {},
env: {
OP_SERVICE_ACCOUNT_TOKEN: n,
HOME: this.home,
OP_LOAD_DESKTOP_APP_SETTINGS: "false",
OP_BIOMETRIC_UNLOCK_ENABLED: "false"
},
timeoutMs: this.timeoutMs,
maxBuffer: MAX_STDOUT_BYTES,
logOutput: false
})).stdout, e.field, e.item);
} catch (e) {
throw classifyOpError(e);
}
}
};
//#endregion
//#region extensions/onepassword/src/tool.ts
const OnePasswordToolSchema = {
type: "object",
additionalProperties: false,
required: ["action"],
properties: {
action: {
type: "string",
enum: ["list", "get"],
description: "List registered secret slugs or get one registered secret."
},
slug: {
type: "string",
pattern: "^[a-z0-9][a-z0-9-]{0,63}$",
description: "Registered secret slug. Required for get."
},
reason: {
type: "string",
minLength: 1,
maxLength: 300,
description: "Why the agent needs this secret. Required for get."
},
authorizationNonce: {
type: "string",
description: "Internal. Injected by the gateway policy layer; never set this manually."
}
}
};
function errorResult(e) {
const t = readStringField(asRecord(e), "code") ?? "OP_ERROR";
const n = e instanceof Error ? e.message : "1Password request failed";
return jsonResult({
ok: false,
error: {
code: t,
message: n
}
});
}
function createOnePasswordTool(e, t) {
return {
name: "onepassword",
label: "1Password",
description: "List curated 1Password secret slugs or retrieve one secret under its configured access policy.",
parameters: OnePasswordToolSchema,
execute: async (n, r) => {
const i = asNonArrayRecord(r);
try {
const r = parseToolInput(i);
if (r.action === "list") return jsonResult({
ok: true,
items: await e.list(t)
});
const a = i[AUTHORIZATION_NONCE_PARAM];
const o = typeof a === "string" ? a : void 0;
const s = await e.get(n, r, t, o);
return jsonResult({
ok: true,
...s
});
} catch (e) {
return errorResult(e);
}
}
};
}
//#endregion
//#region extensions/onepassword/index.ts
const MAX_AUDIT_ROWS = 4e4;
const MAX_STANDING_GRANTS = 32 * 32;
var onepassword_default = definePluginEntry({
id: "onepassword",
name: "1Password",
description: "1Password SecretRef resolver and curated agent broker with approval policy and SQLite audit history.",
register(e) {
const t = parseOnePasswordConfig(e.pluginConfig);
const resolveCurrentConfig = () => {
const t = e.runtime.config.current();
const n = resolveLivePluginConfigObject(() => t, "onepassword", e.pluginConfig);
return resolveEffectiveEnableState({
id: "onepassword",
origin: "bundled",
config: createNormalizedPluginsConfig(t.plugins),
rootConfig: t,
enabledByDefault: n !== void 0
}).enabled ? parseOnePasswordConfig(n) : void 0;
};
const n = e.runtime.state.openKeyedStoreV2({
namespace: "grants",
maxEntries: MAX_STANDING_GRANTS,
overflowPolicy: "evict-oldest"
});
const r = e.runtime.state.openKeyedStore({
namespace: "audit",
maxEntries: MAX_AUDIT_ROWS,
overflowPolicy: "evict-oldest"
});
const i = e.runtime.state.openKeyedStore({
namespace: "pending",
maxEntries: 512,
overflowPolicy: "evict-oldest"
});
const a = path.join(e.runtime.state.resolveStateDir(process.env), "credentials", "onepassword", "service-account-token");
let o;
const resolveCurrentOpClient = () => {
const t = resolveCurrentConfig();
const n = JSON.stringify([t?.opBin ?? null, t?.opTimeoutMs ?? 15e3]);
if (o?.key === n) return o.client;
const r = new OpClient({
opBin: t?.opBin,
tokenFile: a,
timeoutMs: t?.opTimeoutMs ?? 15e3,
warn: (t) => e.logger.warn(t)
});
o = {
key: n,
client: r
};
return r;
};
const s = t ? new OnePasswordBroker({
resolveConfig: resolveCurrentConfig,
opClient: { getItem: (e) => resolveCurrentOpClient().getItem(e) },
stores: {
audit: r,
grants: n,
pending: i
}
}) : void 0;
e.registerCli(async ({ program: e, config: t }) => {
const { registerOnePasswordCommands: n } = await import("../../cli-4pLcMnCl.mjs");
const { registerOnePasswordSecretRefCommands: i } = await import("../../secret-ref-cli-DdWxZHGR.mjs");
n({
program: e,
resolveConfig: resolveCurrentConfig,
resolveOpClient: resolveCurrentOpClient,
auditStore: r,
registerAdditionalCommands: (e) => i({
command: e,
config: t,
tokenFile: a
})
});
}, { descriptors: [{
name: "onepassword",
description: "Manage the 1Password integration",
hasSubcommands: true
}] });
if (!s) return;
e.registerTool((e) => createOnePasswordTool(s, e), { name: "onepassword" });
e.on("before_tool_call", (e, t) => s.beforeToolCall(e, t));
}
});
//#endregion
export { onepassword_default as default };