@xemahq/kernel-contracts 0.24.1 → 0.25.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.
@@ -29,7 +29,8 @@ export declare enum ContributionKind {
29
29
  OpenCodePlugin = "opencode-plugin",
30
30
  Capability = "capability",
31
31
  ResourceOwnership = "resource-ownership",
32
- StageMachine = "stage-machine"
32
+ StageMachine = "stage-machine",
33
+ SearchType = "search-type"
33
34
  }
34
35
  export declare const ContributionKindSchema: z.ZodEnum<typeof ContributionKind>;
35
36
  export type ContributionKindValue = `${ContributionKind}`;
@@ -1 +1 @@
1
- {"version":3,"file":"contribution-kind.d.ts","sourceRoot":"","sources":["../../../src/contribution/lib/contribution-kind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoBxB,oBAAY,gBAAgB;IAE1B,WAAW,iBAAiB;IAC5B,OAAO,aAAa;IACpB,YAAY,kBAAkB;IAC9B,UAAU,gBAAgB;IAC1B,YAAY,kBAAkB;IAC9B,UAAU,gBAAgB;IAC1B,WAAW,iBAAiB;IAC5B,wBAAwB,+BAA+B;IACvD,UAAU,gBAAgB;IAQ1B,YAAY,kBAAkB;IAM9B,WAAW,iBAAiB;IAW5B,cAAc,oBAAoB;IAElC,kBAAkB,yBAAyB;IAE3C,IAAI,SAAS;IAEb,UAAU,gBAAgB;IAE1B,oBAAoB,0BAA0B;IAE9C,oBAAoB,2BAA2B;IAE/C,yBAAyB,gCAAgC;IAGzD,mBAAmB,yBAAyB;IAI5C,cAAc,oBAAoB;IAElC,eAAe,qBAAqB;IAEpC,iBAAiB,uBAAuB;IAExC,yBAAyB,gCAAgC;IAEzD,WAAW,iBAAiB;IAI5B,UAAU,gBAAgB;IAE1B,YAAY,kBAAkB;IAE9B,cAAc,oBAAoB;IAgBlC,UAAU,eAAe;IAezB,iBAAiB,uBAAuB;IAcxC,YAAY,kBAAkB;CAC/B;AAMD,eAAO,MAAM,sBAAsB,oCAAiC,CAAC;AAErE,MAAM,MAAM,qBAAqB,GAAG,GAAG,gBAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"contribution-kind.d.ts","sourceRoot":"","sources":["../../../src/contribution/lib/contribution-kind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoBxB,oBAAY,gBAAgB;IAE1B,WAAW,iBAAiB;IAC5B,OAAO,aAAa;IACpB,YAAY,kBAAkB;IAC9B,UAAU,gBAAgB;IAC1B,YAAY,kBAAkB;IAC9B,UAAU,gBAAgB;IAC1B,WAAW,iBAAiB;IAC5B,wBAAwB,+BAA+B;IACvD,UAAU,gBAAgB;IAQ1B,YAAY,kBAAkB;IAM9B,WAAW,iBAAiB;IAW5B,cAAc,oBAAoB;IAElC,kBAAkB,yBAAyB;IAE3C,IAAI,SAAS;IAEb,UAAU,gBAAgB;IAE1B,oBAAoB,0BAA0B;IAE9C,oBAAoB,2BAA2B;IAE/C,yBAAyB,gCAAgC;IAGzD,mBAAmB,yBAAyB;IAI5C,cAAc,oBAAoB;IAElC,eAAe,qBAAqB;IAEpC,iBAAiB,uBAAuB;IAExC,yBAAyB,gCAAgC;IAEzD,WAAW,iBAAiB;IAI5B,UAAU,gBAAgB;IAE1B,YAAY,kBAAkB;IAE9B,cAAc,oBAAoB;IAgBlC,UAAU,eAAe;IAezB,iBAAiB,uBAAuB;IAcxC,YAAY,kBAAkB;IAkB9B,UAAU,gBAAgB;CAC3B;AAMD,eAAO,MAAM,sBAAsB,oCAAiC,CAAC;AAErE,MAAM,MAAM,qBAAqB,GAAG,GAAG,gBAAgB,EAAE,CAAC"}
@@ -34,6 +34,7 @@ var ContributionKind;
34
34
  ContributionKind["Capability"] = "capability";
35
35
  ContributionKind["ResourceOwnership"] = "resource-ownership";
36
36
  ContributionKind["StageMachine"] = "stage-machine";
37
+ ContributionKind["SearchType"] = "search-type";
37
38
  })(ContributionKind || (exports.ContributionKind = ContributionKind = {}));
