nuabase 2.3.2 → 2.3.4
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/README.md +44 -30
- package/dist/cjs/index.cjs +227 -213
- package/dist/esm/index.mjs +227 -213
- package/dist/types/backend/direct.d.ts +2 -2
- package/dist/types/backend/types.d.ts +3 -2
- package/dist/types/nua.d.ts +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -146,33 +146,33 @@ Every call returns a discriminated union. When `success` is `false`, you get an
|
|
|
146
146
|
|
|
147
147
|
**Success**
|
|
148
148
|
|
|
149
|
-
| Field | Type
|
|
150
|
-
| ----------- |
|
|
151
|
-
| `success` | `true`
|
|
152
|
-
| `data` | `T` (for `get`) or `Array<{ [pk]: value; [output]: T }>` (for `list`) | The typed result matching your schema.
|
|
153
|
-
| `usage` | `{ promptTokens, completionTokens, totalTokens }`
|
|
154
|
-
| `model` | `string`
|
|
155
|
-
| `latencyMs` | `number`
|
|
156
|
-
| `source` | `'gateway'` \| `'direct'`
|
|
157
|
-
| `meta` | `object`
|
|
149
|
+
| Field | Type | Description |
|
|
150
|
+
| ----------- | --------------------------------------------------------------------- | -------------------------------------------------- |
|
|
151
|
+
| `success` | `true` | Indicates that the request completed successfully. |
|
|
152
|
+
| `data` | `T` (for `get`) or `Array<{ [pk]: value; [output]: T }>` (for `list`) | The typed result matching your schema. |
|
|
153
|
+
| `usage` | `{ promptTokens, completionTokens, totalTokens }` | Token usage statistics for the LLM request. |
|
|
154
|
+
| `model` | `string` | The LLM model used for this request. |
|
|
155
|
+
| `latencyMs` | `number` | Request latency in milliseconds. |
|
|
156
|
+
| `source` | `'gateway'` \| `'direct'` | Which backend processed the request. |
|
|
157
|
+
| `meta` | `object` | Additional metadata (varies by source). |
|
|
158
158
|
|
|
159
159
|
**Gateway-specific metadata** (`meta` when `source` is `'gateway'`):
|
|
160
160
|
|
|
161
|
-
| Field | Type | Description
|
|
162
|
-
| ------------ | --------- |
|
|
163
|
-
| `requestId` | `string` | Unique identifier for tracing.
|
|
164
|
-
| `cached` | `boolean` | Whether the result was served from cache.
|
|
165
|
-
| `llmUsage` | `object` | Token usage from LLM calls.
|
|
166
|
-
| `cacheUsage` | `object` | Token usage served from cache.
|
|
161
|
+
| Field | Type | Description |
|
|
162
|
+
| ------------ | --------- | ----------------------------------------- |
|
|
163
|
+
| `requestId` | `string` | Unique identifier for tracing. |
|
|
164
|
+
| `cached` | `boolean` | Whether the result was served from cache. |
|
|
165
|
+
| `llmUsage` | `object` | Token usage from LLM calls. |
|
|
166
|
+
| `cacheUsage` | `object` | Token usage served from cache. |
|
|
167
167
|
|
|
168
168
|
**Error**
|
|
169
169
|
|
|
170
|
-
| Field | Type
|
|
171
|
-
| ----------- |
|
|
172
|
-
| `success` | `false`
|
|
173
|
-
| `error` | `string`
|
|
174
|
-
| `source` | `'gateway'` \| `'direct'`
|
|
175
|
-
| `latencyMs` | `number`
|
|
170
|
+
| Field | Type | Description |
|
|
171
|
+
| ----------- | ------------------------- | ----------------------------------- |
|
|
172
|
+
| `success` | `false` | Indicates the request failed. |
|
|
173
|
+
| `error` | `string` | Message describing the error. |
|
|
174
|
+
| `source` | `'gateway'` \| `'direct'` | Which backend returned the error. |
|
|
175
|
+
| `latencyMs` | `number` | Time until failure in milliseconds. |
|
|
176
176
|
|
|
177
177
|
## SDK API
|
|
178
178
|
|
|
@@ -187,8 +187,22 @@ Creates a client that connects to the Nuabase API gateway. Use this for producti
|
|
|
187
187
|
**`Nua.direct(config)`**
|
|
188
188
|
Creates a client that calls LLM providers directly (in-process). Use this for serverless, edge functions, or CLI tools where you don't need the gateway infrastructure.
|
|
189
189
|
|
|
190
|
-
- `model
|
|
191
|
-
- `providers: {
|
|
190
|
+
- `model?: ModelInput` – Optional default model. Omit it to use `{ alias: 'fast' }`.
|
|
191
|
+
- `providers: { groq?: { apiKey: string }, cerebras?: { apiKey: string }, gemini?: { apiKey: string }, openrouter?: { apiKey: string } }` – Provider credentials.
|
|
192
|
+
|
|
193
|
+
Model inputs are objects, not provider-prefixed strings:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
await nua.get('Extract the company name', {
|
|
197
|
+
output: { name: 'companyName', schema: z.string() },
|
|
198
|
+
model: { provider: 'openrouter', model: 'z-ai/glm-5.2' },
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
await nua.get('Extract the company name', {
|
|
202
|
+
output: { name: 'companyName', schema: z.string() },
|
|
203
|
+
model: { alias: 'fast' },
|
|
204
|
+
});
|
|
205
|
+
```
|
|
192
206
|
|
|
193
207
|
### Methods
|
|
194
208
|
|
|
@@ -196,7 +210,7 @@ Creates a client that calls LLM providers directly (in-process). Use this for se
|
|
|
196
210
|
Returns a simple string response from the LLM.
|
|
197
211
|
|
|
198
212
|
```ts
|
|
199
|
-
const result = await nua.get(
|
|
213
|
+
const result = await nua.get('Tell me a joke');
|
|
200
214
|
if (result.success) console.log(result.data); // string
|
|
201
215
|
```
|
|
202
216
|
|
|
@@ -208,8 +222,8 @@ Returns a typed single value. Parameters:
|
|
|
208
222
|
- `options.output: { name: string; schema: ZodSchema }` – Output name and Zod schema.
|
|
209
223
|
|
|
210
224
|
```ts
|
|
211
|
-
const result = await nua.get(
|
|
212
|
-
input:
|
|
225
|
+
const result = await nua.get('Extract the address', {
|
|
226
|
+
input: '123 Main St, Springfield, IL 62701',
|
|
213
227
|
output: { name: 'address', schema: AddressSchema },
|
|
214
228
|
});
|
|
215
229
|
if (result.success) console.log(result.data); // typed as z.infer<typeof AddressSchema>
|
|
@@ -224,20 +238,20 @@ Processes an array of items. Parameters:
|
|
|
224
238
|
- `options.output: { name: string; schema: ZodSchema }` – Output configuration.
|
|
225
239
|
|
|
226
240
|
```ts
|
|
227
|
-
const result = await nua.list(
|
|
241
|
+
const result = await nua.list('Classify each lead', {
|
|
228
242
|
input: leads,
|
|
229
243
|
primaryKey: 'id',
|
|
230
244
|
output: { name: 'classification', schema: ClassificationSchema },
|
|
231
245
|
});
|
|
232
246
|
if (result.success) {
|
|
233
|
-
result.data.forEach(row => console.log(row.id, row.classification));
|
|
247
|
+
result.data.forEach((row) => console.log(row.id, row.classification));
|
|
234
248
|
}
|
|
235
249
|
```
|
|
236
250
|
|
|
237
|
-
**`nua.queueGet(prompt, options?)`**
|
|
251
|
+
**`nua.queueGet(prompt, options?)`** _(Gateway mode only)_
|
|
238
252
|
Submits an async job for single-value operations. Returns `{ success: true, jobId }`.
|
|
239
253
|
|
|
240
|
-
**`nua.queueList(prompt, options)`**
|
|
254
|
+
**`nua.queueList(prompt, options)`** _(Gateway mode only)_
|
|
241
255
|
Submits an async job for array operations. Returns `{ success: true, jobId }`.
|
|
242
256
|
|
|
243
257
|
## Next Steps
|