@neon/tools 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +150 -7
- package/dist/descriptions.gen.d.ts +10 -0
- package/dist/descriptions.gen.d.ts.map +1 -0
- package/dist/descriptions.gen.js +150 -0
- package/dist/generated/zod.gen.d.ts +33 -2
- package/dist/generated/zod.gen.d.ts.map +1 -1
- package/dist/generated/zod.gen.js +29 -11
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -11
- package/dist/lib/custom/auth-config.d.ts +164 -0
- package/dist/lib/custom/auth-config.d.ts.map +1 -0
- package/dist/lib/custom/auth-config.js +177 -0
- package/dist/lib/custom/docs.d.ts +58 -0
- package/dist/lib/custom/docs.d.ts.map +1 -0
- package/dist/lib/custom/docs.js +143 -0
- package/dist/lib/custom/feedback.d.ts +15 -0
- package/dist/lib/custom/feedback.d.ts.map +1 -0
- package/dist/lib/custom/feedback.js +55 -0
- package/dist/lib/custom/fetch.d.ts +402 -0
- package/dist/lib/custom/fetch.d.ts.map +1 -0
- package/dist/lib/custom/fetch.js +198 -0
- package/dist/lib/custom/organizations.d.ts +23 -0
- package/dist/lib/custom/organizations.d.ts.map +1 -0
- package/dist/lib/custom/organizations.js +32 -0
- package/dist/lib/custom/resources.d.ts +22 -0
- package/dist/lib/custom/resources.d.ts.map +1 -0
- package/dist/lib/custom/resources.js +113 -0
- package/dist/lib/custom/sql/connection.d.ts +46 -0
- package/dist/lib/custom/sql/connection.d.ts.map +1 -0
- package/dist/lib/custom/sql/connection.js +78 -0
- package/dist/lib/custom/sql/describe-branch.d.ts +84 -0
- package/dist/lib/custom/sql/describe-branch.d.ts.map +1 -0
- package/dist/lib/custom/sql/describe-branch.js +155 -0
- package/dist/lib/custom/sql/inspect/inspect.d.ts +75 -0
- package/dist/lib/custom/sql/inspect/inspect.d.ts.map +1 -0
- package/dist/lib/custom/sql/inspect/inspect.js +135 -0
- package/dist/lib/custom/sql/inspect/queries.d.ts +63 -0
- package/dist/lib/custom/sql/inspect/queries.d.ts.map +1 -0
- package/dist/lib/custom/sql/inspect/queries.js +528 -0
- package/dist/lib/custom/sql/inspect/report.d.ts +31 -0
- package/dist/lib/custom/sql/inspect/report.d.ts.map +1 -0
- package/dist/lib/custom/sql/inspect/report.js +43 -0
- package/dist/lib/custom/sql/inspect/targets.d.ts +27 -0
- package/dist/lib/custom/sql/inspect/targets.d.ts.map +1 -0
- package/dist/lib/custom/sql/inspect/targets.js +33 -0
- package/dist/lib/custom/sql/migrations.d.ts +69 -0
- package/dist/lib/custom/sql/migrations.d.ts.map +1 -0
- package/dist/lib/custom/sql/migrations.js +144 -0
- package/dist/lib/custom/sql/plan.d.ts +27 -0
- package/dist/lib/custom/sql/plan.d.ts.map +1 -0
- package/dist/lib/custom/sql/plan.js +53 -0
- package/dist/lib/custom/sql/query-tuning.d.ts +107 -0
- package/dist/lib/custom/sql/query-tuning.d.ts.map +1 -0
- package/dist/lib/custom/sql/query-tuning.js +129 -0
- package/dist/lib/custom/sql/rows.d.ts +11 -0
- package/dist/lib/custom/sql/rows.d.ts.map +1 -0
- package/dist/lib/custom/sql/rows.js +19 -0
- package/dist/lib/custom/sql/run.d.ts +81 -0
- package/dist/lib/custom/sql/run.d.ts.map +1 -0
- package/dist/lib/custom/sql/run.js +90 -0
- package/dist/lib/custom/sql/schema.d.ts +84 -0
- package/dist/lib/custom/sql/schema.d.ts.map +1 -0
- package/dist/lib/custom/sql/schema.js +201 -0
- package/dist/lib/custom/sql/slow-queries.d.ts +43 -0
- package/dist/lib/custom/sql/slow-queries.d.ts.map +1 -0
- package/dist/lib/custom/sql/slow-queries.js +87 -0
- package/dist/lib/customize.d.ts +9 -2
- package/dist/lib/customize.d.ts.map +1 -1
- package/dist/lib/customize.js +21 -7
- package/dist/lib/ergonomic/bind.d.ts +11 -1
- 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 +870 -38
- package/dist/lib/ergonomic/catalog.d.ts.map +1 -1
- package/dist/lib/ergonomic/catalog.js +44 -8
- package/dist/lib/ergonomic/composed.d.ts +4 -4
- package/dist/lib/ergonomic/composed.d.ts.map +1 -1
- package/dist/lib/ergonomic/composed.js +47 -45
- package/dist/lib/ergonomic/ids.d.ts +3 -1
- package/dist/lib/ergonomic/ids.d.ts.map +1 -1
- package/dist/lib/ergonomic/ids.js +42 -2
- package/dist/lib/ergonomic/index.d.ts +1 -1
- package/dist/lib/ergonomic/index.d.ts.map +1 -1
- package/dist/lib/ergonomic/index.js +2 -2
- package/dist/lib/operation.d.ts +11 -0
- package/dist/lib/operation.d.ts.map +1 -1
- package/dist/lib/references.d.ts +10 -0
- package/dist/lib/references.d.ts.map +1 -0
- package/dist/lib/references.js +28 -0
- package/dist/operations.gen.d.ts +22 -2
- package/dist/operations.gen.d.ts.map +1 -1
- package/dist/operations.gen.js +335 -300
- package/dist/schemas.d.ts +1 -1
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +1 -1
- package/package.json +9 -6
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { pathInputDescriptions } from "../../descriptions.gen.js";
|
|
2
|
+
import { zGetNeonAuthPath } from "../../generated/zod.gen.js";
|
|
3
|
+
import { bindTool, publishedId } from "../ergonomic/bind.js";
|
|
4
|
+
import { NeonApiError } from "@neon/sdk";
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
// src/lib/custom/auth-config.ts
|
|
7
|
+
const REDACTED_SECRET = "***redacted***";
|
|
8
|
+
const getAuthConfigInputSchema = z.strictObject({
|
|
9
|
+
project_id: zGetNeonAuthPath.shape.project_id.describe(pathInputDescriptions.project_id),
|
|
10
|
+
branch_id: zGetNeonAuthPath.shape.branch_id.describe(`${pathInputDescriptions.branch_id} Omit it for the project's default branch.`).optional()
|
|
11
|
+
});
|
|
12
|
+
/** The API's inverted flags are renamed so `allow_sign_up: true` means sign-up is allowed. */
|
|
13
|
+
const emailPasswordSettings = (data) => ({
|
|
14
|
+
enabled: data.enabled,
|
|
15
|
+
allow_sign_up: !data.disable_sign_up,
|
|
16
|
+
verify_email_on_sign_up: data.send_verification_email_on_sign_up,
|
|
17
|
+
verify_email_on_sign_in: data.send_verification_email_on_sign_in,
|
|
18
|
+
email_verification_method: data.email_verification_method,
|
|
19
|
+
require_email_verification: data.require_email_verification,
|
|
20
|
+
auto_sign_in_after_verification: data.auto_sign_in_after_verification,
|
|
21
|
+
revoke_sessions_on_password_reset: data.revoke_sessions_on_password_reset
|
|
22
|
+
});
|
|
23
|
+
const oauthProviderSettings = (provider) => ({
|
|
24
|
+
id: provider.id,
|
|
25
|
+
type: provider.type,
|
|
26
|
+
client_id: provider.client_id ?? null,
|
|
27
|
+
client_secret: provider.client_secret ? REDACTED_SECRET : null,
|
|
28
|
+
...provider.microsoft_tenant_id && { microsoft_tenant_id: provider.microsoft_tenant_id },
|
|
29
|
+
...provider.apple_team_id && { apple_team_id: provider.apple_team_id },
|
|
30
|
+
...provider.apple_key_id && { apple_key_id: provider.apple_key_id }
|
|
31
|
+
});
|
|
32
|
+
const emailProviderSettings = (data) => {
|
|
33
|
+
if (data.type === "standard") {
|
|
34
|
+
if (data.host === void 0 || data.port === void 0 || data.username === void 0) throw new Error("Standard email provider is missing host, port, or username");
|
|
35
|
+
return {
|
|
36
|
+
type: "standard",
|
|
37
|
+
host: data.host,
|
|
38
|
+
port: data.port,
|
|
39
|
+
username: data.username,
|
|
40
|
+
password: REDACTED_SECRET,
|
|
41
|
+
sender_email: data.sender_email,
|
|
42
|
+
sender_name: data.sender_name
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
type: "shared",
|
|
47
|
+
sender_email: data.sender_email ?? null,
|
|
48
|
+
sender_name: data.sender_name ?? null
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const pluginSettings = (data) => ({
|
|
52
|
+
organization: data.organization ?? null,
|
|
53
|
+
magic_link: data.magic_link ?? null,
|
|
54
|
+
phone_number: data.phone_number ?? null
|
|
55
|
+
});
|
|
56
|
+
const ERROR_SNIPPET_MAX_LENGTH = 200;
|
|
57
|
+
/** A short, single-line hint from an API error body, so an HTML error page never lands in the result. */
|
|
58
|
+
const errorBodySnippet = (body) => {
|
|
59
|
+
let text;
|
|
60
|
+
if (typeof body === "string") text = body;
|
|
61
|
+
else if (typeof body === "object" && body !== null) for (const key of [
|
|
62
|
+
"message",
|
|
63
|
+
"error",
|
|
64
|
+
"detail"
|
|
65
|
+
]) {
|
|
66
|
+
const value = Reflect.get(body, key);
|
|
67
|
+
if (typeof value === "string") {
|
|
68
|
+
text = value;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const cleaned = text?.replace(/[\u0000-\u001F\u007F]+/g, " ").trim();
|
|
73
|
+
if (!cleaned) return void 0;
|
|
74
|
+
return cleaned.length > ERROR_SNIPPET_MAX_LENGTH ? `${cleaned.slice(0, ERROR_SNIPPET_MAX_LENGTH)}…` : cleaned;
|
|
75
|
+
};
|
|
76
|
+
const describeReadError = (error) => {
|
|
77
|
+
const snippet = error.status === 404 ? void 0 : errorBodySnippet(error.body);
|
|
78
|
+
return `${error.status} ${snippet ? `${error.message}: ${snippet}` : error.message}`;
|
|
79
|
+
};
|
|
80
|
+
/** Email provider, plugins, and webhook are optional reads: an API error is reported under `_errors` instead of failing the tool. */
|
|
81
|
+
const optionalRead = async (read) => {
|
|
82
|
+
try {
|
|
83
|
+
return {
|
|
84
|
+
ok: true,
|
|
85
|
+
data: await read()
|
|
86
|
+
};
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error instanceof NeonApiError) return {
|
|
89
|
+
ok: false,
|
|
90
|
+
error
|
|
91
|
+
};
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const readAuthConfig = async (neon, input, signal) => {
|
|
96
|
+
const projectId = input.project_id;
|
|
97
|
+
let defaultBranch;
|
|
98
|
+
let branchId;
|
|
99
|
+
if (input.branch_id === void 0) {
|
|
100
|
+
defaultBranch = await neon.branches.getDefault({ projectId }, { signal });
|
|
101
|
+
branchId = defaultBranch.id;
|
|
102
|
+
} else branchId = input.branch_id;
|
|
103
|
+
const ids = {
|
|
104
|
+
projectId,
|
|
105
|
+
branchId
|
|
106
|
+
};
|
|
107
|
+
const integration = await neon.auth.get(ids, { signal });
|
|
108
|
+
const [domains, localhost, emailPassword, oauthProviders, emailProvider, plugins, webhook, branch] = await Promise.all([
|
|
109
|
+
neon.auth.trustedDomains.list(ids, { signal }),
|
|
110
|
+
neon.auth.allowLocalhost.get(ids, { signal }),
|
|
111
|
+
neon.auth.emailAndPassword.get(ids, { signal }),
|
|
112
|
+
neon.auth.oauthProviders.list(ids, { signal }),
|
|
113
|
+
optionalRead(() => neon.auth.emailProvider.get(ids, { signal })),
|
|
114
|
+
optionalRead(() => neon.auth.plugins.get(ids, { signal })),
|
|
115
|
+
optionalRead(() => neon.auth.webhooks.get(ids, { signal })),
|
|
116
|
+
defaultBranch ?? neon.branches.get(ids, { signal })
|
|
117
|
+
]);
|
|
118
|
+
const errors = {};
|
|
119
|
+
let emailProviderValue = null;
|
|
120
|
+
if (emailProvider.ok) emailProviderValue = emailProviderSettings(emailProvider.data);
|
|
121
|
+
else if (emailProvider.error.status !== 404) errors.email_provider = describeReadError(emailProvider.error);
|
|
122
|
+
let pluginsValue = null;
|
|
123
|
+
if (plugins.ok) pluginsValue = pluginSettings(plugins.data);
|
|
124
|
+
else errors.plugins = describeReadError(plugins.error);
|
|
125
|
+
let webhookValue = null;
|
|
126
|
+
if (webhook.ok) webhookValue = webhook.data;
|
|
127
|
+
else errors.webhook = describeReadError(webhook.error);
|
|
128
|
+
return {
|
|
129
|
+
project_id: projectId,
|
|
130
|
+
branch_id: branchId,
|
|
131
|
+
branch_name: branch.name,
|
|
132
|
+
base_url: integration.base_url ?? null,
|
|
133
|
+
jwks_url: integration.jwks_url,
|
|
134
|
+
db_name: integration.db_name,
|
|
135
|
+
integration: {
|
|
136
|
+
auth_provider: integration.auth_provider,
|
|
137
|
+
auth_provider_project_id: integration.auth_provider_project_id,
|
|
138
|
+
branch_id: integration.branch_id,
|
|
139
|
+
db_name: integration.db_name,
|
|
140
|
+
created_at: integration.created_at,
|
|
141
|
+
owned_by: integration.owned_by,
|
|
142
|
+
jwks_url: integration.jwks_url,
|
|
143
|
+
base_url: integration.base_url,
|
|
144
|
+
...integration.transfer_status !== void 0 && { transfer_status: integration.transfer_status }
|
|
145
|
+
},
|
|
146
|
+
trusted_origins: domains.map((entry) => entry.domain),
|
|
147
|
+
allow_localhost: localhost.allow_localhost,
|
|
148
|
+
auth_methods: { email_password: emailPasswordSettings(emailPassword) },
|
|
149
|
+
oauth_providers: oauthProviders.map(oauthProviderSettings),
|
|
150
|
+
email_provider: emailProviderValue,
|
|
151
|
+
plugins: pluginsValue,
|
|
152
|
+
webhook: webhookValue,
|
|
153
|
+
...Object.keys(errors).length > 0 && { _errors: errors }
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
const getAuthConfigTool = (options) => bindTool(options, {
|
|
157
|
+
operationId: "auth.getConfig",
|
|
158
|
+
id: publishedId("auth.getConfig"),
|
|
159
|
+
title: "Get Neon Auth configuration",
|
|
160
|
+
description: "Returns a branch's Neon Auth integration and settings: trusted origins, localhost, email and password, OAuth and email providers, plugins, and webhook, with secrets redacted. Needs Neon Auth on the branch ({{auth.create}}).",
|
|
161
|
+
inputSchema: getAuthConfigInputSchema,
|
|
162
|
+
annotations: {
|
|
163
|
+
readOnlyHint: true,
|
|
164
|
+
destructiveHint: false,
|
|
165
|
+
idempotentHint: true,
|
|
166
|
+
openWorldHint: false
|
|
167
|
+
},
|
|
168
|
+
requiresApproval: false,
|
|
169
|
+
metadata: {
|
|
170
|
+
method: "GET",
|
|
171
|
+
path: "/projects/{project_id}/branches/{branch_id}/auth",
|
|
172
|
+
stability: "stable",
|
|
173
|
+
deprecated: false,
|
|
174
|
+
tags: ["Auth"]
|
|
175
|
+
}
|
|
176
|
+
}, readAuthConfig);
|
|
177
|
+
export { REDACTED_SECRET, getAuthConfigInputSchema, getAuthConfigTool, readAuthConfig };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { type ToolClientOptions } from "../ergonomic/bind.js";
|
|
3
|
+
import type { NeonToolCaller } from "../operation.js";
|
|
4
|
+
export declare const DEFAULT_SITE_SEARCH_URL = "https://br-frosty-cell-a5smzg39-assistant.compute.c-1.us-east-2.aws.neon.tech/site-search";
|
|
5
|
+
export declare const DEFAULT_DOCS_BASE_URL = "https://neon.com";
|
|
6
|
+
export declare const UPSTREAM_TIMEOUT_MS = 10000;
|
|
7
|
+
export declare const upstreamSignal: (signal?: AbortSignal) => AbortSignal;
|
|
8
|
+
export declare const searchDocsInputSchema: z.ZodObject<{
|
|
9
|
+
query: z.ZodString;
|
|
10
|
+
categories: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
11
|
+
docs: "docs";
|
|
12
|
+
api: "api";
|
|
13
|
+
postgresql: "postgresql";
|
|
14
|
+
guides: "guides";
|
|
15
|
+
faqs: "faqs";
|
|
16
|
+
blog: "blog";
|
|
17
|
+
changelog: "changelog";
|
|
18
|
+
}>>>;
|
|
19
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
20
|
+
}, z.core.$strict>;
|
|
21
|
+
export declare const getDocInputSchema: z.ZodObject<{
|
|
22
|
+
slug: z.ZodString;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
/**
|
|
25
|
+
* The search service records each search by caller. A source that cannot be a
|
|
26
|
+
* header falls back to the default; a user agent or client that cannot is dropped.
|
|
27
|
+
*/
|
|
28
|
+
export declare const searchDocsHeaders: (caller: NeonToolCaller | undefined) => Record<string, string>;
|
|
29
|
+
export declare const searchDocsTool: (options: ToolClientOptions) => import("../operation.js").NeonTool<z.ZodObject<{
|
|
30
|
+
query: z.ZodString;
|
|
31
|
+
categories: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
32
|
+
docs: "docs";
|
|
33
|
+
api: "api";
|
|
34
|
+
postgresql: "postgresql";
|
|
35
|
+
guides: "guides";
|
|
36
|
+
faqs: "faqs";
|
|
37
|
+
blog: "blog";
|
|
38
|
+
changelog: "changelog";
|
|
39
|
+
}>>>;
|
|
40
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
41
|
+
}, z.core.$strict>, "search_docs", {
|
|
42
|
+
hits: {
|
|
43
|
+
title: string;
|
|
44
|
+
url: string;
|
|
45
|
+
slug: string;
|
|
46
|
+
category: string;
|
|
47
|
+
breadcrumb: string[];
|
|
48
|
+
heading: string;
|
|
49
|
+
excerpt: string;
|
|
50
|
+
}[];
|
|
51
|
+
}>;
|
|
52
|
+
export declare const getDocTool: (options: ToolClientOptions) => import("../operation.js").NeonTool<z.ZodObject<{
|
|
53
|
+
slug: z.ZodString;
|
|
54
|
+
}, z.core.$strict>, "get_docs", {
|
|
55
|
+
url: string;
|
|
56
|
+
markdown: string;
|
|
57
|
+
}>;
|
|
58
|
+
//# sourceMappingURL=docs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../../src/lib/custom/docs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAuB,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE3E,eAAO,MAAM,uBAAuB,8FACwD,CAAC;AAC7F,eAAO,MAAM,qBAAqB,qBAAqB,CAAC;AAGxD,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAE1C,eAAO,MAAM,cAAc,GAAI,SAAS,WAAW,gBAGlD,CAAC;AAmBF,eAAO,MAAM,qBAAqB;;;;;;;;;;;;kBA2BhC,CAAC;AAEH,eAAO,MAAM,iBAAiB;;kBAM5B,CAAC;AAiCH;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC7B,QAAQ,cAAc,GAAG,SAAS,KAChC,MAAM,CAAC,MAAM,EAAE,MAAM,CAkBvB,CAAC;AAoBF,eAAO,MAAM,cAAc,GAAI,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;EA0DxD,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,SAAS,iBAAiB;;;;;EAyCpD,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { bindPublicTool, publishedId } from "../ergonomic/bind.js";
|
|
2
|
+
import { NeonClientError } from "@neon/sdk";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
// src/lib/custom/docs.ts
|
|
5
|
+
const DEFAULT_SITE_SEARCH_URL = "https://br-frosty-cell-a5smzg39-assistant.compute.c-1.us-east-2.aws.neon.tech/site-search";
|
|
6
|
+
const DEFAULT_DOCS_BASE_URL = "https://neon.com";
|
|
7
|
+
const UPSTREAM_TIMEOUT_MS = 1e4;
|
|
8
|
+
const upstreamSignal = (signal) => {
|
|
9
|
+
const timeout = AbortSignal.timeout(UPSTREAM_TIMEOUT_MS);
|
|
10
|
+
return signal === void 0 ? timeout : AbortSignal.any([signal, timeout]);
|
|
11
|
+
};
|
|
12
|
+
const docsAnnotations = {
|
|
13
|
+
readOnlyHint: true,
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
idempotentHint: true,
|
|
16
|
+
openWorldHint: true
|
|
17
|
+
};
|
|
18
|
+
const SITE_SEARCH_CATEGORIES = [
|
|
19
|
+
"docs",
|
|
20
|
+
"api",
|
|
21
|
+
"postgresql",
|
|
22
|
+
"guides",
|
|
23
|
+
"faqs",
|
|
24
|
+
"blog",
|
|
25
|
+
"changelog"
|
|
26
|
+
];
|
|
27
|
+
const searchDocsInputSchema = z.strictObject({
|
|
28
|
+
query: z.string().trim().min(1).max(500).describe("What to search for, in words, e.g. \"reset a branch\" or \"connection pooling\"."),
|
|
29
|
+
categories: z.array(z.enum(SITE_SEARCH_CATEGORIES)).min(1).max(SITE_SEARCH_CATEGORIES.length).refine((values) => new Set(values).size === values.length, { message: "categories must not repeat a value" }).optional().describe("Only these categories; api is the API reference, postgresql the PostgreSQL tutorial."),
|
|
30
|
+
limit: z.number().int().min(1).max(40).default(10).describe("Maximum number of pages to return.")
|
|
31
|
+
});
|
|
32
|
+
const getDocInputSchema = z.strictObject({ slug: z.string().describe("The slug of a {{docs.search}} hit, e.g. 'docs/guides/prisma' or 'postgresql/tutorial/inner-join'.") });
|
|
33
|
+
const UNEXPECTED_SEARCH_RESPONSE = "Neon site search returned an unexpected response";
|
|
34
|
+
const searchDocsResponseSchema = z.object({ hits: z.array(z.object({
|
|
35
|
+
title: z.string(),
|
|
36
|
+
url: z.string(),
|
|
37
|
+
slug: z.string(),
|
|
38
|
+
category: z.string(),
|
|
39
|
+
breadcrumb: z.array(z.string()),
|
|
40
|
+
heading: z.string(),
|
|
41
|
+
excerpt: z.string()
|
|
42
|
+
})) });
|
|
43
|
+
const upstreamError = (body) => {
|
|
44
|
+
if (typeof body !== "object" || body === null || !("error" in body)) return;
|
|
45
|
+
return typeof body.error === "string" && body.error.trim() !== "" ? body.error : void 0;
|
|
46
|
+
};
|
|
47
|
+
const PRINTABLE_ASCII = /^[\x20-\x7E]+$/;
|
|
48
|
+
const DEFAULT_CALLER_SOURCE = "neon_tools";
|
|
49
|
+
/**
|
|
50
|
+
* The search service records each search by caller. A source that cannot be a
|
|
51
|
+
* header falls back to the default; a user agent or client that cannot is dropped.
|
|
52
|
+
*/
|
|
53
|
+
const searchDocsHeaders = (caller) => {
|
|
54
|
+
const source = caller?.source.trim().slice(0, 100);
|
|
55
|
+
const headers = {
|
|
56
|
+
"Content-Type": "application/json",
|
|
57
|
+
"x-caller-source": source && PRINTABLE_ASCII.test(source) ? source : DEFAULT_CALLER_SOURCE
|
|
58
|
+
};
|
|
59
|
+
const userAgent = caller?.userAgent?.trim().slice(0, 512);
|
|
60
|
+
if (userAgent && PRINTABLE_ASCII.test(userAgent)) headers["x-caller-user-agent"] = userAgent;
|
|
61
|
+
const client = caller?.client?.trim().slice(0, 100);
|
|
62
|
+
if (client && client !== "unknown") headers["x-caller-client"] = encodeURIComponent(client);
|
|
63
|
+
return headers;
|
|
64
|
+
};
|
|
65
|
+
const validateDocSlug = (slug) => {
|
|
66
|
+
if (slug.includes("..")) throw new NeonClientError("Invalid doc slug: path traversal (\"..\") is not allowed");
|
|
67
|
+
if (slug.includes("://")) throw new NeonClientError("Invalid doc slug: absolute URLs are not allowed");
|
|
68
|
+
if (slug.startsWith("/")) throw new NeonClientError("Invalid doc slug: slug must not start with \"/\"");
|
|
69
|
+
};
|
|
70
|
+
const searchDocsTool = (options) => {
|
|
71
|
+
const url = options.siteSearchUrl ?? "https://br-frosty-cell-a5smzg39-assistant.compute.c-1.us-east-2.aws.neon.tech/site-search";
|
|
72
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
73
|
+
return bindPublicTool({
|
|
74
|
+
operationId: "docs.search",
|
|
75
|
+
id: publishedId("docs.search"),
|
|
76
|
+
title: "Search Documentation",
|
|
77
|
+
description: "Searches neon.com docs, API reference, PostgreSQL tutorial, guides, FAQs, changelog, and blog for ranked pages with the slug {{docs.get}} reads.",
|
|
78
|
+
inputSchema: searchDocsInputSchema,
|
|
79
|
+
annotations: docsAnnotations,
|
|
80
|
+
requiresApproval: false,
|
|
81
|
+
metadata: {
|
|
82
|
+
method: "POST",
|
|
83
|
+
path: "/site-search",
|
|
84
|
+
stability: "stable",
|
|
85
|
+
deprecated: false,
|
|
86
|
+
tags: ["Docs"]
|
|
87
|
+
}
|
|
88
|
+
}, async (input, context) => {
|
|
89
|
+
const response = await fetchImpl(url, {
|
|
90
|
+
method: "POST",
|
|
91
|
+
headers: searchDocsHeaders(context.caller),
|
|
92
|
+
body: JSON.stringify(input),
|
|
93
|
+
signal: upstreamSignal(context.signal)
|
|
94
|
+
});
|
|
95
|
+
const raw = await response.text();
|
|
96
|
+
let body;
|
|
97
|
+
try {
|
|
98
|
+
body = JSON.parse(raw);
|
|
99
|
+
} catch {
|
|
100
|
+
throw new Error(`${UNEXPECTED_SEARCH_RESPONSE}: HTTP ${response.status}, body is not JSON`);
|
|
101
|
+
}
|
|
102
|
+
if (response.status === 400) throw new NeonClientError(upstreamError(body) ?? "Neon site search rejected the request");
|
|
103
|
+
if (!response.ok) throw new Error(`Neon site search failed: HTTP ${response.status}`);
|
|
104
|
+
const parsed = searchDocsResponseSchema.safeParse(body);
|
|
105
|
+
if (!parsed.success) {
|
|
106
|
+
const issue = parsed.error.issues[0];
|
|
107
|
+
throw new Error(`${UNEXPECTED_SEARCH_RESPONSE}: ${issue?.path.join(".")} ${issue?.message}`);
|
|
108
|
+
}
|
|
109
|
+
return parsed.data;
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const getDocTool = (options) => {
|
|
113
|
+
const baseUrl = options.docsBaseUrl ?? "https://neon.com";
|
|
114
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
115
|
+
return bindPublicTool({
|
|
116
|
+
operationId: "docs.get",
|
|
117
|
+
id: publishedId("docs.get"),
|
|
118
|
+
title: "Get Documentation Page",
|
|
119
|
+
description: "Returns one neon.com page as markdown, by the slug of a {{docs.search}} hit.",
|
|
120
|
+
inputSchema: getDocInputSchema,
|
|
121
|
+
annotations: docsAnnotations,
|
|
122
|
+
requiresApproval: false,
|
|
123
|
+
metadata: {
|
|
124
|
+
method: "GET",
|
|
125
|
+
path: "/{slug}.md",
|
|
126
|
+
stability: "stable",
|
|
127
|
+
deprecated: false,
|
|
128
|
+
tags: ["Docs"]
|
|
129
|
+
}
|
|
130
|
+
}, async ({ slug }, context) => {
|
|
131
|
+
validateDocSlug(slug);
|
|
132
|
+
const mdSlug = slug.endsWith(".md") ? slug : `${slug}.md`;
|
|
133
|
+
const url = `${baseUrl}/${mdSlug}`;
|
|
134
|
+
const response = await fetchImpl(url, { signal: upstreamSignal(context.signal) });
|
|
135
|
+
if (response.status === 404) throw new NeonClientError(`Doc page not found: "${mdSlug}". Pass the slug of a docs search hit.`);
|
|
136
|
+
if (!response.ok) throw new Error(`Failed to fetch doc page "${mdSlug}": ${response.status} ${response.statusText}`);
|
|
137
|
+
return {
|
|
138
|
+
url,
|
|
139
|
+
markdown: await response.text()
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
export { DEFAULT_DOCS_BASE_URL, DEFAULT_SITE_SEARCH_URL, UPSTREAM_TIMEOUT_MS, getDocInputSchema, getDocTool, searchDocsHeaders, searchDocsInputSchema, searchDocsTool, upstreamSignal };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { type ToolClientOptions } from "../ergonomic/bind.js";
|
|
3
|
+
export declare const DEFAULT_FEEDBACK_URL = "https://feedback.neon.tech/";
|
|
4
|
+
export declare const DEFAULT_FEEDBACK_SOURCE = "neon_tools";
|
|
5
|
+
export declare const MAX_FEEDBACK_LENGTH = 10000;
|
|
6
|
+
export declare const sendFeedbackInputSchema: z.ZodObject<{
|
|
7
|
+
feedback: z.ZodString;
|
|
8
|
+
}, z.core.$strict>;
|
|
9
|
+
/** Sends only the message and `source` to the Neon feedback service: no account, project, or credential. */
|
|
10
|
+
export declare const sendFeedbackTool: (options: ToolClientOptions) => import("../operation.js").NeonTool<z.ZodObject<{
|
|
11
|
+
feedback: z.ZodString;
|
|
12
|
+
}, z.core.$strict>, "send_feedback", {
|
|
13
|
+
message: string;
|
|
14
|
+
}>;
|
|
15
|
+
//# sourceMappingURL=feedback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback.d.ts","sourceRoot":"","sources":["../../../src/lib/custom/feedback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAGN,KAAK,iBAAiB,EACtB,MAAM,sBAAsB,CAAC;AAG9B,eAAO,MAAM,oBAAoB,gCAAgC,CAAC;AAClE,eAAO,MAAM,uBAAuB,eAAe,CAAC;AAGpD,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAE1C,eAAO,MAAM,uBAAuB;;kBASlC,CAAC;AAEH,4GAA4G;AAC5G,eAAO,MAAM,gBAAgB,GAAI,SAAS,iBAAiB;;;;EA4D1D,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { bindPublicTool, publishedId } from "../ergonomic/bind.js";
|
|
2
|
+
import { upstreamSignal } from "./docs.js";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
// src/lib/custom/feedback.ts
|
|
5
|
+
const DEFAULT_FEEDBACK_URL = "https://feedback.neon.tech/";
|
|
6
|
+
const DEFAULT_FEEDBACK_SOURCE = "neon_tools";
|
|
7
|
+
const MAX_FEEDBACK_LENGTH = 1e4;
|
|
8
|
+
const sendFeedbackInputSchema = z.strictObject({ feedback: z.string().trim().min(1).max(MAX_FEEDBACK_LENGTH).describe("The feedback to send to Neon. Do not include passwords, API keys, connection strings, or other secrets.") });
|
|
9
|
+
/** Sends only the message and `source` to the Neon feedback service: no account, project, or credential. */
|
|
10
|
+
const sendFeedbackTool = (options) => {
|
|
11
|
+
const url = options.feedbackUrl ?? "https://feedback.neon.tech/";
|
|
12
|
+
const source = options.feedbackSource ?? "neon_tools";
|
|
13
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
14
|
+
return bindPublicTool({
|
|
15
|
+
operationId: "feedback.send",
|
|
16
|
+
id: publishedId("feedback.send"),
|
|
17
|
+
title: "Send Feedback",
|
|
18
|
+
description: "Sends anonymous feedback text to the Neon team, with no account, project, or connection details. Only call it when the user asks to give feedback.",
|
|
19
|
+
inputSchema: sendFeedbackInputSchema,
|
|
20
|
+
annotations: {
|
|
21
|
+
readOnlyHint: false,
|
|
22
|
+
destructiveHint: false,
|
|
23
|
+
idempotentHint: false,
|
|
24
|
+
openWorldHint: true
|
|
25
|
+
},
|
|
26
|
+
requiresApproval: true,
|
|
27
|
+
metadata: {
|
|
28
|
+
method: "POST",
|
|
29
|
+
path: "/",
|
|
30
|
+
stability: "stable",
|
|
31
|
+
deprecated: false,
|
|
32
|
+
tags: ["Feedback"]
|
|
33
|
+
}
|
|
34
|
+
}, async ({ feedback }, context) => {
|
|
35
|
+
let response;
|
|
36
|
+
try {
|
|
37
|
+
response = await fetchImpl(url, {
|
|
38
|
+
method: "POST",
|
|
39
|
+
headers: { "Content-Type": "application/json" },
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
feedback,
|
|
42
|
+
source
|
|
43
|
+
}),
|
|
44
|
+
signal: upstreamSignal(context.signal)
|
|
45
|
+
});
|
|
46
|
+
} catch (error) {
|
|
47
|
+
const reason = error instanceof Error && error.name === "TimeoutError" ? "did not respond in time" : "could not be reached";
|
|
48
|
+
throw new Error(`The Neon feedback service ${reason}. Try again later.`, { cause: error });
|
|
49
|
+
}
|
|
50
|
+
if (response.status === 429) throw new Error("Too many feedback requests. Wait a minute and try again.");
|
|
51
|
+
if (!response.ok) throw new Error(`Failed to send feedback: ${response.status} ${response.statusText}`);
|
|
52
|
+
return { message: "Feedback received. Thank you!" };
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
export { DEFAULT_FEEDBACK_SOURCE, DEFAULT_FEEDBACK_URL, MAX_FEEDBACK_LENGTH, sendFeedbackInputSchema, sendFeedbackTool };
|