@molroo-io/sdk 0.7.3 → 0.8.3
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/cjs/expression/index.d.ts +103 -0
- package/dist/cjs/expression/index.d.ts.map +1 -0
- package/dist/cjs/expression/index.js +18 -0
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/llm/schema.d.ts +114 -0
- package/dist/cjs/llm/schema.d.ts.map +1 -1
- package/dist/cjs/llm/schema.js +44 -1
- package/dist/cjs/persona/chat-orchestrator.d.ts +2 -2
- package/dist/cjs/persona/chat-orchestrator.d.ts.map +1 -1
- package/dist/cjs/persona/chat-orchestrator.js +128 -48
- package/dist/cjs/persona.d.ts +26 -5
- package/dist/cjs/persona.d.ts.map +1 -1
- package/dist/cjs/persona.js +34 -14
- package/dist/cjs/types.d.ts +18 -5
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/world/world.d.ts +3 -1
- package/dist/cjs/world/world.d.ts.map +1 -1
- package/dist/esm/expression/index.d.ts +103 -0
- package/dist/esm/expression/index.d.ts.map +1 -0
- package/dist/esm/expression/index.js +17 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/llm/schema.d.ts +114 -0
- package/dist/esm/llm/schema.d.ts.map +1 -1
- package/dist/esm/llm/schema.js +43 -0
- package/dist/esm/persona/chat-orchestrator.d.ts +2 -2
- package/dist/esm/persona/chat-orchestrator.d.ts.map +1 -1
- package/dist/esm/persona/chat-orchestrator.js +128 -48
- package/dist/esm/persona.d.ts +26 -5
- package/dist/esm/persona.d.ts.map +1 -1
- package/dist/esm/persona.js +34 -14
- package/dist/esm/types.d.ts +18 -5
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/world/world.d.ts +3 -1
- package/dist/esm/world/world.d.ts.map +1 -1
- package/package.json +11 -2
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @molroo-io/sdk/expression — StyleProfile type definitions
|
|
3
|
+
*
|
|
4
|
+
* Style extraction is now handled server-side via the API.
|
|
5
|
+
* Use `persona.extractStyleProfile(corpus)` to extract and save a StyleProfile.
|
|
6
|
+
*
|
|
7
|
+
* Types inlined from @molroo-io/expression (private package).
|
|
8
|
+
* These must stay in sync with lib/expression/src/types/index.ts.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import type { StyleProfile } from '@molroo-io/sdk/expression';
|
|
13
|
+
*
|
|
14
|
+
* const profile = await persona.extractStyleProfile(chatCorpus);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export interface ExtractionOptions {
|
|
18
|
+
/** Timestamps for turn grouping (same length as messages) */
|
|
19
|
+
timestamps?: number[];
|
|
20
|
+
/** Messages from other participants (for TF-IDF signature detection) */
|
|
21
|
+
otherMessages?: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface LexicalFeatures {
|
|
24
|
+
/** Type-Token Ratio: unique_words / total_words */
|
|
25
|
+
vocabRichness: number;
|
|
26
|
+
/** Yule's K characteristic: 10^4 * (M2 - M1) / M1^2 */
|
|
27
|
+
yuleK: number;
|
|
28
|
+
/** Words appearing only once / total words */
|
|
29
|
+
hapaxRatio: number;
|
|
30
|
+
/** Average word length in characters */
|
|
31
|
+
avgWordLength: number;
|
|
32
|
+
/** Function word (particles, conjunctions) frequency distribution */
|
|
33
|
+
functionWordDist: Record<string, number>;
|
|
34
|
+
}
|
|
35
|
+
export interface StructuralFeatures {
|
|
36
|
+
/** Average message length in characters */
|
|
37
|
+
avgMessageLength: number;
|
|
38
|
+
/** Standard deviation of message length */
|
|
39
|
+
messageLengthStd: number;
|
|
40
|
+
/** Ratio of turns with multiple messages */
|
|
41
|
+
multiMessageRatio: number;
|
|
42
|
+
/** Average number of messages per turn */
|
|
43
|
+
avgMessagesPerTurn: number;
|
|
44
|
+
/** Ratio of messages ending with ? */
|
|
45
|
+
questionRatio: number;
|
|
46
|
+
}
|
|
47
|
+
export interface PunctuationFeatures {
|
|
48
|
+
/** Period usage style */
|
|
49
|
+
periodStyle: 'none' | 'single' | 'double' | 'triple';
|
|
50
|
+
/** Emoji count per message (mean) */
|
|
51
|
+
emojiFrequency: number;
|
|
52
|
+
/** Top N most-used emoji */
|
|
53
|
+
emojiSet: string[];
|
|
54
|
+
/** Laugh expression patterns (e.g. ㅋㅋ, ㅎㅎ, ㅋㅋㅋㅋ) */
|
|
55
|
+
laughStyle: string[];
|
|
56
|
+
/** Laugh expressions per message (mean) */
|
|
57
|
+
laughFrequency: number;
|
|
58
|
+
/** Exclamation mark usage rate */
|
|
59
|
+
exclamationRate: number;
|
|
60
|
+
/** Ellipsis (...) usage rate */
|
|
61
|
+
ellipsisRate: number;
|
|
62
|
+
}
|
|
63
|
+
export interface RegisterFeatures {
|
|
64
|
+
/** 0 (casual/banmal) ~ 1 (formal/jondaenmal) */
|
|
65
|
+
formalityScore: number;
|
|
66
|
+
/** Honorific patterns used */
|
|
67
|
+
honorificPatterns: string[];
|
|
68
|
+
/** How the person addresses the interlocutor */
|
|
69
|
+
addressTerms: string[];
|
|
70
|
+
}
|
|
71
|
+
export interface IdiosyncraticFeatures {
|
|
72
|
+
/** Filler words (아, 음, 근데, etc.) */
|
|
73
|
+
fillerWords: string[];
|
|
74
|
+
/** Contraction patterns (ㄱㅊ, ㅇㅇ, ㄴㄴ, etc.) */
|
|
75
|
+
contractions: string[];
|
|
76
|
+
/** Statistically significant personal expressions */
|
|
77
|
+
signaturePatterns: string[];
|
|
78
|
+
/** Sentence ending pattern distribution */
|
|
79
|
+
sentenceEnders: Record<string, number>;
|
|
80
|
+
}
|
|
81
|
+
export interface ResponsePatterns {
|
|
82
|
+
/** Ratio of conversation initiations */
|
|
83
|
+
initiationRatio: number;
|
|
84
|
+
/** Topic change style description */
|
|
85
|
+
topicChangeStyle: string;
|
|
86
|
+
}
|
|
87
|
+
export interface StatisticalSignature {
|
|
88
|
+
/** Character n-gram frequency distribution (n=2,3) */
|
|
89
|
+
charNgramDist: Record<string, number>;
|
|
90
|
+
/** Word n-gram frequency distribution (n=2) */
|
|
91
|
+
wordNgramDist: Record<string, number>;
|
|
92
|
+
}
|
|
93
|
+
/** Complete individual expression fingerprint */
|
|
94
|
+
export interface StyleProfile {
|
|
95
|
+
lexical: LexicalFeatures;
|
|
96
|
+
structural: StructuralFeatures;
|
|
97
|
+
punctuation: PunctuationFeatures;
|
|
98
|
+
register: RegisterFeatures;
|
|
99
|
+
idiosyncratic: IdiosyncraticFeatures;
|
|
100
|
+
response: ResponsePatterns;
|
|
101
|
+
signature: StatisticalSignature;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/expression/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,WAAW,iBAAiB;IAChC,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,wEAAwE;IACxE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAID,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD,aAAa,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,kBAAkB;IACjC,2CAA2C;IAC3C,gBAAgB,EAAE,MAAM,CAAC;IACzB,2CAA2C;IAC3C,gBAAgB,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,0CAA0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;CACvC;AAED,iDAAiD;AACjD,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,eAAe,CAAC;IACzB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,WAAW,EAAE,mBAAmB,CAAC;IACjC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,aAAa,EAAE,qBAAqB,CAAC;IACrC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,SAAS,EAAE,oBAAoB,CAAC;CACjC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @molroo-io/sdk/expression — StyleProfile type definitions
|
|
4
|
+
*
|
|
5
|
+
* Style extraction is now handled server-side via the API.
|
|
6
|
+
* Use `persona.extractStyleProfile(corpus)` to extract and save a StyleProfile.
|
|
7
|
+
*
|
|
8
|
+
* Types inlined from @molroo-io/expression (private package).
|
|
9
|
+
* These must stay in sync with lib/expression/src/types/index.ts.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import type { StyleProfile } from '@molroo-io/sdk/expression';
|
|
14
|
+
*
|
|
15
|
+
* const profile = await persona.extractStyleProfile(chatCorpus);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export type { LLMAdapter, Message, GenerateTextOptions, GenerateObjectOptions, }
|
|
|
37
37
|
export type { LLMInput } from './llm/resolve';
|
|
38
38
|
export type { MemoryAdapter, RecallQuery, SemanticRecallOptions, RecallLimits, Reflection, } from './memory/types';
|
|
39
39
|
export type { PersonaSummary, PersonaState, PersonaChatResult, } from './persona';
|
|
40
|
-
export type { InterlocutorContext, PerceiveOptions, PerceiveEvent, PerceiveContext, } from './types';
|
|
40
|
+
export type { AppraisalMode, EventAppraisal, InterlocutorContext, PerceiveOptions, PerceiveEvent, PerceiveContext, } from './types';
|
|
41
41
|
export type { AgentResponse, VAD, Velocity, AppraisalVector, State, SoulStage, CatastropheState, MetacogState, AffectDynamicsState, InterpersonalState, RegulationState, RegulationStrategy, RegulationPhase, ActiveRegulation, RegulationRecord, EffectivenessRecord, NeedState, Episode, SocialUpdate, ReflectionPrompt, } from './types';
|
|
42
42
|
export type { PersonaSnapshot, PersonaConfigData, PersonalityTraits, Identity, Goal, MotivationContext, } from './types';
|
|
43
43
|
export type { ApiResponse, ApiErrorResponse, PersonaDynamicState, } from './types';
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhE,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC3F,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD,YAAY,EACV,UAAU,EACV,OAAO,EACP,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,YAAY,EACV,aAAa,EACb,WAAW,EACX,qBAAqB,EACrB,YAAY,EACZ,UAAU,GACX,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,cAAc,EACd,YAAY,EACZ,iBAAiB,GAClB,MAAM,WAAW,CAAC;AAGnB,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,eAAe,GAChB,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,aAAa,EACb,GAAG,EACH,QAAQ,EACR,eA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AAW,EACX,qBAAqB,EACrB,YAAY,EACZ,UAAU,GACX,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,cAAc,EACd,YAAY,EACZ,iBAAiB,GAClB,MAAM,WAAW,CAAC;AAGnB,YAAY,EACV,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,eAAe,GAChB,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,aAAa,EACb,GAAG,EACH,QAAQ,EACR,eAAe,EACf,KAAK,EACL,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,SAAS,EACT,OAAO,EACP,YAAY,EACZ,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,QAAQ,EACR,IAAI,EACJ,iBAAiB,GAClB,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,SAAS,EACT,WAAW,GACZ,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAG9C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/cjs/llm/schema.d.ts
CHANGED
|
@@ -18,6 +18,43 @@ export declare const AppraisalVectorSchema: z.ZodObject<{
|
|
|
18
18
|
adjustment_potential: z.ZodPipe<z.ZodNumber, z.ZodTransform<number, number>>;
|
|
19
19
|
urgency: z.ZodPipe<z.ZodNumber, z.ZodTransform<number, number>>;
|
|
20
20
|
}, z.core.$strip>;
|
|
21
|
+
export declare const EventAppraisalSchema: z.ZodObject<{
|
|
22
|
+
interaction_type: z.ZodEnum<{
|
|
23
|
+
chat: "chat";
|
|
24
|
+
inform: "inform";
|
|
25
|
+
humor: "humor";
|
|
26
|
+
express: "express";
|
|
27
|
+
goodbye: "goodbye";
|
|
28
|
+
}>;
|
|
29
|
+
event_type: z.ZodOptional<z.ZodEnum<{
|
|
30
|
+
praise: "praise";
|
|
31
|
+
criticism: "criticism";
|
|
32
|
+
support: "support";
|
|
33
|
+
rejection: "rejection";
|
|
34
|
+
apology: "apology";
|
|
35
|
+
request: "request";
|
|
36
|
+
betrayal: "betrayal";
|
|
37
|
+
neglect: "neglect";
|
|
38
|
+
}>>;
|
|
39
|
+
agent_role: z.ZodEnum<{
|
|
40
|
+
user: "user";
|
|
41
|
+
self: "self";
|
|
42
|
+
other: "other";
|
|
43
|
+
}>;
|
|
44
|
+
target_role: z.ZodEnum<{
|
|
45
|
+
user: "user";
|
|
46
|
+
self: "self";
|
|
47
|
+
other: "other";
|
|
48
|
+
}>;
|
|
49
|
+
relationship: z.ZodEnum<{
|
|
50
|
+
friend: "friend";
|
|
51
|
+
romantic: "romantic";
|
|
52
|
+
authority: "authority";
|
|
53
|
+
stranger: "stranger";
|
|
54
|
+
}>;
|
|
55
|
+
intensity: z.ZodPipe<z.ZodNumber, z.ZodTransform<number, number>>;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
export type EventAppraisalOutput = z.infer<typeof EventAppraisalSchema>;
|
|
21
58
|
/**
|
|
22
59
|
* Full LLM response schema — response text + appraisal vector.
|
|
23
60
|
*/
|
|
@@ -36,6 +73,44 @@ export declare const LLMResponseSchema: z.ZodObject<{
|
|
|
36
73
|
}, z.core.$strip>;
|
|
37
74
|
}, z.core.$strip>;
|
|
38
75
|
export type LLMResponseOutput = z.infer<typeof LLMResponseSchema>;
|
|
76
|
+
export declare const LLMEventResponseSchema: z.ZodObject<{
|
|
77
|
+
response: z.ZodString;
|
|
78
|
+
interaction_type: z.ZodEnum<{
|
|
79
|
+
chat: "chat";
|
|
80
|
+
inform: "inform";
|
|
81
|
+
humor: "humor";
|
|
82
|
+
express: "express";
|
|
83
|
+
goodbye: "goodbye";
|
|
84
|
+
}>;
|
|
85
|
+
event_type: z.ZodOptional<z.ZodEnum<{
|
|
86
|
+
praise: "praise";
|
|
87
|
+
criticism: "criticism";
|
|
88
|
+
support: "support";
|
|
89
|
+
rejection: "rejection";
|
|
90
|
+
apology: "apology";
|
|
91
|
+
request: "request";
|
|
92
|
+
betrayal: "betrayal";
|
|
93
|
+
neglect: "neglect";
|
|
94
|
+
}>>;
|
|
95
|
+
agent_role: z.ZodEnum<{
|
|
96
|
+
user: "user";
|
|
97
|
+
self: "self";
|
|
98
|
+
other: "other";
|
|
99
|
+
}>;
|
|
100
|
+
target_role: z.ZodEnum<{
|
|
101
|
+
user: "user";
|
|
102
|
+
self: "self";
|
|
103
|
+
other: "other";
|
|
104
|
+
}>;
|
|
105
|
+
relationship: z.ZodEnum<{
|
|
106
|
+
friend: "friend";
|
|
107
|
+
romantic: "romantic";
|
|
108
|
+
authority: "authority";
|
|
109
|
+
stranger: "stranger";
|
|
110
|
+
}>;
|
|
111
|
+
intensity: z.ZodPipe<z.ZodNumber, z.ZodTransform<number, number>>;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
export type LLMEventResponseOutput = z.infer<typeof LLMEventResponseSchema>;
|
|
39
114
|
/**
|
|
40
115
|
* Tool-use aware LLM response schema.
|
|
41
116
|
* The LLM can either produce a normal response or request a memory search.
|
|
@@ -57,4 +132,43 @@ export declare const LLMResponseWithToolsSchema: z.ZodObject<{
|
|
|
57
132
|
search_memory: z.ZodOptional<z.ZodString>;
|
|
58
133
|
}, z.core.$strip>;
|
|
59
134
|
export type LLMResponseWithToolsOutput = z.infer<typeof LLMResponseWithToolsSchema>;
|
|
135
|
+
export declare const LLMEventResponseWithToolsSchema: z.ZodObject<{
|
|
136
|
+
response: z.ZodString;
|
|
137
|
+
interaction_type: z.ZodEnum<{
|
|
138
|
+
chat: "chat";
|
|
139
|
+
inform: "inform";
|
|
140
|
+
humor: "humor";
|
|
141
|
+
express: "express";
|
|
142
|
+
goodbye: "goodbye";
|
|
143
|
+
}>;
|
|
144
|
+
event_type: z.ZodOptional<z.ZodEnum<{
|
|
145
|
+
praise: "praise";
|
|
146
|
+
criticism: "criticism";
|
|
147
|
+
support: "support";
|
|
148
|
+
rejection: "rejection";
|
|
149
|
+
apology: "apology";
|
|
150
|
+
request: "request";
|
|
151
|
+
betrayal: "betrayal";
|
|
152
|
+
neglect: "neglect";
|
|
153
|
+
}>>;
|
|
154
|
+
agent_role: z.ZodEnum<{
|
|
155
|
+
user: "user";
|
|
156
|
+
self: "self";
|
|
157
|
+
other: "other";
|
|
158
|
+
}>;
|
|
159
|
+
target_role: z.ZodEnum<{
|
|
160
|
+
user: "user";
|
|
161
|
+
self: "self";
|
|
162
|
+
other: "other";
|
|
163
|
+
}>;
|
|
164
|
+
relationship: z.ZodEnum<{
|
|
165
|
+
friend: "friend";
|
|
166
|
+
romantic: "romantic";
|
|
167
|
+
authority: "authority";
|
|
168
|
+
stranger: "stranger";
|
|
169
|
+
}>;
|
|
170
|
+
intensity: z.ZodPipe<z.ZodNumber, z.ZodTransform<number, number>>;
|
|
171
|
+
search_memory: z.ZodOptional<z.ZodString>;
|
|
172
|
+
}, z.core.$strip>;
|
|
173
|
+
export type LLMEventResponseWithToolsOutput = z.infer<typeof LLMEventResponseWithToolsSchema>;
|
|
60
174
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/llm/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/llm/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAqBxB;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;iBAuDhC,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoB/B,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;iBAK5B,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAQjC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;iBAarC,CAAC;AAEH,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAEpF,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgB1C,CAAC;AAEH,MAAM,MAAM,+BAA+B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC"}
|
package/dist/cjs/llm/schema.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LLMResponseWithToolsSchema = exports.LLMResponseSchema = exports.AppraisalVectorSchema = void 0;
|
|
3
|
+
exports.LLMEventResponseWithToolsSchema = exports.LLMResponseWithToolsSchema = exports.LLMEventResponseSchema = exports.LLMResponseSchema = exports.EventAppraisalSchema = exports.AppraisalVectorSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
// Ontology constants inlined from @molroo-io/core (private package).
|
|
6
|
+
// These must stay in sync with engine/core/src/modules/ontology/types.ts.
|
|
7
|
+
const INTERACTION_TYPES = ['chat', 'inform', 'humor', 'express', 'goodbye'];
|
|
8
|
+
const EVENT_TYPES = [
|
|
9
|
+
'praise', 'criticism', 'support', 'rejection',
|
|
10
|
+
'apology', 'request', 'betrayal', 'neglect',
|
|
11
|
+
];
|
|
12
|
+
const AGENT_ROLES = ['user', 'self', 'other'];
|
|
13
|
+
const TARGET_ROLES = ['user', 'self', 'other'];
|
|
14
|
+
const RELATIONSHIP_TYPES = ['friend', 'romantic', 'authority', 'stranger'];
|
|
5
15
|
/** Clamp a number to [lo, hi]. */
|
|
6
16
|
const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
|
|
7
17
|
/**
|
|
@@ -50,6 +60,17 @@ exports.AppraisalVectorSchema = zod_1.z.object({
|
|
|
50
60
|
.describe('How much time pressure or immediate action is needed? 0: settled/past event/no rush, 0.5: moderate, 1: immediate action required/acute emergency. For past losses: low. For active threats: high. Use 0-1 range.')
|
|
51
61
|
.transform((v) => clamp(v, 0, 1)),
|
|
52
62
|
});
|
|
63
|
+
exports.EventAppraisalSchema = zod_1.z.object({
|
|
64
|
+
interaction_type: zod_1.z.enum(INTERACTION_TYPES).describe('Conversation mode: chat (small talk), inform (sharing info/news), humor (jokes), express (emotional/relational event), goodbye (farewell).'),
|
|
65
|
+
event_type: zod_1.z.enum(EVENT_TYPES).optional().describe('Relationship event type. Required when interaction_type is "express". Omit for chat/inform/humor/goodbye. One of: praise, criticism, support, rejection, apology, request, betrayal, neglect.'),
|
|
66
|
+
agent_role: zod_1.z.enum(AGENT_ROLES).describe('Primary role responsible for the event from the persona perspective: user, self, or other.'),
|
|
67
|
+
target_role: zod_1.z.enum(TARGET_ROLES).describe('Who is affected by or receives the event: self (persona), user (conversation partner), or other (third party).'),
|
|
68
|
+
relationship: zod_1.z.enum(RELATIONSHIP_TYPES).describe('Relationship context for this event: friend, romantic, authority, or stranger.'),
|
|
69
|
+
intensity: zod_1.z
|
|
70
|
+
.number()
|
|
71
|
+
.describe('Impact strength from 0 to 1.5. Use 1.0 for a normal event and >1.0 for unusually strong events.')
|
|
72
|
+
.transform((v) => clamp(v, 0, 1.5)),
|
|
73
|
+
});
|
|
53
74
|
/**
|
|
54
75
|
* Full LLM response schema — response text + appraisal vector.
|
|
55
76
|
*/
|
|
@@ -57,6 +78,15 @@ exports.LLMResponseSchema = zod_1.z.object({
|
|
|
57
78
|
response: zod_1.z.string().describe('Response message from persona to user'),
|
|
58
79
|
appraisal: exports.AppraisalVectorSchema.describe("Scherer 9-dimensional emotion appraisal of user input from persona's perspective"),
|
|
59
80
|
});
|
|
81
|
+
exports.LLMEventResponseSchema = zod_1.z.object({
|
|
82
|
+
response: zod_1.z.string().describe('Response message from persona to user'),
|
|
83
|
+
interaction_type: exports.EventAppraisalSchema.shape.interaction_type,
|
|
84
|
+
event_type: exports.EventAppraisalSchema.shape.event_type,
|
|
85
|
+
agent_role: exports.EventAppraisalSchema.shape.agent_role,
|
|
86
|
+
target_role: exports.EventAppraisalSchema.shape.target_role,
|
|
87
|
+
relationship: exports.EventAppraisalSchema.shape.relationship,
|
|
88
|
+
intensity: exports.EventAppraisalSchema.shape.intensity,
|
|
89
|
+
});
|
|
60
90
|
/**
|
|
61
91
|
* Tool-use aware LLM response schema.
|
|
62
92
|
* The LLM can either produce a normal response or request a memory search.
|
|
@@ -70,3 +100,16 @@ exports.LLMResponseWithToolsSchema = zod_1.z.object({
|
|
|
70
100
|
.optional()
|
|
71
101
|
.describe('If you need to recall a specific memory before responding, set this to your search query. Leave empty/omit when you can respond without searching.'),
|
|
72
102
|
});
|
|
103
|
+
exports.LLMEventResponseWithToolsSchema = zod_1.z.object({
|
|
104
|
+
response: zod_1.z.string().describe('Response message from persona to user. Set to empty string "" if you need to search memory first.'),
|
|
105
|
+
interaction_type: exports.EventAppraisalSchema.shape.interaction_type,
|
|
106
|
+
event_type: exports.EventAppraisalSchema.shape.event_type,
|
|
107
|
+
agent_role: exports.EventAppraisalSchema.shape.agent_role,
|
|
108
|
+
target_role: exports.EventAppraisalSchema.shape.target_role,
|
|
109
|
+
relationship: exports.EventAppraisalSchema.shape.relationship,
|
|
110
|
+
intensity: exports.EventAppraisalSchema.shape.intensity,
|
|
111
|
+
search_memory: zod_1.z
|
|
112
|
+
.string()
|
|
113
|
+
.optional()
|
|
114
|
+
.describe('If you need to recall a specific memory before responding, set this to your search query. Leave empty/omit when you can respond without searching.'),
|
|
115
|
+
});
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* All external dependencies are injected via ChatOrchestratorDeps.
|
|
6
6
|
*/
|
|
7
7
|
import type { LLMAdapter, Message } from '../llm/adapter';
|
|
8
|
-
import type { AgentResponse, InterlocutorContext, PerceiveOptions } from '../types';
|
|
8
|
+
import type { AgentResponse, AppraisalMode, InterlocutorContext, PerceiveOptions } from '../types';
|
|
9
9
|
import type { RecallLimits } from '../memory/types';
|
|
10
10
|
import type { MemoryAdapter } from '../memory/types';
|
|
11
11
|
import type { EventAdapter } from '../events/types';
|
|
@@ -21,9 +21,9 @@ export interface ChatOrchestratorDeps {
|
|
|
21
21
|
memoryAdapter: MemoryAdapter | null;
|
|
22
22
|
memoryRecallConfig: RecallLimits | undefined;
|
|
23
23
|
events: EventAdapter | null;
|
|
24
|
+
appraisalMode: AppraisalMode;
|
|
24
25
|
getPromptContext: (consumerSuffix?: string, sourceEntity?: string) => Promise<PromptContextResult>;
|
|
25
26
|
perceive: (message: string, options?: PerceiveOptions) => Promise<AgentResponse>;
|
|
26
|
-
searchMemory: (query: string) => Promise<Array<Record<string, unknown>>>;
|
|
27
27
|
}
|
|
28
28
|
export interface ChatOptions {
|
|
29
29
|
from?: string | InterlocutorContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-orchestrator.d.ts","sourceRoot":"","sources":["../../../src/persona/chat-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,K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K,OAAO,CAAC,aAAa,CAAC,CAAC;CAClF;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAC;IACpC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;CAC/F;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,aAAa,CAAC;IACxB,2FAA2F;IAC3F,cAAc,EAAE,OAAO,EAAE,CAAC;CAC3B;AAED,wBAAsB,IAAI,CAAC,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAiKlH"}
|
|
@@ -65,6 +65,49 @@ function buildInterlocutorBlock(ctx) {
|
|
|
65
65
|
}
|
|
66
66
|
return parts.join('\n');
|
|
67
67
|
}
|
|
68
|
+
function buildDirectAppraisalInstruction() {
|
|
69
|
+
return [
|
|
70
|
+
'',
|
|
71
|
+
'## Appraisal Task',
|
|
72
|
+
"Evaluate how RECEIVING the user's message affects this persona emotionally.",
|
|
73
|
+
'The event you are appraising is the message itself arriving, not the described situation.',
|
|
74
|
+
"When the user shares their own experience, appraise through the persona's relational goals.",
|
|
75
|
+
"Rate each dimension from the persona's subjective perspective.",
|
|
76
|
+
'An insult should produce negative goal_congruence and norm_compatibility.',
|
|
77
|
+
'A compliment should produce positive values. Neutral small talk should be near zero.',
|
|
78
|
+
].join('\n');
|
|
79
|
+
}
|
|
80
|
+
function buildEventAppraisalInstruction() {
|
|
81
|
+
return [
|
|
82
|
+
'',
|
|
83
|
+
'## Event Classification Task',
|
|
84
|
+
"Classify the user's message into the ontology event format before emotion is computed.",
|
|
85
|
+
'',
|
|
86
|
+
'### Step 1: interaction_type (required)',
|
|
87
|
+
'Determine the conversation mode: chat (small talk), inform (sharing info/news), humor (jokes/playfulness), express (emotional/relational event), goodbye (farewell/parting).',
|
|
88
|
+
'',
|
|
89
|
+
'### Step 2: event_type (only when interaction_type is "express")',
|
|
90
|
+
'If the message contains a relationship event, classify it: praise, criticism, support, rejection, apology, request, betrayal, or neglect.',
|
|
91
|
+
'Omit event_type for chat, inform, humor, or goodbye — these do not carry relationship events.',
|
|
92
|
+
'',
|
|
93
|
+
'### Step 3: agent_role, target_role, relationship, intensity',
|
|
94
|
+
'agent_role: who performed the action. target_role: who is affected by or receives the action.',
|
|
95
|
+
'Example: "you did great" → interaction=express, event=praise, agent=user, target=self.',
|
|
96
|
+
'Example: "nice weather" → interaction=chat, no event_type, agent=user, target=self.',
|
|
97
|
+
'Example: "my friend betrayed me" → interaction=express, event=betrayal, agent=other, target=user.',
|
|
98
|
+
].join('\n');
|
|
99
|
+
}
|
|
100
|
+
/** Convert an EventAppraisal to the ontologyEvent shape for API. */
|
|
101
|
+
function toOntologyEvent(event) {
|
|
102
|
+
return {
|
|
103
|
+
interaction_type: event.interaction_type,
|
|
104
|
+
...(event.event_type ? { event_type: event.event_type } : {}),
|
|
105
|
+
agent_role: event.agent_role,
|
|
106
|
+
target_role: event.target_role,
|
|
107
|
+
relationship: event.relationship,
|
|
108
|
+
intensity: event.intensity,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
68
111
|
async function chat(deps, message, options) {
|
|
69
112
|
const fromOption = options?.from ?? 'user';
|
|
70
113
|
const from = typeof fromOption === 'string' ? fromOption : fromOption.name;
|
|
@@ -98,30 +141,33 @@ async function chat(deps, message, options) {
|
|
|
98
141
|
}
|
|
99
142
|
let responseText;
|
|
100
143
|
let appraisal;
|
|
144
|
+
let ontologyEvent;
|
|
101
145
|
let earlyPerceiveResponse;
|
|
102
146
|
// Split mode: engineLlm handles appraisal, primary llm handles response text
|
|
103
147
|
if (deps.engineLlm && deps.engineLlm !== deps.llm) {
|
|
104
|
-
const { AppraisalVectorSchema } = await Promise.resolve().then(() => __importStar(require('../llm/schema')));
|
|
105
|
-
const appraisalInstruction = [
|
|
106
|
-
'',
|
|
107
|
-
'## Appraisal Task',
|
|
108
|
-
"Evaluate how RECEIVING the user's message affects this persona emotionally.",
|
|
109
|
-
'The event you are appraising is the message itself arriving — not the described situation.',
|
|
110
|
-
"When the user shares their own experience (e.g. loss, success), appraise through the persona's relational goals: caring about the speaker makes their suffering relevant and incongruent.",
|
|
111
|
-
"Rate each dimension from the persona's subjective perspective.",
|
|
112
|
-
'An insult should produce negative goal_congruence and norm_compatibility.',
|
|
113
|
-
'A compliment should produce positive values. Neutral small talk should be near zero.',
|
|
114
|
-
].join('\n');
|
|
115
148
|
const appraisalMessages = messages.length <= 5 ? messages : messages.slice(-5);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
149
|
+
if (deps.appraisalMode === 'event') {
|
|
150
|
+
const { EventAppraisalSchema } = await Promise.resolve().then(() => __importStar(require('../llm/schema')));
|
|
151
|
+
const { object: appraisalResult } = await deps.engineLlm.generateObject({
|
|
152
|
+
system: systemPrompt + buildEventAppraisalInstruction(),
|
|
153
|
+
messages: appraisalMessages,
|
|
154
|
+
schema: EventAppraisalSchema,
|
|
155
|
+
});
|
|
156
|
+
ontologyEvent = toOntologyEvent(appraisalResult);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
const { AppraisalVectorSchema } = await Promise.resolve().then(() => __importStar(require('../llm/schema')));
|
|
160
|
+
const { object: appraisalResult } = await deps.engineLlm.generateObject({
|
|
161
|
+
system: systemPrompt + buildDirectAppraisalInstruction(),
|
|
162
|
+
messages: appraisalMessages,
|
|
163
|
+
schema: AppraisalVectorSchema,
|
|
164
|
+
});
|
|
165
|
+
appraisal = clampAppraisal(appraisalResult);
|
|
166
|
+
}
|
|
122
167
|
earlyPerceiveResponse = await deps.perceive(message, {
|
|
123
168
|
from,
|
|
124
|
-
appraisal,
|
|
169
|
+
...(appraisal ? { appraisal } : {}),
|
|
170
|
+
...(ontologyEvent ? { ontologyEvent } : {}),
|
|
125
171
|
priorEpisodes: recalledEpisodes.length > 0 ? recalledEpisodes : undefined,
|
|
126
172
|
skipMemory: true,
|
|
127
173
|
});
|
|
@@ -148,17 +194,30 @@ async function chat(deps, message, options) {
|
|
|
148
194
|
else if (hasTools) {
|
|
149
195
|
const result = await generateWithToolLoop(deps, systemPrompt, messages, options?.onToolCall);
|
|
150
196
|
responseText = result.text;
|
|
151
|
-
appraisal =
|
|
197
|
+
appraisal = result.appraisal;
|
|
198
|
+
ontologyEvent = result.ontologyEvent;
|
|
152
199
|
}
|
|
153
200
|
else {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
201
|
+
if (deps.appraisalMode === 'event') {
|
|
202
|
+
const { LLMEventResponseSchema } = await Promise.resolve().then(() => __importStar(require('../llm/schema')));
|
|
203
|
+
const { object: llmResult } = await deps.llm.generateObject({
|
|
204
|
+
system: systemPrompt + buildEventAppraisalInstruction(),
|
|
205
|
+
messages,
|
|
206
|
+
schema: LLMEventResponseSchema,
|
|
207
|
+
});
|
|
208
|
+
responseText = llmResult.response;
|
|
209
|
+
ontologyEvent = toOntologyEvent(llmResult);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
const { LLMResponseSchema } = await Promise.resolve().then(() => __importStar(require('../llm/schema')));
|
|
213
|
+
const { object: llmResult } = await deps.llm.generateObject({
|
|
214
|
+
system: systemPrompt,
|
|
215
|
+
messages,
|
|
216
|
+
schema: LLMResponseSchema,
|
|
217
|
+
});
|
|
218
|
+
responseText = llmResult.response;
|
|
219
|
+
appraisal = clampAppraisal(llmResult.appraisal ?? { ...appraisal_1.NEUTRAL_APPRAISAL });
|
|
220
|
+
}
|
|
162
221
|
}
|
|
163
222
|
// 4. Send to API for emotion processing (skip if already done in split mode)
|
|
164
223
|
let response;
|
|
@@ -168,7 +227,8 @@ async function chat(deps, message, options) {
|
|
|
168
227
|
else {
|
|
169
228
|
response = await deps.perceive(responseText, {
|
|
170
229
|
from,
|
|
171
|
-
appraisal:
|
|
230
|
+
...(appraisal ? { appraisal } : {}),
|
|
231
|
+
...(ontologyEvent ? { ontologyEvent } : {}),
|
|
172
232
|
priorEpisodes: recalledEpisodes.length > 0 ? recalledEpisodes : undefined,
|
|
173
233
|
skipMemory: true,
|
|
174
234
|
});
|
|
@@ -194,40 +254,60 @@ async function chat(deps, message, options) {
|
|
|
194
254
|
}
|
|
195
255
|
async function generateWithToolLoop(deps, system, messages, onToolCall) {
|
|
196
256
|
const MAX_TOOL_ITERATIONS = 3;
|
|
197
|
-
const {
|
|
257
|
+
const { LLMEventResponseSchema, LLMEventResponseWithToolsSchema, LLMResponseSchema, LLMResponseWithToolsSchema, } = await Promise.resolve().then(() => __importStar(require('../llm/schema')));
|
|
198
258
|
let currentSystem = system;
|
|
199
259
|
for (let iteration = 0; iteration < MAX_TOOL_ITERATIONS; iteration++) {
|
|
260
|
+
if (deps.appraisalMode === 'event') {
|
|
261
|
+
const { object: llmResult } = await deps.llm.generateObject({
|
|
262
|
+
system: currentSystem + buildEventAppraisalInstruction(),
|
|
263
|
+
messages,
|
|
264
|
+
schema: LLMEventResponseWithToolsSchema,
|
|
265
|
+
});
|
|
266
|
+
if (!llmResult.search_memory) {
|
|
267
|
+
return {
|
|
268
|
+
text: llmResult.response,
|
|
269
|
+
ontologyEvent: toOntologyEvent(llmResult),
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
const query = llmResult.search_memory;
|
|
273
|
+
const episodes = [];
|
|
274
|
+
if (onToolCall) {
|
|
275
|
+
onToolCall({ name: 'search_memory', args: { query }, result: episodes });
|
|
276
|
+
}
|
|
277
|
+
const resultBlock = `\n\n## Memory Search Results (query: "${query}")\nNo matching memories found.`;
|
|
278
|
+
currentSystem = currentSystem + resultBlock;
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
200
281
|
const { object: llmResult } = await deps.llm.generateObject({
|
|
201
282
|
system: currentSystem,
|
|
202
283
|
messages,
|
|
203
284
|
schema: LLMResponseWithToolsSchema,
|
|
204
285
|
});
|
|
205
286
|
if (!llmResult.search_memory) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
287
|
+
return {
|
|
288
|
+
text: llmResult.response,
|
|
289
|
+
appraisal: clampAppraisal(llmResult.appraisal ?? { ...appraisal_1.NEUTRAL_APPRAISAL }),
|
|
290
|
+
};
|
|
209
291
|
}
|
|
210
292
|
const query = llmResult.search_memory;
|
|
211
|
-
|
|
212
|
-
try {
|
|
213
|
-
episodes = await deps.searchMemory(query);
|
|
214
|
-
}
|
|
215
|
-
catch {
|
|
216
|
-
// Memory search failed — continue without results
|
|
217
|
-
}
|
|
293
|
+
const episodes = [];
|
|
218
294
|
if (onToolCall) {
|
|
219
295
|
onToolCall({ name: 'search_memory', args: { query }, result: episodes });
|
|
220
296
|
}
|
|
221
|
-
const resultBlock =
|
|
222
|
-
? `\n\n## Memory Search Results (query: "${query}")\n${episodes.map(ep => {
|
|
223
|
-
const ts = ep.timestamp ? new Date(ep.timestamp).toISOString() : 'unknown';
|
|
224
|
-
const source = ep.sourceEntity ?? 'unknown';
|
|
225
|
-
const context = ep.context ?? 'no context';
|
|
226
|
-
return `- [${ts}] ${source}: ${context}`;
|
|
227
|
-
}).join('\n')}`
|
|
228
|
-
: `\n\n## Memory Search Results (query: "${query}")\nNo matching memories found.`;
|
|
297
|
+
const resultBlock = `\n\n## Memory Search Results (query: "${query}")\nNo matching memories found.`;
|
|
229
298
|
currentSystem = currentSystem + resultBlock;
|
|
230
299
|
}
|
|
300
|
+
if (deps.appraisalMode === 'event') {
|
|
301
|
+
const { object: finalResult } = await deps.llm.generateObject({
|
|
302
|
+
system: currentSystem + buildEventAppraisalInstruction(),
|
|
303
|
+
messages,
|
|
304
|
+
schema: LLMEventResponseSchema,
|
|
305
|
+
});
|
|
306
|
+
return {
|
|
307
|
+
text: finalResult.response,
|
|
308
|
+
ontologyEvent: toOntologyEvent(finalResult),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
231
311
|
const { object: finalResult } = await deps.llm.generateObject({
|
|
232
312
|
system: currentSystem,
|
|
233
313
|
messages,
|
|
@@ -235,6 +315,6 @@ async function generateWithToolLoop(deps, system, messages, onToolCall) {
|
|
|
235
315
|
});
|
|
236
316
|
return {
|
|
237
317
|
text: finalResult.response,
|
|
238
|
-
appraisal: finalResult.appraisal ?? { ...appraisal_1.NEUTRAL_APPRAISAL },
|
|
318
|
+
appraisal: clampAppraisal(finalResult.appraisal ?? { ...appraisal_1.NEUTRAL_APPRAISAL }),
|
|
239
319
|
};
|
|
240
320
|
}
|