@sidurijs/core 1.0.0
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-executor.d.ts +12 -0
- package/dist/action-executor.js +54 -0
- package/dist/action-policy.d.ts +79 -0
- package/dist/action-policy.js +439 -0
- package/dist/action-policy.test.d.ts +1 -0
- package/dist/action-policy.test.js +363 -0
- package/dist/action.d.ts +72 -0
- package/dist/action.js +2 -0
- package/dist/adversarial.test.d.ts +1 -0
- package/dist/adversarial.test.js +491 -0
- package/dist/architecture-boundary.test.d.ts +1 -0
- package/dist/architecture-boundary.test.js +108 -0
- package/dist/capability.d.ts +78 -0
- package/dist/capability.js +168 -0
- package/dist/capability.test.d.ts +1 -0
- package/dist/capability.test.js +311 -0
- package/dist/chat-contract.d.ts +94 -0
- package/dist/chat-contract.js +104 -0
- package/dist/cognition-planner.d.ts +15 -0
- package/dist/cognition-planner.js +23 -0
- package/dist/container.d.ts +74 -0
- package/dist/container.js +81 -0
- package/dist/context-retriever.d.ts +33 -0
- package/dist/context-retriever.js +260 -0
- package/dist/context.d.ts +46 -0
- package/dist/context.js +85 -0
- package/dist/context.test.d.ts +1 -0
- package/dist/context.test.js +76 -0
- package/dist/conversational-teach.test.d.ts +1 -0
- package/dist/conversational-teach.test.js +941 -0
- package/dist/database.d.ts +1 -0
- package/dist/database.js +17 -0
- package/dist/dispatcher.d.ts +14 -0
- package/dist/dispatcher.js +40 -0
- package/dist/dispatcher.test.d.ts +1 -0
- package/dist/dispatcher.test.js +58 -0
- package/dist/ear-types.d.ts +33 -0
- package/dist/ear-types.js +2 -0
- package/dist/evidence.d.ts +76 -0
- package/dist/evidence.js +27 -0
- package/dist/evidence.test.d.ts +1 -0
- package/dist/evidence.test.js +75 -0
- package/dist/experience-emitter.d.ts +21 -0
- package/dist/experience-emitter.js +47 -0
- package/dist/experience.d.ts +55 -0
- package/dist/experience.js +74 -0
- package/dist/experience.test.d.ts +1 -0
- package/dist/experience.test.js +55 -0
- package/dist/gating.d.ts +45 -0
- package/dist/gating.js +185 -0
- package/dist/gating.test.d.ts +1 -0
- package/dist/gating.test.js +186 -0
- package/dist/index.d.ts +367 -0
- package/dist/index.js +56 -0
- package/dist/input-normalizer.d.ts +14 -0
- package/dist/input-normalizer.js +76 -0
- package/dist/input-normalizer.test.d.ts +1 -0
- package/dist/input-normalizer.test.js +48 -0
- package/dist/intent-classifier.d.ts +37 -0
- package/dist/intent-classifier.js +150 -0
- package/dist/intent-classifier.test.d.ts +1 -0
- package/dist/intent-classifier.test.js +118 -0
- package/dist/memory-settler.d.ts +49 -0
- package/dist/memory-settler.js +161 -0
- package/dist/mouth-types.d.ts +90 -0
- package/dist/mouth-types.js +2 -0
- package/dist/perception-cycle.test.d.ts +1 -0
- package/dist/perception-cycle.test.js +301 -0
- package/dist/perception-pipeline.d.ts +77 -0
- package/dist/perception-pipeline.js +304 -0
- package/dist/perception-pipeline.test.d.ts +1 -0
- package/dist/perception-pipeline.test.js +65 -0
- package/dist/prompt-compiler.d.ts +26 -0
- package/dist/prompt-compiler.js +81 -0
- package/dist/prompt-compiler.test.d.ts +1 -0
- package/dist/prompt-compiler.test.js +90 -0
- package/dist/proposals.d.ts +33 -0
- package/dist/proposals.js +2 -0
- package/dist/response-envelope.d.ts +30 -0
- package/dist/response-envelope.js +90 -0
- package/dist/runtime-facades.test.d.ts +1 -0
- package/dist/runtime-facades.test.js +95 -0
- package/dist/runtime.d.ts +116 -0
- package/dist/runtime.js +778 -0
- package/dist/schema-validator.d.ts +9 -0
- package/dist/schema-validator.js +107 -0
- package/dist/schema-validator.test.d.ts +1 -0
- package/dist/schema-validator.test.js +124 -0
- package/dist/session-history.d.ts +20 -0
- package/dist/session-history.js +55 -0
- package/dist/session-history.test.d.ts +1 -0
- package/dist/session-history.test.js +38 -0
- package/dist/siduri-db.d.ts +235 -0
- package/dist/siduri-db.js +1405 -0
- package/dist/siduri-db.test.d.ts +1 -0
- package/dist/siduri-db.test.js +1021 -0
- package/dist/sqlite-action-store.d.ts +21 -0
- package/dist/sqlite-action-store.js +281 -0
- package/dist/sqlite-action-store.test.d.ts +1 -0
- package/dist/sqlite-action-store.test.js +261 -0
- package/dist/teaching.d.ts +14 -0
- package/dist/teaching.js +14 -0
- package/package.json +43 -0
package/dist/context.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Single-owner, single-machine context model
|
|
3
|
+
// Security perimeter is the local machine boundary (external vs internal).
|
|
4
|
+
// No internal audience, viewer, or owner role hierarchies.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isValidSubjectKind = isValidSubjectKind;
|
|
7
|
+
exports.validateRequestContext = validateRequestContext;
|
|
8
|
+
function isValidSubjectKind(kind) {
|
|
9
|
+
return kind === 'actor' || kind === 'companion' || kind === 'configured';
|
|
10
|
+
}
|
|
11
|
+
function validateRequestContext(context) {
|
|
12
|
+
if (!context || typeof context !== 'object') {
|
|
13
|
+
return {
|
|
14
|
+
accepted: false,
|
|
15
|
+
error: {
|
|
16
|
+
code: 'MISSING_CONTEXT',
|
|
17
|
+
fields: ['context'],
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const ctx = context;
|
|
22
|
+
const missingFields = [];
|
|
23
|
+
if (!ctx.companionId || typeof ctx.companionId !== 'string' || ctx.companionId.trim() === '') {
|
|
24
|
+
missingFields.push('companionId');
|
|
25
|
+
}
|
|
26
|
+
if (!ctx.actor || typeof ctx.actor !== 'object') {
|
|
27
|
+
missingFields.push('actor');
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
if (!ctx.actor.actorId || typeof ctx.actor.actorId !== 'string' || ctx.actor.actorId.trim() === '') {
|
|
31
|
+
missingFields.push('actor.actorId');
|
|
32
|
+
}
|
|
33
|
+
if (!ctx.actor.sessionId || typeof ctx.actor.sessionId !== 'string' || ctx.actor.sessionId.trim() === '') {
|
|
34
|
+
missingFields.push('actor.sessionId');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!ctx.conversation || typeof ctx.conversation !== 'object') {
|
|
38
|
+
missingFields.push('conversation');
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
if (!ctx.conversation.correlationId || typeof ctx.conversation.correlationId !== 'string' || ctx.conversation.correlationId.trim() === '') {
|
|
42
|
+
missingFields.push('conversation.correlationId');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (ctx.subject !== undefined) {
|
|
46
|
+
if (!ctx.subject || typeof ctx.subject !== 'object') {
|
|
47
|
+
missingFields.push('subject');
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
if (!ctx.subject.subjectId || typeof ctx.subject.subjectId !== 'string' || ctx.subject.subjectId.trim() === '') {
|
|
51
|
+
missingFields.push('subject.subjectId');
|
|
52
|
+
}
|
|
53
|
+
if (!isValidSubjectKind(ctx.subject.kind)) {
|
|
54
|
+
missingFields.push('subject.kind');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (ctx.mode !== undefined) {
|
|
59
|
+
if (ctx.mode !== 'casual' && ctx.mode !== 'teach' && ctx.mode !== 'hybrid') {
|
|
60
|
+
return {
|
|
61
|
+
accepted: false,
|
|
62
|
+
error: {
|
|
63
|
+
code: 'INVALID_CONTEXT',
|
|
64
|
+
message: `Invalid interaction mode: '${ctx.mode}' (expected 'casual', 'teach', or 'hybrid')`,
|
|
65
|
+
field: 'mode',
|
|
66
|
+
correlationId: ctx.conversation?.correlationId,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (missingFields.length > 0) {
|
|
72
|
+
return {
|
|
73
|
+
accepted: false,
|
|
74
|
+
error: {
|
|
75
|
+
code: 'MISSING_CONTEXT',
|
|
76
|
+
fields: missingFields,
|
|
77
|
+
correlationId: ctx.conversation?.correlationId,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
accepted: true,
|
|
83
|
+
context: ctx,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const context_1 = require("./context");
|
|
4
|
+
describe('Core Context Contract (Single-Owner Single-Machine)', () => {
|
|
5
|
+
const validContext = {
|
|
6
|
+
companionId: 'companion-a',
|
|
7
|
+
actor: {
|
|
8
|
+
actorId: 'local-user',
|
|
9
|
+
sessionId: 'session-a',
|
|
10
|
+
authenticated: true,
|
|
11
|
+
capabilities: ['chat:interact'],
|
|
12
|
+
},
|
|
13
|
+
conversation: {
|
|
14
|
+
correlationId: 'corr-a',
|
|
15
|
+
},
|
|
16
|
+
subject: {
|
|
17
|
+
subjectId: 'actor:local-user',
|
|
18
|
+
kind: 'actor',
|
|
19
|
+
ownerActorId: 'local-user',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
test('validates a correct RequestContext', () => {
|
|
23
|
+
const result = (0, context_1.validateRequestContext)(validContext);
|
|
24
|
+
expect(result.accepted).toBe(true);
|
|
25
|
+
expect(result.context).toEqual(validContext);
|
|
26
|
+
expect(result.error).toBeUndefined();
|
|
27
|
+
});
|
|
28
|
+
test('validates a correct RequestContext without subject', () => {
|
|
29
|
+
const { subject, ...contextWithoutSubject } = validContext;
|
|
30
|
+
const result = (0, context_1.validateRequestContext)(contextWithoutSubject);
|
|
31
|
+
expect(result.accepted).toBe(true);
|
|
32
|
+
expect(result.context?.subject).toBeUndefined();
|
|
33
|
+
});
|
|
34
|
+
test('rejects missing root context or non-object', () => {
|
|
35
|
+
const result = (0, context_1.validateRequestContext)(null);
|
|
36
|
+
expect(result.accepted).toBe(false);
|
|
37
|
+
expect(result.error?.code).toBe('MISSING_CONTEXT');
|
|
38
|
+
expect(result.error?.fields).toContain('context');
|
|
39
|
+
});
|
|
40
|
+
test('rejects missing companionId, actor, or conversation', () => {
|
|
41
|
+
const result = (0, context_1.validateRequestContext)({});
|
|
42
|
+
expect(result.accepted).toBe(false);
|
|
43
|
+
expect(result.error?.code).toBe('MISSING_CONTEXT');
|
|
44
|
+
expect(result.error?.fields).toEqual(expect.arrayContaining(['companionId', 'actor', 'conversation']));
|
|
45
|
+
});
|
|
46
|
+
test('validates subject kinds and constraints', () => {
|
|
47
|
+
expect((0, context_1.isValidSubjectKind)('actor')).toBe(true);
|
|
48
|
+
expect((0, context_1.isValidSubjectKind)('companion')).toBe(true);
|
|
49
|
+
expect((0, context_1.isValidSubjectKind)('configured')).toBe(true);
|
|
50
|
+
expect((0, context_1.isValidSubjectKind)('user')).toBe(false);
|
|
51
|
+
const invalidSubjectCtx = {
|
|
52
|
+
...validContext,
|
|
53
|
+
subject: { subjectId: 'subject-1', kind: 'invalid_kind' },
|
|
54
|
+
};
|
|
55
|
+
const result = (0, context_1.validateRequestContext)(invalidSubjectCtx);
|
|
56
|
+
expect(result.accepted).toBe(false);
|
|
57
|
+
expect(result.error?.fields).toContain('subject.kind');
|
|
58
|
+
});
|
|
59
|
+
test('rejects missing correlationId and preserves correlationId in error if present', () => {
|
|
60
|
+
const missingCorr = {
|
|
61
|
+
...validContext,
|
|
62
|
+
conversation: { ...validContext.conversation, correlationId: '' },
|
|
63
|
+
};
|
|
64
|
+
const result = (0, context_1.validateRequestContext)(missingCorr);
|
|
65
|
+
expect(result.accepted).toBe(false);
|
|
66
|
+
expect(result.error?.fields).toContain('conversation.correlationId');
|
|
67
|
+
const missingActorId = {
|
|
68
|
+
...validContext,
|
|
69
|
+
actor: { ...validContext.actor, actorId: '' },
|
|
70
|
+
};
|
|
71
|
+
const result2 = (0, context_1.validateRequestContext)(missingActorId);
|
|
72
|
+
expect(result2.accepted).toBe(false);
|
|
73
|
+
expect(result2.error?.fields).toContain('actor.actorId');
|
|
74
|
+
expect(result2.error?.correlationId).toBe('corr-a');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|