@workflow-code/cli 0.2.0 → 0.2.3-20260901001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-27OW6OJ3.js +276 -0
- package/dist/chunk-DPFPLLLT.js +66 -0
- package/dist/chunk-HZABRDJK.js +169 -0
- package/dist/chunk-NSPRIPOP.js +36 -0
- package/dist/chunk-OLNPMIEF.js +14 -0
- package/dist/chunk-PGM3IPWA.js +174 -0
- package/dist/{chunk-GFSYSMR6.js → chunk-TCYG46PO.js} +692 -484
- package/dist/index.js +19 -4
- package/dist/{local-JWDHJRIM.js → local-R4Q7NLP6.js} +52 -14
- package/dist/mcp-PNIRX64G.js +26643 -0
- package/dist/openai-responses-runner-2MPK3UAP.js +210 -0
- package/dist/openai-runner-stdio-ZQJG73I4.js +8 -0
- package/dist/{workspace-2W43PINC.js → workspace-4DAJK3ZR.js} +448 -468
- package/package.json +14 -8
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
isolateOpenAIRunnerStdout
|
|
4
|
+
} from "./chunk-OLNPMIEF.js";
|
|
5
|
+
import "./chunk-NSPRIPOP.js";
|
|
6
|
+
|
|
7
|
+
// src/openai-responses-runner.ts
|
|
8
|
+
import { readFileSync } from "fs";
|
|
9
|
+
import {
|
|
10
|
+
inspectLocalWorkflowStructure,
|
|
11
|
+
isOutputItemStreamChunk,
|
|
12
|
+
runLocalWorkflowWithReport
|
|
13
|
+
} from "workflow-code";
|
|
14
|
+
|
|
15
|
+
// .shared/openai-responses/index.ts
|
|
16
|
+
var OPENAI_RESPONSE_RETENTION_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
17
|
+
var OPENAI_EPHEMERAL_BACKGROUND_RETENTION_MS = 10 * 60 * 1e3;
|
|
18
|
+
function isOpenAIConversationHostInput(value) {
|
|
19
|
+
if (!isRecord(value) || value.kind !== "openai.responses") return false;
|
|
20
|
+
return typeof value.requestId === "string" && typeof value.responseId === "string" && typeof value.projectId === "string" && typeof value.model === "string" && Array.isArray(value.messages) && isRecord(value.settings);
|
|
21
|
+
}
|
|
22
|
+
function isRecord(value) {
|
|
23
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/openai-responses-runner.ts
|
|
27
|
+
async function main(options = {}) {
|
|
28
|
+
const writeProtocolLine = options.writeProtocolLine ?? isolateOpenAIRunnerStdout();
|
|
29
|
+
redirectConsoleToStderr();
|
|
30
|
+
const controller = createProcessAbortController();
|
|
31
|
+
return runOpenAIResponsesRunner({
|
|
32
|
+
abortSignal: controller.signal,
|
|
33
|
+
writeFrame: (frame) => writeProtocolLine(`${JSON.stringify(frame)}
|
|
34
|
+
`)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async function runOpenAIResponsesRunner(dependencies = {}) {
|
|
38
|
+
disableAiSdkWarningLogs();
|
|
39
|
+
const writeFrame = dependencies.writeFrame ?? writeRunnerFrame;
|
|
40
|
+
let request;
|
|
41
|
+
let executionReport;
|
|
42
|
+
try {
|
|
43
|
+
request = parseOpenAIInternalRunnerRequest(
|
|
44
|
+
(dependencies.readInput ?? (() => readFileSync(0, "utf8")))()
|
|
45
|
+
);
|
|
46
|
+
const inspectProject = dependencies.inspectProject ?? inspectLocalWorkflowStructure;
|
|
47
|
+
const structure = inspectProject({ workflowDir: request.projectPath });
|
|
48
|
+
const conversation = structure.conversation;
|
|
49
|
+
if (structure.projectType !== "conversation" || conversation?.openai?.enabled !== true || typeof conversation.openai.outputItemId !== "string") {
|
|
50
|
+
throw new Error("The project does not expose an OpenAI Responses adapter.");
|
|
51
|
+
}
|
|
52
|
+
const outputItemId = conversation.openai.outputItemId;
|
|
53
|
+
writeFrame({ type: "ready", executionId: request.executionId });
|
|
54
|
+
const runWorkflow = dependencies.runWorkflow ?? runLocalWorkflowWithReport;
|
|
55
|
+
executionReport = await runWorkflow({
|
|
56
|
+
workflowDir: request.projectPath,
|
|
57
|
+
runId: request.executionId,
|
|
58
|
+
hostInput: request.hostInput,
|
|
59
|
+
abortSignal: dependencies.abortSignal,
|
|
60
|
+
nodeHooks: createRunnerNodeHooks(request.executionId, outputItemId, writeFrame)
|
|
61
|
+
});
|
|
62
|
+
const report = executionReport;
|
|
63
|
+
if (dependencies.abortSignal?.aborted) {
|
|
64
|
+
writeFrame({ type: "cancelled", executionId: request.executionId, report });
|
|
65
|
+
return 130;
|
|
66
|
+
}
|
|
67
|
+
if (report.status !== "success") {
|
|
68
|
+
writeFrame({
|
|
69
|
+
type: "failed",
|
|
70
|
+
executionId: request.executionId,
|
|
71
|
+
error: { message: readReportError(report) },
|
|
72
|
+
report
|
|
73
|
+
});
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
const item = findOutputItem(report, outputItemId);
|
|
77
|
+
if (item === void 0 || typeof item.content !== "string") {
|
|
78
|
+
throw new Error(`OpenAI adapter output item "${outputItemId}" was not produced.`);
|
|
79
|
+
}
|
|
80
|
+
const metadata = isRecord2(item.metadata) ? item.metadata : {};
|
|
81
|
+
writeFrame({
|
|
82
|
+
type: "completed",
|
|
83
|
+
executionId: request.executionId,
|
|
84
|
+
outputText: item.content,
|
|
85
|
+
outputItemId,
|
|
86
|
+
usage: createOpenAIUsage(report),
|
|
87
|
+
report,
|
|
88
|
+
...typeof metadata.finishReason === "string" ? { finishReason: metadata.finishReason } : {},
|
|
89
|
+
...metadata.providerMetadata === void 0 ? {} : { providerMetadata: metadata.providerMetadata }
|
|
90
|
+
});
|
|
91
|
+
return 0;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
const executionId = request?.executionId ?? "unknown";
|
|
94
|
+
if (dependencies.abortSignal?.aborted) {
|
|
95
|
+
writeFrame({
|
|
96
|
+
type: "cancelled",
|
|
97
|
+
executionId,
|
|
98
|
+
...executionReport === void 0 ? {} : { report: executionReport }
|
|
99
|
+
});
|
|
100
|
+
return 130;
|
|
101
|
+
}
|
|
102
|
+
writeFrame({
|
|
103
|
+
type: "failed",
|
|
104
|
+
executionId,
|
|
105
|
+
error: { message: error instanceof Error ? error.message : "OpenAI runner failed." },
|
|
106
|
+
...executionReport === void 0 ? {} : { report: executionReport }
|
|
107
|
+
});
|
|
108
|
+
return 1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function parseOpenAIInternalRunnerRequest(source) {
|
|
112
|
+
const value = JSON.parse(source);
|
|
113
|
+
if (!isRecord2(value)) throw new Error("Runner request must be a JSON object.");
|
|
114
|
+
if (value.protocolVersion !== 1 || value.action !== "run") {
|
|
115
|
+
throw new Error("Unsupported OpenAI runner protocol version or action.");
|
|
116
|
+
}
|
|
117
|
+
if (typeof value.executionId !== "string" || value.executionId.trim() === "" || typeof value.projectPath !== "string" || value.projectPath.trim() === "" || !isOpenAIConversationHostInput(value.hostInput)) {
|
|
118
|
+
throw new Error("OpenAI runner request is invalid.");
|
|
119
|
+
}
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
function createRunnerNodeHooks(executionId, outputItemId, writeFrame) {
|
|
123
|
+
return {
|
|
124
|
+
onNodeChunk(event) {
|
|
125
|
+
if (!isOutputItemStreamChunk(event.chunk)) return;
|
|
126
|
+
if (event.chunk.type !== "output_item_delta" || event.chunk.itemId !== outputItemId) return;
|
|
127
|
+
if (typeof event.chunk.delta !== "string" || event.chunk.delta === "") return;
|
|
128
|
+
writeFrame({ type: "text-delta", executionId, delta: event.chunk.delta });
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function createOpenAIUsage(report) {
|
|
133
|
+
const usage = report.tokenUsage?.run;
|
|
134
|
+
return {
|
|
135
|
+
input_tokens: usage?.inputTokens ?? 0,
|
|
136
|
+
input_tokens_details: { cached_tokens: usage?.cachedInputTokens ?? 0 },
|
|
137
|
+
output_tokens: usage?.outputTokens ?? 0,
|
|
138
|
+
output_tokens_details: { reasoning_tokens: usage?.reasoningTokens ?? 0 },
|
|
139
|
+
total_tokens: usage?.totalTokens ?? 0
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function findOutputItem(report, outputItemId) {
|
|
143
|
+
for (const output of report.outputs) {
|
|
144
|
+
const item = output.output.items.find((candidate) => candidate.id === outputItemId);
|
|
145
|
+
if (item !== void 0) return item;
|
|
146
|
+
}
|
|
147
|
+
return void 0;
|
|
148
|
+
}
|
|
149
|
+
function readReportError(report) {
|
|
150
|
+
if (!report.result.ok) {
|
|
151
|
+
return readDeepestErrorMessage(report.result.error) ?? report.result.error.message;
|
|
152
|
+
}
|
|
153
|
+
const nodeError = report.nodes.find((node) => node.error !== void 0)?.error;
|
|
154
|
+
if (nodeError !== void 0) return readDeepestErrorMessage(nodeError) ?? nodeError.message;
|
|
155
|
+
return `Workflow execution ended with status ${report.status}.`;
|
|
156
|
+
}
|
|
157
|
+
function readDeepestErrorMessage(value) {
|
|
158
|
+
let current = value;
|
|
159
|
+
let message;
|
|
160
|
+
const seen = /* @__PURE__ */ new Set();
|
|
161
|
+
while (isRecord2(current) && !seen.has(current)) {
|
|
162
|
+
seen.add(current);
|
|
163
|
+
const candidate = typeof current.message === "string" ? current.message.trim() : "";
|
|
164
|
+
if (candidate !== "") message = candidate;
|
|
165
|
+
current = current.cause;
|
|
166
|
+
}
|
|
167
|
+
return message;
|
|
168
|
+
}
|
|
169
|
+
function writeRunnerFrame(frame) {
|
|
170
|
+
process.stdout.write(`${JSON.stringify(frame)}
|
|
171
|
+
`);
|
|
172
|
+
}
|
|
173
|
+
function createProcessAbortController() {
|
|
174
|
+
const controller = new AbortController();
|
|
175
|
+
const abort = () => {
|
|
176
|
+
if (!controller.signal.aborted) controller.abort(new Error("OpenAI runner was cancelled."));
|
|
177
|
+
};
|
|
178
|
+
process.once("SIGINT", abort);
|
|
179
|
+
process.once("SIGTERM", abort);
|
|
180
|
+
return controller;
|
|
181
|
+
}
|
|
182
|
+
function redirectConsoleToStderr() {
|
|
183
|
+
const write = (...values) => {
|
|
184
|
+
process.stderr.write(`${values.map(formatDiagnosticValue).join(" ")}
|
|
185
|
+
`);
|
|
186
|
+
};
|
|
187
|
+
console.log = write;
|
|
188
|
+
console.info = write;
|
|
189
|
+
console.debug = write;
|
|
190
|
+
console.warn = write;
|
|
191
|
+
}
|
|
192
|
+
function disableAiSdkWarningLogs() {
|
|
193
|
+
globalThis.AI_SDK_LOG_WARNINGS = false;
|
|
194
|
+
}
|
|
195
|
+
function formatDiagnosticValue(value) {
|
|
196
|
+
if (typeof value === "string") return value;
|
|
197
|
+
try {
|
|
198
|
+
return JSON.stringify(value);
|
|
199
|
+
} catch {
|
|
200
|
+
return String(value);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function isRecord2(value) {
|
|
204
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
205
|
+
}
|
|
206
|
+
export {
|
|
207
|
+
main,
|
|
208
|
+
parseOpenAIInternalRunnerRequest,
|
|
209
|
+
runOpenAIResponsesRunner
|
|
210
|
+
};
|