openpond-sdk 0.3.3 → 0.4.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.
Files changed (124) hide show
  1. package/TASKSETS.md +55 -0
  2. package/dist/actions-local.js +67 -118
  3. package/dist/actions-local.js.map +4 -4
  4. package/dist/actions.js +4 -92
  5. package/dist/actions.js.map +4 -4
  6. package/dist/chunk-27ETSPHQ.js +83 -0
  7. package/dist/chunk-27ETSPHQ.js.map +7 -0
  8. package/dist/chunk-5PRP457R.js +477 -0
  9. package/dist/chunk-5PRP457R.js.map +7 -0
  10. package/dist/chunk-65D4C7HP.js +273 -0
  11. package/dist/chunk-65D4C7HP.js.map +7 -0
  12. package/dist/chunk-747CMU2Y.js +222 -0
  13. package/dist/chunk-747CMU2Y.js.map +7 -0
  14. package/dist/chunk-7O5X7DBU.js +80 -0
  15. package/dist/chunk-7O5X7DBU.js.map +7 -0
  16. package/dist/chunk-A4ZDOZKP.js +115 -0
  17. package/dist/chunk-A4ZDOZKP.js.map +7 -0
  18. package/dist/chunk-APHPXQEA.js +155 -0
  19. package/dist/chunk-APHPXQEA.js.map +7 -0
  20. package/dist/chunk-AVW35YOH.js +574 -0
  21. package/dist/chunk-AVW35YOH.js.map +7 -0
  22. package/dist/chunk-AZUCY3E5.js +2395 -0
  23. package/dist/chunk-AZUCY3E5.js.map +7 -0
  24. package/dist/chunk-IVEXCIHO.js +1373 -0
  25. package/dist/chunk-IVEXCIHO.js.map +7 -0
  26. package/dist/chunk-K5ZCYOZO.js +49 -0
  27. package/dist/chunk-K5ZCYOZO.js.map +7 -0
  28. package/dist/chunk-LLHE4BOD.js +220 -0
  29. package/dist/chunk-LLHE4BOD.js.map +7 -0
  30. package/dist/chunk-LXXQVGQY.js +1 -0
  31. package/dist/chunk-LXXQVGQY.js.map +7 -0
  32. package/dist/chunk-P27DQ65Z.js +138 -0
  33. package/dist/chunk-P27DQ65Z.js.map +7 -0
  34. package/dist/chunk-QLEJOCQX.js +72 -0
  35. package/dist/chunk-QLEJOCQX.js.map +7 -0
  36. package/dist/chunk-S7I45WJQ.js +57 -0
  37. package/dist/chunk-S7I45WJQ.js.map +7 -0
  38. package/dist/chunk-ZPCK222K.js +586 -0
  39. package/dist/chunk-ZPCK222K.js.map +7 -0
  40. package/dist/index.js +33 -2488
  41. package/dist/index.js.map +4 -4
  42. package/dist/learning.js +16 -2042
  43. package/dist/learning.js.map +4 -4
  44. package/dist/model-batch-review.js +5 -42
  45. package/dist/model-batch-review.js.map +3 -3
  46. package/dist/model-projects.js +29 -430
  47. package/dist/model-projects.js.map +3 -3
  48. package/dist/model-starter-attempts.js +53 -310
  49. package/dist/model-starter-attempts.js.map +4 -4
  50. package/dist/model-starter-catalog.js +17 -460
  51. package/dist/model-starter-catalog.js.map +4 -4
  52. package/dist/model-starters.js +32 -709
  53. package/dist/model-starters.js.map +4 -4
  54. package/dist/model-taskset-authoring.js +11 -44
  55. package/dist/model-taskset-authoring.js.map +3 -3
  56. package/dist/profile-actions.js +4 -211
  57. package/dist/profile-actions.js.map +3 -3
  58. package/dist/project-actions.js +4 -224
  59. package/dist/project-actions.js.map +3 -3
  60. package/dist/refiner.js +14 -554
  61. package/dist/refiner.js.map +4 -4
  62. package/dist/taskset-catalog.js +9 -104
  63. package/dist/taskset-catalog.js.map +3 -3
  64. package/dist/taskset-drafts.js +465 -0
  65. package/dist/taskset-drafts.js.map +7 -0
  66. package/dist/taskset-packages.js +946 -3089
  67. package/dist/taskset-packages.js.map +4 -4
  68. package/dist/training.js +43 -822
  69. package/dist/training.js.map +4 -4
  70. package/dist/types/packages/sdk/src/index.d.ts +3 -3
  71. package/dist/types/packages/sdk/src/index.d.ts.map +1 -1
  72. package/dist/types/packages/sdk/src/learning-client.d.ts +130 -0
  73. package/dist/types/packages/sdk/src/learning-client.d.ts.map +1 -0
  74. package/dist/types/packages/sdk/src/learning.d.ts +1 -129
  75. package/dist/types/packages/sdk/src/learning.d.ts.map +1 -1
  76. package/dist/types/packages/sdk/src/taskset-authored-contracts.d.ts +1170 -0
  77. package/dist/types/packages/sdk/src/taskset-authored-contracts.d.ts.map +1 -0
  78. package/dist/types/packages/sdk/src/taskset-authored-files.d.ts +560 -0
  79. package/dist/types/packages/sdk/src/taskset-authored-files.d.ts.map +1 -0
  80. package/dist/types/packages/sdk/src/taskset-authored-portable-release.d.ts +92 -0
  81. package/dist/types/packages/sdk/src/taskset-authored-portable-release.d.ts.map +1 -0
  82. package/dist/types/packages/sdk/src/taskset-authored-tool-environment.d.ts +15 -0
  83. package/dist/types/packages/sdk/src/taskset-authored-tool-environment.d.ts.map +1 -0
  84. package/dist/types/packages/sdk/src/taskset-authored-validation.d.ts +18 -0
  85. package/dist/types/packages/sdk/src/taskset-authored-validation.d.ts.map +1 -0
  86. package/dist/types/packages/sdk/src/taskset-draft-api-contracts.d.ts +1681 -0
  87. package/dist/types/packages/sdk/src/taskset-draft-api-contracts.d.ts.map +1 -0
  88. package/dist/types/packages/sdk/src/taskset-draft-authoring.d.ts +19 -0
  89. package/dist/types/packages/sdk/src/taskset-draft-authoring.d.ts.map +1 -0
  90. package/dist/types/packages/sdk/src/taskset-draft-client.d.ts +2713 -0
  91. package/dist/types/packages/sdk/src/taskset-draft-client.d.ts.map +1 -0
  92. package/dist/types/packages/sdk/src/taskset-draft-core.d.ts +1000 -0
  93. package/dist/types/packages/sdk/src/taskset-draft-core.d.ts.map +1 -0
  94. package/dist/types/packages/sdk/src/taskset-draft-dataset-artifacts.d.ts +429 -0
  95. package/dist/types/packages/sdk/src/taskset-draft-dataset-artifacts.d.ts.map +1 -0
  96. package/dist/types/packages/sdk/src/taskset-draft-dataset-sources.d.ts +284 -0
  97. package/dist/types/packages/sdk/src/taskset-draft-dataset-sources.d.ts.map +1 -0
  98. package/dist/types/packages/sdk/src/taskset-draft-document.d.ts +846 -0
  99. package/dist/types/packages/sdk/src/taskset-draft-document.d.ts.map +1 -0
  100. package/dist/types/packages/sdk/src/taskset-draft-files.d.ts +8 -0
  101. package/dist/types/packages/sdk/src/taskset-draft-files.d.ts.map +1 -0
  102. package/dist/types/packages/sdk/src/taskset-draft-harness-actions.d.ts +28 -0
  103. package/dist/types/packages/sdk/src/taskset-draft-harness-actions.d.ts.map +1 -0
  104. package/dist/types/packages/sdk/src/taskset-draft-manifests.d.ts +8 -0
  105. package/dist/types/packages/sdk/src/taskset-draft-manifests.d.ts.map +1 -0
  106. package/dist/types/packages/sdk/src/taskset-draft-package-compiler.d.ts +967 -0
  107. package/dist/types/packages/sdk/src/taskset-draft-package-compiler.d.ts.map +1 -0
  108. package/dist/types/packages/sdk/src/taskset-draft-publication.d.ts +10 -0
  109. package/dist/types/packages/sdk/src/taskset-draft-publication.d.ts.map +1 -0
  110. package/dist/types/packages/sdk/src/taskset-draft-source.d.ts +1297 -0
  111. package/dist/types/packages/sdk/src/taskset-draft-source.d.ts.map +1 -0
  112. package/dist/types/packages/sdk/src/taskset-draft-workspace.d.ts +1597 -0
  113. package/dist/types/packages/sdk/src/taskset-draft-workspace.d.ts.map +1 -0
  114. package/dist/types/packages/sdk/src/taskset-drafts.d.ts +16 -0
  115. package/dist/types/packages/sdk/src/taskset-drafts.d.ts.map +1 -0
  116. package/dist/types/packages/sdk/src/taskset-package-grader-projection.d.ts +64 -0
  117. package/dist/types/packages/sdk/src/taskset-package-grader-projection.d.ts.map +1 -0
  118. package/dist/types/packages/sdk/src/taskset-package-projection.d.ts +1514 -0
  119. package/dist/types/packages/sdk/src/taskset-package-projection.d.ts.map +1 -0
  120. package/dist/types/packages/sdk/src/taskset-packages.d.ts +6 -0
  121. package/dist/types/packages/sdk/src/taskset-packages.d.ts.map +1 -1
  122. package/dist/workflows.js +4 -221
  123. package/dist/workflows.js.map +3 -3
  124. package/package.json +5 -1
