@@ -9,7 +9,7 @@ import { z, type ZodTypeAny } from "zod";
99
1010declare const process : { argv : string [ ] ; exitCode ?: number } ;
1111
12- export type StructuredSchemaName = "python_script " | "shell_command " ;
12+ export type StructuredSchemaName = "refund_intake " | "technical_support " ;
1313
1414export type StructuredSchema = {
1515 name : StructuredSchemaName ;
@@ -27,30 +27,35 @@ export type GenerateObjectLike<TObject> = (
2727 request : GenerateObjectRequest
2828) => Promise < { object : TObject } > ;
2929
30- const PYTHON_SCRIPT_SCHEMA = z . object ( {
31- code : z . string ( ) . describe ( "A complete Python script." )
30+ const REFUND_INTAKE_SCHEMA = z . object ( {
31+ kind : z . literal ( "refund" ) ,
32+ customerId : z . string ( ) . describe ( "Customer identifier for the refund request." ) ,
33+ orderId : z . string ( ) . describe ( "Order identifier for the refund request." ) ,
34+ reason : z . string ( ) . describe ( "Customer reason for requesting the refund." )
3235} ) ;
3336
34- const SHELL_COMMAND_SCHEMA = z . object ( {
35- command : z . string ( ) . describe ( "A single shell command." )
37+ const TECHNICAL_SUPPORT_SCHEMA = z . object ( {
38+ kind : z . literal ( "technical_support" ) ,
39+ customerId : z . string ( ) . describe ( "Customer identifier for the support request." ) ,
40+ issue : z . string ( ) . describe ( "Customer issue that needs technical support." )
3641} ) ;
3742
3843const SCHEMA_REGISTRY : Record < StructuredSchemaName , StructuredSchema > = {
39- python_script : {
40- name : "python_script " ,
41- description : "Generate a Python script object." ,
42- schema : PYTHON_SCRIPT_SCHEMA
44+ refund_intake : {
45+ name : "refund_intake " ,
46+ description : "Generate a refund intake object." ,
47+ schema : REFUND_INTAKE_SCHEMA
4348 } ,
44- shell_command : {
45- name : "shell_command " ,
46- description : "Generate a shell command object." ,
47- schema : SHELL_COMMAND_SCHEMA
49+ technical_support : {
50+ name : "technical_support " ,
51+ description : "Generate a technical support intake object." ,
52+ schema : TECHNICAL_SUPPORT_SCHEMA
4853 }
4954} ;
5055
5156const KNOWN_SCHEMAS : readonly StructuredSchemaName [ ] = [
52- "python_script " ,
53- "shell_command "
57+ "refund_intake " ,
58+ "technical_support "
5459] ;
5560
5661export function selectStructuredSchemasFromState (
@@ -109,19 +114,32 @@ export async function generateStructuredObject<TObject>(
109114export async function runExample ( ) : Promise < {
110115 availableSchemaNames : StructuredSchemaName [ ] ;
111116 requestBuilt : boolean ;
112- object : { code : string } | null ;
117+ object : {
118+ kind : "refund" ;
119+ customerId : string ;
120+ orderId : string ;
121+ reason : string ;
122+ } | null ;
113123} > {
114124 const engine = createEngine ( ) ;
115- engine . step ( "use python_script " ) ;
116- engine . step ( "prohibit shell_command " ) ;
125+ engine . step ( "use refund_intake " ) ;
126+ engine . step ( "prohibit technical_support " ) ;
117127
118128 const availableSchemas = selectStructuredSchemasFromState ( engine . state ) ;
119- const generated = await generateStructuredObject < { code : string } > (
129+ const generated = await generateStructuredObject < {
130+ kind : "refund" ;
131+ customerId : string ;
132+ orderId : string ;
133+ reason : string ;
134+ } > (
120135 engine . state ,
121- "Write a short Python script that prints hello ." ,
136+ "Customer customer-123 says: I need a refund for order A-100 ." ,
122137 async ( request ) => ( {
123138 object : {
124- code : `# schema=${ request . schemaName } \nprint("hello")`
139+ kind : "refund" ,
140+ customerId : "customer-123" ,
141+ orderId : "A-100" ,
142+ reason : `Selected schema: ${ request . schemaName } `
125143 }
126144 } )
127145 ) ;
0 commit comments