@bpmsoftwaresolutions/ai-engine-client 1.1.30 → 1.1.32

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +58 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bpmsoftwaresolutions/ai-engine-client",
3
- "version": "1.1.30",
3
+ "version": "1.1.32",
4
4
  "description": "Thin npm client for the AI Engine operator and retrieval APIs",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const DEFAULT_TIMEOUT_MS = 30000;
2
- export const AI_ENGINE_CLIENT_VERSION = '1.1.30';
2
+ export const AI_ENGINE_CLIENT_VERSION = '1.1.32';
3
3
  export const GOVERNED_MUTATION_REQUIRED_CAPABILITIES = [
4
4
  'executeVerifiedMutation',
5
5
  'post_mutation_verification',
@@ -19,6 +19,7 @@ export const LOGA_CONTRACT = 'ai-engine-ui/v1';
19
19
  export const LOGA_INTERACTION_CONTRACT = 'loga-choreography/v1';
20
20
  export const LOGA_NAVIGATION_CONTRACT = 'loga-navigation/v1';
21
21
  export const LOGA_PROJECTION_WORKFLOW = 'loga-document-projection';
22
+ export const TASK_BOUND_SUBSTRATE_EXECUTION_POLICY = 'task_bound_substrate_execution/v1';
22
23
 
23
24
  function trimTrailingSlash(value) {
24
25
  return String(value || '').replace(/\/+$/, '');
@@ -122,6 +123,35 @@ function isPlainObject(value) {
122
123
  return value !== null && typeof value === 'object' && !Array.isArray(value);
123
124
  }
124
125
 
126
+ function normalizeTaskBindingPolicy(taskBinding, { expectedAction = null } = {}) {
127
+ if (!isPlainObject(taskBinding)) return taskBinding;
128
+ const taskId = cleanText(taskBinding.task_id || taskBinding.implementation_item_task_id);
129
+ const roadmapItemId = cleanText(taskBinding.roadmap_item_id || taskBinding.implementation_item_id);
130
+ const taskStatus = cleanText(taskBinding.task_status || taskBinding.status);
131
+ const allowedActions = cleanList(taskBinding.allowed_actions);
132
+ const substrateAction = cleanText(taskBinding.substrate_action) || cleanText(expectedAction);
133
+ return {
134
+ ...taskBinding,
135
+ ...(taskId ? { task_id: taskId } : {}),
136
+ ...(roadmapItemId ? { roadmap_item_id: roadmapItemId, implementation_item_id: roadmapItemId } : {}),
137
+ ...(taskStatus ? { task_status: taskStatus } : {}),
138
+ ...(allowedActions.length > 0 ? { allowed_actions: allowedActions } : {}),
139
+ ...(substrateAction ? { substrate_action: substrateAction } : {}),
140
+ policy_key: cleanText(taskBinding.policy_key) || 'task_bound_substrate_execution',
141
+ policy_version: cleanText(taskBinding.policy_version) || 'v1',
142
+ policy_identifier: cleanText(taskBinding.policy_identifier) || TASK_BOUND_SUBSTRATE_EXECUTION_POLICY,
143
+ };
144
+ }
145
+
146
+ function normalizeMetadataTaskBinding(metadata, { expectedAction = null } = {}) {
147
+ if (!isPlainObject(metadata)) return metadata;
148
+ if (!isPlainObject(metadata.task_binding)) return metadata;
149
+ return {
150
+ ...metadata,
151
+ task_binding: normalizeTaskBindingPolicy(metadata.task_binding, { expectedAction }),
152
+ };
153
+ }
154
+
125
155
  function isActiveBinding(binding) {
126
156
  return isPlainObject(binding) && (
127
157
  binding.is_active === true ||
@@ -497,13 +527,22 @@ export class AIEngineClient {
497
527
  execution_purpose: executionPurpose,
498
528
  success_criteria: successCriteria,
499
529
  mutation_allowed: mutationAllowed,
500
- metadata,
530
+ metadata: normalizeMetadataTaskBinding(metadata),
501
531
  },
502
532
  });
503
533
  }
504
534
 
505
535
  async claimWorkItem(body = {}) {
506
- return this._request('/api/governance/claims/claim-work-item', { method: 'POST', body });
536
+ const normalizedBody = isPlainObject(body)
537
+ ? {
538
+ ...body,
539
+ ...(isPlainObject(body.task_binding)
540
+ ? { task_binding: normalizeTaskBindingPolicy(body.task_binding) }
541
+ : {}),
542
+ metadata: normalizeMetadataTaskBinding(body.metadata),
543
+ }
544
+ : body;
545
+ return this._request('/api/governance/claims/claim-work-item', { method: 'POST', body: normalizedBody });
507
546
  }
508
547
 
509
548
  async bindClaimedWorkItem({
@@ -871,6 +910,22 @@ export class AIEngineClient {
871
910
  });
872
911
  }
873
912
 
913
+ async routeImplementationItem(implementationItemId, body = {}) {
914
+ if (!implementationItemId) throw new Error('implementationItemId is required.');
915
+ const normalizedBody = isPlainObject(body)
916
+ ? {
917
+ ...body,
918
+ ...(isPlainObject(body.task_binding)
919
+ ? { task_binding: normalizeTaskBindingPolicy(body.task_binding) }
920
+ : {}),
921
+ }
922
+ : body;
923
+ return this._request(`/api/governed-implementation/items/${encodeURIComponent(implementationItemId)}/routing`, {
924
+ method: 'PATCH',
925
+ body: normalizedBody,
926
+ });
927
+ }
928
+
874
929
  async persistAssistantTurn(body) {
875
930
  return this._request('/api/v1/assistant-turns', { method: 'POST', body });
876
931
  }