Compare commits

..
2 Commits
Author SHA1 Message Date
Yijia-Xiao 121265d18d release: TradingAgents 1.0.1
See CHANGELOG.md for what 1.0.1 fixes.
2026-11-25 06:36:19 +00:00
Yijia-Xiao 81501e0f10 ci(npm): enable publishing for TradingAgents v1.0.0 2026-11-24 11:06:30 +00:00
17 changed files with 258 additions and 144 deletions
+2 -1
View File
@@ -29,7 +29,8 @@ jobs:
with: with:
node-version: 22 node-version: 22
cache: npm cache: npm
- run: npm ci # Installed as the release installs.
- run: npm run ci:install
- run: npm run typecheck - run: npm run typecheck
- run: npm run lint - run: npm run lint
- run: npm run compile - run: npm run compile
+12 -5
View File
@@ -6,15 +6,21 @@ name: npm
# and @tauric/tradingagents, whose tradingagents command runs the one for the platform it is installed on. The files # and @tauric/tradingagents, whose tradingagents command runs the one for the platform it is installed on. The files
# are the release's own, checked against its SHA256SUMS. Publishing is by npm's trusted publishing (this # are the release's own, checked against its SHA256SUMS. Publishing is by npm's trusted publishing (this
# workflow's OIDC identity, no stored token), which records provenance. The release workflow checks the # workflow's OIDC identity, no stored token), which records provenance. The release workflow checks the
# packages can be written and packed before the release is drafted. # packages can be written and packed before the release is drafted. Run it by hand with a tag to publish a release
# whose run did not finish.
on: on:
release: release:
types: [published] types: [published]
workflow_dispatch:
inputs:
tag:
description: "A published release's tag, such as v1.0.0"
required: true
permissions: {} permissions: {}
concurrency: concurrency:
group: npm-${{ github.event.release.tag_name }} group: npm-${{ github.event.release.tag_name || inputs.tag }}
jobs: jobs:
npm: npm:
@@ -23,11 +29,11 @@ jobs:
contents: read contents: read
id-token: write id-token: write
env: env:
TAG: ${{ github.event.release.tag_name }} TAG: ${{ github.event.release.tag_name || inputs.tag }}
steps: steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with: with:
ref: ${{ github.event.release.tag_name }} ref: ${{ github.event.release.tag_name || inputs.tag }}
persist-credentials: false persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with: with:
@@ -36,7 +42,8 @@ jobs:
cache: npm cache: npm
- name: The tag names this version - name: The tag names this version
run: test "$TAG" = "v$(node -p 'require("./package.json").version')" run: test "$TAG" = "v$(node -p 'require("./package.json").version')"
- run: npm ci --ignore-scripts # No dependency's install script runs, but Bun's own: it puts the bun executable in place.
- run: npm run ci:install
- name: The release's executables, as checked against its SHA256SUMS - name: The release's executables, as checked against its SHA256SUMS
env: env:
GH_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }}
+2 -1
View File
@@ -31,7 +31,8 @@ jobs:
env: env:
TAG: ${{ github.ref_name }} TAG: ${{ github.ref_name }}
run: test "$TAG" = "v$(node -p 'require("./package.json").version')" run: test "$TAG" = "v$(node -p 'require("./package.json").version')"
- run: npm ci # Installed as npm.yml installs, so the packages are checked as they will be published.
- run: npm run ci:install
- name: CHANGELOG.md has this version's notes - name: CHANGELOG.md has this version's notes
env: env:
TAG: ${{ github.ref_name }} TAG: ${{ github.ref_name }}
+9
View File
@@ -1,5 +1,14 @@
# Changelog # Changelog
## 1.0.1 (2026-11-25)
- A plan's report asks the question the planning started from; replies added while planning follow it in the PDF.
- A report opens with the answer, without the progress notes written along the way.
- Price history reads two, three and five years.
- A year of price history that spans February 29 is no longer refused.
- Storing a key names the provider's API key (for example, "Stored the Tauric API key").
- A correlation of returns needs at least three returns (four shared dates); over three dates it reported a perfect +1 or -1.
## 1.0.0 (2026-11-24) ## 1.0.0 (2026-11-24)
- TradingAgents: Towards Agentic Finance Research. - TradingAgents: Towards Agentic Finance Research.
+62 -62
View File
@@ -1,12 +1,12 @@
{ {
"name": "tradingagents", "name": "tradingagents",
"version": "1.0.0", "version": "1.0.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "tradingagents", "name": "tradingagents",
"version": "1.0.0", "version": "1.0.1",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@ai-sdk/anthropic": "4.0.106", "@ai-sdk/anthropic": "4.0.106",
@@ -36,12 +36,12 @@
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "2.6.8", "@biomejs/biome": "2.6.8",
"@types/bun": "1.4.4", "@types/bun": "1.4.5",
"@types/node": "22.20.5", "@types/node": "22.20.5",
"@types/pdfkit": "0.17.7", "@types/pdfkit": "0.17.7",
"@types/react": "19.3.0", "@types/react": "19.3.0",
"@types/semver": "7.8.0", "@types/semver": "7.8.0",
"bun": "1.4.4", "bun": "1.4.5",
"typescript": "7.0.2" "typescript": "7.0.2"
}, },
"engines": { "engines": {
@@ -505,9 +505,9 @@
} }
}, },
"node_modules/@oven/bun-darwin-aarch64": { "node_modules/@oven/bun-darwin-aarch64": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-aarch64/-/bun-darwin-aarch64-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@oven/bun-darwin-aarch64/-/bun-darwin-aarch64-1.4.5.tgz",
"integrity": "sha512-zW/hxwc8sJAILGwB5eTC4i48ouGXf0V4lrxmEOk3JIE6JkYVW1TZh1E2pIempqsezgW1sckTIIDudFON8bJ2Mw==", "integrity": "sha512-4MIFXHmctH2EhAxLXm2/qxNtv17dFtLJylvaOCsrgq6KSqHTs6eW5YSrJjRbJxYUJaR901fsN8JfZOa+CsWpWQ==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -519,9 +519,9 @@
] ]
}, },
"node_modules/@oven/bun-darwin-x64": { "node_modules/@oven/bun-darwin-x64": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64/-/bun-darwin-x64-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64/-/bun-darwin-x64-1.4.5.tgz",
"integrity": "sha512-oKGcxLsvh4oHjAo28nPm8c/xN0o/OmGyj1IHYc94vprkWsW2hNg2keEZt5f40cI5Hvu4jDlSRTR0UNpv1UIAxw==", "integrity": "sha512-qkLPMGHZM9NI6CeHTWwVezzmlo6cC4Ta7yUAjYIWXS366qQcOlcp75t2uZyiuVRBMPS0h9qE0tCcvCHGaFqjJg==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -533,9 +533,9 @@
] ]
}, },
"node_modules/@oven/bun-freebsd-aarch64": { "node_modules/@oven/bun-freebsd-aarch64": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@oven/bun-freebsd-aarch64/-/bun-freebsd-aarch64-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@oven/bun-freebsd-aarch64/-/bun-freebsd-aarch64-1.4.5.tgz",
"integrity": "sha512-klvA9FlwLxZj3JYIOPQA4bbnHIC3uas8kBE4GaGGkeVgAQP/k8hAzYkOqkSaqHBDbxLrTyFEQArEAevJq6NJzg==", "integrity": "sha512-limWGUkd7wNKh9X/KJa4RyPMTdZsI+sqs7KmAWc/zFllRe5BSlN71ZfAVSYDDJMUJUQUvDdAMywH5zYkYrfUzQ==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -547,9 +547,9 @@
] ]
}, },
"node_modules/@oven/bun-freebsd-x64": { "node_modules/@oven/bun-freebsd-x64": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@oven/bun-freebsd-x64/-/bun-freebsd-x64-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@oven/bun-freebsd-x64/-/bun-freebsd-x64-1.4.5.tgz",
"integrity": "sha512-sF1xS/scbyN94P2d0eTiarO6JHxrIvhZNT9hnWjQXW5nwKRtfuP+UYnIMNyvW1BQPcZFP/cvfLBNUIe1ea4zPA==", "integrity": "sha512-LahCo0mJJzscE0PUKO8FXdFiOc2vqt9zhf35gSFAVemeCn88idDWpp/rhNcnEsHWMhf5GMXxGJA5D9deTmzW1g==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -561,9 +561,9 @@
] ]
}, },
"node_modules/@oven/bun-linux-aarch64": { "node_modules/@oven/bun-linux-aarch64": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64/-/bun-linux-aarch64-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64/-/bun-linux-aarch64-1.4.5.tgz",
"integrity": "sha512-ZTVtpf9zmHSBVPX1sBwe5agGb/rN34yPGg/Hby8e2Ax2uCUA2URZKlZH7qLntK7qaFJCMXh9v0GWNYN2zINz1w==", "integrity": "sha512-4BXmsSKnjOrlGWqZV4x/oWa7AVoR+B6lCXddMzOAXBIm3t50eslg9wb66gmtW1AamEQ1l1CDvmmruysEhqOWMg==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -575,9 +575,9 @@
] ]
}, },
"node_modules/@oven/bun-linux-aarch64-android": { "node_modules/@oven/bun-linux-aarch64-android": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64-android/-/bun-linux-aarch64-android-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64-android/-/bun-linux-aarch64-android-1.4.5.tgz",
"integrity": "sha512-5lvn3at5vRC0GxvmiqEiV2/e23tnRi0q5pzR40yfDvDA3OW7PSkt4chF1nA9vnAJhro4/l+ol1FmNP6D3cf/oA==", "integrity": "sha512-SI502JpXyu6em6y8E3F48GO3LwjYXSG3DWEOPhf9LXJWjjnPG9OwrWajtM91saa2vAixZ0ErlZa8UzNORcgcyQ==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -589,9 +589,9 @@
] ]
}, },
"node_modules/@oven/bun-linux-aarch64-musl": { "node_modules/@oven/bun-linux-aarch64-musl": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64-musl/-/bun-linux-aarch64-musl-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64-musl/-/bun-linux-aarch64-musl-1.4.5.tgz",
"integrity": "sha512-QFd0P+mHJxbZFbUla4MgiE5OwxysHaUIYxL2pPNkpWtaI7v4ShOpr8OhBmsuyB0xn5rv/ZJnPsj2y8+bB9+g/A==", "integrity": "sha512-XCNc+WvvMAdNNb+OWTogpy+N9wm62fkVeEVLb6how0RZhW5LPi6c7BlkeVCuWps7XjEl2saFpHFa20/1E+PAHg==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -603,9 +603,9 @@
] ]
}, },
"node_modules/@oven/bun-linux-x64": { "node_modules/@oven/bun-linux-x64": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64/-/bun-linux-x64-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64/-/bun-linux-x64-1.4.5.tgz",
"integrity": "sha512-CHbbkmHVM28T1GFq+6GL4Ao4ujwwYwj1CxFFwEFzLanPfNsId9AhbIP0Q4reWuWBkGimUkoQygrK7Rgjtj3vog==", "integrity": "sha512-IWX9BELoGHAUtMonkeSaNaZwXzRk+oDw6Mk+HBFXd3KHYIBNBsIGRupMZPcgNoDbJpLu6gAJjIoIVPZtt1aJ1g==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -617,9 +617,9 @@
] ]
}, },
"node_modules/@oven/bun-linux-x64-android": { "node_modules/@oven/bun-linux-x64-android": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-android/-/bun-linux-x64-android-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-android/-/bun-linux-x64-android-1.4.5.tgz",
"integrity": "sha512-3dMicj9C1DhaIfDkwt/9GtpU0W+q+GazbG9OIlEyL3Q1BBEz2e6ZRz/JiO8D/ECC0caXAqvnpFudehcLlgIwWQ==", "integrity": "sha512-81X3/qn9v18bHHIHfkGikQ/KztJTJpo6GMuqtwKm/jHMQy+Z8JpjIfxdaYocxeiRwgQhBXlby2HTKPvMyEjsOg==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -631,9 +631,9 @@
] ]
}, },
"node_modules/@oven/bun-linux-x64-musl": { "node_modules/@oven/bun-linux-x64-musl": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-musl/-/bun-linux-x64-musl-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-musl/-/bun-linux-x64-musl-1.4.5.tgz",
"integrity": "sha512-lEEjNOJJrbGZu2NVcPI4uXdILcpspezWkA8R/Jr0RCGhM6zQd0Y7JBIIKNAmbX59EeWpeEz7Q78iLbpcAUypUA==", "integrity": "sha512-10QoW/YfTgnURaGEaHpJCiXjLI2e5iTtfVDaA5JKcyUzaa1cq6cVUY9/Uq5XkYzvtRjHLRe9Oj/lTDIQcxy8HQ==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -645,9 +645,9 @@
] ]
}, },
"node_modules/@oven/bun-windows-aarch64": { "node_modules/@oven/bun-windows-aarch64": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@oven/bun-windows-aarch64/-/bun-windows-aarch64-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@oven/bun-windows-aarch64/-/bun-windows-aarch64-1.4.5.tgz",
"integrity": "sha512-n0ep5ZRPCZY1+dqFJpnnRUZB1wy4GYU6At8RF+pyzySCLjkN9R4rFh2PtBHAgF/lg1vOl3/CeER3pDM+p40ATA==", "integrity": "sha512-MiPFZnBNDnBXgr1oONc5pizC4fOLjnIOfNkYdFEnWzLmoFTg86naZIG3SvS7d/GglpQSAnCKMAzSjI/TAckiRw==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -659,9 +659,9 @@
] ]
}, },
"node_modules/@oven/bun-windows-x64": { "node_modules/@oven/bun-windows-x64": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@oven/bun-windows-x64/-/bun-windows-x64-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@oven/bun-windows-x64/-/bun-windows-x64-1.4.5.tgz",
"integrity": "sha512-a3LNctBVO8PjePsFZfwDleF2JXYf2BfQ1u/PLRnBDLnC2Riml+4+LgJpKj4xRGhB92KweGyQI5PXaTkP9qypMQ==", "integrity": "sha512-FNvply651vcE/GHgNWz6mZvhmkwBuu8Hw54oNzA+CQog+HW+542rXQmZqNHRkFxazD9L3xi+iTtvO3engAgJfw==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -685,13 +685,13 @@
"license": "Apache-2.0" "license": "Apache-2.0"
}, },
"node_modules/@types/bun": { "node_modules/@types/bun": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/@types/bun/-/bun-1.4.4.tgz", "resolved": "https://registry.npmjs.org/@types/bun/-/bun-1.4.5.tgz",
"integrity": "sha512-9wkRDXUXK124pEnAutE6n/l18j+i9GC5IAHK8TmX/2nlySETmky0OU6yL5U8pW1AoKh++AN9auDCr647BfurjQ==", "integrity": "sha512-DpgwNI9z0L1S0gtb45QLCWgwCUcMLnsHYMJHQvpNj7erGiCGBvpggltAIeARrtobNMKMuy0UP7i56tKKgwFs/Q==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"bun-types": "1.4.4" "bun-types": "1.4.5"
} }
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
@@ -1267,9 +1267,9 @@
} }
}, },
"node_modules/bun": { "node_modules/bun": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/bun/-/bun-1.4.4.tgz", "resolved": "https://registry.npmjs.org/bun/-/bun-1.4.5.tgz",
"integrity": "sha512-hj0ASdG6PNjLZGFAXktWb3Uaj/dcv/1wCsIttoEXADNIQBsGjTr+5uLKYbrDkuc7NT0Tkj4yPIqJI2jDxXdvVg==", "integrity": "sha512-SWOAncfhwiqIyaZ3uyuUD/6o8aWbG8QtU6SChlz4u6U/C89gTZafLDCmbUvyNjx+ccxLLHV+lSsWqE1OBN8bBw==",
"cpu": [ "cpu": [
"arm64", "arm64",
"x64" "x64"
@@ -1289,24 +1289,24 @@
"bunx": "bin/bunx.exe" "bunx": "bin/bunx.exe"
}, },
"optionalDependencies": { "optionalDependencies": {
"@oven/bun-darwin-aarch64": "1.4.4", "@oven/bun-darwin-aarch64": "1.4.5",
"@oven/bun-darwin-x64": "1.4.4", "@oven/bun-darwin-x64": "1.4.5",
"@oven/bun-freebsd-aarch64": "1.4.4", "@oven/bun-freebsd-aarch64": "1.4.5",
"@oven/bun-freebsd-x64": "1.4.4", "@oven/bun-freebsd-x64": "1.4.5",
"@oven/bun-linux-aarch64": "1.4.4", "@oven/bun-linux-aarch64": "1.4.5",
"@oven/bun-linux-aarch64-android": "1.4.4", "@oven/bun-linux-aarch64-android": "1.4.5",
"@oven/bun-linux-aarch64-musl": "1.4.4", "@oven/bun-linux-aarch64-musl": "1.4.5",
"@oven/bun-linux-x64": "1.4.4", "@oven/bun-linux-x64": "1.4.5",
"@oven/bun-linux-x64-android": "1.4.4", "@oven/bun-linux-x64-android": "1.4.5",
"@oven/bun-linux-x64-musl": "1.4.4", "@oven/bun-linux-x64-musl": "1.4.5",
"@oven/bun-windows-aarch64": "1.4.4", "@oven/bun-windows-aarch64": "1.4.5",
"@oven/bun-windows-x64": "1.4.4" "@oven/bun-windows-x64": "1.4.5"
} }
}, },
"node_modules/bun-types": { "node_modules/bun-types": {
"version": "1.4.4", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.4.4.tgz", "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.4.5.tgz",
"integrity": "sha512-yjrJh5oGX7mMPKGd19YXyIjmEuj4G4zNC30bs7PM9Az7NQ3ndF3j6hbeRdvJTRQEhJ/FYQwW0a2moweEi2hMxQ==", "integrity": "sha512-ECHn+9dhL3wv0G6u0+7dQvrnaimXiRDxxerYBmhTaLyJEEuvTPWk2Fye3XIf5Y++JIIiHKfQw4Z7V5D8KuiXbg==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
+4 -3
View File
@@ -1,6 +1,6 @@
{ {
"name": "tradingagents", "name": "tradingagents",
"version": "1.0.0", "version": "1.0.1",
"private": true, "private": true,
"description": "TradingAgents: Towards Agentic Finance Research", "description": "TradingAgents: Towards Agentic Finance Research",
"license": "Apache-2.0", "license": "Apache-2.0",
@@ -15,6 +15,7 @@
"dist" "dist"
], ],
"scripts": { "scripts": {
"ci:install": "npm ci --ignore-scripts && node node_modules/bun/install.js",
"build": "tsc -p tsconfig.build.json", "build": "tsc -p tsconfig.build.json",
"compile": "npm run build && bun scripts/compile.ts", "compile": "npm run build && bun scripts/compile.ts",
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p scripts/tsconfig.json", "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p scripts/tsconfig.json",
@@ -23,12 +24,12 @@
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "2.6.8", "@biomejs/biome": "2.6.8",
"@types/bun": "1.4.4", "@types/bun": "1.4.5",
"@types/node": "22.20.5", "@types/node": "22.20.5",
"@types/pdfkit": "0.17.7", "@types/pdfkit": "0.17.7",
"@types/react": "19.3.0", "@types/react": "19.3.0",
"@types/semver": "7.8.0", "@types/semver": "7.8.0",
"bun": "1.4.4", "bun": "1.4.5",
"typescript": "7.0.2" "typescript": "7.0.2"
}, },
"dependencies": { "dependencies": {
+14 -11
View File
@@ -347,20 +347,23 @@ export async function runAgent(
} }
/** /**
* The run's answer: what it wrote after its last research call (data, compute or an agent), in order. Text * The run's answer: what it wrote after its last tool call, as the prompt says; text beside a call is
* written beside bookkeeping calls only (a decision recorded, the plan updated) after that call belongs to * progress. A run that wrote nothing after it (its report beside a bookkeeping call, such as a decision
* the answer; text beside a research call was written before the results it waited for, so it does not. * recorded) answers with what it wrote after its last research call (data, compute or an agent), in order.
*/ */
function answerOf(messages: readonly Message[], registry: Pick<ToolRegistry, "kindOf">): string { function answerOf(messages: readonly Message[], registry: Pick<ToolRegistry, "kindOf">): string {
const researched = (message: Message) => const calls = (research: boolean) => (message: Message) =>
message.role === "assistant" && message.role === "assistant" &&
message.parts.some((part) => part.type === "tool-call" && registry.kindOf(part.name) !== "control"); message.parts.some(
const last = messages.findLastIndex(researched); (part) => part.type === "tool-call" && (!research || registry.kindOf(part.name) !== "control"),
return messages );
.slice(last + 1) const textAfter = (index: number) =>
.flatMap((message) => (message.role === "assistant" ? message.parts : [])) messages
.flatMap((part) => (part.type === "text" && part.text.trim() ? [part.text.trim()] : [])) .slice(index + 1)
.join("\n\n"); .flatMap((message) => (message.role === "assistant" ? message.parts : []))
.flatMap((part) => (part.type === "text" && part.text.trim() ? [part.text.trim()] : []))
.join("\n\n");
return textAfter(messages.findLastIndex(calls(false))) || textAfter(messages.findLastIndex(calls(true)));
} }
/** /**
+15
View File
@@ -4,6 +4,21 @@
import type { VersionNotes } from "./whats-new.js"; import type { VersionNotes } from "./whats-new.js";
export const CHANGELOG: readonly VersionNotes[] = [ export const CHANGELOG: readonly VersionNotes[] = [
{
"version": "1.0.1",
"sections": [
{
"items": [
"A plan's report asks the question the planning started from; replies added while planning follow it in the PDF.",
"A report opens with the answer, without the progress notes written along the way.",
"Price history reads two, three and five years.",
"A year of price history that spans February 29 is no longer refused.",
"Storing a key names the provider's API key (for example, \"Stored the Tauric API key\").",
"A correlation of returns needs at least three returns (four shared dates); over three dates it reported a perfect +1 or -1."
]
}
]
},
{ {
"version": "1.0.0", "version": "1.0.0",
"sections": [ "sections": [
+20 -16
View File
@@ -81,7 +81,7 @@ export function uncovered(report: Report): number {
const texts = [ const texts = [
report.title, report.title,
report.question, report.question,
report.earlier ?? "", ...report.added,
...report.sources, ...report.sources,
...partTexts(report.parts), ...partTexts(report.parts),
]; ];
@@ -336,17 +336,19 @@ export async function reportPdf(report: Report): Promise<Uint8Array> {
); );
doc.y += 14; doc.y += 14;
// The question (after the one before it, when that one's plan may be what it carries out), set off in a // The question (then what was added to it while planning, under one label), set off in a panel; a
// panel; a question too long for a page runs on without the panel. // question too long for a page runs on without the panel.
const asked = [ const asked = [
...(report.earlier ? [{ label: message("report.earlier"), text: report.earlier }] : []),
{ label: message("report.question"), text: report.question }, { label: message("report.question"), text: report.question },
...report.added.map((text, i) => ({ label: i ? "" : message("report.added"), text })),
].filter((entry) => entry.text); ].filter((entry) => entry.text);
if (asked.length) { if (asked.length) {
const inner = width - 28; const inner = width - 28;
const heights = asked.map(({ text }) => { const heights = asked.map(({ label, text }) => {
doc.font("regular").fontSize(BODY); doc.font("regular").fontSize(BODY);
return doc.heightOfString(text, { width: inner, lineGap: LINE_GAP, features: FEATURES }) + 11; return (
doc.heightOfString(text, { width: inner, lineGap: LINE_GAP, features: FEATURES }) + (label ? 11 : 0)
);
}); });
const height = heights.reduce((sum, each) => sum + each, 0) + 6 * (asked.length - 1) + 19; const height = heights.reduce((sum, each) => sum + each, 0) + 6 * (asked.length - 1) + 19;
const panel = height <= bottom() - MARGIN; const panel = height <= bottom() - MARGIN;
@@ -355,16 +357,18 @@ export async function reportPdf(report: Report): Promise<Uint8Array> {
if (panel) doc.save().rect(left, top, width, height).fill(PANEL).restore(); if (panel) doc.save().rect(left, top, width, height).fill(PANEL).restore();
doc.y = top + 9; doc.y = top + 9;
for (const { label, text } of asked) { for (const { label, text } of asked) {
doc if (label) {
.font("bold") doc
.fontSize(6.5) .font("bold")
.fillColor(MUTED) .fontSize(6.5)
.text(label.toUpperCase(), left + 14, doc.y, { .fillColor(MUTED)
characterSpacing: 1, .text(label.toUpperCase(), left + 14, doc.y, {
lineBreak: false, characterSpacing: 1,
features: FEATURES, lineBreak: false,
}); features: FEATURES,
doc.y += 11; });
doc.y += 11;
}
paragraph([{ text }], left + 14, inner, BODY, INK); paragraph([{ text }], left + 14, inner, BODY, INK);
doc.y += 6; doc.y += 6;
} }
+21 -11
View File
@@ -11,12 +11,10 @@ import { type Part, type Run, reportParts } from "./layout.js";
export type Report = { export type Report = {
title: string; title: string;
/** For an answer to a plan, or one that ran it as proposed: the question the planning started from. */
question: string; question: string;
/** /** What the person added while planning, in the order said: the replies in plan mode after the question. */
* The question asked just before in plan mode, when this one was asked in plan mode too or ran its plan added: string[];
* as proposed: the answer may carry out the plan that one got, so the reader sees what it was.
*/
earlier?: string;
/** When the answer was written, as an ISO time. */ /** When the answer was written, as an ISO time. */
at: string; at: string;
model: string; model: string;
@@ -28,7 +26,7 @@ export type Report = {
/** /**
* The last completed turn of `session` in `done` as a report, or undefined when it has none with an answer. * The last completed turn of `session` in `done` as a report, or undefined when it has none with an answer.
* The title is the answer's opening heading when it has one. `model` stands in when the turn did not say. * The question of a plan is the one the planning started from, not the reply that ran it. The title is the answer's opening heading when it has one. `model` stands in when the turn did not say.
*/ */
export function lastReport( export function lastReport(
done: readonly Block[], done: readonly Block[],
@@ -39,16 +37,14 @@ export function lastReport(
); );
const last = turns.at(-1); const last = turns.at(-1);
if (!last?.answer.trim()) return undefined; if (!last?.answer.trim()) return undefined;
const before = turns.at(-2); const [asked, ...added] = planning(turns);
const parts = reportParts(last.answer); const parts = reportParts(last.answer);
const [first, ...rest] = parts; const [first, ...rest] = parts;
const titled = first?.kind === "heading"; const titled = first?.kind === "heading";
return { return {
title: titled ? textOf(first.runs) : message("report.title"), title: titled ? textOf(first.runs) : message("report.title"),
question: printable(last.question).trim(), question: printable((asked ?? last).question).trim(),
...(before?.plan && (last.plan || last.question === message("app.runPlan")) added: added.map((turn) => printable(turn.question).trim()).filter(Boolean),
? { earlier: printable(before.question).trim() }
: {}),
at: last.at, at: last.at,
model: printable(last.model ?? model), model: printable(last.model ?? model),
version: printable(version), version: printable(version),
@@ -57,6 +53,20 @@ export function lastReport(
}; };
} }
/**
* The turns a plan was made in, when the last of `turns` answered in plan mode or ran the plan as proposed:
* the plan-mode turns up to it (the run itself left out), in order. Otherwise none.
*/
function planning(turns: readonly Answered[]): Answered[] {
const last = turns.at(-1);
const ran = !last?.plan && last?.question === message("app.runPlan");
if (!last?.plan && !ran) return [];
const end = ran ? turns.length - 1 : turns.length;
let start = end;
while (start > 0 && turns[start - 1]?.plan) start--;
return turns.slice(start, end);
}
function textOf(runs: readonly Run[]): string { function textOf(runs: readonly Run[]): string {
return runs return runs
.map((run) => run.text) .map((run) => run.text)
+23 -13
View File
@@ -195,6 +195,8 @@ const BOOKKEEPING = new Set(["update_plan", "use_skill", ASK_TOOL]);
const MEMORY = new Set(["recall_memory", "save_note", "record_decision"]); const MEMORY = new Set(["recall_memory", "save_note", "record_decision"]);
/** A call that researches (data, compute, an agent), as against keeping the books: what an answer follows. */ /** A call that researches (data, compute, an agent), as against keeping the books: what an answer follows. */
const researches = (name: string) => !BOOKKEEPING.has(name) && !MEMORY.has(name) && name !== "evidence"; const researches = (name: string) => !BOOKKEEPING.has(name) && !MEMORY.has(name) && name !== "evidence";
/** Steps' text joined as the engine joins an answer's: the ones with text, a blank line between. */
const joined = (...texts: string[]) => texts.filter((text) => text.trim()).join("\n\n");
/** The state once `run` has gone on after a retry: what said it was being asked for again is gone. */ /** The state once `run` has gone on after a retry: what said it was being asked for again is gone. */
function resumed(state: TranscriptState, isMain: boolean, run: string): TranscriptState { function resumed(state: TranscriptState, isMain: boolean, run: string): TranscriptState {
@@ -282,8 +284,9 @@ export type TranscriptState = {
* text of its steps. * text of its steps.
*/ */
/** /**
* `stepText`: the step under way; `sinceResearch`: what the finished steps wrote since the main agent's * `stepText`: the step under way; `sinceCall` and `sinceResearch`: what the finished steps wrote since the
* last research call, which the turn's answer is made of. * main agent's last call and its last research call. The turn's answer is the first, or the second when
* the first is empty, as the engine makes it.
*/ */
/** `worked`: the main agent carried research out (computed, or ran an agent) in this turn. */ /** `worked`: the main agent carried research out (computed, or ran an agent) in this turn. */
turn: { turn: {
@@ -292,6 +295,7 @@ export type TranscriptState = {
asked?: true; asked?: true;
worked?: true; worked?: true;
stepText: string; stepText: string;
sinceCall: string;
sinceResearch: string; sinceResearch: string;
}; };
/** The app wrote the question it just sent: the next `turn.started` does not write it again. */ /** The app wrote the question it just sent: the next `turn.started` does not write it again. */
@@ -346,7 +350,7 @@ export const emptyTranscript: TranscriptState = {
delegated: [], delegated: [],
titles: {}, titles: {},
}, },
turn: { question: "", stepText: "", sinceResearch: "" }, turn: { question: "", stepText: "", sinceCall: "", sinceResearch: "" },
citations: { recorded: [], cited: [] }, citations: { recorded: [], cited: [] },
status: { turnActive: false }, status: { turnActive: false },
}; };
@@ -726,6 +730,7 @@ export function reduceTranscript(
question: event.question, question: event.question,
...(event.mode === "plan" ? { plan: true as const } : {}), ...(event.mode === "plan" ? { plan: true as const } : {}),
stepText: "", stepText: "",
sinceCall: "",
sinceResearch: "", sinceResearch: "",
}, },
citations: { recorded: written.citations.recorded, cited: [] }, citations: { recorded: written.citations.recorded, cited: [] },
@@ -775,16 +780,18 @@ export function reduceTranscript(
turn: { turn: {
...state.turn, ...state.turn,
stepText: "", stepText: "",
sinceResearch: [state.turn.sinceResearch, state.turn.stepText] sinceCall: joined(state.turn.sinceCall, state.turn.stepText),
.filter((t) => t.trim()) sinceResearch: joined(state.turn.sinceResearch, state.turn.stepText),
.join("\n\n"),
}, },
} }
: state; : state;
case "tool.called": { case "tool.called": {
// The main agent acting ends its thinking; its data calls join the step's batch. A research call // The main agent acting ends its thinking; its data calls join the step's batch. A call follows the
// follows the step that made it: what that step and those before wrote is not the answer. // step that made it: what that step and those before wrote is not the answer.
if (isMain && researches(event.name)) state = { ...state, turn: { ...state.turn, sinceResearch: "" } }; if (isMain) {
const sinceResearch = researches(event.name) ? "" : state.turn.sinceResearch;
state = { ...state, turn: { ...state.turn, sinceCall: "", sinceResearch } };
}
if (isMain && carriesOut(event)) state = { ...state, turn: { ...state.turn, worked: true } }; if (isMain && carriesOut(event)) state = { ...state, turn: { ...state.turn, worked: true } };
if (isMain) { if (isMain) {
state = closeThought(state, id, envelope.ts); state = closeThought(state, id, envelope.ts);
@@ -1046,10 +1053,13 @@ export function reduceTranscript(
case "usage.updated": case "usage.updated":
return { ...state, status: { ...state.status, usage: event.usage } }; return { ...state, status: { ...state.status, usage: event.usage } };
case "turn.completed": { case "turn.completed": {
// The answer is what was written since the last research call, the step under way included when a // The answer is what was written since the last call, or since the last research call when nothing
// turn ends without a closing step event; shown already when it was all streamed. A turn that asked // was, the step under way included when a turn ends without a closing step event; shown already when
// ends with its questions, which the question step shows: only what the model wrote is shown here. // it was all streamed. A turn that asked ends with its questions, which the question step shows: only
const written = [state.turn.sinceResearch, state.turn.stepText].filter((t) => t.trim()).join("\n\n"); // what the model wrote is shown here.
const written =
joined(state.turn.sinceCall, state.turn.stepText) ||
joined(state.turn.sinceResearch, state.turn.stepText);
const streamed = event.answer.replace(/\s+/g, "") === written.replace(/\s+/g, ""); const streamed = event.answer.replace(/\s+/g, "") === written.replace(/\s+/g, "");
const flushed = flushText(closeThought(state, id, envelope.ts), id); const flushed = flushText(closeThought(state, id, envelope.ts), id);
// The engine's numbering, for an answer not streamed and for the list of what it cited. // The engine's numbering, for an answer not streamed and for the list of what it cited.
+5 -4
View File
@@ -29,11 +29,12 @@ export function correlate(
if ("error" in aligned) return aligned; if ("error" in aligned) return aligned;
const { columns, dates } = aligned; const { columns, dates } = aligned;
const observations = columns[0]?.length ?? 0; const observations = columns[0]?.length ?? 0;
if (observations < LEAST) { // The minimum counts what is correlated: returns are one fewer than the shared dates.
const points = of === "returns" ? Math.max(0, observations - 1) : observations;
if (points < LEAST) {
const who = series.length === 2 ? `${series[0]?.label} and ${series[1]?.label}` : "the series"; const who = series.length === 2 ? `${series[0]?.label} and ${series[1]?.label}` : "the series";
return { const shared = `${observations} ${dates ? "dates" : "values"}${of === "returns" ? `, so ${points} returns` : ""}`;
error: `${who} share ${observations} ${dates ? "dates" : "values"}; ${of} need at least ${LEAST}`, return { error: `${who} share ${shared}; a correlation needs at least ${LEAST}` };
};
} }
if (of === "returns") { if (of === "returns") {
const index = columns.findIndex((column) => column.some((value) => value <= 0)); const index = columns.findIndex((column) => column.some((value) => value <= 0));
+2
View File
@@ -60,6 +60,8 @@ export const CALLS = {
resultChars: 12_000, resultChars: 12_000,
/** Intraday bars one price_history page asks for: the most the source serves at once. */ /** Intraday bars one price_history page asks for: the most the source serves at once. */
intradayBars: 100, intradayBars: 100,
/** Days of daily bars, both ends counted, one Tauric request serves at most; a longer window is read in pieces. */
dailyWindowDays: 366,
/** Pages of 25 companies a sector screen reads at most: 500 companies, the largest sector. */ /** Pages of 25 companies a sector screen reads at most: 500 companies, the largest sector. */
screenPages: 20, screenPages: 20,
textChars: 10_000, textChars: 10_000,
+4 -3
View File
@@ -100,7 +100,8 @@ const catalog = {
"cli.nothingStoredBecause": ({ reason }: { reason: string }) => `Nothing stored: ${reason}`, "cli.nothingStoredBecause": ({ reason }: { reason: string }) => `Nothing stored: ${reason}`,
"cli.envKeyWins": ({ variable }: { variable: string }) => "cli.envKeyWins": ({ variable }: { variable: string }) =>
`${variable} is set and is used; the stored key is used once it is unset.`, `${variable} is set and is used; the stored key is used once it is unset.`,
"cli.keyStored": ({ name, path }: { name: string; path: string }) => `Stored the ${name} key in ${path}.`, "cli.keyStored": ({ name, path }: { name: string; path: string }) =>
`Stored the ${name === "model" ? "model server" : keyLabel(name)} API key in ${path}.`,
"cli.setup": ({ "cli.setup": ({
app, app,
baseUrlVar, baseUrlVar,
@@ -199,7 +200,7 @@ event odds from Polymarket; the rest is not available.
["/help for commands", "esc to stop"].join(separator), ["/help for commands", "esc to stop"].join(separator),
"report.title": () => "Research report", "report.title": () => "Research report",
"report.question": () => "Question", "report.question": () => "Question",
"report.earlier": () => "Earlier question", "report.added": () => "Added while planning",
"report.sources": () => "Sources", "report.sources": () => "Sources",
"report.written": ({ at }: { at: string }) => `${at.slice(0, 10)} ${at.slice(11, 16)} UTC`, "report.written": ({ at }: { at: string }) => `${at.slice(0, 10)} ${at.slice(11, 16)} UTC`,
"report.page": ({ page, count }: { page: number; count: number }) => `Page ${page} of ${count}`, "report.page": ({ page, count }: { page: number; count: number }) => `Page ${page} of ${count}`,
@@ -644,7 +645,7 @@ event odds from Polymarket; the rest is not available.
"session.signedOut": ({ app }: { app: string }) => `not signed in to ChatGPT: ${app} login chatgpt`, "session.signedOut": ({ app }: { app: string }) => `not signed in to ChatGPT: ${app} login chatgpt`,
"session.changedWhileOpening": () => "the session changed while it was being opened; open it again", "session.changedWhileOpening": () => "the session changed while it was being opened; open it again",
"config.noKey": ({ provider, vars, app }: { provider: string; vars: string; app: string }) => "config.noKey": ({ provider, vars, app }: { provider: string; vars: string; app: string }) =>
`the ${provider} model needs a key: set ${vars}, or store one with ${app} key ${provider}`, `the ${keyLabel(provider)} model needs an API key: set ${vars}, or store one with ${app} key ${provider}`,
"config.badReasoning": ({ where, levels }: { where: string; levels: string }) => "config.badReasoning": ({ where, levels }: { where: string; levels: string }) =>
`${where}: reasoning must be one of ${levels}`, `${where}: reasoning must be one of ${levels}`,
"config.keyForOtherServer": ({ endpoint, app }: { endpoint: string; app: string }) => "config.keyForOtherServer": ({ endpoint, app }: { endpoint: string; app: string }) =>
+1 -1
View File
@@ -10,7 +10,7 @@ export const APP_TITLE = "TradingAgents";
export const MAKER = "Tauric Research"; export const MAKER = "Tauric Research";
/** This build's version; a test keeps it equal to package.json's. */ /** This build's version; a test keeps it equal to package.json's. */
export const VERSION = "1.0.0"; export const VERSION = "1.0.1";
/** How this build names itself to the services it calls. */ /** How this build names itself to the services it calls. */
export const USER_AGENT = `${APP_NAME}/${VERSION}`; export const USER_AGENT = `${APP_NAME}/${VERSION}`;
+55 -8
View File
@@ -6,7 +6,7 @@
* translated into the capability contracts. * translated into the capability contracts.
*/ */
import { errorText } from "../../contracts/index.js"; import { addDays, errorText } from "../../contracts/index.js";
import { CALLS } from "../../contracts/limits.js"; import { CALLS } from "../../contracts/limits.js";
import type { import type {
Capability, Capability,
@@ -47,7 +47,19 @@ type Answer<M extends keyof TauricClient> = TauricClient[M] extends (...args: ne
: never; : never;
export function tauricProvider(client: TauricClient) { export function tauricProvider(client: TauricClient) {
// A window longer than Tauric serves at once is read in pieces, newest first, until it is covered or the
// source's history starts within a piece (an older piece would have nothing).
const daily = async (key: string, window: { from: string; to: string }, signal?: AbortSignal) => { const daily = async (key: string, window: { from: string; to: string }, signal?: AbortSignal) => {
const pieces: DailyBars[] = [];
for (const piece of piecesOf(window)) {
const answer = await dailyPiece(key, piece, signal);
pieces.push(answer);
const since = answer.coverage.history_from;
if (since && since >= piece.from) break;
}
return joined(pieces);
};
const dailyPiece = async (key: string, window: { from: string; to: string }, signal?: AbortSignal) => {
const { kind, id } = parseInstrument(key); const { kind, id } = parseInstrument(key);
const call = signal ? { signal } : {}; const call = signal ? { signal } : {};
const query = { interval: "1d" as const, start: window.from, end: window.to }; const query = { interval: "1d" as const, start: window.from, end: window.to };
@@ -140,13 +152,9 @@ export function tauricProvider(client: TauricClient) {
revision: REVISION[bar.status], revision: REVISION[bar.status],
...(Object.keys(bar.field_states).length ? { field_states: bar.field_states } : {}), ...(Object.keys(bar.field_states).length ? { field_states: bar.field_states } : {}),
})), })),
history_from: answer.coverage.history_from ?? null, history_from: coverage.history_from ?? null,
// A full page may have left earlier bars out; the next page ends just before its oldest bar. The // The bar just before the oldest one served; none at the start of the source's history.
// source's continue_end is not followed here: on intraday pages it can skip a session's first bars. earlier_end: coverage.continue_end ?? null,
earlier_end:
sorted.length >= limit && sorted[0]?.start
? new Date(Date.parse(sorted[0].start) - 1_000).toISOString()
: null,
}; };
}, },
// Both listings from this one source, or neither. // Both listings from this one source, or neither.
@@ -674,6 +682,45 @@ const REVISION = { settled: "final", unsettled: "provisional" } as const satisfi
DailyBar["revision"] DailyBar["revision"]
>; >;
/** `window` as windows Tauric serves, newest first, each ending the day before the one after it starts. */
function piecesOf({ from, to }: { from: string; to: string }): { from: string; to: string }[] {
const pieces: { from: string; to: string }[] = [];
for (let end = to; end >= from; ) {
const earliest = addDays(end, 1 - CALLS.dailyWindowDays);
const start = earliest > from ? earliest : from;
pieces.push({ from: start, to: end });
end = addDays(start, -1);
}
// A window that ends before it starts is asked as it is, for the source to answer.
return pieces.length ? pieces : [{ from, to }];
}
/**
* Pieces of one window, newest first, as one: their bars oldest first, the newest piece's instrument and
* basis, complete only when every piece is, and older bars continuing where the oldest piece says.
*/
function joined(pieces: readonly DailyBars[]): DailyBars {
const newest = pieces[0] as DailyBars;
if (pieces.length === 1) return newest;
const all = [...pieces].reverse();
const oldest = all[0] as DailyBars;
const dated = all.flatMap((piece) => piece.bars);
const completes = all.map((piece) => piece.coverage.complete);
return {
...newest,
bars: dated,
coverage: {
from: dated[0]?.date ?? null,
through: dated.at(-1)?.date ?? null,
complete: completes.includes(false) ? false : completes.includes(null) ? null : true,
complete_reason: all.find((piece) => piece.coverage.complete_reason)?.coverage.complete_reason ?? null,
history_from: all.find((piece) => piece.coverage.history_from)?.coverage.history_from ?? null,
missing_sessions: all.reduce((sum, piece) => sum + piece.coverage.missing_sessions, 0),
},
earlier_end: oldest.earlier_end,
};
}
/** Tauric's answer for the window asked: the bars in it and whether every session there is accounted for. */ /** Tauric's answer for the window asked: the bars in it and whether every session there is accounted for. */
function bars(answer: Bars, { from, to }: { from: string; to: string }): DailyBars { function bars(answer: Bars, { from, to }: { from: string; to: string }): DailyBars {
const within = (date: string) => date >= from && date <= to; const within = (date: string) => date >= from && date <= to;
+7 -5
View File
@@ -11,7 +11,7 @@ import { referenceTo } from "./references.js";
import { defineTool, type ToolAnswer, ToolRefusalError } from "./tool.js"; import { defineTool, type ToolAnswer, ToolRefusalError } from "./tool.js";
import { fieldNotes, instrument, instrumentLine, provenanceOf } from "./tool-text.js"; import { fieldNotes, instrument, instrumentLine, provenanceOf } from "./tool-text.js";
const PERIODS = ["5d", "1mo", "3mo", "6mo", "ytd", "1y"] as const; const PERIODS = ["5d", "1mo", "3mo", "6mo", "ytd", "1y", "2y", "3y", "5y"] as const;
/** Instrument types whose values are rates or yields. */ /** Instrument types whose values are rates or yields. */
const RATES = new Set(["rate"]); const RATES = new Set(["rate"]);
type Period = (typeof PERIODS)[number]; type Period = (typeof PERIODS)[number];
@@ -275,7 +275,8 @@ async function referenceRates(
/** /**
* The dates a period covers, ending at `to` (both inclusive), so every provider answers the same * The dates a period covers, ending at `to` (both inclusive), so every provider answers the same
* window: 5d is the 7 calendar days ending at `to`, months and a year count back by calendar, ytd * window: 5d is the 7 calendar days ending at `to`, months and years count back by calendar and start
* the day after the date they count back to (a year is 365 or 366 days, as Tauric serves at most), ytd
* starts on January 1 of `to`'s year. * starts on January 1 of `to`'s year.
*/ */
export function windowOf(period: Period, to: string): { from: string; to: string } { export function windowOf(period: Period, to: string): { from: string; to: string } {
@@ -284,10 +285,11 @@ export function windowOf(period: Period, to: string): { from: string; to: string
if (period === "5d") { if (period === "5d") {
return { from: new Date(Date.UTC(year, month - 1, date - 6)).toISOString().slice(0, 10), to }; return { from: new Date(Date.UTC(year, month - 1, date - 6)).toISOString().slice(0, 10), to };
} }
// The same day of an earlier month, or that month's last day when it is shorter (March 31 -> February 28). // The day after the same day of an earlier month, or after that month's last day when it is shorter
const back = { "1mo": 1, "3mo": 3, "6mo": 6, "1y": 12 }[period]; // (March 31 -> March 1).
const back = { "1mo": 1, "3mo": 3, "6mo": 6, "1y": 12, "2y": 24, "3y": 36, "5y": 60 }[period];
const lastDay = new Date(Date.UTC(year, month - 1 - back + 1, 0)).getUTCDate(); const lastDay = new Date(Date.UTC(year, month - 1 - back + 1, 0)).getUTCDate();
const from = new Date(Date.UTC(year, month - 1 - back, Math.min(date, lastDay))); const from = new Date(Date.UTC(year, month - 1 - back, Math.min(date, lastDay) + 1));
return { from: from.toISOString().slice(0, 10), to }; return { from: from.toISOString().slice(0, 10), to };
} }