@alva-ai/toolkit 0.25.2-beta.0 → 0.27.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 -1
- package/dist/browser.global.js +14 -14
- package/dist/browser.global.js.map +1 -1
- package/dist/cli.d.ts +41 -2
- package/dist/cli.js +390 -12
- package/dist/cli.js.map +1 -1
- package/dist/dispatch.d.ts +41 -2
- package/dist/dispatch.js +253 -6
- package/dist/dispatch.js.map +1 -1
- package/dist/index.cjs +198 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -3
- package/dist/index.d.ts +42 -3
- package/dist/index.js +197 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ __export(src_exports, {
|
|
|
32
32
|
SUBSCRIBE_PROPOSE_MESSAGE: () => SUBSCRIBE_PROPOSE_MESSAGE,
|
|
33
33
|
SUBSCRIBE_RESULT_MESSAGE: () => SUBSCRIBE_RESULT_MESSAGE,
|
|
34
34
|
SchedulesResource: () => SchedulesResource,
|
|
35
|
+
TradingPairsResource: () => TradingPairsResource,
|
|
35
36
|
UDF_AUTH_REQUIRED_MESSAGE: () => UDF_AUTH_REQUIRED_MESSAGE,
|
|
36
37
|
UDF_CONSENT_REQUEST_MESSAGE: () => UDF_CONSENT_REQUEST_MESSAGE,
|
|
37
38
|
UDF_CONSENT_RESPONSE_MESSAGE: () => UDF_CONSENT_RESPONSE_MESSAGE,
|
|
@@ -2286,8 +2287,8 @@ var NotificationsResource = class {
|
|
|
2286
2287
|
client;
|
|
2287
2288
|
/**
|
|
2288
2289
|
* List the caller's notification history for one feed
|
|
2289
|
-
* `(username, name)`. Authorization
|
|
2290
|
-
*
|
|
2290
|
+
* `(username, name)`. Authorization uses the backend's canonical Feed read
|
|
2291
|
+
* decision (owner, public, bundled paid access, Plan, or Access Group).
|
|
2291
2292
|
*/
|
|
2292
2293
|
async listFeed(params) {
|
|
2293
2294
|
this.client._requireAuth();
|
|
@@ -3549,14 +3550,199 @@ function scheduleEmptyResponse() {
|
|
|
3549
3550
|
);
|
|
3550
3551
|
}
|
|
3551
3552
|
|
|
3553
|
+
// src/resources/tradingPairs.ts
|
|
3554
|
+
function isRecord(value) {
|
|
3555
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3556
|
+
}
|
|
3557
|
+
function stringValue(value) {
|
|
3558
|
+
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
3559
|
+
}
|
|
3560
|
+
function numberValue(value) {
|
|
3561
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
3562
|
+
}
|
|
3563
|
+
function upper(value) {
|
|
3564
|
+
return value === void 0 ? void 0 : value.trim().toUpperCase();
|
|
3565
|
+
}
|
|
3566
|
+
function pairParts(pair) {
|
|
3567
|
+
return pair.split("_");
|
|
3568
|
+
}
|
|
3569
|
+
function inferInstrumentType(rawType, tradingPair) {
|
|
3570
|
+
const type = rawType?.toLowerCase();
|
|
3571
|
+
if (type?.includes("spot")) return "spot";
|
|
3572
|
+
if (type?.includes("perp")) return "perp";
|
|
3573
|
+
if (type?.includes("option")) return "option";
|
|
3574
|
+
return pairParts(tradingPair)[1]?.toLowerCase() ?? "";
|
|
3575
|
+
}
|
|
3576
|
+
function inferUnderlyingType(rawType) {
|
|
3577
|
+
if (rawType === void 0) return void 0;
|
|
3578
|
+
const prefix = rawType.split("-")[0]?.trim().toLowerCase();
|
|
3579
|
+
return prefix && prefix !== rawType.toLowerCase() ? prefix : void 0;
|
|
3580
|
+
}
|
|
3581
|
+
function normalizeCandidate(raw, outerSymbol) {
|
|
3582
|
+
const tradingPair = stringValue(raw.trading_pair) ?? stringValue(raw.tradingPair) ?? stringValue(raw.symbol);
|
|
3583
|
+
if (tradingPair === void 0) return void 0;
|
|
3584
|
+
const type = stringValue(raw.type);
|
|
3585
|
+
const parts = pairParts(tradingPair);
|
|
3586
|
+
const symbol = stringValue(raw.base) ?? outerSymbol ?? (parts.length >= 4 ? parts.slice(2, -1).join("_") : parts.length === 3 ? parts[2] : tradingPair);
|
|
3587
|
+
const market = stringValue(raw.market) ?? stringValue(raw.exchange) ?? parts[0] ?? "";
|
|
3588
|
+
const quote = stringValue(raw.quote) ?? parts[parts.length - 1] ?? "";
|
|
3589
|
+
const instrumentType = stringValue(raw.instrument_type) ?? stringValue(raw.instrumentType) ?? inferInstrumentType(type, tradingPair);
|
|
3590
|
+
const underlyingType = stringValue(raw.underlying_type) ?? stringValue(raw.underlyingType) ?? inferUnderlyingType(type);
|
|
3591
|
+
return {
|
|
3592
|
+
symbol,
|
|
3593
|
+
tradingPair,
|
|
3594
|
+
market,
|
|
3595
|
+
instrumentType,
|
|
3596
|
+
...underlyingType === void 0 ? {} : { underlyingType },
|
|
3597
|
+
quote,
|
|
3598
|
+
...type === void 0 ? {} : { type },
|
|
3599
|
+
...stringValue(raw.description) === void 0 ? {} : { description: stringValue(raw.description) },
|
|
3600
|
+
...numberValue(raw.fee_rate) === void 0 ? numberValue(raw.feeRate) === void 0 ? {} : { feeRate: numberValue(raw.feeRate) } : { feeRate: numberValue(raw.fee_rate) },
|
|
3601
|
+
...stringValue(raw.symbol_icon_url) === void 0 ? stringValue(raw.symbolIconUrl) === void 0 ? {} : { symbolIconUrl: stringValue(raw.symbolIconUrl) } : { symbolIconUrl: stringValue(raw.symbol_icon_url) }
|
|
3602
|
+
};
|
|
3603
|
+
}
|
|
3604
|
+
function flattenResponse(value) {
|
|
3605
|
+
if (!isRecord(value)) return [];
|
|
3606
|
+
const flat = value.trading_pairs;
|
|
3607
|
+
if (Array.isArray(flat)) {
|
|
3608
|
+
return flat.flatMap(
|
|
3609
|
+
(item) => isRecord(item) ? [normalizeCandidate(item)].filter(
|
|
3610
|
+
(candidate) => candidate !== void 0
|
|
3611
|
+
) : []
|
|
3612
|
+
);
|
|
3613
|
+
}
|
|
3614
|
+
const data = value.data;
|
|
3615
|
+
if (!Array.isArray(data)) return [];
|
|
3616
|
+
const candidates = [];
|
|
3617
|
+
for (const symbolGroup of data) {
|
|
3618
|
+
if (!isRecord(symbolGroup)) continue;
|
|
3619
|
+
const symbol = stringValue(symbolGroup.symbol);
|
|
3620
|
+
const groups = symbolGroup.trading_pairs;
|
|
3621
|
+
if (!Array.isArray(groups)) continue;
|
|
3622
|
+
for (const group of groups) {
|
|
3623
|
+
if (!isRecord(group) || !Array.isArray(group.pairs)) continue;
|
|
3624
|
+
for (const pair of group.pairs) {
|
|
3625
|
+
if (!isRecord(pair)) continue;
|
|
3626
|
+
const candidate = normalizeCandidate(
|
|
3627
|
+
{
|
|
3628
|
+
...pair,
|
|
3629
|
+
instrument_type: pair.instrument_type ?? group.instrument_type
|
|
3630
|
+
},
|
|
3631
|
+
symbol
|
|
3632
|
+
);
|
|
3633
|
+
if (candidate !== void 0) candidates.push(candidate);
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
return candidates;
|
|
3638
|
+
}
|
|
3639
|
+
function matchesQuery(candidate, query) {
|
|
3640
|
+
const expected = query.trim();
|
|
3641
|
+
if (candidate.tradingPair === expected) return true;
|
|
3642
|
+
return upper(candidate.symbol) === upper(expected);
|
|
3643
|
+
}
|
|
3644
|
+
function matchesFilter(value, expected) {
|
|
3645
|
+
return expected === void 0 || upper(value) === upper(expected);
|
|
3646
|
+
}
|
|
3647
|
+
function dedupe(candidates) {
|
|
3648
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3649
|
+
return candidates.filter((candidate) => {
|
|
3650
|
+
if (seen.has(candidate.tradingPair)) return false;
|
|
3651
|
+
seen.add(candidate.tradingPair);
|
|
3652
|
+
return true;
|
|
3653
|
+
});
|
|
3654
|
+
}
|
|
3655
|
+
function resolveFilters(params) {
|
|
3656
|
+
const record = isRecord(params) ? params : {};
|
|
3657
|
+
return {
|
|
3658
|
+
market: typeof record.market === "string" ? record.market : void 0,
|
|
3659
|
+
instrumentType: typeof record.instrumentType === "string" ? record.instrumentType : void 0,
|
|
3660
|
+
underlyingType: typeof record.underlyingType === "string" ? record.underlyingType : void 0,
|
|
3661
|
+
quote: typeof record.quote === "string" ? record.quote : void 0
|
|
3662
|
+
};
|
|
3663
|
+
}
|
|
3664
|
+
function pairSearchParams(pair, params) {
|
|
3665
|
+
const parts = pair.split("_");
|
|
3666
|
+
const market = parts[0];
|
|
3667
|
+
const instrumentType = parts[1];
|
|
3668
|
+
const symbol = parts.length >= 4 ? parts.slice(2, -1).join("_") : parts.length === 3 ? parts[2] : void 0;
|
|
3669
|
+
const quote = parts.at(-1);
|
|
3670
|
+
if (!market || !instrumentType || !symbol || !quote) {
|
|
3671
|
+
return { symbol: pair, ...params };
|
|
3672
|
+
}
|
|
3673
|
+
return {
|
|
3674
|
+
symbol,
|
|
3675
|
+
market: params.market ?? market,
|
|
3676
|
+
instrumentType: params.instrumentType ?? instrumentType,
|
|
3677
|
+
underlyingType: params.underlyingType,
|
|
3678
|
+
quote: params.quote ?? quote
|
|
3679
|
+
};
|
|
3680
|
+
}
|
|
3681
|
+
var TradingPairsResource = class {
|
|
3682
|
+
constructor(client) {
|
|
3683
|
+
this.client = client;
|
|
3684
|
+
}
|
|
3685
|
+
client;
|
|
3686
|
+
async search(params) {
|
|
3687
|
+
this.client._requireAuth();
|
|
3688
|
+
const rawSymbol = isRecord(params) ? params.symbol : void 0;
|
|
3689
|
+
const query = typeof rawSymbol === "string" ? rawSymbol.trim() : "";
|
|
3690
|
+
if (!query)
|
|
3691
|
+
throw new AlvaError("INVALID_ARGUMENT", "symbol is required", 400);
|
|
3692
|
+
const response = await this.client._request(
|
|
3693
|
+
"GET",
|
|
3694
|
+
"/api/v1/trading-pairs/search",
|
|
3695
|
+
{ query: { q: query, strict: true } }
|
|
3696
|
+
);
|
|
3697
|
+
const candidates = dedupe(flattenResponse(response)).filter((candidate) => matchesQuery(candidate, query)).filter((candidate) => matchesFilter(candidate.market, params.market)).filter(
|
|
3698
|
+
(candidate) => matchesFilter(candidate.instrumentType, params.instrumentType)
|
|
3699
|
+
).filter(
|
|
3700
|
+
(candidate) => matchesFilter(candidate.underlyingType, params.underlyingType)
|
|
3701
|
+
).filter((candidate) => matchesFilter(candidate.quote, params.quote));
|
|
3702
|
+
const limit = params.limit;
|
|
3703
|
+
if (limit !== void 0 && candidates.length > limit) {
|
|
3704
|
+
return { query, candidates: candidates.slice(0, limit), truncated: true };
|
|
3705
|
+
}
|
|
3706
|
+
return { query, candidates };
|
|
3707
|
+
}
|
|
3708
|
+
async resolve(params) {
|
|
3709
|
+
const record = isRecord(params) ? params : {};
|
|
3710
|
+
const pair = typeof record.pair === "string" ? record.pair.trim() : void 0;
|
|
3711
|
+
const filters = resolveFilters(params);
|
|
3712
|
+
const searchParams = pair === void 0 ? {
|
|
3713
|
+
symbol: typeof record.symbol === "string" ? record.symbol : "",
|
|
3714
|
+
...filters
|
|
3715
|
+
} : pairSearchParams(pair, filters);
|
|
3716
|
+
const result = await this.search(searchParams);
|
|
3717
|
+
const candidates = pair === void 0 ? result.candidates : result.candidates.filter(
|
|
3718
|
+
(candidate) => candidate.tradingPair === pair
|
|
3719
|
+
);
|
|
3720
|
+
if (candidates.length !== 1) {
|
|
3721
|
+
const detailLimit = 50;
|
|
3722
|
+
throw new AlvaError(
|
|
3723
|
+
candidates.length === 0 ? "TRADING_PAIR_NOT_FOUND" : "TRADING_PAIR_NOT_UNIQUE",
|
|
3724
|
+
candidates.length === 0 ? `no canonical trading pair matched "${pair ?? searchParams.symbol}"` : `multiple canonical trading pairs matched "${searchParams.symbol}"`,
|
|
3725
|
+
candidates.length === 0 ? 404 : 409,
|
|
3726
|
+
{
|
|
3727
|
+
query: pair ?? searchParams.symbol,
|
|
3728
|
+
candidateCount: candidates.length,
|
|
3729
|
+
candidates: candidates.slice(0, detailLimit),
|
|
3730
|
+
...candidates.length > detailLimit ? { truncated: true } : {}
|
|
3731
|
+
}
|
|
3732
|
+
);
|
|
3733
|
+
}
|
|
3734
|
+
return candidates[0];
|
|
3735
|
+
}
|
|
3736
|
+
};
|
|
3737
|
+
|
|
3552
3738
|
// src/client.ts
|
|
3553
3739
|
var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
|
|
3554
3740
|
var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
|
|
3555
|
-
function
|
|
3741
|
+
function isRecord2(value) {
|
|
3556
3742
|
return typeof value === "object" && value !== null;
|
|
3557
3743
|
}
|
|
3558
3744
|
function stringField(value, field) {
|
|
3559
|
-
if (!
|
|
3745
|
+
if (!isRecord2(value)) return void 0;
|
|
3560
3746
|
const fieldValue = value[field];
|
|
3561
3747
|
return typeof fieldValue === "string" && fieldValue ? fieldValue : void 0;
|
|
3562
3748
|
}
|
|
@@ -3570,7 +3756,7 @@ function describeCause(cause) {
|
|
|
3570
3756
|
if (cause.message) details.message = cause.message;
|
|
3571
3757
|
const code = stringField(cause, "code");
|
|
3572
3758
|
if (code) details.code = code;
|
|
3573
|
-
} else if (
|
|
3759
|
+
} else if (isRecord2(cause)) {
|
|
3574
3760
|
const code = stringField(cause, "code");
|
|
3575
3761
|
const name = stringField(cause, "name");
|
|
3576
3762
|
const message = stringField(cause, "message");
|
|
@@ -3598,7 +3784,7 @@ function describeFetchFailure(err) {
|
|
|
3598
3784
|
details.message = String(err);
|
|
3599
3785
|
}
|
|
3600
3786
|
const { message: causeMessage, details: causeDetails } = describeCause(
|
|
3601
|
-
|
|
3787
|
+
isRecord2(err) ? err.cause : void 0
|
|
3602
3788
|
);
|
|
3603
3789
|
if (causeDetails) {
|
|
3604
3790
|
details.cause = causeDetails;
|
|
@@ -3658,6 +3844,7 @@ var AlvaClient = class {
|
|
|
3658
3844
|
_credits;
|
|
3659
3845
|
_markets;
|
|
3660
3846
|
_schedules;
|
|
3847
|
+
_tradingPairs;
|
|
3661
3848
|
constructor(config) {
|
|
3662
3849
|
this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
3663
3850
|
this.arraysBaseUrl = config.arraysBaseUrl ?? DEFAULT_ARRAYS_BASE_URL;
|
|
@@ -3755,6 +3942,9 @@ var AlvaClient = class {
|
|
|
3755
3942
|
get markets() {
|
|
3756
3943
|
return this._markets ??= new MarketsResource(this);
|
|
3757
3944
|
}
|
|
3945
|
+
get tradingPairs() {
|
|
3946
|
+
return this._tradingPairs ??= new TradingPairsResource(this);
|
|
3947
|
+
}
|
|
3758
3948
|
get schedules() {
|
|
3759
3949
|
return this._schedules ??= new SchedulesResource(this);
|
|
3760
3950
|
}
|
|
@@ -4371,7 +4561,7 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
4371
4561
|
};
|
|
4372
4562
|
|
|
4373
4563
|
// src/index.ts
|
|
4374
|
-
var VERSION = true ? "0.
|
|
4564
|
+
var VERSION = true ? "0.27.0" : "dev";
|
|
4375
4565
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4376
4566
|
0 && (module.exports = {
|
|
4377
4567
|
AlertsResource,
|
|
@@ -4386,6 +4576,7 @@ var VERSION = true ? "0.25.2-beta.0" : "dev";
|
|
|
4386
4576
|
SUBSCRIBE_PROPOSE_MESSAGE,
|
|
4387
4577
|
SUBSCRIBE_RESULT_MESSAGE,
|
|
4388
4578
|
SchedulesResource,
|
|
4579
|
+
TradingPairsResource,
|
|
4389
4580
|
UDF_AUTH_REQUIRED_MESSAGE,
|
|
4390
4581
|
UDF_CONSENT_REQUEST_MESSAGE,
|
|
4391
4582
|
UDF_CONSENT_RESPONSE_MESSAGE,
|