veryfront 0.1.216 → 0.1.218
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/esm/cli/commands/generate/integration-generator-helpers.d.ts +35 -0
- package/esm/cli/commands/generate/integration-generator-helpers.d.ts.map +1 -0
- package/esm/cli/commands/generate/integration-generator-helpers.js +123 -0
- package/esm/cli/commands/generate/integration-generator.d.ts +1 -2
- package/esm/cli/commands/generate/integration-generator.d.ts.map +1 -1
- package/esm/cli/commands/generate/integration-generator.js +1 -123
- package/esm/cli/commands/knowledge/command-helpers.d.ts +48 -0
- package/esm/cli/commands/knowledge/command-helpers.d.ts.map +1 -0
- package/esm/cli/commands/knowledge/command-helpers.js +216 -0
- package/esm/cli/commands/knowledge/command.d.ts +11 -16
- package/esm/cli/commands/knowledge/command.d.ts.map +1 -1
- package/esm/cli/commands/knowledge/command.js +25 -212
- package/esm/cli/mcp/remote-file-tool-helpers.d.ts +5 -0
- package/esm/cli/mcp/remote-file-tool-helpers.d.ts.map +1 -0
- package/esm/cli/mcp/remote-file-tool-helpers.js +22 -0
- package/esm/cli/mcp/remote-file-tools.d.ts.map +1 -1
- package/esm/cli/mcp/remote-file-tools.js +1 -22
- package/esm/cli/templates/integration-loader-helpers.d.ts +8 -0
- package/esm/cli/templates/integration-loader-helpers.d.ts.map +1 -0
- package/esm/cli/templates/integration-loader-helpers.js +29 -0
- package/esm/cli/templates/integration-loader.d.ts.map +1 -1
- package/esm/cli/templates/integration-loader.js +5 -21
- package/esm/cli/templates/manifest.d.ts +1 -0
- package/esm/cli/templates/manifest.js +2 -1
- package/esm/deno.d.ts +1 -2
- package/esm/deno.js +7 -5
- package/esm/src/agent/runtime/index.d.ts.map +1 -1
- package/esm/src/agent/runtime/index.js +48 -90
- package/esm/src/chat/ag-ui-helpers.d.ts +17 -0
- package/esm/src/chat/ag-ui-helpers.d.ts.map +1 -0
- package/esm/src/chat/ag-ui-helpers.js +111 -0
- package/esm/src/chat/ag-ui.d.ts.map +1 -1
- package/esm/src/chat/ag-ui.js +1 -111
- package/esm/src/config/schemas/config.schema.d.ts +1 -0
- package/esm/src/config/schemas/config.schema.d.ts.map +1 -1
- package/esm/src/config/schemas/config.schema.js +11 -0
- package/esm/src/config/schemas/index.d.ts +11 -1
- package/esm/src/config/schemas/index.d.ts.map +1 -1
- package/esm/src/errors/error-registry-helpers.d.ts +6 -0
- package/esm/src/errors/error-registry-helpers.d.ts.map +1 -0
- package/esm/src/errors/error-registry-helpers.js +9 -0
- package/esm/src/errors/error-registry.d.ts.map +1 -1
- package/esm/src/errors/error-registry.js +4 -3
- package/esm/src/extensions/factory-loader.d.ts +29 -0
- package/esm/src/extensions/factory-loader.d.ts.map +1 -0
- package/esm/src/extensions/factory-loader.js +63 -0
- package/esm/src/extensions/index.d.ts +16 -0
- package/esm/src/extensions/index.d.ts.map +1 -1
- package/esm/src/extensions/index.js +16 -0
- package/esm/src/extensions/interfaces/auth-provider.d.ts +30 -3
- package/esm/src/extensions/interfaces/auth-provider.d.ts.map +1 -1
- package/esm/src/extensions/interfaces/index.d.ts +2 -1
- package/esm/src/extensions/interfaces/index.d.ts.map +1 -1
- package/esm/src/extensions/interfaces/token-cache-store.d.ts +56 -0
- package/esm/src/extensions/interfaces/token-cache-store.d.ts.map +1 -0
- package/esm/src/extensions/interfaces/token-cache-store.js +12 -0
- package/esm/src/extensions/orchestrate.d.ts +54 -0
- package/esm/src/extensions/orchestrate.d.ts.map +1 -0
- package/esm/src/extensions/orchestrate.js +116 -0
- package/esm/src/extensions/recommendations.d.ts.map +1 -1
- package/esm/src/extensions/recommendations.js +1 -0
- package/esm/src/html/styles-builder/plugin-loader.d.ts.map +1 -1
- package/esm/src/html/styles-builder/plugin-loader.js +23 -0
- package/esm/src/html/styles-builder/tailwind-plugin-allowlist.d.ts +29 -0
- package/esm/src/html/styles-builder/tailwind-plugin-allowlist.d.ts.map +1 -0
- package/esm/src/html/styles-builder/tailwind-plugin-allowlist.js +48 -0
- package/esm/src/modules/react-loader/ssr-module-loader/loader-helpers.d.ts +15 -0
- package/esm/src/modules/react-loader/ssr-module-loader/loader-helpers.d.ts.map +1 -0
- package/esm/src/modules/react-loader/ssr-module-loader/loader-helpers.js +22 -0
- package/esm/src/modules/react-loader/ssr-module-loader/loader.d.ts +0 -2
- package/esm/src/modules/react-loader/ssr-module-loader/loader.d.ts.map +1 -1
- package/esm/src/modules/react-loader/ssr-module-loader/loader.js +4 -24
- package/esm/src/platform/adapters/fs/veryfront/adapter-helpers.d.ts +19 -0
- package/esm/src/platform/adapters/fs/veryfront/adapter-helpers.d.ts.map +1 -0
- package/esm/src/platform/adapters/fs/veryfront/adapter-helpers.js +26 -0
- package/esm/src/platform/adapters/fs/veryfront/adapter.d.ts.map +1 -1
- package/esm/src/platform/adapters/fs/veryfront/adapter.js +4 -20
- package/esm/src/platform/adapters/fs/veryfront/read-operations-helpers.d.ts +1 -0
- package/esm/src/platform/adapters/fs/veryfront/read-operations-helpers.d.ts.map +1 -1
- package/esm/src/platform/adapters/fs/veryfront/read-operations-helpers.js +3 -0
- package/esm/src/platform/adapters/fs/veryfront/read-operations.d.ts.map +1 -1
- package/esm/src/platform/adapters/fs/veryfront/read-operations.js +4 -7
- package/esm/src/platform/adapters/fs/veryfront/websocket-manager-helpers.d.ts +28 -0
- package/esm/src/platform/adapters/fs/veryfront/websocket-manager-helpers.d.ts.map +1 -0
- package/esm/src/platform/adapters/fs/veryfront/websocket-manager-helpers.js +41 -0
- package/esm/src/platform/adapters/fs/veryfront/websocket-manager.d.ts +1 -4
- package/esm/src/platform/adapters/fs/veryfront/websocket-manager.d.ts.map +1 -1
- package/esm/src/platform/adapters/fs/veryfront/websocket-manager.js +7 -40
- package/esm/src/provider/runtime-loader/tool-input-status.d.ts +17 -0
- package/esm/src/provider/runtime-loader/tool-input-status.d.ts.map +1 -0
- package/esm/src/provider/runtime-loader/tool-input-status.js +155 -0
- package/esm/src/provider/runtime-loader.d.ts +2 -3
- package/esm/src/provider/runtime-loader.d.ts.map +1 -1
- package/esm/src/provider/runtime-loader.js +2 -155
- package/esm/src/proxy/cache/index.d.ts +1 -1
- package/esm/src/proxy/cache/index.d.ts.map +1 -1
- package/esm/src/proxy/cache/index.js +25 -15
- package/esm/src/proxy/cache/tracing-cache.d.ts +31 -0
- package/esm/src/proxy/cache/tracing-cache.d.ts.map +1 -0
- package/esm/src/proxy/cache/tracing-cache.js +44 -0
- package/esm/src/proxy/cache/types.d.ts +1 -1
- package/esm/src/proxy/cache/types.js +1 -1
- package/esm/src/proxy/handler.d.ts +7 -0
- package/esm/src/proxy/handler.d.ts.map +1 -1
- package/esm/src/proxy/handler.js +50 -29
- package/esm/src/rendering/orchestrator/pipeline-helpers.d.ts +8 -0
- package/esm/src/rendering/orchestrator/pipeline-helpers.d.ts.map +1 -0
- package/esm/src/rendering/orchestrator/pipeline-helpers.js +20 -0
- package/esm/src/rendering/orchestrator/pipeline.d.ts +0 -3
- package/esm/src/rendering/orchestrator/pipeline.d.ts.map +1 -1
- package/esm/src/rendering/orchestrator/pipeline.js +4 -22
- package/esm/src/routing/api/module-loader/loader-helpers.d.ts +10 -0
- package/esm/src/routing/api/module-loader/loader-helpers.d.ts.map +1 -0
- package/esm/src/routing/api/module-loader/loader-helpers.js +62 -0
- package/esm/src/routing/api/module-loader/loader.d.ts +1 -1
- package/esm/src/routing/api/module-loader/loader.d.ts.map +1 -1
- package/esm/src/routing/api/module-loader/loader.js +2 -60
- package/esm/src/server/bootstrap.d.ts +22 -2
- package/esm/src/server/bootstrap.d.ts.map +1 -1
- package/esm/src/server/bootstrap.js +67 -5
- package/esm/src/server/dev-ui/manifest.d.ts +2 -0
- package/esm/src/server/dev-ui/manifest.js +3 -1
- package/esm/src/server/handlers/request/api/project-discovery.d.ts.map +1 -1
- package/esm/src/server/handlers/request/api/project-discovery.js +14 -8
- package/esm/src/server/production-server.js +1 -1
- package/esm/src/server/services/rsc/endpoints/rsc-bundles.generated.d.ts.map +1 -1
- package/esm/src/server/services/rsc/endpoints/rsc-bundles.generated.js +2 -2
- package/esm/src/studio/bridge/bridge-bundle.generated.d.ts.map +1 -1
- package/esm/src/studio/bridge/bridge-bundle.generated.js +1 -1
- package/esm/src/tool/index.d.ts +1 -1
- package/esm/src/tool/index.d.ts.map +1 -1
- package/esm/src/tool/types.d.ts +20 -0
- package/esm/src/tool/types.d.ts.map +1 -1
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +66 -35
- package/src/cli/commands/generate/integration-generator-helpers.ts +185 -0
- package/src/cli/commands/generate/integration-generator.ts +12 -168
- package/src/cli/commands/knowledge/command-helpers.ts +295 -0
- package/src/cli/commands/knowledge/command.ts +33 -259
- package/src/cli/mcp/remote-file-tool-helpers.ts +27 -0
- package/src/cli/mcp/remote-file-tools.ts +6 -28
- package/src/cli/templates/integration-loader-helpers.ts +49 -0
- package/src/cli/templates/integration-loader.ts +10 -28
- package/src/cli/templates/manifest.js +2 -1
- package/src/deno.js +7 -5
- package/src/src/agent/runtime/index.ts +77 -94
- package/src/src/chat/ag-ui-helpers.ts +139 -0
- package/src/src/chat/ag-ui.ts +11 -139
- package/src/src/config/schemas/config.schema.ts +11 -0
- package/src/src/config/schemas/index.ts +15 -1
- package/src/src/errors/error-registry-helpers.ts +23 -0
- package/src/src/errors/error-registry.ts +8 -3
- package/src/src/extensions/factory-loader.ts +76 -0
- package/src/src/extensions/index.ts +20 -0
- package/src/src/extensions/interfaces/auth-provider.ts +35 -3
- package/src/src/extensions/interfaces/index.ts +10 -1
- package/src/src/extensions/interfaces/token-cache-store.ts +58 -0
- package/src/src/extensions/orchestrate.ts +184 -0
- package/src/src/extensions/recommendations.ts +1 -0
- package/src/src/html/styles-builder/plugin-loader.ts +32 -0
- package/src/src/html/styles-builder/tailwind-plugin-allowlist.ts +51 -0
- package/src/src/modules/react-loader/ssr-module-loader/loader-helpers.ts +37 -0
- package/src/src/modules/react-loader/ssr-module-loader/loader.ts +8 -39
- package/src/src/platform/adapters/fs/veryfront/adapter-helpers.ts +43 -0
- package/src/src/platform/adapters/fs/veryfront/adapter.ts +8 -22
- package/src/src/platform/adapters/fs/veryfront/read-operations-helpers.ts +4 -0
- package/src/src/platform/adapters/fs/veryfront/read-operations.ts +4 -7
- package/src/src/platform/adapters/fs/veryfront/websocket-manager-helpers.ts +73 -0
- package/src/src/platform/adapters/fs/veryfront/websocket-manager.ts +29 -44
- package/src/src/provider/runtime-loader/tool-input-status.ts +210 -0
- package/src/src/provider/runtime-loader.ts +6 -203
- package/src/src/proxy/cache/index.ts +27 -15
- package/src/src/proxy/cache/tracing-cache.ts +77 -0
- package/src/src/proxy/cache/types.ts +1 -1
- package/src/src/proxy/handler.ts +57 -31
- package/src/src/rendering/orchestrator/pipeline-helpers.ts +35 -0
- package/src/src/rendering/orchestrator/pipeline.ts +8 -35
- package/src/src/routing/api/module-loader/loader-helpers.ts +68 -0
- package/src/src/routing/api/module-loader/loader.ts +8 -65
- package/src/src/server/bootstrap.ts +88 -7
- package/src/src/server/dev-ui/manifest.js +3 -1
- package/src/src/server/handlers/request/api/project-discovery.ts +19 -8
- package/src/src/server/production-server.ts +1 -1
- package/src/src/server/services/rsc/endpoints/rsc-bundles.generated.ts +2 -2
- package/src/src/studio/bridge/bridge-bundle.generated.ts +1 -1
- package/src/src/tool/index.ts +1 -0
- package/src/src/tool/types.ts +21 -0
- package/src/src/utils/version-constant.ts +1 -1
- package/esm/src/proxy/cache/redis-cache.d.ts +0 -25
- package/esm/src/proxy/cache/redis-cache.d.ts.map +0 -1
- package/esm/src/proxy/cache/redis-cache.js +0 -219
- package/src/src/proxy/cache/redis-cache.ts +0 -255
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type TokenAuthMethod = "basic" | "body" | "client_secret_basic" | "client_secret_post" | "request_body";
|
|
2
|
+
export interface IntegrationGeneratorOptionsLike {
|
|
3
|
+
name?: string;
|
|
4
|
+
displayName?: string;
|
|
5
|
+
authType?: "oauth2" | "api-key";
|
|
6
|
+
apiBaseUrl?: string;
|
|
7
|
+
authorizationUrl?: string;
|
|
8
|
+
tokenUrl?: string;
|
|
9
|
+
scopes?: string;
|
|
10
|
+
tokenAuthMethod?: TokenAuthMethod;
|
|
11
|
+
additionalAuthParams?: string;
|
|
12
|
+
usePKCE?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface IntegrationConfig {
|
|
15
|
+
name: string;
|
|
16
|
+
displayName: string;
|
|
17
|
+
authType: "oauth2" | "api-key";
|
|
18
|
+
apiBaseUrl: string;
|
|
19
|
+
authorizationUrl?: string;
|
|
20
|
+
tokenUrl?: string;
|
|
21
|
+
scopes: string[];
|
|
22
|
+
tokenAuthMethod: TokenAuthMethod;
|
|
23
|
+
additionalAuthParams: Record<string, string>;
|
|
24
|
+
usePKCE: boolean;
|
|
25
|
+
envVarPrefix: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function parseScopes(scopes?: string): string[];
|
|
28
|
+
export declare function parseAdditionalAuthParams(params?: string): Record<string, string>;
|
|
29
|
+
export declare function normalizeTokenAuthMethod(method?: string): TokenAuthMethod;
|
|
30
|
+
export declare function parseBooleanOption(value: string | boolean | undefined, defaultValue?: boolean): boolean;
|
|
31
|
+
export declare function validateIntegrationName(name: string): void;
|
|
32
|
+
export declare function getNonInteractiveConfig(options: IntegrationGeneratorOptionsLike): IntegrationConfig;
|
|
33
|
+
export declare function getToolInputSchema(toolFile: string): string;
|
|
34
|
+
export declare function getToolExecuteBody(toolFile: string): string;
|
|
35
|
+
//# sourceMappingURL=integration-generator-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration-generator-helpers.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/generate/integration-generator-helpers.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB,OAAO,GACP,MAAM,GACN,qBAAqB,GACrB,oBAAoB,GACpB,cAAc,CAAC;AAEnB,MAAM,WAAW,+BAA+B;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,eAAe,EAAE,eAAe,CAAC;IACjC,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAErD;AAED,wBAAgB,yBAAyB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA2BjF;AAED,wBAAgB,wBAAwB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe,CAmBzE;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,EACnC,YAAY,UAAQ,GACnB,OAAO,CAkBT;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAI1D;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,+BAA+B,GACvC,iBAAiB,CAwBnB;AAmCD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE3D"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export function parseScopes(scopes) {
|
|
2
|
+
return scopes?.split(",").map((scope) => scope.trim()) || [];
|
|
3
|
+
}
|
|
4
|
+
export function parseAdditionalAuthParams(params) {
|
|
5
|
+
if (!params?.trim())
|
|
6
|
+
return {};
|
|
7
|
+
return Object.fromEntries(params.split(",")
|
|
8
|
+
.map((entry) => entry.trim())
|
|
9
|
+
.filter(Boolean)
|
|
10
|
+
.map((entry) => {
|
|
11
|
+
const separatorIndex = entry.indexOf("=");
|
|
12
|
+
if (separatorIndex === -1) {
|
|
13
|
+
throw new Error("Additional auth params must use key=value pairs separated by commas");
|
|
14
|
+
}
|
|
15
|
+
const key = entry.slice(0, separatorIndex).trim();
|
|
16
|
+
const value = entry.slice(separatorIndex + 1).trim();
|
|
17
|
+
if (!key || !value) {
|
|
18
|
+
throw new Error("Additional auth params must use non-empty key=value pairs");
|
|
19
|
+
}
|
|
20
|
+
return [key, value];
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
export function normalizeTokenAuthMethod(method) {
|
|
24
|
+
switch (method?.trim().toLowerCase()) {
|
|
25
|
+
case "basic":
|
|
26
|
+
return "basic";
|
|
27
|
+
case "body":
|
|
28
|
+
return "body";
|
|
29
|
+
case "client_secret_basic":
|
|
30
|
+
return "client_secret_basic";
|
|
31
|
+
case "client_secret_post":
|
|
32
|
+
return "client_secret_post";
|
|
33
|
+
case "request_body":
|
|
34
|
+
case undefined:
|
|
35
|
+
case "":
|
|
36
|
+
return "request_body";
|
|
37
|
+
default:
|
|
38
|
+
throw new Error("OAuth token auth method must be one of: request_body, body, basic, client_secret_basic, client_secret_post");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function parseBooleanOption(value, defaultValue = false) {
|
|
42
|
+
if (typeof value === "boolean")
|
|
43
|
+
return value;
|
|
44
|
+
if (!value?.trim())
|
|
45
|
+
return defaultValue;
|
|
46
|
+
switch (value.trim().toLowerCase()) {
|
|
47
|
+
case "y":
|
|
48
|
+
case "yes":
|
|
49
|
+
case "true":
|
|
50
|
+
case "1":
|
|
51
|
+
return true;
|
|
52
|
+
case "n":
|
|
53
|
+
case "no":
|
|
54
|
+
case "false":
|
|
55
|
+
case "0":
|
|
56
|
+
return false;
|
|
57
|
+
default:
|
|
58
|
+
throw new Error("Boolean option must be yes/no, true/false, or 1/0");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function validateIntegrationName(name) {
|
|
62
|
+
if (!name || !/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
63
|
+
throw new Error("Integration name must be lowercase letters, numbers, and hyphens");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function getNonInteractiveConfig(options) {
|
|
67
|
+
const { name, displayName, authType } = options;
|
|
68
|
+
if (!name || !displayName || !authType) {
|
|
69
|
+
throw new Error("Non-interactive mode requires --name, --display-name, and --auth-type options");
|
|
70
|
+
}
|
|
71
|
+
const normalizedName = name.toLowerCase();
|
|
72
|
+
return {
|
|
73
|
+
name: normalizedName,
|
|
74
|
+
displayName,
|
|
75
|
+
authType,
|
|
76
|
+
apiBaseUrl: options.apiBaseUrl ?? `https://api.${name}.com`,
|
|
77
|
+
authorizationUrl: options.authorizationUrl,
|
|
78
|
+
tokenUrl: options.tokenUrl,
|
|
79
|
+
scopes: parseScopes(options.scopes),
|
|
80
|
+
tokenAuthMethod: normalizeTokenAuthMethod(options.tokenAuthMethod),
|
|
81
|
+
additionalAuthParams: parseAdditionalAuthParams(options.additionalAuthParams),
|
|
82
|
+
usePKCE: parseBooleanOption(options.usePKCE, false),
|
|
83
|
+
envVarPrefix: name.toUpperCase().replace(/-/g, "_"),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const TOOL_FILE_CONTENTS = {
|
|
87
|
+
"list-items.ts": {
|
|
88
|
+
inputSchema: `limit: z.number().optional().describe("Maximum number of items to return"),
|
|
89
|
+
offset: z.number().optional().describe("Number of items to skip"),`,
|
|
90
|
+
executeBody: `const items = await listItems({
|
|
91
|
+
limit: input.limit,
|
|
92
|
+
offset: input.offset,
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
success: true,
|
|
96
|
+
items,
|
|
97
|
+
count: items.length,
|
|
98
|
+
};`,
|
|
99
|
+
},
|
|
100
|
+
"get-item.ts": {
|
|
101
|
+
inputSchema: `id: z.string().describe("The ID of the item to retrieve"),`,
|
|
102
|
+
executeBody: `const item = await getItem(input.id);
|
|
103
|
+
return {
|
|
104
|
+
success: true,
|
|
105
|
+
item,
|
|
106
|
+
};`,
|
|
107
|
+
},
|
|
108
|
+
"search.ts": {
|
|
109
|
+
inputSchema: `query: z.string().describe("Search query"),`,
|
|
110
|
+
executeBody: `const results = await searchItems(input.query);
|
|
111
|
+
return {
|
|
112
|
+
success: true,
|
|
113
|
+
results,
|
|
114
|
+
count: results.length,
|
|
115
|
+
};`,
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
export function getToolInputSchema(toolFile) {
|
|
119
|
+
return TOOL_FILE_CONTENTS[toolFile]?.inputSchema ?? "";
|
|
120
|
+
}
|
|
121
|
+
export function getToolExecuteBody(toolFile) {
|
|
122
|
+
return TOOL_FILE_CONTENTS[toolFile]?.executeBody ?? "";
|
|
123
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Generates new service integration scaffolds with interactive prompts.
|
|
5
5
|
* Creates connector.json, API client, OAuth routes, token store, and tool skeletons.
|
|
6
6
|
*/
|
|
7
|
+
import { type TokenAuthMethod } from "./integration-generator-helpers.js";
|
|
7
8
|
export interface IntegrationGeneratorOptions {
|
|
8
9
|
/** Integration name (lowercase, e.g., "twilio") */
|
|
9
10
|
name?: string;
|
|
@@ -28,7 +29,5 @@ export interface IntegrationGeneratorOptions {
|
|
|
28
29
|
/** Skip interactive prompts */
|
|
29
30
|
skipPrompts?: boolean;
|
|
30
31
|
}
|
|
31
|
-
type TokenAuthMethod = "basic" | "body" | "client_secret_basic" | "client_secret_post" | "request_body";
|
|
32
32
|
export declare function generateIntegration(projectDir: string, options?: IntegrationGeneratorOptions): Promise<void>;
|
|
33
|
-
export {};
|
|
34
33
|
//# sourceMappingURL=integration-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration-generator.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/generate/integration-generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"integration-generator.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/generate/integration-generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EASL,KAAK,eAAe,EAErB,MAAM,oCAAoC,CAAC;AAK5C,MAAM,WAAW,2BAA2B;IAC1C,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAChC,mBAAmB;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mCAAmC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,yEAAyE;IACzE,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,oDAAoD;IACpD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,+BAA+B;IAC/B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAaD,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,IAAI,CAAC,CAwBf"}
|
|
@@ -11,6 +11,7 @@ import { createFileSystem } from "../../../src/platform/index.js";
|
|
|
11
11
|
import { ensureDir } from "../../utils/fs.js";
|
|
12
12
|
import { isInteractive as checkIsInteractive, promptSync } from "../../../src/platform/index.js";
|
|
13
13
|
import { isCiEnv, isDenoTestingEnv } from "../../../src/config/index.js";
|
|
14
|
+
import { getNonInteractiveConfig, getToolExecuteBody, getToolInputSchema, normalizeTokenAuthMethod, parseAdditionalAuthParams, parseBooleanOption, parseScopes, validateIntegrationName, } from "./integration-generator-helpers.js";
|
|
14
15
|
import { select } from "../../utils/terminal-select.js";
|
|
15
16
|
let fs;
|
|
16
17
|
function canRunPrompts() {
|
|
@@ -22,71 +23,6 @@ function promptText(question, defaultValue) {
|
|
|
22
23
|
const input = promptSync(fullQuestion);
|
|
23
24
|
return Promise.resolve(input?.trim() || defaultValue || "");
|
|
24
25
|
}
|
|
25
|
-
function parseScopes(scopes) {
|
|
26
|
-
return scopes?.split(",").map((s) => s.trim()) || [];
|
|
27
|
-
}
|
|
28
|
-
function parseAdditionalAuthParams(params) {
|
|
29
|
-
if (!params?.trim())
|
|
30
|
-
return {};
|
|
31
|
-
return Object.fromEntries(params.split(",")
|
|
32
|
-
.map((entry) => entry.trim())
|
|
33
|
-
.filter(Boolean)
|
|
34
|
-
.map((entry) => {
|
|
35
|
-
const separatorIndex = entry.indexOf("=");
|
|
36
|
-
if (separatorIndex === -1) {
|
|
37
|
-
throw new Error("Additional auth params must use key=value pairs separated by commas");
|
|
38
|
-
}
|
|
39
|
-
const key = entry.slice(0, separatorIndex).trim();
|
|
40
|
-
const value = entry.slice(separatorIndex + 1).trim();
|
|
41
|
-
if (!key || !value) {
|
|
42
|
-
throw new Error("Additional auth params must use non-empty key=value pairs");
|
|
43
|
-
}
|
|
44
|
-
return [key, value];
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
function normalizeTokenAuthMethod(method) {
|
|
48
|
-
switch (method?.trim().toLowerCase()) {
|
|
49
|
-
case "basic":
|
|
50
|
-
return "basic";
|
|
51
|
-
case "body":
|
|
52
|
-
return "body";
|
|
53
|
-
case "client_secret_basic":
|
|
54
|
-
return "client_secret_basic";
|
|
55
|
-
case "client_secret_post":
|
|
56
|
-
return "client_secret_post";
|
|
57
|
-
case "request_body":
|
|
58
|
-
case undefined:
|
|
59
|
-
case "":
|
|
60
|
-
return "request_body";
|
|
61
|
-
default:
|
|
62
|
-
throw new Error("OAuth token auth method must be one of: request_body, body, basic, client_secret_basic, client_secret_post");
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function parseBooleanOption(value, defaultValue = false) {
|
|
66
|
-
if (typeof value === "boolean")
|
|
67
|
-
return value;
|
|
68
|
-
if (!value?.trim())
|
|
69
|
-
return defaultValue;
|
|
70
|
-
switch (value.trim().toLowerCase()) {
|
|
71
|
-
case "y":
|
|
72
|
-
case "yes":
|
|
73
|
-
case "true":
|
|
74
|
-
case "1":
|
|
75
|
-
return true;
|
|
76
|
-
case "n":
|
|
77
|
-
case "no":
|
|
78
|
-
case "false":
|
|
79
|
-
case "0":
|
|
80
|
-
return false;
|
|
81
|
-
default:
|
|
82
|
-
throw new Error("Boolean option must be yes/no, true/false, or 1/0");
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
function validateIntegrationName(name) {
|
|
86
|
-
if (!name || !/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
87
|
-
throw new Error("Integration name must be lowercase letters, numbers, and hyphens");
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
26
|
export async function generateIntegration(projectDir, options = {}) {
|
|
91
27
|
fs = createFileSystem();
|
|
92
28
|
const shouldPrompt = !options.skipPrompts && canRunPrompts();
|
|
@@ -109,26 +45,6 @@ export async function generateIntegration(projectDir, options = {}) {
|
|
|
109
45
|
console.log(` 4. Customize the generated tools in ai/integrations/${config.name}/tools/`);
|
|
110
46
|
console.log("");
|
|
111
47
|
}
|
|
112
|
-
function getNonInteractiveConfig(options) {
|
|
113
|
-
const { name, displayName, authType } = options;
|
|
114
|
-
if (!name || !displayName || !authType) {
|
|
115
|
-
throw new Error("Non-interactive mode requires --name, --display-name, and --auth-type options");
|
|
116
|
-
}
|
|
117
|
-
const normalizedName = name.toLowerCase();
|
|
118
|
-
return {
|
|
119
|
-
name: normalizedName,
|
|
120
|
-
displayName,
|
|
121
|
-
authType,
|
|
122
|
-
apiBaseUrl: options.apiBaseUrl ?? `https://api.${name}.com`,
|
|
123
|
-
authorizationUrl: options.authorizationUrl,
|
|
124
|
-
tokenUrl: options.tokenUrl,
|
|
125
|
-
scopes: parseScopes(options.scopes),
|
|
126
|
-
tokenAuthMethod: normalizeTokenAuthMethod(options.tokenAuthMethod),
|
|
127
|
-
additionalAuthParams: parseAdditionalAuthParams(options.additionalAuthParams),
|
|
128
|
-
usePKCE: parseBooleanOption(options.usePKCE, false),
|
|
129
|
-
envVarPrefix: name.toUpperCase().replace(/-/g, "_"),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
48
|
async function getInteractiveConfig(options) {
|
|
133
49
|
console.log("");
|
|
134
50
|
console.log(green("Integration Generator"));
|
|
@@ -666,44 +582,6 @@ export async function searchItems(query: string): Promise<unknown[]> {
|
|
|
666
582
|
await fs.writeTextFile(join(baseDir, "lib", `${config.name}-client.ts`), client);
|
|
667
583
|
cliLogger.debug("Created API client");
|
|
668
584
|
}
|
|
669
|
-
function getToolInputSchema(toolFile) {
|
|
670
|
-
return TOOL_FILE_CONTENTS[toolFile]?.inputSchema ?? "";
|
|
671
|
-
}
|
|
672
|
-
function getToolExecuteBody(toolFile) {
|
|
673
|
-
return TOOL_FILE_CONTENTS[toolFile]?.executeBody ?? "";
|
|
674
|
-
}
|
|
675
|
-
const TOOL_FILE_CONTENTS = {
|
|
676
|
-
"list-items.ts": {
|
|
677
|
-
inputSchema: `limit: z.number().optional().describe("Maximum number of items to return"),
|
|
678
|
-
offset: z.number().optional().describe("Number of items to skip"),`,
|
|
679
|
-
executeBody: `const items = await listItems({
|
|
680
|
-
limit: input.limit,
|
|
681
|
-
offset: input.offset,
|
|
682
|
-
});
|
|
683
|
-
return {
|
|
684
|
-
success: true,
|
|
685
|
-
items,
|
|
686
|
-
count: items.length,
|
|
687
|
-
};`,
|
|
688
|
-
},
|
|
689
|
-
"get-item.ts": {
|
|
690
|
-
inputSchema: `id: z.string().describe("The ID of the item to retrieve"),`,
|
|
691
|
-
executeBody: `const item = await getItem(input.id);
|
|
692
|
-
return {
|
|
693
|
-
success: true,
|
|
694
|
-
item,
|
|
695
|
-
};`,
|
|
696
|
-
},
|
|
697
|
-
"search.ts": {
|
|
698
|
-
inputSchema: `query: z.string().describe("Search query"),`,
|
|
699
|
-
executeBody: `const results = await searchItems(input.query);
|
|
700
|
-
return {
|
|
701
|
-
success: true,
|
|
702
|
-
results,
|
|
703
|
-
count: results.length,
|
|
704
|
-
};`,
|
|
705
|
-
},
|
|
706
|
-
};
|
|
707
585
|
async function createToolSkeletons(baseDir, config) {
|
|
708
586
|
const tools = [
|
|
709
587
|
{
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { KnowledgeIngestFailedFileResult, KnowledgeIngestFileResult, KnowledgeIngestSkippedFileResult } from "./result.js";
|
|
2
|
+
export type KnowledgeSource = {
|
|
3
|
+
kind: "local";
|
|
4
|
+
input: string;
|
|
5
|
+
localPath: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "upload";
|
|
8
|
+
input: string;
|
|
9
|
+
uploadPath: string;
|
|
10
|
+
localPath: string;
|
|
11
|
+
};
|
|
12
|
+
export interface KnowledgeSourceCollection {
|
|
13
|
+
sources: KnowledgeSource[];
|
|
14
|
+
skipped: KnowledgeIngestSkippedFileResult[];
|
|
15
|
+
}
|
|
16
|
+
export declare function normalizeKnowledgeInputPath(inputPath: string): string;
|
|
17
|
+
export declare function normalizeProjectUploadPath(inputPath: string): string;
|
|
18
|
+
export declare function formatKnowledgeUploadSource(uploadPath: string): string;
|
|
19
|
+
export declare function resolveExplicitUploadPath(inputPath: string): string;
|
|
20
|
+
export declare function isLikelyLocalPath(value: string): boolean;
|
|
21
|
+
export declare function isProjectUploadReference(value: string): boolean;
|
|
22
|
+
export declare function stripChatUploadPrefix(name: string): string;
|
|
23
|
+
export declare function resolveKnowledgeDownloadOutputDir(outputDir: string): string;
|
|
24
|
+
export declare function createFailedKnowledgeSource(input: {
|
|
25
|
+
source: string;
|
|
26
|
+
localSourcePath: string;
|
|
27
|
+
message: string;
|
|
28
|
+
reason: KnowledgeIngestFailedFileResult["reason"];
|
|
29
|
+
}): KnowledgeIngestFailedFileResult;
|
|
30
|
+
export declare function collectLocalFiles(root: string, recursive: boolean): Promise<KnowledgeSourceCollection>;
|
|
31
|
+
export declare function buildSourceReference(source: KnowledgeSource): string;
|
|
32
|
+
export declare function buildSuggestedSlug(source: KnowledgeSource, index: number): string;
|
|
33
|
+
export declare function ensureUniqueSlugs(sources: KnowledgeSource[]): string[];
|
|
34
|
+
export declare function deriveKnowledgeRemotePath(outputPath: string, outputDir: string, knowledgePath: string): string;
|
|
35
|
+
export declare function createKnowledgeIngestResult(input: {
|
|
36
|
+
source: string;
|
|
37
|
+
localSourcePath: string;
|
|
38
|
+
outputPath: string;
|
|
39
|
+
remotePath: string;
|
|
40
|
+
parser: {
|
|
41
|
+
slug: string;
|
|
42
|
+
stats: Record<string, unknown>;
|
|
43
|
+
warnings: string[];
|
|
44
|
+
source_type: string;
|
|
45
|
+
summary: string;
|
|
46
|
+
};
|
|
47
|
+
}): KnowledgeIngestFileResult;
|
|
48
|
+
//# sourceMappingURL=command-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-helpers.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/knowledge/command-helpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,+BAA+B,EAC/B,yBAAyB,EACzB,gCAAgC,EACjC,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7E,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,OAAO,EAAE,gCAAgC,EAAE,CAAC;CAC7C;AASD,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAMrE;AAED,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAKtE;AAED,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAanE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGxD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAI/D;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,iCAAiC,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE3E;AAgBD,wBAAgB,2BAA2B,CAAC,KAAK,EAAE;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,+BAA+B,CAAC,QAAQ,CAAC,CAAC;CACnD,GAAG,+BAA+B,CAOlC;AAmCD,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,yBAAyB,CAAC,CA8DpC;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAIpE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAgCjF;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,MAAM,EAAE,CAQtE;AAED,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GACpB,MAAM,CAQR;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,GAAG,yBAAyB,CAY5B"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { createFileSystem } from "../../../src/platform/index.js";
|
|
2
|
+
import { basename, extname, join, normalize, relative } from "../../../src/platform/compat/path/index.js";
|
|
3
|
+
import { classifyKnowledgeDirectoryPath, classifyKnowledgeSourcePath } from "./source-policy.js";
|
|
4
|
+
function slugify(value) {
|
|
5
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "document";
|
|
6
|
+
}
|
|
7
|
+
const CHAT_UPLOAD_PREFIX_RE = /^chat-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}-\d+-[a-z0-9]+-/i;
|
|
8
|
+
export function normalizeKnowledgeInputPath(inputPath) {
|
|
9
|
+
const normalizedPath = normalize(inputPath).replace(/^\/+/, "").replace(/\\/g, "/");
|
|
10
|
+
if (!normalizedPath || normalizedPath.startsWith("..") || normalizedPath.startsWith("/")) {
|
|
11
|
+
throw new Error(`Invalid knowledge input path: ${inputPath}`);
|
|
12
|
+
}
|
|
13
|
+
return normalizedPath;
|
|
14
|
+
}
|
|
15
|
+
export function normalizeProjectUploadPath(inputPath) {
|
|
16
|
+
return normalizeKnowledgeInputPath(inputPath);
|
|
17
|
+
}
|
|
18
|
+
export function formatKnowledgeUploadSource(uploadPath) {
|
|
19
|
+
const normalizedPath = normalizeKnowledgeInputPath(uploadPath);
|
|
20
|
+
return normalizedPath === "uploads" || normalizedPath.startsWith("uploads/")
|
|
21
|
+
? normalizedPath
|
|
22
|
+
: `uploads/${normalizedPath}`;
|
|
23
|
+
}
|
|
24
|
+
export function resolveExplicitUploadPath(inputPath) {
|
|
25
|
+
const normalizedInput = normalizeKnowledgeInputPath(inputPath);
|
|
26
|
+
const displayInput = inputPath.replace(/\\/g, "/");
|
|
27
|
+
const uploadPath = normalizeProjectUploadPath(inputPath);
|
|
28
|
+
if (!uploadPath || uploadPath === "uploads" || normalizedInput === "uploads" ||
|
|
29
|
+
normalizedInput.endsWith("/")) {
|
|
30
|
+
throw new Error(`Directory upload references require --path <prefix> --all: ${displayInput}`);
|
|
31
|
+
}
|
|
32
|
+
return uploadPath;
|
|
33
|
+
}
|
|
34
|
+
export function isLikelyLocalPath(value) {
|
|
35
|
+
return value.startsWith("/") || value.startsWith("./") || value.startsWith("../") ||
|
|
36
|
+
/^[A-Za-z]:[\\/]/.test(value);
|
|
37
|
+
}
|
|
38
|
+
export function isProjectUploadReference(value) {
|
|
39
|
+
if (isLikelyLocalPath(value))
|
|
40
|
+
return false;
|
|
41
|
+
const normalizedValue = normalize(value).replace(/\\/g, "/").replace(/^\/+/, "");
|
|
42
|
+
return normalizedValue === "uploads" || normalizedValue.startsWith("uploads/");
|
|
43
|
+
}
|
|
44
|
+
export function stripChatUploadPrefix(name) {
|
|
45
|
+
return name.replace(CHAT_UPLOAD_PREFIX_RE, "");
|
|
46
|
+
}
|
|
47
|
+
export function resolveKnowledgeDownloadOutputDir(outputDir) {
|
|
48
|
+
return join(outputDir, ".uploads");
|
|
49
|
+
}
|
|
50
|
+
function createSkippedKnowledgeSource(input) {
|
|
51
|
+
return {
|
|
52
|
+
source: input.source,
|
|
53
|
+
localSourcePath: input.localSourcePath ?? null,
|
|
54
|
+
message: input.message,
|
|
55
|
+
reason: input.reason,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function createFailedKnowledgeSource(input) {
|
|
59
|
+
return {
|
|
60
|
+
source: input.source,
|
|
61
|
+
localSourcePath: input.localSourcePath,
|
|
62
|
+
message: input.message,
|
|
63
|
+
reason: input.reason,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function classifySourceOrSkip(input) {
|
|
67
|
+
const decision = classifyKnowledgeSourcePath(input.source);
|
|
68
|
+
if (decision.kind === "ingest") {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return createSkippedKnowledgeSource({
|
|
72
|
+
source: input.source,
|
|
73
|
+
localSourcePath: input.localSourcePath,
|
|
74
|
+
message: decision.message,
|
|
75
|
+
reason: decision.reason,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function classifyDirectoryOrSkip(input) {
|
|
79
|
+
const decision = classifyKnowledgeDirectoryPath(input.source);
|
|
80
|
+
if (decision.kind === "ingest") {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return createSkippedKnowledgeSource({
|
|
84
|
+
source: input.source,
|
|
85
|
+
localSourcePath: null,
|
|
86
|
+
message: decision.message,
|
|
87
|
+
reason: decision.reason,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
export async function collectLocalFiles(root, recursive) {
|
|
91
|
+
const fs = createFileSystem();
|
|
92
|
+
const stat = await fs.stat(root);
|
|
93
|
+
if (stat.isFile) {
|
|
94
|
+
const skipped = classifySourceOrSkip({ source: root, localSourcePath: root });
|
|
95
|
+
return skipped == null
|
|
96
|
+
? {
|
|
97
|
+
sources: [{ kind: "local", input: root, localPath: root }],
|
|
98
|
+
skipped: [],
|
|
99
|
+
}
|
|
100
|
+
: {
|
|
101
|
+
sources: [],
|
|
102
|
+
skipped: [skipped],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (!stat.isDirectory) {
|
|
106
|
+
return { sources: [], skipped: [] };
|
|
107
|
+
}
|
|
108
|
+
const skippedRootDirectory = classifyDirectoryOrSkip({ source: root });
|
|
109
|
+
if (skippedRootDirectory != null) {
|
|
110
|
+
return {
|
|
111
|
+
sources: [],
|
|
112
|
+
skipped: [skippedRootDirectory],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const collection = {
|
|
116
|
+
sources: [],
|
|
117
|
+
skipped: [],
|
|
118
|
+
};
|
|
119
|
+
async function walk(dir) {
|
|
120
|
+
for await (const entry of fs.readDir(dir)) {
|
|
121
|
+
const entryPath = join(dir, entry.name);
|
|
122
|
+
if (entry.isDirectory) {
|
|
123
|
+
const skipped = classifyDirectoryOrSkip({ source: entryPath });
|
|
124
|
+
if (skipped != null) {
|
|
125
|
+
collection.skipped.push(skipped);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (recursive)
|
|
129
|
+
await walk(entryPath);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (!entry.isFile) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const skipped = classifySourceOrSkip({ source: entryPath, localSourcePath: entryPath });
|
|
136
|
+
if (skipped != null) {
|
|
137
|
+
collection.skipped.push(skipped);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
collection.sources.push({ kind: "local", input: root, localPath: entryPath });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
await walk(root);
|
|
144
|
+
collection.sources.sort((left, right) => left.localPath.localeCompare(right.localPath));
|
|
145
|
+
collection.skipped.sort((left, right) => left.source.localeCompare(right.source));
|
|
146
|
+
return collection;
|
|
147
|
+
}
|
|
148
|
+
export function buildSourceReference(source) {
|
|
149
|
+
return source.kind === "upload"
|
|
150
|
+
? formatKnowledgeUploadSource(source.uploadPath)
|
|
151
|
+
: source.localPath;
|
|
152
|
+
}
|
|
153
|
+
export function buildSuggestedSlug(source, index) {
|
|
154
|
+
const normalized = normalize(source.kind === "upload" ? source.uploadPath : source.localPath).replace(/\\/g, "/");
|
|
155
|
+
let stripped;
|
|
156
|
+
if (source.kind === "upload") {
|
|
157
|
+
stripped = normalized
|
|
158
|
+
.replace(/^\/workspace\/uploads\//, "")
|
|
159
|
+
.replace(/^\/workspace\//, "")
|
|
160
|
+
.replace(/^uploads\//, "")
|
|
161
|
+
.replace(/\.[^.]+$/, "");
|
|
162
|
+
}
|
|
163
|
+
else if (normalized.startsWith("/workspace/uploads/")) {
|
|
164
|
+
stripped = normalized.replace(/^\/workspace\/uploads\//, "").replace(/\.[^.]+$/, "");
|
|
165
|
+
}
|
|
166
|
+
else if (normalized.startsWith("/workspace/")) {
|
|
167
|
+
stripped = normalized.replace(/^\/workspace\//, "").replace(/\.[^.]+$/, "");
|
|
168
|
+
}
|
|
169
|
+
else if (normalized.startsWith("/")) {
|
|
170
|
+
stripped = basename(normalized, extname(normalized));
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
stripped = normalized.replace(/\.[^.]+$/, "");
|
|
174
|
+
}
|
|
175
|
+
const lastSlash = stripped.lastIndexOf("/");
|
|
176
|
+
if (lastSlash >= 0) {
|
|
177
|
+
const dir = stripped.slice(0, lastSlash + 1);
|
|
178
|
+
const file = stripChatUploadPrefix(stripped.slice(lastSlash + 1));
|
|
179
|
+
stripped = file ? `${dir}${file}` : stripped;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
stripped = stripChatUploadPrefix(stripped) || stripped;
|
|
183
|
+
}
|
|
184
|
+
return slugify(stripped || basename(normalized, extname(normalized)) || `document-${index + 1}`);
|
|
185
|
+
}
|
|
186
|
+
export function ensureUniqueSlugs(sources) {
|
|
187
|
+
const counts = new Map();
|
|
188
|
+
return sources.map((source, index) => {
|
|
189
|
+
const baseSlug = buildSuggestedSlug(source, index);
|
|
190
|
+
const nextCount = (counts.get(baseSlug) ?? 0) + 1;
|
|
191
|
+
counts.set(baseSlug, nextCount);
|
|
192
|
+
return nextCount === 1 ? baseSlug : `${baseSlug}-${nextCount}`;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
export function deriveKnowledgeRemotePath(outputPath, outputDir, knowledgePath) {
|
|
196
|
+
const relativeOutputPath = relative(outputDir, outputPath).replace(/\\/g, "/");
|
|
197
|
+
if (!relativeOutputPath || relativeOutputPath.startsWith("..")) {
|
|
198
|
+
throw new Error(`Output path is outside output directory: ${outputPath}`);
|
|
199
|
+
}
|
|
200
|
+
const prefix = normalizeKnowledgeInputPath(knowledgePath);
|
|
201
|
+
const normalizedRelative = normalize(relativeOutputPath).replace(/^\/+/, "");
|
|
202
|
+
return `${prefix}/${normalizedRelative}`.replace(/\\/g, "/");
|
|
203
|
+
}
|
|
204
|
+
export function createKnowledgeIngestResult(input) {
|
|
205
|
+
return {
|
|
206
|
+
source: input.source,
|
|
207
|
+
localSourcePath: input.localSourcePath,
|
|
208
|
+
outputPath: input.outputPath,
|
|
209
|
+
remotePath: input.remotePath,
|
|
210
|
+
slug: input.parser.slug,
|
|
211
|
+
sourceType: input.parser.source_type,
|
|
212
|
+
summary: input.parser.summary,
|
|
213
|
+
stats: input.parser.stats,
|
|
214
|
+
warnings: input.parser.warnings,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
@@ -9,6 +9,7 @@ type SafeParseResult<T> = {
|
|
|
9
9
|
import { type CommandResult } from "../../../src/platform/index.js";
|
|
10
10
|
import { type ApiClient } from "../../shared/config.js";
|
|
11
11
|
import type { ParsedArgs } from "../../shared/types.js";
|
|
12
|
+
import * as commandHelpers from "./command-helpers.js";
|
|
12
13
|
import { type Logger } from "../../../src/utils/index.js";
|
|
13
14
|
import { type KnowledgeIngestFailedFileResult, type KnowledgeIngestFileResult, type KnowledgeIngestSkippedFileResult } from "./result.js";
|
|
14
15
|
export interface KnowledgeParserResult {
|
|
@@ -66,22 +67,16 @@ declare const KnowledgeIngestArgsSchema: z.ZodObject<{
|
|
|
66
67
|
}, z.core.$strip>;
|
|
67
68
|
export type KnowledgeIngestOptions = z.infer<typeof KnowledgeIngestArgsSchema>;
|
|
68
69
|
export declare function parseKnowledgeIngestArgs(args: ParsedArgs): SafeParseResult<KnowledgeIngestOptions>;
|
|
69
|
-
export declare
|
|
70
|
-
export declare
|
|
71
|
-
export declare
|
|
72
|
-
export declare
|
|
73
|
-
export declare
|
|
74
|
-
export declare
|
|
75
|
-
export declare
|
|
76
|
-
export declare
|
|
77
|
-
export declare
|
|
78
|
-
export declare
|
|
79
|
-
source: string;
|
|
80
|
-
localSourcePath: string;
|
|
81
|
-
outputPath: string;
|
|
82
|
-
remotePath: string;
|
|
83
|
-
parser: Pick<KnowledgeParserResult, "slug" | "stats" | "warnings" | "source_type" | "summary">;
|
|
84
|
-
}): KnowledgeIngestFileResult;
|
|
70
|
+
export declare const normalizeKnowledgeInputPath: typeof commandHelpers.normalizeKnowledgeInputPath;
|
|
71
|
+
export declare const normalizeProjectUploadPath: typeof commandHelpers.normalizeProjectUploadPath;
|
|
72
|
+
export declare const formatKnowledgeUploadSource: typeof commandHelpers.formatKnowledgeUploadSource;
|
|
73
|
+
export declare const isLikelyLocalPath: typeof commandHelpers.isLikelyLocalPath;
|
|
74
|
+
export declare const stripChatUploadPrefix: typeof commandHelpers.stripChatUploadPrefix;
|
|
75
|
+
export declare const resolveKnowledgeDownloadOutputDir: typeof commandHelpers.resolveKnowledgeDownloadOutputDir;
|
|
76
|
+
export declare const buildSuggestedSlug: typeof commandHelpers.buildSuggestedSlug;
|
|
77
|
+
export declare const ensureUniqueSlugs: typeof commandHelpers.ensureUniqueSlugs;
|
|
78
|
+
export declare const deriveKnowledgeRemotePath: typeof commandHelpers.deriveKnowledgeRemotePath;
|
|
79
|
+
export declare const createKnowledgeIngestResult: typeof commandHelpers.createKnowledgeIngestResult;
|
|
85
80
|
export declare function runKnowledgeParser(input: {
|
|
86
81
|
filePath: string;
|
|
87
82
|
outputDir: string;
|