@usewind/node 0.1.1 → 0.1.2
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.cjs +13 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -3
- package/dist/index.d.ts +23 -3
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -84,11 +84,31 @@ interface ChatStreamChunk {
|
|
|
84
84
|
* `.tool_calls`), JSON-parsed. `null` on the final, settlement-only chunk.
|
|
85
85
|
*/
|
|
86
86
|
delta: unknown;
|
|
87
|
-
/** The final chunk of a stream carries the settled `wind` block; `null` on all others
|
|
87
|
+
/** The final chunk of a stream carries the settled `wind` block; `null` on all others, and on a final chunk that isn't `settled`. */
|
|
88
88
|
wind: WindBlock | null;
|
|
89
|
-
/** Final token counts — on the final chunk only
|
|
89
|
+
/** Final token counts — on the final chunk only, when `settled`. */
|
|
90
90
|
usage?: ChatUsage;
|
|
91
|
+
/** How the call's charge stands — on the final chunk only. */
|
|
92
|
+
settlement?: ChatSettlement;
|
|
93
|
+
/**
|
|
94
|
+
* The call's `Idempotency-Key` — on the final chunk only. A `pending` call's
|
|
95
|
+
* `request.settled` webhook carries it as `request_id`.
|
|
96
|
+
*/
|
|
97
|
+
idempotencyKey?: string;
|
|
91
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* - `settled`: charged on the provider's own token counts; `wind` and `usage`
|
|
101
|
+
* are filled in.
|
|
102
|
+
* - `estimated`: the stream ended before the provider reported usage, and it
|
|
103
|
+
* keeps no record to fetch it from (OpenAI, Anthropic, Google direct), so it
|
|
104
|
+
* was charged on Wind's count of the tokens with the provider's tokenizer.
|
|
105
|
+
* `wind` and `usage` are filled in from that count.
|
|
106
|
+
* - `pending`: the stream ended before the provider reported usage, but the
|
|
107
|
+
* provider keeps a record (OpenRouter), so the charge isn't known yet.
|
|
108
|
+
* `wind` and `usage` are null; the user's hold stays reserved until Wind
|
|
109
|
+
* settles it, and the result arrives as a `request.settled` webhook.
|
|
110
|
+
*/
|
|
111
|
+
type ChatSettlement = 'settled' | 'estimated' | 'pending';
|
|
92
112
|
/** 'frozen' — Wind's own risk layer, independent of anything you or the user configured; clears when the user reconnects. */
|
|
93
113
|
type ConnectionStatus = 'active' | 'exhausted' | 'revoked' | 'frozen';
|
|
94
114
|
interface Connection {
|
|
@@ -640,4 +660,4 @@ declare function createWind(config?: Partial<WindConfig>): Wind;
|
|
|
640
660
|
*/
|
|
641
661
|
declare const wind: Wind;
|
|
642
662
|
|
|
643
|
-
export { type Account, AllocationExhaustedError, type AllocationRequest, type AllocationRequestParams, AppSuspendedError, type ChatMessage, type ChatParams, type ChatResult, type ChatStreamChunk, type ChatTool, type ChatToolChoice, type ChatUsage, type Chattable, type ConnectTransaction, type Connection, ConnectionFrozenError, ConnectionRevokedError, ConnectionScope, type ConnectionStatus, type Feature, FeatureCostExceededError, FeatureModelNotConfiguredError, FeatureScope, type Grant, type GrantStore, IdempotencyKeyReusedError, ModelNotAllowedError, ProviderError, RateLimitedError, type RevokeResult, RiskThrottledError, type RoutesOptions, TokenExpiredError, type TokenResponse, type TransactionStore, type WebhookEvent, Wind, WindApiError, type WindBlock, type WindConfig, WindConfigError, WindError, type WindErrorEnvelope, type WindErrorInit, WindNotConnectedError, WindNotImplementedError, WindSignatureError, createWind, memoryGrantStore, wind };
|
|
663
|
+
export { type Account, AllocationExhaustedError, type AllocationRequest, type AllocationRequestParams, AppSuspendedError, type ChatMessage, type ChatParams, type ChatResult, type ChatSettlement, type ChatStreamChunk, type ChatTool, type ChatToolChoice, type ChatUsage, type Chattable, type ConnectTransaction, type Connection, ConnectionFrozenError, ConnectionRevokedError, ConnectionScope, type ConnectionStatus, type Feature, FeatureCostExceededError, FeatureModelNotConfiguredError, FeatureScope, type Grant, type GrantStore, IdempotencyKeyReusedError, ModelNotAllowedError, ProviderError, RateLimitedError, type RevokeResult, RiskThrottledError, type RoutesOptions, TokenExpiredError, type TokenResponse, type TransactionStore, type WebhookEvent, Wind, WindApiError, type WindBlock, type WindConfig, WindConfigError, WindError, type WindErrorEnvelope, type WindErrorInit, WindNotConnectedError, WindNotImplementedError, WindSignatureError, createWind, memoryGrantStore, wind };
|
package/dist/index.d.ts
CHANGED
|
@@ -84,11 +84,31 @@ interface ChatStreamChunk {
|
|
|
84
84
|
* `.tool_calls`), JSON-parsed. `null` on the final, settlement-only chunk.
|
|
85
85
|
*/
|
|
86
86
|
delta: unknown;
|
|
87
|
-
/** The final chunk of a stream carries the settled `wind` block; `null` on all others
|
|
87
|
+
/** The final chunk of a stream carries the settled `wind` block; `null` on all others, and on a final chunk that isn't `settled`. */
|
|
88
88
|
wind: WindBlock | null;
|
|
89
|
-
/** Final token counts — on the final chunk only
|
|
89
|
+
/** Final token counts — on the final chunk only, when `settled`. */
|
|
90
90
|
usage?: ChatUsage;
|
|
91
|
+
/** How the call's charge stands — on the final chunk only. */
|
|
92
|
+
settlement?: ChatSettlement;
|
|
93
|
+
/**
|
|
94
|
+
* The call's `Idempotency-Key` — on the final chunk only. A `pending` call's
|
|
95
|
+
* `request.settled` webhook carries it as `request_id`.
|
|
96
|
+
*/
|
|
97
|
+
idempotencyKey?: string;
|
|
91
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* - `settled`: charged on the provider's own token counts; `wind` and `usage`
|
|
101
|
+
* are filled in.
|
|
102
|
+
* - `estimated`: the stream ended before the provider reported usage, and it
|
|
103
|
+
* keeps no record to fetch it from (OpenAI, Anthropic, Google direct), so it
|
|
104
|
+
* was charged on Wind's count of the tokens with the provider's tokenizer.
|
|
105
|
+
* `wind` and `usage` are filled in from that count.
|
|
106
|
+
* - `pending`: the stream ended before the provider reported usage, but the
|
|
107
|
+
* provider keeps a record (OpenRouter), so the charge isn't known yet.
|
|
108
|
+
* `wind` and `usage` are null; the user's hold stays reserved until Wind
|
|
109
|
+
* settles it, and the result arrives as a `request.settled` webhook.
|
|
110
|
+
*/
|
|
111
|
+
type ChatSettlement = 'settled' | 'estimated' | 'pending';
|
|
92
112
|
/** 'frozen' — Wind's own risk layer, independent of anything you or the user configured; clears when the user reconnects. */
|
|
93
113
|
type ConnectionStatus = 'active' | 'exhausted' | 'revoked' | 'frozen';
|
|
94
114
|
interface Connection {
|
|
@@ -640,4 +660,4 @@ declare function createWind(config?: Partial<WindConfig>): Wind;
|
|
|
640
660
|
*/
|
|
641
661
|
declare const wind: Wind;
|
|
642
662
|
|
|
643
|
-
export { type Account, AllocationExhaustedError, type AllocationRequest, type AllocationRequestParams, AppSuspendedError, type ChatMessage, type ChatParams, type ChatResult, type ChatStreamChunk, type ChatTool, type ChatToolChoice, type ChatUsage, type Chattable, type ConnectTransaction, type Connection, ConnectionFrozenError, ConnectionRevokedError, ConnectionScope, type ConnectionStatus, type Feature, FeatureCostExceededError, FeatureModelNotConfiguredError, FeatureScope, type Grant, type GrantStore, IdempotencyKeyReusedError, ModelNotAllowedError, ProviderError, RateLimitedError, type RevokeResult, RiskThrottledError, type RoutesOptions, TokenExpiredError, type TokenResponse, type TransactionStore, type WebhookEvent, Wind, WindApiError, type WindBlock, type WindConfig, WindConfigError, WindError, type WindErrorEnvelope, type WindErrorInit, WindNotConnectedError, WindNotImplementedError, WindSignatureError, createWind, memoryGrantStore, wind };
|
|
663
|
+
export { type Account, AllocationExhaustedError, type AllocationRequest, type AllocationRequestParams, AppSuspendedError, type ChatMessage, type ChatParams, type ChatResult, type ChatSettlement, type ChatStreamChunk, type ChatTool, type ChatToolChoice, type ChatUsage, type Chattable, type ConnectTransaction, type Connection, ConnectionFrozenError, ConnectionRevokedError, ConnectionScope, type ConnectionStatus, type Feature, FeatureCostExceededError, FeatureModelNotConfiguredError, FeatureScope, type Grant, type GrantStore, IdempotencyKeyReusedError, ModelNotAllowedError, ProviderError, RateLimitedError, type RevokeResult, RiskThrottledError, type RoutesOptions, TokenExpiredError, type TokenResponse, type TransactionStore, type WebhookEvent, Wind, WindApiError, type WindBlock, type WindConfig, WindConfigError, WindError, type WindErrorEnvelope, type WindErrorInit, WindNotConnectedError, WindNotImplementedError, WindSignatureError, createWind, memoryGrantStore, wind };
|
package/dist/index.js
CHANGED
|
@@ -679,7 +679,7 @@ async function* billedStream(ctx, userId, params, call) {
|
|
|
679
679
|
}
|
|
680
680
|
if (!(res.body instanceof ReadableStream)) {
|
|
681
681
|
const result = res.body;
|
|
682
|
-
yield { delta: result, wind: result.wind ?? null, usage: result.usage };
|
|
682
|
+
yield { delta: result, wind: result.wind ?? null, usage: result.usage, settlement: "settled", idempotencyKey };
|
|
683
683
|
return;
|
|
684
684
|
}
|
|
685
685
|
for await (const event of sseEvents(res.body)) {
|
|
@@ -691,13 +691,13 @@ async function* billedStream(ctx, userId, params, call) {
|
|
|
691
691
|
continue;
|
|
692
692
|
}
|
|
693
693
|
if (data?.wind_final) {
|
|
694
|
-
yield
|
|
694
|
+
yield finalChunk(data.wind_final, idempotencyKey);
|
|
695
695
|
} else if (data?.error) {
|
|
696
696
|
const err = data.error.error ?? data.error;
|
|
697
697
|
const status = err.code === "provider_error" ? 502 : 403;
|
|
698
698
|
throw WindError.fromResponse(status, { error: err }, { requestId: res.requestId });
|
|
699
|
-
} else if (data?.streamed
|
|
700
|
-
yield
|
|
699
|
+
} else if (data?.streamed) {
|
|
700
|
+
yield finalChunk(data, idempotencyKey);
|
|
701
701
|
} else {
|
|
702
702
|
yield { delta: data, wind: null };
|
|
703
703
|
}
|
|
@@ -723,6 +723,15 @@ async function* sseEvents(stream) {
|
|
|
723
723
|
reader.releaseLock();
|
|
724
724
|
}
|
|
725
725
|
}
|
|
726
|
+
function finalChunk(final, idempotencyKey) {
|
|
727
|
+
return {
|
|
728
|
+
delta: null,
|
|
729
|
+
wind: final.wind ?? null,
|
|
730
|
+
usage: final.usage ?? void 0,
|
|
731
|
+
settlement: final.settlement ?? "settled",
|
|
732
|
+
idempotencyKey
|
|
733
|
+
};
|
|
734
|
+
}
|
|
726
735
|
var TOLERANCE_S = 300;
|
|
727
736
|
var WebhookVerifier = class {
|
|
728
737
|
constructor(config) {
|