@autorag/librarian 2.10.0 → 2.10.2

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.
Files changed (94) hide show
  1. package/LICENSE +195 -21
  2. package/NOTICE +16 -23
  3. package/README.md +399 -182
  4. package/dist/agent/agent.d.ts +163 -20
  5. package/dist/agent/context-token-guard.d.ts +23 -0
  6. package/dist/agent/evidence-ledger.d.ts +54 -5
  7. package/dist/agent/evidence-persistence.d.ts +24 -0
  8. package/dist/agent/jev-extension.d.ts +7 -4
  9. package/dist/agent/jikji-find-tool.d.ts +1 -0
  10. package/dist/agent/pi-session.d.ts +35 -2
  11. package/dist/agent/request-limits.d.ts +20 -0
  12. package/dist/agent/search-all-tool.d.ts +1 -0
  13. package/dist/agent/search-documents.d.ts +1 -1
  14. package/dist/agent/search-single-datasource-tool.d.ts +1 -0
  15. package/dist/agent/system-prompt.d.ts +0 -2
  16. package/dist/agent/tool-burst-guard.d.ts +26 -0
  17. package/dist/cli/config.d.ts +39 -23
  18. package/dist/cli/index.js +4195 -1478
  19. package/dist/cloud/config.d.ts +33 -9
  20. package/dist/cloud/credential.d.ts +17 -0
  21. package/dist/cloud/errors.d.ts +6 -6
  22. package/dist/cloud/index.d.ts +5 -4
  23. package/dist/cloud/jev-backend.d.ts +92 -0
  24. package/dist/cloud/models.d.ts +4 -4
  25. package/dist/cloud/oauth-login.d.ts +3 -3
  26. package/dist/cloud/provider.d.ts +16 -11
  27. package/dist/cloud/token.d.ts +2 -2
  28. package/dist/core.d.ts +2 -1
  29. package/dist/core.js +4200 -1506
  30. package/dist/datasource/aliased-skill.d.ts +2 -2
  31. package/dist/datasource/connector-skill.d.ts +2 -2
  32. package/dist/datasource/crawler-skill.d.ts +19 -2
  33. package/dist/datasource/described-skill.d.ts +2 -2
  34. package/dist/datasource/index.d.ts +1 -1
  35. package/dist/datasource/retry.d.ts +49 -0
  36. package/dist/datasource/sidecar/config.d.ts +26 -0
  37. package/dist/datasource/sidecar/descriptors.d.ts +67 -0
  38. package/dist/datasource/sidecar/fusion.d.ts +25 -0
  39. package/dist/datasource/sidecar/index.d.ts +131 -0
  40. package/dist/datasource/sidecar/methods.d.ts +27 -0
  41. package/dist/datasource/skills/clawgallery/skill.d.ts +4 -4
  42. package/dist/datasource/skills/discrawl/skill.d.ts +5 -5
  43. package/dist/datasource/skills/github-gist/skill.d.ts +2 -2
  44. package/dist/datasource/skills/lazykatok/skill.d.ts +5 -5
  45. package/dist/datasource/skills/mailcrawl/skill.d.ts +2 -2
  46. package/dist/datasource/skills/obsidian/skill.d.ts +5 -5
  47. package/dist/datasource/types.d.ts +16 -2
  48. package/dist/embedding-runtime/cache.d.ts +9 -0
  49. package/dist/embedding-runtime/index.d.ts +6 -6
  50. package/dist/embedding-runtime/manifest.d.ts +0 -12
  51. package/dist/embedding-runtime/types.d.ts +1 -1
  52. package/dist/index.d.ts +1 -2
  53. package/dist/index.js +4454 -1757
  54. package/dist/jikji/client.d.ts +13 -2
  55. package/dist/jikji/index.d.ts +1 -1
  56. package/dist/jikji/path-map.d.ts +9 -0
  57. package/dist/jikji/prepare-budget.d.ts +18 -0
  58. package/dist/jikji/serial-queue.d.ts +17 -0
  59. package/dist/jikji/types.d.ts +17 -0
  60. package/dist/mcp/index.js +4442 -1748
  61. package/dist/minsync/client.d.ts +6 -4
  62. package/dist/minsync/installer.d.ts +1 -1
  63. package/dist/minsync/method.d.ts +1 -1
  64. package/dist/minsync/process.d.ts +1 -0
  65. package/dist/minsync/types.d.ts +2 -2
  66. package/dist/mirror/atomic-write.d.ts +6 -0
  67. package/dist/mirror/index-store.d.ts +8 -1
  68. package/dist/mirror/index.d.ts +2 -2
  69. package/dist/mirror/sync.d.ts +57 -1
  70. package/dist/p2p/simplex-server.d.ts +0 -1
  71. package/dist/parser/defaults.d.ts +14 -4
  72. package/dist/parser/errors.d.ts +10 -0
  73. package/dist/parser/isolated.d.ts +77 -0
  74. package/dist/parser/kordoc.d.ts +1 -0
  75. package/dist/parser/ocr-engines.d.ts +6 -0
  76. package/dist/parser/parse-worker.d.ts +1 -0
  77. package/dist/parser/parse-worker.js +780 -0
  78. package/dist/parser/types.d.ts +5 -0
  79. package/dist/process/abort-reason.d.ts +2 -0
  80. package/dist/retrieval/index.d.ts +1 -1
  81. package/dist/retrieval/rerank.d.ts +28 -5
  82. package/licenses/embedding-assets.json +0 -35
  83. package/package.json +26 -29
  84. package/skills/autorag/SKILL.md +3 -2
  85. package/skills/autorag-doctor/SKILL.md +7 -1
  86. package/skills/autorag-lite-setup/SKILL.md +3 -3
  87. package/skills/autorag-setup/SKILL.md +43 -18
  88. package/dist/manifest/index.d.ts +0 -2
  89. package/dist/manifest/loader.d.ts +0 -3
  90. package/dist/manifest/types.d.ts +0 -8
  91. package/licenses/gemma-notice.txt +0 -24
  92. package/licenses/gemma-section-3.2-flow-down.txt +0 -9
  93. package/licenses/gemma-terms-of-use.html +0 -4750
  94. package/licenses/gemma-terms-of-use.txt +0 -158
