@agentfield/sdk 0.1.43 → 0.1.44-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/dist/index.d.ts +108 -2
- package/dist/index.js +163 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -160,6 +160,7 @@ interface ExecutionStatusUpdate {
|
|
|
160
160
|
error?: string;
|
|
161
161
|
durationMs?: number;
|
|
162
162
|
progress?: number;
|
|
163
|
+
statusReason?: string;
|
|
163
164
|
}
|
|
164
165
|
declare class AgentFieldClient {
|
|
165
166
|
private readonly http;
|
|
@@ -187,9 +188,10 @@ declare class AgentFieldClient {
|
|
|
187
188
|
workflowId?: string;
|
|
188
189
|
reasonerId: string;
|
|
189
190
|
agentNodeId: string;
|
|
190
|
-
status: 'running' | 'succeeded' | 'failed';
|
|
191
|
+
status: 'waiting' | 'running' | 'succeeded' | 'failed';
|
|
191
192
|
parentExecutionId?: string;
|
|
192
193
|
parentWorkflowId?: string;
|
|
194
|
+
statusReason?: string;
|
|
193
195
|
inputData?: Record<string, any>;
|
|
194
196
|
result?: any;
|
|
195
197
|
error?: string;
|
|
@@ -980,4 +982,108 @@ declare class StatelessRateLimiter {
|
|
|
980
982
|
executeWithRetry<T>(fn: () => Promise<T>): Promise<T>;
|
|
981
983
|
}
|
|
982
984
|
|
|
983
|
-
|
|
985
|
+
/**
|
|
986
|
+
* Canonical execution status utilities for the AgentField TypeScript SDK.
|
|
987
|
+
*
|
|
988
|
+
* Mirrors the control plane's status normalization and terminal-state logic
|
|
989
|
+
* so that SDK consumers can classify execution statuses consistently.
|
|
990
|
+
*/
|
|
991
|
+
/** Canonical execution status values used by the control plane. */
|
|
992
|
+
declare const ExecutionStatus: {
|
|
993
|
+
readonly PENDING: "pending";
|
|
994
|
+
readonly QUEUED: "queued";
|
|
995
|
+
readonly WAITING: "waiting";
|
|
996
|
+
readonly RUNNING: "running";
|
|
997
|
+
readonly SUCCEEDED: "succeeded";
|
|
998
|
+
readonly FAILED: "failed";
|
|
999
|
+
readonly CANCELLED: "cancelled";
|
|
1000
|
+
readonly TIMEOUT: "timeout";
|
|
1001
|
+
readonly UNKNOWN: "unknown";
|
|
1002
|
+
};
|
|
1003
|
+
type ExecutionStatusValue = (typeof ExecutionStatus)[keyof typeof ExecutionStatus];
|
|
1004
|
+
/** All canonical status strings. */
|
|
1005
|
+
declare const CANONICAL_STATUSES: ReadonlySet<string>;
|
|
1006
|
+
/** Statuses that represent a completed execution (no further transitions). */
|
|
1007
|
+
declare const TERMINAL_STATUSES: ReadonlySet<string>;
|
|
1008
|
+
/** Statuses that represent an active, pollable execution. */
|
|
1009
|
+
declare const ACTIVE_STATUSES: ReadonlySet<string>;
|
|
1010
|
+
/**
|
|
1011
|
+
* Normalize an arbitrary status string to its canonical form.
|
|
1012
|
+
*
|
|
1013
|
+
* Returns `"unknown"` for unrecognized or empty values.
|
|
1014
|
+
*/
|
|
1015
|
+
declare function normalizeStatus(status: string | null | undefined): string;
|
|
1016
|
+
/** Return `true` if the status represents a terminal (completed) execution. */
|
|
1017
|
+
declare function isTerminal(status: string | null | undefined): boolean;
|
|
1018
|
+
/** Return `true` if the status represents an active, pollable execution. */
|
|
1019
|
+
declare function isActive(status: string | null | undefined): boolean;
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* Approval workflow helpers for the AgentField TypeScript SDK.
|
|
1023
|
+
*
|
|
1024
|
+
* Provides methods to request human approval for an execution,
|
|
1025
|
+
* poll for approval status, and wait until resolved.
|
|
1026
|
+
*/
|
|
1027
|
+
/** Payload sent when requesting approval. */
|
|
1028
|
+
interface RequestApprovalPayload {
|
|
1029
|
+
title?: string;
|
|
1030
|
+
description?: string;
|
|
1031
|
+
templateType?: string;
|
|
1032
|
+
payload?: Record<string, any>;
|
|
1033
|
+
projectId: string;
|
|
1034
|
+
expiresInHours?: number;
|
|
1035
|
+
}
|
|
1036
|
+
/** Response from the control plane after creating an approval request. */
|
|
1037
|
+
interface ApprovalRequestResponse {
|
|
1038
|
+
approvalRequestId: string;
|
|
1039
|
+
approvalRequestUrl: string;
|
|
1040
|
+
}
|
|
1041
|
+
/** Approval status returned by the polling endpoint. */
|
|
1042
|
+
interface ApprovalStatusResponse {
|
|
1043
|
+
status: 'pending' | 'approved' | 'rejected' | 'expired';
|
|
1044
|
+
response?: Record<string, any>;
|
|
1045
|
+
requestUrl?: string;
|
|
1046
|
+
requestedAt?: string;
|
|
1047
|
+
respondedAt?: string;
|
|
1048
|
+
}
|
|
1049
|
+
/** Options for the blocking `waitForApproval` helper. */
|
|
1050
|
+
interface WaitForApprovalOptions {
|
|
1051
|
+
/** Initial polling interval in milliseconds (default: 5000). */
|
|
1052
|
+
pollIntervalMs?: number;
|
|
1053
|
+
/** Maximum polling interval in milliseconds (default: 60000). */
|
|
1054
|
+
maxIntervalMs?: number;
|
|
1055
|
+
/** Total timeout in milliseconds (default: unlimited). */
|
|
1056
|
+
timeoutMs?: number;
|
|
1057
|
+
}
|
|
1058
|
+
declare class ApprovalClient {
|
|
1059
|
+
private readonly http;
|
|
1060
|
+
private readonly nodeId;
|
|
1061
|
+
private readonly headers;
|
|
1062
|
+
constructor(opts: {
|
|
1063
|
+
baseURL: string;
|
|
1064
|
+
nodeId: string;
|
|
1065
|
+
apiKey?: string;
|
|
1066
|
+
headers?: Record<string, string>;
|
|
1067
|
+
});
|
|
1068
|
+
/**
|
|
1069
|
+
* Request human approval, transitioning the execution to `waiting`.
|
|
1070
|
+
*
|
|
1071
|
+
* Calls `POST /api/v1/agents/{node}/executions/{id}/request-approval`.
|
|
1072
|
+
*/
|
|
1073
|
+
requestApproval(executionId: string, payload: RequestApprovalPayload): Promise<ApprovalRequestResponse>;
|
|
1074
|
+
/**
|
|
1075
|
+
* Get the current approval status for an execution.
|
|
1076
|
+
*
|
|
1077
|
+
* Calls `GET /api/v1/agents/{node}/executions/{id}/approval-status`.
|
|
1078
|
+
*/
|
|
1079
|
+
getApprovalStatus(executionId: string): Promise<ApprovalStatusResponse>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Poll approval status with exponential backoff until resolved.
|
|
1082
|
+
*
|
|
1083
|
+
* Returns once the status is no longer `pending` (i.e. approved, rejected,
|
|
1084
|
+
* or expired).
|
|
1085
|
+
*/
|
|
1086
|
+
waitForApproval(executionId: string, opts?: WaitForApprovalOptions): Promise<ApprovalStatusResponse>;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
export { ACTIVE_STATUSES, AIClient, type AIConfig, type AIEmbeddingOptions, type AIRequestOptions, type AIStream, 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 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, RateLimitError, type RateLimiterOptions, type ReasonerCapability, ReasonerContext, type ReasonerDefinition, type ReasonerHandler, type ReasonerOptions, type RequestApprovalPayload, type ServerlessAdapter, type ServerlessEvent, type ServerlessResponse, type SkillCapability, SkillContext, type SkillDefinition, type SkillHandler, type SkillOptions, StatelessRateLimiter, TERMINAL_STATUSES, type VectorSearchOptions, type VectorSearchResult, type WaitForApprovalOptions, type WorkflowCredential, type WorkflowMetadata, type WorkflowProgressOptions, WorkflowReporter, type ZodSchema, getCurrentContext, getCurrentSkillContext, isActive, isTerminal, normalizeStatus };
|
package/dist/index.js
CHANGED
|
@@ -806,6 +806,7 @@ var AgentFieldClient = class {
|
|
|
806
806
|
type: event.reasonerId,
|
|
807
807
|
agent_node_id: event.agentNodeId,
|
|
808
808
|
status: event.status,
|
|
809
|
+
status_reason: event.statusReason,
|
|
809
810
|
parent_execution_id: event.parentExecutionId,
|
|
810
811
|
parent_workflow_id: event.parentWorkflowId ?? event.workflowId ?? event.runId,
|
|
811
812
|
input_data: event.inputData ?? {},
|
|
@@ -830,7 +831,8 @@ var AgentFieldClient = class {
|
|
|
830
831
|
result: update.result,
|
|
831
832
|
error: update.error,
|
|
832
833
|
duration_ms: update.durationMs,
|
|
833
|
-
progress: update.progress !== void 0 ? Math.round(update.progress) : void 0
|
|
834
|
+
progress: update.progress !== void 0 ? Math.round(update.progress) : void 0,
|
|
835
|
+
status_reason: update.statusReason
|
|
834
836
|
};
|
|
835
837
|
const bodyStr = JSON.stringify(payload);
|
|
836
838
|
const authHeaders = this.didAuthenticator.signRequest(Buffer.from(bodyStr));
|
|
@@ -3219,6 +3221,165 @@ function sanitize(value) {
|
|
|
3219
3221
|
return value.replace(/[^0-9a-zA-Z]+/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
|
|
3220
3222
|
}
|
|
3221
3223
|
|
|
3222
|
-
|
|
3224
|
+
// src/status/ExecutionStatus.ts
|
|
3225
|
+
var ExecutionStatus = {
|
|
3226
|
+
PENDING: "pending",
|
|
3227
|
+
QUEUED: "queued",
|
|
3228
|
+
WAITING: "waiting",
|
|
3229
|
+
RUNNING: "running",
|
|
3230
|
+
SUCCEEDED: "succeeded",
|
|
3231
|
+
FAILED: "failed",
|
|
3232
|
+
CANCELLED: "cancelled",
|
|
3233
|
+
TIMEOUT: "timeout",
|
|
3234
|
+
UNKNOWN: "unknown"
|
|
3235
|
+
};
|
|
3236
|
+
var CANONICAL_STATUSES = new Set(
|
|
3237
|
+
Object.values(ExecutionStatus)
|
|
3238
|
+
);
|
|
3239
|
+
var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
3240
|
+
ExecutionStatus.SUCCEEDED,
|
|
3241
|
+
ExecutionStatus.FAILED,
|
|
3242
|
+
ExecutionStatus.CANCELLED,
|
|
3243
|
+
ExecutionStatus.TIMEOUT
|
|
3244
|
+
]);
|
|
3245
|
+
var ACTIVE_STATUSES = /* @__PURE__ */ new Set([
|
|
3246
|
+
ExecutionStatus.PENDING,
|
|
3247
|
+
ExecutionStatus.QUEUED,
|
|
3248
|
+
ExecutionStatus.WAITING,
|
|
3249
|
+
ExecutionStatus.RUNNING
|
|
3250
|
+
]);
|
|
3251
|
+
var STATUS_ALIASES = {
|
|
3252
|
+
success: "succeeded",
|
|
3253
|
+
successful: "succeeded",
|
|
3254
|
+
completed: "succeeded",
|
|
3255
|
+
complete: "succeeded",
|
|
3256
|
+
done: "succeeded",
|
|
3257
|
+
ok: "succeeded",
|
|
3258
|
+
error: "failed",
|
|
3259
|
+
failure: "failed",
|
|
3260
|
+
errored: "failed",
|
|
3261
|
+
canceled: "cancelled",
|
|
3262
|
+
cancel: "cancelled",
|
|
3263
|
+
timed_out: "timeout",
|
|
3264
|
+
wait: "queued",
|
|
3265
|
+
awaiting_approval: "waiting",
|
|
3266
|
+
awaiting_human: "waiting",
|
|
3267
|
+
approval_pending: "waiting",
|
|
3268
|
+
in_progress: "running",
|
|
3269
|
+
processing: "running"
|
|
3270
|
+
};
|
|
3271
|
+
function normalizeStatus(status) {
|
|
3272
|
+
if (status == null) return "unknown";
|
|
3273
|
+
const normalized = status.trim().toLowerCase();
|
|
3274
|
+
if (!normalized) return "unknown";
|
|
3275
|
+
if (CANONICAL_STATUSES.has(normalized)) return normalized;
|
|
3276
|
+
return STATUS_ALIASES[normalized] ?? "unknown";
|
|
3277
|
+
}
|
|
3278
|
+
function isTerminal(status) {
|
|
3279
|
+
return TERMINAL_STATUSES.has(normalizeStatus(status));
|
|
3280
|
+
}
|
|
3281
|
+
function isActive(status) {
|
|
3282
|
+
return ACTIVE_STATUSES.has(normalizeStatus(status));
|
|
3283
|
+
}
|
|
3284
|
+
var ApprovalClient = class {
|
|
3285
|
+
http;
|
|
3286
|
+
nodeId;
|
|
3287
|
+
headers;
|
|
3288
|
+
constructor(opts) {
|
|
3289
|
+
this.http = axios5.create({
|
|
3290
|
+
baseURL: opts.baseURL.replace(/\/$/, ""),
|
|
3291
|
+
timeout: 3e4,
|
|
3292
|
+
httpAgent,
|
|
3293
|
+
httpsAgent
|
|
3294
|
+
});
|
|
3295
|
+
this.nodeId = opts.nodeId;
|
|
3296
|
+
const merged = { ...opts.headers ?? {} };
|
|
3297
|
+
if (opts.apiKey) {
|
|
3298
|
+
merged["X-API-Key"] = opts.apiKey;
|
|
3299
|
+
}
|
|
3300
|
+
this.headers = merged;
|
|
3301
|
+
}
|
|
3302
|
+
/**
|
|
3303
|
+
* Request human approval, transitioning the execution to `waiting`.
|
|
3304
|
+
*
|
|
3305
|
+
* Calls `POST /api/v1/agents/{node}/executions/{id}/request-approval`.
|
|
3306
|
+
*/
|
|
3307
|
+
async requestApproval(executionId, payload) {
|
|
3308
|
+
const body = {
|
|
3309
|
+
title: payload.title ?? "Approval Request",
|
|
3310
|
+
description: payload.description ?? "",
|
|
3311
|
+
template_type: payload.templateType ?? "plan-review-v1",
|
|
3312
|
+
payload: payload.payload ?? {},
|
|
3313
|
+
project_id: payload.projectId,
|
|
3314
|
+
expires_in_hours: payload.expiresInHours ?? 72
|
|
3315
|
+
};
|
|
3316
|
+
const res = await this.http.post(
|
|
3317
|
+
`/api/v1/agents/${encodeURIComponent(this.nodeId)}/executions/${encodeURIComponent(executionId)}/request-approval`,
|
|
3318
|
+
body,
|
|
3319
|
+
{ headers: { ...this.headers, "Content-Type": "application/json" } }
|
|
3320
|
+
);
|
|
3321
|
+
return {
|
|
3322
|
+
approvalRequestId: res.data.approval_request_id ?? "",
|
|
3323
|
+
approvalRequestUrl: res.data.approval_request_url ?? ""
|
|
3324
|
+
};
|
|
3325
|
+
}
|
|
3326
|
+
/**
|
|
3327
|
+
* Get the current approval status for an execution.
|
|
3328
|
+
*
|
|
3329
|
+
* Calls `GET /api/v1/agents/{node}/executions/{id}/approval-status`.
|
|
3330
|
+
*/
|
|
3331
|
+
async getApprovalStatus(executionId) {
|
|
3332
|
+
const res = await this.http.get(
|
|
3333
|
+
`/api/v1/agents/${encodeURIComponent(this.nodeId)}/executions/${encodeURIComponent(executionId)}/approval-status`,
|
|
3334
|
+
{ headers: this.headers }
|
|
3335
|
+
);
|
|
3336
|
+
const data = res.data;
|
|
3337
|
+
return {
|
|
3338
|
+
status: data.status ?? "pending",
|
|
3339
|
+
response: data.response,
|
|
3340
|
+
requestUrl: data.request_url,
|
|
3341
|
+
requestedAt: data.requested_at,
|
|
3342
|
+
respondedAt: data.responded_at
|
|
3343
|
+
};
|
|
3344
|
+
}
|
|
3345
|
+
/**
|
|
3346
|
+
* Poll approval status with exponential backoff until resolved.
|
|
3347
|
+
*
|
|
3348
|
+
* Returns once the status is no longer `pending` (i.e. approved, rejected,
|
|
3349
|
+
* or expired).
|
|
3350
|
+
*/
|
|
3351
|
+
async waitForApproval(executionId, opts) {
|
|
3352
|
+
const pollInterval = opts?.pollIntervalMs ?? 5e3;
|
|
3353
|
+
const maxInterval = opts?.maxIntervalMs ?? 6e4;
|
|
3354
|
+
const timeout = opts?.timeoutMs;
|
|
3355
|
+
const backoffFactor = 2;
|
|
3356
|
+
const startTime = Date.now();
|
|
3357
|
+
let interval = pollInterval;
|
|
3358
|
+
while (true) {
|
|
3359
|
+
if (timeout != null && Date.now() - startTime >= timeout) {
|
|
3360
|
+
throw new Error(
|
|
3361
|
+
`Approval for execution ${executionId} timed out after ${timeout}ms`
|
|
3362
|
+
);
|
|
3363
|
+
}
|
|
3364
|
+
await sleep(interval);
|
|
3365
|
+
let data;
|
|
3366
|
+
try {
|
|
3367
|
+
data = await this.getApprovalStatus(executionId);
|
|
3368
|
+
} catch {
|
|
3369
|
+
interval = Math.min(interval * backoffFactor, maxInterval);
|
|
3370
|
+
continue;
|
|
3371
|
+
}
|
|
3372
|
+
if (data.status !== "pending") {
|
|
3373
|
+
return data;
|
|
3374
|
+
}
|
|
3375
|
+
interval = Math.min(interval * backoffFactor, maxInterval);
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
};
|
|
3379
|
+
function sleep(ms) {
|
|
3380
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3381
|
+
}
|
|
3382
|
+
|
|
3383
|
+
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, MCPClient, MCPClientRegistry, MCPToolRegistrar, MemoryClient, MemoryEventClient, MemoryInterface, RateLimitError, ReasonerContext, SkillContext, StatelessRateLimiter, TERMINAL_STATUSES, WorkflowReporter, getCurrentContext, getCurrentSkillContext, isActive, isTerminal, normalizeStatus };
|
|
3223
3384
|
//# sourceMappingURL=index.js.map
|
|
3224
3385
|
//# sourceMappingURL=index.js.map
|