@qverisai/sdk 0.1.2 → 0.3.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +1 -1
  3. package/README.md +129 -216
  4. package/dist/client.d.ts +116 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +334 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/errors.d.ts +25 -0
  9. package/dist/errors.d.ts.map +1 -0
  10. package/dist/errors.js +34 -0
  11. package/dist/errors.js.map +1 -0
  12. package/dist/index.d.ts +14 -20
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +12 -260
  15. package/dist/index.js.map +1 -1
  16. package/dist/integrations/ai.d.ts +768 -0
  17. package/dist/integrations/ai.d.ts.map +1 -0
  18. package/dist/integrations/ai.js +87 -0
  19. package/dist/integrations/ai.js.map +1 -0
  20. package/dist/retry.d.ts +42 -0
  21. package/dist/retry.d.ts.map +1 -0
  22. package/dist/retry.js +63 -0
  23. package/dist/retry.js.map +1 -0
  24. package/dist/types.d.ts +266 -62
  25. package/dist/types.d.ts.map +1 -1
  26. package/dist/types.js +3 -2
  27. package/dist/types.js.map +1 -1
  28. package/package.json +72 -55
  29. package/dist/api/client.d.ts +0 -147
  30. package/dist/api/client.d.ts.map +0 -1
  31. package/dist/api/client.js +0 -201
  32. package/dist/api/client.js.map +0 -1
  33. package/dist/tools/execute.d.ts +0 -89
  34. package/dist/tools/execute.d.ts.map +0 -1
  35. package/dist/tools/execute.js +0 -73
  36. package/dist/tools/execute.js.map +0 -1
  37. package/dist/tools/get-by-ids.d.ts +0 -69
  38. package/dist/tools/get-by-ids.d.ts.map +0 -1
  39. package/dist/tools/get-by-ids.js +0 -55
  40. package/dist/tools/get-by-ids.js.map +0 -1
  41. package/dist/tools/search.d.ts +0 -71
  42. package/dist/tools/search.d.ts.map +0 -1
  43. package/dist/tools/search.js +0 -53
  44. package/dist/tools/search.js.map +0 -1
