@jini-ai/registry 0.7.3-next.2 → 0.7.3-next.3

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/README.md CHANGED
@@ -5,7 +5,7 @@ Three interchangeable backends for a content registry — the thing that answers
5
5
  they share, and real cryptographic signature verification against a GitHub Actions OIDC trust root.
6
6
  The wire types (`RegistryEntry`, `RegistryManifest`, `RegistryBackend`, …) live in
7
7
  `@jini-ai/protocol`; this package only adds the concrete backend logic, mirroring how
8
- `@jini-ai/sqlite-chat` implements ports that `@jini-ai/protocol` defines.
8
+ `@jini-ai/daemon/store/event-log/sqlite` implements ports that `@jini-ai/protocol` defines.
9
9
 
10
10
  ## Install
11
11
 
@@ -132,3 +132,20 @@ Backend options accept core `Clock` (`nowMs()`), while tool-catalog snapshots us
132
132
  Import both kernel types from `@jini-ai/core/primitives`; `RegistryDatabasePort` is exported at root.
133
133
  `tool-catalog-builder` stays universal; its `tool-catalog-builder/sqlite` factory is a Node subpath.
134
134
  Ranking belongs to the injected backend, source/enrichment policy belongs to the host.
135
+
136
+ ## Wiring
137
+
138
+ - **Revision-refreshing tool catalog** (`@jini-ai/registry/tool-catalog-builder`'s
139
+ `createRefreshingToolCatalogQuery({ seed, registry })`): the host injects `registry` (a core
140
+ `ToolRegistry` whose revocable scopes advance `toolRegistryRevision`) and a `seed()` returning
141
+ `{ query, ...anythingElse }` built from ONE `registry.list({})` snapshot — typically
142
+ `buildToolCatalogQuery` over a store factory bound to the same backend connection, so reseeding
143
+ never leaks a connection. Search/describe reseed only when the revision moved; hosts that answer
144
+ extra describe fallbacks (renamed ids, namespace overviews) read `current()` so both come from the
145
+ same seed. The host keeps the backend connection, its disposal, and its enricher/classifier.
146
+ - **Declared search keywords** (`@jini-ai/registry/tool-catalog-builder`'s
147
+ `collectDeclaredToolKeywords({ listSources, readDeclaration, isKnownTool })` and
148
+ `mergeKeywordMaps({ maps })`): the host injects its trusted manifest enumeration (e.g. bundled,
149
+ never installed, packages), a `readDeclaration({ source })` that reads one manifest's keyword
150
+ declaration, and `isKnownTool({ id })` over its native tools; a failing list or read contributes
151
+ nothing. It merges the result with its own keyword map and hands it to `createSearchEnricher`.
@@ -0,0 +1,40 @@
1
+ /** One trusted manifest location, as the host's source enumeration reports it. */
2
+ export interface DeclaredKeywordSource {
3
+ readonly packageRoot: string;
4
+ }
5
+ /** Ignore non-string values and unknown tool ids; metadata can enrich only existing tools.
6
+ * Appends to an id's existing words (space-joined) rather than replacing them.
7
+ * @complexity O(k) declared entries, without I/O. */
8
+ export declare function appendToolKeywords({ keywords, declaration, isKnownTool }: {
9
+ keywords: Record<string, string>;
10
+ declaration: unknown;
11
+ isKnownTool: (required: {
12
+ id: string;
13
+ }) => boolean;
14
+ }, _optional?: {}): void;
15
+ /**
16
+ * Reads every source's keyword declaration through the injected reader. Missing or malformed
17
+ * optional metadata contributes nothing: a failing enumeration yields no sources, and a failing
18
+ * read (or a declaration that throws while being appended) skips only that source. No plugin code
19
+ * is executed here — `readDeclaration` is the host's data read.
20
+ * @param required.listSources - The host's trusted source enumeration.
21
+ * @param required.readDeclaration - Reads one source's raw keyword declaration (id -> words).
22
+ * @param required.isKnownTool - Whether an id names a tool this vocabulary may enrich.
23
+ * @returns A prototype-less id -> words map.
24
+ * @complexity O(p + k) for p sources and k keyword entries; one read per source.
25
+ */
26
+ export declare function collectDeclaredToolKeywords(required: {
27
+ listSources: () => readonly DeclaredKeywordSource[];
28
+ readDeclaration: (required: {
29
+ source: DeclaredKeywordSource;
30
+ }) => unknown;
31
+ isKnownTool: (required: {
32
+ id: string;
33
+ }) => boolean;
34
+ }, _optional?: {}): Record<string, string>;
35
+ /** Merge keyword maps id by id, space-joining each id's non-empty words in map order.
36
+ * @complexity O(m * k) for m maps of k ids. */
37
+ export declare function mergeKeywordMaps({ maps }: {
38
+ maps: readonly Readonly<Record<string, string | undefined>>[];
39
+ }, _optional?: {}): Record<string, string>;
40
+ //# sourceMappingURL=declared-keywords.d.ts.map
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @file Collects search-only tool vocabulary that shipped manifests declare, and merges several
3
+ * keyword maps into the one map {@link createSearchEnricher} indexes. The host owns which sources are
4
+ * trusted (e.g. only bundled, never installed, packages), how a manifest is read and where its
5
+ * declaration lives, and which tool ids exist; all of that is injected. The vocabulary has no
6
+ * authority over registration, approval or callbacks: it only makes existing tools findable.
7
+ */
8
+ import { orFallbackSync } from '@jini-ai/core/errors/idioms';
9
+ /** Ignore non-string values and unknown tool ids; metadata can enrich only existing tools.
10
+ * Appends to an id's existing words (space-joined) rather than replacing them.
11
+ * @complexity O(k) declared entries, without I/O. */
12
+ export function appendToolKeywords({ keywords, declaration, isKnownTool }, _optional = {}) {
13
+ if (typeof declaration !== 'object' || declaration === null || Array.isArray(declaration))
14
+ return;
15
+ for (const [id, words] of Object.entries(declaration)) {
16
+ if (!isKnownTool({ id }) || typeof words !== 'string' || !words.trim())
17
+ continue;
18
+ keywords[id] = [keywords[id], words.trim()].filter(Boolean).join(' ');
19
+ }
20
+ }
21
+ /**
22
+ * Reads every source's keyword declaration through the injected reader. Missing or malformed
23
+ * optional metadata contributes nothing: a failing enumeration yields no sources, and a failing
24
+ * read (or a declaration that throws while being appended) skips only that source. No plugin code
25
+ * is executed here — `readDeclaration` is the host's data read.
26
+ * @param required.listSources - The host's trusted source enumeration.
27
+ * @param required.readDeclaration - Reads one source's raw keyword declaration (id -> words).
28
+ * @param required.isKnownTool - Whether an id names a tool this vocabulary may enrich.
29
+ * @returns A prototype-less id -> words map.
30
+ * @complexity O(p + k) for p sources and k keyword entries; one read per source.
31
+ */
32
+ export function collectDeclaredToolKeywords(required, _optional = {}) {
33
+ const keywords = Object.create(null);
34
+ const sources = orFallbackSync({ work: () => required.listSources(), fallback: [], step: 'List tool keyword manifests' });
35
+ for (const source of sources) {
36
+ orFallbackSync({ work: () => {
37
+ appendToolKeywords({ keywords, declaration: required.readDeclaration({ source }), isKnownTool: required.isKnownTool });
38
+ }, fallback: undefined, step: 'Read tool keyword manifest' }); /* Optional search data never prevents tool catalog construction. */
39
+ }
40
+ return keywords;
41
+ }
42
+ /** Merge keyword maps id by id, space-joining each id's non-empty words in map order.
43
+ * @complexity O(m * k) for m maps of k ids. */
44
+ export function mergeKeywordMaps({ maps }, _optional = {}) {
45
+ const ids = [...new Set(maps.flatMap((map) => Object.keys(map)))];
46
+ return Object.fromEntries(ids.map((id) => [id, maps.map((map) => map[id]).filter(Boolean).join(' ')]));
47
+ }
48
+ //# sourceMappingURL=declared-keywords.js.map
@@ -1,4 +1,7 @@
1
1
  export * from './ports.js';
