feat(contexto): tighten public types + honor retrieval config#149
Open
Chen17-sq wants to merge 1 commit into
Open
feat(contexto): tighten public types + honor retrieval config#149Chen17-sq wants to merge 1 commit into
Chen17-sq wants to merge 1 commit into
Conversation
Two related changes that address both bullets of ekailabs#133: # 1. Type the mindmap item shape (drop ``any[]``) ``SearchResult.items`` was ``any[]``. Anyone implementing ``ContextoBackend`` (ekailabs#116) had to read ``helpers.ts`` to learn the field names. Replaced with two new public types that mirror ``@ekai/mindmap``'s ``ConversationItem`` / ``ScoredItem``: * ``MindmapItem`` — id, role, content, timestamp, metadata * ``ScoredMindmapItem`` — { item: MindmapItem, score, estimatedTokens } Both are re-exported from ``packages/contexto/src/index.ts``. No runtime import is added (the types live in the contexto package; the mindmap shape they mirror is a contract, not an import). The strict typing surfaced a latent bug in ``engine/base.ts``: the dedup loop used ``(r.item ?? r).id``, but neither backend (local + remote) returns raw items — both wrap in ``{item, score, ...}`` and ``MindmapItem.id`` is required. The ``?? r`` fallback was therefore unreachable, and on the off chance it did execute, ``r.id`` would have been ``undefined`` (silently disabling dedup). Replaced both call sites with ``r.item?.id`` and left a comment explaining why. # 2. Honor ``maxResults`` (was hardcoded) + document the defaults ``engine/base.ts`` was using ``DEFAULT_MAX_RESULTS = 7`` regardless of what callers passed via ``BaseConfig``. ``minScore`` was already wired through (line 89). Added ``maxResults?: number`` to BaseConfig and threaded it through the search call. ``filter`` was also already wired through but undocumented. Configuration is now documented in three places, all consistent: * ``packages/contexto/openclaw.plugin.json`` — the runtime schema OpenClaw uses to validate plugin config; added entries for ``maxResults`` / ``minScore`` / ``filter``. * ``packages/contexto/src/index.ts`` — the inline ``configSchema`` on the default-exported plugin definition; same three additions, plus the ``register()`` function now reads them from ``api.pluginConfig`` and threads them into ``base``. * ``packages/contexto/README.md`` Configuration table — gains rows for ``contextEnabled``, ``maxContextChars``, ``maxResults``, ``minScore``, ``filter`` with defaults called out inline. * ``docs/contexto.md`` — new "Tuning Retrieval" section that summarises the three knobs and points back to the README. Closes ekailabs#133. Test plan --------- * ``pnpm --filter @ekai/contexto run build`` (tsc --noEmit) passes cleanly — the strict typing change fixed a latent bug in ``engine/base.ts`` that the loose ``any[]`` typing had been hiding. * No runtime imports added; the new types reference an existing shape from ``@ekai/mindmap`` without depending on it at runtime. * The ``register()`` reader in ``index.ts`` falls back to ``undefined`` for missing fields, which then falls through to the engine's ``DEFAULT_MAX_RESULTS`` / ``DEFAULT_MIN_SCORE`` — existing users who don't set the new fields see zero behaviour change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
Closes #133.
Summary
Addresses both bullets the issue called out:
Plus a latent bug the type tightening surfaced (see below).
What changed
1. Public types in `src/types.ts`
Two new public types replace the `any[]` and mirror `@ekai/mindmap`'s `ConversationItem` / `ScoredItem`:
Both are re-exported from the package entry. No runtime import added — the types describe a shape, not a binding.
2. Wire `maxResults` through
`BaseConfig` gains `maxResults?: number` alongside the (already-present) `minScore` and `filter`. All three are now also declared in:
3. Latent bug fix (surfaced by type tightening)
`engine/base.ts` dedup loop:
Neither backend (local + remote) returns the raw-item shape — both wrap in `{item, score, ...}` and `MindmapItem.id` is required. The `?? r` fallback was unreachable; if it ever ran, `r.id` was `undefined` and silently disabled dedup.
4. Documentation
Diff scope
Backward compatibility
Zero behaviour change for existing users:
Test plan
The issue's "Tighten openclaw peerDependency version range" (#140) and "docs: Normalize docs..." (#135) are addressed in separate PRs (#147, #148) to keep diffs small per concern.