@alva-ai/toolkit 0.9.3 → 0.9.4
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 +24 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +44 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +43 -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
|
}
|
|
@@ -2433,6 +2435,7 @@ var UdfTransportError = class extends UdfError {
|
|
|
2433
2435
|
var PBSV_UPDATE_MESSAGE = "alva:pbsv:update";
|
|
2434
2436
|
var UDF_CONSENT_REQUEST_MESSAGE = "alva:udf:consent-request";
|
|
2435
2437
|
var UDF_CONSENT_RESPONSE_MESSAGE = "alva:udf:consent-response";
|
|
2438
|
+
var UDF_AUTH_REQUIRED_MESSAGE = "alva:udf:auth-required";
|
|
2436
2439
|
var DEFAULT_API_ORIGIN = "https://api-llm.prd.alva.ai";
|
|
2437
2440
|
var CONSENT_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
2438
2441
|
var cachedToken = null;
|
|
@@ -2461,6 +2464,7 @@ var playbookIdFromToken = (token) => {
|
|
|
2461
2464
|
return null;
|
|
2462
2465
|
};
|
|
2463
2466
|
var getViewerToken = () => cachedToken;
|
|
2467
|
+
var isAuthenticated = () => !!getViewerToken();
|
|
2464
2468
|
var stripPbsvFromUrl = (targetWindow) => {
|
|
2465
2469
|
const url = new URL(targetWindow.location.href);
|
|
2466
2470
|
url.searchParams.delete("_pbsv");
|
|
@@ -2488,6 +2492,21 @@ var safeJson = async (response) => {
|
|
|
2488
2492
|
return {};
|
|
2489
2493
|
}
|
|
2490
2494
|
};
|
|
2495
|
+
var parseResultPayload = (result) => {
|
|
2496
|
+
if (typeof result !== "string") return result;
|
|
2497
|
+
try {
|
|
2498
|
+
return JSON.parse(result);
|
|
2499
|
+
} catch {
|
|
2500
|
+
return result;
|
|
2501
|
+
}
|
|
2502
|
+
};
|
|
2503
|
+
var normalizeInvokeResponse = (body) => {
|
|
2504
|
+
const envelope = body;
|
|
2505
|
+
return {
|
|
2506
|
+
...envelope,
|
|
2507
|
+
result: parseResultPayload(envelope.result)
|
|
2508
|
+
};
|
|
2509
|
+
};
|
|
2491
2510
|
var errorMetadata = (body) => body.error?.metadata || body.details?.metadata || {};
|
|
2492
2511
|
var mapUdfErrorResponse = (body, status) => {
|
|
2493
2512
|
const code = body.error?.code || "TRANSPORT";
|
|
@@ -2569,6 +2588,16 @@ var requestConsent = async (playbookId, minAllowance) => {
|
|
|
2569
2588
|
);
|
|
2570
2589
|
});
|
|
2571
2590
|
};
|
|
2591
|
+
var requestAuthentication = (functionName) => {
|
|
2592
|
+
if (!runtimeWindow || !expectedParentOrigin) return;
|
|
2593
|
+
runtimeWindow.parent.postMessage(
|
|
2594
|
+
{
|
|
2595
|
+
type: UDF_AUTH_REQUIRED_MESSAGE,
|
|
2596
|
+
function_name: functionName
|
|
2597
|
+
},
|
|
2598
|
+
expectedParentOrigin
|
|
2599
|
+
);
|
|
2600
|
+
};
|
|
2572
2601
|
var call = async (functionName, params, retried = false) => {
|
|
2573
2602
|
const token = getViewerToken();
|
|
2574
2603
|
if (!token) throw new UdfAuthRequiredError();
|
|
@@ -2605,7 +2634,7 @@ var call = async (functionName, params, retried = false) => {
|
|
|
2605
2634
|
}
|
|
2606
2635
|
const body = await safeJson(response);
|
|
2607
2636
|
if (response.ok) {
|
|
2608
|
-
return body
|
|
2637
|
+
return normalizeInvokeResponse(body);
|
|
2609
2638
|
}
|
|
2610
2639
|
if (body.error?.code === "CONSENT_REQUIRED" && !retried) {
|
|
2611
2640
|
const metadata = errorMetadata(body);
|
|
@@ -2660,11 +2689,15 @@ var renderButton = (target, options) => {
|
|
|
2660
2689
|
const disabledLabel = options.disabledLabel || "Sign in to run";
|
|
2661
2690
|
button.type = "button";
|
|
2662
2691
|
button.className = "alva-udf-button";
|
|
2663
|
-
button.textContent =
|
|
2664
|
-
button.disabled =
|
|
2692
|
+
button.textContent = isAuthenticated() ? label : disabledLabel;
|
|
2693
|
+
button.disabled = false;
|
|
2665
2694
|
button.setAttribute("data-function-name", options.functionName);
|
|
2666
|
-
if (
|
|
2695
|
+
if (!isAuthenticated()) button.setAttribute("aria-disabled", "true");
|
|
2667
2696
|
button.addEventListener("click", async () => {
|
|
2697
|
+
if (!isAuthenticated()) {
|
|
2698
|
+
requestAuthentication(options.functionName);
|
|
2699
|
+
return;
|
|
2700
|
+
}
|
|
2668
2701
|
if (button.disabled) return;
|
|
2669
2702
|
button.disabled = true;
|
|
2670
2703
|
button.textContent = loadingLabel;
|
|
@@ -2683,8 +2716,9 @@ var renderButton = (target, options) => {
|
|
|
2683
2716
|
error
|
|
2684
2717
|
});
|
|
2685
2718
|
} finally {
|
|
2686
|
-
button.disabled =
|
|
2687
|
-
button.textContent =
|
|
2719
|
+
button.disabled = false;
|
|
2720
|
+
button.textContent = isAuthenticated() ? label : disabledLabel;
|
|
2721
|
+
if (!isAuthenticated()) button.setAttribute("aria-disabled", "true");
|
|
2688
2722
|
}
|
|
2689
2723
|
});
|
|
2690
2724
|
container.appendChild(button);
|
|
@@ -2694,6 +2728,7 @@ var udf = {
|
|
|
2694
2728
|
call,
|
|
2695
2729
|
list,
|
|
2696
2730
|
getViewerToken,
|
|
2731
|
+
isAuthenticated,
|
|
2697
2732
|
renderButton,
|
|
2698
2733
|
UdfError,
|
|
2699
2734
|
UdfAuthRequiredError,
|
|
@@ -2726,12 +2761,13 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
2726
2761
|
};
|
|
2727
2762
|
|
|
2728
2763
|
// src/index.ts
|
|
2729
|
-
var VERSION = true ? "0.9.
|
|
2764
|
+
var VERSION = true ? "0.9.4" : "dev";
|
|
2730
2765
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2731
2766
|
0 && (module.exports = {
|
|
2732
2767
|
AlvaClient,
|
|
2733
2768
|
AlvaError,
|
|
2734
2769
|
PBSV_UPDATE_MESSAGE,
|
|
2770
|
+
UDF_AUTH_REQUIRED_MESSAGE,
|
|
2735
2771
|
UDF_CONSENT_REQUEST_MESSAGE,
|
|
2736
2772
|
UDF_CONSENT_RESPONSE_MESSAGE,
|
|
2737
2773
|
UdfAuthRequiredError,
|