Last active
May 8, 2026 12:22
-
-
Save subomi/d9effad7018ce830d76041ff6ddb413d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { types } from "@acme/types-runtime" | |
| import { openai } from "@acme/agent-sdk" | |
| // step 1. | |
| // retrieve a temporary typed sdk for the intent. | |
| const sdk = await types.search({ | |
| intent: "find unpaid enterprise invoices older than 30 days" | |
| }) | |
| console.log(sdk.code) | |
| /* | |
| export interface Invoice { | |
| id: string | |
| customerId: string | |
| status: "paid" | "unpaid" | |
| dueDate: Date | |
| amount: number | |
| } | |
| export interface Customer { | |
| id: string | |
| plan: "free" | "pro" | "enterprise" | |
| } | |
| export interface InvoiceWithCustomer extends Invoice { | |
| customer: Customer | |
| } | |
| /** | |
| * Indexed on: | |
| * - status | |
| * - dueDate | |
| */ | |
| export declare function queryInvoices(input: { | |
| where?: { | |
| status?: Invoice["status"] | |
| dueDate?: { | |
| lt?: Date | |
| gt?: Date | |
| } | |
| } | |
| include?: Array<"customer"> | |
| }): Promise<InvoiceWithCustomer[]> | |
| /** | |
| * Runtime capability metadata | |
| */ | |
| export declare const capabilities: { | |
| queryInvoices: { | |
| auth: ["billing.read"] | |
| mutations: false | |
| estimatedCost: "low" | |
| } | |
| } | |
| */ | |
| // step 2. | |
| // give the returned sdk directly to the model. | |
| // | |
| // the model now codes against a real typed environment | |
| // instead of hallucinating tools. | |
| const generated = await openai.generate({ | |
| model: "gpt-5.5", | |
| system: ` | |
| Generate executable TypeScript. | |
| Rules: | |
| - Only use exported APIs | |
| - Respect type constraints | |
| - Do not invent functions | |
| - Prefer indexed filters | |
| `, | |
| context: sdk.code, | |
| input: ` | |
| Find unpaid enterprise invoices older than 30 days. | |
| Return: | |
| - invoice id | |
| - customer id | |
| - amount | |
| - due date | |
| ` | |
| }) | |
| console.log(generated.code) | |
| /* | |
| const invoices = await queryInvoices({ | |
| where: { | |
| status: "unpaid", | |
| dueDate: { | |
| lt: subDays(new Date(), 30) | |
| } | |
| }, | |
| include: ["customer"] | |
| }) | |
| return invoices | |
| .filter(invoice => | |
| invoice.customer.plan === "enterprise" | |
| ) | |
| .map(invoice => ({ | |
| invoiceId: invoice.id, | |
| customerId: invoice.customerId, | |
| amount: invoice.amount, | |
| dueDate: invoice.dueDate | |
| })) | |
| */ | |
| // step 3. | |
| // execute inside a constrained runtime. | |
| // | |
| // the runtime already understands: | |
| // - capabilities | |
| // - auth | |
| // - side effects | |
| // - policies | |
| // - execution lineage | |
| const result = await types.execute({ | |
| code: generated.code, | |
| auth: { | |
| accessToken: process.env.ACCESS_TOKEN | |
| }, | |
| policies: { | |
| network: "deny", | |
| filesystem: "deny", | |
| mutations: "deny" | |
| } | |
| }) | |
| console.log(result) | |
| /* | |
| { | |
| data: [ | |
| { | |
| invoiceId: "inv_123", | |
| customerId: "cus_456", | |
| amount: 120000, | |
| dueDate: "2026-03-01" | |
| } | |
| ], | |
| execution: { | |
| capabilitiesUsed: [ | |
| "queryInvoices" | |
| ], | |
| durationMs: 82, | |
| rowsScanned: 1842 | |
| } | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment