@aiquants/enrichment-core 0.1.1
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/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +911 -0
- package/dist/index.d.ts +911 -0
- package/dist/index.js +1 -0
- package/package.json +81 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var u=class extends Error{statusCode;responseBody;parsedBody;constructor(t,n,a,i){super(t),this.name="EnrichmentClientError",this.statusCode=n,this.responseBody=a,this.parsedBody=i}},g=class{baseUrl;apiKey;fetchFn;timeoutMs;constructor(t){if(!t||typeof t.baseUrl!="string"||t.baseUrl.trim().length===0)throw new Error("baseUrl is required and must be a non-empty string for EnrichmentClient.");let n=t.baseUrl.trim().replace(/\/$/,"");if(t.apiKey&&n.startsWith("http://")&&!n.includes("localhost")&&!n.includes("127.0.0.1"))throw new Error("Security Violation: Transmitting Bearer tokens over unencrypted HTTP to non-localhost hosts is strictly prohibited.");this.baseUrl=n,this.apiKey=t.apiKey,this.fetchFn=t.fetchFn??fetch,this.timeoutMs=t.timeoutMs&&t.timeoutMs>0?t.timeoutMs:3e4}async request(t,n,a,i){let c=`${this.baseUrl}${t}`;if(i){let o=new URLSearchParams;for(let[P,h]of Object.entries(i))h!=null&&h.trim().length>0&&o.append(P,h);let s=o.toString();s.length>0&&(c+=`?${s}`)}let _={Accept:"application/json"};this.apiKey&&(_.Authorization=`Bearer ${this.apiKey}`),a!==void 0&&(_["Content-Type"]="application/json");let b=new AbortController,O=setTimeout(()=>b.abort(),this.timeoutMs),p;try{p=await this.fetchFn(c,{method:n,headers:_,body:a!==void 0?JSON.stringify(a):void 0,signal:b.signal})}catch(o){let s=o instanceof Error?o.message:String(o);throw new u(`Network request failed for ${n} ${c}: ${s}`,0,"")}finally{clearTimeout(O)}if(!p.ok){let o=await p.text().catch(()=>""),s;try{s=JSON.parse(o)}catch{}throw new u(`API request failed with status ${p.status}: ${o}`,p.status,o,s)}let E=await p.text().catch(()=>"");if(E.trim().length!==0)try{return JSON.parse(E)}catch(o){let s=o instanceof Error?o.message:String(o);throw new u(`Failed to parse response JSON from ${c}: ${s}`,p.status,E)}}};import{z as e}from"zod";import{z as R}from"zod";var k=R.enum(["google_cloud","google_vision","yomitoku_local","faster_whisper_local","google_speech","ollama_local","openai","anthropic","azure_openai","bedrock","custom_openai_compatible"]),f=R.enum(["PUBLIC","INTERNAL","DEPARTMENT","CONFIDENTIAL","RESTRICTED"]),x="RESTRICTED";var Z={rrfK:{min:1,max:200,default:60},alpha:{min:0,max:1,default:.7},threshold:{min:0,max:1},limit:{min:1,max:50,default:10}},T=f.options.filter(r=>r!==x);if(T.length===0)throw new Error("The confidentiality vocabulary left nothing filterable after removing the quarantined level; a validator built from this list would reject every request.");var ee=T,v=["KEYWORD","SPARSE","DENSE","HYBRID","GRAPH_TRAVERSE"],S={KEYWORD:{dense:!1,sparse:!1,graph:!1,lexical:!0},SPARSE:{dense:!1,sparse:!0,graph:!1,lexical:!1},DENSE:{dense:!0,sparse:!1,graph:!1,lexical:!1},HYBRID:{dense:!0,sparse:!0,graph:!0,lexical:!0},GRAPH_TRAVERSE:{dense:!1,sparse:!1,graph:!0,lexical:!1}};function te(r){let t=S[r];return t.dense||t.sparse||t.graph}function ne(r){let t=S[r];return t.dense&&!t.sparse}function re(r,t){let n=S[r],a=(n.dense||n.sparse)&&t.vector,i=n.graph&&t.graph;return a||i?a?i?{mode:r,discardGraph:!1}:n.dense&&n.sparse?{mode:r,discardGraph:!0}:{mode:n.dense?"DENSE":"SPARSE",discardGraph:!1}:{mode:"GRAPH_TRAVERSE",discardGraph:!1}:null}function ae(r){let t=S[r];return[t.dense,t.sparse,t.graph,t.lexical].filter(Boolean).length>1}var y=e.string().trim().min(1,"tenant_id must be a non-empty string"),m=e.string().trim().min(1,"file_uri must be a non-empty string"),ce=e.enum(["PENDING","EXTRACTING","ENRICHING","PROJECTING","SYNCED","FAILED_EXTRACT","FAILED_ENRICH","FAILED_VECTOR","FAILED_GRAPH"]),A=e.object({page:e.number().int().positive().optional(),x:e.number().nonnegative().optional(),y:e.number().nonnegative().optional(),width:e.number().positive().optional(),height:e.number().positive().optional(),start_sec:e.number().nonnegative().optional(),end_sec:e.number().nonnegative().optional(),frame_index:e.number().int().nonnegative().optional(),timestamp_sec:e.number().nonnegative().optional(),scene_confidence:e.number().min(0).max(1).optional()}),U=e.object({title:e.string().trim().min(1),start_sec:e.number().nonnegative(),end_sec:e.number().nonnegative(),summary:e.string()}),z=e.object({start_sec:e.number().nonnegative(),end_sec:e.number().nonnegative(),speaker:e.string().trim().min(1),text:e.string()}),q=e.object({label:e.string(),value:e.number(),currency:e.string()}),pe=e.object({document_type:e.string().optional(),title:e.string().optional(),organization:e.string().optional(),key_entities:e.array(e.string()).optional(),dates:e.array(e.string()).optional(),amounts:e.array(q).optional(),media_type:e.enum(["video","audio"]).optional(),duration_sec:e.number().nonnegative().optional(),chapters:e.array(U).optional(),transcript_segments:e.array(z).optional()}),H=e.enum(["CLOSED","OPEN","HALF_OPEN"]),G=e.enum(["FULL_HYBRID","VECTOR_ONLY","GRAPH_ONLY","STANDARD_SEMANTIC","DEGRADED_KEYWORD_ONLY"]),K=e.enum(v),B=e.object({search_mode:K,quality_tier:G,is_degraded:e.boolean(),degradation_reason:e.string().nullable().optional(),circuit_breaker_status:e.record(H).optional(),latency_ms:e.number().nonnegative()}),I=e.enum(["CONTRACT_LEGAL","EMAIL_THREAD","DAILY_REPORT","FINANCIAL_REPORT","TECHNICAL_SPEC","MASTER_DATA","MEDIA_ASSET","GENERAL_DOCUMENT"]),V=e.enum(["hierarchical","conversation","section","fixed_size","table_aware","semantic","none","multimodal"]),C=e.object({id:e.number().int().positive(),tenant_id:y,parent_metadata_id:e.number().int().positive().nullable().optional(),file_uri:m,file_uri_hash:e.string(),revision:e.number().int().nonnegative(),is_current:e.boolean(),is_deleted:e.boolean(),is_derived:e.boolean(),file_name:e.string(),file_path:e.string(),folder_path:e.string().nullable().optional(),confidentiality_level:f,department_id:e.number().int().positive().nullable().optional(),file_size:e.number().int().nonnegative(),mime_type:e.string(),asset_type:e.string().nullable().optional(),asset_index:e.number().int().nonnegative().nullable().optional(),bounding_box:A.nullable().optional(),created_at:e.string(),updated_at:e.string()}),$=e.object({chunk_uid:e.string().min(1),file_uri:m,score:e.number(),content:e.string(),chunk_index:e.number().int().nonnegative(),clause_identifier:e.string().nullable().optional(),authority_tier:e.number().int().positive().nullable().optional(),breadcrumb_path:e.string().nullable().optional(),bounding_box:A.nullable().optional()}),N=e.object({query:e.string().trim().min(1,"query must not be empty"),tenant_id:y,domain_key:I.optional(),limit:e.number().int().positive().default(10),department_id:e.number().int().positive().optional(),user_roles:e.array(e.string()).default([])}),D=e.object({hits:e.array($),metadata:B}),L=e.object({file_uri:m,tenant_id:y,force:e.boolean().default(!1)}),M=e.object({file_uri:m,domain_key:I,strategy_name:e.string(),chunking_strategy:V.optional(),applied_rule_name:e.string().nullable().optional(),assigned_department_id:e.number().int().positive().nullable().optional()});var w=class extends g{async search(t){let n=N.parse(t),a=await this.request("/ai/search","POST",n);return D.parse(a)}async reclassify(t){let n=L.parse(t),a=await this.request("/ai/reclassify","POST",n);return M.parse(a)}async getFileMetadata(t,n){let a=m.parse(t),i=y.parse(n),c=await this.request("/ai/metadata","GET",void 0,{file_uri:a,tenant_id:i});return C.parse(c)}async getMetadata(t,n){return this.getFileMetadata(t,n)}};var F=[{key:"enable_summary_generation",featureFlagKey:null,label:"\u8981\u7D04\u751F\u6210"},{key:"enable_structured_extraction",featureFlagKey:null,label:"\u69CB\u9020\u5316\u62BD\u51FA"},{key:"enable_asset_extraction",featureFlagKey:"ENABLE_ASSET_EXTRACTION",label:"\u30A2\u30BB\u30C3\u30C8\u62BD\u51FA"},{key:"enable_vector_indexing",featureFlagKey:"ENABLE_VECTOR_INDEXING",label:"\u30D9\u30AF\u30C8\u30EB\u7D22\u5F15"},{key:"enable_graph_indexing",featureFlagKey:"ENABLE_GRAPH_INDEXING",label:"\u30B0\u30E9\u30D5\u6295\u5F71"}],j=new Set(F.map(r=>r.key));function he(r){return j.has(r)}function ge(r){let t=F.find(n=>n.key===r);if(t===void 0)throw new Error(`ENRICHMENT_STAGES does not carry ${r}; the canonical list and the key type have drifted apart.`);return t}var Se={pageSize:{min:1,max:200,default:50},topologyLabels:{min:1,max:24,default:24}};var d=-1,l=0;function Y(r){return/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(r)}function Ee(){let r=typeof globalThis<"u"&&globalThis.crypto?globalThis.crypto:typeof crypto<"u"?crypto:void 0;if(!r||typeof r.getRandomValues!="function")throw new Error("Cryptographically secure random number generator (crypto.getRandomValues) is required but not available.");let t=new Uint8Array(16);r.getRandomValues(t);let n=Date.now();if(n===d){if(l++,l>4095){for(;Date.now()<=d;);n=Date.now(),d=n,l=(t[6]<<4|t[7]&15)&1023}}else n>d?(d=n,l=(t[6]<<4|t[7]&15)&1023):(n=d,l++,l>4095&&(l=0));t[0]=Math.floor(n/1099511627776)&255,t[1]=Math.floor(n/4294967296)&255,t[2]=n>>>24&255,t[3]=n>>>16&255,t[4]=n>>>8&255,t[5]=n&255,t[6]=112|l>>>8&15,t[7]=l&255,t[8]=128|t[8]&63;let a=Array.from(t,c=>c.toString(16).padStart(2,"0")).join("");return`${a.slice(0,8)}-${a.slice(8,12)}-${a.slice(12,16)}-${a.slice(16,20)}-${a.slice(20)}`}function xe(r){if(!Y(r))throw new Error(`Invalid RFC 9562 UUIDv7 string: "${r}"`);let t=r.slice(0,8)+r.slice(9,13),n=parseInt(t,16);if(Number.isNaN(n))throw new Error(`Invalid hex timestamp in UUIDv7: "${t}"`);return new Date(n)}export{q as AmountEntrySchema,g as BaseEnrichmentClient,A as BoundingBoxSchema,I as CanonicalDomainKeySchema,U as ChapterSegmentSchema,V as ChunkingStrategySchema,H as CircuitBreakerStatusSchema,f as ConfidentialityLevelSchema,pe as DocumentStructuredDataSchema,F as ENRICHMENT_STAGES,w as EnrichmentClient,u as EnrichmentClientError,ce as EnrichmentSyncStatusSchema,ee as FILTERABLE_CONFIDENTIALITY_LEVELS,C as FileMetadataResponseSchema,m as FileUriSchema,Se as GRAPH_INDEX_LIMITS,S as MODE_TIERS,k as ModelProviderSchema,x as QUARANTINED_CONFIDENTIALITY_LEVEL,G as QualityTierSchema,L as ReclassifyRequestSchema,M as ReclassifyResponseSchema,v as SEARCH_MODES,Z as SEARCH_PARAM_LIMITS,$ as SearchHitSchema,B as SearchMetadataSchema,K as SearchModeSchema,N as SearchRequestSchema,D as SearchResponseSchema,y as TenantIdSchema,z as TranscriptSegmentSchema,ge as enrichmentStage,Ee as generateUuidV7,he as isEnrichmentStageKey,Y as isValidUuidV7,ae as modeFusesRankings,te as modeNeedsRemoteTiers,ne as modeScoreIsSimilarity,re as narrowModeToAllowedTiers,xe as uuidv7ToDate};
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aiquants/enrichment-core",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Storage metadata AI enrichment core: canonical schemas, RFC 9562 UUIDv7, and API client SDK.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"enrichment",
|
|
7
|
+
"metadata",
|
|
8
|
+
"rag",
|
|
9
|
+
"storage",
|
|
10
|
+
"ai",
|
|
11
|
+
"uuidv7",
|
|
12
|
+
"typescript"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "AI Quants",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/fehde-k/aiquants.git",
|
|
19
|
+
"directory": "packages/enrichment-core"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/fehde-k/aiquants/tree/main/packages/enrichment-core#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/fehde-k/aiquants/issues"
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./dist/index.cjs",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/index.d.cts",
|
|
38
|
+
"default": "./dist/index.cjs"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist",
|
|
44
|
+
"README.md",
|
|
45
|
+
"LICENSE"
|
|
46
|
+
],
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^25.0.3",
|
|
49
|
+
"@vitest/coverage-v8": "^4.1.8",
|
|
50
|
+
"rimraf": "^6.1.2",
|
|
51
|
+
"tsup": "^8.5.1",
|
|
52
|
+
"typescript": "^5.9.3",
|
|
53
|
+
"vitest": "^4.1.8",
|
|
54
|
+
"zod": "^3.25.76"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"zod": "^3.25.0"
|
|
58
|
+
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=18.0.0",
|
|
61
|
+
"pnpm": ">=8.0.0"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsup && node ../../.config/scripts/strip-dts-comments.mjs dist",
|
|
68
|
+
"build:watch": "tsup --watch",
|
|
69
|
+
"dev": "tsup --watch",
|
|
70
|
+
"publish:patch": "pnpm run typecheck && pnpm run --if-present test && pnpm version patch --no-git-tag-version --no-git-checks && pnpm publish --no-git-checks",
|
|
71
|
+
"publish:minor": "pnpm run typecheck && pnpm run --if-present test && pnpm version minor --no-git-tag-version --no-git-checks && pnpm publish --no-git-checks",
|
|
72
|
+
"publish:major": "pnpm run typecheck && pnpm run --if-present test && pnpm version major --no-git-tag-version --no-git-checks && pnpm publish --no-git-checks",
|
|
73
|
+
"typecheck": "tsc --noEmit",
|
|
74
|
+
"clean": "rimraf dist",
|
|
75
|
+
"lint": "biome lint src/",
|
|
76
|
+
"check": "biome check src/ tests/",
|
|
77
|
+
"check:fix": "biome check --write src/ tests/",
|
|
78
|
+
"test": "vitest run",
|
|
79
|
+
"test:coverage": "vitest run --coverage"
|
|
80
|
+
}
|
|
81
|
+
}
|