Skip to content

Commit dd8525c

Browse files
committed
fix(gateway): accept music generation internal events
1 parent eba8fed commit dd8525c

4 files changed

Lines changed: 68 additions & 8 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const AGENT_INTERNAL_EVENT_TYPE_TASK_COMPLETION = "task_completion" as const;
2+
3+
export const AGENT_INTERNAL_EVENT_SOURCES = [
4+
"subagent",
5+
"cron",
6+
"video_generation",
7+
"music_generation",
8+
] as const;
9+
10+
export const AGENT_INTERNAL_EVENT_STATUSES = ["ok", "timeout", "error", "unknown"] as const;
11+
12+
export type AgentInternalEventType = typeof AGENT_INTERNAL_EVENT_TYPE_TASK_COMPLETION;
13+
export type AgentInternalEventSource = (typeof AGENT_INTERNAL_EVENT_SOURCES)[number];
14+
export type AgentInternalEventStatus = (typeof AGENT_INTERNAL_EVENT_STATUSES)[number];

src/agents/internal-events.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
import {
2+
AGENT_INTERNAL_EVENT_TYPE_TASK_COMPLETION,
3+
type AgentInternalEventSource,
4+
type AgentInternalEventStatus,
5+
} from "./internal-event-contract.js";
16
import {
27
escapeInternalRuntimeContextDelimiters,
38
INTERNAL_RUNTIME_CONTEXT_BEGIN,
49
INTERNAL_RUNTIME_CONTEXT_END,
510
} from "./internal-runtime-context.js";
611

7-
export type AgentInternalEventType = "task_completion";
8-
912
export type AgentTaskCompletionInternalEvent = {
10-
type: "task_completion";
11-
source: "subagent" | "cron" | "video_generation" | "music_generation";
13+
type: typeof AGENT_INTERNAL_EVENT_TYPE_TASK_COMPLETION;
14+
source: AgentInternalEventSource;
1215
childSessionKey: string;
1316
childSessionId?: string;
1417
announceType: string;
1518
taskLabel: string;
16-
status: "ok" | "timeout" | "error" | "unknown";
19+
status: AgentInternalEventStatus;
1720
statusLabel: string;
1821
result: string;
1922
statsLine?: string;

src/gateway/protocol/schema/agent.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { Type } from "@sinclair/typebox";
2+
import {
3+
AGENT_INTERNAL_EVENT_SOURCES,
4+
AGENT_INTERNAL_EVENT_STATUSES,
5+
AGENT_INTERNAL_EVENT_TYPE_TASK_COMPLETION,
6+
} from "../../../agents/internal-event-contract.js";
27
import { InputProvenanceSchema, NonEmptyString, SessionLabelString } from "./primitives.js";
38

49
export const AgentInternalEventSchema = Type.Object(
510
{
6-
type: Type.Literal("task_completion"),
7-
source: Type.String({ enum: ["subagent", "cron", "video_generation"] }),
11+
type: Type.Literal(AGENT_INTERNAL_EVENT_TYPE_TASK_COMPLETION),
12+
source: Type.String({ enum: [...AGENT_INTERNAL_EVENT_SOURCES] }),
813
childSessionKey: Type.String(),
914
childSessionId: Type.Optional(Type.String()),
1015
announceType: Type.String(),
1116
taskLabel: Type.String(),
12-
status: Type.String({ enum: ["ok", "timeout", "error", "unknown"] }),
17+
status: Type.String({ enum: [...AGENT_INTERNAL_EVENT_STATUSES] }),
1318
statusLabel: Type.String(),
1419
result: Type.String(),
1520
statsLine: Type.Optional(Type.String()),

src/gateway/server-methods/agent.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,44 @@ describe("gateway agent handler", () => {
759759
);
760760
});
761761

762+
it("accepts music generation internal events", async () => {
763+
primeMainAgentRun();
764+
mocks.agentCommand.mockClear();
765+
const respond = vi.fn();
766+
767+
await invokeAgent(
768+
{
769+
message: "music generation finished",
770+
sessionKey: "agent:main:main",
771+
internalEvents: [
772+
{
773+
type: "task_completion",
774+
source: "music_generation",
775+
childSessionKey: "music:task-123",
776+
childSessionId: "task-123",
777+
announceType: "music generation task",
778+
taskLabel: "compose a loop",
779+
status: "ok",
780+
statusLabel: "completed successfully",
781+
result: "MEDIA: https://example.test/song.mp3",
782+
replyInstruction: "Reply in your normal assistant voice now.",
783+
},
784+
],
785+
idempotencyKey: "music-generation-event",
786+
},
787+
{ reqId: "music-generation-event-1", respond },
788+
);
789+
790+
await waitForAssertion(() => expect(mocks.agentCommand).toHaveBeenCalled());
791+
expect(respond).not.toHaveBeenCalledWith(
792+
false,
793+
undefined,
794+
expect.objectContaining({
795+
message: expect.stringContaining("invalid agent params"),
796+
}),
797+
);
798+
});
799+
762800
it("only forwards workspaceDir for spawned sessions with stored workspace inheritance", async () => {
763801
primeMainAgentRun();
764802
mockMainSessionEntry({

0 commit comments

Comments
 (0)