@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
package/dist/cjs/world/world.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.Molroo = void 0;
|
|
|
5
5
|
const client_1 = require("./client");
|
|
6
6
|
const world_domain_1 = require("./world-domain");
|
|
7
7
|
const persona_1 = require("../persona");
|
|
8
|
+
const errors_1 = require("../shared/errors");
|
|
8
9
|
// ---------------------------------------------------------------------------
|
|
9
10
|
// Internal helper
|
|
10
11
|
// ---------------------------------------------------------------------------
|
|
@@ -56,7 +57,7 @@ class Molroo {
|
|
|
56
57
|
if (typeof input === 'string') {
|
|
57
58
|
// Description path - requires llm
|
|
58
59
|
if (!options?.llm) {
|
|
59
|
-
throw new
|
|
60
|
+
throw new errors_1.MolrooApiError('LLM adapter is required when using description string', errors_1.MolrooErrorCode.LLM_REQUIRED, 400);
|
|
60
61
|
}
|
|
61
62
|
return persona_1.MolrooPersona.create({ baseUrl: this._baseUrl, apiKey: this._apiKey, ...options, llm: options.llm }, input);
|
|
62
63
|
}
|
|
@@ -65,6 +66,28 @@ class Molroo {
|
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Connect to an existing persona by ID.
|
|
69
|
+
*
|
|
70
|
+
* LLM adapter is optional. Without it, {@link MolrooPersona.chat | chat()} will throw,
|
|
71
|
+
* but emotion/state APIs ({@link MolrooPersona.hear | hear()},
|
|
72
|
+
* {@link MolrooPersona.getState | getState()},
|
|
73
|
+
* {@link MolrooPersona.getEngineState | getEngineState()},
|
|
74
|
+
* {@link MolrooPersona.perceive | perceive()},
|
|
75
|
+
* {@link MolrooPersona.tick | tick()}) work without LLM.
|
|
76
|
+
*
|
|
77
|
+
* This is the recommended pattern for hybrid apps that build their own prompts
|
|
78
|
+
* and only need SDK for emotion/psychological state computation.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // Hybrid: emotion engine only (no LLM needed)
|
|
83
|
+
* const persona = await molroo.connectPersona('persona_abc123');
|
|
84
|
+
* const state = await persona.getEngineState(elapsed);
|
|
85
|
+
* const emotion = await persona.hear(userMessage, 'Alice');
|
|
86
|
+
*
|
|
87
|
+
* // Full: SDK handles everything (LLM required)
|
|
88
|
+
* const persona = await molroo.connectPersona('persona_abc123', { llm });
|
|
89
|
+
* const result = await persona.chat('Hello!');
|
|
90
|
+
* ```
|
|
68
91
|
*/
|
|
69
92
|
async connectPersona(personaId, options) {
|
|
70
93
|
return persona_1.MolrooPersona.connect({ baseUrl: this._baseUrl, apiKey: this._apiKey, ...options }, personaId);
|
|
@@ -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/esm/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/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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olve.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/esm/llm/resolve.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { VercelAIAdapter } from './vercel-ai';
|
|
2
|
+
import { MolrooApiError, MolrooErrorCode } from '../shared/errors';
|
|
2
3
|
/**
|
|
3
4
|
* Check if input is a Vercel AI SDK provider instance.
|
|
4
5
|
* Provider instances have a `doGenerate` method.
|
|
@@ -25,5 +26,5 @@ export async function resolveLLM(input) {
|
|
|
25
26
|
if (isVercelProvider(input)) {
|
|
26
27
|
return new VercelAIAdapter({ provider: input });
|
|
27
28
|
}
|
|
28
|
-
throw new
|
|
29
|
+
throw new MolrooApiError('Invalid LLM input. Expected LLMAdapter or Vercel AI SDK provider instance.', MolrooErrorCode.API_ERROR, 400);
|
|
29
30
|
}
|
package/dist/esm/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/esm/llm/schema.js
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
// Ontology constants inlined from @molroo-io/core (private package).
|
|
3
|
-
// These must stay in sync with engine/core/src/modules/ontology/types.ts.
|
|
4
|
-
const INTERACTION_TYPES = ['chat', 'inform', 'humor', 'express', 'goodbye'];
|
|
5
|
-
const EVENT_TYPES = [
|
|
6
|
-
'praise', 'criticism', 'support', 'rejection',
|
|
7
|
-
'apology', 'request', 'betrayal', 'neglect',
|
|
8
|
-
];
|
|
9
|
-
const AGENT_ROLES = ['user', 'self', 'other'];
|
|
10
|
-
const TARGET_ROLES = ['user', 'self', 'other'];
|
|
11
|
-
const RELATIONSHIP_TYPES = ['friend', 'romantic', 'authority', 'stranger'];
|
|
12
2
|
/** Clamp a number to [lo, hi]. */
|
|
13
3
|
const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
|
|
14
4
|
/**
|
|
@@ -57,17 +47,6 @@ export const AppraisalVectorSchema = z.object({
|
|
|
57
47
|
.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.')
|
|
58
48
|
.transform((v) => clamp(v, 0, 1)),
|
|
59
49
|
});
|
|
60
|
-
export const EventAppraisalSchema = z.object({
|
|
61
|
-
interaction_type: z.enum(INTERACTION_TYPES).describe('Conversation mode: chat (small talk), inform (sharing info/news), humor (jokes), express (emotional/relational event), goodbye (farewell).'),
|
|
62
|
-
event_type: 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.'),
|
|
63
|
-
agent_role: z.enum(AGENT_ROLES).describe('Primary role responsible for the event from the persona perspective: user, self, or other.'),
|
|
64
|
-
target_role: z.enum(TARGET_ROLES).describe('Who is affected by or receives the event: self (persona), user (conversation partner), or other (third party).'),
|
|
65
|
-
relationship: z.enum(RELATIONSHIP_TYPES).describe('Relationship context for this event: friend, romantic, authority, or stranger.'),
|
|
66
|
-
intensity: z
|
|
67
|
-
.number()
|
|
68
|
-
.describe('Impact strength from 0 to 1.5. Use 1.0 for a normal event and >1.0 for unusually strong events.')
|
|
69
|
-
.transform((v) => clamp(v, 0, 1.5)),
|
|
70
|
-
});
|
|
71
50
|
/**
|
|
72
51
|
* Full LLM response schema — response text + appraisal vector.
|
|
73
52
|
*/
|
|
@@ -75,15 +54,6 @@ export const LLMResponseSchema = z.object({
|
|
|
75
54
|
response: z.string().describe('Response message from persona to user'),
|
|
76
55
|
appraisal: AppraisalVectorSchema.describe("Scherer 9-dimensional emotion appraisal of user input from persona's perspective"),
|
|
77
56
|
});
|
|
78
|
-
export const LLMEventResponseSchema = z.object({
|
|
79
|
-
response: z.string().describe('Response message from persona to user'),
|
|
80
|
-
interaction_type: EventAppraisalSchema.shape.interaction_type,
|
|
81
|
-
event_type: EventAppraisalSchema.shape.event_type,
|
|
82
|
-
agent_role: EventAppraisalSchema.shape.agent_role,
|
|
83
|
-
target_role: EventAppraisalSchema.shape.target_role,
|
|
84
|
-
relationship: EventAppraisalSchema.shape.relationship,
|
|
85
|
-
intensity: EventAppraisalSchema.shape.intensity,
|
|
86
|
-
});
|
|
87
57
|
/**
|
|
88
58
|
* Tool-use aware LLM response schema.
|
|
89
59
|
* The LLM can either produce a normal response or request a memory search.
|
|
@@ -97,16 +67,3 @@ export const LLMResponseWithToolsSchema = z.object({
|
|
|
97
67
|
.optional()
|
|
98
68
|
.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.'),
|
|
99
69
|
});
|
|
100
|
-
export const LLMEventResponseWithToolsSchema = z.object({
|
|
101
|
-
response: z.string().describe('Response message from persona to user. Set to empty string "" if you need to search memory first.'),
|
|
102
|
-
interaction_type: EventAppraisalSchema.shape.interaction_type,
|
|
103
|
-
event_type: EventAppraisalSchema.shape.event_type,
|
|
104
|
-
agent_role: EventAppraisalSchema.shape.agent_role,
|
|
105
|
-
target_role: EventAppraisalSchema.shape.target_role,
|
|
106
|
-
relationship: EventAppraisalSchema.shape.relationship,
|
|
107
|
-
intensity: EventAppraisalSchema.shape.intensity,
|
|
108
|
-
search_memory: z
|
|
109
|
-
.string()
|
|
110
|
-
.optional()
|
|
111
|
-
.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.'),
|
|
112
|
-
});
|
|
@@ -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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,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"}
|
|
@@ -41,43 +41,17 @@ function buildDirectAppraisalInstruction() {
|
|
|
41
41
|
'A compliment should produce positive values. Neutral small talk should be near zero.',
|
|
42
42
|
].join('\n');
|
|
43
43
|
}
|
|
44
|
-
function buildEventAppraisalInstruction() {
|
|
45
|
-
return [
|
|
46
|
-
'',
|
|
47
|
-
'## Event Classification Task',
|
|
48
|
-
"Classify the user's message into the ontology event format before emotion is computed.",
|
|
49
|
-
'',
|
|
50
|
-
'### Step 1: interaction_type (required)',
|
|
51
|
-
'Determine the conversation mode: chat (small talk), inform (sharing info/news), humor (jokes/playfulness), express (emotional/relational event), goodbye (farewell/parting).',
|
|
52
|
-
'',
|
|
53
|
-
'### Step 2: event_type (only when interaction_type is "express")',
|
|
54
|
-
'If the message contains a relationship event, classify it: praise, criticism, support, rejection, apology, request, betrayal, or neglect.',
|
|
55
|
-
'Omit event_type for chat, inform, humor, or goodbye — these do not carry relationship events.',
|
|
56
|
-
'',
|
|
57
|
-
'### Step 3: agent_role, target_role, relationship, intensity',
|
|
58
|
-
'agent_role: who performed the action. target_role: who is affected by or receives the action.',
|
|
59
|
-
'Example: "you did great" → interaction=express, event=praise, agent=user, target=self.',
|
|
60
|
-
'Example: "nice weather" → interaction=chat, no event_type, agent=user, target=self.',
|
|
61
|
-
'Example: "my friend betrayed me" → interaction=express, event=betrayal, agent=other, target=user.',
|
|
62
|
-
].join('\n');
|
|
63
|
-
}
|
|
64
|
-
/** Convert an EventAppraisal to the ontologyEvent shape for API. */
|
|
65
|
-
function toOntologyEvent(event) {
|
|
66
|
-
return {
|
|
67
|
-
interaction_type: event.interaction_type,
|
|
68
|
-
...(event.event_type ? { event_type: event.event_type } : {}),
|
|
69
|
-
agent_role: event.agent_role,
|
|
70
|
-
target_role: event.target_role,
|
|
71
|
-
relationship: event.relationship,
|
|
72
|
-
intensity: event.intensity,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
44
|
export async function chat(deps, message, options) {
|
|
76
45
|
const fromOption = options?.from ?? 'user';
|
|
77
46
|
const from = typeof fromOption === 'string' ? fromOption : fromOption.name;
|
|
78
47
|
const interlocutor = typeof fromOption === 'object' ? fromOption : null;
|
|
79
48
|
// 1. Fetch server-assembled system prompt
|
|
80
|
-
const ctx = await deps.getPromptContext(
|
|
49
|
+
const ctx = await deps.getPromptContext({
|
|
50
|
+
consumerSuffix: options?.consumerSuffix,
|
|
51
|
+
sourceEntity: from,
|
|
52
|
+
consumerRules: options?.consumerRules,
|
|
53
|
+
consumerExamples: options?.consumerExamples,
|
|
54
|
+
});
|
|
81
55
|
let systemPrompt = ctx.systemPrompt;
|
|
82
56
|
const hasTools = (ctx.tools?.length ?? 0) > 0;
|
|
83
57
|
// 2. Build messages (external history + user message)
|
|
@@ -105,39 +79,31 @@ export async function chat(deps, message, options) {
|
|
|
105
79
|
}
|
|
106
80
|
let responseText;
|
|
107
81
|
let appraisal;
|
|
108
|
-
let ontologyEvent;
|
|
109
82
|
let earlyPerceiveResponse;
|
|
110
83
|
// Split mode: engineLlm handles appraisal, primary llm handles response text
|
|
111
84
|
if (deps.engineLlm && deps.engineLlm !== deps.llm) {
|
|
112
85
|
const appraisalMessages = messages.length <= 5 ? messages : messages.slice(-5);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
ontologyEvent = toOntologyEvent(appraisalResult);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
const { AppraisalVectorSchema } = await import('../llm/schema');
|
|
124
|
-
const { object: appraisalResult } = await deps.engineLlm.generateObject({
|
|
125
|
-
system: systemPrompt + buildDirectAppraisalInstruction(),
|
|
126
|
-
messages: appraisalMessages,
|
|
127
|
-
schema: AppraisalVectorSchema,
|
|
128
|
-
});
|
|
129
|
-
appraisal = clampAppraisal(appraisalResult);
|
|
130
|
-
}
|
|
86
|
+
const { AppraisalVectorSchema } = await import('../llm/schema');
|
|
87
|
+
const { object: appraisalResult } = await deps.engineLlm.generateObject({
|
|
88
|
+
system: systemPrompt + buildDirectAppraisalInstruction(),
|
|
89
|
+
messages: appraisalMessages,
|
|
90
|
+
schema: AppraisalVectorSchema,
|
|
91
|
+
});
|
|
92
|
+
appraisal = clampAppraisal(appraisalResult);
|
|
131
93
|
earlyPerceiveResponse = await deps.perceive(message, {
|
|
132
94
|
from,
|
|
133
|
-
|
|
134
|
-
...(ontologyEvent ? { ontologyEvent } : {}),
|
|
95
|
+
appraisal,
|
|
135
96
|
priorEpisodes: recalledEpisodes.length > 0 ? recalledEpisodes : undefined,
|
|
136
97
|
skipMemory: true,
|
|
137
98
|
});
|
|
138
99
|
let updatedPrompt = systemPrompt;
|
|
139
100
|
try {
|
|
140
|
-
const updatedCtx = await deps.getPromptContext(
|
|
101
|
+
const updatedCtx = await deps.getPromptContext({
|
|
102
|
+
consumerSuffix: options?.consumerSuffix,
|
|
103
|
+
sourceEntity: from,
|
|
104
|
+
consumerRules: options?.consumerRules,
|
|
105
|
+
consumerExamples: options?.consumerExamples,
|
|
106
|
+
});
|
|
141
107
|
updatedPrompt = updatedCtx.systemPrompt;
|
|
142
108
|
if (interlocutor) {
|
|
143
109
|
updatedPrompt += '\n\n' + buildInterlocutorBlock(interlocutor);
|
|
@@ -159,29 +125,16 @@ export async function chat(deps, message, options) {
|
|
|
159
125
|
const result = await generateWithToolLoop(deps, systemPrompt, messages, options?.onToolCall);
|
|
160
126
|
responseText = result.text;
|
|
161
127
|
appraisal = result.appraisal;
|
|
162
|
-
ontologyEvent = result.ontologyEvent;
|
|
163
128
|
}
|
|
164
129
|
else {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
ontologyEvent = toOntologyEvent(llmResult);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
const { LLMResponseSchema } = await import('../llm/schema');
|
|
177
|
-
const { object: llmResult } = await deps.llm.generateObject({
|
|
178
|
-
system: systemPrompt,
|
|
179
|
-
messages,
|
|
180
|
-
schema: LLMResponseSchema,
|
|
181
|
-
});
|
|
182
|
-
responseText = llmResult.response;
|
|
183
|
-
appraisal = clampAppraisal(llmResult.appraisal ?? { ...NEUTRAL_APPRAISAL });
|
|
184
|
-
}
|
|
130
|
+
const { LLMResponseSchema } = await import('../llm/schema');
|
|
131
|
+
const { object: llmResult } = await deps.llm.generateObject({
|
|
132
|
+
system: systemPrompt,
|
|
133
|
+
messages,
|
|
134
|
+
schema: LLMResponseSchema,
|
|
135
|
+
});
|
|
136
|
+
responseText = llmResult.response;
|
|
137
|
+
appraisal = clampAppraisal(llmResult.appraisal ?? { ...NEUTRAL_APPRAISAL });
|
|
185
138
|
}
|
|
186
139
|
// 4. Send to API for emotion processing (skip if already done in split mode)
|
|
187
140
|
let response;
|
|
@@ -192,7 +145,6 @@ export async function chat(deps, message, options) {
|
|
|
192
145
|
response = await deps.perceive(responseText, {
|
|
193
146
|
from,
|
|
194
147
|
...(appraisal ? { appraisal } : {}),
|
|
195
|
-
...(ontologyEvent ? { ontologyEvent } : {}),
|
|
196
148
|
priorEpisodes: recalledEpisodes.length > 0 ? recalledEpisodes : undefined,
|
|
197
149
|
skipMemory: true,
|
|
198
150
|
});
|
|
@@ -218,30 +170,9 @@ export async function chat(deps, message, options) {
|
|
|
218
170
|
}
|
|
219
171
|
async function generateWithToolLoop(deps, system, messages, onToolCall) {
|
|
220
172
|
const MAX_TOOL_ITERATIONS = 3;
|
|
221
|
-
const {
|
|
173
|
+
const { LLMResponseSchema, LLMResponseWithToolsSchema, } = await import('../llm/schema');
|
|
222
174
|
let currentSystem = system;
|
|
223
175
|
for (let iteration = 0; iteration < MAX_TOOL_ITERATIONS; iteration++) {
|
|
224
|
-
if (deps.appraisalMode === 'event') {
|
|
225
|
-
const { object: llmResult } = await deps.llm.generateObject({
|
|
226
|
-
system: currentSystem + buildEventAppraisalInstruction(),
|
|
227
|
-
messages,
|
|
228
|
-
schema: LLMEventResponseWithToolsSchema,
|
|
229
|
-
});
|
|
230
|
-
if (!llmResult.search_memory) {
|
|
231
|
-
return {
|
|
232
|
-
text: llmResult.response,
|
|
233
|
-
ontologyEvent: toOntologyEvent(llmResult),
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
const query = llmResult.search_memory;
|
|
237
|
-
const episodes = [];
|
|
238
|
-
if (onToolCall) {
|
|
239
|
-
onToolCall({ name: 'search_memory', args: { query }, result: episodes });
|
|
240
|
-
}
|
|
241
|
-
const resultBlock = `\n\n## Memory Search Results (query: "${query}")\nNo matching memories found.`;
|
|
242
|
-
currentSystem = currentSystem + resultBlock;
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
176
|
const { object: llmResult } = await deps.llm.generateObject({
|
|
246
177
|
system: currentSystem,
|
|
247
178
|
messages,
|
|
@@ -261,17 +192,6 @@ async function generateWithToolLoop(deps, system, messages, onToolCall) {
|
|
|
261
192
|
const resultBlock = `\n\n## Memory Search Results (query: "${query}")\nNo matching memories found.`;
|
|
262
193
|
currentSystem = currentSystem + resultBlock;
|
|
263
194
|
}
|
|
264
|
-
if (deps.appraisalMode === 'event') {
|
|
265
|
-
const { object: finalResult } = await deps.llm.generateObject({
|
|
266
|
-
system: currentSystem + buildEventAppraisalInstruction(),
|
|
267
|
-
messages,
|
|
268
|
-
schema: LLMEventResponseSchema,
|
|
269
|
-
});
|
|
270
|
-
return {
|
|
271
|
-
text: finalResult.response,
|
|
272
|
-
ontologyEvent: toOntologyEvent(finalResult),
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
195
|
const { object: finalResult } = await deps.llm.generateObject({
|
|
276
196
|
system: currentSystem,
|
|
277
197
|
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"}
|
|
@@ -35,6 +35,8 @@ export class Conversation {
|
|
|
35
35
|
const result = await this._persona.chat(message, {
|
|
36
36
|
from: options?.from ?? this._options.from,
|
|
37
37
|
consumerSuffix: options?.consumerSuffix ?? this._options.consumerSuffix,
|
|
38
|
+
consumerRules: options?.consumerRules ?? this._options.consumerRules,
|
|
39
|
+
consumerExamples: options?.consumerExamples ?? this._options.consumerExamples,
|
|
38
40
|
history: this._history,
|
|
39
41
|
onToolCall: options?.onToolCall,
|
|
40
42
|
});
|
|
@@ -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"}
|