Skip to content
Open
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
12 changes: 9 additions & 3 deletions packages/eve/src/channel/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UserContent } from "ai";

import type { UnstampedMessageStreamEvent, MessageStreamEvent } from "#protocol/message.js";
import type { MessageStreamEvent, UnstampedMessageStreamEvent } from "#protocol/message.js";
import type { CancelTurnStatus } from "#protocol/cancel-turn.js";
import type { RunMode } from "#shared/run-mode.js";
import type { RuntimeActionResult } from "#runtime/actions/types.js";
Expand Down Expand Up @@ -198,10 +198,16 @@ export interface SubagentInputRequestHookPayload {
readonly subagentName: string;
}

/** Authorization lifecycle event forwarded from a delegated child. */
/** Responder-specific lifecycle event forwarded from a delegated child. */
export type SubagentAuthorizationEvent = Extract<
UnstampedMessageStreamEvent,
{ type: "authorization.required" | "authorization.completed" }
{
type:
| "approval.candidate"
| "approval.settled"
| "authorization.required"
| "authorization.completed";
}
>;

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/eve/src/execution/subagent-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ export function isSubagentAdapterState(value: unknown): value is SubagentAdapter
*/
export const SUBAGENT_ADAPTER: ChannelAdapter = {
kind: SUBAGENT_ADAPTER_KIND,
async "approval.candidate"(data, ctx) {
await forwardSubagentAuthorizationEvent({ data, type: "approval.candidate" }, ctx);
},
async "approval.settled"(data, ctx) {
await forwardSubagentAuthorizationEvent({ data, type: "approval.settled" }, ctx);
},
async "authorization.required"(data, ctx) {
await forwardSubagentAuthorizationEvent({ data, type: "authorization.required" }, ctx);
},
Expand Down
46 changes: 46 additions & 0 deletions packages/eve/src/execution/subagent-auth-proxy.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,52 @@ function decodeEvent(chunk: Uint8Array): MessageStreamEvent {
}

describe("subagent authorization proxy", () => {
it("preserves approval candidate and settlement events", async () => {
const parentSessionId = "parent-approval-session";
const session = createSession(parentSessionId);
const { ctx } = buildContext({ adapter: authorizationAdapter, sessionId: parentSessionId });
const chunks: Uint8Array[] = [];
const parentWritable = createCapturingWritable(chunks);
const candidateEvent: SubagentAuthorizationEvent = {
data: {
candidateId: "candidate-1",
outcome: "pending",
requestId: "approval-1",
responderPrincipalId: "slack:T1:U1",
sequence: 0,
stepIndex: 1,
turnId: "child-turn",
},
type: "approval.candidate",
};
const settledEvent: SubagentAuthorizationEvent = {
data: {
outcome: "approved",
requestId: "approval-1",
responderPrincipalId: "slack:T1:U1",
sequence: 0,
stepIndex: 2,
turnId: "child-turn",
},
type: "approval.settled",
};

await emitProxiedSubagentEvent({
ctx,
durableSession: projectToDurableSession(session),
hookPayload: authorizationPayload(candidateEvent),
parentWritable,
});
await emitProxiedSubagentEvent({
ctx,
durableSession: projectToDurableSession(session),
hookPayload: authorizationPayload(settledEvent),
parentWritable,
});

expect(decodeEvent(chunks[0]!)).toMatchObject(candidateEvent);
expect(decodeEvent(chunks[1]!)).toMatchObject(settledEvent);
});
it("preserves events and parent adapter state across required/completed steps", async () => {
const parentSessionId = "parent-session";
const session = createSession(parentSessionId);
Expand Down
Loading