@lacneu/openclaw-knowledge 3.1.2 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +368 -1
  2. package/README.md +131 -0
  3. package/dist/config.d.ts +4 -0
  4. package/dist/config.js +26 -0
  5. package/dist/config.js.map +1 -1
  6. package/dist/index.d.ts +61 -4
  7. package/dist/index.js +463 -50
  8. package/dist/index.js.map +1 -1
  9. package/dist/jina/classifier.d.ts +55 -0
  10. package/dist/jina/classifier.js +170 -0
  11. package/dist/jina/classifier.js.map +1 -0
  12. package/dist/jina/client.d.ts +30 -0
  13. package/dist/jina/client.js +131 -0
  14. package/dist/jina/client.js.map +1 -0
  15. package/dist/jina/errors.d.ts +42 -0
  16. package/dist/jina/errors.js +113 -0
  17. package/dist/jina/errors.js.map +1 -0
  18. package/dist/jina/reranker.d.ts +34 -0
  19. package/dist/jina/reranker.js +95 -0
  20. package/dist/jina/reranker.js.map +1 -0
  21. package/dist/jina/types.d.ts +78 -0
  22. package/dist/jina/types.js +12 -0
  23. package/dist/jina/types.js.map +1 -0
  24. package/dist/pgvector.d.ts +29 -0
  25. package/dist/pgvector.js +68 -0
  26. package/dist/pgvector.js.map +1 -1
  27. package/dist/router/heuristic.d.ts +29 -0
  28. package/dist/router/heuristic.js +104 -0
  29. package/dist/router/heuristic.js.map +1 -0
  30. package/dist/router/index.d.ts +33 -0
  31. package/dist/router/index.js +94 -0
  32. package/dist/router/index.js.map +1 -0
  33. package/dist/router/labels.d.ts +33 -0
  34. package/dist/router/labels.js +67 -0
  35. package/dist/router/labels.js.map +1 -0
  36. package/dist/router/types.d.ts +23 -0
  37. package/dist/router/types.js +7 -0
  38. package/dist/router/types.js.map +1 -0
  39. package/dist/tracing/events.d.ts +83 -0
  40. package/dist/tracing/events.js +86 -0
  41. package/dist/tracing/events.js.map +1 -0
  42. package/dist/types.d.ts +61 -1
  43. package/openclaw.plugin.json +97 -4
  44. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import type { OpenClawPluginApi, PluginLogger } from "openclaw/plugin-sdk/plugin-entry";
2
- import type { BeforePromptBuildEvent, BeforePromptBuildResult, PgPoolLike, ResolvedKnowledgeConfig } from "./types.js";
2
+ import type { Route } from "./router/types.js";
3
+ import type { BeforePromptBuildEvent, BeforePromptBuildResult, PgPoolLike, PluginHookAgentContext, PromptMessage, ResolvedKnowledgeConfig } from "./types.js";
3
4
  export { resolveEnv, resolveConfig } from "./config.js";
4
5
  export { embedQuery } from "./embeddings.js";
5
- export { searchCollection, formatPgvectorResults } from "./pgvector.js";
6
+ export { searchCollection, formatPgvectorResults, rerankPgvectorResults, } from "./pgvector.js";
6
7
  export { queryLightRAG, truncateLightRAG, formatLightRAGResults } from "./lightrag.js";
