Skip to content

Commit

Agents' budget alerts and sessions waiting for approval reach the person they're for: notifications finds who to tell under target as well as at the top level.

syntaqxcommitted Parent2edcd6bBrowse files
1 file+4−10/1 viewed
+4−1
4444 }
4545
4646 /** A user id from the arguments, or one looked up by username. */
47−async function userIdOf(env: Env, args: { user_id?: unknown; username?: unknown }): Promise<string | null> {
47+async function userIdOf(env: Env, given: { user_id?: unknown; username?: unknown; target?: unknown }): Promise<string | null> {
48+ // Who it's for, at the top level or under `target` as the agents service sends it.
49+ const target = given.target && typeof given.target === "object" ? (given.target as { user_id?: unknown; username?: unknown }) : null;
50+ const args = { user_id: given.user_id ?? target?.user_id, username: given.username ?? target?.username };
4851 if (typeof args.user_id === "string" && args.user_id) return args.user_id;
4952 if (typeof args.username !== "string" || !args.username) return null;
5053 const user = await identityClient(env.IDENTITY)