@agent-os-sdk/client 0.2.2 → 0.3.0

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.
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Approvals Module - Human-in-the-Loop Native
3
- *
4
- * NOT IMPLEMENTED - Backend endpoint not available.
5
- * All methods return 501 NotImplemented.
3
+ *
4
+ * Wave 2.x: Real implementation for HITL workflow.
5
+ * Endpoints: /v1/api/workspaces/{workspaceId}/approvals
6
6
  */
7
7
 
8
8
  import type { RawClient, APIResponse } from "../client/raw.js";
@@ -11,58 +11,37 @@ import type { RawClient, APIResponse } from "../client/raw.js";
11
11
  // Types
12
12
  // ============================================================================
13
13
 
14
- export type ApprovalStatus = "pending" | "approved" | "rejected" | "expired" | "auto_approved";
14
+ export type ApprovalStatus = "pending" | "approved" | "denied" | "expired";
15
15
 
16
16
  export interface Approval {
17
17
  id: string;
18
18
  run_id: string;
19
- thread_id?: string;
20
- action: string;
21
- payload: Record<string, unknown>;
19
+ attempt_id: string;
20
+ policy_name: string;
21
+ reason: string;
22
22
  status: ApprovalStatus;
23
- reason?: string;
24
- requested_at: string;
25
- responded_at?: string;
26
- responded_by?: string;
27
- expires_at?: string;
28
- auto_approve_after?: number;
23
+ created_at: string;
24
+ decided_at?: string;
25
+ decided_by_actor?: string;
26
+ payload?: Record<string, unknown>;
29
27
  }
30
28
 
