@cotal-ai/connector-opencode 0.177.0 → 0.179.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.
- package/dist/agui-map.d.ts +9 -2
- package/dist/agui-map.d.ts.map +1 -1
- package/dist/agui-map2.d.ts +29 -7
- package/dist/agui-map2.d.ts.map +1 -1
- package/dist/agui-source.d.ts +13 -2
- package/dist/agui-source.d.ts.map +1 -1
- package/dist/agui-source2.d.ts +18 -3
- package/dist/agui-source2.d.ts.map +1 -1
- package/dist/catalog2.d.ts +5 -0
- package/dist/catalog2.d.ts.map +1 -0
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog1.d.ts +10 -0
- package/dist/command-catalog1.d.ts.map +1 -0
- package/dist/command-routes.d.ts +2 -2
- package/dist/commands1.d.ts +39 -0
- package/dist/commands1.d.ts.map +1 -0
- package/dist/commands2.d.ts +28 -0
- package/dist/commands2.d.ts.map +1 -0
- package/dist/extension.d.ts +2 -1
- package/dist/extension.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/launch.d.ts.map +1 -1
- package/dist/launch.js +2 -2
- package/dist/naming2.d.ts +19 -0
- package/dist/naming2.d.ts.map +1 -0
- package/dist/opencode2-http.d.ts +14 -0
- package/dist/opencode2-http.d.ts.map +1 -0
- package/dist/opencode2-types.d.ts +2 -0
- package/dist/opencode2-types.d.ts.map +1 -1
- package/dist/plugin/docs-bundle.bin +0 -0
- package/dist/plugin/docs-index.bin +0 -0
- package/dist/plugin/index.js +53 -44
- package/dist/plugin-io.d.ts +1 -0
- package/dist/plugin-io.d.ts.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin2.d.ts.map +1 -1
- package/dist/private-serve.d.ts +18 -0
- package/dist/private-serve.d.ts.map +1 -0
- package/dist/prompt-asks.d.ts +48 -0
- package/dist/prompt-asks.d.ts.map +1 -0
- package/dist/prompts.d.ts +93 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/reconnect-command.d.ts +2 -2
- package/dist/serve.js +2 -2
- package/dist/settled-models.d.ts +10 -0
- package/dist/settled-models.d.ts.map +1 -0
- package/dist/stream1.d.ts +50 -0
- package/dist/stream1.d.ts.map +1 -0
- package/dist/stream2.d.ts +70 -0
- package/dist/stream2.d.ts.map +1 -0
- package/package.json +4 -4
package/dist/plugin-io.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface PluginIoDeps {
|
|
|
13
13
|
}
|
|
14
14
|
export interface PluginIo {
|
|
15
15
|
reapRetiredWal(threadId: string, drained: boolean): Promise<void>;
|
|
16
|
+
/** An answer that is not 2xx throws an Error carrying the HTTP `status`. */
|
|
16
17
|
opencodeApi<T>(path: string, init?: RequestInit, timeoutMs?: number): Promise<T>;
|
|
17
18
|
isMessageAbortedError(error: unknown): boolean;
|
|
18
19
|
runErrorOf(error: unknown): {
|
package/dist/plugin-io.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-io.d.ts","sourceRoot":"","sources":["../src/plugin-io.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAsD,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAKhI,4GAA4G;AAC5G,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjF,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IAC/C,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAChE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,QAAQ,
|
|
1
|
+
{"version":3,"file":"plugin-io.d.ts","sourceRoot":"","sources":["../src/plugin-io.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAsD,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAKhI,4GAA4G;AAC5G,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,4EAA4E;IAC5E,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjF,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IAC/C,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAChE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,QAAQ,CAwHrD"}
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAuEA,OAAO,KAAK,EAAE,MAAM,EAAyB,MAAM,qBAAqB,CAAC;AAezE,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,aAAa,GACd,MAAM,mBAAmB,CAAC;AAW3B,eAAO,MAAM,KAAK,EAAE,MA+0CnB,CAAC"}
|
package/dist/plugin2.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin2.d.ts","sourceRoot":"","sources":["../src/plugin2.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin2.d.ts","sourceRoot":"","sources":["../src/plugin2.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,EAAE,gBAAgB,EAAkB,MAAM,sBAAsB,CAAC;AAiE7E;0FAC0F;AAC1F,wBAAsB,UAAU,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAsB7F"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface PrivateServe {
|
|
2
|
+
bin: string;
|
|
3
|
+
cwd: string;
|
|
4
|
+
env: Record<string, string>;
|
|
5
|
+
/** The port `serve` binds. */
|
|
6
|
+
port: string;
|
|
7
|
+
}
|
|
8
|
+
/** What a read is given: the server's URL, the authorization it takes, and a signal aborted once
|
|
9
|
+
* the read ends. */
|
|
10
|
+
export interface ServeRead {
|
|
11
|
+
url: string;
|
|
12
|
+
auth: string;
|
|
13
|
+
signal: AbortSignal;
|
|
14
|
+
}
|
|
15
|
+
/** Ask the OS for a free port (bind :0, read it, release) so co-located peers don't collide. */
|
|
16
|
+
export declare function freePort(): Promise<number>;
|
|
17
|
+
export declare function readPrivateServe<T>(o: PrivateServe, read: (serve: ServeRead) => Promise<T>): Promise<T>;
|
|
18
|
+
//# sourceMappingURL=private-serve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-serve.d.ts","sourceRoot":"","sources":["../src/private-serve.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd;AAED;qBACqB;AACrB,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,gGAAgG;AAChG,wBAAsB,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,CAOhD;AAgBD,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAsB7G"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Each OpenCode line's asks, read from its events and replied to over its HTTP API (prompts.ts holds
|
|
3
|
+
* the desk side). The shapes are the ones the servers emit: 1.x as `@opencode-ai/sdk`'s v2 types
|
|
4
|
+
* name them, 2.x as measured on 2.0.24.
|
|
5
|
+
*
|
|
6
|
+
* - 1.x: `permission.asked` is replied to on `POST /permission/:id/reply` with `once`, `always` or
|
|
7
|
+
* `reject`, and "always" allows its patterns for the rest of the OpenCode session. `question.asked`
|
|
8
|
+
* is replied to on `POST /question/:id/reply` with one list of chosen labels per question, or
|
|
9
|
+
* dismissed on `POST /question/:id/reject`.
|
|
10
|
+
* - 2.x: `permission.asked` is replied to on `POST /api/session/:sid/permission/:id/reply`, and
|
|
11
|
+
* "always" saves an allow rule for the project. A question is a form (`form.created`), replied to
|
|
12
|
+
* on `POST /api/session/:sid/form/:id/reply` with an answer per field key, or cancelled with
|
|
13
|
+
* `DELETE /api/session/:sid/form/:id`.
|
|
14
|
+
*
|
|
15
|
+
* A reject's note goes to OpenCode as its message, which OpenCode hands the model. A permission ask
|
|
16
|
+
* names the tool call it gates, and the plugin's `execute.before` hook, which OpenCode runs before the
|
|
17
|
+
* tool checks its permission, has handed that call over by then.
|
|
18
|
+
*/
|
|
19
|
+
import type { PromptDesk } from "@cotal-ai/connector-core";
|
|
20
|
+
/** Sends one request to OpenCode: true once OpenCode applied it, false when OpenCode answered that it
|
|
21
|
+
* does not hold the ask. */
|
|
22
|
+
export type Send = (path: string, init: RequestInit) => Promise<boolean>;
|
|
23
|
+
/** The asks one plugin serves: its own session's and those of the subagent sessions under it. */
|
|
24
|
+
export interface OpenCodeAsks {
|
|
25
|
+
/** Every event the plugin sees, by its type and payload. */
|
|
26
|
+
event(type: string, data: Record<string, unknown>): void;
|
|
27
|
+
/** A tool call started, from the plugin's `execute.before` hook. */
|
|
28
|
+
toolStarted(callID: string, call: ToolCallSeen): void;
|
|
29
|
+
/** The session's turn ended, so OpenCode waits on no ask of it any more. */
|
|
30
|
+
turnEnded(): void;
|
|
31
|
+
}
|
|
32
|
+
/** A started tool call. Its input is read when an ask names the call, so an input that a later
|
|
33
|
+
* `execute.before` hook repaired is the one shown. */
|
|
34
|
+
export interface ToolCallSeen {
|
|
35
|
+
name: string;
|
|
36
|
+
input(): unknown;
|
|
37
|
+
}
|
|
38
|
+
interface AsksOptions {
|
|
39
|
+
desk(): PromptDesk | undefined;
|
|
40
|
+
warn(msg: string): void;
|
|
41
|
+
send: Send;
|
|
42
|
+
/** The session the plugin drives now. */
|
|
43
|
+
session(): string | undefined;
|
|
44
|
+
}
|
|
45
|
+
export declare function opencode1Asks(opts: AsksOptions): OpenCodeAsks;
|
|
46
|
+
export declare function opencode2Asks(opts: AsksOptions): OpenCodeAsks;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=prompt-asks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-asks.d.ts","sourceRoot":"","sources":["../src/prompt-asks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,0BAA0B,CAAC;AAG1E;6BAC6B;AAC7B,MAAM,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AA4FzE,iGAAiG;AACjG,MAAM,WAAW,YAAY;IAC3B,4DAA4D;IAC5D,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzD,oEAAoE;IACpE,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IACtD,4EAA4E;IAC5E,SAAS,IAAI,IAAI,CAAC;CACnB;AAED;uDACuD;AACvD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,IAAI,OAAO,CAAC;CAClB;AAmBD,UAAU,WAAW;IACnB,IAAI,IAAI,UAAU,GAAG,SAAS,CAAC;IAC/B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,EAAE,IAAI,CAAC;IACX,yCAAyC;IACzC,OAAO,IAAI,MAAM,GAAG,SAAS,CAAC;CAC/B;AAgBD,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,YAAY,CAyB7D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,YAAY,CAyB7D"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode's permission asks and questions on the agent's prompt desk (SPEC 13.22), for both
|
|
3
|
+
* OpenCode lines.
|
|
4
|
+
*
|
|
5
|
+
* OpenCode raises an ask as an event, waits for a reply on its HTTP API, and announces every reply
|
|
6
|
+
* as an event, whoever gave it. So an ask opens a prompt, an accepted answer is a reply over that
|
|
7
|
+
* API, and the reply event of an ask nobody answered here closes its prompt as answered at the
|
|
8
|
+
* terminal. OpenCode's own dialog stays open meanwhile, the first reply wins, and the API refuses a
|
|
9
|
+
* reply to an ask it does not hold.
|
|
10
|
+
*
|
|
11
|
+
* The adapters build each ask from their line's event shapes; this module holds the desk side and
|
|
12
|
+
* the content both lines share.
|
|
13
|
+
*/
|
|
14
|
+
import { type PromptContent, type PromptEffect } from "@cotal-ai/core";
|
|
15
|
+
import type { PromptDesk, PromptVerdict } from "@cotal-ai/connector-core";
|
|
16
|
+
/** One ask OpenCode waits on. */
|
|
17
|
+
export interface OpenCodeAsk {
|
|
18
|
+
/** OpenCode's request id, which its reply event names. */
|
|
19
|
+
id: string;
|
|
20
|
+
content: PromptContent;
|
|
21
|
+
/** Hand the accepted answer to OpenCode: true once OpenCode applied it, false when it does not
|
|
22
|
+
* hold the ask. Any other failure throws. */
|
|
23
|
+
reply(verdict: PromptVerdict): Promise<boolean>;
|
|
24
|
+
}
|
|
25
|
+
export interface OpenCodePrompts {
|
|
26
|
+
/** OpenCode raised an ask. One the desk refuses stays with OpenCode's own dialog. */
|
|
27
|
+
asked(ask: OpenCodeAsk): void;
|
|
28
|
+
/** OpenCode announced the reply to an ask, with what the reply did. */
|
|
29
|
+
replied(id: string, effect: PromptEffect): void;
|
|
30
|
+
/** The turn ended, so OpenCode waits on no ask of it any more. */
|
|
31
|
+
turnEnded(): void;
|
|
32
|
+
}
|
|
33
|
+
export declare function createOpenCodePrompts(opts: {
|
|
34
|
+
desk(): PromptDesk | undefined;
|
|
35
|
+
warn(msg: string): void;
|
|
36
|
+
}): OpenCodePrompts;
|
|
37
|
+
/** What a permission ask carries, in either line's words. */
|
|
38
|
+
export interface PermissionAsk {
|
|
39
|
+
/** The permission asked for, such as `bash`, `shell`, `edit` or `read`. */
|
|
40
|
+
action: string;
|
|
41
|
+
/** What the call would touch: commands, paths or URLs. */
|
|
42
|
+
patterns: string[];
|
|
43
|
+
/** What "always" allows from then on, beside this call. */
|
|
44
|
+
always?: string;
|
|
45
|
+
toolCallId?: string;
|
|
46
|
+
/** The tool call the ask gates, as the plugin saw it start. */
|
|
47
|
+
tool?: {
|
|
48
|
+
name: string;
|
|
49
|
+
input: unknown;
|
|
50
|
+
};
|
|
51
|
+
/** The child session that asked, when it is not the agent's own. */
|
|
52
|
+
scope?: string;
|
|
53
|
+
}
|
|
54
|
+
/** The prompt for a permission ask. Its subject is the gated tool call; with no call seen, it is what
|
|
55
|
+
* the call would touch. A content over the desk's limit leaves the input out, or says how large the
|
|
56
|
+
* patterns are, and then offers only Reject: the desk lets nobody approve an input it cannot show. */
|
|
57
|
+
export declare function permissionContent(p: PermissionAsk): PromptContent;
|
|
58
|
+
/** One field of an OpenCode form, in 2.x's `Form.Field` shape. 1.x questions are read into it. */
|
|
59
|
+
export interface FormField {
|
|
60
|
+
key: string;
|
|
61
|
+
type: string;
|
|
62
|
+
title?: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
required?: boolean;
|
|
65
|
+
hidden?: boolean;
|
|
66
|
+
when?: unknown[];
|
|
67
|
+
format?: string;
|
|
68
|
+
minLength?: number;
|
|
69
|
+
maxLength?: number;
|
|
70
|
+
pattern?: string;
|
|
71
|
+
placeholder?: string;
|
|
72
|
+
default?: unknown;
|
|
73
|
+
options?: Array<{
|
|
74
|
+
value: string;
|
|
75
|
+
label: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
}>;
|
|
78
|
+
custom?: boolean;
|
|
79
|
+
minimum?: unknown;
|
|
80
|
+
maximum?: unknown;
|
|
81
|
+
minItems?: number;
|
|
82
|
+
maxItems?: number;
|
|
83
|
+
}
|
|
84
|
+
/** The prompt for a form or a question, or the reason the form profile cannot carry it. A field's
|
|
85
|
+
* listed choices are offered as a choice; typing an answer of one's own stays at the terminal. */
|
|
86
|
+
export declare function formContent(f: {
|
|
87
|
+
kind: "question" | "form";
|
|
88
|
+
title: string;
|
|
89
|
+
fields: FormField[];
|
|
90
|
+
toolCallId?: string;
|
|
91
|
+
scope?: string;
|
|
92
|
+
}): PromptContent | string;
|
|
93
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"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"}
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* "Reconnecting…" reads as immediate TUI status; the rest is the imperative.
|
|
8
8
|
*
|
|
9
9
|
* It is for the agent's own terminal only. Sent through the agent endpoint it cannot help: a broken
|
|
10
|
-
* link never delivers it, and on a working link it drops the connection its answer needs. So
|
|
11
|
-
*
|
|
10
|
+
* link never delivers it, and on a working link it drops the connection its answer needs. So both
|
|
11
|
+
* plugins leave it out of the endpoint's `commands` list and refuse it on `command`.
|
|
12
12
|
*/
|
|
13
13
|
export declare const RECONNECT_COMMAND: {
|
|
14
14
|
readonly name: "reconnect";
|
package/dist/serve.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{execFileSync as execFileSync2,spawn}from"node:child_process";import{
|
|
2
|
-
`}}function tryAcquireOnce({path,nonce,content}){if(publishAtomic(path,content)){let released=false;return{kind:"acquired",held:{nonce,release(){if(released)return;released=true;const found=readOwner(path);if(found?.owner?.nonce===nonce){try{unlinkSync2(path)}catch{}}}}}}const inspection=inspectLockSnapshot(path);if(inspection.state==="absent")return{kind:"retry"};if(inspection.state==="stale"){const reclaimer=reclaimStale(path,inspection.ino);return reclaimer?{kind:"reclaiming",owner:reclaimer}:{kind:"retry"}}return{kind:"held",owner:inspection.owner}}function reclaimPollMs(pollMs){return Math.min(pollMs,50)}function acquireLock(path,opts={}){const waitMs=opts.waitMs??3e5;const pollMs=opts.pollMs??200;const attempt=newAttempt(path,opts);const deadline=Date.now()+waitMs;let waiting=false;for(;;){const result=tryAcquireOnce(attempt);if(result.kind==="acquired")return result.held;if(result.kind==="retry")continue;const left=deadline-Date.now();if(left<=0)throw lockTimeoutError(path,opts,result.owner,waitMs);if(!waiting){waiting=true;opts.onWait?.()}sleepSync(Math.min(result.kind==="reclaiming"?reclaimPollMs(pollMs):pollMs,left))}}function lockTimeoutError(path,opts,owner,waitMs){return opts.onTimeout?.(owner)??new Error(`${opts.label??"a lock"} is held by a live process (pid ${owner.pid}) and did not release within ${Math.round(waitMs/1e3)}s - retry, or if it is wedged, remove ${path}`)}var OPENCODE_BOOT_TIMEOUT_MS=12e4;var OPENCODE_READINESS_TIMEOUT_MS=OPENCODE_BOOT_TIMEOUT_MS+5e3;function opencodeLine(raw,bin){const m=raw.match(/(?:^|v)(\d+)\.\d+/);const major=m?Number(m[1]):NaN;if(major===1||major===2)return major;throw new Error(`opencode connector: unsupported OpenCode version "${raw}" from ${bin}; this connector supports the 1.x (opencode-ai) and 2.x (@opencode/cli) lines. Install a supported OpenCode in place of ${bin}, for example with \`npm install -g opencode-ai\`, then try again`)}function resolveOpencodeBin(){const override=process.env.COTAL_OPENCODE_BIN?.trim()||process.env.COTAL_OPENCODE_RESOLVED_BIN?.trim();if(process.platform!=="win32")return located(override||"opencode");if(override)return override;for(const dir of(process.env.PATH??"").split(delimiter)){if(!dir)continue;for(const exe of[join(dir,"opencode.exe"),join(dir,"node_modules","opencode-ai","bin","opencode.exe")]){if(executableFile(exe))return resolve(exe)}}return"opencode"}var BIN=resolveOpencodeBin();function executableFile(file){try{accessSync(file,constants2.X_OK);return statSync2(file).isFile()}catch{return false}}function located(bin){if(bin.includes("/"))return bin;for(const dir of(process.env.PATH??"/usr/bin:/bin").split(delimiter)){const absoluteDir=isAbsolute(dir)?dir:dir?`${process.cwd()}/${dir}`:process.cwd();const file=`${absoluteDir}/${bin}`;if(executableFile(file))return file}return bin}var USERNAME="opencode";var SECRET=process.env.OPENCODE_SERVER_PASSWORD||randomBytes2(24).toString("hex");var RECORD_THEN_EXEC=`printf %s "$$" > "$1" && shift && exec "$@"`;async function
|
|
1
|
+
import{execFileSync as execFileSync2,spawn}from"node:child_process";import{once as once2}from"node:events";import{randomBytes as randomBytes2}from"node:crypto";import{accessSync,closeSync as closeSync2,constants as constants2,mkdirSync as mkdirSync3,readdirSync,readFileSync as readFileSync2,rmdirSync,rmSync as rmSync2,statSync as statSync2,writeFileSync as writeFileSync2}from"node:fs";import{delimiter,isAbsolute,join,resolve}from"node:path";import{StringDecoder}from"node:string_decoder";import{execFileSync}from"node:child_process";import{linkSync as linkSync2,mkdirSync as mkdirSync2,readFileSync,rmSync,statSync,unlinkSync as unlinkSync2}from"node:fs";import{randomBytes}from"node:crypto";import{dirname}from"node:path";import{chmodSync,closeSync,constants,fchmodSync,fstatSync,ftruncateSync,linkSync,lstatSync,mkdirSync,openSync,renameSync,unlinkSync,writeFileSync}from"node:fs";var isWin=process.platform==="win32";function notPrivate(path,why){const refused=new Error(`refusing to write "${path}": it ${why}; it was left unchanged`);refused.code="EPERM";return refused}function openPrivate(path,flags){if(isWin){const fd2=openSync(path,flags,384);try{fchmodSync(fd2,384)}catch(e){closeSync(fd2);throw e}return fd2}let fd;try{fd=openSync(path,flags|constants.O_NOFOLLOW|constants.O_NONBLOCK,384)}catch(e){if(e.code==="ELOOP")throw notPrivate(path,"is a symlink");throw e}try{const info=fstatSync(fd);if(!info.isFile())throw notPrivate(path,"is not a regular file");if(info.uid!==process.getuid())throw notPrivate(path,`is owned by uid ${info.uid}, not this user`);fchmodSync(fd,384);return fd}catch(e){closeSync(fd);throw e}}function openPrivateAppend(path){return openPrivate(path,constants.O_WRONLY|constants.O_CREAT|constants.O_APPEND)}function createPrivateRecord(path,data){writeBytes(path,data,true)}function writeBytes(path,data,exclusive){const fd=openPrivate(path,constants.O_WRONLY|constants.O_CREAT|(exclusive?constants.O_EXCL:0));try{try{ftruncateSync(fd);writeFileSync(fd,data)}finally{closeSync(fd)}}catch(e){if(exclusive){try{unlinkSync(path)}catch{}}throw e}}function processStatFields(pid){try{const stat=readFileSync(`/proc/${pid}/stat`,"utf8");const after=stat.lastIndexOf(") ");if(after<0||stat.slice(0,stat.indexOf(" "))!==String(pid))return void 0;return stat.slice(after+2).trim().split(/\s+/)}catch{return void 0}}function processStartToken(pid){if(process.platform==="win32")return void 0;if(process.platform==="linux")return processStatFields(pid)?.[19];try{const out=execFileSync("ps",["-o","lstart=","-p",String(pid)],{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim();return out||void 0}catch{return void 0}}function sleepSync(ms){Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,ms)}function pidAlive(pid){try{process.kill(pid,0);return true}catch(e){const code=e.code;if(code==="ESRCH")return false;if(code==="EPERM")return true;throw e}}function readOwner(path){let raw;try{raw=readFileSync(path,"utf8")}catch(e){const code=e.code;if(code==="ENOENT")return void 0;if(code==="EISDIR"||code==="EACCES"||code==="EPERM")throw new Error(`advisory lock path ${path} is unreadable (${code}) - remove the stray file or directory there and retry`);throw e}let ino;try{ino=statSync(path).ino}catch{}try{return{owner:JSON.parse(raw),ino}}catch{return{ino}}}function inspectLock(path){const inspection=inspectLockSnapshot(path);return inspection.state==="active"?{state:"active",owner:inspection.owner}:{state:inspection.state}}function inspectLockSnapshot(path){const found=readOwner(path);if(found===void 0)return{state:"absent"};const{owner,ino}=found;if(!owner||typeof owner.pid!=="number"||!Number.isInteger(owner.pid)||owner.pid<=0||typeof owner.nonce!=="string"){return{state:"stale",ino}}if(!pidAlive(owner.pid))return{state:"stale",ino};if(owner.start!==void 0){const fields=process.platform==="linux"?processStatFields(owner.pid):void 0;const now=process.platform==="linux"?fields?.[19]:processStartToken(owner.pid);if(now===owner.start&&fields?.[0]==="Z")return{state:"stale",ino};if(now!==void 0&&now!==owner.start)return{state:"stale",ino}}return{state:"active",owner,ino}}function publishAtomic(path,content){const tmp=`${path}.${randomBytes(8).toString("hex")}.tmp`;createPrivateRecord(tmp,content);try{linkSync2(tmp,path);return true}catch(e){if(e.code==="EEXIST")return false;throw e}finally{try{unlinkSync2(tmp)}catch{}}}function reclaimStale(path,inspectedIno){const sentinel=`${path}.reclaim`;const mine=JSON.stringify({pid:process.pid,start:processStartToken(process.pid),nonce:randomBytes(8).toString("hex"),ts:Date.now()});if(!publishAtomic(sentinel,mine)){const reclaimer=inspectLock(sentinel);if(reclaimer.state==="stale")throw new Error(`a lock reclaim was interrupted and its sentinel remains (${sentinel}) - if no cotal process is running, remove it and retry`);return reclaimer.state==="active"?reclaimer.owner:void 0}try{const inspection=inspectLockSnapshot(path);if(inspection.state!=="stale")return;if(inspectedIno!==void 0&&inspection.ino!==void 0&&inspection.ino!==inspectedIno)return;unlinkSync2(path)}catch(e){if(e.code!=="ENOENT")throw e}finally{try{unlinkSync2(sentinel)}catch{}}}function newAttempt(path,opts){mkdirSync2(dirname(path),{recursive:true,mode:448});const nonce=randomBytes(12).toString("hex");const owner={pid:process.pid,start:processStartToken(process.pid),nonce,ts:Date.now(),...opts.label?{label:opts.label}:{}};return{path,nonce,content:`${JSON.stringify(owner)}
|
|
2
|
+
`}}function tryAcquireOnce({path,nonce,content}){if(publishAtomic(path,content)){let released=false;return{kind:"acquired",held:{nonce,release(){if(released)return;released=true;const found=readOwner(path);if(found?.owner?.nonce===nonce){try{unlinkSync2(path)}catch{}}}}}}const inspection=inspectLockSnapshot(path);if(inspection.state==="absent")return{kind:"retry"};if(inspection.state==="stale"){const reclaimer=reclaimStale(path,inspection.ino);return reclaimer?{kind:"reclaiming",owner:reclaimer}:{kind:"retry"}}return{kind:"held",owner:inspection.owner}}function reclaimPollMs(pollMs){return Math.min(pollMs,50)}function acquireLock(path,opts={}){const waitMs=opts.waitMs??3e5;const pollMs=opts.pollMs??200;const attempt=newAttempt(path,opts);const deadline=Date.now()+waitMs;let waiting=false;for(;;){const result=tryAcquireOnce(attempt);if(result.kind==="acquired")return result.held;if(result.kind==="retry")continue;const left=deadline-Date.now();if(left<=0)throw lockTimeoutError(path,opts,result.owner,waitMs);if(!waiting){waiting=true;opts.onWait?.()}sleepSync(Math.min(result.kind==="reclaiming"?reclaimPollMs(pollMs):pollMs,left))}}function lockTimeoutError(path,opts,owner,waitMs){return opts.onTimeout?.(owner)??new Error(`${opts.label??"a lock"} is held by a live process (pid ${owner.pid}) and did not release within ${Math.round(waitMs/1e3)}s - retry, or if it is wedged, remove ${path}`)}var OPENCODE_BOOT_TIMEOUT_MS=12e4;var OPENCODE_READINESS_TIMEOUT_MS=OPENCODE_BOOT_TIMEOUT_MS+5e3;function opencodeLine(raw,bin){const m=raw.match(/(?:^|v)(\d+)\.\d+/);const major=m?Number(m[1]):NaN;if(major===1||major===2)return major;throw new Error(`opencode connector: unsupported OpenCode version "${raw}" from ${bin}; this connector supports the 1.x (opencode-ai) and 2.x (@opencode/cli) lines. Install a supported OpenCode in place of ${bin}, for example with \`npm install -g opencode-ai\`, then try again`)}import{once}from"node:events";import{createServer}from"node:net";async function freePort(){const srv=createServer();srv.listen(0,"127.0.0.1");await once(srv,"listening");const port=srv.address().port;await new Promise(r=>srv.close(()=>r()));return port}function resolveOpencodeBin(){const override=process.env.COTAL_OPENCODE_BIN?.trim()||process.env.COTAL_OPENCODE_RESOLVED_BIN?.trim();if(process.platform!=="win32")return located(override||"opencode");if(override)return override;for(const dir of(process.env.PATH??"").split(delimiter)){if(!dir)continue;for(const exe of[join(dir,"opencode.exe"),join(dir,"node_modules","opencode-ai","bin","opencode.exe")]){if(executableFile(exe))return resolve(exe)}}return"opencode"}var BIN=resolveOpencodeBin();function executableFile(file){try{accessSync(file,constants2.X_OK);return statSync2(file).isFile()}catch{return false}}function located(bin){if(bin.includes("/"))return bin;for(const dir of(process.env.PATH??"/usr/bin:/bin").split(delimiter)){const absoluteDir=isAbsolute(dir)?dir:dir?`${process.cwd()}/${dir}`:process.cwd();const file=`${absoluteDir}/${bin}`;if(executableFile(file))return file}return bin}var USERNAME="opencode";var SECRET=process.env.OPENCODE_SERVER_PASSWORD||randomBytes2(24).toString("hex");var RECORD_THEN_EXEC=`printf %s "$$" > "$1" && shift && exec "$@"`;async function terminate(child){if(child.exitCode!==null||child.signalCode!==null)return;child.kill("SIGTERM");const dead=await Promise.race([once2(child,"exit").then(()=>true),new Promise(r=>setTimeout(()=>r(false),3e3))]);if(!dead){child.kill("SIGKILL");await once2(child,"exit")}}function processCommand(pid){try{if(process.platform==="win32"){return execFileSync2("powershell.exe",["-NoProfile","-NonInteractive","-Command",`(Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}').CommandLine`],{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim()}return execFileSync2("ps",["-p",String(pid),"-o","command="],{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return void 0}}function pidAlive2(pid){try{process.kill(pid,0);return true}catch{return false}}function isLiveOpencodeServe(pid){if(!Number.isInteger(pid)||pid<=0||!pidAlive2(pid))return false;const cmd=processCommand(pid);if(!cmd)return pidAlive2(pid);return/\bserve\b/.test(cmd)&&(/(?:^|[\\/\s])opencode(?:\.exe)?(?:\s|$)/i.test(cmd)||/--hostname\s+127\.0\.0\.1\b/.test(cmd)&&/--port\s+\d+\b/.test(cmd))}async function launch(tuiArgv,serveEnv){const port=process.env.COTAL_OPENCODE_PORT?.trim()||String(await freePort());const url=`http://127.0.0.1:${port}`;const name=process.env.COTAL_NAME?.trim()||"agent";const dataRoot=process.env.COTAL_OPENCODE_HOME?.trim();if(!dataRoot)throw new Error("COTAL_OPENCODE_HOME is not set \u2014 the connector must pin the agent's data root");const agentHome=join(dataRoot,".cotal","opencode",name);const dbPath=join(agentHome,"opencode.db");const claim=acquireLock(join(agentHome,"launch.lock"),{waitMs:0,label:`agent "${name}"'s launch`,onTimeout:owner=>new Error(`agent "${name}" is already running (launcher pid ${owner.pid}) \u2014 kill it first`)});process.on("exit",()=>claim.release());let records=[];try{records=readdirSync(agentHome).filter(file=>/^serve(?:\.[0-9a-f]{32})?\.pid$/.test(file))}catch(e){if(e.code!=="ENOENT")throw e}for(const file of records){const record=join(agentHome,file);let recorded;try{try{recorded=readFileSync2(record,"utf8")}catch(e){if(e.code!=="EISDIR")throw e;rmdirSync(record)}}catch(e){if(e.code!=="ENOENT")throw e}if(recorded===void 0)continue;const pid=Number(recorded);if(isLiveOpencodeServe(pid))throw new Error(`agent "${name}" is already running (opencode serve pid ${pid}) \u2014 kill it first`);rmSync2(record,{force:true})}let versionRaw;try{versionRaw=execFileSync2(BIN,["--version"],{encoding:"utf8",stdio:["ignore","pipe","pipe"]}).trim()}catch(error){const stderr=String(error.stderr??"").trim();process.stderr.write(`[cotal-connector] OpenCode version probe failed${stderr?`: ${stderr.split(/\r?\n/).slice(-2).join(" | ")}`:""}
|
|
3
3
|
`);process.exit(1)}const line=opencodeLine(versionRaw,BIN);mkdirSync3(agentHome,{recursive:true});const launchToken=randomBytes2(16).toString("hex");const pidFile=join(agentHome,`serve.${launchToken}.pid`);const bootLog=join(agentHome,`boot.${launchToken}.log`);const bootFd=openPrivateAppend(bootLog);process.on("exit",()=>closeSync2(bootFd));const bootOutput=d=>{writeFileSync2(bootFd,d);process.stderr.write(d)};bootOutput(`OpenCode boot log: ${bootLog}
|
|
4
4
|
`);const serveArgv=[BIN,"serve","--hostname","127.0.0.1","--port",port];const[serveCommand,...serveArgs]=process.platform==="win32"?serveArgv:["/bin/sh","-c",RECORD_THEN_EXEC,"cotal-serve",pidFile,...serveArgv];const serve=spawn(serveCommand,serveArgs,{env:{...process.env,...serveEnv?.(agentHome),COTAL_OPENCODE_SERVER_URL:url,COTAL_OPENCODE_LINE:String(line),OPENCODE_SERVER_USERNAME:USERNAME,OPENCODE_SERVER_PASSWORD:SECRET,OPENCODE_DB:dbPath},stdio:["ignore","pipe","pipe"]});if(process.platform==="win32")writeFileSync2(pidFile,String(serve.pid));serve.on("exit",()=>rmSync2(pidFile,{force:true}));let tui;let stopping=false;for(const sig of["SIGINT","SIGTERM"])process.on(sig,()=>{stopping=true;void terminate(serve);if(tui)void terminate(tui)});let sessionId;let attached=false;let onSession;let connectorLine;let lastOutput="";const scanner=()=>{const decoder=new StringDecoder("utf8");let partial="";return d=>{if(!attached){lastOutput=(lastOutput+d.toString()).slice(-4e3);bootOutput(d)}if(sessionId)return;const lines=(partial+decoder.write(d)).split("\n");partial=lines.pop()??"";for(const line2 of lines){const session=/\[cotal-session\] (\S+)/.exec(line2);if(session){sessionId=session[1];connectorLine=void 0;onSession?.(sessionId);return}const message=/^\[cotal-connector\] (.+)$/.exec(line2.trimEnd());if(message)connectorLine=message[1]}}};serve.stdout?.on("data",scanner());serve.stderr?.on("data",scanner());let bootFailed=false;serve.on("close",(code,signal)=>{if(!attached){if(!bootFailed&&!stopping)bootOutput(`[cotal-connector] OpenCode exited before its Cotal session was ready (code ${code??signal}); boot log: ${bootLog}. `+(connectorLine?`Last connector message: ${connectorLine}. `:"")+(lastOutput.trim()?`Last output: ${lastOutput.trim().split(/\r?\n/).slice(-2).join(" | ")}
|
|
5
5
|
`:"\n"));process.exit(bootFailed?1:code||(signal||!sessionId&&!stopping?1:0))}});const auth=`Basic ${Buffer.from(`${USERNAME}:${SECRET}`).toString("base64")}`;const pokePath=line===2?"/api/config":"/session";const bootDeadline=Date.now()+OPENCODE_BOOT_TIMEOUT_MS;void(async()=>{while(Date.now()<bootDeadline&&!sessionId&&!bootFailed&&!stopping){try{await fetch(`${url}${pokePath}`,{headers:{authorization:auth},signal:AbortSignal.timeout(1500)})}catch{}await new Promise(r=>setTimeout(r,200))}})();const id=await new Promise(resolve2=>{if(sessionId)return resolve2(sessionId);const timer=setTimeout(()=>resolve2(sessionId),Math.max(0,bootDeadline-Date.now()));onSession=id2=>{clearTimeout(timer);resolve2(id2)}});if(!id){bootFailed=true;bootOutput(`[cotal-connector] OpenCode session not ready after ${OPENCODE_BOOT_TIMEOUT_MS/1e3}s: first-run dependencies or plugin/mesh setup did not finish. Check the retained boot log, then launch again.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads an OpenCode 2.x server's model list once the server's plugins have loaded, and returns the
|
|
3
|
+
* reply's `data`. Until then `GET /api/model` answers 200 with an empty or partial list (measured on
|
|
4
|
+
* 2.4.1: nothing, then one provider's models, then every model at the moment `GET /api/plugin` first
|
|
5
|
+
* lists anything). OpenCode's own `opencode models` waits the same way. The plugin list includes
|
|
6
|
+
* OpenCode's built-in plugins, so it fills on every install. Throws when either route answers
|
|
7
|
+
* anything but a 200 list, or when the wait outlasts `timeoutMs`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readSettledModels(serverUrl: string, authorization: string, timeoutMs: number): Promise<unknown[]>;
|
|
10
|
+
//# sourceMappingURL=settled-models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settled-models.d.ts","sourceRoot":"","sources":["../src/settled-models.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CA0BvH"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode 1.x's live text and reasoning, journaled so a reply streams on the event plane before
|
|
3
|
+
* OpenCode saves it. OpenCode creates a text or reasoning part empty, sends its text as
|
|
4
|
+
* `message.part.delta` events, and then saves it whole with an end mark (measured on 1.19.6), so
|
|
5
|
+
* each part streams under a key of its own id and its own saved record closes the stream.
|
|
6
|
+
*
|
|
7
|
+
* **A line is anchored at the start of the streaming part's message**, the `<message>:<message>`
|
|
8
|
+
* position the source also gives a failed message's stand-in record. The session store holds the
|
|
9
|
+
* part from its first delta, so the store's end would place every line after the part, where its
|
|
10
|
+
* saved record has already closed the stream. The merged source places a line before the first
|
|
11
|
+
* record after its anchor, or where its read starts when it has read past it, so the text arrives
|
|
12
|
+
* after whatever of the message is already published and before the part's saved record.
|
|
13
|
+
*/
|
|
14
|
+
import { type DeltaJournalOptions } from "@cotal-ai/connector-core";
|
|
15
|
+
/** The key a part streams under. It differs from the part id, which a part mapped whole is published
|
|
16
|
+
* under. */
|
|
17
|
+
export declare const streamKey1: (partId: string) => string;
|
|
18
|
+
export declare class OpenCode1DeltaStream {
|
|
19
|
+
private readonly reasoning;
|
|
20
|
+
private journal;
|
|
21
|
+
private sessionID;
|
|
22
|
+
/** Text and reasoning parts created while the journal was open and not saved yet: their kind and
|
|
23
|
+
* the start of their message. A part created earlier never streams, so no stream opens partway
|
|
24
|
+
* through its text. */
|
|
25
|
+
private readonly parts;
|
|
26
|
+
/** The parts with text in the journal that OpenCode has not saved: their anchors. */
|
|
27
|
+
private readonly streaming;
|
|
28
|
+
/** The parts streamed this turn, ended at the turn's end. */
|
|
29
|
+
private readonly turn;
|
|
30
|
+
/** The session's end while the turn's end is journaled. */
|
|
31
|
+
private endedAt;
|
|
32
|
+
/** @param reasoning Whether reasoning is published, and so streamed. */
|
|
33
|
+
constructor(reasoning: boolean);
|
|
34
|
+
/** Journal the session's parts from now on, once. A written line should wake the emitter. */
|
|
35
|
+
open(sessionID: string, opts: Omit<DeltaJournalOptions, "anchor">): void;
|
|
36
|
+
/** Follow one bus event. */
|
|
37
|
+
event(type: string, properties: unknown): void;
|
|
38
|
+
/**
|
|
39
|
+
* The turn ended with the session at `end`: end every part it streamed there, before the run
|
|
40
|
+
* closes, because a run cannot close while a streamed message is open. Anchored at the session's
|
|
41
|
+
* end, the line follows every saved part of the turn, and the reader leaves alone a part its saved
|
|
42
|
+
* record closed.
|
|
43
|
+
*/
|
|
44
|
+
turnEnded(end: string): void;
|
|
45
|
+
close(): void;
|
|
46
|
+
private anchor;
|
|
47
|
+
private part;
|
|
48
|
+
private delta;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=stream1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream1.d.ts","sourceRoot":"","sources":["../src/stream1.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAgB,KAAK,mBAAmB,EAAoB,MAAM,0BAA0B,CAAC;AAGpG;aACa;AACb,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,KAAG,MAA4B,CAAC;AAYzE,qBAAa,oBAAoB;IAenB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAdtC,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,SAAS,CAAqB;IACtC;;4BAEwB;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoE;IAC1F,qFAAqF;IACrF,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA6B;IACvD,6DAA6D;IAC7D,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;IAC1C,2DAA2D;IAC3D,OAAO,CAAC,OAAO,CAAqB;IAEpC,wEAAwE;gBAC3C,SAAS,EAAE,OAAO;IAE/C,6FAA6F;IAC7F,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,GAAG,IAAI;IAMxE,4BAA4B;IAC5B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,IAAI;IAK9C;;;;;OAKG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAc5B,KAAK,IAAI,IAAI;IAKb,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,IAAI;IAYZ,OAAO,CAAC,KAAK;CAQd"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode 2.x's live text and reasoning, journaled so a reply streams on the event plane before the
|
|
3
|
+
* step's message list carries it. 2.x keeps a streaming element empty in that list until its step
|
|
4
|
+
* ends, and sends its text as `session.text.delta` and `session.reasoning.delta` events, each naming
|
|
5
|
+
* the step's message and the element's ordinal among the message's elements of its kind (measured on
|
|
6
|
+
* 2.0.24). So an element streams under a key of its message, kind and ordinal, and the mapper finds
|
|
7
|
+
* the same key from the element's position when its saved record arrives.
|
|
8
|
+
*
|
|
9
|
+
* **A line is anchored at the session's last record before the step's message.** The step's message
|
|
10
|
+
* is in the list, unsettled, from its first element, so a position inside it would hold every line
|
|
11
|
+
* until the step ends. That record is read when the step starts; until it answers, a line takes the
|
|
12
|
+
* furthest position a read of the session has reached, which is never past it. Either way the
|
|
13
|
+
* records before the step come before the line and the step's saved elements after it.
|
|
14
|
+
*/
|
|
15
|
+
import { type DeltaJournalOptions, type StreamDelta } from "@cotal-ai/connector-core";
|
|
16
|
+
/** The key the element of `kind` at `ordinal` among a message's elements of that kind streams under.
|
|
17
|
+
* It differs from the `<message>#<index>` id an element mapped whole is published under. */
|
|
18
|
+
export declare const streamKey2: (messageId: string, kind: StreamDelta["kind"], ordinal: number) => string;
|
|
19
|
+
/** The fields of a 2.x event this stream reads. */
|
|
20
|
+
export interface StreamEvent2 {
|
|
21
|
+
type: string;
|
|
22
|
+
created?: number;
|
|
23
|
+
data?: {
|
|
24
|
+
sessionID?: unknown;
|
|
25
|
+
assistantMessageID?: unknown;
|
|
26
|
+
ordinal?: unknown;
|
|
27
|
+
delta?: unknown;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** What the stream reads of the session's source: the furthest position a read has reached, read
|
|
31
|
+
* synchronously, and the session's last record before a message. */
|
|
32
|
+
interface StreamSource2 {
|
|
33
|
+
readonly reached: string;
|
|
34
|
+
before(messageId: string): Promise<string>;
|
|
35
|
+
}
|
|
36
|
+
export declare class OpenCode2DeltaStream {
|
|
37
|
+
private readonly reasoning;
|
|
38
|
+
private journal;
|
|
39
|
+
private sessionID;
|
|
40
|
+
private openedAt;
|
|
41
|
+
/** Elements that started while the journal was open: their keys. One that started earlier, or
|
|
42
|
+
* whose start is a replay, never streams, so no stream opens partway through its text. */
|
|
43
|
+
private readonly started;
|
|
44
|
+
/** The elements streamed this turn, ended at the turn's end. */
|
|
45
|
+
private readonly turn;
|
|
46
|
+
/** The session's end while the turn's end is journaled. */
|
|
47
|
+
private endedAt;
|
|
48
|
+
/** The running step's message, and the session's last record before it once that is read. */
|
|
49
|
+
private step;
|
|
50
|
+
private session;
|
|
51
|
+
private onError;
|
|
52
|
+
/** @param reasoning Whether reasoning is published, and so streamed. */
|
|
53
|
+
constructor(reasoning: boolean);
|
|
54
|
+
/** Journal the elements of the session `source` reads from now on, once. A written line should
|
|
55
|
+
* wake the emitter. */
|
|
56
|
+
open(sessionID: string, source: StreamSource2, opts: Omit<DeltaJournalOptions, "anchor">): void;
|
|
57
|
+
/** Follow one event of the session's event stream. */
|
|
58
|
+
event(ev: StreamEvent2): void;
|
|
59
|
+
/**
|
|
60
|
+
* The turn ended with the session at `end`: end every element it streamed there, before the run
|
|
61
|
+
* closes, because a run cannot close while a streamed message is open. Anchored at the session's
|
|
62
|
+
* end, the line follows every saved element of the turn, and the reader leaves alone an element its
|
|
63
|
+
* saved record closed.
|
|
64
|
+
*/
|
|
65
|
+
turnEnded(end: string): void;
|
|
66
|
+
close(): void;
|
|
67
|
+
private stepStarted;
|
|
68
|
+
}
|
|
69
|
+
export {};
|
|
70
|
+
//# sourceMappingURL=stream2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream2.d.ts","sourceRoot":"","sources":["../src/stream2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAgB,KAAK,mBAAmB,EAAE,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEpG;6FAC6F;AAC7F,eAAO,MAAM,UAAU,GAAI,WAAW,MAAM,EAAE,MAAM,WAAW,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,KAAG,MAAkD,CAAC;AAE9I,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAClG;AAED;qEACqE;AACrE,UAAU,aAAa;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5C;AASD,qBAAa,oBAAoB;IAiBnB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAhBtC,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,QAAQ,CAAY;IAC5B;+FAC2F;IAC3F,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,gEAAgE;IAChE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;IAC1C,2DAA2D;IAC3D,OAAO,CAAC,OAAO,CAAqB;IACpC,6FAA6F;IAC7F,OAAO,CAAC,IAAI,CAAmD;IAC/D,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,OAAO,CAAoC;IAEnD,wEAAwE;gBAC3C,SAAS,EAAE,OAAO;IAE/C;4BACwB;IACxB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,GAAG,IAAI;IAS/F,sDAAsD;IACtD,KAAK,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI;IAuB7B;;;;;OAKG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAa5B,KAAK,IAAI,IAAI;IAKb,OAAO,CAAC,WAAW;CAYpB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cotal-ai/connector-opencode",
|
|
3
3
|
"description": "Cotal connector for OpenCode: a native in-process plugin that joins a session to the mesh.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.179.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"@cotal-ai/core": ">=0.1.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@cotal-ai/auth": "0.
|
|
25
|
-
"@cotal-ai/connector-core": "0.
|
|
26
|
-
"@cotal-ai/core": "0.
|
|
24
|
+
"@cotal-ai/auth": "0.179.0",
|
|
25
|
+
"@cotal-ai/connector-core": "0.179.0",
|
|
26
|
+
"@cotal-ai/core": "0.179.0",
|
|
27
27
|
"@cotal-ai/smoke-kit": "0.0.0",
|
|
28
28
|
"@nats-io/transport-node": "3.4.0",
|
|
29
29
|
"@opencode-ai/plugin": "^1.16.2",
|