@dexto/client-sdk 1.2.3 → 1.2.5

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,57 @@
1
+ import type { StreamingEvent } from '@dexto/core';
2
+ /**
3
+ * SSE (Server-Sent Events) streaming utilities for client SDK
4
+ * Adapted from @dexto/webui EventStreamClient
5
+ */
6
+ export type MessageStreamEvent = StreamingEvent;
7
+ export interface SSEEvent<T = string> {
8
+ event?: string;
9
+ data?: T;
10
+ id?: string;
11
+ retry?: number;
12
+ }
13
+ export declare class SSEError extends Error {
14
+ status: number;
15
+ body: any;
16
+ constructor(status: number, body: any);
17
+ }
18
+ /**
19
+ * Creates an async generator that yields SSE events from a Response object.
20
+ *
21
+ * @param response The fetch Response object containing the SSE stream
22
+ * @param options Optional configuration including AbortSignal
23
+ */
24
+ export declare function stream<T = string>(response: Response, options?: {
25
+ signal?: AbortSignal;
26
+ }): AsyncGenerator<SSEEvent<T>>;
27
+ /**
28
+ * Helper to create a stream from a promise that resolves to a Response.
29
+ * Useful for chaining with Hono client requests.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const stream = createStream(client.api.chat.$post({ json: { message: 'hi' } }));
34
+ * for await (const event of stream) { ... }
35
+ * ```
36
+ */
37
+ export declare function createStream<T = string>(responsePromise: Promise<Response>, options?: {
38
+ signal?: AbortSignal;
39
+ }): AsyncGenerator<SSEEvent<T>>;
40
+ /**
41
+ * Helper to create a typed message stream from a promise that resolves to a Response.
42
+ * Automatically parses JSON data and yields typed MessageStreamEvent objects.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const stream = createMessageStream(client.api['message-stream'].$post({ ... }));
47
+ * for await (const event of stream) {
48
+ * if (event.type === 'llm:chunk') {
49
+ * console.log(event.content);
50
+ * }
51
+ * }
52
+ * ```
53
+ */
54
+ export declare function createMessageStream(responsePromise: Promise<Response>, options?: {
55
+ signal?: AbortSignal;
56
+ }): AsyncGenerator<MessageStre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+ /**
2
+ * Client configuration for Dexto SDK
3
+ */
4
+ export interface ClientConfig {
5
+ /** Base URL of the Dexto server */
6
+ baseUrl: string;
7
+ /** Optional API key for authentication */
8
+ apiKey?: string;
9
+ }
10
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dexto/client-sdk",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -16,7 +16,14 @@
16
16
  "./package.json": "./package.json"
17
17
  },
18
18
  "dependencies": {
19
- "@dexto/core": "1.2.3"
19
+ "hono": "^4.6.14"
20
+ },
21
+ "devDependencies": {
22
+ "tsup": "^8.0.2",
23
+ "typescript": "^5.4.2",
24
+ "vitest": "^1.3.1",
25
+ "@dexto/core": "1.2.5",
26
+ "@dexto/server": "1.2.5"
20
27
  },
21
28
  "files": [
22
29
  "dist",
@@ -27,8 +34,9 @@
27
34
  },
28
35
  "sideEffects": false,
