MCPcopy Create free account
hub / github.com/apache/maka / normalizeShellRunRecord

Function normalizeShellRunRecord

packages/core/src/shell-run.ts:326–369  ·  view source on GitHub ↗
(
  value: unknown,
  sessionId: string,
  shellRunId: string,
)

Source from the content-addressed store, hash-verified

324}
325
326export function normalizeShellRunRecord(
327 value: unknown,
328 sessionId: string,
329 shellRunId: string,
330): ShellRunRecord {
331 if (!value || typeof value !== 'object' || Array.isArray(value)) {
332 throw new Error(`Invalid ShellRun record for ${shellRunId}: expected an object`);
333 }
334 const record = value as Partial<ShellRunRecord>;
335 const requiredStrings = [
336 record.shellRunId,
337 record.sessionId,
338 record.sourceTurnId,
339 record.sourceToolCallId,
340 record.cwd,
341 record.command,
342 ];
343 const optionalStrings = [record.sourceRunId, record.failureMessage];
344 const valid =
345 hasOnlyKeys(record, SHELL_RUN_RECORD_KEYS) &&
346 requiredStrings.every((item) => typeof item === 'string') &&
347 isShellRunSourceToolCallId(record.sourceToolCallId) &&
348 record.sessionId === sessionId &&
349 record.shellRunId === shellRunId &&
350 isShellRunStatus(record.status) &&
351 isFiniteNumber(record.startedAt) &&
352 isFiniteNumber(record.updatedAt) &&
353 isPositiveInteger(record.revision) &&
354 isShellOutput(record.output) &&
355 (record.completedAt === undefined || isFiniteNumber(record.completedAt)) &&
356 (record.timeoutMs === undefined || isFiniteNumber(record.timeoutMs)) &&
357 (record.exitCode === undefined || isFiniteNumber(record.exitCode)) &&
358 (record.observedAt === undefined || isFiniteNumber(record.observedAt)) &&
359 isShellRunSandboxExecution(record.sandboxExecution) &&
360 isShellRunSandboxEscalation(record.sandboxEscalation, record.sandboxExecution) &&
361 optionalStrings.every((item) => item === undefined || typeof item === 'string');
362 if (!valid) {
363 throw new Error(`Invalid ShellRun record for ${shellRunId}: malformed fields`);
364 }
365 if (!isValidShellRunState(record)) {
366 throw new Error(`Invalid ShellRun record for ${shellRunId}: inconsistent state fields`);
367 }
368 return canonicalShellRunRecord(record as ShellRunRecord);
369}
370
371export function assertShellRunPatch(patch: ShellRunPatch): void {
372 for (const key of Object.keys(patch)) {

Callers 4

createShellRunMethod · 0.90
listSessionShellRunsMethod · 0.90
readSqliteShellRunFunction · 0.90
nextShellRunRecordFunction · 0.85

Calls 10

isShellRunStatusFunction · 0.85
isShellOutputFunction · 0.85
isValidShellRunStateFunction · 0.85
canonicalShellRunRecordFunction · 0.85
hasOnlyKeysFunction · 0.70
isFiniteNumberFunction · 0.70
isPositiveIntegerFunction · 0.70

Tested by

no test coverage detected