-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaxons.ts
More file actions
319 lines (277 loc) · 7.65 KB
/
Copy pathaxons.ts
File metadata and controls
319 lines (277 loc) · 7.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../resource';
import { isRequestOptions } from '../../core';
import { APIPromise } from '../../core';
import * as Core from '../../core';
import * as EventsAPI from './events';
import { AxonEventListView, EventListParams, Events } from './events';
import * as SqlAPI from './sql';
import {
Sql,
SqlBatchParams,
SqlBatchResultView,
SqlColumnMetaView,
SqlQueryParams,
SqlQueryResultView,
SqlResultMetaView,
SqlStatementParams,
SqlStepErrorView,
SqlStepResultView,
} from './sql';
import { AxonsCursorIDPage, type AxonsCursorIDPageParams } from '../../pagination';
import { Stream } from '../../streaming';
import { withStreamAutoReconnect } from '@runloop/api-client/lib/streaming-reconnection';
export class Axons extends APIResource {
events: EventsAPI.Events = new EventsAPI.Events(this._client);
sql: SqlAPI.Sql = new SqlAPI.Sql(this._client);
/**
* [Beta] Create a new axon.
*/
create(body?: AxonCreateParams, options?: Core.RequestOptions): Core.APIPromise<AxonView>;
create(options?: Core.RequestOptions): Core.APIPromise<AxonView>;
create(
body: AxonCreateParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<AxonView> {
if (isRequestOptions(body)) {
return this.create({}, body);
}
return this._client.post('/v1/axons', { body, ...options });
}
/**
* [Beta] Get an axon given ID.
*/
retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise<AxonView> {
return this._client.get(`/v1/axons/${id}`, options);
}
/**
* [Beta] List all active axons.
*/
list(
query?: AxonListParams,
options?: Core.RequestOptions,
): Core.PagePromise<AxonViewsAxonsCursorIDPage, AxonView>;
list(options?: Core.RequestOptions): Core.PagePromise<AxonViewsAxonsCursorIDPage, AxonView>;
list(
query: AxonListParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.PagePromise<AxonViewsAxonsCursorIDPage, AxonView> {
if (isRequestOptions(query)) {
return this.list({}, query);
}
return this._client.getAPIList('/v1/axons', AxonViewsAxonsCursorIDPage, { query, ...options });
}
/**
* [Beta] Publish an event to a specified axon.
*/
publish(
id: string,
body: AxonPublishParams,
options?: Core.RequestOptions,
): Core.APIPromise<PublishResultView> {
return this._client.post(`/v1/axons/${id}/publish`, { body, ...options });
}
/**
* [Beta] Subscribe to an axon event stream via server-sent events.
* On idle timeout (408), reconnects with `after_sequence` derived from the last
* received event (internal to {@link withStreamAutoReconnect}).
*/
subscribeSse(
id: string,
query?: AxonSubscribeSseParams,
options?: Core.RequestOptions,
): APIPromise<Stream<AxonEventView>> {
const mergedOptions: Core.RequestOptions = {
...options,
headers: {
Accept: 'text/event-stream',
...options?.headers,
},
};
const { query: _ignoredOptionsQuery, ...restMerged } = mergedOptions;
const initialAfterSequence = query?.after_sequence;
const getStream: (afterSequence: number | undefined) => APIPromise<Stream<AxonEventView>> = (
afterSequence,
) => {
const seq = afterSequence ?? initialAfterSequence;
const streamQuery = seq !== undefined ? { after_sequence: seq.toString() } : undefined;
return this._client.get(`/v1/axons/${id}/subscribe/sse`, {
...restMerged,
stream: true,
...(streamQuery ? { query: streamQuery } : {}),
}) as APIPromise<Stream<AxonEventView>>;
};
return withStreamAutoReconnect(getStream, (item) => item.sequence);
}
}
export class AxonViewsAxonsCursorIDPage extends AxonsCursorIDPage<AxonView> {}
export interface AxonCreateParams {
/**
* (Optional) Name for the axon.
*/
name?: string | null;
}
export interface AxonEventView {
/**
* The axon identifier.
*/
axon_id: string;
/**
* Event type (e.g. push, pull_request).
*/
event_type: string;
/**
* Event origin.
*/
origin: 'EXTERNAL_EVENT' | 'AGENT_EVENT' | 'USER_EVENT' | 'SYSTEM_EVENT';
/**
* JSON-encoded event payload.
*/
payload: string;
/**
* Monotonic sequence number.
*/
sequence: number;
/**
* Event source (e.g. github, slack).
*/
source: string;
/**
* Timestamp in milliseconds since epoch.
*/
timestamp_ms: number;
}
export interface AxonListView {
/**
* List of active axons.
*/
axons: Array<AxonView>;
has_more: boolean;
total_count?: number | null;
}
export interface AxonView {
/**
* The axon identifier.
*/
id: string;
/**
* Creation time in milliseconds since epoch.
*/
created_at_ms: number;
/**
* The name of the axon.
*/
name?: string | null;
}
export interface PublishParams {
/**
* The event type (e.g. push, pull_request).
*/
event_type: string;
/**
* Event origin.
*/
origin: 'EXTERNAL_EVENT' | 'AGENT_EVENT' | 'USER_EVENT';
/**
* Event payload.
*/
payload: string;
/**
* The source of the event (e.g. github, slack).
*/
source: string;
}
export interface PublishResultView {
/**
* Assigned sequence number.
*/
sequence: number;
/**
* Timestamp in milliseconds since epoch.
*/
timestamp_ms: number;
}
export interface AxonCreateParams {
/**
* (Optional) Name for the axon.
*/
name?: string | null;
}
export interface AxonListParams extends AxonsCursorIDPageParams {
/**
* Filter by axon ID.
*/
id?: string;
/**
* If true (default), includes total_count in the response. Set to false to skip
* the count query for better performance on large datasets.
*/
include_total_count?: boolean;
/**
* Filter by axon name (prefix match supported).
*/
name?: string;
/**
* Search by axon ID or name.
*/
search?: string;
}
export interface AxonPublishParams {
/**
* The event type (e.g. push, pull_request).
*/
event_type: string;
/**
* Event origin.
*/
origin: 'EXTERNAL_EVENT' | 'AGENT_EVENT' | 'USER_EVENT';
/**
* Event payload.
*/
payload: string;
/**
* The source of the event (e.g. github, slack).
*/
source: string;
}
export interface AxonSubscribeSseParams {
/**
* Sequence number after which to start streaming. Events with sequence > this
* value are returned. If unset, replay from the beginning.
*/
after_sequence?: number;
}
Axons.AxonViewsAxonsCursorIDPage = AxonViewsAxonsCursorIDPage;
Axons.Events = Events;
Axons.Sql = Sql;
export declare namespace Axons {
export {
type AxonCreateParams as AxonCreateParams,
type AxonEventView as AxonEventView,
type AxonListView as AxonListView,
type AxonView as AxonView,
type PublishParams as PublishParams,
type PublishResultView as PublishResultView,
AxonViewsAxonsCursorIDPage as AxonViewsAxonsCursorIDPage,
type AxonListParams as AxonListParams,
type AxonPublishParams as AxonPublishParams,
type AxonSubscribeSseParams as AxonSubscribeSseParams,
};
export {
Events as Events,
type AxonEventListView as AxonEventListView,
type EventListParams as EventListParams,
};
export {
Sql as Sql,
type SqlBatchParams as SqlBatchParams,
type SqlBatchResultView as SqlBatchResultView,
type SqlColumnMetaView as SqlColumnMetaView,
type SqlQueryResultView as SqlQueryResultView,
type SqlResultMetaView as SqlResultMetaView,
type SqlStatementParams as SqlStatementParams,
type SqlStepErrorView as SqlStepErrorView,
type SqlStepResultView as SqlStepResultView,
type SqlQueryParams as SqlQueryParams,
};
}