7
- export type { BeforePromptBuildEvent, BeforePromptBuildResult, KnowledgePluginConfig, LightRAGQueryMode, PgPoolLike, PgvectorResult, PgvectorRow, PromptContentPart, PromptMessage, ResolvedKnowledgeConfig, } from "./types.js";
8
+ export { decideRoute } from "./router/index.js";
9
+ export type { BeforePromptBuildEvent, BeforePromptBuildResult, JinaPluginConfig, KnowledgePluginConfig, LightRAGQueryMode, PgPoolLike, PgvectorResult, PgvectorRerankerPluginConfig, PgvectorRow, PluginHookAgentContext, PromptContentPart, PromptMessage, ResolvedKnowledgeConfig, RouterPluginConfig, } from "./types.js";
8
10
  interface HookHandlerDeps {
9
11
  config: ResolvedKnowledgeConfig;
10
12
  pool: PgPoolLike | null;
@@ -14,7 +16,62 @@ interface HookHandlerDeps {
14
16
  * Build the `before_prompt_build` handler bound to a specific plugin state.
15
17
  * Kept as a pure factory so the handler can be unit-tested with fake deps.
16
18
  */
17
- export declare function createBeforePromptBuildHandler(deps: HookHandlerDeps): (event: BeforePromptBuildEvent) => Promise<BeforePromptBuildResult | undefined>;
19
+ export declare function createBeforePromptBuildHandler(deps: HookHandlerDeps): (event: BeforePromptBuildEvent, ctx?: PluginHookAgentContext) => Promise<BeforePromptBuildResult | undefined>;
20
+ /**
21
+ * Project a router decision onto the set of sources that are actually
22
+ * enabled in this deployment. This prevents "silent empty retrieval"
23
+ * when, for example, a pgvector-only deployment is told to use
24
+ * `LIGHTRAG_ONLY` for a multi-hop question — without this projection the
25
+ * task list would be empty and the agent would lose context that
26
+ * pgvector could have provided.
27
+ *
28
+ * Rules:
29
+ * - `NONE` → `NONE` (the router deliberately wants no retrieval).
30
+ * - `ALL` → `ALL` (downstream `shouldUseX` already skips disabled sources).
31
+ * - `PGVECTOR_ONLY` + pgvector disabled:
32
+ * - LightRAG available → `LIGHTRAG_ONLY` (best effort)
33
+ * - neither available → `NONE` (caller short-circuits)
34
+ * - `LIGHTRAG_ONLY` + LightRAG disabled: symmetric.
35
+ *
36
+ * Exported for unit testing.
37
+ */
38
+ export declare function projectRouteOnEnabledSources(route: Route, pgvectorEnabled: boolean, lightragEnabled: boolean): Route;
39
+ /**
40
+ * Strip the OpenClaw envelope (inbound-context blocks + timestamp
41
+ * marker) from the START of a raw user prompt and return only the user
42
+ * utterance. When no envelope is matched, the prompt is returned
43
+ * unchanged — the router then sees the full user content, which is the
44
+ * correct behavior for non-OpenClaw inputs.
45
+ *
46
+ * @internal exported for unit testing
47
+ */
48
+ export declare function stripOpenClawHeaders(prompt: string): string;
49
+ /**
50
+ * Extract the user question from a `before_prompt_build` event.
51
+ *
52
+ * - When `event.prompt` is supplied (SDK 2026.5.0+), it is the
53
+ * authoritative source for the raw user utterance: this function
54
+ * strips the OpenClaw envelope and returns the result, even when the
55
+ * result is empty. `event.messages` is NOT consulted in this case
56
+ * because it carries the aggregated conversation window (multi-KB
57
+ * blob optimized for LLM consumption, not for plugin inspection).
58
+ * - When `event.prompt` is absent (older SDK), fall back to
59
+ * `extractQueryFromMessages(event.messages)`.
60
+ *
61
+ * The downstream `MIN_QUERY_LENGTH` check drops empty or near-empty
62
+ * results, so silently returning `""` from the `prompt` path is safe.
63
+ *
64
+ * @internal exported for unit testing
65
+ */
66
+ export declare function extractUserQuery(event: BeforePromptBuildEvent): string;
67
+ /**
68
+ * Legacy extraction from `event.messages`, used only when the SDK does
69
+ * not populate `event.prompt`. On 2026.5.x+ the primary path is
70
+ * {@link extractUserQuery}.
71
+ *
72
+ * @internal exported for unit testing and backward compatibility
73
+ */
74
+ export declare function extractQueryFromMessages(messages: PromptMessage[] | undefined): string;
18
75
  /**
19
76
  * Register the plugin against a minimal shape-compatible subset of the
20
77
  * OpenClaw plugin API. Returns nothing; side effects are setting a hook and