@hexabot-ai/agentic 3.1.2-alpha.10 → 3.1.2-alpha.12

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/cjs/index.js CHANGED
@@ -19,7 +19,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.withTimeout = exports.sleep = exports.toSnakeCase = exports.isSnakeCaseName = exports.assertSnakeCaseName = exports.createDeferred = exports.mergeSettings = exports.evaluateValue = exports.evaluateMapping = exports.compileValue = exports.NonDeterministicWorkflowError = exports.StepType = exports.WorkflowRunner = exports.WorkflowEventEmitter = exports.Workflow = exports.compileWorkflow = exports.WORKFLOW_RUN_STATUSES = exports.EWorkflowRunStatus = exports.BaseWorkflowContext = exports.defineAction = exports.AbstractAction = void 0;
22
+ exports.remapWorkflowDefinitionResourceRefs = exports.collectWorkflowDefinitionResourceRefs = exports.withTimeout = exports.sleep = exports.toSnakeCase = exports.isSnakeCaseName = exports.assertSnakeCaseName = exports.createDeferred = exports.mergeSettings = exports.evaluateValue = exports.evaluateMapping = exports.compileValue = exports.NonDeterministicWorkflowError = exports.StepType = exports.WorkflowRunner = exports.WorkflowEventEmitter = exports.Workflow = exports.compileWorkflow = exports.WORKFLOW_RUN_STATUSES = exports.EWorkflowRunStatus = exports.BaseWorkflowContext = exports.defineAction = exports.AbstractAction = void 0;
23
23
  var abstract_action_1 = require("./action/abstract-action");
24
24
  Object.defineProperty(exports, "AbstractAction", { enumerable: true, get: function () { return abstract_action_1.AbstractAction; } });
25
25
  var action_1 = require("./action/action");
@@ -52,3 +52,6 @@ Object.defineProperty(exports, "toSnakeCase", { enumerable: true, get: function
52
52
  var timeout_1 = require("./utils/timeout");
53
53
  Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return timeout_1.sleep; } });
54
54
  Object.defineProperty(exports, "withTimeout", { enumerable: true, get: function () { return timeout_1.withTimeout; } });
55
+ var workflow_definition_resources_1 = require("./utils/workflow-definition-resources");
56
+ Object.defineProperty(exports, "collectWorkflowDefinitionResourceRefs", { enumerable: true, get: function () { return workflow_definition_resources_1.collectWorkflowDefinitionResourceRefs; } });
57
+ Object.defineProperty(exports, "remapWorkflowDefinitionResourceRefs", { enumerable: true, get: function () { return workflow_definition_resources_1.remapWorkflowDefinitionResourceRefs; } });
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /*
3
+ * Hexabot — Fair Core License (FCL-1.0-ALv2)
4
+ * Copyright (c) 2026 Hexastack.
5
+ * Full terms: see LICENSE.md.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.remapWorkflowDefinitionResourceRefs = exports.collectWorkflowDefinitionResourceRefs = void 0;
9
+ const getSettingsRef = (definition, settingsKey) => {
10
+ const settings = definition.settings;
11
+ if (!settings || typeof settings !== 'object') {
12
+ return null;
13
+ }
14
+ const value = settings[settingsKey];
15
+ return typeof value === 'string' && value.trim() ? value : null;
16
+ };
17
+ /**
18
+ * Collect external resource IDs referenced by workflow definition defs.
19
+ */
20
+ const collectWorkflowDefinitionResourceRefs = (definition, descriptors) => {
21
+ const result = Object.fromEntries(descriptors.map((descriptor) => [descriptor.kind, new Set()]));
22
+ for (const def of Object.values(definition.defs ?? {})) {
23
+ for (const descriptor of descriptors) {
24
+ if (def.kind !== descriptor.kind) {
25
+ continue;
26
+ }
27
+ const ref = getSettingsRef(def, descriptor.settingsKey);
28
+ if (ref) {
29
+ result[descriptor.kind].add(ref);
30
+ }
31
+ }
32
+ }
33
+ return Object.fromEntries(Object.entries(result).map(([kind, refs]) => [kind, Array.from(refs)]));
34
+ };
35
+ exports.collectWorkflowDefinitionResourceRefs = collectWorkflowDefinitionResourceRefs;
36
+ /**
37
+ * Rewrite external resource IDs referenced by workflow definition defs.
38
+ */
39
+ const remapWorkflowDefinitionResourceRefs = (definition, descriptors, idMaps) => {
40
+ let didChange = false;
41
+ const nextDefs = Object.fromEntries(Object.entries(definition.defs ?? {}).map(([defName, def]) => {
42
+ const descriptor = descriptors.find((item) => item.kind === def.kind);
43
+ if (!descriptor) {
44
+ return [defName, def];
45
+ }
46
+ const currentRef = getSettingsRef(def, descriptor.settingsKey);
47
+ const nextRef = currentRef
48
+ ? idMaps[descriptor.kind]?.[currentRef]
49
+ : undefined;
50
+ if (!currentRef || !nextRef || nextRef === currentRef) {
51
+ return [defName, def];
52
+ }
53
+ didChange = true;
54
+ return [
55
+ defName,
56
+ {
57
+ ...def,
58
+ settings: {
59
+ ...(def.settings ?? {}),
60
+ [descriptor.settingsKey]: nextRef,
61
+ },
62
+ },
63
+ ];
64
+ }));
65
+ if (!didChange) {
66
+ return definition;
67
+ }
68
+ return {
69
+ ...definition,
70
+ defs: nextDefs,
71
+ };
72
+ };
73
+ exports.remapWorkflowDefinitionResourceRefs = remapWorkflowDefinitionResourceRefs;
package/dist/esm/index.js CHANGED
@@ -14,3 +14,4 @@ export { compileValue, evaluateMapping, evaluateValue, mergeSettings, } from './
14
14
  export { createDeferred } from './utils/deferred';
