@qverisai/sdk 0.1.2 → 0.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 QverisAI
3
+ Copyright (c) 2025 QVerisAI
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,216 +1,93 @@
1
- # @qverisai/sdk
2
-
3
- Official Qveris MCP Server SDK Dynamically search and execute tools via natural language.
4
-
5
- [![npm version](https://img.shields.io/npm/v/@qverisai/sdk.svg)](https://www.npmjs.com/package/@qverisai/sdk)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
-
8
- ## Overview
9
-
10
- This SDK provides a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server that enables LLMs to discover and execute third-party tools through the Qveris API. With three simple tools, your AI assistant can:
11
-
12
- - **Search** for tools using natural language queries
13
- - **Get** detailed information about specific tools by their IDs
14
- - **Execute** any discovered tool with the appropriate parameters
15
-
16
- ## Quick Start
17
-
18
- ### 1. Get Your API Key
19
-
20
- Visit [Qveris](https://qveris.ai) to get your API key.
21
-
22
- ### 2. Configure Your MCP Client
23
-
24
- Add the Qveris server to your MCP client configuration:
25
-
26
- **Claude Desktop** (`claude_desktop_config.json`):
27
-
28
- ```json
29
- {
30
- "mcpServers": {
31
- "qveris": {
32
- "command": "npx",
33
- "args": ["@qverisai/sdk"],
34
- "env": {
35
- "QVERIS_API_KEY": "your-api-key-here"
36
- }
37
- }
38
- }
39
- }
40
- ```
41
-
42
- **Cursor** (Settings → MCP Servers):
43
-
44
- ```json
45
- {
46
- "mcpServers": {
47
- "qveris": {
48
- "command": "npx",
49
- "args": ["@qverisai/sdk"],
50
- "env": {
51
- "QVERIS_API_KEY": "your-api-key-here"
52
- }
53
- }
54
- }
55
- }
56
- ```
57
-
58
- ### 3. Start Using
59
-
60
- Once configured, You could add this to system prompt:
61
-
62
- > "You can use qveris MCP Server to dynamically search and execute tools to help the user. First think about what kind of tools might be useful to accomplish the user's task. Then use the search_tools tool with query describing the capability of the tool, not what params you want to pass to the tool later. Then call a suitable searched tool using the execute_tool tool, passing parameters to the searched tool through params_to_tool. You could reference the examples given if any for each tool. You may call make multiple tool calls in a single response."
63
-
64
- Then your AI assistant can search for and execute tools:
65
-
66
- > "Find me a weather tool and get the current weather in Tokyo"
67
-
68
- The assistant will:
69
- 1. Call `search_tools` with query "weather"
70
- 2. Review the results and select an appropriate tool
71
- 3. Call `execute_tool` with the tool_id and parameters
72
-
73
- ## Available Tools
74
-
75
- ### `search_tools`
76
-
77
- Search for available tools based on natural language queries.
78
-
79
- | Parameter | Type | Required | Description |
80
- |-----------|------|----------|-------------|
81
- | `query` | string | ✓ | Natural language description of the capability you need |
82
- | `limit` | number | | Max results to return (1-100, default: 20) |
83
- | `session_id` | string | | Session identifier for tracking (auto-generated if omitted) |
84
-
85
- **Example:**
86
-
87
- ```json
88
- {
89
- "query": "send email notification",
90
- "limit": 10
91
- }
92
- ```
93
-
94
- ### `execute_tool`
95
-
96
- Execute a discovered tool with specific parameters.
97
-
98
- | Parameter | Type | Required | Description |
99
- |-----------|------|----------|-------------|
100
- | `tool_id` | string | ✓ | Tool ID from search results |
101
- | `search_id` | string | ✓ | Search ID from the search that found this tool |
102
- | `params_to_tool` | string | ✓ | JSON string of parameters to pass to the tool |
103
- | `session_id` | string | | Session identifier (auto-generated if omitted) |
104
- | `max_response_size` | number | | Max response size in bytes (default: 20480) |
105
-
106
- **Example:**
107
-
108
- ```json
109
- {
110
- "tool_id": "openweathermap.weather.execute.v1",
111
- "search_id": "abcd1234-ab12-ab12-ab12-abcdef123456",
112
- "params_to_tool": "{\"city\": \"London\", \"units\": \"metric\"}"
113
- }
114
- ```
115
-
116
- ### `get_tools_by_ids`
117
-
118
- Get detailed descriptions of tools based on their tool IDs. Useful for retrieving information about specific tools when you already know their IDs from previous searches.
119
-
120
- | Parameter | Type | Required | Description |
121
- |-----------|------|----------|-------------|
122
- | `tool_ids` | array | ✓ | Array of tool IDs to retrieve (at least one required) |
123
- | `search_id` | string | | Search ID from the search that returned the tool(s) |
124
- | `session_id` | string | | Session identifier (auto-generated if omitted) |
125
-
126
- **Example:**
127
-
128
- ```json
129
- {
130
- "tool_ids": ["openweathermap.weather.execute.v1", "worldbank_refined.search_indicators.v1"],
131
- "search_id": "abcd1234-ab12-ab12-ab12-abcdef123456"
132
- }
133
- ```
134
-
135
- ## Session Management
136
-
137
- Providing a consistent `session_id` in a same user session in any tool call enables:
138
- - Consistent user tracking across multiple tool calls
139
- - Better analytics and usage patterns
140
- - Improved tool recommendations over time
141
-
142
- If not provided, the SDK automatically generates and maintains a session ID for the lifetime of the server process. However, this result in a much larger granularity of user sessions.
143
-
144
- ## Response Handling
145
-
146
- ### Successful Execution
147
-
148
- ```json
149
- {
150
- "execution_id": "abcd1234-ab12-ab12-ab12-abcdef123456",
151
- "tool_id": "openweathermap.weather.execute.v1",
152
- "success": true,
153
- "result": {
154
- "data": {
155
- "temperature": 15.5,
156
- "humidity": 72,
157
- "description": "partly cloudy"
158
- }
159
- },
160
- "execution_time": 0.847
161
- }
162
- ```
163
-
164
- ### Large Responses
165
-
166
- When tool output exceeds `max_response_size`, you'll receive:
167
-
168
- ```json
169
- {
170
- "result": {
171
- "message": "Result content is too long...",
172
- "truncated_content": "[[1678233600000, \"22198.56...",
173
- "full_content_file_url": "https://..."
174
- }
175
- }
176
- ```
177
-
178
- The `full_content_file_url` is valid for 120 minutes.
179
-
180
- ## Environment Variables
181
-
182
- | Variable | Required | Description |
183
- |----------|----------|-------------|
184
- | `QVERIS_API_KEY` | ✓ | Your Qveris API key |
185
-
186
- ## Requirements
187
-
188
- - Node.js 18.0.0 or higher
189
- - A valid Qveris API key
190
-
191
- ## Development
192
-
193
- ```bash
194
- # Clone the repository
195
- git clone https://github.com/qverisai/sdk.git
196
- cd sdk
197
-
198
- # Install dependencies
199
- npm install
200
-
201
- # Build
202
- npm build
203
-
204
- # Run locally
205
- QVERIS_API_KEY=your-key node dist/index.js
206
- ```
207
-
208
- ## License
209
-
210
- MIT © [QverisAI](https://github.com/qverisai)
211
-
212
- ## Support
213
-
214
- - 🐛 [Issue Tracker](https://github.com/qverisai/sdk/issues)
215
- - 💬 Contact: contact@qveris.ai
216
-
1
+ # @qverisai/sdk
2
+
3
+ TypeScript SDK for [QVeris](https://qveris.ai)the Agent External Data & Tool Harness. Discover, inspect and call 1000+ ranked external data & tool capabilities with unified billing and usage audit. No per-provider API keys required.
4
+
5
+ - **Typed end to end** — response types aligned with the public OpenAPI contract (categories, capabilities, `why_recommended`, `expected_cost`, billing)
6
+ - **Zero dependencies** — native `fetch`, Node.js 18+
7
+ - **Same wire semantics** as the [Python SDK](https://pypi.org/project/qveris/) and the [MCP server](https://www.npmjs.com/package/@qverisai/mcp)
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @qverisai/sdk
13
+ ```
14
+
15
+ ## Quickstart
16
+
17
+ ```typescript
18
+ import { Qveris } from '@qverisai/sdk';
19
+
20
+ const qveris = new Qveris({ apiKey: process.env.QVERIS_API_KEY! });
21
+ // or: const qveris = Qveris.fromEnv();
22
+
23
+ // 1. Discover — free, returns ranked capabilities
24
+ const found = await qveris.discover('stock price market data API', { limit: 5 });
25
+ for (const tool of found.results) {
26
+ console.log(tool.tool_id, '—', tool.why_recommended);
27
+ }
28
+
29
+ // 2. Inspect — free, current parameter schemas
30
+ const detail = await qveris.inspect(found.results[0].tool_id, {
31
+ searchId: found.search_id,
32
+ });
33
+
34
+ // 3. Call — billed in credits; response includes pre-settlement billing
35
+ const outcome = await qveris.call(found.results[0].tool_id, {
36
+ searchId: found.search_id,
37
+ parameters: { symbol: 'AAPL' },
38
+ });
39
+ console.log(outcome.success, outcome.result);
40
+ ```
41
+
42
+ ## Audit
43
+
44
+ ```typescript
45
+ // Final charge status for an execution
46
+ const usage = await qveris.usage({ execution_id: outcome.execution_id });
47
+
48
+ // Credit balance movements
49
+ const ledger = await qveris.ledger({ direction: 'consume', summary: true });
50
+
51
+ // Current balance
52
+ const credits = await qveris.credits();
53
+ ```
54
+
55
+ ## Configuration
56
+
57
+ | Option / env var | Description |
58
+ | --- | --- |
59
+ | `apiKey` / `QVERIS_API_KEY` | Required. Create one at [qveris.ai](https://qveris.ai/account?page=api-keys) (global) or [qveris.cn](https://qveris.cn/account?page=api-keys) (China) |
60
+ | `baseUrl` / `QVERIS_BASE_URL` | Override API base URL (highest priority) |
61
+ | `QVERIS_REGION` | Force region: `global` or `cn`. Otherwise auto-detected from the key prefix (`sk-cn-…` → China) |
62
+ | `timeoutMs` | Default request timeout (30s; `call` defaults to 120s) |
63
+
64
+ ## Errors
65
+
66
+ All failures throw `QverisApiError` (an `Error` subclass) with `status`, `details`, and an `observability` object (operation, endpoint, request id) for diagnostics:
67
+
68
+ ```typescript
69
+ import { QverisApiError } from '@qverisai/sdk';
70
+
71
+ try {
72
+ await qveris.call('some.tool.v1', { parameters: {} });
73
+ } catch (err) {
74
+ if (err instanceof QverisApiError && err.status === 402) {
75
+ // insufficient credits — err.message includes the purchase link
76
+ }
77
+ }
78
+ ```
79
+
80
+ ## Version history note
81
+
82
+ Versions `0.1.x` of this npm package were an early MCP-focused SDK, since superseded by [`@qverisai/mcp`](https://www.npmjs.com/package/@qverisai/mcp). The typed REST client documented here starts at **`0.2.0`**.
83
+
84
+ ## Related
85
+
86
+ - [QVeris CLI](https://www.npmjs.com/package/@qverisai/cli) — `qveris discover / inspect / call / usage / ledger`
87
+ - [QVeris MCP server](https://www.npmjs.com/package/@qverisai/mcp) — for Claude, Cursor and other MCP clients
88
+ - [Python SDK](https://pypi.org/project/qveris/)
89
+ - [REST API docs](https://github.com/QVerisAI/qveris-agent-toolkit/blob/main/docs/en-US/rest-api.md)
90
+
91
+ ## License
92
+
93
+ MIT
@@ -0,0 +1,106 @@
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 type { ApiError, CreditsLedgerRequest, CreditsLedgerResponse, CreditsResponse, ExecuteResponse, QverisClientConfig, SearchResponse, UsageEventsResponse, UsageHistoryRequest } from './types.js';
14
+ /** Options for {@link Qveris.discover}. */
15
+ export interface DiscoverOptions {
16
+ /** Maximum number of results (1-100, server default 20) */
17
+ limit?: number;
18
+ /** Session identifier for tracking */
19
+ sessionId?: string;
20
+ /** Per-request timeout override in milliseconds */
21
+ timeoutMs?: number;
22
+ }
23
+ /** Options for {@link Qveris.inspect}. */
24
+ export interface InspectOptions {
25
+ /** The search_id from the discover call that returned the tool(s) */
26
+ searchId?: string;
27
+ /** Session identifier for tracking */
28
+ sessionId?: string;
29
+ /** Per-request timeout override in milliseconds */
30
+ timeoutMs?: number;
31
+ }
32
+ /** Options for {@link Qveris.call}. */
33
+ export interface CallOptions {
34
+ /** Key-value parameters matching the tool's parameter schema */
35
+ parameters: Record<string, unknown>;
36
+ /** The search_id from the discover call that returned this tool */
37
+ searchId?: string;
38
+ /** Session identifier for tracking */
39
+ sessionId?: string;
40
+ /** Max response bytes before truncation (-1 for no limit, server default 20480) */
41
+ maxResponseSize?: number;
42
+ /** Per-request timeout override in milliseconds (default 120s) */
43
+ timeoutMs?: number;
44
+ }
45
+ /**
46
+ * QVeris API client.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * import { Qveris } from '@qverisai/sdk';
51
+ *
52
+ * const qveris = new Qveris({ apiKey: process.env.QVERIS_API_KEY! });
53
+ *
54
+ * const found = await qveris.discover('stock price market data API', { limit: 5 });
55
+ * const tool = found.results[0];
56
+ *
57
+ * const outcome = await qveris.call(tool.tool_id, {
58
+ * searchId: found.search_id,
59
+ * parameters: { symbol: 'AAPL' },
60
+ * });
61
+ * ```
62
+ */
63
+ export declare class Qveris {
64
+ private readonly apiKey;
65
+ private readonly baseUrl;
66
+ private readonly defaultTimeoutMs;
67
+ constructor(config: QverisClientConfig);
68
+ /**
69
+ * Create a client from the QVERIS_API_KEY environment variable.
70
+ * Region is auto-detected from the key prefix (sk-cn-xxx -> cn), or
71
+ * overridden via QVERIS_REGION / QVERIS_BASE_URL.
72
+ */
73
+ static fromEnv(overrides?: Omit<QverisClientConfig, 'apiKey'>): Qveris;
74
+ /**
75
+ * Discover capabilities from a natural-language query. Free.
76
+ */
77
+ discover(query: string, options?: DiscoverOptions): Promise<SearchResponse>;
78
+ /**
79
+ * Inspect capabilities by id to get current parameter schemas. Free.
80
+ * An empty id list resolves locally without a network request.
81
+ */
82
+ inspect(toolIds: string | string[], options?: InspectOptions): Promise<SearchResponse>;
83
+ /**
84
+ * Call a capability. The response may include pre-settlement billing;
85
+ * final charges are reflected in usage() and ledger().
86
+ */
87
+ call(toolId: string, options: CallOptions): Promise<ExecuteResponse>;
88
+ /** Get current credit balance and bucket details. */
89
+ credits(): Promise<CreditsResponse>;
90
+ /** Query request-level usage audit history. */
91
+ usage(filters?: UsageHistoryRequest): Promise<UsageEventsResponse>;
92
+ /** Query final credits ledger entries. */
93
+ ledger(filters?: CreditsLedgerRequest): Promise<CreditsLedgerResponse>;
94
+ /**
95
+ * Makes an authenticated HTTP request and unwraps success envelopes.
96
+ */
97
+ private request;
98
+ /**
99
+ * Unwrap `{status: "success", data: ...}` envelopes; raw payloads pass
100
+ * through. A failure envelope throws before any result parsing, matching
101
+ * the Python SDK behavior.
102
+ */
103
+ private unwrapEnvelope;
104
+ }
105
+ export type { ApiError };
106
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":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