Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c825306
feat(sidebar): new session from a group header, drag sessions into gr…
bk-agent-01 Nov 13, 2026
ce7f64f
feat(settings): reorganize BK Add-ons into Features, Connections, Thi…
bk-agent-01 Nov 13, 2026
8b70f4c
feat(toolyard): default to toolyard.beknown.live, T3_TOOLYARD_URL ove…
bk-agent-01 Nov 13, 2026
2bb4ce6
fix(bk): review fixes — reused drafts forget a group target, backgrou…
bk-agent-01 Nov 13, 2026
3e1c304
fix(bk): CI fixes — format, single Effect.provide, no refs in drag/ne…
bk-agent-01 Nov 13, 2026
aeea49c
fix(bk): lint — shorter header comments, inset focus ring, persist fo…
bk-agent-01 Nov 13, 2026
a432cab
Merge pull request #373 from iamtushar324/t3/abuja-bk-sidebar-setting…
bk-agent-01 Nov 13, 2026
b81e6dc
feat(server): every provider knows the Clerk sender's name, email and…
bk-agent-01 Nov 16, 2026
c7bbbb5
style(server): format the sender identity test import
bk-agent-01 Nov 16, 2026
47d4824
fix(server): identity per message, encoded profile values, steers and…
bk-agent-01 Nov 16, 2026
2651596
fix(server): Effect.fn for the identity wrapper; test type
bk-agent-01 Nov 16, 2026
db031bb
fix(server): identity on native Claude wakes, fail-closed Codex steer…
bk-agent-01 Nov 16, 2026
a7e1cff
style(server): quote style in the identity test
bk-agent-01 Nov 16, 2026
1fccbd1
fix(server): no identity in slash commands; Claude names a human only…
bk-agent-01 Nov 16, 2026
8c78a4e
fix(server): resolve the sender only when an identity block exists; t…
bk-agent-01 Nov 16, 2026
30813ad
fix(server): bind each Claude identity record to its prompt submission
bk-agent-01 Nov 16, 2026
d62b40c
Merge pull request #376 from iamtushar324/tushar/clerk-sender-identit…
bk-agent-01 Nov 16, 2026
04d493e
Merge bkmain into the 2026-11-17 stage promotion
bk-agent-01 Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 78 additions & 9 deletions apps/mobile/src/features/settings/ToolyardSettingsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import * as Option from "effect/Option";
import { AsyncResult, type Atom } from "effect/reactivity";
import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
import {
canReconnectToolyardTeam,
toolyardConnectionPresentation,
toolyardConnectionProblem,
toolyardInstanceHost,
toolyardMethodLabel,
} from "@t3tools/client-runtime/bk-toolyard-presentation";
import {
Expand All @@ -18,7 +21,7 @@ import {
toolyardSettingsOrigin,
type ToolyardSettingsDraft,
} from "@t3tools/client-runtime/toolyard-trust-setup";
import type { ToolyardIntegrationStatus } from "@t3tools/contracts";
import { DEFAULT_TOOLYARD_BASE_URL, type ToolyardIntegrationStatus } from "@t3tools/contracts";
import { Alert, Linking, Pressable, Switch, View } from "react-native";
import { SymbolView } from "../../components/ui/AppSymbol";
import { AppText as Text, AppTextInput } from "../../components/ui/AppText";
Expand Down Expand Up @@ -302,12 +305,19 @@ function EnvironmentToolyardContent({
setBrowserDraft(null);
setError(null);
}
// The server names its default instance; an unconfigured server starts from it.
const defaultBaseUrl = status?.defaultBaseUrl ?? DEFAULT_TOOLYARD_BASE_URL;
const unconfigured = status !== null && (!status.baseUrl || status.removed);
const current = draft ?? {
baseUrl: status?.baseUrl ?? "",
enabled: status?.enabled ?? false,
baseUrl: unconfigured ? defaultBaseUrl : (status?.baseUrl ?? ""),
enabled: unconfigured ? true : (status?.enabled ?? false),
revision: status?.revision ?? 0,
};
const mode = current.mode ?? status?.mode ?? "team";
const setupReady = Boolean(status?.administrator && unconfigured && mode === "team");
const canReconnect = mode === "team" && canReconnectToolyardTeam(status);
const problem = toolyardConnectionProblem(status);
const instanceHost = toolyardInstanceHost(status?.baseUrl);
const modeChange = status?.connection === "connected" && mode !== (status.mode ?? "team");
const canDisconnect =
status?.connection === "connected" &&
Expand Down Expand Up @@ -417,6 +427,39 @@ function EnvironmentToolyardContent({
const timer = setInterval(() => appAtomRegistry.refresh(atom), 3000);
return () => clearInterval(timer);
}, [status?.pendingConnection?.status, atom]);
// The request runs outside the try: the React Compiler cannot lower a conditional inside one.
const submitReconnect = async () => {
if (!status) return;
const saved = await configure({
environmentId: target.environmentId,
input: {
expectedRevision: status.revision,
baseUrl: status.baseUrl ?? "",
origin: status.origin ?? "",
enabled: true,
mode: "team",
reconnect: true,
},
});
appAtomRegistry.refresh(atom);
if (!AsyncResult.isSuccess(saved))
setError(toolyardSettingsFailureMessage(toolyardSettingsFailureCode(saved.cause)));
else if (saved.value.connection !== "connected")
setError(
toolyardConnectionProblem(saved.value) ??
"Toolyard did not restore the connection. Select Refresh, then try again.",
);
};
const reconnect = async () => {
setBusy(true);
setError(null);
try {
await submitReconnect();
} catch {
setError("The reconnect request failed. Select Refresh, then try again.");
}
setBusy(false);
};
const consentAction = async (cancel: boolean) => {
if (!status?.pendingConnection || !status.baseUrl) return;
setError(null);
Expand Down Expand Up @@ -493,7 +536,7 @@ function EnvironmentToolyardContent({
modeChange ||
(mode === "team" && status.teamAvailable === false) ||
(mode === "host" && status.pendingConnection?.status === "pending") ||
(!draft && !apiKey && !status.removed && mode !== "host") ||
(!draft && !apiKey && !status.removed && !setupReady && mode !== "host") ||
((mode === "api-key" || mode === "host") && !status.baseUrl && !status.administrator);
const saveLabel =
mode === "host" && current.enabled
Expand All @@ -512,6 +555,7 @@ function EnvironmentToolyardContent({
: bkAddonTone(presentation.label, presentation.tone);
const summary = connected
? [
instanceHost ? `Toolyard ${instanceHost}` : null,
presentation.host ?? target.label,
presentation.method,
status?.expiresAt ? `Access expires ${bkAddonTime(status.expiresAt)}` : null,
Expand Down Expand Up @@ -540,16 +584,26 @@ function EnvironmentToolyardContent({
</Text>
{summary ? <Text className="text-sm text-foreground-muted">{summary}</Text> : null}
<Text className="text-sm text-foreground-muted">
Toolyard Inbox asks you to decide on restricted calls.
{status.mode === "team"
? "T3 signed you in automatically with your account on this server. Toolyard Inbox asks you to decide on restricted calls."
: "Toolyard Inbox asks you to decide on restricted calls."}
</Text>
</View>
) : (
<>
<Text className="text-sm text-foreground-muted">{presentation.description}</Text>
{status?.mode === "team" && presentation.phase === "revoked" ? (
{presentation.phase === "not_configured" ? (
<Text className="text-sm text-foreground-muted">
{status.administrator
? "Open Server setup, check the Toolyard URL, then select Save and verify trust. T3 then signs in every user of this server automatically."
: "Ask an administrator of this server to set up Toolyard. T3 then signs you in automatically."}
</Text>
) : null}
{problem ? <AlertText>{problem}</AlertText> : null}
{canReconnect ? (
<Text className="text-sm text-foreground-muted">
Select an available method under Connect your account to authorize access. A settings
save does not restore revoked access.
Select Reconnect to ask Toolyard again. Toolyard decides, so access it revoked stays
revoked.
</Text>
) : null}
</>
Expand Down Expand Up @@ -600,6 +654,15 @@ function EnvironmentToolyardContent({
</View>
) : null}
<View className="flex-row flex-wrap gap-2">
{canReconnect ? (
<BkAddonButton
tone="primary"
label="Reconnect"
accessibilityLabel={`Reconnect Toolyard on ${target.label}`}
disabled={busy}
onPress={() => void reconnect()}
/>
) : null}
{status === null || status.connection === "unavailable" ? (
<BkAddonButton
label="Retry"
Expand Down Expand Up @@ -777,9 +840,15 @@ function EnvironmentToolyardContent({
autoCapitalize="none"
autoCorrect={false}
value={current.baseUrl}
placeholder="https://toolyard.dev.beknown.live"
placeholder={defaultBaseUrl}
onChangeText={(baseUrl) => setDraft({ ...current, baseUrl })}
/>
<Text className="text-sm text-foreground-muted">
Server default: {defaultBaseUrl}
{status.defaultBaseUrlSource === "environment"
? " (set by T3_TOOLYARD_URL)."
: ". Set T3_TOOLYARD_URL on the server to change it."}
</Text>
<View className="flex-row items-center justify-between gap-3">
<Text className="flex-1 text-foreground">Enable integration</Text>
<Switch
Expand Down
6 changes: 5 additions & 1 deletion apps/server/src/mcp/McpUpstreamProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
hasManagedToolyardRuntime,
managedToolyardActor,
managedToolyardCredentialForUrl,
managedToolyardMcpUrls,
retireManagedToolyardCredential,
} from "../toolyard/ToolyardIntegration.ts";

Expand Down Expand Up @@ -121,7 +122,10 @@ const makeForwardedRequest = Effect.fn("McpUpstreamProxy.makeForwardedRequest")(
);
break;
}
if (options.integrationId === TOOLYARD_MCP_INTEGRATION_ID || isToolyardGatewayUrl(options.url)) {
if (
options.integrationId === TOOLYARD_MCP_INTEGRATION_ID ||
isToolyardGatewayUrl(options.url, managedToolyardMcpUrls())
) {
outgoing = outgoing.pipe(HttpClientRequest.setHeader(T3_SESSION_ID_HEADER, options.threadId));
}
return outgoing;
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/mcp/ToolyardConnect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const captureLogs = (lines: string[]) =>

describe("personalMcp.connectToolyard", () => {
it("derives the connect endpoint from the MCP URL's origin", () => {
expect(toolyardConnectUrl()).toBe("https://toolyard.dev.beknown.live/v1/connect/t3");
expect(toolyardConnectUrl()).toBe("https://toolyard.beknown.live/v1/connect/t3");
expect(toolyardConnectUrl("https://toolyard.example/mcp")).toBe(
"https://toolyard.example/v1/connect/t3",
);
Expand Down
12 changes: 7 additions & 5 deletions apps/server/src/mcp/UserMcpProfileStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import { makePerUserLock } from "./PerUserLock.ts";
import {
managedToolyardIntegration,
managedToolyardCredential,
managedToolyardBaseUrl,
hasManagedToolyardRuntime,
managedToolyardMcpUrls,
managedToolyardOwnedMcpUrls,
} from "../toolyard/ToolyardIntegration.ts";

const textEncoder = new TextEncoder();
Expand Down Expand Up @@ -109,7 +110,9 @@ export const builtInToolyardIntegration = (): PersonalMcpIntegration => ({
export const isLegacyToolyardIntegration = (integration: {
readonly url: string;
readonly authMode: string;
}): boolean => integration.authMode === "x-bf-vk" && isToolyardGatewayUrl(integration.url);
}): boolean =>
integration.authMode === "x-bf-vk" &&
isToolyardGatewayUrl(integration.url, managedToolyardMcpUrls());

/**
* Pins what a client may not change. The built-in `toolyard` integration keeps
Expand Down Expand Up @@ -207,7 +210,7 @@ const validateIntegration = (integration: PersonalMcpProfileUpdate["integrations
if (
hasManagedToolyardRuntime() &&
integration.id !== TOOLYARD_MCP_INTEGRATION_ID &&
(isToolyardGatewayUrl(integration.url) || integration.url === `${managedToolyardBaseUrl()}/mcp`)
isToolyardGatewayUrl(integration.url, managedToolyardOwnedMcpUrls())
) {
throw new Error(
"Toolyard uses the environment's server-owned connection. Remove the manual Toolyard integration.",
Expand Down Expand Up @@ -342,8 +345,7 @@ export const layer = Layer.effect(
...presentIntegrations(stored.integrations).filter(
(entry) =>
entry.id !== TOOLYARD_MCP_INTEGRATION_ID &&
!isToolyardGatewayUrl(entry.url) &&
entry.url !== `${managedToolyardBaseUrl()}/mcp`,
!isToolyardGatewayUrl(entry.url, managedToolyardOwnedMcpUrls()),
),
],
),
Expand Down
146 changes: 144 additions & 2 deletions apps/server/src/toolyard/ToolyardConnectionCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
import { describe, it, expect } from "@effect/vitest";
import * as NodeCrypto from "node:crypto";
import * as DateTime from "effect/DateTime";
import { ToolyardConnectionCore, canonicalToolyardUrl } from "./ToolyardConnectionCore.ts";
import {
ToolyardConnectionCore,
canonicalToolyardUrl,
type CoreOptions,
isOutageFailureCode,
} from "./ToolyardConnectionCore.ts";
import { toolyardManagedProfile } from "./ToolyardManagedProfile.ts";

function fixture(environmentId = "environment-one", storage = { value: null as string | null }) {
function fixture(
environmentId = "environment-one",
storage = { value: null as string | null },
options: Partial<CoreOptions> = {},
) {
let now = DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-04T00:00:00Z"));
let connects = 0;
let failNextWrite = false;
Expand Down Expand Up @@ -124,6 +133,7 @@ function fixture(environmentId = "environment-one", storage = { value: null as s
if (id === "user_blocked") throw new Error("blocked");
return { email: `${id}@beknown.work`, admin: id === "user_admin" };
},
...options,
});
const configure = (expectedRevision = 0, extras = {}) =>
core.configure("user_admin", {
Expand Down Expand Up @@ -656,3 +666,135 @@ describe("server-owned Toolyard federation", () => {
});
});
});

describe("seamless team sign-in", () => {
const teamReconnect = (core: ToolyardConnectionCore, userId: string, expectedRevision: number) =>
core.configure(userId, {
expectedRevision,
baseUrl: "",
origin: "",
enabled: true,
mode: "team",
reconnect: true,
});

it("offers the server default and uses it, or the saved instance, for an empty base URL", async () => {
const builtIn = fixture();
await builtIn.core.initialize();
expect(await builtIn.core.status("user_admin")).toMatchObject({
baseUrl: null,
defaultBaseUrl: "https://toolyard.beknown.live",
defaultBaseUrlSource: "built-in",
});
const f = fixture(
"environment-one",
{ value: null },
{
defaultBaseUrl: "https://toolyard.test",
defaultBaseUrlSource: "environment",
},
);
await f.core.initialize();
expect(await f.core.status("user_admin")).toMatchObject({
defaultBaseUrl: "https://toolyard.test",
defaultBaseUrlSource: "environment",
});
await f.configure(0, { baseUrl: "" });
expect(f.core.baseUrl()).toBe("https://toolyard.test");
const generation = f.core.binding()?.trustGeneration;
// A later save without a URL keeps the saved instance and its trust.
await f.configure(1, { baseUrl: " " });
expect(f.core.baseUrl()).toBe("https://toolyard.test");
expect(f.core.binding()?.trustGeneration).toBe(generation);
});

it("reconnects every team user after an administrator disables and re-enables the instance", async () => {
const f = fixture();
await f.core.initialize();
await f.configure();
expect((await f.core.status("user_a")).connection).toBe("connected");
const revoked = await f.core.credential("user_b");
expect(await f.core.retire("user_b", revoked!.token!)).toBe(true);
await f.configure(1, { enabled: false });
expect((await f.core.status("user_a")).connection).toBe("disabled");
await f.configure(2);
// Toolyard marks the environment's connections reconnectable on re-registration.
expect(await f.core.status("user_a")).toMatchObject({
connection: "connected",
connectionError: null,
});
// An access T3 retired stays retired; only its owner asks again.
expect((await f.core.status("user_b")).connection).toBe("revoked");
});

it("lets a team user reconnect their own retired connection while Toolyard decides", async () => {
const f = fixture();
await f.core.initialize();
await f.configure();
const first = await f.core.credential("user_a");
expect(await f.core.retire("user_a", first!.token!)).toBe(true);
expect(await f.core.status("user_a")).toMatchObject({
connection: "revoked",
connectionError: "credential_rejected",
});
const connects = f.connects;
const reconnected = await teamReconnect(f.core, "user_a", 1);
expect(reconnected).toMatchObject({ connection: "connected", connectionError: null });
expect(f.connects).toBe(connects + 1);
// Toolyard still holds the same credential, so nothing rotated.
expect((await f.core.credential("user_a"))?.token).toBe(first!.token);
// The server settings and trust stay as they were.
expect(f.core.binding()?.trustGeneration).toBe(1);
expect((await f.core.status("user_admin")).revision).toBe(1);

expect(await f.core.retire("user_a", first!.token!)).toBe(true);
f.setRevoked();
expect(await teamReconnect(f.core, "user_a", 1)).toMatchObject({
connection: "revoked",
connectionError: "connection_revoked",
});
await expect(teamReconnect(f.core, "user_a", 0)).rejects.toMatchObject({
code: "settings_revision_conflict",
});
await expect(teamReconnect(f.core, "local-user", 1)).rejects.toMatchObject({
code: "team_identity_required",
});
});

it("refuses a team reconnect while the instance is disabled", async () => {
const f = fixture();
await f.core.initialize();
await f.configure();
await f.configure(1, { enabled: false });
await expect(teamReconnect(f.core, "user_a", 2)).rejects.toMatchObject({
code: "integration_disabled",
});
});

it("recovers a team connection after an outage in the background, without a status read", async () => {
const f = fixture();
await f.core.initialize();
await f.configure();
f.setOutage(true);
expect(await f.core.credential("user_a")).toBeNull();
expect(await f.core.status("user_a", false)).toMatchObject({
connection: "unavailable",
connectionError: "instance_unavailable",
});
f.advance(31_000);
f.setOutage(false);
await f.core.reconcileCredentials();
expect(await f.core.status("user_a", false)).toMatchObject({
connection: "connected",
connectionError: null,
});
});

it("retries only outage-class failures in the background", () => {
expect(isOutageFailureCode(undefined)).toBe(true);
expect(isOutageFailureCode("instance_unavailable")).toBe(true);
expect(isOutageFailureCode("membership_unavailable")).toBe(true);
expect(isOutageFailureCode("invalid_assertion")).toBe(false);
expect(isOutageFailureCode("conflict")).toBe(false);
});
});
Loading
Loading