rust-kgdb 0.5.6 → 0.5.9

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/index.d.ts CHANGED
@@ -741,3 +741,251 @@ export function createPlanningContext(
741
741
  endpoint: string,
742
742
  hints?: string[]
743
743
  ): PlanningContext
744
+
745
+ // ==============================================
746
+ // HyperMind Architecture Components (v0.5.8+)
747
+ // ==============================================
748
+
749
+ /**
750
+ * TypeId - Hindley-Milner type system with refinement types
751
+ *
752
+ * Base types: String, Int64, Float64, Bool, Unit
753
+ * RDF types: Node, Triple, Quad, BindingSet
754
+ * Compound: List<T>, Option<T>, Result<T,E>, Map<K,V>
755
+ * Refinement: RiskScore, PolicyNumber, ClaimAmount, CreditScore
756
+ */
757
+ export const TypeId: {
758
+ // Base types
759
+ String: 'String'
760
+ Int64: 'Int64'
761
+ Float64: 'Float64'
762
+ Bool: 'Bool'
763
+ Unit: 'Unit'
764
+
765
+ // RDF-native types
766
+ Node: 'Node'
767
+ Triple: 'Triple'
768
+ Quad: 'Quad'
769
+ BindingSet: 'BindingSet'
770
+
771
+ // Compound types
772
+ List: (t: string) => string
773
+ Option: (t: string) => string
774
+ Result: (t: string, e: string) => string
775
+ Map: (k: string, v: string) => string
776
+
777
+ // Refinement types (business domain)
778
+ RiskScore: 'RiskScore'
779
+ PolicyNumber: 'PolicyNumber'
780
+ ClaimAmount: 'ClaimAmount'
781
+ ClaimId: 'ClaimId'
782
+ CreditScore: 'CreditScore'
783
+ ConfidenceScore: 'ConfidenceScore'
784
+
785
+ // Schema types
786
+ SchemaType: (name: string) => string
787
+
788
+ // Type checking
789
+ isCompatible: (output: string, input: string) => boolean
790
+ }
791
+
792
+ /**
793
+ * Tool morphism definition in the TOOL_REGISTRY
794
+ */
795
+ export interface ToolMorphism {
796
+ name: string
797
+ input: string
798
+ output: string
799
+ description: string
800
+ domain: string
801
+ constraints?: Record<string, unknown>
802
+ patterns?: Record<string, string>
803
+ prebuiltRules?: Record<string, string>
804
+ }
805
+
806
+ /**
807
+ * TOOL_REGISTRY - All available tools as typed morphisms (Category Theory)
808
+ * Each tool is an arrow: Input Type → Output Type
809
+ */
810
+ export const TOOL_REGISTRY: Record<string, ToolMorphism>
811
+
812
+ /**
813
+ * LLMPlanner - Natural language to typed tool pipelines
814
+ *
815
+ * Converts natural language prompts into validated execution plans
816
+ * using type checking (Curry-Howard correspondence).
817
+ *
818
+ * @example
819
+ * ```typescript
820
+ * const planner = new LLMPlanner('claude-sonnet-4', TOOL_REGISTRY)
821
+ * const plan = await planner.plan('Find suspicious claims')
822
+ * // plan.steps, plan.type_chain, plan.confidence
823
+ * ```
824
+ */
825
+ export class LLMPlanner {
826
+ constructor(model: string, tools?: Record<string, ToolMorphism>)
827
+
828
+ /**
829
+ * Generate execution plan from natural language
830
+ */
831
+ plan(prompt: string, context?: Record<string, unknown>): Promise<{
832
+ id: string
833
+ prompt: string
834
+ intent: Record<string, unknown>
835
+ steps: Array<{
836
+ id: number
837
+ tool: string
838
+ input_type: string
839
+ output_type: string
840
+ args: Record<string, unknown>
841
+ }>
842
+ type_chain: string
843
+ confidence: number
844
+ explanation: string
845
+ }>
846
+ }
847
+
848
+ /**
849
+ * WasmSandbox configuration
850
+ */
851
+ export interface WasmSandboxConfig {
852
+ /** Maximum memory in bytes (default: 64MB) */
853
+ maxMemory?: number
854
+ /** Maximum execution time in ms (default: 10000) */
855
+ maxExecTime?: number
856
+ /** Capabilities: 'ReadKG', 'WriteKG', 'ExecuteTool' */
857
+ capabilities?: string[]
858
+ /** Fuel limit for operations (default: 1000000) */
859
+ fuelLimit?: number
860
+ }
861
+
862
+ /**
863
+ * WasmSandbox - Secure WASM execution environment
864
+ *
865
+ * All interaction with the Rust core flows through WASM for complete security:
866
+ * - Isolated linear memory (no direct host access)
867
+ * - CPU fuel metering (configurable operation limits)
868
+ * - Capability-based permissions (ReadKG, WriteKG, ExecuteTool)
869
+ * - Memory limits (configurable maximum allocation)
870
+ * - Full audit logging (all tool invocations recorded)
871
+ *
872
+ * @example
873
+ * ```typescript
874
+ * const sandbox = new WasmSandbox({
875
+ * capabilities: ['ReadKG', 'ExecuteTool'],
876
+ * fuelLimit: 1000000,
877
+ * maxMemory: 64 * 1024 * 1024
878
+ * })
879
+ * ```
880
+ */
881
+ export class WasmSandbox {
882
+ constructor(config?: WasmSandboxConfig)
883
+
884
+ /**
885
+ * Create Object Proxy for gRPC-style tool invocation
886
+ */
887
+ createObjectProxy(tools: Record<string, ToolMorphism>): Record<string, (args: unknown) => Promise<unknown>>
888
+
889
+ /**
890
+ * Check if sandbox has a specific capability
891
+ */
892
+ hasCapability(cap: string): boolean
893
+
894
+ /**
895
+ * Get audit log of all tool invocations
896
+ */
897
+ getAuditLog(): Array<{
898
+ timestamp: string
899
+ tool: string
900
+ args: unknown
901
+ result: unknown
902
+ status: 'OK' | 'DENIED'
903
+ error?: string
904
+ fuel_remaining: number
905
+ }>
906
+
907
+ /**
908
+ * Get sandbox metrics
909
+ */
910
+ getMetrics(): {
911
+ fuel_initial: number
912
+ fuel_remaining: number
913
+ fuel_consumed: number
914
+ memory_used: number
915
+ memory_limit: number
916
+ capabilities: string[]
917
+ tool_calls: number
918
+ }
919
+ }
920
+
921
+ /**
922
+ * ComposedAgent - Agent with sandbox execution and witness generation
923
+ */
924
+ export class ComposedAgent {
925
+ name: string
926
+
927
+ /**
928
+ * Execute with natural language prompt
929
+ */
930
+ call(prompt: string): Promise<{
931
+ response: string
932
+ plan: unknown
933
+ results: Array<{ step: unknown; result?: unknown; error?: string; status: string }>
934
+ witness: {
935
+ witness_version: string
936
+ timestamp: string
937
+ agent: string
938
+ model: string
939
+ plan: { id: string; steps: number; confidence: number }
940
+ execution: { tool_calls: Array<{ tool: string; status: string }> }
941
+ sandbox_metrics: unknown
942
+ audit_log: unknown[]
943
+ proof_hash: string
944
+ }
945
+ metrics: unknown
946
+ }>
947
+ }
948
+
949
+ /**
950
+ * AgentBuilder - Fluent builder for agent composition
951
+ *
952
+ * @example
953
+ * ```typescript
954
+ * const agent = new AgentBuilder('compliance-checker')
955
+ * .withTool('kg.sparql.query')
956
+ * .withTool('kg.datalog.infer')
957
+ * .withPlanner('claude-sonnet-4')
958
+ * .withSandbox({ capabilities: ['ReadKG'], fuelLimit: 1000000 })
959
+ * .withHook('afterExecute', (data) => console.log(data))
960
+ * .build()
961
+ * ```
962
+ */
963
+ export class AgentBuilder {
964
+ constructor(name: string)
965
+
966
+ /**
967
+ * Add tool to agent (from TOOL_REGISTRY)
968
+ */
969
+ withTool(toolName: string, toolImpl?: (args: unknown) => Promise<unknown>): this
970
+
971
+ /**
972
+ * Set LLM planner model
973
+ */
974
+ withPlanner(model: string): this
975
+
976
+ /**
977
+ * Configure WASM sandbox
978
+ */
979
+ withSandbox(config: WasmSandboxConfig): this
980
+
981
+ /**
982
+ * Add execution hook
983
+ * Events: 'beforePlan', 'afterPlan', 'beforeExecute', 'afterExecute', 'onError'
984
+ */
985
+ withHook(event: string, handler: (data: unknown) => void): this
986
+
987
+ /**
988
+ * Build the composed agent
989
+ */
990
+ build(): ComposedAgent
991
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rust-kgdb",
3
- "version": "0.5.6",
3
+ "version": "0.5.9",
4
4
  "description": "Production-grade Neuro-Symbolic AI Framework: +86.4% accuracy improvement over vanilla LLMs. High-performance knowledge graph (2.78µs lookups, 35x faster than RDFox). Features fraud detection, underwriting agents, WASM sandbox, type/category/proof theory, and W3C SPARQL 1.1 compliance.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",