@charivo/llm 0.4.3 → 0.6.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.
@@ -13,6 +13,7 @@ var OpenClawLLMProvider = class {
13
13
  model;
14
14
  temperature;
15
15
  maxTokens;
16
+ sessionKey;
16
17
  constructor(config) {
17
18
  if (typeof window !== "undefined" && !config.dangerouslyAllowBrowser) {
18
19
  throw new core.CharivoStateError(
@@ -22,18 +23,17 @@ var OpenClawLLMProvider = class {
22
23
  this.openai = new OpenAI__default.default({
23
24
  apiKey: config.token,
24
25
  baseURL: config.baseURL || "http://127.0.0.1:18789/v1",
25
- defaultHeaders: {
26
- "x-openclaw-agent-id": config.agentId || "main"
27
- },
26
+ defaultHeaders: config.agentId ? { "x-openclaw-agent-id": config.agentId } : void 0,
28
27
  dangerouslyAllowBrowser: config.dangerouslyAllowBrowser
29
28
  });
30
- this.model = config.model || "openclaw";
29
+ this.model = config.model || "openclaw/default";
31
30
  this.temperature = config.temperature ?? 0.7;
32
31
  this.maxTokens = config.maxTokens || 1e3;
32
+ this.sessionKey = config.sessionKey;
33
33
  }
34
34
  async generateResponse(messages) {
35
35
  try {
36
- const openAIMessages = messages.map((msg) => ({
36
+ const openAIMessages = this.selectMessages(messages).map((msg) => ({
37
37
  role: msg.role,
38
38
  content: msg.content
39
39
  }));
@@ -41,13 +41,28 @@ var OpenClawLLMProvider = class {
41
41
  model: this.model,
42
42
  messages: openAIMessages,
43
43
  temperature: this.temperature,
44
- max_tokens: this.maxTokens
44
+ max_tokens: this.maxTokens,
45
+ ...this.sessionKey ? { user: this.sessionKey } : {}
45
46
  });
46
47
  return completion.choices[0]?.message?.content || "";
47
48
  } catch (error) {
48
49
  throw core.toCharivoError("provider", error, "OpenClaw LLM request failed");
49
50
  }
50
51
  }
52
+ /**
53
+ * With a pinned session the gateway already holds the past turns, and resending
54
+ * them would flatten a duplicate copy of the history on top of its own. Keep the
55
+ * system prompts (cheap persona insurance if the session was dropped) and the
56
+ * latest turn.
57
+ */
58
+ selectMessages(messages) {
59
+ const latest = messages[messages.length - 1];
60
+ if (!this.sessionKey || !latest) {
61
+ return messages;
62
+ }
63
+ const systemMessages = messages.filter((msg) => msg.role === "system");
64
+ return latest.role === "system" ? systemMessages : [...systemMessages, latest];
65
+ }
51
66
  };
52
67
  function createOpenClawLLMProvider(config) {
53
68
  return new OpenClawLLMProvider(config);
@@ -57,8 +72,9 @@ function createOpenClawLLMProvider(config) {
57
72
  var OpenClawLLMClient = class {
58
73
  provider;
59
74
  constructor(config) {
75
+ const { sessionKey: _sessionKey, ...rest } = config;
60
76
  this.provider = createOpenClawLLMProvider({
61
- ...config,
77
+ ...rest,
62
78
  dangerouslyAllowBrowser: true
63
79
  });
64
80
  }
@@ -70,7 +86,8 @@ function createOpenClawLLMClient(config) {
70
86
  return new OpenClawLLMClient(config);
71
87
  }
72
88
 
73
- exports.OpenClawLLMClient = OpenClawLLMClient;
89
+ exports.OpenClawLLMProvider = OpenClawLLMProvider;
74
90
  exports.createOpenClawLLMClient = createOpenClawLLMClient;
91
+ exports.createOpenClawLLMProvider = createOpenClawLLMProvider;
75
92
  //# sourceMappingURL=index.js.map
76
93
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/openclaw/provider.ts","../../src/openclaw/index.ts"],"names":["CharivoStateError","OpenAI","toCharivoError"],"mappings":";;;;;;;;;;AAaO,IAAM,sBAAN,MAAiD;AAAA,EAC9C,MAAA;AAAA,EACA,KAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AAAA,EAER,YAAY,MAAA,EAA2B;AACrC,IAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,CAAC,OAAO,uBAAA,EAAyB;AACpE,MAAA,MAAM,IAAIA,sBAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,MAAA,GAAS,IAAIC,uBAAA,CAAO;AAAA,MACvB,QAAQ,MAAA,CA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CAAK,WAAW,yBAAA,CAA0B;AAAA,MACxC,GAAG,MAAA;AAAA,MACH,uBAAA,EAAyB;AAAA,KAC1B,CAAA;AAAA,EACH;AAAA,EAEA,MAAM,KACJ,QAAA,EACiB;AACjB,IAAA,OAAO,IAAA,CAAK,QAAA,CAAS,gBAAA,CAAiB,QAAQ,CAAA;AAAA,EAChD;AACF;AAEO,SAAS,wBACd,MAAA,EACmB;AACnB,EAAA,OAAO,IAAI,kBAAkB,MAAM,CAAA;AACrC","file":"index.js","sourcesContent":["import OpenAI from \"openai\";\nimport { CharivoStateError, LLMProvider, toCharivoError } from \"@charivo/core\";\n\nexport interface OpenClawLLMConfig {\n token: string;\n baseURL?: string;\n agentId?: string;\n model?: string;\n temperature?: number;\n maxTokens?: number;\n dangerouslyAllowBrowser?: boolean;\n}\n\nexport class OpenClawLLMProvider implements LLMProvider {\n private openai: OpenAI;\n private model: string;\n private temperature: number;\n private maxTokens: number;\n\n constructor(config: OpenClawLLMConfig) {\n if (typeof window !== \"undefined\" && !config.dangerouslyAllowBrowser) {\n throw new CharivoStateError(\n \"OpenClaw LLM provider is for server-side use only. Set dangerouslyAllowBrowser: true for testing\",\n );\n }\n\n this.openai = new OpenAI({\n apiKey: config.token,\n baseURL: config.baseURL || \"http://127.0.0.1:18789/v1\",\n defaultHeaders: {\n \"x-openclaw-agent-id\": config.agentId || \"main\",\n },\n dangerouslyAllowBrowser: config.dangerouslyAllowBrowser,\n });\n\n this.model = config.model || \"openclaw\";\n this.temperature = config.temperature ?? 0.7;\n this.maxTokens = config.maxTokens || 1000;\n }\n\n async generateResponse(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n try {\n const openAIMessages = messages.map((msg) => ({\n role: msg.role as \"system\" | \"user\" | \"assistant\",\n content: msg.content,\n }));\n\n const completion = await this.openai.chat.completions.create({\n model: this.model,\n messages: openAIMessages,\n temperature: this.temperature,\n max_tokens: this.maxTokens,\n });\n\n return completion.choices[0]?.message?.content || \"\";\n } catch (error) {\n throw toCharivoError(\"provider\", error, \"OpenClaw LLM request failed\");\n }\n }\n}\n\nexport function createOpenClawLLMProvider(\n config: OpenClawLLMConfig,\n): OpenClawLLMProvider {\n return new OpenClawLLMProvider(config);\n}\n","import { LLMClient } from \"@charivo/core\";\nimport {\n createOpenClawLLMProvider,\n OpenClawLLMConfig,\n OpenClawLLMProvider,\n} from \"./provider\";\n\n// OpenClawLLMConfig를 직접 사용\nexport type OpenClawLLMClientConfig = OpenClawLLMConfig;\n\n/**\n * OpenClaw LLM Client - OpenClaw provider를 래핑해서 클라이언트에서 직접 사용하는 Stateless 클라이언트\n *\n * 로컬 개발이나 테스트 환경에서 사용. 프로덕션에서는 보안상 권장하지 않음.\n * 토큰이 클라이언트에 노출되므로 서버 환경에서만 사용하거나 테스트용으로만 사용해야 함.\n *\n * Stateless 설계: 세션 관리는 외부에서 담당하고, 이 클라이언트는 API 호출만 담당\n */\nexport class OpenClawLLMClient implements LLMClient {\n private provider: OpenClawLLMProvider;\n\n constructor(config: OpenClawLLMClientConfig) {\n // Intentional dev/test escape hatch: this direct browser client exposes\n // credentials. For production, see docs/guide/choosing-packages.md#remote.\n this.provider = createOpenClawLLMProvider({\n ...config,\n dangerouslyAllowBrowser: true,\n });\n }\n\n async call(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n return this.provider.generateResponse(messages);\n }\n}\n\nexport function createOpenClawLLMClient(\n config: OpenClawLLMClientConfig,\n): OpenClawLLMClient {\n return new OpenClawLLMClient(config);\n}\n"]}
1
+ {"version":3,"sources":["../../src/openclaw/provider.ts","../../src/openclaw/index.ts"],"names":["CharivoStateError","OpenAI","toCharivoError"],"mappings":";;;;;;;;;;AAwCO,IAAM,sBAAN,MAAiD;AAAA,EAC9C,MAAA;AAAA,EACA,KAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EAER,YAAY,MAAA,EAA2B;AACrC,IAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe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ider, toCharivoError } from \"@charivo/core\";\n\nexport interface OpenClawLLMConfig {\n token: string;\n baseURL?: string;\n /**\n * Target a specific agent on the gateway.\n * When omitted, the gateway's configured default agent handles the request.\n */\n agentId?: string;\n /**\n * Agent target, not a backend model name. The gateway resolves this to an\n * agent: `openclaw`, `openclaw/default`, or `openclaw/<agentId>`.\n *\n * @default \"openclaw/default\"\n */\n model?: string;\n temperature?: number;\n maxTokens?: number;\n /**\n * Pins the conversation to a server-side session on the gateway.\n *\n * The gateway keeps conversation state itself, but without an identifier it\n * opens a fresh session per request: nothing is persisted between turns and\n * each one strands a throwaway session. Sending this as the `user` field makes\n * the gateway derive a stable session key from it.\n *\n * When set, past turns are not resent — the gateway already holds them. The\n * system prompt is still sent every turn so the persona survives a dropped\n * session.\n *\n * Treat it as a conversation-scoped identifier (e.g. a UUID per conversation,\n * rotated when the user resets the chat). Rotating it is the only way to reset\n * the conversation; the gateway keeps the old transcript under the old key.\n */\n sessionKey?: string;\n dangerouslyAllowBrowser?: boolean;\n}\n\nexport class OpenClawLLMProvider implements LLMProvider {\n private openai: OpenAI;\n private model: string;\n private temperature: number;\n private maxTokens: number;\n private sessionKey?: string;\n\n constructor(config: OpenClawLLMConfig) {\n if (typeof window !== \"undefined\" && !config.dangerouslyAllowBrowser) {\n throw new CharivoStateError(\n \"OpenClaw LLM provider is for server-side use only. Set dangerouslyAllowBrowser: true for testing\",\n );\n }\n\n this.openai = new OpenAI({\n apiKey: config.token,\n baseURL: config.baseURL || \"http://127.0.0.1:18789/v1\",\n defaultHeaders: config.agentId\n ? { \"x-openclaw-agent-id\": config.agentId }\n : undefined,\n dangerouslyAllowBrowser: config.dangerouslyAllowBrowser,\n });\n\n this.model = config.model || \"openclaw/default\";\n this.temperature = config.temperature ?? 0.7;\n this.maxTokens = config.maxTokens || 1000;\n this.sessionKey = config.sessionKey;\n }\n\n async generateResponse(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n try {\n const openAIMessages = this.selectMessages(messages).map((msg) => ({\n role: msg.role as \"system\" | \"user\" | \"assistant\",\n content: msg.content,\n }));\n\n const completion = await this.openai.chat.completions.create({\n model: this.model,\n messages: openAIMessages,\n temperature: this.temperature,\n max_tokens: this.maxTokens,\n ...(this.sessionKey ? { user: this.sessionKey } : {}),\n });\n\n return completion.choices[0]?.message?.content || \"\";\n } catch (error) {\n throw toCharivoError(\"provider\", error, \"OpenClaw LLM request failed\");\n }\n }\n\n /**\n * With a pinned session the gateway already holds the past turns, and resending\n * them would flatten a duplicate copy of the history on top of its own. Keep the\n * system prompts (cheap persona insurance if the session was dropped) and the\n * latest turn.\n */\n private selectMessages(\n messages: Array<{ role: string; content: string }>,\n ): Array<{ role: string; content: string }> {\n const latest = messages[messages.length - 1];\n if (!this.sessionKey || !latest) {\n return messages;\n }\n\n const systemMessages = messages.filter((msg) => msg.role === \"system\");\n return latest.role === \"system\"\n ? systemMessages\n : [...systemMessages, latest];\n }\n}\n\nexport function createOpenClawLLMProvider(\n config: OpenClawLLMConfig,\n): OpenClawLLMProvider {\n return new OpenClawLLMProvider(config);\n}\n","import type { LLMClient } from \"@charivo/core\";\nimport {\n createOpenClawLLMProvider,\n OpenClawLLMConfig,\n OpenClawLLMProvider,\n} from \"./provider\";\n\nexport {\n createOpenClawLLMProvider,\n OpenClawLLMProvider,\n type OpenClawLLMConfig,\n} from \"./provider\";\n\n// No `sessionKey` here, unlike the provider config. Pinning the gateway\n// session requires rotating it on reset, and this client is driven by\n// LLMManager, whose clearHistory()/character switch clear only local history and\n// cannot reach the client. A pinned session would survive that reset and silently\n// replay the old conversation. Server routes construct the provider themselves and\n// can rotate the key, so the option lives there instead.\nexport type OpenClawLLMClientConfig = Omit<OpenClawLLMConfig, \"sessionKey\">;\n\n/**\n * OpenClaw LLM Client - Stateless client that wraps the OpenClaw provider for direct use on the client\n *\n * For use in local development or test environments. Not recommended for production for security reasons.\n * The token is exposed to the client, so use it only in a server environment or for testing purposes.\n *\n * Stateless design: session management is handled externally, and this client only handles API calls\n */\nclass OpenClawLLMClient implements LLMClient {\n private provider: OpenClawLLMProvider;\n\n constructor(config: OpenClawLLMClientConfig) {\n // Strip sessionKey at runtime too: an untyped JS caller can bypass the\n // Omit above and pass it anyway.\n const { sessionKey: _sessionKey, ...rest } = config as OpenClawLLMConfig;\n\n // Intentional dev/test escape hatch: this direct browser client exposes\n // credentials. For production, see docs/guide/choosing-packages.md#remote.\n this.provider = createOpenClawLLMProvider({\n ...rest,\n dangerouslyAllowBrowser: true,\n });\n }\n\n async call(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n return this.provider.generateResponse(messages);\n }\n}\n\nexport function createOpenClawLLMClient(\n config: OpenClawLLMClientConfig,\n): LLMClient {\n return new OpenClawLLMClient(config);\n}\n"]}
@@ -7,6 +7,7 @@ var OpenClawLLMProvider = class {
7
7
  model;
8
8
  temperature;
9
9
  maxTokens;
10
+ sessionKey;
10
11
  constructor(config) {
11
12
  if (typeof window !== "undefined" && !config.dangerouslyAllowBrowser) {
12
13
  throw new CharivoStateError(
@@ -16,18 +17,17 @@ var OpenClawLLMProvider = class {
16
17
  this.openai = new OpenAI({
17
18
  apiKey: config.token,
18
19
  baseURL: config.baseURL || "http://127.0.0.1:18789/v1",
19
- defaultHeaders: {
20
- "x-openclaw-agent-id": config.agentId || "main"
21
- },
20
+ defaultHeaders: config.agentId ? { "x-openclaw-agent-id": config.agentId } : void 0,
22
21
  dangerouslyAllowBrowser: config.dangerouslyAllowBrowser
23
22
  });
24
- this.model = config.model || "openclaw";
23
+ this.model = config.model || "openclaw/default";
25
24
  this.temperature = config.temperature ?? 0.7;
26
25
  this.maxTokens = config.maxTokens || 1e3;
26
+ this.sessionKey = config.sessionKey;
27
27
  }
28
28
  async generateResponse(messages) {
29
29
  try {
30
- const openAIMessages = messages.map((msg) => ({
30
+ const openAIMessages = this.selectMessages(messages).map((msg) => ({
31
31
  role: msg.role,
32
32
  content: msg.content
33
33
  }));
@@ -35,13 +35,28 @@ var OpenClawLLMProvider = class {
35
35
  model: this.model,
36
36
  messages: openAIMessages,
37
37
  temperature: this.temperature,
38
- max_tokens: this.maxTokens
38
+ max_tokens: this.maxTokens,
39
+ ...this.sessionKey ? { user: this.sessionKey } : {}
39
40
  });
40
41
  return completion.choices[0]?.message?.content || "";
41
42
  } catch (error) {
42
43
  throw toCharivoError("provider", error, "OpenClaw LLM request failed");
43
44
  }
44
45
  }
46
+ /**
47
+ * With a pinned session the gateway already holds the past turns, and resending
48
+ * them would flatten a duplicate copy of the history on top of its own. Keep the
49
+ * system prompts (cheap persona insurance if the session was dropped) and the
50
+ * latest turn.
51
+ */
52
+ selectMessages(messages) {
53
+ const latest = messages[messages.length - 1];
54
+ if (!this.sessionKey || !latest) {
55
+ return messages;
56
+ }
57
+ const systemMessages = messages.filter((msg) => msg.role === "system");
58
+ return latest.role === "system" ? systemMessages : [...systemMessages, latest];
59
+ }
45
60
  };
46
61
  function createOpenClawLLMProvider(config) {
47
62
  return new OpenClawLLMProvider(config);
@@ -51,8 +66,9 @@ function createOpenClawLLMProvider(config) {
51
66
  var OpenClawLLMClient = class {
52
67
  provider;
53
68
  constructor(config) {
69
+ const { sessionKey: _sessionKey, ...rest } = config;
54
70
  this.provider = createOpenClawLLMProvider({
55
- ...config,
71
+ ...rest,
56
72
  dangerouslyAllowBrowser: true
57
73
  });
58
74
  }
@@ -64,6 +80,6 @@ function createOpenClawLLMClient(config) {
64
80
  return new OpenClawLLMClient(config);
65
81
  }
66
82
 
67
- export { OpenClawLLMClient, createOpenClawLLMClient };
83
+ export { OpenClawLLMProvider, createOpenClawLLMClient, createOpenClawLLMProvider };
68
84
  //# sourceMappingURL=index.mjs.map
69
85
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/openclaw/provider.ts","../../src/openclaw/index.ts"],"names":[],"mappings":";;;;AAaO,IAAM,sBAAN,MAAiD;AAAA,EAC9C,MAAA;AAAA,EACA,KAAA;AAAA,EACA,WAAA;AAAA,EACA,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e,UAAA,EAAY,KAAA,EAAO,6BAA6B,CAAA;AAAA,IACvE;AAAA,EACF;AACF,CAAA;AAEO,SAAS,0BACd,MAAA,EACqB;AACrB,EAAA,OAAO,IAAI,oBAAoB,MAAM,CAAA;AACvC;;;ACjDO,IAAM,oBAAN,MAA6C;AAAA,EAC1C,QAAA;AAAA,EAER,YAAY,MAAA,EAAiC;AAG3C,IAAA,IAAA,CAAK,WAAW,yBAAA,CAA0B;AAAA,MACxC,GAAG,MAAA;AAAA,MACH,uBAAA,EAAyB;AAAA,KAC1B,CAAA;AAAA,EACH;AAAA,EAEA,MAAM,KACJ,QAAA,EACiB;AACjB,IAAA,OAAO,IAAA,CAAK,QAAA,CAAS,gBAAA,CAAiB,QAAQ,CAAA;AAAA,EAChD;AACF;AAEO,SAAS,wBACd,MAAA,EACmB;AACnB,EAAA,OAAO,IAAI,kBAAkB,MAAM,CAAA;AACrC","file":"index.mjs","sourcesContent":["import OpenAI from \"openai\";\nimport { CharivoStateError, LLMProvider, toCharivoError } from \"@charivo/core\";\n\nexport interface OpenClawLLMConfig {\n token: string;\n baseURL?: string;\n agentId?: string;\n model?: string;\n temperature?: number;\n maxTokens?: number;\n dangerouslyAllowBrowser?: boolean;\n}\n\nexport class OpenClawLLMProvider implements LLMProvider {\n private openai: OpenAI;\n private model: string;\n private temperature: number;\n private maxTokens: number;\n\n constructor(config: OpenClawLLMConfig) {\n if (typeof window !== \"undefined\" && !config.dangerouslyAllowBrowser) {\n throw new CharivoStateError(\n \"OpenClaw LLM provider is for server-side use only. Set dangerouslyAllowBrowser: true for testing\",\n );\n }\n\n this.openai = new OpenAI({\n apiKey: config.token,\n baseURL: config.baseURL || \"http://127.0.0.1:18789/v1\",\n defaultHeaders: {\n \"x-openclaw-agent-id\": config.agentId || \"main\",\n },\n dangerouslyAllowBrowser: config.dangerouslyAllowBrowser,\n });\n\n this.model = config.model || \"openclaw\";\n this.temperature = config.temperature ?? 0.7;\n this.maxTokens = config.maxTokens || 1000;\n }\n\n async generateResponse(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n try {\n const openAIMessages = messages.map((msg) => ({\n role: msg.role as \"system\" | \"user\" | \"assistant\",\n content: msg.content,\n }));\n\n const completion = await this.openai.chat.completions.create({\n model: this.model,\n messages: openAIMessages,\n temperature: this.temperature,\n max_tokens: this.maxTokens,\n });\n\n return completion.choices[0]?.message?.content || \"\";\n } catch (error) {\n throw toCharivoError(\"provider\", error, \"OpenClaw LLM request failed\");\n }\n }\n}\n\nexport function createOpenClawLLMProvider(\n config: OpenClawLLMConfig,\n): OpenClawLLMProvider {\n return new OpenClawLLMProvider(config);\n}\n","import { LLMClient } from \"@charivo/core\";\nimport {\n createOpenClawLLMProvider,\n OpenClawLLMConfig,\n OpenClawLLMProvider,\n} from \"./provider\";\n\n// OpenClawLLMConfig를 직접 사용\nexport type OpenClawLLMClientConfig = OpenClawLLMConfig;\n\n/**\n * OpenClaw LLM Client - OpenClaw provider를 래핑해서 클라이언트에서 직접 사용하는 Stateless 클라이언트\n *\n * 로컬 개발이나 테스트 환경에서 사용. 프로덕션에서는 보안상 권장하지 않음.\n * 토큰이 클라이언트에 노출되므로 서버 환경에서만 사용하거나 테스트용으로만 사용해야 함.\n *\n * Stateless 설계: 세션 관리는 외부에서 담당하고, 이 클라이언트는 API 호출만 담당\n */\nexport class OpenClawLLMClient implements LLMClient {\n private provider: OpenClawLLMProvider;\n\n constructor(config: OpenClawLLMClientConfig) {\n // Intentional dev/test escape hatch: this direct browser client exposes\n // credentials. For production, see docs/guide/choosing-packages.md#remote.\n this.provider = createOpenClawLLMProvider({\n ...config,\n dangerouslyAllowBrowser: true,\n });\n }\n\n async call(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n return this.provider.generateResponse(messages);\n }\n}\n\nexport function createOpenClawLLMClient(\n config: OpenClawLLMClientConfig,\n): OpenClawLLMClient {\n return new OpenClawLLMClient(config);\n}\n"]}
1
+ {"version":3,"sources":["../../src/openclaw/provider.ts","../../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AA,OAAO,IAAA,CAAK,QAAA,CAAS,gBAAA,CAAiB,QAAQ,CAAA;AAAA,EAChD;AACF,CAAA;AAEO,SAAS,wBACd,MAAA,EACW;AACX,EAAA,OAAO,IAAI,kBAAkB,MAAM,CAAA;AACrC","file":"index.mjs","sourcesContent":["import OpenAI from \"openai\";\nimport { CharivoStateError, LLMProvider, toCharivoError } from \"@charivo/core\";\n\nexport interface OpenClawLLMConfig {\n token: string;\n baseURL?: string;\n /**\n * Target a specific agent on the gateway.\n * When omitted, the gateway's configured default agent handles the request.\n */\n agentId?: string;\n /**\n * Agent target, not a backend model name. The gateway resolves this to an\n * agent: `openclaw`, `openclaw/default`, or `openclaw/<agentId>`.\n *\n * @default \"openclaw/default\"\n */\n model?: string;\n temperature?: number;\n maxTokens?: number;\n /**\n * Pins the conversation to a server-side session on the gateway.\n *\n * The gateway keeps conversation state itself, but without an identifier it\n * opens a fresh session per request: nothing is persisted between turns and\n * each one strands a throwaway session. Sending this as the `user` field makes\n * the gateway derive a stable session key from it.\n *\n * When set, past turns are not resent — the gateway already holds them. The\n * system prompt is still sent every turn so the persona survives a dropped\n * session.\n *\n * Treat it as a conversation-scoped identifier (e.g. a UUID per conversation,\n * rotated when the user resets the chat). Rotating it is the only way to reset\n * the conversation; the gateway keeps the old transcript under the old key.\n */\n sessionKey?: string;\n dangerouslyAllowBrowser?: boolean;\n}\n\nexport class OpenClawLLMProvider implements LLMProvider {\n private openai: OpenAI;\n private model: string;\n private temperature: number;\n private maxTokens: number;\n private sessionKey?: string;\n\n constructor(config: OpenClawLLMConfig) {\n if (typeof window !== \"undefined\" && !config.dangerouslyAllowBrowser) {\n throw new CharivoStateError(\n \"OpenClaw LLM provider is for server-side use only. Set dangerouslyAllowBrowser: true for testing\",\n );\n }\n\n this.openai = new OpenAI({\n apiKey: config.token,\n baseURL: config.baseURL || \"http://127.0.0.1:18789/v1\",\n defaultHeaders: config.agentId\n ? { \"x-openclaw-agent-id\": config.agentId }\n : undefined,\n dangerouslyAllowBrowser: config.dangerouslyAllowBrowser,\n });\n\n this.model = config.model || \"openclaw/default\";\n this.temperature = config.temperature ?? 0.7;\n this.maxTokens = config.maxTokens || 1000;\n this.sessionKey = config.sessionKey;\n }\n\n async generateResponse(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n try {\n const openAIMessages = this.selectMessages(messages).map((msg) => ({\n role: msg.role as \"system\" | \"user\" | \"assistant\",\n content: msg.content,\n }));\n\n const completion = await this.openai.chat.completions.create({\n model: this.model,\n messages: openAIMessages,\n temperature: this.temperature,\n max_tokens: this.maxTokens,\n ...(this.sessionKey ? { user: this.sessionKey } : {}),\n });\n\n return completion.choices[0]?.message?.content || \"\";\n } catch (error) {\n throw toCharivoError(\"provider\", error, \"OpenClaw LLM request failed\");\n }\n }\n\n /**\n * With a pinned session the gateway already holds the past turns, and resending\n * them would flatten a duplicate copy of the history on top of its own. Keep the\n * system prompts (cheap persona insurance if the session was dropped) and the\n * latest turn.\n */\n private selectMessages(\n messages: Array<{ role: string; content: string }>,\n ): Array<{ role: string; content: string }> {\n const latest = messages[messages.length - 1];\n if (!this.sessionKey || !latest) {\n return messages;\n }\n\n const systemMessages = messages.filter((msg) => msg.role === \"system\");\n return latest.role === \"system\"\n ? systemMessages\n : [...systemMessages, latest];\n }\n}\n\nexport function createOpenClawLLMProvider(\n config: OpenClawLLMConfig,\n): OpenClawLLMProvider {\n return new OpenClawLLMProvider(config);\n}\n","import type { LLMClient } from \"@charivo/core\";\nimport {\n createOpenClawLLMProvider,\n OpenClawLLMConfig,\n OpenClawLLMProvider,\n} from \"./provider\";\n\nexport {\n createOpenClawLLMProvider,\n OpenClawLLMProvider,\n type OpenClawLLMConfig,\n} from \"./provider\";\n\n// No `sessionKey` here, unlike the provider config. Pinning the gateway\n// session requires rotating it on reset, and this client is driven by\n// LLMManager, whose clearHistory()/character switch clear only local history and\n// cannot reach the client. A pinned session would survive that reset and silently\n// replay the old conversation. Server routes construct the provider themselves and\n// can rotate the key, so the option lives there instead.\nexport type OpenClawLLMClientConfig = Omit<OpenClawLLMConfig, \"sessionKey\">;\n\n/**\n * OpenClaw LLM Client - Stateless client that wraps the OpenClaw provider for direct use on the client\n *\n * For use in local development or test environments. Not recommended for production for security reasons.\n * The token is exposed to the client, so use it only in a server environment or for testing purposes.\n *\n * Stateless design: session management is handled externally, and this client only handles API calls\n */\nclass OpenClawLLMClient implements LLMClient {\n private provider: OpenClawLLMProvider;\n\n constructor(config: OpenClawLLMClientConfig) {\n // Strip sessionKey at runtime too: an untyped JS caller can bypass the\n // Omit above and pass it anyway.\n const { sessionKey: _sessionKey, ...rest } = config as OpenClawLLMConfig;\n\n // Intentional dev/test escape hatch: this direct browser client exposes\n // credentials. For production, see docs/guide/choosing-packages.md#remote.\n this.provider = createOpenClawLLMProvider({\n ...rest,\n dangerouslyAllowBrowser: true,\n });\n }\n\n async call(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n return this.provider.generateResponse(messages);\n }\n}\n\nexport function createOpenClawLLMClient(\n config: OpenClawLLMClientConfig,\n): LLMClient {\n return new OpenClawLLMClient(config);\n}\n"]}
@@ -3,17 +3,6 @@ import { LLMClient } from '@charivo/core';
3
3
  interface RemoteLLMConfig {
4
4
  apiEndpoint?: string;
5
5
  }
6
- /**
7
- * Remote LLM Client - 서버 API를 호출하는 stateless 클라이언트
8
- */
9
- declare class RemoteLLMClient implements LLMClient {
10
- private apiEndpoint;
11
- constructor(config?: RemoteLLMConfig);
12
- call(messages: Array<{
13
- role: string;
14
- content: string;
15
- }>): Promise<string>;
16
- }
17
- declare function createRemoteLLMClient(config?: RemoteLLMConfig): RemoteLLMClient;
6
+ declare function createRemoteLLMClient(config?: RemoteLLMConfig): LLMClient;
18
7
 
19
- export { RemoteLLMClient, type RemoteLLMConfig, createRemoteLLMClient };
8
+ export { type RemoteLLMConfig, createRemoteLLMClient };
@@ -3,17 +3,6 @@ import { LLMClient } from '@charivo/core';
3
3
  interface RemoteLLMConfig {
4
4
  apiEndpoint?: string;
5
5
  }
6
- /**
7
- * Remote LLM Client - 서버 API를 호출하는 stateless 클라이언트
8
- */
9
- declare class RemoteLLMClient implements LLMClient {
10
- private apiEndpoint;
11
- constructor(config?: RemoteLLMConfig);
12
- call(messages: Array<{
13
- role: string;
14
- content: string;
15
- }>): Promise<string>;
16
- }
17
- declare function createRemoteLLMClient(config?: RemoteLLMConfig): RemoteLLMClient;
6
+ declare function createRemoteLLMClient(config?: RemoteLLMConfig): LLMClient;
18
7
 
19
- export { RemoteLLMClient, type RemoteLLMConfig, createRemoteLLMClient };
8
+ export { type RemoteLLMConfig, createRemoteLLMClient };
@@ -64,7 +64,6 @@ function isAbortError(error) {
64
64
  return error instanceof DOMException && error.name === "AbortError" || error instanceof Error && error.name === "AbortError";
65
65
  }
66
66
 
67
- exports.RemoteLLMClient = RemoteLLMClient;
68
67
  exports.createRemoteLLMClient = createRemoteLLMClient;
69
68
  //# sourceMappingURL=index.js.map
70
69
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/remote/index.ts"],"names":["CharivoProviderError","CharivoTimeoutError","CharivoTransportError"],"mappings":";;;;;AAWA,IAAM,kBAAA,GAAqB,GAAA;AAKpB,IAAM,kBAAN,MAA2C;AAAA,EACxC,WAAA;AAAA,EAER,WAAA,CAAY,MAAA,GAA0B,EAAC,EAAG;AACxC,IAAA,IAAA,CAAK,WAAA,GAAc,OAAO,WAAA,IAAe,WAAA;AAAA,EAC3C;AAAA,EAEA,MAAM,KACJ,QAAA,EACiB;AACjB,IAAA,MAAM,WAAW,MAAM,gBAAA;AAAA,MACrB,IAAA,CAAK,WAAA;AAAA,MACL;AAAA,QACE,MAAA,EAAQ,MAAA;AAAA,QACR,OAAA,EAAS;AAAA,UACP,cAAA,EAAgB;AAAA,SAClB;AAAA,QACA,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,UACnB;AAAA,SACD;AAAA,OACH;AAAA,MACA,+BAA+B,kBAAkB,CAAA,EAAA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A,GAAQ;AAAA,KACzC,CAAA;AAAA,EACH,CAAA,SAAE;AACA,IAAA,YAAA,CAAa,SAAS,CAAA;AAAA,EACxB;AACF;AAEA,SAAS,aAAa,KAAA,EAAyB;AAC7C,EAAA,OACG,KAAA,YAAiB,gBAAgB,KAAA,CAAM,IAAA,KAAS,gBAChD,KAAA,YAAiB,KAAA,IAAS,MAAM,IAAA,KAAS,YAAA;AAE9C","file":"index.js","sourcesContent":["import {\n CharivoProviderError,\n CharivoTimeoutError,\n CharivoTransportError,\n type LLMClient,\n} from \"@charivo/core\";\n\nexport interface RemoteLLMConfig {\n apiEndpoint?: string;\n}\n\nconst REQUEST_TIMEOUT_MS = 30_000;\n\n/**\n * Remote LLM Client - 서버 API를 호출하는 stateless 클라이언트\n */\nexport class RemoteLLMClient implements LLMClient {\n private apiEndpoint: string;\n\n constructor(config: RemoteLLMConfig = {}) {\n this.apiEndpoint = config.apiEndpoint || \"/api/chat\";\n }\n\n async call(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n const response = await fetchWithTimeout(\n this.apiEndpoint,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n messages,\n }),\n },\n `LLM request timed out after ${REQUEST_TIMEOUT_MS}ms`,\n );\n\n if (!response.ok) {\n const errorData = await response\n .json()\n .catch(() => ({ error: \"Unknown error\" }));\n throw new CharivoProviderError(\n `API call failed: ${errorData.error || response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n if (!data.success) {\n throw new CharivoProviderError(\n data.error || \"Failed to generate response\",\n );\n }\n\n return data.message || \"\";\n }\n}\n\nexport function createRemoteLLMClient(\n config?: RemoteLLMConfig,\n): RemoteLLMClient {\n return new RemoteLLMClient(config);\n}\n\nasync function fetchWithTimeout(\n input: RequestInfo | URL,\n init: RequestInit,\n timeoutMessage: string,\n): Promise<Response> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);\n\n try {\n return await fetch(input, {\n ...init,\n signal: controller.signal,\n });\n } catch (error) {\n if (isAbortError(error)) {\n throw new CharivoTimeoutError(timeoutMessage, { cause: error });\n }\n throw new CharivoTransportError(\"LLM request failed\", {\n cause: error instanceof Error ? error : undefined,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n}\n\nfunction isAbortError(error: unknown): boolean {\n return (\n (error instanceof DOMException && error.name === \"AbortError\") ||\n (error instanceof Error && error.name === \"AbortError\")\n );\n}\n"]}
1
+ {"version":3,"sources":["../../src/remote/index.ts"],"names":["CharivoProviderError","CharivoTimeoutError","CharivoTransportError"],"mappings":";;;;;AAWA,IAAM,kBAAA,GAAqB,GAAA;AAK3B,IAAM,kBAAN,MAA2C;AAAA,EACjC,WAAA;AAAA,EAER,WAAA,CAAY,MAAA,GAA0B,EAAC,EAAG;AACxC,IAAA,IAAA,CAAK,WAAA,GAAc,OAAO,WAAA,IAAe,WAAA;AAAA,EAC3C;AAAA,EAEA,MAAM,KACJ,QAAA,EACiB;AACjB,IAAA,MAAM,WAAW,MAAM,gBAAA;AAAA,MACrB,IAAA,CAAK,WAAA;AAAA,MACL;AAAA,QACE,MAAA,EAAQ,MAAA;AAAA,QACR,OAAA,EAAS;AAAA,UACP,cAAA,EAAgB;AAAA,SAClB;AAAA,QACA,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,UACnB;AAAA,SACD;AAAA,OACH;AAAA,MACA,+BAA+B,kBAAkB,CAAA,EAAA;AAAA,KACnD;AAEA,IAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,MAAA,MAAM,SAAA,GAAY,MAAM,QAAA,CACrB,IAAA,EAAK,CACL,MAAM,OAAO,EAAE,KAAA,EAAO,eAAA,EAAgB,CAAE,CAAA;AAC3C,MAAA,MAAM,IAAIA,yBAAA;AAAA,QACR,CAAA,iBAAA,EAAoB,SAAA,CAAU,KAAA,IAAS,QAAA,CAAS,UAAU,CAAA;AAAA,OAC5D;AAAA,IACF;AAEA,IAAA,MAAM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portError,\n type LLMClient,\n} from \"@charivo/core\";\n\nexport interface RemoteLLMConfig {\n apiEndpoint?: string;\n}\n\nconst REQUEST_TIMEOUT_MS = 30_000;\n\n/**\n * Remote LLM Client - stateless client that calls the server API\n */\nclass RemoteLLMClient implements LLMClient {\n private apiEndpoint: string;\n\n constructor(config: RemoteLLMConfig = {}) {\n this.apiEndpoint = config.apiEndpoint || \"/api/chat\";\n }\n\n async call(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n const response = await fetchWithTimeout(\n this.apiEndpoint,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n messages,\n }),\n },\n `LLM request timed out after ${REQUEST_TIMEOUT_MS}ms`,\n );\n\n if (!response.ok) {\n const errorData = await response\n .json()\n .catch(() => ({ error: \"Unknown error\" }));\n throw new CharivoProviderError(\n `API call failed: ${errorData.error || response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n if (!data.success) {\n throw new CharivoProviderError(\n data.error || \"Failed to generate response\",\n );\n }\n\n return data.message || \"\";\n }\n}\n\nexport function createRemoteLLMClient(config?: RemoteLLMConfig): LLMClient {\n return new RemoteLLMClient(config);\n}\n\nasync function fetchWithTimeout(\n input: RequestInfo | URL,\n init: RequestInit,\n timeoutMessage: string,\n): Promise<Response> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);\n\n try {\n return await fetch(input, {\n ...init,\n signal: controller.signal,\n });\n } catch (error) {\n if (isAbortError(error)) {\n throw new CharivoTimeoutError(timeoutMessage, { cause: error });\n }\n throw new CharivoTransportError(\"LLM request failed\", {\n cause: error instanceof Error ? error : undefined,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n}\n\nfunction isAbortError(error: unknown): boolean {\n return (\n (error instanceof DOMException && error.name === \"AbortError\") ||\n (error instanceof Error && error.name === \"AbortError\")\n );\n}\n"]}
@@ -62,6 +62,6 @@ function isAbortError(error) {
62
62
  return error instanceof DOMException && error.name === "AbortError" || error instanceof Error && error.name === "AbortError";
63
63
  }
64
64
 
65
- export { RemoteLLMClient, createRemoteLLMClient };
65
+ export { createRemoteLLMClient };
66
66
  //# sourceMappingURL=index.mjs.map
67
67
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/remote/index.ts"],"names":[],"mappings":";;;AAWA,IAAM,kBAAA,GAAqB,GAAA;AAKpB,IAAM,kBAAN,MAA2C;AAAA,EACxC,WAAA;AAAA,EAER,WAAA,CAAY,MAAA,GAA0B,EAAC,EAAG;AACxC,IAAA,IAAA,CAAK,WAAA,GAAc,OAAO,WAAA,IAAe,WAAA;AAAA,EAC3C;AAAA,EAEA,MAAM,KACJ,QAAA,EACiB;AACjB,IAAA,MAAM,WAAW,MAAM,gBAAA;AAAA,MACrB,IAAA,CAAK,WAAA;AAAA,MACL;AAAA,QACE,MAAA,EAAQ,MAAA;AAAA,QACR,OAAA,EAAS;AAAA,UACP,cAAA,EAAgB;AAAA,SAClB;AAAA,QACA,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,UACnB;AAAA,SACD;AAAA,OACH;AAAA,MACA,+BAA+B,kBAAkB,CAAA,EAAA;AAAA,KACnD;AAEA,IAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,MAAA,MAAM,SAAA,GAAY,MAAM,QAAA,CACrB,IAAA,EAAK,CACL,MAAM,OAAO,EAAE,KAAA,EAAO,eAAA,EAAgB,CAAE,CAAA;AAC3C,MAAA,MAAM,IAAI,oBAAA;AAAA,QACR,CAAA,iBAAA,EAAoB,SAAA,CAAU,KAAA,IAAS,QAAA,CAAS,UAAU,CAAA;AAAA,OAC5D;AAAA,IACF;AAEA,IAAA,MAAM,IAAA,GAAO,MAAM,QAAA,CAAS,IAAA,EAAK;AAEjC,IAAA,IAAI,CAAC,KAAK,OAAA,EAAS;AACjB,MAAA,MAAM,IAAI,oBAAA;AAAA,QACR,KAAK,KAAA,IAAS;AAAA,OAChB;AAAA,IACF;AAEA,IAAA,OAAO,KAAK,OAAA,IAAW,EAAA;AAAA,EACzB;AACF;AAEO,SAAS,sBACd,MAAA,EACiB;AACjB,EAAA,OAAO,IAAI,gBAAgB,MAAM,CAAA;AACnC;AAEA,eAAe,gBAAA,CACb,KAAA,EACA,IAAA,EACA,cAAA,EACmB;AACnB,EAAA,MAAM,UAAA,GAAa,IAAI,eAAA,EAAgB;AACvC,EAAA,MAAM,YAAY,UAAA,CAAW,MAAM,UAAA,CAAW,KAAA,IAAS,kBAAkB,CAAA;AAEzE,EAAA,IAAI;AACF,IAAA,OAAO,MAAM,MAAM,KAAA,EAAO;AAAA,MACxB,GAAG,IAAA;AAAA,MACH,QAAQ,UAAA,CAAW;AAAA,KACpB,CAAA;AAAA,EACH,SAAS,KAAA,EAAO;AACd,IAAA,IAAI,YAAA,CAAa,KAAK,CAAA,EAAG;AACvB,MAAA,MAAM,IAAI,mBAAA,CAAoB,cAAA,EAAgB,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,IAChE;AACA,IAAA,MAAM,IAAI,sBAAsB,oBAAA,EAAsB;AAAA,MACpD,KAAA,EAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,GAAQ;AAAA,KACzC,CAAA;AAAA,EACH,CAAA,SAAE;AACA,IAAA,YAAA,CAAa,SAAS,CAAA;AAAA,EACxB;AACF;AAEA,SAAS,aAAa,KAAA,EAAyB;AAC7C,EAAA,OACG,KAAA,YAAiB,gBAAgB,KAAA,CAAM,IAAA,KAAS,gBAChD,KAAA,YAAiB,KAAA,IAAS,MAAM,IAAA,KAAS,YAAA;AAE9C","file":"index.mjs","sourcesContent":["import {\n CharivoProviderError,\n CharivoTimeoutError,\n CharivoTransportError,\n type LLMClient,\n} from \"@charivo/core\";\n\nexport interface RemoteLLMConfig {\n apiEndpoint?: string;\n}\n\nconst REQUEST_TIMEOUT_MS = 30_000;\n\n/**\n * Remote LLM Client - 서버 API를 호출하는 stateless 클라이언트\n */\nexport class RemoteLLMClient implements LLMClient {\n private apiEndpoint: string;\n\n constructor(config: RemoteLLMConfig = {}) {\n this.apiEndpoint = config.apiEndpoint || \"/api/chat\";\n }\n\n async call(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n const response = await fetchWithTimeout(\n this.apiEndpoint,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n messages,\n }),\n },\n `LLM request timed out after ${REQUEST_TIMEOUT_MS}ms`,\n );\n\n if (!response.ok) {\n const errorData = await response\n .json()\n .catch(() => ({ error: \"Unknown error\" }));\n throw new CharivoProviderError(\n `API call failed: ${errorData.error || response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n if (!data.success) {\n throw new CharivoProviderError(\n data.error || \"Failed to generate response\",\n );\n }\n\n return data.message || \"\";\n }\n}\n\nexport function createRemoteLLMClient(\n config?: RemoteLLMConfig,\n): RemoteLLMClient {\n return new RemoteLLMClient(config);\n}\n\nasync function fetchWithTimeout(\n input: RequestInfo | URL,\n init: RequestInit,\n timeoutMessage: string,\n): Promise<Response> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);\n\n try {\n return await fetch(input, {\n ...init,\n signal: controller.signal,\n });\n } catch (error) {\n if (isAbortError(error)) {\n throw new CharivoTimeoutError(timeoutMessage, { cause: error });\n }\n throw new CharivoTransportError(\"LLM request failed\", {\n cause: error instanceof Error ? error : undefined,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n}\n\nfunction isAbortError(error: unknown): boolean {\n return (\n (error instanceof DOMException && error.name === \"AbortError\") ||\n (error instanceof Error && error.name === \"AbortError\")\n );\n}\n"]}
1
+ {"version":3,"sources":["../../src/remote/index.ts"],"names":[],"mappings":";;;AAWA,IAAM,kBAAA,GAAqB,GAAA;AAK3B,IAAM,kBAAN,MAA2C;AAAA,EACjC,WAAA;AAAA,EAER,WAAA,CAAY,MAAA,GAA0B,EAAC,EAAG;AACxC,IAAA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;AACF,IAAA,OAAO,MAAM,MAAM,KAAA,EAAO;AAAA,MACxB,GAAG,IAAA;AAAA,MACH,QAAQ,UAAA,CAAW;AAAA,KACpB,CAAA;AAAA,EACH,SAAS,KAAA,EAAO;AACd,IAAA,IAAI,YAAA,CAAa,KAAK,CAAA,EAAG;AACvB,MAAA,MAAM,IAAI,mBAAA,CAAoB,cAAA,EAAgB,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,IAChE;AACA,IAAA,MAAM,IAAI,sBAAsB,oBAAA,EAAsB;AAAA,MACpD,KAAA,EAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,GAAQ;AAAA,KACzC,CAAA;AAAA,EACH,CAAA,SAAE;AACA,IAAA,YAAA,CAAa,SAAS,CAAA;AAAA,EACxB;AACF;AAEA,SAAS,aAAa,KAAA,EAAyB;AAC7C,EAAA,OACG,KAAA,YAAiB,gBAAgB,KAAA,CAAM,IAAA,KAAS,gBAChD,KAAA,YAAiB,KAAA,IAAS,MAAM,IAAA,KAAS,YAAA;AAE9C","file":"index.mjs","sourcesContent":["import {\n CharivoProviderError,\n CharivoTimeoutError,\n CharivoTransportError,\n type LLMClient,\n} from \"@charivo/core\";\n\nexport interface RemoteLLMConfig {\n apiEndpoint?: string;\n}\n\nconst REQUEST_TIMEOUT_MS = 30_000;\n\n/**\n * Remote LLM Client - stateless client that calls the server API\n */\nclass RemoteLLMClient implements LLMClient {\n private apiEndpoint: string;\n\n constructor(config: RemoteLLMConfig = {}) {\n this.apiEndpoint = config.apiEndpoint || \"/api/chat\";\n }\n\n async call(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n const response = await fetchWithTimeout(\n this.apiEndpoint,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n messages,\n }),\n },\n `LLM request timed out after ${REQUEST_TIMEOUT_MS}ms`,\n );\n\n if (!response.ok) {\n const errorData = await response\n .json()\n .catch(() => ({ error: \"Unknown error\" }));\n throw new CharivoProviderError(\n `API call failed: ${errorData.error || response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n if (!data.success) {\n throw new CharivoProviderError(\n data.error || \"Failed to generate response\",\n );\n }\n\n return data.message || \"\";\n }\n}\n\nexport function createRemoteLLMClient(config?: RemoteLLMConfig): LLMClient {\n return new RemoteLLMClient(config);\n}\n\nasync function fetchWithTimeout(\n input: RequestInfo | URL,\n init: RequestInit,\n timeoutMessage: string,\n): Promise<Response> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);\n\n try {\n return await fetch(input, {\n ...init,\n signal: controller.signal,\n });\n } catch (error) {\n if (isAbortError(error)) {\n throw new CharivoTimeoutError(timeoutMessage, { cause: error });\n }\n throw new CharivoTransportError(\"LLM request failed\", {\n cause: error instanceof Error ? error : undefined,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n}\n\nfunction isAbortError(error: unknown): boolean {\n return (\n (error instanceof DOMException && error.name === \"AbortError\") ||\n (error instanceof Error && error.name === \"AbortError\")\n );\n}\n"]}
@@ -1,19 +1,5 @@
1
1
  import { LLMClient } from '@charivo/core';
2
2
 
3
- /**
4
- * Stub LLM Client - Stateless client for testing
5
- *
6
- * Returns predefined responses in rotation without making real API calls
7
- * Used in development and testing environments
8
- */
9
- declare class StubLLMClient implements LLMClient {
10
- private responses;
11
- private responseIndex;
12
- call(_messages: Array<{
13
- role: string;
14
- content: string;
15
- }>): Promise<string>;
16
- }
17
- declare function createStubLLMClient(): StubLLMClient;
3
+ declare function createStubLLMClient(): LLMClient;
18
4
 
19
- export { StubLLMClient, createStubLLMClient };
5
+ export { createStubLLMClient };
@@ -1,19 +1,5 @@
1
1
  import { LLMClient } from '@charivo/core';
2
2
 
3
- /**
4
- * Stub LLM Client - Stateless client for testing
5
- *
6
- * Returns predefined responses in rotation without making real API calls
7
- * Used in development and testing environments
8
- */
9
- declare class StubLLMClient implements LLMClient {
10
- private responses;
11
- private responseIndex;
12
- call(_messages: Array<{
13
- role: string;
14
- content: string;
15
- }>): Promise<string>;
16
- }
17
- declare function createStubLLMClient(): StubLLMClient;
3
+ declare function createStubLLMClient(): LLMClient;
18
4
 
19
- export { StubLLMClient, createStubLLMClient };
5
+ export { createStubLLMClient };
@@ -28,7 +28,6 @@ function createStubLLMClient() {
28
28
  return new StubLLMClient();
29
29
  }
30
30
 
31
- exports.StubLLMClient = StubLLMClient;
32
31
  exports.createStubLLMClient = createStubLLMClient;
33
32
  //# sourceMappingURL=index.js.map
34
33
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stub/index.ts"],"names":[],"mappings":";;;AAQO,IAAM,gBAAN,MAAyC;AAAA,EACtC,SAAA,GAAsB;AAAA,IAC5B,8BAAA;AAAA,IACA,mCAAA;AAAA,IACA,qBAAA;AAAA,IACA,yDAAA;AAAA,IACA,kBAAA;AAAA,IACA,qCAAA;AAAA,IACA,iBAAA;AAAA,IACA,qCAAA;AAAA,IACA,kCAAA;AAAA,IACA,gBAAA;AAAA,IACA,sBAAA;AAAA,IACA;AAAA,GACF;AAAA,EAEQ,aAAA,GAAgB,CAAA;AAAA,EAExB,MAAM,KACJ,SAAA,EACiB;AAEjB,IAAA,MAAM,IAAI,OAAA,CAAQ,CAAC,YAAY,UAAA,CAAW,OAAA,EAAS,GAAG,CAAC,CAAA;AAEvD,IAAA,MAAM,WAAW,IAAA,CAAK,SAAA,CAAU,KAAK,aAAA,GAAgB,IAAA,CAAK,UAAU,MAAM,CAAA;AAC1E,IAAA,IAAA,CAAK,aAAA,EAAA;AAEL,IAAA,OAAO,QAAA;AAAA,EACT;AACF;AAEO,SAAS,mBAAA,GAAqC;AACnD,EAAA,OAAO,IAAI,aAAA,EAAc;AAC3B","file":"index.js","sourcesContent":["import { LLMClient } from \"@charivo/core\";\n\n/**\n * Stub LLM Client - Stateless client for testing\n *\n * Returns predefined responses in rotation without making real API calls\n * Used in development and testing environments\n */\nexport class StubLLMClient implements LLMClient {\n private responses: string[] = [\n \"Hello! I'm a test character.\",\n \"The weather is really nice today!\",\n \"How can I help you?\",\n \"That's an interesting question. Could you tell me more?\",\n \"Yes, understood!\",\n \"I see. That's an interesting story.\",\n \"I think so too.\",\n \"Hmm... that's a difficult question.\",\n \"Oh no... I'm sorry to hear that.\",\n \"What?! Really?\",\n \"That makes me upset.\",\n \"I'm a bit embarrassed...\",\n ];\n\n private responseIndex = 0;\n\n async call(\n _messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n // 실제 API 호출을 시뮬레이션하기 위한 딜레이\n await new Promise((resolve) => setTimeout(resolve, 500));\n\n const response = this.responses[this.responseIndex % this.responses.length];\n this.responseIndex++;\n\n return response;\n }\n}\n\nexport function createStubLLMClient(): StubLLMClient {\n return new StubLLMClient();\n}\n"]}
1
+ {"version":3,"sources":["../../src/stub/index.ts"],"names":[],"mappings":";;;AAQA,IAAM,gBAAN,MAAyC;AAAA,EAC/B,SAAA,GAAsB;AAAA,IAC5B,8BAAA;AAAA,IACA,mCAAA;AAAA,IACA,qBAAA;AAAA,IACA,yDAAA;AAAA,IACA,kBAAA;AAAA,IACA,qCAAA;AAAA,IACA,iBAAA;AAAA,IACA,qCAAA;AAAA,IACA,kCAAA;AAAA,IACA,gBAAA;AAAA,IACA,sBAAA;AAAA,IACA;AAAA,GACF;AAAA,EAEQ,aAAA,GAAgB,CAAA;AAAA,EAExB,MAAM,KACJ,SAAA,EACiB;AAEjB,IAAA,MAAM,IAAI,OAAA,CAAQ,CAAC,YAAY,UAAA,CAAW,OAAA,EAAS,GAAG,CAAC,CAAA;AAEvD,IAAA,MAAM,WAAW,IAAA,CAAK,SAAA,CAAU,KAAK,aAAA,GAAgB,IAAA,CAAK,UAAU,MAAM,CAAA;AAC1E,IAAA,IAAA,CAAK,aAAA,EAAA;AAEL,IAAA,OAAO,QAAA;AAAA,EACT;AACF,CAAA;AAEO,SAAS,mBAAA,GAAiC;AAC/C,EAAA,OAAO,IAAI,aAAA,EAAc;AAC3B","file":"index.js","sourcesContent":["import type { LLMClient } from \"@charivo/core\";\n\n/**\n * Stub LLM Client - Stateless client for testing\n *\n * Returns predefined responses in rotation without making real API calls\n * Used in development and testing environments\n */\nclass StubLLMClient implements LLMClient {\n private responses: string[] = [\n \"Hello! I'm a test character.\",\n \"The weather is really nice today!\",\n \"How can I help you?\",\n \"That's an interesting question. Could you tell me more?\",\n \"Yes, understood!\",\n \"I see. That's an interesting story.\",\n \"I think so too.\",\n \"Hmm... that's a difficult question.\",\n \"Oh no... I'm sorry to hear that.\",\n \"What?! Really?\",\n \"That makes me upset.\",\n \"I'm a bit embarrassed...\",\n ];\n\n private responseIndex = 0;\n\n async call(\n _messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n // Delay to simulate a real API call\n await new Promise((resolve) => setTimeout(resolve, 500));\n\n const response = this.responses[this.responseIndex % this.responses.length];\n this.responseIndex++;\n\n return response;\n }\n}\n\nexport function createStubLLMClient(): LLMClient {\n return new StubLLMClient();\n}\n"]}
@@ -26,6 +26,6 @@ function createStubLLMClient() {
26
26
  return new StubLLMClient();
27
27
  }
28
28
 
29
- export { StubLLMClient, createStubLLMClient };
29
+ export { createStubLLMClient };
30
30
  //# sourceMappingURL=index.mjs.map
31
31
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stub/index.ts"],"names":[],"mappings":";AAQO,IAAM,gBAAN,MAAyC;AAAA,EACtC,SAAA,GAAsB;AAAA,IAC5B,8BAAA;AAAA,IACA,mCAAA;AAAA,IACA,qBAAA;AAAA,IACA,yDAAA;AAAA,IACA,kBAAA;AAAA,IACA,qCAAA;AAAA,IACA,iBAAA;AAAA,IACA,qCAAA;AAAA,IACA,kCAAA;AAAA,IACA,gBAAA;AAAA,IACA,sBAAA;AAAA,IACA;AAAA,GACF;AAAA,EAEQ,aAAA,GAAgB,CAAA;AAAA,EAExB,MAAM,KACJ,SAAA,EACiB;AAEjB,IAAA,MAAM,IAAI,OAAA,CAAQ,CAAC,YAAY,UAAA,CAAW,OAAA,EAAS,GAAG,CAAC,CAAA;AAEvD,IAAA,MAAM,WAAW,IAAA,CAAK,SAAA,CAAU,KAAK,aAAA,GAAgB,IAAA,CAAK,UAAU,MAAM,CAAA;AAC1E,IAAA,IAAA,CAAK,aAAA,EAAA;AAEL,IAAA,OAAO,QAAA;AAAA,EACT;AACF;AAEO,SAAS,mBAAA,GAAqC;AACnD,EAAA,OAAO,IAAI,aAAA,EAAc;AAC3B","file":"index.mjs","sourcesContent":["import { LLMClient } from \"@charivo/core\";\n\n/**\n * Stub LLM Client - Stateless client for testing\n *\n * Returns predefined responses in rotation without making real API calls\n * Used in development and testing environments\n */\nexport class StubLLMClient implements LLMClient {\n private responses: string[] = [\n \"Hello! I'm a test character.\",\n \"The weather is really nice today!\",\n \"How can I help you?\",\n \"That's an interesting question. Could you tell me more?\",\n \"Yes, understood!\",\n \"I see. That's an interesting story.\",\n \"I think so too.\",\n \"Hmm... that's a difficult question.\",\n \"Oh no... I'm sorry to hear that.\",\n \"What?! Really?\",\n \"That makes me upset.\",\n \"I'm a bit embarrassed...\",\n ];\n\n private responseIndex = 0;\n\n async call(\n _messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n // 실제 API 호출을 시뮬레이션하기 위한 딜레이\n await new Promise((resolve) => setTimeout(resolve, 500));\n\n const response = this.responses[this.responseIndex % this.responses.length];\n this.responseIndex++;\n\n return response;\n }\n}\n\nexport function createStubLLMClient(): StubLLMClient {\n return new StubLLMClient();\n}\n"]}
1
+ {"version":3,"sources":["../../src/stub/index.ts"],"names":[],"mappings":";AAQA,IAAM,gBAAN,MAAyC;AAAA,EAC/B,SAAA,GAAsB;AAAA,IAC5B,8BAAA;AAAA,IACA,mCAAA;AAAA,IACA,qBAAA;AAAA,IACA,yDAAA;AAAA,IACA,kBAAA;AAAA,IACA,qCAAA;AAAA,IACA,iBAAA;AAAA,IACA,qCAAA;AAAA,IACA,kCAAA;AAAA,IACA,gBAAA;AAAA,IACA,sBAAA;AAAA,IACA;AAAA,GACF;AAAA,EAEQ,aAAA,GAAgB,CAAA;AAAA,EAExB,MAAM,KACJ,SAAA,EACiB;AAEjB,IAAA,MAAM,IAAI,OAAA,CAAQ,CAAC,YAAY,UAAA,CAAW,OAAA,EAAS,GAAG,CAAC,CAAA;AAEvD,IAAA,MAAM,WAAW,IAAA,CAAK,SAAA,CAAU,KAAK,aAAA,GAAgB,IAAA,CAAK,UAAU,MAAM,CAAA;AAC1E,IAAA,IAAA,CAAK,aAAA,EAAA;AAEL,IAAA,OAAO,QAAA;AAAA,EACT;AACF,CAAA;AAEO,SAAS,mBAAA,GAAiC;AAC/C,EAAA,OAAO,IAAI,aAAA,EAAc;AAC3B","file":"index.mjs","sourcesContent":["import type { LLMClient } from \"@charivo/core\";\n\n/**\n * Stub LLM Client - Stateless client for testing\n *\n * Returns predefined responses in rotation without making real API calls\n * Used in development and testing environments\n */\nclass StubLLMClient implements LLMClient {\n private responses: string[] = [\n \"Hello! I'm a test character.\",\n \"The weather is really nice today!\",\n \"How can I help you?\",\n \"That's an interesting question. Could you tell me more?\",\n \"Yes, understood!\",\n \"I see. That's an interesting story.\",\n \"I think so too.\",\n \"Hmm... that's a difficult question.\",\n \"Oh no... I'm sorry to hear that.\",\n \"What?! Really?\",\n \"That makes me upset.\",\n \"I'm a bit embarrassed...\",\n ];\n\n private responseIndex = 0;\n\n async call(\n _messages: Array<{ role: string; content: string }>,\n ): Promise<string> {\n // Delay to simulate a real API call\n await new Promise((resolve) => setTimeout(resolve, 500));\n\n const response = this.responses[this.responseIndex % this.responses.length];\n this.responseIndex++;\n\n return response;\n }\n}\n\nexport function createStubLLMClient(): LLMClient {\n return new StubLLMClient();\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charivo/llm",
3
- "version": "0.4.3",
3
+ "version": "0.6.0",
4
4
  "description": "LLM manager and browser adapters for Charivo",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",