statelog-client 0.0.28

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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # statelog-client
2
+
3
+ A client for statelog.
4
+
5
+ ```bash
6
+ pnpm i egonSchiele/statelog-client
7
+ ```
@@ -0,0 +1,64 @@
1
+ export type JSONEdge = {
2
+ type: "regular";
3
+ to: string;
4
+ } | {
5
+ type: "conditional";
6
+ adjacentNodes: readonly string[];
7
+ };
8
+ export declare class StatelogClient {
9
+ private host;
10
+ private debugMode;
11
+ private tid;
12
+ constructor({ host, tid, debugMode, }: {
13
+ host: string;
14
+ tid?: string;
15
+ debugMode?: boolean;
16
+ });
17
+ debug(message: string, data: any): void;
18
+ graph({ nodes, edges, startNode, }: {
19
+ nodes: string[];
20
+ edges: Record<string, JSONEdge>;
21
+ startNode?: string;
22
+ }): void;
23
+ enterNode({ nodeId, data }: {
24
+ nodeId: string;
25
+ data: any;
26
+ }): void;
27
+ exitNode({ nodeId, data, timeTaken, }: {
28
+ nodeId: string;
29
+ data: any;
30
+ timeTaken?: number;
31
+ }): void;
32
+ beforeHook({ nodeId, startData, endData, timeTaken, }: {
33
+ nodeId: string;
34
+ startData: any;
35
+ endData: any;
36
+ timeTaken?: number;
37
+ }): void;
38
+ afterHook({ nodeId, startData, endData, timeTaken, }: {
39
+ nodeId: string;
40
+ startData: any;
41
+ endData: any;
42
+ timeTaken?: number;
43
+ }): void;
44
+ followEdge({ fromNodeId, toNodeId, isConditionalEdge, data, }: {
45
+ fromNodeId: string;
46
+ toNodeId: string;
47
+ isConditionalEdge: boolean;
48
+ data: any;
49
+ }): void;
50
+ promptCompletion({ messages, completion, model, timeTaken, }: {
51
+ messages: any[];
52
+ completion: any;
53
+ model?: string;
54
+ timeTaken?: number;
55
+ }): void;
56
+ toolCall({ toolName, args, output, model, timeTaken, }: {
57
+ toolName: string;
58
+ args: any;
59
+ output: any;
60
+ model?: string;
61
+ timeTaken?: number;
62
+ }): void;
63
+ post(body: Record<string, any>): void;
64
+ }
package/dist/index.js ADDED
@@ -0,0 +1,104 @@
1
+ import { nanoid } from "nanoid";
2
+ export class StatelogClient {
3
+ constructor({ host, tid, debugMode, }) {
4
+ this.host = host;
5
+ this.debugMode = debugMode || false;
6
+ this.tid = tid || nanoid();
7
+ if (this.debugMode)
8
+ console.log(`Statelog client initialized with host: ${host} and TID: ${this.tid}`);
9
+ }
10
+ debug(message, data) {
11
+ this.post({
12
+ type: "debug",
13
+ message: message,
14
+ data,
15
+ });
16
+ }
17
+ graph({ nodes, edges, startNode, }) {
18
+ this.post({
19
+ type: "graph",
20
+ nodes,
21
+ edges,
22
+ startNode,
23
+ });
24
+ }
25
+ enterNode({ nodeId, data }) {
26
+ this.post({
27
+ type: "enterNode",
28
+ nodeId,
29
+ data,
30
+ });
31
+ }
32
+ exitNode({ nodeId, data, timeTaken, }) {
33
+ this.post({
34
+ type: "exitNode",
35
+ nodeId,
36
+ data,
37
+ timeTaken,
38
+ });
39
+ }
40
+ beforeHook({ nodeId, startData, endData, timeTaken, }) {
41
+ this.post({
42
+ type: "beforeHook",
43
+ nodeId,
44
+ startData,
45
+ endData,
46
+ timeTaken,
47
+ });
48
+ }
49
+ afterHook({ nodeId, startData, endData, timeTaken, }) {
50
+ this.post({
51
+ type: "afterHook",
52
+ nodeId,
53
+ startData,
54
+ endData,
55
+ timeTaken,
56
+ });
57
+ }
58
+ followEdge({ fromNodeId, toNodeId, isConditionalEdge, data, }) {
59
+ this.post({
60
+ type: "followEdge",
61
+ edgeId: `${fromNodeId}->${toNodeId}`,
62
+ fromNodeId,
63
+ toNodeId,
64
+ isConditionalEdge,
65
+ data,
66
+ });
67
+ }
68
+ promptCompletion({ messages, completion, model, timeTaken, }) {
69
+ this.post({
70
+ type: "promptCompletion",
71
+ messages,
72
+ completion,
73
+ model,
74
+ timeTaken,
75
+ });
76
+ }
77
+ toolCall({ toolName, args, output, model, timeTaken, }) {
78
+ this.post({
79
+ type: "toolCall",
80
+ toolName,
81
+ args,
82
+ output,
83
+ model,
84
+ timeTaken,
85
+ });
86
+ }
87
+ post(body) {
88
+ const fullUrl = new URL("/api/logs", this.host);
89
+ const url = fullUrl.toString();
90
+ fetch(url, {
91
+ method: "POST",
92
+ headers: {
93
+ "Content-Type": "application/json",
94
+ },
95
+ body: JSON.stringify({
96
+ tid: this.tid,
97
+ data: Object.assign(Object.assign({}, body), { timeStamp: new Date().toISOString() }),
98
+ }),
99
+ }).catch((err) => {
100
+ if (this.debugMode)
101
+ console.error("Failed to send statelog:", err);
102
+ });
103
+ }
104
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "statelog-client",
3
+ "version": "0.0.28",
4
+ "description": "A client for statelog, a logging app",
5
+ "homepage": "https://github.com/egonSchiele/statelog-client",
6
+ "scripts": {
7
+ "test": "vitest",
8
+ "test:tsc": "tsc -p tests/tsconfig.json",
9
+ "coverage": "vitest --coverage",
10
+ "build": "rm -rf dist && tsc",
11
+ "start": "cd dist && node index.js"
12
+ },
13
+ "files": [
14
+ "./dist"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.js",
19
+ "require": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ }
22
+ },
23
+ "type": "module",
24
+ "types": "./dist/index.d.ts",
25
+ "keywords": [
26
+ "statelog",
27
+ "client"
28
+ ],
29
+ "author": "",
30
+ "license": "ISC",
31
+ "devDependencies": {
32
+ "@types/node": "^20.19.27",
33
+ "typescript": "^5.9.3",
34
+ "vitest": "^1.6.1"
35
+ },
36
+ "dependencies": {
37
+ "nanoid": "^5.1.6"
38
+ }
39
+ }