@hasna/knowledge 0.2.27 → 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.
- package/README.md +41 -0
- package/bin/open-knowledge-mcp.js +15 -7
- package/bin/open-knowledge.js +17 -17
- package/dist/agent.d.ts +35 -0
- package/dist/artifact-store.d.ts +63 -0
- package/dist/auth.d.ts +35 -0
- package/dist/embeddings.d.ts +77 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +5709 -0
- package/dist/knowledge-db.d.ts +27 -0
- package/dist/manifest-ingest.d.ts +35 -0
- package/dist/outbox-consume.d.ts +25 -0
- package/dist/provenance.d.ts +50 -0
- package/dist/providers.d.ts +89 -0
- package/dist/reindex.d.ts +37 -0
- package/dist/remote-client.d.ts +108 -0
- package/dist/retrieval.d.ts +71 -0
- package/dist/safety.d.ts +70 -0
- package/dist/sdk.d.ts +72 -0
- package/dist/search.d.ts +65 -0
- package/dist/service.d.ts +117 -0
- package/dist/source-ingest.d.ts +18 -0
- package/dist/source-ref.d.ts +30 -0
- package/dist/source-resolver.d.ts +92 -0
- package/dist/storage-contract.d.ts +106 -0
- package/dist/web-search.d.ts +40 -0
- package/dist/wiki-compiler.d.ts +67 -0
- package/dist/wiki-layout.d.ts +23 -0
- package/dist/workspace.d.ts +111 -0
- package/package.json +15 -7
- package/src/agent.ts +0 -367
- package/src/artifact-store.ts +0 -184
- package/src/auth.ts +0 -123
- package/src/cli.ts +0 -1184
- package/src/embeddings.ts +0 -516
- package/src/knowledge-db.ts +0 -354
- package/src/manifest-ingest.ts +0 -515
- package/src/mcp-http.js +0 -110
- package/src/mcp.js +0 -1503
- package/src/outbox-consume.ts +0 -463
- package/src/provenance.ts +0 -93
- package/src/providers.ts +0 -308
- package/src/reindex.ts +0 -260
- package/src/remote-client.ts +0 -268
- package/src/retrieval.ts +0 -326
- package/src/safety.ts +0 -265
- package/src/schema.js +0 -25
- package/src/search.ts +0 -510
- package/src/service.ts +0 -443
- package/src/source-ingest.ts +0 -268
- package/src/source-ref.ts +0 -104
- package/src/source-resolver.ts +0 -436
- package/src/storage-contract.ts +0 -346
- package/src/store.ts +0 -113
- package/src/web-search.ts +0 -330
- package/src/wiki-compiler.ts +0 -711
- package/src/wiki-layout.ts +0 -251
- package/src/workspace.ts +0 -251
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type KnowledgeAuthStatus } from './auth';
|
|
2
|
+
import { type KnowledgePromptOptions } from './agent';
|
|
3
|
+
import { type EmbeddingIndexOptions, type EmbeddingSearchOptions } from './embeddings';
|
|
4
|
+
import { type ProviderStatusResult, type ModelRegistryEntry } from './providers';
|
|
5
|
+
import { type ReindexRuntimeOptions } from './reindex';
|
|
6
|
+
import { RemoteKnowledgeClient, type RemoteKnowledgeRegistryContract } from './remote-client';
|
|
7
|
+
import { type RetrievalOptions } from './retrieval';
|
|
8
|
+
import { type HybridSearchOptions } from './search';
|
|
9
|
+
import { type WebSearchOptions } from './web-search';
|
|
10
|
+
import { type WikiCompileOptions } from './wiki-compiler';
|
|
11
|
+
import { type StorageContract, type StorageValidationResult } from './storage-contract';
|
|
12
|
+
import { type KnowledgeConfig, type KnowledgeWorkspace } from './workspace';
|
|
13
|
+
export interface KnowledgeServiceOptions {
|
|
14
|
+
scope?: string;
|
|
15
|
+
cwd?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface KnowledgePathsResult {
|
|
18
|
+
ok: true;
|
|
19
|
+
scope: string;
|
|
20
|
+
home: string;
|
|
21
|
+
config_path: string;
|
|
22
|
+
json_store_path: string;
|
|
23
|
+
knowledge_db_path: string;
|
|
24
|
+
artifacts_dir: string;
|
|
25
|
+
indexes_dir: string;
|
|
26
|
+
logs_dir: string;
|
|
27
|
+
runs_dir: string;
|
|
28
|
+
schemas_dir: string;
|
|
29
|
+
wiki_dir: string;
|
|
30
|
+
config: KnowledgeConfig;
|
|
31
|
+
message: string;
|
|
32
|
+
}
|
|
33
|
+
export interface KnowledgeSetupResult {
|
|
34
|
+
ok: true;
|
|
35
|
+
mode: KnowledgeConfig['mode'];
|
|
36
|
+
api_url: string | null;
|
|
37
|
+
storage_type: KnowledgeConfig['storage']['type'];
|
|
38
|
+
artifact_uri_prefix: string;
|
|
39
|
+
canonical_hasna_xyz: StorageContract['canonical_hasna_xyz'];
|
|
40
|
+
config_path: string;
|
|
41
|
+
next: string[];
|
|
42
|
+
message: string;
|
|
43
|
+
}
|
|
44
|
+
export declare class KnowledgeService {
|
|
45
|
+
private readonly options;
|
|
46
|
+
private ensuredWorkspace?;
|
|
47
|
+
private cachedConfig?;
|
|
48
|
+
constructor(options?: KnowledgeServiceOptions);
|
|
49
|
+
get scope(): string;
|
|
50
|
+
get workspace(): KnowledgeWorkspace;
|
|
51
|
+
ensureWorkspace(): KnowledgeWorkspace;
|
|
52
|
+
jsonStorePath(): string;
|
|
53
|
+
config(): KnowledgeConfig;
|
|
54
|
+
safetyPolicy(): import("./safety").SafetyPolicy;
|
|
55
|
+
artifactStore(): import("./artifact-store").ArtifactStore;
|
|
56
|
+
storageContract(): StorageContract;
|
|
57
|
+
validateStorage(): StorageValidationResult;
|
|
58
|
+
setup(options?: {
|
|
59
|
+
mode?: string;
|
|
60
|
+
apiUrl?: string;
|
|
61
|
+
canonicalHasnaXyz?: boolean;
|
|
62
|
+
}): KnowledgeSetupResult;
|
|
63
|
+
authStatus(env?: Record<string, string | undefined>): KnowledgeAuthStatus;
|
|
64
|
+
saveAuth(input: {
|
|
65
|
+
apiKey: string;
|
|
66
|
+
email?: string;
|
|
67
|
+
orgId?: string;
|
|
68
|
+
orgSlug?: string;
|
|
69
|
+
userId?: string;
|
|
70
|
+
apiUrl?: string;
|
|
71
|
+
}, env?: Record<string, string | undefined>): import("./auth").KnowledgeAuthConfig;
|
|
72
|
+
clearAuth(env?: Record<string, string | undefined>): boolean;
|
|
73
|
+
remoteContract(): RemoteKnowledgeRegistryContract;
|
|
74
|
+
remoteClient(env?: Record<string, string | undefined>): RemoteKnowledgeClient | null;
|
|
75
|
+
paths(): KnowledgePathsResult;
|
|
76
|
+
initDb(): {
|
|
77
|
+
path: string;
|
|
78
|
+
schema_version: number;
|
|
79
|
+
};
|
|
80
|
+
dbStats(): import("./knowledge-db").KnowledgeDbStats;
|
|
81
|
+
initWiki(): Promise<import("./wiki-layout").WikiLayoutInitResult>;
|
|
82
|
+
compileWiki(options?: Omit<WikiCompileOptions, 'dbPath' | 'store'>): Promise<import("./wiki-compiler").WikiCompileResult>;
|
|
83
|
+
fileAnswer(options: {
|
|
84
|
+
prompt: string;
|
|
85
|
+
answer: string;
|
|
86
|
+
approveWrite?: boolean;
|
|
87
|
+
limit?: number;
|
|
88
|
+
semantic?: boolean;
|
|
89
|
+
modelRef?: string;
|
|
90
|
+
dimensions?: number;
|
|
91
|
+
fake?: boolean;
|
|
92
|
+
}): Promise<import("./wiki-compiler").WikiAnswerFileResult>;
|
|
93
|
+
lintWiki(): import("./wiki-compiler").WikiLintResult;
|
|
94
|
+
ingestManifest(input: string): Promise<import("./manifest-ingest").ManifestIngestResult>;
|
|
95
|
+
ingestSource(sourceRef: string, purpose?: string): Promise<import("./source-ingest").SourceIngestResult>;
|
|
96
|
+
resolveSource(sourceRef: string, options?: {
|
|
97
|
+
purpose?: string;
|
|
98
|
+
limit?: number;
|
|
99
|
+
}): Promise<import("./source-resolver").SourceResolveResult>;
|
|
100
|
+
consumeOutbox(input: string): Promise<import("./outbox-consume").OutboxConsumeResult>;
|
|
101
|
+
reindexHealth(options?: Omit<ReindexRuntimeOptions, 'dbPath' | 'config'>): import("./reindex").ReindexHealthResult;
|
|
102
|
+
enqueueReindex(options?: Omit<ReindexRuntimeOptions, 'dbPath' | 'config'>): import("./reindex").ReindexEnqueueResult;
|
|
103
|
+
refreshEmbeddings(options?: Omit<ReindexRuntimeOptions & {
|
|
104
|
+
full?: boolean;
|
|
105
|
+
limit?: number;
|
|
106
|
+
}, 'dbPath' | 'config'>): Promise<import("./reindex").ReindexEmbeddingsResult>;
|
|
107
|
+
providerStatus(env?: Record<string, string | undefined>): ProviderStatusResult;
|
|
108
|
+
modelRegistry(): ModelRegistryEntry[];
|
|
109
|
+
embeddingStatus(): import("./embeddings").EmbeddingStatusResult;
|
|
110
|
+
indexEmbeddings(options?: Omit<EmbeddingIndexOptions, 'dbPath' | 'config'>): Promise<import("./embeddings").EmbeddingIndexResult>;
|
|
111
|
+
semanticSearch(options: Omit<EmbeddingSearchOptions, 'dbPath' | 'config'>): Promise<import("./embeddings").SemanticSearchResult>;
|
|
112
|
+
search(options: Omit<HybridSearchOptions, 'dbPath' | 'config'>): Promise<import("./search").HybridSearchResult>;
|
|
113
|
+
retrieveContext(options: Omit<RetrievalOptions, 'dbPath' | 'config'>): Promise<import("./retrieval").KnowledgeContextPack>;
|
|
114
|
+
runPrompt(options: Omit<KnowledgePromptOptions, 'dbPath' | 'config'>): Promise<import("./agent").KnowledgePromptResult>;
|
|
115
|
+
webSearch(options: Omit<WebSearchOptions, 'dbPath' | 'config' | 'safetyPolicy'>): Promise<import("./web-search").WebSearchResult>;
|
|
116
|
+
}
|
|
117
|
+
export declare function createKnowledgeService(options?: KnowledgeServiceOptions): KnowledgeService;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ManifestIngestResult } from './manifest-ingest';
|
|
2
|
+
import type { KnowledgeConfig } from './workspace';
|
|
3
|
+
import { type SafetyPolicy } from './safety';
|
|
4
|
+
export interface SourceIngestOptions {
|
|
5
|
+
dbPath: string;
|
|
6
|
+
sourceRef: string;
|
|
7
|
+
purpose?: string;
|
|
8
|
+
config?: KnowledgeConfig;
|
|
9
|
+
safetyPolicy?: SafetyPolicy;
|
|
10
|
+
now?: Date;
|
|
11
|
+
}
|
|
12
|
+
export interface SourceIngestResult extends ManifestIngestResult {
|
|
13
|
+
source_ref: string;
|
|
14
|
+
content_source: 'catalog_chunks' | 'extracted_text_ref' | 'file' | 's3' | 'web';
|
|
15
|
+
read_only: true;
|
|
16
|
+
hash: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function ingestSourceRef(options: SourceIngestOptions): Promise<SourceIngestResult>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type SourceRefKind = 'open-files' | 's3' | 'file' | 'web';
|
|
2
|
+
export interface BaseSourceRef {
|
|
3
|
+
kind: SourceRefKind;
|
|
4
|
+
uri: string;
|
|
5
|
+
}
|
|
6
|
+
export interface OpenFilesSourceRef extends BaseSourceRef {
|
|
7
|
+
kind: 'open-files';
|
|
8
|
+
entity: 'file' | 'source';
|
|
9
|
+
id: string;
|
|
10
|
+
revision_id?: string;
|
|
11
|
+
path?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface S3SourceRef extends BaseSourceRef {
|
|
14
|
+
kind: 's3';
|
|
15
|
+
bucket: string;
|
|
16
|
+
key: string;
|
|
17
|
+
}
|
|
18
|
+
export interface FileSourceRef extends BaseSourceRef {
|
|
19
|
+
kind: 'file';
|
|
20
|
+
path: string;
|
|
21
|
+
}
|
|
22
|
+
export interface WebSourceRef extends BaseSourceRef {
|
|
23
|
+
kind: 'web';
|
|
24
|
+
url: string;
|
|
25
|
+
}
|
|
26
|
+
export type SourceRef = OpenFilesSourceRef | S3SourceRef | FileSourceRef | WebSourceRef;
|
|
27
|
+
export declare function parseSourceRef(uri: string): SourceRef;
|
|
28
|
+
export declare function catalogSourceUriForRef(uri: string, parsed?: SourceRef): string;
|
|
29
|
+
export declare function revisionIdForSourceRef(uri: string): string | null;
|
|
30
|
+
export declare function isSupportedSourceRef(uri: string): boolean;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type KnowledgeProvenance } from './provenance';
|
|
2
|
+
import { type SafetyPolicy } from './safety';
|
|
3
|
+
export interface SourceResolveOptions {
|
|
4
|
+
dbPath: string;
|
|
5
|
+
sourceRef: string;
|
|
6
|
+
purpose?: string;
|
|
7
|
+
limit?: number;
|
|
8
|
+
now?: Date;
|
|
9
|
+
safetyPolicy?: SafetyPolicy;
|
|
10
|
+
}
|
|
11
|
+
export interface SourceResolverEvidence {
|
|
12
|
+
resolver: 'open-files-read-only';
|
|
13
|
+
mode: 'local_catalog';
|
|
14
|
+
purpose: string;
|
|
15
|
+
read_only: true;
|
|
16
|
+
source_ref: string;
|
|
17
|
+
source_uri: string;
|
|
18
|
+
source_revision_id: string | null;
|
|
19
|
+
revision: string | null;
|
|
20
|
+
hash: string | null;
|
|
21
|
+
chunk_id?: string;
|
|
22
|
+
start_offset?: number | null;
|
|
23
|
+
end_offset?: number | null;
|
|
24
|
+
resolved_at: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ResolvedSourceChunk {
|
|
27
|
+
id: string;
|
|
28
|
+
kind: string;
|
|
29
|
+
ordinal: number;
|
|
30
|
+
text: string;
|
|
31
|
+
token_count: number | null;
|
|
32
|
+
start_offset: number | null;
|
|
33
|
+
end_offset: number | null;
|
|
34
|
+
metadata: Record<string, unknown>;
|
|
35
|
+
evidence: SourceResolverEvidence;
|
|
36
|
+
provenance: KnowledgeProvenance;
|
|
37
|
+
}
|
|
38
|
+
export interface ResolvedSourceCitation {
|
|
39
|
+
source_ref: string;
|
|
40
|
+
source_uri: string;
|
|
41
|
+
chunk_id: string;
|
|
42
|
+
quote: string;
|
|
43
|
+
start_offset: number | null;
|
|
44
|
+
end_offset: number | null;
|
|
45
|
+
evidence: SourceResolverEvidence;
|
|
46
|
+
provenance: KnowledgeProvenance;
|
|
47
|
+
}
|
|
48
|
+
export interface SourceResolveResult {
|
|
49
|
+
source_ref: string;
|
|
50
|
+
source_uri: string;
|
|
51
|
+
purpose: string;
|
|
52
|
+
read_only: true;
|
|
53
|
+
resolved: boolean;
|
|
54
|
+
resolver: {
|
|
55
|
+
name: 'open-files-read-only';
|
|
56
|
+
mode: 'local_catalog';
|
|
57
|
+
contract: 'open-files-knowledge-source-v1';
|
|
58
|
+
};
|
|
59
|
+
source: {
|
|
60
|
+
id: string;
|
|
61
|
+
uri: string;
|
|
62
|
+
kind: string;
|
|
63
|
+
title: string | null;
|
|
64
|
+
metadata: Record<string, unknown>;
|
|
65
|
+
permissions: Record<string, unknown>;
|
|
66
|
+
updated_at: string;
|
|
67
|
+
} | null;
|
|
68
|
+
revision: {
|
|
69
|
+
id: string;
|
|
70
|
+
revision: string;
|
|
71
|
+
hash: string | null;
|
|
72
|
+
extracted_text_uri: string | null;
|
|
73
|
+
metadata: Record<string, unknown>;
|
|
74
|
+
created_at: string;
|
|
75
|
+
reindex_required: boolean;
|
|
76
|
+
} | null;
|
|
77
|
+
content: {
|
|
78
|
+
mime: string | null;
|
|
79
|
+
size: number | null;
|
|
80
|
+
hash: string | null;
|
|
81
|
+
text_available: boolean;
|
|
82
|
+
chunks_total: number;
|
|
83
|
+
chunks_returned: number;
|
|
84
|
+
char_count_returned: number;
|
|
85
|
+
extracted_text_ref: string | null;
|
|
86
|
+
bytes_available: false;
|
|
87
|
+
bytes_exposed: false;
|
|
88
|
+
};
|
|
89
|
+
chunks: ResolvedSourceChunk[];
|
|
90
|
+
citations: ResolvedSourceCitation[];
|
|
91
|
+
}
|
|
92
|
+
export declare function resolveOpenFilesSource(options: SourceResolveOptions): Promise<SourceResolveResult>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Database } from 'bun:sqlite';
|
|
2
|
+
import { REMOTE_KNOWLEDGE_CONTRACT_VERSION } from './remote-client';
|
|
3
|
+
import type { KnowledgeConfig, KnowledgeWorkspace } from './workspace';
|
|
4
|
+
import { HASNA_XYZ_KNOWLEDGE_CANONICAL } from './workspace';
|
|
5
|
+
export interface StorageArtifactClass {
|
|
6
|
+
kind: string;
|
|
7
|
+
prefix: string;
|
|
8
|
+
description: string;
|
|
9
|
+
}
|
|
10
|
+
export interface StorageContract {
|
|
11
|
+
scope: string;
|
|
12
|
+
mode: KnowledgeConfig['mode'];
|
|
13
|
+
storage_type: KnowledgeConfig['storage']['type'];
|
|
14
|
+
workspace_home: string;
|
|
15
|
+
local_layout: {
|
|
16
|
+
app_path: string;
|
|
17
|
+
config_path: string;
|
|
18
|
+
json_store_path: string;
|
|
19
|
+
knowledge_db_path: string;
|
|
20
|
+
directories: Record<string, string>;
|
|
21
|
+
};
|
|
22
|
+
artifact_store: {
|
|
23
|
+
type: KnowledgeConfig['storage']['type'];
|
|
24
|
+
artifacts_root: string;
|
|
25
|
+
uri_prefix: string;
|
|
26
|
+
s3: {
|
|
27
|
+
bucket: string;
|
|
28
|
+
prefix: string;
|
|
29
|
+
region: string | null;
|
|
30
|
+
profile: string | null;
|
|
31
|
+
server_side_encryption: string | null;
|
|
32
|
+
kms_key_configured: boolean;
|
|
33
|
+
} | null;
|
|
34
|
+
};
|
|
35
|
+
canonical_hasna_xyz: {
|
|
36
|
+
division: typeof HASNA_XYZ_KNOWLEDGE_CANONICAL.division;
|
|
37
|
+
app_type: typeof HASNA_XYZ_KNOWLEDGE_CANONICAL.app_type;
|
|
38
|
+
app: typeof HASNA_XYZ_KNOWLEDGE_CANONICAL.app;
|
|
39
|
+
env: typeof HASNA_XYZ_KNOWLEDGE_CANONICAL.env;
|
|
40
|
+
active: boolean;
|
|
41
|
+
local_path: string;
|
|
42
|
+
s3: {
|
|
43
|
+
bucket: string;
|
|
44
|
+
region: string;
|
|
45
|
+
profile: string;
|
|
46
|
+
prefix: string;
|
|
47
|
+
uri_prefix: string;
|
|
48
|
+
server_side_encryption: string;
|
|
49
|
+
};
|
|
50
|
+
secrets: {
|
|
51
|
+
env: string;
|
|
52
|
+
aws: string;
|
|
53
|
+
s3: string;
|
|
54
|
+
rds: null;
|
|
55
|
+
future_rds: string;
|
|
56
|
+
};
|
|
57
|
+
evidence_doc: string;
|
|
58
|
+
};
|
|
59
|
+
hosted: {
|
|
60
|
+
enabled: boolean;
|
|
61
|
+
api_url: string;
|
|
62
|
+
api_url_env: 'KNOWLEDGE_API_URL';
|
|
63
|
+
api_key_env: 'KNOWLEDGE_API_KEY';
|
|
64
|
+
auth_storage: '~/.hasna/knowledge/auth.json';
|
|
65
|
+
remote_contract_version: typeof REMOTE_KNOWLEDGE_CONTRACT_VERSION;
|
|
66
|
+
requires_hosted_account_for_local_use: false;
|
|
67
|
+
};
|
|
68
|
+
source_ownership: {
|
|
69
|
+
owner: 'open-files';
|
|
70
|
+
preferred_ref: string;
|
|
71
|
+
allowed_schemes: string[];
|
|
72
|
+
raw_source_bytes_stored_in_open_knowledge: false;
|
|
73
|
+
stores: string[];
|
|
74
|
+
does_not_store: string[];
|
|
75
|
+
};
|
|
76
|
+
generated_artifacts: StorageArtifactClass[];
|
|
77
|
+
scalability: {
|
|
78
|
+
catalog: string;
|
|
79
|
+
indexes: string;
|
|
80
|
+
logs: string;
|
|
81
|
+
markdown: string;
|
|
82
|
+
};
|
|
83
|
+
warnings: string[];
|
|
84
|
+
}
|
|
85
|
+
export interface StorageValidationResult {
|
|
86
|
+
ok: boolean;
|
|
87
|
+
errors: string[];
|
|
88
|
+
warnings: string[];
|
|
89
|
+
}
|
|
90
|
+
export interface GeneratedStorageObject {
|
|
91
|
+
uri: string;
|
|
92
|
+
key: string;
|
|
93
|
+
kind: string;
|
|
94
|
+
content_type?: string;
|
|
95
|
+
hash?: string;
|
|
96
|
+
size_bytes?: number;
|
|
97
|
+
metadata?: Record<string, unknown>;
|
|
98
|
+
}
|
|
99
|
+
export declare function hashArtifactBody(body: string | Uint8Array): {
|
|
100
|
+
hash: string;
|
|
101
|
+
size_bytes: number;
|
|
102
|
+
};
|
|
103
|
+
export declare function artifactKindForKey(key: string): string;
|
|
104
|
+
export declare function resolveStorageContract(config: KnowledgeConfig, workspace: KnowledgeWorkspace, scope?: string): StorageContract;
|
|
105
|
+
export declare function validateStorageConfig(config: KnowledgeConfig, workspace: KnowledgeWorkspace): StorageValidationResult;
|
|
106
|
+
export declare function recordStorageObjects(db: Database, objects: GeneratedStorageObject[], now?: Date): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type AiProviderId } from './providers';
|
|
2
|
+
import { type SafetyPolicy } from './safety';
|
|
3
|
+
import type { KnowledgeConfig } from './workspace';
|
|
4
|
+
export interface WebSearchOptions {
|
|
5
|
+
dbPath: string;
|
|
6
|
+
query: string;
|
|
7
|
+
config?: KnowledgeConfig;
|
|
8
|
+
safetyPolicy?: SafetyPolicy;
|
|
9
|
+
modelRef?: string;
|
|
10
|
+
provider?: AiProviderId;
|
|
11
|
+
limit?: number;
|
|
12
|
+
maxUses?: number;
|
|
13
|
+
domains?: string[];
|
|
14
|
+
fake?: boolean;
|
|
15
|
+
fileResults?: boolean;
|
|
16
|
+
env?: Record<string, string | undefined>;
|
|
17
|
+
now?: Date;
|
|
18
|
+
}
|
|
19
|
+
export interface WebSearchSource {
|
|
20
|
+
url: string;
|
|
21
|
+
title: string | null;
|
|
22
|
+
snippet: string | null;
|
|
23
|
+
provider_metadata: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
export interface WebSearchResult {
|
|
26
|
+
run_id: string;
|
|
27
|
+
query: string;
|
|
28
|
+
provider: string;
|
|
29
|
+
model: string;
|
|
30
|
+
answer: string;
|
|
31
|
+
sources: WebSearchSource[];
|
|
32
|
+
filed_sources: number;
|
|
33
|
+
usage: {
|
|
34
|
+
input_tokens: number;
|
|
35
|
+
output_tokens: number;
|
|
36
|
+
cost_usd: number;
|
|
37
|
+
};
|
|
38
|
+
warnings: string[];
|
|
39
|
+
}
|
|
40
|
+
export declare function runProviderWebSearch(options: WebSearchOptions): Promise<WebSearchResult>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ArtifactStore } from './artifact-store';
|
|
2
|
+
import type { KnowledgeContextPack } from './retrieval';
|
|
3
|
+
export interface WikiCompileOptions {
|
|
4
|
+
dbPath: string;
|
|
5
|
+
store: ArtifactStore;
|
|
6
|
+
title?: string;
|
|
7
|
+
query?: string;
|
|
8
|
+
sourceRefs?: string[];
|
|
9
|
+
limit?: number;
|
|
10
|
+
now?: Date;
|
|
11
|
+
}
|
|
12
|
+
export interface WikiCompileResult {
|
|
13
|
+
page_id: string;
|
|
14
|
+
path: string;
|
|
15
|
+
artifact_uri: string;
|
|
16
|
+
content_hash: string;
|
|
17
|
+
chunks_seen: number;
|
|
18
|
+
citations_written: number;
|
|
19
|
+
concept_page_id: string | null;
|
|
20
|
+
indexes_updated: number;
|
|
21
|
+
log_key: string;
|
|
22
|
+
warnings: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface WikiAnswerFileOptions {
|
|
25
|
+
dbPath: string;
|
|
26
|
+
store: ArtifactStore;
|
|
27
|
+
prompt: string;
|
|
28
|
+
answer: string;
|
|
29
|
+
context: KnowledgeContextPack;
|
|
30
|
+
approveWrite?: boolean;
|
|
31
|
+
now?: Date;
|
|
32
|
+
}
|
|
33
|
+
export interface WikiAnswerFileResult {
|
|
34
|
+
approved: boolean;
|
|
35
|
+
durable_writes_performed: boolean;
|
|
36
|
+
page_id: string | null;
|
|
37
|
+
path: string | null;
|
|
38
|
+
artifact_uri: string | null;
|
|
39
|
+
citations_written: number;
|
|
40
|
+
log_key: string | null;
|
|
41
|
+
message: string;
|
|
42
|
+
}
|
|
43
|
+
export interface WikiLintIssue {
|
|
44
|
+
type: 'missing_citation' | 'stale_citation' | 'duplicate_page' | 'orphan_page' | 'unresolved_source_ref' | 'contradiction_marker' | 'new_article_candidate';
|
|
45
|
+
severity: 'info' | 'warn' | 'error';
|
|
46
|
+
page_id?: string;
|
|
47
|
+
path?: string;
|
|
48
|
+
source_uri?: string;
|
|
49
|
+
chunk_id?: string;
|
|
50
|
+
message: string;
|
|
51
|
+
}
|
|
52
|
+
export interface WikiLintResult {
|
|
53
|
+
ok: boolean;
|
|
54
|
+
issue_count: number;
|
|
55
|
+
issues: WikiLintIssue[];
|
|
56
|
+
counts: {
|
|
57
|
+
active_pages: number;
|
|
58
|
+
citations: number;
|
|
59
|
+
backlinks: number;
|
|
60
|
+
new_article_candidates: number;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export declare function compileWikiPage(options: WikiCompileOptions): Promise<WikiCompileResult>;
|
|
64
|
+
export declare function fileAnswerToWiki(options: WikiAnswerFileOptions): Promise<WikiAnswerFileResult>;
|
|
65
|
+
export declare function lintWiki(options: {
|
|
66
|
+
dbPath: string;
|
|
67
|
+
}): WikiLintResult;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Database } from 'bun:sqlite';
|
|
2
|
+
import type { ArtifactStore } from './artifact-store';
|
|
3
|
+
import { type GeneratedStorageObject } from './storage-contract';
|
|
4
|
+
export interface WikiLayoutInitResult {
|
|
5
|
+
schema_key: string;
|
|
6
|
+
root_index_key: string;
|
|
7
|
+
wiki_readme_key: string;
|
|
8
|
+
log_key: string;
|
|
9
|
+
artifacts: GeneratedStorageObject[];
|
|
10
|
+
written: string[];
|
|
11
|
+
}
|
|
12
|
+
interface CatalogArtifact {
|
|
13
|
+
key: string;
|
|
14
|
+
uri: string;
|
|
15
|
+
hash?: string;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
export declare function agentSchemaTemplate(): string;
|
|
19
|
+
export declare function rootIndexTemplate(): string;
|
|
20
|
+
export declare function wikiReadmeTemplate(): string;
|
|
21
|
+
export declare function initializeWikiLayout(store: ArtifactStore, now?: Date): Promise<WikiLayoutInitResult>;
|
|
22
|
+
export declare function recordWikiLayoutCatalog(db: Database, artifacts: CatalogArtifact[], now?: Date): void;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export declare const HASNA_KNOWLEDGE_APP_PATH: string;
|
|
2
|
+
export interface KnowledgeWorkspace {
|
|
3
|
+
home: string;
|
|
4
|
+
configPath: string;
|
|
5
|
+
jsonStorePath: string;
|
|
6
|
+
knowledgeDbPath: string;
|
|
7
|
+
artifactsDir: string;
|
|
8
|
+
cacheDir: string;
|
|
9
|
+
exportsDir: string;
|
|
10
|
+
indexesDir: string;
|
|
11
|
+
logsDir: string;
|
|
12
|
+
runsDir: string;
|
|
13
|
+
schemasDir: string;
|
|
14
|
+
wikiDir: string;
|
|
15
|
+
}
|
|
16
|
+
export interface KnowledgeConfig {
|
|
17
|
+
version: 1;
|
|
18
|
+
mode: 'local' | 'hosted';
|
|
19
|
+
hosted?: {
|
|
20
|
+
api_url?: string;
|
|
21
|
+
};
|
|
22
|
+
storage: {
|
|
23
|
+
type: 'local' | 's3';
|
|
24
|
+
artifacts_root: string;
|
|
25
|
+
s3?: {
|
|
26
|
+
bucket: string;
|
|
27
|
+
prefix?: string;
|
|
28
|
+
region?: string;
|
|
29
|
+
profile?: string;
|
|
30
|
+
max_attempts?: number;
|
|
31
|
+
server_side_encryption?: 'AES256' | 'aws:kms';
|
|
32
|
+
kms_key_id?: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
sources: {
|
|
36
|
+
preferred_ref: 'open-files';
|
|
37
|
+
allowed_schemes: string[];
|
|
38
|
+
};
|
|
39
|
+
embeddings?: {
|
|
40
|
+
default_model?: string;
|
|
41
|
+
dimensions?: number;
|
|
42
|
+
batch_size?: number;
|
|
43
|
+
max_parallel_calls?: number;
|
|
44
|
+
};
|
|
45
|
+
providers?: {
|
|
46
|
+
default_model?: string;
|
|
47
|
+
aliases?: Record<string, string>;
|
|
48
|
+
openai?: {
|
|
49
|
+
api_key_env?: string;
|
|
50
|
+
base_url?: string;
|
|
51
|
+
default_model?: string;
|
|
52
|
+
};
|
|
53
|
+
anthropic?: {
|
|
54
|
+
api_key_env?: string;
|
|
55
|
+
base_url?: string;
|
|
56
|
+
default_model?: string;
|
|
57
|
+
};
|
|
58
|
+
deepseek?: {
|
|
59
|
+
api_key_env?: string;
|
|
60
|
+
base_url?: string;
|
|
61
|
+
default_model?: string;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
safety?: {
|
|
65
|
+
network?: {
|
|
66
|
+
web_search_enabled?: boolean;
|
|
67
|
+
s3_reads_enabled?: boolean;
|
|
68
|
+
allowed_s3_buckets?: string[];
|
|
69
|
+
};
|
|
70
|
+
redaction?: {
|
|
71
|
+
enabled?: boolean;
|
|
72
|
+
};
|
|
73
|
+
approvals?: {
|
|
74
|
+
generated_writes_require_approval?: boolean;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export declare const HASNA_XYZ_KNOWLEDGE_CANONICAL: {
|
|
79
|
+
readonly division: "xyz";
|
|
80
|
+
readonly app_type: "opensource";
|
|
81
|
+
readonly app: "knowledge";
|
|
82
|
+
readonly env: "prod";
|
|
83
|
+
readonly local_path: string;
|
|
84
|
+
readonly s3: {
|
|
85
|
+
readonly bucket: "hasna-xyz-opensource-knowledge-prod";
|
|
86
|
+
readonly region: "us-east-1";
|
|
87
|
+
readonly profile: "hasna-xyz-infra";
|
|
88
|
+
readonly prefix: ".hasna/apps/knowledge";
|
|
89
|
+
readonly server_side_encryption: "AES256";
|
|
90
|
+
};
|
|
91
|
+
readonly secrets: {
|
|
92
|
+
readonly env: "hasna/xyz/opensource/knowledge/prod/env";
|
|
93
|
+
readonly aws: "hasna/xyz/opensource/knowledge/prod/aws";
|
|
94
|
+
readonly s3: "hasna/xyz/opensource/knowledge/prod/s3";
|
|
95
|
+
readonly rds: any;
|
|
96
|
+
readonly future_rds: "hasna/xyz/opensource/knowledge/prod/rds";
|
|
97
|
+
};
|
|
98
|
+
readonly source_owner: "open-files";
|
|
99
|
+
readonly evidence_doc: "docs/canonical-secrets-bootstrap-2026-06-08.md";
|
|
100
|
+
};
|
|
101
|
+
export declare function canonicalHasnaXyzKnowledgeStorage(): KnowledgeConfig['storage'];
|
|
102
|
+
export declare function legacyGlobalStorePath(): string;
|
|
103
|
+
export declare function globalKnowledgeHome(): string;
|
|
104
|
+
export declare function projectKnowledgeHome(cwd?: string): string;
|
|
105
|
+
export declare function workspaceForHome(home: string): KnowledgeWorkspace;
|
|
106
|
+
export declare function defaultKnowledgeConfig(): KnowledgeConfig;
|
|
107
|
+
export declare function ensureKnowledgeWorkspace(home: string): KnowledgeWorkspace;
|
|
108
|
+
export declare function resolveScopedWorkspace(scope: string | undefined, cwd?: string): KnowledgeWorkspace;
|
|
109
|
+
export declare function ensureParentDir(path: string): void;
|
|
110
|
+
export declare function readKnowledgeConfig(path: string): KnowledgeConfig;
|
|
111
|
+
export declare function writeKnowledgeConfig(path: string, config: KnowledgeConfig): void;
|
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna/knowledge",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.28",
|
|
4
4
|
"description": "Agent-friendly local knowledge CLI with JSON output, pagination, and safe destructive actions",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
6
14
|
"bin": {
|
|
7
15
|
"knowledge": "bin/open-knowledge.js",
|
|
8
16
|
"open-knowledge": "bin/open-knowledge.js",
|
|
@@ -10,7 +18,7 @@
|
|
|
10
18
|
},
|
|
11
19
|
"files": [
|
|
12
20
|
"bin",
|
|
13
|
-
"
|
|
21
|
+
"dist",
|
|
14
22
|
"docs",
|
|
15
23
|
"LICENSE",
|
|
16
24
|
"README.md"
|
|
@@ -18,9 +26,8 @@
|
|
|
18
26
|
"scripts": {
|
|
19
27
|
"test": "bun test",
|
|
20
28
|
"test:cli": "bun test tests/cli.test.ts",
|
|
21
|
-
"build": "bun build --target=bun --outfile=bin/open-knowledge.js --minify --external @aws-sdk/client-s3 --external @aws-sdk/credential-providers --external ai --external @ai-sdk/openai --external @ai-sdk/anthropic --external @ai-sdk/deepseek src/cli.ts && bun build --target=bun --outfile=bin/open-knowledge-mcp.js --external @modelcontextprotocol/sdk --external @aws-sdk/client-s3 --external @aws-sdk/credential-providers --external ai --external @ai-sdk/openai --external @ai-sdk/anthropic --external @ai-sdk/deepseek src/mcp.js",
|
|
22
|
-
"prepublishOnly": "bun run build"
|
|
23
|
-
"postinstall": "bun run build"
|
|
29
|
+
"build": "rm -rf dist && bun build --target=bun --outfile=bin/open-knowledge.js --minify --external @aws-sdk/client-s3 --external @aws-sdk/credential-providers --external ai --external @ai-sdk/openai --external @ai-sdk/anthropic --external @ai-sdk/deepseek src/cli.ts && bun build --target=bun --outfile=bin/open-knowledge-mcp.js --external @modelcontextprotocol/sdk --external @aws-sdk/client-s3 --external @aws-sdk/credential-providers --external ai --external @ai-sdk/openai --external @ai-sdk/anthropic --external @ai-sdk/deepseek src/mcp.js && bun build ./src/index.ts --outdir ./dist --target bun --external @aws-sdk/client-s3 --external @aws-sdk/credential-providers --external ai --external @ai-sdk/openai --external @ai-sdk/anthropic --external @ai-sdk/deepseek && bunx tsc -p tsconfig.build.json",
|
|
30
|
+
"prepublishOnly": "bun run build"
|
|
24
31
|
},
|
|
25
32
|
"keywords": [
|
|
26
33
|
"knowledge",
|
|
@@ -49,12 +56,13 @@
|
|
|
49
56
|
"node": ">=18"
|
|
50
57
|
},
|
|
51
58
|
"dependencies": {
|
|
52
|
-
"@aws-sdk/client-s3": "^3.1063.0",
|
|
53
|
-
"@aws-sdk/credential-providers": "^3.1063.0",
|
|
54
59
|
"@ai-sdk/anthropic": "^3.0.81",
|
|
55
60
|
"@ai-sdk/deepseek": "^2.0.35",
|
|
56
61
|
"@ai-sdk/openai": "^3.0.68",
|
|
62
|
+
"@aws-sdk/client-s3": "^3.1063.0",
|
|
63
|
+
"@aws-sdk/credential-providers": "^3.1063.0",
|
|
57
64
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
65
|
+
"@types/json-schema": "^7.0.15",
|
|
58
66
|
"ai": "^6.0.197",
|
|
59
67
|
"zod": "^4.3.6"
|
|
60
68
|
},
|