Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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") {
try {
let inference: ReturnType<typeof inferSchema> | undefined;
for (const run of latestRuns) {
const parsed = await parsePacket({ data: run.payload, dataType: run.payloadType });
inference = inferSchema(parsed, inference);
}
if (inference) {
inferredPayloadSchema = inference.toJSONSchema();
}
} catch {
// Ignore inference errors — it's best-effort
}
}

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