From b4231bcbfe559fa49b52fc3b63dd4b58905a0bda Mon Sep 17 00:00:00 2001 From: Ling-Sen Peng Date: Tue, 18 Aug 2026 15:21:46 -0700 Subject: [PATCH] fix(examples): remove broken require.main guards and their importer examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 63-deploy.ts and 63d-serve-from-package.ts guarded main() with 'require.main === module', which throws ReferenceError in ES module scope — crashing them on direct execution and, transitively, the examples importing agents from them. Delete 63c-run-by-name.ts and 63e-run-monitoring.ts (the only importers that made a main() guard necessary), invoke main() directly like every other example, and update the README references. --- examples/agents/63-deploy.ts | 12 +++---- examples/agents/63c-run-by-name.ts | 41 ----------------------- examples/agents/63d-serve-from-package.ts | 12 +++---- examples/agents/63e-run-monitoring.ts | 35 ------------------- examples/agents/README.md | 6 ++-- 5 files changed, 10 insertions(+), 96 deletions(-) delete mode 100644 examples/agents/63c-run-by-name.ts delete mode 100644 examples/agents/63e-run-monitoring.ts diff --git a/examples/agents/63-deploy.ts b/examples/agents/63-deploy.ts index aae2411d..ef7c94d3 100644 --- a/examples/agents/63-deploy.ts +++ b/examples/agents/63-deploy.ts @@ -90,11 +90,7 @@ async function main() { } } -// Guard: 63c-run-by-name.ts imports docAssistant from this file — only run -// when executed directly, not on import. -if (require.main === module) { - main().catch((err) => { - console.error(err); - process.exitCode = 1; - }); -} +main().catch((err) => { + console.error(err); + process.exitCode = 1; +}); diff --git a/examples/agents/63c-run-by-name.ts b/examples/agents/63c-run-by-name.ts deleted file mode 100644 index 97a6ae30..00000000 --- a/examples/agents/63c-run-by-name.ts +++ /dev/null @@ -1,41 +0,0 @@ -/** - * 63c - Direct Run — kept alongside the Python "run by name" variant for parity. - * - * The current TypeScript runtime accepts agent objects here, so this example - * uses the imported agent definition directly. The commented production - * pattern below shows the standalone deploy() CI/CD step; serve() alone - * (see 63b-serve.ts) deploys and starts workers in one call and is - * sufficient without it. - * - * Requirements: - * - Conductor server running - * - CONDUCTOR_SERVER_URL=http://localhost:8080/api as environment variable - * - CONDUCTOR_AGENT_LLM_MODEL=openai/gpt-4o-mini as environment variable - */ - -import { docAssistant } from './63-deploy.js'; -import { AgentRuntime } from '@io-orkes/conductor-javascript/agents'; - -async function main() { - const runtime = new AgentRuntime(); - try { - const result = await runtime.run(docAssistant, 'How do I reset my password?'); - result.printResult(); - - // Production pattern: - // 1. Deploy once during CI/CD (optional -- serve() below also deploys): - // await runtime.deploy(docAssistant); - // CLI alternative: - // agentspan deploy --package sdk/typescript/examples --agents doc_assistant - // - // 2. In a separate long-lived worker process (deploys + registers workers + starts polling): - // await runtime.serve(docAssistant); - } finally { - await runtime.shutdown(); - } -} - -main().catch((err) => { - console.error(err); - process.exitCode = 1; -}); diff --git a/examples/agents/63d-serve-from-package.ts b/examples/agents/63d-serve-from-package.ts index a9ff67ff..35db41b7 100644 --- a/examples/agents/63d-serve-from-package.ts +++ b/examples/agents/63d-serve-from-package.ts @@ -62,11 +62,7 @@ async function main() { } } -// Guard: 63e-run-monitoring.ts imports monitoringAgent from this file — only -// run when executed directly, not on import. -if (require.main === module) { - main().catch((err) => { - console.error(err); - process.exitCode = 1; - }); -} +main().catch((err) => { + console.error(err); + process.exitCode = 1; +}); diff --git a/examples/agents/63e-run-monitoring.ts b/examples/agents/63e-run-monitoring.ts deleted file mode 100644 index 1c984cb2..00000000 --- a/examples/agents/63e-run-monitoring.ts +++ /dev/null @@ -1,35 +0,0 @@ -/** - * 63e - Run Monitoring Agent — use runtime.run() and print the result. - * - * Requirements: - * - Conductor server running - * - CONDUCTOR_SERVER_URL=http://localhost:8080/api as environment variable - * - CONDUCTOR_AGENT_LLM_MODEL=openai/gpt-4o-mini as environment variable - */ - -import { monitoringAgent } from './63d-serve-from-package.js'; -import { AgentRuntime } from '@io-orkes/conductor-javascript/agents'; - -async function main() { - const runtime = new AgentRuntime(); - try { - const result = await runtime.run(monitoringAgent, 'Is everything healthy? Run a full check.'); - result.printResult(); - - // Production pattern: - // 1. Deploy once during CI/CD (optional -- serve() below also deploys): - // await runtime.deploy(monitoringAgent); - // CLI alternative: - // agentspan deploy --package sdk/typescript/examples --agents monitoring - // - // 2. In a separate long-lived worker process (deploys + registers workers + starts polling): - // await runtime.serve(monitoringAgent); - } finally { - await runtime.shutdown(); - } -} - -main().catch((err) => { - console.error(err); - process.exitCode = 1; -}); diff --git a/examples/agents/README.md b/examples/agents/README.md index f2cbf011..9c231d30 100644 --- a/examples/agents/README.md +++ b/examples/agents/README.md @@ -46,8 +46,8 @@ In production, the three concerns are separated: Every example includes the deploy/serve pattern as commented code at the bottom of its `main()` function — look for the `// Production pattern:` comment. -See [63-deploy.ts](63-deploy.ts), [63b-serve.ts](63b-serve.ts), and -[63c-run-by-name.ts](63c-run-by-name.ts) for a complete working example of this pattern. +See [63-deploy.ts](63-deploy.ts) and [63b-serve.ts](63b-serve.ts) for a complete +working example of this pattern. --- @@ -316,9 +316,7 @@ cd examples/agents/openai && npx tsx 01-basic-agent.ts | 17 | [Scheduled Agent](17-scheduled-agent.ts) | Deploy an agent on a cron schedule | | 63 | [Deploy](63-deploy.ts) | Register agent with the server | | 63b | [Serve](63b-serve.ts) | Start a long-running worker | -| 63c | [Run by Name](63c-run-by-name.ts) | Execute a pre-deployed agent | | 63d | [Serve from Package](63d-serve-from-package.ts) | Serve agents from a package | -| 63e | [Run Monitoring](63e-run-monitoring.ts) | Monitor running executions | ## End-to-End Use Cases