@neon/tools 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -5
- package/dist/index.d.ts +50 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -19
- package/dist/lib/workflows.d.ts +315 -0
- package/dist/lib/workflows.d.ts.map +1 -0
- package/dist/lib/workflows.js +113 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@neon/tools`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Agent tools for the Neon Management API and for the `@neon/sdk` workflows that attach compute and return a connection string. Select only the operations and workflows an agent needs, then use the canonical descriptors directly or adapt them for MCP, Eve, and Mastra.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install @neon/tools
|
|
@@ -48,9 +48,53 @@ await tools.listProjects.execute(
|
|
|
48
48
|
);
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
The returned record is keyed by OpenAPI operation ID. Each tool includes its
|
|
51
|
+
The returned record is keyed by OpenAPI operation ID or workflow id. Each tool includes its Zod 4 `inputSchema`, snake-case `id`, title, description, safety annotations, stability metadata, and an `execute()` function. Inputs are flat: path, query, header, and body fields sit on one object. A body that is a single object wrapper is lifted, so `create_project` takes `{ name, region_id, org_id, ... }` rather than `{ project: { name } }`. A body with several properties keeps those properties, so `create_project_branch` takes `{ project_id, branch, endpoints, annotation_value }` and `branch` is still an object. Two email-provider updates keep a `body` field because the API request is a discriminated union.
|
|
52
52
|
|
|
53
|
-
`operationIds` exports every valid selector. `execute()` strictly validates the input, rejects unknown fields instead of dropping them, and returns typed, JSON-safe `{ data }`. Neon SDK errors remain typed and are thrown to the caller.
|
|
53
|
+
`operationIds` exports every valid operation selector. `execute()` strictly validates the input, rejects unknown fields instead of dropping them, and returns typed, JSON-safe `{ data }`. Neon SDK errors remain typed and are thrown to the caller.
|
|
54
|
+
|
|
55
|
+
## Workflows
|
|
56
|
+
|
|
57
|
+
`workflows` selects methods from the `@neon/sdk` ergonomic client. These are not OpenAPI operations: they attach a default compute, wait until the resource is ready, and return a connection string. `operations` is the generated Management API. At least one of the two arrays is required.
|
|
58
|
+
|
|
59
|
+
Both workflow tools poll until the resource is ready. The default deadline is five minutes (`wait.timeoutMs`). Pass `wait: { timeoutMs: 30_000 }` on `createNeonTools` or `createNeonTool` to bound that. Set it below the host's own tool-call timeout, otherwise the host gives up first. An abort `signal` on `execute` or a wait timeout stops the poll, not the create: the branch or project may already exist, and the error does not include its id. List before retrying. `metadata.method` and `metadata.path` name the first request; extra readiness GETs are not listed there. `inject.projectId` still works on `createBranchWithCompute` because its path is `/projects/{project_id}/branches`.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const tools = createNeonTools({
|
|
63
|
+
apiKey,
|
|
64
|
+
operations: ["listProjects"],
|
|
65
|
+
workflows: ["createBranchWithCompute", "createProjectAndConnect"],
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const { data } = await tools.createBranchWithCompute.execute({
|
|
69
|
+
project_id: "project-id",
|
|
70
|
+
name: "feature-x",
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
await tools.createProjectAndConnect.execute({
|
|
74
|
+
name: "agent-project",
|
|
75
|
+
region_id: "aws-us-east-1",
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`createNeonTool` accepts the same workflow ids:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const createBranch = createNeonTool("createBranchWithCompute", { apiKey });
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`workflowIds` lists the selectors. Record keys name the entity (`createBranchWithCompute`, `createProjectAndConnect`) and call `neon.branches.createWithCompute` and `neon.projects.createAndConnect`. Published ids are `create_branch_with_compute` and `create_project_and_connect`. Input fields are snake_case, same as generated tools. `names` can rename a workflow the same way it renames an operation:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
const tools = createNeonTools({
|
|
89
|
+
apiKey,
|
|
90
|
+
workflows: ["createBranchWithCompute"],
|
|
91
|
+
names: { createBranchWithCompute: "create_branch" },
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
tools.createBranchWithCompute.id; // "create_branch"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`create_project_branch` still creates a branch with no compute when `endpoints` is omitted. It can attach compute if you pass `endpoints`; it does not wait or return a connection string. Use `createBranchWithCompute` when the next step needs to connect.
|
|
54
98
|
|
|
55
99
|
## Optional host add-ons
|
|
56
100
|
|
|
@@ -116,7 +160,7 @@ The record is still keyed by operation ID (`tools.createProjectBranch`). MCP and
|
|
|
116
160
|
|
|
117
161
|
### Project and branch injection
|
|
118
162
|
|
|
119
|
-
|
|
163
|
+
Tools take path parameters as `project_id` and `branch_id`. A host that already knows those values can inject them, including on `createBranchWithCompute`. Without `omitFromSchema`, the published field becomes optional and a caller-supplied value wins. With `omitFromSchema: true`, the field is removed from the published schema and the injector is the only source:
|
|
120
164
|
|
|
121
165
|
```ts
|
|
122
166
|
const tools = createNeonTools({
|
|
@@ -152,7 +196,7 @@ await grant.run({ projectId: "project-id" }, () => tools.getProject.execute({}))
|
|
|
152
196
|
|
|
153
197
|
Injectors only apply to tools that have that path key. `listProjects` is unchanged. Empty inject values fail closed. Invalid ids still fail the original path schema before fetch.
|
|
154
198
|
|
|
155
|
-
|
|
199
|
+
`onExecute` and `inject` apply to workflow tools the same way they apply to generated tools. Grant filtering, read-only filtering, and access-control notices stay in the host.
|
|
156
200
|
|
|
157
201
|
Injection reads the URL template, so it fills path `project_id` and `branch_id` only. Query and body fields with those names stay caller-supplied, including `getConnectionURI.branch_id`, `createOrgApiKey.project_id`, `createNeonAuthIntegration.project_id` / `branch_id`, `createNeonAuthNewUser.project_id`, `createNeonAuthProviderSDKKeys.project_id`, `transferNeonAuthProviderProject.project_id`, `addProjectJWKS.branch_id`, `createProjectEndpoint.branch_id`, `updateProjectEndpoint.branch_id`, and `getProjectAdvisorSecurityIssues.branch_id`. `omitFromSchema: true` does not hide those fields.
|
|
158
202
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,68 @@
|
|
|
1
1
|
import { type NeonConfig, NeonError } from "@neon/sdk";
|
|
2
2
|
import { type NeonBearerCredential } from "./lib/auth.js";
|
|
3
3
|
import { type InjectedNeonTool, type NeonToolCustomizeOptions, type NeonToolInjectOptions, type NeonToolNameOverrides } from "./lib/customize.js";
|
|
4
|
+
import { type NeonWorkflowId, type WorkflowFactories, workflowIds } from "./lib/workflows.js";
|
|
4
5
|
import { type NeonOperationId, operationFactories, operationIds } from "./operations.gen.js";
|
|
5
6
|
export type { NeonBearerCredential } from "./lib/auth.js";
|
|
6
7
|
export type { InjectedNeonTool, NeonToolCustomizeOptions, NeonToolDescriptionOverrides, NeonToolDescriptionSource, NeonToolInjectOptions, NeonToolInjectValue, NeonToolNameOverrides, NeonToolNameSource, NeonToolOnExecute, NeonToolOnExecuteEvent, } from "./lib/customize.js";
|
|
7
8
|
export type { JsonSafe, JsonSafeBlob, NeonTool, NeonToolAnnotations, NeonToolExecutionContext, NeonToolMetadata, NeonToolResult, } from "./lib/operation.js";
|
|
8
|
-
export type { NeonOperationId };
|
|
9
|
-
export { NeonError, operationIds };
|
|
9
|
+
export type { NeonOperationId, NeonWorkflowId };
|
|
10
|
+
export { NeonError, operationIds, workflowIds };
|
|
10
11
|
type OperationFactories = typeof operationFactories;
|
|
11
|
-
export type NeonTools<Operations extends readonly NeonOperationId[]> = {
|
|
12
|
+
export type NeonTools<Operations extends readonly NeonOperationId[] = [], Workflows extends readonly NeonWorkflowId[] = []> = {
|
|
12
13
|
[Operation in Operations[number]]: ReturnType<OperationFactories[Operation]>;
|
|
14
|
+
} & {
|
|
15
|
+
[Workflow in Workflows[number]]: ReturnType<WorkflowFactories[Workflow]>;
|
|
13
16
|
};
|
|
14
|
-
export type InjectedNeonTools<Operations extends readonly NeonOperationId[], Inject> = {
|
|
17
|
+
export type InjectedNeonTools<Operations extends readonly NeonOperationId[], Inject, Workflows extends readonly NeonWorkflowId[] = []> = {
|
|
15
18
|
[Operation in Operations[number]]: InjectedNeonTool<ReturnType<OperationFactories[Operation]>, Inject>;
|
|
19
|
+
} & {
|
|
20
|
+
[Workflow in Workflows[number]]: InjectedNeonTool<ReturnType<WorkflowFactories[Workflow]>, Inject>;
|
|
16
21
|
};
|
|
17
22
|
type WithPublishedId<Tool> = Tool extends {
|
|
18
23
|
id: string;
|
|
19
24
|
} ? Omit<Tool, "id"> & {
|
|
20
25
|
id: string;
|
|
21
26
|
} : Tool;
|
|
22
|
-
export interface NeonToolsClientOptions extends Pick<NeonConfig, "baseUrl" | "fetch">, Omit<NeonToolCustomizeOptions, "name" | "names"> {
|
|
27
|
+
export interface NeonToolsClientOptions extends Pick<NeonConfig, "baseUrl" | "fetch" | "wait">, Omit<NeonToolCustomizeOptions, "name" | "names"> {
|
|
23
28
|
apiKey?: NeonBearerCredential;
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
operations:
|
|
30
|
+
interface OperationSelection {
|
|
31
|
+
operations: readonly NeonOperationId[];
|
|
32
|
+
workflows?: readonly NeonWorkflowId[];
|
|
33
|
+
}
|
|
34
|
+
interface WorkflowSelection {
|
|
35
|
+
workflows: readonly NeonWorkflowId[];
|
|
36
|
+
operations?: readonly NeonOperationId[];
|
|
27
37
|
}
|
|
28
|
-
type
|
|
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> = {
|
|
29
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]>>;
|
|
30
62
|
};
|
|
31
|
-
type NamedNeonTool<
|
|
32
|
-
|
|
63
|
+
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;
|
|
65
|
+
export declare function createNeonTools<const T extends CreateNeonToolsInput, const Inject extends NeonToolInjectOptions | undefined = undefined>(options: T & {
|
|
33
66
|
inject?: Inject;
|
|
34
67
|
} & ({
|
|
35
68
|
name: (id: string) => string;
|
|
@@ -37,11 +70,11 @@ export declare function createNeonTools<const Operations extends readonly NeonOp
|
|
|
37
70
|
} | {
|
|
38
71
|
names: NeonToolNameOverrides;
|
|
39
72
|
name?: (id: string) => string;
|
|
40
|
-
})):
|
|
41
|
-
export declare function createNeonTools<const
|
|
73
|
+
})): NamedNeonToolsFor<T, Inject>;
|
|
74
|
+
export declare function createNeonTools<const T extends CreateNeonToolsInput, const Inject extends NeonToolInjectOptions | undefined = undefined>(options: T & {
|
|
42
75
|
inject?: Inject;
|
|
43
|
-
}):
|
|
44
|
-
export declare function createNeonTool<const
|
|
76
|
+
}): NeonToolsFor<T, Inject>;
|
|
77
|
+
export declare function createNeonTool<const Id extends NeonToolId, const Inject extends NeonToolInjectOptions | undefined = undefined>(id: Id, options: NeonToolsClientOptions & {
|
|
45
78
|
inject?: Inject;
|
|
46
79
|
} & ({
|
|
47
80
|
name: (id: string) => string;
|
|
@@ -49,8 +82,8 @@ export declare function createNeonTool<const Operation extends NeonOperationId,
|
|
|
49
82
|
} | {
|
|
50
83
|
names: NeonToolNameOverrides;
|
|
51
84
|
name?: (id: string) => string;
|
|
52
|
-
})): NamedNeonTool<
|
|
53
|
-
export declare function createNeonTool<const
|
|
85
|
+
})): NamedNeonTool<Id, Inject>;
|
|
86
|
+
export declare function createNeonTool<const Id extends NeonToolId, const Inject extends NeonToolInjectOptions | undefined = undefined>(id: Id, options: NeonToolsClientOptions & {
|
|
54
87
|
inject?: Inject;
|
|
55
|
-
}): Inject extends NeonToolInjectOptions ? InjectedNeonTool<
|
|
88
|
+
}): Inject extends NeonToolInjectOptions ? InjectedNeonTool<ToolForId<Id>, Inject> : ToolForId<Id>;
|
|
56
89
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;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;
|
|
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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MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAY7D,wBAAgB,cAAc,CAC7B,KAAK,CAAC,EAAE,SAAS,UAAU,EAC3B,KAAK,CAAC,MAAM,SAAS,qBAAqB,GAAG,SAAS,GAAG,SAAS,EAElE,EAAE,EAAE,EAAE,EACN,OAAO,EAAE,sBAAsB,GAAG;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,CACA;IAAE,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,qBAAqB,CAAA;CAAE,GAC/D;IAAE,KAAK,EAAE,qBAAqB,CAAC;IAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAA;CAAE,CACjE,GACA,aAAa,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;AAC7B,wBAAgB,cAAc,CAC7B,KAAK,CAAC,EAAE,SAAS,UAAU,EAC3B,KAAK,CAAC,MAAM,SAAS,qBAAqB,GAAG,SAAS,GAAG,SAAS,EAElE,EAAE,EAAE,EAAE,EACN,OAAO,EAAE,sBAAsB,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACnD,MAAM,SAAS,qBAAqB,GACpC,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,GACvC,SAAS,CAAC,EAAE,CAAC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { missingBearerCredential, requireBearerCredential } from "./lib/auth.js";
|
|
2
2
|
import { applyToolCustomization, assertToolCustomizeOptions, hasToolCustomization } from "./lib/customize.js";
|
|
3
|
+
import { isNeonWorkflowId, workflowFactoryFor, workflowIds } from "./lib/workflows.js";
|
|
3
4
|
import { operationFactories, operationIds } from "./operations.gen.js";
|
|
4
5
|
import { NeonError, createNeonClient } from "@neon/sdk";
|
|
5
6
|
//#region src/index.ts
|
|
6
7
|
const createRawClient = (options) => createNeonClient({
|
|
7
8
|
apiKey: options.apiKey === void 0 ? missingBearerCredential : requireBearerCredential(options.apiKey),
|
|
8
9
|
...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
|
|
9
|
-
...options.fetch === void 0 ? {} : { fetch: options.fetch }
|
|
10
|
+
...options.fetch === void 0 ? {} : { fetch: options.fetch },
|
|
11
|
+
...options.wait === void 0 ? {} : { wait: options.wait }
|
|
10
12
|
}).client;
|
|
11
13
|
const operationFactoryFor = (operationId) => {
|
|
12
14
|
const knownOperationId = operationIds.find((candidate) => candidate === operationId);
|
|
@@ -19,44 +21,57 @@ const assertKnownNameKeys = (names, tools) => {
|
|
|
19
21
|
const unknown = Object.keys(names).filter((key) => !known.has(key));
|
|
20
22
|
if (unknown.length > 0) throw new TypeError(`Unknown Neon tool name override: ${unknown.join(", ")}`);
|
|
21
23
|
};
|
|
22
|
-
function assertNeonTools(value, operations) {
|
|
24
|
+
function assertNeonTools(value, operations, workflows) {
|
|
23
25
|
if (typeof value !== "object" || value === null) throw new TypeError("Expected generated Neon tools to be an object.");
|
|
24
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}".`);
|
|
25
28
|
}
|
|
26
29
|
const bindTools = (options) => {
|
|
27
30
|
assertToolCustomizeOptions(options);
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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))];
|
|
33
39
|
});
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
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)];
|
|
37
45
|
});
|
|
46
|
+
const rawEntries = [...operationEntries, ...workflowEntries];
|
|
38
47
|
assertKnownNameKeys(options.names, rawEntries.map(([, tool]) => tool));
|
|
39
|
-
const entries = rawEntries.map(([
|
|
40
|
-
return [
|
|
48
|
+
const entries = rawEntries.map(([id, tool]) => {
|
|
49
|
+
return [id, hasToolCustomization(options) ? applyToolCustomization(tool, options) : tool];
|
|
41
50
|
});
|
|
42
51
|
const publishedIds = /* @__PURE__ */ new Map();
|
|
43
|
-
for (const [
|
|
52
|
+
for (const [id, tool] of entries) {
|
|
44
53
|
const previous = publishedIds.get(tool.id);
|
|
45
|
-
if (previous !== void 0) throw new Error(`Duplicate Neon tool id "${tool.id}" for ${previous}, ${
|
|
46
|
-
publishedIds.set(tool.id,
|
|
54
|
+
if (previous !== void 0) throw new Error(`Duplicate Neon tool id "${tool.id}" for ${previous}, ${id}`);
|
|
55
|
+
publishedIds.set(tool.id, id);
|
|
47
56
|
}
|
|
48
57
|
const tools = Object.fromEntries(entries);
|
|
49
|
-
assertNeonTools(tools,
|
|
58
|
+
assertNeonTools(tools, operations, workflows);
|
|
50
59
|
return tools;
|
|
51
60
|
};
|
|
52
61
|
function createNeonTools(options) {
|
|
53
62
|
return bindTools(options);
|
|
54
63
|
}
|
|
55
|
-
function createNeonTool(
|
|
64
|
+
function createNeonTool(id, options) {
|
|
56
65
|
assertToolCustomizeOptions(options);
|
|
57
|
-
|
|
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
|
+
}
|
|
58
73
|
assertKnownNameKeys(options.names, [tool]);
|
|
59
74
|
return hasToolCustomization(options) ? applyToolCustomization(tool, options) : tool;
|
|
60
75
|
}
|
|
61
76
|
//#endregion
|
|
62
|
-
export { NeonError, createNeonTool, createNeonTools, operationIds };
|
|
77
|
+
export { NeonError, createNeonTool, createNeonTools, operationIds, workflowIds };
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { type NeonConfig } from "@neon/sdk";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
import { type NeonBearerCredential } from "./auth.js";
|
|
4
|
+
import type { NeonTool } from "./operation.js";
|
|
5
|
+
export interface WorkflowClientOptions {
|
|
6
|
+
apiKey?: NeonBearerCredential;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
fetch?: typeof fetch;
|
|
9
|
+
wait?: NeonConfig["wait"];
|
|
10
|
+
}
|
|
11
|
+
export declare const createBranchWithComputeInputSchema: z.ZodObject<{
|
|
12
|
+
project_id: z.ZodString;
|
|
13
|
+
name: z.ZodOptional<z.ZodString>;
|
|
14
|
+
parent_id: z.ZodOptional<z.ZodString>;
|
|
15
|
+
compute: z.ZodOptional<z.ZodObject<{
|
|
16
|
+
min_cu: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
max_cu: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
suspend_timeout_seconds: z.ZodOptional<z.ZodInt>;
|
|
19
|
+
}, z.core.$strict>>;
|
|
20
|
+
pooled: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
}, z.core.$strict>;
|
|
22
|
+
export declare const createProjectAndConnectInputSchema: z.ZodObject<{
|
|
23
|
+
pooled: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
settings: z.ZodOptional<z.ZodObject<{
|
|
25
|
+
quota: z.ZodOptional<z.ZodObject<{
|
|
26
|
+
active_time_seconds: z.ZodOptional<z.ZodInt>;
|
|
27
|
+
compute_time_seconds: z.ZodOptional<z.ZodInt>;
|
|
28
|
+
written_data_bytes: z.ZodOptional<z.ZodInt>;
|
|
29
|
+
data_transfer_bytes: z.ZodOptional<z.ZodInt>;
|
|
30
|
+
logical_size_bytes: z.ZodOptional<z.ZodInt>;
|
|
31
|
+
}, z.core.$strict>>;
|
|
32
|
+
allowed_ips: z.ZodOptional<z.ZodObject<{
|
|
33
|
+
ips: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
34
|
+
protected_branches_only: z.ZodOptional<z.ZodBoolean>;
|
|
35
|
+
}, z.core.$strict>>;
|
|
36
|
+
enable_logical_replication: z.ZodOptional<z.ZodBoolean>;
|
|
37
|
+
maintenance_window: z.ZodOptional<z.ZodObject<{
|
|
38
|
+
weekdays: z.ZodArray<z.ZodInt>;
|
|
39
|
+
start_time: z.ZodString;
|
|
40
|
+
end_time: z.ZodString;
|
|
41
|
+
}, z.core.$strict>>;
|
|
42
|
+
block_public_connections: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
block_vpc_connections: z.ZodOptional<z.ZodBoolean>;
|
|
44
|
+
audit_log_level: z.ZodOptional<z.ZodEnum<{
|
|
45
|
+
base: "base";
|
|
46
|
+
extended: "extended";
|
|
47
|
+
full: "full";
|
|
48
|
+
}>>;
|
|
49
|
+
hipaa: z.ZodOptional<z.ZodBoolean>;
|
|
50
|
+
preload_libraries: z.ZodOptional<z.ZodObject<{
|
|
51
|
+
use_defaults: z.ZodOptional<z.ZodBoolean>;
|
|
52
|
+
enabled_libraries: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
53
|
+
}, z.core.$strict>>;
|
|
54
|
+
}, z.core.$strict>>;
|
|
55
|
+
name: z.ZodOptional<z.ZodString>;
|
|
56
|
+
branch: z.ZodOptional<z.ZodObject<{
|
|
57
|
+
name: z.ZodOptional<z.ZodString>;
|
|
58
|
+
role_name: z.ZodOptional<z.ZodString>;
|
|
59
|
+
database_name: z.ZodOptional<z.ZodString>;
|
|
60
|
+
annotations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
61
|
+
}, z.core.$strict>>;
|
|
62
|
+
autoscaling_limit_min_cu: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
autoscaling_limit_max_cu: z.ZodOptional<z.ZodNumber>;
|
|
64
|
+
provisioner: z.ZodOptional<z.ZodString>;
|
|
65
|
+
region_id: z.ZodOptional<z.ZodString>;
|
|
66
|
+
default_endpoint_settings: z.ZodOptional<z.ZodObject<{
|
|
67
|
+
pg_settings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
68
|
+
pgbouncer_settings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
69
|
+
autoscaling_limit_min_cu: z.ZodOptional<z.ZodNumber>;
|
|
70
|
+
autoscaling_limit_max_cu: z.ZodOptional<z.ZodNumber>;
|
|
71
|
+
suspend_timeout_seconds: z.ZodOptional<z.ZodInt>;
|
|
72
|
+
}, z.core.$strict>>;
|
|
73
|
+
pg_version: z.ZodOptional<z.ZodInt>;
|
|
74
|
+
store_passwords: z.ZodOptional<z.ZodBoolean>;
|
|
75
|
+
history_retention_seconds: z.ZodOptional<z.ZodInt>;
|
|
76
|
+
org_id: z.ZodOptional<z.ZodString>;
|
|
77
|
+
}, z.core.$strict>;
|
|
78
|
+
export declare const workflowIds: readonly ["createBranchWithCompute", "createProjectAndConnect"];
|
|
79
|
+
export type NeonWorkflowId = (typeof workflowIds)[number];
|
|
80
|
+
export declare const workflowFactories: {
|
|
81
|
+
createBranchWithCompute: (options: WorkflowClientOptions) => NeonTool<z.ZodObject<{
|
|
82
|
+
project_id: z.ZodString;
|
|
83
|
+
name: z.ZodOptional<z.ZodString>;
|
|
84
|
+
parent_id: z.ZodOptional<z.ZodString>;
|
|
85
|
+
compute: z.ZodOptional<z.ZodObject<{
|
|
86
|
+
min_cu: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
max_cu: z.ZodOptional<z.ZodNumber>;
|
|
88
|
+
suspend_timeout_seconds: z.ZodOptional<z.ZodInt>;
|
|
89
|
+
}, z.core.$strict>>;
|
|
90
|
+
pooled: z.ZodOptional<z.ZodBoolean>;
|
|
91
|
+
}, z.core.$strict>, "create_branch_with_compute", {
|
|
92
|
+
branch: {
|
|
93
|
+
id: string;
|
|
94
|
+
project_id: string;
|
|
95
|
+
parent_id?: string | null | undefined;
|
|
96
|
+
parent_lsn?: string | null | undefined;
|
|
97
|
+
parent_timestamp?: string | null | undefined;
|
|
98
|
+
name: string;
|
|
99
|
+
current_state: import("@neon/sdk").BranchState;
|
|
100
|
+
pending_state?: string | null | undefined;
|
|
101
|
+
state_changed_at: string;
|
|
102
|
+
logical_size?: number | null | undefined;
|
|
103
|
+
creation_source: string;
|
|
104
|
+
primary?: boolean | null | undefined;
|
|
105
|
+
default: boolean;
|
|
106
|
+
protected: boolean;
|
|
107
|
+
cpu_used_sec: number;
|
|
108
|
+
compute_time_seconds: number;
|
|
109
|
+
active_time_seconds: number;
|
|
110
|
+
written_data_bytes: number;
|
|
111
|
+
data_transfer_bytes: number;
|
|
112
|
+
created_at: string;
|
|
113
|
+
updated_at: string;
|
|
114
|
+
ttl_interval_seconds?: number | null | undefined;
|
|
115
|
+
expires_at?: string | null | undefined;
|
|
116
|
+
last_reset_at?: string | null | undefined;
|
|
117
|
+
created_by?: {
|
|
118
|
+
name?: string | null | undefined;
|
|
119
|
+
image?: string | null | undefined;
|
|
120
|
+
} | null | undefined;
|
|
121
|
+
init_source?: string | null | undefined;
|
|
122
|
+
restore_status?: string | null | undefined;
|
|
123
|
+
restored_from?: string | null | undefined;
|
|
124
|
+
restored_as?: string | null | undefined;
|
|
125
|
+
restricted_actions?: {
|
|
126
|
+
name: string;
|
|
127
|
+
reason: string;
|
|
128
|
+
}[] | null | undefined;
|
|
129
|
+
recovery?: {
|
|
130
|
+
deleted_at: string;
|
|
131
|
+
recoverable_until: string;
|
|
132
|
+
deletion_method: "user" | "ttl";
|
|
133
|
+
} | null | undefined;
|
|
134
|
+
};
|
|
135
|
+
endpoint: {
|
|
136
|
+
host: string;
|
|
137
|
+
id: string;
|
|
138
|
+
name?: string | null | undefined;
|
|
139
|
+
project_id: string;
|
|
140
|
+
branch_id: string;
|
|
141
|
+
autoscaling_limit_min_cu: import("@neon/sdk").ComputeUnit;
|
|
142
|
+
autoscaling_limit_max_cu: import("@neon/sdk").ComputeUnit;
|
|
143
|
+
region_id: string;
|
|
144
|
+
type: import("@neon/sdk").EndpointType;
|
|
145
|
+
current_state: import("@neon/sdk").EndpointState;
|
|
146
|
+
pending_state?: import("@neon/sdk").EndpointState | null | undefined;
|
|
147
|
+
settings: {
|
|
148
|
+
pg_settings?: {
|
|
149
|
+
[x: string]: string;
|
|
150
|
+
} | null | undefined;
|
|
151
|
+
pgbouncer_settings?: {
|
|
152
|
+
[x: string]: string;
|
|
153
|
+
} | null | undefined;
|
|
154
|
+
preload_libraries?: {
|
|
155
|
+
use_defaults?: boolean | null | undefined;
|
|
156
|
+
enabled_libraries?: string[] | null | undefined;
|
|
157
|
+
} | null | undefined;
|
|
158
|
+
};
|
|
159
|
+
pooler_enabled: boolean;
|
|
160
|
+
pooler_mode: import("@neon/sdk").EndpointPoolerMode;
|
|
161
|
+
disabled: boolean;
|
|
162
|
+
passwordless_access: boolean;
|
|
163
|
+
last_active?: string | null | undefined;
|
|
164
|
+
creation_source: string;
|
|
165
|
+
created_at: string;
|
|
166
|
+
updated_at: string;
|
|
167
|
+
started_at?: string | null | undefined;
|
|
168
|
+
suspended_at?: string | null | undefined;
|
|
169
|
+
proxy_host: string;
|
|
170
|
+
suspend_timeout_seconds: import("@neon/sdk").SuspendTimeoutSeconds;
|
|
171
|
+
provisioner: import("@neon/sdk").Provisioner;
|
|
172
|
+
compute_release_version?: string | null | undefined;
|
|
173
|
+
};
|
|
174
|
+
connectionString: string;
|
|
175
|
+
}>;
|
|
176
|
+
createProjectAndConnect: (options: WorkflowClientOptions) => NeonTool<z.ZodObject<{
|
|
177
|
+
pooled: z.ZodOptional<z.ZodBoolean>;
|
|
178
|
+
settings: z.ZodOptional<z.ZodObject<{
|
|
179
|
+
quota: z.ZodOptional<z.ZodObject<{
|
|
180
|
+
active_time_seconds: z.ZodOptional<z.ZodInt>;
|
|
181
|
+
compute_time_seconds: z.ZodOptional<z.ZodInt>;
|
|
182
|
+
written_data_bytes: z.ZodOptional<z.ZodInt>;
|
|
183
|
+
data_transfer_bytes: z.ZodOptional<z.ZodInt>;
|
|
184
|
+
logical_size_bytes: z.ZodOptional<z.ZodInt>;
|
|
185
|
+
}, z.core.$strict>>;
|
|
186
|
+
allowed_ips: z.ZodOptional<z.ZodObject<{
|
|
187
|
+
ips: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
188
|
+
protected_branches_only: z.ZodOptional<z.ZodBoolean>;
|
|
189
|
+
}, z.core.$strict>>;
|
|
190
|
+
enable_logical_replication: z.ZodOptional<z.ZodBoolean>;
|
|
191
|
+
maintenance_window: z.ZodOptional<z.ZodObject<{
|
|
192
|
+
weekdays: z.ZodArray<z.ZodInt>;
|
|
193
|
+
start_time: z.ZodString;
|
|
194
|
+
end_time: z.ZodString;
|
|
195
|
+
}, z.core.$strict>>;
|
|
196
|
+
block_public_connections: z.ZodOptional<z.ZodBoolean>;
|
|
197
|
+
block_vpc_connections: z.ZodOptional<z.ZodBoolean>;
|
|
198
|
+
audit_log_level: z.ZodOptional<z.ZodEnum<{
|
|
199
|
+
base: "base";
|
|
200
|
+
extended: "extended";
|
|
201
|
+
full: "full";
|
|
202
|
+
}>>;
|
|
203
|
+
hipaa: z.ZodOptional<z.ZodBoolean>;
|
|
204
|
+
preload_libraries: z.ZodOptional<z.ZodObject<{
|
|
205
|
+
use_defaults: z.ZodOptional<z.ZodBoolean>;
|
|
206
|
+
enabled_libraries: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
207
|
+
}, z.core.$strict>>;
|
|
208
|
+
}, z.core.$strict>>;
|
|
209
|
+
name: z.ZodOptional<z.ZodString>;
|
|
210
|
+
branch: z.ZodOptional<z.ZodObject<{
|
|
211
|
+
name: z.ZodOptional<z.ZodString>;
|
|
212
|
+
role_name: z.ZodOptional<z.ZodString>;
|
|
213
|
+
database_name: z.ZodOptional<z.ZodString>;
|
|
214
|
+
annotations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
215
|
+
}, z.core.$strict>>;
|
|
216
|
+
autoscaling_limit_min_cu: z.ZodOptional<z.ZodNumber>;
|
|
217
|
+
autoscaling_limit_max_cu: z.ZodOptional<z.ZodNumber>;
|
|
218
|
+
provisioner: z.ZodOptional<z.ZodString>;
|
|
219
|
+
region_id: z.ZodOptional<z.ZodString>;
|
|
220
|
+
default_endpoint_settings: z.ZodOptional<z.ZodObject<{
|
|
221
|
+
pg_settings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
222
|
+
pgbouncer_settings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
223
|
+
autoscaling_limit_min_cu: z.ZodOptional<z.ZodNumber>;
|
|
224
|
+
autoscaling_limit_max_cu: z.ZodOptional<z.ZodNumber>;
|
|
225
|
+
suspend_timeout_seconds: z.ZodOptional<z.ZodInt>;
|
|
226
|
+
}, z.core.$strict>>;
|
|
227
|
+
pg_version: z.ZodOptional<z.ZodInt>;
|
|
228
|
+
store_passwords: z.ZodOptional<z.ZodBoolean>;
|
|
229
|
+
history_retention_seconds: z.ZodOptional<z.ZodInt>;
|
|
230
|
+
org_id: z.ZodOptional<z.ZodString>;
|
|
231
|
+
}, z.core.$strict>, "create_project_and_connect", {
|
|
232
|
+
project: {
|
|
233
|
+
data_storage_bytes_hour: number;
|
|
234
|
+
data_transfer_bytes: number;
|
|
235
|
+
written_data_bytes: number;
|
|
236
|
+
compute_time_seconds: number;
|
|
237
|
+
active_time_seconds: number;
|
|
238
|
+
cpu_used_sec: number;
|
|
239
|
+
id: string;
|
|
240
|
+
platform_id: string;
|
|
241
|
+
region_id: string;
|
|
242
|
+
name: string;
|
|
243
|
+
provisioner: import("@neon/sdk").Provisioner;
|
|
244
|
+
default_endpoint_settings?: {
|
|
245
|
+
pg_settings?: {
|
|
246
|
+
[x: string]: string;
|
|
247
|
+
} | null | undefined;
|
|
248
|
+
pgbouncer_settings?: {
|
|
249
|
+
[x: string]: string;
|
|
250
|
+
} | null | undefined;
|
|
251
|
+
autoscaling_limit_min_cu?: number | null | undefined;
|
|
252
|
+
autoscaling_limit_max_cu?: number | null | undefined;
|
|
253
|
+
suspend_timeout_seconds?: number | null | undefined;
|
|
254
|
+
} | null | undefined;
|
|
255
|
+
settings?: {
|
|
256
|
+
quota?: {
|
|
257
|
+
active_time_seconds?: number | null | undefined;
|
|
258
|
+
compute_time_seconds?: number | null | undefined;
|
|
259
|
+
written_data_bytes?: number | null | undefined;
|
|
260
|
+
data_transfer_bytes?: number | null | undefined;
|
|
261
|
+
logical_size_bytes?: number | null | undefined;
|
|
262
|
+
} | null | undefined;
|
|
263
|
+
allowed_ips?: {
|
|
264
|
+
ips?: string[] | null | undefined;
|
|
265
|
+
protected_branches_only?: boolean | null | undefined;
|
|
266
|
+
} | null | undefined;
|
|
267
|
+
enable_logical_replication?: boolean | null | undefined;
|
|
268
|
+
maintenance_window?: {
|
|
269
|
+
weekdays: number[];
|
|
270
|
+
start_time: string;
|
|
271
|
+
end_time: string;
|
|
272
|
+
} | null | undefined;
|
|
273
|
+
block_public_connections?: boolean | null | undefined;
|
|
274
|
+
block_vpc_connections?: boolean | null | undefined;
|
|
275
|
+
audit_log_level?: import("@neon/sdk").ProjectAuditLogLevel | null | undefined;
|
|
276
|
+
hipaa?: boolean | null | undefined;
|
|
277
|
+
preload_libraries?: {
|
|
278
|
+
use_defaults?: boolean | null | undefined;
|
|
279
|
+
enabled_libraries?: string[] | null | undefined;
|
|
280
|
+
} | null | undefined;
|
|
281
|
+
} | null | undefined;
|
|
282
|
+
pg_version: import("@neon/sdk").PgVersion;
|
|
283
|
+
proxy_host: string;
|
|
284
|
+
branch_logical_size_limit: number;
|
|
285
|
+
branch_logical_size_limit_bytes: number;
|
|
286
|
+
store_passwords: boolean;
|
|
287
|
+
maintenance_starts_at?: string | null | undefined;
|
|
288
|
+
creation_source: string;
|
|
289
|
+
history_retention_seconds: number;
|
|
290
|
+
created_at: string;
|
|
291
|
+
updated_at: string;
|
|
292
|
+
synthetic_storage_size?: number | null | undefined;
|
|
293
|
+
consumption_period_start: string;
|
|
294
|
+
consumption_period_end: string;
|
|
295
|
+
quota_reset_at?: string | null | undefined;
|
|
296
|
+
owner_id: string;
|
|
297
|
+
owner?: {
|
|
298
|
+
email: string;
|
|
299
|
+
name: string;
|
|
300
|
+
branches_limit: number;
|
|
301
|
+
subscription_type: import("@neon/sdk").BillingSubscriptionType;
|
|
302
|
+
} | null | undefined;
|
|
303
|
+
compute_last_active_at?: string | null | undefined;
|
|
304
|
+
org_id?: string | null | undefined;
|
|
305
|
+
maintenance_scheduled_for?: string | null | undefined;
|
|
306
|
+
hipaa_enabled_at?: string | null | undefined;
|
|
307
|
+
effective_project_permission?: (import("@neon/sdk").ProjectPermissionLevel | null) | undefined;
|
|
308
|
+
};
|
|
309
|
+
connectionString: string;
|
|
310
|
+
}>;
|
|
311
|
+
};
|
|
312
|
+
export type WorkflowFactories = typeof workflowFactories;
|
|
313
|
+
export declare const isNeonWorkflowId: (id: string) => id is NeonWorkflowId;
|
|
314
|
+
export declare const workflowFactoryFor: (workflowId: NeonWorkflowId) => WorkflowFactories[NeonWorkflowId];
|
|
315
|
+
//# sourceMappingURL=workflows.d.ts.map
|
|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AAI,IAAI,MAAM,KAAG,EAAE,IAAI,cACJ,CAAC;AAEjD,eAAO,MAAM,kBAAkB,GAC9B,YAAY,cAAc,KACxB,iBAAiB,CAAC,cAAc,CAQlC,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { missingBearerCredential, requireBearerCredential } from "./auth.js";
|
|
2
|
+
import { zBranchCreateRequest, zComputeUnit, zCreateProjectBody, zCreateProjectBranchPath, zSuspendTimeoutSeconds } from "../generated/zod.gen.js";
|
|
3
|
+
import { toToolResult } from "./result.js";
|
|
4
|
+
import { createNeonClient } from "@neon/sdk";
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
//#region src/lib/workflows.ts
|
|
7
|
+
const branchCreateFields = zBranchCreateRequest.shape.branch.unwrap().shape;
|
|
8
|
+
const projectCreateFields = zCreateProjectBody.shape.project.shape;
|
|
9
|
+
const writeAnnotations = {
|
|
10
|
+
readOnlyHint: false,
|
|
11
|
+
destructiveHint: true,
|
|
12
|
+
openWorldHint: true
|
|
13
|
+
};
|
|
14
|
+
const pooledField = z.boolean().describe("Return a pooled connection string. Default true. Set false for a direct connection.").optional();
|
|
15
|
+
const createBranchWithComputeInputSchema = z.strictObject({
|
|
16
|
+
project_id: zCreateProjectBranchPath.shape.project_id,
|
|
17
|
+
name: branchCreateFields.name,
|
|
18
|
+
parent_id: branchCreateFields.parent_id,
|
|
19
|
+
compute: z.strictObject({
|
|
20
|
+
min_cu: zComputeUnit.optional(),
|
|
21
|
+
max_cu: zComputeUnit.optional(),
|
|
22
|
+
suspend_timeout_seconds: zSuspendTimeoutSeconds.optional()
|
|
23
|
+
}).optional(),
|
|
24
|
+
pooled: pooledField
|
|
25
|
+
});
|
|
26
|
+
const createProjectAndConnectInputSchema = z.strictObject({
|
|
27
|
+
...projectCreateFields,
|
|
28
|
+
pooled: pooledField
|
|
29
|
+
});
|
|
30
|
+
const workflowIds = ["createBranchWithCompute", "createProjectAndConnect"];
|
|
31
|
+
const resolveApiKey = (options, context) => {
|
|
32
|
+
if (context !== void 0 && "apiKey" in context) {
|
|
33
|
+
if (context.apiKey === void 0) throw new TypeError("A Neon API key or OAuth access token is required");
|
|
34
|
+
return requireBearerCredential(context.apiKey);
|
|
35
|
+
}
|
|
36
|
+
return options.apiKey === void 0 ? missingBearerCredential : requireBearerCredential(options.apiKey);
|
|
37
|
+
};
|
|
38
|
+
const workflowClient = (options, context) => createNeonClient({
|
|
39
|
+
apiKey: resolveApiKey(options, context),
|
|
40
|
+
throwOnError: true,
|
|
41
|
+
...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
|
|
42
|
+
...options.fetch === void 0 ? {} : { fetch: options.fetch },
|
|
43
|
+
...options.wait === void 0 ? {} : { wait: options.wait }
|
|
44
|
+
});
|
|
45
|
+
const bindWorkflow = (options, tool, run) => ({
|
|
46
|
+
...tool,
|
|
47
|
+
async execute(input, context) {
|
|
48
|
+
const parsed = await tool.inputSchema.parseAsync(input);
|
|
49
|
+
const result = await run(workflowClient(options, context), parsed, context?.signal);
|
|
50
|
+
return toToolResult(result);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const createBranchWithComputeTool = (options) => bindWorkflow(options, {
|
|
54
|
+
operationId: "createBranchWithCompute",
|
|
55
|
+
id: "create_branch_with_compute",
|
|
56
|
+
title: "Create branch with compute",
|
|
57
|
+
description: "Create a branch with a read-write endpoint and return its connection string. Use this instead of create_project_branch when the next step needs to connect: create_project_branch omits compute unless you pass endpoints, and it does not wait or return a connection string. The call waits until the compute is ready, up to five minutes by default.",
|
|
58
|
+
inputSchema: createBranchWithComputeInputSchema,
|
|
59
|
+
annotations: writeAnnotations,
|
|
60
|
+
requiresApproval: true,
|
|
61
|
+
metadata: {
|
|
62
|
+
method: "POST",
|
|
63
|
+
path: "/projects/{project_id}/branches",
|
|
64
|
+
stability: "stable",
|
|
65
|
+
deprecated: false,
|
|
66
|
+
tags: ["Branch"]
|
|
67
|
+
}
|
|
68
|
+
}, (neon, input, signal) => neon.branches.createWithCompute(input.project_id, {
|
|
69
|
+
name: input.name,
|
|
70
|
+
parentId: input.parent_id,
|
|
71
|
+
compute: input.compute === void 0 ? void 0 : {
|
|
72
|
+
minCu: input.compute.min_cu,
|
|
73
|
+
maxCu: input.compute.max_cu,
|
|
74
|
+
suspendTimeoutSeconds: input.compute.suspend_timeout_seconds
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
signal,
|
|
78
|
+
...input.pooled === void 0 ? {} : { pooled: input.pooled }
|
|
79
|
+
}));
|
|
80
|
+
const createProjectAndConnectTool = (options) => bindWorkflow(options, {
|
|
81
|
+
operationId: "createProjectAndConnect",
|
|
82
|
+
id: "create_project_and_connect",
|
|
83
|
+
title: "Create project and connect",
|
|
84
|
+
description: "Create a project and return a connection string to its default branch. Use this instead of create_project when the next step needs to connect. The call waits until the default compute is ready, up to five minutes by default.",
|
|
85
|
+
inputSchema: createProjectAndConnectInputSchema,
|
|
86
|
+
annotations: writeAnnotations,
|
|
87
|
+
requiresApproval: true,
|
|
88
|
+
metadata: {
|
|
89
|
+
method: "POST",
|
|
90
|
+
path: "/projects",
|
|
91
|
+
stability: "stable",
|
|
92
|
+
deprecated: false,
|
|
93
|
+
tags: ["Project"]
|
|
94
|
+
}
|
|
95
|
+
}, (neon, input, signal) => {
|
|
96
|
+
const { pooled, ...project } = input;
|
|
97
|
+
return neon.projects.createAndConnect(project, {
|
|
98
|
+
signal,
|
|
99
|
+
...pooled === void 0 ? {} : { pooled }
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
const workflowFactories = {
|
|
103
|
+
createBranchWithCompute: createBranchWithComputeTool,
|
|
104
|
+
createProjectAndConnect: createProjectAndConnectTool
|
|
105
|
+
};
|
|
106
|
+
const isNeonWorkflowId = (id) => workflowIds.includes(id);
|
|
107
|
+
const workflowFactoryFor = (workflowId) => {
|
|
108
|
+
const knownWorkflowId = workflowIds.find((candidate) => candidate === workflowId);
|
|
109
|
+
if (knownWorkflowId === void 0) throw new TypeError(`Unknown Neon workflow "${workflowId}".`);
|
|
110
|
+
return workflowFactories[knownWorkflowId];
|
|
111
|
+
};
|
|
112
|
+
//#endregion
|
|
113
|
+
export { createBranchWithComputeInputSchema, createProjectAndConnectInputSchema, isNeonWorkflowId, workflowFactories, workflowFactoryFor, workflowIds };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neon/tools",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Agent tools for the Neon Management API and SDK workflows, compatible with MCP, Eve, and Mastra.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"neon",
|
|
7
7
|
"database",
|