@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/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);
@@ -353,6 +356,33 @@ var FeedResource = class {
353
356
  this.client = client;
354
357
  }
355
358
  client;
359
+ /**
360
+ * Stop a feed's producer cronjob. This pauses future scheduled runs while
361
+ * preserving the feed and its existing data.
362
+ *
363
+ * Auth: caller must own the feed (uid match), enforced by the backend.
364
+ */
365
+ async stop(params) {
366
+ this.client._requireAuth();
367
+ const id = requireFeedID(params.id);
368
+ return this.client._request(
369
+ "POST",
370
+ `/api/v1/feed/${encodeURIComponent(String(id))}/stop`
371
+ );
372
+ }
373
+ /**
374
+ * Resume a stopped feed's producer cronjob.
375
+ *
376
+ * Auth: caller must own the feed (uid match), enforced by the backend.
377
+ */
378
+ async resume(params) {
379
+ this.client._requireAuth();
380
+ const id = requireFeedID(params.id);
381
+ return this.client._request(
382
+ "POST",
383
+ `/api/v1/feed/${encodeURIComponent(String(id))}/resume`
384
+ );
385
+ }
356
386
  /**
357
387
  * Soft-delete a feed and all its active majors. Cascades:
358
388
  * - all active feed_majors are soft-deleted in the same transaction
@@ -363,15 +393,19 @@ var FeedResource = class {
363
393
  */
364
394
  async delete(params) {
365
395
  this.client._requireAuth();
366
- if (!Number.isInteger(params.id) || params.id <= 0) {
367
- throw new Error("feed id must be a positive integer");
368
- }
396
+ const id = requireFeedID(params.id);
369
397
  return this.client._request(
370
398
  "DELETE",
371
- `/api/v1/feed/${encodeURIComponent(String(params.id))}`
399
+ `/api/v1/feed/${encodeURIComponent(String(id))}`
372
400
  );
373
401
  }
374
402
  };
403
+ function requireFeedID(id) {
404
+ if (!Number.isInteger(id) || id <= 0) {
405
+ throw new Error("feed id must be a positive integer");
406
+ }
407
+ return id;
408
+ }
375
409
 
376
410
  // src/resources/playbooks.ts
377
411
  var PLAYBOOK_VISIBILITIES = [
@@ -1608,6 +1642,36 @@ var SKILL_ENDPOINT_METADATA = [
1608
1642
  required_subscription_tier: "pro",
1609
1643
  access: "pro_only",
1610
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
1611
1675
  }
1612
1676
  ];
1613
1677
  function getSkillEndpointMetadata(skill, file) {
@@ -2218,6 +2282,160 @@ var FeedbackResource = class {
2218
2282
  }
2219
2283
  };
2220
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
+
2221
2439
  // src/client.ts
2222
2440
  var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
2223
2441
  var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
