UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

63 lines • 3.04 kB
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= import { z } from 'zod'; import { timeoutShape } from "../../core/api/config.js"; import { DEFAULT_TIMEOUT } from "../../core/api/constants.js"; import { rstripSlash } from "../../utils/slash.js"; import { normalizeNonEmpty, REDACTED_SECRET, secretStr } from "../secrets.js"; export const DifyConfig = z.object({ apiKey: secretStr().describe('Dify Knowledge API key, sent as `Authorization: Bearer`.'), baseUrl: z.string().describe('Dify API root, such as `https://api.dify.ai/v1`.'), datasetId: z.string().describe('ID of the Knowledge dataset the mount shows.'), slugMetadataName: z.string().optional().meta({ description: "Document metadata field whose value is the document's path in the mount. A document without it is mounted under its document name.", default: 'slug', }), maxConcurrency: z.number().optional().meta({ description: 'The most Dify API requests in flight at once.', default: 10, }), retryAttempts: z.number().optional().meta({ description: 'Attempts per request, the first included. A 429, a 5xx or a transport error is retried.', default: 4, }), retryMaxDelay: z.number().optional().meta({ description: 'Longest wait in seconds before a retry, whether from backoff or `Retry-After`.', default: 30, }), ...timeoutShape, }); function normalizePositive(value, fallback, field) { const resolved = value ?? fallback; if (!(resolved > 0)) { throw new Error(`${field} must be positive`); } return resolved; } export function resolveDifyConfig(config) { return { apiKey: config.apiKey, baseUrl: rstripSlash(config.baseUrl), datasetId: normalizeNonEmpty(config.datasetId, 'datasetId'), slugMetadataName: normalizeNonEmpty(config.slugMetadataName ?? 'slug', 'slugMetadataName'), maxConcurrency: normalizePositive(config.maxConcurrency, 10, 'maxConcurrency'), timeout: normalizePositive(config.timeout, DEFAULT_TIMEOUT, 'timeout'), retryAttempts: normalizePositive(config.retryAttempts, 4, 'retryAttempts'), retryMaxDelay: normalizePositive(config.retryMaxDelay, 30, 'retryMaxDelay'), }; } export function redactDifyConfig(config) { return { ...config, apiKey: REDACTED_SECRET }; } //# sourceMappingURL=config.js.map