Normalize tool lifecycle payloads
- Canonicalize provider runtime tool data and usage snapshots - Update work log extraction and user input contracts for the new schema - Add coverage for the revised lifecycle and ingestion shapes
This commit is contained in:
1 parent
ca41079cd9
commit
b6a5321043
15 files changed
+546
-243
No files matched your search
@@ -1836,7 +1836,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,
|
||||
@@ -102,6 +103,16 @@ function asString(value: unknown): string | undefined {
|
||||
return typeof value === "string" ? value : undefined;
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -283,7 +294,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,
|
||||
@@ -433,7 +446,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,
|
||||
|
||||
@@ -923,12 +923,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",
|
||||
@@ -940,17 +941,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",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
type CanonicalItemType,
|
||||
type CanonicalToolLifecycleData,
|
||||
type CanonicalRequestType,
|
||||
EventId,
|
||||
type ProviderApprovalDecision,
|
||||
@@ -739,6 +740,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);
|
||||
@@ -1416,8 +1527,7 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
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 }
|
||||
: {}),
|
||||
@@ -1443,10 +1553,19 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
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: {
|
||||
@@ -1500,8 +1619,7 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
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 }
|
||||
: {}),
|
||||
@@ -1639,10 +1757,19 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
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: {
|
||||
@@ -1708,10 +1835,19 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
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: {
|
||||
@@ -1764,11 +1900,12 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
|
||||
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({
|
||||
@@ -1784,7 +1921,7 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
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: {
|
||||
@@ -1832,7 +1969,7 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
status: itemStatus,
|
||||
title: tool.title,
|
||||
...(tool.detail ? { detail: tool.detail } : {}),
|
||||
data: toolData,
|
||||
...(toolData ? { data: toolData } : {}),
|
||||
},
|
||||
providerRefs: nativeProviderRefs(context, { providerItemId: tool.itemId }),
|
||||
raw: {
|
||||
@@ -2011,25 +2148,22 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
},
|
||||
});
|
||||
return;
|
||||
case "task_progress":
|
||||
if (message.usage) {
|
||||
const normalizedUsage = normalizeClaudeTokenUsage(
|
||||
message.usage,
|
||||
context.lastKnownContextWindow,
|
||||
);
|
||||
if (normalizedUsage) {
|
||||
context.lastKnownTokenUsage = normalizedUsage;
|
||||
const usageStamp = yield* makeEventStamp();
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
eventId: usageStamp.eventId,
|
||||
createdAt: usageStamp.createdAt,
|
||||
type: "thread.token-usage.updated",
|
||||
payload: {
|
||||
usage: normalizedUsage,
|
||||
},
|
||||
});
|
||||
}
|
||||
case "task_progress": {
|
||||
const normalizedUsage = message.usage
|
||||
? normalizeClaudeTokenUsage(message.usage, context.lastKnownContextWindow)
|
||||
: undefined;
|
||||
if (normalizedUsage) {
|
||||
context.lastKnownTokenUsage = normalizedUsage;
|
||||
const usageStamp = yield* makeEventStamp();
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
eventId: usageStamp.eventId,
|
||||
createdAt: usageStamp.createdAt,
|
||||
type: "thread.token-usage.updated",
|
||||
payload: {
|
||||
usage: normalizedUsage,
|
||||
},
|
||||
});
|
||||
}
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
@@ -2038,30 +2172,28 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
taskId: RuntimeTaskId.makeUnsafe(message.task_id),
|
||||
description: message.description,
|
||||
...(message.summary ? { summary: message.summary } : {}),
|
||||
...(message.usage ? { usage: message.usage } : {}),
|
||||
...(normalizedUsage ? { usage: normalizedUsage } : {}),
|
||||
...(message.last_tool_name ? { lastToolName: message.last_tool_name } : {}),
|
||||
},
|
||||
});
|
||||
return;
|
||||
case "task_notification":
|
||||
if (message.usage) {
|
||||
const normalizedUsage = normalizeClaudeTokenUsage(
|
||||
message.usage,
|
||||
context.lastKnownContextWindow,
|
||||
);
|
||||
if (normalizedUsage) {
|
||||
context.lastKnownTokenUsage = normalizedUsage;
|
||||
const usageStamp = yield* makeEventStamp();
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
eventId: usageStamp.eventId,
|
||||
createdAt: usageStamp.createdAt,
|
||||
type: "thread.token-usage.updated",
|
||||
payload: {
|
||||
usage: normalizedUsage,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
case "task_notification": {
|
||||
const normalizedUsage = message.usage
|
||||
? normalizeClaudeTokenUsage(message.usage, context.lastKnownContextWindow)
|
||||
: undefined;
|
||||
if (normalizedUsage) {
|
||||
context.lastKnownTokenUsage = normalizedUsage;
|
||||
const usageStamp = yield* makeEventStamp();
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
eventId: usageStamp.eventId,
|
||||
createdAt: usageStamp.createdAt,
|
||||
type: "thread.token-usage.updated",
|
||||
payload: {
|
||||
usage: normalizedUsage,
|
||||
},
|
||||
});
|
||||
}
|
||||
yield* offerRuntimeEvent({
|
||||
...base,
|
||||
@@ -2070,10 +2202,11 @@ function makeClaudeAdapter(options?: ClaudeAdapterLiveOptions) {
|
||||
taskId: RuntimeTaskId.makeUnsafe(message.task_id),
|
||||
status: message.status,
|
||||
...(message.summary ? { summary: message.summary } : {}),
|
||||
...(message.usage ? { usage: message.usage } : {}),
|
||||
...(normalizedUsage ? { usage: normalizedUsage } : {}),
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
default:
|
||||
yield* emitRuntimeWarning(
|
||||
context,
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
import {
|
||||
type CanonicalItemType,
|
||||
type CanonicalToolLifecycleData,
|
||||
type CanonicalRequestType,
|
||||
type ProviderEvent,
|
||||
type ProviderRuntimeEvent,
|
||||
@@ -111,6 +112,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;
|
||||
}
|
||||
|
||||
function normalizeCodexTokenUsage(value: unknown): ThreadTokenUsageSnapshot | undefined {
|
||||
const usage = asObject(value);
|
||||
const totalUsage = asObject(usage?.total_token_usage ?? usage?.total);
|
||||
@@ -318,27 +424,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) {
|
||||
@@ -563,7 +671,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 ?? {}) }
|
||||
: {}),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -795,8 +905,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) }
|
||||
: {}),
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
type ProjectScript,
|
||||
type ModelSlug,
|
||||
type ProviderKind,
|
||||
type ProviderUserInputAnswers,
|
||||
type ProjectEntry,
|
||||
type ProjectId,
|
||||
type ProviderApprovalDecision,
|
||||
@@ -2739,7 +2740,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
);
|
||||
|
||||
const onRespondToUserInput = useCallback(
|
||||
async (requestId: ApprovalRequestId, answers: Record<string, unknown>) => {
|
||||
async (requestId: ApprovalRequestId, answers: ProviderUserInputAnswers) => {
|
||||
const api = readNativeApi();
|
||||
if (!api || !activeThreadId) return;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { UserInputQuestion } from "@t3tools/contracts";
|
||||
import type { ProviderUserInputAnswers, UserInputQuestion } from "@t3tools/contracts";
|
||||
|
||||
export interface PendingUserInputDraftAnswer {
|
||||
selectedOptionLabel?: string;
|
||||
@@ -55,7 +55,7 @@ export function setPendingUserInputCustomAnswer(
|
||||
export function buildPendingUserInputAnswers(
|
||||
questions: ReadonlyArray<UserInputQuestion>,
|
||||
draftAnswers: Record<string, PendingUserInputDraftAnswer>,
|
||||
): Record<string, string> | null {
|
||||
): ProviderUserInputAnswers | null {
|
||||
const answers: Record<string, string> = {};
|
||||
|
||||
for (const question of questions) {
|
||||
|
||||
@@ -697,9 +697,8 @@ describe("deriveWorkLogEntries", () => {
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
data: {
|
||||
item: {
|
||||
command: ["bun", "run", "lint"],
|
||||
},
|
||||
kind: "command_execution",
|
||||
command: "bun run lint",
|
||||
},
|
||||
},
|
||||
}),
|
||||
@@ -721,12 +720,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,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -751,12 +749,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"],
|
||||
},
|
||||
},
|
||||
}),
|
||||
@@ -792,9 +786,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",
|
||||
},
|
||||
},
|
||||
}),
|
||||
@@ -819,7 +811,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",
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
type CanonicalToolLifecycleData,
|
||||
isToolLifecycleItemType,
|
||||
type OrchestrationLatestTurn,
|
||||
type OrchestrationThreadActivity,
|
||||
@@ -476,22 +477,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 command = extractToolCommand(payload);
|
||||
const changedFiles = extractChangedFiles(payload);
|
||||
const title = extractToolTitle(payload);
|
||||
const entry: DerivedWorkLogEntry = {
|
||||
id: activity.id,
|
||||
createdAt: activity.createdAt,
|
||||
@@ -499,12 +488,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 command = extractToolCommand(toolData);
|
||||
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 (command) {
|
||||
@@ -624,10 +625,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;
|
||||
@@ -650,22 +647,37 @@ function normalizeCommandValue(value: unknown): string | null {
|
||||
return parts.length > 0 ? parts.join(" ") : null;
|
||||
}
|
||||
|
||||
function extractToolCommand(payload: Record<string, unknown> | null): string | null {
|
||||
const data = asRecord(payload?.data);
|
||||
const item = asRecord(data?.item);
|
||||
const itemResult = asRecord(item?.result);
|
||||
const itemInput = asRecord(item?.input);
|
||||
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 extractToolCommand(data: CanonicalToolLifecycleData | undefined): string | null {
|
||||
if (data?.kind !== "command_execution") {
|
||||
return null;
|
||||
}
|
||||
const candidates = [
|
||||
normalizeCommandValue(item?.command),
|
||||
normalizeCommandValue(itemInput?.command),
|
||||
normalizeCommandValue(itemResult?.command),
|
||||
normalizeCommandValue(data?.command),
|
||||
normalizeCommandValue(data.command),
|
||||
normalizeCommandValue(data.input?.command),
|
||||
];
|
||||
return candidates.find((candidate) => candidate !== null) ?? 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): {
|
||||
@@ -690,28 +702,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;
|
||||
@@ -720,58 +740,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,16 @@ export * from "./ipc";
|
||||
export * from "./terminal";
|
||||
export * from "./provider";
|
||||
export * from "./providerRuntime";
|
||||
export * from "./threadUsage";
|
||||
export * from "./model";
|
||||
export * from "./ws";
|
||||
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";
|
||||
@@ -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;
|
||||
@@ -14,7 +14,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",
|
||||
@@ -79,9 +82,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;
|
||||
@@ -294,7 +294,7 @@ const RuntimeErrorActivityPayload = Schema.Struct({
|
||||
|
||||
const RuntimeWarningActivityPayload = Schema.Struct({
|
||||
message: TrimmedNonEmptyString,
|
||||
detail: Schema.optional(Schema.Unknown),
|
||||
detail: Schema.optional(CanonicalJsonValueSchema),
|
||||
});
|
||||
|
||||
const RuntimePlanStep = Schema.Struct({
|
||||
@@ -309,12 +309,12 @@ const TurnPlanUpdatedActivityPayload = Schema.Struct({
|
||||
|
||||
const UserInputRequestedActivityPayload = Schema.Struct({
|
||||
requestId: Schema.optional(TrimmedNonEmptyString),
|
||||
questions: Schema.Array(Schema.Unknown),
|
||||
questions: Schema.Array(UserInputQuestion),
|
||||
});
|
||||
|
||||
const UserInputResolvedActivityPayload = Schema.Struct({
|
||||
requestId: Schema.optional(TrimmedNonEmptyString),
|
||||
answers: Schema.Record(Schema.String, Schema.Unknown),
|
||||
answers: ProviderUserInputAnswers,
|
||||
});
|
||||
|
||||
const TaskStartedActivityPayload = Schema.Struct({
|
||||
@@ -328,19 +328,19 @@ const TaskProgressActivityPayload = Schema.Struct({
|
||||
detail: TrimmedNonEmptyString,
|
||||
summary: Schema.optional(TrimmedNonEmptyString),
|
||||
lastToolName: Schema.optional(TrimmedNonEmptyString),
|
||||
usage: Schema.optional(Schema.Unknown),
|
||||
usage: Schema.optional(ThreadTokenUsageSnapshot),
|
||||
});
|
||||
|
||||
const TaskCompletedActivityPayload = Schema.Struct({
|
||||
taskId: TrimmedNonEmptyString,
|
||||
status: TrimmedNonEmptyString,
|
||||
detail: Schema.optional(TrimmedNonEmptyString),
|
||||
usage: Schema.optional(Schema.Unknown),
|
||||
usage: Schema.optional(ThreadTokenUsageSnapshot),
|
||||
});
|
||||
|
||||
const ContextCompactionActivityPayload = Schema.Struct({
|
||||
state: Schema.Literal("compacted"),
|
||||
detail: Schema.optional(Schema.Unknown),
|
||||
detail: Schema.optional(CanonicalJsonValueSchema),
|
||||
});
|
||||
|
||||
const ToolStartedOrCompletedActivityPayload = Schema.Struct({
|
||||
@@ -352,7 +352,7 @@ const ToolUpdatedActivityPayload = Schema.Struct({
|
||||
itemType: TrimmedNonEmptyString,
|
||||
status: Schema.optional(TrimmedNonEmptyString),
|
||||
detail: Schema.optional(TrimmedNonEmptyString),
|
||||
data: Schema.optional(Schema.Unknown),
|
||||
data: Schema.optional(CanonicalToolLifecycleData),
|
||||
});
|
||||
|
||||
const CheckpointRevertFailedActivityPayload = Schema.Struct({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Option, Schema } from "effect";
|
||||
import { Schema } from "effect";
|
||||
import {
|
||||
EventId,
|
||||
IsoDateTime,
|
||||
@@ -11,11 +11,13 @@ import {
|
||||
TurnId,
|
||||
} from "./baseSchemas";
|
||||
import { ProviderKind } from "./orchestration";
|
||||
import { CanonicalToolLifecycleData } from "./toolLifecycle";
|
||||
export { ThreadTokenUsageSnapshot } from "./threadUsage";
|
||||
import { ThreadTokenUsageSnapshot as ThreadTokenUsageSnapshotSchema } 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",
|
||||
@@ -244,12 +246,12 @@ 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;
|
||||
|
||||
const ThreadTokenUsageUpdatedPayload = Schema.Struct({
|
||||
usage: ThreadTokenUsageSnapshotSchema,
|
||||
usage: ThreadTokenUsageSnapshot,
|
||||
});
|
||||
export type ThreadTokenUsageUpdatedPayload = typeof ThreadTokenUsageUpdatedPayload.Type;
|
||||
|
||||
@@ -262,8 +264,7 @@ 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),
|
||||
});
|
||||
@@ -301,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;
|
||||
|
||||
@@ -327,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(() => Option.some(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;
|
||||
|
||||
@@ -365,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;
|
||||
@@ -374,7 +358,7 @@ 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;
|
||||
|
||||
|
||||
@@ -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 { Option, 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(() => Option.some(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