15
15
  export { assertSnakeCaseName, isSnakeCaseName, toSnakeCase, } from './utils/naming';
16
16
  export { sleep, withTimeout } from './utils/timeout';
17
+ export { collectWorkflowDefinitionResourceRefs, remapWorkflowDefinitionResourceRefs, } from './utils/workflow-definition-resources';
@@ -0,0 +1,68 @@
1
+ /*
2
+ * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
+ * Copyright (c) 2026 Hexastack.
4
+ * Full terms: see LICENSE.md.
5
+ */
6
+ const getSettingsRef = (definition, settingsKey) => {
7
+ const settings = definition.settings;
8
+ if (!settings || typeof settings !== 'object') {
9
+ return null;
10
+ }
11
+ const value = settings[settingsKey];
12
+ return typeof value === 'string' && value.trim() ? value : null;
13
+ };
14
+ /**
15
+ * Collect external resource IDs referenced by workflow definition defs.
16
+ */
17
+ export const collectWorkflowDefinitionResourceRefs = (definition, descriptors) => {
18
+ const result = Object.fromEntries(descriptors.map((descriptor) => [descriptor.kind, new Set()]));
19
+ for (const def of Object.values(definition.defs ?? {})) {
20
+ for (const descriptor of descriptors) {
21
+ if (def.kind !== descriptor.kind) {
22
+ continue;
23
+ }
24
+ const ref = getSettingsRef(def, descriptor.settingsKey);
25
+ if (ref) {
26
+ result[descriptor.kind].add(ref);
27
+ }
28
+ }
29
+ }
30
+ return Object.fromEntries(Object.entries(result).map(([kind, refs]) => [kind, Array.from(refs)]));
31
+ };
32
+ /**
33
+ * Rewrite external resource IDs referenced by workflow definition defs.
34
+ */
35
+ export const remapWorkflowDefinitionResourceRefs = (definition, descriptors, idMaps) => {
36
+ let didChange = false;
37
+ const nextDefs = Object.fromEntries(Object.entries(definition.defs ?? {}).map(([defName, def]) => {
38
+ const descriptor = descriptors.find((item) => item.kind === def.kind);
39
+ if (!descriptor) {
40
+ return [defName, def];
41
+ }
42
+ const currentRef = getSettingsRef(def, descriptor.settingsKey);
43
+ const nextRef = currentRef
44
+ ? idMaps[descriptor.kind]?.[currentRef]
45
+ : undefined;
46
+ if (!currentRef || !nextRef || nextRef === currentRef) {
47
+ return [defName, def];
48
+ }
49
+ didChange = true;
50
+ return [
51
+ defName,
52
+ {
53
+ ...def,
54
+ settings: {
55
+ ...(def.settings ?? {}),
56
+ [descriptor.settingsKey]: nextRef,
57
+ },
58
+ },
59
+ ];
60
+ }));
61
+ if (!didChange) {
62
+ return definition;
63
+ }
64
+ return {
65
+ ...definition,
66
+ defs: nextDefs,
67
+ };
68
+ };
@@ -15,4 +15,5 @@ export { createDeferred } from './utils/deferred';
15
15
  export type { Deferred } from './utils/deferred';
