@inferencesh/sdk 0.29.0 → 0.29.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/agent/actions.js +1 -0
- package/dist/agent/types.d.ts +3 -1
- package/dist/api/tasks.js +4 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/types.d.ts +74 -2
- package/dist/types.js +18 -0
- package/dist/utils.d.ts +11 -1
- package/dist/utils.js +16 -6
- package/package.json +1 -1
package/dist/agent/actions.js
CHANGED
package/dist/agent/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Public types for the Agent chat module.
|
|
5
5
|
*/
|
|
6
6
|
import type { Dispatch } from 'react';
|
|
7
|
-
import type { AgentRunDTO, AgentVersionDTO, AlwaysAllowOptionsDTO, AlwaysAllowResultDTO, ToolExplanationDTO, ChatAgentDTO, ChatDTO, ChatMessageDTO, ChatSettingsDTO, ChatSettingsRequest, AgentTool, AgentConfigInput as GeneratedAgentConfig, CoreAppConfigInput as CoreAppConfig, FileRef, ElicitResult } from '../types.js';
|
|
7
|
+
import type { AgentRunDTO, AgentVersionDTO, AlwaysAllowOptionsDTO, AlwaysAllowResultDTO, ToolExplanationDTO, ChatAgentDTO, ChatDTO, ChatMessageDTO, ChatSettingsDTO, ChatSettingsRequest, AgentTool, AgentConfigInput as GeneratedAgentConfig, CoreAppConfigInput as CoreAppConfig, FileRef, ElicitResult, InterruptDTO } from '../types.js';
|
|
8
8
|
import type { HttpClient } from '../http/client.js';
|
|
9
9
|
import type { ClientToolResult } from '../tool-builder.js';
|
|
10
10
|
import type { StreamableManager } from '../http/streamable.js';
|
|
@@ -190,6 +190,8 @@ export interface AgentChatActions {
|
|
|
190
190
|
* `requires_sign_in` (ErrorCodeRequiresSignIn).
|
|
191
191
|
*/
|
|
192
192
|
resolveInterrupt: (interruptId: string, decision: 'allow' | 'deny') => Promise<void>;
|
|
193
|
+
/** A run's pending interrupts (`heldTurn` finds a held turn among them). */
|
|
194
|
+
listRunInterrupts: (runId: string) => Promise<InterruptDTO[]>;
|
|
193
195
|
/** Load older messages (scroll-up pagination). Returns true if more exist. */
|
|
194
196
|
loadOlderMessages: () => Promise<boolean>;
|
|
195
197
|
/** Whether there are older messages to load */
|
package/dist/api/tasks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { streamUntilTerminal } from '../http/stream-until-terminal.js';
|
|
2
2
|
import { PollManager } from '../http/poll.js';
|
|
3
|
-
import { TaskStatusCompleted, TaskStatusFailed, TaskStatusCancelled, } from '../types.js';
|
|
3
|
+
import { TaskStatusCompleted, TaskStatusFailed, TaskStatusCancelled, TaskStatusRejected, } from '../types.js';
|
|
4
4
|
import { parseStatus } from '../utils.js';
|
|
5
5
|
//TODO: This is ugly...
|
|
6
6
|
function stripTask(task) {
|
|
@@ -28,6 +28,9 @@ function settleTerminal(data, stripped, settle) {
|
|
|
28
28
|
case TaskStatusCancelled:
|
|
29
29
|
settle.reject(new Error('task cancelled'));
|
|
30
30
|
break;
|
|
31
|
+
case TaskStatusRejected:
|
|
32
|
+
settle.reject(new Error(data.error || 'task rejected'));
|
|
33
|
+
break;
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -36,8 +36,8 @@ export type { ClientTool, ClientToolHandler, ClientToolResult } from './tool-bui
|
|
|
36
36
|
export { lifecycleHook, learningHooks } from './hook-builder.js';
|
|
37
37
|
export type { LifecycleHookBuilder } from './hook-builder.js';
|
|
38
38
|
export { DeltaAccumulator, createLLMDeltaAccumulator, type DeltaEvent, type FieldTags, type FieldTagsRegistry } from './delta.js';
|
|
39
|
-
export { parseStatus, isTerminalStatus, isChatBusy, isAwaitingHuman, isRunTerminal, isRunInterrupted, isRunSettled, isRunWorking, isMessageTerminal, pendingApprovals, } from './utils.js';
|
|
40
|
-
export type { PendingApproval } from './utils.js';
|
|
39
|
+
export { parseStatus, isTerminalStatus, isChatBusy, isAwaitingHuman, isRunTerminal, isRunInterrupted, isRunSettled, isRunWorking, isMessageTerminal, pendingApprovals, heldTurn, } from './utils.js';
|
|
40
|
+
export type { PendingApproval, HeldTurn } from './utils.js';
|
|
41
41
|
export * from './types.js';
|
|
42
42
|
export type { TaskDTO as Task } from './types.js';
|
|
43
43
|
import { HttpClient, type HttpClientConfig } from './http/client.js';
|
package/dist/index.js
CHANGED
|
@@ -38,7 +38,7 @@ export { lifecycleHook, learningHooks } from './hook-builder.js';
|
|
|
38
38
|
// Delta accumulator for streaming responses
|
|
39
39
|
export { DeltaAccumulator, createLLMDeltaAccumulator } from './delta.js';
|
|
40
40
|
// Status utilities (handle both int and string status values)
|
|
41
|
-
export { parseStatus, isTerminalStatus, isChatBusy, isAwaitingHuman, isRunTerminal, isRunInterrupted, isRunSettled, isRunWorking, isMessageTerminal, pendingApprovals, } from './utils.js';
|
|
41
|
+
export { parseStatus, isTerminalStatus, isChatBusy, isAwaitingHuman, isRunTerminal, isRunInterrupted, isRunSettled, isRunWorking, isMessageTerminal, pendingApprovals, heldTurn, } from './utils.js';
|
|
42
42
|
// Types - includes TaskStatus constants and all DTOs
|
|
43
43
|
export * from './types.js';
|
|
44
44
|
// =============================================================================
|
package/dist/types.d.ts
CHANGED
|
@@ -1489,6 +1489,34 @@ export interface CredentialRequirement {
|
|
|
1489
1489
|
* Auth is the credential's auth provider, for a slug no row defines yet.
|
|
1490
1490
|
*/
|
|
1491
1491
|
auth?: AuthMethod;
|
|
1492
|
+
/**
|
|
1493
|
+
* The rest describe the platform api_key scheme a platform app's deploy
|
|
1494
|
+
* catalogues for the slug: set on the scheme it creates, and filled into
|
|
1495
|
+
* an existing one only where that is still empty (an admin's edit
|
|
1496
|
+
* stands). Any other deploy ignores them.
|
|
1497
|
+
* DisplayName is the scheme's name ("Claude Code"); at most
|
|
1498
|
+
* MaxCredentialDisplayName characters.
|
|
1499
|
+
*/
|
|
1500
|
+
display_name?: string;
|
|
1501
|
+
/**
|
|
1502
|
+
* ConnectionScope is who a connection belongs to: team (empty) or user.
|
|
1503
|
+
*/
|
|
1504
|
+
connection_scope?: CredentialScope;
|
|
1505
|
+
/**
|
|
1506
|
+
* Instructions tell a person how to get the key (markdown, at most
|
|
1507
|
+
* MaxAuthProviderInstructions characters).
|
|
1508
|
+
*/
|
|
1509
|
+
instructions?: string;
|
|
1510
|
+
/**
|
|
1511
|
+
* DocsURL is the scheme's documentation link.
|
|
1512
|
+
*/
|
|
1513
|
+
docs_url?: string;
|
|
1514
|
+
/**
|
|
1515
|
+
* ExpiresAfterDays is how long a saved key lasts: it counts as expired
|
|
1516
|
+
* this many days after it is saved. 0 is never; at most
|
|
1517
|
+
* MaxExpiresAfterDays.
|
|
1518
|
+
*/
|
|
1519
|
+
expires_after_days?: number;
|
|
1492
1520
|
}
|
|
1493
1521
|
/**
|
|
1494
1522
|
* CompanySeed is a provider (the company behind a credential) as an app
|
|
@@ -2652,9 +2680,20 @@ export interface CredentialConfigDTO {
|
|
|
2652
2680
|
description: string;
|
|
2653
2681
|
icon_url?: string;
|
|
2654
2682
|
how_it_works?: string[];
|
|
2683
|
+
/**
|
|
2684
|
+
* Instructions tell a person how to get what this credential asks for
|
|
2685
|
+
* (markdown, links allowed): the auth scheme's.
|
|
2686
|
+
*/
|
|
2687
|
+
instructions?: string;
|
|
2655
2688
|
docs_url?: string;
|
|
2656
2689
|
secret_fields?: SecretFieldConfig[];
|
|
2657
2690
|
allows_byok: boolean;
|
|
2691
|
+
/**
|
|
2692
|
+
* ExpiresAfterDays is how long a saved key lasts, in days: a key counts
|
|
2693
|
+
* as expired that long after it is saved (its credential's expires_at).
|
|
2694
|
+
* 0 is never.
|
|
2695
|
+
*/
|
|
2696
|
+
expires_after_days?: number;
|
|
2658
2697
|
available: boolean;
|
|
2659
2698
|
has_managed: boolean;
|
|
2660
2699
|
/**
|
|
@@ -2702,6 +2741,10 @@ export interface SecretFieldConfig {
|
|
|
2702
2741
|
placeholder: string;
|
|
2703
2742
|
sensitive: boolean;
|
|
2704
2743
|
optional: boolean;
|
|
2744
|
+
/**
|
|
2745
|
+
* Pattern is the scheme field's pattern (shared.SecretField.Pattern).
|
|
2746
|
+
*/
|
|
2747
|
+
pattern?: string;
|
|
2705
2748
|
}
|
|
2706
2749
|
/**
|
|
2707
2750
|
* SearchRequest represents a search request.
|
|
@@ -3017,7 +3060,7 @@ export interface DecideEntitlementRequestRequest {
|
|
|
3017
3060
|
* and APIError.Code on the legacy envelope. Clients branch on these, so a
|
|
3018
3061
|
* code is a named const here, where it generates into models and the SDKs.
|
|
3019
3062
|
*/
|
|
3020
|
-
export type ErrorCode = "invalid_request" | "validation_error" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "name_conflict" | "already_exists" | "not_configured" | "method_not_allowed" | "rate_limited" | "internal_error" | "team_role_required" | "blocked_by_usage_policy" | "last_owner" | "account_deactivated" | "account_banned" | "person_required" | "otp_required" | "requires_sign_in" | "insufficient_scope" | "invalid_scope" | "impersonation_reason_required" | "mcp_auth_expired" | "admin_session_required" | "admin_scopes_not_approved" | "cli_session_required" | "admin_required" | "same_admin_required" | "browser_session_required" | "invalid_ttl" | "admin_authenticator_required" | "limit_exceeded" | "feature_not_available" | "entitlement_unavailable" | "payment_required" | "payment_method_required" | "form_closed" | "already_submitted" | "already_claimed" | "already_entitled" | "request_open" | "invalid_code" | "already_processed" | "expired" | "code_confirmation_required" | "app_retired" | "app_maintenance" | "invalid_transition" | "SESSION_NOT_FOUND" | "SESSION_EXPIRED" | "SESSION_ENDED" | "WORKER_LEASED" | "APP_MISMATCH" | "VERSION_MISMATCH" | "agents_disabled" | "remote_offline" | "remote_timeout" | "harness_not_drivable" | "harness_too_old";
|
|
3063
|
+
export type ErrorCode = "invalid_request" | "validation_error" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "name_conflict" | "already_exists" | "not_configured" | "method_not_allowed" | "rate_limited" | "internal_error" | "requirements_not_met" | "team_role_required" | "blocked_by_usage_policy" | "last_owner" | "account_deactivated" | "account_banned" | "person_required" | "otp_required" | "requires_sign_in" | "insufficient_scope" | "invalid_scope" | "impersonation_reason_required" | "mcp_auth_expired" | "admin_session_required" | "admin_scopes_not_approved" | "cli_session_required" | "admin_required" | "same_admin_required" | "browser_session_required" | "invalid_ttl" | "admin_authenticator_required" | "limit_exceeded" | "feature_not_available" | "entitlement_unavailable" | "payment_required" | "payment_method_required" | "form_closed" | "already_submitted" | "already_claimed" | "already_entitled" | "request_open" | "invalid_code" | "already_processed" | "expired" | "code_confirmation_required" | "app_retired" | "app_maintenance" | "invalid_transition" | "SESSION_NOT_FOUND" | "SESSION_EXPIRED" | "SESSION_ENDED" | "WORKER_LEASED" | "APP_MISMATCH" | "VERSION_MISMATCH" | "agents_disabled" | "remote_offline" | "remote_timeout" | "harness_not_drivable" | "harness_too_old";
|
|
3021
3064
|
export declare const ErrorCodeInvalidRequest: ErrorCode;
|
|
3022
3065
|
export declare const ErrorCodeValidationError: ErrorCode;
|
|
3023
3066
|
export declare const ErrorCodeUnauthorized: ErrorCode;
|
|
@@ -3030,6 +3073,12 @@ export declare const ErrorCodeNotConfigured: ErrorCode;
|
|
|
3030
3073
|
export declare const ErrorCodeMethodNotAllowed: ErrorCode;
|
|
3031
3074
|
export declare const ErrorCodeRateLimited: ErrorCode;
|
|
3032
3075
|
export declare const ErrorCodeInternalError: ErrorCode;
|
|
3076
|
+
/**
|
|
3077
|
+
* ErrorCodeRequirementsNotMet (412): the run needs a secret or a
|
|
3078
|
+
* credential the caller has not set up. Meta "errors" lists each
|
|
3079
|
+
* RequirementError, its action saying how to set it up.
|
|
3080
|
+
*/
|
|
3081
|
+
export declare const ErrorCodeRequirementsNotMet: ErrorCode;
|
|
3033
3082
|
/**
|
|
3034
3083
|
* ErrorCodeTeamRoleRequired: the caller's team role or org-admin status
|
|
3035
3084
|
* does not allow the action. Meta is TeamRoleRequiredMeta when a
|
|
@@ -4723,6 +4772,11 @@ export interface SetupAction {
|
|
|
4723
4772
|
* list comes from; sent back when the keys are saved.
|
|
4724
4773
|
*/
|
|
4725
4774
|
provider_website?: string;
|
|
4775
|
+
/**
|
|
4776
|
+
* Instructions tell a person how to get what the provider's scheme
|
|
4777
|
+
* asks for (markdown, links allowed).
|
|
4778
|
+
*/
|
|
4779
|
+
instructions?: string;
|
|
4726
4780
|
}
|
|
4727
4781
|
/**
|
|
4728
4782
|
* CheckRequirementsRequest is the request body for checking requirements
|
|
@@ -5759,6 +5813,12 @@ export interface SecretField {
|
|
|
5759
5813
|
placeholder?: string;
|
|
5760
5814
|
sensitive?: boolean;
|
|
5761
5815
|
optional?: boolean;
|
|
5816
|
+
/**
|
|
5817
|
+
* Pattern, when set, is a regular expression (RE2) a saved value must
|
|
5818
|
+
* match, so a pasted login link or the wrong key is refused on save
|
|
5819
|
+
* instead of failing the first run ("^sk-ant-oat01-").
|
|
5820
|
+
*/
|
|
5821
|
+
pattern?: string;
|
|
5762
5822
|
}
|
|
5763
5823
|
/**
|
|
5764
5824
|
* AuthMethodClientAuth is how client_id/client_secret reach the token
|
|
@@ -6650,6 +6710,12 @@ export declare const GraphEdgeTypeReferences: GraphEdgeType;
|
|
|
6650
6710
|
export declare const GraphEdgeTypeSupersedes: GraphEdgeType;
|
|
6651
6711
|
export declare const GraphEdgeTypeInput: GraphEdgeType;
|
|
6652
6712
|
export declare const GraphEdgeTypeOutput: GraphEdgeType;
|
|
6713
|
+
/**
|
|
6714
|
+
* InterruptResourceTurn is an interrupt that holds a run's next turn before
|
|
6715
|
+
* its model call, with nothing in flight; its ResourceID is the run's. An
|
|
6716
|
+
* allow starts the turn, a deny ends the run.
|
|
6717
|
+
*/
|
|
6718
|
+
export declare const InterruptResourceTurn: InterruptResourceType;
|
|
6653
6719
|
/**
|
|
6654
6720
|
* MergeStrategy defines how a delta field should be merged by consumers.
|
|
6655
6721
|
*/
|
|
@@ -7456,6 +7522,12 @@ export declare const TaskStatusUploading: TaskStatus;
|
|
|
7456
7522
|
export declare const TaskStatusCompleted: TaskStatus;
|
|
7457
7523
|
export declare const TaskStatusFailed: TaskStatus;
|
|
7458
7524
|
export declare const TaskStatusCancelled: TaskStatus;
|
|
7525
|
+
/**
|
|
7526
|
+
* TaskStatusRejected is a run admission refused (no balance, no payment
|
|
7527
|
+
* method). The task is written already ended, keeping what was asked
|
|
7528
|
+
* for; it never ran and no status leads to it.
|
|
7529
|
+
*/
|
|
7530
|
+
export declare const TaskStatusRejected: TaskStatus;
|
|
7459
7531
|
/**
|
|
7460
7532
|
* Infra defines where a task should run.
|
|
7461
7533
|
*/
|
|
@@ -7801,7 +7873,7 @@ export declare const InterruptResolutionDeny: InterruptResolution;
|
|
|
7801
7873
|
/**
|
|
7802
7874
|
* InterruptResourceType identifies the kind of resource an interrupt gates.
|
|
7803
7875
|
*/
|
|
7804
|
-
export type InterruptResourceType = "tool_invocation" | "hook_event";
|
|
7876
|
+
export type InterruptResourceType = "turn" | "tool_invocation" | "hook_event";
|
|
7805
7877
|
export declare const InterruptResourceToolInvocation: InterruptResourceType;
|
|
7806
7878
|
export declare const InterruptResourceHookEvent: InterruptResourceType;
|
|
7807
7879
|
/**
|
package/dist/types.js
CHANGED
|
@@ -389,6 +389,12 @@ export const ErrorCodeNotConfigured = "not_configured";
|
|
|
389
389
|
export const ErrorCodeMethodNotAllowed = "method_not_allowed";
|
|
390
390
|
export const ErrorCodeRateLimited = "rate_limited";
|
|
391
391
|
export const ErrorCodeInternalError = "internal_error";
|
|
392
|
+
/**
|
|
393
|
+
* ErrorCodeRequirementsNotMet (412): the run needs a secret or a
|
|
394
|
+
* credential the caller has not set up. Meta "errors" lists each
|
|
395
|
+
* RequirementError, its action saying how to set it up.
|
|
396
|
+
*/
|
|
397
|
+
export const ErrorCodeRequirementsNotMet = "requirements_not_met";
|
|
392
398
|
/**
|
|
393
399
|
* ErrorCodeTeamRoleRequired: the caller's team role or org-admin status
|
|
394
400
|
* does not allow the action. Meta is TeamRoleRequiredMeta when a
|
|
@@ -980,6 +986,12 @@ export const GraphEdgeTypeReferences = "references";
|
|
|
980
986
|
export const GraphEdgeTypeSupersedes = "supersedes";
|
|
981
987
|
export const GraphEdgeTypeInput = "input";
|
|
982
988
|
export const GraphEdgeTypeOutput = "output";
|
|
989
|
+
/**
|
|
990
|
+
* InterruptResourceTurn is an interrupt that holds a run's next turn before
|
|
991
|
+
* its model call, with nothing in flight; its ResourceID is the run's. An
|
|
992
|
+
* allow starts the turn, a deny ends the run.
|
|
993
|
+
*/
|
|
994
|
+
export const InterruptResourceTurn = "turn";
|
|
983
995
|
export const MergeStrategyConcat = "concat";
|
|
984
996
|
export const MergeStrategyReplace = "replace";
|
|
985
997
|
export const MergeStrategyIndexed = "indexed";
|
|
@@ -1455,6 +1467,12 @@ export const TaskStatusUploading = 9;
|
|
|
1455
1467
|
export const TaskStatusCompleted = 10;
|
|
1456
1468
|
export const TaskStatusFailed = 11;
|
|
1457
1469
|
export const TaskStatusCancelled = 12;
|
|
1470
|
+
/**
|
|
1471
|
+
* TaskStatusRejected is a run admission refused (no balance, no payment
|
|
1472
|
+
* method). The task is written already ended, keeping what was asked
|
|
1473
|
+
* for; it never ran and no status leads to it.
|
|
1474
|
+
*/
|
|
1475
|
+
export const TaskStatusRejected = 13;
|
|
1458
1476
|
export const InfraPrivate = "private";
|
|
1459
1477
|
export const InfraCloud = "cloud";
|
|
1460
1478
|
export const InfraPrivateFirst = "private_first";
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Status utilities for handling both int and string-based status values.
|
|
3
3
|
* Provides future compatibility when API migrates from int to string status.
|
|
4
4
|
*/
|
|
5
|
+
import type { InterruptDTO } from './types.js';
|
|
5
6
|
import { TaskStatus } from './types.js';
|
|
6
7
|
import type { AgentRunState, ChatDTO, ChatMessageStatus } from './types.js';
|
|
7
8
|
/**
|
|
@@ -10,7 +11,7 @@ import type { AgentRunState, ChatDTO, ChatMessageStatus } from './types.js';
|
|
|
10
11
|
*/
|
|
11
12
|
export declare function parseStatus(status: number | string | undefined | null): TaskStatus;
|
|
12
13
|
/**
|
|
13
|
-
* Check if a task status is terminal (completed, failed, or
|
|
14
|
+
* Check if a task status is terminal (completed, failed, cancelled, or rejected).
|
|
14
15
|
* Handles both int and string status values.
|
|
15
16
|
*/
|
|
16
17
|
export declare function isTerminalStatus(status: number | string | undefined | null): boolean;
|
|
@@ -39,3 +40,12 @@ export type PendingApproval = {
|
|
|
39
40
|
* which the API projects onto the chat, so no message scan is needed.
|
|
40
41
|
*/
|
|
41
42
|
export declare function pendingApprovals(chat: ChatDTO | null | undefined): PendingApproval[];
|
|
43
|
+
/** A run's next turn held for the person (InterruptResourceTurn): after a long stretch without them, it waits for "keep going" (allow) or "stop" (deny). */
|
|
44
|
+
export type HeldTurn = {
|
|
45
|
+
interruptId: string;
|
|
46
|
+
runId: string;
|
|
47
|
+
/** Steps the run took without the person, when the api says. */
|
|
48
|
+
steps: number | null;
|
|
49
|
+
};
|
|
50
|
+
/** The held turn among a run's pending interrupts, if one is held. */
|
|
51
|
+
export declare function heldTurn(interrupts: InterruptDTO[] | null | undefined): HeldTurn | null;
|
package/dist/utils.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Status utilities for handling both int and string-based status values.
|
|
3
3
|
* Provides future compatibility when API migrates from int to string status.
|
|
4
4
|
*/
|
|
5
|
-
import { InterruptReasonToolApproval, InterruptStatusPending } from './types.js';
|
|
6
|
-
import { TaskStatusUnknown, TaskStatusReceived, TaskStatusQueued, TaskStatusDispatched, TaskStatusPreparing, TaskStatusServing, TaskStatusSettingUp, TaskStatusRunning, TaskStatusCancelling, TaskStatusUploading, TaskStatusCompleted, TaskStatusFailed, TaskStatusCancelled, AgentRunStateWorking, AgentRunStateSubmitted, AgentRunStateInputRequired, AgentRunStateAuthRequired, AgentRunStateCompleted, AgentRunStateFailed, AgentRunStateCanceled, AgentRunStateRejected, ChatMessageStatusReady, ChatMessageStatusFailed, ChatMessageStatusCancelled, ChatStatusBusy, ChatStatusAwaitingInput, } from './types.js';
|
|
5
|
+
import { InterruptReasonToolApproval, InterruptResourceTurn, InterruptStatusPending } from './types.js';
|
|
6
|
+
import { TaskStatusUnknown, TaskStatusReceived, TaskStatusQueued, TaskStatusDispatched, TaskStatusPreparing, TaskStatusServing, TaskStatusSettingUp, TaskStatusRunning, TaskStatusCancelling, TaskStatusUploading, TaskStatusCompleted, TaskStatusFailed, TaskStatusCancelled, TaskStatusRejected, AgentRunStateWorking, AgentRunStateSubmitted, AgentRunStateInputRequired, AgentRunStateAuthRequired, AgentRunStateCompleted, AgentRunStateFailed, AgentRunStateCanceled, AgentRunStateRejected, ChatMessageStatusReady, ChatMessageStatusFailed, ChatMessageStatusCancelled, ChatStatusBusy, ChatStatusAwaitingInput, } from './types.js';
|
|
7
7
|
/** Map string status names to TaskStatus values (for future string-based API) */
|
|
8
8
|
const STATUS_STRING_MAP = {
|
|
9
9
|
unknown: TaskStatusUnknown,
|
|
@@ -19,6 +19,7 @@ const STATUS_STRING_MAP = {
|
|
|
19
19
|
completed: TaskStatusCompleted,
|
|
20
20
|
failed: TaskStatusFailed,
|
|
21
21
|
cancelled: TaskStatusCancelled,
|
|
22
|
+
rejected: TaskStatusRejected,
|
|
22
23
|
};
|
|
23
24
|
/**
|
|
24
25
|
* Parse task status from int or string to TaskStatus number.
|
|
@@ -37,12 +38,12 @@ export function parseStatus(status) {
|
|
|
37
38
|
return TaskStatusUnknown;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
|
-
* Check if a task status is terminal (completed, failed, or
|
|
41
|
+
* Check if a task status is terminal (completed, failed, cancelled, or rejected).
|
|
41
42
|
* Handles both int and string status values.
|
|
42
43
|
*/
|
|
43
44
|
export function isTerminalStatus(status) {
|
|
44
45
|
const parsed = parseStatus(status);
|
|
45
|
-
return parsed === TaskStatusCompleted || parsed === TaskStatusFailed || parsed === TaskStatusCancelled;
|
|
46
|
+
return parsed === TaskStatusCompleted || parsed === TaskStatusFailed || parsed === TaskStatusCancelled || parsed === TaskStatusRejected;
|
|
46
47
|
}
|
|
47
48
|
// Run and message state predicates. Ports of the Go methods AgentRunState.IsTerminal/
|
|
48
49
|
// IsInterrupted/IsSettled and ChatMessageStatus.IsTerminal; every consumer uses these.
|
|
@@ -79,7 +80,8 @@ export function isAwaitingHuman(chat) {
|
|
|
79
80
|
return isRunInterrupted(run.state);
|
|
80
81
|
return chat?.status === ChatStatusAwaitingInput;
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
/** An interrupt's meta, which arrives as an object or a JSON string. */
|
|
84
|
+
function parseMeta(interrupt) {
|
|
83
85
|
const meta = interrupt.meta;
|
|
84
86
|
if (!meta)
|
|
85
87
|
return {};
|
|
@@ -104,7 +106,7 @@ export function pendingApprovals(chat) {
|
|
|
104
106
|
if (interrupt.reason !== InterruptReasonToolApproval || interrupt.status !== InterruptStatusPending) {
|
|
105
107
|
continue;
|
|
106
108
|
}
|
|
107
|
-
const meta =
|
|
109
|
+
const meta = parseMeta(interrupt);
|
|
108
110
|
out.push({
|
|
109
111
|
interruptId: interrupt.id,
|
|
110
112
|
toolInvocationId: interrupt.resource_id ?? meta.tool_invocation_id ?? '',
|
|
@@ -115,3 +117,11 @@ export function pendingApprovals(chat) {
|
|
|
115
117
|
}
|
|
116
118
|
return out;
|
|
117
119
|
}
|
|
120
|
+
/** The held turn among a run's pending interrupts, if one is held. */
|
|
121
|
+
export function heldTurn(interrupts) {
|
|
122
|
+
const interrupt = interrupts?.find(i => i.resource_type === InterruptResourceTurn && i.status === InterruptStatusPending);
|
|
123
|
+
if (!interrupt)
|
|
124
|
+
return null;
|
|
125
|
+
const { steps } = parseMeta(interrupt);
|
|
126
|
+
return { interruptId: interrupt.id, runId: interrupt.run_id, steps: typeof steps === 'number' ? steps : null };
|
|
127
|
+
}
|