@amux.ai/utils 0.1.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/index.cjs ADDED
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ // src/stream.ts
4
+ function parseSSE(chunk) {
5
+ const lines = chunk.split("\n");
6
+ const events = [];
7
+ for (const line of lines) {
8
+ const trimmed = line.trim();
9
+ if (trimmed.startsWith("data: ")) {
10
+ const data = trimmed.slice(6);
11
+ if (data !== "[DONE]") {
12
+ events.push({ data });
13
+ }
14
+ }
15
+ }
16
+ return events;
17
+ }
18
+ function createSSE(data) {
19
+ return `data: ${JSON.stringify(data)}
20
+
21
+ `;
22
+ }
23
+
24
+ // src/error.ts
25
+ var LLMBridgeError = class extends Error {
26
+ constructor(message, code, status, details) {
27
+ super(message);
28
+ this.code = code;
29
+ this.status = status;
30
+ this.details = details;
31
+ this.name = "LLMBridgeError";
32
+ }
33
+ };
34
+ function normalizeError(error) {
35
+ if (error instanceof LLMBridgeError) {
36
+ return {
37
+ message: error.message,
38
+ code: error.code,
39
+ status: error.status,
40
+ details: error.details
41
+ };
42
+ }
43
+ if (error instanceof Error) {
44
+ return {
45
+ message: error.message
46
+ };
47
+ }
48
+ return {
49
+ message: String(error)
50
+ };
51
+ }
52
+
53
+ exports.LLMBridgeError = LLMBridgeError;
54
+ exports.createSSE = createSSE;
55
+ exports.normalizeError = normalizeError;
56
+ exports.parseSSE = parseSSE;
57
+ //# sourceMappingURL=index.cjs.map
58
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/stream.ts","../src/error.ts"],"names":[],"mappings":";;;AAGO,SAAS,SAAS,KAAA,EAAwC;AAC/D,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,KAAA,CAAM,IAAI,CAAA;AAC9B,EAAA,MAAM,SAAkC,EAAC;AAEzC,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,I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["/**\n * Parse SSE (Server-Sent Events) stream\n */\nexport function parseSSE(chunk: string): Array<{ data: string }> {\n const lines = chunk.split('\\n')\n const events: Array<{ data: string }> = []\n\n for (const line of lines) {\n const trimmed = line.trim()\n if (trimmed.startsWith('data: ')) {\n const data = trimmed.slice(6)\n if (data !== '[DONE]') {\n events.push({ data })\n }\n }\n }\n\n return events\n}\n\n/**\n * Create SSE format string\n */\nexport function createSSE(data: unknown): string {\n return `data: ${JSON.stringify(data)}\\n\\n`\n}\n","/**\n * Standard error class for Amux\n */\nexport class LLMBridgeError extends Error {\n constructor(\n message: string,\n public code?: string,\n public status?: number,\n public details?: Record<string, unknown>\n ) {\n super(message)\n this.name = 'LLMBridgeError'\n }\n}\n\n/**\n * Normalize error to standard format\n */\nexport function normalizeError(error: unknown): {\n message: string\n code?: string\n status?: number\n details?: Record<string, unknown>\n} {\n if (error instanceof LLMBridgeError) {\n return {\n message: error.message,\n code: error.code,\n status: error.status,\n details: error.details,\n }\n }\n\n if (error instanceof Error) {\n return {\n message: error.message,\n }\n }\n\n return {\n message: String(error),\n }\n}\n"]}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Parse SSE (Server-Sent Events) stream
3
+ */
4
+ declare function parseSSE(chunk: string): Array<{
5
+ data: string;
6
+ }>;
7
+ /**
8
+ * Create SSE format string
9
+ */
10
+ declare function createSSE(data: unknown): string;
11
+
12
+ /**
13
+ * Standard error class for Amux
14
+ */
15
+ declare class LLMBridgeError extends Error {
16
+ code?: string | undefined;
17
+ status?: number | undefined;
18
+ details?: Record<string, unknown> | undefined;
19
+ constructor(message: string, code?: string | undefined, status?: number | undefined, details?: Record<string, unknown> | undefined);
20
+ }
21
+ /**
22
+ * Normalize error to standard format
23
+ */
24
+ declare function normalizeError(error: unknown): {
25
+ message: string;
26
+ code?: string;
27
+ status?: number;
28
+ details?: Record<string, unknown>;
29
+ };
30
+
31
+ export { LLMBridgeError, createSSE, normalizeError, parseSSE };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Parse SSE (Server-Sent Events) stream
3
+ */
4
+ declare function parseSSE(chunk: string): Array<{
5
+ data: string;
6
+ }>;
7
+ /**
8
+ * Create SSE format string
9
+ */
10
+ declare function createSSE(data: unknown): string;
11
+
12
+ /**
13
+ * Standard error class for Amux
14
+ */
15
+ declare class LLMBridgeError extends Error {
16
+ code?: string | undefined;
17
+ status?: number | undefined;
18
+ details?: Record<string, unknown> | undefined;
19
+ constructor(message: string, code?: string | undefined, status?: number | undefined, details?: Record<string, unknown> | undefined);
20
+ }
21
+ /**
22
+ * Normalize error to standard format
23
+ */
24
+ declare function normalizeError(error: unknown): {
25
+ message: string;
26
+ code?: string;
27
+ status?: number;
28
+ details?: Record<string, unknown>;
29
+ };
30
+
31
+ export { LLMBridgeError, createSSE, normalizeError, parseSSE };
package/dist/index.js ADDED
@@ -0,0 +1,53 @@
1
+ // src/stream.ts
2
+ function parseSSE(chunk) {
3
+ const lines = chunk.split("\n");
4
+ const events = [];
5
+ for (const line of lines) {
6
+ const trimmed = line.trim();
7
+ if (trimmed.startsWith("data: ")) {
8
+ const data = trimmed.slice(6);
9
+ if (data !== "[DONE]") {
10
+ events.push({ data });
11
+ }
12
+ }
13
+ }
14
+ return events;
15
+ }
16
+ function createSSE(data) {
17
+ return `data: ${JSON.stringify(data)}
18
+
19
+ `;
20
+ }
21
+
22
+ // src/error.ts
23
+ var LLMBridgeError = class extends Error {
24
+ constructor(message, code, status, details) {
25
+ super(message);
26
+ this.code = code;
27
+ this.status = status;
28
+ this.details = details;
29
+ this.name = "LLMBridgeError";
30
+ }
31
+ };
32
+ function normalizeError(error) {
33
+ if (error instanceof LLMBridgeError) {
34
+ return {
35
+ message: error.message,
36
+ code: error.code,
37
+ status: error.status,
38
+ details: error.details
39
+ };
40
+ }
41
+ if (error instanceof Error) {
42
+ return {
43
+ message: error.message
44
+ };
45
+ }
46
+ return {
47
+ message: String(error)
48
+ };
49
+ }
50
+
51
+ export { LLMBridgeError, createSSE, normalizeError, parseS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AM,KAAA,CAAM,IAAA;AAAA,MACZ,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,SAAS,KAAA,CAAM;AAAA,KACjB;AAAA,EACF;AAEA,EAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,IAAA,OAAO;AAAA,MACL,SAAS,KAAA,CAAM;AAAA,KACjB;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,OAAO,KAAK;AAAA,GACvB;AACF","file":"index.js","sourcesContent":["/**\n * Parse SSE (Server-Sent Events) stream\n */\nexport function parseSSE(chunk: string): Array<{ data: string }> {\n const lines = chunk.split('\\n')\n const events: Array<{ data: string }> = []\n\n for (const line of lines) {\n const trimmed = line.trim()\n if (trimmed.startsWith('data: ')) {\n const data = trimmed.slice(6)\n if (data !== '[DONE]') {\n events.push({ data })\n }\n }\n }\n\n return events\n}\n\n/**\n * Create SSE format string\n */\nexport function createSSE(data: unknown): string {\n return `data: ${JSON.stringify(data)}\\n\\n`\n}\n","/**\n * Standard error class for Amux\n */\nexport class LLMBridgeError extends Error {\n constructor(\n message: string,\n public code?: string,\n public status?: number,\n public details?: Record<string, unknown>\n ) {\n super(message)\n this.name = 'LLMBridgeError'\n }\n}\n\n/**\n * Normalize error to standard format\n */\nexport function normalizeError(error: unknown): {\n message: string\n code?: string\n status?: number\n details?: Record<string, unknown>\n} {\n if (error instanceof LLMBridgeError) {\n return {\n message: error.message,\n code: error.code,\n status: error.status,\n details: error.details,\n }\n }\n\n if (error instanceof Error) {\n return {\n message: error.message,\n }\n }\n\n return {\n message: String(error),\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@amux.ai/utils",
3
+ "version": "0.1.0",
4
+ "description": "Shared utilities for Amux",
5
+ "keywords": [
6
+ "amux",
7
+ "llm",
8
+ "utils"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/isboyjc/amux.git",
13
+ "directory": "packages/utils"
14
+ },
15
+ "license": "MIT",
16
+ "author": "isboyjc",
17
+ "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js",
22
+ "require": "./dist/index.cjs"
23
+ }
24
+ },
25
+ "main": "./dist/index.cjs",
26
+ "module": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "devDependencies": {
32
+ "@types/node": "^20.11.5",
33
+ "tsup": "^8.0.1",
34
+ "typescript": "^5.3.3",
35
+ "vitest": "^1.2.1"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "scripts": {
41
+ "build": "tsup",
42
+ "dev": "tsup --watch",
43
+ "test": "vitest run",
44
+ "test:watch": "vitest",
45
+ "typecheck": "tsc --noEmit",
46
+ "lint": "eslint src --ext .ts",
47
+ "clean": "rm -rf dist"
48
+ }
49
+ }