@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/dist/index.d.cts CHANGED
@@ -13,6 +13,7 @@ interface UserProfile {
13
13
  username: string;
14
14
  subscription_tier: 'free' | 'pro';
15
15
  telegram_username: string | null;
16
+ slack_username: string | null;
16
17
  /** Caller's alfs home directory, e.g. `/alva/home/<username>`. */
17
18
  home_path: string;
18
19
  }
@@ -1229,6 +1230,95 @@ declare class FeedbackResource {
1229
1230
  submit(params: SubmitFeedbackRequest): Promise<SubmitFeedbackResponse>;
1230
1231
  }
1231
1232
 
1233
+ interface PlaybookFunction {
1234
+ id: string | number;
1235
+ playbook_id: string | number;
1236
+ function_name: string;
1237
+ entry_script_path: string;
1238
+ created_at?: string;
1239
+ updated_at?: string;
1240
+ disabled?: boolean;
1241
+ params_schema?: string;
1242
+ allow_charges?: boolean;
1243
+ }
1244
+ interface RegisterFunctionParams {
1245
+ playbook_id: number;
1246
+ function_name: string;
1247
+ entry_script_path: string;
1248
+ params_schema?: string;
1249
+ allow_charges?: boolean;
1250
+ }
1251
+ interface RegisterFunctionResponse {
1252
+ function?: PlaybookFunction;
1253
+ }
1254
+ interface ListFunctionsParams {
1255
+ playbook_id: number;
1256
+ }
1257
+ interface ListFunctionsResponse {
1258
+ functions: PlaybookFunction[];
1259
+ }
1260
+ interface DeleteFunctionParams {
1261
+ playbook_id: number;
1262
+ function_name: string;
1263
+ }
1264
+ interface InvokeFunctionParams {
1265
+ playbook_id: number;
1266
+ function_name: string;
1267
+ parameters?: unknown;
1268
+ }
1269
+ interface InvokeFunctionResponse<TResult = unknown> {
1270
+ result: TResult;
1271
+ logs: string;
1272
+ credits_used_total: number;
1273
+ credits_charged_owner: number;
1274
+ credits_charged_consumer: number;
1275
+ }
1276
+ interface CreditAllowance {
1277
+ id: string | number;
1278
+ consumer_uid: string | number;
1279
+ playbook_id: string | number;
1280
+ amount: number;
1281
+ used: number;
1282
+ remaining: number;
1283
+ created_at_ms?: number;
1284
+ updated_at_ms?: number;
1285
+ }
1286
+ interface GetAllowanceParams {
1287
+ playbook_id: number;
1288
+ }
1289
+ interface ListAllowancesResponse {
1290
+ allowances: CreditAllowance[];
1291
+ }
1292
+ interface CreateAllowanceParams {
1293
+ playbook_id: number;
1294
+ amount: number;
1295
+ }
1296
+ interface CreateAllowanceResponse {
1297
+ allowance: CreditAllowance;
1298
+ }
1299
+ interface RevokeAllowanceParams {
1300
+ playbook_id: number;
1301
+ }
1302
+ interface RevokeAllowanceResponse {
1303
+ ok: boolean;
1304
+ }
1305
+ /**
1306
+ * Playbook function management. These functions are registered by a playbook
1307
+ * creator and invoked by released playbook UI through the browser UDF runtime.
1308
+ */
1309
+ declare class FunctionsResource {
1310
+ private client;
1311
+ constructor(client: AlvaClient);
1312
+ register(params: RegisterFunctionParams): Promise<RegisterFunctionResponse>;
1313
+ list(params: ListFunctionsParams): Promise<ListFunctionsResponse>;
1314
+ delete(params: DeleteFunctionParams): Promise<void>;
1315
+ invoke<TResult = unknown>(params: InvokeFunctionParams): Promise<InvokeFunctionResponse<TResult>>;
1316
+ getAllowance(params: GetAllowanceParams): Promise<CreditAllowance | null>;
1317
+ listAllowances(): Promise<ListAllowancesResponse>;
1318
+ createAllowance(params: CreateAllowanceParams): Promise<CreateAllowanceResponse>;
1319
+ revokeAllowance(params: RevokeAllowanceParams): Promise<RevokeAllowanceResponse>;
1320
+ }
1321
+
1232
1322
  interface RequestOptions {
1233
1323
  query?: Record<string, unknown>;
1234
1324
  body?: unknown;
@@ -1272,6 +1362,7 @@ declare class AlvaClient {
1272
1362
  private _subscriptions?;
1273
1363
  private _channelGroupSubscriptions?;
1274
1364
  private _feedback?;
1365
+ private _functions?;
1275
1366
  constructor(config: AlvaClientConfig);
1276
1367
  get fs(): FsResource;
1277
1368
  get run(): RunResource;
@@ -1295,6 +1386,7 @@ declare class AlvaClient {
1295
1386
  get subscriptions(): SubscriptionsResource;
1296
1387
  get channelGroupSubscriptions(): ChannelGroupSubscriptionsResource;
1297
1388
  get feedback(): FeedbackResource;
1389
+ get functions(): FunctionsResource;
1298
1390
  _requireAuth(): void;
1299
1391
  _request(method: string, path: string, options?: RequestOptions): Promise<unknown>;
1300
1392
  }
@@ -1316,6 +1408,20 @@ type UdfErrorBody = {
1316
1408
  metadata?: Record<string, unknown>;
1317
1409
  };
1318
1410
  };
1411
+ type SubscribeProposalResult = 'subscribed' | 'declined' | 'timeout' | 'error';
1412
+ type SubscribeProposalInput = {
1413
+ feedOwner: string;
1414
+ feedName: string;
1415
+ };
1416
+ type SubscribeApi = {
1417
+ /**
1418
+ * Ask the parent (main site) to offer the viewer a subscription to a feed.
1419
+ * The iframe CANNOT subscribe directly — it only proposes; the trusted
1420
+ * parent shows a confirm prompt and, on user confirmation, subscribes with
1421
+ * the viewer's own session. Resolves with the outcome.
1422
+ */
1423
+ propose: (input: SubscribeProposalInput) => Promise<SubscribeProposalResult>;
1424
+ };
1319
1425
  type UdfDescriptor = {
1320
1426
  name: string;
1321
1427
  params_schema: unknown | null;
@@ -1364,6 +1470,7 @@ declare global {
1364
1470
  interface Window {
1365
1471
  alva?: {
1366
1472
  udf?: UdfApi;
1473
+ subscribe?: SubscribeApi;
1367
1474
  [key: string]: unknown;
1368
1475
  };
1369
1476
  }
@@ -1411,13 +1518,16 @@ declare const PBSV_UPDATE_MESSAGE = "alva:pbsv:update";
1411
1518
  declare const UDF_CONSENT_REQUEST_MESSAGE = "alva:udf:consent-request";
1412
1519
  declare const UDF_CONSENT_RESPONSE_MESSAGE = "alva:udf:consent-response";
1413
1520
  declare const UDF_AUTH_REQUIRED_MESSAGE = "alva:udf:auth-required";
1521
+ declare const SUBSCRIBE_PROPOSE_MESSAGE = "alva:subscribe:propose";
1522
+ declare const SUBSCRIBE_RESULT_MESSAGE = "alva:subscribe:result";
1414
1523
  declare const playbookIdFromToken: (token: string | null) => string | null;
1415
1524
  declare const getViewerToken: () => string | null;
1416
1525
  declare const mapUdfErrorResponse: (body: UdfErrorBody, status?: number) => UdfError;
1526
+ declare const subscribe: SubscribeApi;
1417
1527
  declare const udf: UdfApi;
1418
1528
  declare const installPlaybookRuntime: (targetWindow?: Window) => void;
1419
1529
 
1420
1530
  /** SDK version, injected at build time from package.json. */
1421
1531
  declare const VERSION: string;
1422
1532
 
1423
- export { AlvaClient, type AlvaClientConfig, AlvaError, type ChannelGroupAdminInfo, type ChannelGroupCallerInfo, type ChannelGroupSubscription, type ChannelGroupSubscriptionContextResponse, type ChannelGroupSubscriptionListResponse, type ChannelGroupSubscriptionMutationParams, type ChannelGroupSubscriptionMutationResponse, type ChannelGroupSubscriptionSessionParams, type ChannelGroupSubscriptionTarget, type ChannelGroupSubscriptionTargetType, type FeedDeleteRequest, type FeedDeleteResponse, type FeedStatusUpdateRequest, type FeedStatusUpdateResponse, type FsChmodParams, type FsCopyParams, type FsEntry, type FsGrantParams, type FsMkdirParams, type FsRawWriteParams, type FsReadParams, type FsReaddirParams, type FsReaddirResponse, type FsReadlinkParams, type FsRemoveParams, type FsRenameParams, type FsRevokeParams, type FsStat, type FsSymlinkParams, type FsWriteParams, type FsWriteResponse, type NotificationPreference, type NotificationPreferenceKey, type NotificationPreferenceUpdateParams, type NotificationPreferenceUpdateResponse, type NotificationPreferencesResponse, PBSV_UPDATE_MESSAGE, type PlaybookSkillFile, type PlaybookSkillFileMeta, type PlaybookSkillMeta, type PlaybookSkillSummary, type PlaybookSkillTagEntry, type SkillDoc, type SkillEndpointMetadata, type SkillEndpointTier, type SkillMetadata, type SkillSummary, type SubmitFeedbackRequest, type SubmitFeedbackResponse, type TrendingPlaybookItem, type TrendingPlaybooksDir, type TrendingPlaybooksParams, type TrendingPlaybooksResponse, type TrendingPlaybooksSort, UDF_AUTH_REQUIRED_MESSAGE, UDF_CONSENT_REQUEST_MESSAGE, UDF_CONSENT_RESPONSE_MESSAGE, type UdfApi, UdfAuthRequiredError, type UdfButtonEventDetail, type UdfButtonOptions, UdfConsentDeniedError, UdfConsentRequiredError, UdfConsentTimeoutError, type UdfDescriptor, UdfError, UdfExecutionError, UdfFunctionDisabledError, UdfFunctionNotFoundError, UdfInsufficientCredits, type UdfInvokeResponse, UdfPidMismatchError, UdfRateLimitedError, UdfTokenExpiredError, UdfTokenInvalidError, UdfTransportError, VERSION, getViewerToken, installPlaybookRuntime, mapUdfErrorResponse, playbookIdFromToken, udf };
1533
+ export { AlvaClient, type AlvaClientConfig, AlvaError, type ChannelGroupAdminInfo, type ChannelGroupCallerInfo, type ChannelGroupSubscription, type ChannelGroupSubscriptionContextResponse, type ChannelGroupSubscriptionListResponse, type ChannelGroupSubscriptionMutationParams, type ChannelGroupSubscriptionMutationResponse, type ChannelGroupSubscriptionSessionParams, type ChannelGroupSubscriptionTarget, type ChannelGroupSubscriptionTargetType, type CreateAllowanceParams, type CreateAllowanceResponse, type CreditAllowance, type DeleteFunctionParams, type FeedDeleteRequest, type FeedDeleteResponse, type FeedStatusUpdateRequest, type FeedStatusUpdateResponse, type FsChmodParams, type FsCopyParams, type FsEntry, type FsGrantParams, type FsMkdirParams, type FsRawWriteParams, type FsReadParams, type FsReaddirParams, type FsReaddirResponse, type FsReadlinkParams, type FsRemoveParams, type FsRenameParams, type FsRevokeParams, type FsStat, type FsSymlinkParams, type FsWriteParams, type FsWriteResponse, type GetAllowanceParams, type InvokeFunctionParams, type InvokeFunctionResponse, type ListAllowancesResponse, type ListFunctionsParams, type ListFunctionsResponse, type NotificationPreference, type NotificationPreferenceKey, type NotificationPreferenceUpdateParams, type NotificationPreferenceUpdateResponse, type NotificationPreferencesResponse, PBSV_UPDATE_MESSAGE, type PlaybookFunction, type PlaybookSkillFile, type PlaybookSkillFileMeta, type PlaybookSkillMeta, type PlaybookSkillSummary, type PlaybookSkillTagEntry, type RegisterFunctionParams, type RegisterFunctionResponse, type RevokeAllowanceParams, type RevokeAllowanceResponse, SUBSCRIBE_PROPOSE_MESSAGE, SUBSCRIBE_RESULT_MESSAGE, type SkillDoc, type SkillEndpointMetadata, type SkillEndpointTier, type SkillMetadata, type SkillSummary, type SubmitFeedbackRequest, type SubmitFeedbackResponse, type SubscribeApi, type SubscribeProposalInput, type SubscribeProposalResult, type TrendingPlaybookItem, type TrendingPlaybooksDir, type TrendingPlaybooksParams, type TrendingPlaybooksResponse, type TrendingPlaybooksSort, UDF_AUTH_REQUIRED_MESSAGE, UDF_CONSENT_REQUEST_MESSAGE, UDF_CONSENT_RESPONSE_MESSAGE, type UdfApi, UdfAuthRequiredError, type UdfButtonEventDetail, type UdfButtonOptions, UdfConsentDeniedError, UdfConsentRequiredError, UdfConsentTimeoutError, type UdfDescriptor, UdfError, UdfExecutionError, UdfFunctionDisabledError, UdfFunctionNotFoundError, UdfInsufficientCredits, type UdfInvokeResponse, UdfPidMismatchError, UdfRateLimitedError, UdfTokenExpiredError, UdfTokenInvalidError, UdfTransportError, VERSION, getViewerToken, installPlaybookRuntime, mapUdfErrorResponse, playbookIdFromToken, subscribe, udf };
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ interface UserProfile {
13
13
  username: string;
14
14
  subscription_tier: 'free' | 'pro';
15
15
  telegram_username: string | null;
16
+ slack_username: string | null;
16
17
  /** Caller's alfs home directory, e.g. `/alva/home/<username>`. */
17
18
  home_path: string;
18
19
  }
@@ -1229,6 +1230,95 @@ declare class FeedbackResource {
1229
1230
  submit(params: SubmitFeedbackRequest): Promise<SubmitFeedbackResponse>;
1230
1231
  }
1231
1232
 
1233
+ interface PlaybookFunction {
1234
+ id: string | number;
1235
+ playbook_id: string | number;
1236
+ function_name: string;
1237
+ entry_script_path: string;
1238
+ created_at?: string;
1239
+ updated_at?: string;
1240
+ disabled?: boolean;
1241
+ params_schema?: string;
1242
+ allow_charges?: boolean;
1243
+ }
1244
+ interface RegisterFunctionParams {
1245
+ playbook_id: number;
1246
+ function_name: string;
1247
+ entry_script_path: string;
1248
+ params_schema?: string;
1249
+ allow_charges?: boolean;
1250
+ }
1251
+ interface RegisterFunctionResponse {
1252
+ function?: PlaybookFunction;
1253
+ }
1254
+ interface ListFunctionsParams {
1255
+ playbook_id: number;
1256
+ }
1257
+ interface ListFunctionsResponse {
1258
+ functions: PlaybookFunction[];
1259
+ }
1260
+ interface DeleteFunctionParams {
1261
+ playbook_id: number;
1262
+ function_name: string;
1263
+ }
1264
+ interface InvokeFunctionParams {
1265
+ playbook_id: number;
1266
+ function_name: string;
1267
+ parameters?: unknown;
1268
+ }
1269
+ interface InvokeFunctionResponse<TResult = unknown> {
1270
+ result: TResult;
1271
+ logs: string;
1272
+ credits_used_total: number;
1273
+ credits_charged_owner: number;
1274
+ credits_charged_consumer: number;
1275
+ }
1276
+ interface CreditAllowance {
1277
+ id: string | number;
1278
+ consumer_uid: string | number;
1279
+ playbook_id: string | number;
1280
+ amount: number;
1281
+ used: number;
1282
+ remaining: number;
1283
+ created_at_ms?: number;
1284
+ updated_at_ms?: number;
1285
+ }
1286
+ interface GetAllowanceParams {
1287
+ playbook_id: number;
1288
+ }
1289
+ interface ListAllowancesResponse {
1290
+ allowances: CreditAllowance[];
1291
+ }
1292
+ interface CreateAllowanceParams {
1293
+ playbook_id: number;
1294
+ amount: number;
1295
+ }
1296
+ interface CreateAllowanceResponse {
1297
+ allowance: CreditAllowance;
1298
+ }
1299
+ interface RevokeAllowanceParams {
1300
+ playbook_id: number;
1301
+ }
1302
+ interface RevokeAllowanceResponse {
1303
+ ok: boolean;
1304
+ }
1305
+ /**
1306
+ * Playbook function management. These functions are registered by a playbook
1307
+ * creator and invoked by released playbook UI through the browser UDF runtime.
1308
+ */
1309
+ declare class FunctionsResource {
1310
+ private client;
1311
+ constructor(client: AlvaClient);
1312
+ register(params: RegisterFunctionParams): Promise<RegisterFunctionResponse>;
1313
+ list(params: ListFunctionsParams): Promise<ListFunctionsResponse>;
1314
+ delete(params: DeleteFunctionParams): Promise<void>;
1315
+ invoke<TResult = unknown>(params: InvokeFunctionParams): Promise<InvokeFunctionResponse<TResult>>;
1316
+ getAllowance(params: GetAllowanceParams): Promise<CreditAllowance | null>;
1317
+ listAllowances(): Promise<ListAllowancesResponse>;
1318
+ createAllowance(params: CreateAllowanceParams): Promise<CreateAllowanceResponse>;
1319
+ revokeAllowance(params: RevokeAllowanceParams): Promise<RevokeAllowanceResponse>;
1320
+ }
1321
+
1232
1322
  interface RequestOptions {
1233
1323
  query?: Record<string, unknown>;
1234
1324
  body?: unknown;
@@ -1272,6 +1362,7 @@ declare class AlvaClient {
1272
1362
  private _subscriptions?;
1273
1363
  private _channelGroupSubscriptions?;
1274
1364
  private _feedback?;
1365
+ private _functions?;
1275
1366
  constructor(config: AlvaClientConfig);
1276
1367
  get fs(): FsResource;
1277
1368
  get run(): RunResource;
@@ -1295,6 +1386,7 @@ declare class AlvaClient {
1295
1386
  get subscriptions(): SubscriptionsResource;
1296
1387
  get channelGroupSubscriptions(): ChannelGroupSubscriptionsResource;
1297
1388
  get feedback(): FeedbackResource;
1389
+ get functions(): FunctionsResource;
1298
1390
  _requireAuth(): void;
1299
1391
  _request(method: string, path: string, options?: RequestOptions): Promise<unknown>;
1300
1392
  }
@@ -1316,6 +1408,20 @@ type UdfErrorBody = {
1316
1408
  metadata?: Record<string, unknown>;
1317
1409
  };
1318
1410
  };
1411
+ type SubscribeProposalResult = 'subscribed' | 'declined' | 'timeout' | 'error';
1412
+ type SubscribeProposalInput = {
1413
+ feedOwner: string;
1414
+ feedName: string;
1415
+ };
1416
+ type SubscribeApi = {
1417
+ /**
1418
+ * Ask the parent (main site) to offer the viewer a subscription to a feed.
1419
+ * The iframe CANNOT subscribe directly — it only proposes; the trusted
1420
+ * parent shows a confirm prompt and, on user confirmation, subscribes with
1421
+ * the viewer's own session. Resolves with the outcome.
1422
+ */
1423
+ propose: (input: SubscribeProposalInput) => Promise<SubscribeProposalResult>;
1424
+ };
1319
1425
  type UdfDescriptor = {
1320
1426
  name: string;
1321
1427
  params_schema: unknown | null;
@@ -1364,6 +1470,7 @@ declare global {
1364
1470
  interface Window {
1365
1471
  alva?: {
1366
1472
  udf?: UdfApi;
1473
+ subscribe?: SubscribeApi;
1367
1474
  [key: string]: unknown;
1368
1475
  };
1369
1476
  }
@@ -1411,13 +1518,16 @@ declare const PBSV_UPDATE_MESSAGE = "alva:pbsv:update";
1411
1518
  declare const UDF_CONSENT_REQUEST_MESSAGE = "alva:udf:consent-request";
1412
1519
  declare const UDF_CONSENT_RESPONSE_MESSAGE = "alva:udf:consent-response";
1413
1520
  declare const UDF_AUTH_REQUIRED_MESSAGE = "alva:udf:auth-required";
1521
+ declare const SUBSCRIBE_PROPOSE_MESSAGE = "alva:subscribe:propose";
1522
+ declare const SUBSCRIBE_RESULT_MESSAGE = "alva:subscribe:result";
1414
1523
  declare const playbookIdFromToken: (token: string | null) => string | null;
1415
1524
  declare const getViewerToken: () => string | null;
1416
1525
  declare const mapUdfErrorResponse: (body: UdfErrorBody, status?: number) => UdfError;
1526
+ declare const subscribe: SubscribeApi;
1417
1527
  declare const udf: UdfApi;
1418
1528
  declare const installPlaybookRuntime: (targetWindow?: Window) => void;
1419
1529
 
1420
1530
  /** SDK version, injected at build time from package.json. */
1421
1531
  declare const VERSION: string;
1422
1532
 
1423
- export { AlvaClient, type AlvaClientConfig, AlvaError, type ChannelGroupAdminInfo, type ChannelGroupCallerInfo, type ChannelGroupSubscription, type ChannelGroupSubscriptionContextResponse, type ChannelGroupSubscriptionListResponse, type ChannelGroupSubscriptionMutationParams, type ChannelGroupSubscriptionMutationResponse, type ChannelGroupSubscriptionSessionParams, type ChannelGroupSubscriptionTarget, type ChannelGroupSubscriptionTargetType, type FeedDeleteRequest, type FeedDeleteResponse, type FeedStatusUpdateRequest, type FeedStatusUpdateResponse, type FsChmodParams, type FsCopyParams, type FsEntry, type FsGrantParams, type FsMkdirParams, type FsRawWriteParams, type FsReadParams, type FsReaddirParams, type FsReaddirResponse, type FsReadlinkParams, type FsRemoveParams, type FsRenameParams, type FsRevokeParams, type FsStat, type FsSymlinkParams, type FsWriteParams, type FsWriteResponse, type NotificationPreference, type NotificationPreferenceKey, type NotificationPreferenceUpdateParams, type NotificationPreferenceUpdateResponse, type NotificationPreferencesResponse, PBSV_UPDATE_MESSAGE, type PlaybookSkillFile, type PlaybookSkillFileMeta, type PlaybookSkillMeta, type PlaybookSkillSummary, type PlaybookSkillTagEntry, type SkillDoc, type SkillEndpointMetadata, type SkillEndpointTier, type SkillMetadata, type SkillSummary, type SubmitFeedbackRequest, type SubmitFeedbackResponse, type TrendingPlaybookItem, type TrendingPlaybooksDir, type TrendingPlaybooksParams, type TrendingPlaybooksResponse, type TrendingPlaybooksSort, UDF_AUTH_REQUIRED_MESSAGE, UDF_CONSENT_REQUEST_MESSAGE, UDF_CONSENT_RESPONSE_MESSAGE, type UdfApi, UdfAuthRequiredError, type UdfButtonEventDetail, type UdfButtonOptions, UdfConsentDeniedError, UdfConsentRequiredError, UdfConsentTimeoutError, type UdfDescriptor, UdfError, UdfExecutionError, UdfFunctionDisabledError, UdfFunctionNotFoundError, UdfInsufficientCredits, type UdfInvokeResponse, UdfPidMismatchError, UdfRateLimitedError, UdfTokenExpiredError, UdfTokenInvalidError, UdfTransportError, VERSION, getViewerToken, installPlaybookRuntime, mapUdfErrorResponse, playbookIdFromToken, udf };
1533
+ export { AlvaClient, type AlvaClientConfig, AlvaError, type ChannelGroupAdminInfo, type ChannelGroupCallerInfo, type ChannelGroupSubscription, type ChannelGroupSubscriptionContextResponse, type ChannelGroupSubscriptionListResponse, type ChannelGroupSubscriptionMutationParams, type ChannelGroupSubscriptionMutationResponse, type ChannelGroupSubscriptionSessionParams, type ChannelGroupSubscriptionTarget, type ChannelGroupSubscriptionTargetType, type CreateAllowanceParams, type CreateAllowanceResponse, type CreditAllowance, type DeleteFunctionParams, type FeedDeleteRequest, type FeedDeleteResponse, type FeedStatusUpdateRequest, type FeedStatusUpdateResponse, type FsChmodParams, type FsCopyParams, type FsEntry, type FsGrantParams, type FsMkdirParams, type FsRawWriteParams, type FsReadParams, type FsReaddirParams, type FsReaddirResponse, type FsReadlinkParams, type FsRemoveParams, type FsRenameParams, type FsRevokeParams, type FsStat, type FsSymlinkParams, type FsWriteParams, type FsWriteResponse, type GetAllowanceParams, type InvokeFunctionParams, type InvokeFunctionResponse, type ListAllowancesResponse, type ListFunctionsParams, type ListFunctionsResponse, type NotificationPreference, type NotificationPreferenceKey, type NotificationPreferenceUpdateParams, type NotificationPreferenceUpdateResponse, type NotificationPreferencesResponse, PBSV_UPDATE_MESSAGE, type PlaybookFunction, type PlaybookSkillFile, type PlaybookSkillFileMeta, type PlaybookSkillMeta, type PlaybookSkillSummary, type PlaybookSkillTagEntry, type RegisterFunctionParams, type RegisterFunctionResponse, type RevokeAllowanceParams, type RevokeAllowanceResponse, SUBSCRIBE_PROPOSE_MESSAGE, SUBSCRIBE_RESULT_MESSAGE, type SkillDoc, type SkillEndpointMetadata, type SkillEndpointTier, type SkillMetadata, type SkillSummary, type SubmitFeedbackRequest, type SubmitFeedbackResponse, type SubscribeApi, type SubscribeProposalInput, type SubscribeProposalResult, type TrendingPlaybookItem, type TrendingPlaybooksDir, type TrendingPlaybooksParams, type TrendingPlaybooksResponse, type TrendingPlaybooksSort, UDF_AUTH_REQUIRED_MESSAGE, UDF_CONSENT_REQUEST_MESSAGE, UDF_CONSENT_RESPONSE_MESSAGE, type UdfApi, UdfAuthRequiredError, type UdfButtonEventDetail, type UdfButtonOptions, UdfConsentDeniedError, UdfConsentRequiredError, UdfConsentTimeoutError, type UdfDescriptor, UdfError, UdfExecutionError, UdfFunctionDisabledError, UdfFunctionNotFoundError, UdfInsufficientCredits, type UdfInvokeResponse, UdfPidMismatchError, UdfRateLimitedError, UdfTokenExpiredError, UdfTokenInvalidError, UdfTransportError, VERSION, getViewerToken, installPlaybookRuntime, mapUdfErrorResponse, playbookIdFromToken, subscribe, udf };
package/dist/index.js CHANGED
@@ -1588,6 +1588,36 @@ var SKILL_ENDPOINT_METADATA = [
1588
1588
  required_subscription_tier: "pro",
1589
1589
  access: "pro_only",
1590
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
1591
1621
  }
1592
1622
  ];
1593
1623
  function getSkillEndpointMetadata(skill, file) {
@@ -2198,6 +2228,160 @@ var FeedbackResource = class {
2198
2228
  }
2199
2229
  };
2200
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
+
2201
2385
  // src/client.ts
2202
2386
  var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
2203
2387
  var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
@@ -2232,6 +2416,7 @@ var AlvaClient = class {
2232
2416
  _subscriptions;
2233
2417
  _channelGroupSubscriptions;
2234
2418
  _feedback;
2419
+ _functions;
2235
2420
  constructor(config) {
2236
2421
  this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
2237
2422
  this.arraysBaseUrl = config.arraysBaseUrl ?? DEFAULT_ARRAYS_BASE_URL;
@@ -2308,6 +2493,9 @@ var AlvaClient = class {
2308
2493
  get feedback() {
2309
2494
  return this._feedback ??= new FeedbackResource(this);
2310
2495
  }
2496
+ get functions() {
2497
+ return this._functions ??= new FunctionsResource(this);
2498
+ }
2311
2499
  _requireAuth() {
2312
2500
  if (!this.pbsvToken && !this.viewer_token && !this.apiKey) {
2313
2501
  throw new AlvaError(
@@ -2467,6 +2655,8 @@ var PBSV_UPDATE_MESSAGE = "alva:pbsv:update";
2467
2655
  var UDF_CONSENT_REQUEST_MESSAGE = "alva:udf:consent-request";
2468
2656
  var UDF_CONSENT_RESPONSE_MESSAGE = "alva:udf:consent-response";
2469
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";
2470
2660
  var DEFAULT_API_ORIGIN = "https://api-llm.prd.alva.ai";
2471
2661
  var CONSENT_TIMEOUT_MS = 5 * 60 * 1e3;
2472
2662
  var cachedToken = null;
@@ -2476,6 +2666,13 @@ var playbookIdFromBoot = null;
2476
2666
  var runtimeWindow = null;
2477
2667
  var installed = false;
2478
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
+ };
2479
2676
  var decodeBase64Url = (value) => {
2480
2677
  const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
2481
2678
  const padded = normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "=");
@@ -2523,7 +2720,7 @@ var safeJson = async (response) => {
2523
2720
  return {};
2524
2721
  }
2525
2722
  };
2526
- var parseResultPayload = (result) => {
2723
+ var parseResultPayload2 = (result) => {
2527
2724
  if (typeof result !== "string") return result;
2528
2725
  try {
2529
2726
  return JSON.parse(result);
@@ -2535,7 +2732,7 @@ var normalizeInvokeResponse = (body) => {
2535
2732
  const envelope = body;
2536
2733
  return {
2537
2734
  ...envelope,
2538
- result: parseResultPayload(envelope.result)
2735
+ result: parseResultPayload2(envelope.result)
2539
2736
  };
2540
2737
  };
2541
2738
  var errorMetadata = (body) => body.error?.metadata || body.details?.metadata || {};
@@ -2581,6 +2778,15 @@ var onMessage = (event) => {
2581
2778
  }
2582
2779
  return;
2583
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
+ }
2584
2790
  if (data.type !== UDF_CONSENT_RESPONSE_MESSAGE) return;
2585
2791
  if (typeof data.request_id !== "string") return;
2586
2792
  const pending = pendingConsents.get(data.request_id);
@@ -2619,6 +2825,33 @@ var requestConsent = async (playbookId, minAllowance) => {
2619
2825
  );
2620
2826
  });
2621
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
+ };
2622
2855
  var requestAuthentication = (functionName) => {
2623
2856
  if (!runtimeWindow || !expectedParentOrigin) return;
2624
2857
  runtimeWindow.parent.postMessage(
@@ -2787,16 +3020,19 @@ var installPlaybookRuntime = (targetWindow) => {
2787
3020
  const existing = target.alva || {};
2788
3021
  target.alva = {
2789
3022
  ...existing,
2790
- udf
3023
+ udf,
3024
+ subscribe
2791
3025
  };
2792
3026
  };
2793
3027
 
2794
3028
  // src/index.ts
2795
- var VERSION = true ? "0.11.2" : "dev";
3029
+ var VERSION = true ? "0.11.3-beta.0" : "dev";
2796
3030
  export {
2797
3031
  AlvaClient,
2798
3032
  AlvaError,
2799
3033
  PBSV_UPDATE_MESSAGE,
3034
+ SUBSCRIBE_PROPOSE_MESSAGE,
3035
+ SUBSCRIBE_RESULT_MESSAGE,
2800
3036
  UDF_AUTH_REQUIRED_MESSAGE,
2801
3037
  UDF_CONSENT_REQUEST_MESSAGE,
2802
3038
  UDF_CONSENT_RESPONSE_MESSAGE,
@@ -2819,6 +3055,7 @@ export {
2819
3055
  installPlaybookRuntime,
2820
3056
  mapUdfErrorResponse,
2821
3057
  playbookIdFromToken,
3058
+ subscribe,
2822
3059
  udf
2823
3060
  };
2824
3061
  //# sourceMappingURL=index.js.map