@siduri-x/core 2.0.4 → 2.0.6
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/context-retriever.d.ts +3 -0
- package/dist/context-retriever.js +23 -2
- package/dist/conversational-teach.test.d.ts +1 -0
- package/dist/conversational-teach.test.js +643 -0
- package/dist/index.d.ts +7 -1
- package/dist/intent-classifier.js +2 -2
- package/dist/memory-settler.d.ts +22 -1
- package/dist/memory-settler.js +69 -8
- package/dist/perception-cycle.test.js +14 -0
- package/dist/perception-pipeline.js +13 -2
- package/dist/prompt-compiler.d.ts +3 -0
- package/dist/prompt-compiler.js +5 -2
- package/dist/response-envelope.d.ts +1 -0
- package/dist/response-envelope.js +2 -1
- package/dist/runtime.d.ts +46 -0
- package/dist/runtime.js +237 -1
- package/dist/siduri-db.d.ts +7 -0
- package/dist/siduri-db.js +172 -11
- package/dist/siduri-db.test.js +2 -1
- package/dist/teaching.d.ts +6 -7
- package/dist/teaching.js +7 -125
- package/package.json +1 -1
|
@@ -15,9 +15,9 @@ function classifyInputIntent(text, context, overrides) {
|
|
|
15
15
|
const isTeachingLike = overrides?.isTeachingLike ??
|
|
16
16
|
(explicitTeaching.claims.length > 0 ||
|
|
17
17
|
explicitTeaching.behaviorProposals.length > 0 ||
|
|
18
|
-
/\
|
|
18
|
+
/\b(?:remember that|my name is|call me)\b/i.test(normalizedMessage));
|
|
19
19
|
const isSelfIdentityRequest = overrides?.isSelfIdentityRequest ??
|
|
20
|
-
/\b(?:who|what) are you\b|\bwho is siduri\b|\b(?:your|my) name\b|\btell me about yourself\b|\bdescribe yourself\b|\bwhat is your origin\b|\bwho created you\b|\bwho made you\b|\bintroduce yourself\b/.test(normalizedMessage);
|
|
20
|
+
/\b(?:who|what) are you\b|\bwho is siduri\b|\b(?:your|my) name\b|\bdo you know me\b|\bwho am i\b|\btell me about yourself\b|\bdescribe yourself\b|\bwhat is your origin\b|\bwho created you\b|\bwho made you\b|\bintroduce yourself\b/.test(normalizedMessage);
|
|
21
21
|
const isGreeting = overrides?.isGreeting ??
|
|
22
22
|
/^(?:hello|hi|hey|greetings|good morning|good afternoon|good evening|howdy|yo)[.!]?$/.test(normalizedMessage);
|
|
23
23
|
const shouldQueryKnowledge = overrides?.shouldQueryKnowledge ??
|
package/dist/memory-settler.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MemoryOrgan, Claim, ResponsePlan, RequestContext, InteractionMode } from './index';
|
|
1
|
+
import { MemoryOrgan, SelfRepository, Claim, BehaviorDirective, ResponsePlan, RequestContext, InteractionMode } from './index';
|
|
2
2
|
import { extractDeterministicTeaching } from './teaching';
|
|
3
3
|
export interface MemorySettlementParams {
|
|
4
4
|
companionId: string;
|
|
@@ -6,6 +6,7 @@ export interface MemorySettlementParams {
|
|
|
6
6
|
role: 'OWNER' | 'VIEWER' | 'OPERATOR';
|
|
7
7
|
requestContext: RequestContext;
|
|
8
8
|
memory?: MemoryOrgan;
|
|
9
|
+
self?: SelfRepository;
|
|
9
10
|
explicitTeaching: ReturnType<typeof extractDeterministicTeaching>;
|
|
10
11
|
plan: ResponsePlan;
|
|
11
12
|
effectiveMode?: InteractionMode;
|
|
@@ -16,10 +17,30 @@ export interface MemoryProposalReceipt {
|
|
|
16
17
|
predicate: string;
|
|
17
18
|
value: string;
|
|
18
19
|
status: string;
|
|
20
|
+
claim_type?: string;
|
|
21
|
+
content?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface BehavioralProposalReceipt {
|
|
24
|
+
directive_id: string;
|
|
25
|
+
domain?: string;
|
|
26
|
+
knowledge_domain?: string;
|
|
27
|
+
memory_class?: string;
|
|
28
|
+
runtime_effect?: string;
|
|
29
|
+
subject?: string;
|
|
30
|
+
predicate?: string;
|
|
31
|
+
value?: string;
|
|
32
|
+
status: string;
|
|
33
|
+
behavior?: {
|
|
34
|
+
instruction: string;
|
|
35
|
+
frequency?: string;
|
|
36
|
+
preferred_positions?: string[];
|
|
37
|
+
};
|
|
19
38
|
}
|
|
20
39
|
export interface MemorySettlementResult {
|
|
21
40
|
createdMemoryProposals: Claim[];
|
|
22
41
|
memoryProposalReceipts: MemoryProposalReceipt[];
|
|
42
|
+
createdBehavioralProposals?: BehaviorDirective[];
|
|
43
|
+
behavioralProposalReceipts?: BehavioralProposalReceipt[];
|
|
23
44
|
}
|
|
24
45
|
/**
|
|
25
46
|
* Persists source events, deterministic teaching claims, LLM memory proposals,
|
package/dist/memory-settler.js
CHANGED
|
@@ -6,7 +6,7 @@ exports.settleMemoryProposals = settleMemoryProposals;
|
|
|
6
6
|
* and LLM behavior proposals to the MemoryOrgan.
|
|
7
7
|
*/
|
|
8
8
|
async function settleMemoryProposals(params) {
|
|
9
|
-
const { companionId, perceivedText, role, requestContext, memory, explicitTeaching, plan, effectiveMode, } = params;
|
|
9
|
+
const { companionId, perceivedText, role, requestContext, memory, self, explicitTeaching, plan, effectiveMode, } = params;
|
|
10
10
|
// Zero Memory Drift: Casual mode completely suppresses all proposal generation
|
|
11
11
|
const mode = effectiveMode || requestContext.mode || 'hybrid';
|
|
12
12
|
if (mode === 'casual') {
|
|
@@ -43,6 +43,7 @@ async function settleMemoryProposals(params) {
|
|
|
43
43
|
if (memory && typeof memory.proposeClaim === 'function') {
|
|
44
44
|
for (const claim of explicitTeaching.claims) {
|
|
45
45
|
const proposal = await memory.proposeClaim({
|
|
46
|
+
companionId,
|
|
46
47
|
subject: claim.subject,
|
|
47
48
|
predicate: claim.predicate,
|
|
48
49
|
value: claim.value,
|
|
@@ -61,6 +62,7 @@ async function settleMemoryProposals(params) {
|
|
|
61
62
|
if (plan.memoryProposals && plan.memoryProposals.length > 0) {
|
|
62
63
|
for (const p of plan.memoryProposals) {
|
|
63
64
|
const proposal = await memory.proposeClaim({
|
|
65
|
+
companionId,
|
|
64
66
|
subject: p.subject || `actor:${requestContext.actor.actorId}`,
|
|
65
67
|
predicate: p.predicate,
|
|
66
68
|
value: p.value,
|
|
@@ -74,17 +76,72 @@ async function settleMemoryProposals(params) {
|
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
const createdBehavioralProposals = [];
|
|
80
|
+
const behavioralProposalReceipts = [];
|
|
81
|
+
const allBehaviorProposals = [
|
|
82
|
+
...explicitTeaching.behaviorProposals,
|
|
83
|
+
...(plan.behaviorProposals || []),
|
|
84
|
+
];
|
|
85
|
+
for (const bp of allBehaviorProposals) {
|
|
86
|
+
let directive;
|
|
87
|
+
if (memory && typeof memory.proposeDirective === 'function') {
|
|
88
|
+
directive = await memory.proposeDirective({
|
|
89
|
+
companionId,
|
|
83
90
|
directive: bp.directive,
|
|
84
91
|
priority: bp.priority || 50,
|
|
85
|
-
|
|
92
|
+
category: bp.category || 'behavioral',
|
|
93
|
+
supersedesId: bp.supersedesId,
|
|
94
|
+
scopeActor: bp.scopeActor || (bp.subject?.startsWith('actor:') ? bp.subject.slice(6) : undefined),
|
|
95
|
+
memoryClass: bp.memoryClass,
|
|
96
|
+
subject: bp.subject,
|
|
97
|
+
predicate: bp.predicate,
|
|
98
|
+
value: bp.value,
|
|
99
|
+
sourceEventId: sourceEventId || bp.sourceEventId,
|
|
86
100
|
});
|
|
87
101
|
}
|
|
102
|
+
if (!directive || !directive.id) {
|
|
103
|
+
directive = {
|
|
104
|
+
id: directive?.id || `dir-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
|
|
105
|
+
companionId,
|
|
106
|
+
directive: bp.directive,
|
|
107
|
+
priority: bp.priority || 50,
|
|
108
|
+
status: 'pending',
|
|
109
|
+
category: (bp.category || 'behavioral'),
|
|
110
|
+
scopeActor: bp.scopeActor,
|
|
111
|
+
supersedesId: bp.supersedesId,
|
|
112
|
+
createdAt: new Date().toISOString(),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
createdBehavioralProposals.push(directive);
|
|
116
|
+
if (self && typeof self.commitDirectives === 'function') {
|
|
117
|
+
await self.commitDirectives(companionId, [{
|
|
118
|
+
id: directive.id,
|
|
119
|
+
companionId,
|
|
120
|
+
directive: bp.directive,
|
|
121
|
+
priority: bp.priority || 50,
|
|
122
|
+
status: 'pending',
|
|
123
|
+
category: (bp.category || 'behavioral'),
|
|
124
|
+
scopeActor: bp.scopeActor,
|
|
125
|
+
supersedesId: bp.supersedesId,
|
|
126
|
+
createdAt: new Date().toISOString(),
|
|
127
|
+
}]);
|
|
128
|
+
}
|
|
129
|
+
behavioralProposalReceipts.push({
|
|
130
|
+
directive_id: directive.id,
|
|
131
|
+
domain: 'behavioral',
|
|
132
|
+
knowledge_domain: 'behavioral',
|
|
133
|
+
memory_class: bp.memoryClass || 'behavioral',
|
|
134
|
+
runtime_effect: bp.memoryClass || 'behavioral',
|
|
135
|
+
subject: bp.subject || `companion:${companionId}`,
|
|
136
|
+
predicate: bp.predicate || 'rule',
|
|
137
|
+
value: bp.value || bp.directive,
|
|
138
|
+
status: 'pending',
|
|
139
|
+
behavior: {
|
|
140
|
+
instruction: bp.directive,
|
|
141
|
+
frequency: 'continuous',
|
|
142
|
+
preferred_positions: [],
|
|
143
|
+
},
|
|
144
|
+
});
|
|
88
145
|
}
|
|
89
146
|
const memoryProposalReceipts = createdMemoryProposals.map((p) => ({
|
|
90
147
|
proposal_id: p.id,
|
|
@@ -92,9 +149,13 @@ async function settleMemoryProposals(params) {
|
|
|
92
149
|
predicate: p.predicate,
|
|
93
150
|
value: p.value,
|
|
94
151
|
status: (p.status || 'pending').toLowerCase().replace(/_/g, '-'),
|
|
152
|
+
claim_type: p.claimType,
|
|
153
|
+
content: p.content,
|
|
95
154
|
}));
|
|
96
155
|
return {
|
|
97
156
|
createdMemoryProposals,
|
|
98
157
|
memoryProposalReceipts,
|
|
158
|
+
createdBehavioralProposals,
|
|
159
|
+
behavioralProposalReceipts,
|
|
99
160
|
};
|
|
100
161
|
}
|
|
@@ -212,6 +212,13 @@ describe('SiduriRuntime Unified Perception Cycle & Session History', () => {
|
|
|
212
212
|
generatePlan: jest.fn().mockResolvedValue({
|
|
213
213
|
speech: 'I have recorded your preferred title as Chief Engineer.',
|
|
214
214
|
language: 'en',
|
|
215
|
+
memoryProposals: [
|
|
216
|
+
{
|
|
217
|
+
subject: 'actor:alice',
|
|
218
|
+
predicate: 'preferred_address',
|
|
219
|
+
value: 'Chief Engineer',
|
|
220
|
+
},
|
|
221
|
+
],
|
|
215
222
|
}),
|
|
216
223
|
};
|
|
217
224
|
const runtime = new runtime_1.SiduriRuntime('comp-teach', { name: 'TeachBot' }, {
|
|
@@ -255,6 +262,13 @@ describe('SiduriRuntime Unified Perception Cycle & Session History', () => {
|
|
|
255
262
|
generatePlan: jest.fn().mockResolvedValue({
|
|
256
263
|
speech: 'Recorded the command.',
|
|
257
264
|
language: 'en',
|
|
265
|
+
memoryProposals: [
|
|
266
|
+
{
|
|
267
|
+
subject: 'companion:comp-infer',
|
|
268
|
+
predicate: 'name',
|
|
269
|
+
value: 'Atlas',
|
|
270
|
+
},
|
|
271
|
+
],
|
|
258
272
|
}),
|
|
259
273
|
};
|
|
260
274
|
const runtime = new runtime_1.SiduriRuntime('comp-infer', { name: 'InferBot' }, {
|
|
@@ -88,6 +88,9 @@ const promptCompilationStage = async (context) => {
|
|
|
88
88
|
requestContext: context.input.requestContext,
|
|
89
89
|
behavior: context.organs.behavior,
|
|
90
90
|
activeDirectives: context.contextRetrieval.activeDirectives,
|
|
91
|
+
selfIdentity: context.contextRetrieval.selfIdentity,
|
|
92
|
+
selfRelationship: context.contextRetrieval.selfRelationship,
|
|
93
|
+
personality: context.contextRetrieval.personality,
|
|
91
94
|
subsystemDiagnostics: context.contextRetrieval.subsystemDiagnostics,
|
|
92
95
|
knowledgeData: context.contextRetrieval.knowledgeData,
|
|
93
96
|
memoryData: context.contextRetrieval.memoryData,
|
|
@@ -121,8 +124,14 @@ const responseGatingStage = async (context) => {
|
|
|
121
124
|
candidateSpeech: context.plan.speech,
|
|
122
125
|
candidateLanguage: context.plan.language || 'ja',
|
|
123
126
|
internalMonologue: context.plan.internalMonologue,
|
|
124
|
-
memoryProposals:
|
|
125
|
-
|
|
127
|
+
memoryProposals: [
|
|
128
|
+
...(context.intent?.explicitTeaching?.claims || []),
|
|
129
|
+
...(context.plan.memoryProposals || []),
|
|
130
|
+
],
|
|
131
|
+
behaviorProposals: [
|
|
132
|
+
...(context.intent?.explicitTeaching?.behaviorProposals || []),
|
|
133
|
+
...(context.plan.behaviorProposals || []),
|
|
134
|
+
],
|
|
126
135
|
evidenceRecords: context.contextRetrieval.collectedEvidence,
|
|
127
136
|
citations: context.contextRetrieval.citations,
|
|
128
137
|
});
|
|
@@ -146,6 +155,7 @@ const memorySettlementStage = async (context) => {
|
|
|
146
155
|
role: context.input.role,
|
|
147
156
|
requestContext: context.input.requestContext,
|
|
148
157
|
memory: context.organs.memory,
|
|
158
|
+
self: context.organs.self,
|
|
149
159
|
explicitTeaching: context.intent.explicitTeaching,
|
|
150
160
|
plan: context.plan,
|
|
151
161
|
effectiveMode: context.intent.effectiveMode,
|
|
@@ -236,6 +246,7 @@ const envelopeAssemblyStage = async (context) => {
|
|
|
236
246
|
speechId: context.experienceEmission?.speechId,
|
|
237
247
|
createdMemoryProposals: context.memorySettlement.createdMemoryProposals,
|
|
238
248
|
memoryProposalReceipts: context.memorySettlement.memoryProposalReceipts,
|
|
249
|
+
behavioralProposalReceipts: context.memorySettlement.behavioralProposalReceipts,
|
|
239
250
|
actionResults: context.actionResults || [],
|
|
240
251
|
filteredEvidenceIds: context.gateEval.filteredEvidenceIds,
|
|
241
252
|
filteredCitations: context.gateEval.filteredCitations,
|
|
@@ -6,6 +6,9 @@ export interface PromptCompilationParams {
|
|
|
6
6
|
requestContext: RequestContext;
|
|
7
7
|
behavior?: BehaviorOrgan;
|
|
8
8
|
activeDirectives: BehaviorDirective[];
|
|
9
|
+
selfIdentity?: any;
|
|
10
|
+
selfRelationship?: any;
|
|
11
|
+
personality?: any;
|
|
9
12
|
subsystemDiagnostics: Record<string, string>;
|
|
10
13
|
knowledgeData: KnowledgeItem[];
|
|
11
14
|
memoryData: Claim[];
|
package/dist/prompt-compiler.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.compilePrompts = compilePrompts;
|
|
|
5
5
|
* Compiles neutral system prompt and formatted context prompt from structured data.
|
|
6
6
|
*/
|
|
7
7
|
async function compilePrompts(params) {
|
|
8
|
-
const { companionName, companionId, role, requestContext, behavior, activeDirectives, subsystemDiagnostics, knowledgeData, memoryData, lifeContext, effectiveMode, subtitleLanguage, } = params;
|
|
8
|
+
const { companionName, companionId, role, requestContext, behavior, activeDirectives, selfIdentity, selfRelationship, personality, subsystemDiagnostics, knowledgeData, memoryData, lifeContext, effectiveMode, subtitleLanguage, } = params;
|
|
9
9
|
let contextPrompt = '';
|
|
10
10
|
if (Object.keys(subsystemDiagnostics).length > 0) {
|
|
11
11
|
contextPrompt +=
|
|
@@ -40,13 +40,16 @@ async function compilePrompts(params) {
|
|
|
40
40
|
? await behavior.compile({
|
|
41
41
|
directives: activeDirectives,
|
|
42
42
|
companionId,
|
|
43
|
+
identity: selfIdentity,
|
|
44
|
+
relationship: selfRelationship,
|
|
45
|
+
personality,
|
|
43
46
|
actorId: requestContext.actor.actorId,
|
|
44
47
|
})
|
|
45
48
|
: '';
|
|
46
49
|
const modeInstruction = effectiveMode === 'casual'
|
|
47
50
|
? 'Operating Mode: Casual (Zero memory drift - do not attempt to persist personal claims or directives).'
|
|
48
51
|
: effectiveMode === 'teach'
|
|
49
|
-
? 'Operating Mode: Teach Mode (Active learning session -
|
|
52
|
+
? 'Operating Mode: Teach Mode (Active learning session - listen attentively to what the user shares about their identity, affiliations, relationship, or preferences, and companion identity/role. Accurately formulate candidate memoryProposals and behaviorProposals for review).'
|
|
50
53
|
: undefined;
|
|
51
54
|
const subtitleInstruction = subtitleLanguage && subtitleLanguage !== 'off'
|
|
52
55
|
? `Requested Subtitle Language: "${subtitleLanguage}". Along with your primary speech, provide a natural subtitle translation in "${subtitleLanguage}" in the subtitle field.`
|
|
@@ -11,6 +11,7 @@ export interface AssembleResponseEnvelopeParams {
|
|
|
11
11
|
speechId?: string;
|
|
12
12
|
createdMemoryProposals: Claim[];
|
|
13
13
|
memoryProposalReceipts: MemoryProposalReceipt[];
|
|
14
|
+
behavioralProposalReceipts?: any[];
|
|
14
15
|
actionResults: ActionExecutionResult[];
|
|
15
16
|
filteredEvidenceIds?: string[];
|
|
16
17
|
filteredCitations?: ResponseCitation[];
|
|
@@ -29,7 +29,7 @@ function createGateRejectionEnvelope(stagedPlan, gateEval) {
|
|
|
29
29
|
* Assembles the standardized response structure for approved companion responses.
|
|
30
30
|
*/
|
|
31
31
|
function assembleResponseEnvelope(params) {
|
|
32
|
-
const { stagedPlan, speech, language, subtitle, subtitles, subtitleLanguage, speechId, createdMemoryProposals, memoryProposalReceipts, actionResults, filteredEvidenceIds, filteredCitations, subsystemDiagnostics, experienceEvents, mouthDelivery, effectiveMode, } = params;
|
|
32
|
+
const { stagedPlan, speech, language, subtitle, subtitles, subtitleLanguage, speechId, createdMemoryProposals, memoryProposalReceipts, behavioralProposalReceipts, actionResults, filteredEvidenceIds, filteredCitations, subsystemDiagnostics, experienceEvents, mouthDelivery, effectiveMode, } = params;
|
|
33
33
|
const resolvedSubtitles = {
|
|
34
34
|
...(mouthDelivery?.subtitles || {}),
|
|
35
35
|
...(subtitles || {}),
|
|
@@ -56,6 +56,7 @@ function assembleResponseEnvelope(params) {
|
|
|
56
56
|
language,
|
|
57
57
|
proposals: createdMemoryProposals,
|
|
58
58
|
memory_proposals: memoryProposalReceipts,
|
|
59
|
+
behavioral_proposals: behavioralProposalReceipts || [],
|
|
59
60
|
action_results: actionResults,
|
|
60
61
|
evidence_ids: filteredEvidenceIds,
|
|
61
62
|
citations: filteredCitations,
|
package/dist/runtime.d.ts
CHANGED
|
@@ -38,6 +38,48 @@ export declare class SiduriRuntime {
|
|
|
38
38
|
initialize(): Promise<void>;
|
|
39
39
|
getSessionHistory(sessionKey: string): Message[];
|
|
40
40
|
clearHistory(sessionKey?: string): void;
|
|
41
|
+
/**
|
|
42
|
+
* Approves a memory proposal or behavior proposal and canonically promotes
|
|
43
|
+
* Self-affecting mutations to SelfRepository.
|
|
44
|
+
*/
|
|
45
|
+
approveProposal(proposalId: string, options?: {
|
|
46
|
+
companionId?: string;
|
|
47
|
+
}): Promise<{
|
|
48
|
+
success: boolean;
|
|
49
|
+
target?: string;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Rejects a memory or behavior proposal.
|
|
53
|
+
*/
|
|
54
|
+
rejectProposal(proposalId: string, options?: {
|
|
55
|
+
companionId?: string;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
success: boolean;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Approves a behavioral directive in Self and Memory.
|
|
61
|
+
*/
|
|
62
|
+
approveDirective(directiveId: string, options?: {
|
|
63
|
+
companionId?: string;
|
|
64
|
+
}): Promise<{
|
|
65
|
+
success: boolean;
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Rejects a behavioral directive in Self and Memory.
|
|
69
|
+
*/
|
|
70
|
+
rejectDirective(directiveId: string, options?: {
|
|
71
|
+
companionId?: string;
|
|
72
|
+
}): Promise<{
|
|
73
|
+
success: boolean;
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* Revokes a behavioral directive in Self and Memory.
|
|
77
|
+
*/
|
|
78
|
+
revokeDirective(directiveId: string, options?: {
|
|
79
|
+
companionId?: string;
|
|
80
|
+
}): Promise<{
|
|
81
|
+
success: boolean;
|
|
82
|
+
}>;
|
|
41
83
|
/**
|
|
42
84
|
* Processes an incoming perception (sensory audio, text, platform event, or observation alert)
|
|
43
85
|
* through the decoupled PerceptionPipeline.
|
|
@@ -48,3 +90,7 @@ export declare class SiduriRuntime {
|
|
|
48
90
|
*/
|
|
49
91
|
handleUserMessage(message: string, roleOrContext?: 'OWNER' | 'VIEWER' | 'OPERATOR' | RequestContext | string, history?: Message[], medium?: MouthMedium, signal?: AbortSignal, subtitleLanguage?: string): Promise<any>;
|
|
50
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Canonically promotes an approved Claim into SelfRepository state.
|
|
95
|
+
*/
|
|
96
|
+
export declare function promoteApprovedClaimToSelf(claim: any, self: SelfRepository, companionId?: string): Promise<void>;
|
package/dist/runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SiduriRuntime = void 0;
|
|
4
|
+
exports.promoteApprovedClaimToSelf = promoteApprovedClaimToSelf;
|
|
4
5
|
const perception_pipeline_1 = require("./perception-pipeline");
|
|
5
6
|
const container_1 = require("./container");
|
|
6
7
|
/**
|
|
@@ -52,7 +53,25 @@ class SiduriRuntime {
|
|
|
52
53
|
this.container.sessionHistory.setHistory('default', messages);
|
|
53
54
|
}
|
|
54
55
|
async initialize() {
|
|
55
|
-
|
|
56
|
+
await this.container.initialize();
|
|
57
|
+
if (this.memory && this.self && typeof this.memory.approveClaim === 'function') {
|
|
58
|
+
const originalApproveClaim = this.memory.approveClaim.bind(this.memory);
|
|
59
|
+
this.memory.approveClaim = async (id) => {
|
|
60
|
+
await originalApproveClaim(id);
|
|
61
|
+
const targetCompId = this.id;
|
|
62
|
+
const claims = typeof this.memory.getAllClaims === 'function'
|
|
63
|
+
? await this.memory.getAllClaims(500)
|
|
64
|
+
: await this.memory.getClaims(500);
|
|
65
|
+
let found = claims.find((c) => c.id === id);
|
|
66
|
+
if (!found && typeof this.memory.getPendingClaims === 'function') {
|
|
67
|
+
const pending = await this.memory.getPendingClaims(500);
|
|
68
|
+
found = pending.find((c) => c.id === id);
|
|
69
|
+
}
|
|
70
|
+
if (found && this.self) {
|
|
71
|
+
await promoteApprovedClaimToSelf(found, this.self, targetCompId);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
56
75
|
}
|
|
57
76
|
getSessionHistory(sessionKey) {
|
|
58
77
|
return this.container.sessionHistory.getHistory(sessionKey);
|
|
@@ -60,6 +79,102 @@ class SiduriRuntime {
|
|
|
60
79
|
clearHistory(sessionKey) {
|
|
61
80
|
this.container.sessionHistory.clear(sessionKey);
|
|
62
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Approves a memory proposal or behavior proposal and canonically promotes
|
|
84
|
+
* Self-affecting mutations to SelfRepository.
|
|
85
|
+
*/
|
|
86
|
+
async approveProposal(proposalId, options) {
|
|
87
|
+
const companionId = options?.companionId || this.id;
|
|
88
|
+
// 1. Approve claim in memory if present
|
|
89
|
+
if (this.memory && typeof this.memory.approveClaim === 'function') {
|
|
90
|
+
await this.memory.approveClaim(proposalId);
|
|
91
|
+
}
|
|
92
|
+
// 2. Fetch claim
|
|
93
|
+
let claim;
|
|
94
|
+
if (this.memory) {
|
|
95
|
+
const claims = typeof this.memory.getAllClaims === 'function'
|
|
96
|
+
? await this.memory.getAllClaims(500)
|
|
97
|
+
: await this.memory.getClaims(500);
|
|
98
|
+
claim = claims.find((c) => c.id === proposalId);
|
|
99
|
+
if (!claim && typeof this.memory.getPendingClaims === 'function') {
|
|
100
|
+
const pending = await this.memory.getPendingClaims(500);
|
|
101
|
+
claim = pending.find((c) => c.id === proposalId);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// 3. Promote to Self if Self exists and claim is Self-affecting
|
|
105
|
+
if (claim && this.self) {
|
|
106
|
+
await promoteApprovedClaimToSelf(claim, this.self, companionId);
|
|
107
|
+
return { success: true, target: 'self' };
|
|
108
|
+
}
|
|
109
|
+
// 4. Also check if proposalId is a directive ID
|
|
110
|
+
if (this.self && typeof this.self.approveDirective === 'function') {
|
|
111
|
+
try {
|
|
112
|
+
await this.self.approveDirective(proposalId, companionId);
|
|
113
|
+
return { success: true, target: 'self_directive' };
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// Not a pending directive or already active
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return { success: true, target: 'memory' };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Rejects a memory or behavior proposal.
|
|
123
|
+
*/
|
|
124
|
+
async rejectProposal(proposalId, options) {
|
|
125
|
+
const companionId = options?.companionId || this.id;
|
|
126
|
+
if (this.memory && typeof this.memory.rejectClaim === 'function') {
|
|
127
|
+
await this.memory.rejectClaim(proposalId);
|
|
128
|
+
}
|
|
129
|
+
if (this.self && typeof this.self.rejectDirective === 'function') {
|
|
130
|
+
try {
|
|
131
|
+
await this.self.rejectDirective(proposalId, companionId);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// ignore
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { success: true };
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Approves a behavioral directive in Self and Memory.
|
|
141
|
+
*/
|
|
142
|
+
async approveDirective(directiveId, options) {
|
|
143
|
+
const companionId = options?.companionId || this.id;
|
|
144
|
+
if (this.self && typeof this.self.approveDirective === 'function') {
|
|
145
|
+
await this.self.approveDirective(directiveId, companionId);
|
|
146
|
+
}
|
|
147
|
+
if (this.memory && typeof this.memory.approveDirective === 'function') {
|
|
148
|
+
await this.memory.approveDirective(directiveId, companionId);
|
|
149
|
+
}
|
|
150
|
+
return { success: true };
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Rejects a behavioral directive in Self and Memory.
|
|
154
|
+
*/
|
|
155
|
+
async rejectDirective(directiveId, options) {
|
|
156
|
+
const companionId = options?.companionId || this.id;
|
|
157
|
+
if (this.self && typeof this.self.rejectDirective === 'function') {
|
|
158
|
+
await this.self.rejectDirective(directiveId, companionId);
|
|
159
|
+
}
|
|
160
|
+
if (this.memory && typeof this.memory.rejectDirective === 'function') {
|
|
161
|
+
await this.memory.rejectDirective(directiveId, companionId);
|
|
162
|
+
}
|
|
163
|
+
return { success: true };
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Revokes a behavioral directive in Self and Memory.
|
|
167
|
+
*/
|
|
168
|
+
async revokeDirective(directiveId, options) {
|
|
169
|
+
const companionId = options?.companionId || this.id;
|
|
170
|
+
if (this.self && typeof this.self.revokeDirective === 'function') {
|
|
171
|
+
await this.self.revokeDirective(directiveId, companionId);
|
|
172
|
+
}
|
|
173
|
+
if (this.memory && typeof this.memory.revokeDirective === 'function') {
|
|
174
|
+
await this.memory.revokeDirective(directiveId, companionId);
|
|
175
|
+
}
|
|
176
|
+
return { success: true };
|
|
177
|
+
}
|
|
63
178
|
/**
|
|
64
179
|
* Processes an incoming perception (sensory audio, text, platform event, or observation alert)
|
|
65
180
|
* through the decoupled PerceptionPipeline.
|
|
@@ -94,3 +209,124 @@ class SiduriRuntime {
|
|
|
94
209
|
}
|
|
95
210
|
}
|
|
96
211
|
exports.SiduriRuntime = SiduriRuntime;
|
|
212
|
+
/**
|
|
213
|
+
* Canonically promotes an approved Claim into SelfRepository state.
|
|
214
|
+
*/
|
|
215
|
+
async function promoteApprovedClaimToSelf(claim, self, companionId) {
|
|
216
|
+
const targetCompanionId = companionId || claim.companionId || 'default';
|
|
217
|
+
const subject = (claim.subject || '').toLowerCase();
|
|
218
|
+
const predicate = (claim.predicate || '').toLowerCase();
|
|
219
|
+
const value = claim.value || '';
|
|
220
|
+
if (!value)
|
|
221
|
+
return;
|
|
222
|
+
// 1. Identity mutations: companion identity/role/origin/name/ethos
|
|
223
|
+
if (subject.startsWith('companion:') ||
|
|
224
|
+
subject === 'companion' ||
|
|
225
|
+
subject === 'siduri' ||
|
|
226
|
+
subject === 'self') {
|
|
227
|
+
const existing = (await self.getIdentity(targetCompanionId)) || {
|
|
228
|
+
companionId: targetCompanionId,
|
|
229
|
+
name: 'Siduri',
|
|
230
|
+
version: '1.0.0',
|
|
231
|
+
updatedAt: new Date().toISOString(),
|
|
232
|
+
};
|
|
233
|
+
if (predicate === 'role' || predicate === 'archetype') {
|
|
234
|
+
existing.archetype = value;
|
|
235
|
+
existing.role = value;
|
|
236
|
+
existing.updatedAt = new Date().toISOString();
|
|
237
|
+
await self.setIdentity(existing);
|
|
238
|
+
await self.commitDirectives(targetCompanionId, [
|
|
239
|
+
{
|
|
240
|
+
id: `dir-role-${claim.id || Date.now()}`,
|
|
241
|
+
companionId: targetCompanionId,
|
|
242
|
+
priority: 70,
|
|
243
|
+
directive: `Acknowledge role as ${value}`,
|
|
244
|
+
status: 'active',
|
|
245
|
+
category: 'relational',
|
|
246
|
+
createdAt: new Date().toISOString(),
|
|
247
|
+
},
|
|
248
|
+
]);
|
|
249
|
+
}
|
|
250
|
+
else if (predicate === 'origin' || predicate === 'created_by') {
|
|
251
|
+
existing.origin = value;
|
|
252
|
+
existing.updatedAt = new Date().toISOString();
|
|
253
|
+
await self.setIdentity(existing);
|
|
254
|
+
}
|
|
255
|
+
else if (predicate === 'name') {
|
|
256
|
+
existing.name = value;
|
|
257
|
+
existing.updatedAt = new Date().toISOString();
|
|
258
|
+
await self.setIdentity(existing);
|
|
259
|
+
}
|
|
260
|
+
else if (predicate === 'ethos') {
|
|
261
|
+
existing.ethos = value;
|
|
262
|
+
existing.updatedAt = new Date().toISOString();
|
|
263
|
+
await self.setIdentity(existing);
|
|
264
|
+
}
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
// 2. Relationship mutations: creator or user stated relationship, name, or affiliation
|
|
268
|
+
if (claim.claimType === 'relationship' ||
|
|
269
|
+
predicate === 'stated_relationship' ||
|
|
270
|
+
predicate === 'relationship' ||
|
|
271
|
+
predicate === 'relationship_to_siduri' ||
|
|
272
|
+
(predicate === 'name' && (subject.startsWith('actor:') || subject === 'user' || subject === 'primary_user')) ||
|
|
273
|
+
predicate === 'preferred_address' ||
|
|
274
|
+
predicate === 'affiliation') {
|
|
275
|
+
const rawSubject = (claim.subject || 'actor:user').replace(/^actor:actor:/, 'actor:');
|
|
276
|
+
const isCreator = value.toLowerCase() === 'creator';
|
|
277
|
+
const isName = predicate === 'name' || predicate === 'preferred_address';
|
|
278
|
+
const isAffil = predicate === 'affiliation';
|
|
279
|
+
const existingRel = typeof self.getRelationship === 'function'
|
|
280
|
+
? await self.getRelationship(targetCompanionId, rawSubject)
|
|
281
|
+
: null;
|
|
282
|
+
const role = isCreator ? value : (existingRel?.role || (isName || isAffil ? existingRel?.role : value));
|
|
283
|
+
const name = isName ? value : existingRel?.name;
|
|
284
|
+
const affiliation = isAffil ? value : existingRel?.affiliation;
|
|
285
|
+
const stance = isCreator ? 'familiar_loyal' : (existingRel?.stance || 'neutral');
|
|
286
|
+
const trustScore = isCreator ? 1.0 : (existingRel?.trustScore ?? 0.8);
|
|
287
|
+
const familiarity = isCreator ? 0.9 : (existingRel?.familiarity ?? 0.5);
|
|
288
|
+
const interactionConventions = isCreator
|
|
289
|
+
? Array.from(new Set([...(existingRel?.interactionConventions || []), 'Direct communication', 'Highest administrative trust']))
|
|
290
|
+
: (existingRel?.interactionConventions || []);
|
|
291
|
+
await self.updateRelationship(targetCompanionId, {
|
|
292
|
+
companionId: targetCompanionId,
|
|
293
|
+
entityId: rawSubject,
|
|
294
|
+
entityType: 'human',
|
|
295
|
+
name,
|
|
296
|
+
affiliation,
|
|
297
|
+
role,
|
|
298
|
+
stance,
|
|
299
|
+
trustScore,
|
|
300
|
+
familiarity,
|
|
301
|
+
interactionConventions,
|
|
302
|
+
});
|
|
303
|
+
if (isName) {
|
|
304
|
+
await self.commitDirectives(targetCompanionId, [
|
|
305
|
+
{
|
|
306
|
+
id: `dir-name-${claim.id || Date.now()}`,
|
|
307
|
+
companionId: targetCompanionId,
|
|
308
|
+
priority: 75,
|
|
309
|
+
directive: `Address ${rawSubject} as ${value}`,
|
|
310
|
+
status: 'active',
|
|
311
|
+
category: 'relational',
|
|
312
|
+
createdAt: new Date().toISOString(),
|
|
313
|
+
},
|
|
314
|
+
]);
|
|
315
|
+
}
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
// 3. Behavioral rule claim
|
|
319
|
+
if (predicate === 'behavioral_rule' || predicate === 'rule') {
|
|
320
|
+
await self.commitDirectives(targetCompanionId, [
|
|
321
|
+
{
|
|
322
|
+
id: `dir-rule-${claim.id || Date.now()}`,
|
|
323
|
+
companionId: targetCompanionId,
|
|
324
|
+
priority: 60,
|
|
325
|
+
directive: value,
|
|
326
|
+
status: 'active',
|
|
327
|
+
category: 'behavioral',
|
|
328
|
+
createdAt: new Date().toISOString(),
|
|
329
|
+
},
|
|
330
|
+
]);
|
|
331
|
+
}
|
|
332
|
+
}
|
package/dist/siduri-db.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export interface SelfIdentity {
|
|
|
3
3
|
companionId: string;
|
|
4
4
|
name: string;
|
|
5
5
|
archetype?: string;
|
|
6
|
+
role?: string;
|
|
6
7
|
origin?: string;
|
|
7
8
|
ethos?: string;
|
|
8
9
|
version: string;
|
|
@@ -30,6 +31,8 @@ export interface SelfRelationship {
|
|
|
30
31
|
companionId: string;
|
|
31
32
|
entityId: string;
|
|
32
33
|
entityType?: 'human' | 'companion' | 'system';
|
|
34
|
+
name?: string;
|
|
35
|
+
affiliation?: string;
|
|
33
36
|
role?: string;
|
|
34
37
|
stance?: string;
|
|
35
38
|
trustScore?: number;
|
|
@@ -148,6 +151,10 @@ export declare class SiduriDatabase {
|
|
|
148
151
|
status?: string;
|
|
149
152
|
}): MemoryClaim;
|
|
150
153
|
approveClaim(id: string, companionId?: string): void;
|
|
154
|
+
/**
|
|
155
|
+
* Canonically promotes a Claim into Self domain tables.
|
|
156
|
+
*/
|
|
157
|
+
promoteClaimToSelf(claim: MemoryClaim | any): void;
|
|
151
158
|
rejectClaim(id: string, companionId?: string): void;
|
|
152
159
|
revokeClaim(id: string, companionId?: string): void;
|
|
153
160
|
expireClaim(id: string, companionId?: string): void;
|