@alva-ai/toolkit 0.13.1 → 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/dist/browser.global.js +43 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/cli.d.ts +65 -1
- package/dist/cli.js +372 -24
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +144 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -2
- package/dist/index.d.ts +66 -2
- package/dist/index.js +144 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.d.ts
CHANGED
|
@@ -21,6 +21,52 @@ interface UserProfile {
|
|
|
21
21
|
/** Caller's alfs home directory, e.g. `/alva/home/<username>`. */
|
|
22
22
|
home_path: string;
|
|
23
23
|
}
|
|
24
|
+
interface CreditWallet {
|
|
25
|
+
balance: number;
|
|
26
|
+
totalRemaining: number;
|
|
27
|
+
todayUsed: number;
|
|
28
|
+
}
|
|
29
|
+
interface CreditWalletItemsParams {
|
|
30
|
+
/** Inclusive UTC lower bound, Unix milliseconds. */
|
|
31
|
+
startAtMs: number;
|
|
32
|
+
/** Exclusive UTC upper bound, Unix milliseconds. */
|
|
33
|
+
endAtMs: number;
|
|
34
|
+
/** Optional chat/session id to filter consumption records. */
|
|
35
|
+
sessionId?: string;
|
|
36
|
+
/** Page size, defaulted and capped by the gateway. */
|
|
37
|
+
first?: number;
|
|
38
|
+
/** Opaque cursor from a previous page's `pageInfo.endCursor`. */
|
|
39
|
+
after?: string;
|
|
40
|
+
}
|
|
41
|
+
interface CreditWalletItem {
|
|
42
|
+
id: string;
|
|
43
|
+
sessionId: string | null;
|
|
44
|
+
playbookId: string | null;
|
|
45
|
+
feedId: string | null;
|
|
46
|
+
op: string;
|
|
47
|
+
source: string;
|
|
48
|
+
amount: number;
|
|
49
|
+
extras?: unknown;
|
|
50
|
+
/** Creation timestamp, Unix milliseconds. */
|
|
51
|
+
createdAtMs: number;
|
|
52
|
+
}
|
|
53
|
+
interface CreditWalletPageInfo {
|
|
54
|
+
hasNextPage: boolean;
|
|
55
|
+
hasPreviousPage: boolean;
|
|
56
|
+
startCursor: string | null;
|
|
57
|
+
endCursor: string | null;
|
|
58
|
+
}
|
|
59
|
+
interface CreditWalletItemEdge {
|
|
60
|
+
cursor: string;
|
|
61
|
+
node: CreditWalletItem;
|
|
62
|
+
}
|
|
63
|
+
interface CreditWalletItemConnection {
|
|
64
|
+
pageInfo: CreditWalletPageInfo;
|
|
65
|
+
edges: CreditWalletItemEdge[];
|
|
66
|
+
}
|
|
67
|
+
interface CreditWalletItemsResponse extends CreditWallet {
|
|
68
|
+
items: CreditWalletItemConnection;
|
|
69
|
+
}
|
|
24
70
|
type SubscriptionTier = 'SUBSCRIPTION_TIER_UNSPECIFIED' | 'SUBSCRIPTION_TIER_FREE' | 'SUBSCRIPTION_TIER_PRO';
|
|
25
71
|
interface EnsureArraysJwtResponse {
|
|
26
72
|
expires_at: number;
|
|
@@ -226,6 +272,12 @@ interface FeedReleaseRequest {
|
|
|
226
272
|
view_json?: Record<string, unknown>;
|
|
227
273
|
description?: string;
|
|
228
274
|
changelog?: string;
|
|
275
|
+
/**
|
|
276
|
+
* Agent kind that produces this feed (e.g. "alpi"). Optional. Marks the feed
|
|
277
|
+
* as an agent feed whose prompt is editable; an empty/omitted value means a
|
|
278
|
+
* regular (non-agent) feed. The backend validates it against its catalog.
|
|
279
|
+
*/
|
|
280
|
+
agent_type?: string;
|
|
229
281
|
}
|
|
230
282
|
interface FeedReleaseResponse {
|
|
231
283
|
feed_id: number;
|
|
@@ -953,8 +1005,10 @@ interface TrendingPlaybookItem {
|
|
|
953
1005
|
description: string;
|
|
954
1006
|
tags: string[];
|
|
955
1007
|
follow_count: number;
|
|
956
|
-
/** Relative web path for opening or citing the playbook. */
|
|
1008
|
+
/** Relative web path for opening or citing the playbook, e.g. `/u/alice/playbooks/btc`. */
|
|
957
1009
|
url_path: string;
|
|
1010
|
+
/** Absolute, clickable web URL, e.g. `https://alva.ai/u/alice/playbooks/btc`. */
|
|
1011
|
+
url: string;
|
|
958
1012
|
/** README ALFS path when available. */
|
|
959
1013
|
readme?: string;
|
|
960
1014
|
/** Cursor to pass as `cursor` / `current` for pagination. */
|
|
@@ -1473,6 +1527,14 @@ declare class FunctionsResource {
|
|
|
1473
1527
|
revokeAllowance(params: RevokeAllowanceParams): Promise<RevokeAllowanceResponse>;
|
|
1474
1528
|
}
|
|
1475
1529
|
|
|
1530
|
+
declare class CreditsResource {
|
|
1531
|
+
private client;
|
|
1532
|
+
constructor(client: AlvaClient);
|
|
1533
|
+
wallet(): Promise<CreditWallet>;
|
|
1534
|
+
items(params: CreditWalletItemsParams): Promise<CreditWalletItemsResponse>;
|
|
1535
|
+
private graphql;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1476
1538
|
interface RequestOptions {
|
|
1477
1539
|
query?: Record<string, unknown>;
|
|
1478
1540
|
body?: unknown;
|
|
@@ -1531,6 +1593,7 @@ declare class AlvaClient {
|
|
|
1531
1593
|
private _channelGroupSubscriptions?;
|
|
1532
1594
|
private _feedback?;
|
|
1533
1595
|
private _functions?;
|
|
1596
|
+
private _credits?;
|
|
1534
1597
|
constructor(config: AlvaClientConfig);
|
|
1535
1598
|
get fs(): FsResource;
|
|
1536
1599
|
get run(): RunResource;
|
|
@@ -1555,6 +1618,7 @@ declare class AlvaClient {
|
|
|
1555
1618
|
get channelGroupSubscriptions(): ChannelGroupSubscriptionsResource;
|
|
1556
1619
|
get feedback(): FeedbackResource;
|
|
1557
1620
|
get functions(): FunctionsResource;
|
|
1621
|
+
get credits(): CreditsResource;
|
|
1558
1622
|
_requireAuth(): void;
|
|
1559
1623
|
_request(method: string, path: string, options?: RequestOptions): Promise<unknown>;
|
|
1560
1624
|
}
|
package/dist/cli.js
CHANGED
|
@@ -8855,13 +8855,13 @@ body {
|
|
|
8855
8855
|
width: 0.5px;
|
|
8856
8856
|
flex-shrink: 0;
|
|
8857
8857
|
margin-block: var(--spacing-l);
|
|
8858
|
-
background-color: var(--line-
|
|
8858
|
+
background-color: var(--line-l12);
|
|
8859
8859
|
}
|
|
8860
8860
|
|
|
8861
8861
|
.divider-h {
|
|
8862
8862
|
height: 0.5px;
|
|
8863
8863
|
margin-inline: var(--spacing-l);
|
|
8864
|
-
background-color: var(--line-
|
|
8864
|
+
background-color: var(--line-l12);
|
|
8865
8865
|
}
|
|
8866
8866
|
|
|
8867
8867
|
/* \u2500\u2500 Equal Height Fill \u2500\u2500 */
|
|
@@ -9086,7 +9086,7 @@ body {
|
|
|
9086
9086
|
left: var(--spacing-m);
|
|
9087
9087
|
right: var(--spacing-m);
|
|
9088
9088
|
height: 0.5px;
|
|
9089
|
-
background: var(--line-
|
|
9089
|
+
background: var(--line-l12);
|
|
9090
9090
|
}
|
|
9091
9091
|
|
|
9092
9092
|
.feed-item:last-child::after {
|
|
@@ -9282,7 +9282,7 @@ body {
|
|
|
9282
9282
|
width: 88px;
|
|
9283
9283
|
height: 70px;
|
|
9284
9284
|
border-radius: var(--radius-ct-s);
|
|
9285
|
-
border:
|
|
9285
|
+
border: 0.5px solid var(--line-l12);
|
|
9286
9286
|
flex-shrink: 0;
|
|
9287
9287
|
overflow: hidden;
|
|
9288
9288
|
position: relative;
|
|
@@ -9795,7 +9795,8 @@ var ReleaseResource = class {
|
|
|
9795
9795
|
cronjob_id: params.cronjob_id,
|
|
9796
9796
|
view_json: params.view_json,
|
|
9797
9797
|
description: params.description,
|
|
9798
|
-
changelog: params.changelog
|
|
9798
|
+
changelog: params.changelog,
|
|
9799
|
+
agent_type: params.agent_type
|
|
9799
9800
|
}
|
|
9800
9801
|
});
|
|
9801
9802
|
}
|
|
@@ -9981,8 +9982,11 @@ var PlaybooksResource = class {
|
|
|
9981
9982
|
"/api/v1/playbooks/trending",
|
|
9982
9983
|
{ query }
|
|
9983
9984
|
);
|
|
9985
|
+
const webOrigin = webOriginFromApiBase(this.client.baseUrl);
|
|
9984
9986
|
return {
|
|
9985
|
-
playbooks: (raw.playbooks ?? []).map(
|
|
9987
|
+
playbooks: (raw.playbooks ?? []).map(
|
|
9988
|
+
(p) => toAgentPlaybook(p, webOrigin)
|
|
9989
|
+
),
|
|
9986
9990
|
has_next: raw.has_next ?? false
|
|
9987
9991
|
};
|
|
9988
9992
|
}
|
|
@@ -10011,10 +10015,23 @@ var PlaybooksResource = class {
|
|
|
10011
10015
|
);
|
|
10012
10016
|
}
|
|
10013
10017
|
};
|
|
10014
|
-
function
|
|
10018
|
+
function webOriginFromApiBase(apiBaseUrl) {
|
|
10019
|
+
try {
|
|
10020
|
+
const host = new URL(apiBaseUrl).hostname;
|
|
10021
|
+
const match = /^api-llm\.([a-z0-9-]+)\.alva\.ai$/i.exec(host);
|
|
10022
|
+
if (match) {
|
|
10023
|
+
const env = match[1].toLowerCase();
|
|
10024
|
+
return env === "prd" ? "https://alva.ai" : `https://${env}.alva.ai`;
|
|
10025
|
+
}
|
|
10026
|
+
} catch {
|
|
10027
|
+
}
|
|
10028
|
+
return "https://alva.ai";
|
|
10029
|
+
}
|
|
10030
|
+
function toAgentPlaybook(raw, webOrigin) {
|
|
10015
10031
|
const username = raw.creator?.name ?? "";
|
|
10016
10032
|
const name = raw.name ?? "";
|
|
10017
10033
|
const ref = username && name ? `${username}/${name}` : name;
|
|
10034
|
+
const urlPath = username && name ? `/u/${username}/playbooks/${name}` : "";
|
|
10018
10035
|
return {
|
|
10019
10036
|
id: raw.id === void 0 ? "" : String(raw.id),
|
|
10020
10037
|
ref,
|
|
@@ -10024,7 +10041,8 @@ function toAgentPlaybook(raw) {
|
|
|
10024
10041
|
description: raw.description ?? "",
|
|
10025
10042
|
tags: raw.tags ?? [],
|
|
10026
10043
|
follow_count: raw.follow_count ?? 0,
|
|
10027
|
-
url_path:
|
|
10044
|
+
url_path: urlPath,
|
|
10045
|
+
url: urlPath ? `${webOrigin}${urlPath}` : "",
|
|
10028
10046
|
...raw.readme ? { readme: raw.readme } : {},
|
|
10029
10047
|
cursor: raw.cursor ?? ""
|
|
10030
10048
|
};
|
|
@@ -12012,6 +12030,122 @@ function parseResultPayload(result) {
|
|
|
12012
12030
|
}
|
|
12013
12031
|
}
|
|
12014
12032
|
|
|
12033
|
+
// src/resources/credits.ts
|
|
12034
|
+
var CREDIT_WALLET_QUERY = `
|
|
12035
|
+
query ToolkitCreditWallet {
|
|
12036
|
+
viewer {
|
|
12037
|
+
creditWallet {
|
|
12038
|
+
balance
|
|
12039
|
+
totalRemaining
|
|
12040
|
+
todayUsed
|
|
12041
|
+
}
|
|
12042
|
+
}
|
|
12043
|
+
}
|
|
12044
|
+
`.trim();
|
|
12045
|
+
var CREDIT_WALLET_ITEMS_QUERY = `
|
|
12046
|
+
query ToolkitCreditWalletItems($input: CreditWalletItemConnectionInput!) {
|
|
12047
|
+
viewer {
|
|
12048
|
+
creditWallet {
|
|
12049
|
+
balance
|
|
12050
|
+
totalRemaining
|
|
12051
|
+
todayUsed
|
|
12052
|
+
items(input: $input) {
|
|
12053
|
+
pageInfo {
|
|
12054
|
+
hasNextPage
|
|
12055
|
+
hasPreviousPage
|
|
12056
|
+
startCursor
|
|
12057
|
+
endCursor
|
|
12058
|
+
}
|
|
12059
|
+
edges {
|
|
12060
|
+
cursor
|
|
12061
|
+
node {
|
|
12062
|
+
id
|
|
12063
|
+
sessionId
|
|
12064
|
+
playbookId
|
|
12065
|
+
feedId
|
|
12066
|
+
op
|
|
12067
|
+
source
|
|
12068
|
+
amount
|
|
12069
|
+
extras
|
|
12070
|
+
createdAtMs
|
|
12071
|
+
}
|
|
12072
|
+
}
|
|
12073
|
+
}
|
|
12074
|
+
}
|
|
12075
|
+
}
|
|
12076
|
+
}
|
|
12077
|
+
`.trim();
|
|
12078
|
+
function graphQLErrorMessage(errors) {
|
|
12079
|
+
const messages = errors.map(
|
|
12080
|
+
(error) => typeof error.message === "string" && error.message ? error.message : void 0
|
|
12081
|
+
).filter((message) => Boolean(message));
|
|
12082
|
+
return messages.length > 0 ? messages.join("; ") : "GraphQL request failed";
|
|
12083
|
+
}
|
|
12084
|
+
var CreditsResource = class {
|
|
12085
|
+
constructor(client) {
|
|
12086
|
+
this.client = client;
|
|
12087
|
+
}
|
|
12088
|
+
client;
|
|
12089
|
+
async wallet() {
|
|
12090
|
+
this.client._requireAuth();
|
|
12091
|
+
const data = await this.graphql(CREDIT_WALLET_QUERY);
|
|
12092
|
+
const wallet = data.viewer?.creditWallet;
|
|
12093
|
+
if (!wallet) {
|
|
12094
|
+
throw new AlvaError(
|
|
12095
|
+
"GRAPHQL_EMPTY_RESPONSE",
|
|
12096
|
+
"GraphQL response did not include viewer.creditWallet",
|
|
12097
|
+
502
|
|
12098
|
+
);
|
|
12099
|
+
}
|
|
12100
|
+
return wallet;
|
|
12101
|
+
}
|
|
12102
|
+
async items(params) {
|
|
12103
|
+
this.client._requireAuth();
|
|
12104
|
+
const data = await this.graphql(
|
|
12105
|
+
CREDIT_WALLET_ITEMS_QUERY,
|
|
12106
|
+
{
|
|
12107
|
+
input: {
|
|
12108
|
+
startAtMs: params.startAtMs,
|
|
12109
|
+
endAtMs: params.endAtMs,
|
|
12110
|
+
sessionId: params.sessionId,
|
|
12111
|
+
first: params.first,
|
|
12112
|
+
after: params.after
|
|
12113
|
+
}
|
|
12114
|
+
}
|
|
12115
|
+
);
|
|
12116
|
+
const wallet = data.viewer?.creditWallet;
|
|
12117
|
+
if (!wallet) {
|
|
12118
|
+
throw new AlvaError(
|
|
12119
|
+
"GRAPHQL_EMPTY_RESPONSE",
|
|
12120
|
+
"GraphQL response did not include viewer.creditWallet.items",
|
|
12121
|
+
502
|
|
12122
|
+
);
|
|
12123
|
+
}
|
|
12124
|
+
return wallet;
|
|
12125
|
+
}
|
|
12126
|
+
async graphql(query, variables) {
|
|
12127
|
+
const response = await this.client._request("POST", "/query", {
|
|
12128
|
+
body: variables === void 0 ? { query } : { query, variables }
|
|
12129
|
+
});
|
|
12130
|
+
if (response.errors && response.errors.length > 0) {
|
|
12131
|
+
throw new AlvaError(
|
|
12132
|
+
"GRAPHQL_ERROR",
|
|
12133
|
+
graphQLErrorMessage(response.errors),
|
|
12134
|
+
400,
|
|
12135
|
+
{ errors: response.errors }
|
|
12136
|
+
);
|
|
12137
|
+
}
|
|
12138
|
+
if (!response.data) {
|
|
12139
|
+
throw new AlvaError(
|
|
12140
|
+
"GRAPHQL_EMPTY_RESPONSE",
|
|
12141
|
+
"GraphQL response did not include data",
|
|
12142
|
+
502
|
|
12143
|
+
);
|
|
12144
|
+
}
|
|
12145
|
+
return response.data;
|
|
12146
|
+
}
|
|
12147
|
+
};
|
|
12148
|
+
|
|
12015
12149
|
// src/client.ts
|
|
12016
12150
|
var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
|
|
12017
12151
|
var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
|
|
@@ -12113,6 +12247,7 @@ var AlvaClient = class {
|
|
|
12113
12247
|
_channelGroupSubscriptions;
|
|
12114
12248
|
_feedback;
|
|
12115
12249
|
_functions;
|
|
12250
|
+
_credits;
|
|
12116
12251
|
constructor(config) {
|
|
12117
12252
|
this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
12118
12253
|
this.arraysBaseUrl = config.arraysBaseUrl ?? DEFAULT_ARRAYS_BASE_URL;
|
|
@@ -12194,6 +12329,9 @@ var AlvaClient = class {
|
|
|
12194
12329
|
get functions() {
|
|
12195
12330
|
return this._functions ??= new FunctionsResource(this);
|
|
12196
12331
|
}
|
|
12332
|
+
get credits() {
|
|
12333
|
+
return this._credits ??= new CreditsResource(this);
|
|
12334
|
+
}
|
|
12197
12335
|
_requireAuth() {
|
|
12198
12336
|
if (!this.pbsvToken && !this.viewer_token && !this.apiKey) {
|
|
12199
12337
|
throw new AlvaError(
|
|
@@ -12361,7 +12499,7 @@ var AlvaClient = class {
|
|
|
12361
12499
|
return void 0;
|
|
12362
12500
|
}
|
|
12363
12501
|
const contentType = response.headers.get("content-type") ?? "";
|
|
12364
|
-
if (contentType.includes("application/octet-stream") || contentType.includes("image/")) {
|
|
12502
|
+
if (contentType.includes("application/octet-stream") || contentType.startsWith("text/") || contentType.includes("image/")) {
|
|
12365
12503
|
return response.arrayBuffer();
|
|
12366
12504
|
}
|
|
12367
12505
|
return response.json();
|
|
@@ -13116,12 +13254,69 @@ function formatPlaybookSkillFile(file) {
|
|
|
13116
13254
|
return file.content;
|
|
13117
13255
|
}
|
|
13118
13256
|
|
|
13257
|
+
// src/cli/playbooksFormat.ts
|
|
13258
|
+
var MAX_DESC = 200;
|
|
13259
|
+
function truncate(text, max = MAX_DESC) {
|
|
13260
|
+
const trimmed = text.trim().replace(/\s+/g, " ");
|
|
13261
|
+
if (trimmed.length <= max) return trimmed;
|
|
13262
|
+
return `${trimmed.slice(0, max - 1).trimEnd()}\u2026`;
|
|
13263
|
+
}
|
|
13264
|
+
function discoveryUrl(item, webOrigin) {
|
|
13265
|
+
if (!item.owner_username || !item.name) return "";
|
|
13266
|
+
return `${webOrigin}/u/${item.owner_username}/playbooks/${item.name}`;
|
|
13267
|
+
}
|
|
13268
|
+
function formatTrendingPlaybooks(resp) {
|
|
13269
|
+
const items = resp.playbooks ?? [];
|
|
13270
|
+
if (items.length === 0) return "(no playbooks)\n";
|
|
13271
|
+
const lines = [`${items.length} playbook(s):`, ""];
|
|
13272
|
+
for (const p of items) {
|
|
13273
|
+
const title = p.display_name || p.name || p.ref;
|
|
13274
|
+
const followed = p.follow_count ? ` \u2605 ${p.follow_count}` : "";
|
|
13275
|
+
lines.push(`\u2022 ${title}${followed}`);
|
|
13276
|
+
if (p.ref) lines.push(` ${p.ref}`);
|
|
13277
|
+
if (p.url) lines.push(` ${p.url}`);
|
|
13278
|
+
if (p.description) lines.push(` ${truncate(p.description)}`);
|
|
13279
|
+
if (p.tags && p.tags.length > 0)
|
|
13280
|
+
lines.push(` tags: ${p.tags.join(", ")}`);
|
|
13281
|
+
lines.push("");
|
|
13282
|
+
}
|
|
13283
|
+
if (resp.has_next) {
|
|
13284
|
+
lines.push("(more results \u2014 pass --cursor <last item cursor> to page)", "");
|
|
13285
|
+
}
|
|
13286
|
+
return lines.join("\n");
|
|
13287
|
+
}
|
|
13288
|
+
function formatPlaybook(item, webOrigin) {
|
|
13289
|
+
if (!item) return "(not found or not visible)\n";
|
|
13290
|
+
return discoveryItemLines(item, webOrigin).join("\n") + "\n";
|
|
13291
|
+
}
|
|
13292
|
+
function formatPlaybookList(items, webOrigin, opts = {}) {
|
|
13293
|
+
if (!items || items.length === 0) return "(no playbooks)\n";
|
|
13294
|
+
const lines = [`${items.length} playbook(s):`, ""];
|
|
13295
|
+
for (const item of items) lines.push(...discoveryItemLines(item, webOrigin));
|
|
13296
|
+
if (opts.hasNext) {
|
|
13297
|
+
lines.push("(more results \u2014 pass --cursor <cursor> to page)", "");
|
|
13298
|
+
}
|
|
13299
|
+
return lines.join("\n");
|
|
13300
|
+
}
|
|
13301
|
+
function discoveryItemLines(item, webOrigin) {
|
|
13302
|
+
const title = item.display_name || item.name || item.ref || item.id;
|
|
13303
|
+
const visibility = item.visibility ? ` [${item.visibility}]` : "";
|
|
13304
|
+
const out = [`\u2022 ${title}${visibility}`];
|
|
13305
|
+
const ref = item.ref || (item.owner_username && item.name ? `${item.owner_username}/${item.name}` : "");
|
|
13306
|
+
if (ref) out.push(` ${ref}`);
|
|
13307
|
+
const url = discoveryUrl(item, webOrigin);
|
|
13308
|
+
if (url) out.push(` ${url}`);
|
|
13309
|
+
if (item.id) out.push(` id: ${item.id}`);
|
|
13310
|
+
out.push("");
|
|
13311
|
+
return out;
|
|
13312
|
+
}
|
|
13313
|
+
|
|
13119
13314
|
// src/cli/index.ts
|
|
13120
13315
|
import * as fs2 from "fs";
|
|
13121
13316
|
import * as os2 from "os";
|
|
13122
13317
|
import * as fsPromises2 from "fs/promises";
|
|
13123
13318
|
import { Agent, setGlobalDispatcher } from "undici";
|
|
13124
|
-
var CLI_VERSION = true ? "0.
|
|
13319
|
+
var CLI_VERSION = true ? "0.14.0" : "dev";
|
|
13125
13320
|
var DEFAULT_RUN_TIMEOUT_MS = 6e5;
|
|
13126
13321
|
var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
|
|
13127
13322
|
var configuredRunFetchTimeoutMs;
|
|
@@ -13156,6 +13351,7 @@ Commands:
|
|
|
13156
13351
|
feed Feed lifecycle management (delete)
|
|
13157
13352
|
playbooks Playbook discovery (trending, get, list) and visibility
|
|
13158
13353
|
functions Playbook UDF function management (register, list, delete, invoke, allowance)
|
|
13354
|
+
credits Credit wallet and self-scoped usage history (wallet, items)
|
|
13159
13355
|
secrets Secret management (create, list, get, update, delete)
|
|
13160
13356
|
sdk SDK documentation (doc, partitions, partition-summary)
|
|
13161
13357
|
skillhub Playbook skills (list, tags, get, file)
|
|
@@ -13266,6 +13462,33 @@ Response fields:
|
|
|
13266
13462
|
|
|
13267
13463
|
Examples:
|
|
13268
13464
|
alva user me`,
|
|
13465
|
+
credits: `Usage: alva credits <subcommand> [options]
|
|
13466
|
+
|
|
13467
|
+
Read the authenticated user's own credit wallet and consumption history.
|
|
13468
|
+
|
|
13469
|
+
Subcommands:
|
|
13470
|
+
wallet Show current wallet balance, total remaining, and UTC today usage
|
|
13471
|
+
items List raw credit consumption records in a time window
|
|
13472
|
+
|
|
13473
|
+
Items window flags (choose exactly one):
|
|
13474
|
+
--today UTC day containing the current time
|
|
13475
|
+
--last <duration> Recent window, e.g. 7d, 24h, 30m
|
|
13476
|
+
--start <time> --end <time> Explicit UTC window; accepts ISO, YYYY-MM-DD, or Unix ms
|
|
13477
|
+
|
|
13478
|
+
Items optional flags:
|
|
13479
|
+
--session-id <id> Filter to one chat/session
|
|
13480
|
+
--first <n> Page size (1-500)
|
|
13481
|
+
--after <cursor> Opaque cursor from pageInfo.endCursor
|
|
13482
|
+
|
|
13483
|
+
Notes:
|
|
13484
|
+
- Results are viewer-scoped by the backend; there is no --user-id override.
|
|
13485
|
+
- --start is inclusive and --end is exclusive.
|
|
13486
|
+
|
|
13487
|
+
Examples:
|
|
13488
|
+
alva credits wallet
|
|
13489
|
+
alva credits items --today --first 20
|
|
13490
|
+
alva credits items --last 7d --session-id 2069373335591239680
|
|
13491
|
+
alva credits items --start 2026-06-23 --end 2026-06-24`,
|
|
13269
13492
|
fs: `Usage: alva fs <subcommand> [options]
|
|
13270
13493
|
|
|
13271
13494
|
Subcommands:
|
|
@@ -13515,9 +13738,16 @@ Set-visibility flags:
|
|
|
13515
13738
|
--name <name> Playbook name (required; owner derived from auth)
|
|
13516
13739
|
--visibility <v> public, private, or paid (required, case-insensitive)
|
|
13517
13740
|
|
|
13518
|
-
|
|
13741
|
+
Output:
|
|
13742
|
+
trending / get / list print a readable summary (title, ref, clickable
|
|
13743
|
+
URL, description, tags) by default. Pass --json for the raw envelope
|
|
13744
|
+
(for scripting / jq).
|
|
13745
|
+
--json Emit raw JSON instead of the readable rendering
|
|
13746
|
+
|
|
13747
|
+
JSON response fields:
|
|
13519
13748
|
playbooks[].ref "username/name" identifier for agents
|
|
13520
|
-
playbooks[].url_path
|
|
13749
|
+
playbooks[].url_path Relative web path: /u/username/playbooks/name
|
|
13750
|
+
playbooks[].url Absolute web URL: https://alva.ai/u/username/playbooks/name
|
|
13521
13751
|
playbooks[].description Short summary
|
|
13522
13752
|
playbooks[].tags Discovery tags
|
|
13523
13753
|
playbooks[].follow_count Social proof signal
|
|
@@ -13618,6 +13848,9 @@ Feed flags:
|
|
|
13618
13848
|
--view-json <json> View configuration JSON
|
|
13619
13849
|
--description <text> Feed description
|
|
13620
13850
|
--changelog <text> Per-major changelog summary
|
|
13851
|
+
--agent-type <type> Agent kind that produces this feed, e.g. "alpi".
|
|
13852
|
+
Marks the feed as an agent feed with an editable
|
|
13853
|
+
prompt (AGENTS.md). Omit for a regular feed.
|
|
13621
13854
|
|
|
13622
13855
|
Playbook-draft flags:
|
|
13623
13856
|
--name <name> URL-safe playbook name, unique per user (required)
|
|
@@ -13655,6 +13888,7 @@ Display name conventions:
|
|
|
13655
13888
|
Examples:
|
|
13656
13889
|
alva release feed --name btc-ema --version 1.0.0 --cronjob-id 42
|
|
13657
13890
|
alva release feed --name nvda-insiders --version 1.0.0 --cronjob-id 43 --description "NVDA insider trading activity"
|
|
13891
|
+
alva release feed --name market-pulse --version 1.0.0 --cronjob-id 44 --agent-type alpi
|
|
13658
13892
|
alva release playbook-draft --name btc-dashboard --display-name "BTC Trend Dashboard" --feeds '[{"feed_id":100}]' --trading-symbols '["BTC"]'
|
|
13659
13893
|
alva release playbook-draft --name btc-dashboard --display-name "BTC Trend Dashboard" --feeds '[{"feed_id":100}]' --skill-id alva/screener
|
|
13660
13894
|
alva release playbook-draft --name btc-dashboard --display-name "BTC Trend Dashboard" --feeds '[{"feed_id":100}]' --tags '["btc","macro"]'
|
|
@@ -14142,7 +14376,8 @@ var BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
|
|
|
14142
14376
|
"no-browser",
|
|
14143
14377
|
"browser",
|
|
14144
14378
|
"base64",
|
|
14145
|
-
"full"
|
|
14379
|
+
"full",
|
|
14380
|
+
"today"
|
|
14146
14381
|
]);
|
|
14147
14382
|
function parseFlags2(argv) {
|
|
14148
14383
|
const flags = {};
|
|
@@ -14314,6 +14549,93 @@ function playbookVisibility(val) {
|
|
|
14314
14549
|
"playbooks"
|
|
14315
14550
|
);
|
|
14316
14551
|
}
|
|
14552
|
+
function parseCreditsTimestamp(value, flag, command) {
|
|
14553
|
+
const trimmed = value.trim();
|
|
14554
|
+
if (/^\d+$/.test(trimmed)) {
|
|
14555
|
+
const ms = Number(trimmed);
|
|
14556
|
+
if (Number.isSafeInteger(ms)) return ms;
|
|
14557
|
+
}
|
|
14558
|
+
const normalized = /^\d{4}-\d{2}-\d{2}$/.test(trimmed) ? `${trimmed}T00:00:00Z` : /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?$/.test(trimmed) ? `${trimmed}Z` : trimmed;
|
|
14559
|
+
const parsed = Date.parse(normalized);
|
|
14560
|
+
if (Number.isNaN(parsed)) {
|
|
14561
|
+
throw new CliUsageError(
|
|
14562
|
+
`--${flag} must be an ISO time, YYYY-MM-DD, or Unix ms for '${command}', got '${value}'`,
|
|
14563
|
+
command.split(" ")[0]
|
|
14564
|
+
);
|
|
14565
|
+
}
|
|
14566
|
+
return parsed;
|
|
14567
|
+
}
|
|
14568
|
+
function parseCreditsDurationMs(value) {
|
|
14569
|
+
const match = /^([1-9]\d*)([mhd])$/.exec(value.trim().toLowerCase());
|
|
14570
|
+
if (!match) {
|
|
14571
|
+
throw new CliUsageError(
|
|
14572
|
+
`--last must be a positive duration like 30m, 24h, or 7d for 'credits items', got '${value}'`,
|
|
14573
|
+
"credits"
|
|
14574
|
+
);
|
|
14575
|
+
}
|
|
14576
|
+
const amount = Number(match[1]);
|
|
14577
|
+
const unit = match[2];
|
|
14578
|
+
const multiplier = unit === "m" ? 6e4 : unit === "h" ? 36e5 : 864e5;
|
|
14579
|
+
const durationMs = amount * multiplier;
|
|
14580
|
+
if (!Number.isSafeInteger(durationMs)) {
|
|
14581
|
+
throw new CliUsageError(
|
|
14582
|
+
`--last duration is too large for 'credits items', got '${value}'`,
|
|
14583
|
+
"credits"
|
|
14584
|
+
);
|
|
14585
|
+
}
|
|
14586
|
+
return durationMs;
|
|
14587
|
+
}
|
|
14588
|
+
function parseCreditsItemsParams(flags) {
|
|
14589
|
+
const command = "credits items";
|
|
14590
|
+
const hasToday = boolFlag(flags["today"]) === true;
|
|
14591
|
+
const hasLast = flags["last"] !== void 0;
|
|
14592
|
+
const hasStart = flags["start"] !== void 0;
|
|
14593
|
+
const hasEnd = flags["end"] !== void 0;
|
|
14594
|
+
const windowCount = (hasToday ? 1 : 0) + (hasLast ? 1 : 0) + (hasStart || hasEnd ? 1 : 0);
|
|
14595
|
+
if (windowCount !== 1) {
|
|
14596
|
+
throw new CliUsageError(
|
|
14597
|
+
"Choose exactly one window for 'credits items': --today, --last, or --start with --end",
|
|
14598
|
+
"credits"
|
|
14599
|
+
);
|
|
14600
|
+
}
|
|
14601
|
+
if (hasStart !== hasEnd) {
|
|
14602
|
+
throw new CliUsageError(
|
|
14603
|
+
"--start and --end must be provided together for 'credits items'",
|
|
14604
|
+
"credits"
|
|
14605
|
+
);
|
|
14606
|
+
}
|
|
14607
|
+
let startAtMs;
|
|
14608
|
+
let endAtMs;
|
|
14609
|
+
if (hasToday) {
|
|
14610
|
+
const now = /* @__PURE__ */ new Date();
|
|
14611
|
+
startAtMs = Date.UTC(
|
|
14612
|
+
now.getUTCFullYear(),
|
|
14613
|
+
now.getUTCMonth(),
|
|
14614
|
+
now.getUTCDate()
|
|
14615
|
+
);
|
|
14616
|
+
endAtMs = startAtMs + 864e5;
|
|
14617
|
+
} else if (hasLast) {
|
|
14618
|
+
const durationMs = parseCreditsDurationMs(flags["last"]);
|
|
14619
|
+
endAtMs = Date.now();
|
|
14620
|
+
startAtMs = endAtMs - durationMs;
|
|
14621
|
+
} else {
|
|
14622
|
+
startAtMs = parseCreditsTimestamp(flags["start"], "start", command);
|
|
14623
|
+
endAtMs = parseCreditsTimestamp(flags["end"], "end", command);
|
|
14624
|
+
}
|
|
14625
|
+
if (endAtMs <= startAtMs) {
|
|
14626
|
+
throw new CliUsageError(
|
|
14627
|
+
"--end must be greater than --start for 'credits items'",
|
|
14628
|
+
"credits"
|
|
14629
|
+
);
|
|
14630
|
+
}
|
|
14631
|
+
return {
|
|
14632
|
+
startAtMs,
|
|
14633
|
+
endAtMs,
|
|
14634
|
+
sessionId: flags["session-id"],
|
|
14635
|
+
first: optionalBoundedIntegerFlag(flags, "first", command, 1, 500),
|
|
14636
|
+
after: flags["after"]
|
|
14637
|
+
};
|
|
14638
|
+
}
|
|
14317
14639
|
function jsonParse(val) {
|
|
14318
14640
|
if (val === void 0) return void 0;
|
|
14319
14641
|
try {
|
|
@@ -14684,15 +15006,32 @@ async function dispatch(client, args, meta, deps) {
|
|
|
14684
15006
|
);
|
|
14685
15007
|
}
|
|
14686
15008
|
}
|
|
15009
|
+
case "credits": {
|
|
15010
|
+
if (!subcommand)
|
|
15011
|
+
throw new CliUsageError("Missing subcommand for credits", "credits");
|
|
15012
|
+
switch (subcommand) {
|
|
15013
|
+
case "wallet":
|
|
15014
|
+
return client.credits.wallet();
|
|
15015
|
+
case "items":
|
|
15016
|
+
return client.credits.items(parseCreditsItemsParams(flags));
|
|
15017
|
+
default:
|
|
15018
|
+
throw new CliUsageError(
|
|
15019
|
+
`Unknown subcommand: credits ${subcommand}`,
|
|
15020
|
+
"credits"
|
|
15021
|
+
);
|
|
15022
|
+
}
|
|
15023
|
+
}
|
|
14687
15024
|
case "playbooks": {
|
|
14688
15025
|
if (!subcommand)
|
|
14689
15026
|
throw new CliUsageError(
|
|
14690
15027
|
"Missing subcommand for playbooks",
|
|
14691
15028
|
"playbooks"
|
|
14692
15029
|
);
|
|
15030
|
+
const asJson = boolFlag(flags["json"]) ?? false;
|
|
15031
|
+
const webOrigin = webOriginFromApiBase(client.baseUrl);
|
|
14693
15032
|
switch (subcommand) {
|
|
14694
|
-
case "trending":
|
|
14695
|
-
|
|
15033
|
+
case "trending": {
|
|
15034
|
+
const result = await client.playbooks.trending({
|
|
14696
15035
|
keyword: flags["keyword"],
|
|
14697
15036
|
tags: csvList(flags["tags"] ?? flags["tag"]),
|
|
14698
15037
|
sort: trendingPlaybooksSort(flags["sort"]),
|
|
@@ -14700,6 +15039,8 @@ async function dispatch(client, args, meta, deps) {
|
|
|
14700
15039
|
cursor: flags["cursor"],
|
|
14701
15040
|
current: flags["current"]
|
|
14702
15041
|
});
|
|
15042
|
+
return asJson ? result : formatTrendingPlaybooks(result);
|
|
15043
|
+
}
|
|
14703
15044
|
case "set-visibility":
|
|
14704
15045
|
return client.playbooks.setVisibility({
|
|
14705
15046
|
name: requireFlag(flags, "name", "playbooks set-visibility"),
|
|
@@ -14710,25 +15051,31 @@ async function dispatch(client, args, meta, deps) {
|
|
|
14710
15051
|
case "get": {
|
|
14711
15052
|
const ids = csvList(flags["ids"]);
|
|
14712
15053
|
if (ids && ids.length > 0) {
|
|
14713
|
-
|
|
15054
|
+
const result = await client.playbooks.getByIds(ids);
|
|
15055
|
+
return asJson ? result : formatPlaybookList(result.items, webOrigin);
|
|
14714
15056
|
}
|
|
14715
|
-
if (flags["id"]) {
|
|
14716
|
-
|
|
14717
|
-
|
|
14718
|
-
|
|
14719
|
-
|
|
15057
|
+
if (flags["id"] || flags["ref"]) {
|
|
15058
|
+
const result = await client.playbooks.get({
|
|
15059
|
+
id: flags["id"],
|
|
15060
|
+
ref: flags["ref"]
|
|
15061
|
+
});
|
|
15062
|
+
return asJson ? result : formatPlaybook(result, webOrigin);
|
|
14720
15063
|
}
|
|
14721
15064
|
throw new CliUsageError(
|
|
14722
15065
|
"--id, --ids or --ref is required",
|
|
14723
15066
|
"playbooks"
|
|
14724
15067
|
);
|
|
14725
15068
|
}
|
|
14726
|
-
case "list":
|
|
14727
|
-
|
|
15069
|
+
case "list": {
|
|
15070
|
+
const result = await client.playbooks.listByOwner({
|
|
14728
15071
|
owner: requireFlag(flags, "owner", "playbooks list"),
|
|
14729
15072
|
limit: num(flags["limit"]),
|
|
14730
15073
|
cursor: flags["cursor"]
|
|
14731
15074
|
});
|
|
15075
|
+
return asJson ? result : formatPlaybookList(result.items, webOrigin, {
|
|
15076
|
+
hasNext: result.has_next
|
|
15077
|
+
});
|
|
15078
|
+
}
|
|
14732
15079
|
default:
|
|
14733
15080
|
throw new CliUsageError(
|
|
14734
15081
|
`Unknown subcommand: playbooks ${subcommand}`,
|
|
@@ -14864,7 +15211,8 @@ async function dispatch(client, args, meta, deps) {
|
|
|
14864
15211
|
cronjob_id: requireNumericFlag(flags, "cronjob-id", "release feed"),
|
|
14865
15212
|
view_json: jsonParse(flags["view-json"]),
|
|
14866
15213
|
description: flags["description"],
|
|
14867
|
-
changelog: flags["changelog"]
|
|
15214
|
+
changelog: flags["changelog"],
|
|
15215
|
+
agent_type: flags["agent-type"]
|
|
14868
15216
|
});
|
|
14869
15217
|
case "playbook-draft":
|
|
14870
15218
|
return client.release.playbookDraft({
|