@codemation/core-nodes 0.0.16 → 0.0.18

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/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @codemation/core-nodes
2
+
3
+ ## 0.0.18
4
+
5
+ ### Patch Changes
6
+
7
+ - f0c6878: Introduce Changesets, a single CI status check for branch protection, and the Codemation pre-stable license across published packages.
8
+ - Updated dependencies [f0c6878]
9
+ - @codemation/core@0.0.18
package/LICENSE ADDED
@@ -0,0 +1,37 @@
1
+ Codemation Pre-Stable License
2
+
3
+ Copyright (c) Made Relevant B.V. All rights reserved.
4
+
5
+ 1. Definitions
6
+
7
+ "Software" means the Codemation source code, documentation, and artifacts in this repository and any published npm packages in the Codemation monorepo.
8
+
9
+ "Stable Version" means the first published release of the package `@codemation/core` on the public npm registry with version 1.0.0 or higher.
10
+
11
+ 2. Permitted use (before Stable Version)
12
+
13
+ Until a Stable Version exists, you may use, copy, modify, and distribute the Software only for non-commercial purposes, including personal learning, research, evaluation, and internal use within your organization that does not charge third parties for access to the Software or a product or service whose primary value is the Software.
14
+
15
+ 3. Restrictions (before Stable Version)
16
+
17
+ Until a Stable Version exists, you must not:
18
+
19
+ a) Sell, rent, lease, or sublicense the Software or a derivative work for a fee;
20
+
21
+ b) Offer the Software or a derivative work as part of a paid product or service (including hosting, support, or consulting) where the Software is a material part of the offering;
22
+
23
+ c) Use the Software or a derivative work primarily to generate revenue or commercial advantage for you or others.
24
+
25
+ These restrictions apply to all versions published before a Stable Version, even if a later Stable Version is released under different terms.
26
+
27
+ 4. After Stable Version
28
+
29
+ The maintainers may publish a Stable Version under different license terms. If they do, those terms apply only to that Stable Version and subsequent releases they designate; they do not automatically apply to earlier pre-stable versions.
30
+
31
+ 5. No warranty
32
+
33
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
+
35
+ 6. Third-party components
36
+
37
+ The Software may include third-party components under their own licenses. Those licenses govern those components.
package/dist/index.cjs CHANGED
@@ -1219,6 +1219,166 @@ function createWorkflowBuilder(meta) {
1219
1219
  }) });
1220
1220
  }
1221
1221
 
