@agentfield/sdk 0.1.69-rc.9 → 0.1.69

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
@@ -973,8 +973,8 @@ interface ServerlessEvent {
973
973
  type?: 'reasoner' | 'skill';
974
974
  body?: any;
975
975
  input?: any;
976
- executionContext?: Partial<ExecutionMetadata>;
977
- execution_context?: Partial<ExecutionMetadata>;
976
+ executionContext?: RawExecutionContext;
977
+ execution_context?: RawExecutionContext;
978
978
  }
979
979
  interface ServerlessResponse {
980
980
  statusCode: number;
@@ -984,6 +984,30 @@ interface ServerlessResponse {
984
984
  type ServerlessAdapter = (event: any, context?: any) => ServerlessEvent;
985
985
  type AgentHandler = (event: ServerlessEvent | http.IncomingMessage, res?: http.ServerResponse) => Promise<ServerlessResponse | void> | ServerlessResponse | void;
986
986
  type Awaitable<T> = T | Promise<T>;
987
+ interface RawExecutionContext {
988
+ executionId?: string;
989
+ runId?: string;
990
+ workflowId?: string;
991
+ rootWorkflowId?: string;
992
+ parentExecutionId?: string;
993
+ reasonerId?: string;
994
+ sessionId?: string;
995
+ actorId?: string;
996
+ callerDid?: string;
997
+ targetDid?: string;
998
+ agentNodeDid?: string;
999
+ execution_id?: string;
1000
+ run_id?: string;
1001
+ workflow_id?: string;
1002
+ root_workflow_id?: string;
1003
+ parent_execution_id?: string;
1004
+ reasoner_id?: string;
1005
+ session_id?: string;
1006
+ actor_id?: string;
1007
+ caller_did?: string;
1008
+ target_did?: string;
1009
+ agent_node_did?: string;
1010
+ }
987
1011
 
988
1012
  interface AgentRouterOptions {
989
1013
  prefix?: string;
@@ -1180,7 +1204,20 @@ declare class DidManager {
1180
1204
 
1181
1205
  declare class RateLimitError extends Error {
1182
1206
  retryAfter?: number;
1183
- constructor(message: string, retryAfter?: number);
1207
+ status?: number;
1208
+ statusCode?: number;
1209
+ response?: {
1210
+ status?: number;
1211
+ statusCode?: number;
1212
+ status_code?: number;
1213
+ headers?: Record<string, string>;
1214
+ };
1215
+ constructor(message: string, retryAfter?: number, status?: number, statusCode?: number, response?: {
1216
+ status?: number;
1217
+ statusCode?: number;
1218
+ status_code?: number;
1219
+ headers?: Record<string, string>;
1220
+ });
1184
1221
  }
1185
1222
  interface RateLimiterOptions {
1186
1223
  maxRetries?: number;
@@ -1639,4 +1676,4 @@ declare class ApprovalClient {
1639
1676
  waitForApproval(executionId: string, opts?: WaitForApprovalOptions): Promise<ApprovalStatusResponse>;
1640
1677
  }
1641
1678
 
1642
- 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, Audio, type AudioOutput, 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 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 MemoryChangeEvent, MemoryClient, MemoryClientBase, type MemoryConfig, MemoryEventClient, type MemoryEventHandler, type MemoryEventHistoryOptions, MemoryInterface, type MemoryRequestMetadata, type MemoryRequestOptions, type MemoryScope, type MemoryWatchHandler, type Metrics, type MultimodalContent, MultimodalResponse, 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, Text, type ToolCallConfig, type ToolCallRecord, type ToolCallTrace, type ToolsOption, type VectorSearchOptions, type VectorSearchResult, type WaitForApprovalOptions, type WorkflowCredential, type WorkflowMetadata, type WorkflowProgressOptions, WorkflowReporter, type ZodSchema, audioFromBase64, audioFromBuffer, audioFromFile, audioFromUrl, buildProvider, buildToolConfig, capabilitiesToTools, capabilityToMetadataTool, capabilityToTool, createExecutionLogger, createHarnessResult, createMetrics, createMultimodalResponse, createRawResult, executeToolCallLoop, fileFromBase64, fileFromBuffer, fileFromPath, fileFromUrl, getCurrentContext, getCurrentSkillContext, imageFromBase64, imageFromBuffer, imageFromFile, imageFromUrl, isActive, isExecutionLogBatchPayload, isTerminal, normalizeExecutionLogEntry, normalizeStatus, serializeExecutionLogEntry, text };
1679
+ 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, Audio, type AudioOutput, 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 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 MemoryChangeEvent, MemoryClient, MemoryClientBase, type MemoryConfig, MemoryEventClient, type MemoryEventHandler, type MemoryEventHistoryOptions, MemoryInterface, type MemoryRequestMetadata, type MemoryRequestOptions, type MemoryScope, type MemoryWatchHandler, type Metrics, type MultimodalContent, MultimodalResponse, RateLimitError, type RateLimiterOptions, type RawExecutionContext, 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, Text, type ToolCallConfig, type ToolCallRecord, type ToolCallTrace, type ToolsOption, type VectorSearchOptions, type VectorSearchResult, type WaitForApprovalOptions, type WorkflowCredential, type WorkflowMetadata, type WorkflowProgressOptions, WorkflowReporter, type ZodSchema, audioFromBase64, audioFromBuffer, audioFromFile, audioFromUrl, buildProvider, buildToolConfig, capabilitiesToTools, capabilityToMetadataTool, capabilityToTool, createExecutionLogger, createHarnessResult, createMetrics, createMultimodalResponse, createRawResult, executeToolCallLoop, fileFromBase64, fileFromBuffer, fileFromPath, fileFromUrl, getCurrentContext, getCurrentSkillContext, imageFromBase64, imageFromBuffer, imageFromFile, imageFromUrl, isActive, isExecutionLogBatchPayload, isTerminal, normalizeExecutionLogEntry, normalizeStatus, serializeExecutionLogEntry, text };
package/dist/index.js CHANGED
@@ -1386,10 +1386,16 @@ function getCurrentSkillContext() {
1386
1386
  }
1387
1387
  var RateLimitError = class extends Error {
1388
1388
  retryAfter;
1389
- constructor(message, retryAfter) {
1389
+ status;
1390
+ statusCode;
1391
+ response;
1392
+ constructor(message, retryAfter, status, statusCode, response) {
1390
1393
  super(message);
1391
1394
  this.name = "RateLimitError";
1392
1395
  this.retryAfter = retryAfter;
1396
+ this.status = status;
1397
+ this.statusCode = statusCode;
1398
+ this.response = response;
1393
1399
  }
1394
1400
  };
1395
1401
  var StatelessRateLimiter = class {
@@ -1418,23 +1424,27 @@ var StatelessRateLimiter = class {
1418
1424
  }
1419
1425
  _isRateLimitError(error) {
1420
1426
  if (!error) return false;
1421
- const err = error;
1422
- const className = err?.constructor?.name;
1423
- if (className && className.includes("RateLimitError")) {
1427
+ if (error instanceof RateLimitError) {
1424
1428
  return true;
1425
1429
  }
1426
- const response = err?.response;
1427
- const statusCandidates = [
1428
- err?.status,
1429
- err?.statusCode,
1430
- response?.status,
1431
- response?.statusCode,
1432
- response?.status_code
1433
- ];
1434
- if (statusCandidates.some((code) => code === 429 || code === 503)) {
1435
- return true;
1430
+ if (typeof error === "object" && error !== null) {
1431
+ const ctorName = error.constructor?.name;
1432
+ if (typeof ctorName === "string" && ctorName.includes("RateLimitError")) {
1433
+ return true;
1434
+ }
1435
+ const err = error;
1436
+ const statusCandidates = [
1437
+ err.status,
1438
+ err.statusCode,
1439
+ err.response?.status,
1440
+ err.response?.statusCode,
1441
+ err.response?.status_code
1442
+ ];
1443
+ if (statusCandidates.some((code) => code === 429 || code === 503)) {
1444
+ return true;
1445
+ }
1436
1446
  }
1437
- const message = String(err?.message ?? err ?? "").toLowerCase();
1447
+ const message = toError(error).message.toLowerCase();
1438
1448
  const rateLimitKeywords = [
1439
1449
  "rate limit",
1440
1450
  "rate-limit",
@@ -1454,22 +1464,31 @@ var StatelessRateLimiter = class {
1454
1464
  }
1455
1465
  _extractRetryAfter(error) {
1456
1466
  if (!error) return void 0;
1467
+ if (error instanceof RateLimitError && error.retryAfter) {
1468
+ return error.retryAfter;
1469
+ }
1470
+ if (typeof error !== "object" || error === null) return void 0;
1457
1471
  const err = error;
1458
- const headers = err?.response?.headers ?? err?.response?.Headers ?? err?.response?.header;
1472
+ const headers = err.response?.headers ?? err.response?.Headers ?? err.response?.header;
1459
1473
  if (headers && typeof headers === "object") {
1460
1474
  const retryAfterKey = Object.keys(headers).find((k) => k.toLowerCase() === "retry-after");
1461
1475
  if (retryAfterKey) {
1462
- const value = Array.isArray(headers[retryAfterKey]) ? headers[retryAfterKey][0] : headers[retryAfterKey];
1463
- const parsed2 = parseFloat(value);
1464
- if (!Number.isNaN(parsed2)) {
1465
- return parsed2;
1476
+ const raw = headers[retryAfterKey];
1477
+ const value = Array.isArray(raw) ? raw[0] : raw;
1478
+ if (value !== void 0) {
1479
+ const parsed = parseFloat(String(value));
1480
+ if (!Number.isNaN(parsed)) {
1481
+ return parsed;
1482
+ }
1466
1483
  }
1467
1484
  }
1468
1485
  }
1469
- const retryAfter = err?.retryAfter ?? err?.retry_after;
1470
- const parsed = parseFloat(retryAfter);
1471
- if (!Number.isNaN(parsed)) {
1472
- return parsed;
1486
+ const rawRetry = err.retryAfter ?? err.retry_after;
1487
+ if (rawRetry !== void 0) {
1488
+ const parsed = parseFloat(String(rawRetry));
1489
+ if (!Number.isNaN(parsed)) {
1490
+ return parsed;
1491
+ }
1473
1492
  }
1474
1493
  return void 0;
1475
1494
  }
@@ -1553,6 +1572,10 @@ var StatelessRateLimiter = class {
1553
1572
  );
1554
1573
  }
1555
1574
  };
1575
+ function toError(error) {
1576
+ if (error instanceof Error) return error;
1577
+ return new Error(String(error));
1578
+ }
1556
1579
 
1557
1580
  // src/ai/AIClient.ts
1558
1581
  function repairJsonText(text2) {
@@ -2085,9 +2108,13 @@ var AgentFieldClient = class {
2085
2108
  if (respData) {
2086
2109
  const status = err.response.status;
2087
2110
  const msg = respData.message || respData.error || JSON.stringify(respData);
2088
- const enriched = new Error(`execute ${target} failed (${status}): ${msg}`);
2089
- enriched.status = status;
2090
- enriched.responseData = respData;
2111
+ const enriched = Object.assign(
2112
+ new Error(`execute ${target} failed (${status}): ${msg}`),
2113
+ {
2114
+ status,
2115
+ responseData: respData
2116
+ }
2117
+ );
2091
2118
  throw enriched;
2092
2119
  }
2093
2120
  throw err;
@@ -2213,52 +2240,52 @@ var AgentFieldClient = class {
2213
2240
  }
2214
2241
  mapDiscoveryResponse(payload) {
2215
2242
  return {
2216
- discoveredAt: String(payload?.discovered_at ?? ""),
2217
- totalAgents: Number(payload?.total_agents ?? 0),
2218
- totalReasoners: Number(payload?.total_reasoners ?? 0),
2219
- totalSkills: Number(payload?.total_skills ?? 0),
2243
+ discoveredAt: String(payload.discovered_at ?? ""),
2244
+ totalAgents: Number(payload.total_agents ?? 0),
2245
+ totalReasoners: Number(payload.total_reasoners ?? 0),
2246
+ totalSkills: Number(payload.total_skills ?? 0),
2220
2247
  pagination: {
2221
- limit: Number(payload?.pagination?.limit ?? 0),
2222
- offset: Number(payload?.pagination?.offset ?? 0),
2223
- hasMore: Boolean(payload?.pagination?.has_more)
2248
+ limit: Number(payload.pagination?.limit ?? 0),
2249
+ offset: Number(payload.pagination?.offset ?? 0),
2250
+ hasMore: Boolean(payload.pagination?.has_more)
2224
2251
  },
2225
- capabilities: (payload?.capabilities ?? []).map((cap) => ({
2226
- agentId: cap?.agent_id ?? "",
2227
- baseUrl: cap?.base_url ?? "",
2228
- version: cap?.version ?? "",
2229
- healthStatus: cap?.health_status ?? "",
2230
- deploymentType: cap?.deployment_type,
2231
- lastHeartbeat: cap?.last_heartbeat,
2232
- reasoners: (cap?.reasoners ?? []).map((r) => ({
2233
- id: r?.id ?? "",
2234
- description: r?.description,
2235
- tags: r?.tags ?? [],
2236
- inputSchema: r?.input_schema,
2237
- outputSchema: r?.output_schema,
2238
- examples: r?.examples,
2239
- invocationTarget: r?.invocation_target ?? ""
2252
+ capabilities: (payload.capabilities ?? []).map((cap) => ({
2253
+ agentId: cap.agent_id ?? "",
2254
+ baseUrl: cap.base_url ?? "",
2255
+ version: cap.version ?? "",
2256
+ healthStatus: cap.health_status ?? "",
2257
+ deploymentType: cap.deployment_type,
2258
+ lastHeartbeat: cap.last_heartbeat,
2259
+ reasoners: (cap.reasoners ?? []).map((r) => ({
2260
+ id: r.id ?? "",
2261
+ description: r.description,
2262
+ tags: r.tags ?? [],
2263
+ inputSchema: r.input_schema,
2264
+ outputSchema: r.output_schema,
2265
+ examples: r.examples,
2266
+ invocationTarget: r.invocation_target ?? ""
2240
2267
  })),
2241
- skills: (cap?.skills ?? []).map((s) => ({
2242
- id: s?.id ?? "",
2243
- description: s?.description,
2244
- tags: s?.tags ?? [],
2245
- inputSchema: s?.input_schema,
2246
- invocationTarget: s?.invocation_target ?? ""
2268
+ skills: (cap.skills ?? []).map((s) => ({
2269
+ id: s.id ?? "",
2270
+ description: s.description,
2271
+ tags: s.tags ?? [],
2272
+ inputSchema: s.input_schema,
2273
+ invocationTarget: s.invocation_target ?? ""
2247
2274
  }))
2248
2275
  }))
2249
2276
  };
2250
2277
  }
2251
2278
  mapCompactDiscovery(payload) {
2252
2279
  const toCap = (cap) => ({
2253
- id: cap?.id ?? "",
2254
- agentId: cap?.agent_id ?? "",
2255
- target: cap?.target ?? "",
2256
- tags: cap?.tags ?? []
2280
+ id: cap.id ?? "",
2281
+ agentId: cap.agent_id ?? "",
2282
+ target: cap.target ?? "",
2283
+ tags: cap.tags ?? []
2257
2284
  });
2258
2285
  return {
2259
- discoveredAt: String(payload?.discovered_at ?? ""),
2260
- reasoners: (payload?.reasoners ?? []).map(toCap),
2261
- skills: (payload?.skills ?? []).map(toCap)
2286
+ discoveredAt: String(payload.discovered_at ?? ""),
2287
+ reasoners: (payload.reasoners ?? []).map(toCap),
2288
+ skills: (payload.skills ?? []).map(toCap)
2262
2289
  };
2263
2290
  }
2264
2291
  sanitizeHeaders(headers) {
@@ -3510,6 +3537,21 @@ function registerAgentfieldLogsRoute(app, ring) {
3510
3537
  var TargetNotFoundError = class extends Error {
3511
3538
  };
3512
3539
  var harnessRunners = /* @__PURE__ */ new WeakMap();
3540
+ function normalizeExecutionContext(ctx) {
3541
+ return {
3542
+ executionId: ctx.executionId ?? ctx.execution_id,
3543
+ runId: ctx.runId ?? ctx.run_id,
3544
+ workflowId: ctx.workflowId ?? ctx.workflow_id,
3545
+ rootWorkflowId: ctx.rootWorkflowId ?? ctx.root_workflow_id,
3546
+ parentExecutionId: ctx.parentExecutionId ?? ctx.parent_execution_id,
3547
+ reasonerId: ctx.reasonerId ?? ctx.reasoner_id,
3548
+ sessionId: ctx.sessionId ?? ctx.session_id,
3549
+ actorId: ctx.actorId ?? ctx.actor_id,
3550
+ callerDid: ctx.callerDid ?? ctx.caller_did,
3551
+ targetDid: ctx.targetDid ?? ctx.target_did,
3552
+ agentNodeDid: ctx.agentNodeDid ?? ctx.agent_node_did
3553
+ };
3554
+ }
3513
3555
  var Agent = class {
3514
3556
  config;
3515
3557
  app;
@@ -4264,21 +4306,8 @@ var Agent = class {
4264
4306
  return parsed;
4265
4307
  }
4266
4308
  mergeExecutionContext(event) {
4267
- const ctx = event?.executionContext ?? event?.execution_context;
4268
- if (!ctx) return {};
4269
- return {
4270
- executionId: ctx.executionId ?? ctx.execution_id ?? ctx.executionId,
4271
- runId: ctx.runId ?? ctx.run_id,
4272
- workflowId: ctx.workflowId ?? ctx.workflow_id,
4273
- rootWorkflowId: ctx.rootWorkflowId ?? ctx.root_workflow_id,
4274
- parentExecutionId: ctx.parentExecutionId ?? ctx.parent_execution_id,
4275
- reasonerId: ctx.reasonerId ?? ctx.reasoner_id,
4276
- sessionId: ctx.sessionId ?? ctx.session_id,
4277
- actorId: ctx.actorId ?? ctx.actor_id,
4278
- callerDid: ctx.callerDid ?? ctx.caller_did,
4279
- targetDid: ctx.targetDid ?? ctx.target_did,
4280
- agentNodeDid: ctx.agentNodeDid ?? ctx.agent_node_did
4281
- };
4309
+ const rawCtx = event?.executionContext ?? event?.execution_context;
4310
+ return rawCtx ? normalizeExecutionContext(rawCtx) : {};
4282
4311
  }
4283
4312
  extractInvocationDetails(params) {
4284
4313
  const pathTarget = this.parsePathTarget(params.path);
@@ -4339,12 +4368,9 @@ var Agent = class {
4339
4368
  const parsed = this.parseBody(body);
4340
4369
  if (parsed && typeof parsed === "object") {
4341
4370
  const { target, reasoner, skill, type, targetType, ...rest } = parsed;
4342
- if (parsed.input !== void 0) {
4343
- return parsed.input;
4344
- }
4345
- if (parsed.data !== void 0) {
4346
- return parsed.data;
4347
- }
4371
+ const parsedBody = parsed;
4372
+ if (parsedBody.input !== void 0) return parsedBody.input;
4373
+ if (parsedBody.data !== void 0) return parsedBody.data;
4348
4374
  if (Object.keys(rest).length === 0) {
4349
4375
  return {};
4350
4376
  }