@@ -1,227 +1,7 @@
1
- // src/project-actions.ts
2
- import { promises as fs } from "node:fs";
3
-
4
- // ../cloud/dist/api/core.js
5
- var DEFAULT_API_TIMEOUT_MS = 3e4;
6
- var DEFAULT_API_RESPONSE_BYTES = 8 * 1024 * 1024;
7
- var LONG_STREAM_API_OPTIONS = { timeoutMs: 15 * 60 * 1e3, maxResponseBytes: 64 * 1024 * 1024 };
8
- var ApiTimeoutError = class extends Error {
9
- timeoutMs;
10
- requestUrl;
11
- code = "OPENPOND_API_TIMEOUT";
12
- constructor(timeoutMs, requestUrl) {
13
- super(`API request timed out after ${timeoutMs}ms: ${requestUrl}`);
14
- this.timeoutMs = timeoutMs;
15
- this.requestUrl = requestUrl;
16
- this.name = "ApiTimeoutError";
17
- }
18
- };
19
- var ApiResponseTooLargeError = class extends Error {
20
- maximumBytes;
21
- requestUrl;
22
- code = "OPENPOND_API_RESPONSE_TOO_LARGE";
23
- constructor(maximumBytes, requestUrl) {
24
- super(`API response exceeded ${maximumBytes} bytes: ${requestUrl}`);
25
- this.maximumBytes = maximumBytes;
26
- this.requestUrl = requestUrl;
27
- this.name = "ApiResponseTooLargeError";
28
- }
29
- };
30
- var OpenPondApiError = class extends Error {
31
- status;
32
- apiMessage;
33
- code;
34
- constructor(status, errorCode, label, apiMessage = null) {
35
- const detail = apiMessage || errorCode;
36
- super(`${label} failed: ${status}${detail ? ` ${detail}` : ""}`);
37
- this.status = status;
38
- this.apiMessage = apiMessage;
39
- this.name = "OpenPondApiError";
40
- this.code = errorCode || "OPENPOND_API_ERROR";
41
- }
42
- };
43
- async function apiFetch(baseUrl, token, requestPath, options = {}) {
44
- const { timeoutMs = DEFAULT_API_TIMEOUT_MS, maxResponseBytes = DEFAULT_API_RESPONSE_BYTES, ...init } = options;
45
- const requestUrl = `${baseUrl}${requestPath}`;
46
- const headers = new Headers(init.headers);
47
- headers.set("Content-Type", "application/json");
48
- const apiKey = process.env.OPENPOND_API_KEY;
49
- const trimmedToken = token?.trim() || "";
50
- const tokenIsApiKey = trimmedToken.startsWith("opk_");
51
- const effectiveApiKey = apiKey || (tokenIsApiKey ? trimmedToken : null);
52
- if (effectiveApiKey && !headers.has("openpond-api-key"))
53
- headers.set("openpond-api-key", effectiveApiKey);
54
- if (token) {
55
- headers.set("Authorization", tokenIsApiKey ? `ApiKey ${trimmedToken}` : `Bearer ${token}`);
56
- } else if (apiKey && !headers.has("Authorization")) {
57
- headers.set("Authorization", `ApiKey ${apiKey}`);
58
- }
59
- const timeoutController = new AbortController();
60
- const timeoutError = new ApiTimeoutError(timeoutMs, requestUrl);
61
- const timer = timeoutMs > 0 ? setTimeout(() => timeoutController.abort(timeoutError), timeoutMs) : null;
62
- timer?.unref?.();
63
- const signal = composedSignal(init.signal, timeoutController.signal, timeoutMs);
64
- const cleanup = () => {
65
- if (timer)
66
- clearTimeout(timer);
67
- };
68
- try {
69
- const response = await fetch(requestUrl, { ...init, headers, signal });
70
- return boundedResponse(response, {
71
- cleanup,
72
- maximumBytes: maxResponseBytes,
73
- requestUrl,
74
- timeoutController,
75
- timeoutError
76
- });
77
- } catch (error) {
78
- cleanup();
79
- if (timeoutController.signal.aborted)
80
- throw timeoutError;
81
- throw error;
82
- }
83
- }
84
- async function readApiJson(response, label) {
85
- let payload;
86
- try {
87
- const text = await response.text();
88
- payload = text ? JSON.parse(text) : {};
89
- } catch (error) {
90
- if (error instanceof ApiTimeoutError || error instanceof ApiResponseTooLargeError)
91
- throw error;
92
- payload = {};
93
- }
94
- if (!response.ok) {
95
- const errorCode = typeof payload.error === "string" ? payload.error : null;
96
- const apiMessage = typeof payload.message === "string" ? payload.message : null;
97
- throw new OpenPondApiError(response.status, errorCode, label, apiMessage);
98
- }
99
- return payload;
100
- }
101
- function boundedResponse(response, input) {
102
- if (!response.body) {
103
- input.cleanup();
104
- return response;
105
- }
106
- const contentLength = Number(response.headers.get("content-length"));
107
- if (input.maximumBytes > 0 && Number.isFinite(contentLength) && contentLength > input.maximumBytes) {
108
- input.cleanup();
109
- void response.body.cancel();
110
- throw new ApiResponseTooLargeError(input.maximumBytes, input.requestUrl);
111
- }
112
- const reader = response.body.getReader();
113
- let receivedBytes = 0;
114
- const body = new ReadableStream({
115
- async pull(controller) {
116
- try {
117
- const result = await reader.read();
118
- if (result.done) {
119
- input.cleanup();
120
- controller.close();
121
- return;
122
- }
123
- receivedBytes += result.value.byteLength;
124
- if (input.maximumBytes > 0 && receivedBytes > input.maximumBytes) {
125
- input.cleanup();
126
- await reader.cancel();
127
- controller.error(new ApiResponseTooLargeError(input.maximumBytes, input.requestUrl));
128
- return;
129
- }
130
- controller.enqueue(result.value);
131
- } catch (error) {
132
- input.cleanup();
133
- controller.error(input.timeoutController.signal.aborted ? input.timeoutError : error);
134
- }
135
- },
136
- async cancel(reason) {
137
- input.cleanup();
138
- await reader.cancel(reason);
139
- }
140
- });
141
- return new Response(body, {
142
- headers: response.headers,
143
- status: response.status,
144
- statusText: response.statusText
145
- });
146
- }
147
- function composedSignal(callerSignal, timeoutSignal, timeoutMs) {
148
- if (timeoutMs <= 0)
149
- return callerSignal ?? void 0;
150
- return callerSignal ? AbortSignal.any([callerSignal, timeoutSignal]) : timeoutSignal;
151
- }
152
-
153
- // src/project-actions.ts
154
- var OpenPondProjectActionsClient = class {
155
- #apiKey;
156
- #apiBaseUrl;
157
- constructor(input) {
158
- this.#apiKey = input.apiKey;
159
- this.#apiBaseUrl = input.apiBaseUrl.replace(/\/+$/, "");
160
- }
161
- async list(input) {
162
- const response = await apiFetch(
163
- this.#apiBaseUrl,
164
- this.#apiKey,
165
- projectActionPath(input.projectId, "releases", input.teamId)
166
- );
167
- return (await readApiJson(response, "List Project Action releases")).releases;
168
- }
169
- async catalog(input) {
170
- const response = await apiFetch(
171
- this.#apiBaseUrl,
172
- this.#apiKey,
173
- projectActionPath(input.projectId, "catalog", input.teamId)
174
- );
175
- return (await readApiJson(response, "Get Project Action catalog")).catalog;
176
- }
177
- async publish(input) {
178
- const [bundle, runner] = await Promise.all([
179
- fs.readFile(input.build.bundlePath),
180
- fs.readFile(input.build.runnerPath)
181
- ]);
182
- const response = await apiFetch(
183
- this.#apiBaseUrl,
184
- this.#apiKey,
185
- projectActionPath(input.projectId, "releases", input.teamId),
186
- {
187
- method: "POST",
188
- body: JSON.stringify({
189
- sourceRef: input.sourceRef,
190
- sourceCommitSha: input.sourceCommitSha,
191
- bundleBase64: bundle.toString("base64"),
192
- runnerBase64: runner.toString("base64"),
193
- registry: input.build.registry,
194
- manifest: input.build.manifest,
195
- metadata: input.metadata
196
- })
197
- }
198
- );
199
- return (await readApiJson(response, "Publish Project Actions")).release;
200
- }
201
- async run(input) {
202
- const response = await apiFetch(
203
- this.#apiBaseUrl,
204
- this.#apiKey,
205
- projectActionPath(input.projectId, `actions/${encodeURIComponent(input.actionId)}`, input.teamId),
206
- {
207
- method: "POST",
208
- body: JSON.stringify({
209
- input: input.value ?? {},
210
- releaseId: input.releaseId,
211
- idempotencyKey: input.idempotencyKey,
212
- callerType: input.callerType ?? "sdk",
213
- callerId: input.callerId
214
- }),
215
- signal: input.signal,
216
- timeoutMs: 15 * 60 * 1e3
217
- }
218
- );
219
- return (await readApiJson(response, "Run Project Action")).invocation;
220
- }
221
- };
222
- function projectActionPath(projectId, suffix, teamId) {
223
- return `/v1/project-actions/${encodeURIComponent(projectId)}/${suffix}?teamId=${encodeURIComponent(teamId)}`;
224
- }
1
+ import {
2
+ OpenPondProjectActionsClient
3
+ } from "./chunk-27ETSPHQ.js";
4
+ import "./chunk-APHPXQEA.js";
225
5
  export {
226
6
  OpenPondProjectActionsClient
227
7
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/project-actions.ts", "../../cloud/src/api/core.ts"],
4
- "sourcesContent": ["import { promises as fs } from \"node:fs\";\n\nimport { apiFetch, readApiJson } from \"@openpond/cloud/api/core\";\n\nimport type { ProjectActionBuildResult, ProjectActionRegistry } from \"../../actions/src/types.js\";\n\nexport type ProjectActionRelease = {\n id: string;\n projectId: string;\n sourceCommitSha: string;\n bundleHash: string;\n registryHash: string;\n status: string;\n createdAt: string;\n};\n\nexport type HostedProjectActionCatalog = {\n releaseId: string;\n sourceCommitSha: string;\n bundleHash: string;\n registryHash: string;\n registry: ProjectActionRegistry;\n};\n\nexport type ProjectActionInvocation<TOutput = Record<string, unknown>> = {\n id: string;\n releaseId: string;\n projectId: string;\n actionId: string;\n status: \"running\" | \"succeeded\" | \"failed\";\n resultJson: TOutput;\n traceJson: Record<string, unknown>[];\n outputJson: Record<string, unknown>[];\n failureCode?: string | null;\n failureMessage?: string | null;\n};\n\ntype ProjectActionClientInput = {\n apiKey: string;\n apiBaseUrl: string;\n};\n\nexport class OpenPondProjectActionsClient {\n readonly #apiKey: string;\n readonly #apiBaseUrl: string;\n\n constructor(input: ProjectActionClientInput) {\n this.#apiKey = input.apiKey;\n this.#apiBaseUrl = input.apiBaseUrl.replace(/\\/+$/, \"\");\n }\n\n async list(input: { projectId: string; teamId: string }): Promise<ProjectActionRelease[]> {\n const response = await apiFetch(\n this.#apiBaseUrl,\n this.#apiKey,\n projectActionPath(input.projectId, \"releases\", input.teamId),\n );\n return (await readApiJson<{ releases: ProjectActionRelease[] }>(response, \"List Project Action releases\")).releases;\n }\n\n async catalog(input: { projectId: string; teamId: string }): Promise<HostedProjectActionCatalog> {\n const response = await apiFetch(\n this.#apiBaseUrl,\n this.#apiKey,\n projectActionPath(input.projectId, \"catalog\", input.teamId),\n );\n return (await readApiJson<{ catalog: HostedProjectActionCatalog }>(response, \"Get Project Action catalog\")).catalog;\n }\n\n async publish(input: {\n projectId: string;\n teamId: string;\n sourceRef: string;\n sourceCommitSha: string;\n build: ProjectActionBuildResult;\n metadata?: Record<string, unknown>;\n }): Promise<ProjectActionRelease> {\n const [bundle, runner] = await Promise.all([\n fs.readFile(input.build.bundlePath),\n fs.readFile(input.build.runnerPath),\n ]);\n const response = await apiFetch(\n this.#apiBaseUrl,\n this.#apiKey,\n projectActionPath(input.projectId, \"releases\", input.teamId),\n {\n method: \"POST\",\n body: JSON.stringify({\n sourceRef: input.sourceRef,\n sourceCommitSha: input.sourceCommitSha,\n bundleBase64: bundle.toString(\"base64\"),\n runnerBase64: runner.toString(\"base64\"),\n registry: input.build.registry,\n manifest: input.build.manifest,\n metadata: input.metadata,\n }),\n },\n );\n return (await readApiJson<{ release: ProjectActionRelease }>(response, \"Publish Project Actions\")).release;\n }\n\n async run<TOutput = Record<string, unknown>>(input: {\n projectId: string;\n teamId: string;\n actionId: string;\n value?: Record<string, unknown>;\n releaseId?: string;\n idempotencyKey?: string;\n callerType?: \"sdk\" | \"work\" | \"scheduled_work\" | \"website\" | \"internal\";\n callerId?: string;\n signal?: AbortSignal;\n }): Promise<ProjectActionInvocation<TOutput>> {\n const response = await apiFetch(\n this.#apiBaseUrl,\n this.#apiKey,\n projectActionPath(input.projectId, `actions/${encodeURIComponent(input.actionId)}`, input.teamId),\n {\n method: \"POST\",\n body: JSON.stringify({\n input: input.value ?? {},\n releaseId: input.releaseId,\n idempotencyKey: input.idempotencyKey,\n callerType: input.callerType ?? \"sdk\",\n callerId: input.callerId,\n }),\n signal: input.signal,\n timeoutMs: 15 * 60 * 1000,\n },\n );\n return (await readApiJson<{ invocation: ProjectActionInvocation<TOutput> }>(response, \"Run Project Action\")).invocation;\n }\n}\n\nfunction projectActionPath(projectId: string, suffix: string, teamId: string): string {\n return `/v1/project-actions/${encodeURIComponent(projectId)}/${suffix}?teamId=${encodeURIComponent(teamId)}`;\n}\n", "const DEFAULT_API_TIMEOUT_MS = 30_000;\nconst DEFAULT_API_RESPONSE_BYTES = 8 * 1024 * 1024;\nexport const LONG_STREAM_API_OPTIONS = { timeoutMs: 15 * 60 * 1000, maxResponseBytes: 64 * 1024 * 1024 } as const;\n\nexport type ApiFetchOptions = RequestInit & {\n timeoutMs?: number;\n maxResponseBytes?: number;\n};\n\nexport class ApiTimeoutError extends Error {\n readonly code = \"OPENPOND_API_TIMEOUT\";\n\n constructor(readonly timeoutMs: number, readonly requestUrl: string) {\n super(`API request timed out after ${timeoutMs}ms: ${requestUrl}`);\n this.name = \"ApiTimeoutError\";\n }\n}\n\nexport class ApiResponseTooLargeError extends Error {\n readonly code = \"OPENPOND_API_RESPONSE_TOO_LARGE\";\n\n constructor(readonly maximumBytes: number, readonly requestUrl: string) {\n super(`API response exceeded ${maximumBytes} bytes: ${requestUrl}`);\n this.name = \"ApiResponseTooLargeError\";\n }\n}\n\nexport class OpenPondApiError extends Error {\n readonly code: string;\n\n constructor(\n readonly status: number,\n errorCode: string | null,\n label: string,\n readonly apiMessage: string | null = null,\n ) {\n const detail = apiMessage || errorCode;\n super(`${label} failed: ${status}${detail ? ` ${detail}` : \"\"}`);\n this.name = \"OpenPondApiError\";\n this.code = errorCode || \"OPENPOND_API_ERROR\";\n }\n}\n\nexport async function apiFetch(\n baseUrl: string,\n token: string | null,\n requestPath: string,\n options: ApiFetchOptions = {},\n): Promise<Response> {\n const { timeoutMs = DEFAULT_API_TIMEOUT_MS, maxResponseBytes = DEFAULT_API_RESPONSE_BYTES, ...init } = options;\n const requestUrl = `${baseUrl}${requestPath}`;\n const headers = new Headers(init.headers);\n headers.set(\"Content-Type\", \"application/json\");\n const apiKey = process.env.OPENPOND_API_KEY;\n const trimmedToken = token?.trim() || \"\";\n const tokenIsApiKey = trimmedToken.startsWith(\"opk_\");\n const effectiveApiKey = apiKey || (tokenIsApiKey ? trimmedToken : null);\n if (effectiveApiKey && !headers.has(\"openpond-api-key\")) headers.set(\"openpond-api-key\", effectiveApiKey);\n if (token) {\n headers.set(\"Authorization\", tokenIsApiKey ? `ApiKey ${trimmedToken}` : `Bearer ${token}`);\n } else if (apiKey && !headers.has(\"Authorization\")) {\n headers.set(\"Authorization\", `ApiKey ${apiKey}`);\n }\n\n const timeoutController = new AbortController();\n const timeoutError = new ApiTimeoutError(timeoutMs, requestUrl);\n const timer = timeoutMs > 0\n ? setTimeout(() => timeoutController.abort(timeoutError), timeoutMs)\n : null;\n timer?.unref?.();\n const signal = composedSignal(init.signal, timeoutController.signal, timeoutMs);\n const cleanup = () => {\n if (timer) clearTimeout(timer);\n };\n\n try {\n const response = await fetch(requestUrl, { ...init, headers, signal });\n return boundedResponse(response, {\n cleanup,\n maximumBytes: maxResponseBytes,\n requestUrl,\n timeoutController,\n timeoutError,\n });\n } catch (error) {\n cleanup();\n if (timeoutController.signal.aborted) throw timeoutError;\n throw error;\n }\n}\n\nexport async function readApiJson<T>(response: Response, label: string): Promise<T> {\n let payload: T & { error?: unknown; message?: unknown };\n try {\n const text = await response.text();\n payload = (text ? JSON.parse(text) : {}) as T & { error?: unknown; message?: unknown };\n } catch (error) {\n if (error instanceof ApiTimeoutError || error instanceof ApiResponseTooLargeError) throw error;\n payload = {} as T & { error?: unknown; message?: unknown };\n }\n if (!response.ok) {\n const errorCode = typeof payload.error === \"string\" ? payload.error : null;\n const apiMessage =\n typeof payload.message === \"string\" ? payload.message : null;\n throw new OpenPondApiError(response.status, errorCode, label, apiMessage);\n }\n return payload as T;\n}\n\nfunction boundedResponse(\n response: Response,\n input: {\n cleanup: () => void;\n maximumBytes: number;\n requestUrl: string;\n timeoutController: AbortController;\n timeoutError: ApiTimeoutError;\n },\n): Response {\n if (!response.body) {\n input.cleanup();\n return response;\n }\n const contentLength = Number(response.headers.get(\"content-length\"));\n if (input.maximumBytes > 0 && Number.isFinite(contentLength) && contentLength > input.maximumBytes) {\n input.cleanup();\n void response.body.cancel();\n throw new ApiResponseTooLargeError(input.maximumBytes, input.requestUrl);\n }\n\n const reader = response.body.getReader();\n let receivedBytes = 0;\n const body = new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n const result = await reader.read();\n if (result.done) {\n input.cleanup();\n controller.close();\n return;\n }\n receivedBytes += result.value.byteLength;\n if (input.maximumBytes > 0 && receivedBytes > input.maximumBytes) {\n input.cleanup();\n await reader.cancel();\n controller.error(new ApiResponseTooLargeError(input.maximumBytes, input.requestUrl));\n return;\n }\n controller.enqueue(result.value);\n } catch (error) {\n input.cleanup();\n controller.error(input.timeoutController.signal.aborted ? input.timeoutError : error);\n }\n },\n async cancel(reason) {\n input.cleanup();\n await reader.cancel(reason);\n },\n });\n return new Response(body, {\n headers: response.headers,\n status: response.status,\n statusText: response.statusText,\n });\n}\n\nfunction composedSignal(\n callerSignal: AbortSignal | null | undefined,\n timeoutSignal: AbortSignal,\n timeoutMs: number,\n): AbortSignal | undefined {\n if (timeoutMs <= 0) return callerSignal ?? undefined;\n return callerSignal ? AbortSignal.any([callerSignal, timeoutSignal]) : timeoutSignal;\n}\n"],
5
- "mappings": ";AAAA,SAAS,YAAY,UAAU;;;ACA/B,IAAM,yBAAyB;AAC/B,IAAM,6BAA6B,IAAI,OAAO;AACvC,IAAM,0BAA0B,EAAE,WAAW,KAAK,KAAK,KAAM,kBAAkB,KAAK,OAAO,KAAI;AAOhG,IAAO,kBAAP,cAA+B,MAAK;EAGnB;EAA4B;EAFxC,OAAO;EAEhB,YAAqB,WAA4B,YAAkB;AACjE,UAAM,+BAA+B,SAAS,OAAO,UAAU,EAAE;AAD9C,SAAA,YAAA;AAA4B,SAAA,aAAA;AAE/C,SAAK,OAAO;EACd;;AAGI,IAAO,2BAAP,cAAwC,MAAK;EAG5B;EAA+B;EAF3C,OAAO;EAEhB,YAAqB,cAA+B,YAAkB;AACpE,UAAM,yBAAyB,YAAY,WAAW,UAAU,EAAE;AAD/C,SAAA,eAAA;AAA+B,SAAA,aAAA;AAElD,SAAK,OAAO;EACd;;AAGI,IAAO,mBAAP,cAAgC,MAAK;EAI9B;EAGA;EANF;EAET,YACW,QACT,WACA,OACS,aAA4B,MAAI;AAEzC,UAAM,SAAS,cAAc;AAC7B,UAAM,GAAG,KAAK,YAAY,MAAM,GAAG,SAAS,IAAI,MAAM,KAAK,EAAE,EAAE;AANtD,SAAA,SAAA;AAGA,SAAA,aAAA;AAIT,SAAK,OAAO;AACZ,SAAK,OAAO,aAAa;EAC3B;;AAGF,eAAsB,SACpB,SACA,OACA,aACA,UAA2B,CAAA,GAAE;AAE7B,QAAM,EAAE,YAAY,wBAAwB,mBAAmB,4BAA4B,GAAG,KAAI,IAAK;AACvG,QAAM,aAAa,GAAG,OAAO,GAAG,WAAW;AAC3C,QAAM,UAAU,IAAI,Q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