Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Declare each route's actor on the route instead of a parallel list (#2352)

Regan Bell2ae451f0af64
diff --git a/src/api/routes/auth-broker.ts b/src/api/routes/auth-broker.ts
index 0438c0f34..dfa36774c 100644
--- a/src/api/routes/auth-broker.ts
+++ b/src/api/routes/auth-broker.ts
@@ -219,11 +219,11 @@ async function redeemInvitation(ctx: ApiCtx): Promise<void> {
}
export const authBrokerRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/auth/invitations/redeem", auth: "source", handle: redeemInvitation },
- { method: "POST", path: "/v1/auth/trusted/admin", auth: "source", handle: trustedAdmin },
- { method: "POST", path: "/v1/auth/broker/sessions", auth: "source", handle: brokerSession },
- { method: "POST", path: "/v1/auth/broker/sessions/use", auth: "source", handle: brokerSession },
- { method: "POST", path: "/v1/auth/broker/sessions/revoke", auth: "source", handle: brokerSession },
- { method: "POST", path: "/v1/auth/broker/claim", auth: "source", handle: claimBrokerNonce },
+ { method: "POST", path: "/v1/auth/invitations/redeem", actor: "system", auth: "source", handle: redeemInvitation },
+ { method: "POST", path: "/v1/auth/trusted/admin", actor: "system", auth: "source", handle: trustedAdmin },
+ { method: "POST", path: "/v1/auth/broker/sessions", actor: "system", auth: "source", handle: brokerSession },
+ { method: "POST", path: "/v1/auth/broker/sessions/use", actor: "system", auth: "source", handle: brokerSession },
+ { method: "POST", path: "/v1/auth/broker/sessions/revoke", actor: "person", auth: "source", handle: brokerSession },
+ { method: "POST", path: "/v1/auth/broker/claim", actor: "system", auth: "source", handle: claimBrokerNonce },
{ method: "GET", path: "/v1/auth/broker/email-allowed", auth: "source", handle: emailAllowed },
];
diff --git a/src/api/routes/background-work.ts b/src/api/routes/background-work.ts
index 0ac6968f6..2155437d2 100644
--- a/src/api/routes/background-work.ts
+++ b/src/api/routes/background-work.ts
@@ -84,5 +84,5 @@ async function backgroundWork(ctx: ApiCtx): Promise<void> {
export const backgroundWorkRoutes: ReadonlyArray<Route<ApiCtx>> = [
{ method: "GET", path: "/v1/background-work", auth: "source", handle: backgroundWork },
- { method: "POST", path: "/v1/background-work", auth: "source", handle: backgroundWork },
+ { method: "POST", path: "/v1/background-work", actor: "system", auth: "source", handle: backgroundWork },
];
diff --git a/src/api/routes/blobs.ts b/src/api/routes/blobs.ts
index fc26f81ce..b5fea27e6 100644
--- a/src/api/routes/blobs.ts
+++ b/src/api/routes/blobs.ts
@@ -103,6 +103,6 @@ async function getBlob(ctx: BaseCtx): Promise<void> {
}
export const blobRoutes: ReadonlyArray<Route<BaseCtx>> = [
- { method: "POST", path: "/v1/blobs", auth: "either", handle: putBlob },
+ { method: "POST", path: "/v1/blobs", actor: "system", auth: "either", handle: putBlob },
{ method: "GET", path: "/v1/blobs/:id", auth: "either", handle: getBlob },
];
diff --git a/src/api/routes/connectors.ts b/src/api/routes/connectors.ts
index 8d48eaf47..efdc96339 100644
--- a/src/api/routes/connectors.ts
+++ b/src/api/routes/connectors.ts
@@ -553,9 +553,26 @@ export const connectorRoutes: ReadonlyArray<Route<ApiCtx>> = [
{ method: "GET", path: "/v1/connectors/gmail/sent", auth: "source", handle: gmailSent },
{ method: "POST", path: "/v1/connectors/oauth/consent/mint", auth: { aud: "oauth-consent" }, handle: consentMint },
{ method: "GET", path: "/v1/connectors/oauth/consent/redeem/:linkId", auth: "source", handle: consentRedeem },
- { match: (m, p) => m === "GET" && parseOAuthRoute(p)?.action === "start", auth: "source", handle: oauthStart },
- { method: "GET", path: "/v1/connectors/oauth/status", auth: "source", handle: oauthStatus },
- { method: "POST", path: "/v1/connectors/oauth/revoke", auth: "either", handle: oauthRevoke },
- { method: "POST", path: "/v1/connectors/token", auth: "source", handle: setToken },
+ {
+ match: (m, p) => m === "GET" && parseOAuthRoute(p)?.action === "start",
+ actor: "query.principalId",
+ auth: "source",
+ handle: oauthStart,
+ },
+ {
+ method: "GET",
+ path: "/v1/connectors/oauth/status",
+ actor: "query.principalId",
+ auth: "source",
+ handle: oauthStatus,
+ },
+ {
+ method: "POST",
+ path: "/v1/connectors/oauth/revoke",
+ actor: "body.principalId",
+ auth: "either",
+ handle: oauthRevoke,
+ },
+ { method: "POST", path: "/v1/connectors/token", actor: "body.principalId", auth: "source", handle: setToken },
{ method: "GET", path: "/v1/connectors/catalog", auth: "source", handle: catalog },
];
diff --git a/src/api/routes/context-policy.ts b/src/api/routes/context-policy.ts
index 22f3deb2f..e9a301467 100644
--- a/src/api/routes/context-policy.ts
+++ b/src/api/routes/context-policy.ts
@@ -91,6 +91,6 @@ export async function setContextPolicy(ctx: ApiCtx): Promise<void> {
}
export const contextPolicyRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "GET", path: "/v1/contexts/policy", auth: "source", handle: getContextPolicy },
+ { method: "GET", path: "/v1/contexts/policy", actor: "query.principalId", auth: "source", handle: getContextPolicy },
{ method: "PUT", path: "/v1/contexts/policy", auth: "source", handle: setContextPolicy },
];
diff --git a/src/api/routes/context.ts b/src/api/routes/context.ts
index 24c1e1538..d0ff90503 100644
--- a/src/api/routes/context.ts
+++ b/src/api/routes/context.ts
@@ -253,8 +253,14 @@ async function fulfillContextRequest(ctx: ApiCtx): Promise<void> {
}
export const contextRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/surface-context", auth: "either", handle: createSurfaceContextRequest },
- { method: "POST", path: "/v1/surface-file", auth: "either", handle: createSurfaceFileRequest },
+ { method: "POST", path: "/v1/surface-context", actor: "system", auth: "either", handle: createSurfaceContextRequest },
+ { method: "POST", path: "/v1/surface-file", actor: "system", auth: "either", handle: createSurfaceFileRequest },
{ method: "GET", path: "/v1/surface-context/pending", auth: "source", handle: listPendingContextRequests },
- { method: "POST", path: "/v1/surface-context/:id/result", auth: "source", handle: fulfillContextRequest },
+ {
+ method: "POST",
+ path: "/v1/surface-context/:id/result",
+ actor: "system",
+ auth: "source",
+ handle: fulfillContextRequest,
+ },
];
diff --git a/src/api/routes/crons.ts b/src/api/routes/crons.ts
index 367a14481..557539ff8 100644
--- a/src/api/routes/crons.ts
+++ b/src/api/routes/crons.ts
@@ -10,7 +10,7 @@ import { isObj } from "./shared.ts";
import { notifyOwnerOfCronEdit } from "../../triggers/edit-notice.ts";
import { canAdministerCron } from "../control-service.ts";
import { CRON_PATCH_NOTHING_TO_CHANGE } from "../control-service.ts";
-import { type ApiCtx, type Route } from "./route.ts";
+import { withActor, type ApiCtx, type Route } from "./route.ts";
function defaultTimezoneFor(capability: CapabilityClaims | null): string {
return typeof capability?.timezone === "string" && capability.timezone.trim()
@@ -451,19 +451,21 @@ async function cronById(ctx: ApiCtx): Promise<void> {
}
export const cronRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/crons", auth: "either", handle: createCron },
- { method: "GET", path: "/v1/crons", auth: "either", handle: listCrons },
- { method: "POST", path: "/v1/crons/:id/disable", auth: "either", handle: disableCron },
- { method: "POST", path: "/v1/crons/:id/destination", auth: "either", handle: retargetCron },
- { method: "POST", path: "/v1/crons/:id/run", auth: "either", handle: runCronNow },
+ { method: "POST", path: "/v1/crons", actor: "body.createdBy", auth: "either", handle: createCron },
+ { method: "GET", path: "/v1/crons", actor: "query.viewer", auth: "either", handle: listCrons },
{ method: "POST", path: "/v1/crons/:id/note", auth: "either", handle: noteCron },
- { method: "GET", path: "/v1/crons/:id/runs", auth: "either", handle: cronRuns },
- {
- match: (m, p) =>
- p.startsWith("/v1/crons/") &&
- !p.slice("/v1/crons/".length).includes("/") &&
- (m === "GET" || m === "PATCH" || m === "DELETE"),
- auth: "either",
- handle: cronById,
- },
+ ...withActor("query.principalId", [
+ { method: "POST", path: "/v1/crons/:id/disable", auth: "either", handle: disableCron },
+ { method: "POST", path: "/v1/crons/:id/destination", auth: "either", handle: retargetCron },
+ { method: "POST", path: "/v1/crons/:id/run", auth: "either", handle: runCronNow },
+ { method: "GET", path: "/v1/crons/:id/runs", auth: "either", handle: cronRuns },
+ {
+ match: (m, p) =>
+ p.startsWith("/v1/crons/") &&
+ !p.slice("/v1/crons/".length).includes("/") &&
+ (m === "GET" || m === "PATCH" || m === "DELETE"),
+ auth: "either",
+ handle: cronById,
+ },
+ ]),
];
diff --git a/src/api/routes/deployment-layer.ts b/src/api/routes/deployment-layer.ts
index 37acb990e..0777890a0 100644
--- a/src/api/routes/deployment-layer.ts
+++ b/src/api/routes/deployment-layer.ts
@@ -81,5 +81,5 @@ async function putDeploymentLayer(ctx: ApiCtx): Promise<void> {
export const deploymentLayerRoutes: ReadonlyArray<Route<ApiCtx>> = [
{ method: "GET", path: "/v1/deployment-layer", auth: "source", handle: getDeploymentLayer },
- { method: "PUT", path: "/v1/deployment-layer", auth: "source", handle: putDeploymentLayer },
+ { method: "PUT", path: "/v1/deployment-layer", actor: "system", auth: "source", handle: putDeploymentLayer },
];
diff --git a/src/api/routes/deployment-live-smoke.ts b/src/api/routes/deployment-live-smoke.ts
index 703f0d061..e1d009282 100644
--- a/src/api/routes/deployment-live-smoke.ts
+++ b/src/api/routes/deployment-live-smoke.ts
@@ -61,5 +61,5 @@ async function deploymentLiveSmoke(ctx: ApiCtx): Promise<void> {
}
export const deploymentLiveSmokeRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/deployment/live-session", auth: "source", handle: deploymentLiveSmoke },
+ { method: "POST", path: "/v1/deployment/live-session", actor: "system", auth: "source", handle: deploymentLiveSmoke },
];
diff --git a/src/api/routes/deployments.ts b/src/api/routes/deployments.ts
index 02ad38f85..7ddbf3ec1 100644
--- a/src/api/routes/deployments.ts
+++ b/src/api/routes/deployments.ts
@@ -1717,13 +1717,13 @@ export const deploymentRawRoutes: ReadonlyArray<Route<BaseCtx>> = [
];
export const deploymentRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/deployments", auth: "source", handle: createDeployment },
- { method: "GET", path: "/v1/deployments", auth: "either", handle: listDeployments },
+ { method: "POST", path: "/v1/deployments", actor: "body.createdBy", auth: "source", handle: createDeployment },
+ { method: "GET", path: "/v1/deployments", actor: "query.principalId", auth: "either", handle: listDeployments },
{ method: "GET", path: "/v1/deployments/:id", auth: "either", handle: getDeployment },
{ method: "GET", path: "/v1/deployments/:id/fetch", auth: "either", handle: fetchDeployment },
{ method: "GET", path: "/v1/deployments/:id/logs", auth: "either", handle: deploymentLogs },
{ method: "GET", path: "/v1/deployments/:id/git-url", auth: "either", handle: deploymentGitUrl },
- { method: "GET", path: "/v1/deployments/:id/share", auth: "either", handle: getDeploymentShares },
+ { method: "GET", path: "/v1/deployments/:id/share", actor: "person", auth: "either", handle: getDeploymentShares },
{ method: "POST", path: "/v1/deployments/:id/share", auth: "either", handle: shareDeployment },
{ method: "POST", path: "/v1/deployments/:id/rollback", auth: "source", handle: rollbackDeployment },
{ method: "POST", path: "/v1/deployments/:id/redeploy", auth: "source", handle: redeployDeployment },
diff --git a/src/api/routes/directory.ts b/src/api/routes/directory.ts
index a870a6a8f..8033b532e 100644
--- a/src/api/routes/directory.ts
+++ b/src/api/routes/directory.ts
@@ -3,7 +3,7 @@ import type { DirectoryMember } from "../../directory/directory-store.ts";
import { canonicalPerson } from "../../directory/person.ts";
import { sendJson } from "../http.ts";
import { audit, isObj, orgScope } from "./shared.ts";
-import { type ApiCtx, type Route } from "./route.ts";
+import { withActor, type ApiCtx, type Route } from "./route.ts";
const numOrUndef = (v: unknown): number | undefined => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
@@ -180,10 +180,7 @@ async function channelMembership(ctx: ApiCtx): Promise<void> {
}
export const directoryRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/principals/:id/deactivate", auth: "source", handle: deactivatePrincipal },
- { method: "POST", path: "/v1/principals/:id/reactivate", auth: "source", handle: reactivatePrincipal },
{ method: "GET", path: "/v1/principals/:id/canonical", auth: "source", handle: canonicalPrincipal },
- { method: "POST", path: "/v1/directory", auth: "source", handle: pushDirectory },
{ method: "GET", path: "/v1/directory/meta", auth: "source", handle: directoryMeta },
{
method: "GET",
@@ -191,5 +188,10 @@ export const directoryRoutes: ReadonlyArray<Route<ApiCtx>> = [
auth: "source",
handle: channelMembership,
},
- { method: "GET", path: "/v1/directory/resolve", auth: "either", handle: resolveDirectory },
+ { method: "GET", path: "/v1/directory/resolve", actor: "person", auth: "either", handle: resolveDirectory },
+ ...withActor("system", [
+ { method: "POST", path: "/v1/principals/:id/deactivate", auth: "source", handle: deactivatePrincipal },
+ { method: "POST", path: "/v1/principals/:id/reactivate", auth: "source", handle: reactivatePrincipal },
+ { method: "POST", path: "/v1/directory", auth: "source", handle: pushDirectory },
+ ]),
];
diff --git a/src/api/routes/egress-audit.ts b/src/api/routes/egress-audit.ts
index cae4c19c4..ffa626bd6 100644
--- a/src/api/routes/egress-audit.ts
+++ b/src/api/routes/egress-audit.ts
@@ -54,5 +54,5 @@ async function ingestEgressAudit(ctx: ApiCtx): Promise<void> {
}
export const egressAuditRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/egress-audit", auth: "source", handle: ingestEgressAudit },
+ { method: "POST", path: "/v1/egress-audit", actor: "system", auth: "source", handle: ingestEgressAudit },
];
diff --git a/src/api/routes/file-uploads.ts b/src/api/routes/file-uploads.ts
index e7c4eca70..f06ad3644 100644
--- a/src/api/routes/file-uploads.ts
+++ b/src/api/routes/file-uploads.ts
@@ -3,7 +3,7 @@ import { sendJson } from "../http.ts";
import { scopeId, type ScopeId } from "../../types.ts";
import { FileUploadError } from "../../files/direct-file-upload.ts";
import { isObj, audit } from "./shared.ts";
-import type { ApiCtx, Route } from "./route.ts";
+import { withActor, type ApiCtx, type Route } from "./route.ts";
async function handleUpload(ctx: ApiCtx): Promise<void> {
const { res, deps, app, capability, actor, params, method, pathname } = ctx;
@@ -78,10 +78,12 @@ async function handleUpload(ctx: ApiCtx): Promise<void> {
}
export const fileUploadRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "GET", path: "/v1/files/upload-client", auth: "either", handle: handleUpload },
- { method: "POST", path: "/v1/files/uploads", auth: "either", handle: handleUpload },
- { method: "GET", path: "/v1/files/uploads/:id", auth: "either", handle: handleUpload },
- { method: "POST", path: "/v1/files/uploads/:id/parts/:part", auth: "either", handle: handleUpload },
- { method: "POST", path: "/v1/files/uploads/:id/complete", auth: "either", handle: handleUpload },
- { method: "DELETE", path: "/v1/files/uploads/:id", auth: "either", handle: handleUpload },
+ { method: "GET", path: "/v1/files/upload-client", actor: "query.viewer", auth: "either", handle: handleUpload },
+ { method: "GET", path: "/v1/files/uploads/:id", actor: "query.viewer", auth: "either", handle: handleUpload },
+ ...withActor("body.principalId", [
+ { method: "POST", path: "/v1/files/uploads", auth: "either", handle: handleUpload },
+ { method: "POST", path: "/v1/files/uploads/:id/parts/:part", auth: "either", handle: handleUpload },
+ { method: "POST", path: "/v1/files/uploads/:id/complete", auth: "either", handle: handleUpload },
+ { method: "DELETE", path: "/v1/files/uploads/:id", auth: "either", handle: handleUpload },
+ ]),
];
diff --git a/src/api/routes/inbox.ts b/src/api/routes/inbox.ts
index 58657d276..d06dae7d3 100644
--- a/src/api/routes/inbox.ts
+++ b/src/api/routes/inbox.ts
@@ -245,8 +245,8 @@ async function viewers(ctx: ApiCtx): Promise<void> {
}
export const inboxRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "GET", path: "/v1/inbox", auth: "source", handle: inbox },
- { method: "POST", path: "/v1/inbox/viewers", auth: "source", handle: viewers },
- { method: "GET", path: "/v1/inbox/access", auth: "source", handle: access },
- { method: "PUT", path: "/v1/inbox", auth: "source", handle: inbox },
+ { method: "GET", path: "/v1/inbox", actor: "query.principalId", auth: "source", handle: inbox },
+ { method: "POST", path: "/v1/inbox/viewers", actor: "system", auth: "source", handle: viewers },
+ { method: "GET", path: "/v1/inbox/access", actor: "query.principalId", auth: "source", handle: access },
+ { method: "PUT", path: "/v1/inbox", actor: "query.principalId", auth: "source", handle: inbox },
];
diff --git a/src/api/routes/keychain.ts b/src/api/routes/keychain.ts
index 8c3cab74a..5e2d5b4dc 100644
--- a/src/api/routes/keychain.ts
+++ b/src/api/routes/keychain.ts
@@ -315,13 +315,13 @@ async function handleApproval(ctx: ApiCtx): Promise<void> {
}
export const keychainRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/keychain/credentials", auth: "either", handle: handleKeychain },
+ { method: "POST", path: "/v1/keychain/credentials", actor: "system", auth: "either", handle: handleKeychain },
{ method: "GET", path: "/v1/keychain/credentials", auth: "either", handle: handleKeychain },
{ method: "GET", path: "/v1/keychain/overview", auth: "either", handle: handleKeychain },
- { method: "DELETE", path: "/v1/keychain/credentials/:id", auth: "either", handle: handleKeychain },
+ { method: "DELETE", path: "/v1/keychain/credentials/:id", actor: "system", auth: "either", handle: handleKeychain },
{ method: "GET", path: "/v1/keychain/grants", auth: "either", handle: handleKeychain },
- { method: "POST", path: "/v1/keychain/grants/:id/revoke", auth: "either", handle: handleKeychain },
- { method: "POST", path: "/v1/keychain/asks", auth: "either", handle: handleKeychain },
+ { method: "POST", path: "/v1/keychain/grants/:id/revoke", actor: "system", auth: "either", handle: handleKeychain },
+ { method: "POST", path: "/v1/keychain/asks", actor: "system", auth: "either", handle: handleKeychain },
{ method: "GET", path: "/v1/keychain/asks", auth: "either", handle: handleKeychain },
{ method: "POST", path: "/v1/keychain/approvals/:id", auth: "source", handle: handleApproval },
];
diff --git a/src/api/routes/loop-ingress.ts b/src/api/routes/loop-ingress.ts
index eb237467c..8bc545f83 100644
--- a/src/api/routes/loop-ingress.ts
+++ b/src/api/routes/loop-ingress.ts
@@ -2,7 +2,7 @@ import { scopeId } from "../../types.ts";
import { sendJson, readRawBody, PayloadTooLargeError } from "../http.ts";
import { loadAdministrable } from "./loops.ts";
import { isObj } from "./shared.ts";
-import type { ApiCtx, BaseCtx, Route } from "./route.ts";
+import { withActor, type ApiCtx, type BaseCtx, type Route } from "./route.ts";
import type { LoopIngress, IngressSetup } from "../../loops/ingress.ts";
import { errMessage } from "../../util/errors.ts";
@@ -82,9 +82,11 @@ async function receive(ctx: BaseCtx) {
}
export const loopIngressRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "GET", path: "/v1/loops/:id/ingestion", auth: "source", handle: list },
- { method: "POST", path: "/v1/loops/:id/ingestion", auth: "source", handle: change },
- { method: "PATCH", path: "/v1/loops/:id/ingestion/:sourceId", auth: "source", handle: change },
+ ...withActor("query.principalId", [
+ { method: "GET", path: "/v1/loops/:id/ingestion", auth: "source", handle: list },
+ { method: "POST", path: "/v1/loops/:id/ingestion", auth: "source", handle: change },
+ { method: "PATCH", path: "/v1/loops/:id/ingestion/:sourceId", auth: "source", handle: change },
+ ]),
];
export const loopIngressRawRoutes: ReadonlyArray<Route<BaseCtx>> = [
diff --git a/src/api/routes/loop-items.ts b/src/api/routes/loop-items.ts
index 75e63c014..2df7f3b71 100644
--- a/src/api/routes/loop-items.ts
+++ b/src/api/routes/loop-items.ts
@@ -4,7 +4,7 @@ import { canonicalJson } from "../../util/objects.ts";
import { errMessage } from "../../util/errors.ts";
import { sendJson } from "../http.ts";
import { isObj } from "./shared.ts";
-import { type ApiCtx, type Route } from "./route.ts";
+import { withActor, type ApiCtx, type Route } from "./route.ts";
import {
requireLoopAuthority,
canAdministerLoop,
@@ -678,22 +678,24 @@ function serializeItemAction(handler: (ctx: ApiCtx) => Promise<void>): (ctx: Api
export const loopItemRoutes: ReadonlyArray<Route<ApiCtx>> = [
{ method: "POST", path: "/v1/loops/inbox/sent-chat", auth: "source", handle: ensureSentChat },
- { method: "GET", path: "/v1/loops/inbox", auth: "either", handle: getInboxLoop },
- { method: "POST", path: "/v1/loops/inbox/sync-cron", auth: "source", handle: ensureInboxSyncCron },
- { method: "GET", path: "/v1/loops/:id/items", auth: "either", handle: listItems },
- { method: "POST", path: "/v1/loops/:id/items", auth: "either", handle: ingestItems },
- { method: "GET", path: "/v1/loops/:id/items/:itemId", auth: "either", handle: getItem },
{ method: "GET", path: "/v1/loops/:id/items/:itemId/image", auth: "source", handle: serveItemImage },
- {
- method: "POST",
- path: "/v1/loops/:id/items/:itemId/action",
- auth: "either",
- handle: serializeItemAction(actOnItem),
- },
- {
- method: "POST",
- path: "/v1/loops/:id/items/:itemId/followup",
- auth: "either",
- handle: serializeItemAction(followUpOnItem),
- },
+ ...withActor("query.principalId", [
+ { method: "GET", path: "/v1/loops/inbox", auth: "either", handle: getInboxLoop },
+ { method: "POST", path: "/v1/loops/inbox/sync-cron", auth: "source", handle: ensureInboxSyncCron },
+ { method: "GET", path: "/v1/loops/:id/items", auth: "either", handle: listItems },
+ { method: "POST", path: "/v1/loops/:id/items", auth: "either", handle: ingestItems },
+ { method: "GET", path: "/v1/loops/:id/items/:itemId", auth: "either", handle: getItem },
+ {
+ method: "POST",
+ path: "/v1/loops/:id/items/:itemId/action",
+ auth: "either",
+ handle: serializeItemAction(actOnItem),
+ },
+ {
+ method: "POST",
+ path: "/v1/loops/:id/items/:itemId/followup",
+ auth: "either",
+ handle: serializeItemAction(followUpOnItem),
+ },
+ ]),
];
diff --git a/src/api/routes/loops.ts b/src/api/routes/loops.ts
index 6e7d0dbe2..ac3cd734f 100644
--- a/src/api/routes/loops.ts
+++ b/src/api/routes/loops.ts
@@ -20,7 +20,7 @@ import type { ScopedConfigStore } from "../../resolution/config-store.ts";
import { errMessage, swallow } from "../../util/errors.ts";
import { sendJson } from "../http.ts";
import { isObj, resolveCapabilityDestination } from "./shared.ts";
-import { type ApiCtx, type Route } from "./route.ts";
+import { withActor, type ApiCtx, type Route } from "./route.ts";
export interface LoopServiceDeps {
lock?: AdvisoryLock;
@@ -676,15 +676,17 @@ async function revokeShipGrant(ctx: ApiCtx): Promise<void> {
}
export const loopRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/loops", auth: "either", handle: createLoop },
- { method: "GET", path: "/v1/loops", auth: "either", handle: listLoops },
- { method: "GET", path: "/v1/loops/:id", auth: "either", handle: getLoop },
- { method: "PATCH", path: "/v1/loops/:id", auth: "either", handle: patchLoop },
- { method: "DELETE", path: "/v1/loops/:id", auth: "either", handle: deleteLoop },
- { method: "POST", path: "/v1/loops/:id/fire", auth: "either", handle: fireLoopNow },
{ method: "POST", path: "/v1/loops/:id/triage/preview", auth: "source", handle: previewLoopTriage },
- { method: "POST", path: "/v1/loops/:id/outputs/:outputId/decide", auth: "either", handle: decideOutput },
- { method: "POST", path: "/v1/loops/:id/grants", auth: "either", handle: graduateShipAction },
- { method: "POST", path: "/v1/loops/:id/autopilot", auth: "either", handle: setAutopilot },
- { method: "DELETE", path: "/v1/loops/:id/grants/:grantId", auth: "either", handle: revokeShipGrant },
+ ...withActor("query.principalId", [
+ { method: "POST", path: "/v1/loops", auth: "either", handle: createLoop },
+ { method: "GET", path: "/v1/loops", auth: "either", handle: listLoops },
+ { method: "GET", path: "/v1/loops/:id", auth: "either", handle: getLoop },
+ { method: "PATCH", path: "/v1/loops/:id", auth: "either", handle: patchLoop },
+ { method: "DELETE", path: "/v1/loops/:id", auth: "either", handle: deleteLoop },
+ { method: "POST", path: "/v1/loops/:id/fire", auth: "either", handle: fireLoopNow },
+ { method: "POST", path: "/v1/loops/:id/outputs/:outputId/decide", auth: "either", handle: decideOutput },
+ { method: "POST", path: "/v1/loops/:id/grants", auth: "either", handle: graduateShipAction },
+ { method: "POST", path: "/v1/loops/:id/autopilot", auth: "either", handle: setAutopilot },
+ { method: "DELETE", path: "/v1/loops/:id/grants/:grantId", auth: "either", handle: revokeShipGrant },
+ ]),
];
diff --git a/src/api/routes/projects.ts b/src/api/routes/projects.ts
index 4847b52b3..88f397dd7 100644
--- a/src/api/routes/projects.ts
+++ b/src/api/routes/projects.ts
@@ -1,6 +1,6 @@
import { sendJson } from "../http.ts";
import { isObj } from "./shared.ts";
-import { type ApiCtx, type Route } from "./route.ts";
+import { withActor, type ApiCtx, type Route } from "./route.ts";
function capabilityPrincipal(ctx: ApiCtx, requested: string): string | null {
if (!ctx.capability) return requested;
@@ -108,11 +108,13 @@ async function clearProjectSlackChannel(ctx: ApiCtx): Promise<void> {
}
export const projectRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "GET", path: "/v1/projects", auth: "either", handle: listProjects },
- { method: "POST", path: "/v1/projects", auth: "either", handle: createProject },
+ { method: "GET", path: "/v1/projects", actor: "query.principalId", auth: "either", handle: listProjects },
{ method: "PATCH", path: "/v1/projects/:id", auth: "either", handle: renameProject },
- { method: "POST", path: "/v1/projects/:id/members", auth: "either", handle: addProjectMember },
- { method: "DELETE", path: "/v1/projects/:id/members/:memberId", auth: "either", handle: removeProjectMember },
{ method: "PUT", path: "/v1/projects/:id/slack-channel", auth: "either", handle: setProjectSlackChannel },
{ method: "DELETE", path: "/v1/projects/:id/slack-channel", auth: "either", handle: clearProjectSlackChannel },
+ ...withActor("body.principalId", [
+ { method: "POST", path: "/v1/projects", auth: "either", handle: createProject },
+ { method: "POST", path: "/v1/projects/:id/members", auth: "either", handle: addProjectMember },
+ { method: "DELETE", path: "/v1/projects/:id/members/:memberId", auth: "either", handle: removeProjectMember },
+ ]),
];
diff --git a/src/api/routes/route.ts b/src/api/routes/route.ts
index 542b08740..b5941b786 100644
--- a/src/api/routes/route.ts
+++ b/src/api/routes/route.ts
@@ -31,12 +31,19 @@ export interface ApiCtx extends BaseCtx {
export type RouteAuth = "either" | "source" | "public" | { aud: string };
+export type RouteActor = "person" | "system" | `${"query" | "body"}.${string}`;
+
export type Route<C extends BaseCtx = ApiCtx> = {
handle: (ctx: C) => void | Promise<void>;
auth: RouteAuth;
+ actor?: RouteActor;
maxBodyBytes?: number;
} & ({ method: string; path: string } | { match: (method: string, pathname: string) => boolean });
+export function withActor<C extends BaseCtx>(actor: RouteActor, routes: Route<C>[]): Route<C>[] {
+ return routes.map((route) => ({ actor, ...route }));
+}
+
export async function run<C extends BaseCtx>(route: Route<C>, params: Record<string, string>, ctx: C): Promise<void> {
ctx.params = params;
await route.handle(ctx);
diff --git a/src/api/routes/run-events.ts b/src/api/routes/run-events.ts
index e9d0bcd62..f4d3625de 100644
--- a/src/api/routes/run-events.ts
+++ b/src/api/routes/run-events.ts
@@ -174,5 +174,5 @@ async function streamRun(ctx: ApiCtx): Promise<void> {
}
export const runEventRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "GET", path: "/v1/runs/:id/events", auth: "source", handle: streamRun },
+ { method: "GET", path: "/v1/runs/:id/events", actor: "person", auth: "source", handle: streamRun },
];
diff --git a/src/api/routes/secret-drop.ts b/src/api/routes/secret-drop.ts
index afd0f3a02..cee5f3c1e 100644
--- a/src/api/routes/secret-drop.ts
+++ b/src/api/routes/secret-drop.ts
@@ -391,7 +391,7 @@ async function redeemDrop(ctx: ApiCtx): Promise<void> {
}
export const secretDropRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/keychain/drops", auth: "either", handle: mintDrop },
+ { method: "POST", path: "/v1/keychain/drops", actor: "system", auth: "either", handle: mintDrop },
{ method: "GET", path: "/v1/keychain/drops/:id/form", auth: "source", handle: dropForm },
- { method: "POST", path: "/v1/keychain/drops/:id", auth: "source", handle: redeemDrop },
+ { method: "POST", path: "/v1/keychain/drops/:id", actor: "system", auth: "source", handle: redeemDrop },
];
diff --git a/src/api/routes/session-sharing.ts b/src/api/routes/session-sharing.ts
index c3670ffc7..60ca3ae0b 100644
--- a/src/api/routes/session-sharing.ts
+++ b/src/api/routes/session-sharing.ts
@@ -148,9 +148,12 @@ async function readShare(ctx: ApiCtx): Promise<void> {
}
export const sessionSharingRoutes: ReadonlyArray<Route> = [
- { method: "POST", path: "/v1/sessions/:id/share", auth: "source", handle: createShare },
- ...["shared-sessions", "public-shares"].flatMap((prefix): Route[] => [
- { method: "GET", path: `/v1/${prefix}/:token`, auth: "source", handle: readShare },
- { method: "GET", path: `/v1/${prefix}/:token/files/:fileId`, auth: "source", handle: readShare },
- ]),
+ { method: "POST", path: "/v1/sessions/:id/share", actor: "body.principalId", auth: "source", handle: createShare },
+ ...(["shared-sessions", "public-shares"] as const).flatMap((prefix): Route[] => {
+ const actor = prefix === "shared-sessions" ? ("query.viewer" as const) : undefined;
+ return [
+ { method: "GET", path: `/v1/${prefix}/:token`, actor, auth: "source", handle: readShare },
+ { method: "GET", path: `/v1/${prefix}/:token/files/:fileId`, actor, auth: "source", handle: readShare },
+ ];
+ }),
];
diff --git a/src/api/routes/surface-cache.ts b/src/api/routes/surface-cache.ts
index 74dd001e1..61d3810a0 100644
--- a/src/api/routes/surface-cache.ts
+++ b/src/api/routes/surface-cache.ts
@@ -104,7 +104,7 @@ async function setChannelPolicy(ctx: ApiCtx): Promise<void> {
}
export const surfaceCacheRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/surface-cache/ingest", auth: "source", handle: ingestSurfaceEvents },
+ { method: "POST", path: "/v1/surface-cache/ingest", actor: "system", auth: "source", handle: ingestSurfaceEvents },
{ method: "GET", path: "/v1/surface-cache/policy", auth: "source", handle: getChannelPolicy },
- { method: "POST", path: "/v1/surface-cache/policy", auth: "source", handle: setChannelPolicy },
+ { method: "POST", path: "/v1/surface-cache/policy", actor: "system", auth: "source", handle: setChannelPolicy },
];
diff --git a/src/api/routes/surface.ts b/src/api/routes/surface.ts
index a08640fda..2033127f5 100644
--- a/src/api/routes/surface.ts
+++ b/src/api/routes/surface.ts
@@ -32,7 +32,7 @@ import {
uiStateId,
} from "../../surfaces/ui-state.ts";
import { redactWebhook } from "./webhooks.ts";
-import { type ApiCtx, type Route } from "./route.ts";
+import { withActor, type ApiCtx, type Route } from "./route.ts";
import {
ARTIFACT_TYPES,
isArtifactType,
@@ -1350,38 +1350,12 @@ async function putPinnedSkills(ctx: ApiCtx): Promise<void> {
export const surfaceRoutes: ReadonlyArray<Route<ApiCtx>> = [
...sessionSharingRoutes,
...suggestedActivityRoutes,
- { method: "POST", path: "/v1/session-cap", auth: "source", handle: sessionCapability },
- { method: "GET", path: "/v1/resources/search", auth: "source", handle: searchResources },
- { method: "GET", path: "/v1/sessions/search", auth: "source", handle: searchSessions },
- { method: "POST", path: "/v1/sessions/:id/title", auth: "source", handle: regenerateSessionTitle },
- { method: "POST", path: "/v1/sessions/:id/fork", auth: "source", handle: forkSession },
- { method: "POST", path: "/v1/sessions/:id/detach", auth: "source", handle: detachSession },
- { method: "POST", path: "/v1/sessions/:id/goal/cancel", auth: "source", handle: cancelSessionGoal },
- { method: "GET", path: "/v1/sessions/:id/approvals", auth: "source", handle: listSessionApprovals },
- { method: "GET", path: "/v1/sessions/:id/background", auth: "source", handle: getSessionBackground },
- {
- method: "GET",
- path: "/v1/sessions/:id/background/:pid/output",
- auth: "source",
- handle: getSessionBackgroundOutput,
- },
- { method: "GET", path: "/v1/sessions/:id/entries/:seq", auth: "source", handle: getSessionEntry },
- { method: "GET", path: "/v1/sessions/:id", auth: "source", handle: getSession },
- { method: "GET", path: "/v1/files/:id/content", auth: "either", handle: getFileContent },
- { method: "POST", path: "/v1/files/upload", auth: "source", handle: uploadFile },
- { method: "GET", path: "/v1/files", auth: "either", handle: listFiles },
- { method: "POST", path: "/v1/sessions/:id", auth: "source", handle: patchSession },
- { method: "GET", path: "/v1/sessions", auth: "source", handle: listSessions },
+ { method: "POST", path: "/v1/session-cap", actor: "system", auth: "source", handle: sessionCapability },
{ method: "GET", path: "/v1/conversations", auth: "either", handle: listAgentConversations },
{ method: "GET", path: "/v1/conversations/:id", auth: "either", handle: getAgentConversation },
{ method: "POST", path: "/v1/conversations/:id", auth: "either", handle: patchAgentConversation },
- { method: "GET", path: "/v1/contexts", auth: "source", handle: listContexts },
- { method: "GET", path: "/v1/scope-resources", auth: "source", handle: listScopeResources },
{ method: "GET", path: "/v1/ui-state", auth: "source", handle: getUiState },
{ method: "PUT", path: "/v1/ui-state", auth: "source", handle: putUiState },
- { method: "GET", path: "/v1/memory", auth: "source", handle: selfMemory },
- { method: "PATCH", path: "/v1/memory", auth: "source", handle: selfMemory },
- { method: "DELETE", path: "/v1/memory", auth: "source", handle: selfMemory },
{ method: "GET", path: "/v1/apis", auth: "either", handle: listAgentApis },
{
match: (m, p) =>
@@ -1396,14 +1370,8 @@ export const surfaceRoutes: ReadonlyArray<Route<ApiCtx>> = [
auth: "source",
handle: agentMemory,
},
- { method: "GET", path: "/v1/skills", auth: "source", handle: listSkills },
- { method: "GET", path: "/v1/skills/:id", auth: "either", handle: getSkillDetail },
- { method: "POST", path: "/v1/skills", auth: "either", handle: createSkill },
- { method: "PUT", path: "/v1/skills/:id", auth: "either", handle: updateSkill },
- { method: "DELETE", path: "/v1/skills/:id", auth: "either", handle: deleteSkill },
- { method: "POST", path: "/v1/skills/:id/restore", auth: "either", handle: restoreSkill },
- { method: "POST", path: "/v1/grants", auth: "source", handle: createGrant },
- { method: "POST", path: "/v1/grants/revoke", auth: "source", handle: revokeGrant },
+ { method: "POST", path: "/v1/grants", actor: "system", auth: "source", handle: createGrant },
+ { method: "POST", path: "/v1/grants/revoke", actor: "system", auth: "source", handle: revokeGrant },
{ method: "POST", path: "/v1/share", auth: "either", handle: shareArtifact },
{ method: "GET", path: "/v1/surface-config", auth: "source", handle: getSurfaceConfig },
{ method: "GET", path: "/v1/runtime-config", auth: "either", handle: getRuntimeConfig },
@@ -1411,7 +1379,45 @@ export const surfaceRoutes: ReadonlyArray<Route<ApiCtx>> = [
{ method: "GET", path: "/v1/channel-header-pin", auth: "either", handle: getChannelHeaderPin },
{ method: "PUT", path: "/v1/channel-header-pin", auth: "either", handle: putChannelHeaderPin },
{ method: "GET", path: "/v1/soul", auth: "either", handle: getSoul },
- { method: "POST", path: "/v1/soul", auth: "either", handle: postSoul },
+ { method: "POST", path: "/v1/soul", actor: "body.actorId", auth: "either", handle: postSoul },
{ method: "GET", path: "/v1/pinned-skills", auth: "either", handle: getPinnedSkills },
{ method: "PUT", path: "/v1/pinned-skills", auth: "either", handle: putPinnedSkills },
+ ...withActor("body.principalId", [
+ { method: "POST", path: "/v1/sessions/:id/title", auth: "source", handle: regenerateSessionTitle },
+ { method: "POST", path: "/v1/sessions/:id/fork", auth: "source", handle: forkSession },
+ { method: "POST", path: "/v1/sessions/:id/detach", auth: "source", handle: detachSession },
+ { method: "POST", path: "/v1/sessions/:id/goal/cancel", auth: "source", handle: cancelSessionGoal },
+ { method: "POST", path: "/v1/files/upload", auth: "source", handle: uploadFile },
+ { method: "POST", path: "/v1/sessions/:id", auth: "source", handle: patchSession },
+ { method: "PATCH", path: "/v1/memory", auth: "source", handle: selfMemory },
+ { method: "DELETE", path: "/v1/memory", auth: "source", handle: selfMemory },
+ { method: "POST", path: "/v1/skills", auth: "either", handle: createSkill },
+ { method: "PUT", path: "/v1/skills/:id", auth: "either", handle: updateSkill },
+ { method: "DELETE", path: "/v1/skills/:id", auth: "either", handle: deleteSkill },
+ { method: "POST", path: "/v1/skills/:id/restore", auth: "either", handle: restoreSkill },
+ ]),
+ ...withActor("query.principalId", [
+ { method: "GET", path: "/v1/resources/search", auth: "source", handle: searchResources },
+ { method: "GET", path: "/v1/sessions/search", auth: "source", handle: searchSessions },
+ { method: "GET", path: "/v1/sessions", auth: "source", handle: listSessions },
+ { method: "GET", path: "/v1/contexts", auth: "source", handle: listContexts },
+ { method: "GET", path: "/v1/scope-resources", auth: "source", handle: listScopeResources },
+ { method: "GET", path: "/v1/memory", auth: "source", handle: selfMemory },
+ { method: "GET", path: "/v1/skills", auth: "source", handle: listSkills },
+ { method: "GET", path: "/v1/skills/:id", auth: "either", handle: getSkillDetail },
+ ]),
+ ...withActor("query.viewer", [
+ { method: "GET", path: "/v1/sessions/:id/approvals", auth: "source", handle: listSessionApprovals },
+ { method: "GET", path: "/v1/sessions/:id/background", auth: "source", handle: getSessionBackground },
+ {
+ method: "GET",
+ path: "/v1/sessions/:id/background/:pid/output",
+ auth: "source",
+ handle: getSessionBackgroundOutput,
+ },
+ { method: "GET", path: "/v1/sessions/:id/entries/:seq", auth: "source", handle: getSessionEntry },
+ { method: "GET", path: "/v1/sessions/:id", auth: "source", handle: getSession },
+ { method: "GET", path: "/v1/files/:id/content", auth: "either", handle: getFileContent },
+ { method: "GET", path: "/v1/files", auth: "either", handle: listFiles },
+ ]),
];
diff --git a/src/api/routes/turns.ts b/src/api/routes/turns.ts
index 9b18c6cbc..e46105f98 100644
--- a/src/api/routes/turns.ts
+++ b/src/api/routes/turns.ts
@@ -307,17 +307,23 @@ async function postTurnMetrics(ctx: ApiCtx): Promise<void> {
}
export const turnRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/turns", auth: "source", handle: postTurn },
- { method: "POST", path: "/v1/turns/:runId/metrics", auth: "source", handle: postTurnMetrics },
- { method: "GET", path: "/v1/approvals/pending", auth: "source", handle: getPendingApproval },
- { method: "GET", path: "/v1/approvals/:id", auth: "source", handle: getApproval },
- { method: "POST", path: "/v1/runs/:id/delivery-state", auth: "source", handle: postRunDeliveryState },
+ { method: "POST", path: "/v1/turns", actor: "system", auth: "source", handle: postTurn },
+ { method: "POST", path: "/v1/turns/:runId/metrics", actor: "system", auth: "source", handle: postTurnMetrics },
+ { method: "GET", path: "/v1/approvals/pending", actor: "person", auth: "source", handle: getPendingApproval },
+ { method: "GET", path: "/v1/approvals/:id", actor: "person", auth: "source", handle: getApproval },
+ {
+ method: "POST",
+ path: "/v1/runs/:id/delivery-state",
+ actor: "system",
+ auth: "source",
+ handle: postRunDeliveryState,
+ },
{ method: "POST", path: "/v1/runs/:id/signal", auth: "source", maxBodyBytes: 6_000_000, handle: postRunSignal },
{ method: "PATCH", path: "/v1/runs/:id/input", auth: "source", handle: patchQueuedRun },
{ method: "POST", path: "/v1/runs/:id/withdraw", auth: "source", handle: postRunWithdraw },
- { method: "GET", path: "/v1/runs/:id", auth: "source", handle: getRun },
- { method: "GET", path: "/v1/runs", auth: "source", handle: getActiveRunForThread },
+ { method: "GET", path: "/v1/runs/:id", actor: "person", auth: "source", handle: getRun },
+ { method: "GET", path: "/v1/runs", actor: "person", auth: "source", handle: getActiveRunForThread },
{ method: "GET", path: "/v1/deliveries", auth: "source", handle: listDeliveries },
- { method: "POST", path: "/v1/deliveries/:id/ack", auth: "source", handle: ackDelivery },
- { method: "POST", path: "/v1/deliveries/ack-by-key", auth: "source", handle: ackDeliveryByKey },
+ { method: "POST", path: "/v1/deliveries/:id/ack", actor: "system", auth: "source", handle: ackDelivery },
+ { method: "POST", path: "/v1/deliveries/ack-by-key", actor: "system", auth: "source", handle: ackDeliveryByKey },
];
diff --git a/src/api/routes/user-model-auth.ts b/src/api/routes/user-model-auth.ts
index b46709fa1..58cbc93fd 100644
--- a/src/api/routes/user-model-auth.ts
+++ b/src/api/routes/user-model-auth.ts
@@ -4,7 +4,7 @@ import { createCodexDeviceLogin } from "../../model/codex-device-login.ts";
import { errMessage } from "../../util/errors.ts";
import { sendJson } from "../http.ts";
import { validateProviderApiKey } from "./admin/model-providers.ts";
-import type { ApiCtx, Route } from "./route.ts";
+import { withActor, type ApiCtx, type Route } from "./route.ts";
import { audit } from "./shared.ts";
function caller(ctx: ApiCtx): string | null {
@@ -165,12 +165,14 @@ async function claudeComplete(ctx: ApiCtx): Promise<void> {
}
export const userModelAuthRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/user-model-auth/account", auth: "source", handle: setAccount },
- { method: "GET", path: "/v1/user-model-auth/status", auth: "source", handle: getStatus },
- { method: "POST", path: "/v1/user-model-auth/api-key", auth: "source", handle: putApiKey },
- { method: "POST", path: "/v1/user-model-auth/disconnect", auth: "source", handle: disconnect },
- { method: "POST", path: "/v1/user-model-auth/chatgpt/start", auth: "source", handle: chatgptStart },
- { method: "POST", path: "/v1/user-model-auth/chatgpt/poll", auth: "source", handle: chatgptPoll },
- { method: "POST", path: "/v1/user-model-auth/claude/start", auth: "source", handle: claudeStart },
- { method: "POST", path: "/v1/user-model-auth/claude/complete", auth: "source", handle: claudeComplete },
+ { method: "GET", path: "/v1/user-model-auth/status", actor: "query.principalId", auth: "source", handle: getStatus },
+ ...withActor("body.principalId", [
+ { method: "POST", path: "/v1/user-model-auth/account", auth: "source", handle: setAccount },
+ { method: "POST", path: "/v1/user-model-auth/api-key", auth: "source", handle: putApiKey },
+ { method: "POST", path: "/v1/user-model-auth/disconnect", auth: "source", handle: disconnect },
+ { method: "POST", path: "/v1/user-model-auth/chatgpt/start", auth: "source", handle: chatgptStart },
+ { method: "POST", path: "/v1/user-model-auth/chatgpt/poll", auth: "source", handle: chatgptPoll },
+ { method: "POST", path: "/v1/user-model-auth/claude/start", auth: "source", handle: claudeStart },
+ { method: "POST", path: "/v1/user-model-auth/claude/complete", auth: "source", handle: claudeComplete },
+ ]),
];
diff --git a/src/api/routes/webhooks.ts b/src/api/routes/webhooks.ts
index 0bc95eb53..2721c13fc 100644
--- a/src/api/routes/webhooks.ts
+++ b/src/api/routes/webhooks.ts
@@ -193,10 +193,22 @@ export const webhookRawRoutes: ReadonlyArray<Route<BaseCtx>> = [
];
export const webhookRoutes: ReadonlyArray<Route<ApiCtx>> = [
- { method: "POST", path: "/v1/webhooks", auth: "either", handle: createWebhook },
- { method: "GET", path: "/v1/webhooks", auth: "either", handle: listWebhooks },
- { method: "GET", path: "/v1/webhooks/:id/events", auth: "either", handle: listWebhookEvents },
- { method: "POST", path: "/v1/webhooks/:id/update", auth: "either", handle: updateWebhook },
- { method: "POST", path: "/v1/webhooks/:id/disable", auth: "either", handle: disableWebhook },
+ { method: "POST", path: "/v1/webhooks", actor: "body.createdBy", auth: "either", handle: createWebhook },
+ { method: "GET", path: "/v1/webhooks", actor: "query.viewer", auth: "either", handle: listWebhooks },
+ { method: "GET", path: "/v1/webhooks/:id/events", actor: "query.viewer", auth: "either", handle: listWebhookEvents },
+ {
+ method: "POST",
+ path: "/v1/webhooks/:id/update",
+ actor: "query.principalId",
+ auth: "either",
+ handle: updateWebhook,
+ },
+ {
+ method: "POST",
+ path: "/v1/webhooks/:id/disable",
+ actor: "query.principalId",
+ auth: "either",
+ handle: disableWebhook,
+ },
{ method: "POST", path: "/v1/webhooks/:id/enable", auth: "either", handle: enableWebhook },
];
diff --git a/src/api/server.ts b/src/api/server.ts
index 7fd78e360..e396962ad 100644
--- a/src/api/server.ts
+++ b/src/api/server.ts
@@ -23,12 +23,11 @@ import {
} from "../auth/source-auth.ts";
import { verifyCapabilityToken, CONTROL_PLANE_AUD, type CapabilityClaims } from "../auth/capability-token.ts";
import { verifyPortalIdentity, PORTAL_IDENTITY_HEADER, type PortalIdentity } from "../auth/portal-identity.ts";
-import { isUserScoped, userScopedField, assertedActor, isUnclassifiedWrite } from "./user-scoped-routes.ts";
import { errMessage } from "../util/errors.ts";
import { parseScopeId, scopeId } from "../types.ts";
import { canonicalPayload } from "../../plugins/chassis/src/source-auth-sign.ts";
import { armBodyDeadline, PayloadTooLargeError, readRawBody, sendJson, verifyOrReject } from "./http.ts";
-import { findRoute, run, type ApiCtx, type BaseCtx, type Route, type RouteAuth } from "./routes/route.ts";
+import { findRoute, run, type ApiCtx, type BaseCtx, type Route } from "./routes/route.ts";
import { apiRoutes, rawRoutes } from "./routes/index.ts";
import { proxyDeploymentSubdomain } from "./routes/deployments.ts";
import { CAPABILITY_HEADER } from "./contract.ts";
@@ -138,6 +137,8 @@ function strictPostAllowed(pathname: string): boolean {
return /^\/v1\/skills\/[^/]+\/restore$/.test(pathname);
}
+const WRITE_METHODS = new Set(["POST", "PUT", "PATCH", "DELETE"]);
+
function capabilityFromHeaders(req: IncomingMessage): string | null {
const h = req.headers[CAPABILITY_HEADER];
return typeof h === "string" && h ? h : null;
@@ -254,8 +255,9 @@ async function gate(
pathname: string,
url: URL,
raw: string,
- routeAuth: RouteAuth | undefined,
+ route: Pick<Route, "auth" | "actor"> | undefined,
): Promise<GateResult | null> {
+ const routeAuth = route?.auth;
const { deps, secret, auth, requirePortalIdentity, allowUnsignedSourceAuth } = wiring;
const isPublicRoute = routeAuth === "public";
const requiredAud = typeof routeAuth === "object" ? routeAuth.aud : null;
@@ -341,20 +343,18 @@ async function gate(
body !== null &&
typeof body === "object" &&
(body as { surface?: unknown }).surface === "web";
+ const routeActor = route?.actor ?? (WRITE_METHODS.has(method) ? "person" : undefined);
const needsActor =
- isUserScoped(method, pathname) ||
- webTurn ||
- pathname.startsWith("/v1/admin/") ||
- isUnclassifiedWrite(method, pathname);
+ webTurn || pathname.startsWith("/v1/admin/") || (routeActor !== undefined && routeActor !== "system");
if (needsActor) {
if (!psecret || !actor) {
sendJson(res, 401, { error: "unauthorized", message: "portal identity required" });
return null;
}
- const field = webTurn ? undefined : userScopedField(method, pathname);
+ const field = !webTurn && routeActor?.includes(".") ? routeActor : undefined;
let asserted: unknown = null;
if (webTurn) asserted = (body as { actor?: { externalId?: unknown } }).actor?.externalId ?? null;
- else if (field) asserted = assertedActor(field, url, body, req);
+ else if (field) asserted = assertedActorField(field, url, body);
const actorId = actor.p;
const matchesActor = (value: unknown): boolean => typeof value === "string" && samePerson(value, actorId);
if ((field && !matchesActor(asserted)) || (!field && asserted !== null && !matchesActor(asserted))) {
@@ -367,6 +367,13 @@ async function gate(
return { body, capability, actor };
}
+function assertedActorField(field: string, url: URL, body: unknown): unknown {
+ const [where, name] = field.split(".", 2) as [string, string];
+ if (where === "query") return url.searchParams.get(name);
+ const value = body && typeof body === "object" ? (body as Record<string, unknown>)[name] : undefined;
+ return typeof value === "string" ? value : null;
+}
+
function baseCtx(req: IncomingMessage, res: ServerResponse, wiring: Wiring): BaseCtx {
const url = new URL(req.url ?? "/", "http://localhost");
return { req, res, ...wiring, url, pathname: url.pathname, method: req.method ?? "GET", params: {} };
@@ -416,7 +423,7 @@ function buildFastify(wiring: Wiring, server: Server): { fastify: FastifyInstanc
const base = baseCtx(req, res, wiring);
const raw = rawBodies.get(req) ?? "";
const found = findRoute(matchRoutes, base.method, base.pathname);
- const g = await gate(req, res, wiring, base.method, base.pathname, base.url, raw, found?.route.auth);
+ const g = await gate(req, res, wiring, base.method, base.pathname, base.url, raw, found?.route);
if (!g) return;
if (found) {
const ctx: ApiCtx = {
@@ -471,7 +478,7 @@ function buildFastify(wiring: Wiring, server: Server): { fastify: FastifyInstanc
url.pathname,
url,
raw,
- request.routeOptions.config.route?.auth,
+ request.routeOptions.config.route,
);
if (!result) {
reply.hijack();
diff --git a/src/api/user-scoped-routes.ts b/src/api/user-scoped-routes.ts
deleted file mode 100644
index 719b81c14..000000000
--- a/src/api/user-scoped-routes.ts
+++ /dev/null
@@ -1,193 +0,0 @@
-import type { IncomingMessage } from "node:http";
-
-type Field = { in: "query" | "body" | "header"; name: string };
-type Rule = { method: string; re: RegExp; field?: Field };
-
-function pat(method: string, template: string, field?: Field): Rule {
- const re = new RegExp("^" + template.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/:[^/]+/g, "[^/]+") + "$");
- return field ? { method, re, field } : { method, re };
-}
-
-const USER_SCOPED: Rule[] = [
- pat("POST", "/v1/composio/complete-auth"),
- pat("POST", "/v1/composio/authorize"),
- pat("POST", "/v1/composio/execute"),
- pat("POST", "/v1/auth/broker/sessions/revoke"),
- pat("POST", "/v1/loops", { in: "query", name: "principalId" }),
- pat("GET", "/v1/loops", { in: "query", name: "principalId" }),
- pat("GET", "/v1/loops/:id", { in: "query", name: "principalId" }),
- pat("PATCH", "/v1/loops/:id", { in: "query", name: "principalId" }),
- pat("DELETE", "/v1/loops/:id", { in: "query", name: "principalId" }),
- pat("GET", "/v1/inbox", { in: "query", name: "principalId" }),
- pat("GET", "/v1/inbox/access", { in: "query", name: "principalId" }),
- pat("PUT", "/v1/inbox", { in: "query", name: "principalId" }),
- pat("GET", "/v1/loops/:id/ingestion", { in: "query", name: "principalId" }),
- pat("POST", "/v1/loops/:id/ingestion", { in: "query", name: "principalId" }),
- pat("PATCH", "/v1/loops/:id/ingestion/:sourceId", { in: "query", name: "principalId" }),
- pat("POST", "/v1/loops/:id/fire", { in: "query", name: "principalId" }),
- pat("POST", "/v1/loops/:id/outputs/:outputId/decide", { in: "query", name: "principalId" }),
- pat("POST", "/v1/loops/:id/grants", { in: "query", name: "principalId" }),
- pat("POST", "/v1/loops/:id/autopilot", { in: "query", name: "principalId" }),
- pat("DELETE", "/v1/loops/:id/grants/:grantId", { in: "query", name: "principalId" }),
- pat("GET", "/v1/loops/inbox", { in: "query", name: "principalId" }),
- pat("POST", "/v1/loops/inbox/sync-cron", { in: "query", name: "principalId" }),
- pat("GET", "/v1/loops/:id/items", { in: "query", name: "principalId" }),
- pat("POST", "/v1/loops/:id/items", { in: "query", name: "principalId" }),
- pat("GET", "/v1/loops/:id/items/:itemId", { in: "query", name: "principalId" }),
- pat("POST", "/v1/loops/:id/items/:itemId/action", { in: "query", name: "principalId" }),
- pat("POST", "/v1/loops/:id/items/:itemId/followup", { in: "query", name: "principalId" }),
- pat("POST", "/v1/sessions/:id/share", { in: "body", name: "principalId" }),
- pat("GET", "/v1/shared-sessions/:token", { in: "query", name: "viewer" }),
- pat("GET", "/v1/shared-sessions/:token/files/:fileId", { in: "query", name: "viewer" }),
- pat("GET", "/v1/sessions/search", { in: "query", name: "principalId" }),
- pat("GET", "/v1/sessions/:id", { in: "query", name: "viewer" }),
- pat("GET", "/v1/sessions/:id/entries/:seq", { in: "query", name: "viewer" }),
- pat("GET", "/v1/sessions/:id/approvals", { in: "query", name: "viewer" }),
- pat("GET", "/v1/sessions/:id/background", { in: "query", name: "viewer" }),
- pat("GET", "/v1/sessions/:id/background/:pid/output", { in: "query", name: "viewer" }),
- pat("GET", "/v1/files/:id/content", { in: "query", name: "viewer" }),
- pat("GET", "/v1/files", { in: "query", name: "viewer" }),
- pat("GET", "/v1/files/upload-client", { in: "query", name: "viewer" }),
- pat("POST", "/v1/files/uploads", { in: "body", name: "principalId" }),
- pat("GET", "/v1/files/uploads/:id", { in: "query", name: "viewer" }),
- pat("POST", "/v1/files/uploads/:id/parts/:part", { in: "body", name: "principalId" }),
- pat("POST", "/v1/files/uploads/:id/complete", { in: "body", name: "principalId" }),
- pat("DELETE", "/v1/files/uploads/:id", { in: "body", name: "principalId" }),
- pat("POST", "/v1/files/upload", { in: "body", name: "principalId" }),
- pat("POST", "/v1/sessions/:id", { in: "body", name: "principalId" }),
- pat("POST", "/v1/sessions/:id/title", { in: "body", name: "principalId" }),
- pat("POST", "/v1/sessions/:id/fork", { in: "body", name: "principalId" }),
- pat("POST", "/v1/sessions/:id/detach", { in: "body", name: "principalId" }),
- pat("POST", "/v1/sessions/:id/goal/cancel", { in: "body", name: "principalId" }),
- pat("GET", "/v1/sessions", { in: "query", name: "principalId" }),
- pat("GET", "/v1/resources/search", { in: "query", name: "principalId" }),
- pat("GET", "/v1/contexts", { in: "query", name: "principalId" }),
- pat("GET", "/v1/projects", { in: "query", name: "principalId" }),
- pat("POST", "/v1/projects", { in: "body", name: "principalId" }),
- pat("POST", "/v1/projects/:id/members", { in: "body", name: "principalId" }),
- pat("DELETE", "/v1/projects/:id/members/:memberId", { in: "body", name: "principalId" }),
- pat("GET", "/v1/scope-resources", { in: "query", name: "principalId" }),
- pat("GET", "/v1/memory", { in: "query", name: "principalId" }),
- pat("PATCH", "/v1/memory", { in: "body", name: "principalId" }),
- pat("DELETE", "/v1/memory", { in: "body", name: "principalId" }),
- pat("GET", "/v1/contexts/policy", { in: "query", name: "principalId" }),
- pat("GET", "/v1/skills", { in: "query", name: "principalId" }),
- pat("GET", "/v1/skills/:id", { in: "query", name: "principalId" }),
- pat("POST", "/v1/skills", { in: "body", name: "principalId" }),
- pat("PUT", "/v1/skills/:id", { in: "body", name: "principalId" }),
- pat("DELETE", "/v1/skills/:id", { in: "body", name: "principalId" }),
- pat("POST", "/v1/skills/:id/restore", { in: "body", name: "principalId" }),
- pat("POST", "/v1/soul", { in: "body", name: "actorId" }),
- pat("POST", "/v1/webhooks", { in: "body", name: "createdBy" }),
- pat("GET", "/v1/webhooks", { in: "query", name: "viewer" }),
- pat("GET", "/v1/webhooks/:id/events", { in: "query", name: "viewer" }),
- pat("GET", "/v1/crons", { in: "query", name: "viewer" }),
- pat("POST", "/v1/crons", { in: "body", name: "createdBy" }),
- pat("GET", "/v1/crons/:id", { in: "query", name: "principalId" }),
- pat("PATCH", "/v1/crons/:id", { in: "query", name: "principalId" }),
- pat("DELETE", "/v1/crons/:id", { in: "query", name: "principalId" }),
- pat("POST", "/v1/crons/:id/disable", { in: "query", name: "principalId" }),
- pat("POST", "/v1/crons/:id/run", { in: "query", name: "principalId" }),
- pat("POST", "/v1/crons/:id/destination", { in: "query", name: "principalId" }),
- pat("GET", "/v1/crons/:id/runs", { in: "query", name: "principalId" }),
- pat("GET", "/v1/deployments", { in: "query", name: "principalId" }),
- pat("POST", "/v1/deployments", { in: "body", name: "createdBy" }),
- pat("GET", "/v1/user-model-auth/status", { in: "query", name: "principalId" }),
- pat("POST", "/v1/user-model-auth/account", { in: "body", name: "principalId" }),
- pat("POST", "/v1/user-model-auth/api-key", { in: "body", name: "principalId" }),
- pat("POST", "/v1/user-model-auth/disconnect", { in: "body", name: "principalId" }),
- pat("POST", "/v1/user-model-auth/chatgpt/start", { in: "body", name: "principalId" }),
- pat("POST", "/v1/user-model-auth/chatgpt/poll", { in: "body", name: "principalId" }),
- pat("POST", "/v1/user-model-auth/claude/start", { in: "body", name: "principalId" }),
- pat("POST", "/v1/user-model-auth/claude/complete", { in: "body", name: "principalId" }),
- pat("GET", "/v1/connectors/oauth/:provider/start", { in: "query", name: "principalId" }),
- pat("GET", "/v1/connectors/oauth/status", { in: "query", name: "principalId" }),
- pat("POST", "/v1/connectors/token", { in: "body", name: "principalId" }),
- pat("POST", "/v1/connectors/oauth/revoke", { in: "body", name: "principalId" }),
- pat("POST", "/v1/webhooks/:id/disable", { in: "query", name: "principalId" }),
- pat("POST", "/v1/webhooks/:id/update", { in: "query", name: "principalId" }),
- pat("POST", "/v1/deployments/:id/display-name"),
- pat("POST", "/v1/deployments/:id/name"),
- pat("POST", "/v1/deployments/:id/archive"),
- pat("POST", "/v1/deployments/:id/restore"),
- pat("POST", "/v1/deployments/:id/rollback"),
- pat("POST", "/v1/deployments/:id/redeploy"),
- pat("GET", "/v1/deployments/:id/share"),
- pat("POST", "/v1/deployments/:id/share"),
- pat("GET", "/v1/approvals/:id"),
- pat("GET", "/v1/approvals/pending"),
- pat("GET", "/v1/directory/resolve"),
- pat("POST", "/v1/reach"),
- pat("POST", "/v1/share"),
- pat("POST", "/v1/environments"),
- pat("POST", "/v1/environments/attach"),
- pat("POST", "/v1/emoji"),
- pat("GET", "/v1/runs/:id"),
- pat("GET", "/v1/runs/:id/events"),
- pat("GET", "/v1/runs"),
- pat("POST", "/v1/runs/:id/signal"),
-];
-
-const SYSTEM: Rule[] = [
- pat("POST", "/v1/turns"),
- pat("POST", "/v1/turns/:id/metrics"),
- pat("POST", "/v1/runs/:id/delivery-state"),
- pat("POST", "/v1/deliveries/:id/ack"),
- pat("POST", "/v1/deliveries/ack-by-key"),
- pat("POST", "/v1/inbox/viewers"),
- pat("POST", "/v1/directory"),
- pat("POST", "/v1/principals/:id/deactivate"),
- pat("POST", "/v1/principals/:id/reactivate"),
- pat("POST", "/v1/surface-cache/ingest"),
- pat("POST", "/v1/surface-cache/policy"),
- pat("POST", "/v1/surface-context/:id/result"),
- pat("POST", "/v1/grants"),
- pat("POST", "/v1/grants/revoke"),
- pat("POST", "/v1/blobs"),
- pat("POST", "/v1/egress-audit"),
- pat("POST", "/v1/auth/broker/claim"),
- pat("POST", "/v1/auth/trusted/admin"),
- pat("POST", "/v1/auth/invitations/redeem"),
- pat("POST", "/v1/auth/broker/sessions"),
- pat("POST", "/v1/auth/broker/sessions/use"),
- pat("PUT", "/v1/deployment-layer"),
- pat("POST", "/v1/background-work"),
- pat("POST", "/v1/deployment/live-session"),
- pat("POST", "/v1/session-cap"),
- pat("POST", "/v1/keychain/drops/:id"),
- pat("POST", "/v1/keychain/asks"),
- pat("POST", "/v1/keychain/credentials"),
- pat("DELETE", "/v1/keychain/credentials/:id"),
- pat("POST", "/v1/keychain/drops"),
- pat("POST", "/v1/keychain/grants/:id/revoke"),
- pat("POST", "/v1/surface-context"),
- pat("POST", "/v1/surface-file"),
-];
-
-const WRITE = new Set(["POST", "PUT", "DELETE", "PATCH"]);
-
-export function isUserScoped(method: string, pathname: string): boolean {
- return USER_SCOPED.some((r) => r.method === method && r.re.test(pathname));
-}
-
-export function userScopedField(method: string, pathname: string): Field | undefined {
- return USER_SCOPED.find((r) => r.method === method && !!r.field && r.re.test(pathname))?.field;
-}
-
-export function isUnclassifiedWrite(method: string, pathname: string): boolean {
- if (!WRITE.has(method)) return false;
- if (pathname.startsWith("/v1/admin/")) return false;
- if (isUserScoped(method, pathname)) return false;
- return !SYSTEM.some((r) => r.method === method && r.re.test(pathname));
-}
-
-export function assertedActor(field: Field, url: URL, body: unknown, req: IncomingMessage): string | null {
- if (field.in === "query") return url.searchParams.get(field.name);
- if (field.in === "header") {
- const v = req.headers[field.name];
- return (Array.isArray(v) ? v[0] : v) ?? null;
- }
- const b = body as Record<string, unknown> | null;
- const v = b && typeof b === "object" ? b[field.name] : undefined;
- return typeof v === "string" ? v : null;
-}
diff --git a/test/portal-identity-gate.test.ts b/test/portal-identity-gate.test.ts
index 8246edc2f..5019915ce 100644
--- a/test/portal-identity-gate.test.ts
+++ b/test/portal-identity-gate.test.ts
@@ -11,7 +11,6 @@ import { mintSignedPayload } from "../src/auth/signed-token.ts";
import { verifyCapabilityToken } from "../src/auth/capability-token.ts";
import { testConfig } from "./support/test-config.ts";
import { scopeId } from "../src/types.ts";
-import { isUnclassifiedWrite } from "../src/api/user-scoped-routes.ts";
import { signedHeaders } from "../plugins/chassis/src/core-client.ts";
import { authBrokerRoutes } from "../src/api/routes/auth-broker.ts";
@@ -394,16 +393,14 @@ describe("user-scoped routes require a portal-verified actor when enforcement is
});
describe("service-to-service writes are classified", () => {
- it("every auth:source write route is classified, so production gating cannot demand a portal identity from a plugin", () => {
- const unclassified = authBrokerRoutes
- .filter((route) => "path" in route && route.auth === "source")
- .map((route) => route as { method: string; path: string })
- .filter((route) => isUnclassifiedWrite(route.method, route.path))
- .map((route) => `${route.method} ${route.path}`);
+ it("every auth-broker source write declares its actor, so production gating cannot demand a portal identity from a plugin", () => {
+ const undeclared = authBrokerRoutes
+ .filter((route) => "path" in route && route.auth === "source" && route.method !== "GET" && !route.actor)
+ .map((route) => `${(route as { method: string }).method} ${(route as { path: string }).path}`);
assert.deepEqual(
- unclassified,
+ undeclared,
[],
- "an unclassified write requires a portal identity under REQUIRE_SIGNED_PORTAL_IDENTITY; add it to SYSTEM in user-scoped-routes.ts",
+ 'a write defaults to requiring a portal identity under REQUIRE_SIGNED_PORTAL_IDENTITY; declare actor: "system" or "person" on the route',
);
});
});