2
2
  export * from './query.js';
3
3
  export * from './search-enricher.js';
4
+ export * from './declared-keywords.js';
5
+ export * from './scoped-query.js';
6
+ export { createMemoryCatalogStoreFactory } from './memory.js';
4
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,7 @@
1
1
  export * from './ports.js';
2
2
  export * from './query.js';
3
3
  export * from './search-enricher.js';
4
+ export * from './declared-keywords.js';
5
+ export * from './scoped-query.js';
6
+ export { createMemoryCatalogStoreFactory } from './memory.js';
4
7
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ import type { CatalogStoreFactory } from './ports.js';
2
+ /** Independent snapshots for small catalogs. Rank by matched substrings in ID and description,
3
+ * with ties in registration order. No storage or provider dependency.
4
+ * @complexity Linear scan of entry text per term, then O(h log h) to rank h matching entries. */
5
+ export declare function createMemoryCatalogStoreFactory(_required: Record<string, never>, _optional?: Record<string, never>): CatalogStoreFactory;
6
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1,30 @@
1
+ /** Independent snapshots for small catalogs. Rank by matched substrings in ID and description,
2
+ * with ties in registration order. No storage or provider dependency.
3
+ * @complexity Linear scan of entry text per term, then O(h log h) to rank h matching entries. */
4
+ export function createMemoryCatalogStoreFactory(_required, _optional = {}) {
5
+ return {
6
+ create({ entries }, _optional = {}) {
7
+ const rows = entries.map(entry => ({
8
+ entry: { ...entry },
9
+ searchText: `${entry.id} ${entry.description}`.toLowerCase(),
10
+ }));
11
+ return {
12
+ search({ query }, { limit = 10 } = {}) {
13
+ const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
14
+ const hits = rows.flatMap(({ entry, searchText }) => {
15
+ const score = terms.length === 0 ? 1 : terms.filter(term => searchText.includes(term)).length;
16
+ if (score === 0)
17
+ return [];
18
+ const { inputSchema: _schema, ...hit } = entry;
19
+ return [{ ...hit, score }];
20
+ });
21
+ return hits.sort((a, b) => b.score - a.score).slice(0, limit);
22
+ },
23
+ describe({ id }, _optional = {}) {
24
+ return rows.find(({ entry }) => entry.id === id)?.entry ?? null;
25
+ },
26
+ };
27
+ },
28
+ };
29
+ }
30
+ //# sourceMappingURL=memory.js.map
@@ -29,4 +29,25 @@ export interface LiveToolCatalogQuery {
29
29
  export declare function createLiveToolCatalogQuery(required: {
30
30
  initial: ToolCatalogQuery;
31
31
  }, _optional?: Record<string, never>): LiveToolCatalogQuery;
32
+ /** A catalog that reseeds its disposable snapshot whenever the registry's revision moves. */
33
+ export interface RefreshingToolCatalogQuery<S extends {
34
+ readonly query: ToolCatalogQuery;
35
+ }> extends ToolCatalogQuery {
36
+ /** The snapshot current requests must use, reseeded first if the registry revision advanced.
37
+ * Hosts that answer from more than `query` (a namespace overview built from the same entries)
38
+ * read it here so both halves come from one seed and cannot disagree. */
39
+ current(): S;
40
+ }
41
+ /** Revocable host scopes advance a registry revision (`@jini-ai/core`'s `toolRegistryRevision`);
42
+ * every search/describe compares it and reseeds through the host's `seed` only when it changed.
43
+ * The host's seed decides what a reseed reuses: reseeding the SAME backend connection keeps one
44
+ * snapshot owner and avoids leaking a replacement connection per revision. A static registry
45
+ * without a revision (`undefined`) never reseeds, so it stays a plain snapshot.
46
+ * @complexity O(1) per request when the revision is unchanged; one `seed()` when it moved. */
47
+ export declare function createRefreshingToolCatalogQuery<S extends {
48
+ readonly query: ToolCatalogQuery;
49
+ }>(required: {
50
+ seed: () => S;
51
+ registry: object;
52
+ }, _optional?: Record<string, never>): RefreshingToolCatalogQuery<S>;
32
53
  //# sourceMappingURL=query.d.ts.map
@@ -1,4 +1,4 @@
1
- import { toolDiscoveryMetadata } from '@jini-ai/core';
1
+ import { toolDiscoveryMetadata, toolRegistryRevision } from '@jini-ai/core';
2
2
  import { nowIso } from '@jini-ai/core/primitives';
3
3
  import { inputSignature } from './input-signature.js';
4
4
  /** Live overview, preserving registration order; vocabulary and source policy are host-owned. */
@@ -76,4 +76,27 @@ export function createLiveToolCatalogQuery(required, _optional = {}) {
76
76
  rebind({ next }) { current = next; },
77
77
  };
78
78
  }
