@alva-ai/toolkit 0.22.0 → 0.23.0-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/README.md +2 -0
- package/dist/browser.global.js +130 -3
- package/dist/browser.global.js.map +1 -1
- package/dist/cli.d.ts +129 -0
- package/dist/cli.js +411 -1
- package/dist/cli.js.map +1 -1
- package/dist/dispatch.d.ts +130 -1
- package/dist/dispatch.js +94 -1
- package/dist/dispatch.js.map +1 -1
- package/dist/index.cjs +320 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +130 -1
- package/dist/index.d.ts +130 -1
- package/dist/index.js +319 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -25,6 +25,7 @@ __export(src_exports, {
|
|
|
25
25
|
AlvaError: () => AlvaError,
|
|
26
26
|
AutomationResource: () => AutomationResource,
|
|
27
27
|
CliUsageError: () => CliUsageError,
|
|
28
|
+
MarketsResource: () => MarketsResource,
|
|
28
29
|
PBSV_UPDATE_MESSAGE: () => PBSV_UPDATE_MESSAGE,
|
|
29
30
|
SUBSCRIBE_PROPOSE_MESSAGE: () => SUBSCRIBE_PROPOSE_MESSAGE,
|
|
30
31
|
SUBSCRIBE_RESULT_MESSAGE: () => SUBSCRIBE_RESULT_MESSAGE,
|
|
@@ -2562,6 +2563,319 @@ var CreditsResource = class {
|
|
|
2562
2563
|
}
|
|
2563
2564
|
};
|
|
2564
2565
|
|
|
2566
|
+
// src/resources/markets.ts
|
|
2567
|
+
var FISCAL_QUARTERS = [
|
|
2568
|
+
"Q1",
|
|
2569
|
+
"Q2",
|
|
2570
|
+
"Q3",
|
|
2571
|
+
"Q4"
|
|
2572
|
+
];
|
|
2573
|
+
var EARNINGS_EVENTS = [
|
|
2574
|
+
"latest-completed",
|
|
2575
|
+
"next-confirmed"
|
|
2576
|
+
];
|
|
2577
|
+
var NARRATIVE_QUERY = `
|
|
2578
|
+
query ToolkitCompanyNarrative($ticker: String!) {
|
|
2579
|
+
market {
|
|
2580
|
+
entity(input: { ticker: $ticker, kind: STOCK }) {
|
|
2581
|
+
ticker
|
|
2582
|
+
companyInsight {
|
|
2583
|
+
asOf
|
|
2584
|
+
generatedAtMs
|
|
2585
|
+
narrative
|
|
2586
|
+
peers
|
|
2587
|
+
}
|
|
2588
|
+
companyInsightHistory {
|
|
2589
|
+
snapshots {
|
|
2590
|
+
asOf
|
|
2591
|
+
generatedAtMs
|
|
2592
|
+
narrative
|
|
2593
|
+
}
|
|
2594
|
+
changeLog {
|
|
2595
|
+
asOf
|
|
2596
|
+
generatedAtMs
|
|
2597
|
+
narrativeChangeLog
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
`.trim();
|
|
2604
|
+
var EARNINGS_CATALOG_QUERY = `
|
|
2605
|
+
query ToolkitCompanyEarningsCatalog($ticker: String!) {
|
|
2606
|
+
market {
|
|
2607
|
+
entity(input: { ticker: $ticker, kind: STOCK }) {
|
|
2608
|
+
ticker
|
|
2609
|
+
earningsPeriods {
|
|
2610
|
+
unresolvedEventCount
|
|
2611
|
+
defaultPeriod {
|
|
2612
|
+
fiscalYear
|
|
2613
|
+
fiscalQuarter
|
|
2614
|
+
label
|
|
2615
|
+
fiscalDateEnding
|
|
2616
|
+
earningsDate
|
|
2617
|
+
session
|
|
2618
|
+
status
|
|
2619
|
+
isDefault
|
|
2620
|
+
}
|
|
2621
|
+
periods {
|
|
2622
|
+
fiscalYear
|
|
2623
|
+
fiscalQuarter
|
|
2624
|
+
label
|
|
2625
|
+
fiscalDateEnding
|
|
2626
|
+
earningsDate
|
|
2627
|
+
session
|
|
2628
|
+
status
|
|
2629
|
+
isDefault
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
`.trim();
|
|
2636
|
+
var EARNINGS_QUERY = `
|
|
2637
|
+
query ToolkitCompanyEarnings($ticker: String!, $input: CompanyEarningsInput) {
|
|
2638
|
+
market {
|
|
2639
|
+
entity(input: { ticker: $ticker, kind: STOCK }) {
|
|
2640
|
+
ticker
|
|
2641
|
+
earnings(input: $input) {
|
|
2642
|
+
period {
|
|
2643
|
+
fiscalYear
|
|
2644
|
+
fiscalQuarter
|
|
2645
|
+
label
|
|
2646
|
+
fiscalDateEnding
|
|
2647
|
+
earningsDate
|
|
2648
|
+
session
|
|
2649
|
+
status
|
|
2650
|
+
isDefault
|
|
2651
|
+
}
|
|
2652
|
+
preEarningsAnalysis {
|
|
2653
|
+
status
|
|
2654
|
+
asOf
|
|
2655
|
+
summary
|
|
2656
|
+
whatWouldChangeView
|
|
2657
|
+
mainQuestion
|
|
2658
|
+
investorFocus
|
|
2659
|
+
consensusAndGuidance
|
|
2660
|
+
stockSetup
|
|
2661
|
+
eventRisk
|
|
2662
|
+
whatWouldDriveUpside
|
|
2663
|
+
bullCase
|
|
2664
|
+
baseCase
|
|
2665
|
+
bearCase
|
|
2666
|
+
keyAsymmetry
|
|
2667
|
+
consensusN
|
|
2668
|
+
consensusObservedAt
|
|
2669
|
+
}
|
|
2670
|
+
earningsRelease {
|
|
2671
|
+
status
|
|
2672
|
+
releaseDate
|
|
2673
|
+
url
|
|
2674
|
+
}
|
|
2675
|
+
earningsTranscript {
|
|
2676
|
+
status
|
|
2677
|
+
date
|
|
2678
|
+
publishedAtMs
|
|
2679
|
+
sections {
|
|
2680
|
+
name
|
|
2681
|
+
entries {
|
|
2682
|
+
speaker
|
|
2683
|
+
title
|
|
2684
|
+
content
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
postEarningsSummary {
|
|
2689
|
+
status
|
|
2690
|
+
asOf
|
|
2691
|
+
reportedCurrency
|
|
2692
|
+
evidenceState
|
|
2693
|
+
openingQuote
|
|
2694
|
+
openingQuoteSpeaker
|
|
2695
|
+
openingQuoteTitle
|
|
2696
|
+
openingQuoteNote
|
|
2697
|
+
buriedSignals
|
|
2698
|
+
whatYouShouldKnow
|
|
2699
|
+
consensusN
|
|
2700
|
+
consensusObservedAt
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
`.trim();
|
|
2707
|
+
function graphQLErrorMessage2(errors) {
|
|
2708
|
+
const messages = errors.map(
|
|
2709
|
+
(error) => typeof error.message === "string" && error.message ? error.message : void 0
|
|
2710
|
+
).filter((message) => Boolean(message));
|
|
2711
|
+
return messages.length > 0 ? messages.join("; ") : "GraphQL request failed";
|
|
2712
|
+
}
|
|
2713
|
+
function normalizedTicker(ticker) {
|
|
2714
|
+
const normalized = ticker.trim().toUpperCase();
|
|
2715
|
+
if (!normalized) {
|
|
2716
|
+
throw new AlvaError("INVALID_ARGUMENT", "ticker is required", 400);
|
|
2717
|
+
}
|
|
2718
|
+
return normalized;
|
|
2719
|
+
}
|
|
2720
|
+
var MarketsResource = class {
|
|
2721
|
+
constructor(client) {
|
|
2722
|
+
this.client = client;
|
|
2723
|
+
}
|
|
2724
|
+
client;
|
|
2725
|
+
async narrative(ticker) {
|
|
2726
|
+
this.client._requireAuth();
|
|
2727
|
+
const requestedTicker = normalizedTicker(ticker);
|
|
2728
|
+
const data = await this.graphql(NARRATIVE_QUERY, {
|
|
2729
|
+
ticker: requestedTicker
|
|
2730
|
+
});
|
|
2731
|
+
const entity = data.market?.entity;
|
|
2732
|
+
if (!entity) {
|
|
2733
|
+
throw this.notFound(requestedTicker);
|
|
2734
|
+
}
|
|
2735
|
+
return {
|
|
2736
|
+
ticker: entity.ticker,
|
|
2737
|
+
current: entity.companyInsight,
|
|
2738
|
+
history: entity.companyInsightHistory
|
|
2739
|
+
};
|
|
2740
|
+
}
|
|
2741
|
+
async earningsPeriods(ticker) {
|
|
2742
|
+
this.client._requireAuth();
|
|
2743
|
+
const requestedTicker = normalizedTicker(ticker);
|
|
2744
|
+
const data = await this.graphql(
|
|
2745
|
+
EARNINGS_CATALOG_QUERY,
|
|
2746
|
+
{ ticker: requestedTicker }
|
|
2747
|
+
);
|
|
2748
|
+
const entity = data.market?.entity;
|
|
2749
|
+
if (!entity) {
|
|
2750
|
+
throw this.notFound(requestedTicker);
|
|
2751
|
+
}
|
|
2752
|
+
if (!entity.earningsPeriods) {
|
|
2753
|
+
throw new AlvaError(
|
|
2754
|
+
"MARKETS_EARNINGS_NOT_COVERED",
|
|
2755
|
+
`No earnings periods are available for ${entity.ticker}`,
|
|
2756
|
+
404,
|
|
2757
|
+
{ ticker: entity.ticker }
|
|
2758
|
+
);
|
|
2759
|
+
}
|
|
2760
|
+
return entity.earningsPeriods;
|
|
2761
|
+
}
|
|
2762
|
+
async earnings(params) {
|
|
2763
|
+
this.client._requireAuth();
|
|
2764
|
+
const ticker = normalizedTicker(params.ticker);
|
|
2765
|
+
const requestedEvent = params.event;
|
|
2766
|
+
const requestedFiscalYear = params.fiscalYear;
|
|
2767
|
+
const requestedFiscalQuarter = params.fiscalQuarter;
|
|
2768
|
+
const hasExplicitPeriod = requestedFiscalYear !== void 0 || requestedFiscalQuarter !== void 0;
|
|
2769
|
+
if (requestedEvent !== void 0 && hasExplicitPeriod) {
|
|
2770
|
+
throw new AlvaError(
|
|
2771
|
+
"INVALID_ARGUMENT",
|
|
2772
|
+
"event cannot be combined with fiscalYear or fiscalQuarter",
|
|
2773
|
+
400
|
|
2774
|
+
);
|
|
2775
|
+
}
|
|
2776
|
+
if (requestedFiscalYear === void 0 !== (requestedFiscalQuarter === void 0)) {
|
|
2777
|
+
throw new AlvaError(
|
|
2778
|
+
"INVALID_ARGUMENT",
|
|
2779
|
+
"fiscalYear and fiscalQuarter must be provided together",
|
|
2780
|
+
400
|
|
2781
|
+
);
|
|
2782
|
+
}
|
|
2783
|
+
if (requestedEvent !== void 0 && !EARNINGS_EVENTS.includes(requestedEvent)) {
|
|
2784
|
+
throw new AlvaError(
|
|
2785
|
+
"INVALID_ARGUMENT",
|
|
2786
|
+
`Unknown earnings event selector: ${requestedEvent}`,
|
|
2787
|
+
400
|
|
2788
|
+
);
|
|
2789
|
+
}
|
|
2790
|
+
if (requestedFiscalYear !== void 0 && (!Number.isInteger(requestedFiscalYear) || requestedFiscalYear < 1900 || requestedFiscalYear > 9999)) {
|
|
2791
|
+
throw new AlvaError(
|
|
2792
|
+
"INVALID_ARGUMENT",
|
|
2793
|
+
"fiscalYear must be an integer between 1900 and 9999",
|
|
2794
|
+
400
|
|
2795
|
+
);
|
|
2796
|
+
}
|
|
2797
|
+
if (requestedFiscalQuarter !== void 0 && !FISCAL_QUARTERS.includes(requestedFiscalQuarter)) {
|
|
2798
|
+
throw new AlvaError(
|
|
2799
|
+
"INVALID_ARGUMENT",
|
|
2800
|
+
"fiscalQuarter must be Q1, Q2, Q3, or Q4",
|
|
2801
|
+
400
|
|
2802
|
+
);
|
|
2803
|
+
}
|
|
2804
|
+
let fiscalYear;
|
|
2805
|
+
let fiscalQuarter;
|
|
2806
|
+
if (requestedFiscalYear !== void 0 && requestedFiscalQuarter !== void 0) {
|
|
2807
|
+
fiscalYear = requestedFiscalYear;
|
|
2808
|
+
fiscalQuarter = requestedFiscalQuarter;
|
|
2809
|
+
} else {
|
|
2810
|
+
const event = requestedEvent ?? "latest-completed";
|
|
2811
|
+
const catalog = await this.earningsPeriods(ticker);
|
|
2812
|
+
const period = this.selectPeriod(catalog, event, ticker);
|
|
2813
|
+
fiscalYear = period.fiscalYear;
|
|
2814
|
+
fiscalQuarter = period.fiscalQuarter;
|
|
2815
|
+
}
|
|
2816
|
+
const data = await this.graphql(EARNINGS_QUERY, {
|
|
2817
|
+
ticker,
|
|
2818
|
+
input: { fiscalYear, fiscalQuarter }
|
|
2819
|
+
});
|
|
2820
|
+
const entity = data.market?.entity;
|
|
2821
|
+
if (!entity) {
|
|
2822
|
+
throw this.notFound(ticker);
|
|
2823
|
+
}
|
|
2824
|
+
if (!entity.earnings) {
|
|
2825
|
+
throw new AlvaError(
|
|
2826
|
+
"MARKETS_EARNINGS_NOT_COVERED",
|
|
2827
|
+
`No earnings content is available for ${entity.ticker} FY${fiscalYear} ${fiscalQuarter}`,
|
|
2828
|
+
404,
|
|
2829
|
+
{ ticker: entity.ticker, fiscalYear, fiscalQuarter }
|
|
2830
|
+
);
|
|
2831
|
+
}
|
|
2832
|
+
return { ticker: entity.ticker, ...entity.earnings };
|
|
2833
|
+
}
|
|
2834
|
+
selectPeriod(catalog, event, ticker) {
|
|
2835
|
+
if (event === "latest-completed") {
|
|
2836
|
+
if (catalog.defaultPeriod) return catalog.defaultPeriod;
|
|
2837
|
+
} else {
|
|
2838
|
+
const upcoming = catalog.periods.filter((period) => period.status === "UPCOMING").sort((a, b) => a.earningsDate.localeCompare(b.earningsDate));
|
|
2839
|
+
if (upcoming.length > 0) return upcoming[0];
|
|
2840
|
+
}
|
|
2841
|
+
throw new AlvaError(
|
|
2842
|
+
"MARKETS_EARNINGS_EVENT_NOT_FOUND",
|
|
2843
|
+
`No ${event} earnings event is available for ${ticker}`,
|
|
2844
|
+
404,
|
|
2845
|
+
{ ticker, event }
|
|
2846
|
+
);
|
|
2847
|
+
}
|
|
2848
|
+
notFound(ticker) {
|
|
2849
|
+
return new AlvaError(
|
|
2850
|
+
"MARKETS_ENTITY_NOT_FOUND",
|
|
2851
|
+
`No stock entity was found for ${ticker}`,
|
|
2852
|
+
404,
|
|
2853
|
+
{ ticker }
|
|
2854
|
+
);
|
|
2855
|
+
}
|
|
2856
|
+
async graphql(query, variables) {
|
|
2857
|
+
const response = await this.client._request("POST", "/query", {
|
|
2858
|
+
body: { query, variables }
|
|
2859
|
+
});
|
|
2860
|
+
if (response.errors && response.errors.length > 0) {
|
|
2861
|
+
throw new AlvaError(
|
|
2862
|
+
"GRAPHQL_ERROR",
|
|
2863
|
+
graphQLErrorMessage2(response.errors),
|
|
2864
|
+
400,
|
|
2865
|
+
{ errors: response.errors }
|
|
2866
|
+
);
|
|
2867
|
+
}
|
|
2868
|
+
if (!response.data) {
|
|
2869
|
+
throw new AlvaError(
|
|
2870
|
+
"GRAPHQL_EMPTY_RESPONSE",
|
|
2871
|
+
"GraphQL response did not include data",
|
|
2872
|
+
502
|
|
2873
|
+
);
|
|
2874
|
+
}
|
|
2875
|
+
return response.data;
|
|
2876
|
+
}
|
|
2877
|
+
};
|
|
2878
|
+
|
|
2565
2879
|
// src/client.ts
|
|
2566
2880
|
var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
|
|
2567
2881
|
var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
|
|
@@ -2669,6 +2983,7 @@ var AlvaClient = class {
|
|
|
2669
2983
|
_feedback;
|
|
2670
2984
|
_functions;
|
|
2671
2985
|
_credits;
|
|
2986
|
+
_markets;
|
|
2672
2987
|
constructor(config) {
|
|
2673
2988
|
this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
2674
2989
|
this.arraysBaseUrl = config.arraysBaseUrl ?? DEFAULT_ARRAYS_BASE_URL;
|
|
@@ -2763,6 +3078,9 @@ var AlvaClient = class {
|
|
|
2763
3078
|
get credits() {
|
|
2764
3079
|
return this._credits ??= new CreditsResource(this);
|
|
2765
3080
|
}
|
|
3081
|
+
get markets() {
|
|
3082
|
+
return this._markets ??= new MarketsResource(this);
|
|
3083
|
+
}
|
|
2766
3084
|
_requireAuth() {
|
|
2767
3085
|
if (!this.pbsvToken && !this.viewer_token && !this.apiKey) {
|
|
2768
3086
|
throw new AlvaError(
|
|
@@ -3364,7 +3682,7 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
3364
3682
|
};
|
|
3365
3683
|
|
|
3366
3684
|
// src/index.ts
|
|
3367
|
-
var VERSION = true ? "0.
|
|
3685
|
+
var VERSION = true ? "0.23.0-beta.0" : "dev";
|
|
3368
3686
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3369
3687
|
0 && (module.exports = {
|
|
3370
3688
|
AlertsResource,
|
|
@@ -3372,6 +3690,7 @@ var VERSION = true ? "0.22.0" : "dev";
|
|
|
3372
3690
|
AlvaError,
|
|
3373
3691
|
AutomationResource,
|
|
3374
3692
|
CliUsageError,
|
|
3693
|
+
MarketsResource,
|
|
3375
3694
|
PBSV_UPDATE_MESSAGE,
|
|
3376
3695
|
SUBSCRIBE_PROPOSE_MESSAGE,
|
|
3377
3696
|
SUBSCRIBE_RESULT_MESSAGE,
|