Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Let one 1Password item have its own bots, ahead of its vault's (#4954)

Bugfixer 21231325a6b56
diff --git a/electron/cloud-send.mjs b/electron/cloud-send.mjs
index 81e467eb25..8c5c62113c 100644
--- a/electron/cloud-send.mjs
+++ b/electron/cloud-send.mjs
@@ -906,6 +906,13 @@ export function createCloudSend({ local, cloud, handoff, store, onChange = () =>
const granted = await ctx.session.call("PATCH", `/api/logins/1password/vaults/${encodeURIComponent(vault)}`, { bots: botsOnCloud(bots, ctx.cloudBots) });
if (!granted.ok && granted.status !== 404) throw refusedError("refused", granted, "My Cloud connected 1Password but could not keep its vaults to the same bots.");
}
+ // An item narrowed here must not open to every bot there; a Cloud too old for item choices (405) fails out loud.
+ for (const [item, bots] of Object.entries(onePassword.itemGrants ?? {})) {
+ const [vault, id, ...rest] = item.split(":");
+ if (rest.length || !VAULT_ID.test(vault ?? "") || !VAULT_ID.test(id ?? "")) continue;
+ const granted = await ctx.session.call("PATCH", `/api/logins/1password/items/${encodeURIComponent(vault)}/${encodeURIComponent(id)}`, { bots: botsOnCloud(bots, ctx.cloudBots) });
+ if (!granted.ok && granted.status !== 404) throw refusedError("refused", granted, "My Cloud connected 1Password but could not keep its logins to the same bots. Update My Cloud and send again.");
+ }
done(ctx, row.key);
ctx.result.onePassword = true;
}
diff --git a/electron/cloud-send.node-test.mjs b/electron/cloud-send.node-test.mjs
index 93ec1d8b0c..d5d9e944b3 100644
--- a/electron/cloud-send.node-test.mjs
+++ b/electron/cloud-send.node-test.mjs
@@ -393,6 +393,24 @@ test("1Password refused on My Cloud is told in words for this computer, not My C
assert.equal(busy.result.failed[0].final, undefined, "any other refusal can be tried again");
});
+test("1Password items with bots of their own keep them on My Cloud; a Cloud too old for that fails out loud", async () => {
+ const onePassword = { key: itemKey.onePassword(), kind: "1password", label: "1Password", parts: { token: "t" } };
+ const sides = fakeSides({ localItems: [onePassword] });
+ sides.deps.handoff = async () => ({ onePassword: { token: "ops_fake", grants: { v1: [] }, itemGrants: { "v1:i1": "all", "bad:id:x": "all" } } });
+ const outcome = await createCloudSend(sides.deps).send();
+ assert.equal(outcome.result.failed.length, 0);
+ assert.ok(sides.calls.includes("PATCH /api/logins/1password/vaults/v1"));
+ assert.ok(sides.calls.includes("PATCH /api/logins/1password/items/v1/i1"), "the item's own bots go too");
+ assert.ok(!sides.calls.some((call) => call.includes("/items/bad")), "a malformed item key is skipped");
+ const old = fakeSides({ localItems: [onePassword], refuse: { "/api/logins/1password/items/v1/i1": { status: 405, error: "method not allowed" } } });
+ old.deps.handoff = async () => ({ onePassword: { token: "ops_fake", grants: {}, itemGrants: { "v1:i1": [] } } });
+ const refused = await createCloudSend(old.deps).send();
+ assert.deepEqual(refused.result.failed.map((entry) => entry.key), ["1password"], "never left open to every bot there");
+ const gone = fakeSides({ localItems: [onePassword], refuse: { "/api/logins/1password/items/v1/i1": { status: 404, error: "no such item" } } });
+ gone.deps.handoff = async () => ({ onePassword: { token: "ops_fake", grants: {}, itemGrants: { "v1:i1": [] } } });
+ assert.equal((await createCloudSend(gone.deps).send()).result.failed.length, 0, "an item My Cloud's token does not read is skipped");
+});
+
test("chats by row: the cursor moves only past what My Cloud took; one removed there is never sent again; one being answered waits", async () => {
const rows = { "t-a": [{ id: "a1", at: 1 }, { id: "a2", at: 2 }], "t-b": [{ id: "b1", at: 1 }], "t-c": [{ id: "c1", at: 1 }] };
const heads = () => Object.entries(rows).map(([threadId, list]) => ({ bot: "ember", threadId, last: list.length, lastId: list.at(-1).id, busy: threadId === "t-c" }));
diff --git a/server/bot-logins.ts b/server/bot-logins.ts
index 9bd741c137..73777e42ab 100644
--- a/server/bot-logins.ts
+++ b/server/bot-logins.ts
@@ -174,6 +174,11 @@ export class BotLogins {
this.store.setOnePasswordGrant(vaultId, bots);
return this.onePassword.status();
},
+ grantItem: (item, bots) => {
+ if (!this.onePassword.hasItem(item)) return false;
+ this.store.setOnePasswordItemGrant(item, bots);
+ return true;
+ },
},
};
}
diff --git a/server/cloud-send.ts b/server/cloud-send.ts
index cc657810b3..fda0b0ca50 100644
--- a/server/cloud-send.ts
+++ b/server/cloud-send.ts
@@ -35,7 +35,7 @@ export interface CloudSendSources {
/** The stored picture's bytes, or null when it is gone. */
picture(avatarUrl: string): Uint8Array | null;
logins(): ReadonlyArray<{ id: string; site: string; hosts: readonly string[]; exactHost: boolean; username: string; updatedAt: number }>;
- onePassword(): { connectedAt: number; grants: Record<string, LoginBots> } | null;
+ onePassword(): { connectedAt: number; grants: Record<string, LoginBots>; itemGrants?: Record<string, LoginBots> } | null;
/** Saved Vault secrets, never a value. Linked password-manager items are not listed: they stay linked. */
secrets?(): ReadonlyArray<{ id: string; name: string; updatedAt: number }>;
settings(): { profile?: { name?: string; email?: string; aboutMe?: string }; language?: string };
@@ -127,7 +127,9 @@ export function cloudSendSummary(sources: CloudSendSources, { move = false, bot:
const onePassword = sources.onePassword();
if (onePassword) {
items.push({ key: itemKey.onePassword(), kind: "1password", label: "1Password",
- parts: { token: partHash(onePassword.connectedAt), vaults: partHash(onePassword.grants) } });
+ // Items' own bots count with the vaults', so narrowing one item sends again; without any the hash stays as before.
+ parts: { token: partHash(onePassword.connectedAt),
+ vaults: partHash(Object.keys(onePassword.itemGrants ?? {}).length ? { vaults: onePassword.grants, items: onePassword.itemGrants } : onePassword.grants) } });
}
for (const secret of sources.secrets?.() ?? []) {
items.push({ key: itemKey.secret(secret.id), kind: "secret", label: secret.name, id: secret.id, parts: { saved: partHash(secret.updatedAt) } });
diff --git a/server/index.ts b/server/index.ts
index f8906fd387..c13e04bc12 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -739,7 +739,7 @@ const heldSecrets = new HeldSecrets(logins);
addHeldSecretScrubber((text) => heldSecrets.scrub(text));
const onePassword = new OnePasswordLogins({
token: () => logins.onePasswordToken(),
- grants: () => logins.onePasswordGrants(),
+ grants: () => logins.onePasswordGrants(), itemGrants: () => logins.onePasswordItemGrants(),
connect: async (token) => {
let sdk: OnePasswordSdk;
try { sdk = nativeRequire()("@1password/sdk") as OnePasswordSdk; }
diff --git a/server/login-handoff.test.ts b/server/login-handoff.test.ts
index 83e4e4c247..f2a1548bf2 100644
--- a/server/login-handoff.test.ts
+++ b/server/login-handoff.test.ts
@@ -35,16 +35,17 @@ describe("the private login handoff to the desktop's main process", () => {
expect(parseTotpKey((posted[0] as { login: { totp: string } }).login.totp)).toEqual(totp);
});
- it("hands the 1Password token with its vaults' bots, and says plainly when there is nothing to hand", () => {
+ it("hands the 1Password token with its vaults' and items' bots, and says plainly when there is nothing to hand", () => {
const { store, posted, ask } = setup();
ask({ type: LOGIN_HANDOFF_REQUEST, requestId: "request-0002", what: { kind: "1password" } });
store.setOnePasswordToken(TOKEN);
store.setOnePasswordGrant("v1", ["pepper"]);
+ store.setOnePasswordItemGrant("v1:i1", []);
ask({ type: LOGIN_HANDOFF_REQUEST, requestId: "request-0003", what: { kind: "1password" } });
ask({ type: LOGIN_HANDOFF_REQUEST, requestId: "request-0004", what: { kind: "login", id: "gone" } });
expect(posted).toEqual([
{ type: LOGIN_HANDOFF_RESULT, requestId: "request-0002", ok: false, error: "1Password is not connected on this computer." },
- { type: LOGIN_HANDOFF_RESULT, requestId: "request-0003", ok: true, onePassword: { token: TOKEN, grants: { v1: ["pepper"] } } },
+ { type: LOGIN_HANDOFF_RESULT, requestId: "request-0003", ok: true, onePassword: { token: TOKEN, grants: { v1: ["pepper"] }, itemGrants: { "v1:i1": [] } } },
{ type: LOGIN_HANDOFF_RESULT, requestId: "request-0004", ok: false, error: "This login is no longer saved on this computer." },
]);
});
@@ -62,7 +63,7 @@ describe("the private login handoff to the desktop's main process", () => {
expect(posted).toEqual([
{ type: LOGIN_HANDOFF_RESULT, requestId: "request-0101", ok: false, error: ONE_PASSWORD_DEAD_HERE },
{ type: LOGIN_HANDOFF_RESULT, requestId: "request-0102", ok: false, error: ONE_PASSWORD_DEAD_HERE },
- { type: LOGIN_HANDOFF_RESULT, requestId: "request-0103", ok: true, onePassword: { token: TOKEN, grants: {} } },
+ { type: LOGIN_HANDOFF_RESULT, requestId: "request-0103", ok: true, onePassword: { token: TOKEN, grants: {}, itemGrants: {} } },
]);
expect(JSON.stringify(posted.slice(0, 2))).not.toContain(TOKEN);
});
diff --git a/server/login-handoff.ts b/server/login-handoff.ts
index 0f538f8d99..978ee013b6 100644
--- a/server/login-handoff.ts
+++ b/server/login-handoff.ts
@@ -47,7 +47,7 @@ export interface HandedSecret {
}
export type LoginHandoffAnswer =
- | { ok: true; onePassword: { token: string; grants: Record<string, LoginBots> } }
+ | { ok: true; onePassword: { token: string; grants: Record<string, LoginBots>; itemGrants: Record<string, LoginBots> } }
| { ok: true; login: HandedLogin }
| { ok: true; secret: HandedSecret }
| { ok: true; secrets: Record<string, string> }
@@ -85,7 +85,7 @@ function parse(raw: unknown): { requestId: string; what: Ask } | null {
return null;
}
-type HandoffStore = Pick<VaultStore, "changes" | "get" | "secret" | "listSecrets" | "onePasswordToken" | "onePasswordGrants">;
+type HandoffStore = Pick<VaultStore, "changes" | "get" | "secret" | "listSecrets" | "onePasswordToken" | "onePasswordGrants" | "onePasswordItemGrants">;
/** This computer's own 1Password problem, from its last read of the vaults (OnePasswordLogins.status().error). */
type OnePasswordProblem = () => string | undefined;
@@ -98,7 +98,7 @@ export function answerLoginHandoff(store: HandoffStore, what: Exclude<LoginHando
// 1Password itself refused this token here: My Cloud would only refuse it too, in words meant for its own page.
const problem = onePasswordProblem();
if (problem === ONE_PASSWORD_REFUSED || problem === ONE_PASSWORD_MALFORMED) return { ok: false, error: ONE_PASSWORD_DEAD_HERE };
- return { ok: true, onePassword: { token, grants: store.onePasswordGrants() } };
+ return { ok: true, onePassword: { token, grants: store.onePasswordGrants(), itemGrants: store.onePasswordItemGrants() } };
}
if (what.kind === "secret") {
const secret = store.secret(what.id);
diff --git a/server/onepassword.test.ts b/server/onepassword.test.ts
index a191bfa40c..f300c96fec 100644
--- a/server/onepassword.test.ts
+++ b/server/onepassword.test.ts
@@ -17,7 +17,7 @@ const DEPLOY = "fake-deploy-Passw0rd";
const NOTE = "fake-note-text-456";
const ACME_SECRET = "fake-acme-client-secret-789";
-function setup(options: { token?: string | null; fail?: () => Error | null; now?: () => number; grants?: Record<string, LoginBots> } = {}) {
+function setup(options: { token?: string | null; fail?: () => Error | null; now?: () => number; grants?: Record<string, LoginBots>; itemGrants?: Record<string, LoginBots> } = {}) {
const { sdk, calls } = fakeOnePasswordSdk({
token: TOKEN,
fail: options.fail,
@@ -42,7 +42,8 @@ function setup(options: { token?: string | null; fail?: () => Error | null; now?
});
let token: string | null = options.token === undefined ? TOKEN : options.token;
const grants = options.grants ?? {};
- const source = new OnePasswordLogins({ token: () => token, grants: () => grants, connect: (value) => sdkOnePasswordClient(sdk, value, "9.9.9"), now: options.now });
+ const itemGrants = options.itemGrants ?? {};
+ const source = new OnePasswordLogins({ token: () => token, grants: () => grants, itemGrants: () => itemGrants, connect: (value) => sdkOnePasswordClient(sdk, value, "9.9.9"), now: options.now });
return { source, calls, setToken: (value: string | null) => { token = value; } };
}
@@ -120,6 +121,34 @@ describe("1Password logins", () => {
expect(source.hasVault("v9")).toBe(false);
});
+ it("lets one item have its own bots ahead of its vault's, for logins and secrets alike", async () => {
+ // The vault is closed to every bot; only the picked items are opened, each to its own bots.
+ const { source } = setup({ grants: { v1: [] }, itemGrants: { "v1:i1": ["pepper"], "v1:i6": ["quill"], "v2:f1": [] } });
+ await source.refresh();
+ expect(linkedSites(source, "pepper").map((login) => login.site)).toEqual(["example.com"]);
+ expect(linkedCandidates(source, "accounts.example.com", "pepper").map((candidate) => candidate.username)).toEqual(["[email protected]"]);
+ expect(linkedCandidates(source, "accounts.example.com", "quill")).toEqual([]);
+ // Another item in the same vault still follows the closed vault.
+ expect(linkedCandidates(source, "crm.example.org", "pepper")).toEqual([]);
+ // An item can be narrowed inside a vault every bot may use.
+ expect(linkedCandidates(source, "bank.example.net", "pepper")).toEqual([]);
+ expect(findLinkedSecret([source], "Stripe secret key", "quill")).toMatchObject({ secret: { id: "1password:v1:i6" } });
+ expect(findLinkedSecret([source], "Stripe secret key", "pepper")).toBeNull();
+ expect(findLinkedSecret([source], "Deploy", "quill")).toBeNull();
+ const rows = source.list();
+ expect(rows.map((row) => [row.site, row.bots, row.onePassword])).toEqual([
+ ["example.com", ["pepper"], { item: "v1:i1", ownBots: true }],
+ ["example.net", [], { item: "v2:f1", ownBots: true }],
+ ["example.org", [], { item: "v1:i2", ownBots: false }],
+ ]);
+ expect(linkedSecrets(source).map((secret) => [secret.name, secret.onePassword])).toContainEqual(["Deploy", { item: "v1:i7", ownBots: false }]);
+ expect(source.hasItem("v1:i1")).toBe(true);
+ expect(source.hasItem("v1:i6")).toBe(true);
+ expect(source.hasItem("v1:i3")).toBe(false);
+ expect(source.hasItem("v9:i1")).toBe(false);
+ expect(JSON.stringify(source.items())).not.toContain(VAULT_PASSWORD);
+ });
+
it("is filled through the same path as a saved login: same origin rule, same TOTP, nothing back to the bot", async () => {
const { source } = setup();
await source.refresh();
diff --git a/server/onepassword.ts b/server/onepassword.ts
index a5cb041606..e3df05373a 100644
--- a/server/onepassword.ts
+++ b/server/onepassword.ts
@@ -2,7 +2,7 @@
// The official SDK (@1password/sdk, MIT) is a CommonJS wrapper over a 14 MB
// WebAssembly core it reads from beside itself, so it is never bundled: it is
// required on first use, and only when a token exists.
-import type { LoginBots, LoginPlace, LoginSummary, OnePasswordStatus, OnePasswordVault } from "../shared/logins.ts";
+import type { LoginBots, LoginPlace, LoginSummary, OnePasswordItemRef, OnePasswordStatus, OnePasswordVault } from "../shared/logins.ts";
import { loginSite, normalizeLoginHost } from "../shared/logins.ts";
import { parseTotpKey } from "./totp.ts";
import type { LinkedItem, LinkedValue, VaultProvider } from "./vault/providers.ts";
@@ -119,6 +119,11 @@ const MAX_ITEMS = 500;
const FIELDS_BATCH = 50;
const STALE_MS = 10 * 60_000;
+/** How an item's own bots are stored: `<vault id>:<item id>`. */
+export function onePasswordItemKey(vaultId: string, itemId: string): string {
+ return `${vaultId}:${itemId}`;
+}
+
export function isOnePasswordLoginId(id: string): boolean {
return id.startsWith(ID_PREFIX);
}
@@ -153,6 +158,7 @@ export class OnePasswordLogins implements VaultProvider {
private readonly token: () => string | null;
private readonly connect: (token: string) => Promise<OnePasswordClient>;
private readonly grants: () => Record<string, LoginBots>;
+ private readonly itemGrants: () => Record<string, LoginBots>;
private readonly now: () => number;
private client: { token: string; client: OnePasswordClient } | null = null;
private entries: Entry[] = [];
@@ -164,10 +170,14 @@ export class OnePasswordLogins implements VaultProvider {
private refreshing: Promise<OnePasswordStatus> | null = null;
private readonly lastUsed = new Map<string, number>();
- constructor(options: { token: () => string | null; connect: (token: string) => Promise<OnePasswordClient>; grants?: () => Record<string, LoginBots>; now?: () => number }) {
+ constructor(options: {
+ token: () => string | null; connect: (token: string) => Promise<OnePasswordClient>; grants?: () => Record<string, LoginBots>;
+ itemGrants?: () => Record<string, LoginBots>; now?: () => number;
+ }) {
this.token = options.token;
this.connect = options.connect;
this.grants = options.grants ?? (() => ({}));
+ this.itemGrants = options.itemGrants ?? (() => ({}));
this.now = options.now ?? Date.now;
}
@@ -175,6 +185,20 @@ export class OnePasswordLogins implements VaultProvider {
return this.grants()[vaultId] ?? "all";
}
+ /** An item's own bots when it has them, else its vault's. */
+ private itemAccess(entry: { vaultId: string; itemId: string }): { bots: LoginBots; onePassword: OnePasswordItemRef } {
+ const item = onePasswordItemKey(entry.vaultId, entry.itemId);
+ const own = this.itemGrants()[item];
+ return { bots: own ?? this.botsFor(entry.vaultId), onePassword: { item, ownBots: own !== undefined } };
+ }
+
+ /** Whether the token reads this item (`<vault id>:<item id>`) as a login or a secret. */
+ hasItem(item: string): boolean {
+ if (!this.token()) return false;
+ const reads = (entry: { vaultId: string; itemId: string }) => onePasswordItemKey(entry.vaultId, entry.itemId) === item;
+ return this.entries.some(reads) || this.secrets.some(reads);
+ }
+
private connected(): OnePasswordStatus {
const vaults: OnePasswordVault[] = this.vaults.map((vault) => ({ ...vault, bots: this.botsFor(vault.id) }));
return { connected: true, vaults, items: this.itemCount, ...(this.error ? { error: this.error } : {}) };
@@ -279,10 +303,10 @@ export class OnePasswordLogins implements VaultProvider {
return [
...this.entries.map((entry): LinkedItem => ({
kind: "login", id: entry.id, site: entry.site, hosts: [...entry.hosts], exactHost: false, username: entry.username, hasTotp: entry.hasTotp,
- source: "1password", bots: this.botsFor(entry.vaultId), createdAt: 0, ...this.lastUsedOf(entry.itemId),
+ source: "1password", ...this.itemAccess(entry), createdAt: 0, ...this.lastUsedOf(entry.itemId),
})),
...this.secrets.map((entry): LinkedItem => ({
- kind: "secret", id: entry.id, name: entry.name, fields: [...entry.fields], source: "linked", provider: this.id, bots: this.botsFor(entry.vaultId),
+ kind: "secret", id: entry.id, name: entry.name, fields: [...entry.fields], source: "linked", provider: this.id, ...this.itemAccess(entry),
readOnly: true, ...this.lastUsedOf(entry.itemId),
})),
];
diff --git a/server/routes/cloud-send.test.ts b/server/routes/cloud-send.test.ts
index 8e9f59c93b..ef28f56926 100644
--- a/server/routes/cloud-send.test.ts
+++ b/server/routes/cloud-send.test.ts
@@ -6,7 +6,7 @@ const handler = (messages: Array<{ role: string; text?: string }>, hasMore = fal
bots: () => [{ id: "bot-00000001", threadId: "thread-0001", name: "Yuki", title: "", description: "", soul: "", tasks: [{ threadId: "thread-0001" }] } as never],
messagesTail: () => ({ messages, hasMore }),
skills: () => [],
- logins: { listSecrets: () => [], secret: () => null, changes: () => [], get: () => null, onePasswordConnectedAt: () => null, onePasswordGrants: () => ({}), onePasswordToken: () => null },
+ logins: { listSecrets: () => [], secret: () => null, changes: () => [], get: () => null, onePasswordConnectedAt: () => null, onePasswordGrants: () => ({}), onePasswordItemGrants: () => ({}), onePasswordToken: () => null },
config: () => ({}),
});
async function bots(route: ReturnType<typeof createCloudSendRoutes>): Promise<string[]> {
@@ -38,7 +38,7 @@ describe("what a move asks of a server", () => {
appVersion: "0.1.120",
bots: () => [{ id: "bot-00000001", threadId: "thread-0001", name: "Yuki", soul: "Be brief." } as never, { id: "bot-00000002", threadId: "thread-0002", name: "Kit", soul: "Plan." } as never],
messagesTail: () => ({ messages: [], hasMore: false }), skills: () => [],
- logins: { listSecrets: () => [], secret: () => null, changes: () => [stored], get: (id) => (id === "l1" ? stored as never : null), onePasswordConnectedAt: () => null, onePasswordGrants: () => ({}), onePasswordToken: () => null },
+ logins: { listSecrets: () => [], secret: () => null, changes: () => [stored], get: (id) => (id === "l1" ? stored as never : null), onePasswordConnectedAt: () => null, onePasswordGrants: () => ({}), onePasswordItemGrants: () => ({}), onePasswordToken: () => null },
config: () => ({}), cloudHome, connectionFingerprints: () => ({ "key:openrouter": "f".repeat(64) }),
});
@@ -52,7 +52,7 @@ describe("what a move asks of a server", () => {
const routine = { id: "r1", name: "Morning", prompt: "Report.", target: "bot", botId: "bot-00000001", runOn: "maus", enabled: true, schedule: { type: "daily", time: "09:00", weekdays: [1] },
durationMinutes: 15, nextRunAt: null, createdAt: 1, updatedAt: 1 };
const route = createCloudSendRoutes({ appVersion: "0.1.120", bots: () => [{ id: "bot-00000001", threadId: "thread-0001", name: "Yuki", soul: "Be brief.", pinned: true } as never],
- messagesTail: () => ({ messages: [], hasMore: false }), skills: () => [], logins: { listSecrets: () => [], secret: () => null, changes: () => [], get: () => null, onePasswordConnectedAt: () => null, onePasswordGrants: () => ({}), onePasswordToken: () => null },
+ messagesTail: () => ({ messages: [], hasMore: false }), skills: () => [], logins: { listSecrets: () => [], secret: () => null, changes: () => [], get: () => null, onePasswordConnectedAt: () => null, onePasswordGrants: () => ({}), onePasswordItemGrants: () => ({}), onePasswordToken: () => null },
config: () => ({}), move: { dataDir: "/data", store: { bots: [], bot: () => undefined } as never, routines: () => ({ listRoutines: () => [routine], listRuns: () => [], adopt() {} }) as never,
calls: () => null, webhooks: () => null, appEvents: () => null, claudeCodeSkills: () => [], instanceExists: () => true, owner: () => null,
teamMemory: { list: () => [], adopt: () => 0 } as never, aboutMe: () => "", saveAboutMe() {} } });
diff --git a/server/routes/cloud-send.ts b/server/routes/cloud-send.ts
index c418f7c653..64c1033848 100644
--- a/server/routes/cloud-send.ts
+++ b/server/routes/cloud-send.ts
@@ -32,7 +32,7 @@ import { PASS, type RouteHandler } from "./table.ts";
export interface CloudSendRouteDeps extends Pick<CloudSendSources, "appVersion" | "bots" | "skills"> {
messagesTail(threadId: string, limit: number): { messages: ReadonlyArray<{ role: string; text?: string }>; hasMore: boolean };
- logins: Pick<VaultStore, "changes" | "get" | "listSecrets" | "secret" | "onePasswordConnectedAt" | "onePasswordGrants" | "onePasswordToken">;
+ logins: Pick<VaultStore, "changes" | "get" | "listSecrets" | "secret" | "onePasswordConnectedAt" | "onePasswordGrants" | "onePasswordItemGrants" | "onePasswordToken">;
config(): Pick<AppConfig, "profile" | "language">;
lineLanguage?: LineLanguage;
chats?: CloudSendChatsDeps;
@@ -72,7 +72,7 @@ export function createCloudSendRoutes(deps: CloudSendRouteDeps): RouteHandler {
secrets: () => deps.logins.listSecrets(TEAM_READER),
onePassword: () => {
const connectedAt = deps.logins.onePasswordConnectedAt();
- return connectedAt === null ? null : { connectedAt, grants: deps.logins.onePasswordGrants() };
+ return connectedAt === null ? null : { connectedAt, grants: deps.logins.onePasswordGrants(), itemGrants: deps.logins.onePasswordItemGrants() };
},
settings: () => { const { profile, language } = deps.config(); return { profile, language }; },
...(deps.move ? { move: { items: (bots: ReadonlySet<string>, only?: BotRecord) => moveItems(deps.move!, bots, only), botParts: (bot: BotRecord) => moveBotParts(bot, partHash) } } : {}),
diff --git a/server/routes/logins.test.ts b/server/routes/logins.test.ts
index b5c22c79f2..685041d21c 100644
--- a/server/routes/logins.test.ts
+++ b/server/routes/logins.test.ts
@@ -34,7 +34,8 @@ async function serve() {
const { sdk } = fakeOnePasswordSdk({ token: TOKEN, vaults: { v1: { title: "Shared with OMB", items: [
{ id: "i1", title: "Example", urls: ["https://vault.example.com"], username: "vault-user", password: VAULT_PASSWORD },
] } } });
- const onePassword = new OnePasswordLogins({ token: () => store.onePasswordToken(), grants: () => store.onePasswordGrants(), connect: (token) => sdkOnePasswordClient(sdk, token, "0.0.0") });
+ const onePassword = new OnePasswordLogins({ token: () => store.onePasswordToken(), grants: () => store.onePasswordGrants(), itemGrants: () => store.onePasswordItemGrants(),
+ connect: (token) => sdkOnePasswordClient(sdk, token, "0.0.0") });
const logins = new BotLogins(store, onePassword);
const routes = [createLoginRoutes(logins.routes((id) => ["pepper", "quill"].includes(id)))];
const answers: string[] = [];
@@ -60,6 +61,7 @@ describe("Settings → Logins routes", () => {
for (const method of ["GET", "POST"]) expect(requiredScope(method, "/api/logins")).toBe("admin");
for (const method of ["PATCH", "DELETE"]) expect(requiredScope(method, "/api/logins/abc")).toBe("admin");
expect(requiredScope("PATCH", "/api/logins/1password/vaults/v1")).toBe("admin");
+ expect(requiredScope("PATCH", "/api/logins/1password/items/v1/i1")).toBe("admin");
});
it("add, list, change and delete a login, and never return its password or 2FA key", async () => {
@@ -151,6 +153,32 @@ describe("Settings → Logins routes", () => {
expect((await logins.candidates("pepper", "vault.example.com")).map((login) => login.username)).toEqual(["vault-user"]);
});
+ it("keeps one 1Password item to its own bots ahead of its vault's, and hands it back on null", async () => {
+ const { store, logins, call, answers } = await serve();
+ await call("POST", "/api/logins/1password", { token: TOKEN });
+ await call("PATCH", "/api/logins/1password/vaults/v1", { bots: [] });
+ expect(await logins.candidates("pepper", "vault.example.com")).toEqual([]);
+ const opened = await call("PATCH", "/api/logins/1password/items/v1/i1", { bots: ["pepper"] });
+ expect(opened.status).toBe(200);
+ expect(opened.body.logins[0]).toMatchObject({ bots: ["pepper"], onePassword: { item: "v1:i1", ownBots: true } });
+ expect(store.onePasswordItemGrants()).toEqual({ "v1:i1": ["pepper"] });
+ expect((await logins.candidates("pepper", "vault.example.com")).map((login) => login.username)).toEqual(["vault-user"]);
+ expect(await logins.candidates("quill", "vault.example.com")).toEqual([]);
+ // The vault's own choice does not reopen or close an item with bots of its own.
+ await call("PATCH", "/api/logins/1password/vaults/v1", { bots: "all" });
+ expect(await logins.candidates("quill", "vault.example.com")).toEqual([]);
+ expect((await call("PATCH", "/api/logins/1password/items/v1/i1", { bots: ["nobody"] })).body).toEqual({ error: LOGIN_ERRORS.bots });
+ expect((await call("PATCH", "/api/logins/1password/items/v1/i1", {})).status).toBe(400);
+ expect((await call("PATCH", "/api/logins/1password/items/v1/i9", { bots: "all" })).status).toBe(404);
+ expect((await call("PATCH", "/api/logins/1password/items/v9/i1", { bots: "all" })).status).toBe(404);
+ expect(store.onePasswordItemGrants()).toEqual({ "v1:i1": ["pepper"] });
+ const back = await call("PATCH", "/api/logins/1password/items/v1/i1", { bots: null });
+ expect(back.body.logins[0]).toMatchObject({ bots: "all", onePassword: { item: "v1:i1", ownBots: false } });
+ expect(store.onePasswordItemGrants()).toEqual({});
+ expect((await logins.candidates("quill", "vault.example.com")).map((login) => login.username)).toEqual(["vault-user"]);
+ for (const answer of answers) { expect(answer).not.toContain(VAULT_PASSWORD); expect(answer).not.toContain(TOKEN); }
+ });
+
it("takes changes as JSON only, so another page's form cannot post one", async () => {
const { call } = await serve();
expect((await call("POST", "/api/logins", { site: "example.com", password: PASSWORD }, "text/plain")).status).toBe(415);
diff --git a/server/routes/logins.ts b/server/routes/logins.ts
index 3cfd004bb8..8d6cef0402 100644
--- a/server/routes/logins.ts
+++ b/server/routes/logins.ts
@@ -18,11 +18,14 @@ export interface LoginRouteDeps {
disconnect(): OnePasswordStatus;
/** Null for a vault the token does not read. */
grant(vaultId: string, bots: LoginBots): OnePasswordStatus | null;
+ /** Bots for one item (`<vault id>:<item id>`) ahead of its vault's; null hands it back. False for an item the token does not read. */
+ grantItem(item: string, bots: LoginBots | null): boolean;
};
}
const ONE_PASSWORD = "/api/logins/1password";
const VAULT = /^\/api\/logins\/1password\/vaults\/([\w-]{1,128})$/u;
+const ITEM = /^\/api\/logins\/1password\/items\/([\w-]{1,128})\/([\w-]{1,128})$/u;
const ID = /^[\w-]{1,128}$/u;
@@ -100,6 +103,15 @@ export function createLoginRoutes(deps: LoginRouteDeps): RouteHandler {
const status = deps.onePassword.grant(vault[1]!, bots.value);
return status ? json(res, 200, { onePassword: status }) : json(res, 404, { error: "no such vault" });
}
+ const item = ITEM.exec(path);
+ if (item && method === "PATCH") {
+ const body = await readBody(req, 16_384);
+ const value = body && typeof body === "object" ? body.bots : undefined;
+ const bots = value === null ? { ok: true as const, value: null } : parseBots(value, deps.botExists);
+ if (!bots.ok || bots.value === undefined) return json(res, 400, { error: bots.ok ? LOGIN_ERRORS.bots : bots.error });
+ if (!deps.onePassword.grantItem(`${item[1]!}:${item[2]!}`, bots.value)) return json(res, 404, { error: "no such item" });
+ return json(res, 200, { logins: deps.onePassword.list(), onePassword: deps.onePassword.status() });
+ }
if (path === ONE_PASSWORD || path.startsWith(`${ONE_PASSWORD}/`)) return json(res, 405, { error: "method not allowed" });
if (path === "/api/logins" && method === "POST") {
const body = await readBody(req, 16_384);
diff --git a/server/routes/vault.test.ts b/server/routes/vault.test.ts
index b06aaba74a..ef3a72a013 100644
--- a/server/routes/vault.test.ts
+++ b/server/routes/vault.test.ts
@@ -120,7 +120,8 @@ describe("the Vault routes", () => {
await call("POST", "/api/vault/secrets", { name: "Stripe secret key", value: VALUE });
const listed = await call("GET", "/api/vault");
expect(listed.body.secrets.map((secret: { name: string; source: string }) => [secret.name, secret.source])).toEqual([["Stripe secret key", "settings"], ["Notion token", "linked"]]);
- expect(listed.body.secrets[1]).toEqual({ id: "1password:v1:n1", name: "Notion token", fields: [], source: "linked", provider: "1password", bots: "all", readOnly: true });
+ expect(listed.body.secrets[1]).toEqual({ id: "1password:v1:n1", name: "Notion token", fields: [], source: "linked", provider: "1password", bots: "all", readOnly: true,
+ onePassword: { item: "v1:n1", ownBots: false } });
expect((await call("DELETE", "/api/vault/secrets/1password:v1:n1")).status).toBe(404);
expect((await call("PATCH", "/api/vault/secrets/1password:v1:n1", { name: "x" })).status).toBe(404);
for (const answer of answers) expect(answer).not.toContain(LINKED_VALUE);
diff --git a/server/vault-store.test.ts b/server/vault-store.test.ts
index da7a5d58c8..a16d043759 100644
--- a/server/vault-store.test.ts
+++ b/server/vault-store.test.ts
@@ -156,6 +156,14 @@ describe("the saved logins store", () => {
expect(new VaultStore({ dataDir: dir }).onePasswordGrants()).toEqual({ v1: ["pepper"], v2: [] });
store.setOnePasswordGrant("v1", "all");
expect(new VaultStore({ dataDir: dir }).onePasswordGrants()).toEqual({ v2: [] });
+ expect(store.onePasswordItemGrants()).toEqual({});
+ store.setOnePasswordItemGrant("v2:i1", ["pepper"]);
+ store.setOnePasswordItemGrant("v2:i2", "all");
+ expect(new VaultStore({ dataDir: dir }).onePasswordItemGrants()).toEqual({ "v2:i1": ["pepper"], "v2:i2": "all" });
+ store.setOnePasswordItemGrant("v2:i1", null);
+ store.setOnePasswordItemGrant("v2:i2", null);
+ expect(new VaultStore({ dataDir: dir }).onePasswordItemGrants()).toEqual({});
+ expect(new VaultStore({ dataDir: dir }).onePasswordGrants()).toEqual({ v2: [] });
});
});
diff --git a/server/vault-store.ts b/server/vault-store.ts
index c8af7394c1..726ce12cb1 100644
--- a/server/vault-store.ts
+++ b/server/vault-store.ts
@@ -67,6 +67,8 @@ const fileSchema = z.object({
onePassword: z.object({ token: z.string().min(1), connectedAt: z.number() }).optional(),
/** Vault id → the bots that may use its logins; a vault not named here is for every bot. Kept across reconnects. */
onePasswordGrants: z.record(z.string(), botsSchema).optional(),
+ /** 1Password item (`<vault id>:<item id>`) → the bots that may use it, ahead of its vault's choice. Kept across reconnects. */
+ onePasswordItemGrants: z.record(z.string(), botsSchema).optional(),
/** Security: MCP server name → the items whose `vault:<id>` that server may read. Written only when a bot's secretRef
* is redeemed into the server (or a move carries the server), so a pointer planted in config.json reads nothing. */
mcpKeys: z.record(z.string(), z.array(z.string().min(1))).optional(),
@@ -495,6 +497,19 @@ export class VaultStore {
this.write(Object.keys(grants).length ? { ...rest, onePasswordGrants: grants } : rest);
}
+ onePasswordItemGrants(): Record<string, LoginBots> {
+ return this.read().onePasswordItemGrants ?? {};
+ }
+
+ /** null hands the item back to its vault's choice. */
+ setOnePasswordItemGrant(key: string, bots: LoginBots | null): void {
+ const data = this.read();
+ const { [key]: _previous, ...others } = data.onePasswordItemGrants ?? {};
+ const grants = bots === null ? others : { ...others, [key]: bots };
+ const { onePasswordItemGrants: _grants, ...rest } = data;
+ this.write(Object.keys(grants).length ? { ...rest, onePasswordItemGrants: grants } : rest);
+ }
+
secretValues(): string[] {
const data = this.read();
return [
diff --git a/shared/logins.ts b/shared/logins.ts
index 41fa208292..d6a199446d 100644
--- a/shared/logins.ts
+++ b/shared/logins.ts
@@ -37,6 +37,14 @@ export interface LoginSummary extends LoginPlace {
bots: LoginBots;
createdAt: number;
lastUsedAt?: number;
+ /** A 1Password login's item, and whether its bots are its own choice rather than its vault's. */
+ onePassword?: OnePasswordItemRef;
+}
+
+/** One 1Password item: `<vault id>:<item id>`, and whether it has bots of its own instead of its vault's. */
+export interface OnePasswordItemRef {
+ item: string;
+ ownBots: boolean;
}
/** A 1Password vault the service account reads, and the bots that may use its
diff --git a/shared/vault.ts b/shared/vault.ts
index c9d6e98e56..043cf3c5d8 100644
--- a/shared/vault.ts
+++ b/shared/vault.ts
@@ -5,7 +5,7 @@
* see a saved secret as a list row, never its value.
*/
import { CUSTOM_SECRET_LABEL_MAX } from "./credential-request.ts";
-import type { LoginBots } from "./logins.ts";
+import type { LoginBots, OnePasswordItemRef } from "./logins.ts";
/** One saved secret as Settings shows it. There is no value field, and no
* route ever returns one: a saved value is only ever replaced. */
@@ -44,6 +44,8 @@ export interface LinkedSecret {
bots: LoginBots;
readOnly: true;
lastUsedAt?: number;
+ /** From 1Password: its item, and whether its bots are its own choice rather than its vault's. */
+ onePassword?: OnePasswordItemRef;
}
/** A saved item a secure card offers under "Use a saved one": its name only. Picking it lets the asking bot use it. */
diff --git a/src/components/VaultSettings.test.ts b/src/components/VaultSettings.test.ts
index 561bfec73f..d7633ccc97 100644
--- a/src/components/VaultSettings.test.ts
+++ b/src/components/VaultSettings.test.ts
@@ -187,6 +187,39 @@ describe("Settings → Vault: logins", () => {
expect(host.querySelector('[data-login-row="example.com"]')!.textContent).toContain("From 1Password · Quill");
});
+ it("keeps one 1Password item to its own bots ahead of its vault's, and hands it back to the vault's choice", async () => {
+ const on = { connected: true, vaults: [{ id: "v1", title: "Shared with OMB", items: 1, bots: "all" }], items: 1 };
+ const follows = { ...VAULT_LOGIN, onePassword: { item: "v1:i1", ownBots: false } };
+ const own = { ...VAULT_LOGIN, bots: ["quill"], onePassword: { item: "v1:i1", ownBots: true } };
+ fixture.api
+ .mockResolvedValueOnce({ logins: [follows], onePassword: on })
+ .mockResolvedValueOnce({ logins: [own], onePassword: on })
+ .mockResolvedValueOnce({ logins: [own], onePassword: on })
+ .mockResolvedValueOnce({ logins: [follows], onePassword: on })
+ .mockResolvedValueOnce({ logins: [follows], onePassword: on });
+ await render();
+ const row = () => host.querySelector('[data-login-row="example.com"]')!;
+ const editor = () => host.querySelector('[data-onepassword-item="v1:i1"]')!;
+ const flush = () => act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)); });
+ expect(row().textContent).toContain("From 1Password · All bots (its vault's choice)");
+ await click("Change who can use example.com");
+ expect(host.querySelector("[data-login-form]"), "a 1Password item's password is not changed here").toBeNull();
+ expect(button("Use the vault's choice"), "it already follows its vault").toBeUndefined();
+ await act(async () => { [...editor().querySelectorAll<HTMLInputElement>('input[type="radio"]')][1]!.click(); });
+ await act(async () => { [...editor().querySelectorAll<HTMLInputElement>('input[type="checkbox"]')][1]!.click(); });
+ await click("Save changes");
+ await flush();
+ expect(fixture.api).toHaveBeenNthCalledWith(2, "/api/logins/1password/items/v1/i1", { method: "PATCH", body: JSON.stringify({ bots: ["quill"] }) });
+ expect(row().textContent).toContain("From 1Password · Quill");
+ expect(row().textContent).not.toContain("vault's choice");
+ await click("Change who can use example.com");
+ await click("Use the vault's choice");
+ await flush();
+ expect(fixture.api).toHaveBeenNthCalledWith(4, "/api/logins/1password/items/v1/i1", { method: "PATCH", body: JSON.stringify({ bots: null }) });
+ expect(row().textContent).toContain("From 1Password · All bots (its vault's choice)");
+ expect(host.querySelector("[data-onepassword-item]")).toBeNull();
+ });
+
it("says why 1Password refused a token", async () => {
fixture.api.mockResolvedValueOnce({ logins: [], onePassword: OFF }).mockRejectedValueOnce(new Error("1Password did not accept the token."));
await render();
diff --git a/src/components/VaultSettings.tsx b/src/components/VaultSettings.tsx
index a68451b20c..4d2b7d1843 100644
--- a/src/components/VaultSettings.tsx
+++ b/src/components/VaultSettings.tsx
@@ -1,11 +1,11 @@
import { useEffect, useState, type FormEvent } from "react";
import { ChevronDown, KeyRound, Loader2, LockKeyhole, ShieldCheck, Trash2 } from "lucide-react";
-import { loginHeldBackFor, type LoginBots, type LoginSummary, type OnePasswordStatus, type OnePasswordVault } from "../../shared/logins";
+import { loginHeldBackFor, type LoginBots, type LoginSummary, type OnePasswordItemRef, type OnePasswordStatus, type OnePasswordVault } from "../../shared/logins";
import type { LinkedSecret, VaultSecret } from "../../shared/vault";
import { t } from "@/lib/i18n";
import { productName } from "@/lib/brand";
-import { addLogin, changeLogin, connectOnePassword, deleteLogin, disconnectOnePassword, grantVault, refreshOnePassword } from "@/lib/logins";
+import { addLogin, changeLogin, connectOnePassword, deleteLogin, disconnectOnePassword, grantOnePasswordItem, grantVault, refreshOnePassword } from "@/lib/logins";
import { relativeTime } from "@/lib/memory";
import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";
import { deleteSecret, listVault } from "@/lib/vault";
@@ -125,6 +125,17 @@ export function VaultSettings() {
</button>
</div>
);
+ /** A 1Password item without bots of its own follows its vault: say so, since changing the vault changes it. */
+ const whoLine = (value: LoginBots, item?: OnePasswordItemRef) =>
+ item && !item.ownBots ? t("settings.logins.onePassword.vaultChoice", { who: botNames(value) }) : botNames(value);
+ const itemButton = (id: string, name: string) => !member && editing !== id && (
+ <button type="button" className={ROW_BUTTON} disabled={busy} onClick={() => startEdit(id)}
+ aria-label={t("settings.logins.onePassword.changeItem", { name })}>{t("settings.logins.change")}</button>
+ );
+ const itemEditor = (item: OnePasswordItemRef, value: LoginBots) => (
+ <OnePasswordItemAccess item={item} value={value} bots={bots} onCancel={() => setEditing(null)}
+ onSaved={async () => { setEditing(null); await load(); }} />
+ );
const rows = rowsOf(logins ?? [], secrets, filter, query);
const empty = logins !== null && logins.length === 0 && secrets.length === 0;
@@ -144,7 +155,7 @@ export function VaultSettings() {
<div dir="auto" className="truncate text-[12px] text-ink-secondary">{login.username || t("settings.logins.noUsername")}</div>
{signInHostsLine(login) && <div dir="ltr" className="truncate text-[12px] text-ink-tertiary" data-login-hosts>{signInHostsLine(login)}</div>}
<div className="mt-0.5 text-[12px] leading-snug text-ink-tertiary">
- {[t(SOURCE_KEYS[login.source]), botNames(login.bots), used(login.lastUsedAt)].join(" · ")}
+ {[t(SOURCE_KEYS[login.source]), whoLine(login.bots, login.onePassword), used(login.lastUsedAt)].join(" · ")}
</div>
{loginHeldBackFor(login, state.bots).length > 0 && (
<div className="mt-0.5 text-[12px] leading-snug text-warning" data-login-held-back>
@@ -153,8 +164,10 @@ export function VaultSettings() {
)}
</div>
{login.source !== "1password" && rowButtons(login.id, "login", login.site, () => startEdit(login.id, login))}
+ {login.onePassword && itemButton(login.id, login.site)}
</div>
- {editing === login.id && (
+ {editing === login.id && login.onePassword && itemEditor(login.onePassword, login.bots)}
+ {editing === login.id && !login.onePassword && (
<div className="ms-6 rounded-lg bg-inset/60 p-3">
<LoginForm username={false} replacing submitLabel={t("settings.logins.saveChange")} autoFocus
onCancel={() => setEditing(null)}
@@ -185,11 +198,13 @@ export function VaultSettings() {
<div className="min-w-0 flex-1">
<div dir="auto" className="truncate text-[13px] font-medium text-ink" title={secret.name}>{secret.name}</div>
<div className="mt-0.5 text-[12px] leading-snug text-ink-tertiary">
- {[t(SOURCE_KEYS[secret.source]), botNames(secret.bots), used(secret.lastUsedAt)].join(" · ")}
+ {[t(SOURCE_KEYS[secret.source]), whoLine(secret.bots, secret.source === "linked" ? secret.onePassword : undefined), used(secret.lastUsedAt)].join(" · ")}
</div>
</div>
{secret.source !== "linked" && rowButtons(secret.id, "secret", secret.name, () => startEdit(secret.id))}
+ {secret.source === "linked" && secret.onePassword && itemButton(secret.id, secret.name)}
</div>
+ {editing === secret.id && secret.source === "linked" && secret.onePassword && itemEditor(secret.onePassword, secret.bots)}
{editing === secret.id && secret.source !== "linked" && (
<div className="ms-6 rounded-lg bg-inset/60 p-3">
<SecretForm secret={secret} bots={bots} onCancel={() => setEditing(null)} onSaved={async () => { setEditing(null); await load(); }} />
@@ -285,6 +300,40 @@ function ExactHostChoice({ checked, onChange, label }: { checked: boolean; onCha
);
}
+/** Which bots may use one 1Password item, ahead of its vault's choice; "Use the vault's choice" hands it back. */
+function OnePasswordItemAccess({ item, value: initial, bots, onCancel, onSaved }: {
+ item: OnePasswordItemRef;
+ value: LoginBots;
+ bots: ReadonlyArray<{ id: string; name: string }>;
+ onCancel: () => void;
+ onSaved: () => Promise<void>;
+}) {
+ const [value, setValue] = useState<LoginBots>(initial);
+ const [busy, setBusy] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+ const save = async (next: LoginBots | null) => {
+ setBusy(true);
+ setError(null);
+ try { await grantOnePasswordItem(item.item, next); await onSaved(); }
+ catch (cause) { setError(cause instanceof Error && cause.message ? cause.message : t("settings.logins.onePassword.error")); }
+ finally { setBusy(false); }
+ };
+ return (
+ <div className="ms-6 flex flex-col gap-2 rounded-lg bg-inset/60 p-3" data-onepassword-item={item.item}>
+ <LoginBotPicker value={value} onChange={setValue} bots={bots} disabled={busy} />
+ <p className="text-[12px] leading-snug text-ink-tertiary">{t("settings.logins.onePassword.itemNote")}</p>
+ {error && <p role="alert" className="text-[12px] text-danger">{error}</p>}
+ <div className="flex flex-wrap justify-end gap-2">
+ {item.ownBots && (
+ <button type="button" className="ui-button ui-button-md" disabled={busy} onClick={() => void save(null)}>{t("settings.logins.onePassword.useVaultChoice")}</button>
+ )}
+ <button type="button" className="ui-button ui-button-md" disabled={busy} onClick={onCancel}>{t("logins.cancel")}</button>
+ <button type="button" className="ui-button ui-button-md ui-button-primary" disabled={busy} onClick={() => void save(value)}>{t("settings.logins.saveChange")}</button>
+ </div>
+ </div>
+ );
+}
+
function VaultAccess({ vault, bots, botNames, disabled, onChange }: {
vault: OnePasswordVault;
bots: ReadonlyArray<{ id: string; name: string }>;
diff --git a/src/lib/logins.ts b/src/lib/logins.ts
index e26d18371e..f10366bff2 100644
--- a/src/lib/logins.ts
+++ b/src/lib/logins.ts
@@ -53,6 +53,15 @@ export async function grantVault(vaultId: string, bots: LoginBots): Promise<OneP
})).onePassword;
}
+/** Bots for one 1Password item (`<vault id>:<item id>`) ahead of its vault's; null hands it back to the vault's choice. */
+export async function grantOnePasswordItem(item: string, bots: LoginBots | null): Promise<void> {
+ const [vaultId = "", itemId = ""] = item.split(":");
+ await api(`/api/logins/1password/items/${encodeURIComponent(vaultId)}/${encodeURIComponent(itemId)}`, {
+ method: "PATCH",
+ body: JSON.stringify({ bots }),
+ });
+}
+
export async function deleteLogin(id: string): Promise<void> {
await api(`/api/logins/${encodeURIComponent(id)}`, { method: "DELETE" });
}
diff --git a/src/locales/en.json b/src/locales/en.json
index bf963b7654..c41c715ed5 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -3846,6 +3846,10 @@
"settings.logins.onePassword.vaults": "1Password vaults",
"settings.logins.onePassword.vaultUse": "{count} logins · {who}",
"settings.logins.onePassword.changeVault": "Change who can use {vault}",
+ "settings.logins.onePassword.changeItem": "Change who can use {name}",
+ "settings.logins.onePassword.vaultChoice": "{who} (its vault's choice)",
+ "settings.logins.onePassword.itemNote": "This choice is for this 1Password item only, ahead of its vault's. It stays when the vault's choice changes.",
+ "settings.logins.onePassword.useVaultChoice": "Use the vault's choice",
"settings.logins.onePassword.error": "Couldn't reach 1Password. Check your internet connection and the token, then try again.",
"settings.logins.onePassword.note": "The token is encrypted on the computer {app} runs on and never shown again. 1Password logins appear in the list above, filled the same way, and are changed in 1Password. A vault is for every bot unless you choose bots for it.",
"settings.logins.cloudOwn": "These are the Cloud's own logins. Your computer's logins come here by themselves when the {app} app on that computer moves your bots here.",