@introspection-sdk/introspection-node 0.5.0 → 0.5.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.
Files changed (37) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/pagination.d.ts +38 -0
  3. package/dist/pagination.d.ts.map +1 -0
  4. package/dist/pagination.js +43 -0
  5. package/dist/pagination.js.map +1 -0
  6. package/dist/resources/experiments.d.ts +6 -4
  7. package/dist/resources/experiments.d.ts.map +1 -1
  8. package/dist/resources/experiments.js +11 -15
  9. package/dist/resources/experiments.js.map +1 -1
  10. package/dist/resources/recipes.d.ts +6 -4
  11. package/dist/resources/recipes.d.ts.map +1 -1
  12. package/dist/resources/recipes.js +11 -15
  13. package/dist/resources/recipes.js.map +1 -1
  14. package/dist/resources/runtimes.d.ts +6 -4
  15. package/dist/resources/runtimes.d.ts.map +1 -1
  16. package/dist/resources/runtimes.js +11 -15
  17. package/dist/resources/runtimes.js.map +1 -1
  18. package/dist/runner-resources/conversations.d.ts +14 -10
  19. package/dist/runner-resources/conversations.d.ts.map +1 -1
  20. package/dist/runner-resources/conversations.js +24 -30
  21. package/dist/runner-resources/conversations.js.map +1 -1
  22. package/dist/runner-resources/files.d.ts +14 -11
  23. package/dist/runner-resources/files.d.ts.map +1 -1
  24. package/dist/runner-resources/files.js +31 -36
  25. package/dist/runner-resources/files.js.map +1 -1
  26. package/dist/runner-resources/tasks.d.ts +6 -4
  27. package/dist/runner-resources/tasks.d.ts.map +1 -1
  28. package/dist/runner-resources/tasks.js +11 -15
  29. package/dist/runner-resources/tasks.js.map +1 -1
  30. package/package.json +6 -6
  31. package/src/pagination.ts +69 -0
  32. package/src/resources/experiments.ts +15 -14
  33. package/src/resources/recipes.ts +15 -14
  34. package/src/resources/runtimes.ts +15 -14
  35. package/src/runner-resources/conversations.ts +37 -33
  36. package/src/runner-resources/files.ts +52 -37
  37. package/src/runner-resources/tasks.ts +15 -14
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  File as FileResource,
3
+ FileCreateOptions,
3
4
  FileCreateTextParams,
4
5
  FileListParams,
5
6
  FileType,
@@ -8,6 +9,7 @@ import type {
8
9
  Paginated,
9
10
  } from "@introspection-sdk/types";
10
11
  import { HttpClient } from "../http.js";
12
+ import { Paginator, cursorPaginate } from "../pagination.js";
11
13
 
12
14
  export type FileUploadBody =
13
15
  | { file: Blob; name?: string; file_type?: FileType }