31
- export interface ApprovalRequest {
32
- run_id: string;
33
- action: string;
34
- payload: Record<string, unknown>;
35
- expires_in_seconds?: number;
36
- auto_approve_after_seconds?: number;
37
- notify_channels?: string[];
29
+ export interface ApprovalDecision {
30
+ decision: "approve" | "deny";
31
+ comment?: string;
38
32
  }
39
33
 
40
34
  export interface ApprovalListResponse {
41
35
  items: Approval[];
42
36
  total: number;
43
- pending_count: number;
44
- }
45
-
46
- export interface ApprovalDecision {
47
- approval_id: string;
48
- decision: "approve" | "reject";
49
- reason?: string;
50
- modified_payload?: Record<string, unknown>;
51
37
  }
52
38
 
53
- // ============================================================================
54
- // Helper for 501 responses
55
- // ============================================================================
56
-
57
- function notImplemented<T>(method: string): APIResponse<T> {
58
- return {
59
- data: undefined,
60
- error: {
61
- code: "NOT_IMPLEMENTED",
62
- message: `ApprovalsModule.${method}() is not implemented. Backend endpoint not available.`,
63
- },
64
- response: new Response(null, { status: 501, statusText: "Not Implemented" }),
65
- };
39
+ export interface ApprovalStatusResponse {
40
+ id: string;
41
+ status: ApprovalStatus;
42
+ decided_at?: string;
43
+ decided_by_actor?: string;
44
+ decision_comment?: string;
66
45
  }
67
46
 
68
47
  // ============================================================================
@@ -70,40 +49,103 @@ function notImplemented<T>(method: string): APIResponse<T> {
70
49
  // ============================================================================
71
50
 
72
51
  export class ApprovalsModule {
73
- constructor(private client: RawClient, private headers: () => Record<string, string>) { }
74
-
75
- /** @returns 501 Not Implemented */
76
- async list(params?: {
52
+ constructor(
53
+ private client: RawClient,
54
+ private headers: () => Record<string, string>
55
+ ) { }
56
+
57
+ /**
58
+ * List approvals for a workspace.
59
+ * @param workspaceId - Workspace ID
60
+ * @param params - Filter options
61
+ */
62
+ async list(workspaceId: string, params?: {
77
63
  status?: ApprovalStatus;
78
- run_id?: string;
79
64
  limit?: number;
80
- offset?: number;
81
65
  }): Promise<APIResponse<ApprovalListResponse>> {
82
- return notImplemented<ApprovalListResponse>("list");
66
+ return this.client.GET<ApprovalListResponse>(
67
+ "/v1/api/workspaces/{workspaceId}/approvals",
68
+ {
69
+ params: {
70
+ path: { workspaceId },
71
+ query: {
72
+ status: params?.status,
73
+ limit: params?.limit ?? 50
74
+ }
75
+ },
76
+ headers: this.headers(),
77
+ }
78
+ );
83
79
  }
84
80
 
85
- /** @returns 501 Not Implemented */
86
- async get(approvalId: string): Promise<APIResponse<Approval>> {
87
- return notImplemented<Approval>("get");
81
+ /**
82
+ * Get a specific approval by ID.
83
+ * @param workspaceId - Workspace ID
84
+ * @param approvalId - Approval ID
85
+ */
86
+ async get(workspaceId: string, approvalId: string): Promise<APIResponse<Approval>> {
87
+ return this.client.GET<Approval>(
88
+ "/v1/api/workspaces/{workspaceId}/approvals/{approvalId}",
89
+ {
90
+ params: {
91
+ path: { workspaceId, approvalId }
92
+ },
93
+ headers: this.headers(),
94
+ }
95
+ );
88
96
  }
89
97
 
90
- /** @returns 501 Not Implemented */
91
- async create(request: ApprovalRequest): Promise<APIResponse<Approval>> {
92
- return notImplemented<Approval>("create");
98
+ /**
99
+ * Approve an approval request.
100
+ * @param workspaceId - Workspace ID
101
+ * @param approvalId - Approval ID
102
+ * @param comment - Optional reason for approval
103
+ */
104
+ async approve(workspaceId: string, approvalId: string, comment?: string): Promise<APIResponse<ApprovalStatusResponse>> {
105
+ return this.client.POST<ApprovalStatusResponse>(
106
+ "/v1/api/workspaces/{workspaceId}/approvals/{approvalId}/decision",
107
+ {
108
+ params: {
109
+ path: { workspaceId, approvalId }
110
+ },
111
+ body: {
112
+ decision: "approve",
113
+ comment
114
+ },
115
+ headers: this.headers(),
116
+ }
117
+ );
93
118
  }
94
119
 
95
- /** @returns 501 Not Implemented */
96
- async approve(approvalId: string, reason?: string): Promise<APIResponse<Approval>> {
97
- return notImplemented<Approval>("approve");
120
+ /**
121
+ * Deny an approval request.
122
+ * @param workspaceId - Workspace ID
123
+ * @param approvalId - Approval ID
124
+ * @param comment - Optional reason for denial
125
+ */
126
+ async deny(workspaceId: string, approvalId: string, comment?: string): Promise<APIResponse<ApprovalStatusResponse>> {
127
+ return this.client.POST<ApprovalStatusResponse>(
128
+ "/v1/api/workspaces/{workspaceId}/approvals/{approvalId}/decision",
129
+ {
130
+ params: {
131
+ path: { workspaceId, approvalId }
132
+ },
133
+ body: {
134
+ decision: "deny",
135
+ comment
136
+ },
137
+ headers: this.headers(),
138
+ }
139
+ );
98
140
  }
99
141
 
100
- /** @returns 501 Not Implemented */
101
- async reject(approvalId: string, reason?: string): Promise<APIResponse<Approval>> {
102
- return notImplemented<Approval>("reject");
142
+ /**
143
+ * Shorthand: List pending approvals for a workspace.
144
+ */
145
+ async listPending(workspaceId: string, limit = 50): Promise<APIResponse<ApprovalListResponse>> {
146
+ return this.list(workspaceId, { status: "pending", limit });
103
147
  }
104
148
 
105
- /** @returns 501 Not Implemented */
106
- async awaitApproval(runId: string, timeoutSeconds?: number): Promise<APIResponse<Approval>> {
107
- return notImplemented<Approval>("awaitApproval");
108
- }
149
+ // Convenience aliases
150
+ reject = this.deny;
109
151
  }