16
16
  export { assertSnakeCaseName, isSnakeCaseName, toSnakeCase, } from './utils/naming';
17
17
  export { sleep, withTimeout } from './utils/timeout';
18
+ export { collectWorkflowDefinitionResourceRefs, remapWorkflowDefinitionResourceRefs, type WorkflowDefinitionResourceDescriptor, type WorkflowDefinitionResourceIdMaps, type WorkflowDefinitionResourceRefs, } from './utils/workflow-definition-resources';
18
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,YAAY,EACV,MAAM,EACN,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,EACd,OAAO,EACP,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,GACtB,MAAM,WAAW,CAAC;AAEnB,cAAc,aAAa,CAAC;AAE5B,YAAY,EACV,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,eAAe,EACf,QAAQ,EACR,oBAAoB,EACpB,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,YAAY,EACV,QAAQ,EACR,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAElC,YAAY,EACV,QAAQ,IAAI,gBAAgB,EAC5B,iBAAiB,IAAI,y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BAA6B,EAClC,KAAK,uBAAuB,GAC7B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,YAAY,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,WAAW,GACZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EACL,qCAAqC,EACrC,mCAAmC,EACnC,KAAK,oCAAoC,EACzC,KAAK,gCAAgC,EACrC,KAAK,8BAA8B,GACpC,MAAM,uCAAuC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { WorkflowDefinition } from '../dsl.types';
2
+ export type WorkflowDefinitionResourceDescriptor = {
3
+ kind: string;
4
+ settingsKey: string;
5
+ };
6
+ export type WorkflowDefinitionResourceRefs = Record<string, string[]>;
7
+ export type WorkflowDefinitionResourceIdMaps = Record<string, Record<string, string>>;
8
+ /**
9
+ * Collect external resource IDs referenced by workflow definition defs.
10
+ */
11
+ export declare const collectWorkflowDefinitionResourceRefs: (definition: WorkflowDefinition, descriptors: WorkflowDefinitionResourceDescriptor[]) => WorkflowDefinitionResourceRefs;
12
+ /**
13
+ * Rewrite external resource IDs referenced by workflow definition defs.
14
+ */
15
+ export declare const remapWorkflowDefinitionResourceRefs: (definition: WorkflowDefinition, descriptors: WorkflowDefinitionResourceDescriptor[], idMaps: WorkflowDefinitionResourceIdMaps) => WorkflowDefinition;
16
+ //# sourceMappingURL=workflow-definition-resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-definition-resources.d.ts","sourceRoot":"","sources":["../../../src/utils/workflow-definition-resources.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAiB,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEtE,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAEtE,MAAM,MAAM,gCAAgC,GAAG,MAAM,CACnD,MAAM,EACN,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CACvB,CAAC;AAgBF;;GAEG;AACH,eAAO,MAAM,qCAAqC,GAChD,YAAY,kBAAkB,EAC9B,aAAa,oCAAoC,EAAE,KAClD,8BAqBF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mCAAmC,GAC9C,YAAY,kBAAkB,EAC9B,aAAa,oCAAoC,EAAE,EACnD,QAAQ,gCAAgC,KACvC,kBAwCF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexabot-ai/agentic",
3
- "version": "3.1.2-alpha.10",
3
+ "version": "3.1.2-alpha.12",
4
4
  "description": "Schemas and utilities for the Hexabot agentic workflow DSL.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -0,0 +1,97 @@
