@neon/tools 2.14.4 → 2.16.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.
Files changed (96) hide show
  1. package/README.md +195 -5
  2. package/dist/descriptions.gen.js +2 -2
  3. package/dist/effect.d.ts +22 -0
  4. package/dist/effect.d.ts.map +1 -0
  5. package/dist/effect.js +3 -0
  6. package/dist/generated/output.gen.d.ts +3418 -0
  7. package/dist/generated/output.gen.d.ts.map +1 -0
  8. package/dist/generated/output.gen.js +1498 -0
  9. package/dist/generated/zod.gen.d.ts +3 -3
  10. package/dist/index.d.ts +17 -5
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +30 -9
  13. package/dist/lib/custom/auth-config.d.ts +63 -2
  14. package/dist/lib/custom/auth-config.d.ts.map +1 -1
  15. package/dist/lib/custom/auth-config.js +34 -7
  16. package/dist/lib/custom/docs.d.ts +32 -2
  17. package/dist/lib/custom/docs.d.ts.map +1 -1
  18. package/dist/lib/custom/docs.js +18 -1
  19. package/dist/lib/custom/feedback.d.ts +7 -2
  20. package/dist/lib/custom/feedback.d.ts.map +1 -1
  21. package/dist/lib/custom/feedback.js +3 -0
  22. package/dist/lib/custom/fetch.d.ts +15 -1
  23. package/dist/lib/custom/fetch.d.ts.map +1 -1
  24. package/dist/lib/custom/fetch.js +10 -1
  25. package/dist/lib/custom/organizations.d.ts +23 -1
  26. package/dist/lib/custom/organizations.d.ts.map +1 -1
  27. package/dist/lib/custom/organizations.js +3 -0
  28. package/dist/lib/custom/resources.d.ts +15 -1
  29. package/dist/lib/custom/resources.d.ts.map +1 -1
  30. package/dist/lib/custom/resources.js +8 -1
  31. package/dist/lib/custom/sql/connection.d.ts +6 -7
  32. package/dist/lib/custom/sql/connection.d.ts.map +1 -1
  33. package/dist/lib/custom/sql/connection.js +10 -12
  34. package/dist/lib/custom/sql/describe-branch.d.ts +99 -1
  35. package/dist/lib/custom/sql/describe-branch.d.ts.map +1 -1
  36. package/dist/lib/custom/sql/describe-branch.js +11 -2
  37. package/dist/lib/custom/sql/inspect/inspect.d.ts +27 -1
  38. package/dist/lib/custom/sql/inspect/inspect.d.ts.map +1 -1
  39. package/dist/lib/custom/sql/inspect/inspect.js +17 -3
  40. package/dist/lib/custom/sql/migrations.d.ts +46 -2
  41. package/dist/lib/custom/sql/migrations.d.ts.map +1 -1
  42. package/dist/lib/custom/sql/migrations.js +29 -7
  43. package/dist/lib/custom/sql/query-tuning.d.ts +90 -2
  44. package/dist/lib/custom/sql/query-tuning.d.ts.map +1 -1
  45. package/dist/lib/custom/sql/query-tuning.js +31 -8
  46. package/dist/lib/custom/sql/run.d.ts +30 -3
  47. package/dist/lib/custom/sql/run.d.ts.map +1 -1
  48. package/dist/lib/custom/sql/run.js +15 -6
  49. package/dist/lib/custom/sql/schema.d.ts +76 -2
  50. package/dist/lib/custom/sql/schema.d.ts.map +1 -1
  51. package/dist/lib/custom/sql/schema.js +34 -5
  52. package/dist/lib/custom/sql/slow-queries.d.ts +15 -1
  53. package/dist/lib/custom/sql/slow-queries.d.ts.map +1 -1
  54. package/dist/lib/custom/sql/slow-queries.js +11 -3
  55. package/dist/lib/customize.d.ts +1 -1
  56. package/dist/lib/customize.d.ts.map +1 -1
  57. package/dist/lib/customize.js +8 -4
  58. package/dist/lib/effect/errors.d.ts +51 -0
  59. package/dist/lib/effect/errors.d.ts.map +1 -0
  60. package/dist/lib/effect/errors.js +37 -0
  61. package/dist/lib/effect/tools.d.ts +56 -0
  62. package/dist/lib/effect/tools.d.ts.map +1 -0
  63. package/dist/lib/effect/tools.js +67 -0
  64. package/dist/lib/ergonomic/bind.d.ts +25 -7
  65. package/dist/lib/ergonomic/bind.d.ts.map +1 -1
  66. package/dist/lib/ergonomic/bind.js +13 -3
  67. package/dist/lib/ergonomic/catalog.d.ts +5335 -180
  68. package/dist/lib/ergonomic/catalog.d.ts.map +1 -1
  69. package/dist/lib/ergonomic/catalog.js +286 -23
  70. package/dist/lib/ergonomic/composed.d.ts +866 -12
  71. package/dist/lib/ergonomic/composed.d.ts.map +1 -1
  72. package/dist/lib/ergonomic/composed.js +63 -0
  73. package/dist/lib/mcp-json-schema.d.ts +20 -0
  74. package/dist/lib/mcp-json-schema.d.ts.map +1 -1
  75. package/dist/lib/mcp-json-schema.js +89 -1
  76. package/dist/lib/mcp-register.d.ts +1 -1
  77. package/dist/lib/mcp-register.d.ts.map +1 -1
  78. package/dist/lib/mcp-register.js +2 -1
  79. package/dist/lib/operation.d.ts +56 -5
  80. package/dist/lib/operation.d.ts.map +1 -1
  81. package/dist/lib/operation.js +6 -1
  82. package/dist/lib/policy.d.ts +24 -0
  83. package/dist/lib/policy.d.ts.map +1 -0
  84. package/dist/lib/policy.js +49 -0
  85. package/dist/lib/redact.d.ts +8 -0
  86. package/dist/lib/redact.d.ts.map +1 -0
  87. package/dist/lib/redact.js +40 -0
  88. package/dist/mastra.d.ts +2 -1
  89. package/dist/mastra.d.ts.map +1 -1
  90. package/dist/mcp-v1.d.ts.map +1 -1
  91. package/dist/mcp-v1.js +3 -1
  92. package/dist/mcp.d.ts +3 -3
  93. package/dist/mcp.d.ts.map +1 -1
  94. package/dist/mcp.js +3 -3
  95. package/dist/operations.gen.d.ts +194 -194
  96. package/package.json +21 -2
