cascade-ai 0.72.0 → 0.74.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/index.d.cts CHANGED
@@ -1797,6 +1797,33 @@ declare class CascadeRouter extends EventEmitter {
1797
1797
  private sessionCostUsd;
1798
1798
  private runTokens;
1799
1799
  private runCostUsd;
1800
+ /**
1801
+ * Budget held for calls that are IN FLIGHT — admitted by the preflight check
1802
+ * but not yet counted by recordStats. Without these, concurrent calls all
1803
+ * measure themselves against the same unspent allowance and are all admitted.
1804
+ * Released when each call settles; reset by beginRun() alongside the totals.
1805
+ */
1806
+ private reservedTokens;
1807
+ private reservedCostUsd;
1808
+ /**
1809
+ * Fires when this run's budget is spent, cancelling work already in flight.
1810
+ *
1811
+ * The kill switch was previously only a flag, which stops calls that have
1812
+ * not yet submitted. A parallel wave's earlier members are already at the
1813
+ * provider by then, and they carried on generating for a run whose output
1814
+ * would be discarded. Every provider call chains to this, so tripping the
1815
+ * ceiling reaches the requests that are running, not just the ones queued.
1816
+ */
1817
+ private runAbort;
1818
+ /**
1819
+ * Bumped by every beginRun(). A release handle remembers the generation it
1820
+ * was issued in and does nothing if that has moved on: beginRun() zeroes the
1821
+ * counters, so a call still in flight from the previous run would otherwise
1822
+ * subtract its estimate from the NEW run's totals and drive them negative —
1823
+ * leaving later preflights believing there is more allowance than the cap
1824
+ * actually holds, which is worse than no gate at all.
1825
+ */
1826
+ private runGeneration;
1800
1827
  private runBudgetExceeded;
1801
1828
  private runBudgetExceededReason;
1802
1829
  /**
@@ -2036,6 +2063,21 @@ declare class CascadeRouter extends EventEmitter {
2036
2063
  * Used to populate the desktop model pickers with the user's real models.
2037
2064
  */
2038
2065
  getAvailableModels(): ModelInfo[];
2066
+ /**
2067
+ * Why each configured provider failed its availability probe, kept so the
2068
+ * surfaces can say something better than "add an API key" to a user who
2069
+ * already has one. Cleared and refilled by each detectAvailableProviders().
2070
+ */
2071
+ private probeFailures;
2072
+ /**
2073
+ * What stopped the configured providers from being usable, if anything.
2074
+ * Empty when every configured provider passed — or when none was configured,
2075
+ * which is a different problem with a different answer.
2076
+ */
2077
+ providerProbeFailures(): Array<{
2078
+ provider: ProviderType;
2079
+ reason: string;
2080
+ }>;
2039
2081
  /** Logs why a configured provider failed its availability probe. */
2040
2082
  private emitProbeFailure;
2041
2083
  private detectAvailableProviders;
@@ -2046,6 +2088,13 @@ declare class CascadeRouter extends EventEmitter {
2046
2088
  private getProvider;
2047
2089
  private createProvider;
2048
2090
  private getAnyModelForProvider;
2091
+ /**
2092
+ * `runGeneration` is the generation the call was ADMITTED in — see
2093
+ * `generate()`. Session-wide accounting always applies (the spend is real
2094
+ * whenever it lands), but the per-RUN ceiling is only meaningful for the run
2095
+ * the call belongs to, so a straggler from a finished run is left out of it.
2096
+ * Omitted by the direct callers in tests, which have no run to straddle.
2097
+ */
2049
2098
  private recordStats;
2050
2099
  /**
2051
2100
  * Resets per-run accounting at the start of each `cascade run`. Session
@@ -2053,6 +2102,60 @@ declare class CascadeRouter extends EventEmitter {
2053
2102
  * per-task ceiling is cleared so the next task starts with a fresh allowance.
2054
2103
  */
2055
2104
  beginRun(): void;
2105
+ /**
2106
+ * Refuse a call whose input alone cannot fit what is left of the run budget.
2107
+ *
2108
+ * `enforceRunBudget()` below runs AFTER a call returns, which makes the caps
2109
+ * a stop rather than a pre-authorisation: the tokens are already bought by
2110
+ * the time it looks. That was tolerable while a prompt could not exceed
2111
+ * 20,000 characters, and stopped being so when that cap was removed in
2112
+ * 0.72.0 — a multi-megabyte prompt is billed in full on the very first call
2113
+ * (the complexity classifier sends the whole thing), and no ceiling
2114
+ * configured downstream can give that money back.
2115
+ *
2116
+ * Deliberately narrow, because a false refusal is worse than a late stop:
2117
+ *
2118
+ * • INPUT ONLY. What a call returns is not knowable in advance, and
2119
+ * charging a worst-case `maxTokens` of output against the budget would
2120
+ * decline runs that would have finished comfortably. Input is the part
2121
+ * that is already determined, and it is the part the removed cap used to
2122
+ * bound.
2123
+ * • Compared against what REMAINS (`cap - spent`), not the whole cap, so a
2124
+ * call is judged on the budget it can actually draw from.
2125
+ * • Skipped when the model has no usable price. An estimate cannot be made,
2126
+ * and refusing on ignorance would break every self-hosted and local model
2127
+ * the moment a cost cap is set. The post-hoc stop still applies there.
2128
+ * • Skipped entirely when no cap is configured — there is nothing to
2129
+ * pre-authorise against.
2130
+ *
2131
+ * The message names the cap AND the estimate, because "too expensive" with
2132
+ * no numbers gives the user nothing to change.
2133
+ */
2134
+ private enforcePreflightBudget;
2135
+ /**
2136
+ * What this call will send, in tokens.
2137
+ *
2138
+ * Text is the bulk of it, but not all of it: providers bill the serialized
2139
+ * TOOL DEFINITIONS on every native-tool call (Anthropic sends each name,
2140
+ * description and input schema), and an image is billed by its own size
2141
+ * rather than as the `[image]` placeholder `contentToText` reduces it to. A
2142
+ * tool-heavy or vision request could therefore pass either cap while its real
2143
+ * input already exceeded the allowance.
2144
+ */
2145
+ private estimateInputTokens;
2146
+ /**
2147
+ * Report a wait that ended because something asked it to stop, the same way
2148
+ * the provider call below reports one.
2149
+ *
2150
+ * The queue waits sit OUTSIDE the try/catch that maps aborts, so without
2151
+ * this a cancellation surfaced as whatever the queue happened to throw and
2152
+ * was retried or failed over like an ordinary error. A budget abort keeps
2153
+ * saying it ran out of budget — otherwise the reason the run stopped is lost
2154
+ * on the way up — and anything else that was aborted becomes a cancellation.
2155
+ */
2156
+ private asAbortFailure;
2157
+ /** Trips the same run-level flag a post-hoc overrun does, and reports it the same way. */
2158
+ private failPreflight;
2056
2159
  /**
2057
2160
  * Enforce the hard per-task ceiling. Once tripped, the flag makes every
2058
2161
  * subsequent (and concurrent) generate() call in this run fail fast.
@@ -3043,6 +3146,7 @@ interface BroadcastMessage {
3043
3146
  timestamp: string;
3044
3147
  }
3045
3148
  declare class PeerBus extends EventEmitter {
3149
+ constructor();
3046
3150
  private outputs;
3047
3151
  private waiters;
3048
3152
  private members;
package/dist/index.d.ts CHANGED
@@ -1797,6 +1797,33 @@ declare class CascadeRouter extends EventEmitter {
1797
1797
  private sessionCostUsd;
1798
1798
  private runTokens;
1799
1799
  private runCostUsd;
1800
+ /**
1801
+ * Budget held for calls that are IN FLIGHT — admitted by the preflight check
1802
+ * but not yet counted by recordStats. Without these, concurrent calls all
1803
+ * measure themselves against the same unspent allowance and are all admitted.
1804
+ * Released when each call settles; reset by beginRun() alongside the totals.
1805
+ */
1806
+ private reservedTokens;
1807
+ private reservedCostUsd;
1808
+ /**
1809
+ * Fires when this run's budget is spent, cancelling work already in flight.
1810
+ *
1811
+ * The kill switch was previously only a flag, which stops calls that have
1812
+ * not yet submitted. A parallel wave's earlier members are already at the
1813
+ * provider by then, and they carried on generating for a run whose output
1814
+ * would be discarded. Every provider call chains to this, so tripping the
1815
+ * ceiling reaches the requests that are running, not just the ones queued.
1816
+ */
1817
+ private runAbort;
1818
+ /**
1819
+ * Bumped by every beginRun(). A release handle remembers the generation it
1820
+ * was issued in and does nothing if that has moved on: beginRun() zeroes the
1821
+ * counters, so a call still in flight from the previous run would otherwise
1822
+ * subtract its estimate from the NEW run's totals and drive them negative —
1823
+ * leaving later preflights believing there is more allowance than the cap
1824
+ * actually holds, which is worse than no gate at all.
1825
+ */
1826
+ private runGeneration;
1800
1827
  private runBudgetExceeded;
1801
1828
  private runBudgetExceededReason;
1802
1829
  /**
@@ -2036,6 +2063,21 @@ declare class CascadeRouter extends EventEmitter {
2036
2063
  * Used to populate the desktop model pickers with the user's real models.
2037
2064
  */
2038
2065
  getAvailableModels(): ModelInfo[];
2066
+ /**
2067
+ * Why each configured provider failed its availability probe, kept so the
2068
+ * surfaces can say something better than "add an API key" to a user who
2069
+ * already has one. Cleared and refilled by each detectAvailableProviders().
2070
+ */
2071
+ private probeFailures;
2072
+ /**
2073
+ * What stopped the configured providers from being usable, if anything.
2074
+ * Empty when every configured provider passed — or when none was configured,
2075
+ * which is a different problem with a different answer.
2076
+ */
2077
+ providerProbeFailures(): Array<{
2078
+ provider: ProviderType;
2079
+ reason: string;
2080
+ }>;
2039
2081
  /** Logs why a configured provider failed its availability probe. */
2040
2082
  private emitProbeFailure;
2041
2083
  private detectAvailableProviders;
@@ -2046,6 +2088,13 @@ declare class CascadeRouter extends EventEmitter {
2046
2088
  private getProvider;
2047
2089
  private createProvider;
2048
2090
  private getAnyModelForProvider;
2091
+ /**
2092
+ * `runGeneration` is the generation the call was ADMITTED in — see
2093
+ * `generate()`. Session-wide accounting always applies (the spend is real
2094
+ * whenever it lands), but the per-RUN ceiling is only meaningful for the run
2095
+ * the call belongs to, so a straggler from a finished run is left out of it.
2096
+ * Omitted by the direct callers in tests, which have no run to straddle.
2097
+ */
2049
2098
  private recordStats;
2050
2099
  /**
2051
2100
  * Resets per-run accounting at the start of each `cascade run`. Session
@@ -2053,6 +2102,60 @@ declare class CascadeRouter extends EventEmitter {
2053
2102
  * per-task ceiling is cleared so the next task starts with a fresh allowance.
2054
2103
  */
2055
2104
  beginRun(): void;
2105
+ /**
2106
+ * Refuse a call whose input alone cannot fit what is left of the run budget.
2107
+ *
2108
+ * `enforceRunBudget()` below runs AFTER a call returns, which makes the caps
2109
+ * a stop rather than a pre-authorisation: the tokens are already bought by
2110
+ * the time it looks. That was tolerable while a prompt could not exceed
2111
+ * 20,000 characters, and stopped being so when that cap was removed in
2112
+ * 0.72.0 — a multi-megabyte prompt is billed in full on the very first call
2113
+ * (the complexity classifier sends the whole thing), and no ceiling
2114
+ * configured downstream can give that money back.
2115
+ *
2116
+ * Deliberately narrow, because a false refusal is worse than a late stop:
2117
+ *
2118
+ * • INPUT ONLY. What a call returns is not knowable in advance, and
2119
+ * charging a worst-case `maxTokens` of output against the budget would
2120
+ * decline runs that would have finished comfortably. Input is the part
2121
+ * that is already determined, and it is the part the removed cap used to
2122
+ * bound.
2123
+ * • Compared against what REMAINS (`cap - spent`), not the whole cap, so a
2124
+ * call is judged on the budget it can actually draw from.
2125
+ * • Skipped when the model has no usable price. An estimate cannot be made,
2126
+ * and refusing on ignorance would break every self-hosted and local model
2127
+ * the moment a cost cap is set. The post-hoc stop still applies there.
2128
+ * • Skipped entirely when no cap is configured — there is nothing to
2129
+ * pre-authorise against.
2130
+ *
2131
+ * The message names the cap AND the estimate, because "too expensive" with
2132
+ * no numbers gives the user nothing to change.
2133
+ */
2134
+ private enforcePreflightBudget;
2135
+ /**
2136
+ * What this call will send, in tokens.
2137
+ *
2138
+ * Text is the bulk of it, but not all of it: providers bill the serialized
2139
+ * TOOL DEFINITIONS on every native-tool call (Anthropic sends each name,
2140
+ * description and input schema), and an image is billed by its own size
2141
+ * rather than as the `[image]` placeholder `contentToText` reduces it to. A
2142
+ * tool-heavy or vision request could therefore pass either cap while its real
2143
+ * input already exceeded the allowance.
2144
+ */
2145
+ private estimateInputTokens;
2146
+ /**
2147
+ * Report a wait that ended because something asked it to stop, the same way
2148
+ * the provider call below reports one.
2149
+ *
2150
+ * The queue waits sit OUTSIDE the try/catch that maps aborts, so without
2151
+ * this a cancellation surfaced as whatever the queue happened to throw and
2152
+ * was retried or failed over like an ordinary error. A budget abort keeps
2153
+ * saying it ran out of budget — otherwise the reason the run stopped is lost
2154
+ * on the way up — and anything else that was aborted becomes a cancellation.
2155
+ */
2156
+ private asAbortFailure;
2157
+ /** Trips the same run-level flag a post-hoc overrun does, and reports it the same way. */
2158
+ private failPreflight;
2056
2159
  /**
2057
2160
  * Enforce the hard per-task ceiling. Once tripped, the flag makes every
2058
2161
  * subsequent (and concurrent) generate() call in this run fail fast.
@@ -3043,6 +3146,7 @@ interface BroadcastMessage {
3043
3146
  timestamp: string;
3044
3147
  }
3045
3148
  declare class PeerBus extends EventEmitter {
3149
+ constructor();
3046
3150
  private outputs;
3047
3151
  private waiters;
3048
3152
  private members;