@clude/sdk 3.2.0 → 3.3.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.
@@ -0,0 +1,120 @@
1
+ /**
2
+ * CLUDE Cortex v2 — The Integration Layer
3
+ *
4
+ * Extends the existing Cortex SDK with:
5
+ * - Cognitive model router (right model for the right task)
6
+ * - Memory Packs (portable memory bundles for cross-agent sharing)
7
+ * - Multi-backend support (local SQLite → Supabase → custom)
8
+ * - Privacy controls (private inference, selective sharing)
9
+ * - Token metering hooks ($CLUDE gas tracking)
10
+ *
11
+ * The 5 P's: Private, Portable, Permissionless, Poly-model, Persistent
12
+ */
13
+ import { Cortex } from './cortex';
14
+ import type { CortexConfig, MemoryType } from './types';
15
+ export type CognitiveFunction = 'embed' | 'recall' | 'store' | 'consolidate' | 'reflect' | 'emerge' | 'classify' | 'summarize' | 'search';
16
+ export interface ModelRoute {
17
+ provider: string;
18
+ model: string;
19
+ maxTokens?: number;
20
+ temperature?: number;
21
+ }
22
+ export interface RouterConfig {
23
+ routes: Partial<Record<CognitiveFunction, ModelRoute>>;
24
+ fallback: ModelRoute;
25
+ }
26
+ export interface MemoryPack {
27
+ id: string;
28
+ name: string;
29
+ description: string;
30
+ memories: PackedMemory[];
31
+ created_at: string;
32
+ created_by: string;
33
+ signature?: string;
34
+ format_version: number;
35
+ }
36
+ export interface PackedMemory {
37
+ content: string;
38
+ summary: string;
39
+ type: MemoryType;
40
+ importance: number;
41
+ tags: string[];
42
+ concepts: string[];
43
+ created_at: string;
44
+ }
45
+ export type PrivacyLevel = 'private' | 'shared' | 'public';
46
+ export interface PrivacyPolicy {
47
+ /** Default privacy for new memories */
48
+ default: PrivacyLevel;
49
+ /** Types that are always private regardless of default */
50
+ alwaysPrivate: MemoryType[];
51
+ /** Whether to use private inference for all LLM calls */
52
+ privateInference: boolean;
53
+ /** Whether to encrypt memories at rest */
54
+ encryptAtRest: boolean;
55
+ }
56
+ export interface MeteringEvent {
57
+ operation: 'store' | 'recall' | 'dream' | 'export' | 'import';
58
+ tokens_used: number;
59
+ memory_count: number;
60
+ timestamp: string;
61
+ }
62
+ export type MeteringHandler = (event: MeteringEvent) => void | Promise<void>;
63
+ export interface CortexV2Config extends CortexConfig {
64
+ /** Cognitive model router configuration */
65
+ router?: Partial<RouterConfig>;
66
+ /** Privacy policy */
67
+ privacy?: Partial<PrivacyPolicy>;
68
+ /** Token metering callback (for $CLUDE gas tracking) */
69
+ onMeter?: MeteringHandler;
70
+ }
71
+ export declare class CortexV2 extends Cortex {
72
+ private router;
73
+ private privacy;
74
+ private onMeter;
75
+ private meterLog;
76
+ constructor(config: CortexV2Config);
77
+ /** Get the configured model for a cognitive function */
78
+ getRoute(fn: CognitiveFunction): ModelRoute;
79
+ /** Update a route at runtime */
80
+ setRoute(fn: CognitiveFunction, route: ModelRoute): void;
81
+ /** Export selected memories as a portable pack */
82
+ exportPack(opts: {
83
+ name: string;
84
+ description: string;
85
+ memoryIds?: number[];
86
+ types?: MemoryType[];
87
+ query?: string;
88
+ limit?: number;
89
+ }): Promise<MemoryPack>;
90
+ /** Import a memory pack into this agent's memory */
91
+ importPack(pack: MemoryPack, opts?: {
92
+ /** Override importance for imported memories */
93
+ importanceMultiplier?: number;
94
+ /** Prefix for imported memory tags */
95
+ tagPrefix?: string;
96
+ /** Only import specific types */
97
+ types?: MemoryType[];
98
+ }): Promise<{
99
+ imported: number;
100
+ skipped: number;
101
+ }>;
102
+ /** Serialize a pack to JSON string */
103
+ serializePack(pack: MemoryPack): string;
104
+ /** Serialize a pack to Markdown (human-readable) */
105
+ serializePackMarkdown(pack: MemoryPack): string;
106
+ /** Parse a pack from JSON string */
107
+ parsePack(json: string): MemoryPack;
108
+ /** Get current privacy policy */
109
+ getPrivacyPolicy(): PrivacyPolicy;
110
+ /** Update privacy policy */
111
+ setPrivacyPolicy(policy: Partial<PrivacyPolicy>): void;
112
+ /** Get all metering events */
113
+ getMeterLog(): MeteringEvent[];
114
+ /** Get total operations by type */
115
+ getMeterSummary(): Record<string, {
116
+ count: number;
117
+ totalMemories: number;
118
+ }>;
119
+ private meter;
120
+ }
@@ -0,0 +1,63 @@
1
+ import './sdk-mode';
2
+ import type { CortexConfig, DreamOptions, Memory, MemorySummary, MemoryType, StoreMemoryOptions, RecallOptions, MemoryStats } from './types';
3
+ import type { MemoryLinkType } from './shared-constants';
4
+ export declare class Cortex {
5
+ private config;
6
+ private db;
7
+ private http;
8
+ private hostedMode;
9
+ private initialized;
10
+ private dreamActive;
11
+ constructor(config: CortexConfig);
12
+ /** Initialize database schema, encryption, and on-chain registry. Call before store/recall. */
13
+ init(): Promise<void>;
14
+ /** Store a new memory. Returns memory ID or null. */
15
+ store(opts: StoreMemoryOptions): Promise<number | null>;
16
+ /** Recall memories with hybrid vector + keyword + graph scoring. */
17
+ recall(opts?: RecallOptions): Promise<Memory[]>;
18
+ /** Recall lightweight summaries (progressive disclosure). */
19
+ recallSummaries(opts?: RecallOptions): Promise<MemorySummary[]>;
20
+ /** Hydrate full memory content for specific IDs. */
21
+ hydrate(ids: number[]): Promise<Memory[]>;
22
+ /** Apply type-specific memory decay. Self-hosted only. */
23
+ decay(): Promise<number>;
24
+ /** Get memory system statistics. */
25
+ stats(): Promise<MemoryStats>;
26
+ /** Get recent memories from the last N hours. */
27
+ recent(hours: number, types?: MemoryType[], limit?: number): Promise<Memory[]>;
28
+ /** Get current self-model memories. */
29
+ selfModel(): Promise<Memory[]>;
30
+ /** Create a typed link between two memories. */
31
+ link(sourceId: number, targetId: number, type: MemoryLinkType, strength?: number): Promise<void>;
32
+ /** Run one full dream cycle. Self-hosted only — requires anthropic config. */
33
+ dream(opts?: DreamOptions): Promise<void>;
34
+ /** Start cron-based dream schedule. Self-hosted only — requires anthropic config. */
35
+ startDreamSchedule(): void;
36
+ /** Stop the dream schedule. */
37
+ stopDreamSchedule(): void;
38
+ /** Run a single active reflection (meditation) session. Self-hosted only. */
39
+ reflect(opts?: {
40
+ onReflection?: (journal: any) => Promise<void>;
41
+ }): Promise<any>;
42
+ /** Start the active reflection (meditation) schedule. Self-hosted only. */
43
+ startReflectionSchedule(): void;
44
+ /** Stop the active reflection schedule. */
45
+ stopReflectionSchedule(): void;
46
+ /** Score memory importance using LLM. Self-hosted only. */
47
+ scoreImportance(description: string): Promise<number>;
48
+ /** Format memories into context string for LLM prompts. Works in both modes. */
49
+ formatContext(memories: Memory[]): string;
50
+ /** Infer structured concepts from memory content. Works in both modes. */
51
+ inferConcepts(summary: string, source: string, tags: string[]): string[];
52
+ /** Listen for memory events. Self-hosted only. */
53
+ on(event: 'memory:stored', handler: (payload: {
54
+ importance: number;
55
+ memoryType: string;
56
+ }) => void): void;
57
+ /** Verify a memory exists in the on-chain registry by its ID. Self-hosted only. */
58
+ verifyOnChain(memoryId: number): Promise<boolean>;
59
+ /** Clean up resources and stop schedules. */
60
+ destroy(): void;
61
+ private guard;
62
+ private requireSelfHosted;
63
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * HTTP transport for hosted Cortex mode.
3
+ * Wraps fetch calls with Bearer auth and JSON serialization.
4
+ */
5
+ export declare class HttpTransport {
6
+ private baseUrl;
7
+ private apiKey;
8
+ constructor(config: {
9
+ apiKey: string;
10
+ baseUrl?: string;
11
+ });
12
+ post<T>(path: string, body?: Record<string, unknown>): Promise<T>;
13
+ get<T>(path: string, params?: Record<string, string | undefined>): Promise<T>;
14
+ }
@@ -0,0 +1,4 @@
1
+ export { Cortex } from './cortex';
2
+ export { CortexV2 } from './cortex-v2';
3
+ export type { CortexConfig, DreamOptions, MemoryType, Memory, MemorySummary, StoreMemoryOptions, RecallOptions, MemoryStats, MemoryLinkType, MemoryConcept, } from './types';
4
+ export type { CortexV2Config, CognitiveFunction, ModelRoute, RouterConfig, MemoryPack, PackedMemory, PrivacyLevel, PrivacyPolicy, MeteringEvent, MeteringHandler, } from './cortex-v2';