@neon/tools 0.0.0 → 0.2.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.
@@ -0,0 +1,29 @@
1
+ import { type NeonConfig, NeonError } from "@neon/sdk";
2
+ import { type NeonBearerCredential } from "./lib/auth.js";
3
+ import { type InjectedNeonTool, type NeonToolCustomizeOptions, type NeonToolInjectOptions } from "./lib/customize.js";
4
+ import { type NeonOperationId, operationFactories, operationIds } from "./operations.gen.js";
5
+ export type { NeonBearerCredential } from "./lib/auth.js";
6
+ export type { InjectedNeonTool, NeonToolCustomizeOptions, NeonToolDescriptionOverrides, NeonToolDescriptionSource, NeonToolInjectOptions, NeonToolInjectValue, NeonToolOnExecute, NeonToolOnExecuteEvent, } from "./lib/customize.js";
7
+ export type { JsonSafe, JsonSafeBlob, NeonTool, NeonToolAnnotations, NeonToolExecutionContext, NeonToolMetadata, NeonToolResult, } from "./lib/operation.js";
8
+ export type { NeonOperationId };
9
+ export { NeonError, operationIds };
10
+ type OperationFactories = typeof operationFactories;
11
+ export type NeonTools<Operations extends readonly NeonOperationId[]> = {
12
+ [Operation in Operations[number]]: ReturnType<OperationFactories[Operation]>;
13
+ };
14
+ export type InjectedNeonTools<Operations extends readonly NeonOperationId[], Inject> = {
15
+ [Operation in Operations[number]]: InjectedNeonTool<ReturnType<OperationFactories[Operation]>, Inject>;
16
+ };
17
+ export interface NeonToolsClientOptions extends Pick<NeonConfig, "baseUrl" | "fetch">, NeonToolCustomizeOptions {
18
+ apiKey?: NeonBearerCredential;
19
+ }
20
+ export interface CreateNeonToolsOptions<Operations extends readonly NeonOperationId[]> extends NeonToolsClientOptions {
21
+ operations: Operations;
22
+ }
23
+ export declare const createNeonTools: <const Operations extends readonly NeonOperationId[], const Inject extends NeonToolInjectOptions | undefined = undefined>(options: CreateNeonToolsOptions<Operations> & {
24
+ inject?: Inject;
25
+ }) => Inject extends NeonToolInjectOptions ? InjectedNeonTools<Operations, Inject> : NeonTools<Operations>;
26
+ export declare function createNeonTool<const Operation extends NeonOperationId, const Inject extends NeonToolInjectOptions | undefined = undefined>(operationId: Operation, options: NeonToolsClientOptions & {
27
+ inject?: Inject;
28
+ }): Inject extends NeonToolInjectOptions ? InjectedNeonTool<ReturnType<OperationFactories[Operation]>, Inject> : ReturnType<OperationFactories[Operation]>;
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,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,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;AAChC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;AAEnC,KAAK,kBAAkB,GAAG,OAAO,kBAAkB,CAAC;AAEpD,MAAM,MAAM,SAAS,CAAC,UAAU,SAAS,SAAS,eAAe,EAAE,IAAI;KACrE,SAAS,IAAI,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,CAC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CAAC,CAS3C"}
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ import { missingBearerCredential, requireBearerCredential } from "./lib/auth.js";
2
+ import { applyToolCustomization, assertToolCustomizeOptions, hasToolCustomization } from "./lib/customize.js";
3
+ import { operationFactories, operationIds } from "./operations.gen.js";
4
+ import { NeonError, createNeonClient } from "@neon/sdk";
5
+ //#region src/index.ts
6
+ const createRawClient = (options) => createNeonClient({
7
+ apiKey: options.apiKey === void 0 ? missingBearerCredential : requireBearerCredential(options.apiKey),
8
+ ...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
9
+ ...options.fetch === void 0 ? {} : { fetch: options.fetch }
10
+ }).client;
11
+ const operationFactoryFor = (operationId) => {
12
+ const knownOperationId = operationIds.find((candidate) => candidate === operationId);
13
+ if (knownOperationId === void 0) throw new TypeError(`Unknown Neon operation "${operationId}".`);
14
+ return operationFactories[knownOperationId];
15
+ };
16
+ function assertNeonTools(value, operations) {
17
+ if (typeof value !== "object" || value === null) throw new TypeError("Expected generated Neon tools to be an object.");
18
+ for (const operationId of operations) if (!(operationId in value)) throw new TypeError(`Missing generated Neon tool "${operationId}".`);
19
+ }
20
+ const bindTools = (options) => {
21
+ assertToolCustomizeOptions(options);
22
+ const selected = /* @__PURE__ */ new Set();
23
+ const selectedFactories = options.operations.map((operationId) => {
24
+ if (selected.has(operationId)) throw new Error(`Duplicate Neon operation "${operationId}"`);
25
+ selected.add(operationId);
26
+ return [operationId, operationFactoryFor(operationId)];
27
+ });
28
+ const client = createRawClient(options);
29
+ const entries = selectedFactories.map(([operationId, factory]) => {
30
+ const tool = factory(client);
31
+ return [operationId, hasToolCustomization(options) ? applyToolCustomization(tool, options) : tool];
32
+ });
33
+ const tools = Object.fromEntries(entries);
34
+ assertNeonTools(tools, options.operations);
35
+ return tools;
36
+ };
37
+ const createNeonTools = (options) => bindTools(options);
38
+ function createNeonTool(operationId, options) {
39
+ assertToolCustomizeOptions(options);
40
+ const tool = operationFactoryFor(operationId)(createRawClient(options));
41
+ return hasToolCustomization(options) ? applyToolCustomization(tool, options) : tool;
42
+ }
43
+ //#endregion
44
+ export { NeonError, createNeonTool, createNeonTools, operationIds };
@@ -0,0 +1,5 @@
1
+ import type { NeonConfig } from "@neon/sdk";
2
+ export type NeonBearerCredential = NeonConfig["apiKey"];
3
+ export declare const missingBearerCredential: () => never;
4
+ export declare const requireBearerCredential: (value: NeonBearerCredential) => NeonBearerCredential;
5
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AAKxD,eAAO,MAAM,uBAAuB,QAAO,KAE1C,CAAC;AASF,eAAO,MAAM,uBAAuB,GACnC,OAAO,oBAAoB,KACzB,oBAKF,CAAC"}
@@ -0,0 +1,15 @@
1
+ //#region src/lib/auth.ts
2
+ const missingCredentialMessage = "A Neon API key or OAuth access token is required";
3
+ const missingBearerCredential = () => {
4
+ throw new TypeError(missingCredentialMessage);
5
+ };
6
+ const requireNonEmptyCredential = (value) => {
7
+ if (typeof value !== "string" || value.length === 0) throw new TypeError(missingCredentialMessage);
8
+ return value;
9
+ };
10
+ const requireBearerCredential = (value) => {
11
+ if (typeof value === "function") return async () => requireNonEmptyCredential(await value());
12
+ return requireNonEmptyCredential(value);
13
+ };
14
+ //#endregion
15
+ export { missingBearerCredential, requireBearerCredential };
@@ -0,0 +1,7 @@
1
+ export declare const decodeBase64: (value: string) => Blob;
2
+ export declare const encodeBlob: (value: Blob) => Promise<{
3
+ base64: string;
4
+ contentType: string;
5
+ size: number;
6
+ }>;
7
+ //# sourceMappingURL=binary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../../src/lib/binary.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,IAO5C,CAAC;AAEF,eAAO,MAAM,UAAU,GACtB,OAAO,IAAI,KACT,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAI9D,CAAC"}
@@ -0,0 +1,19 @@
1
+ //#region src/lib/binary.ts
2
+ const bytesToBase64 = (bytes) => {
3
+ let binary = "";
4
+ for (const byte of bytes) binary += String.fromCharCode(byte);
5
+ return btoa(binary);
6
+ };
7
+ const decodeBase64 = (value) => {
8
+ const binary = atob(value);
9
+ const bytes = new Uint8Array(binary.length);
10
+ for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
11
+ return new Blob([bytes]);
12
+ };
13
+ const encodeBlob = async (value) => ({
14
+ base64: bytesToBase64(new Uint8Array(await value.arrayBuffer())),
15
+ contentType: value.type,
16
+ size: value.size
17
+ });
18
+ //#endregion
19
+ export { decodeBase64, encodeBlob };
@@ -0,0 +1,52 @@
1
+ import * as z from "zod";
2
+ import type { NeonTool, NeonToolExecutionContext, NeonToolResult } from "./operation.js";
3
+ export type NeonToolInjectValue = string | (() => string | undefined | Promise<string | undefined>);
4
+ export interface NeonToolInjectOptions {
5
+ projectId?: NeonToolInjectValue;
6
+ branchId?: NeonToolInjectValue;
7
+ omitFromSchema?: boolean;
8
+ }
9
+ export interface NeonToolDescriptionSource {
10
+ operationId: string;
11
+ id: string;
12
+ title: string;
13
+ description: string;
14
+ }
15
+ export type NeonToolDescriptionOverrides = Readonly<Record<string, string>> | ((tool: NeonToolDescriptionSource) => string);
16
+ export interface NeonToolOnExecuteEvent<Output = unknown> {
17
+ operationId: string;
18
+ id: string;
19
+ input: unknown;
20
+ execute: () => Promise<NeonToolResult<Output>>;
21
+ }
22
+ export type NeonToolOnExecute = <Output>(event: NeonToolOnExecuteEvent<Output>) => Promise<NeonToolResult<Output>>;
23
+ export interface NeonToolCustomizeOptions {
24
+ descriptions?: NeonToolDescriptionOverrides;
25
+ onExecute?: NeonToolOnExecute;
26
+ inject?: NeonToolInjectOptions;
27
+ }
28
+ type InjectedPathKey<Inject> = ("projectId" extends keyof Inject ? Inject["projectId"] extends undefined ? never : "project_id" : never) | ("branchId" extends keyof Inject ? Inject["branchId"] extends undefined ? never : "branch_id" : never);
29
+ type OptionalInjectedPath<Path, Keys extends string> = [
30
+ keyof Omit<Path, Keys>
31
+ ] extends [never] ? {
32
+ path?: Omit<Path, Keys> & Partial<Pick<Path, Extract<Keys, keyof Path>>>;
33
+ } : {
34
+ path: Omit<Path, Keys> & Partial<Pick<Path, Extract<Keys, keyof Path>>>;
35
+ };
36
+ type ApplyInjectToInput<Input, Inject> = [InjectedPathKey<Inject>] extends [
37
+ never
38
+ ] ? Input : Input extends {
39
+ path: infer Path;
40
+ } ? Inject extends {
41
+ omitFromSchema: true;
42
+ } ? [keyof Omit<Path, InjectedPathKey<Inject>>] extends [never] ? Omit<Input, "path"> : Omit<Input, "path"> & {
43
+ path: Omit<Path, InjectedPathKey<Inject>>;
44
+ } : Omit<Input, "path"> & OptionalInjectedPath<Path, InjectedPathKey<Inject>> : Input;
45
+ export type InjectedNeonTool<Tool, Inject> = Tool extends NeonTool<infer Schema, string, infer Output> ? Omit<Tool, "execute"> & {
46
+ execute(input: ApplyInjectToInput<z.input<Schema>, Inject>, context?: NeonToolExecutionContext): Promise<NeonToolResult<Output>>;
47
+ } : Tool;
48
+ export declare const assertToolCustomizeOptions: (options: NeonToolCustomizeOptions) => void;
49
+ export declare const hasToolCustomization: (options: NeonToolCustomizeOptions) => boolean;
50
+ export declare const applyToolCustomization: <Tool extends NeonTool>(tool: Tool, options: NeonToolCustomizeOptions) => Tool;
51
+ export {};
52
+ //# sourceMappingURL=customize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customize.d.ts","sourceRoot":"","sources":["../../src/lib/customize.ts"],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AC,MAAM,CAAC,CAAC,CAAC;CAC1C,GACD,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,GACnB,oBAAoB,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC,GACpD,KAAK,CAAC;AAEV,MAAM,MAAM,gBAAgB,CAAC,IAAI,EAAE,MAAM,IACxC,IAAI,SAAS,QAAQ,CAAC,MAAM,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC,GACtD,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG;IACxB,OAAO,CACN,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAClD,OAAO,CAAC,EAAE,wBAAwB,GAChC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;CACnC,GACA,IAAI,CAAC;AAeT,eAAO,MAAM,0BAA0B,GACtC,SAAS,wBAAwB,KAC/B,IAEF,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAChC,SAAS,wBAAwB,KAC/B,OAGkC,CAAC;AAEtC,eAAO,MAAM,sBAAsB,GAAI,IAAI,SAAS,QAAQ,EAC3D,MAAM,IAAI,EACV,SAAS,wBAAwB,KAC/B,IAsBF,CAAC"}
@@ -0,0 +1,172 @@
1
+ import * as z from "zod";
2
+ //#region src/lib/customize.ts
3
+ const missingInjectMessage = (name) => `A ${name} inject value is required`;
4
+ const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
5
+ const assertToolCustomizeOptions = (options) => {
6
+ resolveInject(options.inject);
7
+ };
8
+ const hasToolCustomization = (options) => options.descriptions !== void 0 || options.onExecute !== void 0 || resolveInject(options.inject).hasAny;
9
+ const applyToolCustomization = (tool, options) => {
10
+ const inject = resolveInject(options.inject);
11
+ const description = applyDescription(tool, options.descriptions);
12
+ const inputSchema = publishInputSchema(tool.inputSchema, inject);
13
+ const wrapExecute = options.onExecute !== void 0 || inject.hasAny;
14
+ if (description === tool.description && inputSchema === tool.inputSchema && !wrapExecute) return tool;
15
+ return {
16
+ ...tool,
17
+ description,
18
+ inputSchema,
19
+ execute: wrapExecute ? wrapToolExecute(tool, options.onExecute, inject) : tool.execute
20
+ };
21
+ };
22
+ function resolveInject(inject) {
23
+ if (inject === void 0) return {
24
+ omitFromSchema: false,
25
+ hasAny: false
26
+ };
27
+ const projectId = requireInjectValue("projectId", inject.projectId);
28
+ const branchId = requireInjectValue("branchId", inject.branchId);
29
+ const hasAny = projectId !== void 0 || branchId !== void 0;
30
+ const omitFromSchema = inject.omitFromSchema === true;
31
+ if (omitFromSchema && !hasAny) throw new TypeError("omitFromSchema requires inject.projectId or inject.branchId");
32
+ return {
33
+ projectId,
34
+ branchId,
35
+ omitFromSchema,
36
+ hasAny
37
+ };
38
+ }
39
+ function requireInjectValue(name, value) {
40
+ if (value === void 0) return;
41
+ if (typeof value === "function") return value;
42
+ if (typeof value === "string") {
43
+ if (value.length === 0) throw new TypeError(missingInjectMessage(name));
44
+ return value;
45
+ }
46
+ throw new TypeError(missingInjectMessage(name));
47
+ }
48
+ function applyDescription(tool, descriptions) {
49
+ if (descriptions === void 0) return tool.description;
50
+ if (typeof descriptions === "function") {
51
+ const description = descriptions({
52
+ operationId: tool.operationId,
53
+ id: tool.id,
54
+ title: tool.title,
55
+ description: tool.description
56
+ });
57
+ if (typeof description !== "string") throw new TypeError("Neon tool description overrides must return a string");
58
+ return description;
59
+ }
60
+ const description = descriptions[tool.operationId] ?? descriptions[tool.id];
61
+ if (description === void 0) return tool.description;
62
+ if (typeof description !== "string") throw new TypeError("Neon tool description overrides must be strings");
63
+ return description;
64
+ }
65
+ function wrapToolExecute(tool, onExecute, inject) {
66
+ const originalExecute = tool.execute.bind(tool);
67
+ const availableKeys = pathKeys(tool.inputSchema);
68
+ const mode = inject.omitFromSchema ? "override" : "fill";
69
+ return async (input, context) => {
70
+ const run = async () => originalExecute(mergePathPatch(input, await resolveInjectedPath(input, inject, availableKeys, mode), mode), context);
71
+ if (onExecute === void 0) return run();
72
+ return onExecute({
73
+ operationId: tool.operationId,
74
+ id: tool.id,
75
+ input: cloneInput(input),
76
+ execute: run
77
+ });
78
+ };
79
+ }
80
+ async function resolveInjectedPath(input, inject, availableKeys, mode) {
81
+ const present = isPlainObject(input) && isPlainObject(input.path) ? input.path : void 0;
82
+ const patch = {};
83
+ for (const [name, pathKey] of [["projectId", "project_id"], ["branchId", "branch_id"]]) {
84
+ if (!availableKeys.has(pathKey)) continue;
85
+ const injector = inject[name];
86
+ if (injector === void 0) continue;
87
+ if (mode === "fill" && present?.[pathKey] !== void 0) continue;
88
+ const value = typeof injector === "function" ? await injector() : injector;
89
+ if (value === void 0) {
90
+ if (mode === "override") throw new TypeError(missingInjectMessage(name));
91
+ continue;
92
+ }
93
+ if (typeof value !== "string" || value.length === 0) throw new TypeError(missingInjectMessage(name));
94
+ patch[pathKey] = value;
95
+ }
96
+ return patch;
97
+ }
98
+ function mergePathPatch(input, patch, mode) {
99
+ if (Object.keys(patch).length === 0) return input === void 0 ? {} : input;
100
+ if (input === void 0) return { path: patch };
101
+ if (!isPlainObject(input)) return input;
102
+ const path = input.path;
103
+ if (path === void 0) return {
104
+ ...input,
105
+ path: patch
106
+ };
107
+ if (!isPlainObject(path)) return input;
108
+ const nextPath = { ...path };
109
+ for (const [key, value] of Object.entries(patch)) if (mode === "override" || nextPath[key] === void 0) nextPath[key] = value;
110
+ return {
111
+ ...input,
112
+ path: nextPath
113
+ };
114
+ }
115
+ function cloneInput(input) {
116
+ if (!isPlainObject(input)) return input;
117
+ if (!isPlainObject(input.path)) return { ...input };
118
+ return {
119
+ ...input,
120
+ path: { ...input.path }
121
+ };
122
+ }
123
+ function objectShape(schema) {
124
+ if (schema instanceof z.ZodOptional) return objectShape(schema.unwrap());
125
+ if (schema instanceof z.ZodObject) return schema.shape;
126
+ }
127
+ function pathKeys(schema) {
128
+ const shape = objectShape(schema);
129
+ if (shape?.path === void 0) return /* @__PURE__ */ new Set();
130
+ const pathShape = objectShape(shape.path);
131
+ if (pathShape === void 0) return /* @__PURE__ */ new Set();
132
+ return new Set(Object.keys(pathShape));
133
+ }
134
+ function publishInputSchema(schema, inject) {
135
+ if (!inject.hasAny) return schema;
136
+ const available = pathKeys(schema);
137
+ const modes = {};
138
+ if (inject.projectId !== void 0 && available.has("project_id")) modes.project_id = inject.omitFromSchema ? "omit" : "optional";
139
+ if (inject.branchId !== void 0 && available.has("branch_id")) modes.branch_id = inject.omitFromSchema ? "omit" : "optional";
140
+ if (modes.project_id === void 0 && modes.branch_id === void 0) return schema;
141
+ return rewritePathSchema(schema, modes);
142
+ }
143
+ function rewritePathSchema(schema, modes) {
144
+ if (!(schema instanceof z.ZodObject)) return schema;
145
+ const shape = schema.shape;
146
+ if (shape.path === void 0) return schema;
147
+ let pathSchema = shape.path;
148
+ if (shape.path instanceof z.ZodOptional) pathSchema = shape.path.unwrap();
149
+ const pathWasOptional = shape.path instanceof z.ZodOptional;
150
+ if (!(pathSchema instanceof z.ZodObject)) return schema;
151
+ const pathShape = { ...pathSchema.shape };
152
+ let changed = false;
153
+ for (const key of ["project_id", "branch_id"]) {
154
+ const mode = modes[key];
155
+ if (mode === void 0 || pathShape[key] === void 0) continue;
156
+ changed = true;
157
+ if (mode === "omit") delete pathShape[key];
158
+ else pathShape[key] = pathShape[key].optional();
159
+ }
160
+ if (!changed) return schema;
161
+ const restShape = { ...shape };
162
+ const remaining = Object.keys(pathShape);
163
+ if (remaining.length === 0) {
164
+ delete restShape.path;
165
+ return Object.keys(restShape).length === 0 ? z.strictObject({}) : z.strictObject(restShape);
166
+ }
167
+ const nextPath = z.strictObject(pathShape);
168
+ restShape.path = pathWasOptional || remaining.every((key) => pathShape[key] instanceof z.ZodOptional) ? nextPath.optional() : nextPath;
169
+ return z.strictObject(restShape);
170
+ }
171
+ //#endregion
172
+ export { applyToolCustomization, assertToolCustomizeOptions, hasToolCustomization };
@@ -0,0 +1,56 @@
1
+ import { type Client } from "@neon/sdk/raw";
2
+ import type * as z from "zod";
3
+ import { type NeonBearerCredential } from "./auth.js";
4
+ export interface NeonToolAnnotations {
5
+ readOnlyHint: boolean;
6
+ destructiveHint?: boolean;
7
+ idempotentHint?: boolean;
8
+ openWorldHint: boolean;
9
+ }
10
+ export interface NeonToolExecutionContext {
11
+ signal?: AbortSignal;
12
+ apiKey?: NeonBearerCredential;
13
+ }
14
+ export interface NeonToolMetadata {
15
+ method: string;
16
+ path: string;
17
+ stability: string;
18
+ deprecated: boolean;
19
+ tags: readonly string[];
20
+ }
21
+ export interface JsonSafeBlob {
22
+ base64: string;
23
+ contentType: string;
24
+ size: number;
25
+ }
26
+ export type JsonSafe<Value> = unknown extends Value ? unknown : Value extends null ? null : Value extends void ? null : Value extends bigint | Date ? string : Value extends Blob ? JsonSafeBlob : Value extends string | number | boolean ? Value : Value extends readonly (infer Item)[] ? JsonSafe<Item>[] : Value extends object ? {
27
+ [Key in keyof Value]: JsonSafe<Value[Key]>;
28
+ } : unknown;
29
+ export interface NeonToolResult<Data = unknown> {
30
+ data: Data;
31
+ }
32
+ export interface NeonTool<InputSchema extends z.ZodType = z.ZodType, Id extends string = string, Output = unknown> {
33
+ operationId: string;
34
+ id: Id;
35
+ title: string;
36
+ description: string;
37
+ inputSchema: InputSchema;
38
+ annotations: NeonToolAnnotations;
39
+ requiresApproval: boolean;
40
+ metadata: NeonToolMetadata;
41
+ execute(input: z.input<InputSchema>, context?: NeonToolExecutionContext): Promise<NeonToolResult<Output>>;
42
+ }
43
+ export interface NeonOperation<InputSchema extends z.ZodType, Id extends string = string, Output = unknown> {
44
+ operationId: string;
45
+ id: Id;
46
+ title: string;
47
+ description: string;
48
+ inputSchema: InputSchema;
49
+ annotations: NeonToolAnnotations;
50
+ requiresApproval: boolean;
51
+ metadata: NeonToolMetadata;
52
+ invoke(client: Client, input: z.output<InputSchema>, signal?: AbortSignal): Promise<Output>;
53
+ }
54
+ export declare const defineOperation: <const InputSchema extends z.ZodType, const Id extends string, Output>(operation: NeonOperation<InputSchema, Id, Output>) => NeonOperation<InputSchema, Id, Output>;
55
+ export declare const bindOperation: <const InputSchema extends z.ZodType, const Id extends string, Output>(operation: NeonOperation<InputSchema, Id, Output>, client: Client) => NeonTool<InputSchema, Id, JsonSafe<Awaited<Output>>>;
56
+ //# sourceMappingURL=operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/lib/operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAC;AAC9B,OAAO,EAAE,KAAK,oBAAoB,EAA2B,MAAM,WAAW,CAAC;AAG/E,MAAM,WAAW,mBAAmB;IACnC,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,wBAAwB;IACxC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,oBAAoB,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,QAAQ,CAAC,KAAK,IAAI,OAAO,SAAS,KAAK,GAChD,OAAO,GACP,KAAK,SAAS,IAAI,GACjB,IAAI,GACJ,KAAK,SAAS,IAAI,GACjB,IAAI,GACJ,KAAK,SAAS,MAAM,GAAG,IAAI,GAC1B,MAAM,G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zB,WAAW,EAAE,mBAAmB,CAAC;IACjC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,MAAM,CACL,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,EAC5B,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,CAAC,CAAC;CACnB;AAED,eAAO,MAAM,eAAe,GAC3B,KAAK,CAAC,WAAW,SAAS,CAAC,CAAC,OAAO,EACnC,KAAK,CAAC,EAAE,SAAS,MAAM,EACvB,MAAM,EAEN,WAAW,aAAa,CAAC,WAAW,EAAE,EAAE,EAAE,MAAM,CAAC,2CACpC,CAAC;AAEf,eAAO,MAAM,aAAa,GACzB,KAAK,CAAC,WAAW,SAAS,CAAC,CAAC,OAAO,EACnC,KAAK,CAAC,EAAE,SAAS,MAAM,EACvB,MAAM,EAEN,WAAW,aAAa,CAAC,WAAW,EAAE,EAAE,EAAE,MAAM,CAAC,EACjD,QAAQ,MAAM,KACZ,QAAQ,CAAC,WAAW,EAAE,EAAE,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAsBpD,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { requireBearerCredential } from "./auth.js";
2
+ import { toToolResult } from "./result.js";
3
+ import { createClient } from "@neon/sdk/raw";
4
+ //#region src/lib/operation.ts
5
+ const defineOperation = (operation) => operation;
6
+ const bindOperation = (operation, client) => ({
7
+ operationId: operation.operationId,
8
+ id: operation.id,
9
+ title: operation.title,
10
+ description: operation.description,
11
+ inputSchema: operation.inputSchema,
12
+ annotations: operation.annotations,
13
+ requiresApproval: operation.requiresApproval,
14
+ metadata: operation.metadata,
15
+ async execute(input, context) {
16
+ const parsed = await operation.inputSchema.parseAsync(input);
17
+ const activeClient = context !== void 0 && "apiKey" in context ? clientWithCredential(client, context.apiKey) : client;
18
+ const result = await operation.invoke(activeClient, parsed, context?.signal);
19
+ return toToolResult(result);
20
+ }
21
+ });
22
+ const clientWithCredential = (client, apiKey) => {
23
+ if (apiKey === void 0) throw new TypeError("A Neon API key or OAuth access token is required");
24
+ return createClient({
25
+ ...client.getConfig(),
26
+ auth: requireBearerCredential(apiKey)
27
+ });
28
+ };
29
+ //#endregion
30
+ export { bindOperation, defineOperation };
@@ -0,0 +1,3 @@
1
+ import type { JsonSafe, NeonToolResult } from "./operation.js";
2
+ export declare const toToolResult: <Value>(value: Value) => Promise<NeonToolResult<JsonSafe<Value>>>;
3
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/lib/result.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAsC/D,eAAO,MAAM,YAAY,GAAU,KAAK,EACvC,OAAO,KAAK,KACV,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAExC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { encodeBlob } from "./binary.js";
2
+ //#region src/lib/result.ts
3
+ async function toJsonSafe(value) {
4
+ if (value === void 0 || value === null) return null;
5
+ if (typeof value === "bigint") return value.toString();
6
+ if (typeof value === "string" || typeof value === "boolean" || typeof value === "number") return value;
7
+ if (value instanceof Blob) return encodeBlob(value);
8
+ if (value instanceof Date) return value.toISOString();
9
+ if (Array.isArray(value)) return Promise.all(value.map(toJsonSafe));
10
+ if (typeof value === "object") {
11
+ const entries = await Promise.all(Object.entries(value).map(async ([key, child]) => [key, await toJsonSafe(child)]));
12
+ return Object.fromEntries(entries);
13
+ }
14
+ throw new TypeError(`Unsupported tool result value: ${typeof value}`);
15
+ }
16
+ const toToolResult = async (value) => ({ data: await toJsonSafe(value) });
17
+ //#endregion
18
+ export { toToolResult };
@@ -0,0 +1,32 @@
1
+ import type * as z from "zod";
2
+ import type { NeonTool, NeonToolExecutionContext, NeonToolResult } from "./lib/operation.js";
3
+ export interface MastraToolContext {
4
+ abortSignal?: AbortSignal;
5
+ }
6
+ export type MastraToolConfig<Tool extends NeonTool> = {
7
+ id: Tool["id"];
8
+ description: string;
9
+ inputSchema: Tool["inputSchema"];
10
+ requireApproval: boolean;
11
+ execute(input: Parameters<Tool["execute"]>[0], context: MastraToolContext): ReturnType<Tool["execute"]>;
12
+ };
13
+ export type MastraTools<Tools extends Readonly<Record<string, NeonTool>>> = {
14
+ [Tool in Tools[keyof Tools] as Tool["id"]]: MastraToolConfig<Tool>;
15
+ };
16
+ type MastraToolSource = {
17
+ id: string;
18
+ description: string;
19
+ inputSchema: z.ZodType;
20
+ requiresApproval: boolean;
21
+ execute: (input: never, context?: NeonToolExecutionContext) => Promise<NeonToolResult<unknown>>;
22
+ };
23
+ export declare const toMastraTool: <const Tool extends MastraToolSource>(tool: Tool) => {
24
+ id: string;
25
+ description: string;
26
+ inputSchema: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
27
+ requireApproval: boolean;
28
+ execute: (input: Parameters<Tool["execute"]>[0], context: MastraToolContext) => ReturnType<Tool["execute"]>;
29
+ };
30
+ export declare const toMastraTools: <const Tools extends Readonly<Record<string, NeonTool>>>(tools: Tools) => MastraTools<Tools>;
31
+ export {};
32
+ //# sourceMappingURL=mastra.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mastra.d.ts","sourceRoot":"","sources":["../src/mastra.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAC;AAC9B,OAAO,KAAK,EACX,QAAQ,EACR,wBAAwB,EACxB,cAAc,EACd,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,iBAAiB;IACjC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,MAAM,gBAAgB,CAAC,IAAI,SAAS,QAAQ,IAAI;IACrD,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACf,WA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@@ -0,0 +1,19 @@
1
+ //#region src/mastra.ts
2
+ const toMastraTool = (tool) => ({
3
+ id: tool.id,
4
+ description: tool.description,
5
+ inputSchema: tool.inputSchema,
6
+ requireApproval: tool.requiresApproval,
7
+ execute: (input, context) => tool.execute(input, { signal: context.abortSignal })
8
+ });
9
+ function assertMastraTools(value, tools) {
10
+ if (typeof value !== "object" || value === null) throw new TypeError("Expected Mastra tools to be an object.");
11
+ for (const tool of Object.values(tools)) if (!(tool.id in value)) throw new TypeError(`Missing Mastra tool "${tool.id}".`);
12
+ }
13
+ const toMastraTools = (tools) => {
14
+ const adapted = Object.fromEntries(Object.values(tools).map((tool) => [tool.id, toMastraTool(tool)]));
15
+ assertMastraTools(adapted, tools);
16
+ return adapted;
17
+ };
18
+ //#endregion
19
+ export { toMastraTool, toMastraTools };
@@ -0,0 +1,3 @@
1
+ export type { McpToolResult, McpToolServer } from "./mcp.js";
2
+ export { registerNeonTools } from "./mcp.js";
3
+ //# sourceMappingURL=mcp-v1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-v1.d.ts","sourceRoot":"","sources":["../src/mcp-v1.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC"}
package/dist/mcp-v1.js ADDED
@@ -0,0 +1,2 @@
1
+ import { registerNeonTools } from "./mcp.js";
2
+ export { registerNeonTools };
package/dist/mcp.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { NeonTool } from "./lib/operation.js";
2
+ export interface McpToolResult {
3
+ content: Array<{
4
+ type: "text";
5
+ text: string;
6
+ }>;
7
+ structuredContent: Record<string, unknown>;
8
+ isError?: boolean;
9
+ }
10
+ export interface McpToolServer {
11
+ registerTool: object;
12
+ }
13
+ export declare const registerNeonTools: (server: McpToolServer, tools: Readonly<Record<string, NeonTool>>) => void;
14
+ //# sourceMappingURL=mcp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC7B,YAAY,EAAE,MAAM,CAAC;CACrB;AAsDD,eAAO,MAAM,iBAAiB,GAC7B,QAAQ,aAAa,EACrB,OAAO,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,KACvC,IAqDF,CAAC"}