@neta-art/cohub 1.28.0 → 1.28.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.
- package/dist/chunks/http.d.ts +13 -3
- package/dist/chunks/http.js +7 -1
- package/dist/index.js +24 -11
- package/package.json +1 -1
package/dist/chunks/http.d.ts
CHANGED
|
@@ -2006,6 +2006,18 @@ declare class SpaceCheckpointApi {
|
|
|
2006
2006
|
constructor(transport: HttpTransport, spaceId: string, id: string);
|
|
2007
2007
|
get(customFetch?: Fetch): Promise<SpaceCheckpointDetailResponse>;
|
|
2008
2008
|
}
|
|
2009
|
+
type CheckpointListPageInfo = {
|
|
2010
|
+
hasMore: boolean;
|
|
2011
|
+
nextCursor: string | null;
|
|
2012
|
+
};
|
|
2013
|
+
type CheckpointListOptions = {
|
|
2014
|
+
limit?: number;
|
|
2015
|
+
cursor?: string | null;
|
|
2016
|
+
};
|
|
2017
|
+
type CheckpointListResponse = {
|
|
2018
|
+
checkpoints: CheckpointRecord[];
|
|
2019
|
+
pageInfo?: CheckpointListPageInfo;
|
|
2020
|
+
};
|
|
2009
2021
|
type SpaceCheckpointsApi = ((checkpointId: string) => SpaceCheckpointApi) & {
|
|
2010
2022
|
checkpoint: (checkpointId: string) => SpaceCheckpointApi;
|
|
2011
2023
|
latest: () => SpaceCheckpointApi;
|
|
@@ -2014,9 +2026,7 @@ type SpaceCheckpointsApi = ((checkpointId: string) => SpaceCheckpointApi) & {
|
|
|
2014
2026
|
taskRunId: string;
|
|
2015
2027
|
existing?: boolean;
|
|
2016
2028
|
}>;
|
|
2017
|
-
list: () => Promise<
|
|
2018
|
-
checkpoints: CheckpointRecord[];
|
|
2019
|
-
}>;
|
|
2029
|
+
list: (options?: CheckpointListOptions) => Promise<CheckpointListResponse>;
|
|
2020
2030
|
get: (checkpointId: string, customFetch?: Fetch) => Promise<SpaceCheckpointDetailResponse>;
|
|
2021
2031
|
};
|
|
2022
2032
|
declare class SpaceClient {
|
package/dist/chunks/http.js
CHANGED
|
@@ -1856,7 +1856,13 @@ function createSpaceCheckpointsApi(transport, spaceId) {
|
|
|
1856
1856
|
headers: { "Content-Type": "application/json" },
|
|
1857
1857
|
body: JSON.stringify({ description: description ?? null })
|
|
1858
1858
|
}),
|
|
1859
|
-
list: () =>
|
|
1859
|
+
list: (options) => {
|
|
1860
|
+
const params = new URLSearchParams();
|
|
1861
|
+
if (options?.limit !== void 0) params.set("limit", String(options.limit));
|
|
1862
|
+
if (options?.cursor) params.set("cursor", options.cursor);
|
|
1863
|
+
const query = params.toString();
|
|
1864
|
+
return transport.request(`/api/spaces/${spaceId}/checkpoints${query ? `?${query}` : ""}`);
|
|
1865
|
+
},
|
|
1860
1866
|
get: (checkpointId, customFetch) => checkpoint(checkpointId).get(customFetch)
|
|
1861
1867
|
});
|
|
1862
1868
|
}
|
package/dist/index.js
CHANGED
|
@@ -143,7 +143,7 @@ const hasParent = () => isBrowser() && window.parent !== window;
|
|
|
143
143
|
const getParentOrigin = () => {
|
|
144
144
|
if (!isBrowser()) return null;
|
|
145
145
|
const ancestorOrigin = window.location.ancestorOrigins?.[0];
|
|
146
|
-
if (ancestorOrigin) return ancestorOrigin;
|
|
146
|
+
if (typeof ancestorOrigin === "string" && ancestorOrigin) return ancestorOrigin;
|
|
147
147
|
try {
|
|
148
148
|
return document.referrer ? new URL(document.referrer).origin : null;
|
|
149
149
|
} catch {
|
|
@@ -151,22 +151,37 @@ const getParentOrigin = () => {
|
|
|
151
151
|
}
|
|
152
152
|
};
|
|
153
153
|
let trustedParentOrigin = null;
|
|
154
|
-
const request = (message, timeoutMs = 1200) => {
|
|
154
|
+
const request = (message, timeoutMs = 1200, retryIntervalMs) => {
|
|
155
155
|
if (!hasParent()) return Promise.resolve(null);
|
|
156
156
|
const requestId = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random()}`;
|
|
157
157
|
return new Promise((resolve, reject) => {
|
|
158
|
-
|
|
158
|
+
let retryTimer = null;
|
|
159
|
+
const parentOrigin = trustedParentOrigin ?? getParentOrigin();
|
|
160
|
+
const postRequest = () => {
|
|
161
|
+
try {
|
|
162
|
+
window.parent.postMessage({
|
|
163
|
+
...message,
|
|
164
|
+
requestId
|
|
165
|
+
}, parentOrigin ?? "*");
|
|
166
|
+
} catch {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const cleanup = () => {
|
|
171
|
+
clearTimeout(timer);
|
|
172
|
+
if (retryTimer) clearInterval(retryTimer);
|
|
159
173
|
window.removeEventListener("message", onMessage);
|
|
174
|
+
};
|
|
175
|
+
const timer = setTimeout(() => {
|
|
176
|
+
cleanup();
|
|
160
177
|
resolve(null);
|
|
161
178
|
}, timeoutMs);
|
|
162
|
-
const parentOrigin = trustedParentOrigin ?? getParentOrigin();
|
|
163
179
|
const onMessage = (event) => {
|
|
164
180
|
if (event.source !== window.parent) return;
|
|
165
181
|
if (parentOrigin && event.origin !== parentOrigin) return;
|
|
166
182
|
const data = event.data;
|
|
167
183
|
if (!data || data.requestId !== requestId) return;
|
|
168
|
-
|
|
169
|
-
window.removeEventListener("message", onMessage);
|
|
184
|
+
cleanup();
|
|
170
185
|
trustedParentOrigin = event.origin;
|
|
171
186
|
if (data.type === "cohub.work.error") {
|
|
172
187
|
reject(new Error(data.message));
|
|
@@ -175,16 +190,14 @@ const request = (message, timeoutMs = 1200) => {
|
|
|
175
190
|
resolve(data);
|
|
176
191
|
};
|
|
177
192
|
window.addEventListener("message", onMessage);
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
requestId
|
|
181
|
-
}, parentOrigin ?? "*");
|
|
193
|
+
postRequest();
|
|
194
|
+
if (retryIntervalMs) retryTimer = setInterval(postRequest, retryIntervalMs);
|
|
182
195
|
});
|
|
183
196
|
};
|
|
184
197
|
var WorkRuntimeApi = class {
|
|
185
198
|
token = null;
|
|
186
199
|
async context() {
|
|
187
|
-
return (await request({ type: "cohub.work.context" }, 8e3))?.context ?? null;
|
|
200
|
+
return (await request({ type: "cohub.work.context" }, 8e3, 250))?.context ?? null;
|
|
188
201
|
}
|
|
189
202
|
async getAccessToken(options) {
|
|
190
203
|
if (this.token && !options?.forceRefresh) return this.token;
|