@alva-ai/toolkit 0.11.2-beta.0 → 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 +583 -59
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +279 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +134 -1
- package/dist/index.d.ts +134 -1
- package/dist/index.js +276 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -302,6 +302,33 @@ var FeedResource = class {
|
|
|
302
302
|
this.client = client;
|
|
303
303
|
}
|
|
304
304
|
client;
|
|
305
|
+
/**
|
|
306
|
+
* Stop a feed's producer cronjob. This pauses future scheduled runs while
|
|
307
|
+
* preserving the feed and its existing data.
|
|
308
|
+
*
|
|
309
|
+
* Auth: caller must own the feed (uid match), enforced by the backend.
|
|
310
|
+
*/
|
|
311
|
+
async stop(params) {
|
|
312
|
+
this.client._requireAuth();
|
|
313
|
+
const id = requireFeedID(params.id);
|
|
314
|
+
return this.client._request(
|
|
315
|
+
"POST",
|
|
316
|
+
`/api/v1/feed/${encodeURIComponent(String(id))}/stop`
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Resume a stopped feed's producer cronjob.
|
|
321
|
+
*
|
|
322
|
+
* Auth: caller must own the feed (uid match), enforced by the backend.
|
|
323
|
+
*/
|
|
324
|
+
async resume(params) {
|
|
325
|
+
this.client._requireAuth();
|
|
326
|
+
const id = requireFeedID(params.id);
|
|
327
|
+
return this.client._request(
|
|
328
|
+
"POST",
|
|
329
|
+
`/api/v1/feed/${encodeURIComponent(String(id))}/resume`
|
|
330
|
+
);
|
|
331
|
+
}
|
|
305
332
|
/**
|
|
306
333
|
* Soft-delete a feed and all its active majors. Cascades:
|
|
307
334
|
* - all active feed_majors are soft-deleted in the same transaction
|
|
@@ -312,15 +339,19 @@ var FeedResource = class {
|
|
|
312
339
|
*/
|
|
313
340
|
async delete(params) {
|
|
314
341
|
this.client._requireAuth();
|
|
315
|
-
|
|
316
|
-
throw new Error("feed id must be a positive integer");
|
|
317
|
-
}
|
|
342
|
+
const id = requireFeedID(params.id);
|
|
318
343
|
return this.client._request(
|
|
319
344
|
"DELETE",
|
|
320
|
-
`/api/v1/feed/${encodeURIComponent(String(
|
|
345
|
+
`/api/v1/feed/${encodeURIComponent(String(id))}`
|
|
321
346
|
);
|
|
322
347
|
}
|
|
323
348
|
};
|
|
349
|
+
function requireFeedID(id) {
|
|
350
|
+
if (!Number.isInteger(id) || id <= 0) {
|
|
351
|
+
throw new Error("feed id must be a positive integer");
|
|
352
|
+
}
|
|
353
|
+
return id;
|
|
354
|
+
}
|
|
324
355
|
|
|
325
356
|
// src/resources/playbooks.ts
|
|
326
357
|
var PLAYBOOK_VISIBILITIES = [
|
|
@@ -1557,6 +1588,36 @@ var SKILL_ENDPOINT_METADATA = [
|
|
|
1557
1588
|
required_subscription_tier: "pro",
|
|
1558
1589
|
access: "pro_only",
|
|
1559
1590
|
pro_required: true
|
|
1591
|
+
},
|
|
1592
|
+
{
|
|
1593
|
+
skill: "arrays-data-api-equity-fundamentals",
|
|
1594
|
+
file: "company-detail-non-us",
|
|
1595
|
+
method: "GET",
|
|
1596
|
+
path: "/api/v1/stocks/non-us/company/detail",
|
|
1597
|
+
tier: "public",
|
|
1598
|
+
required_subscription_tier: "free",
|
|
1599
|
+
access: "free_and_pro",
|
|
1600
|
+
pro_required: false
|
|
1601
|
+
},
|
|
1602
|
+
{
|
|
1603
|
+
skill: "arrays-data-api-social-feeds",
|
|
1604
|
+
file: "x-search",
|
|
1605
|
+
method: "GET",
|
|
1606
|
+
path: "/api/v1/social-feeds/x/search",
|
|
1607
|
+
tier: "alternative",
|
|
1608
|
+
required_subscription_tier: "pro",
|
|
1609
|
+
access: "pro_only",
|
|
1610
|
+
pro_required: true
|
|
1611
|
+
},
|
|
1612
|
+
{
|
|
1613
|
+
skill: "arrays-data-api-spot-market-price-and-volume",
|
|
1614
|
+
file: "stocks-non-us-kline",
|
|
1615
|
+
method: "GET",
|
|
1616
|
+
path: "/api/v1/stocks/non-us/kline",
|
|
1617
|
+
tier: "public",
|
|
1618
|
+
required_subscription_tier: "free",
|
|
1619
|
+
access: "free_and_pro",
|
|
1620
|
+
pro_required: false
|
|
1560
1621
|
}
|
|
1561
1622
|
];
|
|
1562
1623
|
function getSkillEndpointMetadata(skill, file) {
|
|
@@ -2167,6 +2228,160 @@ var FeedbackResource = class {
|
|
|
2167
2228
|
}
|
|
2168
2229
|
};
|
|
2169
2230
|
|
|
2231
|
+
// src/resources/functions.ts
|
|
2232
|
+
var FunctionsResource = class {
|
|
2233
|
+
constructor(client) {
|
|
2234
|
+
this.client = client;
|
|
2235
|
+
}
|
|
2236
|
+
client;
|
|
2237
|
+
async register(params) {
|
|
2238
|
+
this.client._requireAuth();
|
|
2239
|
+
return this.client._request("POST", "/api/v1/service/functions", {
|
|
2240
|
+
body: {
|
|
2241
|
+
playbook_id: params.playbook_id,
|
|
2242
|
+
function_name: params.function_name,
|
|
2243
|
+
entry_script_path: params.entry_script_path,
|
|
2244
|
+
params_schema: params.params_schema,
|
|
2245
|
+
allow_charges: params.allow_charges
|
|
2246
|
+
}
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
async list(params) {
|
|
2250
|
+
this.client._requireAuth();
|
|
2251
|
+
return this.client._request("GET", "/api/v1/service/functions", {
|
|
2252
|
+
query: {
|
|
2253
|
+
playbook_id: params.playbook_id
|
|
2254
|
+
}
|
|
2255
|
+
});
|
|
2256
|
+
}
|
|
2257
|
+
async delete(params) {
|
|
2258
|
+
this.client._requireAuth();
|
|
2259
|
+
await this.client._request("DELETE", "/api/v1/service/functions", {
|
|
2260
|
+
query: {
|
|
2261
|
+
playbook_id: params.playbook_id,
|
|
2262
|
+
function_name: params.function_name
|
|
2263
|
+
}
|
|
2264
|
+
});
|
|
2265
|
+
}
|
|
2266
|
+
async invoke(params) {
|
|
2267
|
+
this.client._requireAuth();
|
|
2268
|
+
const response = await this.client._request(
|
|
2269
|
+
"POST",
|
|
2270
|
+
"/api/v1/service/invoke",
|
|
2271
|
+
{
|
|
2272
|
+
body: {
|
|
2273
|
+
playbook_id: params.playbook_id,
|
|
2274
|
+
function_name: params.function_name,
|
|
2275
|
+
parameters_json: JSON.stringify(params.parameters ?? {})
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
);
|
|
2279
|
+
return {
|
|
2280
|
+
...response,
|
|
2281
|
+
result: parseResultPayload(response.result)
|
|
2282
|
+
};
|
|
2283
|
+
}
|
|
2284
|
+
async getAllowance(params) {
|
|
2285
|
+
this.client._requireAuth();
|
|
2286
|
+
const response = await this.client._request(
|
|
2287
|
+
"GET",
|
|
2288
|
+
"/api/v1/service/allowance",
|
|
2289
|
+
{
|
|
2290
|
+
query: {
|
|
2291
|
+
playbook_id: params.playbook_id
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
);
|
|
2295
|
+
return normalizeAllowance(response.allowance);
|
|
2296
|
+
}
|
|
2297
|
+
async listAllowances() {
|
|
2298
|
+
this.client._requireAuth();
|
|
2299
|
+
const response = await this.client._request(
|
|
2300
|
+
"GET",
|
|
2301
|
+
"/api/v1/service/allowances"
|
|
2302
|
+
);
|
|
2303
|
+
return {
|
|
2304
|
+
allowances: (response.allowances ?? []).map((allowance) => normalizeAllowance(allowance)).filter(
|
|
2305
|
+
(allowance) => allowance !== null
|
|
2306
|
+
)
|
|
2307
|
+
};
|
|
2308
|
+
}
|
|
2309
|
+
async createAllowance(params) {
|
|
2310
|
+
this.client._requireAuth();
|
|
2311
|
+
const response = await this.client._request(
|
|
2312
|
+
"POST",
|
|
2313
|
+
"/api/v1/service/allowance",
|
|
2314
|
+
{
|
|
2315
|
+
body: {
|
|
2316
|
+
playbook_id: params.playbook_id,
|
|
2317
|
+
amount: params.amount
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
);
|
|
2321
|
+
return { allowance: requireAllowance(response.allowance) };
|
|
2322
|
+
}
|
|
2323
|
+
async revokeAllowance(params) {
|
|
2324
|
+
this.client._requireAuth();
|
|
2325
|
+
await this.client._request("DELETE", "/api/v1/service/allowance", {
|
|
2326
|
+
query: {
|
|
2327
|
+
playbook_id: params.playbook_id
|
|
2328
|
+
}
|
|
2329
|
+
});
|
|
2330
|
+
return { ok: true };
|
|
2331
|
+
}
|
|
2332
|
+
};
|
|
2333
|
+
function normalizeAllowance(raw) {
|
|
2334
|
+
if (!raw) return null;
|
|
2335
|
+
const allowance = {
|
|
2336
|
+
id: raw.id ?? "",
|
|
2337
|
+
consumer_uid: raw.consumer_uid ?? raw.consumerUid ?? "",
|
|
2338
|
+
playbook_id: raw.playbook_id ?? raw.playbookId ?? "",
|
|
2339
|
+
amount: raw.amount ?? 0,
|
|
2340
|
+
used: raw.used ?? 0,
|
|
2341
|
+
remaining: raw.remaining ?? 0
|
|
2342
|
+
};
|
|
2343
|
+
const createdAtMs = timestampMs(
|
|
2344
|
+
raw.created_at_ms ?? raw.createdAtMs ?? raw.created_at ?? raw.createdAt
|
|
2345
|
+
);
|
|
2346
|
+
const updatedAtMs = timestampMs(
|
|
2347
|
+
raw.updated_at_ms ?? raw.updatedAtMs ?? raw.updated_at ?? raw.updatedAt
|
|
2348
|
+
);
|
|
2349
|
+
if (createdAtMs !== void 0) allowance.created_at_ms = createdAtMs;
|
|
2350
|
+
if (updatedAtMs !== void 0) allowance.updated_at_ms = updatedAtMs;
|
|
2351
|
+
return allowance;
|
|
2352
|
+
}
|
|
2353
|
+
function requireAllowance(raw) {
|
|
2354
|
+
const allowance = normalizeAllowance(raw);
|
|
2355
|
+
if (!allowance) {
|
|
2356
|
+
throw new Error("allowance response missing allowance");
|
|
2357
|
+
}
|
|
2358
|
+
return allowance;
|
|
2359
|
+
}
|
|
2360
|
+
function timestampMs(value) {
|
|
2361
|
+
if (value === void 0 || value === null) return void 0;
|
|
2362
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
2363
|
+
if (typeof value === "string") {
|
|
2364
|
+
const numeric = Number(value);
|
|
2365
|
+
if (Number.isFinite(numeric)) return numeric;
|
|
2366
|
+
const parsed = Date.parse(value);
|
|
2367
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
2368
|
+
}
|
|
2369
|
+
if (typeof value !== "object") return void 0;
|
|
2370
|
+
const ts = value;
|
|
2371
|
+
const seconds = typeof ts.seconds === "number" ? ts.seconds : typeof ts.seconds === "string" ? Number(ts.seconds) : void 0;
|
|
2372
|
+
const nanos = typeof ts.nanos === "number" ? ts.nanos : typeof ts.nanos === "string" ? Number(ts.nanos) : 0;
|
|
2373
|
+
if (seconds === void 0 || !Number.isFinite(seconds)) return void 0;
|
|
2374
|
+
return seconds * 1e3 + Math.floor((Number.isFinite(nanos) ? nanos : 0) / 1e6);
|
|
2375
|
+
}
|
|
2376
|
+
function parseResultPayload(result) {
|
|
2377
|
+
if (typeof result !== "string") return result;
|
|
2378
|
+
try {
|
|
2379
|
+
return JSON.parse(result);
|
|
2380
|
+
} catch {
|
|
2381
|
+
return result;
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2170
2385
|
// src/client.ts
|
|
2171
2386
|
var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
|
|
2172
2387
|
var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
|
|
@@ -2201,6 +2416,7 @@ var AlvaClient = class {
|
|
|
2201
2416
|
_subscriptions;
|
|
2202
2417
|
_channelGroupSubscriptions;
|
|
2203
2418
|
_feedback;
|
|
2419
|
+
_functions;
|
|
2204
2420
|
constructor(config) {
|
|
2205
2421
|
this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
2206
2422
|
this.arraysBaseUrl = config.arraysBaseUrl ?? DEFAULT_ARRAYS_BASE_URL;
|
|
@@ -2277,6 +2493,9 @@ var AlvaClient = class {
|
|
|
2277
2493
|
get feedback() {
|
|
2278
2494
|
return this._feedback ??= new FeedbackResource(this);
|
|
2279
2495
|
}
|
|
2496
|
+
get functions() {
|
|
2497
|
+
return this._functions ??= new FunctionsResource(this);
|
|
2498
|
+
}
|
|
2280
2499
|
_requireAuth() {
|
|
2281
2500
|
if (!this.pbsvToken && !this.viewer_token && !this.apiKey) {
|
|
2282
2501
|
throw new AlvaError(
|
|
@@ -2436,6 +2655,8 @@ var PBSV_UPDATE_MESSAGE = "alva:pbsv:update";
|
|
|
2436
2655
|
var UDF_CONSENT_REQUEST_MESSAGE = "alva:udf:consent-request";
|
|
2437
2656
|
var UDF_CONSENT_RESPONSE_MESSAGE = "alva:udf:consent-response";
|
|
2438
2657
|
var UDF_AUTH_REQUIRED_MESSAGE = "alva:udf:auth-required";
|
|
2658
|
+
var SUBSCRIBE_PROPOSE_MESSAGE = "alva:subscribe:propose";
|
|
2659
|
+
var SUBSCRIBE_RESULT_MESSAGE = "alva:subscribe:result";
|
|
2439
2660
|
var DEFAULT_API_ORIGIN = "https://api-llm.prd.alva.ai";
|
|
2440
2661
|
var CONSENT_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
2441
2662
|
var cachedToken = null;
|
|
@@ -2445,6 +2666,13 @@ var playbookIdFromBoot = null;
|
|
|
2445
2666
|
var runtimeWindow = null;
|
|
2446
2667
|
var installed = false;
|
|
2447
2668
|
var pendingConsents = /* @__PURE__ */ new Map();
|
|
2669
|
+
var pendingProposals = /* @__PURE__ */ new Map();
|
|
2670
|
+
var normalizeProposalResult = (value) => {
|
|
2671
|
+
if (value === "subscribed" || value === "declined" || value === "timeout") {
|
|
2672
|
+
return value;
|
|
2673
|
+
}
|
|
2674
|
+
return "error";
|
|
2675
|
+
};
|
|
2448
2676
|
var decodeBase64Url = (value) => {
|
|
2449
2677
|
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
2450
2678
|
const padded = normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "=");
|
|
@@ -2492,7 +2720,7 @@ var safeJson = async (response) => {
|
|
|
2492
2720
|
return {};
|
|
2493
2721
|
}
|
|
2494
2722
|
};
|
|
2495
|
-
var
|
|
2723
|
+
var parseResultPayload2 = (result) => {
|
|
2496
2724
|
if (typeof result !== "string") return result;
|
|
2497
2725
|
try {
|
|
2498
2726
|
return JSON.parse(result);
|
|
@@ -2504,7 +2732,7 @@ var normalizeInvokeResponse = (body) => {
|
|
|
2504
2732
|
const envelope = body;
|
|
2505
2733
|
return {
|
|
2506
2734
|
...envelope,
|
|
2507
|
-
result:
|
|
2735
|
+
result: parseResultPayload2(envelope.result)
|
|
2508
2736
|
};
|
|
2509
2737
|
};
|
|
2510
2738
|
var errorMetadata = (body) => body.error?.metadata || body.details?.metadata || {};
|
|
@@ -2550,6 +2778,15 @@ var onMessage = (event) => {
|
|
|
2550
2778
|
}
|
|
2551
2779
|
return;
|
|
2552
2780
|
}
|
|
2781
|
+
if (data.type === SUBSCRIBE_RESULT_MESSAGE) {
|
|
2782
|
+
if (typeof data.request_id !== "string") return;
|
|
2783
|
+
const pending2 = pendingProposals.get(data.request_id);
|
|
2784
|
+
if (!pending2) return;
|
|
2785
|
+
clearTimeout(pending2.timer);
|
|
2786
|
+
pendingProposals.delete(data.request_id);
|
|
2787
|
+
pending2.resolve(normalizeProposalResult(data.status));
|
|
2788
|
+
return;
|
|
2789
|
+
}
|
|
2553
2790
|
if (data.type !== UDF_CONSENT_RESPONSE_MESSAGE) return;
|
|
2554
2791
|
if (typeof data.request_id !== "string") return;
|
|
2555
2792
|
const pending = pendingConsents.get(data.request_id);
|
|
@@ -2588,6 +2825,33 @@ var requestConsent = async (playbookId, minAllowance) => {
|
|
|
2588
2825
|
);
|
|
2589
2826
|
});
|
|
2590
2827
|
};
|
|
2828
|
+
var proposeSubscribe = async (input) => {
|
|
2829
|
+
if (!runtimeWindow || !expectedParentOrigin) return "error";
|
|
2830
|
+
const feedOwner = typeof input?.feedOwner === "string" ? input.feedOwner.trim() : "";
|
|
2831
|
+
const feedName = typeof input?.feedName === "string" ? input.feedName.trim() : "";
|
|
2832
|
+
if (!feedOwner || !feedName) return "error";
|
|
2833
|
+
const targetOrigin = expectedParentOrigin;
|
|
2834
|
+
const requestId = randomRequestId();
|
|
2835
|
+
return new Promise((resolve) => {
|
|
2836
|
+
const timer = setTimeout(() => {
|
|
2837
|
+
pendingProposals.delete(requestId);
|
|
2838
|
+
resolve("timeout");
|
|
2839
|
+
}, CONSENT_TIMEOUT_MS);
|
|
2840
|
+
pendingProposals.set(requestId, { resolve, timer });
|
|
2841
|
+
runtimeWindow?.parent.postMessage(
|
|
2842
|
+
{
|
|
2843
|
+
type: SUBSCRIBE_PROPOSE_MESSAGE,
|
|
2844
|
+
request_id: requestId,
|
|
2845
|
+
playbook_id: playbookIdFromBoot,
|
|
2846
|
+
feed: { owner: feedOwner, name: feedName }
|
|
2847
|
+
},
|
|
2848
|
+
targetOrigin
|
|
2849
|
+
);
|
|
2850
|
+
});
|
|
2851
|
+
};
|
|
2852
|
+
var subscribe = {
|
|
2853
|
+
propose: proposeSubscribe
|
|
2854
|
+
};
|
|
2591
2855
|
var requestAuthentication = (functionName) => {
|
|
2592
2856
|
if (!runtimeWindow || !expectedParentOrigin) return;
|
|
2593
2857
|
runtimeWindow.parent.postMessage(
|
|
@@ -2756,16 +3020,19 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
2756
3020
|
const existing = target.alva || {};
|
|
2757
3021
|
target.alva = {
|
|
2758
3022
|
...existing,
|
|
2759
|
-
udf
|
|
3023
|
+
udf,
|
|
3024
|
+
subscribe
|
|
2760
3025
|
};
|
|
2761
3026
|
};
|
|
2762
3027
|
|
|
2763
3028
|
// src/index.ts
|
|
2764
|
-
var VERSION = true ? "0.11.
|
|
3029
|
+
var VERSION = true ? "0.11.3-beta.0" : "dev";
|
|
2765
3030
|
export {
|
|
2766
3031
|
AlvaClient,
|
|
2767
3032
|
AlvaError,
|
|
2768
3033
|
PBSV_UPDATE_MESSAGE,
|
|
3034
|
+
SUBSCRIBE_PROPOSE_MESSAGE,
|
|
3035
|
+
SUBSCRIBE_RESULT_MESSAGE,
|
|
2769
3036
|
UDF_AUTH_REQUIRED_MESSAGE,
|
|
2770
3037
|
UDF_CONSENT_REQUEST_MESSAGE,
|
|
2771
3038
|
UDF_CONSENT_RESPONSE_MESSAGE,
|
|
@@ -2788,6 +3055,7 @@ export {
|
|
|
2788
3055
|
installPlaybookRuntime,
|
|
2789
3056
|
mapUdfErrorResponse,
|
|
2790
3057
|
playbookIdFromToken,
|
|
3058
|
+
subscribe,
|
|
2791
3059
|
udf
|
|
2792
3060
|
};
|
|
2793
3061
|
//# sourceMappingURL=index.js.map
|