@providerkit/core 0.23.0 → 0.24.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 +29 -7
- package/dist/auth/with-token.d.ts +4 -1
- package/dist/auth/with-token.d.ts.map +1 -1
- package/dist/auth/with-token.js +4 -1
- package/dist/auth/with-token.js.map +1 -1
- package/dist/gate.d.ts +29 -0
- package/dist/gate.d.ts.map +1 -0
- package/dist/gate.js +96 -0
- package/dist/gate.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/key-pool.d.ts +11 -0
- package/dist/key-pool.d.ts.map +1 -1
- package/dist/key-pool.js +14 -0
- package/dist/key-pool.js.map +1 -1
- package/dist/providers/anthropic.d.ts +7 -0
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +3 -1
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/factory.d.ts +26 -0
- package/dist/providers/factory.d.ts.map +1 -1
- package/dist/providers/factory.js +41 -9
- package/dist/providers/factory.js.map +1 -1
- package/dist/providers/openai.d.ts +7 -0
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +3 -1
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/responses.d.ts +11 -0
- package/dist/providers/responses.d.ts.map +1 -1
- package/dist/providers/responses.js +3 -1
- package/dist/providers/responses.js.map +1 -1
- package/dist/registry.d.ts +105 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +291 -0
- package/dist/registry.js.map +1 -0
- package/dist/tools.d.ts +8 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +2 -2
- package/dist/tools.js.map +1 -1
- package/dist/turn.d.ts +55 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +125 -0
- package/dist/turn.js.map +1 -0
- package/dist/types.d.ts +8 -22
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -45
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/auth/with-token.ts +4 -1
- package/src/gate.ts +152 -0
- package/src/index.ts +3 -0
- package/src/key-pool.ts +15 -0
- package/src/providers/anthropic.ts +10 -1
- package/src/providers/factory.ts +66 -21
- package/src/providers/openai.ts +10 -1
- package/src/providers/responses.ts +14 -1
- package/src/registry.ts +420 -0
- package/src/tools.ts +10 -2
- package/src/turn.ts +166 -0
- package/src/types.ts +8 -62
package/src/types.ts
CHANGED
|
@@ -71,8 +71,9 @@ export type ContentPart = TextPart | ImagePart | FilePart;
|
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* A tool the model asked to run. `arguments` is the RAW JSON string, not a
|
|
74
|
-
* parsed object: it arrives in fragments and can be truncated mid-stream
|
|
75
|
-
*
|
|
74
|
+
* parsed object: it arrives in fragments and can be truncated mid-stream.
|
|
75
|
+
* `collectTurn` joins the fragments; healing and validating them is the
|
|
76
|
+
* consumer's job (see tools/define).
|
|
76
77
|
*/
|
|
77
78
|
export interface ToolCall {
|
|
78
79
|
id: string;
|
|
@@ -151,7 +152,7 @@ export interface ToolDefinition {
|
|
|
151
152
|
|
|
152
153
|
export type FinishReason = "stop" | "length" | "tool_calls" | "content_filter";
|
|
153
154
|
|
|
154
|
-
/** Incremental tool-call fragment, assembled by `index`
|
|
155
|
+
/** Incremental tool-call fragment, assembled by `index`. `collectTurn` does it. */
|
|
155
156
|
export interface ToolCallDelta {
|
|
156
157
|
index: number;
|
|
157
158
|
id?: string;
|
|
@@ -385,9 +386,10 @@ export interface StreamOptions {
|
|
|
385
386
|
*/
|
|
386
387
|
jsonWithTools?: JsonWithTools;
|
|
387
388
|
/**
|
|
388
|
-
* Stable id for the conversation or job this call belongs to. Sent
|
|
389
|
-
*
|
|
390
|
-
*
|
|
389
|
+
* Stable id for the conversation or job this call belongs to. Sent in the
|
|
390
|
+
* `sessionHeader` of endpoints that name one (OpenCode Go routes and caches
|
|
391
|
+
* by it), and as `prompt_cache_key` on the Responses shape. A call without
|
|
392
|
+
* one sends the provider's `instanceSessionId` in that header instead.
|
|
391
393
|
*/
|
|
392
394
|
sessionId?: string;
|
|
393
395
|
/**
|
|
@@ -440,62 +442,6 @@ export interface Provider {
|
|
|
440
442
|
): AsyncIterable<ProviderChunk>;
|
|
441
443
|
}
|
|
442
444
|
|
|
443
|
-
export interface Completion {
|
|
444
|
-
text: string;
|
|
445
|
-
/** Present when the stream identifies the endpoint that answered. */
|
|
446
|
-
provider?: string;
|
|
447
|
-
reasoning: string;
|
|
448
|
-
/** Present only where the provider sent one. See ChatMessage.reasoningDetails. */
|
|
449
|
-
reasoningDetails?: unknown[];
|
|
450
|
-
/** Present only where the provider sent them. See ChatMessage.reasoningItems. */
|
|
451
|
-
reasoningItems?: ReasoningItems;
|
|
452
|
-
usage: TokenUsage;
|
|
453
|
-
finishReason: FinishReason | null;
|
|
454
|
-
model: string;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
/** Drain a no-tools stream into a Completion. Usage chunks are cumulative on
|
|
458
|
-
* some providers and final-only on others: the LAST one wins. */
|
|
459
|
-
export async function drainStream(
|
|
460
|
-
stream: AsyncIterable<ProviderChunk>,
|
|
461
|
-
model: string,
|
|
462
|
-
): Promise<Completion> {
|
|
463
|
-
let text = "";
|
|
464
|
-
let reasoning = "";
|
|
465
|
-
// Not concatenated: this half of the record is a payload the provider owns,
|
|
466
|
-
// and it arrives whole on one delta rather than in fragments. Dropped here,
|
|
467
|
-
// a drained turn replays only half its own reasoning on the next round —
|
|
468
|
-
// which is the failure `reasoningDetails` exists to prevent.
|
|
469
|
-
let reasoningDetails: unknown[] | undefined;
|
|
470
|
-
let reasoningItems: ReasoningItems | undefined;
|
|
471
|
-
let usage: TokenUsage = EMPTY_USAGE;
|
|
472
|
-
let finishReason: FinishReason | null = null;
|
|
473
|
-
let source: ProviderChunk["source"];
|
|
474
|
-
for await (const chunk of stream) {
|
|
475
|
-
if (chunk.source) source = chunk.source;
|
|
476
|
-
if (chunk.type === "delta") {
|
|
477
|
-
if (chunk.content) text += chunk.content;
|
|
478
|
-
if (chunk.reasoning) reasoning += chunk.reasoning;
|
|
479
|
-
if (chunk.reasoningDetails?.length) reasoningDetails = chunk.reasoningDetails;
|
|
480
|
-
if (chunk.reasoningItems?.items.length) reasoningItems = chunk.reasoningItems;
|
|
481
|
-
} else if (chunk.type === "usage" && chunk.usage) {
|
|
482
|
-
usage = chunk.usage;
|
|
483
|
-
} else if (chunk.type === "finish" && chunk.finishReason) {
|
|
484
|
-
finishReason = chunk.finishReason;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
return {
|
|
488
|
-
text,
|
|
489
|
-
reasoning,
|
|
490
|
-
...(reasoningDetails ? { reasoningDetails } : {}),
|
|
491
|
-
...(reasoningItems ? { reasoningItems } : {}),
|
|
492
|
-
usage,
|
|
493
|
-
finishReason,
|
|
494
|
-
model: source?.model ?? model,
|
|
495
|
-
...(source ? { provider: source.provider } : {}),
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
|
|
499
445
|
/**
|
|
500
446
|
* Prepare a history for a thinking-DISABLED turn: strip `reasoning` from every
|
|
501
447
|
* assistant message.
|