@molroo-io/sdk 0.9.0 → 0.10.0
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/defaults/index.d.ts.map +1 -1
- package/dist/cjs/defaults/index.js +10 -5
- 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 +2 -2
- 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 +330 -36
- package/dist/cjs/persona.d.ts.map +1 -1
- package/dist/cjs/persona.js +302 -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/api-client.js +2 -2
- package/dist/esm/defaults/index.d.ts.map +1 -1
- package/dist/esm/defaults/index.js +10 -2
- 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/generate/persona.js +2 -2
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -6
- package/dist/esm/llm/resolve.d.ts.map +1 -1
- package/dist/esm/llm/resolve.js +3 -2
- 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/llm/vercel-ai/index.js +2 -2
- package/dist/esm/package.json +1 -0
- 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 +32 -112
- 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 +31 -5
- package/dist/esm/persona.d.ts +330 -36
- package/dist/esm/persona.d.ts.map +1 -1
- package/dist/esm/persona.js +308 -26
- 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/types.js +1 -1
- package/dist/esm/world/client.js +2 -2
- package/dist/esm/world/errors.js +1 -1
- package/dist/esm/world/index.js +5 -5
- package/dist/esm/world/world-domain.js +3 -3
- 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 +23 -7
- 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 +27 -4
- package/package.json +3 -3
- package/dist/cjs/defaults/persona.json +0 -17
- package/dist/esm/defaults/persona.json +0 -17
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* WorldPersona는 Persona SDK와 동일한 DX(getState, getPromptContext, react)를
|
|
8
8
|
* 제공하되, 내부적으로 World API 엔드포인트를 사용한다.
|
|
9
9
|
*/
|
|
10
|
-
import { unwrap } from './client';
|
|
11
|
-
import { toWireAppraisal } from '../shared/appraisal';
|
|
10
|
+
import { unwrap } from './client.js';
|
|
11
|
+
import { toWireAppraisal } from '../shared/appraisal.js';
|
|
12
|
+
import { MolrooApiError, MolrooErrorCode } from '../shared/errors.js';
|
|
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
|
/**
|
|
@@ -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,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AalC;;;;;;;;;;;OAWG;IACG,aAAa,CACjB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,cAAc,GAAG;QAAE,GAAG,EAAE,QAAQ,CAAA;KAAE,GAC1C,OAAO,CAAC,aAAa,CAAC;IAEzB;;;;;;;;;;OAUG;IACG,aAAa,CACjB,aAAa,EAAE,iBAAiB,EAChC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,aAAa,CAAC;IA2BzB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,cAAc,CAClB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,aAAa,CAAC;IAOzB;;;OAGG;IACG,eAAe,CACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,cAAc,GAAG;QAAE,GAAG,EAAE,QAAQ,CAAA;KAAE,GAC1C,OAAO,CAAC,aAAa,CAAC;IAIzB;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,cAAc,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAWlF;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,KAAK,CAAC;IAwB9D;;OAEG;IACG,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAmB1C;;;;;;OAMG;IACG,UAAU,CACd,OAAO,CAAC,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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// INFO: @F001 Top-level SDK entry point — see plan step 4
|
|
2
|
-
import { createWorldClient, unwrap } from './client';
|
|
3
|
-
import { World } from './world-domain';
|
|
4
|
-
import { MolrooPersona } from '../persona';
|
|
2
|
+
import { createWorldClient, unwrap } from './client.js';
|
|
3
|
+
import { World } from './world-domain.js';
|
|
4
|
+
import { MolrooPersona } from '../persona.js';
|
|
5
|
+
import { MolrooApiError, MolrooErrorCode } from '../shared/errors.js';
|
|
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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molroo-io/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Unified SDK for molroo emotion engine — persona, world, LLM integration",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dist"
|
|
42
42
|
],
|
|
43
43
|
"scripts": {
|
|
44
|
-
"build": "rm -rf dist && tsc -p tsconfig.build.json && tsc -p tsconfig.esm.json",
|
|
44
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && tsc -p tsconfig.esm.json && node scripts/fix-esm-extensions.mjs",
|
|
45
45
|
"test": "vitest run",
|
|
46
46
|
"test:watch": "vitest",
|
|
47
47
|
"test:coverage": "vitest run --coverage",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"format:check": "prettier --check 'src/**/*.ts'",
|
|
52
52
|
"clean": "rm -rf dist",
|
|
53
53
|
"docs": "typedoc",
|
|
54
|
-
"gen:types": "node
|
|
54
|
+
"gen:types": "node ../api/scripts/dump-spec.mjs ../api/dist/openapi.json && openapi-typescript ../api/dist/openapi.json -o src/generated/api.d.ts"
|
|
55
55
|
},
|
|
56
56
|
"keywords": [
|
|
57
57
|
"emotion",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"personality": {
|
|
3
|
-
"O": 0.5,
|
|
4
|
-
"C": 0.5,
|
|
5
|
-
"E": 0.5,
|
|
6
|
-
"A": 0.5,
|
|
7
|
-
"N": 0.5,
|
|
8
|
-
"H": 0.5
|
|
9
|
-
},
|
|
10
|
-
"identity": {
|
|
11
|
-
"name": "Persona",
|
|
12
|
-
"role": "A person with a neutral, balanced personality.",
|
|
13
|
-
"speakingStyle": "Natural, conversational tone.",
|
|
14
|
-
"coreValues": ["honesty", "kindness"]
|
|
15
|
-
},
|
|
16
|
-
"goals": []
|
|
17
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"personality": {
|
|
3
|
-
"O": 0.5,
|
|
4
|
-
"C": 0.5,
|
|
5
|
-
"E": 0.5,
|
|
6
|
-
"A": 0.5,
|
|
7
|
-
"N": 0.5,
|
|
8
|
-
"H": 0.5
|
|
9
|
-
},
|
|
10
|
-
"identity": {
|
|
11
|
-
"name": "Persona",
|
|
12
|
-
"role": "A person with a neutral, balanced personality.",
|
|
13
|
-
"speakingStyle": "Natural, conversational tone.",
|
|
14
|
-
"coreValues": ["honesty", "kindness"]
|
|
15
|
-
},
|
|
16
|
-
"goals": []
|
|
17
|
-
}
|