@farming-labs/docs 0.2.60 → 0.2.62
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 +1 -1
- package/package.json +11 -1
- package/dist/agent-BFqyqEnC.mjs +0 -4547
- package/dist/agent-DlxriaTs.mjs +0 -624
- package/dist/agent-evals-kJs2Y9xR.mjs +0 -2144
- package/dist/agent-export-BgUaiW8f.mjs +0 -869
- package/dist/agent-scope-CCaIY1aK.mjs +0 -283
- package/dist/agents-Djh-HXih.mjs +0 -219
- package/dist/analytics-Bx44lg6d.mjs +0 -177
- package/dist/cli/index.d.mts +0 -15
- package/dist/cli/index.mjs +0 -452
- package/dist/client/react.d.mts +0 -45
- package/dist/client/react.mjs +0 -223
- package/dist/cloud-BH_sHX64.mjs +0 -1615
- package/dist/cloud-analytics-CSyFE6SS.mjs +0 -132
- package/dist/cloud-ask-ai-B2WnG4fF.d.mts +0 -23
- package/dist/cloud-ask-ai-hnJfj8-X.mjs +0 -382
- package/dist/code-blocks-qe0T8-xe.mjs +0 -871
- package/dist/codeblocks-Bq67u32v.mjs +0 -250
- package/dist/config-DASewQ0x.mjs +0 -363
- package/dist/dev-DgY5xGl9.mjs +0 -1333
- package/dist/docs-cloud-server.d.mts +0 -70
- package/dist/docs-cloud-server.mjs +0 -310
- package/dist/doctor-CO1VMcF_.mjs +0 -1906
- package/dist/downgrade-BZs86NVr.mjs +0 -184
- package/dist/errors-CVqZ3kOO.mjs +0 -20
- package/dist/golden-evaluations-BN9u2wxw.mjs +0 -1483
- package/dist/i18n-CAlj1ADU.mjs +0 -40
- package/dist/index.d.mts +0 -1099
- package/dist/index.mjs +0 -9
- package/dist/init-Bd_k06bR.mjs +0 -1233
- package/dist/mcp-B_yXL5G5.mjs +0 -137
- package/dist/mcp.d.mts +0 -287
- package/dist/mcp.mjs +0 -4135
- package/dist/metadata-BDuewuzq.mjs +0 -237
- package/dist/package-version-qik_4J6C.mjs +0 -128
- package/dist/reading-time-BkEft6SD.mjs +0 -741
- package/dist/review-NC-sOdXn.mjs +0 -665
- package/dist/robots-DskPvGPw.mjs +0 -178
- package/dist/robots-ltltiLJF.mjs +0 -197
- package/dist/search-C1JitPwi.d.mts +0 -397
- package/dist/search-D57JXQLj.mjs +0 -1758
- package/dist/search-o4Ud6OXv.mjs +0 -102
- package/dist/server.d.mts +0 -341
- package/dist/server.mjs +0 -11
- package/dist/sitemap-Cq-Yj_iA.mjs +0 -247
- package/dist/sitemap-server-C1ibVKOy.mjs +0 -1137
- package/dist/templates-DNw15P-x.mjs +0 -2373
- package/dist/types-XHABMh_f.d.mts +0 -3248
- package/dist/upgrade-BCJTCW3O.mjs +0 -56
- package/dist/utils-6UCLxv4B.mjs +0 -225
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { F as DocsAnalyticsConfig, I as DocsAnalyticsEvent, L as DocsAnalyticsEventInput } from "./types-XHABMh_f.mjs";
|
|
2
|
-
import { n as DocsCloudAskAIResponseOptions, t as DocsCloudAskAIConfig } from "./cloud-ask-ai-B2WnG4fF.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/docs-cloud-server.d.ts
|
|
5
|
-
type DocsCloudRuntimeValue<T = string> = T | undefined | null | (() => T | undefined | null);
|
|
6
|
-
type DocsCloudRuntimeEnv = Record<string, string | undefined> | (() => Record<string, string | undefined>);
|
|
7
|
-
interface DocsCloudServerOptions {
|
|
8
|
-
projectId?: DocsCloudRuntimeValue;
|
|
9
|
-
apiKey?: DocsCloudRuntimeValue;
|
|
10
|
-
apiKeyEnv?: DocsCloudRuntimeValue;
|
|
11
|
-
analyticsKey?: DocsCloudRuntimeValue;
|
|
12
|
-
apiBaseUrl?: DocsCloudRuntimeValue;
|
|
13
|
-
analyticsEndpoint?: DocsCloudRuntimeValue;
|
|
14
|
-
publicBaseUrl?: DocsCloudRuntimeValue;
|
|
15
|
-
env?: DocsCloudRuntimeEnv;
|
|
16
|
-
fetch?: typeof fetch;
|
|
17
|
-
config?: DocsCloudAskAIConfig;
|
|
18
|
-
analytics?: boolean | DocsAnalyticsConfig;
|
|
19
|
-
metadata?: Record<string, unknown>;
|
|
20
|
-
}
|
|
21
|
-
interface DocsCloudTrackEventOptions {
|
|
22
|
-
request?: Request;
|
|
23
|
-
locale?: string;
|
|
24
|
-
source?: DocsAnalyticsEvent["source"];
|
|
25
|
-
input?: DocsAnalyticsEventInput["input"];
|
|
26
|
-
metadata?: Record<string, unknown>;
|
|
27
|
-
properties?: Record<string, unknown>;
|
|
28
|
-
}
|
|
29
|
-
interface DocsCloudAskAIOptions extends Omit<DocsCloudAskAIResponseOptions, "config" | "env" | "fetch" | "publicBaseUrl"> {
|
|
30
|
-
config?: DocsCloudAskAIConfig;
|
|
31
|
-
env?: Record<string, string | undefined>;
|
|
32
|
-
fetch?: typeof fetch;
|
|
33
|
-
publicBaseUrl?: string;
|
|
34
|
-
}
|
|
35
|
-
interface DocsCloudRouteHandlerOptions {
|
|
36
|
-
locale?: string | ((request: Request) => string | undefined | Promise<string | undefined>);
|
|
37
|
-
publicBaseUrl?: string | ((request: Request) => string | undefined | Promise<string | undefined>);
|
|
38
|
-
}
|
|
39
|
-
interface DocsCloudPublicConfig {
|
|
40
|
-
ok: true;
|
|
41
|
-
configured: {
|
|
42
|
-
projectId: boolean;
|
|
43
|
-
apiKey: boolean;
|
|
44
|
-
};
|
|
45
|
-
projectId?: string;
|
|
46
|
-
apiBaseUrl: string;
|
|
47
|
-
features: {
|
|
48
|
-
analytics: boolean;
|
|
49
|
-
askAI: boolean;
|
|
50
|
-
};
|
|
51
|
-
metadata?: Record<string, unknown>;
|
|
52
|
-
}
|
|
53
|
-
interface DocsCloudAnalyticsServer {
|
|
54
|
-
track(event: DocsAnalyticsEventInput, options?: DocsCloudTrackEventOptions): Promise<boolean>;
|
|
55
|
-
}
|
|
56
|
-
interface DocsCloudServer {
|
|
57
|
-
analytics: DocsCloudAnalyticsServer;
|
|
58
|
-
trackEvent(event: DocsAnalyticsEventInput, options?: DocsCloudTrackEventOptions): Promise<boolean>;
|
|
59
|
-
askAI(request: Request, options?: DocsCloudAskAIOptions): Promise<Response>;
|
|
60
|
-
handleRequest(request: Request, options?: DocsCloudRouteHandlerOptions): Promise<Response>;
|
|
61
|
-
getPublicConfig(): DocsCloudPublicConfig;
|
|
62
|
-
}
|
|
63
|
-
interface DocsCloudRouteHandlers {
|
|
64
|
-
GET(request: Request): Promise<Response>;
|
|
65
|
-
POST(request: Request): Promise<Response>;
|
|
66
|
-
}
|
|
67
|
-
declare function createDocsCloudServer(options?: DocsCloudServerOptions): DocsCloudServer;
|
|
68
|
-
declare function createDocsCloudRouteHandler(docsCloud: DocsCloudServer, options?: DocsCloudRouteHandlerOptions): DocsCloudRouteHandlers;
|
|
69
|
-
//#endregion
|
|
70
|
-
export { DocsCloudAnalyticsServer, DocsCloudAskAIOptions, DocsCloudPublicConfig, DocsCloudRouteHandlerOptions, DocsCloudRouteHandlers, DocsCloudRuntimeEnv, DocsCloudRuntimeValue, DocsCloudServer, DocsCloudServerOptions, DocsCloudTrackEventOptions, createDocsCloudRouteHandler, createDocsCloudServer };
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import { n as sendDocsCloudAnalyticsEvent } from "./cloud-analytics-CSyFE6SS.mjs";
|
|
2
|
-
import { t as createDocsCloudAskAIResponse } from "./cloud-ask-ai-hnJfj8-X.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/docs-cloud-server.ts
|
|
5
|
-
const DEFAULT_DOCS_CLOUD_API_BASE_URL = "https://api.farming-labs.dev";
|
|
6
|
-
const DEFAULT_DOCS_CLOUD_API_KEY_ENV = "DOCS_CLOUD_API_KEY";
|
|
7
|
-
const DOCS_CLOUD_PROJECT_ID_ENVS = [
|
|
8
|
-
"DOCS_CLOUD_PROJECT_ID",
|
|
9
|
-
"PUBLIC_DOCS_CLOUD_PROJECT_ID",
|
|
10
|
-
"NEXT_PUBLIC_DOCS_CLOUD_PROJECT_ID"
|
|
11
|
-
];
|
|
12
|
-
const DOCS_CLOUD_API_BASE_URL_ENVS = [
|
|
13
|
-
"DOCS_CLOUD_API_BASE_URL",
|
|
14
|
-
"DOCS_CLOUD_API_URL",
|
|
15
|
-
"PUBLIC_DOCS_CLOUD_URL",
|
|
16
|
-
"NEXT_PUBLIC_DOCS_CLOUD_URL"
|
|
17
|
-
];
|
|
18
|
-
const DOCS_CLOUD_ANALYTICS_KEY_ENVS = [
|
|
19
|
-
"DOCS_CLOUD_ANALYTICS_KEY",
|
|
20
|
-
"PUBLIC_DOCS_CLOUD_ANALYTICS_KEY",
|
|
21
|
-
"NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_KEY"
|
|
22
|
-
];
|
|
23
|
-
const DOCS_CLOUD_ANALYTICS_ENDPOINT_ENVS = [
|
|
24
|
-
"DOCS_CLOUD_ANALYTICS_ENDPOINT",
|
|
25
|
-
"PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT",
|
|
26
|
-
"NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT"
|
|
27
|
-
];
|
|
28
|
-
function isPlainObject(value) {
|
|
29
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30
|
-
}
|
|
31
|
-
function asString(value) {
|
|
32
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
33
|
-
}
|
|
34
|
-
function normalizeRuntimeString(value) {
|
|
35
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
36
|
-
}
|
|
37
|
-
function resolveRuntimeValue(value) {
|
|
38
|
-
return (typeof value === "function" ? value() : value) ?? void 0;
|
|
39
|
-
}
|
|
40
|
-
function resolveRuntimeString(value) {
|
|
41
|
-
return normalizeRuntimeString(resolveRuntimeValue(value));
|
|
42
|
-
}
|
|
43
|
-
function readProcessEnv(name) {
|
|
44
|
-
if (typeof process === "undefined") return void 0;
|
|
45
|
-
return normalizeRuntimeString(process.env?.[name]);
|
|
46
|
-
}
|
|
47
|
-
function resolveRuntimeEnv(env) {
|
|
48
|
-
return typeof env === "function" ? env() : env ?? {};
|
|
49
|
-
}
|
|
50
|
-
function readEnv(name, env) {
|
|
51
|
-
return normalizeRuntimeString(env[name]) ?? readProcessEnv(name);
|
|
52
|
-
}
|
|
53
|
-
function readFirstEnv(names, env) {
|
|
54
|
-
for (const name of names) {
|
|
55
|
-
const value = readEnv(name, env);
|
|
56
|
-
if (value) return value;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function stripTrailingSlash(value) {
|
|
60
|
-
return value.replace(/\/+$/, "");
|
|
61
|
-
}
|
|
62
|
-
function jsonResponse(data, init) {
|
|
63
|
-
const headers = new Headers(init?.headers);
|
|
64
|
-
headers.set("Cache-Control", "no-store");
|
|
65
|
-
headers.set("Content-Type", "application/json");
|
|
66
|
-
return Response.json(data, {
|
|
67
|
-
...init,
|
|
68
|
-
headers
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
function requestProperties(request) {
|
|
72
|
-
const userAgent = request?.headers.get("user-agent")?.trim();
|
|
73
|
-
return userAgent ? { userAgent } : {};
|
|
74
|
-
}
|
|
75
|
-
function mergeRecords(...records) {
|
|
76
|
-
const merged = {};
|
|
77
|
-
for (const record of records) {
|
|
78
|
-
if (!record) continue;
|
|
79
|
-
Object.assign(merged, record);
|
|
80
|
-
}
|
|
81
|
-
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
82
|
-
}
|
|
83
|
-
function omitAction(record) {
|
|
84
|
-
const { action: _action, ...rest } = record;
|
|
85
|
-
return rest;
|
|
86
|
-
}
|
|
87
|
-
function isAskAIBody(body) {
|
|
88
|
-
if (!isPlainObject(body)) return false;
|
|
89
|
-
return Array.isArray(body.messages) || typeof body.question === "string";
|
|
90
|
-
}
|
|
91
|
-
function resolveRouteAction(request, body) {
|
|
92
|
-
const queryAction = asString(new URL(request.url).searchParams.get("action"));
|
|
93
|
-
const bodyAction = isPlainObject(body) ? asString(body.action) : void 0;
|
|
94
|
-
const action = (queryAction ?? bodyAction)?.toLowerCase().replace(/_/g, "-");
|
|
95
|
-
if (action === "ask-ai" || action === "ai" || action === "chat") return "ask-ai";
|
|
96
|
-
if (isAskAIBody(body)) return "ask-ai";
|
|
97
|
-
return "analytics";
|
|
98
|
-
}
|
|
99
|
-
function resolveAnalyticsEvent(body) {
|
|
100
|
-
if (!isPlainObject(body)) return void 0;
|
|
101
|
-
const eventCandidate = isPlainObject(body.event) ? body.event : isPlainObject(body.payload) ? body.payload : body;
|
|
102
|
-
const eventRecord = eventCandidate === body && typeof body.action === "string" ? omitAction(body) : eventCandidate;
|
|
103
|
-
return typeof eventRecord.type === "string" ? eventRecord : void 0;
|
|
104
|
-
}
|
|
105
|
-
function askAIPayload(body) {
|
|
106
|
-
if (!isPlainObject(body)) return body;
|
|
107
|
-
return isPlainObject(body.payload) ? body.payload : omitAction(body);
|
|
108
|
-
}
|
|
109
|
-
function createJsonRequest(request, body) {
|
|
110
|
-
const headers = new Headers(request.headers);
|
|
111
|
-
headers.set("Content-Type", "application/json");
|
|
112
|
-
return new Request(request.url, {
|
|
113
|
-
method: request.method,
|
|
114
|
-
headers,
|
|
115
|
-
body: JSON.stringify(body),
|
|
116
|
-
signal: request.signal
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
async function readJson(request) {
|
|
120
|
-
try {
|
|
121
|
-
return await request.clone().json();
|
|
122
|
-
} catch {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
async function resolveRouteValue(value, request) {
|
|
127
|
-
if (typeof value === "function") return normalizeRuntimeString(await value(request));
|
|
128
|
-
return normalizeRuntimeString(value);
|
|
129
|
-
}
|
|
130
|
-
function createDocsCloudServer(options = {}) {
|
|
131
|
-
function env() {
|
|
132
|
-
return resolveRuntimeEnv(options.env);
|
|
133
|
-
}
|
|
134
|
-
function apiKeyEnv() {
|
|
135
|
-
return resolveRuntimeString(options.apiKeyEnv) ?? options.config?.cloud?.apiKey?.env?.trim() ?? DEFAULT_DOCS_CLOUD_API_KEY_ENV;
|
|
136
|
-
}
|
|
137
|
-
function projectId() {
|
|
138
|
-
const runtimeEnv = env();
|
|
139
|
-
return resolveRuntimeString(options.projectId) ?? readFirstEnv(DOCS_CLOUD_PROJECT_ID_ENVS, runtimeEnv);
|
|
140
|
-
}
|
|
141
|
-
function apiKey() {
|
|
142
|
-
const runtimeEnv = env();
|
|
143
|
-
const keyEnv = apiKeyEnv();
|
|
144
|
-
return resolveRuntimeString(options.apiKey) ?? readEnv(keyEnv, runtimeEnv);
|
|
145
|
-
}
|
|
146
|
-
function analyticsKey() {
|
|
147
|
-
const runtimeEnv = env();
|
|
148
|
-
return resolveRuntimeString(options.analyticsKey) ?? apiKey() ?? readFirstEnv(DOCS_CLOUD_ANALYTICS_KEY_ENVS, runtimeEnv);
|
|
149
|
-
}
|
|
150
|
-
function apiBaseUrl() {
|
|
151
|
-
const runtimeEnv = env();
|
|
152
|
-
return stripTrailingSlash(resolveRuntimeString(options.apiBaseUrl) ?? readFirstEnv(DOCS_CLOUD_API_BASE_URL_ENVS, runtimeEnv) ?? DEFAULT_DOCS_CLOUD_API_BASE_URL);
|
|
153
|
-
}
|
|
154
|
-
function analyticsEndpoint() {
|
|
155
|
-
const runtimeEnv = env();
|
|
156
|
-
return resolveRuntimeString(options.analyticsEndpoint) ?? readFirstEnv(DOCS_CLOUD_ANALYTICS_ENDPOINT_ENVS, runtimeEnv) ?? `${apiBaseUrl()}/v1/analytics/events`;
|
|
157
|
-
}
|
|
158
|
-
function publicBaseUrl() {
|
|
159
|
-
return resolveRuntimeString(options.publicBaseUrl);
|
|
160
|
-
}
|
|
161
|
-
function askAIEnv(overrides) {
|
|
162
|
-
const key = apiKey();
|
|
163
|
-
const keyEnv = apiKeyEnv();
|
|
164
|
-
const id = projectId();
|
|
165
|
-
return {
|
|
166
|
-
...env(),
|
|
167
|
-
...overrides,
|
|
168
|
-
DOCS_CLOUD_API_BASE_URL: apiBaseUrl(),
|
|
169
|
-
...id ? {
|
|
170
|
-
DOCS_CLOUD_PROJECT_ID: id,
|
|
171
|
-
PUBLIC_DOCS_CLOUD_PROJECT_ID: id
|
|
172
|
-
} : {},
|
|
173
|
-
...key ? {
|
|
174
|
-
[keyEnv]: key,
|
|
175
|
-
DOCS_CLOUD_API_KEY: key
|
|
176
|
-
} : {}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
async function trackEvent(event, trackOptions = {}) {
|
|
180
|
-
const id = projectId();
|
|
181
|
-
if (!id) return false;
|
|
182
|
-
const requestUrl = trackOptions.request ? new URL(trackOptions.request.url) : void 0;
|
|
183
|
-
const normalized = {
|
|
184
|
-
...event,
|
|
185
|
-
timestamp: event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
186
|
-
source: event.source ?? trackOptions.source ?? "server",
|
|
187
|
-
url: event.url ?? trackOptions.request?.url,
|
|
188
|
-
path: event.path ?? requestUrl?.pathname,
|
|
189
|
-
locale: event.locale ?? trackOptions.locale,
|
|
190
|
-
input: event.input ?? trackOptions.input,
|
|
191
|
-
metadata: mergeRecords(options.metadata, trackOptions.metadata, event.metadata),
|
|
192
|
-
properties: mergeRecords(requestProperties(trackOptions.request), trackOptions.properties, event.properties)
|
|
193
|
-
};
|
|
194
|
-
await sendDocsCloudAnalyticsEvent({
|
|
195
|
-
endpoint: analyticsEndpoint(),
|
|
196
|
-
projectId: id,
|
|
197
|
-
apiKey: analyticsKey(),
|
|
198
|
-
fetch: options.fetch
|
|
199
|
-
}, normalized);
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
function analyticsConfig(analytics) {
|
|
203
|
-
const selectedAnalytics = analytics ?? options.analytics;
|
|
204
|
-
if (selectedAnalytics === false) return false;
|
|
205
|
-
const userConfig = typeof selectedAnalytics === "object" ? selectedAnalytics : {};
|
|
206
|
-
const userOnEvent = userConfig.onEvent;
|
|
207
|
-
return {
|
|
208
|
-
...userConfig,
|
|
209
|
-
cloud: false,
|
|
210
|
-
console: userConfig.console ?? false,
|
|
211
|
-
onEvent: async (event) => {
|
|
212
|
-
let userError;
|
|
213
|
-
if (userOnEvent) try {
|
|
214
|
-
await userOnEvent(event);
|
|
215
|
-
} catch (error) {
|
|
216
|
-
userError = error;
|
|
217
|
-
}
|
|
218
|
-
await trackEvent(event);
|
|
219
|
-
if (typeof userError !== "undefined") throw userError;
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
async function askAI(request, askOptions = {}) {
|
|
224
|
-
const config = {
|
|
225
|
-
...options.config,
|
|
226
|
-
...askOptions.config,
|
|
227
|
-
ai: {
|
|
228
|
-
enabled: true,
|
|
229
|
-
provider: "docs-cloud",
|
|
230
|
-
...options.config?.ai,
|
|
231
|
-
...askOptions.config?.ai
|
|
232
|
-
},
|
|
233
|
-
cloud: {
|
|
234
|
-
...options.config?.cloud,
|
|
235
|
-
...askOptions.config?.cloud,
|
|
236
|
-
apiKey: {
|
|
237
|
-
...options.config?.cloud?.apiKey,
|
|
238
|
-
...askOptions.config?.cloud?.apiKey,
|
|
239
|
-
env: apiKeyEnv()
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
analytics: analyticsConfig(askOptions.config?.analytics ?? options.config?.analytics)
|
|
243
|
-
};
|
|
244
|
-
return createDocsCloudAskAIResponse(request, {
|
|
245
|
-
...askOptions,
|
|
246
|
-
config,
|
|
247
|
-
env: askAIEnv(askOptions.env),
|
|
248
|
-
fetch: askOptions.fetch ?? options.fetch,
|
|
249
|
-
publicBaseUrl: askOptions.publicBaseUrl ?? publicBaseUrl()
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
function getPublicConfig() {
|
|
253
|
-
const id = projectId();
|
|
254
|
-
const key = apiKey();
|
|
255
|
-
return {
|
|
256
|
-
ok: true,
|
|
257
|
-
configured: {
|
|
258
|
-
projectId: Boolean(id),
|
|
259
|
-
apiKey: Boolean(key)
|
|
260
|
-
},
|
|
261
|
-
...id ? { projectId: id } : {},
|
|
262
|
-
apiBaseUrl: apiBaseUrl(),
|
|
263
|
-
features: {
|
|
264
|
-
analytics: options.analytics !== false,
|
|
265
|
-
askAI: options.config?.ai?.enabled !== false
|
|
266
|
-
},
|
|
267
|
-
...options.metadata ? { metadata: options.metadata } : {}
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
async function handleRequest(request, routeOptions = {}) {
|
|
271
|
-
if (request.method === "GET") return jsonResponse(getPublicConfig());
|
|
272
|
-
if (request.method !== "POST") return jsonResponse({ error: "Method not allowed." }, { status: 405 });
|
|
273
|
-
const body = await readJson(request);
|
|
274
|
-
if (resolveRouteAction(request, body) === "ask-ai") {
|
|
275
|
-
const locale = await resolveRouteValue(routeOptions.locale, request);
|
|
276
|
-
const routePublicBaseUrl = await resolveRouteValue(routeOptions.publicBaseUrl, request);
|
|
277
|
-
return askAI(isPlainObject(body) && typeof body.action === "string" ? createJsonRequest(request, askAIPayload(body)) : request, {
|
|
278
|
-
locale,
|
|
279
|
-
publicBaseUrl: routePublicBaseUrl
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
const event = resolveAnalyticsEvent(body);
|
|
283
|
-
if (!event) return jsonResponse({ error: "Invalid analytics event. Expected an object with a string type." }, { status: 400 });
|
|
284
|
-
if (!await trackEvent(event, { request })) return jsonResponse({ error: "Docs Cloud project id is not configured." }, { status: 500 });
|
|
285
|
-
return jsonResponse({
|
|
286
|
-
ok: true,
|
|
287
|
-
type: "analytics"
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
return {
|
|
291
|
-
analytics: { track: trackEvent },
|
|
292
|
-
trackEvent,
|
|
293
|
-
askAI,
|
|
294
|
-
handleRequest,
|
|
295
|
-
getPublicConfig
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
function createDocsCloudRouteHandler(docsCloud, options = {}) {
|
|
299
|
-
return {
|
|
300
|
-
GET(request) {
|
|
301
|
-
return docsCloud.handleRequest(request, options);
|
|
302
|
-
},
|
|
303
|
-
POST(request) {
|
|
304
|
-
return docsCloud.handleRequest(request, options);
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
//#endregion
|
|
310
|
-
export { createDocsCloudRouteHandler, createDocsCloudServer };
|