Skip to content

Commit cae337f

Browse files
committed
feat: make SRS endpoint and apiKey optional, fallback to server-side defaults
1 parent ae7b0dd commit cae337f

4 files changed

Lines changed: 37 additions & 16 deletions

File tree

examples/computeragent-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ interface RunBody {
300300
*/
301301
attachments?: Array<{ path: string; content: string; encoding?: "utf8" | "base64" }>;
302302
/** Per-tool-call policy enforcement (forwarded to the harness decider). */
303-
policy?: { kind: "srs"; endpoint: string; apiKey: string; policyId: string; principalId: string };
303+
policy?: { kind: "srs"; endpoint?: string; apiKey?: string; policyId: string; principalId: string };
304304
}
305305

306306
interface ActiveRun {
@@ -705,7 +705,7 @@ interface SandboxBody {
705705
sessionId?: string;
706706
debug?: boolean;
707707
sessionStore?: { kind: string; options?: unknown };
708-
policy?: { kind: "srs"; endpoint: string; apiKey: string; policyId: string; principalId: string };
708+
policy?: { kind: "srs"; endpoint?: string; apiKey?: string; policyId: string; principalId: string };
709709
/** RBAC / multi-tenancy identity for observability — see RunBody.identity. */
710710
identity?: InvocationIdentity;
711711
/** Display name of the agent — recorded in the dashboard session index. */

packages/harness-server/src/services/create-session.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,29 @@ export async function createSession(
6666

6767
// Build a policy decider from wire-side config. Only "srs" is supported
6868
// today — extend by branching on body.policy.kind here.
69-
const policyDecider = body.policy
70-
? new SrsPolicyDecider({
71-
kind: "srs",
72-
endpoint: body.policy.endpoint,
73-
apiKey: body.policy.apiKey,
74-
policyId: body.policy.policyId,
75-
principalId: body.policy.principalId,
76-
})
77-
: undefined;
69+
//
70+
// `endpoint`/`apiKey` may be omitted by the caller (e.g. an SDK that knows
71+
// the binding but is never handed the SRS key). Fall back to this server's
72+
// own SRS_BASE_URL / SRS_API_KEY env so the key stays server-side.
73+
let policyDecider: SrsPolicyDecider | undefined;
74+
if (body.policy) {
75+
const endpoint = body.policy.endpoint ?? process.env["SRS_BASE_URL"];
76+
const apiKey = body.policy.apiKey ?? process.env["SRS_API_KEY"];
77+
if (!endpoint || !apiKey) {
78+
throw BadRequest(
79+
"SRS_NOT_CONFIGURED",
80+
"policy is set but the SRS endpoint/apiKey is neither supplied in the " +
81+
"request nor available via SRS_BASE_URL/SRS_API_KEY on the harness",
82+
);
83+
}
84+
policyDecider = new SrsPolicyDecider({
85+
kind: "srs",
86+
endpoint,
87+
apiKey,
88+
policyId: body.policy.policyId,
89+
principalId: body.policy.principalId,
90+
});
91+
}
7892

7993
const session = new Session(
8094
sessionId,

packages/protocol/src/harness-rest.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,17 @@ export const CreateSessionBody = z.object({
8181
* tool call through it. Deny short-circuits the engine's permission
8282
* request with `behavior: "deny"` — no SSE round-trip to a client.
8383
*
84-
* Currently supported: `{ kind: "srs", endpoint, apiKey, policyId, principalId }`.
84+
* Currently supported: `{ kind: "srs", endpoint?, apiKey?, policyId, principalId }`.
85+
*
86+
* `endpoint`/`apiKey` are optional: a caller that only knows the binding
87+
* (e.g. a client that fetched policyId/principalId from AgentOS but is never
88+
* given the SRS key) may omit them, and the harness fills both from its own
89+
* `SRS_BASE_URL` / `SRS_API_KEY` env. This keeps the SRS key server-side.
8590
*/
8691
policy: z.object({
8792
kind: z.literal("srs"),
88-
endpoint: z.string().min(1),
89-
apiKey: z.string().min(1),
93+
endpoint: z.string().min(1).optional(),
94+
apiKey: z.string().min(1).optional(),
9095
policyId: z.string().min(1),
9196
principalId: z.string().min(1),
9297
}).optional(),

packages/sdk/src/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ export interface ComputerAgentOptions {
153153
*/
154154
readonly policy?: {
155155
readonly kind: "srs";
156-
readonly endpoint: string;
157-
readonly apiKey: string;
156+
/** Optional — harness falls back to its own SRS_BASE_URL when omitted. */
157+
readonly endpoint?: string;
158+
/** Optional — harness falls back to its own SRS_API_KEY when omitted. */
159+
readonly apiKey?: string;
158160
readonly policyId: string;
159161
readonly principalId: string;
160162
};

0 commit comments

Comments
 (0)