Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .server-changes/test-page-sidebar-tabs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
area: webapp
type: feature
---

Add sidebar tabs (Options, AI, Schema) to the Test page for schemaTask payload generation and schema viewing.
22 changes: 22 additions & 0 deletions apps/webapp/app/presenters/v3/TestTaskPresenter.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
type TaskRunTemplate,
PrismaClientOrTransaction,
} from "@trigger.dev/database";
import { inferSchema } from "@jsonhero/schema-infer";
import parse from "parse-duration";
import { type PrismaClient } from "~/db.server";
import { RunsRepository } from "~/services/runsRepository/runsRepository.server";
Expand Down Expand Up @@ -34,6 +35,8 @@ type Task = {
taskIdentifier: string;
filePath: string;
friendlyId: string;
payloadSchema?: unknown;
inferredPayloadSchema?: unknown;
};

type Queue = {
Expand Down Expand Up @@ -244,11 +247,30 @@ export class TestTaskPresenter {
},
});

// Infer schema from existing run payloads when no explicit schema is defined
let inferredPayloadSchema: unknown | undefined;
if (!task.payloadSchema && latestRuns.length > 0 && task.triggerSource === "STANDARD") {
let inference: ReturnType<typeof inferSchema> | undefined;
for (const run of latestRuns) {
try {
const parsed = await parsePacket({ data: run.payload, dataType: run.payloadType });
inference = inferSchema(parsed, inference);
} catch {
// Skip malformed runs — inference is best-effort
}
}
if (inference) {
inferredPayloadSchema = inference.toJSONSchema();
}
}

const taskWithEnvironment = {
id: task.id,
taskIdentifier: task.slug,
filePath: task.filePath,
friendlyId: task.friendlyId,
payloadSchema: task.payloadSchema ?? undefined,
inferredPayloadSchema,
};

switch (task.triggerSource) {
Expand Down
Loading