29
36
  "scripts": {
30
- "build": "tsup",
31
- "typecheck": "tsc -p tsconfig.json --noEmit",
37
+ "build": "tsup && tsc -p tsconfig.json --emitDeclarationOnly",
38
+ "dev": "tsup --watch",
39
+ "typecheck": "tsc -p tsconfig.typecheck.json --noEmit",
32
40
  "lint": "eslint . --ext .ts,.tsx",
33
41
  "test": "vitest run",
34
42
  "test:watch": "vitest watch"
package/dist/index.d.cts DELETED
@@ -1,232 +0,0 @@
1
- import { ImageData, FileData, ProviderInfo, LLMRouter, SupportedFileType, ModelInfo, McpServerConfig, ToolSet, AgentEventMap, SessionEventMap, SessionMetadata, LLMConfig, SearchOptions, SearchResponse, SessionSearchResponse } from '@dexto/core';
2
- export { AgentEventMap, FileData, ImageData, InternalMessage, LLMConfig, LLMProvider, LLMRouter, McpServerConfig, ModelInfo, ProviderInfo, SearchOptions, SearchResponse, SearchResult, SessionEventMap, SessionMetadata, SessionSearchResponse, SessionSearchResult, SupportedFileType, ToolSet } from '@dexto/core';
3
-
4
- interface ClientConfig {
5
- baseUrl: string;
6
- apiKey?: string | undefined;
7
- timeout?: number | undefined;
8
- retries?: number | undefined;
9
- }
10
- interface ClientOptions {
11
- enableWebSocket?: boolean | undefined;
12
- reconnect?: boolean | undefined;
13
- reconnectInterval?: number | undefined;
14
- debug?: boolean | undefined;
15
- }
16
- interface MessageInput {
17
- content: string;
18
- imageData?: ImageData;
19
- fileData?: FileData;
20
- sessionId?: string;
21
- stream?: boolean;
22
- }
23
- interface MessageResponse {
24
- response: string;
25
- sessionId: string;
26
- }
27
- type ClientProviderInfo = ProviderInfo;
28
- type McpServer = McpServerConfig;
29
- type Tool = ToolSet;
30
- type CatalogModel = ModelInfo;
31
- type CatalogProvider = ProviderInfo;
32
- interface CatalogOptions {
33
- provider?: string;
34
- hasKey?: boolean;
35
- router?: LLMRouter;
36
- fileType?: SupportedFileType;
37
- defaultOnly?: boolean;
38
- mode?: 'grouped' | 'flat';
39
- }
40
- interface CatalogResponse {
41
- providers?: Record<string, CatalogProvider>;
42
- models?: Array<CatalogModel & {
43
- provider: string;
44
- }>;
45
- }
46
- type DextoEvent = {
47
- [K in keyof AgentEventMap as K extends string ? K : never]: {
48
- type: K;
49
- data: AgentEventMap[K];
50
- };
51
- }[keyof AgentEventMap] | {
52
- [K in keyof SessionEventMap as K extends string ? K : never]: {
53
- type: K;
54
- data: SessionEventMap[K];
55
- sessionId: string;
56
- };
57
- }[keyof SessionEventMap];
58
-
59
- type EventHandler = (event: DextoEvent) => void;
60
-
61
- /**
62
- * Dexto Client SDK - Ultra-lightweight HTTP/WebSocket wrapper
63
- *
64
- * This SDK provides a thin interface for interacting with Dexto API.
65
- * All validation is handled by the server - we just pass data through.
66
- *
67
- * @example
68
- * ```typescript
69
- * const client = new DextoClient({
70
- * baseUrl: 'https://your-dexto-server.com',
71
- * apiKey: 'optional-api-key'
72
- * });
73
- *
74
- * await client.connect();
75
- *
76
- * const response = await client.sendMessage({
77
- * content: 'Hello, how can you help me?'
78
- * });
79
- *
80
- * console.log(response.response);
81
- * ```
82
- */
83
- declare class DextoClient {
84
- private http;
85
- private ws;
86
- private config;
87
- private options;
88
- constructor(config: ClientConfig, options?: ClientOptions);
89
- private initializeWebSocket;
90
- /**
91
- * Establish connection to Dexto server (including WebSocket if enabled)
92
- */
93
- connect(): Promise<void>;
94
- /**
95
- * Disconnect from Dexto server
96
- */
97
- disconnect(): void;
98
- /**
99
- * Send a message to the Dexto agent
100
- */
101
- sendMessage(input: MessageInput): Promise<MessageResponse>;
102
- /**
103
- * Send a message via WebSocket for streaming responses
104
- */
105
- sendMessageStream(input: MessageInput): boolean;
106
- /**
107
- * List all sessions
108
- */
109
- listSessions(): Promise<SessionMetadata[]>;
110
- /**
111
- * Create a new session
112
- */
113
- createSession(sessionId?: string): Promise<SessionMetadata>;
114
- /**
115
- * Get session details
116
- */
117
- getSession(sessionId: string): Promise<SessionMetadata>;
118
- /**
119
- * Get session conversation history
120
- */
121
- getSessionHistory(sessionId: string): Promise<any[]>;
122
- /**
123
- * Delete a session permanently
124
- */
125
- deleteSession(sessionId: string): Promise<void>;
126
- /**
127
- * Load a session as the current working session
128
- */
129
- loadSession(sessionId: string | null): Promise<void>;
130
- /**
131
- * Get the current working session
132
- */
133
- getCurrentSession(): Promise<string>;
134
- /**
135
- * Reset conversation (clear history while keeping session alive)
136
- */
137
- resetConversation(sessionId?: string): Promise<void>;
138
- /**
139
- * Get current LLM configuration
140
- */
141
- getCurrentLLMConfig(sessionId?: string): Promise<LLMConfig>;
142
- /**
143
- * Switch LLM configuration
144
- */
145
- switchLLM(config: Partial<LLMConfig>, sessionId?: string): Promise<LLMConfig>;
146
- /**
147
- * Get available LLM providers and models
148
- */
149
- getLLMProviders(): Promise<Record<string, ClientProviderInfo>>;
150
- /**
151
- * Get LLM catalog with filtering options
152
- */
153
- getLLMCatalog(options?: CatalogOptions): Promise<CatalogResponse>;
154
- /**
155
- * List connected MCP servers
156
- */
157
- listMCPServers(): Promise<McpServer[]>;
158
- /**
159
- * Connect to a new MCP server
160
- */
161
- connectMCPServer(name: string, config: Record<string, unknown>): Promise<void>;
162
- /**
163
- * Disconnect from an MCP server
164
- */
165
- disconnectMCPServer(serverId: string): Promise<void>;
166
- /**
167
- * Get tools from a specific MCP server
168
- */
169
- getMCPServerTools(serverId: string): Promise<Tool[]>;
170
- /**
171
- * Execute a tool from an MCP server
172
- */
173
- executeMCPTool(serverId: string, toolName: string, args: unknown): Promise<unknown>;
174
- /**
175
- * Search messages across sessions
176
- */
177
- searchMessages(query: string, options?: SearchOptions): Promise<SearchResponse>;
178
- /**
179
- * Search sessions that contain the query
180
- */
181
- searchSessions(query: string): Promise<SessionSearchResponse>;
182
- /**
183
- * Subscribe to real-time events
184
- */
185
- on(eventType: string, handler: EventHandler): () => void;
186
- /**
187
- * Subscribe to connection state changes
188
- */
189
- onConnectionState(handler: (state: 'connecting' | 'open' | 'closed' | 'error') => void): () => void;
190
- /**
191
- * Get agent greeting message
192
- */
193
- getGreeting(sessionId?: string): Promise<string | null>;
194
- /**
195
- * Get connection status
196
- */
197
- get connectionState(): 'connecting' | 'open' | 'closed' | 'error';
198
- /**
199
- * Check if client is connected
200
- */
201
- get isConnected(): boolean;
202
- /**
203
- * Get client configuration
204
- */
205
- get clientConfig(): Readonly<ClientConfig>;
206
- }
207
-
208
- /**
209
- * Simple error factory for client SDK
210
- * No complex validation - let server handle validation and return appropriate errors
211
- */
212
- declare class ClientError {
213
- /**
214
- * Connection and Network Errors
215
- */
216
- static connectionFailed(baseUrl: string, originalError?: Error): Error;
217
- static networkError(message: string, originalError?: Error): Error;
218
- static httpError(status: number, statusText: string, endpoint?: string, details?: unknown): Error;
219
- static timeoutError(operation: string, timeout: number): Error;
220
- /**
221
- * WebSocket Errors
222
- */
223
- static websocketConnectionFailed(url: string, originalError?: Error): Error;
224
- static websocketSendFailed(originalError?: Error): Error;
225
- /**
226
- * Configuration Errors
227
- */
228
- static invalidConfig(field: string, value: unknown, reason: string): Error;
229
- static responseParseError(originalError?: Error): Error;
230
- }
231
-
232
- export { type CatalogModel, type CatalogOptions, type CatalogProvider, type CatalogResponse, type ClientConfig, ClientError, type ClientOptions, type ClientProviderInfo, DextoClient, type DextoEvent, type McpServer, type MessageInput, type MessageResponse, type Tool };