@neon/tools 2.12.0 → 2.13.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 (91) hide show
  1. package/README.md +150 -7
  2. package/dist/descriptions.gen.d.ts +10 -0
  3. package/dist/descriptions.gen.d.ts.map +1 -0
  4. package/dist/descriptions.gen.js +150 -0
  5. package/dist/generated/zod.gen.d.ts +3 -3
  6. package/dist/index.d.ts +4 -3
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +14 -11
  9. package/dist/lib/custom/auth-config.d.ts +164 -0
  10. package/dist/lib/custom/auth-config.d.ts.map +1 -0
  11. package/dist/lib/custom/auth-config.js +177 -0
  12. package/dist/lib/custom/docs.d.ts +58 -0
  13. package/dist/lib/custom/docs.d.ts.map +1 -0
  14. package/dist/lib/custom/docs.js +143 -0
  15. package/dist/lib/custom/feedback.d.ts +15 -0
  16. package/dist/lib/custom/feedback.d.ts.map +1 -0
  17. package/dist/lib/custom/feedback.js +55 -0
  18. package/dist/lib/custom/fetch.d.ts +402 -0
  19. package/dist/lib/custom/fetch.d.ts.map +1 -0
  20. package/dist/lib/custom/fetch.js +198 -0
  21. package/dist/lib/custom/organizations.d.ts +23 -0
  22. package/dist/lib/custom/organizations.d.ts.map +1 -0
  23. package/dist/lib/custom/organizations.js +32 -0
  24. package/dist/lib/custom/resources.d.ts +22 -0
  25. package/dist/lib/custom/resources.d.ts.map +1 -0
  26. package/dist/lib/custom/resources.js +113 -0
  27. package/dist/lib/custom/sql/connection.d.ts +46 -0
  28. package/dist/lib/custom/sql/connection.d.ts.map +1 -0
  29. package/dist/lib/custom/sql/connection.js +78 -0
  30. package/dist/lib/custom/sql/describe-branch.d.ts +84 -0
  31. package/dist/lib/custom/sql/describe-branch.d.ts.map +1 -0
  32. package/dist/lib/custom/sql/describe-branch.js +155 -0
  33. package/dist/lib/custom/sql/inspect/inspect.d.ts +75 -0
  34. package/dist/lib/custom/sql/inspect/inspect.d.ts.map +1 -0
  35. package/dist/lib/custom/sql/inspect/inspect.js +135 -0
  36. package/dist/lib/custom/sql/inspect/queries.d.ts +63 -0
  37. package/dist/lib/custom/sql/inspect/queries.d.ts.map +1 -0
  38. package/dist/lib/custom/sql/inspect/queries.js +528 -0
  39. package/dist/lib/custom/sql/inspect/report.d.ts +31 -0
  40. package/dist/lib/custom/sql/inspect/report.d.ts.map +1 -0
  41. package/dist/lib/custom/sql/inspect/report.js +43 -0
  42. package/dist/lib/custom/sql/inspect/targets.d.ts +27 -0
  43. package/dist/lib/custom/sql/inspect/targets.d.ts.map +1 -0
  44. package/dist/lib/custom/sql/inspect/targets.js +33 -0
  45. package/dist/lib/custom/sql/migrations.d.ts +69 -0
  46. package/dist/lib/custom/sql/migrations.d.ts.map +1 -0
  47. package/dist/lib/custom/sql/migrations.js +144 -0
  48. package/dist/lib/custom/sql/plan.d.ts +27 -0
  49. package/dist/lib/custom/sql/plan.d.ts.map +1 -0
  50. package/dist/lib/custom/sql/plan.js +53 -0
  51. package/dist/lib/custom/sql/query-tuning.d.ts +107 -0
  52. package/dist/lib/custom/sql/query-tuning.d.ts.map +1 -0
  53. package/dist/lib/custom/sql/query-tuning.js +129 -0
  54. package/dist/lib/custom/sql/rows.d.ts +11 -0
  55. package/dist/lib/custom/sql/rows.d.ts.map +1 -0
  56. package/dist/lib/custom/sql/rows.js +19 -0
  57. package/dist/lib/custom/sql/run.d.ts +81 -0
  58. package/dist/lib/custom/sql/run.d.ts.map +1 -0
  59. package/dist/lib/custom/sql/run.js +90 -0
  60. package/dist/lib/custom/sql/schema.d.ts +84 -0
  61. package/dist/lib/custom/sql/schema.d.ts.map +1 -0
  62. package/dist/lib/custom/sql/schema.js +201 -0
  63. package/dist/lib/custom/sql/slow-queries.d.ts +43 -0
  64. package/dist/lib/custom/sql/slow-queries.d.ts.map +1 -0
  65. package/dist/lib/custom/sql/slow-queries.js +87 -0
  66. package/dist/lib/customize.d.ts +9 -2
  67. package/dist/lib/customize.d.ts.map +1 -1
  68. package/dist/lib/customize.js +21 -7
  69. package/dist/lib/ergonomic/bind.d.ts +11 -1
  70. package/dist/lib/ergonomic/bind.d.ts.map +1 -1
  71. package/dist/lib/ergonomic/bind.js +13 -3
  72. package/dist/lib/ergonomic/catalog.d.ts +854 -39
  73. package/dist/lib/ergonomic/catalog.d.ts.map +1 -1
  74. package/dist/lib/ergonomic/catalog.js +35 -8
  75. package/dist/lib/ergonomic/composed.d.ts +4 -4
  76. package/dist/lib/ergonomic/composed.d.ts.map +1 -1
  77. package/dist/lib/ergonomic/composed.js +47 -45
  78. package/dist/lib/ergonomic/ids.d.ts +3 -1
  79. package/dist/lib/ergonomic/ids.d.ts.map +1 -1
  80. package/dist/lib/ergonomic/ids.js +41 -2
  81. package/dist/lib/ergonomic/index.d.ts +1 -1
  82. package/dist/lib/ergonomic/index.d.ts.map +1 -1
  83. package/dist/lib/ergonomic/index.js +2 -2
  84. package/dist/lib/operation.d.ts +11 -0
  85. package/dist/lib/operation.d.ts.map +1 -1
  86. package/dist/lib/references.d.ts +10 -0
  87. package/dist/lib/references.d.ts.map +1 -0
  88. package/dist/lib/references.js +28 -0
  89. package/dist/operations.gen.d.ts +2 -2
  90. package/dist/operations.gen.js +301 -301
  91. package/package.json +8 -5
