nuabase 1.0.1 → 1.1.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/dist/cjs/index.cjs +131 -10
- package/dist/esm/index.mjs +131 -10
- package/dist/types/lib/api-client.d.ts +1 -1
- package/dist/types/lib/env.d.ts +1 -0
- package/dist/types/nua/cast_array/response-schema.d.ts +1 -1
- package/dist/types/nua/cast_array/types.d.ts +16 -1
- package/dist/types/nua/core.d.ts +2 -0
- package/dist/types/nua/get-request/index.d.ts +6 -0
- package/dist/types/nua/get-request/types.d.ts +34 -0
- package/dist/types/nua/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
|
|
5
|
+
function resolveConfigValue(config, key, envVar) {
|
|
6
|
+
if (config[key]) return config[key];
|
|
7
|
+
const pe = globalThis.process;
|
|
8
|
+
const isNode = !!pe?.versions?.node;
|
|
9
|
+
if (isNode) {
|
|
10
|
+
return pe?.env?.[envVar];
|
|
11
|
+
}
|
|
12
|
+
return void 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
5
15
|
async function parseErrorResponse(response, urlPath) {
|
|
6
16
|
const fallbackMessage = `Request to ${urlPath} failed with status ${response.status}${response.statusText ? ` ${response.statusText}` : ""}`;
|
|
7
17
|
let responseBody = "";
|
|
@@ -47,25 +57,29 @@ function getErrorMessageFromException(error) {
|
|
|
47
57
|
|
|
48
58
|
class NuabaseAPIClient {
|
|
49
59
|
constructor(config = {}) {
|
|
50
|
-
this.apiKey = config
|
|
51
|
-
this.baseUrl = config
|
|
60
|
+
this.apiKey = resolveConfigValue(config, "apiKey", "NUABASE_API_KEY") || "";
|
|
61
|
+
this.baseUrl = resolveConfigValue(config, "baseUrl", "NUABASE_API_URL") || "https://api.nuabase.com";
|
|
52
62
|
if (!this.apiKey) {
|
|
53
63
|
throw new Error(
|
|
54
64
|
"API key is required. Provide it via config.apiKey or NUABASE_API_KEY environment variable."
|
|
55
65
|
);
|
|
56
66
|
}
|
|
57
67
|
}
|
|
58
|
-
async request(urlPath, params) {
|
|
68
|
+
async request(method, urlPath, params) {
|
|
59
69
|
const url = `${this.baseUrl}/${urlPath}`;
|
|
60
70
|
let response;
|
|
71
|
+
const hasBody = method !== "GET" && params !== void 0;
|
|
72
|
+
const headers = {
|
|
73
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
74
|
+
};
|
|
75
|
+
if (hasBody) {
|
|
76
|
+
headers["Content-Type"] = "application/json";
|
|
77
|
+
}
|
|
61
78
|
try {
|
|
62
79
|
response = await fetch(url, {
|
|
63
|
-
method
|
|
64
|
-
headers
|
|
65
|
-
|
|
66
|
-
Authorization: `Bearer ${this.apiKey}`
|
|
67
|
-
},
|
|
68
|
-
body: JSON.stringify(params)
|
|
80
|
+
method,
|
|
81
|
+
headers,
|
|
82
|
+
body: hasBody ? JSON.stringify(params) : void 0
|
|
69
83
|
});
|
|
70
84
|
} catch (e) {
|
|
71
85
|
return { error: `Error calling Nuabase API: ${getErrorMessageFromException(e)}` };
|
|
@@ -151,6 +165,25 @@ const validateArrayFnDef = (fnDef) => {
|
|
|
151
165
|
return parsed.data;
|
|
152
166
|
};
|
|
153
167
|
|
|
168
|
+
function addOriginalInputRows(inputRows, outputRows, primaryKeyName) {
|
|
169
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
170
|
+
for (const row of inputRows) {
|
|
171
|
+
lookup.set(row[primaryKeyName], row);
|
|
172
|
+
}
|
|
173
|
+
return outputRows.map((row) => {
|
|
174
|
+
const primaryKeyValue = row[primaryKeyName];
|
|
175
|
+
const sourceRow = lookup.get(primaryKeyValue);
|
|
176
|
+
if (!sourceRow) {
|
|
177
|
+
throw new Error(
|
|
178
|
+
`Unable to locate source row for primary key "${String(primaryKeyValue)}" in cast array response.`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
...row,
|
|
183
|
+
sourceRow
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
}
|
|
154
187
|
const toCastArrayApiRequest = (prompt, data, primaryKeyName, outputName, outputSchema) => ({
|
|
155
188
|
input: {
|
|
156
189
|
prompt,
|
|
@@ -173,6 +206,7 @@ const createArrayFn = (client, inputFnDef) => {
|
|
|
173
206
|
const baseFn = async (data, primaryKeyName) => {
|
|
174
207
|
validateArrayRequestParams(data, primaryKeyName);
|
|
175
208
|
const response = await client.request(
|
|
209
|
+
"POST",
|
|
176
210
|
"cast/array",
|
|
177
211
|
toCastArrayApiRequest(
|
|
178
212
|
fnDef.prompt,
|
|
@@ -194,6 +228,7 @@ const createArrayFn = (client, inputFnDef) => {
|
|
|
194
228
|
const nowFn = async (data, primaryKeyName) => {
|
|
195
229
|
validateArrayRequestParams(data, primaryKeyName);
|
|
196
230
|
const response = await client.request(
|
|
231
|
+
"POST",
|
|
197
232
|
"cast/array/now",
|
|
198
233
|
toCastArrayApiRequest(
|
|
199
234
|
fnDef.prompt,
|
|
@@ -216,7 +251,11 @@ const createArrayFn = (client, inputFnDef) => {
|
|
|
216
251
|
isSuccess: true,
|
|
217
252
|
llmRequestId: parsedResponse.data.llmRequestId,
|
|
218
253
|
kind: parsedResponse.data.kind,
|
|
219
|
-
data:
|
|
254
|
+
data: addOriginalInputRows(
|
|
255
|
+
data,
|
|
256
|
+
parsedResponse.data.data,
|
|
257
|
+
primaryKeyName
|
|
258
|
+
),
|
|
220
259
|
rowsWithNoResults: parsedResponse.data.rowsWithNoResults,
|
|
221
260
|
cacheHits: parsedResponse.data.cacheHits
|
|
222
261
|
};
|
|
@@ -276,6 +315,7 @@ const createValueFn = (client, inputFnDef) => {
|
|
|
276
315
|
return void 0;
|
|
277
316
|
};
|
|
278
317
|
const sendRequest = async (path, data) => client.request(
|
|
318
|
+
"POST",
|
|
279
319
|
path,
|
|
280
320
|
toCastValueApiRequest(fnDef.prompt, data, fnDef.output.name, outputJsonSchema)
|
|
281
321
|
);
|
|
@@ -317,6 +357,84 @@ const createValueFn = (client, inputFnDef) => {
|
|
|
317
357
|
});
|
|
318
358
|
};
|
|
319
359
|
|
|
360
|
+
const errorParseFailed = {
|
|
361
|
+
kind: "internal-error",
|
|
362
|
+
message: "Unable to parse stored LLM result"
|
|
363
|
+
};
|
|
364
|
+
const dateFromIso = zod.z.preprocess(
|
|
365
|
+
(value) => {
|
|
366
|
+
if (value == null) return null;
|
|
367
|
+
if (value instanceof Date) return value;
|
|
368
|
+
if (typeof value === "string") {
|
|
369
|
+
const parsed = new Date(value);
|
|
370
|
+
if (!Number.isNaN(parsed.getTime())) return parsed;
|
|
371
|
+
}
|
|
372
|
+
return zod.z.NEVER;
|
|
373
|
+
},
|
|
374
|
+
zod.z.union([zod.z.date(), zod.z.null()])
|
|
375
|
+
);
|
|
376
|
+
const mandatoryDateFromIso = zod.z.preprocess((value) => {
|
|
377
|
+
if (value instanceof Date) return value;
|
|
378
|
+
if (typeof value === "string") {
|
|
379
|
+
const parsed = new Date(value);
|
|
380
|
+
if (!Number.isNaN(parsed.getTime())) return parsed;
|
|
381
|
+
}
|
|
382
|
+
return zod.z.NEVER;
|
|
383
|
+
}, zod.z.date());
|
|
384
|
+
const apiResponseSchema = zod.z.object({
|
|
385
|
+
id: zod.z.string(),
|
|
386
|
+
requestType: zod.z.string(),
|
|
387
|
+
llmStatus: zod.z.union([
|
|
388
|
+
zod.z.literal("pending"),
|
|
389
|
+
zod.z.literal("processing"),
|
|
390
|
+
zod.z.literal("success"),
|
|
391
|
+
zod.z.literal("failed")
|
|
392
|
+
]),
|
|
393
|
+
sseStatus: zod.z.union([
|
|
394
|
+
zod.z.literal("n/a"),
|
|
395
|
+
zod.z.literal("pending"),
|
|
396
|
+
zod.z.literal("sent"),
|
|
397
|
+
zod.z.literal("failed")
|
|
398
|
+
]),
|
|
399
|
+
webhookStatus: zod.z.union([
|
|
400
|
+
zod.z.literal("n/a"),
|
|
401
|
+
zod.z.literal("pending"),
|
|
402
|
+
zod.z.literal("sent"),
|
|
403
|
+
zod.z.literal("failed")
|
|
404
|
+
]),
|
|
405
|
+
input: zod.z.object({
|
|
406
|
+
prompt: zod.z.union([zod.z.string(), zod.z.null()]),
|
|
407
|
+
data: zod.z.union([zod.z.string(), zod.z.null()]),
|
|
408
|
+
primaryKey: zod.z.union([zod.z.string(), zod.z.null()])
|
|
409
|
+
}),
|
|
410
|
+
output: zod.z.object({
|
|
411
|
+
name: zod.z.string(),
|
|
412
|
+
schema: zod.z.string(),
|
|
413
|
+
effectiveSchema: zod.z.string()
|
|
414
|
+
}),
|
|
415
|
+
result: zod.z.union([zod.z.record(zod.z.string(), zod.z.unknown()), zod.z.null()]).optional(),
|
|
416
|
+
error: zod.z.union([zod.z.string(), zod.z.null()]),
|
|
417
|
+
fullPrompt: zod.z.string(),
|
|
418
|
+
model: zod.z.string(),
|
|
419
|
+
provider: zod.z.string(),
|
|
420
|
+
startedAt: dateFromIso,
|
|
421
|
+
finishedAt: dateFromIso,
|
|
422
|
+
createdAt: mandatoryDateFromIso,
|
|
423
|
+
updatedAt: mandatoryDateFromIso
|
|
424
|
+
});
|
|
425
|
+
const isNuabaseError = (value) => Boolean(value && typeof value === "object" && "isError" in value && value.isError);
|
|
426
|
+
async function getRequest(client, llmRequestId) {
|
|
427
|
+
const response = await client.request("GET", `requests/${encodeURIComponent(llmRequestId)}`);
|
|
428
|
+
if (isNuabaseError(response)) {
|
|
429
|
+
return response;
|
|
430
|
+
}
|
|
431
|
+
const parsedResponse = apiResponseSchema.safeParse(response);
|
|
432
|
+
if (!parsedResponse.success) {
|
|
433
|
+
return errorParseFailed;
|
|
434
|
+
}
|
|
435
|
+
return parsedResponse.data;
|
|
436
|
+
}
|
|
437
|
+
|
|
320
438
|
class Nua {
|
|
321
439
|
constructor(config) {
|
|
322
440
|
this.apiClient = new NuabaseAPIClient(config);
|
|
@@ -327,6 +445,9 @@ class Nua {
|
|
|
327
445
|
createFn(fnDef) {
|
|
328
446
|
return createValueFn(this.apiClient, fnDef);
|
|
329
447
|
}
|
|
448
|
+
async getRequest(llmRequestId) {
|
|
449
|
+
return getRequest(this.apiClient, llmRequestId);
|
|
450
|
+
}
|
|
330
451
|
}
|
|
331
452
|
|
|
332
453
|
exports.Nua = Nua;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
function resolveConfigValue(config, key, envVar) {
|
|
4
|
+
if (config[key]) return config[key];
|
|
5
|
+
const pe = globalThis.process;
|
|
6
|
+
const isNode = !!pe?.versions?.node;
|
|
7
|
+
if (isNode) {
|
|
8
|
+
return pe?.env?.[envVar];
|
|
9
|
+
}
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
3
13
|
async function parseErrorResponse(response, urlPath) {
|
|
4
14
|
const fallbackMessage = `Request to ${urlPath} failed with status ${response.status}${response.statusText ? ` ${response.statusText}` : ""}`;
|
|
5
15
|
let responseBody = "";
|
|
@@ -45,25 +55,29 @@ function getErrorMessageFromException(error) {
|
|
|
45
55
|
|
|
46
56
|
class NuabaseAPIClient {
|
|
47
57
|
constructor(config = {}) {
|
|
48
|
-
this.apiKey = config
|
|
49
|
-
this.baseUrl = config
|
|
58
|
+
this.apiKey = resolveConfigValue(config, "apiKey", "NUABASE_API_KEY") || "";
|
|
59
|
+
this.baseUrl = resolveConfigValue(config, "baseUrl", "NUABASE_API_URL") || "https://api.nuabase.com";
|
|
50
60
|
if (!this.apiKey) {
|
|
51
61
|
throw new Error(
|
|
52
62
|
"API key is required. Provide it via config.apiKey or NUABASE_API_KEY environment variable."
|
|
53
63
|
);
|
|
54
64
|
}
|
|
55
65
|
}
|
|
56
|
-
async request(urlPath, params) {
|
|
66
|
+
async request(method, urlPath, params) {
|
|
57
67
|
const url = `${this.baseUrl}/${urlPath}`;
|
|
58
68
|
let response;
|
|
69
|
+
const hasBody = method !== "GET" && params !== void 0;
|
|
70
|
+
const headers = {
|
|
71
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
72
|
+
};
|
|
73
|
+
if (hasBody) {
|
|
74
|
+
headers["Content-Type"] = "application/json";
|
|
75
|
+
}
|
|
59
76
|
try {
|
|
60
77
|
response = await fetch(url, {
|
|
61
|
-
method
|
|
62
|
-
headers
|
|
63
|
-
|
|
64
|
-
Authorization: `Bearer ${this.apiKey}`
|
|
65
|
-
},
|
|
66
|
-
body: JSON.stringify(params)
|
|
78
|
+
method,
|
|
79
|
+
headers,
|
|
80
|
+
body: hasBody ? JSON.stringify(params) : void 0
|
|
67
81
|
});
|
|
68
82
|
} catch (e) {
|
|
69
83
|
return { error: `Error calling Nuabase API: ${getErrorMessageFromException(e)}` };
|
|
@@ -149,6 +163,25 @@ const validateArrayFnDef = (fnDef) => {
|
|
|
149
163
|
return parsed.data;
|
|
150
164
|
};
|
|
151
165
|
|
|
166
|
+
function addOriginalInputRows(inputRows, outputRows, primaryKeyName) {
|
|
167
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
168
|
+
for (const row of inputRows) {
|
|
169
|
+
lookup.set(row[primaryKeyName], row);
|
|
170
|
+
}
|
|
171
|
+
return outputRows.map((row) => {
|
|
172
|
+
const primaryKeyValue = row[primaryKeyName];
|
|
173
|
+
const sourceRow = lookup.get(primaryKeyValue);
|
|
174
|
+
if (!sourceRow) {
|
|
175
|
+
throw new Error(
|
|
176
|
+
`Unable to locate source row for primary key "${String(primaryKeyValue)}" in cast array response.`
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
...row,
|
|
181
|
+
sourceRow
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
}
|
|
152
185
|
const toCastArrayApiRequest = (prompt, data, primaryKeyName, outputName, outputSchema) => ({
|
|
153
186
|
input: {
|
|
154
187
|
prompt,
|
|
@@ -171,6 +204,7 @@ const createArrayFn = (client, inputFnDef) => {
|
|
|
171
204
|
const baseFn = async (data, primaryKeyName) => {
|
|
172
205
|
validateArrayRequestParams(data, primaryKeyName);
|
|
173
206
|
const response = await client.request(
|
|
207
|
+
"POST",
|
|
174
208
|
"cast/array",
|
|
175
209
|
toCastArrayApiRequest(
|
|
176
210
|
fnDef.prompt,
|
|
@@ -192,6 +226,7 @@ const createArrayFn = (client, inputFnDef) => {
|
|
|
192
226
|
const nowFn = async (data, primaryKeyName) => {
|
|
193
227
|
validateArrayRequestParams(data, primaryKeyName);
|
|
194
228
|
const response = await client.request(
|
|
229
|
+
"POST",
|
|
195
230
|
"cast/array/now",
|
|
196
231
|
toCastArrayApiRequest(
|
|
197
232
|
fnDef.prompt,
|
|
@@ -214,7 +249,11 @@ const createArrayFn = (client, inputFnDef) => {
|
|
|
214
249
|
isSuccess: true,
|
|
215
250
|
llmRequestId: parsedResponse.data.llmRequestId,
|
|
216
251
|
kind: parsedResponse.data.kind,
|
|
217
|
-
data:
|
|
252
|
+
data: addOriginalInputRows(
|
|
253
|
+
data,
|
|
254
|
+
parsedResponse.data.data,
|
|
255
|
+
primaryKeyName
|
|
256
|
+
),
|
|
218
257
|
rowsWithNoResults: parsedResponse.data.rowsWithNoResults,
|
|
219
258
|
cacheHits: parsedResponse.data.cacheHits
|
|
220
259
|
};
|
|
@@ -274,6 +313,7 @@ const createValueFn = (client, inputFnDef) => {
|
|
|
274
313
|
return void 0;
|
|
275
314
|
};
|
|
276
315
|
const sendRequest = async (path, data) => client.request(
|
|
316
|
+
"POST",
|
|
277
317
|
path,
|
|
278
318
|
toCastValueApiRequest(fnDef.prompt, data, fnDef.output.name, outputJsonSchema)
|
|
279
319
|
);
|
|
@@ -315,6 +355,84 @@ const createValueFn = (client, inputFnDef) => {
|
|
|
315
355
|
});
|
|
316
356
|
};
|
|
317
357
|
|
|
358
|
+
const errorParseFailed = {
|
|
359
|
+
kind: "internal-error",
|
|
360
|
+
message: "Unable to parse stored LLM result"
|
|
361
|
+
};
|
|
362
|
+
const dateFromIso = z.preprocess(
|
|
363
|
+
(value) => {
|
|
364
|
+
if (value == null) return null;
|
|
365
|
+
if (value instanceof Date) return value;
|
|
366
|
+
if (typeof value === "string") {
|
|
367
|
+
const parsed = new Date(value);
|
|
368
|
+
if (!Number.isNaN(parsed.getTime())) return parsed;
|
|
369
|
+
}
|
|
370
|
+
return z.NEVER;
|
|
371
|
+
},
|
|
372
|
+
z.union([z.date(), z.null()])
|
|
373
|
+
);
|
|
374
|
+
const mandatoryDateFromIso = z.preprocess((value) => {
|
|
375
|
+
if (value instanceof Date) return value;
|
|
376
|
+
if (typeof value === "string") {
|
|
377
|
+
const parsed = new Date(value);
|
|
378
|
+
if (!Number.isNaN(parsed.getTime())) return parsed;
|
|
379
|
+
}
|
|
380
|
+
return z.NEVER;
|
|
381
|
+
}, z.date());
|
|
382
|
+
const apiResponseSchema = z.object({
|
|
383
|
+
id: z.string(),
|
|
384
|
+
requestType: z.string(),
|
|
385
|
+
llmStatus: z.union([
|
|
386
|
+
z.literal("pending"),
|
|
387
|
+
z.literal("processing"),
|
|
388
|
+
z.literal("success"),
|
|
389
|
+
z.literal("failed")
|
|
390
|
+
]),
|
|
391
|
+
sseStatus: z.union([
|
|
392
|
+
z.literal("n/a"),
|
|
393
|
+
z.literal("pending"),
|
|
394
|
+
z.literal("sent"),
|
|
395
|
+
z.literal("failed")
|
|
396
|
+
]),
|
|
397
|
+
webhookStatus: z.union([
|
|
398
|
+
z.literal("n/a"),
|
|
399
|
+
z.literal("pending"),
|
|
400
|
+
z.literal("sent"),
|
|
401
|
+
z.literal("failed")
|
|
402
|
+
]),
|
|
403
|
+
input: z.object({
|
|
404
|
+
prompt: z.union([z.string(), z.null()]),
|
|
405
|
+
data: z.union([z.string(), z.null()]),
|
|
406
|
+
primaryKey: z.union([z.string(), z.null()])
|
|
407
|
+
}),
|
|
408
|
+
output: z.object({
|
|
409
|
+
name: z.string(),
|
|
410
|
+
schema: z.string(),
|
|
411
|
+
effectiveSchema: z.string()
|
|
412
|
+
}),
|
|
413
|
+
result: z.union([z.record(z.string(), z.unknown()), z.null()]).optional(),
|
|
414
|
+
error: z.union([z.string(), z.null()]),
|
|
415
|
+
fullPrompt: z.string(),
|
|
416
|
+
model: z.string(),
|
|
417
|
+
provider: z.string(),
|
|
418
|
+
startedAt: dateFromIso,
|
|
419
|
+
finishedAt: dateFromIso,
|
|
420
|
+
createdAt: mandatoryDateFromIso,
|
|
421
|
+
updatedAt: mandatoryDateFromIso
|
|
422
|
+
});
|
|
423
|
+
const isNuabaseError = (value) => Boolean(value && typeof value === "object" && "isError" in value && value.isError);
|
|
424
|
+
async function getRequest(client, llmRequestId) {
|
|
425
|
+
const response = await client.request("GET", `requests/${encodeURIComponent(llmRequestId)}`);
|
|
426
|
+
if (isNuabaseError(response)) {
|
|
427
|
+
return response;
|
|
428
|
+
}
|
|
429
|
+
const parsedResponse = apiResponseSchema.safeParse(response);
|
|
430
|
+
if (!parsedResponse.success) {
|
|
431
|
+
return errorParseFailed;
|
|
432
|
+
}
|
|
433
|
+
return parsedResponse.data;
|
|
434
|
+
}
|
|
435
|
+
|
|
318
436
|
class Nua {
|
|
319
437
|
constructor(config) {
|
|
320
438
|
this.apiClient = new NuabaseAPIClient(config);
|
|
@@ -325,6 +443,9 @@ class Nua {
|
|
|
325
443
|
createFn(fnDef) {
|
|
326
444
|
return createValueFn(this.apiClient, fnDef);
|
|
327
445
|
}
|
|
446
|
+
async getRequest(llmRequestId) {
|
|
447
|
+
return getRequest(this.apiClient, llmRequestId);
|
|
448
|
+
}
|
|
328
449
|
}
|
|
329
450
|
|
|
330
451
|
export { Nua };
|
|
@@ -7,5 +7,5 @@ export declare class NuabaseAPIClient {
|
|
|
7
7
|
private readonly apiKey;
|
|
8
8
|
private readonly baseUrl;
|
|
9
9
|
constructor(config?: NuabaseConfig);
|
|
10
|
-
request(urlPath: string, params
|
|
10
|
+
request(method: 'GET' | 'POST', urlPath: string, params?: object): Promise<NuabaseError | unknown>;
|
|
11
11
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveConfigValue<T extends Record<string, any>>(config: T, key: keyof T, envVar: string): string | undefined;
|
|
@@ -7,7 +7,7 @@ type NuaApiResponseShape<OutputZodSchema extends z.ZodTypeAny, OutputName extend
|
|
|
7
7
|
kind: 'cast/array';
|
|
8
8
|
data: Array<ResponseRow<OutputZodSchema, OutputName, PrimaryKeyName, InputRecord>>;
|
|
9
9
|
cacheHits: number;
|
|
10
|
-
rowsWithNoResults:
|
|
10
|
+
rowsWithNoResults: UserDataPKValue[];
|
|
11
11
|
isSuccess: true;
|
|
12
12
|
isError?: false;
|
|
13
13
|
};
|
|
@@ -10,9 +10,24 @@ export type ArrayFnDef<OutputName extends string, OutputZodSchema extends z.ZodT
|
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
export declare const validateArrayFnDef: <OutputName extends string, OutputZodSchema extends z.ZodTypeAny>(fnDef: ArrayFnDef<OutputName, OutputZodSchema>) => ArrayFnDef<OutputName, OutputZodSchema>;
|
|
13
|
-
|
|
13
|
+
type CastArraySuccessFromApi<OutputZodSchema extends z.ZodTypeAny, OutputName extends string, PrimaryKeyName extends string, InputRecord extends PrimaryKeyedInputRecord<PrimaryKeyName>> = NuaApiResponse_CastArray<OutputZodSchema, OutputName, PrimaryKeyName, InputRecord>;
|
|
14
|
+
type CastArraySourceRowAugmentation<PrimaryKeyName extends string, InputRecord extends PrimaryKeyedInputRecord<PrimaryKeyName>> = {
|
|
15
|
+
/**
|
|
16
|
+
* SDK-added field containing the full input row for convenience; not returned by the API.
|
|
17
|
+
*/
|
|
18
|
+
sourceRow: InputRecord;
|
|
19
|
+
};
|
|
20
|
+
type CastArraySuccessRowWithSource<OutputZodSchema extends z.ZodTypeAny, OutputName extends string, PrimaryKeyName extends string, InputRecord extends PrimaryKeyedInputRecord<PrimaryKeyName>> = CastArraySuccessFromApi<OutputZodSchema, OutputName, PrimaryKeyName, InputRecord>['data'][number] & CastArraySourceRowAugmentation<PrimaryKeyName, InputRecord>;
|
|
21
|
+
export type CastArraySuccessWithSource<OutputZodSchema extends z.ZodTypeAny, OutputName extends string, PrimaryKeyName extends string, InputRecord extends PrimaryKeyedInputRecord<PrimaryKeyName>> = Omit<CastArraySuccessFromApi<OutputZodSchema, OutputName, PrimaryKeyName, InputRecord>, 'data'> & {
|
|
22
|
+
/**
|
|
23
|
+
* Each row mirrors the API payload and includes the SDK-provided `sourceRow`.
|
|
24
|
+
*/
|
|
25
|
+
data: CastArraySuccessRowWithSource<OutputZodSchema, OutputName, PrimaryKeyName, InputRecord>[];
|
|
26
|
+
};
|
|
27
|
+
export type ArrayFnResult<OutputZodSchema extends z.ZodTypeAny, OutputName extends string, PrimaryKeyName extends string, InputRecord extends PrimaryKeyedInputRecord<PrimaryKeyName>> = NuabaseError | CastArraySuccessWithSource<OutputZodSchema, OutputName, PrimaryKeyName, InputRecord>;
|
|
14
28
|
export type ArrayFnQueuedResult = NuabaseError | NuaQueuedResponse;
|
|
15
29
|
export type ArrayFn<OutputZodSchema extends z.ZodTypeAny, OutputName extends string> = {
|
|
16
30
|
<PrimaryKeyName extends string, InputRecord extends PrimaryKeyedInputRecord<PrimaryKeyName>>(data: InputRecord[], primaryKeyName: PrimaryKeyName): Promise<ArrayFnQueuedResult>;
|
|
17
31
|
now: <PrimaryKeyName extends string, InputRecord extends PrimaryKeyedInputRecord<PrimaryKeyName>>(data: InputRecord[], primaryKeyName: PrimaryKeyName) => Promise<ArrayFnResult<OutputZodSchema, OutputName, PrimaryKeyName, InputRecord>>;
|
|
18
32
|
};
|
|
33
|
+
export {};
|
package/dist/types/nua/core.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { NuabaseAPIClient, NuabaseConfig } from '../lib/api-client';
|
|
2
2
|
import { ArrayFn, ArrayFnDef } from './cast_array/types';
|
|
3
3
|
import { ValueFn, ValueFnDef } from './cast_value/types';
|
|
4
|
+
import { GetRequestResult } from './get-request';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
export declare class Nua {
|
|
6
7
|
apiClient: NuabaseAPIClient;
|
|
7
8
|
constructor(config?: NuabaseConfig);
|
|
8
9
|
createArrayFn<OutputName extends string, OutputZodSchema extends z.ZodTypeAny>(fnDef: ArrayFnDef<OutputName, OutputZodSchema>): ArrayFn<OutputZodSchema, OutputName>;
|
|
9
10
|
createFn<OutputName extends string, OutputZodSchema extends z.ZodTypeAny>(fnDef: ValueFnDef<OutputName, OutputZodSchema>): ValueFn<OutputZodSchema, OutputName>;
|
|
11
|
+
getRequest(llmRequestId: string): Promise<GetRequestResult>;
|
|
10
12
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NuabaseAPIClient } from '../../lib/api-client';
|
|
2
|
+
import { NuabaseError } from '../../lib/error-response';
|
|
3
|
+
import { ApiResponseLlmRequest, NuaInternalError } from './types';
|
|
4
|
+
export type GetRequestResult = ApiResponseLlmRequest | NuaInternalError | NuabaseError;
|
|
5
|
+
export declare function getRequest(client: NuabaseAPIClient, llmRequestId: string): Promise<GetRequestResult>;
|
|
6
|
+
export type { ApiResponseLlmRequest, LlmRequestStatus, NuaInternalError, SseRequestStatus, WebhookRequestStatus, } from './types';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type LlmRequestType = string;
|
|
2
|
+
export type LlmRequestStatus = 'pending' | 'processing' | 'success' | 'failed';
|
|
3
|
+
export type SseRequestStatus = 'n/a' | 'pending' | 'sent' | 'failed';
|
|
4
|
+
export type WebhookRequestStatus = 'n/a' | 'pending' | 'sent' | 'failed';
|
|
5
|
+
export type NuaInternalError = {
|
|
6
|
+
kind: 'internal-error';
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
export type ApiResponseLlmRequest = {
|
|
10
|
+
id: string;
|
|
11
|
+
requestType: LlmRequestType;
|
|
12
|
+
llmStatus: LlmRequestStatus;
|
|
13
|
+
sseStatus: SseRequestStatus;
|
|
14
|
+
webhookStatus: WebhookRequestStatus;
|
|
15
|
+
input: {
|
|
16
|
+
prompt: string | null;
|
|
17
|
+
data: string | null;
|
|
18
|
+
primaryKey: string | null;
|
|
19
|
+
};
|
|
20
|
+
output: {
|
|
21
|
+
name: string;
|
|
22
|
+
schema: string;
|
|
23
|
+
effectiveSchema: string;
|
|
24
|
+
};
|
|
25
|
+
result?: Record<string, unknown> | null;
|
|
26
|
+
error: string | null;
|
|
27
|
+
fullPrompt: string;
|
|
28
|
+
model: string;
|
|
29
|
+
provider: string;
|
|
30
|
+
startedAt: Date | null;
|
|
31
|
+
finishedAt: Date | null;
|
|
32
|
+
createdAt: Date;
|
|
33
|
+
updatedAt: Date;
|
|
34
|
+
};
|
|
@@ -2,3 +2,4 @@ export { Nua } from './core';
|
|
|
2
2
|
export { createArrayFn } from './cast_array/factory';
|
|
3
3
|
export { validateArrayRequestParams } from './cast_array/request-validation';
|
|
4
4
|
export type { ArrayFn, ArrayFnDef } from './cast_array/types';
|
|
5
|
+
export type { ApiResponseLlmRequest, GetRequestResult, LlmRequestStatus, NuaInternalError, SseRequestStatus, WebhookRequestStatus, } from './get-request';
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "nuabase",
|
|
3
3
|
"description": "Nuabase TypeScript client to create typed functions from LLM prompts",
|
|
4
4
|
"packageManager": "yarn@4.10.3+sha512.c38cafb5c7bb273f3926d04e55e1d8c9dfa7d9c3ea1f36a4868fa028b9e5f72298f0b7f401ad5eb921749eb012eb1c3bb74bf7503df3ee43fd600d14a018266f",
|
|
5
|
-
"version": "1.0
|
|
5
|
+
"version": "1.1.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Jasim A Basheer <jasim@nuabase.com>",
|
|
8
8
|
"engines": {
|