79
+ /** Revocable host scopes advance a registry revision (`@jini-ai/core`'s `toolRegistryRevision`);
80
+ * every search/describe compares it and reseeds through the host's `seed` only when it changed.
81
+ * The host's seed decides what a reseed reuses: reseeding the SAME backend connection keeps one
82
+ * snapshot owner and avoids leaking a replacement connection per revision. A static registry
83
+ * without a revision (`undefined`) never reseeds, so it stays a plain snapshot.
84
+ * @complexity O(1) per request when the revision is unchanged; one `seed()` when it moved. */
85
+ export function createRefreshingToolCatalogQuery(required, _optional = {}) {
86
+ let snapshot = required.seed();
87
+ let revision = toolRegistryRevision({ registry: required.registry });
88
+ const current = () => {
89
+ const next = toolRegistryRevision({ registry: required.registry });
90
+ if (next !== revision) {
91
+ snapshot = required.seed();
92
+ revision = next;
93
+ }
94
+ return snapshot;
95
+ };
96
+ return {
97
+ current,
98
+ search: (query, optional) => current().query.search(query, optional),
99
+ describe: query => current().query.describe(query),
100
+ };
101
+ }
79
102
  //# sourceMappingURL=query.js.map
@@ -0,0 +1,91 @@
1
+ import type { ToolCatalogEntry, ToolCatalogHit, ToolCatalogQuery } from './ports.js';
2
+ /** Server-derived identity of one discovery request; never read off the wire by this module. */
3
+ export interface ToolCatalogScope {
4
+ readonly workspaceId: string;
5
+ readonly principalId: string;
6
+ /** Absent when the host cannot name a current version: the view is then built anew and never cached. */
7
+ readonly permissionVersion?: string | number;
8
+ readonly registryRevision?: string | number;
9
+ /** The tool ids this principal may discover in this workspace. */
10
+ readonly allowedToolIds: ReadonlySet<string>;
11
+ }
12
+ /** The entity types one principal may target through one tool's discriminator property. */
13
+ export interface EntityTypeProjection {
14
+ /** Top-level input-schema property that discriminates the entity kind. */
15
+ readonly property: string;
16
+ readonly types: readonly string[];
17
+ }
18
+ /** A personalized result; it never holds a credential or the request it was resolved from. */
19
+ export type ScopedToolCatalogResult = {
20
+ readonly kind: 'search';
21
+ readonly hits: readonly ToolCatalogHit[];
22
+ } | {
23
+ readonly kind: 'describe';
24
+ readonly entry: ToolCatalogEntry | null;
25
+ };
26
+ /** Host-owned bounded cache; eviction and size limits belong to the host. */
27
+ export interface ScopedToolCatalogCache {
28
+ get(required: {
29
+ key: string;
30
+ }): ScopedToolCatalogResult | undefined;
31
+ set(required: {
32
+ key: string;
33
+ value: ScopedToolCatalogResult;
34
+ }): void;
35
+ }
36
+ export interface ScopedToolCatalogArgs<R> {
37
+ /** The shared, identity-neutral index; consulted only after a scope resolved. */
38
+ readonly catalog: ToolCatalogQuery;
39
+ /** Returns null/undefined for a request whose scope is unknown; such a request discovers nothing. */
40
+ readonly resolveScope: (required: {
41
+ request: R;
42
+ }, optional?: Record<string, never>) => ToolCatalogScope | null | undefined | Promise<ToolCatalogScope | null | undefined>;
43
+ /** undefined when the tool has no entity discriminator. */
44
+ readonly entityTypesFor: (required: {
45
+ toolId: string;
46
+ scope: ToolCatalogScope;
47
+ }, optional?: Record<string, never>) => EntityTypeProjection | undefined;
48
+ }
49
+ /** A catalog query whose limit also accepts an explicit undefined, so it satisfies HTTP route ports
50
+ * declared under exactOptionalPropertyTypes as well as this package's `ToolCatalogQuery`. */
51
+ export interface ScopedToolCatalogView {
52
+ search(required: {
53
+ readonly query: string;
54
+ }, optional?: {
55
+ readonly limit?: number | undefined;
56
+ }): ToolCatalogHit[];
57
+ describe(required: {
58
+ readonly id: string;
59
+ }): ToolCatalogEntry | null;
60
+ }
61
+ export interface ScopedToolCatalog<R> {
62
+ /** Shaped like the daemon catalog routes' per-request host port. */
63
+ catalogFor(required: {
64
+ request: R;
65
+ }): Promise<ScopedToolCatalogView>;
66
+ }
67
+ type Schema = Record<string, unknown>;
68
+ /**
69
+ * Narrows one tool's entity discriminator enum to the permitted types on a CLONE of the schema;
70
+ * the shared descriptor schema is never written. Use it on describe results and on provider tool
71
+ * snapshots before publication.
72
+ * @returns The projected clone, or null when nothing is permitted (no offer, never an unconstrained string).
73
+ * @complexity O(s + t·e) for schema size s, t permitted and e declared types.
74
+ */
75
+ export declare function projectEntityDiscriminator(required: {
76
+ inputSchema: unknown;
77
+ projection: EntityTypeProjection;
78
+ }, _optional?: Record<string, never>): Schema | null;
79
+ /**
80
+ * Serves one shared, identity-neutral index per principal. Each request resolves its scope on the
81
+ * server; an unknown scope discovers nothing and the shared index is never consulted, so there is
82
+ * no fallback to an unscoped or borrowed authenticated view. Results are cached only when the host
83
+ * injects a cache AND names a permission version, keyed by the full scope plus the tool or the
84
+ * normalized query and limit. Discovery is not authorization: invocation must still pass the
85
+ * host's real permission check.
86
+ */
87
+ export declare function createScopedToolCatalog<R>(required: ScopedToolCatalogArgs<R>, optional?: {
88
+ cache?: ScopedToolCatalogCache;
89
+ }): ScopedToolCatalog<R>;
90
+ export {};
91
+ //# sourceMappingURL=scoped-query.d.ts.map
@@ -0,0 +1,146 @@
1
+ import { inputSignature } from './input-signature.js';
2
+ function isSchema(value) {
3
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
4
+ }
5
+ const EMPTY_VIEW = {
6
+ search: () => [],
7
+ describe: () => null,
8
+ };
9
+ /**
10
+ * Narrows one tool's entity discriminator enum to the permitted types on a CLONE of the schema;
11
+ * the shared descriptor schema is never written. Use it on describe results and on provider tool
12
+ * snapshots before publication.
13
+ * @returns The projected clone, or null when nothing is permitted (no offer, never an unconstrained string).
14
+ * @complexity O(s + t·e) for schema size s, t permitted and e declared types.
15
+ */
16
+ export function projectEntityDiscriminator(required, _optional = {}) {
17
+ const permitted = [...new Set(required.projection.types)];
18
+ if (permitted.length === 0 || !isSchema(required.inputSchema))
19
+ return null;
20
+ const clone = structuredClone(required.inputSchema);
21
+ const properties = isSchema(clone.properties) ? clone.properties : {};
22
+ const current = properties[required.projection.property];
23
+ const field = isSchema(current) ? current : { type: 'string' };
24
+ const declared = Array.isArray(field.enum) ? field.enum : undefined;
25
+ // A permission never widens what the tool itself declares it accepts.
26
+ const allowed = declared === undefined ? permitted : permitted.filter(type => declared.includes(type));
27
+ if (allowed.length === 0)
28
+ return null;
29
+ properties[required.projection.property] = { ...field, enum: allowed };
30
+ return { ...clone, properties };
31
+ }
32
+ /** The entry this scope may see, projected; null when the tool is hidden or offers no entity type. */
33
+ function offerEntry({ entry, view }) {
34
+ if (!view.scope.allowedToolIds.has(entry.id))
35
+ return null;
36
+ const projection = view.entityTypesFor({ toolId: entry.id, scope: view.scope });
37
+ if (projection === undefined)
38
+ return entry;
39
+ const inputSchema = projectEntityDiscriminator({ inputSchema: entry.inputSchema, projection });
40
+ return inputSchema === null ? null : { ...entry, inputSchema };
41
+ }
42
+ /** A hit carries a signature built from the shared schema, so a projected tool's signature is rebuilt. */
43
+ function offerHit({ hit, view }) {
44
+ if (!view.scope.allowedToolIds.has(hit.id))
45
+ return null;
46
+ const projection = view.entityTypesFor({ toolId: hit.id, scope: view.scope });
47
+ if (projection === undefined)
48
+ return hit;
49
+ const described = view.catalog.describe({ id: hit.id });
50
+ const inputSchema = described === null ? null : projectEntityDiscriminator({ inputSchema: described.inputSchema, projection });
51
+ if (inputSchema === null)
52
+ return null;
53
+ const { signature: _shared, ...rest } = hit;
54
+ const signature = inputSignature({ inputSchema });
55
+ return signature === undefined ? rest : { ...rest, signature };
56
+ }
57
+ /**
58
+ * Ranked hits this scope may see. Hidden tools can outrank visible ones, so the fetch window
59
+ * doubles until `limit` visible hits are found or the shared index runs out.
60
+ * @complexity O(n log n) shared-index reads in the worst case for an index of n tools; per-hit
61
+ * offers are memoized so each tool is projected at most once per search.
62
+ */
63
+ function searchVisible({ query, limit, view }) {
64
+ if (limit === 0)
65
+ return [];
66
+ const offers = new Map();
67
+ for (let window = limit;; window *= 2) {
68
+ const hits = view.catalog.search({ query }, { limit: window });
69
+ const visible = visibleHits({ hits, offers, view });
70
+ if (visible.length >= limit || hits.length < window)
71
+ return visible.slice(0, limit);
72
+ }
73
+ }
74
+ /** One fetch window's visible hits, in rank order, reusing offers already computed for this search. */
75
+ function visibleHits({ hits, offers, view }) {
76
+ const visible = [];
77
+ for (const hit of hits) {
78
+ if (!offers.has(hit.id))
79
+ offers.set(hit.id, offerHit({ hit, view }));
80
+ const offered = offers.get(hit.id);
81
+ if (offered)
82
+ visible.push(offered);
83
+ }
84
+ return visible;
85
+ }
86
+ /** Collapses whitespace so equivalent queries share one key and reach the index identically. */
87
+ function normalizeQuery(query) {
88
+ return query.trim().replace(/\s+/g, ' ');
89
+ }
90
+ /** The cache key for this scope, or undefined when this request must not be cached. */
91
+ function scopeKey({ scope, cache }) {
92
+ if (cache === undefined || scope.permissionVersion === undefined)
93
+ return undefined;
94
+ // Why-comment — registry revision tracks available tools, not who may see the tools or entity variants.
95
+ const identity = [scope.workspaceId, scope.principalId, scope.permissionVersion, scope.registryRevision ?? null];
96
+ return parts => JSON.stringify([...identity, ...parts]);
97
+ }
98
+ function scopedView({ view, cache }) {
99
+ const keyFor = scopeKey({ scope: view.scope, cache });
100
+ const read = (key) => (key === undefined ? undefined : cache?.get({ key }));
101
+ const write = (key, value) => { if (key !== undefined)
102
+ cache?.set({ key, value }); };
103
+ return {
104
+ search({ query }, { limit = 10 } = {}) {
105
+ if (!Number.isSafeInteger(limit) || limit < 0)
106
+ throw new RangeError('catalog limit must be a nonnegative integer');
107
+ const normalized = normalizeQuery(query);
108
+ const key = keyFor?.(['search', normalized, limit]);
109
+ const stored = read(key);
110
+ if (stored?.kind === 'search')
111
+ return [...stored.hits];
112
+ const hits = searchVisible({ query: normalized, limit, view });
113
+ write(key, { kind: 'search', hits });
114
+ return hits;
115
+ },
116
+ describe({ id }) {
117
+ const key = keyFor?.(['describe', id]);
118
+ const stored = read(key);
119
+ if (stored?.kind === 'describe')
120
+ return stored.entry;
121
+ const entry = view.catalog.describe({ id });
122
+ const offered = entry === null ? null : offerEntry({ entry, view });
123
+ write(key, { kind: 'describe', entry: offered });
124
+ return offered;
125
+ },
126
+ };
127
+ }
128
+ /**
129
+ * Serves one shared, identity-neutral index per principal. Each request resolves its scope on the
130
+ * server; an unknown scope discovers nothing and the shared index is never consulted, so there is
131
+ * no fallback to an unscoped or borrowed authenticated view. Results are cached only when the host
132
+ * injects a cache AND names a permission version, keyed by the full scope plus the tool or the
133
+ * normalized query and limit. Discovery is not authorization: invocation must still pass the
134
+ * host's real permission check.
135
+ */
136
+ export function createScopedToolCatalog(required, optional = {}) {
137
+ return {
138
+ async catalogFor({ request }) {
139
+ const scope = await required.resolveScope({ request });
140
+ if (!scope || !scope.workspaceId || !scope.principalId)
141
+ return EMPTY_VIEW;
142
+ return scopedView({ view: { catalog: required.catalog, scope, entityTypesFor: required.entityTypesFor }, cache: optional.cache });
143
+ },
144
+ };
145
+ }
146
+ //# sourceMappingURL=scoped-query.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/registry",
3
- "version": "0.7.3-next.2",
3
+ "version": "0.7.3-next.3",
4
4
  "description": "Pluggable content-registry backends (static, GitHub, database) and semver specifier resolution over @jini-ai/protocol’s registry wire types.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -77,8 +77,8 @@