@@ -1,12 +1,12 @@
1
1
  import { pathInputDescriptions } from "../../../descriptions.gen.js";
2
2
  import { bindTool, publishedId } from "../../ergonomic/bind.js";
3
- import { SQL_METADATA, projectIdField, refuseInReadOnly, resolveConnection } from "./connection.js";
4
- import { describeTableAt } from "./schema.js";
5
- import { explainStatement, runTransaction, sqlWriteAnnotations } from "./run.js";
3
+ import { projectIdField, resolveConnection, sqlMetadata } from "./connection.js";
4
+ import { describeTableAt, tableSchemaOutputSchema } from "./schema.js";
5
+ import { explainStatement, runTransaction, sqlRowsOutputSchema, sqlWriteAnnotations } from "./run.js";
6
6
  import { withTemporaryBranch } from "./migrations.js";
7
7
  import { extractExecutionMetrics, extractTablesFromPlan } from "./plan.js";
8
- import { NeonClientError } from "@neon/sdk";
9
8
  import * as z from "zod";
9
+ import { NeonClientError } from "@neon/sdk";
10
10
  import { randomUUID } from "node:crypto";
11
11
  // src/lib/custom/sql/query-tuning.ts
12
12
  const prepareQueryTuningInputSchema = z.strictObject({
@@ -26,12 +26,30 @@ const completeQueryTuningInputSchema = z.strictObject({
26
26
  temporary_branch_id: z.string().describe("The temporary_branch_id from {{queryTuning.prepare}}."),
27
27
  branch_id: z.string().optional().describe(`${pathInputDescriptions.branch_id} The branch that receives the changes; omit it for the default branch.`)
28
28
  });
29
+ const prepareQueryTuningOutputSchema = z.looseObject({
30
+ complete: z.looseObject({
31
+ tuning_id: z.string(),
32
+ database_name: z.string(),
33
+ project_id: z.string(),
34
+ temporary_branch_id: z.string(),
35
+ role_name: z.string().nullish()
36
+ }).describe("The values that apply or discard the tuning."),
37
+ execution_plan: sqlRowsOutputSchema.describe("EXPLAIN ANALYZE output."),
38
+ table_schemas: z.array(z.looseObject({
39
+ tableName: z.string(),
40
+ schema: tableSchemaOutputSchema,
41
+ formatted: z.string()
42
+ })).describe("Schemas of the tables the query reads."),
43
+ sql: z.string(),
44
+ baseline_metrics: z.looseObject({}).describe("Execution and planning time, cost, rows, and buffer usage.")
45
+ });
29
46
  const prepareQueryTuningTool = (options) => bindTool(options, {
30
47
  operationId: "queryTuning.prepare",
31
48
  id: publishedId("queryTuning.prepare"),
32
49
  title: "Prepare Query Tuning",
33
50
  description: "Runs EXPLAIN ANALYZE for a slow query on a new temporary branch; returns the plan, table schemas, and a tuning_id. Try changes there with {{sql.run}} and {{sql.explain}}, then always call {{queryTuning.complete}} with the complete object so the branch is deleted. Not {{migrations.prepare}}.",
34
51
  inputSchema: prepareQueryTuningInputSchema,
52
+ outputSchema: prepareQueryTuningOutputSchema,
35
53
  annotations: {
36
54
  readOnlyHint: false,
37
55
  destructiveHint: false,
@@ -39,9 +57,8 @@ const prepareQueryTuningTool = (options) => bindTool(options, {
39
57
  openWorldHint: false
40
58
  },
41
59
  requiresApproval: true,
42
- metadata: SQL_METADATA
60
+ metadata: sqlMetadata(false)
43
61
  }, async (neonClient, input, signal, context) => {
44
- refuseInReadOnly(context);
45
62
  const projectId = input.project_id;
46
63
  return withTemporaryBranch(neonClient, projectId, void 0, signal, async (branch) => {
47
64
  const target = {
@@ -88,17 +105,23 @@ const prepareQueryTuningTool = (options) => bindTool(options, {
88
105
  };
89
106
  });
90
107
  });
108
+ const completeQueryTuningOutputSchema = z.looseObject({
109
+ message: z.string().describe("What ran, one step per line."),
110
+ appliedChanges: z.array(z.string()).nullish(),
111
+ results: z.array(sqlRowsOutputSchema).nullish(),
112
+ deletedBranches: z.array(z.string()).nullish()
113
+ });
91
114
  const completeQueryTuningTool = (options) => bindTool(options, {
92
115
  operationId: "queryTuning.complete",
93
116
  id: publishedId("queryTuning.complete"),
94
117
  title: "Complete Query Tuning",
95
118
  description: "Applies or discards query-tuning changes and deletes the temporary branch. NEVER run autonomously. Pass the complete object from {{queryTuning.prepare}} and suggested_sql_statements; apply_changes true applies, omitted discards. Call it even when the user rejects.",
96
119
  inputSchema: completeQueryTuningInputSchema,
120
+ outputSchema: completeQueryTuningOutputSchema,
97
121
  annotations: sqlWriteAnnotations,
98
122
  requiresApproval: true,
99
- metadata: SQL_METADATA
123
+ metadata: sqlMetadata(false)
100
124
  }, async (neonClient, input, signal, context) => {
101
- refuseInReadOnly(context);
102
125
  const operationLog = [];
103
126
  let results;
104
127
  if (input.apply_changes && input.suggested_sql_statements.length > 0) {
@@ -37,6 +37,7 @@ export declare const explainStatement: (neonClient: NeonClient<true>, input: {
37
37
  sql: string;
38
38
  analyze: boolean;
39
39
  } & ConnectionTarget, context: NeonToolExecutionContext, signal?: AbortSignal) => Promise<Row[]>;
40
+ export declare const sqlRowsOutputSchema: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
40
41
  export declare const runSqlTool: (options: ToolClientOptions) => import("../../operation.js").NeonTool<z.ZodObject<{
41
42
  sql: z.ZodString;
42
43
  project_id: z.ZodString;
@@ -52,7 +53,19 @@ export declare const runSqlTool: (options: ToolClientOptions) => import("../../o
52
53
  totalRowCount: number;
53
54
  truncated: boolean;
54
55
  note?: string | null | undefined;
55
- }>;
56
+ }, z.ZodObject<{
57
+ rows: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
58
+ totalRowCount: z.ZodNumber;
59
+ truncated: z.ZodBoolean;
60
+ note: z.ZodOptional<z.ZodNullable<z.ZodString>>;
61
+ }, z.core.$loose>> & {
62
+ outputSchema: z.ZodObject<{
63
+ rows: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
64
+ totalRowCount: z.ZodNumber;
65
+ truncated: z.ZodBoolean;
66
+ note: z.ZodOptional<z.ZodNullable<z.ZodString>>;
67
+ }, z.core.$loose>;
68
+ };
56
69
  export declare const runSqlTransactionTool: (options: ToolClientOptions) => import("../../operation.js").NeonTool<z.ZodObject<{
57
70
  sql_statements: z.ZodArray<z.ZodString>;
58
71
  project_id: z.ZodString;
@@ -68,7 +81,19 @@ export declare const runSqlTransactionTool: (options: ToolClientOptions) => impo
68
81
  totalRowCount: number;
69
82
  truncated: boolean;
70
83
  note?: string | null | undefined;
71
- }[]>;
84
+ }[], z.ZodArray<z.ZodObject<{
85
+ rows: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
86
+ totalRowCount: z.ZodNumber;
87
+ truncated: z.ZodBoolean;
88
+ note: z.ZodOptional<z.ZodNullable<z.ZodString>>;
89
+ }, z.core.$loose>>> & {
90
+ outputSchema: z.ZodArray<z.ZodObject<{
91
+ rows: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
92
+ totalRowCount: z.ZodNumber;
93
+ truncated: z.ZodBoolean;
94
+ note: z.ZodOptional<z.ZodNullable<z.ZodString>>;
95
+ }, z.core.$loose>>;
96
+ };
72
97
  export declare const explainSqlTool: (options: ToolClientOptions) => import("../../operation.js").NeonTool<z.ZodObject<{
73
98
  sql: z.ZodString;
74
99
  project_id: z.ZodString;
@@ -77,5 +102,7 @@ export declare const explainSqlTool: (options: ToolClientOptions) => import("../
77
102
  analyze: z.ZodDefault<z.ZodBoolean>;
78
103
  }, z.core.$strict>, "explain_sql", {
79
104
  [x: string]: unknown;
80
- }[]>;
105
+ }[], z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>> & {
106
+ outputSchema: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
107
+ };
81
108
  //# sourceMappingURL=run.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../../src/lib/custom/sql/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EACX,mBAAmB,EACnB,wBAAwB,EACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEN,KAAK,gBAAgB,EASrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEN,KAAK,GAAG,EAGR,MAAM,WAAW,CAAC;AAEnB,eAAO,MAAM,mBAAmB,EAAE,mBAKjC,CAAC;AAYF,eAAO,MAAM,iBAAiB;;;;;;;;kBAQ5B,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;;;;;;kBAUvC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;kBAWhC,CAAC;AAEH,uFAAuF;AACvF,eAAO,MAAM,YAAY,GACxB,YAAY,UAAU,CAAC,IAAI,CAAC,EAC5B,QAAQ,gBAAgB,EACxB,KAAK,MAAM,EACX,SAAS,wBAAwB,EACjC,SAAS,WAAW,KAClB,OAAO,CAAC,GAAG,EAAE,CAef,CAAC;AAEF,eAAO,MAAM,cAAc,GAC1B,YAAY,UAAU,CAAC,IAAI,CAAC,EAC5B,QAAQ,gB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AAM,YAAY,GACxB,YAAY,UAAU,CAAC,IAAI,CAAC,EAC5B,QAAQ,gBAAgB,EACxB,KAAK,MAAM,EACX,SAAS,wBAAwB,EACjC,SAAS,WAAW,KAClB,OAAO,CAAC,GAAG,EAAE,CAef,CAAC;AAEF,eAAO,MAAM,cAAc,GAC1B,YAAY,UAAU,CAAC,IAAI,CAAC,EAC5B,QAAQ,gBAAgB,EACxB,YAAY,SAAS,MAAM,EAAE,EAC7B,SAAS,wBAAwB,EACjC,SAAS,WAAW,KAClB,OAAO,CAAC,GAAG,EAAE,EAAE,CAWjB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC5B,YAAY,UAAU,CAAC,IAAI,CAAC,EAC5B,OAAO;IACN,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;CACjB,GAAG,gBAAgB,EACpB,SAAS,wBAAwB,EACjC,SAAS,WAAW,KAClB,OAAO,CAAC,GAAG,EAAE,CAWf,CAAC;AAEF,eAAO,MAAM,mBAAmB,oDAA6C,CAAC;AAW9E,eAAO,MAAM,UAAU,GAAI,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BnD,CAAC;AAEH,eAAO,MAAM,qBAAqB,GAAI,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyB9D,CAAC;AAEH,eAAO,MAAM,cAAc,GAAI,SAAS,iBAAiB;;;;;;;;;;CAiBvD,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { bindTool, publishedId } from "../../ergonomic/bind.js";
2
- import { SQL_METADATA, branchIdField, computeIdField, databaseNameField, projectIdField, refuseInReadOnly, resolveConnection, roleNameField, sqlClient } from "./connection.js";
2
+ import { branchIdField, computeIdField, databaseNameField, projectIdField, resolveConnection, roleNameField, sqlClient, sqlMetadata } from "./connection.js";
3
3
  import { SQL_MAX_ROWS_LIMIT, capRows } from "./rows.js";
4
4
  import * as z from "zod";
5
5
  // src/lib/custom/sql/run.ts
@@ -54,15 +54,23 @@ const explainStatement = (neonClient, input, context, signal) => {
54
54
  const prefix = input.analyze ? "EXPLAIN (ANALYZE, VERBOSE, BUFFERS, FILECACHE, FORMAT JSON)" : "EXPLAIN (VERBOSE, FORMAT JSON)";
55
55
  return runStatement(neonClient, input, `${prefix} ${input.sql}`, context, signal);
56
56
  };
57
+ const sqlRowsOutputSchema = z.array(z.record(z.string(), z.unknown()));
58
+ const sqlResultOutputSchema = z.looseObject({
59
+ rows: sqlRowsOutputSchema.describe("Result rows, keyed by column name."),
60
+ totalRowCount: z.number().describe("Rows the statement returned."),
61
+ truncated: z.boolean().describe("Whether rows holds fewer than totalRowCount."),
62
+ note: z.string().nullish()
63
+ });
57
64
  const runSqlTool = (options) => bindTool(options, {
58
65
  operationId: "sql.run",
59
66
  id: publishedId("sql.run"),
60
67
  title: "Run SQL",
61
68
  description: "Runs one SQL statement on a branch's database and returns its rows. After a prepare step, pass its temporary branch_id. NEVER run destructive SQL autonomously; always ask the user first.",
62
69
  inputSchema: runSqlInputSchema,
70
+ outputSchema: sqlResultOutputSchema,
63
71
  annotations: sqlWriteAnnotations,
64
72
  requiresApproval: true,
65
- metadata: SQL_METADATA
73
+ metadata: sqlMetadata(true)
66
74
  }, async (neonClient, input, signal, context) => capRows(await runStatement(neonClient, input, input.sql, context, signal), input.max_rows));
67
75
  const runSqlTransactionTool = (options) => bindTool(options, {
68
76
  operationId: "sql.runTransaction",
@@ -70,11 +78,11 @@ const runSqlTransactionTool = (options) => bindTool(options, {
70
78
  title: "Run SQL Transaction",
71
79
  description: "Runs several SQL statements in one transaction and returns each one's rows. After a prepare step, pass its temporary branch_id. NEVER run destructive SQL autonomously; always ask the user first.",
72
80
  inputSchema: runSqlTransactionInputSchema,
81
+ outputSchema: z.array(sqlResultOutputSchema),
73
82
  annotations: sqlWriteAnnotations,
74
83
  requiresApproval: true,
75
- metadata: SQL_METADATA
84
+ metadata: sqlMetadata(false)
76
85
  }, async (neonClient, input, signal, context) => {
77
- refuseInReadOnly(context);
78
86
  return (await runTransaction(neonClient, input, input.sql_statements, context, signal)).map((rows) => capRows(rows, input.max_rows));
79
87
  });
80
88
  const explainSqlTool = (options) => bindTool(options, {
@@ -83,8 +91,9 @@ const explainSqlTool = (options) => bindTool(options, {
83
91
  title: "Explain SQL Statement",
84
92
  description: "Returns a statement's execution plan as JSON. analyze true executes it, side effects included, so never analyze potentially destructive SQL autonomously. For rows, use {{sql.run}}.",
85
93
  inputSchema: explainSqlInputSchema,
94
+ outputSchema: sqlRowsOutputSchema,
86
95
  annotations: sqlWriteAnnotations,
87
96
  requiresApproval: true,
88
- metadata: SQL_METADATA
97
+ metadata: sqlMetadata(true)
89
98
  }, (neonClient, input, signal, context) => explainStatement(neonClient, input, context, signal));
90
- export { explainSqlInputSchema, explainSqlTool, explainStatement, runSqlInputSchema, runSqlTool, runSqlTransactionInputSchema, runSqlTransactionTool, runStatement, runTransaction, sqlWriteAnnotations };
99
+ export { explainSqlInputSchema, explainSqlTool, explainStatement, runSqlInputSchema, runSqlTool, runSqlTransactionInputSchema, runSqlTransactionTool, runStatement, runTransaction, sqlRowsOutputSchema, sqlWriteAnnotations };
@@ -49,7 +49,31 @@ export declare const listTablesTool: (options: ToolClientOptions) => import("../
49
49
  database_name: z.ZodOptional<z.ZodString>;
50
50
  }, z.core.$strict>, "list_tables_schema", {
51
51
  [x: string]: unknown;
52
- }[]>;
52
+ }[], z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>> & {
53
+ outputSchema: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
54
+ };
55
+ export declare const tableSchemaOutputSchema: z.ZodObject<{
56
+ columns: z.ZodArray<z.ZodObject<{
57
+ name: z.ZodString;
58
+ type: z.ZodString;
59
+ nullable: z.ZodBoolean;
60
+ default: z.ZodNullable<z.ZodString>;
61
+ description: z.ZodNullable<z.ZodString>;
62
+ }, z.core.$loose>>;
63
+ indexes: z.ZodArray<z.ZodObject<{
64
+ name: z.ZodString;
65
+ definition: z.ZodString;
66
+ size: z.ZodString;
67
+ }, z.core.$loose>>;
68
+ constraints: z.ZodArray<z.ZodObject<{
69
+ name: z.ZodString;
70
+ type: z.ZodString;
71
+ definition: z.ZodString;
72
+ }, z.core.$loose>>;
73
+ tableSize: z.ZodString;
74
+ indexSize: z.ZodString;
75
+ totalSize: z.ZodString;
76
+ }, z.core.$loose>;
53
77
  export declare const describeTableTool: (options: ToolClientOptions) => import("../../operation.js").NeonTool<z.ZodObject<{
54
78
  table_name: z.ZodString;
55
79
  project_id: z.ZodString;
@@ -79,6 +103,56 @@ export declare const describeTableTool: (options: ToolClientOptions) => import("
79
103
  totalSize: string;
80
104
  };
81
105
  formatted: string;
82
- }>;
106
+ }, z.ZodObject<{
107
+ raw: z.ZodObject<{
108
+ columns: z.ZodArray<z.ZodObject<{
109
+ name: z.ZodString;
110
+ type: z.ZodString;
111
+ nullable: z.ZodBoolean;
112
+ default: z.ZodNullable<z.ZodString>;
113
+ description: z.ZodNullable<z.ZodString>;
114
+ }, z.core.$loose>>;
115
+ indexes: z.ZodArray<z.ZodObject<{
116
+ name: z.ZodString;
117
+ definition: z.ZodString;
118
+ size: z.ZodString;
119
+ }, z.core.$loose>>;
120
+ constraints: z.ZodArray<z.ZodObject<{
121
+ name: z.ZodString;
122
+ type: z.ZodString;
123
+ definition: z.ZodString;
124
+ }, z.core.$loose>>;
125
+ tableSize: z.ZodString;
126
+ indexSize: z.ZodString;
127
+ totalSize: z.ZodString;
128
+ }, z.core.$loose>;
129
+ formatted: z.ZodString;
130
+ }, z.core.$loose>> & {
131
+ outputSchema: z.ZodObject<{
132
+ raw: z.ZodObject<{
133
+ columns: z.ZodArray<z.ZodObject<{
134
+ name: z.ZodString;
135
+ type: z.ZodString;
136
+ nullable: z.ZodBoolean;
137
+ default: z.ZodNullable<z.ZodString>;
138
+ description: z.ZodNullable<z.ZodString>;
139
+ }, z.core.$loose>>;
140
+ indexes: z.ZodArray<z.ZodObject<{
141
+ name: z.ZodString;
142
+ definition: z.ZodString;
143
+ size: z.ZodString;
144
+ }, z.core.$loose>>;
145
+ constraints: z.ZodArray<z.ZodObject<{
146
+ name: z.ZodString;
147
+ type: z.ZodString;
148
+ definition: z.ZodString;
149
+ }, z.core.$loose>>;
150
+ tableSize: z.ZodString;
151
+ indexSize: z.ZodString;
152
+ totalSize: z.ZodString;
153
+ }, z.core.$loose>;
154
+ formatted: z.ZodString;
155
+ }, z.core.$loose>;
156
+ };
83
157
  export {};
84
158
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/lib/custom/sql/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAU9D,eAAO,MAAM,kBAAkB,EAAE,mBAKhC,CAAC;AAEF,eAAO,MAAM,qBAAqB;;;;kBAIhC,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;kBASnC,CAAC;AAyGH,UAAU,iBAAiB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,UAAU,gBAAgB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,UAAU,qBAAqB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,OAAO,EAAE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AI,CAAC;CAC3B;AAED,UAAU,gBAAgB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,UAAU,qBAAqB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,WAAW,EAAE,qBAAqB,EAAE,CAAC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CAClB;AAmDD,eAAO,MAAM,sBAAsB,GAAI,MAAM,gBAAgB,KAAG,MAmC/D,CAAC;AAEF,eAAO,MAAM,eAAe,GAC3B,KAAK,MAAM,EACX,WAAW,MAAM,EACjB,SAAS,WAAW;;;EAUpB,CAAC;AAMF,eAAO,MAAM,cAAc,GAAI,SAAS,iBAAiB;;;;;;;;CAwBvD,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;iBA2BlC,CAAC;AASH,eAAO,MAAM,iBAAiB,GAAI,SAAS,iBAAiB;;;;;;;;kBAnMrD,MAAM;kBACN,MAAM;sBACF,OAAO;qBACR,MAAM,GAAG,IAAI;yBACT,MAAM,GAAG,IAAI;;;kBAIpB,MAAM;wBACA,MAAM;kBACZ,MAAM;;;kBAIN,MAAM;kBACN,MAAM;wBACA,MAAM;;mBAOP,MAAM;mBACN,MAAM;mBACN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkMhB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { bindTool, publishedId } from "../../ergonomic/bind.js";
2
- import { SQL_METADATA, branchIdField, databaseNameField, projectIdField, resolveConnection, sqlClient } from "./connection.js";
3
- import { NeonClientError } from "@neon/sdk";
2
+ import { branchIdField, databaseNameField, projectIdField, resolveConnection, sqlClient, sqlMetadata } from "./connection.js";
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,
@@ -185,30 +185,59 @@ const describeTableAt = async (uri, tableName, signal) => {
185
185
  formatted: formatTableDescription(description)
186
186
  };
187
187
  };
188
+ const listTablesOutputSchema = z.array(z.record(z.string(), z.unknown())).describe("One row per table: table_schema, table_name, table_type.");
188
189
  const listTablesTool = (options) => bindTool(options, {
189
190
  operationId: "schema.listTables",
190
191
  id: publishedId("schema.listTables"),
191
192
  title: "Get Database Tables",
192
193
  description: "Lists a database's tables and views outside the system schemas. For one table's columns, use {{schema.describeTable}}.",
193
194
  inputSchema: listTablesInputSchema,
195
+ outputSchema: listTablesOutputSchema,
194
196
  annotations: sqlReadAnnotations,
195
197
  requiresApproval: false,
196
- metadata: SQL_METADATA
198
+ metadata: sqlMetadata(true)
197
199
  }, async (neonClient, input, signal, context) => {
198
200
  const connection = await resolveConnection(neonClient, input, context, signal);
199
201
  return sqlClient(connection.uri, signal).query(LIST_TABLES_SQL);
200
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
+ });
201
229
  const describeTableTool = (options) => bindTool(options, {
202
230
  operationId: "schema.describeTable",
203
231
  id: publishedId("schema.describeTable"),
204
232
  title: "Describe Table Schema",
205
233
  description: "Returns a table's columns, indexes, constraints, and sizes. For every table, use {{schema.listTables}}.",
206
234
  inputSchema: describeTableInputSchema,
235
+ outputSchema: describeTableOutputSchema,
207
236
  annotations: sqlReadAnnotations,
208
237
  requiresApproval: false,
209
- metadata: SQL_METADATA
238
+ metadata: sqlMetadata(true)
210
239
  }, async (neonClient, input, signal, context) => {
211
240
  const connection = await resolveConnection(neonClient, input, context, signal);
212
241
  return describeTableAt(connection.uri, input.table_name, signal);
213
242
  });
214
- 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;AA+BH,eAAO,MAAM,mBAAmB,GAAI,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+D5D,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
- import { SQL_METADATA, branchIdField, computeIdField, databaseNameField, projectIdField, resolveConnection, sqlClient } from "./connection.js";
3
- import { NeonClientError } from "@neon/sdk";
2
+ import { branchIdField, computeIdField, databaseNameField, projectIdField, resolveConnection, sqlClient, sqlMetadata } from "./connection.js";
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,
@@ -51,7 +59,7 @@ const listSlowQueriesTool = (options) => bindTool(options, {
51
59
  openWorldHint: false
52
60
  },
53
61
  requiresApproval: false,
54
- metadata: SQL_METADATA
62
+ metadata: sqlMetadata(true)
55
63
  }, async (neonClient, input, signal, context) => {
56
64
  const connection = await resolveConnection(neonClient, input, context, signal);
57
65
  const sql = sqlClient(connection.uri, signal);
@@ -50,7 +50,7 @@ export declare const assertToolCustomizeOptions: (options: NeonToolCustomizeOpti
50
50
  * run once per selected tool. A reference to a tool that is not selected
51
51
  * resolves to its default id without calling them.
52
52
  */
53
- export declare const applyToolCustomization: <Tool extends NeonTool>(tool: Tool, options: NeonToolCustomizeOptions, publishedIds: ReadonlyMap<string, string>) => Omit<Tool, "id"> & {
53
+ export declare const applyToolCustomization: <Tool extends NeonTool>(tool: Tool, options: NeonToolCustomizeOptions, publishedIds: ReadonlyMap<string, string>, guard?: (context?: NeonToolExecutionContext) => void) => Omit<Tool, "id"> & {
54
54
  id: string;
55
55
  };
56
56
  /** Applies `names`, then `name`, to a tool's default id. Call it once per selected tool. */
@@ -1 +1 @@
1
- {"version":3,"file":"customize.d.ts","sourceRoot":"","sources":["../../src/lib/customize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,KAAK,EACX,QAAQ,EACR,wBAAwB,EACxB,cAAc,EACd,MAAM,gBAAgB,CAAC;AAOxB,MAAM,MAAM,mBAAmB,GAC5B,MAAM,GACN,CAAC,MAAM,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC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,EAAE,SAAS,CAAC,GAAG;IACxB,OAAO,CACN,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAClD,OAAO,CAAC,EAAE,wBAAwB,GAChC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;CACnC,GACA,IAAI,CAAC;AAsBT,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,GAAG,CAAC,MAAM,CACU,CAAC;AAEvE,eAAO,MAAM,0BAA0B,GACtC,SAAS,wBAAwB,KAC/B,IAgBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GAAI,IAAI,SAAS,QAAQ,EAC3D,MAAM,IAAI,EACV,SAAS,wBAAwB,EACjC,cAAc,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,QAAQ,CAAC,OAAO,CAAC,EAAE,wBAAwB,KAAK,IAAI,KAClD,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CA4CjC,CAAC;AAEF,4FAA4F;AAC5F,wBAAgB,eAAe,CAC9B,IAAI,EAAE,kBAAkB,EACxB,OAAO,EAAE,wBAAwB,GAC/B,MAAM,CA8BR"}
@@ -18,7 +18,7 @@ const assertToolCustomizeOptions = (options) => {
18
18
  * run once per selected tool. A reference to a tool that is not selected
19
19
  * resolves to its default id without calling them.
20
20
  */
21
- const applyToolCustomization = (tool, options, publishedIds) => {
21
+ const applyToolCustomization = (tool, options, publishedIds, guard) => {
22
22
  const inject = resolveInject(options.inject);
23
23
  const id = publishedIds.get(tool.operationId);
24
24
  if (id === void 0) throw new TypeError(`No published id for ${tool.operationId}`);
@@ -38,7 +38,7 @@ const applyToolCustomization = (tool, options, publishedIds) => {
38
38
  execute: wrapExecute ? wrapToolExecute({
39
39
  ...tool,
40
40
  id
41
- }, options.onExecute, inject) : tool.execute
41
+ }, options.onExecute, inject, guard) : tool.execute
42
42
  };
43
43
  };
44
44
  /** Applies `names`, then `name`, to a tool's default id. Call it once per selected tool. */
@@ -103,12 +103,16 @@ function applyDescription(tool, descriptions) {
103
103
  if (typeof description !== "string") throw new TypeError("Neon tool description overrides must be strings");
104
104
  return description;
105
105
  }
106
- function wrapToolExecute(tool, onExecute, inject) {
106
+ /** `guard` runs before injected ids resolve, so a refused call never resolves them. */
107
+ function wrapToolExecute(tool, onExecute, inject, guard) {
107
108
  const originalExecute = tool.execute.bind(tool);
108
109
  const availableKeys = pathTemplateParams(tool.metadata.path);
109
110
  const mode = inject.omitFromSchema ? "override" : "fill";
110
111
  return async (input, context) => {
111
- const run = async () => originalExecute(mergeFields(input, await resolveInjectedFields(input, inject, availableKeys, mode), mode), context);
112
+ const run = async () => {
113
+ guard?.(context);
114
+ return originalExecute(mergeFields(input, await resolveInjectedFields(input, inject, availableKeys, mode), mode), context);
115
+ };
112
116
  if (onExecute === void 0) return run();
113
117
  return onExecute({
114
118
  operationId: tool.operationId,
@@ -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 };