import type * as Effect from "effect/Effect"; import type * as Stream from "effect/Stream"; import type { ShellResult } from "../shared/shell"; import type { TaskSummary } from "../shared/tasks"; import type { WebResult, WebSource } from "../shared/web"; import type { AgentFailure } from "../worker/agent-io"; import type { CredentialFailure, ModelConfiguration, } from "../worker/model-settings"; import type { PersonalAgent } from "../worker/personal-agent"; import type { PersonalModels } from "../worker/personal-models"; import type { OperationResult } from "../worker/operation-result"; import { shellResults } from "../worker/shell-execution"; import type { ShellHost } from "../worker/shell-tool"; import type { TaskStore } from "../worker/task-store"; import type { WebFailure } from "../worker/web-errors"; import { readWebUrl } from "../worker/web-read"; import { searchWeb } from "../worker/web-search"; import { webSource } from "../worker/web-source"; function webContracts(ai: Ai, source: Omit) { const search: Effect.Effect = searchWeb( ai, "query", 3, ); const read: Effect.Effect = readWebUrl( "https://example.com", { toolCallId: "read", messages: [], context: undefined, }, ); const hashed: Effect.Effect = webSource(source); // @ts-expect-error Internal application operations compose as Effects. const promise: Promise = searchWeb(ai, "query", 3); return { search, read, hashed, promise }; } function agentContracts( tasks: TaskStore, models: PersonalModels, agent: PersonalAgent, host: ShellHost, ) { const created: Effect.Effect = tasks.create({}); const snapshot: Effect.Effect< { configuration: ModelConfiguration; apiKey?: string }, CredentialFailure | AgentFailure > = models.readModelConfiguration(); const shell: Stream.Stream = shellResults( () => host, "echo ready", ); const rpc: Promise = agent.createTask({}); const modelRpc: Promise< OperationResult<{ configuration: ModelConfiguration; apiKey?: string; }> > = agent.readModelConfiguration(); // @ts-expect-error Native RPC never transports an Effect execution object. const effectRpc: Effect.Effect = agent.createTask( {}, ); return { created, snapshot, shell, rpc, modelRpc, effectRpc }; }