@charivo/llm 0.2.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.
@@ -0,0 +1,61 @@
1
+ // src/remote/index.ts
2
+ var REQUEST_TIMEOUT_MS = 3e4;
3
+ var RemoteLLMClient = class {
4
+ apiEndpoint;
5
+ constructor(config = {}) {
6
+ this.apiEndpoint = config.apiEndpoint || "/api/chat";
7
+ }
8
+ async call(messages) {
9
+ const response = await fetchWithTimeout(
10
+ this.apiEndpoint,
11
+ {
12
+ method: "POST",
13
+ headers: {
14
+ "Content-Type": "application/json"
15
+ },
16
+ body: JSON.stringify({
17
+ messages
18
+ })
19
+ },
20
+ `LLM request timed out after ${REQUEST_TIMEOUT_MS}ms`
21
+ );
22
+ if (!response.ok) {
23
+ const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
24
+ throw new Error(
25
+ `API call failed: ${errorData.error || response.statusText}`
26
+ );
27
+ }
28
+ const data = await response.json();
29
+ if (!data.success) {
30
+ throw new Error(data.error || "Failed to generate response");
31
+ }
32
+ return data.message || "";
33
+ }
34
+ };
35
+ function createRemoteLLMClient(config) {
36
+ return new RemoteLLMClient(config);
37
+ }
38
+ async function fetchWithTimeout(input, init, timeoutMessage) {
39
+ const controller = new AbortController();
40
+ const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
41
+ try {
42
+ return await fetch(input, {
43
+ ...init,
44
+ signal: controller.signal
45
+ });
46
+ } catch (error) {
47
+ if (isAbortError(error)) {
48
+ throw new Error(timeoutMessage);
49
+ }
50
+ throw error;
51
+ } finally {
52
+ clearTimeout(timeoutId);
53
+ }
54
+ }
55
+ function isAbortError(error) {
56
+ return error instanceof DOMException && error.name === "AbortError" || error instanceof Error && error.name === "AbortError";
57
+ }
58
+
59
+ export { RemoteLLMClient, createRemoteLLMClient };
60
+ //# sourceMappingURL=index.mjs.map
61
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version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AAA,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,MAAM,cAAc,CAAA;AAAA,IAChC;AACA,IAAA,MAAM,KAAA;AAAA,EACR,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 type { LLMClient } 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 Error(\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 Error(data.error || \"Failed to generate response\");\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 Error(timeoutMessage);\n }\n throw error;\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"]}
@@ -0,0 +1,19 @@
1
+ import { LLMClient } from '@charivo/core';
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;
18
+
19
+ export { StubLLMClient, createStubLLMClient };
@@ -0,0 +1,19 @@
1
+ import { LLMClient } from '@charivo/core';
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;
18
+
19
+ export { StubLLMClient, createStubLLMClient };
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ // src/stub/index.ts
4
+ var StubLLMClient = class {
5
+ responses = [
6
+ "Hello! I'm a test character.",
7
+ "The weather is really nice today!",
8
+ "How can I help you?",
9
+ "That's an interesting question. Could you tell me more?",
10
+ "Yes, understood!",
11
+ "I see. That's an interesting story.",
12
+ "I think so too.",
13
+ "Hmm... that's a difficult question.",
14
+ "Oh no... I'm sorry to hear that.",
15
+ "What?! Really?",
16
+ "That makes me upset.",
17
+ "I'm a bit embarrassed..."
18
+ ];
19
+ responseIndex = 0;
20
+ async call(_messages) {
21
+ await new Promise((resolve) => setTimeout(resolve, 500));
22
+ const response = this.responses[this.responseIndex % this.responses.length];
23
+ this.responseIndex++;
24
+ return response;
25
+ }
26
+ };
27
+ function createStubLLMClient() {
28
+ return new StubLLMClient();
29
+ }
30
+
31
+ exports.StubLLMClient = StubLLMClient;
32
+ exports.createStubLLMClient = createStubLLMClient;
33
+ //# sourceMappingURL=index.js.map
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,31 @@
1
+ // src/stub/index.ts
2
+ var StubLLMClient = class {
3
+ responses = [
4
+ "Hello! I'm a test character.",
5
+ "The weather is really nice today!",
6
+ "How can I help you?",
7
+ "That's an interesting question. Could you tell me more?",
8
+ "Yes, understood!",
9
+ "I see. That's an interesting story.",
10
+ "I think so too.",
11
+ "Hmm... that's a difficult question.",
12
+ "Oh no... I'm sorry to hear that.",
13
+ "What?! Really?",
14
+ "That makes me upset.",
15
+ "I'm a bit embarrassed..."
16
+ ];
17
+ responseIndex = 0;
18
+ async call(_messages) {
19
+ await new Promise((resolve) => setTimeout(resolve, 500));
20
+ const response = this.responses[this.responseIndex % this.responses.length];
21
+ this.responseIndex++;
22
+ return response;
23
+ }
24
+ };
25
+ function createStubLLMClient() {
26
+ return new StubLLMClient();
27
+ }
28
+
29
+ export { StubLLMClient, createStubLLMClient };
30
+ //# sourceMappingURL=index.mjs.map
31
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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"]}
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@charivo/llm",
3
+ "version": "0.2.0",
4
+ "description": "LLM manager and browser adapters for Charivo",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./remote": {
15
+ "types": "./dist/remote/index.d.ts",
16
+ "import": "./dist/remote/index.mjs",
17
+ "require": "./dist/remote/index.js"
18
+ },
19
+ "./openai": {
20
+ "types": "./dist/openai/index.d.ts",
21
+ "import": "./dist/openai/index.mjs",
22
+ "require": "./dist/openai/index.js"
23
+ },
24
+ "./openclaw": {
25
+ "types": "./dist/openclaw/index.d.ts",
26
+ "import": "./dist/openclaw/index.mjs",
27
+ "require": "./dist/openclaw/index.js"
28
+ },
29
+ "./stub": {
30
+ "types": "./dist/stub/index.d.ts",
31
+ "import": "./dist/stub/index.mjs",
32
+ "require": "./dist/stub/index.js"
33
+ }
34
+ },
35
+ "dependencies": {
36
+ "openai": "^4.47.1",
37
+ "@charivo/core": "0.7.0"
38
+ },
39
+ "devDependencies": {
40
+ "tsup": "^8.5.0",
41
+ "typescript": "^5.9.2"
42
+ },
43
+ "files": [
44
+ "dist"
45
+ ],
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "license": "MIT",
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "https://github.com/zeikar/charivo.git",
53
+ "directory": "packages/llm"
54
+ },
55
+ "author": {
56
+ "name": "Zeikar",
57
+ "url": "https://github.com/zeikar"
58
+ },
59
+ "homepage": "https://github.com/zeikar/charivo#readme",
60
+ "bugs": {
61
+ "url": "https://github.com/zeikar/charivo/issues"
62
+ },
63
+ "scripts": {
64
+ "build": "tsup",
65
+ "dev": "tsup --watch",
66
+ "clean": "rm -rf dist",
67
+ "typecheck": "tsc --noEmit"
68
+ }
69
+ }