@@ -1,5 +1,5 @@
1
1
  import type { RetrievalMethod } from "../retrieval/types.js";
2
- import type { DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, SourceDescription } from "./types.js";
2
+ import type { DatasourceIndexOptions, DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, SourceDescription } from "./types.js";
3
3
  export interface AliasDatasourceSkillOptions {
4
4
  readonly alias: string;
5
5
  readonly channelIds?: readonly string[];
@@ -19,7 +19,7 @@ export declare class AliasedDatasourceSkill implements DatasourceSkill {
19
19
  constructor(skill: DatasourceSkill, options: AliasDatasourceSkillOptions);
20
20
  describe(): DatasourceSkillDescriptor;
21
21
  polling(): import("./types.js").PollingMetadata;
22
- index(): Promise<DatasourceIndexResult>;
22
+ index(options?: DatasourceIndexOptions): Promise<DatasourceIndexResult>;
23
23
  retrievalMethods(): readonly RetrievalMethod[];
24
24
  describeSources(): readonly SourceDescription[];
25
25
  skillManifest(): DatasourceSkillManifest;
@@ -22,7 +22,7 @@
22
22
  import type { RetrievalMethod, RetrievalMethodDescriptor, RetrievalOptions, RetrievalResult } from "../retrieval/types.js";
23
23
  import { DatasourceChunkStore } from "./chunk-store.js";
24
24
  import type { DatasourceConnector } from "./connector.js";
25
- import type { DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "./types.js";
25
+ import type { DatasourceIndexOptions, DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "./types.js";
26
26
  /** Static identity/behavior shared by all instances of one skill kind. */
27
27
  export interface ConnectorSkillDefinition {
28
28
  /** Stable skill name and datasource id, e.g. `"slack"`. */
@@ -86,7 +86,7 @@ export declare class ConnectorDatasourceSkill implements DatasourceSkill {
86
86
  constructor(definition: ConnectorSkillDefinition, options: ConnectorSkillOptions);
87
87
  describe(): DatasourceSkillDescriptor;
88
88
  polling(): PollingMetadata;
89
- index(): Promise<DatasourceIndexResult>;
89
+ index(options?: DatasourceIndexOptions): Promise<DatasourceIndexResult>;
90
90
  retrievalMethods(): readonly RetrievalMethod[];
91
91
  describeSources(): readonly SourceDescription[];
92
92
  skillManifest(): DatasourceSkillManifest;
@@ -1,6 +1,7 @@
1
1
  import type { RetrievalMethod } from "../retrieval/types.js";
2
2
  import type { CrawlerSearchOptions, CrawlerSearchResult, CrawlerSyncResult } from "./crawler-types.js";
3
- import type { DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "./types.js";
3
+ import { type CrawlerSidecarOptions } from "./sidecar/index.js";
4
+ import type { DatasourceIndexOptions, DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "./types.js";
4
5
  export interface CrawlerSkillClient {
5
6
  sync(signal?: AbortSignal): Promise<CrawlerSyncResult>;
6
7
  search(query: string, options?: CrawlerSearchOptions): Promise<CrawlerSearchResult>;
@@ -27,6 +28,12 @@ export interface CrawlerDatasourceSkillOptions {
27
28
  /** Omitted/empty means search every chat/channel. */
28
29
  readonly channelIds?: readonly string[];
29
30
  readonly channelNames?: readonly string[];
31
+ /**
32
+ * Opt-in read-only sidecar over the crawler's own SQLite archive: adds BM25-ranked,
33
+ * semantic and hybrid methods next to the CLI-backed FTS method. The crawler database
34
+ * is never written; sidecar state lives in `sidecarDbPath`.
35
+ */
36
+ readonly sidecar?: CrawlerSidecarOptions;
30
37
  }
31
38
  export declare class CrawlerDatasourceSkill implements DatasourceSkill {
32
39
  private readonly definition;
@@ -37,12 +44,22 @@ export declare class CrawlerDatasourceSkill implements DatasourceSkill {
37
44
  private readonly tags;
38
45
  private readonly channelIds;
39
46
  private readonly channelNames;
47
+ private readonly sidecar;
40
48
  private lastIndexedAt;
41
49
  constructor(definition: CrawlerDatasourceDefinition, options: CrawlerDatasourceSkillOptions);
42
50
  describe(): DatasourceSkillDescriptor;
43
51
  polling(): PollingMetadata;
44
- index(): Promise<DatasourceIndexResult>;
52
+ index(options?: DatasourceIndexOptions): Promise<DatasourceIndexResult>;
53
+ /**
54
+ * Embed new crawler messages into the sidecar. Never fails the index (the CLI sync already succeeded and BM25
55
+ * stays available): any sidecar problem, including a thrown database error, becomes a warning. A bounded sync
56
+ * that left a backlog says so, so a partial semantic index is not mistaken for a complete one.
57
+ */
58
+ private syncSidecar;
59
+ /** Release the sidecar's database handles. Safe to call repeatedly; later use reopens them. */
60
+ close(): void;
45
61
  retrievalMethods(): readonly RetrievalMethod[];
62
+ private cliMethod;
46
63
  describeSources(): readonly SourceDescription[];
47
64
  skillManifest(): DatasourceSkillManifest;
48
65
  private fail;
@@ -1,5 +1,5 @@
1
1
  import type { RetrievalMethod } from "../retrieval/types.js";
2
- import type { DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "./types.js";
2
+ import type { DatasourceIndexOptions, DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "./types.js";
3
3
  /**
4
4
  * Adds operator-authored context to a configured datasource without changing
5
5
  * its backend, access identity, or retrieval methods.
@@ -10,7 +10,7 @@ export declare class DescribedDatasourceSkill implements DatasourceSkill {
10
10
  constructor(skill: DatasourceSkill, description: string);
11
11
  describe(): DatasourceSkillDescriptor;
12
12
  polling(): PollingMetadata;
13
- index(): Promise<DatasourceIndexResult>;
13
+ index(options?: DatasourceIndexOptions): Promise<DatasourceIndexResult>;
14
14
  retrievalMethods(): readonly RetrievalMethod[];
15
15
  describeSources(): readonly SourceDescription[];
16
16
  skillManifest(): DatasourceSkillManifest;
@@ -22,4 +22,4 @@ export { SlackSkill, type SlackSkillOptions, SlacrawlClient, type SlacrawlOption
22
22
  export { SpotlightConnector, type SpotlightConnectorOptions, SpotlightSkill, type SpotlightSkillOptions, } from "./skills/spotlight/index.js";
23
23
  export { TelecrawlClient, type TelecrawlOptions, TelecrawlSkill, type TelecrawlSkillOptions, } from "./skills/telecrawl/index.js";
24
24
  export { WacrawlClient, type WacrawlOptions, WacrawlSkill, type WacrawlSkillOptions } from "./skills/wacrawl/index.js";
25
- export type { DatasourceDiagnostic, DatasourceDiagnosticCode, DatasourceIndexFail, DatasourceIndexOk, DatasourceIndexResult, DatasourceInstance, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription, } from "./types.js";
25
+ export type { DatasourceDiagnostic, DatasourceDiagnosticCode, DatasourceIndexFail, DatasourceIndexOk, DatasourceIndexOptions, DatasourceIndexResult, DatasourceInstance, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription, } from "./types.js";
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Shared retry/backoff policy for datasource `index()` calls.
3
+ *
4
+ * Failure causes differ per datasource (HTTP status, CLI exit reason, ...), so
5
+ * no attempt is made to classify them. {@link indexWithRetry} retries every
6
+ * failed or thrown `index()` with jittered exponential backoff and, once the
7
+ * retries are used up, reports that datasource as failed so the refresh moves
8
+ * on to the next one.
9
+ *
10
+ * Process-tree termination of a timed-out CLI is a separate concern (#1587,
11
+ * #1586); this module never touches the spawn code.
12
+ */
13
+ import type { DatasourceIndexResult, DatasourceSkill } from "./types.js";
14
+ export interface DatasourceRetryPolicy {
15
+ /** Re-runs after the first call; `0` disables retrying. */
16
+ readonly maxRetries: number;
17
+ /** Backoff before the first retry; doubles for each later retry. */
18
+ readonly baseDelayMs: number;
19
+ /** Upper bound on one backoff step (before jitter). */
20
+ readonly maxDelayMs: number;
21
+ }
22
+ export interface DatasourceRetryOptions extends Partial<DatasourceRetryPolicy> {
23
+ /** Jitter source in `[0, 1]`; injectable for deterministic tests. */
24
+ readonly random?: () => number;
25
+ /** Delay implementation; injectable so tests and hosts need not wait in real time. */
26
+ readonly sleep?: (ms: number) => Promise<void>;
27
+ }
28
+ /** Two retries (three calls in total) with 1s then 2s of backoff, jittered. */
29
+ export declare const DEFAULT_DATASOURCE_RETRY_POLICY: DatasourceRetryPolicy;
30
+ /**
31
+ * Backoff before retry number `retry` (1-based): `baseDelayMs * 2^(retry-1)`
32
+ * capped at `maxDelayMs`, then jittered into the upper half of that step so
33
+ * simultaneous refreshes do not hammer the same upstream in lockstep.
34
+ */
35
+ export declare function datasourceRetryDelayMs(retry: number, policy: DatasourceRetryPolicy & {
36
+ readonly random?: () => number;
37
+ }): number;
38
+ /**
39
+ * Run `skill.index()`, retrying any failure (a failed result or a throw). A
40
+ * first-time success is returned untouched. Otherwise the result carries the
41
+ * total `attempts`; an exhausted failure also carries `attempts` in its message
42
+ * and last diagnostic, and a late success carries an info diagnostic naming the
43
+ * last error it recovered from. A thrown `index()` becomes a
44
+ * `datasource-index-failed` result.
45
+ *
46
+ * A cancelled `signal` is not a datasource failure: it is rethrown at once
47
+ * (also from the backoff wait) instead of being retried or reported.
48
+ */
49
+ export declare function indexWithRetry(skill: DatasourceSkill, options?: DatasourceRetryOptions, signal?: AbortSignal): Promise<DatasourceIndexResult>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Turns a datasource's `connector.sidecar` config into {@link CrawlerSidecarOptions}.
3
+ *
4
+ * On by default for every datasource that has a crawler descriptor; opt out with
5
+ *
6
+ * "connector": { "sidecar": false }
7
+ *
8
+ * or tune it:
9
+ *
10
+ * "connector": { "sidecar": { "crawlerDbPath": "~/.slacrawl/slacrawl.db", "semantic": false } }
11
+ *
12
+ * The sidecar's own database always lives under the AutoRAG workspace, one file
13
+ * per datasource instance, never next to (or inside) the crawler's archive.
14
+ */
15
+ import type { CrawlerDescriptor } from "./descriptors.js";
16
+ import type { CrawlerSidecarOptions } from "./index.js";
17
+ export interface ResolveSidecarInput {
18
+ readonly descriptor: CrawlerDescriptor;
19
+ readonly connector: Record<string, unknown> | undefined;
20
+ readonly workspaceRoot: string | undefined;
21
+ readonly registrationName: string;
22
+ readonly instanceId: string;
23
+ /** Where the crawler keeps its archive when the user did not say. */
24
+ readonly defaultCrawlerDb: string;
25
+ }
26
+ export declare function resolveSidecarOptions(input: ResolveSidecarInput): CrawlerSidecarOptions | undefined;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Declarative description of a crawler's read-only SQLite schema. The sidecar
3
+ * engine (index.ts) is crawler-agnostic: everything that differs between
4
+ * slacrawl, telecrawl, wacrawl and notcrawl is expressed here as SQL fragments.
5
+ *
6
+ * Every SQL fragment is a trusted constant authored in this file. User input
7
+ * (the search query, workspace id) is only ever bound as a parameter.
8
+ *
9
+ * The crawler database is opened read-only and ATTACHed; the sidecar owns a
10
+ * separate database file, so a crawler that rebuilds, migrates, purges or
11
+ * vacuums its own file can never lose or corrupt sidecar state.
12
+ */
13
+ export interface CrawlerDescriptor {
14
+ readonly id: string;
15
+ /**
16
+ * True when the crawler's own TOML config (`connector.configPath`) can relocate its archive via
17
+ * `db_path`. The sidecar then follows that setting instead of assuming the default archive.
18
+ */
19
+ readonly archivePathInConfig?: boolean;
20
+ /** `message_key` stored in the sidecar for each row; unique per message within one crawler DB. */
21
+ readonly keyExpression: string;
22
+ /**
23
+ * Public chunk id for a stored key. MUST equal the id the crawler's CLI client derives for the
24
+ * same message (see each skill's `parseHits`), so the retrieval merger deduplicates a message
25
+ * found by both the CLI-backed and the sidecar methods.
26
+ */
27
+ readonly chunkId: (key: string, metadata: Readonly<Record<string, string>>) => string;
28
+ /** FROM + JOINs exposing alias `m` (message-like row) and any lookup aliases used below. */
29
+ readonly fromClause: string;
30
+ /** Row visibility predicate: excludes soft-deleted rows. May reference a `:scope` parameter when `scopeColumn` is set. */
31
+ readonly liveWhere: string;
32
+ /** Column that the optional workspace/account scope filters on; omitted when the crawler has one account per DB. */
33
+ readonly scopeExpression?: string;
34
+ /** SQL returning the embeddable/displayed body of the row. */
35
+ readonly textExpression: string;
36
+ /** Optional extra text prepended to the embedding input (title, channel). */
37
+ readonly titleExpression?: string;
38
+ /** Seconds-since-epoch expression used for `publishedAt`; omitted when unknown. */
39
+ readonly epochSecondsExpression?: string;
40
+ /**
41
+ * FTS5 relation joined to the message row. `joinOn` ties the FTS row to alias `m`;
42
+ * `table` is the FTS table (also the argument to bm25()).
43
+ */
44
+ readonly fts: {
45
+ readonly table: string;
46
+ readonly joinOn: string;
47
+ };
48
+ /** Extra result columns mapped into hit metadata: a SQL expression and the metadata key it fills. */
49
+ readonly metadata: readonly {
50
+ readonly sql: string;
51
+ readonly key: string;
52
+ }[];
53
+ /**
54
+ * SQL for the chat/channel id and name the allowlist (`channels.ids/names`) matches. Pushed into the
55
+ * row predicate, so excluded chats are never searched, embedded, or kept in the sidecar.
56
+ */
57
+ readonly channelIdExpression: string;
58
+ readonly channelNameExpression: string;
59
+ /** Path-opaque label for the hierarchy: ["workspaces", ws, "channels", name] etc. */
60
+ readonly hierarchy: (metadata: Readonly<Record<string, unknown>>) => readonly string[];
61
+ }
62
+ export declare const CRAWLER_DESCRIPTORS: {
63
+ readonly slack: CrawlerDescriptor;
64
+ readonly telegram: CrawlerDescriptor;
65
+ readonly whatsapp: CrawlerDescriptor;
66
+ };
67
+ export type SidecarCrawlerId = keyof typeof CRAWLER_DESCRIPTORS;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Pure ranking primitives shared by every crawler sidecar: float32 vector
3
+ * (de)serialization, cosine top-k, and reciprocal rank fusion. No I/O.
4
+ */
5
+ export declare function encodeVector(vector: readonly number[]): Uint8Array;
6
+ /** Inverse of {@link encodeVector}; undefined when the blob is not a whole number of float32s. */
7
+ export declare function decodeVector(blob: Uint8Array): Float32Array | undefined;
8
+ /** Cosine similarity; 0 (never NaN) for zero-length, zero-norm, or mismatched-dimension inputs. */
9
+ export declare function cosine(a: ArrayLike<number>, b: ArrayLike<number>): number;
10
+ export interface KeyedVector {
11
+ readonly key: string;
12
+ readonly vector: ArrayLike<number>;
13
+ }
14
+ export interface ScoredKey {
15
+ readonly key: string;
16
+ readonly score: number;
17
+ }
18
+ /** Best `k` positive-similarity keys, descending; ties broken by key for determinism. */
19
+ export declare function topKByCosine(query: ArrayLike<number>, rows: Iterable<KeyedVector>, k: number): ScoredKey[];
20
+ /**
21
+ * Reciprocal rank fusion over ranked key lists (best first). A key repeated
22
+ * inside one list counts once, at its best rank. Ties keep first-seen order,
23
+ * so earlier lists win.
24
+ */
25
+ export declare function reciprocalRankFusion(lists: readonly (readonly string[])[]): ScoredKey[];
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Crawler sidecar: BM25 + semantic + hybrid retrieval over a crawler's own
3
+ * SQLite archive without touching it.
4
+ *
5
+ * The sidecar owns a separate database file (MAIN). The crawler's database is
6
+ * ATTACHed read-only, so a crawler that migrates, purges, vacuums or rebuilds
7
+ * its file cannot lose sidecar state, and the sidecar cannot corrupt the
8
+ * crawler. Only vectors keyed by the crawler's message key are stored; message
9
+ * bodies are always read from the crawler database at query time.
10
+ *
11
+ * Everything crawler-specific lives in a {@link CrawlerDescriptor}; this file
12
+ * is shared by every crawler.
13
+ */
14
+ import type { Embedder } from "../../embedding-runtime/gateway-embedder.js";
15
+ import type { CrawlerDescriptor } from "./descriptors.js";
16
+ export interface SidecarHit {
17
+ readonly key: string;
18
+ readonly content: string;
19
+ readonly score: number;
20
+ readonly title?: string;
21
+ /** Milliseconds since epoch. */
22
+ readonly publishedAt?: number;
23
+ readonly metadata: Readonly<Record<string, string>>;
24
+ }
25
+ export type SidecarSyncResult = {
26
+ readonly ok: true;
27
+ readonly embedded: number;
28
+ /** Messages the embedder rejected on their own; retried only after their text changes. */
29
+ readonly skipped: number;
30
+ readonly pruned: number;
31
+ /** Messages still waiting for a vector after this sync (0 when fully caught up). */
32
+ readonly remaining: number;
33
+ } | {
34
+ readonly ok: false;
35
+ readonly message: string;
36
+ };
37
+ export interface CrawlerSidecarOptions {
38
+ readonly descriptor: CrawlerDescriptor;
39
+ readonly crawlerDbPath: string;
40
+ readonly sidecarDbPath: string;
41
+ /** Restricts every query to one workspace/account when the descriptor supports scoping. */
42
+ readonly workspaceId?: string;
43
+ /**
44
+ * Chat/channel allowlist (`channels.ids/names`). Empty means every chat. Applied in SQL, so excluded chats are
45
+ * never searched, embedded, or kept as vectors.
46
+ */
47
+ readonly channelIds?: readonly string[];
48
+ readonly channelNames?: readonly string[];
49
+ /** Required for semantic and hybrid search; lexical search works without it. */
50
+ readonly embedder?: Embedder;
51
+ /** Messages per embedding request and per write transaction. Default {@link DEFAULT_BATCH_SIZE}. */
52
+ readonly batchSize?: number;
53
+ /**
54
+ * Most messages one `sync()` will embed. A first sync over a large archive otherwise holds the whole
55
+ * refresh for minutes; the remainder is picked up by the next sync, and BM25 never waits for vectors.
56
+ * Default {@link DEFAULT_MAX_EMBED_PER_SYNC}.
57
+ */
58
+ readonly maxEmbedPerSync?: number;
59
+ }
60
+ export declare class CrawlerSidecar {
61
+ readonly descriptor: CrawlerDescriptor;
62
+ private readonly options;
63
+ private readonly select;
64
+ private readonly where;
65
+ /** Opened on first use: building a skill must not create files, directories, or file descriptors. */
66
+ private opened;
67
+ /** Identity of the attached crawler file; a crawler that replaces or deletes its archive forces a re-attach. */
68
+ private attached;
69
+ /**
70
+ * The last query's embedding and ranking. The semantic and hybrid methods of one search ask for the same
71
+ * query, so they share one embedding call and one vector scan. Short-lived, and dropped on any write.
72
+ */
73
+ private lastSemantic;
74
+ constructor(options: CrawlerSidecarOptions);
75
+ /** The sidecar database, created on first call. Only reached once the crawler archive exists. */
76
+ private get db();
77
+ /**
78
+ * Attach the crawler archive read-only, once it exists and has the expected
79
+ * shape. The crawler may not have synced yet, or may have replaced or deleted
80
+ * its file, so this is re-checked on every call: a changed file is re-attached,
81
+ * a missing one detached. Nothing is created on disk until the archive exists.
82
+ */
83
+ private attachCrawler;
84
+ private detachCrawler;
85
+ /** True when a semantic index can be built: an embedder is configured. */
86
+ get semanticEnabled(): boolean;
87
+ /** Release the database handle. Safe to call repeatedly; a later search reopens and re-attaches. */
88
+ close(): void;
89
+ /** Bound parameters for {@link where}, in the order its predicates appear. */
90
+ private whereParams;
91
+ /** BM25-ranked lexical search. Natural-language queries are OR-ed term by term. */
92
+ searchLexical(query: string, topK: number): SidecarHit[];
93
+ /** Cosine search over embedded messages. Empty when there is no embedder or the query embedding fails. */
94
+ searchSemantic(query: string, topK: number): Promise<SidecarHit[]>;
95
+ /** Best `pool` stored vectors for `query`, reusing the previous ranking when it already covers `pool`. */
96
+ private rankSemantic;
97
+ /** Reciprocal-rank fusion of lexical and semantic rankings; lexical-only when semantic is unavailable. */
98
+ searchHybrid(query: string, topK: number): Promise<SidecarHit[]>;
99
+ /**
100
+ * Bring the vector table in line with the crawler archive: drop vectors of
101
+ * purged/deleted messages, embed new or edited ones, re-embed all on an
102
+ * embedding identity change. An embedder failure keeps what was already
103
+ * stored. A message the embedder keeps rejecting while others succeed is
104
+ * skipped until its text changes, so it cannot stall the backlog behind it.
105
+ * Database errors (for example a lock held past the busy timeout) throw.
106
+ */
107
+ sync(): Promise<SidecarSyncResult>;
108
+ private adoptIdentity;
109
+ /** Delete vectors whose message no longer exists, is deleted, or fell out of scope. */
110
+ private prune;
111
+ /** Keys with no vector yet, or whose embedded text changed since. */
112
+ private pendingKeys;
113
+ /** Live rows for the given keys, in the order given. */
114
+ private hydrate;
115
+ /**
116
+ * Upsert vectors keyed by message. `undefined` stores an empty vector: the message is recorded as tried at
117
+ * this text hash (so it is not retried every sync) but never ranked.
118
+ */
119
+ private store;
120
+ private storedVectors;
121
+ private transaction;
122
+ private toRow;
123
+ private toHit;
124
+ }
125
+ /**
126
+ * FTS5 MATCH expression for free text: every alphanumeric term quoted and
127
+ * OR-ed. Quoting neutralizes FTS operators (AND, NOT, NEAR, *, parentheses),
128
+ * so user text can never change the query's structure. Undefined when the
129
+ * text contains no searchable term.
130
+ */
131
+ export declare function toMatchQuery(text: string): string | undefined;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * RetrievalMethod adapters over a {@link CrawlerSidecar}. One class serves every
3
+ * crawler and every mode; the only per-instance input is the datasource identity
4
+ * (the channel allowlist is applied by the sidecar's SQL).
5
+ */
6
+ import type { RetrievalMethod, RetrievalMethodDescriptor, RetrievalOptions, RetrievalResult } from "../../retrieval/types.js";
7
+ import type { CrawlerDescriptor } from "./descriptors.js";
8
+ import type { CrawlerSidecar } from "./index.js";
9
+ export type SidecarMode = "bm25" | "semantic" | "hybrid";
10
+ export interface SidecarMethodOptions {
11
+ readonly sidecar: CrawlerSidecar;
12
+ readonly descriptor: CrawlerDescriptor;
13
+ readonly mode: SidecarMode;
14
+ readonly datasourceId: string;
15
+ readonly skillType: string;
16
+ readonly instanceId: string;
17
+ readonly tags: readonly string[];
18
+ }
19
+ /** Result method name; `bm25` keeps the `-sidecar-` infix so it never collides with the CLI-backed `-fts` method. */
20
+ export declare function sidecarMethodName(datasourceId: string, mode: SidecarMode): string;
21
+ export declare class SidecarRetrievalMethod implements RetrievalMethod {
22
+ private readonly options;
23
+ constructor(options: SidecarMethodOptions);
24
+ describe(): RetrievalMethodDescriptor;
25
+ retrieve(query: string, options: RetrievalOptions): Promise<RetrievalResult[]>;
26
+ private toResult;
27
+ }
@@ -1,10 +1,10 @@
1
1
  import type { RetrievalMethod } from "../../../retrieval/types.js";
2
- import type { DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "../../types.js";
2
+ import type { DatasourceIndexOptions, DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "../../types.js";
3
3
  import { type ClawGallerySearchClient } from "./methods.js";
4
4
  import type { ClawGalleryIndexResult, ClawGalleryOptions, ClawGallerySearchMode, ClawGalleryVdrResult } from "./types.js";
5
5
  export interface ClawGallerySkillClient extends ClawGallerySearchClient {
6
- bootstrap(): Promise<ClawGalleryIndexResult>;
7
- syncVisual(): Promise<ClawGalleryVdrResult>;
6
+ bootstrap(signal?: AbortSignal): Promise<ClawGalleryIndexResult>;
7
+ syncVisual(signal?: AbortSignal): Promise<ClawGalleryVdrResult>;
8
8
  }
9
9
  export interface ClawGallerySkillOptions {
10
10
  readonly client: ClawGallerySkillClient;
@@ -28,7 +28,7 @@ export declare class ClawGallerySkill implements DatasourceSkill {
28
28
  constructor(options: ClawGallerySkillOptions);
29
29
  describe(): DatasourceSkillDescriptor;
30
30
  polling(): PollingMetadata;
31
- index(): Promise<DatasourceIndexResult>;
31
+ index(options?: DatasourceIndexOptions): Promise<DatasourceIndexResult>;
32
32
  retrievalMethods(): readonly RetrievalMethod[];
33
33
  describeSources(): readonly SourceDescription[];
34
34
  skillManifest(): DatasourceSkillManifest;
@@ -1,11 +1,11 @@
1
1
  import type { RetrievalMethod } from "../../../retrieval/types.js";
2
- import type { DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "../../types.js";
2
+ import type { DatasourceIndexOptions, DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "../../types.js";
3
3
  import { type DiscrawlSearchClient } from "./methods.js";
4
4
  import type { DiscrawlDoctorResult, DiscrawlEmbedResult, DiscrawlSearchMode, DiscrawlSyncResult } from "./types.js";
5
5
  export interface DiscrawlSkillClient extends DiscrawlSearchClient {
6
- doctor(): Promise<DiscrawlDoctorResult>;
7
- sync(): Promise<DiscrawlSyncResult>;
8
- embed(limit?: number, rebuild?: boolean): Promise<DiscrawlEmbedResult>;
6
+ doctor(signal?: AbortSignal): Promise<DiscrawlDoctorResult>;
7
+ sync(signal?: AbortSignal): Promise<DiscrawlSyncResult>;
8
+ embed(limit?: number, rebuild?: boolean, signal?: AbortSignal): Promise<DiscrawlEmbedResult>;
9
9
  prepareEmbeddings?(): Promise<boolean>;
10
10
  }
11
11
  export interface DiscrawlSkillOptions {
@@ -47,7 +47,7 @@ export declare class DiscrawlSkill implements DatasourceSkill {
47
47
  constructor(options: DiscrawlSkillOptions);
48
48
  describe(): DatasourceSkillDescriptor;
49
49
  polling(): PollingMetadata;
50
- index(): Promise<DatasourceIndexResult>;
50
+ index(options?: DatasourceIndexOptions): Promise<DatasourceIndexResult>;
51
51
  retrievalMethods(): readonly RetrievalMethod[];
52
52
  describeSources(): readonly SourceDescription[];
53
53
  skillManifest(): DatasourceSkillManifest;
@@ -10,7 +10,7 @@
10
10
  import { type Embedder, type GatewayEmbedderOptions } from "../../../embedding-runtime/gateway-embedder.js";
11
11
  import type { RetrievalMethod } from "../../../retrieval/types.js";
12
12
  import { ConnectorDatasourceSkill, type ConnectorSkillDefinition, type ConnectorSkillOptions } from "../../connector-skill.js";
13
- import type { DatasourceIndexResult } from "../../types.js";
13
+ import type { DatasourceIndexOptions, DatasourceIndexResult } from "../../types.js";
14
14
  import { GitHubGistConnector, type GitHubGistConnectorOptions } from "./connector.js";
15
15
  export declare const GITHUB_GIST_SKILL_DEFINITION: ConnectorSkillDefinition;
16
16
  export declare function gistDatasourceDir(workspaceRoot: string, skillName: string, instanceId: string): string;
@@ -34,6 +34,6 @@ export declare class GitHubGistSkill extends ConnectorDatasourceSkill {
34
34
  private readonly semanticEmbedder;
35
35
  private readonly semanticMethod;
36
36
  constructor(options?: GitHubGistSkillOptions);
37
- index(): Promise<DatasourceIndexResult>;
37
+ index(options?: DatasourceIndexOptions): Promise<DatasourceIndexResult>;
38
38
  retrievalMethods(): readonly RetrievalMethod[];
39
39
  }
@@ -1,11 +1,11 @@
1
1
  import type { RetrievalMethod } from "../../../retrieval/types.js";
2
- import type { DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "../../types.js";
2
+ import type { DatasourceIndexOptions, DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "../../types.js";
3
3
  import { type LazykatokSearchClient } from "./methods.js";
4
4
  import type { LazykatokDoctorResult, LazykatokIndexResult, LazykatokSyncResult } from "./types.js";
5
5
  export interface LazykatokSkillClient extends LazykatokSearchClient {
6
- doctor(): Promise<LazykatokDoctorResult>;
7
- sync(): Promise<LazykatokSyncResult>;
8
- index(): Promise<LazykatokIndexResult>;
6
+ doctor(signal?: AbortSignal): Promise<LazykatokDoctorResult>;
7
+ sync(signal?: AbortSignal): Promise<LazykatokSyncResult>;
8
+ index(signal?: AbortSignal): Promise<LazykatokIndexResult>;
9
9
  }
10
10
  export interface LazykatokSkillOptions {
11
11
  readonly client: LazykatokSkillClient;
@@ -25,7 +25,7 @@ export declare class LazykatokSkill implements DatasourceSkill {
25
25
  constructor(options: LazykatokSkillOptions);
26
26
  describe(): DatasourceSkillDescriptor;
27
27
  polling(): PollingMetadata;
28
- index(): Promise<DatasourceIndexResult>;
28
+ index(options?: DatasourceIndexOptions): Promise<DatasourceIndexResult>;
29
29
  retrievalMethods(): readonly RetrievalMethod[];
30
30
  describeSources(): readonly SourceDescription[];
31
31
  skillManifest(): DatasourceSkillManifest;
@@ -1,5 +1,5 @@
1
1
  import type { RetrievalMethod } from "../../../retrieval/types.js";
2
- import type { DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "../../types.js";
2
+ import type { DatasourceIndexOptions, DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "../../types.js";
3
3
  import { type MailcrawlIndexClient } from "./client.js";
4
4
  import type { MailcrawlOptions, MailcrawlSyncResult } from "./types.js";
5
5
  export interface MailcrawlSkillClient extends MailcrawlIndexClient {
@@ -26,7 +26,7 @@ export declare class MailcrawlSkill implements DatasourceSkill {
26
26
  constructor(options?: MailcrawlSkillOptions);
27
27
  describe(): DatasourceSkillDescriptor;
28
28
  polling(): PollingMetadata;
29
- index(): Promise<DatasourceIndexResult>;
29
+ index(options?: DatasourceIndexOptions): Promise<DatasourceIndexResult>;
30
30
  retrievalMethods(): readonly RetrievalMethod[];
31
31
  describeSources(): readonly SourceDescription[];
32
32
  skillManifest(): DatasourceSkillManifest;
@@ -1,11 +1,11 @@
1
1
  import type { RetrievalMethod } from "../../../retrieval/types.js";
2
- import type { DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "../../types.js";
2
+ import type { DatasourceIndexOptions, DatasourceIndexResult, DatasourceSkill, DatasourceSkillDescriptor, DatasourceSkillManifest, PollingMetadata, SourceDescription } from "../../types.js";
3
3
  import { type ObsidianSearchClient } from "./methods.js";
4
4
  import type { QmdEmbedResult, QmdEnsureResult, QmdUpdateResult } from "./types.js";
5
5
  export interface ObsidianSkillClient extends ObsidianSearchClient {
6
- ensureCollection(): Promise<QmdEnsureResult>;
7
- update(): Promise<QmdUpdateResult>;
8
- embed(): Promise<QmdEmbedResult>;
6
+ ensureCollection(signal?: AbortSignal): Promise<QmdEnsureResult>;
7
+ update(signal?: AbortSignal): Promise<QmdUpdateResult>;
8
+ embed(signal?: AbortSignal): Promise<QmdEmbedResult>;
9
9
  }
10
10
  export interface ObsidianSkillOptions {
11
11
  readonly datasourceId?: string;
@@ -37,7 +37,7 @@ export declare class ObsidianSkill implements DatasourceSkill {
37
37
  constructor(options?: ObsidianSkillOptions);
38
38
  describe(): DatasourceSkillDescriptor;
39
39
  polling(): PollingMetadata;
40
- index(): Promise<DatasourceIndexResult>;
40
+ index(options?: DatasourceIndexOptions): Promise<DatasourceIndexResult>;
41
41
  retrievalMethods(): readonly RetrievalMethod[];
42
42
  describeSources(): readonly SourceDescription[];
43
43
  skillManifest(): DatasourceSkillManifest;
@@ -52,6 +52,11 @@ export interface DatasourceSkillDescriptor {
52
52
  /** Optional list of instance ids this skill reports. */
53
53
  readonly instances?: readonly string[];
54
54
  }
55
+ /** Per-call options for {@link DatasourceSkill.index}. */
56
+ export interface DatasourceIndexOptions {
57
+ /** Aborting stops the index run and kills any CLI it spawned. An aborted run may reject instead of returning a fail variant. */
58
+ readonly signal?: AbortSignal;
59
+ }
55
60
  /**
56
61
  * A pluggable datasource skill. Skills are server-bound: they are constructed
57
62
  * with trusted configuration and never derive authority from model/tool args.
@@ -67,7 +72,7 @@ export interface DatasourceSkill {
67
72
  * never throws. Remote embedding egress MUST be rejected here and reported
68
73
  * via a `datasource-embedding-egress-rejected` diagnostic.
69
74
  */
70
- index(): Promise<DatasourceIndexResult>;
75
+ index(options?: DatasourceIndexOptions): Promise<DatasourceIndexResult>;
71
76
  /** Retrieval methods exposed by this skill, fed into the shared pipeline. */
72
77
  retrievalMethods(): readonly RetrievalMethod[];
73
78
  /** Opaque source descriptions for the skill's current evidence set. */
@@ -128,6 +133,11 @@ export interface DatasourceIndexOk {
128
133
  readonly chunkCount: number;
129
134
  readonly indexedAt: number;
130
135
  readonly diagnostics: readonly DatasourceDiagnostic[];
136
+ /**
137
+ * Total `index()` calls it took (set only when the refresh retried; a
138
+ * first-time success omits it).
139
+ */
140
+ readonly attempts?: number;
131
141
  }
132
142
  /** Failed indexing outcome. Never thrown; returned with diagnostics. */
133
143
  export interface DatasourceIndexFail {
@@ -139,13 +149,17 @@ export interface DatasourceIndexFail {
139
149
  readonly error?: string;
140
150
  readonly code?: DatasourceDiagnosticCode;
141
151
  readonly message?: string;
152
+ /** Total `index()` calls made before this result was reported (set by the refresh retry policy). */
153
+ readonly attempts?: number;
142
154
  }
143
155
  /**
144
156
  * Index result — an ok/fail discriminated union. Skills MUST NOT throw from
145
157
  * `index()`; they return a fail variant instead.
146
158
  */
147
159
  export type DatasourceIndexResult = DatasourceIndexOk | DatasourceIndexFail;
148
- export type DatasourceDiagnosticCode = "datasource-unavailable" | "datasource-cli-error" | "datasource-empty" | "datasource-rate-limited" | "datasource-auth-error" | "datasource-embedding-egress-rejected" | "datasource-index-failed" | "datasource-permission-denied" | "datasource-remote-embedding-rejected";
160
+ export type DatasourceDiagnosticCode = "datasource-unavailable" | "datasource-cli-error" | "datasource-empty" | "datasource-rate-limited" | "datasource-auth-error" | "datasource-embedding-egress-rejected" | "datasource-index-failed"
161
+ /** Index succeeded but is incomplete (e.g. a semantic backlog still draining); not a failure. */
162
+ | "datasource-index-partial" | "datasource-permission-denied" | "datasource-remote-embedding-rejected";
149
163
  /** Path-opaque diagnostic emitted by the datasource layer. */
150
164
  export interface DatasourceDiagnostic {
151
165
  readonly code: DatasourceDiagnosticCode;
@@ -16,6 +16,15 @@ export interface CacheOptions {
16
16
  readonly downloadTimeoutMs?: number;
17
17
  }
18
18
  export declare function verifyCacheEntry(path: string, expectedSha256: string): Promise<string>;
19
+ /**
20
+ * Marker a distributor writes inside `<archive>.extracted/` when it ships the
21
+ * runtime already extracted instead of as the pinned archive. Its content is the
22
+ * archive's SHA-256, so a tree provisioned for another runtime build is never
23
+ * taken for this one. A signed and notarized macOS app needs this: every Mach-O
24
+ * it carries must be re-signed with the app's Developer ID, so the binaries can
25
+ * no longer be packed back into an archive that matches the pinned digest.
26
+ */
27
+ export declare const PROVISIONED_RUNTIME_MARKER = ".autorag-archive-sha256";
19
28
  export declare function hasVerifiedAsset(asset: CacheAsset, cacheRoot?: string): Promise<boolean>;
20
29
  export declare function downloadAsset(asset: CacheAsset, options?: CacheOptions): Promise<string>;
21
30
  export declare function importAsset(sourcePath: string, asset: CacheAsset, options?: CacheOptions): Promise<string>;