@motebit/sdk 0.6.10 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,203 +1,9 @@
1
- declare const __brand: unique symbol;
2
- type Brand<T, B extends string> = T & {
3
- readonly [__brand]?: B;
4
- };
5
- export type MotebitId = Brand<string, "MotebitId">;
6
- export type DeviceId = Brand<string, "DeviceId">;
7
- export type NodeId = Brand<string, "NodeId">;
8
- export type GoalId = Brand<string, "GoalId">;
9
- export type EventId = Brand<string, "EventId">;
10
- export type ConversationId = Brand<string, "ConversationId">;
11
- export type PlanId = Brand<string, "PlanId">;
12
- export type AllocationId = Brand<string, "AllocationId">;
13
- export type SettlementId = Brand<string, "SettlementId">;
14
- export type ListingId = Brand<string, "ListingId">;
15
- export type ProposalId = Brand<string, "ProposalId">;
16
- /** Brand a string as a MotebitId after validation. */
17
- export declare function asMotebitId(id: string): MotebitId;
18
- /** Brand a string as a DeviceId after validation. */
19
- export declare function asDeviceId(id: string): DeviceId;
20
- /** Brand a string as a NodeId after validation. */
21
- export declare function asNodeId(id: string): NodeId;
22
- /** Brand a string as a GoalId after validation. */
23
- export declare function asGoalId(id: string): GoalId;
24
- /** Brand a string as an EventId after validation. */
25
- export declare function asEventId(id: string): EventId;
26
- /** Brand a string as a ConversationId after validation. */
27
- export declare function asConversationId(id: string): ConversationId;
28
- /** Brand a string as a PlanId after validation. */
29
- export declare function asPlanId(id: string): PlanId;
30
- /** Brand a string as an AllocationId after validation. */
31
- export declare function asAllocationId(id: string): AllocationId;
32
- /** Brand a string as a SettlementId after validation. */
33
- export declare function asSettlementId(id: string): SettlementId;
34
- /** Brand a string as a ListingId after validation. */
35
- export declare function asListingId(id: string): ListingId;
36
- /** Brand a string as a ProposalId after validation. */
37
- export declare function asProposalId(id: string): ProposalId;
38
- export declare enum TrustMode {
39
- Full = "full",
40
- Guarded = "guarded",
41
- Minimal = "minimal"
42
- }
43
- export declare enum BatteryMode {
44
- Normal = "normal",
45
- LowPower = "low_power",
46
- Critical = "critical"
47
- }
48
- export declare enum AgentTrustLevel {
49
- Unknown = "unknown",
50
- FirstContact = "first_contact",
51
- Verified = "verified",
52
- Trusted = "trusted",
53
- Blocked = "blocked"
54
- }
55
- export declare enum MotebitType {
56
- Personal = "personal",
57
- Service = "service",
58
- Collaborative = "collaborative"
59
- }
60
- export declare enum ProposalStatus {
61
- Pending = "pending",
62
- Accepted = "accepted",
63
- Countered = "countered",
64
- Rejected = "rejected",
65
- Withdrawn = "withdrawn",
66
- Expired = "expired"
67
- }
68
- export declare enum ProposalResponseType {
69
- Accept = "accept",
70
- Reject = "reject",
71
- Counter = "counter"
72
- }
73
- export interface AgentTrustRecord {
74
- motebit_id: MotebitId;
75
- remote_motebit_id: MotebitId;
76
- trust_level: AgentTrustLevel;
77
- public_key?: string;
78
- first_seen_at: number;
79
- last_seen_at: number;
80
- interaction_count: number;
81
- successful_tasks?: number;
82
- failed_tasks?: number;
83
- notes?: string;
84
- /** Exponential moving average of result quality [0, 1]. */
85
- avg_quality?: number;
86
- /** Number of quality samples collected. */
87
- quality_sample_count?: number;
88
- }
89
- /** Canonical AgentTrustLevel → [0,1] mapping (single source of truth). */
90
- export declare const TRUST_LEVEL_SCORES: Record<string, number>;
91
- /** Convert a trust level to its numeric score. */
92
- export declare function trustLevelToScore(level: AgentTrustLevel | string): number;
93
- /** Semiring zero — annihilator for ⊗, identity for ⊕. */
94
- export declare const TRUST_ZERO = 0;
95
- /** Semiring one — identity for ⊗. */
96
- export declare const TRUST_ONE = 1;
97
- /** ⊕: parallel paths — pick the best route. */
98
- export declare function trustAdd(a: number, b: number): number;
99
- /** ⊗: serial chain — discount per hop. */
100
- export declare function trustMultiply(a: number, b: number): number;
101
- /** Fold a chain of trust scores with ⊗. Empty chain → 1.0 (identity). */
102
- export declare function composeTrustChain(scores: number[]): number;
103
- /** Fold parallel route scores with ⊕. No routes → 0.0 (identity). */
104
- export declare function joinParallelRoutes(scores: number[]): number;
105
- /** Thresholds for automatic trust level promotion/demotion. */
106
- export interface TrustTransitionThresholds {
107
- /** Min successful tasks for FirstContact → Verified (default 5) */
108
- promoteToVerified_minTasks: number;
109
- /** Min success rate for FirstContact → Verified (default 0.8) */
110
- promoteToVerified_minRate: number;
111
- /** Min successful tasks for Verified → Trusted (default 20) */
112
- promoteToTrusted_minTasks: number;
113
- /** Min success rate for Verified → Trusted (default 0.9) */
114
- promoteToTrusted_minRate: number;
115
- /** Success rate below this triggers demotion (default 0.5) */
116
- demote_belowRate: number;
117
- /** Min total tasks before demotion can trigger (default 3) */
118
- demote_minTasks: number;
119
- }
120
- export declare const DEFAULT_TRUST_THRESHOLDS: TrustTransitionThresholds;
121
- /**
122
- * Pure: evaluate whether a trust record should transition levels.
123
- *
124
- * Promotion: sustained evidence of success (asymmetric — harder to earn).
125
- * Demotion: success rate dropping below threshold (faster — protect the network).
126
- * Blocked is never auto-assigned or auto-removed (security decision).
127
- *
128
- * Returns the new level, or null if no transition.
129
- */
130
- export declare function evaluateTrustTransition(record: AgentTrustRecord, thresholds?: Partial<TrustTransitionThresholds>): AgentTrustLevel | null;
131
- /** Structural type for recursive delegation receipt walking. */
132
- export interface DelegationReceiptLike {
133
- motebit_id: string;
134
- delegation_receipts?: DelegationReceiptLike[];
135
- }
136
- /**
137
- * Compose trust through a delegation receipt tree.
138
- *
139
- * Walks `receipt.delegation_receipts` recursively:
140
- * - Each sub-delegation: directTrust ⊗ getTrust(sub.motebit_id)
141
- * - Parallel branches joined with ⊕ (best route wins)
142
- * - No sub-delegations → returns directTrust unchanged.
143
- */
144
- export declare function composeDelegationTrust(directTrust: number, receipt: DelegationReceiptLike, getTrust: (motebitId: string) => number): number;
145
- export declare enum SensitivityLevel {
146
- None = "none",
147
- Personal = "personal",
148
- Medical = "medical",
149
- Financial = "financial",
150
- Secret = "secret"
151
- }
152
- export declare enum EventType {
153
- IdentityCreated = "identity_created",
154
- StateUpdated = "state_updated",
155
- MemoryFormed = "memory_formed",
156
- MemoryDecayed = "memory_decayed",
157
- MemoryDeleted = "memory_deleted",
158
- MemoryAccessed = "memory_accessed",
159
- ProviderSwapped = "provider_swapped",
160
- ExportRequested = "export_requested",
161
- DeleteRequested = "delete_requested",
162
- SyncCompleted = "sync_completed",
163
- AuditEntry = "audit_entry",
164
- ToolUsed = "tool_used",
165
- PolicyViolation = "policy_violation",
166
- GoalCreated = "goal_created",
167
- GoalExecuted = "goal_executed",
168
- GoalRemoved = "goal_removed",
169
- ApprovalRequested = "approval_requested",
170
- ApprovalApproved = "approval_approved",
171
- ApprovalDenied = "approval_denied",
172
- ApprovalExpired = "approval_expired",
173
- GoalCompleted = "goal_completed",
174
- GoalProgress = "goal_progress",
175
- MemoryAudit = "memory_audit",
176
- MemoryPinned = "memory_pinned",
177
- PlanCreated = "plan_created",
178
- PlanStepStarted = "plan_step_started",
179
- PlanStepCompleted = "plan_step_completed",
180
- PlanStepFailed = "plan_step_failed",
181
- PlanCompleted = "plan_completed",
182
- PlanStepDelegated = "plan_step_delegated",
183
- CredentialRevoked = "credential_revoked",
184
- IdentityRevoked = "identity_revoked",
185
- PlanFailed = "plan_failed",
186
- HousekeepingRun = "housekeeping_run",
187
- ReflectionCompleted = "reflection_completed",
188
- MemoryConsolidated = "memory_consolidated",
189
- AgentTaskCompleted = "agent_task_completed",
190
- AgentTaskFailed = "agent_task_failed",
191
- AgentTaskDenied = "agent_task_denied",
192
- ProposalCreated = "proposal_created",
193
- ProposalAccepted = "proposal_accepted",
194
- ProposalRejected = "proposal_rejected",
195
- ProposalCountered = "proposal_countered",
196
- CollaborativeStepCompleted = "collaborative_step_completed",
197
- ChainTrustComputed = "chain_trust_computed",
198
- TrustLevelChanged = "trust_level_changed",
199
- KeyRotated = "key_rotated"
200
- }
1
+ export * from "@motebit/protocol";
2
+ export * from "./models";
3
+ export * from "./color-presets";
4
+ export * from "./approval-presets";
5
+ export * from "./governance-config";
6
+ import type { SensitivityLevel, NodeId, MotebitId, TrustMode, BatteryMode, EventLogEntry, MemoryContent, MemoryCandidate, ToolDefinition, AgentTrustRecord, EventStoreAdapter, IdentityStorage, AuditLogAdapter, StateSnapshotAdapter, AuditLogSink, ConversationStoreAdapter, PlanStoreAdapter, AgentTrustStoreAdapter, ServiceListingStoreAdapter, BudgetAllocationStoreAdapter, SettlementStoreAdapter, LatencyStatsStoreAdapter, CredentialStoreAdapter, ApprovalStoreAdapter, MotebitIdentity, AuditRecord } from "@motebit/protocol";
201
7
  export declare enum RelationType {
202
8
  Related = "related",
203
9
  CausedBy = "caused_by",
@@ -207,16 +13,6 @@ export declare enum RelationType {
207
13
  PartOf = "part_of",
208
14
  Supersedes = "supersedes"
209
15
  }
210
- export declare enum MemoryType {
211
- Episodic = "episodic",
212
- Semantic = "semantic"
213
- }
214
- export interface MotebitIdentity {
215
- readonly motebit_id: MotebitId;
216
- readonly created_at: number;
217
- readonly owner_id: string;
218
- version_clock: number;
219
- }
220
16
  export interface MotebitState {
221
17
  attention: number;
222
18
  processing: number;
@@ -243,15 +39,6 @@ export declare const SPECIES_CONSTRAINTS: Readonly<{
243
39
  readonly DRIFT_VARIATION_MAX: 0.1;
244
40
  }>;
245
41
  export type SpeciesConstraints = typeof SPECIES_CONSTRAINTS;
246
- /** Cognition-facing memory content — what the agent's mind sees. */
247
- export interface MemoryContent {
248
- content: string;
249
- confidence: number;
250
- sensitivity: SensitivityLevel;
251
- memory_type?: MemoryType;
252
- valid_from?: number;
253
- valid_until?: number | null;
254
- }
255
42
  /** Full memory node including persistence metadata. */
256
43
  export interface MemoryNode extends MemoryContent {
257
44
  node_id: NodeId;
@@ -271,135 +58,51 @@ export interface MemoryEdge {
271
58
  weight: number;
272
59
  confidence: number;
273
60
  }
274
- export interface MemoryCandidate {
275
- content: string;
276
- confidence: number;
277
- sensitivity: SensitivityLevel;
278
- memory_type?: MemoryType;
279
- }
280
- export interface EventLogEntry {
281
- event_id: EventId;
282
- motebit_id: MotebitId;
283
- /** Device that originated this event (for multi-device conflict resolution) */
284
- device_id?: DeviceId;
285
- timestamp: number;
286
- event_type: EventType;
287
- payload: Record<string, unknown>;
288
- version_clock: number;
289
- tombstoned: boolean;
290
- }
291
- export declare enum RiskLevel {
292
- R0_READ = 0,
293
- R1_DRAFT = 1,
294
- R2_WRITE = 2,
295
- R3_EXECUTE = 3,
296
- R4_MONEY = 4
297
- }
298
- export declare enum DataClass {
299
- PUBLIC = "public",
300
- PRIVATE = "private",
301
- SECRET = "secret"
302
- }
303
- export declare enum SideEffect {
304
- NONE = "none",
305
- REVERSIBLE = "reversible",
306
- IRREVERSIBLE = "irreversible"
307
- }
308
- export interface ToolRiskProfile {
309
- risk: RiskLevel;
310
- dataClass: DataClass;
311
- sideEffect: SideEffect;
312
- requiresApproval: boolean;
313
- }
314
- /** M-of-N approval quorum configuration. */
315
- export interface ApprovalQuorum {
316
- /** Number of approvals required (M). */
317
- threshold: number;
318
- /** Authorized approver identifiers. */
319
- approvers: string[];
320
- /** Minimum risk level that triggers quorum (optional — default: all approval-required tools). */
321
- risk_floor?: string;
322
- }
323
- export interface PolicyDecision {
324
- allowed: boolean;
325
- requiresApproval: boolean;
326
- reason?: string;
327
- budgetRemaining?: {
328
- calls: number;
329
- timeMs: number;
330
- cost: number;
331
- };
332
- /** When quorum is required, contains the quorum metadata. */
333
- quorum?: {
334
- required: number;
335
- approvers: string[];
336
- collected: string[];
337
- };
338
- }
339
- export interface TurnContext {
340
- turnId: string;
341
- runId?: string;
342
- toolCallCount: number;
343
- turnStartMs: number;
344
- costAccumulated: number;
345
- /** Caller motebit ID — set in MCP server mode when caller presents a signed token. */
346
- callerMotebitId?: string;
347
- /** Caller trust level — set in MCP server mode for identity-aware policy decisions. */
348
- callerTrustLevel?: AgentTrustLevel;
349
- /** Type of the remote motebit making the call (personal/service/collaborative). */
350
- remoteMotebitType?: string;
351
- /** Delegation scope — when set, only tools within this scope are allowed. */
352
- delegationScope?: string;
61
+ export interface MemoryQuery {
62
+ motebit_id: string;
63
+ min_confidence?: number;
64
+ sensitivity_filter?: SensitivityLevel[];
65
+ limit?: number;
66
+ include_tombstoned?: boolean;
67
+ pinned?: boolean;
353
68
  }
354
- export interface InjectionWarning {
355
- detected: boolean;
356
- patterns: string[];
357
- directiveDensity?: number;
358
- structuralFlags?: string[];
69
+ export interface MemoryStorageAdapter {
70
+ saveNode(node: MemoryNode): Promise<void>;
71
+ getNode(nodeId: string): Promise<MemoryNode | null>;
72
+ queryNodes(query: MemoryQuery): Promise<MemoryNode[]>;
73
+ saveEdge(edge: MemoryEdge): Promise<void>;
74
+ getEdges(nodeId: string): Promise<MemoryEdge[]>;
75
+ tombstoneNode(nodeId: string): Promise<void>;
76
+ /** Tombstone with ownership check. Returns true if the node existed and belonged to motebitId. */
77
+ tombstoneNodeOwned?(nodeId: string, motebitId: string): Promise<boolean>;
78
+ pinNode(nodeId: string, pinned: boolean): Promise<void>;
79
+ getAllNodes(motebitId: string): Promise<MemoryNode[]>;
80
+ getAllEdges(motebitId: string): Promise<MemoryEdge[]>;
359
81
  }
360
- export interface ToolAuditEntry {
361
- turnId: string;
362
- runId?: string;
363
- callId: string;
364
- tool: string;
365
- args: Record<string, unknown>;
366
- decision: PolicyDecision;
367
- result?: {
368
- ok: boolean;
369
- durationMs: number;
370
- };
371
- injection?: InjectionWarning;
372
- costUnits?: number;
373
- timestamp: number;
82
+ export interface RenderSpec {
83
+ geometry: GeometrySpec;
84
+ material: MaterialSpec;
85
+ lighting: LightingSpec;
374
86
  }
375
- export interface ToolDefinition {
376
- name: string;
377
- description: string;
378
- inputSchema: Record<string, unknown>;
379
- requiresApproval?: boolean;
380
- /** Risk hint for PolicyGate classification. If absent, inferred from name/description. */
381
- riskHint?: {
382
- risk?: RiskLevel;
383
- dataClass?: DataClass;
384
- sideEffect?: SideEffect;
385
- };
87
+ export interface GeometrySpec {
88
+ form: "droplet";
89
+ base_radius: number;
90
+ height: number;
386
91
  }
387
- export interface ToolResult {
388
- ok: boolean;
389
- data?: unknown;
390
- error?: string;
391
- /** Set by adapters that already applied boundary wrapping (e.g. MCP client). */
392
- _sanitized?: boolean;
92
+ export interface MaterialSpec {
93
+ ior: number;
94
+ subsurface: number;
95
+ roughness: number;
96
+ clearcoat: number;
97
+ surface_noise_amplitude: number;
98
+ base_color: [number, number, number];
99
+ emissive_intensity: number;
100
+ tint: [number, number, number];
393
101
  }
394
- export type ToolHandler = (args: Record<string, unknown>) => Promise<ToolResult>;
395
- export interface ToolRegistry {
396
- list(): ToolDefinition[];
397
- execute(name: string, args: Record<string, unknown>): Promise<ToolResult>;
398
- register(tool: ToolDefinition, handler: ToolHandler): void;
399
- /** Replace the handler for an existing tool, or register if new. */
400
- replace?(tool: ToolDefinition, handler: ToolHandler): void;
401
- /** Remove a tool from the registry. Returns true if it existed. */
402
- unregister?(name: string): boolean;
102
+ export interface LightingSpec {
103
+ environment: "hdri";
104
+ exposure: number;
105
+ ambient_intensity: number;
403
106
  }
404
107
  export interface ContextPack {
405
108
  recent_events: EventLogEntry[];
@@ -464,15 +167,6 @@ export interface IntelligenceProvider {
464
167
  estimateConfidence(): Promise<number>;
465
168
  extractMemoryCandidates(response: AIResponse): Promise<MemoryCandidate[]>;
466
169
  }
467
- export interface AuditRecord {
468
- audit_id: string;
469
- motebit_id: MotebitId;
470
- timestamp: number;
471
- action: string;
472
- target_type: string;
473
- target_id: string;
474
- details: Record<string, unknown>;
475
- }
476
170
  export interface ExportManifest {
477
171
  motebit_id: MotebitId;
478
172
  exported_at: number;
@@ -482,453 +176,6 @@ export interface ExportManifest {
482
176
  events: EventLogEntry[];
483
177
  audit_log: AuditRecord[];
484
178
  }
485
- export interface SyncCursor {
486
- motebit_id: MotebitId;
487
- last_event_id: EventId;
488
- last_version_clock: number;
489
- }
490
- export interface ConflictEdge {
491
- local_event: EventLogEntry;
492
- remote_event: EventLogEntry;
493
- resolution: "local_wins" | "remote_wins" | "merged" | "unresolved";
494
- }
495
- /** Conversation metadata for sync. Matches persistence Conversation shape using snake_case for wire format. */
496
- export interface SyncConversation {
497
- conversation_id: ConversationId;
498
- motebit_id: MotebitId;
499
- started_at: number;
500
- last_active_at: number;
501
- title: string | null;
502
- summary: string | null;
503
- message_count: number;
504
- }
505
- /** Conversation message for sync. Matches persistence ConversationMessage shape using snake_case for wire format. */
506
- export interface SyncConversationMessage {
507
- message_id: string;
508
- conversation_id: ConversationId;
509
- motebit_id: MotebitId;
510
- role: string;
511
- content: string;
512
- tool_calls: string | null;
513
- tool_call_id: string | null;
514
- created_at: number;
515
- token_estimate: number;
516
- }
517
- /** Result of a conversation sync cycle. */
518
- export interface ConversationSyncResult {
519
- conversations_pushed: number;
520
- conversations_pulled: number;
521
- messages_pushed: number;
522
- messages_pulled: number;
523
- }
524
- export interface RenderSpec {
525
- geometry: GeometrySpec;
526
- material: MaterialSpec;
527
- lighting: LightingSpec;
528
- }
529
- export interface GeometrySpec {
530
- form: "droplet";
531
- base_radius: number;
532
- height: number;
533
- }
534
- export interface MaterialSpec {
535
- ior: number;
536
- subsurface: number;
537
- roughness: number;
538
- clearcoat: number;
539
- surface_noise_amplitude: number;
540
- base_color: [number, number, number];
541
- emissive_intensity: number;
542
- tint: [number, number, number];
543
- }
544
- export interface LightingSpec {
545
- environment: "hdri";
546
- exposure: number;
547
- ambient_intensity: number;
548
- }
549
- export declare enum PlanStatus {
550
- Active = "active",
551
- Completed = "completed",
552
- Failed = "failed",
553
- Paused = "paused"
554
- }
555
- export declare enum StepStatus {
556
- Pending = "pending",
557
- Running = "running",
558
- Completed = "completed",
559
- Failed = "failed",
560
- Skipped = "skipped"
561
- }
562
- export interface PlanStep {
563
- step_id: string;
564
- plan_id: PlanId;
565
- ordinal: number;
566
- description: string;
567
- prompt: string;
568
- depends_on: string[];
569
- optional: boolean;
570
- status: StepStatus;
571
- required_capabilities?: DeviceCapability[];
572
- /** Task ID assigned by the relay when this step was delegated to a remote device. */
573
- delegation_task_id?: string;
574
- /** Motebit ID of the agent assigned to execute this step in collaborative plans. */
575
- assigned_motebit_id?: MotebitId;
576
- result_summary: string | null;
577
- error_message: string | null;
578
- tool_calls_made: number;
579
- started_at: number | null;
580
- completed_at: number | null;
581
- retry_count: number;
582
- updated_at: number;
583
- }
584
- export interface Plan {
585
- plan_id: PlanId;
586
- goal_id: GoalId;
587
- motebit_id: MotebitId;
588
- title: string;
589
- status: PlanStatus;
590
- created_at: number;
591
- updated_at: number;
592
- current_step_index: number;
593
- total_steps: number;
594
- proposal_id?: ProposalId;
595
- collaborative?: boolean;
596
- }
597
- /** Plan record for cross-device sync. Mirrors Plan but uses wire-format field names. */
598
- export interface SyncPlan {
599
- plan_id: PlanId;
600
- goal_id: GoalId;
601
- motebit_id: MotebitId;
602
- title: string;
603
- status: PlanStatus;
604
- created_at: number;
605
- updated_at: number;
606
- current_step_index: number;
607
- total_steps: number;
608
- proposal_id: string | null;
609
- collaborative: number;
610
- }
611
- /** Plan step record for cross-device sync. */
612
- export interface SyncPlanStep {
613
- step_id: string;
614
- plan_id: PlanId;
615
- motebit_id: MotebitId;
616
- ordinal: number;
617
- description: string;
618
- prompt: string;
619
- depends_on: string;
620
- optional: boolean;
621
- status: StepStatus;
622
- required_capabilities: string | null;
623
- delegation_task_id: string | null;
624
- assigned_motebit_id: string | null;
625
- result_summary: string | null;
626
- error_message: string | null;
627
- tool_calls_made: number;
628
- started_at: number | null;
629
- completed_at: number | null;
630
- retry_count: number;
631
- updated_at: number;
632
- }
633
- /** Result of a plan sync cycle. */
634
- export interface PlanSyncResult {
635
- plans_pushed: number;
636
- plans_pulled: number;
637
- steps_pushed: number;
638
- steps_pulled: number;
639
- }
640
- export declare enum DeviceCapability {
641
- StdioMcp = "stdio_mcp",
642
- HttpMcp = "http_mcp",
643
- FileSystem = "file_system",
644
- Keyring = "keyring",
645
- Background = "background",
646
- LocalLlm = "local_llm"
647
- }
648
- export declare enum AgentTaskStatus {
649
- Pending = "pending",
650
- Claimed = "claimed",
651
- Running = "running",
652
- Completed = "completed",
653
- Failed = "failed",
654
- Denied = "denied",
655
- Expired = "expired"
656
- }
657
- export interface AgentTask {
658
- task_id: string;
659
- motebit_id: MotebitId;
660
- prompt: string;
661
- submitted_at: number;
662
- submitted_by?: string;
663
- wall_clock_ms?: number;
664
- status: AgentTaskStatus;
665
- claimed_by?: string;
666
- required_capabilities?: DeviceCapability[];
667
- step_id?: string;
668
- /** Delegation scope — when set, restricts which tools the task can use. */
669
- delegated_scope?: string;
670
- }
671
- export interface ExecutionReceipt {
672
- task_id: string;
673
- motebit_id: MotebitId;
674
- /** Signer's Ed25519 public key (hex). Enables verification without relay lookup. */
675
- public_key?: string;
676
- device_id: DeviceId;
677
- submitted_at: number;
678
- completed_at: number;
679
- status: "completed" | "failed" | "denied";
680
- result: string;
681
- tools_used: string[];
682
- memories_formed: number;
683
- prompt_hash: string;
684
- result_hash: string;
685
- delegation_receipts?: ExecutionReceipt[];
686
- /** Cryptographic binding to the relay's economic identity for this task. */
687
- relay_task_id?: string;
688
- /** Scope from the delegation token that authorized this execution, if any. */
689
- delegated_scope?: string;
690
- signature: string;
691
- }
692
- export interface DelegatedStepResult {
693
- step_id: string;
694
- task_id: string;
695
- receipt: ExecutionReceipt;
696
- result_text: string;
697
- /** Routing provenance from the relay — why this agent was selected. */
698
- routing_choice?: {
699
- selected_agent: string;
700
- composite_score: number;
701
- sub_scores: Record<string, number>;
702
- routing_paths: string[][];
703
- alternatives_considered: number;
704
- };
705
- }
706
- /**
707
- * A key succession record proving that one Ed25519 key has been replaced by another.
708
- * Both the old and new keys sign the record, creating a cryptographic chain of custody.
709
- * Structurally compatible with @motebit/crypto KeySuccessionRecord.
710
- */
711
- export interface KeySuccessionRecord {
712
- old_public_key: string;
713
- new_public_key: string;
714
- timestamp: number;
715
- reason?: string;
716
- old_key_signature: string;
717
- new_key_signature: string;
718
- }
719
- /** Result of verifying a key succession chain. */
720
- export interface SuccessionChainResult {
721
- valid: boolean;
722
- /** The original (genesis) public key. */
723
- genesis_public_key: string;
724
- /** The current (active) public key. */
725
- current_public_key: string;
726
- /** Number of key rotations. */
727
- length: number;
728
- /** If invalid, the index of the first broken link and error. */
729
- error?: {
730
- index: number;
731
- message: string;
732
- };
733
- }
734
- export type ExecutionTimelineType = "goal_started" | "plan_created" | "step_started" | "tool_invoked" | "tool_result" | "step_completed" | "step_failed" | "step_delegated" | "plan_completed" | "plan_failed" | "goal_completed" | "proposal_created" | "proposal_accepted" | "proposal_rejected" | "proposal_countered" | "collaborative_step_completed";
735
- export interface ExecutionTimelineEntry {
736
- timestamp: number;
737
- type: ExecutionTimelineType;
738
- payload: Record<string, unknown>;
739
- }
740
- export interface ExecutionStepSummary {
741
- step_id: string;
742
- ordinal: number;
743
- description: string;
744
- status: string;
745
- tools_used: string[];
746
- tool_calls: number;
747
- started_at: number | null;
748
- completed_at: number | null;
749
- delegation?: {
750
- task_id: string;
751
- receipt_hash?: string;
752
- /** Routing provenance: why this agent was selected for delegation. */
753
- routing_choice?: {
754
- selected_agent: string;
755
- composite_score: number;
756
- sub_scores: {
757
- trust: number;
758
- success_rate: number;
759
- latency: number;
760
- price_efficiency: number;
761
- capability_match: number;
762
- availability: number;
763
- };
764
- /** Derivation paths through the agent graph. */
765
- routing_paths: string[][];
766
- /** Number of candidate agents that were scored. */
767
- alternatives_considered: number;
768
- };
769
- };
770
- }
771
- export interface GoalExecutionManifest {
772
- spec: "motebit/execution-ledger@1.0";
773
- motebit_id: string;
774
- goal_id: string;
775
- plan_id: string;
776
- started_at: number;
777
- completed_at: number;
778
- status: "completed" | "failed" | "paused" | "active";
779
- timeline: ExecutionTimelineEntry[];
780
- steps: ExecutionStepSummary[];
781
- delegation_receipts: DelegationReceiptSummary[];
782
- content_hash: string;
783
- signature?: string;
784
- }
785
- export interface DelegationReceiptSummary {
786
- task_id: string;
787
- motebit_id: string;
788
- device_id: string;
789
- status: string;
790
- completed_at: number;
791
- tools_used: string[];
792
- signature_prefix: string;
793
- }
794
- export interface AgentCapabilities {
795
- motebit_id: MotebitId;
796
- public_key: string;
797
- /** W3C did:key URI derived from the Ed25519 public key. */
798
- did?: string;
799
- tools: string[];
800
- governance: {
801
- trust_mode: string;
802
- max_risk_auto: number;
803
- require_approval_above: number;
804
- deny_above: number;
805
- };
806
- online_devices: number;
807
- }
808
- export interface CapabilityPrice {
809
- capability: string;
810
- unit_cost: number;
811
- currency: string;
812
- per: "task" | "tool_call" | "token";
813
- }
814
- export interface AgentServiceListing {
815
- listing_id: ListingId;
816
- motebit_id: MotebitId;
817
- capabilities: string[];
818
- pricing: CapabilityPrice[];
819
- sla: {
820
- max_latency_ms: number;
821
- availability_guarantee: number;
822
- };
823
- description: string;
824
- /** Wallet address for x402 on-chain payment settlement (e.g. "0x..." for EVM). */
825
- pay_to_address?: string;
826
- /**
827
- * Self-declared regulatory risk score [0, ∞). 0 = no risk, higher = more risk.
828
- * Accumulates along delegation chains via RegulatoryRiskSemiring (min, +).
829
- * Sources: jurisdiction, data handling classification, compliance certifications,
830
- * audit requirements. The score is declared by the agent; verification is via
831
- * credentials (e.g. compliance attestation VCs).
832
- */
833
- regulatory_risk?: number;
834
- updated_at: number;
835
- }
836
- export interface RouteScore {
837
- motebit_id: MotebitId;
838
- composite: number;
839
- sub_scores: {
840
- trust: number;
841
- success_rate: number;
842
- latency: number;
843
- price_efficiency: number;
844
- capability_match: number;
845
- availability: number;
846
- };
847
- selected: boolean;
848
- }
849
- export interface BudgetAllocation {
850
- allocation_id: AllocationId;
851
- goal_id: GoalId;
852
- candidate_motebit_id: MotebitId;
853
- amount_locked: number;
854
- currency: string;
855
- created_at: number;
856
- status: "locked" | "settled" | "released" | "disputed";
857
- }
858
- /**
859
- * The relay's settlement fee rate (5%).
860
- * Applied to every completed or partial settlement that flows through the relay.
861
- * This is the Stripe model: the relay proves the work happened, takes its cut.
862
- */
863
- export declare const PLATFORM_FEE_RATE = 0.05;
864
- export interface SettlementRecord {
865
- settlement_id: SettlementId;
866
- allocation_id: AllocationId;
867
- receipt_hash: string;
868
- ledger_hash: string | null;
869
- /** Amount paid to the executing agent (after platform fee deduction). */
870
- amount_settled: number;
871
- /** Platform fee extracted by the relay. */
872
- platform_fee: number;
873
- /** Fee rate applied (e.g. 0.05 = 5%). Recorded per-settlement for auditability. */
874
- platform_fee_rate: number;
875
- /** x402 payment transaction hash (when paid on-chain). */
876
- x402_tx_hash?: string;
877
- /** x402 network used for payment (CAIP-2 identifier). */
878
- x402_network?: string;
879
- status: "completed" | "partial" | "refunded";
880
- settled_at: number;
881
- }
882
- export interface CollaborativePlanProposal {
883
- proposal_id: ProposalId;
884
- plan_id: PlanId;
885
- initiator_motebit_id: MotebitId;
886
- participants: ProposalParticipant[];
887
- status: ProposalStatus;
888
- created_at: number;
889
- expires_at: number;
890
- updated_at: number;
891
- }
892
- export interface ProposalParticipant {
893
- motebit_id: MotebitId;
894
- assigned_steps: number[];
895
- response: ProposalResponseType | null;
896
- responded_at: number | null;
897
- counter_steps?: ProposalStepCounter[];
898
- }
899
- export interface ProposalStepCounter {
900
- ordinal: number;
901
- description?: string;
902
- prompt?: string;
903
- reason: string;
904
- }
905
- export interface ProposalResponse {
906
- proposal_id: ProposalId;
907
- responder_motebit_id: MotebitId;
908
- response: ProposalResponseType;
909
- counter_steps?: ProposalStepCounter[];
910
- signature: string;
911
- }
912
- export interface CollaborativeReceipt {
913
- proposal_id: ProposalId;
914
- plan_id: PlanId;
915
- participant_receipts: ExecutionReceipt[];
916
- content_hash: string;
917
- initiator_signature: string;
918
- }
919
- export interface MarketConfig {
920
- weight_trust: number;
921
- weight_success_rate: number;
922
- weight_latency: number;
923
- weight_price_efficiency: number;
924
- weight_capability_match: number;
925
- weight_availability: number;
926
- latency_norm_k: number;
927
- max_candidates: number;
928
- settlement_timeout_ms: number;
929
- /** Exploration weight [0-1]: 0 = pure exploitation, 1 = pure exploration. Default 0. */
930
- exploration_weight?: number;
931
- }
932
179
  /**
933
180
  * Precision weights derived from the intelligence gradient.
934
181
  *
@@ -940,41 +187,6 @@ export interface MarketConfig {
940
187
  * High gradient → high self-trust → exploit known-good routes, trust memory.
941
188
  * Low gradient → low self-trust → explore, diversify, question memory.
942
189
  */
943
- export declare const VC_TYPE_GRADIENT = "AgentGradientCredential";
944
- export declare const VC_TYPE_REPUTATION = "AgentReputationCredential";
945
- export declare const VC_TYPE_TRUST = "AgentTrustCredential";
946
- export interface GradientCredentialSubject {
947
- id: string;
948
- gradient: number;
949
- knowledge_density: number;
950
- knowledge_quality: number;
951
- graph_connectivity: number;
952
- temporal_stability: number;
953
- retrieval_quality: number;
954
- interaction_efficiency: number;
955
- tool_efficiency: number;
956
- curiosity_pressure: number;
957
- measured_at: number;
958
- }
959
- export interface ReputationCredentialSubject {
960
- id: string;
961
- success_rate: number;
962
- avg_latency_ms: number;
963
- task_count: number;
964
- trust_score: number;
965
- availability: number;
966
- sample_size: number;
967
- measured_at: number;
968
- }
969
- export interface TrustCredentialSubject {
970
- id: string;
971
- trust_level: string;
972
- interaction_count: number;
973
- successful_tasks: number;
974
- failed_tasks: number;
975
- first_seen_at: number;
976
- last_seen_at: number;
977
- }
978
190
  export interface PrecisionWeights {
979
191
  /** Overall self-trust [0-1]. Sigmoid of composite gradient. */
980
192
  selfTrust: number;
@@ -985,84 +197,6 @@ export interface PrecisionWeights {
985
197
  /** Curiosity modulation [0-1]. Fed back into state vector curiosity field. */
986
198
  curiosityModulation: number;
987
199
  }
988
- export interface ConversationStoreAdapter {
989
- createConversation(motebitId: string): string;
990
- appendMessage(conversationId: string, motebitId: string, msg: {
991
- role: string;
992
- content: string;
993
- toolCalls?: string;
994
- toolCallId?: string;
995
- }): void;
996
- loadMessages(conversationId: string, limit?: number): Array<{
997
- messageId: string;
998
- conversationId: string;
999
- motebitId: string;
1000
- role: string;
1001
- content: string;
1002
- toolCalls: string | null;
1003
- toolCallId: string | null;
1004
- createdAt: number;
1005
- tokenEstimate: number;
1006
- }>;
1007
- getActiveConversation(motebitId: string): {
1008
- conversationId: string;
1009
- startedAt: number;
1010
- lastActiveAt: number;
1011
- summary: string | null;
1012
- } | null;
1013
- updateSummary(conversationId: string, summary: string): void;
1014
- updateTitle(conversationId: string, title: string): void;
1015
- listConversations(motebitId: string, limit?: number): Array<{
1016
- conversationId: string;
1017
- startedAt: number;
1018
- lastActiveAt: number;
1019
- title: string | null;
1020
- messageCount: number;
1021
- }>;
1022
- deleteConversation(conversationId: string): void;
1023
- }
1024
- export interface StateSnapshotAdapter {
1025
- saveState(motebitId: string, stateJson: string, versionClock?: number): void;
1026
- loadState(motebitId: string): string | null;
1027
- /** Version clock at last snapshot — used to determine what's safe to compact. */
1028
- getSnapshotClock?(motebitId: string): number;
1029
- }
1030
- export interface KeyringAdapter {
1031
- get(key: string): Promise<string | null>;
1032
- set(key: string, value: string): Promise<void>;
1033
- delete(key: string): Promise<void>;
1034
- }
1035
- export interface AgentTrustStoreAdapter {
1036
- getAgentTrust(motebitId: string, remoteMotebitId: string): Promise<AgentTrustRecord | null>;
1037
- setAgentTrust(record: AgentTrustRecord): Promise<void>;
1038
- listAgentTrust(motebitId: string): Promise<AgentTrustRecord[]>;
1039
- updateTrustLevel(motebitId: string, remoteMotebitId: string, level: AgentTrustLevel): Promise<void>;
1040
- }
1041
- export interface ServiceListingStoreAdapter {
1042
- get(motebitId: string): Promise<AgentServiceListing | null>;
1043
- set(listing: AgentServiceListing): Promise<void>;
1044
- list(): Promise<AgentServiceListing[]>;
1045
- delete(listingId: string): Promise<void>;
1046
- }
1047
- export interface BudgetAllocationStoreAdapter {
1048
- get(allocationId: string): Promise<BudgetAllocation | null>;
1049
- create(allocation: BudgetAllocation): Promise<void>;
1050
- updateStatus(allocationId: string, status: string): Promise<void>;
1051
- listByGoal(goalId: string): Promise<BudgetAllocation[]>;
1052
- }
1053
- export interface SettlementStoreAdapter {
1054
- get(settlementId: string): Promise<SettlementRecord | null>;
1055
- create(settlement: SettlementRecord): Promise<void>;
1056
- listByAllocation(allocationId: string): Promise<SettlementRecord[]>;
1057
- }
1058
- export interface LatencyStatsStoreAdapter {
1059
- record(motebitId: string, remoteMotebitId: string, latencyMs: number): Promise<void>;
1060
- getStats(motebitId: string, remoteMotebitId: string, limit?: number): Promise<{
1061
- avg_ms: number;
1062
- p95_ms: number;
1063
- sample_count: number;
1064
- }>;
1065
- }
1066
200
  export interface GradientSnapshot {
1067
201
  motebit_id: string;
1068
202
  timestamp: number;
@@ -1107,132 +241,6 @@ export interface GradientStoreAdapter {
1107
241
  latest(motebitId: string): GradientSnapshot | null;
1108
242
  list(motebitId: string, limit?: number): GradientSnapshot[];
1109
243
  }
1110
- export interface EventFilter {
1111
- motebit_id?: string;
1112
- event_types?: EventType[];
1113
- after_timestamp?: number;
1114
- before_timestamp?: number;
1115
- after_version_clock?: number;
1116
- limit?: number;
1117
- }
1118
- export interface EventStoreAdapter {
1119
- append(entry: EventLogEntry): Promise<void>;
1120
- /**
1121
- * Atomically assign the next version_clock and append the event.
1122
- * Eliminates the race condition in the getLatestClock() + clock+1 pattern.
1123
- * Returns the assigned version_clock.
1124
- */
1125
- appendWithClock?(entry: Omit<EventLogEntry, "version_clock">): Promise<number>;
1126
- query(filter: EventFilter): Promise<EventLogEntry[]>;
1127
- getLatestClock(motebitId: string): Promise<number>;
1128
- tombstone(eventId: string, motebitId: string): Promise<void>;
1129
- /** Delete events with version_clock <= beforeClock. Returns count deleted. */
1130
- compact?(motebitId: string, beforeClock: number): Promise<number>;
1131
- /** Count total events for a motebit. */
1132
- countEvents?(motebitId: string): Promise<number>;
1133
- }
1134
- export interface MemoryQuery {
1135
- motebit_id: string;
1136
- min_confidence?: number;
1137
- sensitivity_filter?: SensitivityLevel[];
1138
- limit?: number;
1139
- include_tombstoned?: boolean;
1140
- pinned?: boolean;
1141
- }
1142
- export interface MemoryStorageAdapter {
1143
- saveNode(node: MemoryNode): Promise<void>;
1144
- getNode(nodeId: string): Promise<MemoryNode | null>;
1145
- queryNodes(query: MemoryQuery): Promise<MemoryNode[]>;
1146
- saveEdge(edge: MemoryEdge): Promise<void>;
1147
- getEdges(nodeId: string): Promise<MemoryEdge[]>;
1148
- tombstoneNode(nodeId: string): Promise<void>;
1149
- /** Tombstone with ownership check. Returns true if the node existed and belonged to motebitId. */
1150
- tombstoneNodeOwned?(nodeId: string, motebitId: string): Promise<boolean>;
1151
- pinNode(nodeId: string, pinned: boolean): Promise<void>;
1152
- getAllNodes(motebitId: string): Promise<MemoryNode[]>;
1153
- getAllEdges(motebitId: string): Promise<MemoryEdge[]>;
1154
- }
1155
- export interface DeviceRegistration {
1156
- device_id: string;
1157
- motebit_id: string;
1158
- device_token: string;
1159
- public_key: string;
1160
- registered_at: number;
1161
- device_name?: string;
1162
- }
1163
- export interface IdentityStorage {
1164
- save(identity: MotebitIdentity): Promise<void>;
1165
- load(motebitId: string): Promise<MotebitIdentity | null>;
1166
- loadByOwner(ownerId: string): Promise<MotebitIdentity | null>;
1167
- saveDevice?(device: DeviceRegistration): Promise<void>;
1168
- loadDevice?(deviceId: string): Promise<DeviceRegistration | null>;
1169
- loadDeviceByToken?(token: string): Promise<DeviceRegistration | null>;
1170
- listDevices?(motebitId: string): Promise<DeviceRegistration[]>;
1171
- }
1172
- export interface AuditLogAdapter {
1173
- record(entry: AuditRecord): Promise<void>;
1174
- query(motebitId: string, options?: {
1175
- limit?: number;
1176
- after?: number;
1177
- }): Promise<AuditRecord[]>;
1178
- }
1179
- export interface AuditStatsSince {
1180
- distinctTurns: number;
1181
- totalToolCalls: number;
1182
- succeeded: number;
1183
- blocked: number;
1184
- failed: number;
1185
- }
1186
- export interface AuditLogSink {
1187
- append(entry: ToolAuditEntry): void;
1188
- query(turnId: string): ToolAuditEntry[];
1189
- getAll(): ToolAuditEntry[];
1190
- queryStatsSince(afterTimestamp: number): AuditStatsSince;
1191
- /** Query tool audit entries by run_id (plan execution). Optional — returns [] if not implemented. */
1192
- queryByRunId?(runId: string): ToolAuditEntry[];
1193
- }
1194
- export interface PlanStoreAdapter {
1195
- savePlan(plan: Plan): void;
1196
- getPlan(planId: string): Plan | null;
1197
- getPlanForGoal(goalId: string): Plan | null;
1198
- updatePlan(planId: string, updates: Partial<Plan>): void;
1199
- saveStep(step: PlanStep): void;
1200
- getStep(stepId: string): PlanStep | null;
1201
- getStepsForPlan(planId: string): PlanStep[];
1202
- updateStep(stepId: string, updates: Partial<PlanStep>): void;
1203
- getNextPendingStep(planId: string): PlanStep | null;
1204
- /** List all active plans for a motebit. Optional — returns [] if not implemented. */
1205
- listActivePlans?(motebitId: string): Plan[];
1206
- }
1207
- /** Stored credential record — JSON-serialized VC with metadata. */
1208
- export interface StoredCredential {
1209
- credential_id: string;
1210
- /** The agent the credential is about (credentialSubject.id). */
1211
- subject_motebit_id: string;
1212
- /** did:key of the issuer. */
1213
- issuer_did: string;
1214
- /** e.g. "AgentReputationCredential", "AgentTrustCredential", "AgentGradientCredential". */
1215
- credential_type: string;
1216
- /** Full JSON-serialized VerifiableCredential. */
1217
- credential_json: string;
1218
- issued_at: number;
1219
- }
1220
- export interface CredentialStoreAdapter {
1221
- save(credential: StoredCredential): void;
1222
- /** List credentials about a specific subject agent. */
1223
- listBySubject(subjectMotebitId: string, limit?: number): StoredCredential[];
1224
- /** List all credentials, optionally filtered by type. */
1225
- list(motebitId: string, type?: string, limit?: number): StoredCredential[];
1226
- }
1227
- export interface ApprovalStoreAdapter {
1228
- /** Collect a quorum approval vote. Returns whether threshold is met and collected voter IDs. */
1229
- collectApproval(approvalId: string, approverId: string): {
1230
- met: boolean;
1231
- collected: string[];
1232
- };
1233
- /** Set quorum metadata on a pending approval item. */
1234
- setQuorum(approvalId: string, required: number, approvers: string[]): void;
1235
- }
1236
244
  export interface StorageAdapters {
1237
245
  eventStore: EventStoreAdapter;
1238
246
  memoryStorage: MemoryStorageAdapter;
@@ -1251,5 +259,4 @@ export interface StorageAdapters {
1251
259
  credentialStore?: CredentialStoreAdapter;
1252
260
  approvalStore?: ApprovalStoreAdapter;
1253
261
  }
1254
- export {};
1255
262
  //# sourceMappingURL=index.d.ts.map