38
39
  exports.ContributionKindSchema = zod_1.z.nativeEnum(ContributionKind);
39
40
  //# sourceMappingURL=contribution-kind.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contribution-kind.js","sourceRoot":"","sources":["../../../src/contribution/lib/contribution-kind.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAoBxB,IAAY,gBAoHX;AApHD,WAAY,gBAAgB;IAE1B,gDAA4B,CAAA;IAC5B,wCAAoB,CAAA;IACpB,kDAA8B,CAAA;IAC9B,8CAA0B,CAAA;IAC1B,kDAA8B,CAAA;IAC9B,8CAA0B,CAAA;IAC1B,gDAA4B,CAAA;IAC5B,2EAAuD,CAAA;IACvD,8CAA0B,CAAA;IAQ1B,kDAA8B,CAAA;IAM9B,gDAA4B,CAAA;IAW5B,sDAAkC,CAAA;IAElC,+DAA2C,CAAA;IAE3C,iCAAa,CAAA;IAEb,8CAA0B,CAAA;IAE1B,kEAA8C,CAAA;IAE9C,mEAA+C,CAAA;IAE/C,6EAAyD,CAAA;IAGzD,gEAA4C,CAAA;IAI5C,sDAAkC,CAAA;IAElC,wDAAoC,CAAA;IAEpC,4DAAwC,CAAA;IAExC,6EAAyD,CAAA;IAEzD,gDAA4B,CAAA;IAI5B,8CAA0B,CAAA;IAE1B,kDAA8B,CAAA;IAE9B,sDAAkC,CAAA;IAgBlC,6CAAyB,CAAA;IAezB,4DAAwC,CAAA;IAcxC,kDAA8B,CAAA;AAChC,CAAC,EApHW,gBAAgB,gCAAhB,gBAAgB,QAoH3B;AAMY,QAAA,sBAAsB,GAAG,OAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC"}
