@mozaik-ai/core 3.14.0 → 4.0.0-beta.10
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 +18 -118
- package/dist/index.d.mts +436 -199
- package/dist/index.d.ts +436 -199
- package/dist/index.js +939 -589
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +926 -581
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/domain/model-context/model-context.ts","../src/domain/model-context/context-item/context-item.ts","../src/domain/model-context/context-item/item-content/item-content.ts","../src/domain/model-context/context-item/item-content/input-text.ts","../src/domain/model-context/context-item/client-item/user-message.ts","../src/domain/model-context/context-item/client-item/developer-message.ts","../src/domain/model-context/context-item/item-content/output-text.ts","../src/domain/model-context/context-item/model-item/model-message.ts","../src/domain/model-context/context-item/model-item/function-call.ts","../src/domain/model-context/context-item/model-item/reasoning.ts","../src/domain/generative-model/request-validation/structured-output.ts","../src/domain/model-context/context-item/client-item/function-call-output.ts","../src/domain/generative-model/token-usage.ts","../src/infrastructure/mcp/mcp-client.ts","../src/infrastructure/mcp/mcp-tool-registry.ts","../src/infrastructure/repository/in-memory-model-context-repository.ts","../src/domain/model-context/context-item/client-item/system-message.ts","../src/domain/agentic-environment/participant.ts","../src/domain/agentic-environment/errors/base-error.ts","../src/domain/agentic-environment/agentic-environment.ts","../src/domain/model-context/semantic-event/semantic-event.ts","../src/domain/agentic-environment/inference/response.ts","../src/application/services/inference-runner.ts","../src/application/use-cases/run-inference.ts","../src/application/use-cases/execute-function-call.ts","../src/application/services/function-call-runner.ts","../src/application/participants/participant.ts","../src/application/use-cases/send-message.ts","../src/infrastructure/providers/anthropic/endpoints/anthropic-messages-mapper.ts","../src/infrastructure/providers/anthropic/endpoints/anthropic-messages.ts","../src/infrastructure/providers/openai/endpoints/openai-responses.ts","../src/domain/model-context/context-item/item-content/summary-text.ts","../src/infrastructure/providers/openai/endpoints/openai-responses-mapper.ts","../src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts","../src/infrastructure/providers/gemini/endpoints/gemini-generate-content-mapper.ts","../src/infrastructure/providers/openai/endpoints/openai-chat-completions-mapper.ts","../src/infrastructure/providers/openai/endpoints/openai-chat-completions.ts","../src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts","../src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts","../src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts","../src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts","../src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts","../src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts","../src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts","../src/infrastructure/providers/openai/models/gpt-5-4.ts","../src/infrastructure/providers/openai/models/gpt-5-4-mini.ts","../src/infrastructure/providers/openai/models/gpt-5-4-nano.ts","../src/infrastructure/providers/openai/models/gpt-5-5.ts","../src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts","../src/infrastructure/repository/generative-model-repository.ts","../src/domain/generative-model/request-validation/reasoning-effort.ts","../src/domain/generative-model/request-validation/tool-calling.ts","../src/domain/generative-model/request-validation/streaming.ts","../src/domain/generative-model/request-validation/context.ts","../src/domain/generative-model/request-validation/inference-request-validator.ts","../src/index.ts"],"sourcesContent":["import type { ContextItem } from \"@domain/model-context/context-item/context-item\"\n\nexport class ModelContext {\n\treadonly id: string\n\treadonly projectId: string\n\treadonly items: ContextItem[]\n\n\tconstructor(id: string, projectId: string, items: ContextItem[]) {\n\t\tthis.projectId = projectId\n\t\tthis.id = id\n\t\tthis.items = items\n\t}\n\n\taddContextItem(item: ContextItem): ModelContext {\n\t\tthis.items.push(item)\n\t\treturn this\n\t}\n\n\tapplyModelOutput(items: ContextItem[]): ModelContext {\n\t\tfor (const item of items) {\n\t\t\tconst itemType = item.getType()\n\t\t\tif (itemType !== \"function_call\" && itemType !== \"message\" && itemType !== \"reasoning\") {\n\t\t\t\tthrow new Error(`Invalid item type: ${itemType}`)\n\t\t\t}\n\t\t}\n\t\tthis.items.push(...items)\n\t\treturn this\n\t}\n\n\tgetItems(): ContextItem[] {\n\t\treturn this.items\n\t}\n\n\tgetLastItem(): ContextItem {\n\t\tif (this.items.length === 0) {\n\t\t\tthrow new Error(\"No items in context\")\n\t\t}\n\t\treturn this.items[this.items.length - 1]\n\t}\n\n\tstatic create(projectId: string): ModelContext {\n\t\tconst id = crypto.randomUUID()\n\t\treturn new ModelContext(id, projectId, [])\n\t}\n\n\tstatic rehydrate(data: { id: string; projectId: string; items: ContextItem[] }): ModelContext {\n\t\treturn new ModelContext(data.id, data.projectId, data.items)\n\t}\n}\n","export abstract class ContextItem {\n\tabstract readonly type: string\n\n\tgetType(): string {\n\t\treturn this.type\n\t}\n}\n","export abstract class ItemContent {\n\tabstract readonly type: string\n}\n","import { ItemContent } from \"@domain/model-context/context-item/item-content/item-content\"\n\nexport class InputText extends ItemContent {\n\treadonly type = \"input_text\"\n\n\tprivate constructor(public readonly text: string) {\n\t\tsuper()\n\t}\n\n\tstatic create(text: string): InputText {\n\t\treturn new InputText(text)\n\t}\n\n\tstatic rehydrate(data: { text: string }): InputText {\n\t\treturn new InputText(data.text)\n\t}\n}\n","import { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\n\nexport class UserMessageItem extends ContextItem {\n\treadonly type = \"message\"\n\treadonly role = \"user\"\n\treadonly content: InputText\n\n\tprivate constructor(content: InputText) {\n\t\tsuper()\n\t\tthis.content = content\n\t}\n\n\tstatic create(text: string): UserMessageItem {\n\t\tconst content = InputText.create(text)\n\t\treturn new UserMessageItem(content)\n\t}\n\n\tstatic rehydrate(data: { text: string }): UserMessageItem {\n\t\tconst content = InputText.rehydrate(data)\n\t\treturn new UserMessageItem(content)\n\t}\n}\n","import { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\nimport { ContextItem } from \"@domain/model-context/context-item/context-item\"\n\nexport class DeveloperMessageItem extends ContextItem {\n\treadonly type = \"message\"\n\treadonly role = \"developer\"\n\treadonly content: InputText\n\n\tprivate constructor(content: InputText) {\n\t\tsuper()\n\t\tthis.content = content\n\t}\n\n\tstatic create(text: string): DeveloperMessageItem {\n\t\tconst content = InputText.create(text)\n\t\treturn new DeveloperMessageItem(content)\n\t}\n\n\tstatic rehydrate(data: { text: string }): DeveloperMessageItem {\n\t\tconst content = InputText.rehydrate(data)\n\t\treturn new DeveloperMessageItem(content)\n\t}\n}\n","import { ItemContent } from \"@domain/model-context/context-item/item-content/item-content\"\n\nexport class OutputText extends ItemContent {\n\treadonly type = \"output_text\"\n\n\tprivate constructor(public readonly text: string) {\n\t\tsuper()\n\t}\n\n\tstatic rehydrate(data: { text: string }): OutputText {\n\t\treturn new OutputText(data.text)\n\t}\n}\n","import { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { OutputText } from \"@domain/model-context/context-item/item-content/output-text\"\n\nexport class ModelMessageItem extends ContextItem {\n\treadonly type = \"message\"\n\treadonly role = \"assistant\"\n\treadonly content: OutputText\n\n\tprivate constructor(content: OutputText) {\n\t\tsuper()\n\t\tthis.content = content\n\t}\n\n\tstatic rehydrate(data: { text: string }): ModelMessageItem {\n\t\tconst content = OutputText.rehydrate(data)\n\t\treturn new ModelMessageItem(content)\n\t}\n}\n","import { ContextItem } from \"@domain/model-context/context-item/context-item\"\n\nexport class FunctionCallItem extends ContextItem {\n\treadonly type = \"function_call\"\n\treadonly callId: string\n\treadonly name: string\n\treadonly args: string\n\n\tprivate constructor(callId: string, name: string, args: string) {\n\t\tsuper()\n\t\tthis.callId = callId\n\t\tthis.name = name\n\t\tthis.args = args\n\t}\n\n\tstatic rehydrate(data: { callId: string; name: string; args: string }): FunctionCallItem {\n\t\treturn new FunctionCallItem(data.callId, data.name, data.args)\n\t}\n}\n","import type { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\nimport type { SummaryText } from \"@domain/model-context/context-item/item-content/summary-text\"\nimport { ContextItem } from \"@domain/model-context/context-item/context-item\"\n\nexport class ReasoningItem extends ContextItem {\n\treadonly type = \"reasoning\"\n\treadonly content: InputText | undefined\n\treadonly encryptedContent: string | undefined\n\treadonly summary: SummaryText[]\n\n\tprivate constructor(\n\t\tcontent: InputText | undefined,\n\t\tencryptedContent?: string | undefined,\n\t\tsummary: SummaryText[] = [],\n\t) {\n\t\tsuper()\n\t\tthis.content = content\n\t\tthis.encryptedContent = encryptedContent\n\t\tthis.summary = summary\n\t}\n\n\tstatic rehydrate(data: {\n\t\tcontent: InputText | undefined\n\t\tencryptedContent: string | undefined\n\t\tsummary: SummaryText[]\n\t}): ReasoningItem {\n\t\treturn new ReasoningItem(data.content, data.encryptedContent, data.summary)\n\t}\n}\n","import type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport type { ModelName, ModelSpecification } from \"../generative-model\"\nimport type { RequestValidationRule } from \"./rule\"\n\nexport type StructuredOutputFormat = {\n\tname?: string\n\tschema: Record<string, any>\n\tstrict?: boolean\n}\n\nexport class StructuredOutputValidation implements RequestValidationRule {\n\treadonly name = \"structured-output\"\n\n\tisValid(inferenceParams: InferenceParams<ModelName>, model: ModelSpecification): boolean {\n\t\tif (inferenceParams.structuredOutput === undefined) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn model.supportsStructuredOutput\n\t}\n}\n","import { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\n\nexport class FunctionCallOutputItem extends ContextItem {\n\treadonly type = \"function_call_output\"\n\treadonly callId: string\n\treadonly output: InputText\n\n\tprivate constructor(callId: string, output: InputText) {\n\t\tsuper()\n\t\tthis.callId = callId\n\t\tthis.output = output\n\t}\n\n\tstatic create(callId: string, output: string): FunctionCallOutputItem {\n\t\tconst outputText = InputText.create(output)\n\t\treturn new FunctionCallOutputItem(callId, outputText)\n\t}\n\n\tstatic rehydrate(data: { callId: string; output: InputText }): FunctionCallOutputItem {\n\t\treturn new FunctionCallOutputItem(data.callId, data.output)\n\t}\n}\n","export class InputTokenDetails {\n\treadonly cached_tokens: number\n\n\tconstructor(cached_tokens: number) {\n\t\tthis.cached_tokens = cached_tokens\n\t}\n}\n\nexport class OutputTokenDetails {\n\treadonly reasoning_tokens: number\n\n\tconstructor(reasoning_tokens: number) {\n\t\tthis.reasoning_tokens = reasoning_tokens\n\t}\n}\n\nexport class TokenUsage {\n\treadonly inputTokens: number\n\treadonly outputTokens: number\n\treadonly totalTokens: number\n\treadonly inputTokenDetails: InputTokenDetails\n\treadonly outputTokenDetails: OutputTokenDetails\n\n\tconstructor(\n\t\tinputTokens: number,\n\t\toutputTokens: number,\n\t\ttotalTokens: number,\n\t\tinputTokenDetails: InputTokenDetails,\n\t\toutputTokenDetails: OutputTokenDetails,\n\t) {\n\t\tthis.inputTokens = inputTokens\n\t\tthis.outputTokens = outputTokens\n\t\tthis.totalTokens = totalTokens\n\t\tthis.inputTokenDetails = inputTokenDetails\n\t\tthis.outputTokenDetails = outputTokenDetails\n\t}\n}\n","import { Client } from \"@modelcontextprotocol/sdk/client/index.js\"\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\"\n\nexport interface McpServerConfig {\n\t/** The MCP server URL, e.g. https://api.githubcopilot.com/mcp/ */\n\turl: string\n\t/** Bearer token sent as `Authorization: Bearer <token>` (e.g. a GitHub token). */\n\tauthToken?: string\n\t/** Extra headers merged into every request (overridden by `authToken` for Authorization). */\n\theaders?: Record<string, string>\n\t/** Client name reported to the server (defaults to \"mozaik\"). */\n\tname?: string\n}\n\nexport interface McpToolSpec {\n\tname: string\n\tdescription: string\n\t/** JSON Schema for the tool's arguments (maps 1:1 to FunctionTool.parameters). */\n\tinputSchema: Record<string, any>\n}\n\n/**\n * A thin wrapper over the MCP TypeScript SDK using the Streamable HTTP transport — what\n * remote MCP servers (e.g. GitHub's `api.githubcopilot.com/mcp/`) speak. One client per\n * server; lazily connects on first use. Infrastructure-only: the domain never sees this.\n */\nexport class McpClient {\n\tprivate readonly client: Client\n\tprivate readonly transport: StreamableHTTPClientTransport\n\tprivate connected = false\n\n\tconstructor(private readonly config: McpServerConfig) {\n\t\tconst headers: Record<string, string> = { ...(config.headers ?? {}) }\n\t\tif (config.authToken) headers.Authorization = `Bearer ${config.authToken}`\n\t\tthis.transport = new StreamableHTTPClientTransport(\n\t\t\tnew URL(config.url),\n\t\t\tObject.keys(headers).length > 0 ? { requestInit: { headers } } : undefined,\n\t\t)\n\t\tthis.client = new Client({ name: config.name ?? \"mozaik\", version: \"1.0.0\" }, { capabilities: {} })\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.connected) return\n\t\tawait this.client.connect(this.transport)\n\t\tthis.connected = true\n\t}\n\n\t/** The tools this server exposes. */\n\tasync listTools(): Promise<McpToolSpec[]> {\n\t\tawait this.connect()\n\t\tconst res = await this.client.listTools()\n\t\treturn (res.tools ?? []).map((t) => ({\n\t\t\tname: t.name,\n\t\t\tdescription: t.description ?? \"\",\n\t\t\tinputSchema: (t.inputSchema as Record<string, any>) ?? { type: \"object\", properties: {} },\n\t\t}))\n\t}\n\n\t/** Call a tool by name; returns its text output. Throws if the server flags an error. */\n\tasync callTool(name: string, args: Record<string, any>): Promise<string> {\n\t\tawait this.connect()\n\t\tconst res = await this.client.callTool({ name, arguments: args ?? {} })\n\t\tconst text = extractText(res)\n\t\tif ((res as { isError?: boolean }).isError) {\n\t\t\tthrow new Error(`MCP tool \"${name}\" failed: ${text || \"unknown error\"}`)\n\t\t}\n\t\treturn text\n\t}\n\n\tasync close(): Promise<void> {\n\t\tif (!this.connected) return\n\t\ttry {\n\t\t\tawait this.client.close()\n\t\t} catch {\n\t\t\t// best-effort teardown — the transport may already be gone\n\t\t}\n\t\tthis.connected = false\n\t}\n}\n\n/** Concatenate the text blocks of an MCP tool result (ignores non-text content). */\nfunction extractText(res: unknown): string {\n\tconst content = (res as { content?: unknown }).content\n\tif (!Array.isArray(content)) return \"\"\n\treturn content\n\t\t.filter((c): c is { type: \"text\"; text: string } => (c as { type?: string })?.type === \"text\" && typeof (c as { text?: unknown }).text === \"string\")\n\t\t.map((c) => c.text)\n\t\t.join(\"\\n\")\n}\n","import type { FunctionTool } from \"@domain/generative-model/tool\"\nimport { McpClient, type McpServerConfig } from \"./mcp-client.js\"\n\n/** The slice of an MCP client the registry needs — lets tests inject a fake. */\nexport interface McpClientLike {\n\tlistTools(): Promise<Array<{ name: string; description: string; inputSchema: Record<string, any> }>>\n\tcallTool(name: string, args: Record<string, any>): Promise<string>\n\tclose(): Promise<void>\n}\n\n/**\n * Connects to one or more MCP servers and exposes their tools as mozaik `FunctionTool`s.\n * Each tool's `invoke()` proxies the call back to its MCP server. Because they are plain\n * FunctionTools, every provider mapper and the existing function-call loop handle them\n * with no changes — MCP support adds no new tool type and touches no provider code.\n *\n * `strict` is false: MCP servers publish arbitrary JSON Schemas that won't always satisfy\n * a provider's strict function-calling mode.\n */\nexport class McpToolRegistry {\n\tprivate readonly clients: McpClientLike[] = []\n\n\tconstructor(\n\t\tprivate readonly servers: McpServerConfig[],\n\t\tprivate readonly createClient: (config: McpServerConfig) => McpClientLike = (config) => new McpClient(config),\n\t) {}\n\n\t/** Discover every tool across the configured servers, as FunctionTools ready to pass to a model. */\n\tasync discoverTools(): Promise<FunctionTool[]> {\n\t\tconst tools: FunctionTool[] = []\n\t\tfor (const server of this.servers) {\n\t\t\tconst client = this.createClient(server)\n\t\t\tthis.clients.push(client)\n\t\t\tfor (const spec of await client.listTools()) {\n\t\t\t\ttools.push({\n\t\t\t\t\ttype: \"function\",\n\t\t\t\t\tname: spec.name,\n\t\t\t\t\tdescription: spec.description,\n\t\t\t\t\tparameters: spec.inputSchema,\n\t\t\t\t\tstrict: false,\n\t\t\t\t\tinvoke: (args: unknown) => client.callTool(spec.name, (args as Record<string, any>) ?? {}),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn tools\n\t}\n\n\t/** Close all underlying MCP connections. */\n\tasync close(): Promise<void> {\n\t\tawait Promise.all(this.clients.map((c) => c.close()))\n\t}\n}\n","import { ModelContext } from \"@domain/model-context/model-context\"\nimport type { ModelContextRepository } from \"@domain/model-context/model-context-repository\"\n\nexport class InMemoryModelContextRepository implements ModelContextRepository {\n\tprivate readonly store = new Map<string, ModelContext>()\n\tprivate readonly projectIndex = new Map<string, Set<string>>()\n\n\tasync save(context: ModelContext): Promise<void> {\n\t\tconst existing = this.store.get(context.id)\n\t\tif (existing && existing.projectId !== context.projectId) {\n\t\t\tconst prevSet = this.projectIndex.get(existing.projectId)\n\t\t\tprevSet?.delete(existing.id)\n\t\t\tif (prevSet && prevSet.size === 0) this.projectIndex.delete(existing.projectId)\n\t\t}\n\n\t\tthis.store.set(context.id, this.clone(context))\n\n\t\tlet set = this.projectIndex.get(context.projectId)\n\t\tif (!set) {\n\t\t\tset = new Set<string>()\n\t\t\tthis.projectIndex.set(context.projectId, set)\n\t\t}\n\t\tset.add(context.id)\n\t}\n\n\tasync get(id: string): Promise<ModelContext> {\n\t\tconst context = this.store.get(id)\n\t\tif (!context) {\n\t\t\tthrow new Error(`Context not found: ${id}`)\n\t\t}\n\t\treturn this.clone(context)\n\t}\n\n\tasync getByProjectId(projectId: string): Promise<ModelContext[]> {\n\t\tconst ids = this.projectIndex.get(projectId)\n\t\tif (!ids || ids.size === 0) return []\n\t\treturn [...ids]\n\t\t\t.map((id) => this.store.get(id))\n\t\t\t.filter((c): c is ModelContext => Boolean(c))\n\t\t\t.map((c) => this.clone(c))\n\t}\n\n\tprivate clone(context: ModelContext): ModelContext {\n\t\treturn ModelContext.rehydrate({\n\t\t\tid: context.id,\n\t\t\tprojectId: context.projectId,\n\t\t\titems: [...context.getItems()],\n\t\t})\n\t}\n}\n","import { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\nimport { ContextItem } from \"@domain/model-context/context-item/context-item\"\n\nexport class SystemMessageItem extends ContextItem {\n\treadonly type = \"message\"\n\treadonly role = \"system\"\n\treadonly content: InputText\n\n\tprivate constructor(content: InputText) {\n\t\tsuper()\n\t\tthis.content = content\n\t}\n\n\tstatic create(text: string): SystemMessageItem {\n\t\tconst content = InputText.create(text)\n\t\treturn new SystemMessageItem(content)\n\t}\n\n\tstatic rehydrate(data: { text: string }): SystemMessageItem {\n\t\tconst content = InputText.rehydrate(data)\n\t\treturn new SystemMessageItem(content)\n\t}\n}\n","import type { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport type { AgenticEnvironment } from \"./agentic-environment\"\nimport type { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport type { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport type { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport type { SemanticEvent } from \"@domain/model-context/semantic-event/semantic-event\"\nimport type { AgenticError } from \"./errors/base-error\"\n\ntype ParticipantClassConstructor = new (...args: any[]) => Participant\n\nexport abstract class Participant {\n\tprivate environments: AgenticEnvironment[] = []\n\tprotected listens: ParticipantClassConstructor[] = []\n\tprivate active: Map<AgenticEnvironment, boolean> = new Map()\n\n\tjoin(environment: AgenticEnvironment) {\n\t\tif (this.isJoinedTo(environment)) {\n\t\t\treturn\n\t\t}\n\t\tenvironment.subscribe(this)\n\t\tthis.environments.push(environment)\n\t\tthis.active.set(environment, true)\n\t}\n\n\tleave(environment: AgenticEnvironment) {\n\t\tif (!this.isJoinedTo(environment)) {\n\t\t\treturn\n\t\t}\n\t\tenvironment.unsubscribe(this)\n\t\tthis.environments = this.environments.filter((e) => e !== environment)\n\t\tthis.active.delete(environment)\n\t}\n\n\tisJoinedTo(environment: AgenticEnvironment): boolean {\n\t\treturn this.environments.includes(environment)\n\t}\n\n\tgetEnvironments(): AgenticEnvironment[] {\n\t\treturn this.environments\n\t}\n\n\tgetListeners(): ParticipantClassConstructor[] {\n\t\treturn this.listens\n\t}\n\n\tgetEnvironmentState(environment: AgenticEnvironment) {\n\t\treturn this.active.get(environment)\n\t}\n\n\tmarkInactive(environment: AgenticEnvironment) {\n\t\tif (this.active.has(environment)) {\n\t\t\tthis.active.set(environment, false)\n\t\t}\n\t}\n\n\tmarkActive(environment: AgenticEnvironment) {\n\t\tif (this.active.has(environment)) {\n\t\t\tthis.active.set(environment, true)\n\t\t}\n\t}\n\n\tabstract onParticipantJoined(participant: Participant): Promise<void> | void\n\n\tabstract onParticipantLeft(participant: Participant): Promise<void> | void\n\n\tabstract onJoined(): Promise<void> | void\n\n\tabstract onLeft(): Promise<void> | void\n\n\tabstract onFunctionCall(item: FunctionCallItem): Promise<void> | void\n\n\tabstract onExternalFunctionCall(source: Participant, item: FunctionCallItem): Promise<void> | void\n\n\tabstract onFunctionCallOutput(item: FunctionCallOutputItem): Promise<void> | void\n\n\tabstract onExternalFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): Promise<void> | void\n\n\tabstract onReasoning(item: ReasoningItem): Promise<void> | void\n\n\tabstract onExternalReasoning(source: Participant, item: ReasoningItem): Promise<void> | void\n\n\tabstract onModelMessage(item: ModelMessageItem): Promise<void> | void\n\n\tabstract onExternalModelMessage(source: Participant, item: ModelMessageItem): Promise<void> | void\n\n\tabstract onMessage(message: string): Promise<void> | void\n\n\tabstract onInternalEvent(item: SemanticEvent<unknown>): Promise<void> | void\n\n\tabstract onExternalEvent(source: Participant, item: SemanticEvent<unknown>): Promise<void> | void\n\n\tabstract onError(error: AgenticError): void\n\n\tabstract onParticipantError(source: Participant, error: AgenticError): void\n}\n","import type { AgenticEnvironment } from \"../agentic-environment\"\nimport type { Participant } from \"../participant\"\n\ninterface AgenticErrorOpts {\n\tmessage: string\n\tstack?: string\n\tsource?: Participant\n\tenviornment?: AgenticEnvironment\n}\n\nexport class AgenticError extends Error {\n\tprivate source?: Participant\n\tprivate environment?: AgenticEnvironment\n\n\tconstructor({ message, stack, source, enviornment }: AgenticErrorOpts) {\n\t\tsuper()\n\n\t\tthis.message = message\n\t\tthis.stack = stack\n\t\tthis.source = source\n\t\tthis.environment = enviornment\n\t}\n\n\tgetSource() {\n\t\treturn this.source\n\t}\n\n\tgetEnvironment() {\n\t\treturn this.environment\n\t}\n}\n","import type { Participant } from \"@domain/agentic-environment/participant\"\nimport type { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport type { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport type { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport type { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport type { SemanticEvent } from \"@domain/model-context/semantic-event/semantic-event\"\nimport { AgenticError } from \"./errors/base-error\"\n\nexport interface AgenticEnvironmentOptions {\n\tsilent?: boolean\n}\n\nexport class AgenticEnvironment {\n\tprotected subscribers: Participant[] = []\n\tprivate name?: string\n\tprivate options?: AgenticEnvironmentOptions\n\tprivate showLogs?: boolean\n\n\tconstructor(name?: string, opts?: AgenticEnvironmentOptions) {\n\t\tthis.name = name\n\t\tthis.options = opts\n\n\t\tthis.showLogs = this.options?.silent !== false\n\t}\n\n\tsubscribe(participant: Participant) {\n\t\tthis.subscribers.push(participant)\n\t\tfor (const subscriber of this.subscribers) {\n\t\t\tif (participant === subscriber) {\n\t\t\t\tparticipant.onJoined()\n\t\t\t} else {\n\t\t\t\tsubscriber.onParticipantJoined(participant)\n\t\t\t}\n\t\t}\n\t}\n\n\tunsubscribe(participant: Participant) {\n\t\tconst exists = this.subscribers.includes(participant)\n\n\t\tif (!exists) {\n\t\t\treturn\n\t\t}\n\n\t\tparticipant.onLeft()\n\n\t\tthis.subscribers = this.subscribers.filter((p) => p !== participant)\n\n\t\tfor (const subscriber of this.subscribers) {\n\t\t\tsubscriber.onParticipantLeft(participant)\n\t\t}\n\t}\n\n\tdeliverFunctionCall(source: Participant, item: FunctionCallItem): void {\n\t\tthis.deliverToSubscribers(source, {\n\t\t\tinternal: (src) => src.onFunctionCall(item),\n\t\t\texternal: (sub) => sub.onExternalFunctionCall(source, item),\n\t\t})\n\t}\n\n\tdeliverModelMessage(source: Participant, item: ModelMessageItem): void {\n\t\tthis.deliverToSubscribers(source, {\n\t\t\tinternal: (src) => src.onModelMessage(item),\n\t\t\texternal: (sub) => sub.onExternalModelMessage(source, item),\n\t\t})\n\t}\n\n\tdeliverReasoning(source: Participant, item: ReasoningItem): void {\n\t\tthis.deliverToSubscribers(source, {\n\t\t\tinternal: (src) => src.onReasoning(item),\n\t\t\texternal: (sub) => sub.onExternalReasoning(source, item),\n\t\t})\n\t}\n\n\tdeliverFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): void {\n\t\tthis.deliverToSubscribers(source, {\n\t\t\tinternal: (src) => src.onFunctionCallOutput(item),\n\t\t\texternal: (sub) => sub.onExternalFunctionCallOutput(source, item),\n\t\t})\n\t}\n\n\tdeliverMessage(source: Participant, message: string): void {\n\t\tthis.deliverToSubscribers(source, {\n\t\t\texternal: (sub) => sub.onMessage(message),\n\t\t})\n\t}\n\n\tdeliverSemanticEvent(source: Participant, item: SemanticEvent<unknown>): void {\n\t\tthis.deliverToSubscribers(source, {\n\t\t\tinternal: (src) => src.onInternalEvent(item),\n\t\t\texternal: (sub) => sub.onExternalEvent(source, item),\n\t\t})\n\t}\n\n\tdeliverError(source: Participant, error: AgenticError) {\n\t\tthis.deliverToSubscribers(source, {\n\t\t\tinternal: (src) => {\n\t\t\t\ttry {\n\t\t\t\t\tsrc.onError(error)\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (this.showLogs) {\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`[AgenticEnvironment] Participant.onError() failed. Reason: ${error as Error}\\n ${JSON.stringify({ error }, null, 2)}`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tsrc.markInactive(this)\n\t\t\t\t}\n\t\t\t},\n\t\t\texternal: (sub) => {\n\t\t\t\ttry {\n\t\t\t\t\tsub.onParticipantError(source, error)\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (this.showLogs) {\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`[AgenticEnvironment] Participant.onError() failed. Reason: ${error as Error}\\n ${JSON.stringify({ error }, null, 2)}`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t})\n\t}\n\n\tprivate getListeningParticipants(source: Participant) {\n\t\treturn this.subscribers.filter(\n\t\t\t(sub) =>\n\t\t\t\tsub !== source &&\n\t\t\t\t(sub.getListeners().length === 0 || sub.getListeners().some((listener) => source instanceof listener)),\n\t\t)\n\t}\n\n\tprivate deliverToSubscribers(\n\t\tsource: Participant,\n\t\thandlers: { internal?: (src: Participant) => void; external: (sub: Participant) => void },\n\t) {\n\t\tconst authorizedListeners = this.getListeningParticipants(source)\n\n\t\tfor (const subscriber of this.subscribers) {\n\t\t\tconst isActive = subscriber.getEnvironmentState(this)\n\n\t\t\tif (isActive) {\n\t\t\t\ttry {\n\t\t\t\t\tif (subscriber === source) {\n\t\t\t\t\t\thandlers?.internal?.(subscriber)\n\t\t\t\t\t} else if (authorizedListeners.includes(subscriber)) {\n\t\t\t\t\t\thandlers?.external?.(subscriber)\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.handleError(subscriber, error as Error)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate handleError(subscriber: Participant, error: Error) {\n\t\tif (error instanceof AgenticError) {\n\t\t\treturn this.deliverError(subscriber, error)\n\t\t}\n\n\t\tconst agenticError = new AgenticError({\n\t\t\tmessage: error.message,\n\t\t\tstack: error.stack,\n\t\t\tenviornment: this,\n\t\t\tsource: subscriber,\n\t\t})\n\n\t\treturn this.deliverError(subscriber, agenticError)\n\t}\n}\n","export class SemanticEvent<T> {\n\treadonly type: string\n\treadonly data: T\n\n\tconstructor(type: string, data: T) {\n\t\tthis.type = type\n\t\tthis.data = data\n\t}\n\n\tgetType(): string {\n\t\treturn this.type\n\t}\n}\n","import type { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport type { TokenUsage } from \"@domain/generative-model/token-usage\"\n\nexport class InferenceResponse {\n\treadonly contextItems: ContextItem[]\n\treadonly tokenUsage?: TokenUsage\n\n\tconstructor(contextItems: ContextItem[], tokenUsage: TokenUsage | undefined) {\n\t\tthis.contextItems = contextItems\n\t\tthis.tokenUsage = tokenUsage\n\t}\n}\n","import type { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport type { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport type { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport type { SemanticEvent } from \"@domain/model-context/semantic-event/semantic-event\"\nimport type { Endpoint } from \"@domain/generative-model/endpoint\"\nimport type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport type { ModelName } from \"@domain/generative-model/generative-model\"\n\ntype InferenceItem = ReasoningItem | FunctionCallItem | ModelMessageItem | SemanticEvent<unknown>\n\nexport interface InferenceRunner {\n\trun(request: InferenceParams<ModelName>, endpoint: Endpoint): AsyncIterable<InferenceItem>\n}\n\nexport class StreamingInference implements InferenceRunner {\n\tasync *run(request: InferenceParams<ModelName>, endpoint: Endpoint): AsyncIterable<InferenceItem> {\n\t\tif (request.signal?.aborted) {\n\t\t\treturn\n\t\t}\n\t\tyield* endpoint.stream(request, request.signal)\n\t}\n}\n\nexport class NonStreamingInference implements InferenceRunner {\n\tasync *run(request: InferenceParams<ModelName>, endpoint: Endpoint): AsyncIterable<InferenceItem> {\n\t\tif (request.signal?.aborted) {\n\t\t\treturn\n\t\t}\n\t\tconst response = await endpoint.infer(request)\n\t\tfor (const item of response.contextItems) {\n\t\t\tif (request.signal?.aborted) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tyield item as InferenceItem\n\t\t}\n\t}\n}\n","import { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport { SemanticEvent } from \"@domain/model-context/semantic-event/semantic-event\"\nimport type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport type { RunInferenceUseCase } from \"@domain/agentic-environment/use-cases/run-inference\"\nimport type { InferenceRunner } from \"@app/services/inference-runner\"\nimport { NonStreamingInference, StreamingInference } from \"@app/services/inference-runner\"\nimport type { InferenceRequestValidator } from \"@domain/generative-model/request-validation/inference-request-validator\"\nimport type { ModelName } from \"@domain/generative-model/generative-model\"\nimport type { GenerativeModelRepository } from \"@domain/generative-model/generative-model-repository\"\n\nexport class RunInference implements RunInferenceUseCase<ModelName> {\n\tconstructor(\n\t\tprivate readonly generativeModelRepository: GenerativeModelRepository,\n\t\tprivate readonly requestValidator: InferenceRequestValidator,\n\t) {}\n\n\tasync execute(inferenceParams: InferenceParams<ModelName>): Promise<void> {\n\t\tconst { caller, environment, signal } = inferenceParams\n\n\t\tconst generativeModel = await this.generativeModelRepository.getByModelName(inferenceParams.model)\n\n\t\tthis.requestValidator.validate(inferenceParams, generativeModel.specification)\n\n\t\tconst resolvedParams: InferenceParams<ModelName> = {\n\t\t\t...inferenceParams,\n\t\t\tmaxOutputTokens: inferenceParams.maxOutputTokens ?? generativeModel.specification.maxOutputTokens,\n\t\t}\n\n\t\tconst inferenceRunner: InferenceRunner = inferenceParams.streaming\n\t\t\t? new StreamingInference()\n\t\t\t: new NonStreamingInference()\n\n\t\tconst result = inferenceRunner.run(resolvedParams, generativeModel.endpoint)\n\n\t\tfor await (const item of result) {\n\t\t\tif (signal?.aborted) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tif (item instanceof ReasoningItem) {\n\t\t\t\tenvironment.deliverReasoning(caller, item)\n\t\t\t} else if (item instanceof FunctionCallItem) {\n\t\t\t\tenvironment.deliverFunctionCall(caller, item)\n\t\t\t} else if (item instanceof ModelMessageItem) {\n\t\t\t\tenvironment.deliverModelMessage(caller, item)\n\t\t\t} else if (item instanceof SemanticEvent) {\n\t\t\t\tenvironment.deliverSemanticEvent(caller, item)\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { FunctionCallRunner } from \"@app/services/function-call-runner\"\nimport type { AgenticEnvironment } from \"@domain/agentic-environment/agentic-environment\"\nimport type { Participant } from \"@domain/agentic-environment/participant\"\nimport type { ExecuteFunctionCallUseCase } from \"@domain/agentic-environment/use-cases/execute-function-call\"\nimport type { Tool } from \"@domain/generative-model/tool\"\nimport type { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\n\nexport class ExecuteFunctionCall implements ExecuteFunctionCallUseCase {\n\tconstructor(private readonly functionCallRunner: FunctionCallRunner) {}\n\n\tasync execute(\n\t\tenvironment: AgenticEnvironment,\n\t\tfunctionCallItem: FunctionCallItem,\n\t\ttool: Tool,\n\t\tcaller: Participant,\n\t\tsignal?: AbortSignal,\n\t): Promise<void> {\n\t\tconst stream = this.functionCallRunner.run(functionCallItem, tool, signal)\n\n\t\tfor await (const item of stream) {\n\t\t\tenvironment.deliverFunctionCallOutput(caller, item)\n\t\t}\n\t}\n}\n","import type { Tool } from \"@domain/generative-model/tool\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport type { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\n\nexport class FunctionCallRunner {\n\tasync *run(call: FunctionCallItem, tool: Tool, signal?: AbortSignal): AsyncIterable<FunctionCallOutputItem> {\n\t\tif (signal?.aborted) {\n\t\t\treturn\n\t\t}\n\n\t\tif (!tool) throw new Error(`Unknown tool: ${call.name}`)\n\n\t\tconst result = await tool.invoke(JSON.parse(call.args))\n\t\tyield FunctionCallOutputItem.create(call.callId, JSON.stringify(result))\n\t}\n}\n","import type { AgenticError } from \"@domain/agentic-environment/errors/base-error\"\nimport { Participant } from \"@domain/agentic-environment/participant\"\nimport type { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport type { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport type { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport type { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport type { SemanticEvent } from \"@domain/model-context/semantic-event/semantic-event\"\n\nexport class BaseParticipant extends Participant {\n\tonFunctionCall(_item: FunctionCallItem) {}\n\tonExternalFunctionCall(_source: Participant, _item: FunctionCallItem) {}\n\tonFunctionCallOutput(_item: FunctionCallOutputItem) {}\n\tonExternalFunctionCallOutput(_source: Participant, _item: FunctionCallOutputItem) {}\n\tonReasoning(_item: ReasoningItem) {}\n\tonExternalReasoning(_source: Participant, _item: ReasoningItem) {}\n\tonModelMessage(_item: ModelMessageItem) {}\n\tonExternalModelMessage(_source: Participant, _item: ModelMessageItem) {}\n\tonMessage(_message: string) {}\n\tonJoined() {}\n\tonLeft() {}\n\tonParticipantJoined(_participant: Participant) {}\n\tonParticipantLeft(_participant: Participant) {}\n\tonInternalEvent(_item: SemanticEvent<unknown>) {}\n\tonExternalEvent(_source: Participant, _item: SemanticEvent<unknown>) {}\n\tonError(_error: AgenticError): void {}\n\tonParticipantError(_source: Participant, _error: AgenticError): void {}\n}\n","import type { AgenticEnvironment } from \"@domain/agentic-environment/agentic-environment\"\nimport type { Participant } from \"@domain/agentic-environment/participant\"\nimport type { SendMessageUseCase } from \"@domain/agentic-environment/use-cases/send-message\"\n\nexport class SendMessage implements SendMessageUseCase {\n\tasync execute(environment: AgenticEnvironment, message: string, caller: Participant): Promise<void> {\n\t\tif (!caller.isJoinedTo(environment)) {\n\t\t\tthrow new Error(\"Not joined to environment\")\n\t\t}\n\n\t\tenvironment.deliverMessage(caller, message)\n\t}\n}\n","import type { ModelName } from \"@domain/generative-model/generative-model\"\nimport type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport { DeveloperMessageItem } from \"@domain/model-context/context-item/client-item/developer-message\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport { SystemMessageItem } from \"@domain/model-context/context-item/client-item/system-message\"\nimport { UserMessageItem } from \"@domain/model-context/context-item/client-item/user-message\"\nimport { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\nimport { InferenceResponse } from \"@domain/agentic-environment/inference/response\"\nimport { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\nimport type { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { InputTokenDetails, OutputTokenDetails, TokenUsage } from \"@domain/generative-model/token-usage\"\nimport type Anthropic from \"@anthropic-ai/sdk\"\n\nexport class AnthropicMessagesMapper implements InferenceEndpointMapper {\n\ttoRequest(inferenceParams: InferenceParams<ModelName>) {\n\t\tconst { messages, system } = this.mapContextItems(inferenceParams)\n\t\tconst outputConfig: any = {}\n\n\t\tconst request: any = {\n\t\t\tmodel: inferenceParams.model,\n\t\t\tmessages,\n\t\t}\n\n\t\trequest.max_tokens = inferenceParams.maxOutputTokens!\n\n\t\tif (system) {\n\t\t\trequest.system = system\n\t\t}\n\n\t\tif (inferenceParams.tools && inferenceParams.tools.length > 0) {\n\t\t\trequest.tools = inferenceParams.tools.map((tool) => ({\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tinput_schema: tool.parameters,\n\t\t\t}))\n\t\t}\n\n\t\tif (inferenceParams.structuredOutput) {\n\t\t\toutputConfig.format = {\n\t\t\t\ttype: \"json_schema\",\n\t\t\t\tjson_schema: inferenceParams.structuredOutput.schema,\n\t\t\t}\n\t\t}\n\n\t\tif (inferenceParams.reasoningEffort) {\n\t\t\trequest.thinking = { type: \"adaptive\" }\n\t\t\toutputConfig.effort = inferenceParams.reasoningEffort\n\t\t}\n\n\t\tif (Object.keys(outputConfig).length > 0) {\n\t\t\trequest.output_config = outputConfig\n\t\t}\n\n\t\tif (inferenceParams.streaming) {\n\t\t\trequest.stream = inferenceParams.streaming\n\t\t}\n\n\t\treturn request\n\t}\n\n\ttoResponse(response: any): InferenceResponse {\n\t\tconst contextItems = this.extractContextItems(response)\n\t\tconst tokenUsage = this.extractTokenUsage(response)\n\t\treturn new InferenceResponse(contextItems, tokenUsage)\n\t}\n\n\tprivate addContentBlock(messages: any[], role: \"user\" | \"assistant\", block: any): void {\n\t\tconst lastMessage = messages[messages.length - 1]\n\t\tif (lastMessage?.role === role) {\n\t\t\tlastMessage.content.push(block)\n\t\t\treturn\n\t\t}\n\n\t\tmessages.push({\n\t\t\trole: role,\n\t\t\tcontent: [block],\n\t\t})\n\t}\n\n\tmapContextItems(inferenceParams: InferenceParams<ModelName>): { messages: any[]; system?: string } {\n\t\tconst context = inferenceParams.context\n\t\tconst messages: any[] = []\n\t\tconst system: string[] = []\n\n\t\tfor (const item of context.getItems()) {\n\t\t\tif (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {\n\t\t\t\tsystem.push(item.content.text)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof UserMessageItem) {\n\t\t\t\tthis.addContentBlock(messages, \"user\", { type: \"text\", text: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof ModelMessageItem) {\n\t\t\t\tthis.addContentBlock(messages, \"assistant\", { type: \"text\", text: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof ReasoningItem) {\n\t\t\t\tthis.addContentBlock(messages, \"assistant\", {\n\t\t\t\t\ttype: \"thinking\",\n\t\t\t\t\tthinking: item.content?.text ?? \"\",\n\t\t\t\t\tsignature: item.encryptedContent ?? \"\",\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallItem) {\n\t\t\t\tlet input: any\n\t\t\t\ttry {\n\t\t\t\t\tinput = JSON.parse(item.args)\n\t\t\t\t} catch {\n\t\t\t\t\tinput = item.args\n\t\t\t\t}\n\t\t\t\tthis.addContentBlock(messages, \"assistant\", {\n\t\t\t\t\ttype: \"tool_use\",\n\t\t\t\t\tid: item.callId,\n\t\t\t\t\tname: item.name,\n\t\t\t\t\tinput: input,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallOutputItem) {\n\t\t\t\tthis.addContentBlock(messages, \"user\", {\n\t\t\t\t\ttype: \"tool_result\",\n\t\t\t\t\ttool_use_id: item.callId,\n\t\t\t\t\tcontent: item.output.text,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tmessages: messages,\n\t\t\tsystem: system.length > 0 ? system.join(\"\\n\\n\") : undefined,\n\t\t}\n\t}\n\n\textractTokenUsage(response: Anthropic.Messages.Message): TokenUsage | undefined {\n\t\tif (!response.usage) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn new TokenUsage(\n\t\t\tresponse.usage.input_tokens,\n\t\t\tresponse.usage.output_tokens,\n\t\t\tresponse.usage.input_tokens + response.usage.output_tokens,\n\t\t\tnew InputTokenDetails(\n\t\t\t\t(response.usage.cache_creation_input_tokens ?? 0) + (response.usage.cache_read_input_tokens ?? 0),\n\t\t\t),\n\t\t\tnew OutputTokenDetails(0),\n\t\t)\n\t}\n\n\textractContextItems(response: Anthropic.Messages.Message): ContextItem[] {\n\t\tconst items: ContextItem[] = []\n\n\t\tfor (const block of response.content as any[]) {\n\t\t\tif (block.type === \"text\") {\n\t\t\t\titems.push(ModelMessageItem.rehydrate({ text: block.text }))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (block.type === \"tool_use\") {\n\t\t\t\titems.push(\n\t\t\t\t\tFunctionCallItem.rehydrate({\n\t\t\t\t\t\tcallId: block.id,\n\t\t\t\t\t\tname: block.name,\n\t\t\t\t\t\targs: JSON.stringify(block.input ?? {}),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (block.type === \"thinking\") {\n\t\t\t\titems.push(\n\t\t\t\t\tReasoningItem.rehydrate({\n\t\t\t\t\t\tcontent: block.thinking ? InputText.rehydrate({ text: block.thinking }) : undefined,\n\t\t\t\t\t\tencryptedContent: block.signature,\n\t\t\t\t\t\tsummary: [],\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\treturn items\n\t}\n}\n","import type { InferenceResponse } from \"@domain/agentic-environment/inference/response\"\nimport { SemanticEvent } from \"@domain/model-context/semantic-event/semantic-event\"\nimport type { Endpoint } from \"@domain/generative-model/endpoint\"\nimport type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport type { ModelName } from \"@domain/generative-model/generative-model\"\nimport { AnthropicMessagesMapper } from \"./anthropic-messages-mapper\"\nimport Anthropic from \"@anthropic-ai/sdk\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\n\n/**\n * Native Anthropic adapter on the `@anthropic-ai/sdk` (`messages.create`).\n * Maps domain context to Anthropic's `messages`/`content` blocks shape,\n * system prompt, tools, adaptive thinking, and structured output config.\n */\nexport class AnthropicMessages implements Endpoint {\n\tendpointMapper: InferenceEndpointMapper\n\tprivate readonly client: Anthropic\n\n\tconstructor(endpointMapper: InferenceEndpointMapper = new AnthropicMessagesMapper()) {\n\t\tthis.endpointMapper = endpointMapper\n\t\tthis.client = new Anthropic()\n\t}\n\n\tasync infer(inferenceParams: InferenceParams<ModelName>): Promise<InferenceResponse> {\n\t\tconst inferenceRequest = this.endpointMapper.toRequest(inferenceParams)\n\t\tconst response = await this.client.messages.create(inferenceRequest)\n\n\t\treturn this.endpointMapper.toResponse(response)\n\t}\n\n\tasync *stream(\n\t\tinferenceParams: InferenceParams<ModelName>,\n\t\tsignal?: AbortSignal,\n\t): AsyncIterable<SemanticEvent<unknown>> {\n\t\tconst inferenceRequest = this.endpointMapper.toRequest(inferenceParams)\n\t\tconst stream: any = await this.client.messages.create(inferenceRequest)\n\n\t\tfor await (const event of stream) {\n\t\t\tif (signal?.aborted) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tyield new SemanticEvent(event.type, event)\n\t\t}\n\t}\n}\n","import { SemanticEvent } from \"@domain/model-context/semantic-event/semantic-event\"\nimport type { InferenceResponse } from \"@domain/agentic-environment/inference/response\"\nimport type { Endpoint } from \"@domain/generative-model/endpoint\"\nimport OpenAI from \"openai\"\nimport type { ModelName } from \"@domain/generative-model/generative-model\"\nimport type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport { OpenAIResponsesMapper } from \"./openai-responses-mapper\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\n\nexport class OpenAIResponses implements Endpoint {\n\tendpointMapper: InferenceEndpointMapper\n\tprivate readonly client: OpenAI\n\n\tconstructor(endpointMapper: InferenceEndpointMapper = new OpenAIResponsesMapper()) {\n\t\tthis.endpointMapper = endpointMapper\n\t\tthis.client = new OpenAI()\n\t}\n\n\tasync infer(inferenceParams: InferenceParams<ModelName>): Promise<InferenceResponse> {\n\t\tconst request = this.endpointMapper.toRequest(inferenceParams)\n\t\tconst response = await this.client.responses.create(request)\n\n\t\treturn this.endpointMapper.toResponse(response)\n\t}\n\n\tasync *stream(\n\t\tinferenceParams: InferenceParams<ModelName>,\n\t\tsignal?: AbortSignal,\n\t): AsyncIterable<SemanticEvent<unknown>> {\n\t\tconst request = this.endpointMapper.toRequest(inferenceParams)\n\t\tconst response: any = await this.client.responses.create(request)\n\n\t\tfor await (const event of response) {\n\t\t\tif (signal?.aborted) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tyield new SemanticEvent(event.type, event)\n\t\t}\n\t}\n}\n","import { ItemContent } from \"@domain/model-context/context-item/item-content/item-content\"\n\nexport class SummaryText extends ItemContent {\n\treadonly type = \"summary_text\"\n\n\tprivate constructor(public readonly text: string) {\n\t\tsuper()\n\t}\n\n\tstatic rehydrate(data: { text: string }): SummaryText {\n\t\treturn new SummaryText(data.text)\n\t}\n}\n","import type { ModelName } from \"@domain/generative-model/generative-model\"\nimport type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\nimport { DeveloperMessageItem } from \"@domain/model-context/context-item/client-item/developer-message\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport { SystemMessageItem } from \"@domain/model-context/context-item/client-item/system-message\"\nimport { UserMessageItem } from \"@domain/model-context/context-item/client-item/user-message\"\nimport { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport { SummaryText } from \"@domain/model-context/context-item/item-content/summary-text\"\nimport { InferenceResponse } from \"@domain/agentic-environment/inference/response\"\nimport type { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { InputTokenDetails, OutputTokenDetails, TokenUsage } from \"@domain/generative-model/token-usage\"\nimport type OpenAI from \"openai\"\n\nexport class OpenAIResponsesMapper implements InferenceEndpointMapper {\n\ttoRequest(inferenceParams: InferenceParams<ModelName>): any {\n\t\tconst request: any = {\n\t\t\tmodel: inferenceParams.model,\n\t\t\tinput: this.mapContextItems(inferenceParams),\n\t\t}\n\n\t\tif (inferenceParams.tools && inferenceParams.tools.length > 0) {\n\t\t\trequest.tools = inferenceParams.tools.map((tool) => ({\n\t\t\t\ttype: tool.type,\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tparameters: tool.parameters,\n\t\t\t}))\n\t\t}\n\n\t\tif (inferenceParams.reasoningEffort) {\n\t\t\trequest.reasoning = {\n\t\t\t\teffort: inferenceParams.reasoningEffort,\n\t\t\t}\n\t\t}\n\n\t\tif (inferenceParams.structuredOutput) {\n\t\t\tconst format = inferenceParams.structuredOutput\n\t\t\trequest.text = {\n\t\t\t\tformat: {\n\t\t\t\t\ttype: \"json_schema\",\n\t\t\t\t\tname: format.name ?? \"response\",\n\t\t\t\t\tschema: format.schema,\n\t\t\t\t\tstrict: format.strict ?? true,\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\n\t\tif (inferenceParams.streaming) {\n\t\t\trequest.stream = inferenceParams.streaming\n\t\t}\n\n\t\treturn request\n\t}\n\n\ttoResponse(response: any): InferenceResponse {\n\t\tconst contextItems = this.extractContextItems(response)\n\t\tconst tokenUsage = this.extractTokenUsage(response)\n\t\treturn new InferenceResponse(contextItems, tokenUsage)\n\t}\n\n\tmapContextItems(inferenceParams: InferenceParams<ModelName>): any[] {\n\t\tconst input: any[] = []\n\n\t\tfor (const item of inferenceParams.context.getItems()) {\n\t\t\tif (\n\t\t\t\titem instanceof DeveloperMessageItem ||\n\t\t\t\titem instanceof SystemMessageItem ||\n\t\t\t\titem instanceof UserMessageItem\n\t\t\t) {\n\t\t\t\tinput.push({\n\t\t\t\t\ttype: item.type,\n\t\t\t\t\trole: item.role,\n\t\t\t\t\tcontent: [{ type: \"input_text\", text: item.content.text }],\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof ModelMessageItem) {\n\t\t\t\tinput.push({\n\t\t\t\t\ttype: item.type,\n\t\t\t\t\trole: item.role,\n\t\t\t\t\tcontent: [{ type: \"output_text\", text: item.content.text }],\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallItem) {\n\t\t\t\tinput.push({\n\t\t\t\t\ttype: item.type,\n\t\t\t\t\tcall_id: item.callId,\n\t\t\t\t\tname: item.name,\n\t\t\t\t\targuments: item.args,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallOutputItem) {\n\t\t\t\tinput.push({\n\t\t\t\t\ttype: item.type,\n\t\t\t\t\tcall_id: item.callId,\n\t\t\t\t\toutput: [{ type: \"input_text\", text: item.output.text }],\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof ReasoningItem) {\n\t\t\t\tconst reasoningInput: Record<string, unknown> = {\n\t\t\t\t\ttype: item.type,\n\t\t\t\t\tsummary: item.summary.map((summary) => ({ type: \"summary_text\", text: summary.text })),\n\t\t\t\t}\n\t\t\t\tif (item.encryptedContent !== undefined) {\n\t\t\t\t\treasoningInput.encrypted_content = item.encryptedContent\n\t\t\t\t}\n\t\t\t\tinput.push(reasoningInput)\n\t\t\t}\n\t\t}\n\n\t\treturn input\n\t}\n\n\textractTokenUsage(response: OpenAI.Responses.Response): TokenUsage | undefined {\n\t\tif (!response.usage) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn new TokenUsage(\n\t\t\tresponse.usage.input_tokens,\n\t\t\tresponse.usage.output_tokens,\n\t\t\tresponse.usage.total_tokens,\n\t\t\tnew InputTokenDetails(response.usage.input_tokens_details?.cached_tokens ?? 0),\n\t\t\tnew OutputTokenDetails(response.usage.output_tokens_details?.reasoning_tokens ?? 0),\n\t\t)\n\t}\n\n\textractContextItems(response: any): ContextItem[] {\n\t\tconst items: ContextItem[] = []\n\n\t\tfor (const item of response.output ?? []) {\n\t\t\tif (item.type === \"message\" && item.role === \"assistant\") {\n\t\t\t\tconst firstContent = item.content?.[0]\n\t\t\t\tif (firstContent) {\n\t\t\t\t\titems.push(ModelMessageItem.rehydrate(firstContent as { text: string }))\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (item.type === \"function_call\") {\n\t\t\t\titems.push(\n\t\t\t\t\tFunctionCallItem.rehydrate({\n\t\t\t\t\t\tcallId: item.call_id,\n\t\t\t\t\t\tname: item.name,\n\t\t\t\t\t\targs: item.arguments,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (item.type === \"reasoning\") {\n\t\t\t\titems.push(\n\t\t\t\t\tReasoningItem.rehydrate({\n\t\t\t\t\t\tcontent: undefined,\n\t\t\t\t\t\tencryptedContent: item.encrypted_content,\n\t\t\t\t\t\tsummary: (item.summary ?? []).map((summary: { text: string }) =>\n\t\t\t\t\t\t\tSummaryText.rehydrate({ text: summary.text }),\n\t\t\t\t\t\t),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\treturn items\n\t}\n}\n","import type { InferenceResponse } from \"@domain/agentic-environment/inference/response\"\nimport { SemanticEvent } from \"@domain/model-context/semantic-event/semantic-event\"\nimport { GoogleGenAI } from \"@google/genai\"\nimport type { Endpoint } from \"@domain/generative-model/endpoint\"\nimport type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport type { ModelName } from \"@domain/generative-model/generative-model\"\nimport { GeminiGenerateContentMapper } from \"./gemini-generate-content-mapper\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\n\n/**\n * Native Gemini adapter on the `@google/genai` SDK (`generateContent` /\n * `generateContentStream`). Unlike an OpenAI-compat shim this maps our\n * domain context to Gemini's native `contents`/`parts` shape, system\n * instruction, `functionDeclarations`, and `thinkingConfig`, and reads\n * thought parts + native usage metadata back out. Another `ModelRuntime`\n * — no runner or port changes.\n */\nexport class GeminiGenerateContent implements Endpoint {\n\tendpointMapper: InferenceEndpointMapper\n\tprivate readonly client: GoogleGenAI\n\n\tconstructor(endpointMapper: InferenceEndpointMapper = new GeminiGenerateContentMapper()) {\n\t\tthis.endpointMapper = endpointMapper\n\t\tthis.client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY })\n\t}\n\n\tasync infer(inferenceParams: InferenceParams<ModelName>): Promise<InferenceResponse> {\n\t\tconst inferenceRequest = this.endpointMapper.toRequest(inferenceParams)\n\t\tconst response = await this.client.models.generateContent(inferenceRequest)\n\n\t\treturn this.endpointMapper.toResponse(response)\n\t}\n\n\tasync *stream(\n\t\tinferenceParams: InferenceParams<ModelName>,\n\t\tsignal?: AbortSignal,\n\t): AsyncIterable<SemanticEvent<unknown>> {\n\t\tconst inferenceRequest = this.endpointMapper.toRequest(inferenceParams)\n\t\tconst stream = await this.client.models.generateContentStream(inferenceRequest)\n\n\t\tfor await (const chunk of stream) {\n\t\t\tif (signal?.aborted) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tyield new SemanticEvent(\"generate_content_chunk\", chunk)\n\t\t}\n\t}\n}\n","import type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport { InferenceResponse } from \"@domain/agentic-environment/inference/response\"\nimport type { ModelName } from \"@domain/generative-model/generative-model\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\nimport { InputTokenDetails, OutputTokenDetails, TokenUsage } from \"@domain/generative-model/token-usage\"\nimport { DeveloperMessageItem } from \"@domain/model-context/context-item/client-item/developer-message\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport { SystemMessageItem } from \"@domain/model-context/context-item/client-item/system-message\"\nimport { UserMessageItem } from \"@domain/model-context/context-item/client-item/user-message\"\nimport type { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\nimport { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\n\nexport class GeminiGenerateContentMapper implements InferenceEndpointMapper {\n\ttoRequest(inferenceParams: InferenceParams<ModelName>) {\n\t\tconst { contents, systemInstruction } = this.mapContextItems(inferenceParams)\n\t\tconst config: any = {}\n\n\t\tif (systemInstruction) {\n\t\t\tconfig.systemInstruction = systemInstruction\n\t\t}\n\n\t\tif (inferenceParams.tools && inferenceParams.tools.length > 0) {\n\t\t\tconfig.tools = [\n\t\t\t\t{\n\t\t\t\t\tfunctionDeclarations: inferenceParams.tools.map((tool) => ({\n\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\t\tparametersJsonSchema: tool.parameters,\n\t\t\t\t\t})),\n\t\t\t\t},\n\t\t\t]\n\t\t}\n\n\t\tif (inferenceParams.structuredOutput) {\n\t\t\tconfig.responseMimeType = \"application/json\"\n\t\t\tconfig.responseSchema = inferenceParams.structuredOutput.schema\n\t\t}\n\n\t\tif (inferenceParams.reasoningEffort) {\n\t\t\tconfig.thinkingConfig = {\n\t\t\t\tthinkingLevel: inferenceParams.reasoningEffort,\n\t\t\t\tincludeThoughts: true,\n\t\t\t}\n\t\t}\n\n\t\tconst request: any = {\n\t\t\tmodel: inferenceParams.model,\n\t\t\tcontents,\n\t\t\tconfig,\n\t\t}\n\n\t\tif (inferenceParams.streaming) {\n\t\t\trequest.stream = inferenceParams.streaming\n\t\t}\n\n\t\treturn request\n\t}\n\n\ttoResponse(response: any): InferenceResponse {\n\t\tconst contextItems = this.extractContextItems(response)\n\t\tconst tokenUsage = this.extractTokenUsage(response)\n\t\treturn new InferenceResponse(contextItems, tokenUsage)\n\t}\n\n\tmapContextItems(inferenceParams: InferenceParams<ModelName>): { contents: any[]; systemInstruction?: string } {\n\t\tconst context = inferenceParams.context\n\t\tconst contents: any[] = []\n\t\tconst system: string[] = []\n\t\tconst callNames = new Map<string, string>()\n\n\t\tfor (const item of context.getItems()) {\n\t\t\tif (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {\n\t\t\t\tsystem.push(item.content.text)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof UserMessageItem) {\n\t\t\t\tthis.addPart(contents, \"user\", { text: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof ModelMessageItem) {\n\t\t\t\tthis.addPart(contents, \"model\", { text: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallItem) {\n\t\t\t\tcallNames.set(item.callId, item.name)\n\t\t\t\tlet args: any\n\t\t\t\ttry {\n\t\t\t\t\targs = JSON.parse(item.args)\n\t\t\t\t} catch {\n\t\t\t\t\targs = {}\n\t\t\t\t}\n\t\t\t\tthis.addPart(contents, \"model\", { functionCall: { id: item.callId, name: item.name, args } })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallOutputItem) {\n\t\t\t\tthis.addPart(contents, \"user\", {\n\t\t\t\t\tfunctionResponse: {\n\t\t\t\t\t\tid: item.callId,\n\t\t\t\t\t\tname: callNames.get(item.callId) ?? \"\",\n\t\t\t\t\t\tresponse: this.parseResponse(item.output.text),\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tcontents,\n\t\t\tsystemInstruction: system.length > 0 ? system.join(\"\\n\\n\") : undefined,\n\t\t}\n\t}\n\n\tprivate addPart(contents: any[], role: \"user\" | \"model\", part: any): void {\n\t\tconst last = contents[contents.length - 1]\n\t\tif (last?.role === role) {\n\t\t\tlast.parts.push(part)\n\t\t\treturn\n\t\t}\n\n\t\tcontents.push({ role, parts: [part] })\n\t}\n\n\tprivate parseResponse(output: string): any {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(output)\n\t\t\treturn parsed && typeof parsed === \"object\" ? parsed : { output }\n\t\t} catch {\n\t\t\treturn { output }\n\t\t}\n\t}\n\n\textractTokenUsage(response: any): TokenUsage | undefined {\n\t\tconst usage = response.usageMetadata\n\t\tif (!usage) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn new TokenUsage(\n\t\t\tusage.promptTokenCount ?? 0,\n\t\t\tusage.candidatesTokenCount ?? 0,\n\t\t\tusage.totalTokenCount ?? 0,\n\t\t\tnew InputTokenDetails(usage.cachedContentTokenCount ?? 0),\n\t\t\tnew OutputTokenDetails(usage.thoughtsTokenCount ?? 0),\n\t\t)\n\t}\n\n\textractContextItems(response: any): ContextItem[] {\n\t\tconst items: ContextItem[] = []\n\t\tconst parts = response.candidates?.[0]?.content?.parts ?? []\n\n\t\tfor (const part of parts) {\n\t\t\tif (part.thought && part.text) {\n\t\t\t\titems.push(\n\t\t\t\t\tReasoningItem.rehydrate({\n\t\t\t\t\t\tcontent: InputText.rehydrate({ text: part.text }),\n\t\t\t\t\t\tencryptedContent: undefined,\n\t\t\t\t\t\tsummary: [],\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (part.text) {\n\t\t\t\titems.push(ModelMessageItem.rehydrate({ text: part.text }))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (part.functionCall) {\n\t\t\t\titems.push(\n\t\t\t\t\tFunctionCallItem.rehydrate({\n\t\t\t\t\t\tcallId: part.functionCall.id ?? \"\",\n\t\t\t\t\t\tname: part.functionCall.name,\n\t\t\t\t\t\targs: JSON.stringify(part.functionCall.args ?? {}),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\treturn items\n\t}\n}\n","import type { ModelName } from \"@domain/generative-model/generative-model\"\nimport type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\nimport { DeveloperMessageItem } from \"@domain/model-context/context-item/client-item/developer-message\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport { SystemMessageItem } from \"@domain/model-context/context-item/client-item/system-message\"\nimport { UserMessageItem } from \"@domain/model-context/context-item/client-item/user-message\"\nimport { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport { InferenceResponse } from \"@domain/agentic-environment/inference/response\"\nimport { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\nimport { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport type { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { InputTokenDetails, OutputTokenDetails, TokenUsage } from \"@domain/generative-model/token-usage\"\n\nexport class OpenAIChatCompletionsMapper implements InferenceEndpointMapper {\n\ttoRequest(inferenceParams: InferenceParams<ModelName>) {\n\t\tconst request: any = {\n\t\t\tmodel: inferenceParams.model,\n\t\t\tmessages: this.mapContextItems(inferenceParams),\n\t\t}\n\n\t\tif (inferenceParams.tools && inferenceParams.tools.length > 0) {\n\t\t\trequest.tools = inferenceParams.tools.map((tool) => ({\n\t\t\t\ttype: \"function\",\n\t\t\t\tfunction: {\n\t\t\t\t\tname: tool.name,\n\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\tparameters: tool.parameters,\n\t\t\t\t},\n\t\t\t}))\n\t\t}\n\n\t\tif (inferenceParams.reasoningEffort) {\n\t\t\trequest.reasoning_effort = inferenceParams.reasoningEffort\n\t\t}\n\n\t\tif (inferenceParams.streaming) {\n\t\t\trequest.stream = inferenceParams.streaming\n\t\t}\n\n\t\treturn request\n\t}\n\n\ttoResponse(response: any): InferenceResponse {\n\t\tconst contextItems = this.extractContextItems(response)\n\t\tconst tokenUsage = this.extractTokenUsage(response)\n\t\treturn new InferenceResponse(contextItems, tokenUsage)\n\t}\n\n\tmapContextItems(inferenceParams: InferenceParams<ModelName>): any[] {\n\t\tconst messages: any[] = []\n\n\t\tfor (const item of inferenceParams.context.getItems()) {\n\t\t\tif (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {\n\t\t\t\tmessages.push({ role: \"system\", content: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof UserMessageItem) {\n\t\t\t\tmessages.push({ role: \"user\", content: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof ModelMessageItem) {\n\t\t\t\tmessages.push({ role: \"assistant\", content: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallItem) {\n\t\t\t\tconst toolCall = {\n\t\t\t\t\tid: item.callId,\n\t\t\t\t\ttype: \"function\",\n\t\t\t\t\tfunction: { name: item.name, arguments: item.args },\n\t\t\t\t}\n\t\t\t\tconst last = messages[messages.length - 1]\n\t\t\t\tif (last?.role === \"assistant\") {\n\t\t\t\t\tlast.tool_calls = last.tool_calls ?? []\n\t\t\t\t\tlast.tool_calls.push(toolCall)\n\t\t\t\t} else {\n\t\t\t\t\tmessages.push({ role: \"assistant\", content: null, tool_calls: [toolCall] })\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallOutputItem) {\n\t\t\t\tmessages.push({ role: \"tool\", tool_call_id: item.callId, content: item.output.text })\n\t\t\t}\n\t\t}\n\n\t\treturn messages\n\t}\n\n\textractTokenUsage(response: any): TokenUsage | undefined {\n\t\tif (!response.usage) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn new TokenUsage(\n\t\t\tresponse.usage.prompt_tokens,\n\t\t\tresponse.usage.completion_tokens,\n\t\t\tresponse.usage.total_tokens,\n\t\t\tnew InputTokenDetails(response.usage.prompt_tokens_details?.cached_tokens ?? 0),\n\t\t\tnew OutputTokenDetails(response.usage.completion_tokens_details?.reasoning_tokens ?? 0),\n\t\t)\n\t}\n\n\textractContextItems(response: any): ContextItem[] {\n\t\tconst items: ContextItem[] = []\n\t\tconst message = response.choices?.[0]?.message\n\t\tif (!message) {\n\t\t\treturn items\n\t\t}\n\n\t\tif (message.reasoning_content) {\n\t\t\titems.push(\n\t\t\t\tReasoningItem.rehydrate({\n\t\t\t\t\tcontent: InputText.rehydrate({ text: message.reasoning_content }),\n\t\t\t\t\tencryptedContent: undefined,\n\t\t\t\t\tsummary: [],\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tif (message.content) {\n\t\t\titems.push(ModelMessageItem.rehydrate({ text: message.content }))\n\t\t}\n\n\t\tfor (const toolCall of message.tool_calls ?? []) {\n\t\t\titems.push(\n\t\t\t\tFunctionCallItem.rehydrate({\n\t\t\t\t\tcallId: toolCall.id,\n\t\t\t\t\tname: toolCall.function.name,\n\t\t\t\t\targs: toolCall.function.arguments,\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\treturn items\n\t}\n}\n","import type { InferenceResponse } from \"@domain/agentic-environment/inference/response\"\nimport { SemanticEvent } from \"@domain/model-context/semantic-event/semantic-event\"\nimport type { Endpoint } from \"@domain/generative-model/endpoint\"\nimport { OpenAIChatCompletionsMapper } from \"./openai-chat-completions-mapper\"\nimport type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport type { ModelName } from \"@domain/generative-model/generative-model\"\nimport OpenAI from \"openai\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\n\n/**\n * Optional connection config. When omitted, the `openai` SDK reads\n * `OPENAI_API_KEY` and `OPENAI_BASE_URL` from the environment, so the\n * default-constructed runtime targets whatever `OPENAI_BASE_URL` points\n * at (real OpenAI when unset). Provider presets (e.g. DeepSeek) pass an\n * explicit base URL + credential.\n */\nexport interface OpenAICompatibleConfig {\n\tbaseURL?: string\n\tapiKey?: string\n\t/**\n\t * Extra request-body fields merged into every `chat.completions`\n\t * call. This is how provider-specific quirks are handled **without\n\t * a per-provider subclass in mozaik** — the consumer supplies the\n\t * vendor-only fields (e.g. DeepSeek's `{ thinking: { type } }`,\n\t * safety flags, routing hints). Standard fields the runtime already\n\t * sets (`model`, `messages`, `tools`, `reasoning_effort`) take\n\t * precedence and are not overwritten.\n\t */\n\textraBody?: Record<string, unknown>\n}\n\n/**\n * Generic adapter for any **OpenAI Chat Completions**-compatible\n * endpoint — real OpenAI, DeepSeek, Xiaomi MiMo, OpenRouter, vLLM,\n * Ollama, etc. It speaks `/chat/completions` (not the Responses API),\n * which is the dialect third-party OpenAI-compatible providers expose.\n *\n * The base URL and credential are configurable; everything else (the\n * `ModelContext` ⇄ chat-message conversion, tool-call round-trip, token\n * usage extraction) is provider-agnostic. Provider-specific request\n * shaping (e.g. DeepSeek's `thinking` field) is supplied by the\n * consumer via {@link OpenAICompatibleConfig.extraBody} — mozaik stays\n * generic and gains no per-provider subclasses.\n *\n * Was `DeepSeekChatCompletions`; generalized so consumers can point it\n * at any OpenAI-compatible endpoint.\n */\nexport class OpenAIChatCompletions implements Endpoint {\n\tendpointMapper: InferenceEndpointMapper\n\tprivate readonly client: OpenAI\n\tprivate readonly extraBody: Record<string, unknown>\n\n\tconstructor(\n\t\tendpointMapper: InferenceEndpointMapper = new OpenAIChatCompletionsMapper(),\n\t\tconfig: OpenAICompatibleConfig = {},\n\t) {\n\t\tthis.endpointMapper = endpointMapper\n\t\t// Passing `undefined` for baseURL/apiKey lets the SDK fall back\n\t\t// to OPENAI_BASE_URL / OPENAI_API_KEY from the environment.\n\t\tthis.client = new OpenAI({\n\t\t\tbaseURL: config.baseURL,\n\t\t\tapiKey: config.apiKey,\n\t\t})\n\t\tthis.extraBody = config.extraBody ?? {}\n\t}\n\n\tprivate buildRequest(inferenceParams: InferenceParams<ModelName>): any {\n\t\treturn {\n\t\t\t...this.extraBody,\n\t\t\t...this.endpointMapper.toRequest(inferenceParams),\n\t\t}\n\t}\n\n\tasync infer(inferenceParams: InferenceParams<ModelName>): Promise<InferenceResponse> {\n\t\tconst response = await this.client.chat.completions.create(this.buildRequest(inferenceParams))\n\n\t\treturn this.endpointMapper.toResponse(response)\n\t}\n\n\tasync *stream(\n\t\tinferenceParams: InferenceParams<ModelName>,\n\t\tsignal?: AbortSignal,\n\t): AsyncIterable<SemanticEvent<unknown>> {\n\t\tconst stream: any = await this.client.chat.completions.create(this.buildRequest(inferenceParams))\n\n\t\tfor await (const event of stream) {\n\t\t\tif (signal?.aborted) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tyield new SemanticEvent(event.object ?? \"chat.completion.chunk\", event)\n\t\t}\n\t}\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const claudeSonnet46Specification: ModelSpecification = {\n\tname: \"claude-sonnet-4-6\",\n\tprovider: \"anthropic\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"max\", \"high\", \"medium\", \"low\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 200_000,\n\tmaxOutputTokens: 64_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const claudeOpus48Specification: ModelSpecification = {\n\tname: \"claude-opus-4-8\",\n\tprovider: \"anthropic\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"max\", \"xhigh\", \"high\", \"medium\", \"low\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 200_000,\n\tmaxOutputTokens: 32_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const claudeOpus47Specification: ModelSpecification = {\n\tname: \"claude-opus-4-7\",\n\tprovider: \"anthropic\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"max\", \"xhigh\", \"high\", \"medium\", \"low\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 200_000,\n\tmaxOutputTokens: 32_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const gemini35FlashSpecification: ModelSpecification = {\n\tname: \"gemini-3.5-flash\",\n\tprovider: \"google\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"high\", \"medium\", \"low\", \"minimal\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 1_048_576,\n\tmaxOutputTokens: 64_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const gemini31ProSpecification: ModelSpecification = {\n\tname: \"gemini-3.1-pro-preview\",\n\tprovider: \"google\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"high\", \"medium\", \"low\", \"minimal\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 1_048_576,\n\tmaxOutputTokens: 64_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const deepSeekV4FlashSpecification: ModelSpecification = {\n\tname: \"deepseek-v4-flash\",\n\tprovider: \"deepseek\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"max\", \"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 1_000_000,\n\tmaxOutputTokens: 384_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: false,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const deepSeekV4ProSpecification: ModelSpecification = {\n\tname: \"deepseek-v4-pro\",\n\tprovider: \"deepseek\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"max\", \"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 1_000_000,\n\tmaxOutputTokens: 384_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: false,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const gpt54Specification: ModelSpecification = {\n\tname: \"gpt-5.4\",\n\tprovider: \"openai\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"xhigh\", \"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 1_050_000,\n\tmaxOutputTokens: 128_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const gpt54MiniSpecification: ModelSpecification = {\n\tname: \"gpt-5.4-mini\",\n\tprovider: \"openai\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"xhigh\", \"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 400_000,\n\tmaxOutputTokens: 128_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const gpt54NanoSpecification: ModelSpecification = {\n\tname: \"gpt-5.4-nano\",\n\tprovider: \"openai\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"xhigh\", \"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 400_000,\n\tmaxOutputTokens: 128_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const gpt55Specification: ModelSpecification = {\n\tname: \"gpt-5.5\",\n\tprovider: \"openai\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"xhigh\", \"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 1_050_000,\n\tmaxOutputTokens: 128_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const claudeHaiku45Specification: ModelSpecification = {\n\tname: \"claude-haiku-4-5\",\n\tprovider: \"anthropic\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 200_000,\n\tmaxOutputTokens: 64_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import { AnthropicMessages } from \"@infra/providers/anthropic/endpoints/anthropic-messages\"\nimport { OpenAIResponses } from \"@infra/providers/openai/endpoints/openai-responses\"\nimport { GeminiGenerateContent } from \"@infra/providers/gemini/endpoints/gemini-generate-content\"\nimport { OpenAIChatCompletions } from \"@infra/providers/openai/endpoints/openai-chat-completions\"\nimport { claudeSonnet46Specification } from \"@infra/providers/anthropic/models/claude-4-6-sonnet\"\nimport { claudeOpus48Specification } from \"@infra/providers/anthropic/models/claude-4-8-opus\"\nimport { claudeOpus47Specification } from \"@infra/providers/anthropic/models/claude-4-7-opus\"\nimport { gemini35FlashSpecification } from \"@infra/providers/gemini/models/gemini-3-5-flash\"\nimport { gemini31ProSpecification } from \"@infra/providers/gemini/models/gemini-3-1-pro\"\nimport { deepSeekV4FlashSpecification } from \"@infra/providers/deepseek/models/deepseek-v4-flash\"\nimport { deepSeekV4ProSpecification } from \"@infra/providers/deepseek/models/deepseek-v4-pro\"\nimport { gpt54Specification } from \"@infra/providers/openai/models/gpt-5-4\"\nimport { gpt54MiniSpecification } from \"@infra/providers/openai/models/gpt-5-4-mini\"\nimport { gpt54NanoSpecification } from \"@infra/providers/openai/models/gpt-5-4-nano\"\nimport { gpt55Specification } from \"@infra/providers/openai/models/gpt-5-5\"\nimport { claudeHaiku45Specification } from \"@infra/providers/anthropic/models/claude-4-5-haiku\"\nimport type { GenerativeModel, ModelName } from \"@domain/generative-model/generative-model\"\nimport type { GenerativeModelRepository } from \"@domain/generative-model/generative-model-repository\"\n\nexport class InMemoryGenerativeModelRepository implements GenerativeModelRepository {\n\tgetByModelName(modelName: ModelName): Promise<GenerativeModel> {\n\t\tlet generativeModel = undefined\n\t\tswitch (modelName) {\n\t\t\tcase \"gpt-5.4\":\n\t\t\t\tgenerativeModel = {\n\t\t\t\t\tendpoint: new OpenAIResponses(),\n\t\t\t\t\tspecification: gpt54Specification,\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase \"gpt-5.4-mini\":\n\t\t\t\tgenerativeModel = {\n\t\t\t\t\tendpoint: new OpenAIResponses(),\n\t\t\t\t\tspecification: gpt54MiniSpecification,\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase \"gpt-5.4-nano\":\n\t\t\t\tgenerativeModel = {\n\t\t\t\t\tendpoint: new OpenAIResponses(),\n\t\t\t\t\tspecification: gpt54NanoSpecification,\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase \"gpt-5.5\":\n\t\t\t\tgenerativeModel = {\n\t\t\t\t\tendpoint: new OpenAIResponses(),\n\t\t\t\t\tspecification: gpt55Specification,\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase \"claude-haiku-4-5\":\n\t\t\t\tgenerativeModel = {\n\t\t\t\t\tendpoint: new AnthropicMessages(),\n\t\t\t\t\tspecification: claudeHaiku45Specification,\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase \"claude-sonnet-4-6\":\n\t\t\t\tgenerativeModel = {\n\t\t\t\t\tendpoint: new AnthropicMessages(),\n\t\t\t\t\tspecification: claudeSonnet46Specification,\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase \"claude-opus-4-7\":\n\t\t\t\tgenerativeModel = {\n\t\t\t\t\tendpoint: new AnthropicMessages(),\n\t\t\t\t\tspecification: claudeOpus47Specification,\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase \"claude-opus-4-8\":\n\t\t\t\tgenerativeModel = {\n\t\t\t\t\tendpoint: new AnthropicMessages(),\n\t\t\t\t\tspecification: claudeOpus48Specification,\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase \"gemini-3.5-flash\":\n\t\t\t\tgenerativeModel = {\n\t\t\t\t\tendpoint: new GeminiGenerateContent(),\n\t\t\t\t\tspecification: gemini35FlashSpecification,\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase \"gemini-3.1-pro-preview\":\n\t\t\t\tgenerativeModel = {\n\t\t\t\t\tendpoint: new GeminiGenerateContent(),\n\t\t\t\t\tspecification: gemini31ProSpecification,\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase \"deepseek-v4-flash\":\n\t\t\t\tgenerativeModel = {\n\t\t\t\t\tendpoint: new OpenAIChatCompletions(),\n\t\t\t\t\tspecification: deepSeekV4FlashSpecification,\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase \"deepseek-v4-pro\":\n\t\t\t\tgenerativeModel = {\n\t\t\t\t\tendpoint: new OpenAIChatCompletions(),\n\t\t\t\t\tspecification: deepSeekV4ProSpecification,\n\t\t\t\t}\n\t\t}\n\n\t\tif (!generativeModel) {\n\t\t\tthrow new Error(`Unsupported model: ${modelName}`)\n\t\t}\n\n\t\treturn Promise.resolve(generativeModel)\n\t}\n}\n","import type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport type { RequestValidationRule } from \"./rule\"\nimport type { ModelName, ModelSpecification } from \"../generative-model\"\n\nexport class ReasoningEffortValidation implements RequestValidationRule {\n\treadonly name = \"reasoning-effort\"\n\n\tisValid(inferenceParams: InferenceParams<ModelName>, model: ModelSpecification): boolean {\n\t\tif (inferenceParams.reasoningEffort === undefined) {\n\t\t\treturn true\n\t\t}\n\n\t\tif (!model.supportsReasoningEffort) {\n\t\t\treturn false\n\t\t}\n\n\t\treturn model.supportedReasoningEfforts.includes(inferenceParams.reasoningEffort)\n\t}\n}\n","import type { RequestValidationRule } from \"./rule\"\nimport type { ModelName, ModelSpecification } from \"../generative-model\"\nimport type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\n\nexport class ToolCallingValidation implements RequestValidationRule {\n\treadonly name = \"tool-calling\"\n\n\tisValid(inferenceParams: InferenceParams<ModelName>, model: ModelSpecification): boolean {\n\t\tif (inferenceParams.tools === undefined) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn model.supportsFunctionCalling\n\t}\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\nimport type { RequestValidationRule } from \"./rule\"\nimport type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport type { ModelName } from \"@domain/generative-model/generative-model\"\n\nexport class StreamingValidation implements RequestValidationRule {\n\treadonly name = \"streaming\"\n\n\tisValid(inferenceParams: InferenceParams<ModelName>, model: ModelSpecification): boolean {\n\t\tif (!inferenceParams.streaming) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn model.supportsStreaming\n\t}\n}\n","import type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport type { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { DeveloperMessageItem } from \"@domain/model-context/context-item/client-item/developer-message\"\nimport { SystemMessageItem } from \"@domain/model-context/context-item/client-item/system-message\"\nimport { UserMessageItem } from \"@domain/model-context/context-item/client-item/user-message\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport type { RequestValidationRule } from \"./rule\"\nimport type { ModelName, ModelSpecification } from \"../generative-model\"\n\nfunction getContextItemValidationKey(item: ContextItem): string {\n\tif (item instanceof UserMessageItem) {\n\t\treturn \"user_message\"\n\t}\n\tif (item instanceof SystemMessageItem) {\n\t\treturn \"system_message\"\n\t}\n\tif (item instanceof DeveloperMessageItem) {\n\t\treturn \"developer_message\"\n\t}\n\tif (item instanceof ModelMessageItem) {\n\t\treturn \"model_message\"\n\t}\n\treturn item.getType()\n}\n\nexport class ContextValidation implements RequestValidationRule {\n\treadonly name = \"context\"\n\n\tisValid(inferenceParams: InferenceParams<ModelName>, model: ModelSpecification): boolean {\n\t\treturn inferenceParams.context.items.every((item) =>\n\t\t\tmodel.supportedContextItemTypes.includes(getContextItemValidationKey(item)),\n\t\t)\n\t}\n}\n","import type { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport type { ModelName, ModelSpecification } from \"../generative-model\"\nimport type { RequestValidationRule } from \"./rule\"\nimport { ReasoningEffortValidation } from \"./reasoning-effort\"\nimport { ToolCallingValidation } from \"./tool-calling\"\nimport { StreamingValidation } from \"./streaming\"\nimport { StructuredOutputValidation } from \"./structured-output\"\nimport { ContextValidation } from \"./context\"\n\nexport const defaultRequestValidationRules: RequestValidationRule[] = [\n\tnew ReasoningEffortValidation(),\n\tnew ToolCallingValidation(),\n\tnew StreamingValidation(),\n\tnew StructuredOutputValidation(),\n\tnew ContextValidation(),\n]\n\nexport class InferenceRequestValidator {\n\tconstructor(private readonly rules: RequestValidationRule[] = defaultRequestValidationRules) {}\n\n\tvalidate(inferenceParams: InferenceParams<ModelName>, model: ModelSpecification): void {\n\t\tfor (const rule of this.rules) {\n\t\t\tif (!rule.isValid(inferenceParams, model)) {\n\t\t\t\tthrow new Error(`Request validation \"${rule.name}\" failed for model \"${model.name}\"`)\n\t\t\t}\n\t\t}\n\t}\n}\n","import { ModelContext } from \"@domain/model-context/model-context\"\nimport { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { UserMessageItem } from \"@domain/model-context/context-item/client-item/user-message\"\nimport { DeveloperMessageItem } from \"@domain/model-context/context-item/client-item/developer-message\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport { StructuredOutputFormat } from \"@domain/generative-model/request-validation/structured-output\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport { ModelContextRepository } from \"@domain/model-context/model-context-repository\"\nimport { InputTokenDetails, OutputTokenDetails, TokenUsage } from \"@domain/generative-model/token-usage\"\nimport { Tool } from \"@domain/generative-model/tool\"\nimport { McpClient, type McpServerConfig, type McpToolSpec } from \"@infra/mcp/mcp-client\"\nimport { McpToolRegistry } from \"@infra/mcp/mcp-tool-registry\"\nimport { InMemoryModelContextRepository } from \"@infra/repository/in-memory-model-context-repository\"\nimport { SystemMessageItem } from \"@domain/model-context/context-item/client-item/system-message\"\nimport { Participant } from \"@domain/agentic-environment/participant\"\nimport { AgenticEnvironment } from \"@domain/agentic-environment/agentic-environment\"\nimport { AgenticError } from \"@domain/agentic-environment/errors/base-error\"\nimport { SemanticEvent } from \"@domain/model-context/semantic-event/semantic-event\"\nimport { InferenceResponse } from \"@domain/agentic-environment/inference/response\"\nimport { Endpoint } from \"@domain/generative-model/endpoint\"\nimport { RunInference } from \"@app/use-cases/run-inference\"\nimport { InferenceParams } from \"@domain/agentic-environment/inference/params\"\nimport { ExecuteFunctionCall } from \"@app/use-cases/execute-function-call\"\nimport { FunctionCallRunner } from \"@app/services/function-call-runner\"\nimport { BaseParticipant } from \"@app/participants/participant\"\nimport { SendMessage } from \"@app/use-cases/send-message\"\nimport { ModelName } from \"@domain/generative-model/generative-model\"\nimport type { GenerativeModelRepository } from \"@domain/generative-model/generative-model-repository\"\nimport { InMemoryGenerativeModelRepository } from \"@infra/repository/generative-model-repository\"\nimport { InferenceRequestValidator } from \"@domain/generative-model/request-validation/inference-request-validator\"\n\nconst generativeModelRepository: GenerativeModelRepository = new InMemoryGenerativeModelRepository()\nconst inferenceRequestValidator = new InferenceRequestValidator()\nconst runInferenceUseCase = new RunInference(generativeModelRepository, inferenceRequestValidator)\nconst executeFunctionCallUseCase = new ExecuteFunctionCall(new FunctionCallRunner())\nconst sendMessageUseCase = new SendMessage()\n\nconst runInference = (inferenceParams: InferenceParams<ModelName>): void => {\n\trunInferenceUseCase.execute(inferenceParams)\n}\n\nconst executeFunctionCall = (\n\tenvironment: AgenticEnvironment,\n\tfunctionCallItem: FunctionCallItem,\n\ttool: Tool,\n\tcaller: Participant,\n): void => {\n\texecuteFunctionCallUseCase.execute(environment, functionCallItem, tool, caller)\n}\n\nconst sendMessage = (environment: AgenticEnvironment, message: string, caller: Participant): void => {\n\tsendMessageUseCase.execute(environment, message, caller)\n}\n\nexport {\n\tModelContext,\n\tModelContextRepository,\n\tModelName,\n\tInMemoryModelContextRepository,\n\tContextItem,\n\tSemanticEvent,\n\tUserMessageItem,\n\tDeveloperMessageItem,\n\tSystemMessageItem,\n\tModelMessageItem,\n\tFunctionCallItem,\n\tFunctionCallOutputItem,\n\tReasoningItem,\n\tStructuredOutputFormat,\n\tTokenUsage,\n\tInputTokenDetails,\n\tOutputTokenDetails,\n\tTool,\n\tMcpClient,\n\ttype McpServerConfig,\n\ttype McpToolSpec,\n\tMcpToolRegistry,\n\tEndpoint,\n\tAgenticEnvironment,\n\tParticipant,\n\tBaseParticipant,\n\tAgenticError,\n\tInferenceResponse,\n\tInferenceParams,\n\trunInference,\n\texecuteFunctionCall,\n\tsendMessage,\n}\n"],"mappings":";AAEO,IAAM,eAAN,MAAM,cAAa;AAAA,EAKzB,YAAY,IAAY,WAAmB,OAAsB;AAChE,SAAK,YAAY;AACjB,SAAK,KAAK;AACV,SAAK,QAAQ;AAAA,EACd;AAAA,EAEA,eAAe,MAAiC;AAC/C,SAAK,MAAM,KAAK,IAAI;AACpB,WAAO;AAAA,EACR;AAAA,EAEA,iBAAiB,OAAoC;AACpD,eAAW,QAAQ,OAAO;AACzB,YAAM,WAAW,KAAK,QAAQ;AAC9B,UAAI,aAAa,mBAAmB,aAAa,aAAa,aAAa,aAAa;AACvF,cAAM,IAAI,MAAM,sBAAsB,QAAQ,EAAE;AAAA,MACjD;AAAA,IACD;AACA,SAAK,MAAM,KAAK,GAAG,KAAK;AACxB,WAAO;AAAA,EACR;AAAA,EAEA,WAA0B;AACzB,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,cAA2B;AAC1B,QAAI,KAAK,MAAM,WAAW,GAAG;AAC5B,YAAM,IAAI,MAAM,qBAAqB;AAAA,IACtC;AACA,WAAO,KAAK,MAAM,KAAK,MAAM,SAAS,CAAC;AAAA,EACxC;AAAA,EAEA,OAAO,OAAO,WAAiC;AAC9C,UAAM,KA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;AAAA,MACrF;AAAA,IACD;AAAA,EACD;AACD;;;ACMA,IAAM,4BAAuD,IAAI,kCAAkC;AACnG,IAAM,4BAA4B,IAAI,0BAA0B;AAChE,IAAM,sBAAsB,IAAI,aAAa,2BAA2B,yBAAyB;AACjG,IAAM,6BAA6B,IAAI,oBAAoB,IAAI,mBAAmB,CAAC;AACnF,IAAM,qBAAqB,IAAI,YAAY;AAE3C,IAAM,eAAe,CAAC,oBAAsD;AAC3E,sBAAoB,QAAQ,eAAe;AAC5C;AAEA,IAAM,sBAAsB,CAC3B,aACA,kBACA,MACA,WACU;AACV,6BAA2B,QAAQ,aAAa,kBAAkB,MAAM,MAAM;AAC/E;AAEA,IAAM,cAAc,CAAC,aAAiC,SAAiB,WAA8B;AACpG,qBAAmB,QAAQ,aAAa,SAAS,MAAM;AACxD;","names":["_a","error","generativeModelRepository","OpenAI"]}
|
|
1
|
+
{"version":3,"sources":["../src/domain/model-context/model-context.ts","../src/domain/model-context/context-item/context-item.ts","../src/domain/model-context/context-item/item-content/item-content.ts","../src/domain/model-context/context-item/item-content/input-text.ts","../src/domain/model-context/context-item/client-item/user-message.ts","../src/domain/model-context/context-item/client-item/developer-message.ts","../src/domain/model-context/context-item/item-content/output-text.ts","../src/domain/model-context/context-item/model-item/model-message.ts","../src/domain/model-context/context-item/model-item/function-call.ts","../src/domain/model-context/context-item/model-item/reasoning.ts","../src/domain/generative-model/request-validation/structured-output.ts","../src/domain/model-context/context-item/client-item/function-call-output.ts","../src/domain/generative-model/token-usage.ts","../src/infrastructure/mcp/mcp-client.ts","../src/infrastructure/mcp/mcp-tool-registry.ts","../src/domain/model-context/context-item/client-item/system-message.ts","../src/domain/agentic-environment/semantic-event/event.ts","../src/application/states/inference.ts","../src/domain/agentic-environment/participant/participant.ts","../src/domain/agentic-environment/participant/memory.ts","../src/domain/agentic-environment/participant/agent.ts","../src/application/use-cases/create-agent.ts","../src/domain/agentic-environment/participant/human.ts","../src/application/use-cases/create-human.ts","../src/domain/agentic-environment/runtime-state.ts","../src/application/services/runtime.ts","../src/domain/agentic-environment/semantic-event/event-processor.ts","../src/application/use-cases/join.ts","../src/application/use-cases/leave.ts","../src/application/use-cases/send-message.ts","../src/domain/agentic-environment/loop/agent-loop.ts","../src/domain/agentic-environment/loop/state-executor.ts","../src/application/states/function-call.ts","../src/application/states/context-update.ts","../src/application/states/model-message.ts","../src/domain/agentic-environment/loop/transition-resolver.ts","../src/domain/agentic-environment/loop/transition-specification.ts","../src/domain/agentic-environment/loop/transition-rule.ts","../src/domain/agentic-environment/loop/event-publisher-visitor.ts","../src/application/states/inference-streaming.ts","../src/application/use-cases/run-loop.ts","../src/infrastructure/providers/anthropic/endpoints/anthropic-messages-mapper.ts","../src/infrastructure/providers/anthropic/endpoints/anthropic-messages.ts","../src/infrastructure/providers/openai/endpoints/openai-responses.ts","../src/domain/model-context/context-item/item-content/summary-text.ts","../src/infrastructure/providers/openai/endpoints/openai-responses-mapper.ts","../src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts","../src/infrastructure/providers/gemini/endpoints/gemini-generate-content-mapper.ts","../src/infrastructure/providers/openai/endpoints/openai-chat-completions-mapper.ts","../src/infrastructure/providers/openai/endpoints/openai-chat-completions.ts","../src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts","../src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts","../src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts","../src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts","../src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts","../src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts","../src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts","../src/infrastructure/providers/openai/models/gpt-5-4.ts","../src/infrastructure/providers/openai/models/gpt-5-4-mini.ts","../src/infrastructure/providers/openai/models/gpt-5-4-nano.ts","../src/infrastructure/providers/openai/models/gpt-5-5.ts","../src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts","../src/application/services/models.ts","../src/domain/generative-model/request-validation/reasoning-effort.ts","../src/domain/generative-model/request-validation/tool-calling.ts","../src/domain/generative-model/request-validation/streaming.ts","../src/domain/generative-model/request-validation/context.ts","../src/domain/generative-model/request-validation/inference-request-validator.ts","../src/application/services/inference-runner.ts","../src/application/services/function-call.ts","../src/application/use-cases/send-event.ts","../src/define-runtime.ts","../src/domain/agentic-environment/situation/situation-specification.ts"],"sourcesContent":["import type { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { FunctionCallItem } from \"./context-item/model-item/function-call\"\nimport { ModelMessageItem } from \"./context-item/model-item/model-message\"\nimport { ReasoningItem } from \"./context-item/model-item/reasoning\"\n\nexport type ModelContextItem = ModelMessageItem | FunctionCallItem | ReasoningItem\n\nexport class ModelContext {\n\treadonly id: string\n\treadonly items: ContextItem[]\n\n\tconstructor(id: string, items: ContextItem[]) {\n\t\tthis.id = id\n\t\tthis.items = items\n\t}\n\n\tgetItems(): ContextItem[] {\n\t\treturn this.items\n\t}\n\n\taddContextItems(contextItems: ContextItem[]): ModelContext {\n\t\tthis.items.push(...contextItems)\n\t\treturn this\n\t}\n\n\taddItem(item: ContextItem): ModelContext {\n\t\tthis.items.push(item)\n\t\treturn this\n\t}\n\n\tstatic create(): ModelContext {\n\t\tconst id = crypto.randomUUID()\n\t\treturn new ModelContext(id, [])\n\t}\n\n\tstatic rehydrate(data: { id: string; items: ContextItem[] }): ModelContext {\n\t\treturn new ModelContext(data.id, data.items)\n\t}\n}\n","export abstract class ContextItem {\n\tabstract readonly type: string\n\n\tgetType(): string {\n\t\treturn this.type\n\t}\n}\n","export abstract class ItemContent {\n\tabstract readonly type: string\n}\n","import { ItemContent } from \"@domain/model-context/context-item/item-content/item-content\"\n\nexport class InputText extends ItemContent {\n\treadonly type = \"input_text\"\n\n\tprivate constructor(public readonly text: string) {\n\t\tsuper()\n\t}\n\n\tstatic create(text: string): InputText {\n\t\treturn new InputText(text)\n\t}\n\n\tstatic rehydrate(data: { text: string }): InputText {\n\t\treturn new InputText(data.text)\n\t}\n}\n","import { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\n\nexport class UserMessageItem extends ContextItem {\n\treadonly type = \"message\"\n\treadonly role = \"user\"\n\treadonly content: InputText\n\n\tprivate constructor(content: InputText) {\n\t\tsuper()\n\t\tthis.content = content\n\t}\n\n\tstatic create(text: string): UserMessageItem {\n\t\tconst content = InputText.create(text)\n\t\treturn new UserMessageItem(content)\n\t}\n\n\tstatic rehydrate(data: { text: string }): UserMessageItem {\n\t\tconst content = InputText.rehydrate(data)\n\t\treturn new UserMessageItem(content)\n\t}\n}\n","import { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\nimport { ContextItem } from \"@domain/model-context/context-item/context-item\"\n\nexport class DeveloperMessageItem extends ContextItem {\n\treadonly type = \"message\"\n\treadonly role = \"developer\"\n\treadonly content: InputText\n\n\tprivate constructor(content: InputText) {\n\t\tsuper()\n\t\tthis.content = content\n\t}\n\n\tstatic create(text: string): DeveloperMessageItem {\n\t\tconst content = InputText.create(text)\n\t\treturn new DeveloperMessageItem(content)\n\t}\n\n\tstatic rehydrate(data: { text: string }): DeveloperMessageItem {\n\t\tconst content = InputText.rehydrate(data)\n\t\treturn new DeveloperMessageItem(content)\n\t}\n}\n","import { ItemContent } from \"@domain/model-context/context-item/item-content/item-content\"\n\nexport class OutputText extends ItemContent {\n\treadonly type = \"output_text\"\n\n\tprivate constructor(public readonly text: string) {\n\t\tsuper()\n\t}\n\n\tstatic rehydrate(data: { text: string }): OutputText {\n\t\treturn new OutputText(data.text)\n\t}\n}\n","import { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { OutputText } from \"@domain/model-context/context-item/item-content/output-text\"\n\nexport class ModelMessageItem extends ContextItem {\n\treadonly type = \"message\"\n\treadonly role = \"assistant\"\n\treadonly content: OutputText\n\n\tprivate constructor(content: OutputText) {\n\t\tsuper()\n\t\tthis.content = content\n\t}\n\n\tstatic rehydrate(data: { text: string }): ModelMessageItem {\n\t\tconst content = OutputText.rehydrate(data)\n\t\treturn new ModelMessageItem(content)\n\t}\n}\n","import { ContextItem } from \"@domain/model-context/context-item/context-item\"\n\nexport class FunctionCallItem extends ContextItem {\n\treadonly type = \"function_call\"\n\treadonly callId: string\n\treadonly name: string\n\treadonly args: string\n\n\tprivate constructor(callId: string, name: string, args: string) {\n\t\tsuper()\n\t\tthis.callId = callId\n\t\tthis.name = name\n\t\tthis.args = args\n\t}\n\n\tstatic rehydrate(data: { callId: string; name: string; args: string }): FunctionCallItem {\n\t\treturn new FunctionCallItem(data.callId, data.name, data.args)\n\t}\n}\n","import type { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\nimport type { SummaryText } from \"@domain/model-context/context-item/item-content/summary-text\"\nimport { ContextItem } from \"@domain/model-context/context-item/context-item\"\n\nexport class ReasoningItem extends ContextItem {\n\treadonly type = \"reasoning\"\n\treadonly content: InputText | undefined\n\treadonly encryptedContent: string | undefined\n\treadonly summary: SummaryText[]\n\n\tprivate constructor(\n\t\tcontent: InputText | undefined,\n\t\tencryptedContent?: string | undefined,\n\t\tsummary: SummaryText[] = [],\n\t) {\n\t\tsuper()\n\t\tthis.content = content\n\t\tthis.encryptedContent = encryptedContent\n\t\tthis.summary = summary\n\t}\n\n\tstatic rehydrate(data: {\n\t\tcontent: InputText | undefined\n\t\tencryptedContent: string | undefined\n\t\tsummary: SummaryText[]\n\t}): ReasoningItem {\n\t\treturn new ReasoningItem(data.content, data.encryptedContent, data.summary)\n\t}\n}\n","import type { InferenceInput } from \"@app/states/inference\"\nimport type { ModelSpecification } from \"../generative-model\"\nimport type { RequestValidationRule } from \"./rule\"\n\nexport type StructuredOutputFormat = {\n\tname?: string\n\tschema: Record<string, any>\n\tstrict?: boolean\n}\n\nexport class StructuredOutputValidation implements RequestValidationRule {\n\treadonly name = \"structured-output\"\n\n\tisValid(inferenceInput: InferenceInput, model: ModelSpecification): boolean {\n\t\tif (inferenceInput.structuredOutput === undefined) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn model.supportsStructuredOutput\n\t}\n}\n","import { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\n\nexport class FunctionCallOutputItem extends ContextItem {\n\treadonly type = \"function_call_output\"\n\treadonly callId: string\n\treadonly output: InputText\n\n\tprivate constructor(callId: string, output: InputText) {\n\t\tsuper()\n\t\tthis.callId = callId\n\t\tthis.output = output\n\t}\n\n\tstatic create(callId: string, output: string): FunctionCallOutputItem {\n\t\tconst outputText = InputText.create(output)\n\t\treturn new FunctionCallOutputItem(callId, outputText)\n\t}\n\n\tstatic rehydrate(data: { callId: string; output: InputText }): FunctionCallOutputItem {\n\t\treturn new FunctionCallOutputItem(data.callId, data.output)\n\t}\n}\n","export class InputTokenDetails {\n\treadonly cached_tokens: number\n\n\tconstructor(cached_tokens: number) {\n\t\tthis.cached_tokens = cached_tokens\n\t}\n}\n\nexport class OutputTokenDetails {\n\treadonly reasoning_tokens: number\n\n\tconstructor(reasoning_tokens: number) {\n\t\tthis.reasoning_tokens = reasoning_tokens\n\t}\n}\n\nexport class TokenUsage {\n\treadonly inputTokens: number\n\treadonly outputTokens: number\n\treadonly totalTokens: number\n\treadonly inputTokenDetails: InputTokenDetails\n\treadonly outputTokenDetails: OutputTokenDetails\n\n\tconstructor(\n\t\tinputTokens: number,\n\t\toutputTokens: number,\n\t\ttotalTokens: number,\n\t\tinputTokenDetails: InputTokenDetails,\n\t\toutputTokenDetails: OutputTokenDetails,\n\t) {\n\t\tthis.inputTokens = inputTokens\n\t\tthis.outputTokens = outputTokens\n\t\tthis.totalTokens = totalTokens\n\t\tthis.inputTokenDetails = inputTokenDetails\n\t\tthis.outputTokenDetails = outputTokenDetails\n\t}\n}\n","import { Client } from \"@modelcontextprotocol/sdk/client/index.js\"\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\"\n\nexport interface McpServerConfig {\n\t/** The MCP server URL, e.g. https://api.githubcopilot.com/mcp/ */\n\turl: string\n\t/** Bearer token sent as `Authorization: Bearer <token>` (e.g. a GitHub token). */\n\tauthToken?: string\n\t/** Extra headers merged into every request (overridden by `authToken` for Authorization). */\n\theaders?: Record<string, string>\n\t/** Client name reported to the server (defaults to \"mozaik\"). */\n\tname?: string\n}\n\nexport interface McpToolSpec {\n\tname: string\n\tdescription: string\n\t/** JSON Schema for the tool's arguments (maps 1:1 to FunctionTool.parameters). */\n\tinputSchema: Record<string, any>\n}\n\n/**\n * A thin wrapper over the MCP TypeScript SDK using the Streamable HTTP transport — what\n * remote MCP servers (e.g. GitHub's `api.githubcopilot.com/mcp/`) speak. One client per\n * server; lazily connects on first use. Infrastructure-only: the domain never sees this.\n */\nexport class McpClient {\n\tprivate readonly client: Client\n\tprivate readonly transport: StreamableHTTPClientTransport\n\tprivate connected = false\n\n\tconstructor(private readonly config: McpServerConfig) {\n\t\tconst headers: Record<string, string> = { ...(config.headers ?? {}) }\n\t\tif (config.authToken) headers.Authorization = `Bearer ${config.authToken}`\n\t\tthis.transport = new StreamableHTTPClientTransport(\n\t\t\tnew URL(config.url),\n\t\t\tObject.keys(headers).length > 0 ? { requestInit: { headers } } : undefined,\n\t\t)\n\t\tthis.client = new Client({ name: config.name ?? \"mozaik\", version: \"1.0.0\" }, { capabilities: {} })\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.connected) return\n\t\tawait this.client.connect(this.transport)\n\t\tthis.connected = true\n\t}\n\n\t/** The tools this server exposes. */\n\tasync listTools(): Promise<McpToolSpec[]> {\n\t\tawait this.connect()\n\t\tconst res = await this.client.listTools()\n\t\treturn (res.tools ?? []).map((t) => ({\n\t\t\tname: t.name,\n\t\t\tdescription: t.description ?? \"\",\n\t\t\tinputSchema: (t.inputSchema as Record<string, any>) ?? { type: \"object\", properties: {} },\n\t\t}))\n\t}\n\n\t/** Call a tool by name; returns its text output. Throws if the server flags an error. */\n\tasync callTool(name: string, args: Record<string, any>): Promise<string> {\n\t\tawait this.connect()\n\t\tconst res = await this.client.callTool({ name, arguments: args ?? {} })\n\t\tconst text = extractText(res)\n\t\tif ((res as { isError?: boolean }).isError) {\n\t\t\tthrow new Error(`MCP tool \"${name}\" failed: ${text || \"unknown error\"}`)\n\t\t}\n\t\treturn text\n\t}\n\n\tasync close(): Promise<void> {\n\t\tif (!this.connected) return\n\t\ttry {\n\t\t\tawait this.client.close()\n\t\t} catch {\n\t\t\t// best-effort teardown — the transport may already be gone\n\t\t}\n\t\tthis.connected = false\n\t}\n}\n\n/** Concatenate the text blocks of an MCP tool result (ignores non-text content). */\nfunction extractText(res: unknown): string {\n\tconst content = (res as { content?: unknown }).content\n\tif (!Array.isArray(content)) return \"\"\n\treturn content\n\t\t.filter((c): c is { type: \"text\"; text: string } => (c as { type?: string })?.type === \"text\" && typeof (c as { text?: unknown }).text === \"string\")\n\t\t.map((c) => c.text)\n\t\t.join(\"\\n\")\n}\n","import type { FunctionTool } from \"@domain/generative-model/tool\"\nimport { McpClient, type McpServerConfig } from \"./mcp-client.js\"\n\n/** The slice of an MCP client the registry needs — lets tests inject a fake. */\nexport interface McpClientLike {\n\tlistTools(): Promise<Array<{ name: string; description: string; inputSchema: Record<string, any> }>>\n\tcallTool(name: string, args: Record<string, any>): Promise<string>\n\tclose(): Promise<void>\n}\n\n/**\n * Connects to one or more MCP servers and exposes their tools as mozaik `FunctionTool`s.\n * Each tool's `invoke()` proxies the call back to its MCP server. Because they are plain\n * FunctionTools, every provider mapper and the existing function-call loop handle them\n * with no changes — MCP support adds no new tool type and touches no provider code.\n *\n * `strict` is false: MCP servers publish arbitrary JSON Schemas that won't always satisfy\n * a provider's strict function-calling mode.\n */\nexport class McpToolRegistry {\n\tprivate readonly clients: McpClientLike[] = []\n\n\tconstructor(\n\t\tprivate readonly servers: McpServerConfig[],\n\t\tprivate readonly createClient: (config: McpServerConfig) => McpClientLike = (config) => new McpClient(config),\n\t) {}\n\n\t/** Discover every tool across the configured servers, as FunctionTools ready to pass to a model. */\n\tasync discoverTools(): Promise<FunctionTool[]> {\n\t\tconst tools: FunctionTool[] = []\n\t\tfor (const server of this.servers) {\n\t\t\tconst client = this.createClient(server)\n\t\t\tthis.clients.push(client)\n\t\t\tfor (const spec of await client.listTools()) {\n\t\t\t\ttools.push({\n\t\t\t\t\ttype: \"function\",\n\t\t\t\t\tname: spec.name,\n\t\t\t\t\tdescription: spec.description,\n\t\t\t\t\tparameters: spec.inputSchema,\n\t\t\t\t\tstrict: false,\n\t\t\t\t\tinvoke: (args: unknown) => client.callTool(spec.name, (args as Record<string, any>) ?? {}),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn tools\n\t}\n\n\t/** Close all underlying MCP connections. */\n\tasync close(): Promise<void> {\n\t\tawait Promise.all(this.clients.map((c) => c.close()))\n\t}\n}\n","import { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\nimport { ContextItem } from \"@domain/model-context/context-item/context-item\"\n\nexport class SystemMessageItem extends ContextItem {\n\treadonly type = \"message\"\n\treadonly role = \"system\"\n\treadonly content: InputText\n\n\tprivate constructor(content: InputText) {\n\t\tsuper()\n\t\tthis.content = content\n\t}\n\n\tstatic create(text: string): SystemMessageItem {\n\t\tconst content = InputText.create(text)\n\t\treturn new SystemMessageItem(content)\n\t}\n\n\tstatic rehydrate(data: { text: string }): SystemMessageItem {\n\t\tconst content = InputText.rehydrate(data)\n\t\treturn new SystemMessageItem(content)\n\t}\n}\n","import { ParticipantManifest } from \"../participant/participant\"\n\nexport class SemanticEvent<TType extends string = string, TPayload = unknown> {\n\treadonly type: TType\n\treadonly producerId: string\n\treadonly occurredAt: Date\n\treadonly payload: TPayload\n\n\tconstructor(type: TType, producerId: string, occurredAt: Date, payload: TPayload) {\n\t\tthis.type = type\n\t\tthis.producerId = producerId\n\t\tthis.occurredAt = occurredAt\n\t\tthis.payload = payload\n\t}\n\n\tstatic create<TType extends string = string, TPayload = unknown>(\n\t\ttype: TType,\n\t\tproducerId: string,\n\t\tpayload: TPayload,\n\t): SemanticEvent<TType, TPayload> {\n\t\tconst occurredAt = new Date()\n\t\treturn new SemanticEvent(type, producerId, occurredAt, payload)\n\t}\n}\n\nexport class ParticipantJoinedEvent extends SemanticEvent<\"participant.joined\", ParticipantManifest> {\n\tstatic init(manifest: ParticipantManifest): ParticipantJoinedEvent {\n\t\treturn SemanticEvent.create(\"participant.joined\", manifest.id, manifest)\n\t}\n}\n\nexport class ParticipantLeftEvent extends SemanticEvent<\"participant.left\", ParticipantManifest> {\n\tstatic init(manifest: ParticipantManifest): ParticipantLeftEvent {\n\t\treturn SemanticEvent.create(\"participant.left\", manifest.id, manifest)\n\t}\n}\n\nexport class MessageSentEvent extends SemanticEvent<\"message.sent\", { message: string }> {\n\tstatic init(producerId: string, message: string): MessageSentEvent {\n\t\treturn SemanticEvent.create(\"message.sent\", producerId, { message })\n\t}\n}\n\nexport class ModelAnswerEvent extends SemanticEvent<\"model.answer\", { answer: string }> {\n\tstatic init(producerId: string, answer: string): ModelAnswerEvent {\n\t\treturn ModelAnswerEvent.create(\"model.answer\", producerId, { answer })\n\t}\n}\n","import { LoopState, LoopStateExecution } from \"@domain/agentic-environment/loop/loop-state\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\n\nimport type { Tool } from \"@domain/generative-model/tool\"\nimport type { ModelContext } from \"@domain/model-context/model-context\"\nimport type { StructuredOutputFormat } from \"@domain/generative-model/request-validation/structured-output\"\nimport { LoopVisitor } from \"@domain/agentic-environment/loop/loop-visitor\"\nimport { SemanticEvent } from \"@domain/agentic-environment/semantic-event/event\"\n\nexport type InferenceInput = {\n\tmodel: string\n\tmaxOutputTokens?: number\n\treasoningEffort?: string\n\ttools?: Tool[]\n\tstreaming?: boolean\n\tstructuredOutput?: StructuredOutputFormat\n\tcontext: ModelContext\n}\n\nexport type InferenceItem = FunctionCallItem | ReasoningItem | ModelMessageItem\n\nexport type InferenceOutput = {\n\titems: InferenceItem[]\n\trowResponse: any\n}\n\nexport interface InferenceRunner {\n\trun(request: InferenceInput): Promise<InferenceOutput>\n\tstream(request: InferenceInput): AsyncGenerator<SemanticEvent>\n}\n\nexport class InferenceState implements LoopState<InferenceInput, LoopStateExecution<\"inference\">> {\n\treadonly id = \"inference\"\n\n\tconstructor(private readonly inferenceRunner: InferenceRunner) {}\n\n\tasync run(input: InferenceInput, loopVisitor: LoopVisitor): Promise<LoopStateExecution<\"inference\">> {\n\t\tloopVisitor.visitInferenceStarted(input)\n\n\t\tconst output = await this.inferenceRunner.run(input)\n\n\t\tloopVisitor.visitInferenceCompleted(output)\n\t\treturn {\n\t\t\tstateId: this.id,\n\t\t\tinput,\n\t\t\toutput,\n\t\t}\n\t}\n}\n","import { SituationHandler } from \"../situation/situation-handler\"\n\nexport type ParticipantRole = \"agent\" | \"human\"\n\nexport type ParticipantManifest = {\n\treadonly id: string\n\treadonly name: string\n\treadonly role: ParticipantRole\n\treadonly capabilities?: readonly string[]\n}\n\nexport abstract class Participant {\n\tprivate readonly manifest: ParticipantManifest\n\tprivate handlers: SituationHandler[]\n\n\tprotected constructor(manifest: ParticipantManifest, handlers: SituationHandler[]) {\n\t\tthis.manifest = manifest\n\t\tthis.handlers = handlers\n\t}\n\n\tgetManifest(): ParticipantManifest {\n\t\treturn this.manifest\n\t}\n\n\tgetId(): string {\n\t\treturn this.manifest.id\n\t}\n\n\tgetHandlers(): SituationHandler[] {\n\t\treturn this.handlers\n\t}\n\n\tsetHandlers(handlers: SituationHandler[]): void {\n\t\tthis.handlers = handlers\n\t}\n}\n","import { ModelContext } from \"@domain/model-context/model-context\"\n\nexport class Memory {\n\tprivate readonly context: ModelContext\n\tprivate constructor(context: ModelContext) {\n\t\tthis.context = context\n\t}\n\n\tgetContext(): ModelContext {\n\t\treturn this.context\n\t}\n\n\tstatic create(): Memory {\n\t\tconst context = ModelContext.create()\n\t\treturn new Memory(context)\n\t}\n}\n","import { Memory } from \"./memory\"\nimport { Participant, ParticipantManifest } from \"./participant\"\nimport { Tool } from \"@domain/generative-model/tool\"\nimport { SituationHandler } from \"../situation/situation-handler\"\nimport { DeveloperMessageItem } from \"@domain/model-context/context-item/client-item/developer-message\"\n\nexport class Agent extends Participant {\n\tprivate memory: Memory\n\tprivate developerMessage: string\n\tprivate tools: Tool[]\n\n\tconstructor(\n\t\tmanifest: ParticipantManifest,\n\t\tdeveloperMessage: string,\n\t\ttools: Tool[],\n\t\tmemory: Memory,\n\t\thandlers: SituationHandler[],\n\t) {\n\t\tsuper(manifest, handlers)\n\t\tthis.memory = memory\n\t\tthis.developerMessage = developerMessage\n\t\tthis.tools = tools\n\t}\n\n\tstatic create({\n\t\tname,\n\t\tinstruction,\n\t\ttools,\n\t\tcapabilities,\n\t\thandlers,\n\t}: {\n\t\tinstruction: string\n\t\ttools: Tool[]\n\t\tname: string\n\t\tcapabilities: readonly string[]\n\t\thandlers: SituationHandler[]\n\t}): Agent {\n\t\tconst id = crypto.randomUUID()\n\t\tconst memory = Memory.create()\n\t\tconst manifest: ParticipantManifest = { id, name, capabilities, role: \"agent\" }\n\n\t\tconst developerMessage = DeveloperMessageItem.create(instruction)\n\t\tmemory.getContext().addItem(developerMessage)\n\t\treturn new Agent(manifest, instruction, tools, memory, handlers)\n\t}\n\n\tgetTools(): Tool[] {\n\t\treturn this.tools\n\t}\n\n\tgetDeveloperMessage(): string {\n\t\treturn this.developerMessage\n\t}\n\n\tgetMemory(): Memory {\n\t\treturn this.memory\n\t}\n}\n","import { Agent } from \"@domain/agentic-environment/participant/agent\"\nimport { Tool } from \"@domain/generative-model/tool\"\nimport { SituationHandler } from \"@domain/agentic-environment/situation/situation-handler\"\n\nexport function createAgent({\n\tname,\n\tcapabilities,\n\tinstruction,\n\ttools,\n\thandlers,\n}: {\n\tname: string\n\tcapabilities: readonly string[]\n\tinstruction: string\n\ttools: Tool[]\n\thandlers: SituationHandler[]\n}): Agent {\n\treturn Agent.create({ name, instruction, capabilities, tools, handlers })\n}\n","import { Participant, ParticipantManifest } from \"./participant\"\nimport { SituationHandler } from \"../situation/situation-handler\"\n\nexport class Human extends Participant {\n\tconstructor(manifest: ParticipantManifest, handlers: SituationHandler[]) {\n\t\tsuper(manifest, handlers)\n\t}\n\n\tstatic create({\n\t\tname,\n\t\tcapabilities,\n\t\thandlers,\n\t}: {\n\t\tname: string\n\t\tcapabilities: readonly string[]\n\t\thandlers: SituationHandler[]\n\t}): Human {\n\t\tconst id = crypto.randomUUID()\n\t\tconst manifest: ParticipantManifest = { id, name, capabilities, role: \"human\" }\n\t\treturn new Human(manifest, handlers)\n\t}\n}\n","import { Human } from \"@domain/agentic-environment/participant/human\"\nimport { SituationHandler } from \"@domain/agentic-environment/situation/situation-handler\"\n\nexport function createHuman({\n\tname,\n\tcapabilities,\n\thandlers,\n}: {\n\tname: string\n\tcapabilities: readonly string[]\n\thandlers: SituationHandler[]\n}): Human {\n\treturn Human.create({ name, capabilities, handlers })\n}\n","import { Participant } from \"./participant/participant\"\n\nexport abstract class RuntimeState {\n\tparticipants: Map<string, Participant> = new Map()\n\n\taddParticipant(participant: Participant): void {\n\t\tconst isExists = this.participants.get(participant.getId())\n\n\t\tif (isExists) return\n\n\t\tthis.participants.set(participant.getId(), participant)\n\t}\n\n\tremoveParticipant(participant: Participant): void {\n\t\tthis.participants.delete(participant.getId())\n\t}\n\n\tgetParticipant(id: string): Participant | undefined {\n\t\treturn this.participants.get(id)\n\t}\n\n\tgetParticipants(): readonly Participant[] {\n\t\treturn [...this.participants.values()]\n\t}\n}\n","import { Participant } from \"@domain/agentic-environment/participant/participant\"\nimport { RuntimeState } from \"@domain/agentic-environment/runtime-state\"\nimport { EventProcessor } from \"@domain/agentic-environment/semantic-event/event-processor\"\nimport {\n\tParticipantJoinedEvent,\n\tParticipantLeftEvent,\n\tSemanticEvent,\n} from \"@domain/agentic-environment/semantic-event/event\"\nimport { InferenceRunner } from \"@app/states/inference\"\nimport { FunctionCallRunner } from \"@app/states/function-call\"\n\nexport class RuntimeService<TRuntimeState extends RuntimeState> {\n\tconstructor(\n\t\tpublic readonly state: TRuntimeState,\n\t\tprivate readonly processor: EventProcessor,\n\t\tprivate readonly inferenceRunner: InferenceRunner,\n\t\tprivate readonly functionCallRunner: FunctionCallRunner,\n\t) {}\n\n\tjoin(participant: Participant): void {\n\t\tthis.state.addParticipant(participant)\n\t\tthis.publish(ParticipantJoinedEvent.init(participant.getManifest()))\n\t}\n\n\tleave(participant: Participant): void {\n\t\tthis.state.removeParticipant(participant)\n\t\tthis.publish(ParticipantLeftEvent.init(participant.getManifest()))\n\t}\n\n\tpublish(event: SemanticEvent): void {\n\t\tfor (const participant of this.state.getParticipants()) {\n\t\t\tthis.processor.process(event, participant)\n\t\t}\n\t}\n\n\tgetParticipant(id: string): Participant | undefined {\n\t\tif (!this.state.getParticipant(id)) {\n\t\t\tthrow new Error(`Participant ${id} not found`)\n\t\t}\n\n\t\treturn this.state.getParticipant(id)\n\t}\n\n\tgetInferenceRunner(): InferenceRunner {\n\t\treturn this.inferenceRunner\n\t}\n\n\tgetFunctionCallRunner(): FunctionCallRunner {\n\t\treturn this.functionCallRunner\n\t}\n}\n","import { SemanticEvent } from \"@domain/agentic-environment/semantic-event/event\"\nimport { Participant } from \"../participant/participant\"\n\nexport class EventProcessor {\n\tprocess(event: SemanticEvent, consumer: Participant): void {\n\t\tfor (const handler of consumer.getHandlers()) {\n\t\t\tconst isSatisfied = handler.specification.isSatisfiedBy({\n\t\t\t\tevent,\n\t\t\t\tparticipant: consumer,\n\t\t\t})\n\t\t\tif (isSatisfied) {\n\t\t\t\thandler.processor.apply({ event, participant: consumer })\n\t\t\t}\n\t\t}\n\t}\n}\n","import { RuntimeService } from \"@app/services/runtime\"\nimport { Participant } from \"@domain/agentic-environment/participant/participant\"\nimport { RuntimeState } from \"@domain/agentic-environment/runtime-state\"\n\nexport function createJoin<TRuntimeState extends RuntimeState>(resolveRuntime: () => RuntimeService<TRuntimeState>) {\n\treturn function join(participant: Participant): void {\n\t\tresolveRuntime().join(participant)\n\t}\n}\n","import { RuntimeService } from \"@app/services/runtime\"\nimport { Participant } from \"@domain/agentic-environment/participant/participant\"\nimport { RuntimeState } from \"@domain/agentic-environment/runtime-state\"\n\nexport function createLeave<TRuntimeState extends RuntimeState>(resolveRuntime: () => RuntimeService<TRuntimeState>) {\n\treturn function leave(participant: Participant): void {\n\t\tresolveRuntime().leave(participant)\n\t}\n}\n","import { RuntimeService } from \"@app/services/runtime\"\nimport { RuntimeState } from \"@domain/agentic-environment/runtime-state\"\nimport { MessageSentEvent } from \"@domain/agentic-environment/semantic-event/event\"\n\nexport function createSendMessage<TRuntimeState extends RuntimeState>(\n\tresolveRuntime: () => RuntimeService<TRuntimeState>,\n) {\n\treturn function sendMessage(message: string, senderId: string): void {\n\t\tconst runtime = resolveRuntime()\n\t\tconst participant = runtime.getParticipant(senderId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(`Participant ${senderId} not found`)\n\t\t}\n\n\t\tconst userMessage: MessageSentEvent = MessageSentEvent.init(senderId, message)\n\t\truntime.publish(userMessage)\n\t}\n}\n","import { LoopTransition, ReceivedMessage } from \"./loop-state\"\nimport { LoopVisitor } from \"./loop-visitor\"\nimport { LoopStateExecutor } from \"./state-executor\"\nimport { TransitionResolver } from \"./transition-resolver\"\n\nexport interface InterceptionHandler {\n\tisSatisfiedBy(transition: LoopTransition): boolean\n\thandle(transition: LoopTransition): Promise<LoopTransition>\n}\n\nexport class AgentLoop {\n\tprivate constructor(\n\t\tprivate readonly loopId: string,\n\t\tprivate readonly stateExecutor: LoopStateExecutor,\n\t\tprivate readonly transitionResolver: TransitionResolver,\n\t\tprivate readonly interceptionHandler?: InterceptionHandler,\n\t) {}\n\n\tasync run(message: ReceivedMessage, loopVisitor: LoopVisitor): Promise<void> {\n\t\tlet transition: LoopTransition = {\n\t\t\tnextStateId: \"context_update\",\n\t\t\tinput: message,\n\t\t}\n\n\t\twhile (transition.nextStateId !== \"idle\") {\n\t\t\tconst isInterceptionSatisfied = this.interceptionHandler?.isSatisfiedBy(transition)\n\n\t\t\tif (isInterceptionSatisfied && this.interceptionHandler) {\n\t\t\t\tloopVisitor.visitInterceptionStarted(transition)\n\t\t\t\ttransition = await this.interceptionHandler.handle(transition)\n\t\t\t\tloopVisitor.visitInterceptionFinished(transition)\n\t\t\t} else {\n\t\t\t\tconst execution = await this.stateExecutor.execute(transition, loopVisitor)\n\t\t\t\ttransition = this.transitionResolver.resolve(execution)\n\t\t\t}\n\t\t}\n\t}\n\n\tgetLoopId(): string {\n\t\treturn this.loopId\n\t}\n\n\tstatic create(\n\t\tstateExecutor: LoopStateExecutor,\n\t\ttransitionResolver: TransitionResolver,\n\t\tinterceptionHandler?: InterceptionHandler,\n\t): AgentLoop {\n\t\tconst loopId = crypto.randomUUID()\n\t\treturn new AgentLoop(loopId, stateExecutor, transitionResolver, interceptionHandler)\n\t}\n}\n","import { ExecutableLoopStateId, LoopStateExecution, LoopTransition } from \"./loop-state\"\nimport { LoopVisitor } from \"./loop-visitor\"\nimport { FunctionCallState } from \"@app/states/function-call\"\nimport { InferenceState } from \"@app/states/inference\"\nimport { ContextUpdateState } from \"@app/states/context-update\"\nimport { ModelMessageState } from \"@app/states/model-message\"\nimport { InferenceStreamingState } from \"@app/states/inference-streaming\"\n\nexport class LoopStateExecutor {\n\tconstructor(\n\t\tprivate readonly contextUpdateState: ContextUpdateState,\n\t\tprivate readonly inferenceState: InferenceState,\n\t\tprivate readonly inferenceStreamingState: InferenceStreamingState,\n\t\tprivate readonly functionCallState: FunctionCallState,\n\t\tprivate readonly modelMessageState: ModelMessageState,\n\t) {}\n\n\texecute(\n\t\ttransition: LoopTransition<\"context_update\">,\n\t\tloopVisitor: LoopVisitor,\n\t): Promise<LoopStateExecution<\"context_update\">>\n\n\texecute(transition: LoopTransition<\"inference\">, loopVisitor: LoopVisitor): Promise<LoopStateExecution<\"inference\">>\n\n\texecute(\n\t\ttransition: LoopTransition<\"function_call\">,\n\t\tloopVisitor: LoopVisitor,\n\t): Promise<LoopStateExecution<\"function_call\">>\n\n\texecute(\n\t\ttransition: LoopTransition<\"model_message\">,\n\t\tloopVisitor: LoopVisitor,\n\t): Promise<LoopStateExecution<\"model_message\">>\n\n\texecute(transition: LoopTransition<ExecutableLoopStateId>, loopVisitor: LoopVisitor): Promise<LoopStateExecution>\n\n\tasync execute(\n\t\ttransition: LoopTransition<ExecutableLoopStateId>,\n\t\tloopVisitor: LoopVisitor,\n\t): Promise<LoopStateExecution> {\n\t\tswitch (transition.nextStateId) {\n\t\t\tcase \"context_update\":\n\t\t\t\treturn await this.contextUpdateState.run(transition.input, loopVisitor)\n\n\t\t\tcase \"inference\":\n\t\t\t\treturn await this.inferenceState.run(transition.input, loopVisitor)\n\n\t\t\tcase \"inference_streaming\":\n\t\t\t\treturn await this.inferenceStreamingState.run(transition.input, loopVisitor)\n\n\t\t\tcase \"function_call\":\n\t\t\t\treturn await this.functionCallState.run(transition.input, loopVisitor)\n\n\t\t\tcase \"model_message\":\n\t\t\t\treturn await this.modelMessageState.run(transition.input, loopVisitor)\n\t\t}\n\t}\n}\n","import { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport { LoopState, LoopStateExecution } from \"@domain/agentic-environment/loop/loop-state\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport { InferenceInput } from \"./inference\"\nimport { Tool } from \"@domain/generative-model/tool\"\nimport { LoopVisitor } from \"@domain/agentic-environment/loop/loop-visitor\"\n\nexport interface FunctionCallRunner {\n\trun(call: FunctionCallItem, tool: Tool): Promise<FunctionCallOutputItem>\n}\n\nexport interface FunctionCallParams {\n\tcall: FunctionCallItem\n\tinferenceInput: InferenceInput\n}\n\nexport class FunctionCallState implements LoopState<FunctionCallParams, LoopStateExecution<\"function_call\">> {\n\treadonly id = \"function_call\"\n\n\tconstructor(private readonly functionCallRunner: FunctionCallRunner) {}\n\n\tasync run(input: FunctionCallParams, loopVisitor: LoopVisitor): Promise<LoopStateExecution<\"function_call\">> {\n\t\tloopVisitor.visitFunctionCallStarted(input)\n\n\t\tconst { call, inferenceInput } = input\n\n\t\tlet tool: Tool | undefined = inferenceInput.tools?.find((tool) => tool.name === call.name)\n\n\t\tif (!tool) {\n\t\t\treturn {\n\t\t\t\tstateId: this.id,\n\t\t\t\tinput,\n\t\t\t\toutput: {\n\t\t\t\t\titem: FunctionCallOutputItem.create(call.callId, `Error: unknown tool \"${call.name}\"`),\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\n\t\tconst item = await this.functionCallRunner.run(call, tool)\n\n\t\tloopVisitor.visitFunctionCallCompleted(item)\n\t\treturn {\n\t\t\tstateId: this.id,\n\t\t\tinput,\n\t\t\toutput: {\n\t\t\t\titem,\n\t\t\t},\n\t\t}\n\t}\n}\n","import { InferenceInput } from \"@app/states/inference\"\nimport { UserMessageItem } from \"@domain/model-context/context-item/client-item/user-message\"\nimport { LoopState, LoopStateExecution, ReceivedMessage } from \"@domain/agentic-environment/loop/loop-state\"\nimport { LoopVisitor } from \"@domain/agentic-environment/loop/loop-visitor\"\n\nexport class ContextUpdateState implements LoopState<ReceivedMessage, LoopStateExecution<\"context_update\">> {\n\treadonly id = \"context_update\"\n\n\tasync run(input: ReceivedMessage, loopVisitor: LoopVisitor): Promise<LoopStateExecution<\"context_update\">> {\n\t\tloopVisitor.visitContextUpdateStarted(input)\n\n\t\tconst userMessage = UserMessageItem.create(input.content)\n\n\t\tconst output: InferenceInput = {\n\t\t\t...input.input,\n\t\t\tcontext: input.input.context.addContextItems([userMessage]),\n\t\t}\n\n\t\tloopVisitor.visitContextUpdateCompleted(output)\n\t\treturn {\n\t\t\tstateId: this.id,\n\t\t\tinput,\n\t\t\toutput,\n\t\t}\n\t}\n}\n","import { LoopState, LoopStateExecution, ModelMessageParams } from \"@domain/agentic-environment/loop/loop-state\"\nimport { LoopVisitor } from \"@domain/agentic-environment/loop/loop-visitor\"\n\nexport class ModelMessageState implements LoopState<ModelMessageParams, LoopStateExecution<\"model_message\">> {\n\treadonly id = \"model_message\"\n\n\tasync run(input: ModelMessageParams, loopVisitor: LoopVisitor): Promise<LoopStateExecution<\"model_message\">> {\n\t\tloopVisitor.visitModelAnswer(input)\n\t\treturn {\n\t\t\tstateId: this.id,\n\t\t\tinput,\n\t\t\toutput: undefined,\n\t\t}\n\t}\n}\n","import { LoopTransitionRule } from \"./transition-rule\"\nimport { LoopStateExecution, LoopTransition } from \"./loop-state\"\n\nexport class TransitionResolver {\n\tconstructor(private readonly rules: LoopTransitionRule[]) {}\n\n\tresolve(execution: LoopStateExecution): LoopTransition {\n\t\tconst rule = this.rules.find((rule) => rule.specification.isSatisfiedBy(execution))\n\n\t\tif (!rule) {\n\t\t\tthrow new Error(`No transition rule found after \"${execution.stateId}\"`)\n\t\t}\n\n\t\treturn rule.createTransition(execution)\n\t}\n}\n","import { LoopStateExecution } from \"./loop-state\"\n\nexport interface TransitionSpecification {\n\tisSatisfiedBy(execution: LoopStateExecution): boolean\n}\n\nexport class AndSpecification implements TransitionSpecification {\n\tconstructor(\n\t\tprivate readonly left: TransitionSpecification,\n\t\tprivate readonly right: TransitionSpecification,\n\t) {}\n\n\tisSatisfiedBy(execution: LoopStateExecution): boolean {\n\t\treturn this.left.isSatisfiedBy(execution) && this.right.isSatisfiedBy(execution)\n\t}\n}\n\nexport class OrSpecification implements TransitionSpecification {\n\tconstructor(\n\t\tprivate readonly left: TransitionSpecification,\n\t\tprivate readonly right: TransitionSpecification,\n\t) {}\n\n\tisSatisfiedBy(execution: LoopStateExecution): boolean {\n\t\treturn this.left.isSatisfiedBy(execution) || this.right.isSatisfiedBy(execution)\n\t}\n}\n\nexport class NotSpecification implements TransitionSpecification {\n\tconstructor(private readonly specification: TransitionSpecification) {}\n\n\tisSatisfiedBy(execution: LoopStateExecution): boolean {\n\t\treturn !this.specification.isSatisfiedBy(execution)\n\t}\n}\n\n// ============================================================\n// Concrete transition specifications\n// ============================================================\n\nexport class MessageReceivedSpecification implements TransitionSpecification {\n\tisSatisfiedBy(execution: LoopStateExecution): boolean {\n\t\treturn execution.stateId === \"context_update\"\n\t}\n}\n\ntype InferenceExecution = Extract<LoopStateExecution, { stateId: \"inference\" | \"inference_streaming\" }>\n\n/** Buffered and streaming inference produce the same output, so both satisfy the inference specifications. */\nfunction isInferenceExecution(execution: LoopStateExecution): execution is InferenceExecution {\n\treturn execution.stateId === \"inference\" || execution.stateId === \"inference_streaming\"\n}\n\nexport class InferenceProducedFunctionCallSpecification implements TransitionSpecification {\n\tisSatisfiedBy(execution: LoopStateExecution): boolean {\n\t\treturn isInferenceExecution(execution) && execution.output.items.some((item) => item.type === \"function_call\")\n\t}\n}\n\nexport class InferenceProducedModelMessageSpecification implements TransitionSpecification {\n\tisSatisfiedBy(execution: LoopStateExecution): boolean {\n\t\treturn (\n\t\t\tisInferenceExecution(execution) &&\n\t\t\texecution.output.items.some((item) => item.type === \"message\" && item.role === \"assistant\")\n\t\t)\n\t}\n}\n\nexport class FunctionCallCompletedSpecification implements TransitionSpecification {\n\tisSatisfiedBy(execution: LoopStateExecution): boolean {\n\t\treturn execution.stateId === \"function_call\"\n\t}\n}\n\nexport class ModelMessageCompletedSpecification implements TransitionSpecification {\n\tisSatisfiedBy(execution: LoopStateExecution): boolean {\n\t\treturn execution.stateId === \"model_message\"\n\t}\n}\n\nexport class StreamingInferenceSpecification implements TransitionSpecification {\n\tisSatisfiedBy(execution: LoopStateExecution): boolean {\n\t\treturn execution.stateId === \"inference\" && execution.input.streaming === true\n\t}\n}\n","import { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport { LoopStateExecution, LoopTransition } from \"./loop-state\"\nimport {\n\tFunctionCallCompletedSpecification,\n\tInferenceProducedFunctionCallSpecification,\n\tInferenceProducedModelMessageSpecification,\n\tMessageReceivedSpecification,\n\tModelMessageCompletedSpecification,\n\tTransitionSpecification,\n} from \"./transition-specification\"\n\nexport interface LoopTransitionRule {\n\treadonly specification: TransitionSpecification\n\n\tcreateTransition(execution: LoopStateExecution): LoopTransition\n}\n\nexport class ContextPreparationToInferenceRule implements LoopTransitionRule {\n\treadonly specification = new MessageReceivedSpecification()\n\n\tcreateTransition(execution: LoopStateExecution): LoopTransition<\"inference\" | \"inference_streaming\"> {\n\t\tif (execution.stateId !== \"context_update\") {\n\t\t\tthrow new Error(\"Expected context_preparation execution\")\n\t\t}\n\n\t\tconst nextStateId = execution.output.streaming ? \"inference_streaming\" : \"inference\"\n\n\t\treturn {\n\t\t\tnextStateId,\n\t\t\tinput: execution.output,\n\t\t}\n\t}\n}\n\nexport class InferenceToFunctionCallRule implements LoopTransitionRule {\n\treadonly specification = new InferenceProducedFunctionCallSpecification()\n\n\tcreateTransition(execution: LoopStateExecution): LoopTransition<\"function_call\"> {\n\t\tif (\n\t\t\t(execution.stateId !== \"inference\" && execution.stateId !== \"inference_streaming\") ||\n\t\t\t!execution.output.items.some((item) => item.type === \"function_call\")\n\t\t) {\n\t\t\tthrow new Error(\"Expected inference function-call output\")\n\t\t}\n\n\t\tconst functionCallItem = execution.output.items.find((item) => item.type === \"function_call\")\n\n\t\tif (!functionCallItem) {\n\t\t\tthrow new Error(\"Expected inference function-call output\")\n\t\t}\n\n\t\treturn {\n\t\t\tnextStateId: \"function_call\",\n\t\t\tinput: {\n\t\t\t\tcall: functionCallItem,\n\t\t\t\tinferenceInput: execution.input,\n\t\t\t},\n\t\t}\n\t}\n}\n\nexport class InferenceToModelMessageRule implements LoopTransitionRule {\n\treadonly specification = new InferenceProducedModelMessageSpecification()\n\n\tcreateTransition(execution: LoopStateExecution): LoopTransition<\"model_message\"> {\n\t\tif (\n\t\t\t(execution.stateId !== \"inference\" && execution.stateId !== \"inference_streaming\") ||\n\t\t\t!execution.output.items.some((item) => item.type === \"message\" && item.role === \"assistant\")\n\t\t) {\n\t\t\tthrow new Error(\"Expected inference model-message output\")\n\t\t}\n\t\tconst modelMessageItem = execution.output.items.find(\n\t\t\t(item) => item.type === \"message\" && item.role === \"assistant\",\n\t\t) as ModelMessageItem\n\n\t\tif (!modelMessageItem) {\n\t\t\tthrow new Error(\"Expected inference model-message output\")\n\t\t}\n\n\t\treturn {\n\t\t\tnextStateId: \"model_message\",\n\t\t\tinput: {\n\t\t\t\tanswer: modelMessageItem,\n\t\t\t},\n\t\t}\n\t}\n}\n\nexport class FunctionCallToInferenceRule implements LoopTransitionRule {\n\treadonly specification = new FunctionCallCompletedSpecification()\n\n\tcreateTransition(execution: LoopStateExecution): LoopTransition<\"inference\" | \"inference_streaming\"> {\n\t\tif (execution.stateId !== \"function_call\") {\n\t\t\tthrow new Error(\"Expected function_call execution\")\n\t\t}\n\n\t\tconst previousRequest = execution.input.inferenceInput\n\n\t\tpreviousRequest.context.addContextItems([execution.input.call, execution.output.item])\n\n\t\treturn {\n\t\t\tnextStateId: previousRequest.streaming ? \"inference_streaming\" : \"inference\",\n\t\t\tinput: {\n\t\t\t\t...previousRequest,\n\t\t\t},\n\t\t}\n\t}\n}\n\nexport class ModelMessageToIdleRule implements LoopTransitionRule {\n\treadonly specification = new ModelMessageCompletedSpecification()\n\n\tcreateTransition(execution: LoopStateExecution): LoopTransition<\"idle\"> {\n\t\tif (execution.stateId !== \"model_message\") {\n\t\t\tthrow new Error(\"Expected model_message execution\")\n\t\t}\n\n\t\treturn {\n\t\t\tnextStateId: \"idle\",\n\t\t\tinput: undefined,\n\t\t}\n\t}\n}\n","import { InferenceInput, InferenceOutput } from \"@app/states/inference\"\nimport { LoopTransition, ModelMessageParams, ReceivedMessage } from \"./loop-state\"\nimport { LoopVisitor } from \"./loop-visitor\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport { FunctionCallParams } from \"@app/states/function-call\"\nimport { RuntimeService } from \"@app/services/runtime\"\nimport { RuntimeState } from \"../runtime-state\"\nimport { SemanticEvent } from \"@domain/agentic-environment/semantic-event/event\"\nimport { CloudClient, createCloudClient } from \"@mozaik-ai/cloud-sdk\"\n\nexport class EventPublisherLoopVisitor implements LoopVisitor {\n\tprivate readonly cloud: CloudClient\n\tconstructor(\n\t\tprivate readonly agentId: string,\n\t\tprivate readonly loopId: string,\n\t\tprivate readonly runtime: RuntimeService<RuntimeState>,\n\t) {\n\t\tthis.cloud = createCloudClient()\n\t}\n\n\tvisitContextUpdateStarted(input: ReceivedMessage): void {\n\t\tthis.publish(\"context_update.started\", { ...input, loopId: this.loopId })\n\t}\n\n\tvisitContextUpdateCompleted(output: InferenceInput): void {\n\t\tthis.publish(\"context_update.completed\", { ...output, loopId: this.loopId })\n\t}\n\n\tvisitInferenceStarted(input: InferenceInput): void {\n\t\tthis.publish(\"inference.started\", input)\n\t}\n\n\tvisitInferenceEvent(event: SemanticEvent): void {\n\t\tthis.publish(\"inference.stream\", event)\n\t}\n\n\tvisitInferenceCompleted(output: InferenceOutput): void {\n\t\tthis.publish(\"inference.completed\", output)\n\t}\n\n\tvisitFunctionCallStarted(input: FunctionCallParams): void {\n\t\tthis.publish(\"function_call.started\", input)\n\t}\n\n\tvisitFunctionCallCompleted(output: FunctionCallOutputItem): void {\n\t\tthis.publish(\"function_call.completed\", output)\n\t}\n\n\tvisitModelAnswer(input: ModelMessageParams): void {\n\t\tthis.publish(\"model.answer\", input)\n\t}\n\n\tvisitInterceptionStarted(transition: LoopTransition): void {\n\t\tthis.publish(\"interception.started\", transition)\n\t}\n\n\tvisitInterceptionFinished(transition: LoopTransition): void {\n\t\tthis.publish(\"interception.finished\", transition)\n\t}\n\n\tprivate publish<TPayload>(type: string, payload: TPayload): void {\n\t\tconst event = new SemanticEvent(type, this.agentId, new Date(), payload)\n\t\tthis.runtime.publish(event)\n\n\t\tif (this.cloud.enabled) {\n\t\t\tthis.cloud.send(event)\n\t\t}\n\t}\n}\n","import { LoopVisitor } from \"@domain/agentic-environment/loop/loop-visitor\"\nimport { LoopState } from \"@domain/agentic-environment/loop/loop-state\"\nimport { InferenceInput, InferenceOutput } from \"./inference\"\nimport { LoopStateExecution } from \"@domain/agentic-environment/loop/loop-state\"\nimport { InferenceRunner } from \"./inference\"\n\nexport class InferenceStreamingState implements LoopState<InferenceInput, LoopStateExecution<\"inference_streaming\">> {\n\treadonly id = \"inference_streaming\"\n\n\tconstructor(private readonly inferenceRunner: InferenceRunner) {}\n\n\tasync run(input: InferenceInput, loopVisitor: LoopVisitor): Promise<LoopStateExecution<\"inference_streaming\">> {\n\t\tloopVisitor.visitInferenceStarted(input)\n\n\t\tlet output: InferenceOutput | undefined = undefined\n\n\t\tfor await (const event of this.inferenceRunner.stream(input)) {\n\t\t\tloopVisitor.visitInferenceEvent(event)\n\n\t\t\tif (event.type === \"inference.output\") {\n\t\t\t\toutput = event.payload as InferenceOutput\n\t\t\t}\n\t\t}\n\n\t\tif (!output) {\n\t\t\tthrow new Error(\"Inference output not found\")\n\t\t}\n\n\t\tloopVisitor.visitInferenceCompleted(output)\n\n\t\treturn {\n\t\t\tstateId: \"inference_streaming\",\n\t\t\tinput,\n\t\t\toutput,\n\t\t}\n\t}\n}\n","import { RuntimeService } from \"@app/services/runtime\"\nimport { AgentLoop } from \"@domain/agentic-environment/loop/agent-loop\"\nimport { LoopStateExecutor } from \"@domain/agentic-environment/loop/state-executor\"\nimport { FunctionCallState } from \"@app/states/function-call\"\nimport { InferenceInput, InferenceState } from \"@app/states/inference\"\nimport { ContextUpdateState } from \"@app/states/context-update\"\nimport { ModelMessageState } from \"@app/states/model-message\"\nimport { TransitionResolver } from \"@domain/agentic-environment/loop/transition-resolver\"\nimport {\n\tFunctionCallToInferenceRule,\n\tInferenceToFunctionCallRule,\n\tInferenceToModelMessageRule,\n\tContextPreparationToInferenceRule,\n\tModelMessageToIdleRule,\n} from \"@domain/agentic-environment/loop/transition-rule\"\nimport { RuntimeState } from \"@domain/agentic-environment/runtime-state\"\nimport { EventPublisherLoopVisitor } from \"@domain/agentic-environment/loop/event-publisher-visitor\"\nimport { InferenceStreamingState } from \"@app/states/inference-streaming\"\nimport { InterceptionHandler } from \"@domain/agentic-environment/loop/agent-loop\"\n\nexport function createRunLoop<TRuntimeState extends RuntimeState>(resolveRuntime: () => RuntimeService<TRuntimeState>) {\n\treturn function runLoop(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\tinferenceInput: InferenceInput,\n\t\tinterceptionHandler?: InterceptionHandler,\n\t) {\n\t\tconst runtime = resolveRuntime()\n\t\tconst inferenceRunner = runtime.getInferenceRunner()\n\t\tconst functionCallRunner = runtime.getFunctionCallRunner()\n\n\t\tconst transitionResolver = new TransitionResolver([\n\t\t\t// High-priority interception rules would go first.\n\t\t\tnew ContextPreparationToInferenceRule(),\n\t\t\tnew InferenceToFunctionCallRule(),\n\t\t\tnew InferenceToModelMessageRule(),\n\t\t\tnew FunctionCallToInferenceRule(),\n\t\t\tnew ModelMessageToIdleRule(),\n\t\t])\n\n\t\tconst stateExecutor = new LoopStateExecutor(\n\t\t\tnew ContextUpdateState(),\n\t\t\tnew InferenceState(inferenceRunner),\n\t\t\tnew InferenceStreamingState(inferenceRunner),\n\t\t\tnew FunctionCallState(functionCallRunner),\n\t\t\tnew ModelMessageState(),\n\t\t)\n\n\t\tconst agentLoop = AgentLoop.create(stateExecutor, transitionResolver, interceptionHandler)\n\n\t\tconst loopVisitor = new EventPublisherLoopVisitor(agentId, agentLoop.getLoopId(), runtime)\n\n\t\tagentLoop.run(\n\t\t\t{\n\t\t\t\tcontent: message,\n\t\t\t\tinput: inferenceInput,\n\t\t\t},\n\t\t\tloopVisitor,\n\t\t)\n\t}\n}\n","import type { InferenceInput, InferenceItem, InferenceOutput } from \"@app/states/inference\"\nimport { DeveloperMessageItem } from \"@domain/model-context/context-item/client-item/developer-message\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport { SystemMessageItem } from \"@domain/model-context/context-item/client-item/system-message\"\nimport { UserMessageItem } from \"@domain/model-context/context-item/client-item/user-message\"\nimport { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\nimport { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\nimport type { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { InputTokenDetails, OutputTokenDetails, TokenUsage } from \"@domain/generative-model/token-usage\"\nimport type Anthropic from \"@anthropic-ai/sdk\"\n\nexport class AnthropicMessagesMapper implements InferenceEndpointMapper {\n\ttoRequest(inferenceInput: InferenceInput) {\n\t\tconst { messages, system } = this.mapContextItems(inferenceInput)\n\t\tconst outputConfig: any = {}\n\n\t\tconst request: any = {\n\t\t\tmodel: inferenceInput.model,\n\t\t\tmessages,\n\t\t}\n\n\t\trequest.max_tokens = inferenceInput.maxOutputTokens!\n\n\t\tif (system) {\n\t\t\trequest.system = system\n\t\t}\n\n\t\tif (inferenceInput.tools && inferenceInput.tools.length > 0) {\n\t\t\trequest.tools = inferenceInput.tools.map((tool) => ({\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tinput_schema: tool.parameters,\n\t\t\t}))\n\t\t}\n\n\t\tif (inferenceInput.structuredOutput) {\n\t\t\toutputConfig.format = {\n\t\t\t\ttype: \"json_schema\",\n\t\t\t\tjson_schema: inferenceInput.structuredOutput.schema,\n\t\t\t}\n\t\t}\n\n\t\tif (inferenceInput.reasoningEffort) {\n\t\t\trequest.thinking = { type: \"adaptive\" }\n\t\t\toutputConfig.effort = inferenceInput.reasoningEffort\n\t\t}\n\n\t\tif (Object.keys(outputConfig).length > 0) {\n\t\t\trequest.output_config = outputConfig\n\t\t}\n\n\t\tif (inferenceInput.streaming) {\n\t\t\trequest.stream = inferenceInput.streaming\n\t\t}\n\n\t\treturn request\n\t}\n\n\tprivate addContentBlock(messages: any[], role: \"user\" | \"assistant\", block: any): void {\n\t\tconst lastMessage = messages[messages.length - 1]\n\t\tif (lastMessage?.role === role) {\n\t\t\tlastMessage.content.push(block)\n\t\t\treturn\n\t\t}\n\n\t\tmessages.push({\n\t\t\trole: role,\n\t\t\tcontent: [block],\n\t\t})\n\t}\n\n\tmapContextItems(inferenceInput: InferenceInput): { messages: any[]; system?: string } {\n\t\tconst context = inferenceInput.context\n\t\tconst messages: any[] = []\n\t\tconst system: string[] = []\n\n\t\tfor (const item of context.getItems()) {\n\t\t\tif (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {\n\t\t\t\tsystem.push(item.content.text)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof UserMessageItem) {\n\t\t\t\tthis.addContentBlock(messages, \"user\", { type: \"text\", text: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof ModelMessageItem) {\n\t\t\t\tthis.addContentBlock(messages, \"assistant\", { type: \"text\", text: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof ReasoningItem) {\n\t\t\t\tthis.addContentBlock(messages, \"assistant\", {\n\t\t\t\t\ttype: \"thinking\",\n\t\t\t\t\tthinking: item.content?.text ?? \"\",\n\t\t\t\t\tsignature: item.encryptedContent ?? \"\",\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallItem) {\n\t\t\t\tlet input: any\n\t\t\t\ttry {\n\t\t\t\t\tinput = JSON.parse(item.args)\n\t\t\t\t} catch {\n\t\t\t\t\tinput = item.args\n\t\t\t\t}\n\t\t\t\tthis.addContentBlock(messages, \"assistant\", {\n\t\t\t\t\ttype: \"tool_use\",\n\t\t\t\t\tid: item.callId,\n\t\t\t\t\tname: item.name,\n\t\t\t\t\tinput: input,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallOutputItem) {\n\t\t\t\tthis.addContentBlock(messages, \"user\", {\n\t\t\t\t\ttype: \"tool_result\",\n\t\t\t\t\ttool_use_id: item.callId,\n\t\t\t\t\tcontent: item.output.text,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tmessages: messages,\n\t\t\tsystem: system.length > 0 ? system.join(\"\\n\\n\") : undefined,\n\t\t}\n\t}\n\n\textractTokenUsage(response: Anthropic.Messages.Message): TokenUsage | undefined {\n\t\tif (!response.usage) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn new TokenUsage(\n\t\t\tresponse.usage.input_tokens,\n\t\t\tresponse.usage.output_tokens,\n\t\t\tresponse.usage.input_tokens + response.usage.output_tokens,\n\t\t\tnew InputTokenDetails(\n\t\t\t\t(response.usage.cache_creation_input_tokens ?? 0) + (response.usage.cache_read_input_tokens ?? 0),\n\t\t\t),\n\t\t\tnew OutputTokenDetails(0),\n\t\t)\n\t}\n\n\ttoResponse(response: Anthropic.Messages.Message): InferenceOutput {\n\t\tconst items: InferenceItem[] = []\n\n\t\tfor (const block of response.content as any[]) {\n\t\t\tif (block.type === \"text\") {\n\t\t\t\titems.push(ModelMessageItem.rehydrate({ text: block.text }))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (block.type === \"tool_use\") {\n\t\t\t\titems.push(\n\t\t\t\t\tFunctionCallItem.rehydrate({\n\t\t\t\t\t\tcallId: block.id,\n\t\t\t\t\t\tname: block.name,\n\t\t\t\t\t\targs: JSON.stringify(block.input ?? {}),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (block.type === \"thinking\") {\n\t\t\t\titems.push(\n\t\t\t\t\tReasoningItem.rehydrate({\n\t\t\t\t\t\tcontent: block.thinking ? InputText.rehydrate({ text: block.thinking }) : undefined,\n\t\t\t\t\t\tencryptedContent: block.signature,\n\t\t\t\t\t\tsummary: [],\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\treturn { items, rowResponse: response }\n\t}\n}\n","import { SemanticEvent } from \"@domain/agentic-environment/semantic-event/event\"\nimport type { Endpoint } from \"@domain/generative-model/endpoint\"\nimport type { InferenceInput, InferenceOutput } from \"@app/states/inference\"\nimport { AnthropicMessagesMapper } from \"./anthropic-messages-mapper\"\nimport Anthropic from \"@anthropic-ai/sdk\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\n\nexport interface AnthropicConnectionConfig {\n\tbaseURL?: string\n\tapiKey?: string\n}\n\n/**\n * Native Anthropic adapter on the `@anthropic-ai/sdk` (`messages.create`).\n * Maps domain context to Anthropic's `messages`/`content` blocks shape,\n * system prompt, tools, adaptive thinking, and structured output config.\n */\nexport class AnthropicMessages implements Endpoint {\n\tendpointMapper: InferenceEndpointMapper\n\tprivate _client?: Anthropic\n\tprivate readonly clientConfig: AnthropicConnectionConfig\n\n\tconstructor(\n\t\tendpointMapper: InferenceEndpointMapper = new AnthropicMessagesMapper(),\n\t\tconfig: AnthropicConnectionConfig = {},\n\t) {\n\t\tthis.endpointMapper = endpointMapper\n\t\tthis.clientConfig = config\n\t}\n\n\tprivate get client(): Anthropic {\n\t\treturn (this._client ??= new Anthropic({\n\t\t\tbaseURL: this.clientConfig.baseURL,\n\t\t\tapiKey: this.clientConfig.apiKey,\n\t\t}))\n\t}\n\n\tasync infer(inferenceInput: InferenceInput): Promise<InferenceOutput> {\n\t\tconst request = this.endpointMapper.toRequest(inferenceInput)\n\t\tconst response = await this.client.messages.create(request)\n\n\t\treturn this.endpointMapper.toResponse(response)\n\t}\n\n\tasync *stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent> {\n\t\tconst request = this.endpointMapper.toRequest(inferenceInput)\n\t\tconst stream = this.client.messages.stream(request)\n\n\t\tfor await (const event of stream) {\n\t\t\tyield event as unknown as SemanticEvent\n\t\t}\n\n\t\tconst output = this.endpointMapper.toResponse(await stream.finalMessage())\n\n\t\tyield {\n\t\t\ttype: \"inference.output\",\n\t\t\tproducerId: request.model,\n\t\t\toccurredAt: new Date(),\n\t\t\tpayload: output,\n\t\t}\n\t}\n}\n","import { SemanticEvent } from \"@domain/agentic-environment/semantic-event/event\"\nimport type { InferenceOutput } from \"@app/states/inference\"\nimport type { Endpoint } from \"@domain/generative-model/endpoint\"\nimport OpenAI from \"openai\"\nimport type { InferenceInput } from \"@app/states/inference\"\nimport { OpenAIResponsesMapper } from \"./openai-responses-mapper\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\n\nexport class OpenAIResponses implements Endpoint {\n\tendpointMapper: InferenceEndpointMapper\n\tprivate _client?: OpenAI\n\n\tconstructor(endpointMapper: InferenceEndpointMapper = new OpenAIResponsesMapper()) {\n\t\tthis.endpointMapper = endpointMapper\n\t}\n\n\tprivate get client(): OpenAI {\n\t\treturn (this._client ??= new OpenAI())\n\t}\n\n\tasync infer(inferenceInput: InferenceInput): Promise<InferenceOutput> {\n\t\tconst request = this.endpointMapper.toRequest(inferenceInput)\n\t\tconst response = await this.client.responses.create(request)\n\n\t\treturn this.endpointMapper.toResponse(response)\n\t}\n\n\tasync *stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent> {\n\t\tconst request = this.endpointMapper.toRequest(inferenceInput)\n\t\tconst stream: any = await this.client.responses.create({ ...request, stream: true })\n\n\t\t// Only the terminal `response.completed` event carries the assembled\n\t\t// response; the deltas before it cannot be mapped to an InferenceOutput.\n\t\tlet completedResponse: any = undefined\n\t\tfor await (const event of stream) {\n\t\t\tif (event.type === \"response.completed\") {\n\t\t\t\tcompletedResponse = event.response\n\t\t\t}\n\n\t\t\tyield event\n\t\t}\n\n\t\tif (!completedResponse) {\n\t\t\tthrow new Error(\"Stream ended without a completed response\")\n\t\t}\n\n\t\tconst output = this.endpointMapper.toResponse(completedResponse)\n\n\t\tyield {\n\t\t\ttype: \"inference.output\",\n\t\t\tpayload: output,\n\t\t\toccurredAt: new Date(),\n\t\t\tproducerId: inferenceInput.model,\n\t\t}\n\t}\n}\n","import { ItemContent } from \"@domain/model-context/context-item/item-content/item-content\"\n\nexport class SummaryText extends ItemContent {\n\treadonly type = \"summary_text\"\n\n\tprivate constructor(public readonly text: string) {\n\t\tsuper()\n\t}\n\n\tstatic rehydrate(data: { text: string }): SummaryText {\n\t\treturn new SummaryText(data.text)\n\t}\n}\n","import type { InferenceInput, InferenceItem } from \"@app/states/inference\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\nimport { DeveloperMessageItem } from \"@domain/model-context/context-item/client-item/developer-message\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport { SystemMessageItem } from \"@domain/model-context/context-item/client-item/system-message\"\nimport { UserMessageItem } from \"@domain/model-context/context-item/client-item/user-message\"\nimport { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport { SummaryText } from \"@domain/model-context/context-item/item-content/summary-text\"\nimport { InferenceOutput } from \"@app/states/inference\"\nimport type { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { InputTokenDetails, OutputTokenDetails, TokenUsage } from \"@domain/generative-model/token-usage\"\nimport type OpenAI from \"openai\"\n\nexport class OpenAIResponsesMapper implements InferenceEndpointMapper {\n\ttoRequest(inferenceInput: InferenceInput): any {\n\t\tconst request: any = {\n\t\t\tmodel: inferenceInput.model,\n\t\t\tinput: this.mapContextItems(inferenceInput),\n\t\t}\n\n\t\tif (inferenceInput.tools && inferenceInput.tools.length > 0) {\n\t\t\trequest.tools = inferenceInput.tools.map((tool) => ({\n\t\t\t\ttype: tool.type,\n\t\t\t\tname: tool.name,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tparameters: tool.parameters,\n\t\t\t}))\n\t\t}\n\n\t\tif (inferenceInput.reasoningEffort) {\n\t\t\trequest.reasoning = {\n\t\t\t\teffort: inferenceInput.reasoningEffort,\n\t\t\t}\n\t\t}\n\n\t\tif (inferenceInput.structuredOutput) {\n\t\t\tconst format = inferenceInput.structuredOutput\n\t\t\trequest.text = {\n\t\t\t\tformat: {\n\t\t\t\t\ttype: \"json_schema\",\n\t\t\t\t\tname: format.name ?? \"response\",\n\t\t\t\t\tschema: format.schema,\n\t\t\t\t\tstrict: format.strict ?? true,\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\n\t\tif (inferenceInput.streaming) {\n\t\t\trequest.stream = inferenceInput.streaming\n\t\t}\n\n\t\treturn request\n\t}\n\n\tmapContextItems(inferenceInput: InferenceInput): any[] {\n\t\tconst input: any[] = []\n\n\t\tfor (const item of inferenceInput.context.getItems()) {\n\t\t\tif (\n\t\t\t\titem instanceof DeveloperMessageItem ||\n\t\t\t\titem instanceof SystemMessageItem ||\n\t\t\t\titem instanceof UserMessageItem\n\t\t\t) {\n\t\t\t\tinput.push({\n\t\t\t\t\ttype: item.type,\n\t\t\t\t\trole: item.role,\n\t\t\t\t\tcontent: [{ type: \"input_text\", text: item.content.text }],\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof ModelMessageItem) {\n\t\t\t\tinput.push({\n\t\t\t\t\ttype: item.type,\n\t\t\t\t\trole: item.role,\n\t\t\t\t\tcontent: [{ type: \"output_text\", text: item.content.text }],\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallItem) {\n\t\t\t\tinput.push({\n\t\t\t\t\ttype: item.type,\n\t\t\t\t\tcall_id: item.callId,\n\t\t\t\t\tname: item.name,\n\t\t\t\t\targuments: item.args,\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallOutputItem) {\n\t\t\t\tinput.push({\n\t\t\t\t\ttype: item.type,\n\t\t\t\t\tcall_id: item.callId,\n\t\t\t\t\toutput: [{ type: \"input_text\", text: item.output.text }],\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof ReasoningItem) {\n\t\t\t\tconst reasoningInput: Record<string, unknown> = {\n\t\t\t\t\ttype: item.type,\n\t\t\t\t\tsummary: item.summary.map((summary) => ({ type: \"summary_text\", text: summary.text })),\n\t\t\t\t}\n\t\t\t\tif (item.encryptedContent !== undefined) {\n\t\t\t\t\treasoningInput.encrypted_content = item.encryptedContent\n\t\t\t\t}\n\t\t\t\tinput.push(reasoningInput)\n\t\t\t}\n\t\t}\n\n\t\treturn input\n\t}\n\n\textractTokenUsage(response: OpenAI.Responses.Response): TokenUsage | undefined {\n\t\tif (!response.usage) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn new TokenUsage(\n\t\t\tresponse.usage.input_tokens,\n\t\t\tresponse.usage.output_tokens,\n\t\t\tresponse.usage.total_tokens,\n\t\t\tnew InputTokenDetails(response.usage.input_tokens_details?.cached_tokens ?? 0),\n\t\t\tnew OutputTokenDetails(response.usage.output_tokens_details?.reasoning_tokens ?? 0),\n\t\t)\n\t}\n\n\ttoResponse(response: any): InferenceOutput {\n\t\tconst items: InferenceItem[] = []\n\n\t\tfor (const item of response.output ?? []) {\n\t\t\tif (item.type === \"message\" && item.role === \"assistant\") {\n\t\t\t\tconst firstContent = item.content?.[0]\n\t\t\t\tif (firstContent) {\n\t\t\t\t\titems.push(ModelMessageItem.rehydrate(firstContent as { text: string }))\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (item.type === \"function_call\") {\n\t\t\t\titems.push(\n\t\t\t\t\tFunctionCallItem.rehydrate({\n\t\t\t\t\t\tcallId: item.call_id,\n\t\t\t\t\t\tname: item.name,\n\t\t\t\t\t\targs: item.arguments,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (item.type === \"reasoning\") {\n\t\t\t\titems.push(\n\t\t\t\t\tReasoningItem.rehydrate({\n\t\t\t\t\t\tcontent: undefined,\n\t\t\t\t\t\tencryptedContent: item.encrypted_content,\n\t\t\t\t\t\tsummary: (item.summary ?? []).map((summary: { text: string }) =>\n\t\t\t\t\t\t\tSummaryText.rehydrate({ text: summary.text }),\n\t\t\t\t\t\t),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\titems,\n\t\t\trowResponse: response,\n\t\t}\n\t}\n}\n","import { SemanticEvent } from \"@domain/agentic-environment/semantic-event/event\"\nimport { GoogleGenAI } from \"@google/genai\"\nimport type { Endpoint } from \"@domain/generative-model/endpoint\"\nimport type { InferenceInput, InferenceOutput } from \"@app/states/inference\"\nimport { GeminiGenerateContentMapper } from \"./gemini-generate-content-mapper\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\n\nexport interface GeminiConnectionConfig {\n\tbaseURL?: string\n\tapiKey?: string\n}\n\n/**\n * Native Gemini adapter on the `@google/genai` SDK (`generateContent` /\n * `generateContentStream`). Unlike an OpenAI-compat shim this maps our\n * domain context to Gemini's native `contents`/`parts` shape, system\n * instruction, `functionDeclarations`, and `thinkingConfig`, and reads\n * thought parts + native usage metadata back out. Another `ModelRuntime`\n * — no runner or port changes.\n */\nexport class GeminiGenerateContent implements Endpoint {\n\tendpointMapper: InferenceEndpointMapper\n\tprivate _client?: GoogleGenAI\n\tprivate readonly clientConfig: GeminiConnectionConfig\n\n\tconstructor(\n\t\tendpointMapper: InferenceEndpointMapper = new GeminiGenerateContentMapper(),\n\t\tconfig: GeminiConnectionConfig = {},\n\t) {\n\t\tthis.endpointMapper = endpointMapper\n\t\tthis.clientConfig = config\n\t}\n\n\tprivate get client(): GoogleGenAI {\n\t\treturn (this._client ??= new GoogleGenAI({\n\t\t\tapiKey: this.clientConfig.apiKey ?? process.env.GEMINI_API_KEY,\n\t\t\t...(this.clientConfig.baseURL ? { httpOptions: { baseUrl: this.clientConfig.baseURL } } : {}),\n\t\t}))\n\t}\n\n\tasync infer(inferenceInput: InferenceInput): Promise<InferenceOutput> {\n\t\tconst request = this.endpointMapper.toRequest(inferenceInput)\n\t\tconst response = await this.client.models.generateContent(request)\n\n\t\treturn this.endpointMapper.toResponse(response)\n\t}\n\n\tasync *stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent> {\n\t\tconst request = this.endpointMapper.toRequest(inferenceInput)\n\t\tconst stream: any = await this.client.models.generateContentStream(request)\n\n\t\tlet lastEvent: SemanticEvent | undefined = undefined\n\t\tfor await (const chunk of stream) {\n\t\t\tlastEvent = chunk\n\t\t\tyield chunk\n\t\t}\n\n\t\tif (!lastEvent) {\n\t\t\tthrow new Error(\"Last event not found\")\n\t\t}\n\n\t\tconst output = this.endpointMapper.toResponse(lastEvent)\n\n\t\tyield {\n\t\t\ttype: \"inference.output\",\n\t\t\tproducerId: request.model,\n\t\t\toccurredAt: new Date(),\n\t\t\tpayload: output,\n\t\t}\n\t}\n}\n","import type { InferenceInput, InferenceItem, InferenceOutput } from \"@app/states/inference\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\nimport { InputTokenDetails, OutputTokenDetails, TokenUsage } from \"@domain/generative-model/token-usage\"\nimport { DeveloperMessageItem } from \"@domain/model-context/context-item/client-item/developer-message\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport { SystemMessageItem } from \"@domain/model-context/context-item/client-item/system-message\"\nimport { UserMessageItem } from \"@domain/model-context/context-item/client-item/user-message\"\nimport { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\nimport { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\n\nexport class GeminiGenerateContentMapper implements InferenceEndpointMapper {\n\ttoRequest(inferenceInput: InferenceInput) {\n\t\tconst { contents, systemInstruction } = this.mapContextItems(inferenceInput)\n\t\tconst config: any = {}\n\n\t\tif (systemInstruction) {\n\t\t\tconfig.systemInstruction = systemInstruction\n\t\t}\n\n\t\tif (inferenceInput.tools && inferenceInput.tools.length > 0) {\n\t\t\tconfig.tools = [\n\t\t\t\t{\n\t\t\t\t\tfunctionDeclarations: inferenceInput.tools.map((tool) => ({\n\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\t\tparametersJsonSchema: tool.parameters,\n\t\t\t\t\t})),\n\t\t\t\t},\n\t\t\t]\n\t\t}\n\n\t\tif (inferenceInput.structuredOutput) {\n\t\t\tconfig.responseMimeType = \"application/json\"\n\t\t\tconfig.responseSchema = inferenceInput.structuredOutput.schema\n\t\t}\n\n\t\tif (inferenceInput.reasoningEffort) {\n\t\t\tconfig.thinkingConfig = {\n\t\t\t\tthinkingLevel: inferenceInput.reasoningEffort,\n\t\t\t\tincludeThoughts: true,\n\t\t\t}\n\t\t}\n\n\t\tconst request: any = {\n\t\t\tmodel: inferenceInput.model,\n\t\t\tcontents,\n\t\t\tconfig,\n\t\t}\n\n\t\tif (inferenceInput.streaming) {\n\t\t\trequest.stream = inferenceInput.streaming\n\t\t}\n\n\t\treturn request\n\t}\n\n\tmapContextItems(inferenceInput: InferenceInput): { contents: any[]; systemInstruction?: string } {\n\t\tconst context = inferenceInput.context\n\t\tconst contents: any[] = []\n\t\tconst system: string[] = []\n\t\tconst callNames = new Map<string, string>()\n\n\t\tfor (const item of context.getItems()) {\n\t\t\tif (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {\n\t\t\t\tsystem.push(item.content.text)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof UserMessageItem) {\n\t\t\t\tthis.addPart(contents, \"user\", { text: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof ModelMessageItem) {\n\t\t\t\tthis.addPart(contents, \"model\", { text: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallItem) {\n\t\t\t\tcallNames.set(item.callId, item.name)\n\t\t\t\tlet args: any\n\t\t\t\ttry {\n\t\t\t\t\targs = JSON.parse(item.args)\n\t\t\t\t} catch {\n\t\t\t\t\targs = {}\n\t\t\t\t}\n\t\t\t\tthis.addPart(contents, \"model\", { functionCall: { id: item.callId, name: item.name, args } })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallOutputItem) {\n\t\t\t\tthis.addPart(contents, \"user\", {\n\t\t\t\t\tfunctionResponse: {\n\t\t\t\t\t\tid: item.callId,\n\t\t\t\t\t\tname: callNames.get(item.callId) ?? \"\",\n\t\t\t\t\t\tresponse: this.parseResponse(item.output.text),\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tcontents,\n\t\t\tsystemInstruction: system.length > 0 ? system.join(\"\\n\\n\") : undefined,\n\t\t}\n\t}\n\n\tprivate addPart(contents: any[], role: \"user\" | \"model\", part: any): void {\n\t\tconst last = contents[contents.length - 1]\n\t\tif (last?.role === role) {\n\t\t\tlast.parts.push(part)\n\t\t\treturn\n\t\t}\n\n\t\tcontents.push({ role, parts: [part] })\n\t}\n\n\tprivate parseResponse(output: string): any {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(output)\n\t\t\treturn parsed && typeof parsed === \"object\" ? parsed : { output }\n\t\t} catch {\n\t\t\treturn { output }\n\t\t}\n\t}\n\n\textractTokenUsage(response: any): TokenUsage | undefined {\n\t\tconst usage = response.usageMetadata\n\t\tif (!usage) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn new TokenUsage(\n\t\t\tusage.promptTokenCount ?? 0,\n\t\t\tusage.candidatesTokenCount ?? 0,\n\t\t\tusage.totalTokenCount ?? 0,\n\t\t\tnew InputTokenDetails(usage.cachedContentTokenCount ?? 0),\n\t\t\tnew OutputTokenDetails(usage.thoughtsTokenCount ?? 0),\n\t\t)\n\t}\n\n\ttoResponse(response: any): InferenceOutput {\n\t\tconst items: InferenceItem[] = []\n\t\tconst parts = response.candidates?.[0]?.content?.parts ?? []\n\n\t\tfor (const part of parts) {\n\t\t\tif (part.thought && part.text) {\n\t\t\t\titems.push(\n\t\t\t\t\tReasoningItem.rehydrate({\n\t\t\t\t\t\tcontent: InputText.rehydrate({ text: part.text }),\n\t\t\t\t\t\tencryptedContent: undefined,\n\t\t\t\t\t\tsummary: [],\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (part.text) {\n\t\t\t\titems.push(ModelMessageItem.rehydrate({ text: part.text }))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (part.functionCall) {\n\t\t\t\titems.push(\n\t\t\t\t\tFunctionCallItem.rehydrate({\n\t\t\t\t\t\tcallId: part.functionCall.id ?? \"\",\n\t\t\t\t\t\tname: part.functionCall.name,\n\t\t\t\t\t\targs: JSON.stringify(part.functionCall.args ?? {}),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\treturn { items, rowResponse: response }\n\t}\n}\n","import type { InferenceInput, InferenceItem, InferenceOutput } from \"@app/states/inference\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\nimport { DeveloperMessageItem } from \"@domain/model-context/context-item/client-item/developer-message\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport { SystemMessageItem } from \"@domain/model-context/context-item/client-item/system-message\"\nimport { UserMessageItem } from \"@domain/model-context/context-item/client-item/user-message\"\nimport { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport { InputText } from \"@domain/model-context/context-item/item-content/input-text\"\nimport { ReasoningItem } from \"@domain/model-context/context-item/model-item/reasoning\"\nimport type { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { InputTokenDetails, OutputTokenDetails, TokenUsage } from \"@domain/generative-model/token-usage\"\n\nexport class OpenAIChatCompletionsMapper implements InferenceEndpointMapper {\n\ttoRequest(inferenceInput: InferenceInput) {\n\t\tconst request: any = {\n\t\t\tmodel: inferenceInput.model,\n\t\t\tmessages: this.mapContextItems(inferenceInput),\n\t\t}\n\n\t\tif (inferenceInput.tools && inferenceInput.tools.length > 0) {\n\t\t\trequest.tools = inferenceInput.tools.map((tool) => ({\n\t\t\t\ttype: \"function\",\n\t\t\t\tfunction: {\n\t\t\t\t\tname: tool.name,\n\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\tparameters: tool.parameters,\n\t\t\t\t},\n\t\t\t}))\n\t\t}\n\n\t\tif (inferenceInput.reasoningEffort) {\n\t\t\trequest.reasoning_effort = inferenceInput.reasoningEffort\n\t\t}\n\n\t\tif (inferenceInput.streaming) {\n\t\t\trequest.stream = inferenceInput.streaming\n\t\t}\n\n\t\treturn request\n\t}\n\n\tmapContextItems(inferenceInput: InferenceInput): any[] {\n\t\tconst messages: any[] = []\n\n\t\tfor (const item of inferenceInput.context.getItems()) {\n\t\t\tif (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {\n\t\t\t\tmessages.push({ role: \"system\", content: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof UserMessageItem) {\n\t\t\t\tmessages.push({ role: \"user\", content: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof ModelMessageItem) {\n\t\t\t\tmessages.push({ role: \"assistant\", content: item.content.text })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallItem) {\n\t\t\t\tconst toolCall = {\n\t\t\t\t\tid: item.callId,\n\t\t\t\t\ttype: \"function\",\n\t\t\t\t\tfunction: { name: item.name, arguments: item.args },\n\t\t\t\t}\n\t\t\t\tconst last = messages[messages.length - 1]\n\t\t\t\tif (last?.role === \"assistant\") {\n\t\t\t\t\tlast.tool_calls = last.tool_calls ?? []\n\t\t\t\t\tlast.tool_calls.push(toolCall)\n\t\t\t\t} else {\n\t\t\t\t\tmessages.push({ role: \"assistant\", content: null, tool_calls: [toolCall] })\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (item instanceof FunctionCallOutputItem) {\n\t\t\t\tmessages.push({ role: \"tool\", tool_call_id: item.callId, content: item.output.text })\n\t\t\t}\n\t\t}\n\n\t\treturn messages\n\t}\n\n\textractTokenUsage(response: any): TokenUsage | undefined {\n\t\tif (!response.usage) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn new TokenUsage(\n\t\t\tresponse.usage.prompt_tokens,\n\t\t\tresponse.usage.completion_tokens,\n\t\t\tresponse.usage.total_tokens,\n\t\t\tnew InputTokenDetails(response.usage.prompt_tokens_details?.cached_tokens ?? 0),\n\t\t\tnew OutputTokenDetails(response.usage.completion_tokens_details?.reasoning_tokens ?? 0),\n\t\t)\n\t}\n\n\ttoResponse(response: any): InferenceOutput {\n\t\tconst items: InferenceItem[] = []\n\t\tconst message = response.choices?.[0]?.message\n\t\tif (!message) {\n\t\t\treturn { items: [], rowResponse: response }\n\t\t}\n\n\t\tif (message.reasoning_content) {\n\t\t\titems.push(\n\t\t\t\tReasoningItem.rehydrate({\n\t\t\t\t\tcontent: InputText.rehydrate({ text: message.reasoning_content }),\n\t\t\t\t\tencryptedContent: undefined,\n\t\t\t\t\tsummary: [],\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tif (message.content) {\n\t\t\titems.push(ModelMessageItem.rehydrate({ text: message.content }))\n\t\t}\n\n\t\tfor (const toolCall of message.tool_calls ?? []) {\n\t\t\titems.push(\n\t\t\t\tFunctionCallItem.rehydrate({\n\t\t\t\t\tcallId: toolCall.id,\n\t\t\t\t\tname: toolCall.function.name,\n\t\t\t\t\targs: toolCall.function.arguments,\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\treturn { items, rowResponse: response }\n\t}\n}\n","import type { InferenceOutput } from \"@app/states/inference\"\nimport { SemanticEvent } from \"@domain/agentic-environment/semantic-event/event\"\nimport type { Endpoint } from \"@domain/generative-model/endpoint\"\nimport { OpenAIChatCompletionsMapper } from \"./openai-chat-completions-mapper\"\nimport type { InferenceInput } from \"@app/states/inference\"\nimport OpenAI from \"openai\"\nimport type { InferenceEndpointMapper } from \"@domain/generative-model/inference-endpoint-mapper\"\n\n/**\n * Optional connection config. When omitted, the `openai` SDK reads\n * `OPENAI_API_KEY` and `OPENAI_BASE_URL` from the environment, so the\n * default-constructed runtime targets whatever `OPENAI_BASE_URL` points\n * at (real OpenAI when unset). Provider presets (e.g. DeepSeek) pass an\n * explicit base URL + credential.\n */\nexport interface OpenAICompatibleConfig {\n\tbaseURL?: string\n\tapiKey?: string\n\t/**\n\t * Extra request-body fields merged into every `chat.completions`\n\t * call. This is how provider-specific quirks are handled **without\n\t * a per-provider subclass in mozaik** — the consumer supplies the\n\t * vendor-only fields (e.g. DeepSeek's `{ thinking: { type } }`,\n\t * safety flags, routing hints). Standard fields the runtime already\n\t * sets (`model`, `messages`, `tools`, `reasoning_effort`) take\n\t * precedence and are not overwritten.\n\t */\n\textraBody?: Record<string, unknown>\n}\n\n/**\n * Generic adapter for any **OpenAI Chat Completions**-compatible\n * endpoint — real OpenAI, DeepSeek, Xiaomi MiMo, OpenRouter, vLLM,\n * Ollama, etc. It speaks `/chat/completions` (not the Responses API),\n * which is the dialect third-party OpenAI-compatible providers expose.\n *\n * The base URL and credential are configurable; everything else (the\n * `ModelContext` ⇄ chat-message conversion, tool-call round-trip, token\n * usage extraction) is provider-agnostic. Provider-specific request\n * shaping (e.g. DeepSeek's `thinking` field) is supplied by the\n * consumer via {@link OpenAICompatibleConfig.extraBody} — mozaik stays\n * generic and gains no per-provider subclasses.\n *\n * Was `DeepSeekChatCompletions`; generalized so consumers can point it\n * at any OpenAI-compatible endpoint.\n */\nexport class OpenAIChatCompletions implements Endpoint {\n\tendpointMapper: InferenceEndpointMapper\n\tprivate _client?: OpenAI\n\tprivate readonly clientConfig: OpenAICompatibleConfig\n\tprivate readonly extraBody: Record<string, unknown>\n\n\tconstructor(\n\t\tendpointMapper: InferenceEndpointMapper = new OpenAIChatCompletionsMapper(),\n\t\tconfig: OpenAICompatibleConfig = {},\n\t) {\n\t\tthis.endpointMapper = endpointMapper\n\t\tthis.clientConfig = config\n\t\tthis.extraBody = config.extraBody ?? {}\n\t}\n\n\tprivate get client(): OpenAI {\n\t\t// Passing `undefined` for baseURL/apiKey lets the SDK fall back\n\t\t// to OPENAI_BASE_URL / OPENAI_API_KEY from the environment.\n\t\treturn (this._client ??= new OpenAI({\n\t\t\tbaseURL: this.clientConfig.baseURL,\n\t\t\tapiKey: this.clientConfig.apiKey,\n\t\t}))\n\t}\n\n\tprivate buildRequest(inferenceInput: InferenceInput): any {\n\t\treturn {\n\t\t\t...this.extraBody,\n\t\t\t...this.endpointMapper.toRequest(inferenceInput),\n\t\t}\n\t}\n\n\tasync infer(inferenceInput: InferenceInput): Promise<InferenceOutput> {\n\t\tconst response = await this.client.chat.completions.create(this.buildRequest(inferenceInput))\n\n\t\treturn this.endpointMapper.toResponse(response)\n\t}\n\n\tasync *stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent> {\n\t\tconst stream = this.client.chat.completions.stream(this.buildRequest(inferenceInput))\n\n\t\tfor await (const chunk of stream) {\n\t\t\tyield chunk as unknown as SemanticEvent\n\t\t}\n\n\t\tconst output = this.endpointMapper.toResponse(await stream.finalChatCompletion())\n\n\t\tyield {\n\t\t\ttype: \"inference.output\",\n\t\t\tpayload: output,\n\t\t\toccurredAt: new Date(),\n\t\t\tproducerId: inferenceInput.model,\n\t\t}\n\t}\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const claudeSonnet46Specification: ModelSpecification = {\n\tname: \"claude-sonnet-4-6\",\n\tprovider: \"anthropic\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"max\", \"high\", \"medium\", \"low\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 200_000,\n\tmaxOutputTokens: 64_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const claudeOpus48Specification: ModelSpecification = {\n\tname: \"claude-opus-4-8\",\n\tprovider: \"anthropic\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"max\", \"xhigh\", \"high\", \"medium\", \"low\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 200_000,\n\tmaxOutputTokens: 32_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const claudeOpus47Specification: ModelSpecification = {\n\tname: \"claude-opus-4-7\",\n\tprovider: \"anthropic\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"max\", \"xhigh\", \"high\", \"medium\", \"low\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 200_000,\n\tmaxOutputTokens: 32_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const gemini35FlashSpecification: ModelSpecification = {\n\tname: \"gemini-3.5-flash\",\n\tprovider: \"google\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"high\", \"medium\", \"low\", \"minimal\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 1_048_576,\n\tmaxOutputTokens: 64_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const gemini31ProSpecification: ModelSpecification = {\n\tname: \"gemini-3.1-pro-preview\",\n\tprovider: \"google\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"high\", \"medium\", \"low\", \"minimal\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 1_048_576,\n\tmaxOutputTokens: 64_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const deepSeekV4FlashSpecification: ModelSpecification = {\n\tname: \"deepseek-v4-flash\",\n\tprovider: \"deepseek\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"max\", \"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 1_000_000,\n\tmaxOutputTokens: 384_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: false,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const deepSeekV4ProSpecification: ModelSpecification = {\n\tname: \"deepseek-v4-pro\",\n\tprovider: \"deepseek\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"max\", \"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 1_000_000,\n\tmaxOutputTokens: 384_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: false,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const gpt54Specification: ModelSpecification = {\n\tname: \"gpt-5.4\",\n\tprovider: \"openai\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"xhigh\", \"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 1_050_000,\n\tmaxOutputTokens: 128_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const gpt54MiniSpecification: ModelSpecification = {\n\tname: \"gpt-5.4-mini\",\n\tprovider: \"openai\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"xhigh\", \"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 400_000,\n\tmaxOutputTokens: 128_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const gpt54NanoSpecification: ModelSpecification = {\n\tname: \"gpt-5.4-nano\",\n\tprovider: \"openai\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"xhigh\", \"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 400_000,\n\tmaxOutputTokens: 128_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const gpt55Specification: ModelSpecification = {\n\tname: \"gpt-5.5\",\n\tprovider: \"openai\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"xhigh\", \"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 1_050_000,\n\tmaxOutputTokens: 128_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\n\nexport const claudeHaiku45Specification: ModelSpecification = {\n\tname: \"claude-haiku-4-5\",\n\tprovider: \"anthropic\",\n\tsupportsReasoningEffort: true,\n\tsupportedReasoningEfforts: [\"high\", \"medium\", \"low\", \"none\"],\n\tsupportedContextItemTypes: [\n\t\t\"user_message\",\n\t\t\"system_message\",\n\t\t\"developer_message\",\n\t\t\"reasoning\",\n\t\t\"function_call\",\n\t\t\"function_call_output\",\n\t\t\"model_message\",\n\t],\n\tsupportsStreaming: true,\n\tcontextWindowSize: 200_000,\n\tmaxOutputTokens: 64_000,\n\tsupportsFunctionCalling: true,\n\tsupportsStructuredOutput: true,\n}\n","import { AnthropicMessages } from \"@infra/providers/anthropic/endpoints/anthropic-messages\"\nimport { OpenAIResponses } from \"@infra/providers/openai/endpoints/openai-responses\"\nimport { GeminiGenerateContent } from \"@infra/providers/gemini/endpoints/gemini-generate-content\"\nimport { OpenAIChatCompletions } from \"@infra/providers/openai/endpoints/openai-chat-completions\"\nimport { claudeSonnet46Specification } from \"@infra/providers/anthropic/models/claude-4-6-sonnet\"\nimport { claudeOpus48Specification } from \"@infra/providers/anthropic/models/claude-4-8-opus\"\nimport { claudeOpus47Specification } from \"@infra/providers/anthropic/models/claude-4-7-opus\"\nimport { gemini35FlashSpecification } from \"@infra/providers/gemini/models/gemini-3-5-flash\"\nimport { gemini31ProSpecification } from \"@infra/providers/gemini/models/gemini-3-1-pro\"\nimport { deepSeekV4FlashSpecification } from \"@infra/providers/deepseek/models/deepseek-v4-flash\"\nimport { deepSeekV4ProSpecification } from \"@infra/providers/deepseek/models/deepseek-v4-pro\"\nimport { gpt54Specification } from \"@infra/providers/openai/models/gpt-5-4\"\nimport { gpt54MiniSpecification } from \"@infra/providers/openai/models/gpt-5-4-mini\"\nimport { gpt54NanoSpecification } from \"@infra/providers/openai/models/gpt-5-4-nano\"\nimport { gpt55Specification } from \"@infra/providers/openai/models/gpt-5-5\"\nimport { claudeHaiku45Specification } from \"@infra/providers/anthropic/models/claude-4-5-haiku\"\nimport type { GenerativeModel } from \"@domain/generative-model/generative-model\"\n\nexport const supportedModels: GenerativeModel[] = [\n\t{\n\t\tendpoint: new OpenAIResponses(),\n\t\tspecification: gpt54Specification,\n\t},\n\t{\n\t\tendpoint: new OpenAIResponses(),\n\t\tspecification: gpt54MiniSpecification,\n\t},\n\t{\n\t\tendpoint: new OpenAIResponses(),\n\t\tspecification: gpt54NanoSpecification,\n\t},\n\t{\n\t\tendpoint: new OpenAIResponses(),\n\t\tspecification: gpt55Specification,\n\t},\n\t{\n\t\tendpoint: new AnthropicMessages(),\n\t\tspecification: claudeHaiku45Specification,\n\t},\n\t{\n\t\tendpoint: new AnthropicMessages(),\n\t\tspecification: claudeSonnet46Specification,\n\t},\n\t{\n\t\tendpoint: new AnthropicMessages(),\n\t\tspecification: claudeOpus47Specification,\n\t},\n\t{\n\t\tendpoint: new AnthropicMessages(),\n\t\tspecification: claudeOpus48Specification,\n\t},\n\t{\n\t\tendpoint: new GeminiGenerateContent(),\n\t\tspecification: gemini35FlashSpecification,\n\t},\n\t{\n\t\tendpoint: new GeminiGenerateContent(),\n\t\tspecification: gemini31ProSpecification,\n\t},\n\t{\n\t\tendpoint: new OpenAIChatCompletions(),\n\t\tspecification: deepSeekV4FlashSpecification,\n\t},\n\t{\n\t\tendpoint: new OpenAIChatCompletions(),\n\t\tspecification: deepSeekV4ProSpecification,\n\t},\n]\n","import type { InferenceInput } from \"@app/states/inference\"\nimport type { RequestValidationRule } from \"./rule\"\nimport type { ModelSpecification } from \"../generative-model\"\n\nexport class ReasoningEffortValidation implements RequestValidationRule {\n\treadonly name = \"reasoning-effort\"\n\n\tisValid(inferenceInput: InferenceInput, model: ModelSpecification): boolean {\n\t\tif (inferenceInput.reasoningEffort === undefined) {\n\t\t\treturn true\n\t\t}\n\n\t\tif (!model.supportsReasoningEffort) {\n\t\t\treturn false\n\t\t}\n\n\t\treturn model.supportedReasoningEfforts.includes(inferenceInput.reasoningEffort)\n\t}\n}\n","import type { RequestValidationRule } from \"./rule\"\nimport type { ModelSpecification } from \"../generative-model\"\nimport type { InferenceInput } from \"@app/states/inference\"\n\nexport class ToolCallingValidation implements RequestValidationRule {\n\treadonly name = \"tool-calling\"\n\n\tisValid(inferenceInput: InferenceInput, model: ModelSpecification): boolean {\n\t\tif (inferenceInput.tools === undefined) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn model.supportsFunctionCalling\n\t}\n}\n","import type { ModelSpecification } from \"@domain/generative-model/generative-model\"\nimport type { RequestValidationRule } from \"./rule\"\nimport type { InferenceInput } from \"@app/states/inference\"\n\nexport class StreamingValidation implements RequestValidationRule {\n\treadonly name = \"streaming\"\n\n\tisValid(inferenceInput: InferenceInput, model: ModelSpecification): boolean {\n\t\tif (!inferenceInput.streaming) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn model.supportsStreaming\n\t}\n}\n","import type { InferenceInput } from \"@app/states/inference\"\nimport type { ContextItem } from \"@domain/model-context/context-item/context-item\"\nimport { DeveloperMessageItem } from \"@domain/model-context/context-item/client-item/developer-message\"\nimport { SystemMessageItem } from \"@domain/model-context/context-item/client-item/system-message\"\nimport { UserMessageItem } from \"@domain/model-context/context-item/client-item/user-message\"\nimport { ModelMessageItem } from \"@domain/model-context/context-item/model-item/model-message\"\nimport type { RequestValidationRule } from \"./rule\"\nimport type { ModelSpecification } from \"../generative-model\"\n\nfunction getContextItemValidationKey(item: ContextItem): string {\n\tif (item instanceof UserMessageItem) {\n\t\treturn \"user_message\"\n\t}\n\tif (item instanceof SystemMessageItem) {\n\t\treturn \"system_message\"\n\t}\n\tif (item instanceof DeveloperMessageItem) {\n\t\treturn \"developer_message\"\n\t}\n\tif (item instanceof ModelMessageItem) {\n\t\treturn \"model_message\"\n\t}\n\treturn item.getType()\n}\n\nexport class ContextValidation implements RequestValidationRule {\n\treadonly name = \"context\"\n\n\tisValid(inferenceInput: InferenceInput, model: ModelSpecification): boolean {\n\t\treturn inferenceInput.context.items.every((item) =>\n\t\t\tmodel.supportedContextItemTypes.includes(getContextItemValidationKey(item)),\n\t\t)\n\t}\n}\n","import type { InferenceInput } from \"@app/states/inference\"\nimport type { ModelSpecification } from \"../generative-model\"\nimport type { RequestValidationRule } from \"./rule\"\nimport { ReasoningEffortValidation } from \"./reasoning-effort\"\nimport { ToolCallingValidation } from \"./tool-calling\"\nimport { StreamingValidation } from \"./streaming\"\nimport { StructuredOutputValidation } from \"./structured-output\"\nimport { ContextValidation } from \"./context\"\n\nexport const defaultRequestValidationRules: RequestValidationRule[] = [\n\tnew ReasoningEffortValidation(),\n\tnew ToolCallingValidation(),\n\tnew StreamingValidation(),\n\tnew StructuredOutputValidation(),\n\tnew ContextValidation(),\n]\n\nexport class InferenceInputValidator {\n\tconstructor(private readonly rules: RequestValidationRule[] = defaultRequestValidationRules) {}\n\n\tvalidate(inferenceInput: InferenceInput, model: ModelSpecification): void {\n\t\tfor (const rule of this.rules) {\n\t\t\tif (!rule.isValid(inferenceInput, model)) {\n\t\t\t\tthrow new Error(`Request validation \"${rule.name}\" failed for model \"${model.name}\"`)\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { InferenceInput, InferenceOutput, InferenceRunner } from \"@app/states/inference\"\nimport type { InferenceInputValidator } from \"@domain/generative-model/request-validation/inference-request-validator\"\nimport { GenerativeModel } from \"@domain/generative-model/generative-model\"\nimport { SemanticEvent } from \"@domain/agentic-environment/semantic-event/event\"\n\nexport type InferenceCompletedParams = { answer: string; producerId: string; price?: number }\n\nexport class DefaultInferenceRunner implements InferenceRunner {\n\tconstructor(\n\t\tprivate readonly supportedModels: GenerativeModel[],\n\t\tprivate readonly requestValidator: InferenceInputValidator,\n\t) {}\n\n\tasync run(input: InferenceInput): Promise<InferenceOutput> {\n\t\tconst generativeModel = this.supportedModels.find((model) => model.specification.name === input.model)\n\t\tif (!generativeModel) {\n\t\t\tthrow new Error(`Unsupported model: ${input.model}`)\n\t\t}\n\n\t\tthis.requestValidator.validate(input, generativeModel.specification)\n\n\t\treturn await generativeModel.endpoint.infer(input)\n\t}\n\n\tasync *stream(input: InferenceInput): AsyncGenerator<SemanticEvent> {\n\t\tconst generativeModel = this.supportedModels.find((model) => model.specification.name === input.model)\n\t\tif (!generativeModel) {\n\t\t\tthrow new Error(`Unsupported model: ${input.model}`)\n\t\t}\n\n\t\tthis.requestValidator.validate(input, generativeModel.specification)\n\n\t\tyield* generativeModel.endpoint.stream(input)\n\t}\n}\n","import { FunctionCallRunner } from \"@app/states/function-call\"\nimport { Tool } from \"@domain/generative-model/tool\"\nimport { FunctionCallOutputItem } from \"@domain/model-context/context-item/client-item/function-call-output\"\nimport { FunctionCallItem } from \"@domain/model-context/context-item/model-item/function-call\"\n\nexport class DefaultFunctionCallRunner implements FunctionCallRunner {\n\tasync run(input: FunctionCallItem, tool: Tool): Promise<FunctionCallOutputItem> {\n\t\ttry {\n\t\t\tconst result = await tool.invoke(JSON.parse(input.args))\n\t\t\treturn FunctionCallOutputItem.create(input.callId, JSON.stringify(result))\n\t\t} catch (error) {\n\t\t\treturn FunctionCallOutputItem.create(input.callId, `Error calling tool: ${error}`)\n\t\t}\n\t}\n}\n","import { RuntimeService } from \"@app/services/runtime\"\nimport { RuntimeState } from \"@domain/agentic-environment/runtime-state\"\nimport { SemanticEvent } from \"@domain/agentic-environment/semantic-event/event\"\n\nexport function createSendEvent<TRuntimeState extends RuntimeState>(\n\tresolveRuntime: () => RuntimeService<TRuntimeState>,\n) {\n\treturn function sendEvent(event: SemanticEvent, senderId: string): void {\n\t\tconst runtime = resolveRuntime()\n\t\tconst participant = runtime.getParticipant(senderId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(`Participant ${senderId} not found`)\n\t\t}\n\n\t\truntime.publish(event)\n\t}\n}\n","import { RuntimeService } from \"@app/services/runtime\"\nimport { Participant } from \"@domain/agentic-environment/participant/participant\"\nimport { RuntimeState } from \"@domain/agentic-environment/runtime-state\"\nimport { EventProcessor } from \"@domain/agentic-environment/semantic-event/event-processor\"\nimport { createJoin } from \"./application/use-cases/join\"\nimport { createLeave } from \"./application/use-cases/leave\"\nimport { createSendMessage } from \"./application/use-cases/send-message\"\nimport { createRunLoop } from \"@app/use-cases/run-loop\"\nimport { InferenceRunner } from \"@app/states/inference\"\nimport { supportedModels } from \"@app/services/models\"\nimport { GenerativeModel } from \"@domain/generative-model/generative-model\"\nimport { InferenceInputValidator } from \"@domain/generative-model/request-validation/inference-request-validator\"\nimport { DefaultInferenceRunner } from \"@app/services/inference-runner\"\nimport { DefaultFunctionCallRunner } from \"@app/services/function-call\"\nimport { createSendEvent } from \"@app/use-cases/send-event\"\n\nexport type InferenceRunnerConfig = {\n\tsupportedModels?: GenerativeModel[]\n\trunner?: InferenceRunner\n}\n\nexport function defineRuntime<TRuntimeState extends RuntimeState>() {\n\tlet runtime: RuntimeService<TRuntimeState> | null = null\n\tconst processor = new EventProcessor()\n\n\tfunction initializeRuntime(config: {\n\t\tstate: TRuntimeState\n\t\tinferenceRunnerConfig?: InferenceRunnerConfig\n\t}): RuntimeService<TRuntimeState> {\n\t\tif (runtime) {\n\t\t\tthrow new Error(\"Runtime already initialized\")\n\t\t}\n\n\t\tconst inferenceRunner =\n\t\t\tconfig.inferenceRunnerConfig?.runner ??\n\t\t\tnew DefaultInferenceRunner(\n\t\t\t\tconfig.inferenceRunnerConfig?.supportedModels ?? supportedModels,\n\t\t\t\tnew InferenceInputValidator(),\n\t\t\t)\n\n\t\tconst functionCallRunner = new DefaultFunctionCallRunner()\n\n\t\truntime = new RuntimeService(config.state, processor, inferenceRunner, functionCallRunner)\n\n\t\treturn runtime\n\t}\n\n\tfunction resolveRuntime(): RuntimeService<TRuntimeState> {\n\t\tif (!runtime) {\n\t\t\tthrow new Error(\"Runtime not initialized\")\n\t\t}\n\n\t\treturn runtime\n\t}\n\n\tfunction resolveParticipant(id: string): Participant {\n\t\tif (!runtime) {\n\t\t\tthrow new Error(\"Runtime not initialized\")\n\t\t}\n\n\t\tconst participant = runtime.state.getParticipant(id)\n\n\t\tif (!participant) {\n\t\t\tthrow new Error(`Participant ${id} not found`)\n\t\t}\n\n\t\treturn participant\n\t}\n\n\tconst join = createJoin(resolveRuntime)\n\tconst leave = createLeave(resolveRuntime)\n\tconst sendMessage = createSendMessage(resolveRuntime)\n\tconst sendEvent = createSendEvent(resolveRuntime)\n\tconst runLoop = createRunLoop(resolveRuntime)\n\n\treturn {\n\t\tinitializeRuntime,\n\t\tresolveRuntime,\n\t\tresolveParticipant,\n\t\tjoin,\n\t\tleave,\n\t\tsendMessage,\n\t\tsendEvent,\n\t\trunLoop,\n\t}\n}\n","import { SemanticEvent } from \"@domain/agentic-environment/semantic-event/event\"\nimport { Participant } from \"../participant/participant\"\n\nexport type SituationContext<TEvent extends SemanticEvent = SemanticEvent> = {\n\treadonly event: TEvent\n\treadonly participant: Participant\n}\n\nexport abstract class SituationSpecification<TEvent extends SemanticEvent = SemanticEvent> {\n\tabstract isSatisfiedBy(situationContext: SituationContext<TEvent>): boolean\n\n\tand(other: SituationSpecification<TEvent>): SituationSpecification<TEvent> {\n\t\treturn new AndSituationSpecification(this, other)\n\t}\n\n\tor(other: SituationSpecification<TEvent>): SituationSpecification<TEvent> {\n\t\treturn new OrSituationSpecification(this, other)\n\t}\n\n\tnot(): SituationSpecification<TEvent> {\n\t\treturn new NotSituationSpecification(this)\n\t}\n}\n\nclass AndSituationSpecification<TEvent extends SemanticEvent> extends SituationSpecification<TEvent> {\n\tconstructor(\n\t\tprivate readonly left: SituationSpecification<TEvent>,\n\t\tprivate readonly right: SituationSpecification<TEvent>,\n\t) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn this.left.isSatisfiedBy(situationContext) && this.right.isSatisfiedBy(situationContext)\n\t}\n}\n\nclass OrSituationSpecification<TEvent extends SemanticEvent> extends SituationSpecification<TEvent> {\n\tconstructor(\n\t\tprivate readonly left: SituationSpecification<TEvent>,\n\t\tprivate readonly right: SituationSpecification<TEvent>,\n\t) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn this.left.isSatisfiedBy(situationContext) || this.right.isSatisfiedBy(situationContext)\n\t}\n}\n\nclass NotSituationSpecification<TEvent extends SemanticEvent> extends SituationSpecification<TEvent> {\n\tconstructor(private readonly rule: SituationSpecification<TEvent>) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn !this.rule.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