@hydradb/mcp 1.1.1 → 1.2.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/CHANGELOG.md +204 -0
- package/README.md +92 -34
- package/dist/adapters.d.ts +27 -16
- package/dist/adapters.js +58 -54
- package/dist/adapters.js.map +1 -1
- package/dist/config.d.ts +2 -0
- package/dist/config.js +27 -1
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +43 -3
- package/dist/context.js +374 -34
- package/dist/context.js.map +1 -1
- package/dist/descriptions.d.ts +55 -28
- package/dist/descriptions.js +206 -52
- package/dist/descriptions.js.map +1 -1
- package/dist/hydra/client.d.ts +77 -8
- package/dist/hydra/client.js +127 -21
- package/dist/hydra/client.js.map +1 -1
- package/dist/hydra/errors.js +91 -6
- package/dist/hydra/errors.js.map +1 -1
- package/dist/hydra/index.d.ts +2 -2
- package/dist/hydra/index.js +1 -1
- package/dist/hydra/index.js.map +1 -1
- package/dist/index.js +97 -10
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +18 -1
- package/dist/server.js +1001 -104
- package/dist/server.js.map +1 -1
- package/dist/tool-names.d.ts +2 -1
- package/dist/tool-names.js +2 -0
- package/dist/tool-names.js.map +1 -1
- package/dist/types.d.ts +8 -51
- package/dist/types.js +6 -5
- package/dist/types.js.map +1 -1
- package/package.json +11 -6
package/dist/hydra/client.d.ts
CHANGED
|
@@ -16,6 +16,23 @@
|
|
|
16
16
|
import { HydraDBClient } from "@hydradb/sdk";
|
|
17
17
|
import type { HydraDB as SDK } from "@hydradb/sdk";
|
|
18
18
|
export type ContextKind = "memory" | "knowledge";
|
|
19
|
+
/**
|
|
20
|
+
* Sized to fit inside a typical MCP host's tool timeout rather than outlast it,
|
|
21
|
+
* so a stalled call fails with a HydraDB diagnostic the caller can act on
|
|
22
|
+
* instead of a generic host-side timeout carrying no information.
|
|
23
|
+
*/
|
|
24
|
+
export declare const DEFAULT_TIMEOUT_SECONDS = 30;
|
|
25
|
+
export declare const DEFAULT_MAX_RETRIES = 2;
|
|
26
|
+
/**
|
|
27
|
+
* Per-call transport controls, separate from the domain params.
|
|
28
|
+
*
|
|
29
|
+
* `signal` carries the host's cancellation into the SDK. Without it a cancelled
|
|
30
|
+
* MCP tool call leaves the outbound HTTP request in flight: the caller has given
|
|
31
|
+
* up, and the process keeps working and keeps retrying on its behalf.
|
|
32
|
+
*/
|
|
33
|
+
export interface RequestOptions {
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
}
|
|
19
36
|
/**
|
|
20
37
|
* Retrieval accepts a third corpus selector the write/list paths do not: `all`,
|
|
21
38
|
* which searches memories and knowledge together. Only `context.query` takes it
|
|
@@ -31,16 +48,44 @@ export interface HydraConfig {
|
|
|
31
48
|
collection?: string;
|
|
32
49
|
/** Optional base URL override; defaults to the SDK's environment. */
|
|
33
50
|
baseUrl?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Per-attempt deadline. The SDK's own default is 60s, which combined with its
|
|
53
|
+
* 2 retries means a persistently failing endpoint can occupy a caller for
|
|
54
|
+
* ~3 minutes with no output — far longer than any MCP host waits, so in
|
|
55
|
+
* practice the host times out first and the caller gets a generic error with
|
|
56
|
+
* no HydraDB diagnostic while this process keeps retrying.
|
|
57
|
+
*/
|
|
58
|
+
timeoutSeconds?: number;
|
|
59
|
+
/** Retries per call. The SDK defaults to 2; set explicitly so it is a choice. */
|
|
60
|
+
maxRetries?: number;
|
|
34
61
|
}
|
|
35
62
|
export interface QueryParams {
|
|
36
63
|
query: string;
|
|
37
64
|
kind?: QueryKind;
|
|
65
|
+
/**
|
|
66
|
+
* How the terms in `query` are combined. Keyword semantics, so it is only
|
|
67
|
+
* meaningful — and only accepted — under `queryBy: "text"`; see `query`.
|
|
68
|
+
*/
|
|
38
69
|
operator?: "or" | "and" | "phrase";
|
|
70
|
+
/**
|
|
71
|
+
* Retrieval method. `hybrid` (what the API uses when this is omitted) runs
|
|
72
|
+
* dense and sparse retrieval together; `text` is keyword matching only.
|
|
73
|
+
*/
|
|
74
|
+
queryBy?: "hybrid" | "text";
|
|
39
75
|
maxResults?: number;
|
|
40
76
|
mode?: "fast" | "thinking" | "auto";
|
|
41
77
|
graphContext?: boolean;
|
|
42
78
|
alpha?: number;
|
|
43
79
|
recencyBias?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Restrict retrieval to these source ids. A hard pre-filter: the server
|
|
82
|
+
* returns nothing rather than widening when none match.
|
|
83
|
+
*/
|
|
84
|
+
ids?: string[];
|
|
85
|
+
/** Exact-match filters over stored metadata. No ranges, no partial matches. */
|
|
86
|
+
metadataFilters?: Record<string, unknown>;
|
|
87
|
+
/** Adjacent chunks pulled in alongside each match, for surrounding context. */
|
|
88
|
+
numRelatedChunks?: number;
|
|
44
89
|
/** Per-call collection override. */
|
|
45
90
|
collection?: string;
|
|
46
91
|
}
|
|
@@ -62,6 +107,19 @@ export interface IngestParams {
|
|
|
62
107
|
/** Passed through only when `infer` is truthy (host-owned default text). */
|
|
63
108
|
customInstructions?: string;
|
|
64
109
|
upsert?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Tenant metadata stored alongside the memory, and matchable later via
|
|
112
|
+
* `metadataFilters` on query.
|
|
113
|
+
*
|
|
114
|
+
* Accepted by the backend (`domain/memories/models.go`) but absent from the
|
|
115
|
+
* generated SDK request type, which is why the wrapper carries it explicitly
|
|
116
|
+
* inside the memory item rather than as a typed field.
|
|
117
|
+
*/
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
/** Document-level metadata, matchable via `additional_metadata`. */
|
|
120
|
+
additionalMetadata?: Record<string, unknown>;
|
|
121
|
+
/** When the fact was true, as opposed to when it was stored (RFC3339 date). */
|
|
122
|
+
observationDate?: string;
|
|
65
123
|
/** Filename to attach when ingesting knowledge text as a document. */
|
|
66
124
|
filename?: string;
|
|
67
125
|
collection?: string;
|
|
@@ -114,20 +172,31 @@ declare abstract class Resource {
|
|
|
114
172
|
}
|
|
115
173
|
export declare class ContextResource extends Resource {
|
|
116
174
|
constructor(sdk: HydraDBClient, database: string, collection?: string);
|
|
117
|
-
/**
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
175
|
+
/**
|
|
176
|
+
* The single retrieval entry point (SDK `client.query`).
|
|
177
|
+
*
|
|
178
|
+
* `async` so the operator/retrieval validation below surfaces as a rejection,
|
|
179
|
+
* for the same reason `ingest` is async.
|
|
180
|
+
*/
|
|
181
|
+
query(params: QueryParams, opts?: RequestOptions): Promise<SDK.SearchV2RetrievalResult>;
|
|
182
|
+
/**
|
|
183
|
+
* Ingest a memory or knowledge item (SDK `context.ingest`, multipart).
|
|
184
|
+
*
|
|
185
|
+
* `async` so the knowledge-path validation below surfaces as a rejection.
|
|
186
|
+
* Every other failure in this wrapper rejects, and a caller that only handles
|
|
187
|
+
* `.catch()` would otherwise see this one escape as a synchronous throw.
|
|
188
|
+
*/
|
|
189
|
+
ingest(params: IngestParams, opts?: RequestOptions): Promise<SDK.IngestionV2SourceUploadResponse>;
|
|
121
190
|
/** List memories or knowledge sources (SDK `context.list`). */
|
|
122
|
-
list(params?: ListParams): Promise<SDK.ListV2SourceListResponse>;
|
|
191
|
+
list(params?: ListParams, opts?: RequestOptions): Promise<SDK.ListV2SourceListResponse>;
|
|
123
192
|
/** Fetch a source's content (SDK `context.inspect`; was "fetch content"). */
|
|
124
|
-
inspect(params: InspectParams): Promise<SDK.FetchV2SourceFetchResponse>;
|
|
193
|
+
inspect(params: InspectParams, opts?: RequestOptions): Promise<SDK.FetchV2SourceFetchResponse>;
|
|
125
194
|
/** Per-source indexing progress (SDK `context.status`). */
|
|
126
|
-
ingestionStatus(params: IngestionStatusParams): Promise<SDK.IngestionV2BatchProcessingStatus>;
|
|
195
|
+
ingestionStatus(params: IngestionStatusParams, opts?: RequestOptions): Promise<SDK.IngestionV2BatchProcessingStatus>;
|
|
127
196
|
/** Knowledge-graph relations (SDK `context.relations`). */
|
|
128
197
|
relations(params?: RelationsParams): Promise<SDK.GraphGraphRelationsResponse>;
|
|
129
198
|
/** Delete memories or knowledge sources (SDK `context.delete`). */
|
|
130
|
-
delete(params: DeleteParams): Promise<SDK.SourcesMemoryDeleteResponse>;
|
|
199
|
+
delete(params: DeleteParams, opts?: RequestOptions): Promise<SDK.SourcesMemoryDeleteResponse>;
|
|
131
200
|
}
|
|
132
201
|
export declare class DatabasesResource extends Resource {
|
|
133
202
|
constructor(sdk: HydraDBClient, database: string, collection?: string);
|
package/dist/hydra/client.js
CHANGED
|
@@ -17,8 +17,34 @@ import { Buffer } from "node:buffer";
|
|
|
17
17
|
import { HydraDBClient } from "@hydradb/sdk";
|
|
18
18
|
import { unwrap } from "./envelope.js";
|
|
19
19
|
import { translateError } from "./errors.js";
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Sized to fit inside a typical MCP host's tool timeout rather than outlast it,
|
|
22
|
+
* so a stalled call fails with a HydraDB diagnostic the caller can act on
|
|
23
|
+
* instead of a generic host-side timeout carrying no information.
|
|
24
|
+
*/
|
|
25
|
+
export const DEFAULT_TIMEOUT_SECONDS = 30;
|
|
26
|
+
export const DEFAULT_MAX_RETRIES = 2;
|
|
27
|
+
/**
|
|
28
|
+
* An SDK logger that cannot corrupt the stdio transport.
|
|
29
|
+
*
|
|
30
|
+
* The SDK's own `ConsoleLogger` implements `debug`/`info` via `console.debug` /
|
|
31
|
+
* `console.info`, which are stdout aliases in Node. On stdio transport stdout IS
|
|
32
|
+
* the JSON-RPC channel, so a single SDK log line would break the session.
|
|
33
|
+
*
|
|
34
|
+
* Not currently live — the SDK's default logger is constructed `silent: true` —
|
|
35
|
+
* but the exposure is one `logging: { level: "debug" }` away, which is precisely
|
|
36
|
+
* what someone debugging a production incident reaches for. Passing an explicit
|
|
37
|
+
* logger pins the safe behaviour instead of inheriting it.
|
|
38
|
+
*/
|
|
39
|
+
const STDERR_LOGGER = {
|
|
40
|
+
debug: (message, ...args) => console.error("[hydradb-sdk]", message, ...args),
|
|
41
|
+
info: (message, ...args) => console.error("[hydradb-sdk]", message, ...args),
|
|
42
|
+
warn: (message, ...args) => console.error("[hydradb-sdk]", message, ...args),
|
|
43
|
+
error: (message, ...args) => console.error("[hydradb-sdk]", message, ...args),
|
|
44
|
+
};
|
|
45
|
+
/** Wrapper options → the SDK's per-request options, omitted when there is nothing to say. */
|
|
46
|
+
function req(opts) {
|
|
47
|
+
return opts?.signal ? { abortSignal: opts.signal } : undefined;
|
|
22
48
|
}
|
|
23
49
|
class Resource {
|
|
24
50
|
constructor(sdk, database, collection) {
|
|
@@ -42,28 +68,64 @@ class Resource {
|
|
|
42
68
|
}
|
|
43
69
|
}
|
|
44
70
|
export class ContextResource extends Resource {
|
|
71
|
+
// The base constructor is `protected`, so this one is what makes the class
|
|
72
|
+
// instantiable from outside the file. Removing it fails with TS2674.
|
|
73
|
+
// biome-ignore lint/complexity/noUselessConstructor: widens visibility
|
|
45
74
|
constructor(sdk, database, collection) {
|
|
46
75
|
super(sdk, database, collection);
|
|
47
76
|
}
|
|
48
|
-
/**
|
|
49
|
-
|
|
77
|
+
/**
|
|
78
|
+
* The single retrieval entry point (SDK `client.query`).
|
|
79
|
+
*
|
|
80
|
+
* `async` so the operator/retrieval validation below surfaces as a rejection,
|
|
81
|
+
* for the same reason `ingest` is async.
|
|
82
|
+
*/
|
|
83
|
+
async query(params, opts) {
|
|
84
|
+
// `operator` is keyword syntax, and the API accepts it only when the
|
|
85
|
+
// request also asks for keyword retrieval. On hybrid it does not ignore
|
|
86
|
+
// the field, it refuses the whole call:
|
|
87
|
+
// Hydra DB /query → 400: INVALID_INPUT: operator is only valid with query_by=text
|
|
88
|
+
// This wrapper forwarded `operator` and never sent `query_by`, so EVERY
|
|
89
|
+
// call that set it 400'd — the parameter could not succeed under any
|
|
90
|
+
// input. An operator therefore carries its retrieval method with it.
|
|
91
|
+
//
|
|
92
|
+
// A caller that states `queryBy` is never overridden: `hybrid` with an
|
|
93
|
+
// operator is a contradiction only they can resolve, so it is rejected
|
|
94
|
+
// here rather than sent to fail on the wire (the same stance the
|
|
95
|
+
// knowledge-ingest path takes toward params it cannot honour).
|
|
96
|
+
if (params.operator != null && params.queryBy === "hybrid") {
|
|
97
|
+
throw new Error(`operator "${params.operator}" is only valid with queryBy "text" — ` +
|
|
98
|
+
`hybrid retrieval rejects the request outright. Drop operator to keep ` +
|
|
99
|
+
`hybrid retrieval, or pass queryBy "text" to match on the terms.`);
|
|
100
|
+
}
|
|
101
|
+
const queryBy = params.queryBy ?? (params.operator != null ? "text" : undefined);
|
|
50
102
|
return this.call("/query", () => this.sdk.query({
|
|
51
103
|
...this.scope(params.collection),
|
|
52
104
|
query: params.query,
|
|
53
|
-
type:
|
|
105
|
+
type: params.kind,
|
|
54
106
|
operator: params.operator,
|
|
107
|
+
queryBy,
|
|
55
108
|
maxResults: params.maxResults,
|
|
56
109
|
mode: params.mode,
|
|
57
110
|
graphContext: params.graphContext,
|
|
58
111
|
alpha: params.alpha,
|
|
59
112
|
recencyBias: params.recencyBias,
|
|
60
|
-
|
|
113
|
+
ids: params.ids,
|
|
114
|
+
metadataFilters: params.metadataFilters,
|
|
115
|
+
numRelatedChunks: params.numRelatedChunks,
|
|
116
|
+
}, req(opts)));
|
|
61
117
|
}
|
|
62
|
-
/**
|
|
63
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Ingest a memory or knowledge item (SDK `context.ingest`, multipart).
|
|
120
|
+
*
|
|
121
|
+
* `async` so the knowledge-path validation below surfaces as a rejection.
|
|
122
|
+
* Every other failure in this wrapper rejects, and a caller that only handles
|
|
123
|
+
* `.catch()` would otherwise see this one escape as a synchronous throw.
|
|
124
|
+
*/
|
|
125
|
+
async ingest(params, opts) {
|
|
64
126
|
const request = {
|
|
65
127
|
...this.scope(params.collection),
|
|
66
|
-
type:
|
|
128
|
+
type: params.kind,
|
|
67
129
|
};
|
|
68
130
|
if (params.upsert != null) {
|
|
69
131
|
request.upsert = String(params.upsert);
|
|
@@ -88,9 +150,41 @@ export class ContextResource extends Resource {
|
|
|
88
150
|
item.title = params.title;
|
|
89
151
|
if (params.userName != null)
|
|
90
152
|
item.user_name = params.userName;
|
|
153
|
+
if (params.metadata != null)
|
|
154
|
+
item.metadata = params.metadata;
|
|
155
|
+
if (params.additionalMetadata != null) {
|
|
156
|
+
item.additional_metadata = params.additionalMetadata;
|
|
157
|
+
}
|
|
158
|
+
if (params.observationDate != null) {
|
|
159
|
+
item.observation_date = params.observationDate;
|
|
160
|
+
}
|
|
91
161
|
request.memories = JSON.stringify([item]);
|
|
92
162
|
}
|
|
93
163
|
else {
|
|
164
|
+
// The knowledge path can only carry the document itself and its
|
|
165
|
+
// filename. Everything below belongs to the memory item shape and has
|
|
166
|
+
// nowhere to go here — so reject rather than accept and discard. A
|
|
167
|
+
// caller that sets `infer: true` on a knowledge write and is answered
|
|
168
|
+
// "success: 1, failed: 0" has been told its instruction was honoured
|
|
169
|
+
// when it was dropped on the floor.
|
|
170
|
+
const unsupported = [
|
|
171
|
+
["pairs", params.pairs],
|
|
172
|
+
["sourceId", params.sourceId],
|
|
173
|
+
["infer", params.infer],
|
|
174
|
+
["isMarkdown", params.isMarkdown],
|
|
175
|
+
["customInstructions", params.customInstructions],
|
|
176
|
+
["userName", params.userName],
|
|
177
|
+
["metadata", params.metadata],
|
|
178
|
+
["additionalMetadata", params.additionalMetadata],
|
|
179
|
+
["observationDate", params.observationDate],
|
|
180
|
+
]
|
|
181
|
+
.filter(([, value]) => value != null)
|
|
182
|
+
.map(([name]) => name);
|
|
183
|
+
if (unsupported.length > 0) {
|
|
184
|
+
throw new Error(`Knowledge ingestion does not support ${unsupported.join(", ")} — ` +
|
|
185
|
+
`those apply to memory ingestion only. Pass kind "memory" instead, ` +
|
|
186
|
+
`or drop them.`);
|
|
187
|
+
}
|
|
94
188
|
// Knowledge is multipart with the document as a file part — never the
|
|
95
189
|
// `app_knowledge` JSON field (guards the DX-G-002 class of bug).
|
|
96
190
|
if (params.text != null) {
|
|
@@ -103,54 +197,57 @@ export class ContextResource extends Resource {
|
|
|
103
197
|
};
|
|
104
198
|
}
|
|
105
199
|
}
|
|
106
|
-
return this.call("/context/ingest", () => this.sdk.context.ingest(request));
|
|
200
|
+
return this.call("/context/ingest", () => this.sdk.context.ingest(request, req(opts)));
|
|
107
201
|
}
|
|
108
202
|
/** List memories or knowledge sources (SDK `context.list`). */
|
|
109
|
-
list(params = {}) {
|
|
203
|
+
list(params = {}, opts) {
|
|
110
204
|
return this.call("/context/list", () => this.sdk.context.list({
|
|
111
205
|
...this.scope(params.collection),
|
|
112
|
-
type:
|
|
206
|
+
type: params.kind,
|
|
113
207
|
ids: params.ids,
|
|
114
208
|
page: params.page,
|
|
115
209
|
pageSize: params.pageSize,
|
|
116
|
-
}));
|
|
210
|
+
}, req(opts)));
|
|
117
211
|
}
|
|
118
212
|
/** Fetch a source's content (SDK `context.inspect`; was "fetch content"). */
|
|
119
|
-
inspect(params) {
|
|
213
|
+
inspect(params, opts) {
|
|
120
214
|
return this.call("/context/inspect", () => this.sdk.context.inspect({
|
|
121
215
|
...this.scope(params.collection),
|
|
122
216
|
id: params.id,
|
|
123
217
|
mode: params.mode,
|
|
124
218
|
expirySeconds: params.expirySeconds,
|
|
125
|
-
}));
|
|
219
|
+
}, req(opts)));
|
|
126
220
|
}
|
|
127
221
|
/** Per-source indexing progress (SDK `context.status`). */
|
|
128
|
-
ingestionStatus(params) {
|
|
222
|
+
ingestionStatus(params, opts) {
|
|
129
223
|
return this.call("/context/status", () => this.sdk.context.status({
|
|
130
224
|
...this.scope(params.collection),
|
|
131
225
|
ids: params.ids,
|
|
132
|
-
}));
|
|
226
|
+
}, req(opts)));
|
|
133
227
|
}
|
|
134
228
|
/** Knowledge-graph relations (SDK `context.relations`). */
|
|
135
229
|
relations(params = {}) {
|
|
136
230
|
return this.call("/context/relations", () => this.sdk.context.relations({
|
|
137
231
|
...this.scope(params.collection),
|
|
138
232
|
id: params.id,
|
|
139
|
-
type:
|
|
233
|
+
type: params.kind,
|
|
140
234
|
limit: params.limit,
|
|
141
235
|
cursor: params.cursor,
|
|
142
236
|
}));
|
|
143
237
|
}
|
|
144
238
|
/** Delete memories or knowledge sources (SDK `context.delete`). */
|
|
145
|
-
delete(params) {
|
|
239
|
+
delete(params, opts) {
|
|
146
240
|
return this.call("/context", () => this.sdk.context.delete({
|
|
147
241
|
...this.scope(params.collection),
|
|
148
242
|
ids: params.ids,
|
|
149
|
-
type:
|
|
150
|
-
}));
|
|
243
|
+
type: params.kind,
|
|
244
|
+
}, req(opts)));
|
|
151
245
|
}
|
|
152
246
|
}
|
|
153
247
|
export class DatabasesResource extends Resource {
|
|
248
|
+
// The base constructor is `protected`, so this one is what makes the class
|
|
249
|
+
// instantiable from outside the file. Removing it fails with TS2674.
|
|
250
|
+
// biome-ignore lint/complexity/noUselessConstructor: widens visibility
|
|
154
251
|
constructor(sdk, database, collection) {
|
|
155
252
|
super(sdk, database, collection);
|
|
156
253
|
}
|
|
@@ -189,6 +286,15 @@ export class HydraDB {
|
|
|
189
286
|
new HydraDBClient({
|
|
190
287
|
token: config.token,
|
|
191
288
|
...(config.baseUrl != null ? { baseUrl: config.baseUrl } : {}),
|
|
289
|
+
// Both are stated rather than inherited. The SDK's defaults (60s,
|
|
290
|
+
// 2 retries) were never chosen by this server, and their product is
|
|
291
|
+
// a ~3 minute worst case on the slowest tool it exposes.
|
|
292
|
+
timeoutInSeconds: config.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS,
|
|
293
|
+
maxRetries: config.maxRetries ?? DEFAULT_MAX_RETRIES,
|
|
294
|
+
// Never inherit the SDK's console logger: it writes to stdout, which
|
|
295
|
+
// on stdio transport is the JSON-RPC channel. Only the sink is
|
|
296
|
+
// overridden — level and silencing keep the SDK's own defaults.
|
|
297
|
+
logging: { logger: STDERR_LOGGER },
|
|
192
298
|
});
|
|
193
299
|
this.context = new ContextResource(client, config.database, config.collection);
|
|
194
300
|
this.databases = new DatabasesResource(client, config.database, config.collection);
|
package/dist/hydra/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/hydra/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/hydra/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAoBrC;;;;;;;;;;;GAWG;AACH,MAAM,aAAa,GAAG;IACrB,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE,CAC9C,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE,CAC7C,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE,CAC7C,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAA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HydraWrapperError extends Error {
|
|
|
27
27
|
Object.setPrototypeOf(this, HydraWrapperError.prototype);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
/** Anything past this is not diagnosis, it is payload. */
|
|
31
|
+
const MAX_BODY_CHARS = 512;
|
|
32
|
+
/**
|
|
33
|
+
* Credential-shaped substrings, scrubbed before an error body is shown.
|
|
34
|
+
*
|
|
35
|
+
* Defence in depth for bodies we did not write. HydraDB's own error path is
|
|
36
|
+
* clean — every 401 message is a static string literal and backend failures
|
|
37
|
+
* collapse to "Internal server error" — but this string also carries whatever a
|
|
38
|
+
* CDN, load balancer, WAF or corporate proxy returns, and those are not ours to
|
|
39
|
+
* vouch for. The SDK already redacts sensitive headers and query params before
|
|
40
|
+
* logging; response bodies are the one place it does not.
|
|
41
|
+
*/
|
|
42
|
+
const SECRET_PATTERNS = [
|
|
43
|
+
[/\bBearer\s+\S+/gi, "Bearer [redacted]"],
|
|
44
|
+
[/\b(sk|hdb|key|tok)[-_][A-Za-z0-9_-]{16,}/g, "[redacted]"],
|
|
45
|
+
[
|
|
46
|
+
/("(?:api[-_]?key|token|authorization|password|secret)"\s*:\s*)"[^"]*"/gi,
|
|
47
|
+
'$1"[redacted]"',
|
|
48
|
+
],
|
|
49
|
+
];
|
|
50
|
+
function scrub(text) {
|
|
51
|
+
let out = text;
|
|
52
|
+
for (const [pattern, replacement] of SECRET_PATTERNS) {
|
|
53
|
+
out = out.replace(pattern, replacement);
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
/** Reduce an HTML error page to its readable text, so the cap spends its budget well. */
|
|
58
|
+
function stripMarkup(text) {
|
|
59
|
+
if (!/^\s*</.test(text))
|
|
60
|
+
return text;
|
|
61
|
+
const title = text.match(/<title[^>]*>([\s\S]*?)<\/title>/i)?.[1]?.trim();
|
|
62
|
+
const stripped = text
|
|
63
|
+
.replace(/<script[\s\S]*?<\/script>/gi, " ")
|
|
64
|
+
.replace(/<style[\s\S]*?<\/style>/gi, " ")
|
|
65
|
+
.replace(/<[^>]+>/g, " ")
|
|
66
|
+
.replace(/\s+/g, " ")
|
|
67
|
+
.trim();
|
|
68
|
+
return title ? `${title} — ${stripped}` : stripped;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The v2 envelope, when the body is one.
|
|
72
|
+
*
|
|
73
|
+
* Rendering `error.code` / `error.message` / `meta.request_id` instead of the
|
|
74
|
+
* whole JSON blob makes the common case both shorter AND more useful: the
|
|
75
|
+
* request id is exactly what a user needs to file a support ticket, and it was
|
|
76
|
+
* previously buried in a stringified object.
|
|
77
|
+
*/
|
|
78
|
+
function fromEnvelope(body) {
|
|
79
|
+
if (body == null || typeof body !== "object")
|
|
80
|
+
return undefined;
|
|
81
|
+
const record = body;
|
|
82
|
+
const error = record.error;
|
|
83
|
+
if (error == null || typeof error !== "object")
|
|
84
|
+
return undefined;
|
|
85
|
+
const { code, message } = error;
|
|
86
|
+
const parts = [];
|
|
87
|
+
if (typeof code === "string" && code !== "")
|
|
88
|
+
parts.push(code);
|
|
89
|
+
if (typeof message === "string" && message !== "")
|
|
90
|
+
parts.push(message);
|
|
91
|
+
if (parts.length === 0)
|
|
92
|
+
return undefined;
|
|
93
|
+
const meta = record.meta;
|
|
94
|
+
const requestId = meta != null && typeof meta === "object"
|
|
95
|
+
? meta.request_id
|
|
96
|
+
: undefined;
|
|
97
|
+
const trailer = typeof requestId === "string" && requestId !== ""
|
|
98
|
+
? ` (request_id: ${requestId})`
|
|
99
|
+
: "";
|
|
100
|
+
return `${parts.join(": ")}${trailer}`;
|
|
101
|
+
}
|
|
30
102
|
function bodyToString(body) {
|
|
31
103
|
if (body == null)
|
|
32
104
|
return "";
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
105
|
+
const structured = fromEnvelope(body);
|
|
106
|
+
if (structured != null)
|
|
107
|
+
return truncate(scrub(structured));
|
|
108
|
+
let raw;
|
|
109
|
+
if (typeof body === "string") {
|
|
110
|
+
raw = body;
|
|
37
111
|
}
|
|
38
|
-
|
|
39
|
-
|
|
112
|
+
else {
|
|
113
|
+
try {
|
|
114
|
+
raw = JSON.stringify(body);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
raw = String(body);
|
|
118
|
+
}
|
|
40
119
|
}
|
|
120
|
+
return truncate(scrub(stripMarkup(raw)));
|
|
121
|
+
}
|
|
122
|
+
function truncate(text) {
|
|
123
|
+
if (text.length <= MAX_BODY_CHARS)
|
|
124
|
+
return text;
|
|
125
|
+
return `${text.slice(0, MAX_BODY_CHARS)}… (truncated, ${text.length} chars)`;
|
|
41
126
|
}
|
|
42
127
|
/**
|
|
43
128
|
* Translate any error thrown by an SDK call into a `HydraWrapperError` carrying
|
package/dist/hydra/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/hydra/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAU3C,YACC,OAAe,EACf,IAAY,EACZ,IAA2D;QAE3D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,EAAE,IAAI,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,CAAC;QACzB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACD;AAED,SAAS,YAAY,CAAC,IAAa;IAClC,IAAI,IAAI,IAAI,IAAI;QAAE,OAAO,EAAE,CAAC;
|
|
1
|
+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AI,GAAG,YAAY,YAAY,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC;QAC9B,MAAM,UAAU,GAAG,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAC3D,OAAO,IAAI,iBAAiB,CAC3B,YAAY,IAAI,MAAM,UAAU,KAAK,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAC7D,IAAI,EACJ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CACtC,CAAC;IACH,CAAC;IAED,sEAAsE;IACtE,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,IAAI,iBAAiB,CAAC,YAAY,IAAI,WAAW,OAAO,EAAE,EAAE,IAAI,EAAE;QACxE,KAAK,EAAE,GAAG;KACV,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/hydra/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* It is intentionally self-contained so the same pattern can be ported to the
|
|
6
6
|
* other client repos (per CONTRACT.md).
|
|
7
7
|
*/
|
|
8
|
-
export { HydraDB, ContextResource, DatabasesResource } from "./client.js";
|
|
9
|
-
export type { HydraConfig, ContextKind, QueryKind, ConversationTurn, QueryParams, IngestParams, ListParams, InspectParams, IngestionStatusParams, RelationsParams, DeleteParams, CreateDatabaseParams, } from "./client.js";
|
|
8
|
+
export { HydraDB, ContextResource, DatabasesResource, DEFAULT_TIMEOUT_SECONDS, DEFAULT_MAX_RETRIES, } from "./client.js";
|
|
9
|
+
export type { HydraConfig, ContextKind, RequestOptions, QueryKind, ConversationTurn, QueryParams, IngestParams, ListParams, InspectParams, IngestionStatusParams, RelationsParams, DeleteParams, CreateDatabaseParams, } from "./client.js";
|
|
10
10
|
export { HydraWrapperError, translateError } from "./errors.js";
|
|
11
11
|
export { unwrap } from "./envelope.js";
|
package/dist/hydra/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* It is intentionally self-contained so the same pattern can be ported to the
|
|
6
6
|
* other client repos (per CONTRACT.md).
|
|
7
7
|
*/
|
|
8
|
-
export { HydraDB, ContextResource, DatabasesResource } from "./client.js";
|
|
8
|
+
export { HydraDB, ContextResource, DatabasesResource, DEFAULT_TIMEOUT_SECONDS, DEFAULT_MAX_RETRIES, } from "./client.js";
|
|
9
9
|
export { HydraWrapperError, translateError } from "./errors.js";
|
|
10
10
|
export { unwrap } from "./envelope.js";
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
package/dist/hydra/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hydra/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hydra/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACN,OAAO,EACP,eAAe,EACf,iBAAiB,EACjB,uBAAuB,EACvB,mBAAmB,GACnB,MAAM,aAAa,CAAC;AAgBrB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC"}
|