@hasna/knowledge 0.2.26 → 0.2.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +61 -0
  2. package/bin/open-knowledge-mcp.js +85 -9
  3. package/bin/open-knowledge.js +86 -86
  4. package/dist/agent.d.ts +35 -0
  5. package/dist/artifact-store.d.ts +63 -0
  6. package/dist/auth.d.ts +35 -0
  7. package/dist/embeddings.d.ts +77 -0
  8. package/dist/index.d.ts +20 -0
  9. package/dist/index.js +5709 -0
  10. package/dist/knowledge-db.d.ts +27 -0
  11. package/dist/manifest-ingest.d.ts +35 -0
  12. package/dist/outbox-consume.d.ts +25 -0
  13. package/dist/provenance.d.ts +50 -0
  14. package/dist/providers.d.ts +89 -0
  15. package/dist/reindex.d.ts +37 -0
  16. package/dist/remote-client.d.ts +108 -0
  17. package/dist/retrieval.d.ts +71 -0
  18. package/dist/safety.d.ts +70 -0
  19. package/dist/sdk.d.ts +72 -0
  20. package/dist/search.d.ts +65 -0
  21. package/dist/service.d.ts +117 -0
  22. package/dist/source-ingest.d.ts +18 -0
  23. package/dist/source-ref.d.ts +30 -0
  24. package/dist/source-resolver.d.ts +92 -0
  25. package/dist/storage-contract.d.ts +106 -0
  26. package/dist/web-search.d.ts +40 -0
  27. package/dist/wiki-compiler.d.ts +67 -0
  28. package/dist/wiki-layout.d.ts +23 -0
  29. package/dist/workspace.d.ts +111 -0
  30. package/docs/architecture/ai-native-knowledge-base.md +24 -0
  31. package/docs/architecture/hosted-wrapper-responsibilities.md +8 -0
  32. package/docs/canonical-secrets-bootstrap-2026-06-08.md +127 -0
  33. package/package.json +15 -7
  34. package/src/agent.ts +0 -367
  35. package/src/artifact-store.ts +0 -184
  36. package/src/auth.ts +0 -123
  37. package/src/cli.ts +0 -1181
  38. package/src/embeddings.ts +0 -516
  39. package/src/knowledge-db.ts +0 -354
  40. package/src/manifest-ingest.ts +0 -515
  41. package/src/mcp-http.js +0 -110
  42. package/src/mcp.js +0 -1503
  43. package/src/outbox-consume.ts +0 -463
  44. package/src/provenance.ts +0 -93
  45. package/src/providers.ts +0 -308
  46. package/src/reindex.ts +0 -260
  47. package/src/remote-client.ts +0 -268
  48. package/src/retrieval.ts +0 -326
  49. package/src/safety.ts +0 -265
  50. package/src/schema.js +0 -25
  51. package/src/search.ts +0 -510
  52. package/src/service.ts +0 -432
  53. package/src/source-ingest.ts +0 -268
  54. package/src/source-ref.ts +0 -104
  55. package/src/source-resolver.ts +0 -436
  56. package/src/storage-contract.ts +0 -293
  57. package/src/store.ts +0 -113
  58. package/src/web-search.ts +0 -330
  59. package/src/wiki-compiler.ts +0 -711
  60. package/src/wiki-layout.ts +0 -251
  61. package/src/workspace.ts +0 -213
