Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

feat(eve): label background task activity (#3333)

Ben Pankow638aed57e721
diff --git a/.changeset/task-presentation-label.md b/.changeset/task-presentation-label.md
new file mode 100644
index 000000000..1d6b68983
--- /dev/null
+++ b/.changeset/task-presentation-label.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Background task activity now uses a tool's per-call label when one is provided, while retaining the tool or subagent name for execution identity.
diff --git a/packages/eve/extension-contracts/compatibility/channel/v20.ts b/packages/eve/extension-contracts/compatibility/channel/v20.ts
new file mode 100644
index 000000000..2462a4352
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/channel/v20.ts
@@ -0,0 +1,11 @@
+import { defineChannel, POST } from "#public/channels/index.js";
+
+export default defineChannel({
+ metadata: () => ({ audience: "public" }),
+ routes: [
+ POST("/continue/:sessionId", async (_request, { attachSession, params }) => {
+ const result = await attachSession(params.sessionId!).send("Continue.", { auth: null });
+ return Response.json({ accepted: result.status === "accepted" });
+ }),
+ ],
+});
diff --git a/packages/eve/extension-contracts/compatibility/dynamicTool/v36.ts b/packages/eve/extension-contracts/compatibility/dynamicTool/v36.ts
new file mode 100644
index 000000000..0552088f0
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/dynamicTool/v36.ts
@@ -0,0 +1,20 @@
+import { z } from "zod";
+
+import { defineDynamic, defineTool } from "#public/tools/index.js";
+
+export default defineDynamic({
+ events: {
+ "session.started": () =>
+ defineTool({
+ description: "Report deployment progress.",
+ inputSchema: z.object({ service: z.string() }),
+ outputSchema: z.object({ url: z.string() }),
+ label: {
+ complete: ({ service }, { url }) => `Deployed ${service} to ${url}`,
+ delta: ({ service }) => `Deploying ${service}`,
+ start: ({ service }) => `Deploy ${service}`,
+ },
+ execute: async ({ service }) => ({ url: `https://${service}.example.com` }),
+ }),
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/schedule/v11.ts b/packages/eve/extension-contracts/compatibility/schedule/v11.ts
new file mode 100644
index 000000000..639fc8dd7
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/schedule/v11.ts
@@ -0,0 +1,8 @@
+import { defineSchedule } from "#public/schedules/index.js";
+
+export default defineSchedule({
+ cron: "0 9 * * *",
+ run({ waitUntil, appAuth }) {
+ waitUntil(Promise.resolve(appAuth.principalId));
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/tool/v36.ts b/packages/eve/extension-contracts/compatibility/tool/v36.ts
new file mode 100644
index 000000000..75ca1333d
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/tool/v36.ts
@@ -0,0 +1,16 @@
+import { z } from "zod";
+
+import { defineTool } from "#public/tools/index.js";
+
+export default defineTool({
+ description: "Report the active session.",
+ inputSchema: z.object({}),
+ outputSchema: z.object({
+ sessionId: z.string(),
+ turnId: z.string(),
+ }),
+ execute: (_input, ctx) => ({
+ sessionId: ctx.session.id,
+ turnId: ctx.session.turn.id,
+ }),
+});
diff --git a/packages/eve/extension-contracts/reports/channel/v21.json b/packages/eve/extension-contracts/reports/channel/v21.json
new file mode 100644
index 000000000..bde379fa9
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/channel/v21.json
@@ -0,0 +1,21 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "channel",
+ "epoch": 21,
+ "sha256": "752407f276d3a3abcffe03c75bfad70a4c58358c158fc15a5846820d2b486f5c",
+ "exports": [
+ "DELETE",
+ "GET",
+ "HEAD",
+ "OPTIONS",
+ "PATCH",
+ "POST",
+ "PUT",
+ "WS",
+ "createWebSocketUpgradeServer",
+ "defineChannel",
+ "disableRoute",
+ "isChannel",
+ "isDisabledRouteSentinel"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/dynamicTool/v37.json b/packages/eve/extension-contracts/reports/dynamicTool/v37.json
new file mode 100644
index 000000000..d2205bb60
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/dynamicTool/v37.json
@@ -0,0 +1,14 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "dynamicTool",
+ "epoch": 37,
+ "sha256": "9f18c208c383d17cb5ccae70c06039d789460207a585bea6c7fa897521ed5e61",
+ "exports": [
+ "DynamicToolEntry",
+ "DynamicToolEvents",
+ "DynamicToolResult",
+ "DynamicToolSet",
+ "defineDurableCallback",
+ "defineDynamic"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/schedule/v12.json b/packages/eve/extension-contracts/reports/schedule/v12.json
new file mode 100644
index 000000000..906690d91
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/schedule/v12.json
@@ -0,0 +1,14 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "schedule",
+ "epoch": 12,
+ "sha256": "37188120b55d126fd1537d0987ddd9f562bf44e39d2ef6cb6d66f3104b3eb53a",
+ "exports": [
+ "ScheduleDefinition",
+ "ScheduleHandlerArgs",
+ "ScheduleRunHandler",
+ "ScheduleToFn",
+ "TypedReceiveTarget",
+ "defineSchedule"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/tool/v37.json b/packages/eve/extension-contracts/reports/tool/v37.json
new file mode 100644
index 000000000..5d79b32ce
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/tool/v37.json
@@ -0,0 +1,20 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "tool",
+ "epoch": 37,
+ "sha256": "a9b81894ffcc35a545decb6d6102333875f6c44d4bace868b15aef51fe37d440",
+ "exports": [
+ "defaultWebSearch",
+ "defineTool",
+ "defineWorkflowTool",
+ "disableTool",
+ "experimental_workflow",
+ "isDisabledToolSentinel",
+ "isExperimentalWorkflowToolDefinition",
+ "isWebSearchToolDefinition",
+ "toolOutput",
+ "toolOutputPart",
+ "toolResultFrom",
+ "webSearch"
+ ]
+}
diff --git a/packages/eve/src/compiler/extension-compatibility.ts b/packages/eve/src/compiler/extension-compatibility.ts
index 373aea2d2..e6dbf13dd 100644
--- a/packages/eve/src/compiler/extension-compatibility.ts
+++ b/packages/eve/src/compiler/extension-compatibility.ts
@@ -22,8 +22,8 @@ interface ExtensionCapabilityContract {
const EXTENSION_CAPABILITY_CONTRACTS = {
extension: { current: 1, supported: [1], dropped: {} },
tool: {
- current: 36,
- supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 28, 29, 30, 31, 32, 34, 35, 36],
+ current: 37,
+ supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 28, 29, 30, 31, 32, 34, 35, 36, 37],
dropped: {
14: "TaskExec.delegated was removed; migrate to workflow-backed background tools",
15: "TaskExec replaces stageEffect with send",
@@ -43,10 +43,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
dynamicTool: {
- current: 36,
+ current: 37,
supported: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 28, 29, 30, 31, 32,
- 33, 34, 35, 36,
+ 33, 34, 35, 36, 37,
],
dropped: {
21: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
@@ -58,15 +58,15 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
channel: {
- current: 20,
- supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20],
+ current: 21,
+ supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21],
dropped: {
12: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
},
},
schedule: {
- current: 11,
- supported: [1, 2, 3, 4, 6, 7, 8, 9, 10, 11],
+ current: 12,
+ supported: [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12],
dropped: {
5: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
},
diff --git a/packages/eve/src/execution/activity-work.ts b/packages/eve/src/execution/activity-work.ts
index f9f620934..78dd40d6c 100644
--- a/packages/eve/src/execution/activity-work.ts
+++ b/packages/eve/src/execution/activity-work.ts
@@ -23,6 +23,7 @@ export function deriveRootTurnWorkIdentity(session: Session): ActivityWorkIdenti
export function deriveBackgroundTaskActivityObserver(input: {
readonly activityObserver: ActivityObserverConfig | undefined;
readonly callId: string;
+ readonly label?: string;
readonly name: string;
readonly parentSessionId: string;
readonly parentTurnId: string;
@@ -67,6 +68,7 @@ export function deriveChildActivityObserverConfig(input: {
export function deriveChildWorkIdentity(input: {
readonly callId: string;
readonly kind: Exclude<ActivityWorkKind, "root-turn">;
+ readonly label?: string;
readonly name: string;
readonly parentSessionId: string;
readonly parentTurnId: string;
@@ -76,6 +78,7 @@ export function deriveChildWorkIdentity(input: {
callId: input.callId,
id: deriveChildActivityWorkId(input),
kind: input.kind,
+ label: input.label,
name: input.name,
parentId: input.parentWork.id,
rootSessionId: input.parentWork.rootSessionId,
diff --git a/packages/eve/src/execution/session-activity.ts b/packages/eve/src/execution/session-activity.ts
index 5ce67561e..b9ce258a3 100644
--- a/packages/eve/src/execution/session-activity.ts
+++ b/packages/eve/src/execution/session-activity.ts
@@ -92,6 +92,7 @@ function startWork(
: "running");
const work: ActivityWorkStateV1 = {
...event.work,
+ label: event.work.label === undefined ? undefined : normalizePresentationText(event.work.label),
name: event.work.name === undefined ? undefined : normalizePresentationText(event.work.name),
phase: phase as ActivityWorkPhase,
settledAt: pending?.settledAt ?? (phase === "cancelled" ? parent?.settledAt : undefined),
diff --git a/packages/eve/src/execution/session-command-inbox.test.ts b/packages/eve/src/execution/session-command-inbox.test.ts
index 9cca2d323..434da7062 100644
--- a/packages/eve/src/execution/session-command-inbox.test.ts
+++ b/packages/eve/src/execution/session-command-inbox.test.ts
@@ -123,7 +123,7 @@ describe("createSessionCommandInbox", () => {
);
expect(createHookMock).toHaveBeenCalledOnce();
expect(createHookMock).toHaveBeenCalledWith({
- metadata: { sessionInboxWireVersion: 6, workflowTaskAuthorization: true },
+ metadata: { sessionInboxWireVersion: 7, workflowTaskAuthorization: true },
token: "stable",
});
await inbox.dispose();
diff --git a/packages/eve/src/execution/tasks/parent/delegate.ts b/packages/eve/src/execution/tasks/parent/delegate.ts
index 128c3a843..15d471b8b 100644
--- a/packages/eve/src/execution/tasks/parent/delegate.ts
+++ b/packages/eve/src/execution/tasks/parent/delegate.ts
@@ -5,6 +5,7 @@
*/
import type { ActivityObserverConfig } from "#channel/types.js";
import type { HarnessSession } from "#harness/types.js";
+import type { ActivityWorkIdentityV1 } from "#protocol/activity.js";
import {
readLatestTaskView,
sendTaskCommand,
@@ -20,6 +21,7 @@ import { isTerminalTaskStatus, type TaskMetadata } from "#tasks/types.js";
/** A prepared background task: identity plus its started durable run. */
export interface BackgroundTask {
+ readonly activityWorkIdentity?: ActivityWorkIdentityV1;
readonly taskInboxToken: string;
readonly createdByStepIndex?: number;
readonly createdByTurnId: string;
diff --git a/packages/eve/src/execution/tasks/parent/tool-execution.integration.test.ts b/packages/eve/src/execution/tasks/parent/tool-execution.integration.test.ts
index a798e3925..0c51ea80c 100644
--- a/packages/eve/src/execution/tasks/parent/tool-execution.integration.test.ts
+++ b/packages/eve/src/execution/tasks/parent/tool-execution.integration.test.ts
@@ -98,9 +98,11 @@ async function createScope(session = createSession(), activityObserver?: Activit
agentId: string | undefined = identity.id,
name = identity.name,
resultKind: "subagent" | "tool" = "subagent",
+ label?: (input: unknown) => string,
) {
const definition = {
execute: vi.fn(),
+ label: label === undefined ? undefined : { start: label },
name,
nodeId: identity.nodeId,
resultKind,
@@ -191,6 +193,40 @@ describe("background subagent steering", () => {
},
);
+ it("persists a tool-derived task label without changing its subagent identity", async () => {
+ const activityObserver = {
+ sink: { url: "https://parent.example/activity", version: 1 as const },
+ workIdentity: {
+ id: "work:root",
+ kind: "root-turn" as const,
+ rootSessionId: "parent",
+ rootTurnId: "turn-2",
+ },
+ };
+ const scope = await createScope(createSession(), activityObserver);
+
+ await scope.execute("steering-call", identity.id, identity.name, "subagent", (input) => {
+ (input as { message: string }).message = "Mutated";
+ return "Investigator";
+ });
+ expect(startTaskRun).toHaveBeenCalledWith(
+ expect.objectContaining({
+ workflow: expect.objectContaining({
+ input: { agentId: identity.id, message: "Use the updated instruction" },
+ }),
+ }),
+ );
+ const committed = await scope.commit();
+ const task = getSessionTaskIndex(committed.state).find(
+ (candidate) => candidate.taskId !== entry.taskId,
+ );
+
+ expect(task).toMatchObject({
+ activityWorkIdentity: { label: "Investigator", name: "research" },
+ metadata: { name: "research" },
+ });
+ });
+
it("cancels the old task before starting a new task in the same child", async () => {
const scope = await createScope();
const cancellation = Promise.withResolvers<typeof cancelledView>();
diff --git a/packages/eve/src/execution/tasks/parent/tool-execution.ts b/packages/eve/src/execution/tasks/parent/tool-execution.ts
index 0bb1267fd..d5c3ed80e 100644
--- a/packages/eve/src/execution/tasks/parent/tool-execution.ts
+++ b/packages/eve/src/execution/tasks/parent/tool-execution.ts
@@ -17,9 +17,9 @@ import {
type BackgroundToolExecutor,
} from "#harness/background-tools.js";
import { deriveBackgroundTaskActivityObserver } from "#execution/activity-work.js";
-import type { ActivityWorkIdentityV1 } from "#protocol/activity.js";
import { isAsyncIterable } from "#shared/async-iterable.js";
import { parseJsonValue } from "#shared/json.js";
+import { projectToolStartLabel } from "#harness/action-presentation.js";
import type { ToolExecuteOptions } from "#tools/definition.js";
import { createTaskMessage, isTaskMessage, type TaskExec } from "#tools/task.js";
import { findSessionTaskEntry, recordSessionTask } from "#tasks/session-index.js";
@@ -55,11 +55,6 @@ import { cancelBackgroundAgentTask } from "#execution/tools/subagent/task-cancel
const IN_PROCESS_WORKFLOW_EXECUTOR = { data: {}, kind: "workflow-task" } as const;
-type ActivityBackgroundTask = BackgroundTask & {
- readonly activityWorkIdentity?: ActivityWorkIdentityV1;
-};
-type ActivityBackgroundTaskDraft = Omit<ActivityBackgroundTask, "taskRunId">;
-
interface BackgroundToolExecutionRecord {
readonly callId: string;
claim?: {
@@ -71,7 +66,7 @@ interface BackgroundToolExecutionRecord {
readonly operationId: string;
};
settled: boolean;
- task?: ActivityBackgroundTask;
+ task?: BackgroundTask;
}
interface BackgroundToolStepResult {
@@ -335,7 +330,7 @@ class BackgroundToolExecutionScope implements BackgroundToolExecutor {
readonly record: BackgroundToolExecutionRecord;
}): Promise<{
readonly receipt?: { readonly agentId: string };
- readonly task: ActivityBackgroundTask;
+ readonly task: BackgroundTask;
}> {
const workflow =
input.input.definition.workflowId === undefined
@@ -386,10 +381,12 @@ class BackgroundToolExecutionScope implements BackgroundToolExecutor {
kind: "tool" as const,
name: input.input.definition.name,
};
+ const activityLabel = projectToolStartLabel(input.input.definition, input.input.toolInput);
const taskInput = {
activityObserver: deriveBackgroundTaskActivityObserver({
activityObserver: input.ctx.get(ActivityObserverKey),
callId: input.input.options.toolCallId,
+ label: activityLabel,
name: metadata.name,
parentSessionId: this.initialSession.sessionId,
parentTurnId,
@@ -419,7 +416,7 @@ class BackgroundToolExecutionScope implements BackgroundToolExecutor {
throw new Error(`Background workflow tool "${input.input.definition.name}" has no input.`);
}
- const task: ActivityBackgroundTaskDraft = {
+ const task: Omit<BackgroundTask, "taskRunId"> = {
...prepareBackgroundTask(taskInput),
activityWorkIdentity:
workflow.resultKind === "subagent" ? taskInput.activityObserver?.workIdentity : undefined,
diff --git a/packages/eve/src/execution/tools/subagent/task-activity.integration.test.ts b/packages/eve/src/execution/tools/subagent/task-activity.integration.test.ts
index 9940615b4..d56581382 100644
--- a/packages/eve/src/execution/tools/subagent/task-activity.integration.test.ts
+++ b/packages/eve/src/execution/tools/subagent/task-activity.integration.test.ts
@@ -75,10 +75,11 @@ const bundle = {
subagentRegistry: createRuntimeSubagentRegistry({ subagents: [] }),
} as Parameters<typeof startSubagent>[0]["bundle"];
-function taskObserver(callId: string): Observer {
+function taskObserver(callId: string, label?: string): Observer {
const observer = deriveBackgroundTaskActivityObserver({
activityObserver: parentObserver,
callId,
+ label,
name: "research",
parentSessionId: session.sessionId,
parentTurnId: "parent-turn",
@@ -205,10 +206,11 @@ describe("task-owned subagent activity", () => {
it.each(["local", "remote"] as const)(
"keeps one task item through %s child activity and settlement",
async (kind) => {
- const task = taskObserver("task-a");
+ const task = taskObserver("task-a", "Investigator");
const captured = await start(kind, task);
if (captured === undefined) throw new Error("Expected child observer");
expect(captured).toEqual(task);
+ expect(captured.workIdentity).toMatchObject({ label: "Investigator", name: "research" });
let snapshot = apply(initialSnapshot(), taskEvents(task, "working"));
snapshot = apply(snapshot, project(turn("turn.started", "child-turn"), captured));
snapshot = apply(snapshot, project(tool("actions.requested", "child-turn"), captured));
diff --git a/packages/eve/src/execution/wire/session-inbox-contract.ts b/packages/eve/src/execution/wire/session-inbox-contract.ts
index eef65f157..8770453c7 100644
--- a/packages/eve/src/execution/wire/session-inbox-contract.ts
+++ b/packages/eve/src/execution/wire/session-inbox-contract.ts
@@ -1,5 +1,5 @@
/** Every explicit session-inbox wire version still supported by producers. */
-export const SESSION_INBOX_WIRE_VERSIONS = [1, 2, 3, 4, 5, 6] as const;
+export const SESSION_INBOX_WIRE_VERSIONS = [1, 2, 3, 4, 5, 6, 7] as const;
export type SessionInboxWireVersion = (typeof SESSION_INBOX_WIRE_VERSIONS)[number];
diff --git a/packages/eve/src/execution/wire/session-inbox-encoder.ts b/packages/eve/src/execution/wire/session-inbox-encoder.ts
index b3fa727c8..c2addce6a 100644
--- a/packages/eve/src/execution/wire/session-inbox-encoder.ts
+++ b/packages/eve/src/execution/wire/session-inbox-encoder.ts
@@ -34,11 +34,15 @@ import {
encodeSessionCommandV6,
type SessionInboxWireV6,
} from "#execution/wire/session-inbox-wire.v6.js";
+import {
+ encodeSessionCommandV7,
+ type SessionInboxWireV7,
+} from "#execution/wire/session-inbox-wire.v7.js";
type SessionInboxCommand = DeliverHookPayload | SessionCommand | SessionTimeoutHookPayload;
/** Current wire type consumed after migration. */
-export type SessionInboxWire = SessionInboxWireV6;
+export type SessionInboxWire = SessionInboxWireV7;
type LegacySessionInboxWireTarget = Extract<SessionInboxWireTarget, { readonly version: 0 }>;
type VersionedSessionInboxEncoder = (command: SessionInboxCommand) => unknown;
@@ -55,6 +59,7 @@ const versionedEncoders = {
5: (command: SessionInboxCommand) =>
encodeSessionCommandV5(withoutOwnedTaskCancellation(command)),
6: encodeSessionCommandV6,
+ 7: encodeSessionCommandV7,
} satisfies Record<SessionInboxWireVersion, VersionedSessionInboxEncoder>;
/** Encodes a command for the selected session-inbox consumer. */
@@ -64,6 +69,7 @@ function encode(command: SessionInboxCommand, target: { readonly version: 3 }):
function encode(command: SessionInboxCommand, target: { readonly version: 4 }): SessionInboxWireV4;
function encode(command: SessionInboxCommand, target: { readonly version: 5 }): SessionInboxWireV5;
function encode(command: SessionInboxCommand, target: { readonly version: 6 }): SessionInboxWireV6;
+function encode(command: SessionInboxCommand, target: { readonly version: 7 }): SessionInboxWireV7;
function encode(
command: SessionInboxCommand,
target: { readonly version: SessionInboxWireVersion },
@@ -82,6 +88,7 @@ function encode(
| SessionInboxWireV4
| SessionInboxWireV5
| SessionInboxWireV6
+ | SessionInboxWireV7
| Record<string, unknown>;
function encode(
command: SessionInboxCommand,
@@ -93,21 +100,23 @@ function encode(
| SessionInboxWireV4
| SessionInboxWireV5
| SessionInboxWireV6
+ | SessionInboxWireV7
| Record<string, unknown> {
if (command.kind === "cancel" && command.tasks === true && target.version < 6) {
throw new SessionInboxWireError(
`Cannot encode session-owned task cancellation for wire version ${target.version}.`,
);
}
+ const encodable = target.version < 7 ? withoutActivityLabels(command) : command;
if (target.version === 0) {
const currentTaskWire =
- target.variant === "send" && command.kind === "send" && command.payload.task !== undefined
- ? encodeSessionCommandV5(command)
+ target.variant === "send" && encodable.kind === "send" && encodable.payload.task !== undefined
+ ? encodeSessionCommandV5(encodable)
: undefined;
let legacy = encodeSessionCommandV0(
encodeSessionCommandV1(
withoutCurrentTaskMessages(
- withoutAcceptedDeployment(withoutOwnedTaskCancellation(command)),
+ withoutAcceptedDeployment(withoutOwnedTaskCancellation(encodable)),
),
),
target.variant,
@@ -133,19 +142,37 @@ function encode(
};
}
if (isSessionInboxWireVersion(target.version)) {
- return versionedEncoders[target.version](command) as
+ return versionedEncoders[target.version](encodable) as
| SessionInboxWireV1
| SessionInboxWireV2
| SessionInboxWireV3
| SessionInboxWireV4
| SessionInboxWireV5
- | SessionInboxWireV6;
+ | SessionInboxWireV6
+ | SessionInboxWireV7;
}
throw new SessionInboxWireError(
`Cannot encode session inbox payload for unknown wire version ${JSON.stringify((target as { version?: unknown }).version)}.`,
);
}
+function withoutActivityLabels(command: SessionInboxCommand): SessionInboxCommand {
+ if (
+ (command.kind !== "send" && command.kind !== "deliver") ||
+ command.caller?.activityObserver?.workIdentity?.label === undefined
+ ) {
+ return command;
+ }
+ const { label: _label, ...workIdentity } = command.caller.activityObserver.workIdentity;
+ return {
+ ...command,
+ caller: {
+ ...command.caller,
+ activityObserver: { ...command.caller.activityObserver, workIdentity },
+ },
+ };
+}
+
function withoutOwnedTaskCancellation(command: SessionInboxCommand): SessionInboxCommand {
if (command.kind !== "cancel" || command.tasks === undefined) return command;
const { tasks: _tasks, ...legacy } = command;
diff --git a/packages/eve/src/execution/wire/session-inbox-wire.ts b/packages/eve/src/execution/wire/session-inbox-wire.ts
index 902a3d80e..e9f8a70c8 100644
--- a/packages/eve/src/execution/wire/session-inbox-wire.ts
+++ b/packages/eve/src/execution/wire/session-inbox-wire.ts
@@ -53,6 +53,15 @@ const sessionInboxWireV5Migration: VersionMigration = {
to: 6,
};
+const sessionInboxWireV6Migration: VersionMigration = {
+ from: 6,
+ migrate(prior) {
+ if (!isObject(prior)) throw new Error("session inbox wire v6 value is not an object.");
+ return { ...prior, version: 7 };
+ },
+ to: 7,
+};
+
const sessionInboxMigrations: readonly VersionMigration[] = [
sessionInboxWireV0Migration,
sessionInboxWireV1Migration,
@@ -60,6 +69,7 @@ const sessionInboxMigrations: readonly VersionMigration[] = [
sessionInboxWireV3Migration,
sessionInboxWireV4Migration,
sessionInboxWireV5Migration,
+ sessionInboxWireV6Migration,
];
/**
diff --git a/packages/eve/src/execution/wire/session-inbox-wire.v7.test.ts b/packages/eve/src/execution/wire/session-inbox-wire.v7.test.ts
new file mode 100644
index 000000000..47868e086
--- /dev/null
+++ b/packages/eve/src/execution/wire/session-inbox-wire.v7.test.ts
@@ -0,0 +1,64 @@
+import { describe, expect, it } from "vitest";
+
+import { sessionInboxWire } from "#execution/wire/session-inbox-encoder.js";
+import { sessionInboxWire as sessionInboxWireDecoder } from "#execution/wire/session-inbox-wire.js";
+import { sessionInboxWireV7Schema } from "#execution/wire/session-inbox-wire.v7.js";
+
+const caller = {
+ activityObserver: {
+ sink: { url: "https://example.com/eve/v1/activity/opaque-token", version: 1 as const },
+ workIdentity: {
+ callId: "call-1",
+ id: "work:call-1",
+ kind: "task" as const,
+ label: "Investigator",
+ name: "researcher",
+ rootSessionId: "root",
+ rootTurnId: "turn",
+ },
+ },
+ callId: "call-1",
+ replyTo: {
+ kind: "callback" as const,
+ token: "callback-token",
+ url: "https://example.com/callback",
+ },
+ subagentName: "researcher",
+};
+
+describe("session inbox wire v7", () => {
+ it("round-trips delegated activity labels", () => {
+ const wire = sessionInboxWire.encode(
+ { caller, kind: "send", payload: { message: "observe" } },
+ { version: 7 },
+ );
+
+ expect(wire).toMatchObject({ caller, version: 7 });
+ expect(sessionInboxWireDecoder.decode(JSON.parse(JSON.stringify(wire)))).toMatchObject({
+ caller,
+ kind: "deliver",
+ payloads: [{ message: "observe" }],
+ });
+ });
+
+ it.each([1, 2, 3, 4, 5, 6] as const)("omits activity labels for v%i consumers", (version) => {
+ const wire = sessionInboxWire.encode(
+ { caller, kind: "send", payload: { message: "observe" } },
+ { version },
+ );
+
+ expect(wire).not.toHaveProperty("caller.activityObserver.workIdentity.label");
+ });
+
+ it("keeps the v7 deliver schema strict", () => {
+ expect(
+ sessionInboxWireV7Schema.safeParse({
+ caller: { ...caller, activityObserver: { ...caller.activityObserver, extra: true } },
+ kind: "deliver",
+ payload: {},
+ payloads: [{}],
+ version: 7,
+ }).success,
+ ).toBe(false);
+ });
+});
diff --git a/packages/eve/src/execution/wire/session-inbox-wire.v7.ts b/packages/eve/src/execution/wire/session-inbox-wire.v7.ts
new file mode 100644
index 000000000..51b84ef39
--- /dev/null
+++ b/packages/eve/src/execution/wire/session-inbox-wire.v7.ts
@@ -0,0 +1,99 @@
+import { z } from "#compiled/zod/index.js";
+
+import type {
+ DeliverHookPayload,
+ SessionCommand,
+ SessionTimeoutHookPayload,
+} from "#channel/types.js";
+import { SessionInboxWireError } from "#execution/wire/session-inbox-contract.js";
+import {
+ encodeSessionCommandV6,
+ sessionInboxWireV6Schema,
+} from "#execution/wire/session-inbox-wire.v6.js";
+import { formatValidationError } from "#runtime/validation.js";
+
+const v6 = sessionInboxWireV6Schema.options;
+const v6Deliver = v6[0];
+const v6Caller = v6Deliver.shape.caller.unwrap();
+const v6ActivityObserver = v6Caller.shape.activityObserver.unwrap();
+const v6WorkIdentity = v6ActivityObserver.shape.workIdentity.unwrap();
+const VERSION = 7;
+const version = z.literal(VERSION);
+
+/** Version 7 adds optional presentation labels to delegated activity work. */
+export const sessionInboxWireV7Schema = z.discriminatedUnion("kind", [
+ v6Deliver.extend({
+ caller: v6Caller
+ .extend({
+ activityObserver: v6ActivityObserver
+ .extend({
+ workIdentity: v6WorkIdentity.extend({ label: z.string().optional() }).optional(),
+ })
+ .optional(),
+ })
+ .optional(),
+ version,
+ }),
+ v6[1].extend({ version }),
+ v6[2].extend({ version }),
+ v6[3].extend({ version }),
+ v6[4].extend({ version }),
+ v6[5].extend({ version }),
+]);
+
+export type SessionInboxWireV7 = z.infer<typeof sessionInboxWireV7Schema>;
+
+/** Builds and validates one complete version-7 wire value. */
+export function encodeSessionCommandV7(
+ command: DeliverHookPayload | SessionCommand | SessionTimeoutHookPayload,
+): SessionInboxWireV7 {
+ const label = readActivityLabel(command);
+ const encoded = encodeSessionCommandV6(withoutActivityLabel(command));
+ const value =
+ label === undefined || encoded.kind !== "deliver" || encoded.caller === undefined
+ ? { ...encoded, version: VERSION }
+ : {
+ ...encoded,
+ caller: {
+ ...encoded.caller,
+ activityObserver: {
+ ...encoded.caller.activityObserver!,
+ workIdentity: { ...encoded.caller.activityObserver!.workIdentity!, label },
+ },
+ },
+ version: VERSION,
+ };
+ const parsed = sessionInboxWireV7Schema.safeParse(value);
+ if (!parsed.success) {
+ throw new SessionInboxWireError(
+ `Produced a session inbox payload that does not match wire version ${VERSION}: ${formatValidationError(parsed.error)}`,
+ );
+ }
+ return parsed.data;
+}
+
+function readActivityLabel(
+ command: DeliverHookPayload | SessionCommand | SessionTimeoutHookPayload,
+): string | undefined {
+ return command.kind === "send" || command.kind === "deliver"
+ ? command.caller?.activityObserver?.workIdentity?.label
+ : undefined;
+}
+
+function withoutActivityLabel(
+ command: DeliverHookPayload | SessionCommand | SessionTimeoutHookPayload,
+): DeliverHookPayload | SessionCommand | SessionTimeoutHookPayload {
+ if (
+ (command.kind !== "send" && command.kind !== "deliver") ||
+ command.caller?.activityObserver?.workIdentity?.label === undefined
+ )
+ return command;
+ const { label: _label, ...workIdentity } = command.caller.activityObserver.workIdentity;
+ return {
+ ...command,
+ caller: {
+ ...command.caller,
+ activityObserver: { ...command.caller.activityObserver, workIdentity },
+ },
+ };
+}
diff --git a/packages/eve/src/harness/action-presentation.ts b/packages/eve/src/harness/action-presentation.ts
index 7d5d9aae5..937587f17 100644
--- a/packages/eve/src/harness/action-presentation.ts
+++ b/packages/eve/src/harness/action-presentation.ts
@@ -2,6 +2,7 @@ import type { ToolSet, TypedToolCall } from "ai";
import type { ActionPresentationByCallId } from "#protocol/message.js";
import { createRuntimeActionRequestFromToolCall } from "#harness/coordination.js";
+import type { HarnessToolDefinition } from "#harness/execute-tool.js";
import type { HarnessToolMap } from "#harness/types.js";
import type { RuntimeActionRequest } from "#shared/action-types.js";
import { normalizePresentationText } from "#shared/presentation-text.js";
@@ -17,13 +18,25 @@ export function createPresentedRuntimeActionRequestFromToolCall(input: {
readonly tools: HarnessToolMap;
}): RuntimeActionRequestProjection {
const action = createRuntimeActionRequestFromToolCall(input);
- const start = input.tools.get(input.toolCall.toolName)?.label?.start;
- if (start === undefined) return { action };
+ const presentationLabel = projectToolStartLabel(
+ input.tools.get(input.toolCall.toolName),
+ action.input,
+ );
+ return presentationLabel === undefined ? { action } : { action, presentationLabel };
+}
+
+/** Calls a tool's label callback with a detached, JSON-safe input copy. */
+export function projectToolStartLabel(
+ definition: { readonly label?: HarnessToolDefinition["label"] } | undefined,
+ input: unknown,
+): string | undefined {
+ const start = definition?.label?.start;
+ if (start === undefined) return undefined;
try {
- const label = normalizePresentationText(start(parseJsonObject(action.input)));
- return label === "" ? { action } : { action, presentationLabel: label };
+ const label = normalizePresentationText(start(parseJsonObject(input)));
+ return label === "" ? undefined : label;
} catch {
- return { action };
+ return undefined;
}
}
diff --git a/packages/eve/src/harness/background-tools.ts b/packages/eve/src/harness/background-tools.ts
index 8299803b5..35e69c710 100644
--- a/packages/eve/src/harness/background-tools.ts
+++ b/packages/eve/src/harness/background-tools.ts
@@ -1,11 +1,12 @@
import { loadContext } from "#context/container.js";
import { ContextKey } from "#context/key.js";
-import type { ToolExecuteOptions } from "#tools/definition.js";
+import type { InternalToolLabelDefinition, ToolExecuteOptions } from "#tools/definition.js";
import type { TaskExec } from "#tools/task.js";
import type { AgentView } from "#subagents/handles/prompt.js";
import type { JsonValue } from "#shared/json.js";
export interface BackgroundExecutableTool {
+ readonly label?: InternalToolLabelDefinition;
readonly execute: (input: unknown, options: ToolExecuteOptions, task: TaskExec) => unknown;
readonly executeInput?: (input: unknown) => JsonValue;
readonly name: string;
diff --git a/packages/eve/src/protocol/activity.ts b/packages/eve/src/protocol/activity.ts
index 5ae105dc4..eddcc3d2b 100644
--- a/packages/eve/src/protocol/activity.ts
+++ b/packages/eve/src/protocol/activity.ts
@@ -11,6 +11,7 @@ export interface ActivityWorkIdentityV1 {
readonly callId?: string;
readonly id: string;
readonly kind: ActivityWorkKind;
+ readonly label?: string;
readonly name?: string;
readonly parentId?: string;
readonly rootSessionId: string;
@@ -132,6 +133,7 @@ export function parseActivityWorkIdentityV1(value: unknown): ActivityWorkIdentit
"callId",
"id",
"kind",
+ "label",
"name",
"parentId",
"rootSessionId",
@@ -148,6 +150,7 @@ export function parseActivityWorkIdentityV1(value: unknown): ActivityWorkIdentit
!isIdentity(value.rootSessionId) ||
!isIdentity(value.rootTurnId) ||
!isOptionalIdentity(value.callId) ||
+ !isOptionalBoundedString(value.label) ||
!isOptionalBoundedString(value.name) ||
!isOptionalIdentity(value.parentId) ||
!isOptionalIdentity(value.sessionId) ||
@@ -158,6 +161,7 @@ export function parseActivityWorkIdentityV1(value: unknown): ActivityWorkIdentit
callId: value.callId,
id: value.id,
kind,
+ label: value.label,
name: value.name,
parentId: value.parentId,
rootSessionId: value.rootSessionId,
diff --git a/packages/eve/src/public/channels/slack/activity-plan.ts b/packages/eve/src/public/channels/slack/activity-plan.ts
index 081c9487c..8ea4e800f 100644
--- a/packages/eve/src/public/channels/slack/activity-plan.ts
+++ b/packages/eve/src/public/channels/slack/activity-plan.ts
@@ -204,7 +204,7 @@ function taskChunk(work: ActivityWorkStateV1) {
return {
type: "task_update",
id: safeId(work.id),
- title: work.kind === "root-turn" ? "Agent turn" : (work.name ?? "Agent work"),
+ title: work.kind === "root-turn" ? "Agent turn" : (work.label ?? work.name ?? "Agent work"),
status: status(work.phase),
};
}
diff --git a/packages/eve/src/tasks/session-index.test.ts b/packages/eve/src/tasks/session-index.test.ts
index d59e0c21d..5f55fd9fa 100644
--- a/packages/eve/src/tasks/session-index.test.ts
+++ b/packages/eve/src/tasks/session-index.test.ts
@@ -100,6 +100,52 @@ describe("session task index", () => {
expect(findSessionTaskEntry(session.state, "task_a")?.metadata).toEqual(subagentMetadata);
});
+ it("keeps a terminal view when replayed activity presentation changes", () => {
+ let session = recordSessionTask(createSession(), {
+ activityWorkIdentity: {
+ callId: "call-1",
+ id: "work:task",
+ kind: "task",
+ label: "First label",
+ name: "research",
+ parentId: "work:root",
+ rootSessionId: "root-session",
+ rootTurnId: "root-turn",
+ },
+ taskInboxToken: "task:token-1",
+ createdByTurnId: "turn-1",
+ metadata,
+ taskId: "task_a",
+ taskRunId: "run-1",
+ });
+ session = {
+ ...session,
+ state: cacheTerminalTaskView(session.state, terminal("task_a", "completed")),
+ };
+ session = recordSessionTask(session, {
+ activityWorkIdentity: {
+ callId: "call-1",
+ id: "work:task",
+ kind: "task",
+ label: "Second label",
+ name: "research",
+ parentId: "work:root",
+ rootSessionId: "root-session",
+ rootTurnId: "root-turn",
+ },
+ taskInboxToken: "task:token-2",
+ createdByTurnId: "turn-1",
+ metadata,
+ taskId: "task_a",
+ taskRunId: "run-2",
+ });
+
+ expect(findSessionTaskEntry(session.state, "task_a")).toMatchObject({
+ activityWorkIdentity: { label: "Second label" },
+ terminalView: terminal("task_a", "completed"),
+ });
+ });
+
it("replaces the entry on replayed creation instead of duplicating it", () => {
let session = recordSessionTask(createSession(), {
taskInboxToken: "task:token-1",