@restatedev/agents 0.4.0 → 0.5.0

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.
@@ -0,0 +1,249 @@
1
+ // OpenCode on the object's database: `openOpenCode(db, fence, options)` boots
2
+ // OpenCode 2.2's embedded host (@opencode/sdk) with its database in a SQL
3
+ // session, `ctx.db`.
4
+ //
5
+ // The host is OpenCode's workerd profile, the one it boots in a Cloudflare
6
+ // Durable Object: no local filesystem, shell, terminal, npm or version
7
+ // control, config given inline, plugins given in code. Only its database
8
+ // differs. The workerd profile reads a Durable Object's SQLite, whose `exec`
9
+ // is synchronous; here OpenCode gets an Effect SqlClient instead, which is
10
+ // asynchronous, through `Database.configuredClient` (OpenCode's), the seam
11
+ // OpenCode keeps for an injected client. Each transaction is an SQL
12
+ // transaction, and the session runs statements one at a time, as OpenCode's
13
+ // own clients do.
14
+ //
15
+ // `fence.closed` refuses every statement from then on: an attempt that is
16
+ // giving up stores nothing more, as Restate fences an attempt that a newer
17
+ // one replaced.
18
+ //
19
+ // At boot, OpenCode sweeps the turns a previous process left claimed
20
+ // (`SessionRestart`): `restart` says what this boot does with them (see
21
+ // {@link Restart}), and `Host.swept` settles once the sweep is done.
22
+ //
23
+ // Step 0 of docs/opencode.md (the spike) found its seams; `./opencode/db` exports it.
24
+ import { Context, Deferred, Effect, Exit, Layer, Option, Scope } from 'effect';
25
+ import { Reactivity } from 'effect/reactivity';
26
+ import { SqlClient, Statement } from 'effect/sql';
27
+ import { SqlError, UnknownError } from 'effect/sql/SqlError';
28
+ import { Bus } from '@opencode/core/bus';
29
+ import { Database as OpenCodeDatabase } from '@opencode/core/database/database';
30
+ import { fromPromise } from '@opencode/core/plugin/promise';
31
+ import { SessionEvent } from '@opencode/core/session/event';
32
+ import { SessionExecution } from '@opencode/core/session/execution';
33
+ import { SessionRestart } from '@opencode/core/session/execution/restart';
34
+ import { SessionStore } from '@opencode/core/session/store';
35
+ import { ConfigPluginSource } from '@opencode/core/config/plugin/source';
36
+ import { Pty } from '@opencode/core/pty';
37
+ import { Snapshot } from '@opencode/core/snapshot';
38
+ import { ServerWorkerd } from '@opencode/server/workerd';
39
+ import { OpenCode } from '@opencode/sdk/effect';
40
+ const error = (operation, cause) => new SqlError({
41
+ reason: new UnknownError({
42
+ cause,
43
+ message: cause instanceof Error ? cause.message : String(cause),
44
+ operation,
45
+ }),
46
+ });
47
+ /** The connection inside a transaction, for statements of that transaction. */
48
+ const InTransaction = Context.Service('@restatedev/agents/OpenCodeTransaction');
49
+ /** A statement that writes. */
50
+ const WRITE = /^\s*(INSERT|UPDATE|DELETE|REPLACE)\b/i;
51
+ /**
52
+ * A connection whose statements go to `target`: the session, which runs one
53
+ * call at a time and holds them while a transaction runs, or that
54
+ * transaction's database. Each is refused once `fence` closes; `wrote` is
55
+ * told of each statement that writes.
56
+ */
57
+ function connection(target, fence, wrote = () => { }) {
58
+ // Effect binds what the compiler made of OpenCode's values: SQL values.
59
+ const exec = (read, sql, params) => Effect.tryPromise({
60
+ try: async () => {
61
+ if (fence.closed)
62
+ throw new Error('the attempt is over');
63
+ const result = await read(sql, params);
64
+ if (WRITE.test(sql))
65
+ wrote();
66
+ return result;
67
+ },
68
+ catch: (cause) => error('execute', cause),
69
+ });
70
+ const run = (sql, params = []) => exec((s, p) => target.query(s, p), sql, params);
71
+ const runValues = (sql, params = []) => exec((s, p) => target.values(s, p), sql, params);
72
+ const transformed = (sql, params, transformRows) => transformRows ? Effect.map(run(sql, params), transformRows) : run(sql, params);
73
+ return {
74
+ execute: transformed,
75
+ executeRaw: (sql, params) => run(sql, params),
76
+ executeValues: (sql, params) => runValues(sql, params),
77
+ executeValuesUnprepared: (sql, params) => runValues(sql, params),
78
+ executeUnprepared: transformed,
79
+ executeStream: () => {
80
+ throw new Error('executeStream is not supported');
81
+ },
82
+ };
83
+ }
84
+ /**
85
+ * An Effect SqlClient over `db`, with its statements refused once `fence`
86
+ * closes. `committed` runs after each write is committed: a transaction that
87
+ * wrote, or a statement that writes outside one.
88
+ */
89
+ export function sqlClient(db, fence, committed = () => { }) {
90
+ // `effect` as one SQL transaction: it commits when `effect` succeeds
91
+ // and rolls back when it fails. Its statements go to the transaction's
92
+ // database.
93
+ const withTransaction = (effect) => Effect.withFiber((fiber) => {
94
+ if (Option.isSome(Context.getOption(fiber.context, InTransaction))) {
95
+ return Effect.fail(error('transaction', new Error('nested transactions are not supported')));
96
+ }
97
+ return Effect.callback((resume) => {
98
+ const rollback = new Error('rollback');
99
+ let interrupted = false;
100
+ let resumed = false;
101
+ let wrote = false;
102
+ // Settles when the transaction has committed, or rejects: with
103
+ // `rollback` once `effect` failed, or with the error of BEGIN or COMMIT.
104
+ const ended = db.transaction((tx) => new Promise((resolve, reject) => {
105
+ if (interrupted)
106
+ return reject(rollback);
107
+ const inner = Effect.provideContext(effect, Context.add(fiber.context, InTransaction, [connection(tx, fence, () => (wrote = true)), 0]));
108
+ resumed = true;
109
+ resume(
110
+ // A finalizer, so that the body settles however `effect`
111
+ // ends, an interruption included: otherwise the transaction
112
+ // would hold the session for good.
113
+ Effect.onExit(inner, (exit) => {
114
+ if (Exit.isSuccess(exit)) {
115
+ resolve();
116
+ return Effect.void;
117
+ }
118
+ reject(rollback);
119
+ return Effect.promise(() => settled);
120
+ }).pipe(
121
+ // The commit is part of the transaction: if it fails, so
122
+ // does the transaction.
123
+ Effect.flatMap((value) => Effect.as(Effect.tryPromise({ try: () => ended, catch: (e) => error('commit', e) }), value))));
124
+ }));
125
+ ended.then(() => (wrote ? committed() : undefined), () => undefined);
126
+ const settled = ended.catch((cause) => {
127
+ // BEGIN failed: `effect` never ran.
128
+ if (!resumed && cause !== rollback)
129
+ resume(Effect.fail(error('transaction', cause)));
130
+ });
131
+ return Effect.suspend(() => {
132
+ interrupted = true;
133
+ return Effect.promise(() => settled);
134
+ });
135
+ });
136
+ });
137
+ const make = Effect.gen(function* () {
138
+ const client = yield* SqlClient.make({
139
+ // Outside a transaction, a statement commits as it runs.
140
+ acquirer: Effect.succeed(connection(db, fence, committed)),
141
+ compiler: Statement.makeCompilerSqlite(),
142
+ driver: 'sqlite-restate',
143
+ spanAttributes: [['db.system.name', 'sqlite']],
144
+ transactionService: InTransaction,
145
+ });
146
+ return Object.assign(client, { withTransaction, transactionStatements: false });
147
+ });
148
+ return Layer.effect(SqlClient.SqlClient, make).pipe(Layer.provide(Reactivity.layer));
149
+ }
150
+ /** The result `own` gives a running tool call of a closed turn, by default. */
151
+ const CUT_OFF = 'The turn ended before this call returned: it may or may not have happened.';
152
+ /** The error `own` closes a turn with, by default. */
153
+ const ENDED = 'Ended: the turn was killed before it finished.';
154
+ /**
155
+ * A `SessionRestart` that closes each claimed top-level session this process
156
+ * does not run: OpenCode's budget's events (`Execution.Failed`, the release
157
+ * as its commit), and before them a `Tool.Failed` of our result for each
158
+ * streaming or running tool part. No synthetic message, no drain, no model.
159
+ */
160
+ const closing = (cutOff, ended) => Layer.effect(SessionRestart.Service, Effect.gen(function* () {
161
+ const store = yield* SessionStore.Service;
162
+ const execution = yield* SessionExecution.Service;
163
+ const bus = yield* Bus.Service;
164
+ const close = Effect.fnUntraced(function* (sessionID) {
165
+ for (const message of yield* Effect.orDie(store.context(sessionID))) {
166
+ if (message.type !== 'assistant')
167
+ continue;
168
+ for (const part of message.content) {
169
+ if (part.type !== 'tool')
170
+ continue;
171
+ if (part.state.status !== 'streaming' && part.state.status !== 'running')
172
+ continue;
173
+ yield* bus.publish(SessionEvent.Tool.Failed, {
174
+ sessionID,
175
+ assistantMessageID: message.id,
176
+ id: part.id,
177
+ error: { type: 'aborted', message: cutOff(part.id, part.name) },
178
+ executed: part.executed === true,
179
+ });
180
+ }
181
+ }
182
+ yield* bus.publish(SessionEvent.Execution.Failed, { sessionID, error: { type: 'aborted', message: ended } }, { commit: () => store.release(sessionID) });
183
+ });
184
+ return SessionRestart.Service.of({
185
+ resumeSuspendedSessions: Effect.gen(function* () {
186
+ const active = yield* execution.active;
187
+ // Child sessions' claims: v1 has no background subagents to recover.
188
+ yield* store.releaseChildClaims([]);
189
+ const claimed = (yield* store.listSuspended()).filter((id) => !active.has(id));
190
+ yield* Effect.forEach(claimed, close, { discard: true });
191
+ }),
192
+ });
193
+ }));
194
+ /** The sweep's service for `restart` and `closer`. */
195
+ const restarts = (restart, closer, cutOff, ended) => {
196
+ if (restart === 'none')
197
+ return Layer.succeed(SessionRestart.Service, { resumeSuspendedSessions: Effect.void });
198
+ if (restart === 'resume')
199
+ return SessionRestart.layer({ maxAttempts: Infinity });
200
+ return closer === 'budget' ? SessionRestart.layer({ maxAttempts: 0 }) : closing(cutOff, ended);
201
+ };
202
+ /** `service`, whose sweep completes `done` as it ends, however it ends. */
203
+ const observed = (layer, done) => Layer.effect(SessionRestart.Service, Effect.map(SessionRestart.Service, (inner) => SessionRestart.Service.of({
204
+ resumeSuspendedSessions: inner.resumeSuspendedSessions.pipe(Effect.onExit((exit) => Effect.asVoid(Deferred.done(done, Exit.asVoid(exit))))),
205
+ }))).pipe(Layer.provide(layer));
206
+ /** What a replacement replaces: `LayerNode`'s own record of it (its source node). */
207
+ const sourceOf = (replacement) => {
208
+ const key = Object.getOwnPropertySymbols(replacement).find((s) => s.description === 'LayerNode.Replacement');
209
+ return key && replacement[key]?.source;
210
+ };
211
+ /**
212
+ * Boot OpenCode with its database in `db`; the boot sweeps the turns left
213
+ * claimed as `restart` says. Close the host when done.
214
+ */
215
+ export async function openOpenCode(db, fence, { plugins = [], config = {}, local = false, restart = 'resume', closer = 'budget', committed, cutOff = () => CUT_OFF, ended = ENDED, }) {
216
+ // The workerd profile, but for its database, which comes first. (The
217
+ // Promise API's OpenCode.create takes no replacements; the Effect API's does.)
218
+ const profile = { storage: undefined, models: { fetch: false } };
219
+ // Taken by the node each replaces, not by position (2.1 added Npm's). Local
220
+ // keeps the stubs of snapshots, the pty and plugin discovery only.
221
+ const kept = local ? new Set([Snapshot.node, Pty.node, ConfigPluginSource.node]) : undefined;
222
+ const rest = ServerWorkerd.replacements(profile).filter((r) => {
223
+ const source = sourceOf(r);
224
+ if (source === undefined)
225
+ throw new Error('OpenCode: a workerd replacement of unknown node');
226
+ return source !== OpenCodeDatabase.node && (kept === undefined || kept.has(source));
227
+ });
228
+ const scope = Scope.makeUnsafe();
229
+ const done = Deferred.makeUnsafe();
230
+ const sweep = observed(restarts(restart, closer, cutOff, ended), done);
231
+ const client = await Effect.runPromise(OpenCode.create({
232
+ ...ServerWorkerd.serverOptions({ ...profile, config: { content: JSON.stringify(config) } }),
233
+ plugins: plugins.map(fromPromise),
234
+ }, {
235
+ overrides: [
236
+ OpenCodeDatabase.node.replace(OpenCodeDatabase.configuredClient(sqlClient(db, fence, committed))),
237
+ ...rest,
238
+ SessionRestart.node.replace(SessionRestart.node.mapLayer(() => sweep)),
239
+ ],
240
+ }).pipe(Scope.provide(scope)));
241
+ return {
242
+ client,
243
+ // The client's calls need nothing more: OpenCode provided it all.
244
+ call: (effect) => Effect.runPromise(effect),
245
+ swept: Effect.runPromise(Deferred.await(done)),
246
+ close: () => Effect.runPromise(Scope.close(scope, Exit.void)),
247
+ };
248
+ }
249
+ //# sourceMappingURL=db.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/opencode/db.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,0EAA0E;AAC1E,qBAAqB;AACrB,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,yEAAyE;AACzE,6EAA6E;AAC7E,2EAA2E;AAC3E,2EAA2E;AAC3E,oEAAoE;AACpE,4EAA4E;AAC5E,kBAAkB;AAClB,EAAE;AACF,0EAA0E;AAC1E,2EAA2E;AAC3E,gBAAgB;AAChB,EAAE;AACF,qEAAqE;AACrE,wEAAwE;AACxE,qEAAqE;AACrE,EAAE;AACF,sFAAsF;AACtF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAA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C;KAC9D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,184 @@
1
+ import * as restate from '@restatedev/sessions';
2
+ import type { Plugin } from '@opencode/plugin';
3
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
4
+ import type { z } from 'zod';
5
+ import { type Check, type Configure } from '../common.ts';
6
+ import { type Call, type Items } from '../conversation.ts';
7
+ import { type Definition } from '../object.ts';
8
+ import { type Answer } from '../output.ts';
9
+ import { type Tool as AnyTool } from '../tools.ts';
10
+ import { type Host } from './db.ts';
11
+ /** An OpenCode model reference. */
12
+ export interface ModelRef {
13
+ providerID: string;
14
+ id: string;
15
+ }
16
+ /** An OpenCode tool of your own: `execute` gets the input and the tool call's id. */
17
+ export interface OpenCodeTool<Input = unknown> {
18
+ name: string;
19
+ description: string;
20
+ input: StandardSchemaV1<unknown, Input>;
21
+ execute(input: Input, callId: string): Promise<string>;
22
+ }
23
+ /** OpenCode's message id of prompt `id`: letters, digits, `_` and `-`. */
24
+ export declare const messageIdOf: (id: string) => string;
25
+ /** A tool call's result, as an item holds it. */
26
+ interface ItemResult {
27
+ id: string;
28
+ name: string;
29
+ output: string;
30
+ error?: boolean;
31
+ }
32
+ /**
33
+ * An item of the conversation: a user's message, an assistant's message (a
34
+ * step of OpenCode's: its text and tool calls), or tool calls' results. One
35
+ * copied from OpenCode (a message steered to the turn, say) has `from`: the
36
+ * id of its OpenCode message, and for a result the id of its part too
37
+ * (`<message>/<part>`), by which it is copied once.
38
+ */
39
+ export type Item = {
40
+ type: 'user';
41
+ text: string;
42
+ from?: string;
43
+ } | {
44
+ type: 'assistant';
45
+ text: string;
46
+ calls?: Call[];
47
+ from?: string;
48
+ } | {
49
+ type: 'results';
50
+ results: ItemResult[];
51
+ from?: string;
52
+ };
53
+ /**
54
+ * OpenCode's items. A user's message is said by the user; an assistant's
55
+ * says its text, with its tool calls; results are results. OpenCode's
56
+ * synthetic messages, idle markers and compactions are never copied.
57
+ */
58
+ export declare const items: Items<Item>;
59
+ /** What `work` gets: `prompt(text)`, and the OpenCode host for anything else. */
60
+ export interface OpenCodeSession {
61
+ /** OpenCode, booted on its first use. */
62
+ host: () => Promise<Host>;
63
+ /**
64
+ * Answer `text`, once, with the answer's text: a turn of the object's
65
+ * conversation (each prompt of an invocation has an id of its own, the
66
+ * same on every attempt). With `check`, a reply it returns a message for
67
+ * is asked again within the turn, once. With `reminder`, the model is told
68
+ * it after the prompt, which the conversation keeps as it was asked.
69
+ */
70
+ prompt: (text: string, check?: Check, reminder?: string) => Promise<string>;
71
+ }
72
+ /** An agent's options: `chat`, `prompt` and `withOpenCode` take them. */
73
+ export interface Options<O extends z.ZodObject | undefined = z.ZodObject | undefined> {
74
+ /** The model of the session, as `provider/model-id`: MODEL, or else openai/gpt-6-sol. */
75
+ model?: string | ModelRef;
76
+ /** The system prompt: who the agent is, and how it answers. */
77
+ system?: string;
78
+ /** The agent's tools, which replace OpenCode's own: `tool()`s, Restate's (`call`, `signal`...), or OpenCode tools of your own. */
79
+ tools?: (AnyTool | OpenCodeTool)[];
80
+ /**
81
+ * A directory of the local machine, made if missing: OpenCode keeps its own
82
+ * tools (read, write, edit, shell, glob, grep...) there, besides `tools`,
83
+ * and the session works in it. Or a function of the invocation's context
84
+ * that gives one: `(ctx) => \`/work/${ctx.key}\``.
85
+ */
86
+ workspace?: string | ((ctx: restate.SessionContext) => string | Promise<string>);
87
+ /** OpenCode plugins, such as the one of the model. */
88
+ plugins?: Plugin.Plugin[];
89
+ /**
90
+ * How OpenCode asks the model again after a request failed for a reason
91
+ * that passes (an overloaded or unreachable provider, a rate limit), as pi
92
+ * does: by default without limit, 2 s after the first failure, then twice
93
+ * as long each time, a minute apart at most (`baseDelayMs`,
94
+ * `maxAgentDelayMs`), but never before the provider said to try again
95
+ * (its `retry-after`, which the cap does not shorten: up to 15 minutes, as
96
+ * OpenCode takes it). A request refused for good (a wrong API key, an
97
+ * unknown model, a request a retry would make again) is never asked again,
98
+ * and ends the turn (424). Unlike pi, OpenCode asks again 10 times at most
99
+ * in a step of the turn, and after its 4th timeout in a step not at all:
100
+ * without `maxRetries`, an outage OpenCode stops asking again about fails
101
+ * the attempt instead, and Restate's retry of it resumes the turn, waits
102
+ * from 2 s again. With `maxRetries`, a failure after that many retries of
103
+ * a step ends the turn, as one OpenCode stops asking again about does.
104
+ * `enabled: false` asks no request again.
105
+ */
106
+ retry?: Partial<RetryPolicy>;
107
+ /**
108
+ * With a workspace, OpenCode's own tools ask before what its permission
109
+ * rules say to ask about (by default, a read of a `.env` file). Without
110
+ * `approval`, nobody answers such an ask: it is denied, as OpenCode denies
111
+ * one nobody is present for, and the model gets the denial as the tool's
112
+ * error. With `approval`, the tool call waits for the signal
113
+ * {@link APPROVAL} to the agent, which `pending` shows with the call's tool
114
+ * and arguments and the permission asked (`action`, `resources`); `true`,
115
+ * or a text such as "approved" or "yes", allows it, anything else denies
116
+ * it (a text, or `{ reason }`, is the denial's reason, for the model).
117
+ */
118
+ approval?: boolean;
119
+ /**
120
+ * The answer as data: a zod object, whose JSON the agent replies with
121
+ * (checked), and `chat` and `prompt` answer with (see output.ts).
122
+ */
123
+ output?: O;
124
+ }
125
+ /** How a failed model request is asked again ({@link Options.retry}): pi's policy, as OpenCode can take it. */
126
+ export interface RetryPolicy {
127
+ enabled: boolean;
128
+ maxRetries: number;
129
+ baseDelayMs: number;
130
+ maxAgentDelayMs?: number;
131
+ }
132
+ /** The signal that an OpenCode tool call waits for, to the agent, when OpenCode asks for a permission (`approval`). */
133
+ export declare const APPROVAL = "approval";
134
+ /**
135
+ * Run `work(opencode)` with OpenCode over the object's database: `model` is
136
+ * the session's model, `plugins` OpenCode plugins (such as the model's), and
137
+ * `tools` the agent's tools. `opencode` has `prompt(text)`, and the
138
+ * OpenCode host for anything else.
139
+ */
140
+ export declare const withOpenCode: <T>(ctx: restate.SessionContext, { plugins, model: named, system, tools, workspace: where, retry, approval }: Options, work: (opencode: OpenCodeSession) => Promise<T>) => Promise<T>;
141
+ /**
142
+ * Answer `text`, once: a retried attempt resumes the same prompt. Each prompt
143
+ * of an invocation is a prompt of its own. With `output`, it answers with the
144
+ * value the agent replies with (see output.ts), not its text.
145
+ */
146
+ export declare const prompt: <O extends z.ZodObject | undefined = undefined>(ctx: restate.SessionContext, text: string, options?: Options<O>) => Promise<Answer<O>>;
147
+ /**
148
+ * A chat handler: each message an invocation, the session in the object's
149
+ * database, with `options`, or the options a function of the invocation's
150
+ * context gives (each user's workspace, say). It takes the message as plain
151
+ * text (`curl -d 'Hi'`) or as a JSON string (`curl --json '"Hi"'`).
152
+ */
153
+ export declare const chat: <O extends z.ZodObject | undefined = undefined>(options?: Configure<Options<O>>) => {
154
+ input: restate.Serde<string>;
155
+ accept: string;
156
+ explicitCancellation: boolean;
157
+ handler: (ctx: restate.SessionContext, text: string) => Promise<Answer<O>>;
158
+ };
159
+ /**
160
+ * A view of the conversation as clients read it: a page at a time, or what
161
+ * is new or changed since a cursor; `view: 'summary'` for each turn's
162
+ * message and answer. It answers while a message is answered. `clear` also
163
+ * empties OpenCode's database.
164
+ */
165
+ export declare const messages: () => (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
166
+ /** An agent: a virtual object `name`, one per key, whose `chat` handler is {@link chat}, and `messages` {@link messages}. */
167
+ export declare const agent: <P extends string, O extends z.ZodObject | undefined = undefined>({ name, description, schema, background, window, budget, ...options }: Options<O> & Definition<P>) => restate.VirtualObjectDefinition<P, {
168
+ signal: (ctx: restate.ViewContext, signal: import("../signals.ts").Signal) => Promise<import("../signals.ts").Resolved>;
169
+ pending: (ctx: restate.ViewContext) => Promise<import("../signals.ts").Waiting[]>;
170
+ status: (ctx: restate.ViewContext) => Promise<import("../object.ts").Status>;
171
+ stop: (ctx: restate.ViewContext) => Promise<import("../object.ts").Stopped>;
172
+ notifications: (ctx: restate.ViewContext) => Promise<import("../signals.ts").Notifications>;
173
+ watch: (ctx: restate.ViewContext, watch: import("../signals.ts").Watch) => Promise<import("../signals.ts").Notifications>;
174
+ } & {
175
+ clear: (ctx: restate.ViewContext) => Promise<import("../object.ts").Stopped>;
176
+ steer: (ctx: restate.ViewContext, text: string) => Promise<import("../signals.ts").Steered>;
177
+ sync: (ctx: restate.ViewContext, { cursor, revision, timeoutSeconds, limit, view }?: import("../object.ts").SyncRequest) => Promise<import("../object.ts").Synced>;
178
+ } & {
179
+ chat: (ctx: restate.SessionContext, text: string) => Promise<Answer<O>>;
180
+ } & {
181
+ messages: (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
182
+ }>;
183
+ export {};
184
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/opencode/index.ts"],"names":[],"mappings":"AAwEA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAGhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAIL,KAAK,KAAK,EAEV,KAAK,SAAS,EAYf,MAAM,cAAc,CAAC;AACtB,OAAO,EAA4B,KAAK,IAAI,EAAE,KAAK,KAAK,EAAiC,MAAM,oBAAoB,CAAC;AAGpH,OAAO,EAAE,KAAK,UAAU,EAAiB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,KAAK,MAAM,EAAe,MAAM,cAAc,CAAC;AACxD,OAAO,EAAU,KAAK,IAAI,IAAI,OAAO,EAAW,MAAM,aAAa,CAAC;AACpE,OAAO,EAAc,KAAK,IAAI,EAA8B,MAAM,SAAS,CAAC;AAE5E,mCAAmC;AACnC,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;CACZ;AAQD,qFAAqF;AACrF,MAAM,WAAW,YAAY,CA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