77
77
  "registry": "https://registry.npmjs.org"
78
78
  },
79
79
  "dependencies": {
80
- "@jini-ai/core": "^0.7.3-next.2",
81
- "@jini-ai/protocol": "^0.7.3-next.2"
80
+ "@jini-ai/protocol": "^0.7.3-next.3",
81
+ "@jini-ai/core": "^0.7.3-next.3"
82
82
  },
83
83
  "peerDependencies": {
84
84
  "better-sqlite3": "^13.0.0"
@@ -86,10 +86,10 @@
86
86
  "devDependencies": {
87
87
  "@types/better-sqlite3": "^7.6.11",
88
88
  "better-sqlite3": "^13.0.0",
89
- "@jini-ai/core": "^0.7.3-next.2",
90
- "@jini-ai/db": "0.7.3-next.2",
91
- "@jini-ai/platform": "^0.7.3-next.2",
92
- "@jini-ai/protocol": "^0.7.3-next.2"
89
+ "@jini-ai/core": "^0.7.3-next.3",
90
+ "@jini-ai/platform": "^0.7.3-next.3",
91
+ "@jini-ai/db": "0.7.3-next.3",
92
+ "@jini-ai/protocol": "^0.7.3-next.3"
93
93
  },
94
94
  "peerDependenciesMeta": {
95
95
  "better-sqlite3": {