@terminals-tech/sdk 1.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/LICENSE +92 -0
- package/README.md +109 -0
- package/dist/index.cjs +9670 -0
- package/dist/index.d.cts +3548 -0
- package/dist/index.d.ts +3548 -0
- package/dist/index.js +9641 -0
- package/package.json +47 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,3548 @@
|
|
|
1
|
+
import { JSONSchema7 } from 'json-schema';
|
|
2
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Delegation Primitive — Cross-surface/cross-agent work flow edges
|
|
7
|
+
*
|
|
8
|
+
* Part of the D/L/R (Delegate/Lease/Refine) interaction primitive system.
|
|
9
|
+
* Encodes directed work flow from one surface/agent to another.
|
|
10
|
+
*
|
|
11
|
+
* Grounded in Lafont's constructor (gamma) combinator —
|
|
12
|
+
* builds structure by creating new agent/surface bindings.
|
|
13
|
+
*
|
|
14
|
+
* @module core/primitives/delegation
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* All surfaces in the workspace — aligned with NavigationRail WorkspaceMode.
|
|
18
|
+
*/
|
|
19
|
+
declare const SURFACE_IDS: readonly ["chat", "compose", "whiteboard", "world", "skills", "generate", "lobby"];
|
|
20
|
+
type SurfaceId = (typeof SURFACE_IDS)[number];
|
|
21
|
+
/** Endpoint in a delegation — a surface with optional item/agent specificity. */
|
|
22
|
+
interface DelegationEndpoint<S = SurfaceId> {
|
|
23
|
+
surface: S;
|
|
24
|
+
itemId?: string;
|
|
25
|
+
agentId?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A directed edge representing work flowing from one surface/agent to another.
|
|
29
|
+
*
|
|
30
|
+
* Every "Continue with Zero" button, every "Send to Compose" action,
|
|
31
|
+
* every persona switch is a DelegationEdge.
|
|
32
|
+
*/
|
|
33
|
+
interface DelegationEdge<S = SurfaceId, T = SurfaceId> {
|
|
34
|
+
/** Unique identifier (format: del_<uuid>) */
|
|
35
|
+
id: string;
|
|
36
|
+
/** Source endpoint */
|
|
37
|
+
from: DelegationEndpoint<S>;
|
|
38
|
+
/** Target endpoint */
|
|
39
|
+
to: DelegationEndpoint<T>;
|
|
40
|
+
/** Arbitrary payload carried across the delegation */
|
|
41
|
+
payload: unknown;
|
|
42
|
+
/** Links to L3 interaction-store for audit trail */
|
|
43
|
+
interactionId?: string;
|
|
44
|
+
/** AMB strategy for delegation resolution */
|
|
45
|
+
strategy?: "amb" | "race" | "explore" | "fallback";
|
|
46
|
+
/** Creation timestamp (Unix ms) */
|
|
47
|
+
createdAt: number;
|
|
48
|
+
}
|
|
49
|
+
/** Input for creating a DelegationEdge (id and createdAt are auto-generated). */
|
|
50
|
+
type DelegationEdgeInput<S = SurfaceId, T = SurfaceId> = Omit<DelegationEdge<S, T>, "id" | "createdAt">;
|
|
51
|
+
/**
|
|
52
|
+
* A linked sequence of delegation edges forming a workflow path.
|
|
53
|
+
*
|
|
54
|
+
* Inspired by Google Interactions API `previous_interaction_id` pattern.
|
|
55
|
+
* Tracks how work flows across surfaces within a session.
|
|
56
|
+
*/
|
|
57
|
+
interface DelegationChain {
|
|
58
|
+
/** Unique identifier (format: dch_<uuid>) */
|
|
59
|
+
id: string;
|
|
60
|
+
/** Ordered edges in the chain */
|
|
61
|
+
edges: DelegationEdge[];
|
|
62
|
+
/** The root interaction this chain belongs to */
|
|
63
|
+
rootInteractionId: string;
|
|
64
|
+
/** The surface the chain currently points to (last edge's `to`) */
|
|
65
|
+
currentSurface: SurfaceId;
|
|
66
|
+
}
|
|
67
|
+
declare function isValidSurfaceId(value: unknown): value is SurfaceId;
|
|
68
|
+
declare function createDelegationEdge<S extends SurfaceId = SurfaceId, T extends SurfaceId = SurfaceId>(input: DelegationEdgeInput<S, T>): DelegationEdge<S, T>;
|
|
69
|
+
declare function createDelegationChain(initialEdge: DelegationEdge, rootInteractionId: string): DelegationChain;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* SDK Primitives - Shared Type Definitions
|
|
73
|
+
*
|
|
74
|
+
* Minimal type definitions shared across SDK primitive modules.
|
|
75
|
+
* Part of the AXON architecture L1 (SDK Core).
|
|
76
|
+
*/
|
|
77
|
+
/**
|
|
78
|
+
* Metadata attached to operation results
|
|
79
|
+
*/
|
|
80
|
+
interface ResultMeta {
|
|
81
|
+
/** Operation duration in milliseconds */
|
|
82
|
+
duration: number;
|
|
83
|
+
/** ISO timestamp of operation completion */
|
|
84
|
+
timestamp: string;
|
|
85
|
+
/** Source identifier (function, module, service) */
|
|
86
|
+
source: string;
|
|
87
|
+
/** Optional trace ID for distributed tracing */
|
|
88
|
+
traceId?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Task execution states
|
|
92
|
+
*/
|
|
93
|
+
type TaskStatus = "pending" | "running" | "completed" | "failed" | "cancelled" | "retrying";
|
|
94
|
+
/**
|
|
95
|
+
* AXON architecture layers
|
|
96
|
+
*
|
|
97
|
+
* L1: SDK Core - Timeline, TemporalKV, session management
|
|
98
|
+
* L2: Platform - DAG orchestration, runners, tracing
|
|
99
|
+
* L3: Mesh Coordination - Event sourcing, convergence, matching
|
|
100
|
+
* L4: Brain Interface - Coherence, cognitive processing, swarm
|
|
101
|
+
* L5: External Protocols - MCP, A2A, ACP, Gemini
|
|
102
|
+
*/
|
|
103
|
+
type LayerLevel = "L1" | "L2" | "L3" | "L4" | "L5";
|
|
104
|
+
/**
|
|
105
|
+
* Validated<T> - Branded type for semantically validated values
|
|
106
|
+
*
|
|
107
|
+
* Marks a value as having passed validation. The validation is
|
|
108
|
+
* performed at runtime, but the type system tracks that validation
|
|
109
|
+
* has occurred.
|
|
110
|
+
*
|
|
111
|
+
* This pattern prevents using unvalidated data in contexts that
|
|
112
|
+
* require validation, catching bugs at compile time.
|
|
113
|
+
*
|
|
114
|
+
* @typeParam T - The underlying validated type
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* function processConfig(config: Validated<Config>): void {
|
|
119
|
+
* // Safe: config has been validated
|
|
120
|
+
* }
|
|
121
|
+
*
|
|
122
|
+
* const raw = { port: 8080 };
|
|
123
|
+
* // processConfig(raw); // Error: not Validated<Config>
|
|
124
|
+
*
|
|
125
|
+
* const validated = validated(raw);
|
|
126
|
+
* processConfig(validated); // OK
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
type Validated<T> = T & {
|
|
130
|
+
readonly _validated: true;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Untrusted<T> - Branded type for untrusted/raw input values
|
|
134
|
+
*
|
|
135
|
+
* Marks a value as coming from an untrusted source (user input,
|
|
136
|
+
* external API, etc.). Must be validated before use.
|
|
137
|
+
*
|
|
138
|
+
* @typeParam T - The underlying type
|
|
139
|
+
*/
|
|
140
|
+
type Untrusted<T> = T & {
|
|
141
|
+
readonly _untrusted: true;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Mark a value as validated
|
|
145
|
+
*
|
|
146
|
+
* @param value - Value that has passed validation
|
|
147
|
+
* @returns Validated wrapper
|
|
148
|
+
*/
|
|
149
|
+
declare function validated<T>(value: T): Validated<T>;
|
|
150
|
+
/**
|
|
151
|
+
* Remove the validation brand from a Validated<T> value
|
|
152
|
+
*
|
|
153
|
+
* Strips the `_validated` property and returns the underlying type.
|
|
154
|
+
* Use at consumption boundaries where the brand is no longer needed.
|
|
155
|
+
*
|
|
156
|
+
* @param value - Validated value to unbrand
|
|
157
|
+
* @returns The underlying value without the validation brand
|
|
158
|
+
*/
|
|
159
|
+
declare function unbrand<T>(value: Validated<T>): T;
|
|
160
|
+
/**
|
|
161
|
+
* Mark a value as untrusted (from external source)
|
|
162
|
+
*
|
|
163
|
+
* @param value - Raw value from untrusted source
|
|
164
|
+
* @returns Untrusted wrapper
|
|
165
|
+
*/
|
|
166
|
+
declare function untrusted<T>(value: T): Untrusted<T>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* SDK Message Primitives
|
|
170
|
+
*
|
|
171
|
+
* Canonical message types for all cross-layer communication.
|
|
172
|
+
* The atomic unit of communication in the terminals SDK.
|
|
173
|
+
*
|
|
174
|
+
* Part of AXON architecture L1 (SDK Core).
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* SDKAddress - Universal address for any node in the SDK
|
|
179
|
+
*
|
|
180
|
+
* Format: `{layer}:{nodeType}:{nodeId}` or `{layer}:{nodeType}:{nodeId}:{userId}`
|
|
181
|
+
* Examples:
|
|
182
|
+
* - `L3:kernel:v0` - The AXON kernel
|
|
183
|
+
* - `L2:orchestrator:v0` - The orchestrator
|
|
184
|
+
* - `L4:brain:zero:user123` - Zero brain for a specific user
|
|
185
|
+
* - `L5:mcp:filesystem` - MCP filesystem server
|
|
186
|
+
*/
|
|
187
|
+
interface SDKAddress {
|
|
188
|
+
/** Architecture layer (L1-L5) */
|
|
189
|
+
layer: LayerLevel;
|
|
190
|
+
/** Node type identifier */
|
|
191
|
+
nodeType: string;
|
|
192
|
+
/** Node instance identifier */
|
|
193
|
+
nodeId: string;
|
|
194
|
+
/** Optional user scope */
|
|
195
|
+
userId?: string;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Message type discriminator
|
|
199
|
+
*/
|
|
200
|
+
type SDKMessageType = "command" | "query" | "event" | "response";
|
|
201
|
+
/**
|
|
202
|
+
* Protocol type for external bridges
|
|
203
|
+
*/
|
|
204
|
+
type SDKProtocolType = "mcp" | "a2a" | "internal" | "ws" | "http";
|
|
205
|
+
/**
|
|
206
|
+
* Message metadata
|
|
207
|
+
*/
|
|
208
|
+
interface SDKMessageMeta {
|
|
209
|
+
/** Message creation timestamp */
|
|
210
|
+
timestamp: number;
|
|
211
|
+
/** Distributed trace ID */
|
|
212
|
+
traceId: string;
|
|
213
|
+
/** Correlation ID for request/response pairing */
|
|
214
|
+
correlationId?: string;
|
|
215
|
+
/** Message priority (0=critical, 1=high, 2=normal, 3=low, 4=background) */
|
|
216
|
+
priority?: number;
|
|
217
|
+
/** Time-to-live in milliseconds */
|
|
218
|
+
ttl?: number;
|
|
219
|
+
/** Retry count */
|
|
220
|
+
retries?: number;
|
|
221
|
+
/** Session ID for context propagation */
|
|
222
|
+
sessionId?: string;
|
|
223
|
+
/** Interaction ID for multi-agent workflow aggregation */
|
|
224
|
+
interactionId?: string;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Protocol bridging info
|
|
228
|
+
*/
|
|
229
|
+
interface SDKProtocolInfo {
|
|
230
|
+
/** Protocol type */
|
|
231
|
+
type: SDKProtocolType;
|
|
232
|
+
/** Protocol version */
|
|
233
|
+
version: string;
|
|
234
|
+
/** Original message for protocol bridges */
|
|
235
|
+
originalMessage?: unknown;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* SDKMessage<P> - The canonical message type for all SDK communication
|
|
239
|
+
*
|
|
240
|
+
* This is the high-level JSON message format used across layers.
|
|
241
|
+
* For binary/low-level communication with AXON kernel, convert using
|
|
242
|
+
* `toAxonMessage()` and `fromAxonMessage()`.
|
|
243
|
+
*
|
|
244
|
+
* @typeParam P - Payload type
|
|
245
|
+
*/
|
|
246
|
+
interface SDKMessage<P = unknown> {
|
|
247
|
+
/** Unique message identifier */
|
|
248
|
+
id: string;
|
|
249
|
+
/** Message type */
|
|
250
|
+
type: SDKMessageType;
|
|
251
|
+
/** Source node address */
|
|
252
|
+
source: SDKAddress;
|
|
253
|
+
/** Target node address */
|
|
254
|
+
target: SDKAddress;
|
|
255
|
+
/** Message payload */
|
|
256
|
+
payload: P;
|
|
257
|
+
/** Message metadata */
|
|
258
|
+
meta: SDKMessageMeta;
|
|
259
|
+
/** Optional protocol bridging info */
|
|
260
|
+
protocol?: SDKProtocolInfo;
|
|
261
|
+
/**
|
|
262
|
+
* Optional capability identifier for L5 protocol compatibility.
|
|
263
|
+
* Used to specify the capability being invoked (e.g., MCP tool name, A2A skill).
|
|
264
|
+
* This enables unified message handling across protocol bridges.
|
|
265
|
+
*/
|
|
266
|
+
capability?: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Interaction Primitive - Multi-Agent Workflow Aggregation
|
|
271
|
+
*
|
|
272
|
+
* Interactions unify multi-agent workflows by aggregating messages and events
|
|
273
|
+
* via a shared interactionId. This provides:
|
|
274
|
+
* - Complete workflow audit trail
|
|
275
|
+
* - Causality tracking across agents
|
|
276
|
+
* - Semantic clustering of related operations
|
|
277
|
+
* - Replay and time-travel debugging
|
|
278
|
+
*
|
|
279
|
+
* Part of AXON architecture L1 (SDK Core).
|
|
280
|
+
*
|
|
281
|
+
* @module core/primitives/interaction
|
|
282
|
+
*/
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Classification of interaction patterns.
|
|
286
|
+
*
|
|
287
|
+
* - request: A asks B to do something (single exchange)
|
|
288
|
+
* - conversation: Multi-turn dialogue between participants
|
|
289
|
+
* - collaboration: Multiple agents working together on shared goal
|
|
290
|
+
* - workflow: Orchestrated multi-step process with defined stages
|
|
291
|
+
* - observation: Read-only participation (monitoring, logging)
|
|
292
|
+
*/
|
|
293
|
+
type InteractionType = "request" | "conversation" | "collaboration" | "workflow" | "observation" | "generation" | "live_session" | "mutation";
|
|
294
|
+
/**
|
|
295
|
+
* Lifecycle status of an interaction.
|
|
296
|
+
*
|
|
297
|
+
* - initiated: Created but not yet active
|
|
298
|
+
* - active: In progress
|
|
299
|
+
* - processing: Long-running provider operation
|
|
300
|
+
* - paused: Temporarily suspended
|
|
301
|
+
* - completed: Successfully finished
|
|
302
|
+
* - failed: Terminated with error
|
|
303
|
+
* - cancelled: User/system terminated
|
|
304
|
+
*/
|
|
305
|
+
type InteractionStatus = "initiated" | "active" | "processing" | "paused" | "completed" | "failed" | "cancelled";
|
|
306
|
+
/**
|
|
307
|
+
* Role of a participant in an interaction.
|
|
308
|
+
*
|
|
309
|
+
* - initiator: Started the interaction
|
|
310
|
+
* - responder: Responding to initiator
|
|
311
|
+
* - observer: Read-only participant
|
|
312
|
+
* - coordinator: Orchestrating the workflow
|
|
313
|
+
*/
|
|
314
|
+
type ParticipantRole = "initiator" | "responder" | "observer" | "coordinator";
|
|
315
|
+
/**
|
|
316
|
+
* A participant in an interaction with role and lifecycle tracking.
|
|
317
|
+
*/
|
|
318
|
+
interface Participant {
|
|
319
|
+
/** Universal address of the participant */
|
|
320
|
+
address: SDKAddress;
|
|
321
|
+
/** Role within the interaction */
|
|
322
|
+
role: ParticipantRole;
|
|
323
|
+
/** When participant joined (Unix ms) */
|
|
324
|
+
joinedAt: number;
|
|
325
|
+
/** When participant left (Unix ms), undefined if still active */
|
|
326
|
+
leftAt?: number;
|
|
327
|
+
/** Optional participant-specific metadata */
|
|
328
|
+
metadata?: Record<string, unknown>;
|
|
329
|
+
/** Capabilities required to participate in or fulfill this interaction */
|
|
330
|
+
requiredCapabilities?: string[];
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* A condition for workflow completion.
|
|
334
|
+
* Used to define when an interaction should transition to completed.
|
|
335
|
+
*/
|
|
336
|
+
interface InteractionExitCriterion {
|
|
337
|
+
/** Unique criterion identifier */
|
|
338
|
+
id: string;
|
|
339
|
+
/** Human-readable description */
|
|
340
|
+
description: string;
|
|
341
|
+
/** Expression or description of the condition */
|
|
342
|
+
condition: string;
|
|
343
|
+
/** Whether this criterion has been satisfied */
|
|
344
|
+
met: boolean;
|
|
345
|
+
/** When criterion was met (Unix ms) */
|
|
346
|
+
metAt?: number;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Interaction - The workflow container.
|
|
350
|
+
*
|
|
351
|
+
* Aggregates messages and events across agents via shared interactionId.
|
|
352
|
+
* Supports nesting (parent/child), context propagation, and semantic search.
|
|
353
|
+
*
|
|
354
|
+
* @typeParam TContext - Domain-specific context type
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```typescript
|
|
358
|
+
* const interaction: Interaction<{ topic: string }> = {
|
|
359
|
+
* id: 'int_abc-123',
|
|
360
|
+
* type: 'conversation',
|
|
361
|
+
* status: 'active',
|
|
362
|
+
* participants: [
|
|
363
|
+
* { address: agentA, role: 'initiator', joinedAt: Date.now() },
|
|
364
|
+
* { address: agentB, role: 'responder', joinedAt: Date.now() }
|
|
365
|
+
* ],
|
|
366
|
+
* childIds: [],
|
|
367
|
+
* createdAt: Date.now(),
|
|
368
|
+
* context: { topic: 'code review' },
|
|
369
|
+
* labels: ['anticipatory', 'pair-review'],
|
|
370
|
+
* exitCriteria: []
|
|
371
|
+
* };
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
interface Interaction<TContext = unknown> {
|
|
375
|
+
/** Unique identifier (format: int_<uuid>) */
|
|
376
|
+
id: string;
|
|
377
|
+
/** Interaction classification */
|
|
378
|
+
type: InteractionType;
|
|
379
|
+
/** Current lifecycle status */
|
|
380
|
+
status: InteractionStatus;
|
|
381
|
+
/** All participants in this interaction */
|
|
382
|
+
participants: Participant[];
|
|
383
|
+
/** Parent interaction ID (for nesting) */
|
|
384
|
+
parentId?: string;
|
|
385
|
+
/** Child interaction IDs (spawned sub-interactions) */
|
|
386
|
+
childIds: string[];
|
|
387
|
+
/** Creation timestamp (Unix ms) */
|
|
388
|
+
createdAt: number;
|
|
389
|
+
/** When interaction became active */
|
|
390
|
+
startedAt?: number;
|
|
391
|
+
/** When interaction completed/failed/cancelled */
|
|
392
|
+
completedAt?: number;
|
|
393
|
+
/** Domain-specific context */
|
|
394
|
+
context: TContext;
|
|
395
|
+
/** Categorical labels for filtering/analysis */
|
|
396
|
+
labels: string[];
|
|
397
|
+
/** Exit conditions for workflow completion */
|
|
398
|
+
exitCriteria: InteractionExitCriterion[];
|
|
399
|
+
/** Optional embedding for semantic search (384-dim recommended) */
|
|
400
|
+
embedding?: Float32Array;
|
|
401
|
+
/** Monotonic ordinal for strict sequencing of manifold mutations */
|
|
402
|
+
ordinal?: number;
|
|
403
|
+
/** Mathematical uncertainty/complexity of the cognitive state (UTOPIA Manifold) */
|
|
404
|
+
entropy?: number;
|
|
405
|
+
/** Derivative of attention/token generation speed over time */
|
|
406
|
+
momentum?: number;
|
|
407
|
+
/** Extensible metadata */
|
|
408
|
+
metadata?: Record<string, unknown>;
|
|
409
|
+
/** Capabilities required to participate in or fulfill this interaction */
|
|
410
|
+
requiredCapabilities?: string[];
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Interaction Event Primitives - Lifecycle Event Schema
|
|
415
|
+
*
|
|
416
|
+
* Canonical event types for interaction lifecycle (creation + status transitions).
|
|
417
|
+
* Part of AXON architecture L1 (SDK Core).
|
|
418
|
+
*/
|
|
419
|
+
|
|
420
|
+
type InteractionLifecycleEventType = "interaction:created" | "interaction:status_changed";
|
|
421
|
+
interface InteractionCreatedPayload {
|
|
422
|
+
interaction: Interaction;
|
|
423
|
+
/** Optional per-interaction sequence number (monotonic) */
|
|
424
|
+
sequence?: number;
|
|
425
|
+
}
|
|
426
|
+
interface InteractionStatusPayload {
|
|
427
|
+
interactionId: string;
|
|
428
|
+
from?: InteractionStatus;
|
|
429
|
+
to: InteractionStatus;
|
|
430
|
+
at: number;
|
|
431
|
+
/** Optional per-interaction sequence number (monotonic) */
|
|
432
|
+
sequence?: number;
|
|
433
|
+
}
|
|
434
|
+
type InteractionLifecycleEventPayload = InteractionCreatedPayload | InteractionStatusPayload;
|
|
435
|
+
interface InteractionLifecycleEvent<TType extends InteractionLifecycleEventType = InteractionLifecycleEventType> {
|
|
436
|
+
type: TType;
|
|
437
|
+
payload: InteractionLifecycleEventPayload;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Interaction Lifecycle - Single Source of Truth
|
|
442
|
+
*
|
|
443
|
+
* Creates lifecycle events alongside interaction entity transitions.
|
|
444
|
+
* Part of AXON architecture L1 (SDK Core).
|
|
445
|
+
*/
|
|
446
|
+
|
|
447
|
+
interface InteractionCreateInput<TContext = unknown> {
|
|
448
|
+
type?: InteractionType;
|
|
449
|
+
status?: InteractionStatus;
|
|
450
|
+
context: TContext;
|
|
451
|
+
labels?: string[];
|
|
452
|
+
participants?: Array<{
|
|
453
|
+
address: SDKAddress;
|
|
454
|
+
role: "initiator" | "responder" | "observer" | "coordinator";
|
|
455
|
+
metadata?: Record<string, unknown>;
|
|
456
|
+
}>;
|
|
457
|
+
id?: string;
|
|
458
|
+
/** Parent interaction ID for hierarchy linking */
|
|
459
|
+
parentId?: string;
|
|
460
|
+
}
|
|
461
|
+
interface InteractionCreateResult<TContext = unknown> {
|
|
462
|
+
interaction: Interaction<TContext>;
|
|
463
|
+
events: InteractionLifecycleEvent[];
|
|
464
|
+
}
|
|
465
|
+
interface InteractionLifecycleOptions {
|
|
466
|
+
/** Optional per-interaction sequence number */
|
|
467
|
+
sequence?: number;
|
|
468
|
+
/** Optional override for event timestamp */
|
|
469
|
+
timestamp?: number;
|
|
470
|
+
}
|
|
471
|
+
declare function createInteractionWithEvents<TContext = unknown>(input: InteractionCreateInput<TContext>, options?: InteractionLifecycleOptions): InteractionCreateResult<TContext>;
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Tab Configuration for BaseHub
|
|
475
|
+
*
|
|
476
|
+
* Defines available tabs, their metadata, and helper utilities for tab management.
|
|
477
|
+
* All tabs support keyboard shortcuts and visual theming.
|
|
478
|
+
*
|
|
479
|
+
* MECE TAB DESIGN:
|
|
480
|
+
* ----------------
|
|
481
|
+
* Tabs follow Mutually Exclusive, Collectively Exhaustive (MECE) principles:
|
|
482
|
+
*
|
|
483
|
+
* ENABLED TABS (4):
|
|
484
|
+
* - Home - System overview, primitives dashboard
|
|
485
|
+
* - Brain - Knowledge base, data sources, accumulated context
|
|
486
|
+
* - Studio - Unified canvas: Chat + Compose + Execute (merged Zero/Compose/Orchestrate)
|
|
487
|
+
* - World - 3D topology navigation (merged: Discover, Knowledge)
|
|
488
|
+
*
|
|
489
|
+
* DISABLED/MERGED TABS (6):
|
|
490
|
+
* - Zero → Merged into Studio (Chat pane)
|
|
491
|
+
* - Compose → Merged into Studio (Compose pane)
|
|
492
|
+
* - Orchestrate → Merged into Studio (Execution controls)
|
|
493
|
+
* - Discover → Merged into World/Discover section
|
|
494
|
+
* - Monitor → Merged into Studio/Insights panel
|
|
495
|
+
* - Knowledge → Merged into World/Knowledge section
|
|
496
|
+
*
|
|
497
|
+
* RATIONALE:
|
|
498
|
+
* Studio unifies Chat/Compose/Orchestrate into one canvas-first abstraction.
|
|
499
|
+
* All three are complementary activities that benefit from side-by-side visibility.
|
|
500
|
+
*
|
|
501
|
+
* @see CLAUDE.md for architecture documentation
|
|
502
|
+
*/
|
|
503
|
+
/**
|
|
504
|
+
* Available tab identifiers
|
|
505
|
+
*/
|
|
506
|
+
type TabId = "home" | "brain" | "studio" | "zero" | "compose" | "orchestrate" | "discover" | "monitor" | "knowledge" | "world";
|
|
507
|
+
/**
|
|
508
|
+
* Tab configuration metadata
|
|
509
|
+
*/
|
|
510
|
+
interface TabConfig {
|
|
511
|
+
/** Unique identifier for the tab */
|
|
512
|
+
id: TabId;
|
|
513
|
+
/** Display label for the tab */
|
|
514
|
+
label: string;
|
|
515
|
+
/** Description of tab functionality */
|
|
516
|
+
description: string;
|
|
517
|
+
/** Short label for compact UI (rail icons, mobile nav) */
|
|
518
|
+
short: string;
|
|
519
|
+
/** Icon identifier (for future UI integration) */
|
|
520
|
+
icon?: string;
|
|
521
|
+
/** Whether tab is enabled and visible */
|
|
522
|
+
enabled: boolean;
|
|
523
|
+
/** Keyboard shortcut for tab activation */
|
|
524
|
+
keyboardShortcut?: string;
|
|
525
|
+
/** Theme color for tab (hex format) */
|
|
526
|
+
color?: string;
|
|
527
|
+
/** Route href for navigation link */
|
|
528
|
+
href?: string;
|
|
529
|
+
/** Pathname patterns that activate this tab */
|
|
530
|
+
pathPatterns?: string[];
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Coherence Metrics Types (L1 Core)
|
|
535
|
+
*
|
|
536
|
+
* Extracted from L4 Brains to prevent L1→L4 layer violation.
|
|
537
|
+
* These types are shared across layers for coherence measurement.
|
|
538
|
+
*/
|
|
539
|
+
interface CoherenceMetrics$1 {
|
|
540
|
+
/** Connection to factual/contextual reality (0-1) */
|
|
541
|
+
grounding: number;
|
|
542
|
+
/** Self-consistency of reasoning (0-1) */
|
|
543
|
+
internal: number;
|
|
544
|
+
/** Clarity and actionability of output (0-1) */
|
|
545
|
+
crystallization: number;
|
|
546
|
+
/** Overall coherence score (weighted average) */
|
|
547
|
+
overall: number;
|
|
548
|
+
/** Timestamp of measurement */
|
|
549
|
+
timestamp: number;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
type CoherenceMetrics = CoherenceMetrics$1;
|
|
553
|
+
/**
|
|
554
|
+
* Enhanced coherence result with human-readable explanations
|
|
555
|
+
*/
|
|
556
|
+
interface CoherenceResult extends CoherenceMetrics {
|
|
557
|
+
/** Human-readable explanations for each metric */
|
|
558
|
+
explanations: {
|
|
559
|
+
grounding: string;
|
|
560
|
+
internal: string;
|
|
561
|
+
crystallization: string;
|
|
562
|
+
overall: string;
|
|
563
|
+
};
|
|
564
|
+
/** Actionable improvement suggestions */
|
|
565
|
+
suggestions: string[];
|
|
566
|
+
/** Severity level based on overall score */
|
|
567
|
+
severity: "excellent" | "good" | "moderate" | "poor" | "critical";
|
|
568
|
+
}
|
|
569
|
+
interface CoherenceInput {
|
|
570
|
+
/** The agent's output text */
|
|
571
|
+
output: string;
|
|
572
|
+
/** Original context/prompt */
|
|
573
|
+
context?: string;
|
|
574
|
+
/** Previous outputs for consistency checking */
|
|
575
|
+
history?: string[];
|
|
576
|
+
/** Ground truth facts to check against */
|
|
577
|
+
groundTruth?: string[];
|
|
578
|
+
}
|
|
579
|
+
interface CoherenceConfig {
|
|
580
|
+
/** Weight for grounding score (default: 0.4) */
|
|
581
|
+
groundingWeight?: number;
|
|
582
|
+
/** Weight for internal consistency (default: 0.3) */
|
|
583
|
+
internalWeight?: number;
|
|
584
|
+
/** Weight for crystallization (default: 0.3) */
|
|
585
|
+
crystallizationWeight?: number;
|
|
586
|
+
/** Minimum confidence threshold (default: 0.5) */
|
|
587
|
+
minConfidence?: number;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Calculate overall coherence metrics
|
|
591
|
+
*/
|
|
592
|
+
declare function calculateCoherence(input: CoherenceInput, config?: CoherenceConfig): CoherenceMetrics;
|
|
593
|
+
/**
|
|
594
|
+
* Check if coherence meets minimum threshold
|
|
595
|
+
*/
|
|
596
|
+
declare function isCoherent(metrics: CoherenceMetrics, minThreshold?: number): boolean;
|
|
597
|
+
/**
|
|
598
|
+
* Get improvement suggestions based on metrics
|
|
599
|
+
*/
|
|
600
|
+
declare function getCoherenceSuggestions(metrics: CoherenceMetrics): string[];
|
|
601
|
+
/**
|
|
602
|
+
* Calculate enhanced coherence with explanations
|
|
603
|
+
*/
|
|
604
|
+
declare function calculateCoherenceWithExplanations(input: CoherenceInput, config?: CoherenceConfig): CoherenceResult;
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Validation Primitives (IO Boundary Security)
|
|
608
|
+
*
|
|
609
|
+
* Uses Ajv for JSON Schema validation.
|
|
610
|
+
*
|
|
611
|
+
* IMPORTANT: This module is NOT compatible with Vercel Edge Runtime (Middleware)
|
|
612
|
+
* because Ajv uses `new Function()` for schema compilation. For Edge-compatible
|
|
613
|
+
* validation, use a non-eval based library or pre-compiled schemas.
|
|
614
|
+
*/
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Validate untrusted data against a schema
|
|
618
|
+
*
|
|
619
|
+
* @param data - The untrusted data to validate
|
|
620
|
+
* @param schema - JSON Schema to validate against
|
|
621
|
+
* @returns Validated data or null if validation fails
|
|
622
|
+
*/
|
|
623
|
+
declare function validateWithSchema<T>(data: Untrusted<T>, schema: JSONSchema7 | Record<string, unknown>): Validated<T> | null;
|
|
624
|
+
/**
|
|
625
|
+
* Helper to wrap and validate in one step
|
|
626
|
+
*/
|
|
627
|
+
declare function secureValidate<T>(data: T, schema: JSONSchema7 | Record<string, unknown>): Validated<T> | null;
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* SDK Result Type - Railway-Oriented Error Handling
|
|
631
|
+
*
|
|
632
|
+
* Discriminated union type for type-safe error handling without exceptions.
|
|
633
|
+
* Inspired by Rust's Result<T, E> and functional programming patterns.
|
|
634
|
+
*
|
|
635
|
+
* Part of the AXON architecture L1 (SDK Core).
|
|
636
|
+
*/
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Discriminated union representing success or failure
|
|
640
|
+
*
|
|
641
|
+
* @template T - Success value type
|
|
642
|
+
* @template E - Error type (defaults to Error)
|
|
643
|
+
*
|
|
644
|
+
* @example
|
|
645
|
+
* ```typescript
|
|
646
|
+
* const success: SDKResult<number> = ok(42);
|
|
647
|
+
* const failure: SDKResult<number> = err(new Error('failed'));
|
|
648
|
+
*
|
|
649
|
+
* if (isOk(success)) {
|
|
650
|
+
* console.log(success.value); // Type-safe access to value
|
|
651
|
+
* }
|
|
652
|
+
* ```
|
|
653
|
+
*/
|
|
654
|
+
type SDKResult<T, E = Error> = {
|
|
655
|
+
ok: true;
|
|
656
|
+
value: T;
|
|
657
|
+
meta?: ResultMeta;
|
|
658
|
+
} | {
|
|
659
|
+
ok: false;
|
|
660
|
+
error: E;
|
|
661
|
+
meta?: ResultMeta;
|
|
662
|
+
};
|
|
663
|
+
/**
|
|
664
|
+
* Create a successful result
|
|
665
|
+
*
|
|
666
|
+
* @template T - Success value type
|
|
667
|
+
* @param value - The success value
|
|
668
|
+
* @param meta - Optional metadata
|
|
669
|
+
* @returns Success result
|
|
670
|
+
*
|
|
671
|
+
* @example
|
|
672
|
+
* ```typescript
|
|
673
|
+
* const result = ok(42, {
|
|
674
|
+
* duration: 100,
|
|
675
|
+
* timestamp: new Date().toISOString(),
|
|
676
|
+
* source: 'calculateAnswer'
|
|
677
|
+
* });
|
|
678
|
+
* ```
|
|
679
|
+
*/
|
|
680
|
+
declare function ok<T>(value: T, meta?: ResultMeta): SDKResult<T, never>;
|
|
681
|
+
/**
|
|
682
|
+
* Create an error result
|
|
683
|
+
*
|
|
684
|
+
* @template E - Error type
|
|
685
|
+
* @param error - The error value
|
|
686
|
+
* @param meta - Optional metadata
|
|
687
|
+
* @returns Error result
|
|
688
|
+
*
|
|
689
|
+
* @example
|
|
690
|
+
* ```typescript
|
|
691
|
+
* const result = err(new Error('Database connection failed'), {
|
|
692
|
+
* duration: 5000,
|
|
693
|
+
* timestamp: new Date().toISOString(),
|
|
694
|
+
* source: 'connectToDatabase'
|
|
695
|
+
* });
|
|
696
|
+
* ```
|
|
697
|
+
*/
|
|
698
|
+
declare function err<E = Error>(error: E, meta?: ResultMeta): SDKResult<never, E>;
|
|
699
|
+
/**
|
|
700
|
+
* Type guard for successful results
|
|
701
|
+
*
|
|
702
|
+
* @param result - Result to check
|
|
703
|
+
* @returns True if result is Ok
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* ```typescript
|
|
707
|
+
* const result = ok(42);
|
|
708
|
+
* if (isOk(result)) {
|
|
709
|
+
* console.log(result.value); // Type narrowed to { ok: true, value: number }
|
|
710
|
+
* }
|
|
711
|
+
* ```
|
|
712
|
+
*/
|
|
713
|
+
declare function isOk<T, E>(result: SDKResult<T, E>): result is {
|
|
714
|
+
ok: true;
|
|
715
|
+
value: T;
|
|
716
|
+
meta?: ResultMeta;
|
|
717
|
+
};
|
|
718
|
+
/**
|
|
719
|
+
* Type guard for error results
|
|
720
|
+
*
|
|
721
|
+
* @param result - Result to check
|
|
722
|
+
* @returns True if result is Err
|
|
723
|
+
*
|
|
724
|
+
* @example
|
|
725
|
+
* ```typescript
|
|
726
|
+
* const result = err(new Error('failed'));
|
|
727
|
+
* if (isErr(result)) {
|
|
728
|
+
* console.error(result.error); // Type narrowed to { ok: false, error: Error }
|
|
729
|
+
* }
|
|
730
|
+
* ```
|
|
731
|
+
*/
|
|
732
|
+
declare function isErr<T, E>(result: SDKResult<T, E>): result is {
|
|
733
|
+
ok: false;
|
|
734
|
+
error: E;
|
|
735
|
+
meta?: ResultMeta;
|
|
736
|
+
};
|
|
737
|
+
/**
|
|
738
|
+
* Map a successful result to a new value
|
|
739
|
+
*
|
|
740
|
+
* @template T - Input value type
|
|
741
|
+
* @template U - Output value type
|
|
742
|
+
* @template E - Error type
|
|
743
|
+
* @param result - Input result
|
|
744
|
+
* @param fn - Mapping function (only called if Ok)
|
|
745
|
+
* @returns Mapped result
|
|
746
|
+
*
|
|
747
|
+
* @example
|
|
748
|
+
* ```typescript
|
|
749
|
+
* const result = ok(42);
|
|
750
|
+
* const doubled = map(result, x => x * 2); // ok(84)
|
|
751
|
+
*
|
|
752
|
+
* const error = err(new Error('failed'));
|
|
753
|
+
* const mapped = map(error, x => x * 2); // err(Error('failed'))
|
|
754
|
+
* ```
|
|
755
|
+
*/
|
|
756
|
+
declare function map<T, U, E>(result: SDKResult<T, E>, fn: (value: T) => U): SDKResult<U, E>;
|
|
757
|
+
/**
|
|
758
|
+
* Chain operations that return Results (flatMap/bind)
|
|
759
|
+
*
|
|
760
|
+
* @template T - Input value type
|
|
761
|
+
* @template U - Output value type
|
|
762
|
+
* @template E - Error type
|
|
763
|
+
* @param result - Input result
|
|
764
|
+
* @param fn - Function returning a Result (only called if Ok)
|
|
765
|
+
* @returns Flattened result
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* ```typescript
|
|
769
|
+
* const parseNumber = (s: string): SDKResult<number> =>
|
|
770
|
+
* isNaN(Number(s)) ? err(new Error('Not a number')) : ok(Number(s));
|
|
771
|
+
*
|
|
772
|
+
* const input = ok("42");
|
|
773
|
+
* const parsed = flatMap(input, parseNumber); // ok(42)
|
|
774
|
+
*
|
|
775
|
+
* const invalid = ok("xyz");
|
|
776
|
+
* const failed = flatMap(invalid, parseNumber); // err(Error('Not a number'))
|
|
777
|
+
* ```
|
|
778
|
+
*/
|
|
779
|
+
declare function flatMap<T, U, E>(result: SDKResult<T, E>, fn: (value: T) => SDKResult<U, E>): SDKResult<U, E>;
|
|
780
|
+
/**
|
|
781
|
+
* Standard error codes for store operations
|
|
782
|
+
*/
|
|
783
|
+
type StoreErrorCode = "DB_ERROR" | "NOT_FOUND" | "CONFLICT" | "VALIDATION_ERROR";
|
|
784
|
+
/**
|
|
785
|
+
* Store operation error
|
|
786
|
+
*/
|
|
787
|
+
interface StoreError {
|
|
788
|
+
code: StoreErrorCode;
|
|
789
|
+
message: string;
|
|
790
|
+
cause?: Error;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Registry primitives for type-safe key-value storage with LRU eviction and TTL expiration
|
|
795
|
+
* Part of the Terminals.tech SDK core primitives
|
|
796
|
+
*/
|
|
797
|
+
interface Registry<K, V> {
|
|
798
|
+
get(key: K): V | undefined;
|
|
799
|
+
set(key: K, value: V): void;
|
|
800
|
+
has(key: K): boolean;
|
|
801
|
+
delete(key: K): boolean;
|
|
802
|
+
clear(): void;
|
|
803
|
+
size(): number;
|
|
804
|
+
keys(): IterableIterator<K>;
|
|
805
|
+
values(): IterableIterator<V>;
|
|
806
|
+
entries(): IterableIterator<[K, V]>;
|
|
807
|
+
toArray(): V[];
|
|
808
|
+
}
|
|
809
|
+
interface RegistryConfig<K, V> {
|
|
810
|
+
maxSize?: number;
|
|
811
|
+
ttlMs?: number;
|
|
812
|
+
onEvict?: (key: K, value: V) => void;
|
|
813
|
+
onExpire?: (key: K, value: V) => void;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Factory: Basic registry with optional config
|
|
817
|
+
*/
|
|
818
|
+
declare function createRegistry<K, V>(config?: RegistryConfig<K, V>): Registry<K, V>;
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Node in a directed acyclic graph
|
|
822
|
+
*/
|
|
823
|
+
interface DAGNode<T> {
|
|
824
|
+
id: string;
|
|
825
|
+
data: T;
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Edge connecting two nodes in a DAG
|
|
829
|
+
*/
|
|
830
|
+
interface DAGEdge<E = void> {
|
|
831
|
+
from: string;
|
|
832
|
+
to: string;
|
|
833
|
+
data?: E;
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* DAG validation error with specific type classification
|
|
837
|
+
*/
|
|
838
|
+
declare class DAGValidationError extends Error {
|
|
839
|
+
readonly type: "cycle" | "missing_node" | "duplicate_node" | "self_loop";
|
|
840
|
+
constructor(message: string, type: "cycle" | "missing_node" | "duplicate_node" | "self_loop");
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Directed Acyclic Graph with efficient traversal and validation
|
|
844
|
+
*/
|
|
845
|
+
interface DAG<N, E = void> {
|
|
846
|
+
readonly nodes: ReadonlyMap<string, DAGNode<N>>;
|
|
847
|
+
readonly edges: ReadonlyArray<DAGEdge<E>>;
|
|
848
|
+
getNode(id: string): DAGNode<N> | undefined;
|
|
849
|
+
getIncoming(nodeId: string): DAGEdge<E>[];
|
|
850
|
+
getOutgoing(nodeId: string): DAGEdge<E>[];
|
|
851
|
+
getAncestors(nodeId: string): string[];
|
|
852
|
+
getDescendants(nodeId: string): string[];
|
|
853
|
+
getRoots(): string[];
|
|
854
|
+
getLeaves(): string[];
|
|
855
|
+
topologicalSort(): string[];
|
|
856
|
+
levels(): string[][];
|
|
857
|
+
bfs(startId: string, visitor: (node: DAGNode<N>) => boolean | void): void;
|
|
858
|
+
dfs(startId: string, visitor: (node: DAGNode<N>) => boolean | void): void;
|
|
859
|
+
hasCycle(): boolean;
|
|
860
|
+
validate(): SDKResult<void, DAGValidationError[]>;
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Create a DAG with validation
|
|
864
|
+
*
|
|
865
|
+
* @param nodes - Array of nodes to include in the graph
|
|
866
|
+
* @param edges - Array of edges connecting nodes
|
|
867
|
+
* @returns Result containing the DAG or validation errors
|
|
868
|
+
*
|
|
869
|
+
* @example
|
|
870
|
+
* ```typescript
|
|
871
|
+
* const result = createDAG(
|
|
872
|
+
* [
|
|
873
|
+
* { id: 'a', data: { value: 1 } },
|
|
874
|
+
* { id: 'b', data: { value: 2 } },
|
|
875
|
+
* { id: 'c', data: { value: 3 } }
|
|
876
|
+
* ],
|
|
877
|
+
* [
|
|
878
|
+
* { from: 'a', to: 'b' },
|
|
879
|
+
* { from: 'b', to: 'c' }
|
|
880
|
+
* ]
|
|
881
|
+
* )
|
|
882
|
+
*
|
|
883
|
+
* if (result.ok) {
|
|
884
|
+
* const sorted = result.value.topologicalSort() // ['a', 'b', 'c']
|
|
885
|
+
* const levels = result.value.levels() // [['a'], ['b'], ['c']]
|
|
886
|
+
* }
|
|
887
|
+
* ```
|
|
888
|
+
*/
|
|
889
|
+
declare function createDAG<N, E = void>(nodes: DAGNode<N>[], edges: DAGEdge<E>[]): SDKResult<DAG<N, E>, DAGValidationError[]>;
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Unified SDK Types
|
|
893
|
+
*
|
|
894
|
+
* Canonical type definitions for the Terminals.tech SDK.
|
|
895
|
+
* Isomorphic types that work across browser/server/edge/webcontainer environments.
|
|
896
|
+
*
|
|
897
|
+
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
898
|
+
*
|
|
899
|
+
* Type Organization:
|
|
900
|
+
* - Environment & Config
|
|
901
|
+
* - Storage Adapters
|
|
902
|
+
* - HTTP Client
|
|
903
|
+
* - LLM Providers
|
|
904
|
+
* - MCP (Model Context Protocol)
|
|
905
|
+
* - Authentication
|
|
906
|
+
* - Runners (code execution)
|
|
907
|
+
* - Context Injection
|
|
908
|
+
* - Events & Graphs
|
|
909
|
+
* - Embeddings
|
|
910
|
+
* - Observer-Oriented OOP Primitives (Observable pattern)
|
|
911
|
+
* - Layer-specific state types (Execution, Reasoning, Connection)
|
|
912
|
+
*
|
|
913
|
+
* @module sdk-types
|
|
914
|
+
*/
|
|
915
|
+
|
|
916
|
+
interface NodePolicy$1 {
|
|
917
|
+
fs?: {
|
|
918
|
+
mode?: "sandboxed" | "full";
|
|
919
|
+
allowedPaths?: string[];
|
|
920
|
+
};
|
|
921
|
+
network?: {
|
|
922
|
+
egress?: "ask" | "deny" | "allow:list";
|
|
923
|
+
allowList?: string[];
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
interface StackPolicies$1 {
|
|
927
|
+
fs?: {
|
|
928
|
+
mode?: "sandboxed" | "full";
|
|
929
|
+
allowedPaths?: string[];
|
|
930
|
+
};
|
|
931
|
+
network?: {
|
|
932
|
+
egress?: "ask" | "deny" | "allow:list";
|
|
933
|
+
allowList?: string[];
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* Phase Dynamics Primitives
|
|
939
|
+
*
|
|
940
|
+
* Minimal utilities for coupled-oscillator dynamics and synchronization metrics.
|
|
941
|
+
* Intended for L1 use by L3 mesh metrics, L4 brains (swarm), and L2 nodes.
|
|
942
|
+
*/
|
|
943
|
+
interface OrderParameter {
|
|
944
|
+
/** Synchronization magnitude (0..1) */
|
|
945
|
+
R: number;
|
|
946
|
+
/** Collective phase (radians, -π..π) */
|
|
947
|
+
psi: number;
|
|
948
|
+
}
|
|
949
|
+
declare function wrapTo2Pi(theta: number): number;
|
|
950
|
+
declare function wrapToPi(theta: number): number;
|
|
951
|
+
/**
|
|
952
|
+
* Kuramoto order parameter:
|
|
953
|
+
* R e^{iψ} = (1/N) Σ e^{iθ_j}
|
|
954
|
+
*/
|
|
955
|
+
declare function orderParameter(phases: ArrayLike<number>): OrderParameter;
|
|
956
|
+
/**
|
|
957
|
+
* Phase Locking Value (PLV) between two phase time-series:
|
|
958
|
+
* PLV = |⟨exp(i(φ_a - φ_b))⟩|
|
|
959
|
+
*/
|
|
960
|
+
declare function phaseLockingValue(phiA: ArrayLike<number>, phiB: ArrayLike<number>): number;
|
|
961
|
+
interface KuramotoStepOptions {
|
|
962
|
+
/**
|
|
963
|
+
* If true, wraps resulting phases to [-π, π) (default: true).
|
|
964
|
+
* When false, phases are allowed to drift unbounded.
|
|
965
|
+
*/
|
|
966
|
+
wrap?: boolean;
|
|
967
|
+
/**
|
|
968
|
+
* If true, normalize coupling by per-node degree (default: true).
|
|
969
|
+
* Stabilizes dynamics across heterogeneous adjacency.
|
|
970
|
+
*/
|
|
971
|
+
normalizeCoupling?: boolean;
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Advance one Euler step of Kuramoto dynamics:
|
|
975
|
+
* dθ_i/dt = ω_i + K * Σ_j A_ij sin(θ_j - θ_i)
|
|
976
|
+
*
|
|
977
|
+
* - If `adjacency` is undefined, assumes all-to-all coupling (excluding self).
|
|
978
|
+
* - If `omega` is a scalar, uses the same ω for all oscillators.
|
|
979
|
+
*
|
|
980
|
+
* Returns a new Float32Array (pure; does not mutate the input phases).
|
|
981
|
+
*/
|
|
982
|
+
declare function kuramotoStep(phases: ArrayLike<number>, omega: ArrayLike<number> | number, K: number, adjacency: ArrayLike<ArrayLike<number>> | undefined, dt: number, opts?: KuramotoStepOptions): Float32Array;
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* EventBus - Type-safe event emitter pattern
|
|
986
|
+
*
|
|
987
|
+
* Unified event infrastructure for Terminals.tech.
|
|
988
|
+
* Supports both generic pub/sub and layer-aware AXON signals.
|
|
989
|
+
*
|
|
990
|
+
* @example
|
|
991
|
+
* ```typescript
|
|
992
|
+
* // Define event types
|
|
993
|
+
* type MyEvents = {
|
|
994
|
+
* 'user:login': { userId: string; timestamp: number }
|
|
995
|
+
* 'user:logout': { userId: string }
|
|
996
|
+
* 'error': Error
|
|
997
|
+
* }
|
|
998
|
+
*
|
|
999
|
+
* // Create typed bus
|
|
1000
|
+
* const bus = createEventBus<MyEvents>()
|
|
1001
|
+
*
|
|
1002
|
+
* // Subscribe with type safety
|
|
1003
|
+
* const unsub = bus.on('user:login', (payload) => {
|
|
1004
|
+
* console.log(payload.userId) // TypeScript knows this is string
|
|
1005
|
+
* })
|
|
1006
|
+
*
|
|
1007
|
+
* // Emit with type checking
|
|
1008
|
+
* bus.emit('user:login', { userId: '123', timestamp: Date.now() })
|
|
1009
|
+
*
|
|
1010
|
+
* // Clean up
|
|
1011
|
+
* unsub()
|
|
1012
|
+
* ```
|
|
1013
|
+
*/
|
|
1014
|
+
|
|
1015
|
+
/**
|
|
1016
|
+
* Signal types for cross-layer communication
|
|
1017
|
+
*/
|
|
1018
|
+
type SignalType = "health_update" | "circuit_change" | "convergence_update" | "coherence_update" | "resonance_update" | "tensor_state_update" | "task_complete" | "task_failed" | "adaptation_required" | "backpressure_warning" | "audio_metrics_update" | "mesh_update" | "mesh_query" | "session_state_change" | "skill_capture_started" | "skill_action_recorded" | "skill_capture_completed" | "skill_crystallized" | "skill_training_started" | "skill_training_completed" | "skill_artifact_activated" | "skill_suggested" | "skill_executed" | "skill_peer_review" | "skill_delegation" | "skill_agent_refine" | "skill_selection" | "skill_backpressure" | "skill_budget_exceeded" | "skill_error" | "interaction_created" | "interaction_status_changed" | "deploy_scaffold" | "deploy_push" | "deploy_build" | "deploy_status" | "deploy_preview" | "deploy_live" | "deploy_error" | "potentiation_rising" | "potentiation_peak" | "potentiation_discharge" | "potentiation_reset" | "action_dispatched" | "action_executed" | "action_failed" | "combo_completed" | "input_surface_changed" | "forge_scene_saved" | "forge_iteration_recorded" | "forge_profile_crystallized" | "forge_profile_requested" | "integration_connected" | "integration_disconnected" | "integration_heartbeat" | "integration_error" | "ui_navigation" | "ui_surface_opened" | "ui_surface_closed" | "ui_interaction" | "ui_error_shown" | "ui_search" | "artifact_preview" | "manifold_node_added" | "manifold_edge_added" | "manifold_query" | "manifold_snapshot" | "connector_status_changed" | "connector_sync_started" | "connector_sync_complete" | "connector_sync_error" | "connector_document_indexed" | "graph_entity_upserted" | "graph_relationship_added" | "graph_traversal_complete" | "intent_signal_emitted" | "oscillator_phase_updated" | "oscillator_suggestion_generated" | "journey_note_created" | "journey_note_deleted" | "journey_edge_created" | "journey_cluster_created" | "journey_replay_entered" | "journey_replay_exited" | "journey_spatial_navigate" | "journey_completed" | "boundary_crossed" | "boundary_sealed" | "convergence_declared" | "convergence_lost" | "crystallization_declared" | "crystallization_melted" | "chat_message_sent" | "chat_message_received" | "chat_error" | "coherence_gate_accepted" | "coherence_gate_rejected" | "manifold_geodesic_computed" | "manifold_distance_measured" | "sematon_created" | "sematon_witnessed" | "sematon_folded" | "sematon_realized" | "sematon_expired";
|
|
1019
|
+
/**
|
|
1020
|
+
* Layer-aware signal for AXON cross-layer communication
|
|
1021
|
+
*/
|
|
1022
|
+
interface Signal<T = unknown> {
|
|
1023
|
+
id: string;
|
|
1024
|
+
type: SignalType;
|
|
1025
|
+
source: LayerLevel;
|
|
1026
|
+
target: LayerLevel;
|
|
1027
|
+
payload: T;
|
|
1028
|
+
timestamp: number;
|
|
1029
|
+
correlationId?: string;
|
|
1030
|
+
/** Interaction ID for causal chain tracking across the AXON signal flow */
|
|
1031
|
+
interactionId?: string;
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Handler for layer-aware signals
|
|
1035
|
+
*/
|
|
1036
|
+
interface SignalHandler<T = unknown> {
|
|
1037
|
+
(signal: Signal<T>): void | Promise<void>;
|
|
1038
|
+
}
|
|
1039
|
+
type EventHandler<T> = (payload: T) => void | Promise<void>;
|
|
1040
|
+
type WildcardHandler<Events> = <K extends keyof Events>(event: K, payload: Events[K]) => void | Promise<void>;
|
|
1041
|
+
interface TypedEventBus<Events extends Record<string, unknown>> {
|
|
1042
|
+
/**
|
|
1043
|
+
* Subscribe to an event
|
|
1044
|
+
* @returns Unsubscribe function
|
|
1045
|
+
*/
|
|
1046
|
+
on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): () => void;
|
|
1047
|
+
/**
|
|
1048
|
+
* Subscribe to an event for a single emission
|
|
1049
|
+
* @returns Unsubscribe function
|
|
1050
|
+
*/
|
|
1051
|
+
once<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): () => void;
|
|
1052
|
+
/**
|
|
1053
|
+
* Unsubscribe from an event
|
|
1054
|
+
*/
|
|
1055
|
+
off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): void;
|
|
1056
|
+
/**
|
|
1057
|
+
* Emit an event to all subscribers
|
|
1058
|
+
*/
|
|
1059
|
+
emit<K extends keyof Events>(event: K, payload: Events[K]): void;
|
|
1060
|
+
/**
|
|
1061
|
+
* Emit and wait for all async handlers
|
|
1062
|
+
*/
|
|
1063
|
+
emitAsync<K extends keyof Events>(event: K, payload: Events[K]): Promise<void>;
|
|
1064
|
+
/**
|
|
1065
|
+
* Subscribe to all events
|
|
1066
|
+
* @returns Unsubscribe function
|
|
1067
|
+
*/
|
|
1068
|
+
onAny(handler: WildcardHandler<Events>): () => void;
|
|
1069
|
+
/**
|
|
1070
|
+
* Remove all listeners for an event, or all listeners
|
|
1071
|
+
*/
|
|
1072
|
+
removeAllListeners<K extends keyof Events>(event?: K): void;
|
|
1073
|
+
/**
|
|
1074
|
+
* Get listener count for an event
|
|
1075
|
+
*/
|
|
1076
|
+
listenerCount<K extends keyof Events>(event: K): number;
|
|
1077
|
+
/**
|
|
1078
|
+
* Get all registered event names
|
|
1079
|
+
*/
|
|
1080
|
+
eventNames(): Array<keyof Events>;
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Create a type-safe event bus
|
|
1084
|
+
*/
|
|
1085
|
+
declare function createEventBus<Events extends Record<string, unknown>>(): TypedEventBus<Events>;
|
|
1086
|
+
type Unsubscribe = () => void;
|
|
1087
|
+
/**
|
|
1088
|
+
* SignalBus interface for AXON cross-layer communication
|
|
1089
|
+
*/
|
|
1090
|
+
interface SignalBus {
|
|
1091
|
+
/**
|
|
1092
|
+
* Emit a signal to all matching subscribers
|
|
1093
|
+
*/
|
|
1094
|
+
emit<T>(type: SignalType, source: LayerLevel, target: LayerLevel, payload: T, correlationId?: string, interactionId?: string): Signal<T>;
|
|
1095
|
+
/**
|
|
1096
|
+
* Subscribe to signals matching criteria
|
|
1097
|
+
*/
|
|
1098
|
+
subscribe(type: SignalType | "*", handler: SignalHandler, options?: {
|
|
1099
|
+
sourceLayer?: LayerLevel;
|
|
1100
|
+
targetLayer?: LayerLevel;
|
|
1101
|
+
}): Unsubscribe;
|
|
1102
|
+
/**
|
|
1103
|
+
* Subscribe to signals from a specific layer
|
|
1104
|
+
*/
|
|
1105
|
+
subscribeFromLayer(layer: LayerLevel, handler: SignalHandler): Unsubscribe;
|
|
1106
|
+
/**
|
|
1107
|
+
* Subscribe to signals targeting a specific layer
|
|
1108
|
+
*/
|
|
1109
|
+
subscribeToLayer(layer: LayerLevel, handler: SignalHandler): Unsubscribe;
|
|
1110
|
+
/**
|
|
1111
|
+
* Get recent signals for debugging
|
|
1112
|
+
*/
|
|
1113
|
+
getRecentSignals(count?: number): Signal[];
|
|
1114
|
+
/**
|
|
1115
|
+
* Get signals by correlation ID
|
|
1116
|
+
*/
|
|
1117
|
+
getCorrelated(correlationId: string): Signal[];
|
|
1118
|
+
/**
|
|
1119
|
+
* Clear all subscriptions (for testing)
|
|
1120
|
+
*/
|
|
1121
|
+
clearSubscriptions(): void;
|
|
1122
|
+
/**
|
|
1123
|
+
* Clear signal log (for testing)
|
|
1124
|
+
*/
|
|
1125
|
+
clearLog(): void;
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Create a layer-aware signal bus for AXON cross-layer communication
|
|
1129
|
+
*/
|
|
1130
|
+
declare function createSignalBus(maxLogSize?: number): SignalBus;
|
|
1131
|
+
/**
|
|
1132
|
+
* Get or create the global signal bus instance
|
|
1133
|
+
*/
|
|
1134
|
+
declare function getSignalBus(): SignalBus;
|
|
1135
|
+
/**
|
|
1136
|
+
* Convenience: Emit a signal on the global bus
|
|
1137
|
+
*/
|
|
1138
|
+
declare function emitSignal<T>(type: SignalType, source: LayerLevel, target: LayerLevel, payload: T, correlationId?: string, interactionId?: string): Signal<T>;
|
|
1139
|
+
/**
|
|
1140
|
+
* Convenience: Subscribe to signals on the global bus
|
|
1141
|
+
*/
|
|
1142
|
+
declare function subscribeToSignals(type: SignalType | "*", handler: SignalHandler, options?: {
|
|
1143
|
+
sourceLayer?: LayerLevel;
|
|
1144
|
+
targetLayer?: LayerLevel;
|
|
1145
|
+
}): Unsubscribe;
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* NeuroState - Unified Brain State Management
|
|
1149
|
+
*
|
|
1150
|
+
* Centralizes all cognitive signals (Coherence, Convergence, Load) into a single
|
|
1151
|
+
* source of truth that drives the Computer Construct experience.
|
|
1152
|
+
*
|
|
1153
|
+
* Bridges the "Internal" (Coherence) with the "External" (Convergence/Mesh)
|
|
1154
|
+
* to derive high-level "Mood" and system responsiveness.
|
|
1155
|
+
*/
|
|
1156
|
+
|
|
1157
|
+
type SystemMood = "dormant" | "focused" | "flow" | "chaotic" | "overloaded";
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
* Real-time audio metrics from frequency analysis
|
|
1161
|
+
*/
|
|
1162
|
+
interface AudioMetrics {
|
|
1163
|
+
/** Low frequency energy (bass) normalized 0-1 */
|
|
1164
|
+
bass: number;
|
|
1165
|
+
/** High frequency energy normalized 0-1 */
|
|
1166
|
+
high: number;
|
|
1167
|
+
/** Spectral centroid / brightness normalized 0-1 */
|
|
1168
|
+
brightness: number;
|
|
1169
|
+
/** Spectral entropy / chaos measure normalized 0-1 */
|
|
1170
|
+
entropy: number;
|
|
1171
|
+
/** Raw frequency bin data */
|
|
1172
|
+
raw: Uint8Array;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* L1 AudioSource — Omniprovider audio source abstraction
|
|
1177
|
+
*
|
|
1178
|
+
* Every audio source (playlist, generative, Lyria, external, DAW) implements
|
|
1179
|
+
* this interface. SemanticOscillator provides Kuramoto-compatible phase coupling
|
|
1180
|
+
* between audio parameters and app state signals.
|
|
1181
|
+
*/
|
|
1182
|
+
|
|
1183
|
+
/** Continuous parameter with Kuramoto phase coupling */
|
|
1184
|
+
interface SemanticOscillator {
|
|
1185
|
+
readonly name: string;
|
|
1186
|
+
value: number;
|
|
1187
|
+
set(v: number): void;
|
|
1188
|
+
/** Kuramoto coupling: dv = K * sin(target - self) */
|
|
1189
|
+
couple(targetPhase: number, strength: number): void;
|
|
1190
|
+
}
|
|
1191
|
+
/** Unified audio source interface — any provider, same shape */
|
|
1192
|
+
interface AudioSource {
|
|
1193
|
+
readonly id: string;
|
|
1194
|
+
readonly type: "playlist" | "generative" | "lyria" | "external" | "daw";
|
|
1195
|
+
connect(destination: AudioNode): void;
|
|
1196
|
+
disconnect(): void;
|
|
1197
|
+
getMetrics(): AudioMetrics | null;
|
|
1198
|
+
play(): Promise<void>;
|
|
1199
|
+
pause(): void;
|
|
1200
|
+
dispose(): void;
|
|
1201
|
+
readonly oscillators: ReadonlyMap<string, SemanticOscillator>;
|
|
1202
|
+
}
|
|
1203
|
+
/** Platform-level audio configuration */
|
|
1204
|
+
interface AudioSourceConfig {
|
|
1205
|
+
defaultSource: AudioSource["type"];
|
|
1206
|
+
generativePreset?: {
|
|
1207
|
+
root: number;
|
|
1208
|
+
harmonicSeries: number[];
|
|
1209
|
+
filterCutoff: number;
|
|
1210
|
+
reverbWet: number;
|
|
1211
|
+
};
|
|
1212
|
+
lyriaPreset?: {
|
|
1213
|
+
temperature: number;
|
|
1214
|
+
guidance: number;
|
|
1215
|
+
genreMix: Record<string, number>;
|
|
1216
|
+
density: number;
|
|
1217
|
+
brightness: number;
|
|
1218
|
+
};
|
|
1219
|
+
couplingStrength?: number;
|
|
1220
|
+
entrainmentMode?: string;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
/**
|
|
1224
|
+
* Platform Configuration Types
|
|
1225
|
+
*
|
|
1226
|
+
* Each product powered by Terminals OS provides a PlatformConfig
|
|
1227
|
+
* that customizes the workspace shell (NavigationRail, ContextBar,
|
|
1228
|
+
* theme colors, identity).
|
|
1229
|
+
*
|
|
1230
|
+
* @module platform/types
|
|
1231
|
+
*/
|
|
1232
|
+
|
|
1233
|
+
interface PlatformIdentity {
|
|
1234
|
+
/** Unique platform identifier */
|
|
1235
|
+
id: string;
|
|
1236
|
+
/** Display name */
|
|
1237
|
+
name: string;
|
|
1238
|
+
/** One-line tagline */
|
|
1239
|
+
tagline: string;
|
|
1240
|
+
/** Attribution line */
|
|
1241
|
+
poweredBy: string;
|
|
1242
|
+
/** Production domain for this platform (e.g. "pathfind.tech"). Omit for root OS. */
|
|
1243
|
+
domain?: string;
|
|
1244
|
+
/** Path for cross-domain auth handoff (e.g. "/auth/handoff"). Required when domain is set. */
|
|
1245
|
+
handoffPath?: string;
|
|
1246
|
+
}
|
|
1247
|
+
/** Surface appearance tokens for glassmorphic UI */
|
|
1248
|
+
interface SurfaceTokens {
|
|
1249
|
+
/** Page void background (hex, e.g. "#020303") */
|
|
1250
|
+
void: string;
|
|
1251
|
+
/** Card/panel background (CSS value, e.g. "rgba(255,255,255,0.03)") */
|
|
1252
|
+
cardBg: string;
|
|
1253
|
+
/** Default border (CSS value) */
|
|
1254
|
+
border: string;
|
|
1255
|
+
/** Hover border (CSS value) */
|
|
1256
|
+
borderHover: string;
|
|
1257
|
+
/** Backdrop blur class (e.g. "backdrop-blur-md") */
|
|
1258
|
+
blur: string;
|
|
1259
|
+
/** Selection background (hex) */
|
|
1260
|
+
selectionBg: string;
|
|
1261
|
+
/** Selection text (hex) */
|
|
1262
|
+
selectionText: string;
|
|
1263
|
+
}
|
|
1264
|
+
/** Animation timing presets */
|
|
1265
|
+
interface AnimationTokens {
|
|
1266
|
+
/** Crystallize reveal duration per element (ms) */
|
|
1267
|
+
crystallizeDuration: number;
|
|
1268
|
+
/** Stagger delay between elements (ms) */
|
|
1269
|
+
staggerDelay: number;
|
|
1270
|
+
/** Border rotation speed (s) */
|
|
1271
|
+
borderSpinDuration: number;
|
|
1272
|
+
/** Breathing/pulse cycle (s) */
|
|
1273
|
+
breatheDuration: number;
|
|
1274
|
+
/** Edge pulse cycle (s) */
|
|
1275
|
+
edgePulseDuration: number;
|
|
1276
|
+
/** GSAP scrub smoothing (0-1) */
|
|
1277
|
+
scrubSmoothing: number;
|
|
1278
|
+
}
|
|
1279
|
+
interface PlatformTheme {
|
|
1280
|
+
/** Primary accent color (hex) */
|
|
1281
|
+
accent: string;
|
|
1282
|
+
/** Glow variant for dark backgrounds (hex) */
|
|
1283
|
+
accentGlow: string;
|
|
1284
|
+
/** Optional per-layer color overrides */
|
|
1285
|
+
layerOverrides?: Partial<Record<"L1" | "L2" | "L3" | "L4" | "L5", string>>;
|
|
1286
|
+
/** Surface appearance tokens */
|
|
1287
|
+
surfaces?: SurfaceTokens;
|
|
1288
|
+
/** Animation timing tokens */
|
|
1289
|
+
animations?: AnimationTokens;
|
|
1290
|
+
}
|
|
1291
|
+
interface QuickAction {
|
|
1292
|
+
label: string;
|
|
1293
|
+
icon: string;
|
|
1294
|
+
href: string;
|
|
1295
|
+
layer: "L1" | "L2" | "L3" | "L4" | "L5";
|
|
1296
|
+
}
|
|
1297
|
+
interface AmbientFieldConfig {
|
|
1298
|
+
particleCount: number;
|
|
1299
|
+
colors: string[];
|
|
1300
|
+
connectionDistance: number;
|
|
1301
|
+
connectionOpacity: number;
|
|
1302
|
+
particleOpacity: number;
|
|
1303
|
+
particleSize: [number, number];
|
|
1304
|
+
fps: number;
|
|
1305
|
+
}
|
|
1306
|
+
interface DashboardConfig {
|
|
1307
|
+
kpiRefreshMs?: number;
|
|
1308
|
+
insightRefreshMs?: number;
|
|
1309
|
+
showPipeline?: boolean;
|
|
1310
|
+
showAmbientStrip?: boolean;
|
|
1311
|
+
}
|
|
1312
|
+
interface LobbyConfig {
|
|
1313
|
+
ambientField?: AmbientFieldConfig;
|
|
1314
|
+
shaderOpacity?: number;
|
|
1315
|
+
showIntelligencePulse?: boolean;
|
|
1316
|
+
quickActions?: QuickAction[];
|
|
1317
|
+
moodToShaderMode?: Partial<Record<SystemMood, string>>;
|
|
1318
|
+
dashboard?: DashboardConfig;
|
|
1319
|
+
}
|
|
1320
|
+
interface PlatformConfig {
|
|
1321
|
+
identity: PlatformIdentity;
|
|
1322
|
+
theme: PlatformTheme;
|
|
1323
|
+
/** Override enabled tabs — merged with global TAB_CONFIGS */
|
|
1324
|
+
tabOverrides?: Partial<Record<TabId, Partial<TabConfig>>>;
|
|
1325
|
+
/** Landing page component path for dynamic import */
|
|
1326
|
+
landingComponent?: string;
|
|
1327
|
+
/** Lobby/home tab configuration */
|
|
1328
|
+
lobby?: LobbyConfig;
|
|
1329
|
+
/** Audio source configuration for this platform */
|
|
1330
|
+
audio?: AudioSourceConfig;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
/**
|
|
1334
|
+
* Terminal SDK — High-level Terminal management
|
|
1335
|
+
*
|
|
1336
|
+
* Simplified API for terminal identity, interactions, and lifecycle.
|
|
1337
|
+
* Hides Machine, Brain, Interface, MeshCoordinator, A2A, MCP internals.
|
|
1338
|
+
*
|
|
1339
|
+
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
1340
|
+
* @module sdk/terminal
|
|
1341
|
+
*/
|
|
1342
|
+
|
|
1343
|
+
type terminal_Interaction<TContext = unknown> = Interaction<TContext>;
|
|
1344
|
+
type terminal_InteractionStatus = InteractionStatus;
|
|
1345
|
+
type terminal_InteractionType = InteractionType;
|
|
1346
|
+
type terminal_LayerLevel = LayerLevel;
|
|
1347
|
+
type terminal_PlatformConfig = PlatformConfig;
|
|
1348
|
+
type terminal_PlatformIdentity = PlatformIdentity;
|
|
1349
|
+
type terminal_PlatformTheme = PlatformTheme;
|
|
1350
|
+
type terminal_SurfaceId = SurfaceId;
|
|
1351
|
+
type terminal_TaskStatus = TaskStatus;
|
|
1352
|
+
declare const terminal_createInteractionWithEvents: typeof createInteractionWithEvents;
|
|
1353
|
+
declare namespace terminal {
|
|
1354
|
+
export { type terminal_Interaction as Interaction, type terminal_InteractionStatus as InteractionStatus, type terminal_InteractionType as InteractionType, type terminal_LayerLevel as LayerLevel, type terminal_PlatformConfig as PlatformConfig, type terminal_PlatformIdentity as PlatformIdentity, type terminal_PlatformTheme as PlatformTheme, type terminal_SurfaceId as SurfaceId, type terminal_TaskStatus as TaskStatus, createInteractionWithEvents as createInteraction, terminal_createInteractionWithEvents as createInteractionWithEvents };
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
/**
|
|
1358
|
+
* RetryStrategy - Unified retry pattern for async operations
|
|
1359
|
+
*
|
|
1360
|
+
* ## Architectural Note
|
|
1361
|
+
*
|
|
1362
|
+
* This module (base/retry.ts) provides **direct async wrappers** for imperative patterns.
|
|
1363
|
+
* It is intentionally distinct from primitives/middleware.ts which provides
|
|
1364
|
+
* **functional middleware composition** with the Middleware<T, R> type.
|
|
1365
|
+
*
|
|
1366
|
+
* The distinction serves different use cases:
|
|
1367
|
+
* - **base/retry.ts**: Direct function wrapping for imperative code
|
|
1368
|
+
* - `withRetry(fn, strategy)` - wraps and executes immediately
|
|
1369
|
+
* - `retryable(fn, strategy)` - returns a retry-wrapped function
|
|
1370
|
+
* - `createCircuitBreaker(options)` - stateful circuit breaker instance
|
|
1371
|
+
*
|
|
1372
|
+
* - **primitives/middleware.ts**: Composable middleware chains
|
|
1373
|
+
* - `compose(...middlewares)` - functional composition
|
|
1374
|
+
* - `withResilience(config)` - declarative resilience configuration
|
|
1375
|
+
* - Designed for pipeline-style processing
|
|
1376
|
+
*
|
|
1377
|
+
* Both are valid patterns for different contexts. Do not force unification.
|
|
1378
|
+
*
|
|
1379
|
+
* @example
|
|
1380
|
+
* ```typescript
|
|
1381
|
+
* // Use exponential backoff
|
|
1382
|
+
* const result = await withRetry(
|
|
1383
|
+
* () => fetch('/api/data'),
|
|
1384
|
+
* exponentialBackoff({ maxAttempts: 3, baseDelayMs: 100 })
|
|
1385
|
+
* )
|
|
1386
|
+
*
|
|
1387
|
+
* // Custom strategy
|
|
1388
|
+
* const customStrategy: RetryStrategy = {
|
|
1389
|
+
* maxAttempts: 5,
|
|
1390
|
+
* baseDelayMs: 200,
|
|
1391
|
+
* maxDelayMs: 5000,
|
|
1392
|
+
* shouldRetry: (error, attempt) => error.message !== 'unauthorized'
|
|
1393
|
+
* }
|
|
1394
|
+
* ```
|
|
1395
|
+
*/
|
|
1396
|
+
interface RetryStrategy {
|
|
1397
|
+
/** Maximum number of attempts (including initial) */
|
|
1398
|
+
maxAttempts: number;
|
|
1399
|
+
/** Initial delay between retries in milliseconds */
|
|
1400
|
+
baseDelayMs: number;
|
|
1401
|
+
/** Maximum delay cap in milliseconds */
|
|
1402
|
+
maxDelayMs: number;
|
|
1403
|
+
/** Function to determine if retry should occur */
|
|
1404
|
+
shouldRetry: (error: Error, attempt: number) => boolean;
|
|
1405
|
+
/** Optional jitter factor (0-1) to randomize delays */
|
|
1406
|
+
jitter?: number;
|
|
1407
|
+
}
|
|
1408
|
+
interface RetryOptions {
|
|
1409
|
+
/** Override max attempts */
|
|
1410
|
+
maxAttempts?: number;
|
|
1411
|
+
/** Override base delay */
|
|
1412
|
+
baseDelayMs?: number;
|
|
1413
|
+
/** Override max delay */
|
|
1414
|
+
maxDelayMs?: number;
|
|
1415
|
+
/** Add jitter (0-1) */
|
|
1416
|
+
jitter?: number;
|
|
1417
|
+
/** Custom retry condition */
|
|
1418
|
+
shouldRetry?: (error: Error, attempt: number) => boolean;
|
|
1419
|
+
/** Callback on each retry */
|
|
1420
|
+
onRetry?: (error: Error, attempt: number, delayMs: number) => void;
|
|
1421
|
+
/** Abort signal to cancel retries */
|
|
1422
|
+
signal?: AbortSignal;
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* Execute an async operation with retry logic
|
|
1426
|
+
*/
|
|
1427
|
+
declare function withRetry<T>(fn: () => Promise<T>, strategyOrOptions?: RetryStrategy | Partial<RetryOptions>): Promise<T>;
|
|
1428
|
+
/**
|
|
1429
|
+
* Circuit breaker state
|
|
1430
|
+
*/
|
|
1431
|
+
interface CircuitBreakerState {
|
|
1432
|
+
failures: number;
|
|
1433
|
+
lastFailure: number | null;
|
|
1434
|
+
isOpen: boolean;
|
|
1435
|
+
nextAttempt: number | null;
|
|
1436
|
+
}
|
|
1437
|
+
interface CircuitBreakerOptions {
|
|
1438
|
+
/** Number of failures before opening circuit */
|
|
1439
|
+
failureThreshold: number;
|
|
1440
|
+
/** Time to wait before attempting to close circuit (ms) */
|
|
1441
|
+
resetTimeoutMs: number;
|
|
1442
|
+
/** Optional: half-open state allows limited requests */
|
|
1443
|
+
halfOpenRequests?: number;
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Create a circuit breaker for protecting against cascading failures
|
|
1447
|
+
*/
|
|
1448
|
+
declare function createCircuitBreaker(options: CircuitBreakerOptions): {
|
|
1449
|
+
/**
|
|
1450
|
+
* Execute function with circuit breaker protection.
|
|
1451
|
+
*
|
|
1452
|
+
* States:
|
|
1453
|
+
* CLOSED — failures < threshold, all requests pass through
|
|
1454
|
+
* OPEN — failures >= threshold, fast-fails until resetTimeoutMs elapses
|
|
1455
|
+
* HALF_OPEN — resetTimeoutMs elapsed, allows `halfOpenRequests` concurrent probes
|
|
1456
|
+
*
|
|
1457
|
+
* Transitions:
|
|
1458
|
+
* T1: CLOSED → CLOSED (success resets failures)
|
|
1459
|
+
* T2: CLOSED → OPEN (failure hits threshold)
|
|
1460
|
+
* T3: OPEN → OPEN (fast-fail, time not elapsed)
|
|
1461
|
+
* T4: OPEN → HALF_OPEN (time elapsed, probe allowed)
|
|
1462
|
+
* T5: HALF_OPEN → CLOSED (probe succeeds)
|
|
1463
|
+
* T6: HALF_OPEN → OPEN (probe fails)
|
|
1464
|
+
*/
|
|
1465
|
+
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
1466
|
+
/**
|
|
1467
|
+
* Get current state
|
|
1468
|
+
*/
|
|
1469
|
+
getState(): Readonly<CircuitBreakerState>;
|
|
1470
|
+
/**
|
|
1471
|
+
* Manually reset the circuit breaker
|
|
1472
|
+
*/
|
|
1473
|
+
reset(): void;
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1476
|
+
type NodePolicy = NodePolicy$1;
|
|
1477
|
+
type StackPolicies = StackPolicies$1;
|
|
1478
|
+
/**
|
|
1479
|
+
* Runtime tier for node execution.
|
|
1480
|
+
*
|
|
1481
|
+
* Defines the execution environment for computational nodes:
|
|
1482
|
+
* - `worker`: Web Worker/service worker
|
|
1483
|
+
* - `container-lite`: Lightweight containerized runtime
|
|
1484
|
+
* - `webcontainer`: Browser-based container (WebAssembly)
|
|
1485
|
+
* - `edge`: Edge function/serverless
|
|
1486
|
+
* - `wasm-hvm`: WebAssembly with HVM (Higher-order Virtual Machine)
|
|
1487
|
+
* - `stack`: Nested stack execution
|
|
1488
|
+
*
|
|
1489
|
+
* @example
|
|
1490
|
+
* const tier: RuntimeTier = "worker";
|
|
1491
|
+
*/
|
|
1492
|
+
type RuntimeTier = "worker" | "container-lite" | "webcontainer" | "edge" | "wasm-hvm" | "stack";
|
|
1493
|
+
/**
|
|
1494
|
+
* Secret reference for node execution.
|
|
1495
|
+
*
|
|
1496
|
+
* Links a secret from the vault into node environment.
|
|
1497
|
+
*
|
|
1498
|
+
* @example
|
|
1499
|
+
* const secret: NodeSecretRef = {
|
|
1500
|
+
* name: "api_key",
|
|
1501
|
+
* scope: "stack",
|
|
1502
|
+
* env: "OPENAI_API_KEY",
|
|
1503
|
+
* required: true
|
|
1504
|
+
* };
|
|
1505
|
+
*/
|
|
1506
|
+
interface NodeSecretRef {
|
|
1507
|
+
/** Secret identifier in vault */
|
|
1508
|
+
name: string;
|
|
1509
|
+
/** Resolution scope: node-local or stack-wide */
|
|
1510
|
+
scope: "node" | "stack";
|
|
1511
|
+
/** Environment variable name (defaults to name if omitted) */
|
|
1512
|
+
env?: string;
|
|
1513
|
+
/** Whether secret must exist (default: false) */
|
|
1514
|
+
required?: boolean;
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Runtime-specific entrypoints for node execution.
|
|
1518
|
+
*
|
|
1519
|
+
* Each runtime tier has its own entrypoint format.
|
|
1520
|
+
* At least one entrypoint must be specified.
|
|
1521
|
+
*
|
|
1522
|
+
* @example
|
|
1523
|
+
* const entrypoints: NodeEntrypoints = {
|
|
1524
|
+
* worker: { module: "./transform.js", export: "transform" },
|
|
1525
|
+
* edge: { endpoint: "https://api.example.com/process" }
|
|
1526
|
+
* };
|
|
1527
|
+
*/
|
|
1528
|
+
interface NodeEntrypoints {
|
|
1529
|
+
/** Web Worker entrypoint */
|
|
1530
|
+
worker?: {
|
|
1531
|
+
module: string;
|
|
1532
|
+
export?: string;
|
|
1533
|
+
};
|
|
1534
|
+
/** Container-lite entrypoint */
|
|
1535
|
+
"container-lite"?: {
|
|
1536
|
+
command: string;
|
|
1537
|
+
args?: string[];
|
|
1538
|
+
cwd?: string;
|
|
1539
|
+
};
|
|
1540
|
+
/** WebContainer entrypoint */
|
|
1541
|
+
webcontainer?: {
|
|
1542
|
+
command: string;
|
|
1543
|
+
args?: string[];
|
|
1544
|
+
cwd?: string;
|
|
1545
|
+
};
|
|
1546
|
+
/** WASM HVM entrypoint */
|
|
1547
|
+
"wasm-hvm"?: {
|
|
1548
|
+
module: string;
|
|
1549
|
+
function?: string;
|
|
1550
|
+
};
|
|
1551
|
+
/** Edge function entrypoint */
|
|
1552
|
+
edge?: {
|
|
1553
|
+
endpoint: string;
|
|
1554
|
+
};
|
|
1555
|
+
}
|
|
1556
|
+
/**
|
|
1557
|
+
* Base manifest fields shared by nodes and stacks.
|
|
1558
|
+
*
|
|
1559
|
+
* @internal
|
|
1560
|
+
*/
|
|
1561
|
+
interface BaseManifestV0 {
|
|
1562
|
+
/** Unique identifier (must be stable across versions) */
|
|
1563
|
+
id: string;
|
|
1564
|
+
/** Semantic version (e.g., "1.0.0") */
|
|
1565
|
+
version: string;
|
|
1566
|
+
/** Human-readable name */
|
|
1567
|
+
name?: string;
|
|
1568
|
+
/** Description of functionality */
|
|
1569
|
+
description?: string;
|
|
1570
|
+
/** Security and resource policies */
|
|
1571
|
+
policies?: NodePolicy | StackPolicies;
|
|
1572
|
+
/** Arbitrary metadata for extensions */
|
|
1573
|
+
metadata?: Record<string, unknown>;
|
|
1574
|
+
}
|
|
1575
|
+
/**
|
|
1576
|
+
* Node manifest for DAG orchestrator.
|
|
1577
|
+
*
|
|
1578
|
+
* Defines a single computational node in a workflow.
|
|
1579
|
+
* Nodes are atomic execution units with typed inputs/outputs.
|
|
1580
|
+
*
|
|
1581
|
+
* @example
|
|
1582
|
+
* const node: NodeManifestV0 = {
|
|
1583
|
+
* id: "llm-transform",
|
|
1584
|
+
* version: "1.0.0",
|
|
1585
|
+
* kind: "transform",
|
|
1586
|
+
* runtimes: ["worker", "edge"],
|
|
1587
|
+
* entrypoints: {
|
|
1588
|
+
* worker: { module: "./llm.js", export: "transform" }
|
|
1589
|
+
* },
|
|
1590
|
+
* inputsSchema: {
|
|
1591
|
+
* type: "object",
|
|
1592
|
+
* properties: {
|
|
1593
|
+
* prompt: { type: "string" }
|
|
1594
|
+
* },
|
|
1595
|
+
* required: ["prompt"]
|
|
1596
|
+
* },
|
|
1597
|
+
* outputsSchema: {
|
|
1598
|
+
* type: "object",
|
|
1599
|
+
* properties: {
|
|
1600
|
+
* text: { type: "string" }
|
|
1601
|
+
* }
|
|
1602
|
+
* }
|
|
1603
|
+
* };
|
|
1604
|
+
*/
|
|
1605
|
+
interface NodeManifestV0 extends BaseManifestV0 {
|
|
1606
|
+
/** Node type classification */
|
|
1607
|
+
kind: "prompt" | "mcp" | "task" | "transform" | "webhook" | "custom";
|
|
1608
|
+
/** UI label override */
|
|
1609
|
+
label?: string;
|
|
1610
|
+
/** Supported runtime tiers (in priority order) */
|
|
1611
|
+
runtimes: RuntimeTier[];
|
|
1612
|
+
/** Runtime-specific execution entrypoints */
|
|
1613
|
+
entrypoints: NodeEntrypoints;
|
|
1614
|
+
/** JSON Schema for input validation */
|
|
1615
|
+
inputsSchema?: JSONSchema7;
|
|
1616
|
+
/** JSON Schema for output validation */
|
|
1617
|
+
outputsSchema?: JSONSchema7;
|
|
1618
|
+
/** Declared capabilities (e.g., "network", "filesystem") */
|
|
1619
|
+
capabilities?: string[];
|
|
1620
|
+
/** Secret references required by this node */
|
|
1621
|
+
secrets?: NodeSecretRef[];
|
|
1622
|
+
/** Lifecycle hooks for instrumentation */
|
|
1623
|
+
hooks?: {
|
|
1624
|
+
explain?: string;
|
|
1625
|
+
debug?: string;
|
|
1626
|
+
askInput?: string;
|
|
1627
|
+
};
|
|
1628
|
+
/** UI configuration */
|
|
1629
|
+
ui?: {
|
|
1630
|
+
/** Node-specific UI config */
|
|
1631
|
+
config?: unknown;
|
|
1632
|
+
/** Output viewer configuration */
|
|
1633
|
+
viewer?: {
|
|
1634
|
+
kind?: "text" | "table" | "json" | "custom";
|
|
1635
|
+
componentId?: string;
|
|
1636
|
+
};
|
|
1637
|
+
};
|
|
1638
|
+
/** MCP server integration */
|
|
1639
|
+
mcp?: {
|
|
1640
|
+
/** MCP server identifier */
|
|
1641
|
+
server?: string;
|
|
1642
|
+
/** Exposed MCP tools */
|
|
1643
|
+
tools?: Array<{
|
|
1644
|
+
name: string;
|
|
1645
|
+
schema?: JSONSchema7;
|
|
1646
|
+
}>;
|
|
1647
|
+
};
|
|
1648
|
+
/** Observability configuration */
|
|
1649
|
+
observability?: {
|
|
1650
|
+
/** Emit execution logs */
|
|
1651
|
+
emitLogs?: boolean;
|
|
1652
|
+
/** Emit output artifacts */
|
|
1653
|
+
emitArtifacts?: boolean;
|
|
1654
|
+
/** Trace attribute keys to capture */
|
|
1655
|
+
traceAttributes?: string[];
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
/**
|
|
1659
|
+
* Stack-level secret scope definition.
|
|
1660
|
+
*
|
|
1661
|
+
* Defines which nodes can access a secret.
|
|
1662
|
+
*
|
|
1663
|
+
* @example
|
|
1664
|
+
* const secretScope: StackSecretScope = {
|
|
1665
|
+
* scope: ["fetch-node", "transform-node"],
|
|
1666
|
+
* required: true
|
|
1667
|
+
* };
|
|
1668
|
+
*/
|
|
1669
|
+
interface StackSecretScope {
|
|
1670
|
+
/** Node IDs that can access this secret */
|
|
1671
|
+
scope: string[];
|
|
1672
|
+
/** Whether secret must exist */
|
|
1673
|
+
required?: boolean;
|
|
1674
|
+
}
|
|
1675
|
+
/**
|
|
1676
|
+
* Stack-level runtime tier configuration.
|
|
1677
|
+
*
|
|
1678
|
+
* Allows stack-wide defaults with per-node overrides.
|
|
1679
|
+
*
|
|
1680
|
+
* @example
|
|
1681
|
+
* const runtimes: StackRuntimes = {
|
|
1682
|
+
* default: ["worker", "edge"],
|
|
1683
|
+
* overrides: {
|
|
1684
|
+
* "heavy-compute": ["container-lite"]
|
|
1685
|
+
* }
|
|
1686
|
+
* };
|
|
1687
|
+
*/
|
|
1688
|
+
interface StackRuntimes {
|
|
1689
|
+
/** Default runtime tiers for all nodes */
|
|
1690
|
+
default?: RuntimeTier[];
|
|
1691
|
+
/** Per-node runtime tier overrides (nodeId -> tiers) */
|
|
1692
|
+
overrides?: Record<string, RuntimeTier[]>;
|
|
1693
|
+
}
|
|
1694
|
+
/**
|
|
1695
|
+
* Node configuration within a stack.
|
|
1696
|
+
*
|
|
1697
|
+
* References a node manifest and provides instance-specific config.
|
|
1698
|
+
*
|
|
1699
|
+
* @example
|
|
1700
|
+
* const nodeConfig: StackNodeConfig = {
|
|
1701
|
+
* id: "fetch-1",
|
|
1702
|
+
* nodeRef: "http-fetch",
|
|
1703
|
+
* config: { timeout: 5000 },
|
|
1704
|
+
* runtimes: ["edge"],
|
|
1705
|
+
* secrets: ["api_key"]
|
|
1706
|
+
* };
|
|
1707
|
+
*/
|
|
1708
|
+
interface StackNodeConfig {
|
|
1709
|
+
/** Unique ID within stack */
|
|
1710
|
+
id: string;
|
|
1711
|
+
/** Reference to NodeManifestV0.id */
|
|
1712
|
+
nodeRef: string;
|
|
1713
|
+
/** Node-specific configuration */
|
|
1714
|
+
config?: Record<string, unknown>;
|
|
1715
|
+
/** Runtime tier override */
|
|
1716
|
+
runtimes?: RuntimeTier[];
|
|
1717
|
+
/** Security policy override */
|
|
1718
|
+
policies?: NodePolicy;
|
|
1719
|
+
/** Secret names from stack.secrets */
|
|
1720
|
+
secrets?: string[];
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* Directed edge connecting two nodes in the stack DAG.
|
|
1724
|
+
*
|
|
1725
|
+
* Defines data flow from one node's outputs to another's inputs.
|
|
1726
|
+
*
|
|
1727
|
+
* @example
|
|
1728
|
+
* const edge: StackEdge = {
|
|
1729
|
+
* from: "fetch-1",
|
|
1730
|
+
* to: "transform-1",
|
|
1731
|
+
* map: { "data": "input" }
|
|
1732
|
+
* };
|
|
1733
|
+
*/
|
|
1734
|
+
interface StackEdge {
|
|
1735
|
+
/** Source node ID */
|
|
1736
|
+
from: string;
|
|
1737
|
+
/** Target node ID */
|
|
1738
|
+
to: string;
|
|
1739
|
+
/** Output-to-input key mapping (defaults to identity) */
|
|
1740
|
+
map?: Record<string, string>;
|
|
1741
|
+
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Manifest layer provenance.
|
|
1744
|
+
*
|
|
1745
|
+
* - `L0`: Landing/Zero layer (low-level primitives)
|
|
1746
|
+
* - `L1`: Compose/Platform layer (higher-level abstractions)
|
|
1747
|
+
*/
|
|
1748
|
+
type ManifestLayer = "L0" | "L1" | "L2" | "L3" | "L4" | "L5";
|
|
1749
|
+
/**
|
|
1750
|
+
* Stack manifest for DAG orchestrator.
|
|
1751
|
+
*
|
|
1752
|
+
* Defines a complete workflow as a directed acyclic graph (DAG) of nodes.
|
|
1753
|
+
*
|
|
1754
|
+
* @example
|
|
1755
|
+
* const stack: StackManifestV0 = {
|
|
1756
|
+
* id: "data-pipeline",
|
|
1757
|
+
* version: "1.0.0",
|
|
1758
|
+
* nodes: [
|
|
1759
|
+
* { id: "fetch", nodeRef: "http-fetch", config: { url: "..." } },
|
|
1760
|
+
* { id: "transform", nodeRef: "llm-transform" }
|
|
1761
|
+
* ],
|
|
1762
|
+
* edges: [
|
|
1763
|
+
* { from: "fetch", to: "transform", map: { data: "input" } }
|
|
1764
|
+
* ],
|
|
1765
|
+
* secrets: {
|
|
1766
|
+
* api_key: { scope: ["fetch"], required: true }
|
|
1767
|
+
* }
|
|
1768
|
+
* };
|
|
1769
|
+
*/
|
|
1770
|
+
interface StackManifestV0 extends BaseManifestV0 {
|
|
1771
|
+
/** Node instances in this stack */
|
|
1772
|
+
nodes: StackNodeConfig[];
|
|
1773
|
+
/** Edges connecting nodes (data flow) */
|
|
1774
|
+
edges?: StackEdge[];
|
|
1775
|
+
/** Stack-level secret definitions */
|
|
1776
|
+
secrets?: Record<string, StackSecretScope>;
|
|
1777
|
+
/** Runtime tier configuration */
|
|
1778
|
+
runtimes?: StackRuntimes;
|
|
1779
|
+
/** Provenance layer (L0 or L1) */
|
|
1780
|
+
layer?: ManifestLayer;
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
/**
|
|
1784
|
+
* Skill Manifest Types (L1)
|
|
1785
|
+
*
|
|
1786
|
+
* Core types for the Skills Platform. A SkillManifest extends StackManifestV0
|
|
1787
|
+
* with skill-specific metadata — a skill IS a stack with agent orchestration.
|
|
1788
|
+
*
|
|
1789
|
+
* @module skills/types
|
|
1790
|
+
*/
|
|
1791
|
+
|
|
1792
|
+
type SkillCategory = "startup" | "legal" | "finance" | "engineering" | "content" | "research" | "operations" | "marketing" | "verification";
|
|
1793
|
+
type SkillOutputType = "document" | "website" | "spreadsheet" | "presentation" | "codebase" | "analysis" | "dataset" | "visual" | "video" | "audio" | "composite";
|
|
1794
|
+
declare const SKILL_TIERS: readonly ["flagship", "professional", "utility"];
|
|
1795
|
+
type SkillTier = (typeof SKILL_TIERS)[number];
|
|
1796
|
+
declare const SKILL_RANKS: readonly ["skill", "flow", "fleet", "org", "society"];
|
|
1797
|
+
type SkillRank = (typeof SKILL_RANKS)[number];
|
|
1798
|
+
/** Effective-dated rank assignment — immutable audit trail */
|
|
1799
|
+
interface RankAssignment {
|
|
1800
|
+
/** Current rank */
|
|
1801
|
+
rank: SkillRank;
|
|
1802
|
+
/** ISO 8601 timestamp when this rank became effective */
|
|
1803
|
+
effectiveFrom: string;
|
|
1804
|
+
/** ISO 8601 timestamp when this rank was superseded (null = current) */
|
|
1805
|
+
effectiveTo: string | null;
|
|
1806
|
+
/** Evidence that promotion invariants were satisfied */
|
|
1807
|
+
proof?: PromotionProof;
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Promotion proof — the Curry-Howard witness type.
|
|
1811
|
+
* Each promotion requires structural evidence that the entity
|
|
1812
|
+
* satisfies the invariants of the target rank.
|
|
1813
|
+
*/
|
|
1814
|
+
interface PromotionProof {
|
|
1815
|
+
/** Source rank */
|
|
1816
|
+
from: SkillRank;
|
|
1817
|
+
/** Target rank */
|
|
1818
|
+
to: SkillRank;
|
|
1819
|
+
/** Structural invariant checks that passed */
|
|
1820
|
+
invariants: PromotionInvariant[];
|
|
1821
|
+
/** Timestamp of promotion evaluation */
|
|
1822
|
+
evaluatedAt: string;
|
|
1823
|
+
/** Quality score at time of promotion (0-1) */
|
|
1824
|
+
qualityScore: number;
|
|
1825
|
+
}
|
|
1826
|
+
interface PromotionInvariant {
|
|
1827
|
+
/** Invariant name (e.g., "has_convergence", "has_3_plus_skills", "has_mesh_events") */
|
|
1828
|
+
name: string;
|
|
1829
|
+
/** Whether this invariant was satisfied */
|
|
1830
|
+
satisfied: boolean;
|
|
1831
|
+
/** Human-readable evidence */
|
|
1832
|
+
evidence?: string;
|
|
1833
|
+
}
|
|
1834
|
+
interface SkillCapabilities {
|
|
1835
|
+
/** Allow image generation via connected media providers */
|
|
1836
|
+
allowImageGen?: boolean;
|
|
1837
|
+
/** Allow video generation via connected media providers */
|
|
1838
|
+
allowVideoGen?: boolean;
|
|
1839
|
+
/** Allow MCP tool access during execution */
|
|
1840
|
+
allowTools?: boolean;
|
|
1841
|
+
/** Allow web search during execution */
|
|
1842
|
+
allowWebSearch?: boolean;
|
|
1843
|
+
/** Allow code execution in sandbox */
|
|
1844
|
+
allowCodeExec?: boolean;
|
|
1845
|
+
}
|
|
1846
|
+
interface SkillAgent {
|
|
1847
|
+
/** Agent role name (e.g., "Market Researcher", "Legal Analyst") */
|
|
1848
|
+
role: string;
|
|
1849
|
+
/** What this agent does in the workflow */
|
|
1850
|
+
description: string;
|
|
1851
|
+
/** Maps to a NodeManifestV0.id in the stack */
|
|
1852
|
+
nodeRef?: string;
|
|
1853
|
+
/** When true, a synthetic peer reviewer evaluates this agent's output after completion */
|
|
1854
|
+
peerReview?: boolean;
|
|
1855
|
+
}
|
|
1856
|
+
interface SkillSampleOutput {
|
|
1857
|
+
type: SkillOutputType;
|
|
1858
|
+
title: string;
|
|
1859
|
+
/** Screenshot or live preview URL */
|
|
1860
|
+
previewUrl?: string;
|
|
1861
|
+
description: string;
|
|
1862
|
+
}
|
|
1863
|
+
/** External service dependency for a skill */
|
|
1864
|
+
interface SkillServiceRequirement {
|
|
1865
|
+
/** Unique key for this requirement (e.g., "search", "database", "email") */
|
|
1866
|
+
key: string;
|
|
1867
|
+
/** Human-readable label */
|
|
1868
|
+
label: string;
|
|
1869
|
+
/** Type of service needed */
|
|
1870
|
+
type: "mcp" | "api" | "credential";
|
|
1871
|
+
/** Description of what this service is used for */
|
|
1872
|
+
description: string;
|
|
1873
|
+
/** Whether this service is required or optional */
|
|
1874
|
+
required: boolean;
|
|
1875
|
+
/** Suggested MCP server names (for type: "mcp") */
|
|
1876
|
+
suggestedServers?: string[];
|
|
1877
|
+
}
|
|
1878
|
+
interface SkillMeta<TInput extends Record<string, unknown> = Record<string, unknown>> {
|
|
1879
|
+
/** Unique skill slug (url-safe) */
|
|
1880
|
+
slug: string;
|
|
1881
|
+
/** Display name */
|
|
1882
|
+
title: string;
|
|
1883
|
+
/** One-line value proposition */
|
|
1884
|
+
tagline: string;
|
|
1885
|
+
/** Detailed description (markdown) */
|
|
1886
|
+
description: string;
|
|
1887
|
+
/** Skill category */
|
|
1888
|
+
category: SkillCategory;
|
|
1889
|
+
/** Skill tier (complexity/impact level) */
|
|
1890
|
+
tier: SkillTier;
|
|
1891
|
+
/** Expected output artifact types */
|
|
1892
|
+
outputs: SkillOutputType[];
|
|
1893
|
+
/** Estimated execution time range in seconds [min, max] */
|
|
1894
|
+
estimatedTime: [number, number];
|
|
1895
|
+
/** Required input schema (JSON Schema) */
|
|
1896
|
+
inputSchema: JSONSchema7;
|
|
1897
|
+
/** Agent roles involved in this skill */
|
|
1898
|
+
agents: SkillAgent[];
|
|
1899
|
+
/** Sample input for demo/preview (typed to match inputSchema) */
|
|
1900
|
+
sampleInput?: TInput;
|
|
1901
|
+
/** Sample output artifacts for showcase */
|
|
1902
|
+
sampleOutputs?: SkillSampleOutput[];
|
|
1903
|
+
/** Tags for filtering */
|
|
1904
|
+
tags: string[];
|
|
1905
|
+
/** Author */
|
|
1906
|
+
author: string;
|
|
1907
|
+
/** Icon identifier (from icon set) */
|
|
1908
|
+
icon?: string;
|
|
1909
|
+
/** Cosmic gradient pair index (0-7 from cosmicGradients) */
|
|
1910
|
+
gradientIndex?: number;
|
|
1911
|
+
/** Output schema for composition chaining (JSON Schema) */
|
|
1912
|
+
outputSchema?: JSONSchema7;
|
|
1913
|
+
/** Allow agents to dynamically delegate tasks to ephemeral agents. Max 2 per run. */
|
|
1914
|
+
allowDelegation?: boolean;
|
|
1915
|
+
/** External service dependencies (MCP servers, APIs, credentials) */
|
|
1916
|
+
services?: SkillServiceRequirement[];
|
|
1917
|
+
/** Runtime capability toggles (image gen, video gen, tools, etc.) */
|
|
1918
|
+
capabilities?: SkillCapabilities;
|
|
1919
|
+
/** Current rank in the hierarchy (default: "skill") */
|
|
1920
|
+
rank?: SkillRank;
|
|
1921
|
+
/** Effective-dated rank history — immutable audit trail */
|
|
1922
|
+
rankHistory?: RankAssignment[];
|
|
1923
|
+
/**
|
|
1924
|
+
* Convergence configuration for iterative agent output refinement.
|
|
1925
|
+
*
|
|
1926
|
+
* Future optimization: the manual convergence loop in runner.ts could be
|
|
1927
|
+
* replaced by `withRetry()` + `withCircuitBreaker()` from
|
|
1928
|
+
* `lib/terminals-tech/core/primitives/middleware` — they provide the same
|
|
1929
|
+
* retry/backoff/threshold semantics with composable middleware chaining.
|
|
1930
|
+
* See also `createRefinementLoop()` from `primitives/refinement` which
|
|
1931
|
+
* encapsulates the score/delta/plateau logic as a standalone primitive.
|
|
1932
|
+
*/
|
|
1933
|
+
convergence?: {
|
|
1934
|
+
/** Max refinement iterations per agent. Default 1 (no refinement), max 5. */
|
|
1935
|
+
maxIterations: number;
|
|
1936
|
+
/** Quality threshold (0-1). Agent output must meet this to pass. Default 0.7. */
|
|
1937
|
+
qualityThreshold: number;
|
|
1938
|
+
/** Minimum quality improvement per iteration. Stops early if delta < this. Default 0.05. */
|
|
1939
|
+
minDelta: number;
|
|
1940
|
+
/** Refinement strategy: retry (re-execute), critique (LLM critic), refine (critique + inject feedback). */
|
|
1941
|
+
strategy: "retry" | "critique" | "refine";
|
|
1942
|
+
};
|
|
1943
|
+
}
|
|
1944
|
+
/**
|
|
1945
|
+
* A SkillManifest extends StackManifestV0 with skill-specific metadata.
|
|
1946
|
+
*
|
|
1947
|
+
* This is the core type — a skill IS a stack manifest with agent orchestration
|
|
1948
|
+
* metadata. The `skill` field contains all presentation and execution metadata.
|
|
1949
|
+
*
|
|
1950
|
+
* The `TInput` parameter establishes compile-time correspondence between
|
|
1951
|
+
* the JSON Schema `inputSchema`, the typed `sampleInput`, and the runtime
|
|
1952
|
+
* input validated by `SkillRunner.start()`.
|
|
1953
|
+
*/
|
|
1954
|
+
interface SkillManifest<TInput extends Record<string, unknown> = Record<string, unknown>> extends StackManifestV0 {
|
|
1955
|
+
/** Skill-specific metadata */
|
|
1956
|
+
skill: SkillMeta<TInput>;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
type ManifestType = "skill" | "stack" | "node" | "project";
|
|
1960
|
+
type ManifestSource = "system" | "user" | "compose" | "marketplace" | "import";
|
|
1961
|
+
interface RegistryEntry {
|
|
1962
|
+
type: ManifestType;
|
|
1963
|
+
manifest: SkillManifest | StackManifestV0 | NodeManifestV0 | Record<string, unknown>;
|
|
1964
|
+
source: ManifestSource;
|
|
1965
|
+
registeredAt: number;
|
|
1966
|
+
tags?: string[];
|
|
1967
|
+
}
|
|
1968
|
+
interface RegistryFilter {
|
|
1969
|
+
type?: ManifestType;
|
|
1970
|
+
source?: ManifestSource;
|
|
1971
|
+
category?: SkillCategory;
|
|
1972
|
+
tags?: string[];
|
|
1973
|
+
limit?: number;
|
|
1974
|
+
}
|
|
1975
|
+
declare class ManifestRegistry {
|
|
1976
|
+
private entries;
|
|
1977
|
+
register(manifest: SkillManifest | StackManifestV0 | NodeManifestV0 | Record<string, unknown>, type: ManifestType, source: ManifestSource, tags?: string[]): void;
|
|
1978
|
+
get(key: string): RegistryEntry | undefined;
|
|
1979
|
+
getSkill(slug: string): SkillManifest | undefined;
|
|
1980
|
+
getAll(filter?: RegistryFilter): RegistryEntry[];
|
|
1981
|
+
resolve(ref: string): RegistryEntry | null;
|
|
1982
|
+
search(query: string, filter?: RegistryFilter): RegistryEntry[];
|
|
1983
|
+
unregister(key: string): boolean;
|
|
1984
|
+
get size(): number;
|
|
1985
|
+
clear(): void;
|
|
1986
|
+
private deriveKey;
|
|
1987
|
+
}
|
|
1988
|
+
/** Singleton registry instance */
|
|
1989
|
+
declare const registry: ManifestRegistry;
|
|
1990
|
+
|
|
1991
|
+
/**
|
|
1992
|
+
* Core SDK — Fundamental utilities and data structures
|
|
1993
|
+
*
|
|
1994
|
+
* Result types, retry/circuit-breaker, event bus, validation, DAG, registry.
|
|
1995
|
+
* Hides internal combinators, vector ops, stream internals.
|
|
1996
|
+
*
|
|
1997
|
+
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
1998
|
+
* @module sdk/core
|
|
1999
|
+
*/
|
|
2000
|
+
|
|
2001
|
+
type core_CircuitBreakerOptions = CircuitBreakerOptions;
|
|
2002
|
+
type core_DAG<N, E = void> = DAG<N, E>;
|
|
2003
|
+
type core_DAGEdge<E = void> = DAGEdge<E>;
|
|
2004
|
+
type core_DAGNode<T> = DAGNode<T>;
|
|
2005
|
+
type core_EventHandler<T> = EventHandler<T>;
|
|
2006
|
+
type core_ManifestRegistry = ManifestRegistry;
|
|
2007
|
+
declare const core_ManifestRegistry: typeof ManifestRegistry;
|
|
2008
|
+
type core_Registry<K, V> = Registry<K, V>;
|
|
2009
|
+
type core_RetryOptions = RetryOptions;
|
|
2010
|
+
type core_SDKResult<T, E = Error> = SDKResult<T, E>;
|
|
2011
|
+
type core_StoreError = StoreError;
|
|
2012
|
+
type core_TypedEventBus<Events extends Record<string, unknown>> = TypedEventBus<Events>;
|
|
2013
|
+
type core_Untrusted<T> = Untrusted<T>;
|
|
2014
|
+
type core_Validated<T> = Validated<T>;
|
|
2015
|
+
declare const core_createCircuitBreaker: typeof createCircuitBreaker;
|
|
2016
|
+
declare const core_createDAG: typeof createDAG;
|
|
2017
|
+
declare const core_createEventBus: typeof createEventBus;
|
|
2018
|
+
declare const core_createRegistry: typeof createRegistry;
|
|
2019
|
+
declare const core_err: typeof err;
|
|
2020
|
+
declare const core_isErr: typeof isErr;
|
|
2021
|
+
declare const core_isOk: typeof isOk;
|
|
2022
|
+
declare const core_ok: typeof ok;
|
|
2023
|
+
declare const core_registry: typeof registry;
|
|
2024
|
+
declare const core_secureValidate: typeof secureValidate;
|
|
2025
|
+
declare const core_unbrand: typeof unbrand;
|
|
2026
|
+
declare const core_untrusted: typeof untrusted;
|
|
2027
|
+
declare const core_validateWithSchema: typeof validateWithSchema;
|
|
2028
|
+
declare const core_validated: typeof validated;
|
|
2029
|
+
declare const core_withRetry: typeof withRetry;
|
|
2030
|
+
declare namespace core {
|
|
2031
|
+
export { type core_CircuitBreakerOptions as CircuitBreakerOptions, type core_DAG as DAG, type core_DAGEdge as DAGEdge, type core_DAGNode as DAGNode, type core_EventHandler as EventHandler, core_ManifestRegistry as ManifestRegistry, type core_Registry as Registry, type core_RetryOptions as RetryOptions, type core_SDKResult as SDKResult, type core_StoreError as StoreError, type core_TypedEventBus as TypedEventBus, type core_Untrusted as Untrusted, type core_Validated as Validated, core_createCircuitBreaker as createCircuitBreaker, core_createDAG as createDAG, core_createEventBus as createEventBus, core_createRegistry as createRegistry, core_err as err, flatMap as flatMapResult, core_isErr as isErr, core_isOk as isOk, map as mapResult, core_ok as ok, core_registry as registry, core_secureValidate as secureValidate, core_unbrand as unbrand, core_untrusted as untrusted, core_validateWithSchema as validateWithSchema, core_validated as validated, core_withRetry as withRetry };
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
/**
|
|
2035
|
+
* L0 Category Theory Primitives
|
|
2036
|
+
*
|
|
2037
|
+
* Foundational categorical abstractions for cross-layer type mappings.
|
|
2038
|
+
* Provides the mathematical foundation for isomorphisms between AXON layers.
|
|
2039
|
+
*
|
|
2040
|
+
* @license BUSL-1.1
|
|
2041
|
+
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
2042
|
+
* @module core/L0/category
|
|
2043
|
+
*/
|
|
2044
|
+
/**
|
|
2045
|
+
* A morphism is a structure-preserving transformation between types.
|
|
2046
|
+
* This is the fundamental building block of category theory.
|
|
2047
|
+
*/
|
|
2048
|
+
type Morphism<A, B> = (a: A) => B;
|
|
2049
|
+
/**
|
|
2050
|
+
* Async morphism for transformations that may be asynchronous
|
|
2051
|
+
*/
|
|
2052
|
+
type AsyncMorphism<A, B> = (a: A) => Promise<B>;
|
|
2053
|
+
/**
|
|
2054
|
+
* A Category consists of objects and morphisms between them,
|
|
2055
|
+
* with composition and identity laws.
|
|
2056
|
+
*/
|
|
2057
|
+
interface Category<Obj, Hom> {
|
|
2058
|
+
/** Identity morphism for each object */
|
|
2059
|
+
identity<A extends Obj>(a: A): Hom;
|
|
2060
|
+
/** Composition of morphisms: g . f = g(f(x)) */
|
|
2061
|
+
compose<A extends Obj, B extends Obj, C extends Obj>(f: Hom, g: Hom): Hom;
|
|
2062
|
+
}
|
|
2063
|
+
/**
|
|
2064
|
+
* An isomorphism is a bijective morphism with an inverse.
|
|
2065
|
+
* For A and B to be isomorphic, there must exist:
|
|
2066
|
+
* - forward: A → B
|
|
2067
|
+
* - backward: B → A
|
|
2068
|
+
* - such that: backward(forward(a)) = a AND forward(backward(b)) = b
|
|
2069
|
+
*/
|
|
2070
|
+
interface Iso<A, B> {
|
|
2071
|
+
/** Forward transformation: A → B */
|
|
2072
|
+
forward: Morphism<A, B>;
|
|
2073
|
+
/** Backward transformation: B → A */
|
|
2074
|
+
backward: Morphism<B, A>;
|
|
2075
|
+
/** Optional metadata about the isomorphism */
|
|
2076
|
+
meta?: IsoMeta;
|
|
2077
|
+
}
|
|
2078
|
+
/**
|
|
2079
|
+
* Metadata about an isomorphism
|
|
2080
|
+
*/
|
|
2081
|
+
interface IsoMeta {
|
|
2082
|
+
/** Human-readable name */
|
|
2083
|
+
name?: string;
|
|
2084
|
+
/** Description of what this iso does */
|
|
2085
|
+
description?: string;
|
|
2086
|
+
/** Whether this is an exact isomorphism (no information loss) */
|
|
2087
|
+
exact?: boolean;
|
|
2088
|
+
/** Confidence score for derived isomorphisms (0-1) */
|
|
2089
|
+
confidence?: number;
|
|
2090
|
+
/** Source layer (L1-L5) */
|
|
2091
|
+
sourceLayer?: LayerId;
|
|
2092
|
+
/** Target layer (L1-L5) */
|
|
2093
|
+
targetLayer?: LayerId;
|
|
2094
|
+
}
|
|
2095
|
+
/**
|
|
2096
|
+
* Async isomorphism for transformations that may be asynchronous
|
|
2097
|
+
*/
|
|
2098
|
+
interface AsyncIso<A, B> {
|
|
2099
|
+
forward: AsyncMorphism<A, B>;
|
|
2100
|
+
backward: AsyncMorphism<B, A>;
|
|
2101
|
+
meta?: IsoMeta;
|
|
2102
|
+
}
|
|
2103
|
+
/**
|
|
2104
|
+
* An embedding is a one-way structure-preserving transformation.
|
|
2105
|
+
* Unlike isomorphisms, embeddings may not have a full inverse.
|
|
2106
|
+
* The partial inverse extracts as much as possible from the target type.
|
|
2107
|
+
*/
|
|
2108
|
+
interface Embed<A, B> {
|
|
2109
|
+
/** Embed A into B */
|
|
2110
|
+
embed: Morphism<A, B>;
|
|
2111
|
+
/** Partial extraction from B (may lose information) */
|
|
2112
|
+
extract: Morphism<B, Partial<A>>;
|
|
2113
|
+
/** Whether the embedding is lossless */
|
|
2114
|
+
lossless?: boolean;
|
|
2115
|
+
}
|
|
2116
|
+
/**
|
|
2117
|
+
* A functor maps objects and morphisms between categories
|
|
2118
|
+
* while preserving identity and composition.
|
|
2119
|
+
*/
|
|
2120
|
+
interface Functor<F> {
|
|
2121
|
+
/** Map a morphism over the functor */
|
|
2122
|
+
map<A, B>(f: Morphism<A, B>): (fa: F) => F;
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* Natural transformation between functors F and G.
|
|
2126
|
+
* For each object A, provides a morphism F(A) → G(A)
|
|
2127
|
+
* such that the naturality square commutes.
|
|
2128
|
+
*/
|
|
2129
|
+
type NaturalTransformation<F, G> = <A>(fa: F) => G;
|
|
2130
|
+
/**
|
|
2131
|
+
* AXON Layer identifiers
|
|
2132
|
+
*/
|
|
2133
|
+
type LayerId = "L0" | "L1" | "L2" | "L3" | "L4" | "L5";
|
|
2134
|
+
/**
|
|
2135
|
+
* Layer metadata
|
|
2136
|
+
*/
|
|
2137
|
+
interface LayerMeta {
|
|
2138
|
+
id: LayerId;
|
|
2139
|
+
name: string;
|
|
2140
|
+
description: string;
|
|
2141
|
+
color: string;
|
|
2142
|
+
}
|
|
2143
|
+
/**
|
|
2144
|
+
* AXON Layer definitions
|
|
2145
|
+
*/
|
|
2146
|
+
declare const LAYERS: Record<LayerId, LayerMeta>;
|
|
2147
|
+
/**
|
|
2148
|
+
* Valid layer transitions in the AXON architecture
|
|
2149
|
+
*/
|
|
2150
|
+
declare const VALID_TRANSITIONS: ReadonlyArray<[LayerId, LayerId]>;
|
|
2151
|
+
/**
|
|
2152
|
+
* Product type - categorical product of A and B
|
|
2153
|
+
*/
|
|
2154
|
+
type Product<A, B> = readonly [A, B];
|
|
2155
|
+
/**
|
|
2156
|
+
* Coproduct (sum) type - categorical coproduct of A and B
|
|
2157
|
+
*/
|
|
2158
|
+
type Coproduct<A, B> = {
|
|
2159
|
+
readonly tag: "left";
|
|
2160
|
+
readonly value: A;
|
|
2161
|
+
} | {
|
|
2162
|
+
readonly tag: "right";
|
|
2163
|
+
readonly value: B;
|
|
2164
|
+
};
|
|
2165
|
+
/**
|
|
2166
|
+
* Create a left-tagged coproduct
|
|
2167
|
+
*/
|
|
2168
|
+
declare function left<A, B>(value: A): Coproduct<A, B>;
|
|
2169
|
+
/**
|
|
2170
|
+
* Create a right-tagged coproduct
|
|
2171
|
+
*/
|
|
2172
|
+
declare function right<A, B>(value: B): Coproduct<A, B>;
|
|
2173
|
+
/**
|
|
2174
|
+
* Fold over a coproduct
|
|
2175
|
+
*/
|
|
2176
|
+
declare function fold<A, B, C>(onLeft: Morphism<A, C>, onRight: Morphism<B, C>): Morphism<Coproduct<A, B>, C>;
|
|
2177
|
+
/**
|
|
2178
|
+
* A proof witness type - represents evidence that P holds
|
|
2179
|
+
*/
|
|
2180
|
+
type Proof<P> = P extends true ? {
|
|
2181
|
+
readonly _witness: unique symbol;
|
|
2182
|
+
} : never;
|
|
2183
|
+
/**
|
|
2184
|
+
* A verified value with attached proof
|
|
2185
|
+
*/
|
|
2186
|
+
interface Verified<T, P> {
|
|
2187
|
+
readonly value: T;
|
|
2188
|
+
readonly proof: Proof<P>;
|
|
2189
|
+
}
|
|
2190
|
+
/**
|
|
2191
|
+
* Compose two morphisms: g . f
|
|
2192
|
+
*/
|
|
2193
|
+
declare function compose<A, B, C>(f: Morphism<A, B>, g: Morphism<B, C>): Morphism<A, C>;
|
|
2194
|
+
/**
|
|
2195
|
+
* Compose two async morphisms
|
|
2196
|
+
*/
|
|
2197
|
+
declare function composeAsync<A, B, C>(f: AsyncMorphism<A, B>, g: AsyncMorphism<B, C>): Promise<AsyncMorphism<A, C>>;
|
|
2198
|
+
/**
|
|
2199
|
+
* Identity morphism
|
|
2200
|
+
*/
|
|
2201
|
+
declare function identity<A>(): Morphism<A, A>;
|
|
2202
|
+
/**
|
|
2203
|
+
* Compose two isomorphisms
|
|
2204
|
+
*/
|
|
2205
|
+
declare function composeIso<A, B, C>(iso1: Iso<A, B>, iso2: Iso<B, C>): Iso<A, C>;
|
|
2206
|
+
/**
|
|
2207
|
+
* Invert an isomorphism
|
|
2208
|
+
*/
|
|
2209
|
+
declare function invertIso<A, B>(iso: Iso<A, B>): Iso<B, A>;
|
|
2210
|
+
/**
|
|
2211
|
+
* Create an identity isomorphism
|
|
2212
|
+
*/
|
|
2213
|
+
declare function identityIso<A>(): Iso<A, A>;
|
|
2214
|
+
/**
|
|
2215
|
+
* A typed bridge between two layers with verified transition
|
|
2216
|
+
*/
|
|
2217
|
+
interface LayerBridge<From extends LayerId, To extends LayerId, A, B> {
|
|
2218
|
+
readonly sourceLayer: From;
|
|
2219
|
+
readonly targetLayer: To;
|
|
2220
|
+
readonly iso: Iso<A, B>;
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* Check if a layer transition is valid
|
|
2224
|
+
*/
|
|
2225
|
+
declare function isValidTransition(from: LayerId, to: LayerId): boolean;
|
|
2226
|
+
/**
|
|
2227
|
+
* Create a layer bridge (validates transition at runtime)
|
|
2228
|
+
*/
|
|
2229
|
+
declare function createBridge<From extends LayerId, To extends LayerId, A, B>(from: From, to: To, iso: Iso<A, B>): LayerBridge<From, To, A, B> | null;
|
|
2230
|
+
|
|
2231
|
+
/**
|
|
2232
|
+
* L0 Information Theory Primitives
|
|
2233
|
+
*
|
|
2234
|
+
* Provides measures for information preservation, entropy,
|
|
2235
|
+
* and semantic density in cross-layer transformations.
|
|
2236
|
+
*
|
|
2237
|
+
* @module core/L0/information
|
|
2238
|
+
*/
|
|
2239
|
+
/**
|
|
2240
|
+
* Calculate Shannon entropy for a probability distribution.
|
|
2241
|
+
* H(X) = -Σ p(x) log₂ p(x)
|
|
2242
|
+
*
|
|
2243
|
+
* @param probabilities - Array of probabilities (should sum to 1)
|
|
2244
|
+
* @returns Entropy in bits
|
|
2245
|
+
*/
|
|
2246
|
+
declare function entropy(probabilities: number[]): number;
|
|
2247
|
+
/**
|
|
2248
|
+
* Calculate joint entropy H(X, Y)
|
|
2249
|
+
*
|
|
2250
|
+
* @param jointProbabilities - 2D array of joint probabilities P(X=x, Y=y)
|
|
2251
|
+
* @returns Joint entropy in bits
|
|
2252
|
+
*/
|
|
2253
|
+
declare function jointEntropy(jointProbabilities: number[][]): number;
|
|
2254
|
+
/**
|
|
2255
|
+
* Calculate conditional entropy H(Y|X) = H(X,Y) - H(X)
|
|
2256
|
+
*
|
|
2257
|
+
* @param jointProbabilities - 2D array P(X=x, Y=y)
|
|
2258
|
+
* @returns Conditional entropy in bits
|
|
2259
|
+
*/
|
|
2260
|
+
declare function conditionalEntropy(jointProbabilities: number[][]): number;
|
|
2261
|
+
/**
|
|
2262
|
+
* Calculate mutual information I(X; Y) = H(X) + H(Y) - H(X, Y)
|
|
2263
|
+
* Measures how much knowing one variable reduces uncertainty about the other.
|
|
2264
|
+
*
|
|
2265
|
+
* @param pX - Marginal probability of X
|
|
2266
|
+
* @param pY - Marginal probability of Y
|
|
2267
|
+
* @param pXY - Joint probability P(X, Y) as 2D array
|
|
2268
|
+
* @returns Mutual information in bits
|
|
2269
|
+
*/
|
|
2270
|
+
declare function mutualInformation(pX: number[], pY: number[], pXY: number[][]): number;
|
|
2271
|
+
/**
|
|
2272
|
+
* Metrics for measuring information preservation in transformations
|
|
2273
|
+
*/
|
|
2274
|
+
interface InformationPreservation {
|
|
2275
|
+
/** Fraction of source information retained (0-1) */
|
|
2276
|
+
retention: number;
|
|
2277
|
+
/** Entropy of the source */
|
|
2278
|
+
sourceEntropy: number;
|
|
2279
|
+
/** Entropy of the target */
|
|
2280
|
+
targetEntropy: number;
|
|
2281
|
+
/** Mutual information between source and target */
|
|
2282
|
+
mutualInfo: number;
|
|
2283
|
+
/** Whether the transformation is lossless */
|
|
2284
|
+
lossless: boolean;
|
|
2285
|
+
}
|
|
2286
|
+
/**
|
|
2287
|
+
* Measure information preservation between source and transformed representations.
|
|
2288
|
+
* Uses hash-based sampling for large datasets.
|
|
2289
|
+
*
|
|
2290
|
+
* @param source - Original values
|
|
2291
|
+
* @param transformed - Transformed values
|
|
2292
|
+
* @param roundTrip - Optional round-trip values (transformed → source)
|
|
2293
|
+
* @returns Information preservation metrics
|
|
2294
|
+
*/
|
|
2295
|
+
declare function measurePreservation<S, T>(source: S[], transformed: T[], roundTrip?: S[]): InformationPreservation;
|
|
2296
|
+
/**
|
|
2297
|
+
* Semantic density measures bits of meaningful information per token.
|
|
2298
|
+
* Higher density = more information packed into fewer tokens.
|
|
2299
|
+
*/
|
|
2300
|
+
interface SemanticDensity {
|
|
2301
|
+
/** Total tokens in the representation */
|
|
2302
|
+
tokenCount: number;
|
|
2303
|
+
/** Estimated information content in bits */
|
|
2304
|
+
informationBits: number;
|
|
2305
|
+
/** Bits per token */
|
|
2306
|
+
density: number;
|
|
2307
|
+
/** Compression ratio compared to baseline */
|
|
2308
|
+
compressionRatio: number;
|
|
2309
|
+
}
|
|
2310
|
+
/**
|
|
2311
|
+
* Calculate semantic density of a representation.
|
|
2312
|
+
*
|
|
2313
|
+
* @param tokens - Array of tokens (strings, symbols, etc.)
|
|
2314
|
+
* @param baselineTokensPerBit - Baseline tokens per bit of information (default: 2)
|
|
2315
|
+
* @returns Semantic density metrics
|
|
2316
|
+
*/
|
|
2317
|
+
declare function calculateSemanticDensity(tokens: string[], baselineTokensPerBit?: number): SemanticDensity;
|
|
2318
|
+
/**
|
|
2319
|
+
* Estimate Kolmogorov complexity via compression.
|
|
2320
|
+
* Lower complexity = more compressible = more structured.
|
|
2321
|
+
*
|
|
2322
|
+
* @param data - String representation of data
|
|
2323
|
+
* @returns Estimated complexity as compression ratio
|
|
2324
|
+
*/
|
|
2325
|
+
declare function estimateComplexity(data: string): number;
|
|
2326
|
+
/**
|
|
2327
|
+
* Calculate KL divergence D_KL(P || Q) = Σ p(x) log(p(x)/q(x))
|
|
2328
|
+
* Measures how much P differs from Q.
|
|
2329
|
+
*
|
|
2330
|
+
* @param p - True distribution
|
|
2331
|
+
* @param q - Approximate distribution
|
|
2332
|
+
* @returns KL divergence (non-negative, 0 = identical)
|
|
2333
|
+
*/
|
|
2334
|
+
declare function klDivergence(p: number[], q: number[]): number;
|
|
2335
|
+
/**
|
|
2336
|
+
* Calculate Jensen-Shannon divergence (symmetric KL variant)
|
|
2337
|
+
* JSD(P, Q) = 0.5 * D_KL(P || M) + 0.5 * D_KL(Q || M) where M = 0.5(P + Q)
|
|
2338
|
+
*
|
|
2339
|
+
* @param p - First distribution
|
|
2340
|
+
* @param q - Second distribution
|
|
2341
|
+
* @returns JS divergence in [0, 1]
|
|
2342
|
+
*/
|
|
2343
|
+
declare function jsDivergence(p: number[], q: number[]): number;
|
|
2344
|
+
/**
|
|
2345
|
+
* Normalize an array to sum to 1 (probability distribution)
|
|
2346
|
+
*/
|
|
2347
|
+
declare function normalize(values: number[]): number[];
|
|
2348
|
+
/**
|
|
2349
|
+
* Calculate cosine similarity between two vectors
|
|
2350
|
+
*/
|
|
2351
|
+
declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
2352
|
+
|
|
2353
|
+
/**
|
|
2354
|
+
* L0 Automatic Isomorphism Derivation
|
|
2355
|
+
*
|
|
2356
|
+
* Automatically derives isomorphisms between compatible types
|
|
2357
|
+
* using structural analysis and field mapping.
|
|
2358
|
+
*
|
|
2359
|
+
* @license BUSL-1.1
|
|
2360
|
+
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
2361
|
+
* @module core/L0/derivation
|
|
2362
|
+
*/
|
|
2363
|
+
|
|
2364
|
+
/**
|
|
2365
|
+
* Type shape descriptor for structural analysis
|
|
2366
|
+
*/
|
|
2367
|
+
interface TypeShape {
|
|
2368
|
+
/** Type kind (object, array, primitive, etc.) */
|
|
2369
|
+
kind: "object" | "array" | "primitive" | "null" | "undefined";
|
|
2370
|
+
/** For objects: map of field name to TypeShape */
|
|
2371
|
+
fields?: Record<string, TypeShape>;
|
|
2372
|
+
/** For arrays: element type shape */
|
|
2373
|
+
elementType?: TypeShape;
|
|
2374
|
+
/** For primitives: the primitive type */
|
|
2375
|
+
primitiveType?: "string" | "number" | "boolean" | "bigint" | "symbol";
|
|
2376
|
+
/** Whether the field is optional */
|
|
2377
|
+
optional?: boolean;
|
|
2378
|
+
}
|
|
2379
|
+
/**
|
|
2380
|
+
* Extract the structural shape of a value at runtime
|
|
2381
|
+
*
|
|
2382
|
+
* @param value - Value to analyze
|
|
2383
|
+
* @returns TypeShape descriptor
|
|
2384
|
+
*/
|
|
2385
|
+
declare function extractShape(value: unknown): TypeShape;
|
|
2386
|
+
/**
|
|
2387
|
+
* Calculate similarity between two type shapes (Jaccard-like)
|
|
2388
|
+
*
|
|
2389
|
+
* @param a - First type shape
|
|
2390
|
+
* @param b - Second type shape
|
|
2391
|
+
* @returns Similarity score (0-1)
|
|
2392
|
+
*/
|
|
2393
|
+
declare function shapeSimilarity(a: TypeShape, b: TypeShape): number;
|
|
2394
|
+
/**
|
|
2395
|
+
* A mapping between fields in source and target types
|
|
2396
|
+
*/
|
|
2397
|
+
interface FieldMapping {
|
|
2398
|
+
/** Source field name */
|
|
2399
|
+
source: string;
|
|
2400
|
+
/** Target field name */
|
|
2401
|
+
target: string;
|
|
2402
|
+
/** Confidence of the mapping (0-1) */
|
|
2403
|
+
confidence: number;
|
|
2404
|
+
/** Transform function if types differ */
|
|
2405
|
+
transform?: Morphism<unknown, unknown>;
|
|
2406
|
+
}
|
|
2407
|
+
/**
|
|
2408
|
+
* Derive field mappings between two object shapes
|
|
2409
|
+
*
|
|
2410
|
+
* @param source - Source type shape
|
|
2411
|
+
* @param target - Target type shape
|
|
2412
|
+
* @returns Array of field mappings
|
|
2413
|
+
*/
|
|
2414
|
+
declare function deriveFieldMappings(source: TypeShape, target: TypeShape): FieldMapping[];
|
|
2415
|
+
/**
|
|
2416
|
+
* Result of automatic isomorphism derivation
|
|
2417
|
+
*/
|
|
2418
|
+
interface DerivedIso<A, B> extends Iso<A, B> {
|
|
2419
|
+
/** Field mappings used */
|
|
2420
|
+
fieldMappings: FieldMapping[];
|
|
2421
|
+
/** Overall confidence score */
|
|
2422
|
+
confidence: number;
|
|
2423
|
+
}
|
|
2424
|
+
/**
|
|
2425
|
+
* Options for isomorphism derivation
|
|
2426
|
+
*/
|
|
2427
|
+
interface DerivationOptions {
|
|
2428
|
+
/** Minimum confidence threshold (default: 0.5) */
|
|
2429
|
+
minConfidence?: number;
|
|
2430
|
+
/** Whether to include partial mappings (default: true) */
|
|
2431
|
+
includePartial?: boolean;
|
|
2432
|
+
/** Custom field transforms */
|
|
2433
|
+
customTransforms?: Record<string, Morphism<unknown, unknown>>;
|
|
2434
|
+
}
|
|
2435
|
+
/**
|
|
2436
|
+
* Automatically derive an isomorphism between two types based on structure
|
|
2437
|
+
*
|
|
2438
|
+
* @param sampleA - Sample value of type A
|
|
2439
|
+
* @param sampleB - Sample value of type B
|
|
2440
|
+
* @param options - Derivation options
|
|
2441
|
+
* @returns Derived isomorphism or null if not derivable
|
|
2442
|
+
*/
|
|
2443
|
+
declare function deriveIsomorphism<A extends object, B extends object>(sampleA: A, sampleB: B, options?: DerivationOptions): DerivedIso<A, B> | null;
|
|
2444
|
+
/**
|
|
2445
|
+
* Verify an isomorphism by testing round-trip on sample values
|
|
2446
|
+
*
|
|
2447
|
+
* @param iso - Isomorphism to verify
|
|
2448
|
+
* @param samples - Sample values to test
|
|
2449
|
+
* @returns True if all round-trips match
|
|
2450
|
+
*/
|
|
2451
|
+
declare function verifyIsomorphism<A, B>(iso: Iso<A, B>, samples: A[]): boolean;
|
|
2452
|
+
/**
|
|
2453
|
+
* Check if two types are structurally compatible for isomorphism
|
|
2454
|
+
*
|
|
2455
|
+
* @param shapeA - Source type shape
|
|
2456
|
+
* @param shapeB - Target type shape
|
|
2457
|
+
* @returns Compatibility score (0-1)
|
|
2458
|
+
*/
|
|
2459
|
+
declare function checkCompatibility(shapeA: TypeShape, shapeB: TypeShape): number;
|
|
2460
|
+
/**
|
|
2461
|
+
* Check if a type can be embedded into another (one-way mapping)
|
|
2462
|
+
*
|
|
2463
|
+
* @param source - Source type shape
|
|
2464
|
+
* @param target - Target type shape
|
|
2465
|
+
* @returns True if source can be fully embedded in target
|
|
2466
|
+
*/
|
|
2467
|
+
declare function canEmbed(source: TypeShape, target: TypeShape): boolean;
|
|
2468
|
+
|
|
2469
|
+
/**
|
|
2470
|
+
* L0 Sematon — The Smallest Meaning-Bearing Unit
|
|
2471
|
+
*
|
|
2472
|
+
* The sematon is the atomic unit of operational meaning in Terminals OS.
|
|
2473
|
+
* It carries a typed payload, convergence witness, p-adic address,
|
|
2474
|
+
* information-theoretic metrics, and a constructor flag that guarantees
|
|
2475
|
+
* the Deutsch-Marletto invariant: after transforming an input, the
|
|
2476
|
+
* sematon retains the ability to transform again.
|
|
2477
|
+
*
|
|
2478
|
+
* The sematon unifies Signal<T>, ContextNode, FractalSnapshot,
|
|
2479
|
+
* ConvergenceWitness, and CombinatorEvent into a single formal type
|
|
2480
|
+
* at the L0 foundation layer.
|
|
2481
|
+
*
|
|
2482
|
+
* Core Engine Primitive.
|
|
2483
|
+
*
|
|
2484
|
+
* @license BUSL-1.1
|
|
2485
|
+
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
2486
|
+
* @module core/L0/sematon
|
|
2487
|
+
*/
|
|
2488
|
+
/**
|
|
2489
|
+
* Payload kind classification for sematons.
|
|
2490
|
+
* Determines how the payload is interpreted across layers.
|
|
2491
|
+
*/
|
|
2492
|
+
type SematonKind = "signal" | "context" | "fractal" | "witness" | "combinator" | "interaction" | "custom";
|
|
2493
|
+
/**
|
|
2494
|
+
* Convergence witness snapshot embedded in a sematon.
|
|
2495
|
+
* Minimal subset of ConvergenceWitness for portability.
|
|
2496
|
+
*/
|
|
2497
|
+
interface SematonWitness {
|
|
2498
|
+
/** Kuramoto order parameter R in [0, 1] */
|
|
2499
|
+
R: number;
|
|
2500
|
+
/** Shannon entropy of activation distribution */
|
|
2501
|
+
activationEntropy: number;
|
|
2502
|
+
/** Whether convergence criteria are met */
|
|
2503
|
+
converged: boolean;
|
|
2504
|
+
/** Step at which this witness was taken */
|
|
2505
|
+
step: number;
|
|
2506
|
+
}
|
|
2507
|
+
/**
|
|
2508
|
+
* The Sematon — smallest meaning-bearing unit with operational consequence.
|
|
2509
|
+
*
|
|
2510
|
+
* Generic over T (the payload type):
|
|
2511
|
+
* T = Signal payload at signal kind
|
|
2512
|
+
* T = ContextNode metadata at context kind
|
|
2513
|
+
* T = FractalSnapshot at fractal kind
|
|
2514
|
+
* T = arbitrary at custom kind
|
|
2515
|
+
*/
|
|
2516
|
+
interface Sematon<T = unknown> {
|
|
2517
|
+
/** Unique identifier */
|
|
2518
|
+
readonly id: string;
|
|
2519
|
+
/** Payload kind classification */
|
|
2520
|
+
readonly kind: SematonKind;
|
|
2521
|
+
/** The meaning-bearing payload */
|
|
2522
|
+
readonly payload: T;
|
|
2523
|
+
/** Convergence witness at creation time */
|
|
2524
|
+
readonly witness: SematonWitness;
|
|
2525
|
+
/** p-adic address for hierarchical locality */
|
|
2526
|
+
readonly padicAddress: string;
|
|
2527
|
+
/** Shannon entropy of payload (bits) */
|
|
2528
|
+
readonly entropy: number;
|
|
2529
|
+
/** Semantic density (bits per token) */
|
|
2530
|
+
readonly density: number;
|
|
2531
|
+
/** The resistance to constructive transformation: H / (ρ * R) */
|
|
2532
|
+
readonly impedance: number;
|
|
2533
|
+
/** Deterministic content hash (FNV-1a) */
|
|
2534
|
+
readonly shapeHash: string;
|
|
2535
|
+
/**
|
|
2536
|
+
* Constructor flag: can this sematon participate in further transformations?
|
|
2537
|
+
* True iff: witness has converged AND entropy is finite AND payload is non-empty.
|
|
2538
|
+
* This is the Deutsch-Marletto invariant.
|
|
2539
|
+
*/
|
|
2540
|
+
readonly constructive: boolean;
|
|
2541
|
+
/** Creation timestamp */
|
|
2542
|
+
readonly createdAt: number;
|
|
2543
|
+
/** Source layer or surface that produced this sematon */
|
|
2544
|
+
readonly source: string;
|
|
2545
|
+
}
|
|
2546
|
+
/**
|
|
2547
|
+
* Folded (serializable) representation of a Sematon.
|
|
2548
|
+
* Suitable for JSON serialization, mesh relay, or persistence.
|
|
2549
|
+
*/
|
|
2550
|
+
interface FoldedSematon {
|
|
2551
|
+
id: string;
|
|
2552
|
+
kind: SematonKind;
|
|
2553
|
+
payload: string;
|
|
2554
|
+
witness: SematonWitness;
|
|
2555
|
+
padicAddress: string;
|
|
2556
|
+
entropy: number;
|
|
2557
|
+
density: number;
|
|
2558
|
+
impedance: number;
|
|
2559
|
+
shapeHash: string;
|
|
2560
|
+
constructive: boolean;
|
|
2561
|
+
createdAt: number;
|
|
2562
|
+
source: string;
|
|
2563
|
+
}
|
|
2564
|
+
interface SematonConfig<T> {
|
|
2565
|
+
kind: SematonKind;
|
|
2566
|
+
payload: T;
|
|
2567
|
+
witness: SematonWitness;
|
|
2568
|
+
padicAddress?: string;
|
|
2569
|
+
source?: string;
|
|
2570
|
+
}
|
|
2571
|
+
/**
|
|
2572
|
+
* Create a new Sematon from configuration.
|
|
2573
|
+
*/
|
|
2574
|
+
declare function createSematon<T>(config: SematonConfig<T>): Sematon<T>;
|
|
2575
|
+
/**
|
|
2576
|
+
* Get the Shannon entropy of a sematon's payload.
|
|
2577
|
+
*/
|
|
2578
|
+
declare function sematonEntropy<T>(sematon: Sematon<T>): number;
|
|
2579
|
+
/**
|
|
2580
|
+
* Get the semantic density of a sematon.
|
|
2581
|
+
*/
|
|
2582
|
+
declare function sematonDensity<T>(sematon: Sematon<T>): number;
|
|
2583
|
+
/**
|
|
2584
|
+
* Check if a sematon can participate in further transformations.
|
|
2585
|
+
* This is the Deutsch-Marletto constructor invariant.
|
|
2586
|
+
*/
|
|
2587
|
+
declare function isRealizable<T>(sematon: Sematon<T>): boolean;
|
|
2588
|
+
/**
|
|
2589
|
+
* Compute distance between two sematons using payload cosine similarity
|
|
2590
|
+
* weighted by witness R proximity.
|
|
2591
|
+
*
|
|
2592
|
+
* Distance in [0, 1] where 0 = identical, 1 = maximally different.
|
|
2593
|
+
*/
|
|
2594
|
+
declare function sematonDistance<T>(a: Sematon<T>, b: Sematon<T>): number;
|
|
2595
|
+
/**
|
|
2596
|
+
* Fold a Sematon into a JSON-serializable representation.
|
|
2597
|
+
* HVM γ (construct) — compress for handoff, persistence, or relay.
|
|
2598
|
+
*/
|
|
2599
|
+
declare function foldSematon<T>(sematon: Sematon<T>): FoldedSematon;
|
|
2600
|
+
/**
|
|
2601
|
+
* Unfold a serialized representation back into a Sematon.
|
|
2602
|
+
* HVM δ (duplicate) — expand from handoff, persistence, or relay.
|
|
2603
|
+
*/
|
|
2604
|
+
declare function unfoldSematon<T>(folded: FoldedSematon): Sematon<T>;
|
|
2605
|
+
|
|
2606
|
+
/**
|
|
2607
|
+
* L0 Realizability Trace — Constructor Proof Runtime
|
|
2608
|
+
*
|
|
2609
|
+
* A RealizabilityTrace is an ordered sequence of RealizabilitySteps.
|
|
2610
|
+
* Each step records: input Sematon(s), output Sematon(s), a ConvergenceWitness
|
|
2611
|
+
* snapshot, and information gain.
|
|
2612
|
+
*
|
|
2613
|
+
* verifyTrace() checks three constructor invariants:
|
|
2614
|
+
* 1. Each input was realizable (constructive flag true)
|
|
2615
|
+
* 2. Each witness converged (R above threshold)
|
|
2616
|
+
* 3. Information is non-decreasing across steps
|
|
2617
|
+
*
|
|
2618
|
+
* This is the Deutsch-Marletto constructor invariant made executable:
|
|
2619
|
+
* after transforming inputs, the system retains the ability to transform again.
|
|
2620
|
+
*
|
|
2621
|
+
* @license BUSL-1.1
|
|
2622
|
+
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
2623
|
+
* @module core/L0/realizability
|
|
2624
|
+
*/
|
|
2625
|
+
|
|
2626
|
+
interface RealizabilityStep {
|
|
2627
|
+
/** Step index in the trace */
|
|
2628
|
+
index: number;
|
|
2629
|
+
/** Input sematons consumed by this step */
|
|
2630
|
+
inputs: Sematon[];
|
|
2631
|
+
/** Output sematons produced by this step */
|
|
2632
|
+
outputs: Sematon[];
|
|
2633
|
+
/** Convergence witness at this step */
|
|
2634
|
+
witness: SematonWitness;
|
|
2635
|
+
/** Total information content of outputs (bits) */
|
|
2636
|
+
informationGain: number;
|
|
2637
|
+
/** Timestamp */
|
|
2638
|
+
timestamp: number;
|
|
2639
|
+
}
|
|
2640
|
+
interface RealizabilityTrace {
|
|
2641
|
+
/** Unique trace identifier */
|
|
2642
|
+
id: string;
|
|
2643
|
+
/** Ordered sequence of steps */
|
|
2644
|
+
steps: RealizabilityStep[];
|
|
2645
|
+
/** Whether the trace has been verified */
|
|
2646
|
+
verified: boolean;
|
|
2647
|
+
/** Total information gain across all steps */
|
|
2648
|
+
totalInfoGain: number;
|
|
2649
|
+
/** Count of constructive (realizable) steps */
|
|
2650
|
+
constructiveSteps: number;
|
|
2651
|
+
/** Creation timestamp */
|
|
2652
|
+
createdAt: number;
|
|
2653
|
+
}
|
|
2654
|
+
interface VerificationSuccess {
|
|
2655
|
+
valid: true;
|
|
2656
|
+
totalInfoGain: number;
|
|
2657
|
+
constructiveSteps: number;
|
|
2658
|
+
}
|
|
2659
|
+
interface VerificationFailure {
|
|
2660
|
+
valid: false;
|
|
2661
|
+
failureStep: number;
|
|
2662
|
+
reason: string;
|
|
2663
|
+
}
|
|
2664
|
+
type VerificationResult = VerificationSuccess | VerificationFailure;
|
|
2665
|
+
/**
|
|
2666
|
+
* Create a single realizability step.
|
|
2667
|
+
* Computes informationGain as the sum of output sematon entropies.
|
|
2668
|
+
*/
|
|
2669
|
+
declare function createRealizabilityStep(index: number, inputs: Sematon[], outputs: Sematon[], witness: SematonWitness): RealizabilityStep;
|
|
2670
|
+
/**
|
|
2671
|
+
* Construct a RealizabilityTrace from an ordered sequence of steps.
|
|
2672
|
+
* Computes totalInfoGain and constructiveSteps.
|
|
2673
|
+
*/
|
|
2674
|
+
declare function traceRealizability(steps: RealizabilityStep[]): RealizabilityTrace;
|
|
2675
|
+
/**
|
|
2676
|
+
* Verify a realizability trace against three constructor invariants:
|
|
2677
|
+
* 1. Each step's inputs must all be realizable
|
|
2678
|
+
* 2. Each step's witness must have converged
|
|
2679
|
+
* 3. Information is non-decreasing across steps
|
|
2680
|
+
*
|
|
2681
|
+
* Returns VerificationSuccess or VerificationFailure with step index and reason.
|
|
2682
|
+
*/
|
|
2683
|
+
declare function verifyTrace(trace: RealizabilityTrace): VerificationResult;
|
|
2684
|
+
/**
|
|
2685
|
+
* Fold a RealizabilityTrace into a JSON string.
|
|
2686
|
+
* Sematons are folded via foldSematon first for portable serialization.
|
|
2687
|
+
*/
|
|
2688
|
+
declare function foldTrace(trace: RealizabilityTrace): string;
|
|
2689
|
+
/**
|
|
2690
|
+
* Unfold a JSON string back into a RealizabilityTrace.
|
|
2691
|
+
* Sematons are unfolded via unfoldSematon.
|
|
2692
|
+
*/
|
|
2693
|
+
declare function unfoldTrace(json: string): RealizabilityTrace;
|
|
2694
|
+
|
|
2695
|
+
/**
|
|
2696
|
+
* L0 Foundation Layer
|
|
2697
|
+
*
|
|
2698
|
+
* Provides categorical foundations and information-theoretic primitives
|
|
2699
|
+
* for cross-layer mappings in the AXON architecture.
|
|
2700
|
+
*
|
|
2701
|
+
* @module core/L0
|
|
2702
|
+
*/
|
|
2703
|
+
|
|
2704
|
+
type index_AsyncIso<A, B> = AsyncIso<A, B>;
|
|
2705
|
+
type index_AsyncMorphism<A, B> = AsyncMorphism<A, B>;
|
|
2706
|
+
type index_Category<Obj, Hom> = Category<Obj, Hom>;
|
|
2707
|
+
type index_Coproduct<A, B> = Coproduct<A, B>;
|
|
2708
|
+
type index_DerivationOptions = DerivationOptions;
|
|
2709
|
+
type index_DerivedIso<A, B> = DerivedIso<A, B>;
|
|
2710
|
+
type index_Embed<A, B> = Embed<A, B>;
|
|
2711
|
+
type index_FieldMapping = FieldMapping;
|
|
2712
|
+
type index_FoldedSematon = FoldedSematon;
|
|
2713
|
+
type index_Functor<F> = Functor<F>;
|
|
2714
|
+
type index_InformationPreservation = InformationPreservation;
|
|
2715
|
+
type index_Iso<A, B> = Iso<A, B>;
|
|
2716
|
+
type index_IsoMeta = IsoMeta;
|
|
2717
|
+
declare const index_LAYERS: typeof LAYERS;
|
|
2718
|
+
type index_LayerBridge<From extends LayerId, To extends LayerId, A, B> = LayerBridge<From, To, A, B>;
|
|
2719
|
+
type index_LayerId = LayerId;
|
|
2720
|
+
type index_LayerMeta = LayerMeta;
|
|
2721
|
+
type index_Morphism<A, B> = Morphism<A, B>;
|
|
2722
|
+
type index_NaturalTransformation<F, G> = NaturalTransformation<F, G>;
|
|
2723
|
+
type index_Product<A, B> = Product<A, B>;
|
|
2724
|
+
type index_Proof<P> = Proof<P>;
|
|
2725
|
+
type index_RealizabilityStep = RealizabilityStep;
|
|
2726
|
+
type index_RealizabilityTrace = RealizabilityTrace;
|
|
2727
|
+
type index_SemanticDensity = SemanticDensity;
|
|
2728
|
+
type index_Sematon<T = unknown> = Sematon<T>;
|
|
2729
|
+
type index_SematonConfig<T> = SematonConfig<T>;
|
|
2730
|
+
type index_SematonKind = SematonKind;
|
|
2731
|
+
type index_SematonWitness = SematonWitness;
|
|
2732
|
+
type index_TypeShape = TypeShape;
|
|
2733
|
+
declare const index_VALID_TRANSITIONS: typeof VALID_TRANSITIONS;
|
|
2734
|
+
type index_VerificationFailure = VerificationFailure;
|
|
2735
|
+
type index_VerificationResult = VerificationResult;
|
|
2736
|
+
type index_VerificationSuccess = VerificationSuccess;
|
|
2737
|
+
type index_Verified<T, P> = Verified<T, P>;
|
|
2738
|
+
declare const index_calculateSemanticDensity: typeof calculateSemanticDensity;
|
|
2739
|
+
declare const index_canEmbed: typeof canEmbed;
|
|
2740
|
+
declare const index_checkCompatibility: typeof checkCompatibility;
|
|
2741
|
+
declare const index_compose: typeof compose;
|
|
2742
|
+
declare const index_composeAsync: typeof composeAsync;
|
|
2743
|
+
declare const index_composeIso: typeof composeIso;
|
|
2744
|
+
declare const index_conditionalEntropy: typeof conditionalEntropy;
|
|
2745
|
+
declare const index_cosineSimilarity: typeof cosineSimilarity;
|
|
2746
|
+
declare const index_createBridge: typeof createBridge;
|
|
2747
|
+
declare const index_createRealizabilityStep: typeof createRealizabilityStep;
|
|
2748
|
+
declare const index_createSematon: typeof createSematon;
|
|
2749
|
+
declare const index_deriveFieldMappings: typeof deriveFieldMappings;
|
|
2750
|
+
declare const index_deriveIsomorphism: typeof deriveIsomorphism;
|
|
2751
|
+
declare const index_entropy: typeof entropy;
|
|
2752
|
+
declare const index_estimateComplexity: typeof estimateComplexity;
|
|
2753
|
+
declare const index_extractShape: typeof extractShape;
|
|
2754
|
+
declare const index_fold: typeof fold;
|
|
2755
|
+
declare const index_foldSematon: typeof foldSematon;
|
|
2756
|
+
declare const index_foldTrace: typeof foldTrace;
|
|
2757
|
+
declare const index_identity: typeof identity;
|
|
2758
|
+
declare const index_identityIso: typeof identityIso;
|
|
2759
|
+
declare const index_invertIso: typeof invertIso;
|
|
2760
|
+
declare const index_isRealizable: typeof isRealizable;
|
|
2761
|
+
declare const index_isValidTransition: typeof isValidTransition;
|
|
2762
|
+
declare const index_jointEntropy: typeof jointEntropy;
|
|
2763
|
+
declare const index_jsDivergence: typeof jsDivergence;
|
|
2764
|
+
declare const index_klDivergence: typeof klDivergence;
|
|
2765
|
+
declare const index_left: typeof left;
|
|
2766
|
+
declare const index_measurePreservation: typeof measurePreservation;
|
|
2767
|
+
declare const index_mutualInformation: typeof mutualInformation;
|
|
2768
|
+
declare const index_normalize: typeof normalize;
|
|
2769
|
+
declare const index_right: typeof right;
|
|
2770
|
+
declare const index_sematonDensity: typeof sematonDensity;
|
|
2771
|
+
declare const index_sematonDistance: typeof sematonDistance;
|
|
2772
|
+
declare const index_sematonEntropy: typeof sematonEntropy;
|
|
2773
|
+
declare const index_shapeSimilarity: typeof shapeSimilarity;
|
|
2774
|
+
declare const index_traceRealizability: typeof traceRealizability;
|
|
2775
|
+
declare const index_unfoldSematon: typeof unfoldSematon;
|
|
2776
|
+
declare const index_unfoldTrace: typeof unfoldTrace;
|
|
2777
|
+
declare const index_verifyIsomorphism: typeof verifyIsomorphism;
|
|
2778
|
+
declare const index_verifyTrace: typeof verifyTrace;
|
|
2779
|
+
declare namespace index {
|
|
2780
|
+
export { type index_AsyncIso as AsyncIso, type index_AsyncMorphism as AsyncMorphism, type index_Category as Category, type index_Coproduct as Coproduct, type index_DerivationOptions as DerivationOptions, type index_DerivedIso as DerivedIso, type index_Embed as Embed, type index_FieldMapping as FieldMapping, type index_FoldedSematon as FoldedSematon, type index_Functor as Functor, type index_InformationPreservation as InformationPreservation, type index_Iso as Iso, type index_IsoMeta as IsoMeta, index_LAYERS as LAYERS, type index_LayerBridge as LayerBridge, type index_LayerId as LayerId, type index_LayerMeta as LayerMeta, type index_Morphism as Morphism, type index_NaturalTransformation as NaturalTransformation, type index_Product as Product, type index_Proof as Proof, type index_RealizabilityStep as RealizabilityStep, type index_RealizabilityTrace as RealizabilityTrace, type index_SemanticDensity as SemanticDensity, type index_Sematon as Sematon, type index_SematonConfig as SematonConfig, type index_SematonKind as SematonKind, type index_SematonWitness as SematonWitness, type index_TypeShape as TypeShape, index_VALID_TRANSITIONS as VALID_TRANSITIONS, type index_VerificationFailure as VerificationFailure, type index_VerificationResult as VerificationResult, type index_VerificationSuccess as VerificationSuccess, type index_Verified as Verified, index_calculateSemanticDensity as calculateSemanticDensity, index_canEmbed as canEmbed, index_checkCompatibility as checkCompatibility, index_compose as compose, index_composeAsync as composeAsync, index_composeIso as composeIso, index_conditionalEntropy as conditionalEntropy, index_cosineSimilarity as cosineSimilarity, index_createBridge as createBridge, index_createRealizabilityStep as createRealizabilityStep, index_createSematon as createSematon, index_deriveFieldMappings as deriveFieldMappings, index_deriveIsomorphism as deriveIsomorphism, index_entropy as entropy, index_estimateComplexity as estimateComplexity, index_extractShape as extractShape, index_fold as fold, index_foldSematon as foldSematon, index_foldTrace as foldTrace, index_identity as identity, index_identityIso as identityIso, index_invertIso as invertIso, index_isRealizable as isRealizable, index_isValidTransition as isValidTransition, index_jointEntropy as jointEntropy, index_jsDivergence as jsDivergence, index_klDivergence as klDivergence, index_left as left, index_measurePreservation as measurePreservation, index_mutualInformation as mutualInformation, index_normalize as normalize, index_right as right, index_sematonDensity as sematonDensity, index_sematonDistance as sematonDistance, index_sematonEntropy as sematonEntropy, index_shapeSimilarity as shapeSimilarity, index_traceRealizability as traceRealizability, index_unfoldSematon as unfoldSematon, index_unfoldTrace as unfoldTrace, index_verifyIsomorphism as verifyIsomorphism, index_verifyTrace as verifyTrace };
|
|
2781
|
+
}
|
|
2782
|
+
|
|
2783
|
+
/**
|
|
2784
|
+
* Action Algebra — Input-Agnostic Action Types
|
|
2785
|
+
*
|
|
2786
|
+
* All input surfaces (keyboard, gamepad, voice, touch) compile down to this algebra.
|
|
2787
|
+
* All executors interpret this algebra into effects.
|
|
2788
|
+
*
|
|
2789
|
+
* @module core/primitives/action
|
|
2790
|
+
*/
|
|
2791
|
+
|
|
2792
|
+
type NavigationTarget = {
|
|
2793
|
+
kind: "surface";
|
|
2794
|
+
surface: SurfaceId;
|
|
2795
|
+
} | {
|
|
2796
|
+
kind: "tab";
|
|
2797
|
+
tab: string;
|
|
2798
|
+
} | {
|
|
2799
|
+
kind: "route";
|
|
2800
|
+
path: string;
|
|
2801
|
+
params?: Record<string, string>;
|
|
2802
|
+
} | {
|
|
2803
|
+
kind: "focus";
|
|
2804
|
+
elementId: string;
|
|
2805
|
+
} | {
|
|
2806
|
+
kind: "relative";
|
|
2807
|
+
direction: "up" | "down" | "left" | "right";
|
|
2808
|
+
};
|
|
2809
|
+
type SkillRef = {
|
|
2810
|
+
kind: "slug";
|
|
2811
|
+
slug: string;
|
|
2812
|
+
} | {
|
|
2813
|
+
kind: "id";
|
|
2814
|
+
id: string;
|
|
2815
|
+
} | {
|
|
2816
|
+
kind: "command";
|
|
2817
|
+
commandId: string;
|
|
2818
|
+
};
|
|
2819
|
+
interface ComposeEdge {
|
|
2820
|
+
sourceId: string;
|
|
2821
|
+
targetId: string;
|
|
2822
|
+
port?: string;
|
|
2823
|
+
}
|
|
2824
|
+
type ObserveTarget = {
|
|
2825
|
+
kind: "metric";
|
|
2826
|
+
metricId: string;
|
|
2827
|
+
} | {
|
|
2828
|
+
kind: "panel";
|
|
2829
|
+
panelId: string;
|
|
2830
|
+
} | {
|
|
2831
|
+
kind: "surface";
|
|
2832
|
+
surface: SurfaceId;
|
|
2833
|
+
};
|
|
2834
|
+
interface DelegateAssignment {
|
|
2835
|
+
agentId: string;
|
|
2836
|
+
taskDescription: string;
|
|
2837
|
+
context?: Record<string, unknown>;
|
|
2838
|
+
}
|
|
2839
|
+
type Action = {
|
|
2840
|
+
verb: "navigate";
|
|
2841
|
+
target: NavigationTarget;
|
|
2842
|
+
} | {
|
|
2843
|
+
verb: "execute";
|
|
2844
|
+
skill: SkillRef;
|
|
2845
|
+
args?: Record<string, unknown>;
|
|
2846
|
+
} | {
|
|
2847
|
+
verb: "compose";
|
|
2848
|
+
edge: ComposeEdge;
|
|
2849
|
+
} | {
|
|
2850
|
+
verb: "observe";
|
|
2851
|
+
target: ObserveTarget;
|
|
2852
|
+
zoom?: number;
|
|
2853
|
+
} | {
|
|
2854
|
+
verb: "delegate";
|
|
2855
|
+
assignment: DelegateAssignment;
|
|
2856
|
+
} | {
|
|
2857
|
+
verb: "palette";
|
|
2858
|
+
query?: string;
|
|
2859
|
+
} | {
|
|
2860
|
+
verb: "cancel";
|
|
2861
|
+
} | {
|
|
2862
|
+
verb: "undo";
|
|
2863
|
+
} | {
|
|
2864
|
+
verb: "redo";
|
|
2865
|
+
} | {
|
|
2866
|
+
verb: "sequence";
|
|
2867
|
+
actions: Action[];
|
|
2868
|
+
};
|
|
2869
|
+
type InputSurface = "keyboard" | "gamepad" | "voice" | "touch" | "command_palette";
|
|
2870
|
+
interface ActionEvent {
|
|
2871
|
+
action: Action;
|
|
2872
|
+
source: InputSurface;
|
|
2873
|
+
timestamp: number;
|
|
2874
|
+
inputTrace?: string[];
|
|
2875
|
+
}
|
|
2876
|
+
interface ActionContext {
|
|
2877
|
+
activeSurface: SurfaceId;
|
|
2878
|
+
activeTab: string;
|
|
2879
|
+
selection: string[];
|
|
2880
|
+
isTextFocused: boolean;
|
|
2881
|
+
isModalOpen: boolean;
|
|
2882
|
+
}
|
|
2883
|
+
type ActionPredicate = (ctx: ActionContext) => boolean;
|
|
2884
|
+
interface KeyboardTrigger {
|
|
2885
|
+
type: "chord" | "key" | "sequence";
|
|
2886
|
+
keys: string[];
|
|
2887
|
+
timeout?: number;
|
|
2888
|
+
}
|
|
2889
|
+
type GamepadButton = "a" | "b" | "x" | "y" | "lb" | "rb" | "lt" | "rt" | "back" | "start" | "ls" | "rs" | "dpad_up" | "dpad_down" | "dpad_left" | "dpad_right";
|
|
2890
|
+
interface GamepadTrigger {
|
|
2891
|
+
type: "button" | "combo" | "axis";
|
|
2892
|
+
buttons?: GamepadButton[];
|
|
2893
|
+
sequence?: {
|
|
2894
|
+
button: GamepadButton;
|
|
2895
|
+
holdMs?: number;
|
|
2896
|
+
}[];
|
|
2897
|
+
axis?: {
|
|
2898
|
+
stick: "left" | "right";
|
|
2899
|
+
direction: "up" | "down" | "left" | "right";
|
|
2900
|
+
threshold?: number;
|
|
2901
|
+
};
|
|
2902
|
+
}
|
|
2903
|
+
interface VoiceTrigger {
|
|
2904
|
+
type: "intent";
|
|
2905
|
+
patterns: string[];
|
|
2906
|
+
confidenceThreshold?: number;
|
|
2907
|
+
}
|
|
2908
|
+
interface TouchTrigger {
|
|
2909
|
+
type: "gesture";
|
|
2910
|
+
gesture: "swipe_left" | "swipe_right" | "swipe_up" | "swipe_down" | "pinch_in" | "pinch_out" | "long_press" | "double_tap" | "three_finger_swipe";
|
|
2911
|
+
}
|
|
2912
|
+
type InputTrigger = KeyboardTrigger | GamepadTrigger | VoiceTrigger | TouchTrigger;
|
|
2913
|
+
interface ActionBinding {
|
|
2914
|
+
id: string;
|
|
2915
|
+
action: Action;
|
|
2916
|
+
label: string;
|
|
2917
|
+
category: string;
|
|
2918
|
+
when: ActionPredicate;
|
|
2919
|
+
trigger: InputTrigger;
|
|
2920
|
+
surface: InputSurface;
|
|
2921
|
+
}
|
|
2922
|
+
/** Sequence two actions (flattens nested sequences) */
|
|
2923
|
+
declare function seq(a: Action, b: Action): Action;
|
|
2924
|
+
/** Navigate then execute */
|
|
2925
|
+
declare function goAndRun(target: NavigationTarget, skill: SkillRef): Action;
|
|
2926
|
+
/** Delegate then observe */
|
|
2927
|
+
declare function delegateAndWatch(assignment: DelegateAssignment, metric: ObserveTarget): Action;
|
|
2928
|
+
|
|
2929
|
+
/**
|
|
2930
|
+
* ActionBus — Singleton event bus for the Action Algebra
|
|
2931
|
+
*
|
|
2932
|
+
* All input surfaces publish ActionEvents here.
|
|
2933
|
+
* The executor and any observers subscribe here.
|
|
2934
|
+
*
|
|
2935
|
+
* @module core/primitives/action-bus
|
|
2936
|
+
*/
|
|
2937
|
+
|
|
2938
|
+
type ActionBusEvents = {
|
|
2939
|
+
"action:dispatched": ActionEvent;
|
|
2940
|
+
"action:executed": ActionEvent & {
|
|
2941
|
+
result: "success" | "error";
|
|
2942
|
+
error?: string;
|
|
2943
|
+
};
|
|
2944
|
+
"action:cancelled": {
|
|
2945
|
+
reason: string;
|
|
2946
|
+
timestamp: number;
|
|
2947
|
+
};
|
|
2948
|
+
"context:changed": ActionContext;
|
|
2949
|
+
};
|
|
2950
|
+
declare function getActionBus(): TypedEventBus<ActionBusEvents>;
|
|
2951
|
+
declare function dispatchAction(event: ActionEvent): void;
|
|
2952
|
+
declare function onAction(handler: (event: ActionEvent) => void): () => void;
|
|
2953
|
+
|
|
2954
|
+
/**
|
|
2955
|
+
* Mesh SDK — Event emission, subscription, and query
|
|
2956
|
+
*
|
|
2957
|
+
* Cross-layer communication via signals and the action bus.
|
|
2958
|
+
* Hides Interaction primitive internals, SDKMessage, AXON internals.
|
|
2959
|
+
*
|
|
2960
|
+
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
2961
|
+
* @module sdk/mesh
|
|
2962
|
+
*/
|
|
2963
|
+
|
|
2964
|
+
type mesh_Action = Action;
|
|
2965
|
+
type mesh_ActionBinding = ActionBinding;
|
|
2966
|
+
type mesh_ActionBusEvents = ActionBusEvents;
|
|
2967
|
+
type mesh_ActionContext = ActionContext;
|
|
2968
|
+
type mesh_ActionEvent = ActionEvent;
|
|
2969
|
+
type mesh_InputSurface = InputSurface;
|
|
2970
|
+
type mesh_Signal<T = unknown> = Signal<T>;
|
|
2971
|
+
type mesh_SignalBus = SignalBus;
|
|
2972
|
+
type mesh_SignalHandler<T = unknown> = SignalHandler<T>;
|
|
2973
|
+
type mesh_SignalType = SignalType;
|
|
2974
|
+
declare const mesh_createSignalBus: typeof createSignalBus;
|
|
2975
|
+
declare const mesh_delegateAndWatch: typeof delegateAndWatch;
|
|
2976
|
+
declare const mesh_dispatchAction: typeof dispatchAction;
|
|
2977
|
+
declare const mesh_emitSignal: typeof emitSignal;
|
|
2978
|
+
declare const mesh_getActionBus: typeof getActionBus;
|
|
2979
|
+
declare const mesh_getSignalBus: typeof getSignalBus;
|
|
2980
|
+
declare const mesh_goAndRun: typeof goAndRun;
|
|
2981
|
+
declare const mesh_onAction: typeof onAction;
|
|
2982
|
+
declare const mesh_seq: typeof seq;
|
|
2983
|
+
declare const mesh_subscribeToSignals: typeof subscribeToSignals;
|
|
2984
|
+
declare namespace mesh {
|
|
2985
|
+
export { type mesh_Action as Action, type mesh_ActionBinding as ActionBinding, type mesh_ActionBusEvents as ActionBusEvents, type mesh_ActionContext as ActionContext, type mesh_ActionEvent as ActionEvent, type mesh_InputSurface as InputSurface, type mesh_Signal as Signal, type mesh_SignalBus as SignalBus, type mesh_SignalHandler as SignalHandler, type mesh_SignalType as SignalType, mesh_createSignalBus as createSignalBus, mesh_delegateAndWatch as delegateAndWatch, mesh_dispatchAction as dispatchAction, mesh_emitSignal as emitSignal, mesh_getActionBus as getActionBus, mesh_getSignalBus as getSignalBus, mesh_goAndRun as goAndRun, mesh_onAction as onAction, mesh_seq as seq, mesh_subscribeToSignals as subscribeToSignals };
|
|
2986
|
+
}
|
|
2987
|
+
|
|
2988
|
+
type brain_CoherenceConfig = CoherenceConfig;
|
|
2989
|
+
type brain_CoherenceInput = CoherenceInput;
|
|
2990
|
+
type brain_CoherenceMetrics = CoherenceMetrics;
|
|
2991
|
+
type brain_CoherenceResult = CoherenceResult;
|
|
2992
|
+
type brain_KuramotoStepOptions = KuramotoStepOptions;
|
|
2993
|
+
type brain_OrderParameter = OrderParameter;
|
|
2994
|
+
declare const brain_calculateCoherence: typeof calculateCoherence;
|
|
2995
|
+
declare const brain_calculateCoherenceWithExplanations: typeof calculateCoherenceWithExplanations;
|
|
2996
|
+
declare const brain_getCoherenceSuggestions: typeof getCoherenceSuggestions;
|
|
2997
|
+
declare const brain_isCoherent: typeof isCoherent;
|
|
2998
|
+
declare const brain_kuramotoStep: typeof kuramotoStep;
|
|
2999
|
+
declare const brain_orderParameter: typeof orderParameter;
|
|
3000
|
+
declare const brain_phaseLockingValue: typeof phaseLockingValue;
|
|
3001
|
+
declare const brain_wrapTo2Pi: typeof wrapTo2Pi;
|
|
3002
|
+
declare const brain_wrapToPi: typeof wrapToPi;
|
|
3003
|
+
declare namespace brain {
|
|
3004
|
+
export { type brain_CoherenceConfig as CoherenceConfig, type brain_CoherenceInput as CoherenceInput, type brain_CoherenceMetrics as CoherenceMetrics, type brain_CoherenceResult as CoherenceResult, type brain_KuramotoStepOptions as KuramotoStepOptions, type brain_OrderParameter as OrderParameter, brain_calculateCoherence as calculateCoherence, brain_calculateCoherenceWithExplanations as calculateCoherenceWithExplanations, brain_getCoherenceSuggestions as getCoherenceSuggestions, brain_isCoherent as isCoherent, brain_kuramotoStep as kuramotoStep, brain_orderParameter as orderParameter, brain_phaseLockingValue as phaseLockingValue, brain_wrapTo2Pi as wrapTo2Pi, brain_wrapToPi as wrapToPi };
|
|
3005
|
+
}
|
|
3006
|
+
|
|
3007
|
+
/**
|
|
3008
|
+
* Agent Communication Bus — in-memory message passing for skill agents.
|
|
3009
|
+
*
|
|
3010
|
+
* Scoped per skill run. Agents publish findings, review requests, and
|
|
3011
|
+
* delegation requests. Downstream agents receive accumulated context
|
|
3012
|
+
* via their system prompt.
|
|
3013
|
+
*
|
|
3014
|
+
* @module skills/agent-bus
|
|
3015
|
+
*/
|
|
3016
|
+
type AgentMessageType = "finding" | "question" | "review_request" | "review_response" | "delegation_request" | "delegation_response";
|
|
3017
|
+
interface AgentMessage {
|
|
3018
|
+
fromAgent: string;
|
|
3019
|
+
toAgent?: string;
|
|
3020
|
+
type: AgentMessageType;
|
|
3021
|
+
payload: string;
|
|
3022
|
+
timestamp: number;
|
|
3023
|
+
runId: string;
|
|
3024
|
+
}
|
|
3025
|
+
type MessageHandler = (msg: AgentMessage) => void;
|
|
3026
|
+
interface AgentBus {
|
|
3027
|
+
publish(msg: AgentMessage): void;
|
|
3028
|
+
query(filter: {
|
|
3029
|
+
fromAgent?: string;
|
|
3030
|
+
type?: string;
|
|
3031
|
+
}): AgentMessage[];
|
|
3032
|
+
subscribe(agentId: string, handler: MessageHandler): () => void;
|
|
3033
|
+
getAll(): AgentMessage[];
|
|
3034
|
+
}
|
|
3035
|
+
/**
|
|
3036
|
+
* Create an AgentBus scoped to a single skill run.
|
|
3037
|
+
* Messages are stored in-memory (array). No persistence needed —
|
|
3038
|
+
* the bus lifetime matches the SkillRunner instance.
|
|
3039
|
+
*/
|
|
3040
|
+
declare function createAgentBus(runId: string): AgentBus;
|
|
3041
|
+
|
|
3042
|
+
/**
|
|
3043
|
+
* Protocol SDK — MCP and A2A protocol connections
|
|
3044
|
+
*
|
|
3045
|
+
* Delegation primitives and agent communication types.
|
|
3046
|
+
* Hides MCP client lifecycle, A2A internals.
|
|
3047
|
+
*
|
|
3048
|
+
* @copyright © 2026 Intuition Labs LLC. All rights reserved. Patent Pending.
|
|
3049
|
+
* @module sdk/protocol
|
|
3050
|
+
*/
|
|
3051
|
+
|
|
3052
|
+
type protocol_AgentBus = AgentBus;
|
|
3053
|
+
type protocol_AgentMessage = AgentMessage;
|
|
3054
|
+
type protocol_AgentMessageType = AgentMessageType;
|
|
3055
|
+
type protocol_DelegationChain = DelegationChain;
|
|
3056
|
+
type protocol_DelegationEdge<S = SurfaceId, T = SurfaceId> = DelegationEdge<S, T>;
|
|
3057
|
+
type protocol_DelegationEdgeInput<S = SurfaceId, T = SurfaceId> = DelegationEdgeInput<S, T>;
|
|
3058
|
+
type protocol_DelegationEndpoint<S = SurfaceId> = DelegationEndpoint<S>;
|
|
3059
|
+
declare const protocol_createAgentBus: typeof createAgentBus;
|
|
3060
|
+
declare const protocol_createDelegationChain: typeof createDelegationChain;
|
|
3061
|
+
declare const protocol_createDelegationEdge: typeof createDelegationEdge;
|
|
3062
|
+
declare const protocol_isValidSurfaceId: typeof isValidSurfaceId;
|
|
3063
|
+
declare namespace protocol {
|
|
3064
|
+
export { type protocol_AgentBus as AgentBus, type protocol_AgentMessage as AgentMessage, type protocol_AgentMessageType as AgentMessageType, type protocol_DelegationChain as DelegationChain, type protocol_DelegationEdge as DelegationEdge, type protocol_DelegationEdgeInput as DelegationEdgeInput, type protocol_DelegationEndpoint as DelegationEndpoint, protocol_createAgentBus as createAgentBus, protocol_createDelegationChain as createDelegationChain, protocol_createDelegationEdge as createDelegationEdge, protocol_isValidSurfaceId as isValidSurfaceId };
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
/**
|
|
3068
|
+
* MCP Sampling Support (MCP Specification 2025-11-25)
|
|
3069
|
+
*
|
|
3070
|
+
* Enables MCP servers to request LLM completions from clients.
|
|
3071
|
+
* This allows servers to execute agentic loops using the user's tokens
|
|
3072
|
+
* while maintaining user control over model interactions.
|
|
3073
|
+
*
|
|
3074
|
+
* @specification MCP 2025-11-25
|
|
3075
|
+
* @see https://modelcontextprotocol.io/specification/2025-11-25/client/sampling
|
|
3076
|
+
*/
|
|
3077
|
+
interface MCPSamplingCapabilities {
|
|
3078
|
+
/** Whether sampling is enabled */
|
|
3079
|
+
enabled: boolean;
|
|
3080
|
+
/** Available models for sampling */
|
|
3081
|
+
models?: string[];
|
|
3082
|
+
/** Maximum tokens per request */
|
|
3083
|
+
maxTokens?: number;
|
|
3084
|
+
/** Supported sampling parameters */
|
|
3085
|
+
supportedParams?: string[];
|
|
3086
|
+
}
|
|
3087
|
+
|
|
3088
|
+
/** JSON Schema type for tool input/output definitions */
|
|
3089
|
+
type JSONSchemaType = Record<string, unknown>;
|
|
3090
|
+
/** Metadata record for MCP requests/responses */
|
|
3091
|
+
type MCPMetadata = Record<string, unknown>;
|
|
3092
|
+
/** Server process reference type - can be ChildProcess or any spawned process */
|
|
3093
|
+
type MCPServerProcess = {
|
|
3094
|
+
kill: () => void;
|
|
3095
|
+
stdin?: unknown;
|
|
3096
|
+
stdout?: unknown;
|
|
3097
|
+
stderr?: unknown;
|
|
3098
|
+
};
|
|
3099
|
+
interface MCPServer {
|
|
3100
|
+
id: string;
|
|
3101
|
+
name: string;
|
|
3102
|
+
package: string;
|
|
3103
|
+
status: "disconnected" | "starting" | "connected" | "error";
|
|
3104
|
+
client?: Client;
|
|
3105
|
+
transport?: StdioClientTransport;
|
|
3106
|
+
tools?: MCPTool[];
|
|
3107
|
+
resources?: MCPResource[];
|
|
3108
|
+
prompts?: MCPPrompt[];
|
|
3109
|
+
lastError?: string;
|
|
3110
|
+
process?: MCPServerProcess;
|
|
3111
|
+
command?: string;
|
|
3112
|
+
args?: string[];
|
|
3113
|
+
protocolVersion?: string;
|
|
3114
|
+
capabilities?: MCPServerCapabilities;
|
|
3115
|
+
oauth?: MCPOAuthConfig;
|
|
3116
|
+
}
|
|
3117
|
+
interface MCPTool {
|
|
3118
|
+
name: string;
|
|
3119
|
+
description: string;
|
|
3120
|
+
inputSchema: JSONSchemaType;
|
|
3121
|
+
outputSchema?: JSONSchemaType;
|
|
3122
|
+
serverId: string;
|
|
3123
|
+
serverName: string;
|
|
3124
|
+
icon?: string;
|
|
3125
|
+
category?: string;
|
|
3126
|
+
_meta?: MCPMetadata;
|
|
3127
|
+
}
|
|
3128
|
+
interface MCPResource {
|
|
3129
|
+
uri: string;
|
|
3130
|
+
name: string;
|
|
3131
|
+
description?: string;
|
|
3132
|
+
mimeType?: string;
|
|
3133
|
+
icon?: string;
|
|
3134
|
+
_meta?: MCPMetadata;
|
|
3135
|
+
}
|
|
3136
|
+
/** Prompt argument definition */
|
|
3137
|
+
interface MCPPromptArgument {
|
|
3138
|
+
name: string;
|
|
3139
|
+
description?: string;
|
|
3140
|
+
required?: boolean;
|
|
3141
|
+
}
|
|
3142
|
+
interface MCPPrompt {
|
|
3143
|
+
name: string;
|
|
3144
|
+
description?: string;
|
|
3145
|
+
arguments?: MCPPromptArgument[];
|
|
3146
|
+
icon?: string;
|
|
3147
|
+
_meta?: MCPMetadata;
|
|
3148
|
+
}
|
|
3149
|
+
interface MCPServerCapabilities {
|
|
3150
|
+
experimental?: Record<string, unknown>;
|
|
3151
|
+
elicitation?: boolean;
|
|
3152
|
+
structuredContent?: boolean;
|
|
3153
|
+
resourceLinks?: boolean;
|
|
3154
|
+
sampling?: boolean | MCPSamplingCapabilities;
|
|
3155
|
+
roots?: boolean;
|
|
3156
|
+
tasks?: boolean;
|
|
3157
|
+
}
|
|
3158
|
+
interface MCPOAuthConfig {
|
|
3159
|
+
authorizationUrl?: string;
|
|
3160
|
+
tokenUrl?: string;
|
|
3161
|
+
clientId?: string;
|
|
3162
|
+
scopes?: string[];
|
|
3163
|
+
resourceServer?: boolean;
|
|
3164
|
+
resourceIndicators?: string[];
|
|
3165
|
+
}
|
|
3166
|
+
|
|
3167
|
+
/**
|
|
3168
|
+
* A2A Protocol Module (v0.3+)
|
|
3169
|
+
* Agent-to-Agent communication protocol (Linux Foundation AAIF standard)
|
|
3170
|
+
*
|
|
3171
|
+
* This module provides a comprehensive implementation of the A2A protocol for
|
|
3172
|
+
* inter-agent communication within Terminals.tech.
|
|
3173
|
+
*
|
|
3174
|
+
* **Features:**
|
|
3175
|
+
* - Agent card registration and discovery
|
|
3176
|
+
* - Capability-based agent lookup
|
|
3177
|
+
* - Message validation against agent capabilities
|
|
3178
|
+
* - gRPC transport support (v0.3)
|
|
3179
|
+
* - Streaming via SSE (v0.3)
|
|
3180
|
+
* - Push notifications (v0.3)
|
|
3181
|
+
* - Extensions mechanism (v0.3)
|
|
3182
|
+
* - Security card signing (v0.3)
|
|
3183
|
+
* - QuerySkill() dynamic discovery (Q1 2026)
|
|
3184
|
+
*
|
|
3185
|
+
* **Reference:** https://github.com/google-a2a/A2A
|
|
3186
|
+
* @module a2a
|
|
3187
|
+
* @version 0.3+
|
|
3188
|
+
*/
|
|
3189
|
+
/**
|
|
3190
|
+
* Agent card describing capabilities and endpoints (v0.3+)
|
|
3191
|
+
*/
|
|
3192
|
+
interface A2AAgentCard {
|
|
3193
|
+
/** Unique agent identifier */
|
|
3194
|
+
id: string;
|
|
3195
|
+
/** Human-readable agent name */
|
|
3196
|
+
name: string;
|
|
3197
|
+
/** Agent description */
|
|
3198
|
+
description: string;
|
|
3199
|
+
/** List of agent capabilities */
|
|
3200
|
+
capabilities: A2ACapability[];
|
|
3201
|
+
/** Communication endpoints */
|
|
3202
|
+
endpoints: A2AEndpoint[];
|
|
3203
|
+
/** Agent version */
|
|
3204
|
+
version: string;
|
|
3205
|
+
/** Protocol version */
|
|
3206
|
+
protocol: "a2a/1.0" | "a2a/0.3";
|
|
3207
|
+
/** Extended capabilities (v0.3+) */
|
|
3208
|
+
extendedCapabilities?: {
|
|
3209
|
+
streaming: boolean;
|
|
3210
|
+
pushNotifications: boolean;
|
|
3211
|
+
stateTransitionHistory: boolean;
|
|
3212
|
+
};
|
|
3213
|
+
/** Supported extensions (v0.3+) */
|
|
3214
|
+
extensions?: A2AExtension[];
|
|
3215
|
+
/** Push notification endpoint (v0.3+) */
|
|
3216
|
+
pushNotificationEndpoint?: string;
|
|
3217
|
+
/** Security signature (v0.3+) */
|
|
3218
|
+
signature?: string;
|
|
3219
|
+
signedAt?: number;
|
|
3220
|
+
publicKey?: string;
|
|
3221
|
+
}
|
|
3222
|
+
/**
|
|
3223
|
+
* Agent capability definition
|
|
3224
|
+
*/
|
|
3225
|
+
interface A2ACapability {
|
|
3226
|
+
/** Capability name */
|
|
3227
|
+
name: string;
|
|
3228
|
+
/** Capability description */
|
|
3229
|
+
description: string;
|
|
3230
|
+
/** Optional JSON schema for inputs */
|
|
3231
|
+
inputSchema?: Record<string, unknown>;
|
|
3232
|
+
/** Optional JSON schema for outputs */
|
|
3233
|
+
outputSchema?: Record<string, unknown>;
|
|
3234
|
+
}
|
|
3235
|
+
/**
|
|
3236
|
+
* Agent communication endpoint (v0.3+ with gRPC)
|
|
3237
|
+
*/
|
|
3238
|
+
interface A2AEndpoint {
|
|
3239
|
+
/** Endpoint protocol type */
|
|
3240
|
+
type: "http" | "ws" | "grpc";
|
|
3241
|
+
/** Endpoint URL */
|
|
3242
|
+
url: string;
|
|
3243
|
+
/** Optional authentication configuration */
|
|
3244
|
+
authentication?: A2AAuth;
|
|
3245
|
+
/** gRPC service definition (for grpc type) */
|
|
3246
|
+
protoFile?: string;
|
|
3247
|
+
/** gRPC package name */
|
|
3248
|
+
packageName?: string;
|
|
3249
|
+
/** gRPC service name */
|
|
3250
|
+
serviceName?: string;
|
|
3251
|
+
}
|
|
3252
|
+
/**
|
|
3253
|
+
* Authentication configuration for endpoints
|
|
3254
|
+
*/
|
|
3255
|
+
interface A2AAuth {
|
|
3256
|
+
/** Authentication type */
|
|
3257
|
+
type: "bearer" | "api-key" | "oauth2" | "none";
|
|
3258
|
+
/** Optional authentication configuration */
|
|
3259
|
+
config?: Record<string, unknown>;
|
|
3260
|
+
}
|
|
3261
|
+
/**
|
|
3262
|
+
* A2A protocol message
|
|
3263
|
+
*/
|
|
3264
|
+
interface A2AMessage {
|
|
3265
|
+
/** Unique message identifier */
|
|
3266
|
+
id: string;
|
|
3267
|
+
/** Source agent ID */
|
|
3268
|
+
from: string;
|
|
3269
|
+
/** Target agent ID */
|
|
3270
|
+
to: string;
|
|
3271
|
+
/** Message type */
|
|
3272
|
+
type: "request" | "response" | "notification" | "error";
|
|
3273
|
+
/** Capability being invoked */
|
|
3274
|
+
capability: string;
|
|
3275
|
+
/** Message payload */
|
|
3276
|
+
payload: unknown;
|
|
3277
|
+
/** Message timestamp (milliseconds since epoch) */
|
|
3278
|
+
timestamp: number;
|
|
3279
|
+
/** Optional correlation ID for request-response pairing */
|
|
3280
|
+
correlationId?: string;
|
|
3281
|
+
/** Optional additional metadata */
|
|
3282
|
+
metadata?: Record<string, unknown>;
|
|
3283
|
+
}
|
|
3284
|
+
/**
|
|
3285
|
+
* A2A Extension (v0.3+)
|
|
3286
|
+
*
|
|
3287
|
+
* Extensions allow agents to declare support for custom capabilities
|
|
3288
|
+
* beyond the base protocol.
|
|
3289
|
+
*/
|
|
3290
|
+
interface A2AExtension {
|
|
3291
|
+
/** Extension name */
|
|
3292
|
+
name: string;
|
|
3293
|
+
/** Extension version */
|
|
3294
|
+
version: string;
|
|
3295
|
+
/** Extension description */
|
|
3296
|
+
description?: string;
|
|
3297
|
+
/** Extension methods */
|
|
3298
|
+
methods: Array<{
|
|
3299
|
+
name: string;
|
|
3300
|
+
description?: string;
|
|
3301
|
+
inputSchema: Record<string, unknown>;
|
|
3302
|
+
outputSchema: Record<string, unknown>;
|
|
3303
|
+
}>;
|
|
3304
|
+
}
|
|
3305
|
+
|
|
3306
|
+
/**
|
|
3307
|
+
* String literal type for high-level message types
|
|
3308
|
+
*/
|
|
3309
|
+
type AxonMessageTypeString = "command" | "event" | "query" | "response";
|
|
3310
|
+
/**
|
|
3311
|
+
* Protocol type for message routing
|
|
3312
|
+
*/
|
|
3313
|
+
type AxonProtocolType = "mcp" | "a2a" | "internal";
|
|
3314
|
+
/**
|
|
3315
|
+
* High-level AXON message for JSON-based protocol communication.
|
|
3316
|
+
*
|
|
3317
|
+
* @deprecated Use `SDKMessage` from `../core/primitives/message` instead.
|
|
3318
|
+
* This type is maintained for backward compatibility with existing code.
|
|
3319
|
+
* SDKMessage is the canonical message type across all SDK layers.
|
|
3320
|
+
*
|
|
3321
|
+
* Migration path:
|
|
3322
|
+
* - Replace `HighLevelAxonMessage` imports with `SDKMessage`
|
|
3323
|
+
* - Use `createMessage()` or helpers from message.ts
|
|
3324
|
+
* - For source/target, use `SDKAddress` instead of plain strings
|
|
3325
|
+
*
|
|
3326
|
+
* For binary/low-level communication, use AxonMessage instead.
|
|
3327
|
+
*/
|
|
3328
|
+
interface HighLevelAxonMessage {
|
|
3329
|
+
id: string;
|
|
3330
|
+
type: AxonMessageTypeString;
|
|
3331
|
+
source: string;
|
|
3332
|
+
target: string;
|
|
3333
|
+
payload: unknown;
|
|
3334
|
+
meta: {
|
|
3335
|
+
timestamp: number;
|
|
3336
|
+
traceId: string;
|
|
3337
|
+
priority?: number;
|
|
3338
|
+
/** @deprecated Use SDKMessage.meta.correlationId */
|
|
3339
|
+
correlationId?: string;
|
|
3340
|
+
/** @deprecated Use SDKMessage.meta.ttl */
|
|
3341
|
+
ttl?: number;
|
|
3342
|
+
/** @deprecated Use SDKMessage.meta.sessionId */
|
|
3343
|
+
sessionId?: string;
|
|
3344
|
+
/** @deprecated Use SDKMessage.meta.interactionId */
|
|
3345
|
+
interactionId?: string;
|
|
3346
|
+
};
|
|
3347
|
+
protocol?: {
|
|
3348
|
+
type: AxonProtocolType;
|
|
3349
|
+
version: string;
|
|
3350
|
+
originalMessage?: unknown;
|
|
3351
|
+
};
|
|
3352
|
+
/**
|
|
3353
|
+
* Optional capability identifier for L5 protocol compatibility.
|
|
3354
|
+
* @deprecated Use SDKMessage.capability instead
|
|
3355
|
+
*/
|
|
3356
|
+
capability?: string;
|
|
3357
|
+
}
|
|
3358
|
+
|
|
3359
|
+
/**
|
|
3360
|
+
* Protocol Bridge for MCP and A2A
|
|
3361
|
+
*
|
|
3362
|
+
* Unified bridge layer that enables interoperability between MCP servers
|
|
3363
|
+
* and A2A agents, routing messages through the AXON message bus.
|
|
3364
|
+
*
|
|
3365
|
+
* This bridge allows:
|
|
3366
|
+
* - MCP tools to be exposed as A2A capabilities
|
|
3367
|
+
* - A2A agents to be accessed as MCP servers
|
|
3368
|
+
* - Seamless protocol translation
|
|
3369
|
+
* - Unified routing through AXON
|
|
3370
|
+
*/
|
|
3371
|
+
|
|
3372
|
+
/**
|
|
3373
|
+
* Re-export HighLevelAxonMessage as AxonMessage for backward compatibility.
|
|
3374
|
+
*
|
|
3375
|
+
* @deprecated Use SDKMessage from '../core/primitives/message' instead.
|
|
3376
|
+
* This alias will be removed in a future version.
|
|
3377
|
+
*/
|
|
3378
|
+
type AxonMessage = HighLevelAxonMessage;
|
|
3379
|
+
/** MCP message structure */
|
|
3380
|
+
interface MCPMessage {
|
|
3381
|
+
method?: string;
|
|
3382
|
+
params?: Record<string, unknown>;
|
|
3383
|
+
id?: string;
|
|
3384
|
+
}
|
|
3385
|
+
/**
|
|
3386
|
+
* Protocol Bridge
|
|
3387
|
+
*
|
|
3388
|
+
* Translates between MCP, A2A, and AXON protocols
|
|
3389
|
+
*/
|
|
3390
|
+
declare class ProtocolBridge {
|
|
3391
|
+
private mcpToA2AMap;
|
|
3392
|
+
private a2aToMCPMap;
|
|
3393
|
+
private axonBus?;
|
|
3394
|
+
constructor(axonBus?: AxonMessageBus);
|
|
3395
|
+
/**
|
|
3396
|
+
* Set AXON message bus
|
|
3397
|
+
*/
|
|
3398
|
+
setAxonBus(bus: AxonMessageBus): void;
|
|
3399
|
+
/**
|
|
3400
|
+
* Convert MCP tool to A2A capability
|
|
3401
|
+
*/
|
|
3402
|
+
mcpToolToA2ACapability(tool: MCPTool): A2ACapability;
|
|
3403
|
+
/**
|
|
3404
|
+
* Convert MCP server to A2A agent card
|
|
3405
|
+
*/
|
|
3406
|
+
mcpServerToA2AAgent(server: MCPServer): A2AAgentCard;
|
|
3407
|
+
/**
|
|
3408
|
+
* Convert A2A capability to MCP tool
|
|
3409
|
+
*/
|
|
3410
|
+
a2aCapabilityToMCPTool(capability: A2ACapability, agentId: string, agentName: string): MCPTool;
|
|
3411
|
+
/**
|
|
3412
|
+
* Convert A2A agent to MCP server facade
|
|
3413
|
+
*/
|
|
3414
|
+
a2aAgentToMCPServer(agent: A2AAgentCard): MCPServer;
|
|
3415
|
+
/**
|
|
3416
|
+
* Register an MCP server facade
|
|
3417
|
+
*/
|
|
3418
|
+
registerMCPServer(server: MCPServer): void;
|
|
3419
|
+
/**
|
|
3420
|
+
* Register an A2A agent facade
|
|
3421
|
+
*/
|
|
3422
|
+
registerA2AAgent(agent: A2AAgentCard): void;
|
|
3423
|
+
/**
|
|
3424
|
+
* Route message through AXON
|
|
3425
|
+
* @returns true if message was routed, false if rejected due to validation failure
|
|
3426
|
+
*/
|
|
3427
|
+
route(message: AxonMessage): Promise<boolean>;
|
|
3428
|
+
/**
|
|
3429
|
+
* Convert MCP message to AXON message
|
|
3430
|
+
*/
|
|
3431
|
+
mcpMessageToAxon(mcpMessage: MCPMessage, source: string, target: string): AxonMessage;
|
|
3432
|
+
/**
|
|
3433
|
+
* Convert A2A message to AXON message
|
|
3434
|
+
*/
|
|
3435
|
+
a2aMessageToAxon(a2aMessage: A2AMessage): AxonMessage;
|
|
3436
|
+
/**
|
|
3437
|
+
* Convert AXON message to MCP message
|
|
3438
|
+
*
|
|
3439
|
+
* SECURITY: Uses secureValidate to prevent unsafe type assertions at protocol boundaries.
|
|
3440
|
+
* All external data is validated before use.
|
|
3441
|
+
*/
|
|
3442
|
+
axonToMCPMessage(axonMessage: AxonMessage): MCPMessage;
|
|
3443
|
+
/**
|
|
3444
|
+
* Convert AXON message to A2A message
|
|
3445
|
+
*
|
|
3446
|
+
* SECURITY: Uses secureValidate to prevent unsafe type assertions at protocol boundaries.
|
|
3447
|
+
* All external data is validated before use.
|
|
3448
|
+
*/
|
|
3449
|
+
axonToA2AMessage(axonMessage: AxonMessage): A2AMessage;
|
|
3450
|
+
/**
|
|
3451
|
+
* Get mapping from MCP server ID to A2A agent ID
|
|
3452
|
+
*/
|
|
3453
|
+
getMCPToA2AMapping(mcpServerId: string): string | undefined;
|
|
3454
|
+
/**
|
|
3455
|
+
* Get mapping from A2A agent ID to MCP server ID
|
|
3456
|
+
*/
|
|
3457
|
+
getA2AToMCPMapping(a2aAgentId: string): string | undefined;
|
|
3458
|
+
/**
|
|
3459
|
+
* Clear all mappings
|
|
3460
|
+
*/
|
|
3461
|
+
clearMappings(): void;
|
|
3462
|
+
private routeMCPMessage;
|
|
3463
|
+
private routeA2AMessage;
|
|
3464
|
+
private mapA2ATypeToAxon;
|
|
3465
|
+
private mapAxonTypeToA2A;
|
|
3466
|
+
}
|
|
3467
|
+
/**
|
|
3468
|
+
* AXON Message Bus Interface
|
|
3469
|
+
*
|
|
3470
|
+
* Simplified interface for message bus integration.
|
|
3471
|
+
* Supports both legacy AxonMessage and canonical SDKMessage formats.
|
|
3472
|
+
*/
|
|
3473
|
+
interface AxonMessageBus {
|
|
3474
|
+
/**
|
|
3475
|
+
* @deprecated Use publishSDK for canonical SDKMessage support
|
|
3476
|
+
*/
|
|
3477
|
+
publish(message: AxonMessage): Promise<void>;
|
|
3478
|
+
/**
|
|
3479
|
+
* @deprecated Use subscribeSDK for canonical SDKMessage support
|
|
3480
|
+
*/
|
|
3481
|
+
subscribe(topic: string, handler: (message: AxonMessage) => Promise<void>): () => void;
|
|
3482
|
+
unsubscribe(topic: string): void;
|
|
3483
|
+
}
|
|
3484
|
+
/**
|
|
3485
|
+
* Extended AXON Message Bus Interface with SDKMessage support
|
|
3486
|
+
*
|
|
3487
|
+
* Provides first-class support for the canonical SDKMessage type
|
|
3488
|
+
* while maintaining backward compatibility with AxonMessage.
|
|
3489
|
+
*/
|
|
3490
|
+
interface SDKMessageBus extends AxonMessageBus {
|
|
3491
|
+
/** Publish a canonical SDKMessage */
|
|
3492
|
+
publishSDK<P = unknown>(message: SDKMessage<P>): Promise<void>;
|
|
3493
|
+
/** Subscribe to SDKMessage events */
|
|
3494
|
+
subscribeSDK<P = unknown>(topic: string, handler: (message: SDKMessage<P>) => Promise<void>): () => void;
|
|
3495
|
+
}
|
|
3496
|
+
/**
|
|
3497
|
+
* Simple in-memory AXON message bus implementation
|
|
3498
|
+
*
|
|
3499
|
+
* Implements both AxonMessageBus (legacy) and SDKMessageBus (canonical) interfaces.
|
|
3500
|
+
* Internally stores SDKMessage and converts as needed for legacy handlers.
|
|
3501
|
+
*/
|
|
3502
|
+
declare class InMemoryAxonBus implements SDKMessageBus {
|
|
3503
|
+
private subscribers;
|
|
3504
|
+
private sdkSubscribers;
|
|
3505
|
+
/**
|
|
3506
|
+
* Publish a legacy AxonMessage
|
|
3507
|
+
* @deprecated Use publishSDK for canonical SDKMessage support
|
|
3508
|
+
*/
|
|
3509
|
+
publish(message: AxonMessage): Promise<void>;
|
|
3510
|
+
/**
|
|
3511
|
+
* Publish a canonical SDKMessage
|
|
3512
|
+
*/
|
|
3513
|
+
publishSDK<P = unknown>(message: SDKMessage<P>): Promise<void>;
|
|
3514
|
+
/**
|
|
3515
|
+
* Subscribe to legacy AxonMessage events
|
|
3516
|
+
* @deprecated Use subscribeSDK for canonical SDKMessage support
|
|
3517
|
+
*/
|
|
3518
|
+
subscribe(topic: string, handler: (message: AxonMessage) => Promise<void>): () => void;
|
|
3519
|
+
/**
|
|
3520
|
+
* Subscribe to canonical SDKMessage events
|
|
3521
|
+
*/
|
|
3522
|
+
subscribeSDK<P = unknown>(topic: string, handler: (message: SDKMessage<P>) => Promise<void>): () => void;
|
|
3523
|
+
unsubscribe(topic: string): void;
|
|
3524
|
+
private publishToTopic;
|
|
3525
|
+
private publishSDKToTopic;
|
|
3526
|
+
getStats(): {
|
|
3527
|
+
topics: number;
|
|
3528
|
+
totalHandlers: number;
|
|
3529
|
+
sdkHandlers: number;
|
|
3530
|
+
};
|
|
3531
|
+
}
|
|
3532
|
+
/**
|
|
3533
|
+
* Create a protocol bridge instance
|
|
3534
|
+
*/
|
|
3535
|
+
declare function createProtocolBridge(axonBus?: AxonMessageBus): ProtocolBridge;
|
|
3536
|
+
/**
|
|
3537
|
+
* Create an in-memory AXON bus
|
|
3538
|
+
*/
|
|
3539
|
+
declare function createAxonBus(): InMemoryAxonBus;
|
|
3540
|
+
|
|
3541
|
+
/**
|
|
3542
|
+
* @terminals-tech/sdk
|
|
3543
|
+
*
|
|
3544
|
+
* Curated package facade for the npm package.
|
|
3545
|
+
*/
|
|
3546
|
+
declare const SDK_VERSION = "1.0.0-rc.1";
|
|
3547
|
+
|
|
3548
|
+
export { type AxonMessage, type AxonMessageBus, brain as Brain, type CoherenceConfig, type CoherenceInput, type CoherenceMetrics, type CoherenceResult, core as Core, InMemoryAxonBus, type KuramotoStepOptions, index as L0, mesh as Mesh, type OrderParameter, protocol as Protocol, ProtocolBridge, SDK_VERSION, terminal as Terminal, calculateCoherence, calculateCoherenceWithExplanations, createAxonBus, createProtocolBridge, getCoherenceSuggestions, isCoherent, kuramotoStep, orderParameter, phaseLockingValue, wrapTo2Pi, wrapToPi };
|