soulbridge 0.0.11 → 0.0.12
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.
|
@@ -31,6 +31,14 @@ export interface SoulOptions {
|
|
|
31
31
|
deviceId?: string;
|
|
32
32
|
/** Defaults to the lexicon analyzer; pass an LLM-backed one to opt in (ADR 0015). */
|
|
33
33
|
analyzer?: AffectAnalyzer;
|
|
34
|
+
/**
|
|
35
|
+
* Optional model access, injected the same way as `analyzer`. Adapters supply
|
|
36
|
+
* it from their host's own model (an in-process service, a CLI subprocess, an
|
|
37
|
+
* HTTP endpoint). Omit it and every verb stays rule-only.
|
|
38
|
+
*/
|
|
39
|
+
llm?: LlmFn;
|
|
40
|
+
/** Messages longer than this are not sent to the model. Defaults to 2000. */
|
|
41
|
+
llmMaxChars?: number;
|
|
34
42
|
}
|
|
35
43
|
export declare class Soul {
|
|
36
44
|
readonly store: SoulStore;
|
|
@@ -39,6 +47,8 @@ export declare class Soul {
|
|
|
39
47
|
readonly name: string;
|
|
40
48
|
readonly deviceId: string;
|
|
41
49
|
readonly analyzer: AffectAnalyzer;
|
|
50
|
+
readonly llm?: LlmFn;
|
|
51
|
+
readonly llmMaxChars: number;
|
|
42
52
|
constructor(options: SoulOptions);
|
|
43
53
|
/** Verb 1: session start. */
|
|
44
54
|
context(request?: Partial<ContextRequest>): ContextResult;
|
|
@@ -56,10 +66,7 @@ export declare class Soul {
|
|
|
56
66
|
* The analyzer may be async (a model); any failure degrades to the lexicon
|
|
57
67
|
* analyzer. Emotion is computed from the turn only — never from affect.
|
|
58
68
|
*/
|
|
59
|
-
observe(turn: Turn
|
|
60
|
-
llm?: LlmFn;
|
|
61
|
-
maxLlmChars?: number;
|
|
62
|
-
}): Promise<ObserveResult>;
|
|
69
|
+
observe(turn: Turn): Promise<ObserveResult>;
|
|
63
70
|
/**
|
|
64
71
|
* Explicit form of `observe`: the host decided this is worth keeping.
|
|
65
72
|
* Same write path, no extraction heuristics.
|
|
@@ -71,7 +78,6 @@ export declare class Soul {
|
|
|
71
78
|
}): string;
|
|
72
79
|
/** Verb 4: session end. */
|
|
73
80
|
reflect(turns: Turn[], options?: {
|
|
74
|
-
llm?: LlmFn;
|
|
75
81
|
updateEmotion?: boolean;
|
|
76
82
|
}): Promise<ReflectResult>;
|
|
77
83
|
stats(): {
|
|
@@ -27,6 +27,8 @@ export class Soul {
|
|
|
27
27
|
name;
|
|
28
28
|
deviceId;
|
|
29
29
|
analyzer;
|
|
30
|
+
llm;
|
|
31
|
+
llmMaxChars;
|
|
30
32
|
constructor(options) {
|
|
31
33
|
this.store = options.store;
|
|
32
34
|
this.soulId = options.soulId;
|
|
@@ -34,6 +36,8 @@ export class Soul {
|
|
|
34
36
|
this.name = options.name ?? '小灵';
|
|
35
37
|
this.deviceId = options.deviceId ?? 'dev_local';
|
|
36
38
|
this.analyzer = options.analyzer ?? lexiconAnalyzer;
|
|
39
|
+
this.llm = options.llm;
|
|
40
|
+
this.llmMaxChars = options.llmMaxChars ?? 2000;
|
|
37
41
|
if (!this.store.identity(this.soulId)) {
|
|
38
42
|
this.store.ensureSoul({
|
|
39
43
|
soulId: this.soulId,
|
|
@@ -80,7 +84,7 @@ export class Soul {
|
|
|
80
84
|
* The analyzer may be async (a model); any failure degrades to the lexicon
|
|
81
85
|
* analyzer. Emotion is computed from the turn only — never from affect.
|
|
82
86
|
*/
|
|
83
|
-
async observe(turn
|
|
87
|
+
async observe(turn) {
|
|
84
88
|
const now = turn.at ?? Date.now();
|
|
85
89
|
const affect = turn.role === 'user' ? await this.analyzeTurn(turn.content) : emptyAffect();
|
|
86
90
|
// Rules first: they are precise and cheap. Only when they find nothing does
|
|
@@ -88,11 +92,10 @@ export class Soul {
|
|
|
88
92
|
// a rule that already fired.
|
|
89
93
|
let drafts = ruleExtract([turn]);
|
|
90
94
|
let extractedBy = drafts.length > 0 ? 'rules' : 'none';
|
|
91
|
-
if (drafts.length === 0 && turn.role === 'user' &&
|
|
92
|
-
|
|
93
|
-
if (turn.content.length <= limit) {
|
|
95
|
+
if (drafts.length === 0 && turn.role === 'user' && this.llm) {
|
|
96
|
+
if (turn.content.length <= this.llmMaxChars) {
|
|
94
97
|
try {
|
|
95
|
-
const draft = await llmExtractTurn(turn.content,
|
|
98
|
+
const draft = await llmExtractTurn(turn.content, this.llm);
|
|
96
99
|
if (draft) {
|
|
97
100
|
drafts = [draft];
|
|
98
101
|
extractedBy = 'llm';
|
|
@@ -172,7 +175,7 @@ export class Soul {
|
|
|
172
175
|
soulId: this.soulId,
|
|
173
176
|
userId: this.userId,
|
|
174
177
|
turns,
|
|
175
|
-
llm:
|
|
178
|
+
llm: this.llm,
|
|
176
179
|
updateEmotion: options.updateEmotion,
|
|
177
180
|
});
|
|
178
181
|
}
|