@nodetool-ai/sdk 0.8.1
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 +122 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/chat.d.ts +137 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +268 -0
- package/dist/chat.js.map +1 -0
- package/dist/client.d.ts +55 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +70 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -0
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# `@nodetool-ai/sdk`
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the NodeTool server.
|
|
4
|
+
|
|
5
|
+
- **Fully-typed tRPC client** covering the entire `AppRouter` surface
|
|
6
|
+
(threads, messages, models, workflows, jobs, assets, settings, …) —
|
|
7
|
+
no separate API definition to maintain.
|
|
8
|
+
- **`ChatSocket`** — typed event-emitter wrapper around the chat
|
|
9
|
+
WebSocket protocol (msgpack frames, with JSON fallback).
|
|
10
|
+
- Works in browsers and Node ≥18. In Node, pass a `WebSocket`
|
|
11
|
+
constructor from the [`ws`](https://www.npmjs.com/package/ws) package.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
This package lives inside the NodeTool monorepo. From a workspace
|
|
16
|
+
that depends on it (`@nodetool-ai/sdk: "*"`), import directly:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { createNodetoolClient } from "@nodetool-ai/sdk";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { createNodetoolClient } from "@nodetool-ai/sdk";
|
|
26
|
+
|
|
27
|
+
const nodetool = createNodetoolClient({
|
|
28
|
+
baseUrl: "http://localhost:7777",
|
|
29
|
+
authToken: process.env.NODETOOL_TOKEN ?? null
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// ── tRPC ──────────────────────────────────────────────────────
|
|
33
|
+
const { threads } = await nodetool.trpc.threads.list.query({ limit: 50 });
|
|
34
|
+
const thread = await nodetool.trpc.threads.create.mutate({ title: "Hi" });
|
|
35
|
+
const { messages } = await nodetool.trpc.messages.list.query({
|
|
36
|
+
thread_id: thread.id,
|
|
37
|
+
limit: 100
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// ── Convenience: list LLM models from configured providers ────
|
|
41
|
+
const models = await nodetool.listLanguageModels();
|
|
42
|
+
// → [{ id: "gpt-5.4-mini", name: "GPT 5.4 mini", provider: "openai" }, …]
|
|
43
|
+
|
|
44
|
+
// ── Streaming chat WebSocket ──────────────────────────────────
|
|
45
|
+
const socket = nodetool.chat();
|
|
46
|
+
|
|
47
|
+
socket.on("chunk", (c) => {
|
|
48
|
+
// c.content — partial text; c.done — true on the final chunk
|
|
49
|
+
});
|
|
50
|
+
socket.on("message", (m) => {
|
|
51
|
+
// Final persisted assistant message (after stream completes)
|
|
52
|
+
});
|
|
53
|
+
socket.on("tool_call", (t) => {
|
|
54
|
+
// t.name, t.args
|
|
55
|
+
});
|
|
56
|
+
socket.on("error", (e) => console.error(e.message));
|
|
57
|
+
socket.on("state", (s) => console.log("ws state:", s));
|
|
58
|
+
|
|
59
|
+
socket.connect();
|
|
60
|
+
socket.send({
|
|
61
|
+
threadId: thread.id,
|
|
62
|
+
text: "Hello!",
|
|
63
|
+
model: "fake-model-v1",
|
|
64
|
+
provider: "fake"
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// To cancel an in-flight stream:
|
|
68
|
+
socket.stop(thread.id);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Node usage
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { WebSocket } from "ws";
|
|
75
|
+
import { createNodetoolClient } from "@nodetool-ai/sdk";
|
|
76
|
+
|
|
77
|
+
const nodetool = createNodetoolClient({
|
|
78
|
+
baseUrl: "http://localhost:7777",
|
|
79
|
+
WebSocket // pass the ws constructor explicitly
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## API surface
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
createNodetoolClient(opts: {
|
|
87
|
+
baseUrl: string;
|
|
88
|
+
authToken?: string | null;
|
|
89
|
+
fetch?: typeof fetch;
|
|
90
|
+
WebSocket?: typeof WebSocket;
|
|
91
|
+
}): NodetoolClient
|
|
92
|
+
|
|
93
|
+
interface NodetoolClient {
|
|
94
|
+
baseUrl: string;
|
|
95
|
+
authToken: string | null;
|
|
96
|
+
trpc: CreateTRPCClient<AppRouter>; // full type-safe tRPC client
|
|
97
|
+
chat(): ChatSocket; // open a new chat WebSocket
|
|
98
|
+
listLanguageModels(): Promise<{
|
|
99
|
+
id: string; name: string; provider: string;
|
|
100
|
+
}[]>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
class ChatSocket {
|
|
104
|
+
connect(): void;
|
|
105
|
+
disconnect(): void;
|
|
106
|
+
send(opts: SendChatMessageOptions): void;
|
|
107
|
+
stop(threadId: string): void;
|
|
108
|
+
on<K extends keyof ChatEvents>(event: K, h: (p: ChatEvents[K]) => void): () => void;
|
|
109
|
+
getState(): ConnectionState;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Discriminated `ChatEvent` union covers `chunk`, `message`, `tool_call`,
|
|
114
|
+
`error`, `generation_stopped`, `thread_update`, `planning_update`,
|
|
115
|
+
`task_update`, plus a `raw` catch-all for forward-compatible frames.
|
|
116
|
+
|
|
117
|
+
## Worked example
|
|
118
|
+
|
|
119
|
+
See [`examples/chat_app/`](../../examples/chat_app/) for a complete
|
|
120
|
+
shadcn/ui chat client built on top of this SDK, plus a CLI smoke test
|
|
121
|
+
([`scripts/live-test.mjs`](../../examples/chat_app/scripts/live-test.mjs))
|
|
122
|
+
that exercises the same flow end-to-end.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2026-09-28T09:19:19.084Z
|
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChatSocket — typed wrapper around the unified NodeTool chat WebSocket.
|
|
3
|
+
*
|
|
4
|
+
* Wire format: msgpack frames by default (length-tagged, binary), with a JSON
|
|
5
|
+
* text fallback if msgpack encoding fails. Inbound frames are decoded and
|
|
6
|
+
* dispatched to the appropriate `on(<type>)` handlers as a discriminated
|
|
7
|
+
* union, so consumers never see raw bytes.
|
|
8
|
+
*/
|
|
9
|
+
import type { Chunk, Message, ToolCallUpdate, PlanningUpdate, TaskUpdate, ErrorMessage } from "@nodetool-ai/protocol";
|
|
10
|
+
export type WebSocketCtor = typeof WebSocket;
|
|
11
|
+
/**
|
|
12
|
+
* A field value as it comes off the wire. msgpack and JSON both decode into
|
|
13
|
+
* this domain, so a frame's own fields have a contract before anything narrows
|
|
14
|
+
* them to a protocol shape.
|
|
15
|
+
*/
|
|
16
|
+
export type ChatFrameValue = null | boolean | number | string | Uint8Array | ChatFrameValue[] | ChatFrameFields;
|
|
17
|
+
export interface ChatFrameFields {
|
|
18
|
+
[field: string]: ChatFrameValue | undefined;
|
|
19
|
+
}
|
|
20
|
+
export type ConnectionState = "idle" | "connecting" | "connected" | "disconnected" | "reconnecting" | "error";
|
|
21
|
+
/** A streamed text chunk. `done: true` marks the end of one assistant turn. */
|
|
22
|
+
export interface ChatChunkEvent extends Chunk {
|
|
23
|
+
type: "chunk";
|
|
24
|
+
}
|
|
25
|
+
/** A complete persisted message (assistant final or echoed user input). */
|
|
26
|
+
export interface ChatMessageEvent extends Message {
|
|
27
|
+
type: "message";
|
|
28
|
+
role: "user" | "assistant" | "system" | "tool";
|
|
29
|
+
}
|
|
30
|
+
/** Tool invocation announced mid-stream. */
|
|
31
|
+
export interface ChatToolCallEvent extends ToolCallUpdate {
|
|
32
|
+
}
|
|
33
|
+
/** Server-side failure during chat processing. */
|
|
34
|
+
export interface ChatErrorEvent extends ErrorMessage {
|
|
35
|
+
}
|
|
36
|
+
/** Ack frame after a `stop` command. */
|
|
37
|
+
export interface ChatGenerationStoppedEvent {
|
|
38
|
+
type: "generation_stopped";
|
|
39
|
+
thread_id?: string | null;
|
|
40
|
+
job_id?: string | null;
|
|
41
|
+
message?: string;
|
|
42
|
+
}
|
|
43
|
+
/** A new derived title for a thread (e.g. after summarisation). */
|
|
44
|
+
export interface ChatThreadUpdateEvent {
|
|
45
|
+
type: "thread_update";
|
|
46
|
+
thread_id: string;
|
|
47
|
+
title?: string;
|
|
48
|
+
}
|
|
49
|
+
/** Anything else — surfaced raw so callers can opt in to it. */
|
|
50
|
+
export interface ChatRawEvent extends ChatFrameFields {
|
|
51
|
+
type: string;
|
|
52
|
+
}
|
|
53
|
+
export type ChatEvent = ChatChunkEvent | ChatMessageEvent | ChatToolCallEvent | ChatErrorEvent | ChatGenerationStoppedEvent | ChatThreadUpdateEvent | PlanningUpdate | TaskUpdate | ChatRawEvent;
|
|
54
|
+
export interface SendChatMessageOptions {
|
|
55
|
+
threadId: string;
|
|
56
|
+
text: string;
|
|
57
|
+
model?: string | null;
|
|
58
|
+
provider?: string | null;
|
|
59
|
+
agentMode?: boolean;
|
|
60
|
+
tools?: string[] | null;
|
|
61
|
+
collections?: string[] | null;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the turn's tool calls run, ask, or are blocked — `"auto"` runs
|
|
64
|
+
* everything, `"default"` parks actions on an approval request, `"plan"`
|
|
65
|
+
* blocks them. Omitted leaves the server's default (`"default"`), which
|
|
66
|
+
* needs a surface that can answer approvals.
|
|
67
|
+
*/
|
|
68
|
+
permissionMode?: "plan" | "default" | "auto" | null;
|
|
69
|
+
}
|
|
70
|
+
export interface ChatSocketOptions {
|
|
71
|
+
/** Full WebSocket URL, e.g. `ws://localhost:7777/ws`. */
|
|
72
|
+
url: string;
|
|
73
|
+
authToken?: string | null;
|
|
74
|
+
/** Override for environments without a global `WebSocket`. */
|
|
75
|
+
WebSocket?: WebSocketCtor;
|
|
76
|
+
/** Initial reconnect backoff in ms (default 1500, capped at 15s). */
|
|
77
|
+
reconnectDelayMs?: number;
|
|
78
|
+
/** Max reconnect attempts before giving up (default 10, 0 disables). */
|
|
79
|
+
maxReconnect?: number;
|
|
80
|
+
}
|
|
81
|
+
type EventMap = {
|
|
82
|
+
chunk: ChatChunkEvent;
|
|
83
|
+
message: ChatMessageEvent;
|
|
84
|
+
tool_call: ChatToolCallEvent;
|
|
85
|
+
error: ChatErrorEvent;
|
|
86
|
+
generation_stopped: ChatGenerationStoppedEvent;
|
|
87
|
+
thread_update: ChatThreadUpdateEvent;
|
|
88
|
+
planning_update: PlanningUpdate;
|
|
89
|
+
task_update: TaskUpdate;
|
|
90
|
+
raw: ChatEvent;
|
|
91
|
+
state: ConnectionState;
|
|
92
|
+
};
|
|
93
|
+
type Listener<K extends keyof EventMap> = (payload: EventMap[K]) => void;
|
|
94
|
+
export declare class ChatSocket {
|
|
95
|
+
private readonly url;
|
|
96
|
+
private readonly authToken;
|
|
97
|
+
private readonly Ctor;
|
|
98
|
+
private readonly reconnectDelayMs;
|
|
99
|
+
private readonly maxReconnect;
|
|
100
|
+
private socket;
|
|
101
|
+
private state;
|
|
102
|
+
private intentionalClose;
|
|
103
|
+
private reconnectAttempts;
|
|
104
|
+
private reconnectTimer;
|
|
105
|
+
private readonly listeners;
|
|
106
|
+
constructor(options: ChatSocketOptions);
|
|
107
|
+
/** Current connection state. */
|
|
108
|
+
getState(): ConnectionState;
|
|
109
|
+
/**
|
|
110
|
+
* Subscribe to an event. Returns an unsubscribe function.
|
|
111
|
+
*
|
|
112
|
+
* The `raw` event fires for every inbound frame, including types that don't
|
|
113
|
+
* have their own typed handler — useful for bridging future server events.
|
|
114
|
+
*/
|
|
115
|
+
on<K extends keyof EventMap>(event: K, listener: Listener<K>): () => void;
|
|
116
|
+
/** Open the socket. No-op if already open or connecting. */
|
|
117
|
+
connect(): void;
|
|
118
|
+
/** Close the socket and cancel any pending reconnect. */
|
|
119
|
+
disconnect(): void;
|
|
120
|
+
/** Send a `chat_message` command. */
|
|
121
|
+
send(opts: SendChatMessageOptions): void;
|
|
122
|
+
/** Send a `stop` command for the given thread. */
|
|
123
|
+
stop(threadId: string): void;
|
|
124
|
+
/**
|
|
125
|
+
* Reattach to a thread's in-flight turn after a disconnect: the server
|
|
126
|
+
* replays every frame it stamped after `lastSeq`, so a dropped socket costs
|
|
127
|
+
* no output and no second inference.
|
|
128
|
+
*/
|
|
129
|
+
resume(threadId: string, lastSeq: number): void;
|
|
130
|
+
private setState;
|
|
131
|
+
private emit;
|
|
132
|
+
private sendCommand;
|
|
133
|
+
private handleRaw;
|
|
134
|
+
private scheduleReconnect;
|
|
135
|
+
}
|
|
136
|
+
export {};
|
|
137
|
+
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../src/chat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EACV,KAAK,EACL,OAAO,EAEP,cAAc,EACd,cAAc,EACd,UAAU,EACV,YAAY,EACb,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,aAAa,GAAG,OAAO,SAAS,CAAC;AAE7C;;;;GAIG;AACH,MAAM,MAAM,cAAc,GACtB,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,UAAU,GACV,cAAc,EAAE,GAChB,eAAe,CAAC;AAEpB,MAAM,WAAW,eAAe;IAC9B,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAAC;CAC7C;AAKD,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,YAAY,GACZ,WAAW,GACX,cAAc,GACd,cAAc,GACd,OAAO,CAAC;AAEZ,+EAA+E;AAC/E,MAAM,WAAW,cAAe,SAAQ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B,OAAO,CAAC,cAAc,CAA8C;IACpE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAWxB;IAEF,YAAY,OAAO,EAAE,iBAAiB,EAarC;IAED,gCAAgC;IAChC,QAAQ,IAAI,eAAe,CAE1B;IAED;;;;;OAKG;IACH,EAAE,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,CAMxE;IAED,4DAA4D;IAC5D,OAAO,IAAI,IAAI,CAqCd;IAED,yDAAyD;IACzD,UAAU,IAAI,IAAI,CAOjB;IAED,qCAAqC;IACrC,IAAI,CAAC,IAAI,EAAE,sBAAsB,GAAG,IAAI,CAgBvC;IAED,kDAAkD;IAClD,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAE3B;IAED;;;;OAIG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAK9C;IAED,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,IAAI;IAWZ,OAAO,CAAC,WAAW;IAmBnB,OAAO,CAAC,SAAS;IAiBjB,OAAO,CAAC,iBAAiB;CAgB1B"}
|
package/dist/chat.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChatSocket — typed wrapper around the unified NodeTool chat WebSocket.
|
|
3
|
+
*
|
|
4
|
+
* Wire format: msgpack frames by default (length-tagged, binary), with a JSON
|
|
5
|
+
* text fallback if msgpack encoding fails. Inbound frames are decoded and
|
|
6
|
+
* dispatched to the appropriate `on(<type>)` handlers as a discriminated
|
|
7
|
+
* union, so consumers never see raw bytes.
|
|
8
|
+
*/
|
|
9
|
+
import { pack, unpack } from "msgpackr";
|
|
10
|
+
const DEFAULT_RECONNECT_MS = 1500;
|
|
11
|
+
const DEFAULT_MAX_RECONNECT = 10;
|
|
12
|
+
const MAX_RECONNECT_MS = 15_000;
|
|
13
|
+
export class ChatSocket {
|
|
14
|
+
url;
|
|
15
|
+
authToken;
|
|
16
|
+
Ctor;
|
|
17
|
+
reconnectDelayMs;
|
|
18
|
+
maxReconnect;
|
|
19
|
+
socket = null;
|
|
20
|
+
state = "idle";
|
|
21
|
+
intentionalClose = false;
|
|
22
|
+
reconnectAttempts = 0;
|
|
23
|
+
reconnectTimer = null;
|
|
24
|
+
listeners = {
|
|
25
|
+
chunk: new Set(),
|
|
26
|
+
message: new Set(),
|
|
27
|
+
tool_call: new Set(),
|
|
28
|
+
error: new Set(),
|
|
29
|
+
generation_stopped: new Set(),
|
|
30
|
+
thread_update: new Set(),
|
|
31
|
+
planning_update: new Set(),
|
|
32
|
+
task_update: new Set(),
|
|
33
|
+
raw: new Set(),
|
|
34
|
+
state: new Set()
|
|
35
|
+
};
|
|
36
|
+
constructor(options) {
|
|
37
|
+
this.url = options.url;
|
|
38
|
+
this.authToken = options.authToken ?? null;
|
|
39
|
+
this.reconnectDelayMs = options.reconnectDelayMs ?? DEFAULT_RECONNECT_MS;
|
|
40
|
+
this.maxReconnect = options.maxReconnect ?? DEFAULT_MAX_RECONNECT;
|
|
41
|
+
const Ctor = options.WebSocket ?? globalCtor();
|
|
42
|
+
if (!Ctor) {
|
|
43
|
+
throw new Error("No `WebSocket` constructor available. Pass `WebSocket` from `ws` " +
|
|
44
|
+
"(Node) or run in a browser context.");
|
|
45
|
+
}
|
|
46
|
+
this.Ctor = Ctor;
|
|
47
|
+
}
|
|
48
|
+
/** Current connection state. */
|
|
49
|
+
getState() {
|
|
50
|
+
return this.state;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Subscribe to an event. Returns an unsubscribe function.
|
|
54
|
+
*
|
|
55
|
+
* The `raw` event fires for every inbound frame, including types that don't
|
|
56
|
+
* have their own typed handler — useful for bridging future server events.
|
|
57
|
+
*/
|
|
58
|
+
on(event, listener) {
|
|
59
|
+
const set = this.listeners[event];
|
|
60
|
+
set.add(listener);
|
|
61
|
+
return () => {
|
|
62
|
+
set.delete(listener);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Open the socket. No-op if already open or connecting. */
|
|
66
|
+
connect() {
|
|
67
|
+
if (this.socket &&
|
|
68
|
+
(this.socket.readyState === this.Ctor.OPEN ||
|
|
69
|
+
this.socket.readyState === this.Ctor.CONNECTING)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.intentionalClose = false;
|
|
73
|
+
this.setState("connecting");
|
|
74
|
+
let url = this.url;
|
|
75
|
+
if (this.authToken) {
|
|
76
|
+
url +=
|
|
77
|
+
(url.includes("?") ? "&" : "?") +
|
|
78
|
+
"token=" +
|
|
79
|
+
encodeURIComponent(this.authToken);
|
|
80
|
+
}
|
|
81
|
+
const ws = new this.Ctor(url);
|
|
82
|
+
ws.binaryType = "arraybuffer";
|
|
83
|
+
this.socket = ws;
|
|
84
|
+
ws.onopen = () => {
|
|
85
|
+
this.reconnectAttempts = 0;
|
|
86
|
+
this.setState("connected");
|
|
87
|
+
};
|
|
88
|
+
ws.onclose = () => {
|
|
89
|
+
this.socket = null;
|
|
90
|
+
if (this.intentionalClose) {
|
|
91
|
+
this.setState("disconnected");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.setState("reconnecting");
|
|
95
|
+
this.scheduleReconnect();
|
|
96
|
+
};
|
|
97
|
+
ws.onerror = () => this.setState("error");
|
|
98
|
+
ws.onmessage = (ev) => this.handleRaw(ev.data);
|
|
99
|
+
}
|
|
100
|
+
/** Close the socket and cancel any pending reconnect. */
|
|
101
|
+
disconnect() {
|
|
102
|
+
this.intentionalClose = true;
|
|
103
|
+
if (this.reconnectTimer) {
|
|
104
|
+
clearTimeout(this.reconnectTimer);
|
|
105
|
+
this.reconnectTimer = null;
|
|
106
|
+
}
|
|
107
|
+
this.socket?.close();
|
|
108
|
+
}
|
|
109
|
+
/** Send a `chat_message` command. */
|
|
110
|
+
send(opts) {
|
|
111
|
+
this.sendCommand({
|
|
112
|
+
command: "chat_message",
|
|
113
|
+
data: {
|
|
114
|
+
type: "message",
|
|
115
|
+
role: "user",
|
|
116
|
+
content: [{ type: "text", text: opts.text }],
|
|
117
|
+
thread_id: opts.threadId,
|
|
118
|
+
model: opts.model ?? null,
|
|
119
|
+
provider: opts.provider ?? null,
|
|
120
|
+
agent_mode: opts.agentMode ?? false,
|
|
121
|
+
tools: opts.tools ?? null,
|
|
122
|
+
collections: opts.collections ?? null,
|
|
123
|
+
permission_mode: opts.permissionMode ?? null
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/** Send a `stop` command for the given thread. */
|
|
128
|
+
stop(threadId) {
|
|
129
|
+
this.sendCommand({ command: "stop", data: { thread_id: threadId } });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Reattach to a thread's in-flight turn after a disconnect: the server
|
|
133
|
+
* replays every frame it stamped after `lastSeq`, so a dropped socket costs
|
|
134
|
+
* no output and no second inference.
|
|
135
|
+
*/
|
|
136
|
+
resume(threadId, lastSeq) {
|
|
137
|
+
this.sendCommand({
|
|
138
|
+
command: "resume_chat",
|
|
139
|
+
data: { thread_id: threadId, last_seq: lastSeq }
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
setState(state) {
|
|
143
|
+
if (this.state === state)
|
|
144
|
+
return;
|
|
145
|
+
this.state = state;
|
|
146
|
+
this.emit("state", state);
|
|
147
|
+
}
|
|
148
|
+
emit(event, payload) {
|
|
149
|
+
for (const fn of this.listeners[event]) {
|
|
150
|
+
try {
|
|
151
|
+
fn(payload);
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
// Don't let one buggy listener break the dispatcher.
|
|
155
|
+
console.error("[ChatSocket] listener for", event, "threw:", err);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
sendCommand(payload) {
|
|
160
|
+
if (!this.socket || this.socket.readyState !== this.Ctor.OPEN) {
|
|
161
|
+
throw new Error("WebSocket is not connected");
|
|
162
|
+
}
|
|
163
|
+
let frame;
|
|
164
|
+
try {
|
|
165
|
+
frame = pack(payload);
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
console.warn("[ChatSocket] msgpack encode failed, falling back to JSON:", err);
|
|
169
|
+
frame = JSON.stringify(payload);
|
|
170
|
+
}
|
|
171
|
+
// SAFETY: msgpackr owns encoded frames, so their backing store is an
|
|
172
|
+
// ArrayBuffer. Its declaration also covers shared buffers supplied by callers.
|
|
173
|
+
this.socket.send(frame);
|
|
174
|
+
}
|
|
175
|
+
handleRaw(inbound) {
|
|
176
|
+
const frame = isTextFrame(inbound)
|
|
177
|
+
? parseTextFrame(inbound)
|
|
178
|
+
: decodeBinaryFrame(inbound);
|
|
179
|
+
if (!frame)
|
|
180
|
+
return;
|
|
181
|
+
this.emit("raw", frame);
|
|
182
|
+
const type = frame.type;
|
|
183
|
+
if (isKnownEventType(type)) {
|
|
184
|
+
// SAFETY: `isKnownEventType` proved the tag is one of `EventMap`'s
|
|
185
|
+
// discriminated keys, so the frame is that key's payload. TypeScript
|
|
186
|
+
// cannot correlate a union key with its own payload across the generic
|
|
187
|
+
// `emit` call.
|
|
188
|
+
this.emit(type, frame);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
scheduleReconnect() {
|
|
192
|
+
if (this.maxReconnect === 0) {
|
|
193
|
+
this.setState("error");
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (this.reconnectAttempts >= this.maxReconnect) {
|
|
197
|
+
this.setState("error");
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
this.reconnectAttempts++;
|
|
201
|
+
const delay = Math.min(this.reconnectDelayMs * this.reconnectAttempts, MAX_RECONNECT_MS);
|
|
202
|
+
this.reconnectTimer = setTimeout(() => this.connect(), delay);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const KNOWN_TYPES = new Set([
|
|
206
|
+
"chunk",
|
|
207
|
+
"message",
|
|
208
|
+
"tool_call",
|
|
209
|
+
"error",
|
|
210
|
+
"generation_stopped",
|
|
211
|
+
"thread_update",
|
|
212
|
+
"planning_update",
|
|
213
|
+
"task_update"
|
|
214
|
+
]);
|
|
215
|
+
function isKnownEventType(type) {
|
|
216
|
+
return KNOWN_TYPES.has(type);
|
|
217
|
+
}
|
|
218
|
+
function isTextFrame(inbound) {
|
|
219
|
+
return typeof inbound === "string";
|
|
220
|
+
}
|
|
221
|
+
/** `typeof` calls null, arrays and byte blobs "object" too; a frame body is none of those. */
|
|
222
|
+
function isFrameFields(value) {
|
|
223
|
+
return (typeof value === "object" &&
|
|
224
|
+
value !== null &&
|
|
225
|
+
!Array.isArray(value) &&
|
|
226
|
+
!(value instanceof Uint8Array));
|
|
227
|
+
}
|
|
228
|
+
function isFrameTag(value) {
|
|
229
|
+
return typeof value === "string";
|
|
230
|
+
}
|
|
231
|
+
function toChatEvent(decoded) {
|
|
232
|
+
if (!isFrameFields(decoded) || !isFrameTag(decoded.type))
|
|
233
|
+
return null;
|
|
234
|
+
// SAFETY: the two predicates above establish exactly what `ChatEvent`'s
|
|
235
|
+
// widest member `ChatRawEvent` declares — a keyed frame body with a string
|
|
236
|
+
// `type`. Tags we model narrow further in `handleRaw`.
|
|
237
|
+
return decoded;
|
|
238
|
+
}
|
|
239
|
+
function parseTextFrame(text) {
|
|
240
|
+
try {
|
|
241
|
+
return toChatEvent(JSON.parse(text));
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
console.error("[ChatSocket] failed to parse JSON frame:", err);
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function decodeBinaryFrame(inbound) {
|
|
249
|
+
try {
|
|
250
|
+
return toChatEvent(unpack(frameBytes(inbound)));
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
console.error("[ChatSocket] failed to decode msgpack frame:", err);
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/** Some platforms deliver a Buffer-like view rather than a bare `ArrayBuffer`. */
|
|
258
|
+
function frameBytes(inbound) {
|
|
259
|
+
return inbound instanceof ArrayBuffer
|
|
260
|
+
? new Uint8Array(inbound)
|
|
261
|
+
: new Uint8Array(inbound.buffer, inbound.byteOffset, inbound.byteLength);
|
|
262
|
+
}
|
|
263
|
+
function globalCtor() {
|
|
264
|
+
if (typeof WebSocket !== "undefined")
|
|
265
|
+
return WebSocket;
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=chat.js.map
|
package/dist/chat.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../src/chat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAqKxC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,MAAM,OAAO,UAAU;IACJ,GAAG,CAAS;IACZ,SAAS,CAAgB;IACzB,IAAI,CAAgB;IACpB,gBAAgB,CAAS;IACzB,YAAY,CAAS;IAE9B,MAAM,GAAqB,IAAI,CAAC;IAChC,KAAK,GAAoB,MAAM,CAAC;IAChC,gBAAgB,GAAG,KAAK,CAAC;IACzB,iBAAiB,GAAG,CAAC,CAAC;IACtB,cAAc,GAAyC,IAAI,CAAC;IACnD,SAAS,GAAkB;QAC1C,KAAK,EAAE,IAAI,GAAG,EAAE;QAChB,OAAO,EAAE,IAAI,GAAG,EAAE;QAClB,SAAS,EAAE,IAAI,GAAG,EAAE;QACpB,KAAK,EAAE,IAAI,GAAG,EAAE;QAChB,kBAAkB,EAAE,IAAI,GAAG,EAAE;QAC7B,aAAa,EAAE,IAAI,GAAG,EAAE;QACxB,eAAe,EAAE,I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SAAS,UAAU,CAAC,OAAsC;IACxD,OAAO,OAAO,YAAY,WAAW;QACnC,CAAC,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC;QACzB,CAAC,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,UAAU;IACjB,IAAI,OAAO,SAAS,KAAK,WAAW;QAAE,OAAO,SAAS,CAAC;IACvD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type CreateTRPCClient } from "@trpc/client";
|
|
2
|
+
import type { AppRouter } from "@nodetool-ai/websocket/trpc";
|
|
3
|
+
import { ChatSocket, type WebSocketCtor } from "./chat.js";
|
|
4
|
+
export interface CreateNodetoolClientOptions {
|
|
5
|
+
/** Server base URL, e.g. `http://localhost:7777`. */
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
/**
|
|
8
|
+
* Optional bearer token. Sent as `Authorization: Bearer <token>` on every
|
|
9
|
+
* tRPC and REST call, and appended as `?token=<token>` on the chat WebSocket.
|
|
10
|
+
*/
|
|
11
|
+
authToken?: string | null;
|
|
12
|
+
/**
|
|
13
|
+
* Override `fetch`. Defaults to the global `fetch`. Pass a wrapped fetch to
|
|
14
|
+
* inject extra headers, observability, etc.
|
|
15
|
+
*/
|
|
16
|
+
fetch?: typeof fetch;
|
|
17
|
+
/**
|
|
18
|
+
* `WebSocket` constructor for environments without a global one (e.g. Node).
|
|
19
|
+
* Browsers: leave undefined to use the built-in `WebSocket`.
|
|
20
|
+
* Node 18+: pass `WebSocket` from the `ws` package.
|
|
21
|
+
*/
|
|
22
|
+
WebSocket?: WebSocketCtor;
|
|
23
|
+
}
|
|
24
|
+
export interface NodetoolClient {
|
|
25
|
+
/** Server base URL. */
|
|
26
|
+
readonly baseUrl: string;
|
|
27
|
+
/** Auth token used for new sockets and tRPC calls. */
|
|
28
|
+
readonly authToken: string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Typed tRPC client covering the full {@link AppRouter} surface
|
|
31
|
+
* (threads, messages, models, workflows, jobs, assets, settings, …).
|
|
32
|
+
*/
|
|
33
|
+
readonly trpc: CreateTRPCClient<AppRouter>;
|
|
34
|
+
/**
|
|
35
|
+
* Open a new chat WebSocket. The returned {@link ChatSocket} is an
|
|
36
|
+
* event emitter for `chunk` / `message` / `tool_call` / `error` frames
|
|
37
|
+
* and exposes `send()` and `stop()` for outbound commands.
|
|
38
|
+
*
|
|
39
|
+
* Multiple chat sockets can be opened against the same client — typical use
|
|
40
|
+
* is one-per-active-thread.
|
|
41
|
+
*/
|
|
42
|
+
chat(): ChatSocket;
|
|
43
|
+
/**
|
|
44
|
+
* Convenience helper: list every LLM model from every provider that
|
|
45
|
+
* advertises the `generate_message` capability and is configured for the
|
|
46
|
+
* current user. Output is a flat list with `{ id, name, provider }`.
|
|
47
|
+
*/
|
|
48
|
+
listLanguageModels(): Promise<Array<{
|
|
49
|
+
id: string;
|
|
50
|
+
name: string;
|
|
51
|
+
provider: string;
|
|
52
|
+
}>>;
|
|
53
|
+
}
|
|
54
|
+
export declare function createNodetoolClient(options: CreateNodetoolClientOptions): NodetoolClient;
|
|
55
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAE3D,MAAM,WAAW,2BAA2B;IAC1C,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,uBAAuB;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,sDAAsD;IACtD,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC3C;;;;;;;OAOG;IACH,IAAI,IAAI,UAAU,CAAC;IACnB;;;;OAIG;IACH,kBAAkB,IAAI,OAAO,CAC3B,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CACtD,CAAC;CACH;AAeD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,2BAA2B,GACnC,cAAc,CA+DhB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createTRPCClient, httpBatchLink } from "@trpc/client";
|
|
2
|
+
import { TRPC_MAX_BATCH_SIZE } from "@nodetool-ai/protocol";
|
|
3
|
+
import { ChatSocket } from "./chat.js";
|
|
4
|
+
function trimTrailingSlash(s) {
|
|
5
|
+
return s.endsWith("/") ? s.slice(0, -1) : s;
|
|
6
|
+
}
|
|
7
|
+
function defaultFetch() {
|
|
8
|
+
if (typeof fetch === "undefined") {
|
|
9
|
+
throw new Error("No global `fetch` available — pass `fetch` in CreateNodetoolClientOptions");
|
|
10
|
+
}
|
|
11
|
+
return fetch;
|
|
12
|
+
}
|
|
13
|
+
export function createNodetoolClient(options) {
|
|
14
|
+
const baseUrl = trimTrailingSlash(options.baseUrl);
|
|
15
|
+
const authToken = options.authToken ?? null;
|
|
16
|
+
const fetchImpl = options.fetch ?? defaultFetch();
|
|
17
|
+
const trpc = createTRPCClient({
|
|
18
|
+
links: [
|
|
19
|
+
httpBatchLink({
|
|
20
|
+
url: `${baseUrl}/trpc`,
|
|
21
|
+
// Cap the batch: tRPC joins every procedure name into one URL path
|
|
22
|
+
// segment, and Fastify's router rejects a segment over `maxParamLength`
|
|
23
|
+
// with a 404. A model-picker mount batched 116 procedures into a ~2900
|
|
24
|
+
// char path and got nothing back.
|
|
25
|
+
maxItems: TRPC_MAX_BATCH_SIZE,
|
|
26
|
+
// POST keeps the batched input in the request body instead of the URL,
|
|
27
|
+
// so large batches stay under reverse-proxy URL-length limits. See #3979.
|
|
28
|
+
methodOverride: "POST",
|
|
29
|
+
fetch: fetchImpl,
|
|
30
|
+
headers() {
|
|
31
|
+
return authToken ? { Authorization: `Bearer ${authToken}` } : {};
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
]
|
|
35
|
+
});
|
|
36
|
+
const wsUrl = baseUrl.replace(/^http(s?):\/\//, (_, s) => `ws${s}://`) + "/ws";
|
|
37
|
+
return {
|
|
38
|
+
baseUrl,
|
|
39
|
+
authToken,
|
|
40
|
+
trpc,
|
|
41
|
+
chat() {
|
|
42
|
+
return new ChatSocket({
|
|
43
|
+
url: wsUrl,
|
|
44
|
+
authToken,
|
|
45
|
+
WebSocket: options.WebSocket
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
async listLanguageModels() {
|
|
49
|
+
const providers = await trpc.models.providers.query();
|
|
50
|
+
const llmProviders = providers.filter((p) => p.capabilities.includes("generate_message"));
|
|
51
|
+
const groups = await Promise.all(llmProviders.map(async (p) => {
|
|
52
|
+
try {
|
|
53
|
+
const models = await trpc.models.llmByProvider.query({
|
|
54
|
+
provider: p.provider
|
|
55
|
+
});
|
|
56
|
+
return models.map((m) => ({
|
|
57
|
+
id: m.id ?? m.name,
|
|
58
|
+
name: m.name ?? m.id,
|
|
59
|
+
provider: p.provider
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
return groups.flat();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,aAAa,EAEd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,UAAU,EAAsB,MAAM,WAAW,CAAC;AAoD3D,SAAS,iBAAiB,CAAC,CAAS;IAClC,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,YAAY;IACnB,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,OAAoC;IAEpC,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACnD,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;IAC5C,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,IAAI,YAAY,EAAE,CAAC;IAElD,MAAM,IAAI,GAAgC,gBAAgB,CAAY;QACpE,KAAK,EAAE;YACL,aAAa,CAAC;gBACZ,GAAG,EAAE,GAAG,OAAO,OAAO;gBACtB,mEAAmE;gBACnE,wEAAwE;gBACxE,uEAAuE;gBACvE,kCAAkC;gBAClC,QAAQ,EAAE,mBAAmB;gBAC7B,uEAAuE;gBACvE,0EA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CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE;wBACpB,QAAQ,EAAE,CAAC,CAAC,QAAQ;qBACrB,CAAC,CAAC,CAAC;gBACN,CAAC;gBAAC,MAAM,CAAC;oBACP,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,CACH,CAAC;YACF,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nodetool-ai/sdk — TypeScript SDK for the NodeTool server.
|
|
3
|
+
*
|
|
4
|
+
* Surfaces:
|
|
5
|
+
* - `createNodetoolClient()` — typed tRPC client (full AppRouter coverage)
|
|
6
|
+
* plus a `.chat()` factory for the streaming WebSocket.
|
|
7
|
+
* - `ChatSocket` — typed event-emitter wrapper around the chat WebSocket
|
|
8
|
+
* protocol (msgpack frames, with JSON fallback).
|
|
9
|
+
*
|
|
10
|
+
* Works in both browsers (native `WebSocket`/`fetch`) and Node ≥18 (native
|
|
11
|
+
* `fetch`; pass a `WebSocket` constructor from the `ws` package).
|
|
12
|
+
*/
|
|
13
|
+
export { createNodetoolClient } from "./client.js";
|
|
14
|
+
export type { NodetoolClient, CreateNodetoolClientOptions } from "./client.js";
|
|
15
|
+
export { ChatSocket } from "./chat.js";
|
|
16
|
+
export type { ChatEvent, ChatChunkEvent, ChatMessageEvent, ChatToolCallEvent, ChatErrorEvent, ChatGenerationStoppedEvent, ChatThreadUpdateEvent, ChatRawEvent, ChatFrameFields, ChatFrameValue, SendChatMessageOptions, ChatSocketOptions, ConnectionState, WebSocketCtor } from "./chat.js";
|
|
17
|
+
export type { AppRouter } from "@nodetool-ai/websocket/trpc";
|
|
18
|
+
export type { Chunk, ContentType, JobStatus, TaskUpdate, PlanningUpdate, ToolCallUpdate, ErrorMessage } from "@nodetool-ai/protocol";
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EACV,cAAc,EACd,2BAA2B,EAC5B,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,YAAY,EACV,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,0BAA0B,EAC1B,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,EACf,aAAa,EACd,MAAM,WAAW,CAAC;AAInB,YAAY,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAG7D,YAAY,EACV,KAAK,EACL,WAAW,EACX,SAAS,EACT,UAAU,EACV,cAAc,EACd,cAAc,EACd,YAAY,EACb,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nodetool-ai/sdk — TypeScript SDK for the NodeTool server.
|
|
3
|
+
*
|
|
4
|
+
* Surfaces:
|
|
5
|
+
* - `createNodetoolClient()` — typed tRPC client (full AppRouter coverage)
|
|
6
|
+
* plus a `.chat()` factory for the streaming WebSocket.
|
|
7
|
+
* - `ChatSocket` — typed event-emitter wrapper around the chat WebSocket
|
|
8
|
+
* protocol (msgpack frames, with JSON fallback).
|
|
9
|
+
*
|
|
10
|
+
* Works in both browsers (native `WebSocket`/`fetch`) and Node ≥18 (native
|
|
11
|
+
* `fetch`; pass a `WebSocket` constructor from the `ws` package).
|
|
12
|
+
*/
|
|
13
|
+
export { createNodetoolClient } from "./client.js";
|
|
14
|
+
export { ChatSocket } from "./chat.js";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAMnD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nodetool-ai/sdk",
|
|
3
|
+
"version": "0.8.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=22.0.0"
|
|
7
|
+
},
|
|
8
|
+
"description": "TypeScript SDK for the NodeTool server — typed tRPC client + chat WebSocket",
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"module": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"nodetool-dev": "./src/index.ts",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "node ../../scripts/build-typescript-workspace.mjs",
|
|
22
|
+
"lint": "node ../../scripts/run-tsc.mjs --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@nodetool-ai/protocol": "^0.8.1",
|
|
26
|
+
"@nodetool-ai/websocket": "^0.8.1",
|
|
27
|
+
"@trpc/client": "^11.17.0",
|
|
28
|
+
"msgpackr": "^1.10.2"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^22.0.0",
|
|
32
|
+
"@types/ws": "^8.5.13",
|
|
33
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
34
|
+
"ws": "^8.18.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"ws": "^8.18.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"ws": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/nodetool-ai/nodetool.git",
|
|
48
|
+
"directory": "packages/sdk"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://nodetool.ai",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/nodetool-ai/nodetool/issues"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"dist",
|
|
59
|
+
"README.md"
|
|
60
|
+
],
|
|
61
|
+
"keywords": [
|
|
62
|
+
"nodetool",
|
|
63
|
+
"ai",
|
|
64
|
+
"workflow",
|
|
65
|
+
"workflow-automation",
|
|
66
|
+
"typescript",
|
|
67
|
+
"sdk",
|
|
68
|
+
"trpc",
|
|
69
|
+
"client",
|
|
70
|
+
"websocket",
|
|
71
|
+
"api-client"
|
|
72
|
+
]
|
|
73
|
+
}
|