@neon/tools 2.14.3 → 2.15.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/README.md +79 -2
- package/dist/effect.d.ts +22 -0
- package/dist/effect.d.ts.map +1 -0
- package/dist/effect.js +3 -0
- package/dist/generated/output.gen.d.ts +3418 -0
- package/dist/generated/output.gen.d.ts.map +1 -0
- package/dist/generated/output.gen.js +1498 -0
- package/dist/lib/custom/auth-config.d.ts +63 -1
- package/dist/lib/custom/auth-config.d.ts.map +1 -1
- package/dist/lib/custom/auth-config.js +21 -1
- package/dist/lib/custom/docs.d.ts +32 -2
- package/dist/lib/custom/docs.d.ts.map +1 -1
- package/dist/lib/custom/docs.js +16 -1
- package/dist/lib/custom/feedback.d.ts +7 -2
- package/dist/lib/custom/feedback.d.ts.map +1 -1
- package/dist/lib/custom/feedback.js +2 -0
- package/dist/lib/custom/fetch.d.ts +15 -1
- package/dist/lib/custom/fetch.d.ts.map +1 -1
- package/dist/lib/custom/fetch.js +9 -1
- package/dist/lib/custom/organizations.d.ts +23 -1
- package/dist/lib/custom/organizations.d.ts.map +1 -1
- package/dist/lib/custom/organizations.js +2 -0
- package/dist/lib/custom/resources.d.ts +15 -1
- package/dist/lib/custom/resources.d.ts.map +1 -1
- package/dist/lib/custom/resources.js +7 -1
- package/dist/lib/custom/sql/connection.js +1 -1
- package/dist/lib/custom/sql/describe-branch.d.ts +99 -1
- package/dist/lib/custom/sql/describe-branch.d.ts.map +1 -1
- package/dist/lib/custom/sql/describe-branch.js +9 -0
- package/dist/lib/custom/sql/inspect/inspect.d.ts +27 -1
- package/dist/lib/custom/sql/inspect/inspect.d.ts.map +1 -1
- package/dist/lib/custom/sql/inspect/inspect.js +15 -1
- package/dist/lib/custom/sql/migrations.d.ts +46 -2
- package/dist/lib/custom/sql/migrations.d.ts.map +1 -1
- package/dist/lib/custom/sql/migrations.js +26 -2
- package/dist/lib/custom/sql/plan.d.ts +8 -2
- package/dist/lib/custom/sql/plan.d.ts.map +1 -1
- package/dist/lib/custom/sql/plan.js +13 -6
- package/dist/lib/custom/sql/query-tuning.d.ts +90 -2
- package/dist/lib/custom/sql/query-tuning.d.ts.map +1 -1
- package/dist/lib/custom/sql/query-tuning.js +33 -8
- package/dist/lib/custom/sql/run.d.ts +30 -3
- package/dist/lib/custom/sql/run.d.ts.map +1 -1
- package/dist/lib/custom/sql/run.js +11 -1
- package/dist/lib/custom/sql/schema.d.ts +76 -2
- package/dist/lib/custom/sql/schema.d.ts.map +1 -1
- package/dist/lib/custom/sql/schema.js +78 -36
- package/dist/lib/custom/sql/slow-queries.d.ts +15 -1
- package/dist/lib/custom/sql/slow-queries.d.ts.map +1 -1
- package/dist/lib/custom/sql/slow-queries.js +9 -1
- package/dist/lib/effect/errors.d.ts +51 -0
- package/dist/lib/effect/errors.d.ts.map +1 -0
- package/dist/lib/effect/errors.js +37 -0
- package/dist/lib/effect/tools.d.ts +56 -0
- package/dist/lib/effect/tools.d.ts.map +1 -0
- package/dist/lib/effect/tools.js +67 -0
- package/dist/lib/ergonomic/bind.d.ts +20 -6
- package/dist/lib/ergonomic/bind.d.ts.map +1 -1
- package/dist/lib/ergonomic/bind.js +2 -1
- package/dist/lib/ergonomic/catalog.d.ts +5333 -172
- package/dist/lib/ergonomic/catalog.d.ts.map +1 -1
- package/dist/lib/ergonomic/catalog.js +186 -1
- package/dist/lib/ergonomic/composed.d.ts +866 -12
- package/dist/lib/ergonomic/composed.d.ts.map +1 -1
- package/dist/lib/ergonomic/composed.js +34 -0
- package/dist/lib/mcp-json-schema.d.ts +20 -0
- package/dist/lib/mcp-json-schema.d.ts.map +1 -1
- package/dist/lib/mcp-json-schema.js +89 -1
- package/dist/lib/mcp-register.d.ts +1 -1
- package/dist/lib/mcp-register.d.ts.map +1 -1
- package/dist/lib/mcp-register.js +2 -1
- package/dist/lib/operation.d.ts +6 -1
- package/dist/lib/operation.d.ts.map +1 -1
- package/dist/mcp-v1.d.ts.map +1 -1
- package/dist/mcp-v1.js +3 -1
- package/dist/mcp.d.ts +3 -3
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +3 -3
- package/dist/operations.gen.d.ts +194 -194
- package/package.json +22 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { bindTool, publishedId } from "../../ergonomic/bind.js";
|
|
2
2
|
import { SQL_METADATA, branchIdField, databaseNameField, projectIdField, resolveConnection, sqlClient } from "./connection.js";
|
|
3
|
-
import { NeonClientError } from "@neon/sdk";
|
|
4
3
|
import * as z from "zod";
|
|
4
|
+
import { NeonClientError } from "@neon/sdk";
|
|
5
5
|
// src/lib/custom/sql/schema.ts
|
|
6
6
|
const sqlReadAnnotations = {
|
|
7
7
|
readOnlyHint: true,
|
|
@@ -29,6 +29,27 @@ const LIST_TABLES_SQL = `
|
|
|
29
29
|
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
|
|
30
30
|
ORDER BY table_schema, table_name;
|
|
31
31
|
`;
|
|
32
|
+
const RESOLVE_TABLE_SQL = `
|
|
33
|
+
WITH candidates AS (
|
|
34
|
+
SELECT oid
|
|
35
|
+
FROM pg_catalog.pg_class
|
|
36
|
+
WHERE relname = $1::text AND pg_catalog.pg_table_is_visible(oid)
|
|
37
|
+
UNION
|
|
38
|
+
SELECT cls.oid
|
|
39
|
+
FROM pg_catalog.pg_class cls
|
|
40
|
+
JOIN pg_catalog.pg_namespace ns ON ns.oid = cls.relnamespace
|
|
41
|
+
WHERE ns.nspname || '.' || cls.relname = $1
|
|
42
|
+
UNION
|
|
43
|
+
SELECT to_regclass($1)::oid
|
|
44
|
+
)
|
|
45
|
+
SELECT
|
|
46
|
+
cls.oid::text AS oid,
|
|
47
|
+
format('%I.%I', ns.nspname, cls.relname) AS quoted_name
|
|
48
|
+
FROM candidates
|
|
49
|
+
JOIN pg_catalog.pg_class cls ON cls.oid = candidates.oid
|
|
50
|
+
JOIN pg_catalog.pg_namespace ns ON ns.oid = cls.relnamespace
|
|
51
|
+
ORDER BY quoted_name;
|
|
52
|
+
`;
|
|
32
53
|
const DESCRIBE_COLUMNS_SQL = `
|
|
33
54
|
WITH target AS (
|
|
34
55
|
SELECT
|
|
@@ -37,7 +58,7 @@ const DESCRIBE_COLUMNS_SQL = `
|
|
|
37
58
|
cls.relname AS table_name
|
|
38
59
|
FROM pg_catalog.pg_class cls
|
|
39
60
|
JOIN pg_catalog.pg_namespace ns ON ns.oid = cls.relnamespace
|
|
40
|
-
WHERE cls.oid =
|
|
61
|
+
WHERE cls.oid = $1::oid
|
|
41
62
|
)
|
|
42
63
|
SELECT
|
|
43
64
|
c.column_name as name,
|
|
@@ -55,57 +76,49 @@ const DESCRIBE_COLUMNS_SQL = `
|
|
|
55
76
|
ORDER BY c.ordinal_position;
|
|
56
77
|
`;
|
|
57
78
|
const DESCRIBE_INDEXES_SQL = `
|
|
58
|
-
WITH target AS (
|
|
59
|
-
SELECT to_regclass($1) AS oid
|
|
60
|
-
)
|
|
61
79
|
SELECT
|
|
62
80
|
i.relname as name,
|
|
63
81
|
pg_get_indexdef(i.oid) as definition,
|
|
64
82
|
pg_size_pretty(pg_relation_size(i.oid)) as size
|
|
65
|
-
FROM
|
|
66
|
-
JOIN pg_catalog.pg_class t ON t.oid = target.oid
|
|
83
|
+
FROM pg_catalog.pg_class t
|
|
67
84
|
JOIN pg_catalog.pg_index ix ON t.oid = ix.indrelid
|
|
68
85
|
JOIN pg_catalog.pg_class i ON i.oid = ix.indexrelid
|
|
69
|
-
WHERE t.relkind = 'r';
|
|
86
|
+
WHERE t.oid = $1::oid AND t.relkind = 'r';
|
|
70
87
|
`;
|
|
71
88
|
const DESCRIBE_CONSTRAINTS_SQL = `
|
|
72
|
-
WITH target AS (
|
|
73
|
-
SELECT
|
|
74
|
-
cls.oid,
|
|
75
|
-
ns.nspname AS table_schema,
|
|
76
|
-
cls.relname AS table_name
|
|
77
|
-
FROM pg_catalog.pg_class cls
|
|
78
|
-
JOIN pg_catalog.pg_namespace ns ON ns.oid = cls.relnamespace
|
|
79
|
-
WHERE cls.oid = to_regclass($1)
|
|
80
|
-
)
|
|
81
89
|
SELECT
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
conname as name,
|
|
91
|
+
CASE contype
|
|
92
|
+
WHEN 'p' THEN 'PRIMARY KEY'
|
|
93
|
+
WHEN 'f' THEN 'FOREIGN KEY'
|
|
94
|
+
WHEN 'u' THEN 'UNIQUE'
|
|
95
|
+
WHEN 'c' THEN 'CHECK'
|
|
96
|
+
WHEN 'x' THEN 'EXCLUDE'
|
|
97
|
+
END as type,
|
|
98
|
+
pg_get_constraintdef(oid) as definition
|
|
99
|
+
FROM pg_catalog.pg_constraint
|
|
100
|
+
WHERE conrelid = $1::oid AND contype IN ('p', 'f', 'u', 'c', 'x')
|
|
101
|
+
ORDER BY conname;
|
|
92
102
|
`;
|
|
93
103
|
const DESCRIBE_SIZES_SQL = `
|
|
94
104
|
SELECT
|
|
95
|
-
pg_size_pretty(pg_total_relation_size(
|
|
96
|
-
pg_size_pretty(pg_relation_size(
|
|
105
|
+
pg_size_pretty(pg_total_relation_size($1::oid)) as total_size,
|
|
106
|
+
pg_size_pretty(pg_relation_size($1::oid)) as table_size,
|
|
97
107
|
pg_size_pretty(
|
|
98
|
-
pg_total_relation_size(
|
|
108
|
+
pg_total_relation_size($1::oid) - pg_relation_size($1::oid)
|
|
99
109
|
) as index_size;
|
|
100
110
|
`;
|
|
101
111
|
const describeTable = async (uri, tableName, signal) => {
|
|
102
112
|
const sql = sqlClient(uri, signal);
|
|
103
|
-
|
|
113
|
+
const candidates = await sql.query(RESOLVE_TABLE_SQL, [tableName]);
|
|
114
|
+
const [table, ...others] = candidates;
|
|
115
|
+
if (table === void 0) return null;
|
|
116
|
+
if (others.length > 0) throw new NeonClientError(`Table name ${tableName} matches ${candidates.length} tables. Pass one of these quoted names: ${candidates.map((candidate) => candidate.quoted_name).join(", ")}`);
|
|
104
117
|
const [columns, indexes, constraints, sizes] = await Promise.all([
|
|
105
|
-
sql.query(DESCRIBE_COLUMNS_SQL, [
|
|
106
|
-
sql.query(DESCRIBE_INDEXES_SQL, [
|
|
107
|
-
sql.query(DESCRIBE_CONSTRAINTS_SQL, [
|
|
108
|
-
sql.query(DESCRIBE_SIZES_SQL, [
|
|
118
|
+
sql.query(DESCRIBE_COLUMNS_SQL, [table.oid]),
|
|
119
|
+
sql.query(DESCRIBE_INDEXES_SQL, [table.oid]),
|
|
120
|
+
sql.query(DESCRIBE_CONSTRAINTS_SQL, [table.oid]),
|
|
121
|
+
sql.query(DESCRIBE_SIZES_SQL, [table.oid])
|
|
109
122
|
]);
|
|
110
123
|
const size = sizes[0];
|
|
111
124
|
if (size === void 0) throw new Error(`Table size query returned no row for ${tableName}`);
|
|
@@ -172,12 +185,14 @@ const describeTableAt = async (uri, tableName, signal) => {
|
|
|
172
185
|
formatted: formatTableDescription(description)
|
|
173
186
|
};
|
|
174
187
|
};
|
|
188
|
+
const listTablesOutputSchema = z.array(z.record(z.string(), z.unknown())).describe("One row per table: table_schema, table_name, table_type.");
|
|
175
189
|
const listTablesTool = (options) => bindTool(options, {
|
|
176
190
|
operationId: "schema.listTables",
|
|
177
191
|
id: publishedId("schema.listTables"),
|
|
178
192
|
title: "Get Database Tables",
|
|
179
193
|
description: "Lists a database's tables and views outside the system schemas. For one table's columns, use {{schema.describeTable}}.",
|
|
180
194
|
inputSchema: listTablesInputSchema,
|
|
195
|
+
outputSchema: listTablesOutputSchema,
|
|
181
196
|
annotations: sqlReadAnnotations,
|
|
182
197
|
requiresApproval: false,
|
|
183
198
|
metadata: SQL_METADATA
|
|
@@ -185,12 +200,39 @@ const listTablesTool = (options) => bindTool(options, {
|
|
|
185
200
|
const connection = await resolveConnection(neonClient, input, context, signal);
|
|
186
201
|
return sqlClient(connection.uri, signal).query(LIST_TABLES_SQL);
|
|
187
202
|
});
|
|
203
|
+
const tableSchemaOutputSchema = z.looseObject({
|
|
204
|
+
columns: z.array(z.looseObject({
|
|
205
|
+
name: z.string(),
|
|
206
|
+
type: z.string(),
|
|
207
|
+
nullable: z.boolean(),
|
|
208
|
+
default: z.string().nullable(),
|
|
209
|
+
description: z.string().nullable()
|
|
210
|
+
})),
|
|
211
|
+
indexes: z.array(z.looseObject({
|
|
212
|
+
name: z.string(),
|
|
213
|
+
definition: z.string(),
|
|
214
|
+
size: z.string()
|
|
215
|
+
})),
|
|
216
|
+
constraints: z.array(z.looseObject({
|
|
217
|
+
name: z.string(),
|
|
218
|
+
type: z.string(),
|
|
219
|
+
definition: z.string()
|
|
220
|
+
})),
|
|
221
|
+
tableSize: z.string(),
|
|
222
|
+
indexSize: z.string(),
|
|
223
|
+
totalSize: z.string()
|
|
224
|
+
});
|
|
225
|
+
const describeTableOutputSchema = z.looseObject({
|
|
226
|
+
raw: tableSchemaOutputSchema.describe("Columns, indexes, constraints, and sizes."),
|
|
227
|
+
formatted: z.string().describe("The same, as text.")
|
|
228
|
+
});
|
|
188
229
|
const describeTableTool = (options) => bindTool(options, {
|
|
189
230
|
operationId: "schema.describeTable",
|
|
190
231
|
id: publishedId("schema.describeTable"),
|
|
191
232
|
title: "Describe Table Schema",
|
|
192
233
|
description: "Returns a table's columns, indexes, constraints, and sizes. For every table, use {{schema.listTables}}.",
|
|
193
234
|
inputSchema: describeTableInputSchema,
|
|
235
|
+
outputSchema: describeTableOutputSchema,
|
|
194
236
|
annotations: sqlReadAnnotations,
|
|
195
237
|
requiresApproval: false,
|
|
196
238
|
metadata: SQL_METADATA
|
|
@@ -198,4 +240,4 @@ const describeTableTool = (options) => bindTool(options, {
|
|
|
198
240
|
const connection = await resolveConnection(neonClient, input, context, signal);
|
|
199
241
|
return describeTableAt(connection.uri, input.table_name, signal);
|
|
200
242
|
});
|
|
201
|
-
export { describeTableAt, describeTableInputSchema, describeTableTool, formatTableDescription, listTablesInputSchema, listTablesTool, sqlReadAnnotations };
|
|
243
|
+
export { describeTableAt, describeTableInputSchema, describeTableTool, formatTableDescription, listTablesInputSchema, listTablesTool, sqlReadAnnotations, tableSchemaOutputSchema };
|
|
@@ -39,5 +39,19 @@ export declare const listSlowQueriesTool: (options: ToolClientOptions) => import
|
|
|
39
39
|
};
|
|
40
40
|
}[];
|
|
41
41
|
total_queries_found: number;
|
|
42
|
-
}
|
|
42
|
+
}, z.ZodObject<{
|
|
43
|
+
slow_queries: z.ZodArray<z.ZodObject<{
|
|
44
|
+
query: z.ZodUnknown;
|
|
45
|
+
calls: z.ZodUnknown;
|
|
46
|
+
}, z.core.$loose>>;
|
|
47
|
+
total_queries_found: z.ZodNumber;
|
|
48
|
+
}, z.core.$loose>> & {
|
|
49
|
+
outputSchema: z.ZodObject<{
|
|
50
|
+
slow_queries: z.ZodArray<z.ZodObject<{
|
|
51
|
+
query: z.ZodUnknown;
|
|
52
|
+
calls: z.ZodUnknown;
|
|
53
|
+
}, z.core.$loose>>;
|
|
54
|
+
total_queries_found: z.ZodNumber;
|
|
55
|
+
}, z.core.$loose>;
|
|
56
|
+
};
|
|
43
57
|
//# sourceMappingURL=slow-queries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slow-queries.d.ts","sourceRoot":"","sources":["../../../../src/lib/custom/sql/slow-queries.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,yBAAyB,CAAC;AAWjC,eAAO,MAAM,0BAA0B;;;;;;;kBAarC,CAAC;
|
|
1
|
+
{"version":3,"file":"slow-queries.d.ts","sourceRoot":"","sources":["../../../../src/lib/custom/sql/slow-queries.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,yBAAyB,CAAC;AAWjC,eAAO,MAAM,0BAA0B;;;;;;;kBAarC,CAAC;AAwCH,eAAO,MAAM,mBAAmB,GAAI,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgE5D,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { bindTool, publishedId } from "../../ergonomic/bind.js";
|
|
2
2
|
import { SQL_METADATA, branchIdField, computeIdField, databaseNameField, projectIdField, resolveConnection, sqlClient } from "./connection.js";
|
|
3
|
-
import { NeonClientError } from "@neon/sdk";
|
|
4
3
|
import * as z from "zod";
|
|
4
|
+
import { NeonClientError } from "@neon/sdk";
|
|
5
5
|
// src/lib/custom/sql/slow-queries.ts
|
|
6
6
|
const listSlowQueriesInputSchema = z.strictObject({
|
|
7
7
|
project_id: projectIdField,
|
|
@@ -38,12 +38,20 @@ const SLOW_QUERIES_SQL = `
|
|
|
38
38
|
ORDER BY mean_exec_time DESC
|
|
39
39
|
LIMIT $1;
|
|
40
40
|
`;
|
|
41
|
+
const listSlowQueriesOutputSchema = z.looseObject({
|
|
42
|
+
slow_queries: z.array(z.looseObject({
|
|
43
|
+
query: z.unknown(),
|
|
44
|
+
calls: z.unknown()
|
|
45
|
+
})).describe("pg_stat_statements entries: query, calls, timings in ms, rows, and block and WAL counters."),
|
|
46
|
+
total_queries_found: z.number()
|
|
47
|
+
});
|
|
41
48
|
const listSlowQueriesTool = (options) => bindTool(options, {
|
|
42
49
|
operationId: "queries.listSlow",
|
|
43
50
|
id: publishedId("queries.listSlow"),
|
|
44
51
|
title: "List Slow Queries",
|
|
45
52
|
description: "Lists queries from pg_stat_statements, slowest mean execution time first. For sizes, indexes, locks, cache, bloat, or replication, use {{database.inspect}}.",
|
|
46
53
|
inputSchema: listSlowQueriesInputSchema,
|
|
54
|
+
outputSchema: listSlowQueriesOutputSchema,
|
|
47
55
|
annotations: {
|
|
48
56
|
readOnlyHint: true,
|
|
49
57
|
destructiveHint: false,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type NeonEffectError } from "@neon/effect";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
declare const NeonToolInputError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
4
|
+
readonly _tag: "NeonToolInputError";
|
|
5
|
+
} & Readonly<A>;
|
|
6
|
+
/** The tool input failed its schema. */
|
|
7
|
+
export declare class NeonToolInputError extends NeonToolInputError_base<{
|
|
8
|
+
readonly message: string;
|
|
9
|
+
readonly issues: z.ZodError["issues"];
|
|
10
|
+
/** The `ZodError` the input schema threw. */
|
|
11
|
+
readonly cause: z.ZodError;
|
|
12
|
+
}> {
|
|
13
|
+
}
|
|
14
|
+
declare const NeonSqlError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
15
|
+
readonly _tag: "NeonSqlError";
|
|
16
|
+
} & Readonly<A>;
|
|
17
|
+
/** Postgres rejected the statement. */
|
|
18
|
+
export declare class NeonSqlError extends NeonSqlError_base<{
|
|
19
|
+
readonly message: string;
|
|
20
|
+
/** The SQLSTATE Postgres answered with. */
|
|
21
|
+
readonly code: string;
|
|
22
|
+
readonly position: string | undefined;
|
|
23
|
+
readonly detail: string | undefined;
|
|
24
|
+
readonly hint: string | undefined;
|
|
25
|
+
readonly where: string | undefined;
|
|
26
|
+
/** The driver's `NeonDbError`. */
|
|
27
|
+
readonly cause: Error;
|
|
28
|
+
}> {
|
|
29
|
+
}
|
|
30
|
+
declare const NeonSqlConnectionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
31
|
+
readonly _tag: "NeonSqlConnectionError";
|
|
32
|
+
} & Readonly<A>;
|
|
33
|
+
/** The SQL endpoint failed before Postgres answered, so there is no SQLSTATE. */
|
|
34
|
+
export declare class NeonSqlConnectionError extends NeonSqlConnectionError_base<{
|
|
35
|
+
readonly message: string;
|
|
36
|
+
/** The driver's `NeonDbError`. */
|
|
37
|
+
readonly cause: Error;
|
|
38
|
+
}> {
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Every error an Effect tool can fail with. A cancelled call is an interrupted
|
|
42
|
+
* fiber, so aborts have no counterpart here.
|
|
43
|
+
*/
|
|
44
|
+
export type NeonToolError = NeonEffectError | NeonToolInputError | NeonSqlError | NeonSqlConnectionError;
|
|
45
|
+
/**
|
|
46
|
+
* Map a failure a tool threw to its tagged error. Anything else, including the
|
|
47
|
+
* aborts an interrupted call produces, is rethrown so Effect records a defect.
|
|
48
|
+
*/
|
|
49
|
+
export declare const toNeonToolError: (error: unknown) => NeonToolError;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/lib/effect/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAqB,MAAM,cAAc,CAAC;AAGvE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;;;;AAEzB,wCAAwC;AACxC,qBAAa,kBAAmB,SAAQ,wBAAuC;IAC9E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACtC,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC;CAC3B,CAAC;CAAG;;;;AAEL,uCAAuC;AACvC,qBAAa,YAAa,SAAQ,kBAAiC;IAClE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,kCAAkC;IAClC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACtB,CAAC;CAAG;;;;AAEL,iFAAiF;AACjF,qBAAa,sBAAuB,SAAQ,4BAE1C;IACD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,kCAAkC;IAClC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACtB,CAAC;CAAG;AAEL;;;GAGG;AACH,MAAM,MAAM,aAAa,GACtB,eAAe,GACf,kBAAkB,GAClB,YAAY,GACZ,sBAAsB,CAAC;AAe1B;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,aAYhD,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { toNeonEffectError } from "@neon/effect";
|
|
2
|
+
import { NeonDbError } from "@neondatabase/serverless";
|
|
3
|
+
import { Data } from "effect";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
// src/lib/effect/errors.ts
|
|
6
|
+
/** The tool input failed its schema. */
|
|
7
|
+
var NeonToolInputError = class extends Data.TaggedError("NeonToolInputError") {};
|
|
8
|
+
/** Postgres rejected the statement. */
|
|
9
|
+
var NeonSqlError = class extends Data.TaggedError("NeonSqlError") {};
|
|
10
|
+
/** The SQL endpoint failed before Postgres answered, so there is no SQLSTATE. */
|
|
11
|
+
var NeonSqlConnectionError = class extends Data.TaggedError("NeonSqlConnectionError") {};
|
|
12
|
+
const sqlError = (error) => error.code === void 0 || error.code === "" ? new NeonSqlConnectionError({
|
|
13
|
+
message: error.message,
|
|
14
|
+
cause: error
|
|
15
|
+
}) : new NeonSqlError({
|
|
16
|
+
message: error.message,
|
|
17
|
+
code: error.code,
|
|
18
|
+
position: error.position,
|
|
19
|
+
detail: error.detail,
|
|
20
|
+
hint: error.hint,
|
|
21
|
+
where: error.where,
|
|
22
|
+
cause: error
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Map a failure a tool threw to its tagged error. Anything else, including the
|
|
26
|
+
* aborts an interrupted call produces, is rethrown so Effect records a defect.
|
|
27
|
+
*/
|
|
28
|
+
const toNeonToolError = (error) => {
|
|
29
|
+
if (error instanceof z.ZodError) return new NeonToolInputError({
|
|
30
|
+
message: error.message,
|
|
31
|
+
issues: error.issues,
|
|
32
|
+
cause: error
|
|
33
|
+
});
|
|
34
|
+
if (error instanceof NeonDbError) return sqlError(error);
|
|
35
|
+
return toNeonEffectError(error);
|
|
36
|
+
};
|
|
37
|
+
export { NeonSqlConnectionError, NeonSqlError, NeonToolInputError, toNeonToolError };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Effect, Schedule } from "effect";
|
|
2
|
+
import type { NeonToolAnnotations, NeonToolExecutionContext } from "../operation.js";
|
|
3
|
+
import { type NeonToolError } from "./errors.js";
|
|
4
|
+
/** The tool shape an Effect tool is built from: any Neon tool, customized or not. */
|
|
5
|
+
export interface ExecutableNeonTool<Input = never, Output = unknown> {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly annotations: NeonToolAnnotations;
|
|
8
|
+
execute(input: Input, context?: NeonToolExecutionContext): Promise<Output>;
|
|
9
|
+
}
|
|
10
|
+
/** The execution context of an Effect tool. Interrupting the fiber cancels the call. */
|
|
11
|
+
export type NeonEffectToolContext = Omit<NeonToolExecutionContext, "signal">;
|
|
12
|
+
type ToolInput<Tool> = Tool extends ExecutableNeonTool<infer Input, unknown> ? Input : never;
|
|
13
|
+
type ToolOutput<Tool> = Tool extends ExecutableNeonTool<never, infer Output> ? Output : never;
|
|
14
|
+
/** A Neon tool whose `execute` returns an Effect. Every other field is unchanged. */
|
|
15
|
+
export type NeonEffectTool<Tool extends ExecutableNeonTool, Input = ToolInput<Tool>, Output = ToolOutput<Tool>> = Omit<Tool, "execute"> & {
|
|
16
|
+
readonly execute: (input: Input, context?: NeonEffectToolContext) => Effect.Effect<Output, NeonToolError>;
|
|
17
|
+
};
|
|
18
|
+
export type NeonEffectTools<Tools extends Readonly<Record<string, ExecutableNeonTool>>> = {
|
|
19
|
+
readonly [Id in keyof Tools]: NeonEffectTool<Tools[Id]>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Which failures to retry and how. A policy only ever sees failures of
|
|
23
|
+
* read-only tools that the SDK did not already retry: the adapter never resends
|
|
24
|
+
* a mutation, and leaves 423, 429, and 503 responses to the SDK, which retries
|
|
25
|
+
* them and honours `Retry-After`.
|
|
26
|
+
*/
|
|
27
|
+
export interface NeonToolRetryPolicy {
|
|
28
|
+
readonly schedule: Schedule.Schedule<unknown, NeonToolError>;
|
|
29
|
+
/** Retries after the first attempt. */
|
|
30
|
+
readonly times: number;
|
|
31
|
+
readonly shouldRetry: (failure: {
|
|
32
|
+
readonly tool: ExecutableNeonTool;
|
|
33
|
+
readonly error: NeonToolError;
|
|
34
|
+
}) => boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface EffectToolOptions {
|
|
37
|
+
/** No retries unless set. A retry runs the whole tool again, hooks included. */
|
|
38
|
+
readonly retry?: NeonToolRetryPolicy;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Retries a read-only tool that got no response from the Neon API, twice, with
|
|
42
|
+
* jittered exponential backoff from 200 ms. A read is safe to send again; a
|
|
43
|
+
* mutation that may have reached the API is not, so it is never retried.
|
|
44
|
+
*/
|
|
45
|
+
export declare const retryReadOnlyNetworkFailures: NeonToolRetryPolicy;
|
|
46
|
+
/**
|
|
47
|
+
* Run a Neon tool as an Effect, in a span named `NeonTools.<id>`. The span
|
|
48
|
+
* records `error.type` for every failure but fails only for the server's: a
|
|
49
|
+
* caller's mistake keeps it ok. `neon.tool.attempts` counts the attempts, and
|
|
50
|
+
* `neon.tool.retried_error.type` names the failure a retry recovered from.
|
|
51
|
+
*/
|
|
52
|
+
export declare const toEffectTool: <Input, Output, Tool extends ExecutableNeonTool>(tool: Tool & ExecutableNeonTool<Input, Output>, options?: EffectToolOptions) => NeonEffectTool<Tool, Input, Output>;
|
|
53
|
+
/** Run every tool of a `createNeonTools` result as an Effect. */
|
|
54
|
+
export declare const toEffectTools: <Tools extends Readonly<Record<string, ExecutableNeonTool>>>(tools: Tools, options?: EffectToolOptions) => NeonEffectTools<Tools>;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/lib/effect/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA0B,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,KAAK,EACX,mBAAmB,EACnB,wBAAwB,EACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,aAAa,CAAC;AAElE,qFAAqF;AACrF,MAAM,WAAW,kBAAkB,CAAC,KAAK,GAAG,KAAK,EAAE,MAAM,GAAG,OAAO;IAClE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAC1C,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3E;AAED,wFAAwF;AACxF,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,wBAAwB,EAAE,QAAQ,CAAC,CAAC;AAE7E,KAAK,SAAS,CAAC,IAAI,IAClB,IAAI,SAAS,kBAAkB,CAAC,MAAM,KAAK,EAAE,OAAO,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;AAEvE,KAAK,UAAU,CAAC,IAAI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,KAAK,EAAE,MAAM,EAAE,IAAI,SAAS,kBAAkB,EAC1E,MAAM,IAAI,GAAG,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,EAC9C,UAAS,iBAAsB,KAC7B,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CA+DpC,CAAC;AAEF,iEAAiE;AACjE,eAAO,MAAM,aAAa,GACzB,KAAK,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,EAE1D,OAAO,KAAK,EACZ,UAAS,iBAAsB,KAC7B,eAAe,CAAC,KAAK,CAMI,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { toNeonToolError } from "./errors.js";
|
|
2
|
+
import { Effect, Predicate, Ref, Result, Schedule } from "effect";
|
|
3
|
+
// src/lib/effect/tools.ts
|
|
4
|
+
/**
|
|
5
|
+
* Retries a read-only tool that got no response from the Neon API, twice, with
|
|
6
|
+
* jittered exponential backoff from 200 ms. A read is safe to send again; a
|
|
7
|
+
* mutation that may have reached the API is not, so it is never retried.
|
|
8
|
+
*/
|
|
9
|
+
const retryReadOnlyNetworkFailures = {
|
|
10
|
+
schedule: Schedule.exponential("200 millis").pipe(Schedule.jittered),
|
|
11
|
+
times: 2,
|
|
12
|
+
shouldRetry: ({ error }) => Predicate.isTagged(error, "NeonNetworkError")
|
|
13
|
+
};
|
|
14
|
+
const SDK_RETRIED_STATUSES = /* @__PURE__ */ new Set([
|
|
15
|
+
423,
|
|
16
|
+
429,
|
|
17
|
+
503
|
|
18
|
+
]);
|
|
19
|
+
const sdkRetried = (error) => "status" in error && typeof error.status === "number" && SDK_RETRIED_STATUSES.has(error.status);
|
|
20
|
+
const mayRetry = (tool, error, policy) => tool.annotations.readOnlyHint && !sdkRetried(error) && policy.shouldRetry({
|
|
21
|
+
tool,
|
|
22
|
+
error
|
|
23
|
+
});
|
|
24
|
+
const SERVER_SQLSTATE_CLASSES = /* @__PURE__ */ new Set([
|
|
25
|
+
"08",
|
|
26
|
+
"40",
|
|
27
|
+
"53",
|
|
28
|
+
"55",
|
|
29
|
+
"57",
|
|
30
|
+
"58",
|
|
31
|
+
"F0",
|
|
32
|
+
"XX"
|
|
33
|
+
]);
|
|
34
|
+
const isCallerError = (error) => {
|
|
35
|
+
if (Predicate.isTagged(error, "NeonSqlError")) return !SERVER_SQLSTATE_CLASSES.has(error.code.slice(0, 2));
|
|
36
|
+
return Predicate.isTagged(error, "NeonToolInputError") || "status" in error && typeof error.status === "number" && error.status < 500;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Run a Neon tool as an Effect, in a span named `NeonTools.<id>`. The span
|
|
40
|
+
* records `error.type` for every failure but fails only for the server's: a
|
|
41
|
+
* caller's mistake keeps it ok. `neon.tool.attempts` counts the attempts, and
|
|
42
|
+
* `neon.tool.retried_error.type` names the failure a retry recovered from.
|
|
43
|
+
*/
|
|
44
|
+
const toEffectTool = (tool, options = {}) => {
|
|
45
|
+
const { retry } = options;
|
|
46
|
+
const attempt = (input, context, attempts) => Ref.updateAndGet(attempts, (n) => n + 1).pipe(Effect.flatMap((n) => Effect.annotateCurrentSpan("neon.tool.attempts", n)), Effect.andThen(Effect.tryPromise({
|
|
47
|
+
try: (signal) => tool.execute(input, {
|
|
48
|
+
...context,
|
|
49
|
+
signal
|
|
50
|
+
}),
|
|
51
|
+
catch: toNeonToolError
|
|
52
|
+
})));
|
|
53
|
+
const run = (input, context, attempts) => retry === void 0 ? attempt(input, context, attempts) : attempt(input, context, attempts).pipe(Effect.tapError((error) => mayRetry(tool, error, retry) ? Effect.annotateCurrentSpan("neon.tool.retried_error.type", error._tag) : Effect.void), Effect.retry({
|
|
54
|
+
schedule: retry.schedule,
|
|
55
|
+
times: retry.times,
|
|
56
|
+
while: (error) => mayRetry(tool, error, retry)
|
|
57
|
+
}));
|
|
58
|
+
const execute = (input, context) => Ref.make(0).pipe(Effect.flatMap((attempts) => run(input, context, attempts)), Effect.map(Result.succeed), Effect.tapError((error) => Effect.annotateCurrentSpan("error.type", error._tag)), Effect.catchIf(isCallerError, (error) => Effect.succeed(Result.fail(error))), Effect.withSpan(`NeonTools.${tool.id}`, { attributes: { "neon.tool.id": tool.id } }), Effect.flatMap(Effect.fromResult));
|
|
59
|
+
const { execute: _promiseExecute, ...descriptor } = tool;
|
|
60
|
+
return {
|
|
61
|
+
...descriptor,
|
|
62
|
+
execute
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/** Run every tool of a `createNeonTools` result as an Effect. */
|
|
66
|
+
const toEffectTools = (tools, options = {}) => Object.fromEntries(Object.entries(tools).map(([id, tool]) => [id, toEffectTool(tool, options)]));
|
|
67
|
+
export { retryReadOnlyNetworkFailures, toEffectTool, toEffectTools };
|
|
@@ -38,9 +38,17 @@ export declare const collectObjectList: (neon: NeonClient<true>, input: {
|
|
|
38
38
|
prefix: string;
|
|
39
39
|
}>;
|
|
40
40
|
export declare const collectPages: <T>(list: Paginated<T, true>, maxItems?: number) => Promise<T[]>;
|
|
41
|
-
export declare const bindTool: <const InputSchema extends z.ZodType, const Id extends string, Output>(options: ToolClientOptions, tool: Omit<NeonTool<InputSchema, Id, JsonSafe<Awaited<Output
|
|
41
|
+
export declare const bindTool: <const InputSchema extends z.ZodType, const Id extends string, Output, OutputSchema extends z.ZodType>(options: ToolClientOptions, tool: Omit<NeonTool<InputSchema, Id, JsonSafe<Awaited<Output>>, OutputSchema>, "execute"> & {
|
|
42
|
+
outputSchema: OutputSchema;
|
|
43
|
+
}, run: (neon: NeonClient<true>, input: z.output<InputSchema>, signal: AbortSignal | undefined, context: NeonToolExecutionContext) => Promise<Output>) => NeonTool<InputSchema, Id, JsonSafe<Awaited<Output>>, OutputSchema> & {
|
|
44
|
+
outputSchema: OutputSchema;
|
|
45
|
+
};
|
|
42
46
|
/** A tool that calls no Neon API and so needs no credential. */
|
|
43
|
-
export declare const bindPublicTool: <const InputSchema extends z.ZodType, const Id extends string, Output>(tool: Omit<NeonTool<InputSchema, Id, JsonSafe<Awaited<Output
|
|
47
|
+
export declare const bindPublicTool: <const InputSchema extends z.ZodType, const Id extends string, Output, OutputSchema extends z.ZodType>(tool: Omit<NeonTool<InputSchema, Id, JsonSafe<Awaited<Output>>, OutputSchema>, "execute"> & {
|
|
48
|
+
outputSchema: OutputSchema;
|
|
49
|
+
}, run: (input: z.output<InputSchema>, context: NeonToolExecutionContext) => Promise<Output>) => NeonTool<InputSchema, Id, JsonSafe<Awaited<Output>>, OutputSchema> & {
|
|
50
|
+
outputSchema: OutputSchema;
|
|
51
|
+
};
|
|
44
52
|
type GeneratedTool<G extends NeonOperationId> = ReturnType<(typeof operationFactories)[G]>;
|
|
45
53
|
type GeneratedSchema<G extends NeonOperationId> = GeneratedTool<G>["inputSchema"];
|
|
46
54
|
type GeneratedInput<G extends NeonOperationId> = z.output<GeneratedSchema<G>>;
|
|
@@ -52,16 +60,22 @@ type FromGeneratedMeta = {
|
|
|
52
60
|
};
|
|
53
61
|
type OmittedInput<G extends NeonOperationId, Keys extends string> = Omit<GeneratedInput<G>, Keys>;
|
|
54
62
|
type OmittedArg<G extends NeonOperationId, Keys extends string> = Omit<GeneratedArg<G>, Keys>;
|
|
55
|
-
export declare function fromGenerated<const Id extends NeonToolId, const G extends NeonOperationId, Output>(options: ToolClientOptions, spec: FromGeneratedMeta & {
|
|
63
|
+
export declare function fromGenerated<const Id extends NeonToolId, const G extends NeonOperationId, Output, OutputSchema extends z.ZodType>(options: ToolClientOptions, spec: FromGeneratedMeta & {
|
|
56
64
|
id: Id;
|
|
57
65
|
generated: G;
|
|
66
|
+
output: OutputSchema;
|
|
58
67
|
run: (neon: NeonClient<true>, input: GeneratedInput<G>, signal?: AbortSignal) => Promise<Output>;
|
|
59
|
-
}): NeonTool<GeneratedSchema<G>, PublishedId<Id>, JsonSafe<Awaited<Output
|
|
60
|
-
|
|
68
|
+
}): NeonTool<GeneratedSchema<G>, PublishedId<Id>, JsonSafe<Awaited<Output>>, OutputSchema> & {
|
|
69
|
+
outputSchema: OutputSchema;
|
|
70
|
+
};
|
|
71
|
+
export declare function fromGenerated<const Id extends NeonToolId, const G extends NeonOperationId, const Keys extends keyof GeneratedInput<G> & string, Output, OutputSchema extends z.ZodType>(options: ToolClientOptions, spec: FromGeneratedMeta & {
|
|
61
72
|
id: Id;
|
|
62
73
|
generated: G;
|
|
63
74
|
omit: readonly Keys[];
|
|
75
|
+
output: OutputSchema;
|
|
64
76
|
run: (neon: NeonClient<true>, input: OmittedInput<G, Keys>, signal?: AbortSignal) => Promise<Output>;
|
|
65
|
-
}): NeonTool<z.ZodType<OmittedInput<G, Keys>, OmittedArg<G, Keys>>, PublishedId<Id>, JsonSafe<Awaited<Output
|
|
77
|
+
}): NeonTool<z.ZodType<OmittedInput<G, Keys>, OmittedArg<G, Keys>>, PublishedId<Id>, JsonSafe<Awaited<Output>>, OutputSchema> & {
|
|
78
|
+
outputSchema: OutputSchema;
|
|
79
|
+
};
|
|
66
80
|
export {};
|
|
67
81
|
//# sourceMappingURL=bind.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../../../src/lib/ergonomic/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,UAAU,EAEf,KAAK,UAAU,EACf,KAAK,SAAS,EACd,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,EACN,KAAK,eAAe,EACpB,kBAAkB,EAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEN,KAAK,oBAAoB,EAEzB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACX,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,wBAAwB,EACxB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,WAAW,iBAAiB;IACjC,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC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AAC,CAAC;CACrB,GACC,QAAQ,CACV,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EACrD,WAAW,CAAC,EAAE,CAAC,EACf,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EACzB,YAAY,CACZ,GAAG;IAAE,YAAY,EAAE,YAAY,CAAA;CAAE,CAAC"}
|
|
@@ -2,8 +2,8 @@ import { toolDescriptions } from "../../descriptions.gen.js";
|
|
|
2
2
|
import { missingBearerCredential, requireBearerCredential } from "../auth.js";
|
|
3
3
|
import { toToolResult } from "../result.js";
|
|
4
4
|
import { operationFactories } from "../../operations.gen.js";
|
|
5
|
-
import { NeonClientError, createNeonClient } from "@neon/sdk";
|
|
6
5
|
import * as z from "zod";
|
|
6
|
+
import { NeonClientError, createNeonClient } from "@neon/sdk";
|
|
7
7
|
// src/lib/ergonomic/bind.ts
|
|
8
8
|
const ALL_PAGES = " Returns every page. Pass limit to cap how many.";
|
|
9
9
|
const inertClient = createNeonClient({ apiKey: "unused" }).client;
|
|
@@ -112,6 +112,7 @@ function fromGenerated(options, spec) {
|
|
|
112
112
|
title: generated.title,
|
|
113
113
|
description: spec.list ? `${description.trimEnd()}${ALL_PAGES}` : description,
|
|
114
114
|
inputSchema,
|
|
115
|
+
outputSchema: spec.output,
|
|
115
116
|
annotations: spec.annotations ?? generated.annotations,
|
|
116
117
|
requiresApproval: spec.requiresApproval ?? generated.requiresApproval,
|
|
117
118
|
metadata: generated.metadata,
|