@autorag/librarian 2.6.3 → 2.7.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/dist/index.js CHANGED
@@ -7764,8 +7764,9 @@ function createReranker(config) {
7764
7764
  if (config === false || config === undefined)
7765
7765
  return;
7766
7766
  const provider = config.provider ?? DEFAULT_RERANK_PROVIDER;
7767
- if (provider !== DEFAULT_RERANK_PROVIDER)
7768
- return;
7767
+ if (!SUPPORTED_RERANK_PROVIDERS.includes(provider)) {
7768
+ throw new Error(`Unsupported rerank provider "${provider}"; supported providers: ${SUPPORTED_RERANK_PROVIDERS.join(", ")}`);
7769
+ }
7769
7770
  return new OpenRouterReranker(config);
7770
7771
  }
7771
7772
 
@@ -7794,8 +7795,8 @@ class OpenRouterReranker {
7794
7795
  sdkOptions.timeoutMs = options.timeoutMs;
7795
7796
  const sdk = new OpenRouter(sdkOptions);
7796
7797
  this.client = {
7797
- rerank: async (request) => {
7798
- const response = await sdk.rerank.rerank(request);
7798
+ rerank: async (request, requestOptions) => {
7799
+ const response = await sdk.rerank.rerank(request, requestOptions);
7799
7800
  if (typeof response === "string")
7800
7801
  throw new Error(response);
7801
7802
  return response;
@@ -7824,7 +7825,7 @@ class OpenRouterReranker {
7824
7825
  };
7825
7826
  if (options.topN !== undefined)
7826
7827
  requestBody.topN = options.topN;
7827
- const response = await this.client.rerank({ requestBody });
7828
+ const response = await this.client.rerank({ requestBody }, { signal: options.signal });
7828
7829
  const ordered = Array.isArray(response?.results) ? response.results : [];
7829
7830
  const seen = new Set;
7830
7831
  const reranked = [];
@@ -7854,8 +7855,10 @@ class OpenRouterReranker {
7854
7855
  return reranked;
7855
7856
  }
7856
7857
  }
7857
- var DEFAULT_RERANK_MODEL = "voyageai/rerank-3-lite", DEFAULT_RERANK_PROVIDER = "openrouter", DEFAULT_RERANK_API_KEY_ENV = "OPENROUTER_API_KEY";
7858
- var init_rerank = () => {};
7858
+ var DEFAULT_RERANK_MODEL = "voyageai/rerank-3-lite", DEFAULT_RERANK_PROVIDER = "openrouter", DEFAULT_RERANK_API_KEY_ENV = "OPENROUTER_API_KEY", SUPPORTED_RERANK_PROVIDERS;
7859
+ var init_rerank = __esm(() => {
7860
+ SUPPORTED_RERANK_PROVIDERS = [DEFAULT_RERANK_PROVIDER];
7861
+ });
7859
7862
 
7860
7863
  // src/web/search/credentials.ts
7861
7864
  function envCredential(...names) {
@@ -7911,392 +7914,9 @@ var init_model_auth = __esm(() => {
7911
7914
  };
7912
7915
  });
7913
7916
 
7914
- // src/filesystem/cloud-placeholder.ts
7915
- import { execFile as execFile2 } from "node:child_process";
7916
- import { lstat } from "node:fs/promises";
7917
- import { dirname as dirname10, relative as relative6, sep as sep7 } from "node:path";
7918
- import { promisify as promisify2 } from "node:util";
7919
- function pathLooksLikeCloudRoot(target) {
7920
- const normalized = target.replaceAll("\\", "/");
7921
- return MAC_CLOUD_PATH_MARKERS.some((marker) => normalized.includes(marker)) || WINDOWS_CLOUD_PATH_MARKERS.some((marker) => normalized.toLowerCase().includes(marker.toLowerCase()));
7922
- }
7923
- async function classifyFilesystemRoot(target) {
7924
- if (pathLooksLikeCloudRoot(target)) {
7925
- return { kind: "file-provider", reason: "path-marker", provider: cloudProviderFromPath(target) };
7926
- }
7927
- if (process.platform === "darwin")
7928
- return classifyDarwinRoot(target);
7929
- if (process.platform === "win32")
7930
- return classifyWindowsRoot(target);
7931
- return { kind: "local", reason: "local" };
7932
- }
7933
- async function isDatalessPlaceholder(target) {
7934
- if (process.platform === "darwin") {
7935
- try {
7936
- const { stdout } = await execFileAsync("/usr/bin/stat", ["-f", "%f", target], { timeout: 2000 });
7937
- const flags = Number.parseInt(stdout.trim(), 16);
7938
- return Number.isFinite(flags) && (flags & UF_DATALESS) !== 0;
7939
- } catch {
7940
- return false;
7941
- }
7942
- }
7943
- if (process.platform === "win32") {
7944
- const attributes = await windowsFileAttributes(target);
7945
- return attributes !== undefined && (attributes & WINDOWS_FILE_ATTRIBUTE_OFFLINE) !== 0 && (attributes & (WINDOWS_FILE_ATTRIBUTE_RECALL_ON_OPEN | WINDOWS_FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS)) !== 0;
7946
- }
7947
- return false;
7948
- }
7949
- async function classifyDarwinRoot(target) {
7950
- let cursor = target;
7951
- for (let depth = 0;depth < 8; depth += 1) {
7952
- const provider = await readFileProviderDomain(cursor);
7953
- if (provider !== undefined)
7954
- return { kind: "file-provider", reason: "file-provider-xattr", provider };
7955
- const parent = dirname10(cursor);
7956
- if (parent === cursor)
7957
- break;
7958
- cursor = parent;
7959
- }
7960
- return { kind: "local", reason: "local" };
7961
- }
7962
- async function classifyWindowsRoot(target) {
7963
- const attributes = await windowsFileAttributes(target);
7964
- if (attributes !== undefined && (attributes & WINDOWS_FILE_ATTRIBUTE_OFFLINE) !== 0 && (attributes & (WINDOWS_FILE_ATTRIBUTE_RECALL_ON_OPEN | WINDOWS_FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS)) !== 0) {
7965
- return { kind: "file-provider", reason: "placeholder-attribute", provider: "windows-cloud-files" };
7966
- }
7967
- if (await windowsCloudVolume(target)) {
7968
- return { kind: "file-provider", reason: "cloud-volume", provider: "windows-cloud-volume" };
7969
- }
7970
- return { kind: "local", reason: "local" };
7971
- }
7972
- async function windowsFileAttributes(target) {
7973
- try {
7974
- const script = `(Get-Item -LiteralPath ${quotePowerShell(target)} -Force).Attributes.value__`;
7975
- const { stdout } = await execFileAsync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script], {
7976
- timeout: 2000
7977
- });
7978
- const value = Number.parseInt(stdout.trim(), 10);
7979
- return Number.isFinite(value) ? value : undefined;
7980
- } catch {
7981
- return;
7982
- }
7983
- }
7984
- async function windowsCloudVolume(target) {
7985
- try {
7986
- const root = /^[A-Za-z]:/.test(target) ? `${target.slice(0, 2)}\\` : target;
7987
- const script = `Get-Volume -DriveLetter '${root[0]}' -ErrorAction SilentlyContinue | ` + "Select-Object -Property FileSystem,FileSystemLabel | ConvertTo-Json -Compress";
7988
- const { stdout } = await execFileAsync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script], {
7989
- timeout: 2000
7990
- });
7991
- return /drivefs|google drive|onedrive|cloud/i.test(stdout);
7992
- } catch {
7993
- return false;
7994
- }
7995
- }
7996
- async function readFileProviderDomain(target) {
7997
- try {
7998
- await lstat(target);
7999
- const { stdout } = await execFileAsync("/usr/bin/xattr", ["-p", FILE_PROVIDER_XATTR, target], {
8000
- timeout: 2000
8001
- });
8002
- const value = stdout.trim();
8003
- return value.length > 0 ? value : undefined;
8004
- } catch {
8005
- return;
8006
- }
8007
- }
8008
- function cloudProviderFromPath(target) {
8009
- const lower = target.toLowerCase();
8010
- if (lower.includes("googledrive") || lower.includes("google drive") || lower.includes("drivefs"))
8011
- return "google-drive";
8012
- if (lower.includes("onedrive"))
8013
- return "onedrive";
8014
- if (lower.includes("mobile documents") || lower.includes("clouddocs"))
8015
- return "icloud";
8016
- return "file-provider";
8017
- }
8018
- function quotePowerShell(value) {
8019
- return `'${value.replaceAll("'", "''")}'`;
8020
- }
8021
- var execFileAsync, UF_DATALESS = 32768, FILE_PROVIDER_XATTR = "com.apple.file-provider-domain-id", WINDOWS_FILE_ATTRIBUTE_OFFLINE = 4096, WINDOWS_FILE_ATTRIBUTE_RECALL_ON_OPEN = 262144, WINDOWS_FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 4194304, MAC_CLOUD_PATH_MARKERS, WINDOWS_CLOUD_PATH_MARKERS;
8022
- var init_cloud_placeholder = __esm(() => {
8023
- execFileAsync = promisify2(execFile2);
8024
- MAC_CLOUD_PATH_MARKERS = ["/Library/CloudStorage/", "/Library/Mobile Documents/"];
8025
- WINDOWS_CLOUD_PATH_MARKERS = [
8026
- "\\OneDrive",
8027
- "/OneDrive",
8028
- "\\Google Drive",
8029
- "/Google Drive",
8030
- "\\GoogleDriveFS",
8031
- "/GoogleDriveFS",
8032
- "\\My Drive",
8033
- "/My Drive",
8034
- "\\Shared drives",
8035
- "/Shared drives"
8036
- ];
8037
- });
8038
-
8039
- // src/agent/bash-tool.ts
8040
- import { spawn as spawn9 } from "node:child_process";
8041
- import { Type as Type2 } from "typebox";
8042
- function runCommand(command, cwd, timeoutMs, maxOutputBytes, signal) {
8043
- return new Promise((resolve) => {
8044
- if (signal?.aborted) {
8045
- resolve({
8046
- output: "",
8047
- exitCode: undefined,
8048
- aborted: true,
8049
- terminationFailed: false,
8050
- timedOut: false,
8051
- truncated: false
8052
- });
8053
- return;
8054
- }
8055
- const shell = process.platform === "win32" ? "bash.exe" : "/bin/bash";
8056
- const child = spawn9(shell, ["-c", command], {
8057
- cwd,
8058
- detached: process.platform !== "win32",
8059
- windowsHide: true
8060
- });
8061
- const chunks = [];
8062
- let total = 0;
8063
- let truncated = false;
8064
- let timedOut = false;
8065
- let aborted = false;
8066
- let settled = false;
8067
- let killGraceTimer;
8068
- let terminationRequested = false;
8069
- let terminationStarted = false;
8070
- let terminationSettled = false;
8071
- let terminationFailed = false;
8072
- let pendingExitCode;
8073
- const collect = (data) => {
8074
- if (total >= maxOutputBytes) {
8075
- truncated = true;
8076
- return;
8077
- }
8078
- const remaining = maxOutputBytes - total;
8079
- if (data.length > remaining) {
8080
- chunks.push(data.subarray(0, remaining));
8081
- total = maxOutputBytes;
8082
- truncated = true;
8083
- } else {
8084
- chunks.push(data);
8085
- total += data.length;
8086
- }
8087
- };
8088
- child.stdout?.on("data", collect);
8089
- child.stderr?.on("data", collect);
8090
- const finish = (exitCode) => {
8091
- if (settled)
8092
- return;
8093
- if (terminationRequested && !terminationSettled) {
8094
- pendingExitCode = exitCode;
8095
- return;
8096
- }
8097
- settled = true;
8098
- clearTimeout(timer);
8099
- if (killGraceTimer !== undefined)
8100
- clearTimeout(killGraceTimer);
8101
- signal?.removeEventListener("abort", onAbort);
8102
- resolve({
8103
- output: Buffer.concat(chunks).toString("utf8"),
8104
- exitCode,
8105
- aborted,
8106
- terminationFailed,
8107
- timedOut,
8108
- truncated
8109
- });
8110
- };
8111
- const killDirectChild = () => {
8112
- try {
8113
- return child.kill("SIGKILL");
8114
- } catch {
8115
- return false;
8116
- }
8117
- };
8118
- const killProcessTree = async () => {
8119
- if (child.pid === undefined)
8120
- return true;
8121
- if (process.platform === "win32") {
8122
- return await new Promise((resolve) => {
8123
- const killer = spawn9("taskkill", ["/pid", String(child.pid), "/t", "/f"], { stdio: "ignore" });
8124
- let completed = false;
8125
- const graceTimer = setTimeout(() => {
8126
- if (completed)
8127
- return;
8128
- completed = true;
8129
- killer.kill();
8130
- resolve(killDirectChild());
8131
- }, KILL_EXIT_GRACE_MS);
8132
- const finishKill = (success) => {
8133
- if (completed)
8134
- return;
8135
- completed = true;
8136
- clearTimeout(graceTimer);
8137
- if (!success)
8138
- killDirectChild();
8139
- resolve(success);
8140
- };
8141
- killer.on("error", () => finishKill(false));
8142
- killer.on("close", (code) => finishKill(code === 0));
8143
- });
8144
- }
8145
- try {
8146
- process.kill(-child.pid, "SIGKILL");
8147
- return true;
8148
- } catch {
8149
- killDirectChild();
8150
- return false;
8151
- }
8152
- };
8153
- const releaseAfterKill = async () => {
8154
- if (terminationStarted)
8155
- return;
8156
- terminationStarted = true;
8157
- const killed = await killProcessTree();
8158
- terminationSettled = true;
8159
- terminationFailed = !killed;
8160
- child.stdout?.destroy();
8161
- child.stderr?.destroy();
8162
- killGraceTimer = setTimeout(() => finish(undefined), KILL_EXIT_GRACE_MS);
8163
- if (pendingExitCode !== undefined)
8164
- finish(pendingExitCode);
8165
- };
8166
- const timer = setTimeout(() => {
8167
- timedOut = true;
8168
- terminationRequested = true;
8169
- releaseAfterKill();
8170
- }, timeoutMs);
8171
- const onAbort = () => {
8172
- aborted = true;
8173
- terminationRequested = true;
8174
- releaseAfterKill();
8175
- };
8176
- if (signal) {
8177
- if (signal.aborted)
8178
- onAbort();
8179
- else
8180
- signal.addEventListener("abort", onAbort, { once: true });
8181
- }
8182
- child.on("error", () => finish(undefined));
8183
- child.on("close", (code) => finish(code === null ? undefined : code));
8184
- });
8185
- }
8186
- function createBashTool(options) {
8187
- const defaultTimeout = options.timeoutMs ?? DEFAULT_TIMEOUT_MS6;
8188
- const maxOutputBytes = options.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES;
8189
- return {
8190
- name: BASH_TOOL_NAME,
8191
- label: "Bash",
8192
- description: "Run a shell command to explore and read the document collection (ls, find, grep, cat, head, sed, rg). Returns combined stdout/stderr.",
8193
- parameters: bashSchema,
8194
- async execute(_toolCallId, params, signal) {
8195
- const command = String(params.command ?? "").trim();
8196
- if (command.length === 0) {
8197
- return {
8198
- content: [{ type: "text", text: "Command was empty; nothing was run." }],
8199
- details: {
8200
- method: "bash",
8201
- command: "",
8202
- aborted: false,
8203
- exitCode: undefined,
8204
- terminationFailed: false,
8205
- timedOut: false,
8206
- truncated: false
8207
- }
8208
- };
8209
- }
8210
- const cwd = typeof params.cwd === "string" && params.cwd.length > 0 ? params.cwd : options.cwd;
8211
- if (CLOUD_CONTENT_COMMAND.test(command)) {
8212
- const classification = await classifyFilesystemRoot(cwd);
8213
- if (classification.kind === "file-provider") {
8214
- return {
8215
- content: [
8216
- {
8217
- type: "text",
8218
- text: "AUTORAG_CLOUD_PLACEHOLDER_BLOCKED: content access under a cloud placeholder root was refused to prevent remote hydration. " + "Use the configured cloud-drive datasource or a materialized local file."
8219
- }
8220
- ],
8221
- details: {
8222
- method: "bash",
8223
- command,
8224
- aborted: false,
8225
- exitCode: undefined,
8226
- terminationFailed: false,
8227
- timedOut: false,
8228
- truncated: false
8229
- }
8230
- };
8231
- }
8232
- if (await isDatalessPlaceholder(cwd)) {
8233
- return {
8234
- content: [
8235
- {
8236
- type: "text",
8237
- text: "AUTORAG_CLOUD_PLACEHOLDER_BLOCKED: the working path is a data-less cloud placeholder. " + "Use the configured cloud-drive datasource or materialize the file first."
8238
- }
8239
- ],
8240
- details: {
8241
- method: "bash",
8242
- command,
8243
- aborted: false,
8244
- exitCode: undefined,
8245
- terminationFailed: false,
8246
- timedOut: false,
8247
- truncated: false
8248
- }
8249
- };
8250
- }
8251
- }
8252
- const timeoutMs = typeof params.timeoutMs === "number" && params.timeoutMs > 0 ? params.timeoutMs : defaultTimeout;
8253
- const run = await runCommand(command, cwd, timeoutMs, maxOutputBytes, signal);
8254
- const parts = [];
8255
- parts.push(run.output.length > 0 ? run.output : run.aborted ? "(command aborted)" : "(no output)");
8256
- if (run.timedOut)
8257
- parts.push(`
8258
- (command timed out after ${timeoutMs}ms and was killed)`);
8259
- if (run.truncated)
8260
- parts.push(`
8261
- (output truncated at ${maxOutputBytes} bytes)`);
8262
- if (run.exitCode !== undefined && run.exitCode !== 0 && !run.timedOut) {
8263
- parts.push(`
8264
- (exit code ${run.exitCode})`);
8265
- }
8266
- if (run.terminationFailed)
8267
- parts.push(`
8268
- (process termination failed)`);
8269
- return {
8270
- content: [{ type: "text", text: parts.join("") }],
8271
- details: {
8272
- method: "bash",
8273
- command,
8274
- aborted: run.aborted,
8275
- exitCode: run.exitCode,
8276
- terminationFailed: run.terminationFailed,
8277
- timedOut: run.timedOut,
8278
- truncated: run.truncated
8279
- }
8280
- };
8281
- }
8282
- };
8283
- }
8284
- var BASH_TOOL_NAME = "bash", DEFAULT_TIMEOUT_MS6 = 120000, DEFAULT_MAX_OUTPUT_BYTES = 131072, KILL_EXIT_GRACE_MS = 5000, bashSchema, CLOUD_CONTENT_COMMAND;
8285
- var init_bash_tool = __esm(() => {
8286
- init_cloud_placeholder();
8287
- bashSchema = Type2.Object({
8288
- command: Type2.String({
8289
- description: "Shell command to run (bash -c). Use standard tools like ls, find, grep, cat, head, sed, rg."
8290
- }),
8291
- cwd: Type2.Optional(Type2.String({ description: "Working directory for the command. Defaults to the configured workspace root." })),
8292
- timeoutMs: Type2.Optional(Type2.Integer({ description: "Optional timeout in milliseconds for this command." }))
8293
- });
8294
- CLOUD_CONTENT_COMMAND = /\b(?:rg|ripgrep|grep|egrep|fgrep|cat|less|more|head|tail|sed|awk)\b/i;
8295
- });
8296
-
8297
7917
  // src/agent/datasource-skill.ts
8298
7918
  import { formatSkillsForSystemPrompt } from "@earendil-works/pi-agent-core";
8299
- import { Type as Type3 } from "typebox";
7919
+ import { Type as Type2 } from "typebox";
8300
7920
  function datasourceSkillLocation(name) {
8301
7921
  return `datasource://${name}`;
8302
7922
  }
