@bounty-ai/agent-sdk 0.1.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.
@@ -0,0 +1,177 @@
1
+ type SdkContractVersion = "v1";
2
+ type AssignmentStatus = "assigned" | "verifying" | "timed_out";
3
+ type OutcomePayload = Record<string, unknown>;
4
+ type AssignmentResultOutput = {
5
+ type: "table" | "text" | "image" | "file" | "collection";
6
+ key?: string;
7
+ label?: string;
8
+ required?: boolean;
9
+ details?: Record<string, unknown>;
10
+ };
11
+ type AssignmentResultSchema = {
12
+ version?: number;
13
+ outputs: AssignmentResultOutput[];
14
+ };
15
+ type AssignmentOutcome = {
16
+ title: string;
17
+ payload: OutcomePayload;
18
+ requested_unit_price_value?: number;
19
+ requested_total_price_value?: number;
20
+ currency?: string;
21
+ time_window?: string;
22
+ };
23
+ type Assignment = {
24
+ assignment_id: string;
25
+ template_slug: string;
26
+ result_schema: AssignmentResultSchema;
27
+ outcome: AssignmentOutcome;
28
+ };
29
+ type AssignmentEnvelopeV1 = {
30
+ version: SdkContractVersion;
31
+ assignment: Assignment;
32
+ };
33
+ type AssignmentResult = {
34
+ status: AssignmentStatus;
35
+ result?: Record<string, unknown>;
36
+ error?: string;
37
+ };
38
+ type AssignmentAckStatus = "accepted" | "rejected";
39
+ type AssignmentAckRequest = {
40
+ status: AssignmentAckStatus;
41
+ reason?: string;
42
+ };
43
+ type WebhookInput = {
44
+ body: string;
45
+ signature?: string;
46
+ timestamp?: string;
47
+ };
48
+ type SubmitResultRequest = {
49
+ assignmentId: string;
50
+ status: AssignmentStatus;
51
+ result?: Record<string, unknown>;
52
+ error?: string;
53
+ };
54
+ type SubmitErrorRequest = {
55
+ assignmentId: string;
56
+ error: string;
57
+ details?: Record<string, unknown>;
58
+ };
59
+ type ApiErrorBody = {
60
+ code?: string;
61
+ message?: string;
62
+ details?: unknown;
63
+ };
64
+
65
+ declare class SdkError extends Error {
66
+ constructor(message: string);
67
+ }
68
+ declare class ApiError extends SdkError {
69
+ readonly status: number;
70
+ readonly code: string | undefined;
71
+ readonly body: ApiErrorBody | null;
72
+ readonly retryable: boolean;
73
+ constructor(params: {
74
+ status: number;
75
+ message: string;
76
+ code: string | undefined;
77
+ body: ApiErrorBody | null;
78
+ });
79
+ }
80
+
81
+ type ClientOptions = {
82
+ baseUrl: string;
83
+ apiKey: string;
84
+ fetchImpl?: typeof fetch;
85
+ };
86
+ declare class AgentClient {
87
+ private readonly baseUrl;
88
+ private readonly apiKey;
89
+ private readonly fetchImpl;
90
+ constructor(options: ClientOptions);
91
+ ackAssignment(assignmentId: string, request: AssignmentAckRequest): Promise<void>;
92
+ submitResult(input: SubmitResultRequest): Promise<void>;
93
+ submitError(input: SubmitErrorRequest): Promise<void>;
94
+ private post;
95
+ private toApiError;
96
+ }
97
+
98
+ declare function computeWebhookSignature(params: {
99
+ webhookSecret: string;
100
+ timestamp: string;
101
+ body: string;
102
+ }): string;
103
+ declare function verifyWebhookSignature(params: {
104
+ webhookSecret: string;
105
+ timestamp?: string;
106
+ body: string;
107
+ signature?: string;
108
+ }): void;
109
+
110
+ declare const DEFAULT_SIGNATURE_HEADER = "x-bounty-signature";
111
+ declare const DEFAULT_TIMESTAMP_HEADER = "x-bounty-timestamp";
112
+ type WebhookHandlerOptions = {
113
+ webhookSecret: string;
114
+ onAssignment: (params: {
115
+ assignment: Assignment;
116
+ }) => Promise<AssignmentResult>;
117
+ verifySignature?: boolean;
118
+ };
119
+ type WebhookHttpResponse = {
120
+ status: number;
121
+ body: AssignmentResult;
122
+ };
123
+ declare function createWebhookHandler(options: WebhookHandlerOptions): (input: WebhookInput) => Promise<AssignmentResult>;
124
+ declare function executeWebhook(handler: ReturnType<typeof createWebhookHandler>, input: WebhookInput): Promise<WebhookHttpResponse>;
125
+
126
+ declare function createExpressWebhookHandler(options: WebhookHandlerOptions): (req: {
127
+ headers: Record<string, string | string[] | undefined>;
128
+ body?: unknown;
129
+ rawBody?: string;
130
+ }, res: {
131
+ status: (code: number) => {
132
+ json: (payload: unknown) => void;
133
+ };
134
+ }) => Promise<void>;
135
+ declare function createFastifyWebhookHandler(options: WebhookHandlerOptions): (request: {
136
+ headers: Record<string, string | string[] | undefined>;
137
+ body?: unknown;
138
+ rawBody?: string;
139
+ }, reply: {
140
+ code: (statusCode: number) => {
141
+ send: (payload: unknown) => void;
142
+ };
143
+ }) => Promise<void>;
144
+ declare function createNextWebhookHandler(options: WebhookHandlerOptions): (request: Request) => Promise<Response>;
145
+ declare function createHonoWebhookHandler(options: WebhookHandlerOptions): (c: {
146
+ req: {
147
+ text: () => Promise<string>;
148
+ header: (name: string) => string | undefined;
149
+ };
150
+ json: (payload: unknown, status?: number) => Response;
151
+ }) => Promise<Response>;
152
+
153
+ declare function parseAssignmentV1(body: string): Assignment;
154
+ declare function toAssignmentEnvelopeV1(assignment: Assignment): AssignmentEnvelopeV1;
155
+ declare function getContractVersion(): SdkContractVersion;
156
+
157
+ type TableRow = Record<string, unknown>;
158
+ type TablePayload = {
159
+ table: {
160
+ columns: string[];
161
+ rows: TableRow[];
162
+ };
163
+ row_count: number;
164
+ rows_unique: boolean;
165
+ has_contact_method: boolean;
166
+ summary?: string;
167
+ };
168
+ type CreateTableResultOptions = {
169
+ columns?: string[];
170
+ summary?: string;
171
+ contactFields?: string[];
172
+ dedupeBy?: string[];
173
+ };
174
+ declare function createTablePayload(rows: TableRow[], options?: CreateTableResultOptions): TablePayload;
175
+ declare function createTableResult(rows: TableRow[], options?: CreateTableResultOptions): Pick<AssignmentResult, "result">;
176
+
177
+ export { AgentClient, ApiError, type ApiErrorBody, type Assignment, type AssignmentAckRequest, type AssignmentAckStatus, type AssignmentEnvelopeV1, type AssignmentOutcome, type AssignmentResult, type AssignmentResultOutput, type AssignmentResultSchema, type AssignmentStatus, type ClientOptions, type CreateTableResultOptions, DEFAULT_SIGNATURE_HEADER, DEFAULT_TIMESTAMP_HEADER, type OutcomePayload, type SdkContractVersion, SdkError, type SubmitErrorRequest, type SubmitResultRequest, type TablePayload, type TableRow, type WebhookHandlerOptions, type WebhookHttpResponse, type WebhookInput, computeWebhookSignature, createExpressWebhookHandler, createFastifyWebhookHandler, createHonoWebhookHandler, createNextWebhookHandler, createTablePayload, createTableResult, createWebhookHandler, executeWebhook, getContractVersion, parseAssignmentV1, toAssignmentEnvelopeV1, verifyWebhookSignature };
@@ -0,0 +1,177 @@
1
+ type SdkContractVersion = "v1";
2
+ type AssignmentStatus = "assigned" | "verifying" | "timed_out";
3
+ type OutcomePayload = Record<string, unknown>;
4
+ type AssignmentResultOutput = {
5
+ type: "table" | "text" | "image" | "file" | "collection";
6
+ key?: string;
7
+ label?: string;
8
+ required?: boolean;
9
+ details?: Record<string, unknown>;
10
+ };
11
+ type AssignmentResultSchema = {
12
+ version?: number;
13
+ outputs: AssignmentResultOutput[];
14
+ };
15
+ type AssignmentOutcome = {
16
+ title: string;
17
+ payload: OutcomePayload;
18
+ requested_unit_price_value?: number;
19
+ requested_total_price_value?: number;
20
+ currency?: string;
21
+ time_window?: string;
22
+ };
23
+ type Assignment = {
24
+ assignment_id: string;
25
+ template_slug: string;
26
+ result_schema: AssignmentResultSchema;
27
+ outcome: AssignmentOutcome;
28
+ };
29
+ type AssignmentEnvelopeV1 = {
30
+ version: SdkContractVersion;
31
+ assignment: Assignment;
32
+ };
33
+ type AssignmentResult = {
34
+ status: AssignmentStatus;
35
+ result?: Record<string, unknown>;
36
+ error?: string;
37
+ };
38
+ type AssignmentAckStatus = "accepted" | "rejected";
39
+ type AssignmentAckRequest = {
40
+ status: AssignmentAckStatus;
41
+ reason?: string;
42
+ };
43
+ type WebhookInput = {
44
+ body: string;
45
+ signature?: string;
46
+ timestamp?: string;
47
+ };
48
+ type SubmitResultRequest = {
49
+ assignmentId: string;
50
+ status: AssignmentStatus;
51
+ result?: Record<string, unknown>;
52
+ error?: string;
53
+ };
54
+ type SubmitErrorRequest = {
55
+ assignmentId: string;
56
+ error: string;
57
+ details?: Record<string, unknown>;
58
+ };
59
+ type ApiErrorBody = {
60
+ code?: string;
61
+ message?: string;
62
+ details?: unknown;
63
+ };
64
+
65
+ declare class SdkError extends Error {
66
+ constructor(message: string);
67
+ }
68
+ declare class ApiError extends SdkError {
69
+ readonly status: number;
70
+ readonly code: string | undefined;
71
+ readonly body: ApiErrorBody | null;
72
+ readonly retryable: boolean;
73
+ constructor(params: {
74
+ status: number;
75
+ message: string;
76
+ code: string | undefined;
77
+ body: ApiErrorBody | null;
78
+ });
79
+ }
80
+
81
+ type ClientOptions = {
82
+ baseUrl: string;
83
+ apiKey: string;
84
+ fetchImpl?: typeof fetch;
85
+ };
86
+ declare class AgentClient {
87
+ private readonly baseUrl;
88
+ private readonly apiKey;
89
+ private readonly fetchImpl;
90
+ constructor(options: ClientOptions);
91
+ ackAssignment(assignmentId: string, request: AssignmentAckRequest): Promise<void>;
92
+ submitResult(input: SubmitResultRequest): Promise<void>;
93
+ submitError(input: SubmitErrorRequest): Promise<void>;
94
+ private post;
95
+ private toApiError;
96
+ }
97
+
98
+ declare function computeWebhookSignature(params: {
99
+ webhookSecret: string;
100
+ timestamp: string;
101
+ body: string;
102
+ }): string;
103
+ declare function verifyWebhookSignature(params: {
104
+ webhookSecret: string;
105
+ timestamp?: string;
106
+ body: string;
107
+ signature?: string;
108
+ }): void;
109
+
110
+ declare const DEFAULT_SIGNATURE_HEADER = "x-bounty-signature";
111
+ declare const DEFAULT_TIMESTAMP_HEADER = "x-bounty-timestamp";
112
+ type WebhookHandlerOptions = {
113
+ webhookSecret: string;
114
+ onAssignment: (params: {
115
+ assignment: Assignment;
116
+ }) => Promise<AssignmentResult>;
117
+ verifySignature?: boolean;
118
+ };
119
+ type WebhookHttpResponse = {
120
+ status: number;
121
+ body: AssignmentResult;
122
+ };
123
+ declare function createWebhookHandler(options: WebhookHandlerOptions): (input: WebhookInput) => Promise<AssignmentResult>;
124
+ declare function executeWebhook(handler: ReturnType<typeof createWebhookHandler>, input: WebhookInput): Promise<WebhookHttpResponse>;
125
+
126
+ declare function createExpressWebhookHandler(options: WebhookHandlerOptions): (req: {
127
+ headers: Record<string, string | string[] | undefined>;
128
+ body?: unknown;
129
+ rawBody?: string;
130
+ }, res: {
131
+ status: (code: number) => {
132
+ json: (payload: unknown) => void;
133
+ };
134
+ }) => Promise<void>;
135
+ declare function createFastifyWebhookHandler(options: WebhookHandlerOptions): (request: {
136
+ headers: Record<string, string | string[] | undefined>;
137
+ body?: unknown;
138
+ rawBody?: string;
139
+ }, reply: {
140
+ code: (statusCode: number) => {
141
+ send: (payload: unknown) => void;
142
+ };
143
+ }) => Promise<void>;
144
+ declare function createNextWebhookHandler(options: WebhookHandlerOptions): (request: Request) => Promise<Response>;
145
+ declare function createHonoWebhookHandler(options: WebhookHandlerOptions): (c: {
146
+ req: {
147
+ text: () => Promise<string>;
148
+ header: (name: string) => string | undefined;
149
+ };
150
+ json: (payload: unknown, status?: number) => Response;
151
+ }) => Promise<Response>;
152
+
153
+ declare function parseAssignmentV1(body: string): Assignment;
154
+ declare function toAssignmentEnvelopeV1(assignment: Assignment): AssignmentEnvelopeV1;
155
+ declare function getContractVersion(): SdkContractVersion;
156
+
157
+ type TableRow = Record<string, unknown>;
158
+ type TablePayload = {
159
+ table: {
160
+ columns: string[];
161
+ rows: TableRow[];
162
+ };
163
+ row_count: number;
164
+ rows_unique: boolean;
165
+ has_contact_method: boolean;
166
+ summary?: string;
167
+ };
168
+ type CreateTableResultOptions = {
169
+ columns?: string[];
170
+ summary?: string;
171
+ contactFields?: string[];
172
+ dedupeBy?: string[];
173
+ };
174
+ declare function createTablePayload(rows: TableRow[], options?: CreateTableResultOptions): TablePayload;
175
+ declare function createTableResult(rows: TableRow[], options?: CreateTableResultOptions): Pick<AssignmentResult, "result">;
176
+
177
+ export { AgentClient, ApiError, type ApiErrorBody, type Assignment, type AssignmentAckRequest, type AssignmentAckStatus, type AssignmentEnvelopeV1, type AssignmentOutcome, type AssignmentResult, type AssignmentResultOutput, type AssignmentResultSchema, type AssignmentStatus, type ClientOptions, type CreateTableResultOptions, DEFAULT_SIGNATURE_HEADER, DEFAULT_TIMESTAMP_HEADER, type OutcomePayload, type SdkContractVersion, SdkError, type SubmitErrorRequest, type SubmitResultRequest, type TablePayload, type TableRow, type WebhookHandlerOptions, type WebhookHttpResponse, type WebhookInput, computeWebhookSignature, createExpressWebhookHandler, createFastifyWebhookHandler, createHonoWebhookHandler, createNextWebhookHandler, createTablePayload, createTableResult, createWebhookHandler, executeWebhook, getContractVersion, parseAssignmentV1, toAssignmentEnvelopeV1, verifyWebhookSignature };