Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

feat(contracts): add bot, group, MCP, and subscription-auth schemas

Leo Orel63f6290cc449
diff --git a/packages/contracts/src/baseSchemas.ts b/packages/contracts/src/baseSchemas.ts
index e12bf3e97..ef25b13fc 100644
--- a/packages/contracts/src/baseSchemas.ts
+++ b/packages/contracts/src/baseSchemas.ts
@@ -56,6 +56,10 @@ export const ThreadId = makeEntityId("ThreadId");
export type ThreadId = typeof ThreadId.Type;
export const ProjectId = makeEntityId("ProjectId");
export type ProjectId = typeof ProjectId.Type;
+export const BotId = makeEntityId("BotId");
+export type BotId = typeof BotId.Type;
+export const GroupId = makeEntityId("GroupId");
+export type GroupId = typeof GroupId.Type;
export const EnvironmentId = makeEntityId("EnvironmentId");
export type EnvironmentId = typeof EnvironmentId.Type;
export const CommandId = makeEntityId("CommandId");
diff --git a/packages/contracts/src/botConfig.test.ts b/packages/contracts/src/botConfig.test.ts
new file mode 100644
index 000000000..28dfabce5
--- /dev/null
+++ b/packages/contracts/src/botConfig.test.ts
@@ -0,0 +1,58 @@
+import * as Schema from "effect/Schema";
+import { describe, expect, it } from "vite-plus/test";
+
+import { BotCreatedPayload, BotUsageCap } from "./orchestration.ts";
+
+const decodeUsageCap = Schema.decodeUnknownSync(BotUsageCap);
+const decodeCreated = Schema.decodeUnknownSync(BotCreatedPayload);
+
+describe("BotUsageCap", () => {
+ it("accepts positive token limits and rejects invalid limits", () => {
+ expect(decodeUsageCap({ unit: "tokens", limit: 50_000 })).toEqual({
+ unit: "tokens",
+ limit: 50_000,
+ });
+ for (const limit of [0, -1, 1.5, Number.NaN, Number.POSITIVE_INFINITY]) {
+ expect(() => decodeUsageCap({ unit: "tokens", limit })).toThrow();
+ }
+ });
+
+ it("defaults old bot events to full access with no cap", () => {
+ const bot = decodeCreated({
+ botId: "bot-old",
+ name: "Old bot",
+ title: "Generalist",
+ avatar: { kind: "blob", shape: "circle", color: "#5B7FD4" },
+ engine: null,
+ sandbox: null,
+ groupId: null,
+ createdAt: "2026-01-01T00:00:00.000Z",
+ updatedAt: "2026-01-01T00:00:00.000Z",
+ });
+
+ expect(bot.runtimeMode).toBe("full-access");
+ expect(bot.usageCap).toBeNull();
+ expect(bot.label).toBeNull();
+ expect(bot.description).toBeNull();
+ expect(bot.disabledMcpServerIds).toEqual([]);
+ expect(bot.disabledMcpServerIds).toEqual([]);
+ });
+
+ it("accepts cloud sandbox providers on bot events", () => {
+ for (const sandbox of ["local", "vercel", "akeru-cloud", "upstash"] as const) {
+ expect(
+ decodeCreated({
+ botId: "bot-sandbox",
+ name: "Sandbox bot",
+ title: "Generalist",
+ avatar: { kind: "blob", shape: "circle", color: "#5B7FD4" },
+ engine: null,
+ sandbox,
+ groupId: null,
+ createdAt: "2026-01-01T00:00:00.000Z",
+ updatedAt: "2026-01-01T00:00:00.000Z",
+ }).sandbox,
+ ).toBe(sandbox);
+ }
+ });
+});
diff --git a/packages/contracts/src/environmentHttp.ts b/packages/contracts/src/environmentHttp.ts
index e74948622..999825eef 100644
--- a/packages/contracts/src/environmentHttp.ts
+++ b/packages/contracts/src/environmentHttp.ts
@@ -33,12 +33,6 @@ import {
OrchestrationShellSnapshot,
OrchestrationThreadDetailSnapshot,
} from "./orchestration.ts";
-import {
- PullRequestDiffInput,
- PullRequestDiffResult,
- PullRequestOperationError,
- PullRequestUnavailableError,
-} from "./pullRequest.ts";
import {
RelayCloudEnvironmentHealthRequest,
RelayCloudMintCredentialRequest,
@@ -530,22 +524,6 @@ export class EnvironmentOrchestrationHttpApi extends HttpApiGroup.make("orchestr
}).middleware(EnvironmentAuthenticatedAuth),
) {}
-/** Large, compressible pull-request payloads travel over HTTP rather than the RPC socket. */
-export class EnvironmentPullRequestsHttpApi extends HttpApiGroup.make("pullRequests").add(
- HttpApiEndpoint.post("diff", "/api/pull-requests/diff", {
- headers: OptionalBearerHeaders,
- payload: PullRequestDiffInput,
- success: PullRequestDiffResult,
- error: [
- PullRequestUnavailableError,
- PullRequestOperationError,
- EnvironmentAuthInvalidError,
- EnvironmentScopeRequiredError,
- EnvironmentInternalError,
- ],
- }).middleware(EnvironmentAuthenticatedAuth),
-) {}
-
export class EnvironmentConnectHttpApi extends HttpApiGroup.make("connect")
.add(
HttpApiEndpoint.post("linkProof", "/api/connect/link-proof", {
@@ -611,5 +589,4 @@ export class EnvironmentHttpApi extends HttpApi.make("environment")
.add(EnvironmentMetadataHttpApi)
.add(EnvironmentAuthHttpApi)
.add(EnvironmentOrchestrationHttpApi)
- .add(EnvironmentPullRequestsHttpApi)
.add(EnvironmentConnectHttpApi) {}
diff --git a/packages/contracts/src/index.ts b/packages/contracts/src/index.ts
index c6daef868..a289b2ac4 100644
--- a/packages/contracts/src/index.ts
+++ b/packages/contracts/src/index.ts
@@ -12,13 +12,14 @@ export * from "./provider.ts";
export * from "./providerInstance.ts";
export * from "./providerRuntime.ts";
export * from "./model.ts";
+export * from "./mcpServer.ts";
export * from "./keybindings.ts";
export * from "./server.ts";
export * from "./settings.ts";
+export * from "./subscriptionAuth.ts";
export * from "./git.ts";
export * from "./vcs.ts";
export * from "./sourceControl.ts";
-export * from "./pullRequest.ts";
export * from "./orchestration.ts";
export * from "./t3ProjectFile.ts";
export * from "./editor.ts";
diff --git a/packages/contracts/src/mcpServer.test.ts b/packages/contracts/src/mcpServer.test.ts
new file mode 100644
index 000000000..81208b0ba
--- /dev/null
+++ b/packages/contracts/src/mcpServer.test.ts
@@ -0,0 +1,132 @@
+import { describe, expect, it } from "vite-plus/test";
+import * as Schema from "effect/Schema";
+
+import {
+ McpServer,
+ McpServerConfiguration,
+ McpServerId,
+ resolveBotMcpServers,
+} from "./mcpServer.ts";
+
+const decodeConfiguration = Schema.decodeUnknownSync(McpServerConfiguration);
+const decodeServer = Schema.decodeUnknownSync(McpServer);
+
+const timestamps = {
+ createdAt: "2026-03-22T10:00:00.000Z",
+ updatedAt: "2026-03-22T10:00:00.000Z",
+};
+
+describe("McpServerConfiguration", () => {
+ it("accepts a stdio server with a command and args", () => {
+ expect(
+ decodeConfiguration({
+ name: "Filesystem",
+ transport: "stdio",
+ command: "bunx",
+ args: ["@modelcontextprotocol/server-filesystem", "/workspace"],
+ }),
+ ).toEqual({
+ name: "Filesystem",
+ transport: "stdio",
+ command: "bunx",
+ args: ["@modelcontextprotocol/server-filesystem", "/workspace"],
+ });
+ });
+
+ it("rejects a stdio server without a command", () => {
+ expect(() =>
+ decodeConfiguration({
+ name: "Filesystem",
+ transport: "stdio",
+ args: [],
+ }),
+ ).toThrow();
+ });
+
+ it.each(["http://localhost:3100/mcp", "https://mcp.example.com/v1"])(
+ "accepts the HTTP URL %s",
+ (url) => {
+ expect(
+ decodeConfiguration({
+ name: "Remote",
+ transport: "url",
+ url,
+ }),
+ ).toEqual({ name: "Remote", transport: "url", url });
+ },
+ );
+
+ it.each(["mcp.example.com", "ftp://mcp.example.com", "not a url"])(
+ "rejects the non-HTTP URL %s",
+ (url) => {
+ expect(() =>
+ decodeConfiguration({
+ name: "Remote",
+ transport: "url",
+ url,
+ }),
+ ).toThrow();
+ },
+ );
+
+ it.each(["https://user:[email protected]/v1", "https://[email protected]/v1"])(
+ "rejects the credential-bearing URL %s",
+ (url) => {
+ expect(() =>
+ decodeConfiguration({
+ name: "Remote",
+ transport: "url",
+ url,
+ }),
+ ).toThrow();
+ },
+ );
+});
+
+describe("McpServer", () => {
+ it("decodes the complete registry record", () => {
+ expect(
+ decodeServer({
+ id: "mcp-filesystem",
+ name: "Filesystem",
+ transport: "stdio",
+ command: "bunx",
+ args: [],
+ enabled: true,
+ ...timestamps,
+ }),
+ ).toEqual({
+ id: "mcp-filesystem",
+ name: "Filesystem",
+ transport: "stdio",
+ command: "bunx",
+ args: [],
+ enabled: true,
+ ...timestamps,
+ });
+ });
+
+ it("inherits every globally enabled server unless the bot excludes it", () => {
+ const installed = decodeServer({
+ id: "builtin-exa",
+ name: "Exa",
+ transport: "url",
+ url: "https://mcp.exa.ai/mcp",
+ enabled: true,
+ ...timestamps,
+ });
+ const disabledGlobally = decodeServer({
+ id: "builtin-context",
+ name: "Context",
+ transport: "url",
+ url: "https://mcp.context.dev/mcp",
+ enabled: false,
+ ...timestamps,
+ });
+
+ expect(resolveBotMcpServers([installed, disabledGlobally], [])).toEqual([installed]);
+ expect(
+ resolveBotMcpServers([installed, disabledGlobally], [McpServerId.make("builtin-exa")]),
+ ).toEqual([]);
+ });
+});
diff --git a/packages/contracts/src/mcpServer.ts b/packages/contracts/src/mcpServer.ts
new file mode 100644
index 000000000..ffd9d607d
--- /dev/null
+++ b/packages/contracts/src/mcpServer.ts
@@ -0,0 +1,85 @@
+import * as Schema from "effect/Schema";
+
+import { IsoDateTime, TrimmedNonEmptyString } from "./baseSchemas.ts";
+
+export const McpServerId = TrimmedNonEmptyString.pipe(Schema.brand("McpServerId"));
+export type McpServerId = typeof McpServerId.Type;
+
+export const McpServerTransport = Schema.Literals(["stdio", "url"]);
+export type McpServerTransport = typeof McpServerTransport.Type;
+
+export const McpServerUrl = TrimmedNonEmptyString.check(
+ Schema.makeFilter((value) => {
+ if (!/^https?:\/\//i.test(value)) {
+ return "MCP server URL must be an absolute HTTP or HTTPS URL.";
+ }
+ try {
+ const url = new URL(value);
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
+ return "MCP server URL must be an absolute HTTP or HTTPS URL.";
+ }
+ // The registry stores no credentials; a userinfo URL would smuggle one
+ // into plain event payloads.
+ if (url.username !== "" || url.password !== "") {
+ return "MCP server URL must not contain credentials.";
+ }
+ return true;
+ } catch {
+ return "MCP server URL must be an absolute HTTP or HTTPS URL.";
+ }
+ }),
+);
+
+const StdioMcpServerConfiguration = Schema.Struct({
+ name: TrimmedNonEmptyString,
+ transport: Schema.Literal("stdio"),
+ command: TrimmedNonEmptyString,
+ args: Schema.optional(Schema.Array(Schema.String)),
+});
+
+const UrlMcpServerConfiguration = Schema.Struct({
+ name: TrimmedNonEmptyString,
+ transport: Schema.Literal("url"),
+ url: McpServerUrl,
+});
+
+export const McpServerConfiguration = Schema.Union([
+ StdioMcpServerConfiguration,
+ UrlMcpServerConfiguration,
+]);
+export type McpServerConfiguration = typeof McpServerConfiguration.Type;
+
+/**
+ * A workspace-level raw MCP server registration. Runtime launch, Mastra tool
+ * attachment, Executor, Composio, and per-bot enablement are outside this registry.
+ * Credentials stay in external secret storage and never belong in this record.
+ */
+export const McpServer = Schema.Union([
+ Schema.Struct({
+ id: McpServerId,
+ ...StdioMcpServerConfiguration.fields,
+ enabled: Schema.Boolean,
+ createdAt: IsoDateTime,
+ updatedAt: IsoDateTime,
+ }),
+ Schema.Struct({
+ id: McpServerId,
+ ...UrlMcpServerConfiguration.fields,
+ enabled: Schema.Boolean,
+ createdAt: IsoDateTime,
+ updatedAt: IsoDateTime,
+ }),
+]);
+export type McpServer = typeof McpServer.Type;
+
+/**
+ * Resolve the global MCP registry for one bot. Global installation is the
+ * default; a bot stores only the server ids it excludes.
+ */
+export function resolveBotMcpServers(
+ servers: readonly McpServer[],
+ disabledMcpServerIds: readonly McpServerId[],
+): readonly McpServer[] {
+ const excluded = new Set(disabledMcpServerIds);
+ return servers.filter((server) => server.enabled && !excluded.has(server.id));
+}
diff --git a/packages/contracts/src/orchestration.test.ts b/packages/contracts/src/orchestration.test.ts
index 52b893f39..4306b7f4c 100644
--- a/packages/contracts/src/orchestration.test.ts
+++ b/packages/contracts/src/orchestration.test.ts
@@ -3,6 +3,7 @@ import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";
import {
+ BotAvatar,
DEFAULT_PROVIDER_INTERACTION_MODE,
DEFAULT_RUNTIME_MODE,
ClientOrchestrationCommand,
@@ -29,6 +30,7 @@ import {
} from "./orchestration.ts";
import { ProviderInstanceId } from "./providerInstance.ts";
+const decodeBotAvatar = Schema.decodeUnknownEffect(BotAvatar);
const decodeTurnDiffInput = Schema.decodeUnknownEffect(OrchestrationGetTurnDiffInput);
const decodeFullThreadDiffInput = Schema.decodeUnknownEffect(OrchestrationGetFullThreadDiffInput);
const decodeThreadTurnDiff = Schema.decodeUnknownEffect(ThreadTurnDiff);
@@ -59,6 +61,27 @@ const decodeOrchestrationEvent = Schema.decodeUnknownEffect(OrchestrationEvent);
const decodeThreadMetaUpdatedPayload = Schema.decodeUnknownEffect(ThreadMetaUpdatedPayload);
const decodeDispatchCommandError = Schema.decodeUnknownEffect(OrchestrationDispatchCommandError);
+it.effect("decodes every bot avatar variant", () =>
+ Effect.gen(function* () {
+ assert.deepEqual(
+ [
+ yield* decodeBotAvatar({ kind: "blob", shape: "squircle", color: "#7357ff" }),
+ yield* decodeBotAvatar({ kind: "dither", seed: "scout" }),
+ yield* decodeBotAvatar({
+ kind: "image",
+ assetPath: "bots/scout.png",
+ dithered: true,
+ }),
+ ],
+ [
+ { kind: "blob", shape: "squircle", color: "#7357ff" },
+ { kind: "dither", seed: "scout" },
+ { kind: "image", assetPath: "bots/scout.png", dithered: true },
+ ],
+ );
+ }),
+);
+
it.effect("decodes a dispatch error after its bootstrap thread was deleted", () =>
Effect.gen(function* () {
const error = yield* decodeDispatchCommandError({
@@ -352,6 +375,44 @@ it.effect("accepts bootstrap metadata in thread.turn.start", () =>
}),
);
+it.effect("rejects dual ownership in thread.turn.start bootstrap", () =>
+ Effect.gen(function* () {
+ const result = yield* Effect.result(
+ decodeThreadTurnStartCommand({
+ type: "thread.turn.start",
+ commandId: "cmd-turn-bootstrap-dual-owner",
+ threadId: "thread-dual-owner",
+ message: {
+ messageId: "msg-bootstrap-dual-owner",
+ role: "user",
+ text: "hello",
+ attachments: [],
+ },
+ bootstrap: {
+ createThread: {
+ projectId: "project-1",
+ botId: "bot-1",
+ groupId: "group-1",
+ title: "Invalid bootstrap thread",
+ modelSelection: {
+ provider: "codex",
+ model: "gpt-5.4",
+ },
+ runtimeMode: "full-access",
+ interactionMode: "default",
+ branch: null,
+ worktreePath: null,
+ createdAt: "2026-01-01T00:00:00.000Z",
+ },
+ },
+ createdAt: "2026-01-01T00:00:00.000Z",
+ }),
+ );
+
+ assert.equal(result._tag, "Failure");
+ }),
+);
+
it.effect("decodes thread.created runtime mode for historical events", () =>
Effect.gen(function* () {
const parsed = yield* decodeThreadCreatedPayload({
@@ -396,6 +457,35 @@ it.effect("decodes thread.meta-updated payloads with explicit provider", () =>
}),
);
+it.effect("decodes exclusive thread ownership", () =>
+ Effect.gen(function* () {
+ const base = {
+ type: "thread.create" as const,
+ commandId: "cmd-thread-owner",
+ threadId: "thread-owned",
+ projectId: "project-1",
+ title: "Owned thread",
+ modelSelection: { provider: "codex", model: "gpt-5.4" },
+ runtimeMode: "full-access" as const,
+ interactionMode: "default" as const,
+ branch: null,
+ worktreePath: null,
+ createdAt: "2026-01-01T00:00:00.000Z",
+ };
+ const owned = yield* decodeOrchestrationCommand({ ...base, botId: "bot-1" });
+ assert.equal(owned.type, "thread.create");
+ if (owned.type === "thread.create") {
+ assert.equal(owned.botId, "bot-1");
+ assert.equal(owned.groupId, undefined);
+ }
+
+ const invalid = yield* Effect.result(
+ decodeOrchestrationCommand({ ...base, botId: "bot-1", groupId: "group-1" }),
+ );
+ assert.equal(invalid._tag, "Failure");
+ }),
+);
+
it.effect("decodes thread archive and unarchive commands", () =>
Effect.gen(function* () {
const archive = yield* decodeOrchestrationCommand({
diff --git a/packages/contracts/src/orchestration.ts b/packages/contracts/src/orchestration.ts
index 682d65fda..4e62c1d2e 100644
--- a/packages/contracts/src/orchestration.ts
+++ b/packages/contracts/src/orchestration.ts
@@ -7,10 +7,12 @@ import { ProviderOptionSelections } from "./model.ts";
import { RepositoryIdentity, ThreadEnvMode } from "./environment.ts";
import {
ApprovalRequestId,
+ BotId,
CheckpointRef,
ClientSurface,
CommandId,
EventId,
+ GroupId,
IsoDateTime,
MessageId,
NonNegativeInt,
@@ -23,6 +25,7 @@ import {
TurnId,
} from "./baseSchemas.ts";
import { ProviderInstanceId } from "./providerInstance.ts";
+import { McpServer, McpServerId, McpServerUrl } from "./mcpServer.ts";
export const ORCHESTRATION_WS_METHODS = {
dispatchCommand: "orchestration.dispatchCommand",
@@ -261,6 +264,93 @@ export const OrchestrationProject = Schema.Struct({
});
export type OrchestrationProject = typeof OrchestrationProject.Type;
+export const BotAvatar = Schema.Union([
+ Schema.Struct({
+ kind: Schema.Literal("blob"),
+ shape: Schema.Literals([
+ "circle",
+ "squircle",
+ "square",
+ "pill",
+ "triangle",
+ "hex",
+ "cloud",
+ "drop",
+ ]),
+ color: Schema.String,
+ }),
+ Schema.Struct({
+ kind: Schema.Literal("dither"),
+ seed: Schema.String,
+ }),
+ Schema.Struct({
+ kind: Schema.Literal("image"),
+ assetPath: Schema.String,
+ dithered: Schema.Boolean,
+ }),
+]);
+export type BotAvatar = typeof BotAvatar.Type;
+
+export const BotEngine = Schema.Struct({
+ provider: TrimmedNonEmptyString,
+ model: TrimmedNonEmptyString,
+});
+export type BotEngine = typeof BotEngine.Type;
+
+export const BotSandbox = Schema.Literals(["local", "vercel", "akeru-cloud", "upstash"]);
+export type BotSandbox = typeof BotSandbox.Type;
+
+export const BotUsageCap = Schema.Struct({
+ unit: Schema.Literal("tokens"),
+ limit: Schema.Int.check(Schema.isGreaterThan(0)),
+});
+export type BotUsageCap = typeof BotUsageCap.Type;
+
+export const OrchestrationBot = Schema.Struct({
+ id: BotId,
+ name: TrimmedNonEmptyString,
+ title: TrimmedNonEmptyString,
+ label: Schema.NullOr(TrimmedNonEmptyString).pipe(
+ Schema.withDecodingDefault(Effect.succeed(null)),
+ ),
+ description: Schema.NullOr(Schema.String).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
+ disabledMcpServerIds: Schema.Array(McpServerId).pipe(
+ Schema.withDecodingDefault(Effect.succeed([])),
+ ),
+ avatar: BotAvatar,
+ engine: Schema.NullOr(BotEngine),
+ sandbox: Schema.NullOr(BotSandbox),
+ runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_RUNTIME_MODE))),
+ usageCap: Schema.NullOr(BotUsageCap).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
+ groupId: Schema.NullOr(GroupId),
+ archivedAt: Schema.NullOr(IsoDateTime),
+ createdAt: IsoDateTime,
+ updatedAt: IsoDateTime,
+});
+export type OrchestrationBot = typeof OrchestrationBot.Type;
+
+export const GroupMembershipRole = Schema.Literals(["boss", "specialist"]);
+export type GroupMembershipRole = typeof GroupMembershipRole.Type;
+
+export const GroupMembership = Schema.Struct({
+ botId: BotId,
+ role: GroupMembershipRole,
+});
+export type GroupMembership = typeof GroupMembership.Type;
+
+export const GROUP_SHARED_WORKSPACE_WARNING =
+ "Bots share this workspace. Anyone who can talk to a bot can reach anything the workspace can.";
+
+export const OrchestrationGroup = Schema.Struct({
+ id: GroupId,
+ name: TrimmedNonEmptyString,
+ bossBotId: Schema.NullOr(BotId).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
+ members: Schema.Array(GroupMembership).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
+ createdAt: IsoDateTime,
+ updatedAt: IsoDateTime,
+});
+export type OrchestrationGroup = typeof OrchestrationGroup.Type;
+
export const OrchestrationMessageRole = Schema.Literals(["user", "assistant", "system"]);
export type OrchestrationMessageRole = typeof OrchestrationMessageRole.Type;
@@ -270,6 +360,7 @@ export const OrchestrationMessage = Schema.Struct({
text: Schema.String,
attachments: Schema.optional(Schema.Array(ChatAttachment)),
turnId: Schema.NullOr(TurnId),
+ respondingBotId: Schema.optional(Schema.NullOr(BotId)),
streaming: Schema.Boolean,
createdAt: IsoDateTime,
updatedAt: IsoDateTime,
@@ -377,6 +468,7 @@ export const OrchestrationLatestTurn = Schema.Struct({
startedAt: Schema.NullOr(IsoDateTime),
completedAt: Schema.NullOr(IsoDateTime),
assistantMessageId: Schema.NullOr(MessageId),
+ respondingBotId: Schema.optional(Schema.NullOr(BotId)),
sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
});
export type OrchestrationLatestTurn = typeof OrchestrationLatestTurn.Type;
@@ -398,6 +490,9 @@ export type ThreadLinkedPullRequest = typeof ThreadLinkedPullRequest.Type;
export const OrchestrationThread = Schema.Struct({
id: ThreadId,
projectId: ProjectId,
+ botId: Schema.optional(Schema.NullOr(BotId)),
+ groupId: Schema.optional(Schema.NullOr(GroupId)),
+ respondingBotId: Schema.optional(Schema.NullOr(BotId)),
title: TrimmedNonEmptyString,
modelSelection: ModelSelection,
runtimeMode: RuntimeMode,
@@ -451,6 +546,9 @@ export type OrchestrationThread = typeof OrchestrationThread.Type;
export const OrchestrationReadModel = Schema.Struct({
snapshotSequence: NonNegativeInt,
projects: Schema.Array(OrchestrationProject),
+ bots: Schema.Array(OrchestrationBot).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
+ groups: Schema.Array(OrchestrationGroup).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
+ mcpServers: Schema.optional(Schema.Array(McpServer)),
threads: Schema.Array(OrchestrationThread),
updatedAt: IsoDateTime,
});
@@ -474,6 +572,9 @@ export type OrchestrationProjectShell = typeof OrchestrationProjectShell.Type;
export const OrchestrationThreadShell = Schema.Struct({
id: ThreadId,
projectId: ProjectId,
+ botId: Schema.optional(Schema.NullOr(BotId)),
+ groupId: Schema.optional(Schema.NullOr(GroupId)),
+ respondingBotId: Schema.optional(Schema.NullOr(BotId)),
title: TrimmedNonEmptyString,
modelSelection: ModelSelection,
runtimeMode: RuntimeMode,
@@ -529,6 +630,9 @@ export type OrchestrationThreadShell = typeof OrchestrationThreadShell.Type;
export const OrchestrationShellSnapshot = Schema.Struct({
snapshotSequence: NonNegativeInt,
projects: Schema.Array(OrchestrationProjectShell),
+ bots: Schema.Array(OrchestrationBot).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
+ groups: Schema.Array(OrchestrationGroup).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
+ mcpServers: Schema.optional(Schema.Array(McpServer)),
threads: Schema.Array(OrchestrationThreadShell),
updatedAt: IsoDateTime,
});
@@ -545,6 +649,31 @@ export const OrchestrationShellStreamEvent = Schema.Union([
sequence: NonNegativeInt,
projectId: ProjectId,
}),
+ Schema.Struct({
+ kind: Schema.Literal("bot-upserted"),
+ sequence: NonNegativeInt,
+ bot: OrchestrationBot,
+ }),
+ Schema.Struct({
+ kind: Schema.Literal("group-upserted"),
+ sequence: NonNegativeInt,
+ group: OrchestrationGroup,
+ }),
+ Schema.Struct({
+ kind: Schema.Literal("group-removed"),
+ sequence: NonNegativeInt,
+ groupId: GroupId,
+ }),
+ Schema.Struct({
+ kind: Schema.Literal("mcp-server-upserted"),
+ sequence: NonNegativeInt,
+ mcpServer: McpServer,
+ }),
+ Schema.Struct({
+ kind: Schema.Literal("mcp-server-removed"),
+ sequence: NonNegativeInt,
+ mcpServerId: McpServerId,
+ }),
Schema.Struct({
kind: Schema.Literal("thread-upserted"),
sequence: NonNegativeInt,
@@ -693,11 +822,170 @@ const ProjectDeleteCommand = Schema.Struct({
force: Schema.optional(Schema.Boolean),
});
+const BotCreateCommand = Schema.Struct({
+ type: Schema.Literal("bot.create"),
+ commandId: CommandId,
+ botId: BotId,
+ name: TrimmedNonEmptyString,
+ title: TrimmedNonEmptyString,
+ label: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
+ description: Schema.optional(Schema.NullOr(Schema.String)),
+ disabledMcpServerIds: Schema.optional(Schema.Array(McpServerId)),
+ avatar: BotAvatar,
+ engine: Schema.NullOr(BotEngine),
+ sandbox: Schema.NullOr(BotSandbox),
+ runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_RUNTIME_MODE))),
+ usageCap: Schema.NullOr(BotUsageCap).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
+ groupId: Schema.NullOr(GroupId),
+ createdAt: IsoDateTime,
+});
+
+const BotUpdateCommand = Schema.Struct({
+ type: Schema.Literal("bot.update"),
+ commandId: CommandId,
+ botId: BotId,
+ name: Schema.optional(TrimmedNonEmptyString),
+ title: Schema.optional(TrimmedNonEmptyString),
+ label: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
+ description: Schema.optional(Schema.NullOr(Schema.String)),
+ disabledMcpServerIds: Schema.optional(Schema.Array(McpServerId)),
+ avatar: Schema.optional(BotAvatar),
+ engine: Schema.optional(Schema.NullOr(BotEngine)),
+ sandbox: Schema.optional(Schema.NullOr(BotSandbox)),
+ runtimeMode: Schema.optional(RuntimeMode),
+ usageCap: Schema.optional(Schema.NullOr(BotUsageCap)),
+ groupId: Schema.optional(Schema.NullOr(GroupId)),
+});
+
+const BotArchiveCommand = Schema.Struct({
+ type: Schema.Literal("bot.archive"),
+ commandId: CommandId,
+ botId: BotId,
+});
+
+const BotRestoreCommand = Schema.Struct({
+ type: Schema.Literal("bot.restore"),
+ commandId: CommandId,
+ botId: BotId,
+});
+
+const GroupCreateCommand = Schema.Struct({
+ type: Schema.Literal("group.create"),
+ commandId: CommandId,
+ groupId: GroupId,
+ name: TrimmedNonEmptyString,
+ // Optional at the wire boundary so the decider returns the domain-specific
+ // missing-boss rejection instead of a generic schema failure.
+ bossBotId: Schema.optional(BotId),
+ specialistBotIds: Schema.optional(Schema.Array(BotId)),
+ createdAt: IsoDateTime,
+});
+
+const GroupRenameCommand = Schema.Struct({
+ type: Schema.Literal("group.rename"),
+ commandId: CommandId,
+ groupId: GroupId,
+ name: TrimmedNonEmptyString,
+});
+
+const GroupDeleteCommand = Schema.Struct({
+ type: Schema.Literal("group.delete"),
+ commandId: CommandId,
+ groupId: GroupId,
+});
+
+const GroupMemberAssignCommand = Schema.Struct({
+ type: Schema.Literal("group.member.assign"),
+ commandId: CommandId,
+ groupId: GroupId,
+ botId: BotId,
+ role: GroupMembershipRole,
+});
+
+const GroupMemberUnassignCommand = Schema.Struct({
+ type: Schema.Literal("group.member.unassign"),
+ commandId: CommandId,
+ groupId: GroupId,
+ botId: BotId,
+});
+
+const GroupBossSetCommand = Schema.Struct({
+ type: Schema.Literal("group.boss.set"),
+ commandId: CommandId,
+ groupId: GroupId,
+ bossBotId: BotId,
+ // This makes boss replacement and removal of the old boss one atomic
+ // command. Without it, the old boss remains a specialist.
+ unassignPreviousBoss: Schema.optional(Schema.Boolean),
+});
+
+const McpServerCreateCommand = Schema.Union([
+ Schema.Struct({
+ type: Schema.Literal("mcp-server.create"),
+ commandId: CommandId,
+ mcpServerId: McpServerId,
+ name: TrimmedNonEmptyString,
+ transport: Schema.Literal("stdio"),
+ command: TrimmedNonEmptyString,
+ args: Schema.optional(Schema.Array(Schema.String)),
+ createdAt: IsoDateTime,
+ }),
+ Schema.Struct({
+ type: Schema.Literal("mcp-server.create"),
+ commandId: CommandId,
+ mcpServerId: McpServerId,
+ name: TrimmedNonEmptyString,
+ transport: Schema.Literal("url"),
+ url: McpServerUrl,
+ createdAt: IsoDateTime,
+ }),
+]);
+
+const McpServerUpdateCommand = Schema.Union([
+ Schema.Struct({
+ type: Schema.Literal("mcp-server.update"),
+ commandId: CommandId,
+ mcpServerId: McpServerId,
+ name: TrimmedNonEmptyString,
+ transport: Schema.Literal("stdio"),
+ command: TrimmedNonEmptyString,
+ args: Schema.optional(Schema.Array(Schema.String)),
+ }),
+ Schema.Struct({
+ type: Schema.Literal("mcp-server.update"),
+ commandId: CommandId,
+ mcpServerId: McpServerId,
+ name: TrimmedNonEmptyString,
+ transport: Schema.Literal("url"),
+ url: McpServerUrl,
+ }),
+]);
+
+const McpServerDeleteCommand = Schema.Struct({
+ type: Schema.Literal("mcp-server.delete"),
+ commandId: CommandId,
+ mcpServerId: McpServerId,
+});
+
+const McpServerEnableCommand = Schema.Struct({
+ type: Schema.Literal("mcp-server.enable"),
+ commandId: CommandId,
+ mcpServerId: McpServerId,
+});
+
+const McpServerDisableCommand = Schema.Struct({
+ type: Schema.Literal("mcp-server.disable"),
+ commandId: CommandId,
+ mcpServerId: McpServerId,
+});
+
const ThreadCreateCommand = Schema.Struct({
type: Schema.Literal("thread.create"),
commandId: CommandId,
threadId: ThreadId,
projectId: ProjectId,
+ botId: Schema.optional(Schema.NullOr(BotId)),
+ groupId: Schema.optional(Schema.NullOr(GroupId)),
title: TrimmedNonEmptyString,
modelSelection: ModelSelection,
runtimeMode: RuntimeMode,
@@ -707,7 +995,12 @@ const ThreadCreateCommand = Schema.Struct({
branch: Schema.NullOr(TrimmedNonEmptyString),
worktreePath: Schema.NullOr(TrimmedNonEmptyString),
createdAt: IsoDateTime,
-});
+}).check(
+ Schema.makeFilter(
+ (input) =>
+ input.botId == null || input.groupId == null || "thread cannot belong to a bot and group",
+ ),
+);
const ThreadDeleteCommand = Schema.Struct({
type: Schema.Literal("thread.delete"),
@@ -828,6 +1121,8 @@ const ThreadInteractionModeSetCommand = Schema.Struct({
const ThreadTurnStartBootstrapCreateThread = Schema.Struct({
projectId: ProjectId,
+ botId: Schema.optional(Schema.NullOr(BotId)),
+ groupId: Schema.optional(Schema.NullOr(GroupId)),
title: TrimmedNonEmptyString,
modelSelection: ModelSelection,
runtimeMode: RuntimeMode,
@@ -835,7 +1130,12 @@ const ThreadTurnStartBootstrapCreateThread = Schema.Struct({
branch: Schema.NullOr(TrimmedNonEmptyString),
worktreePath: Schema.NullOr(TrimmedNonEmptyString),
createdAt: IsoDateTime,
-});
+}).check(
+ Schema.makeFilter(
+ (input) =>
+ input.botId == null || input.groupId == null || "thread cannot belong to a bot and group",
+ ),
+);
const ThreadTurnStartBootstrapPrepareWorktree = Schema.Struct({
projectCwd: TrimmedNonEmptyString,
@@ -870,6 +1170,7 @@ export const ThreadTurnStartCommand = Schema.Struct({
),
bootstrap: Schema.optional(ThreadTurnStartBootstrap),
sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
+ respondingBotId: Schema.optional(BotId),
createdAt: IsoDateTime,
});
@@ -889,6 +1190,7 @@ const ClientThreadTurnStartCommand = Schema.Struct({
interactionMode: ProviderInteractionMode,
bootstrap: Schema.optional(ThreadTurnStartBootstrap),
sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
+ respondingBotId: Schema.optional(BotId),
createdAt: IsoDateTime,
});
@@ -943,6 +1245,21 @@ const DispatchableClientOrchestrationCommand = Schema.Union([
ProjectCreateCommand,
ProjectMetaUpdateCommand,
ProjectDeleteCommand,
+ BotCreateCommand,
+ BotUpdateCommand,
+ BotArchiveCommand,
+ BotRestoreCommand,
+ GroupCreateCommand,
+ GroupRenameCommand,
+ GroupDeleteCommand,
+ GroupMemberAssignCommand,
+ GroupMemberUnassignCommand,
+ GroupBossSetCommand,
+ McpServerCreateCommand,
+ McpServerUpdateCommand,
+ McpServerDeleteCommand,
+ McpServerEnableCommand,
+ McpServerDisableCommand,
ThreadCreateCommand,
ThreadDeleteCommand,
ThreadArchiveCommand,
@@ -971,6 +1288,21 @@ export const ClientOrchestrationCommand = Schema.Union([
ProjectCreateCommand,
ProjectMetaUpdateCommand,
ProjectDeleteCommand,
+ BotCreateCommand,
+ BotUpdateCommand,
+ BotArchiveCommand,
+ BotRestoreCommand,
+ GroupCreateCommand,
+ GroupRenameCommand,
+ GroupDeleteCommand,
+ GroupMemberAssignCommand,
+ GroupMemberUnassignCommand,
+ GroupBossSetCommand,
+ McpServerCreateCommand,
+ McpServerUpdateCommand,
+ McpServerDeleteCommand,
+ McpServerEnableCommand,
+ McpServerDisableCommand,
ThreadCreateCommand,
ThreadDeleteCommand,
ThreadArchiveCommand,
@@ -1089,6 +1421,21 @@ export const OrchestrationEventType = Schema.Literals([
"project.created",
"project.meta-updated",
"project.deleted",
+ "bot.created",
+ "bot.updated",
+ "bot.archived",
+ "bot.restored",
+ "group.created",
+ "group.renamed",
+ "group.deleted",
+ "group.member-assigned",
+ "group.member-unassigned",
+ "group.boss-set",
+ "mcp-server.created",
+ "mcp-server.updated",
+ "mcp-server.deleted",
+ "mcp-server.enabled",
+ "mcp-server.disabled",
"thread.created",
"thread.deleted",
"thread.archived",
@@ -1118,7 +1465,13 @@ export const OrchestrationEventType = Schema.Literals([
]);
export type OrchestrationEventType = typeof OrchestrationEventType.Type;
-export const OrchestrationAggregateKind = Schema.Literals(["project", "thread"]);
+export const OrchestrationAggregateKind = Schema.Literals([
+ "project",
+ "bot",
+ "group",
+ "mcp-server",
+ "thread",
+]);
export type OrchestrationAggregateKind = typeof OrchestrationAggregateKind.Type;
export const OrchestrationActorKind = Schema.Literals(["client", "server", "provider"]);
@@ -1152,9 +1505,121 @@ export const ProjectDeletedPayload = Schema.Struct({
deletedAt: IsoDateTime,
});
+export const BotCreatedPayload = Schema.Struct({
+ botId: BotId,
+ name: TrimmedNonEmptyString,
+ title: TrimmedNonEmptyString,
+ label: Schema.NullOr(TrimmedNonEmptyString).pipe(
+ Schema.withDecodingDefault(Effect.succeed(null)),
+ ),
+ description: Schema.NullOr(Schema.String).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
+ disabledMcpServerIds: Schema.Array(McpServerId).pipe(
+ Schema.withDecodingDefault(Effect.succeed([])),
+ ),
+ avatar: BotAvatar,
+ engine: Schema.NullOr(BotEngine),
+ sandbox: Schema.NullOr(BotSandbox),
+ runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_RUNTIME_MODE))),
+ usageCap: Schema.NullOr(BotUsageCap).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
+ groupId: Schema.NullOr(GroupId),
+ createdAt: IsoDateTime,
+ updatedAt: IsoDateTime,
+});
+
+export const BotUpdatedPayload = Schema.Struct({
+ botId: BotId,
+ name: Schema.optional(TrimmedNonEmptyString),
+ title: Schema.optional(TrimmedNonEmptyString),
+ label: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
+ description: Schema.optional(Schema.NullOr(Schema.String)),
+ disabledMcpServerIds: Schema.optional(Schema.Array(McpServerId)),
+ avatar: Schema.optional(BotAvatar),
+ engine: Schema.optional(Schema.NullOr(BotEngine)),
+ sandbox: Schema.optional(Schema.NullOr(BotSandbox)),
+ runtimeMode: Schema.optional(RuntimeMode),
+ usageCap: Schema.optional(Schema.NullOr(BotUsageCap)),
+ groupId: Schema.optional(Schema.NullOr(GroupId)),
+ updatedAt: IsoDateTime,
+});
+
+export const BotArchivedPayload = Schema.Struct({
+ botId: BotId,
+ archivedAt: IsoDateTime,
+ updatedAt: IsoDateTime,
+});
+
+export const BotRestoredPayload = Schema.Struct({
+ botId: BotId,
+ updatedAt: IsoDateTime,
+});
+
+export const GroupCreatedPayload = Schema.Struct({
+ groupId: GroupId,
+ name: TrimmedNonEmptyString,
+ // Defaults keep pre-membership group.created events replayable.
+ bossBotId: Schema.NullOr(BotId).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
+ members: Schema.Array(GroupMembership).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
+ createdAt: IsoDateTime,
+ updatedAt: IsoDateTime,
+});
+
+export const GroupRenamedPayload = Schema.Struct({
+ groupId: GroupId,
+ name: TrimmedNonEmptyString,
+ updatedAt: IsoDateTime,
+});
+
+export const GroupDeletedPayload = Schema.Struct({
+ groupId: GroupId,
+ deletedAt: IsoDateTime,
+});
+
+export const GroupMemberAssignedPayload = Schema.Struct({
+ groupId: GroupId,
+ member: GroupMembership,
+ updatedAt: IsoDateTime,
+});
+
+export const GroupMemberUnassignedPayload = Schema.Struct({
+ groupId: GroupId,
+ botId: BotId,
+ updatedAt: IsoDateTime,
+});
+
+export const GroupBossSetPayload = Schema.Struct({
+ groupId: GroupId,
+ bossBotId: BotId,
+ previousBossBotId: Schema.NullOr(BotId),
+ previousBossRole: Schema.NullOr(Schema.Literals(["specialist", "unassigned"])),
+ updatedAt: IsoDateTime,
+});
+
+export const McpServerCreatedPayload = Schema.Struct({
+ mcpServer: McpServer,
+});
+
+export const McpServerUpdatedPayload = Schema.Struct({
+ mcpServer: McpServer,
+});
+
+export const McpServerDeletedPayload = Schema.Struct({
+ mcpServerId: McpServerId,
+ deletedAt: IsoDateTime,
+});
+
+export const McpServerEnabledPayload = Schema.Struct({
+ mcpServer: McpServer,
+});
+
+export const McpServerDisabledPayload = Schema.Struct({
+ mcpServer: McpServer,
+});
+
export const ThreadCreatedPayload = Schema.Struct({
threadId: ThreadId,
projectId: ProjectId,
+ botId: Schema.optional(Schema.NullOr(BotId)),
+ groupId: Schema.optional(Schema.NullOr(GroupId)),
title: TrimmedNonEmptyString,
modelSelection: ModelSelection,
runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_RUNTIME_MODE))),
@@ -1270,6 +1735,7 @@ export const ThreadMessageSentPayload = Schema.Struct({
text: Schema.String,
attachments: Schema.optional(Schema.Array(ChatAttachment)),
turnId: Schema.NullOr(TurnId),
+ respondingBotId: Schema.optional(Schema.NullOr(BotId)),
streaming: Schema.Boolean,
createdAt: IsoDateTime,
updatedAt: IsoDateTime,
@@ -1285,6 +1751,7 @@ export const ThreadTurnStartRequestedPayload = Schema.Struct({
Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
),
sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
+ respondingBotId: Schema.optional(Schema.NullOr(BotId)),
createdAt: IsoDateTime,
});
@@ -1376,7 +1843,7 @@ const EventBaseFields = {
sequence: NonNegativeInt,
eventId: EventId,
aggregateKind: OrchestrationAggregateKind,
- aggregateId: Schema.Union([ProjectId, ThreadId]),
+ aggregateId: Schema.Union([ProjectId, BotId, GroupId, McpServerId, ThreadId]),
occurredAt: IsoDateTime,
commandId: Schema.NullOr(CommandId),
causationEventId: Schema.NullOr(EventId),
@@ -1400,6 +1867,81 @@ export const OrchestrationEvent = Schema.Union([
type: Schema.Literal("project.deleted"),
payload: ProjectDeletedPayload,
}),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("bot.created"),
+ payload: BotCreatedPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("bot.updated"),
+ payload: BotUpdatedPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("bot.archived"),
+ payload: BotArchivedPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("bot.restored"),
+ payload: BotRestoredPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("group.created"),
+ payload: GroupCreatedPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("group.renamed"),
+ payload: GroupRenamedPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("group.deleted"),
+ payload: GroupDeletedPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("group.member-assigned"),
+ payload: GroupMemberAssignedPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("group.member-unassigned"),
+ payload: GroupMemberUnassignedPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("group.boss-set"),
+ payload: GroupBossSetPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("mcp-server.created"),
+ payload: McpServerCreatedPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("mcp-server.updated"),
+ payload: McpServerUpdatedPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("mcp-server.deleted"),
+ payload: McpServerDeletedPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("mcp-server.enabled"),
+ payload: McpServerEnabledPayload,
+ }),
+ Schema.Struct({
+ ...EventBaseFields,
+ type: Schema.Literal("mcp-server.disabled"),
+ payload: McpServerDisabledPayload,
+ }),
Schema.Struct({
...EventBaseFields,
type: Schema.Literal("thread.created"),
diff --git a/packages/contracts/src/provider.test.ts b/packages/contracts/src/provider.test.ts
index ba7ca6374..4a5520f71 100644
--- a/packages/contracts/src/provider.test.ts
+++ b/packages/contracts/src/provider.test.ts
@@ -43,12 +43,23 @@ describe("ProviderSessionStartInput", () => {
runtimeMode: "full-access",
});
expect(parsed.runtimeMode).toBe("full-access");
+ expect(parsed.botSandbox).toBeUndefined();
expect(parsed.modelSelection?.instanceId).toBe("codex");
expect(parsed.modelSelection?.model).toBe("gpt-5.3-codex");
expect(getOptionValue(parsed.modelSelection?.options, "reasoningEffort")).toBe("high");
expect(getOptionValue(parsed.modelSelection?.options, "fastMode")).toBe(true);
});
+ it("accepts a bot sandbox provider", () => {
+ const parsed = decodeProviderSessionStartInput({
+ threadId: "thread-1",
+ provider: "codex",
+ botSandbox: "vercel",
+ runtimeMode: "full-access",
+ });
+ expect(parsed.botSandbox).toBe("vercel");
+ });
+
it("rejects payloads without runtime mode", () => {
expect(() =>
decodeProviderSessionStartInput({
diff --git a/packages/contracts/src/provider.ts b/packages/contracts/src/provider.ts
index 42a943923..cd513edd7 100644
--- a/packages/contracts/src/provider.ts
+++ b/packages/contracts/src/provider.ts
@@ -1,5 +1,6 @@
import * as Schema from "effect/Schema";
import { TrimmedNonEmptyString } from "./baseSchemas.ts";
+import { McpServer, McpServerId } from "./mcpServer.ts";
import {
ApprovalRequestId,
EventId,
@@ -9,6 +10,7 @@ import {
TurnId,
} from "./baseSchemas.ts";
import {
+ BotSandbox,
ChatAttachment,
ModelSelection,
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
@@ -43,6 +45,7 @@ export const ProviderSession = Schema.Struct({
model: Schema.optional(TrimmedNonEmptyString),
threadId: ThreadId,
resumeCursor: Schema.optional(Schema.Unknown),
+ mcpServerIds: Schema.optional(Schema.Array(McpServerId)),
activeTurnId: Schema.optional(TurnId),
createdAt: IsoDateTime,
updatedAt: IsoDateTime,
@@ -61,6 +64,8 @@ export const ProviderSessionStartInput = Schema.Struct({
resumeCursor: Schema.optional(Schema.Unknown),
approvalPolicy: Schema.optional(ProviderApprovalPolicy),
sandboxMode: Schema.optional(ProviderSandboxMode),
+ botSandbox: Schema.optional(Schema.NullOr(BotSandbox)),
+ mcpServers: Schema.optional(Schema.Array(McpServer)),
runtimeMode: RuntimeMode,
});
export type ProviderSessionStartInput = typeof ProviderSessionStartInput.Type;
diff --git a/packages/contracts/src/rpc.ts b/packages/contracts/src/rpc.ts
index 14363cfed..33ec8ede5 100644
--- a/packages/contracts/src/rpc.ts
+++ b/packages/contracts/src/rpc.ts
@@ -80,32 +80,6 @@ import {
ProviderUploadFeedbackResult,
} from "./provider.ts";
import { ProviderInstanceId } from "./providerInstance.ts";
-import {
- PullRequestActionInput,
- PullRequestActivity,
- PullRequestCommentInput,
- PullRequestCommentUpdateInput,
- PullRequestDetail,
- PullRequestDiffFileContentsInput,
- PullRequestDiffFileContentsResult,
- PullRequestInvalidateInput,
- PullRequestListInput,
- PullRequestListResult,
- PullRequestListStatsInput,
- PullRequestListStatsResult,
- PullRequestOperationError,
- PullRequestReactionInput,
- PullRequestRef,
- PullRequestReviewerCandidateList,
- PullRequestReviewerRequestInput,
- PullRequestSubmitReviewInput,
- PullRequestThreadCommentsInput,
- PullRequestThreadCommentsResult,
- PullRequestThreadReplyInput,
- PullRequestThreadResolutionInput,
- PullRequestUnavailableError,
- PullRequestUpdateInput,
-} from "./pullRequest.ts";
import {
RelayClientInstallFailedError,
RelayClientInstallProgressEventSchema,
@@ -194,6 +168,16 @@ import {
} from "./resourceTelemetry.ts";
import { UsageReadError, UsageSummary, UsageSummaryInput } from "./usage.ts";
import { ServerSettings, ServerSettingsError, ServerSettingsPatch } from "./settings.ts";
+import {
+ SubscriptionAuthCompleteInput,
+ SubscriptionAuthError,
+ SubscriptionAuthLoginProgress,
+ SubscriptionAuthLogoutInput,
+ SubscriptionAuthPollInput,
+ SubscriptionAuthStartInput,
+ SubscriptionAuthStartResult,
+ SubscriptionAuthStatuses,
+} from "./subscriptionAuth.ts";
import {
SourceControlCloneRepositoryInput,
SourceControlCloneRepositoryResult,
@@ -280,6 +264,12 @@ export const WS_METHODS = {
serverRemoveKeybinding: "server.removeKeybinding",
serverGetSettings: "server.getSettings",
serverUpdateSettings: "server.updateSettings",
+ subscriptionAuthList: "subscriptionAuth.list",
+ subscriptionAuthStart: "subscriptionAuth.start",
+ subscriptionAuthPoll: "subscriptionAuth.poll",
+ subscriptionAuthComplete: "subscriptionAuth.complete",
+ subscriptionAuthCancel: "subscriptionAuth.cancel",
+ subscriptionAuthLogout: "subscriptionAuth.logout",
serverDiscoverSourceControl: "server.discoverSourceControl",
serverGetTraceDiagnostics: "server.getTraceDiagnostics",
serverGetProcessDiagnostics: "server.getProcessDiagnostics",
@@ -296,25 +286,6 @@ export const WS_METHODS = {
cloudGetRelayClientStatus: "cloud.getRelayClientStatus",
cloudInstallRelayClient: "cloud.installRelayClient",
- // Pull request methods
- pullRequestsList: "pullRequests.list",
- pullRequestsListStats: "pullRequests.listStats",
- pullRequestsDetail: "pullRequests.detail",
- pullRequestsActivity: "pullRequests.activity",
- pullRequestsThreadComments: "pullRequests.threadComments",
- pullRequestsDiffFileContents: "pullRequests.diffFileContents",
- pullRequestsRunAction: "pullRequests.runAction",
- pullRequestsUpdate: "pullRequests.update",
- pullRequestsComment: "pullRequests.comment",
- pullRequestsUpdateComment: "pullRequests.updateComment",
- pullRequestsSubmitReview: "pullRequests.submitReview",
- pullRequestsReplyToThread: "pullRequests.replyToThread",
- pullRequestsSetThreadResolution: "pullRequests.setThreadResolution",
- pullRequestsSetReaction: "pullRequests.setReaction",
- pullRequestsInvalidate: "pullRequests.invalidate",
- pullRequestsReviewerCandidates: "pullRequests.reviewerCandidates",
- pullRequestsRequestReviewers: "pullRequests.requestReviewers",
-
// Source control methods
sourceControlLookupRepository: "sourceControl.lookupRepository",
sourceControlCloneRepository: "sourceControl.cloneRepository",
@@ -405,6 +376,42 @@ export const WsServerUpdateSettingsRpc = Rpc.make(WS_METHODS.serverUpdateSetting
error: Schema.Union([ServerSettingsError, EnvironmentAuthorizationError]),
});
+export const WsSubscriptionAuthListRpc = Rpc.make(WS_METHODS.subscriptionAuthList, {
+ payload: Schema.Struct({}),
+ success: SubscriptionAuthStatuses,
+ error: Schema.Union([SubscriptionAuthError, EnvironmentAuthorizationError]),
+});
+
+export const WsSubscriptionAuthStartRpc = Rpc.make(WS_METHODS.subscriptionAuthStart, {
+ payload: SubscriptionAuthStartInput,
+ success: SubscriptionAuthStartResult,
+ error: Schema.Union([SubscriptionAuthError, EnvironmentAuthorizationError]),
+});
+
+export const WsSubscriptionAuthPollRpc = Rpc.make(WS_METHODS.subscriptionAuthPoll, {
+ payload: SubscriptionAuthPollInput,
+ success: SubscriptionAuthLoginProgress,
+ error: Schema.Union([SubscriptionAuthError, EnvironmentAuthorizationError]),
+});
+
+export const WsSubscriptionAuthCompleteRpc = Rpc.make(WS_METHODS.subscriptionAuthComplete, {
+ payload: SubscriptionAuthCompleteInput,
+ success: SubscriptionAuthLoginProgress,
+ error: Schema.Union([SubscriptionAuthError, EnvironmentAuthorizationError]),
+});
+
+export const WsSubscriptionAuthCancelRpc = Rpc.make(WS_METHODS.subscriptionAuthCancel, {
+ payload: SubscriptionAuthPollInput,
+ success: Schema.Struct({}),
+ error: Schema.Union([SubscriptionAuthError, EnvironmentAuthorizationError]),
+});
+
+export const WsSubscriptionAuthLogoutRpc = Rpc.make(WS_METHODS.subscriptionAuthLogout, {
+ payload: SubscriptionAuthLogoutInput,
+ success: SubscriptionAuthStatuses,
+ error: Schema.Union([SubscriptionAuthError, EnvironmentAuthorizationError]),
+});
+
export const WsServerDiscoverSourceControlRpc = Rpc.make(WS_METHODS.serverDiscoverSourceControl, {
payload: Schema.Struct({}),
success: SourceControlDiscoveryResult,
@@ -488,130 +495,6 @@ export const WsServerGetBackgroundPolicyRpc = Rpc.make(WS_METHODS.serverGetBackg
error: EnvironmentAuthorizationError,
});
-const PullRequestRpcError = Schema.Union([
- PullRequestUnavailableError,
- PullRequestOperationError,
- EnvironmentAuthorizationError,
-]);
-
-export const WsPullRequestsListRpc = Rpc.make(WS_METHODS.pullRequestsList, {
- payload: PullRequestListInput,
- success: PullRequestListResult,
- error: PullRequestRpcError,
-});
-
-/**
- * The line counts for rows already on the page. Its own call because on GitHub the pair costs
- * 40-60% of the listing read that answers everything else on the row, so the rows arrive first
- * and their stats a moment later.
- */
-export const WsPullRequestsListStatsRpc = Rpc.make(WS_METHODS.pullRequestsListStats, {
- payload: PullRequestListStatsInput,
- success: PullRequestListStatsResult,
- error: PullRequestRpcError,
-});
-
-export const WsPullRequestsDetailRpc = Rpc.make(WS_METHODS.pullRequestsDetail, {
- payload: PullRequestRef,
- success: PullRequestDetail,
- error: PullRequestRpcError,
-});
-
-export const WsPullRequestsActivityRpc = Rpc.make(WS_METHODS.pullRequestsActivity, {
- payload: PullRequestRef,
- success: PullRequestActivity,
- error: PullRequestRpcError,
-});
-
-export const WsPullRequestsThreadCommentsRpc = Rpc.make(WS_METHODS.pullRequestsThreadComments, {
- payload: PullRequestThreadCommentsInput,
- success: PullRequestThreadCommentsResult,
- error: PullRequestRpcError,
-});
-
-export const WsPullRequestsDiffFileContentsRpc = Rpc.make(WS_METHODS.pullRequestsDiffFileContents, {
- payload: PullRequestDiffFileContentsInput,
- success: PullRequestDiffFileContentsResult,
- error: PullRequestRpcError,
-});
-
-export const WsPullRequestsRunActionRpc = Rpc.make(WS_METHODS.pullRequestsRunAction, {
- payload: PullRequestActionInput,
- success: Schema.Void,
- error: PullRequestRpcError,
-});
-
-export const WsPullRequestsUpdateRpc = Rpc.make(WS_METHODS.pullRequestsUpdate, {
- payload: PullRequestUpdateInput,
- success: Schema.Void,
- error: PullRequestRpcError,
-});
-
-export const WsPullRequestsCommentRpc = Rpc.make(WS_METHODS.pullRequestsComment, {
- payload: PullRequestCommentInput,
- success: Schema.Void,
- error: PullRequestRpcError,
-});
-
-export const WsPullRequestsUpdateCommentRpc = Rpc.make(WS_METHODS.pullRequestsUpdateComment, {
- payload: PullRequestCommentUpdateInput,
- success: Schema.Void,
- error: PullRequestRpcError,
-});
-
-export const WsPullRequestsSubmitReviewRpc = Rpc.make(WS_METHODS.pullRequestsSubmitReview, {
- payload: PullRequestSubmitReviewInput,
- success: Schema.Void,
- error: PullRequestRpcError,
-});
-
-export const WsPullRequestsReplyToThreadRpc = Rpc.make(WS_METHODS.pullRequestsReplyToThread, {
- payload: PullRequestThreadReplyInput,
- success: Schema.Void,
- error: PullRequestRpcError,
-});
-
-export const WsPullRequestsSetThreadResolutionRpc = Rpc.make(
- WS_METHODS.pullRequestsSetThreadResolution,
- {
- payload: PullRequestThreadResolutionInput,
- success: Schema.Void,
- error: PullRequestRpcError,
- },
-);
-
-export const WsPullRequestsSetReactionRpc = Rpc.make(WS_METHODS.pullRequestsSetReaction, {
- payload: PullRequestReactionInput,
- success: Schema.Void,
- error: PullRequestRpcError,
-});
-
-export const WsPullRequestsInvalidateRpc = Rpc.make(WS_METHODS.pullRequestsInvalidate, {
- payload: PullRequestInvalidateInput,
- success: Schema.Void,
- error: PullRequestRpcError,
-});
-
-/**
- * Read on its own rather than as part of the detail: the people who may be asked are only wanted
- * once somebody opens the menu, and reading them with every change request would spend a request
- * per host on a list nobody looked at.
- */
-export const WsPullRequestsReviewerCandidatesRpc = Rpc.make(
- WS_METHODS.pullRequestsReviewerCandidates,
- {
- payload: PullRequestRef,
- success: PullRequestReviewerCandidateList,
- error: PullRequestRpcError,
- },
-);
-
-export const WsPullRequestsRequestReviewersRpc = Rpc.make(WS_METHODS.pullRequestsRequestReviewers, {
- payload: PullRequestReviewerRequestInput,
- success: Schema.Void,
- error: PullRequestRpcError,
-});
-
export const WsSourceControlLookupRepositoryRpc = Rpc.make(
WS_METHODS.sourceControlLookupRepository,
{
@@ -1028,6 +911,12 @@ export const WsRpcGroup = RpcGroup.make(
WsServerRemoveKeybindingRpc,
WsServerGetSettingsRpc,
WsServerUpdateSettingsRpc,
+ WsSubscriptionAuthListRpc,
+ WsSubscriptionAuthStartRpc,
+ WsSubscriptionAuthPollRpc,
+ WsSubscriptionAuthCompleteRpc,
+ WsSubscriptionAuthCancelRpc,
+ WsSubscriptionAuthLogoutRpc,
WsServerDiscoverSourceControlRpc,
WsServerGetTraceDiagnosticsRpc,
WsServerGetProcessDiagnosticsRpc,
@@ -1041,23 +930,6 @@ export const WsRpcGroup = RpcGroup.make(
WsServerGetBackgroundPolicyRpc,
WsCloudGetRelayClientStatusRpc,
WsCloudInstallRelayClientRpc,
- WsPullRequestsListRpc,
- WsPullRequestsListStatsRpc,
- WsPullRequestsDetailRpc,
- WsPullRequestsActivityRpc,
- WsPullRequestsThreadCommentsRpc,
- WsPullRequestsDiffFileContentsRpc,
- WsPullRequestsRunActionRpc,
- WsPullRequestsUpdateRpc,
- WsPullRequestsCommentRpc,
- WsPullRequestsUpdateCommentRpc,
- WsPullRequestsSubmitReviewRpc,
- WsPullRequestsReplyToThreadRpc,
- WsPullRequestsSetThreadResolutionRpc,
- WsPullRequestsSetReactionRpc,
- WsPullRequestsInvalidateRpc,
- WsPullRequestsReviewerCandidatesRpc,
- WsPullRequestsRequestReviewersRpc,
WsSourceControlLookupRepositoryRpc,
WsSourceControlCloneRepositoryRpc,
WsSourceControlPublishRepositoryRpc,
diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts
index 76bb032c8..fec022d5d 100644
--- a/packages/contracts/src/settings.ts
+++ b/packages/contracts/src/settings.ts
@@ -30,6 +30,17 @@ export const TimestampFormat = Schema.Literals(["locale", "12-hour", "24-hour"])
export type TimestampFormat = typeof TimestampFormat.Type;
export const DEFAULT_TIMESTAMP_FORMAT: TimestampFormat = "locale";
+export const MIN_USAGE_REFRESH_MINUTES = 1;
+export const MAX_USAGE_REFRESH_MINUTES = 60;
+export const DEFAULT_USAGE_REFRESH_MINUTES = 5;
+export const UsageRefreshMinutes = Schema.Int.check(
+ Schema.isBetween({
+ minimum: MIN_USAGE_REFRESH_MINUTES,
+ maximum: MAX_USAGE_REFRESH_MINUTES,
+ }),
+);
+export type UsageRefreshMinutes = typeof UsageRefreshMinutes.Type;
+
export const SidebarProjectSortOrder = Schema.Literals(["updated_at", "created_at", "manual"]);
export type SidebarProjectSortOrder = typeof SidebarProjectSortOrder.Type;
export const DEFAULT_SIDEBAR_PROJECT_SORT_ORDER: SidebarProjectSortOrder = "updated_at";
@@ -254,6 +265,9 @@ export const ClientSettingsSchema = Schema.Struct({
timestampFormat: TimestampFormat.pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_TIMESTAMP_FORMAT)),
),
+ usageRefreshMinutes: UsageRefreshMinutes.pipe(
+ Schema.withDecodingDefault(Effect.succeed(DEFAULT_USAGE_REFRESH_MINUTES)),
+ ),
wordWrap: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
});
export type ClientSettings = typeof ClientSettingsSchema.Type;
@@ -951,6 +965,7 @@ export const ClientSettingsPatch = Schema.Struct({
sidebarThreadSortOrder: Schema.optionalKey(SidebarThreadSortOrder),
sidebarThreadPreviewCount: Schema.optionalKey(SidebarThreadPreviewCount),
timestampFormat: Schema.optionalKey(TimestampFormat),
+ usageRefreshMinutes: Schema.optionalKey(UsageRefreshMinutes),
wordWrap: Schema.optionalKey(Schema.Boolean),
});
export type ClientSettingsPatch = typeof ClientSettingsPatch.Type;
diff --git a/packages/contracts/src/subscriptionAuth.test.ts b/packages/contracts/src/subscriptionAuth.test.ts
new file mode 100644
index 000000000..a47937dba
--- /dev/null
+++ b/packages/contracts/src/subscriptionAuth.test.ts
@@ -0,0 +1,46 @@
+import { describe, expect, it } from "vite-plus/test";
+import * as Schema from "effect/Schema";
+
+import {
+ SubscriptionAuthLoginProgress,
+ SubscriptionAuthStartResult,
+ SubscriptionAuthStatuses,
+} from "./subscriptionAuth.ts";
+
+const decodeStatuses = Schema.decodeUnknownSync(SubscriptionAuthStatuses);
+const decodeStartResult = Schema.decodeUnknownSync(SubscriptionAuthStartResult);
+const decodeLoginProgress = Schema.decodeUnknownSync(SubscriptionAuthLoginProgress);
+
+describe("subscription auth contracts", () => {
+ it("decodes provider statuses without any credential fields", () => {
+ const decoded = decodeStatuses({
+ providers: [{ provider: "openai-codex", connected: true, expiresAt: 123 }],
+ });
+ expect(decoded.providers[0]).toEqual({
+ provider: "openai-codex",
+ connected: true,
+ expiresAt: 123,
+ });
+ });
+
+ it("decodes a remote-safe device login", () => {
+ expect(
+ decodeStartResult({
+ loginId: "login-1",
+ provider: "xai",
+ url: "https://auth.x.ai/device",
+ userCode: "ABCD-EFGH",
+ completion: "poll",
+ }),
+ ).toMatchObject({ provider: "xai", completion: "poll" });
+ });
+
+ it("strips credential-shaped fields from progress", () => {
+ const decoded = decodeLoginProgress({
+ status: "connected",
+ access: "must-not-cross-the-wire",
+ });
+ expect(decoded).toEqual({ status: "connected" });
+ expect("access" in decoded).toBe(false);
+ });
+});
diff --git a/packages/contracts/src/subscriptionAuth.ts b/packages/contracts/src/subscriptionAuth.ts
new file mode 100644
index 000000000..c10064754
--- /dev/null
+++ b/packages/contracts/src/subscriptionAuth.ts
@@ -0,0 +1,86 @@
+/**
+ * Subscription provider auth: bring-your-own-subscription login flows.
+ *
+ * A provider here is a consumer subscription (Claude Pro/Max, ChatGPT, Cursor,
+ * X Premium, Kimi For Coding) connected over OAuth. Tokens never cross this
+ * contract — the server holds them; clients only see connection status and
+ * login-flow progress.
+ */
+import * as Schema from "effect/Schema";
+
+export const SubscriptionProviderId = Schema.Literals([
+ "anthropic",
+ "openai-codex",
+ "cursor",
+ "xai",
+ "kimi-for-coding",
+]);
+export type SubscriptionProviderId = typeof SubscriptionProviderId.Type;
+
+export const SubscriptionProviderStatus = Schema.Struct({
+ provider: SubscriptionProviderId,
+ connected: Schema.Boolean,
+ /** ms epoch when the current access token expires. Absent when disconnected. */
+ expiresAt: Schema.optional(Schema.Number),
+});
+export type SubscriptionProviderStatus = typeof SubscriptionProviderStatus.Type;
+
+export const SubscriptionAuthStatuses = Schema.Struct({
+ providers: Schema.Array(SubscriptionProviderStatus),
+});
+export type SubscriptionAuthStatuses = typeof SubscriptionAuthStatuses.Type;
+
+export const SubscriptionAuthStartInput = Schema.Struct({
+ provider: SubscriptionProviderId,
+});
+export type SubscriptionAuthStartInput = typeof SubscriptionAuthStartInput.Type;
+
+/**
+ * A started login. `completion` says how it finishes: "poll" flows settle by
+ * repeated `poll` calls; "paste" flows need the user to paste a code into
+ * `complete`.
+ */
+export const SubscriptionAuthStartResult = Schema.Struct({
+ loginId: Schema.String,
+ provider: SubscriptionProviderId,
+ url: Schema.String,
+ userCode: Schema.optional(Schema.String),
+ instructions: Schema.optional(Schema.String),
+ completion: Schema.Literals(["poll", "paste"]),
+});
+export type SubscriptionAuthStartResult = typeof SubscriptionAuthStartResult.Type;
+
+export const SubscriptionAuthPollInput = Schema.Struct({
+ loginId: Schema.String,
+});
+export type SubscriptionAuthPollInput = typeof SubscriptionAuthPollInput.Type;
+
+export const SubscriptionAuthCompleteInput = Schema.Struct({
+ loginId: Schema.String,
+ /** Pasted authorization input: full URL, `code#state`, or bare code. */
+ code: Schema.String,
+});
+export type SubscriptionAuthCompleteInput = typeof SubscriptionAuthCompleteInput.Type;
+
+export const SubscriptionAuthLoginProgress = Schema.Union([
+ Schema.Struct({ status: Schema.Literal("connected") }),
+ Schema.Struct({ status: Schema.Literal("pending"), nextPollMs: Schema.Number }),
+ Schema.Struct({ status: Schema.Literal("failed"), error: Schema.String }),
+]);
+export type SubscriptionAuthLoginProgress = typeof SubscriptionAuthLoginProgress.Type;
+
+export const SubscriptionAuthLogoutInput = Schema.Struct({
+ provider: SubscriptionProviderId,
+});
+export type SubscriptionAuthLogoutInput = typeof SubscriptionAuthLogoutInput.Type;
+
+export class SubscriptionAuthError extends Schema.TaggedErrorClass<SubscriptionAuthError>()(
+ "SubscriptionAuthError",
+ {
+ reason: Schema.String,
+ },
+) {
+ override get message(): string {
+ return this.reason;
+ }
+}
diff --git a/packages/contracts/src/usage.ts b/packages/contracts/src/usage.ts
index cde888a61..81fa6fef5 100644
--- a/packages/contracts/src/usage.ts
+++ b/packages/contracts/src/usage.ts
@@ -15,6 +15,7 @@
import * as Schema from "effect/Schema";
import { NonNegativeInt, TrimmedNonEmptyString } from "./baseSchemas.ts";
+import { SubscriptionProviderId } from "./subscriptionAuth.ts";
/**
* Bumped whenever the shape of {@link UsageSummary} changes incompatibly. The
@@ -160,6 +161,31 @@ export const UsagePricing = Schema.Struct({
});
export type UsagePricing = typeof UsagePricing.Type;
+export const UsagePlanWindowKind = Schema.Literals(["session", "weekly", "model"]);
+export type UsagePlanWindowKind = typeof UsagePlanWindowKind.Type;
+
+/** One subscription window, as a percent used of that cap. */
+export const UsagePlanWindow = Schema.Struct({
+ kind: UsagePlanWindowKind,
+ label: TrimmedNonEmptyString,
+ usedPercent: Schema.Number,
+ resetsAt: Schema.NullOr(Schema.String),
+});
+export type UsagePlanWindow = typeof UsagePlanWindow.Type;
+
+export const UsagePlanLimitsStatus = Schema.Literals(["ok", "failed"]);
+export type UsagePlanLimitsStatus = typeof UsagePlanLimitsStatus.Type;
+
+/** Live plan meters for one Settings → Providers login. */
+export const UsageProviderPlanLimits = Schema.Struct({
+ provider: SubscriptionProviderId,
+ status: UsagePlanLimitsStatus,
+ plan: Schema.NullOr(TrimmedNonEmptyString),
+ message: Schema.NullOr(TrimmedNonEmptyString),
+ windows: Schema.Array(UsagePlanWindow),
+});
+export type UsageProviderPlanLimits = typeof UsageProviderPlanLimits.Type;
+
export const UsageSummaryInput = Schema.Struct({
/** Inclusive first day of the window, in `timeZone`. */
sinceDay: UsageDay,
@@ -190,6 +216,8 @@ export const UsageSummary = Schema.Struct({
pricing: UsagePricing,
/** Wall-clock cost of the scan, surfaced in diagnostics. */
scanDurationMs: NonNegativeInt,
+ /** Live Claude and Codex plan windows. Absent on older servers. */
+ planLimits: Schema.optional(Schema.Array(UsageProviderPlanLimits)),
});
export type UsageSummary = typeof UsageSummary.Type;