@alva-ai/toolkit 0.11.2 → 0.11.3-beta.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.
- package/README.md +23 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/cli.js +531 -51
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +244 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +111 -1
- package/dist/index.d.ts +111 -1
- package/dist/index.js +241 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,8 @@ __export(src_exports, {
|
|
|
23
23
|
AlvaClient: () => AlvaClient,
|
|
24
24
|
AlvaError: () => AlvaError,
|
|
25
25
|
PBSV_UPDATE_MESSAGE: () => PBSV_UPDATE_MESSAGE,
|
|
26
|
+
SUBSCRIBE_PROPOSE_MESSAGE: () => SUBSCRIBE_PROPOSE_MESSAGE,
|
|
27
|
+
SUBSCRIBE_RESULT_MESSAGE: () => SUBSCRIBE_RESULT_MESSAGE,
|
|
26
28
|
UDF_AUTH_REQUIRED_MESSAGE: () => UDF_AUTH_REQUIRED_MESSAGE,
|
|
27
29
|
UDF_CONSENT_REQUEST_MESSAGE: () => UDF_CONSENT_REQUEST_MESSAGE,
|
|
28
30
|
UDF_CONSENT_RESPONSE_MESSAGE: () => UDF_CONSENT_RESPONSE_MESSAGE,
|
|
@@ -45,6 +47,7 @@ __export(src_exports, {
|
|
|
45
47
|
installPlaybookRuntime: () => installPlaybookRuntime,
|
|
46
48
|
mapUdfErrorResponse: () => mapUdfErrorResponse,
|
|
47
49
|
playbookIdFromToken: () => playbookIdFromToken,
|
|
50
|
+
subscribe: () => subscribe,
|
|
48
51
|
udf: () => udf
|
|
49
52
|
});
|
|
50
53
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -1639,6 +1642,36 @@ var SKILL_ENDPOINT_METADATA = [
|
|
|
1639
1642
|
required_subscription_tier: "pro",
|
|
1640
1643
|
access: "pro_only",
|
|
1641
1644
|
pro_required: true
|
|
1645
|
+
},
|
|
1646
|
+
{
|
|
1647
|
+
skill: "arrays-data-api-equity-fundamentals",
|
|
1648
|
+
file: "company-detail-non-us",
|
|
1649
|
+
method: "GET",
|
|
1650
|
+
path: "/api/v1/stocks/non-us/company/detail",
|
|
1651
|
+
tier: "public",
|
|
1652
|
+
required_subscription_tier: "free",
|
|
1653
|
+
access: "free_and_pro",
|
|
1654
|
+
pro_required: false
|
|
1655
|
+
},
|
|
1656
|
+
{
|
|
1657
|
+
skill: "arrays-data-api-social-feeds",
|
|
1658
|
+
file: "x-search",
|
|
1659
|
+
method: "GET",
|
|
1660
|
+
path: "/api/v1/social-feeds/x/search",
|
|
1661
|
+
tier: "alternative",
|
|
1662
|
+
required_subscription_tier: "pro",
|
|
1663
|
+
access: "pro_only",
|
|
1664
|
+
pro_required: true
|
|
1665
|
+
},
|
|
1666
|
+
{
|
|
1667
|
+
skill: "arrays-data-api-spot-market-price-and-volume",
|
|
1668
|
+
file: "stocks-non-us-kline",
|
|
1669
|
+
method: "GET",
|
|
1670
|
+
path: "/api/v1/stocks/non-us/kline",
|
|
1671
|
+
tier: "public",
|
|
1672
|
+
required_subscription_tier: "free",
|
|
1673
|
+
access: "free_and_pro",
|
|
1674
|
+
pro_required: false
|
|
1642
1675
|
}
|
|
1643
1676
|
];
|
|
1644
1677
|
function getSkillEndpointMetadata(skill, file) {
|
|
@@ -2249,6 +2282,160 @@ var FeedbackResource = class {
|
|
|
2249
2282
|
}
|
|
2250
2283
|
};
|
|
2251
2284
|
|
|
2285
|
+
// src/resources/functions.ts
|
|
2286
|
+
var FunctionsResource = class {
|
|
2287
|
+
constructor(client) {
|
|
2288
|
+
this.client = client;
|
|
2289
|
+
}
|
|
2290
|
+
client;
|
|
2291
|
+
async register(params) {
|
|
2292
|
+
this.client._requireAuth();
|
|
2293
|
+
return this.client._request("POST", "/api/v1/service/functions", {
|
|
2294
|
+
body: {
|
|
2295
|
+
playbook_id: params.playbook_id,
|
|
2296
|
+
function_name: params.function_name,
|
|
2297
|
+
entry_script_path: params.entry_script_path,
|
|
2298
|
+
params_schema: params.params_schema,
|
|
2299
|
+
allow_charges: params.allow_charges
|
|
2300
|
+
}
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
async list(params) {
|
|
2304
|
+
this.client._requireAuth();
|
|
2305
|
+
return this.client._request("GET", "/api/v1/service/functions", {
|
|
2306
|
+
query: {
|
|
2307
|
+
playbook_id: params.playbook_id
|
|
2308
|
+
}
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
async delete(params) {
|
|
2312
|
+
this.client._requireAuth();
|
|
2313
|
+
await this.client._request("DELETE", "/api/v1/service/functions", {
|
|
2314
|
+
query: {
|
|
2315
|
+
playbook_id: params.playbook_id,
|
|
2316
|
+
function_name: params.function_name
|
|
2317
|
+
}
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
async invoke(params) {
|
|
2321
|
+
this.client._requireAuth();
|
|
2322
|
+
const response = await this.client._request(
|
|
2323
|
+
"POST",
|
|
2324
|
+
"/api/v1/service/invoke",
|
|
2325
|
+
{
|
|
2326
|
+
body: {
|
|
2327
|
+
playbook_id: params.playbook_id,
|
|
2328
|
+
function_name: params.function_name,
|
|
2329
|
+
parameters_json: JSON.stringify(params.parameters ?? {})
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
);
|
|
2333
|
+
return {
|
|
2334
|
+
...response,
|
|
2335
|
+
result: parseResultPayload(response.result)
|
|
2336
|
+
};
|
|
2337
|
+
}
|
|
2338
|
+
async getAllowance(params) {
|
|
2339
|
+
this.client._requireAuth();
|
|
2340
|
+
const response = await this.client._request(
|
|
2341
|
+
"GET",
|
|
2342
|
+
"/api/v1/service/allowance",
|
|
2343
|
+
{
|
|
2344
|
+
query: {
|
|
2345
|
+
playbook_id: params.playbook_id
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
);
|
|
2349
|
+
return normalizeAllowance(response.allowance);
|
|
2350
|
+
}
|
|
2351
|
+
async listAllowances() {
|
|
2352
|
+
this.client._requireAuth();
|
|
2353
|
+
const response = await this.client._request(
|
|
2354
|
+
"GET",
|
|
2355
|
+
"/api/v1/service/allowances"
|
|
2356
|
+
);
|
|
2357
|
+
return {
|
|
2358
|
+
allowances: (response.allowances ?? []).map((allowance) => normalizeAllowance(allowance)).filter(
|
|
2359
|
+
(allowance) => allowance !== null
|
|
2360
|
+
)
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2363
|
+
async createAllowance(params) {
|
|
2364
|
+
this.client._requireAuth();
|
|
2365
|
+
const response = await this.client._request(
|
|
2366
|
+
"POST",
|
|
2367
|
+
"/api/v1/service/allowance",
|
|
2368
|
+
{
|
|
2369
|
+
body: {
|
|
2370
|
+
playbook_id: params.playbook_id,
|
|
2371
|
+
amount: params.amount
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
);
|
|
2375
|
+
return { allowance: requireAllowance(response.allowance) };
|
|
2376
|
+
}
|
|
2377
|
+
async revokeAllowance(params) {
|
|
2378
|
+
this.client._requireAuth();
|
|
2379
|
+
await this.client._request("DELETE", "/api/v1/service/allowance", {
|
|
2380
|
+
query: {
|
|
2381
|
+
playbook_id: params.playbook_id
|
|
2382
|
+
}
|
|
2383
|
+
});
|
|
2384
|
+
return { ok: true };
|
|
2385
|
+
}
|
|
2386
|
+
};
|
|
2387
|
+
function normalizeAllowance(raw) {
|
|
2388
|
+
if (!raw) return null;
|
|
2389
|
+
const allowance = {
|
|
2390
|
+
id: raw.id ?? "",
|
|
2391
|
+
consumer_uid: raw.consumer_uid ?? raw.consumerUid ?? "",
|
|
2392
|
+
playbook_id: raw.playbook_id ?? raw.playbookId ?? "",
|
|
2393
|
+
amount: raw.amount ?? 0,
|
|
2394
|
+
used: raw.used ?? 0,
|
|
2395
|
+
remaining: raw.remaining ?? 0
|
|
2396
|
+
};
|
|
2397
|
+
const createdAtMs = timestampMs(
|
|
2398
|
+
raw.created_at_ms ?? raw.createdAtMs ?? raw.created_at ?? raw.createdAt
|
|
2399
|
+
);
|
|
2400
|
+
const updatedAtMs = timestampMs(
|
|
2401
|
+
raw.updated_at_ms ?? raw.updatedAtMs ?? raw.updated_at ?? raw.updatedAt
|
|
2402
|
+
);
|
|
2403
|
+
if (createdAtMs !== void 0) allowance.created_at_ms = createdAtMs;
|
|
2404
|
+
if (updatedAtMs !== void 0) allowance.updated_at_ms = updatedAtMs;
|
|
2405
|
+
return allowance;
|
|
2406
|
+
}
|
|
2407
|
+
function requireAllowance(raw) {
|
|
2408
|
+
const allowance = normalizeAllowance(raw);
|
|
2409
|
+
if (!allowance) {
|
|
2410
|
+
throw new Error("allowance response missing allowance");
|
|
2411
|
+
}
|
|
2412
|
+
return allowance;
|
|
2413
|
+
}
|
|
2414
|
+
function timestampMs(value) {
|
|
2415
|
+
if (value === void 0 || value === null) return void 0;
|
|
2416
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
2417
|
+
if (typeof value === "string") {
|
|
2418
|
+
const numeric = Number(value);
|
|
2419
|
+
if (Number.isFinite(numeric)) return numeric;
|
|
2420
|
+
const parsed = Date.parse(value);
|
|
2421
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
2422
|
+
}
|
|
2423
|
+
if (typeof value !== "object") return void 0;
|
|
2424
|
+
const ts = value;
|
|
2425
|
+
const seconds = typeof ts.seconds === "number" ? ts.seconds : typeof ts.seconds === "string" ? Number(ts.seconds) : void 0;
|
|
2426
|
+
const nanos = typeof ts.nanos === "number" ? ts.nanos : typeof ts.nanos === "string" ? Number(ts.nanos) : 0;
|
|
2427
|
+
if (seconds === void 0 || !Number.isFinite(seconds)) return void 0;
|
|
2428
|
+
return seconds * 1e3 + Math.floor((Number.isFinite(nanos) ? nanos : 0) / 1e6);
|
|
2429
|
+
}
|
|
2430
|
+
function parseResultPayload(result) {
|
|
2431
|
+
if (typeof result !== "string") return result;
|
|
2432
|
+
try {
|
|
2433
|
+
return JSON.parse(result);
|
|
2434
|
+
} catch {
|
|
2435
|
+
return result;
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2252
2439
|
// src/client.ts
|
|
2253
2440
|
var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
|
|
2254
2441
|
var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
|
|
@@ -2283,6 +2470,7 @@ var AlvaClient = class {
|
|
|
2283
2470
|
_subscriptions;
|
|
2284
2471
|
_channelGroupSubscriptions;
|
|
2285
2472
|
_feedback;
|
|
2473
|
+
_functions;
|
|
2286
2474
|
constructor(config) {
|
|
2287
2475
|
this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
2288
2476
|
this.arraysBaseUrl = config.arraysBaseUrl ?? DEFAULT_ARRAYS_BASE_URL;
|
|
@@ -2359,6 +2547,9 @@ var AlvaClient = class {
|
|
|
2359
2547
|
get feedback() {
|
|
2360
2548
|
return this._feedback ??= new FeedbackResource(this);
|
|
2361
2549
|
}
|
|
2550
|
+
get functions() {
|
|
2551
|
+
return this._functions ??= new FunctionsResource(this);
|
|
2552
|
+
}
|
|
2362
2553
|
_requireAuth() {
|
|
2363
2554
|
if (!this.pbsvToken && !this.viewer_token && !this.apiKey) {
|
|
2364
2555
|
throw new AlvaError(
|
|
@@ -2518,6 +2709,8 @@ var PBSV_UPDATE_MESSAGE = "alva:pbsv:update";
|
|
|
2518
2709
|
var UDF_CONSENT_REQUEST_MESSAGE = "alva:udf:consent-request";
|
|
2519
2710
|
var UDF_CONSENT_RESPONSE_MESSAGE = "alva:udf:consent-response";
|
|
2520
2711
|
var UDF_AUTH_REQUIRED_MESSAGE = "alva:udf:auth-required";
|
|
2712
|
+
var SUBSCRIBE_PROPOSE_MESSAGE = "alva:subscribe:propose";
|
|
2713
|
+
var SUBSCRIBE_RESULT_MESSAGE = "alva:subscribe:result";
|
|
2521
2714
|
var DEFAULT_API_ORIGIN = "https://api-llm.prd.alva.ai";
|
|
2522
2715
|
var CONSENT_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
2523
2716
|
var cachedToken = null;
|
|
@@ -2527,6 +2720,13 @@ var playbookIdFromBoot = null;
|
|
|
2527
2720
|
var runtimeWindow = null;
|
|
2528
2721
|
var installed = false;
|
|
2529
2722
|
var pendingConsents = /* @__PURE__ */ new Map();
|
|
2723
|
+
var pendingProposals = /* @__PURE__ */ new Map();
|
|
2724
|
+
var normalizeProposalResult = (value) => {
|
|
2725
|
+
if (value === "subscribed" || value === "declined" || value === "timeout") {
|
|
2726
|
+
return value;
|
|
2727
|
+
}
|
|
2728
|
+
return "error";
|
|
2729
|
+
};
|
|
2530
2730
|
var decodeBase64Url = (value) => {
|
|
2531
2731
|
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
2532
2732
|
const padded = normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "=");
|
|
@@ -2574,7 +2774,7 @@ var safeJson = async (response) => {
|
|
|
2574
2774
|
return {};
|
|
2575
2775
|
}
|
|
2576
2776
|
};
|
|
2577
|
-
var
|
|
2777
|
+
var parseResultPayload2 = (result) => {
|
|
2578
2778
|
if (typeof result !== "string") return result;
|
|
2579
2779
|
try {
|
|
2580
2780
|
return JSON.parse(result);
|
|
@@ -2586,7 +2786,7 @@ var normalizeInvokeResponse = (body) => {
|
|
|
2586
2786
|
const envelope = body;
|
|
2587
2787
|
return {
|
|
2588
2788
|
...envelope,
|
|
2589
|
-
result:
|
|
2789
|
+
result: parseResultPayload2(envelope.result)
|
|
2590
2790
|
};
|
|
2591
2791
|
};
|
|
2592
2792
|
var errorMetadata = (body) => body.error?.metadata || body.details?.metadata || {};
|
|
@@ -2632,6 +2832,15 @@ var onMessage = (event) => {
|
|
|
2632
2832
|
}
|
|
2633
2833
|
return;
|
|
2634
2834
|
}
|
|
2835
|
+
if (data.type === SUBSCRIBE_RESULT_MESSAGE) {
|
|
2836
|
+
if (typeof data.request_id !== "string") return;
|
|
2837
|
+
const pending2 = pendingProposals.get(data.request_id);
|
|
2838
|
+
if (!pending2) return;
|
|
2839
|
+
clearTimeout(pending2.timer);
|
|
2840
|
+
pendingProposals.delete(data.request_id);
|
|
2841
|
+
pending2.resolve(normalizeProposalResult(data.status));
|
|
2842
|
+
return;
|
|
2843
|
+
}
|
|
2635
2844
|
if (data.type !== UDF_CONSENT_RESPONSE_MESSAGE) return;
|
|
2636
2845
|
if (typeof data.request_id !== "string") return;
|
|
2637
2846
|
const pending = pendingConsents.get(data.request_id);
|
|
@@ -2670,6 +2879,33 @@ var requestConsent = async (playbookId, minAllowance) => {
|
|
|
2670
2879
|
);
|
|
2671
2880
|
});
|
|
2672
2881
|
};
|
|
2882
|
+
var proposeSubscribe = async (input) => {
|
|
2883
|
+
if (!runtimeWindow || !expectedParentOrigin) return "error";
|
|
2884
|
+
const feedOwner = typeof input?.feedOwner === "string" ? input.feedOwner.trim() : "";
|
|
2885
|
+
const feedName = typeof input?.feedName === "string" ? input.feedName.trim() : "";
|
|
2886
|
+
if (!feedOwner || !feedName) return "error";
|
|
2887
|
+
const targetOrigin = expectedParentOrigin;
|
|
2888
|
+
const requestId = randomRequestId();
|
|
2889
|
+
return new Promise((resolve) => {
|
|
2890
|
+
const timer = setTimeout(() => {
|
|
2891
|
+
pendingProposals.delete(requestId);
|
|
2892
|
+
resolve("timeout");
|
|
2893
|
+
}, CONSENT_TIMEOUT_MS);
|
|
2894
|
+
pendingProposals.set(requestId, { resolve, timer });
|
|
2895
|
+
runtimeWindow?.parent.postMessage(
|
|
2896
|
+
{
|
|
2897
|
+
type: SUBSCRIBE_PROPOSE_MESSAGE,
|
|
2898
|
+
request_id: requestId,
|
|
2899
|
+
playbook_id: playbookIdFromBoot,
|
|
2900
|
+
feed: { owner: feedOwner, name: feedName }
|
|
2901
|
+
},
|
|
2902
|
+
targetOrigin
|
|
2903
|
+
);
|
|
2904
|
+
});
|
|
2905
|
+
};
|
|
2906
|
+
var subscribe = {
|
|
2907
|
+
propose: proposeSubscribe
|
|
2908
|
+
};
|
|
2673
2909
|
var requestAuthentication = (functionName) => {
|
|
2674
2910
|
if (!runtimeWindow || !expectedParentOrigin) return;
|
|
2675
2911
|
runtimeWindow.parent.postMessage(
|
|
@@ -2838,17 +3074,20 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
2838
3074
|
const existing = target.alva || {};
|
|
2839
3075
|
target.alva = {
|
|
2840
3076
|
...existing,
|
|
2841
|
-
udf
|
|
3077
|
+
udf,
|
|
3078
|
+
subscribe
|
|
2842
3079
|
};
|
|
2843
3080
|
};
|
|
2844
3081
|
|
|
2845
3082
|
// src/index.ts
|
|
2846
|
-
var VERSION = true ? "0.11.
|
|
3083
|
+
var VERSION = true ? "0.11.3-beta.0" : "dev";
|
|
2847
3084
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2848
3085
|
0 && (module.exports = {
|
|
2849
3086
|
AlvaClient,
|
|
2850
3087
|
AlvaError,
|
|
2851
3088
|
PBSV_UPDATE_MESSAGE,
|
|
3089
|
+
SUBSCRIBE_PROPOSE_MESSAGE,
|
|
3090
|
+
SUBSCRIBE_RESULT_MESSAGE,
|
|
2852
3091
|
UDF_AUTH_REQUIRED_MESSAGE,
|
|
2853
3092
|
UDF_CONSENT_REQUEST_MESSAGE,
|
|
2854
3093
|
UDF_CONSENT_RESPONSE_MESSAGE,
|
|
@@ -2871,6 +3110,7 @@ var VERSION = true ? "0.11.2" : "dev";
|
|
|
2871
3110
|
installPlaybookRuntime,
|
|
2872
3111
|
mapUdfErrorResponse,
|
|
2873
3112
|
playbookIdFromToken,
|
|
3113
|
+
subscribe,
|
|
2874
3114
|
udf
|
|
2875
3115
|
});
|
|
2876
3116
|
//# sourceMappingURL=index.cjs.map
|