@oscharko-dev/keiko-contracts 0.2.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.
- package/dist/.tsbuildinfo +1 -0
- package/dist/bff-wire.d.ts +661 -0
- package/dist/bff-wire.d.ts.map +1 -0
- package/dist/bff-wire.js +102 -0
- package/dist/bug-investigation-events.d.ts +92 -0
- package/dist/bug-investigation-events.d.ts.map +1 -0
- package/dist/bug-investigation-events.js +18 -0
- package/dist/coding-context.d.ts +76 -0
- package/dist/coding-context.d.ts.map +1 -0
- package/dist/coding-context.js +158 -0
- package/dist/connected-context.d.ts +174 -0
- package/dist/connected-context.d.ts.map +1 -0
- package/dist/connected-context.js +636 -0
- package/dist/conversation-budget.d.ts +37 -0
- package/dist/conversation-budget.d.ts.map +1 -0
- package/dist/conversation-budget.js +97 -0
- package/dist/editor-agent.d.ts +131 -0
- package/dist/editor-agent.d.ts.map +1 -0
- package/dist/editor-agent.js +197 -0
- package/dist/editor-completion.d.ts +62 -0
- package/dist/editor-completion.d.ts.map +1 -0
- package/dist/editor-completion.js +147 -0
- package/dist/editor-dirty-close.d.ts +17 -0
- package/dist/editor-dirty-close.d.ts.map +1 -0
- package/dist/editor-dirty-close.js +8 -0
- package/dist/editor-hot-exit.d.ts +18 -0
- package/dist/editor-hot-exit.d.ts.map +1 -0
- package/dist/editor-hot-exit.js +42 -0
- package/dist/editor-inline-completion.d.ts +70 -0
- package/dist/editor-inline-completion.d.ts.map +1 -0
- package/dist/editor-inline-completion.js +215 -0
- package/dist/editor-layout.d.ts +105 -0
- package/dist/editor-layout.d.ts.map +1 -0
- package/dist/editor-layout.js +479 -0
- package/dist/editor-patch-apply.d.ts +77 -0
- package/dist/editor-patch-apply.d.ts.map +1 -0
- package/dist/editor-patch-apply.js +122 -0
- package/dist/editor-session.d.ts +31 -0
- package/dist/editor-session.d.ts.map +1 -0
- package/dist/editor-session.js +75 -0
- package/dist/editor-test-generation.d.ts +104 -0
- package/dist/editor-test-generation.d.ts.map +1 -0
- package/dist/editor-test-generation.js +211 -0
- package/dist/evaluations.d.ts +75 -0
- package/dist/evaluations.d.ts.map +1 -0
- package/dist/evaluations.js +16 -0
- package/dist/evidence.d.ts +297 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +9 -0
- package/dist/gateway.d.ts +129 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +66 -0
- package/dist/harness.d.ts +274 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/harness.js +38 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +83 -0
- package/dist/language-service.d.ts +145 -0
- package/dist/language-service.d.ts.map +1 -0
- package/dist/language-service.js +161 -0
- package/dist/local-knowledge-large-document-validation.d.ts +7 -0
- package/dist/local-knowledge-large-document-validation.d.ts.map +1 -0
- package/dist/local-knowledge-large-document-validation.js +161 -0
- package/dist/local-knowledge-large-document.d.ts +113 -0
- package/dist/local-knowledge-large-document.d.ts.map +1 -0
- package/dist/local-knowledge-large-document.js +142 -0
- package/dist/local-knowledge-paths.d.ts +3 -0
- package/dist/local-knowledge-paths.d.ts.map +1 -0
- package/dist/local-knowledge-paths.js +65 -0
- package/dist/local-knowledge-records.d.ts +190 -0
- package/dist/local-knowledge-records.d.ts.map +1 -0
- package/dist/local-knowledge-records.js +36 -0
- package/dist/local-knowledge-schema-validation.d.ts +19 -0
- package/dist/local-knowledge-schema-validation.d.ts.map +1 -0
- package/dist/local-knowledge-schema-validation.js +115 -0
- package/dist/local-knowledge-schema.d.ts +14 -0
- package/dist/local-knowledge-schema.d.ts.map +1 -0
- package/dist/local-knowledge-schema.js +715 -0
- package/dist/local-knowledge-validation.d.ts +20 -0
- package/dist/local-knowledge-validation.d.ts.map +1 -0
- package/dist/local-knowledge-validation.js +487 -0
- package/dist/local-knowledge.d.ts +158 -0
- package/dist/local-knowledge.d.ts.map +1 -0
- package/dist/local-knowledge.js +63 -0
- package/dist/memory-audit-events.d.ts +73 -0
- package/dist/memory-audit-events.d.ts.map +1 -0
- package/dist/memory-audit-events.js +44 -0
- package/dist/memory-audit-validation.d.ts +4 -0
- package/dist/memory-audit-validation.d.ts.map +1 -0
- package/dist/memory-audit-validation.js +151 -0
- package/dist/memory-barrel.d.ts +15 -0
- package/dist/memory-barrel.d.ts.map +1 -0
- package/dist/memory-barrel.js +20 -0
- package/dist/memory-internal.d.ts +26 -0
- package/dist/memory-internal.d.ts.map +1 -0
- package/dist/memory-internal.js +104 -0
- package/dist/memory-operations-validation.d.ts +12 -0
- package/dist/memory-operations-validation.d.ts.map +1 -0
- package/dist/memory-operations-validation.js +267 -0
- package/dist/memory-operations.d.ts +156 -0
- package/dist/memory-operations.d.ts.map +1 -0
- package/dist/memory-operations.js +29 -0
- package/dist/memory-record-validation.d.ts +10 -0
- package/dist/memory-record-validation.d.ts.map +1 -0
- package/dist/memory-record-validation.js +101 -0
- package/dist/memory-records.d.ts +66 -0
- package/dist/memory-records.d.ts.map +1 -0
- package/dist/memory-records.js +22 -0
- package/dist/memory-retrieval-validation.d.ts +6 -0
- package/dist/memory-retrieval-validation.d.ts.map +1 -0
- package/dist/memory-retrieval-validation.js +108 -0
- package/dist/memory-validation.d.ts +31 -0
- package/dist/memory-validation.d.ts.map +1 -0
- package/dist/memory-validation.js +318 -0
- package/dist/memory-workflow-port.d.ts +26 -0
- package/dist/memory-workflow-port.d.ts.map +1 -0
- package/dist/memory-workflow-port.js +13 -0
- package/dist/memory.d.ts +81 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +104 -0
- package/dist/prompt-enhancer-analyzer.d.ts +7 -0
- package/dist/prompt-enhancer-analyzer.d.ts.map +1 -0
- package/dist/prompt-enhancer-analyzer.js +745 -0
- package/dist/prompt-enhancer-bff.d.ts +67 -0
- package/dist/prompt-enhancer-bff.d.ts.map +1 -0
- package/dist/prompt-enhancer-bff.js +156 -0
- package/dist/prompt-enhancer-critic.d.ts +46 -0
- package/dist/prompt-enhancer-critic.d.ts.map +1 -0
- package/dist/prompt-enhancer-critic.js +35 -0
- package/dist/prompt-enhancer-grounding.d.ts +19 -0
- package/dist/prompt-enhancer-grounding.d.ts.map +1 -0
- package/dist/prompt-enhancer-grounding.js +235 -0
- package/dist/prompt-enhancer-safety.d.ts +66 -0
- package/dist/prompt-enhancer-safety.d.ts.map +1 -0
- package/dist/prompt-enhancer-safety.js +446 -0
- package/dist/prompt-enhancer-validation.d.ts +28 -0
- package/dist/prompt-enhancer-validation.d.ts.map +1 -0
- package/dist/prompt-enhancer-validation.js +931 -0
- package/dist/prompt-enhancer.d.ts +184 -0
- package/dist/prompt-enhancer.d.ts.map +1 -0
- package/dist/prompt-enhancer.js +350 -0
- package/dist/qualityIntelligence/assertNever.d.ts +2 -0
- package/dist/qualityIntelligence/assertNever.d.ts.map +1 -0
- package/dist/qualityIntelligence/assertNever.js +7 -0
- package/dist/qualityIntelligence/auditSummary.d.ts +25 -0
- package/dist/qualityIntelligence/auditSummary.d.ts.map +1 -0
- package/dist/qualityIntelligence/auditSummary.js +7 -0
- package/dist/qualityIntelligence/bffWire.d.ts +356 -0
- package/dist/qualityIntelligence/bffWire.d.ts.map +1 -0
- package/dist/qualityIntelligence/bffWire.js +22 -0
- package/dist/qualityIntelligence/coverageMap.d.ts +21 -0
- package/dist/qualityIntelligence/coverageMap.d.ts.map +1 -0
- package/dist/qualityIntelligence/coverageMap.js +29 -0
- package/dist/qualityIntelligence/editableRevision.d.ts +21 -0
- package/dist/qualityIntelligence/editableRevision.d.ts.map +1 -0
- package/dist/qualityIntelligence/editableRevision.js +8 -0
- package/dist/qualityIntelligence/evidenceAtom.d.ts +35 -0
- package/dist/qualityIntelligence/evidenceAtom.d.ts.map +1 -0
- package/dist/qualityIntelligence/evidenceAtom.js +29 -0
- package/dist/qualityIntelligence/exportBundle.d.ts +28 -0
- package/dist/qualityIntelligence/exportBundle.d.ts.map +1 -0
- package/dist/qualityIntelligence/exportBundle.js +46 -0
- package/dist/qualityIntelligence/handoffEnvelope.d.ts +23 -0
- package/dist/qualityIntelligence/handoffEnvelope.d.ts.map +1 -0
- package/dist/qualityIntelligence/handoffEnvelope.js +8 -0
- package/dist/qualityIntelligence/ids.d.ts +58 -0
- package/dist/qualityIntelligence/ids.d.ts.map +1 -0
- package/dist/qualityIntelligence/ids.js +93 -0
- package/dist/qualityIntelligence/index.d.ts +29 -0
- package/dist/qualityIntelligence/index.d.ts.map +1 -0
- package/dist/qualityIntelligence/index.js +20 -0
- package/dist/qualityIntelligence/reviewRecord.d.ts +19 -0
- package/dist/qualityIntelligence/reviewRecord.d.ts.map +1 -0
- package/dist/qualityIntelligence/reviewRecord.js +20 -0
- package/dist/qualityIntelligence/runPlanAndEvents.d.ts +84 -0
- package/dist/qualityIntelligence/runPlanAndEvents.d.ts.map +1 -0
- package/dist/qualityIntelligence/runPlanAndEvents.js +51 -0
- package/dist/qualityIntelligence/sourceEnvelope.d.ts +77 -0
- package/dist/qualityIntelligence/sourceEnvelope.d.ts.map +1 -0
- package/dist/qualityIntelligence/sourceEnvelope.js +118 -0
- package/dist/qualityIntelligence/testCaseCandidate.d.ts +21 -0
- package/dist/qualityIntelligence/testCaseCandidate.d.ts.map +1 -0
- package/dist/qualityIntelligence/testCaseCandidate.js +21 -0
- package/dist/qualityIntelligence/testQualityRubric.d.ts +17 -0
- package/dist/qualityIntelligence/testQualityRubric.d.ts.map +1 -0
- package/dist/qualityIntelligence/testQualityRubric.js +32 -0
- package/dist/qualityIntelligence/validationFinding.d.ts +48 -0
- package/dist/qualityIntelligence/validationFinding.d.ts.map +1 -0
- package/dist/qualityIntelligence/validationFinding.js +36 -0
- package/dist/relationships-validation.d.ts +13 -0
- package/dist/relationships-validation.d.ts.map +1 -0
- package/dist/relationships-validation.js +422 -0
- package/dist/relationships.d.ts +79 -0
- package/dist/relationships.d.ts.map +1 -0
- package/dist/relationships.js +307 -0
- package/dist/text-safety.d.ts +7 -0
- package/dist/text-safety.d.ts.map +1 -0
- package/dist/text-safety.js +58 -0
- package/dist/tools.d.ts +153 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +118 -0
- package/dist/unit-test-events.d.ts +87 -0
- package/dist/unit-test-events.d.ts.map +1 -0
- package/dist/unit-test-events.js +14 -0
- package/dist/verification-summary.d.ts +38 -0
- package/dist/verification-summary.d.ts.map +1 -0
- package/dist/verification-summary.js +5 -0
- package/dist/verification.d.ts +64 -0
- package/dist/verification.d.ts.map +1 -0
- package/dist/verification.js +13 -0
- package/dist/workflow-descriptor.d.ts +21 -0
- package/dist/workflow-descriptor.d.ts.map +1 -0
- package/dist/workflow-descriptor.js +8 -0
- package/dist/workflow-handoff.d.ts +69 -0
- package/dist/workflow-handoff.d.ts.map +1 -0
- package/dist/workflow-handoff.js +381 -0
- package/dist/workspace-descriptors.d.ts +21 -0
- package/dist/workspace-descriptors.d.ts.map +1 -0
- package/dist/workspace-descriptors.js +180 -0
- package/dist/workspace-ui.d.ts +119 -0
- package/dist/workspace-ui.d.ts.map +1 -0
- package/dist/workspace-ui.js +105 -0
- package/dist/workspace.d.ts +104 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +27 -0
- package/package.json +71 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CapsuleSet, ConnectorGraphState, ConnectorNode, EmbeddingModelIdentity, KnowledgeCapsule, KnowledgeSourceScope } from "./local-knowledge.js";
|
|
2
|
+
import type { CapsuleReindexRequest } from "./local-knowledge-records.js";
|
|
3
|
+
export interface ValidationOk<T> {
|
|
4
|
+
readonly ok: true;
|
|
5
|
+
readonly value: T;
|
|
6
|
+
}
|
|
7
|
+
export interface ValidationFail {
|
|
8
|
+
readonly ok: false;
|
|
9
|
+
readonly errors: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
export type LocalKnowledgeValidation<T> = ValidationOk<T> | ValidationFail;
|
|
12
|
+
export declare function isSafeDisplaySummary(value: unknown): value is string;
|
|
13
|
+
export declare function validateEmbeddingModelIdentity(input: unknown): LocalKnowledgeValidation<EmbeddingModelIdentity>;
|
|
14
|
+
export declare function validateKnowledgeSourceScope(input: unknown): LocalKnowledgeValidation<KnowledgeSourceScope>;
|
|
15
|
+
export declare function validateKnowledgeCapsule(input: unknown): LocalKnowledgeValidation<KnowledgeCapsule>;
|
|
16
|
+
export declare function validateCapsuleSet(input: unknown): LocalKnowledgeValidation<CapsuleSet>;
|
|
17
|
+
export declare function validateCapsuleReindexRequest(input: unknown): LocalKnowledgeValidation<CapsuleReindexRequest>;
|
|
18
|
+
export declare function validateConnectorGraphState(input: unknown): LocalKnowledgeValidation<ConnectorGraphState>;
|
|
19
|
+
export type { ConnectorNode };
|
|
20
|
+
//# sourceMappingURL=local-knowledge-validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-knowledge-validation.d.ts","sourceRoot":"","sources":["../src/local-knowledge-validation.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EACnB,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAiB1E,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CACnB;AACD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AACD,MAAM,MAAM,wBAAwB,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC;AAmC3E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAQpE;AAyFD,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,OAAO,GACb,wBAAwB,CAAC,sBAAsB,CAAC,CA2BlD;AA+ED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,OAAO,GACb,wBAAwB,CAAC,oBAAoB,CAAC,CAuBhD;AAwDD,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,GACb,wBAAwB,CAAC,gBAAgB,CAAC,CA4B5C;AAgBD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,wBAAwB,CAAC,UAAU,CAAC,CAuBvF;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,OAAO,GACb,wBAAwB,CAAC,qBAAqB,CAAC,CAqBjD;AAmKD,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,OAAO,GACb,wBAAwB,CAAC,mBAAmB,CAAC,CAuB/C;AAID,YAAY,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
// Pure validators for the Local Knowledge Connector contracts (Epic #189, Issue #191).
|
|
2
|
+
// No filesystem reads, no clock reads, no crypto, no randomness; these helpers only inspect
|
|
3
|
+
// the structure of an `unknown` payload and report which invariants failed. Producers and
|
|
4
|
+
// consumers wire these at trust-boundary edges (BFF, audit, indexer entry points).
|
|
5
|
+
//
|
|
6
|
+
// Each validator returns a discriminated `{ ok: true; value } | { ok: false; errors }` so
|
|
7
|
+
// downstream code can branch without throwing. Errors are short, machine-readable strings,
|
|
8
|
+
// one per failed invariant, to keep diagnostics deterministic for evaluation harnesses.
|
|
9
|
+
import { CAPSULE_ANSWER_GROUNDING_POLICIES, CAPSULE_LIFECYCLE_STATES, CAPSULE_METADATA_KEY_MAX_CHARS, CAPSULE_METADATA_MAX_KEYS, CAPSULE_METADATA_VALUE_MAX_CHARS, CAPSULE_OUTPUT_MODES, CAPSULE_RETRIEVAL_EFFORTS, CONNECTOR_NODE_KINDS, EMBEDDING_VECTOR_METRICS, KNOWLEDGE_SOURCE_SCOPE_KINDS, } from "./local-knowledge.js";
|
|
10
|
+
import { CAPSULE_REINDEX_MODES } from "./local-knowledge-records.js";
|
|
11
|
+
import { isSafeScopePath, isSafeStorageReference } from "./local-knowledge-paths.js";
|
|
12
|
+
// ─── Shared primitive guards ──────────────────────────────────────────────────
|
|
13
|
+
function isRecord(value) {
|
|
14
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
function isNonEmptyTrimmedString(value) {
|
|
17
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
18
|
+
}
|
|
19
|
+
function isFiniteNonNegativeNumber(value) {
|
|
20
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
21
|
+
}
|
|
22
|
+
function isFinitePositiveInteger(value) {
|
|
23
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
24
|
+
}
|
|
25
|
+
function isStringArray(value) {
|
|
26
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
27
|
+
}
|
|
28
|
+
// Soft-cap chosen to keep browser surfaces safe (matches the upper bound a Conversation
|
|
29
|
+
// Center summary card will render without truncation). NUL and the ASCII control range
|
|
30
|
+
// are rejected because they corrupt terminal output and many UI text renderers; \n and \t
|
|
31
|
+
// are explicitly allowed since legitimate display strings carry line breaks.
|
|
32
|
+
const SAFE_DISPLAY_MAX_CHARS = 4096;
|
|
33
|
+
// Intentionally matches control characters; this is the entire purpose of the safety
|
|
34
|
+
// gate. The `no-control-regex` lint rule guards against accidental control matches, not
|
|
35
|
+
// deliberate ones.
|
|
36
|
+
// eslint-disable-next-line no-control-regex
|
|
37
|
+
const FORBIDDEN_CONTROL_RE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/;
|
|
38
|
+
export function isSafeDisplaySummary(value) {
|
|
39
|
+
if (typeof value !== "string") {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (value.length > SAFE_DISPLAY_MAX_CHARS) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return !FORBIDDEN_CONTROL_RE.test(value);
|
|
46
|
+
}
|
|
47
|
+
function isSafeDisplayString(value) {
|
|
48
|
+
return isNonEmptyTrimmedString(value) && isSafeDisplaySummary(value);
|
|
49
|
+
}
|
|
50
|
+
function validateSafeDisplayStringField(errors, field, value) {
|
|
51
|
+
if (!isSafeDisplayString(value)) {
|
|
52
|
+
errors.push(`${field} must be a browser-safe non-empty trimmed string`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function validateSafeDisplayStringArrayField(errors, field, value) {
|
|
56
|
+
if (!Array.isArray(value)) {
|
|
57
|
+
errors.push(`${field} must be a string array`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
for (const entry of value) {
|
|
61
|
+
if (!isSafeDisplayString(entry)) {
|
|
62
|
+
errors.push(`${field} entry must be a browser-safe non-empty trimmed string`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function validateSafeMetadataMap(errors, field, value) {
|
|
68
|
+
if (value === undefined) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!isRecord(value)) {
|
|
72
|
+
errors.push(`${field} must be an object when set`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const entries = Object.entries(value);
|
|
76
|
+
if (entries.length > CAPSULE_METADATA_MAX_KEYS) {
|
|
77
|
+
errors.push(`${field} may contain at most ${String(CAPSULE_METADATA_MAX_KEYS)} entries`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
for (const [key, entryValue] of entries) {
|
|
81
|
+
if (!isSafeDisplayString(key) || key.length > CAPSULE_METADATA_KEY_MAX_CHARS) {
|
|
82
|
+
errors.push(`${field} keys must be browser-safe non-empty strings no longer than ${String(CAPSULE_METADATA_KEY_MAX_CHARS)} characters`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (typeof entryValue !== "string" ||
|
|
86
|
+
!isSafeDisplaySummary(entryValue) ||
|
|
87
|
+
entryValue.length > CAPSULE_METADATA_VALUE_MAX_CHARS) {
|
|
88
|
+
errors.push(`${field} values must be browser-safe strings no longer than ${String(CAPSULE_METADATA_VALUE_MAX_CHARS)} characters`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function validateOnlyKeys(record, allowedKeys, field, errors) {
|
|
94
|
+
const allowed = new Set(allowedKeys);
|
|
95
|
+
for (const key of Object.keys(record)) {
|
|
96
|
+
if (!allowed.has(key)) {
|
|
97
|
+
errors.push(`${field} must not include ${key}`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// ─── EmbeddingModelIdentity ───────────────────────────────────────────────────
|
|
103
|
+
function pushBadEnum(errors, field, value, allowed) {
|
|
104
|
+
if (typeof value !== "string" || !allowed.includes(value)) {
|
|
105
|
+
errors.push(`${field} must be one of ${allowed.join("|")}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export function validateEmbeddingModelIdentity(input) {
|
|
109
|
+
const errors = [];
|
|
110
|
+
if (!isRecord(input)) {
|
|
111
|
+
return { ok: false, errors: ["embeddingModelIdentity must be an object"] };
|
|
112
|
+
}
|
|
113
|
+
if (!isNonEmptyTrimmedString(input.provider)) {
|
|
114
|
+
errors.push("embeddingModelIdentity.provider must be a non-empty string");
|
|
115
|
+
}
|
|
116
|
+
if (!isNonEmptyTrimmedString(input.modelId)) {
|
|
117
|
+
errors.push("embeddingModelIdentity.modelId must be a non-empty string");
|
|
118
|
+
}
|
|
119
|
+
if (!isFinitePositiveInteger(input.vectorDimensions)) {
|
|
120
|
+
errors.push("embeddingModelIdentity.vectorDimensions must be a positive integer");
|
|
121
|
+
}
|
|
122
|
+
pushBadEnum(errors, "embeddingModelIdentity.vectorMetric", input.vectorMetric, EMBEDDING_VECTOR_METRICS);
|
|
123
|
+
if (input.modelRevision !== undefined && !isNonEmptyTrimmedString(input.modelRevision)) {
|
|
124
|
+
errors.push("embeddingModelIdentity.modelRevision must be a non-empty string when set");
|
|
125
|
+
}
|
|
126
|
+
if (errors.length > 0) {
|
|
127
|
+
return { ok: false, errors };
|
|
128
|
+
}
|
|
129
|
+
return { ok: true, value: input };
|
|
130
|
+
}
|
|
131
|
+
// ─── KnowledgeSourceScope ─────────────────────────────────────────────────────
|
|
132
|
+
function validateGlobs(field, globs, errors) {
|
|
133
|
+
if (globs === undefined) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (!isStringArray(globs)) {
|
|
137
|
+
errors.push(`${field} must be a string array when set`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (globs.length === 0) {
|
|
141
|
+
errors.push(`${field} must be omitted instead of set to an empty array`);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const seen = new Set();
|
|
145
|
+
for (const glob of globs) {
|
|
146
|
+
if (glob.length === 0 || glob.includes("\0") || !isSafeStorageReference(glob)) {
|
|
147
|
+
errors.push(`${field} entry must be a safe relative NUL-free glob`);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (seen.has(glob)) {
|
|
151
|
+
errors.push(`${field} entries must be unique`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
seen.add(glob);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function validateGlobOverlap(input, errors) {
|
|
158
|
+
if (!isStringArray(input.includeGlobs) || !isStringArray(input.excludeGlobs)) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const include = new Set(input.includeGlobs);
|
|
162
|
+
for (const exclude of input.excludeGlobs) {
|
|
163
|
+
if (include.has(exclude)) {
|
|
164
|
+
errors.push("scope.excludeGlobs entries must not exactly cancel includeGlobs entries");
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function validateFolderScope(input, errors) {
|
|
170
|
+
if (typeof input.rootPath !== "string" || !isSafeScopePath(input.rootPath)) {
|
|
171
|
+
errors.push("scope.rootPath is unsafe or empty");
|
|
172
|
+
}
|
|
173
|
+
if (typeof input.recursive !== "boolean") {
|
|
174
|
+
errors.push("scope.recursive must be a boolean");
|
|
175
|
+
}
|
|
176
|
+
validateGlobs("scope.includeGlobs", input.includeGlobs, errors);
|
|
177
|
+
validateGlobs("scope.excludeGlobs", input.excludeGlobs, errors);
|
|
178
|
+
validateGlobOverlap(input, errors);
|
|
179
|
+
}
|
|
180
|
+
function validateRepositoryScope(input, errors) {
|
|
181
|
+
if (typeof input.repositoryRoot !== "string" || !isSafeScopePath(input.repositoryRoot)) {
|
|
182
|
+
errors.push("scope.repositoryRoot is unsafe or empty");
|
|
183
|
+
}
|
|
184
|
+
validateGlobs("scope.includeGlobs", input.includeGlobs, errors);
|
|
185
|
+
validateGlobs("scope.excludeGlobs", input.excludeGlobs, errors);
|
|
186
|
+
validateGlobOverlap(input, errors);
|
|
187
|
+
}
|
|
188
|
+
function validateFilesScope(input, errors) {
|
|
189
|
+
if (typeof input.rootPath !== "string" || !isSafeScopePath(input.rootPath)) {
|
|
190
|
+
errors.push("scope.rootPath is unsafe or empty");
|
|
191
|
+
}
|
|
192
|
+
if (!Array.isArray(input.files) || input.files.length === 0) {
|
|
193
|
+
errors.push("scope.files must be a non-empty array");
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
for (const entry of input.files) {
|
|
197
|
+
if (typeof entry !== "string" || !isSafeStorageReference(entry)) {
|
|
198
|
+
errors.push("scope.files entry is unsafe or empty");
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
export function validateKnowledgeSourceScope(input) {
|
|
204
|
+
if (!isRecord(input)) {
|
|
205
|
+
return { ok: false, errors: ["scope must be an object"] };
|
|
206
|
+
}
|
|
207
|
+
const kind = input.kind;
|
|
208
|
+
if (!KNOWLEDGE_SOURCE_SCOPE_KINDS.includes(kind)) {
|
|
209
|
+
return {
|
|
210
|
+
ok: false,
|
|
211
|
+
errors: [`scope.kind must be one of ${KNOWLEDGE_SOURCE_SCOPE_KINDS.join("|")}`],
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const errors = [];
|
|
215
|
+
if (kind === "folder") {
|
|
216
|
+
validateFolderScope(input, errors);
|
|
217
|
+
}
|
|
218
|
+
else if (kind === "repository") {
|
|
219
|
+
validateRepositoryScope(input, errors);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
validateFilesScope(input, errors);
|
|
223
|
+
}
|
|
224
|
+
if (errors.length > 0) {
|
|
225
|
+
return { ok: false, errors };
|
|
226
|
+
}
|
|
227
|
+
return { ok: true, value: input };
|
|
228
|
+
}
|
|
229
|
+
// ─── KnowledgeCapsule ─────────────────────────────────────────────────────────
|
|
230
|
+
function validateCapsuleEnums(input, errors) {
|
|
231
|
+
pushBadEnum(errors, "capsule.retrievalEffort", input.retrievalEffort, CAPSULE_RETRIEVAL_EFFORTS);
|
|
232
|
+
pushBadEnum(errors, "capsule.outputMode", input.outputMode, CAPSULE_OUTPUT_MODES);
|
|
233
|
+
pushBadEnum(errors, "capsule.answerGroundingPolicy", input.answerGroundingPolicy, CAPSULE_ANSWER_GROUNDING_POLICIES);
|
|
234
|
+
pushBadEnum(errors, "capsule.lifecycleState", input.lifecycleState, CAPSULE_LIFECYCLE_STATES);
|
|
235
|
+
}
|
|
236
|
+
function validateCapsuleTimestamps(input, errors) {
|
|
237
|
+
if (!isFiniteNonNegativeNumber(input.createdAt)) {
|
|
238
|
+
errors.push("capsule.createdAt must be a finite non-negative number");
|
|
239
|
+
}
|
|
240
|
+
if (!isFiniteNonNegativeNumber(input.updatedAt)) {
|
|
241
|
+
errors.push("capsule.updatedAt must be a finite non-negative number");
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function validateCapsuleSourceLineage(input, errors) {
|
|
245
|
+
if (!Array.isArray(input.sourceIds) || input.sourceIds.length === 0) {
|
|
246
|
+
errors.push("capsule.sourceIds must be a non-empty array");
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
for (const id of input.sourceIds) {
|
|
250
|
+
if (!isNonEmptyTrimmedString(id)) {
|
|
251
|
+
errors.push("capsule.sourceIds entry must be a non-empty string");
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function validateKnowledgeCapsuleDisplayMetadata(input, errors) {
|
|
257
|
+
validateSafeDisplayStringField(errors, "capsule.displayName", input.displayName);
|
|
258
|
+
if (input.description !== undefined) {
|
|
259
|
+
validateSafeDisplayStringField(errors, "capsule.description", input.description);
|
|
260
|
+
}
|
|
261
|
+
if (input.sourceRoutingInstructions !== undefined) {
|
|
262
|
+
validateSafeDisplayStringField(errors, "capsule.sourceRoutingInstructions", input.sourceRoutingInstructions);
|
|
263
|
+
}
|
|
264
|
+
validateSafeDisplayStringArrayField(errors, "capsule.tags", input.tags);
|
|
265
|
+
validateSafeMetadataMap(errors, "capsule.metadata", input.metadata);
|
|
266
|
+
}
|
|
267
|
+
export function validateKnowledgeCapsule(input) {
|
|
268
|
+
if (!isRecord(input)) {
|
|
269
|
+
return { ok: false, errors: ["capsule must be an object"] };
|
|
270
|
+
}
|
|
271
|
+
const errors = [];
|
|
272
|
+
if (!isNonEmptyTrimmedString(input.id)) {
|
|
273
|
+
errors.push("capsule.id must be a non-empty string");
|
|
274
|
+
}
|
|
275
|
+
validateKnowledgeCapsuleDisplayMetadata(input, errors);
|
|
276
|
+
validateCapsuleSourceLineage(input, errors);
|
|
277
|
+
validateCapsuleEnums(input, errors);
|
|
278
|
+
const identityResult = validateEmbeddingModelIdentity(input.embeddingModelIdentity);
|
|
279
|
+
if (!identityResult.ok) {
|
|
280
|
+
for (const reason of identityResult.errors) {
|
|
281
|
+
errors.push(`capsule.${reason}`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (typeof input.storageReference !== "string" ||
|
|
285
|
+
!isSafeStorageReference(input.storageReference)) {
|
|
286
|
+
errors.push("capsule.storageReference must be a safe relative path");
|
|
287
|
+
}
|
|
288
|
+
validateCapsuleTimestamps(input, errors);
|
|
289
|
+
if (errors.length > 0) {
|
|
290
|
+
return { ok: false, errors };
|
|
291
|
+
}
|
|
292
|
+
return { ok: true, value: input };
|
|
293
|
+
}
|
|
294
|
+
// ─── CapsuleSet ───────────────────────────────────────────────────────────────
|
|
295
|
+
function validateCapsuleSetCapsuleIds(input, errors) {
|
|
296
|
+
if (!Array.isArray(input.capsuleIds) || input.capsuleIds.length === 0) {
|
|
297
|
+
errors.push("capsuleSet.capsuleIds must be a non-empty array");
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
for (const id of input.capsuleIds) {
|
|
301
|
+
if (!isNonEmptyTrimmedString(id)) {
|
|
302
|
+
errors.push("capsuleSet.capsuleIds entry must be a non-empty string");
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
export function validateCapsuleSet(input) {
|
|
308
|
+
if (!isRecord(input)) {
|
|
309
|
+
return { ok: false, errors: ["capsuleSet must be an object"] };
|
|
310
|
+
}
|
|
311
|
+
const errors = [];
|
|
312
|
+
if (!isNonEmptyTrimmedString(input.id)) {
|
|
313
|
+
errors.push("capsuleSet.id must be a non-empty string");
|
|
314
|
+
}
|
|
315
|
+
if (!isSafeDisplayString(input.displayName)) {
|
|
316
|
+
errors.push("capsuleSet.displayName must be a browser-safe non-empty trimmed string");
|
|
317
|
+
}
|
|
318
|
+
if (input.description !== undefined && !isSafeDisplayString(input.description)) {
|
|
319
|
+
errors.push("capsuleSet.description must be a browser-safe non-empty trimmed string");
|
|
320
|
+
}
|
|
321
|
+
validateSafeDisplayStringArrayField(errors, "capsuleSet.tags", input.tags);
|
|
322
|
+
validateCapsuleSetCapsuleIds(input, errors);
|
|
323
|
+
if (!isFiniteNonNegativeNumber(input.composedAt)) {
|
|
324
|
+
errors.push("capsuleSet.composedAt must be a finite non-negative number");
|
|
325
|
+
}
|
|
326
|
+
if (errors.length > 0) {
|
|
327
|
+
return { ok: false, errors };
|
|
328
|
+
}
|
|
329
|
+
return { ok: true, value: input };
|
|
330
|
+
}
|
|
331
|
+
export function validateCapsuleReindexRequest(input) {
|
|
332
|
+
if (!isRecord(input)) {
|
|
333
|
+
return { ok: false, errors: ["reindexRequest must be an object"] };
|
|
334
|
+
}
|
|
335
|
+
const errors = [];
|
|
336
|
+
if (!isNonEmptyTrimmedString(input.capsuleId)) {
|
|
337
|
+
errors.push("reindexRequest.capsuleId must be a non-empty string");
|
|
338
|
+
}
|
|
339
|
+
if (input.mode !== undefined &&
|
|
340
|
+
!CAPSULE_REINDEX_MODES.includes(input.mode)) {
|
|
341
|
+
errors.push(`reindexRequest.mode must be one of ${CAPSULE_REINDEX_MODES.join("|")}`);
|
|
342
|
+
}
|
|
343
|
+
if (input.force !== undefined && typeof input.force !== "boolean") {
|
|
344
|
+
errors.push("reindexRequest.force must be a boolean when provided");
|
|
345
|
+
}
|
|
346
|
+
if (errors.length > 0) {
|
|
347
|
+
return { ok: false, errors };
|
|
348
|
+
}
|
|
349
|
+
return { ok: true, value: input };
|
|
350
|
+
}
|
|
351
|
+
// ─── ConnectorGraphState ──────────────────────────────────────────────────────
|
|
352
|
+
function validateFilesWindowNode(node, errors) {
|
|
353
|
+
validateOnlyKeys(node, ["kind", "nodeId", "scope"], "graph.nodes entry.files-window", errors);
|
|
354
|
+
const scopeResult = validateKnowledgeSourceScope(node.scope);
|
|
355
|
+
if (!scopeResult.ok) {
|
|
356
|
+
for (const reason of scopeResult.errors) {
|
|
357
|
+
errors.push(`graph.nodes entry.files-window.${reason}`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function validateLocalKnowledgeNodeTarget(target, errors) {
|
|
362
|
+
if (!isRecord(target)) {
|
|
363
|
+
errors.push("graph.nodes entry.local-knowledge.target must be an object");
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (target.kind === "capsule") {
|
|
367
|
+
validateOnlyKeys(target, ["kind", "capsuleId"], "graph.nodes entry.local-knowledge.target.capsule", errors);
|
|
368
|
+
if (!isNonEmptyTrimmedString(target.capsuleId)) {
|
|
369
|
+
errors.push("graph.nodes entry.local-knowledge.target.capsuleId must be a non-empty string");
|
|
370
|
+
}
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if (target.kind === "capsule-set") {
|
|
374
|
+
validateOnlyKeys(target, ["kind", "capsuleSetId"], "graph.nodes entry.local-knowledge.target.capsule-set", errors);
|
|
375
|
+
if (!isNonEmptyTrimmedString(target.capsuleSetId)) {
|
|
376
|
+
errors.push("graph.nodes entry.local-knowledge.target.capsuleSetId must be a non-empty string");
|
|
377
|
+
}
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
errors.push('graph.nodes entry.local-knowledge.target.kind must be "capsule" or "capsule-set"');
|
|
381
|
+
}
|
|
382
|
+
function validateLocalKnowledgeNode(node, errors) {
|
|
383
|
+
validateOnlyKeys(node, ["kind", "nodeId", "target"], "graph.nodes entry.local-knowledge", errors);
|
|
384
|
+
validateLocalKnowledgeNodeTarget(node.target, errors);
|
|
385
|
+
}
|
|
386
|
+
function validateConversationCenterNode(node, errors) {
|
|
387
|
+
validateOnlyKeys(node, ["kind", "nodeId", "conversationId", "route"], "graph.nodes entry.conversation-center", errors);
|
|
388
|
+
if (!isNonEmptyTrimmedString(node.conversationId)) {
|
|
389
|
+
errors.push("graph.nodes entry.conversation-center.conversationId must be a non-empty string");
|
|
390
|
+
}
|
|
391
|
+
if (!isNonEmptyTrimmedString(node.route)) {
|
|
392
|
+
errors.push("graph.nodes entry.conversation-center.route must be a non-empty string");
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function collectNodeKinds(nodes, errors) {
|
|
396
|
+
const nodeKinds = new Map();
|
|
397
|
+
for (const node of nodes) {
|
|
398
|
+
if (!isRecord(node)) {
|
|
399
|
+
errors.push("graph.nodes entry must be an object");
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (!isNonEmptyTrimmedString(node.nodeId)) {
|
|
403
|
+
errors.push("graph.nodes entry must have a non-empty nodeId");
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (nodeKinds.has(node.nodeId)) {
|
|
407
|
+
errors.push(`graph.nodes contains a duplicate nodeId: ${node.nodeId}`);
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (typeof node.kind !== "string" ||
|
|
411
|
+
!CONNECTOR_NODE_KINDS.includes(node.kind)) {
|
|
412
|
+
errors.push("graph.nodes entry has an unknown kind");
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
nodeKinds.set(node.nodeId, node.kind);
|
|
416
|
+
if (node.kind === "files-window") {
|
|
417
|
+
validateFilesWindowNode(node, errors);
|
|
418
|
+
}
|
|
419
|
+
else if (node.kind === "local-knowledge") {
|
|
420
|
+
validateLocalKnowledgeNode(node, errors);
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
validateConversationCenterNode(node, errors);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return nodeKinds;
|
|
427
|
+
}
|
|
428
|
+
function validateEdgeNodeId(field, nodeId, nodeKinds, errors) {
|
|
429
|
+
if (typeof nodeId !== "string" || !nodeKinds.has(nodeId)) {
|
|
430
|
+
errors.push(`graph.edges references unknown ${field}.nodeId`);
|
|
431
|
+
return undefined;
|
|
432
|
+
}
|
|
433
|
+
return nodeId;
|
|
434
|
+
}
|
|
435
|
+
function validateEdgeNodeKind(field, kind, nodeId, nodeKinds, errors) {
|
|
436
|
+
if (typeof kind !== "string" || !CONNECTOR_NODE_KINDS.includes(kind)) {
|
|
437
|
+
errors.push(`graph.edges ${field}.kind must be a known node kind`);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (nodeId !== undefined && nodeKinds.get(nodeId) !== kind) {
|
|
441
|
+
errors.push(`graph.edges ${field}.kind must match the referenced node kind`);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
function validateEdgeRecord(edge, nodeKinds, errors) {
|
|
445
|
+
const from = edge.from;
|
|
446
|
+
const to = edge.to;
|
|
447
|
+
const fromId = validateEdgeNodeId("from", from.nodeId, nodeKinds, errors);
|
|
448
|
+
const toId = validateEdgeNodeId("to", to.nodeId, nodeKinds, errors);
|
|
449
|
+
validateEdgeNodeKind("from", from.kind, fromId, nodeKinds, errors);
|
|
450
|
+
validateEdgeNodeKind("to", to.kind, toId, nodeKinds, errors);
|
|
451
|
+
if (!isFiniteNonNegativeNumber(edge.createdAt)) {
|
|
452
|
+
errors.push("graph.edges entry must have a finite non-negative createdAt");
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function validateEdges(edges, nodeKinds, errors) {
|
|
456
|
+
for (const edge of edges) {
|
|
457
|
+
if (!isRecord(edge) || !isRecord(edge.from) || !isRecord(edge.to)) {
|
|
458
|
+
errors.push("graph.edges entry must have from/to objects");
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
validateEdgeRecord(edge, nodeKinds, errors);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
export function validateConnectorGraphState(input) {
|
|
465
|
+
if (!isRecord(input)) {
|
|
466
|
+
return { ok: false, errors: ["graph must be an object"] };
|
|
467
|
+
}
|
|
468
|
+
const errors = [];
|
|
469
|
+
if (input.schemaVersion !== "1") {
|
|
470
|
+
errors.push('graph.schemaVersion must be the literal "1"');
|
|
471
|
+
}
|
|
472
|
+
if (!Array.isArray(input.nodes)) {
|
|
473
|
+
return { ok: false, errors: [...errors, "graph.nodes must be an array"] };
|
|
474
|
+
}
|
|
475
|
+
if (!Array.isArray(input.edges)) {
|
|
476
|
+
return { ok: false, errors: [...errors, "graph.edges must be an array"] };
|
|
477
|
+
}
|
|
478
|
+
const nodeKinds = collectNodeKinds(input.nodes, errors);
|
|
479
|
+
validateEdges(input.edges, nodeKinds, errors);
|
|
480
|
+
if (!isFiniteNonNegativeNumber(input.updatedAt)) {
|
|
481
|
+
errors.push("graph.updatedAt must be a finite non-negative number");
|
|
482
|
+
}
|
|
483
|
+
if (errors.length > 0) {
|
|
484
|
+
return { ok: false, errors };
|
|
485
|
+
}
|
|
486
|
+
return { ok: true, value: input };
|
|
487
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
export declare const LOCAL_KNOWLEDGE_SCHEMA_VERSION: "1";
|
|
2
|
+
declare const KnowledgeCapsuleIdBrand: unique symbol;
|
|
3
|
+
declare const KnowledgeSourceIdBrand: unique symbol;
|
|
4
|
+
declare const CapsuleSetIdBrand: unique symbol;
|
|
5
|
+
declare const DocumentIdBrand: unique symbol;
|
|
6
|
+
declare const ChunkIdBrand: unique symbol;
|
|
7
|
+
declare const VectorIdBrand: unique symbol;
|
|
8
|
+
export type KnowledgeCapsuleId = string & {
|
|
9
|
+
readonly [KnowledgeCapsuleIdBrand]: true;
|
|
10
|
+
};
|
|
11
|
+
export type KnowledgeSourceId = string & {
|
|
12
|
+
readonly [KnowledgeSourceIdBrand]: true;
|
|
13
|
+
};
|
|
14
|
+
export type CapsuleSetId = string & {
|
|
15
|
+
readonly [CapsuleSetIdBrand]: true;
|
|
16
|
+
};
|
|
17
|
+
export type DocumentId = string & {
|
|
18
|
+
readonly [DocumentIdBrand]: true;
|
|
19
|
+
};
|
|
20
|
+
export type ChunkId = string & {
|
|
21
|
+
readonly [ChunkIdBrand]: true;
|
|
22
|
+
};
|
|
23
|
+
export type VectorId = string & {
|
|
24
|
+
readonly [VectorIdBrand]: true;
|
|
25
|
+
};
|
|
26
|
+
export type EmbeddingVectorMetric = "cosine" | "euclidean" | "dot";
|
|
27
|
+
export declare const EMBEDDING_VECTOR_METRICS: readonly EmbeddingVectorMetric[];
|
|
28
|
+
export interface EmbeddingModelIdentity {
|
|
29
|
+
readonly provider: string;
|
|
30
|
+
readonly modelId: string;
|
|
31
|
+
readonly vectorDimensions: number;
|
|
32
|
+
readonly vectorMetric: EmbeddingVectorMetric;
|
|
33
|
+
readonly modelRevision?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ParserDependencyVersion {
|
|
36
|
+
readonly packageName: string;
|
|
37
|
+
readonly version: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ParserIdentity {
|
|
40
|
+
readonly parserId: string;
|
|
41
|
+
readonly parserVersion: string;
|
|
42
|
+
readonly dependencyVersions?: readonly ParserDependencyVersion[];
|
|
43
|
+
}
|
|
44
|
+
export type KnowledgeSourceScope = {
|
|
45
|
+
readonly kind: "folder";
|
|
46
|
+
readonly rootPath: string;
|
|
47
|
+
readonly recursive: boolean;
|
|
48
|
+
readonly includeGlobs?: readonly string[];
|
|
49
|
+
readonly excludeGlobs?: readonly string[];
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: "repository";
|
|
52
|
+
readonly repositoryRoot: string;
|
|
53
|
+
readonly includeGlobs?: readonly string[];
|
|
54
|
+
readonly excludeGlobs?: readonly string[];
|
|
55
|
+
} | {
|
|
56
|
+
readonly kind: "files";
|
|
57
|
+
readonly rootPath: string;
|
|
58
|
+
readonly files: readonly string[];
|
|
59
|
+
};
|
|
60
|
+
export type KnowledgeSourceScopeKind = KnowledgeSourceScope["kind"];
|
|
61
|
+
export declare const KNOWLEDGE_SOURCE_SCOPE_KINDS: readonly KnowledgeSourceScopeKind[];
|
|
62
|
+
export interface KnowledgeSource {
|
|
63
|
+
readonly id: KnowledgeSourceId;
|
|
64
|
+
readonly displayName: string;
|
|
65
|
+
readonly description?: string;
|
|
66
|
+
readonly tags: readonly string[];
|
|
67
|
+
readonly scope: KnowledgeSourceScope;
|
|
68
|
+
readonly createdAt: number;
|
|
69
|
+
readonly updatedAt: number;
|
|
70
|
+
}
|
|
71
|
+
export type CapsuleLifecycleState = "draft" | "indexing" | "ready" | "stale" | "deleting" | "error";
|
|
72
|
+
export declare const CAPSULE_LIFECYCLE_STATES: readonly CapsuleLifecycleState[];
|
|
73
|
+
export type CapsuleRetrievalEffort = "minimal" | "default" | "deep";
|
|
74
|
+
export declare const CAPSULE_RETRIEVAL_EFFORTS: readonly CapsuleRetrievalEffort[];
|
|
75
|
+
export type CapsuleOutputMode = "answers" | "snippets" | "raw";
|
|
76
|
+
export declare const CAPSULE_OUTPUT_MODES: readonly CapsuleOutputMode[];
|
|
77
|
+
export type CapsuleAnswerGroundingPolicy = "require-citations" | "require-citations-or-state-no-evidence" | "best-effort";
|
|
78
|
+
export declare const CAPSULE_ANSWER_GROUNDING_POLICIES: readonly CapsuleAnswerGroundingPolicy[];
|
|
79
|
+
export interface KnowledgeCapsule {
|
|
80
|
+
readonly id: KnowledgeCapsuleId;
|
|
81
|
+
readonly displayName: string;
|
|
82
|
+
readonly description?: string;
|
|
83
|
+
readonly tags: readonly string[];
|
|
84
|
+
readonly sourceIds: readonly KnowledgeSourceId[];
|
|
85
|
+
readonly sourceRoutingInstructions?: string;
|
|
86
|
+
readonly alwaysQuery?: boolean;
|
|
87
|
+
readonly retrievalEffort: CapsuleRetrievalEffort;
|
|
88
|
+
readonly outputMode: CapsuleOutputMode;
|
|
89
|
+
readonly answerGroundingPolicy: CapsuleAnswerGroundingPolicy;
|
|
90
|
+
readonly embeddingModelIdentity: EmbeddingModelIdentity;
|
|
91
|
+
readonly lifecycleState: CapsuleLifecycleState;
|
|
92
|
+
readonly storageReference: string;
|
|
93
|
+
readonly metadata?: Readonly<Record<string, string>>;
|
|
94
|
+
readonly createdAt: number;
|
|
95
|
+
readonly updatedAt: number;
|
|
96
|
+
}
|
|
97
|
+
export interface CapsuleSet {
|
|
98
|
+
readonly id: CapsuleSetId;
|
|
99
|
+
readonly displayName: string;
|
|
100
|
+
readonly description?: string;
|
|
101
|
+
readonly tags: readonly string[];
|
|
102
|
+
readonly capsuleIds: readonly KnowledgeCapsuleId[];
|
|
103
|
+
readonly composedAt: number;
|
|
104
|
+
}
|
|
105
|
+
export declare const CAPSULE_METADATA_MAX_KEYS: 16;
|
|
106
|
+
export declare const CAPSULE_METADATA_KEY_MAX_CHARS: 128;
|
|
107
|
+
export declare const CAPSULE_METADATA_VALUE_MAX_CHARS: 1024;
|
|
108
|
+
export declare const CAPSULE_SET_MAX_MEMBERS: 16;
|
|
109
|
+
export interface UpdateCapsulePatch {
|
|
110
|
+
readonly displayName?: string;
|
|
111
|
+
readonly description?: string;
|
|
112
|
+
readonly metadata?: Readonly<Record<string, string>>;
|
|
113
|
+
}
|
|
114
|
+
export interface CreateCapsuleSetBody {
|
|
115
|
+
readonly displayName: string;
|
|
116
|
+
readonly description?: string;
|
|
117
|
+
readonly capsuleIds: readonly string[];
|
|
118
|
+
}
|
|
119
|
+
export type ConnectorNodeKind = "files-window" | "local-knowledge" | "conversation-center";
|
|
120
|
+
export declare const CONNECTOR_NODE_KINDS: readonly ConnectorNodeKind[];
|
|
121
|
+
export type LocalKnowledgeNodeTarget = {
|
|
122
|
+
readonly kind: "capsule";
|
|
123
|
+
readonly capsuleId: KnowledgeCapsuleId;
|
|
124
|
+
} | {
|
|
125
|
+
readonly kind: "capsule-set";
|
|
126
|
+
readonly capsuleSetId: CapsuleSetId;
|
|
127
|
+
};
|
|
128
|
+
export type ConnectorNode = {
|
|
129
|
+
readonly kind: "files-window";
|
|
130
|
+
readonly nodeId: string;
|
|
131
|
+
readonly scope: KnowledgeSourceScope;
|
|
132
|
+
} | {
|
|
133
|
+
readonly kind: "local-knowledge";
|
|
134
|
+
readonly nodeId: string;
|
|
135
|
+
readonly target: LocalKnowledgeNodeTarget;
|
|
136
|
+
} | {
|
|
137
|
+
readonly kind: "conversation-center";
|
|
138
|
+
readonly nodeId: string;
|
|
139
|
+
readonly conversationId: string;
|
|
140
|
+
readonly route: string;
|
|
141
|
+
};
|
|
142
|
+
export interface ConnectorNodeRef {
|
|
143
|
+
readonly nodeId: string;
|
|
144
|
+
readonly kind: ConnectorNodeKind;
|
|
145
|
+
}
|
|
146
|
+
export interface ConnectorEdge {
|
|
147
|
+
readonly from: ConnectorNodeRef;
|
|
148
|
+
readonly to: ConnectorNodeRef;
|
|
149
|
+
readonly createdAt: number;
|
|
150
|
+
}
|
|
151
|
+
export interface ConnectorGraphState {
|
|
152
|
+
readonly schemaVersion: typeof LOCAL_KNOWLEDGE_SCHEMA_VERSION;
|
|
153
|
+
readonly nodes: readonly ConnectorNode[];
|
|
154
|
+
readonly edges: readonly ConnectorEdge[];
|
|
155
|
+
readonly updatedAt: number;
|
|
156
|
+
}
|
|
157
|
+
export {};
|
|
158
|
+
//# sourceMappingURL=local-knowledge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-knowledge.d.ts","sourceRoot":"","sources":["../src/local-knowledge.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,8BAA8B,EAAG,GAAY,CAAC;AAO3D,OAAO,CAAC,MAAM,uBAAuB,EAAE,OAAO,MAAM,CAAC;AACrD,OAAO,CAAC,MAAM,sBAAsB,EAAE,OAAO,MAAM,CAAC;AACpD,OAAO,CAAC,MAAM,iBAAiB,EAAE,OAAO,MAAM,CAAC;AAC/C,OAAO,CAAC,MAAM,eAAe,EAAE,OAAO,MAAM,CAAC;AAC7C,OAAO,CAAC,MAAM,YAAY,EAAE,OAAO,MAAM,CAAC;AAC1C,OAAO,CAAC,MAAM,aAAa,EAAE,OAAO,MAAM,CAAC;AAE3C,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,uBAAuB,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AACvF,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,sBAAsB,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AACrF,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,iBAAiB,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAC3E,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAAE,QA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