1222
+ //#endregion
1223
+ //#region src/workflowAuthoring/WorkflowChatModelFactory.types.ts
1224
+ var WorkflowChatModelFactory = class {
1225
+ static create(model) {
1226
+ if (typeof model !== "string") return model;
1227
+ const [provider, resolvedModel] = model.includes(":") ? model.split(":", 2) : ["openai", model];
1228
+ if (provider !== "openai") throw new Error(`Unsupported workflow().agent() model provider "${provider}".`);
1229
+ return new OpenAIChatModelConfig("OpenAI", resolvedModel);
1230
+ }
1231
+ };
1232
+
1233
+ //#endregion
1234
+ //#region src/workflowAuthoring/WorkflowAgentNodeFactory.types.ts
1235
+ var WorkflowAgentNodeFactory = class {
1236
+ static create(nameOrOptions, optionsOrUndefined) {
1237
+ const options = typeof nameOrOptions === "string" ? optionsOrUndefined : nameOrOptions;
1238
+ const name = typeof nameOrOptions === "string" ? nameOrOptions : "AI agent";
1239
+ const prompt = options.prompt;
1240
+ return new AIAgent({
1241
+ name,
1242
+ messages: [{
1243
+ role: "user",
1244
+ content: typeof prompt === "function" ? ({ item }) => prompt(item.json) : prompt
1245
+ }],
1246
+ chatModel: WorkflowChatModelFactory.create(options.model),
1247
+ tools: options.tools,
1248
+ id: options.id,
1249
+ retryPolicy: options.retryPolicy,
1250
+ guardrails: options.guardrails
1251
+ });
1252
+ }
1253
+ };
1254
+
1255
+ //#endregion
1256
+ //#region src/workflowAuthoring/WorkflowDefinedNodeResolver.types.ts
1257
+ var WorkflowDefinedNodeResolver = class {
1258
+ static resolve(definitionOrKey) {
1259
+ if (typeof definitionOrKey !== "string") return definitionOrKey;
1260
+ const definition = __codemation_core.DefinedNodeRegistry.resolve(definitionOrKey);
1261
+ if (!definition) throw new Error(`No helper-defined node with key "${definitionOrKey}" is registered in this module graph.`);
1262
+ return definition;
1263
+ }
1264
+ };
1265
+
1266
+ //#endregion
1267
+ //#region src/workflowAuthoring/WorkflowDurationParser.types.ts
1268
+ var WorkflowDurationParser = class {
1269
+ static parse(duration) {
1270
+ if (typeof duration === "number") return Number.isFinite(duration) && duration > 0 ? Math.floor(duration) : 0;
1271
+ const match = duration.trim().toLowerCase().match(/^(\d+)(ms|s|m|h)$/);
1272
+ if (!match) throw new Error(`Unsupported wait duration "${duration}". Use a number of milliseconds or values like "500ms", "2s", "5m".`);
1273
+ const value = Number(match[1]);
1274
+ const unit = match[2];
1275
+ if (unit === "ms") return value;
1276
+ if (unit === "s") return value * 1e3;
1277
+ if (unit === "m") return value * 6e4;
1278
+ return value * 36e5;
1279
+ }
1280
+ };
1281
+
1282
+ //#endregion
1283
+ //#region src/workflowAuthoring/WorkflowBranchBuilder.types.ts
1284
+ var WorkflowBranchBuilder = class WorkflowBranchBuilder {
1285
+ constructor(steps = []) {
1286
+ this.steps = steps;
1287
+ }
1288
+ then(config) {
1289
+ return new WorkflowBranchBuilder([...this.steps, config]);
1290
+ }
1291
+ map(nameOrMapper, mapperOrUndefined, id) {
1292
+ const name = typeof nameOrMapper === "string" ? nameOrMapper : "Map data";
1293
+ const mapper = typeof nameOrMapper === "string" ? mapperOrUndefined : nameOrMapper;
1294
+ return this.then(new MapData(name, (item) => mapper(item.json), id));
1295
+ }
1296
+ wait(nameOrDuration, durationOrUndefined, id) {
1297
+ const name = typeof nameOrDuration === "string" && durationOrUndefined !== void 0 ? nameOrDuration : "Wait";
1298
+ const duration = durationOrUndefined ?? nameOrDuration;
1299
+ return this.then(new Wait(name, WorkflowDurationParser.parse(duration), id));
1300
+ }
1301
+ agent(nameOrOptions, optionsOrUndefined) {
1302
+ return this.then(WorkflowAgentNodeFactory.create(nameOrOptions, optionsOrUndefined));
1303
+ }
1304
+ node(definitionOrKey, config, name, id) {
1305
+ const definition = WorkflowDefinedNodeResolver.resolve(definitionOrKey);
1306
+ return this.then(definition.create(config, name, id));
1307
+ }
1308
+ getSteps() {
1309
+ return this.steps;
1310
+ }
1311
+ };
1312
+
1313
+ //#endregion
1314
+ //#region src/workflowAuthoring/WorkflowChain.types.ts
1315
+ var WorkflowChain = class WorkflowChain {
1316
+ constructor(chain) {
1317
+ this.chain = chain;
1318
+ }
1319
+ then(config) {
1320
+ return new WorkflowChain(this.chain.then(config));
1321
+ }
1322
+ map(nameOrMapper, mapperOrUndefined, id) {
1323
+ const name = typeof nameOrMapper === "string" ? nameOrMapper : "Map data";
1324
+ const mapper = typeof nameOrMapper === "string" ? mapperOrUndefined : nameOrMapper;
1325
+ return this.then(new MapData(name, (item) => mapper(item.json), id));
1326
+ }
1327
+ wait(nameOrDuration, durationOrUndefined, id) {
1328
+ const name = typeof nameOrDuration === "string" && durationOrUndefined !== void 0 ? nameOrDuration : "Wait";
1329
+ const duration = durationOrUndefined ?? nameOrDuration;
1330
+ return this.then(new Wait(name, WorkflowDurationParser.parse(duration), id));
1331
+ }
1332
+ if(nameOrPredicate, predicateOrBranches, branchesOrUndefined) {
1333
+ const name = typeof nameOrPredicate === "string" ? nameOrPredicate : "If";
1334
+ const predicate = typeof nameOrPredicate === "string" ? predicateOrBranches : nameOrPredicate;
1335
+ const branches = typeof nameOrPredicate === "string" ? branchesOrUndefined : predicateOrBranches;
1336
+ const cursor = this.chain.then(new If(name, (item) => predicate(item.json)));
1337
+ const trueSteps = branches.true?.(new WorkflowBranchBuilder()).getSteps();
1338
+ const falseSteps = branches.false?.(new WorkflowBranchBuilder()).getSteps();
1339
+ return new WorkflowChain(cursor.when({
1340
+ true: trueSteps,
1341
+ false: falseSteps
1342
+ }));
1343
+ }
1344
+ agent(nameOrOptions, optionsOrUndefined) {
1345
+ return this.then(WorkflowAgentNodeFactory.create(nameOrOptions, optionsOrUndefined));
1346
+ }
1347
+ node(definitionOrKey, config, name, id) {
1348
+ const definition = WorkflowDefinedNodeResolver.resolve(definitionOrKey);
1349
+ return this.then(definition.create(config, name, id));
1350
+ }
1351
+ build() {
1352
+ return this.chain.build();
1353
+ }
1354
+ };
1355
+
1356
+ //#endregion
1357
+ //#region src/workflowAuthoring/WorkflowAuthoringBuilder.types.ts
1358
+ var WorkflowAuthoringBuilder = class WorkflowAuthoringBuilder {
1359
+ constructor(id, workflowName = id) {
1360
+ this.id = id;
1361
+ this.workflowName = workflowName;
1362
+ }
1363
+ name(name) {
1364
+ return new WorkflowAuthoringBuilder(this.id, name);
1365
+ }
1366
+ manualTrigger(nameOrDefaultItems, defaultItemsOrUndefined, id) {
1367
+ const builder = createWorkflowBuilder({
1368
+ id: this.id,
1369
+ name: this.workflowName
1370
+ });
1371
+ if (typeof nameOrDefaultItems === "string") return new WorkflowChain(builder.trigger(new ManualTrigger(nameOrDefaultItems, defaultItemsOrUndefined, id)));
1372
+ return new WorkflowChain(builder.trigger(new ManualTrigger("Manual trigger", nameOrDefaultItems)));
1373
+ }
1374
+ };
1375
+
1376
+ //#endregion
1377
+ //#region src/workflowAuthoring.types.ts
1378
+ function workflow(id) {
1379
+ return new WorkflowAuthoringBuilder(id);
1380
+ }
1381
+
1222
1382
  //#endregion
