@bratsos/workflow-engine 0.2.0 → 0.3.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 +5 -1
- package/dist/{chunk-P4KMGCT3.js → chunk-QBYB2PJJ.js} +24 -8
- package/dist/chunk-QBYB2PJJ.js.map +1 -0
- package/dist/{chunk-HL3OJG7W.js → chunk-WZ533CPU.js} +155 -80
- package/dist/chunk-WZ533CPU.js.map +1 -0
- package/dist/client.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/kernel/index.d.ts +2 -2
- package/dist/kernel/index.js +1 -1
- package/dist/{plugins-BCnDUwIc.d.ts → plugins-CPC-X0rR.d.ts} +6 -0
- package/package.json +8 -8
- package/skills/workflow-engine/SKILL.md +4 -2
- package/skills/workflow-engine/references/04-ai-integration.md +33 -3
- package/skills/workflow-engine/references/08-common-patterns.md +10 -0
- package/dist/chunk-HL3OJG7W.js.map +0 -1
- package/dist/chunk-P4KMGCT3.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alex Bratsos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -642,7 +642,7 @@ async execute(ctx) {
|
|
|
642
642
|
| `run.transition` | Advance to next stage group | `workflowRunId` |
|
|
643
643
|
| `run.cancel` | Cancel a running workflow | `workflowRunId`, `reason?` |
|
|
644
644
|
| `run.rerunFrom` | Rerun from a specific stage | `workflowRunId`, `fromStageId` |
|
|
645
|
-
| `job.execute` | Execute a single stage | `idempotencyKey?`, `workflowRunId`, `workflowId`, `stageId`, `config` |
|
|
645
|
+
| `job.execute` | Execute a single stage (multi-phase transactions) | `idempotencyKey?`, `workflowRunId`, `workflowId`, `stageId`, `config` |
|
|
646
646
|
| `stage.pollSuspended` | Poll suspended stages | `maxChecks?` (returns `resumedWorkflowRunIds`) |
|
|
647
647
|
| `lease.reapStale` | Release stale job leases | `staleThresholdMs` |
|
|
648
648
|
| `outbox.flush` | Publish pending events | `maxEvents?` |
|
|
@@ -652,6 +652,10 @@ Idempotency behavior:
|
|
|
652
652
|
- Replaying the same `idempotencyKey` returns cached results.
|
|
653
653
|
- If the same key is already executing, dispatch throws `IdempotencyInProgressError`.
|
|
654
654
|
|
|
655
|
+
Transaction behavior:
|
|
656
|
+
- Most commands execute inside a single database transaction (handler + outbox events).
|
|
657
|
+
- `job.execute` uses multi-phase transactions: Phase 1 commits `RUNNING` status immediately, Phase 2 runs `stageDef.execute()` outside any transaction, Phase 3 commits the final status. This avoids holding a database connection during long-running stage execution.
|
|
658
|
+
|
|
655
659
|
### Node Host Config
|
|
656
660
|
|
|
657
661
|
| Option | Type | Default | Description |
|
|
@@ -1372,6 +1372,18 @@ function getModelProvider(modelConfig) {
|
|
|
1372
1372
|
}
|
|
1373
1373
|
return google(modelConfig.id);
|
|
1374
1374
|
}
|
|
1375
|
+
function getEmbeddingModelProvider(modelConfig) {
|
|
1376
|
+
if (modelConfig.provider === "openrouter") {
|
|
1377
|
+
return openrouter.textEmbeddingModel(modelConfig.id);
|
|
1378
|
+
}
|
|
1379
|
+
if (modelConfig.provider === "google") {
|
|
1380
|
+
const googleModelId = modelConfig.id.replace(/^google\//, "");
|
|
1381
|
+
return google.embeddingModel(googleModelId);
|
|
1382
|
+
}
|
|
1383
|
+
throw new Error(
|
|
1384
|
+
`Unsupported embedding provider "${modelConfig.provider}" for model "${modelConfig.id}". Supported providers: "openrouter", "google".`
|
|
1385
|
+
);
|
|
1386
|
+
}
|
|
1375
1387
|
function calculateCostWithDiscount(modelKey, inputTokens, outputTokens, isBatch = false) {
|
|
1376
1388
|
const model = getModel(modelKey);
|
|
1377
1389
|
const baseCost = calculateCost(modelKey, inputTokens, outputTokens);
|
|
@@ -1718,6 +1730,7 @@ var AIHelperImpl = class _AIHelperImpl {
|
|
|
1718
1730
|
logger.debug(`embed request`, {
|
|
1719
1731
|
model: modelKey,
|
|
1720
1732
|
modelId: modelConfig.id,
|
|
1733
|
+
provider: modelConfig.provider,
|
|
1721
1734
|
textCount: texts.length,
|
|
1722
1735
|
textPreview,
|
|
1723
1736
|
dimensions,
|
|
@@ -1727,14 +1740,16 @@ var AIHelperImpl = class _AIHelperImpl {
|
|
|
1727
1740
|
const embeddings = [];
|
|
1728
1741
|
let totalInputTokens = 0;
|
|
1729
1742
|
for (const t of texts) {
|
|
1730
|
-
const
|
|
1743
|
+
const embeddingModel = getEmbeddingModelProvider(modelConfig);
|
|
1731
1744
|
const result = await embed({
|
|
1732
|
-
model:
|
|
1745
|
+
model: embeddingModel,
|
|
1733
1746
|
value: t,
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1747
|
+
...modelConfig.provider === "google" && {
|
|
1748
|
+
providerOptions: {
|
|
1749
|
+
google: {
|
|
1750
|
+
outputDimensionality: dimensions,
|
|
1751
|
+
taskType: options.taskType ?? "RETRIEVAL_DOCUMENT"
|
|
1752
|
+
}
|
|
1738
1753
|
}
|
|
1739
1754
|
}
|
|
1740
1755
|
});
|
|
@@ -1767,6 +1782,7 @@ var AIHelperImpl = class _AIHelperImpl {
|
|
|
1767
1782
|
});
|
|
1768
1783
|
logger.debug(`embed response`, {
|
|
1769
1784
|
model: modelKey,
|
|
1785
|
+
provider: modelConfig.provider,
|
|
1770
1786
|
embeddingsCount: embeddings.length,
|
|
1771
1787
|
dimensions,
|
|
1772
1788
|
inputTokens: totalInputTokens,
|
|
@@ -2288,5 +2304,5 @@ function createAIHelper(topic, logger2, logContext) {
|
|
|
2288
2304
|
}
|
|
2289
2305
|
|
|
2290
2306
|
export { AVAILABLE_MODELS, AnthropicBatchProvider, DEFAULT_MODEL_KEY, GoogleBatchProvider, ModelKey, ModelStatsTracker, NoInputSchema, OpenAIBatchProvider, calculateCost, createAIHelper, defineAsyncBatchStage, defineStage, getBestProviderForModel, getDefaultModel, getModel, getModelById, getRegisteredModel, listModels, listRegisteredModels, modelSupportsBatch, printAvailableModels, registerModels, requireStageOutput, resolveModelForProvider };
|
|
2291
|
-
//# sourceMappingURL=chunk-
|
|
2292
|
-
//# sourceMappingURL=chunk-
|
|
2307
|
+
//# sourceMappingURL=chunk-QBYB2PJJ.js.map
|
|
2308
|
+
//# sourceMappingURL=chunk-QBYB2PJJ.js.map
|