@@ -22,23 +24,20 @@ export class FileVersionsApi {
22
24
  constructor(private readonly http: HttpClient) {}
23
25
 
24
26
  /**
25
- * Iterate versions of a file. Pages are fetched lazily as the
26
- * iterator is consumed; stop early to stop fetching.
27
+ * List versions of a file. `await` the result for the first page, or
28
+ * `for await` it to stream every version across pages (fetched lazily;
29
+ * stop early to stop fetching).
27
30
  */
28
- async *list(
29
- fileId: string,
30
- params?: ListParams,
31
- ): AsyncIterable<FileResource> {
32
- let next: string | undefined = params?.next;
33
- do {
34
- const page = await this.http.request<Paginated<FileResource>>({
35
- method: "GET",
36
- path: `/v1/files/${encodeURIComponent(fileId)}/versions`,
37
- query: { ...params, next } as Record<string, unknown>,
38
- });
39
- for (const f of page.records) yield f;
40
- next = page.next ?? undefined;
41
- } while (next);
31
+ list(fileId: string, params?: ListParams): Paginator<FileResource> {
32
+ return cursorPaginate(
33
+ (next) =>
34
+ this.http.request<Paginated<FileResource>>({
35
+ method: "GET",
36
+ path: `/v1/files/${encodeURIComponent(fileId)}/versions`,
37
+ query: { ...params, next } as Record<string, unknown>,
38
+ }),
39
+ params?.next,
40
+ );
42
41
  }
43
42
 
44
43
  get(fileId: string, versionId: string): Promise<FileResource> {
@@ -48,8 +47,12 @@ export class FileVersionsApi {
48
47
  });
49
48
  }
50
49
 
51
- create(fileId: string, body: FileUploadBody): Promise<FileResource> {
52
- const form = toFormData(body);
50
+ create(
51
+ fileId: string,
52
+ body: FileUploadBody,
53
+ options?: FileCreateOptions,
54
+ ): Promise<FileResource> {
55
+ const form = toFormData(body, options);
53
56
  return this.http.request<FileResource>({
54
57
  method: "POST",
55
58
  path: `/v1/files/${encodeURIComponent(fileId)}/versions`,
@@ -66,25 +69,28 @@ export class FilesApi {
66
69
  }
67
70
 
68
71
  /**
69
- * Iterate files matching `params`. Pages are fetched lazily as the
70
- * iterator is consumed (`limit` sets the page size, `next` the
71
- * starting cursor); stop early to stop fetching.
72
+ * List files matching `params`. `await` the result for the first page,
73
+ * or `for await` it to stream every file across pages (fetched lazily —
74
+ * `limit` sets the page size, `next` the starting cursor; stop early to
75
+ * stop fetching).
72
76
  */
73
- async *list(params?: FileListParams): AsyncIterable<FileResource> {
74
- let next: string | undefined = params?.next;
75
- do {
76
- const page = await this.http.request<Paginated<FileResource>>({
77
- method: "GET",
78
- path: "/v1/files",
79
- query: { ...params, next } as Record<string, unknown>,
80
- });
81
- for (const f of page.records) yield f;
82
- next = page.next ?? undefined;
83
- } while (next);
77
+ list(params?: FileListParams): Paginator<FileResource> {
78
+ return cursorPaginate(
79
+ (next) =>
80
+ this.http.request<Paginated<FileResource>>({
81
+ method: "GET",
82
+ path: "/v1/files",
83
+ query: { ...params, next } as Record<string, unknown>,
84
+ }),
85
+ params?.next,
86
+ );
84
87
  }
85
88
 
86
- upload(body: FileUploadBody): Promise<FileResource> {
87
- const form = toFormData(body);
89
+ upload(
90
+ body: FileUploadBody,
91
+ options?: FileCreateOptions,
92
+ ): Promise<FileResource> {
93
+ const form = toFormData(body, options);
88
94
  return this.http.request<FileResource>({
89
95
  method: "POST",
90
96
  path: "/v1/files",
@@ -92,11 +98,16 @@ export class FilesApi {
92
98
  });
93
99
  }
94
100
 
95
- createText(body: FileCreateTextParams): Promise<FileResource> {
101
+ createText(
102
+ body: FileCreateTextParams,
103
+ options?: FileCreateOptions,
104
+ ): Promise<FileResource> {
96
105
  return this.http.request<FileResource>({
97
106
  method: "POST",
98
107
  path: "/v1/files",
99
- body,
108
+ body: options?.visibility
109
+ ? { ...body, visibility: options.visibility }
110
+ : body,
100
111
  });
101
112
  }
102
113
 
@@ -140,7 +151,10 @@ export class FilesApi {
140
151
  }
141
152
  }
142
153
 
143
- function toFormData(body: FileUploadBody): FormData {
154
+ function toFormData(
155
+ body: FileUploadBody,
156
+ options?: FileCreateOptions,
157
+ ): FormData {
144
158
  const fd = new FormData();
145
159
  if ("file" in body && body.file instanceof Blob) {
146
160
  fd.append("file", body.file, body.name);
@@ -160,5 +174,6 @@ function toFormData(body: FileUploadBody): FormData {
160
174
  }
161
175
  if (body.name) fd.append("name", body.name);
162
176
  if (body.file_type) fd.append("file_type", body.file_type);
177
+ if (options?.visibility) fd.append("visibility", options.visibility);
163
178
  return fd;
164
179
  }
@@ -12,6 +12,7 @@ import type {
12
12
  TaskUpdateParams,
13
13
  } from "@introspection-sdk/types";
14
14
  import { HttpClient } from "../http.js";
15
+ import { Paginator, cursorPaginate } from "../pagination.js";
15
16
  import { parseSse } from "../streaming.js";
16
17
 
17
18
  export interface StartParams extends TaskCreateParams {
@@ -85,21 +86,21 @@ export class TasksApi {
85
86
  }
86
87
 
87
88
  /**
88
- * Iterate tasks matching `params`. Pages are fetched lazily as the
89
- * iterator is consumed (`limit` sets the page size, `next` the
90
- * starting cursor); stop early to stop fetching.
89
+ * List tasks matching `params`. `await` the result for the first page,
90
+ * or `for await` it to stream every task across pages (fetched lazily —
91
+ * `limit` sets the page size, `next` the starting cursor; stop early to
92
+ * stop fetching).
91
93
  */
92
- async *list(params?: TaskListParams): AsyncIterable<Task> {
93
- let next: string | undefined = params?.next;
94
- do {
95
- const page = await this.http.request<Paginated<Task>>({
96
- method: "GET",
97
- path: "/v1/tasks",
98
- query: { ...params, next } as Record<string, unknown>,
99
- });
100
- for (const t of page.records) yield t;
101
- next = page.next ?? undefined;
102
- } while (next);
94
+ list(params?: TaskListParams): Paginator<Task> {
95
+ return cursorPaginate(
96
+ (next) =>
97
+ this.http.request<Paginated<Task>>({
98
+ method: "GET",
99
+ path: "/v1/tasks",
100
+ query: { ...params, next } as Record<string, unknown>,
101
+ }),
102
+ params?.next,
103
+ );
103
104
  }
104
105
 
105
106
  create(body: TaskCreateParams): Promise<TaskCreateResponse> {