a222db6f2d
- Add missing agent deps to template package.json so bun workspace
resolution works during `bun build` (workflow-agent-cursor for develop,
workflow-agent-hermes + workflow-execute for solve-issue)
- Create scripts/build-bundles.sh that builds both template bundles into
dist/*.esm.js with correct --external flags for runtime-symlinked packages
- Add build:bundles script to root package.json
- Extend ensureUncagedWorkflowSymlink to also symlink workflow-util,
workflow-execute, and workflow-register (needed by externalized bundles)
- Defer agent creation in develop bundle-entry.ts via lazy init so
requireEnv('WORKFLOW_LLM_API_KEY') only throws at first invocation,
not at import() time (fixes workflowAsAgent crash)
- Document that env vars must be set before the first worker spawn
(workers are persistent and don't inherit later env changes)
Fixes #206
Co-authored-by: Cursor <cursoragent@cursor.com>
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
/**
|
|
* develop bundle entry — 小橘 🍊
|
|
*
|
|
* All roles use cursor-agent with workspace auto-extracted from context.
|
|
*
|
|
* ENV VARS: WORKFLOW_LLM_API_KEY (required), WORKFLOW_LLM_BASE_URL,
|
|
* WORKFLOW_LLM_MODEL, WORKFLOW_CURSOR_MODEL, WORKFLOW_CURSOR_TIMEOUT.
|
|
* Must be set before the first worker spawn — workers are persistent and
|
|
* do not pick up env changes after initial import.
|
|
*/
|
|
import { createCursorAgent } from "@uncaged/workflow-agent-cursor";
|
|
import type { AgentContext, AgentFn, AgentFnResult } from "@uncaged/workflow-runtime";
|
|
import { createWorkflow } from "@uncaged/workflow-runtime";
|
|
import { buildDevelopDescriptor, developWorkflowDefinition } from "./src/index.js";
|
|
|
|
function optionalEnv(name: string): string | null {
|
|
const value = process.env[name];
|
|
if (value === undefined || value === "") {
|
|
return null;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
function requireEnv(name: string): string {
|
|
const value = process.env[name];
|
|
if (value === undefined || value === "") {
|
|
throw new Error(`missing required env var: ${name}`);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
function createLazyAgent(): AgentFn {
|
|
let cached: AgentFn | null = null;
|
|
return (ctx: AgentContext): Promise<AgentFnResult> => {
|
|
if (cached === null) {
|
|
const llmProvider = {
|
|
baseUrl:
|
|
optionalEnv("WORKFLOW_LLM_BASE_URL") ??
|
|
"https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
apiKey: requireEnv("WORKFLOW_LLM_API_KEY"),
|
|
model: optionalEnv("WORKFLOW_LLM_MODEL") ?? "qwen-plus",
|
|
};
|
|
cached = createCursorAgent({
|
|
model: optionalEnv("WORKFLOW_CURSOR_MODEL"),
|
|
timeout: optionalEnv("WORKFLOW_CURSOR_TIMEOUT")
|
|
? Number(optionalEnv("WORKFLOW_CURSOR_TIMEOUT"))
|
|
: 0,
|
|
workspace: null,
|
|
llmProvider,
|
|
});
|
|
}
|
|
return cached(ctx);
|
|
};
|
|
}
|
|
|
|
const wf = createWorkflow(developWorkflowDefinition, { agent: createLazyAgent(), overrides: null });
|
|
|
|
export const descriptor = buildDevelopDescriptor();
|
|
export const run = wf;
|