1
+ /*
2
+ * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
+ * Copyright (c) 2026 Hexastack.
4
+ * Full terms: see LICENSE.md.
5
+ */
6
+
7
+ import type { WorkflowDefinition } from '../dsl.types';
8
+ import {
9
+ collectWorkflowDefinitionResourceRefs,
10
+ remapWorkflowDefinitionResourceRefs,
11
+ type WorkflowDefinitionResourceDescriptor,
12
+ } from '../utils/workflow-definition-resources';
13
+
14
+ const descriptors: WorkflowDefinitionResourceDescriptor[] = [
15
+ { kind: 'memory', settingsKey: 'definition_id' },
16
+ { kind: 'mcp', settingsKey: 'server_id' },
17
+ ];
18
+ const definition: WorkflowDefinition = {
19
+ defs: {
20
+ profile_memory: {
21
+ kind: 'memory',
22
+ settings: {
23
+ definition_id: 'memory-1',
24
+ },
25
+ },
26
+ duplicate_profile_memory: {
27
+ kind: 'memory',
28
+ settings: {
29
+ definition_id: 'memory-1',
30
+ },
31
+ },
32
+ search_mcp: {
33
+ kind: 'mcp',
34
+ settings: {
35
+ server_id: 'mcp-1',
36
+ },
37
+ },
38
+ greet: {
39
+ kind: 'task',
40
+ action: 'send_message',
41
+ bindings: {
42
+ memory: ['profile_memory'],
43
+ mcp: ['search_mcp'],
44
+ },
45
+ },
46
+ },
47
+ flow: [{ do: 'greet' }],
48
+ outputs: { result: '=$output.greet' },
49
+ };
50
+
51
+ describe('workflow definition resource helpers', () => {
52
+ it('collects unique resource references by descriptor kind', () => {
53
+ expect(
54
+ collectWorkflowDefinitionResourceRefs(definition, descriptors),
55
+ ).toEqual({
56
+ memory: ['memory-1'],
57
+ mcp: ['mcp-1'],
58
+ });
59
+ });
60
+
61
+ it('remaps resource references without mutating the original definition', () => {
62
+ const updated = remapWorkflowDefinitionResourceRefs(
63
+ definition,
64
+ descriptors,
65
+ {
66
+ memory: { 'memory-1': 'memory-local' },
67
+ mcp: { 'mcp-1': 'mcp-local' },
68
+ },
69
+ );
70
+
71
+ expect(updated).not.toBe(definition);
72
+ expect(updated.defs.profile_memory.settings).toEqual({
73
+ definition_id: 'memory-local',
74
+ });
75
+ expect(updated.defs.duplicate_profile_memory.settings).toEqual({
76
+ definition_id: 'memory-local',
77
+ });
78
+ expect(updated.defs.search_mcp.settings).toEqual({
79
+ server_id: 'mcp-local',
80
+ });
81
+ expect(definition.defs.profile_memory.settings).toEqual({
82
+ definition_id: 'memory-1',
83
+ });
84
+ expect(definition.defs.search_mcp.settings).toEqual({
85
+ server_id: 'mcp-1',
86
+ });
87
+ });
88
+
89
+ it('returns the original definition when no refs change', () => {
90
+ expect(
91
+ remapWorkflowDefinitionResourceRefs(definition, descriptors, {
92
+ memory: {},
93
+ mcp: {},
94
+ }),
95
+ ).toBe(definition);
96
+ });
97
+ });
package/src/index.ts CHANGED
@@ -114,3 +114,11 @@ export {
114
114
  } from './utils/naming';
115
115
 
116
116
  export { sleep, withTimeout } from './utils/timeout';
