@agentfield/sdk 0.1.60 → 0.1.61-rc.1

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.ts CHANGED
@@ -2,6 +2,7 @@ import express from 'express';
2
2
  import http from 'node:http';
3
3
  import * as _ai_sdk_provider from '@ai-sdk/provider';
4
4
  import { z } from 'zod';
5
+ import { AxiosInstance } from 'axios';
5
6
  import { ToolSet } from 'ai';
6
7
 
7
8
  type ZodSchema<T> = z.Schema<T, z.ZodTypeDef, any>;
@@ -76,9 +77,18 @@ interface VectorSearchResult {
76
77
  score: number;
77
78
  metadata?: Record<string, any>;
78
79
  }
79
- declare class MemoryClient {
80
- private readonly http;
80
+ declare class MemoryClientBase {
81
+ protected readonly http: AxiosInstance;
81
82
  private readonly defaultHeaders;
83
+ constructor(baseUrl: string, defaultHeaders?: Record<string, string | number | boolean | undefined>);
84
+ protected buildHeaders(options?: MemoryRequestOptions): {
85
+ [x: string]: string;
86
+ };
87
+ private scopeToHeader;
88
+ private resolveScopeId;
89
+ private sanitizeHeaders;
90
+ }
91
+ declare class MemoryClient extends MemoryClientBase {
82
92
  constructor(baseUrl: string, defaultHeaders?: Record<string, string | number | boolean | undefined>);
83
93
  set(key: string, data: any, options?: MemoryRequestOptions): Promise<void>;
84
94
  get<T = any>(key: string, options?: MemoryRequestOptions): Promise<T | undefined>;
@@ -88,14 +98,15 @@ declare class MemoryClient {
88
98
  setVector(key: string, embedding: number[], metadata?: any, options?: MemoryRequestOptions): Promise<void>;
89
99
  deleteVector(key: string, options?: MemoryRequestOptions): Promise<void>;
90
100
  searchVector(queryEmbedding: number[], options?: VectorSearchOptions): Promise<VectorSearchResult[]>;
91
- private buildHeaders;
92
- private scopeToHeader;
93
- private resolveScopeId;
94
- private sanitizeHeaders;
95
101
  }
96
102
 
97
103
  type MemoryEventHandler = (event: MemoryChangeEvent) => Promise<void> | void;
98
- declare class MemoryEventClient {
104
+ interface MemoryEventHistoryOptions extends MemoryRequestOptions {
105
+ patterns?: string[];
106
+ since?: Date;
107
+ limit?: number;
108
+ }
109
+ declare class MemoryEventClient extends MemoryClientBase {
99
110
  private readonly url;
100
111
  private ws?;
101
112
  private handlers;
@@ -104,7 +115,8 @@ declare class MemoryEventClient {
104
115
  private reconnectPending;
105
116
  private reconnectTimer?;
106
117
  private readonly headers;
107
- constructor(baseUrl: string, headers?: Record<string, string | number | boolean | undefined>);
118
+ private readonly apiKey?;
119
+ constructor(baseUrl: string, headers?: Record<string, string | number | boolean | undefined>, apiKey?: string);
108
120
  start(): void;
109
121
  onEvent(handler: MemoryEventHandler): void;
110
122
  stop(): void;
@@ -112,6 +124,7 @@ declare class MemoryEventClient {
112
124
  private connect;
113
125
  private scheduleReconnect;
114
126
  private buildForwardHeaders;
127
+ history(options?: MemoryEventHistoryOptions): Promise<MemoryChangeEvent[]>;
115
128
  }
116
129
 
117
130
  interface MemoryChangeEvent {
@@ -1288,4 +1301,4 @@ declare class ApprovalClient {
1288
1301
  waitForApproval(executionId: string, opts?: WaitForApprovalOptions): Promise<ApprovalStatusResponse>;
1289
1302
  }
1290
1303
 
1291
- 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 ApprovalRequestResponse, type ApprovalStatusResponse, type AuditTrailExport, type AuditTrailFilters, type Awaitable, CANONICAL_STATUSES, type CompactCapability, type CompactDiscoveryResponse, DIDAuthenticator, type DIDIdentity, type DIDIdentityPackage, type DIDRegistrationRequest, type DIDRegistrationResponse, type DeploymentType, DidClient, DidInterface, DidManager, type DiscoveryFormat, type DiscoveryOptions, type DiscoveryPagination, type DiscoveryResponse, type DiscoveryResult, ExecutionContext, type ExecutionCredential, type ExecutionMetadata, ExecutionStatus, type ExecutionStatusValue, 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, MCPClient, MCPClientRegistry, type MCPConfig, type MCPHealthSummary, type MCPServerConfig, type MCPTool, MCPToolRegistrar, type MCPToolRegistrarOptions, type MCPToolRegistration, type MemoryChangeEvent, MemoryClient, type MemoryConfig, MemoryEventClient, type MemoryEventHandler, MemoryInterface, type MemoryRequestMetadata, type MemoryRequestOptions, type MemoryScope, type MemoryWatchHandler, type Metrics, RateLimitError, type RateLimiterOptions, type RawResult, type ReasonerCapability, ReasonerContext, type ReasonerDefinition, type ReasonerHandler, type ReasonerOptions, type RequestApprovalPayload, SUPPORTED_PROVIDERS, type ServerlessAdapter, type ServerlessEvent, type ServerlessResponse, type SkillCapability, SkillContext, type SkillDefinition, type SkillHandler, type SkillOptions, StatelessRateLimiter, TERMINAL_STATUSES, type ToolCallConfig, type ToolCallRecord, type ToolCallTrace, type ToolsOption, type VectorSearchOptions, type VectorSearchResult, type WaitForApprovalOptions, type WorkflowCredential, type WorkflowMetadata, type WorkflowProgressOptions, WorkflowReporter, type ZodSchema, buildProvider, buildToolConfig, capabilitiesToTools, capabilityToMetadataTool, capabilityToTool, createHarnessResult, createMetrics, createRawResult, executeToolCallLoop, getCurrentContext, getCurrentSkillContext, isActive, isTerminal, normalizeStatus };
1304
+ 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 ApprovalRequestResponse, type ApprovalStatusResponse, type AuditTrailExport, type AuditTrailFilters, type Awaitable, CANONICAL_STATUSES, type CompactCapability, type CompactDiscoveryResponse, DIDAuthenticator, type DIDIdentity, type DIDIdentityPackage, type DIDRegistrationRequest, type DIDRegistrationResponse, type DeploymentType, DidClient, DidInterface, DidManager, type DiscoveryFormat, type DiscoveryOptions, type DiscoveryPagination, type DiscoveryResponse, type DiscoveryResult, ExecutionContext, type ExecutionCredential, type ExecutionMetadata, ExecutionStatus, type ExecutionStatusValue, 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, MCPClient, MCPClientRegistry, type MCPConfig, type MCPHealthSummary, type MCPServerConfig, type MCPTool, MCPToolRegistrar, type MCPToolRegistrarOptions, type MCPToolRegistration, type MemoryChangeEvent, MemoryClient, MemoryClientBase, type MemoryConfig, MemoryEventClient, type MemoryEventHandler, type MemoryEventHistoryOptions, MemoryInterface, type MemoryRequestMetadata, type MemoryRequestOptions, type MemoryScope, type MemoryWatchHandler, type Metrics, RateLimitError, type RateLimiterOptions, type RawResult, type ReasonerCapability, ReasonerContext, type ReasonerDefinition, type ReasonerHandler, type ReasonerOptions, type RequestApprovalPayload, SUPPORTED_PROVIDERS, type ServerlessAdapter, type ServerlessEvent, type ServerlessResponse, type SkillCapability, SkillContext, type SkillDefinition, type SkillHandler, type SkillOptions, StatelessRateLimiter, TERMINAL_STATUSES, type ToolCallConfig, type ToolCallRecord, type ToolCallTrace, type ToolsOption, type VectorSearchOptions, type VectorSearchResult, type WaitForApprovalOptions, type WorkflowCredential, type WorkflowMetadata, type WorkflowProgressOptions, WorkflowReporter, type ZodSchema, buildProvider, buildToolConfig, capabilitiesToTools, capabilityToMetadataTool, capabilityToTool, createHarnessResult, createMetrics, createRawResult, executeToolCallLoop, getCurrentContext, getCurrentSkillContext, isActive, isTerminal, normalizeStatus };
package/dist/index.js CHANGED
@@ -2145,7 +2145,7 @@ var AgentFieldClient = class {
2145
2145
  });
2146
2146
  }
2147
2147
  };
2148
- var MemoryClient = class {
2148
+ var MemoryClientBase = class {
2149
2149
  http;
2150
2150
  defaultHeaders;
2151
2151
  constructor(baseUrl, defaultHeaders) {
@@ -2157,6 +2157,67 @@ var MemoryClient = class {
2157
2157
  });
2158
2158
  this.defaultHeaders = this.sanitizeHeaders(defaultHeaders ?? {});
2159
2159
  }
2160
+ buildHeaders(options = {}) {
2161
+ const { scope, scopeId, metadata } = options;
2162
+ const headers = { ...this.defaultHeaders };
2163
+ const workflowId = metadata?.workflowId ?? metadata?.runId;
2164
+ if (workflowId) headers["X-Workflow-ID"] = workflowId;
2165
+ if (metadata?.sessionId) headers["X-Session-ID"] = metadata.sessionId;
2166
+ if (metadata?.actorId) headers["X-Actor-ID"] = metadata.actorId;
2167
+ if (metadata?.runId) headers["X-Run-ID"] = metadata.runId;
2168
+ if (metadata?.executionId) headers["X-Execution-ID"] = metadata.executionId;
2169
+ if (metadata?.parentExecutionId) headers["X-Parent-Execution-ID"] = metadata.parentExecutionId;
2170
+ if (metadata?.callerDid) headers["X-Caller-DID"] = metadata.callerDid;
2171
+ if (metadata?.targetDid) headers["X-Target-DID"] = metadata.targetDid;
2172
+ if (metadata?.agentNodeDid) headers["X-Agent-Node-DID"] = metadata.agentNodeDid;
2173
+ if (metadata?.agentNodeId) headers["X-Agent-Node-ID"] = metadata.agentNodeId;
2174
+ const headerName = this.scopeToHeader(scope);
2175
+ const resolvedScopeId = this.resolveScopeId(scope, scopeId, metadata);
2176
+ if (headerName && resolvedScopeId) {
2177
+ headers[headerName] = resolvedScopeId;
2178
+ }
2179
+ return { ...headers, ...this.sanitizeHeaders(options.headers ?? {}) };
2180
+ }
2181
+ scopeToHeader(scope) {
2182
+ switch (scope) {
2183
+ case "workflow":
2184
+ return "X-Workflow-ID";
2185
+ case "session":
2186
+ return "X-Session-ID";
2187
+ case "actor":
2188
+ return "X-Actor-ID";
2189
+ default:
2190
+ return void 0;
2191
+ }
2192
+ }
2193
+ resolveScopeId(scope, scopeId, metadata) {
2194
+ if (scopeId) return scopeId;
2195
+ switch (scope) {
2196
+ case "workflow":
2197
+ return metadata?.workflowId ?? metadata?.runId;
2198
+ case "session":
2199
+ return metadata?.sessionId;
2200
+ case "actor":
2201
+ return metadata?.actorId;
2202
+ case "global":
2203
+ return "global";
2204
+ default:
2205
+ return void 0;
2206
+ }
2207
+ }
2208
+ sanitizeHeaders(headers) {
2209
+ const sanitized = {};
2210
+ Object.entries(headers).forEach(([key, value]) => {
2211
+ if (value === void 0 || value === null) return;
2212
+ sanitized[key] = typeof value === "string" ? value : String(value);
2213
+ });
2214
+ return sanitized;
2215
+ }
2216
+ };
2217
+ var MemoryClient = class extends MemoryClientBase {
2218
+ constructor(baseUrl, defaultHeaders) {
2219
+ super(baseUrl, defaultHeaders);
2220
+ }
2160
2221
  async set(key, data, options = {}) {
2161
2222
  const payload = { key, data };
2162
2223
  if (options.scope) payload.scope = options.scope;
@@ -2227,64 +2288,8 @@ var MemoryClient = class {
2227
2288
  });
2228
2289
  return res.data ?? [];
2229
2290
  }
2230
- buildHeaders(options = {}) {
2231
- const { scope, scopeId, metadata } = options;
2232
- const headers = { ...this.defaultHeaders };
2233
- const workflowId = metadata?.workflowId ?? metadata?.runId;
2234
- if (workflowId) headers["X-Workflow-ID"] = workflowId;
2235
- if (metadata?.sessionId) headers["X-Session-ID"] = metadata.sessionId;
2236
- if (metadata?.actorId) headers["X-Actor-ID"] = metadata.actorId;
2237
- if (metadata?.runId) headers["X-Run-ID"] = metadata.runId;
2238
- if (metadata?.executionId) headers["X-Execution-ID"] = metadata.executionId;
2239
- if (metadata?.parentExecutionId) headers["X-Parent-Execution-ID"] = metadata.parentExecutionId;
2240
- if (metadata?.callerDid) headers["X-Caller-DID"] = metadata.callerDid;
2241
- if (metadata?.targetDid) headers["X-Target-DID"] = metadata.targetDid;
2242
- if (metadata?.agentNodeDid) headers["X-Agent-Node-DID"] = metadata.agentNodeDid;
2243
- if (metadata?.agentNodeId) headers["X-Agent-Node-ID"] = metadata.agentNodeId;
2244
- const headerName = this.scopeToHeader(scope);
2245
- const resolvedScopeId = this.resolveScopeId(scope, scopeId, metadata);
2246
- if (headerName && resolvedScopeId) {
2247
- headers[headerName] = resolvedScopeId;
2248
- }
2249
- return { ...headers, ...this.sanitizeHeaders(options.headers ?? {}) };
2250
- }
2251
- scopeToHeader(scope) {
2252
- switch (scope) {
2253
- case "workflow":
2254
- return "X-Workflow-ID";
2255
- case "session":
2256
- return "X-Session-ID";
2257
- case "actor":
2258
- return "X-Actor-ID";
2259
- default:
2260
- return void 0;
2261
- }
2262
- }
2263
- resolveScopeId(scope, scopeId, metadata) {
2264
- if (scopeId) return scopeId;
2265
- switch (scope) {
2266
- case "workflow":
2267
- return metadata?.workflowId ?? metadata?.runId;
2268
- case "session":
2269
- return metadata?.sessionId;
2270
- case "actor":
2271
- return metadata?.actorId;
2272
- case "global":
2273
- return "global";
2274
- default:
2275
- return void 0;
2276
- }
2277
- }
2278
- sanitizeHeaders(headers) {
2279
- const sanitized = {};
2280
- Object.entries(headers).forEach(([key, value]) => {
2281
- if (value === void 0 || value === null) return;
2282
- sanitized[key] = typeof value === "string" ? value : String(value);
2283
- });
2284
- return sanitized;
2285
- }
2286
2291
  };
