@siduri-x/core 2.0.3 → 2.0.5

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/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
- return this.container.initialize();
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.
@@ -81,7 +196,7 @@ class SiduriRuntime {
81
196
  /**
82
197
  * Primary entrypoint for text chat messages.
83
198
  */
84
- async handleUserMessage(message, roleOrContext = 'OWNER', history = [], medium, signal) {
199
+ async handleUserMessage(message, roleOrContext = 'OWNER', history = [], medium, signal, subtitleLanguage) {
85
200
  return this.processPerception({
86
201
  source: 'text_chat',
87
202
  text: message,
@@ -89,7 +204,99 @@ class SiduriRuntime {
89
204
  history,
90
205
  medium,
91
206
  signal,
207
+ subtitleLanguage,
92
208
  });
93
209
  }
94
210
  }
95
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
268
+ if (claim.claimType === 'relationship' ||
269
+ predicate === 'stated_relationship' ||
270
+ predicate === 'relationship' ||
271
+ predicate === 'relationship_to_siduri') {
272
+ const rawSubject = (claim.subject || 'actor:user').replace(/^actor:actor:/, 'actor:');
273
+ const isCreator = value.toLowerCase() === 'creator';
274
+ await self.updateRelationship(targetCompanionId, {
275
+ companionId: targetCompanionId,
276
+ entityId: rawSubject,
277
+ entityType: 'human',
278
+ role: value,
279
+ stance: isCreator ? 'familiar_loyal' : 'neutral',
280
+ trustScore: isCreator ? 1.0 : 0.8,
281
+ familiarity: isCreator ? 0.9 : 0.5,
282
+ interactionConventions: isCreator
283
+ ? ['Direct communication', 'Highest administrative trust']
284
+ : [],
285
+ });
286
+ return;
287
+ }
288
+ // 3. Behavioral rule claim
289
+ if (predicate === 'behavioral_rule' || predicate === 'rule') {
290
+ await self.commitDirectives(targetCompanionId, [
291
+ {
292
+ id: `dir-rule-${claim.id || Date.now()}`,
293
+ companionId: targetCompanionId,
294
+ priority: 60,
295
+ directive: value,
296
+ status: 'active',
297
+ category: 'behavioral',
298
+ createdAt: new Date().toISOString(),
299
+ },
300
+ ]);
301
+ }
302
+ }
@@ -1,7 +1,9 @@
1
+ import { ClaimStatus, DirectiveStatus } from './proposals';
1
2
  export interface SelfIdentity {
2
3
  companionId: string;
3
4
  name: string;
4
5
  archetype?: string;
6
+ role?: string;
5
7
  origin?: string;
6
8
  ethos?: string;
7
9
  version: string;
@@ -19,7 +21,7 @@ export interface SelfDirective {
19
21
  companionId: string;
20
22
  priority?: number;
21
23
  directive: string;
22
- status: 'PENDING' | 'ACTIVE' | 'DISABLED' | 'SUPERSEDED' | 'REJECTED' | 'REVOKED' | 'EXPIRED';
24
+ status: DirectiveStatus;
23
25
  category: 'behavioral' | 'guardrail' | 'relational' | string;
24
26
  scopeActor?: string;
25
27
  supersedesId?: string;
@@ -90,7 +92,7 @@ export interface MemoryClaim {
90
92
  subject: string;
91
93
  predicate: string;
92
94
  value: string;
93
- status: 'PENDING' | 'APPROVED' | 'REJECTED' | 'SESSION_ONLY' | 'SUPERSEDED' | 'REVOKED' | 'EXPIRED';
95
+ status: ClaimStatus;
94
96
  confidence: number;
95
97
  validFrom?: string;
96
98
  validUntil?: string;
@@ -99,6 +101,7 @@ export interface MemoryClaim {
99
101
  supersedes?: string;
100
102
  sourceEventId?: string;
101
103
  }
104
+ export declare function normalizeStatus(status?: string, defaultStatus?: string): string;
102
105
  export interface SiduriDatabaseOptions {
103
106
  dbPath?: string;
104
107
  }
@@ -111,7 +114,9 @@ export declare class SiduriDatabase {
111
114
  setIdentity(identity: SelfIdentity): void;
112
115
  getPersonality(companionId: string): PersonalityTraits | undefined;
113
116
  setPersonality(companionId: string, traits: PersonalityTraits): void;
117
+ private rowToSelfDirective;
114
118
  getActiveDirectives(companionId: string): SelfDirective[];
119
+ getAllDirectives(companionId: string): SelfDirective[];
115
120
  commitDirective(directive: SelfDirective): void;
116
121
  getDirective(id: string, companionId?: string): SelfDirective | undefined;
117
122
  approveDirective(id: string, companionId?: string): void;
@@ -135,13 +140,19 @@ export declare class SiduriDatabase {
135
140
  recordEvent(event: EpisodicEvent): void;
136
141
  getRecentEvents(companionId: string, limit?: number): EpisodicEvent[];
137
142
  getEvent(id: string): EpisodicEvent | undefined;
143
+ private rowToMemoryClaim;
138
144
  proposeClaim(claim: Omit<MemoryClaim, 'status' | 'confidence' | 'assertedAt'> & {
139
145
  confidence?: number;
140
146
  assertedAt?: string;
141
147
  supersedes?: string;
142
148
  sourceEventId?: string;
149
+ status?: string;
143
150
  }): MemoryClaim;
144
151
  approveClaim(id: string, companionId?: string): void;
152
+ /**
153
+ * Canonically promotes a Claim into Self domain tables.
154
+ */
155
+ promoteClaimToSelf(claim: MemoryClaim | any): void;
145
156
  rejectClaim(id: string, companionId?: string): void;
146
157
  revokeClaim(id: string, companionId?: string): void;
147
158
  expireClaim(id: string, companionId?: string): void;
@@ -149,6 +160,7 @@ export declare class SiduriDatabase {
149
160
  searchClaims(companionId: string, query: string, limit?: number): MemoryClaim[];
150
161
  getPendingClaims(companionId: string, limit?: number): MemoryClaim[];
151
162
  getApprovedClaims(companionId: string, limit?: number): MemoryClaim[];
163
+ getAllClaims(companionId?: string, limit?: number): MemoryClaim[];
152
164
  getClaim(id: string): MemoryClaim | undefined;
153
165
  resetMemory(companionId: string): void;
154
166
  }