@dakera-ai/dakera 0.6.0 → 0.6.2
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 +42 -7
- package/dist/index.d.ts +42 -7
- package/dist/index.js +79 -22
- package/dist/index.mjs +77 -22
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -966,6 +966,8 @@ interface CrossAgentNetworkResponse {
|
|
|
966
966
|
nodes: AgentNetworkNode[];
|
|
967
967
|
edges: AgentNetworkEdge[];
|
|
968
968
|
stats: AgentNetworkStats;
|
|
969
|
+
/** Total number of memory nodes in the network (added in server v0.6.2). */
|
|
970
|
+
node_count: number;
|
|
969
971
|
}
|
|
970
972
|
/** Request body for POST /v1/knowledge/network/cross-agent */
|
|
971
973
|
interface CrossAgentNetworkRequest {
|
|
@@ -1744,6 +1746,16 @@ declare class DakeraClient {
|
|
|
1744
1746
|
* ```
|
|
1745
1747
|
*/
|
|
1746
1748
|
streamMemoryEvents(): AsyncGenerator<MemoryEvent>;
|
|
1749
|
+
/**
|
|
1750
|
+
* Return a URL with `?api_key=<key>` appended for use with browser-native
|
|
1751
|
+
* `EventSource`, which cannot send custom request headers.
|
|
1752
|
+
*
|
|
1753
|
+
* @example
|
|
1754
|
+
* ```ts
|
|
1755
|
+
* const src = new EventSource(client.sseUrl('/v1/namespaces/my-ns/events'));
|
|
1756
|
+
* ```
|
|
1757
|
+
*/
|
|
1758
|
+
sseUrl(path: string): string;
|
|
1747
1759
|
/** Low-level SSE streaming helper — parses the SSE wire format. */
|
|
1748
1760
|
private _streamSse;
|
|
1749
1761
|
/** Parse a single SSE event block into a {@link DakeraEvent}. */
|
|
@@ -1763,11 +1775,30 @@ declare class DakeraClient {
|
|
|
1763
1775
|
/**
|
|
1764
1776
|
* Dakera SDK Errors
|
|
1765
1777
|
*/
|
|
1778
|
+
/** Server error codes returned in structured error responses */
|
|
1779
|
+
declare enum ErrorCode {
|
|
1780
|
+
NAMESPACE_NOT_FOUND = "NAMESPACE_NOT_FOUND",
|
|
1781
|
+
VECTOR_NOT_FOUND = "VECTOR_NOT_FOUND",
|
|
1782
|
+
DIMENSION_MISMATCH = "DIMENSION_MISMATCH",
|
|
1783
|
+
EMPTY_VECTOR = "EMPTY_VECTOR",
|
|
1784
|
+
INVALID_REQUEST = "INVALID_REQUEST",
|
|
1785
|
+
STORAGE_ERROR = "STORAGE_ERROR",
|
|
1786
|
+
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
1787
|
+
QUOTA_EXCEEDED = "QUOTA_EXCEEDED",
|
|
1788
|
+
SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
|
|
1789
|
+
AUTHENTICATION_REQUIRED = "AUTHENTICATION_REQUIRED",
|
|
1790
|
+
INVALID_API_KEY = "INVALID_API_KEY",
|
|
1791
|
+
API_KEY_EXPIRED = "API_KEY_EXPIRED",
|
|
1792
|
+
INSUFFICIENT_SCOPE = "INSUFFICIENT_SCOPE",
|
|
1793
|
+
NAMESPACE_ACCESS_DENIED = "NAMESPACE_ACCESS_DENIED",
|
|
1794
|
+
UNKNOWN = "UNKNOWN"
|
|
1795
|
+
}
|
|
1766
1796
|
/** Base error class for all Dakera errors */
|
|
1767
1797
|
declare class DakeraError extends Error {
|
|
1768
1798
|
readonly statusCode?: number;
|
|
1769
1799
|
readonly responseBody?: unknown;
|
|
1770
|
-
|
|
1800
|
+
readonly code?: ErrorCode;
|
|
1801
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, code?: ErrorCode);
|
|
1771
1802
|
}
|
|
1772
1803
|
/** Raised when unable to connect to Dakera server */
|
|
1773
1804
|
declare class ConnectionError extends DakeraError {
|
|
@@ -1775,28 +1806,32 @@ declare class ConnectionError extends DakeraError {
|
|
|
1775
1806
|
}
|
|
1776
1807
|
/** Raised when a requested resource is not found */
|
|
1777
1808
|
declare class NotFoundError extends DakeraError {
|
|
1778
|
-
constructor(message: string, statusCode?: number, responseBody?: unknown);
|
|
1809
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, code?: ErrorCode);
|
|
1779
1810
|
}
|
|
1780
1811
|
/** Raised when request validation fails */
|
|
1781
1812
|
declare class ValidationError extends DakeraError {
|
|
1782
|
-
constructor(message: string, statusCode?: number, responseBody?: unknown);
|
|
1813
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, code?: ErrorCode);
|
|
1783
1814
|
}
|
|
1784
1815
|
/** Raised when rate limit is exceeded */
|
|
1785
1816
|
declare class RateLimitError extends DakeraError {
|
|
1786
1817
|
readonly retryAfter?: number;
|
|
1787
|
-
constructor(message: string, statusCode?: number, responseBody?: unknown, retryAfter?: number);
|
|
1818
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, retryAfter?: number, code?: ErrorCode);
|
|
1788
1819
|
}
|
|
1789
1820
|
/** Raised when the server returns a 5xx error */
|
|
1790
1821
|
declare class ServerError extends DakeraError {
|
|
1791
|
-
constructor(message: string, statusCode?: number, responseBody?: unknown);
|
|
1822
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, code?: ErrorCode);
|
|
1792
1823
|
}
|
|
1793
1824
|
/** Raised when authentication fails */
|
|
1794
1825
|
declare class AuthenticationError extends DakeraError {
|
|
1795
|
-
constructor(message: string, statusCode?: number, responseBody?: unknown);
|
|
1826
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, code?: ErrorCode);
|
|
1827
|
+
}
|
|
1828
|
+
/** Raised when authorization fails (403 Forbidden) */
|
|
1829
|
+
declare class AuthorizationError extends DakeraError {
|
|
1830
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, code?: ErrorCode);
|
|
1796
1831
|
}
|
|
1797
1832
|
/** Raised when a request times out */
|
|
1798
1833
|
declare class TimeoutError extends DakeraError {
|
|
1799
1834
|
constructor(message: string);
|
|
1800
1835
|
}
|
|
1801
1836
|
|
|
1802
|
-
export { type AccessPatternHint, type AgentId, type AgentNetworkEdge, type AgentNetworkInfo, type AgentNetworkNode, type AgentNetworkStats, 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, type ConfigureNamespaceRequest, type ConfigureNamespaceResponse, ConnectionError, type ConsolidateRequest, type ConsolidateResponse, type CreateKeyRequest, type CrossAgentNetworkRequest, type CrossAgentNetworkResponse, 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 MemoryEvent, 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 };
|
|
1837
|
+
export { type AccessPatternHint, type AgentId, type AgentNetworkEdge, type AgentNetworkInfo, type AgentNetworkNode, type AgentNetworkStats, type AgentStats, type AgentSummary, type AggregationGroup, type AggregationRequest, type AggregationResponse, type AnalyticsOptions, type AnalyticsOverview, type ApiKey, AuthenticationError, AuthorizationError, type BackupInfo, type BatchQuerySpec, type BatchTextQueryOptions, type BatchTextQueryResponse, type Branded, type CacheStats, type ClientOptions, type ClusterNode, type ClusterStatus, type ColumnUpsertRequest, type ConfigureNamespaceRequest, type ConfigureNamespaceResponse, ConnectionError, type ConsolidateRequest, type ConsolidateResponse, type CreateKeyRequest, type CrossAgentNetworkRequest, type CrossAgentNetworkResponse, DakeraClient, DakeraError, type DakeraEvent, type DeduplicateRequest, type DeduplicateResponse, type DeleteOptions, type DeleteResponse, type DistanceMetric, type Document, type DocumentInput, type EmbeddingModel, ErrorCode, 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 MemoryEvent, 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
|
@@ -966,6 +966,8 @@ interface CrossAgentNetworkResponse {
|
|
|
966
966
|
nodes: AgentNetworkNode[];
|
|
967
967
|
edges: AgentNetworkEdge[];
|
|
968
968
|
stats: AgentNetworkStats;
|
|
969
|
+
/** Total number of memory nodes in the network (added in server v0.6.2). */
|
|
970
|
+
node_count: number;
|
|
969
971
|
}
|
|
970
972
|
/** Request body for POST /v1/knowledge/network/cross-agent */
|
|
971
973
|
interface CrossAgentNetworkRequest {
|
|
@@ -1744,6 +1746,16 @@ declare class DakeraClient {
|
|
|
1744
1746
|
* ```
|
|
1745
1747
|
*/
|
|
1746
1748
|
streamMemoryEvents(): AsyncGenerator<MemoryEvent>;
|
|
1749
|
+
/**
|
|
1750
|
+
* Return a URL with `?api_key=<key>` appended for use with browser-native
|
|
1751
|
+
* `EventSource`, which cannot send custom request headers.
|
|
1752
|
+
*
|
|
1753
|
+
* @example
|
|
1754
|
+
* ```ts
|
|
1755
|
+
* const src = new EventSource(client.sseUrl('/v1/namespaces/my-ns/events'));
|
|
1756
|
+
* ```
|
|
1757
|
+
*/
|
|
1758
|
+
sseUrl(path: string): string;
|
|
1747
1759
|
/** Low-level SSE streaming helper — parses the SSE wire format. */
|
|
1748
1760
|
private _streamSse;
|
|
1749
1761
|
/** Parse a single SSE event block into a {@link DakeraEvent}. */
|
|
@@ -1763,11 +1775,30 @@ declare class DakeraClient {
|
|
|
1763
1775
|
/**
|
|
1764
1776
|
* Dakera SDK Errors
|
|
1765
1777
|
*/
|
|
1778
|
+
/** Server error codes returned in structured error responses */
|
|
1779
|
+
declare enum ErrorCode {
|
|
1780
|
+
NAMESPACE_NOT_FOUND = "NAMESPACE_NOT_FOUND",
|
|
1781
|
+
VECTOR_NOT_FOUND = "VECTOR_NOT_FOUND",
|
|
1782
|
+
DIMENSION_MISMATCH = "DIMENSION_MISMATCH",
|
|
1783
|
+
EMPTY_VECTOR = "EMPTY_VECTOR",
|
|
1784
|
+
INVALID_REQUEST = "INVALID_REQUEST",
|
|
1785
|
+
STORAGE_ERROR = "STORAGE_ERROR",
|
|
1786
|
+
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
1787
|
+
QUOTA_EXCEEDED = "QUOTA_EXCEEDED",
|
|
1788
|
+
SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
|
|
1789
|
+
AUTHENTICATION_REQUIRED = "AUTHENTICATION_REQUIRED",
|
|
1790
|
+
INVALID_API_KEY = "INVALID_API_KEY",
|
|
1791
|
+
API_KEY_EXPIRED = "API_KEY_EXPIRED",
|
|
1792
|
+
INSUFFICIENT_SCOPE = "INSUFFICIENT_SCOPE",
|
|
1793
|
+
NAMESPACE_ACCESS_DENIED = "NAMESPACE_ACCESS_DENIED",
|
|
1794
|
+
UNKNOWN = "UNKNOWN"
|
|
1795
|
+
}
|
|
1766
1796
|
/** Base error class for all Dakera errors */
|
|
1767
1797
|
declare class DakeraError extends Error {
|
|
1768
1798
|
readonly statusCode?: number;
|
|
1769
1799
|
readonly responseBody?: unknown;
|
|
1770
|
-
|
|
1800
|
+
readonly code?: ErrorCode;
|
|
1801
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, code?: ErrorCode);
|
|
1771
1802
|
}
|
|
1772
1803
|
/** Raised when unable to connect to Dakera server */
|
|
1773
1804
|
declare class ConnectionError extends DakeraError {
|
|
@@ -1775,28 +1806,32 @@ declare class ConnectionError extends DakeraError {
|
|
|
1775
1806
|
}
|
|
1776
1807
|
/** Raised when a requested resource is not found */
|
|
1777
1808
|
declare class NotFoundError extends DakeraError {
|
|
1778
|
-
constructor(message: string, statusCode?: number, responseBody?: unknown);
|
|
1809
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, code?: ErrorCode);
|
|
1779
1810
|
}
|
|
1780
1811
|
/** Raised when request validation fails */
|
|
1781
1812
|
declare class ValidationError extends DakeraError {
|
|
1782
|
-
constructor(message: string, statusCode?: number, responseBody?: unknown);
|
|
1813
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, code?: ErrorCode);
|
|
1783
1814
|
}
|
|
1784
1815
|
/** Raised when rate limit is exceeded */
|
|
1785
1816
|
declare class RateLimitError extends DakeraError {
|
|
1786
1817
|
readonly retryAfter?: number;
|
|
1787
|
-
constructor(message: string, statusCode?: number, responseBody?: unknown, retryAfter?: number);
|
|
1818
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, retryAfter?: number, code?: ErrorCode);
|
|
1788
1819
|
}
|
|
1789
1820
|
/** Raised when the server returns a 5xx error */
|
|
1790
1821
|
declare class ServerError extends DakeraError {
|
|
1791
|
-
constructor(message: string, statusCode?: number, responseBody?: unknown);
|
|
1822
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, code?: ErrorCode);
|
|
1792
1823
|
}
|
|
1793
1824
|
/** Raised when authentication fails */
|
|
1794
1825
|
declare class AuthenticationError extends DakeraError {
|
|
1795
|
-
constructor(message: string, statusCode?: number, responseBody?: unknown);
|
|
1826
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, code?: ErrorCode);
|
|
1827
|
+
}
|
|
1828
|
+
/** Raised when authorization fails (403 Forbidden) */
|
|
1829
|
+
declare class AuthorizationError extends DakeraError {
|
|
1830
|
+
constructor(message: string, statusCode?: number, responseBody?: unknown, code?: ErrorCode);
|
|
1796
1831
|
}
|
|
1797
1832
|
/** Raised when a request times out */
|
|
1798
1833
|
declare class TimeoutError extends DakeraError {
|
|
1799
1834
|
constructor(message: string);
|
|
1800
1835
|
}
|
|
1801
1836
|
|
|
1802
|
-
export { type AccessPatternHint, type AgentId, type AgentNetworkEdge, type AgentNetworkInfo, type AgentNetworkNode, type AgentNetworkStats, 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, type ConfigureNamespaceRequest, type ConfigureNamespaceResponse, ConnectionError, type ConsolidateRequest, type ConsolidateResponse, type CreateKeyRequest, type CrossAgentNetworkRequest, type CrossAgentNetworkResponse, 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 MemoryEvent, 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 };
|
|
1837
|
+
export { type AccessPatternHint, type AgentId, type AgentNetworkEdge, type AgentNetworkInfo, type AgentNetworkNode, type AgentNetworkStats, type AgentStats, type AgentSummary, type AggregationGroup, type AggregationRequest, type AggregationResponse, type AnalyticsOptions, type AnalyticsOverview, type ApiKey, AuthenticationError, AuthorizationError, type BackupInfo, type BatchQuerySpec, type BatchTextQueryOptions, type BatchTextQueryResponse, type Branded, type CacheStats, type ClientOptions, type ClusterNode, type ClusterStatus, type ColumnUpsertRequest, type ConfigureNamespaceRequest, type ConfigureNamespaceResponse, ConnectionError, type ConsolidateRequest, type ConsolidateResponse, type CreateKeyRequest, type CrossAgentNetworkRequest, type CrossAgentNetworkResponse, DakeraClient, DakeraError, type DakeraEvent, type DeduplicateRequest, type DeduplicateResponse, type DeleteOptions, type DeleteResponse, type DistanceMetric, type Document, type DocumentInput, type EmbeddingModel, ErrorCode, 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 MemoryEvent, 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
|
@@ -21,9 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
AuthenticationError: () => AuthenticationError,
|
|
24
|
+
AuthorizationError: () => AuthorizationError,
|
|
24
25
|
ConnectionError: () => ConnectionError,
|
|
25
26
|
DakeraClient: () => DakeraClient,
|
|
26
27
|
DakeraError: () => DakeraError,
|
|
28
|
+
ErrorCode: () => ErrorCode,
|
|
27
29
|
NotFoundError: () => NotFoundError,
|
|
28
30
|
RateLimitError: () => RateLimitError,
|
|
29
31
|
ServerError: () => ServerError,
|
|
@@ -37,14 +39,34 @@ __export(index_exports, {
|
|
|
37
39
|
module.exports = __toCommonJS(index_exports);
|
|
38
40
|
|
|
39
41
|
// src/errors.ts
|
|
42
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
43
|
+
ErrorCode2["NAMESPACE_NOT_FOUND"] = "NAMESPACE_NOT_FOUND";
|
|
44
|
+
ErrorCode2["VECTOR_NOT_FOUND"] = "VECTOR_NOT_FOUND";
|
|
45
|
+
ErrorCode2["DIMENSION_MISMATCH"] = "DIMENSION_MISMATCH";
|
|
46
|
+
ErrorCode2["EMPTY_VECTOR"] = "EMPTY_VECTOR";
|
|
47
|
+
ErrorCode2["INVALID_REQUEST"] = "INVALID_REQUEST";
|
|
48
|
+
ErrorCode2["STORAGE_ERROR"] = "STORAGE_ERROR";
|
|
49
|
+
ErrorCode2["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
|
50
|
+
ErrorCode2["QUOTA_EXCEEDED"] = "QUOTA_EXCEEDED";
|
|
51
|
+
ErrorCode2["SERVICE_UNAVAILABLE"] = "SERVICE_UNAVAILABLE";
|
|
52
|
+
ErrorCode2["AUTHENTICATION_REQUIRED"] = "AUTHENTICATION_REQUIRED";
|
|
53
|
+
ErrorCode2["INVALID_API_KEY"] = "INVALID_API_KEY";
|
|
54
|
+
ErrorCode2["API_KEY_EXPIRED"] = "API_KEY_EXPIRED";
|
|
55
|
+
ErrorCode2["INSUFFICIENT_SCOPE"] = "INSUFFICIENT_SCOPE";
|
|
56
|
+
ErrorCode2["NAMESPACE_ACCESS_DENIED"] = "NAMESPACE_ACCESS_DENIED";
|
|
57
|
+
ErrorCode2["UNKNOWN"] = "UNKNOWN";
|
|
58
|
+
return ErrorCode2;
|
|
59
|
+
})(ErrorCode || {});
|
|
40
60
|
var DakeraError = class _DakeraError extends Error {
|
|
41
61
|
statusCode;
|
|
42
62
|
responseBody;
|
|
43
|
-
|
|
63
|
+
code;
|
|
64
|
+
constructor(message, statusCode, responseBody, code) {
|
|
44
65
|
super(message);
|
|
45
66
|
this.name = "DakeraError";
|
|
46
67
|
this.statusCode = statusCode;
|
|
47
68
|
this.responseBody = responseBody;
|
|
69
|
+
this.code = code;
|
|
48
70
|
Object.setPrototypeOf(this, _DakeraError.prototype);
|
|
49
71
|
}
|
|
50
72
|
};
|
|
@@ -56,42 +78,49 @@ var ConnectionError = class _ConnectionError extends DakeraError {
|
|
|
56
78
|
}
|
|
57
79
|
};
|
|
58
80
|
var NotFoundError = class _NotFoundError extends DakeraError {
|
|
59
|
-
constructor(message, statusCode, responseBody) {
|
|
60
|
-
super(message, statusCode, responseBody);
|
|
81
|
+
constructor(message, statusCode, responseBody, code) {
|
|
82
|
+
super(message, statusCode, responseBody, code);
|
|
61
83
|
this.name = "NotFoundError";
|
|
62
84
|
Object.setPrototypeOf(this, _NotFoundError.prototype);
|
|
63
85
|
}
|
|
64
86
|
};
|
|
65
87
|
var ValidationError = class _ValidationError extends DakeraError {
|
|
66
|
-
constructor(message, statusCode, responseBody) {
|
|
67
|
-
super(message, statusCode, responseBody);
|
|
88
|
+
constructor(message, statusCode, responseBody, code) {
|
|
89
|
+
super(message, statusCode, responseBody, code);
|
|
68
90
|
this.name = "ValidationError";
|
|
69
91
|
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
70
92
|
}
|
|
71
93
|
};
|
|
72
94
|
var RateLimitError = class _RateLimitError extends DakeraError {
|
|
73
95
|
retryAfter;
|
|
74
|
-
constructor(message, statusCode, responseBody, retryAfter) {
|
|
75
|
-
super(message, statusCode, responseBody);
|
|
96
|
+
constructor(message, statusCode, responseBody, retryAfter, code) {
|
|
97
|
+
super(message, statusCode, responseBody, code);
|
|
76
98
|
this.name = "RateLimitError";
|
|
77
99
|
this.retryAfter = retryAfter;
|
|
78
100
|
Object.setPrototypeOf(this, _RateLimitError.prototype);
|
|
79
101
|
}
|
|
80
102
|
};
|
|
81
103
|
var ServerError = class _ServerError extends DakeraError {
|
|
82
|
-
constructor(message, statusCode, responseBody) {
|
|
83
|
-
super(message, statusCode, responseBody);
|
|
104
|
+
constructor(message, statusCode, responseBody, code) {
|
|
105
|
+
super(message, statusCode, responseBody, code);
|
|
84
106
|
this.name = "ServerError";
|
|
85
107
|
Object.setPrototypeOf(this, _ServerError.prototype);
|
|
86
108
|
}
|
|
87
109
|
};
|
|
88
110
|
var AuthenticationError = class _AuthenticationError extends DakeraError {
|
|
89
|
-
constructor(message, statusCode, responseBody) {
|
|
90
|
-
super(message, statusCode, responseBody);
|
|
111
|
+
constructor(message, statusCode, responseBody, code) {
|
|
112
|
+
super(message, statusCode, responseBody, code);
|
|
91
113
|
this.name = "AuthenticationError";
|
|
92
114
|
Object.setPrototypeOf(this, _AuthenticationError.prototype);
|
|
93
115
|
}
|
|
94
116
|
};
|
|
117
|
+
var AuthorizationError = class _AuthorizationError extends DakeraError {
|
|
118
|
+
constructor(message, statusCode, responseBody, code) {
|
|
119
|
+
super(message, statusCode, responseBody, code);
|
|
120
|
+
this.name = "AuthorizationError";
|
|
121
|
+
Object.setPrototypeOf(this, _AuthorizationError.prototype);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
95
124
|
var TimeoutError = class _TimeoutError extends DakeraError {
|
|
96
125
|
constructor(message) {
|
|
97
126
|
super(message);
|
|
@@ -101,6 +130,12 @@ var TimeoutError = class _TimeoutError extends DakeraError {
|
|
|
101
130
|
};
|
|
102
131
|
|
|
103
132
|
// src/client.ts
|
|
133
|
+
function parseErrorCode(raw) {
|
|
134
|
+
if (typeof raw === "string" && raw in ErrorCode) {
|
|
135
|
+
return raw;
|
|
136
|
+
}
|
|
137
|
+
return "UNKNOWN" /* UNKNOWN */;
|
|
138
|
+
}
|
|
104
139
|
var DEFAULT_OPTIONS = {
|
|
105
140
|
baseUrl: "http://localhost:3000",
|
|
106
141
|
timeout: 3e4,
|
|
@@ -183,27 +218,33 @@ var DakeraClient = class {
|
|
|
183
218
|
return body;
|
|
184
219
|
}
|
|
185
220
|
const errorMessage = typeof body === "object" && body !== null && "error" in body ? String(body.error) : typeof body === "string" ? body : `HTTP ${response.status}`;
|
|
221
|
+
const code = parseErrorCode(
|
|
222
|
+
typeof body === "object" && body !== null && "code" in body ? body.code : void 0
|
|
223
|
+
);
|
|
186
224
|
switch (response.status) {
|
|
187
225
|
case 400:
|
|
188
|
-
throw new ValidationError(errorMessage, response.status, body);
|
|
226
|
+
throw new ValidationError(errorMessage, response.status, body, code);
|
|
189
227
|
case 401:
|
|
190
|
-
throw new AuthenticationError("Authentication failed", response.status, body);
|
|
228
|
+
throw new AuthenticationError("Authentication failed", response.status, body, code);
|
|
229
|
+
case 403:
|
|
230
|
+
throw new AuthorizationError(errorMessage, response.status, body, code);
|
|
191
231
|
case 404:
|
|
192
|
-
throw new NotFoundError(errorMessage, response.status, body);
|
|
232
|
+
throw new NotFoundError(errorMessage, response.status, body, code);
|
|
193
233
|
case 429: {
|
|
194
234
|
const retryAfter = response.headers.get("Retry-After");
|
|
195
235
|
throw new RateLimitError(
|
|
196
236
|
"Rate limit exceeded",
|
|
197
237
|
response.status,
|
|
198
238
|
body,
|
|
199
|
-
retryAfter ? parseInt(retryAfter, 10) : void 0
|
|
239
|
+
retryAfter ? parseInt(retryAfter, 10) : void 0,
|
|
240
|
+
code
|
|
200
241
|
);
|
|
201
242
|
}
|
|
202
243
|
default:
|
|
203
244
|
if (response.status >= 500) {
|
|
204
|
-
throw new ServerError(errorMessage, response.status, body);
|
|
245
|
+
throw new ServerError(errorMessage, response.status, body, code);
|
|
205
246
|
}
|
|
206
|
-
throw new DakeraError(errorMessage, response.status, body);
|
|
247
|
+
throw new DakeraError(errorMessage, response.status, body, code);
|
|
207
248
|
}
|
|
208
249
|
}
|
|
209
250
|
sleep(ms) {
|
|
@@ -1300,15 +1341,29 @@ var DakeraClient = class {
|
|
|
1300
1341
|
const url = `${this.baseUrl}/v1/events/stream`;
|
|
1301
1342
|
yield* this._streamSseMemory(url);
|
|
1302
1343
|
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Return a URL with `?api_key=<key>` appended for use with browser-native
|
|
1346
|
+
* `EventSource`, which cannot send custom request headers.
|
|
1347
|
+
*
|
|
1348
|
+
* @example
|
|
1349
|
+
* ```ts
|
|
1350
|
+
* const src = new EventSource(client.sseUrl('/v1/namespaces/my-ns/events'));
|
|
1351
|
+
* ```
|
|
1352
|
+
*/
|
|
1353
|
+
sseUrl(path) {
|
|
1354
|
+
const base = `${this.baseUrl}${path}`;
|
|
1355
|
+
if (!this.apiKey) return base;
|
|
1356
|
+
const sep = base.includes("?") ? "&" : "?";
|
|
1357
|
+
return `${base}${sep}api_key=${encodeURIComponent(this.apiKey)}`;
|
|
1358
|
+
}
|
|
1303
1359
|
/** Low-level SSE streaming helper — parses the SSE wire format. */
|
|
1304
1360
|
async *_streamSse(url) {
|
|
1361
|
+
const sseUrl = this.apiKey ? `${url}${url.includes("?") ? "&" : "?"}api_key=${encodeURIComponent(this.apiKey)}` : url;
|
|
1305
1362
|
const headers = {
|
|
1306
|
-
...this.headers,
|
|
1307
|
-
// includes Authorization and any custom headers
|
|
1308
1363
|
Accept: "text/event-stream",
|
|
1309
1364
|
"Cache-Control": "no-cache"
|
|
1310
1365
|
};
|
|
1311
|
-
const response = await fetch(
|
|
1366
|
+
const response = await fetch(sseUrl, { headers });
|
|
1312
1367
|
if (!response.ok || !response.body) {
|
|
1313
1368
|
throw new Error(`SSE connection failed: ${response.status} ${response.statusText}`);
|
|
1314
1369
|
}
|
|
@@ -1354,12 +1409,12 @@ var DakeraClient = class {
|
|
|
1354
1409
|
* so callers receive a fully-populated {@link MemoryEvent}.
|
|
1355
1410
|
*/
|
|
1356
1411
|
async *_streamSseMemory(url) {
|
|
1412
|
+
const sseUrl = this.apiKey ? `${url}${url.includes("?") ? "&" : "?"}api_key=${encodeURIComponent(this.apiKey)}` : url;
|
|
1357
1413
|
const headers = {
|
|
1358
|
-
...this.headers,
|
|
1359
1414
|
Accept: "text/event-stream",
|
|
1360
1415
|
"Cache-Control": "no-cache"
|
|
1361
1416
|
};
|
|
1362
|
-
const response = await fetch(
|
|
1417
|
+
const response = await fetch(sseUrl, { headers });
|
|
1363
1418
|
if (!response.ok || !response.body) {
|
|
1364
1419
|
throw new Error(`SSE connection failed: ${response.status} ${response.statusText}`);
|
|
1365
1420
|
}
|
|
@@ -1424,9 +1479,11 @@ function sessionId(id) {
|
|
|
1424
1479
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1425
1480
|
0 && (module.exports = {
|
|
1426
1481
|
AuthenticationError,
|
|
1482
|
+
AuthorizationError,
|
|
1427
1483
|
ConnectionError,
|
|
1428
1484
|
DakeraClient,
|
|
1429
1485
|
DakeraError,
|
|
1486
|
+
ErrorCode,
|
|
1430
1487
|
NotFoundError,
|
|
1431
1488
|
RateLimitError,
|
|
1432
1489
|
ServerError,
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
// src/errors.ts
|
|
2
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
3
|
+
ErrorCode2["NAMESPACE_NOT_FOUND"] = "NAMESPACE_NOT_FOUND";
|
|
4
|
+
ErrorCode2["VECTOR_NOT_FOUND"] = "VECTOR_NOT_FOUND";
|
|
5
|
+
ErrorCode2["DIMENSION_MISMATCH"] = "DIMENSION_MISMATCH";
|
|
6
|
+
ErrorCode2["EMPTY_VECTOR"] = "EMPTY_VECTOR";
|
|
7
|
+
ErrorCode2["INVALID_REQUEST"] = "INVALID_REQUEST";
|
|
8
|
+
ErrorCode2["STORAGE_ERROR"] = "STORAGE_ERROR";
|
|
9
|
+
ErrorCode2["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
|
10
|
+
ErrorCode2["QUOTA_EXCEEDED"] = "QUOTA_EXCEEDED";
|
|
11
|
+
ErrorCode2["SERVICE_UNAVAILABLE"] = "SERVICE_UNAVAILABLE";
|
|
12
|
+
ErrorCode2["AUTHENTICATION_REQUIRED"] = "AUTHENTICATION_REQUIRED";
|
|
13
|
+
ErrorCode2["INVALID_API_KEY"] = "INVALID_API_KEY";
|
|
14
|
+
ErrorCode2["API_KEY_EXPIRED"] = "API_KEY_EXPIRED";
|
|
15
|
+
ErrorCode2["INSUFFICIENT_SCOPE"] = "INSUFFICIENT_SCOPE";
|
|
16
|
+
ErrorCode2["NAMESPACE_ACCESS_DENIED"] = "NAMESPACE_ACCESS_DENIED";
|
|
17
|
+
ErrorCode2["UNKNOWN"] = "UNKNOWN";
|
|
18
|
+
return ErrorCode2;
|
|
19
|
+
})(ErrorCode || {});
|
|
2
20
|
var DakeraError = class _DakeraError extends Error {
|
|
3
21
|
statusCode;
|
|
4
22
|
responseBody;
|
|
5
|
-
|
|
23
|
+
code;
|
|
24
|
+
constructor(message, statusCode, responseBody, code) {
|
|
6
25
|
super(message);
|
|
7
26
|
this.name = "DakeraError";
|
|
8
27
|
this.statusCode = statusCode;
|
|
9
28
|
this.responseBody = responseBody;
|
|
29
|
+
this.code = code;
|
|
10
30
|
Object.setPrototypeOf(this, _DakeraError.prototype);
|
|
11
31
|
}
|
|
12
32
|
};
|
|
@@ -18,42 +38,49 @@ var ConnectionError = class _ConnectionError extends DakeraError {
|
|
|
18
38
|
}
|
|
19
39
|
};
|
|
20
40
|
var NotFoundError = class _NotFoundError extends DakeraError {
|
|
21
|
-
constructor(message, statusCode, responseBody) {
|
|
22
|
-
super(message, statusCode, responseBody);
|
|
41
|
+
constructor(message, statusCode, responseBody, code) {
|
|
42
|
+
super(message, statusCode, responseBody, code);
|
|
23
43
|
this.name = "NotFoundError";
|
|
24
44
|
Object.setPrototypeOf(this, _NotFoundError.prototype);
|
|
25
45
|
}
|
|
26
46
|
};
|
|
27
47
|
var ValidationError = class _ValidationError extends DakeraError {
|
|
28
|
-
constructor(message, statusCode, responseBody) {
|
|
29
|
-
super(message, statusCode, responseBody);
|
|
48
|
+
constructor(message, statusCode, responseBody, code) {
|
|
49
|
+
super(message, statusCode, responseBody, code);
|
|
30
50
|
this.name = "ValidationError";
|
|
31
51
|
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
32
52
|
}
|
|
33
53
|
};
|
|
34
54
|
var RateLimitError = class _RateLimitError extends DakeraError {
|
|
35
55
|
retryAfter;
|
|
36
|
-
constructor(message, statusCode, responseBody, retryAfter) {
|
|
37
|
-
super(message, statusCode, responseBody);
|
|
56
|
+
constructor(message, statusCode, responseBody, retryAfter, code) {
|
|
57
|
+
super(message, statusCode, responseBody, code);
|
|
38
58
|
this.name = "RateLimitError";
|
|
39
59
|
this.retryAfter = retryAfter;
|
|
40
60
|
Object.setPrototypeOf(this, _RateLimitError.prototype);
|
|
41
61
|
}
|
|
42
62
|
};
|
|
43
63
|
var ServerError = class _ServerError extends DakeraError {
|
|
44
|
-
constructor(message, statusCode, responseBody) {
|
|
45
|
-
super(message, statusCode, responseBody);
|
|
64
|
+
constructor(message, statusCode, responseBody, code) {
|
|
65
|
+
super(message, statusCode, responseBody, code);
|
|
46
66
|
this.name = "ServerError";
|
|
47
67
|
Object.setPrototypeOf(this, _ServerError.prototype);
|
|
48
68
|
}
|
|
49
69
|
};
|
|
50
70
|
var AuthenticationError = class _AuthenticationError extends DakeraError {
|
|
51
|
-
constructor(message, statusCode, responseBody) {
|
|
52
|
-
super(message, statusCode, responseBody);
|
|
71
|
+
constructor(message, statusCode, responseBody, code) {
|
|
72
|
+
super(message, statusCode, responseBody, code);
|
|
53
73
|
this.name = "AuthenticationError";
|
|
54
74
|
Object.setPrototypeOf(this, _AuthenticationError.prototype);
|
|
55
75
|
}
|
|
56
76
|
};
|
|
77
|
+
var AuthorizationError = class _AuthorizationError extends DakeraError {
|
|
78
|
+
constructor(message, statusCode, responseBody, code) {
|
|
79
|
+
super(message, statusCode, responseBody, code);
|
|
80
|
+
this.name = "AuthorizationError";
|
|
81
|
+
Object.setPrototypeOf(this, _AuthorizationError.prototype);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
57
84
|
var TimeoutError = class _TimeoutError extends DakeraError {
|
|
58
85
|
constructor(message) {
|
|
59
86
|
super(message);
|
|
@@ -63,6 +90,12 @@ var TimeoutError = class _TimeoutError extends DakeraError {
|
|
|
63
90
|
};
|
|
64
91
|
|
|
65
92
|
// src/client.ts
|
|
93
|
+
function parseErrorCode(raw) {
|
|
94
|
+
if (typeof raw === "string" && raw in ErrorCode) {
|
|
95
|
+
return raw;
|
|
96
|
+
}
|
|
97
|
+
return "UNKNOWN" /* UNKNOWN */;
|
|
98
|
+
}
|
|
66
99
|
var DEFAULT_OPTIONS = {
|
|
67
100
|
baseUrl: "http://localhost:3000",
|
|
68
101
|
timeout: 3e4,
|
|
@@ -145,27 +178,33 @@ var DakeraClient = class {
|
|
|
145
178
|
return body;
|
|
146
179
|
}
|
|
147
180
|
const errorMessage = typeof body === "object" && body !== null && "error" in body ? String(body.error) : typeof body === "string" ? body : `HTTP ${response.status}`;
|
|
181
|
+
const code = parseErrorCode(
|
|
182
|
+
typeof body === "object" && body !== null && "code" in body ? body.code : void 0
|
|
183
|
+
);
|
|
148
184
|
switch (response.status) {
|
|
149
185
|
case 400:
|
|
150
|
-
throw new ValidationError(errorMessage, response.status, body);
|
|
186
|
+
throw new ValidationError(errorMessage, response.status, body, code);
|
|
151
187
|
case 401:
|
|
152
|
-
throw new AuthenticationError("Authentication failed", response.status, body);
|
|
188
|
+
throw new AuthenticationError("Authentication failed", response.status, body, code);
|
|
189
|
+
case 403:
|
|
190
|
+
throw new AuthorizationError(errorMessage, response.status, body, code);
|
|
153
191
|
case 404:
|
|
154
|
-
throw new NotFoundError(errorMessage, response.status, body);
|
|
192
|
+
throw new NotFoundError(errorMessage, response.status, body, code);
|
|
155
193
|
case 429: {
|
|
156
194
|
const retryAfter = response.headers.get("Retry-After");
|
|
157
195
|
throw new RateLimitError(
|
|
158
196
|
"Rate limit exceeded",
|
|
159
197
|
response.status,
|
|
160
198
|
body,
|
|
161
|
-
retryAfter ? parseInt(retryAfter, 10) : void 0
|
|
199
|
+
retryAfter ? parseInt(retryAfter, 10) : void 0,
|
|
200
|
+
code
|
|
162
201
|
);
|
|
163
202
|
}
|
|
164
203
|
default:
|
|
165
204
|
if (response.status >= 500) {
|
|
166
|
-
throw new ServerError(errorMessage, response.status, body);
|
|
205
|
+
throw new ServerError(errorMessage, response.status, body, code);
|
|
167
206
|
}
|
|
168
|
-
throw new DakeraError(errorMessage, response.status, body);
|
|
207
|
+
throw new DakeraError(errorMessage, response.status, body, code);
|
|
169
208
|
}
|
|
170
209
|
}
|
|
171
210
|
sleep(ms) {
|
|
@@ -1262,15 +1301,29 @@ var DakeraClient = class {
|
|
|
1262
1301
|
const url = `${this.baseUrl}/v1/events/stream`;
|
|
1263
1302
|
yield* this._streamSseMemory(url);
|
|
1264
1303
|
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Return a URL with `?api_key=<key>` appended for use with browser-native
|
|
1306
|
+
* `EventSource`, which cannot send custom request headers.
|
|
1307
|
+
*
|
|
1308
|
+
* @example
|
|
1309
|
+
* ```ts
|
|
1310
|
+
* const src = new EventSource(client.sseUrl('/v1/namespaces/my-ns/events'));
|
|
1311
|
+
* ```
|
|
1312
|
+
*/
|
|
1313
|
+
sseUrl(path) {
|
|
1314
|
+
const base = `${this.baseUrl}${path}`;
|
|
1315
|
+
if (!this.apiKey) return base;
|
|
1316
|
+
const sep = base.includes("?") ? "&" : "?";
|
|
1317
|
+
return `${base}${sep}api_key=${encodeURIComponent(this.apiKey)}`;
|
|
1318
|
+
}
|
|
1265
1319
|
/** Low-level SSE streaming helper — parses the SSE wire format. */
|
|
1266
1320
|
async *_streamSse(url) {
|
|
1321
|
+
const sseUrl = this.apiKey ? `${url}${url.includes("?") ? "&" : "?"}api_key=${encodeURIComponent(this.apiKey)}` : url;
|
|
1267
1322
|
const headers = {
|
|
1268
|
-
...this.headers,
|
|
1269
|
-
// includes Authorization and any custom headers
|
|
1270
1323
|
Accept: "text/event-stream",
|
|
1271
1324
|
"Cache-Control": "no-cache"
|
|
1272
1325
|
};
|
|
1273
|
-
const response = await fetch(
|
|
1326
|
+
const response = await fetch(sseUrl, { headers });
|
|
1274
1327
|
if (!response.ok || !response.body) {
|
|
1275
1328
|
throw new Error(`SSE connection failed: ${response.status} ${response.statusText}`);
|
|
1276
1329
|
}
|
|
@@ -1316,12 +1369,12 @@ var DakeraClient = class {
|
|
|
1316
1369
|
* so callers receive a fully-populated {@link MemoryEvent}.
|
|
1317
1370
|
*/
|
|
1318
1371
|
async *_streamSseMemory(url) {
|
|
1372
|
+
const sseUrl = this.apiKey ? `${url}${url.includes("?") ? "&" : "?"}api_key=${encodeURIComponent(this.apiKey)}` : url;
|
|
1319
1373
|
const headers = {
|
|
1320
|
-
...this.headers,
|
|
1321
1374
|
Accept: "text/event-stream",
|
|
1322
1375
|
"Cache-Control": "no-cache"
|
|
1323
1376
|
};
|
|
1324
|
-
const response = await fetch(
|
|
1377
|
+
const response = await fetch(sseUrl, { headers });
|
|
1325
1378
|
if (!response.ok || !response.body) {
|
|
1326
1379
|
throw new Error(`SSE connection failed: ${response.status} ${response.statusText}`);
|
|
1327
1380
|
}
|
|
@@ -1385,9 +1438,11 @@ function sessionId(id) {
|
|
|
1385
1438
|
}
|
|
1386
1439
|
export {
|
|
1387
1440
|
AuthenticationError,
|
|
1441
|
+
AuthorizationError,
|
|
1388
1442
|
ConnectionError,
|
|
1389
1443
|
DakeraClient,
|
|
1390
1444
|
DakeraError,
|
|
1445
|
+
ErrorCode,
|
|
1391
1446
|
NotFoundError,
|
|
1392
1447
|
RateLimitError,
|
|
1393
1448
|
ServerError,
|