@@ -0,0 +1,402 @@
1
+ import { type NeonClient } from "@neon/sdk";
2
+ import * as z from "zod";
3
+ import { type ToolClientOptions } from "../ergonomic/bind.js";
4
+ import type { NeonToolExecutionContext } from "../operation.js";
5
+ export declare const fetchResourceInputSchema: z.ZodObject<{
6
+ id: z.ZodString;
7
+ }, z.core.$strict>;
8
+ export declare const fetchResource: (neonClient: NeonClient<true>, id: string, context: NeonToolExecutionContext, consoleUrl: string, signal?: AbortSignal) => Promise<{
9
+ id: string;
10
+ title: string;
11
+ text: string;
12
+ url: string;
13
+ metadata: {
14
+ organization: import("@neon/sdk").Organization;
15
+ members: import("@neon/sdk").MemberWithUser[];
16
+ projects: import("@neon/sdk").ProjectListItem[];
17
+ };
18
+ } | {
19
+ id: string;
20
+ title: string;
21
+ text: string;
22
+ url: string;
23
+ metadata: {
24
+ project: import("@neon/sdk").Project;
25
+ branches: import("@neon/sdk").Branch[];
26
+ };
27
+ } | {
28
+ id: string;
29
+ title: string;
30
+ text: string;
31
+ url: string;
32
+ metadata: {
33
+ endpoint: import("@neon/sdk").Endpoint;
34
+ };
35
+ } | {
36
+ id: string;
37
+ title: string;
38
+ text: string;
39
+ url: string;
40
+ metadata: {
41
+ snapshot: import("@neon/sdk").Snapshot;
42
+ };
43
+ } | {
44
+ id: string;
45
+ title: string;
46
+ text: string;
47
+ url: string;
48
+ metadata: {
49
+ branch: import("@neon/sdk").Branch;
50
+ database_structure: import("./sql/rows.js").Row[][] | null;
51
+ database_structure_error?: string;
52
+ };
53
+ }>;
54
+ export declare const fetchResourceTool: (options: ToolClientOptions) => import("../operation.js").NeonTool<z.ZodObject<{
55
+ id: z.ZodString;
56
+ }, z.core.$strict>, "fetch_resources", {
57
+ id: string;
58
+ title: string;
59
+ text: string;
60
+ url: string;
61
+ metadata: {
62
+ organization: {
63
+ id: string;
64
+ name: string;
65
+ handle: string;
66
+ plan: string;
67
+ created_at: string;
68
+ managed_by: string;
69
+ updated_at: string;
70
+ allow_hipaa_projects?: boolean | null | undefined;
71
+ require_mfa?: boolean | null | undefined;
72
+ };
73
+ members: {
74
+ member: {
75
+ id: string;
76
+ user_id: string;
77
+ org_id: string;
78
+ role: import("@neon/sdk").MemberRole;
79
+ joined_at?: string | null | undefined;
80
+ };
81
+ user: {
82
+ email: string;
83
+ has_mfa?: boolean | null | undefined;
84
+ deactivated_at?: string | null | undefined;
85
+ };
86
+ }[];
87
+ projects: {
88
+ id: string;
89
+ platform_id: string;
90
+ region_id: string;
91
+ name: string;
92
+ provisioner: import("@neon/sdk").Provisioner;
93
+ default_endpoint_settings?: {
94
+ pg_settings?: {
95
+ [x: string]: string;
96
+ } | null | undefined;
97
+ pgbouncer_settings?: {
98
+ [x: string]: string;
99
+ } | null | undefined;
100
+ autoscaling_limit_min_cu?: number | null | undefined;
101
+ autoscaling_limit_max_cu?: number | null | undefined;
102
+ suspend_timeout_seconds?: number | null | undefined;
103
+ } | null | undefined;
104
+ settings?: {
105
+ quota?: {
106
+ active_time_seconds?: number | null | undefined;
107
+ compute_time_seconds?: number | null | undefined;
108
+ written_data_bytes?: number | null | undefined;
109
+ data_transfer_bytes?: number | null | undefined;
110
+ logical_size_bytes?: number | null | undefined;
111
+ } | null | undefined;
112
+ allowed_ips?: {
113
+ ips?: string[] | null | undefined;
114
+ protected_branches_only?: boolean | null | undefined;
115
+ } | null | undefined;
116
+ enable_logical_replication?: boolean | null | undefined;
117
+ maintenance_window?: {
118
+ weekdays: number[];
119
+ start_time: string;
120
+ end_time: string;
121
+ } | null | undefined;
122
+ block_public_connections?: boolean | null | undefined;
123
+ block_vpc_connections?: boolean | null | undefined;
124
+ audit_log_level?: import("@neon/sdk").ProjectAuditLogLevel | null | undefined;
125
+ hipaa?: boolean | null | undefined;
126
+ preload_libraries?: {
127
+ use_defaults?: boolean | null | undefined;
128
+ enabled_libraries?: string[] | null | undefined;
129
+ } | null | undefined;
130
+ } | null | undefined;
131
+ pg_version: import("@neon/sdk").PgVersion;
132
+ proxy_host: string;
133
+ branch_logical_size_limit: number;
134
+ branch_logical_size_limit_bytes: number;
135
+ store_passwords: boolean;
136
+ active_time: number;
137
+ cpu_used_sec: number;
138
+ maintenance_starts_at?: string | null | undefined;
139
+ creation_source: string;
140
+ created_at: string;
141
+ updated_at: string;
142
+ synthetic_storage_size?: number | null | undefined;
143
+ quota_reset_at?: string | null | undefined;
144
+ owner_id: string;
145
+ compute_last_active_at?: string | null | undefined;
146
+ org_id?: string | null | undefined;
147
+ org_name?: string | null | undefined;
148
+ history_retention_seconds?: number | null | undefined;
149
+ hipaa_enabled_at?: string | null | undefined;
150
+ deleted_at?: string | null | undefined;
151
+ recoverable_until?: string | null | undefined;
152
+ effective_project_permission?: (import("@neon/sdk").ProjectPermissionLevel | null) | undefined;
153
+ }[];
154
+ };
155
+ } | {
156
+ id: string;
157
+ title: string;
158
+ text: string;
159
+ url: string;
160
+ metadata: {
161
+ project: {
162
+ data_storage_bytes_hour: number;
163
+ data_transfer_bytes: number;
164
+ written_data_bytes: number;
165
+ compute_time_seconds: number;
166
+ active_time_seconds: number;
167
+ cpu_used_sec: number;
168
+ id: string;
169
+ platform_id: string;
170
+ region_id: string;
171
+ name: string;
172
+ provisioner: import("@neon/sdk").Provisioner;
173
+ default_endpoint_settings?: {
174
+ pg_settings?: {
175
+ [x: string]: string;
176
+ } | null | undefined;
177
+ pgbouncer_settings?: {
178
+ [x: string]: string;
179
+ } | null | undefined;
180
+ autoscaling_limit_min_cu?: number | null | undefined;
181
+ autoscaling_limit_max_cu?: number | null | undefined;
182
+ suspend_timeout_seconds?: number | null | undefined;
183
+ } | null | undefined;
184
+ settings?: {
185
+ quota?: {
186
+ active_time_seconds?: number | null | undefined;
187
+ compute_time_seconds?: number | null | undefined;
188
+ written_data_bytes?: number | null | undefined;
189
+ data_transfer_bytes?: number | null | undefined;
190
+ logical_size_bytes?: number | null | undefined;
191
+ } | null | undefined;
192
+ allowed_ips?: {
193
+ ips?: string[] | null | undefined;
194
+ protected_branches_only?: boolean | null | undefined;
195
+ } | null | undefined;
196
+ enable_logical_replication?: boolean | null | undefined;
197
+ maintenance_window?: {
198
+ weekdays: number[];
199
+ start_time: string;
200
+ end_time: string;
201
+ } | null | undefined;
202
+ block_public_connections?: boolean | null | undefined;
203
+ block_vpc_connections?: boolean | null | undefined;
204
+ audit_log_level?: import("@neon/sdk").ProjectAuditLogLevel | null | undefined;
205
+ hipaa?: boolean | null | undefined;
206
+ preload_libraries?: {
207
+ use_defaults?: boolean | null | undefined;
208
+ enabled_libraries?: string[] | null | undefined;
209
+ } | null | undefined;
210
+ } | null | undefined;
211
+ pg_version: import("@neon/sdk").PgVersion;
212
+ proxy_host: string;
213
+ branch_logical_size_limit: number;
214
+ branch_logical_size_limit_bytes: number;
215
+ store_passwords: boolean;
216
+ maintenance_starts_at?: string | null | undefined;
217
+ creation_source: string;
218
+ history_retention_seconds: number;
219
+ created_at: string;
220
+ updated_at: string;
221
+ synthetic_storage_size?: number | null | undefined;
222
+ consumption_period_start: string;
223
+ consumption_period_end: string;
224
+ quota_reset_at?: string | null | undefined;
225
+ owner_id: string;
226
+ owner?: {
227
+ email: string;
228
+ name: string;
229
+ branches_limit: number;
230
+ subscription_type: import("@neon/sdk").BillingSubscriptionType;
231
+ } | null | undefined;
232
+ compute_last_active_at?: string | null | undefined;
233
+ org_id?: string | null | undefined;
234
+ maintenance_scheduled_for?: string | null | undefined;
235
+ hipaa_enabled_at?: string | null | undefined;
236
+ effective_project_permission?: (import("@neon/sdk").ProjectPermissionLevel | null) | undefined;
237
+ };
238
+ branches: {
239
+ id: string;
240
+ project_id: string;
241
+ parent_id?: string | null | undefined;
242
+ parent_lsn?: string | null | undefined;
243
+ parent_timestamp?: string | null | undefined;
244
+ name: string;
245
+ current_state: import("@neon/sdk").BranchState;
246
+ pending_state?: string | null | undefined;
247
+ state_changed_at: string;
248
+ logical_size?: number | null | undefined;
249
+ creation_source: string;
250
+ primary?: boolean | null | undefined;
251
+ default: boolean;
252
+ protected: boolean;
253
+ cpu_used_sec: number;
254
+ compute_time_seconds: number;
255
+ active_time_seconds: number;
256
+ written_data_bytes: number;
257
+ data_transfer_bytes: number;
258
+ created_at: string;
259
+ updated_at: string;
260
+ ttl_interval_seconds?: number | null | undefined;
261
+ expires_at?: string | null | undefined;
262
+ last_reset_at?: string | null | undefined;
263
+ created_by?: {
264
+ name?: string | null | undefined;
265
+ image?: string | null | undefined;
266
+ } | null | undefined;
267
+ init_source?: string | null | undefined;
268
+ restore_status?: string | null | undefined;
269
+ restored_from?: string | null | undefined;
270
+ restored_as?: string | null | undefined;
271
+ restricted_actions?: {
272
+ name: string;
273
+ reason: string;
274
+ }[] | null | undefined;
275
+ recovery?: {
276
+ deleted_at: string;
277
+ recoverable_until: string;
278
+ deletion_method: "user" | "ttl";
279
+ } | null | undefined;
280
+ }[];
281
+ };
282
+ } | {
283
+ id: string;
284
+ title: string;
285
+ text: string;
286
+ url: string;
287
+ metadata: {
288
+ endpoint: {
289
+ host: string;
290
+ id: string;
291
+ name?: string | null | undefined;
292
+ project_id: string;
293
+ branch_id: string;
294
+ autoscaling_limit_min_cu: import("@neon/sdk").ComputeUnit;
295
+ autoscaling_limit_max_cu: import("@neon/sdk").ComputeUnit;
296
+ region_id: string;
297
+ type: import("@neon/sdk").EndpointType;
298
+ current_state: import("@neon/sdk").EndpointState;
299
+ pending_state?: import("@neon/sdk").EndpointState | null | undefined;
300
+ settings: {
301
+ pg_settings?: {
302
+ [x: string]: string;
303
+ } | null | undefined;
304
+ pgbouncer_settings?: {
305
+ [x: string]: string;
306
+ } | null | undefined;
307
+ preload_libraries?: {
308
+ use_defaults?: boolean | null | undefined;
309
+ enabled_libraries?: string[] | null | undefined;
310
+ } | null | undefined;
311
+ };
312
+ pooler_enabled: boolean;
313
+ pooler_mode: import("@neon/sdk").EndpointPoolerMode;
314
+ disabled: boolean;
315
+ passwordless_access: boolean;
316
+ last_active?: string | null | undefined;
317
+ creation_source: string;
318
+ created_at: string;
319
+ updated_at: string;
320
+ started_at?: string | null | undefined;
321
+ suspended_at?: string | null | undefined;
322
+ proxy_host: string;
323
+ suspend_timeout_seconds: import("@neon/sdk").SuspendTimeoutSeconds;
324
+ provisioner: import("@neon/sdk").Provisioner;
325
+ compute_release_version?: string | null | undefined;
326
+ };
327
+ };
328
+ } | {
329
+ id: string;
330
+ title: string;
331
+ text: string;
332
+ url: string;
333
+ metadata: {
334
+ snapshot: {
335
+ id: string;
336
+ name: string;
337
+ lsn?: string | null | undefined;
338
+ timestamp?: string | null | undefined;
339
+ source_branch_id?: string | null | undefined;
340
+ created_at: string;
341
+ expires_at?: string | null | undefined;
342
+ manual?: boolean | null | undefined;
343
+ full_size?: number | null | undefined;
344
+ diff_size?: number | null | undefined;
345
+ };
346
+ };
347
+ } | {
348
+ id: string;
349
+ title: string;
350
+ text: string;
351
+ url: string;
352
+ metadata: {
353
+ branch: {
354
+ id: string;
355
+ project_id: string;
356
+ parent_id?: string | null | undefined;
357
+ parent_lsn?: string | null | undefined;
358
+ parent_timestamp?: string | null | undefined;
359
+ name: string;
360
+ current_state: import("@neon/sdk").BranchState;
361
+ pending_state?: string | null | undefined;
362
+ state_changed_at: string;
363
+ logical_size?: number | null | undefined;
364
+ creation_source: string;
365
+ primary?: boolean | null | undefined;
366
+ default: boolean;
367
+ protected: boolean;
368
+ cpu_used_sec: number;
369
+ compute_time_seconds: number;
370
+ active_time_seconds: number;
371
+ written_data_bytes: number;
372
+ data_transfer_bytes: number;
373
+ created_at: string;
374
+ updated_at: string;
375
+ ttl_interval_seconds?: number | null | undefined;
376
+ expires_at?: string | null | undefined;
377
+ last_reset_at?: string | null | undefined;
378
+ created_by?: {
379
+ name?: string | null | undefined;
380
+ image?: string | null | undefined;
381
+ } | null | undefined;
382
+ init_source?: string | null | undefined;
383
+ restore_status?: string | null | undefined;
384
+ restored_from?: string | null | undefined;
385
+ restored_as?: string | null | undefined;
386
+ restricted_actions?: {
387
+ name: string;
388
+ reason: string;
389
+ }[] | null | undefined;
390
+ recovery?: {
391
+ deleted_at: string;
392
+ recoverable_until: string;
393
+ deletion_method: "user" | "ttl";
394
+ } | null | undefined;
395
+ };
396
+ database_structure: {
397
+ [x: string]: unknown;
398
+ }[][] | null;
399
+ database_structure_error?: string | null | undefined;
400
+ };
401
+ }>;
402
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/lib/custom/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAmC,MAAM,WAAW,CAAC;AAC7E,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAQhE,eAAO,MAAM,wBAAwB;;kBAOnC,CAAC;AAkMH,eAAO,MAAM,aAAa,GACzB,YAAY,UAAU,CAAC,IAAI,CAAC,EAC5B,IAAI,MAAM,EACV,SAAS,wBAAwB,EACjC,YAAY,MAAM,EAClB,SAAS,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+DpB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6B3D,CAAC"}
@@ -0,0 +1,198 @@
1
+ import { bindTool, publishedId } from "../ergonomic/bind.js";
2
+ import { consoleBaseUrl, isAccessRefusal } from "./resources.js";
3
+ import { describeBranch } from "./sql/describe-branch.js";
4
+ import { NeonClientError } from "@neon/sdk";
5
+ import * as z from "zod";
6
+ // src/lib/custom/fetch.ts
7
+ const fetchResourceInputSchema = z.strictObject({ id: z.string().min(1).describe("An id from {{resources.search}}, such as project:<project_id>.") });
8
+ /** The first page only; a list the API refuses is empty. */
9
+ const firstPageIfAllowed = async (list) => {
10
+ try {
11
+ return (await list.page()).items;
12
+ } catch (error) {
13
+ if (isAccessRefusal(error)) return [];
14
+ throw error;
15
+ }
16
+ };
17
+ const localDate = (value) => new Date(value).toLocaleDateString();
18
+ const fetchOrganization = async (neonClient, id, orgId, consoleUrl, signal) => {
19
+ const organization = await neonClient.organizations.get({ orgId }, { signal });
20
+ const [members, projects] = await Promise.all([firstPageIfAllowed(neonClient.organizations.members.list({ orgId }, { signal })), firstPageIfAllowed(neonClient.projects.list({ org_id: orgId }, { signal }))]);
21
+ const lines = [
22
+ "**Organization Details**",
23
+ "**Basic Information:**",
24
+ `- Name: ${organization.name}`,
25
+ `- ID: ${organization.id}`,
26
+ `- Created: ${localDate(organization.created_at)}`,
27
+ "",
28
+ "**Statistics:**",
29
+ ...members.length > 0 ? [`- Members: ${members.length}`] : [],
30
+ `- Projects: ${projects.length}`,
31
+ "",
32
+ "**Raw Data:**",
33
+ JSON.stringify({
34
+ org: organization,
35
+ members,
36
+ projects
37
+ }, null, 2),
38
+ ""
39
+ ];
40
+ return {
41
+ id,
42
+ title: organization.name,
43
+ text: lines.join("\n"),
44
+ url: new URL(`/app/${encodeURIComponent(organization.id)}/projects`, consoleUrl).toString(),
45
+ metadata: {
46
+ organization,
47
+ members,
48
+ projects
49
+ }
50
+ };
51
+ };
52
+ const fetchProject = async (neonClient, id, projectId, consoleUrl, signal) => {
53
+ const [branchPage, project] = await Promise.all([neonClient.branches.list({ projectId }, { signal }).page(), neonClient.projects.get({ projectId }, { signal })]);
54
+ const branches = branchPage.items;
55
+ const defaultBranch = branches.find((branch) => branch.default);
56
+ const text = `**Project Details**
57
+
58
+ **Basic Information:**
59
+ - Name: ${project.name}
60
+ - ID: ${project.id}
61
+ - Region: ${project.region_id}
62
+ - PostgreSQL Version: ${project.pg_version}
63
+ - Created: ${localDate(project.created_at)}
64
+ - Last Updated: ${localDate(project.updated_at)}
65
+
66
+ **Statistics:**
67
+ - Branches: ${branches.length}
68
+ - Default Branch: ${defaultBranch?.name} (${defaultBranch?.id})
69
+
70
+ **Raw Data:**
71
+ ${JSON.stringify({
72
+ project,
73
+ branches
74
+ }, null, 2)}
75
+ `;
76
+ return {
77
+ id,
78
+ title: project.name,
79
+ text,
80
+ url: new URL(`/app/projects/${encodeURIComponent(project.id)}`, consoleUrl).toString(),
81
+ metadata: {
82
+ project,
83
+ branches
84
+ }
85
+ };
86
+ };
87
+ const fetchEndpoint = async (neonClient, id, projectId, endpointId, consoleUrl, signal) => {
88
+ const endpoint = await neonClient.postgres.endpoints.get({
89
+ projectId,
90
+ endpointId
91
+ }, { signal });
92
+ const text = `**Compute Endpoint Details**
93
+
94
+ - ID: ${endpoint.id}
95
+ - Type: ${endpoint.type}
96
+ - State: ${endpoint.current_state}
97
+ - Host: ${endpoint.host}
98
+ - Branch: ${endpoint.branch_id}
99
+ - Project: ${endpoint.project_id}
100
+ - Region: ${endpoint.region_id}
101
+ - Autoscaling: ${endpoint.autoscaling_limit_min_cu}-${endpoint.autoscaling_limit_max_cu} CU
102
+
103
+ **Raw Data:**
104
+ ${JSON.stringify(endpoint, null, 2)}
105
+ `;
106
+ return {
107
+ id,
108
+ title: `${endpoint.id} (${endpoint.type})`,
109
+ text,
110
+ url: new URL(`/app/projects/${encodeURIComponent(projectId)}/branches/${encodeURIComponent(endpoint.branch_id)}`, consoleUrl).toString(),
111
+ metadata: { endpoint }
112
+ };
113
+ };
114
+ const fetchSnapshot = async (neonClient, id, projectId, snapshotId, consoleUrl, signal) => {
115
+ const snapshot = (await neonClient.snapshots.list({ projectId }, { signal })).find((candidate) => candidate.id === snapshotId);
116
+ if (snapshot === void 0) throw new NeonClientError(`Snapshot ${snapshotId} not found in project ${projectId}`);
117
+ const text = `**Snapshot Details**
118
+
119
+ - Name: ${snapshot.name}
120
+ - ID: ${snapshot.id}
121
+ - Source branch: ${snapshot.source_branch_id ?? "unknown"}
122
+ - Taken at: ${snapshot.timestamp ?? snapshot.lsn ?? "unknown"}
123
+
124
+ **Raw Data:**
125
+ ${JSON.stringify(snapshot, null, 2)}
126
+ `;
127
+ return {
128
+ id,
129
+ title: snapshot.name,
130
+ text,
131
+ url: new URL(`/app/projects/${encodeURIComponent(projectId)}`, consoleUrl).toString(),
132
+ metadata: { snapshot }
133
+ };
134
+ };
135
+ const invalidId = (id) => new NeonClientError(`Invalid ID format: "${id}". Expected format: org:*, project:*, branch:<project>/<branch>, endpoint:<project>/<endpoint>, or snapshot:<project>/<snapshot>`);
136
+ /** `<prefix><project>/<child>`, the form resources.search returns for project-scoped resources. */
137
+ const projectScopedId = (id, prefix) => {
138
+ const [projectId, childId, ...rest] = id.slice(prefix.length).split("/");
139
+ if (!projectId || !childId || rest.length > 0) throw invalidId(id);
140
+ return [projectId, childId];
141
+ };
142
+ const fetchResource = async (neonClient, id, context, consoleUrl, signal) => {
143
+ if (id.startsWith("org:")) return fetchOrganization(neonClient, id, id.slice(4), consoleUrl, signal);
144
+ if (id.startsWith("org-")) return fetchOrganization(neonClient, id, id, consoleUrl, signal);
145
+ if (id.startsWith("project:")) return fetchProject(neonClient, id, id.slice(8), consoleUrl, signal);
146
+ if (id.startsWith("endpoint:")) {
147
+ const [projectId, endpointId] = projectScopedId(id, "endpoint:");
148
+ return fetchEndpoint(neonClient, id, projectId, endpointId, consoleUrl, signal);
149
+ }
150
+ if (id.startsWith("snapshot:")) {
151
+ const [projectId, snapshotId] = projectScopedId(id, "snapshot:");
152
+ return fetchSnapshot(neonClient, id, projectId, snapshotId, consoleUrl, signal);
153
+ }
154
+ if (id.startsWith("branch:")) {
155
+ const [projectId, branchId] = projectScopedId(id, "branch:");
156
+ const { text, console_url, ...metadata } = await describeBranch(neonClient, {
157
+ project_id: projectId,
158
+ branch_id: branchId
159
+ }, context, consoleUrl, signal);
160
+ return {
161
+ id,
162
+ title: metadata.branch.name,
163
+ text,
164
+ url: console_url,
165
+ metadata
166
+ };
167
+ }
168
+ throw invalidId(id);
169
+ };
170
+ const fetchResourceTool = (options) => {
171
+ const consoleUrl = consoleBaseUrl(options.baseUrl ?? "https://console.neon.tech/api/v2");
172
+ return bindTool(options, {
173
+ operationId: "resources.fetch",
174
+ id: publishedId("resources.fetch"),
175
+ title: "Fetch",
176
+ description: "Returns an organization, project, branch, compute, or snapshot by an id from {{resources.search}}: markdown text, console URL, and records in metadata.",
177
+ inputSchema: fetchResourceInputSchema,
178
+ annotations: {
179
+ readOnlyHint: true,
180
+ destructiveHint: false,
181
+ idempotentHint: true,
182
+ openWorldHint: false
183
+ },
184
+ requiresApproval: false,
185
+ metadata: {
186
+ method: "SQL",
187
+ path: "/projects",
188
+ stability: "stable",
189
+ deprecated: false,
190
+ tags: [
191
+ "Organization",
192
+ "Project",
193
+ "Branch"
194
+ ]
195
+ }
196
+ }, (neonClient, input, signal, context) => fetchResource(neonClient, input.id, context, consoleUrl, signal));
197
+ };
198
+ export { fetchResource, fetchResourceInputSchema, fetchResourceTool };
@@ -0,0 +1,23 @@
1
+ import * as z from "zod";
2
+ import { type ToolClientOptions } from "../ergonomic/bind.js";
3
+ export declare const userOrganizationsInputSchema: z.ZodObject<{
4
+ search: z.ZodOptional<z.ZodString>;
5
+ }, z.core.$strict>;
6
+ export declare const matchesNameOrId: (entity: {
7
+ name: string;
8
+ id: string;
9
+ }, query: string) => boolean;
10
+ export declare const userOrganizationsTool: (options: ToolClientOptions) => import("../operation.js").NeonTool<z.ZodObject<{
11
+ search: z.ZodOptional<z.ZodString>;
12
+ }, z.core.$strict>, "organizations_user", {
13
+ id: string;
14
+ name: string;
15
+ handle: string;
16
+ plan: string;
17
+ created_at: string;
18
+ managed_by: string;
19
+ updated_at: string;
20
+ allow_hipaa_projects?: boolean | null | undefined;
21
+ require_mfa?: boolean | null | undefined;
22
+ }[]>;
23
+ //# sourceMappingURL=organizations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organizations.d.ts","sourceRoot":"","sources":["../../../src/lib/custom/organizations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,sBAAsB,CAAC;AAE9B,eAAO,MAAM,4BAA4B;;kBAKvC,CAAC;AAEH,eAAO,MAAM,eAAe,GAC3B,QAAQ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EACpC,OAAO,MAAM,YAOb,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,SAAS,iBAAiB;;;;;;;;;;;;IAyB9D,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { bindTool, publishedId } from "../ergonomic/bind.js";
2
+ import * as z from "zod";
3
+ // src/lib/custom/organizations.ts
4
+ const userOrganizationsInputSchema = z.strictObject({ search: z.string().describe("Part of an organization name or id, ignoring case.").optional() });
5
+ const matchesNameOrId = (entity, query) => {
6
+ const needle = query.toLowerCase();
7
+ return entity.name.toLowerCase().includes(needle) || entity.id.toLowerCase().includes(needle);
8
+ };
9
+ const userOrganizationsTool = (options) => bindTool(options, {
10
+ operationId: "user.organizations",
11
+ id: publishedId("user.organizations"),
12
+ title: "List organizations for the current user",
13
+ description: "Lists the organizations the user belongs to; an organization API key gets its own organization. search filters by name or id.",
14
+ inputSchema: userOrganizationsInputSchema,
15
+ annotations: {
16
+ readOnlyHint: true,
17
+ openWorldHint: false
18
+ },
19
+ requiresApproval: false,
20
+ metadata: {
21
+ method: "GET",
22
+ path: "/users/me/organizations",
23
+ stability: "stable",
24
+ deprecated: false,
25
+ tags: ["Users", "Organizations"]
26
+ }
27
+ }, async (neon, { search }, signal) => {
28
+ const organizations = await neon.user.organizations({ signal });
29
+ if (!search) return organizations;
30
+ return organizations.filter((org) => matchesNameOrId(org, search));
31
+ });
32
+ export { matchesNameOrId, userOrganizationsInputSchema, userOrganizationsTool };
@@ -0,0 +1,22 @@
1
+ import * as z from "zod";
2
+ import { type ToolClientOptions } from "../ergonomic/bind.js";
3
+ export declare const DEFAULT_API_BASE_URL = "https://console.neon.tech/api/v2";
4
+ export declare const searchResourcesInputSchema: z.ZodObject<{
5
+ query: z.ZodString;
6
+ }, z.core.$strict>;
7
+ export declare const consoleBaseUrl: (apiBaseUrl: string) => string;
8
+ /**
9
+ * 403 and 404 mean the credential may not read that list. Any other API error,
10
+ * such as a 5xx or an exhausted 429, is a failure the caller must see.
11
+ */
12
+ export declare const isAccessRefusal: (error: unknown) => boolean;
13
+ export declare const searchResourcesTool: (options: ToolClientOptions) => import("../operation.js").NeonTool<z.ZodObject<{
14
+ query: z.ZodString;
15
+ }, z.core.$strict>, "search_resources", {
16
+ results: {
17
+ id: string;
18
+ title: string;
19
+ url: string;
20
+ }[];
21
+ }>;
22
+ //# sourceMappingURL=resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/lib/custom/resources.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,sBAAsB,CAAC;AAG9B,eAAO,MAAM,oBAAoB,qCAAqC,CAAC;AAGvE,eAAO,MAAM,0BAA0B;;kBAOrC,CAAC;AAQH,eAAO,MAAM,cAAc,GAAI,YAAY,MAAM,WACT,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,OAEF,CAAC;AA0HhD,eAAO,MAAM,mBAAmB,GAAI,SAAS,iBAAiB;;;;YAxIzD,MAAM;eACH,MAAM;aACR,MAAM;;EAwKX,CAAC"}