@bpmsoftwaresolutions/ai-engine-client 1.1.87 → 1.1.89
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/package.json +1 -1
- package/src/client.js +192 -4903
- package/src/domains/charters.js +5 -0
- package/src/domains/claims.js +58 -0
- package/src/domains/commit-governance.js +68 -0
- package/src/domains/context-orientation.js +48 -0
- package/src/domains/context-sessions.js +46 -0
- package/src/domains/execution-eligibility.js +44 -0
- package/src/domains/governed-implementation.js +7 -0
- package/src/domains/implementation-artifacts.js +61 -0
- package/src/domains/implementation-checks.js +41 -0
- package/src/domains/implementation-items.js +82 -89
- package/src/domains/implementation-packets.js +173 -0
- package/src/domains/implementation-tasks.js +125 -6
- package/src/domains/portfolio.js +125 -1
- package/src/domains/project-chartering.js +18 -0
- package/src/domains/project-reports.js +14 -0
- package/src/domains/project-resume.js +18 -0
- package/src/domains/projects.js +348 -24
- package/src/domains/roadmap-reports.js +6 -0
- package/src/domains/session-governance.js +64 -0
- package/src/domains/tool-binding-approvals.js +102 -0
- package/src/domains/verified-mutations.js +7 -0
- package/src/domains/work-start.js +192 -0
- package/src/domains/workflow-composition.js +3416 -7
- package/src/domains/workflow-turns.js +6 -0
- package/src/index.js +1 -1
- package/src/utils/task-binding.js +31 -0
- package/src/utils/verified-mutations.js +128 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { cleanList, cleanText, isPlainObject } from '../utils/text.js';
|
|
2
|
+
import { normalizeMetadataTaskBinding, normalizeTaskBindingPolicy } from '../utils/task-binding.js';
|
|
3
|
+
import { contextSessionIdFromInput } from './context-sessions.js';
|
|
4
|
+
|
|
5
|
+
function isActiveBinding(binding) {
|
|
6
|
+
return binding !== null && typeof binding === 'object' && !Array.isArray(binding) && (
|
|
7
|
+
binding.is_active === true ||
|
|
8
|
+
binding.is_active === 1 ||
|
|
9
|
+
binding.is_active === 'true' ||
|
|
10
|
+
binding.is_active === 'True'
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function activeToolKeysFromRegistry(registry) {
|
|
15
|
+
const bindings = Array.isArray(registry?.bindings) ? registry.bindings : [];
|
|
16
|
+
const seen = new Set();
|
|
17
|
+
const keys = [];
|
|
18
|
+
for (const binding of bindings) {
|
|
19
|
+
if (!isActiveBinding(binding)) continue;
|
|
20
|
+
const key = cleanText(binding.tool_key);
|
|
21
|
+
if (!key || seen.has(key)) continue;
|
|
22
|
+
seen.add(key);
|
|
23
|
+
keys.push(key);
|
|
24
|
+
}
|
|
25
|
+
return keys;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function reminderTokens(reminders) {
|
|
29
|
+
const tokens = [];
|
|
30
|
+
for (const reminder of Array.isArray(reminders) ? reminders : []) {
|
|
31
|
+
if (reminder === null || typeof reminder !== 'object' || Array.isArray(reminder)) continue;
|
|
32
|
+
for (const value of [reminder.reminder_key, reminder.reminder_id]) {
|
|
33
|
+
const token = cleanText(value);
|
|
34
|
+
if (token && !tokens.includes(token)) tokens.push(token);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return tokens;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function createWorkStartDomain(client) {
|
|
41
|
+
return {
|
|
42
|
+
startWork: (body = {}) => client._request('/api/work/start', { method: 'POST', body }),
|
|
43
|
+
startClaimedWork: ({
|
|
44
|
+
claimName,
|
|
45
|
+
actorId,
|
|
46
|
+
intentId,
|
|
47
|
+
declaredScopeFiles,
|
|
48
|
+
allowedMutationSurfaces,
|
|
49
|
+
runtimeSessionId,
|
|
50
|
+
executionPurpose,
|
|
51
|
+
successCriteria,
|
|
52
|
+
mutationAllowed,
|
|
53
|
+
metadata,
|
|
54
|
+
...rest
|
|
55
|
+
} = {}) => client._request('/api/governance/claims/start-claimed-work', {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
body: {
|
|
58
|
+
...rest,
|
|
59
|
+
claim_name: claimName,
|
|
60
|
+
actor_id: actorId,
|
|
61
|
+
intent_id: intentId,
|
|
62
|
+
declared_scope_files: declaredScopeFiles,
|
|
63
|
+
allowed_mutation_surfaces: allowedMutationSurfaces,
|
|
64
|
+
runtime_session_id: runtimeSessionId,
|
|
65
|
+
execution_purpose: executionPurpose,
|
|
66
|
+
success_criteria: successCriteria,
|
|
67
|
+
mutation_allowed: mutationAllowed,
|
|
68
|
+
metadata: normalizeMetadataTaskBinding(metadata),
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
claimWorkItem: (body = {}) => {
|
|
72
|
+
const normalizedBody = body !== null && typeof body === 'object' && !Array.isArray(body)
|
|
73
|
+
? {
|
|
74
|
+
...body,
|
|
75
|
+
...(body.task_binding !== null && typeof body.task_binding === 'object' && !Array.isArray(body.task_binding)
|
|
76
|
+
? { task_binding: normalizeTaskBindingPolicy(body.task_binding) }
|
|
77
|
+
: {}),
|
|
78
|
+
metadata: normalizeMetadataTaskBinding(body.metadata),
|
|
79
|
+
}
|
|
80
|
+
: body;
|
|
81
|
+
return client._request('/api/governance/claims/claim-work-item', { method: 'POST', body: normalizedBody });
|
|
82
|
+
},
|
|
83
|
+
bindClaimedWorkItem: async ({
|
|
84
|
+
claimId,
|
|
85
|
+
contextSessionId,
|
|
86
|
+
workflowRunId,
|
|
87
|
+
agentSessionId,
|
|
88
|
+
claimedItemId,
|
|
89
|
+
claimedItemKey,
|
|
90
|
+
claimName,
|
|
91
|
+
actorId,
|
|
92
|
+
workflowId,
|
|
93
|
+
workflowSlug,
|
|
94
|
+
requiredToolKeys,
|
|
95
|
+
declaredScopeFiles,
|
|
96
|
+
allowedMutationSurfaces,
|
|
97
|
+
successCriteria,
|
|
98
|
+
acknowledgedReminders,
|
|
99
|
+
intentConfirmation,
|
|
100
|
+
actorSignature,
|
|
101
|
+
autoSignoff = true,
|
|
102
|
+
metadata,
|
|
103
|
+
} = {}) => {
|
|
104
|
+
const normalizedContextSessionId = contextSessionIdFromInput({
|
|
105
|
+
contextSessionId,
|
|
106
|
+
context_session_id: contextSessionId,
|
|
107
|
+
claim: { context_session_id: contextSessionId },
|
|
108
|
+
});
|
|
109
|
+
const normalizedClaimId = cleanText(claimId);
|
|
110
|
+
const normalizedWorkflowRunId = cleanText(workflowRunId);
|
|
111
|
+
const normalizedAgentSessionId = cleanText(agentSessionId);
|
|
112
|
+
const normalizedClaimedItemId = cleanText(claimedItemId);
|
|
113
|
+
const normalizedClaimedItemKey = cleanText(claimedItemKey);
|
|
114
|
+
const normalizedClaimedItemRef = normalizedClaimedItemId || normalizedClaimedItemKey;
|
|
115
|
+
if (!normalizedContextSessionId) throw new Error('contextSessionId is required.');
|
|
116
|
+
if (!normalizedWorkflowRunId) throw new Error('workflowRunId is required.');
|
|
117
|
+
if (!normalizedAgentSessionId) throw new Error('agentSessionId is required.');
|
|
118
|
+
if (!normalizedClaimedItemRef) throw new Error('claimedItemId or claimedItemKey is required.');
|
|
119
|
+
|
|
120
|
+
const normalizedWorkflowId = cleanText(workflowId);
|
|
121
|
+
const normalizedWorkflowSlug = cleanText(workflowSlug);
|
|
122
|
+
let normalizedRequiredToolKeys = cleanList(requiredToolKeys);
|
|
123
|
+
let workflowRegistry = null;
|
|
124
|
+
if (normalizedRequiredToolKeys.length === 0 && (normalizedWorkflowId || normalizedWorkflowSlug)) {
|
|
125
|
+
workflowRegistry = await client.getWorkflowToolRegistry({
|
|
126
|
+
workflowId: normalizedWorkflowId,
|
|
127
|
+
workflowSlug: normalizedWorkflowSlug,
|
|
128
|
+
});
|
|
129
|
+
normalizedRequiredToolKeys = activeToolKeysFromRegistry(workflowRegistry);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const lockClaimResult = await client.contextSessions.lockContextSessionClaim(normalizedContextSessionId);
|
|
133
|
+
const lockedContextSession = lockClaimResult?.context_session || lockClaimResult;
|
|
134
|
+
const lockedContextSessionId = contextSessionIdFromInput(lockedContextSession) || normalizedContextSessionId;
|
|
135
|
+
|
|
136
|
+
const claimWorkItemResult = await client.claimWorkItem({
|
|
137
|
+
context_session_id: lockedContextSessionId,
|
|
138
|
+
workflow_run_id: normalizedWorkflowRunId,
|
|
139
|
+
agent_session_id: normalizedAgentSessionId,
|
|
140
|
+
claimed_item_id: normalizedClaimedItemId,
|
|
141
|
+
claimed_item_key: normalizedClaimedItemKey,
|
|
142
|
+
claim_name: claimName,
|
|
143
|
+
actor_id: actorId,
|
|
144
|
+
workflow_id: normalizedWorkflowId,
|
|
145
|
+
workflow_slug: normalizedWorkflowSlug,
|
|
146
|
+
required_tool_keys: normalizedRequiredToolKeys,
|
|
147
|
+
declared_scope_files: cleanList(declaredScopeFiles).length > 0
|
|
148
|
+
? cleanList(declaredScopeFiles)
|
|
149
|
+
: [normalizedClaimedItemRef],
|
|
150
|
+
allowed_mutation_surfaces: cleanList(allowedMutationSurfaces).length > 0
|
|
151
|
+
? cleanList(allowedMutationSurfaces)
|
|
152
|
+
: ['project_roadmap_task'],
|
|
153
|
+
success_criteria: successCriteria,
|
|
154
|
+
metadata,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
let signedClaim = null;
|
|
158
|
+
const resolvedClaimId = cleanText(claimWorkItemResult?.claim_id) || normalizedClaimId;
|
|
159
|
+
if (autoSignoff && resolvedClaimId) {
|
|
160
|
+
const claimEnvelope = isPlainObject(claimWorkItemResult?.claim) ? claimWorkItemResult.claim : claimWorkItemResult;
|
|
161
|
+
const reminders = cleanList(acknowledgedReminders).length > 0
|
|
162
|
+
? cleanList(acknowledgedReminders)
|
|
163
|
+
: reminderTokens(claimEnvelope?.required_reminders);
|
|
164
|
+
if (reminders.length > 0) {
|
|
165
|
+
signedClaim = await client.signoffClaim(resolvedClaimId, {
|
|
166
|
+
acknowledged_reminders: reminders,
|
|
167
|
+
intent_confirmation: cleanText(intentConfirmation) || 'I confirm this governed execution intent and scope.',
|
|
168
|
+
actor_signature: cleanText(actorSignature) || cleanText(actorId) || client.actorId,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
claim_id: resolvedClaimId,
|
|
175
|
+
context_session_id: lockedContextSessionId,
|
|
176
|
+
workflow_run_id: normalizedWorkflowRunId,
|
|
177
|
+
agent_session_id: normalizedAgentSessionId,
|
|
178
|
+
required_tool_keys: normalizedRequiredToolKeys,
|
|
179
|
+
workflow_registry: workflowRegistry,
|
|
180
|
+
lock_claim_result: lockClaimResult,
|
|
181
|
+
claim_work_item_result: claimWorkItemResult,
|
|
182
|
+
signed_claim: signedClaim,
|
|
183
|
+
approved_tool_keys: cleanList(
|
|
184
|
+
signedClaim?.approved_tool_keys ||
|
|
185
|
+
signedClaim?.claim?.approved_tool_keys ||
|
|
186
|
+
claimWorkItemResult?.approved_tool_keys ||
|
|
187
|
+
claimWorkItemResult?.claim?.approved_tool_keys
|
|
188
|
+
),
|
|
189
|
+
};
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|