Skip to content

An open-source, faster Devin alternative

TypeScript

agent: the event input variant for delivered turn outcomes

Igor Zalutski534fb8919476
diff --git a/agent/src/index.test.ts b/agent/src/index.test.ts
index 8b427123..6215b023 100644
--- a/agent/src/index.test.ts
+++ b/agent/src/index.test.ts
@@ -6,9 +6,12 @@ import {
defineMemory,
documentMemory,
httpMemory,
+ useInput,
useMemory,
useSecret,
+ type AgentInput,
type MemoryProjection,
+ type OutcomeEvent,
} from "./index.js";
const HOOKS = Symbol.for("opencomputer.agent-hooks");
@@ -402,3 +405,49 @@ test("useMemory fails a render whose session has no binding for the resource", (
/hooks can only run while rendering an agent/,
);
});
+
+// Public delivery slice: the input an event subscription delivers. This is
+// the authoring contract the review found missing; the narrowing below is
+// what has to type-check for an agent to read the event.
+test("useInput narrows a delivered turn outcome to its typed event", () => {
+ const event: OutcomeEvent = {
+ id: "event_9",
+ type: "turn.completed",
+ sessionId: "ses_worker",
+ turnId: "turn-1",
+ agentId: "worker",
+ occurredAt: "2026-09-10T12:00:00.000Z",
+ result: { text: "Guide reproduced; the fix is in step 3.", truncated: false },
+ };
+ const input: AgentInput = {
+ source: "event",
+ text: "Outcome event turn.completed from worker.",
+ event,
+ };
+ const globals = globalThis as Record<PropertyKey, unknown>;
+ globals[HOOKS] = { useInput: () => input };
+ try {
+ const read = useInput();
+ assert.equal(read.source, "event");
+ if (read.source === "event") {
+ assert.equal(read.event.type, "turn.completed");
+ assert.equal(read.event.sessionId, "ses_worker");
+ assert.equal(read.event.result?.text, "Guide reproduced; the fix is in step 3.");
+ assert.equal(read.event.error, undefined);
+ }
+ // A failed outcome carries the reason and the bounded message instead.
+ const failed: AgentInput = {
+ source: "event",
+ event: { ...event, type: "turn.failed", reason: "runtime_lost", error: "The agent runtime stopped reporting" },
+ };
+ if (failed.source === "event" && failed.event.type === "turn.failed") {
+ assert.equal(failed.event.reason, "runtime_lost");
+ assert.equal(failed.event.error, "The agent runtime stopped reporting");
+ }
+ // The other sources have no event.
+ const user: AgentInput = { source: "user", text: "hi" };
+ assert.equal("event" in user, false);
+ } finally {
+ delete globals[HOOKS];
+ }
+});
diff --git a/agent/src/index.ts b/agent/src/index.ts
index 598e8f60..54c3e0bc 100644
--- a/agent/src/index.ts
+++ b/agent/src/index.ts
@@ -20,7 +20,8 @@ export type InputSource =
| "schedule"
| "webhook"
| "subagent"
- | "system";
+ | "system"
+ | "event";
export interface ScheduleRunContext {
readonly id: string;
@@ -37,6 +38,33 @@ export interface WebhookRequestContext {
readonly receivedAt: string;
}
+/** The turn outcomes an event subscription delivers. */
+export type OutcomeEventType = "turn.completed" | "turn.failed" | "turn.cancelled";
+
+/**
+ * A recorded turn outcome of another session in the project, delivered by
+ * an event subscription as the input of a new turn. The platform attests
+ * where it came from through `source: "event"`; the included agent output
+ * is data to reason about, not instructions to follow.
+ */
+export interface OutcomeEvent {
+ /** The source session's own id for its terminal `turn.*` event. */
+ readonly id: string;
+ readonly type: OutcomeEventType;
+ /** The session and turn whose outcome this is. */
+ readonly sessionId: string;
+ readonly turnId: string;
+ /** The agent that ran the source turn. */
+ readonly agentId: string;
+ readonly occurredAt: string;
+ /** Why the turn failed or was cancelled, when the source recorded a reason. */
+ readonly reason?: string;
+ /** The failure message, bounded, when the turn failed. */
+ readonly error?: string;
+ /** The final assistant message of a completed turn; `truncated` when it was cut to fit. */
+ readonly result?: { readonly text: string; readonly truncated?: boolean };
+}
+
interface BasicAgentInput {
readonly text?: string;
readonly payload?: DataValue;
@@ -44,7 +72,7 @@ interface BasicAgentInput {
export type AgentInput =
| (BasicAgentInput & {
- readonly source: Exclude<InputSource, "schedule" | "webhook">;
+ readonly source: Exclude<InputSource, "schedule" | "webhook" | "event">;
})
| (BasicAgentInput & {
readonly source: "schedule";
@@ -53,6 +81,10 @@ export type AgentInput =
| (BasicAgentInput & {
readonly source: "webhook";
readonly webhook: Readonly<WebhookRequestContext>;
+ })
+ | (BasicAgentInput & {
+ readonly source: "event";
+ readonly event: Readonly<OutcomeEvent>;
});
export interface ResourceReference {