@agentfield/sdk 0.1.123 → 0.1.124-rc.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/README.md CHANGED
@@ -7,6 +7,26 @@ The TypeScript SDK provides an idiomatic Node.js interface for building and runn
7
7
  npm install @agentfield/sdk
8
8
  ```
9
9
 
10
+ ## Memory event subscriptions
11
+
12
+ Pass filters when starting a memory event client to apply them on the server before events are sent over the WebSocket:
13
+
14
+ ```ts
15
+ import { MemoryEventClient } from '@agentfield/sdk';
16
+
17
+ const events = new MemoryEventClient('http://localhost:8080');
18
+ events.onEvent((event) => console.log(event.key));
19
+ events.start({
20
+ patterns: ['user_*', 'session.*'],
21
+ scope: 'session',
22
+ scopeId: 'session-123'
23
+ });
24
+ ```
25
+
26
+ `patterns` is a list of memory-key globs and is sent as a comma-separated query parameter. `scope` accepts `workflow`, `session`, `actor`, or `global`, while `scopeId` maps to the server's `scope_id` parameter. All filters are optional, and automatic reconnects reuse the original filters. Omitting them keeps the existing behavior of receiving all events.
27
+
28
+ Server-side filtering reduces WebSocket traffic and client-side processing for high-volume event streams.
29
+
10
30
  ## Rate limiting
11
31
  AI calls are wrapped with a stateless rate limiter that matches the Python SDK: exponential backoff, container-scoped jitter, Retry-After support, and a circuit breaker.
12
32
 
package/dist/index.d.ts CHANGED
@@ -219,6 +219,12 @@ declare class MemoryClient extends MemoryClientBase {
219
219
  }
220
220
 
221
221
  type MemoryEventHandler = (event: MemoryChangeEvent) => Promise<void> | void;
222
+ interface MemoryEventSubscriptionOptions {
223
+ /** Memory key glob patterns to filter on the server. */
224
+ patterns?: string[];
225
+ scope?: MemoryRequestOptions['scope'];
226
+ scopeId?: string;
227
+ }
222
228
  interface MemoryEventHistoryOptions extends MemoryRequestOptions {
223
229
  patterns?: string[];
224
230
  since?: Date;
@@ -234,13 +240,16 @@ declare class MemoryEventClient extends MemoryClientBase {
234
240
  private reconnectTimer?;
235
241
  private readonly headers;
236
242
  private readonly apiKey?;
243
+ private subscriptionOptions;
237
244
  constructor(baseUrl: string, headers?: Record<string, string | number | boolean | undefined>, apiKey?: string);
238
- start(): void;
245
+ /** Starts the event stream with optional server-side filters. */
246
+ start(options?: MemoryEventSubscriptionOptions): void;
239
247
  onEvent(handler: MemoryEventHandler): void;
240
248
  stop(): void;
241
249
  private cleanup;
242
250
  private connect;
243
251
  private scheduleReconnect;
252
+ private buildWebSocketUrl;
244
253
  private buildForwardHeaders;
245
254
  history(options?: MemoryEventHistoryOptions): Promise<MemoryChangeEvent[]>;
246
255
  }
@@ -3003,4 +3012,4 @@ declare function simulateSchedule<R>(handler: (ctx: SimulatedContext) => R | Pro
3003
3012
  */
3004
3013
  declare function loadFixture(source: string): Record<string, unknown>;
3005
3014
 
3006
- export { ACTIVE_STATUSES, AIClient, type AIConfig, type AIEmbeddingOptions, type AIRequestOptions, type AIStream, type AIToolRequestOptions, Agent, type AgentCapability, type AgentConfig, type AgentHandler, AgentRouter, type AgentRouterOptions, type AgentState, ApprovalClient, type ApprovalDecision, type ApprovalRequestResponse, ApprovalResult, type ApprovalStatusResponse, Audio, type AudioOutput, type AudioRequest, type AuditTrailExport, type AuditTrailFilters, type Awaitable, CANONICAL_STATUSES, type CompactCapability, type CompactDiscoveryResponse, type CostEntry, type CostEntryInit, CostTracker, DIDAuthenticator, type DIDIdentity, type DIDIdentityPackage, type DIDRegistrationRequest, type DIDRegistrationResponse, type DeploymentType, DidClient, DidInterface, DidManager, type DidResolver, type DiscoveryFormat, type DiscoveryOptions, type DiscoveryPagination, type DiscoveryResponse, type DiscoveryResult, type EventTriggerBinding, type EventTriggerSpec, ExecutionContext, type ExecutionCredential, type ExecutionLogAttributes, type ExecutionLogBatchPayload, type ExecutionLogContext, type ExecutionLogEmitOptions, type ExecutionLogEntry, type ExecutionLogLevel, type ExecutionLogTransport, type ExecutionLogTransportPayload, type ExecutionLogWireEntry, ExecutionLogger, type ExecutionLoggerOptions, type ExecutionMetadata, ExecutionStatus, type ExecutionStatusValue, File, type FileOutput, type GenerateCredentialOptions, type GenerateCredentialParams, HEADER_CALLER_DID, HEADER_DID_NONCE, HEADER_DID_SIGNATURE, HEADER_DID_TIMESTAMP, type HarnessConfig, type HarnessOptions, type HarnessProvider, type HarnessResult, HarnessRunner, type HealthStatus, Image, type ImageOutput, type ImageRequest, JWE_ALG, JWE_ENC, KEY_AGREEMENT_TYPE, MODEL_VARIANT_SEP, type MediaProvider, MediaProviderError, type MediaResponse, MediaRouter, type MemoryChangeEvent, MemoryClient, MemoryClientBase, type MemoryConfig, MemoryEventClient, type MemoryEventHandler, type MemoryEventHistoryOptions, MemoryInterface, type MemoryRequestMetadata, type MemoryRequestOptions, type MemoryScope, type MemoryWatchHandler, type Metrics, type ModelVariant, type MultimodalContent, MultimodalResponse, OpenRouterMediaProvider, type OpenRouterMediaProviderOptions, PauseClock, PauseManager, type Payload, PayloadEncryptionError, RateLimitError, type RateLimiterOptions, type RawExecutionContext, type RawResult, RealtimeSession, type ReasonerCapability, ReasonerContext, type ReasonerDefinition, type ReasonerHandler, type ReasonerOptions, type RequestApprovalPayload, SUPPORTED_PROVIDERS, SUPPORTED_SESSION_TRANSPORTS, type ScheduleTriggerBinding, type ScheduleTriggerSpec, type ServerlessAdapter, type ServerlessEvent, type ServerlessResponse, type SessionDefinition, type SessionOptions, type SessionProvider, type SessionTransport, type SessionTransportCapability, SessionTransportError, type SessionTurn, type SimulateScheduleOptions, type SimulateTriggerOptions, type SimulatedContext, type SkillCapability, SkillContext, type SkillDefinition, type SkillHandler, type SkillOptions, StatelessRateLimiter, TERMINAL_STATUSES, Text, type ToolCallConfig, type ToolCallRecord, type ToolCallTrace, type ToolsOption, type TriggerBinding, type TriggerContext, type TriggerEnvelope, USAGE_ENVELOPE_KEY, type UnwrapResult, type UsageEntryWire, type UsageSummaryWire, type VectorSearchOptions, type VectorSearchResult, Video, type VideoFrameImage, type VideoInputReference, type VideoRequest, type WaitForApprovalOptions, type WorkflowCredential, type WorkflowMetadata, type WorkflowProgressOptions, WorkflowReporter, type ZodSchema, applyTriggerTransform, attachUsageToSyncResult, audioFromBase64, audioFromBuffer, audioFromFile, audioFromUrl, buildProvider, buildSessionDefinition, buildToolConfig, capabilitiesToTools, capabilityToMetadataTool, capabilityToTool, createExecutionLogger, createHarnessResult, createMetrics, createMultimodalResponse, createRawResult, decrypt, decryptToString, deriveProvider, encryptForDid, encryptToJwk, eventTrigger, executeToolCallLoop, extractKeyAgreementJwk, fileFromBase64, fileFromBuffer, fileFromPath, fileFromUrl, generateX25519KeyPair, getCurrentContext, getCurrentSkillContext, imageFromBase64, imageFromBuffer, imageFromFile, imageFromUrl, installApprovalWebhookRoute, isActive, isExecutionLogBatchPayload, isTerminal, isTriggerEnvelope, loadFixture, normalizeExecutionLogEntry, normalizeSessionTransportValue, normalizeStatus, resolveModelAndVariant, scheduleTrigger, serializeExecutionLogEntry, simulateSchedule, simulateTrigger, splitModelVariant, text, triggerToPayload, unwrapEnvelope, usageSummaryOrNull, validateSessionTransport, videoFromBase64, videoFromBuffer, videoFromFile, videoFromUrl };
3015
+ export { ACTIVE_STATUSES, AIClient, type AIConfig, type AIEmbeddingOptions, type AIRequestOptions, type AIStream, type AIToolRequestOptions, Agent, type AgentCapability, type AgentConfig, type AgentHandler, AgentRouter, type AgentRouterOptions, type AgentState, ApprovalClient, type ApprovalDecision, type ApprovalRequestResponse, ApprovalResult, type ApprovalStatusResponse, Audio, type AudioOutput, type AudioRequest, type AuditTrailExport, type AuditTrailFilters, type Awaitable, CANONICAL_STATUSES, type CompactCapability, type CompactDiscoveryResponse, type CostEntry, type CostEntryInit, CostTracker, DIDAuthenticator, type DIDIdentity, type DIDIdentityPackage, type DIDRegistrationRequest, type DIDRegistrationResponse, type DeploymentType, DidClient, DidInterface, DidManager, type DidResolver, type DiscoveryFormat, type DiscoveryOptions, type DiscoveryPagination, type DiscoveryResponse, type DiscoveryResult, type EventTriggerBinding, type EventTriggerSpec, ExecutionContext, type ExecutionCredential, type ExecutionLogAttributes, type ExecutionLogBatchPayload, type ExecutionLogContext, type ExecutionLogEmitOptions, type ExecutionLogEntry, type ExecutionLogLevel, type ExecutionLogTransport, type ExecutionLogTransportPayload, type ExecutionLogWireEntry, ExecutionLogger, type ExecutionLoggerOptions, type ExecutionMetadata, ExecutionStatus, type ExecutionStatusValue, File, type FileOutput, type GenerateCredentialOptions, type GenerateCredentialParams, HEADER_CALLER_DID, HEADER_DID_NONCE, HEADER_DID_SIGNATURE, HEADER_DID_TIMESTAMP, type HarnessConfig, type HarnessOptions, type HarnessProvider, type HarnessResult, HarnessRunner, type HealthStatus, Image, type ImageOutput, type ImageRequest, JWE_ALG, JWE_ENC, KEY_AGREEMENT_TYPE, MODEL_VARIANT_SEP, type MediaProvider, MediaProviderError, type MediaResponse, MediaRouter, type MemoryChangeEvent, MemoryClient, MemoryClientBase, type MemoryConfig, MemoryEventClient, type MemoryEventHandler, type MemoryEventHistoryOptions, type MemoryEventSubscriptionOptions, MemoryInterface, type MemoryRequestMetadata, type MemoryRequestOptions, type MemoryScope, type MemoryWatchHandler, type Metrics, type ModelVariant, type MultimodalContent, MultimodalResponse, OpenRouterMediaProvider, type OpenRouterMediaProviderOptions, PauseClock, PauseManager, type Payload, PayloadEncryptionError, RateLimitError, type RateLimiterOptions, type RawExecutionContext, type RawResult, RealtimeSession, type ReasonerCapability, ReasonerContext, type ReasonerDefinition, type ReasonerHandler, type ReasonerOptions, type RequestApprovalPayload, SUPPORTED_PROVIDERS, SUPPORTED_SESSION_TRANSPORTS, type ScheduleTriggerBinding, type ScheduleTriggerSpec, type ServerlessAdapter, type ServerlessEvent, type ServerlessResponse, type SessionDefinition, type SessionOptions, type SessionProvider, type SessionTransport, type SessionTransportCapability, SessionTransportError, type SessionTurn, type SimulateScheduleOptions, type SimulateTriggerOptions, type SimulatedContext, type SkillCapability, SkillContext, type SkillDefinition, type SkillHandler, type SkillOptions, StatelessRateLimiter, TERMINAL_STATUSES, Text, type ToolCallConfig, type ToolCallRecord, type ToolCallTrace, type ToolsOption, type TriggerBinding, type TriggerContext, type TriggerEnvelope, USAGE_ENVELOPE_KEY, type UnwrapResult, type UsageEntryWire, type UsageSummaryWire, type VectorSearchOptions, type VectorSearchResult, Video, type VideoFrameImage, type VideoInputReference, type VideoRequest, type WaitForApprovalOptions, type WorkflowCredential, type WorkflowMetadata, type WorkflowProgressOptions, WorkflowReporter, type ZodSchema, applyTriggerTransform, attachUsageToSyncResult, audioFromBase64, audioFromBuffer, audioFromFile, audioFromUrl, buildProvider, buildSessionDefinition, buildToolConfig, capabilitiesToTools, capabilityToMetadataTool, capabilityToTool, createExecutionLogger, createHarnessResult, createMetrics, createMultimodalResponse, createRawResult, decrypt, decryptToString, deriveProvider, encryptForDid, encryptToJwk, eventTrigger, executeToolCallLoop, extractKeyAgreementJwk, fileFromBase64, fileFromBuffer, fileFromPath, fileFromUrl, generateX25519KeyPair, getCurrentContext, getCurrentSkillContext, imageFromBase64, imageFromBuffer, imageFromFile, imageFromUrl, installApprovalWebhookRoute, isActive, isExecutionLogBatchPayload, isTerminal, isTriggerEnvelope, loadFixture, normalizeExecutionLogEntry, normalizeSessionTransportValue, normalizeStatus, resolveModelAndVariant, scheduleTrigger, serializeExecutionLogEntry, simulateSchedule, simulateTrigger, splitModelVariant, text, triggerToPayload, unwrapEnvelope, usageSummaryOrNull, validateSessionTransport, videoFromBase64, videoFromBuffer, videoFromFile, videoFromUrl };
package/dist/index.js CHANGED
@@ -3888,14 +3888,20 @@ var MemoryEventClient = class extends MemoryClientBase {
3888
3888
  reconnectTimer;
3889
3889
  headers;
3890
3890
  apiKey;
3891
+ subscriptionOptions = {};
3891
3892
  constructor(baseUrl, headers, apiKey) {
3892
3893
  super(baseUrl, headers);
3893
3894
  this.url = `${baseUrl.replace(/^http/, "ws")}/api/v1/memory/events/ws`;
3894
3895
  this.headers = this.buildForwardHeaders(headers ?? {});
3895
3896
  this.apiKey = apiKey;
3896
3897
  }
3897
- start() {
3898
+ /** Starts the event stream with optional server-side filters. */
3899
+ start(options = {}) {
3898
3900
  if (this.ws) return;
3901
+ this.subscriptionOptions = {
3902
+ ...options,
3903
+ patterns: options.patterns ? [...options.patterns] : void 0
3904
+ };
3899
3905
  this.connect();
3900
3906
  }
3901
3907
  onEvent(handler) {
@@ -3919,7 +3925,7 @@ var MemoryEventClient = class extends MemoryClientBase {
3919
3925
  connect() {
3920
3926
  this.cleanup();
3921
3927
  this.reconnectPending = false;
3922
- this.ws = new WebSocket(this.url, { headers: this.headers });
3928
+ this.ws = new WebSocket(this.buildWebSocketUrl(), { headers: this.headers });
3923
3929
  this.ws.on("open", () => {
3924
3930
  this.reconnectDelay = 1e3;
3925
3931
  });
@@ -3947,6 +3953,21 @@ var MemoryEventClient = class extends MemoryClientBase {
3947
3953
  this.connect();
3948
3954
  }, this.reconnectDelay);
3949
3955
  }
3956
+ buildWebSocketUrl() {
3957
+ const params = new URLSearchParams();
3958
+ const { patterns, scope, scopeId } = this.subscriptionOptions;
3959
+ if (patterns && patterns.length > 0) {
3960
+ params.set("patterns", patterns.join(","));
3961
+ }
3962
+ if (scope) {
3963
+ params.set("scope", scope);
3964
+ }
3965
+ if (scopeId) {
3966
+ params.set("scope_id", scopeId);
3967
+ }
3968
+ const query = params.toString();
3969
+ return query ? `${this.url}?${query}` : this.url;
3970
+ }
3950
3971
  buildForwardHeaders(headers) {
3951
3972
  const allowed = /* @__PURE__ */ new Set(["authorization", "cookie"]);
3952
3973
  const sanitized = {};