@mokronos/wfkit 0.1.0
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/LICENSE +21 -0
- package/README.md +57 -0
- package/dist/authoring.d.ts +7 -0
- package/dist/authoring.d.ts.map +1 -0
- package/dist/authoring.js +8 -0
- package/dist/authoring.js.map +1 -0
- package/dist/cli/integrations.d.ts +3 -0
- package/dist/cli/integrations.d.ts.map +1 -0
- package/dist/cli/integrations.js +40 -0
- package/dist/cli/integrations.js.map +1 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +591 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/core.d.ts +198 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +1061 -0
- package/dist/core.js.map +1 -0
- package/dist/errors.d.ts +3 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +154 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +24 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/replay.d.ts +3 -0
- package/dist/replay.d.ts.map +1 -0
- package/dist/replay.js +28 -0
- package/dist/replay.js.map +1 -0
- package/dist/runtime.d.ts +70 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +183 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema.d.ts +18 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +19 -0
- package/dist/schema.js.map +1 -0
- package/dist/schemas.d.ts +1198 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +383 -0
- package/dist/schemas.js.map +1 -0
- package/dist/sdk/artifact.d.ts +41 -0
- package/dist/sdk/artifact.d.ts.map +1 -0
- package/dist/sdk/artifact.js +94 -0
- package/dist/sdk/artifact.js.map +1 -0
- package/dist/sdk/graph.d.ts +15 -0
- package/dist/sdk/graph.d.ts.map +1 -0
- package/dist/sdk/graph.js +388 -0
- package/dist/sdk/graph.js.map +1 -0
- package/dist/sdk/index.d.ts +14 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +8 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sdk/integrations.d.ts +18 -0
- package/dist/sdk/integrations.d.ts.map +1 -0
- package/dist/sdk/integrations.js +20 -0
- package/dist/sdk/integrations.js.map +1 -0
- package/dist/sdk/json.d.ts +4 -0
- package/dist/sdk/json.d.ts.map +1 -0
- package/dist/sdk/json.js +31 -0
- package/dist/sdk/json.js.map +1 -0
- package/dist/sdk/loader.d.ts +10 -0
- package/dist/sdk/loader.d.ts.map +1 -0
- package/dist/sdk/loader.js +75 -0
- package/dist/sdk/loader.js.map +1 -0
- package/dist/sdk/sdk.d.ts +102 -0
- package/dist/sdk/sdk.d.ts.map +1 -0
- package/dist/sdk/sdk.js +669 -0
- package/dist/sdk/sdk.js.map +1 -0
- package/dist/sdk/sqlite.d.ts +8 -0
- package/dist/sdk/sqlite.d.ts.map +1 -0
- package/dist/sdk/sqlite.js +288 -0
- package/dist/sdk/sqlite.js.map +1 -0
- package/dist/signal.d.ts +17 -0
- package/dist/signal.d.ts.map +1 -0
- package/dist/signal.js +78 -0
- package/dist/signal.js.map +1 -0
- package/dist/testing/index.d.ts +35 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +244 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +67 -0
- package/src/authoring.ts +32 -0
- package/src/cli/integrations.ts +75 -0
- package/src/cli/main.ts +793 -0
- package/src/core.ts +1515 -0
- package/src/errors.ts +19 -0
- package/src/events.ts +37 -0
- package/src/index.ts +109 -0
- package/src/replay.ts +29 -0
- package/src/runtime.ts +314 -0
- package/src/schema.ts +34 -0
- package/src/schemas.ts +473 -0
- package/src/sdk/artifact.ts +176 -0
- package/src/sdk/graph.ts +486 -0
- package/src/sdk/index.ts +64 -0
- package/src/sdk/integrations.ts +49 -0
- package/src/sdk/json.ts +40 -0
- package/src/sdk/loader.ts +99 -0
- package/src/sdk/sdk.ts +911 -0
- package/src/sdk/sqlite.ts +405 -0
- package/src/signal.ts +116 -0
- package/src/testing/index.ts +341 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { createInMemoryDeterminismState } from "../core.js";
|
|
2
|
+
import { Cancelled } from "../sdk/index.js";
|
|
3
|
+
import { cancelSignalWaits, deliverSignal } from "../signal.js";
|
|
4
|
+
import { ExecutionId } from "../schemas.js";
|
|
5
|
+
const nowIso = () => new Date().toISOString();
|
|
6
|
+
const executionId = () => crypto.randomUUID();
|
|
7
|
+
const parseDurationMs = (duration) => {
|
|
8
|
+
if (typeof duration === "number") {
|
|
9
|
+
return duration;
|
|
10
|
+
}
|
|
11
|
+
const raw = String(duration).trim();
|
|
12
|
+
const match = /^(\d+(?:\.\d+)?)\s*([a-zA-Z]+)?$/.exec(raw);
|
|
13
|
+
if (match === null) {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
const value = Number(match[1]);
|
|
17
|
+
const unit = (match[2] ?? "millis").toLowerCase();
|
|
18
|
+
if (unit.startsWith("ms") || unit.startsWith("milli"))
|
|
19
|
+
return value;
|
|
20
|
+
if (unit.startsWith("sec"))
|
|
21
|
+
return value * 1_000;
|
|
22
|
+
if (unit.startsWith("min"))
|
|
23
|
+
return value * 60_000;
|
|
24
|
+
if (unit.startsWith("hour"))
|
|
25
|
+
return value * 60 * 60_000;
|
|
26
|
+
if (unit.startsWith("day"))
|
|
27
|
+
return value * 24 * 60 * 60_000;
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
const statusFromEvent = (event) => {
|
|
31
|
+
switch (event.type) {
|
|
32
|
+
case "sleep.started":
|
|
33
|
+
case "signal.waiting":
|
|
34
|
+
return "suspended";
|
|
35
|
+
case "sleep.completed":
|
|
36
|
+
case "signal.received":
|
|
37
|
+
case "signal.timeout":
|
|
38
|
+
case "step.started":
|
|
39
|
+
case "step.completed":
|
|
40
|
+
return "running";
|
|
41
|
+
default:
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export const createTestRuntime = (options = {}) => {
|
|
46
|
+
const timeSkipping = options.timeSkipping ?? true;
|
|
47
|
+
const executions = new Map();
|
|
48
|
+
const idempotencyKeys = new Map();
|
|
49
|
+
const stepMocks = new Map();
|
|
50
|
+
const failOnce = new Set();
|
|
51
|
+
const recorders = [];
|
|
52
|
+
const timers = [];
|
|
53
|
+
const secrets = new Map();
|
|
54
|
+
let virtualNow = 0;
|
|
55
|
+
const secretResolver = {
|
|
56
|
+
resolve: (name) => {
|
|
57
|
+
const value = secrets.get(name);
|
|
58
|
+
if (value === undefined) {
|
|
59
|
+
throw new Error(`Unknown test secret: ${name} (register it with rt.setSecret)`);
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const appendHistory = (record, event) => {
|
|
65
|
+
record.history.push({
|
|
66
|
+
sequence: record.history.length + 1,
|
|
67
|
+
createdAt: nowIso(),
|
|
68
|
+
event
|
|
69
|
+
});
|
|
70
|
+
const nextStatus = statusFromEvent(event);
|
|
71
|
+
if (nextStatus !== undefined && record.status !== "failed") {
|
|
72
|
+
record.status = nextStatus;
|
|
73
|
+
}
|
|
74
|
+
if (event.type === "compensation.started") {
|
|
75
|
+
for (const recorder of recorders) {
|
|
76
|
+
recorder.calls.push({ step: event.stepName, result: event.result });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const requireExecution = (id) => {
|
|
81
|
+
const execution = executions.get(id);
|
|
82
|
+
if (execution === undefined) {
|
|
83
|
+
throw new Error(`Unknown workflow execution: ${id}`);
|
|
84
|
+
}
|
|
85
|
+
return execution;
|
|
86
|
+
};
|
|
87
|
+
const makeDelay = (duration) => {
|
|
88
|
+
if (timeSkipping) {
|
|
89
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
90
|
+
}
|
|
91
|
+
const due = virtualNow + parseDurationMs(duration);
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
timers.push({ due, resolve });
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
const buildStepExecutors = () => {
|
|
97
|
+
const executors = new Map();
|
|
98
|
+
const steps = new Set([...stepMocks.keys(), ...failOnce]);
|
|
99
|
+
for (const step of steps) {
|
|
100
|
+
executors.set(step, async (input, context) => {
|
|
101
|
+
if (failOnce.has(step)) {
|
|
102
|
+
failOnce.delete(step);
|
|
103
|
+
throw new Error(`Injected failure for step ${step.name}`);
|
|
104
|
+
}
|
|
105
|
+
const mock = stepMocks.get(step);
|
|
106
|
+
return mock === undefined
|
|
107
|
+
? step.execute(input, context)
|
|
108
|
+
: mock(input, context);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return executors;
|
|
112
|
+
};
|
|
113
|
+
const launch = (workflow, payload, record) => {
|
|
114
|
+
void workflow.executeInMemory(payload, {
|
|
115
|
+
executionId: record.executionId,
|
|
116
|
+
determinism: record.determinism,
|
|
117
|
+
stepExecutors: buildStepExecutors(),
|
|
118
|
+
sleep: ({ duration }) => makeDelay(duration),
|
|
119
|
+
signalTimeout: ({ duration }) => makeDelay(duration),
|
|
120
|
+
secrets: secretResolver,
|
|
121
|
+
onEvent: (event) => {
|
|
122
|
+
appendHistory(record, event);
|
|
123
|
+
}
|
|
124
|
+
}).then((value) => {
|
|
125
|
+
record.status = "completed";
|
|
126
|
+
record.finishedAt = nowIso();
|
|
127
|
+
record.result = { type: "completed", value };
|
|
128
|
+
record.resolveResult(record.result);
|
|
129
|
+
}, (error) => {
|
|
130
|
+
record.status = "failed";
|
|
131
|
+
record.finishedAt = nowIso();
|
|
132
|
+
record.result = { type: "failed", error };
|
|
133
|
+
record.resolveResult(record.result);
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
const createExecution = (workflow, payload, opts = {}) => {
|
|
137
|
+
let resolveResult;
|
|
138
|
+
const resultPromise = new Promise((resolve) => {
|
|
139
|
+
resolveResult = resolve;
|
|
140
|
+
});
|
|
141
|
+
const id = opts.id ?? executionId();
|
|
142
|
+
const record = {
|
|
143
|
+
executionId: id,
|
|
144
|
+
workflow,
|
|
145
|
+
payload,
|
|
146
|
+
determinism: opts.determinism ?? createInMemoryDeterminismState(),
|
|
147
|
+
status: "running",
|
|
148
|
+
startedAt: nowIso(),
|
|
149
|
+
history: [],
|
|
150
|
+
resultPromise,
|
|
151
|
+
resolveResult
|
|
152
|
+
};
|
|
153
|
+
executions.set(id, record);
|
|
154
|
+
appendHistory(record, {
|
|
155
|
+
type: "execution.started",
|
|
156
|
+
executionId: ExecutionId.make(id),
|
|
157
|
+
workflowName: workflow.name,
|
|
158
|
+
version: workflow.version,
|
|
159
|
+
payload,
|
|
160
|
+
...(opts.actor === undefined ? {} : { actor: opts.actor })
|
|
161
|
+
});
|
|
162
|
+
launch(workflow, payload, record);
|
|
163
|
+
return record;
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
mockStep(step, impl) {
|
|
167
|
+
stepMocks.set(step, impl);
|
|
168
|
+
},
|
|
169
|
+
failStepOnce(step) {
|
|
170
|
+
failOnce.add(step);
|
|
171
|
+
},
|
|
172
|
+
recordCompensations() {
|
|
173
|
+
const recorder = { calls: [] };
|
|
174
|
+
recorders.push(recorder);
|
|
175
|
+
return recorder;
|
|
176
|
+
},
|
|
177
|
+
async start(workflow, payload, opts = {}) {
|
|
178
|
+
const workflowKey = `${workflow.name}@v${workflow.version}`;
|
|
179
|
+
if (opts.idempotencyKey !== undefined) {
|
|
180
|
+
const existingId = idempotencyKeys.get(`${workflowKey}:${opts.idempotencyKey}`);
|
|
181
|
+
if (existingId !== undefined) {
|
|
182
|
+
return { executionId: existingId, version: workflow.version };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const record = createExecution(workflow, payload, opts.actor === undefined ? {} : { actor: opts.actor });
|
|
186
|
+
if (opts.idempotencyKey !== undefined) {
|
|
187
|
+
idempotencyKeys.set(`${workflowKey}:${opts.idempotencyKey}`, record.executionId);
|
|
188
|
+
}
|
|
189
|
+
return { executionId: record.executionId, version: workflow.version };
|
|
190
|
+
},
|
|
191
|
+
async replay(id, workflow, payload) {
|
|
192
|
+
const previous = requireExecution(id);
|
|
193
|
+
const record = createExecution(workflow, payload, {
|
|
194
|
+
id,
|
|
195
|
+
determinism: previous.determinism
|
|
196
|
+
});
|
|
197
|
+
return { executionId: record.executionId, version: workflow.version };
|
|
198
|
+
},
|
|
199
|
+
sendSignal(executionId, name, payload) {
|
|
200
|
+
return deliverSignal(executionId, name, payload);
|
|
201
|
+
},
|
|
202
|
+
result(executionId) {
|
|
203
|
+
return requireExecution(executionId).resultPromise;
|
|
204
|
+
},
|
|
205
|
+
async status(executionId) {
|
|
206
|
+
return requireExecution(executionId).status;
|
|
207
|
+
},
|
|
208
|
+
async history(executionId) {
|
|
209
|
+
return requireExecution(executionId).history;
|
|
210
|
+
},
|
|
211
|
+
async cancel(executionId, opts = {}) {
|
|
212
|
+
const record = requireExecution(executionId);
|
|
213
|
+
const compensate = opts.compensate ?? true;
|
|
214
|
+
appendHistory(record, {
|
|
215
|
+
type: "execution.cancelled",
|
|
216
|
+
executionId: ExecutionId.make(executionId),
|
|
217
|
+
compensate,
|
|
218
|
+
...(opts.actor === undefined ? {} : { actor: opts.actor })
|
|
219
|
+
});
|
|
220
|
+
if (compensate) {
|
|
221
|
+
record.status = "compensating";
|
|
222
|
+
}
|
|
223
|
+
cancelSignalWaits(executionId, new Cancelled({ compensate }));
|
|
224
|
+
},
|
|
225
|
+
setSecret(name, value) {
|
|
226
|
+
secrets.set(name, value);
|
|
227
|
+
},
|
|
228
|
+
async advanceTime(duration) {
|
|
229
|
+
virtualNow += parseDurationMs(duration);
|
|
230
|
+
timers.sort((left, right) => left.due - right.due);
|
|
231
|
+
for (let index = 0; index < timers.length;) {
|
|
232
|
+
const timer = timers[index];
|
|
233
|
+
if (timer.due > virtualNow) {
|
|
234
|
+
index++;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
timers.splice(index, 1);
|
|
238
|
+
timer.resolve();
|
|
239
|
+
}
|
|
240
|
+
await Promise.resolve();
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAA;AAQ3D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAwD3C,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;AAC7C,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,CAAA;AAE7C,MAAM,eAAe,GAAG,CAAC,QAAwB,EAAU,EAAE;IAC3D,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,QAAQ,CAAA;IACjB,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAA;IACnC,MAAM,KAAK,GAAG,kCAAkC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC1D,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,CAAC,CAAA;IACV,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9B,MAAM,IAAI,GAAG,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face — the stable API agents design against.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/mokronos/wf.git",
|
|
10
|
+
"directory": "packages/wf"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/mokronos/wf#readme",
|
|
13
|
+
"bugs": "https://github.com/mokronos/wf/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"workflow",
|
|
16
|
+
"durable-execution",
|
|
17
|
+
"effect",
|
|
18
|
+
"bun",
|
|
19
|
+
"agent"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"bun": ">=1.2"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"registry": "https://registry.npmjs.org"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"src",
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
33
|
+
"bin": {
|
|
34
|
+
"wf": "dist/cli/main.js",
|
|
35
|
+
"wf-integrations": "dist/cli/integrations.js"
|
|
36
|
+
},
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"bun": "./src/index.ts",
|
|
41
|
+
"development": "./src/index.ts",
|
|
42
|
+
"default": "./dist/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./schemas": {
|
|
45
|
+
"types": "./dist/schemas.d.ts",
|
|
46
|
+
"bun": "./src/schemas.ts",
|
|
47
|
+
"development": "./src/schemas.ts",
|
|
48
|
+
"default": "./dist/schemas.js"
|
|
49
|
+
},
|
|
50
|
+
"./testing": {
|
|
51
|
+
"types": "./dist/testing/index.d.ts",
|
|
52
|
+
"bun": "./src/testing/index.ts",
|
|
53
|
+
"development": "./src/testing/index.ts",
|
|
54
|
+
"default": "./dist/testing/index.js"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
59
|
+
"prepublishOnly": "bun run build"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"@effect/platform-bun": "^4.0.0-beta.93",
|
|
63
|
+
"@effect/platform-node": "^4.0.0-beta.93",
|
|
64
|
+
"@effect/sql-sqlite-bun": "^4.0.0-beta.93",
|
|
65
|
+
"effect": "^4.0.0-beta.93"
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/authoring.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Lightweight authoring entrypoint used by workflow source loaders.
|
|
2
|
+
// Keep this free of runtime/sdk imports so workflow modules can be inspected
|
|
3
|
+
// in non-Bun tooling such as the web dashboard dev server.
|
|
4
|
+
export {
|
|
5
|
+
createInMemoryDeterminismState,
|
|
6
|
+
defineStep,
|
|
7
|
+
defineWorkflow,
|
|
8
|
+
envSecretResolver,
|
|
9
|
+
isSecretRef,
|
|
10
|
+
NonDeterminismError,
|
|
11
|
+
secret
|
|
12
|
+
} from "./core.ts"
|
|
13
|
+
export type {
|
|
14
|
+
DefinedWorkflow,
|
|
15
|
+
InMemoryDeterminismState,
|
|
16
|
+
OrchestrationCall,
|
|
17
|
+
OrchestrationKind,
|
|
18
|
+
SecretRef,
|
|
19
|
+
SecretResolver,
|
|
20
|
+
SignalOutcome,
|
|
21
|
+
Step,
|
|
22
|
+
StepConcurrency,
|
|
23
|
+
StepContext,
|
|
24
|
+
StepRetryPolicy,
|
|
25
|
+
TerminalFailure,
|
|
26
|
+
WorkflowContext,
|
|
27
|
+
WorkflowValue
|
|
28
|
+
} from "./core.ts"
|
|
29
|
+
export { defineError } from "./errors.ts"
|
|
30
|
+
export type { WorkflowEvent, WorkflowEventSink } from "./events.ts"
|
|
31
|
+
export { deliverSignal, SignalDeliveryError } from "./signal.ts"
|
|
32
|
+
export { t } from "./schema.ts"
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { BunRuntime, BunServices } from "@effect/platform-bun"
|
|
3
|
+
import { Console, Effect, Option } from "effect"
|
|
4
|
+
import { Argument, Command, Flag } from "effect/unstable/cli"
|
|
5
|
+
import { discover } from "../index.ts"
|
|
6
|
+
import type { IntegrationKind, IntegrationSearchResult } from "../index.ts"
|
|
7
|
+
|
|
8
|
+
class IntegrationDiscoveryError extends Error {
|
|
9
|
+
readonly _tag = "IntegrationDiscoveryError"
|
|
10
|
+
readonly originalError: unknown
|
|
11
|
+
|
|
12
|
+
constructor(error: unknown) {
|
|
13
|
+
super(error instanceof Error ? error.message : "Integration discovery failed")
|
|
14
|
+
this.name = "IntegrationDiscoveryError"
|
|
15
|
+
this.originalError = error
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const kind = Flag.choice("kind", ["mcp", "openapi", "graphql", "cli"] as const).pipe(
|
|
20
|
+
Flag.optional,
|
|
21
|
+
Flag.withDescription("Limit results to one integration surface kind")
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const limit = Flag.integer("limit").pipe(
|
|
25
|
+
Flag.withDefault(20),
|
|
26
|
+
Flag.withDescription("Maximum number of results to return")
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
const searchTerm = Argument.string("search_term").pipe(
|
|
30
|
+
Argument.withDescription("Service, domain, or integration capability to search for")
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
const formatKinds = (kinds: ReadonlyArray<IntegrationKind>): string => kinds.join(", ")
|
|
34
|
+
|
|
35
|
+
const formatResult = (result: IntegrationSearchResult): string =>
|
|
36
|
+
`${result.domain}\t${formatKinds(result.kinds)}\t${result.description}\t${result.url}`
|
|
37
|
+
|
|
38
|
+
const discoverCommand = Command.make(
|
|
39
|
+
"discover",
|
|
40
|
+
{ kind, limit, searchTerm },
|
|
41
|
+
({ kind, limit, searchTerm }) =>
|
|
42
|
+
Effect.tryPromise({
|
|
43
|
+
try: () => {
|
|
44
|
+
const selectedKind = Option.getOrUndefined(kind)
|
|
45
|
+
return discover(searchTerm, {
|
|
46
|
+
...(selectedKind === undefined ? {} : { kind: selectedKind }),
|
|
47
|
+
limit
|
|
48
|
+
})
|
|
49
|
+
},
|
|
50
|
+
catch: (error) => new IntegrationDiscoveryError(error)
|
|
51
|
+
}).pipe(
|
|
52
|
+
Effect.flatMap(({ results }) =>
|
|
53
|
+
Effect.gen(function* () {
|
|
54
|
+
if (results.length === 0) {
|
|
55
|
+
yield* Console.log("No integrations found.")
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const result of results) {
|
|
60
|
+
yield* Console.log(formatResult(result))
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
).pipe(Command.withDescription("Search integrations.sh for agent-ready integration surfaces"))
|
|
66
|
+
|
|
67
|
+
const app = Command.make("integrations", {}).pipe(
|
|
68
|
+
Command.withDescription("Discover public integration surfaces from integrations.sh"),
|
|
69
|
+
Command.withSubcommands([discoverCommand] as const)
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
Command.run(app, { version: "0.0.0" }).pipe(
|
|
73
|
+
Effect.provide(BunServices.layer),
|
|
74
|
+
BunRuntime.runMain
|
|
75
|
+
)
|