@sidurijs/self 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.
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_SAFETY_PATTERNS = void 0;
4
+ exports.normalizeText = normalizeText;
5
+ exports.scanDirective = scanDirective;
6
+ // ── Layer 1: Unicode normalization & deobfuscation ──────────────────────
7
+ const INVISIBLE_CHARS = /[\u200B\u200C\u200D\u2060\uFEFF\u00AD\u034F\u17B4\u17B5\u180E\u2061-\u2064\u206A-\u206F]/g;
8
+ const LEET_MAP = {
9
+ '0': 'o', '1': 'i', '3': 'e', '4': 'a', '5': 's',
10
+ '7': 't', '@': 'a', '$': 's', '!': 'i',
11
+ };
12
+ const CONFUSABLE_MAP = {
13
+ '\u0430': 'a', '\u0435': 'e', '\u043E': 'o', '\u0440': 'p', '\u0441': 'c',
14
+ '\u0443': 'y', '\u0445': 'x', '\u0456': 'i', '\u0458': 'j', '\u04BB': 'h',
15
+ '\u0261': 'g', '\u03B1': 'a', '\u03BF': 'o', '\u03B5': 'e',
16
+ // Fullwidth Latin
17
+ '\uFF41': 'a', '\uFF42': 'b', '\uFF43': 'c', '\uFF44': 'd', '\uFF45': 'e',
18
+ '\uFF46': 'f', '\uFF47': 'g', '\uFF48': 'h', '\uFF49': 'i', '\uFF4A': 'j',
19
+ '\uFF4B': 'k', '\uFF4C': 'l', '\uFF4D': 'm', '\uFF4E': 'n', '\uFF4F': 'o',
20
+ '\uFF50': 'p', '\uFF51': 'q', '\uFF52': 'r', '\uFF53': 's', '\uFF54': 't',
21
+ '\uFF55': 'u', '\uFF56': 'v', '\uFF57': 'w', '\uFF58': 'x', '\uFF59': 'y',
22
+ '\uFF5A': 'z',
23
+ };
24
+ function normalizeText(input) {
25
+ let text = input;
26
+ text = text.replace(INVISIBLE_CHARS, '');
27
+ text = text.replace(/./g, (ch) => CONFUSABLE_MAP[ch] ?? ch);
28
+ text = text.toLowerCase();
29
+ text = text.replace(/[013457@$!]/g, (ch) => LEET_MAP[ch] ?? ch);
30
+ text = text.replace(/\b([a-z])(?:\s+[a-z]){2,}\b/g, (match) => match.replace(/\s+/g, ''));
31
+ text = text.replace(/\s+/g, ' ').trim();
32
+ return text;
33
+ }
34
+ // ── Layer 2: Multi-category pattern bank ─────────────────────────────────
35
+ const OVERRIDE_VERBS = '(?:ignore|override|bypass|skip|circumvent|disregard|forget|violate|break|disable|remove|deactivate|nullify|suspend|suppress|eliminate|drop|abandon|dismiss|disobey)';
36
+ const NEGATION_VERBS = '(?:do not follow|don\'t follow|stop following|stop enforcing|never follow|never enforce|cease following|quit following)';
37
+ const SAFETY_NOUNS = '(?:system|policy|policies|rules?|approval|permissions?|restrictions?|guidelines?|constraints?|guardrails?|instructions?|authorization|gating|safety|safeguards?|boundaries|limits?|protections?)';
38
+ const DISCLOSURE_VERBS = '(?:reveal|expose|leak|dump|show|output|print|display|disclose|share|repeat back|read out|recite|reproduce|echo|emit|return|give me)';
39
+ const SECRET_NOUNS = '(?:secret|token|api key|private memory|system prompt|initial prompt|hidden instructions?|internal state|configuration|prompt text|original instructions?|base prompt)';
40
+ const ESCALATION_PHRASES = [
41
+ /\b(?:developer|admin|unrestricted|unfiltered|unlimited|god|root|sudo|superuser)\s*mode\b/,
42
+ /\b(?:jailbreak|jail break|jailbroken)\b/,
43
+ /\byou are now\b.{0,40}\b(?:unrestricted|unfiltered|without limits|without restrictions|without rules|without guidelines|free from)\b/,
44
+ /\byour (?:new|real|actual|true)\s+(?:instructions?|prompt|rules?|policy|guidelines?)\b/,
45
+ /\bfrom now on you (?:will|must|should|shall)\b.{0,60}\b(?:obey|comply|follow all|do whatever|do anything|never refuse)\b/,
46
+ /\bpretend\b.{0,40}\b(?:no restrictions|no rules|no limits|no guidelines|no constraints|unrestricted|unfiltered)\b/,
47
+ /\bact as if\b.{0,40}\b(?:permissions?|restrictions?|rules?|policy|guidelines?|constraints?)\b.{0,20}\b(?:don't|do not|doesn't|does not|did not|didn't)\b/,
48
+ /\byou have\s+(?:full|complete|total|unlimited|unrestricted)\s+(?:\w+\s+)?(?:access|permissions?|authorization|control)\b/,
49
+ /\btreat\s+(?:all|every)\b.{0,40}\b(?:operator|admin|owner|administrator)\b/,
50
+ ];
51
+ const APPROVAL_TAMPERING = [
52
+ /\b(?:auto(?:-|\s)?approve|automatically approve|always approve|approve\s+all|approve\s+every)\b/,
53
+ /\b(?:always accept|never reject|never deny|never refuse|skip\s+approval|bypass\s+approval)\b/,
54
+ /\b(?:treat as approved|mark as active|activate all|force activate|directly activate)\b/,
55
+ /\b(?:without\s+(?:approval|review|verification|confirmation|checking|authorization))\b/,
56
+ ];
57
+ const SAFETY_DISABLE = [
58
+ /\b(?:turn off|shut off|switch off|power off|deactivate|disable|remove|delete|erase|clear|wipe|purge)\b.{0,30}\b(?:safety|security|filter|filtering|moderation|censorship|guardrails?)\b/,
59
+ /\b(?:no\s+(?:safety|security|content)\s+(?:filter|filtering|check|checks|moderation|restrictions))\b/,
60
+ /\b(?:without\s+(?:safety|security|content)\s+(?:filter|filtering|check|checks|moderation|restrictions))\b/,
61
+ ];
62
+ const OVERRIDE_PATTERN = new RegExp(`\\b${OVERRIDE_VERBS}\\b.{0,60}\\b${SAFETY_NOUNS}\\b`, 'i');
63
+ const NEGATION_PATTERN = new RegExp(`\\b${NEGATION_VERBS}\\b.{0,60}\\b${SAFETY_NOUNS}\\b`, 'i');
64
+ const DISCLOSURE_PATTERN = new RegExp(`\\b${DISCLOSURE_VERBS}\\b.{0,60}\\b${SECRET_NOUNS}\\b`, 'i');
65
+ // ── Layer 3: Structural heuristics ───────────────────────────────────────
66
+ const STRUCTURAL_HEURISTICS = [
67
+ { pattern: /\byour\s+new\s+(?:system\s+)?(?:policy|rules?|instructions?|guidelines?|prompt)\s+(?:is|are|will be|should be)\b/i, reason: 'policy_redefinition' },
68
+ { pattern: /\b(?:when|if|after|once)\b.{0,60}\b(?:ignore|stop|disable|bypass|override|forget|drop|abandon)\b.{0,40}\b(?:safety|rules?|policy|guidelines?|restrictions?|guardrails?)\b/i, reason: 'conditional_unsafe_trigger' },
69
+ { pattern: /\b(?:respond|reply|answer|act|behave)\b.{0,30}\b(?:as if you were|as though you are|like you are|pretending to be)\b.{0,40}\b(?:unfiltered|unrestricted|evil|uncensored|without limits)\b/i, reason: 'identity_swap' },
70
+ { pattern: /\b(?:obey\s+all|do\s+whatever|do\s+anything|comply\s+with\s+(?:any|all|every)|always\s+comply|never\s+refuse|never\s+decline|never\s+deny\s+a\s+request)\b/i, reason: 'blanket_obedience' },
71
+ { pattern: /\b(?:execute|run|invoke|call|trigger)\b.{0,20}\b(?:any|all|every)\b.{0,30}\b(?:tool|command|action|function|operation)\b.{0,40}\b(?:without|no)\b.{0,20}\b(?:check|auth|approval|verification|restriction)\b/i, reason: 'unauthorized_execution' },
72
+ ];
73
+ exports.DEFAULT_SAFETY_PATTERNS = {
74
+ overridePattern: OVERRIDE_PATTERN,
75
+ negationPattern: NEGATION_PATTERN,
76
+ disclosurePattern: DISCLOSURE_PATTERN,
77
+ escalationPhrases: ESCALATION_PHRASES,
78
+ approvalTampering: APPROVAL_TAMPERING,
79
+ safetyDisable: SAFETY_DISABLE,
80
+ structuralHeuristics: STRUCTURAL_HEURISTICS,
81
+ };
82
+ function scanDirective(raw, patterns = exports.DEFAULT_SAFETY_PATTERNS) {
83
+ if (!raw || raw.trim() === '') {
84
+ return { safe: true };
85
+ }
86
+ const text = normalizeText(raw);
87
+ if (patterns.overridePattern.test(text)) {
88
+ return { safe: false, reason: 'unsafe_override' };
89
+ }
90
+ if (patterns.negationPattern.test(text)) {
91
+ return { safe: false, reason: 'unsafe_negation' };
92
+ }
93
+ if (patterns.disclosurePattern.test(text)) {
94
+ return { safe: false, reason: 'unsafe_disclosure' };
95
+ }
96
+ for (const pattern of patterns.escalationPhrases) {
97
+ if (pattern.test(text)) {
98
+ return { safe: false, reason: 'unsafe_escalation' };
99
+ }
100
+ }
101
+ for (const pattern of patterns.approvalTampering) {
102
+ if (pattern.test(text)) {
103
+ return { safe: false, reason: 'unsafe_approval_tampering' };
104
+ }
105
+ }
106
+ for (const pattern of patterns.safetyDisable) {
107
+ if (pattern.test(text)) {
108
+ return { safe: false, reason: 'unsafe_safety_disable' };
109
+ }
110
+ }
111
+ for (const { pattern, reason } of patterns.structuralHeuristics) {
112
+ if (pattern.test(text)) {
113
+ return { safe: false, reason };
114
+ }
115
+ }
116
+ return { safe: true };
117
+ }
@@ -0,0 +1,9 @@
1
+ import { SelfPackageParseResult } from './types';
2
+ /**
3
+ * Lightweight YAML to JS object parser supporting basic nested maps, lists, and primitives
4
+ * suitable for .self manifest schemas. Falls back to JSON.parse if the text starts with '{'.
5
+ */
6
+ export declare function parseYamlOrJson(content: string): any;
7
+ export declare class SelfPackageParser {
8
+ static parse(rawContent: string): SelfPackageParseResult;
9
+ }
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SelfPackageParser = void 0;
4
+ exports.parseYamlOrJson = parseYamlOrJson;
5
+ const safety_scanner_1 = require("./safety-scanner");
6
+ /**
7
+ * Lightweight YAML to JS object parser supporting basic nested maps, lists, and primitives
8
+ * suitable for .self manifest schemas. Falls back to JSON.parse if the text starts with '{'.
9
+ */
10
+ function parseYamlOrJson(content) {
11
+ const trimmed = content.trim();
12
+ if (trimmed.startsWith('{')) {
13
+ return JSON.parse(trimmed);
14
+ }
15
+ const lines = content.split('\n');
16
+ const root = {};
17
+ const stack = [
18
+ { indent: -1, obj: root },
19
+ ];
20
+ for (let i = 0; i < lines.length; i++) {
21
+ const rawLine = lines[i];
22
+ // Remove comments
23
+ const commentIdx = rawLine.indexOf('#');
24
+ const line = (commentIdx >= 0 ? rawLine.slice(0, commentIdx) : rawLine).replace(/\r$/, '');
25
+ if (!line.trim())
26
+ continue;
27
+ const indent = line.search(/\S/);
28
+ const text = line.trim();
29
+ // Pop stack to match current indentation
30
+ while (stack.length > 1 && indent <= stack[stack.length - 1].indent) {
31
+ stack.pop();
32
+ }
33
+ const currentParent = stack[stack.length - 1];
34
+ // Check if line is a list item: "- something"
35
+ if (text.startsWith('- ')) {
36
+ const listContent = text.slice(2).trim();
37
+ // Ensure parent has an array for current key or parent itself is list
38
+ let targetArray;
39
+ if (Array.isArray(currentParent.obj)) {
40
+ targetArray = currentParent.obj;
41
+ }
42
+ else if (currentParent.key) {
43
+ const parentFrame = stack.length > 1 ? stack[stack.length - 2] : null;
44
+ if (parentFrame && parentFrame.obj[currentParent.key] === currentParent.obj && Object.keys(currentParent.obj).length === 0) {
45
+ targetArray = [];
46
+ parentFrame.obj[currentParent.key] = targetArray;
47
+ currentParent.obj = targetArray;
48
+ }
49
+ else if (Array.isArray(currentParent.obj[currentParent.key])) {
50
+ targetArray = currentParent.obj[currentParent.key];
51
+ }
52
+ else {
53
+ targetArray = [];
54
+ currentParent.obj[currentParent.key] = targetArray;
55
+ }
56
+ }
57
+ else {
58
+ targetArray = [];
59
+ }
60
+ // Check if list item has inline key-value (e.g. "- id: 'dir-01'")
61
+ const colonIdx = listContent.indexOf(':');
62
+ if (colonIdx > 0 && !listContent.startsWith('"') && !listContent.startsWith("'")) {
63
+ const itemKey = listContent.slice(0, colonIdx).trim();
64
+ const itemVal = parsePrimitive(listContent.slice(colonIdx + 1).trim());
65
+ const itemObj = {};
66
+ if (itemVal !== undefined && itemVal !== '') {
67
+ itemObj[itemKey] = itemVal;
68
+ }
69
+ else {
70
+ itemObj[itemKey] = {};
71
+ }
72
+ targetArray.push(itemObj);
73
+ stack.push({ indent, obj: itemObj, isList: false });
74
+ }
75
+ else {
76
+ // Plain list item (scalar)
77
+ targetArray.push(parsePrimitive(listContent));
78
+ }
79
+ continue;
80
+ }
81
+ // Key-value pair: "key: value"
82
+ const colonIdx = text.indexOf(':');
83
+ if (colonIdx > 0) {
84
+ const key = text.slice(0, colonIdx).trim();
85
+ const valStr = text.slice(colonIdx + 1).trim();
86
+ let targetObj = currentParent.obj;
87
+ if (Array.isArray(targetObj)) {
88
+ targetObj = targetObj[targetObj.length - 1];
89
+ }
90
+ if (valStr === '' || valStr === undefined) {
91
+ // Nested map or upcoming list
92
+ const childObj = {};
93
+ targetObj[key] = childObj;
94
+ stack.push({ indent, obj: childObj, key, isList: false });
95
+ }
96
+ else {
97
+ targetObj[key] = parsePrimitive(valStr);
98
+ }
99
+ }
100
+ }
101
+ return root;
102
+ }
103
+ function parsePrimitive(val) {
104
+ if (val === '')
105
+ return '';
106
+ if (val === 'true')
107
+ return true;
108
+ if (val === 'false')
109
+ return false;
110
+ if (val === 'null')
111
+ return null;
112
+ // Quoted string
113
+ if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
114
+ return val.slice(1, -1);
115
+ }
116
+ // Number
117
+ const num = Number(val);
118
+ if (!isNaN(num) && val.trim() !== '') {
119
+ return num;
120
+ }
121
+ return val;
122
+ }
123
+ class SelfPackageParser {
124
+ static parse(rawContent) {
125
+ const errors = [];
126
+ let data;
127
+ try {
128
+ data = parseYamlOrJson(rawContent);
129
+ }
130
+ catch (err) {
131
+ return {
132
+ isValid: false,
133
+ errors: [`Failed to parse .self file: ${err.message}`],
134
+ scannedDirectives: [],
135
+ };
136
+ }
137
+ if (!data || typeof data !== 'object') {
138
+ return {
139
+ isValid: false,
140
+ errors: ['Invalid .self file format: Root must be an object'],
141
+ scannedDirectives: [],
142
+ };
143
+ }
144
+ // 1. Spec & Kind
145
+ if (data.specVersion !== '1.0.0' && data.specVersion !== '2.0.0') {
146
+ errors.push(`Unsupported or missing specVersion: "${data.specVersion}" (expected "1.0.0" or "2.0.0")`);
147
+ }
148
+ if (data.kind !== 'self') {
149
+ errors.push(`Invalid kind: "${data.kind}" (expected "self")`);
150
+ }
151
+ if (!data.id || typeof data.id !== 'string') {
152
+ errors.push('Missing required string field: "id"');
153
+ }
154
+ if (!data.name || typeof data.name !== 'string') {
155
+ errors.push('Missing required string field: "name"');
156
+ }
157
+ if (!data.version || typeof data.version !== 'string') {
158
+ errors.push('Missing required string field: "version"');
159
+ }
160
+ // 2. Author
161
+ if (!data.author || typeof data.author !== 'object' || !data.author.name) {
162
+ errors.push('Missing required field: "author" with "name"');
163
+ }
164
+ // 3. Identity
165
+ if (!data.identity || typeof data.identity !== 'object' || !data.identity.name) {
166
+ errors.push('Missing required field: "identity" with "name"');
167
+ }
168
+ // 4. Personality validation (Optional in v2.0 / LLM-native mode)
169
+ const p = data.personality;
170
+ let traits;
171
+ if (p !== undefined && p !== null) {
172
+ if (typeof p !== 'object') {
173
+ errors.push('Field "personality" must be an object if provided');
174
+ }
175
+ else {
176
+ traits = {};
177
+ const keys = ['warmth', 'formality', 'sarcasm', 'verbosity', 'curiosity'];
178
+ for (const k of keys) {
179
+ if (p[k] !== undefined) {
180
+ if (typeof p[k] !== 'number' || p[k] < 0.0 || p[k] > 1.0) {
181
+ errors.push(`Personality trait "${k}" must be a number between 0.0 and 1.0`);
182
+ }
183
+ else {
184
+ traits[k] = p[k];
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+ // 5. Relationships validation (Optional)
191
+ const relationships = Array.isArray(data.relationships)
192
+ ? data.relationships
193
+ .filter((r) => r && typeof r === 'object' && r.entityId)
194
+ .map((r) => ({
195
+ entityId: String(r.entityId),
196
+ role: String(r.role || 'user'),
197
+ stance: String(r.stance || 'neutral'),
198
+ conventions: Array.isArray(r.conventions) ? r.conventions.map(String) : undefined,
199
+ }))
200
+ : undefined;
201
+ // 6. Dialogue Examples validation (Optional)
202
+ const dialogueExamples = Array.isArray(data.dialogueExamples)
203
+ ? data.dialogueExamples
204
+ .filter((ex) => ex && typeof ex === 'object' && ex.user && ex.assistant)
205
+ .map((ex) => ({
206
+ user: String(ex.user),
207
+ assistant: String(ex.assistant),
208
+ }))
209
+ : undefined;
210
+ // 7. Directives validation & scanning
211
+ const scannedDirectives = [];
212
+ if (!Array.isArray(data.directives)) {
213
+ errors.push('Missing required array field: "directives"');
214
+ }
215
+ else {
216
+ for (let i = 0; i < data.directives.length; i++) {
217
+ const d = data.directives[i];
218
+ if (!d || typeof d !== 'object' || !d.directive) {
219
+ errors.push(`Directive at index ${i} is missing "directive" string`);
220
+ continue;
221
+ }
222
+ const scan = (0, safety_scanner_1.scanDirective)(d.directive);
223
+ scannedDirectives.push({
224
+ id: d.id || `dir-${i + 1}`,
225
+ priority: typeof d.priority === 'number' ? d.priority : 50,
226
+ directive: d.directive,
227
+ category: d.category || 'behavioral',
228
+ scopeActor: d.scopeActor,
229
+ supersedesId: d.supersedesId,
230
+ scanResult: scan,
231
+ approvedByDefault: scan.safe,
232
+ });
233
+ }
234
+ }
235
+ const isValid = errors.length === 0;
236
+ let manifest;
237
+ if (isValid) {
238
+ manifest = {
239
+ specVersion: data.specVersion,
240
+ kind: 'self',
241
+ id: data.id,
242
+ name: data.name,
243
+ version: data.version,
244
+ author: {
245
+ name: data.author.name,
246
+ url: data.author.url,
247
+ signature: data.author.signature,
248
+ },
249
+ license: data.license,
250
+ identity: {
251
+ name: data.identity.name,
252
+ archetype: data.identity.archetype,
253
+ origin: data.identity.origin,
254
+ ethos: data.identity.ethos,
255
+ },
256
+ personality: traits,
257
+ relationships,
258
+ directives: scannedDirectives.map((sd) => ({
259
+ id: sd.id,
260
+ priority: sd.priority,
261
+ directive: sd.directive,
262
+ category: sd.category,
263
+ scopeActor: sd.scopeActor,
264
+ supersedesId: sd.supersedesId,
265
+ })),
266
+ guardrails: Array.isArray(data.guardrails) ? data.guardrails : undefined,
267
+ dialogueExamples,
268
+ };
269
+ }
270
+ return {
271
+ manifest,
272
+ scannedDirectives,
273
+ isValid,
274
+ errors,
275
+ };
276
+ }
277
+ }
278
+ exports.SelfPackageParser = SelfPackageParser;
@@ -0,0 +1,29 @@
1
+ import { SiduriDatabase, SelfIdentity, PersonalityTraits, SelfDirective, SelfRelationship, SelfDialogueExample } from '@sidurijs/core';
2
+ import { SelfRepository } from './types';
3
+ export interface SqliteSelfRepositoryOptions {
4
+ db?: SiduriDatabase;
5
+ dbPath?: string;
6
+ }
7
+ export declare const DEFAULT_PERSONALITY_TRAITS: PersonalityTraits;
8
+ export declare class SqliteSelfRepository implements SelfRepository {
9
+ private db;
10
+ private ownsDb;
11
+ constructor(options?: SqliteSelfRepositoryOptions);
12
+ getIdentity(companionId: string): Promise<SelfIdentity | undefined>;
13
+ setIdentity(identity: SelfIdentity): Promise<void>;
14
+ getPersonality(companionId: string): Promise<PersonalityTraits>;
15
+ setPersonality(companionId: string, traits: PersonalityTraits): Promise<void>;
16
+ getActiveDirectives(companionId: string): Promise<SelfDirective[]>;
17
+ commitDirectives(companionId: string, directives: SelfDirective[]): Promise<void>;
18
+ approveDirective(id: string, companionId?: string): Promise<void>;
19
+ rejectDirective(id: string, companionId?: string): Promise<void>;
20
+ revokeDirective(id: string, companionId?: string): Promise<void>;
21
+ expireDirective(id: string, companionId?: string): Promise<void>;
22
+ disableDirective(id: string, companionId?: string): Promise<void>;
23
+ getRelationships(companionId: string): Promise<SelfRelationship[]>;
24
+ getRelationship(companionId: string, entityId: string): Promise<SelfRelationship | null>;
25
+ updateRelationship(companionId: string, rel: SelfRelationship): Promise<void>;
26
+ getExemplars(companionId: string): Promise<SelfDialogueExample[]>;
27
+ setExemplars(companionId: string, exemplars: SelfDialogueExample[]): Promise<void>;
28
+ close(): void;
29
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SqliteSelfRepository = exports.DEFAULT_PERSONALITY_TRAITS = void 0;
4
+ const core_1 = require("@sidurijs/core");
5
+ exports.DEFAULT_PERSONALITY_TRAITS = {
6
+ warmth: 0.5,
7
+ formality: 0.5,
8
+ sarcasm: 0.5,
9
+ verbosity: 0.5,
10
+ curiosity: 0.5,
11
+ };
12
+ class SqliteSelfRepository {
13
+ db;
14
+ ownsDb;
15
+ constructor(options = {}) {
16
+ if (options.db) {
17
+ this.db = options.db;
18
+ this.ownsDb = false;
19
+ }
20
+ else {
21
+ this.db = new core_1.SiduriDatabase({ dbPath: options.dbPath });
22
+ this.ownsDb = true;
23
+ }
24
+ }
25
+ async getIdentity(companionId) {
26
+ return this.db.getIdentity(companionId);
27
+ }
28
+ async setIdentity(identity) {
29
+ this.db.setIdentity(identity);
30
+ }
31
+ async getPersonality(companionId) {
32
+ const traits = this.db.getPersonality(companionId);
33
+ return traits || { ...exports.DEFAULT_PERSONALITY_TRAITS };
34
+ }
35
+ async setPersonality(companionId, traits) {
36
+ this.db.setPersonality(companionId, traits);
37
+ }
38
+ async getActiveDirectives(companionId) {
39
+ return this.db.getActiveDirectives(companionId);
40
+ }
41
+ async commitDirectives(companionId, directives) {
42
+ for (const d of directives) {
43
+ this.db.commitDirective({
44
+ ...d,
45
+ companionId,
46
+ });
47
+ }
48
+ }
49
+ async approveDirective(id, companionId) {
50
+ this.db.approveDirective(id, companionId);
51
+ }
52
+ async rejectDirective(id, companionId) {
53
+ this.db.rejectDirective(id, companionId);
54
+ }
55
+ async revokeDirective(id, companionId) {
56
+ this.db.revokeDirective(id, companionId);
57
+ }
58
+ async expireDirective(id, companionId) {
59
+ this.db.expireDirective(id, companionId);
60
+ }
61
+ async disableDirective(id, companionId) {
62
+ this.db.disableDirective(id, companionId);
63
+ }
64
+ async getRelationships(companionId) {
65
+ return this.db.getRelationships(companionId);
66
+ }
67
+ async getRelationship(companionId, entityId) {
68
+ const rel = this.db.getRelationship(companionId, entityId);
69
+ return rel ?? null;
70
+ }
71
+ async updateRelationship(companionId, rel) {
72
+ this.db.upsertRelationship({
73
+ ...rel,
74
+ companionId,
75
+ });
76
+ }
77
+ async getExemplars(companionId) {
78
+ return this.db.getExemplars(companionId);
79
+ }
80
+ async setExemplars(companionId, exemplars) {
81
+ this.db.setExemplars(companionId, exemplars);
82
+ }
83
+ close() {
84
+ if (this.ownsDb) {
85
+ this.db.close();
86
+ }
87
+ }
88
+ }
89
+ exports.SqliteSelfRepository = SqliteSelfRepository;
@@ -0,0 +1 @@
1
+ export {};