1223
1383
  //#region src/workflows/AIAgentConnectionWorkflowExpander.ts
1224
1384
  /**
@@ -1228,18 +1388,18 @@ var AIAgentConnectionWorkflowExpander = class {
1228
1388
  constructor(connectionCredentialNodeConfigFactory) {
1229
1389
  this.connectionCredentialNodeConfigFactory = connectionCredentialNodeConfigFactory;
1230
1390
  }
1231
- expand(workflow) {
1391
+ expand(workflow$1) {
1232
1392
  const existingByParentAndName = /* @__PURE__ */ new Map();
1233
- for (const c of workflow.connections ?? []) existingByParentAndName.set(`${c.parentNodeId}\0${c.connectionName}`, c);
1393
+ for (const c of workflow$1.connections ?? []) existingByParentAndName.set(`${c.parentNodeId}\0${c.connectionName}`, c);
1234
1394
  const extraNodes = [];
1235
1395
  const extraConnections = [];
1236
- for (const node$12 of workflow.nodes) {
1396
+ for (const node$12 of workflow$1.nodes) {
1237
1397
  if (node$12.type !== AIAgentNode || !__codemation_core.AgentConfigInspector.isAgentNodeConfig(node$12.config)) continue;
1238
1398
  const agentId = node$12.id;
1239
1399
  const agentConfig = node$12.config;
1240
1400
  if (!existingByParentAndName.has(`${agentId}\0llm`)) {
1241
1401
  const llmId = __codemation_core.ConnectionNodeIdFactory.languageModelConnectionNodeId(agentId);
1242
- this.assertNoIdCollision(workflow, extraNodes, llmId);
1402
+ this.assertNoIdCollision(workflow$1, extraNodes, llmId);
1243
1403
  extraNodes.push({
1244
1404
  id: llmId,
1245
1405
  kind: "node",
@@ -1257,7 +1417,7 @@ var AIAgentConnectionWorkflowExpander = class {
1257
1417
  const toolIds = [];
1258
1418
  for (const tool of agentConfig.tools ?? []) {
1259
1419
  const toolId = __codemation_core.ConnectionNodeIdFactory.toolConnectionNodeId(agentId, tool.name);
1260
- this.assertNoIdCollision(workflow, extraNodes, toolId);
1420
+ this.assertNoIdCollision(workflow$1, extraNodes, toolId);
1261
1421
  toolIds.push(toolId);
1262
1422
  extraNodes.push({
1263
1423
  id: toolId,
@@ -1274,15 +1434,15 @@ var AIAgentConnectionWorkflowExpander = class {
1274
1434
  });
1275
1435
  }
1276
1436
  }
1277
- if (extraNodes.length === 0) return workflow;
1437
+ if (extraNodes.length === 0) return workflow$1;
1278
1438
  return {
1279
- ...workflow,
1280
- nodes: [...workflow.nodes, ...extraNodes],
1281
- connections: [...workflow.connections ?? [], ...extraConnections]
1439
+ ...workflow$1,
1440
+ nodes: [...workflow$1.nodes, ...extraNodes],
1441
+ connections: [...workflow$1.connections ?? [], ...extraConnections]
1282
1442
  };
1283
1443
  }
1284
- assertNoIdCollision(workflow, pending, id) {
1285
- if (workflow.nodes.some((n) => n.id === id) || pending.some((n) => n.id === id)) throw new Error(`AIAgent connection expansion: node id "${id}" already exists. Rename the conflicting node or adjust the workflow.`);
1444
+ assertNoIdCollision(workflow$1, pending, id) {
1445
+ if (workflow$1.nodes.some((n) => n.id === id) || pending.some((n) => n.id === id)) throw new Error(`AIAgent connection expansion: node id "${id}" already exists. Rename the conflicting node or adjust the workflow.`);
1286
1446
  }
1287
1447
  };
1288
1448
 
@@ -1418,7 +1578,11 @@ Object.defineProperty(exports, 'WebhookTriggerNode', {
1418
1578
  return WebhookTriggerNode;
1419
1579
  }
1420
1580
  });
1581
+ exports.WorkflowAuthoringBuilder = WorkflowAuthoringBuilder;
1582
+ exports.WorkflowBranchBuilder = WorkflowBranchBuilder;
1583
+ exports.WorkflowChain = WorkflowChain;
1421
1584
  exports.createWorkflowBuilder = createWorkflowBuilder;
1422
1585
  exports.openAiChatModelPresets = openAiChatModelPresets;
1423
1586
  exports.registerCoreNodes = registerCoreNodes;
1587
+ exports.workflow = workflow;
1424
1588
  //# sourceMappingURL=index.cjs.map