@@ -2252,6 +2470,7 @@ var AlvaClient = class {
2252
2470
  _subscriptions;
2253
2471
  _channelGroupSubscriptions;
2254
2472
  _feedback;
2473
+ _functions;
2255
2474
  constructor(config) {
2256
2475
  this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
2257
2476
  this.arraysBaseUrl = config.arraysBaseUrl ?? DEFAULT_ARRAYS_BASE_URL;
@@ -2328,6 +2547,9 @@ var AlvaClient = class {
2328
2547
  get feedback() {
2329
2548
  return this._feedback ??= new FeedbackResource(this);
2330
2549
  }
2550
+ get functions() {
2551
+ return this._functions ??= new FunctionsResource(this);
2552
+ }
2331
2553
  _requireAuth() {
2332
2554
  if (!this.pbsvToken && !this.viewer_token && !this.apiKey) {
2333
2555
  throw new AlvaError(
@@ -2487,6 +2709,8 @@ var PBSV_UPDATE_MESSAGE = "alva:pbsv:update";
2487
2709
  var UDF_CONSENT_REQUEST_MESSAGE = "alva:udf:consent-request";
2488
2710
  var UDF_CONSENT_RESPONSE_MESSAGE = "alva:udf:consent-response";
2489
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";
2490
2714
  var DEFAULT_API_ORIGIN = "https://api-llm.prd.alva.ai";
2491
2715
  var CONSENT_TIMEOUT_MS = 5 * 60 * 1e3;
2492
2716
  var cachedToken = null;
@@ -2496,6 +2720,13 @@ var playbookIdFromBoot = null;
2496
2720
  var runtimeWindow = null;
2497
2721
  var installed = false;
2498
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
+ };
2499
2730
  var decodeBase64Url = (value) => {
2500
2731
  const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
2501
2732
  const padded = normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "=");
@@ -2543,7 +2774,7 @@ var safeJson = async (response) => {
2543
2774
  return {};
2544
2775
  }
2545
2776
  };
2546
- var parseResultPayload = (result) => {
2777
+ var parseResultPayload2 = (result) => {
2547
2778
  if (typeof result !== "string") return result;
2548
2779
  try {
2549
2780
  return JSON.parse(result);
@@ -2555,7 +2786,7 @@ var normalizeInvokeResponse = (body) => {
2555
2786
  const envelope = body;
2556
2787
  return {
2557
2788
  ...envelope,
2558
- result: parseResultPayload(envelope.result)
2789
+ result: parseResultPayload2(envelope.result)
2559
2790
  };
2560
2791
  };
2561
2792
  var errorMetadata = (body) => body.error?.metadata || body.details?.metadata || {};
@@ -2601,6 +2832,15 @@ var onMessage = (event) => {
2601
2832
  }
2602
2833
  return;
2603
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
+ }
2604
2844
  if (data.type !== UDF_CONSENT_RESPONSE_MESSAGE) return;
2605
2845
  if (typeof data.request_id !== "string") return;
2606
2846
  const pending = pendingConsents.get(data.request_id);
@@ -2639,6 +2879,33 @@ var requestConsent = async (playbookId, minAllowance) => {
2639
2879
  );
2640
2880
  });
2641
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
+ };
2642
2909
  var requestAuthentication = (functionName) => {
2643
2910
  if (!runtimeWindow || !expectedParentOrigin) return;
2644
2911
  runtimeWindow.parent.postMessage(
@@ -2807,17 +3074,20 @@ var installPlaybookRuntime = (targetWindow) => {
2807
3074
  const existing = target.alva || {};
2808
3075
  target.alva = {
2809
3076
  ...existing,
2810
- udf
3077
+ udf,
3078
+ subscribe
2811
3079
  };
2812
3080
  };
2813
3081
 
2814
3082
  // src/index.ts
2815
- var VERSION = true ? "0.11.2-beta.0" : "dev";
3083
+ var VERSION = true ? "0.11.3-beta.0" : "dev";
2816
3084
  // Annotate the CommonJS export names for ESM import in node:
2817
3085
  0 && (module.exports = {
2818
3086
  AlvaClient,
2819
3087
  AlvaError,
2820
3088
  PBSV_UPDATE_MESSAGE,
3089
+ SUBSCRIBE_PROPOSE_MESSAGE,
3090
+ SUBSCRIBE_RESULT_MESSAGE,
2821
3091
  UDF_AUTH_REQUIRED_MESSAGE,
2822
3092
  UDF_CONSENT_REQUEST_MESSAGE,
2823
3093
  UDF_CONSENT_RESPONSE_MESSAGE,
@@ -2840,6 +3110,7 @@ var VERSION = true ? "0.11.2-beta.0" : "dev";
2840
3110
  installPlaybookRuntime,
2841
3111
  mapUdfErrorResponse,
2842
3112
  playbookIdFromToken,
3113
+ subscribe,
2843
3114
  udf
2844
3115
  });
2845
3116
  //# sourceMappingURL=index.cjs.map