@siduri-x/core 1.0.3 → 1.0.4
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/action-policy.js +9 -2
- package/dist/action-policy.test.js +37 -0
- package/dist/chat-contract.d.ts +0 -1
- package/dist/chat-contract.js +4 -2
- package/dist/runtime.js +0 -1
- package/package.json +1 -1
package/dist/action-policy.js
CHANGED
|
@@ -73,10 +73,17 @@ class ActionPolicyEngine {
|
|
|
73
73
|
await this.recordAudit(action, undefined, decision, 'REJECTED');
|
|
74
74
|
return { decision };
|
|
75
75
|
}
|
|
76
|
-
// Role check if tool restricts roles
|
|
76
|
+
// Role check if tool restricts roles (supports administrator/owner role parity)
|
|
77
77
|
if (toolDef.allowedRoles && toolDef.allowedRoles.length > 0) {
|
|
78
78
|
const actorRole = effectiveContext.actor.authorizationRole;
|
|
79
|
-
|
|
79
|
+
const normalizedActorRoles = new Set([actorRole.toLowerCase()]);
|
|
80
|
+
if (actorRole === 'administrator' || actorRole === 'owner') {
|
|
81
|
+
normalizedActorRoles.add('administrator');
|
|
82
|
+
normalizedActorRoles.add('owner');
|
|
83
|
+
normalizedActorRoles.add('admin');
|
|
84
|
+
}
|
|
85
|
+
const isAuthorizedRole = toolDef.allowedRoles.some((r) => normalizedActorRoles.has(r.toLowerCase()));
|
|
86
|
+
if (!isAuthorizedRole) {
|
|
80
87
|
const decision = {
|
|
81
88
|
allowed: false,
|
|
82
89
|
reason: `Actor role "${actorRole}" is not authorized to execute tool "${action.toolName}"`,
|
|
@@ -154,4 +154,41 @@ describe('ActionPolicyEngine Boundary', () => {
|
|
|
154
154
|
expect(log?.parametersHash).toBeDefined();
|
|
155
155
|
expect(log?.resultHash).toBeDefined();
|
|
156
156
|
});
|
|
157
|
+
it('supports single-owner role parity between owner and administrator', async () => {
|
|
158
|
+
const ownerTool = {
|
|
159
|
+
name: 'builtin/owner_tool',
|
|
160
|
+
description: 'Owner only tool',
|
|
161
|
+
inputSchema: {},
|
|
162
|
+
riskLevel: 'LOW',
|
|
163
|
+
allowedRoles: ['owner'],
|
|
164
|
+
};
|
|
165
|
+
engine.registerToolDefinition(ownerTool);
|
|
166
|
+
// Context with authorizationRole: 'administrator'
|
|
167
|
+
const adminContext = {
|
|
168
|
+
...sampleContext,
|
|
169
|
+
actor: {
|
|
170
|
+
...sampleContext.actor,
|
|
171
|
+
authorizationRole: 'administrator',
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
const actionWithAdmin = {
|
|
175
|
+
actionId: 'act-owner-admin',
|
|
176
|
+
toolName: 'builtin/owner_tool',
|
|
177
|
+
parameters: {},
|
|
178
|
+
context: adminContext,
|
|
179
|
+
};
|
|
180
|
+
const res = await engine.evaluateAction(actionWithAdmin);
|
|
181
|
+
expect(res.decision.allowed).toBe(true);
|
|
182
|
+
expect(res.capability).toBeDefined();
|
|
183
|
+
// Context with authorizationRole: 'operator' (non-owner) is rejected
|
|
184
|
+
const operatorAction = {
|
|
185
|
+
actionId: 'act-owner-op',
|
|
186
|
+
toolName: 'builtin/owner_tool',
|
|
187
|
+
parameters: {},
|
|
188
|
+
context: sampleContext, // has authorizationRole: 'operator'
|
|
189
|
+
};
|
|
190
|
+
const resOp = await engine.evaluateAction(operatorAction);
|
|
191
|
+
expect(resOp.decision.allowed).toBe(false);
|
|
192
|
+
expect(resOp.decision.decisionCode).toBe('REJECTED_UNAUTHORIZED');
|
|
193
|
+
});
|
|
157
194
|
});
|
package/dist/chat-contract.d.ts
CHANGED
package/dist/chat-contract.js
CHANGED
|
@@ -20,10 +20,10 @@ async function dispatchCompanionChat(runtime, payload) {
|
|
|
20
20
|
? 'OWNER'
|
|
21
21
|
: authRole === 'operator'
|
|
22
22
|
? 'OPERATOR'
|
|
23
|
-
: 'VIEWER';
|
|
23
|
+
: (authRole === 'viewer' ? 'VIEWER' : 'OWNER');
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
roleOrContext = '
|
|
26
|
+
roleOrContext = 'OWNER';
|
|
27
27
|
}
|
|
28
28
|
const runtimeResult = await runtime.handleUserMessage(userMessage, roleOrContext, history);
|
|
29
29
|
// Normalize response plan
|
|
@@ -48,6 +48,8 @@ async function dispatchCompanionChat(runtime, payload) {
|
|
|
48
48
|
const metadata = {
|
|
49
49
|
...(runtimeResult?.metadata || {}),
|
|
50
50
|
};
|
|
51
|
+
delete metadata.internal_monologue;
|
|
52
|
+
delete metadata.internalMonologue;
|
|
51
53
|
return {
|
|
52
54
|
status: runtimeResult?.status || 'APPROVED',
|
|
53
55
|
response_id: runtimeResult?.response_id,
|
package/dist/runtime.js
CHANGED
package/package.json
CHANGED