@apowerb/apowerb-sdk 0.1.11 → 0.1.13

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/api.js +39 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apowerb/apowerb-sdk",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "JavaScript SDK for the apowerb backend: agents, tools, RAG, BI, webhooks and billing. Dependency-free, runs in the browser and in Node.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/api.js CHANGED
@@ -249,15 +249,30 @@ export const getSessionHistory = (agentName, userId, sessionId) =>
249
249
  request(`/api/adk/sessions/${agentName}/${userId}/${sessionId}`);
250
250
 
251
251
  // --- Artifacts (silent401: don't clear auth on 401 — artifacts may fail independently) ---
252
+
253
+ /** Uploads and generated files live under the same routes, told apart by `kind`. */
254
+ const kindQuery = (kind) => (kind ? `?kind=${encodeURIComponent(kind)}` : "");
255
+
256
+ /**
257
+ * The whole library in one request.
258
+ *
259
+ * Returns `{items, supported}`. `supported: false` means the backend is on
260
+ * its local-disk fallback, which has no equivalent sweep — the caller falls
261
+ * back to listing per session. Older backends answer 404, same thing.
262
+ */
263
+ export const listArtifactLibrary = () =>
264
+ request("/api/artifacts/library", { silent401: true });
265
+
252
266
  export const listArtifacts = (agentName, userId, sessionId) =>
253
267
  request(`/api/artifacts/${agentName}/${userId}/${sessionId}`, {
254
268
  silent401: true,
255
269
  });
256
270
 
257
- export const loadArtifact = (agentName, userId, sessionId, filename) =>
258
- request(`/api/artifacts/${agentName}/${userId}/${sessionId}/${filename}`, {
259
- silent401: true,
260
- });
271
+ export const loadArtifact = (agentName, userId, sessionId, filename, kind) =>
272
+ request(
273
+ `/api/artifacts/${agentName}/${userId}/${sessionId}/${filename}${kindQuery(kind)}`,
274
+ { silent401: true },
275
+ );
261
276
 
262
277
  export const executeArtifact = (
263
278
  agentName,
@@ -265,9 +280,10 @@ export const executeArtifact = (
265
280
  sessionId,
266
281
  filename,
267
282
  options,
283
+ kind,
268
284
  ) =>
269
285
  request(
270
- `/api/artifacts/${agentName}/${userId}/${sessionId}/${filename}/execute`,
286
+ `/api/artifacts/${agentName}/${userId}/${sessionId}/${filename}/execute${kindQuery(kind)}`,
271
287
  {
272
288
  method: "POST",
273
289
  body: JSON.stringify(options || {}),
@@ -957,24 +973,21 @@ export const demandEmailVerification = (userId) =>
957
973
  export const disableAdminUserMfa = (userId) =>
958
974
  request(`/api/admin/users/${userId}/disable-mfa`, { method: "POST" });
959
975
 
960
- // Organisations — superadmin only; these answer 403 to an org admin.
961
- export const listAdminOrganizations = () => request("/api/admin/organizations");
962
-
963
- export const createAdminOrganization = ({ name, description }) =>
964
- request("/api/admin/organizations", {
965
- method: "POST",
966
- body: JSON.stringify({ name, ...(description ? { description } : {}) }),
967
- });
968
-
969
- export const renameAdminOrganization = (orgId, { name, description }) =>
970
- request(`/api/admin/organizations/${orgId}`, {
971
- method: "PATCH",
972
- body: JSON.stringify({ name, ...(description ? { description } : {}) }),
973
- });
974
-
975
- export const deleteAdminOrganization = (orgId) =>
976
- request(`/api/admin/organizations/${orgId}`, { method: "DELETE" });
977
-
978
- // A user belongs to at most one organisation, so this moves rather than adds.
979
- export const setUserOrganization = (orgId, userId) =>
980
- request(`/api/admin/organizations/${orgId}/members/${userId}`, { method: "PUT" });
976
+ /**
977
+ * Fetches a file's bytes through the authenticated API and hands back a Blob.
978
+ *
979
+ * A PDF or an image has no text body to rebuild client-side: downloading it
980
+ * from what the artifact endpoint returns would write an empty file. The
981
+ * download route serves the object itself.
982
+ */
983
+ export const downloadAgentFile = async (agentName, filename) => {
984
+ const token = getAuthToken();
985
+ const res = await fetch(
986
+ apiUrl(`/api/files/${agentName}/${encodeURIComponent(filename)}`),
987
+ { headers: token ? { Authorization: `Bearer ${token}` } : {} },
988
+ );
989
+ if (!res.ok) {
990
+ throw new Error(`Download failed (${res.status})`);
991
+ }
992
+ return res.blob();
993
+ };