@alva-ai/toolkit 0.13.0 → 0.14.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 +4 -2
- package/dist/browser.global.js +43 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/cli.d.ts +71 -2
- package/dist/cli.js +373 -24
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +154 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +70 -2
- package/dist/index.d.ts +70 -2
- package/dist/index.js +153 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
AlvaClient: () => AlvaClient,
|
|
24
24
|
AlvaError: () => AlvaError,
|
|
25
|
+
CliUsageError: () => CliUsageError,
|
|
25
26
|
PBSV_UPDATE_MESSAGE: () => PBSV_UPDATE_MESSAGE,
|
|
26
27
|
SUBSCRIBE_PROPOSE_MESSAGE: () => SUBSCRIBE_PROPOSE_MESSAGE,
|
|
27
28
|
SUBSCRIBE_RESULT_MESSAGE: () => SUBSCRIBE_RESULT_MESSAGE,
|
|
@@ -65,6 +66,14 @@ var AlvaError = class extends Error {
|
|
|
65
66
|
this.details = details;
|
|
66
67
|
}
|
|
67
68
|
};
|
|
69
|
+
var CliUsageError = class extends Error {
|
|
70
|
+
command;
|
|
71
|
+
constructor(message, command) {
|
|
72
|
+
super(message);
|
|
73
|
+
this.name = "CliUsageError";
|
|
74
|
+
this.command = command;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
68
77
|
|
|
69
78
|
// src/resources/fs.ts
|
|
70
79
|
function isValidUtf8(bytes) {
|
|
@@ -359,7 +368,8 @@ var ReleaseResource = class {
|
|
|
359
368
|
cronjob_id: params.cronjob_id,
|
|
360
369
|
view_json: params.view_json,
|
|
361
370
|
description: params.description,
|
|
362
|
-
changelog: params.changelog
|
|
371
|
+
changelog: params.changelog,
|
|
372
|
+
agent_type: params.agent_type
|
|
363
373
|
}
|
|
364
374
|
});
|
|
365
375
|
}
|
|
@@ -545,8 +555,11 @@ var PlaybooksResource = class {
|
|
|
545
555
|
"/api/v1/playbooks/trending",
|
|
546
556
|
{ query }
|
|
547
557
|
);
|
|
558
|
+
const webOrigin = webOriginFromApiBase(this.client.baseUrl);
|
|
548
559
|
return {
|
|
549
|
-
playbooks: (raw.playbooks ?? []).map(
|
|
560
|
+
playbooks: (raw.playbooks ?? []).map(
|
|
561
|
+
(p) => toAgentPlaybook(p, webOrigin)
|
|
562
|
+
),
|
|
550
563
|
has_next: raw.has_next ?? false
|
|
551
564
|
};
|
|
552
565
|
}
|
|
@@ -575,10 +588,23 @@ var PlaybooksResource = class {
|
|
|
575
588
|
);
|
|
576
589
|
}
|
|
577
590
|
};
|
|
578
|
-
function
|
|
591
|
+
function webOriginFromApiBase(apiBaseUrl) {
|
|
592
|
+
try {
|
|
593
|
+
const host = new URL(apiBaseUrl).hostname;
|
|
594
|
+
const match = /^api-llm\.([a-z0-9-]+)\.alva\.ai$/i.exec(host);
|
|
595
|
+
if (match) {
|
|
596
|
+
const env = match[1].toLowerCase();
|
|
597
|
+
return env === "prd" ? "https://alva.ai" : `https://${env}.alva.ai`;
|
|
598
|
+
}
|
|
599
|
+
} catch {
|
|
600
|
+
}
|
|
601
|
+
return "https://alva.ai";
|
|
602
|
+
}
|
|
603
|
+
function toAgentPlaybook(raw, webOrigin) {
|
|
579
604
|
const username = raw.creator?.name ?? "";
|
|
580
605
|
const name = raw.name ?? "";
|
|
581
606
|
const ref = username && name ? `${username}/${name}` : name;
|
|
607
|
+
const urlPath = username && name ? `/u/${username}/playbooks/${name}` : "";
|
|
582
608
|
return {
|
|
583
609
|
id: raw.id === void 0 ? "" : String(raw.id),
|
|
584
610
|
ref,
|
|
@@ -588,7 +614,8 @@ function toAgentPlaybook(raw) {
|
|
|
588
614
|
description: raw.description ?? "",
|
|
589
615
|
tags: raw.tags ?? [],
|
|
590
616
|
follow_count: raw.follow_count ?? 0,
|
|
591
|
-
url_path:
|
|
617
|
+
url_path: urlPath,
|
|
618
|
+
url: urlPath ? `${webOrigin}${urlPath}` : "",
|
|
592
619
|
...raw.readme ? { readme: raw.readme } : {},
|
|
593
620
|
cursor: raw.cursor ?? ""
|
|
594
621
|
};
|
|
@@ -2576,6 +2603,122 @@ function parseResultPayload(result) {
|
|
|
2576
2603
|
}
|
|
2577
2604
|
}
|
|
2578
2605
|
|
|
2606
|
+
// src/resources/credits.ts
|
|
2607
|
+
var CREDIT_WALLET_QUERY = `
|
|
2608
|
+
query ToolkitCreditWallet {
|
|
2609
|
+
viewer {
|
|
2610
|
+
creditWallet {
|
|
2611
|
+
balance
|
|
2612
|
+
totalRemaining
|
|
2613
|
+
todayUsed
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
`.trim();
|
|
2618
|
+
var CREDIT_WALLET_ITEMS_QUERY = `
|
|
2619
|
+
query ToolkitCreditWalletItems($input: CreditWalletItemConnectionInput!) {
|
|
2620
|
+
viewer {
|
|
2621
|
+
creditWallet {
|
|
2622
|
+
balance
|
|
2623
|
+
totalRemaining
|
|
2624
|
+
todayUsed
|
|
2625
|
+
items(input: $input) {
|
|
2626
|
+
pageInfo {
|
|
2627
|
+
hasNextPage
|
|
2628
|
+
hasPreviousPage
|
|
2629
|
+
startCursor
|
|
2630
|
+
endCursor
|
|
2631
|
+
}
|
|
2632
|
+
edges {
|
|
2633
|
+
cursor
|
|
2634
|
+
node {
|
|
2635
|
+
id
|
|
2636
|
+
sessionId
|
|
2637
|
+
playbookId
|
|
2638
|
+
feedId
|
|
2639
|
+
op
|
|
2640
|
+
source
|
|
2641
|
+
amount
|
|
2642
|
+
extras
|
|
2643
|
+
createdAtMs
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
`.trim();
|
|
2651
|
+
function graphQLErrorMessage(errors) {
|
|
2652
|
+
const messages = errors.map(
|
|
2653
|
+
(error) => typeof error.message === "string" && error.message ? error.message : void 0
|
|
2654
|
+
).filter((message) => Boolean(message));
|
|
2655
|
+
return messages.length > 0 ? messages.join("; ") : "GraphQL request failed";
|
|
2656
|
+
}
|
|
2657
|
+
var CreditsResource = class {
|
|
2658
|
+
constructor(client) {
|
|
2659
|
+
this.client = client;
|
|
2660
|
+
}
|
|
2661
|
+
client;
|
|
2662
|
+
async wallet() {
|
|
2663
|
+
this.client._requireAuth();
|
|
2664
|
+
const data = await this.graphql(CREDIT_WALLET_QUERY);
|
|
2665
|
+
const wallet = data.viewer?.creditWallet;
|
|
2666
|
+
if (!wallet) {
|
|
2667
|
+
throw new AlvaError(
|
|
2668
|
+
"GRAPHQL_EMPTY_RESPONSE",
|
|
2669
|
+
"GraphQL response did not include viewer.creditWallet",
|
|
2670
|
+
502
|
|
2671
|
+
);
|
|
2672
|
+
}
|
|
2673
|
+
return wallet;
|
|
2674
|
+
}
|
|
2675
|
+
async items(params) {
|
|
2676
|
+
this.client._requireAuth();
|
|
2677
|
+
const data = await this.graphql(
|
|
2678
|
+
CREDIT_WALLET_ITEMS_QUERY,
|
|
2679
|
+
{
|
|
2680
|
+
input: {
|
|
2681
|
+
startAtMs: params.startAtMs,
|
|
2682
|
+
endAtMs: params.endAtMs,
|
|
2683
|
+
sessionId: params.sessionId,
|
|
2684
|
+
first: params.first,
|
|
2685
|
+
after: params.after
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
);
|
|
2689
|
+
const wallet = data.viewer?.creditWallet;
|
|
2690
|
+
if (!wallet) {
|
|
2691
|
+
throw new AlvaError(
|
|
2692
|
+
"GRAPHQL_EMPTY_RESPONSE",
|
|
2693
|
+
"GraphQL response did not include viewer.creditWallet.items",
|
|
2694
|
+
502
|
|
2695
|
+
);
|
|
2696
|
+
}
|
|
2697
|
+
return wallet;
|
|
2698
|
+
}
|
|
2699
|
+
async graphql(query, variables) {
|
|
2700
|
+
const response = await this.client._request("POST", "/query", {
|
|
2701
|
+
body: variables === void 0 ? { query } : { query, variables }
|
|
2702
|
+
});
|
|
2703
|
+
if (response.errors && response.errors.length > 0) {
|
|
2704
|
+
throw new AlvaError(
|
|
2705
|
+
"GRAPHQL_ERROR",
|
|
2706
|
+
graphQLErrorMessage(response.errors),
|
|
2707
|
+
400,
|
|
2708
|
+
{ errors: response.errors }
|
|
2709
|
+
);
|
|
2710
|
+
}
|
|
2711
|
+
if (!response.data) {
|
|
2712
|
+
throw new AlvaError(
|
|
2713
|
+
"GRAPHQL_EMPTY_RESPONSE",
|
|
2714
|
+
"GraphQL response did not include data",
|
|
2715
|
+
502
|
|
2716
|
+
);
|
|
2717
|
+
}
|
|
2718
|
+
return response.data;
|
|
2719
|
+
}
|
|
2720
|
+
};
|
|
2721
|
+
|
|
2579
2722
|
// src/client.ts
|
|
2580
2723
|
var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
|
|
2581
2724
|
var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
|
|
@@ -2677,6 +2820,7 @@ var AlvaClient = class {
|
|
|
2677
2820
|
_channelGroupSubscriptions;
|
|
2678
2821
|
_feedback;
|
|
2679
2822
|
_functions;
|
|
2823
|
+
_credits;
|
|
2680
2824
|
constructor(config) {
|
|
2681
2825
|
this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
2682
2826
|
this.arraysBaseUrl = config.arraysBaseUrl ?? DEFAULT_ARRAYS_BASE_URL;
|
|
@@ -2758,6 +2902,9 @@ var AlvaClient = class {
|
|
|
2758
2902
|
get functions() {
|
|
2759
2903
|
return this._functions ??= new FunctionsResource(this);
|
|
2760
2904
|
}
|
|
2905
|
+
get credits() {
|
|
2906
|
+
return this._credits ??= new CreditsResource(this);
|
|
2907
|
+
}
|
|
2761
2908
|
_requireAuth() {
|
|
2762
2909
|
if (!this.pbsvToken && !this.viewer_token && !this.apiKey) {
|
|
2763
2910
|
throw new AlvaError(
|
|
@@ -2925,7 +3072,7 @@ var AlvaClient = class {
|
|
|
2925
3072
|
return void 0;
|
|
2926
3073
|
}
|
|
2927
3074
|
const contentType = response.headers.get("content-type") ?? "";
|
|
2928
|
-
if (contentType.includes("application/octet-stream") || contentType.includes("image/")) {
|
|
3075
|
+
if (contentType.includes("application/octet-stream") || contentType.startsWith("text/") || contentType.includes("image/")) {
|
|
2929
3076
|
return response.arrayBuffer();
|
|
2930
3077
|
}
|
|
2931
3078
|
return response.json();
|
|
@@ -3359,11 +3506,12 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
3359
3506
|
};
|
|
3360
3507
|
|
|
3361
3508
|
// src/index.ts
|
|
3362
|
-
var VERSION = true ? "0.
|
|
3509
|
+
var VERSION = true ? "0.14.0" : "dev";
|
|
3363
3510
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3364
3511
|
0 && (module.exports = {
|
|
3365
3512
|
AlvaClient,
|
|
3366
3513
|
AlvaError,
|
|
3514
|
+
CliUsageError,
|
|
3367
3515
|
PBSV_UPDATE_MESSAGE,
|
|
3368
3516
|
SUBSCRIBE_PROPOSE_MESSAGE,
|
|
3369
3517
|
SUBSCRIBE_RESULT_MESSAGE,
|