Merge pull request #381 from pikasTech/fix/workbench-user-submit-clock
Pipelines as Code CI / agentrun-nc01-v02-ci-a41772776368fb2b963f39e99f8e57c31a800723 Failed
Pipelines as Code CI / agentrun-nc01-v02-ci-a41772776368fb2b963f39e99f8e57c31a800723 Failed
保留 Workbench 用户消息提交时间
This commit is contained in:
+10
-2
@@ -52,12 +52,14 @@ export function userMessagePayloadForCommand(run: RunRecord, command: CommandRec
|
||||
const text = promptBearingText(command.payload);
|
||||
if (text === null) return null;
|
||||
const targetTraceId = command.type === "steer" ? nonEmptyText(command.payload.targetTraceId) : null;
|
||||
const submittedAt = isoTimestamp(command.payload.submittedAt);
|
||||
return {
|
||||
commandId: command.id,
|
||||
traceId: agentRunBusinessTraceId(run, command),
|
||||
userMessageId: nonEmptyText(command.payload.userMessageId) ?? `msg_${command.id}_user`,
|
||||
text,
|
||||
source: command.type === "steer" ? "agentrun-steer-command-payload" : "agentrun-turn-command-payload",
|
||||
...(submittedAt ? { submittedAt } : {}),
|
||||
...(targetTraceId ? { targetTraceId } : {}),
|
||||
valuesPrinted: false,
|
||||
};
|
||||
@@ -103,16 +105,22 @@ function normalizeCommandOutputPayload(payload: JsonRecord): JsonRecord {
|
||||
}
|
||||
|
||||
function normalizeUserMessagePayload(payload: JsonRecord): JsonRecord {
|
||||
const { targetTraceId: _targetTraceId, ...rest } = payload;
|
||||
const { targetTraceId: _targetTraceId, submittedAt: _submittedAt, ...rest } = payload;
|
||||
const commandId = nonEmptyText(payload.commandId);
|
||||
const userMessageId = nonEmptyText(payload.userMessageId);
|
||||
const text = typeof payload.text === "string" && payload.text.trim().length > 0 ? redactText(payload.text) : null;
|
||||
const source = nonEmptyText(payload.source);
|
||||
const targetTraceId = nonEmptyText(payload.targetTraceId);
|
||||
const submittedAt = isoTimestamp(payload.submittedAt);
|
||||
if (!commandId || !userMessageId || text === null || !source) {
|
||||
throw new AgentRunError("schema-invalid", "user_message event requires commandId, userMessageId, non-empty text, and source", { httpStatus: 400 });
|
||||
}
|
||||
return { ...rest, commandId, userMessageId, text, source, ...(targetTraceId ? { targetTraceId } : {}), valuesPrinted: false };
|
||||
return { ...rest, commandId, userMessageId, text, source, ...(targetTraceId ? { targetTraceId } : {}), ...(submittedAt ? { submittedAt } : {}), valuesPrinted: false };
|
||||
}
|
||||
|
||||
function isoTimestamp(value: unknown): string | null {
|
||||
const timestamp = nonEmptyText(value);
|
||||
return timestamp && Number.isFinite(Date.parse(timestamp)) ? new Date(Date.parse(timestamp)).toISOString() : null;
|
||||
}
|
||||
|
||||
function promptBearingText(payload: JsonRecord): string | null {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import assert from "node:assert/strict";
|
||||
import type { CreateRunInput } from "../../common/types.js";
|
||||
import { MemoryAgentRunStore } from "../../mgr/store.js";
|
||||
import type { SelfTestCase } from "../harness.js";
|
||||
|
||||
const selfTest: SelfTestCase = () => {
|
||||
const store = new MemoryAgentRunStore();
|
||||
const run = store.createRun(runInput());
|
||||
const submittedAt = "2026-07-20T01:13:07.699Z";
|
||||
const command = store.createCommand(run.id, {
|
||||
type: "turn",
|
||||
idempotencyKey: "user-submitted-at",
|
||||
payload: {
|
||||
prompt: "hi",
|
||||
traceId: "trc_user_submitted_at",
|
||||
userMessageId: "msg_user_submitted_at",
|
||||
submittedAt,
|
||||
},
|
||||
});
|
||||
const event = store.listEvents(run.id, 0, 10)
|
||||
.find((candidate) => candidate.type === "user_message" && candidate.payload.commandId === command.id);
|
||||
|
||||
assert.equal(event?.payload.submittedAt, submittedAt);
|
||||
return { name: "user-submitted-at", tests: ["command-user-message-preserves-submitted-at"] };
|
||||
};
|
||||
|
||||
function runInput(): CreateRunInput {
|
||||
return {
|
||||
tenantId: "hwlab",
|
||||
projectId: "pikasTech/HWLAB",
|
||||
workspaceRef: { kind: "host-path", path: "/tmp/agentrun-user-submitted-at" },
|
||||
sessionRef: { sessionId: "ses_user_submitted_at", metadata: { hwlabSessionId: "ses_user_submitted_at" } },
|
||||
resourceBundleRef: null,
|
||||
providerId: "NC01",
|
||||
backendProfile: "gpt-pika",
|
||||
executionPolicy: {
|
||||
sandbox: "danger-full-access",
|
||||
approval: "never",
|
||||
timeoutMs: 60_000,
|
||||
network: "enabled",
|
||||
secretScope: { allowCredentialEcho: false, providerCredentials: [] },
|
||||
},
|
||||
traceSink: null,
|
||||
};
|
||||
}
|
||||
|
||||
export default selfTest;
|
||||
Reference in New Issue
Block a user