@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
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type KnowledgeContextPack, type RetrievalOptions } from './retrieval';
|
|
2
|
+
export interface KnowledgePromptOptions extends Omit<RetrievalOptions, 'query'> {
|
|
3
|
+
prompt: string;
|
|
4
|
+
generate?: boolean;
|
|
5
|
+
approveWrite?: boolean;
|
|
6
|
+
now?: Date;
|
|
7
|
+
}
|
|
8
|
+
export interface KnowledgePromptResult {
|
|
9
|
+
run_id: string;
|
|
10
|
+
prompt: string;
|
|
11
|
+
generated: boolean;
|
|
12
|
+
provider: string;
|
|
13
|
+
model: string;
|
|
14
|
+
answer: string;
|
|
15
|
+
context: KnowledgeContextPack;
|
|
16
|
+
citations: KnowledgeContextPack['citations'];
|
|
17
|
+
proposed_wiki_updates: Array<{
|
|
18
|
+
kind: 'answer_note';
|
|
19
|
+
title: string;
|
|
20
|
+
citations: string[];
|
|
21
|
+
requires_approval: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
write_policy: {
|
|
24
|
+
approved: boolean;
|
|
25
|
+
durable_writes_performed: false;
|
|
26
|
+
reason: string;
|
|
27
|
+
};
|
|
28
|
+
usage: {
|
|
29
|
+
input_tokens: number;
|
|
30
|
+
output_tokens: number;
|
|
31
|
+
cost_usd: number;
|
|
32
|
+
};
|
|
33
|
+
warnings: string[];
|
|
34
|
+
}
|
|
35
|
+
export declare function runKnowledgePrompt(options: KnowledgePromptOptions): Promise<KnowledgePromptResult>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { KnowledgeConfig, KnowledgeWorkspace } from './workspace';
|
|
2
|
+
interface S3ClientLike {
|
|
3
|
+
send(command: unknown): Promise<any>;
|
|
4
|
+
}
|
|
5
|
+
export interface ArtifactWrite {
|
|
6
|
+
key: string;
|
|
7
|
+
body: string | Uint8Array;
|
|
8
|
+
content_type?: string;
|
|
9
|
+
metadata?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
export interface ArtifactStore {
|
|
12
|
+
readonly type: 'local' | 's3';
|
|
13
|
+
readonly canRead: boolean;
|
|
14
|
+
readonly canWrite: boolean;
|
|
15
|
+
put(entry: ArtifactWrite): Promise<{
|
|
16
|
+
key: string;
|
|
17
|
+
uri: string;
|
|
18
|
+
}>;
|
|
19
|
+
getText(key: string): Promise<string>;
|
|
20
|
+
exists(key: string): Promise<boolean>;
|
|
21
|
+
}
|
|
22
|
+
export declare function normalizeArtifactKey(key: string): string;
|
|
23
|
+
export declare class LocalArtifactStore implements ArtifactStore {
|
|
24
|
+
private readonly root;
|
|
25
|
+
readonly type: "local";
|
|
26
|
+
readonly canRead = true;
|
|
27
|
+
readonly canWrite = true;
|
|
28
|
+
constructor(root: string);
|
|
29
|
+
put(entry: ArtifactWrite): Promise<{
|
|
30
|
+
key: string;
|
|
31
|
+
uri: string;
|
|
32
|
+
}>;
|
|
33
|
+
getText(key: string): Promise<string>;
|
|
34
|
+
exists(key: string): Promise<boolean>;
|
|
35
|
+
}
|
|
36
|
+
export interface S3ArtifactStoreOptions {
|
|
37
|
+
bucket: string;
|
|
38
|
+
prefix?: string;
|
|
39
|
+
region?: string;
|
|
40
|
+
profile?: string;
|
|
41
|
+
max_attempts?: number;
|
|
42
|
+
server_side_encryption?: 'AES256' | 'aws:kms';
|
|
43
|
+
kms_key_id?: string;
|
|
44
|
+
client?: S3ClientLike;
|
|
45
|
+
}
|
|
46
|
+
export declare class S3ArtifactStore implements ArtifactStore {
|
|
47
|
+
private readonly options;
|
|
48
|
+
readonly type: "s3";
|
|
49
|
+
readonly canRead = true;
|
|
50
|
+
readonly canWrite = true;
|
|
51
|
+
private client?;
|
|
52
|
+
constructor(options: S3ArtifactStoreOptions);
|
|
53
|
+
private getClient;
|
|
54
|
+
private objectKey;
|
|
55
|
+
put(entry: ArtifactWrite): Promise<{
|
|
56
|
+
key: string;
|
|
57
|
+
uri: string;
|
|
58
|
+
}>;
|
|
59
|
+
getText(key: string): Promise<string>;
|
|
60
|
+
exists(key: string): Promise<boolean>;
|
|
61
|
+
}
|
|
62
|
+
export declare function createArtifactStore(config: KnowledgeConfig, workspace: KnowledgeWorkspace): ArtifactStore;
|
|
63
|
+
export {};
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { KnowledgeConfig } from './workspace';
|
|
2
|
+
export interface KnowledgeAuthConfig {
|
|
3
|
+
api_key: string;
|
|
4
|
+
email?: string;
|
|
5
|
+
org_id?: string;
|
|
6
|
+
org_slug?: string;
|
|
7
|
+
user_id?: string;
|
|
8
|
+
api_url?: string;
|
|
9
|
+
created_at: string;
|
|
10
|
+
}
|
|
11
|
+
export interface KnowledgeAuthStatus {
|
|
12
|
+
authenticated: boolean;
|
|
13
|
+
source: 'env' | 'file' | 'none';
|
|
14
|
+
api_url: string;
|
|
15
|
+
auth_path: string;
|
|
16
|
+
email: string | null;
|
|
17
|
+
org_id: string | null;
|
|
18
|
+
org_slug: string | null;
|
|
19
|
+
user_id: string | null;
|
|
20
|
+
api_key_present: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare const DEFAULT_KNOWLEDGE_API_URL = "https://knowledge.hasna.xyz";
|
|
23
|
+
export declare function normalizeKnowledgeApiOrigin(apiUrl: string): string;
|
|
24
|
+
export declare function knowledgeAuthPath(env?: Record<string, string | undefined>): string;
|
|
25
|
+
export declare function resolveKnowledgeApiUrl(config?: KnowledgeConfig, env?: Record<string, string | undefined>): string;
|
|
26
|
+
export declare function getKnowledgeAuth(env?: Record<string, string | undefined>): KnowledgeAuthConfig | null;
|
|
27
|
+
export declare function saveKnowledgeAuth(auth: Omit<KnowledgeAuthConfig, 'created_at'> & {
|
|
28
|
+
created_at?: string;
|
|
29
|
+
}, env?: Record<string, string | undefined>): KnowledgeAuthConfig;
|
|
30
|
+
export declare function clearKnowledgeAuth(env?: Record<string, string | undefined>): boolean;
|
|
31
|
+
export declare function getKnowledgeApiKey(env?: Record<string, string | undefined>): {
|
|
32
|
+
apiKey: string | null;
|
|
33
|
+
source: KnowledgeAuthStatus['source'];
|
|
34
|
+
};
|
|
35
|
+
export declare function knowledgeAuthStatus(config?: KnowledgeConfig, env?: Record<string, string | undefined>): KnowledgeAuthStatus;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type AiProviderId } from './providers';
|
|
2
|
+
import { type KnowledgeProvenance } from './provenance';
|
|
3
|
+
import type { KnowledgeConfig } from './workspace';
|
|
4
|
+
export interface EmbeddingRuntimeOptions {
|
|
5
|
+
config?: KnowledgeConfig;
|
|
6
|
+
env?: Record<string, string | undefined>;
|
|
7
|
+
modelRef?: string;
|
|
8
|
+
dimensions?: number;
|
|
9
|
+
fake?: boolean;
|
|
10
|
+
batchSize?: number;
|
|
11
|
+
maxParallelCalls?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface EmbeddingIndexOptions extends EmbeddingRuntimeOptions {
|
|
14
|
+
dbPath: string;
|
|
15
|
+
limit?: number;
|
|
16
|
+
sourceRevisionId?: string;
|
|
17
|
+
now?: Date;
|
|
18
|
+
}
|
|
19
|
+
export interface EmbeddingSearchOptions extends EmbeddingRuntimeOptions {
|
|
20
|
+
dbPath: string;
|
|
21
|
+
query: string;
|
|
22
|
+
limit?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface EmbeddingUsage {
|
|
25
|
+
input_tokens: number;
|
|
26
|
+
}
|
|
27
|
+
export interface EmbeddingVectorResult {
|
|
28
|
+
provider: AiProviderId;
|
|
29
|
+
model: string;
|
|
30
|
+
dimensions: number;
|
|
31
|
+
vectors: number[][];
|
|
32
|
+
usage: EmbeddingUsage;
|
|
33
|
+
}
|
|
34
|
+
export interface EmbeddingIndexResult {
|
|
35
|
+
provider: AiProviderId;
|
|
36
|
+
model: string;
|
|
37
|
+
dimensions: number;
|
|
38
|
+
chunks_seen: number;
|
|
39
|
+
chunks_embedded: number;
|
|
40
|
+
embeddings_upserted: number;
|
|
41
|
+
vector_entries_upserted: number;
|
|
42
|
+
usage: EmbeddingUsage;
|
|
43
|
+
}
|
|
44
|
+
export interface EmbeddingStatusResult {
|
|
45
|
+
total_embeddings: number;
|
|
46
|
+
total_vector_entries: number;
|
|
47
|
+
indexes: Array<{
|
|
48
|
+
provider: string;
|
|
49
|
+
model: string;
|
|
50
|
+
dimensions: number;
|
|
51
|
+
entries: number;
|
|
52
|
+
updated_at: string | null;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
55
|
+
export interface SemanticSearchResult {
|
|
56
|
+
provider: AiProviderId;
|
|
57
|
+
model: string;
|
|
58
|
+
dimensions: number;
|
|
59
|
+
query: string;
|
|
60
|
+
results: Array<{
|
|
61
|
+
chunk_id: string;
|
|
62
|
+
score: number;
|
|
63
|
+
text: string;
|
|
64
|
+
source_uri: string | null;
|
|
65
|
+
source_ref: string | null;
|
|
66
|
+
revision: string | null;
|
|
67
|
+
hash: string | null;
|
|
68
|
+
provenance: KnowledgeProvenance | null;
|
|
69
|
+
}>;
|
|
70
|
+
}
|
|
71
|
+
export declare const DEFAULT_EMBEDDING_MODEL_REF = "openai:text-embedding-3-small";
|
|
72
|
+
export declare const DEFAULT_EMBEDDING_DIMENSIONS = 1536;
|
|
73
|
+
export declare function resolveEmbeddingModelRef(modelRef?: string, config?: KnowledgeConfig): string;
|
|
74
|
+
export declare function embedTexts(texts: string[], options?: EmbeddingRuntimeOptions): Promise<EmbeddingVectorResult>;
|
|
75
|
+
export declare function indexKnowledgeEmbeddings(options: EmbeddingIndexOptions): Promise<EmbeddingIndexResult>;
|
|
76
|
+
export declare function embeddingIndexStatus(dbPath: string): EmbeddingStatusResult;
|
|
77
|
+
export declare function searchVectorIndex(options: EmbeddingSearchOptions): Promise<SemanticSearchResult>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { createKnowledgeClient, createKnowledgeSdk, type KnowledgeAskOptions, type KnowledgeAuthInput, type KnowledgeClient, type KnowledgeClientOptions, type KnowledgeContextOptions, type KnowledgeSearchOptions, type KnowledgeSetupOptions, type KnowledgeWebSearchOptions, } from './sdk.js';
|
|
2
|
+
export { createKnowledgeService, KnowledgeService, type KnowledgePathsResult, type KnowledgeServiceOptions, type KnowledgeSetupResult, } from './service.js';
|
|
3
|
+
export { HASNA_KNOWLEDGE_APP_PATH, HASNA_XYZ_KNOWLEDGE_CANONICAL, canonicalHasnaXyzKnowledgeStorage, defaultKnowledgeConfig, ensureKnowledgeWorkspace, globalKnowledgeHome, projectKnowledgeHome, readKnowledgeConfig, resolveScopedWorkspace, workspaceForHome, writeKnowledgeConfig, type KnowledgeConfig, type KnowledgeWorkspace, } from './workspace.js';
|
|
4
|
+
export { createArtifactStore, LocalArtifactStore, S3ArtifactStore, normalizeArtifactKey, type ArtifactStore, type ArtifactWrite, type S3ArtifactStoreOptions, } from './artifact-store.js';
|
|
5
|
+
export { artifactKindForKey, hashArtifactBody, resolveStorageContract, validateStorageConfig, type GeneratedStorageObject, type StorageArtifactClass, type StorageContract, type StorageValidationResult, } from './storage-contract.js';
|
|
6
|
+
export { parseSourceRef, catalogSourceUriForRef, revisionIdForSourceRef, isSupportedSourceRef, type BaseSourceRef, type FileSourceRef, type OpenFilesSourceRef, type S3SourceRef, type SourceRef, type SourceRefKind, type WebSourceRef, } from './source-ref.js';
|
|
7
|
+
export { hybridSearch, type HybridSearchEntry, type HybridSearchOptions, type HybridSearchResult, type SearchProvenance, type SearchResultKind, } from './search.js';
|
|
8
|
+
export { retrieveKnowledgeContext, type KnowledgeContextPack, type RetrievalCitation, type RetrievalExcerpt, type RetrievalGraphEvidence, type RetrievalOptions, type RerankedSearchEntry, } from './retrieval.js';
|
|
9
|
+
export { runKnowledgePrompt, type KnowledgePromptOptions, type KnowledgePromptResult, } from './agent.js';
|
|
10
|
+
export { DEFAULT_EMBEDDING_DIMENSIONS, DEFAULT_EMBEDDING_MODEL_REF, embedTexts, embeddingIndexStatus, indexKnowledgeEmbeddings, resolveEmbeddingModelRef, searchVectorIndex, type EmbeddingIndexOptions, type EmbeddingIndexResult, type EmbeddingRuntimeOptions, type EmbeddingSearchOptions, type EmbeddingStatusResult, type EmbeddingUsage, type EmbeddingVectorResult, type SemanticSearchResult, } from './embeddings.js';
|
|
11
|
+
export { createAiSdkProviderRegistry, languageModelFor, listModelRegistry, modelAliases, parseModelRef, providerCredentialStatus, providerSettings, providerStatus, resolveModelRef, type AiProviderId, type AiProviderRuntimeOptions, type AiProviderSettings, type AiProvidersConfig, type ModelCapabilities, type ModelRegistryEntry, type ProviderCredentialStatus, type ProviderStatusResult, } from './providers.js';
|
|
12
|
+
export { runProviderWebSearch, type WebSearchOptions, type WebSearchResult, type WebSearchSource, } from './web-search.js';
|
|
13
|
+
export { compileWikiPage, fileAnswerToWiki, lintWiki, type WikiAnswerFileOptions, type WikiAnswerFileResult, type WikiCompileOptions, type WikiCompileResult, type WikiLintIssue, type WikiLintResult, } from './wiki-compiler.js';
|
|
14
|
+
export { ingestOpenFilesManifest, ingestOpenFilesManifestItems, type ManifestIngestOptions, type ManifestIngestResult, type ManifestItemsIngestOptions, type ManifestObject, } from './manifest-ingest.js';
|
|
15
|
+
export { ingestSourceRef, type SourceIngestOptions, type SourceIngestResult, } from './source-ingest.js';
|
|
16
|
+
export { resolveOpenFilesSource, type ResolvedSourceChunk, type ResolvedSourceCitation, type SourceResolveOptions, type SourceResolveResult, type SourceResolverEvidence, } from './source-resolver.js';
|
|
17
|
+
export { consumeOpenFilesOutbox, type OutboxConsumeOptions, type OutboxConsumeResult, } from './outbox-consume.js';
|
|
18
|
+
export { enqueueMissingEmbeddings, refreshEmbeddingIndex, reindexHealth, type ReindexEmbeddingsResult, type ReindexEnqueueResult, type ReindexHealthResult, type ReindexRuntimeOptions, } from './reindex.js';
|
|
19
|
+
export { DEFAULT_KNOWLEDGE_API_URL, clearKnowledgeAuth, getKnowledgeApiKey, getKnowledgeAuth, knowledgeAuthPath, knowledgeAuthStatus, normalizeKnowledgeApiOrigin, resolveKnowledgeApiUrl, saveKnowledgeAuth, type KnowledgeAuthConfig, type KnowledgeAuthStatus, } from './auth.js';
|
|
20
|
+
export { REMOTE_KNOWLEDGE_CONTRACT_VERSION, RemoteKnowledgeClient, knowledgeRegistryContract, normalizeRemoteKnowledgeRunContract, type RemoteKnowledgeArtifact, type RemoteKnowledgeArtifactContract, type RemoteKnowledgeLogEntry, type RemoteKnowledgePromptRequest, type RemoteKnowledgeRegistryContract, type RemoteKnowledgeRunContract, type RemoteKnowledgeRunStatus, type RemoteKnowledgeSearchRequest, type RemoteKnowledgeSourceContract, type RemoteKnowledgeSyncRequest, } from './remote-client.js';
|