@molroo-io/sdk 0.9.0 → 0.9.1
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/events/types.d.ts +1 -1
- package/dist/cjs/events/types.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/llm/resolve.d.ts.map +1 -1
- package/dist/cjs/llm/resolve.js +2 -1
- package/dist/cjs/llm/schema.d.ts +0 -114
- package/dist/cjs/llm/schema.d.ts.map +1 -1
- package/dist/cjs/llm/schema.js +1 -44
- package/dist/cjs/persona/chat-orchestrator.d.ts +18 -3
- package/dist/cjs/persona/chat-orchestrator.d.ts.map +1 -1
- package/dist/cjs/persona/chat-orchestrator.js +29 -109
- package/dist/cjs/persona/conversation.d.ts +22 -1
- package/dist/cjs/persona/conversation.d.ts.map +1 -1
- package/dist/cjs/persona/conversation.js +2 -0
- package/dist/cjs/persona/memory-pipeline.d.ts.map +1 -1
- package/dist/cjs/persona/memory-pipeline.js +30 -4
- package/dist/cjs/persona.d.ts +270 -36
- package/dist/cjs/persona.d.ts.map +1 -1
- package/dist/cjs/persona.js +238 -19
- package/dist/cjs/shared/errors.d.ts +5 -1
- package/dist/cjs/shared/errors.d.ts.map +1 -1
- package/dist/cjs/shared/errors.js +4 -0
- package/dist/cjs/types.d.ts +18 -0
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/world/world-persona.d.ts +20 -5
- package/dist/cjs/world/world-persona.d.ts.map +1 -1
- package/dist/cjs/world/world-persona.js +21 -5
- package/dist/cjs/world/world.d.ts +23 -3
- package/dist/cjs/world/world.d.ts.map +1 -1
- package/dist/cjs/world/world.js +24 -1
- package/dist/esm/events/types.d.ts +1 -1
- package/dist/esm/events/types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/llm/resolve.d.ts.map +1 -1
- package/dist/esm/llm/resolve.js +2 -1
- package/dist/esm/llm/schema.d.ts +0 -114
- package/dist/esm/llm/schema.d.ts.map +1 -1
- package/dist/esm/llm/schema.js +0 -43
- package/dist/esm/persona/chat-orchestrator.d.ts +18 -3
- package/dist/esm/persona/chat-orchestrator.d.ts.map +1 -1
- package/dist/esm/persona/chat-orchestrator.js +29 -109
- package/dist/esm/persona/conversation.d.ts +22 -1
- package/dist/esm/persona/conversation.d.ts.map +1 -1
- package/dist/esm/persona/conversation.js +2 -0
- package/dist/esm/persona/memory-pipeline.d.ts.map +1 -1
- package/dist/esm/persona/memory-pipeline.js +30 -4
- package/dist/esm/persona.d.ts +270 -36
- package/dist/esm/persona.d.ts.map +1 -1
- package/dist/esm/persona.js +237 -19
- package/dist/esm/shared/errors.d.ts +5 -1
- package/dist/esm/shared/errors.d.ts.map +1 -1
- package/dist/esm/shared/errors.js +4 -0
- package/dist/esm/types.d.ts +18 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/world/world-persona.d.ts +20 -5
- package/dist/esm/world/world-persona.d.ts.map +1 -1
- package/dist/esm/world/world-persona.js +21 -5
- package/dist/esm/world/world.d.ts +23 -3
- package/dist/esm/world/world.d.ts.map +1 -1
- package/dist/esm/world/world.js +24 -1
- package/package.json +1 -1
|
@@ -15,7 +15,7 @@ export interface SDKEvent {
|
|
|
15
15
|
payload?: Record<string, unknown>;
|
|
16
16
|
}
|
|
17
17
|
/** Event type categories. */
|
|
18
|
-
export type SDKEventType = 'emotion_changed' | 'memory_consolidated' | 'reflection_generated' | PersonaEventType;
|
|
18
|
+
export type SDKEventType = 'emotion_changed' | 'memory_consolidated' | 'reflection_generated' | 'pipeline_error' | PersonaEventType;
|
|
19
19
|
/** Persona-specific event types. */
|
|
20
20
|
export type PersonaEventType = 'chat' | 'perceive' | 'emotion_update' | 'state_change' | 'memory_created' | 'reflection_created';
|
|
21
21
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/events/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,2FAA2F;IAC3F,SAAS,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAED,wBAAwB;AACxB,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,6BAA6B;AAC7B,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAAG,qBAAqB,GAAG,sBAAsB,GAAG,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/events/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,2FAA2F;IAC3F,SAAS,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAED,wBAAwB;AACxB,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,6BAA6B;AAC7B,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAAG,qBAAqB,GAAG,sBAAsB,GAAG,gBAAgB,GAAG,gBAAgB,CAAC;AAEpI,oCAAoC;AACpC,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,UAAU,GACV,gBAAgB,GAChB,cAAc,GACd,gBAAgB,GAChB,oBAAoB,CAAC"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export type { MemoryAdapter, RecallQuery, SemanticRecallOptions, RecallLimits, R
|
|
|
39
39
|
export type { PersonaSummary, PersonaState, PersonaChatResult, } from './persona';
|
|
40
40
|
export { Conversation } from './persona/conversation';
|
|
41
41
|
export type { ConversationOptions } from './persona/conversation';
|
|
42
|
-
export type { AppraisalMode,
|
|
42
|
+
export type { AppraisalMode, InterlocutorContext, RelationshipContext, PerceiveOptions, PerceiveEvent, PerceiveContext, } from './types';
|
|
43
43
|
export type { AgentResponse, VAD, Velocity, AppraisalVector, State, SoulStage, CatastropheState, MetacogState, AffectDynamicsState, InterpersonalState, RegulationState, RegulationStrategy, RegulationPhase, ActiveRegulation, RegulationRecord, EffectivenessRecord, NeedState, Episode, SocialUpdate, ReflectionPrompt, } from './types';
|
|
44
44
|
export type { PersonaSnapshot, PersonaConfigData, PersonalityTraits, Identity, Goal, MotivationContext, } from './types';
|
|
45
45
|
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,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGjF,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,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,YAAY,EACV,aAAa,EACb,
|
|
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,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGjF,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,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../src/llm/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../src/llm/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAGxC,sDAAsD;AACtD,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,aAAa,CAAC;AAelD;;;GAGG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAqBrE"}
|
package/dist/cjs/llm/resolve.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveLLM = resolveLLM;
|
|
4
4
|
const vercel_ai_1 = require("./vercel-ai");
|
|
5
|
+
const errors_1 = require("../shared/errors");
|
|
5
6
|
/**
|
|
6
7
|
* Check if input is a Vercel AI SDK provider instance.
|
|
7
8
|
* Provider instances have a `doGenerate` method.
|
|
@@ -28,5 +29,5 @@ async function resolveLLM(input) {
|
|
|
28
29
|
if (isVercelProvider(input)) {
|
|
29
30
|
return new vercel_ai_1.VercelAIAdapter({ provider: input });
|
|
30
31
|
}
|
|
31
|
-
throw new
|
|
32
|
+
throw new errors_1.MolrooApiError('Invalid LLM input. Expected LLMAdapter or Vercel AI SDK provider instance.', errors_1.MolrooErrorCode.API_ERROR, 400);
|
|
32
33
|
}
|
package/dist/cjs/llm/schema.d.ts
CHANGED
|
@@ -18,43 +18,6 @@ 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>;
|
|
58
21
|
/**
|
|
59
22
|
* Full LLM response schema — response text + appraisal vector.
|
|
60
23
|
*/
|
|
@@ -73,44 +36,6 @@ export declare const LLMResponseSchema: z.ZodObject<{
|
|
|
73
36
|
}, z.core.$strip>;
|
|
74
37
|
}, z.core.$strip>;
|
|
75
38
|
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>;
|
|
114
39
|
/**
|
|
115
40
|
* Tool-use aware LLM response schema.
|
|
116
41
|
* The LLM can either produce a normal response or request a memory search.
|
|
@@ -132,43 +57,4 @@ export declare const LLMResponseWithToolsSchema: z.ZodObject<{
|
|
|
132
57
|
search_memory: z.ZodOptional<z.ZodString>;
|
|
133
58
|
}, z.core.$strip>;
|
|
134
59
|
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>;
|
|
174
60
|
//# 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;AAKxB;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;iBAuDhC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;iBAK5B,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;iBAarC,CAAC;AAEH,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC"}
|
package/dist/cjs/llm/schema.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.LLMResponseWithToolsSchema = exports.LLMResponseSchema = 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'];
|
|
15
5
|
/** Clamp a number to [lo, hi]. */
|
|
16
6
|
const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
|
|
17
7
|
/**
|
|
@@ -60,17 +50,6 @@ exports.AppraisalVectorSchema = zod_1.z.object({
|
|
|
60
50
|
.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.')
|
|
61
51
|
.transform((v) => clamp(v, 0, 1)),
|
|
62
52
|
});
|
|
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
|
-
});
|
|
74
53
|
/**
|
|
75
54
|
* Full LLM response schema — response text + appraisal vector.
|
|
76
55
|
*/
|
|
@@ -78,15 +57,6 @@ exports.LLMResponseSchema = zod_1.z.object({
|
|
|
78
57
|
response: zod_1.z.string().describe('Response message from persona to user'),
|
|
79
58
|
appraisal: exports.AppraisalVectorSchema.describe("Scherer 9-dimensional emotion appraisal of user input from persona's perspective"),
|
|
80
59
|
});
|
|
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
|
-
});
|
|
90
60
|
/**
|
|
91
61
|
* Tool-use aware LLM response schema.
|
|
92
62
|
* The LLM can either produce a normal response or request a memory search.
|
|
@@ -100,16 +70,3 @@ exports.LLMResponseWithToolsSchema = zod_1.z.object({
|
|
|
100
70
|
.optional()
|
|
101
71
|
.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.'),
|
|
102
72
|
});
|
|
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,
|
|
8
|
+
import type { AgentResponse, 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,14 +21,29 @@ export interface ChatOrchestratorDeps {
|
|
|
21
21
|
memoryAdapter: MemoryAdapter | null;
|
|
22
22
|
memoryRecallConfig: RecallLimits | undefined;
|
|
23
23
|
events: EventAdapter | null;
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
getPromptContext: (options?: {
|
|
25
|
+
consumerSuffix?: string;
|
|
26
|
+
sourceEntity?: string;
|
|
27
|
+
consumerRules?: string;
|
|
28
|
+
consumerExamples?: string;
|
|
29
|
+
}) => Promise<PromptContextResult>;
|
|
26
30
|
perceive: (message: string, options?: PerceiveOptions) => Promise<AgentResponse>;
|
|
27
31
|
}
|
|
28
32
|
export interface ChatOptions {
|
|
29
33
|
from?: string | InterlocutorContext;
|
|
30
34
|
history?: Message[];
|
|
35
|
+
/** Free-form app-specific context appended to the system prompt as-is. */
|
|
31
36
|
consumerSuffix?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Behavioral constraints and absolute rules for this conversation.
|
|
39
|
+
* Examples: "Never break character", "Always respond in Korean".
|
|
40
|
+
*/
|
|
41
|
+
consumerRules?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Few-shot example messages that demonstrate the desired style or behavior.
|
|
44
|
+
* Used to guide the LLM's tone and response format.
|
|
45
|
+
*/
|
|
46
|
+
consumerExamples?: string;
|
|
32
47
|
onToolCall?: (call: {
|
|
33
48
|
name: string;
|
|
34
49
|
args: Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-orchestrator.d.ts","sourceRoot":"","sources":["../../../src/persona/chat-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EACV,aAAa,
|
|
1
|
+
{"version":3,"file":"chat-orchestrator.d.ts","sourceRoot":"","sources":["../../../src/persona/chat-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EACV,aAAa,EAGb,mBAAmB,EACnB,eAAe,EAChB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAIpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA4CpD,KAAK,mBAAmB,GAAG;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,UAAU,CAAC;IAChB,SAAS,EAAE,UAAU,GAAG,IAAI,CAAC;IAC7B,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IACpC,kBAAkB,EAAE,YAAY,GAAG,SAAS,CAAC;IAC7C,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,gBAAgB,EAAE,CAAC,OAAO,CAAC,EAAE;QAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACnC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,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,0EAA0E;IAC1E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,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,CAkJlH"}
|
|
@@ -77,43 +77,17 @@ function buildDirectAppraisalInstruction() {
|
|
|
77
77
|
'A compliment should produce positive values. Neutral small talk should be near zero.',
|
|
78
78
|
].join('\n');
|
|
79
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
|
-
}
|
|
111
80
|
async function chat(deps, message, options) {
|
|
112
81
|
const fromOption = options?.from ?? 'user';
|
|
113
82
|
const from = typeof fromOption === 'string' ? fromOption : fromOption.name;
|
|
114
83
|
const interlocutor = typeof fromOption === 'object' ? fromOption : null;
|
|
115
84
|
// 1. Fetch server-assembled system prompt
|
|
116
|
-
const ctx = await deps.getPromptContext(
|
|
85
|
+
const ctx = await deps.getPromptContext({
|
|
86
|
+
consumerSuffix: options?.consumerSuffix,
|
|
87
|
+
sourceEntity: from,
|
|
88
|
+
consumerRules: options?.consumerRules,
|
|
89
|
+
consumerExamples: options?.consumerExamples,
|
|
90
|
+
});
|
|
117
91
|
let systemPrompt = ctx.systemPrompt;
|
|
118
92
|
const hasTools = (ctx.tools?.length ?? 0) > 0;
|
|
119
93
|
// 2. Build messages (external history + user message)
|
|
@@ -141,39 +115,31 @@ async function chat(deps, message, options) {
|
|
|
141
115
|
}
|
|
142
116
|
let responseText;
|
|
143
117
|
let appraisal;
|
|
144
|
-
let ontologyEvent;
|
|
145
118
|
let earlyPerceiveResponse;
|
|
146
119
|
// Split mode: engineLlm handles appraisal, primary llm handles response text
|
|
147
120
|
if (deps.engineLlm && deps.engineLlm !== deps.llm) {
|
|
148
121
|
const appraisalMessages = messages.length <= 5 ? messages : messages.slice(-5);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
+
const { AppraisalVectorSchema } = await Promise.resolve().then(() => __importStar(require('../llm/schema')));
|
|
123
|
+
const { object: appraisalResult } = await deps.engineLlm.generateObject({
|
|
124
|
+
system: systemPrompt + buildDirectAppraisalInstruction(),
|
|
125
|
+
messages: appraisalMessages,
|
|
126
|
+
schema: AppraisalVectorSchema,
|
|
127
|
+
});
|
|
128
|
+
appraisal = clampAppraisal(appraisalResult);
|
|
167
129
|
earlyPerceiveResponse = await deps.perceive(message, {
|
|
168
130
|
from,
|
|
169
|
-
|
|
170
|
-
...(ontologyEvent ? { ontologyEvent } : {}),
|
|
131
|
+
appraisal,
|
|
171
132
|
priorEpisodes: recalledEpisodes.length > 0 ? recalledEpisodes : undefined,
|
|
172
133
|
skipMemory: true,
|
|
173
134
|
});
|
|
174
135
|
let updatedPrompt = systemPrompt;
|
|
175
136
|
try {
|
|
176
|
-
const updatedCtx = await deps.getPromptContext(
|
|
137
|
+
const updatedCtx = await deps.getPromptContext({
|
|
138
|
+
consumerSuffix: options?.consumerSuffix,
|
|
139
|
+
sourceEntity: from,
|
|
140
|
+
consumerRules: options?.consumerRules,
|
|
141
|
+
consumerExamples: options?.consumerExamples,
|
|
142
|
+
});
|
|
177
143
|
updatedPrompt = updatedCtx.systemPrompt;
|
|
178
144
|
if (interlocutor) {
|
|
179
145
|
updatedPrompt += '\n\n' + buildInterlocutorBlock(interlocutor);
|
|
@@ -195,29 +161,16 @@ async function chat(deps, message, options) {
|
|
|
195
161
|
const result = await generateWithToolLoop(deps, systemPrompt, messages, options?.onToolCall);
|
|
196
162
|
responseText = result.text;
|
|
197
163
|
appraisal = result.appraisal;
|
|
198
|
-
ontologyEvent = result.ontologyEvent;
|
|
199
164
|
}
|
|
200
165
|
else {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
}
|
|
166
|
+
const { LLMResponseSchema } = await Promise.resolve().then(() => __importStar(require('../llm/schema')));
|
|
167
|
+
const { object: llmResult } = await deps.llm.generateObject({
|
|
168
|
+
system: systemPrompt,
|
|
169
|
+
messages,
|
|
170
|
+
schema: LLMResponseSchema,
|
|
171
|
+
});
|
|
172
|
+
responseText = llmResult.response;
|
|
173
|
+
appraisal = clampAppraisal(llmResult.appraisal ?? { ...appraisal_1.NEUTRAL_APPRAISAL });
|
|
221
174
|
}
|
|
222
175
|
// 4. Send to API for emotion processing (skip if already done in split mode)
|
|
223
176
|
let response;
|
|
@@ -228,7 +181,6 @@ async function chat(deps, message, options) {
|
|
|
228
181
|
response = await deps.perceive(responseText, {
|
|
229
182
|
from,
|
|
230
183
|
...(appraisal ? { appraisal } : {}),
|
|
231
|
-
...(ontologyEvent ? { ontologyEvent } : {}),
|
|
232
184
|
priorEpisodes: recalledEpisodes.length > 0 ? recalledEpisodes : undefined,
|
|
233
185
|
skipMemory: true,
|
|
234
186
|
});
|
|
@@ -254,30 +206,9 @@ async function chat(deps, message, options) {
|
|
|
254
206
|
}
|
|
255
207
|
async function generateWithToolLoop(deps, system, messages, onToolCall) {
|
|
256
208
|
const MAX_TOOL_ITERATIONS = 3;
|
|
257
|
-
const {
|
|
209
|
+
const { LLMResponseSchema, LLMResponseWithToolsSchema, } = await Promise.resolve().then(() => __importStar(require('../llm/schema')));
|
|
258
210
|
let currentSystem = system;
|
|
259
211
|
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
|
-
}
|
|
281
212
|
const { object: llmResult } = await deps.llm.generateObject({
|
|
282
213
|
system: currentSystem,
|
|
283
214
|
messages,
|
|
@@ -297,17 +228,6 @@ async function generateWithToolLoop(deps, system, messages, onToolCall) {
|
|
|
297
228
|
const resultBlock = `\n\n## Memory Search Results (query: "${query}")\nNo matching memories found.`;
|
|
298
229
|
currentSystem = currentSystem + resultBlock;
|
|
299
230
|
}
|
|
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
|
-
}
|
|
311
231
|
const { object: finalResult } = await deps.llm.generateObject({
|
|
312
232
|
system: currentSystem,
|
|
313
233
|
messages,
|
|
@@ -7,8 +7,18 @@ export interface ConversationOptions {
|
|
|
7
7
|
maxMessages?: number;
|
|
8
8
|
/** Default source entity for all messages in this conversation. */
|
|
9
9
|
from?: string | InterlocutorContext;
|
|
10
|
-
/**
|
|
10
|
+
/** Free-form app-specific context appended to every system prompt in this conversation. */
|
|
11
11
|
consumerSuffix?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Behavioral constraints and absolute rules applied to every message in this conversation.
|
|
14
|
+
* Examples: "Never break character", "Always respond in Korean".
|
|
15
|
+
*/
|
|
16
|
+
consumerRules?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Few-shot example messages for style/behavior reference, applied to every message in this conversation.
|
|
19
|
+
* Helps the LLM match a specific tone or response format.
|
|
20
|
+
*/
|
|
21
|
+
consumerExamples?: string;
|
|
12
22
|
}
|
|
13
23
|
/**
|
|
14
24
|
* Auto-managed conversation session that tracks message history.
|
|
@@ -44,7 +54,18 @@ export declare class Conversation {
|
|
|
44
54
|
*/
|
|
45
55
|
send(message: string, options?: {
|
|
46
56
|
from?: string | InterlocutorContext;
|
|
57
|
+
/** Free-form app-specific context appended to the system prompt for this message only. */
|
|
47
58
|
consumerSuffix?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Behavioral constraints and absolute rules for this message only.
|
|
61
|
+
* Overrides the session-level `consumerRules` when provided.
|
|
62
|
+
*/
|
|
63
|
+
consumerRules?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Few-shot example messages for style/behavior reference for this message only.
|
|
66
|
+
* Overrides the session-level `consumerExamples` when provided.
|
|
67
|
+
*/
|
|
68
|
+
consumerExamples?: string;
|
|
48
69
|
onToolCall?: (call: {
|
|
49
70
|
name: string;
|
|
50
71
|
args: Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../src/persona/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEnE,2DAA2D;AAC3D,MAAM,WAAW,mBAAmB;IAClC,8GAA8G;IAC9G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAC;IACpC,
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../src/persona/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEnE,2DAA2D;AAC3D,MAAM,WAAW,mBAAmB;IAClC,8GAA8G;IAC9G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAC;IACpC,2FAA2F;IAC3F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsB;gBAEnC,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,mBAAmB;IAKjE;;;;;;OAMG;IACG,IAAI,CACR,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAC;QACpC,0FAA0F;QAC1F,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB;;;WAGG;QACH,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB;;;WAGG;QACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAAC,MAAM,EAAE,OAAO,CAAA;SAAE,KAAK,IAAI,CAAC;KAC/F,GACA,OAAO,CAAC,iBAAiB,CAAC;IAkB7B,kDAAkD;IAClD,IAAI,QAAQ,IAAI,SAAS,OAAO,EAAE,CAEjC;IAED,8CAA8C;IAC9C,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,sCAAsC;IACtC,KAAK,IAAI,IAAI;IAIb,iDAAiD;IACjD,OAAO,CAAC,WAAW;CAMpB"}
|
|
@@ -38,6 +38,8 @@ class Conversation {
|
|
|
38
38
|
const result = await this._persona.chat(message, {
|
|
39
39
|
from: options?.from ?? this._options.from,
|
|
40
40
|
consumerSuffix: options?.consumerSuffix ?? this._options.consumerSuffix,
|
|
41
|
+
consumerRules: options?.consumerRules ?? this._options.consumerRules,
|
|
42
|
+
consumerExamples: options?.consumerExamples ?? this._options.consumerExamples,
|
|
41
43
|
history: this._history,
|
|
42
44
|
onToolCall: options?.onToolCall,
|
|
43
45
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-pipeline.d.ts","sourceRoot":"","sources":["../../../src/persona/memory-pipeline.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAc,MAAM,iBAAiB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAyB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"memory-pipeline.d.ts","sourceRoot":"","sources":["../../../src/persona/memory-pipeline.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAc,MAAM,iBAAiB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAyB,MAAM,UAAU,CAAC;AAyBrE,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IACpC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,GAAG,EAAE,UAAU,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,UAAU,GAAG,IAAI,CAAC;CAC9B;AAiDD;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAUpF;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAmBhF"}
|
|
@@ -3,12 +3,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.postPerceive = postPerceive;
|
|
4
4
|
exports.postChat = postChat;
|
|
5
5
|
const event_emitter_1 = require("./event-emitter");
|
|
6
|
+
/** Emit pipeline error or log warning if no EventAdapter. */
|
|
7
|
+
function handlePipelineError(deps, stage, error) {
|
|
8
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9
|
+
if (deps.events) {
|
|
10
|
+
deps.events.emit({
|
|
11
|
+
type: 'pipeline_error',
|
|
12
|
+
personaId: deps.personaId,
|
|
13
|
+
timestamp: Date.now(),
|
|
14
|
+
payload: { stage, error: message },
|
|
15
|
+
}).catch(() => {
|
|
16
|
+
// Last resort: log to console if event emit itself fails
|
|
17
|
+
console.warn(`[molroo-sdk] Pipeline error (${stage}):`, message);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
console.warn(`[molroo-sdk] Pipeline error (${stage}):`, message);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
6
24
|
/** Save episode (shared between perceive and chat pipelines). */
|
|
7
25
|
function saveEpisode(deps, response) {
|
|
8
26
|
if (!response.memoryEpisode)
|
|
9
27
|
return;
|
|
10
28
|
if (deps.memoryAdapter) {
|
|
11
|
-
deps.memoryAdapter.saveEpisode(response.memoryEpisode).catch(() => {
|
|
29
|
+
deps.memoryAdapter.saveEpisode(response.memoryEpisode).catch((err) => {
|
|
30
|
+
handlePipelineError(deps, 'save_episode', err);
|
|
31
|
+
});
|
|
12
32
|
}
|
|
13
33
|
}
|
|
14
34
|
/** Handle reflection generation (LLM call + save). */
|
|
@@ -48,7 +68,9 @@ function postPerceive(deps, response) {
|
|
|
48
68
|
return;
|
|
49
69
|
saveEpisode(deps, response);
|
|
50
70
|
if (deps.events) {
|
|
51
|
-
(0, event_emitter_1.emitResponseEvents)(deps.events, deps.personaId, response, Date.now()).catch(() => {
|
|
71
|
+
(0, event_emitter_1.emitResponseEvents)(deps.events, deps.personaId, response, Date.now()).catch((err) => {
|
|
72
|
+
handlePipelineError(deps, 'event_emit', err);
|
|
73
|
+
});
|
|
52
74
|
}
|
|
53
75
|
}
|
|
54
76
|
/**
|
|
@@ -61,9 +83,13 @@ function postChat(deps, response) {
|
|
|
61
83
|
const hasLlm = deps.engineLlm || deps.llm;
|
|
62
84
|
const hasMemory = deps.memoryAdapter;
|
|
63
85
|
if (hasLlm && hasMemory && response.reflectionPrompt) {
|
|
64
|
-
handleReflection(deps, response.reflectionPrompt, response.emotion.vad).catch(() => {
|
|
86
|
+
handleReflection(deps, response.reflectionPrompt, response.emotion.vad).catch((err) => {
|
|
87
|
+
handlePipelineError(deps, 'reflection', err);
|
|
88
|
+
});
|
|
65
89
|
}
|
|
66
90
|
if (deps.events) {
|
|
67
|
-
(0, event_emitter_1.emitResponseEvents)(deps.events, deps.personaId, response, now).catch(() => {
|
|
91
|
+
(0, event_emitter_1.emitResponseEvents)(deps.events, deps.personaId, response, now).catch((err) => {
|
|
92
|
+
handlePipelineError(deps, 'event_emit', err);
|
|
93
|
+
});
|
|
68
94
|
}
|
|
69
95
|
}
|