@@ -0,0 +1,27 @@
1
+ import { Database } from 'bun:sqlite';
2
+ export declare const CURRENT_SCHEMA_VERSION = 5;
3
+ export interface KnowledgeDbStats {
4
+ schema_version: number;
5
+ sources: number;
6
+ source_revisions: number;
7
+ chunks: number;
8
+ wiki_pages: number;
9
+ citations: number;
10
+ indexes: number;
11
+ runs: number;
12
+ run_events: number;
13
+ redaction_findings: number;
14
+ audit_events: number;
15
+ approval_gates: number;
16
+ storage_objects: number;
17
+ embeddings: number;
18
+ vector_entries: number;
19
+ reindex_queue: number;
20
+ }
21
+ export declare function openKnowledgeDb(path: string): Database;
22
+ export declare function migrateKnowledgeDb(path: string): {
23
+ path: string;
24
+ schema_version: number;
25
+ };
26
+ export declare function getSchemaVersion(db: Database): number;
27
+ export declare function getKnowledgeDbStats(path: string): KnowledgeDbStats;
@@ -0,0 +1,35 @@
1
+ import type { KnowledgeConfig } from './workspace';
2
+ import { type SafetyPolicy } from './safety';
3
+ export interface ManifestIngestOptions {
4
+ dbPath: string;
5
+ input: string;
6
+ config?: KnowledgeConfig;
7
+ safetyPolicy?: SafetyPolicy;
8
+ now?: Date;
9
+ maxChunkChars?: number;
10
+ chunkOverlapChars?: number;
11
+ }
12
+ export interface ManifestItemsIngestOptions {
13
+ dbPath: string;
14
+ items: ManifestObject[];
15
+ sourceLabel: string;
16
+ readAction?: string;
17
+ safetyPolicy?: SafetyPolicy;
18
+ now?: Date;
19
+ maxChunkChars?: number;
20
+ chunkOverlapChars?: number;
21
+ }
22
+ export interface ManifestIngestResult {
23
+ path: string;
24
+ db_path: string;
25
+ items_seen: number;
26
+ sources_upserted: number;
27
+ revisions_upserted: number;
28
+ chunks_inserted: number;
29
+ chunks_deleted: number;
30
+ redactions: number;
31
+ skipped: number;
32
+ }
33
+ export type ManifestObject = Record<string, unknown>;
34
+ export declare function ingestOpenFilesManifest(options: ManifestIngestOptions): Promise<ManifestIngestResult>;
35
+ export declare function ingestOpenFilesManifestItems(options: ManifestItemsIngestOptions): Promise<ManifestIngestResult>;
@@ -0,0 +1,25 @@
1
+ import type { KnowledgeConfig } from './workspace';
2
+ import { type SafetyPolicy } from './safety';
3
+ export interface OutboxConsumeOptions {
4
+ dbPath: string;
5
+ input: string;
6
+ config?: KnowledgeConfig;
7
+ safetyPolicy?: SafetyPolicy;
8
+ now?: Date;
9
+ }
10
+ export interface OutboxConsumeResult {
11
+ path: string;
12
+ db_path: string;
13
+ run_id: string;
14
+ events_seen: number;
15
+ sources_touched: number;
16
+ revisions_touched: number;
17
+ chunks_deleted: number;
18
+ embeddings_deleted: number;
19
+ stale_revisions: number;
20
+ deleted_sources: number;
21
+ moved_sources: number;
22
+ permission_updates: number;
23
+ vector_entries_deleted: number;
24
+ }
25
+ export declare function consumeOpenFilesOutbox(options: OutboxConsumeOptions): Promise<OutboxConsumeResult>;
@@ -0,0 +1,50 @@
1
+ export interface KnowledgeProvenance {
2
+ source_owner: 'open-files';
3
+ source_ref: string | null;
4
+ source_uri: string | null;
5
+ source_kind: string | null;
6
+ source_revision_id: string | null;
7
+ revision: string | null;
8
+ hash: string | null;
9
+ chunk_id: string | null;
10
+ start_offset: number | null;
11
+ end_offset: number | null;
12
+ status: string | null;
13
+ read_only: true;
14
+ citation_required: boolean;
15
+ resolver: string | null;
16
+ stale: boolean;
17
+ }
18
+ export interface GeneratedArtifactProvenance {
19
+ source_owner: 'open-files';
20
+ generated_from: string;
21
+ artifact_key: string;
22
+ source_refs: string[];
23
+ read_only_sources: true;
24
+ citation_required: boolean;
25
+ raw_source_bytes_stored_in_open_knowledge: false;
26
+ }
27
+ export interface SourceProvenanceInput {
28
+ source_ref?: string | null;
29
+ source_uri?: string | null;
30
+ source_kind?: string | null;
31
+ source_revision_id?: string | null;
32
+ revision?: string | null;
33
+ hash?: string | null;
34
+ chunk_id?: string | null;
35
+ start_offset?: number | null;
36
+ end_offset?: number | null;
37
+ status?: string | null;
38
+ resolver?: string | null;
39
+ }
40
+ export declare function isStaleStatus(status: string | null | undefined): boolean;
41
+ export declare function sourceProvenance(input: SourceProvenanceInput): KnowledgeProvenance;
42
+ export declare function generatedArtifactProvenance(input: {
43
+ generated_from: string;
44
+ artifact_key: string;
45
+ source_refs?: string[];
46
+ citation_required?: boolean;
47
+ }): GeneratedArtifactProvenance;
48
+ export declare function withProvenance<T extends Record<string, unknown>>(metadata: T, provenance: KnowledgeProvenance | GeneratedArtifactProvenance): T & {
49
+ provenance: KnowledgeProvenance | GeneratedArtifactProvenance;
50
+ };
@@ -0,0 +1,89 @@
1
+ import type { Database } from 'bun:sqlite';
2
+ import type { KnowledgeConfig } from './workspace';
3
+ export type AiProviderId = 'openai' | 'anthropic' | 'deepseek';
4
+ export interface AiProviderSettings {
5
+ api_key_env: string;
6
+ base_url?: string;
7
+ default_model: string;
8
+ }
9
+ export interface AiProvidersConfig {
10
+ default_model?: string;
11
+ aliases?: Record<string, string>;
12
+ openai?: Partial<AiProviderSettings>;
13
+ anthropic?: Partial<AiProviderSettings>;
14
+ deepseek?: Partial<AiProviderSettings>;
15
+ }
16
+ export interface ModelCapabilities {
17
+ text_generation: boolean;
18
+ structured_output: boolean;
19
+ tool_usage: boolean;
20
+ tool_streaming: boolean;
21
+ image_input: boolean;
22
+ native_web_search: boolean;
23
+ reasoning: boolean;
24
+ embeddings: boolean;
25
+ }
26
+ export interface ModelRegistryEntry {
27
+ alias: string;
28
+ model_ref: string;
29
+ provider: AiProviderId;
30
+ model: string;
31
+ default: boolean;
32
+ capabilities: ModelCapabilities;
33
+ }
34
+ export interface ProviderCredentialStatus {
35
+ provider: AiProviderId;
36
+ api_key_env: string;
37
+ configured: boolean;
38
+ source: 'env' | 'missing';
39
+ base_url: string | null;
40
+ default_model: string;
41
+ }
42
+ export interface ProviderStatusResult {
43
+ default_model: string;
44
+ providers: ProviderCredentialStatus[];
45
+ models: ModelRegistryEntry[];
46
+ }
47
+ export interface NormalizedProviderUsage {
48
+ provider: string;
49
+ model: string;
50
+ input_tokens: number;
51
+ output_tokens: number;
52
+ cost_usd: number;
53
+ metadata: Record<string, unknown>;
54
+ }
55
+ type ProviderFactory = (settings: {
56
+ apiKey: string;
57
+ baseURL?: string;
58
+ }) => unknown;
59
+ export interface AiProviderRuntimeOptions {
60
+ config?: KnowledgeConfig;
61
+ env?: Record<string, string | undefined>;
62
+ factories?: Partial<Record<AiProviderId, ProviderFactory>>;
63
+ }
64
+ export declare function providerSettings(config: KnowledgeConfig | undefined, provider: AiProviderId): AiProviderSettings;
65
+ export declare function modelAliases(config?: KnowledgeConfig): Record<string, string>;
66
+ export declare function parseModelRef(modelRef: string): {
67
+ provider: AiProviderId;
68
+ model: string;
69
+ };
70
+ export declare function resolveModelRef(aliasOrRef: string, config?: KnowledgeConfig): string;
71
+ export declare function listModelRegistry(config?: KnowledgeConfig): ModelRegistryEntry[];
72
+ export declare function providerCredentialStatus(config: KnowledgeConfig | undefined, env?: Record<string, string | undefined>): ProviderCredentialStatus[];
73
+ export declare function providerStatus(config?: KnowledgeConfig, env?: Record<string, string | undefined>): ProviderStatusResult;
74
+ export declare function assertProviderCredentials(provider: AiProviderId, config?: KnowledgeConfig, env?: Record<string, string | undefined>): ProviderCredentialStatus;
75
+ export declare function createAiSdkProviderRegistry(options?: AiProviderRuntimeOptions): Promise<import("ai").ProviderRegistryProvider<never, ":">>;
76
+ export declare function languageModelFor(aliasOrRef: string, options?: AiProviderRuntimeOptions): Promise<import("@ai-sdk/provider").LanguageModelV3>;
77
+ export declare function normalizeAiSdkUsage(input: {
78
+ provider: string;
79
+ model: string;
80
+ usage?: Record<string, unknown> | null;
81
+ providerMetadata?: Record<string, unknown> | null;
82
+ costUsd?: number;
83
+ }): NormalizedProviderUsage;
84
+ export declare function recordProviderUsage(db: Database, input: NormalizedProviderUsage & {
85
+ run_id?: string | null;
86
+ created_at?: string;
87
+ }): string;
88
+ export declare function createDeterministicFakeProvider(provider: AiProviderId): ProviderFactory;
89
+ export {};
@@ -0,0 +1,37 @@
1
+ import { indexKnowledgeEmbeddings, type EmbeddingRuntimeOptions } from './embeddings';
2
+ import type { KnowledgeConfig } from './workspace';
3
+ export interface ReindexRuntimeOptions extends EmbeddingRuntimeOptions {
4
+ dbPath: string;
5
+ config?: KnowledgeConfig;
6
+ now?: Date;
7
+ }
8
+ export interface ReindexHealthResult {
9
+ schema_version: number;
10
+ chunks: number;
11
+ vector_entries: number;
12
+ missing_embeddings: number;
13
+ queued: Record<string, number>;
14
+ stale_revisions: number;
15
+ }
16
+ export interface ReindexEnqueueResult {
17
+ enqueued: number;
18
+ already_queued: number;
19
+ reason: string;
20
+ }
21
+ export interface ReindexEmbeddingsResult {
22
+ run_id: string;
23
+ full: boolean;
24
+ deleted_embeddings: number;
25
+ deleted_vector_entries: number;
26
+ queued: ReindexEnqueueResult;
27
+ indexed: Awaited<ReturnType<typeof indexKnowledgeEmbeddings>>;
28
+ completed_queue_items: number;
29
+ }
30
+ export declare function reindexHealth(options: ReindexRuntimeOptions): ReindexHealthResult;
31
+ export declare function enqueueMissingEmbeddings(options: ReindexRuntimeOptions & {
32
+ reason?: string;
33
+ }): ReindexEnqueueResult;
34
+ export declare function refreshEmbeddingIndex(options: ReindexRuntimeOptions & {
35
+ full?: boolean;
36
+ limit?: number;
37
+ }): Promise<ReindexEmbeddingsResult>;
@@ -0,0 +1,108 @@
1
+ import type { KnowledgeConfig } from './workspace';
2
+ export declare const REMOTE_KNOWLEDGE_CONTRACT_VERSION: 1;
3
+ export type RemoteKnowledgeRunStatus = 'queued' | 'running' | 'completed' | 'failed' | 'canceled';
4
+ export interface RemoteKnowledgeSourceContract {
5
+ owner: 'open-files';
6
+ preferred_ref: 'open-files';
7
+ allowed_schemes: string[];
8
+ raw_source_bytes_stored_in_open_knowledge: false;
9
+ }
10
+ export interface RemoteKnowledgeArtifactContract {
11
+ storage_type: 'local' | 's3' | 'managed';
12
+ uri_prefix: string | null;
13
+ generated_only: true;
14
+ }
15
+ export interface RemoteKnowledgeRegistryContract {
16
+ contract_version: typeof REMOTE_KNOWLEDGE_CONTRACT_VERSION;
17
+ service: 'open-knowledge';
18
+ mode: 'local' | 'hosted';
19
+ capabilities: string[];
20
+ endpoints: {
21
+ registry: string;
22
+ search: string;
23
+ ask: string;
24
+ build: string;
25
+ sync: string;
26
+ run_status: string;
27
+ run_logs: string;
28
+ run_artifacts: string;
29
+ };
30
+ source_contract: RemoteKnowledgeSourceContract;
31
+ artifact_contract: RemoteKnowledgeArtifactContract;
32
+ }
33
+ export interface RemoteKnowledgeRunContract {
34
+ contract_version: typeof REMOTE_KNOWLEDGE_CONTRACT_VERSION;
35
+ id?: string;
36
+ type?: 'search' | 'ask' | 'build' | 'sync' | 'artifact' | 'status';
37
+ status?: RemoteKnowledgeRunStatus | string;
38
+ query?: string;
39
+ prompt?: string;
40
+ output_preview?: unknown;
41
+ citations?: unknown[];
42
+ artifacts?: unknown[];
43
+ usage?: Record<string, unknown>;
44
+ created_at?: string;
45
+ started_at?: string;
46
+ completed_at?: string;
47
+ duration_ms?: number;
48
+ error_code?: string;
49
+ error_message?: string;
50
+ error?: string;
51
+ details?: unknown;
52
+ }
53
+ export interface RemoteKnowledgeSearchRequest {
54
+ query: string;
55
+ limit?: number;
56
+ semantic?: boolean;
57
+ source_refs?: string[];
58
+ }
59
+ export interface RemoteKnowledgePromptRequest extends RemoteKnowledgeSearchRequest {
60
+ prompt: string;
61
+ generate?: boolean;
62
+ approve_write?: boolean;
63
+ }
64
+ export interface RemoteKnowledgeSyncRequest {
65
+ source_refs?: string[];
66
+ artifact_prefix?: string;
67
+ mode?: 'pull' | 'push' | 'both';
68
+ }
69
+ export interface RemoteKnowledgeLogEntry {
70
+ id?: string;
71
+ run_id?: string;
72
+ level?: string;
73
+ event?: string;
74
+ metadata?: Record<string, unknown>;
75
+ created_at?: string;
76
+ }
77
+ export interface RemoteKnowledgeArtifact {
78
+ id?: string;
79
+ uri?: string;
80
+ key?: string;
81
+ kind?: string;
82
+ content_type?: string;
83
+ hash?: string;
84
+ size_bytes?: number;
85
+ metadata?: Record<string, unknown>;
86
+ }
87
+ export declare function normalizeRemoteKnowledgeRunContract(payload: unknown, fallback?: Partial<RemoteKnowledgeRunContract>): RemoteKnowledgeRunContract;
88
+ export declare function knowledgeRegistryContract(input: {
89
+ mode: 'local' | 'hosted';
90
+ sourceSchemes: string[];
91
+ storageType: 'local' | 's3' | 'managed';
92
+ artifactUriPrefix: string | null;
93
+ }): RemoteKnowledgeRegistryContract;
94
+ export declare class RemoteKnowledgeClient {
95
+ private readonly apiKey;
96
+ private readonly apiUrl;
97
+ constructor(apiKey: string, apiUrl: string);
98
+ static fromConfig(config?: KnowledgeConfig, env?: Record<string, string | undefined>): RemoteKnowledgeClient | null;
99
+ private request;
100
+ registry(): Promise<RemoteKnowledgeRegistryContract>;
101
+ search(request: RemoteKnowledgeSearchRequest): Promise<RemoteKnowledgeRunContract>;
102
+ ask(request: RemoteKnowledgePromptRequest): Promise<RemoteKnowledgeRunContract>;
103
+ build(request: RemoteKnowledgePromptRequest): Promise<RemoteKnowledgeRunContract>;
104
+ sync(request?: RemoteKnowledgeSyncRequest): Promise<RemoteKnowledgeRunContract>;
105
+ runStatus(runId: string): Promise<RemoteKnowledgeRunContract | null>;
106
+ runLogs(runId: string): Promise<RemoteKnowledgeLogEntry[]>;
107
+ runArtifacts(runId: string): Promise<RemoteKnowledgeArtifact[]>;
108
+ }
@@ -0,0 +1,71 @@
1
+ import { type HybridSearchEntry, type HybridSearchOptions, type HybridSearchResult, type SearchProvenance } from './search';
2
+ export interface RetrievalOptions extends HybridSearchOptions {
3
+ contextChars?: number;
4
+ }
5
+ export interface RerankedSearchEntry extends HybridSearchEntry {
6
+ rerank: {
7
+ base_score: number;
8
+ final_score: number;
9
+ exact_score: number;
10
+ citation_score: number;
11
+ freshness_score: number;
12
+ authority_score: number;
13
+ };
14
+ }
15
+ export interface RetrievalCitation {
16
+ id: string;
17
+ result_id: string;
18
+ kind: HybridSearchEntry['kind'];
19
+ source_uri: string | null;
20
+ source_ref: string | null;
21
+ artifact_uri: string | null;
22
+ artifact_path: string | null;
23
+ revision: string | null;
24
+ hash: string | null;
25
+ chunk_id: string | null;
26
+ start_offset: number | null;
27
+ end_offset: number | null;
28
+ quote: string | null;
29
+ provenance: SearchProvenance | null;
30
+ }
31
+ export interface RetrievalExcerpt {
32
+ id: string;
33
+ result_id: string;
34
+ citation_id: string | null;
35
+ kind: HybridSearchEntry['kind'];
36
+ text: string;
37
+ score: number;
38
+ }
39
+ export interface RetrievalGraphEvidence {
40
+ citations: Array<{
41
+ id: string;
42
+ chunk_id: string | null;
43
+ wiki_page_id: string | null;
44
+ source_uri: string;
45
+ quote: string | null;
46
+ start_offset: number | null;
47
+ end_offset: number | null;
48
+ }>;
49
+ backlinks: Array<{
50
+ from_page_id: string;
51
+ to_page_id: string;
52
+ label: string | null;
53
+ }>;
54
+ }
55
+ export interface KnowledgeContextPack {
56
+ query: string;
57
+ normalized_query: string;
58
+ created_at: string;
59
+ mode: HybridSearchResult['mode'];
60
+ warnings: string[];
61
+ search_counts: HybridSearchResult['counts'];
62
+ results: RerankedSearchEntry[];
63
+ citations: RetrievalCitation[];
64
+ excerpts: RetrievalExcerpt[];
65
+ graph: RetrievalGraphEvidence;
66
+ notes: {
67
+ permissions: string[];
68
+ freshness: string[];
69
+ };
70
+ }
71
+ export declare function retrieveKnowledgeContext(options: RetrievalOptions): Promise<KnowledgeContextPack>;
@@ -0,0 +1,70 @@
1
+ import type { Database } from 'bun:sqlite';
2
+ import type { KnowledgeConfig, KnowledgeWorkspace } from './workspace';
3
+ export type SafetyDecision = 'allow' | 'deny' | 'requires_approval';
4
+ export interface SafetyPolicy {
5
+ mode: 'local' | 'hosted';
6
+ allowWriteRoots: string[];
7
+ readOnlySourceAccess: boolean;
8
+ network: {
9
+ webSearchEnabled: boolean;
10
+ s3ReadsEnabled: boolean;
11
+ allowedS3Buckets: string[];
12
+ };
13
+ redaction: {
14
+ enabled: boolean;
15
+ };
16
+ approvals: {
17
+ generatedWritesRequireApproval: boolean;
18
+ };
19
+ }
20
+ export interface SafetyAuditInput {
21
+ event_type: string;
22
+ action: string;
23
+ target_uri?: string | null;
24
+ decision: SafetyDecision | 'redacted' | 'info';
25
+ metadata?: Record<string, unknown>;
26
+ created_at?: string;
27
+ }
28
+ export interface RedactionFinding {
29
+ type: string;
30
+ severity: 'low' | 'medium' | 'high';
31
+ start: number;
32
+ end: number;
33
+ }
34
+ export interface RedactionResult {
35
+ text: string;
36
+ findings: RedactionFinding[];
37
+ }
38
+ export declare function resolveSafetyPolicy(config: KnowledgeConfig, workspace: KnowledgeWorkspace): SafetyPolicy;
39
+ export declare function assertWriteAllowed(targetPath: string, policy: SafetyPolicy): void;
40
+ export declare function assertS3ReadAllowed(uri: string, policy: SafetyPolicy): void;
41
+ export declare function assertWebSearchAllowed(policy: SafetyPolicy): void;
42
+ export declare function redactSecrets(text: string, policy?: Pick<SafetyPolicy, 'redaction'>): RedactionResult;
43
+ export declare function auditId(input: SafetyAuditInput): string;
44
+ export declare function recordAuditEvent(db: Database, input: SafetyAuditInput): string;
45
+ export declare function recordRedactionFindings(db: Database, input: {
46
+ source_uri?: string | null;
47
+ run_id?: string | null;
48
+ findings: RedactionFinding[];
49
+ metadata?: Record<string, unknown>;
50
+ created_at?: string;
51
+ }): number;
52
+ export declare function createApprovalGate(db: Database, input: {
53
+ action: string;
54
+ target_uri?: string | null;
55
+ reason?: string | null;
56
+ approved_by?: string | null;
57
+ metadata?: Record<string, unknown>;
58
+ created_at?: string;
59
+ }): {
60
+ id: string;
61
+ status: 'approved';
62
+ };
63
+ export declare function hasApproval(db: Database, action: string, targetUri?: string | null): boolean;
64
+ export declare function approvalStatus(db: Database, policy: SafetyPolicy, action: string, targetUri?: string | null): {
65
+ action: string;
66
+ target_uri: string | null;
67
+ approval_required: boolean;
68
+ approved: boolean;
69
+ decision: SafetyDecision;
70
+ };
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { KnowledgeService, type KnowledgeServiceOptions } from './service.js';
2
+ export type KnowledgeClientOptions = KnowledgeServiceOptions;
3
+ export type KnowledgeSetupOptions = Parameters<KnowledgeService['setup']>[0];
4
+ export type KnowledgeAuthInput = Parameters<KnowledgeService['saveAuth']>[0];
5
+ export type KnowledgeAskOptions = Omit<Parameters<KnowledgeService['runPrompt']>[0], 'prompt'>;
6
+ export type KnowledgeSearchOptions = Parameters<KnowledgeService['search']>[0];
7
+ export type KnowledgeContextOptions = Parameters<KnowledgeService['retrieveContext']>[0];
8
+ export type KnowledgeWebSearchOptions = Parameters<KnowledgeService['webSearch']>[0];
9
+ export interface KnowledgeClient {
10
+ /**
11
+ * Escape hatch for advanced integrations. Prefer the grouped SDK methods for
12
+ * app-facing code; this service may expose lower-level operations over time.
13
+ */
14
+ readonly unstable_service: KnowledgeService;
15
+ readonly paths: () => ReturnType<KnowledgeService['paths']>;
16
+ readonly setup: (options?: KnowledgeSetupOptions) => ReturnType<KnowledgeService['setup']>;
17
+ readonly auth: {
18
+ readonly status: (env?: Record<string, string | undefined>) => ReturnType<KnowledgeService['authStatus']>;
19
+ readonly login: (input: KnowledgeAuthInput, env?: Record<string, string | undefined>) => ReturnType<KnowledgeService['saveAuth']>;
20
+ readonly logout: (env?: Record<string, string | undefined>) => ReturnType<KnowledgeService['clearAuth']>;
21
+ };
22
+ readonly remote: {
23
+ readonly contract: () => ReturnType<KnowledgeService['remoteContract']>;
24
+ readonly client: (env?: Record<string, string | undefined>) => ReturnType<KnowledgeService['remoteClient']>;
25
+ };
26
+ readonly storage: {
27
+ readonly status: () => ReturnType<KnowledgeService['storageContract']>;
28
+ readonly validate: () => ReturnType<KnowledgeService['validateStorage']>;
29
+ readonly artifactStore: () => ReturnType<KnowledgeService['artifactStore']>;
30
+ };
31
+ readonly db: {
32
+ readonly init: () => ReturnType<KnowledgeService['initDb']>;
33
+ readonly stats: () => ReturnType<KnowledgeService['dbStats']>;
34
+ };
35
+ readonly wiki: {
36
+ readonly init: () => ReturnType<KnowledgeService['initWiki']>;
37
+ readonly compile: (options?: Parameters<KnowledgeService['compileWiki']>[0]) => ReturnType<KnowledgeService['compileWiki']>;
38
+ readonly fileAnswer: (options: Parameters<KnowledgeService['fileAnswer']>[0]) => ReturnType<KnowledgeService['fileAnswer']>;
39
+ readonly lint: () => ReturnType<KnowledgeService['lintWiki']>;
40
+ };
41
+ readonly ingest: {
42
+ readonly manifest: (input: string) => ReturnType<KnowledgeService['ingestManifest']>;
43
+ readonly source: (sourceRef: string, purpose?: string) => ReturnType<KnowledgeService['ingestSource']>;
44
+ };
45
+ readonly sources: {
46
+ readonly resolve: (sourceRef: string, options?: Parameters<KnowledgeService['resolveSource']>[1]) => ReturnType<KnowledgeService['resolveSource']>;
47
+ readonly consumeOutbox: (input: string) => ReturnType<KnowledgeService['consumeOutbox']>;
48
+ };
49
+ readonly reindex: {
50
+ readonly health: (options?: Parameters<KnowledgeService['reindexHealth']>[0]) => ReturnType<KnowledgeService['reindexHealth']>;
51
+ readonly enqueue: (options?: Parameters<KnowledgeService['enqueueReindex']>[0]) => ReturnType<KnowledgeService['enqueueReindex']>;
52
+ readonly refreshEmbeddings: (options?: Parameters<KnowledgeService['refreshEmbeddings']>[0]) => ReturnType<KnowledgeService['refreshEmbeddings']>;
53
+ };
54
+ readonly providers: {
55
+ readonly status: (env?: Record<string, string | undefined>) => ReturnType<KnowledgeService['providerStatus']>;
56
+ readonly models: () => ReturnType<KnowledgeService['modelRegistry']>;
57
+ };
58
+ readonly embeddings: {
59
+ readonly status: () => ReturnType<KnowledgeService['embeddingStatus']>;
60
+ readonly index: (options?: Parameters<KnowledgeService['indexEmbeddings']>[0]) => ReturnType<KnowledgeService['indexEmbeddings']>;
61
+ readonly search: (options: Parameters<KnowledgeService['semanticSearch']>[0]) => ReturnType<KnowledgeService['semanticSearch']>;
62
+ };
63
+ readonly search: (options: KnowledgeSearchOptions) => ReturnType<KnowledgeService['search']>;
64
+ readonly retrieveContext: (options: KnowledgeContextOptions) => ReturnType<KnowledgeService['retrieveContext']>;
65
+ readonly ask: (prompt: string, options?: KnowledgeAskOptions) => ReturnType<KnowledgeService['runPrompt']>;
66
+ readonly build: (prompt: string, options?: KnowledgeAskOptions) => ReturnType<KnowledgeService['runPrompt']>;
67
+ readonly web: {
68
+ readonly search: (options: KnowledgeWebSearchOptions) => ReturnType<KnowledgeService['webSearch']>;
69
+ };
70
+ }
71
+ export declare function createKnowledgeClient(options?: KnowledgeClientOptions): KnowledgeClient;
72
+ export declare const createKnowledgeSdk: typeof createKnowledgeClient;
@@ -0,0 +1,65 @@
1
+ import { type EmbeddingRuntimeOptions } from './embeddings';
2
+ import { type GeneratedArtifactProvenance, type KnowledgeProvenance } from './provenance';
3
+ import type { KnowledgeConfig } from './workspace';
4
+ export type SearchResultKind = 'source_chunk' | 'wiki_chunk' | 'wiki_page' | 'knowledge_index';
5
+ export type SearchProvenance = KnowledgeProvenance | GeneratedArtifactProvenance;
6
+ export interface HybridSearchOptions extends EmbeddingRuntimeOptions {
7
+ dbPath: string;
8
+ query: string;
9
+ limit?: number;
10
+ semantic?: boolean;
11
+ config?: KnowledgeConfig;
12
+ }
13
+ export interface HybridSearchResult {
14
+ query: string;
15
+ limit: number;
16
+ mode: {
17
+ keyword: true;
18
+ catalog: true;
19
+ semantic: boolean;
20
+ };
21
+ semantic_provider: string | null;
22
+ semantic_model: string | null;
23
+ semantic_dimensions: number | null;
24
+ counts: {
25
+ keyword_results: number;
26
+ catalog_results: number;
27
+ semantic_results: number;
28
+ merged_results: number;
29
+ };
30
+ warnings: string[];
31
+ results: HybridSearchEntry[];
32
+ }
33
+ export interface HybridSearchEntry {
34
+ kind: SearchResultKind;
35
+ id: string;
36
+ title: string | null;
37
+ text: string | null;
38
+ score: number;
39
+ scores: {
40
+ keyword?: number;
41
+ semantic?: number;
42
+ catalog?: number;
43
+ };
44
+ source: {
45
+ uri: string | null;
46
+ ref: string | null;
47
+ kind: string | null;
48
+ revision: string | null;
49
+ hash: string | null;
50
+ } | null;
51
+ citation: {
52
+ chunk_id: string | null;
53
+ start_offset: number | null;
54
+ end_offset: number | null;
55
+ } | null;
56
+ artifact: {
57
+ uri: string | null;
58
+ path: string | null;
59
+ hash: string | null;
60
+ shard_key: string | null;
61
+ } | null;
62
+ provenance: SearchProvenance | null;
63
+ reasons: string[];
64
+ }
65
+ export declare function hybridSearch(options: HybridSearchOptions): Promise<HybridSearchResult>;