@neon/tools 2.14.4 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +195 -5
- package/dist/descriptions.gen.js +2 -2
- package/dist/effect.d.ts +22 -0
- package/dist/effect.d.ts.map +1 -0
- package/dist/effect.js +3 -0
- package/dist/generated/output.gen.d.ts +3418 -0
- package/dist/generated/output.gen.d.ts.map +1 -0
- package/dist/generated/output.gen.js +1498 -0
- package/dist/generated/zod.gen.d.ts +3 -3
- package/dist/index.d.ts +17 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -9
- package/dist/lib/custom/auth-config.d.ts +63 -2
- package/dist/lib/custom/auth-config.d.ts.map +1 -1
- package/dist/lib/custom/auth-config.js +34 -7
- package/dist/lib/custom/docs.d.ts +32 -2
- package/dist/lib/custom/docs.d.ts.map +1 -1
- package/dist/lib/custom/docs.js +18 -1
- package/dist/lib/custom/feedback.d.ts +7 -2
- package/dist/lib/custom/feedback.d.ts.map +1 -1
- package/dist/lib/custom/feedback.js +3 -0
- package/dist/lib/custom/fetch.d.ts +15 -1
- package/dist/lib/custom/fetch.d.ts.map +1 -1
- package/dist/lib/custom/fetch.js +10 -1
- package/dist/lib/custom/organizations.d.ts +23 -1
- package/dist/lib/custom/organizations.d.ts.map +1 -1
- package/dist/lib/custom/organizations.js +3 -0
- package/dist/lib/custom/resources.d.ts +15 -1
- package/dist/lib/custom/resources.d.ts.map +1 -1
- package/dist/lib/custom/resources.js +8 -1
- package/dist/lib/custom/sql/connection.d.ts +6 -7
- package/dist/lib/custom/sql/connection.d.ts.map +1 -1
- package/dist/lib/custom/sql/connection.js +10 -12
- package/dist/lib/custom/sql/describe-branch.d.ts +99 -1
- package/dist/lib/custom/sql/describe-branch.d.ts.map +1 -1
- package/dist/lib/custom/sql/describe-branch.js +11 -2
- package/dist/lib/custom/sql/inspect/inspect.d.ts +27 -1
- package/dist/lib/custom/sql/inspect/inspect.d.ts.map +1 -1
- package/dist/lib/custom/sql/inspect/inspect.js +17 -3
- package/dist/lib/custom/sql/migrations.d.ts +46 -2
- package/dist/lib/custom/sql/migrations.d.ts.map +1 -1
- package/dist/lib/custom/sql/migrations.js +29 -7
- package/dist/lib/custom/sql/query-tuning.d.ts +90 -2
- package/dist/lib/custom/sql/query-tuning.d.ts.map +1 -1
- package/dist/lib/custom/sql/query-tuning.js +31 -8
- package/dist/lib/custom/sql/run.d.ts +30 -3
- package/dist/lib/custom/sql/run.d.ts.map +1 -1
- package/dist/lib/custom/sql/run.js +15 -6
- package/dist/lib/custom/sql/schema.d.ts +76 -2
- package/dist/lib/custom/sql/schema.d.ts.map +1 -1
- package/dist/lib/custom/sql/schema.js +34 -5
- package/dist/lib/custom/sql/slow-queries.d.ts +15 -1
- package/dist/lib/custom/sql/slow-queries.d.ts.map +1 -1
- package/dist/lib/custom/sql/slow-queries.js +11 -3
- package/dist/lib/customize.d.ts +1 -1
- package/dist/lib/customize.d.ts.map +1 -1
- package/dist/lib/customize.js +8 -4
- package/dist/lib/effect/errors.d.ts +51 -0
- package/dist/lib/effect/errors.d.ts.map +1 -0
- package/dist/lib/effect/errors.js +37 -0
- package/dist/lib/effect/tools.d.ts +56 -0
- package/dist/lib/effect/tools.d.ts.map +1 -0
- package/dist/lib/effect/tools.js +67 -0
- package/dist/lib/ergonomic/bind.d.ts +25 -7
- package/dist/lib/ergonomic/bind.d.ts.map +1 -1
- package/dist/lib/ergonomic/bind.js +13 -3
- package/dist/lib/ergonomic/catalog.d.ts +5335 -180
- package/dist/lib/ergonomic/catalog.d.ts.map +1 -1
- package/dist/lib/ergonomic/catalog.js +286 -23
- package/dist/lib/ergonomic/composed.d.ts +866 -12
- package/dist/lib/ergonomic/composed.d.ts.map +1 -1
- package/dist/lib/ergonomic/composed.js +63 -0
- package/dist/lib/mcp-json-schema.d.ts +20 -0
- package/dist/lib/mcp-json-schema.d.ts.map +1 -1
- package/dist/lib/mcp-json-schema.js +89 -1
- package/dist/lib/mcp-register.d.ts +1 -1
- package/dist/lib/mcp-register.d.ts.map +1 -1
- package/dist/lib/mcp-register.js +2 -1
- package/dist/lib/operation.d.ts +56 -5
- package/dist/lib/operation.d.ts.map +1 -1
- package/dist/lib/operation.js +6 -1
- package/dist/lib/policy.d.ts +24 -0
- package/dist/lib/policy.d.ts.map +1 -0
- package/dist/lib/policy.js +49 -0
- package/dist/lib/redact.d.ts +8 -0
- package/dist/lib/redact.d.ts.map +1 -0
- package/dist/lib/redact.js +40 -0
- package/dist/mastra.d.ts +2 -1
- package/dist/mastra.d.ts.map +1 -1
- package/dist/mcp-v1.d.ts.map +1 -1
- package/dist/mcp-v1.js +3 -1
- package/dist/mcp.d.ts +3 -3
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +3 -3
- package/dist/operations.gen.d.ts +194 -194
- package/package.json +21 -2
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Effect, Schedule } from "effect";
|
|
2
|
+
import type { NeonToolAnnotations, NeonToolExecutionContext } from "../operation.js";
|
|
3
|
+
import { type NeonToolError } from "./errors.js";
|
|
4
|
+
/** The tool shape an Effect tool is built from: any Neon tool, customized or not. */
|
|
5
|
+
export interface ExecutableNeonTool<Input = never, Output = unknown> {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly annotations: NeonToolAnnotations;
|
|
8
|
+
execute(input: Input, context?: NeonToolExecutionContext): Promise<Output>;
|
|
9
|
+
}
|
|
10
|
+
/** The execution context of an Effect tool. Interrupting the fiber cancels the call. */
|
|
11
|
+
export type NeonEffectToolContext = Omit<NeonToolExecutionContext, "signal">;
|
|
12
|
+
type ToolInput<Tool> = Tool extends ExecutableNeonTool<infer Input, unknown> ? Input : never;
|
|
13
|
+
type ToolOutput<Tool> = Tool extends ExecutableNeonTool<never, infer Output> ? Output : never;
|
|
14
|
+
/** A Neon tool whose `execute` returns an Effect. Every other field is unchanged. */
|
|
15
|
+
export type NeonEffectTool<Tool extends ExecutableNeonTool, Input = ToolInput<Tool>, Output = ToolOutput<Tool>> = Omit<Tool, "execute"> & {
|
|
16
|
+
readonly execute: (input: Input, context?: NeonEffectToolContext) => Effect.Effect<Output, NeonToolError>;
|
|
17
|
+
};
|
|
18
|
+
export type NeonEffectTools<Tools extends Readonly<Record<string, ExecutableNeonTool>>> = {
|
|
19
|
+
readonly [Id in keyof Tools]: NeonEffectTool<Tools[Id]>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Which failures to retry and how. A policy only ever sees failures of
|
|
23
|
+
* read-only tools that the SDK did not already retry: the adapter never resends
|
|
24
|
+
* a mutation, and leaves 423, 429, and 503 responses to the SDK, which retries
|
|
25
|
+
* them and honours `Retry-After`.
|
|
26
|
+
*/
|
|
27
|
+
export interface NeonToolRetryPolicy {
|
|
28
|
+
readonly schedule: Schedule.Schedule<unknown, NeonToolError>;
|
|
29
|
+
/** Retries after the first attempt. */
|
|
30
|
+
readonly times: number;
|
|
31
|
+
readonly shouldRetry: (failure: {
|
|
32
|
+
readonly tool: ExecutableNeonTool;
|
|
33
|
+
readonly error: NeonToolError;
|
|
34
|
+
}) => boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface EffectToolOptions {
|
|
37
|
+
/** No retries unless set. A retry runs the whole tool again, hooks included. */
|
|
38
|
+
readonly retry?: NeonToolRetryPolicy;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Retries a read-only tool that got no response from the Neon API, twice, with
|
|
42
|
+
* jittered exponential backoff from 200 ms. A read is safe to send again; a
|
|
43
|
+
* mutation that may have reached the API is not, so it is never retried.
|
|
44
|
+
*/
|
|
45
|
+
export declare const retryReadOnlyNetworkFailures: NeonToolRetryPolicy;
|
|
46
|
+
/**
|
|
47
|
+
* Run a Neon tool as an Effect, in a span named `NeonTools.<id>`. The span
|
|
48
|
+
* records `error.type` for every failure but fails only for the server's: a
|
|
49
|
+
* caller's mistake keeps it ok. `neon.tool.attempts` counts the attempts, and
|
|
50
|
+
* `neon.tool.retried_error.type` names the failure a retry recovered from.
|
|
51
|
+
*/
|
|
52
|
+
export declare const toEffectTool: <Input, Output, Tool extends ExecutableNeonTool>(tool: Tool & ExecutableNeonTool<Input, Output>, options?: EffectToolOptions) => NeonEffectTool<Tool, Input, Output>;
|
|
53
|
+
/** Run every tool of a `createNeonTools` result as an Effect. */
|
|
54
|
+
export declare const toEffectTools: <Tools extends Readonly<Record<string, ExecutableNeonTool>>>(tools: Tools, options?: EffectToolOptions) => NeonEffectTools<Tools>;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/lib/effect/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA0B,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,KAAK,EACX,mBAAmB,EACnB,wBAAwB,EACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,aAAa,CAAC;AAElE,qFAAqF;AACrF,MAAM,WAAW,kBAAkB,CAAC,KAAK,GAAG,KAAK,EAAE,MAAM,GAAG,OAAO;IAClE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAC1C,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3E;AAED,wFAAwF;AACxF,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,wBAAwB,EAAE,QAAQ,CAAC,CAAC;AAE7E,KAAK,SAAS,CAAC,IAAI,IAClB,IAAI,SAAS,kBAAkB,CAAC,MAAM,KAAK,EAAE,OAAO,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;AAEvE,KAAK,UAAU,CAAC,IAAI,IACnB,IAAI,SAAS,kBAAkB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AAI,SAAS,kBAAkB,EAC1E,MAAM,IAAI,GAAG,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,EAC9C,UAAS,iBAAsB,KAC7B,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CA+DpC,CAAC;AAEF,iEAAiE;AACjE,eAAO,MAAM,aAAa,GACzB,KAAK,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,EAE1D,OAAO,KAAK,EACZ,UAAS,iBAAsB,KAC7B,eAAe,CAAC,KAAK,CAMI,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { toNeonToolError } from "./errors.js";
|
|
2
|
+
import { Effect, Predicate, Ref, Result, Schedule } from "effect";
|
|
3
|
+
// src/lib/effect/tools.ts
|
|
4
|
+
/**
|
|
5
|
+
* Retries a read-only tool that got no response from the Neon API, twice, with
|
|
6
|
+
* jittered exponential backoff from 200 ms. A read is safe to send again; a
|
|
7
|
+
* mutation that may have reached the API is not, so it is never retried.
|
|
8
|
+
*/
|
|
9
|
+
const retryReadOnlyNetworkFailures = {
|
|
10
|
+
schedule: Schedule.exponential("200 millis").pipe(Schedule.jittered),
|
|
11
|
+
times: 2,
|
|
12
|
+
shouldRetry: ({ error }) => Predicate.isTagged(error, "NeonNetworkError")
|
|
13
|
+
};
|
|
14
|
+
const SDK_RETRIED_STATUSES = /* @__PURE__ */ new Set([
|
|
15
|
+
423,
|
|
16
|
+
429,
|
|
17
|
+
503
|
|
18
|
+
]);
|
|
19
|
+
const sdkRetried = (error) => "status" in error && typeof error.status === "number" && SDK_RETRIED_STATUSES.has(error.status);
|
|
20
|
+
const mayRetry = (tool, error, policy) => tool.annotations.readOnlyHint && !sdkRetried(error) && policy.shouldRetry({
|
|
21
|
+
tool,
|
|
22
|
+
error
|
|
23
|
+
});
|
|
24
|
+
const SERVER_SQLSTATE_CLASSES = /* @__PURE__ */ new Set([
|
|
25
|
+
"08",
|
|
26
|
+
"40",
|
|
27
|
+
"53",
|
|
28
|
+
"55",
|
|
29
|
+
"57",
|
|
30
|
+
"58",
|
|
31
|
+
"F0",
|
|
32
|
+
"XX"
|
|
33
|
+
]);
|
|
34
|
+
const isCallerError = (error) => {
|
|
35
|
+
if (Predicate.isTagged(error, "NeonSqlError")) return !SERVER_SQLSTATE_CLASSES.has(error.code.slice(0, 2));
|
|
36
|
+
return Predicate.isTagged(error, "NeonToolInputError") || "status" in error && typeof error.status === "number" && error.status < 500;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Run a Neon tool as an Effect, in a span named `NeonTools.<id>`. The span
|
|
40
|
+
* records `error.type` for every failure but fails only for the server's: a
|
|
41
|
+
* caller's mistake keeps it ok. `neon.tool.attempts` counts the attempts, and
|
|
42
|
+
* `neon.tool.retried_error.type` names the failure a retry recovered from.
|
|
43
|
+
*/
|
|
44
|
+
const toEffectTool = (tool, options = {}) => {
|
|
45
|
+
const { retry } = options;
|
|
46
|
+
const attempt = (input, context, attempts) => Ref.updateAndGet(attempts, (n) => n + 1).pipe(Effect.flatMap((n) => Effect.annotateCurrentSpan("neon.tool.attempts", n)), Effect.andThen(Effect.tryPromise({
|
|
47
|
+
try: (signal) => tool.execute(input, {
|
|
48
|
+
...context,
|
|
49
|
+
signal
|
|
50
|
+
}),
|
|
51
|
+
catch: toNeonToolError
|
|
52
|
+
})));
|
|
53
|
+
const run = (input, context, attempts) => retry === void 0 ? attempt(input, context, attempts) : attempt(input, context, attempts).pipe(Effect.tapError((error) => mayRetry(tool, error, retry) ? Effect.annotateCurrentSpan("neon.tool.retried_error.type", error._tag) : Effect.void), Effect.retry({
|
|
54
|
+
schedule: retry.schedule,
|
|
55
|
+
times: retry.times,
|
|
56
|
+
while: (error) => mayRetry(tool, error, retry)
|
|
57
|
+
}));
|
|
58
|
+
const execute = (input, context) => Ref.make(0).pipe(Effect.flatMap((attempts) => run(input, context, attempts)), Effect.map(Result.succeed), Effect.tapError((error) => Effect.annotateCurrentSpan("error.type", error._tag)), Effect.catchIf(isCallerError, (error) => Effect.succeed(Result.fail(error))), Effect.withSpan(`NeonTools.${tool.id}`, { attributes: { "neon.tool.id": tool.id } }), Effect.flatMap(Effect.fromResult));
|
|
59
|
+
const { execute: _promiseExecute, ...descriptor } = tool;
|
|
60
|
+
return {
|
|
61
|
+
...descriptor,
|
|
62
|
+
execute
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/** Run every tool of a `createNeonTools` result as an Effect. */
|
|
66
|
+
const toEffectTools = (tools, options = {}) => Object.fromEntries(Object.entries(tools).map(([id, tool]) => [id, toEffectTool(tool, options)]));
|
|
67
|
+
export { retryReadOnlyNetworkFailures, toEffectTool, toEffectTools };
|
|
@@ -2,7 +2,7 @@ import { type NeonClient, type NeonConfig, type Paginated } from "@neon/sdk";
|
|
|
2
2
|
import * as z from "zod";
|
|
3
3
|
import { type NeonOperationId, operationFactories } from "../../operations.gen.js";
|
|
4
4
|
import { type NeonBearerCredential } from "../auth.js";
|
|
5
|
-
import type
|
|
5
|
+
import { type JsonSafe, type NeonSecretField, type NeonTool, type NeonToolAnnotations, type NeonToolExecutionContext, type NeonToolMetadataInput } from "../operation.js";
|
|
6
6
|
import type { NeonToolId } from "./ids.js";
|
|
7
7
|
export interface ToolClientOptions {
|
|
8
8
|
apiKey?: NeonBearerCredential;
|
|
@@ -38,9 +38,17 @@ export declare const collectObjectList: (neon: NeonClient<true>, input: {
|
|
|
38
38
|
prefix: string;
|
|
39
39
|
}>;
|
|
40
40
|
export declare const collectPages: <T>(list: Paginated<T, true>, maxItems?: number) => Promise<T[]>;
|
|
41
|
-
|
|
41
|
+
type ToolDefinition<InputSchema extends z.ZodType, Id extends string, Output, OutputSchema extends z.ZodType> = Omit<NeonTool<InputSchema, Id, JsonSafe<Awaited<Output>>, OutputSchema>, "execute" | "metadata"> & {
|
|
42
|
+
outputSchema: OutputSchema;
|
|
43
|
+
metadata: NeonToolMetadataInput;
|
|
44
|
+
};
|
|
45
|
+
export declare const bindTool: <const InputSchema extends z.ZodType, const Id extends string, Output, OutputSchema extends z.ZodType>(options: ToolClientOptions, tool: ToolDefinition<InputSchema, Id, Output, OutputSchema>, run: (neon: NeonClient<true>, input: z.output<InputSchema>, signal: AbortSignal | undefined, context: NeonToolExecutionContext) => Promise<Output>) => NeonTool<InputSchema, Id, JsonSafe<Awaited<Output>>, OutputSchema> & {
|
|
46
|
+
outputSchema: OutputSchema;
|
|
47
|
+
};
|
|
42
48
|
/** A tool that calls no Neon API and so needs no credential. */
|
|
43
|
-
export declare const bindPublicTool: <const InputSchema extends z.ZodType, const Id extends string, Output>(tool:
|
|
49
|
+
export declare const bindPublicTool: <const InputSchema extends z.ZodType, const Id extends string, Output, OutputSchema extends z.ZodType>(tool: ToolDefinition<InputSchema, Id, Output, OutputSchema>, run: (input: z.output<InputSchema>, context: NeonToolExecutionContext) => Promise<Output>) => NeonTool<InputSchema, Id, JsonSafe<Awaited<Output>>, OutputSchema> & {
|
|
50
|
+
outputSchema: OutputSchema;
|
|
51
|
+
};
|
|
44
52
|
type GeneratedTool<G extends NeonOperationId> = ReturnType<(typeof operationFactories)[G]>;
|
|
45
53
|
type GeneratedSchema<G extends NeonOperationId> = GeneratedTool<G>["inputSchema"];
|
|
46
54
|
type GeneratedInput<G extends NeonOperationId> = z.output<GeneratedSchema<G>>;
|
|
@@ -49,19 +57,29 @@ type FromGeneratedMeta = {
|
|
|
49
57
|
list?: boolean;
|
|
50
58
|
annotations?: NeonToolAnnotations;
|
|
51
59
|
requiresApproval?: boolean;
|
|
60
|
+
/** Defaults to a `GET` that needs no approval. */
|
|
61
|
+
readOnlySafe?: boolean;
|
|
62
|
+
secretOutputFields?: readonly NeonSecretField[];
|
|
63
|
+
returnsOnlySecrets?: boolean;
|
|
52
64
|
};
|
|
53
65
|
type OmittedInput<G extends NeonOperationId, Keys extends string> = Omit<GeneratedInput<G>, Keys>;
|
|
54
66
|
type OmittedArg<G extends NeonOperationId, Keys extends string> = Omit<GeneratedArg<G>, Keys>;
|
|
55
|
-
export declare function fromGenerated<const Id extends NeonToolId, const G extends NeonOperationId, Output>(options: ToolClientOptions, spec: FromGeneratedMeta & {
|
|
67
|
+
export declare function fromGenerated<const Id extends NeonToolId, const G extends NeonOperationId, Output, OutputSchema extends z.ZodType>(options: ToolClientOptions, spec: FromGeneratedMeta & {
|
|
56
68
|
id: Id;
|
|
57
69
|
generated: G;
|
|
70
|
+
output: OutputSchema;
|
|
58
71
|
run: (neon: NeonClient<true>, input: GeneratedInput<G>, signal?: AbortSignal) => Promise<Output>;
|
|
59
|
-
}): NeonTool<GeneratedSchema<G>, PublishedId<Id>, JsonSafe<Awaited<Output
|
|
60
|
-
|
|
72
|
+
}): NeonTool<GeneratedSchema<G>, PublishedId<Id>, JsonSafe<Awaited<Output>>, OutputSchema> & {
|
|
73
|
+
outputSchema: OutputSchema;
|
|
74
|
+
};
|
|
75
|
+
export declare function fromGenerated<const Id extends NeonToolId, const G extends NeonOperationId, const Keys extends keyof GeneratedInput<G> & string, Output, OutputSchema extends z.ZodType>(options: ToolClientOptions, spec: FromGeneratedMeta & {
|
|
61
76
|
id: Id;
|
|
62
77
|
generated: G;
|
|
63
78
|
omit: readonly Keys[];
|
|
79
|
+
output: OutputSchema;
|
|
64
80
|
run: (neon: NeonClient<true>, input: OmittedInput<G, Keys>, signal?: AbortSignal) => Promise<Output>;
|
|
65
|
-
}): NeonTool<z.ZodType<OmittedInput<G, Keys>, OmittedArg<G, Keys>>, PublishedId<Id>, JsonSafe<Awaited<Output
|
|
81
|
+
}): NeonTool<z.ZodType<OmittedInput<G, Keys>, OmittedArg<G, Keys>>, PublishedId<Id>, JsonSafe<Awaited<Output>>, OutputSchema> & {
|
|
82
|
+
outputSchema: OutputSchema;
|
|
83
|
+
};
|
|
66
84
|
export {};
|
|
67
85
|
//# sourceMappingURL=bind.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../../../src/lib/ergonomic/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,UAAU,EAEf,KAAK,UAAU,EACf,KAAK,SAAS,EACd,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,EACN,KAAK,eAAe,EACpB,kBAAkB,EAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEN,KAAK,oBAAoB,EAEzB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../../../src/lib/ergonomic/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,UAAU,EAEf,KAAK,UAAU,EACf,KAAK,SAAS,EACd,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,EACN,KAAK,eAAe,EACpB,kBAAkB,EAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEN,KAAK,oBAAoB,EAEzB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAE1B,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;IAC1B,2CAA2C;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4CAA4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CAAC,CAAC,CAAC,EAClB,WAAW,CAAC,EAAE,CAAC,EACf,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EACzB,YAAY,CACZ,GAAG;IAAE,YAAY,EAAE,YAAY,CAAA;CAAE,CAAC;AACnC,wBAAgB,aAAa,CAC5B,KAAK,CAAC,EAAE,SAAS,UAAU,EAC3B,KAAK,CAAC,CAAC,SAAS,eAAe,EAC/B,KAAK,CAAC,IAAI,SAAS,MAAM,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,EACnD,MAAM,EACN,YAAY,SAAS,CAAC,CAAC,OAAO,EAE9B,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,iBAAiB,GAAG;IACzB,EAAE,EAAE,EAAE,CAAC;IACP,SAAS,EAAE,CAAC,CAAC;IACb,IAAI,EAAE,SAAS,IAAI,EAAE,CAAC;IACtB,MAAM,EAAE,YAAY,CAAC;IACrB,GAAG,EAAE,CACJ,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,EACtB,KAAK,EAAE,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,EAC5B,MAAM,CAAC,EAAE,WAAW,KAChB,OAAO,CAAC,MAAM,CAAC,CAAC;CACrB,GACC,QAAQ,CACV,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EACrD,WAAW,CAAC,EAAE,CAAC,EACf,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EACzB,YAAY,CACZ,GAAG;IAAE,YAAY,EAAE,YAAY,CAAA;CAAE,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { toolDescriptions } from "../../descriptions.gen.js";
|
|
2
2
|
import { missingBearerCredential, requireBearerCredential } from "../auth.js";
|
|
3
3
|
import { toToolResult } from "../result.js";
|
|
4
|
+
import { toolMetadata } from "../operation.js";
|
|
4
5
|
import { operationFactories } from "../../operations.gen.js";
|
|
5
|
-
import { NeonClientError, createNeonClient } from "@neon/sdk";
|
|
6
6
|
import * as z from "zod";
|
|
7
|
+
import { NeonClientError, createNeonClient } from "@neon/sdk";
|
|
7
8
|
// src/lib/ergonomic/bind.ts
|
|
8
9
|
const ALL_PAGES = " Returns every page. Pass limit to cap how many.";
|
|
9
10
|
const inertClient = createNeonClient({ apiKey: "unused" }).client;
|
|
@@ -87,6 +88,7 @@ const collectPages = async (list, maxItems) => {
|
|
|
87
88
|
};
|
|
88
89
|
const bindTool = (options, tool, run) => ({
|
|
89
90
|
...tool,
|
|
91
|
+
metadata: toolMetadata(tool.metadata),
|
|
90
92
|
async execute(input, context) {
|
|
91
93
|
const parsed = await tool.inputSchema.parseAsync(input);
|
|
92
94
|
const result = await run(toolClient(options, context), parsed, context?.signal, context ?? {});
|
|
@@ -96,6 +98,7 @@ const bindTool = (options, tool, run) => ({
|
|
|
96
98
|
/** A tool that calls no Neon API and so needs no credential. */
|
|
97
99
|
const bindPublicTool = (tool, run) => ({
|
|
98
100
|
...tool,
|
|
101
|
+
metadata: toolMetadata(tool.metadata),
|
|
99
102
|
async execute(input, context) {
|
|
100
103
|
const parsed = await tool.inputSchema.parseAsync(input);
|
|
101
104
|
return toToolResult(await run(parsed, context ?? {}));
|
|
@@ -106,15 +109,22 @@ function fromGenerated(options, spec) {
|
|
|
106
109
|
const schema = generated.inputSchema;
|
|
107
110
|
const inputSchema = spec.omit === void 0 || spec.omit.length === 0 ? schema : omitObjectKeys(schema, spec.omit);
|
|
108
111
|
const description = toolDescriptions[spec.id] ?? generated.description;
|
|
112
|
+
const requiresApproval = spec.requiresApproval ?? generated.requiresApproval;
|
|
109
113
|
return {
|
|
110
114
|
operationId: spec.id,
|
|
111
115
|
id: publishedId(spec.id),
|
|
112
116
|
title: generated.title,
|
|
113
117
|
description: spec.list ? `${description.trimEnd()}${ALL_PAGES}` : description,
|
|
114
118
|
inputSchema,
|
|
119
|
+
outputSchema: spec.output,
|
|
115
120
|
annotations: spec.annotations ?? generated.annotations,
|
|
116
|
-
requiresApproval
|
|
117
|
-
metadata:
|
|
121
|
+
requiresApproval,
|
|
122
|
+
metadata: toolMetadata({
|
|
123
|
+
...generated.metadata,
|
|
124
|
+
readOnlySafe: spec.readOnlySafe ?? (generated.metadata.method === "GET" && !requiresApproval),
|
|
125
|
+
secretOutputFields: spec.secretOutputFields,
|
|
126
|
+
returnsOnlySecrets: spec.returnsOnlySecrets
|
|
127
|
+
}),
|
|
118
128
|
async execute(input, context) {
|
|
119
129
|
const parsed = await inputSchema.parseAsync(input);
|
|
120
130
|
const result = await spec.run(toolClient(options, context), parsed, context?.signal);
|