@neon/tools 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,67 +1,41 @@
1
- import { type NeonConfig, NeonError } from "@neon/sdk";
2
- import { type NeonBearerCredential } from "./lib/auth.js";
1
+ import { NeonError } from "@neon/sdk";
3
2
  import { type InjectedNeonTool, type NeonToolCustomizeOptions, type NeonToolInjectOptions, type NeonToolNameOverrides } from "./lib/customize.js";
4
- import { type NeonWorkflowId, type WorkflowFactories, workflowIds } from "./lib/workflows.js";
5
- import { type NeonOperationId, operationFactories, operationIds } from "./operations.gen.js";
3
+ import { type NeonToolId, type ToolClientOptions, toolFactories, toolIds } from "./lib/ergonomic/index.js";
6
4
  export type { NeonBearerCredential } from "./lib/auth.js";
7
5
  export type { InjectedNeonTool, NeonToolCustomizeOptions, NeonToolDescriptionOverrides, NeonToolDescriptionSource, NeonToolInjectOptions, NeonToolInjectValue, NeonToolNameOverrides, NeonToolNameSource, NeonToolOnExecute, NeonToolOnExecuteEvent, } from "./lib/customize.js";
8
6
  export type { JsonSafe, JsonSafeBlob, NeonTool, NeonToolAnnotations, NeonToolExecutionContext, NeonToolMetadata, NeonToolResult, } from "./lib/operation.js";