117
+
118
+ export {
119
+ collectWorkflowDefinitionResourceRefs,
120
+ remapWorkflowDefinitionResourceRefs,
121
+ type WorkflowDefinitionResourceDescriptor,
122
+ type WorkflowDefinitionResourceIdMaps,
123
+ type WorkflowDefinitionResourceRefs,
124
+ } from './utils/workflow-definition-resources';
@@ -0,0 +1,111 @@
1
+ /*
2
+ * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
+ * Copyright (c) 2026 Hexastack.
4
+ * Full terms: see LICENSE.md.
5
+ */
6
+
7
+ import type { DefDefinition, WorkflowDefinition } from '../dsl.types';
8
+
9
+ export type WorkflowDefinitionResourceDescriptor = {
10
+ kind: string;
11
+ settingsKey: string;
12
+ };
13
+
14
+ export type WorkflowDefinitionResourceRefs = Record<string, string[]>;
15
+
16
+ export type WorkflowDefinitionResourceIdMaps = Record<
17
+ string,
18
+ Record<string, string>
19
+ >;
20
+
21
+ const getSettingsRef = (
22
+ definition: DefDefinition,
23
+ settingsKey: string,
24
+ ): string | null => {
25
+ const settings = definition.settings;
26
+ if (!settings || typeof settings !== 'object') {
27
+ return null;
28
+ }
29
+
30
+ const value = (settings as Record<string, unknown>)[settingsKey];
31
+
32
+ return typeof value === 'string' && value.trim() ? value : null;
33
+ };
34
+
35
+ /**
36
+ * Collect external resource IDs referenced by workflow definition defs.
37
+ */
38
+ export const collectWorkflowDefinitionResourceRefs = (
39
+ definition: WorkflowDefinition,
40
+ descriptors: WorkflowDefinitionResourceDescriptor[],
41
+ ): WorkflowDefinitionResourceRefs => {
42
+ const result = Object.fromEntries(
43
+ descriptors.map((descriptor) => [descriptor.kind, new Set<string>()]),
44
+ ) as Record<string, Set<string>>;
45
+
46
+ for (const def of Object.values(definition.defs ?? {})) {
47
+ for (const descriptor of descriptors) {
48
+ if (def.kind !== descriptor.kind) {
49
+ continue;
50
+ }
51
+
52
+ const ref = getSettingsRef(def, descriptor.settingsKey);
53
+ if (ref) {
54
+ result[descriptor.kind].add(ref);
55
+ }
56
+ }
57
+ }
58
+
59
+ return Object.fromEntries(
60
+ Object.entries(result).map(([kind, refs]) => [kind, Array.from(refs)]),
61
+ );
62
+ };
63
+
64
+ /**
65
+ * Rewrite external resource IDs referenced by workflow definition defs.
66
+ */
67
+ export const remapWorkflowDefinitionResourceRefs = (
68
+ definition: WorkflowDefinition,
69
+ descriptors: WorkflowDefinitionResourceDescriptor[],
70
+ idMaps: WorkflowDefinitionResourceIdMaps,
71
+ ): WorkflowDefinition => {
72
+ let didChange = false;
73
+ const nextDefs = Object.fromEntries(
74
+ Object.entries(definition.defs ?? {}).map(([defName, def]) => {
75
+ const descriptor = descriptors.find((item) => item.kind === def.kind);
76
+ if (!descriptor) {
77
+ return [defName, def];
78
+ }
79
+
80
+ const currentRef = getSettingsRef(def, descriptor.settingsKey);
81
+ const nextRef = currentRef
82
+ ? idMaps[descriptor.kind]?.[currentRef]
83
+ : undefined;
84
+ if (!currentRef || !nextRef || nextRef === currentRef) {
85
+ return [defName, def];
86
+ }
87
+
88
+ didChange = true;
89
+
90
+ return [
91
+ defName,
92
+ {
93
+ ...def,
94
+ settings: {
95
+ ...(def.settings ?? {}),
96
+ [descriptor.settingsKey]: nextRef,
97
+ },
98
+ },
99
+ ];
100
+ }),
101
+ ) as WorkflowDefinition['defs'];
102
+
103
+ if (!didChange) {
104
+ return definition;
105
+ }
106
+
107
+ return {
108
+ ...definition,
109
+ defs: nextDefs,
110
+ };
111
+ };