@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/index.d.ts
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
export * from './context';
|
|
2
|
+
export * from './proposals';
|
|
3
|
+
export * from './evidence';
|
|
4
|
+
export * from './gating';
|
|
5
|
+
export * from './experience';
|
|
6
|
+
export * from './dispatcher';
|
|
7
|
+
export * from './action';
|
|
8
|
+
export * from './action-policy';
|
|
9
|
+
export * from './ear-types';
|
|
10
|
+
export * from './capability';
|
|
11
|
+
export * from './sqlite-action-store';
|
|
12
|
+
export * from './teaching';
|
|
13
|
+
export * from './runtime';
|
|
14
|
+
export * from './chat-contract';
|
|
15
|
+
export * from './input-normalizer';
|
|
16
|
+
export * from './intent-classifier';
|
|
17
|
+
export * from './context-retriever';
|
|
18
|
+
export * from './prompt-compiler';
|
|
19
|
+
export * from './cognition-planner';
|
|
20
|
+
export * from './memory-settler';
|
|
21
|
+
export * from './action-executor';
|
|
22
|
+
export * from './experience-emitter';
|
|
23
|
+
export * from './response-envelope';
|
|
24
|
+
export * from './session-history';
|
|
25
|
+
export * from './schema-validator';
|
|
26
|
+
export * from './siduri-db';
|
|
27
|
+
export * from './database';
|
|
28
|
+
export * from './container';
|
|
29
|
+
export * from './perception-pipeline';
|
|
30
|
+
import { EvidenceRecord } from './evidence';
|
|
31
|
+
import { ActionIntent } from './action';
|
|
32
|
+
import { RequestContext } from './context';
|
|
33
|
+
import { EarIngestOptions } from './ear-types';
|
|
34
|
+
import { ClaimType, ClaimAuthority, ClaimStatus, DirectiveStatus, SourceEvent, MemoryProposal, BehaviorProposal } from './proposals';
|
|
35
|
+
export interface OrganConfig {
|
|
36
|
+
provider: string;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
export interface CompanionConfig {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
brain: OrganConfig;
|
|
43
|
+
voice: OrganConfig;
|
|
44
|
+
memory: OrganConfig;
|
|
45
|
+
knowledge: OrganConfig;
|
|
46
|
+
behavior: OrganConfig;
|
|
47
|
+
body: OrganConfig;
|
|
48
|
+
vision: OrganConfig;
|
|
49
|
+
}
|
|
50
|
+
export interface Message {
|
|
51
|
+
role: 'user' | 'assistant' | 'system';
|
|
52
|
+
content: string;
|
|
53
|
+
name?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface BrainContext {
|
|
56
|
+
systemPrompt: string;
|
|
57
|
+
contextPrompt: string;
|
|
58
|
+
recentMessages: Message[];
|
|
59
|
+
recipient?: MemoryScope;
|
|
60
|
+
}
|
|
61
|
+
export interface ResponsePlan {
|
|
62
|
+
speech: string;
|
|
63
|
+
language: string;
|
|
64
|
+
subtitle?: string;
|
|
65
|
+
subtitles?: Record<string, string>;
|
|
66
|
+
memoryProposals?: MemoryProposal[];
|
|
67
|
+
behaviorProposals?: BehaviorProposal[];
|
|
68
|
+
actionIntents?: ActionIntent[];
|
|
69
|
+
internalMonologue?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface RetrievalPlan {
|
|
72
|
+
shouldQueryKnowledge: boolean;
|
|
73
|
+
knowledgeQueries: string[];
|
|
74
|
+
shouldQueryMemory?: boolean;
|
|
75
|
+
memoryQueries?: string[];
|
|
76
|
+
reasoning?: string;
|
|
77
|
+
}
|
|
78
|
+
export interface PersonaCompilationResult {
|
|
79
|
+
isValid: boolean;
|
|
80
|
+
manifest: {
|
|
81
|
+
specVersion?: string;
|
|
82
|
+
kind?: 'self';
|
|
83
|
+
id?: string;
|
|
84
|
+
name?: string;
|
|
85
|
+
version?: string;
|
|
86
|
+
author?: {
|
|
87
|
+
name: string;
|
|
88
|
+
url?: string;
|
|
89
|
+
signature?: string;
|
|
90
|
+
};
|
|
91
|
+
identity: {
|
|
92
|
+
name: string;
|
|
93
|
+
archetype?: string;
|
|
94
|
+
origin?: string;
|
|
95
|
+
ethos?: string;
|
|
96
|
+
};
|
|
97
|
+
personality?: PersonalityTraits;
|
|
98
|
+
relationships?: Array<{
|
|
99
|
+
entityId: string;
|
|
100
|
+
role?: string;
|
|
101
|
+
stance?: string;
|
|
102
|
+
conventions?: string[];
|
|
103
|
+
}>;
|
|
104
|
+
directives: Array<{
|
|
105
|
+
id?: string;
|
|
106
|
+
directive: string;
|
|
107
|
+
category?: 'guardrail' | 'relational' | 'behavioral';
|
|
108
|
+
priority?: number;
|
|
109
|
+
scopeActor?: string;
|
|
110
|
+
supersedesId?: string;
|
|
111
|
+
}>;
|
|
112
|
+
dialogueExamples?: Array<{
|
|
113
|
+
user: string;
|
|
114
|
+
assistant: string;
|
|
115
|
+
}>;
|
|
116
|
+
};
|
|
117
|
+
errors?: string[];
|
|
118
|
+
}
|
|
119
|
+
export interface BrainOrgan {
|
|
120
|
+
generatePlan(context: BrainContext): Promise<ResponsePlan>;
|
|
121
|
+
planRetrieval?(text: string, context?: RequestContext, recentHistory?: {
|
|
122
|
+
role: string;
|
|
123
|
+
content: string;
|
|
124
|
+
}[]): Promise<RetrievalPlan>;
|
|
125
|
+
compilePersona?(content: string, options?: {
|
|
126
|
+
companionId?: string;
|
|
127
|
+
}): Promise<PersonaCompilationResult>;
|
|
128
|
+
}
|
|
129
|
+
export type MemoryScope = 'companion' | 'user' | string;
|
|
130
|
+
export interface Claim {
|
|
131
|
+
id: string;
|
|
132
|
+
subject: string;
|
|
133
|
+
predicate: string;
|
|
134
|
+
value: string;
|
|
135
|
+
status: ClaimStatus;
|
|
136
|
+
evidence?: string[];
|
|
137
|
+
scope?: MemoryScope;
|
|
138
|
+
companionId: string;
|
|
139
|
+
provenance?: string;
|
|
140
|
+
sourceEventId?: string;
|
|
141
|
+
claimType?: ClaimType;
|
|
142
|
+
authority?: ClaimAuthority;
|
|
143
|
+
userConfirmation?: 'explicit' | 'implied' | 'none';
|
|
144
|
+
sensitivity?: string;
|
|
145
|
+
confidence?: number;
|
|
146
|
+
assertedAt?: string;
|
|
147
|
+
validFrom?: string;
|
|
148
|
+
validUntil?: string;
|
|
149
|
+
supersedes?: string;
|
|
150
|
+
replaces?: string;
|
|
151
|
+
[key: string]: unknown;
|
|
152
|
+
}
|
|
153
|
+
export interface BehaviorDirective {
|
|
154
|
+
id: string;
|
|
155
|
+
companionId: string;
|
|
156
|
+
directive: string;
|
|
157
|
+
priority: number;
|
|
158
|
+
status: DirectiveStatus;
|
|
159
|
+
supersedesId?: string;
|
|
160
|
+
memoryClass?: 'identity' | 'relationship' | 'behavioral';
|
|
161
|
+
subject?: string;
|
|
162
|
+
predicate?: string;
|
|
163
|
+
value?: string;
|
|
164
|
+
validFrom?: string;
|
|
165
|
+
validUntil?: string;
|
|
166
|
+
[key: string]: unknown;
|
|
167
|
+
}
|
|
168
|
+
export interface MemoryQueryOptions {
|
|
169
|
+
sensitivity?: string;
|
|
170
|
+
limit?: number;
|
|
171
|
+
minConfidence?: number;
|
|
172
|
+
now?: string | Date;
|
|
173
|
+
[key: string]: unknown;
|
|
174
|
+
}
|
|
175
|
+
export interface MemoryOrgan {
|
|
176
|
+
initialize(companionId: string): Promise<void>;
|
|
177
|
+
proposeClaim(claim: Omit<Claim, 'id' | 'status' | 'companionId'>): Promise<Claim>;
|
|
178
|
+
searchClaims(query: string, scopeOrOptions?: MemoryScope | MemoryQueryOptions, limit?: number): Promise<Claim[]>;
|
|
179
|
+
getClaims(limit?: number): Promise<Claim[]>;
|
|
180
|
+
getPendingClaims(limit?: number): Promise<Claim[]>;
|
|
181
|
+
getApprovedClaims?(companionId?: string, limit?: number): Promise<any[]>;
|
|
182
|
+
approveClaim(id: string): Promise<void>;
|
|
183
|
+
rejectClaim(id: string): Promise<void>;
|
|
184
|
+
markClaimSessionOnly?(id: string): Promise<void>;
|
|
185
|
+
expireClaim?(id: string): Promise<void>;
|
|
186
|
+
revokeClaim?(id: string, reason?: string): Promise<void>;
|
|
187
|
+
getDirectives(companionId?: string): Promise<BehaviorDirective[]>;
|
|
188
|
+
proposeDirective(directiveData: Omit<BehaviorDirective, 'id' | 'status' | 'companionId'> & {
|
|
189
|
+
companionId?: string;
|
|
190
|
+
}): Promise<BehaviorDirective>;
|
|
191
|
+
approveDirective(id: string, companionId?: string): Promise<void>;
|
|
192
|
+
rejectDirective(id: string, companionId?: string): Promise<void>;
|
|
193
|
+
revokeDirective(id: string, companionId?: string): Promise<void>;
|
|
194
|
+
disableDirective(id: string, companionId?: string): Promise<void>;
|
|
195
|
+
expireDirective?(id: string, companionId?: string): Promise<void>;
|
|
196
|
+
supersedeClaim?(id: string, replacement: Omit<Claim, 'id' | 'status' | 'companionId'>): Promise<Claim>;
|
|
197
|
+
updateClaim?(id: string, updates: Partial<Pick<Claim, 'subject' | 'predicate' | 'value' | 'scope' | 'sensitivity' | 'confidence' | 'validFrom' | 'validUntil'>>): Promise<Claim>;
|
|
198
|
+
resetMemory?(): Promise<void>;
|
|
199
|
+
addSourceEvent?(event: SourceEvent): Promise<SourceEvent>;
|
|
200
|
+
getSourceEvent?(id: string): Promise<SourceEvent | undefined>;
|
|
201
|
+
}
|
|
202
|
+
export interface AudioEvent {
|
|
203
|
+
type: 'STARTED' | 'COMPLETED' | 'FAILED';
|
|
204
|
+
speechId: string;
|
|
205
|
+
text?: string;
|
|
206
|
+
language?: string;
|
|
207
|
+
audioBuffer?: Uint8Array;
|
|
208
|
+
}
|
|
209
|
+
export interface VoiceOrgan {
|
|
210
|
+
enqueueSpeech(text: string, language: string, priority?: number): string;
|
|
211
|
+
onLifecycleEvent(callback: (event: AudioEvent) => void): void;
|
|
212
|
+
getQueueStatus(): {
|
|
213
|
+
pending: number;
|
|
214
|
+
current?: string;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
export interface VisionOrgan {
|
|
218
|
+
analyze(imageUrl: string, prompt: string): Promise<string>;
|
|
219
|
+
}
|
|
220
|
+
export interface ActiveSelfProjection {
|
|
221
|
+
identityFacts: string[];
|
|
222
|
+
relationshipFacts: string[];
|
|
223
|
+
behavioralRules: string[];
|
|
224
|
+
activeIds: string[];
|
|
225
|
+
excludedIds: string[];
|
|
226
|
+
diagnostics: Record<string, string>;
|
|
227
|
+
render(): string;
|
|
228
|
+
}
|
|
229
|
+
export interface BehaviorContext {
|
|
230
|
+
directives: BehaviorDirective[];
|
|
231
|
+
companionId?: string;
|
|
232
|
+
actorId?: string;
|
|
233
|
+
sessionId?: string;
|
|
234
|
+
now?: string;
|
|
235
|
+
[key: string]: unknown;
|
|
236
|
+
}
|
|
237
|
+
export interface BehaviorOrgan {
|
|
238
|
+
compile(context: BehaviorContext): Promise<string>;
|
|
239
|
+
compileProjection?(context: BehaviorContext): Promise<ActiveSelfProjection>;
|
|
240
|
+
}
|
|
241
|
+
export interface KnowledgeItem {
|
|
242
|
+
content: string;
|
|
243
|
+
provenance: string;
|
|
244
|
+
revision: string;
|
|
245
|
+
citations: KnowledgeCitation[];
|
|
246
|
+
evidenceRecord?: EvidenceRecord;
|
|
247
|
+
}
|
|
248
|
+
export interface KnowledgeCitation {
|
|
249
|
+
sourceId: string;
|
|
250
|
+
documentId?: string;
|
|
251
|
+
chunkId?: string;
|
|
252
|
+
locator?: string;
|
|
253
|
+
}
|
|
254
|
+
export interface KnowledgeOrgan {
|
|
255
|
+
search(query: string): Promise<KnowledgeItem[]>;
|
|
256
|
+
}
|
|
257
|
+
export interface EarPerception {
|
|
258
|
+
id: string;
|
|
259
|
+
source: string;
|
|
260
|
+
text?: string;
|
|
261
|
+
audioBuffer?: Uint8Array;
|
|
262
|
+
metadata?: Record<string, unknown>;
|
|
263
|
+
timestamp: string;
|
|
264
|
+
}
|
|
265
|
+
export interface EarOrgan {
|
|
266
|
+
listen(source: string, payload: unknown, options?: EarIngestOptions): Promise<EarPerception>;
|
|
267
|
+
transcribeAudio?(audio: Uint8Array): Promise<string>;
|
|
268
|
+
classifyIntent?(text: string, context?: RequestContext): Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
269
|
+
}
|
|
270
|
+
export interface BodyOrgan {
|
|
271
|
+
setExpression(expression: string): void;
|
|
272
|
+
speak(speechId: string, text?: string, language?: string): void;
|
|
273
|
+
act(action: string): void;
|
|
274
|
+
completeAction?(): void;
|
|
275
|
+
}
|
|
276
|
+
export interface ObservationReading {
|
|
277
|
+
entity: string;
|
|
278
|
+
value: string;
|
|
279
|
+
confidence: number;
|
|
280
|
+
sourceCrop?: string;
|
|
281
|
+
ocrText?: string;
|
|
282
|
+
competingInterpretations?: string[];
|
|
283
|
+
}
|
|
284
|
+
export interface Observation {
|
|
285
|
+
observationId: string;
|
|
286
|
+
evidenceId: string;
|
|
287
|
+
sourceName: string;
|
|
288
|
+
providerId: string;
|
|
289
|
+
readings: ObservationReading[];
|
|
290
|
+
confidence: number;
|
|
291
|
+
createdAt: string;
|
|
292
|
+
expiresAt: string;
|
|
293
|
+
frameDigest: string;
|
|
294
|
+
}
|
|
295
|
+
export interface ObservationResult {
|
|
296
|
+
observation?: Observation;
|
|
297
|
+
duplicate: boolean;
|
|
298
|
+
reason?: 'empty_frame' | 'duplicate_frame' | 'invalid_reading' | 'provider_failure';
|
|
299
|
+
}
|
|
300
|
+
export interface ObservationOrgan {
|
|
301
|
+
ingest(frame: Uint8Array, sourceName: string, providerId?: string): Promise<ObservationResult>;
|
|
302
|
+
current(now?: Date): Observation[];
|
|
303
|
+
clearExpired(now?: Date): number;
|
|
304
|
+
}
|
|
305
|
+
export interface HealthProbeContext {
|
|
306
|
+
config: unknown;
|
|
307
|
+
env: NodeJS.ProcessEnv | Record<string, string | undefined>;
|
|
308
|
+
}
|
|
309
|
+
export interface HealthProbeResult {
|
|
310
|
+
ok: boolean;
|
|
311
|
+
message?: string;
|
|
312
|
+
details?: Record<string, unknown>;
|
|
313
|
+
}
|
|
314
|
+
export type HealthProbeFn = (context: HealthProbeContext) => Promise<HealthProbeResult> | HealthProbeResult;
|
|
315
|
+
export * from './mouth-types';
|
|
316
|
+
import type { SelfIdentity, PersonalityTraits, SelfDirective, SelfRelationship, SelfDialogueExample, LifeInventoryItem, LifeScheduleItem, LifePreference, LifeEntity, LifeEvent, LifeTask, MemoryClaim, EpisodicEvent } from './siduri-db';
|
|
317
|
+
export type { SelfIdentity, PersonalityTraits, SelfDirective, SelfRelationship, SelfDialogueExample, LifeInventoryItem, LifeScheduleItem, LifePreference, LifeEntity, LifeEvent, LifeTask, MemoryClaim, EpisodicEvent, };
|
|
318
|
+
export interface SelfRepository {
|
|
319
|
+
getIdentity(companionId: string): Promise<SelfIdentity | undefined>;
|
|
320
|
+
setIdentity(identity: SelfIdentity): Promise<void>;
|
|
321
|
+
getPersonality?(companionId: string): Promise<PersonalityTraits>;
|
|
322
|
+
setPersonality?(companionId: string, traits: PersonalityTraits): Promise<void>;
|
|
323
|
+
getActiveDirectives(companionId: string): Promise<SelfDirective[]>;
|
|
324
|
+
getRelationship(companionId: string, entityId: string): Promise<SelfRelationship | null>;
|
|
325
|
+
getRelationships?(companionId: string): Promise<SelfRelationship[]>;
|
|
326
|
+
getExemplars?(companionId: string): Promise<SelfDialogueExample[]>;
|
|
327
|
+
setExemplars?(companionId: string, exemplars: SelfDialogueExample[]): Promise<void>;
|
|
328
|
+
commitDirectives(companionId: string, directives: SelfDirective[]): Promise<void>;
|
|
329
|
+
updateRelationship(companionId: string, rel: SelfRelationship): Promise<void>;
|
|
330
|
+
disableDirective?(id: string, companionId?: string): Promise<void>;
|
|
331
|
+
approveDirective?(id: string, companionId?: string): Promise<void>;
|
|
332
|
+
rejectDirective?(id: string, companionId?: string): Promise<void>;
|
|
333
|
+
revokeDirective?(id: string, companionId?: string): Promise<void>;
|
|
334
|
+
expireDirective?(id: string, companionId?: string): Promise<void>;
|
|
335
|
+
getActiveSelf?(companionId: string): Promise<{
|
|
336
|
+
identity?: SelfIdentity;
|
|
337
|
+
personality?: PersonalityTraits;
|
|
338
|
+
directives: SelfDirective[];
|
|
339
|
+
relationships?: SelfRelationship[];
|
|
340
|
+
exemplars?: SelfDialogueExample[];
|
|
341
|
+
}>;
|
|
342
|
+
}
|
|
343
|
+
export interface LifeDatabase {
|
|
344
|
+
getInventory(companionId: string, domain?: string): Promise<LifeInventoryItem[]>;
|
|
345
|
+
getFinanceSummary?(companionId: string): Promise<any>;
|
|
346
|
+
getSchedule?(companionId: string, windowStart?: Date, windowEnd?: Date): Promise<LifeScheduleItem[]>;
|
|
347
|
+
getPreferences?(companionId: string): Promise<Record<string, string> | LifePreference[]>;
|
|
348
|
+
getEntities?(companionId: string, entityType?: string, domain?: string): Promise<LifeEntity[]>;
|
|
349
|
+
getEvents?(companionId: string, stream?: string, limit?: number): Promise<LifeEvent[]>;
|
|
350
|
+
getTasks?(companionId: string, status?: string): Promise<LifeTask[]>;
|
|
351
|
+
queryContext(companionId: string, query: string): Promise<string[]>;
|
|
352
|
+
searchLifeContext?(queryText: string): Promise<string[]>;
|
|
353
|
+
}
|
|
354
|
+
export interface EpisodicMemoryStore {
|
|
355
|
+
recordEvent(companionId: string, event: any): Promise<void>;
|
|
356
|
+
searchClaims(companionId: string, query: string, limit?: number): Promise<MemoryClaim[]>;
|
|
357
|
+
proposeClaim(claim: any): Promise<MemoryClaim>;
|
|
358
|
+
approveClaim(claimId: string): Promise<void>;
|
|
359
|
+
rejectClaim?(claimId: string): Promise<void>;
|
|
360
|
+
getApprovedClaims?(companionId: string, limit?: number): Promise<MemoryClaim[]>;
|
|
361
|
+
getRecentEvents?(companionId: string, limit?: number): Promise<EpisodicEvent[]>;
|
|
362
|
+
}
|
|
363
|
+
export interface EKnowledgeOrgan {
|
|
364
|
+
search(query: string): Promise<KnowledgeItem[]>;
|
|
365
|
+
}
|
|
366
|
+
export { promoteApprovedClaimToSelf, promoteApprovedClaimToKnowledge, isSelfAffectingClaim, isKnowledgeAffectingClaim, } from './runtime';
|
|
367
|
+
export { SiduriDatabase, type SiduriDatabaseOptions, type LogLevel, type SystemLog, } from './siduri-db';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SiduriDatabase = exports.isKnowledgeAffectingClaim = exports.isSelfAffectingClaim = exports.promoteApprovedClaimToKnowledge = exports.promoteApprovedClaimToSelf = void 0;
|
|
18
|
+
// Export neutral context types and validator
|
|
19
|
+
__exportStar(require("./context"), exports);
|
|
20
|
+
__exportStar(require("./proposals"), exports);
|
|
21
|
+
__exportStar(require("./evidence"), exports);
|
|
22
|
+
__exportStar(require("./gating"), exports);
|
|
23
|
+
__exportStar(require("./experience"), exports);
|
|
24
|
+
__exportStar(require("./dispatcher"), exports);
|
|
25
|
+
__exportStar(require("./action"), exports);
|
|
26
|
+
__exportStar(require("./action-policy"), exports);
|
|
27
|
+
__exportStar(require("./ear-types"), exports);
|
|
28
|
+
__exportStar(require("./capability"), exports);
|
|
29
|
+
__exportStar(require("./sqlite-action-store"), exports);
|
|
30
|
+
__exportStar(require("./teaching"), exports);
|
|
31
|
+
__exportStar(require("./runtime"), exports);
|
|
32
|
+
__exportStar(require("./chat-contract"), exports);
|
|
33
|
+
__exportStar(require("./input-normalizer"), exports);
|
|
34
|
+
__exportStar(require("./intent-classifier"), exports);
|
|
35
|
+
__exportStar(require("./context-retriever"), exports);
|
|
36
|
+
__exportStar(require("./prompt-compiler"), exports);
|
|
37
|
+
__exportStar(require("./cognition-planner"), exports);
|
|
38
|
+
__exportStar(require("./memory-settler"), exports);
|
|
39
|
+
__exportStar(require("./action-executor"), exports);
|
|
40
|
+
__exportStar(require("./experience-emitter"), exports);
|
|
41
|
+
__exportStar(require("./response-envelope"), exports);
|
|
42
|
+
__exportStar(require("./session-history"), exports);
|
|
43
|
+
__exportStar(require("./schema-validator"), exports);
|
|
44
|
+
__exportStar(require("./siduri-db"), exports);
|
|
45
|
+
__exportStar(require("./database"), exports);
|
|
46
|
+
__exportStar(require("./container"), exports);
|
|
47
|
+
__exportStar(require("./perception-pipeline"), exports);
|
|
48
|
+
// Mouth (Communication & Output Delivery)
|
|
49
|
+
__exportStar(require("./mouth-types"), exports);
|
|
50
|
+
var runtime_1 = require("./runtime");
|
|
51
|
+
Object.defineProperty(exports, "promoteApprovedClaimToSelf", { enumerable: true, get: function () { return runtime_1.promoteApprovedClaimToSelf; } });
|
|
52
|
+
Object.defineProperty(exports, "promoteApprovedClaimToKnowledge", { enumerable: true, get: function () { return runtime_1.promoteApprovedClaimToKnowledge; } });
|
|
53
|
+
Object.defineProperty(exports, "isSelfAffectingClaim", { enumerable: true, get: function () { return runtime_1.isSelfAffectingClaim; } });
|
|
54
|
+
Object.defineProperty(exports, "isKnowledgeAffectingClaim", { enumerable: true, get: function () { return runtime_1.isKnowledgeAffectingClaim; } });
|
|
55
|
+
var siduri_db_1 = require("./siduri-db");
|
|
56
|
+
Object.defineProperty(exports, "SiduriDatabase", { enumerable: true, get: function () { return siduri_db_1.SiduriDatabase; } });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Message, RequestContext, EarOrgan } from './index';
|
|
2
|
+
export interface NormalizedInput {
|
|
3
|
+
perceivedText: string;
|
|
4
|
+
sanitizedText: string;
|
|
5
|
+
requestContext: RequestContext;
|
|
6
|
+
role: 'OWNER' | 'VIEWER' | 'OPERATOR';
|
|
7
|
+
isContextObject: boolean;
|
|
8
|
+
boundedHistory: Message[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Validates raw user input, synthesizes RequestContext, normalizes history,
|
|
12
|
+
* and routes input through EarOrgan if available.
|
|
13
|
+
*/
|
|
14
|
+
export declare function normalizeUserInput(message: string, roleOrContext: ("OWNER" | "VIEWER" | "OPERATOR" | RequestContext | string) | undefined, history: Message[] | undefined, companionId: string, ear?: EarOrgan): Promise<NormalizedInput>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeUserInput = normalizeUserInput;
|
|
4
|
+
/**
|
|
5
|
+
* Validates raw user input, synthesizes RequestContext, normalizes history,
|
|
6
|
+
* and routes input through EarOrgan if available.
|
|
7
|
+
*/
|
|
8
|
+
async function normalizeUserInput(message, roleOrContext = 'OWNER', history = [], companionId, ear) {
|
|
9
|
+
if (typeof message !== 'string' || !message.trim() || message.length > 4000) {
|
|
10
|
+
throw new Error('message must be a non-empty string of at most 4000 characters');
|
|
11
|
+
}
|
|
12
|
+
if (!Array.isArray(history) ||
|
|
13
|
+
history.length > 20 ||
|
|
14
|
+
history.some((item) => !item || !['user', 'assistant'].includes(item.role) || typeof item.content !== 'string')) {
|
|
15
|
+
throw new Error('history must contain at most 20 user/assistant messages');
|
|
16
|
+
}
|
|
17
|
+
const isContextObject = typeof roleOrContext === 'object' && roleOrContext !== null;
|
|
18
|
+
const role = isContextObject
|
|
19
|
+
? (roleOrContext.actor?.authorizationRole === 'viewer' || roleOrContext.actor?.authenticated === false
|
|
20
|
+
? 'VIEWER'
|
|
21
|
+
: 'OWNER')
|
|
22
|
+
: roleOrContext;
|
|
23
|
+
const defaultActor = {
|
|
24
|
+
actorId: role === 'VIEWER' ? 'anonymous-session' : 'owner-user',
|
|
25
|
+
sessionId: `sess-${companionId}`,
|
|
26
|
+
authorizationRole: role === 'VIEWER' ? 'viewer' : 'administrator',
|
|
27
|
+
capabilities: role === 'VIEWER' ? ['chat'] : ['chat', 'memory:approve', 'action:execute'],
|
|
28
|
+
authenticated: role !== 'VIEWER',
|
|
29
|
+
};
|
|
30
|
+
const defaultConversation = {
|
|
31
|
+
channel: 'direct',
|
|
32
|
+
correlationId: `corr-${Date.now()}`,
|
|
33
|
+
};
|
|
34
|
+
const requestContext = isContextObject
|
|
35
|
+
? {
|
|
36
|
+
companionId: roleOrContext.companionId || companionId,
|
|
37
|
+
actor: {
|
|
38
|
+
...defaultActor,
|
|
39
|
+
...(roleOrContext.actor || {}),
|
|
40
|
+
},
|
|
41
|
+
conversation: {
|
|
42
|
+
...defaultConversation,
|
|
43
|
+
...(roleOrContext.conversation || {}),
|
|
44
|
+
},
|
|
45
|
+
source: roleOrContext.source || 'local',
|
|
46
|
+
...(roleOrContext.mode ? { mode: roleOrContext.mode } : {}),
|
|
47
|
+
...(roleOrContext.subject ? { subject: roleOrContext.subject } : {}),
|
|
48
|
+
...(roleOrContext.metadata ? { metadata: roleOrContext.metadata } : {}),
|
|
49
|
+
}
|
|
50
|
+
: {
|
|
51
|
+
companionId,
|
|
52
|
+
actor: defaultActor,
|
|
53
|
+
conversation: defaultConversation,
|
|
54
|
+
source: 'local',
|
|
55
|
+
};
|
|
56
|
+
// Universal Perception: Route user input through EarOrgan if available
|
|
57
|
+
let perceivedText = message;
|
|
58
|
+
if (ear && typeof ear.listen === 'function') {
|
|
59
|
+
const perception = await ear.listen('text_chat', message, {
|
|
60
|
+
context: requestContext,
|
|
61
|
+
});
|
|
62
|
+
perceivedText = perception.text || message;
|
|
63
|
+
}
|
|
64
|
+
const boundedHistory = history.map((item) => ({
|
|
65
|
+
role: item.role,
|
|
66
|
+
content: item.content.slice(0, 2000).replace(/\0/g, ''),
|
|
67
|
+
}));
|
|
68
|
+
return {
|
|
69
|
+
perceivedText,
|
|
70
|
+
sanitizedText: message,
|
|
71
|
+
requestContext,
|
|
72
|
+
role,
|
|
73
|
+
isContextObject,
|
|
74
|
+
boundedHistory,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const input_normalizer_1 = require("./input-normalizer");
|
|
4
|
+
describe('InputNormalizer', () => {
|
|
5
|
+
test('rejects empty or oversized messages', async () => {
|
|
6
|
+
await expect((0, input_normalizer_1.normalizeUserInput)('', 'OWNER', [], 'comp-1')).rejects.toThrow('message must be a non-empty string of at most 4000 characters');
|
|
7
|
+
await expect((0, input_normalizer_1.normalizeUserInput)(' ', 'OWNER', [], 'comp-1')).rejects.toThrow('message must be a non-empty string of at most 4000 characters');
|
|
8
|
+
const oversized = 'a'.repeat(4001);
|
|
9
|
+
await expect((0, input_normalizer_1.normalizeUserInput)(oversized, 'OWNER', [], 'comp-1')).rejects.toThrow('message must be a non-empty string of at most 4000 characters');
|
|
10
|
+
});
|
|
11
|
+
test('rejects oversized history or invalid message roles', async () => {
|
|
12
|
+
const invalidHistory = Array(21).fill({ role: 'user', content: 'hi' });
|
|
13
|
+
await expect((0, input_normalizer_1.normalizeUserInput)('hi', 'OWNER', invalidHistory, 'comp-1')).rejects.toThrow('history must contain at most 20 user/assistant messages');
|
|
14
|
+
const malformedRole = [{ role: 'bad_role', content: 'test' }];
|
|
15
|
+
await expect((0, input_normalizer_1.normalizeUserInput)('hi', 'OWNER', malformedRole, 'comp-1')).rejects.toThrow('history must contain at most 20 user/assistant messages');
|
|
16
|
+
});
|
|
17
|
+
test('normalizes role string into full RequestContext and strips null bytes from history', async () => {
|
|
18
|
+
const historyWithNulls = [{ role: 'user', content: 'hello\0world' }];
|
|
19
|
+
const result = await (0, input_normalizer_1.normalizeUserInput)('hello', 'OWNER', historyWithNulls, 'comp-1');
|
|
20
|
+
expect(result.role).toBe('OWNER');
|
|
21
|
+
expect(result.requestContext.companionId).toBe('comp-1');
|
|
22
|
+
expect(result.requestContext.actor.authorizationRole).toBe('administrator');
|
|
23
|
+
expect(result.requestContext.actor.authenticated).toBe(true);
|
|
24
|
+
expect(result.boundedHistory[0].content).toBe('helloworld');
|
|
25
|
+
});
|
|
26
|
+
test('routes input through EarOrgan when present', async () => {
|
|
27
|
+
const mockEar = {
|
|
28
|
+
listen: jest.fn().mockResolvedValue({
|
|
29
|
+
id: 'perc-1',
|
|
30
|
+
source: 'text_chat',
|
|
31
|
+
text: 'transcribed text',
|
|
32
|
+
timestamp: new Date().toISOString(),
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
const result = await (0, input_normalizer_1.normalizeUserInput)('raw text', 'VIEWER', [], 'comp-1', mockEar);
|
|
36
|
+
expect(mockEar.listen).toHaveBeenCalledWith('text_chat', 'raw text', expect.anything());
|
|
37
|
+
expect(result.perceivedText).toBe('transcribed text');
|
|
38
|
+
});
|
|
39
|
+
test('safely normalizes partial context object (e.g. { mode: "hybrid" }) with default actor and conversation', async () => {
|
|
40
|
+
const result = await (0, input_normalizer_1.normalizeUserInput)('test query', { mode: 'hybrid' }, [], 'comp-2');
|
|
41
|
+
expect(result.requestContext.conversation).toBeDefined();
|
|
42
|
+
expect(result.requestContext.conversation.channel).toBe('direct');
|
|
43
|
+
expect(result.requestContext.conversation.correlationId).toBeDefined();
|
|
44
|
+
expect(result.requestContext.actor).toBeDefined();
|
|
45
|
+
expect(result.requestContext.actor.actorId).toBe('owner-user');
|
|
46
|
+
expect(result.requestContext.mode).toBe('hybrid');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { RequestContext, InteractionMode } from './index';
|
|
2
|
+
import { extractDeterministicTeaching } from './teaching';
|
|
3
|
+
export interface IntentClassification {
|
|
4
|
+
normalizedMessage: string;
|
|
5
|
+
explicitTeaching: ReturnType<typeof extractDeterministicTeaching>;
|
|
6
|
+
isTeachingLike: boolean;
|
|
7
|
+
isSelfIdentityRequest: boolean;
|
|
8
|
+
isGreeting: boolean;
|
|
9
|
+
shouldQueryKnowledge: boolean;
|
|
10
|
+
knowledgeQueries?: string[];
|
|
11
|
+
primaryQuery?: string;
|
|
12
|
+
memoryQueries?: string[];
|
|
13
|
+
effectiveMode: InteractionMode;
|
|
14
|
+
confidence?: number;
|
|
15
|
+
classifierOrigin?: 'heuristic' | 'cognitive' | 'ear' | 'brain';
|
|
16
|
+
}
|
|
17
|
+
export type CognitiveIntentClassifier = (text: string, context: RequestContext) => Promise<Partial<IntentClassification>> | Partial<IntentClassification>;
|
|
18
|
+
/**
|
|
19
|
+
* Strips conversational syntax, companion invocations, and question carrier phrases
|
|
20
|
+
* to extract targeted keyword search terms (e.g., "Siduri, who is Sandrone" -> ["Sandrone"]).
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractSearchKeywords(text: string, companionName?: string, recentHistory?: {
|
|
23
|
+
role: string;
|
|
24
|
+
content: string;
|
|
25
|
+
}[]): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Evaluates domain heuristics and intent classification for user messages.
|
|
28
|
+
* Determines if deterministic teaching is present, resolves the effective
|
|
29
|
+
* interaction mode (casual, teach, hybrid), and determines if external knowledge
|
|
30
|
+
* retrieval is appropriate.
|
|
31
|
+
*/
|
|
32
|
+
export declare function classifyInputIntent(text: string, context: RequestContext, overrides?: Partial<IntentClassification>): IntentClassification;
|
|
33
|
+
/**
|
|
34
|
+
* Asynchronously classifies intent, allowing an EarOrgan or cognitive model
|
|
35
|
+
* to provide semantic classification before falling back to heuristics.
|
|
36
|
+
*/
|
|
37
|
+
export declare function classifyInputIntentAsync(text: string, context: RequestContext, classifier?: CognitiveIntentClassifier): Promise<IntentClassification>;
|