@terminals-tech/sdk 1.0.0-rc.1 → 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/README.md +15 -19
- package/dist/WebContainerManager-4LIOGRVM.js +22 -0
- package/dist/browser-http-client-ZQLDWZMU.js +317 -0
- package/dist/cache-VKYSQRXX.js +45 -0
- package/dist/capabilities-MIPUMBLL.js +96 -0
- package/dist/chunk-2ESYSVXG.js +48 -0
- package/dist/chunk-2WTYE4SW.js +190 -0
- package/dist/chunk-3LFMIVJM.js +40 -0
- package/dist/chunk-ABCK4FWN.js +136 -0
- package/dist/chunk-AFDUOYHD.js +2060 -0
- package/dist/chunk-BCOQMFKT.js +265 -0
- package/dist/chunk-BYXBJQAS.js +0 -0
- package/dist/chunk-DKFJIILR.js +9798 -0
- package/dist/chunk-EXI3LJVJ.js +51 -0
- package/dist/chunk-FOXUEYWK.js +42 -0
- package/dist/chunk-GJWAJAX3.js +173 -0
- package/dist/chunk-H3POJCFA.js +333 -0
- package/dist/chunk-KASHT6C5.js +784 -0
- package/dist/chunk-KHR7ZYCX.js +4034 -0
- package/dist/chunk-L45BSQDJ.js +296 -0
- package/dist/chunk-LLGZTP3G.js +5521 -0
- package/dist/chunk-NTMBOESX.js +152 -0
- package/dist/chunk-OCLSAUCD.js +474 -0
- package/dist/chunk-OSSRZOGC.js +190 -0
- package/dist/chunk-PPFTKJDB.js +497 -0
- package/dist/chunk-PWAHFID5.js +381 -0
- package/dist/chunk-Q2VI6ICE.js +188 -0
- package/dist/chunk-QJFKEQHF.js +6460 -0
- package/dist/chunk-QWXPVB2L.js +320 -0
- package/dist/chunk-QWZRZKLZ.js +896 -0
- package/dist/chunk-STMI72WH.js +1005 -0
- package/dist/chunk-TSQ3BGLA.js +11945 -0
- package/dist/chunk-UJDUQNE2.js +79 -0
- package/dist/chunk-VZA2NUH3.js +118 -0
- package/dist/chunk-WGBCRNMB.js +1817 -0
- package/dist/chunk-WU4OTGJE.js +752 -0
- package/dist/chunk-XPJ63Y6T.js +70 -0
- package/dist/chunk-Y2EULKA2.js +172 -0
- package/dist/chunk-YJEZWCYV.js +94 -0
- package/dist/chunk-ZVO47SQV.js +150 -0
- package/dist/container-lite-QD3CRLS4.js +327 -0
- package/dist/core-H2UUDATO.js +146 -0
- package/dist/crypto-D4LMI2RN.js +45 -0
- package/dist/db-BWC2GGBN.js +50 -0
- package/dist/demo-T655Z5S4.js +87 -0
- package/dist/diagnostics-6RQTBR6I.js +113 -0
- package/dist/dist-OPDCWARF.js +727 -0
- package/dist/dist-VXJEKX3T.js +2441 -0
- package/dist/dist-VYGJXGUS.js +1008 -0
- package/dist/embeddings-7QXTXUMC.js +15 -0
- package/dist/embeddings-MAEWWUHW.js +9 -0
- package/dist/graph-RKMNE2X5.js +36 -0
- package/dist/hvm-CBEP3M4F.js +126 -0
- package/dist/index.cjs +49874 -8001
- package/dist/index.d.cts +1629 -1363
- package/dist/index.d.ts +1629 -1363
- package/dist/index.js +2462 -8130
- package/dist/mcp-NK34ZNM5.js +101 -0
- package/dist/mcp-client-service-browser-SGB2K3VZ.js +14 -0
- package/dist/neuro-state-XHRGIRVO.js +498 -0
- package/dist/nodes-K6GKI2FM.js +364 -0
- package/dist/package-EXUIU2RL.js +93 -0
- package/dist/package-VGL7HYTO.js +106 -0
- package/dist/package-XHMLOAQ4.js +98 -0
- package/dist/pg-events-QJAM2HIP.js +15 -0
- package/dist/pglite-adapter-43IOUBMV.js +50 -0
- package/dist/pgliteService-IUGNNOVU.js +258 -0
- package/dist/policy-IRJCM6FS.js +13 -0
- package/dist/registry-5WTDYQVQ.js +26 -0
- package/dist/registry-FW63E7FE.js +16 -0
- package/dist/registry-ZQ2IBLF6.js +9 -0
- package/dist/resolver-ALOJSOK5.js +24 -0
- package/dist/scheduler-B5CEYKWT.js +127 -0
- package/dist/secret-store-H7273UIT.js +18 -0
- package/dist/server-VW6DYDLH.js +18 -0
- package/dist/skills-VN7IN7SJ.js +6375 -0
- package/dist/stack-4KWCQQP7.js +103 -0
- package/dist/storage-L7MWNSPG.js +13 -0
- package/dist/supabaseService-6AYP2VY3.js +476 -0
- package/dist/topology-CIWWNVAN.js +13 -0
- package/dist/webcontainer-XWCE56F3.js +281 -0
- package/package.json +9 -3
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
// ../../lib/terminals-tech/core/primitives/result.ts
|
|
2
|
+
function ok(value, meta) {
|
|
3
|
+
return { ok: true, value, meta };
|
|
4
|
+
}
|
|
5
|
+
function err(error, meta) {
|
|
6
|
+
return { ok: false, error, meta };
|
|
7
|
+
}
|
|
8
|
+
function isOk(result) {
|
|
9
|
+
return result.ok === true;
|
|
10
|
+
}
|
|
11
|
+
function isErr(result) {
|
|
12
|
+
return result.ok === false;
|
|
13
|
+
}
|
|
14
|
+
function map(result, fn) {
|
|
15
|
+
if (isOk(result)) {
|
|
16
|
+
return ok(fn(result.value), result.meta);
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
function flatMap(result, fn) {
|
|
21
|
+
if (isOk(result)) {
|
|
22
|
+
return fn(result.value);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ../../lib/terminals-tech/core/primitives/registry.ts
|
|
28
|
+
var BasicRegistry = class {
|
|
29
|
+
store;
|
|
30
|
+
config;
|
|
31
|
+
constructor(config = {}) {
|
|
32
|
+
this.store = /* @__PURE__ */ new Map();
|
|
33
|
+
this.config = config;
|
|
34
|
+
}
|
|
35
|
+
get(key) {
|
|
36
|
+
const entry = this.store.get(key);
|
|
37
|
+
if (!entry) return void 0;
|
|
38
|
+
if (this.config.ttlMs && this.isTTLEntry(entry)) {
|
|
39
|
+
if (Date.now() > entry.expiresAt) {
|
|
40
|
+
this.store.delete(key);
|
|
41
|
+
this.config.onExpire?.(key, entry.value);
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
return entry.value;
|
|
45
|
+
}
|
|
46
|
+
return entry;
|
|
47
|
+
}
|
|
48
|
+
set(key, value) {
|
|
49
|
+
const entry = this.config.ttlMs ? { value, expiresAt: Date.now() + this.config.ttlMs } : value;
|
|
50
|
+
this.store.set(key, entry);
|
|
51
|
+
if (this.config.maxSize && this.store.size > this.config.maxSize) {
|
|
52
|
+
const firstKey = this.store.keys().next().value;
|
|
53
|
+
if (firstKey !== void 0) {
|
|
54
|
+
const firstValue = this.store.get(firstKey);
|
|
55
|
+
this.store.delete(firstKey);
|
|
56
|
+
if (firstValue) {
|
|
57
|
+
const val = this.isTTLEntry(firstValue) ? firstValue.value : firstValue;
|
|
58
|
+
this.config.onEvict?.(firstKey, val);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
has(key) {
|
|
64
|
+
return this.get(key) !== void 0;
|
|
65
|
+
}
|
|
66
|
+
delete(key) {
|
|
67
|
+
return this.store.delete(key);
|
|
68
|
+
}
|
|
69
|
+
clear() {
|
|
70
|
+
this.store.clear();
|
|
71
|
+
}
|
|
72
|
+
size() {
|
|
73
|
+
this.pruneExpired();
|
|
74
|
+
return this.store.size;
|
|
75
|
+
}
|
|
76
|
+
keys() {
|
|
77
|
+
this.pruneExpired();
|
|
78
|
+
return this.store.keys();
|
|
79
|
+
}
|
|
80
|
+
values() {
|
|
81
|
+
this.pruneExpired();
|
|
82
|
+
const storeValues = Array.from(this.store.values());
|
|
83
|
+
const isTTLEntry = this.isTTLEntry.bind(this);
|
|
84
|
+
return (function* () {
|
|
85
|
+
for (const entry of storeValues) {
|
|
86
|
+
if (isTTLEntry(entry)) {
|
|
87
|
+
yield entry.value;
|
|
88
|
+
} else {
|
|
89
|
+
yield entry;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
})();
|
|
93
|
+
}
|
|
94
|
+
entries() {
|
|
95
|
+
this.pruneExpired();
|
|
96
|
+
const storeEntries = Array.from(this.store.entries());
|
|
97
|
+
const isTTLEntry = this.isTTLEntry.bind(this);
|
|
98
|
+
return (function* () {
|
|
99
|
+
for (const [key, entry] of storeEntries) {
|
|
100
|
+
const value = isTTLEntry(entry) ? entry.value : entry;
|
|
101
|
+
yield [key, value];
|
|
102
|
+
}
|
|
103
|
+
})();
|
|
104
|
+
}
|
|
105
|
+
toArray() {
|
|
106
|
+
return Array.from(this.values());
|
|
107
|
+
}
|
|
108
|
+
isTTLEntry(entry) {
|
|
109
|
+
return typeof entry === "object" && entry !== null && "value" in entry && "expiresAt" in entry && typeof entry.expiresAt === "number";
|
|
110
|
+
}
|
|
111
|
+
pruneExpired() {
|
|
112
|
+
if (!this.config.ttlMs) return;
|
|
113
|
+
const now = Date.now();
|
|
114
|
+
const toDelete = [];
|
|
115
|
+
const entries = Array.from(this.store.entries());
|
|
116
|
+
for (const [key, entry] of entries) {
|
|
117
|
+
if (this.isTTLEntry(entry) && now > entry.expiresAt) {
|
|
118
|
+
toDelete.push(key);
|
|
119
|
+
this.config.onExpire?.(key, entry.value);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const key of toDelete) {
|
|
123
|
+
this.store.delete(key);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
function createRegistry(config) {
|
|
128
|
+
return new BasicRegistry(config);
|
|
129
|
+
}
|
|
130
|
+
var GlobalRegistryNamespace = class {
|
|
131
|
+
namespaces = /* @__PURE__ */ new Map();
|
|
132
|
+
get(namespace) {
|
|
133
|
+
let registry = this.namespaces.get(namespace);
|
|
134
|
+
if (!registry) {
|
|
135
|
+
registry = createRegistry();
|
|
136
|
+
this.namespaces.set(namespace, registry);
|
|
137
|
+
}
|
|
138
|
+
return registry;
|
|
139
|
+
}
|
|
140
|
+
create(namespace, config) {
|
|
141
|
+
const registry = createRegistry(config);
|
|
142
|
+
this.namespaces.set(namespace, registry);
|
|
143
|
+
return registry;
|
|
144
|
+
}
|
|
145
|
+
clear(namespace) {
|
|
146
|
+
if (namespace) {
|
|
147
|
+
this.namespaces.get(namespace)?.clear();
|
|
148
|
+
} else {
|
|
149
|
+
const registryValues = Array.from(this.namespaces.values());
|
|
150
|
+
for (const registry of registryValues) {
|
|
151
|
+
registry.clear();
|
|
152
|
+
}
|
|
153
|
+
this.namespaces.clear();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var registries = new GlobalRegistryNamespace();
|
|
158
|
+
|
|
159
|
+
// ../../lib/terminals-tech/core/primitives/dag.ts
|
|
160
|
+
var DAGValidationError = class extends Error {
|
|
161
|
+
constructor(message, type) {
|
|
162
|
+
super(message);
|
|
163
|
+
this.type = type;
|
|
164
|
+
this.name = "DAGValidationError";
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var DAGImpl = class {
|
|
168
|
+
nodes;
|
|
169
|
+
edges;
|
|
170
|
+
// Adjacency lists for O(1) neighbor lookup
|
|
171
|
+
incoming;
|
|
172
|
+
outgoing;
|
|
173
|
+
constructor(nodes, edges) {
|
|
174
|
+
this.nodes = nodes;
|
|
175
|
+
this.edges = edges;
|
|
176
|
+
this.incoming = /* @__PURE__ */ new Map();
|
|
177
|
+
this.outgoing = /* @__PURE__ */ new Map();
|
|
178
|
+
const nodeKeys = Array.from(nodes.keys());
|
|
179
|
+
for (const node of nodeKeys) {
|
|
180
|
+
this.incoming.set(node, []);
|
|
181
|
+
this.outgoing.set(node, []);
|
|
182
|
+
}
|
|
183
|
+
for (const edge of edges) {
|
|
184
|
+
this.incoming.get(edge.to)?.push(edge);
|
|
185
|
+
this.outgoing.get(edge.from)?.push(edge);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
getNode(id) {
|
|
189
|
+
return this.nodes.get(id);
|
|
190
|
+
}
|
|
191
|
+
getIncoming(nodeId) {
|
|
192
|
+
return this.incoming.get(nodeId) ?? [];
|
|
193
|
+
}
|
|
194
|
+
getOutgoing(nodeId) {
|
|
195
|
+
return this.outgoing.get(nodeId) ?? [];
|
|
196
|
+
}
|
|
197
|
+
getAncestors(nodeId) {
|
|
198
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
199
|
+
const queue = [nodeId];
|
|
200
|
+
while (queue.length > 0) {
|
|
201
|
+
const current = queue.shift();
|
|
202
|
+
if (!current) continue;
|
|
203
|
+
const incoming = this.getIncoming(current);
|
|
204
|
+
for (const edge of incoming) {
|
|
205
|
+
if (!ancestors.has(edge.from)) {
|
|
206
|
+
ancestors.add(edge.from);
|
|
207
|
+
queue.push(edge.from);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return Array.from(ancestors);
|
|
212
|
+
}
|
|
213
|
+
getDescendants(nodeId) {
|
|
214
|
+
const descendants = /* @__PURE__ */ new Set();
|
|
215
|
+
const queue = [nodeId];
|
|
216
|
+
while (queue.length > 0) {
|
|
217
|
+
const current = queue.shift();
|
|
218
|
+
if (!current) continue;
|
|
219
|
+
const outgoing = this.getOutgoing(current);
|
|
220
|
+
for (const edge of outgoing) {
|
|
221
|
+
if (!descendants.has(edge.to)) {
|
|
222
|
+
descendants.add(edge.to);
|
|
223
|
+
queue.push(edge.to);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return Array.from(descendants);
|
|
228
|
+
}
|
|
229
|
+
getRoots() {
|
|
230
|
+
return Array.from(this.nodes.keys()).filter((id) => this.getIncoming(id).length === 0);
|
|
231
|
+
}
|
|
232
|
+
getLeaves() {
|
|
233
|
+
return Array.from(this.nodes.keys()).filter((id) => this.getOutgoing(id).length === 0);
|
|
234
|
+
}
|
|
235
|
+
topologicalSort() {
|
|
236
|
+
const result = [];
|
|
237
|
+
const inDegree = /* @__PURE__ */ new Map();
|
|
238
|
+
const nodeIds = Array.from(this.nodes.keys());
|
|
239
|
+
for (const id of nodeIds) {
|
|
240
|
+
inDegree.set(id, this.getIncoming(id).length);
|
|
241
|
+
}
|
|
242
|
+
const queue = [];
|
|
243
|
+
const inDegreeEntries = Array.from(inDegree.entries());
|
|
244
|
+
for (const [id, degree] of inDegreeEntries) {
|
|
245
|
+
if (degree === 0) {
|
|
246
|
+
queue.push(id);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
while (queue.length > 0) {
|
|
250
|
+
const current = queue.shift();
|
|
251
|
+
if (!current) continue;
|
|
252
|
+
result.push(current);
|
|
253
|
+
for (const edge of this.getOutgoing(current)) {
|
|
254
|
+
const degree = inDegree.get(edge.to);
|
|
255
|
+
if (degree === void 0) continue;
|
|
256
|
+
const newDegree = degree - 1;
|
|
257
|
+
inDegree.set(edge.to, newDegree);
|
|
258
|
+
if (newDegree === 0) {
|
|
259
|
+
queue.push(edge.to);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (result.length !== this.nodes.size) {
|
|
264
|
+
throw new DAGValidationError("Cannot sort: graph contains cycles", "cycle");
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
levels() {
|
|
269
|
+
const levels = [];
|
|
270
|
+
const inDegree = /* @__PURE__ */ new Map();
|
|
271
|
+
const nodeIds = Array.from(this.nodes.keys());
|
|
272
|
+
for (const id of nodeIds) {
|
|
273
|
+
inDegree.set(id, this.getIncoming(id).length);
|
|
274
|
+
}
|
|
275
|
+
let currentLevel = [];
|
|
276
|
+
const inDegreeEntries = Array.from(inDegree.entries());
|
|
277
|
+
for (const [id, degree] of inDegreeEntries) {
|
|
278
|
+
if (degree === 0) {
|
|
279
|
+
currentLevel.push(id);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
while (currentLevel.length > 0) {
|
|
283
|
+
levels.push(currentLevel);
|
|
284
|
+
const nextLevel = [];
|
|
285
|
+
for (const nodeId of currentLevel) {
|
|
286
|
+
for (const edge of this.getOutgoing(nodeId)) {
|
|
287
|
+
const degree = inDegree.get(edge.to);
|
|
288
|
+
if (degree === void 0) continue;
|
|
289
|
+
const newDegree = degree - 1;
|
|
290
|
+
inDegree.set(edge.to, newDegree);
|
|
291
|
+
if (newDegree === 0) {
|
|
292
|
+
nextLevel.push(edge.to);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
currentLevel = nextLevel;
|
|
297
|
+
}
|
|
298
|
+
return levels;
|
|
299
|
+
}
|
|
300
|
+
bfs(startId, visitor) {
|
|
301
|
+
const visited = /* @__PURE__ */ new Set();
|
|
302
|
+
const queue = [startId];
|
|
303
|
+
while (queue.length > 0) {
|
|
304
|
+
const current = queue.shift();
|
|
305
|
+
if (!current) continue;
|
|
306
|
+
if (visited.has(current)) continue;
|
|
307
|
+
visited.add(current);
|
|
308
|
+
const node = this.nodes.get(current);
|
|
309
|
+
if (!node) continue;
|
|
310
|
+
const shouldStop = visitor(node);
|
|
311
|
+
if (shouldStop === true) return;
|
|
312
|
+
for (const edge of this.getOutgoing(current)) {
|
|
313
|
+
if (!visited.has(edge.to)) {
|
|
314
|
+
queue.push(edge.to);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
dfs(startId, visitor) {
|
|
320
|
+
const visited = /* @__PURE__ */ new Set();
|
|
321
|
+
const visit = (nodeId) => {
|
|
322
|
+
if (visited.has(nodeId)) return false;
|
|
323
|
+
visited.add(nodeId);
|
|
324
|
+
const node = this.nodes.get(nodeId);
|
|
325
|
+
if (!node) return false;
|
|
326
|
+
const shouldStop = visitor(node);
|
|
327
|
+
if (shouldStop === true) return true;
|
|
328
|
+
for (const edge of this.getOutgoing(nodeId)) {
|
|
329
|
+
if (visit(edge.to)) return true;
|
|
330
|
+
}
|
|
331
|
+
return false;
|
|
332
|
+
};
|
|
333
|
+
visit(startId);
|
|
334
|
+
}
|
|
335
|
+
hasCycle() {
|
|
336
|
+
const WHITE = 0;
|
|
337
|
+
const GRAY = 1;
|
|
338
|
+
const BLACK = 2;
|
|
339
|
+
const colors = /* @__PURE__ */ new Map();
|
|
340
|
+
const nodeIds = Array.from(this.nodes.keys());
|
|
341
|
+
for (const id of nodeIds) {
|
|
342
|
+
colors.set(id, WHITE);
|
|
343
|
+
}
|
|
344
|
+
const hasCycleUtil = (nodeId) => {
|
|
345
|
+
colors.set(nodeId, GRAY);
|
|
346
|
+
for (const edge of this.getOutgoing(nodeId)) {
|
|
347
|
+
const color = colors.get(edge.to);
|
|
348
|
+
if (color === GRAY) {
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
if (color === WHITE && hasCycleUtil(edge.to)) {
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
colors.set(nodeId, BLACK);
|
|
356
|
+
return false;
|
|
357
|
+
};
|
|
358
|
+
const allNodeIds = Array.from(this.nodes.keys());
|
|
359
|
+
for (const id of allNodeIds) {
|
|
360
|
+
if (colors.get(id) === WHITE) {
|
|
361
|
+
if (hasCycleUtil(id)) {
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
validate() {
|
|
369
|
+
const errors = [];
|
|
370
|
+
if (this.hasCycle()) {
|
|
371
|
+
errors.push(new DAGValidationError("Graph contains cycles", "cycle"));
|
|
372
|
+
}
|
|
373
|
+
for (const edge of this.edges) {
|
|
374
|
+
if (!this.nodes.has(edge.from)) {
|
|
375
|
+
errors.push(
|
|
376
|
+
new DAGValidationError(`Edge references missing node: ${edge.from}`, "missing_node")
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
if (!this.nodes.has(edge.to)) {
|
|
380
|
+
errors.push(
|
|
381
|
+
new DAGValidationError(`Edge references missing node: ${edge.to}`, "missing_node")
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
for (const edge of this.edges) {
|
|
386
|
+
if (edge.from === edge.to) {
|
|
387
|
+
errors.push(
|
|
388
|
+
new DAGValidationError(`Self-loop detected: ${edge.from} -> ${edge.to}`, "self_loop")
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (errors.length > 0) {
|
|
393
|
+
return { ok: false, error: errors };
|
|
394
|
+
}
|
|
395
|
+
return { ok: true, value: void 0 };
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
function createDAG(nodes, edges) {
|
|
399
|
+
const errors = [];
|
|
400
|
+
const nodeIds = /* @__PURE__ */ new Set();
|
|
401
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
402
|
+
for (const node of nodes) {
|
|
403
|
+
if (nodeIds.has(node.id)) {
|
|
404
|
+
errors.push(new DAGValidationError(`Duplicate node ID: ${node.id}`, "duplicate_node"));
|
|
405
|
+
} else {
|
|
406
|
+
nodeIds.add(node.id);
|
|
407
|
+
nodeMap.set(node.id, node);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (errors.length > 0) {
|
|
411
|
+
return { ok: false, error: errors };
|
|
412
|
+
}
|
|
413
|
+
const dag = new DAGImpl(nodeMap, edges);
|
|
414
|
+
const validationResult = dag.validate();
|
|
415
|
+
if (validationResult.ok === false) {
|
|
416
|
+
return { ok: false, error: validationResult.error };
|
|
417
|
+
}
|
|
418
|
+
return { ok: true, value: dag };
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// ../../lib/terminals-tech/core/primitives/iq.ts
|
|
422
|
+
function assertSameLength(a, b) {
|
|
423
|
+
if (a.length !== b.length) {
|
|
424
|
+
throw new Error(`I/Q length mismatch: ${a.length} vs ${b.length}`);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
function l2NormSquared(v) {
|
|
428
|
+
let s = 0;
|
|
429
|
+
for (let i = 0; i < v.length; i++) s += v[i] * v[i];
|
|
430
|
+
return s;
|
|
431
|
+
}
|
|
432
|
+
function dot(a, b) {
|
|
433
|
+
const n = Math.min(a.length, b.length);
|
|
434
|
+
let s = 0;
|
|
435
|
+
for (let i = 0; i < n; i++) s += a[i] * b[i];
|
|
436
|
+
return s;
|
|
437
|
+
}
|
|
438
|
+
function _private_seedFromVector(v) {
|
|
439
|
+
const n = v.length;
|
|
440
|
+
const seed = new Float32Array(n);
|
|
441
|
+
if (n === 0) return seed;
|
|
442
|
+
for (let i = 0; i < n; i++) {
|
|
443
|
+
const j = (i + 1) % n;
|
|
444
|
+
const sign = i % 2 === 0 ? 1 : -1;
|
|
445
|
+
seed[i] = sign * v[j];
|
|
446
|
+
}
|
|
447
|
+
return seed;
|
|
448
|
+
}
|
|
449
|
+
function _private_orthogonalize(seed, against) {
|
|
450
|
+
const denom = l2NormSquared(against);
|
|
451
|
+
if (denom <= 0) return seed;
|
|
452
|
+
const proj = dot(seed, against) / denom;
|
|
453
|
+
const q = new Float32Array(seed.length);
|
|
454
|
+
for (let i = 0; i < seed.length; i++) q[i] = seed[i] - proj * against[i];
|
|
455
|
+
return q;
|
|
456
|
+
}
|
|
457
|
+
function _private_fallbackOrthogonalVector(against) {
|
|
458
|
+
const n = against.length;
|
|
459
|
+
const denom = l2NormSquared(against);
|
|
460
|
+
if (denom <= 0) {
|
|
461
|
+
const q = new Float32Array(n);
|
|
462
|
+
if (n > 0) q[0] = 1;
|
|
463
|
+
return q;
|
|
464
|
+
}
|
|
465
|
+
for (let k = 0; k < n; k++) {
|
|
466
|
+
const seed = new Float32Array(n);
|
|
467
|
+
seed[k] = 1;
|
|
468
|
+
const q = _private_orthogonalize(seed, against);
|
|
469
|
+
const q2 = l2NormSquared(q);
|
|
470
|
+
if (q2 > 1e-12) return q;
|
|
471
|
+
}
|
|
472
|
+
return new Float32Array(n);
|
|
473
|
+
}
|
|
474
|
+
function toIQ(v, opts = {}) {
|
|
475
|
+
const mode = opts.mode ?? "orthogonalTransform";
|
|
476
|
+
if (mode === "dualEncoder") {
|
|
477
|
+
throw new Error("IQ mode 'dualEncoder' is reserved for future explicit I/Q encoders");
|
|
478
|
+
}
|
|
479
|
+
const inPhase = v instanceof Float32Array ? new Float32Array(v) : new Float32Array(v);
|
|
480
|
+
const seed = _private_seedFromVector(inPhase);
|
|
481
|
+
let quadrature = _private_orthogonalize(seed, inPhase);
|
|
482
|
+
if (l2NormSquared(quadrature) <= 1e-12) {
|
|
483
|
+
quadrature = _private_fallbackOrthogonalVector(inPhase);
|
|
484
|
+
}
|
|
485
|
+
if (opts.normalizePair) {
|
|
486
|
+
const total2 = l2NormSquared(inPhase) + l2NormSquared(quadrature);
|
|
487
|
+
if (total2 > 0) {
|
|
488
|
+
const inv = 1 / Math.sqrt(total2);
|
|
489
|
+
for (let i = 0; i < inPhase.length; i++) inPhase[i] *= inv;
|
|
490
|
+
for (let i = 0; i < quadrature.length; i++) quadrature[i] *= inv;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return { inPhase, quadrature };
|
|
494
|
+
}
|
|
495
|
+
function phase(iq) {
|
|
496
|
+
assertSameLength(iq.inPhase, iq.quadrature);
|
|
497
|
+
const out = new Float32Array(iq.inPhase.length);
|
|
498
|
+
for (let i = 0; i < out.length; i++) {
|
|
499
|
+
out[i] = Math.atan2(iq.quadrature[i], iq.inPhase[i]);
|
|
500
|
+
}
|
|
501
|
+
return out;
|
|
502
|
+
}
|
|
503
|
+
function phaseShift(iq, delta) {
|
|
504
|
+
assertSameLength(iq.inPhase, iq.quadrature);
|
|
505
|
+
const c = Math.cos(delta);
|
|
506
|
+
const s = Math.sin(delta);
|
|
507
|
+
const I2 = new Float32Array(iq.inPhase.length);
|
|
508
|
+
const Q2 = new Float32Array(iq.quadrature.length);
|
|
509
|
+
for (let i = 0; i < iq.inPhase.length; i++) {
|
|
510
|
+
const I = iq.inPhase[i];
|
|
511
|
+
const Q = iq.quadrature[i];
|
|
512
|
+
I2[i] = I * c - Q * s;
|
|
513
|
+
Q2[i] = I * s + Q * c;
|
|
514
|
+
}
|
|
515
|
+
return { inPhase: I2, quadrature: Q2 };
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// ../../lib/terminals-tech/core/primitives/phase.ts
|
|
519
|
+
function wrapTo2Pi(theta) {
|
|
520
|
+
const twoPi = Math.PI * 2;
|
|
521
|
+
let t = theta % twoPi;
|
|
522
|
+
if (t < 0) t += twoPi;
|
|
523
|
+
return t;
|
|
524
|
+
}
|
|
525
|
+
function wrapToPi(theta) {
|
|
526
|
+
const twoPi = Math.PI * 2;
|
|
527
|
+
let t = (theta + Math.PI) % twoPi;
|
|
528
|
+
if (t < 0) t += twoPi;
|
|
529
|
+
return t - Math.PI;
|
|
530
|
+
}
|
|
531
|
+
function orderParameter(phases) {
|
|
532
|
+
const n = phases.length;
|
|
533
|
+
if (n === 0) return { R: 0, psi: 0 };
|
|
534
|
+
let c = 0;
|
|
535
|
+
let s = 0;
|
|
536
|
+
for (let i = 0; i < n; i++) {
|
|
537
|
+
const t = phases[i];
|
|
538
|
+
c += Math.cos(t);
|
|
539
|
+
s += Math.sin(t);
|
|
540
|
+
}
|
|
541
|
+
c /= n;
|
|
542
|
+
s /= n;
|
|
543
|
+
return { R: Math.hypot(c, s), psi: Math.atan2(s, c) };
|
|
544
|
+
}
|
|
545
|
+
function phaseLockingValue(phiA, phiB) {
|
|
546
|
+
if (phiA.length !== phiB.length) {
|
|
547
|
+
throw new Error(`PLV length mismatch: ${phiA.length} vs ${phiB.length}`);
|
|
548
|
+
}
|
|
549
|
+
const n = phiA.length;
|
|
550
|
+
if (n === 0) return 0;
|
|
551
|
+
let c = 0;
|
|
552
|
+
let s = 0;
|
|
553
|
+
for (let i = 0; i < n; i++) {
|
|
554
|
+
const d = phiA[i] - phiB[i];
|
|
555
|
+
c += Math.cos(d);
|
|
556
|
+
s += Math.sin(d);
|
|
557
|
+
}
|
|
558
|
+
c /= n;
|
|
559
|
+
s /= n;
|
|
560
|
+
return Math.hypot(c, s);
|
|
561
|
+
}
|
|
562
|
+
function kuramotoStep(phases, omega, K, adjacency, dt, opts = {}) {
|
|
563
|
+
const n = phases.length;
|
|
564
|
+
const wrap = opts.wrap ?? true;
|
|
565
|
+
const normalizeCoupling = opts.normalizeCoupling ?? true;
|
|
566
|
+
const next = new Float32Array(n);
|
|
567
|
+
const omegaIsScalar = typeof omega === "number";
|
|
568
|
+
if (!omegaIsScalar && omega.length !== n) {
|
|
569
|
+
throw new Error(
|
|
570
|
+
`omega length mismatch: expected ${n}, got ${omega.length}`
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
for (let i = 0; i < n; i++) {
|
|
574
|
+
const thetaI = phases[i];
|
|
575
|
+
const wI = omegaIsScalar ? omega : omega[i];
|
|
576
|
+
let couplingSum = 0;
|
|
577
|
+
let degree = 0;
|
|
578
|
+
if (adjacency) {
|
|
579
|
+
const row = adjacency[i];
|
|
580
|
+
if (!row || row.length !== n) {
|
|
581
|
+
throw new Error(`adjacency row ${i} length mismatch`);
|
|
582
|
+
}
|
|
583
|
+
for (let j = 0; j < n; j++) {
|
|
584
|
+
if (j === i) continue;
|
|
585
|
+
const aij = row[j] ?? 0;
|
|
586
|
+
if (!aij) continue;
|
|
587
|
+
couplingSum += aij * Math.sin(phases[j] - thetaI);
|
|
588
|
+
degree += normalizeCoupling ? Math.abs(aij) : 1;
|
|
589
|
+
}
|
|
590
|
+
} else {
|
|
591
|
+
for (let j = 0; j < n; j++) {
|
|
592
|
+
if (j === i) continue;
|
|
593
|
+
couplingSum += Math.sin(phases[j] - thetaI);
|
|
594
|
+
}
|
|
595
|
+
degree = Math.max(1, n - 1);
|
|
596
|
+
}
|
|
597
|
+
const coupling = degree > 0 ? K / degree * couplingSum : 0;
|
|
598
|
+
const dtheta = wI + coupling;
|
|
599
|
+
const thetaNext = thetaI + dtheta * dt;
|
|
600
|
+
next[i] = wrap ? wrapToPi(thetaNext) : thetaNext;
|
|
601
|
+
}
|
|
602
|
+
return next;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// ../../lib/terminals-tech/geometry/hyperbolic.ts
|
|
606
|
+
function hyperbolicDistance(u, v) {
|
|
607
|
+
let uMagSq = 0;
|
|
608
|
+
let vMagSq = 0;
|
|
609
|
+
let diffSq = 0;
|
|
610
|
+
const len = Math.min(u.length, v.length);
|
|
611
|
+
for (let i = 0; i < len; i++) {
|
|
612
|
+
const ui = u[i];
|
|
613
|
+
const vi = v[i];
|
|
614
|
+
uMagSq += ui * ui;
|
|
615
|
+
vMagSq += vi * vi;
|
|
616
|
+
const d = ui - vi;
|
|
617
|
+
diffSq += d * d;
|
|
618
|
+
}
|
|
619
|
+
const safeUMagSq = Math.min(uMagSq, 0.9999);
|
|
620
|
+
const safeVMagSq = Math.min(vMagSq, 0.9999);
|
|
621
|
+
const numerator = 2 * diffSq;
|
|
622
|
+
const denominator = (1 - safeUMagSq) * (1 - safeVMagSq);
|
|
623
|
+
return Math.acosh(1 + numerator / denominator);
|
|
624
|
+
}
|
|
625
|
+
function hyperbolicResonance(u, v) {
|
|
626
|
+
const dist = hyperbolicDistance(u, v);
|
|
627
|
+
return Math.exp(-dist);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// ../../lib/terminals-tech/core/primitives/vector.ts
|
|
631
|
+
function cosineSimilarityAny(a, b) {
|
|
632
|
+
const n = Math.min(a.length, b.length);
|
|
633
|
+
let dot2 = 0;
|
|
634
|
+
let na = 0;
|
|
635
|
+
let nb = 0;
|
|
636
|
+
for (let i = 0; i < n; i++) {
|
|
637
|
+
const ai = a[i];
|
|
638
|
+
const bi = b[i];
|
|
639
|
+
dot2 += ai * bi;
|
|
640
|
+
na += ai * ai;
|
|
641
|
+
nb += bi * bi;
|
|
642
|
+
}
|
|
643
|
+
const denom = Math.sqrt(na) * Math.sqrt(nb);
|
|
644
|
+
if (denom === 0) return 0;
|
|
645
|
+
return dot2 / denom;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// ../../lib/terminals-tech/core/primitives/resonance.ts
|
|
649
|
+
function clamp01(x) {
|
|
650
|
+
if (!Number.isFinite(x)) return 0;
|
|
651
|
+
return Math.max(0, Math.min(1, x));
|
|
652
|
+
}
|
|
653
|
+
function cosineResonance(a, b) {
|
|
654
|
+
const cos = cosineSimilarityAny(a, b);
|
|
655
|
+
return clamp01((cos + 1) / 2);
|
|
656
|
+
}
|
|
657
|
+
function hierarchicalResonance(a, b) {
|
|
658
|
+
return clamp01(hyperbolicResonance(a, b));
|
|
659
|
+
}
|
|
660
|
+
function iqPhaseLockResonance(a, b) {
|
|
661
|
+
const phiA = phase(a);
|
|
662
|
+
const phiB = phase(b);
|
|
663
|
+
return clamp01(phaseLockingValue(phiA, phiB));
|
|
664
|
+
}
|
|
665
|
+
function blendResonance(components, weights = {}) {
|
|
666
|
+
const wSemantic = weights.semantic ?? (components.semantic != null ? 1 : 0);
|
|
667
|
+
const wHier = weights.hierarchical ?? (components.hierarchical != null ? 1 : 0);
|
|
668
|
+
const wPhase = weights.phaseLock ?? (components.phaseLock != null ? 1 : 0);
|
|
669
|
+
const denom = wSemantic + wHier + wPhase;
|
|
670
|
+
if (denom <= 0) return 0;
|
|
671
|
+
const semantic = components.semantic != null ? clamp01(components.semantic) : 0;
|
|
672
|
+
const hierarchical = components.hierarchical != null ? clamp01(components.hierarchical) : 0;
|
|
673
|
+
const phaseLock = components.phaseLock != null ? clamp01(components.phaseLock) : 0;
|
|
674
|
+
return clamp01((wSemantic * semantic + wHier * hierarchical + wPhase * phaseLock) / denom);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// ../../lib/terminals-tech/core/primitives/delegation.ts
|
|
678
|
+
var SURFACE_IDS = [
|
|
679
|
+
"chat",
|
|
680
|
+
"compose",
|
|
681
|
+
"whiteboard",
|
|
682
|
+
"world",
|
|
683
|
+
"skills",
|
|
684
|
+
"generate",
|
|
685
|
+
"lobby"
|
|
686
|
+
];
|
|
687
|
+
function isValidSurfaceId(value) {
|
|
688
|
+
return typeof value === "string" && SURFACE_IDS.includes(value);
|
|
689
|
+
}
|
|
690
|
+
function createDelegationEdge(input) {
|
|
691
|
+
return {
|
|
692
|
+
id: `del_${crypto.randomUUID()}`,
|
|
693
|
+
createdAt: Date.now(),
|
|
694
|
+
...input
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
function createDelegationChain(initialEdge, rootInteractionId) {
|
|
698
|
+
return {
|
|
699
|
+
id: `dch_${crypto.randomUUID()}`,
|
|
700
|
+
edges: [initialEdge],
|
|
701
|
+
rootInteractionId,
|
|
702
|
+
currentSurface: initialEdge.to.surface
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
export {
|
|
707
|
+
ok,
|
|
708
|
+
err,
|
|
709
|
+
isOk,
|
|
710
|
+
isErr,
|
|
711
|
+
map,
|
|
712
|
+
flatMap,
|
|
713
|
+
createRegistry,
|
|
714
|
+
createDAG,
|
|
715
|
+
toIQ,
|
|
716
|
+
phaseShift,
|
|
717
|
+
wrapTo2Pi,
|
|
718
|
+
wrapToPi,
|
|
719
|
+
orderParameter,
|
|
720
|
+
phaseLockingValue,
|
|
721
|
+
kuramotoStep,
|
|
722
|
+
cosineResonance,
|
|
723
|
+
hierarchicalResonance,
|
|
724
|
+
iqPhaseLockResonance,
|
|
725
|
+
blendResonance,
|
|
726
|
+
isValidSurfaceId,
|
|
727
|
+
createDelegationEdge,
|
|
728
|
+
createDelegationChain
|
|
729
|
+
};
|
|
730
|
+
/**
|
|
731
|
+
* I/Q (In-phase / Quadrature) Primitives
|
|
732
|
+
*
|
|
733
|
+
* Deterministic complex/analytic representation for phase-coherent operations.
|
|
734
|
+
* This is a minimal L1 primitive: it does not assume a specific embedding model,
|
|
735
|
+
* only that vectors can be treated as paired (I,Q) components.
|
|
736
|
+
*
|
|
737
|
+
* Grounding: https://en.wikipedia.org/wiki/In-phase_and_quadrature_components
|
|
738
|
+
*
|
|
739
|
+
* @license BUSL-1.1
|
|
740
|
+
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
741
|
+
*/
|
|
742
|
+
/**
|
|
743
|
+
* Hyperbolic Geometry Primitives (Poincaré Ball Model)
|
|
744
|
+
*
|
|
745
|
+
* Implements the "Scholze Pyramid" intuition where:
|
|
746
|
+
* - Center = Abstract Root (Zero) / High Entropy
|
|
747
|
+
* - Boundary = Rigid State (Ledger) / Low Entropy
|
|
748
|
+
* - Radius = p-adic Valuation (Specificity)
|
|
749
|
+
*
|
|
750
|
+
* @license BUSL-1.1
|
|
751
|
+
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
752
|
+
*/
|