@molroo-io/sdk 0.8.4 → 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/errors.d.ts +1 -1
- package/dist/cjs/errors.d.ts.map +1 -1
- package/dist/cjs/errors.js +2 -1
- 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 +4 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -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 +84 -0
- package/dist/cjs/persona/conversation.d.ts.map +1 -0
- package/dist/cjs/persona/conversation.js +72 -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 +441 -22
- package/dist/cjs/persona.d.ts.map +1 -1
- package/dist/cjs/persona.js +418 -6
- package/dist/cjs/shared/errors.d.ts +32 -2
- package/dist/cjs/shared/errors.d.ts.map +1 -1
- package/dist/cjs/shared/errors.js +33 -2
- package/dist/cjs/types.d.ts +70 -5
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/types.js +2 -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 +28 -5
- package/dist/cjs/world/world.d.ts.map +1 -1
- package/dist/cjs/world/world.js +29 -3
- package/dist/esm/errors.d.ts +1 -1
- package/dist/esm/errors.d.ts.map +1 -1
- package/dist/esm/errors.js +1 -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 +4 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -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 +84 -0
- package/dist/esm/persona/conversation.d.ts.map +1 -0
- package/dist/esm/persona/conversation.js +68 -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 +441 -22
- package/dist/esm/persona.d.ts.map +1 -1
- package/dist/esm/persona.js +418 -7
- package/dist/esm/shared/errors.d.ts +32 -2
- package/dist/esm/shared/errors.d.ts.map +1 -1
- package/dist/esm/shared/errors.js +32 -1
- package/dist/esm/types.d.ts +70 -5
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +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 +28 -5
- package/dist/esm/world/world.d.ts.map +1 -1
- package/dist/esm/world/world.js +29 -3
- package/package.json +1 -1
|
@@ -3,10 +3,41 @@
|
|
|
3
3
|
*
|
|
4
4
|
* `instanceof MolrooApiError` catches ALL API errors (persona + world).
|
|
5
5
|
* `instanceof WorldApiError` catches world-only errors.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { MolrooApiError, MolrooErrorCode } from '@molroo-io/sdk';
|
|
10
|
+
*
|
|
11
|
+
* try {
|
|
12
|
+
* await persona.chat('hello');
|
|
13
|
+
* } catch (e) {
|
|
14
|
+
* if (e instanceof MolrooApiError && e.code === MolrooErrorCode.LLM_NOT_CONFIGURED) {
|
|
15
|
+
* console.log('Please provide an LLM adapter');
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
6
19
|
*/
|
|
20
|
+
/** Machine-readable error codes for programmatic error handling. */
|
|
21
|
+
export var MolrooErrorCode;
|
|
22
|
+
(function (MolrooErrorCode) {
|
|
23
|
+
/** LLM adapter is required for this operation (e.g., description-based create). */
|
|
24
|
+
MolrooErrorCode["LLM_REQUIRED"] = "LLM_REQUIRED";
|
|
25
|
+
/** LLM adapter was not configured at initialization (e.g., calling chat() without llm). */
|
|
26
|
+
MolrooErrorCode["LLM_NOT_CONFIGURED"] = "LLM_NOT_CONFIGURED";
|
|
27
|
+
/** Requested entity (persona, world, etc.) was not found. */
|
|
28
|
+
MolrooErrorCode["ENTITY_NOT_FOUND"] = "ENTITY_NOT_FOUND";
|
|
29
|
+
/** Authentication failed — invalid or missing API key. */
|
|
30
|
+
MolrooErrorCode["UNAUTHORIZED"] = "UNAUTHORIZED";
|
|
31
|
+
/** API returned an unexpected error not covered by other codes. */
|
|
32
|
+
MolrooErrorCode["API_ERROR"] = "API_ERROR";
|
|
33
|
+
/** Feature is not yet implemented. */
|
|
34
|
+
MolrooErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
|
|
35
|
+
/** Memory pipeline operation failed (fire-and-forget, non-blocking). */
|
|
36
|
+
MolrooErrorCode["PIPELINE_ERROR"] = "PIPELINE_ERROR";
|
|
37
|
+
})(MolrooErrorCode || (MolrooErrorCode = {}));
|
|
7
38
|
export class MolrooApiError extends Error {
|
|
8
39
|
constructor(message,
|
|
9
|
-
/** Machine-readable error code
|
|
40
|
+
/** Machine-readable error code. Use {@link MolrooErrorCode} for type-safe matching. */
|
|
10
41
|
code,
|
|
11
42
|
/** HTTP status code. */
|
|
12
43
|
status) {
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -21,6 +21,19 @@ export interface InterlocutorContext {
|
|
|
21
21
|
/** Arbitrary key-value extensions rendered as subsections. */
|
|
22
22
|
extensions?: Record<string, string>;
|
|
23
23
|
}
|
|
24
|
+
/** Relationship state between two entities, used for social update computation. */
|
|
25
|
+
export interface RelationshipContext {
|
|
26
|
+
/** Overall closeness/intimacy (0–1). */
|
|
27
|
+
closeness?: number;
|
|
28
|
+
/** Mutual trust level (0–1). */
|
|
29
|
+
trust?: number;
|
|
30
|
+
/** How well they know each other (0–1). */
|
|
31
|
+
familiarity?: number;
|
|
32
|
+
/** Relationship type label. */
|
|
33
|
+
type?: 'friend' | 'romantic' | 'authority' | 'stranger' | string;
|
|
34
|
+
/** Additional relationship-specific fields. */
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}
|
|
24
37
|
type PerceiveBody = RequestBody<'/personas/{id}/perceive', 'post'>;
|
|
25
38
|
export type PerceiveEvent = PerceiveBody['event'];
|
|
26
39
|
export type PerceiveContext = NonNullable<PerceiveBody['context']>;
|
|
@@ -38,7 +51,7 @@ export interface PerceiveOptions {
|
|
|
38
51
|
type?: string;
|
|
39
52
|
/** Low-level stimulus overrides (bodyBudgetDelta, vadOverride, etc.). */
|
|
40
53
|
stimulus?: PerceiveEvent['stimulus'];
|
|
41
|
-
/** Extra payload fields merged into event.payload alongside message. */
|
|
54
|
+
/** Extra payload fields merged into event.payload alongside message (app-specific data). */
|
|
42
55
|
payload?: Record<string, unknown>;
|
|
43
56
|
/** Prior episodic memories for context-aware appraisal. */
|
|
44
57
|
priorEpisodes?: Episode[];
|
|
@@ -46,7 +59,7 @@ export interface PerceiveOptions {
|
|
|
46
59
|
* When provided, the engine computes trust/intimacy/proximity deltas
|
|
47
60
|
* and emits socialUpdates in the response.
|
|
48
61
|
* Typically sourced from World-level storage (D1). */
|
|
49
|
-
relationshipContext?:
|
|
62
|
+
relationshipContext?: RelationshipContext;
|
|
50
63
|
/** Skip saving memoryEpisode to the episode store. Default: false. */
|
|
51
64
|
skipMemory?: boolean;
|
|
52
65
|
}
|
|
@@ -58,7 +71,34 @@ export interface EventAppraisal {
|
|
|
58
71
|
relationship: 'friend' | 'romantic' | 'authority' | 'stranger';
|
|
59
72
|
intensity: number;
|
|
60
73
|
}
|
|
61
|
-
|
|
74
|
+
/** Full dynamic state returned by the persona state endpoint. */
|
|
75
|
+
export interface PersonaDynamicState {
|
|
76
|
+
emotion: {
|
|
77
|
+
vad: VAD;
|
|
78
|
+
discrete?: {
|
|
79
|
+
primary: string;
|
|
80
|
+
secondary?: string;
|
|
81
|
+
intensity: number;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
mood?: {
|
|
85
|
+
vad: VAD;
|
|
86
|
+
};
|
|
87
|
+
somatic?: string[];
|
|
88
|
+
narrative?: {
|
|
89
|
+
tone: number;
|
|
90
|
+
agency: number;
|
|
91
|
+
coherence: number;
|
|
92
|
+
};
|
|
93
|
+
goals?: Goal[];
|
|
94
|
+
bodyBudget?: number;
|
|
95
|
+
soulStage?: {
|
|
96
|
+
id: number;
|
|
97
|
+
name: string;
|
|
98
|
+
};
|
|
99
|
+
/** Additional engine-specific fields. */
|
|
100
|
+
[key: string]: unknown;
|
|
101
|
+
}
|
|
62
102
|
export type BlendRatio = Record<string, number>;
|
|
63
103
|
export interface AgentResponse {
|
|
64
104
|
text?: string;
|
|
@@ -143,7 +183,14 @@ export interface SocialUpdate {
|
|
|
143
183
|
dimension: string;
|
|
144
184
|
delta: number;
|
|
145
185
|
}
|
|
146
|
-
|
|
186
|
+
/** Full persona snapshot including engine state, config, and metadata. */
|
|
187
|
+
export interface PersonaSnapshot {
|
|
188
|
+
config?: PersonaConfigData;
|
|
189
|
+
state?: State;
|
|
190
|
+
engineVersion?: string;
|
|
191
|
+
/** Additional engine-specific fields. */
|
|
192
|
+
[key: string]: unknown;
|
|
193
|
+
}
|
|
147
194
|
/**
|
|
148
195
|
* HEXACO-PI-R personality domain traits (Ashton & Lee, 2007).
|
|
149
196
|
* Each value ranges from 0 (low) to 1 (high).
|
|
@@ -175,6 +222,18 @@ export interface Identity {
|
|
|
175
222
|
coreValues?: string[];
|
|
176
223
|
culturalIdentity?: string;
|
|
177
224
|
description?: string;
|
|
225
|
+
/** Character backstory or personal history. */
|
|
226
|
+
backstory?: string;
|
|
227
|
+
/** Key relationships and how the persona perceives them. e.g. {"mom": "strict but loving"} */
|
|
228
|
+
relationships?: Record<string, string>;
|
|
229
|
+
/** Interests, hobbies, or topics the persona cares about. */
|
|
230
|
+
interests?: string[];
|
|
231
|
+
/** Characteristic speech patterns or verbal tics. e.g. ["ends sentences with ~잖아", "says 진짜 when surprised"] */
|
|
232
|
+
speechPatterns?: string[];
|
|
233
|
+
/** Emotional reaction patterns. e.g. {"angry": "goes quiet and terse", "happy": "talks fast"} */
|
|
234
|
+
emotionalPatterns?: Record<string, string>;
|
|
235
|
+
/** Distinctive habits or quirks. e.g. ["taps fingers when thinking", "avoids eye contact when lying"] */
|
|
236
|
+
quirks?: string[];
|
|
178
237
|
extensions?: Record<string, string>;
|
|
179
238
|
}
|
|
180
239
|
export interface Goal {
|
|
@@ -190,6 +249,12 @@ export interface PersonaConfigData {
|
|
|
190
249
|
goals?: Goal[];
|
|
191
250
|
[key: string]: unknown;
|
|
192
251
|
}
|
|
252
|
+
/** Persona identity config as returned by {@link MolrooPersona.getIdentity}. */
|
|
253
|
+
export interface PersonaIdentity {
|
|
254
|
+
identity: Identity;
|
|
255
|
+
personality: PersonalityTraits;
|
|
256
|
+
goals?: Goal[];
|
|
257
|
+
}
|
|
193
258
|
export interface MotivationContext {
|
|
194
259
|
goals: Goal[];
|
|
195
260
|
activeGoal?: Goal;
|
|
@@ -272,5 +337,5 @@ export interface State {
|
|
|
272
337
|
regulation: RegulationState;
|
|
273
338
|
prevMaskIntegrity?: number;
|
|
274
339
|
}
|
|
275
|
-
export { MolrooApiError } from './errors';
|
|
340
|
+
export { MolrooApiError, MolrooErrorCode } from './errors';
|
|
276
341
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAI7C,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AACpD,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAIjF,MAAM,MAAM,WAAW,CACrB,CAAC,SAAS,MAAM,KAAK,EACrB,CAAC,SAAS,MAAM,GAAG,KAAK,GAAG,OAAO,IAChC,KAAK,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE;YAAE,kBAAkB,EAAE,MAAM,CAAC,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,CAAC,GAC1F,CAAC,GACD,KAAK,CAAC;AAeV;;2EAE2E;AAC3E,MAAM,WAAW,mBAAmB;IAClC,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAID,KAAK,YAAY,GAAG,WAAW,CAAC,yBAAyB,EAAE,MAAM,CAAC,CAAC;AACnE,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;AAClD,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC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QAAQ,CAAC;IACnB,eAAe,EAAE,KAAK,CAAC,GAAG,GAAG;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,SAAS,CAAC;IACtB,gBAAgB,EAAE,eAAe,CAAC;IAClC,kBAAkB,CAAC,EAAE,GAAG,CAAC;IACzB,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,gBAAgB,CAAC;IAC9B,OAAO,EAAE,YAAY,CAAC;IACtB,eAAe,EAAE,mBAAmB,CAAC;IACrC,aAAa,EAAE,kBAAkB,CAAC;IAClC,UAAU,EAAE,eAAe,CAAC;IAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAID,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/esm/types.js
CHANGED
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
// Pipeline: Engine Zod schemas → @hono/zod-openapi → OpenAPI JSON → openapi-typescript → api.d.ts
|
|
9
9
|
// ============================================================================
|
|
10
10
|
// ── Error (re-exported from errors.ts) ──
|
|
11
|
-
export { MolrooApiError } from './errors';
|
|
11
|
+
export { MolrooApiError, MolrooErrorCode } from './errors';
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { type ApiClient } from './client';
|
|
11
11
|
import type { Appraisal } from './types';
|
|
12
12
|
import type { LLMAdapter } from '../llm/adapter';
|
|
13
|
+
import type { ZodSchema } from 'zod';
|
|
13
14
|
export type LLMMessage = {
|
|
14
15
|
role: 'user' | 'assistant' | 'system';
|
|
15
16
|
content: string;
|
|
@@ -71,7 +72,7 @@ export interface PersonaDetail {
|
|
|
71
72
|
};
|
|
72
73
|
state: WorldPersonaState | null;
|
|
73
74
|
}
|
|
74
|
-
export interface ReactOptions {
|
|
75
|
+
export interface ReactOptions<T = string> {
|
|
75
76
|
/** Who is performing the action (e.g. 'yongjun'). */
|
|
76
77
|
actor?: string;
|
|
77
78
|
actorType?: 'user' | 'persona';
|
|
@@ -80,7 +81,7 @@ export interface ReactOptions {
|
|
|
80
81
|
/** Prior conversation turns for context. */
|
|
81
82
|
history?: LLMMessage[];
|
|
82
83
|
/** Zod schema for structured output. Omit for plain text. */
|
|
83
|
-
schema?:
|
|
84
|
+
schema?: ZodSchema<T>;
|
|
84
85
|
temperature?: number;
|
|
85
86
|
}
|
|
86
87
|
export interface ReactResult<T = string> {
|
|
@@ -117,8 +118,22 @@ export declare class WorldPersona {
|
|
|
117
118
|
getState(): Promise<WorldPersonaState>;
|
|
118
119
|
/** Get speaking style from persona config (identity.speakingStyle). */
|
|
119
120
|
getSpeakingStyle(): Promise<string | undefined>;
|
|
120
|
-
/**
|
|
121
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Get LLM system prompt assembled from all persona subsystems + world context.
|
|
123
|
+
*
|
|
124
|
+
* @param options - Prompt context options.
|
|
125
|
+
* @param options.sourceEntity - Name of the conversation partner for interlocutor-aware rendering.
|
|
126
|
+
* @param options.consumerSuffix - Free-form app-specific context appended to the system prompt as-is.
|
|
127
|
+
* @param options.consumerRules - Behavioral constraints and absolute rules.
|
|
128
|
+
* Examples: "Never break character", "Always respond in Korean".
|
|
129
|
+
* @param options.consumerExamples - Few-shot example messages for style/behavior reference.
|
|
130
|
+
*/
|
|
131
|
+
getPromptContext(options?: {
|
|
132
|
+
sourceEntity?: string;
|
|
133
|
+
consumerSuffix?: string;
|
|
134
|
+
consumerRules?: string;
|
|
135
|
+
consumerExamples?: string;
|
|
136
|
+
}): Promise<PromptContext>;
|
|
122
137
|
/**
|
|
123
138
|
* Send a predefined action to this persona's emotion engine.
|
|
124
139
|
* Invalidates cached state.
|
|
@@ -183,6 +198,6 @@ export declare class WorldPersona {
|
|
|
183
198
|
* console.log(r2.narrative.dialogue); // typed
|
|
184
199
|
* ```
|
|
185
200
|
*/
|
|
186
|
-
react<T = string>(action: string, options: ReactOptions): Promise<ReactResult<T>>;
|
|
201
|
+
react<T = string>(action: string, options: ReactOptions<T>): Promise<ReactResult<T>>;
|
|
187
202
|
}
|
|
188
203
|
//# sourceMappingURL=world-persona.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"world-persona.d.ts","sourceRoot":"","sources":["../../../src/world/world-persona.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAU,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"world-persona.d.ts","sourceRoot":"","sources":["../../../src/world/world-persona.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAU,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAMrC,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC;AAMlC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,KAAK,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC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,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAiD3B"}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { unwrap } from './client';
|
|
11
11
|
import { toWireAppraisal } from '../shared/appraisal';
|
|
12
|
+
import { MolrooApiError, MolrooErrorCode } from '../shared/errors';
|
|
12
13
|
export class WorldPersona {
|
|
13
14
|
/** @internal — use World.persona() instead. */
|
|
14
15
|
constructor(client, worldId, personaId, options) {
|
|
@@ -54,11 +55,26 @@ export class WorldPersona {
|
|
|
54
55
|
const detail = await this.getDetail();
|
|
55
56
|
return detail.config?.identity?.speakingStyle;
|
|
56
57
|
}
|
|
57
|
-
/**
|
|
58
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Get LLM system prompt assembled from all persona subsystems + world context.
|
|
60
|
+
*
|
|
61
|
+
* @param options - Prompt context options.
|
|
62
|
+
* @param options.sourceEntity - Name of the conversation partner for interlocutor-aware rendering.
|
|
63
|
+
* @param options.consumerSuffix - Free-form app-specific context appended to the system prompt as-is.
|
|
64
|
+
* @param options.consumerRules - Behavioral constraints and absolute rules.
|
|
65
|
+
* Examples: "Never break character", "Always respond in Korean".
|
|
66
|
+
* @param options.consumerExamples - Few-shot example messages for style/behavior reference.
|
|
67
|
+
*/
|
|
68
|
+
async getPromptContext(options) {
|
|
69
|
+
const { sourceEntity, consumerSuffix, consumerRules, consumerExamples } = options ?? {};
|
|
59
70
|
const { data } = await this._client.POST('/worlds/{id}/personas/{pid}/prompt-context', {
|
|
60
71
|
params: { path: { id: this._worldId, pid: this._personaId } },
|
|
61
|
-
body:
|
|
72
|
+
body: {
|
|
73
|
+
...(sourceEntity ? { sourceEntity } : {}),
|
|
74
|
+
...(consumerSuffix ? { consumerSuffix } : {}),
|
|
75
|
+
...(consumerRules ? { consumerRules } : {}),
|
|
76
|
+
...(consumerExamples ? { consumerExamples } : {}),
|
|
77
|
+
},
|
|
62
78
|
});
|
|
63
79
|
return unwrap(data);
|
|
64
80
|
}
|
|
@@ -134,7 +150,7 @@ export class WorldPersona {
|
|
|
134
150
|
*/
|
|
135
151
|
async react(action, options) {
|
|
136
152
|
if (!this._llm) {
|
|
137
|
-
throw new
|
|
153
|
+
throw new MolrooApiError('WorldPersona.react() requires an LLM adapter. Pass { llm } to world.persona().', MolrooErrorCode.LLM_NOT_CONFIGURED, 400);
|
|
138
154
|
}
|
|
139
155
|
// 1. Interact — emotion engine processes the action
|
|
140
156
|
const interactResult = await this.interact(action, {
|
|
@@ -142,7 +158,7 @@ export class WorldPersona {
|
|
|
142
158
|
actorType: options.actorType,
|
|
143
159
|
});
|
|
144
160
|
// 2. Get prompt context — now reflects updated emotion
|
|
145
|
-
const ctx = await this.getPromptContext(options.actor);
|
|
161
|
+
const ctx = await this.getPromptContext({ sourceEntity: options.actor });
|
|
146
162
|
// 3. LLM generates narrative
|
|
147
163
|
const messages = [
|
|
148
164
|
...(options.history ?? []),
|
|
@@ -2,7 +2,7 @@ import { type ApiClient } from './client';
|
|
|
2
2
|
import { World } from './world-domain';
|
|
3
3
|
import { MolrooPersona } from '../persona';
|
|
4
4
|
import type { PersonaSummary } from '../persona';
|
|
5
|
-
import type {
|
|
5
|
+
import type { PersonaConfigData } from '../types';
|
|
6
6
|
import type { LLMInput } from '../llm/resolve';
|
|
7
7
|
import type { MemoryAdapter, RecallLimits } from '../memory/types';
|
|
8
8
|
import type { EventAdapter } from '../events/types';
|
|
@@ -18,8 +18,6 @@ export interface PersonaOptions {
|
|
|
18
18
|
memory?: MemoryAdapter;
|
|
19
19
|
recall?: RecallLimits;
|
|
20
20
|
events?: EventAdapter;
|
|
21
|
-
/** Appraisal generation mode for `chat()`. `'direct'` (default) generates raw appraisal vectors; `'event'` classifies into ontology events and converts server-side. */
|
|
22
|
-
appraisalMode?: AppraisalMode;
|
|
23
21
|
}
|
|
24
22
|
/**
|
|
25
23
|
* Unified entry point for the molroo SDK.
|
|
@@ -74,6 +72,28 @@ export declare class Molroo {
|
|
|
74
72
|
createPersona(personaConfig: PersonaConfigData, options?: PersonaOptions): Promise<MolrooPersona>;
|
|
75
73
|
/**
|
|
76
74
|
* Connect to an existing persona by ID.
|
|
75
|
+
*
|
|
76
|
+
* LLM adapter is optional. Without it, {@link MolrooPersona.chat | chat()} will throw,
|
|
77
|
+
* but emotion/state APIs ({@link MolrooPersona.hear | hear()},
|
|
78
|
+
* {@link MolrooPersona.getState | getState()},
|
|
79
|
+
* {@link MolrooPersona.getEngineState | getEngineState()},
|
|
80
|
+
* {@link MolrooPersona.perceive | perceive()},
|
|
81
|
+
* {@link MolrooPersona.tick | tick()}) work without LLM.
|
|
82
|
+
*
|
|
83
|
+
* This is the recommended pattern for hybrid apps that build their own prompts
|
|
84
|
+
* and only need SDK for emotion/psychological state computation.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* // Hybrid: emotion engine only (no LLM needed)
|
|
89
|
+
* const persona = await molroo.connectPersona('persona_abc123');
|
|
90
|
+
* const state = await persona.getEngineState(elapsed);
|
|
91
|
+
* const emotion = await persona.hear(userMessage, 'Alice');
|
|
92
|
+
*
|
|
93
|
+
* // Full: SDK handles everything (LLM required)
|
|
94
|
+
* const persona = await molroo.connectPersona('persona_abc123', { llm });
|
|
95
|
+
* const result = await persona.chat('Hello!');
|
|
96
|
+
* ```
|
|
77
97
|
*/
|
|
78
98
|
connectPersona(personaId: string, options?: PersonaOptions): Promise<MolrooPersona>;
|
|
79
99
|
/**
|
|
@@ -99,8 +119,11 @@ export declare class Molroo {
|
|
|
99
119
|
*/
|
|
100
120
|
getWorld(id: string): Promise<World>;
|
|
101
121
|
/**
|
|
102
|
-
* List worlds
|
|
103
|
-
* efficiency when only metadata is needed.
|
|
122
|
+
* List worlds for the authenticated tenant.
|
|
123
|
+
* Returns raw data objects (not World instances) for efficiency when only metadata is needed.
|
|
124
|
+
*
|
|
125
|
+
* @param options - Pagination options (limit, cursor).
|
|
126
|
+
* @returns Paginated list of world data and next cursor.
|
|
104
127
|
*/
|
|
105
128
|
listWorlds(options?: PaginationOptions): Promise<{
|
|
106
129
|
worlds: WorldData[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"world.d.ts","sourceRoot":"","sources":["../../../src/world/world.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"world.d.ts","sourceRoot":"","sources":["../../../src/world/world.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EACV,SAAS,EACT,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAiCjB,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,0FAA0F;AAC1F,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,MAAM,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EAAE,iBAAiB,GAC1B,OAAO,CAAC;QAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CA6B/D"}
|
package/dist/esm/world/world.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { createWorldClient, unwrap } from './client';
|
|
3
3
|
import { World } from './world-domain';
|
|
4
4
|
import { MolrooPersona } from '../persona';
|
|
5
|
+
import { MolrooApiError, MolrooErrorCode } from '../shared/errors';
|
|
5
6
|
// ---------------------------------------------------------------------------
|
|
6
7
|
// Internal helper
|
|
7
8
|
// ---------------------------------------------------------------------------
|
|
@@ -53,7 +54,7 @@ export class Molroo {
|
|
|
53
54
|
if (typeof input === 'string') {
|
|
54
55
|
// Description path - requires llm
|
|
55
56
|
if (!options?.llm) {
|
|
56
|
-
throw new
|
|
57
|
+
throw new MolrooApiError('LLM adapter is required when using description string', MolrooErrorCode.LLM_REQUIRED, 400);
|
|
57
58
|
}
|
|
58
59
|
return MolrooPersona.create({ baseUrl: this._baseUrl, apiKey: this._apiKey, ...options, llm: options.llm }, input);
|
|
59
60
|
}
|
|
@@ -62,6 +63,28 @@ export class Molroo {
|
|
|
62
63
|
}
|
|
63
64
|
/**
|
|
64
65
|
* Connect to an existing persona by ID.
|
|
66
|
+
*
|
|
67
|
+
* LLM adapter is optional. Without it, {@link MolrooPersona.chat | chat()} will throw,
|
|
68
|
+
* but emotion/state APIs ({@link MolrooPersona.hear | hear()},
|
|
69
|
+
* {@link MolrooPersona.getState | getState()},
|
|
70
|
+
* {@link MolrooPersona.getEngineState | getEngineState()},
|
|
71
|
+
* {@link MolrooPersona.perceive | perceive()},
|
|
72
|
+
* {@link MolrooPersona.tick | tick()}) work without LLM.
|
|
73
|
+
*
|
|
74
|
+
* This is the recommended pattern for hybrid apps that build their own prompts
|
|
75
|
+
* and only need SDK for emotion/psychological state computation.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Hybrid: emotion engine only (no LLM needed)
|
|
80
|
+
* const persona = await molroo.connectPersona('persona_abc123');
|
|
81
|
+
* const state = await persona.getEngineState(elapsed);
|
|
82
|
+
* const emotion = await persona.hear(userMessage, 'Alice');
|
|
83
|
+
*
|
|
84
|
+
* // Full: SDK handles everything (LLM required)
|
|
85
|
+
* const persona = await molroo.connectPersona('persona_abc123', { llm });
|
|
86
|
+
* const result = await persona.chat('Hello!');
|
|
87
|
+
* ```
|
|
65
88
|
*/
|
|
66
89
|
async connectPersona(personaId, options) {
|
|
67
90
|
return MolrooPersona.connect({ baseUrl: this._baseUrl, apiKey: this._apiKey, ...options }, personaId);
|
|
@@ -111,8 +134,11 @@ export class Molroo {
|
|
|
111
134
|
return new World(this._client, toWorldData(raw));
|
|
112
135
|
}
|
|
113
136
|
/**
|
|
114
|
-
* List worlds
|
|
115
|
-
* efficiency when only metadata is needed.
|
|
137
|
+
* List worlds for the authenticated tenant.
|
|
138
|
+
* Returns raw data objects (not World instances) for efficiency when only metadata is needed.
|
|
139
|
+
*
|
|
140
|
+
* @param options - Pagination options (limit, cursor).
|
|
141
|
+
* @returns Paginated list of world data and next cursor.
|
|
116
142
|
*/
|
|
117
143
|
async listWorlds(options) {
|
|
118
144
|
const { data } = await this._client.GET('/worlds', {
|