@@ -25,10 +25,11 @@ export const kind = 'summarize' as const
2525// ===========================
2626
2727/** Extract provider options from a SummarizeAdapter via ~types */
28- export type SummarizeProviderOptions < TAdapter > =
29- TAdapter extends SummarizeAdapter < any , any >
30- ? TAdapter [ '~types' ] [ 'providerOptions' ]
31- : object
28+ export type SummarizeProviderOptions < TAdapter > = TAdapter extends {
29+ '~types' : { providerOptions : infer P extends object }
30+ }
31+ ? P
32+ : object
3233
3334// ===========================
3435// Activity Options Type
@@ -42,7 +43,7 @@ export type SummarizeProviderOptions<TAdapter> =
4243 * @template TStream - Whether to stream the output
4344 */
4445export interface SummarizeActivityOptions <
45- TAdapter extends SummarizeAdapter < string , object > ,
46+ TAdapter extends SummarizeAdapter < string , SummarizeProviderOptions < TAdapter > > ,
4647 TStream extends boolean = false ,
4748> {
4849 /** The summarize adapter to use (must be created with a model) */
@@ -150,7 +151,7 @@ function createId(prefix: string): string {
150151 * ```
151152 */
152153export function summarize <
153- TAdapter extends SummarizeAdapter < string , object > ,
154+ TAdapter extends SummarizeAdapter < string , SummarizeProviderOptions < TAdapter > > ,
154155 TStream extends boolean = false ,
155156> (
156157 options : SummarizeActivityOptions < TAdapter , TStream > ,
@@ -159,26 +160,22 @@ export function summarize<
159160
160161 if ( stream ) {
161162 return runStreamingSummarize (
162- options as SummarizeActivityOptions <
163- SummarizeAdapter < string , object > ,
164- true
165- > ,
163+ options as SummarizeActivityOptions < TAdapter , true > ,
166164 ) as SummarizeActivityResult < TStream >
167165 }
168166
169167 return runSummarize (
170- options as SummarizeActivityOptions <
171- SummarizeAdapter < string , object > ,
172- false
173- > ,
168+ options as SummarizeActivityOptions < TAdapter , false > ,
174169 ) as SummarizeActivityResult < TStream >
175170}
176171
177172/**
178173 * Run non-streaming summarization
179174 */
180- async function runSummarize (
181- options : SummarizeActivityOptions < SummarizeAdapter < string , object > , false > ,
175+ async function runSummarize <
176+ TAdapter extends SummarizeAdapter < string , SummarizeProviderOptions < TAdapter > > ,
177+ > (
178+ options : SummarizeActivityOptions < TAdapter , false > ,
182179) : Promise < SummarizationResult > {
183180 const { adapter, text, maxLength, style, focus, modelOptions } = options
184181 const model = adapter . model
@@ -247,8 +244,10 @@ async function runSummarize(
247244 * Uses the adapter's native streaming if available, otherwise falls back
248245 * to non-streaming and yields the result as a single chunk.
249246 */
250- async function * runStreamingSummarize (
251- options : SummarizeActivityOptions < SummarizeAdapter < string , object > , true > ,
247+ async function * runStreamingSummarize <
248+ TAdapter extends SummarizeAdapter < string , SummarizeProviderOptions < TAdapter > > ,
249+ > (
250+ options : SummarizeActivityOptions < TAdapter , true > ,
252251) : AsyncIterable < StreamChunk > {
253252 const { adapter, text, maxLength, style, focus, modelOptions } = options
254253 const model = adapter . model
@@ -296,7 +295,7 @@ async function* runStreamingSummarize(
296295 * Create typed options for the summarize() function without executing.
297296 */
298297export function createSummarizeOptions <
299- TAdapter extends SummarizeAdapter < string , object > ,
298+ TAdapter extends SummarizeAdapter < string , SummarizeProviderOptions < TAdapter > > ,
300299 TStream extends boolean = false ,
301300> (
302301 options : SummarizeActivityOptions < TAdapter , TStream > ,
0 commit comments