1
+ {"version":3,"file":"contribution-kind.js","sourceRoot":"","sources":["../../../src/contribution/lib/contribution-kind.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAoBxB,IAAY,gBAsIX;AAtID,WAAY,gBAAgB;IAE1B,gDAA4B,CAAA;IAC5B,wCAAoB,CAAA;IACpB,kDAA8B,CAAA;IAC9B,8CAA0B,CAAA;IAC1B,kDAA8B,CAAA;IAC9B,8CAA0B,CAAA;IAC1B,gDAA4B,CAAA;IAC5B,2EAAuD,CAAA;IACvD,8CAA0B,CAAA;IAQ1B,kDAA8B,CAAA;IAM9B,gDAA4B,CAAA;IAW5B,sDAAkC,CAAA;IAElC,+DAA2C,CAAA;IAE3C,iCAAa,CAAA;IAEb,8CAA0B,CAAA;IAE1B,kEAA8C,CAAA;IAE9C,mEAA+C,CAAA;IAE/C,6EAAyD,CAAA;IAGzD,gEAA4C,CAAA;IAI5C,sDAAkC,CAAA;IAElC,wDAAoC,CAAA;IAEpC,4DAAwC,CAAA;IAExC,6EAAyD,CAAA;IAEzD,gDAA4B,CAAA;IAI5B,8CAA0B,CAAA;IAE1B,kDAA8B,CAAA;IAE9B,sDAAkC,CAAA;IAgBlC,6CAAyB,CAAA;IAezB,4DAAwC,CAAA;IAcxC,kDAA8B,CAAA;IAkB9B,8CAA0B,CAAA;AAC5B,CAAC,EAtIW,gBAAgB,gCAAhB,gBAAgB,QAsI3B;AAMY,QAAA,sBAAsB,GAAG,OAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './lib/search-contribution';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":"AAkBA,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lib/search-contribution"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAkBA,4DAA0C"}
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+ import { type CapabilityRef } from '../../capability';
3
+ import { XemaObjectKind } from '../../object';
4
+ import { ResourceVisibilityPattern } from '../../resource';
5
+ export interface SearchTypeRenderHints {
6
+ readonly label: string;
7
+ readonly icon?: string;
8
+ readonly routeTemplate?: string;
9
+ }
10
+ export declare const SearchTypeRenderHintsSchema: z.ZodType<SearchTypeRenderHints>;
11
+ export interface SearchTypeAuthzMapping {
12
+ readonly resourceType: string;
13
+ readonly defaultVisibility: ResourceVisibilityPattern;
14
+ }
15
+ export declare const SearchTypeAuthzMappingSchema: z.ZodType<SearchTypeAuthzMapping>;
16
+ export interface SearchTypeContributionManifest {
17
+ readonly objectKind: XemaObjectKind;
18
+ readonly docType?: string;
19
+ readonly renderHints: SearchTypeRenderHints;
20
+ readonly searchableFields: readonly string[];
21
+ readonly embeddingEligibleDefault: boolean;
22
+ readonly authz: SearchTypeAuthzMapping;
23
+ readonly searchReplayCapabilityRef?: CapabilityRef;
24
+ }
25
+ export declare const SearchTypeContributionManifestSchema: z.ZodType<SearchTypeContributionManifest>;
26
+ export declare function searchTypeNaturalKey(objectKind: XemaObjectKind, docType?: string): string;
27
+ //# sourceMappingURL=search-contribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-contribution.d.ts","sourceRoot":"","sources":["../../../src/search/lib/search-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAwB,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,yBAAyB,EAE1B,MAAM,gBAAgB,CAAC;AA6BxB,MAAM,WAAW,qBAAqB;IAEpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAMvB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,eAAO,MAAM,2BAA2B,EAAE,CAAC,CAAC,OAAO,CAAC,qBAAqB,CASjC,CAAC;AAWzC,MAAM,WAAW,sBAAsB;IAErC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B,QAAQ,CAAC,iBAAiB,EAAE,yBAAyB,CAAC;CACvD;AAED,eAAO,MAAM,4BAA4B,EAAE,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAIlC,CAAC;AAiB1C,MAAM,WAAW,8BAA8B;IAK7C,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IAMpC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAE1B,QAAQ,CAAC,WAAW,EAAE,qBAAqB,CAAC;IAK5C,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IAM7C,QAAQ,CAAC,wBAAwB,EAAE,OAAO,CAAC;IAE3C,QAAQ,CAAC,KAAK,EAAE,sBAAsB,CAAC;IAOvC,QAAQ,CAAC,yBAAyB,CAAC,EAAE,aAAa,CAAC;CACpD;AASD,eAAO,MAAM,oCAAoC,EAAE,CAAC,CAAC,OAAO,CAAC,8BAA8B,CAY1C,CAAC;AAOlD,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,cAAc,EAC1B,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,CAER"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SearchTypeContributionManifestSchema = exports.SearchTypeAuthzMappingSchema = exports.SearchTypeRenderHintsSchema = void 0;
4
+ exports.searchTypeNaturalKey = searchTypeNaturalKey;
5
+ const zod_1 = require("zod");
6
+ const capability_1 = require("../../capability");
7
+ const object_1 = require("../../object");
8
+ const resource_1 = require("../../resource");
9
+ const SEARCH_TYPE_STRING_MAX = 200;
10
+ const SEARCH_TYPE_ROUTE_TEMPLATE_MAX = 500;
11
+ const SEARCH_TYPE_FIELDS_MAX = 100;
12
+ exports.SearchTypeRenderHintsSchema = zod_1.z.object({
13
+ label: zod_1.z.string().min(1).max(SEARCH_TYPE_STRING_MAX),
14
+ icon: zod_1.z.string().min(1).max(SEARCH_TYPE_STRING_MAX).optional(),
15
+ routeTemplate: zod_1.z
16
+ .string()
17
+ .min(1)
18
+ .max(SEARCH_TYPE_ROUTE_TEMPLATE_MAX)
19
+ .optional(),
20
+ });
21
+ exports.SearchTypeAuthzMappingSchema = zod_1.z.object({
22
+ resourceType: zod_1.z.string().min(1).max(SEARCH_TYPE_STRING_MAX),
23
+ defaultVisibility: resource_1.ResourceVisibilityPatternSchema,
24
+ });
25
+ exports.SearchTypeContributionManifestSchema = zod_1.z.object({
26
+ objectKind: object_1.XemaObjectKindSchema,
27
+ docType: zod_1.z.string().min(1).max(SEARCH_TYPE_STRING_MAX).optional(),
28
+ renderHints: exports.SearchTypeRenderHintsSchema,
29
+ searchableFields: zod_1.z
30
+ .array(zod_1.z.string().min(1).max(SEARCH_TYPE_STRING_MAX))
31
+ .min(1)
32
+ .max(SEARCH_TYPE_FIELDS_MAX),
33
+ embeddingEligibleDefault: zod_1.z.boolean(),
34
+ authz: exports.SearchTypeAuthzMappingSchema,
35
+ searchReplayCapabilityRef: capability_1.CapabilityRefSchema.optional(),
36
+ });
37
+ function searchTypeNaturalKey(objectKind, docType) {
38
+ return docType ? `${objectKind}/${docType}` : String(objectKind);
39
+ }
40
+ //# sourceMappingURL=search-contribution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-contribution.js","sourceRoot":"","sources":["../../../src/search/lib/search-contribution.ts"],"names":[],"mappings":";;;AA+JA,oDAKC;AApKD,6BAAwB;AAExB,iDAA2E;AAC3E,yCAAoE;AACpE,6CAGwB;AAOxB,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAOnC,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAO3C,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAqBtB,QAAA,2BAA2B,GACtC,OAAC,CAAC,MAAM,CAAC;IACP,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,sBAAsB,CAAC;IACpD,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,QAAQ,EAAE;IAC9D,aAAa,EAAE,OAAC;SACb,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,8BAA8B,CAAC;SACnC,QAAQ,EAAE;CACd,CAAqC,CAAC;AAkB5B,QAAA,4BAA4B,GACvC,OAAC,CAAC,MAAM,CAAC;IACP,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,sBAAsB,CAAC;IAC3D,iBAAiB,EAAE,0CAA+B;CACnD,CAAsC,CAAC;AA4D7B,QAAA,oCAAoC,GAC/C,OAAC,CAAC,MAAM,CAAC;IACP,UAAU,EAAE,6BAAoB;IAChC,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,QAAQ,EAAE;IACjE,WAAW,EAAE,mCAA2B;IACxC,gBAAgB,EAAE,OAAC;SAChB,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;SACpD,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,sBAAsB,CAAC;IAC9B,wBAAwB,EAAE,OAAC,CAAC,OAAO,EAAE;IACrC,KAAK,EAAE,oCAA4B;IACnC,yBAAyB,EAAE,gCAAmB,CAAC,QAAQ,EAAE;CAC1D,CAA8C,CAAC;AAOlD,SAAgB,oBAAoB,CAClC,UAA0B,EAC1B,OAAgB;IAEhB,OAAO,OAAO,CAAC,CAAC,CAAC,GAAG,UAAU,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AACnE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xemahq/kernel-contracts",
3
- "version": "0.24.1",
3
+ "version": "0.25.0",
4
4
  "description": "Consolidated Xema OS kernel wire contracts — pure types + zod schemas for the kernel protocol surfaces. One package, one npm scope, wildcard per-surface subpath exports. No framework/runtime deps.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Neuralchowder Inc. <developer@xema.dev> (https://xema.dev)",
@@ -134,6 +134,24 @@ export enum ContributionKind {
134
134
  * stage machine is a host-domain concept, not a kernel one.
135
135
  */
136
136
  StageMachine = 'stage-machine',
137
+
138
+ // -- Search result-type self-registration ----------------------------------
139
+ /**
140
+ * A search RESULT-TYPE declaration contributed by a biome — the
141
+ * `XemaObjectKind`/`docType` it covers, render/route hints (label, icon,
142
+ * deep-link template), the searchable-field set + embedding-eligibility
143
+ * default, and the authz mapping (`resourceType` + default
144
+ * `ResourceVisibilityPattern`). The kernel owns this enum member AND the
145
+ * manifest schema (`SearchTypeContributionManifestSchema`, exported from
146
+ * `@xemahq/kernel-contracts/search`), mirroring the `Capability` and
147
+ * `ResourceOwnership` kinds: a single value-identical wire shape both the
148
+ * contribution-file parser (`search-type.parser.ts` in `biome-host-api`) and
149
+ * the owning service (`search-api`) validate fail-fast. Provenance is stamped
150
+ * by the parser from the discovering biome's manifest — authors do not
151
+ * declare it inline. RESULT-TYPES are contributed (declarative, boot-time);
152
+ * document INSTANCES are event-fed (runtime, via `IndexableDocument`).
153
+ */
154
+ SearchType = 'search-type',
137
155
  }
138
156
 
139
157
  /**
@@ -0,0 +1,19 @@
1
+ // ═══════════════════════════════════════════════════════════════════════════
2
+ // @xemahq/kernel-contracts/search — search RESULT-TYPE contribution contract.
3
+ //
4
+ // Pure types + Zod schemas for the `ContributionKind.SearchType` manifest: the
5
+ // declarative, boot-time registration of a search result-type (the
6
+ // `(XemaObjectKind, docType)` facet) a biome contributes to `search-api`. The
7
+ // object model (`object` subpath) is the identity backbone, the authz mapping
8
+ // reuses the `resource` subpath's `ResourceVisibilityPattern`, and the optional
9
+ // replay ref reuses the `capability` subpath's `CapabilityRef` — this surface
10
+ // therefore declares exactly three cross-subpath edges
11
+ // (`search -> object`, `search -> resource`, `search -> capability`), all
12
+ // acyclic. Zero runtime deps beyond `zod`.
13
+ //
14
+ // NOTE: this is distinct from the `search-source` subpath, which carries the
15
+ // runtime `IndexableDocument` (document INSTANCES, event-fed). RESULT-TYPES are
16
+ // contributed (declarative); INSTANCES are event-fed (runtime).
17
+ // ═══════════════════════════════════════════════════════════════════════════
18
+
19
+ export * from './lib/search-contribution';
@@ -0,0 +1,165 @@
1
+ import { z } from 'zod';
2
+
3
+ import { CapabilityRefSchema, type CapabilityRef } from '../../capability';
4
+ import { XemaObjectKind, XemaObjectKindSchema } from '../../object';
5
+ import {
6
+ ResourceVisibilityPattern,
7
+ ResourceVisibilityPatternSchema,
8
+ } from '../../resource';
9
+
10
+ /**
11
+ * Maximum length of the short identifier / label strings on a search-type
12
+ * manifest. Bounded so describe/list responses stay small and persisted rows
13
+ * have a predictable upper size.
14
+ */
15
+ const SEARCH_TYPE_STRING_MAX = 200;
16
+
17
+ /**
18
+ * Maximum length of the deep-link route template. A route template is a small
19
+ * path pattern (e.g. `/kb/{orgId}/pages/{slug}`), never a full document, so a
20
+ * generous-but-bounded cap keeps a contribution envelope small.
21
+ */
22
+ const SEARCH_TYPE_ROUTE_TEMPLATE_MAX = 500;
23
+
24
+ /**
25
+ * Hard cap on the number of searchable fields a single result-type may declare.
26
+ * A result-type that genuinely needs more distinct searchable fields is a
27
+ * modelling smell — fold the extra text into `content`.
28
+ */
29
+ const SEARCH_TYPE_FIELDS_MAX = 100;
30
+
31
+ /**
32
+ * `SearchTypeRenderHints` — the generic render/route hints a result-type ships
33
+ * so the frontend can present a hit WITHOUT hardcoding a per-kind switch. The
34
+ * search-web biome's generic renderer reads these; a new biome becomes
35
+ * fully-renderable purely by contributing them.
36
+ */
37
+ export interface SearchTypeRenderHints {
38
+ /** Human-readable result-type label (e.g. "Knowledge Page"). ≤ 200 chars. */
39
+ readonly label: string;
40
+ /** Optional icon slug/name the frontend maps to an icon component. ≤ 200 chars. */
41
+ readonly icon?: string;
42
+ /**
43
+ * Optional deep-link route template with `{placeholder}` segments the
44
+ * frontend fills from a result's fields (e.g. `/kb/{orgId}/pages/{slug}`).
45
+ * ≤ 500 chars. Absent ⇒ the result is not directly deep-linkable.
46
+ */
47
+ readonly routeTemplate?: string;
48
+ }
49
+
50
+ export const SearchTypeRenderHintsSchema: z.ZodType<SearchTypeRenderHints> =
51
+ z.object({
52
+ label: z.string().min(1).max(SEARCH_TYPE_STRING_MAX),
53
+ icon: z.string().min(1).max(SEARCH_TYPE_STRING_MAX).optional(),
54
+ routeTemplate: z
55
+ .string()
56
+ .min(1)
57
+ .max(SEARCH_TYPE_ROUTE_TEMPLATE_MAX)
58
+ .optional(),
59
+ }) as z.ZodType<SearchTypeRenderHints>;
60
+
61
+ /**
62
+ * `SearchTypeAuthzMapping` — how instances of this result-type map onto the
63
+ * result-level permission model. `resourceType` is the FGA resource-type slug
64
+ * used for the `authorization-api` `ListObjects` push-down; `defaultVisibility`
65
+ * is the fallback `ResourceVisibilityPattern` applied to an instance that does
66
+ * not carry its own per-instance visibility. Reuses the kernel
67
+ * `ResourceVisibilityPattern` — the SAME closed set the `ResourceOwnership`
68
+ * contribution declares — so search and object-registry never drift.
69
+ */
70
+ export interface SearchTypeAuthzMapping {
71
+ /** The FGA/authorization resource-type slug for this result-type. ≤ 200 chars. */
72
+ readonly resourceType: string;
73
+ /** Fallback visibility for an instance with no explicit per-instance pattern. */
74
+ readonly defaultVisibility: ResourceVisibilityPattern;
75
+ }
76
+
77
+ export const SearchTypeAuthzMappingSchema: z.ZodType<SearchTypeAuthzMapping> =
78
+ z.object({
79
+ resourceType: z.string().min(1).max(SEARCH_TYPE_STRING_MAX),
80
+ defaultVisibility: ResourceVisibilityPatternSchema,
81
+ }) as z.ZodType<SearchTypeAuthzMapping>;
82
+
83
+ /**
84
+ * Manifest shape carried by every `ContributionKind.SearchType` envelope.
85
+ * One contribution = one search RESULT-TYPE (the `(objectKind, docType)`
86
+ * facet).
87
+ *
88
+ * Mirrors `CapabilityContributionManifest` / `ResourceOwnershipContributionManifest`
89
+ * precisely: a value-identical subset of the wire body the owning service
90
+ * (`search-api`) accepts, validated fail-fast at biome-discovery time.
91
+ * Provenance (`biome.id`, `biome.version`) is NOT a field here — the
92
+ * `SearchTypeParser` stamps it from the discovering biome's `xema-biome.json`.
93
+ * Authors do not declare provenance inline.
94
+ *
95
+ * Validation is fail-fast: a contribution that violates any constraint is
96
+ * rejected at boot. No silent coercion.
97
+ */
98
+ export interface SearchTypeContributionManifest {
99
+ /**
100
+ * The `XemaObjectKind` this result-type covers. The object model is the
101
+ * identity/scope backbone — every result addresses through it.
102
+ */
103
+ readonly objectKind: XemaObjectKind;
104
+ /**
105
+ * Optional biome sub-facet under `objectKind` (e.g. `kb_page` under
106
+ * `knowledge-page`). Absent ⇒ the result-type covers the kind as a whole.
107
+ * The natural key of a result-type is `(objectKind, docType)`.
108
+ */
109
+ readonly docType?: string;
110
+ /** Generic render/route hints so the frontend presents hits without a per-kind switch. */
111
+ readonly renderHints: SearchTypeRenderHints;
112
+ /**
113
+ * The set of instance fields that carry retrieval-worthy text for this
114
+ * result-type. At least one; hard-capped at 100.
115
+ */
116
+ readonly searchableFields: readonly string[];
117
+ /**
118
+ * Default embedding-eligibility for instances of this result-type when the
119
+ * instance itself does not declare `embeddingEligible`. A closed, declared
120
+ * default — never inferred from any other field.
121
+ */
122
+ readonly embeddingEligibleDefault: boolean;
123
+ /** How instances of this result-type map onto the result-level permission model. */
124
+ readonly authz: SearchTypeAuthzMapping;
125
+ /**
126
+ * Optional capability ref for replaying/opening an instance of this
127
+ * result-type (e.g. `knowledge-base:page.replay@1`). Absent ⇒ this
128
+ * result-type has no replay capability. A typed `CapabilityRef`, never a
129
+ * free-form string.
130
+ */
131
+ readonly searchReplayCapabilityRef?: CapabilityRef;
132
+ }
133
+
134
+ /**
135
+ * Zod validator for `SearchTypeContributionManifest`. The biome-discovery
136
+ * parser AND `search-api`'s contribution-sync handler BOTH route every
137
+ * candidate envelope through this schema, so a malformed contribution fails at
138
+ * the boundary instead of at the wire (mirrors
139
+ * `CapabilityContributionManifestSchema`).
140
+ */
141
+ export const SearchTypeContributionManifestSchema: z.ZodType<SearchTypeContributionManifest> =
142
+ z.object({
143
+ objectKind: XemaObjectKindSchema,
144
+ docType: z.string().min(1).max(SEARCH_TYPE_STRING_MAX).optional(),
145
+ renderHints: SearchTypeRenderHintsSchema,
146
+ searchableFields: z
147
+ .array(z.string().min(1).max(SEARCH_TYPE_STRING_MAX))
148
+ .min(1)
149
+ .max(SEARCH_TYPE_FIELDS_MAX),
150
+ embeddingEligibleDefault: z.boolean(),
151
+ authz: SearchTypeAuthzMappingSchema,
152
+ searchReplayCapabilityRef: CapabilityRefSchema.optional(),
153
+ }) as z.ZodType<SearchTypeContributionManifest>;
154
+
155
+ /**
156
+ * The stable natural key of a result-type: `objectKind` when no `docType`, else
157
+ * `objectKind/docType`. Centralized so the parser slug, the DB unique key, and
158
+ * the reconciler's `seenKeyOf` all agree.
159
+ */
160
+ export function searchTypeNaturalKey(
161
+ objectKind: XemaObjectKind,
162
+ docType?: string,
163
+ ): string {
164
+ return docType ? `${objectKind}/${docType}` : String(objectKind);
165
+ }