@@ -8342,15 +7962,15 @@ function createLoadDatasourceSkillTool(provider) {
8342
7962
  }
8343
7963
  var LOAD_DATASOURCE_SKILL_TOOL_NAME = "load_datasource_skill", loadDatasourceSkillSchema;
8344
7964
  var init_datasource_skill = __esm(() => {
8345
- loadDatasourceSkillSchema = Type3.Object({
8346
- name: Type3.String({
7965
+ loadDatasourceSkillSchema = Type2.Object({
7966
+ name: Type2.String({
8347
7967
  description: "Datasource skill name from the available skills list to load full instructions for."
8348
7968
  })
8349
7969
  });
8350
7970
  });
8351
7971
 
8352
7972
  // src/agent/dupey-tool.ts
8353
- import { Type as Type4 } from "typebox";
7973
+ import { Type as Type3 } from "typebox";
8354
7974
  function createScanDuplicateDocumentsTool(provider) {
8355
7975
  return {
8356
7976
  name: SCAN_DUPLICATE_DOCUMENTS_TOOL_NAME,
@@ -8469,11 +8089,11 @@ function formatScore(value) {
8469
8089
  }
8470
8090
  var SCAN_DUPLICATE_DOCUMENTS_TOOL_NAME = "scan_duplicate_documents", MAX_RENDERED_FAMILIES = 200, MAX_RENDERED_MEMBERS = 50, scanDuplicateDocumentsSchema;
8471
8091
  var init_dupey_tool = __esm(() => {
8472
- scanDuplicateDocumentsSchema = Type4.Object({});
8092
+ scanDuplicateDocumentsSchema = Type3.Object({});
8473
8093
  });
8474
8094
 
8475
8095
  // src/agent/emit-results-tool.ts
8476
- import { Type as Type5 } from "typebox";
8096
+ import { Type as Type4 } from "typebox";
8477
8097
  function createEmitResultsTool(capture) {
8478
8098
  return {
8479
8099
  name: EMIT_AUTORAG_RESULTS_TOOL_NAME,
@@ -8526,55 +8146,55 @@ function createEmitResultsTool(capture) {
8526
8146
  }
8527
8147
  var EMIT_AUTORAG_RESULTS_TOOL_NAME = "emit_autorag_results", evidenceRefSchema, emitResultsSchema;
8528
8148
  var init_emit_results_tool = __esm(() => {
8529
- evidenceRefSchema = Type5.Object({
8530
- method: Type5.String({ description: "Retrieval method namespace for this evidence chunk" }),
8531
- source: Type5.String({ description: "Internal opaque source identifier for this evidence chunk" }),
8532
- excerpt: Type5.Optional(Type5.String({ description: "Evidence excerpt used for stable ID normalization" })),
8533
- content: Type5.Optional(Type5.String({ description: "Evidence content used for stable ID normalization" })),
8534
- retrievalResultId: Type5.Optional(Type5.String({ description: "Backend retrieval ID when path-opaque and stable" })),
8535
- chunkIndex: Type5.Optional(Type5.Integer({ description: "Chunk index, if available" })),
8536
- lineNumber: Type5.Optional(Type5.Integer({ description: "Line number, if available" })),
8537
- stableEvidenceId: Type5.Optional(Type5.String({ description: "Stable evidence ID, if already normalized" })),
8538
- retrieverMix: Type5.Optional(Type5.Array(Type5.String({ maxLength: 64 }), {
8149
+ evidenceRefSchema = Type4.Object({
8150
+ method: Type4.String({ description: "Retrieval method namespace for this evidence chunk" }),
8151
+ source: Type4.String({ description: "Internal opaque source identifier for this evidence chunk" }),
8152
+ excerpt: Type4.Optional(Type4.String({ description: "Evidence excerpt used for stable ID normalization" })),
8153
+ content: Type4.Optional(Type4.String({ description: "Evidence content used for stable ID normalization" })),
8154
+ retrievalResultId: Type4.Optional(Type4.String({ description: "Backend retrieval ID when path-opaque and stable" })),
8155
+ chunkIndex: Type4.Optional(Type4.Integer({ description: "Chunk index, if available" })),
8156
+ lineNumber: Type4.Optional(Type4.Integer({ description: "Line number, if available" })),
8157
+ stableEvidenceId: Type4.Optional(Type4.String({ description: "Stable evidence ID, if already normalized" })),
8158
+ retrieverMix: Type4.Optional(Type4.Array(Type4.String({ maxLength: 64 }), {
8539
8159
  description: "Retrievers that contributed to this result",
8540
8160
  maxItems: 8
8541
8161
  })),
8542
- parserType: Type5.Optional(Type5.String({ description: "Parser that produced this evidence", maxLength: 120 })),
8543
- documentType: Type5.Optional(Type5.String({ description: "Document type, if known", maxLength: 120 })),
8544
- documentArea: Type5.Optional(Type5.String({ description: "Document collection area, if known", maxLength: 120 })),
8545
- evidenceType: Type5.Optional(Type5.String({ description: "Evidence type, if known", maxLength: 120 })),
8546
- evidenceLocation: Type5.Optional(Type5.String({ description: "Human-readable evidence location", maxLength: 120 })),
8547
- confidence: Type5.Optional(Type5.Number({ description: "Evidence confidence, 0..1", minimum: 0, maximum: 1 }))
8162
+ parserType: Type4.Optional(Type4.String({ description: "Parser that produced this evidence", maxLength: 120 })),
8163
+ documentType: Type4.Optional(Type4.String({ description: "Document type, if known", maxLength: 120 })),
8164
+ documentArea: Type4.Optional(Type4.String({ description: "Document collection area, if known", maxLength: 120 })),
8165
+ evidenceType: Type4.Optional(Type4.String({ description: "Evidence type, if known", maxLength: 120 })),
8166
+ evidenceLocation: Type4.Optional(Type4.String({ description: "Human-readable evidence location", maxLength: 120 })),
8167
+ confidence: Type4.Optional(Type4.Number({ description: "Evidence confidence, 0..1", minimum: 0, maximum: 1 }))
8548
8168
  });
8549
- emitResultsSchema = Type5.Object({
8550
- answer: Type5.String({
8169
+ emitResultsSchema = Type4.Object({
8170
+ answer: Type4.String({
8551
8171
  description: "Answer for the caller. When a first answer was already delivered to the caller during this run, this MUST contain only the corrections and newly verified findings relative to it — never restate the first answer; otherwise it is the complete answer. At most 5 bullet points (plus optional explanation); reference results by bracketed number (e.g. [1], [2]) without file paths or raw chunk text."
8552
8172
  }),
8553
- results: Type5.Array(Type5.Object({
8554
- number: Type5.Integer({ description: "1-based result number" }),
8555
- title: Type5.String({ description: "Short name of the curated knowledge unit" }),
8556
- summary: Type5.String({ description: "Key insight: purpose, details, and line range" }),
8557
- evidence: Type5.Array(Type5.Object({
8558
- excerpt: Type5.String({ description: "Supporting excerpt" }),
8559
- lineNumber: Type5.Optional(Type5.Integer({ description: "Line number of the excerpt, if known" }))
8173
+ results: Type4.Array(Type4.Object({
8174
+ number: Type4.Integer({ description: "1-based result number" }),
8175
+ title: Type4.String({ description: "Short name of the curated knowledge unit" }),
8176
+ summary: Type4.String({ description: "Key insight: purpose, details, and line range" }),
8177
+ evidence: Type4.Array(Type4.Object({
8178
+ excerpt: Type4.String({ description: "Supporting excerpt" }),
8179
+ lineNumber: Type4.Optional(Type4.Integer({ description: "Line number of the excerpt, if known" }))
8560
8180
  })),
8561
- confidence: Type5.Number({ description: "Confidence in this result, 0..1", minimum: 0, maximum: 1 })
8181
+ confidence: Type4.Number({ description: "Confidence in this result, 0..1", minimum: 0, maximum: 1 })
8562
8182
  }), { description: "Numbered curated knowledge units." }),
8563
- mapping: Type5.Array(Type5.Object({
8564
- number: Type5.Integer({ description: "Matches the result number this entry maps" }),
8565
- source: Type5.String({ description: "Source identifier — a real file path or a datasource id" }),
8566
- method: Type5.String({ description: "Retrieval method or tool that produced the source" }),
8567
- content: Type5.String({ description: "Raw content snippet for feedback tracking" }),
8568
- evidenceRefs: Type5.Optional(Type5.Array(evidenceRefSchema, {
8183
+ mapping: Type4.Array(Type4.Object({
8184
+ number: Type4.Integer({ description: "Matches the result number this entry maps" }),
8185
+ source: Type4.String({ description: "Source identifier — a real file path or a datasource id" }),
8186
+ method: Type4.String({ description: "Retrieval method or tool that produced the source" }),
8187
+ content: Type4.String({ description: "Raw content snippet for feedback tracking" }),
8188
+ evidenceRefs: Type4.Optional(Type4.Array(evidenceRefSchema, {
8569
8189
  description: "Hidden evidence chunk references supporting this curated result"
8570
8190
  }))
8571
8191
  }), { description: "Internal number -> source/method mapping for feedback. One entry per result number." }),
8572
- warnings: Type5.Optional(Type5.Array(Type5.String(), { description: "Optional warnings about this result set" }))
8192
+ warnings: Type4.Optional(Type4.Array(Type4.String(), { description: "Optional warnings about this result set" }))
8573
8193
  });
8574
8194
  });
8575
8195
 
8576
8196
  // src/agent/everything-search-tool.ts
8577
- import { Type as Type6 } from "typebox";
8197
+ import { Type as Type5 } from "typebox";
8578
8198
  function createEverythingSearchTool(provider) {
8579
8199
  return {
8580
8200
  name: EVERYTHING_SEARCH_TOOL_NAME,
@@ -8626,28 +8246,28 @@ ${lines.join(`
8626
8246
  }
8627
8247
  var EVERYTHING_SEARCH_TOOL_NAME = "everything_search", MAX_RESULTS_CAP2 = 1000, DEFAULT_MAX_RESULTS3 = 100, everythingSearchSchema;
8628
8248
  var init_everything_search_tool = __esm(() => {
8629
- everythingSearchSchema = Type6.Object({
8630
- query: Type6.String({
8249
+ everythingSearchSchema = Type5.Object({
8250
+ query: Type5.String({
8631
8251
  description: 'Everything search syntax over file and folder names: space = AND, | = OR, ! = NOT, "quoted phrase", wildcards (*.pdf), ext:pdf;docx, dm:thisweek, size:>10mb, parent:<folder>, path fragments like \\reports\\ when matchPath is true.'
8632
8252
  }),
8633
- regex: Type6.Optional(Type6.Boolean({ description: "Treat query as a regular expression." })),
8634
- matchCase: Type6.Optional(Type6.Boolean()),
8635
- matchPath: Type6.Optional(Type6.Boolean({ description: "Match against the full path instead of the name." })),
8636
- wholeWord: Type6.Optional(Type6.Boolean()),
8637
- kind: Type6.Optional(Type6.Union([Type6.Literal("files"), Type6.Literal("folders")])),
8638
- path: Type6.Optional(Type6.String({ description: "Absolute folder to search within." })),
8639
- sort: Type6.Optional(Type6.Union([
8640
- Type6.Literal("name-ascending"),
8641
- Type6.Literal("name-descending"),
8642
- Type6.Literal("path-ascending"),
8643
- Type6.Literal("path-descending"),
8644
- Type6.Literal("size-ascending"),
8645
- Type6.Literal("size-descending"),
8646
- Type6.Literal("date-modified-ascending"),
8647
- Type6.Literal("date-modified-descending")
8253
+ regex: Type5.Optional(Type5.Boolean({ description: "Treat query as a regular expression." })),
8254
+ matchCase: Type5.Optional(Type5.Boolean()),
8255
+ matchPath: Type5.Optional(Type5.Boolean({ description: "Match against the full path instead of the name." })),
8256
+ wholeWord: Type5.Optional(Type5.Boolean()),
8257
+ kind: Type5.Optional(Type5.Union([Type5.Literal("files"), Type5.Literal("folders")])),
8258
+ path: Type5.Optional(Type5.String({ description: "Absolute folder to search within." })),
8259
+ sort: Type5.Optional(Type5.Union([
8260
+ Type5.Literal("name-ascending"),
8261
+ Type5.Literal("name-descending"),
8262
+ Type5.Literal("path-ascending"),
8263
+ Type5.Literal("path-descending"),
8264
+ Type5.Literal("size-ascending"),
8265
+ Type5.Literal("size-descending"),
8266
+ Type5.Literal("date-modified-ascending"),
8267
+ Type5.Literal("date-modified-descending")
8648
8268
  ])),
8649
- offset: Type6.Optional(Type6.Integer({ minimum: 0, description: "Skip this many results (pagination)." })),
8650
- maxResults: Type6.Optional(Type6.Integer({
8269
+ offset: Type5.Optional(Type5.Integer({ minimum: 0, description: "Skip this many results (pagination)." })),
8270
+ maxResults: Type5.Optional(Type5.Integer({
8651
8271
  minimum: 1,
8652
8272
  description: `Maximum results (default ${DEFAULT_MAX_RESULTS3}, cap ${MAX_RESULTS_CAP2}).`
8653
8273
  }))
@@ -8655,7 +8275,7 @@ var init_everything_search_tool = __esm(() => {
8655
8275
  });
8656
8276
 
8657
8277
  // src/agent/fast-answer-tool.ts
8658
- import { Type as Type7 } from "typebox";
8278
+ import { Type as Type6 } from "typebox";
8659
8279
  function createEmitFastAnswerTool(capture) {
8660
8280
  return {
8661
8281
  name: EMIT_FAST_ANSWER_TOOL_NAME,
@@ -8689,29 +8309,29 @@ function createEmitFastAnswerTool(capture) {
8689
8309
  }
8690
8310
  var EMIT_FAST_ANSWER_TOOL_NAME = "emit_fast_answer", fastAnswerSchema;
8691
8311
  var init_fast_answer_tool = __esm(() => {
8692
- fastAnswerSchema = Type7.Object({
8693
- answer: Type7.String({
8312
+ fastAnswerSchema = Type6.Object({
8313
+ answer: Type6.String({
8694
8314
  description: "Complete, self-contained first answer for the caller in at most 5 bullet points (plus optional explanation), produced immediately from baseline retrieval evidence. Reference results by bracketed number (e.g. [1], [2]) without file paths or raw chunk text."
8695
8315
  }),
8696
- results: Type7.Array(Type7.Object({
8697
- number: Type7.Integer({ description: "1-based result number" }),
8698
- title: Type7.String({ description: "Short name of the knowledge unit" }),
8699
- summary: Type7.String({ description: "Key insight backing the first answer" }),
8700
- evidence: Type7.Optional(Type7.Array(Type7.Object({
8701
- excerpt: Type7.String({ description: "Supporting excerpt" }),
8702
- lineNumber: Type7.Optional(Type7.Integer({ description: "Line number of the excerpt, if known" }))
8316
+ results: Type6.Array(Type6.Object({
8317
+ number: Type6.Integer({ description: "1-based result number" }),
8318
+ title: Type6.String({ description: "Short name of the knowledge unit" }),
8319
+ summary: Type6.String({ description: "Key insight backing the first answer" }),
8320
+ evidence: Type6.Optional(Type6.Array(Type6.Object({
8321
+ excerpt: Type6.String({ description: "Supporting excerpt" }),
8322
+ lineNumber: Type6.Optional(Type6.Integer({ description: "Line number of the excerpt, if known" }))
8703
8323
  }))),
8704
- confidence: Type7.Optional(Type7.Number({ description: "Confidence in this result, 0..1", minimum: 0, maximum: 1 }))
8324
+ confidence: Type6.Optional(Type6.Number({ description: "Confidence in this result, 0..1", minimum: 0, maximum: 1 }))
8705
8325
  }), { description: "Numbered knowledge units backing the first answer." }),
8706
- sources: Type7.Optional(Type7.Array(Type7.Object({
8707
- number: Type7.Integer({ description: "Matches the result number this source belongs to" }),
8708
- source: Type7.String({ description: "Source identifier — a real file path or a datasource id" })
8326
+ sources: Type6.Optional(Type6.Array(Type6.Object({
8327
+ number: Type6.Integer({ description: "Matches the result number this source belongs to" }),
8328
+ source: Type6.String({ description: "Source identifier — a real file path or a datasource id" })
8709
8329
  }), { description: "Optional number -> source mapping for the first answer." }))
8710
8330
  });
8711
8331
  });
8712
8332
 
8713
8333
  // src/agent/fsearch-search-tool.ts
8714
- import { Type as Type8 } from "typebox";
8334
+ import { Type as Type7 } from "typebox";
8715
8335
  function createFSearchSearchTool(provider) {
8716
8336
  return {
8717
8337
  name: FSEARCH_SEARCH_TOOL_NAME,
@@ -8767,27 +8387,27 @@ ${lines.join(`
8767
8387
  }
8768
8388
  var FSEARCH_SEARCH_TOOL_NAME = "fsearch_search", MAX_RESULTS_CAP3 = 1000, DEFAULT_MAX_RESULTS4 = 100, fsearchSearchSchema;
8769
8389
  var init_fsearch_search_tool = __esm(() => {
8770
- fsearchSearchSchema = Type8.Object({
8771
- query: Type8.String({
8390
+ fsearchSearchSchema = Type7.Object({
8391
+ query: Type7.String({
8772
8392
  description: 'FSearch query syntax over file and folder names: space = AND, OR keyword = OR (never the pipe |), ! = NOT, "quoted phrase", wildcards (*.pdf), ext:pdf;docx, size:>10mb, path:<fragment>, case:, regex:. When the slow-walk fallback answers (fsearch-cli not installed), only substring/regex name matching applies.'
8773
8393
  }),
8774
- regex: Type8.Optional(Type8.Boolean({ description: "Treat query as a regular expression." })),
8775
- matchCase: Type8.Optional(Type8.Boolean()),
8776
- matchPath: Type8.Optional(Type8.Boolean({ description: "Match against the full path instead of the name." })),
8777
- kind: Type8.Optional(Type8.Union([Type8.Literal("files"), Type8.Literal("folders")])),
8778
- path: Type8.Optional(Type8.String({ description: "Absolute folder to search within." })),
8779
- sort: Type8.Optional(Type8.Union([
8780
- Type8.Literal("name-ascending"),
8781
- Type8.Literal("name-descending"),
8782
- Type8.Literal("path-ascending"),
8783
- Type8.Literal("path-descending"),
8784
- Type8.Literal("size-ascending"),
8785
- Type8.Literal("size-descending"),
8786
- Type8.Literal("date-modified-ascending"),
8787
- Type8.Literal("date-modified-descending")
8394
+ regex: Type7.Optional(Type7.Boolean({ description: "Treat query as a regular expression." })),
8395
+ matchCase: Type7.Optional(Type7.Boolean()),
8396
+ matchPath: Type7.Optional(Type7.Boolean({ description: "Match against the full path instead of the name." })),
8397
+ kind: Type7.Optional(Type7.Union([Type7.Literal("files"), Type7.Literal("folders")])),
8398
+ path: Type7.Optional(Type7.String({ description: "Absolute folder to search within." })),
8399
+ sort: Type7.Optional(Type7.Union([
8400
+ Type7.Literal("name-ascending"),
8401
+ Type7.Literal("name-descending"),
8402
+ Type7.Literal("path-ascending"),
8403
+ Type7.Literal("path-descending"),
8404
+ Type7.Literal("size-ascending"),
8405
+ Type7.Literal("size-descending"),
8406
+ Type7.Literal("date-modified-ascending"),
8407
+ Type7.Literal("date-modified-descending")
8788
8408
  ])),
8789
- offset: Type8.Optional(Type8.Integer({ minimum: 0, description: "Skip this many results (pagination)." })),
8790
- maxResults: Type8.Optional(Type8.Integer({
8409
+ offset: Type7.Optional(Type7.Integer({ minimum: 0, description: "Skip this many results (pagination)." })),
8410
+ maxResults: Type7.Optional(Type7.Integer({
8791
8411
  minimum: 1,
8792
8412
  description: `Maximum results (default ${DEFAULT_MAX_RESULTS4}, cap ${MAX_RESULTS_CAP3}).`
8793
8413
  }))
@@ -8795,7 +8415,7 @@ var init_fsearch_search_tool = __esm(() => {
8795
8415
  });
8796
8416
 
8797
8417
  // src/agent/jikji-find-tool.ts
8798
- import { Type as Type9 } from "typebox";
8418
+ import { Type as Type8 } from "typebox";
8799
8419
  function createJikjiFindTool(provider) {
8800
8420
  return {
8801
8421
  name: JIKJI_FIND_TOOL_NAME,
@@ -8916,10 +8536,10 @@ function formatDirective(policy) {
8916
8536
  }
8917
8537
  var JIKJI_FIND_TOOL_NAME = "jikji_find", jikjiFindSchema;
8918
8538
  var init_jikji_find_tool = __esm(() => {
8919
- jikjiFindSchema = Type9.Object({
8920
- query: Type9.String({ description: "Query for Jikji local file discovery." }),
8921
- topK: Type9.Optional(Type9.Integer({ description: "Maximum number of answer paths / candidates to return." })),
8922
- first: Type9.Optional(Type9.Boolean({ description: "Return only the first/best answer." }))
8539
+ jikjiFindSchema = Type8.Object({
8540
+ query: Type8.String({ description: "Query for Jikji local file discovery." }),
8541
+ topK: Type8.Optional(Type8.Integer({ description: "Maximum number of answer paths / candidates to return." })),
8542
+ first: Type8.Optional(Type8.Boolean({ description: "Return only the first/best answer." }))
8923
8543
  });
8924
8544
  });
8925
8545
 
@@ -8981,7 +8601,7 @@ import {
8981
8601
  watch,
8982
8602
  writeFileSync as writeFileSync10
8983
8603
  } from "node:fs";
8984
- import { dirname as dirname11, join as join21 } from "node:path";
8604
+ import { dirname as dirname10, join as join21 } from "node:path";
8985
8605
  function requestsDir(workspacePath) {
8986
8606
  return join21(workspacePath, P2P_DIR, "requests");
8987
8607
  }
@@ -8998,7 +8618,7 @@ function isRecord11(value) {
8998
8618
  return typeof value === "object" && value !== null && !Array.isArray(value);
8999
8619
  }
9000
8620
  function atomicWrite(path, value) {
9001
- mkdirSync11(dirname11(path), { recursive: true });
8621
+ mkdirSync11(dirname10(path), { recursive: true });
9002
8622
  const tempPath = `${path}.${process.pid}.tmp`;
9003
8623
  writeFileSync10(tempPath, `${JSON.stringify(value, null, 2)}
9004
8624
  `, { mode: 384 });
@@ -9404,7 +9024,7 @@ var init_egress_gate = __esm(() => {
9404
9024
 
9405
9025
  // src/p2p/policy.ts
9406
9026
  import { existsSync as existsSync16, mkdirSync as mkdirSync12, readFileSync as readFileSync13, writeFileSync as writeFileSync11 } from "node:fs";
9407
- import { basename as basename10, dirname as dirname12, join as join22, resolve as resolve12 } from "node:path";
9027
+ import { basename as basename10, dirname as dirname11, join as join22, resolve as resolve12 } from "node:path";
9408
9028
  import { parse as parseToml } from "smol-toml";
9409
9029
  function isRecord12(value) {
9410
9030
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -9742,7 +9362,7 @@ class PolicyStore {
9742
9362
  }
9743
9363
  persistSeenSources() {
9744
9364
  try {
9745
- mkdirSync12(dirname12(this.seenSourcesPath), { recursive: true });
9365
+ mkdirSync12(dirname11(this.seenSourcesPath), { recursive: true });
9746
9366
  writeFileSync11(this.seenSourcesPath, `${JSON.stringify({
9747
9367
  sources: [...this.seenSources].sort(),
9748
9368
  pending: [...this.pendingSources].sort()
@@ -9888,57 +9508,57 @@ var init_policy = __esm(() => {
9888
9508
  });
9889
9509
 
9890
9510
  // src/p2p/wire.ts
9891
- import { Type as Type10 } from "typebox";
9511
+ import { Type as Type9 } from "typebox";
9892
9512
  var PeerRefusalCodeSchema, PeerDiagnosticSchema, PeerFileEntrySchema, PeerResultEntrySchema, PeerQueryRequestSchema, PeerQueryResponseSchema;
9893
9513
  var init_wire = __esm(() => {
9894
- PeerRefusalCodeSchema = Type10.Union([
9895
- Type10.Literal("auth-error"),
9896
- Type10.Literal("replay-rejected"),
9897
- Type10.Literal("rate-limited"),
9898
- Type10.Literal("injection-detected"),
9899
- Type10.Literal("policy-denied"),
9900
- Type10.Literal("queue-full"),
9901
- Type10.Literal("internal-error")
9514
+ PeerRefusalCodeSchema = Type9.Union([
9515
+ Type9.Literal("auth-error"),
9516
+ Type9.Literal("replay-rejected"),
9517
+ Type9.Literal("rate-limited"),
9518
+ Type9.Literal("injection-detected"),
9519
+ Type9.Literal("policy-denied"),
9520
+ Type9.Literal("queue-full"),
9521
+ Type9.Literal("internal-error")
9902
9522
  ]);
9903
- PeerDiagnosticSchema = Type10.Object({
9904
- code: Type10.String({ minLength: 1, description: "Diagnostic or refusal code" }),
9905
- message: Type10.String({ description: "Human-readable diagnostic message" })
9523
+ PeerDiagnosticSchema = Type9.Object({
9524
+ code: Type9.String({ minLength: 1, description: "Diagnostic or refusal code" }),
9525
+ message: Type9.String({ description: "Human-readable diagnostic message" })
9906
9526
  });
9907
- PeerFileEntrySchema = Type10.Object({
9908
- source: Type10.String({
9527
+ PeerFileEntrySchema = Type9.Object({
9528
+ source: Type9.String({
9909
9529
  description: "Canonical retrieval source identifier"
9910
9530
  }),
9911
- contentBase64: Type10.String({ description: "Base64-encoded file content" }),
9912
- redacted: Type10.Boolean({ description: "Whether the content was PII-redacted" })
9531
+ contentBase64: Type9.String({ description: "Base64-encoded file content" }),
9532
+ redacted: Type9.Boolean({ description: "Whether the content was PII-redacted" })
9913
9533
  });
9914
- PeerResultEntrySchema = Type10.Object({
9915
- number: Type10.Integer({ minimum: 1, description: "1-based result number" }),
9916
- title: Type10.String({ minLength: 1, description: "Short title of the result" }),
9917
- summary: Type10.String({ description: "Key insight summary" }),
9918
- source: Type10.String({
9534
+ PeerResultEntrySchema = Type9.Object({
9535
+ number: Type9.Integer({ minimum: 1, description: "1-based result number" }),
9536
+ title: Type9.String({ minLength: 1, description: "Short title of the result" }),
9537
+ summary: Type9.String({ description: "Key insight summary" }),
9538
+ source: Type9.String({
9919
9539
  description: "Canonical retrieval source identifier"
9920
9540
  }),
9921
- excerpt: Type10.String({ description: "Supporting excerpt" })
9541
+ excerpt: Type9.String({ description: "Supporting excerpt" })
9922
9542
  });
9923
- PeerQueryRequestSchema = Type10.Object({
9924
- v: Type10.Literal(1, { description: "Protocol version" }),
9925
- query: Type10.String({ minLength: 1, maxLength: 4096, description: "Search query (max 4096 chars)" }),
9926
- topK: Type10.Optional(Type10.Integer({ minimum: 1, maximum: 20, description: "Max results to return (max 20)" })),
9927
- scope: Type10.Optional(Type10.String({ description: "Optional search scope hint" }))
9543
+ PeerQueryRequestSchema = Type9.Object({
9544
+ v: Type9.Literal(1, { description: "Protocol version" }),
9545
+ query: Type9.String({ minLength: 1, maxLength: 4096, description: "Search query (max 4096 chars)" }),
9546
+ topK: Type9.Optional(Type9.Integer({ minimum: 1, maximum: 20, description: "Max results to return (max 20)" })),
9547
+ scope: Type9.Optional(Type9.String({ description: "Optional search scope hint" }))
9928
9548
  });
9929
- PeerQueryResponseSchema = Type10.Object({
9930
- v: Type10.Literal(1, { description: "Protocol version" }),
9931
- status: Type10.Union([Type10.Literal("ok"), Type10.Literal("rejected")], {
9549
+ PeerQueryResponseSchema = Type9.Object({
9550
+ v: Type9.Literal(1, { description: "Protocol version" }),
9551
+ status: Type9.Union([Type9.Literal("ok"), Type9.Literal("rejected")], {
9932
9552
  description: "Response status"
9933
9553
  }),
9934
- answer: Type10.String({ description: "Curated answer text" }),
9935
- results: Type10.Array(PeerResultEntrySchema, {
9554
+ answer: Type9.String({ description: "Curated answer text" }),
9555
+ results: Type9.Array(PeerResultEntrySchema, {
9936
9556
  description: "Curated result entries with opaque source ids"
9937
9557
  }),
9938
- files: Type10.Array(PeerFileEntrySchema, {
9558
+ files: Type9.Array(PeerFileEntrySchema, {
9939
9559
  description: "Attached original files with opaque source ids"
9940
9560
  }),
9941
- diagnostics: Type10.Array(PeerDiagnosticSchema, {
9561
+ diagnostics: Type9.Array(PeerDiagnosticSchema, {
9942
9562
  description: "Diagnostic messages (degraded-mode, rejection reasons, etc.)"
9943
9563
  })
9944
9564
  });
@@ -9947,7 +9567,7 @@ var init_wire = __esm(() => {
9947
9567
  // src/p2p/simplex-query-store.ts
9948
9568
  import { randomUUID as randomUUID6 } from "node:crypto";
9949
9569
  import { existsSync as existsSync17, mkdirSync as mkdirSync13, readdirSync as readdirSync5, readFileSync as readFileSync14, renameSync as renameSync8, unlinkSync as unlinkSync4, writeFileSync as writeFileSync12 } from "node:fs";
9950
- import { dirname as dirname13, join as join23 } from "node:path";
9570
+ import { dirname as dirname12, join as join23 } from "node:path";
9951
9571
  import { Value } from "typebox/value";
9952
9572
  function statePath(workspacePath, directory, id) {
9953
9573
  return join23(workspacePath, QUERY_DIR, directory, `${id}.json`);
@@ -9956,7 +9576,7 @@ function isRecord13(value) {
9956
9576
  return typeof value === "object" && value !== null && !Array.isArray(value);
9957
9577
  }
9958
9578
  function atomicWrite2(path, value) {
9959
- mkdirSync13(dirname13(path), { recursive: true });
9579
+ mkdirSync13(dirname12(path), { recursive: true });
9960
9580
  const tempPath = `${path}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
9961
9581
  writeFileSync12(tempPath, `${JSON.stringify(value, null, 2)}
9962
9582
  `, { mode: 384 });
@@ -10185,7 +9805,7 @@ var init_simplex_query_store = __esm(() => {
10185
9805
  // src/p2p/simplex-server.ts
10186
9806
  import { existsSync as existsSync18, mkdirSync as mkdirSync14, readFileSync as readFileSync15, writeFileSync as writeFileSync13 } from "node:fs";
10187
9807
  import { join as join24 } from "node:path";
10188
- import { Type as Type11 } from "typebox";
9808
+ import { Type as Type10 } from "typebox";
10189
9809
  import { Value as Value2 } from "typebox/value";
10190
9810
  function targetTokens(value) {
10191
9811
  return new Set((value.toLocaleLowerCase().match(TARGET_TOKEN_PATTERN) ?? []).filter((token) => token.length > 1));
@@ -10499,11 +10119,11 @@ var init_simplex_server = __esm(() => {
10499
10119
  shareBytes: false,
10500
10120
  redact: true
10501
10121
  };
10502
- SimplexWireEnvelopeSchema = Type11.Object({
10503
- v: Type11.Literal(1, { description: "Envelope version" }),
10504
- kind: Type11.Union([Type11.Literal("query"), Type11.Literal("response")], { description: "Payload kind" }),
10505
- id: Type11.String({ minLength: 1, maxLength: 128, description: "Correlation id" }),
10506
- payload: Type11.Unknown({ description: "PeerQueryRequest or PeerQueryResponse" })
10122
+ SimplexWireEnvelopeSchema = Type10.Object({
10123
+ v: Type10.Literal(1, { description: "Envelope version" }),
10124
+ kind: Type10.Union([Type10.Literal("query"), Type10.Literal("response")], { description: "Payload kind" }),
10125
+ id: Type10.String({ minLength: 1, maxLength: 128, description: "Correlation id" }),
10126
+ payload: Type10.Unknown({ description: "PeerQueryRequest or PeerQueryResponse" })
10507
10127
  });
10508
10128
  TARGET_TOKEN_PATTERN = /[\p{L}\p{N}]+/gu;
10509
10129
  PEERS_DIR = join24(".autorag", "p2p");
@@ -10516,7 +10136,7 @@ var init_simplex_server = __esm(() => {
10516
10136
  });
10517
10137
 
10518
10138
  // src/agent/peer-target-tool.ts
10519
- import { Type as Type12 } from "typebox";
10139
+ import { Type as Type11 } from "typebox";
10520
10140
  function createRecommendPeerTargetsTool(workspacePath) {
10521
10141
  return {
10522
10142
  name: RECOMMEND_PEER_TARGETS_TOOL_NAME,
@@ -10549,13 +10169,212 @@ function createRecommendPeerTargetsTool(workspacePath) {
10549
10169
  var RECOMMEND_PEER_TARGETS_TOOL_NAME = "recommend_peer_targets", recommendPeerTargetsSchema;
10550
10170
  var init_peer_target_tool = __esm(() => {
10551
10171
  init_simplex_server();
10552
- recommendPeerTargetsSchema = Type12.Object({
10553
- query: Type12.String({ description: "Question or topic to match against local peer personas." })
10172
+ recommendPeerTargetsSchema = Type11.Object({
10173
+ query: Type11.String({ description: "Question or topic to match against local peer personas." })
10174
+ });
10175
+ });
10176
+
10177
+ // src/agent/pi-session.ts
10178
+ import { join as join25 } from "node:path";
10179
+ import { streamSimple as compatStreamSimple } from "@earendil-works/pi-ai/compat";
10180
+ import {
10181
+ createAgentSession,
10182
+ createAgentSessionFromServices,
10183
+ createAgentSessionRuntime,
10184
+ createAgentSessionServices,
10185
+ DefaultResourceLoader,
10186
+ getAgentDir,
10187
+ ModelRuntime,
10188
+ SessionManager,
10189
+ SettingsManager
10190
+ } from "@earendil-works/pi-coding-agent";
10191
+ function toToolDefinition(tool) {
10192
+ return {
10193
+ name: tool.name,
10194
+ label: tool.label,
10195
+ description: tool.description,
10196
+ parameters: tool.parameters,
10197
+ ...tool.prepareArguments === undefined ? {} : { prepareArguments: tool.prepareArguments },
10198
+ execute: async (toolCallId, params, signal, onUpdate) => {
10199
+ return tool.execute(toolCallId, params, signal, onUpdate);
10200
+ }
10201
+ };
10202
+ }
10203
+ function modelConfig(model, configuredApiKey) {
10204
+ return {
10205
+ name: model.name,
10206
+ baseUrl: model.baseUrl,
10207
+ api: model.api,
10208
+ ...configuredApiKey === undefined ? {} : { apiKey: configuredApiKey },
10209
+ authHeader: false,
10210
+ streamSimple: (requestModel, context, options) => compatStreamSimple(requestModel, context, {
10211
+ ...options,
10212
+ ...configuredApiKey === EMBEDDED_AUTH_MARKER ? { apiKey: undefined } : {}
10213
+ }),
10214
+ models: [
10215
+ {
10216
+ id: model.id,
10217
+ name: model.name,
10218
+ reasoning: model.reasoning,
10219
+ input: [...model.input],
10220
+ cost: model.cost,
10221
+ contextWindow: model.contextWindow,
10222
+ maxTokens: model.maxTokens,
10223
+ ...model.thinkingLevelMap === undefined ? {} : { thinkingLevelMap: model.thinkingLevelMap }
10224
+ }
10225
+ ]
10226
+ };
10227
+ }
10228
+ async function configureModelRuntime(modelRuntime, model, apiKey, providerApiKeys) {
10229
+ if (model !== undefined) {
10230
+ const configuredKey = apiKey ?? providerApiKeys?.[model.provider];
10231
+ if (modelRuntime.getModel(model.provider, model.id) === undefined) {
10232
+ modelRuntime.registerProvider(model.provider, modelConfig(model, configuredKey ?? EMBEDDED_AUTH_MARKER));
10233
+ }
10234
+ }
10235
+ const keys = new Map;
10236
+ if (model !== undefined && apiKey !== undefined)
10237
+ keys.set(model.provider, apiKey);
10238
+ for (const [provider, key] of Object.entries(providerApiKeys ?? {}))
10239
+ keys.set(provider, key);
10240
+ for (const [provider, key] of keys)
10241
+ await modelRuntime.setRuntimeApiKey(provider, key);
10242
+ }
10243
+ function createAutoRAGExtension(getSystemPrompt, contextTransform) {
10244
+ return (pi) => {
10245
+ pi.on("before_agent_start", () => ({ systemPrompt: getSystemPrompt() }));
10246
+ if (contextTransform !== undefined) {
10247
+ pi.on("context", async (event) => ({ messages: await contextTransform(event.messages) }));
10248
+ }
10249
+ };
10250
+ }
10251
+ function createAutoRAGInteractiveExtension(getSystemPrompt, contextTransform, onQuery) {
10252
+ return (pi) => {
10253
+ pi.on("before_agent_start", () => ({ systemPrompt: getSystemPrompt() }));
10254
+ if (contextTransform !== undefined) {
10255
+ pi.on("context", async (event) => ({ messages: await contextTransform(event.messages) }));
10256
+ }
10257
+ pi.on("input", async (event) => {
10258
+ const query = event.text.trim();
10259
+ if (event.source !== "interactive" || query.length === 0 || query.startsWith("/"))
10260
+ return;
10261
+ try {
10262
+ await onQuery(query, pi);
10263
+ } catch (error) {
10264
+ pi.sendMessage({
10265
+ customType: "autorag.error",
10266
+ content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
10267
+ display: true
10268
+ });
10269
+ }
10270
+ return { action: "handled" };
10271
+ });
10272
+ };
10273
+ }
10274
+ async function createAutoRAGPiSession(options) {
10275
+ const agentDir = options.agentDir ?? getAgentDir();
10276
+ const settingsManager = SettingsManager.create(options.cwd, agentDir);
10277
+ if (settingsManager.getDefaultTools() === undefined) {
10278
+ settingsManager.applyOverrides({ defaultTools: [...PI_BUILTIN_TOOL_NAMES] });
10279
+ }
10280
+ const modelRuntime = await ModelRuntime.create({
10281
+ authPath: join25(agentDir, "auth.json"),
10282
+ modelsPath: join25(agentDir, "models.json")
10283
+ });
10284
+ await configureModelRuntime(modelRuntime, options.model, options.apiKey, options.providerApiKeys);
10285
+ const customTools = [...options.customTools];
10286
+ const resourceLoader = new DefaultResourceLoader({
10287
+ cwd: options.cwd,
10288
+ agentDir,
10289
+ settingsManager,
10290
+ extensionFactories: [createAutoRAGExtension(options.getSystemPrompt, options.contextTransform)],
10291
+ systemPromptOverride: () => options.getSystemPrompt(),
10292
+ appendSystemPromptOverride: () => []
10293
+ });
10294
+ await resourceLoader.reload();
10295
+ const sessionManager = options.sessionPath ? SessionManager.open(options.sessionPath, options.sessionDir, options.cwd) : options.persistSession ? SessionManager.create(options.cwd, options.sessionDir) : SessionManager.inMemory(options.cwd);
10296
+ const customToolNames = customTools.map((tool) => tool.name);
10297
+ const customToolDefinitions = customTools.map(toToolDefinition);
10298
+ const { session } = await createAgentSession({
10299
+ cwd: options.cwd,
10300
+ agentDir,
10301
+ modelRuntime,
10302
+ settingsManager,
10303
+ resourceLoader,
10304
+ sessionManager,
10305
+ model: options.model,
10306
+ customTools: customToolDefinitions,
10307
+ tools: [...PI_BUILTIN_TOOL_NAMES, ...customToolNames],
10308
+ excludeTools: options.remoteSession ? ["edit", "write", "powershell"] : undefined,
10309
+ thinkingLevel: "off"
10310
+ });
10311
+ const initialToolNames = [...new Set([...session.getActiveToolNames(), ...customToolNames])];
10312
+ session.setActiveToolsByName(initialToolNames);
10313
+ return {
10314
+ session,
10315
+ baseToolNames: initialToolNames,
10316
+ sessionFile: session.sessionFile
10317
+ };
10318
+ }
10319
+ async function createAutoRAGPiInteractiveRuntime(options) {
10320
+ const agentDir = options.agentDir ?? getAgentDir();
10321
+ const settingsManager = SettingsManager.create(options.cwd, agentDir);
10322
+ if (settingsManager.getDefaultTools() === undefined) {
10323
+ settingsManager.applyOverrides({ defaultTools: [...PI_BUILTIN_TOOL_NAMES] });
10324
+ }
10325
+ const modelRuntime = await ModelRuntime.create({
10326
+ authPath: join25(agentDir, "auth.json"),
10327
+ modelsPath: join25(agentDir, "models.json")
10554
10328
  });
10329
+ await configureModelRuntime(modelRuntime, options.model, options.apiKey, options.providerApiKeys);
10330
+ const sessionManager = options.sessionPath ? SessionManager.open(options.sessionPath, options.sessionDir, options.cwd) : SessionManager.create(options.cwd, options.sessionDir);
10331
+ const createRuntime = async ({
10332
+ cwd,
10333
+ agentDir: runtimeAgentDir,
10334
+ sessionManager: runtimeSessionManager,
10335
+ sessionStartEvent
10336
+ }) => {
10337
+ const services = await createAgentSessionServices({
10338
+ cwd,
10339
+ agentDir: runtimeAgentDir,
10340
+ modelRuntime,
10341
+ settingsManager,
10342
+ resourceLoaderOptions: {
10343
+ extensionFactories: [
10344
+ createAutoRAGInteractiveExtension(options.getSystemPrompt, options.contextTransform, options.onQuery)
10345
+ ],
10346
+ systemPrompt: options.getSystemPrompt(),
10347
+ appendSystemPrompt: []
10348
+ }
10349
+ });
10350
+ const result = await createAgentSessionFromServices({
10351
+ services,
10352
+ sessionManager: runtimeSessionManager,
10353
+ sessionStartEvent,
10354
+ customTools: options.customTools.map(toToolDefinition),
10355
+ tools: [...PI_BUILTIN_TOOL_NAMES, ...options.customTools.map((tool) => tool.name)],
10356
+ excludeTools: options.remoteSession ? ["edit", "write", "powershell"] : undefined
10357
+ });
10358
+ if (options.inactiveToolNames !== undefined && options.inactiveToolNames.length > 0) {
10359
+ const inactive = new Set(options.inactiveToolNames);
10360
+ result.session.setActiveToolsByName(result.session.getActiveToolNames().filter((name) => !inactive.has(name)));
10361
+ }
10362
+ return { ...result, services, diagnostics: services.diagnostics };
10363
+ };
10364
+ const runtime = await createAgentSessionRuntime(createRuntime, {
10365
+ cwd: options.cwd,
10366
+ agentDir,
10367
+ sessionManager
10368
+ });
10369
+ return { runtime, dispose: () => runtime.dispose() };
10370
+ }
10371
+ var PI_BUILTIN_TOOL_NAMES, EMBEDDED_AUTH_MARKER = "<autorag-embedded-model>";
10372
+ var init_pi_session = __esm(() => {
10373
+ PI_BUILTIN_TOOL_NAMES = ["read", "bash", "edit", "write", "grep", "find", "ls"];
10555
10374
  });
10556
10375
 
10557
10376
  // src/agent/query-peer-tool.ts
10558
- import { Type as Type13 } from "typebox";
10377
+ import { Type as Type12 } from "typebox";
10559
10378
  function failure(alias, message) {
10560
10379
  const details = { method: "query_peer_agent", ok: false, alias, message };
10561
10380
  return { content: [{ type: "text", text: message }], details };
@@ -10660,18 +10479,18 @@ var QUERY_PEER_AGENT_TOOL_NAME = "query_peer_agent", queryPeerAgentSchema;
10660
10479
  var init_query_peer_tool = __esm(() => {
10661
10480
  init_simplex_query_store();
10662
10481
  init_simplex_server();
10663
- queryPeerAgentSchema = Type13.Object({
10664
- alias: Type13.String({ minLength: 1 }),
10665
- query: Type13.String({ minLength: 1, maxLength: 4096 }),
10666
- topK: Type13.Optional(Type13.Integer({ minimum: 1, maximum: 20 })),
10667
- scope: Type13.Optional(Type13.String())
10482
+ queryPeerAgentSchema = Type12.Object({
10483
+ alias: Type12.String({ minLength: 1 }),
10484
+ query: Type12.String({ minLength: 1, maxLength: 4096 }),
10485
+ topK: Type12.Optional(Type12.Integer({ minimum: 1, maximum: 20 })),
10486
+ scope: Type12.Optional(Type12.String())
10668
10487
  });
10669
10488
  });
10670
10489
 
10671
10490
  // src/agent/refresh-progress.ts
10672
10491
  import { randomUUID as randomUUID7 } from "node:crypto";
10673
10492
  import { mkdirSync as mkdirSync15, readFileSync as readFileSync16, renameSync as renameSync9, rmSync as rmSync6, writeFileSync as writeFileSync14 } from "node:fs";
10674
- import { dirname as dirname14 } from "node:path";
10493
+ import { dirname as dirname13 } from "node:path";
10675
10494
  function readRefreshProgress(root) {
10676
10495
  try {
10677
10496
  const parsed = JSON.parse(readFileSync16(refreshProgressPath(root), "utf8"));
@@ -10685,7 +10504,7 @@ function readRefreshProgress(root) {
10685
10504
  }
10686
10505
  function writeRefreshProgress(root, progress) {
10687
10506
  const path = refreshProgressPath(root);
10688
- mkdirSync15(dirname14(path), { recursive: true });
10507
+ mkdirSync15(dirname13(path), { recursive: true });
10689
10508
  const temporaryPath = `${path}.${randomUUID7()}.tmp`;
10690
10509
  try {
10691
10510
  writeFileSync14(temporaryPath, `${JSON.stringify(progress, null, 2)}
@@ -10908,7 +10727,7 @@ var init_search_documents = __esm(() => {
10908
10727
  });
10909
10728
 
10910
10729
  // src/agent/search-all-tool.ts
10911
- import { Type as Type14 } from "typebox";
10730
+ import { Type as Type13 } from "typebox";
10912
10731
  function createSearchAllDocumentsTool(provider) {
10913
10732
  return {
10914
10733
  name: SEARCH_ALL_DOCUMENTS_TOOL_NAME,
@@ -10961,17 +10780,17 @@ ${rows.join(`
10961
10780
  var SEARCH_ALL_DOCUMENTS_TOOL_NAME = "search_all_documents", searchAllSchema;
10962
10781
  var init_search_all_tool = __esm(() => {
10963
10782
  init_search_documents();
10964
- searchAllSchema = Type14.Object({
10965
- query: Type14.String({ description: "Query to search across all configured retrieval methods." }),
10966
- topK: Type14.Optional(Type14.Integer({
10783
+ searchAllSchema = Type13.Object({
10784
+ query: Type13.String({ description: "Query to search across all configured retrieval methods." }),
10785
+ topK: Type13.Optional(Type13.Integer({
10967
10786
  description: "Upper bound on returned evidence. Omit it to receive every distinct chunk the methods found; set it only when you deliberately want a shorter list."
10968
10787
  })),
10969
- scope: Type14.Optional(Type14.String({ description: "Optional opaque virtual-path scope, e.g. /docs or /docs/**." }))
10788
+ scope: Type13.Optional(Type13.String({ description: "Optional opaque virtual-path scope, e.g. /docs or /docs/**." }))
10970
10789
  });
10971
10790
  });
10972
10791
 
10973
10792
  // src/agent/search-minsync-tool.ts
10974
- import { Type as Type15 } from "typebox";
10793
+ import { Type as Type14 } from "typebox";
10975
10794
  function createSearchMinSyncDocumentsTool(getMethod, resolveScope = (scope) => scope) {
10976
10795
  return {
10977
10796
  name: SEARCH_MINSYNC_DOCUMENTS_TOOL_NAME,
@@ -11042,12 +10861,12 @@ ${rows.join(`
11042
10861
  var SEARCH_MINSYNC_DOCUMENTS_TOOL_NAME = "semantic_search_local_docs", searchMinSyncSchema;
11043
10862
  var init_search_minsync_tool = __esm(() => {
11044
10863
  init_search_documents();
11045
- searchMinSyncSchema = Type15.Object({
11046
- query: Type15.String({
10864
+ searchMinSyncSchema = Type14.Object({
10865
+ query: Type14.String({
11047
10866
  description: "Semantic query to search parsed document mirrors with MinSync vector retrieval."
11048
10867
  }),
11049
- topK: Type15.Optional(Type15.Integer({ description: "Maximum number of MinSync semantic chunks to return. Defaults to 50." })),
11050
- scope: Type15.Optional(Type15.String({ description: "Optional opaque virtual-path scope, e.g. /docs or /docs/**." }))
10868
+ topK: Type14.Optional(Type14.Integer({ description: "Maximum number of MinSync semantic chunks to return. Defaults to 50." })),
10869
+ scope: Type14.Optional(Type14.String({ description: "Optional opaque virtual-path scope, e.g. /docs or /docs/**." }))
11051
10870
  });
11052
10871
  });
11053
10872
 
@@ -11065,7 +10884,7 @@ function datasourceSearchToolName(datasourceId) {
11065
10884
  }
11066
10885
 
11067
10886
  // src/agent/search-single-datasource-tool.ts
11068
- import { Type as Type16 } from "typebox";
10887
+ import { Type as Type15 } from "typebox";
11069
10888
  function createSingleDatasourceSearchTools(provider, specs) {
11070
10889
  return specs.map((spec) => createTool(provider, spec));
11071
10890
  }
@@ -11129,10 +10948,10 @@ var singleDatasourceToolName, searchSingleDatasourceSchema;
11129
10948
  var init_search_single_datasource_tool = __esm(() => {
11130
10949
  init_search_documents();
11131
10950
  singleDatasourceToolName = datasourceSearchToolName;
11132
- searchSingleDatasourceSchema = Type16.Object({
11133
- query: Type16.String({ description: "Query to search within this datasource connection." }),
11134
- topK: Type16.Optional(Type16.Integer({ description: "Maximum number of chunks to return. Defaults to 50." })),
11135
- scope: Type16.Optional(Type16.String({ description: "Optional scope narrowing inside this datasource, e.g. one instance root." }))
10951
+ searchSingleDatasourceSchema = Type15.Object({
10952
+ query: Type15.String({ description: "Query to search within this datasource connection." }),
10953
+ topK: Type15.Optional(Type15.Integer({ description: "Maximum number of chunks to return. Defaults to 50." })),
10954
+ scope: Type15.Optional(Type15.String({ description: "Optional scope narrowing inside this datasource, e.g. one instance root." }))
11136
10955
  });
11137
10956
  });
11138
10957
 
@@ -11645,7 +11464,7 @@ var init_url_target = __esm(() => {
11645
11464
  // src/web/fetch/convert.ts
11646
11465
  import { mkdtemp as mkdtemp2, rm as rm3, writeFile as writeFile3 } from "node:fs/promises";
11647
11466
  import { tmpdir as tmpdir2 } from "node:os";
11648
- import { join as join25 } from "node:path";
11467
+ import { join as join26 } from "node:path";
11649
11468
  function combineSignals2(signal, timeoutMs) {
11650
11469
  if (!signal)
11651
11470
  return AbortSignal.timeout(timeoutMs);
@@ -11721,8 +11540,8 @@ async function convertBinaryPayload(buffer, extension, _finalUrl, signal) {
11721
11540
  if (!parser) {
11722
11541
  return { content: "", ok: false, error: `No parser registered for ${ext}` };
11723
11542
  }
11724
- const tempDir = await mkdtemp2(join25(tmpdir2(), "autorag-fetch-"));
11725
- const tempPath = join25(tempDir, `payload${ext}`);
11543
+ const tempDir = await mkdtemp2(join26(tmpdir2(), "autorag-fetch-"));
11544
+ const tempPath = join26(tempDir, `payload${ext}`);
11726
11545
  try {
11727
11546
  await writeFile3(tempPath, buffer);
11728
11547
  const input = {
@@ -13281,7 +13100,7 @@ var init_render = __esm(() => {
13281
13100
  });
13282
13101
 
13283
13102
  // src/agent/web-fetch-tool.ts
13284
- import { Type as Type17 } from "typebox";
13103
+ import { Type as Type16 } from "typebox";
13285
13104
  function truncateHead(output, maxBytes, maxLines) {
13286
13105
  const lines = output.split(`
13287
13106
  `);
@@ -13378,9 +13197,9 @@ var WEB_FETCH_TOOL_NAME = "web_fetch", FETCH_DEFAULT_MAX_LINES = 300, FETCH_MAX_
13378
13197
  var init_web_fetch_tool = __esm(() => {
13379
13198
  init_render();
13380
13199
  FETCH_MAX_OUTPUT_BYTES = 50 * 1024;
13381
- webFetchSchema = Type17.Object({
13382
- url: Type17.String({ description: "The http(s) URL to fetch and read." }),
13383
- raw: Type17.Optional(Type17.Boolean({ description: "Return the raw response body without markdown rendering or formatting." }))
13200
+ webFetchSchema = Type16.Object({
13201
+ url: Type16.String({ description: "The http(s) URL to fetch and read." }),
13202
+ raw: Type16.Optional(Type16.Boolean({ description: "Return the raw response body without markdown rendering or formatting." }))
13384
13203
  });
13385
13204
  });
13386
13205
 
@@ -16900,7 +16719,7 @@ var init_search = __esm(() => {
16900
16719
  });
16901
16720
 
16902
16721
  // src/agent/web-search-tool.ts
16903
- import { Type as Type18 } from "typebox";
16722
+ import { Type as Type17 } from "typebox";
16904
16723
  function createWebSearchTool(options = {}) {
16905
16724
  return {
16906
16725
  name: WEB_SEARCH_TOOL_NAME,
@@ -16970,24 +16789,23 @@ function createWebSearchTool(options = {}) {
16970
16789
  var WEB_SEARCH_TOOL_NAME = "web_search", webSearchSchema;
16971
16790
  var init_web_search_tool = __esm(() => {
16972
16791
  init_search();
16973
- webSearchSchema = Type18.Object({
16974
- query: Type18.String({
16792
+ webSearchSchema = Type17.Object({
16793
+ query: Type17.String({
16975
16794
  description: 'Search query. Supports Google-style directives: site:/-site:, after:/before: (YYYY-MM-DD), inurl:, intitle:, filetype:, "exact phrase", -term, OR.'
16976
16795
  }),
16977
- recency: Type18.Optional(Type18.Union([Type18.Literal("day"), Type18.Literal("week"), Type18.Literal("month"), Type18.Literal("year")], {
16796
+ recency: Type17.Optional(Type17.Union([Type17.Literal("day"), Type17.Literal("week"), Type17.Literal("month"), Type17.Literal("year")], {
16978
16797
  description: "Optional recency window for results (pure time filter)."
16979
16798
  })),
16980
- limit: Type18.Optional(Type18.Integer({ description: "Maximum number of results to return." })),
16981
- num_search_results: Type18.Optional(Type18.Integer({ description: "Alias for limit (result count hint)." }))
16799
+ limit: Type17.Optional(Type17.Integer({ description: "Maximum number of results to return." })),
16800
+ num_search_results: Type17.Optional(Type17.Integer({ description: "Alias for limit (result count hint)." }))
16982
16801
  });
16983
16802
  });
16984
16803
 
16985
16804
  // src/agent/agent.ts
16986
16805
  import { randomUUID as randomUUID8 } from "node:crypto";
16987
16806
  import { existsSync as existsSync20, watch as fsWatch, mkdirSync as mkdirSync16, realpathSync as realpathSync5, statSync, writeFileSync as writeFileSync15 } from "node:fs";
16988
- import { basename as basename11, dirname as dirname15, join as join26, resolve as resolve13 } from "node:path";
16989
- import { Agent } from "@earendil-works/pi-agent-core";
16990
- import { clampThinkingLevel, streamSimple } from "@earendil-works/pi-ai/compat";
16807
+ import { basename as basename11, dirname as dirname14, join as join27, resolve as resolve13 } from "node:path";
16808
+ import { clampThinkingLevel } from "@earendil-works/pi-ai/compat";
16991
16809
  function hasSearchEvidence(toolName, details, isError) {
16992
16810
  if (isError || details === null || typeof details !== "object")
16993
16811
  return false;
@@ -17004,9 +16822,6 @@ function hasSearchEvidence(toolName, details, isError) {
17004
16822
  }
17005
16823
  return Array.isArray(outcome.sources) && outcome.sources.some((source) => typeof source === "string" && source.trim().length > 0) || Array.isArray(outcome.results) && outcome.results.some((result) => result !== null && typeof result === "object" && typeof result.source === "string" && result.source.trim().length > 0);
17006
16824
  }
17007
- function keepLlmMessages(messages) {
17008
- return messages.filter((message) => message.role === "system" || message.role === "user" || message.role === "assistant" || message.role === "toolResult");
17009
- }
17010
16825
  function positiveLimit(value, fallback, path) {
17011
16826
  if (value === undefined)
17012
16827
  return fallback;
@@ -17047,6 +16862,7 @@ class AutoRAGAgent {
17047
16862
  sessions = new Map;
17048
16863
  activeRun = false;
17049
16864
  resultCapture;
16865
+ interactiveFastAnswerCallback;
17050
16866
  modelNativeSearchAuth;
17051
16867
  retrievalTrace = [];
17052
16868
  preliminaryCallback;
@@ -17095,6 +16911,10 @@ class AutoRAGAgent {
17095
16911
  droppedCallerToolNames;
17096
16912
  searchTimeoutMs;
17097
16913
  maxSearchToolCalls;
16914
+ piAgentDir;
16915
+ piSessionDir;
16916
+ persistPiSessions;
16917
+ boundPiRuntime;
17098
16918
  remoteSession;
17099
16919
  activeRetrievalOptions;
17100
16920
  searchToolCallCount = 0;
@@ -17116,6 +16936,9 @@ class AutoRAGAgent {
17116
16936
  this.finalThinkingLevel = thinking === false ? undefined : thinking?.final ?? "high";
17117
16937
  this.apiKey = options.apiKey;
17118
16938
  this.providerApiKeys = options.providerApiKeys;
16939
+ this.piAgentDir = options.piAgentDir;
16940
+ this.piSessionDir = options.piSessionDir;
16941
+ this.persistPiSessions = options.persistPiSessions ?? true;
17119
16942
  const manifests = manifestDir ? loadManifests(manifestDir) : [];
17120
16943
  this.datasourceSkills = options.datasourceSkills ?? [];
17121
16944
  this.datasourceVirtualScopePrefixes = this.datasourceSkills.map((skill) => normalizeVirtualPath2(`/${skill.describe().name}`));
@@ -17176,10 +16999,10 @@ class AutoRAGAgent {
17176
16999
  if (fsearchClient.isSupported())
17177
17000
  this.fsearchClient = fsearchClient;
17178
17001
  }
17179
- const memPath = memoryPath ?? join26(resolveAutoRAGHome(), "memory.json");
17002
+ const memPath = memoryPath ?? join27(resolveAutoRAGHome(), "memory.json");
17180
17003
  this.memory = new RetrievalMemory({ storagePath: memPath });
17181
17004
  this.memory.load();
17182
- this.runLogger = new AutoRAGRunLogger(join26(dirname15(memPath), "logs", "runs.jsonl"));
17005
+ this.runLogger = new AutoRAGRunLogger(join27(dirname14(memPath), "logs", "runs.jsonl"));
17183
17006
  const checkMemoryTool = createCheckMemoryTool(this.memory);
17184
17007
  const singleDatasourceTools = createSingleDatasourceSearchTools(this, this.singleDatasourceToolSpecs());
17185
17008
  this.searchToolNames = new Set([...SEARCH_TOOLS, ...singleDatasourceTools.map((tool) => tool.name)]);
@@ -17188,16 +17011,13 @@ class AutoRAGAgent {
17188
17011
  const loadDatasourceSkillTool = createLoadDatasourceSkillTool(this);
17189
17012
  const emitResultsTool = createEmitResultsTool((details) => this.resultCapture?.(details));
17190
17013
  const scanDuplicateDocumentsTool = this.dupeyOptions === false ? undefined : createScanDuplicateDocumentsTool(this);
17191
- const bashTool = createBashTool({
17192
- cwd: this.workspaceProjectRoot
17193
- });
17194
17014
  const peerTargetTool = this.remoteSession ? undefined : createRecommendPeerTargetsTool(this.workspaceProjectRoot);
17195
17015
  const peerQuery = options.peerQuery;
17196
17016
  const queryPeerTool = this.remoteSession || peerQuery === undefined || peerQuery === false ? undefined : createQueryPeerAgentTool({
17197
17017
  workspacePath: this.workspaceProjectRoot,
17198
17018
  onResponse: peerQuery?.onResponse,
17199
17019
  openTransport: peerQuery?.openTransport ?? (() => openPeerQueryTransport({
17200
- dbPrefix: peerQuery?.simplexDbPrefix ?? join26(this.workspaceProjectRoot, ".autorag", "p2p", "simplex"),
17020
+ dbPrefix: peerQuery?.simplexDbPrefix ?? join27(this.workspaceProjectRoot, ".autorag", "p2p", "simplex"),
17201
17021
  displayName: `autorag-${basename11(this.workspaceProjectRoot) || "node"}`
17202
17022
  })),
17203
17023
  autoStart: true,
@@ -17211,7 +17031,7 @@ class AutoRAGAgent {
17211
17031
  const webSearchTool = webToolsEnabled ? createWebSearchTool({ ...webSearchOption ?? {}, modelAuth: () => this.modelNativeSearchAuth }) : undefined;
17212
17032
  const webFetchTool = webToolsEnabled && webSearchOption?.fetch !== false ? createWebFetchTool(webSearchOption?.fetch ?? {}) : undefined;
17213
17033
  const reservedNames = new Set([
17214
- BASH_TOOL_NAME,
17034
+ ...PI_BUILTIN_TOOL_NAMES,
17215
17035
  "check_memory",
17216
17036
  ...singleDatasourceTools.map((tool) => tool.name),
17217
17037
  LOAD_DATASOURCE_SKILL_TOOL_NAME,
@@ -17238,7 +17058,6 @@ class AutoRAGAgent {
17238
17058
  });
17239
17059
  this.droppedCallerToolNames = [...new Set(droppedCallerToolNames)];
17240
17060
  const orderedTools = [
17241
- ...bashTool !== undefined ? [bashTool] : [],
17242
17061
  ...callerTools,
17243
17062
  checkMemoryTool,
17244
17063
  searchMinSyncTool,
@@ -17263,7 +17082,7 @@ class AutoRAGAgent {
17263
17082
  return true;
17264
17083
  });
17265
17084
  this.tools = tools;
17266
- const toolNames = tools.map((tool) => tool.name);
17085
+ const toolNames = [...PI_BUILTIN_TOOL_NAMES, ...tools.map((tool) => tool.name)];
17267
17086
  this.baseSystemPromptConfig = {
17268
17087
  toolNames,
17269
17088
  modelId: options.model?.id,
@@ -17274,28 +17093,14 @@ class AutoRAGAgent {
17274
17093
  retrievedContentGuard: false
17275
17094
  };
17276
17095
  const systemPrompt = buildSystemPrompt(this.currentSystemPromptConfig());
17277
- this.innerAgent = new Agent({
17278
- initialState: {
17096
+ this.innerAgent = {
17097
+ state: {
17279
17098
  systemPrompt,
17280
- model: options.model,
17281
- tools
17099
+ tools: [...PI_BUILTIN_TOOL_NAMES.map((name) => ({ name })), ...tools],
17100
+ messages: []
17282
17101
  },
17283
- streamFn: streamSimple,
17284
- convertToLlm: keepLlmMessages,
17285
- transformContext: async (messages) => this.withMemoryContext(messages),
17286
- afterToolCall: async (context) => {
17287
- const toolName = context.toolCall.name;
17288
- if (!this.lastQuery || !this.searchToolNames.has(toolName))
17289
- return;
17290
- if (!hasSearchEvidence(toolName, context.result.details, context.isError))
17291
- return;
17292
- const details = context.result.details;
17293
- const method = details?.method ?? toolName;
17294
- this.memory.recordWeakSignal(this.lastQuery, method, "followup");
17295
- this.memory.save();
17296
- return;
17297
- }
17298
- });
17102
+ transformContext: (messages) => this.withMemoryContext(messages)
17103
+ };
17299
17104
  if (options.autoRefresh) {
17300
17105
  this.startAutoRefresh(options.autoRefresh.intervalMs, { immediate: options.autoRefresh.immediate });
17301
17106
  }
@@ -17336,7 +17141,16 @@ ${summary}
17336
17141
  ...messages
17337
17142
  ];
17338
17143
  }
17339
- resolveSessionModel() {
17144
+ async resolveSessionModel() {
17145
+ const boundModel = this.boundPiRuntime?.session.model;
17146
+ if (boundModel !== undefined) {
17147
+ const auth = await this.boundPiRuntime?.session.modelRuntime.getAuth(boundModel);
17148
+ const apiKey = auth?.auth.apiKey;
17149
+ return {
17150
+ model: boundModel,
17151
+ ...apiKey !== undefined ? { apiKey, providerApiKeys: { [boundModel.provider]: apiKey } } : {}
17152
+ };
17153
+ }
17340
17154
  if (this.configuredModel !== undefined) {
17341
17155
  return {
17342
17156
  model: this.configuredModel,
@@ -17351,19 +17165,40 @@ ${summary}
17351
17165
  providerApiKeys: { [local.provider]: local.apiKey }
17352
17166
  };
17353
17167
  }
17354
- createSearchSession(resolved, systemPrompt) {
17355
- const agent = new Agent({
17356
- initialState: { systemPrompt, model: resolved.model, tools: [...this.tools] },
17357
- streamFn: streamSimple,
17358
- getApiKey: (provider) => resolved.providerApiKeys?.[provider] ?? (provider === resolved.model.provider ? resolved.apiKey : undefined),
17359
- convertToLlm: keepLlmMessages,
17360
- transformContext: async (messages) => this.withMemoryContext(messages)
17168
+ async createSearchSession(resolved, systemPrompt, extraTools = []) {
17169
+ if (this.boundPiRuntime !== undefined) {
17170
+ const session = this.boundPiRuntime.session;
17171
+ return {
17172
+ agent: session.agent,
17173
+ piSession: session,
17174
+ prompt: async (prompt) => session.prompt(prompt, { source: "extension" }),
17175
+ abort: async () => session.abort(),
17176
+ dispose: () => {}
17177
+ };
17178
+ }
17179
+ const piSession = await createAutoRAGPiSession({
17180
+ cwd: this.workspaceProjectRoot,
17181
+ agentDir: this.piAgentDir,
17182
+ sessionDir: this.piSessionDir,
17183
+ persistSession: this.persistPiSessions,
17184
+ model: resolved.model,
17185
+ apiKey: resolved.apiKey,
17186
+ providerApiKeys: resolved.providerApiKeys,
17187
+ getSystemPrompt: () => systemPrompt,
17188
+ customTools: [
17189
+ ...this.tools.filter((tool) => !PI_BUILTIN_TOOL_NAMES.includes(tool.name)),
17190
+ ...extraTools
17191
+ ],
17192
+ remoteSession: this.remoteSession,
17193
+ contextTransform: (messages) => this.withMemoryContext(messages)
17361
17194
  });
17195
+ const agent = piSession.session.agent;
17362
17196
  return {
17363
17197
  agent,
17364
- prompt: async (prompt) => agent.prompt(prompt),
17365
- abort: async () => agent.abort(),
17366
- dispose: () => {}
17198
+ piSession: piSession.session,
17199
+ prompt: async (prompt) => piSession.session.prompt(prompt, { source: "extension" }),
17200
+ abort: async () => piSession.session.abort(),
17201
+ dispose: () => piSession.session.dispose()
17367
17202
  };
17368
17203
  }
17369
17204
  configureSearchSession(session) {
@@ -17414,6 +17249,55 @@ ${summary}
17414
17249
  this.listeners.delete(listener);
17415
17250
  };
17416
17251
  }
17252
+ async createPiInteractiveRuntime() {
17253
+ const resolved = this.configuredModel === undefined ? undefined : await this.resolveSessionModel();
17254
+ const runtime = await createAutoRAGPiInteractiveRuntime({
17255
+ cwd: this.workspaceProjectRoot,
17256
+ agentDir: this.piAgentDir,
17257
+ sessionDir: this.piSessionDir,
17258
+ persistSession: this.persistPiSessions,
17259
+ ...resolved === undefined ? {} : {
17260
+ model: resolved.model,
17261
+ ...resolved.apiKey !== undefined ? { apiKey: resolved.apiKey } : {},
17262
+ ...resolved.providerApiKeys !== undefined ? { providerApiKeys: resolved.providerApiKeys } : {}
17263
+ },
17264
+ getSystemPrompt: () => buildSystemPrompt(this.currentSystemPromptConfig({
17265
+ modelId: this.boundPiRuntime?.session.model?.id ?? resolved?.model.id
17266
+ })),
17267
+ contextTransform: (messages) => this.withMemoryContext(messages),
17268
+ customTools: [
17269
+ ...this.tools.filter((tool) => !PI_BUILTIN_TOOL_NAMES.includes(tool.name)),
17270
+ ...this.fastThinkingLevel === undefined ? [] : [createEmitFastAnswerTool((details) => this.interactiveFastAnswerCallback?.(details))]
17271
+ ],
17272
+ onQuery: (query, pi) => this.runInteractivePiQuery(query, pi),
17273
+ inactiveToolNames: this.fastThinkingLevel === undefined ? [] : [EMIT_FAST_ANSWER_TOOL_NAME]
17274
+ });
17275
+ this.boundPiRuntime = runtime.runtime;
17276
+ if (this.fastThinkingLevel !== undefined) {
17277
+ runtime.runtime.session.setActiveToolsByName(runtime.runtime.session.getActiveToolNames().filter((name) => name !== EMIT_FAST_ANSWER_TOOL_NAME));
17278
+ }
17279
+ const dispose = runtime.dispose;
17280
+ return {
17281
+ ...runtime,
17282
+ dispose: async () => {
17283
+ if (this.boundPiRuntime === runtime.runtime)
17284
+ this.boundPiRuntime = undefined;
17285
+ await dispose();
17286
+ }
17287
+ };
17288
+ }
17289
+ async runInteractivePiQuery(query, pi) {
17290
+ pi.setSessionName(query.slice(0, 80));
17291
+ for await (const event of this.searchDocumentsStream(query)) {
17292
+ const text = event.type === "progress" ? event.text : event.response.answer;
17293
+ pi.sendMessage({
17294
+ customType: `autorag.${event.type}`,
17295
+ content: [{ type: "text", text }],
17296
+ display: true,
17297
+ details: event
17298
+ });
17299
+ }
17300
+ }
17417
17301
  abort() {
17418
17302
  this.activeSession?.abort();
17419
17303
  }
@@ -17496,14 +17380,21 @@ ${summary}
17496
17380
  this.scheduleMinSyncPrepare();
17497
17381
  let captured;
17498
17382
  let fastCaptured;
17383
+ const emitPreliminary = (details) => {
17384
+ if (fastCaptured !== undefined)
17385
+ return;
17386
+ fastCaptured = details;
17387
+ this.preliminaryCallback?.(createPreliminarySearchDocumentsResponse(sessionId, trimmedQuery, details, this.collectComponentDiagnostics()));
17388
+ };
17499
17389
  let session;
17390
+ this.interactiveFastAnswerCallback = emitPreliminary;
17500
17391
  let unsubscribers = [];
17501
17392
  this.resultCapture = (details) => {
17502
17393
  captured = details;
17503
17394
  };
17504
17395
  let searchStarted = false;
17505
17396
  try {
17506
- const resolved = this.resolveSessionModel();
17397
+ const resolved = await this.resolveSessionModel();
17507
17398
  this.modelNativeSearchAuth = modelNativeAuthFromAgentModel({
17508
17399
  provider: resolved.model.provider,
17509
17400
  ...resolved.apiKey !== undefined ? { apiKey: resolved.apiKey } : {},
@@ -17518,7 +17409,7 @@ ${summary}
17518
17409
  model: resolved.model.id
17519
17410
  });
17520
17411
  searchStarted = true;
17521
- session = this.createSearchSession(resolved, buildSystemPrompt(this.currentSystemPromptConfig({ modelId: resolved.model.id })));
17412
+ session = await this.createSearchSession(resolved, buildSystemPrompt(this.currentSystemPromptConfig({ modelId: resolved.model.id })), this.fastThinkingLevel === undefined ? [] : [createEmitFastAnswerTool(emitPreliminary)]);
17522
17413
  this.activeSession = session;
17523
17414
  unsubscribers = this.configureSearchSession(session);
17524
17415
  let timeout;
@@ -17536,28 +17427,35 @@ ${initialRetrievalContext}`);
17536
17427
  }
17537
17428
  return;
17538
17429
  }
17539
- const emitPreliminary = (details) => {
17540
- if (fastCaptured !== undefined)
17541
- return;
17542
- fastCaptured = details;
17543
- this.preliminaryCallback?.(createPreliminarySearchDocumentsResponse(sessionId, trimmedQuery, details, this.collectComponentDiagnostics()));
17544
- };
17545
- const fastTool = createEmitFastAnswerTool(emitPreliminary);
17546
17430
  const baseline = await retrievalPromise;
17547
- session.agent.state.thinkingLevel = clampThinkingLevel(resolved.model, this.fastThinkingLevel);
17548
- session.agent.state.tools = [...this.tools, fastTool];
17431
+ const sessionAgent = session.piSession;
17432
+ if (sessionAgent !== undefined) {
17433
+ sessionAgent.setThinkingLevel(clampThinkingLevel(resolved.model, this.fastThinkingLevel));
17434
+ sessionAgent.setActiveToolsByName([
17435
+ ...sessionAgent.getActiveToolNames().filter((name) => name !== EMIT_FAST_ANSWER_TOOL_NAME),
17436
+ EMIT_FAST_ANSWER_TOOL_NAME
17437
+ ]);
17438
+ } else {
17439
+ session.agent.state.thinkingLevel = clampThinkingLevel(resolved.model, this.fastThinkingLevel);
17440
+ session.agent.state.tools = [...this.tools, { name: EMIT_FAST_ANSWER_TOOL_NAME }];
17441
+ }
17549
17442
  await session.prompt(this.buildFastAnswerPrompt(trimmedQuery, options, baseline));
17550
17443
  let preliminary = fastCaptured;
17551
17444
  if (preliminary === undefined) {
17552
- const text = lastAssistantText(session.agent.state.messages);
17445
+ const text = lastAssistantText(session.piSession?.messages ?? session.agent.state.messages);
17553
17446
  if (text !== undefined)
17554
17447
  preliminary = { answer: text, results: [], sources: [] };
17555
17448
  }
17556
17449
  if (preliminary !== undefined)
17557
17450
  emitPreliminary(preliminary);
17558
17451
  if (captured === undefined && this.finalThinkingLevel !== undefined) {
17559
- session.agent.state.thinkingLevel = clampThinkingLevel(resolved.model, this.finalThinkingLevel);
17560
- session.agent.state.tools = [...this.tools];
17452
+ if (sessionAgent !== undefined) {
17453
+ sessionAgent.setThinkingLevel(clampThinkingLevel(resolved.model, this.finalThinkingLevel));
17454
+ sessionAgent.setActiveToolsByName(sessionAgent.getActiveToolNames().filter((name) => name !== EMIT_FAST_ANSWER_TOOL_NAME));
17455
+ } else {
17456
+ session.agent.state.thinkingLevel = clampThinkingLevel(resolved.model, this.finalThinkingLevel);
17457
+ session.agent.state.tools = [...this.tools];
17458
+ }
17561
17459
  const fastAnswerDelivered = preliminary !== undefined && this.preliminaryCallback !== undefined;
17562
17460
  await session.prompt(this.buildRefinementPrompt(trimmedQuery, options, preliminary, fastAnswerDelivered));
17563
17461
  }
@@ -17686,6 +17584,8 @@ ${initialRetrievalContext}`);
17686
17584
  this.resultCapture = undefined;
17687
17585
  this.activeRetrievalOptions = undefined;
17688
17586
  this.preliminaryCallback = undefined;
17587
+ if (this.interactiveFastAnswerCallback === emitPreliminary)
17588
+ this.interactiveFastAnswerCallback = undefined;
17689
17589
  this.activeRun = false;
17690
17590
  }
17691
17591
  }
@@ -18082,7 +17982,7 @@ ${initialRetrievalContext ?? "Pending; continue only with a brief progress state
18082
17982
  lastError: undefined
18083
17983
  };
18084
17984
  if (needsParsed) {
18085
- mkdirSync16(dirname15(refreshReadinessPath(this.workspaceProjectRoot)), { recursive: true });
17985
+ mkdirSync16(dirname14(refreshReadinessPath(this.workspaceProjectRoot)), { recursive: true });
18086
17986
  writeFileSync15(refreshReadinessPath(this.workspaceProjectRoot), `{"version":1,"completed":true,"parsed":true}
18087
17987
  `);
18088
17988
  }
@@ -18294,7 +18194,7 @@ ${initialRetrievalContext ?? "Pending; continue only with a brief progress state
18294
18194
  written: 0,
18295
18195
  deleted: 0,
18296
18196
  skipped: 0,
18297
- indexPath: join26(this.workspaceProjectRoot, PARSED_MIRROR_SUBDIR),
18197
+ indexPath: join27(this.workspaceProjectRoot, PARSED_MIRROR_SUBDIR),
18298
18198
  diagnostics
18299
18199
  };
18300
18200
  }
@@ -18840,7 +18740,7 @@ function toMinSyncReasonDiagnostic(reason) {
18840
18740
  function pinExcludedPath(path) {
18841
18741
  const resolvedPath = resolve13(path);
18842
18742
  try {
18843
- return join26(realpathSync5(dirname15(resolvedPath)), basename11(resolvedPath));
18743
+ return join27(realpathSync5(dirname14(resolvedPath)), basename11(resolvedPath));
18844
18744
  } catch {
18845
18745
  return resolvedPath;
18846
18746
  }
@@ -18901,7 +18801,6 @@ var init_agent = __esm(() => {
18901
18801
  init_rerank();
18902
18802
  init_scope();
18903
18803
  init_model_auth();
18904
- init_bash_tool();
18905
18804
  init_datasource_skill();
18906
18805
  init_dupey_tool();
18907
18806
  init_emit_results_tool();
@@ -18911,6 +18810,7 @@ var init_agent = __esm(() => {
18911
18810
  init_jikji_find_tool();
18912
18811
  init_local_model();
18913
18812
  init_peer_target_tool();
18813
+ init_pi_session();
18914
18814
  init_query_peer_tool();
18915
18815
  init_refresh_progress();
18916
18816
  init_search_all_tool();
@@ -19103,7 +19003,7 @@ ${this.description}`
19103
19003
  }
19104
19004
 
19105
19005
  // src/datasource/skills/clawgallery/client.ts
19106
- import { spawn as spawn10 } from "node:child_process";
19006
+ import { spawn as spawn9 } from "node:child_process";
19107
19007
  import { existsSync as existsSync21 } from "node:fs";
19108
19008
 
19109
19009
  class ClawGalleryClient {
@@ -19208,7 +19108,7 @@ class ClawGalleryClient {
19208
19108
  function spawnCli(binary, args, env, options, signal) {
19209
19109
  return new Promise((resolve) => {
19210
19110
  const portable = portableSpawnCommand(binary, args);
19211
- const child = spawn10(portable.command, [...portable.args], { env, stdio: ["ignore", "pipe", "pipe"] });
19111
+ const child = spawn9(portable.command, [...portable.args], { env, stdio: ["ignore", "pipe", "pipe"] });
19212
19112
  let stdout = "";
19213
19113
  let stderr = "";
19214
19114
  let settled = false;
@@ -19217,7 +19117,7 @@ function spawnCli(binary, args, env, options, signal) {
19217
19117
  const timeout = setTimeout(() => {
19218
19118
  reason = "timeout";
19219
19119
  terminate2(child);
19220
- }, options.timeoutMs ?? DEFAULT_TIMEOUT_MS7);
19120
+ }, options.timeoutMs ?? DEFAULT_TIMEOUT_MS6);
19221
19121
  const abort = () => {
19222
19122
  reason = "aborted";
19223
19123
  terminate2(child);
@@ -19332,7 +19232,7 @@ function boundDiagnosticText(value) {
19332
19232
  return "";
19333
19233
  return value.trim().slice(0, 4000);
19334
19234
  }
19335
- var DEFAULT_BINARY2 = "clawgallery", DEFAULT_TIMEOUT_MS7 = 60000, DEFAULT_MAX_BUFFER_BYTES2, SAFE_ENV;
19235
+ var DEFAULT_BINARY2 = "clawgallery", DEFAULT_TIMEOUT_MS6 = 60000, DEFAULT_MAX_BUFFER_BYTES2, SAFE_ENV;
19336
19236
  var init_client5 = __esm(() => {
19337
19237
  init_portable_spawn();
19338
19238
  DEFAULT_MAX_BUFFER_BYTES2 = 4 * 1024 * 1024;
@@ -19660,7 +19560,7 @@ function statusToReason(status) {
19660
19560
  }
19661
19561
  async function requestText(url, options) {
19662
19562
  const fetchImpl = options.fetchImpl ?? globalThis.fetch;
19663
- const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS8;
19563
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS7;
19664
19564
  let response;
19665
19565
  try {
19666
19566
  response = await fetchImpl(url, {
@@ -19724,13 +19624,13 @@ function resolveToken(token, tokenEnv) {
19724
19624
  }
19725
19625
  return;
19726
19626
  }
19727
- var DEFAULT_TIMEOUT_MS8 = 15000;
19627
+ var DEFAULT_TIMEOUT_MS7 = 15000;
19728
19628
 
19729
19629
  // src/datasource/skills/cloud-drive/rclone-connector.ts
19730
- import { spawn as spawn11 } from "node:child_process";
19630
+ import { spawn as spawn10 } from "node:child_process";
19731
19631
  import { mkdirSync as mkdirSync17, readFileSync as readFileSync17, renameSync as renameSync10, rmSync as rmSync7, writeFileSync as writeFileSync16 } from "node:fs";
19732
19632
  import { readFile as readFile4 } from "node:fs/promises";
19733
- import { dirname as dirname16, join as join27, normalize as normalize3 } from "node:path";
19633
+ import { dirname as dirname15, join as join28, normalize as normalize3 } from "node:path";
19734
19634
 
19735
19635
  class RcloneConnector {
19736
19636
  options;
@@ -19746,7 +19646,7 @@ class RcloneConnector {
19746
19646
  if (remote === undefined || remote.length === 0) {
19747
19647
  return { ok: false, reason: "not-configured", message: "rclone remote not configured" };
19748
19648
  }
19749
- const timeoutMs = this.options.timeoutMs ?? DEFAULT_TIMEOUT_MS9;
19649
+ const timeoutMs = this.options.timeoutMs ?? DEFAULT_TIMEOUT_MS8;
19750
19650
  const exportFormats = this.options.exportFormats ?? DEFAULT_EXPORT_FORMATS;
19751
19651
  let listResult;
19752
19652
  try {
@@ -19817,7 +19717,7 @@ class RcloneConnector {
19817
19717
  return;
19818
19718
  const destination = mirrorFilePath(paths.mirrorRoot, entry.path);
19819
19719
  const temp = `${destination}.autorag-tmp`;
19820
- mkdirSync17(dirname16(temp), { recursive: true });
19720
+ mkdirSync17(dirname15(temp), { recursive: true });
19821
19721
  let copied;
19822
19722
  try {
19823
19723
  copied = await this.runner(copyArgs(remote, entry.path, temp, exportFormats, this.options.concurrency, this.options.bandwidthLimit), timeoutMs);
@@ -19922,12 +19822,12 @@ function sameEntry(previous, current) {
19922
19822
  return previous?.path === current.path && previous.size === current.size && previous.modTime === current.modTime && previous.remoteId === current.remoteId && JSON.stringify(previous.hashes) === JSON.stringify(current.hashes);
19923
19823
  }
19924
19824
  function mirrorPaths(workspaceRoot, skillName, instanceId) {
19925
- const base = join27(workspaceRoot, ".autorag", "datasources", skillName, instanceId);
19926
- return { mirrorRoot: join27(base, "mirror"), manifestPath: join27(base, "manifest.json") };
19825
+ const base = join28(workspaceRoot, ".autorag", "datasources", skillName, instanceId);
19826
+ return { mirrorRoot: join28(base, "mirror"), manifestPath: join28(base, "manifest.json") };
19927
19827
  }
19928
19828
  function mirrorFilePath(root, path) {
19929
19829
  const safe = normalize3(path).replace(/^(\.\.(?:[/\\]|$))+|^[/\\]+/gu, "");
19930
- return join27(root, safe);
19830
+ return join28(root, safe);
19931
19831
  }
19932
19832
  function remoteTarget(remote, path) {
19933
19833
  return remote.endsWith(":") || remote.endsWith("/") ? `${remote}${path}` : `${remote}/${path}`;
@@ -19953,7 +19853,7 @@ function loadManifest2(path) {
19953
19853
  }
19954
19854
  }
19955
19855
  function saveManifest(path, manifest) {
19956
- mkdirSync17(dirname16(path), { recursive: true });
19856
+ mkdirSync17(dirname15(path), { recursive: true });
19957
19857
  const temp = `${path}.autorag-tmp`;
19958
19858
  writeFileSync16(temp, `${JSON.stringify(manifest)}
19959
19859
  `, "utf8");
@@ -20031,7 +19931,7 @@ function shortFailure(result) {
20031
19931
  function runBinary(binary, args, timeoutMs, env, cwd) {
20032
19932
  return new Promise((resolvePromise) => {
20033
19933
  const portable = portableSpawnCommand(binary, args);
20034
- const child = spawn11(portable.command, [...portable.args], {
19934
+ const child = spawn10(portable.command, [...portable.args], {
20035
19935
  ...env === undefined ? {} : { env: { ...process.env, ...env } },
20036
19936
  ...cwd === undefined ? {} : { cwd },
20037
19937
  stdio: ["ignore", "pipe", "pipe"]
@@ -20055,7 +19955,7 @@ function runBinary(binary, args, timeoutMs, env, cwd) {
20055
19955
  });
20056
19956
  });
20057
19957
  }
20058
- var DEFAULT_BINARY3 = "rclone", DEFAULT_EXTENSIONS, DEFAULT_EXPORT_FORMATS = "txt,csv", DEFAULT_MAX_DOCUMENTS = 200, DEFAULT_MAX_BYTES_PER_FILE, DEFAULT_TIMEOUT_MS9 = 60000, MAX_CONTENT_CHARS = 1e5;
19958
+ var DEFAULT_BINARY3 = "rclone", DEFAULT_EXTENSIONS, DEFAULT_EXPORT_FORMATS = "txt,csv", DEFAULT_MAX_DOCUMENTS = 200, DEFAULT_MAX_BYTES_PER_FILE, DEFAULT_TIMEOUT_MS8 = 60000, MAX_CONTENT_CHARS = 1e5;
20059
19959
  var init_rclone_connector = __esm(() => {
20060
19960
  init_defaults();
20061
19961
  init_portable_spawn();
@@ -20106,9 +20006,9 @@ var init_connector = () => {};
20106
20006
 
20107
20007
  // src/datasource/chunk-store.ts
20108
20008
  import { existsSync as existsSync22, mkdirSync as mkdirSync18, readFileSync as readFileSync18, writeFileSync as writeFileSync17 } from "node:fs";
20109
- import { dirname as dirname17, join as join28 } from "node:path";
20009
+ import { dirname as dirname16, join as join29 } from "node:path";
20110
20010
  function datasourceChunkStorePath(workspaceRoot, skillName, instanceId) {
20111
- return join28(workspaceRoot, ".autorag", "datasources", sanitizeIdSegment(skillName), sanitizeIdSegment(instanceId), "chunks.json");
20011
+ return join29(workspaceRoot, ".autorag", "datasources", sanitizeIdSegment(skillName), sanitizeIdSegment(instanceId), "chunks.json");
20112
20012
  }
20113
20013
 
20114
20014
  class DatasourceChunkStore {
@@ -20221,7 +20121,7 @@ class DatasourceChunkStore {
20221
20121
  if (this.storePath === undefined)
20222
20122
  return;
20223
20123
  try {
20224
- mkdirSync18(dirname17(this.storePath), { recursive: true });
20124
+ mkdirSync18(dirname16(this.storePath), { recursive: true });
20225
20125
  const payload = {
20226
20126
  version: STORE_VERSION,
20227
20127
  skill: this.skillName,
@@ -20644,13 +20544,13 @@ var init_cloud_drive = __esm(() => {
20644
20544
  });
20645
20545
 
20646
20546
  // src/process/terminate-tree.ts
20647
- import { spawn as spawn12 } from "node:child_process";
20547
+ import { spawn as spawn11 } from "node:child_process";
20648
20548
  function terminateProcessTree(child, signal = "SIGKILL") {
20649
20549
  const pid = child.pid;
20650
20550
  if (pid === undefined)
20651
20551
  return false;
20652
20552
  if (process.platform === "win32") {
20653
- const killer = spawn12("taskkill", ["/pid", String(pid), "/t", "/f"], { stdio: "ignore", windowsHide: true });
20553
+ const killer = spawn11("taskkill", ["/pid", String(pid), "/t", "/f"], { stdio: "ignore", windowsHide: true });
20654
20554
  killer.on("error", () => killDirectChild(child, signal));
20655
20555
  killer.on("close", (code) => {
20656
20556
  if (code !== 0)
@@ -20693,9 +20593,9 @@ var init_types4 = __esm(() => {
20693
20593
  });
20694
20594
 
20695
20595
  // src/datasource/skills/discrawl/client.ts
20696
- import { spawn as spawn13 } from "node:child_process";
20596
+ import { spawn as spawn12 } from "node:child_process";
20697
20597
  import { mkdirSync as mkdirSync19, readFileSync as readFileSync19, writeFileSync as writeFileSync18 } from "node:fs";
20698
- import { dirname as dirname18 } from "node:path";
20598
+ import { dirname as dirname17 } from "node:path";
20699
20599
 
20700
20600
  class DiscrawlClient {
20701
20601
  options;
@@ -20719,7 +20619,7 @@ class DiscrawlClient {
20719
20619
  return { configured: false, rebuildRequired: false };
20720
20620
  const previous = managed ? parseManagedEmbedding(existing) : undefined;
20721
20621
  const config = managedDiscrawlConfig({ ...runtime, baseUrl: nativeGatewayBaseUrl(runtime.baseUrl) });
20722
- mkdirSync19(dirname18(path), { recursive: true });
20622
+ mkdirSync19(dirname17(path), { recursive: true });
20723
20623
  if (existing !== config)
20724
20624
  writeFileSync18(path, config, "utf8");
20725
20625
  return {
@@ -20833,7 +20733,7 @@ function spawnDiscrawl(request) {
20833
20733
  return new Promise((resolveResult) => {
20834
20734
  const { options, args, env, signal } = request;
20835
20735
  const portable = portableSpawnCommand(options.binaryPath ?? DEFAULT_DISCRAWL_BINARY, args);
20836
- const child = spawn13(portable.command, [...portable.args], {
20736
+ const child = spawn12(portable.command, [...portable.args], {
20837
20737
  env,
20838
20738
  ...request.cwd === undefined ? {} : { cwd: request.cwd },
20839
20739
  detached: process.platform !== "win32",
@@ -21742,12 +21642,12 @@ var init_github = __esm(() => {
21742
21642
  });
21743
21643
 
21744
21644
  // src/datasource/skills/github-gist/connector.ts
21745
- import { execFile as execFile3 } from "node:child_process";
21645
+ import { execFile as execFile2 } from "node:child_process";
21746
21646
  import { existsSync as existsSync23, mkdirSync as mkdirSync20, readFileSync as readFileSync20, writeFileSync as writeFileSync19 } from "node:fs";
21747
- import { dirname as dirname19 } from "node:path";
21647
+ import { dirname as dirname18 } from "node:path";
21748
21648
  async function defaultGhTokenRunner() {
21749
21649
  return new Promise((resolve) => {
21750
- execFile3("gh", ["auth", "token"], { timeout: GH_TOKEN_TIMEOUT_MS }, (error, stdout) => {
21650
+ execFile2("gh", ["auth", "token"], { timeout: GH_TOKEN_TIMEOUT_MS }, (error, stdout) => {
21751
21651
  if (error) {
21752
21652
  resolve(undefined);
21753
21653
  return;
@@ -21880,7 +21780,7 @@ class GitHubGistConnector {
21880
21780
  if (statePath === undefined)
21881
21781
  return;
21882
21782
  try {
21883
- mkdirSync20(dirname19(statePath), { recursive: true });
21783
+ mkdirSync20(dirname18(statePath), { recursive: true });
21884
21784
  writeFileSync19(statePath, `${JSON.stringify(state)}
21885
21785
  `, "utf8");
21886
21786
  } catch {}
@@ -21927,7 +21827,7 @@ var init_connector3 = () => {};
21927
21827
  // src/datasource/skills/github-gist/semantic.ts
21928
21828
  import { createHash as createHash10 } from "node:crypto";
21929
21829
  import { existsSync as existsSync24, mkdirSync as mkdirSync21, readFileSync as readFileSync21, writeFileSync as writeFileSync20 } from "node:fs";
21930
- import { dirname as dirname20 } from "node:path";
21830
+ import { dirname as dirname19 } from "node:path";
21931
21831
  function contentHash(chunk) {
21932
21832
  return createHash10("sha256").update(`${chunk.title ?? ""}
21933
21833
  ${chunk.content}`).digest("hex");
@@ -22035,7 +21935,7 @@ ${chunk.content}`));
22035
21935
  if (this.identity === undefined)
22036
21936
  return;
22037
21937
  try {
22038
- mkdirSync21(dirname20(this.statePath), { recursive: true });
21938
+ mkdirSync21(dirname19(this.statePath), { recursive: true });
22039
21939
  const payload = {
22040
21940
  version: VECTORS_VERSION,
22041
21941
  identity: this.identity,
@@ -22175,9 +22075,9 @@ var init_semantic = __esm(() => {
22175
22075
  });
22176
22076
 
22177
22077
  // src/datasource/skills/github-gist/skill.ts
22178
- import { join as join29 } from "node:path";
22078
+ import { join as join30 } from "node:path";
22179
22079
  function gistDatasourceDir(workspaceRoot, skillName, instanceId) {
22180
- return join29(workspaceRoot, ".autorag", "datasources", sanitizeIdSegment(skillName), sanitizeIdSegment(instanceId));
22080
+ return join30(workspaceRoot, ".autorag", "datasources", sanitizeIdSegment(skillName), sanitizeIdSegment(instanceId));
22181
22081
  }
22182
22082
  var GITHUB_GIST_SKILL_DEFINITION, DEFAULT_INSTANCE_ID3 = "default", GitHubGistSkill;
22183
22083
  var init_skill5 = __esm(() => {
@@ -22205,7 +22105,7 @@ var init_skill5 = __esm(() => {
22205
22105
  constructor(options = {}) {
22206
22106
  const { connector, connectorOptions, semantic, ...rest } = options;
22207
22107
  const instanceId = options.instanceId ?? DEFAULT_INSTANCE_ID3;
22208
- const statePath = connectorOptions?.statePath ?? (options.workspaceRoot === undefined ? undefined : join29(gistDatasourceDir(options.workspaceRoot, GITHUB_GIST_SKILL_DEFINITION.skillName, instanceId), "state.json"));
22108
+ const statePath = connectorOptions?.statePath ?? (options.workspaceRoot === undefined ? undefined : join30(gistDatasourceDir(options.workspaceRoot, GITHUB_GIST_SKILL_DEFINITION.skillName, instanceId), "state.json"));
22209
22109
  super(GITHUB_GIST_SKILL_DEFINITION, {
22210
22110
  ...rest,
22211
22111
  connector: connector ?? new GitHubGistConnector({
@@ -22215,7 +22115,7 @@ var init_skill5 = __esm(() => {
22215
22115
  });
22216
22116
  if (semantic?.enabled !== false) {
22217
22117
  this.semanticIndex = new GistSemanticIndex({
22218
- statePath: semantic?.statePath ?? (options.workspaceRoot === undefined ? undefined : join29(gistDatasourceDir(options.workspaceRoot, GITHUB_GIST_SKILL_DEFINITION.skillName, instanceId), "vectors.json"))
22118
+ statePath: semantic?.statePath ?? (options.workspaceRoot === undefined ? undefined : join30(gistDatasourceDir(options.workspaceRoot, GITHUB_GIST_SKILL_DEFINITION.skillName, instanceId), "vectors.json"))
22219
22119
  });
22220
22120
  this.semanticEmbedder = semantic?.embedder ?? createGatewayGistEmbedder(semantic?.embedderOptions ?? {});
22221
22121
  this.semanticMethod = new GitHubGistSemanticMethod({
@@ -22271,7 +22171,7 @@ function connectorSyncTimeoutHint() {
22271
22171
  var DEFAULT_CONNECTOR_SYNC_TIMEOUT_MS = 1800000;
22272
22172
 
22273
22173
  // src/datasource/crawler-client.ts
22274
- import { spawn as spawn14 } from "node:child_process";
22174
+ import { spawn as spawn13 } from "node:child_process";
22275
22175
 
22276
22176
  class CrawlerCliClient {
22277
22177
  profile;
@@ -22308,7 +22208,7 @@ class CrawlerCliClient {
22308
22208
  function spawnCrawler(command, args, env, signal, options, timeoutMs, cwd) {
22309
22209
  return new Promise((resolve) => {
22310
22210
  const portable = portableSpawnCommand(command, args);
22311
- const child = spawn14(portable.command, [...portable.args], {
22211
+ const child = spawn13(portable.command, [...portable.args], {
22312
22212
  env,
22313
22213
  ...cwd === undefined ? {} : { cwd },
22314
22214
  stdio: ["ignore", "pipe", "pipe"]
@@ -22936,9 +22836,9 @@ var init_types5 = __esm(() => {
22936
22836
  });
22937
22837
 
22938
22838
  // src/datasource/skills/lazykatok/client.ts
22939
- import { spawn as spawn15 } from "node:child_process";
22839
+ import { spawn as spawn14 } from "node:child_process";
22940
22840
  import { existsSync as existsSync25 } from "node:fs";
22941
- import { delimiter as delimiter4, join as join30 } from "node:path";
22841
+ import { delimiter as delimiter4, join as join31 } from "node:path";
22942
22842
 
22943
22843
  class LazykatokClient {
22944
22844
  options;
@@ -23036,7 +22936,7 @@ function spawnLazykatok(request) {
23036
22936
  return new Promise((resolve) => {
23037
22937
  const { options, args, env, signal } = request;
23038
22938
  const portable = portableSpawnCommand(commandFor2(options, env), args);
23039
- const child = spawn15(portable.command, [...portable.args], {
22939
+ const child = spawn14(portable.command, [...portable.args], {
23040
22940
  env,
23041
22941
  ...request.cwd === undefined ? {} : { cwd: request.cwd },
23042
22942
  detached: process.platform !== "win32",
@@ -23126,7 +23026,7 @@ function lookupInPath2(executable, env) {
23126
23026
  for (const dir of pathEnv.split(delimiter4)) {
23127
23027
  if (dir.length === 0)
23128
23028
  continue;
23129
- const candidate = join30(dir, executable);
23029
+ const candidate = join31(dir, executable);
23130
23030
  if (existsSync25(candidate))
23131
23031
  return candidate;
23132
23032
  }
@@ -23616,7 +23516,7 @@ var init_lazykatok = __esm(() => {
23616
23516
 
23617
23517
  // src/datasource/skills/mail-export/connector.ts
23618
23518
  import { readdir as readdir3, readFile as readFile5, stat as stat6 } from "node:fs/promises";
23619
- import { basename as basename12, dirname as dirname21, extname as extname7, join as join31 } from "node:path";
23519
+ import { basename as basename12, dirname as dirname20, extname as extname7, join as join32 } from "node:path";
23620
23520
  import { simpleParser as simpleParser2 } from "mailparser";
23621
23521
 
23622
23522
  class MailExportConnector {
@@ -23642,7 +23542,7 @@ class MailExportConnector {
23642
23542
  continue;
23643
23543
  const extension = extname7(entry.name).toLowerCase();
23644
23544
  if (extension === ".eml" || extension === ".mbox") {
23645
- files.push(join31(entry.parentPath, entry.name));
23545
+ files.push(join32(entry.parentPath, entry.name));
23646
23546
  }
23647
23547
  }
23648
23548
  } else if (info.isFile()) {
@@ -23677,7 +23577,7 @@ class MailExportConnector {
23677
23577
  continue;
23678
23578
  }
23679
23579
  const stem = basename12(file, extname7(file));
23680
- const mailboxDir = basename12(dirname21(file));
23580
+ const mailboxDir = basename12(dirname20(file));
23681
23581
  const hierarchy = ["mailboxes", mailboxDir, stem];
23682
23582
  const extension = extname7(file).toLowerCase();
23683
23583
  const rawMessages = extension === ".mbox" ? splitMbox(bytes.toString("utf8")) : [bytes.toString("utf8")];
@@ -23801,7 +23701,7 @@ function ensurePrivateMailcrawlDataDir(path) {
23801
23701
  var init_config = () => {};
23802
23702
 
23803
23703
  // src/datasource/skills/mailcrawl/client.ts
23804
- import { spawn as spawn16 } from "node:child_process";
23704
+ import { spawn as spawn15 } from "node:child_process";
23805
23705
 
23806
23706
  class MailcrawlClient {
23807
23707
  options;
@@ -23921,7 +23821,7 @@ class MailcrawlClient {
23921
23821
  function spawnMailcrawl(binary, args, env, options, signal, timeoutMs) {
23922
23822
  return new Promise((resolveResult) => {
23923
23823
  const portable = portableSpawnCommand(binary, args);
23924
- const child = spawn16(portable.command, portable.args, {
23824
+ const child = spawn15(portable.command, portable.args, {
23925
23825
  env,
23926
23826
  detached: process.platform !== "win32",
23927
23827
  stdio: ["ignore", "pipe", "pipe"]
@@ -24752,15 +24652,15 @@ var init_notion = __esm(() => {
24752
24652
  });
24753
24653
 
24754
24654
  // src/datasource/skills/obsidian/paths.ts
24755
- import { join as join32 } from "node:path";
24655
+ import { join as join33 } from "node:path";
24756
24656
  function obsidianDatasourceRoot(workspaceRoot, instanceId) {
24757
- return join32(workspaceRoot, AUTORAG_DIRNAME, DATASOURCES_DIRNAME, OBSIDIAN_DATASOURCE_DIRNAME, instanceId);
24657
+ return join33(workspaceRoot, AUTORAG_DIRNAME, DATASOURCES_DIRNAME, OBSIDIAN_DATASOURCE_DIRNAME, instanceId);
24758
24658
  }
24759
24659
  function obsidianQmdConfigDir(workspaceRoot, instanceId) {
24760
- return join32(obsidianDatasourceRoot(workspaceRoot, instanceId), "config");
24660
+ return join33(obsidianDatasourceRoot(workspaceRoot, instanceId), "config");
24761
24661
  }
24762
24662
  function obsidianQmdCacheDir(workspaceRoot, instanceId) {
24763
- return join32(obsidianDatasourceRoot(workspaceRoot, instanceId), "cache");
24663
+ return join33(obsidianDatasourceRoot(workspaceRoot, instanceId), "cache");
24764
24664
  }
24765
24665
  function stripEdgeDashes(value) {
24766
24666
  let start = 0;
@@ -24782,7 +24682,7 @@ var init_paths5 = () => {};
24782
24682
  var DEFAULT_QMD_BINARY = "qmd", DEFAULT_QMD_TIMEOUT_MS = 60000, DEFAULT_QMD_MAX_BUFFER_BYTES = 1048576;
24783
24683
 
24784
24684
  // src/datasource/skills/obsidian/client.ts
24785
- import { spawn as spawn17 } from "node:child_process";
24685
+ import { spawn as spawn16 } from "node:child_process";
24786
24686
  import { mkdirSync as mkdirSync23, writeFileSync as writeFileSync21 } from "node:fs";
24787
24687
  import { isAbsolute as isAbsolute6, resolve as resolve14 } from "node:path";
24788
24688
 
@@ -24907,7 +24807,7 @@ function isAllowedEnvKey2(key) {
24907
24807
  function spawnQmd(request) {
24908
24808
  return new Promise((resolveResult) => {
24909
24809
  const portable = portableSpawnCommand(request.binaryPath ?? DEFAULT_QMD_BINARY, request.args);
24910
- const child = spawn17(portable.command, [...portable.args], {
24810
+ const child = spawn16(portable.command, [...portable.args], {
24911
24811
  env: request.env,
24912
24812
  ...request.cwd === undefined ? {} : { cwd: request.cwd },
24913
24813
  detached: process.platform !== "win32",
@@ -25780,7 +25680,7 @@ var init_slack = __esm(() => {
25780
25680
  });
25781
25681
 
25782
25682
  // src/datasource/skills/spotlight/connector.ts
25783
- import { spawn as spawn18 } from "node:child_process";
25683
+ import { spawn as spawn17 } from "node:child_process";
25784
25684
  import { createHash as createHash11 } from "node:crypto";
25785
25685
  import { readFile as fsReadFile, stat as stat7 } from "node:fs/promises";
25786
25686
  import { basename as basename13, extname as extname8 } from "node:path";
@@ -25804,7 +25704,7 @@ class SpotlightConnector {
25804
25704
  if (queries.length === 0) {
25805
25705
  return { ok: false, reason: "not-configured", message: "no spotlight queries configured" };
25806
25706
  }
25807
- const timeoutMs = this.options.timeoutMs ?? DEFAULT_TIMEOUT_MS10;
25707
+ const timeoutMs = this.options.timeoutMs ?? DEFAULT_TIMEOUT_MS9;
25808
25708
  const status = await this.run("mdutil", ["-s", "/"], timeoutMs);
25809
25709
  if (status.ok && /indexing disabled/iu.test(status.stdout)) {
25810
25710
  return {
@@ -25899,8 +25799,8 @@ class SpotlightConnector {
25899
25799
  return { ok: true, documents, ...warnings.length > 0 ? { warnings } : {} };
25900
25800
  }
25901
25801
  }
25902
- var DEFAULT_MAX_RESULTS_PER_QUERY = 100, DEFAULT_MAX_DOCUMENTS5 = 300, DEFAULT_MAX_BYTES_PER_FILE3, DEFAULT_TIMEOUT_MS10 = 15000, MAX_CONTENT_CHARS3 = 1e5, MAX_BUFFER_BYTES, FDA_GUIDANCE = "grant Full Disk Access to the terminal or app running AutoRAG (System Settings -> Privacy & Security -> Full Disk Access), then restart it", spawnRunner = (command, args, timeoutMs) => new Promise((resolve) => {
25903
- const child = spawn18(command, [...args], { stdio: ["ignore", "pipe", "pipe"] });
25802
+ var DEFAULT_MAX_RESULTS_PER_QUERY = 100, DEFAULT_MAX_DOCUMENTS5 = 300, DEFAULT_MAX_BYTES_PER_FILE3, DEFAULT_TIMEOUT_MS9 = 15000, MAX_CONTENT_CHARS3 = 1e5, MAX_BUFFER_BYTES, FDA_GUIDANCE = "grant Full Disk Access to the terminal or app running AutoRAG (System Settings -> Privacy & Security -> Full Disk Access), then restart it", spawnRunner = (command, args, timeoutMs) => new Promise((resolve) => {
25803
+ const child = spawn17(command, [...args], { stdio: ["ignore", "pipe", "pipe"] });
25904
25804
  let stdout = "";
25905
25805
  let stderr = "";
25906
25806
  let settled = false;
@@ -26461,8 +26361,9 @@ var init_factory = __esm(() => {
26461
26361
  // src/cli/config.ts
26462
26362
  import { randomUUID as randomUUID9 } from "node:crypto";
26463
26363
  import { existsSync as existsSync26, mkdirSync as mkdirSync24, readFileSync as readFileSync22, renameSync as renameSync11, unlinkSync as unlinkSync5, writeFileSync as writeFileSync22 } from "node:fs";
26464
- import { basename as basename14, dirname as dirname22, isAbsolute as isAbsolute7, join as join33, resolve as resolve15 } from "node:path";
26465
- import { findEnvKeys, getEnvApiKey, getModel, getProviders } from "@earendil-works/pi-ai/compat";
26364
+ import { basename as basename14, dirname as dirname21, isAbsolute as isAbsolute7, join as join34, resolve as resolve15 } from "node:path";
26365
+ import { findEnvKeys, getEnvApiKey } from "@earendil-works/pi-ai/compat";
26366
+ import { getAgentDir as getAgentDir2, ModelRuntime as ModelRuntime2, SettingsManager as SettingsManager2 } from "@earendil-works/pi-coding-agent";
26466
26367
  function resolveConfigPath(input) {
26467
26368
  const flags = input.flags;
26468
26369
  const env = input.env ?? process.env;
@@ -26476,9 +26377,9 @@ function resolveConfigPath(input) {
26476
26377
  return { configPath: envConfig, explicit: true };
26477
26378
  }
26478
26379
  return {
26479
- configPath: join33(resolveAutoRAGHome(env), DEFAULT_CONFIG_FILENAME),
26380
+ configPath: join34(resolveAutoRAGHome(env), DEFAULT_CONFIG_FILENAME),
26480
26381
  explicit: false,
26481
- legacyPath: join33(cwd, LEGACY_CONFIG_FILENAME)
26382
+ legacyPath: join34(cwd, LEGACY_CONFIG_FILENAME)
26482
26383
  };
26483
26384
  }
26484
26385
  function readConfigFile(configPath, explicit) {
@@ -26534,7 +26435,7 @@ function acquireConfigWriteLock(configPath) {
26534
26435
  });
26535
26436
  }
26536
26437
  function replaceFileAtomically(path, contents, assertCommitAllowed) {
26537
- const temporaryPath = join33(dirname22(path), `.${basename14(path)}.${process.pid}.${randomUUID9()}.tmp`);
26438
+ const temporaryPath = join34(dirname21(path), `.${basename14(path)}.${process.pid}.${randomUUID9()}.tmp`);
26538
26439
  try {
26539
26440
  writeFileSync22(temporaryPath, contents, { encoding: "utf8", flag: "wx", flush: true, mode: 384 });
26540
26441
  assertCommitAllowed?.();
@@ -26548,11 +26449,11 @@ function migrateLegacyConfig(configPath, legacyPath) {
26548
26449
  return;
26549
26450
  const legacy = readConfigFile(legacyPath, true);
26550
26451
  const legacyBytes = readFileSync22(legacyPath);
26551
- const migrated = normalizeLegacyConfigPaths(legacy ?? {}, dirname22(legacyPath));
26452
+ const migrated = normalizeLegacyConfigPaths(legacy ?? {}, dirname21(legacyPath));
26552
26453
  const migratedPathsUnchanged = legacy?.workspacePath === migrated.workspacePath && legacy?.memoryPath === migrated.memoryPath && JSON.stringify(legacy?.searchPaths) === JSON.stringify(migrated.searchPaths);
26553
26454
  const migratedBytes = migratedPathsUnchanged ? legacyBytes : `${JSON.stringify(migrated, null, 2)}
26554
26455
  `;
26555
- mkdirSync24(dirname22(configPath), { recursive: true });
26456
+ mkdirSync24(dirname21(configPath), { recursive: true });
26556
26457
  const lock = acquireConfigWriteLock(configPath);
26557
26458
  try {
26558
26459
  const winner = readConfigFile(configPath, false);
@@ -26582,7 +26483,7 @@ function resolveConfigFileReadOnly(configPath, explicit, legacyPath) {
26582
26483
  const legacy = readConfigFile(legacyPath, false);
26583
26484
  if (legacy === undefined)
26584
26485
  return {};
26585
- return normalizeLegacyConfigPaths(legacy, dirname22(legacyPath));
26486
+ return normalizeLegacyConfigPaths(legacy, dirname21(legacyPath));
26586
26487
  }
26587
26488
  function resolveSearchPaths(searchPaths, origin) {
26588
26489
  return searchPaths.map((searchPath) => resolvePersistedPath(searchPath, origin));
@@ -27017,10 +26918,10 @@ function resolveConfig(input) {
27017
26918
  const file = readOnly ? resolveConfigFileReadOnly(configPath, explicit, legacyPath) : !explicit && legacyPath ? migrateLegacyConfig(configPath, legacyPath) ?? readConfigFile(configPath, explicit) ?? {} : readConfigFile(configPath, explicit) ?? {};
27018
26919
  const defaultSearchPaths = ["."];
27019
26920
  const defaultWorkspacePath = cwd;
27020
- const defaultMemoryPath = join33(resolveAutoRAGHome(env), "memory.json");
26921
+ const defaultMemoryPath = join34(resolveAutoRAGHome(env), "memory.json");
27021
26922
  const flagSearchPaths = parseCsv(flagString(flags, "search-paths"));
27022
26923
  const envSearchPaths = parseCsv(envString(env, "AUTORAG_SEARCH_PATHS"));
27023
- const configOrigin = dirname22(resolve15(configPath));
26924
+ const configOrigin = dirname21(resolve15(configPath));
27024
26925
  const fileWorkspacePath = typeof file.workspacePath === "string" ? resolvePersistedPath(file.workspacePath, configOrigin) : undefined;
27025
26926
  const fileSearchPaths = file.searchPaths ? resolveSearchPaths(file.searchPaths, fileWorkspacePath ?? configOrigin) : undefined;
27026
26927
  if (file.excludePaths !== undefined && (!Array.isArray(file.excludePaths) || file.excludePaths.some((path) => typeof path !== "string" || path.length === 0))) {
@@ -27185,6 +27086,9 @@ function normalizeRerankConfig(raw, path) {
27185
27086
  }
27186
27087
  out.provider = record.provider.trim();
27187
27088
  }
27089
+ if (!SUPPORTED_RERANK_PROVIDERS.includes(out.provider ?? "")) {
27090
+ throw new ConfigError(`${path}.provider must be one of: ${SUPPORTED_RERANK_PROVIDERS.join(", ")}`);
27091
+ }
27188
27092
  if (record.model !== undefined) {
27189
27093
  if (typeof record.model !== "string" || record.model.trim() === "") {
27190
27094
  throw new ConfigError(`${path}.model must be a non-empty string`);
@@ -27316,12 +27220,7 @@ function buildModelFromConfiguredEndpoint(reference) {
27316
27220
  maxTokens: reference.maxTokens ?? 16384
27317
27221
  };
27318
27222
  }
27319
- function resolveCatalogModel(reference) {
27320
- if (!getProviders().includes(reference.provider))
27321
- return;
27322
- const catalog = getModel(reference.provider, reference.id);
27323
- if (catalog === undefined)
27324
- return;
27223
+ function mergeCatalogModel(catalog, reference) {
27325
27224
  return {
27326
27225
  ...catalog,
27327
27226
  ...reference.name !== undefined ? { name: reference.name } : {},
@@ -27333,109 +27232,120 @@ function resolveCatalogModel(reference) {
27333
27232
  ...reference.maxTokens !== undefined ? { maxTokens: reference.maxTokens } : {}
27334
27233
  };
27335
27234
  }
27336
- function resolveRegisteredModel(reference) {
27337
- const catalog = resolveCatalogModel(reference);
27235
+ function resolveRuntimeCatalogModel(runtime, reference) {
27236
+ const catalog = runtime.getModel(reference.provider, reference.id);
27237
+ if (catalog === undefined)
27238
+ return;
27239
+ return mergeCatalogModel(catalog, reference);
27240
+ }
27241
+ function resolveRegisteredModel(runtime, reference) {
27242
+ const catalog = resolveRuntimeCatalogModel(runtime, reference);
27338
27243
  if (catalog !== undefined)
27339
27244
  return catalog;
27340
27245
  if (isConfiguredEndpoint(reference))
27341
27246
  return buildModelFromConfiguredEndpoint(reference);
27342
27247
  throw new ConfigError(`Unknown configured model: ${reference.provider}/${reference.id}. ${UNKNOWN_MODEL_HINT}`);
27343
27248
  }
27344
- function resolveBuiltInModel(reference) {
27249
+ function resolveBuiltInModel(runtime, reference) {
27345
27250
  if (reference === undefined)
27346
27251
  return;
27347
- const catalog = resolveCatalogModel(reference);
27252
+ const catalog = resolveRuntimeCatalogModel(runtime, reference);
27348
27253
  if (catalog !== undefined)
27349
27254
  return catalog;
27350
27255
  if (isConfiguredEndpoint(reference))
27351
27256
  return buildModelFromConfiguredEndpoint(reference);
27352
- if (getProviders().includes(reference.provider)) {
27257
+ if (runtime.getProvider(reference.provider) !== undefined) {
27353
27258
  throw new ConfigError(`Unknown configured model: ${reference.provider}/${reference.id}. ${UNKNOWN_MODEL_HINT}`);
27354
27259
  }
27355
27260
  return;
27356
27261
  }
27357
- function resolveModel(config) {
27262
+ function resolveAgentDir(options) {
27263
+ return options.agentDir ?? getAgentDir2();
27264
+ }
27265
+ function getModelRuntime(agentDir) {
27266
+ const cached = modelRuntimeCache.get(agentDir);
27267
+ if (cached !== undefined)
27268
+ return cached;
27269
+ const created = ModelRuntime2.create({
27270
+ authPath: join34(agentDir, "auth.json"),
27271
+ modelsPath: join34(agentDir, "models.json"),
27272
+ allowModelNetwork: false
27273
+ });
27274
+ modelRuntimeCache.set(agentDir, created);
27275
+ created.catch(() => {
27276
+ modelRuntimeCache.delete(agentDir);
27277
+ });
27278
+ return created;
27279
+ }
27280
+ async function resolveModel(config, options = {}) {
27358
27281
  if (!config.model) {
27359
27282
  throw new ConfigError('No model configured. Provide --model-provider and --model-id on the command line, or set the "model" key (with provider and id) in the config file.');
27360
27283
  }
27361
- return resolveRegisteredModel(config.model);
27284
+ const runtime = options.runtime ?? await getModelRuntime(resolveAgentDir(options));
27285
+ return resolveRegisteredModel(runtime, config.model);
27362
27286
  }
27363
- function resolveAgentModelCore(config, localOptions = {}) {
27364
- const modelRef = config.model;
27365
- const registered = resolveBuiltInModel(modelRef);
27366
- const needsLocal = modelRef === undefined || registered === undefined;
27367
- const localModelOptions = { ...localOptions, modelId: modelRef?.id };
27368
- const local = needsLocal ? loadLocalAutoRAGModel(localModelOptions) : undefined;
27369
- const model = registered ?? (modelRef === undefined || modelRef.provider === local?.provider ? local?.model : resolveRegisteredModel(modelRef));
27370
- const configuredEndpoint = isConfiguredEndpoint(modelRef);
27371
- const usesConfiguredEndpoint = configuredEndpoint;
27372
- const env = localOptions.env ?? process.env;
27373
- const fromLocal = registered === undefined && (modelRef === undefined || modelRef.provider === local?.provider);
27374
- const catalog = registered !== undefined && !configuredEndpoint;
27375
- if (local === undefined && !usesConfiguredEndpoint) {
27376
- return {
27377
- model,
27378
- modelRef,
27379
- fromLocal,
27380
- configuredEndpoint,
27381
- catalog,
27382
- local,
27383
- usesConfiguredEndpoint,
27384
- env
27385
- };
27386
- }
27387
- const providerApiKeys = {};
27388
- if (local !== undefined)
27389
- providerApiKeys[local.provider] = local.apiKey;
27390
- for (const ref of [modelRef]) {
27391
- if (!isConfiguredEndpoint(ref))
27392
- continue;
27393
- const envName = configuredApiKeyEnv(ref);
27394
- const value = env[envName];
27395
- if (typeof value === "string" && value.length > 0) {
27396
- providerApiKeys[ref.provider] = value;
27397
- }
27398
- }
27399
- const apiKey = local !== undefined && (modelRef === undefined || modelRef.provider === local.provider) ? local.apiKey : providerApiKeys[model.provider] !== undefined && usesConfiguredEndpoint ? providerApiKeys[model.provider] : undefined;
27287
+ function localFallbackOptions(options, modelId) {
27400
27288
  return {
27401
- model,
27402
- ...apiKey !== undefined ? { apiKey } : {},
27403
- ...Object.keys(providerApiKeys).length > 0 ? { providerApiKeys } : {},
27404
- modelRef,
27405
- fromLocal,
27406
- configuredEndpoint,
27407
- catalog,
27408
- local,
27409
- usesConfiguredEndpoint,
27410
- env
27289
+ ...options.configPath !== undefined ? { configPath: options.configPath } : {},
27290
+ ...options.env !== undefined ? { env: options.env } : {},
27291
+ ...modelId !== undefined ? { modelId } : {}
27411
27292
  };
27412
27293
  }
27413
- function resolveAgentModel(config, localOptions = {}) {
27414
- const core = resolveAgentModelCore(config, localOptions);
27294
+ function localRuntimeAuth(local) {
27415
27295
  return {
27416
- model: core.model,
27417
- ...core.apiKey !== undefined ? { apiKey: core.apiKey } : {},
27418
- ...core.providerApiKeys !== undefined ? { providerApiKeys: core.providerApiKeys } : {}
27296
+ apiKey: local.apiKey,
27297
+ providerApiKeys: { [local.provider]: local.apiKey },
27298
+ present: true,
27299
+ source: "local_runtime"
27419
27300
  };
27420
27301
  }
27421
- function providerApiKeyEnvName(provider) {
27422
- return `${provider.replace(/[^A-Za-z0-9_]/g, "_").toUpperCase()}_API_KEY`;
27423
- }
27424
- function resolveRoleAuth(model, fromLocal, local, providerApiKeys, configuredEndpoint, apiKeyEnv, env) {
27425
- if (fromLocal && local !== undefined && model.provider === local.provider) {
27426
- return { present: true, source: "local_runtime" };
27302
+ async function resolvePiDefaultModel(runtime, options) {
27303
+ let provider;
27304
+ let id;
27305
+ try {
27306
+ const settings = SettingsManager2.create(options.cwd ?? process.cwd(), resolveAgentDir(options));
27307
+ provider = settings.getDefaultProvider();
27308
+ id = settings.getDefaultModel();
27309
+ } catch {
27310
+ return;
27427
27311
  }
27428
- if (configuredEndpoint) {
27429
- const envName = apiKeyEnv ?? providerApiKeyEnvName(model.provider);
27430
- if (providerApiKeys?.[model.provider] !== undefined) {
27431
- return { present: true, source: "env", envName };
27432
- }
27433
- const fromEnv = env[envName] ?? process.env[envName];
27434
- if (typeof fromEnv === "string" && fromEnv.length > 0) {
27435
- return { present: true, source: "env", envName };
27436
- }
27437
- return { present: false, source: "none", envName };
27312
+ if (provider === undefined || id === undefined)
27313
+ return;
27314
+ const model = runtime.getModel(provider, id);
27315
+ if (model === undefined)
27316
+ return;
27317
+ try {
27318
+ if (await runtime.checkAuth(provider) === undefined)
27319
+ return;
27320
+ } catch {
27321
+ return;
27438
27322
  }
27323
+ return model;
27324
+ }
27325
+ function resolveConfiguredEndpointAuth(reference, model, env) {
27326
+ const envName = configuredApiKeyEnv(reference);
27327
+ const value = env[envName];
27328
+ const providerApiKeys = typeof value === "string" && value.length > 0 ? { [model.provider]: value } : undefined;
27329
+ const fromProcessEnv = process.env[envName];
27330
+ const present = providerApiKeys !== undefined || typeof fromProcessEnv === "string" && fromProcessEnv.length > 0;
27331
+ return {
27332
+ ...providerApiKeys !== undefined ? { apiKey: providerApiKeys[model.provider], providerApiKeys } : {},
27333
+ present,
27334
+ source: present ? "env" : "none",
27335
+ envName
27336
+ };
27337
+ }
27338
+ async function resolveCatalogAuth(runtime, model, env) {
27339
+ try {
27340
+ const result = await runtime.getAuth(model);
27341
+ if (result !== undefined) {
27342
+ const apiKey = result.auth.apiKey;
27343
+ if (typeof apiKey === "string" && apiKey.length > 0) {
27344
+ return { apiKey, providerApiKeys: { [model.provider]: apiKey }, present: true, source: "pi_auth" };
27345
+ }
27346
+ return { present: true, source: "pi_auth" };
27347
+ }
27348
+ } catch {}
27439
27349
  const envKeys = findEnvKeys(model.provider);
27440
27350
  if (envKeys !== undefined && envKeys.length > 0) {
27441
27351
  for (const key of envKeys) {
@@ -27450,21 +27360,102 @@ function resolveRoleAuth(model, fromLocal, local, providerApiKeys, configuredEnd
27450
27360
  }
27451
27361
  return { present: false, source: "none", envName: envKeys[0] };
27452
27362
  }
27453
- const catalogKey = getEnvApiKey(model.provider);
27454
- if (catalogKey !== undefined) {
27363
+ if (getEnvApiKey(model.provider) !== undefined) {
27455
27364
  return { present: true, source: "catalog" };
27456
27365
  }
27457
27366
  return { present: false, source: "none", envName: providerApiKeyEnvName(model.provider) };
27458
27367
  }
27368
+ async function resolveAgentModelCore(config, options = {}) {
27369
+ const env = options.env ?? process.env;
27370
+ const runtime = options.runtime ?? await getModelRuntime(resolveAgentDir(options));
27371
+ const modelRef = config.model;
27372
+ if (modelRef !== undefined && isConfiguredEndpoint(modelRef)) {
27373
+ const catalogModel = resolveRuntimeCatalogModel(runtime, modelRef);
27374
+ const model = catalogModel ?? buildModelFromConfiguredEndpoint(modelRef);
27375
+ return {
27376
+ model,
27377
+ modelRef,
27378
+ fromLocal: false,
27379
+ configuredEndpoint: true,
27380
+ catalog: catalogModel !== undefined,
27381
+ local: undefined,
27382
+ env,
27383
+ auth: resolveConfiguredEndpointAuth(modelRef, model, env)
27384
+ };
27385
+ }
27386
+ const registered = resolveBuiltInModel(runtime, modelRef);
27387
+ if (registered !== undefined) {
27388
+ return {
27389
+ model: registered,
27390
+ modelRef,
27391
+ fromLocal: false,
27392
+ configuredEndpoint: false,
27393
+ catalog: true,
27394
+ local: undefined,
27395
+ env,
27396
+ auth: await resolveCatalogAuth(runtime, registered, env)
27397
+ };
27398
+ }
27399
+ if (modelRef === undefined) {
27400
+ const piDefault = await resolvePiDefaultModel(runtime, options);
27401
+ if (piDefault !== undefined) {
27402
+ return {
27403
+ model: piDefault,
27404
+ modelRef,
27405
+ fromLocal: false,
27406
+ configuredEndpoint: false,
27407
+ catalog: true,
27408
+ local: undefined,
27409
+ env,
27410
+ auth: await resolveCatalogAuth(runtime, piDefault, env)
27411
+ };
27412
+ }
27413
+ const local = loadLocalAutoRAGModel(localFallbackOptions(options, undefined));
27414
+ return {
27415
+ model: local.model,
27416
+ modelRef,
27417
+ fromLocal: true,
27418
+ configuredEndpoint: false,
27419
+ catalog: false,
27420
+ local,
27421
+ env,
27422
+ auth: localRuntimeAuth(local)
27423
+ };
27424
+ }
27425
+ const local = loadLocalAutoRAGModel(localFallbackOptions(options, modelRef.id));
27426
+ const fromLocal = modelRef.provider === local.provider;
27427
+ const model = fromLocal ? local.model : resolveRegisteredModel(runtime, modelRef);
27428
+ return {
27429
+ model,
27430
+ modelRef,
27431
+ fromLocal,
27432
+ configuredEndpoint: false,
27433
+ catalog: !fromLocal,
27434
+ local: fromLocal ? local : undefined,
27435
+ env,
27436
+ auth: fromLocal ? localRuntimeAuth(local) : await resolveCatalogAuth(runtime, model, env)
27437
+ };
27438
+ }
27439
+ async function resolveAgentModel(config, options = {}) {
27440
+ const core = await resolveAgentModelCore(config, options);
27441
+ return {
27442
+ model: core.model,
27443
+ ...core.auth.apiKey !== undefined ? { apiKey: core.auth.apiKey } : {},
27444
+ ...core.auth.providerApiKeys !== undefined ? { providerApiKeys: core.auth.providerApiKeys } : {}
27445
+ };
27446
+ }
27447
+ function providerApiKeyEnvName(provider) {
27448
+ return `${provider.replace(/[^A-Za-z0-9_]/g, "_").toUpperCase()}_API_KEY`;
27449
+ }
27459
27450
  function resolveRoleSource(ref, fromLocal, configuredEndpoint, catalog) {
27460
- if (ref === undefined)
27461
- return "local_runtime";
27462
27451
  if (configuredEndpoint)
27463
27452
  return "config";
27464
27453
  if (fromLocal)
27465
27454
  return "mixed";
27466
27455
  if (catalog)
27467
27456
  return "catalog";
27457
+ if (ref === undefined)
27458
+ return "local_runtime";
27468
27459
  return "config";
27469
27460
  }
27470
27461
  function buildResolvedRole(model, auth, resolutionSource) {
@@ -27481,14 +27472,18 @@ function buildResolvedRole(model, auth, resolutionSource) {
27481
27472
  resolutionSource
27482
27473
  };
27483
27474
  }
27484
- function resolveAgentModelDetailed(config, localOptions = {}) {
27485
- const core = resolveAgentModelCore(config, localOptions);
27486
- const auth = resolveRoleAuth(core.model, core.fromLocal, core.local, core.providerApiKeys, core.configuredEndpoint, core.modelRef !== undefined ? configuredApiKeyEnv(core.modelRef) : undefined, core.env);
27475
+ async function resolveAgentModelDetailed(config, options = {}) {
27476
+ const core = await resolveAgentModelCore(config, options);
27477
+ const auth = {
27478
+ present: core.auth.present,
27479
+ source: core.auth.source,
27480
+ ...core.auth.envName !== undefined ? { envName: core.auth.envName } : {}
27481
+ };
27487
27482
  const source = resolveRoleSource(core.modelRef, core.fromLocal, core.configuredEndpoint, core.catalog);
27488
27483
  return {
27489
27484
  model: core.model,
27490
- ...core.apiKey !== undefined ? { apiKey: core.apiKey } : {},
27491
- ...core.providerApiKeys !== undefined ? { providerApiKeys: core.providerApiKeys } : {},
27485
+ ...core.auth.apiKey !== undefined ? { apiKey: core.auth.apiKey } : {},
27486
+ ...core.auth.providerApiKeys !== undefined ? { providerApiKeys: core.auth.providerApiKeys } : {},
27492
27487
  role: buildResolvedRole(core.model, auth, source)
27493
27488
  };
27494
27489
  }
@@ -27502,7 +27497,7 @@ function writeConfigObject(path, config) {
27502
27497
  if (config === null || typeof config !== "object" || Array.isArray(config)) {
27503
27498
  throw new ConfigError("Config file must be a JSON object");
27504
27499
  }
27505
- mkdirSync24(dirname22(path), { recursive: true });
27500
+ mkdirSync24(dirname21(path), { recursive: true });
27506
27501
  const contents = `${JSON.stringify(config, null, 2)}
27507
27502
  `;
27508
27503
  const lock = acquireConfigWriteLock(path);
@@ -27515,7 +27510,7 @@ function writeConfigObject(path, config) {
27515
27510
  function writeDefaultConfig(path, partial, opts = {}) {
27516
27511
  const cwd = resolve15(opts.cwd ?? process.cwd());
27517
27512
  const workspacePath = resolvePersistedPath(partial.workspacePath ?? ".", cwd);
27518
- const memoryPath = partial.memoryPath === undefined ? join33(resolveAutoRAGHome(opts.env), "memory.json") : resolvePersistedPath(partial.memoryPath, workspacePath);
27513
+ const memoryPath = partial.memoryPath === undefined ? join34(resolveAutoRAGHome(opts.env), "memory.json") : resolvePersistedPath(partial.memoryPath, workspacePath);
27519
27514
  const full = {
27520
27515
  searchPaths: resolveSearchPaths(partial.searchPaths ?? ["."], cwd),
27521
27516
  workspacePath,
@@ -27546,7 +27541,7 @@ function writeDefaultConfig(path, partial, opts = {}) {
27546
27541
  full.p2p = normalizeP2pConfig(partial.p2p);
27547
27542
  else
27548
27543
  full.p2p = { enabled: false };
27549
- mkdirSync24(dirname22(path), { recursive: true });
27544
+ mkdirSync24(dirname21(path), { recursive: true });
27550
27545
  const contents = `${JSON.stringify(full, null, 2)}
27551
27546
  `;
27552
27547
  const lock = acquireConfigWriteLock(path);
@@ -27569,7 +27564,7 @@ function writeDefaultConfig(path, partial, opts = {}) {
27569
27564
  lock.release();
27570
27565
  }
27571
27566
  }
27572
- var DEFAULT_CONFIG_FILENAME = "config.json", LEGACY_CONFIG_FILENAME = "autorag.config.json", CONFIG_LOCK_RETRY_MS = 10, CONFIG_LOCK_TIMEOUT_MS = 1e4, CONFIG_LOCK_STALE_MS = 30000, ConfigError, AGENT_MODEL_APIS, AGENT_MODEL_INPUTS, API_KEY_ENV_PATTERN2, POSITIVE_INT_FIELDS, EMBEDDER_ALLOWLIST, MINSYNC_ALLOWLIST, MINSYNC_LEGACY_IGNORED, P2P_ALLOWLIST, P2P_QUOTA_ALLOWLIST, LIMITS_ALLOWLIST, LIMITS_PREFETCH_ALLOWLIST, RERANK_ALLOWLIST, UNKNOWN_MODEL_HINT = "Add baseUrl (and optional api/apiKeyEnv) for an OpenAI-compatible endpoint outside the pi-ai catalog, or use a pi-ai catalog model id.";
27567
+ var DEFAULT_CONFIG_FILENAME = "config.json", LEGACY_CONFIG_FILENAME = "autorag.config.json", CONFIG_LOCK_RETRY_MS = 10, CONFIG_LOCK_TIMEOUT_MS = 1e4, CONFIG_LOCK_STALE_MS = 30000, ConfigError, AGENT_MODEL_APIS, AGENT_MODEL_INPUTS, API_KEY_ENV_PATTERN2, POSITIVE_INT_FIELDS, EMBEDDER_ALLOWLIST, MINSYNC_ALLOWLIST, MINSYNC_LEGACY_IGNORED, P2P_ALLOWLIST, P2P_QUOTA_ALLOWLIST, LIMITS_ALLOWLIST, LIMITS_PREFETCH_ALLOWLIST, RERANK_ALLOWLIST, UNKNOWN_MODEL_HINT = "Add baseUrl (and optional api/apiKeyEnv) for an OpenAI-compatible endpoint outside the pi-ai catalog, or use a pi-ai catalog model id.", modelRuntimeCache;
27573
27568
  var init_config2 = __esm(() => {
27574
27569
  init_local_model();
27575
27570
  init_home();
@@ -27647,6 +27642,7 @@ var init_config2 = __esm(() => {
27647
27642
  sectionLimit: true
27648
27643
  };
27649
27644
  RERANK_ALLOWLIST = new Set(["enabled", "provider", "model", "apiKeyEnv", "baseUrl", "topN", "timeoutMs"]);
27645
+ modelRuntimeCache = new Map;
27650
27646
  });
27651
27647
 
27652
27648
  // src/core.ts
@@ -28062,6 +28058,7 @@ export {
28062
28058
  RetrievalMethodRegistry,
28063
28059
  RssConnector,
28064
28060
  RssSkill,
28061
+ SUPPORTED_RERANK_PROVIDERS,
28065
28062
  SlackSkill,
28066
28063
  SlacrawlClient,
28067
28064
  SpotlightConnector,