@alva-ai/toolkit 0.9.3 → 0.9.5
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/README.md +4 -3
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/cli.js +85 -11
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +73 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -2
- package/dist/index.d.ts +39 -2
- package/dist/index.js +72 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,7 @@ __export(src_exports, {
|
|
|
23
23
|
AlvaClient: () => AlvaClient,
|
|
24
24
|
AlvaError: () => AlvaError,
|
|
25
25
|
PBSV_UPDATE_MESSAGE: () => PBSV_UPDATE_MESSAGE,
|
|
26
|
+
UDF_AUTH_REQUIRED_MESSAGE: () => UDF_AUTH_REQUIRED_MESSAGE,
|
|
26
27
|
UDF_CONSENT_REQUEST_MESSAGE: () => UDF_CONSENT_REQUEST_MESSAGE,
|
|
27
28
|
UDF_CONSENT_RESPONSE_MESSAGE: () => UDF_CONSENT_RESPONSE_MESSAGE,
|
|
28
29
|
UdfAuthRequiredError: () => UdfAuthRequiredError,
|
|
@@ -218,7 +219,8 @@ var DeployResource = class {
|
|
|
218
219
|
path: params.path,
|
|
219
220
|
cron_expression: params.cron_expression,
|
|
220
221
|
args: params.args,
|
|
221
|
-
push_notify: params.push_notify
|
|
222
|
+
push_notify: params.push_notify,
|
|
223
|
+
max_heap_size_mb: params.max_heap_size_mb
|
|
222
224
|
}
|
|
223
225
|
});
|
|
224
226
|
}
|
|
@@ -372,6 +374,11 @@ var FeedResource = class {
|
|
|
372
374
|
};
|
|
373
375
|
|
|
374
376
|
// src/resources/playbooks.ts
|
|
377
|
+
var PLAYBOOK_VISIBILITIES = [
|
|
378
|
+
"public",
|
|
379
|
+
"private",
|
|
380
|
+
"paid"
|
|
381
|
+
];
|
|
375
382
|
var PlaybooksResource = class {
|
|
376
383
|
constructor(client) {
|
|
377
384
|
this.client = client;
|
|
@@ -405,6 +412,30 @@ var PlaybooksResource = class {
|
|
|
405
412
|
has_next: raw.has_next ?? false
|
|
406
413
|
};
|
|
407
414
|
}
|
|
415
|
+
/**
|
|
416
|
+
* Set a playbook's visibility. Requires authentication; the owner is
|
|
417
|
+
* resolved server-side from the authenticated user, so only the playbook
|
|
418
|
+
* `name` is needed.
|
|
419
|
+
*
|
|
420
|
+
* Note: `private` and `paid` are paid-tier capabilities. A free-tier user
|
|
421
|
+
* receives a `PERMISSION_DENIED` error from the gateway, which is surfaced
|
|
422
|
+
* here unchanged.
|
|
423
|
+
*/
|
|
424
|
+
async setVisibility(params) {
|
|
425
|
+
if (!PLAYBOOK_VISIBILITIES.includes(params.visibility)) {
|
|
426
|
+
throw new AlvaError(
|
|
427
|
+
"INVALID_ARGUMENT",
|
|
428
|
+
`Invalid visibility "${params.visibility}". Expected one of: ${PLAYBOOK_VISIBILITIES.join(", ")}.`,
|
|
429
|
+
400
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
this.client._requireAuth();
|
|
433
|
+
return await this.client._request(
|
|
434
|
+
"POST",
|
|
435
|
+
`/api/v1/playbook/${encodeURIComponent(params.name)}/visibility`,
|
|
436
|
+
{ body: { visibility: params.visibility } }
|
|
437
|
+
);
|
|
438
|
+
}
|
|
408
439
|
};
|
|
409
440
|
function toAgentPlaybook(raw) {
|
|
410
441
|
const username = raw.creator?.name ?? "";
|
|
@@ -2433,6 +2464,7 @@ var UdfTransportError = class extends UdfError {
|
|
|
2433
2464
|
var PBSV_UPDATE_MESSAGE = "alva:pbsv:update";
|
|
2434
2465
|
var UDF_CONSENT_REQUEST_MESSAGE = "alva:udf:consent-request";
|
|
2435
2466
|
var UDF_CONSENT_RESPONSE_MESSAGE = "alva:udf:consent-response";
|
|
2467
|
+
var UDF_AUTH_REQUIRED_MESSAGE = "alva:udf:auth-required";
|
|
2436
2468
|
var DEFAULT_API_ORIGIN = "https://api-llm.prd.alva.ai";
|
|
2437
2469
|
var CONSENT_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
2438
2470
|
var cachedToken = null;
|
|
@@ -2461,6 +2493,7 @@ var playbookIdFromToken = (token) => {
|
|
|
2461
2493
|
return null;
|
|
2462
2494
|
};
|
|
2463
2495
|
var getViewerToken = () => cachedToken;
|
|
2496
|
+
var isAuthenticated = () => !!getViewerToken();
|
|
2464
2497
|
var stripPbsvFromUrl = (targetWindow) => {
|
|
2465
2498
|
const url = new URL(targetWindow.location.href);
|
|
2466
2499
|
url.searchParams.delete("_pbsv");
|
|
@@ -2488,6 +2521,21 @@ var safeJson = async (response) => {
|
|
|
2488
2521
|
return {};
|
|
2489
2522
|
}
|
|
2490
2523
|
};
|
|
2524
|
+
var parseResultPayload = (result) => {
|
|
2525
|
+
if (typeof result !== "string") return result;
|
|
2526
|
+
try {
|
|
2527
|
+
return JSON.parse(result);
|
|
2528
|
+
} catch {
|
|
2529
|
+
return result;
|
|
2530
|
+
}
|
|
2531
|
+
};
|
|
2532
|
+
var normalizeInvokeResponse = (body) => {
|
|
2533
|
+
const envelope = body;
|
|
2534
|
+
return {
|
|
2535
|
+
...envelope,
|
|
2536
|
+
result: parseResultPayload(envelope.result)
|
|
2537
|
+
};
|
|
2538
|
+
};
|
|
2491
2539
|
var errorMetadata = (body) => body.error?.metadata || body.details?.metadata || {};
|
|
2492
2540
|
var mapUdfErrorResponse = (body, status) => {
|
|
2493
2541
|
const code = body.error?.code || "TRANSPORT";
|
|
@@ -2569,6 +2617,16 @@ var requestConsent = async (playbookId, minAllowance) => {
|
|
|
2569
2617
|
);
|
|
2570
2618
|
});
|
|
2571
2619
|
};
|
|
2620
|
+
var requestAuthentication = (functionName) => {
|
|
2621
|
+
if (!runtimeWindow || !expectedParentOrigin) return;
|
|
2622
|
+
runtimeWindow.parent.postMessage(
|
|
2623
|
+
{
|
|
2624
|
+
type: UDF_AUTH_REQUIRED_MESSAGE,
|
|
2625
|
+
function_name: functionName
|
|
2626
|
+
},
|
|
2627
|
+
expectedParentOrigin
|
|
2628
|
+
);
|
|
2629
|
+
};
|
|
2572
2630
|
var call = async (functionName, params, retried = false) => {
|
|
2573
2631
|
const token = getViewerToken();
|
|
2574
2632
|
if (!token) throw new UdfAuthRequiredError();
|
|
@@ -2605,7 +2663,7 @@ var call = async (functionName, params, retried = false) => {
|
|
|
2605
2663
|
}
|
|
2606
2664
|
const body = await safeJson(response);
|
|
2607
2665
|
if (response.ok) {
|
|
2608
|
-
return body
|
|
2666
|
+
return normalizeInvokeResponse(body);
|
|
2609
2667
|
}
|
|
2610
2668
|
if (body.error?.code === "CONSENT_REQUIRED" && !retried) {
|
|
2611
2669
|
const metadata = errorMetadata(body);
|
|
@@ -2660,11 +2718,15 @@ var renderButton = (target, options) => {
|
|
|
2660
2718
|
const disabledLabel = options.disabledLabel || "Sign in to run";
|
|
2661
2719
|
button.type = "button";
|
|
2662
2720
|
button.className = "alva-udf-button";
|
|
2663
|
-
button.textContent =
|
|
2664
|
-
button.disabled =
|
|
2721
|
+
button.textContent = isAuthenticated() ? label : disabledLabel;
|
|
2722
|
+
button.disabled = false;
|
|
2665
2723
|
button.setAttribute("data-function-name", options.functionName);
|
|
2666
|
-
if (
|
|
2724
|
+
if (!isAuthenticated()) button.setAttribute("aria-disabled", "true");
|
|
2667
2725
|
button.addEventListener("click", async () => {
|
|
2726
|
+
if (!isAuthenticated()) {
|
|
2727
|
+
requestAuthentication(options.functionName);
|
|
2728
|
+
return;
|
|
2729
|
+
}
|
|
2668
2730
|
if (button.disabled) return;
|
|
2669
2731
|
button.disabled = true;
|
|
2670
2732
|
button.textContent = loadingLabel;
|
|
@@ -2683,8 +2745,9 @@ var renderButton = (target, options) => {
|
|
|
2683
2745
|
error
|
|
2684
2746
|
});
|
|
2685
2747
|
} finally {
|
|
2686
|
-
button.disabled =
|
|
2687
|
-
button.textContent =
|
|
2748
|
+
button.disabled = false;
|
|
2749
|
+
button.textContent = isAuthenticated() ? label : disabledLabel;
|
|
2750
|
+
if (!isAuthenticated()) button.setAttribute("aria-disabled", "true");
|
|
2688
2751
|
}
|
|
2689
2752
|
});
|
|
2690
2753
|
container.appendChild(button);
|
|
@@ -2694,6 +2757,7 @@ var udf = {
|
|
|
2694
2757
|
call,
|
|
2695
2758
|
list,
|
|
2696
2759
|
getViewerToken,
|
|
2760
|
+
isAuthenticated,
|
|
2697
2761
|
renderButton,
|
|
2698
2762
|
UdfError,
|
|
2699
2763
|
UdfAuthRequiredError,
|
|
@@ -2726,12 +2790,13 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
2726
2790
|
};
|
|
2727
2791
|
|
|
2728
2792
|
// src/index.ts
|
|
2729
|
-
var VERSION = true ? "0.9.
|
|
2793
|
+
var VERSION = true ? "0.9.5" : "dev";
|
|
2730
2794
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2731
2795
|
0 && (module.exports = {
|
|
2732
2796
|
AlvaClient,
|
|
2733
2797
|
AlvaError,
|
|
2734
2798
|
PBSV_UPDATE_MESSAGE,
|
|
2799
|
+
UDF_AUTH_REQUIRED_MESSAGE,
|
|
2735
2800
|
UDF_CONSENT_REQUEST_MESSAGE,
|
|
2736
2801
|
UDF_CONSENT_RESPONSE_MESSAGE,
|
|
2737
2802
|
UdfAuthRequiredError,
|