package/dist/client.js ADDED
@@ -0,0 +1,334 @@
1
+ /**
2
+ * QVeris API client.
3
+ *
4
+ * A lightweight, dependency-free typed client for the QVeris REST API using
5
+ * native fetch (Node.js 18+). Handles authentication, region resolution,
6
+ * success-envelope unwrapping, timeouts, and error normalization.
7
+ *
8
+ * The wire semantics mirror the Python SDK (`qveris` on PyPI) and the MCP
9
+ * server (`@qverisai/mcp`).
10
+ *
11
+ * @module client
12
+ */
13
+ import { QverisApiError } from './errors.js';
14
+ import { computeRetryDelayMs, DEFAULT_BASE_DELAY_MS, DEFAULT_MAX_DELAY_MS, parseRetryAfterMs, resolveMaxRetries, RETRYABLE_STATUS, } from './retry.js';
15
+ /** Region-specific API base URLs */
16
+ const REGION_URLS = {
17
+ global: 'https://qveris.ai/api/v1',
18
+ cn: 'https://qveris.cn/api/v1',
19
+ };
20
+ /**
21
+ * Detect region from API key prefix.
22
+ * sk-cn-xxx -> cn, sk-xxx -> global
23
+ */
24
+ function detectRegionFromKey(apiKey) {
25
+ return apiKey.startsWith('sk-cn-') ? 'cn' : 'global';
26
+ }
27
+ /**
28
+ * Resolve the base URL for the QVeris API.
29
+ * Priority: explicit baseUrl > QVERIS_BASE_URL env > QVERIS_REGION env > key prefix auto-detect > default
30
+ */
31
+ function resolveBaseUrl(apiKey, explicitBaseUrl) {
32
+ if (explicitBaseUrl)
33
+ return explicitBaseUrl.replace(/\/+$/, '');
34
+ if (typeof process !== 'undefined') {
35
+ if (process.env.QVERIS_BASE_URL)
36
+ return process.env.QVERIS_BASE_URL.replace(/\/+$/, '');
37
+ if (process.env.QVERIS_REGION) {
38
+ const region = process.env.QVERIS_REGION.toLowerCase();
39
+ return REGION_URLS[region] ?? REGION_URLS.global;
40
+ }
41
+ }
42
+ return REGION_URLS[detectRegionFromKey(apiKey)];
43
+ }
44
+ /** Default timeout: 30s for discover/inspect/audit, 120s for call */
45
+ const DEFAULT_TIMEOUT_MS = 30_000;
46
+ const EXECUTE_TIMEOUT_MS = 120_000;
47
+ /**
48
+ * QVeris API client.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * import { Qveris } from '@qverisai/sdk';
53
+ *
54
+ * const qveris = new Qveris({ apiKey: process.env.QVERIS_API_KEY! });
55
+ *
56
+ * const found = await qveris.discover('stock price market data API', { limit: 5 });
57
+ * const tool = found.results[0];
58
+ *
59
+ * const outcome = await qveris.call(tool.tool_id, {
60
+ * searchId: found.search_id,
61
+ * parameters: { symbol: 'AAPL' },
62
+ * });
63
+ * ```
64
+ */
65
+ export class Qveris {
66
+ apiKey;
67
+ baseUrl;
68
+ defaultTimeoutMs;
69
+ maxRetries;
70
+ rateLimitRetries = 0;
71
+ constructor(config) {
72
+ if (!config.apiKey) {
73
+ throw new Error('QVeris API key is required.\n' +
74
+ 'Global: https://qveris.ai/account?page=api-keys\n' +
75
+ 'China: https://qveris.cn/account?page=api-keys');
76
+ }
77
+ this.apiKey = config.apiKey;
78
+ this.baseUrl = resolveBaseUrl(config.apiKey, config.baseUrl);
79
+ this.defaultTimeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
80
+ this.maxRetries = resolveMaxRetries(config.maxRetries);
81
+ }
82
+ /**
83
+ * How many times the client has backed off on a rate-limited (429) /
84
+ * transient (503) response so far. Rate-limit backoff is retried pressure,
85
+ * not failure — observe this rather than counting the retried responses.
86
+ */
87
+ get rateLimitRetryCount() {
88
+ return this.rateLimitRetries;
89
+ }
90
+ /** Sleep for `ms` (a seam so tests can stub out the wait). */
91
+ async sleep(ms) {
92
+ if (ms <= 0)
93
+ return;
94
+ await new Promise((resolve) => setTimeout(resolve, ms));
95
+ }
96
+ /**
97
+ * Create a client from the QVERIS_API_KEY environment variable.
98
+ * Region is auto-detected from the key prefix (sk-cn-xxx -> cn), or
99
+ * overridden via QVERIS_REGION / QVERIS_BASE_URL.
100
+ */
101
+ static fromEnv(overrides) {
102
+ const apiKey = process.env.QVERIS_API_KEY;
103
+ if (!apiKey) {
104
+ throw new Error('QVERIS_API_KEY environment variable is required.\n' +
105
+ 'Global: https://qveris.ai/account?page=api-keys\n' +
106
+ 'China: https://qveris.cn/account?page=api-keys');
107
+ }
108
+ return new Qveris({ apiKey, ...overrides });
109
+ }
110
+ /**
111
+ * Discover capabilities from a natural-language query. Free.
112
+ */
113
+ async discover(query, options = {}) {
114
+ return this.request('discover', 'POST', '/search', {
115
+ query,
116
+ ...(options.limit !== undefined && { limit: options.limit }),
117
+ ...(options.sessionId !== undefined && { session_id: options.sessionId }),
118
+ }, options.timeoutMs);
119
+ }
120
+ /**
121
+ * Inspect capabilities by id to get current parameter schemas. Free.
122
+ * An empty id list resolves locally without a network request.
123
+ */
124
+ async inspect(toolIds, options = {}) {
125
+ const ids = typeof toolIds === 'string' ? [toolIds] : toolIds;
126
+ if (ids.length === 0) {
127
+ return { search_id: options.searchId ?? '', total: 0, results: [] };
128
+ }
129
+ return this.request('inspect', 'POST', '/tools/by-ids', {
130
+ tool_ids: ids,
131
+ ...(options.searchId !== undefined && { search_id: options.searchId }),
132
+ ...(options.sessionId !== undefined && { session_id: options.sessionId }),
133
+ }, options.timeoutMs);
134
+ }
135
+ /**
136
+ * Call a capability. The response may include pre-settlement billing;
137
+ * final charges are reflected in usage() and ledger().
138
+ */
139
+ async call(toolId, options) {
140
+ return this.request('call', 'POST', `/tools/execute?tool_id=${encodeURIComponent(toolId)}`, {
141
+ parameters: options.parameters,
142
+ search_id: options.searchId ?? null,
143
+ ...(options.sessionId !== undefined && { session_id: options.sessionId }),
144
+ ...(options.maxResponseSize !== undefined && {
145
+ max_response_size: options.maxResponseSize,
146
+ }),
147
+ }, options.timeoutMs ?? EXECUTE_TIMEOUT_MS);
148
+ }
149
+ /** Get current credit balance and bucket details. */
150
+ async credits() {
151
+ return this.request('credits', 'GET', '/auth/credits');
152
+ }
153
+ /** Query request-level usage audit history. */
154
+ async usage(filters = {}) {
155
+ return this.request('usage_history', 'GET', '/auth/usage/history/v2', undefined, undefined, filters);
156
+ }
157
+ /** Query final credits ledger entries. */
158
+ async ledger(filters = {}) {
159
+ return this.request('credits_ledger', 'GET', '/auth/credits/ledger', undefined, undefined, filters);
160
+ }
161
+ /**
162
+ * Makes an authenticated HTTP request and unwraps success envelopes.
163
+ */
164
+ async request(operation, method, endpoint, body, timeoutMs, query) {
165
+ const url = new URL(`${this.baseUrl}${endpoint}`);
166
+ if (query) {
167
+ for (const [key, value] of Object.entries(query)) {
168
+ if (value !== undefined && value !== null && value !== '') {
169
+ url.searchParams.set(key, String(value));
170
+ }
171
+ }
172
+ }
173
+ const resolvedTimeoutMs = timeoutMs ?? this.defaultTimeoutMs;
174
+ const queryParams = Object.fromEntries(url.searchParams.entries());
175
+ const requestContext = {
176
+ source: 'qveris_api',
177
+ operation,
178
+ method,
179
+ endpoint,
180
+ url: url.toString(),
181
+ ...(Object.keys(queryParams).length > 0 && { query_params: queryParams }),
182
+ timeout_ms: resolvedTimeoutMs,
183
+ };
184
+ // Retry rate-limited (429) / transient (503) responses: honor Retry-After,
185
+ // otherwise exponential backoff with jitter, bounded by maxRetries. Each
186
+ // attempt is a fresh fetch with its own timeout.
187
+ for (let attempt = 0;; attempt++) {
188
+ const controller = new AbortController();
189
+ const timeout = setTimeout(() => controller.abort(), resolvedTimeoutMs);
190
+ let retryDelayMs = null;
191
+ try {
192
+ const response = await fetch(url.toString(), {
193
+ method,
194
+ headers: {
195
+ 'Authorization': `Bearer ${this.apiKey}`,
196
+ 'Content-Type': 'application/json',
197
+ },
198
+ body: body ? JSON.stringify(body) : undefined,
199
+ signal: controller.signal,
200
+ });
201
+ if (RETRYABLE_STATUS.has(response.status) && attempt < this.maxRetries) {
202
+ retryDelayMs = computeRetryDelayMs({
203
+ retryAfterMs: parseRetryAfterMs(response.headers.get('retry-after')),
204
+ attempt,
205
+ baseDelayMs: DEFAULT_BASE_DELAY_MS,
206
+ maxDelayMs: DEFAULT_MAX_DELAY_MS,
207
+ });
208
+ // Discard the body so the connection is released before we retry.
209
+ // (`.cancel?.()` so a body without cancel — e.g. a test double —
210
+ // can't throw here and mask the rate-limit as a network error.)
211
+ await response.body?.cancel?.().catch(() => undefined);
212
+ this.rateLimitRetries++;
213
+ }
214
+ else if (!response.ok) {
215
+ const status = response.status;
216
+ let errorMessage;
217
+ let errorDetails;
218
+ try {
219
+ const errorBody = (await response.json());
220
+ errorMessage =
221
+ errorBody.error_message ||
222
+ errorBody.message ||
223
+ errorBody.error ||
224
+ response.statusText;
225
+ errorDetails = errorBody;
226
+ }
227
+ catch {
228
+ errorMessage = response.statusText || `HTTP ${status}`;
229
+ }
230
+ if (status === 402) {
231
+ const pricingHost = this.baseUrl.includes('qveris.cn')
232
+ ? 'https://qveris.cn'
233
+ : 'https://qveris.ai';
234
+ errorMessage = `Insufficient credits. ${errorMessage}. Purchase credits at ${pricingHost}/pricing`;
235
+ }
236
+ throw new QverisApiError({
237
+ status,
238
+ message: errorMessage,
239
+ ...(errorDetails !== undefined && { details: errorDetails }),
240
+ observability: withErrorContext(requestContext, 'http_error', status, extractRequestId(response)),
241
+ });
242
+ }
243
+ else {
244
+ let payload;
245
+ try {
246
+ payload = await response.json();
247
+ }
248
+ catch {
249
+ throw new QverisApiError({
250
+ status: response.status,
251
+ message: 'Invalid or empty JSON response from API',
252
+ observability: withErrorContext(requestContext, 'invalid_json', response.status, extractRequestId(response)),
253
+ });
254
+ }
255
+ return this.unwrapEnvelope(payload, requestContext);
256
+ }
257
+ }
258
+ catch (err) {
259
+ if (err instanceof QverisApiError) {
260
+ throw err;
261
+ }
262
+ if (err instanceof Error && err.name === 'AbortError') {
263
+ throw new QverisApiError({
264
+ status: 408,
265
+ message: 'Request timed out. Check connectivity or increase timeout.',
266
+ observability: withErrorContext(requestContext, 'timeout', 0),
267
+ ...(errorCause(err) && { cause: errorCause(err) }),
268
+ });
269
+ }
270
+ throw new QverisApiError({
271
+ status: 0,
272
+ message: err instanceof Error && err.message ? err.message : 'Network request failed',
273
+ observability: withErrorContext(requestContext, 'network_error', 0),
274
+ ...(errorCause(err) && { cause: errorCause(err) }),
275
+ });
276
+ }
277
+ finally {
278
+ clearTimeout(timeout);
279
+ }
280
+ // Only reached on the retry path (success returns, errors throw above).
281
+ await this.sleep(retryDelayMs ?? 0);
282
+ }
283
+ }
284
+ /**
285
+ * Unwrap `{status: "success", data: ...}` envelopes; raw payloads pass
286
+ * through. A failure envelope throws before any result parsing, matching
287
+ * the Python SDK behavior.
288
+ */
289
+ unwrapEnvelope(payload, context) {
290
+ if (payload !== null &&
291
+ typeof payload === 'object' &&
292
+ 'status' in payload &&
293
+ 'data' in payload &&
294
+ typeof payload.status === 'string') {
295
+ const envelope = payload;
296
+ if (envelope.status !== 'success') {
297
+ throw new QverisApiError({
298
+ status: envelope.status_code ?? 400,
299
+ message: envelope.message ?? `API returned status "${envelope.status}"`,
300
+ details: payload,
301
+ observability: withErrorContext(context, 'http_error', envelope.status_code ?? 400),
302
+ });
303
+ }
304
+ return envelope.data;
305
+ }
306
+ return payload;
307
+ }
308
+ }
309
+ function withErrorContext(context, errorType, httpStatus, requestId) {
310
+ return {
311
+ ...context,
312
+ error_type: errorType,
313
+ ...(httpStatus !== undefined && { http_status: httpStatus }),
314
+ ...(requestId && { request_id: requestId }),
315
+ };
316
+ }
317
+ function extractRequestId(response) {
318
+ const headers = response.headers;
319
+ return (headers?.get('x-request-id') ??
320
+ headers?.get('x-qveris-request-id') ??
321
+ headers?.get('x-correlation-id') ??
322
+ undefined);
323
+ }
324
+ function errorCause(error) {
325
+ if (!(error instanceof Error))
326
+ return undefined;
327
+ const cause = error.cause;
328
+ if (cause instanceof Error)
329
+ return cause.message;
330
+ if (typeof cause === 'string' && cause)
331
+ return cause;
332
+ return undefined;
333
+ }
334
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C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Q,CAAC,WAAW,IAAI,GAAG,CAAC;iBACpF,CAAC,CAAC;YACL,CAAC;YACD,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QACD,OAAO,OAAY,CAAC;IACtB,CAAC;CACF;AAED,SAAS,gBAAgB,CACvB,OAAyB,EACzB,SAAsD,EACtD,UAAmB,EACnB,SAAkB;IAElB,OAAO;QACL,GAAG,OAAO;QACV,UAAU,EAAE,SAAS;QACrB,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;QAC5D,GAAG,CAAC,SAAS,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;KAC5C,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,QAAkB;IAC1C,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IACjC,OAAO,CACL,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC;QAC5B,OAAO,EAAE,GAAG,CAAC,qBAAqB,CAAC;QACnC,OAAO,EAAE,GAAG,CAAC,kBAAkB,CAAC;QAChC,SAAS,CACV,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAChD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC1B,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC;IACrD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * QVeris SDK error types.
3
+ *
4
+ * @module errors
5
+ */
6
+ import type { ApiError, ApiObservability } from './types.js';
7
+ /**
8
+ * Error thrown for any failed QVeris API interaction: HTTP errors,
9
+ * failure envelopes, timeouts, and network failures.
10
+ *
11
+ * Carries the same shape as the wire-level {@link ApiError} so callers can
12
+ * branch on `status` and inspect `observability` for diagnostics.
13
+ */
14
+ export declare class QverisApiError extends Error implements ApiError {
15
+ /** HTTP status code (0 for network errors, 408 for timeouts) */
16
+ readonly status: number;
17
+ /** Original error details if available */
18
+ readonly details?: unknown;
19
+ /** Request metadata for diagnosing API failures */
20
+ readonly observability?: ApiObservability;
21
+ /** Lower-level transport or runtime cause when available */
22
+ readonly cause?: string;
23
+ constructor(error: ApiError);
24
+ }
25
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE7D;;;;;;GAMG;AACH,qBAAa,cAAe,SAAQ,KAAM,YAAW,QAAQ;IAC3D,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,0CAA0C;IAC1C,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAE3B,mDAAmD;IACnD,QAAQ,CAAC,aAAa,CAAC,EAAE,gBAAgB,CAAC;IAE1C,4DAA4D;IAC5D,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;gBAEZ,KAAK,EAAE,QAAQ;CAQ5B"}
package/dist/errors.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * QVeris SDK error types.
3
+ *
4
+ * @module errors
5
+ */
6
+ /**
7
+ * Error thrown for any failed QVeris API interaction: HTTP errors,
8
+ * failure envelopes, timeouts, and network failures.
9
+ *
10
+ * Carries the same shape as the wire-level {@link ApiError} so callers can
11
+ * branch on `status` and inspect `observability` for diagnostics.
12
+ */
13
+ export class QverisApiError extends Error {
14
+ /** HTTP status code (0 for network errors, 408 for timeouts) */
15
+ status;
16
+ /** Original error details if available */
17
+ details;
18
+ /** Request metadata for diagnosing API failures */
19
+ observability;
20
+ /** Lower-level transport or runtime cause when available */
21
+ cause;
22
+ constructor(error) {
23
+ super(error.message);
24
+ this.name = 'QverisApiError';
25
+ this.status = error.status;
26
+ if (error.details !== undefined)
27
+ this.details = error.details;
28
+ if (error.observability !== undefined)
29
+ this.observability = error.observability;
30
+ if (error.cause !== undefined)
31
+ this.cause = error.cause;
32
+ }
33
+ }
34
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;GAMG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,gEAAgE;IACvD,MAAM,CAAS;IAExB,0CAA0C;IACjC,OAAO,CAAW;IAE3B,mDAAmD;IAC1C,aAAa,CAAoB;IAE1C,4DAA4D;IACnD,KAAK,CAAU;IAExB,YAAY,KAAe;QACzB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9D,IAAI,KAAK,CAAC,aAAa,KAAK,SAAS;YAAE,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;QAChF,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC1D,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,27 +1,21 @@
1
- #!/usr/bin/env node
2
1
  /**
3
- * Qveris MCP Server
2
+ * QVeris TypeScript SDK.
4
3
  *
5
- * A Model Context Protocol (MCP) server that provides access to the Qveris
6
- * tool discovery and execution API. Enables LLMs to dynamically search for
7
- * and execute third-party tools via natural language.
8
- *
9
- * @module @qverisai/sdk
10
- * @version 0.1.0
4
+ * Typed client for the QVeris Agent External Data & Tool Harness:
5
+ * discover, inspect, call, plus usage and credits-ledger audit.
11
6
  *
12
7
  * @example
13
- * Configure in Claude Desktop or Cursor:
14
- * ```json
15
- * {
16
- * "mcpServers": {
17
- * "qveris": {
18
- * "command": "npx",
19
- * "args": ["@qverisai/sdk"],
20
- * "env": { "QVERIS_API_KEY": "your-api-key" }
21
- * }
22
- * }
23
- * }
8
+ * ```typescript
9
+ * import { Qveris } from '@qverisai/sdk';
10
+ *
11
+ * const qveris = Qveris.fromEnv();
12
+ * const found = await qveris.discover('weather forecast API');
24
13
  * ```
14
+ *
15
+ * @module @qverisai/sdk
25
16
  */
26
- export {};
17
+ export { Qveris } from './client.js';
18
+ export type { DiscoverOptions, InspectOptions, CallOptions } from './client.js';
19
+ export { QverisApiError } from './errors.js';
20
+ export * from './types.js';
27
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;GAuBG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,cAAc,YAAY,CAAC"}