Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58f45db792 | ||
|
|
4bf483d491 | ||
|
|
ef47eaa048 | ||
|
|
e95b0dedb0 | ||
|
|
48c7562001 | ||
|
|
4e1ec8c175 | ||
|
|
b6a5321043 | ||
|
|
ca41079cd9 | ||
|
|
d6eeeedc60 | ||
|
|
8b9ee6f74a |
No files matched your search
@@ -32,6 +32,7 @@ import { OrchestrationCommandReceiptRepositoryLive } from "../src/persistence/La
|
||||
import { OrchestrationEventStoreLive } from "../src/persistence/Layers/OrchestrationEventStore.ts";
|
||||
import { ProjectionCheckpointRepositoryLive } from "../src/persistence/Layers/ProjectionCheckpoints.ts";
|
||||
import { ProjectionPendingApprovalRepositoryLive } from "../src/persistence/Layers/ProjectionPendingApprovals.ts";
|
||||
import { ProjectionTurnRepositoryLive } from "../src/persistence/Layers/ProjectionTurns.ts";
|
||||
import { ProviderSessionRuntimeRepositoryLive } from "../src/persistence/Layers/ProviderSessionRuntime.ts";
|
||||
import { makeSqlitePersistenceLive } from "../src/persistence/Layers/Sqlite.ts";
|
||||
import { ProjectionCheckpointRepository } from "../src/persistence/Services/ProjectionCheckpoints.ts";
|
||||
@@ -297,6 +298,7 @@ export const makeOrchestrationIntegrationHarness = (
|
||||
orchestrationLayer.pipe(Layer.provide(projectionSnapshotQueryLayer)),
|
||||
ProjectionCheckpointRepositoryLive,
|
||||
ProjectionPendingApprovalRepositoryLive,
|
||||
ProjectionTurnRepositoryLive,
|
||||
checkpointStoreLayer,
|
||||
providerLayer,
|
||||
RuntimeReceiptBusTest,
|
||||
|
||||
@@ -145,9 +145,9 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
'thread-1',
|
||||
'turn-1',
|
||||
'info',
|
||||
'runtime.note',
|
||||
'provider started',
|
||||
'{"stage":"start"}',
|
||||
'runtime.warning',
|
||||
'Runtime warning',
|
||||
'{"message":"provider started"}',
|
||||
'2026-02-24T00:00:06.000Z'
|
||||
)
|
||||
`;
|
||||
@@ -312,9 +312,9 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
{
|
||||
id: asEventId("activity-1"),
|
||||
tone: "info",
|
||||
kind: "runtime.note",
|
||||
summary: "provider started",
|
||||
payload: { stage: "start" },
|
||||
kind: "runtime.warning",
|
||||
summary: "Runtime warning",
|
||||
payload: { message: "provider started" },
|
||||
turnId: asTurnId("turn-1"),
|
||||
createdAt: "2026-02-24T00:00:06.000Z",
|
||||
},
|
||||
|
||||
@@ -590,7 +590,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
turnId: row.turnId,
|
||||
...(row.sequence !== null ? { sequence: row.sequence } : {}),
|
||||
createdAt: row.createdAt,
|
||||
});
|
||||
} as OrchestrationThreadActivity);
|
||||
activitiesByThread.set(row.threadId, threadActivities);
|
||||
}
|
||||
|
||||
|
||||
@@ -173,8 +173,7 @@ const make = Effect.gen(function* () {
|
||||
| "provider.turn.start.failed"
|
||||
| "provider.turn.interrupt.failed"
|
||||
| "provider.approval.respond.failed"
|
||||
| "provider.user-input.respond.failed"
|
||||
| "provider.session.stop.failed";
|
||||
| "provider.user-input.respond.failed";
|
||||
readonly summary: string;
|
||||
readonly detail: string;
|
||||
readonly turnId: TurnId | null;
|
||||
|
||||
@@ -24,6 +24,7 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { OrchestrationEventStoreLive } from "../../persistence/Layers/OrchestrationEventStore.ts";
|
||||
import { OrchestrationCommandReceiptRepositoryLive } from "../../persistence/Layers/OrchestrationCommandReceipts.ts";
|
||||
import { ProjectionTurnRepositoryLive } from "../../persistence/Layers/ProjectionTurns.ts";
|
||||
import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
|
||||
import {
|
||||
ProviderService,
|
||||
@@ -209,6 +210,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
Layer.provide(SqlitePersistenceMemory),
|
||||
);
|
||||
const layer = ProviderRuntimeIngestionLive.pipe(
|
||||
Layer.provideMerge(ProjectionTurnRepositoryLive),
|
||||
Layer.provideMerge(orchestrationLayer),
|
||||
Layer.provideMerge(SqlitePersistenceMemory),
|
||||
Layer.provideMerge(Layer.succeed(ProviderService, provider.service)),
|
||||
@@ -1896,7 +1898,9 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
status: "in_progress",
|
||||
title: "Run tests",
|
||||
detail: "bun test",
|
||||
data: { pid: 123 },
|
||||
data: {
|
||||
kind: "generic",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
type AssistantDeliveryMode,
|
||||
type CanonicalJsonValue,
|
||||
CommandId,
|
||||
MessageId,
|
||||
type OrchestrationEvent,
|
||||
@@ -18,7 +19,6 @@ import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
|
||||
|
||||
import { ProviderService } from "../../provider/Services/ProviderService.ts";
|
||||
import { ProjectionTurnRepository } from "../../persistence/Services/ProjectionTurns.ts";
|
||||
import { ProjectionTurnRepositoryLive } from "../../persistence/Layers/ProjectionTurns.ts";
|
||||
import { resolveThreadWorkspaceCwd } from "../../checkpointing/Utils.ts";
|
||||
import { isGitRepository } from "../../git/Utils.ts";
|
||||
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
|
||||
@@ -98,6 +98,16 @@ function proposedPlanIdFromEvent(event: ProviderRuntimeEvent, threadId: ThreadId
|
||||
return `plan:${threadId}:event:${event.eventId}`;
|
||||
}
|
||||
|
||||
function toCanonicalJsonValue(value: unknown): CanonicalJsonValue | undefined {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
const normalized = JSON.parse(
|
||||
JSON.stringify(value, (_key, nestedValue) => (nestedValue === undefined ? null : nestedValue)),
|
||||
) as CanonicalJsonValue | null;
|
||||
return normalized ?? undefined;
|
||||
}
|
||||
|
||||
function buildContextWindowActivityPayload(
|
||||
event: ProviderRuntimeEvent,
|
||||
): ThreadTokenUsageSnapshot | undefined {
|
||||
@@ -250,7 +260,9 @@ function runtimeEventToActivities(
|
||||
summary: "Runtime warning",
|
||||
payload: {
|
||||
message: truncateDetail(event.payload.message),
|
||||
...(event.payload.detail !== undefined ? { detail: event.payload.detail } : {}),
|
||||
...(event.payload.detail !== undefined
|
||||
? { detail: toCanonicalJsonValue(event.payload.detail) }
|
||||
: {}),
|
||||
},
|
||||
turnId: toTurnId(event.turnId) ?? null,
|
||||
...maybeSequence,
|
||||
@@ -400,7 +412,9 @@ function runtimeEventToActivities(
|
||||
summary: "Context compacted",
|
||||
payload: {
|
||||
state: event.payload.state,
|
||||
...(event.payload.detail !== undefined ? { detail: event.payload.detail } : {}),
|
||||
...(event.payload.detail !== undefined
|
||||
? { detail: toCanonicalJsonValue(event.payload.detail) }
|
||||
: {}),
|
||||
},
|
||||
turnId: toTurnId(event.turnId) ?? null,
|
||||
...maybeSequence,
|
||||
@@ -1264,7 +1278,4 @@ const make = Effect.fn("make")(function* () {
|
||||
} satisfies ProviderRuntimeIngestionShape;
|
||||
});
|
||||
|
||||
export const ProviderRuntimeIngestionLive = Layer.effect(
|
||||
ProviderRuntimeIngestionService,
|
||||
make(),
|
||||
).pipe(Layer.provide(ProjectionTurnRepositoryLive));
|
||||
export const ProviderRuntimeIngestionLive = Layer.effect(ProviderRuntimeIngestionService, make());
|
||||
@@ -545,7 +545,7 @@ describe("orchestration projector", () => {
|
||||
tone: "tool",
|
||||
kind: "tool.started",
|
||||
summary: "Edit file started",
|
||||
payload: { toolKind: "command" },
|
||||
payload: { itemType: "command_execution" },
|
||||
turnId: "turn-1",
|
||||
createdAt: "2026-02-23T10:00:02.750Z",
|
||||
},
|
||||
@@ -619,7 +619,7 @@ describe("orchestration projector", () => {
|
||||
tone: "tool",
|
||||
kind: "tool.completed",
|
||||
summary: "Edit file complete",
|
||||
payload: { toolKind: "command" },
|
||||
payload: { itemType: "command_execution" },
|
||||
turnId: "turn-2",
|
||||
createdAt: "2026-02-23T10:00:04.750Z",
|
||||
},
|
||||
|
||||
@@ -615,7 +615,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* ClaudeAdapter;
|
||||
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 10).pipe(
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 9).pipe(
|
||||
Stream.runCollect,
|
||||
Effect.forkChild,
|
||||
);
|
||||
@@ -732,7 +732,6 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeEvents.map((event) => event.type),
|
||||
[
|
||||
"session.started",
|
||||
"session.configured",
|
||||
"session.state.changed",
|
||||
"turn.started",
|
||||
"thread.started",
|
||||
@@ -744,7 +743,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
],
|
||||
);
|
||||
|
||||
const turnStarted = runtimeEvents[3];
|
||||
const turnStarted = runtimeEvents[2];
|
||||
assert.equal(turnStarted?.type, "turn.started");
|
||||
if (turnStarted?.type === "turn.started") {
|
||||
assert.equal(String(turnStarted.turnId), String(turn.turnId));
|
||||
@@ -792,7 +791,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* ClaudeAdapter;
|
||||
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 11).pipe(
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 10).pipe(
|
||||
Stream.runCollect,
|
||||
Effect.forkChild,
|
||||
);
|
||||
@@ -898,7 +897,6 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeEvents.map((event) => event.type),
|
||||
[
|
||||
"session.started",
|
||||
"session.configured",
|
||||
"session.state.changed",
|
||||
"turn.started",
|
||||
"thread.started",
|
||||
@@ -929,12 +927,13 @@ describe("ClaudeAdapterLive", () => {
|
||||
const toolInputUpdated = runtimeEvents.find(
|
||||
(event) =>
|
||||
event.type === "item.updated" &&
|
||||
(event.payload.data as { input?: { pattern?: string; path?: string } } | undefined)?.input
|
||||
?.pattern === "foo",
|
||||
event.payload.data?.kind === "generic" &&
|
||||
event.payload.data.input?.pattern === "foo",
|
||||
);
|
||||
assert.equal(toolInputUpdated?.type, "item.updated");
|
||||
if (toolInputUpdated?.type === "item.updated") {
|
||||
assert.deepEqual(toolInputUpdated.payload.data, {
|
||||
kind: "generic",
|
||||
toolName: "Grep",
|
||||
input: {
|
||||
pattern: "foo",
|
||||
@@ -946,17 +945,25 @@ describe("ClaudeAdapterLive", () => {
|
||||
const toolResultUpdated = runtimeEvents.find(
|
||||
(event) =>
|
||||
event.type === "item.updated" &&
|
||||
(event.payload.data as { result?: { tool_use_id?: string } } | undefined)?.result
|
||||
?.tool_use_id === "tool-grep-1",
|
||||
event.payload.data?.kind === "generic" &&
|
||||
event.payload.data.result !== undefined &&
|
||||
event.payload.data.result !== null &&
|
||||
typeof event.payload.data.result === "object" &&
|
||||
!Array.isArray(event.payload.data.result) &&
|
||||
"tool_use_id" in event.payload.data.result &&
|
||||
event.payload.data.result.tool_use_id === "tool-grep-1",
|
||||
);
|
||||
assert.equal(toolResultUpdated?.type, "item.updated");
|
||||
if (toolResultUpdated?.type === "item.updated") {
|
||||
assert.equal(
|
||||
(
|
||||
toolResultUpdated.payload.data as {
|
||||
result?: { content?: string };
|
||||
}
|
||||
).result?.content,
|
||||
toolResultUpdated.payload.data?.kind === "generic" &&
|
||||
toolResultUpdated.payload.data.result !== undefined &&
|
||||
toolResultUpdated.payload.data.result !== null &&
|
||||
typeof toolResultUpdated.payload.data.result === "object" &&
|
||||
!Array.isArray(toolResultUpdated.payload.data.result) &&
|
||||
"content" in toolResultUpdated.payload.data.result
|
||||
? toolResultUpdated.payload.data.result.content
|
||||
: undefined,
|
||||
"src/example.ts:1:foo",
|
||||
);
|
||||
}
|
||||
@@ -971,7 +978,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* ClaudeAdapter;
|
||||
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 8).pipe(
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 7).pipe(
|
||||
Stream.runCollect,
|
||||
Effect.forkChild,
|
||||
);
|
||||
@@ -1047,7 +1054,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* ClaudeAdapter;
|
||||
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 6).pipe(
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 5).pipe(
|
||||
Stream.runCollect,
|
||||
Effect.forkChild,
|
||||
);
|
||||
@@ -1079,7 +1086,6 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeEvents.map((event) => event.type),
|
||||
[
|
||||
"session.started",
|
||||
"session.configured",
|
||||
"session.state.changed",
|
||||
"turn.started",
|
||||
"thread.started",
|
||||
@@ -1140,7 +1146,6 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeEvents.map((event) => event.type),
|
||||
[
|
||||
"session.started",
|
||||
"session.configured",
|
||||
"session.state.changed",
|
||||
"turn.started",
|
||||
"turn.completed",
|
||||
@@ -1148,7 +1153,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
],
|
||||
);
|
||||
|
||||
const turnCompleted = runtimeEvents[4];
|
||||
const turnCompleted = runtimeEvents.find((event) => event.type === "turn.completed");
|
||||
assert.equal(turnCompleted?.type, "turn.completed");
|
||||
if (turnCompleted?.type === "turn.completed") {
|
||||
assert.equal(String(turnCompleted.turnId), String(turn.turnId));
|
||||
@@ -1156,7 +1161,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
assert.equal(turnCompleted.payload.errorMessage, "Claude runtime interrupted.");
|
||||
}
|
||||
|
||||
const sessionExited = runtimeEvents[5];
|
||||
const sessionExited = runtimeEvents.find((event) => event.type === "session.exited");
|
||||
assert.equal(sessionExited?.type, "session.exited");
|
||||
|
||||
assert.equal(yield* adapter.hasSession(THREAD_ID), false);
|
||||
@@ -1245,7 +1250,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* ClaudeAdapter;
|
||||
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 6).pipe(
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 5).pipe(
|
||||
Stream.runCollect,
|
||||
Effect.forkChild,
|
||||
);
|
||||
@@ -1292,7 +1297,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* ClaudeAdapter;
|
||||
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 6).pipe(
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 5).pipe(
|
||||
Stream.runCollect,
|
||||
Effect.forkChild,
|
||||
);
|
||||
@@ -1346,7 +1351,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* ClaudeAdapter;
|
||||
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 7).pipe(
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 6).pipe(
|
||||
Stream.runCollect,
|
||||
Effect.forkChild,
|
||||
);
|
||||
@@ -1415,7 +1420,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* ClaudeAdapter;
|
||||
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 8).pipe(
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 7).pipe(
|
||||
Stream.runCollect,
|
||||
Effect.forkChild,
|
||||
);
|
||||
@@ -1474,7 +1479,6 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeEvents.map((event) => event.type),
|
||||
[
|
||||
"session.started",
|
||||
"session.configured",
|
||||
"session.state.changed",
|
||||
"turn.started",
|
||||
"thread.started",
|
||||
@@ -1619,7 +1623,6 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeEvents.map((event) => event.type),
|
||||
[
|
||||
"session.started",
|
||||
"session.configured",
|
||||
"session.state.changed",
|
||||
"turn.started",
|
||||
"thread.started",
|
||||
@@ -1627,6 +1630,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
"item.completed",
|
||||
"content.delta",
|
||||
"item.completed",
|
||||
"turn.completed",
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1672,7 +1676,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* ClaudeAdapter;
|
||||
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 8).pipe(
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 7).pipe(
|
||||
Stream.runCollect,
|
||||
Effect.forkChild,
|
||||
);
|
||||
@@ -1714,7 +1718,6 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeEvents.map((event) => event.type),
|
||||
[
|
||||
"session.started",
|
||||
"session.configured",
|
||||
"session.state.changed",
|
||||
"turn.started",
|
||||
"thread.started",
|
||||
@@ -1741,7 +1744,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* ClaudeAdapter;
|
||||
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 13).pipe(
|
||||
const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 12).pipe(
|
||||
Stream.runCollect,
|
||||
Effect.forkChild,
|
||||
);
|
||||
@@ -1902,7 +1905,6 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeEvents.map((event) => event.type),
|
||||
[
|
||||
"session.started",
|
||||
"session.configured",
|
||||
"session.state.changed",
|
||||
"turn.started",
|
||||
"thread.started",
|
||||
@@ -2009,10 +2011,10 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeEvents.map((event) => event.type),
|
||||
[
|
||||
"session.started",
|
||||
"session.configured",
|
||||
"session.state.changed",
|
||||
"turn.started",
|
||||
"thread.started",
|
||||
"turn.completed",
|
||||
],
|
||||
);
|
||||
|
||||
@@ -2022,7 +2024,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
assert.equal(sessionStarted.threadId, THREAD_ID);
|
||||
}
|
||||
|
||||
const threadStarted = runtimeEvents[4];
|
||||
const threadStarted = runtimeEvents.find((event) => event.type === "thread.started");
|
||||
assert.equal(threadStarted?.type, "thread.started");
|
||||
if (threadStarted?.type === "thread.started") {
|
||||
assert.equal(threadStarted.threadId, THREAD_ID);
|
||||
@@ -2047,7 +2049,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
|
||||
yield* Stream.take(adapter.streamEvents, 3).pipe(Stream.runDrain);
|
||||
yield* Stream.take(adapter.streamEvents, 2).pipe(Stream.runDrain);
|
||||
|
||||
yield* adapter.sendTurn({
|
||||
threadId: session.threadId,
|
||||
@@ -2156,7 +2158,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
|
||||
yield* Stream.take(adapter.streamEvents, 3).pipe(Stream.runDrain);
|
||||
yield* Stream.take(adapter.streamEvents, 2).pipe(Stream.runDrain);
|
||||
|
||||
const createInput = harness.getLastCreateQueryInput();
|
||||
const canUseTool = createInput?.options.canUseTool;
|
||||
@@ -2589,7 +2591,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
yield* Stream.take(adapter.streamEvents, 3).pipe(Stream.runDrain);
|
||||
yield* Stream.take(adapter.streamEvents, 2).pipe(Stream.runDrain);
|
||||
|
||||
yield* adapter.sendTurn({
|
||||
threadId: session.threadId,
|
||||
@@ -2655,7 +2657,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
yield* Stream.take(adapter.streamEvents, 3).pipe(Stream.runDrain);
|
||||
yield* Stream.take(adapter.streamEvents, 2).pipe(Stream.runDrain);
|
||||
|
||||
yield* adapter.sendTurn({
|
||||
threadId: session.threadId,
|
||||
@@ -2727,8 +2729,8 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
|
||||
// Drain the session startup events (started, configured, state.changed).
|
||||
yield* Stream.take(adapter.streamEvents, 3).pipe(Stream.runDrain);
|
||||
// Drain the session startup events (started, state.changed).
|
||||
yield* Stream.take(adapter.streamEvents, 2).pipe(Stream.runDrain);
|
||||
|
||||
yield* adapter.sendTurn({
|
||||
threadId: session.threadId,
|
||||
@@ -2850,7 +2852,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
yield* Stream.take(adapter.streamEvents, 3).pipe(Stream.runDrain);
|
||||
yield* Stream.take(adapter.streamEvents, 2).pipe(Stream.runDrain);
|
||||
|
||||
const createInput = harness.getLastCreateQueryInput();
|
||||
const canUseTool = createInput?.options.canUseTool;
|
||||
@@ -2916,7 +2918,7 @@ describe("ClaudeAdapterLive", () => {
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
|
||||
yield* Stream.take(adapter.streamEvents, 3).pipe(Stream.runDrain);
|
||||
yield* Stream.take(adapter.streamEvents, 2).pipe(Stream.runDrain);
|
||||
|
||||
const createInput = harness.getLastCreateQueryInput();
|
||||
const canUseTool = createInput?.options.canUseTool;
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
type CanonicalItemType,
|
||||
type CanonicalToolLifecycleData,
|
||||
type CanonicalRequestType,
|
||||
EventId,
|
||||
type ProviderApprovalDecision,
|
||||
@@ -742,6 +743,116 @@ function tryParseJsonRecord(value: string): Record<string, unknown> | undefined
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeCommandValue(value: unknown): string | undefined {
|
||||
if (typeof value === "string") {
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length > 0 ? trimmed : undefined;
|
||||
}
|
||||
if (!Array.isArray(value)) {
|
||||
return undefined;
|
||||
}
|
||||
const parts = value
|
||||
.map((entry) => (typeof entry === "string" ? entry.trim() : ""))
|
||||
.filter((entry) => entry.length > 0);
|
||||
return parts.length > 0 ? parts.join(" ") : undefined;
|
||||
}
|
||||
|
||||
function pushChangedFile(target: string[], seen: Set<string>, value: unknown) {
|
||||
if (typeof value !== "string") {
|
||||
return;
|
||||
}
|
||||
const normalized = value.trim();
|
||||
if (normalized.length === 0 || seen.has(normalized)) {
|
||||
return;
|
||||
}
|
||||
seen.add(normalized);
|
||||
target.push(normalized);
|
||||
}
|
||||
|
||||
function collectChangedFiles(value: unknown, target: string[], seen: Set<string>, depth: number) {
|
||||
if (depth > 4 || target.length >= 12) {
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
for (const entry of value) {
|
||||
collectChangedFiles(entry, target, seen, depth + 1);
|
||||
if (target.length >= 12) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!value || typeof value !== "object") {
|
||||
return;
|
||||
}
|
||||
const record = value as Record<string, unknown>;
|
||||
pushChangedFile(target, seen, record.path);
|
||||
pushChangedFile(target, seen, record.filePath);
|
||||
pushChangedFile(target, seen, record.relativePath);
|
||||
pushChangedFile(target, seen, record.filename);
|
||||
pushChangedFile(target, seen, record.newPath);
|
||||
pushChangedFile(target, seen, record.oldPath);
|
||||
for (const nestedKey of ["result", "input", "content", "files", "edits", "changes"]) {
|
||||
if (nestedKey in record) {
|
||||
collectChangedFiles(record[nestedKey], target, seen, depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function canonicalToolLifecycleData(input: {
|
||||
itemType?: CanonicalItemType | undefined;
|
||||
toolName?: string | undefined;
|
||||
input?: Record<string, unknown> | undefined;
|
||||
result?: unknown;
|
||||
}): CanonicalToolLifecycleData | undefined {
|
||||
const command = normalizeCommandValue(input.input?.command);
|
||||
const changedFiles: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
collectChangedFiles(input.input, changedFiles, seen, 0);
|
||||
collectChangedFiles(input.result, changedFiles, seen, 0);
|
||||
if (input.itemType === "command_execution" && command) {
|
||||
const resultRecord =
|
||||
input.result && typeof input.result === "object" && !Array.isArray(input.result)
|
||||
? (input.result as Record<string, unknown>)
|
||||
: undefined;
|
||||
return {
|
||||
kind: "command_execution",
|
||||
command,
|
||||
...(input.toolName ? { toolName: input.toolName } : {}),
|
||||
...(input.input ? { input: input.input as CanonicalToolLifecycleData["input"] } : {}),
|
||||
...(typeof resultRecord?.content === "string" ? { output: resultRecord.content } : {}),
|
||||
...(typeof resultRecord?.is_error === "boolean" && resultRecord.is_error === false
|
||||
? { exitCode: 0 }
|
||||
: {}),
|
||||
...(input.result !== undefined
|
||||
? { result: input.result as CanonicalToolLifecycleData["result"] }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
if (input.itemType === "file_change" && changedFiles.length > 0) {
|
||||
return {
|
||||
kind: "file_change",
|
||||
changedFiles,
|
||||
...(input.toolName ? { toolName: input.toolName } : {}),
|
||||
...(input.input ? { input: input.input as CanonicalToolLifecycleData["input"] } : {}),
|
||||
...(input.result !== undefined
|
||||
? { result: input.result as CanonicalToolLifecycleData["result"] }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
if (input.toolName || input.input || input.result !== undefined) {
|
||||
return {
|
||||
kind: "generic",
|
||||
...(input.toolName ? { toolName: input.toolName } : {}),
|
||||
...(input.input ? { input: input.input as CanonicalToolLifecycleData["input"] } : {}),
|
||||
...(input.result !== undefined
|
||||
? { result: input.result as CanonicalToolLifecycleData["result"] }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function toolInputFingerprint(input: Record<string, unknown>): string | undefined {
|
||||
try {
|
||||
return JSON.stringify(input);
|
||||
@@ -1385,8 +1496,7 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
payload: {
|
||||
state: status,
|
||||
...(result?.stop_reason !== undefined ? { stopReason: result.stop_reason } : {}),
|
||||
...(result?.usage ? { usage: result.usage } : {}),
|
||||
...(result?.modelUsage ? { modelUsage: result.modelUsage } : {}),
|
||||
...(usageSnapshot ? { usage: usageSnapshot } : {}),
|
||||
...(typeof result?.total_cost_usd === "number"
|
||||
? { totalCostUsd: result.total_cost_usd }
|
||||
: {}),
|
||||
@@ -1412,10 +1522,19 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
status: status === "completed" ? "completed" : "failed",
|
||||
title: tool.title,
|
||||
...(tool.detail ? { detail: tool.detail } : {}),
|
||||
data: {
|
||||
...(canonicalToolLifecycleData({
|
||||
itemType: tool.itemType,
|
||||
toolName: tool.toolName,
|
||||
input: tool.input,
|
||||
},
|
||||
})
|
||||
? {
|
||||
data: canonicalToolLifecycleData({
|
||||
itemType: tool.itemType,
|
||||
toolName: tool.toolName,
|
||||
input: tool.input,
|
||||
}),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
providerRefs: nativeProviderRefs(context, { providerItemId: tool.itemId }),
|
||||
raw: {
|
||||
@@ -1469,8 +1588,7 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
payload: {
|
||||
state: status,
|
||||
...(result?.stop_reason !== undefined ? { stopReason: result.stop_reason } : {}),
|
||||
...(result?.usage ? { usage: result.usage } : {}),
|
||||
...(result?.modelUsage ? { modelUsage: result.modelUsage } : {}),
|
||||
...(usageSnapshot ? { usage: usageSnapshot } : {}),
|
||||
...(typeof result?.total_cost_usd === "number"
|
||||
? { totalCostUsd: result.total_cost_usd }
|
||||
: {}),
|
||||
@@ -1605,10 +1723,19 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
status: "inProgress",
|
||||
title: nextTool.title,
|
||||
...(nextTool.detail ? { detail: nextTool.detail } : {}),
|
||||
data: {
|
||||
...(canonicalToolLifecycleData({
|
||||
itemType: nextTool.itemType,
|
||||
toolName: nextTool.toolName,
|
||||
input: nextTool.input,
|
||||
},
|
||||
})
|
||||
? {
|
||||
data: canonicalToolLifecycleData({
|
||||
itemType: nextTool.itemType,
|
||||
toolName: nextTool.toolName,
|
||||
input: nextTool.input,
|
||||
}),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
providerRefs: nativeProviderRefs(context, { providerItemId: nextTool.itemId }),
|
||||
raw: {
|
||||
@@ -1674,10 +1801,19 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
status: "inProgress",
|
||||
title: tool.title,
|
||||
...(tool.detail ? { detail: tool.detail } : {}),
|
||||
data: {
|
||||
...(canonicalToolLifecycleData({
|
||||
itemType: tool.itemType,
|
||||
toolName: tool.toolName,
|
||||
input: toolInput,
|
||||
},
|
||||
})
|
||||
? {
|
||||
data: canonicalToolLifecycleData({
|
||||
itemType: tool.itemType,
|
||||
toolName: tool.toolName,
|
||||
input: toolInput,
|
||||
}),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
providerRefs: nativeProviderRefs(context, { providerItemId: tool.itemId }),
|
||||
raw: {
|
||||
@@ -1729,11 +1865,12 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
|
||||
const [index, tool] = toolEntry;
|
||||
const itemStatus = toolResult.isError ? "failed" : "completed";
|
||||
const toolData = {
|
||||
const toolData = canonicalToolLifecycleData({
|
||||
itemType: tool.itemType,
|
||||
toolName: tool.toolName,
|
||||
input: tool.input,
|
||||
result: toolResult.block,
|
||||
};
|
||||
});
|
||||
|
||||
const updatedStamp = yield* makeEventStamp();
|
||||
yield* offerRuntimeEvent({
|
||||
@@ -1749,7 +1886,7 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
status: toolResult.isError ? "failed" : "inProgress",
|
||||
title: tool.title,
|
||||
...(tool.detail ? { detail: tool.detail } : {}),
|
||||
data: toolData,
|
||||
...(toolData ? { data: toolData } : {}),
|
||||
},
|
||||
providerRefs: nativeProviderRefs(context, { providerItemId: tool.itemId }),
|
||||
raw: {
|
||||
@@ -1797,7 +1934,7 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
status: itemStatus,
|
||||
title: tool.title,
|
||||
...(tool.detail ? { detail: tool.detail } : {}),
|
||||
data: toolData,
|
||||
...(toolData ? { data: toolData } : {}),
|
||||
},
|
||||
providerRefs: nativeProviderRefs(context, { providerItemId: tool.itemId }),
|
||||
raw: {
|
||||
@@ -1941,15 +2078,6 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
};
|
||||
|
||||
switch (message.subtype) {
|
||||
case "init":
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
type: "session.configured",
|
||||
payload: {
|
||||
config: message as Record<string, unknown>,
|
||||
},
|
||||
});
|
||||
return;
|
||||
case "status":
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
@@ -1971,43 +2099,6 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
},
|
||||
});
|
||||
return;
|
||||
case "hook_started":
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
type: "hook.started",
|
||||
payload: {
|
||||
hookId: message.hook_id,
|
||||
hookName: message.hook_name,
|
||||
hookEvent: message.hook_event,
|
||||
},
|
||||
});
|
||||
return;
|
||||
case "hook_progress":
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
type: "hook.progress",
|
||||
payload: {
|
||||
hookId: message.hook_id,
|
||||
output: message.output,
|
||||
stdout: message.stdout,
|
||||
stderr: message.stderr,
|
||||
},
|
||||
});
|
||||
return;
|
||||
case "hook_response":
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
type: "hook.completed",
|
||||
payload: {
|
||||
hookId: message.hook_id,
|
||||
outcome: message.outcome,
|
||||
output: message.output,
|
||||
stdout: message.stdout,
|
||||
stderr: message.stderr,
|
||||
...(typeof message.exit_code === "number" ? { exitCode: message.exit_code } : {}),
|
||||
},
|
||||
});
|
||||
return;
|
||||
case "task_started":
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
@@ -2046,7 +2137,9 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
taskId: RuntimeTaskId.make(message.task_id),
|
||||
description: message.description,
|
||||
...(message.summary ? { summary: message.summary } : {}),
|
||||
...(message.usage ? { usage: message.usage } : {}),
|
||||
...(message.usage
|
||||
? { usage: normalizeClaudeTokenUsage(message.usage, context.lastKnownContextWindow) }
|
||||
: {}),
|
||||
...(message.last_tool_name ? { lastToolName: message.last_tool_name } : {}),
|
||||
},
|
||||
});
|
||||
@@ -2078,28 +2171,8 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
taskId: RuntimeTaskId.make(message.task_id),
|
||||
status: message.status,
|
||||
...(message.summary ? { summary: message.summary } : {}),
|
||||
...(message.usage ? { usage: message.usage } : {}),
|
||||
},
|
||||
});
|
||||
return;
|
||||
case "files_persisted":
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
type: "files.persisted",
|
||||
payload: {
|
||||
files: Array.isArray(message.files)
|
||||
? message.files.map((file: { filename: string; file_id: string }) => ({
|
||||
filename: file.filename,
|
||||
fileId: file.file_id,
|
||||
}))
|
||||
: [],
|
||||
...(Array.isArray(message.failed)
|
||||
? {
|
||||
failed: message.failed.map((entry: { filename: string; error: string }) => ({
|
||||
filename: entry.filename,
|
||||
error: entry.error,
|
||||
})),
|
||||
}
|
||||
...(message.usage
|
||||
? { usage: normalizeClaudeTokenUsage(message.usage, context.lastKnownContextWindow) }
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
@@ -2114,78 +2187,10 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
}
|
||||
});
|
||||
|
||||
const handleSdkTelemetryMessage = Effect.fn("handleSdkTelemetryMessage")(function* (
|
||||
context: ClaudeSessionContext,
|
||||
message: SDKMessage,
|
||||
) {
|
||||
const stamp = yield* makeEventStamp();
|
||||
const base = {
|
||||
eventId: stamp.eventId,
|
||||
provider: PROVIDER,
|
||||
createdAt: stamp.createdAt,
|
||||
threadId: context.session.threadId,
|
||||
...(context.turnState ? { turnId: asCanonicalTurnId(context.turnState.turnId) } : {}),
|
||||
providerRefs: nativeProviderRefs(context),
|
||||
raw: {
|
||||
source: "claude.sdk.message" as const,
|
||||
method: sdkNativeMethod(message),
|
||||
messageType: message.type,
|
||||
payload: message,
|
||||
},
|
||||
};
|
||||
|
||||
if (message.type === "tool_progress") {
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
type: "tool.progress",
|
||||
payload: {
|
||||
toolUseId: message.tool_use_id,
|
||||
toolName: message.tool_name,
|
||||
elapsedSeconds: message.elapsed_time_seconds,
|
||||
...(message.task_id ? { summary: `task:${message.task_id}` } : {}),
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === "tool_use_summary") {
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
type: "tool.summary",
|
||||
payload: {
|
||||
summary: message.summary,
|
||||
...(message.preceding_tool_use_ids.length > 0
|
||||
? { precedingToolUseIds: message.preceding_tool_use_ids }
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === "auth_status") {
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
type: "auth.status",
|
||||
payload: {
|
||||
isAuthenticating: message.isAuthenticating,
|
||||
output: message.output,
|
||||
...(message.error ? { error: message.error } : {}),
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === "rate_limit_event") {
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
type: "account.rate-limits.updated",
|
||||
payload: {
|
||||
rateLimits: message,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
});
|
||||
const handleSdkTelemetryMessage = (
|
||||
_context: ClaudeSessionContext,
|
||||
_message: SDKMessage,
|
||||
): Effect.Effect<void> => Effect.void;
|
||||
|
||||
const handleSdkMessage = Effect.fn("handleSdkMessage")(function* (
|
||||
context: ClaudeSessionContext,
|
||||
@@ -2789,25 +2794,6 @@ const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
|
||||
providerRefs: {},
|
||||
});
|
||||
|
||||
const configuredStamp = yield* makeEventStamp();
|
||||
yield* offerRuntimeEvent({
|
||||
type: "session.configured",
|
||||
eventId: configuredStamp.eventId,
|
||||
provider: PROVIDER,
|
||||
createdAt: configuredStamp.createdAt,
|
||||
threadId,
|
||||
payload: {
|
||||
config: {
|
||||
...(apiModelId ? { model: apiModelId } : {}),
|
||||
...(input.cwd ? { cwd: input.cwd } : {}),
|
||||
...(effectiveEffort ? { effort: effectiveEffort } : {}),
|
||||
...(permissionMode ? { permissionMode } : {}),
|
||||
...(fastMode ? { fastMode: true } : {}),
|
||||
},
|
||||
},
|
||||
providerRefs: {},
|
||||
});
|
||||
|
||||
const readyStamp = yield* makeEventStamp();
|
||||
yield* offerRuntimeEvent({
|
||||
type: "session.state.changed",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
import {
|
||||
type CanonicalItemType,
|
||||
type CanonicalToolLifecycleData,
|
||||
type CanonicalRequestType,
|
||||
type ProviderEvent,
|
||||
type ProviderRuntimeEvent,
|
||||
@@ -105,6 +106,111 @@ function asNumber(value: unknown): number | undefined {
|
||||
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
||||
}
|
||||
|
||||
function normalizeCommandValue(value: unknown): string | undefined {
|
||||
if (typeof value === "string") {
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length > 0 ? trimmed : undefined;
|
||||
}
|
||||
if (!Array.isArray(value)) {
|
||||
return undefined;
|
||||
}
|
||||
const parts = value
|
||||
.map((entry) => (typeof entry === "string" ? entry.trim() : ""))
|
||||
.filter((entry) => entry.length > 0);
|
||||
return parts.length > 0 ? parts.join(" ") : undefined;
|
||||
}
|
||||
|
||||
function pushChangedFile(target: string[], seen: Set<string>, value: unknown) {
|
||||
if (typeof value !== "string") {
|
||||
return;
|
||||
}
|
||||
const normalized = value.trim();
|
||||
if (normalized.length === 0 || seen.has(normalized)) {
|
||||
return;
|
||||
}
|
||||
seen.add(normalized);
|
||||
target.push(normalized);
|
||||
}
|
||||
|
||||
function collectChangedFiles(value: unknown, target: string[], seen: Set<string>, depth: number) {
|
||||
if (depth > 4 || target.length >= 12) {
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
for (const entry of value) {
|
||||
collectChangedFiles(entry, target, seen, depth + 1);
|
||||
if (target.length >= 12) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const record = asObject(value);
|
||||
if (!record) {
|
||||
return;
|
||||
}
|
||||
|
||||
pushChangedFile(target, seen, record.path);
|
||||
pushChangedFile(target, seen, record.filePath);
|
||||
pushChangedFile(target, seen, record.relativePath);
|
||||
pushChangedFile(target, seen, record.filename);
|
||||
pushChangedFile(target, seen, record.newPath);
|
||||
pushChangedFile(target, seen, record.oldPath);
|
||||
|
||||
for (const nestedKey of ["item", "result", "input", "changes", "files", "edits", "patches"]) {
|
||||
if (!(nestedKey in record)) {
|
||||
continue;
|
||||
}
|
||||
collectChangedFiles(record[nestedKey], target, seen, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
function buildCanonicalToolLifecycleData(
|
||||
itemType: CanonicalItemType,
|
||||
source: Record<string, unknown>,
|
||||
payload: Record<string, unknown>,
|
||||
): CanonicalToolLifecycleData | undefined {
|
||||
const result = asObject(source.result);
|
||||
const input = asObject(source.input);
|
||||
const command = [
|
||||
normalizeCommandValue(source.command),
|
||||
normalizeCommandValue(input?.command),
|
||||
normalizeCommandValue(result?.command),
|
||||
normalizeCommandValue(payload.command),
|
||||
].find((candidate) => candidate !== undefined);
|
||||
const changedFiles: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
collectChangedFiles(source, changedFiles, seen, 0);
|
||||
collectChangedFiles(payload, changedFiles, seen, 0);
|
||||
if (itemType === "command_execution" && command) {
|
||||
return {
|
||||
kind: "command_execution",
|
||||
command,
|
||||
...(input ? { input: input as CanonicalToolLifecycleData["input"] } : {}),
|
||||
...(result ? { result: result as CanonicalToolLifecycleData["result"] } : {}),
|
||||
...(typeof result?.content === "string" ? { output: result.content } : {}),
|
||||
...(asNumber(result?.exitCode) !== undefined ? { exitCode: asNumber(result?.exitCode) } : {}),
|
||||
};
|
||||
}
|
||||
if (itemType === "file_change" && changedFiles.length > 0) {
|
||||
return {
|
||||
kind: "file_change",
|
||||
changedFiles,
|
||||
...(input ? { input: input as CanonicalToolLifecycleData["input"] } : {}),
|
||||
...(result ? { result: result as CanonicalToolLifecycleData["result"] } : {}),
|
||||
};
|
||||
}
|
||||
if (input || result) {
|
||||
return {
|
||||
kind: "generic",
|
||||
...(input ? { input: input as CanonicalToolLifecycleData["input"] } : {}),
|
||||
...(result ? { result: result as CanonicalToolLifecycleData["result"] } : {}),
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const FATAL_CODEX_STDERR_SNIPPETS = ["failed to connect to websocket"];
|
||||
|
||||
function isFatalCodexProcessStderrMessage(message: string): boolean {
|
||||
@@ -319,27 +425,29 @@ function toCanonicalUserInputAnswers(
|
||||
return {};
|
||||
}
|
||||
|
||||
return Object.fromEntries(
|
||||
Object.entries(answers).flatMap(([questionId, value]) => {
|
||||
if (typeof value === "string") {
|
||||
return [[questionId, value] as const];
|
||||
}
|
||||
const normalized: Record<string, string | readonly string[]> = {};
|
||||
for (const [questionId, value] of Object.entries(answers)) {
|
||||
if (typeof value === "string") {
|
||||
normalized[questionId] = value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
const normalized = value.filter((entry): entry is string => typeof entry === "string");
|
||||
return [[questionId, normalized.length === 1 ? normalized[0] : normalized] as const];
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
const entries = value.filter((entry): entry is string => typeof entry === "string");
|
||||
normalized[questionId] = entries.length === 1 ? (entries[0] ?? entries) : entries;
|
||||
continue;
|
||||
}
|
||||
|
||||
const answerObject = asObject(value);
|
||||
const answerList = asArray(answerObject?.answers)?.filter(
|
||||
(entry): entry is string => typeof entry === "string",
|
||||
);
|
||||
if (!answerList) {
|
||||
return [];
|
||||
}
|
||||
return [[questionId, answerList.length === 1 ? answerList[0] : answerList] as const];
|
||||
}),
|
||||
);
|
||||
const answerObject = asObject(value);
|
||||
const answerList = asArray(answerObject?.answers)?.filter(
|
||||
(entry): entry is string => typeof entry === "string",
|
||||
);
|
||||
if (answerList) {
|
||||
normalized[questionId] = answerList.length === 1 ? (answerList[0] ?? answerList) : answerList;
|
||||
}
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function toUserInputQuestions(payload: Record<string, unknown> | undefined) {
|
||||
@@ -566,7 +674,9 @@ function mapItemLifecycle(
|
||||
...(status ? { status } : {}),
|
||||
...(itemTitle(itemType) ? { title: itemTitle(itemType) } : {}),
|
||||
...(detail ? { detail } : {}),
|
||||
...(event.payload !== undefined ? { data: event.payload } : {}),
|
||||
...(buildCanonicalToolLifecycleData(itemType, source, payload ?? {})
|
||||
? { data: buildCanonicalToolLifecycleData(itemType, source, payload ?? {}) }
|
||||
: {}),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -798,8 +908,9 @@ function mapToRuntimeEvents(
|
||||
payload: {
|
||||
state: toTurnStatus(turn?.status),
|
||||
...(asString(turn?.stopReason) ? { stopReason: asString(turn?.stopReason) } : {}),
|
||||
...(turn?.usage !== undefined ? { usage: turn.usage } : {}),
|
||||
...(asObject(turn?.modelUsage) ? { modelUsage: asObject(turn?.modelUsage) } : {}),
|
||||
...(normalizeCodexTokenUsage(turn?.usage)
|
||||
? { usage: normalizeCodexTokenUsage(turn?.usage) }
|
||||
: {}),
|
||||
...(asNumber(turn?.totalCostUsd) !== undefined
|
||||
? { totalCostUsd: asNumber(turn?.totalCostUsd) }
|
||||
: {}),
|
||||
@@ -809,18 +920,6 @@ function mapToRuntimeEvents(
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "turn/aborted") {
|
||||
return [
|
||||
{
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
type: "turn.aborted",
|
||||
payload: {
|
||||
reason: event.message ?? "Turn aborted",
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "turn/plan/updated") {
|
||||
const steps = Array.isArray(payload?.plan) ? payload.plan : [];
|
||||
return [
|
||||
@@ -955,23 +1054,6 @@ function mapToRuntimeEvents(
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "item/mcpToolCall/progress") {
|
||||
return [
|
||||
{
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
type: "tool.progress",
|
||||
payload: {
|
||||
...(asString(payload?.toolUseId) ? { toolUseId: asString(payload?.toolUseId) } : {}),
|
||||
...(asString(payload?.toolName) ? { toolName: asString(payload?.toolName) } : {}),
|
||||
...(asString(payload?.summary) ? { summary: asString(payload?.summary) } : {}),
|
||||
...(asNumber(payload?.elapsedSeconds) !== undefined
|
||||
? { elapsedSeconds: asNumber(payload?.elapsedSeconds) }
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "serverRequest/resolved") {
|
||||
const requestType =
|
||||
toRequestTypeFromResolvedPayload(payload) !== "unknown"
|
||||
@@ -1111,148 +1193,6 @@ function mapToRuntimeEvents(
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "model/rerouted") {
|
||||
return [
|
||||
{
|
||||
type: "model.rerouted",
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
payload: {
|
||||
fromModel: asString(payload?.fromModel) ?? "unknown",
|
||||
toModel: asString(payload?.toModel) ?? "unknown",
|
||||
reason: asString(payload?.reason) ?? "unknown",
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "deprecationNotice") {
|
||||
return [
|
||||
{
|
||||
type: "deprecation.notice",
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
payload: {
|
||||
summary: asString(payload?.summary) ?? "Deprecation notice",
|
||||
...(asString(payload?.details) ? { details: asString(payload?.details) } : {}),
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "configWarning") {
|
||||
return [
|
||||
{
|
||||
type: "config.warning",
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
payload: {
|
||||
summary: asString(payload?.summary) ?? "Configuration warning",
|
||||
...(asString(payload?.details) ? { details: asString(payload?.details) } : {}),
|
||||
...(asString(payload?.path) ? { path: asString(payload?.path) } : {}),
|
||||
...(payload?.range !== undefined ? { range: payload.range } : {}),
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "account/updated") {
|
||||
return [
|
||||
{
|
||||
type: "account.updated",
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
payload: {
|
||||
account: event.payload ?? {},
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "account/rateLimits/updated") {
|
||||
return [
|
||||
{
|
||||
type: "account.rate-limits.updated",
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
payload: {
|
||||
rateLimits: event.payload ?? {},
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "mcpServer/oauthLogin/completed") {
|
||||
return [
|
||||
{
|
||||
type: "mcp.oauth.completed",
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
payload: {
|
||||
success: payload?.success === true,
|
||||
...(asString(payload?.name) ? { name: asString(payload?.name) } : {}),
|
||||
...(asString(payload?.error) ? { error: asString(payload?.error) } : {}),
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "thread/realtime/started") {
|
||||
const realtimeSessionId = asString(payload?.realtimeSessionId);
|
||||
return [
|
||||
{
|
||||
type: "thread.realtime.started",
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
payload: {
|
||||
realtimeSessionId,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "thread/realtime/itemAdded") {
|
||||
return [
|
||||
{
|
||||
type: "thread.realtime.item-added",
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
payload: {
|
||||
item: event.payload ?? {},
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "thread/realtime/outputAudio/delta") {
|
||||
return [
|
||||
{
|
||||
type: "thread.realtime.audio.delta",
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
payload: {
|
||||
audio: event.payload ?? {},
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "thread/realtime/error") {
|
||||
const message = asString(payload?.message) ?? event.message ?? "Realtime error";
|
||||
return [
|
||||
{
|
||||
type: "thread.realtime.error",
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
payload: {
|
||||
message,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "thread/realtime/closed") {
|
||||
return [
|
||||
{
|
||||
type: "thread.realtime.closed",
|
||||
...runtimeEventBase(event, canonicalThreadId),
|
||||
payload: {
|
||||
reason: event.message,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (event.method === "error") {
|
||||
const message =
|
||||
asString(asObject(payload?.error)?.message) ?? event.message ?? "Provider runtime error";
|
||||
|
||||
+46
-17
@@ -136,27 +136,56 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
|
||||
clientSessions: serverAuth.listClientSessions(currentSessionId).pipe(Effect.orDie),
|
||||
});
|
||||
|
||||
const appendSetupScriptActivity = (input: {
|
||||
readonly threadId: ThreadId;
|
||||
readonly kind: "setup-script.requested" | "setup-script.started" | "setup-script.failed";
|
||||
readonly summary: string;
|
||||
readonly createdAt: string;
|
||||
readonly payload: Record<string, unknown>;
|
||||
readonly tone: "info" | "error";
|
||||
}) =>
|
||||
const appendSetupScriptActivity = (
|
||||
input: {
|
||||
readonly threadId: ThreadId;
|
||||
readonly summary: string;
|
||||
readonly createdAt: string;
|
||||
} & (
|
||||
| {
|
||||
readonly kind: "setup-script.requested" | "setup-script.started";
|
||||
readonly payload: {
|
||||
readonly scriptId: string;
|
||||
readonly scriptName: string;
|
||||
readonly terminalId: string;
|
||||
readonly worktreePath: string;
|
||||
};
|
||||
readonly tone: "info";
|
||||
}
|
||||
| {
|
||||
readonly kind: "setup-script.failed";
|
||||
readonly payload: {
|
||||
readonly detail: string;
|
||||
readonly worktreePath: string;
|
||||
};
|
||||
readonly tone: "error";
|
||||
}
|
||||
),
|
||||
) =>
|
||||
orchestrationEngine.dispatch({
|
||||
type: "thread.activity.append",
|
||||
commandId: serverCommandId("setup-script-activity"),
|
||||
threadId: input.threadId,
|
||||
activity: {
|
||||
id: EventId.make(crypto.randomUUID()),
|
||||
tone: input.tone,
|
||||
kind: input.kind,
|
||||
summary: input.summary,
|
||||
payload: input.payload,
|
||||
turnId: null,
|
||||
createdAt: input.createdAt,
|
||||
},
|
||||
activity:
|
||||
input.kind === "setup-script.failed"
|
||||
? {
|
||||
id: EventId.make(crypto.randomUUID()),
|
||||
tone: input.tone,
|
||||
kind: input.kind,
|
||||
summary: input.summary,
|
||||
payload: input.payload,
|
||||
turnId: null,
|
||||
createdAt: input.createdAt,
|
||||
}
|
||||
: {
|
||||
id: EventId.make(crypto.randomUUID()),
|
||||
tone: input.tone,
|
||||
kind: input.kind,
|
||||
summary: input.summary,
|
||||
payload: input.payload,
|
||||
turnId: null,
|
||||
createdAt: input.createdAt,
|
||||
},
|
||||
createdAt: input.createdAt,
|
||||
});
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
type ProviderKind,
|
||||
type ProjectId,
|
||||
type ProviderApprovalDecision,
|
||||
type ProviderUserInputAnswers,
|
||||
type ServerProvider,
|
||||
type ScopedThreadRef,
|
||||
type ThreadId,
|
||||
@@ -2785,7 +2786,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
);
|
||||
|
||||
const onRespondToUserInput = useCallback(
|
||||
async (requestId: ApprovalRequestId, answers: Record<string, unknown>) => {
|
||||
async (requestId: ApprovalRequestId, answers: ProviderUserInputAnswers) => {
|
||||
const api = readEnvironmentApi(environmentId);
|
||||
if (!api || !activeThreadId) return;
|
||||
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { EventId, type OrchestrationThreadActivity, TurnId } from "@t3tools/contracts";
|
||||
import {
|
||||
EventId,
|
||||
type OrchestrationThreadActivity,
|
||||
type OrchestrationThreadActivityKind,
|
||||
TurnId,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
import { deriveLatestContextWindowSnapshot, formatContextWindowTokens } from "./contextWindow";
|
||||
|
||||
function makeActivity(id: string, kind: string, payload: unknown): OrchestrationThreadActivity {
|
||||
function makeActivity(
|
||||
id: string,
|
||||
kind: OrchestrationThreadActivityKind,
|
||||
payload: unknown,
|
||||
): OrchestrationThreadActivity {
|
||||
return {
|
||||
id: EventId.make(id),
|
||||
tone: "info",
|
||||
tone: kind.startsWith("tool.") ? "tool" : "info",
|
||||
kind,
|
||||
summary: kind,
|
||||
payload,
|
||||
turnId: TurnId.make("turn-1"),
|
||||
createdAt: "2026-03-23T00:00:00.000Z",
|
||||
};
|
||||
} as OrchestrationThreadActivity;
|
||||
}
|
||||
|
||||
describe("contextWindow", () => {
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
import type { OrchestrationThreadActivity, ThreadTokenUsageSnapshot } from "@t3tools/contracts";
|
||||
|
||||
function asRecord(value: unknown): Record<string, unknown> | null {
|
||||
return value && typeof value === "object" ? (value as Record<string, unknown>) : null;
|
||||
}
|
||||
|
||||
function asFiniteNumber(value: unknown): number | null {
|
||||
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
||||
}
|
||||
|
||||
function asBoolean(value: unknown): boolean | null {
|
||||
return typeof value === "boolean" ? value : null;
|
||||
}
|
||||
|
||||
type NullableContextWindowUsage = {
|
||||
readonly [Key in keyof ThreadTokenUsageSnapshot]: undefined extends ThreadTokenUsageSnapshot[Key]
|
||||
? Exclude<ThreadTokenUsageSnapshot[Key], undefined> | null
|
||||
@@ -34,38 +22,56 @@ export function deriveLatestContextWindowSnapshot(
|
||||
continue;
|
||||
}
|
||||
|
||||
const payload = asRecord(activity.payload);
|
||||
const usedTokens = asFiniteNumber(payload?.usedTokens);
|
||||
if (usedTokens === null || usedTokens <= 0) {
|
||||
const {
|
||||
payload: {
|
||||
usedTokens,
|
||||
totalProcessedTokens,
|
||||
maxTokens,
|
||||
inputTokens,
|
||||
cachedInputTokens,
|
||||
outputTokens,
|
||||
reasoningOutputTokens,
|
||||
lastUsedTokens,
|
||||
lastInputTokens,
|
||||
lastCachedInputTokens,
|
||||
lastOutputTokens,
|
||||
lastReasoningOutputTokens,
|
||||
toolUses,
|
||||
durationMs,
|
||||
compactsAutomatically,
|
||||
},
|
||||
} = activity;
|
||||
if (!Number.isFinite(usedTokens) || usedTokens <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const maxTokens = asFiniteNumber(payload?.maxTokens);
|
||||
const usedPercentage =
|
||||
maxTokens !== null && maxTokens > 0 ? Math.min(100, (usedTokens / maxTokens) * 100) : null;
|
||||
maxTokens !== undefined && maxTokens > 0
|
||||
? Math.min(100, (usedTokens / maxTokens) * 100)
|
||||
: null;
|
||||
const remainingTokens =
|
||||
maxTokens !== null ? Math.max(0, Math.round(maxTokens - usedTokens)) : null;
|
||||
maxTokens !== undefined ? Math.max(0, Math.round(maxTokens - usedTokens)) : null;
|
||||
const remainingPercentage = usedPercentage !== null ? Math.max(0, 100 - usedPercentage) : null;
|
||||
|
||||
return {
|
||||
usedTokens,
|
||||
totalProcessedTokens: asFiniteNumber(payload?.totalProcessedTokens),
|
||||
maxTokens,
|
||||
totalProcessedTokens: totalProcessedTokens ?? null,
|
||||
maxTokens: maxTokens ?? null,
|
||||
remainingTokens,
|
||||
usedPercentage,
|
||||
remainingPercentage,
|
||||
inputTokens: asFiniteNumber(payload?.inputTokens),
|
||||
cachedInputTokens: asFiniteNumber(payload?.cachedInputTokens),
|
||||
outputTokens: asFiniteNumber(payload?.outputTokens),
|
||||
reasoningOutputTokens: asFiniteNumber(payload?.reasoningOutputTokens),
|
||||
lastUsedTokens: asFiniteNumber(payload?.lastUsedTokens),
|
||||
lastInputTokens: asFiniteNumber(payload?.lastInputTokens),
|
||||
lastCachedInputTokens: asFiniteNumber(payload?.lastCachedInputTokens),
|
||||
lastOutputTokens: asFiniteNumber(payload?.lastOutputTokens),
|
||||
lastReasoningOutputTokens: asFiniteNumber(payload?.lastReasoningOutputTokens),
|
||||
toolUses: asFiniteNumber(payload?.toolUses),
|
||||
durationMs: asFiniteNumber(payload?.durationMs),
|
||||
compactsAutomatically: asBoolean(payload?.compactsAutomatically) ?? false,
|
||||
inputTokens: inputTokens ?? null,
|
||||
cachedInputTokens: cachedInputTokens ?? null,
|
||||
outputTokens: outputTokens ?? null,
|
||||
reasoningOutputTokens: reasoningOutputTokens ?? null,
|
||||
lastUsedTokens: lastUsedTokens ?? null,
|
||||
lastInputTokens: lastInputTokens ?? null,
|
||||
lastCachedInputTokens: lastCachedInputTokens ?? null,
|
||||
lastOutputTokens: lastOutputTokens ?? null,
|
||||
lastReasoningOutputTokens: lastReasoningOutputTokens ?? null,
|
||||
toolUses: toolUses ?? null,
|
||||
durationMs: durationMs ?? null,
|
||||
compactsAutomatically: compactsAutomatically ?? false,
|
||||
updatedAt: activity.createdAt,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
MessageId,
|
||||
ThreadId,
|
||||
TurnId,
|
||||
type OrchestrationThreadActivityKind,
|
||||
type OrchestrationThreadActivity,
|
||||
} from "@t3tools/contracts";
|
||||
import { describe, expect, it } from "vitest";
|
||||
@@ -26,7 +27,7 @@ import {
|
||||
function makeActivity(overrides: {
|
||||
id?: string;
|
||||
createdAt?: string;
|
||||
kind?: string;
|
||||
kind?: OrchestrationThreadActivityKind;
|
||||
summary?: string;
|
||||
tone?: OrchestrationThreadActivity["tone"];
|
||||
payload?: Record<string, unknown>;
|
||||
@@ -43,7 +44,7 @@ function makeActivity(overrides: {
|
||||
payload,
|
||||
turnId: overrides.turnId ? TurnId.make(overrides.turnId) : null,
|
||||
...(overrides.sequence !== undefined ? { sequence: overrides.sequence } : {}),
|
||||
};
|
||||
} as OrchestrationThreadActivity;
|
||||
}
|
||||
|
||||
describe("derivePendingApprovals", () => {
|
||||
@@ -701,9 +702,8 @@ describe("deriveWorkLogEntries", () => {
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
data: {
|
||||
item: {
|
||||
command: ["bun", "run", "lint"],
|
||||
},
|
||||
kind: "command_execution",
|
||||
command: "bun run lint",
|
||||
},
|
||||
},
|
||||
}),
|
||||
@@ -816,12 +816,11 @@ describe("deriveWorkLogEntries", () => {
|
||||
status: "completed",
|
||||
detail: '{ "dev": "vite dev --port 3000" } <exited with exit code 0>',
|
||||
data: {
|
||||
item: {
|
||||
command: ["bun", "run", "dev"],
|
||||
result: {
|
||||
content: '{ "dev": "vite dev --port 3000" } <exited with exit code 0>',
|
||||
exitCode: 0,
|
||||
},
|
||||
kind: "command_execution",
|
||||
command: "bun run dev",
|
||||
result: {
|
||||
content: '{ "dev": "vite dev --port 3000" } <exited with exit code 0>',
|
||||
exitCode: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -846,12 +845,8 @@ describe("deriveWorkLogEntries", () => {
|
||||
payload: {
|
||||
itemType: "file_change",
|
||||
data: {
|
||||
item: {
|
||||
changes: [
|
||||
{ path: "apps/web/src/components/ChatView.tsx" },
|
||||
{ filename: "apps/web/src/session-logic.ts" },
|
||||
],
|
||||
},
|
||||
kind: "file_change",
|
||||
changedFiles: ["apps/web/src/components/ChatView.tsx", "apps/web/src/session-logic.ts"],
|
||||
},
|
||||
},
|
||||
}),
|
||||
@@ -887,9 +882,7 @@ describe("deriveWorkLogEntries", () => {
|
||||
title: "Tool call",
|
||||
detail: 'Read: {"file_path":"/tmp/app.ts"}',
|
||||
data: {
|
||||
item: {
|
||||
command: ["sed", "-n", "1,40p", "/tmp/app.ts"],
|
||||
},
|
||||
kind: "generic",
|
||||
},
|
||||
},
|
||||
}),
|
||||
@@ -914,7 +907,6 @@ describe("deriveWorkLogEntries", () => {
|
||||
createdAt: "2026-02-23T00:00:03.000Z",
|
||||
label: "Tool call completed",
|
||||
detail: 'Read: {"file_path":"/tmp/app.ts"}',
|
||||
command: "sed -n 1,40p /tmp/app.ts",
|
||||
itemType: "dynamic_tool_call",
|
||||
toolTitle: "Tool call",
|
||||
});
|
||||
@@ -1151,7 +1143,7 @@ describe("hasToolActivityForTurn", () => {
|
||||
it("returns true only for matching tool activity in the target turn", () => {
|
||||
const activities: OrchestrationThreadActivity[] = [
|
||||
makeActivity({ id: "tool-1", turnId: "turn-1", kind: "tool.completed", tone: "tool" }),
|
||||
makeActivity({ id: "info-1", turnId: "turn-2", kind: "turn.completed", tone: "info" }),
|
||||
makeActivity({ id: "info-1", turnId: "turn-2", kind: "task.completed", tone: "info" }),
|
||||
];
|
||||
|
||||
expect(hasToolActivityForTurn(activities, TurnId.make("turn-1"))).toBe(true);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
type CanonicalToolLifecycleData,
|
||||
isToolLifecycleItemType,
|
||||
type OrchestrationLatestTurn,
|
||||
type OrchestrationThreadActivity,
|
||||
@@ -478,22 +479,10 @@ function isPlanBoundaryToolActivity(activity: OrchestrationThreadActivity): bool
|
||||
if (activity.kind !== "tool.updated" && activity.kind !== "tool.completed") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const payload =
|
||||
activity.payload && typeof activity.payload === "object"
|
||||
? (activity.payload as Record<string, unknown>)
|
||||
: null;
|
||||
return typeof payload?.detail === "string" && payload.detail.startsWith("ExitPlanMode:");
|
||||
return activity.payload.detail?.startsWith("ExitPlanMode:") ?? false;
|
||||
}
|
||||
|
||||
function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWorkLogEntry {
|
||||
const payload =
|
||||
activity.payload && typeof activity.payload === "object"
|
||||
? (activity.payload as Record<string, unknown>)
|
||||
: null;
|
||||
const commandPreview = extractToolCommand(payload);
|
||||
const changedFiles = extractChangedFiles(payload);
|
||||
const title = extractToolTitle(payload);
|
||||
const entry: DerivedWorkLogEntry = {
|
||||
id: activity.id,
|
||||
createdAt: activity.createdAt,
|
||||
@@ -501,12 +490,24 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
|
||||
tone: activity.tone === "approval" ? "info" : activity.tone,
|
||||
activityKind: activity.kind,
|
||||
};
|
||||
const itemType = extractWorkLogItemType(payload);
|
||||
const requestKind = extractWorkLogRequestKind(payload);
|
||||
if (payload && typeof payload.detail === "string" && payload.detail.length > 0) {
|
||||
const detail = stripTrailingExitCode(payload.detail).output;
|
||||
if (detail) {
|
||||
entry.detail = detail;
|
||||
const toolPayload = toolLifecyclePayloadFromActivity(activity);
|
||||
const detail =
|
||||
"detail" in activity.payload && typeof activity.payload.detail === "string"
|
||||
? activity.payload.detail
|
||||
: undefined;
|
||||
const toolData = toolPayload && "data" in toolPayload ? toolPayload.data : undefined;
|
||||
const commandPreview = extractToolCommand(toolData, detail);
|
||||
const changedFiles = extractChangedFiles(toolData);
|
||||
const title =
|
||||
"title" in activity.payload && typeof activity.payload.title === "string"
|
||||
? extractToolTitle(activity.payload.title)
|
||||
: null;
|
||||
const itemType = extractWorkLogItemType(toolPayload);
|
||||
const requestKind = extractWorkLogRequestKind(activity);
|
||||
if (detail && detail.length > 0) {
|
||||
const normalizedDetail = stripTrailingExitCode(detail).output;
|
||||
if (normalizedDetail) {
|
||||
entry.detail = normalizedDetail;
|
||||
}
|
||||
}
|
||||
if (commandPreview.command) {
|
||||
@@ -534,6 +535,24 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
|
||||
return entry;
|
||||
}
|
||||
|
||||
function toolLifecyclePayloadFromActivity(
|
||||
activity: OrchestrationThreadActivity,
|
||||
):
|
||||
| Extract<
|
||||
OrchestrationThreadActivity,
|
||||
{ kind: "tool.started" | "tool.updated" | "tool.completed" }
|
||||
>["payload"]
|
||||
| null {
|
||||
switch (activity.kind) {
|
||||
case "tool.started":
|
||||
case "tool.updated":
|
||||
case "tool.completed":
|
||||
return activity.payload;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function collapseDerivedWorkLogEntries(
|
||||
entries: ReadonlyArray<DerivedWorkLogEntry>,
|
||||
): DerivedWorkLogEntry[] {
|
||||
@@ -631,10 +650,6 @@ function toLatestProposedPlanState(proposedPlan: ProposedPlan): LatestProposedPl
|
||||
};
|
||||
}
|
||||
|
||||
function asRecord(value: unknown): Record<string, unknown> | null {
|
||||
return value && typeof value === "object" ? (value as Record<string, unknown>) : null;
|
||||
}
|
||||
|
||||
function asTrimmedString(value: unknown): string | null {
|
||||
if (typeof value !== "string") {
|
||||
return null;
|
||||
@@ -787,22 +802,17 @@ function toRawToolCommand(value: unknown, normalizedCommand: string | null): str
|
||||
return formatted === normalizedCommand ? null : formatted;
|
||||
}
|
||||
|
||||
function extractToolCommand(payload: Record<string, unknown> | null): {
|
||||
function extractToolCommand(
|
||||
data: CanonicalToolLifecycleData | undefined,
|
||||
detail: string | undefined,
|
||||
): {
|
||||
command: string | null;
|
||||
rawCommand: string | null;
|
||||
} {
|
||||
const data = asRecord(payload?.data);
|
||||
const item = asRecord(data?.item);
|
||||
const itemResult = asRecord(item?.result);
|
||||
const itemInput = asRecord(item?.input);
|
||||
const itemType = asTrimmedString(payload?.itemType);
|
||||
const detail = asTrimmedString(payload?.detail);
|
||||
const candidates: unknown[] = [
|
||||
item?.command,
|
||||
itemInput?.command,
|
||||
itemResult?.command,
|
||||
data?.command,
|
||||
itemType === "command_execution" && detail ? stripTrailingExitCode(detail).output : null,
|
||||
data?.kind === "command_execution" ? data.command : null,
|
||||
data?.input?.command,
|
||||
data?.kind === "command_execution" && detail ? stripTrailingExitCode(detail).output : null,
|
||||
];
|
||||
|
||||
for (const candidate of candidates) {
|
||||
@@ -822,8 +832,8 @@ function extractToolCommand(payload: Record<string, unknown> | null): {
|
||||
};
|
||||
}
|
||||
|
||||
function extractToolTitle(payload: Record<string, unknown> | null): string | null {
|
||||
return asTrimmedString(payload?.title);
|
||||
function extractToolTitle(value: string | undefined): string | null {
|
||||
return asTrimmedString(value);
|
||||
}
|
||||
|
||||
function stripTrailingExitCode(value: string): {
|
||||
@@ -848,28 +858,36 @@ function stripTrailingExitCode(value: string): {
|
||||
}
|
||||
|
||||
function extractWorkLogItemType(
|
||||
payload: Record<string, unknown> | null,
|
||||
payload:
|
||||
| Extract<
|
||||
OrchestrationThreadActivity,
|
||||
{ kind: "tool.started" | "tool.updated" | "tool.completed" }
|
||||
>["payload"]
|
||||
| null,
|
||||
): WorkLogEntry["itemType"] | undefined {
|
||||
if (typeof payload?.itemType === "string" && isToolLifecycleItemType(payload.itemType)) {
|
||||
if (payload && isToolLifecycleItemType(payload.itemType)) {
|
||||
return payload.itemType;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function extractWorkLogRequestKind(
|
||||
payload: Record<string, unknown> | null,
|
||||
activity: OrchestrationThreadActivity,
|
||||
): WorkLogEntry["requestKind"] | undefined {
|
||||
if (
|
||||
payload?.requestKind === "command" ||
|
||||
payload?.requestKind === "file-read" ||
|
||||
payload?.requestKind === "file-change"
|
||||
) {
|
||||
return payload.requestKind;
|
||||
if (activity.kind !== "approval.requested" && activity.kind !== "approval.resolved") {
|
||||
return undefined;
|
||||
}
|
||||
return requestKindFromRequestType(payload?.requestType) ?? undefined;
|
||||
if (
|
||||
activity.payload.requestKind === "command" ||
|
||||
activity.payload.requestKind === "file-read" ||
|
||||
activity.payload.requestKind === "file-change"
|
||||
) {
|
||||
return activity.payload.requestKind;
|
||||
}
|
||||
return requestKindFromRequestType(activity.payload.requestType) ?? undefined;
|
||||
}
|
||||
|
||||
function pushChangedFile(target: string[], seen: Set<string>, value: unknown) {
|
||||
function pushChangedFile(target: string[], seen: Set<string>, value: string | undefined) {
|
||||
const normalized = asTrimmedString(value);
|
||||
if (!normalized || seen.has(normalized)) {
|
||||
return;
|
||||
@@ -878,58 +896,16 @@ function pushChangedFile(target: string[], seen: Set<string>, value: unknown) {
|
||||
target.push(normalized);
|
||||
}
|
||||
|
||||
function collectChangedFiles(value: unknown, target: string[], seen: Set<string>, depth: number) {
|
||||
if (depth > 4 || target.length >= 12) {
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
for (const entry of value) {
|
||||
collectChangedFiles(entry, target, seen, depth + 1);
|
||||
if (target.length >= 12) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const record = asRecord(value);
|
||||
if (!record) {
|
||||
return;
|
||||
}
|
||||
|
||||
pushChangedFile(target, seen, record.path);
|
||||
pushChangedFile(target, seen, record.filePath);
|
||||
pushChangedFile(target, seen, record.relativePath);
|
||||
pushChangedFile(target, seen, record.filename);
|
||||
pushChangedFile(target, seen, record.newPath);
|
||||
pushChangedFile(target, seen, record.oldPath);
|
||||
|
||||
for (const nestedKey of [
|
||||
"item",
|
||||
"result",
|
||||
"input",
|
||||
"data",
|
||||
"changes",
|
||||
"files",
|
||||
"edits",
|
||||
"patch",
|
||||
"patches",
|
||||
"operations",
|
||||
]) {
|
||||
if (!(nestedKey in record)) {
|
||||
continue;
|
||||
}
|
||||
collectChangedFiles(record[nestedKey], target, seen, depth + 1);
|
||||
if (target.length >= 12) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function extractChangedFiles(payload: Record<string, unknown> | null): string[] {
|
||||
function extractChangedFiles(data: CanonicalToolLifecycleData | undefined): string[] {
|
||||
const changedFiles: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
collectChangedFiles(asRecord(payload?.data), changedFiles, seen, 0);
|
||||
const files = data?.kind === "file_change" ? data.changedFiles : [];
|
||||
for (const file of files) {
|
||||
pushChangedFile(changedFiles, seen, file);
|
||||
if (changedFiles.length >= 12) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return changedFiles;
|
||||
}
|
||||
|
||||
|
||||
@@ -263,9 +263,9 @@ describe("thread selection memoization", () => {
|
||||
{
|
||||
id: EventId.make("activity-1"),
|
||||
tone: "info",
|
||||
kind: "step",
|
||||
kind: "runtime.warning",
|
||||
summary: "working",
|
||||
payload: {},
|
||||
payload: { message: "working" },
|
||||
turnId: TurnId.make("turn-1"),
|
||||
createdAt: "2026-02-13T00:01:30.000Z",
|
||||
},
|
||||
@@ -1108,18 +1108,18 @@ describe("incremental orchestration updates", () => {
|
||||
{
|
||||
id: EventId.make("activity-1"),
|
||||
tone: "info",
|
||||
kind: "step",
|
||||
kind: "runtime.warning",
|
||||
summary: "one",
|
||||
payload: {},
|
||||
payload: { message: "one" },
|
||||
turnId: TurnId.make("turn-1"),
|
||||
createdAt: "2026-02-27T00:00:00.000Z",
|
||||
},
|
||||
{
|
||||
id: EventId.make("activity-2"),
|
||||
tone: "info",
|
||||
kind: "step",
|
||||
kind: "runtime.warning",
|
||||
summary: "two",
|
||||
payload: {},
|
||||
payload: { message: "two" },
|
||||
turnId: TurnId.make("turn-2"),
|
||||
createdAt: "2026-02-27T00:00:02.000Z",
|
||||
},
|
||||
|
||||
@@ -5,12 +5,16 @@ export * from "./ipc";
|
||||
export * from "./terminal";
|
||||
export * from "./provider";
|
||||
export * from "./providerRuntime";
|
||||
export * from "./threadUsage";
|
||||
export * from "./model";
|
||||
export * from "./keybindings";
|
||||
export * from "./server";
|
||||
export * from "./settings";
|
||||
export * from "./git";
|
||||
export * from "./jsonValue";
|
||||
export * from "./orchestration";
|
||||
export * from "./toolLifecycle";
|
||||
export * from "./userInput";
|
||||
export * from "./editor";
|
||||
export * from "./project";
|
||||
export * from "./rpc";
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Schema } from "effect";
|
||||
|
||||
export const CanonicalJsonValueSchema = Schema.Json;
|
||||
export type CanonicalJsonValue = typeof CanonicalJsonValueSchema.Type;
|
||||
|
||||
export const CanonicalJsonObjectSchema = Schema.Record(Schema.String, CanonicalJsonValueSchema);
|
||||
export type CanonicalJsonObject = typeof CanonicalJsonObjectSchema.Type;
|
||||
@@ -15,6 +15,10 @@ import {
|
||||
TrimmedNonEmptyString,
|
||||
TurnId,
|
||||
} from "./baseSchemas";
|
||||
import { CanonicalJsonValueSchema } from "./jsonValue";
|
||||
import { CanonicalToolLifecycleData } from "./toolLifecycle";
|
||||
import { ThreadTokenUsageSnapshot } from "./threadUsage";
|
||||
import { ProviderUserInputAnswers, UserInputQuestion } from "./userInput";
|
||||
|
||||
export const ORCHESTRATION_WS_METHODS = {
|
||||
getSnapshot: "orchestration.getSnapshot",
|
||||
@@ -80,9 +84,6 @@ export const ProviderApprovalDecision = Schema.Literals([
|
||||
"cancel",
|
||||
]);
|
||||
export type ProviderApprovalDecision = typeof ProviderApprovalDecision.Type;
|
||||
export const ProviderUserInputAnswers = Schema.Record(Schema.String, Schema.Unknown);
|
||||
export type ProviderUserInputAnswers = typeof ProviderUserInputAnswers.Type;
|
||||
|
||||
export const PROVIDER_SEND_TURN_MAX_INPUT_CHARS = 120_000;
|
||||
export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8;
|
||||
export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024;
|
||||
@@ -243,16 +244,223 @@ export const OrchestrationThreadActivityTone = Schema.Literals([
|
||||
]);
|
||||
export type OrchestrationThreadActivityTone = typeof OrchestrationThreadActivityTone.Type;
|
||||
|
||||
export const OrchestrationThreadActivity = Schema.Struct({
|
||||
export const OrchestrationThreadActivityKind = Schema.Literals([
|
||||
"approval.requested",
|
||||
"approval.resolved",
|
||||
"runtime.error",
|
||||
"runtime.warning",
|
||||
"turn.plan.updated",
|
||||
"user-input.requested",
|
||||
"user-input.resolved",
|
||||
"task.started",
|
||||
"task.progress",
|
||||
"task.completed",
|
||||
"setup-script.requested",
|
||||
"setup-script.started",
|
||||
"setup-script.failed",
|
||||
"context-compaction",
|
||||
"context-window.updated",
|
||||
"tool.updated",
|
||||
"tool.completed",
|
||||
"tool.started",
|
||||
"checkpoint.revert.failed",
|
||||
"checkpoint.capture.failed",
|
||||
"checkpoint.captured",
|
||||
"provider.turn.start.failed",
|
||||
"provider.turn.interrupt.failed",
|
||||
"provider.approval.respond.failed",
|
||||
"provider.user-input.respond.failed",
|
||||
]);
|
||||
export type OrchestrationThreadActivityKind = typeof OrchestrationThreadActivityKind.Type;
|
||||
|
||||
const OrchestrationThreadActivityBaseFields = {
|
||||
id: EventId,
|
||||
tone: OrchestrationThreadActivityTone,
|
||||
kind: TrimmedNonEmptyString,
|
||||
summary: TrimmedNonEmptyString,
|
||||
payload: Schema.Unknown,
|
||||
turnId: Schema.NullOr(TurnId),
|
||||
sequence: Schema.optional(NonNegativeInt),
|
||||
createdAt: IsoDateTime,
|
||||
} as const;
|
||||
|
||||
const ApprovalRequestedActivityPayload = Schema.Struct({
|
||||
requestId: Schema.optional(TrimmedNonEmptyString),
|
||||
requestKind: Schema.optional(ProviderRequestKind),
|
||||
requestType: Schema.optional(TrimmedNonEmptyString),
|
||||
detail: Schema.optional(TrimmedNonEmptyString),
|
||||
});
|
||||
|
||||
const ApprovalResolvedActivityPayload = Schema.Struct({
|
||||
requestId: Schema.optional(TrimmedNonEmptyString),
|
||||
requestKind: Schema.optional(ProviderRequestKind),
|
||||
requestType: Schema.optional(TrimmedNonEmptyString),
|
||||
decision: Schema.optional(TrimmedNonEmptyString),
|
||||
});
|
||||
|
||||
const RuntimeErrorActivityPayload = Schema.Struct({
|
||||
message: TrimmedNonEmptyString,
|
||||
});
|
||||
|
||||
const RuntimeWarningActivityPayload = Schema.Struct({
|
||||
message: TrimmedNonEmptyString,
|
||||
detail: Schema.optional(CanonicalJsonValueSchema),
|
||||
});
|
||||
|
||||
const RuntimePlanStep = Schema.Struct({
|
||||
step: TrimmedNonEmptyString,
|
||||
status: TrimmedNonEmptyString,
|
||||
});
|
||||
|
||||
const TurnPlanUpdatedActivityPayload = Schema.Struct({
|
||||
plan: Schema.Array(RuntimePlanStep),
|
||||
explanation: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
});
|
||||
|
||||
const UserInputRequestedActivityPayload = Schema.Struct({
|
||||
requestId: Schema.optional(TrimmedNonEmptyString),
|
||||
questions: Schema.Array(UserInputQuestion),
|
||||
});
|
||||
|
||||
const UserInputResolvedActivityPayload = Schema.Struct({
|
||||
requestId: Schema.optional(TrimmedNonEmptyString),
|
||||
answers: ProviderUserInputAnswers,
|
||||
});
|
||||
|
||||
const TaskStartedActivityPayload = Schema.Struct({
|
||||
taskId: TrimmedNonEmptyString,
|
||||
taskType: Schema.optional(TrimmedNonEmptyString),
|
||||
detail: Schema.optional(TrimmedNonEmptyString),
|
||||
});
|
||||
|
||||
const TaskProgressActivityPayload = Schema.Struct({
|
||||
taskId: TrimmedNonEmptyString,
|
||||
detail: TrimmedNonEmptyString,
|
||||
summary: Schema.optional(TrimmedNonEmptyString),
|
||||
lastToolName: Schema.optional(TrimmedNonEmptyString),
|
||||
usage: Schema.optional(ThreadTokenUsageSnapshot),
|
||||
});
|
||||
|
||||
const TaskCompletedActivityPayload = Schema.Struct({
|
||||
taskId: TrimmedNonEmptyString,
|
||||
status: TrimmedNonEmptyString,
|
||||
detail: Schema.optional(TrimmedNonEmptyString),
|
||||
usage: Schema.optional(ThreadTokenUsageSnapshot),
|
||||
});
|
||||
|
||||
const SetupScriptRequestedOrStartedActivityPayload = Schema.Struct({
|
||||
scriptId: TrimmedNonEmptyString,
|
||||
scriptName: TrimmedNonEmptyString,
|
||||
terminalId: TrimmedNonEmptyString,
|
||||
worktreePath: TrimmedNonEmptyString,
|
||||
});
|
||||
|
||||
const SetupScriptFailedActivityPayload = Schema.Struct({
|
||||
detail: TrimmedNonEmptyString,
|
||||
worktreePath: TrimmedNonEmptyString,
|
||||
});
|
||||
|
||||
const ContextCompactionActivityPayload = Schema.Struct({
|
||||
state: Schema.Literal("compacted"),
|
||||
detail: Schema.optional(CanonicalJsonValueSchema),
|
||||
});
|
||||
|
||||
const ToolStartedOrCompletedActivityPayload = Schema.Struct({
|
||||
itemType: TrimmedNonEmptyString,
|
||||
detail: Schema.optional(TrimmedNonEmptyString),
|
||||
});
|
||||
|
||||
const ToolUpdatedActivityPayload = Schema.Struct({
|
||||
itemType: TrimmedNonEmptyString,
|
||||
status: Schema.optional(TrimmedNonEmptyString),
|
||||
detail: Schema.optional(TrimmedNonEmptyString),
|
||||
data: Schema.optional(CanonicalToolLifecycleData),
|
||||
});
|
||||
|
||||
const CheckpointRevertFailedActivityPayload = Schema.Struct({
|
||||
turnCount: NonNegativeInt,
|
||||
detail: TrimmedNonEmptyString,
|
||||
});
|
||||
|
||||
const CheckpointCaptureFailedActivityPayload = Schema.Struct({
|
||||
detail: TrimmedNonEmptyString,
|
||||
});
|
||||
|
||||
const CheckpointCapturedActivityPayload = Schema.Struct({
|
||||
turnCount: NonNegativeInt,
|
||||
status: OrchestrationCheckpointStatus,
|
||||
});
|
||||
|
||||
const ProviderFailureActivityPayload = Schema.Struct({
|
||||
detail: TrimmedNonEmptyString,
|
||||
requestId: Schema.optional(TrimmedNonEmptyString),
|
||||
});
|
||||
|
||||
function makeThreadActivitySchema<
|
||||
Kind extends OrchestrationThreadActivityKind,
|
||||
Payload extends Schema.Schema<any>,
|
||||
>(kind: Kind, tone: OrchestrationThreadActivityTone, payload: Payload) {
|
||||
return Schema.Struct({
|
||||
...OrchestrationThreadActivityBaseFields,
|
||||
tone: Schema.Literal(tone),
|
||||
kind: Schema.Literal(kind),
|
||||
payload,
|
||||
});
|
||||
}
|
||||
|
||||
export const OrchestrationThreadActivity = Schema.Union([
|
||||
makeThreadActivitySchema("approval.requested", "approval", ApprovalRequestedActivityPayload),
|
||||
makeThreadActivitySchema("approval.resolved", "approval", ApprovalResolvedActivityPayload),
|
||||
makeThreadActivitySchema("runtime.error", "error", RuntimeErrorActivityPayload),
|
||||
makeThreadActivitySchema("runtime.warning", "info", RuntimeWarningActivityPayload),
|
||||
makeThreadActivitySchema("turn.plan.updated", "info", TurnPlanUpdatedActivityPayload),
|
||||
makeThreadActivitySchema("user-input.requested", "info", UserInputRequestedActivityPayload),
|
||||
makeThreadActivitySchema("user-input.resolved", "info", UserInputResolvedActivityPayload),
|
||||
makeThreadActivitySchema("task.started", "info", TaskStartedActivityPayload),
|
||||
makeThreadActivitySchema("task.progress", "info", TaskProgressActivityPayload),
|
||||
makeThreadActivitySchema("task.completed", "info", TaskCompletedActivityPayload),
|
||||
makeThreadActivitySchema(
|
||||
"setup-script.requested",
|
||||
"info",
|
||||
SetupScriptRequestedOrStartedActivityPayload,
|
||||
),
|
||||
makeThreadActivitySchema(
|
||||
"setup-script.started",
|
||||
"info",
|
||||
SetupScriptRequestedOrStartedActivityPayload,
|
||||
),
|
||||
makeThreadActivitySchema("setup-script.failed", "error", SetupScriptFailedActivityPayload),
|
||||
makeThreadActivitySchema("context-compaction", "info", ContextCompactionActivityPayload),
|
||||
makeThreadActivitySchema("context-window.updated", "info", ThreadTokenUsageSnapshot),
|
||||
makeThreadActivitySchema("tool.updated", "tool", ToolUpdatedActivityPayload),
|
||||
makeThreadActivitySchema("tool.completed", "tool", ToolStartedOrCompletedActivityPayload),
|
||||
makeThreadActivitySchema("tool.started", "tool", ToolStartedOrCompletedActivityPayload),
|
||||
makeThreadActivitySchema(
|
||||
"checkpoint.revert.failed",
|
||||
"error",
|
||||
CheckpointRevertFailedActivityPayload,
|
||||
),
|
||||
makeThreadActivitySchema(
|
||||
"checkpoint.capture.failed",
|
||||
"error",
|
||||
CheckpointCaptureFailedActivityPayload,
|
||||
),
|
||||
makeThreadActivitySchema("checkpoint.captured", "info", CheckpointCapturedActivityPayload),
|
||||
makeThreadActivitySchema("provider.turn.start.failed", "error", ProviderFailureActivityPayload),
|
||||
makeThreadActivitySchema(
|
||||
"provider.turn.interrupt.failed",
|
||||
"error",
|
||||
ProviderFailureActivityPayload,
|
||||
),
|
||||
makeThreadActivitySchema(
|
||||
"provider.approval.respond.failed",
|
||||
"error",
|
||||
ProviderFailureActivityPayload,
|
||||
),
|
||||
makeThreadActivitySchema(
|
||||
"provider.user-input.respond.failed",
|
||||
"error",
|
||||
ProviderFailureActivityPayload,
|
||||
),
|
||||
]);
|
||||
export type OrchestrationThreadActivity = typeof OrchestrationThreadActivity.Type;
|
||||
|
||||
const OrchestrationLatestTurnState = Schema.Literals([
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Schema } from "effect";
|
||||
import { TrimmedNonEmptyString } from "./baseSchemas";
|
||||
import { ProviderUserInputAnswers } from "./userInput";
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
EventId,
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
ProviderKind,
|
||||
ProviderRequestKind,
|
||||
ProviderSandboxMode,
|
||||
ProviderUserInputAnswers,
|
||||
RuntimeMode,
|
||||
} from "./orchestration";
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Effect, Schema } from "effect";
|
||||
import { Schema } from "effect";
|
||||
import {
|
||||
EventId,
|
||||
IsoDateTime,
|
||||
NonNegativeInt,
|
||||
ProviderItemId,
|
||||
PositiveInt,
|
||||
RuntimeItemId,
|
||||
RuntimeRequestId,
|
||||
RuntimeTaskId,
|
||||
@@ -13,9 +11,13 @@ import {
|
||||
TurnId,
|
||||
} from "./baseSchemas";
|
||||
import { ProviderKind } from "./orchestration";
|
||||
import { CanonicalToolLifecycleData } from "./toolLifecycle";
|
||||
export { ThreadTokenUsageSnapshot } from "./threadUsage";
|
||||
import { ThreadTokenUsageSnapshot } from "./threadUsage";
|
||||
export { ProviderUserInputAnswers, UserInputQuestion } from "./userInput";
|
||||
import { ProviderUserInputAnswers, UserInputQuestion } from "./userInput";
|
||||
|
||||
const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
|
||||
const UnknownRecordSchema = Schema.Record(Schema.String, Schema.Unknown);
|
||||
|
||||
const RuntimeEventRawSource = Schema.Literals([
|
||||
"codex.app-server.notification",
|
||||
@@ -143,21 +145,14 @@ export type CanonicalRequestType = typeof CanonicalRequestType.Type;
|
||||
|
||||
const ProviderRuntimeEventType = Schema.Literals([
|
||||
"session.started",
|
||||
"session.configured",
|
||||
"session.state.changed",
|
||||
"session.exited",
|
||||
"thread.started",
|
||||
"thread.state.changed",
|
||||
"thread.metadata.updated",
|
||||
"thread.token-usage.updated",
|
||||
"thread.realtime.started",
|
||||
"thread.realtime.item-added",
|
||||
"thread.realtime.audio.delta",
|
||||
"thread.realtime.error",
|
||||
"thread.realtime.closed",
|
||||
"turn.started",
|
||||
"turn.completed",
|
||||
"turn.aborted",
|
||||
"turn.plan.updated",
|
||||
"turn.proposed.delta",
|
||||
"turn.proposed.completed",
|
||||
@@ -173,41 +168,20 @@ const ProviderRuntimeEventType = Schema.Literals([
|
||||
"task.started",
|
||||
"task.progress",
|
||||
"task.completed",
|
||||
"hook.started",
|
||||
"hook.progress",
|
||||
"hook.completed",
|
||||
"tool.progress",
|
||||
"tool.summary",
|
||||
"auth.status",
|
||||
"account.updated",
|
||||
"account.rate-limits.updated",
|
||||
"mcp.status.updated",
|
||||
"mcp.oauth.completed",
|
||||
"model.rerouted",
|
||||
"config.warning",
|
||||
"deprecation.notice",
|
||||
"files.persisted",
|
||||
"runtime.warning",
|
||||
"runtime.error",
|
||||
]);
|
||||
export type ProviderRuntimeEventType = typeof ProviderRuntimeEventType.Type;
|
||||
|
||||
const SessionStartedType = Schema.Literal("session.started");
|
||||
const SessionConfiguredType = Schema.Literal("session.configured");
|
||||
const SessionStateChangedType = Schema.Literal("session.state.changed");
|
||||
const SessionExitedType = Schema.Literal("session.exited");
|
||||
const ThreadStartedType = Schema.Literal("thread.started");
|
||||
const ThreadStateChangedType = Schema.Literal("thread.state.changed");
|
||||
const ThreadMetadataUpdatedType = Schema.Literal("thread.metadata.updated");
|
||||
const ThreadTokenUsageUpdatedType = Schema.Literal("thread.token-usage.updated");
|
||||
const ThreadRealtimeStartedType = Schema.Literal("thread.realtime.started");
|
||||
const ThreadRealtimeItemAddedType = Schema.Literal("thread.realtime.item-added");
|
||||
const ThreadRealtimeAudioDeltaType = Schema.Literal("thread.realtime.audio.delta");
|
||||
const ThreadRealtimeErrorType = Schema.Literal("thread.realtime.error");
|
||||
const ThreadRealtimeClosedType = Schema.Literal("thread.realtime.closed");
|
||||
const TurnStartedType = Schema.Literal("turn.started");
|
||||
const TurnCompletedType = Schema.Literal("turn.completed");
|
||||
const TurnAbortedType = Schema.Literal("turn.aborted");
|
||||
const TurnPlanUpdatedType = Schema.Literal("turn.plan.updated");
|
||||
const TurnProposedDeltaType = Schema.Literal("turn.proposed.delta");
|
||||
const TurnProposedCompletedType = Schema.Literal("turn.proposed.completed");
|
||||
@@ -223,20 +197,6 @@ const UserInputResolvedType = Schema.Literal("user-input.resolved");
|
||||
const TaskStartedType = Schema.Literal("task.started");
|
||||
const TaskProgressType = Schema.Literal("task.progress");
|
||||
const TaskCompletedType = Schema.Literal("task.completed");
|
||||
const HookStartedType = Schema.Literal("hook.started");
|
||||
const HookProgressType = Schema.Literal("hook.progress");
|
||||
const HookCompletedType = Schema.Literal("hook.completed");
|
||||
const ToolProgressType = Schema.Literal("tool.progress");
|
||||
const ToolSummaryType = Schema.Literal("tool.summary");
|
||||
const AuthStatusType = Schema.Literal("auth.status");
|
||||
const AccountUpdatedType = Schema.Literal("account.updated");
|
||||
const AccountRateLimitsUpdatedType = Schema.Literal("account.rate-limits.updated");
|
||||
const McpStatusUpdatedType = Schema.Literal("mcp.status.updated");
|
||||
const McpOauthCompletedType = Schema.Literal("mcp.oauth.completed");
|
||||
const ModelReroutedType = Schema.Literal("model.rerouted");
|
||||
const ConfigWarningType = Schema.Literal("config.warning");
|
||||
const DeprecationNoticeType = Schema.Literal("deprecation.notice");
|
||||
const FilesPersistedType = Schema.Literal("files.persisted");
|
||||
const RuntimeWarningType = Schema.Literal("runtime.warning");
|
||||
const RuntimeErrorType = Schema.Literal("runtime.error");
|
||||
|
||||
@@ -259,11 +219,6 @@ const SessionStartedPayload = Schema.Struct({
|
||||
});
|
||||
export type SessionStartedPayload = typeof SessionStartedPayload.Type;
|
||||
|
||||
const SessionConfiguredPayload = Schema.Struct({
|
||||
config: UnknownRecordSchema,
|
||||
});
|
||||
export type SessionConfiguredPayload = typeof SessionConfiguredPayload.Type;
|
||||
|
||||
const SessionStateChangedPayload = Schema.Struct({
|
||||
state: RuntimeSessionState,
|
||||
reason: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
@@ -291,59 +246,15 @@ export type ThreadStateChangedPayload = typeof ThreadStateChangedPayload.Type;
|
||||
|
||||
const ThreadMetadataUpdatedPayload = Schema.Struct({
|
||||
name: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
metadata: Schema.optional(UnknownRecordSchema),
|
||||
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
||||
});
|
||||
export type ThreadMetadataUpdatedPayload = typeof ThreadMetadataUpdatedPayload.Type;
|
||||
|
||||
export const ThreadTokenUsageSnapshot = Schema.Struct({
|
||||
usedTokens: NonNegativeInt,
|
||||
totalProcessedTokens: Schema.optional(NonNegativeInt),
|
||||
maxTokens: Schema.optional(PositiveInt),
|
||||
inputTokens: Schema.optional(NonNegativeInt),
|
||||
cachedInputTokens: Schema.optional(NonNegativeInt),
|
||||
outputTokens: Schema.optional(NonNegativeInt),
|
||||
reasoningOutputTokens: Schema.optional(NonNegativeInt),
|
||||
lastUsedTokens: Schema.optional(NonNegativeInt),
|
||||
lastInputTokens: Schema.optional(NonNegativeInt),
|
||||
lastCachedInputTokens: Schema.optional(NonNegativeInt),
|
||||
lastOutputTokens: Schema.optional(NonNegativeInt),
|
||||
lastReasoningOutputTokens: Schema.optional(NonNegativeInt),
|
||||
toolUses: Schema.optional(NonNegativeInt),
|
||||
durationMs: Schema.optional(NonNegativeInt),
|
||||
compactsAutomatically: Schema.optional(Schema.Boolean),
|
||||
});
|
||||
export type ThreadTokenUsageSnapshot = typeof ThreadTokenUsageSnapshot.Type;
|
||||
|
||||
const ThreadTokenUsageUpdatedPayload = Schema.Struct({
|
||||
usage: ThreadTokenUsageSnapshot,
|
||||
});
|
||||
export type ThreadTokenUsageUpdatedPayload = typeof ThreadTokenUsageUpdatedPayload.Type;
|
||||
|
||||
const ThreadRealtimeStartedPayload = Schema.Struct({
|
||||
realtimeSessionId: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
});
|
||||
export type ThreadRealtimeStartedPayload = typeof ThreadRealtimeStartedPayload.Type;
|
||||
|
||||
const ThreadRealtimeItemAddedPayload = Schema.Struct({
|
||||
item: Schema.Unknown,
|
||||
});
|
||||
export type ThreadRealtimeItemAddedPayload = typeof ThreadRealtimeItemAddedPayload.Type;
|
||||
|
||||
const ThreadRealtimeAudioDeltaPayload = Schema.Struct({
|
||||
audio: Schema.Unknown,
|
||||
});
|
||||
export type ThreadRealtimeAudioDeltaPayload = typeof ThreadRealtimeAudioDeltaPayload.Type;
|
||||
|
||||
const ThreadRealtimeErrorPayload = Schema.Struct({
|
||||
message: TrimmedNonEmptyStringSchema,
|
||||
});
|
||||
export type ThreadRealtimeErrorPayload = typeof ThreadRealtimeErrorPayload.Type;
|
||||
|
||||
const ThreadRealtimeClosedPayload = Schema.Struct({
|
||||
reason: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
});
|
||||
export type ThreadRealtimeClosedPayload = typeof ThreadRealtimeClosedPayload.Type;
|
||||
|
||||
const TurnStartedPayload = Schema.Struct({
|
||||
model: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
effort: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
@@ -353,18 +264,12 @@ export type TurnStartedPayload = typeof TurnStartedPayload.Type;
|
||||
const TurnCompletedPayload = Schema.Struct({
|
||||
state: RuntimeTurnState,
|
||||
stopReason: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
|
||||
usage: Schema.optional(Schema.Unknown),
|
||||
modelUsage: Schema.optional(UnknownRecordSchema),
|
||||
usage: Schema.optional(ThreadTokenUsageSnapshot),
|
||||
totalCostUsd: Schema.optional(Schema.Number),
|
||||
errorMessage: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
});
|
||||
export type TurnCompletedPayload = typeof TurnCompletedPayload.Type;
|
||||
|
||||
const TurnAbortedPayload = Schema.Struct({
|
||||
reason: TrimmedNonEmptyStringSchema,
|
||||
});
|
||||
export type TurnAbortedPayload = typeof TurnAbortedPayload.Type;
|
||||
|
||||
const RuntimePlanStep = Schema.Struct({
|
||||
step: TrimmedNonEmptyStringSchema,
|
||||
status: RuntimePlanStepStatus,
|
||||
@@ -397,7 +302,7 @@ export const ItemLifecyclePayload = Schema.Struct({
|
||||
status: Schema.optional(RuntimeItemStatus),
|
||||
title: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
detail: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
data: Schema.optional(Schema.Unknown),
|
||||
data: Schema.optional(CanonicalToolLifecycleData),
|
||||
});
|
||||
export type ItemLifecyclePayload = typeof ItemLifecyclePayload.Type;
|
||||
|
||||
@@ -423,30 +328,13 @@ const RequestResolvedPayload = Schema.Struct({
|
||||
});
|
||||
export type RequestResolvedPayload = typeof RequestResolvedPayload.Type;
|
||||
|
||||
const UserInputQuestionOption = Schema.Struct({
|
||||
label: TrimmedNonEmptyStringSchema,
|
||||
description: TrimmedNonEmptyStringSchema,
|
||||
});
|
||||
export type UserInputQuestionOption = typeof UserInputQuestionOption.Type;
|
||||
|
||||
export const UserInputQuestion = Schema.Struct({
|
||||
id: TrimmedNonEmptyStringSchema,
|
||||
header: TrimmedNonEmptyStringSchema,
|
||||
question: TrimmedNonEmptyStringSchema,
|
||||
options: Schema.Array(UserInputQuestionOption),
|
||||
multiSelect: Schema.optional(Schema.Boolean).pipe(
|
||||
Schema.withConstructorDefault(Effect.succeed(false)),
|
||||
),
|
||||
});
|
||||
export type UserInputQuestion = typeof UserInputQuestion.Type;
|
||||
|
||||
const UserInputRequestedPayload = Schema.Struct({
|
||||
questions: Schema.Array(UserInputQuestion),
|
||||
});
|
||||
export type UserInputRequestedPayload = typeof UserInputRequestedPayload.Type;
|
||||
|
||||
const UserInputResolvedPayload = Schema.Struct({
|
||||
answers: UnknownRecordSchema,
|
||||
answers: ProviderUserInputAnswers,
|
||||
});
|
||||
export type UserInputResolvedPayload = typeof UserInputResolvedPayload.Type;
|
||||
|
||||
@@ -461,7 +349,7 @@ const TaskProgressPayload = Schema.Struct({
|
||||
taskId: RuntimeTaskId,
|
||||
description: TrimmedNonEmptyStringSchema,
|
||||
summary: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
usage: Schema.optional(Schema.Unknown),
|
||||
usage: Schema.optional(ThreadTokenUsageSnapshot),
|
||||
lastToolName: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
});
|
||||
export type TaskProgressPayload = typeof TaskProgressPayload.Type;
|
||||
@@ -470,117 +358,10 @@ const TaskCompletedPayload = Schema.Struct({
|
||||
taskId: RuntimeTaskId,
|
||||
status: Schema.Literals(["completed", "failed", "stopped"]),
|
||||
summary: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
usage: Schema.optional(Schema.Unknown),
|
||||
usage: Schema.optional(ThreadTokenUsageSnapshot),
|
||||
});
|
||||
export type TaskCompletedPayload = typeof TaskCompletedPayload.Type;
|
||||
|
||||
const HookStartedPayload = Schema.Struct({
|
||||
hookId: TrimmedNonEmptyStringSchema,
|
||||
hookName: TrimmedNonEmptyStringSchema,
|
||||
hookEvent: TrimmedNonEmptyStringSchema,
|
||||
});
|
||||
export type HookStartedPayload = typeof HookStartedPayload.Type;
|
||||
|
||||
const HookProgressPayload = Schema.Struct({
|
||||
hookId: TrimmedNonEmptyStringSchema,
|
||||
output: Schema.optional(Schema.String),
|
||||
stdout: Schema.optional(Schema.String),
|
||||
stderr: Schema.optional(Schema.String),
|
||||
});
|
||||
export type HookProgressPayload = typeof HookProgressPayload.Type;
|
||||
|
||||
const HookCompletedPayload = Schema.Struct({
|
||||
hookId: TrimmedNonEmptyStringSchema,
|
||||
outcome: Schema.Literals(["success", "error", "cancelled"]),
|
||||
output: Schema.optional(Schema.String),
|
||||
stdout: Schema.optional(Schema.String),
|
||||
stderr: Schema.optional(Schema.String),
|
||||
exitCode: Schema.optional(Schema.Int),
|
||||
});
|
||||
export type HookCompletedPayload = typeof HookCompletedPayload.Type;
|
||||
|
||||
const ToolProgressPayload = Schema.Struct({
|
||||
toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
toolName: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
summary: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
elapsedSeconds: Schema.optional(Schema.Number),
|
||||
});
|
||||
export type ToolProgressPayload = typeof ToolProgressPayload.Type;
|
||||
|
||||
const ToolSummaryPayload = Schema.Struct({
|
||||
summary: TrimmedNonEmptyStringSchema,
|
||||
precedingToolUseIds: Schema.optional(Schema.Array(TrimmedNonEmptyStringSchema)),
|
||||
});
|
||||
export type ToolSummaryPayload = typeof ToolSummaryPayload.Type;
|
||||
|
||||
const AuthStatusPayload = Schema.Struct({
|
||||
isAuthenticating: Schema.optional(Schema.Boolean),
|
||||
output: Schema.optional(Schema.Array(Schema.String)),
|
||||
error: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
});
|
||||
export type AuthStatusPayload = typeof AuthStatusPayload.Type;
|
||||
|
||||
const AccountUpdatedPayload = Schema.Struct({
|
||||
account: Schema.Unknown,
|
||||
});
|
||||
export type AccountUpdatedPayload = typeof AccountUpdatedPayload.Type;
|
||||
|
||||
const AccountRateLimitsUpdatedPayload = Schema.Struct({
|
||||
rateLimits: Schema.Unknown,
|
||||
});
|
||||
export type AccountRateLimitsUpdatedPayload = typeof AccountRateLimitsUpdatedPayload.Type;
|
||||
|
||||
const McpStatusUpdatedPayload = Schema.Struct({
|
||||
status: Schema.Unknown,
|
||||
});
|
||||
export type McpStatusUpdatedPayload = typeof McpStatusUpdatedPayload.Type;
|
||||
|
||||
const McpOauthCompletedPayload = Schema.Struct({
|
||||
success: Schema.Boolean,
|
||||
name: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
error: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
});
|
||||
export type McpOauthCompletedPayload = typeof McpOauthCompletedPayload.Type;
|
||||
|
||||
const ModelReroutedPayload = Schema.Struct({
|
||||
fromModel: TrimmedNonEmptyStringSchema,
|
||||
toModel: TrimmedNonEmptyStringSchema,
|
||||
reason: TrimmedNonEmptyStringSchema,
|
||||
});
|
||||
export type ModelReroutedPayload = typeof ModelReroutedPayload.Type;
|
||||
|
||||
const ConfigWarningPayload = Schema.Struct({
|
||||
summary: TrimmedNonEmptyStringSchema,
|
||||
details: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
path: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
range: Schema.optional(Schema.Unknown),
|
||||
});
|
||||
export type ConfigWarningPayload = typeof ConfigWarningPayload.Type;
|
||||
|
||||
const DeprecationNoticePayload = Schema.Struct({
|
||||
summary: TrimmedNonEmptyStringSchema,
|
||||
details: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
});
|
||||
export type DeprecationNoticePayload = typeof DeprecationNoticePayload.Type;
|
||||
|
||||
const FilesPersistedPayload = Schema.Struct({
|
||||
files: Schema.Array(
|
||||
Schema.Struct({
|
||||
filename: TrimmedNonEmptyStringSchema,
|
||||
fileId: TrimmedNonEmptyStringSchema,
|
||||
}),
|
||||
),
|
||||
failed: Schema.optional(
|
||||
Schema.Array(
|
||||
Schema.Struct({
|
||||
filename: TrimmedNonEmptyStringSchema,
|
||||
error: TrimmedNonEmptyStringSchema,
|
||||
}),
|
||||
),
|
||||
),
|
||||
});
|
||||
export type FilesPersistedPayload = typeof FilesPersistedPayload.Type;
|
||||
|
||||
const RuntimeWarningPayload = Schema.Struct({
|
||||
message: TrimmedNonEmptyStringSchema,
|
||||
detail: Schema.optional(Schema.Unknown),
|
||||
@@ -601,14 +382,6 @@ const ProviderRuntimeSessionStartedEvent = Schema.Struct({
|
||||
});
|
||||
export type ProviderRuntimeSessionStartedEvent = typeof ProviderRuntimeSessionStartedEvent.Type;
|
||||
|
||||
const ProviderRuntimeSessionConfiguredEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: SessionConfiguredType,
|
||||
payload: SessionConfiguredPayload,
|
||||
});
|
||||
export type ProviderRuntimeSessionConfiguredEvent =
|
||||
typeof ProviderRuntimeSessionConfiguredEvent.Type;
|
||||
|
||||
const ProviderRuntimeSessionStateChangedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: SessionStateChangedType,
|
||||
@@ -655,46 +428,6 @@ const ProviderRuntimeThreadTokenUsageUpdatedEvent = Schema.Struct({
|
||||
export type ProviderRuntimeThreadTokenUsageUpdatedEvent =
|
||||
typeof ProviderRuntimeThreadTokenUsageUpdatedEvent.Type;
|
||||
|
||||
const ProviderRuntimeThreadRealtimeStartedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: ThreadRealtimeStartedType,
|
||||
payload: ThreadRealtimeStartedPayload,
|
||||
});
|
||||
export type ProviderRuntimeThreadRealtimeStartedEvent =
|
||||
typeof ProviderRuntimeThreadRealtimeStartedEvent.Type;
|
||||
|
||||
const ProviderRuntimeThreadRealtimeItemAddedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: ThreadRealtimeItemAddedType,
|
||||
payload: ThreadRealtimeItemAddedPayload,
|
||||
});
|
||||
export type ProviderRuntimeThreadRealtimeItemAddedEvent =
|
||||
typeof ProviderRuntimeThreadRealtimeItemAddedEvent.Type;
|
||||
|
||||
const ProviderRuntimeThreadRealtimeAudioDeltaEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: ThreadRealtimeAudioDeltaType,
|
||||
payload: ThreadRealtimeAudioDeltaPayload,
|
||||
});
|
||||
export type ProviderRuntimeThreadRealtimeAudioDeltaEvent =
|
||||
typeof ProviderRuntimeThreadRealtimeAudioDeltaEvent.Type;
|
||||
|
||||
const ProviderRuntimeThreadRealtimeErrorEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: ThreadRealtimeErrorType,
|
||||
payload: ThreadRealtimeErrorPayload,
|
||||
});
|
||||
export type ProviderRuntimeThreadRealtimeErrorEvent =
|
||||
typeof ProviderRuntimeThreadRealtimeErrorEvent.Type;
|
||||
|
||||
const ProviderRuntimeThreadRealtimeClosedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: ThreadRealtimeClosedType,
|
||||
payload: ThreadRealtimeClosedPayload,
|
||||
});
|
||||
export type ProviderRuntimeThreadRealtimeClosedEvent =
|
||||
typeof ProviderRuntimeThreadRealtimeClosedEvent.Type;
|
||||
|
||||
const ProviderRuntimeTurnStartedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: TurnStartedType,
|
||||
@@ -709,13 +442,6 @@ const ProviderRuntimeTurnCompletedEvent = Schema.Struct({
|
||||
});
|
||||
export type ProviderRuntimeTurnCompletedEvent = typeof ProviderRuntimeTurnCompletedEvent.Type;
|
||||
|
||||
const ProviderRuntimeTurnAbortedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: TurnAbortedType,
|
||||
payload: TurnAbortedPayload,
|
||||
});
|
||||
export type ProviderRuntimeTurnAbortedEvent = typeof ProviderRuntimeTurnAbortedEvent.Type;
|
||||
|
||||
const ProviderRuntimeTurnPlanUpdatedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: TurnPlanUpdatedType,
|
||||
@@ -825,107 +551,6 @@ const ProviderRuntimeTaskCompletedEvent = Schema.Struct({
|
||||
});
|
||||
export type ProviderRuntimeTaskCompletedEvent = typeof ProviderRuntimeTaskCompletedEvent.Type;
|
||||
|
||||
const ProviderRuntimeHookStartedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: HookStartedType,
|
||||
payload: HookStartedPayload,
|
||||
});
|
||||
export type ProviderRuntimeHookStartedEvent = typeof ProviderRuntimeHookStartedEvent.Type;
|
||||
|
||||
const ProviderRuntimeHookProgressEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: HookProgressType,
|
||||
payload: HookProgressPayload,
|
||||
});
|
||||
export type ProviderRuntimeHookProgressEvent = typeof ProviderRuntimeHookProgressEvent.Type;
|
||||
|
||||
const ProviderRuntimeHookCompletedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: HookCompletedType,
|
||||
payload: HookCompletedPayload,
|
||||
});
|
||||
export type ProviderRuntimeHookCompletedEvent = typeof ProviderRuntimeHookCompletedEvent.Type;
|
||||
|
||||
const ProviderRuntimeToolProgressEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: ToolProgressType,
|
||||
payload: ToolProgressPayload,
|
||||
});
|
||||
export type ProviderRuntimeToolProgressEvent = typeof ProviderRuntimeToolProgressEvent.Type;
|
||||
|
||||
const ProviderRuntimeToolSummaryEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: ToolSummaryType,
|
||||
payload: ToolSummaryPayload,
|
||||
});
|
||||
export type ProviderRuntimeToolSummaryEvent = typeof ProviderRuntimeToolSummaryEvent.Type;
|
||||
|
||||
const ProviderRuntimeAuthStatusEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: AuthStatusType,
|
||||
payload: AuthStatusPayload,
|
||||
});
|
||||
export type ProviderRuntimeAuthStatusEvent = typeof ProviderRuntimeAuthStatusEvent.Type;
|
||||
|
||||
const ProviderRuntimeAccountUpdatedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: AccountUpdatedType,
|
||||
payload: AccountUpdatedPayload,
|
||||
});
|
||||
export type ProviderRuntimeAccountUpdatedEvent = typeof ProviderRuntimeAccountUpdatedEvent.Type;
|
||||
|
||||
const ProviderRuntimeAccountRateLimitsUpdatedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: AccountRateLimitsUpdatedType,
|
||||
payload: AccountRateLimitsUpdatedPayload,
|
||||
});
|
||||
export type ProviderRuntimeAccountRateLimitsUpdatedEvent =
|
||||
typeof ProviderRuntimeAccountRateLimitsUpdatedEvent.Type;
|
||||
|
||||
const ProviderRuntimeMcpStatusUpdatedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: McpStatusUpdatedType,
|
||||
payload: McpStatusUpdatedPayload,
|
||||
});
|
||||
export type ProviderRuntimeMcpStatusUpdatedEvent = typeof ProviderRuntimeMcpStatusUpdatedEvent.Type;
|
||||
|
||||
const ProviderRuntimeMcpOauthCompletedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: McpOauthCompletedType,
|
||||
payload: McpOauthCompletedPayload,
|
||||
});
|
||||
export type ProviderRuntimeMcpOauthCompletedEvent =
|
||||
typeof ProviderRuntimeMcpOauthCompletedEvent.Type;
|
||||
|
||||
const ProviderRuntimeModelReroutedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: ModelReroutedType,
|
||||
payload: ModelReroutedPayload,
|
||||
});
|
||||
export type ProviderRuntimeModelReroutedEvent = typeof ProviderRuntimeModelReroutedEvent.Type;
|
||||
|
||||
const ProviderRuntimeConfigWarningEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: ConfigWarningType,
|
||||
payload: ConfigWarningPayload,
|
||||
});
|
||||
export type ProviderRuntimeConfigWarningEvent = typeof ProviderRuntimeConfigWarningEvent.Type;
|
||||
|
||||
const ProviderRuntimeDeprecationNoticeEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: DeprecationNoticeType,
|
||||
payload: DeprecationNoticePayload,
|
||||
});
|
||||
export type ProviderRuntimeDeprecationNoticeEvent =
|
||||
typeof ProviderRuntimeDeprecationNoticeEvent.Type;
|
||||
|
||||
const ProviderRuntimeFilesPersistedEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: FilesPersistedType,
|
||||
payload: FilesPersistedPayload,
|
||||
});
|
||||
export type ProviderRuntimeFilesPersistedEvent = typeof ProviderRuntimeFilesPersistedEvent.Type;
|
||||
|
||||
const ProviderRuntimeWarningEvent = Schema.Struct({
|
||||
...ProviderRuntimeEventBase.fields,
|
||||
type: RuntimeWarningType,
|
||||
@@ -942,21 +567,14 @@ export type ProviderRuntimeErrorEvent = typeof ProviderRuntimeErrorEvent.Type;
|
||||
|
||||
export const ProviderRuntimeEventV2 = Schema.Union([
|
||||
ProviderRuntimeSessionStartedEvent,
|
||||
ProviderRuntimeSessionConfiguredEvent,
|
||||
ProviderRuntimeSessionStateChangedEvent,
|
||||
ProviderRuntimeSessionExitedEvent,
|
||||
ProviderRuntimeThreadStartedEvent,
|
||||
ProviderRuntimeThreadStateChangedEvent,
|
||||
ProviderRuntimeThreadMetadataUpdatedEvent,
|
||||
ProviderRuntimeThreadTokenUsageUpdatedEvent,
|
||||
ProviderRuntimeThreadRealtimeStartedEvent,
|
||||
ProviderRuntimeThreadRealtimeItemAddedEvent,
|
||||
ProviderRuntimeThreadRealtimeAudioDeltaEvent,
|
||||
ProviderRuntimeThreadRealtimeErrorEvent,
|
||||
ProviderRuntimeThreadRealtimeClosedEvent,
|
||||
ProviderRuntimeTurnStartedEvent,
|
||||
ProviderRuntimeTurnCompletedEvent,
|
||||
ProviderRuntimeTurnAbortedEvent,
|
||||
ProviderRuntimeTurnPlanUpdatedEvent,
|
||||
ProviderRuntimeTurnProposedDeltaEvent,
|
||||
ProviderRuntimeTurnProposedCompletedEvent,
|
||||
@@ -972,20 +590,6 @@ export const ProviderRuntimeEventV2 = Schema.Union([
|
||||
ProviderRuntimeTaskStartedEvent,
|
||||
ProviderRuntimeTaskProgressEvent,
|
||||
ProviderRuntimeTaskCompletedEvent,
|
||||
ProviderRuntimeHookStartedEvent,
|
||||
ProviderRuntimeHookProgressEvent,
|
||||
ProviderRuntimeHookCompletedEvent,
|
||||
ProviderRuntimeToolProgressEvent,
|
||||
ProviderRuntimeToolSummaryEvent,
|
||||
ProviderRuntimeAuthStatusEvent,
|
||||
ProviderRuntimeAccountUpdatedEvent,
|
||||
ProviderRuntimeAccountRateLimitsUpdatedEvent,
|
||||
ProviderRuntimeMcpStatusUpdatedEvent,
|
||||
ProviderRuntimeMcpOauthCompletedEvent,
|
||||
ProviderRuntimeModelReroutedEvent,
|
||||
ProviderRuntimeConfigWarningEvent,
|
||||
ProviderRuntimeDeprecationNoticeEvent,
|
||||
ProviderRuntimeFilesPersistedEvent,
|
||||
ProviderRuntimeWarningEvent,
|
||||
ProviderRuntimeErrorEvent,
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Schema } from "effect";
|
||||
|
||||
import { NonNegativeInt, PositiveInt } from "./baseSchemas";
|
||||
|
||||
export const ThreadTokenUsageSnapshot = Schema.Struct({
|
||||
usedTokens: NonNegativeInt,
|
||||
totalProcessedTokens: Schema.optional(NonNegativeInt),
|
||||
maxTokens: Schema.optional(PositiveInt),
|
||||
inputTokens: Schema.optional(NonNegativeInt),
|
||||
cachedInputTokens: Schema.optional(NonNegativeInt),
|
||||
outputTokens: Schema.optional(NonNegativeInt),
|
||||
reasoningOutputTokens: Schema.optional(NonNegativeInt),
|
||||
lastUsedTokens: Schema.optional(NonNegativeInt),
|
||||
lastInputTokens: Schema.optional(NonNegativeInt),
|
||||
lastCachedInputTokens: Schema.optional(NonNegativeInt),
|
||||
lastOutputTokens: Schema.optional(NonNegativeInt),
|
||||
lastReasoningOutputTokens: Schema.optional(NonNegativeInt),
|
||||
toolUses: Schema.optional(NonNegativeInt),
|
||||
durationMs: Schema.optional(NonNegativeInt),
|
||||
compactsAutomatically: Schema.optional(Schema.Boolean),
|
||||
});
|
||||
export type ThreadTokenUsageSnapshot = typeof ThreadTokenUsageSnapshot.Type;
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Schema } from "effect";
|
||||
|
||||
import { NonNegativeInt, TrimmedNonEmptyString } from "./baseSchemas";
|
||||
import { CanonicalJsonObjectSchema, CanonicalJsonValueSchema } from "./jsonValue";
|
||||
|
||||
export const CommandExecutionToolLifecycleData = Schema.Struct({
|
||||
kind: Schema.Literal("command_execution"),
|
||||
command: TrimmedNonEmptyString,
|
||||
toolName: Schema.optional(TrimmedNonEmptyString),
|
||||
input: Schema.optional(CanonicalJsonObjectSchema),
|
||||
output: Schema.optional(Schema.String),
|
||||
exitCode: Schema.optional(NonNegativeInt),
|
||||
result: Schema.optional(CanonicalJsonValueSchema),
|
||||
});
|
||||
export type CommandExecutionToolLifecycleData = typeof CommandExecutionToolLifecycleData.Type;
|
||||
|
||||
export const FileChangeToolLifecycleData = Schema.Struct({
|
||||
kind: Schema.Literal("file_change"),
|
||||
changedFiles: Schema.Array(TrimmedNonEmptyString),
|
||||
toolName: Schema.optional(TrimmedNonEmptyString),
|
||||
input: Schema.optional(CanonicalJsonObjectSchema),
|
||||
result: Schema.optional(CanonicalJsonValueSchema),
|
||||
});
|
||||
export type FileChangeToolLifecycleData = typeof FileChangeToolLifecycleData.Type;
|
||||
|
||||
export const GenericToolLifecycleData = Schema.Struct({
|
||||
kind: Schema.Literal("generic"),
|
||||
toolName: Schema.optional(TrimmedNonEmptyString),
|
||||
input: Schema.optional(CanonicalJsonObjectSchema),
|
||||
result: Schema.optional(CanonicalJsonValueSchema),
|
||||
});
|
||||
export type GenericToolLifecycleData = typeof GenericToolLifecycleData.Type;
|
||||
|
||||
export const CanonicalToolLifecycleData = Schema.Union([
|
||||
CommandExecutionToolLifecycleData,
|
||||
FileChangeToolLifecycleData,
|
||||
GenericToolLifecycleData,
|
||||
]);
|
||||
export type CanonicalToolLifecycleData = typeof CanonicalToolLifecycleData.Type;
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Effect, Schema } from "effect";
|
||||
|
||||
import { TrimmedNonEmptyString } from "./baseSchemas";
|
||||
|
||||
export const UserInputQuestionOption = Schema.Struct({
|
||||
label: TrimmedNonEmptyString,
|
||||
description: TrimmedNonEmptyString,
|
||||
});
|
||||
export type UserInputQuestionOption = typeof UserInputQuestionOption.Type;
|
||||
|
||||
export const UserInputQuestion = Schema.Struct({
|
||||
id: TrimmedNonEmptyString,
|
||||
header: TrimmedNonEmptyString,
|
||||
question: TrimmedNonEmptyString,
|
||||
options: Schema.Array(UserInputQuestionOption),
|
||||
multiSelect: Schema.optional(Schema.Boolean).pipe(
|
||||
Schema.withConstructorDefault(Effect.succeed(false)),
|
||||
),
|
||||
});
|
||||
export type UserInputQuestion = typeof UserInputQuestion.Type;
|
||||
|
||||
export const ProviderUserInputAnswer = Schema.Union([
|
||||
TrimmedNonEmptyString,
|
||||
Schema.Array(TrimmedNonEmptyString),
|
||||
]);
|
||||
export type ProviderUserInputAnswer = typeof ProviderUserInputAnswer.Type;
|
||||
|
||||
export const ProviderUserInputAnswers = Schema.Record(Schema.String, ProviderUserInputAnswer);
|
||||
export type ProviderUserInputAnswers = typeof ProviderUserInputAnswers.Type;
|
||||
Reference in new issue
Block a user