Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/handlers/project/invoke/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ describe("project invoke", () => {
.args[0] as RuntimeInvokeRequest;
expect(new TextDecoder().decode(request.payload)).toBe(payload);
expect(request.contentType).toBe("application/custom+json");
expect(request.runtimeUserId).toBe("default");
expect(core.runtime.calls.at(-1)!.args[1]).toEqual({ region: TARGET.region });
expect(io.stdout()).toBe("runtime response");
expect(resolved.calls).toEqual([{ target: TARGET }]);
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/project/invoke/runtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const createProjectInvokeRuntimeHandler = (
flag("content-type", "the payload content type", z.string().optional()),
flag("accept", "the accepted response content type", z.string().optional()),
flag("session-id", "the Runtime session ID", z.string().optional()),
flag("user-id", "the Runtime user ID", z.string().optional()),
flag("user-id", 'the Runtime user ID (default: "default")', z.string().optional()),
flag("header", "an ordered application header", z.array(z.string()).optional(), {
sensitive: true,
}),
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/runtime/invoke/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const createInvokeRuntimeHandler = (core: Core, io: AppIO) =>
flag("content-type", "the payload content type", z.string().optional()),
flag("accept", "the accepted response content type", z.string().optional()),
flag("session-id", "the Runtime session ID", z.string().optional()),
flag("user-id", "the Runtime user ID", z.string().optional()),
flag("user-id", 'the Runtime user ID (default: "default")', z.string().optional()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should be get this from DEFAULT_RUNTIME_USER_ID.

flag("header", "an ordered application header", z.array(z.string()).optional(), {
sensitive: true,
}),
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/runtime/invoke/invoke.screen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ describe("Runtime invoke JSON console", () => {
await screen.write("{}");
await screen.press("return");
await waitFor(() => invokeRequests(core).length === 1);
expect(invokeRequests(core)[0]!.runtimeUserId).toBeUndefined();
expect(invokeRequests(core)[0]!.runtimeUserId).toBe("default");
expect(invokeRequests(core)[0]!.applicationHeaders).toBeUndefined();
expect(invokeRequests(core)[0]!.bearerToken).toBeUndefined();
});
Expand Down
1 change: 1 addition & 0 deletions src/handlers/runtime/invoke/invoke.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe("runtime invoke", () => {
qualifier: "DEFAULT",
payload: new TextEncoder().encode('{"prompt":"hello"}'),
contentType: "application/json",
runtimeUserId: "default",
});
expect(invoke.args[1]).toEqual({ region: REGION });
expect(lookup.args[2]).toBe(invoke.args[2]);
Expand Down
9 changes: 9 additions & 0 deletions src/handlers/runtime/invoke/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ describe("normalizeRuntimeInvokeRequest", () => {
expect(request.accept).toBe("application/json, text/event-stream");
});

test("defaults the Runtime user ID when omitted", () => {
const request = normalizeRuntimeInvokeRequest(detail(), {
runtimeId: RUNTIME_ID,
payload: new Uint8Array(),
});

expect(request.runtimeUserId).toBe("default");
});

test("maps every request field and ordered allowed headers once", () => {
const request = normalizeRuntimeInvokeRequest(
detail({
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/runtime/invoke/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type RuntimeInvokeInput = Omit<
> &
Partial<Pick<RuntimeInvokeRequest, "qualifier" | "contentType">>;

const DEFAULT_RUNTIME_USER_ID = "default";
const CUSTOM_HEADER_PREFIX = "x-amzn-bedrock-agentcore-runtime-custom-";
const RESERVED_HEADERS = new Set([
"authorization",
Expand Down Expand Up @@ -170,6 +171,7 @@ export function normalizeRuntimeInvokeRequest(
payload,
contentType: contentType || "application/json",
...modeled,
runtimeUserId: modeled.runtimeUserId ?? DEFAULT_RUNTIME_USER_ID,
accept: modeled.accept ?? (mcp ? "application/json, text/event-stream" : undefined),
...(applicationHeaders.length > 0 && { applicationHeaders }),
};
Expand Down
Loading