@qverisai/sdk 0.1.1 → 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,206 +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 just two simple tools, your AI assistant can:
11
-
12
- - **Search** for tools using natural language queries
13
- - **Execute** any discovered tool with the appropriate parameters
14
-
15
- ## Installation
16
-
17
- ```bash
18
- # Using npx (recommended for MCP)
19
- npx @qverisai/sdk
20
-
21
- # Or install globally
22
- npm add -g @qverisai/sdk
23
- ```
24
-
25
- ## Quick Start
26
-
27
- ### 1. Get Your API Key
28
-
29
- Visit [Qveris](https://qveris.ai) to get your API key.
30
-
31
- ### 2. Configure Your MCP Client
32
-
33
- Add the Qveris server to your MCP client configuration:
34
-
35
- **Claude Desktop** (`claude_desktop_config.json`):
36
-
37
- ```json
38
- {
39
- "mcpServers": {
40
- "qveris": {
41
- "command": "npx",
42
- "args": ["@qverisai/sdk"],
43
- "env": {
44
- "QVERIS_API_KEY": "your-api-key-here"
45
- }
46
- }
47
- }
48
- }
49
- ```
50
-
51
- **Cursor** (Settings → MCP Servers):
52
-
53
- ```json
54
- {
55
- "mcpServers": {
56
- "qveris": {
57
- "command": "npx",
58
- "args": ["@qverisai/sdk"],
59
- "env": {
60
- "QVERIS_API_KEY": "your-api-key-here"
61
- }
62
- }
63
- }
64
- }
65
- ```
66
-
67
- ### 3. Start Using
68
-
69
- Once configured, You could add this to system prompt:
70
-
71
- > "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."
72
-
73
- Then your AI assistant can search for and execute tools:
74
-
75
- > "Find me a weather tool and get the current weather in Tokyo"
76
-
77
- The assistant will:
78
- 1. Call `search_tools` with query "weather"
79
- 2. Review the results and select an appropriate tool
80
- 3. Call `execute_tool` with the tool_id and parameters
81
-
82
- ## Available Tools
83
-
84
- ### `search_tools`
85
-
86
- Search for available tools based on natural language queries.
87
-
88
- | Parameter | Type | Required | Description |
89
- |-----------|------|----------|-------------|
90
- | `query` | string | ✓ | Natural language description of the capability you need |
91
- | `limit` | number | | Max results to return (1-100, default: 20) |
92
- | `session_id` | string | | Session identifier for tracking (auto-generated if omitted) |
93
-
94
- **Example:**
95
-
96
- ```json
97
- {
98
- "query": "send email notification",
99
- "limit": 5
100
- }
101
- ```
102
-
103
- ### `execute_tool`
104
-
105
- Execute a discovered tool with specific parameters.
106
-
107
- | Parameter | Type | Required | Description |
108
- |-----------|------|----------|-------------|
109
- | `tool_id` | string | ✓ | Tool ID from search results |
110
- | `search_id` | string | ✓ | Search ID from the search that found this tool |
111
- | `params_to_tool` | string | ✓ | JSON string of parameters to pass to the tool |
112
- | `session_id` | string | | Session identifier (auto-generated if omitted) |
113
- | `max_response_size` | number | | Max response size in bytes (default: 20480) |
114
-
115
- **Example:**
116
-
117
- ```json
118
- {
119
- "tool_id": "openweathermap_current_weather",
120
- "search_id": "abc123",
121
- "params_to_tool": "{\"city\": \"London\", \"units\": \"metric\"}"
122
- }
123
- ```
124
-
125
- ## Session Management
126
-
127
- Providing a consistent `session_id` in a same user session in any tool call enables:
128
- - Consistent user tracking across multiple tool calls
129
- - Better analytics and usage patterns
130
- - Improved tool recommendations over time
131
-
132
- 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.
133
-
134
- ## Response Handling
135
-
136
- ### Successful Execution
137
-
138
- ```json
139
- {
140
- "execution_id": "exec-123",
141
- "tool_id": "openweathermap_current_weather",
142
- "success": true,
143
- "result": {
144
- "data": {
145
- "temperature": 15.5,
146
- "humidity": 72,
147
- "description": "partly cloudy"
148
- }
149
- },
150
- "execution_time": 0.847
151
- }
152
- ```
153
-
154
- ### Large Responses
155
-
156
- When tool output exceeds `max_response_size`, you'll receive:
157
-
158
- ```json
159
- {
160
- "result": {
161
- "message": "Result content is too long...",
162
- "truncated_content": "[[1678233600000, \"22198.56...",
163
- "full_content_file_url": "https://..."
164
- }
165
- }
166
- ```
167
-
168
- The `full_content_file_url` is valid for 120 minutes.
169
-
170
- ## Environment Variables
171
-
172
- | Variable | Required | Description |
173
- |----------|----------|-------------|
174
- | `QVERIS_API_KEY` | ✓ | Your Qveris API key |
175
-
176
- ## Requirements
177
-
178
- - Node.js 18.0.0 or higher
179
- - A valid Qveris API key
180
-
181
- ## Development
182
-
183
- ```bash
184
- # Clone the repository
185
- git clone https://github.com/qverisai/sdk.git
186
- cd sdk
187
-
188
- # Install dependencies
189
- npm install
190
-
191
- # Build
192
- npm build
193
-
194
- # Run locally
195
- QVERIS_API_KEY=your-key node dist/index.js
196
- ```
197
-
198
- ## License
199
-
200
- MIT © [QverisAI](https://github.com/qverisai)
201
-
202
- ## Support
203
-
204
- - 🐛 [Issue Tracker](https://github.com/qverisai/sdk/issues)
205
- - 💬 Contact: contact@qveris.ai
206
-
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":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAEV,QAAQ,EAGR,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAoCpB,2CAA2C;AAC3C,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;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