@dakera-ai/dakera 0.3.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/dist/index.d.mts CHANGED
@@ -823,6 +823,61 @@ interface ColumnUpsertRequest {
823
823
  /** Expected dimension */
824
824
  dimension?: number;
825
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;
826
881
  /** Cluster status response */
827
882
  interface ClusterStatus {
828
883
  status: string;
@@ -1506,6 +1561,45 @@ declare class DakeraClient {
1506
1561
  rotateKey(keyId: string): Promise<ApiKey>;
1507
1562
  /** Get usage statistics for an API key */
1508
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;
1509
1603
  }
1510
1604
 
1511
1605
  /**
@@ -1547,4 +1641,4 @@ declare class TimeoutError extends DakeraError {
1547
1641
  constructor(message: string);
1548
1642
  }
1549
1643
 
1550
- 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 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 MemoryId, 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 SessionId, 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 VectorId, type VectorInput, type WarmCacheRequest, type WarmCacheResponse, type WarmingPriority, type WarmingTargetTier, agentId, memoryId, sessionId, vectorId };
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
@@ -823,6 +823,61 @@ interface ColumnUpsertRequest {
823
823
  /** Expected dimension */
824
824
  dimension?: number;
825
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;
826
881
  /** Cluster status response */
827
882
  interface ClusterStatus {
828
883
  status: string;
@@ -1506,6 +1561,45 @@ declare class DakeraClient {
1506
1561
  rotateKey(keyId: string): Promise<ApiKey>;
1507
1562
  /** Get usage statistics for an API key */
1508
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;
1509
1603
  }
1510
1604
 
1511
1605
  /**
@@ -1547,4 +1641,4 @@ declare class TimeoutError extends DakeraError {
1547
1641
  constructor(message: string);
1548
1642
  }
1549
1643
 
1550
- 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 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 MemoryId, 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 SessionId, 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 VectorId, type VectorInput, type WarmCacheRequest, type WarmCacheResponse, type WarmingPriority, type WarmingTargetTier, agentId, memoryId, sessionId, vectorId };
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
@@ -1199,6 +1199,96 @@ var DakeraClient = class {
1199
1199
  async keyUsage(keyId) {
1200
1200
  return this.request("GET", `/v1/keys/${keyId}/usage`);
1201
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
+ }
1202
1292
  };
1203
1293
 
1204
1294
  // src/types.ts
package/dist/index.mjs CHANGED
@@ -1161,6 +1161,96 @@ 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
  };
1165
1255
 
1166
1256
  // src/types.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dakera-ai/dakera",
3
- "version": "0.3.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",