10xgraph-client 0.6.0 → 1.0.0-rc.2
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/CHANGELOG.md +207 -0
- package/README.md +11 -5
- package/dist/agent.d.ts +17 -5
- package/dist/agent.d.ts.map +1 -1
- package/dist/cjs/agent.d.ts +33 -0
- package/dist/cjs/client.d.ts +533 -0
- package/dist/cjs/compat.d.ts +27 -0
- package/dist/cjs/endpoints/addThreadMessages.d.ts +25 -0
- package/dist/cjs/endpoints/clearThreadState.d.ts +14 -0
- package/dist/cjs/endpoints/deleteFile.d.ts +13 -0
- package/dist/cjs/endpoints/deleteMemory.d.ts +18 -0
- package/dist/cjs/endpoints/deleteThread.d.ts +18 -0
- package/dist/cjs/endpoints/deleteThreadMessage.d.ts +19 -0
- package/dist/cjs/endpoints/files.d.ts +115 -0
- package/dist/cjs/endpoints/fixGraph.d.ts +33 -0
- package/dist/cjs/endpoints/forgetMemories.d.ts +21 -0
- package/dist/cjs/endpoints/getMemory.d.ts +18 -0
- package/dist/cjs/endpoints/graph.d.ts +50 -0
- package/dist/cjs/endpoints/graphTools.d.ts +31 -0
- package/dist/cjs/endpoints/invoke.d.ts +66 -0
- package/dist/cjs/endpoints/listMemories.d.ts +24 -0
- package/dist/cjs/endpoints/metadata.d.ts +5 -0
- package/dist/cjs/endpoints/observability.d.ts +111 -0
- package/dist/cjs/endpoints/ping.d.ts +9 -0
- package/dist/cjs/endpoints/realtime.d.ts +154 -0
- package/dist/cjs/endpoints/searchMemory.d.ts +56 -0
- package/dist/cjs/endpoints/stateSchema.d.ts +49 -0
- package/dist/cjs/endpoints/stopGraph.d.ts +35 -0
- package/dist/cjs/endpoints/storeMemory.d.ts +32 -0
- package/dist/cjs/endpoints/stream.d.ts +67 -0
- package/dist/cjs/endpoints/threadDetails.d.ts +18 -0
- package/dist/cjs/endpoints/threadMessage.d.ts +16 -0
- package/dist/cjs/endpoints/threadMessages.d.ts +28 -0
- package/dist/cjs/endpoints/threadState.d.ts +13 -0
- package/dist/cjs/endpoints/threads.d.ts +35 -0
- package/dist/cjs/endpoints/updateMemory.d.ts +20 -0
- package/dist/cjs/endpoints/updateThreadMessageFeedback.d.ts +19 -0
- package/dist/cjs/endpoints/updateThreadState.d.ts +22 -0
- package/dist/cjs/endpoints/wsStream.d.ts +34 -0
- package/dist/cjs/errors.d.ts +212 -0
- package/dist/cjs/index.d.ts +41 -0
- package/dist/cjs/interrupt.d.ts +45 -0
- package/dist/cjs/message.d.ts +173 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/request.d.ts +60 -0
- package/dist/cjs/tools.d.ts +80 -0
- package/dist/cjs/ws.d.ts +47 -0
- package/dist/client.d.ts +95 -40
- package/dist/client.d.ts.map +1 -1
- package/dist/endpoints/addThreadMessages.d.ts +4 -0
- package/dist/endpoints/addThreadMessages.d.ts.map +1 -1
- package/dist/endpoints/clearThreadState.d.ts.map +1 -1
- package/dist/endpoints/deleteFile.d.ts +14 -0
- package/dist/endpoints/deleteFile.d.ts.map +1 -0
- package/dist/endpoints/deleteMemory.d.ts.map +1 -1
- package/dist/endpoints/deleteThread.d.ts.map +1 -1
- package/dist/endpoints/deleteThreadMessage.d.ts.map +1 -1
- package/dist/endpoints/files.d.ts +33 -0
- package/dist/endpoints/files.d.ts.map +1 -1
- package/dist/endpoints/fixGraph.d.ts +8 -3
- package/dist/endpoints/fixGraph.d.ts.map +1 -1
- package/dist/endpoints/forgetMemories.d.ts.map +1 -1
- package/dist/endpoints/getMemory.d.ts.map +1 -1
- package/dist/endpoints/graph.d.ts +20 -8
- package/dist/endpoints/graph.d.ts.map +1 -1
- package/dist/endpoints/graphTools.d.ts.map +1 -1
- package/dist/endpoints/invoke.d.ts +8 -0
- package/dist/endpoints/invoke.d.ts.map +1 -1
- package/dist/endpoints/listMemories.d.ts +6 -0
- package/dist/endpoints/listMemories.d.ts.map +1 -1
- package/dist/endpoints/observability.d.ts +54 -0
- package/dist/endpoints/observability.d.ts.map +1 -1
- package/dist/endpoints/ping.d.ts.map +1 -1
- package/dist/endpoints/realtime.d.ts +25 -4
- package/dist/endpoints/realtime.d.ts.map +1 -1
- package/dist/endpoints/searchMemory.d.ts.map +1 -1
- package/dist/endpoints/stateSchema.d.ts.map +1 -1
- package/dist/endpoints/stopGraph.d.ts +13 -3
- package/dist/endpoints/stopGraph.d.ts.map +1 -1
- package/dist/endpoints/storeMemory.d.ts.map +1 -1
- package/dist/endpoints/stream.d.ts +8 -0
- package/dist/endpoints/stream.d.ts.map +1 -1
- package/dist/endpoints/threadDetails.d.ts.map +1 -1
- package/dist/endpoints/threadMessage.d.ts.map +1 -1
- package/dist/endpoints/threadMessages.d.ts +6 -0
- package/dist/endpoints/threadMessages.d.ts.map +1 -1
- package/dist/endpoints/threadState.d.ts.map +1 -1
- package/dist/endpoints/threads.d.ts +6 -0
- package/dist/endpoints/threads.d.ts.map +1 -1
- package/dist/endpoints/updateMemory.d.ts.map +1 -1
- package/dist/endpoints/updateThreadMessageFeedback.d.ts +20 -0
- package/dist/endpoints/updateThreadMessageFeedback.d.ts.map +1 -0
- package/dist/endpoints/updateThreadState.d.ts +6 -1
- package/dist/endpoints/updateThreadState.d.ts.map +1 -1
- package/dist/endpoints/wsStream.d.ts +2 -0
- package/dist/endpoints/wsStream.d.ts.map +1 -1
- package/dist/errors.d.ts +60 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1742 -1217
- package/dist/index.js.map +1 -1
- package/dist/interrupt.d.ts +46 -0
- package/dist/interrupt.d.ts.map +1 -0
- package/dist/request.d.ts +28 -0
- package/dist/request.d.ts.map +1 -1
- package/dist/tools.d.ts +14 -0
- package/dist/tools.d.ts.map +1 -1
- package/package.json +11 -6
- package/src/agent.ts +17 -4
- package/src/client.ts +248 -128
- package/src/endpoints/addThreadMessages.ts +15 -10
- package/src/endpoints/clearThreadState.ts +19 -20
- package/src/endpoints/deleteFile.ts +65 -0
- package/src/endpoints/deleteMemory.ts +9 -13
- package/src/endpoints/deleteThread.ts +9 -13
- package/src/endpoints/deleteThreadMessage.ts +9 -13
- package/src/endpoints/files.ts +164 -131
- package/src/endpoints/fixGraph.ts +15 -16
- package/src/endpoints/forgetMemories.ts +44 -60
- package/src/endpoints/getMemory.ts +9 -9
- package/src/endpoints/graph.ts +28 -21
- package/src/endpoints/graphTools.ts +7 -13
- package/src/endpoints/invoke.ts +105 -84
- package/src/endpoints/listMemories.ts +18 -13
- package/src/endpoints/observability.ts +77 -34
- package/src/endpoints/ping.ts +7 -13
- package/src/endpoints/realtime.ts +101 -39
- package/src/endpoints/searchMemory.ts +19 -13
- package/src/endpoints/stateSchema.ts +7 -13
- package/src/endpoints/stopGraph.ts +20 -16
- package/src/endpoints/storeMemory.ts +7 -8
- package/src/endpoints/stream.ts +179 -61
- package/src/endpoints/threadDetails.ts +9 -14
- package/src/endpoints/threadMessage.ts +9 -9
- package/src/endpoints/threadMessages.ts +15 -9
- package/src/endpoints/threadState.ts +19 -20
- package/src/endpoints/threads.ts +13 -12
- package/src/endpoints/updateMemory.ts +9 -9
- package/src/endpoints/updateThreadMessageFeedback.ts +80 -0
- package/src/endpoints/updateThreadState.ts +28 -22
- package/src/endpoints/wsStream.ts +167 -42
- package/src/errors.ts +332 -93
- package/src/index.ts +9 -0
- package/src/interrupt.ts +60 -0
- package/src/request.ts +134 -0
- package/src/tools.ts +95 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export * from './tools.js';
|
|
2
|
+
export * from './client.js';
|
|
3
|
+
export * from './errors.js';
|
|
4
|
+
export * from './request.js';
|
|
5
|
+
export * from './endpoints/ping.js';
|
|
6
|
+
export * from './endpoints/graph.js';
|
|
7
|
+
export * from './endpoints/graphTools.js';
|
|
8
|
+
export * from './endpoints/observability.js';
|
|
9
|
+
export * from './endpoints/stopGraph.js';
|
|
10
|
+
export * from './endpoints/fixGraph.js';
|
|
11
|
+
export * from './endpoints/stateSchema.js';
|
|
12
|
+
export * from './endpoints/threadState.js';
|
|
13
|
+
export * from './endpoints/updateThreadState.js';
|
|
14
|
+
export * from './endpoints/clearThreadState.js';
|
|
15
|
+
export * from './endpoints/threadMessages.js';
|
|
16
|
+
export * from './endpoints/addThreadMessages.js';
|
|
17
|
+
export * from './endpoints/threadMessage.js';
|
|
18
|
+
export * from './endpoints/deleteThreadMessage.js';
|
|
19
|
+
export * from './endpoints/updateThreadMessageFeedback.js';
|
|
20
|
+
export * from './endpoints/deleteThread.js';
|
|
21
|
+
export * from './endpoints/threads.js';
|
|
22
|
+
export * from './endpoints/threadDetails.js';
|
|
23
|
+
export * from './endpoints/invoke.js';
|
|
24
|
+
export * from './endpoints/stream.js';
|
|
25
|
+
export * from './interrupt.js';
|
|
26
|
+
export * from './endpoints/wsStream.js';
|
|
27
|
+
export * from './ws.js';
|
|
28
|
+
export * from './endpoints/realtime.js';
|
|
29
|
+
export * from './endpoints/storeMemory.js';
|
|
30
|
+
export * from './endpoints/searchMemory.js';
|
|
31
|
+
export * from './endpoints/getMemory.js';
|
|
32
|
+
export * from './endpoints/updateMemory.js';
|
|
33
|
+
export * from './endpoints/deleteMemory.js';
|
|
34
|
+
export * from './endpoints/listMemories.js';
|
|
35
|
+
export * from './endpoints/forgetMemories.js';
|
|
36
|
+
export * from './endpoints/files.js';
|
|
37
|
+
export * from './endpoints/deleteFile.js';
|
|
38
|
+
export * from './endpoints/metadata.js';
|
|
39
|
+
export * from './agent.js';
|
|
40
|
+
export * from './message.js';
|
|
41
|
+
export * from './compat.js';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { StreamChunk } from './endpoints/stream.js';
|
|
2
|
+
/**
|
|
3
|
+
* A pause raised by `interrupt()` in a graph node or tool, waiting for a resume value.
|
|
4
|
+
* Mirrors the server payload at `chunk.data.interrupt` of an `updates` chunk whose
|
|
5
|
+
* `status` is `"interrupted"`.
|
|
6
|
+
*/
|
|
7
|
+
export interface Interrupt {
|
|
8
|
+
/** Unique id of this pause; echo it as `interrupt_id` when resuming. */
|
|
9
|
+
id: string;
|
|
10
|
+
/** Stable position of the call within its node or tool call. */
|
|
11
|
+
key: string;
|
|
12
|
+
/** Node that was running when the graph paused. */
|
|
13
|
+
node: string;
|
|
14
|
+
/** Payload passed to `interrupt()`: what to approve or choose from. */
|
|
15
|
+
value?: unknown;
|
|
16
|
+
/** Human-readable prompt. */
|
|
17
|
+
message?: string | null;
|
|
18
|
+
/** Machine-readable reason, for example `"tool_approval"`. */
|
|
19
|
+
reason: string;
|
|
20
|
+
/** JSON Schema the resume value must follow. */
|
|
21
|
+
response_schema?: Record<string, unknown> | null;
|
|
22
|
+
/** Tool call that paused, when `interrupt()` ran inside a tool. */
|
|
23
|
+
tool_call_id?: string | null;
|
|
24
|
+
}
|
|
25
|
+
/** Spread into the `options` of `invoke`, `stream` or `wsStream` to answer an interrupt. */
|
|
26
|
+
export interface InterruptResume {
|
|
27
|
+
resume: unknown;
|
|
28
|
+
interrupt_id: string;
|
|
29
|
+
}
|
|
30
|
+
/** The pending interrupt carried by a stream chunk, or null when the chunk has none. */
|
|
31
|
+
export declare function getInterrupt(chunk: Pick<StreamChunk, 'event' | 'data'>): Interrupt | null;
|
|
32
|
+
/**
|
|
33
|
+
* Answer an interrupt with approval. `value` is what the interrupted code receives; it
|
|
34
|
+
* defaults to `true`. When the interrupt sets `response_schema`, pass a value that matches it.
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* await client.invoke([], { config: { thread_id }, ...approveInterrupt(interrupt) });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function approveInterrupt(interrupt: Interrupt, value?: unknown): InterruptResume;
|
|
41
|
+
/**
|
|
42
|
+
* Answer an interrupt with a cancel. The server resumes the interrupted code with `null`
|
|
43
|
+
* and does not check it against `response_schema`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function rejectInterrupt(interrupt: Interrupt): InterruptResume;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
export declare class MediaRef {
|
|
2
|
+
kind: 'url' | 'file_id' | 'data';
|
|
3
|
+
url?: string;
|
|
4
|
+
file_id?: string;
|
|
5
|
+
data_base64?: string;
|
|
6
|
+
mime_type?: string;
|
|
7
|
+
size_bytes?: number;
|
|
8
|
+
sha256?: string;
|
|
9
|
+
filename?: string;
|
|
10
|
+
width?: number;
|
|
11
|
+
height?: number;
|
|
12
|
+
duration_ms?: number;
|
|
13
|
+
page?: number;
|
|
14
|
+
constructor(kind?: 'url' | 'file_id' | 'data', url?: string, file_id?: string, data_base64?: string, mime_type?: string, size_bytes?: number, sha256?: string, filename?: string, width?: number, height?: number, duration_ms?: number, page?: number);
|
|
15
|
+
}
|
|
16
|
+
export declare class AnnotationRef {
|
|
17
|
+
url?: string;
|
|
18
|
+
file_id?: string;
|
|
19
|
+
page?: number;
|
|
20
|
+
index?: number;
|
|
21
|
+
title?: string;
|
|
22
|
+
constructor(url?: string, file_id?: string, page?: number, index?: number, title?: string);
|
|
23
|
+
}
|
|
24
|
+
export declare class TextBlock {
|
|
25
|
+
type: 'text';
|
|
26
|
+
text: string;
|
|
27
|
+
annotations: AnnotationRef[];
|
|
28
|
+
constructor(text?: string, annotations?: AnnotationRef[]);
|
|
29
|
+
}
|
|
30
|
+
export declare class ImageBlock {
|
|
31
|
+
type: 'image';
|
|
32
|
+
media: MediaRef;
|
|
33
|
+
alt_text?: string;
|
|
34
|
+
bbox?: number[];
|
|
35
|
+
constructor(media?: MediaRef, alt_text?: string, bbox?: number[]);
|
|
36
|
+
}
|
|
37
|
+
export declare class AudioBlock {
|
|
38
|
+
type: 'audio';
|
|
39
|
+
media: MediaRef;
|
|
40
|
+
transcript?: string;
|
|
41
|
+
sample_rate?: number;
|
|
42
|
+
channels?: number;
|
|
43
|
+
constructor(media?: MediaRef, transcript?: string, sample_rate?: number, channels?: number);
|
|
44
|
+
}
|
|
45
|
+
export declare class VideoBlock {
|
|
46
|
+
type: 'video';
|
|
47
|
+
media: MediaRef;
|
|
48
|
+
thumbnail?: MediaRef;
|
|
49
|
+
constructor(media?: MediaRef, thumbnail?: MediaRef);
|
|
50
|
+
}
|
|
51
|
+
export declare class DocumentBlock {
|
|
52
|
+
type: 'document';
|
|
53
|
+
media: MediaRef;
|
|
54
|
+
pages?: number[];
|
|
55
|
+
excerpt?: string;
|
|
56
|
+
constructor(media?: MediaRef, pages?: number[], excerpt?: string);
|
|
57
|
+
}
|
|
58
|
+
export declare class DataBlock {
|
|
59
|
+
type: 'data';
|
|
60
|
+
mime_type: string;
|
|
61
|
+
data_base64?: string;
|
|
62
|
+
media?: MediaRef;
|
|
63
|
+
constructor(mime_type?: string, data_base64?: string, media?: MediaRef);
|
|
64
|
+
}
|
|
65
|
+
export declare class ToolCallBlock {
|
|
66
|
+
type: 'tool_call';
|
|
67
|
+
id: string;
|
|
68
|
+
name: string;
|
|
69
|
+
args: Record<string, any>;
|
|
70
|
+
tool_type?: string;
|
|
71
|
+
constructor(id?: string, name?: string, args?: Record<string, any>, tool_type?: string);
|
|
72
|
+
}
|
|
73
|
+
export declare class RemoteToolCallBlock {
|
|
74
|
+
type: 'remote_tool_call';
|
|
75
|
+
id: string;
|
|
76
|
+
name: string;
|
|
77
|
+
args: Record<string, any>;
|
|
78
|
+
tool_type: string;
|
|
79
|
+
constructor(id?: string, name?: string, args?: Record<string, any>, tool_type?: string);
|
|
80
|
+
}
|
|
81
|
+
export declare class ToolResultBlock {
|
|
82
|
+
type: 'tool_result';
|
|
83
|
+
call_id: string;
|
|
84
|
+
output: any;
|
|
85
|
+
is_error: boolean;
|
|
86
|
+
status?: 'completed' | 'failed';
|
|
87
|
+
constructor(props: {
|
|
88
|
+
call_id: string;
|
|
89
|
+
output: any;
|
|
90
|
+
status: 'completed' | 'failed';
|
|
91
|
+
is_error: boolean;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
export declare class ReasoningBlock {
|
|
95
|
+
type: 'reasoning';
|
|
96
|
+
summary: string;
|
|
97
|
+
details?: string[];
|
|
98
|
+
constructor(summary?: string, details?: string[]);
|
|
99
|
+
}
|
|
100
|
+
export declare class AnnotationBlock {
|
|
101
|
+
type: 'annotation';
|
|
102
|
+
kind: 'citation' | 'note';
|
|
103
|
+
refs: AnnotationRef[];
|
|
104
|
+
spans?: [number, number][];
|
|
105
|
+
constructor(kind?: 'citation' | 'note', refs?: AnnotationRef[], spans?: [number, number][]);
|
|
106
|
+
}
|
|
107
|
+
export declare class ErrorBlock {
|
|
108
|
+
type: 'error';
|
|
109
|
+
message: string;
|
|
110
|
+
code?: string;
|
|
111
|
+
data?: Record<string, any>;
|
|
112
|
+
constructor(message?: string, code?: string, data?: Record<string, any>);
|
|
113
|
+
}
|
|
114
|
+
export type ContentBlock = TextBlock | ImageBlock | AudioBlock | VideoBlock | DocumentBlock | DataBlock | ToolCallBlock | RemoteToolCallBlock | ToolResultBlock | ReasoningBlock | AnnotationBlock | ErrorBlock;
|
|
115
|
+
export declare class TokenUsages {
|
|
116
|
+
completion_tokens: number;
|
|
117
|
+
prompt_tokens: number;
|
|
118
|
+
total_tokens: number;
|
|
119
|
+
reasoning_tokens: number;
|
|
120
|
+
cache_creation_input_tokens: number;
|
|
121
|
+
cache_read_input_tokens: number;
|
|
122
|
+
image_tokens?: number;
|
|
123
|
+
audio_tokens?: number;
|
|
124
|
+
}
|
|
125
|
+
export declare class Message {
|
|
126
|
+
message_id: string | null;
|
|
127
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
128
|
+
content: ContentBlock[];
|
|
129
|
+
delta: boolean;
|
|
130
|
+
tools_calls?: Record<string, any>[];
|
|
131
|
+
timestamp: number;
|
|
132
|
+
metadata: Record<string, any>;
|
|
133
|
+
usages?: TokenUsages;
|
|
134
|
+
raw?: Record<string, any>;
|
|
135
|
+
constructor(role: 'user' | 'assistant' | 'system' | 'tool', content: ContentBlock[], message_id?: string | null);
|
|
136
|
+
static text_message(content: string, role?: 'user' | 'assistant' | 'system' | 'tool', message_id?: string | null): Message;
|
|
137
|
+
static tool_message(content: ContentBlock[], message_id?: string | null, meta?: Record<string, any>): Message;
|
|
138
|
+
text(): string;
|
|
139
|
+
attach_media(media: MediaRef, as_type: 'image' | 'audio' | 'video' | 'document'): void;
|
|
140
|
+
/**
|
|
141
|
+
* Create a message with an image (via URL or base64).
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const msg = Message.withImage('Describe this', 'https://example.com/photo.jpg');
|
|
146
|
+
* const msg2 = Message.withImage('Describe this', 'data:image/png;base64,...');
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
static withImage(text: string, imageUrl: string, role?: 'user' | 'assistant' | 'system'): Message;
|
|
150
|
+
/**
|
|
151
|
+
* Create a message with a file reference (e.g. from uploadFile result).
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* const upload = await client.uploadFile(pdfFile);
|
|
156
|
+
* const msg = Message.withFile('Summarize this PDF', upload.data.file_id, 'application/pdf');
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
static withFile(text: string, fileId: string, mimeType?: string, role?: 'user' | 'assistant' | 'system'): Message;
|
|
160
|
+
/**
|
|
161
|
+
* Create a multimodal message with arbitrary content blocks.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const msg = Message.multimodal([
|
|
166
|
+
* new TextBlock('Look at these'),
|
|
167
|
+
* new ImageBlock(new MediaRef('url', 'https://...')),
|
|
168
|
+
* new ImageBlock(new MediaRef('url', 'https://...')),
|
|
169
|
+
* ]);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
static multimodal(blocks: ContentBlock[], role?: 'user' | 'assistant' | 'system'): Message;
|
|
173
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { WebSocketImpl } from './ws.js';
|
|
2
|
+
export interface TenxGraphBearerAuth {
|
|
3
|
+
type: 'bearer';
|
|
4
|
+
token: string;
|
|
5
|
+
}
|
|
6
|
+
export interface TenxGraphBasicAuth {
|
|
7
|
+
type: 'basic';
|
|
8
|
+
username: string;
|
|
9
|
+
password: string;
|
|
10
|
+
}
|
|
11
|
+
export interface TenxGraphHeaderAuth {
|
|
12
|
+
type: 'header';
|
|
13
|
+
name: string;
|
|
14
|
+
value: string;
|
|
15
|
+
prefix?: string | null;
|
|
16
|
+
}
|
|
17
|
+
export type TenxGraphAuth = TenxGraphBearerAuth | TenxGraphBasicAuth | TenxGraphHeaderAuth;
|
|
18
|
+
/**
|
|
19
|
+
* Abort `controller` when the caller's `signal` aborts. Returns a cleanup function.
|
|
20
|
+
* A signal that is already aborted aborts the controller immediately.
|
|
21
|
+
*/
|
|
22
|
+
export declare function linkAbortSignal(controller: AbortController, signal?: AbortSignal | null): () => void;
|
|
23
|
+
/** Per-call options accepted by every client method that makes a request. */
|
|
24
|
+
export interface RequestOptions {
|
|
25
|
+
/** Abort to cancel the request. Rejects with the signal's AbortError, never as a timeout. */
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
}
|
|
28
|
+
export interface RequestContext {
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
authToken?: string | null;
|
|
31
|
+
auth?: TenxGraphAuth | null;
|
|
32
|
+
headers?: HeadersInit;
|
|
33
|
+
credentials?: RequestCredentials;
|
|
34
|
+
timeout: number;
|
|
35
|
+
debug: boolean;
|
|
36
|
+
webSocketImpl?: WebSocketImpl;
|
|
37
|
+
/** Caller's cancellation signal for this call. Set per call by the client, not stored. */
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}
|
|
40
|
+
export declare function buildHeaders(context: Pick<RequestContext, 'authToken' | 'auth' | 'headers'>, defaults?: HeadersInit): Record<string, string>;
|
|
41
|
+
export declare function getRequestCredentials(context: Pick<RequestContext, 'credentials'>): Pick<RequestInit, 'credentials'> | Record<string, never>;
|
|
42
|
+
export declare function bearerAuth(token: string): TenxGraphBearerAuth;
|
|
43
|
+
export declare function basicAuth(username: string, password: string): TenxGraphBasicAuth;
|
|
44
|
+
export declare function headerAuth(name: string, value: string, prefix?: string | null): TenxGraphHeaderAuth;
|
|
45
|
+
/** Percent-encode one URL path segment (thread, message or memory id). */
|
|
46
|
+
export declare function encodePathSegment(value: string | number): string;
|
|
47
|
+
/** Strip trailing slashes so `${baseUrl}/path` never produces `//path`. */
|
|
48
|
+
export declare function normalizeBaseUrl(baseUrl: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* fetch with the shared client policy:
|
|
51
|
+
* - the timeout timer is always cleared (also when fetch rejects) and does not keep a Node
|
|
52
|
+
* process alive;
|
|
53
|
+
* - `context.signal` cancels the call (rejects with the AbortError, never as a timeout);
|
|
54
|
+
* - a timeout throws RequestTimeoutError, any other fetch rejection throws NetworkError
|
|
55
|
+
* with the original error as `cause`;
|
|
56
|
+
* - with header-type credentials other than Authorization (e.g. X-API-Key, which fetch does not
|
|
57
|
+
* strip on a redirect)
|
|
58
|
+
* redirects are followed only within the same origin; a cross-origin redirect is refused.
|
|
59
|
+
*/
|
|
60
|
+
export declare function fetchWithTimeout(context: Pick<RequestContext, 'timeout' | 'signal' | 'auth'>, url: string, init?: RequestInit): Promise<Response>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Message } from './message.js';
|
|
2
|
+
export interface ToolHandler {
|
|
3
|
+
(args: any): Promise<any>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* JSON Schema describing a tool's arguments.
|
|
7
|
+
*
|
|
8
|
+
* `properties` and `required` are optional, matching JSON Schema itself: a tool
|
|
9
|
+
* whose arguments are all optional needs neither, and a tool that takes no
|
|
10
|
+
* arguments can be declared as `{ type: 'object' }`. Additional JSON Schema
|
|
11
|
+
* keywords (`additionalProperties`, `$defs`, ...) are passed through untouched.
|
|
12
|
+
*/
|
|
13
|
+
export interface ToolParameter {
|
|
14
|
+
type: string;
|
|
15
|
+
properties?: Record<string, any>;
|
|
16
|
+
required?: string[];
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fill in the JSON Schema defaults a tool declaration may leave out, so the
|
|
21
|
+
* wire format sent to the server is always a complete object schema.
|
|
22
|
+
*/
|
|
23
|
+
export declare function normalizeToolParameters(parameters?: ToolParameter): ToolParameter;
|
|
24
|
+
export interface Tool {
|
|
25
|
+
type: string;
|
|
26
|
+
function: {
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
parameters: ToolParameter;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface ToolRegistration {
|
|
33
|
+
node?: string;
|
|
34
|
+
name: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
parameters?: ToolParameter;
|
|
37
|
+
handler: ToolHandler;
|
|
38
|
+
/**
|
|
39
|
+
* Runs on the server-sent arguments before the handler (after the declared `parameters`
|
|
40
|
+
* check). Throw, or return `false`, to reject the call: the model receives a failed tool
|
|
41
|
+
* result and the handler is not run.
|
|
42
|
+
*/
|
|
43
|
+
validate?: (args: any) => boolean | void | Promise<boolean | void>;
|
|
44
|
+
/** Reject calls whose JSON-serialised arguments exceed this many bytes. Default 1 MiB. */
|
|
45
|
+
maxArgsBytes?: number;
|
|
46
|
+
}
|
|
47
|
+
/** Default cap on serialised tool-call arguments. */
|
|
48
|
+
export declare const DEFAULT_MAX_TOOL_ARGS_BYTES: number;
|
|
49
|
+
/** Check `args` against the top level of a declared JSON Schema; returns an error message or null. */
|
|
50
|
+
export declare function checkToolArguments(args: unknown, parameters?: ToolParameter): string | null;
|
|
51
|
+
export interface ToolDefinition extends ToolHandler {
|
|
52
|
+
name: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
parameters?: ToolParameter;
|
|
55
|
+
node?: string;
|
|
56
|
+
validate?: ToolRegistration['validate'];
|
|
57
|
+
maxArgsBytes?: number;
|
|
58
|
+
}
|
|
59
|
+
export declare class ToolExecutor {
|
|
60
|
+
private tools;
|
|
61
|
+
private toolsByNode;
|
|
62
|
+
constructor(tools?: ToolDefinition[]);
|
|
63
|
+
/**
|
|
64
|
+
* Register a new tool
|
|
65
|
+
*/
|
|
66
|
+
registerTool(registration: ToolRegistration): void;
|
|
67
|
+
/**
|
|
68
|
+
* Get tools for a specific node
|
|
69
|
+
*/
|
|
70
|
+
getToolsForNode(node: string): ToolDefinition[];
|
|
71
|
+
/**
|
|
72
|
+
* Get all tools in OpenAI-compatible format
|
|
73
|
+
*/
|
|
74
|
+
all_tools(): Tool[];
|
|
75
|
+
/**
|
|
76
|
+
* Extract and execute all tool calls from the response
|
|
77
|
+
* Returns an array of tool result messages
|
|
78
|
+
*/
|
|
79
|
+
executeToolCalls(messages: Message[]): Promise<Message[]>;
|
|
80
|
+
}
|
package/dist/cjs/ws.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { TenxGraphAuth } from './request.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sec-WebSocket-Protocol token the server recognizes for browser-safe bearer auth.
|
|
4
|
+
* The client opens the socket with `[WS_BEARER_SUBPROTOCOL, "<jwt>"]`; the server
|
|
5
|
+
* extracts the second protocol entry as the token. This works in browsers (which
|
|
6
|
+
* cannot set request headers on a WebSocket) and avoids leaking the token in the URL.
|
|
7
|
+
*/
|
|
8
|
+
export declare const WS_BEARER_SUBPROTOCOL = "10xgraph-bearer";
|
|
9
|
+
/** Minimal constructor shape shared by the browser `WebSocket` and the Node `ws` package. */
|
|
10
|
+
export type WebSocketImpl = new (url: string, protocols?: string | string[], options?: unknown) => WebSocket;
|
|
11
|
+
/** The auth/transport fields the WS helpers read from a request context. */
|
|
12
|
+
export interface WsAuthContext {
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
authToken?: string | null;
|
|
15
|
+
auth?: TenxGraphAuth | null;
|
|
16
|
+
headers?: HeadersInit;
|
|
17
|
+
credentials?: RequestCredentials;
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
/** Optional WebSocket implementation for runtimes without a global (Node < 21). */
|
|
20
|
+
webSocketImpl?: WebSocketImpl;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolve the bearer token with the same priority as `buildHeaders`.
|
|
24
|
+
*
|
|
25
|
+
* `auth` takes precedence over `authToken`, matching the HTTP path. When `auth`
|
|
26
|
+
* is set to a non-bearer scheme (basic/header) there is no bearer token to send,
|
|
27
|
+
* so this returns `null` rather than silently falling back to `authToken` — the
|
|
28
|
+
* HTTP path would not send a bearer in that case either.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveBearerToken(context: Pick<WsAuthContext, 'authToken' | 'auth'>): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Convert the HTTP base URL to a WebSocket URL and append `path`.
|
|
33
|
+
* The token is never placed in the URL — it travels via the `10xgraph-bearer`
|
|
34
|
+
* subprotocol (browser-safe) and, in Node, the Authorization header.
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildWsUrl(context: Pick<WsAuthContext, 'baseUrl'>, path: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Open a WebSocket with bearer auth.
|
|
39
|
+
*
|
|
40
|
+
* - If a token is present it is sent as the `10xgraph-bearer` subprotocol (works
|
|
41
|
+
* in browsers and Node `ws`).
|
|
42
|
+
* - In Node-style implementations that accept a third `options` argument, the
|
|
43
|
+
* Authorization header is also passed (ignored by browsers).
|
|
44
|
+
* - The implementation is taken from `context.webSocketImpl`, falling back to the
|
|
45
|
+
* global `WebSocket`. If neither exists a descriptive error is thrown.
|
|
46
|
+
*/
|
|
47
|
+
export declare function openWebSocket(url: string, context: WsAuthContext): WebSocket;
|