@alvin0/ai-agent-sdk-protocol-gemini-interactions 0.1.3 → 0.1.4

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.ts CHANGED
@@ -2,7 +2,8 @@ import { GenerateOptions, StreamChunk, UsageCounters } from "@alvin0/ai-agent-sd
2
2
  //#region src/contract.d.ts
3
3
  interface ProtocolRequest {
4
4
  readonly options: GenerateOptions;
5
- readonly maxTokens: number;
5
+ /** Absent when neither the caller, the model, nor the route names an output cap. */
6
+ readonly maxTokens?: number;
6
7
  }
7
8
  interface ProtocolSseEvent {
8
9
  readonly event: string | undefined;
@@ -90,7 +91,7 @@ type WireToolChoice = 'auto' | 'any' | 'none' | {
90
91
  };
91
92
  };
92
93
  interface WireGenerationConfig {
93
- max_output_tokens: number;
94
+ max_output_tokens?: number;
94
95
  temperature?: number;
95
96
  top_p?: number;
96
97
  stop_sequences?: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/contract.ts","../src/wire.ts","../src/protocol.ts","../src/serialize.ts","../src/translate.ts"],"mappings":";;UAEiB;WACN,SAAS;WACT;;UAGM;WACN;WACA;;KAGC,sBACR,QAAQ;WAAwB;;WACrB;WAAwB,OAAO;;UAE7B,mBAAmB;WACzB;WACA,gBAAgB;EACzB,aAAa,SAAS,iBAAiB,SAAS;EAChD,iBAAiB,SAAS,UAAU;EACpC,UAAU,SAAS,iBAAiB,SAAS,oBAAoB;EACjE,UACE,QAAQ,cAAc,mBACtB,SAAS,iBACT,sBACC,eAAe;;;;UC1BH;;WAEN;;WAEA;;UAGM;EACf;EACA;EACA,cAAc;;UAGC;EACf;EACA;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;;KAGU,cAAc,kBAAkB,mBAAmB;KAEnD;EACN;EAAoB,SAAS;;EAC7B;EAAsB,SAAS;;EAC/B;EAAiB;EAAoB,UAAU;;EAC/C;EAAuB;EAAY;EAAc,WAAW;;EAE9D;EACA;EACA;EACA,iBAAiB,0BAA0B;EAC3C;;UAGa;EACf;EACA;EACA;EACA,YAAY,SAAS;;UAGN;EACf;EACA;;KAGU,WAAW,mBAAmB;KAE9B;EAKR;IACE;IACA;;;UAIW;EACf;EACA;EACA;EACA;EACA;EACA;EACA,cAAc;;KAGJ;EACN;EAAc;;EAEhB;EACA;EACA,QAAQ,SAAS;;UAGJ;EACf;EACA,OAAO;EACP;EACA,QAAQ;EACR,kBAAkB;EAClB;EACA;EACA,mBAAmB;;UAGJ;EACf;EACA,mBAAmB;;UAGJ;EACf;EACA;EACA;EACA;EACA;GACC;;UAGc;EACf;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA,QAAQ;;UAGO;EACf;EACA;;UAGe;EACf;EACA;EACA,OAAO;EACP,QAAQ;EACR,cAAc;EACd,QAAQ;;;;cCxJG;UAOI;WACN;WACA;WACA;WACA,gBAAgB;WAChB;WACA,YACP,SAAS,iBACT,SAAS,8BACN,SAAS;WACL,YACP,QAAQ,cAAc,mBACtB,SAAS,iBACT,wBACG,eAAe;;cAGT,4BAA4B,mBAAmB,6BACxD;;;iBCuPY,mCACd,SAAS,iBACT,SAAS,4BACR;;;iBClGoB,kCACrB,QAAQ,cAAc,mBACtB,qBACA,WAAW,kBACV,eAAe"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/contract.ts","../src/wire.ts","../src/protocol.ts","../src/serialize.ts","../src/translate.ts"],"mappings":";;UAEiB;WACN,SAAS;;WAET;;UAGM;WACN;WACA;;KAGC,sBACR,QAAQ;WAAwB;;WACrB;WAAwB,OAAO;;UAE7B,mBAAmB;WACzB;WACA,gBAAgB;EACzB,aAAa,SAAS,iBAAiB,SAAS;EAChD,iBAAiB,SAAS,UAAU;EACpC,UAAU,SAAS,iBAAiB,SAAS,oBAAoB;EACjE,UACE,QAAQ,cAAc,mBACtB,SAAS,iBACT,sBACC,eAAe;;;;UC3BH;;WAEN;;WAEA;;UAGM;EACf;EACA;EACA,cAAc;;UAGC;EACf;EACA;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;;KAGU,cAAc,kBAAkB,mBAAmB;KAEnD;EACN;EAAoB,SAAS;;EAC7B;EAAsB,SAAS;;EAC/B;EAAiB;EAAoB,UAAU;;EAC/C;EAAuB;EAAY;EAAc,WAAW;;EAE9D;EACA;EACA;EACA,iBAAiB,0BAA0B;EAC3C;;UAGa;EACf;EACA;EACA;EACA,YAAY,SAAS;;UAGN;EACf;EACA;;KAGU,WAAW,mBAAmB;KAE9B;EAKR;IACE;IACA;;;UAIW;EACf;EACA;EACA;EACA;EACA;EACA;EACA,cAAc;;KAGJ;EACN;EAAc;;EAEhB;EACA;EACA,QAAQ,SAAS;;UAGJ;EACf;EACA,OAAO;EACP;EACA,QAAQ;EACR,kBAAkB;EAClB;EACA;EACA,mBAAmB;;UAGJ;EACf;EACA,mBAAmB;;UAGJ;EACf;EACA;EACA;EACA;EACA;GACC;;UAGc;EACf;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA,QAAQ;;UAGO;EACf;EACA;;UAGe;EACf;EACA;EACA,OAAO;EACP,QAAQ;EACR,cAAc;EACd,QAAQ;;;;cCxJG;UAOI;WACN;WACA;WACA;WACA,gBAAgB;WAChB;WACA,YACP,SAAS,iBACT,SAAS,8BACN,SAAS;WACL,YACP,QAAQ,cAAc,mBACtB,SAAS,iBACT,wBACG,eAAe;;cAGT,4BAA4B,mBAAmB,6BACxD;;;iBCuPY,mCACd,SAAS,iBACT,SAAS,4BACR;;;iBClGoB,kCACrB,QAAQ,cAAc,mBACtB,qBACA,WAAW,kBACV,eAAe"}
