@terminals-tech/sdk 1.0.0 → 2.0.0-rc.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/README.md +58 -12
- package/dist/{WebContainerManager-4LIOGRVM.js → WebContainerManager-NUGGUIWB.js} +2 -2
- package/dist/catalog-XA5VYWXG.js +16 -0
- package/dist/{chunk-PWAHFID5.js → chunk-D4MOOUDY.js} +3 -3
- package/dist/{chunk-FOXUEYWK.js → chunk-GOQHOLBG.js} +4 -3
- package/dist/{chunk-STMI72WH.js → chunk-ICFYWOI5.js} +35 -38
- package/dist/chunk-PKINKOW2.js +335 -0
- package/dist/chunk-PWEICJ47.js +30 -0
- package/dist/{chunk-KASHT6C5.js → chunk-Q4W3IUTD.js} +8 -8
- package/dist/{chunk-BCOQMFKT.js → chunk-TO7ETE5K.js} +2 -2
- package/dist/{chunk-Q2VI6ICE.js → chunk-UB5OINTA.js} +1 -1
- package/dist/{chunk-PPFTKJDB.js → chunk-WJCIX7RO.js} +3 -3
- package/dist/{chunk-OCLSAUCD.js → chunk-WT6L6DK3.js} +30 -2
- package/dist/{chunk-L45BSQDJ.js → chunk-Y5WLSLLW.js} +1 -1
- package/dist/{container-lite-QD3CRLS4.js → container-lite-Q3O3EP6R.js} +9 -9
- package/dist/core.machine.orchestrator-NW73YDTL.js +24 -0
- package/dist/{demo-T655Z5S4.js → demo-WARANXBT.js} +11 -11
- package/dist/{hvm-CBEP3M4F.js → hvm-A7DGZ3Q5.js} +1 -1
- package/dist/index.cjs +61426 -43456
- package/dist/index.d.cts +331 -140
- package/dist/index.d.ts +331 -140
- package/dist/index.js +253 -328
- package/dist/{neuro-state-XHRGIRVO.js → neuro-state-KINIFV2D.js} +6 -6
- package/dist/{nodes-K6GKI2FM.js → nodes-TWQZUZRM.js} +10 -10
- package/dist/{registry-5WTDYQVQ.js → registry-UARRB6CF.js} +9 -9
- package/dist/{scheduler-B5CEYKWT.js → scheduler-SAQJLKXJ.js} +16 -14
- package/dist/sematon-2EUEZESN.js +19 -0
- package/dist/{server-VW6DYDLH.js → server-JXM4Y2T6.js} +1 -1
- package/dist/{skills-VN7IN7SJ.js → skills-XOFGMUP4.js} +2 -2
- package/dist/{stack-4KWCQQP7.js → stack-4QQCK7MG.js} +17 -15
- package/dist/{supabaseService-6AYP2VY3.js → supabaseService-O4ZFFLZP.js} +2 -2
- package/dist/{webcontainer-XWCE56F3.js → webcontainer-PMWNRO4I.js} +2 -2
- package/package.json +3 -3
- package/dist/{chunk-LLGZTP3G.js → chunk-P4D4RNAV.js} +4 -4
package/dist/index.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
calculateSemanticDensity,
|
|
3
|
+
conditionalEntropy,
|
|
4
|
+
cosineSimilarity,
|
|
5
|
+
createSematon,
|
|
6
|
+
entropy,
|
|
7
|
+
estimateComplexity,
|
|
8
|
+
foldSematon,
|
|
9
|
+
isRealizable,
|
|
10
|
+
jointEntropy,
|
|
11
|
+
jsDivergence,
|
|
12
|
+
klDivergence,
|
|
13
|
+
measurePreservation,
|
|
14
|
+
mutualInformation,
|
|
15
|
+
normalize,
|
|
16
|
+
sematonDensity,
|
|
17
|
+
sematonDistance,
|
|
18
|
+
sematonEntropy,
|
|
19
|
+
unfoldSematon
|
|
20
|
+
} from "./chunk-PKINKOW2.js";
|
|
1
21
|
import {
|
|
2
22
|
ensureSkillsRegistered,
|
|
3
23
|
getAllSkills,
|
|
@@ -5,7 +25,7 @@ import {
|
|
|
5
25
|
getSkillCount,
|
|
6
26
|
getSkillsByCategory,
|
|
7
27
|
registerSkill
|
|
8
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-Y5WLSLLW.js";
|
|
9
29
|
import {
|
|
10
30
|
createDAG,
|
|
11
31
|
createDelegationChain,
|
|
@@ -24,19 +44,11 @@ import {
|
|
|
24
44
|
wrapTo2Pi,
|
|
25
45
|
wrapToPi
|
|
26
46
|
} from "./chunk-WU4OTGJE.js";
|
|
27
|
-
import "./chunk-OCLSAUCD.js";
|
|
28
|
-
import "./chunk-BYXBJQAS.js";
|
|
29
|
-
import {
|
|
30
|
-
SKILL_CATEGORIES,
|
|
31
|
-
SKILL_RANKS,
|
|
32
|
-
SKILL_RUN_STATUSES,
|
|
33
|
-
SKILL_TIERS
|
|
34
|
-
} from "./chunk-ABCK4FWN.js";
|
|
35
47
|
import {
|
|
36
48
|
createInteractionWithEvents,
|
|
37
49
|
formatAddress,
|
|
38
50
|
parseAddress
|
|
39
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-TO7ETE5K.js";
|
|
40
52
|
import {
|
|
41
53
|
createEventBus,
|
|
42
54
|
createSignalBus,
|
|
@@ -44,16 +56,24 @@ import {
|
|
|
44
56
|
getSignalBus,
|
|
45
57
|
subscribeToSignals
|
|
46
58
|
} from "./chunk-2WTYE4SW.js";
|
|
59
|
+
import "./chunk-BYXBJQAS.js";
|
|
60
|
+
import {
|
|
61
|
+
SKILL_CATEGORIES,
|
|
62
|
+
SKILL_RANKS,
|
|
63
|
+
SKILL_RUN_STATUSES,
|
|
64
|
+
SKILL_TIERS
|
|
65
|
+
} from "./chunk-ABCK4FWN.js";
|
|
47
66
|
import {
|
|
48
67
|
secureValidate,
|
|
49
68
|
validateWithSchema
|
|
50
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-GOQHOLBG.js";
|
|
70
|
+
import "./chunk-QJFKEQHF.js";
|
|
51
71
|
import {
|
|
52
72
|
unbrand,
|
|
53
73
|
untrusted,
|
|
54
74
|
validated
|
|
55
75
|
} from "./chunk-EXI3LJVJ.js";
|
|
56
|
-
import "./chunk-
|
|
76
|
+
import "./chunk-WT6L6DK3.js";
|
|
57
77
|
import "./chunk-XPJ63Y6T.js";
|
|
58
78
|
import {
|
|
59
79
|
createCircuitBreaker,
|
|
@@ -66,10 +86,207 @@ import {
|
|
|
66
86
|
// ../../lib/terminals-tech/sdk/terminal.ts
|
|
67
87
|
var terminal_exports = {};
|
|
68
88
|
__export(terminal_exports, {
|
|
89
|
+
Terminal: () => Terminal,
|
|
69
90
|
createInteraction: () => createInteractionWithEvents,
|
|
70
91
|
createInteractionWithEvents: () => createInteractionWithEvents
|
|
71
92
|
});
|
|
72
93
|
|
|
94
|
+
// ../agent-sdk/src/result.ts
|
|
95
|
+
function extractText(outputs) {
|
|
96
|
+
const keys = Object.keys(outputs);
|
|
97
|
+
if (keys.length === 0) return "";
|
|
98
|
+
const lastKey = keys[keys.length - 1];
|
|
99
|
+
const lastOutput = outputs[lastKey];
|
|
100
|
+
if (typeof lastOutput === "string") return lastOutput;
|
|
101
|
+
if (lastOutput && typeof lastOutput === "object" && "result" in lastOutput) {
|
|
102
|
+
const result = lastOutput.result;
|
|
103
|
+
return typeof result === "string" ? result : JSON.stringify(result);
|
|
104
|
+
}
|
|
105
|
+
return JSON.stringify(lastOutput);
|
|
106
|
+
}
|
|
107
|
+
function toTerminalResult(sematon) {
|
|
108
|
+
const { payload, witness } = sematon;
|
|
109
|
+
const outputs = payload.outputs ?? {};
|
|
110
|
+
const entries = Object.entries(outputs);
|
|
111
|
+
const steps = [];
|
|
112
|
+
const agents = [];
|
|
113
|
+
for (let i = 0; i < entries.length; i++) {
|
|
114
|
+
const [id, output] = entries[i];
|
|
115
|
+
steps.push({ agent: id, output, index: i });
|
|
116
|
+
agents.push({ id, output });
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
text: extractText(outputs),
|
|
120
|
+
coherence: witness.R,
|
|
121
|
+
receipt: sematon,
|
|
122
|
+
steps,
|
|
123
|
+
agents,
|
|
124
|
+
duration: payload.duration
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ../agent-sdk/src/terminal.ts
|
|
129
|
+
function generateTerminalId() {
|
|
130
|
+
return `term_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`;
|
|
131
|
+
}
|
|
132
|
+
function buildNodes(agents, task) {
|
|
133
|
+
return agents.map((agent, idx) => ({
|
|
134
|
+
id: `agent-${idx}`,
|
|
135
|
+
nodeRef: "provider.chat.v1",
|
|
136
|
+
config: {
|
|
137
|
+
role: agent.role,
|
|
138
|
+
capabilities: agent.capabilities ?? [],
|
|
139
|
+
prompt: task
|
|
140
|
+
}
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
function buildEdges(agents) {
|
|
144
|
+
const edges = [];
|
|
145
|
+
for (let i = 0; i < agents.length - 1; i++) {
|
|
146
|
+
edges.push({
|
|
147
|
+
from: `agent-${i}`,
|
|
148
|
+
to: `agent-${i + 1}`
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return edges;
|
|
152
|
+
}
|
|
153
|
+
function buildManifest(id, config) {
|
|
154
|
+
return {
|
|
155
|
+
id,
|
|
156
|
+
version: "1.0.0",
|
|
157
|
+
name: `Terminal ${id}`,
|
|
158
|
+
nodes: buildNodes(config.agents, config.task),
|
|
159
|
+
edges: buildEdges(config.agents),
|
|
160
|
+
layer: "L4"
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function flattenOutputs(outputs) {
|
|
164
|
+
if (!outputs) return {};
|
|
165
|
+
const result = {};
|
|
166
|
+
for (const [nodeId, nodeOutput] of outputs) {
|
|
167
|
+
result[nodeId] = nodeOutput;
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
var Terminal = class _Terminal {
|
|
172
|
+
/** Unique terminal identifier */
|
|
173
|
+
id;
|
|
174
|
+
config;
|
|
175
|
+
manifest;
|
|
176
|
+
constructor(id, config) {
|
|
177
|
+
this.id = id;
|
|
178
|
+
this.config = config;
|
|
179
|
+
this.manifest = buildManifest(id, config);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Create a new Terminal from semantic configuration.
|
|
183
|
+
*
|
|
184
|
+
* Translates the developer-friendly config into internal stack manifests,
|
|
185
|
+
* registers required nodes, and returns a ready-to-run Terminal.
|
|
186
|
+
*/
|
|
187
|
+
static async create(config) {
|
|
188
|
+
if (!config.agents || config.agents.length === 0) {
|
|
189
|
+
throw new Error("Terminal.create requires at least one agent");
|
|
190
|
+
}
|
|
191
|
+
if (!config.task || config.task.trim().length === 0) {
|
|
192
|
+
throw new Error("Terminal.create requires a non-empty task");
|
|
193
|
+
}
|
|
194
|
+
const id = generateTerminalId();
|
|
195
|
+
await import("./nodes-TWQZUZRM.js").catch(
|
|
196
|
+
(err2) => console.warn("[Terminal.create] Node catalog init warning:", err2)
|
|
197
|
+
);
|
|
198
|
+
await import("./catalog-XA5VYWXG.js").catch(
|
|
199
|
+
(err2) => console.warn("[Terminal.create] Catalog init warning:", err2)
|
|
200
|
+
);
|
|
201
|
+
return new _Terminal(id, config);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Execute the terminal workflow and return a Sematon-wrapped result.
|
|
205
|
+
*
|
|
206
|
+
* Uses OrchestratorV0 to run the DAG, then wraps the output
|
|
207
|
+
* in a Sematon<TerminalRunResult> with convergence witness.
|
|
208
|
+
*/
|
|
209
|
+
async run() {
|
|
210
|
+
const startTime = Date.now();
|
|
211
|
+
const threshold = this.config.coherence?.threshold ?? 0.6;
|
|
212
|
+
const { createSematon: createSematon2 } = await import("./sematon-2EUEZESN.js");
|
|
213
|
+
const { OrchestratorV0 } = await import("./core.machine.orchestrator-NW73YDTL.js");
|
|
214
|
+
const { resolveNode } = await import("./catalog-XA5VYWXG.js");
|
|
215
|
+
const orchestrator = new OrchestratorV0(
|
|
216
|
+
resolveNode
|
|
217
|
+
);
|
|
218
|
+
let runResult;
|
|
219
|
+
try {
|
|
220
|
+
runResult = await orchestrator.run(this.manifest, {
|
|
221
|
+
terminalId: this.id,
|
|
222
|
+
configOverrides: this.config.provider ? Object.fromEntries(
|
|
223
|
+
this.manifest.nodes.map((n) => [
|
|
224
|
+
n.id,
|
|
225
|
+
{
|
|
226
|
+
provider: this.config.provider,
|
|
227
|
+
model: this.config.model
|
|
228
|
+
}
|
|
229
|
+
])
|
|
230
|
+
) : void 0
|
|
231
|
+
});
|
|
232
|
+
} finally {
|
|
233
|
+
orchestrator.dispose();
|
|
234
|
+
}
|
|
235
|
+
const duration = Date.now() - startTime;
|
|
236
|
+
const outputs = flattenOutputs(runResult.outputs);
|
|
237
|
+
const R = runResult.succeeded ? 0.85 : 0.2;
|
|
238
|
+
const converged = R >= threshold && runResult.succeeded;
|
|
239
|
+
const witness = {
|
|
240
|
+
R,
|
|
241
|
+
activationEntropy: Object.keys(outputs).length > 0 ? 2.5 : 0,
|
|
242
|
+
converged,
|
|
243
|
+
step: this.manifest.nodes.length
|
|
244
|
+
};
|
|
245
|
+
const payload = { outputs, duration };
|
|
246
|
+
return createSematon2({
|
|
247
|
+
kind: "custom",
|
|
248
|
+
payload,
|
|
249
|
+
witness,
|
|
250
|
+
source: `terminal:${this.id}`
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Static convenience: create and run a terminal in one call.
|
|
255
|
+
* Returns a developer-friendly TerminalResult instead of a raw Sematon.
|
|
256
|
+
*/
|
|
257
|
+
static async run(config) {
|
|
258
|
+
const terminal = await _Terminal.create(config);
|
|
259
|
+
const sematon = await terminal.run();
|
|
260
|
+
return toTerminalResult(sematon);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Chain a new terminal execution from a previous Sematon result.
|
|
264
|
+
*
|
|
265
|
+
* Extracts `prev.payload.outputs` and injects them as `previousOutputs`
|
|
266
|
+
* in the config overrides, then creates a new Terminal, runs it, and
|
|
267
|
+
* returns the new Sematon.
|
|
268
|
+
*/
|
|
269
|
+
static async chain(prev, config) {
|
|
270
|
+
const prevPayload = prev.payload;
|
|
271
|
+
const previousOutputs = prevPayload?.outputs ?? {};
|
|
272
|
+
const fullConfig = {
|
|
273
|
+
agents: config.agents ?? [{ role: "assistant" }],
|
|
274
|
+
task: config.task ?? "Continue from previous results",
|
|
275
|
+
coherence: config.coherence,
|
|
276
|
+
provider: config.provider,
|
|
277
|
+
model: config.model
|
|
278
|
+
};
|
|
279
|
+
const terminal = await _Terminal.create(fullConfig);
|
|
280
|
+
for (const node of terminal.manifest.nodes) {
|
|
281
|
+
node.config = {
|
|
282
|
+
...node.config,
|
|
283
|
+
previousOutputs
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
return terminal.run();
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
73
290
|
// ../../lib/terminals-tech/sdk/core.ts
|
|
74
291
|
var core_exports = {};
|
|
75
292
|
__export(core_exports, {
|
|
@@ -275,165 +492,6 @@ function createBridge(from, to, iso) {
|
|
|
275
492
|
};
|
|
276
493
|
}
|
|
277
494
|
|
|
278
|
-
// ../../lib/terminals-tech/core/L0/information.ts
|
|
279
|
-
function entropy(probabilities) {
|
|
280
|
-
if (probabilities.length === 0) return 0;
|
|
281
|
-
const sum = probabilities.reduce((a, b) => a + b, 0);
|
|
282
|
-
const normalized = sum === 0 ? probabilities : probabilities.map((p) => p / sum);
|
|
283
|
-
return normalized.reduce((h, p) => {
|
|
284
|
-
if (p <= 0) return h;
|
|
285
|
-
return h - p * Math.log2(p);
|
|
286
|
-
}, 0);
|
|
287
|
-
}
|
|
288
|
-
function jointEntropy(jointProbabilities) {
|
|
289
|
-
const flat = jointProbabilities.flat();
|
|
290
|
-
return entropy(flat);
|
|
291
|
-
}
|
|
292
|
-
function conditionalEntropy(jointProbabilities) {
|
|
293
|
-
const hXY = jointEntropy(jointProbabilities);
|
|
294
|
-
const pX = jointProbabilities.map((row) => row.reduce((a, b) => a + b, 0));
|
|
295
|
-
const hX = entropy(pX);
|
|
296
|
-
return hXY - hX;
|
|
297
|
-
}
|
|
298
|
-
function mutualInformation(pX, pY, pXY) {
|
|
299
|
-
const hX = entropy(pX);
|
|
300
|
-
const hY = entropy(pY);
|
|
301
|
-
const hXY = jointEntropy(pXY);
|
|
302
|
-
return Math.max(0, hX + hY - hXY);
|
|
303
|
-
}
|
|
304
|
-
function measurePreservation(source, transformed, roundTrip) {
|
|
305
|
-
if (source.length === 0) {
|
|
306
|
-
return {
|
|
307
|
-
retention: 1,
|
|
308
|
-
sourceEntropy: 0,
|
|
309
|
-
targetEntropy: 0,
|
|
310
|
-
mutualInfo: 0,
|
|
311
|
-
lossless: true
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
const sourceFreq = countFrequencies(source.map(String));
|
|
315
|
-
const transformedFreq = countFrequencies(transformed.map(String));
|
|
316
|
-
const n = source.length;
|
|
317
|
-
const sourceProbabilities = Object.values(sourceFreq).map((c) => c / n);
|
|
318
|
-
const transformedProbabilities = Object.values(transformedFreq).map((c) => c / n);
|
|
319
|
-
const sourceEntropy = entropy(sourceProbabilities);
|
|
320
|
-
const targetEntropy = entropy(transformedProbabilities);
|
|
321
|
-
let retention = 1;
|
|
322
|
-
let lossless = true;
|
|
323
|
-
if (roundTrip) {
|
|
324
|
-
const matches = source.filter((s, i) => String(s) === String(roundTrip[i])).length;
|
|
325
|
-
retention = matches / source.length;
|
|
326
|
-
lossless = matches === source.length;
|
|
327
|
-
} else {
|
|
328
|
-
const sourceCardinality = Object.keys(sourceFreq).length;
|
|
329
|
-
const targetCardinality = Object.keys(transformedFreq).length;
|
|
330
|
-
retention = Math.min(1, targetCardinality / sourceCardinality);
|
|
331
|
-
lossless = targetCardinality >= sourceCardinality;
|
|
332
|
-
}
|
|
333
|
-
const minEntropy = Math.min(sourceEntropy, targetEntropy);
|
|
334
|
-
const mutualInfo = retention * minEntropy;
|
|
335
|
-
return {
|
|
336
|
-
retention,
|
|
337
|
-
sourceEntropy,
|
|
338
|
-
targetEntropy,
|
|
339
|
-
mutualInfo,
|
|
340
|
-
lossless
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
function calculateSemanticDensity(tokens, baselineTokensPerBit = 2) {
|
|
344
|
-
if (tokens.length === 0) {
|
|
345
|
-
return {
|
|
346
|
-
tokenCount: 0,
|
|
347
|
-
informationBits: 0,
|
|
348
|
-
density: 0,
|
|
349
|
-
compressionRatio: 1
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
const freq = countFrequencies(tokens);
|
|
353
|
-
const probabilities = Object.values(freq).map((c) => c / tokens.length);
|
|
354
|
-
const informationBits = entropy(probabilities) * tokens.length;
|
|
355
|
-
const density = tokens.length > 0 ? informationBits / tokens.length : 0;
|
|
356
|
-
const baselineBits = tokens.length / baselineTokensPerBit;
|
|
357
|
-
const compressionRatio = baselineBits > 0 ? informationBits / baselineBits : 1;
|
|
358
|
-
return {
|
|
359
|
-
tokenCount: tokens.length,
|
|
360
|
-
informationBits,
|
|
361
|
-
density,
|
|
362
|
-
compressionRatio
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
function estimateComplexity(data) {
|
|
366
|
-
if (data.length === 0) return 0;
|
|
367
|
-
const seen = /* @__PURE__ */ new Set();
|
|
368
|
-
let uniqueSubstrings = 0;
|
|
369
|
-
const windowSize = 8;
|
|
370
|
-
for (let i = 0; i <= data.length - windowSize; i++) {
|
|
371
|
-
const substr = data.slice(i, i + windowSize);
|
|
372
|
-
if (!seen.has(substr)) {
|
|
373
|
-
seen.add(substr);
|
|
374
|
-
uniqueSubstrings++;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
const totalPatterns = Math.max(1, data.length - windowSize + 1);
|
|
378
|
-
return uniqueSubstrings / totalPatterns;
|
|
379
|
-
}
|
|
380
|
-
function klDivergence(p, q) {
|
|
381
|
-
if (p.length !== q.length) {
|
|
382
|
-
throw new Error("Distributions must have same length");
|
|
383
|
-
}
|
|
384
|
-
let divergence = 0;
|
|
385
|
-
for (let i = 0; i < p.length; i++) {
|
|
386
|
-
if (p[i] > 0 && q[i] > 0) {
|
|
387
|
-
divergence += p[i] * Math.log2(p[i] / q[i]);
|
|
388
|
-
} else if (p[i] > 0 && q[i] === 0) {
|
|
389
|
-
return Infinity;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
return divergence;
|
|
393
|
-
}
|
|
394
|
-
function jsDivergence(p, q) {
|
|
395
|
-
if (p.length !== q.length) {
|
|
396
|
-
throw new Error("Distributions must have same length");
|
|
397
|
-
}
|
|
398
|
-
const m = p.map((pi, i) => 0.5 * (pi + q[i]));
|
|
399
|
-
let jsd = 0;
|
|
400
|
-
for (let i = 0; i < p.length; i++) {
|
|
401
|
-
if (p[i] > 0 && m[i] > 0) {
|
|
402
|
-
jsd += 0.5 * p[i] * Math.log2(p[i] / m[i]);
|
|
403
|
-
}
|
|
404
|
-
if (q[i] > 0 && m[i] > 0) {
|
|
405
|
-
jsd += 0.5 * q[i] * Math.log2(q[i] / m[i]);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
return jsd;
|
|
409
|
-
}
|
|
410
|
-
function countFrequencies(values) {
|
|
411
|
-
const freq = {};
|
|
412
|
-
for (const v of values) {
|
|
413
|
-
const key = String(v);
|
|
414
|
-
freq[key] = (freq[key] || 0) + 1;
|
|
415
|
-
}
|
|
416
|
-
return freq;
|
|
417
|
-
}
|
|
418
|
-
function normalize(values) {
|
|
419
|
-
const sum = values.reduce((a, b) => a + b, 0);
|
|
420
|
-
if (sum === 0) return values.map(() => 1 / values.length);
|
|
421
|
-
return values.map((v) => v / sum);
|
|
422
|
-
}
|
|
423
|
-
function cosineSimilarity(a, b) {
|
|
424
|
-
if (a.length !== b.length || a.length === 0) return 0;
|
|
425
|
-
let dot = 0;
|
|
426
|
-
let normA = 0;
|
|
427
|
-
let normB = 0;
|
|
428
|
-
for (let i = 0; i < a.length; i++) {
|
|
429
|
-
dot += a[i] * b[i];
|
|
430
|
-
normA += a[i] * a[i];
|
|
431
|
-
normB += b[i] * b[i];
|
|
432
|
-
}
|
|
433
|
-
const denominator = Math.sqrt(normA) * Math.sqrt(normB);
|
|
434
|
-
return denominator === 0 ? 0 : dot / denominator;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
495
|
// ../../lib/terminals-tech/core/L0/derivation.ts
|
|
438
496
|
function extractShape(value) {
|
|
439
497
|
if (value === null) {
|
|
@@ -627,143 +685,6 @@ function canEmbed(source, target) {
|
|
|
627
685
|
return true;
|
|
628
686
|
}
|
|
629
687
|
|
|
630
|
-
// ../../lib/terminals-tech/core/L0/sematon.ts
|
|
631
|
-
var sematonCounter = 0;
|
|
632
|
-
function fnv1a(input) {
|
|
633
|
-
let hash = 2166136261;
|
|
634
|
-
for (let i = 0; i < input.length; i++) {
|
|
635
|
-
hash ^= input.charCodeAt(i);
|
|
636
|
-
hash = Math.imul(hash, 16777619);
|
|
637
|
-
}
|
|
638
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
639
|
-
}
|
|
640
|
-
function computePayloadEntropy(payload) {
|
|
641
|
-
const json = JSON.stringify(payload);
|
|
642
|
-
if (!json || json.length === 0) return 0;
|
|
643
|
-
const freq = {};
|
|
644
|
-
for (let i = 0; i < json.length; i++) {
|
|
645
|
-
const ch = json[i];
|
|
646
|
-
freq[ch] = (freq[ch] || 0) + 1;
|
|
647
|
-
}
|
|
648
|
-
const probabilities = Object.values(freq).map((c) => c / json.length);
|
|
649
|
-
return entropy(probabilities);
|
|
650
|
-
}
|
|
651
|
-
function computeDensity(payload, entropyBits) {
|
|
652
|
-
const json = JSON.stringify(payload);
|
|
653
|
-
const tokenCount = json ? json.split(/\s+|[,{}[\]":]+/).filter(Boolean).length : 0;
|
|
654
|
-
return tokenCount > 0 ? entropyBits / tokenCount : 0;
|
|
655
|
-
}
|
|
656
|
-
function generatePadicAddress(kind, counter) {
|
|
657
|
-
const kindIndex = [
|
|
658
|
-
"signal",
|
|
659
|
-
"context",
|
|
660
|
-
"fractal",
|
|
661
|
-
"witness",
|
|
662
|
-
"combinator",
|
|
663
|
-
"interaction",
|
|
664
|
-
"custom"
|
|
665
|
-
].indexOf(kind);
|
|
666
|
-
return `${kindIndex}.0.${counter}`;
|
|
667
|
-
}
|
|
668
|
-
function createSematon(config) {
|
|
669
|
-
const counter = ++sematonCounter;
|
|
670
|
-
const id = `sem_${config.kind}_${counter}_${Date.now().toString(36)}`;
|
|
671
|
-
const payloadEntropy = computePayloadEntropy(config.payload);
|
|
672
|
-
const density = computeDensity(config.payload, payloadEntropy);
|
|
673
|
-
const padicAddress = config.padicAddress ?? generatePadicAddress(config.kind, counter);
|
|
674
|
-
const hashInput = [
|
|
675
|
-
config.kind,
|
|
676
|
-
JSON.stringify(config.payload),
|
|
677
|
-
config.witness.R.toFixed(6),
|
|
678
|
-
config.witness.converged.toString(),
|
|
679
|
-
padicAddress
|
|
680
|
-
].join("|");
|
|
681
|
-
const shapeHash = fnv1a(hashInput);
|
|
682
|
-
const constructive = config.witness.converged && Number.isFinite(payloadEntropy) && payloadEntropy > 0 && JSON.stringify(config.payload) !== "null" && JSON.stringify(config.payload) !== "undefined";
|
|
683
|
-
const impedance = density > 0 && config.witness.R > 0 ? payloadEntropy / (density * config.witness.R) : Infinity;
|
|
684
|
-
return {
|
|
685
|
-
id,
|
|
686
|
-
kind: config.kind,
|
|
687
|
-
payload: config.payload,
|
|
688
|
-
witness: { ...config.witness },
|
|
689
|
-
padicAddress,
|
|
690
|
-
entropy: payloadEntropy,
|
|
691
|
-
density,
|
|
692
|
-
impedance,
|
|
693
|
-
shapeHash,
|
|
694
|
-
constructive,
|
|
695
|
-
createdAt: Date.now(),
|
|
696
|
-
source: config.source ?? "unknown"
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
function sematonEntropy(sematon) {
|
|
700
|
-
return sematon.entropy;
|
|
701
|
-
}
|
|
702
|
-
function sematonDensity(sematon) {
|
|
703
|
-
return sematon.density;
|
|
704
|
-
}
|
|
705
|
-
function isRealizable(sematon) {
|
|
706
|
-
return sematon.constructive;
|
|
707
|
-
}
|
|
708
|
-
function sematonDistance(a, b) {
|
|
709
|
-
const vecA = payloadToVector(a.payload);
|
|
710
|
-
const vecB = payloadToVector(b.payload);
|
|
711
|
-
const cosSim = cosineSimilarity(vecA, vecB);
|
|
712
|
-
const rProximity = 1 - Math.abs(a.witness.R - b.witness.R);
|
|
713
|
-
const similarity = 0.7 * Math.max(0, cosSim) + 0.3 * rProximity;
|
|
714
|
-
return 1 - similarity;
|
|
715
|
-
}
|
|
716
|
-
function payloadToVector(payload) {
|
|
717
|
-
const json = JSON.stringify(payload);
|
|
718
|
-
const vec = new Array(128).fill(0);
|
|
719
|
-
if (!json) return vec;
|
|
720
|
-
for (let i = 0; i < json.length; i++) {
|
|
721
|
-
const code = json.charCodeAt(i);
|
|
722
|
-
if (code < 128) {
|
|
723
|
-
vec[code]++;
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
const sum = vec.reduce((s, v) => s + v, 0);
|
|
727
|
-
if (sum > 0) {
|
|
728
|
-
for (let i = 0; i < vec.length; i++) {
|
|
729
|
-
vec[i] /= sum;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
return vec;
|
|
733
|
-
}
|
|
734
|
-
function foldSematon(sematon) {
|
|
735
|
-
return {
|
|
736
|
-
id: sematon.id,
|
|
737
|
-
kind: sematon.kind,
|
|
738
|
-
payload: JSON.stringify(sematon.payload),
|
|
739
|
-
witness: { ...sematon.witness },
|
|
740
|
-
padicAddress: sematon.padicAddress,
|
|
741
|
-
entropy: sematon.entropy,
|
|
742
|
-
density: sematon.density,
|
|
743
|
-
impedance: sematon.impedance,
|
|
744
|
-
shapeHash: sematon.shapeHash,
|
|
745
|
-
constructive: sematon.constructive,
|
|
746
|
-
createdAt: sematon.createdAt,
|
|
747
|
-
source: sematon.source
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
function unfoldSematon(folded) {
|
|
751
|
-
return {
|
|
752
|
-
id: folded.id,
|
|
753
|
-
kind: folded.kind,
|
|
754
|
-
payload: JSON.parse(folded.payload),
|
|
755
|
-
witness: { ...folded.witness },
|
|
756
|
-
padicAddress: folded.padicAddress,
|
|
757
|
-
entropy: folded.entropy,
|
|
758
|
-
density: folded.density,
|
|
759
|
-
impedance: folded.impedance,
|
|
760
|
-
shapeHash: folded.shapeHash,
|
|
761
|
-
constructive: folded.constructive,
|
|
762
|
-
createdAt: folded.createdAt,
|
|
763
|
-
source: folded.source
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
|
|
767
688
|
// ../../lib/terminals-tech/core/L0/realizability.ts
|
|
768
689
|
var traceCounter = 0;
|
|
769
690
|
function createRealizabilityStep(index, inputs, outputs, witness) {
|
|
@@ -3020,7 +2941,7 @@ var HermesHVMBridge = class {
|
|
|
3020
2941
|
async executeBend(bendSource) {
|
|
3021
2942
|
const manifest = this.createManifest(bendSource);
|
|
3022
2943
|
try {
|
|
3023
|
-
const { runInHVM } = await import("./hvm-
|
|
2944
|
+
const { runInHVM } = await import("./hvm-A7DGZ3Q5.js");
|
|
3024
2945
|
const output = await runInHVM(
|
|
3025
2946
|
manifest,
|
|
3026
2947
|
{ bendSource },
|
|
@@ -3913,6 +3834,29 @@ export {
|
|
|
3913
3834
|
createAxonBus,
|
|
3914
3835
|
createProtocolBridge
|
|
3915
3836
|
};
|
|
3837
|
+
/**
|
|
3838
|
+
* ELI5 Result Types for @terminals-tech/agent
|
|
3839
|
+
*
|
|
3840
|
+
* Wraps internal Sematon<TerminalRunResult> into developer-friendly types.
|
|
3841
|
+
* Theory stays in the engine; developers get plain objects.
|
|
3842
|
+
*
|
|
3843
|
+
* @license MIT
|
|
3844
|
+
* @module agent/result
|
|
3845
|
+
*/
|
|
3846
|
+
/**
|
|
3847
|
+
* Terminal.create() Developer API
|
|
3848
|
+
*
|
|
3849
|
+
* The developer-facing entry point for creating and running multi-agent
|
|
3850
|
+
* terminal workflows. Translates semantic configuration into the internal
|
|
3851
|
+
* StackManifestV0 / OrchestratorV0 infrastructure and wraps results as
|
|
3852
|
+
* Sematon<TerminalRunResult>.
|
|
3853
|
+
*
|
|
3854
|
+
* This is a headless API -- no React, no "use client".
|
|
3855
|
+
*
|
|
3856
|
+
* @license BUSL-1.1
|
|
3857
|
+
* @copyright 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
3858
|
+
* @module agent-sdk/terminal
|
|
3859
|
+
*/
|
|
3916
3860
|
/**
|
|
3917
3861
|
* L0 Category Theory Primitives
|
|
3918
3862
|
*
|
|
@@ -3933,25 +3877,6 @@ export {
|
|
|
3933
3877
|
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
3934
3878
|
* @module core/L0/derivation
|
|
3935
3879
|
*/
|
|
3936
|
-
/**
|
|
3937
|
-
* L0 Sematon — The Smallest Meaning-Bearing Unit
|
|
3938
|
-
*
|
|
3939
|
-
* The sematon is the atomic unit of operational meaning in Terminals OS.
|
|
3940
|
-
* It carries a typed payload, convergence witness, p-adic address,
|
|
3941
|
-
* information-theoretic metrics, and a constructor flag that guarantees
|
|
3942
|
-
* the Deutsch-Marletto invariant: after transforming an input, the
|
|
3943
|
-
* sematon retains the ability to transform again.
|
|
3944
|
-
*
|
|
3945
|
-
* The sematon unifies Signal<T>, ContextNode, FractalSnapshot,
|
|
3946
|
-
* ConvergenceWitness, and CombinatorEvent into a single formal type
|
|
3947
|
-
* at the L0 foundation layer.
|
|
3948
|
-
*
|
|
3949
|
-
* Core Engine Primitive.
|
|
3950
|
-
*
|
|
3951
|
-
* @license BUSL-1.1
|
|
3952
|
-
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
3953
|
-
* @module core/L0/sematon
|
|
3954
|
-
*/
|
|
3955
3880
|
/**
|
|
3956
3881
|
* L0 Realizability Trace — Constructor Proof Runtime
|
|
3957
3882
|
*
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
onOrchestratorEvent
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-UB5OINTA.js";
|
|
4
|
+
import "./chunk-D4MOOUDY.js";
|
|
5
5
|
import "./chunk-Y2EULKA2.js";
|
|
6
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-WGBCRNMB.js";
|
|
7
|
+
import "./chunk-TO7ETE5K.js";
|
|
7
8
|
import {
|
|
8
9
|
getSignalBus
|
|
9
10
|
} from "./chunk-2WTYE4SW.js";
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-EXI3LJVJ.js";
|
|
11
|
+
import "./chunk-GOQHOLBG.js";
|
|
12
12
|
import "./chunk-QJFKEQHF.js";
|
|
13
|
+
import "./chunk-EXI3LJVJ.js";
|
|
13
14
|
import "./chunk-ZVO47SQV.js";
|
|
14
|
-
import "./chunk-WGBCRNMB.js";
|
|
15
15
|
import "./chunk-3LFMIVJM.js";
|
|
16
16
|
import "./chunk-AFDUOYHD.js";
|
|
17
17
|
import "./chunk-NTMBOESX.js";
|