@agentuity/server 0.0.64 → 0.0.66
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 +1 -1
- package/dist/api/api.d.ts +5 -9
- package/dist/api/api.d.ts.map +1 -1
- package/dist/api/api.js +41 -20
- package/dist/api/api.js.map +1 -1
- package/dist/api/db/index.d.ts +5 -0
- package/dist/api/db/index.d.ts.map +1 -0
- package/dist/api/db/index.js +5 -0
- package/dist/api/db/index.js.map +1 -0
- package/dist/api/db/logs.d.ts +39 -0
- package/dist/api/db/logs.d.ts.map +1 -0
- package/dist/api/db/logs.js +59 -0
- package/dist/api/db/logs.js.map +1 -0
- package/dist/api/db/query.d.ts +26 -0
- package/dist/api/db/query.d.ts.map +1 -0
- package/dist/api/db/query.js +49 -0
- package/dist/api/db/query.js.map +1 -0
- package/dist/api/db/tables.d.ts +30 -0
- package/dist/api/db/tables.d.ts.map +1 -0
- package/dist/api/db/tables.js +59 -0
- package/dist/api/db/tables.js.map +1 -0
- package/dist/api/db/util.d.ts +31 -0
- package/dist/api/db/util.d.ts.map +1 -0
- package/dist/api/db/util.js +4 -0
- package/dist/api/db/util.js.map +1 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/region/resources.d.ts +2 -0
- package/dist/api/region/resources.d.ts.map +1 -1
- package/dist/api/region/resources.js +1 -0
- package/dist/api/region/resources.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -3
- package/dist/config.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +7 -2
- package/dist/server.js.map +1 -1
- package/package.json +2 -2
- package/src/api/api.ts +54 -24
- package/src/api/db/index.ts +10 -0
- package/src/api/db/logs.ts +75 -0
- package/src/api/db/query.ts +67 -0
- package/src/api/db/tables.ts +92 -0
- package/src/api/db/util.ts +9 -0
- package/src/api/index.ts +1 -0
- package/src/api/region/resources.ts +1 -0
- package/src/config.ts +18 -3
- package/src/server.ts +6 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/api/db/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC,iBAAiB,CAAC,EAAwB,CAAC;AAE1F,MAAM,CAAC,MAAM,sBAAsB,GAAG,eAAe,CAAC,wBAAwB,CAAC,EAI3E,CAAC"}
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
|
package/dist/api/index.js
CHANGED
package/dist/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
|
|
@@ -14,6 +14,7 @@ declare const ResourceListResponse: z.ZodObject<{
|
|
|
14
14
|
username: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
15
15
|
password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
16
16
|
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
+
logical_databases: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
17
18
|
}, z.core.$strip>>;
|
|
18
19
|
}, z.core.$strip>;
|
|
19
20
|
declare const ResourceListResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -35,6 +36,7 @@ declare const ResourceListResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
35
36
|
username: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
36
37
|
password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
37
38
|
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
39
|
+
logical_databases: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
38
40
|
}, z.core.$strip>>;
|
|
39
41
|
}, z.core.$strip>;
|
|
40
42
|
}, z.core.$strip>], "success">;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/api/region/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAqB,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGtD,QAAA,MAAM,oBAAoB
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/api/region/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAqB,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGtD,QAAA,MAAM,oBAAoB;;;;;;;;;;;;;;;;iBAoBxB,CAAC;AACH,QAAA,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;8BAA0C,CAAC;AAE3E,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAC9E,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAClC,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACZ,OAAO,CAAC,YAAY,CAAC,CAUvB"}
|
|
@@ -15,6 +15,7 @@ const ResourceListResponse = z.object({
|
|
|
15
15
|
username: z.string().nullable().optional().describe('the database username'),
|
|
16
16
|
password: z.string().nullable().optional().describe('the database password'),
|
|
17
17
|
url: z.string().nullable().optional().describe('the full database connection URL'),
|
|
18
|
+
logical_databases: z.array(z.string()).optional().describe('list of logical databases'),
|
|
18
19
|
})),
|
|
19
20
|
});
|
|
20
21
|
const ResourceListResponseSchema = APIResponseSchema(ResourceListResponse);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../../src/api/region/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC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AAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC9C,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC;QAC5E,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC;QAC5E,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,kCAAkC,CAAC;QAClF,iBAAiB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC;KACvF,CAAC,CACF;CACD,CAAC,CAAC;AACH,MAAM,0BAA0B,GAAG,iBAAiB,CAAC,oBAAoB,CAAC,CAAC;AAK3E;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,MAAiB,EACjB,KAAa,EACb,MAAc;IAEd,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAChC,KAAK,EACL,wBAAwB,KAAK,IAAI,MAAM,EAAE,EACzC,0BAA0B,CAC1B,CAAC;IACF,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,mBAAmB,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ export interface ServiceUrls {
|
|
|
8
8
|
/**
|
|
9
9
|
* Get service URLs from environment variables with fallback defaults
|
|
10
10
|
*/
|
|
11
|
-
export declare function getServiceUrls(): ServiceUrls;
|
|
11
|
+
export declare function getServiceUrls(region?: string): ServiceUrls;
|
|
12
12
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,cAAc,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,CAU3D"}
|
package/dist/config.js
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Get service URLs from environment variables with fallback defaults
|
|
3
3
|
*/
|
|
4
|
-
export function getServiceUrls() {
|
|
5
|
-
const transportUrl = process.env.AGENTUITY_TRANSPORT_URL || '
|
|
4
|
+
export function getServiceUrls(region) {
|
|
5
|
+
const transportUrl = process.env.AGENTUITY_TRANSPORT_URL || buildRegionalURL(region, 'catalyst');
|
|
6
6
|
return {
|
|
7
7
|
keyvalue: process.env.AGENTUITY_KEYVALUE_URL || transportUrl,
|
|
8
8
|
objectstore: process.env.AGENTUITY_OBJECTSTORE_URL || transportUrl,
|
|
9
|
-
stream: process.env.AGENTUITY_STREAM_URL || '
|
|
9
|
+
stream: process.env.AGENTUITY_STREAM_URL || buildRegionalURL(region, 'streams'),
|
|
10
10
|
vector: process.env.AGENTUITY_VECTOR_URL || transportUrl,
|
|
11
11
|
catalyst: process.env.AGENTUITY_CATALYST_URL || transportUrl,
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
+
function getDomainSuffix(region) {
|
|
15
|
+
if (region === 'local') {
|
|
16
|
+
return 'agentuity.io';
|
|
17
|
+
}
|
|
18
|
+
return 'agentuity.cloud';
|
|
19
|
+
}
|
|
20
|
+
function buildRegionalURL(region, hostname) {
|
|
21
|
+
const suffix = getDomainSuffix(region);
|
|
22
|
+
if (suffix === 'agentuity.io') {
|
|
23
|
+
return `https://${hostname}.${suffix}`;
|
|
24
|
+
}
|
|
25
|
+
return `https://${hostname}-${region}.${suffix}`;
|
|
26
|
+
}
|
|
14
27
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,UAAU,cAAc;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAe;IAC7C,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAEjG,OAAO;QACN,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,YAAY;QAC5D,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,YAAY;QAClE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC;QAC/E,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,YAAY;QACxD,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,YAAY;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MAAM,EAAE,MAAM,sBAEpF"}
|
package/dist/server.js
CHANGED
|
@@ -27,7 +27,12 @@ const redactHeaders = (kv) => {
|
|
|
27
27
|
const _k = k.toLowerCase();
|
|
28
28
|
const v = kv[k];
|
|
29
29
|
if (sensitiveHeaders.has(_k)) {
|
|
30
|
-
|
|
30
|
+
if (_k === 'authorization' && v.startsWith('Bearer ')) {
|
|
31
|
+
values.push(`${_k}=Bearer ${redact(v.substring(7))}`);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
values.push(`${_k}=${redact(v)}`);
|
|
35
|
+
}
|
|
31
36
|
}
|
|
32
37
|
else {
|
|
33
38
|
values.push(`${_k}=${v}`);
|
|
@@ -86,7 +91,7 @@ class ServerFetchAdapter {
|
|
|
86
91
|
response: res,
|
|
87
92
|
};
|
|
88
93
|
}
|
|
89
|
-
const data = await fromResponse(
|
|
94
|
+
const data = await fromResponse(res);
|
|
90
95
|
return {
|
|
91
96
|
ok: true,
|
|
92
97
|
data,
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAarF,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC,CAAC;AAEjE;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CACrB,KAAa,EACb,SAAiB,CAAC,EAClB,SAAiB,CAAC,EAClB,OAAe,GAAG;IAElB,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAEtB,6DAA6D;IAC7D,IAAI,KAAK,CAAC,MAAM,IAAI,MAAM,GAAG,MAAM,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,KAA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CAAC,OAAO,EAAE,CAAC;wBAC1B,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;oBAClD,CAAC;gBACF,CAAC;gBAAC,OAAO,EAAE,EAAE,CAAC;oBACb,GAAG,GAAG,EAAW,CAAC;oBAClB,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,GAAG,YAAY,gBAAgB,EAAE,CAAC;wBAC7D,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CACzB,GAAG,EACH,OAAO,EACP;4BACC,EAAE,EAAE,KAAK;4BACT,QAAQ,EAAE,IAAI,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE;gCACnC,MAAM,EAAE,GAAG,CAAC,UAAU;6BACtB,CAAC;yBACoB,EACvB,GAAG,CACH,CAAC;oBACH,CAAC;gBACF,CAAC;YACF,CAAC,CAAC,CAAC;YACH,IAAI,GAAG,EAAE,CAAC;gBACT,MAAM,GAAG,CAAC;YACX,CAAC;YACD,OAAO,MAAqC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACP,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACzC,CAAC;IACF,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAA4B,EAAE,MAAc;IACpF,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentuity/server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.66",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "Agentuity employees and contributors",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"prepublishOnly": "bun run clean && bun run build"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@agentuity/core": "0.0.
|
|
28
|
+
"@agentuity/core": "0.0.66",
|
|
29
29
|
"zod": "^4.1.12"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
package/src/api/api.ts
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
* API Client for Agentuity Platform
|
|
3
3
|
*
|
|
4
4
|
* Handles HTTP requests to the API with automatic error parsing and User-Agent headers.
|
|
5
|
-
*
|
|
6
|
-
* Error handling:
|
|
7
|
-
* - UPGRADE_REQUIRED (409): Throws UpgradeRequiredError
|
|
8
|
-
* - Other errors: Throws Error with API message or status text
|
|
9
5
|
*/
|
|
10
6
|
|
|
11
7
|
import { z } from 'zod';
|
|
@@ -17,6 +13,7 @@ export interface APIClientConfig {
|
|
|
17
13
|
userAgent?: string;
|
|
18
14
|
maxRetries?: number;
|
|
19
15
|
retryDelayMs?: number;
|
|
16
|
+
headers?: Record<string, string>;
|
|
20
17
|
}
|
|
21
18
|
|
|
22
19
|
const ZodIssuesSchema = z.array(
|
|
@@ -43,19 +40,20 @@ const APIErrorSchema = z.object({
|
|
|
43
40
|
success: z.boolean(),
|
|
44
41
|
code: z.string().optional(),
|
|
45
42
|
message: z.string().optional(),
|
|
46
|
-
error: z
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
error: z
|
|
44
|
+
.union([
|
|
45
|
+
z.string(),
|
|
46
|
+
z.object({
|
|
47
|
+
name: z.string().optional(),
|
|
48
|
+
issues: ZodIssuesSchema.optional(),
|
|
49
|
+
}),
|
|
50
|
+
])
|
|
51
|
+
.optional(),
|
|
50
52
|
details: z.record(z.string(), z.unknown()).optional(),
|
|
51
53
|
});
|
|
52
54
|
|
|
53
|
-
export const APIError = StructuredError(
|
|
54
|
-
'APIErrorResponse',
|
|
55
|
-
'The API encountered an unexpected error attempting to reach the service.'
|
|
56
|
-
)<{
|
|
55
|
+
export const APIError = StructuredError('APIErrorResponse')<{
|
|
57
56
|
url: string;
|
|
58
|
-
error?: string;
|
|
59
57
|
status: number;
|
|
60
58
|
sessionId?: string | null;
|
|
61
59
|
}>();
|
|
@@ -175,7 +173,7 @@ export class APIClient {
|
|
|
175
173
|
}
|
|
176
174
|
|
|
177
175
|
async #makeRequest(method: string, endpoint: string, body?: unknown): Promise<Response> {
|
|
178
|
-
this.#logger.trace('sending %s to %s', method, endpoint);
|
|
176
|
+
this.#logger.trace('sending %s to %s%s', method, this.#baseUrl, endpoint);
|
|
179
177
|
|
|
180
178
|
const maxRetries = this.#config?.maxRetries ?? 3;
|
|
181
179
|
const baseDelayMs = this.#config?.retryDelayMs ?? 100;
|
|
@@ -185,6 +183,7 @@ export class APIClient {
|
|
|
185
183
|
const url = `${this.#baseUrl}${endpoint}`;
|
|
186
184
|
const headers: Record<string, string> = {
|
|
187
185
|
'Content-Type': 'application/json',
|
|
186
|
+
Accept: 'application/json',
|
|
188
187
|
};
|
|
189
188
|
|
|
190
189
|
if (this.#config?.userAgent) {
|
|
@@ -195,6 +194,12 @@ export class APIClient {
|
|
|
195
194
|
headers['Authorization'] = `Bearer ${this.#apiKey}`;
|
|
196
195
|
}
|
|
197
196
|
|
|
197
|
+
if (this.#config?.headers) {
|
|
198
|
+
Object.keys(this.#config.headers).forEach(
|
|
199
|
+
(key) => (headers[key] = this.#config!.headers![key])
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
198
203
|
let response: Response;
|
|
199
204
|
|
|
200
205
|
try {
|
|
@@ -261,9 +266,12 @@ export class APIClient {
|
|
|
261
266
|
let errorData: z.infer<typeof APIErrorSchema> | undefined;
|
|
262
267
|
|
|
263
268
|
try {
|
|
264
|
-
errorData = APIErrorSchema.parse(responseBody);
|
|
265
|
-
} catch {
|
|
266
|
-
|
|
269
|
+
errorData = APIErrorSchema.parse(JSON.parse(responseBody));
|
|
270
|
+
} catch (parseEx) {
|
|
271
|
+
this.#logger.warn(
|
|
272
|
+
'parsing response data against APIError schema failed: %s',
|
|
273
|
+
parseEx
|
|
274
|
+
);
|
|
267
275
|
}
|
|
268
276
|
|
|
269
277
|
// Sanitize headers to avoid leaking API keys
|
|
@@ -295,7 +303,11 @@ export class APIClient {
|
|
|
295
303
|
}
|
|
296
304
|
|
|
297
305
|
// Handle Zod validation errors from the API
|
|
298
|
-
if (
|
|
306
|
+
if (
|
|
307
|
+
typeof errorData?.error === 'object' &&
|
|
308
|
+
errorData?.error?.name === 'ZodError' &&
|
|
309
|
+
errorData.error.issues
|
|
310
|
+
) {
|
|
299
311
|
throw new ValidationOutputError({
|
|
300
312
|
url,
|
|
301
313
|
issues: errorData.error.issues,
|
|
@@ -308,12 +320,22 @@ export class APIClient {
|
|
|
308
320
|
throw new APIError({
|
|
309
321
|
url,
|
|
310
322
|
status: response.status,
|
|
311
|
-
|
|
323
|
+
message:
|
|
324
|
+
typeof errorData.error === 'string'
|
|
325
|
+
? errorData.error
|
|
326
|
+
: (errorData.message ??
|
|
327
|
+
'The API encountered an unexpected error attempting to reach the service.'),
|
|
312
328
|
sessionId,
|
|
313
329
|
});
|
|
314
330
|
}
|
|
315
331
|
|
|
316
|
-
throw new APIError({
|
|
332
|
+
throw new APIError({
|
|
333
|
+
message:
|
|
334
|
+
'The API encountered an unexpected error attempting to reach the service.',
|
|
335
|
+
url: url,
|
|
336
|
+
status: response.status,
|
|
337
|
+
sessionId,
|
|
338
|
+
});
|
|
317
339
|
}
|
|
318
340
|
|
|
319
341
|
// Successful response; handle empty bodies (e.g., 204 No Content)
|
|
@@ -407,7 +429,7 @@ export class APIClient {
|
|
|
407
429
|
}
|
|
408
430
|
}
|
|
409
431
|
|
|
410
|
-
export function getAPIBaseURL(overrides?: { api_url?: string }): string {
|
|
432
|
+
export function getAPIBaseURL(region?: string, overrides?: { api_url?: string }): string {
|
|
411
433
|
if (process.env.AGENTUITY_API_URL) {
|
|
412
434
|
return process.env.AGENTUITY_API_URL;
|
|
413
435
|
}
|
|
@@ -416,10 +438,14 @@ export function getAPIBaseURL(overrides?: { api_url?: string }): string {
|
|
|
416
438
|
return overrides.api_url;
|
|
417
439
|
}
|
|
418
440
|
|
|
419
|
-
|
|
441
|
+
if (region === 'local') {
|
|
442
|
+
return 'https://api.agentuity.io';
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
return 'https://api-v1.agentuity.com';
|
|
420
446
|
}
|
|
421
447
|
|
|
422
|
-
export function getAppBaseURL(overrides?: { app_url?: string }): string {
|
|
448
|
+
export function getAppBaseURL(region?: string, overrides?: { app_url?: string } | null): string {
|
|
423
449
|
if (process.env.AGENTUITY_APP_URL) {
|
|
424
450
|
return process.env.AGENTUITY_APP_URL;
|
|
425
451
|
}
|
|
@@ -428,7 +454,11 @@ export function getAppBaseURL(overrides?: { app_url?: string }): string {
|
|
|
428
454
|
return overrides.app_url;
|
|
429
455
|
}
|
|
430
456
|
|
|
431
|
-
|
|
457
|
+
if (region === 'local') {
|
|
458
|
+
return 'https://app.agentuity.io';
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return 'https://app-v1.agentuity.com';
|
|
432
462
|
}
|
|
433
463
|
|
|
434
464
|
export const APIResponseSchema = <T extends z.ZodType>(dataSchema: T) =>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { dbLogs, DbQueryLogSchema, type DbQueryLog, type DbQueryLogs } from './logs';
|
|
2
|
+
export {
|
|
3
|
+
dbTables,
|
|
4
|
+
generateCreateTableSQL,
|
|
5
|
+
TableSchemaSchema,
|
|
6
|
+
type TableColumn,
|
|
7
|
+
type TableSchema,
|
|
8
|
+
} from './tables';
|
|
9
|
+
export { dbQuery, type QueryColumn, type QueryResult } from './query';
|
|
10
|
+
export { DbResponseError, DbInvalidArgumentError } from './util';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIClient, APIResponseSchema } from '../api';
|
|
3
|
+
import { DbInvalidArgumentError, DbResponseError } from './util';
|
|
4
|
+
|
|
5
|
+
const _DbLogsRequestSchema = z.object({
|
|
6
|
+
database: z.string().describe('the database name'),
|
|
7
|
+
orgId: z.string().describe('the organization ID'),
|
|
8
|
+
region: z.string().describe('the region'),
|
|
9
|
+
startDate: z.string().optional().describe('start date filter'),
|
|
10
|
+
endDate: z.string().optional().describe('end date filter'),
|
|
11
|
+
username: z.string().optional().describe('username filter'),
|
|
12
|
+
command: z.string().optional().describe('command filter'),
|
|
13
|
+
hasError: z.boolean().optional().describe('filter by error status'),
|
|
14
|
+
sessionId: z.string().optional().describe('filter by session ID (trace ID)'),
|
|
15
|
+
limit: z.number().optional().describe('maximum number of logs to return'),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const DbQueryLogSchema = z.object({
|
|
19
|
+
timestamp: z.string().describe('log timestamp'),
|
|
20
|
+
username: z.string().describe('username'),
|
|
21
|
+
database: z.string().describe('database name'),
|
|
22
|
+
duration: z.number().describe('query duration in milliseconds'),
|
|
23
|
+
txStatus: z.string().describe('transaction status'),
|
|
24
|
+
command: z.string().describe('SQL command type'),
|
|
25
|
+
rowCount: z.number().describe('number of rows affected'),
|
|
26
|
+
sql: z.string().describe('SQL query'),
|
|
27
|
+
error: z.string().optional().describe('error message if any'),
|
|
28
|
+
sessionId: z.string().optional().describe('session ID with sess_ prefix'),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const DbLogsResponse = z.array(DbQueryLogSchema);
|
|
32
|
+
|
|
33
|
+
const DbLogsResponseSchema = APIResponseSchema(DbLogsResponse);
|
|
34
|
+
|
|
35
|
+
type DbLogsRequest = z.infer<typeof _DbLogsRequestSchema>;
|
|
36
|
+
type DbLogsResponse = z.infer<typeof DbLogsResponseSchema>;
|
|
37
|
+
|
|
38
|
+
export type DbQueryLog = z.infer<typeof DbQueryLogSchema>;
|
|
39
|
+
export type DbQueryLogs = DbQueryLog[];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get query logs for a database from the App API
|
|
43
|
+
*
|
|
44
|
+
* @param client APIClient configured for the App API base URL
|
|
45
|
+
* @param request
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
export async function dbLogs(client: APIClient, request: DbLogsRequest): Promise<DbQueryLogs> {
|
|
49
|
+
const { database, orgId, region, ...filters } = request;
|
|
50
|
+
|
|
51
|
+
if (!orgId || !region) {
|
|
52
|
+
throw new DbInvalidArgumentError({ message: 'orgId and region are required', orgId, region });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const params = new URLSearchParams();
|
|
56
|
+
Object.entries(filters).forEach(([key, value]) => {
|
|
57
|
+
if (value !== undefined) {
|
|
58
|
+
params.append(key, String(value));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const queryString = params.toString();
|
|
63
|
+
const url = `/resource/2025-03-17/${orgId}/${region}/${database}/logs${queryString ? `?${queryString}` : ''}`;
|
|
64
|
+
|
|
65
|
+
const resp = await client.request<DbLogsResponse>('GET', url, DbLogsResponseSchema);
|
|
66
|
+
|
|
67
|
+
if (resp.success) {
|
|
68
|
+
return resp.data;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
throw new DbResponseError({
|
|
72
|
+
database,
|
|
73
|
+
message: resp.message || 'Failed to fetch database logs',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIClient, APIError } from '../api';
|
|
3
|
+
import { DbInvalidArgumentError, DbResponseError } from './util';
|
|
4
|
+
|
|
5
|
+
const QueryColumnSchema = z.object({
|
|
6
|
+
name: z.string().describe('column name'),
|
|
7
|
+
type: z.string().describe('PostgreSQL data type OID'),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const QueryResultSchema = z.object({
|
|
11
|
+
columns: z.array(QueryColumnSchema).describe('column metadata'),
|
|
12
|
+
rows: z.array(z.record(z.string(), z.any())).describe('query result rows'),
|
|
13
|
+
rowCount: z.number().describe('number of rows returned'),
|
|
14
|
+
truncated: z.boolean().describe('whether results were truncated (max 1000 rows)'),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const QueryResponseSchema = z.object({
|
|
18
|
+
success: z.boolean(),
|
|
19
|
+
message: z.string().optional(),
|
|
20
|
+
data: QueryResultSchema.optional(),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export type QueryColumn = z.infer<typeof QueryColumnSchema>;
|
|
24
|
+
export type QueryResult = z.infer<typeof QueryResultSchema>;
|
|
25
|
+
|
|
26
|
+
interface DbQueryRequest {
|
|
27
|
+
database: string;
|
|
28
|
+
query: string;
|
|
29
|
+
orgId: string;
|
|
30
|
+
region: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function dbQuery(client: APIClient, request: DbQueryRequest): Promise<QueryResult> {
|
|
34
|
+
const { database, query, orgId, region } = request;
|
|
35
|
+
|
|
36
|
+
if (!orgId || !region) {
|
|
37
|
+
throw new DbInvalidArgumentError({ message: 'orgId and region are required', orgId, region });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!query) {
|
|
41
|
+
throw new DbInvalidArgumentError({ message: 'query is required', query });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const url = `/resource/2025-03-17/${orgId}/${region}/${database}/query`;
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const resp = await client.request('POST', url, QueryResponseSchema, { query });
|
|
48
|
+
|
|
49
|
+
if (resp.success && resp.data) {
|
|
50
|
+
return resp.data;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
throw new DbResponseError({
|
|
54
|
+
database,
|
|
55
|
+
message: resp.message ?? 'Failed to execute database query',
|
|
56
|
+
});
|
|
57
|
+
} catch (ex) {
|
|
58
|
+
if (ex instanceof APIError) {
|
|
59
|
+
let message = ex.message;
|
|
60
|
+
if (message?.startsWith('failed to execute query: ')) {
|
|
61
|
+
message = message.substring(25);
|
|
62
|
+
}
|
|
63
|
+
throw new DbResponseError({ database, message });
|
|
64
|
+
}
|
|
65
|
+
throw ex;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIClient, APIResponseSchema } from '../api';
|
|
3
|
+
import { DbInvalidArgumentError, DbResponseError } from './util';
|
|
4
|
+
|
|
5
|
+
const TableColumnSchema = z.object({
|
|
6
|
+
name: z.string().describe('column name'),
|
|
7
|
+
data_type: z.string().describe('PostgreSQL data type'),
|
|
8
|
+
is_nullable: z.boolean().describe('whether the column is nullable'),
|
|
9
|
+
default_value: z.string().optional().describe('default value'),
|
|
10
|
+
is_primary_key: z.boolean().describe('whether this column is part of the primary key'),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const TableSchemaSchema = z.object({
|
|
14
|
+
table_name: z.string().describe('table name'),
|
|
15
|
+
columns: z.array(TableColumnSchema).describe('table columns'),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const TablesResponseSchema = APIResponseSchema(
|
|
19
|
+
z.object({
|
|
20
|
+
tables: z.array(TableSchemaSchema),
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export type TableColumn = z.infer<typeof TableColumnSchema>;
|
|
25
|
+
export type TableSchema = z.infer<typeof TableSchemaSchema>;
|
|
26
|
+
|
|
27
|
+
interface DbTablesRequest {
|
|
28
|
+
database: string;
|
|
29
|
+
orgId: string;
|
|
30
|
+
region: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function dbTables(
|
|
34
|
+
client: APIClient,
|
|
35
|
+
request: DbTablesRequest
|
|
36
|
+
): Promise<TableSchema[]> {
|
|
37
|
+
const { database, orgId, region } = request;
|
|
38
|
+
|
|
39
|
+
if (!orgId || !region) {
|
|
40
|
+
throw new DbInvalidArgumentError({ message: 'orgId and region are required', orgId, region });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const url = `/resource/2025-03-17/${orgId}/${region}/${database}/tables`;
|
|
44
|
+
|
|
45
|
+
const resp = await client.request('GET', url, TablesResponseSchema);
|
|
46
|
+
|
|
47
|
+
if (resp.success) {
|
|
48
|
+
return resp.data.tables;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
throw new DbResponseError({
|
|
52
|
+
database,
|
|
53
|
+
message: resp.message || 'Failed to fetch database tables',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function generateCreateTableSQL(table: TableSchema): string {
|
|
58
|
+
const lines: string[] = [`CREATE TABLE ${table.table_name} (`];
|
|
59
|
+
|
|
60
|
+
// Collect primary key columns
|
|
61
|
+
const primaryKeyColumns: string[] = [];
|
|
62
|
+
|
|
63
|
+
const columnDefs = table.columns.map((col) => {
|
|
64
|
+
let def = ` ${col.name} ${col.data_type}`;
|
|
65
|
+
|
|
66
|
+
if (!col.is_nullable) {
|
|
67
|
+
def += ' NOT NULL';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (col.default_value) {
|
|
71
|
+
def += ` DEFAULT ${col.default_value}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (col.is_primary_key) {
|
|
75
|
+
primaryKeyColumns.push(col.name);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return def;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
lines.push(columnDefs.join(',\n'));
|
|
82
|
+
|
|
83
|
+
// Add table-level PRIMARY KEY constraint if any columns are marked as primary keys
|
|
84
|
+
if (primaryKeyColumns.length > 0) {
|
|
85
|
+
lines.push(',');
|
|
86
|
+
lines.push(` PRIMARY KEY (${primaryKeyColumns.join(', ')})`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
lines.push(');');
|
|
90
|
+
|
|
91
|
+
return lines.join('\n');
|
|
92
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StructuredError } from '@agentuity/core';
|
|
2
|
+
|
|
3
|
+
export const DbResponseError = StructuredError('DbResponseError')<{ database: string }>();
|
|
4
|
+
|
|
5
|
+
export const DbInvalidArgumentError = StructuredError('DbInvalidArgumentError')<{
|
|
6
|
+
orgId?: string;
|
|
7
|
+
region?: string;
|
|
8
|
+
query?: string;
|
|
9
|
+
}>();
|
package/src/api/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ const ResourceListResponse = z.object({
|
|
|
19
19
|
username: z.string().nullable().optional().describe('the database username'),
|
|
20
20
|
password: z.string().nullable().optional().describe('the database password'),
|
|
21
21
|
url: z.string().nullable().optional().describe('the full database connection URL'),
|
|
22
|
+
logical_databases: z.array(z.string()).optional().describe('list of logical databases'),
|
|
22
23
|
})
|
|
23
24
|
),
|
|
24
25
|
});
|