@aleph-ai/tinyaleph 1.0.0
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 +278 -0
- package/backends/cryptographic/index.js +196 -0
- package/backends/index.js +15 -0
- package/backends/interface.js +89 -0
- package/backends/scientific/index.js +272 -0
- package/backends/semantic/index.js +527 -0
- package/backends/semantic/surface.js +393 -0
- package/backends/semantic/two-layer.js +375 -0
- package/core/fano.js +127 -0
- package/core/hilbert.js +564 -0
- package/core/hypercomplex.js +141 -0
- package/core/index.js +133 -0
- package/core/llm.js +132 -0
- package/core/prime.js +184 -0
- package/core/resonance.js +695 -0
- package/core/rformer-tf.js +1086 -0
- package/core/rformer.js +806 -0
- package/core/sieve.js +350 -0
- package/data.json +8163 -0
- package/docs/EXAMPLES_PLAN.md +293 -0
- package/docs/README.md +159 -0
- package/docs/design/ALEPH_CHAT_ARCHITECTURE.md +499 -0
- package/docs/guide/01-quickstart.md +298 -0
- package/docs/guide/02-semantic-computing.md +409 -0
- package/docs/guide/03-cryptographic.md +420 -0
- package/docs/guide/04-scientific.md +494 -0
- package/docs/guide/05-llm-integration.md +568 -0
- package/docs/guide/06-advanced.md +996 -0
- package/docs/guide/README.md +188 -0
- package/docs/reference/01-core.md +695 -0
- package/docs/reference/02-physics.md +601 -0
- package/docs/reference/03-backends.md +892 -0
- package/docs/reference/04-engine.md +632 -0
- package/docs/reference/README.md +252 -0
- package/docs/theory/01-prime-semantics.md +327 -0
- package/docs/theory/02-hypercomplex-algebra.md +421 -0
- package/docs/theory/03-phase-synchronization.md +364 -0
- package/docs/theory/04-entropy-reasoning.md +348 -0
- package/docs/theory/05-non-commutativity.md +402 -0
- package/docs/theory/06-two-layer-meaning.md +414 -0
- package/docs/theory/07-resonant-field-interface.md +419 -0
- package/docs/theory/08-semantic-sieve.md +520 -0
- package/docs/theory/09-temporal-emergence.md +298 -0
- package/docs/theory/10-quaternionic-memory.md +415 -0
- package/docs/theory/README.md +162 -0
- package/engine/aleph.js +418 -0
- package/engine/index.js +7 -0
- package/index.js +23 -0
- package/modular.js +254 -0
- package/package.json +99 -0
- package/physics/collapse.js +95 -0
- package/physics/entropy.js +88 -0
- package/physics/index.js +65 -0
- package/physics/kuramoto.js +91 -0
- package/physics/lyapunov.js +80 -0
- package/physics/oscillator.js +95 -0
- package/types/index.d.ts +575 -0
package/core/index.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core mathematical foundation - exports all core modules
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { Hypercomplex } = require('./hypercomplex');
|
|
6
|
+
const {
|
|
7
|
+
FANO_LINES,
|
|
8
|
+
octonionMultiplyIndex,
|
|
9
|
+
sedenionMultiplyIndex,
|
|
10
|
+
multiplyIndices,
|
|
11
|
+
buildMultiplicationTable
|
|
12
|
+
} = require('./fano');
|
|
13
|
+
const {
|
|
14
|
+
primeGenerator, nthPrime, primesUpTo, isPrime,
|
|
15
|
+
factorize, primeSignature, firstNPrimes,
|
|
16
|
+
GaussianInteger, EisensteinInteger,
|
|
17
|
+
primeToFrequency, primeToAngle, sumOfTwoSquares,
|
|
18
|
+
DEFAULT_PRIMES
|
|
19
|
+
} = require('./prime');
|
|
20
|
+
const LLM = require('./llm');
|
|
21
|
+
|
|
22
|
+
// Prime Hilbert Space (complex amplitudes, quantum-like)
|
|
23
|
+
const {
|
|
24
|
+
Complex,
|
|
25
|
+
PrimeState,
|
|
26
|
+
ResonanceOperators,
|
|
27
|
+
EntropyDrivenEvolution,
|
|
28
|
+
encodeMemory,
|
|
29
|
+
symbolicCompute
|
|
30
|
+
} = require('./hilbert');
|
|
31
|
+
|
|
32
|
+
// Prime Resonance Network components
|
|
33
|
+
const {
|
|
34
|
+
PHI, PHI_CONJ, DELTA_S,
|
|
35
|
+
QuaternionPrime,
|
|
36
|
+
PrimeResonanceIdentity,
|
|
37
|
+
PhaseLockedRing,
|
|
38
|
+
HolographicField,
|
|
39
|
+
EntangledNode,
|
|
40
|
+
ResonantFragment
|
|
41
|
+
} = require('./resonance');
|
|
42
|
+
|
|
43
|
+
// ResoFormer ML primitives
|
|
44
|
+
const {
|
|
45
|
+
Quaternion,
|
|
46
|
+
SparsePrimeState,
|
|
47
|
+
resonanceScore,
|
|
48
|
+
resonantAttention,
|
|
49
|
+
hamiltonCompose,
|
|
50
|
+
measureNonCommutativity,
|
|
51
|
+
computeCoherence,
|
|
52
|
+
haltingDecision,
|
|
53
|
+
coherenceGatedCompute,
|
|
54
|
+
EntropyCollapseHead,
|
|
55
|
+
generateAttractorCodebook,
|
|
56
|
+
PRGraphMemory,
|
|
57
|
+
applyResonanceOperator
|
|
58
|
+
} = require('./rformer');
|
|
59
|
+
|
|
60
|
+
// TensorFlow.js layers (lazy load - may not be available)
|
|
61
|
+
let rformerTF = null;
|
|
62
|
+
try {
|
|
63
|
+
rformerTF = require('./rformer-tf');
|
|
64
|
+
} catch (e) {
|
|
65
|
+
// TensorFlow.js not available, skip
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = {
|
|
69
|
+
// Hypercomplex algebra
|
|
70
|
+
Hypercomplex,
|
|
71
|
+
|
|
72
|
+
// Fano plane / multiplication
|
|
73
|
+
FANO_LINES,
|
|
74
|
+
octonionMultiplyIndex,
|
|
75
|
+
sedenionMultiplyIndex,
|
|
76
|
+
multiplyIndices,
|
|
77
|
+
buildMultiplicationTable,
|
|
78
|
+
|
|
79
|
+
// Prime utilities
|
|
80
|
+
primeGenerator,
|
|
81
|
+
nthPrime,
|
|
82
|
+
primesUpTo,
|
|
83
|
+
isPrime,
|
|
84
|
+
factorize,
|
|
85
|
+
primeSignature,
|
|
86
|
+
firstNPrimes,
|
|
87
|
+
GaussianInteger,
|
|
88
|
+
EisensteinInteger,
|
|
89
|
+
primeToFrequency,
|
|
90
|
+
primeToAngle,
|
|
91
|
+
sumOfTwoSquares,
|
|
92
|
+
DEFAULT_PRIMES,
|
|
93
|
+
|
|
94
|
+
// LLM client
|
|
95
|
+
LLM,
|
|
96
|
+
|
|
97
|
+
// Prime Hilbert Space (HP)
|
|
98
|
+
Complex,
|
|
99
|
+
PrimeState,
|
|
100
|
+
ResonanceOperators,
|
|
101
|
+
EntropyDrivenEvolution,
|
|
102
|
+
encodeMemory,
|
|
103
|
+
symbolicCompute,
|
|
104
|
+
|
|
105
|
+
// Prime Resonance Network
|
|
106
|
+
PHI,
|
|
107
|
+
PHI_CONJ,
|
|
108
|
+
DELTA_S,
|
|
109
|
+
QuaternionPrime,
|
|
110
|
+
PrimeResonanceIdentity,
|
|
111
|
+
PhaseLockedRing,
|
|
112
|
+
HolographicField,
|
|
113
|
+
EntangledNode,
|
|
114
|
+
ResonantFragment,
|
|
115
|
+
|
|
116
|
+
// ResoFormer ML Primitives
|
|
117
|
+
Quaternion,
|
|
118
|
+
SparsePrimeState,
|
|
119
|
+
resonanceScore,
|
|
120
|
+
resonantAttention,
|
|
121
|
+
hamiltonCompose,
|
|
122
|
+
measureNonCommutativity,
|
|
123
|
+
computeCoherence,
|
|
124
|
+
haltingDecision,
|
|
125
|
+
coherenceGatedCompute,
|
|
126
|
+
EntropyCollapseHead,
|
|
127
|
+
generateAttractorCodebook,
|
|
128
|
+
PRGraphMemory,
|
|
129
|
+
applyResonanceOperator,
|
|
130
|
+
|
|
131
|
+
// TensorFlow.js ResoFormer layers (if available)
|
|
132
|
+
...(rformerTF || {})
|
|
133
|
+
};
|
package/core/llm.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LMStudio LLM Client
|
|
3
|
+
* Calls LMStudio's OpenAI-compatible chat endpoint
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const DEFAULT_URL = 'http://192.168.4.79:1234/v1/chat/completions';
|
|
7
|
+
const DEFAULT_MODEL = 'openai/gpt-oss-20b';
|
|
8
|
+
|
|
9
|
+
let _baseUrl = DEFAULT_URL;
|
|
10
|
+
let _model = DEFAULT_MODEL;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Configure LMStudio connection
|
|
14
|
+
* @param {Object} cfg - Configuration
|
|
15
|
+
* @param {string} cfg.baseUrl - Base URL (default: http://localhost:1234/v1/chat/completions)
|
|
16
|
+
* @param {string} cfg.model - Model name (default: local-model)
|
|
17
|
+
*/
|
|
18
|
+
const configure = (cfg = {}) => {
|
|
19
|
+
if (cfg.baseUrl) _baseUrl = cfg.baseUrl;
|
|
20
|
+
if (cfg.model) _model = cfg.model;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Call LMStudio chat endpoint
|
|
25
|
+
* @param {Array<{role: string, content: string}>} messages - Conversation messages
|
|
26
|
+
* @param {Object} options - Generation options
|
|
27
|
+
* @param {number} options.temperature - Sampling temperature (0-2)
|
|
28
|
+
* @param {Object} options.jsonSchema - JSON schema for structured output
|
|
29
|
+
* @param {number} options.maxTokens - Maximum tokens to generate
|
|
30
|
+
* @returns {Promise<{content: string, usage: Object, raw: Object}>}
|
|
31
|
+
*/
|
|
32
|
+
async function chat(messages, options = {}) {
|
|
33
|
+
const { temperature = 0.7, jsonSchema = null, maxTokens = 1024 } = options;
|
|
34
|
+
|
|
35
|
+
const body = {
|
|
36
|
+
model: _model,
|
|
37
|
+
messages,
|
|
38
|
+
temperature,
|
|
39
|
+
max_tokens: maxTokens,
|
|
40
|
+
stream: false
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Add JSON schema if provided (structured output)
|
|
44
|
+
if (jsonSchema) {
|
|
45
|
+
// Adapt to LMStudio/OpenAI Structured Outputs requirement
|
|
46
|
+
body.response_format = {
|
|
47
|
+
type: 'json_schema',
|
|
48
|
+
json_schema: {
|
|
49
|
+
name: 'response',
|
|
50
|
+
schema: jsonSchema
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const res = await fetch(_baseUrl, {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
headers: { 'Content-Type': 'application/json' },
|
|
58
|
+
body: JSON.stringify(body)
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
const err = await res.text().catch(() => 'Unknown error');
|
|
63
|
+
throw new Error(`LMStudio error (${res.status}): ${err}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const data = await res.json();
|
|
67
|
+
const choice = data.choices?.[0];
|
|
68
|
+
|
|
69
|
+
if (!choice) throw new Error('No response from LMStudio');
|
|
70
|
+
|
|
71
|
+
let content = choice.message?.content || '';
|
|
72
|
+
|
|
73
|
+
// Parse JSON if schema was requested
|
|
74
|
+
if (jsonSchema && content) {
|
|
75
|
+
try {
|
|
76
|
+
content = JSON.parse(content);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
// Return raw string if JSON parse fails
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
content,
|
|
84
|
+
usage: data.usage || {},
|
|
85
|
+
raw: data
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Simple completion helper
|
|
91
|
+
* @param {string} prompt - User prompt
|
|
92
|
+
* @param {Object} options - Generation options
|
|
93
|
+
* @returns {Promise<string>}
|
|
94
|
+
*/
|
|
95
|
+
async function complete(prompt, options = {}) {
|
|
96
|
+
const r = await chat([{ role: 'user', content: prompt }], options);
|
|
97
|
+
return r.content;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* System + user message helper
|
|
102
|
+
* @param {string} system - System prompt
|
|
103
|
+
* @param {string} user - User message
|
|
104
|
+
* @param {Object} options - Generation options
|
|
105
|
+
* @returns {Promise<string>}
|
|
106
|
+
*/
|
|
107
|
+
async function ask(system, user, options = {}) {
|
|
108
|
+
const r = await chat([
|
|
109
|
+
{ role: 'system', content: system },
|
|
110
|
+
{ role: 'user', content: user }
|
|
111
|
+
], options);
|
|
112
|
+
return r.content;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Check if LMStudio is running
|
|
117
|
+
* @returns {Promise<boolean>}
|
|
118
|
+
*/
|
|
119
|
+
async function ping() {
|
|
120
|
+
try {
|
|
121
|
+
const r = await fetch(_baseUrl.replace('/chat/completions', '/models'));
|
|
122
|
+
return r.ok;
|
|
123
|
+
} catch { return false; }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get current configuration
|
|
128
|
+
* @returns {{baseUrl: string, model: string}}
|
|
129
|
+
*/
|
|
130
|
+
const getConfig = () => ({ baseUrl: _baseUrl, model: _model });
|
|
131
|
+
|
|
132
|
+
module.exports = { chat, complete, ask, configure, ping, getConfig };
|
package/core/prime.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prime number utilities for encoding and cryptographic operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Prime generation
|
|
6
|
+
function* primeGenerator(start = 2) {
|
|
7
|
+
let n = start;
|
|
8
|
+
while (true) {
|
|
9
|
+
if (isPrime(n)) yield n;
|
|
10
|
+
n++;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function nthPrime(n) {
|
|
15
|
+
let count = 0, candidate = 2;
|
|
16
|
+
while (count < n) {
|
|
17
|
+
if (isPrime(candidate)) count++;
|
|
18
|
+
if (count < n) candidate++;
|
|
19
|
+
}
|
|
20
|
+
return candidate;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function primesUpTo(max) {
|
|
24
|
+
const sieve = new Array(max + 1).fill(true);
|
|
25
|
+
sieve[0] = sieve[1] = false;
|
|
26
|
+
for (let i = 2; i * i <= max; i++) {
|
|
27
|
+
if (sieve[i]) {
|
|
28
|
+
for (let j = i * i; j <= max; j += i) sieve[j] = false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return sieve.map((v, i) => v ? i : 0).filter(Boolean);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isPrime(n) {
|
|
35
|
+
if (n < 2) return false;
|
|
36
|
+
if (n === 2) return true;
|
|
37
|
+
if (n % 2 === 0) return false;
|
|
38
|
+
for (let i = 3, s = Math.sqrt(n); i <= s; i += 2) {
|
|
39
|
+
if (n % i === 0) return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Factorization
|
|
45
|
+
function factorize(n) {
|
|
46
|
+
const factors = {};
|
|
47
|
+
let d = 2;
|
|
48
|
+
while (n > 1) {
|
|
49
|
+
while (n % d === 0) {
|
|
50
|
+
factors[d] = (factors[d] || 0) + 1;
|
|
51
|
+
n /= d;
|
|
52
|
+
}
|
|
53
|
+
d++;
|
|
54
|
+
if (d * d > n && n > 1) {
|
|
55
|
+
factors[n] = (factors[n] || 0) + 1;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return factors;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function primeSignature(primes) {
|
|
63
|
+
return [...primes].sort((a, b) => a - b).join(',');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Gaussian Integers (Z[i])
|
|
67
|
+
class GaussianInteger {
|
|
68
|
+
constructor(real, imag) {
|
|
69
|
+
this.real = real;
|
|
70
|
+
this.imag = imag;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
norm() { return this.real ** 2 + this.imag ** 2; }
|
|
74
|
+
|
|
75
|
+
add(other) {
|
|
76
|
+
return new GaussianInteger(this.real + other.real, this.imag + other.imag);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
mul(other) {
|
|
80
|
+
return new GaussianInteger(
|
|
81
|
+
this.real * other.real - this.imag * other.imag,
|
|
82
|
+
this.real * other.imag + this.imag * other.real
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
conjugate() {
|
|
87
|
+
return new GaussianInteger(this.real, -this.imag);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
isGaussianPrime() {
|
|
91
|
+
const n = this.norm();
|
|
92
|
+
if (!isPrime(n)) return false;
|
|
93
|
+
// Prime if norm is prime and not split
|
|
94
|
+
return n % 4 === 3 || (this.real !== 0 && this.imag !== 0);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
toString() {
|
|
98
|
+
if (this.imag === 0) return `${this.real}`;
|
|
99
|
+
if (this.real === 0) return `${this.imag}i`;
|
|
100
|
+
const sign = this.imag > 0 ? '+' : '';
|
|
101
|
+
return `${this.real}${sign}${this.imag}i`;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Eisenstein Integers (Z[ω] where ω = e^(2πi/3))
|
|
106
|
+
class EisensteinInteger {
|
|
107
|
+
constructor(a, b) {
|
|
108
|
+
this.a = a; // a + b*ω
|
|
109
|
+
this.b = b;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
norm() { return this.a ** 2 - this.a * this.b + this.b ** 2; }
|
|
113
|
+
|
|
114
|
+
add(other) {
|
|
115
|
+
return new EisensteinInteger(this.a + other.a, this.b + other.b);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
mul(other) {
|
|
119
|
+
return new EisensteinInteger(
|
|
120
|
+
this.a * other.a - this.b * other.b,
|
|
121
|
+
this.a * other.b + this.b * other.a - this.b * other.b
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
conjugate() {
|
|
126
|
+
return new EisensteinInteger(this.a - this.b, -this.b);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
isEisensteinPrime() {
|
|
130
|
+
const n = this.norm();
|
|
131
|
+
return isPrime(n) && n % 3 === 2;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
toString() {
|
|
135
|
+
if (this.b === 0) return `${this.a}`;
|
|
136
|
+
if (this.a === 0) return `${this.b}ω`;
|
|
137
|
+
const sign = this.b > 0 ? '+' : '';
|
|
138
|
+
return `${this.a}${sign}${this.b}ω`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Prime-to-angle mapping (PRSC formula)
|
|
143
|
+
function primeToFrequency(p, base = 1, logScale = 10) {
|
|
144
|
+
return base + Math.log(p) / logScale;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function primeToAngle(p) {
|
|
148
|
+
return (360 / p) * (Math.PI / 180);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Sum of two squares representation (for p ≡ 1 mod 4)
|
|
152
|
+
function sumOfTwoSquares(p) {
|
|
153
|
+
if (p === 2) return [1, 1];
|
|
154
|
+
if (p % 4 !== 1) return null;
|
|
155
|
+
|
|
156
|
+
for (let a = 1; a * a <= p; a++) {
|
|
157
|
+
const b2 = p - a * a;
|
|
158
|
+
const b = Math.sqrt(b2);
|
|
159
|
+
if (b === Math.floor(b)) return [a, b];
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Generate first N primes
|
|
165
|
+
function firstNPrimes(n) {
|
|
166
|
+
const primes = [];
|
|
167
|
+
let candidate = 2;
|
|
168
|
+
while (primes.length < n) {
|
|
169
|
+
if (isPrime(candidate)) primes.push(candidate);
|
|
170
|
+
candidate++;
|
|
171
|
+
}
|
|
172
|
+
return primes;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Default prime list (first 100 primes)
|
|
176
|
+
const DEFAULT_PRIMES = firstNPrimes(100);
|
|
177
|
+
|
|
178
|
+
module.exports = {
|
|
179
|
+
primeGenerator, nthPrime, primesUpTo, isPrime,
|
|
180
|
+
factorize, primeSignature, firstNPrimes,
|
|
181
|
+
GaussianInteger, EisensteinInteger,
|
|
182
|
+
primeToFrequency, primeToAngle, sumOfTwoSquares,
|
|
183
|
+
DEFAULT_PRIMES
|
|
184
|
+
};
|