9
- export type { NeonOperationId, NeonWorkflowId };
10
- export { NeonError, operationIds, workflowIds };
11
- type OperationFactories = typeof operationFactories;
12
- export type NeonTools<Operations extends readonly NeonOperationId[] = [], Workflows extends readonly NeonWorkflowId[] = []> = {
13
- [Operation in Operations[number]]: ReturnType<OperationFactories[Operation]>;
14
- } & {
15
- [Workflow in Workflows[number]]: ReturnType<WorkflowFactories[Workflow]>;
7
+ export type { NeonToolId };
8
+ export { NeonError, toolIds };
9
+ type ToolFactories = typeof toolFactories;
10
+ export type NeonTools<Tools extends readonly NeonToolId[] = []> = {
11
+ [Tool in Tools[number]]: ReturnType<ToolFactories[Tool]>;
16
12
  };
17
- export type InjectedNeonTools<Operations extends readonly NeonOperationId[], Inject, Workflows extends readonly NeonWorkflowId[] = []> = {
18
- [Operation in Operations[number]]: InjectedNeonTool<ReturnType<OperationFactories[Operation]>, Inject>;
19
- } & {
20
- [Workflow in Workflows[number]]: InjectedNeonTool<ReturnType<WorkflowFactories[Workflow]>, Inject>;
13
+ export type InjectedNeonTools<Tools extends readonly NeonToolId[], Inject> = {
14
+ [Tool in Tools[number]]: InjectedNeonTool<ReturnType<ToolFactories[Tool]>, Inject>;
21
15
  };
22
16
  type WithPublishedId<Tool> = Tool extends {
23
17
  id: string;
24
18
  } ? Omit<Tool, "id"> & {
25
19
  id: string;
26
20
  } : Tool;
27
- export interface NeonToolsClientOptions extends Pick<NeonConfig, "baseUrl" | "fetch" | "wait">, Omit<NeonToolCustomizeOptions, "name" | "names"> {
28
- apiKey?: NeonBearerCredential;
21
+ export interface NeonToolsClientOptions extends ToolClientOptions, Omit<NeonToolCustomizeOptions, "name" | "names"> {
29
22
  }
30
- interface OperationSelection {
31
- operations: readonly NeonOperationId[];
32
- workflows?: readonly NeonWorkflowId[];
33
- }
34
- interface WorkflowSelection {
35
- workflows: readonly NeonWorkflowId[];
36
- operations?: readonly NeonOperationId[];
37
- }
38
- type CreateNeonToolsInput = NeonToolsClientOptions & (OperationSelection | WorkflowSelection);
39
- export type CreateNeonToolsOptions<Operations extends readonly NeonOperationId[] = readonly NeonOperationId[], Workflows extends readonly NeonWorkflowId[] = readonly []> = NeonToolsClientOptions & (Workflows extends readonly [] ? {
40
- operations: Operations;
41
- workflows?: Workflows;
42
- } : Operations extends readonly [] ? {
43
- workflows: Workflows;
44
- operations?: Operations;
45
- } : {
46
- operations: Operations;
47
- workflows: Workflows;
48
- });
49
- type SelectedOperations<T> = T extends {
50
- operations: infer O extends readonly NeonOperationId[];
51
- } ? O : [];
52
- type SelectedWorkflows<T> = T extends {
53
- workflows: infer W extends readonly NeonWorkflowId[];
54
- } ? W : [];
55
- type NeonToolsFor<T, Inject> = T extends CreateNeonToolsInput ? Inject extends NeonToolInjectOptions ? InjectedNeonTools<SelectedOperations<T>, Inject, SelectedWorkflows<T>> : NeonTools<SelectedOperations<T>, SelectedWorkflows<T>> : never;
56
- type NeonToolId = NeonOperationId | NeonWorkflowId;
57
- type ToolForId<Id extends NeonToolId> = Id extends NeonWorkflowId ? ReturnType<WorkflowFactories[Id]> : Id extends NeonOperationId ? ReturnType<OperationFactories[Id]> : never;
58
- type NamedNeonTools<Operations extends readonly NeonOperationId[], Workflows extends readonly NeonWorkflowId[], Inject> = {
59
- [Operation in Operations[number]]: WithPublishedId<Inject extends NeonToolInjectOptions ? InjectedNeonTool<ReturnType<OperationFactories[Operation]>, Inject> : ReturnType<OperationFactories[Operation]>>;
60
- } & {
61
- [Workflow in Workflows[number]]: WithPublishedId<Inject extends NeonToolInjectOptions ? InjectedNeonTool<ReturnType<WorkflowFactories[Workflow]>, Inject> : ReturnType<WorkflowFactories[Workflow]>>;
23
+ type CreateNeonToolsInput = NeonToolsClientOptions & {
24
+ tools: readonly NeonToolId[];
25
+ };
26
+ export type CreateNeonToolsOptions<Tools extends readonly NeonToolId[] = readonly NeonToolId[]> = NeonToolsClientOptions & {
27
+ tools: Tools;
28
+ };
29
+ type SelectedTools<T> = T extends {
30
+ tools: infer S extends readonly NeonToolId[];
31
+ } ? S : [];
32
+ type NeonToolsFor<T, Inject> = T extends CreateNeonToolsInput ? Inject extends NeonToolInjectOptions ? InjectedNeonTools<SelectedTools<T>, Inject> : NeonTools<SelectedTools<T>> : never;
33
+ type ToolForId<Id extends NeonToolId> = ReturnType<ToolFactories[Id]>;
34
+ type NamedNeonTools<Tools extends readonly NeonToolId[], Inject> = {
35
+ [Tool in Tools[number]]: WithPublishedId<Inject extends NeonToolInjectOptions ? InjectedNeonTool<ReturnType<ToolFactories[Tool]>, Inject> : ReturnType<ToolFactories[Tool]>>;
62
36
  };
63
37
  type NamedNeonTool<Id extends NeonToolId, Inject> = WithPublishedId<Inject extends NeonToolInjectOptions ? InjectedNeonTool<ToolForId<Id>, Inject> : ToolForId<Id>>;
64
- type NamedNeonToolsFor<T, Inject> = T extends CreateNeonToolsInput ? NamedNeonTools<SelectedOperations<T>, SelectedWorkflows<T>, Inject> : never;
38
+ type NamedNeonToolsFor<T, Inject> = T extends CreateNeonToolsInput ? NamedNeonTools<SelectedTools<T>, Inject> : never;
65
39
  export declare function createNeonTools<const T extends CreateNeonToolsInput, const Inject extends NeonToolInjectOptions | undefined = undefined>(options: T & {
66
40
  inject?: Inject;
67
41
  } & ({
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EAEN,KAAK,oBAAoB,EAEzB,MAAM,eAAe,CAAC;AACvB,OAAO,EAIN,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAEN,KAAK,cAAc,EACnB,KAAK,iBAAiB,EAEtB,WAAW,EACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,KAAK,eAAe,EACpB,kBAAkB,EAClB,YAAY,EACZ,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,YAAY,EACX,gBAAgB,EAChB,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EACzB,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACX,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,mBAAmB,EACnB,wBAAwB,EACxB,gBAAgB,EAChB,cAAc,GACd,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC;A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,33 @@
1
- import { missingBearerCredential, requireBearerCredential } from "./lib/auth.js";
2
1
  import { applyToolCustomization, assertToolCustomizeOptions, hasToolCustomization } from "./lib/customize.js";
3
- import { isNeonWorkflowId, workflowFactoryFor, workflowIds } from "./lib/workflows.js";
4
- import { operationFactories, operationIds } from "./operations.gen.js";
5
- import { NeonError, createNeonClient } from "@neon/sdk";
2
+ import { toolFactories } from "./lib/ergonomic/catalog.js";
3
+ import { isNeonToolId, toolIds, unpublishedToolError } from "./lib/ergonomic/ids.js";
4
+ import { NeonError } from "@neon/sdk";
6
5
  //#region src/index.ts
7
- const createRawClient = (options) => createNeonClient({
8
- apiKey: options.apiKey === void 0 ? missingBearerCredential : requireBearerCredential(options.apiKey),
9
- ...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
10
- ...options.fetch === void 0 ? {} : { fetch: options.fetch },
11
- ...options.wait === void 0 ? {} : { wait: options.wait }
12
- }).client;
13
- const operationFactoryFor = (operationId) => {
14
- const knownOperationId = operationIds.find((candidate) => candidate === operationId);
15
- if (knownOperationId === void 0) throw new TypeError(`Unknown Neon operation "${operationId}".`);
16
- return operationFactories[knownOperationId];
17
- };
18
6
  const assertKnownNameKeys = (names, tools) => {
19
7
  if (names === void 0 || typeof names === "function") return;
20
8
  const known = new Set(tools.flatMap((tool) => [tool.operationId, tool.id]));
21
9
  const unknown = Object.keys(names).filter((key) => !known.has(key));
22
10
  if (unknown.length > 0) throw new TypeError(`Unknown Neon tool name override: ${unknown.join(", ")}`);
23
11
  };
24
- function assertNeonTools(value, operations, workflows) {
25
- if (typeof value !== "object" || value === null) throw new TypeError("Expected generated Neon tools to be an object.");
26
- for (const operationId of operations) if (!(operationId in value)) throw new TypeError(`Missing generated Neon tool "${operationId}".`);
27
- for (const workflowId of workflows) if (!(workflowId in value)) throw new TypeError(`Missing Neon workflow tool "${workflowId}".`);
12
+ function assertNeonTools(value, tools) {
13
+ if (typeof value !== "object" || value === null) throw new TypeError("Expected Neon tools to be an object.");
14
+ for (const toolId of tools) if (!(toolId in value)) throw new TypeError(`Missing Neon tool "${toolId}".`);
28
15
  }
16
+ const factoryFor = (id) => {
17
+ const known = toolIds.find((candidate) => candidate === id);
18
+ if (known === void 0) throw unpublishedToolError(id);
19
+ return toolFactories[known];
20
+ };
29
21
  const bindTools = (options) => {
30
22
  assertToolCustomizeOptions(options);
31
- const operations = options.operations ?? [];
32
- const workflows = options.workflows ?? [];
33
- if (operations.length === 0 && workflows.length === 0) throw new TypeError("createNeonTools requires at least one operation or workflow");
34
- const selectedOperations = /* @__PURE__ */ new Set();
35
- const operationEntries = operations.map((operationId) => {
36
- if (selectedOperations.has(operationId)) throw new Error(`Duplicate Neon operation "${operationId}"`);
37
- selectedOperations.add(operationId);
38
- return [operationId, operationFactoryFor(operationId)(createRawClient(options))];
23
+ const selected = options.tools;
24
+ if (selected === void 0 || selected.length === 0) throw new TypeError("createNeonTools requires at least one tool");
25
+ const seen = /* @__PURE__ */ new Set();
26
+ const rawEntries = selected.map((toolId) => {
27
+ if (seen.has(toolId)) throw new Error(`Duplicate Neon tool "${toolId}"`);
28
+ seen.add(toolId);
29
+ return [toolId, factoryFor(toolId)(options)];
39
30
  });
40
- const selectedWorkflows = /* @__PURE__ */ new Set();
41
- const workflowEntries = workflows.map((workflowId) => {
42
- if (selectedWorkflows.has(workflowId)) throw new Error(`Duplicate Neon workflow "${workflowId}"`);
43
- selectedWorkflows.add(workflowId);
44
- return [workflowId, workflowFactoryFor(workflowId)(options)];
45
- });
46
- const rawEntries = [...operationEntries, ...workflowEntries];
47
31
  assertKnownNameKeys(options.names, rawEntries.map(([, tool]) => tool));
48
32
  const entries = rawEntries.map(([id, tool]) => {
49
33
  return [id, hasToolCustomization(options) ? applyToolCustomization(tool, options) : tool];
@@ -55,23 +39,18 @@ const bindTools = (options) => {
55
39
  publishedIds.set(tool.id, id);
56
40
  }
57
41
  const tools = Object.fromEntries(entries);
58
- assertNeonTools(tools, operations, workflows);
42
+ assertNeonTools(tools, selected);
59
43
  return tools;
60
44
  };
61
45
  function createNeonTools(options) {
62
46
  return bindTools(options);
63
47
  }
64
48
  function createNeonTool(id, options) {
49
+ if (!isNeonToolId(id)) throw unpublishedToolError(id);
65
50
  assertToolCustomizeOptions(options);
66
- let tool;
67
- if (isNeonWorkflowId(id)) tool = workflowFactoryFor(id)(options);
68
- else {
69
- const knownOperationId = operationIds.find((candidate) => candidate === id);
70
- if (knownOperationId === void 0) throw new TypeError(`Unknown Neon operation or workflow "${id}".`);
71
- tool = operationFactories[knownOperationId](createRawClient(options));
72
- }
51
+ const tool = factoryFor(id)(options);
73
52
  assertKnownNameKeys(options.names, [tool]);
74
53
  return hasToolCustomization(options) ? applyToolCustomization(tool, options) : tool;
75
54
  }
76
55
  //#endregion
77
- export { NeonError, createNeonTool, createNeonTools, operationIds, workflowIds };
56
+ export { NeonError, createNeonTool, createNeonTools, toolIds };
@@ -0,0 +1,54 @@
1
+ import { type NeonClient, type NeonConfig, type Paginated } from "@neon/sdk";
2
+ import * as z from "zod";
3
+ import { type NeonOperationId, operationFactories } from "../../operations.gen.js";
4
+ import { type NeonBearerCredential } from "../auth.js";
5
+ import type { JsonSafe, NeonTool, NeonToolAnnotations, NeonToolExecutionContext } from "../operation.js";
6
+ import type { NeonToolId } from "./ids.js";
7
+ export interface ToolClientOptions {
8
+ apiKey?: NeonBearerCredential;
9
+ baseUrl?: string;
10
+ fetch?: typeof fetch;
11
+ wait?: NeonConfig["wait"];
12
+ }
13
+ type Snake<S extends string> = S extends `${infer Head}${infer Rest}` ? Head extends Uppercase<Head> ? Head extends Lowercase<Head> ? `${Head}${Snake<Rest>}` : `_${Lowercase<Head>}${Snake<Rest>}` : `${Head}${Snake<Rest>}` : S;
14
+ export type PublishedId<Id extends string> = Id extends `${infer Head}.${infer Rest}` ? `${Snake<Head>}_${PublishedId<Rest>}` : Snake<Id>;
15
+ export declare const publishedId: <Id extends string>(id: Id) => PublishedId<Id>;
16
+ export declare const toolClient: (options: ToolClientOptions, context?: NeonToolExecutionContext) => NeonClient<true>;
17
+ export declare const collectObjectList: (neon: NeonClient<true>, input: {
18
+ project_id: string;
19
+ branch_id: string;
20
+ bucket_name: string;
21
+ prefix?: string;
22
+ delimiter?: string;
23
+ limit?: number;
24
+ }, signal?: AbortSignal) => Promise<{
25
+ folders: string[];
26
+ objects: import("@neon/sdk").BucketObject[];
27
+ prefix: string;
28
+ }>;
29
+ export declare const collectPages: <T>(list: Paginated<T>, maxItems?: number) => Promise<T[]>;
30
+ export declare const bindTool: <const InputSchema extends z.ZodType, const Id extends string, Output>(options: ToolClientOptions, tool: Omit<NeonTool<InputSchema, Id, JsonSafe<Awaited<Output>>>, "execute">, run: (neon: NeonClient<true>, input: z.output<InputSchema>, signal?: AbortSignal) => Promise<Output>) => NeonTool<InputSchema, Id, JsonSafe<Awaited<Output>>>;
31
+ type GeneratedTool<G extends NeonOperationId> = ReturnType<(typeof operationFactories)[G]>;
32
+ type GeneratedSchema<G extends NeonOperationId> = GeneratedTool<G>["inputSchema"];
33
+ type GeneratedInput<G extends NeonOperationId> = z.output<GeneratedSchema<G>>;
34
+ type GeneratedArg<G extends NeonOperationId> = z.input<GeneratedSchema<G>>;
35
+ type FromGeneratedMeta = {
36
+ list?: boolean;
37
+ annotations?: NeonToolAnnotations;
38
+ requiresApproval?: boolean;
39
+ };
40
+ type OmittedInput<G extends NeonOperationId, Keys extends string> = Omit<GeneratedInput<G>, Keys>;
41
+ type OmittedArg<G extends NeonOperationId, Keys extends string> = Omit<GeneratedArg<G>, Keys>;
42
+ export declare function fromGenerated<const Id extends NeonToolId, const G extends NeonOperationId, Output>(options: ToolClientOptions, spec: FromGeneratedMeta & {
43
+ id: Id;
44
+ generated: G;
45
+ run: (neon: NeonClient<true>, input: GeneratedInput<G>, signal?: AbortSignal) => Promise<Output>;
46
+ }): NeonTool<GeneratedSchema<G>, PublishedId<Id>, JsonSafe<Awaited<Output>>>;
47
+ export declare function fromGenerated<const Id extends NeonToolId, const G extends NeonOperationId, const Keys extends keyof GeneratedInput<G> & string, Output>(options: ToolClientOptions, spec: FromGeneratedMeta & {
48
+ id: Id;
49
+ generated: G;
50
+ omit: readonly Keys[];
51
+ run: (neon: NeonClient<true>, input: OmittedInput<G, Keys>, signal?: AbortSignal) => Promise<Output>;
52
+ }): NeonTool<z.ZodType<OmittedInput<G, Keys>, OmittedArg<G, Keys>>, PublishedId<Id>, JsonSafe<Awaited<Output>>>;
53
+ export {};
54
+ //# sourceMappingURL=bind.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../../../src/lib/ergonomic/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,UAAU,EACf,KAAK,UAAU,EAEf,KAAK,SAAS,EACd,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,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;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;CAC1B;AASD,KAAK,KAAK,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,GAAG,MAAM,IAAI,EAAE,GAClE,IAAI,SAAS,SAAS,CAAC,IAAI,CAAC,GAC3B,IAAI,SAAS,SAAS,CAAC,IAAI,CAAC,GAC3B,GAAG,IAAI,GAAG,K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AAC,CACzB,CAAC"}
@@ -0,0 +1,121 @@
1
+ import { missingBearerCredential, requireBearerCredential } from "../auth.js";
2
+ import { toToolResult } from "../result.js";
3
+ import { operationFactories } from "../../operations.gen.js";
4
+ import { NeonError, createNeonClient } from "@neon/sdk";
5
+ import * as z from "zod";
6
+ //#region src/lib/ergonomic/bind.ts
7
+ const ALL_PAGES = " This tool returns every page. Pass limit to cap how many items come back. Do not pass a cursor.";
8
+ const inertClient = createNeonClient({ apiKey: "unused" }).client;
9
+ const publishedId = (id) => id.split(".").map((segment) => segment.replace(/[A-Z]/g, (character) => `_${character.toLowerCase()}`)).join("_");
10
+ const resolveApiKey = (options, context) => {
11
+ if (context !== void 0 && "apiKey" in context) {
12
+ if (context.apiKey === void 0) throw new TypeError("A Neon API key or OAuth access token is required");
13
+ return requireBearerCredential(context.apiKey);
14
+ }
15
+ return options.apiKey === void 0 ? missingBearerCredential : requireBearerCredential(options.apiKey);
16
+ };
17
+ const toolClient = (options, context) => createNeonClient({
18
+ apiKey: resolveApiKey(options, context),
19
+ throwOnError: true,
20
+ waitForReadiness: true,
21
+ ...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
22
+ ...options.fetch === void 0 ? {} : { fetch: options.fetch },
23
+ ...options.wait === void 0 ? {} : { wait: options.wait }
24
+ });
25
+ const objectListPage = (value) => {
26
+ if ("objects" in value && "folders" in value) return value;
27
+ if ("error" in value && value.error !== void 0) throw value.error;
28
+ if ("data" in value && value.data !== void 0) return value.data;
29
+ throw new NeonError("Object list returned no data.", "client");
30
+ };
31
+ const collectObjectList = async (neon, input, signal) => {
32
+ const folders = [];
33
+ const objects = [];
34
+ let prefix = "";
35
+ let cursor;
36
+ for (;;) {
37
+ const page = objectListPage(await neon.storage.objects.list(input.project_id, input.branch_id, input.bucket_name, {
38
+ ...input.prefix === void 0 ? {} : { prefix: input.prefix },
39
+ ...input.delimiter === void 0 ? {} : { delimiter: input.delimiter },
40
+ ...input.limit === void 0 ? {} : { limit: input.limit },
41
+ ...cursor === void 0 ? {} : { cursor }
42
+ }, { signal }));
43
+ for (const folder of page.folders) {
44
+ if (input.limit !== void 0 && folders.length + objects.length >= input.limit) break;
45
+ folders.push(folder);
46
+ }
47
+ for (const object of page.objects) {
48
+ if (input.limit !== void 0 && folders.length + objects.length >= input.limit) break;
49
+ objects.push(object);
50
+ }
51
+ prefix = page.prefix;
52
+ if (input.limit !== void 0 && folders.length + objects.length >= input.limit) break;
53
+ if (page.next_cursor) {
54
+ cursor = page.next_cursor;
55
+ continue;
56
+ }
57
+ if (page.is_truncated) throw new NeonError("Object list was truncated without a next cursor.", "client");
58
+ break;
59
+ }
60
+ return {
61
+ folders,
62
+ objects,
63
+ prefix
64
+ };
65
+ };
66
+ const collectPages = async (list, maxItems) => {
67
+ if (maxItems === void 0) {
68
+ const result = await list.all();
69
+ if (result.error) throw result.error;
70
+ if (result.data === void 0) throw new NeonError("List returned no data.", "client");
71
+ return result.data;
72
+ }
73
+ const items = [];
74
+ let cursor;
75
+ for (;;) {
76
+ const result = await list.page(cursor);
77
+ if (result.error) throw result.error;
78
+ if (result.data === void 0) throw new NeonError("List returned no data.", "client");
79
+ items.push(...result.data.items);
80
+ if (items.length >= maxItems) return items.slice(0, maxItems);
81
+ if (!result.data.cursor || result.data.items.length === 0) break;
82
+ cursor = result.data.cursor;
83
+ }
84
+ return items;
85
+ };
86
+ const bindTool = (options, tool, run) => ({
87
+ ...tool,
88
+ async execute(input, context) {
89
+ const parsed = await tool.inputSchema.parseAsync(input);
90
+ const result = await run(toolClient(options, context), parsed, context?.signal);
91
+ return toToolResult(result);
92
+ }
93
+ });
94
+ function fromGenerated(options, spec) {
95
+ const generated = operationFactories[spec.generated](inertClient);
96
+ const schema = generated.inputSchema;
97
+ const inputSchema = spec.omit === void 0 || spec.omit.length === 0 ? schema : omitObjectKeys(schema, spec.omit);
98
+ return {
99
+ operationId: spec.id,
100
+ id: publishedId(spec.id),
101
+ title: generated.title,
102
+ description: spec.list ? `${generated.description.trimEnd()}${ALL_PAGES}` : generated.description,
103
+ inputSchema,
104
+ annotations: spec.annotations ?? generated.annotations,
105
+ requiresApproval: spec.requiresApproval ?? generated.requiresApproval,
106
+ metadata: generated.metadata,
107
+ async execute(input, context) {
108
+ const parsed = await inputSchema.parseAsync(input);
109
+ const result = await spec.run(toolClient(options, context), parsed, context?.signal);
110
+ return toToolResult(result);
111
+ }
112
+ };
113
+ }
114
+ const omitObjectKeys = (schema, keys) => {
115
+ if (!(schema instanceof z.ZodObject)) throw new TypeError("Generated tool input schemas must be objects");
116
+ const mask = {};
117
+ for (const key of keys) mask[key] = true;
118
+ return schema.omit(mask);
119
+ };
120
+ //#endregion
121
+ export { bindTool, collectObjectList, collectPages, fromGenerated, publishedId, toolClient };