2287
- var MemoryEventClient = class {
2292
+ var MemoryEventClient = class extends MemoryClientBase {
2288
2293
  url;
2289
2294
  ws;
2290
2295
  handlers = [];
@@ -2293,9 +2298,12 @@ var MemoryEventClient = class {
2293
2298
  reconnectPending = false;
2294
2299
  reconnectTimer;
2295
2300
  headers;
2296
- constructor(baseUrl, headers) {
2301
+ apiKey;
2302
+ constructor(baseUrl, headers, apiKey) {
2303
+ super(baseUrl, headers);
2297
2304
  this.url = `${baseUrl.replace(/^http/, "ws")}/api/v1/memory/events/ws`;
2298
2305
  this.headers = this.buildForwardHeaders(headers ?? {});
2306
+ this.apiKey = apiKey;
2299
2307
  }
2300
2308
  start() {
2301
2309
  if (this.ws) return;
@@ -2362,6 +2370,44 @@ var MemoryEventClient = class {
2362
2370
  });
2363
2371
  return sanitized;
2364
2372
  }
2373
+ async history(options = {}) {
2374
+ const {
2375
+ patterns,
2376
+ since,
2377
+ limit = 100,
2378
+ scope,
2379
+ scopeId
2380
+ } = options;
2381
+ try {
2382
+ const headers = this.buildHeaders(options);
2383
+ if (this.apiKey) {
2384
+ headers["X-API-Key"] = this.apiKey;
2385
+ }
2386
+ const params = {
2387
+ limit
2388
+ };
2389
+ if (patterns && patterns.length > 0) {
2390
+ params.patterns = patterns.join(",");
2391
+ }
2392
+ if (since) {
2393
+ params.since = since.toISOString();
2394
+ }
2395
+ if (scope) {
2396
+ params.scope = scope;
2397
+ }
2398
+ if (scopeId) {
2399
+ params.scope_id = scopeId;
2400
+ }
2401
+ const res = await this.http.get("/api/v1/memory/events/history", {
2402
+ params,
2403
+ headers
2404
+ });
2405
+ return res.data ?? [];
2406
+ } catch (e) {
2407
+ console.error(`Failed to get event history: ${e}`);
2408
+ return [];
2409
+ }
2410
+ }
2365
2411
  };
2366
2412
 
2367
2413
  // src/memory/MemoryInterface.ts
@@ -4531,6 +4577,6 @@ function sleep(ms) {
4531
4577
  return new Promise((resolve) => setTimeout(resolve, ms));
4532
4578
  }
4533
4579
 
4534
- export { ACTIVE_STATUSES, AIClient, Agent, AgentRouter, ApprovalClient, CANONICAL_STATUSES, DIDAuthenticator, DidClient, DidInterface, DidManager, ExecutionContext, ExecutionStatus, HEADER_CALLER_DID, HEADER_DID_NONCE, HEADER_DID_SIGNATURE, HEADER_DID_TIMESTAMP, HarnessRunner, MCPClient, MCPClientRegistry, MCPToolRegistrar, MemoryClient, MemoryEventClient, MemoryInterface, RateLimitError, ReasonerContext, SUPPORTED_PROVIDERS, SkillContext, StatelessRateLimiter, TERMINAL_STATUSES, WorkflowReporter, buildProvider, buildToolConfig, capabilitiesToTools, capabilityToMetadataTool, capabilityToTool, createHarnessResult, createMetrics, createRawResult, executeToolCallLoop, getCurrentContext, getCurrentSkillContext, isActive, isTerminal, normalizeStatus };
4580
+ export { ACTIVE_STATUSES, AIClient, Agent, AgentRouter, ApprovalClient, CANONICAL_STATUSES, DIDAuthenticator, DidClient, DidInterface, DidManager, ExecutionContext, ExecutionStatus, HEADER_CALLER_DID, HEADER_DID_NONCE, HEADER_DID_SIGNATURE, HEADER_DID_TIMESTAMP, HarnessRunner, MCPClient, MCPClientRegistry, MCPToolRegistrar, MemoryClient, MemoryClientBase, MemoryEventClient, MemoryInterface, RateLimitError, ReasonerContext, SUPPORTED_PROVIDERS, SkillContext, StatelessRateLimiter, TERMINAL_STATUSES, WorkflowReporter, buildProvider, buildToolConfig, capabilitiesToTools, capabilityToMetadataTool, capabilityToTool, createHarnessResult, createMetrics, createRawResult, executeToolCallLoop, getCurrentContext, getCurrentSkillContext, isActive, isTerminal, normalizeStatus };
4535
4581
  //# sourceMappingURL=index.js.map
4536
4582
  //# sourceMappingURL=index.js.map