package/dist/index.js CHANGED
@@ -195,7 +195,7 @@ function responseFormatOf(format) {
195
195
  function generationConfigOf(request, dialect) {
196
196
  const options = request.options;
197
197
  return {
198
- max_output_tokens: request.maxTokens,
198
+ ...request.maxTokens === void 0 ? {} : { max_output_tokens: request.maxTokens },
199
199
  ...options.temperature === void 0 ? {} : { temperature: options.temperature },
200
200
  ...options.topP === void 0 ? {} : { top_p: options.topP },
201
201
  ...options.stop === void 0 || options.stop.length === 0 ? {} : { stop_sequences: [...options.stop] },
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/serialize.ts","../src/translate.ts","../src/protocol.ts"],"sourcesContent":["import {\n isNativeToolSchema,\n MODEL_ERROR_CODES,\n ModelError,\n type ContentBlock,\n type DocumentBlock,\n type ImageBlock,\n type Message,\n type ModelOutputFormat,\n type ModelToolSchema,\n type NativeWebSearchTool,\n type TextAnnotation,\n type ToolChoice,\n type ToolSchema,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest } from './contract.ts'\nimport type {\n GeminiInteractionsDialect,\n GeminiThoughtState,\n WireContent,\n WireGenerationConfig,\n WireRequest,\n WireResponseFormat,\n WireStep,\n WireTool,\n WireToolChoice,\n} from './wire.ts'\n\nfunction imageContent(block: ImageBlock): WireContent {\n const resolution = block.detail === 'low' || block.detail === 'high'\n ? block.detail\n : undefined\n if (block.source.kind === 'base64') {\n return {\n type: 'image', data: block.source.data, mime_type: block.source.mediaType,\n ...(resolution === undefined ? {} : { resolution }),\n }\n }\n return {\n type: 'image', uri: block.source.kind === 'url' ? block.source.url : block.source.fileId,\n ...(resolution === undefined ? {} : { resolution }),\n }\n}\n\nfunction documentContent(block: DocumentBlock): WireContent {\n if (block.source.kind === 'base64') {\n return { type: 'document', data: block.source.data, mime_type: block.source.mediaType }\n }\n // This API collapses \"remote URL\" and \"uploaded file\" into one `uri`, exactly as\n // it does for images.\n return {\n type: 'document',\n uri: block.source.kind === 'url' ? block.source.url : block.source.fileId,\n mime_type: 'application/pdf',\n }\n}\n\nfunction annotationOf(annotation: TextAnnotation) {\n if (annotation.type !== 'url-citation') return undefined\n return {\n type: 'url_citation',\n url: annotation.url,\n ...(annotation.title === undefined ? {} : { title: annotation.title }),\n ...(annotation.startIndex === undefined ? {} : { start_index: annotation.startIndex }),\n ...(annotation.endIndex === undefined ? {} : { end_index: annotation.endIndex }),\n }\n}\n\nfunction contentOf(block: ContentBlock): WireContent | undefined {\n if (block.type === 'text') {\n const annotations = block.annotations?.map(annotationOf)\n .filter((item): item is NonNullable<typeof item> => item !== undefined)\n return {\n type: 'text', text: block.text,\n ...(annotations === undefined || annotations.length === 0 ? {} : { annotations }),\n }\n }\n if (block.type === 'image') return imageContent(block)\n if (block.type === 'document') return documentContent(block)\n return undefined\n}\n\nfunction thoughtStateOf(value: unknown): GeminiThoughtState {\n if (typeof value !== 'object' || value === null) return {}\n const state = value as GeminiThoughtState\n return {\n ...(typeof state.signature === 'string' ? { signature: state.signature } : {}),\n ...(Array.isArray(state.summary) ? { summary: structuredClone(state.summary) } : {}),\n }\n}\n\nfunction argumentsObject(raw: string): Record<string, unknown> {\n if (raw.length === 0) return {}\n let value: unknown\n try {\n value = JSON.parse(raw)\n } catch (error: unknown) {\n throw new ModelError(\n 'Gemini Interactions requires function-call arguments to be a JSON object',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n { cause: error },\n )\n }\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new ModelError(\n 'Gemini Interactions requires function-call arguments to be a JSON object',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return value as Record<string, unknown>\n}\n\nfunction toolResult(\n block: Extract<ContentBlock, { type: 'tool-result' }>,\n toolNames: ReadonlyMap<string, string>,\n): WireStep {\n const contents = block.content.map(contentOf)\n .filter((item): item is WireContent => item !== undefined)\n const name = toolNames.get(block.toolCallId)\n return {\n type: 'function_result',\n call_id: block.toolCallId,\n ...(name === undefined ? {} : { name }),\n result: contents,\n ...(block.isError === undefined ? {} : { is_error: block.isError }),\n }\n}\n\nfunction appendUserMessage(\n message: Message,\n output: WireStep[],\n toolNames: ReadonlyMap<string, string>,\n): void {\n let content: WireContent[] = []\n const flush = (): void => {\n if (content.length === 0) return\n output.push({ type: 'user_input', content })\n content = []\n }\n for (const block of message.content) {\n if (block.type === 'tool-result') {\n flush()\n output.push(toolResult(block, toolNames))\n continue\n }\n const mapped = contentOf(block)\n if (mapped !== undefined) content.push(mapped)\n }\n flush()\n}\n\nfunction appendAssistantMessage(message: Message, output: WireStep[]): void {\n let content: WireContent[] = []\n const flush = (): void => {\n if (content.length === 0) return\n output.push({ type: 'model_output', content })\n content = []\n }\n for (const block of message.content) {\n if (block.type === 'text' || block.type === 'image' || block.type === 'document') {\n const mapped = contentOf(block)\n if (mapped !== undefined) content.push(mapped)\n continue\n }\n flush()\n if (block.type === 'reasoning') {\n const state = thoughtStateOf(block.providerState)\n const summary = state.summary ?? (block.text.length === 0\n ? undefined\n : [{ type: 'text' as const, text: block.text }])\n output.push({\n type: 'thought',\n ...(state.signature === undefined ? {} : { signature: state.signature }),\n ...(summary === undefined || summary.length === 0 ? {} : { summary: [...summary] }),\n })\n } else if (block.type === 'tool-call') {\n output.push({\n type: 'function_call', id: block.id, name: block.name,\n arguments: argumentsObject(block.arguments),\n })\n }\n }\n flush()\n}\n\nfunction inputOf(request: ProtocolRequest): WireStep[] {\n const output: WireStep[] = []\n const toolNames = new Map<string, string>()\n for (const message of request.options.messages) {\n for (const block of message.content) {\n if (block.type === 'tool-call') toolNames.set(block.id, block.name)\n }\n }\n for (const message of request.options.messages) {\n if (message.role === 'system') continue\n if (message.role === 'assistant') appendAssistantMessage(message, output)\n else appendUserMessage(message, output, toolNames)\n }\n return output\n}\n\nfunction systemInstructionOf(request: ProtocolRequest): string {\n const messages = request.options.messages\n .filter(message => message.role === 'system')\n .flatMap(message => message.content)\n .filter((block): block is Extract<ContentBlock, { type: 'text' }> => block.type === 'text')\n .map(block => block.text)\n return [request.options.system, ...messages]\n .filter((value): value is string => value !== undefined && value.length > 0)\n .join('\\n\\n')\n}\n\nfunction functionTool(tool: ToolSchema): WireTool {\n return {\n type: 'function', name: tool.name, description: tool.description,\n parameters: tool.parameters,\n }\n}\n\nfunction googleSearchTool(tool: NativeWebSearchTool): WireTool {\n if (tool.searchContextSize !== undefined || tool.allowedDomains !== undefined\n || tool.blockedDomains !== undefined || tool.userLocation !== undefined\n || tool.maxUses !== undefined) {\n throw new ModelError(\n 'Gemini Interactions web search does not support SDK search filters or limits',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return { type: 'google_search', search_types: ['web_search'] }\n}\n\nfunction toolOf(tool: ModelToolSchema): WireTool {\n if (!isNativeToolSchema(tool)) return functionTool(tool)\n if (tool.name === 'web-search') return googleSearchTool(tool)\n throw new ModelError(\n 'Gemini Interactions does not expose image generation as an SDK native tool',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n}\n\nfunction toolChoiceOf(choice: ToolChoice): WireToolChoice {\n if (choice === 'required') return 'any'\n if (typeof choice === 'string') return choice\n const name = choice.type === 'native' && choice.name === 'web-search'\n ? 'google_search'\n : choice.name\n return { allowed_tools: { mode: 'any', tools: [name] } }\n}\n\nfunction responseFormatOf(format: ModelOutputFormat | undefined): WireResponseFormat | undefined {\n if (format === undefined) return undefined\n if (format.type === 'text') return { type: 'text', mime_type: 'text/plain' }\n return { type: 'text', mime_type: 'application/json', schema: format.schema }\n}\n\nfunction generationConfigOf(\n request: ProtocolRequest,\n dialect: GeminiInteractionsDialect,\n): WireGenerationConfig {\n const options = request.options\n return {\n max_output_tokens: request.maxTokens,\n ...(options.temperature === undefined ? {} : { temperature: options.temperature }),\n ...(options.topP === undefined ? {} : { top_p: options.topP }),\n ...(options.stop === undefined || options.stop.length === 0\n ? {}\n : { stop_sequences: [...options.stop] }),\n ...(options.reasoningEffort === undefined\n ? {}\n : {\n thinking_level: String(options.reasoningEffort),\n thinking_summaries: dialect.thinkingSummaries,\n }),\n ...(options.toolChoice === undefined ? {} : { tool_choice: toolChoiceOf(options.toolChoice) }),\n }\n}\n\nexport function serializeGeminiInteractionsRequest(\n request: ProtocolRequest,\n dialect: GeminiInteractionsDialect,\n): WireRequest {\n const systemInstruction = systemInstructionOf(request)\n const tools = request.options.tools?.map(toolOf)\n const responseFormat = responseFormatOf(request.options.outputFormat)\n return {\n model: request.options.model,\n input: inputOf(request),\n ...(systemInstruction.length === 0 ? {} : { system_instruction: systemInstruction }),\n ...(tools === undefined || tools.length === 0 ? {} : { tools }),\n ...(responseFormat === undefined ? {} : { response_format: responseFormat }),\n stream: true,\n store: dialect.store,\n generation_config: generationConfigOf(request, dialect),\n }\n}\n","import {\n CONTEXT_WINDOW_EXCEEDED_CODE,\n MODEL_ERROR_CODES,\n ModelError,\n QUOTA_EXCEEDED_CODE,\n ToolCallId,\n type ContentBlock,\n type FinishReason,\n type TextAnnotation,\n type UsageCounters,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest, ProtocolSseEvent, ProtocolStreamChunk } from './contract.ts'\nimport type {\n GeminiThoughtState,\n WireAnnotation,\n WireContent,\n WireInteraction,\n WireStepData,\n WireStreamEvent,\n WireUsage,\n} from './wire.ts'\n\ntype StepKind = 'text' | 'reasoning' | 'tool-call'\n\ninterface OpenStep {\n readonly index: number\n readonly kind: StepKind\n text: string\n arguments: string\n readonly initialArguments: unknown\n callId: string\n name: string\n signature: string | undefined\n summary: WireContent[]\n annotations: TextAnnotation[]\n}\n\nfunction stepKind(type: string | undefined): StepKind | undefined {\n if (type === 'model_output') return 'text'\n if (type === 'thought') return 'reasoning'\n if (type === 'function_call') return 'tool-call'\n return undefined\n}\n\nfunction contentList(value: unknown): WireContent[] {\n if (!Array.isArray(value)) return []\n return value.filter((item): item is WireContent => typeof item === 'object' && item !== null\n && ((item as { type?: unknown }).type === 'text' || (item as { type?: unknown }).type === 'image'))\n}\n\nfunction textOf(contents: readonly WireContent[]): string {\n return contents.filter((item): item is Extract<WireContent, { type: 'text' }> => item.type === 'text')\n .map(item => item.text)\n .join('')\n}\n\nfunction annotationsOf(value: unknown): TextAnnotation[] {\n if (!Array.isArray(value)) return []\n return value.flatMap((item): TextAnnotation[] => {\n if (typeof item !== 'object' || item === null) return []\n const annotation = item as WireAnnotation\n if (annotation.type !== 'url_citation' || typeof annotation.url !== 'string') return []\n return [{\n type: 'url-citation',\n url: annotation.url,\n ...(typeof annotation.title === 'string' ? { title: annotation.title } : {}),\n ...(typeof annotation.start_index === 'number' ? { startIndex: annotation.start_index } : {}),\n ...(typeof annotation.end_index === 'number' ? { endIndex: annotation.end_index } : {}),\n providerState: structuredClone(annotation),\n }]\n })\n}\n\nfunction contentAnnotations(contents: readonly WireContent[]): TextAnnotation[] {\n return contents.flatMap(item => item.type === 'text' ? annotationsOf(item.annotations) : [])\n}\n\nfunction createOpenStep(step: WireStepData, index: number): OpenStep | undefined {\n const kind = stepKind(step.type)\n if (kind === undefined) return undefined\n const content = contentList(step.content)\n const summary = contentList(step.summary)\n return {\n index,\n kind,\n text: kind === 'text' ? textOf(content) : kind === 'reasoning' ? textOf(summary) : '',\n arguments: '',\n initialArguments: step.arguments,\n callId: step.id ?? `call-${index}`,\n name: step.name ?? '',\n signature: step.signature,\n summary,\n annotations: contentAnnotations(content),\n }\n}\n\nfunction blockOf(step: OpenStep): ContentBlock {\n if (step.kind === 'text') {\n return {\n type: 'text', text: step.text,\n ...(step.annotations.length === 0 ? {} : { annotations: step.annotations }),\n }\n }\n if (step.kind === 'reasoning') {\n const state: GeminiThoughtState = {\n ...(step.signature === undefined ? {} : { signature: step.signature }),\n ...(step.summary.length === 0 ? {} : { summary: step.summary }),\n }\n return { type: 'reasoning', text: step.text, providerState: state }\n }\n const argumentsText = step.arguments.length > 0\n ? step.arguments\n : jsonArguments(step.initialArguments)\n return {\n type: 'tool-call', id: ToolCallId(step.callId), name: step.name,\n arguments: argumentsText,\n }\n}\n\nfunction jsonArguments(value: unknown): string {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return '{}'\n return JSON.stringify(value)\n}\n\nfunction thoughtSummaryContent(value: unknown): WireContent[] {\n if (Array.isArray(value)) return contentList(value)\n if (typeof value === 'object' && value !== null) return contentList([value])\n return []\n}\n\nfunction mapUsage(usage: WireUsage): UsageCounters | undefined {\n const source = usage as unknown as Record<string, unknown>\n const rawInput = source.total_input_tokens\n const visibleOutput = source.total_output_tokens\n const cached = source.total_cached_tokens\n const reasoning = source.total_thought_tokens\n const total = source.total_tokens\n if ([rawInput, visibleOutput, cached, reasoning, total].every(value => value === undefined)) return undefined\n\n // Gemini reports thought tokens beside visible output, while the SDK models\n // reasoning as a subset of the full output bucket. Fold them into output once,\n // then retain the subset for cost breakdowns.\n const output = typeof visibleOutput === 'number' && typeof reasoning === 'number'\n ? visibleOutput + reasoning\n : visibleOutput\n\n const normalized: Record<string, unknown> = {\n ...(output === undefined ? {} : { outputTokens: output }),\n ...(total === undefined ? {} : { totalTokens: total }),\n ...(cached === undefined || cached === 0 ? {} : { cacheReadTokens: cached }),\n ...(reasoning === undefined || reasoning === 0 ? {} : { reasoningTokens: reasoning }),\n }\n if (rawInput !== undefined) {\n normalized.inputTokens = typeof rawInput === 'number'\n && (cached === undefined || typeof cached === 'number')\n ? rawInput - (cached ?? 0)\n : rawInput\n }\n return normalized as UsageCounters\n}\n\nfunction errorCode(code: string | undefined, message: string): string {\n const joined = `${code ?? ''} ${message}`.toLowerCase()\n if (/context|token limit|too many tokens/.test(joined)) return CONTEXT_WINDOW_EXCEEDED_CODE\n if (/quota|resource_exhausted/.test(joined)) return QUOTA_EXCEEDED_CODE\n if (/invalid_argument|bad request/.test(joined)) return MODEL_ERROR_CODES.INVALID_REQUEST\n if (/rate|too many requests/.test(joined)) return MODEL_ERROR_CODES.RATE_LIMIT\n return MODEL_ERROR_CODES.SERVER\n}\n\nfunction streamError(event: WireStreamEvent, displayName: string): ModelError {\n const message = event.error?.message ?? `${displayName} reported a streaming error`\n return new ModelError(message, errorCode(event.error?.code, message))\n}\n\nfunction finishReason(interaction: WireInteraction | undefined, sawToolCall: boolean): FinishReason {\n const status = interaction?.status\n if (status === 'requires_action' || sawToolCall) return { kind: 'tool-calls' }\n if (status === 'incomplete' || status === 'budget_exceeded') return { kind: 'max-tokens' }\n return { kind: 'stop' }\n}\n\nexport async function* translateGeminiInteractionsStream(\n events: AsyncIterable<ProtocolSseEvent>,\n displayName: string,\n _request?: ProtocolRequest,\n): AsyncGenerator<ProtocolStreamChunk> {\n const open = new Map<number, OpenStep>()\n let nextIndex = 0\n let sawToolCall = false\n\n for await (const raw of events) {\n if (raw.data === '[DONE]') continue\n let event: WireStreamEvent\n try {\n event = JSON.parse(raw.data) as WireStreamEvent\n } catch (error: unknown) {\n throw new ModelError(\n `${displayName} sent a malformed stream event`,\n MODEL_ERROR_CODES.MALFORMED_RESPONSE,\n { cause: error },\n )\n }\n const eventType = event.event_type ?? raw.event\n\n if (eventType === 'step.start') {\n if (event.index === undefined || event.step === undefined || open.has(event.index)) continue\n const step = createOpenStep(event.step, nextIndex++)\n if (step === undefined) continue\n open.set(event.index, step)\n if (step.kind === 'tool-call') sawToolCall = true\n yield { type: 'block-start', index: step.index, blockType: step.kind }\n if (step.text.length > 0) {\n yield step.kind === 'reasoning'\n ? { type: 'reasoning-delta', index: step.index, text: step.text }\n : { type: 'text-delta', index: step.index, text: step.text }\n }\n continue\n }\n\n if (eventType === 'step.delta') {\n const step = event.index === undefined ? undefined : open.get(event.index)\n if (step === undefined || event.delta === undefined) continue\n const delta = event.delta\n if (delta.type === 'text' && typeof delta.text === 'string' && step.kind === 'text') {\n step.text += delta.text\n yield { type: 'text-delta', index: step.index, text: delta.text }\n } else if (delta.type === 'arguments_delta' && typeof delta.arguments === 'string'\n && step.kind === 'tool-call') {\n step.arguments += delta.arguments\n yield {\n type: 'tool-call-delta', index: step.index, id: ToolCallId(step.callId),\n ...(step.name.length === 0 ? {} : { name: step.name }),\n argumentsDelta: delta.arguments,\n }\n } else if (delta.type === 'thought_signature' && typeof delta.signature === 'string'\n && step.kind === 'reasoning') {\n step.signature = delta.signature\n } else if (delta.type === 'thought_summary' && step.kind === 'reasoning') {\n const content = thoughtSummaryContent(delta.content)\n const text = textOf(content)\n step.summary.push(...content)\n step.text += text\n if (text.length > 0) yield { type: 'reasoning-delta', index: step.index, text }\n } else if (delta.type === 'text_annotation_delta' && step.kind === 'text') {\n step.annotations.push(...annotationsOf(delta.annotations))\n }\n continue\n }\n\n if (eventType === 'step.stop') {\n const step = event.index === undefined ? undefined : open.get(event.index)\n if (step === undefined) continue\n yield { type: 'block-end', index: step.index, block: blockOf(step) }\n open.delete(event.index!)\n continue\n }\n\n if (eventType === 'error') throw streamError(event, displayName)\n\n if (eventType === 'interaction.completed') {\n const interaction = event.interaction\n if (interaction?.status === 'failed' || interaction?.status === 'cancelled') {\n throw new ModelError(\n `${displayName} interaction ${interaction.status}`,\n MODEL_ERROR_CODES.SERVER,\n )\n }\n // Close any step defensively if a provider omitted its `step.stop` frame.\n for (const step of open.values()) {\n yield { type: 'block-end', index: step.index, block: blockOf(step) }\n }\n const usage = interaction?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n yield { type: 'finish', reason: finishReason(interaction, sawToolCall) }\n return\n }\n }\n\n throw new ModelError(\n `${displayName} stream ended before the interaction completed`,\n MODEL_ERROR_CODES.STREAM_CLOSED,\n )\n}\n","import type { ProtocolDefinition, ProtocolRequest, ProtocolSseEvent, ProtocolStreamChunk } from './contract.ts'\nimport { serializeGeminiInteractionsRequest } from './serialize.ts'\nimport { translateGeminiInteractionsStream } from './translate.ts'\nimport type { GeminiInteractionsDialect } from './wire.ts'\n\nexport const GEMINI_INTERACTIONS_PROTOCOL_ID = 'gemini-interactions'\n\nconst DEFAULT_DIALECT: GeminiInteractionsDialect = Object.freeze({\n store: false,\n thinkingSummaries: 'auto',\n})\n\nexport interface GeminiInteractionsProtocolDefinition {\n readonly kind: 'http-wire-protocol'\n readonly apiVersion: 1\n readonly id: string\n readonly defaultDialect: GeminiInteractionsDialect\n readonly endpointPath: () => '/interactions'\n readonly serialize: (\n request: ProtocolRequest,\n dialect: GeminiInteractionsDialect,\n ) => Readonly<Record<string, unknown>>\n readonly translate: (\n events: AsyncIterable<ProtocolSseEvent>,\n request: ProtocolRequest,\n displayName: string,\n ) => AsyncGenerator<ProtocolStreamChunk>\n}\n\nexport const geminiInteractionsProtocol: ProtocolDefinition<GeminiInteractionsDialect>\n & GeminiInteractionsProtocolDefinition = Object.freeze({\n kind: 'http-wire-protocol' as const,\n apiVersion: 1 as const,\n id: GEMINI_INTERACTIONS_PROTOCOL_ID,\n defaultDialect: DEFAULT_DIALECT,\n endpointPath: () => '/interactions' as const,\n serialize(request: ProtocolRequest, dialect: GeminiInteractionsDialect): Readonly<Record<string, unknown>> {\n return serializeGeminiInteractionsRequest(request, dialect) as unknown as Readonly<Record<string, unknown>>\n },\n translate: (\n events: AsyncIterable<ProtocolSseEvent>,\n request: ProtocolRequest,\n displayName: string,\n ): AsyncGenerator<ProtocolStreamChunk> => translateGeminiInteractionsStream(events, displayName, request),\n})\n"],"mappings":";;;AA4BA,SAAS,aAAa,OAAgC;CACpD,MAAM,aAAa,MAAM,WAAW,SAAS,MAAM,WAAW,SAC1D,MAAM,SACN;CACJ,IAAI,MAAM,OAAO,SAAS,UACxB,OAAO;EACL,MAAM;EAAS,MAAM,MAAM,OAAO;EAAM,WAAW,MAAM,OAAO;EAChE,GAAI,eAAe,SAAY,CAAC,IAAI,EAAE,WAAW;CACnD;CAEF,OAAO;EACL,MAAM;EAAS,KAAK,MAAM,OAAO,SAAS,QAAQ,MAAM,OAAO,MAAM,MAAM,OAAO;EAClF,GAAI,eAAe,SAAY,CAAC,IAAI,EAAE,WAAW;CACnD;AACF;AAEA,SAAS,gBAAgB,OAAmC;CAC1D,IAAI,MAAM,OAAO,SAAS,UACxB,OAAO;EAAE,MAAM;EAAY,MAAM,MAAM,OAAO;EAAM,WAAW,MAAM,OAAO;CAAU;C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AS,UAAU,SAAY,SAAY,SAAS,KAAK;GAC/D,IAAI,WAAW,QAAW,MAAM;IAAE,MAAM;IAAS,OAAO;GAAO;GAC/D,MAAM;IAAE,MAAM;IAAU,QAAQ,aAAa,aAAa,WAAW;GAAE;GACvE;EACF;CACF;CAEA,MAAM,IAAI,WACR,GAAG,YAAY,iDACf,kBAAkB,aACpB;AACF;;;;ACvRA,MAAa,kCAAkC;AAE/C,MAAM,kBAA6C,OAAO,OAAO;CAC/D,OAAO;CACP,mBAAmB;AACrB,CAAC;AAmBD,MAAa,6BAC8B,OAAO,OAAO;CACvD,MAAM;CACN,YAAY;CACZ,IAAI;CACJ,gBAAgB;CAChB,oBAAoB;CACpB,UAAU,SAA0B,SAAuE;EACzG,OAAO,mCAAmC,SAAS,OAAO;CAC5D;CACA,YACE,QACA,SACA,gBACwC,kCAAkC,QAAQ,aAAa,OAAO;AAC1G,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/serialize.ts","../src/translate.ts","../src/protocol.ts"],"sourcesContent":["import {\n isNativeToolSchema,\n MODEL_ERROR_CODES,\n ModelError,\n type ContentBlock,\n type DocumentBlock,\n type ImageBlock,\n type Message,\n type ModelOutputFormat,\n type ModelToolSchema,\n type NativeWebSearchTool,\n type TextAnnotation,\n type ToolChoice,\n type ToolSchema,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest } from './contract.ts'\nimport type {\n GeminiInteractionsDialect,\n GeminiThoughtState,\n WireContent,\n WireGenerationConfig,\n WireRequest,\n WireResponseFormat,\n WireStep,\n WireTool,\n WireToolChoice,\n} from './wire.ts'\n\nfunction imageContent(block: ImageBlock): WireContent {\n const resolution = block.detail === 'low' || block.detail === 'high'\n ? block.detail\n : undefined\n if (block.source.kind === 'base64') {\n return {\n type: 'image', data: block.source.data, mime_type: block.source.mediaType,\n ...(resolution === undefined ? {} : { resolution }),\n }\n }\n return {\n type: 'image', uri: block.source.kind === 'url' ? block.source.url : block.source.fileId,\n ...(resolution === undefined ? {} : { resolution }),\n }\n}\n\nfunction documentContent(block: DocumentBlock): WireContent {\n if (block.source.kind === 'base64') {\n return { type: 'document', data: block.source.data, mime_type: block.source.mediaType }\n }\n // This API collapses \"remote URL\" and \"uploaded file\" into one `uri`, exactly as\n // it does for images.\n return {\n type: 'document',\n uri: block.source.kind === 'url' ? block.source.url : block.source.fileId,\n mime_type: 'application/pdf',\n }\n}\n\nfunction annotationOf(annotation: TextAnnotation) {\n if (annotation.type !== 'url-citation') return undefined\n return {\n type: 'url_citation',\n url: annotation.url,\n ...(annotation.title === undefined ? {} : { title: annotation.title }),\n ...(annotation.startIndex === undefined ? {} : { start_index: annotation.startIndex }),\n ...(annotation.endIndex === undefined ? {} : { end_index: annotation.endIndex }),\n }\n}\n\nfunction contentOf(block: ContentBlock): WireContent | undefined {\n if (block.type === 'text') {\n const annotations = block.annotations?.map(annotationOf)\n .filter((item): item is NonNullable<typeof item> => item !== undefined)\n return {\n type: 'text', text: block.text,\n ...(annotations === undefined || annotations.length === 0 ? {} : { annotations }),\n }\n }\n if (block.type === 'image') return imageContent(block)\n if (block.type === 'document') return documentContent(block)\n return undefined\n}\n\nfunction thoughtStateOf(value: unknown): GeminiThoughtState {\n if (typeof value !== 'object' || value === null) return {}\n const state = value as GeminiThoughtState\n return {\n ...(typeof state.signature === 'string' ? { signature: state.signature } : {}),\n ...(Array.isArray(state.summary) ? { summary: structuredClone(state.summary) } : {}),\n }\n}\n\nfunction argumentsObject(raw: string): Record<string, unknown> {\n if (raw.length === 0) return {}\n let value: unknown\n try {\n value = JSON.parse(raw)\n } catch (error: unknown) {\n throw new ModelError(\n 'Gemini Interactions requires function-call arguments to be a JSON object',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n { cause: error },\n )\n }\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new ModelError(\n 'Gemini Interactions requires function-call arguments to be a JSON object',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return value as Record<string, unknown>\n}\n\nfunction toolResult(\n block: Extract<ContentBlock, { type: 'tool-result' }>,\n toolNames: ReadonlyMap<string, string>,\n): WireStep {\n const contents = block.content.map(contentOf)\n .filter((item): item is WireContent => item !== undefined)\n const name = toolNames.get(block.toolCallId)\n return {\n type: 'function_result',\n call_id: block.toolCallId,\n ...(name === undefined ? {} : { name }),\n result: contents,\n ...(block.isError === undefined ? {} : { is_error: block.isError }),\n }\n}\n\nfunction appendUserMessage(\n message: Message,\n output: WireStep[],\n toolNames: ReadonlyMap<string, string>,\n): void {\n let content: WireContent[] = []\n const flush = (): void => {\n if (content.length === 0) return\n output.push({ type: 'user_input', content })\n content = []\n }\n for (const block of message.content) {\n if (block.type === 'tool-result') {\n flush()\n output.push(toolResult(block, toolNames))\n continue\n }\n const mapped = contentOf(block)\n if (mapped !== undefined) content.push(mapped)\n }\n flush()\n}\n\nfunction appendAssistantMessage(message: Message, output: WireStep[]): void {\n let content: WireContent[] = []\n const flush = (): void => {\n if (content.length === 0) return\n output.push({ type: 'model_output', content })\n content = []\n }\n for (const block of message.content) {\n if (block.type === 'text' || block.type === 'image' || block.type === 'document') {\n const mapped = contentOf(block)\n if (mapped !== undefined) content.push(mapped)\n continue\n }\n flush()\n if (block.type === 'reasoning') {\n const state = thoughtStateOf(block.providerState)\n const summary = state.summary ?? (block.text.length === 0\n ? undefined\n : [{ type: 'text' as const, text: block.text }])\n output.push({\n type: 'thought',\n ...(state.signature === undefined ? {} : { signature: state.signature }),\n ...(summary === undefined || summary.length === 0 ? {} : { summary: [...summary] }),\n })\n } else if (block.type === 'tool-call') {\n output.push({\n type: 'function_call', id: block.id, name: block.name,\n arguments: argumentsObject(block.arguments),\n })\n }\n }\n flush()\n}\n\nfunction inputOf(request: ProtocolRequest): WireStep[] {\n const output: WireStep[] = []\n const toolNames = new Map<string, string>()\n for (const message of request.options.messages) {\n for (const block of message.content) {\n if (block.type === 'tool-call') toolNames.set(block.id, block.name)\n }\n }\n for (const message of request.options.messages) {\n if (message.role === 'system') continue\n if (message.role === 'assistant') appendAssistantMessage(message, output)\n else appendUserMessage(message, output, toolNames)\n }\n return output\n}\n\nfunction systemInstructionOf(request: ProtocolRequest): string {\n const messages = request.options.messages\n .filter(message => message.role === 'system')\n .flatMap(message => message.content)\n .filter((block): block is Extract<ContentBlock, { type: 'text' }> => block.type === 'text')\n .map(block => block.text)\n return [request.options.system, ...messages]\n .filter((value): value is string => value !== undefined && value.length > 0)\n .join('\\n\\n')\n}\n\nfunction functionTool(tool: ToolSchema): WireTool {\n return {\n type: 'function', name: tool.name, description: tool.description,\n parameters: tool.parameters,\n }\n}\n\nfunction googleSearchTool(tool: NativeWebSearchTool): WireTool {\n if (tool.searchContextSize !== undefined || tool.allowedDomains !== undefined\n || tool.blockedDomains !== undefined || tool.userLocation !== undefined\n || tool.maxUses !== undefined) {\n throw new ModelError(\n 'Gemini Interactions web search does not support SDK search filters or limits',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return { type: 'google_search', search_types: ['web_search'] }\n}\n\nfunction toolOf(tool: ModelToolSchema): WireTool {\n if (!isNativeToolSchema(tool)) return functionTool(tool)\n if (tool.name === 'web-search') return googleSearchTool(tool)\n throw new ModelError(\n 'Gemini Interactions does not expose image generation as an SDK native tool',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n}\n\nfunction toolChoiceOf(choice: ToolChoice): WireToolChoice {\n if (choice === 'required') return 'any'\n if (typeof choice === 'string') return choice\n const name = choice.type === 'native' && choice.name === 'web-search'\n ? 'google_search'\n : choice.name\n return { allowed_tools: { mode: 'any', tools: [name] } }\n}\n\nfunction responseFormatOf(format: ModelOutputFormat | undefined): WireResponseFormat | undefined {\n if (format === undefined) return undefined\n if (format.type === 'text') return { type: 'text', mime_type: 'text/plain' }\n return { type: 'text', mime_type: 'application/json', schema: format.schema }\n}\n\nfunction generationConfigOf(\n request: ProtocolRequest,\n dialect: GeminiInteractionsDialect,\n): WireGenerationConfig {\n const options = request.options\n return {\n ...(request.maxTokens === undefined ? {} : { max_output_tokens: request.maxTokens }),\n ...(options.temperature === undefined ? {} : { temperature: options.temperature }),\n ...(options.topP === undefined ? {} : { top_p: options.topP }),\n ...(options.stop === undefined || options.stop.length === 0\n ? {}\n : { stop_sequences: [...options.stop] }),\n ...(options.reasoningEffort === undefined\n ? {}\n : {\n thinking_level: String(options.reasoningEffort),\n thinking_summaries: dialect.thinkingSummaries,\n }),\n ...(options.toolChoice === undefined ? {} : { tool_choice: toolChoiceOf(options.toolChoice) }),\n }\n}\n\nexport function serializeGeminiInteractionsRequest(\n request: ProtocolRequest,\n dialect: GeminiInteractionsDialect,\n): WireRequest {\n const systemInstruction = systemInstructionOf(request)\n const tools = request.options.tools?.map(toolOf)\n const responseFormat = responseFormatOf(request.options.outputFormat)\n return {\n model: request.options.model,\n input: inputOf(request),\n ...(systemInstruction.length === 0 ? {} : { system_instruction: systemInstruction }),\n ...(tools === undefined || tools.length === 0 ? {} : { tools }),\n ...(responseFormat === undefined ? {} : { response_format: responseFormat }),\n stream: true,\n store: dialect.store,\n generation_config: generationConfigOf(request, dialect),\n }\n}\n","import {\n CONTEXT_WINDOW_EXCEEDED_CODE,\n MODEL_ERROR_CODES,\n ModelError,\n QUOTA_EXCEEDED_CODE,\n ToolCallId,\n type ContentBlock,\n type FinishReason,\n type TextAnnotation,\n type UsageCounters,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest, ProtocolSseEvent, ProtocolStreamChunk } from './contract.ts'\nimport type {\n GeminiThoughtState,\n WireAnnotation,\n WireContent,\n WireInteraction,\n WireStepData,\n WireStreamEvent,\n WireUsage,\n} from './wire.ts'\n\ntype StepKind = 'text' | 'reasoning' | 'tool-call'\n\ninterface OpenStep {\n readonly index: number\n readonly kind: StepKind\n text: string\n arguments: string\n readonly initialArguments: unknown\n callId: string\n name: string\n signature: string | undefined\n summary: WireContent[]\n annotations: TextAnnotation[]\n}\n\nfunction stepKind(type: string | undefined): StepKind | undefined {\n if (type === 'model_output') return 'text'\n if (type === 'thought') return 'reasoning'\n if (type === 'function_call') return 'tool-call'\n return undefined\n}\n\nfunction contentList(value: unknown): WireContent[] {\n if (!Array.isArray(value)) return []\n return value.filter((item): item is WireContent => typeof item === 'object' && item !== null\n && ((item as { type?: unknown }).type === 'text' || (item as { type?: unknown }).type === 'image'))\n}\n\nfunction textOf(contents: readonly WireContent[]): string {\n return contents.filter((item): item is Extract<WireContent, { type: 'text' }> => item.type === 'text')\n .map(item => item.text)\n .join('')\n}\n\nfunction annotationsOf(value: unknown): TextAnnotation[] {\n if (!Array.isArray(value)) return []\n return value.flatMap((item): TextAnnotation[] => {\n if (typeof item !== 'object' || item === null) return []\n const annotation = item as WireAnnotation\n if (annotation.type !== 'url_citation' || typeof annotation.url !== 'string') return []\n return [{\n type: 'url-citation',\n url: annotation.url,\n ...(typeof annotation.title === 'string' ? { title: annotation.title } : {}),\n ...(typeof annotation.start_index === 'number' ? { startIndex: annotation.start_index } : {}),\n ...(typeof annotation.end_index === 'number' ? { endIndex: annotation.end_index } : {}),\n providerState: structuredClone(annotation),\n }]\n })\n}\n\nfunction contentAnnotations(contents: readonly WireContent[]): TextAnnotation[] {\n return contents.flatMap(item => item.type === 'text' ? annotationsOf(item.annotations) : [])\n}\n\nfunction createOpenStep(step: WireStepData, index: number): OpenStep | undefined {\n const kind = stepKind(step.type)\n if (kind === undefined) return undefined\n const content = contentList(step.content)\n const summary = contentList(step.summary)\n return {\n index,\n kind,\n text: kind === 'text' ? textOf(content) : kind === 'reasoning' ? textOf(summary) : '',\n arguments: '',\n initialArguments: step.arguments,\n callId: step.id ?? `call-${index}`,\n name: step.name ?? '',\n signature: step.signature,\n summary,\n annotations: contentAnnotations(content),\n }\n}\n\nfunction blockOf(step: OpenStep): ContentBlock {\n if (step.kind === 'text') {\n return {\n type: 'text', text: step.text,\n ...(step.annotations.length === 0 ? {} : { annotations: step.annotations }),\n }\n }\n if (step.kind === 'reasoning') {\n const state: GeminiThoughtState = {\n ...(step.signature === undefined ? {} : { signature: step.signature }),\n ...(step.summary.length === 0 ? {} : { summary: step.summary }),\n }\n return { type: 'reasoning', text: step.text, providerState: state }\n }\n const argumentsText = step.arguments.length > 0\n ? step.arguments\n : jsonArguments(step.initialArguments)\n return {\n type: 'tool-call', id: ToolCallId(step.callId), name: step.name,\n arguments: argumentsText,\n }\n}\n\nfunction jsonArguments(value: unknown): string {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return '{}'\n return JSON.stringify(value)\n}\n\nfunction thoughtSummaryContent(value: unknown): WireContent[] {\n if (Array.isArray(value)) return contentList(value)\n if (typeof value === 'object' && value !== null) return contentList([value])\n return []\n}\n\nfunction mapUsage(usage: WireUsage): UsageCounters | undefined {\n const source = usage as unknown as Record<string, unknown>\n const rawInput = source.total_input_tokens\n const visibleOutput = source.total_output_tokens\n const cached = source.total_cached_tokens\n const reasoning = source.total_thought_tokens\n const total = source.total_tokens\n if ([rawInput, visibleOutput, cached, reasoning, total].every(value => value === undefined)) return undefined\n\n // Gemini reports thought tokens beside visible output, while the SDK models\n // reasoning as a subset of the full output bucket. Fold them into output once,\n // then retain the subset for cost breakdowns.\n const output = typeof visibleOutput === 'number' && typeof reasoning === 'number'\n ? visibleOutput + reasoning\n : visibleOutput\n\n const normalized: Record<string, unknown> = {\n ...(output === undefined ? {} : { outputTokens: output }),\n ...(total === undefined ? {} : { totalTokens: total }),\n ...(cached === undefined || cached === 0 ? {} : { cacheReadTokens: cached }),\n ...(reasoning === undefined || reasoning === 0 ? {} : { reasoningTokens: reasoning }),\n }\n if (rawInput !== undefined) {\n normalized.inputTokens = typeof rawInput === 'number'\n && (cached === undefined || typeof cached === 'number')\n ? rawInput - (cached ?? 0)\n : rawInput\n }\n return normalized as UsageCounters\n}\n\nfunction errorCode(code: string | undefined, message: string): string {\n const joined = `${code ?? ''} ${message}`.toLowerCase()\n if (/context|token limit|too many tokens/.test(joined)) return CONTEXT_WINDOW_EXCEEDED_CODE\n if (/quota|resource_exhausted/.test(joined)) return QUOTA_EXCEEDED_CODE\n if (/invalid_argument|bad request/.test(joined)) return MODEL_ERROR_CODES.INVALID_REQUEST\n if (/rate|too many requests/.test(joined)) return MODEL_ERROR_CODES.RATE_LIMIT\n return MODEL_ERROR_CODES.SERVER\n}\n\nfunction streamError(event: WireStreamEvent, displayName: string): ModelError {\n const message = event.error?.message ?? `${displayName} reported a streaming error`\n return new ModelError(message, errorCode(event.error?.code, message))\n}\n\nfunction finishReason(interaction: WireInteraction | undefined, sawToolCall: boolean): FinishReason {\n const status = interaction?.status\n if (status === 'requires_action' || sawToolCall) return { kind: 'tool-calls' }\n if (status === 'incomplete' || status === 'budget_exceeded') return { kind: 'max-tokens' }\n return { kind: 'stop' }\n}\n\nexport async function* translateGeminiInteractionsStream(\n events: AsyncIterable<ProtocolSseEvent>,\n displayName: string,\n _request?: ProtocolRequest,\n): AsyncGenerator<ProtocolStreamChunk> {\n const open = new Map<number, OpenStep>()\n let nextIndex = 0\n let sawToolCall = false\n\n for await (const raw of events) {\n if (raw.data === '[DONE]') continue\n let event: WireStreamEvent\n try {\n event = JSON.parse(raw.data) as WireStreamEvent\n } catch (error: unknown) {\n throw new ModelError(\n `${displayName} sent a malformed stream event`,\n MODEL_ERROR_CODES.MALFORMED_RESPONSE,\n { cause: error },\n )\n }\n const eventType = event.event_type ?? raw.event\n\n if (eventType === 'step.start') {\n if (event.index === undefined || event.step === undefined || open.has(event.index)) continue\n const step = createOpenStep(event.step, nextIndex++)\n if (step === undefined) continue\n open.set(event.index, step)\n if (step.kind === 'tool-call') sawToolCall = true\n yield { type: 'block-start', index: step.index, blockType: step.kind }\n if (step.text.length > 0) {\n yield step.kind === 'reasoning'\n ? { type: 'reasoning-delta', index: step.index, text: step.text }\n : { type: 'text-delta', index: step.index, text: step.text }\n }\n continue\n }\n\n if (eventType === 'step.delta') {\n const step = event.index === undefined ? undefined : open.get(event.index)\n if (step === undefined || event.delta === undefined) continue\n const delta = event.delta\n if (delta.type === 'text' && typeof delta.text === 'string' && step.kind === 'text') {\n step.text += delta.text\n yield { type: 'text-delta', index: step.index, text: delta.text }\n } else if (delta.type === 'arguments_delta' && typeof delta.arguments === 'string'\n && step.kind === 'tool-call') {\n step.arguments += delta.arguments\n yield {\n type: 'tool-call-delta', index: step.index, id: ToolCallId(step.callId),\n ...(step.name.length === 0 ? {} : { name: step.name }),\n argumentsDelta: delta.arguments,\n }\n } else if (delta.type === 'thought_signature' && typeof delta.signature === 'string'\n && step.kind === 'reasoning') {\n step.signature = delta.signature\n } else if (delta.type === 'thought_summary' && step.kind === 'reasoning') {\n const content = thoughtSummaryContent(delta.content)\n const text = textOf(content)\n step.summary.push(...content)\n step.text += text\n if (text.length > 0) yield { type: 'reasoning-delta', index: step.index, text }\n } else if (delta.type === 'text_annotation_delta' && step.kind === 'text') {\n step.annotations.push(...annotationsOf(delta.annotations))\n }\n continue\n }\n\n if (eventType === 'step.stop') {\n const step = event.index === undefined ? undefined : open.get(event.index)\n if (step === undefined) continue\n yield { type: 'block-end', index: step.index, block: blockOf(step) }\n open.delete(event.index!)\n continue\n }\n\n if (eventType === 'error') throw streamError(event, displayName)\n\n if (eventType === 'interaction.completed') {\n const interaction = event.interaction\n if (interaction?.status === 'failed' || interaction?.status === 'cancelled') {\n throw new ModelError(\n `${displayName} interaction ${interaction.status}`,\n MODEL_ERROR_CODES.SERVER,\n )\n }\n // Close any step defensively if a provider omitted its `step.stop` frame.\n for (const step of open.values()) {\n yield { type: 'block-end', index: step.index, block: blockOf(step) }\n }\n const usage = interaction?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n yield { type: 'finish', reason: finishReason(interaction, sawToolCall) }\n return\n }\n }\n\n throw new ModelError(\n `${displayName} stream ended before the interaction completed`,\n MODEL_ERROR_CODES.STREAM_CLOSED,\n )\n}\n","import type { ProtocolDefinition, ProtocolRequest, ProtocolSseEvent, ProtocolStreamChunk } from './contract.ts'\nimport { serializeGeminiInteractionsRequest } from './serialize.ts'\nimport { translateGeminiInteractionsStream } from './translate.ts'\nimport type { GeminiInteractionsDialect } from './wire.ts'\n\nexport const GEMINI_INTERACTIONS_PROTOCOL_ID = 'gemini-interactions'\n\nconst DEFAULT_DIALECT: GeminiInteractionsDialect = Object.freeze({\n store: false,\n thinkingSummaries: 'auto',\n})\n\nexport interface GeminiInteractionsProtocolDefinition {\n readonly kind: 'http-wire-protocol'\n readonly apiVersion: 1\n readonly id: string\n readonly defaultDialect: GeminiInteractionsDialect\n readonly endpointPath: () => '/interactions'\n readonly serialize: (\n request: ProtocolRequest,\n dialect: GeminiInteractionsDialect,\n ) => Readonly<Record<string, unknown>>\n readonly translate: (\n events: AsyncIterable<ProtocolSseEvent>,\n request: ProtocolRequest,\n displayName: string,\n ) => AsyncGenerator<ProtocolStreamChunk>\n}\n\nexport const geminiInteractionsProtocol: ProtocolDefinition<GeminiInteractionsDialect>\n & GeminiInteractionsProtocolDefinition = Object.freeze({\n kind: 'http-wire-protocol' as const,\n apiVersion: 1 as const,\n id: GEMINI_INTERACTIONS_PROTOCOL_ID,\n defaultDialect: DEFAULT_DIALECT,\n endpointPath: () => '/interactions' as const,\n serialize(request: ProtocolRequest, dialect: GeminiInteractionsDialect): Readonly<Record<string, unknown>> {\n return serializeGeminiInteractionsRequest(request, dialect) as unknown as Readonly<Record<string, unknown>>\n },\n translate: (\n events: AsyncIterable<ProtocolSseEvent>,\n request: ProtocolRequest,\n displayName: string,\n ): AsyncGenerator<ProtocolStreamChunk> => translateGeminiInteractionsStream(events, displayName, request),\n})\n"],"mappings":";;;AA4BA,SAAS,aAAa,OAAgC;CACpD,MAAM,aAAa,MAAM,WAAW,SAAS,MAAM,WAAW,SAC1D,MAAM,SACN;CACJ,IAAI,MAAM,OAAO,SAAS,UACxB,OAAO;EACL,MAAM;EAAS,MAAM,MAAM,OAAO;EAAM,WAAW,MAAM,OAAO;EAChE,GAAI,eAAe,SAAY,CAAC,IAAI,EAAE,WAAW;CACnD;CAE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AO,WAAW;EAE/D,IAAI,cAAc,yBAAyB;GACzC,MAAM,cAAc,MAAM;GAC1B,IAAI,aAAa,WAAW,YAAY,aAAa,WAAW,aAC9D,MAAM,IAAI,WACR,GAAG,YAAY,eAAe,YAAY,UAC1C,kBAAkB,MACpB;GAGF,KAAK,MAAM,QAAQ,KAAK,OAAO,GAC7B,MAAM;IAAE,MAAM;IAAa,OAAO,KAAK;IAAO,OAAO,QAAQ,IAAI;GAAE;GAErE,MAAM,QAAQ,aAAa,SAAS;GACpC,MAAM,SAAS,UAAU,SAAY,SAAY,SAAS,KAAK;GAC/D,IAAI,WAAW,QAAW,MAAM;IAAE,MAAM;IAAS,OAAO;GAAO;GAC/D,MAAM;IAAE,MAAM;IAAU,QAAQ,aAAa,aAAa,WAAW;GAAE;GACvE;EACF;CACF;CAEA,MAAM,IAAI,WACR,GAAG,YAAY,iDACf,kBAAkB,aACpB;AACF;;;;ACvRA,MAAa,kCAAkC;AAE/C,MAAM,kBAA6C,OAAO,OAAO;CAC/D,OAAO;CACP,mBAAmB;AACrB,CAAC;AAmBD,MAAa,6BAC8B,OAAO,OAAO;CACvD,MAAM;CACN,YAAY;CACZ,IAAI;CACJ,gBAAgB;CAChB,oBAAoB;CACpB,UAAU,SAA0B,SAAuE;EACzG,OAAO,mCAAmC,SAAS,OAAO;CAC5D;CACA,YACE,QACA,SACA,gBACwC,kCAAkC,QAAQ,aAAa,OAAO;AAC1G,CAAC"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "alvin0 - chaulamdinhai",
5
5
  "email": "chaulamdinhai@gmail.com"
6
6
  },
7
- "version": "0.1.3",
7
+ "version": "0.1.4",
8
8
  "description": "Universal Gemini Interactions wire schema, serializer, and SSE translator for ai-agent-sdk",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -38,10 +38,10 @@
38
38
  "provenance": true
39
39
  },
40
40
  "peerDependencies": {
41
- "@alvin0/ai-agent-sdk-core": "^0.1.3"
41
+ "@alvin0/ai-agent-sdk-core": "^0.1.4"
42
42
  },
43
43
  "devDependencies": {
44
- "@alvin0/ai-agent-sdk-core": "^0.1.3",
44
+ "@alvin0/ai-agent-sdk-core": "^0.1.4",
45
45
  "@arethetypeswrong/cli": "0.18.5",
46
46
  "playwright": "1.62.1",
47
47
  "publint": "0.3.24",