Skip to content

Commit cf045fa

Browse files
committed
fix(agent+memory): unblock CI build (TS errors in 0.3.4 release commit)
Three TS errors broke the Release workflow on master after 827b6b9 landed structured output on session.send: 1) src/api/agent.ts:575 (TS2322) AgentSession interface declares two overloads for send(): send(input): Promise<GenerateTextResult> send<S>(input, opts): Promise<SessionSendStructuredResult<z.infer<S>>> The implementation signature returned just GenerateTextResult, which doesn't satisfy the second overload's structured return. Fix: implementation returns the union `Promise<GenerateTextResult | SessionSendStructuredResult<unknown>>`, constructed by binding the impl to a local `session` const and casting to AgentSession at the return point. Standard pattern for typed overloaded methods in TypeScript: the impl signature stays broader than any single overload, the public overloads narrow it for callers. 2) src/api/agent.ts:602 (TS2345) _responseFormat in GenerateTextOptions was typed { type: string }, too narrow for the schema-bearing payloads structuredOutputFormat.ts produces (OpenAI json_schema with json_schema sub-object, Anthropic _agentosUseToolForStructuredOutput marker, Gemini _gemini extra). Fix: widen GenerateTextOptions._responseFormat to `{ type: string } | Record<string, unknown>`. Comment updated to explain the per-provider shapes the field carries. agent.ts no longer needs a cast at the buildResponseFormat call site. 3) src/memory/CognitiveMemoryManager.ts:852 (TS2304) Cannot find name 'ScoredMemoryTrace'. Trailing edge of typed-network Phase 4.3 commit (d0ab11c) left a referenced type unimported. Fix: add the missing import alongside the other memory types. One-line completion of d0ab11c. (Error 4 from the CI report — TS2353 about retrievedTypedFacts not existing in type — does not reproduce locally on a clean build with these fixes, suggesting the diagnostic was downstream of error 3 and clears once ScoredMemoryTrace resolves.) Local `npm run build` clean. Release workflow should now succeed.
1 parent 64a5e69 commit cf045fa

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/api/agent.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,13 +569,13 @@ export function agent(opts: AgentOptions): Agent {
569569
if (!sessions.has(sessionId)) sessions.set(sessionId, []);
570570
const history = sessions.get(sessionId)!;
571571

572-
return {
572+
const session = {
573573
id: sessionId,
574574

575575
async send(
576576
input: MessageContent,
577577
sendOpts?: SessionSendOptions<ZodType>,
578-
): Promise<GenerateTextResult> {
578+
): Promise<GenerateTextResult | SessionSendStructuredResult<unknown>> {
579579
const textForMemory = typeof input === 'string' ? input : extractTextFromContent(input);
580580
const userMessage: Message = { role: 'user', content: input };
581581
const requestMessages = useMemory
@@ -707,6 +707,11 @@ export function agent(opts: AgentOptions): Agent {
707707
history.length = 0;
708708
},
709709
};
710+
// The send() implementation returns a union (GenerateTextResult |
711+
// SessionSendStructuredResult<unknown>) to cover both interface
712+
// overloads. Cast through unknown so TypeScript accepts the
713+
// implementation as satisfying the overloaded interface.
714+
return session as unknown as AgentSession;
710715
},
711716

712717
async usage(sessionId?: string): Promise<AgentOSUsageAggregate> {

src/api/generateText.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,17 @@ export interface GenerateTextOptions {
332332
*/
333333
onBeforeToolExecution?: (info: ToolCallHookInfo) => Promise<ToolCallHookInfo | null>;
334334
/**
335-
* @internal Used by generateObject to forward response_format to the provider.
336-
* Not part of the public API. Use generateObject for structured output.
335+
* @internal Used by generateObject and AgentSession.send (with
336+
* responseSchema) to forward a provider-specific response_format
337+
* payload to the provider. Not part of the public API.
338+
*
339+
* Shape varies by provider: OpenAI accepts json_object or
340+
* json_schema, Anthropic uses an internal _agentosUseToolForStructuredOutput
341+
* marker that AnthropicProvider routes to forced tool_use, Gemini uses
342+
* a _gemini.responseSchema extra. The provider implementations consume
343+
* whatever shape is here.
337344
*/
338-
_responseFormat?: { type: string };
345+
_responseFormat?: { type: string } | Record<string, unknown>;
339346
}
340347

341348
/**

0 commit comments

Comments
 (0)