Skip to content

Commit 406323d

Browse files
committed
Fix exports
1 parent 193e73c commit 406323d

File tree

4 files changed

+157
-24
lines changed

4 files changed

+157
-24
lines changed

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"types": "dist/index.d.ts",
77
"type": "module",
88
"scripts": {
9-
"build": "tsup src/index.ts --format esm --dts",
10-
"dev": "tsup src/index.ts --format esm --dts --watch",
9+
"build": "tsup src/index.ts src/utils.ts --format esm --dts",
10+
"dev": "tsup src/index.ts src/utils.ts --format esm --dts --watch",
1111
"typecheck": "tsc --noEmit",
1212
"test": "vitest run",
1313
"test:watch": "vitest"
@@ -32,7 +32,7 @@
3232
"dependencies": {
3333
"@mastra/core": "^0.24.0",
3434
"@mastra/libsql": "^0.16.0",
35-
"@opencode-ai/plugin": "^1.0.146",
35+
"@opencode-ai/plugin": "^1.0.147",
3636
"strip-json-comments": "^5.0.3",
3737
"zod": "^3.25.0"
3838
},
@@ -58,6 +58,10 @@
5858
".": {
5959
"import": "./dist/index.js",
6060
"types": "./dist/index.d.ts"
61+
},
62+
"./utils": {
63+
"import": "./dist/utils.js",
64+
"types": "./dist/utils.d.ts"
6165
}
6266
}
6367
}

src/index.ts

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,49 @@ Modes:
304304
// Also export as default for backwards compatibility
305305
export default WorkflowPlugin;
306306

307-
// Re-export types for consumers
308-
export * from "./types.js";
309-
export { loadWorkflows, createLogger } from "./loader/index.js";
310-
export { WorkflowFactory } from "./factory/index.js";
311-
export { WorkflowRunner, handleWorkflowCommand, WorkflowStorage } from "./commands/index.js";
312-
export {
313-
WorkflowToolSchema,
314-
executeWorkflowTool,
315-
getWorkflowToolDefinition,
316-
type WorkflowToolInput,
317-
} from "./tools/index.js";
307+
// IMPORTANT: Only export the plugin function from the main entry point.
308+
// OpenCode's plugin loader iterates over ALL exports and tries to call each
309+
// one as a function. Exporting objects, classes, or Zod schemas here will
310+
// cause runtime errors like "fn3 is not a function".
311+
//
312+
// For utility exports (types, classes, functions), consumers should import
313+
// from the /utils subpath:
314+
// import { WorkflowFactory, loadWorkflows } from "opencode-workflows/utils"
315+
//
316+
// TypeScript types are safe to export since they're erased at runtime.
317+
export type {
318+
JsonPrimitive,
319+
JsonValue,
320+
JsonObject,
321+
InputValue,
322+
WorkflowInputs,
323+
WorkflowPluginConfig,
324+
StepType,
325+
HttpMethod,
326+
FileAction,
327+
BaseStepDefinition,
328+
ShellStepDefinition,
329+
ToolStepDefinition,
330+
AgentStepDefinition,
331+
SuspendStepDefinition,
332+
HttpStepDefinition,
333+
FileStepDefinition,
334+
StepDefinition,
335+
WorkflowDefinition,
336+
WorkflowRunStatus,
337+
ShellStepOutput,
338+
ToolStepOutput,
339+
AgentStepOutput,
340+
SuspendStepOutput,
341+
HttpStepOutput,
342+
FileStepOutput,
343+
StepOutput,
344+
StepResult,
345+
WorkflowRun,
346+
StepExecutionContext,
347+
OpencodeClient,
348+
ShellExecutor,
349+
Logger,
350+
WorkflowEventPayload,
351+
WorkflowRegistry,
352+
} from "./types.js";

src/utils.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* Utility exports for opencode-workflows
3+
*
4+
* This module provides utility functions, classes, and constants that can be
5+
* used by consumers who need programmatic access to workflow functionality.
6+
*
7+
* Import from "opencode-workflows/utils" to access these exports.
8+
*
9+
* @example
10+
* ```ts
11+
* import { WorkflowFactory, loadWorkflows } from "opencode-workflows/utils"
12+
* ```
13+
*/
14+
15+
// Configuration
16+
export { DEFAULT_CONFIG } from "./types.js";
17+
18+
// Loader utilities
19+
export { loadWorkflows, createLogger, topologicalSort } from "./loader/index.js";
20+
21+
// Factory
22+
export { WorkflowFactory, createWorkflowFromDefinition } from "./factory/index.js";
23+
24+
// Commands and runner
25+
export {
26+
WorkflowRunner,
27+
handleWorkflowCommand,
28+
type WorkflowCommandContext,
29+
type WorkflowCommandResult,
30+
type WorkflowRunnerConfig,
31+
} from "./commands/index.js";
32+
33+
// Storage
34+
export { WorkflowStorage, type StorageConfig } from "./storage/index.js";
35+
36+
// Tool utilities
37+
export {
38+
WorkflowToolSchema,
39+
executeWorkflowTool,
40+
getWorkflowToolDefinition,
41+
type WorkflowToolInput,
42+
type WorkflowToolResult,
43+
} from "./tools/index.js";
44+
45+
// Re-export all types
46+
export type {
47+
JsonPrimitive,
48+
JsonValue,
49+
JsonObject,
50+
InputValue,
51+
WorkflowInputs,
52+
WorkflowPluginConfig,
53+
StepType,
54+
HttpMethod,
55+
FileAction,
56+
BaseStepDefinition,
57+
ShellStepDefinition,
58+
ToolStepDefinition,
59+
AgentStepDefinition,
60+
SuspendStepDefinition,
61+
HttpStepDefinition,
62+
FileStepDefinition,
63+
StepDefinition,
64+
WorkflowDefinition,
65+
WorkflowRunStatus,
66+
ShellStepOutput,
67+
ToolStepOutput,
68+
AgentStepOutput,
69+
SuspendStepOutput,
70+
HttpStepOutput,
71+
FileStepOutput,
72+
StepOutput,
73+
StepResult,
74+
WorkflowRun,
75+
StepExecutionContext,
76+
OpencodeClient,
77+
ShellExecutor,
78+
Logger,
79+
WorkflowEventPayload,
80+
WorkflowRegistry,
81+
} from "./types.js";
82+
83+
// Zod schemas for validation (consumers may want to validate workflow definitions)
84+
export {
85+
BaseStepSchema,
86+
ShellStepSchema,
87+
ToolStepSchema,
88+
AgentStepSchema,
89+
SuspendStepSchema,
90+
HttpStepSchema,
91+
FileStepSchema,
92+
StepSchema,
93+
WorkflowDefinitionSchema,
94+
} from "./types.js";

0 commit comments

Comments
 (0)