@cotal-ai/connector-opencode 0.155.2 → 0.157.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,35 @@
1
+ /**
2
+ * Maps OpenCode 2.x session records to AG-UI events, with the same arms and the same withholding as
3
+ * the 1.x mapper (`agui-map.ts`). The source hands over only settled records, in session order, so
4
+ * each record is mapped once, whole.
5
+ *
6
+ * - `text` -> `TEXT_MESSAGE_*`, assistant only
7
+ * - `reasoning` -> `REASONING_*`, off by default
8
+ * - `tool` -> `TOOL_CALL_START` / `ARGS` / `END` / `RESULT`, `toolCallId` is the native call id
9
+ * - `user` -> nothing of its own: it closes the open run, because a new turn began. Its text is
10
+ * never published, for the 1.x reason: a peer batch is prepended into the person's own prompt, so
11
+ * the record has no boundary between the two authors to filter on.
12
+ * - `idle` -> closes the open run with the outcome the server recorded: `failed` is `RUN_ERROR`,
13
+ * and `succeeded` and `interrupted` are `RUN_FINISHED` with no outcome, which says the run ended
14
+ * without claiming it succeeded. A stop someone pressed is not a failure.
15
+ * - every other message kind -> nothing, and it closes nothing.
16
+ *
17
+ * A turn that ends before its first element opened no run, so its `idle` has nothing to close and
18
+ * publishes nothing, as on 1.x. Tool arguments and results are mapped here and dropped by the
19
+ * emitter's egress policy before anything is written, the one place that decides what leaves.
20
+ */
21
+ import { type RecordMapper } from "@cotal-ai/connector-core";
22
+ import type { OpenCode2Record } from "./agui-source2.js";
23
+ export interface OpenCode2MapperOptions {
24
+ /** The native session id: the `threadId` on every event. */
25
+ threadId: string;
26
+ /** Mints a `runId`. Connector-minted, so every `RUN_STARTED` carries `runIdSource: "connector"`. */
27
+ mintRunId: () => string;
28
+ /** The run the write-ahead log has open when this mapper is built, so a re-established plane
29
+ * attributes the next records to it. */
30
+ resumeRunId?: string;
31
+ /** Emit `REASONING_*` for reasoning elements. Off by default. */
32
+ reasoning?: boolean;
33
+ }
34
+ export declare function createOpenCode2Mapper(opts: OpenCode2MapperOptions): RecordMapper<OpenCode2Record>;
35
+ //# sourceMappingURL=agui-map2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agui-map2.d.ts","sourceRoot":"","sources":["../src/agui-map2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAEL,KAAK,YAAY,EAclB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE3E,MAAM,WAAW,sBAAsB;IACrC,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB,oGAAoG;IACpG,SAAS,EAAE,MAAM,MAAM,CAAC;IACxB;6CACyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAcD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,sBAAsB,GAAG,YAAY,CAAC,eAAe,CAAC,CA4DjG"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * A {@link DurableSource} over an OpenCode 2.x session, read through `GET /api/session/:id/message`,
3
+ * the server's supported message list. The shapes below were measured against OpenCode 2.2.5; the
4
+ * redacted captures are `smoke/fixtures/opencode2-sessions.json`.
5
+ *
6
+ * **What 2.x writes, and why it decides the record and the settle rule.** Each model step is one
7
+ * `assistant` message whose `content` holds its elements in the order they started: `text` and
8
+ * `reasoning` carry no id and no end mark of their own, and a `tool` carries its call id and a state
9
+ * that moves from `streaming` to `running` to `completed` or `error`. Streamed deltas never reach
10
+ * the list: a text element holds `""` until it ends and then its whole text. The message gets
11
+ * `time.streamed` once the step's output has ended and `time.completed` once its tools have too.
12
+ * Each turn closes with an `idle` message carrying the turn's `outcome`, so the end of a turn and how
13
+ * it ended are records in order. A prompt sent while a turn runs waits in the session inbox and
14
+ * enters the list only when it is delivered at a step boundary.
15
+ *
16
+ * So a record is one element, keyed by its message id and its position, and the cursor is that pair
17
+ * compared as an order. Message ids sort by creation (measured on every captured session). A message
18
+ * with no element is one record of its own: a user prompt, a turn end, and a step that has not
19
+ * written anything yet, which must hold the read like any unsettled element does.
20
+ */
21
+ import type { DurableSource, SourceRead } from "@cotal-ai/connector-core";
22
+ /** The fields of a 2.x message this source and its mapper read. */
23
+ export interface OpenCode2Message {
24
+ id: string;
25
+ /** `assistant`, `user`, `idle`, `synthetic`, `system`, `skill`, `shell`, `compaction`, or a
26
+ * `*-switched` setting change. */
27
+ type: string;
28
+ time: {
29
+ created: number;
30
+ streamed?: number;
31
+ completed?: number;
32
+ };
33
+ /** An assistant message's elements, in the order they started. */
34
+ content?: OpenCode2Element[];
35
+ /** How the turn an `idle` message closes ended. */
36
+ outcome?: "succeeded" | "failed" | "interrupted";
37
+ error?: {
38
+ type?: string;
39
+ message?: string;
40
+ };
41
+ }
42
+ export type OpenCode2Element = {
43
+ type: "text";
44
+ text: string;
45
+ } | {
46
+ type: "reasoning";
47
+ text: string;
48
+ time?: {
49
+ created: number;
50
+ completed?: number;
51
+ };
52
+ } | {
53
+ type: "tool";
54
+ id: string;
55
+ name: string;
56
+ state: {
57
+ status: "streaming" | "running" | "completed" | "error";
58
+ input?: unknown;
59
+ content?: Array<{
60
+ type: string;
61
+ text?: string;
62
+ }>;
63
+ error?: {
64
+ type?: string;
65
+ message?: string;
66
+ };
67
+ };
68
+ time: {
69
+ created: number;
70
+ ran?: number;
71
+ completed?: number;
72
+ };
73
+ };
74
+ /** One page of the message list, newest first, with the keyset cursor of the page after it. */
75
+ export interface OpenCode2MessagePage {
76
+ data: OpenCode2Message[];
77
+ cursor: {
78
+ next?: string | null;
79
+ };
80
+ }
81
+ /** Fetches the newest page, or the page after the one whose `cursor.next` is passed. Injected so the
82
+ * source can be read without a server. */
83
+ export type FetchMessagePage = (next: string | undefined) => Promise<OpenCode2MessagePage>;
84
+ /** One element of an assistant message at its position, or a message with no element at `-1`. */
85
+ export interface OpenCode2Record {
86
+ message: OpenCode2Message;
87
+ index: number;
88
+ element?: OpenCode2Element;
89
+ }
90
+ export interface OpenCode2SessionSourceOptions {
91
+ page: FetchMessagePage;
92
+ /** Called once per cursor whose record is no longer in the session, which is what a revert does.
93
+ * The read stays correct without it, because the cursor is compared as an order. */
94
+ onVanished?: (cursor: string) => void;
95
+ }
96
+ export declare class OpenCode2SessionSource implements DurableSource<OpenCode2Record> {
97
+ readonly kind = "opencode2-session";
98
+ private readonly page;
99
+ private readonly onVanished?;
100
+ private reportedVanished?;
101
+ constructor(opts: OpenCode2SessionSourceOptions);
102
+ /** Every message at or after `from`, or the whole session when `from` is absent. Pages run newest
103
+ * first, so the read stops at the first page that reaches back to `from`. */
104
+ private messages;
105
+ /** The records in session order, each with whether a later `idle` has ended its turn. */
106
+ private ordered;
107
+ end(): Promise<string>;
108
+ read(cursor: string | undefined): Promise<SourceRead<OpenCode2Record>>;
109
+ }
110
+ //# sourceMappingURL=agui-source2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agui-source2.d.ts","sourceRoot":"","sources":["../src/agui-source2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE1E,mEAAmE;AACnE,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX;uCACmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACjE,kEAAkE;IAClE,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC7B,mDAAmD;IACnD,OAAO,CAAC,EAAE,WAAW,GAAG,QAAQ,GAAG,aAAa,CAAC;IACjD,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,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