@@ -10,8 +10,11 @@ import {
1010} from "@trigger.dev/core/v3" ;
1111import { tracer } from "./tracer.js" ;
1212
13- type PromptOptions < TVariables extends TaskSchema | undefined = undefined > = {
14- id : string ;
13+ type PromptOptions <
14+ TIdentifier extends string = string ,
15+ TVariables extends TaskSchema | undefined = undefined ,
16+ > = {
17+ id : TIdentifier ;
1518 description ?: string ;
1619 model ?: string ;
1720 config ?: Record < string , unknown > ;
@@ -37,14 +40,30 @@ type ResolvedPrompt = {
3740
3841export type { PromptOptions , ResolvedPrompt } ;
3942
40- export type PromptHandle < TVariables extends TaskSchema | undefined = undefined > = {
41- id : string ;
43+ export type PromptHandle <
44+ TIdentifier extends string = string ,
45+ TVariables extends TaskSchema | undefined = undefined ,
46+ > = {
47+ id : TIdentifier ;
4248 resolve (
4349 variables : inferSchemaIn < TVariables > ,
4450 options ?: { label ?: string ; version ?: number }
4551 ) : Promise < ResolvedPrompt > ;
4652} ;
4753
54+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
55+ export type AnyPromptHandle = PromptHandle < string , any > ;
56+
57+ /** Extract the identifier (id literal type) from a PromptHandle */
58+ export type PromptIdentifier < T extends AnyPromptHandle > = T extends PromptHandle < infer TId , any >
59+ ? TId
60+ : string ;
61+
62+ /** Extract the variables input type from a PromptHandle */
63+ export type PromptVariables < T extends AnyPromptHandle > = T extends PromptHandle < any , infer TVariables >
64+ ? inferSchemaIn < TVariables >
65+ : Record < string , unknown > ;
66+
4867/**
4968 * Compile a Mustache-style template by substituting `{{variable}}` placeholders.
5069 */
@@ -101,7 +120,7 @@ function makeToAISDKTelemetry(
101120}
102121
103122function resolveLocally (
104- options : PromptOptions < any > ,
123+ options : PromptOptions < any , any > ,
105124 variables : Record < string , unknown >
106125) : ResolvedPrompt {
107126 const inputJson = Object . keys ( variables ) . length > 0 ? JSON . stringify ( variables ) : undefined ;
@@ -118,9 +137,12 @@ function resolveLocally(
118137 } ;
119138}
120139
121- export function definePrompt < TVariables extends TaskSchema | undefined = undefined > (
122- options : PromptOptions < TVariables >
123- ) : PromptHandle < TVariables > {
140+ export function definePrompt <
141+ TIdentifier extends string ,
142+ TVariables extends TaskSchema | undefined = undefined ,
143+ > (
144+ options : PromptOptions < TIdentifier , TVariables >
145+ ) : PromptHandle < TIdentifier , TVariables > {
124146 const parseVariables = options . variables
125147 ? getSchemaParseFn ( options . variables )
126148 : undefined ;
0 commit comments