@folio-agent/handler 0.6.0 → 0.6.1
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/dist/init/cli.js +4 -3
- package/dist/init/writers.d.ts +5 -1
- package/dist/init/writers.js +6 -2
- package/package.json +1 -1
package/dist/init/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
3
3
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
import { dirname } from "node:path";
|
|
4
|
+
import { dirname, posix } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { DEFAULT_API_ROUTE_PATH, InitArgsError, resolveInitRun, USAGE } from "./options.js";
|
|
7
7
|
import { appendIngestToBuildScript, buildApiRouteTemplate, buildConfigJson, buildThemeCss, deriveEndpointPath, ensureGitignoreEntry, PUBLIC_DIR_NAME, resolveThemeCssPath, THEME_CSS_FILENAME, upsertDevVar, } from "./writers.js";
|
|
@@ -9,7 +9,6 @@ const CONFIG_PATH = "folio-agent.config.json";
|
|
|
9
9
|
const PACKAGE_JSON_PATH = "package.json";
|
|
10
10
|
const DEV_VARS_PATH = ".dev.vars";
|
|
11
11
|
const GITIGNORE_PATH = ".gitignore";
|
|
12
|
-
const KNOWLEDGE_OUTPUT_PATH = "dist/knowledge.json";
|
|
13
12
|
async function readJson(path) {
|
|
14
13
|
if (!existsSync(path))
|
|
15
14
|
return undefined;
|
|
@@ -69,7 +68,9 @@ export async function main(argv = process.argv.slice(2), env = process.env) {
|
|
|
69
68
|
: undefined;
|
|
70
69
|
const pkg = (await readJson(PACKAGE_JSON_PATH)) ?? {};
|
|
71
70
|
const scripts = pkg.scripts ?? {};
|
|
72
|
-
|
|
71
|
+
// API ルート雛形は <distDir>/knowledge.json を import するので、出力先もそこに揃える
|
|
72
|
+
const knowledgeOutputPath = posix.join(answers.distDir, "knowledge.json");
|
|
73
|
+
const nextBuildScript = appendIngestToBuildScript(scripts.build, CONFIG_PATH, knowledgeOutputPath);
|
|
73
74
|
const buildScriptChanged = nextBuildScript !== (scripts.build ?? "");
|
|
74
75
|
const { nextDevVars, gitignoreResult } = planDevVarsAndGitignore(answers.geminiApiKey, await readTextOrEmpty(DEV_VARS_PATH), await readTextOrEmpty(GITIGNORE_PATH));
|
|
75
76
|
const plan = [
|
package/dist/init/writers.d.ts
CHANGED
|
@@ -29,7 +29,11 @@ export interface ApiRouteAnswers {
|
|
|
29
29
|
}
|
|
30
30
|
/** Builds a minimal Cloudflare Pages Function that wires up `createChatHandler`. */
|
|
31
31
|
export declare function buildApiRouteTemplate(answers: ApiRouteAnswers): string;
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Appends the ingest command to a `build` script unless it already runs ingest. Any existing
|
|
34
|
+
* `folio-agent-ingest` counts, whatever its arguments: sites often write to a different output
|
|
35
|
+
* path than the default, and appending a second run would ingest twice.
|
|
36
|
+
*/
|
|
33
37
|
export declare function appendIngestToBuildScript(buildScript: string | undefined, configPath: string, knowledgeOutputPath: string): string;
|
|
34
38
|
/** Adds or replaces a single `KEY=value` line in `.dev.vars` content, leaving other lines untouched. */
|
|
35
39
|
export declare function upsertDevVar(content: string, key: string, value: string): string;
|
package/dist/init/writers.js
CHANGED
|
@@ -90,11 +90,15 @@ export function buildApiRouteTemplate(answers) {
|
|
|
90
90
|
"",
|
|
91
91
|
].join("\n");
|
|
92
92
|
}
|
|
93
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Appends the ingest command to a `build` script unless it already runs ingest. Any existing
|
|
95
|
+
* `folio-agent-ingest` counts, whatever its arguments: sites often write to a different output
|
|
96
|
+
* path than the default, and appending a second run would ingest twice.
|
|
97
|
+
*/
|
|
94
98
|
export function appendIngestToBuildScript(buildScript, configPath, knowledgeOutputPath) {
|
|
95
99
|
const ingestCommand = `${INGEST_COMMAND_PREFIX} ${configPath} ${knowledgeOutputPath}`;
|
|
96
100
|
const base = (buildScript ?? "").trim();
|
|
97
|
-
if (base.includes(
|
|
101
|
+
if (base.includes(INGEST_COMMAND_PREFIX)) {
|
|
98
102
|
return base;
|
|
99
103
|
}
|
|
100
104
|
return base.length > 0 ? `${base} && ${ingestCommand}` : ingestCommand;
|