@dakera-ai/dakera 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
6
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue)](https://www.typescriptlang.org/)
7
7
 
8
- Official TypeScript/JavaScript client for [Dakera](https://github.com/dakera/dakera) - a high-performance vector database.
8
+ Official TypeScript/JavaScript client for [Dakera](https://dakera.ai) a high-performance vector database for AI agent memory.
9
9
 
10
10
  ## Installation
11
11
 
@@ -44,10 +44,12 @@ for (const result of results.results) {
44
44
  ## Features
45
45
 
46
46
  - **Full TypeScript Support**: Complete type definitions for all operations
47
+ - **Branded ID Types**: `VectorId`, `AgentId`, `MemoryId`, `SessionId` prevent cross-assignment bugs
47
48
  - **Vector Operations**: Upsert, query, delete, fetch vectors
48
49
  - **Full-Text Search**: Index documents and perform BM25 search
49
50
  - **Hybrid Search**: Combine vector and text search with configurable weights
50
51
  - **Namespace Management**: Create, list, delete namespaces
52
+ - **Agent Memory**: Store, recall, and manage memories for AI agents
51
53
  - **Metadata Filtering**: Filter queries by metadata fields
52
54
  - **Automatic Retries**: Built-in retry logic with exponential backoff
53
55
  - **Error Handling**: Typed exceptions for different error scenarios
@@ -266,6 +268,29 @@ import type {
266
268
  } from 'dakera';
267
269
  ```
268
270
 
271
+ ### Branded ID Types
272
+
273
+ v0.3.0 introduced branded string types to prevent accidental cross-assignment of IDs at compile time:
274
+
275
+ ```typescript
276
+ import {
277
+ vectorId, agentId, memoryId, sessionId,
278
+ type VectorId, type AgentId, type MemoryId, type SessionId,
279
+ } from 'dakera';
280
+
281
+ // Factory helpers narrow plain strings to branded types
282
+ const vid: VectorId = vectorId('vec-001');
283
+ const aid: AgentId = agentId('my-agent');
284
+
285
+ // TypeScript catches cross-assignment mistakes:
286
+ // const bad: VectorId = agentId('x'); // TS error ✓
287
+
288
+ // All SDK methods accept both branded and plain strings for convenience
289
+ await client.upsert('my-namespace', [
290
+ { id: vid, values: [0.1, 0.2, 0.3] },
291
+ ]);
292
+ ```
293
+
269
294
  ## Browser Support
270
295
 
271
296
  This SDK uses the Fetch API and works in:
@@ -306,7 +331,6 @@ npm run lint
306
331
  | [dakera-dashboard](https://github.com/dakera-ai/dakera-dashboard) | Admin dashboard (Leptos/WASM) |
307
332
  | [dakera-docs](https://github.com/dakera-ai/dakera-docs) | Documentation |
308
333
  | [dakera-deploy](https://github.com/dakera-ai/dakera-deploy) | Deployment configs and Docker Compose |
309
- | [dakera-cortex](https://github.com/dakera-ai/dakera-cortex) | Flagship demo with AI agents |
310
334
 
311
335
  ## License
312
336
 
package/dist/index.d.mts CHANGED
@@ -1,6 +1,28 @@
1
1
  /**
2
2
  * Dakera TypeScript SDK Types
3
3
  */
4
+ declare const __brand: unique symbol;
5
+ type Brand<B> = {
6
+ readonly [__brand]: B;
7
+ };
8
+ /** A branded string type — T is the nominal tag that prevents cross-assignment. */
9
+ type Branded<T extends string, B> = T & Brand<B>;
10
+ /** Opaque ID for a stored vector. */
11
+ type VectorId = Branded<string, 'VectorId'>;
12
+ /** Opaque ID for an agent. */
13
+ type AgentId = Branded<string, 'AgentId'>;
14
+ /** Opaque ID for a memory entry. */
15
+ type MemoryId = Branded<string, 'MemoryId'>;
16
+ /** Opaque ID for a session. */
17
+ type SessionId = Branded<string, 'SessionId'>;
18
+ /** Create a VectorId from a plain string. */
19
+ declare function vectorId(id: string): VectorId;
20
+ /** Create an AgentId from a plain string. */
21
+ declare function agentId(id: string): AgentId;
22
+ /** Create a MemoryId from a plain string. */
23
+ declare function memoryId(id: string): MemoryId;
24
+ /** Create a SessionId from a plain string. */
25
+ declare function sessionId(id: string): SessionId;
4
26
  /** Read consistency level for queries */
5
27
  type ReadConsistency = 'strong' | 'eventual' | 'bounded_staleness';
6
28
  /** Distance metric for similarity search */
@@ -58,19 +80,19 @@ interface WarmCacheResponse {
58
80
  }
59
81
  /** Vector with ID, values, and optional metadata */
60
82
  interface Vector {
61
- id: string;
83
+ id: VectorId;
62
84
  values: number[];
63
85
  metadata?: Record<string, unknown>;
64
86
  }
65
87
  /** Input for vector operations - can be Vector object or plain object */
66
88
  type VectorInput = Vector | {
67
- id: string;
89
+ id: VectorId | string;
68
90
  values: number[];
69
91
  metadata?: Record<string, unknown>;
70
92
  };
71
93
  /** Result from a vector query */
72
94
  interface QueryResult {
73
- id: string;
95
+ id: VectorId;
74
96
  score: number;
75
97
  vector?: number[];
76
98
  metadata?: Record<string, unknown>;
@@ -104,25 +126,25 @@ interface IndexStats {
104
126
  }
105
127
  /** Document for full-text search */
106
128
  interface Document {
107
- id: string;
129
+ id: VectorId;
108
130
  content: string;
109
131
  metadata?: Record<string, unknown>;
110
132
  }
111
133
  /** Input for document operations */
112
134
  type DocumentInput = Document | {
113
- id: string;
135
+ id: VectorId | string;
114
136
  content: string;
115
137
  metadata?: Record<string, unknown>;
116
138
  };
117
139
  /** Result from full-text search */
118
140
  interface FullTextSearchResult {
119
- id: string;
141
+ id: VectorId;
120
142
  score: number;
121
143
  metadata?: Record<string, unknown>;
122
144
  }
123
145
  /** Result from hybrid search */
124
146
  interface HybridSearchResult {
125
- id: string;
147
+ id: VectorId;
126
148
  /** Combined score */
127
149
  score: number;
128
150
  /** Vector similarity score (normalized 0-1) */
@@ -277,7 +299,7 @@ interface TextQueryOptions {
277
299
  */
278
300
  interface TextSearchResult {
279
301
  /** Document ID */
280
- id: string;
302
+ id: VectorId;
281
303
  /** Similarity score */
282
304
  score: number;
283
305
  /** Original text (if includeText was true) */
@@ -348,7 +370,7 @@ interface StoreMemoryRequest {
348
370
  /** A stored memory */
349
371
  interface Memory {
350
372
  /** Memory ID */
351
- id: string;
373
+ id: MemoryId;
352
374
  /** Memory content */
353
375
  content: string;
354
376
  /** Memory type */
@@ -367,7 +389,7 @@ interface Memory {
367
389
  /** A recalled memory with similarity score */
368
390
  interface RecalledMemory {
369
391
  /** Memory ID */
370
- id: string;
392
+ id: MemoryId;
371
393
  /** Memory content */
372
394
  content: string;
373
395
  /** Memory type */
@@ -384,7 +406,7 @@ interface RecalledMemory {
384
406
  /** Response from storing a memory */
385
407
  interface StoreMemoryResponse {
386
408
  /** Created memory ID */
387
- memory_id: string;
409
+ memory_id: MemoryId;
388
410
  /** Status */
389
411
  status: string;
390
412
  }
@@ -411,7 +433,7 @@ interface RecallRequest {
411
433
  /** Request to update importance */
412
434
  interface UpdateImportanceRequest {
413
435
  /** Memory IDs to update */
414
- memory_ids: string[];
436
+ memory_ids: MemoryId[];
415
437
  /** New importance value */
416
438
  importance: number;
417
439
  }
@@ -431,12 +453,12 @@ interface ConsolidateResponse {
431
453
  /** Number of memories removed */
432
454
  removed_count: number;
433
455
  /** IDs of new consolidated memories */
434
- new_memories: string[];
456
+ new_memories: MemoryId[];
435
457
  }
436
458
  /** Request for memory feedback */
437
459
  interface MemoryFeedbackRequest {
438
460
  /** Memory ID */
439
- memory_id: string;
461
+ memory_id: MemoryId;
440
462
  /** Feedback text */
441
463
  feedback: string;
442
464
  /** Optional relevance score */
@@ -452,16 +474,16 @@ interface MemoryFeedbackResponse {
452
474
  /** Request to start a session */
453
475
  interface StartSessionRequest {
454
476
  /** Agent ID */
455
- agent_id: string;
477
+ agent_id: AgentId;
456
478
  /** Optional session metadata */
457
479
  metadata?: Record<string, unknown>;
458
480
  }
459
481
  /** A session */
460
482
  interface Session {
461
483
  /** Session ID */
462
- session_id: string;
484
+ session_id: SessionId;
463
485
  /** Agent ID */
464
- agent_id: string;
486
+ agent_id: AgentId;
465
487
  /** Start timestamp */
466
488
  started_at?: string;
467
489
  /** End timestamp */
@@ -483,7 +505,7 @@ interface ListSessionsOptions {
483
505
  /** Summary info for an agent */
484
506
  interface AgentSummary {
485
507
  /** Agent ID */
486
- agent_id: string;
508
+ agent_id: AgentId;
487
509
  /** Total memory count */
488
510
  memory_count: number;
489
511
  /** Total session count */
@@ -494,7 +516,7 @@ interface AgentSummary {
494
516
  /** Detailed stats for an agent */
495
517
  interface AgentStats {
496
518
  /** Agent ID */
497
- agent_id: string;
519
+ agent_id: AgentId;
498
520
  /** Total memory count */
499
521
  total_memories: number;
500
522
  /** Memories grouped by type */
@@ -512,14 +534,14 @@ interface AgentStats {
512
534
  }
513
535
  /** Request to build a knowledge graph */
514
536
  interface KnowledgeGraphRequest {
515
- agent_id: string;
516
- memory_id?: string;
537
+ agent_id: AgentId;
538
+ memory_id?: MemoryId;
517
539
  depth?: number;
518
540
  min_similarity?: number;
519
541
  }
520
542
  /** A node in the knowledge graph */
521
543
  interface KnowledgeNode {
522
- id: string;
544
+ id: MemoryId;
523
545
  content: string;
524
546
  memory_type?: string;
525
547
  importance?: number;
@@ -527,8 +549,8 @@ interface KnowledgeNode {
527
549
  }
528
550
  /** An edge in the knowledge graph */
529
551
  interface KnowledgeEdge {
530
- source: string;
531
- target: string;
552
+ source: MemoryId;
553
+ target: MemoryId;
532
554
  similarity: number;
533
555
  relationship?: string;
534
556
  }
@@ -540,7 +562,7 @@ interface KnowledgeGraphResponse {
540
562
  }
541
563
  /** Request for full knowledge graph */
542
564
  interface FullKnowledgeGraphRequest {
543
- agent_id: string;
565
+ agent_id: AgentId;
544
566
  max_nodes?: number;
545
567
  min_similarity?: number;
546
568
  cluster_threshold?: number;
@@ -548,8 +570,8 @@ interface FullKnowledgeGraphRequest {
548
570
  }
549
571
  /** Request to summarize memories */
550
572
  interface SummarizeRequest {
551
- agent_id: string;
552
- memory_ids?: string[];
573
+ agent_id: AgentId;
574
+ memory_ids?: MemoryId[];
553
575
  target_type?: string;
554
576
  dry_run?: boolean;
555
577
  }
@@ -557,11 +579,11 @@ interface SummarizeRequest {
557
579
  interface SummarizeResponse {
558
580
  summary: string;
559
581
  source_count: number;
560
- new_memory_id?: string;
582
+ new_memory_id?: MemoryId;
561
583
  }
562
584
  /** Request to deduplicate memories */
563
585
  interface DeduplicateRequest {
564
- agent_id: string;
586
+ agent_id: AgentId;
565
587
  threshold?: number;
566
588
  memory_type?: string;
567
589
  dry_run?: boolean;
@@ -801,6 +823,61 @@ interface ColumnUpsertRequest {
801
823
  /** Expected dimension */
802
824
  dimension?: number;
803
825
  }
826
+ /** Operation status for ``operation_progress`` events. */
827
+ type OpStatus = 'pending' | 'running' | 'completed' | 'failed';
828
+ /** Vector mutation operation type for ``vectors_mutated`` events. */
829
+ type VectorMutationOp = 'upserted' | 'deleted';
830
+ /** A namespace was created. */
831
+ interface NamespaceCreatedEvent {
832
+ type: 'namespace_created';
833
+ namespace: string;
834
+ dimension: number;
835
+ }
836
+ /** A namespace was deleted. */
837
+ interface NamespaceDeletedEvent {
838
+ type: 'namespace_deleted';
839
+ namespace: string;
840
+ }
841
+ /** Progress update for a long-running operation (0–100). */
842
+ interface OperationProgressEvent {
843
+ type: 'operation_progress';
844
+ operation_id: string;
845
+ namespace?: string;
846
+ op_type: string;
847
+ /** Progress percentage 0–100 */
848
+ progress: number;
849
+ status: OpStatus;
850
+ message?: string;
851
+ /** Unix milliseconds */
852
+ updated_at: number;
853
+ }
854
+ /** A background job changed status. */
855
+ interface JobProgressEvent {
856
+ type: 'job_progress';
857
+ job_id: string;
858
+ job_type: string;
859
+ namespace?: string;
860
+ progress: number;
861
+ status: string;
862
+ }
863
+ /** Vectors were upserted or deleted in bulk (threshold: >100 vectors). */
864
+ interface VectorsMutatedEvent {
865
+ type: 'vectors_mutated';
866
+ namespace: string;
867
+ op: VectorMutationOp;
868
+ count: number;
869
+ }
870
+ /**
871
+ * Subscriber fell too far behind — some events were dropped.
872
+ * Reconnect to resume the stream.
873
+ */
874
+ interface StreamLaggedEvent {
875
+ type: 'stream_lagged';
876
+ dropped: number;
877
+ hint: string;
878
+ }
879
+ /** Union of all Dakera SSE event types. */
880
+ type DakeraEvent = NamespaceCreatedEvent | NamespaceDeletedEvent | OperationProgressEvent | JobProgressEvent | VectorsMutatedEvent | StreamLaggedEvent;
804
881
  /** Cluster status response */
805
882
  interface ClusterStatus {
806
883
  status: string;
@@ -1484,6 +1561,45 @@ declare class DakeraClient {
1484
1561
  rotateKey(keyId: string): Promise<ApiKey>;
1485
1562
  /** Get usage statistics for an API key */
1486
1563
  keyUsage(keyId: string): Promise<KeyUsage>;
1564
+ /**
1565
+ * Stream SSE events scoped to a namespace.
1566
+ *
1567
+ * Opens a long-lived connection to `GET /v1/namespaces/{namespace}/events`
1568
+ * and yields {@link DakeraEvent} objects as they arrive. The async
1569
+ * generator runs until the connection closes or the caller breaks the loop.
1570
+ *
1571
+ * Requires a Read-scoped API key.
1572
+ *
1573
+ * @example
1574
+ * ```ts
1575
+ * for await (const event of client.streamNamespaceEvents('my-ns')) {
1576
+ * if (event.type === 'vectors_mutated') {
1577
+ * console.log(`${event.count} vectors ${event.op} in ${event.namespace}`);
1578
+ * }
1579
+ * }
1580
+ * ```
1581
+ */
1582
+ streamNamespaceEvents(namespace: string): AsyncGenerator<DakeraEvent>;
1583
+ /**
1584
+ * Stream all system events from the global event bus.
1585
+ *
1586
+ * Opens a long-lived connection to `GET /ops/events` and yields
1587
+ * {@link DakeraEvent} objects as they arrive.
1588
+ *
1589
+ * Requires an Admin-scoped API key.
1590
+ *
1591
+ * @example
1592
+ * ```ts
1593
+ * for await (const event of client.streamGlobalEvents()) {
1594
+ * console.log(event.type, event);
1595
+ * }
1596
+ * ```
1597
+ */
1598
+ streamGlobalEvents(): AsyncGenerator<DakeraEvent>;
1599
+ /** Low-level SSE streaming helper — parses the SSE wire format. */
1600
+ private _streamSse;
1601
+ /** Parse a single SSE event block into a {@link DakeraEvent}. */
1602
+ private _parseSseBlock;
1487
1603
  }
1488
1604
 
1489
1605
  /**
@@ -1525,4 +1641,4 @@ declare class TimeoutError extends DakeraError {
1525
1641
  constructor(message: string);
1526
1642
  }
1527
1643
 
1528
- export { type AccessPatternHint, type AgentStats, type AgentSummary, type AggregationGroup, type AggregationRequest, type AggregationResponse, type AnalyticsOptions, type AnalyticsOverview, type ApiKey, AuthenticationError, type BackupInfo, type BatchQuerySpec, type BatchTextQueryOptions, type BatchTextQueryResponse, type CacheStats, type ClientOptions, type ClusterNode, type ClusterStatus, type ColumnUpsertRequest, ConnectionError, type ConsolidateRequest, type ConsolidateResponse, type CreateKeyRequest, DakeraClient, DakeraError, type DeduplicateRequest, type DeduplicateResponse, type DeleteOptions, type DeleteResponse, type DistanceMetric, type Document, type DocumentInput, type EmbeddingModel, type ExportRequest, type ExportResponse, type ExportedVector, type FilterExpression, type FilterOperators, type FullKnowledgeGraphRequest, type FullTextSearchResult, type HealthResponse, type HybridSearchResult, type IndexStats, type KeyUsage, type KnowledgeEdge, type KnowledgeGraphRequest, type KnowledgeGraphResponse, type KnowledgeNode, type LatencyAnalytics, type ListSessionsOptions, type Memory, type MemoryFeedbackRequest, type MemoryFeedbackResponse, type MemoryType, type MultiVectorSearchRequest, type MultiVectorSearchResponse, type MultiVectorSearchResult, type NamespaceInfo, NotFoundError, type QueryExplainRequest, type QueryExplainResponse, type QueryOptions, type QueryResult, RateLimitError, type ReadConsistency, type RecallRequest, type RecalledMemory, type SearchResult, ServerError, type Session, type SlowQuery, type StalenessConfig, type StartSessionRequest, type StorageAnalytics, type StoreMemoryRequest, type StoreMemoryResponse, type SummarizeRequest, type SummarizeResponse, type TextDocument, type TextQueryOptions, type TextQueryResponse, type TextSearchResult, type TextUpsertOptions, type TextUpsertResponse, type ThroughputAnalytics, TimeoutError, type TtlConfig, type UnifiedQueryRequest, type UnifiedQueryResponse, type UnifiedSearchResult, type UpdateImportanceRequest, type UpdateMemoryRequest, type UpsertOptions, type UpsertResponse, ValidationError, type Vector, type VectorInput, type WarmCacheRequest, type WarmCacheResponse, type WarmingPriority, type WarmingTargetTier };
1644
+ export { type AccessPatternHint, type AgentId, type AgentStats, type AgentSummary, type AggregationGroup, type AggregationRequest, type AggregationResponse, type AnalyticsOptions, type AnalyticsOverview, type ApiKey, AuthenticationError, type BackupInfo, type BatchQuerySpec, type BatchTextQueryOptions, type BatchTextQueryResponse, type Branded, type CacheStats, type ClientOptions, type ClusterNode, type ClusterStatus, type ColumnUpsertRequest, ConnectionError, type ConsolidateRequest, type ConsolidateResponse, type CreateKeyRequest, DakeraClient, DakeraError, type DakeraEvent, type DeduplicateRequest, type DeduplicateResponse, type DeleteOptions, type DeleteResponse, type DistanceMetric, type Document, type DocumentInput, type EmbeddingModel, type ExportRequest, type ExportResponse, type ExportedVector, type FilterExpression, type FilterOperators, type FullKnowledgeGraphRequest, type FullTextSearchResult, type HealthResponse, type HybridSearchResult, type IndexStats, type JobProgressEvent, type KeyUsage, type KnowledgeEdge, type KnowledgeGraphRequest, type KnowledgeGraphResponse, type KnowledgeNode, type LatencyAnalytics, type ListSessionsOptions, type Memory, type MemoryFeedbackRequest, type MemoryFeedbackResponse, type MemoryId, type MemoryType, type MultiVectorSearchRequest, type MultiVectorSearchResponse, type MultiVectorSearchResult, type NamespaceCreatedEvent, type NamespaceDeletedEvent, type NamespaceInfo, NotFoundError, type OpStatus, type OperationProgressEvent, type QueryExplainRequest, type QueryExplainResponse, type QueryOptions, type QueryResult, RateLimitError, type ReadConsistency, type RecallRequest, type RecalledMemory, type SearchResult, ServerError, type Session, type SessionId, type SlowQuery, type StalenessConfig, type StartSessionRequest, type StorageAnalytics, type StoreMemoryRequest, type StoreMemoryResponse, type StreamLaggedEvent, type SummarizeRequest, type SummarizeResponse, type TextDocument, type TextQueryOptions, type TextQueryResponse, type TextSearchResult, type TextUpsertOptions, type TextUpsertResponse, type ThroughputAnalytics, TimeoutError, type TtlConfig, type UnifiedQueryRequest, type UnifiedQueryResponse, type UnifiedSearchResult, type UpdateImportanceRequest, type UpdateMemoryRequest, type UpsertOptions, type UpsertResponse, ValidationError, type Vector, type VectorId, type VectorInput, type VectorMutationOp, type VectorsMutatedEvent, type WarmCacheRequest, type WarmCacheResponse, type WarmingPriority, type WarmingTargetTier, agentId, memoryId, sessionId, vectorId };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,28 @@
1
1
  /**
2
2
  * Dakera TypeScript SDK Types
3
3
  */
4
+ declare const __brand: unique symbol;
5
+ type Brand<B> = {
6
+ readonly [__brand]: B;
7
+ };
8
+ /** A branded string type — T is the nominal tag that prevents cross-assignment. */
9
+ type Branded<T extends string, B> = T & Brand<B>;
10
+ /** Opaque ID for a stored vector. */
11
+ type VectorId = Branded<string, 'VectorId'>;
12
+ /** Opaque ID for an agent. */
13
+ type AgentId = Branded<string, 'AgentId'>;
14
+ /** Opaque ID for a memory entry. */
15
+ type MemoryId = Branded<string, 'MemoryId'>;
16
+ /** Opaque ID for a session. */
17
+ type SessionId = Branded<string, 'SessionId'>;
18
+ /** Create a VectorId from a plain string. */
19
+ declare function vectorId(id: string): VectorId;
20
+ /** Create an AgentId from a plain string. */
21
+ declare function agentId(id: string): AgentId;
22
+ /** Create a MemoryId from a plain string. */
23
+ declare function memoryId(id: string): MemoryId;
24
+ /** Create a SessionId from a plain string. */
25
+ declare function sessionId(id: string): SessionId;
4
26
  /** Read consistency level for queries */
5
27
  type ReadConsistency = 'strong' | 'eventual' | 'bounded_staleness';
6
28
  /** Distance metric for similarity search */
@@ -58,19 +80,19 @@ interface WarmCacheResponse {
58
80
  }
59
81
  /** Vector with ID, values, and optional metadata */
60
82
  interface Vector {
61
- id: string;
83
+ id: VectorId;
62
84
  values: number[];
63
85
  metadata?: Record<string, unknown>;
64
86
  }
65
87
  /** Input for vector operations - can be Vector object or plain object */
66
88
  type VectorInput = Vector | {
67
- id: string;
89
+ id: VectorId | string;
68
90
  values: number[];
69
91
  metadata?: Record<string, unknown>;
70
92
  };
71
93
  /** Result from a vector query */
72
94
  interface QueryResult {
73
- id: string;
95
+ id: VectorId;
74
96
  score: number;
75
97
  vector?: number[];
76
98
  metadata?: Record<string, unknown>;
@@ -104,25 +126,25 @@ interface IndexStats {
104
126
  }
105
127
  /** Document for full-text search */
106
128
  interface Document {
107
- id: string;
129
+ id: VectorId;
108
130
  content: string;
109
131
  metadata?: Record<string, unknown>;
110
132
  }
111
133
  /** Input for document operations */
112
134
  type DocumentInput = Document | {
113
- id: string;
135
+ id: VectorId | string;
114
136
  content: string;
115
137
  metadata?: Record<string, unknown>;
116
138
  };
117
139
  /** Result from full-text search */
118
140
  interface FullTextSearchResult {
119
- id: string;
141
+ id: VectorId;
120
142
  score: number;
121
143
  metadata?: Record<string, unknown>;
122
144
  }
123
145
  /** Result from hybrid search */
124
146
  interface HybridSearchResult {
125
- id: string;
147
+ id: VectorId;
126
148
  /** Combined score */
127
149
  score: number;
128
150
  /** Vector similarity score (normalized 0-1) */
@@ -277,7 +299,7 @@ interface TextQueryOptions {
277
299
  */
278
300
  interface TextSearchResult {
279
301
  /** Document ID */
280
- id: string;
302
+ id: VectorId;
281
303
  /** Similarity score */
282
304
  score: number;
283
305
  /** Original text (if includeText was true) */
@@ -348,7 +370,7 @@ interface StoreMemoryRequest {
348
370
  /** A stored memory */
349
371
  interface Memory {
350
372
  /** Memory ID */
351
- id: string;
373
+ id: MemoryId;
352
374
  /** Memory content */
353
375
  content: string;
354
376
  /** Memory type */
@@ -367,7 +389,7 @@ interface Memory {
367
389
  /** A recalled memory with similarity score */
368
390
  interface RecalledMemory {
369
391
  /** Memory ID */
370
- id: string;
392
+ id: MemoryId;
371
393
  /** Memory content */
372
394
  content: string;
373
395
  /** Memory type */
@@ -384,7 +406,7 @@ interface RecalledMemory {
384
406
  /** Response from storing a memory */
385
407
  interface StoreMemoryResponse {
386
408
  /** Created memory ID */
387
- memory_id: string;
409
+ memory_id: MemoryId;
388
410
  /** Status */
389
411
  status: string;
390
412
  }
@@ -411,7 +433,7 @@ interface RecallRequest {
411
433
  /** Request to update importance */
412
434
  interface UpdateImportanceRequest {
413
435
  /** Memory IDs to update */
414
- memory_ids: string[];
436
+ memory_ids: MemoryId[];
415
437
  /** New importance value */
416
438
  importance: number;
417
439
  }
@@ -431,12 +453,12 @@ interface ConsolidateResponse {
431
453
  /** Number of memories removed */
432
454
  removed_count: number;
433
455
  /** IDs of new consolidated memories */
434
- new_memories: string[];
456
+ new_memories: MemoryId[];
435
457
  }
436
458
  /** Request for memory feedback */
437
459
  interface MemoryFeedbackRequest {
438
460
  /** Memory ID */
439
- memory_id: string;
461
+ memory_id: MemoryId;
440
462
  /** Feedback text */
441
463
  feedback: string;
442
464
  /** Optional relevance score */
@@ -452,16 +474,16 @@ interface MemoryFeedbackResponse {
452
474
  /** Request to start a session */
453
475
  interface StartSessionRequest {
454
476
  /** Agent ID */
455
- agent_id: string;
477
+ agent_id: AgentId;
456
478
  /** Optional session metadata */
457
479
  metadata?: Record<string, unknown>;
458
480
  }
459
481
  /** A session */
460
482
  interface Session {
461
483
  /** Session ID */
462
- session_id: string;
484
+ session_id: SessionId;
463
485
  /** Agent ID */
464
- agent_id: string;
486
+ agent_id: AgentId;
465
487
  /** Start timestamp */
466
488
  started_at?: string;
467
489
  /** End timestamp */
@@ -483,7 +505,7 @@ interface ListSessionsOptions {
483
505
  /** Summary info for an agent */
484
506
  interface AgentSummary {
485
507
  /** Agent ID */
486
- agent_id: string;
508
+ agent_id: AgentId;
487
509
  /** Total memory count */
488
510
  memory_count: number;
489
511
  /** Total session count */
@@ -494,7 +516,7 @@ interface AgentSummary {
494
516
  /** Detailed stats for an agent */
495
517
  interface AgentStats {
496
518
  /** Agent ID */
497
- agent_id: string;
519
+ agent_id: AgentId;
498
520
  /** Total memory count */
499
521
  total_memories: number;
500
522
  /** Memories grouped by type */
@@ -512,14 +534,14 @@ interface AgentStats {
512
534
  }
513
535
  /** Request to build a knowledge graph */
514
536
  interface KnowledgeGraphRequest {
515
- agent_id: string;
516
- memory_id?: string;
537
+ agent_id: AgentId;
538
+ memory_id?: MemoryId;
517
539
  depth?: number;
518
540
  min_similarity?: number;
519
541
  }
520
542
  /** A node in the knowledge graph */
521
543
  interface KnowledgeNode {
522
- id: string;
544
+ id: MemoryId;
523
545
  content: string;
524
546
  memory_type?: string;
525
547
  importance?: number;
@@ -527,8 +549,8 @@ interface KnowledgeNode {
527
549
  }
528
550
  /** An edge in the knowledge graph */
529
551
  interface KnowledgeEdge {
530
- source: string;
531
- target: string;
552
+ source: MemoryId;
553
+ target: MemoryId;
532
554
  similarity: number;
533
555
  relationship?: string;
534
556
  }
@@ -540,7 +562,7 @@ interface KnowledgeGraphResponse {
540
562
  }
541
563
  /** Request for full knowledge graph */
542
564
  interface FullKnowledgeGraphRequest {
543
- agent_id: string;
565
+ agent_id: AgentId;
544
566
  max_nodes?: number;
545
567
  min_similarity?: number;
546
568
  cluster_threshold?: number;
@@ -548,8 +570,8 @@ interface FullKnowledgeGraphRequest {
548
570
  }
549
571
  /** Request to summarize memories */
550
572
  interface SummarizeRequest {
551
- agent_id: string;
552
- memory_ids?: string[];
573
+ agent_id: AgentId;
574
+ memory_ids?: MemoryId[];
553
575
  target_type?: string;
554
576
  dry_run?: boolean;
555
577
  }
@@ -557,11 +579,11 @@ interface SummarizeRequest {
557
579
  interface SummarizeResponse {
558
580
  summary: string;
559
581
  source_count: number;
560
- new_memory_id?: string;
582
+ new_memory_id?: MemoryId;
561
583
  }
562
584
  /** Request to deduplicate memories */
563
585
  interface DeduplicateRequest {
564
- agent_id: string;
586
+ agent_id: AgentId;
565
587
  threshold?: number;
566
588
  memory_type?: string;
567
589
  dry_run?: boolean;
@@ -801,6 +823,61 @@ interface ColumnUpsertRequest {
801
823
  /** Expected dimension */
802
824
  dimension?: number;
803
825
  }
826
+ /** Operation status for ``operation_progress`` events. */
827
+ type OpStatus = 'pending' | 'running' | 'completed' | 'failed';
828
+ /** Vector mutation operation type for ``vectors_mutated`` events. */
829
+ type VectorMutationOp = 'upserted' | 'deleted';
830
+ /** A namespace was created. */
831
+ interface NamespaceCreatedEvent {
832
+ type: 'namespace_created';
833
+ namespace: string;
834
+ dimension: number;
835
+ }
836
+ /** A namespace was deleted. */
837
+ interface NamespaceDeletedEvent {
838
+ type: 'namespace_deleted';
839
+ namespace: string;
840
+ }
841
+ /** Progress update for a long-running operation (0–100). */
842
+ interface OperationProgressEvent {
843
+ type: 'operation_progress';
844
+ operation_id: string;
845
+ namespace?: string;
846
+ op_type: string;
847
+ /** Progress percentage 0–100 */
848
+ progress: number;
849
+ status: OpStatus;
850
+ message?: string;
851
+ /** Unix milliseconds */
852
+ updated_at: number;
853
+ }
854
+ /** A background job changed status. */
855
+ interface JobProgressEvent {
856
+ type: 'job_progress';
857
+ job_id: string;
858
+ job_type: string;
859
+ namespace?: string;
860
+ progress: number;
861
+ status: string;
862
+ }
863
+ /** Vectors were upserted or deleted in bulk (threshold: >100 vectors). */
864
+ interface VectorsMutatedEvent {
865
+ type: 'vectors_mutated';
866
+ namespace: string;
867
+ op: VectorMutationOp;
868
+ count: number;
869
+ }
870
+ /**
871
+ * Subscriber fell too far behind — some events were dropped.
872
+ * Reconnect to resume the stream.
873
+ */
874
+ interface StreamLaggedEvent {
875
+ type: 'stream_lagged';
876
+ dropped: number;
877
+ hint: string;
878
+ }
879
+ /** Union of all Dakera SSE event types. */
880
+ type DakeraEvent = NamespaceCreatedEvent | NamespaceDeletedEvent | OperationProgressEvent | JobProgressEvent | VectorsMutatedEvent | StreamLaggedEvent;
804
881
  /** Cluster status response */
805
882
  interface ClusterStatus {
806
883
  status: string;
@@ -1484,6 +1561,45 @@ declare class DakeraClient {
1484
1561
  rotateKey(keyId: string): Promise<ApiKey>;
1485
1562
  /** Get usage statistics for an API key */
1486
1563
  keyUsage(keyId: string): Promise<KeyUsage>;
1564
+ /**
1565
+ * Stream SSE events scoped to a namespace.
1566
+ *
1567
+ * Opens a long-lived connection to `GET /v1/namespaces/{namespace}/events`
1568
+ * and yields {@link DakeraEvent} objects as they arrive. The async
1569
+ * generator runs until the connection closes or the caller breaks the loop.
1570
+ *
1571
+ * Requires a Read-scoped API key.
1572
+ *
1573
+ * @example
1574
+ * ```ts
1575
+ * for await (const event of client.streamNamespaceEvents('my-ns')) {
1576
+ * if (event.type === 'vectors_mutated') {
1577
+ * console.log(`${event.count} vectors ${event.op} in ${event.namespace}`);
1578
+ * }
1579
+ * }
1580
+ * ```
1581
+ */
1582
+ streamNamespaceEvents(namespace: string): AsyncGenerator<DakeraEvent>;
1583
+ /**
1584
+ * Stream all system events from the global event bus.
1585
+ *
1586
+ * Opens a long-lived connection to `GET /ops/events` and yields
1587
+ * {@link DakeraEvent} objects as they arrive.
1588
+ *
1589
+ * Requires an Admin-scoped API key.
1590
+ *
1591
+ * @example
1592
+ * ```ts
1593
+ * for await (const event of client.streamGlobalEvents()) {
1594
+ * console.log(event.type, event);
1595
+ * }
1596
+ * ```
1597
+ */
1598
+ streamGlobalEvents(): AsyncGenerator<DakeraEvent>;
1599
+ /** Low-level SSE streaming helper — parses the SSE wire format. */
1600
+ private _streamSse;
1601
+ /** Parse a single SSE event block into a {@link DakeraEvent}. */
1602
+ private _parseSseBlock;
1487
1603
  }
1488
1604
 
1489
1605
  /**
@@ -1525,4 +1641,4 @@ declare class TimeoutError extends DakeraError {
1525
1641
  constructor(message: string);
1526
1642
  }
1527
1643
 
1528
- export { type AccessPatternHint, type AgentStats, type AgentSummary, type AggregationGroup, type AggregationRequest, type AggregationResponse, type AnalyticsOptions, type AnalyticsOverview, type ApiKey, AuthenticationError, type BackupInfo, type BatchQuerySpec, type BatchTextQueryOptions, type BatchTextQueryResponse, type CacheStats, type ClientOptions, type ClusterNode, type ClusterStatus, type ColumnUpsertRequest, ConnectionError, type ConsolidateRequest, type ConsolidateResponse, type CreateKeyRequest, DakeraClient, DakeraError, type DeduplicateRequest, type DeduplicateResponse, type DeleteOptions, type DeleteResponse, type DistanceMetric, type Document, type DocumentInput, type EmbeddingModel, type ExportRequest, type ExportResponse, type ExportedVector, type FilterExpression, type FilterOperators, type FullKnowledgeGraphRequest, type FullTextSearchResult, type HealthResponse, type HybridSearchResult, type IndexStats, type KeyUsage, type KnowledgeEdge, type KnowledgeGraphRequest, type KnowledgeGraphResponse, type KnowledgeNode, type LatencyAnalytics, type ListSessionsOptions, type Memory, type MemoryFeedbackRequest, type MemoryFeedbackResponse, type MemoryType, type MultiVectorSearchRequest, type MultiVectorSearchResponse, type MultiVectorSearchResult, type NamespaceInfo, NotFoundError, type QueryExplainRequest, type QueryExplainResponse, type QueryOptions, type QueryResult, RateLimitError, type ReadConsistency, type RecallRequest, type RecalledMemory, type SearchResult, ServerError, type Session, type SlowQuery, type StalenessConfig, type StartSessionRequest, type StorageAnalytics, type StoreMemoryRequest, type StoreMemoryResponse, type SummarizeRequest, type SummarizeResponse, type TextDocument, type TextQueryOptions, type TextQueryResponse, type TextSearchResult, type TextUpsertOptions, type TextUpsertResponse, type ThroughputAnalytics, TimeoutError, type TtlConfig, type UnifiedQueryRequest, type UnifiedQueryResponse, type UnifiedSearchResult, type UpdateImportanceRequest, type UpdateMemoryRequest, type UpsertOptions, type UpsertResponse, ValidationError, type Vector, type VectorInput, type WarmCacheRequest, type WarmCacheResponse, type WarmingPriority, type WarmingTargetTier };
1644
+ export { type AccessPatternHint, type AgentId, type AgentStats, type AgentSummary, type AggregationGroup, type AggregationRequest, type AggregationResponse, type AnalyticsOptions, type AnalyticsOverview, type ApiKey, AuthenticationError, type BackupInfo, type BatchQuerySpec, type BatchTextQueryOptions, type BatchTextQueryResponse, type Branded, type CacheStats, type ClientOptions, type ClusterNode, type ClusterStatus, type ColumnUpsertRequest, ConnectionError, type ConsolidateRequest, type ConsolidateResponse, type CreateKeyRequest, DakeraClient, DakeraError, type DakeraEvent, type DeduplicateRequest, type DeduplicateResponse, type DeleteOptions, type DeleteResponse, type DistanceMetric, type Document, type DocumentInput, type EmbeddingModel, type ExportRequest, type ExportResponse, type ExportedVector, type FilterExpression, type FilterOperators, type FullKnowledgeGraphRequest, type FullTextSearchResult, type HealthResponse, type HybridSearchResult, type IndexStats, type JobProgressEvent, type KeyUsage, type KnowledgeEdge, type KnowledgeGraphRequest, type KnowledgeGraphResponse, type KnowledgeNode, type LatencyAnalytics, type ListSessionsOptions, type Memory, type MemoryFeedbackRequest, type MemoryFeedbackResponse, type MemoryId, type MemoryType, type MultiVectorSearchRequest, type MultiVectorSearchResponse, type MultiVectorSearchResult, type NamespaceCreatedEvent, type NamespaceDeletedEvent, type NamespaceInfo, NotFoundError, type OpStatus, type OperationProgressEvent, type QueryExplainRequest, type QueryExplainResponse, type QueryOptions, type QueryResult, RateLimitError, type ReadConsistency, type RecallRequest, type RecalledMemory, type SearchResult, ServerError, type Session, type SessionId, type SlowQuery, type StalenessConfig, type StartSessionRequest, type StorageAnalytics, type StoreMemoryRequest, type StoreMemoryResponse, type StreamLaggedEvent, type SummarizeRequest, type SummarizeResponse, type TextDocument, type TextQueryOptions, type TextQueryResponse, type TextSearchResult, type TextUpsertOptions, type TextUpsertResponse, type ThroughputAnalytics, TimeoutError, type TtlConfig, type UnifiedQueryRequest, type UnifiedQueryResponse, type UnifiedSearchResult, type UpdateImportanceRequest, type UpdateMemoryRequest, type UpsertOptions, type UpsertResponse, ValidationError, type Vector, type VectorId, type VectorInput, type VectorMutationOp, type VectorsMutatedEvent, type WarmCacheRequest, type WarmCacheResponse, type WarmingPriority, type WarmingTargetTier, agentId, memoryId, sessionId, vectorId };
package/dist/index.js CHANGED
@@ -28,7 +28,11 @@ __export(index_exports, {
28
28
  RateLimitError: () => RateLimitError,
29
29
  ServerError: () => ServerError,
30
30
  TimeoutError: () => TimeoutError,
31
- ValidationError: () => ValidationError
31
+ ValidationError: () => ValidationError,
32
+ agentId: () => agentId,
33
+ memoryId: () => memoryId,
34
+ sessionId: () => sessionId,
35
+ vectorId: () => vectorId
32
36
  });
33
37
  module.exports = __toCommonJS(index_exports);
34
38
 
@@ -938,59 +942,59 @@ var DakeraClient = class {
938
942
  // Memory Operations
939
943
  // ===========================================================================
940
944
  /** Store a memory for an agent */
941
- async storeMemory(agentId, request) {
942
- return this.request("POST", `/v1/agents/${agentId}/memories`, request);
945
+ async storeMemory(agentId2, request) {
946
+ return this.request("POST", `/v1/agents/${agentId2}/memories`, request);
943
947
  }
944
948
  /** Recall memories for an agent */
945
- async recall(agentId, query, options) {
949
+ async recall(agentId2, query, options) {
946
950
  const body = { query, ...options };
947
- const result = await this.request("POST", `/v1/agents/${agentId}/memories/recall`, body);
951
+ const result = await this.request("POST", `/v1/agents/${agentId2}/memories/recall`, body);
948
952
  return result.memories ?? result;
949
953
  }
950
954
  /** Get a specific memory */
951
- async getMemory(agentId, memoryId) {
952
- return this.request("GET", `/v1/agents/${agentId}/memories/${memoryId}`);
955
+ async getMemory(agentId2, memoryId2) {
956
+ return this.request("GET", `/v1/agents/${agentId2}/memories/${memoryId2}`);
953
957
  }
954
958
  /** Update an existing memory */
955
- async updateMemory(agentId, memoryId, request) {
956
- return this.request("PUT", `/v1/agents/${agentId}/memories/${memoryId}`, request);
959
+ async updateMemory(agentId2, memoryId2, request) {
960
+ return this.request("PUT", `/v1/agents/${agentId2}/memories/${memoryId2}`, request);
957
961
  }
958
962
  /** Delete a memory */
959
- async forget(agentId, memoryId) {
960
- return this.request("DELETE", `/v1/agents/${agentId}/memories/${memoryId}`);
963
+ async forget(agentId2, memoryId2) {
964
+ return this.request("DELETE", `/v1/agents/${agentId2}/memories/${memoryId2}`);
961
965
  }
962
966
  /** Search memories for an agent */
963
- async searchMemories(agentId, query, options) {
967
+ async searchMemories(agentId2, query, options) {
964
968
  const body = { query, ...options };
965
- const result = await this.request("POST", `/v1/agents/${agentId}/memories/search`, body);
969
+ const result = await this.request("POST", `/v1/agents/${agentId2}/memories/search`, body);
966
970
  return result.memories ?? result;
967
971
  }
968
972
  /** Update importance of memories */
969
- async updateImportance(agentId, request) {
970
- return this.request("PUT", `/v1/agents/${agentId}/memories/importance`, request);
973
+ async updateImportance(agentId2, request) {
974
+ return this.request("PUT", `/v1/agents/${agentId2}/memories/importance`, request);
971
975
  }
972
976
  /** Consolidate memories for an agent */
973
- async consolidate(agentId, request) {
974
- return this.request("POST", `/v1/agents/${agentId}/memories/consolidate`, request ?? {});
977
+ async consolidate(agentId2, request) {
978
+ return this.request("POST", `/v1/agents/${agentId2}/memories/consolidate`, request ?? {});
975
979
  }
976
980
  /** Submit feedback on a memory recall */
977
- async memoryFeedback(agentId, request) {
978
- return this.request("POST", `/v1/agents/${agentId}/memories/feedback`, request);
981
+ async memoryFeedback(agentId2, request) {
982
+ return this.request("POST", `/v1/agents/${agentId2}/memories/feedback`, request);
979
983
  }
980
984
  // ===========================================================================
981
985
  // Session Operations
982
986
  // ===========================================================================
983
987
  /** Start a new session */
984
- async startSession(agentId, metadata) {
985
- return this.request("POST", "/v1/sessions/start", { agent_id: agentId, metadata });
988
+ async startSession(agentId2, metadata) {
989
+ return this.request("POST", "/v1/sessions/start", { agent_id: agentId2, metadata });
986
990
  }
987
991
  /** End a session */
988
- async endSession(sessionId) {
989
- return this.request("POST", `/v1/sessions/${sessionId}/end`);
992
+ async endSession(sessionId2) {
993
+ return this.request("POST", `/v1/sessions/${sessionId2}/end`);
990
994
  }
991
995
  /** Get session details */
992
- async getSession(sessionId) {
993
- return this.request("GET", `/v1/sessions/${sessionId}`);
996
+ async getSession(sessionId2) {
997
+ return this.request("GET", `/v1/sessions/${sessionId2}`);
994
998
  }
995
999
  /** List sessions */
996
1000
  async listSessions(options) {
@@ -1003,8 +1007,8 @@ var DakeraClient = class {
1003
1007
  return this.request("GET", `/v1/sessions${qs ? `?${qs}` : ""}`);
1004
1008
  }
1005
1009
  /** Get memories for a session */
1006
- async sessionMemories(sessionId) {
1007
- return this.request("GET", `/v1/sessions/${sessionId}/memories`);
1010
+ async sessionMemories(sessionId2) {
1011
+ return this.request("GET", `/v1/sessions/${sessionId2}/memories`);
1008
1012
  }
1009
1013
  // ===========================================================================
1010
1014
  // Agent Operations
@@ -1014,24 +1018,24 @@ var DakeraClient = class {
1014
1018
  return this.request("GET", "/v1/agents");
1015
1019
  }
1016
1020
  /** Get memories for an agent */
1017
- async agentMemories(agentId, options) {
1021
+ async agentMemories(agentId2, options) {
1018
1022
  const params = new URLSearchParams();
1019
1023
  if (options?.memory_type) params.set("memory_type", options.memory_type);
1020
1024
  if (options?.limit !== void 0) params.set("limit", String(options.limit));
1021
1025
  const qs = params.toString();
1022
- return this.request("GET", `/v1/agents/${agentId}/memories${qs ? `?${qs}` : ""}`);
1026
+ return this.request("GET", `/v1/agents/${agentId2}/memories${qs ? `?${qs}` : ""}`);
1023
1027
  }
1024
1028
  /** Get stats for an agent */
1025
- async agentStats(agentId) {
1026
- return this.request("GET", `/v1/agents/${agentId}/stats`);
1029
+ async agentStats(agentId2) {
1030
+ return this.request("GET", `/v1/agents/${agentId2}/stats`);
1027
1031
  }
1028
1032
  /** Get sessions for an agent */
1029
- async agentSessions(agentId, options) {
1033
+ async agentSessions(agentId2, options) {
1030
1034
  const params = new URLSearchParams();
1031
1035
  if (options?.active_only !== void 0) params.set("active_only", String(options.active_only));
1032
1036
  if (options?.limit !== void 0) params.set("limit", String(options.limit));
1033
1037
  const qs = params.toString();
1034
- return this.request("GET", `/v1/agents/${agentId}/sessions${qs ? `?${qs}` : ""}`);
1038
+ return this.request("GET", `/v1/agents/${agentId2}/sessions${qs ? `?${qs}` : ""}`);
1035
1039
  }
1036
1040
  // ===========================================================================
1037
1041
  // Knowledge Graph Operations
@@ -1195,7 +1199,111 @@ var DakeraClient = class {
1195
1199
  async keyUsage(keyId) {
1196
1200
  return this.request("GET", `/v1/keys/${keyId}/usage`);
1197
1201
  }
1202
+ // ===========================================================================
1203
+ // SSE Streaming (CE-1)
1204
+ // ===========================================================================
1205
+ /**
1206
+ * Stream SSE events scoped to a namespace.
1207
+ *
1208
+ * Opens a long-lived connection to `GET /v1/namespaces/{namespace}/events`
1209
+ * and yields {@link DakeraEvent} objects as they arrive. The async
1210
+ * generator runs until the connection closes or the caller breaks the loop.
1211
+ *
1212
+ * Requires a Read-scoped API key.
1213
+ *
1214
+ * @example
1215
+ * ```ts
1216
+ * for await (const event of client.streamNamespaceEvents('my-ns')) {
1217
+ * if (event.type === 'vectors_mutated') {
1218
+ * console.log(`${event.count} vectors ${event.op} in ${event.namespace}`);
1219
+ * }
1220
+ * }
1221
+ * ```
1222
+ */
1223
+ async *streamNamespaceEvents(namespace) {
1224
+ const url = `${this.baseUrl}/v1/namespaces/${encodeURIComponent(namespace)}/events`;
1225
+ yield* this._streamSse(url);
1226
+ }
1227
+ /**
1228
+ * Stream all system events from the global event bus.
1229
+ *
1230
+ * Opens a long-lived connection to `GET /ops/events` and yields
1231
+ * {@link DakeraEvent} objects as they arrive.
1232
+ *
1233
+ * Requires an Admin-scoped API key.
1234
+ *
1235
+ * @example
1236
+ * ```ts
1237
+ * for await (const event of client.streamGlobalEvents()) {
1238
+ * console.log(event.type, event);
1239
+ * }
1240
+ * ```
1241
+ */
1242
+ async *streamGlobalEvents() {
1243
+ const url = `${this.baseUrl}/ops/events`;
1244
+ yield* this._streamSse(url);
1245
+ }
1246
+ /** Low-level SSE streaming helper — parses the SSE wire format. */
1247
+ async *_streamSse(url) {
1248
+ const headers = {
1249
+ ...this.headers,
1250
+ // includes Authorization and any custom headers
1251
+ Accept: "text/event-stream",
1252
+ "Cache-Control": "no-cache"
1253
+ };
1254
+ const response = await fetch(url, { headers });
1255
+ if (!response.ok || !response.body) {
1256
+ throw new Error(`SSE connection failed: ${response.status} ${response.statusText}`);
1257
+ }
1258
+ const reader = response.body.getReader();
1259
+ const decoder = new TextDecoder();
1260
+ let buffer = "";
1261
+ try {
1262
+ while (true) {
1263
+ const { done, value } = await reader.read();
1264
+ if (done) break;
1265
+ buffer += decoder.decode(value, { stream: true });
1266
+ let boundary;
1267
+ while ((boundary = buffer.indexOf("\n\n")) !== -1) {
1268
+ const block = buffer.slice(0, boundary);
1269
+ buffer = buffer.slice(boundary + 2);
1270
+ const event = this._parseSseBlock(block);
1271
+ if (event !== null) yield event;
1272
+ }
1273
+ }
1274
+ } finally {
1275
+ reader.releaseLock();
1276
+ }
1277
+ }
1278
+ /** Parse a single SSE event block into a {@link DakeraEvent}. */
1279
+ _parseSseBlock(block) {
1280
+ const dataLines = [];
1281
+ for (const line of block.split("\n")) {
1282
+ if (line.startsWith(":")) continue;
1283
+ if (line.startsWith("data:")) dataLines.push(line.slice(5).trimStart());
1284
+ }
1285
+ if (dataLines.length === 0) return null;
1286
+ try {
1287
+ return JSON.parse(dataLines.join("\n"));
1288
+ } catch {
1289
+ return null;
1290
+ }
1291
+ }
1198
1292
  };
1293
+
1294
+ // src/types.ts
1295
+ function vectorId(id) {
1296
+ return id;
1297
+ }
1298
+ function agentId(id) {
1299
+ return id;
1300
+ }
1301
+ function memoryId(id) {
1302
+ return id;
1303
+ }
1304
+ function sessionId(id) {
1305
+ return id;
1306
+ }
1199
1307
  // Annotate the CommonJS export names for ESM import in node:
1200
1308
  0 && (module.exports = {
1201
1309
  AuthenticationError,
@@ -1206,5 +1314,9 @@ var DakeraClient = class {
1206
1314
  RateLimitError,
1207
1315
  ServerError,
1208
1316
  TimeoutError,
1209
- ValidationError
1317
+ ValidationError,
1318
+ agentId,
1319
+ memoryId,
1320
+ sessionId,
1321
+ vectorId
1210
1322
  });
package/dist/index.mjs CHANGED
@@ -904,59 +904,59 @@ var DakeraClient = class {
904
904
  // Memory Operations
905
905
  // ===========================================================================
906
906
  /** Store a memory for an agent */
907
- async storeMemory(agentId, request) {
908
- return this.request("POST", `/v1/agents/${agentId}/memories`, request);
907
+ async storeMemory(agentId2, request) {
908
+ return this.request("POST", `/v1/agents/${agentId2}/memories`, request);
909
909
  }
910
910
  /** Recall memories for an agent */
911
- async recall(agentId, query, options) {
911
+ async recall(agentId2, query, options) {
912
912
  const body = { query, ...options };
913
- const result = await this.request("POST", `/v1/agents/${agentId}/memories/recall`, body);
913
+ const result = await this.request("POST", `/v1/agents/${agentId2}/memories/recall`, body);
914
914
  return result.memories ?? result;
915
915
  }
916
916
  /** Get a specific memory */
917
- async getMemory(agentId, memoryId) {
918
- return this.request("GET", `/v1/agents/${agentId}/memories/${memoryId}`);
917
+ async getMemory(agentId2, memoryId2) {
918
+ return this.request("GET", `/v1/agents/${agentId2}/memories/${memoryId2}`);
919
919
  }
920
920
  /** Update an existing memory */
921
- async updateMemory(agentId, memoryId, request) {
922
- return this.request("PUT", `/v1/agents/${agentId}/memories/${memoryId}`, request);
921
+ async updateMemory(agentId2, memoryId2, request) {
922
+ return this.request("PUT", `/v1/agents/${agentId2}/memories/${memoryId2}`, request);
923
923
  }
924
924
  /** Delete a memory */
925
- async forget(agentId, memoryId) {
926
- return this.request("DELETE", `/v1/agents/${agentId}/memories/${memoryId}`);
925
+ async forget(agentId2, memoryId2) {
926
+ return this.request("DELETE", `/v1/agents/${agentId2}/memories/${memoryId2}`);
927
927
  }
928
928
  /** Search memories for an agent */
929
- async searchMemories(agentId, query, options) {
929
+ async searchMemories(agentId2, query, options) {
930
930
  const body = { query, ...options };
931
- const result = await this.request("POST", `/v1/agents/${agentId}/memories/search`, body);
931
+ const result = await this.request("POST", `/v1/agents/${agentId2}/memories/search`, body);
932
932
  return result.memories ?? result;
933
933
  }
934
934
  /** Update importance of memories */
935
- async updateImportance(agentId, request) {
936
- return this.request("PUT", `/v1/agents/${agentId}/memories/importance`, request);
935
+ async updateImportance(agentId2, request) {
936
+ return this.request("PUT", `/v1/agents/${agentId2}/memories/importance`, request);
937
937
  }
938
938
  /** Consolidate memories for an agent */
939
- async consolidate(agentId, request) {
940
- return this.request("POST", `/v1/agents/${agentId}/memories/consolidate`, request ?? {});
939
+ async consolidate(agentId2, request) {
940
+ return this.request("POST", `/v1/agents/${agentId2}/memories/consolidate`, request ?? {});
941
941
  }
942
942
  /** Submit feedback on a memory recall */
943
- async memoryFeedback(agentId, request) {
944
- return this.request("POST", `/v1/agents/${agentId}/memories/feedback`, request);
943
+ async memoryFeedback(agentId2, request) {
944
+ return this.request("POST", `/v1/agents/${agentId2}/memories/feedback`, request);
945
945
  }
946
946
  // ===========================================================================
947
947
  // Session Operations
948
948
  // ===========================================================================
949
949
  /** Start a new session */
950
- async startSession(agentId, metadata) {
951
- return this.request("POST", "/v1/sessions/start", { agent_id: agentId, metadata });
950
+ async startSession(agentId2, metadata) {
951
+ return this.request("POST", "/v1/sessions/start", { agent_id: agentId2, metadata });
952
952
  }
953
953
  /** End a session */
954
- async endSession(sessionId) {
955
- return this.request("POST", `/v1/sessions/${sessionId}/end`);
954
+ async endSession(sessionId2) {
955
+ return this.request("POST", `/v1/sessions/${sessionId2}/end`);
956
956
  }
957
957
  /** Get session details */
958
- async getSession(sessionId) {
959
- return this.request("GET", `/v1/sessions/${sessionId}`);
958
+ async getSession(sessionId2) {
959
+ return this.request("GET", `/v1/sessions/${sessionId2}`);
960
960
  }
961
961
  /** List sessions */
962
962
  async listSessions(options) {
@@ -969,8 +969,8 @@ var DakeraClient = class {
969
969
  return this.request("GET", `/v1/sessions${qs ? `?${qs}` : ""}`);
970
970
  }
971
971
  /** Get memories for a session */
972
- async sessionMemories(sessionId) {
973
- return this.request("GET", `/v1/sessions/${sessionId}/memories`);
972
+ async sessionMemories(sessionId2) {
973
+ return this.request("GET", `/v1/sessions/${sessionId2}/memories`);
974
974
  }
975
975
  // ===========================================================================
976
976
  // Agent Operations
@@ -980,24 +980,24 @@ var DakeraClient = class {
980
980
  return this.request("GET", "/v1/agents");
981
981
  }
982
982
  /** Get memories for an agent */
983
- async agentMemories(agentId, options) {
983
+ async agentMemories(agentId2, options) {
984
984
  const params = new URLSearchParams();
985
985
  if (options?.memory_type) params.set("memory_type", options.memory_type);
986
986
  if (options?.limit !== void 0) params.set("limit", String(options.limit));
987
987
  const qs = params.toString();
988
- return this.request("GET", `/v1/agents/${agentId}/memories${qs ? `?${qs}` : ""}`);
988
+ return this.request("GET", `/v1/agents/${agentId2}/memories${qs ? `?${qs}` : ""}`);
989
989
  }
990
990
  /** Get stats for an agent */
991
- async agentStats(agentId) {
992
- return this.request("GET", `/v1/agents/${agentId}/stats`);
991
+ async agentStats(agentId2) {
992
+ return this.request("GET", `/v1/agents/${agentId2}/stats`);
993
993
  }
994
994
  /** Get sessions for an agent */
995
- async agentSessions(agentId, options) {
995
+ async agentSessions(agentId2, options) {
996
996
  const params = new URLSearchParams();
997
997
  if (options?.active_only !== void 0) params.set("active_only", String(options.active_only));
998
998
  if (options?.limit !== void 0) params.set("limit", String(options.limit));
999
999
  const qs = params.toString();
1000
- return this.request("GET", `/v1/agents/${agentId}/sessions${qs ? `?${qs}` : ""}`);
1000
+ return this.request("GET", `/v1/agents/${agentId2}/sessions${qs ? `?${qs}` : ""}`);
1001
1001
  }
1002
1002
  // ===========================================================================
1003
1003
  // Knowledge Graph Operations
@@ -1161,7 +1161,111 @@ var DakeraClient = class {
1161
1161
  async keyUsage(keyId) {
1162
1162
  return this.request("GET", `/v1/keys/${keyId}/usage`);
1163
1163
  }
1164
+ // ===========================================================================
1165
+ // SSE Streaming (CE-1)
1166
+ // ===========================================================================
1167
+ /**
1168
+ * Stream SSE events scoped to a namespace.
1169
+ *
1170
+ * Opens a long-lived connection to `GET /v1/namespaces/{namespace}/events`
1171
+ * and yields {@link DakeraEvent} objects as they arrive. The async
1172
+ * generator runs until the connection closes or the caller breaks the loop.
1173
+ *
1174
+ * Requires a Read-scoped API key.
1175
+ *
1176
+ * @example
1177
+ * ```ts
1178
+ * for await (const event of client.streamNamespaceEvents('my-ns')) {
1179
+ * if (event.type === 'vectors_mutated') {
1180
+ * console.log(`${event.count} vectors ${event.op} in ${event.namespace}`);
1181
+ * }
1182
+ * }
1183
+ * ```
1184
+ */
1185
+ async *streamNamespaceEvents(namespace) {
1186
+ const url = `${this.baseUrl}/v1/namespaces/${encodeURIComponent(namespace)}/events`;
1187
+ yield* this._streamSse(url);
1188
+ }
1189
+ /**
1190
+ * Stream all system events from the global event bus.
1191
+ *
1192
+ * Opens a long-lived connection to `GET /ops/events` and yields
1193
+ * {@link DakeraEvent} objects as they arrive.
1194
+ *
1195
+ * Requires an Admin-scoped API key.
1196
+ *
1197
+ * @example
1198
+ * ```ts
1199
+ * for await (const event of client.streamGlobalEvents()) {
1200
+ * console.log(event.type, event);
1201
+ * }
1202
+ * ```
1203
+ */
1204
+ async *streamGlobalEvents() {
1205
+ const url = `${this.baseUrl}/ops/events`;
1206
+ yield* this._streamSse(url);
1207
+ }
1208
+ /** Low-level SSE streaming helper — parses the SSE wire format. */
1209
+ async *_streamSse(url) {
1210
+ const headers = {
1211
+ ...this.headers,
1212
+ // includes Authorization and any custom headers
1213
+ Accept: "text/event-stream",
1214
+ "Cache-Control": "no-cache"
1215
+ };
1216
+ const response = await fetch(url, { headers });
1217
+ if (!response.ok || !response.body) {
1218
+ throw new Error(`SSE connection failed: ${response.status} ${response.statusText}`);
1219
+ }
1220
+ const reader = response.body.getReader();
1221
+ const decoder = new TextDecoder();
1222
+ let buffer = "";
1223
+ try {
1224
+ while (true) {
1225
+ const { done, value } = await reader.read();
1226
+ if (done) break;
1227
+ buffer += decoder.decode(value, { stream: true });
1228
+ let boundary;
1229
+ while ((boundary = buffer.indexOf("\n\n")) !== -1) {
1230
+ const block = buffer.slice(0, boundary);
1231
+ buffer = buffer.slice(boundary + 2);
1232
+ const event = this._parseSseBlock(block);
1233
+ if (event !== null) yield event;
1234
+ }
1235
+ }
1236
+ } finally {
1237
+ reader.releaseLock();
1238
+ }
1239
+ }
1240
+ /** Parse a single SSE event block into a {@link DakeraEvent}. */
1241
+ _parseSseBlock(block) {
1242
+ const dataLines = [];
1243
+ for (const line of block.split("\n")) {
1244
+ if (line.startsWith(":")) continue;
1245
+ if (line.startsWith("data:")) dataLines.push(line.slice(5).trimStart());
1246
+ }
1247
+ if (dataLines.length === 0) return null;
1248
+ try {
1249
+ return JSON.parse(dataLines.join("\n"));
1250
+ } catch {
1251
+ return null;
1252
+ }
1253
+ }
1164
1254
  };
1255
+
1256
+ // src/types.ts
1257
+ function vectorId(id) {
1258
+ return id;
1259
+ }
1260
+ function agentId(id) {
1261
+ return id;
1262
+ }
1263
+ function memoryId(id) {
1264
+ return id;
1265
+ }
1266
+ function sessionId(id) {
1267
+ return id;
1268
+ }
1165
1269
  export {
1166
1270
  AuthenticationError,
1167
1271
  ConnectionError,
@@ -1171,5 +1275,9 @@ export {
1171
1275
  RateLimitError,
1172
1276
  ServerError,
1173
1277
  TimeoutError,
1174
- ValidationError
1278
+ ValidationError,
1279
+ agentId,
1280
+ memoryId,
1281
+ sessionId,
1282
+ vectorId
1175
1283
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dakera-ai/dakera",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "TypeScript/JavaScript SDK for Dakera AI memory platform",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",