@dtoolkit/sdk 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Iván Campillo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,184 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/ivncmp/dtoolkit/main/logo.png" alt="dtoolkit" />
3
+ </p>
4
+
5
+ <h1 align="center">@dtoolkit/sdk</h1>
6
+ <p align="center">Typed HTTP clients for dtoolkit services (dbrain + dproxy)</p>
7
+
8
+ <p align="center">
9
+ <a href="https://www.npmjs.com/package/@dtoolkit/sdk"><img src="https://img.shields.io/npm/v/@dtoolkit/sdk.svg" alt="npm"></a>
10
+ <a href="../../LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License"></a>
11
+ </p>
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @dtoolkit/sdk
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ### DBrainClient
22
+
23
+ Connect to a [dbrain](../dbrain/) persistent memory server:
24
+
25
+ ```ts
26
+ import { DBrainClient } from "@dtoolkit/sdk";
27
+
28
+ const brain = new DBrainClient("http://localhost:7878", "sk-dbr_...");
29
+
30
+ // Search memory
31
+ const results = await brain.search("authentication flow");
32
+
33
+ // Manage entities
34
+ const entities = await brain.listEntities({ category: "projects" });
35
+ const entity = await brain.getEntity("my-project");
36
+
37
+ // Add facts
38
+ await brain.addFact("my-project", {
39
+ id: "fact-1",
40
+ fact: "Uses JWT for session management",
41
+ });
42
+
43
+ // Conversations
44
+ const conv = await brain.startConversation("claude-code");
45
+ await brain.sendMessages(conv.id, [
46
+ { role: "user", content: "How does auth work?" },
47
+ ]);
48
+
49
+ // Documents
50
+ const docs = await brain.listDocuments();
51
+ await brain.putDocument("notes", {
52
+ title: "Architecture Notes",
53
+ content: "...",
54
+ });
55
+ ```
56
+
57
+ ### DProxyClient
58
+
59
+ Connect to a [dproxy](../dproxy/) HTTP API server:
60
+
61
+ ```ts
62
+ import { DProxyClient } from "@dtoolkit/sdk";
63
+
64
+ const proxy = new DProxyClient("http://localhost:7880", "my-token");
65
+
66
+ // Single-shot prompt
67
+ const result = await proxy.ask("explain monads in one sentence", {
68
+ provider: "claude",
69
+ model: "sonnet",
70
+ });
71
+ console.log(result.text);
72
+
73
+ // Streaming
74
+ for await (const event of proxy.askStream("write a haiku")) {
75
+ if (event.type === "text") {
76
+ process.stdout.write(event.text ?? "");
77
+ }
78
+ }
79
+
80
+ // Memory
81
+ await proxy.setMemory("project-context", "This project uses React + Fastify");
82
+ const keys = await proxy.listMemoryKeys();
83
+
84
+ // Templates
85
+ const templates = await proxy.listTemplates();
86
+ const output = await proxy.runTemplate("code-review", {
87
+ vars: { file: "src/index.ts" },
88
+ });
89
+
90
+ // History
91
+ const history = await proxy.listHistory(10);
92
+ const matches = await proxy.searchHistory("monads");
93
+ ```
94
+
95
+ ## Authentication
96
+
97
+ All dtoolkit services use unified `Authorization: Bearer <token>` authentication. Pass the token as the second constructor argument:
98
+
99
+ ```ts
100
+ // Both clients use the same auth mechanism
101
+ const brain = new DBrainClient("http://localhost:7878", "my-token");
102
+ const proxy = new DProxyClient("http://localhost:7880", "my-token");
103
+
104
+ // Or use the options object
105
+ const brain = new DBrainClient({
106
+ baseUrl: "http://localhost:7878",
107
+ token: "my-token",
108
+ });
109
+ ```
110
+
111
+ ## Error Handling
112
+
113
+ Both clients throw `SdkError` on HTTP errors:
114
+
115
+ ```ts
116
+ import { SdkError } from "@dtoolkit/sdk";
117
+
118
+ try {
119
+ await brain.getEntity("nonexistent");
120
+ } catch (err) {
121
+ if (err instanceof SdkError) {
122
+ console.error(err.status); // 404
123
+ console.error(err.path); // /entities/nonexistent
124
+ console.error(err.body); // response body
125
+ }
126
+ }
127
+ ```
128
+
129
+ ## API Reference
130
+
131
+ ### DBrainClient
132
+
133
+ | Method | Description |
134
+ | --- | --- |
135
+ | `health()` | Server health check |
136
+ | `connect()` | Get MCP connection info |
137
+ | `listEntities(filters?)` | List entities (filter by category/type) |
138
+ | `getEntity(id)` | Get entity with all facts |
139
+ | `createEntity(entity)` | Create a new entity |
140
+ | `archiveEntity(id)` | Archive an entity |
141
+ | `listFacts(entityId, filters?)` | List facts for an entity |
142
+ | `addFact(entityId, fact)` | Add a fact to an entity |
143
+ | `bumpFact(id)` | Bump fact access (keeps it hot) |
144
+ | `search(query, options?)` | Full-text search across facts |
145
+ | `memorySummary()` | Get tier summary per entity |
146
+ | `listConversations(filters?)` | List conversations |
147
+ | `getConversation(id)` | Get conversation with messages |
148
+ | `startConversation(source, id?)` | Start a new conversation |
149
+ | `sendMessages(conversationId, messages)` | Send messages to a conversation |
150
+ | `listMessages(conversationId, filters?)` | List messages in a conversation |
151
+ | `pendingMessages()` | Get unprocessed message counts |
152
+ | `listDocuments()` | List workspace documents |
153
+ | `getDocument(key)` | Get a document by key |
154
+ | `putDocument(key, doc)` | Create or update a document |
155
+ | `deleteDocument(key)` | Delete a document |
156
+
157
+ ### DProxyClient
158
+
159
+ | Method | Description |
160
+ | --- | --- |
161
+ | `health()` | Server health check |
162
+ | `ask(prompt, options?)` | Send a prompt (non-streaming) |
163
+ | `askStream(prompt, options?)` | Send a prompt (SSE streaming) |
164
+ | `listHistory(limit?)` | List prompt history |
165
+ | `getHistory(id)` | Get a history entry |
166
+ | `searchHistory(query)` | Search prompt history |
167
+ | `clearHistory(before?)` | Clear history entries |
168
+ | `listMemoryKeys()` | List memory keys |
169
+ | `getMemory(key)` | Get memory content by key |
170
+ | `setMemory(key, content)` | Set memory content |
171
+ | `deleteMemory(key)` | Delete a memory key |
172
+ | `searchMemory(query)` | Search memory content |
173
+ | `listTemplates()` | List prompt templates |
174
+ | `getTemplate(name)` | Get a template by name |
175
+ | `saveTemplate(name, template)` | Save a prompt template |
176
+ | `runTemplate(name, options?)` | Execute a prompt template |
177
+ | `deleteTemplate(name)` | Delete a template |
178
+ | `getConfig()` | Get full server config |
179
+ | `getConfigValue(key)` | Get a config value by key |
180
+ | `setConfigValue(key, value)` | Set a config value |
181
+
182
+ ## License
183
+
184
+ MIT
@@ -0,0 +1,96 @@
1
+ import type { ConnectResponse, ConversationSummary, ConversationWithMessages, Document, DocumentListItem, EntityRow, EntityWithFacts, FactRow, HealthResponse, MemorySummaryRow, Message, PendingMessages, SearchResult } from "./types.js";
2
+ export interface DBrainClientOptions {
3
+ baseUrl: string;
4
+ token: string;
5
+ }
6
+ export declare class DBrainClient {
7
+ private readonly http;
8
+ constructor(baseUrl: string, token: string);
9
+ constructor(options: DBrainClientOptions);
10
+ health(): Promise<HealthResponse>;
11
+ connect(): Promise<ConnectResponse>;
12
+ listEntities(filters?: {
13
+ category?: string;
14
+ type?: string;
15
+ }): Promise<EntityRow[]>;
16
+ getEntity(id: string): Promise<EntityWithFacts>;
17
+ createEntity(entity: {
18
+ id: string;
19
+ name: string;
20
+ type: string;
21
+ category: string;
22
+ metadata?: Record<string, unknown>;
23
+ }): Promise<{
24
+ id: string;
25
+ name: string;
26
+ type: string;
27
+ category: string;
28
+ }>;
29
+ archiveEntity(id: string): Promise<{
30
+ id: string;
31
+ status: string;
32
+ }>;
33
+ listFacts(entityId: string, filters?: {
34
+ tier?: string;
35
+ }): Promise<FactRow[]>;
36
+ addFact(entityId: string, fact: {
37
+ id: string;
38
+ fact: string;
39
+ category?: string;
40
+ timestamp?: string;
41
+ source?: string;
42
+ relatedEntities?: string[];
43
+ }): Promise<{
44
+ id: string;
45
+ entityId: string;
46
+ fact: string;
47
+ }>;
48
+ bumpFact(id: string): Promise<{
49
+ id: string;
50
+ bumped: boolean;
51
+ }>;
52
+ search(query: string, options?: {
53
+ limit?: number;
54
+ entityId?: string;
55
+ tier?: string;
56
+ }): Promise<SearchResult[]>;
57
+ memorySummary(): Promise<MemorySummaryRow[]>;
58
+ listConversations(filters?: {
59
+ source?: string;
60
+ limit?: number;
61
+ }): Promise<ConversationSummary[]>;
62
+ getConversation(id: string): Promise<ConversationWithMessages>;
63
+ startConversation(source: string, id?: string): Promise<{
64
+ id: string;
65
+ source: string;
66
+ started_at: string;
67
+ }>;
68
+ sendMessages(conversationId: string, messages: Array<{
69
+ role: string;
70
+ content: string;
71
+ }>): Promise<Array<{
72
+ id: string;
73
+ role: string;
74
+ timestamp: string;
75
+ }>>;
76
+ listMessages(conversationId: string, filters?: {
77
+ since?: string;
78
+ processed?: boolean;
79
+ }): Promise<Message[]>;
80
+ pendingMessages(): Promise<PendingMessages>;
81
+ listDocuments(): Promise<DocumentListItem[]>;
82
+ getDocument(key: string): Promise<Document>;
83
+ putDocument(key: string, doc: {
84
+ title: string;
85
+ content: string;
86
+ }): Promise<{
87
+ key: string;
88
+ title: string;
89
+ updated_at: string;
90
+ }>;
91
+ deleteDocument(key: string): Promise<{
92
+ key: string;
93
+ deleted: boolean;
94
+ }>;
95
+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0,0 +1,109 @@
1
+ import { HttpClient, enc, qs } from "../http.js";
2
+ export class DBrainClient {
3
+ http;
4
+ constructor(baseUrlOrOptions, token) {
5
+ if (typeof baseUrlOrOptions === "string") {
6
+ this.http = new HttpClient({
7
+ baseUrl: baseUrlOrOptions,
8
+ token: token ?? "",
9
+ });
10
+ }
11
+ else {
12
+ this.http = new HttpClient({
13
+ baseUrl: baseUrlOrOptions.baseUrl,
14
+ token: baseUrlOrOptions.token,
15
+ });
16
+ }
17
+ }
18
+ // --- Health ---
19
+ async health() {
20
+ return this.http.get("/health");
21
+ }
22
+ async connect() {
23
+ return this.http.get("/connect");
24
+ }
25
+ // --- Entities ---
26
+ async listEntities(filters) {
27
+ const params = new URLSearchParams();
28
+ if (filters?.category)
29
+ params.set("category", filters.category);
30
+ if (filters?.type)
31
+ params.set("type", filters.type);
32
+ return this.http.get(`/entities${qs(params)}`);
33
+ }
34
+ async getEntity(id) {
35
+ return this.http.get(`/entities/${enc(id)}`);
36
+ }
37
+ async createEntity(entity) {
38
+ return this.http.post("/entities", entity);
39
+ }
40
+ async archiveEntity(id) {
41
+ return this.http.del(`/entities/${enc(id)}`);
42
+ }
43
+ // --- Facts ---
44
+ async listFacts(entityId, filters) {
45
+ const params = new URLSearchParams();
46
+ if (filters?.tier)
47
+ params.set("tier", filters.tier);
48
+ return this.http.get(`/entities/${enc(entityId)}/facts${qs(params)}`);
49
+ }
50
+ async addFact(entityId, fact) {
51
+ return this.http.post(`/entities/${enc(entityId)}/facts`, fact);
52
+ }
53
+ async bumpFact(id) {
54
+ return this.http.patch(`/facts/${enc(id)}/access`);
55
+ }
56
+ // --- Search ---
57
+ async search(query, options) {
58
+ return this.http.post("/search", { query, ...options });
59
+ }
60
+ async memorySummary() {
61
+ return this.http.get("/memory/summary");
62
+ }
63
+ // --- Conversations ---
64
+ async listConversations(filters) {
65
+ const params = new URLSearchParams();
66
+ if (filters?.source)
67
+ params.set("source", filters.source);
68
+ if (filters?.limit)
69
+ params.set("limit", String(filters.limit));
70
+ return this.http.get(`/conversations${qs(params)}`);
71
+ }
72
+ async getConversation(id) {
73
+ return this.http.get(`/conversations/${enc(id)}`);
74
+ }
75
+ async startConversation(source, id) {
76
+ return this.http.post("/conversations", {
77
+ source,
78
+ ...(id ? { id } : {}),
79
+ });
80
+ }
81
+ async sendMessages(conversationId, messages) {
82
+ return this.http.post(`/conversations/${enc(conversationId)}/messages`, messages.length === 1 ? messages[0] : messages);
83
+ }
84
+ async listMessages(conversationId, filters) {
85
+ const params = new URLSearchParams();
86
+ if (filters?.since)
87
+ params.set("since", filters.since);
88
+ if (filters?.processed !== undefined)
89
+ params.set("processed", String(filters.processed));
90
+ return this.http.get(`/conversations/${enc(conversationId)}/messages${qs(params)}`);
91
+ }
92
+ async pendingMessages() {
93
+ return this.http.get("/conversations/pending");
94
+ }
95
+ // --- Workspace (Documents) ---
96
+ async listDocuments() {
97
+ return this.http.get("/workspace");
98
+ }
99
+ async getDocument(key) {
100
+ return this.http.get(`/workspace/${enc(key)}`);
101
+ }
102
+ async putDocument(key, doc) {
103
+ return this.http.put(`/workspace/${enc(key)}`, doc);
104
+ }
105
+ async deleteDocument(key) {
106
+ return this.http.del(`/workspace/${enc(key)}`);
107
+ }
108
+ }
109
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/dbrain/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAuBjD,MAAM,OAAO,YAAY;IACN,IAAI,CAAa;IAIlC,YAAY,gBAA8C,EAAE,KAAc;QACxE,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE,CAAC;YACzC,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC;gBACzB,OAAO,EAAE,gBAAgB;gBACzB,KAAK,EAAE,KAAK,IAAI,EAAE;aACnB,CAAC,CAAC;QACL,CAAC;aAAM,CA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MAAM,CAAC,EAAE,CAC9D,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACjD,CAAC;IAED,gCAAgC;IAEhC,KAAK,CAAC,aAAa;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,GAAW;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,WAAW,CACf,GAAW,EACX,GAAuC;QAEvC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,GAAW;QAEX,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export { DBrainClient, type DBrainClientOptions } from "./client.js";
2
+ export type { ConnectResponse, ConversationSummary, ConversationWithMessages, Document, DocumentListItem, EntityRow, EntityWithFacts, FactRow, HealthResponse, MemorySummaryRow, Message, PendingMessages, SearchResult, } from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dbrain/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAErE,YAAY,EACV,eAAe,EACf,mBAAmB,EACnB,wBAAwB,EACxB,QAAQ,EACR,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,eAAe,EACf,YAAY,GACb,MAAM,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { DBrainClient } from "./client.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dbrain/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA4B,MAAM,aAAa,CAAC"}
@@ -0,0 +1,123 @@
1
+ export interface HealthResponse {
2
+ status: string;
3
+ name: string;
4
+ version: string;
5
+ entities: number;
6
+ facts: number;
7
+ documents: number;
8
+ conversations: number;
9
+ unprocessed: number;
10
+ }
11
+ export interface ConnectResponse {
12
+ mcp: {
13
+ dbrain: {
14
+ type: string;
15
+ url: string;
16
+ headers: Record<string, string>;
17
+ };
18
+ };
19
+ permissions: string[];
20
+ claudeMd: string;
21
+ }
22
+ export interface EntityRow {
23
+ id: string;
24
+ name: string;
25
+ type: string;
26
+ category: string;
27
+ status: string;
28
+ created_at: string;
29
+ updated_at: string;
30
+ metadata: Record<string, unknown> | null;
31
+ }
32
+ export interface FactRow {
33
+ id: string;
34
+ entity_id: string;
35
+ fact: string;
36
+ category: string;
37
+ timestamp: string;
38
+ status: string;
39
+ superseded_by: string | null;
40
+ related_entities: string[];
41
+ last_accessed: string;
42
+ access_count: number;
43
+ tier: string;
44
+ source: string | null;
45
+ }
46
+ export interface EntityWithFacts extends EntityRow {
47
+ facts: FactRow[];
48
+ }
49
+ export interface ConversationSummary {
50
+ id: string;
51
+ source: string;
52
+ started_at: string;
53
+ ended_at: string | null;
54
+ summary: string | null;
55
+ message_count: number;
56
+ }
57
+ export interface Message {
58
+ id: string;
59
+ role: string;
60
+ content: string;
61
+ timestamp: string;
62
+ processed: number;
63
+ }
64
+ export interface ConversationWithMessages {
65
+ id: string;
66
+ source: string;
67
+ started_at: string;
68
+ ended_at: string | null;
69
+ summary: string | null;
70
+ messages: Message[];
71
+ }
72
+ export interface SearchResult {
73
+ fact: {
74
+ id: string;
75
+ entityId: string;
76
+ fact: string;
77
+ category: string;
78
+ timestamp: string;
79
+ status: string;
80
+ lastAccessed: string;
81
+ accessCount: number;
82
+ tier: string;
83
+ source: string | null;
84
+ };
85
+ entity: {
86
+ id: string;
87
+ name: string;
88
+ type: string;
89
+ category: string;
90
+ };
91
+ score: number;
92
+ }
93
+ export interface MemorySummaryRow {
94
+ id: string;
95
+ name: string;
96
+ type: string;
97
+ category: string;
98
+ hot: number;
99
+ warm: number;
100
+ cold: number;
101
+ total: number;
102
+ }
103
+ export interface Document {
104
+ key: string;
105
+ title: string;
106
+ content: string;
107
+ updated_at: string;
108
+ }
109
+ export interface DocumentListItem {
110
+ key: string;
111
+ title: string;
112
+ updated_at: string;
113
+ }
114
+ export interface PendingMessages {
115
+ total_unprocessed: number;
116
+ conversations: Array<{
117
+ id: string;
118
+ source: string;
119
+ started_at: string;
120
+ unprocessed: number;
121
+ }>;
122
+ }
123
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/dbrain/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE;QACH,MAAM,EAAE;YACN,IAAI,EAAE,MAAM,CAAC;YACb,GAAG,EAAE,MAAM,CAAC;YACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SACjC,CAAC;KACH,CAAC;IACF,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,MAA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IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,KAAK,CAAC;QACnB,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC,CAAC;CACJ"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/dbrain/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import type { AdapterStreamEvent } from "@dtoolkit/core";
2
+ import type { AskOptions, AskResponse, DProxyHealthResponse, HistoryEntry, MemorySearchResult, TemplateDefinition, TemplateRunOptions } from "./types.js";
3
+ export interface DProxyClientOptions {
4
+ baseUrl: string;
5
+ token?: string;
6
+ }
7
+ export declare class DProxyClient {
8
+ private readonly http;
9
+ constructor(baseUrl: string, token?: string);
10
+ constructor(options: DProxyClientOptions);
11
+ health(): Promise<DProxyHealthResponse>;
12
+ ask(prompt: string, options?: AskOptions): Promise<AskResponse>;
13
+ askStream(prompt: string, options?: AskOptions): AsyncGenerator<AdapterStreamEvent>;
14
+ listHistory(limit?: number): Promise<HistoryEntry[]>;
15
+ getHistory(id: string): Promise<HistoryEntry>;
16
+ searchHistory(query: string): Promise<HistoryEntry[]>;
17
+ clearHistory(before?: string): Promise<{
18
+ removed: number;
19
+ }>;
20
+ listMemoryKeys(): Promise<string[]>;
21
+ getMemory(key: string): Promise<string>;
22
+ setMemory(key: string, content: string): Promise<void>;
23
+ deleteMemory(key: string): Promise<void>;
24
+ searchMemory(query: string): Promise<MemorySearchResult[]>;
25
+ listTemplates(): Promise<TemplateDefinition[]>;
26
+ getTemplate(name: string): Promise<TemplateDefinition>;
27
+ saveTemplate(name: string, template: TemplateDefinition): Promise<void>;
28
+ runTemplate(name: string, options?: TemplateRunOptions): Promise<AskResponse>;
29
+ deleteTemplate(name: string): Promise<void>;
30
+ getConfig(): Promise<unknown>;
31
+ getConfigValue(key: string): Promise<unknown>;
32
+ setConfigValue(key: string, value: string): Promise<void>;
33
+ }
34
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/dproxy/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAIzD,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;gBAEtB,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;gBAC/B,OAAO,EAAE,mBAAmB;IAiBlC,MAAM,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAMvC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;IAI9D,SAAS,CACd,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,UAAU,GACnB,cAAc,CAAC,kBAAkB,CAAC;IAqD/B,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IASpD,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAI7C,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAQrD,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAQ3D,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKnC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAOvC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAU1D,aAAa,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAO9C,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAItD,YAAY,CAChB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kBAAkB,GAC3B,OAAO,CAAC,IAAI,CAAC;IAIV,WAAW,CACf,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,CAAC;IAIjB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3C,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAI7B,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAO7C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGhE"}
@@ -0,0 +1,133 @@
1
+ import { HttpClient, SdkError, enc, qs } from "../http.js";
2
+ export class DProxyClient {
3
+ http;
4
+ constructor(baseUrlOrOptions, token) {
5
+ if (typeof baseUrlOrOptions === "string") {
6
+ this.http = new HttpClient({ baseUrl: baseUrlOrOptions, token });
7
+ }
8
+ else {
9
+ this.http = new HttpClient({
10
+ baseUrl: baseUrlOrOptions.baseUrl,
11
+ token: baseUrlOrOptions.token,
12
+ });
13
+ }
14
+ }
15
+ // --- Health ---
16
+ async health() {
17
+ return this.http.get("/v1/health");
18
+ }
19
+ // --- Ask ---
20
+ async ask(prompt, options) {
21
+ return this.http.post("/v1/ask", { prompt, ...options });
22
+ }
23
+ async *askStream(prompt, options) {
24
+ const res = await this.http.requestRaw("POST", "/v1/ask", {
25
+ prompt,
26
+ stream: true,
27
+ ...options,
28
+ });
29
+ if (!res.body) {
30
+ throw new SdkError(0, "Response body is null", "/v1/ask");
31
+ }
32
+ const reader = res.body.getReader();
33
+ const decoder = new TextDecoder();
34
+ let buffer = "";
35
+ try {
36
+ for (;;) {
37
+ const { done, value } = await reader.read();
38
+ if (done)
39
+ break;
40
+ buffer += decoder.decode(value, { stream: true });
41
+ const lines = buffer.split("\n");
42
+ buffer = lines.pop() ?? "";
43
+ for (const line of lines) {
44
+ const trimmed = line.trim();
45
+ if (!trimmed || !trimmed.startsWith("data: "))
46
+ continue;
47
+ const payload = trimmed.slice(6);
48
+ if (payload === "[DONE]")
49
+ return;
50
+ const event = JSON.parse(payload);
51
+ if (event.type === "error") {
52
+ throw new SdkError(0, event.error, "/v1/ask");
53
+ }
54
+ yield event;
55
+ }
56
+ }
57
+ }
58
+ finally {
59
+ reader.releaseLock();
60
+ }
61
+ }
62
+ // --- History ---
63
+ async listHistory(limit) {
64
+ const params = new URLSearchParams();
65
+ if (limit !== undefined)
66
+ params.set("limit", String(limit));
67
+ const res = await this.http.get(`/v1/history${qs(params)}`);
68
+ return res.entries;
69
+ }
70
+ async getHistory(id) {
71
+ return this.http.get(`/v1/history/${enc(id)}`);
72
+ }
73
+ async searchHistory(query) {
74
+ const params = new URLSearchParams({ q: query });
75
+ const res = await this.http.get(`/v1/history/search${qs(params)}`);
76
+ return res.entries;
77
+ }
78
+ async clearHistory(before) {
79
+ const params = new URLSearchParams();
80
+ if (before)
81
+ params.set("before", before);
82
+ return this.http.request("DELETE", `/v1/history${qs(params)}`);
83
+ }
84
+ // --- Memory ---
85
+ async listMemoryKeys() {
86
+ const res = await this.http.get("/v1/memory");
87
+ return res.keys;
88
+ }
89
+ async getMemory(key) {
90
+ const res = await this.http.get(`/v1/memory/${enc(key)}`);
91
+ return res.content;
92
+ }
93
+ async setMemory(key, content) {
94
+ await this.http.put(`/v1/memory/${enc(key)}`, { content });
95
+ }
96
+ async deleteMemory(key) {
97
+ await this.http.del(`/v1/memory/${enc(key)}`);
98
+ }
99
+ async searchMemory(query) {
100
+ const params = new URLSearchParams({ q: query });
101
+ const res = await this.http.get(`/v1/memory/search${qs(params)}`);
102
+ return res.results;
103
+ }
104
+ // --- Templates ---
105
+ async listTemplates() {
106
+ const res = await this.http.get("/v1/templates");
107
+ return res.templates;
108
+ }
109
+ async getTemplate(name) {
110
+ return this.http.get(`/v1/templates/${enc(name)}`);
111
+ }
112
+ async saveTemplate(name, template) {
113
+ await this.http.put(`/v1/templates/${enc(name)}`, template);
114
+ }
115
+ async runTemplate(name, options) {
116
+ return this.http.post(`/v1/templates/${enc(name)}/run`, options ?? {});
117
+ }
118
+ async deleteTemplate(name) {
119
+ await this.http.del(`/v1/templates/${enc(name)}`);
120
+ }
121
+ // --- Config ---
122
+ async getConfig() {
123
+ return this.http.get("/v1/config");
124
+ }
125
+ async getConfigValue(key) {
126
+ const res = await this.http.get(`/v1/config/${key}`);
127
+ return res.value;
128
+ }
129
+ async setConfigValue(key, value) {
130
+ await this.http.put(`/v1/config/${key}`, { value });
131
+ }
132
+ }
133
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/dproxy/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAiB3D,MAAM,OAAO,YAAY;IAC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EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,IAAY;QAC/B,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,iBAAiB;IAEjB,KAAK,CAAC,SAAS;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAW;QAC9B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAC7B,cAAc,GAAG,EAAE,CACpB,CAAC;QACF,OAAO,GAAG,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAW,EAAE,KAAa;QAC7C,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACtD,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export { DProxyClient, type DProxyClientOptions } from "./client.js";
2
+ export type { AskOptions, AskResponse, DProxyHealthResponse, HistoryEntry, MemorySearchResult, ProviderName, TemplateDefinition, TemplateRunOptions, } from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dproxy/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAErE,YAAY,EACV,UAAU,EACV,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { DProxyClient } from "./client.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dproxy/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA4B,MAAM,aAAa,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { AdapterUsage, HistoryEntry, TemplateDefinition } from "@dtoolkit/core";
2
+ export type ProviderName = "claude" | "codex" | "gemini" | "ollama" | "opencode";
3
+ export interface AskOptions {
4
+ provider?: ProviderName;
5
+ model?: string;
6
+ maxTurns?: number;
7
+ maxBudgetUsd?: number;
8
+ systemPrompt?: string;
9
+ memory?: boolean | string[];
10
+ life?: boolean;
11
+ workspace?: boolean;
12
+ chatLog?: boolean;
13
+ sessionId?: string;
14
+ continueSession?: boolean;
15
+ maxSessionTokens?: number;
16
+ saveHistory?: boolean;
17
+ saveChatLog?: boolean;
18
+ }
19
+ export interface AskResponse {
20
+ text: string;
21
+ sessionId?: string;
22
+ costUsd?: number;
23
+ durationMs: number;
24
+ usage?: AdapterUsage;
25
+ raw?: unknown;
26
+ }
27
+ export interface DProxyHealthResponse {
28
+ status: string;
29
+ provider: string;
30
+ version: string;
31
+ }
32
+ export type { HistoryEntry };
33
+ export interface MemorySearchResult {
34
+ key: string;
35
+ content: string;
36
+ }
37
+ export type { TemplateDefinition };
38
+ export interface TemplateRunOptions {
39
+ vars?: Record<string, string>;
40
+ model?: string;
41
+ maxTurns?: number;
42
+ maxBudgetUsd?: number;
43
+ provider?: ProviderName;
44
+ }
45
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/dproxy/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,YAAY,GACpB,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,UAAU,CAAC;AAIf,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,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,CAAC;IACtB,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/dproxy/types.ts"],"names":[],"mappings":""}
package/dist/http.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ export interface HttpClientOptions {
2
+ baseUrl: string;
3
+ token?: string;
4
+ }
5
+ export declare class HttpClient {
6
+ private readonly baseUrl;
7
+ private readonly token;
8
+ constructor(options: HttpClientOptions);
9
+ request<T>(method: string, path: string, body?: unknown): Promise<T>;
10
+ requestRaw(method: string, path: string, body?: unknown): Promise<Response>;
11
+ get<T>(path: string): Promise<T>;
12
+ post<T>(path: string, body: unknown): Promise<T>;
13
+ put<T>(path: string, body: unknown): Promise<T>;
14
+ patch<T>(path: string, body?: unknown): Promise<T>;
15
+ del<T>(path: string): Promise<T>;
16
+ private rawRequest;
17
+ }
18
+ export declare class SdkError extends Error {
19
+ readonly status: number;
20
+ readonly body: string;
21
+ readonly path: string;
22
+ constructor(status: number, body: string, path: string);
23
+ }
24
+ export declare function enc(s: string): string;
25
+ export declare function qs(params: URLSearchParams): string;
26
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;gBAE/B,OAAO,EAAE,iBAAiB;IAKhC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAWpE,UAAU,CACd,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,GACb,OAAO,CAAC,QAAQ,CAAC;IAWpB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIhC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAIhD,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAI/C,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAIlD,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIhC,OAAO,CAAC,UAAU;CAoBnB;AAED,qBAAa,QAAS,SAAQ,KAAK;aAEf,MAAM,EAAE,MAAM;aACd,IAAI,EAAE,MAAM;aACZ,IAAI,EAAE,MAAM;gBAFZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM;CAK/B;AAED,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAErC;AAED,wBAAgB,EAAE,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAGlD"}
package/dist/http.js ADDED
@@ -0,0 +1,73 @@
1
+ export class HttpClient {
2
+ baseUrl;
3
+ token;
4
+ constructor(options) {
5
+ this.baseUrl = options.baseUrl.replace(/\/$/, "");
6
+ this.token = options.token;
7
+ }
8
+ async request(method, path, body) {
9
+ const res = await this.rawRequest(method, path, body);
10
+ if (!res.ok) {
11
+ const text = await res.text().catch(() => "");
12
+ throw new SdkError(res.status, text, path);
13
+ }
14
+ return res.json();
15
+ }
16
+ async requestRaw(method, path, body) {
17
+ const res = await this.rawRequest(method, path, body);
18
+ if (!res.ok) {
19
+ const text = await res.text().catch(() => "");
20
+ throw new SdkError(res.status, text, path);
21
+ }
22
+ return res;
23
+ }
24
+ get(path) {
25
+ return this.request("GET", path);
26
+ }
27
+ post(path, body) {
28
+ return this.request("POST", path, body);
29
+ }
30
+ put(path, body) {
31
+ return this.request("PUT", path, body);
32
+ }
33
+ patch(path, body) {
34
+ return this.request("PATCH", path, body);
35
+ }
36
+ del(path) {
37
+ return this.request("DELETE", path);
38
+ }
39
+ rawRequest(method, path, body) {
40
+ const headers = {};
41
+ if (this.token) {
42
+ headers["Authorization"] = `Bearer ${this.token}`;
43
+ }
44
+ if (body !== undefined) {
45
+ headers["Content-Type"] = "application/json";
46
+ }
47
+ return fetch(`${this.baseUrl}${path}`, {
48
+ method,
49
+ headers,
50
+ body: body !== undefined ? JSON.stringify(body) : undefined,
51
+ });
52
+ }
53
+ }
54
+ export class SdkError extends Error {
55
+ status;
56
+ body;
57
+ path;
58
+ constructor(status, body, path) {
59
+ super(`sdk ${status} on ${path}: ${body}`);
60
+ this.status = status;
61
+ this.body = body;
62
+ this.path = path;
63
+ this.name = "SdkError";
64
+ }
65
+ }
66
+ export function enc(s) {
67
+ return encodeURIComponent(s);
68
+ }
69
+ export function qs(params) {
70
+ const str = params.toString();
71
+ return str ? `?${str}` : "";
72
+ }
73
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,UAAU;IACJ,OAAO,CAAS;IAChB,KAAK,CAAqB;IAE3C,YAAY,OAA0B;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC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UAAU,EAAE,CAAC,MAAuB;IACxC,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC9B,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,10 @@
1
+ export { DBrainClient, type DBrainClientOptions } from "./dbrain/index.js";
2
+ export { DProxyClient, type DProxyClientOptions } from "./dproxy/index.js";
3
+ export { SdkError } from "./http.js";
4
+ /** @deprecated Use SdkError instead */
5
+ export { SdkError as DBrainError } from "./http.js";
6
+ export type { ConnectResponse, ConversationSummary, ConversationWithMessages, Document, DocumentListItem, EntityRow, EntityWithFacts, FactRow, HealthResponse, MemorySummaryRow, Message, PendingMessages, SearchResult, } from "./dbrain/index.js";
7
+ export type { AskOptions, AskResponse, DProxyHealthResponse, MemorySearchResult, ProviderName, TemplateRunOptions, } from "./dproxy/index.js";
8
+ export type { AdapterResult, AdapterStreamEvent, AdapterUsage, } from "@dtoolkit/core";
9
+ export type { HistoryEntry, TemplateDefinition } from "@dtoolkit/core";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAG3E,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,uCAAuC;AACvC,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAGpD,YAAY,EACV,eAAe,EACf,mBAAmB,EACnB,wBAAwB,EACxB,QAAQ,EACR,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,eAAe,EACf,YAAY,GACb,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EACV,UAAU,EACV,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // --- Clients ---
2
+ export { DBrainClient } from "./dbrain/index.js";
3
+ export { DProxyClient } from "./dproxy/index.js";
4
+ // --- Shared ---
5
+ export { SdkError } from "./http.js";
6
+ /** @deprecated Use SdkError instead */
7
+ export { SdkError as DBrainError } from "./http.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,OAAO,EAAE,YAAY,EAA4B,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAA4B,MAAM,mBAAmB,CAAC;AAE3E,iBAAiB;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,uCAAuC;AACvC,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@dtoolkit/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Typed HTTP clients for dtoolkit services (dbrain + dproxy)",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Iván Campillo <ivncmp@gmail.com>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/ivncmp/dtoolkit.git",
11
+ "directory": "packages/sdk"
12
+ },
13
+ "homepage": "https://github.com/ivncmp/dtoolkit/tree/main/packages/sdk",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "engines": {
27
+ "node": ">=22"
28
+ },
29
+ "keywords": [
30
+ "ai",
31
+ "memory",
32
+ "dbrain",
33
+ "dproxy",
34
+ "client",
35
+ "sdk",
36
+ "dtoolkit"
37
+ ],
38
+ "dependencies": {
39
+ "@dtoolkit/core": "0.2.2"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^22.0.0",
43
+ "typescript": "^5.7.0"
44
+ },
45
+ "scripts": {
46
+ "build": "tsc",
47
+ "lint": "eslint src/",
48
+ "lint:fix": "eslint src/ --fix"
49
+ }
50
+ }