@amends-dev/harness-opencode 0.0.0-stage → 0.1.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.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/Opencode2Agent.d.ts +105 -0
  3. package/Opencode2Agent.d.ts.map +1 -0
  4. package/Opencode2Agent.js +72 -0
  5. package/Opencode2Agent.js.map +1 -0
  6. package/OpencodeAgent.d.ts +110 -0
  7. package/OpencodeAgent.d.ts.map +1 -0
  8. package/OpencodeAgent.js +83 -0
  9. package/OpencodeAgent.js.map +1 -0
  10. package/README.md +221 -2
  11. package/index.d.ts +18 -0
  12. package/index.d.ts.map +1 -0
  13. package/index.js +19 -0
  14. package/index.js.map +1 -0
  15. package/internal/agent.d.ts +29 -0
  16. package/internal/agent.d.ts.map +1 -0
  17. package/internal/agent.js +34 -0
  18. package/internal/agent.js.map +1 -0
  19. package/internal/bridge/bunBridge.d.ts +33 -0
  20. package/internal/bridge/bunBridge.d.ts.map +1 -0
  21. package/internal/bridge/bunBridge.js +62 -0
  22. package/internal/bridge/bunBridge.js.map +1 -0
  23. package/internal/bridge/driver.d.ts +81 -0
  24. package/internal/bridge/driver.d.ts.map +1 -0
  25. package/internal/bridge/driver.js +82 -0
  26. package/internal/bridge/driver.js.map +1 -0
  27. package/internal/bridge/hostTools.d.ts +28 -0
  28. package/internal/bridge/hostTools.d.ts.map +1 -0
  29. package/internal/bridge/hostTools.js +41 -0
  30. package/internal/bridge/hostTools.js.map +1 -0
  31. package/internal/bridge/server.d.ts +64 -0
  32. package/internal/bridge/server.d.ts.map +1 -0
  33. package/internal/bridge/server.js +129 -0
  34. package/internal/bridge/server.js.map +1 -0
  35. package/internal/bridge/steps.d.ts +29 -0
  36. package/internal/bridge/steps.d.ts.map +1 -0
  37. package/internal/bridge/steps.js +42 -0
  38. package/internal/bridge/steps.js.map +1 -0
  39. package/internal/bridge/v1/api.d.ts +181 -0
  40. package/internal/bridge/v1/api.d.ts.map +1 -0
  41. package/internal/bridge/v1/api.js +83 -0
  42. package/internal/bridge/v1/api.js.map +1 -0
  43. package/internal/bridge/v1/event.d.ts +597 -0
  44. package/internal/bridge/v1/event.d.ts.map +1 -0
  45. package/internal/bridge/v1/event.js +186 -0
  46. package/internal/bridge/v1/event.js.map +1 -0
  47. package/internal/bridge/v1/main.d.ts +6 -0
  48. package/internal/bridge/v1/main.d.ts.map +1 -0
  49. package/internal/bridge/v1/main.js +8 -0
  50. package/internal/bridge/v1/main.js.map +1 -0
  51. package/internal/bridge/v1/prompt.d.ts +18 -0
  52. package/internal/bridge/v1/prompt.d.ts.map +1 -0
  53. package/internal/bridge/v1/prompt.js +92 -0
  54. package/internal/bridge/v1/prompt.js.map +1 -0
  55. package/internal/bridge/v1/session.d.ts +28 -0
  56. package/internal/bridge/v1/session.d.ts.map +1 -0
  57. package/internal/bridge/v1/session.js +188 -0
  58. package/internal/bridge/v1/session.js.map +1 -0
  59. package/internal/bridge/v1/turn.d.ts +82 -0
  60. package/internal/bridge/v1/turn.d.ts.map +1 -0
  61. package/internal/bridge/v1/turn.js +304 -0
  62. package/internal/bridge/v1/turn.js.map +1 -0
  63. package/internal/bridge/v2/api.d.ts +86 -0
  64. package/internal/bridge/v2/api.d.ts.map +1 -0
  65. package/internal/bridge/v2/api.js +105 -0
  66. package/internal/bridge/v2/api.js.map +1 -0
  67. package/internal/bridge/v2/event.d.ts +539 -0
  68. package/internal/bridge/v2/event.d.ts.map +1 -0
  69. package/internal/bridge/v2/event.js +164 -0
  70. package/internal/bridge/v2/event.js.map +1 -0
  71. package/internal/bridge/v2/main.d.ts +6 -0
  72. package/internal/bridge/v2/main.d.ts.map +1 -0
  73. package/internal/bridge/v2/main.js +8 -0
  74. package/internal/bridge/v2/main.js.map +1 -0
  75. package/internal/bridge/v2/prompt.d.ts +109 -0
  76. package/internal/bridge/v2/prompt.d.ts.map +1 -0
  77. package/internal/bridge/v2/prompt.js +209 -0
  78. package/internal/bridge/v2/prompt.js.map +1 -0
  79. package/internal/bridge/v2/session.d.ts +21 -0
  80. package/internal/bridge/v2/session.d.ts.map +1 -0
  81. package/internal/bridge/v2/session.js +198 -0
  82. package/internal/bridge/v2/session.js.map +1 -0
  83. package/internal/bridge/v2/turn.d.ts +62 -0
  84. package/internal/bridge/v2/turn.d.ts.map +1 -0
  85. package/internal/bridge/v2/turn.js +277 -0
  86. package/internal/bridge/v2/turn.js.map +1 -0
  87. package/internal/models.d.ts +47 -0
  88. package/internal/models.d.ts.map +1 -0
  89. package/internal/models.js +170 -0
  90. package/internal/models.js.map +1 -0
  91. package/internal/template.d.ts +46 -0
  92. package/internal/template.d.ts.map +1 -0
  93. package/internal/template.js +267 -0
  94. package/internal/template.js.map +1 -0
  95. package/package.json +39 -4
@@ -0,0 +1,164 @@
1
+ /**
2
+ * The events opencode 2 publishes for a session as it works, which the driver reads to stream a
3
+ * turn: the session's executions, the steps of each, the text, reasoning, and tool calls of each
4
+ * step, compactions, and the permissions its tools ask and the forms its model asks the user to
5
+ * fill. opencode publishes every event of the server on one stream, live only: the deltas of text,
6
+ * reasoning, and tool input as they come, and the whole of each when it ends.
7
+ *
8
+ * The schemas are opencode 2.0's, with only the fields this adapter reads, so that fields opencode
9
+ * adds do not stop an event from decoding.
10
+ */
11
+ import * as Schema from "effect/Schema";
12
+ import { ModelRef } from "../driver.js";
13
+ import { Tokens } from "../steps.js";
14
+ /** An error opencode reports, as its sessions record it. */
15
+ export const SessionError = Schema.Struct({ type: Schema.String, message: Schema.String });
16
+ /** What a tool returned to the model: text, or a file. */
17
+ export const ToolContent = Schema.Union([
18
+ Schema.Struct({ type: Schema.tag("text"), text: Schema.String }),
19
+ Schema.Struct({
20
+ type: Schema.tag("file"),
21
+ uri: Schema.String,
22
+ mime: Schema.String,
23
+ name: Schema.optionalKey(Schema.String)
24
+ })
25
+ ]);
26
+ /** An event of the session `sessionID`, of the type `type`, with `data` besides its session's id. */
27
+ const sessionEvent = (type, fields) => Schema.Struct({
28
+ type: Schema.tag(type),
29
+ data: Schema.Struct({ sessionID: Schema.String, ...fields })
30
+ });
31
+ /** Of the step that the assistant message `assistantMessageID` records. */
32
+ const inStep = { assistantMessageID: Schema.String };
33
+ /** Of the text or reasoning numbered `ordinal` in its step. */
34
+ const ordinal = { ...inStep, ordinal: Schema.Int };
35
+ /** Of the tool call `id`. */
36
+ const inCall = { ...inStep, id: Schema.String };
37
+ /** opencode started running the session: a prompt it took, and what follows until it is idle. */
38
+ export const ExecutionStarted = sessionEvent("session.execution.started", {});
39
+ /** opencode ran the session until it had nothing more to do. */
40
+ export const ExecutionSucceeded = sessionEvent("session.execution.succeeded", {});
41
+ export const ExecutionFailed = sessionEvent("session.execution.failed", { error: SessionError });
42
+ /** opencode stopped running the session, `reason` saying why. */
43
+ export const ExecutionInterrupted = sessionEvent("session.execution.interrupted", {
44
+ reason: Schema.String
45
+ });
46
+ /** The session started work on the input `inboxID`, such as a prompt. */
47
+ export const InboxDelivered = sessionEvent("session.inbox.delivered", {
48
+ inboxID: Schema.String
49
+ });
50
+ /** A step started: one response of `model`, which the assistant message records. */
51
+ export const StepStarted = sessionEvent("session.step.started", {
52
+ ...inStep,
53
+ model: ModelRef,
54
+ /** When opencode sent the request, in milliseconds since the epoch. */
55
+ started: Schema.Finite
56
+ });
57
+ /** A step ended, `finish` saying why. */
58
+ export const StepEnded = sessionEvent("session.step.ended", {
59
+ ...inStep,
60
+ finish: Schema.String,
61
+ tokens: Tokens
62
+ });
63
+ /** A step failed, ending the session's execution. */
64
+ export const StepFailed = sessionEvent("session.step.failed", { ...inStep, error: SessionError });
65
+ export const TextStarted = sessionEvent("session.text.started", ordinal);
66
+ export const TextDelta = sessionEvent("session.text.delta", { ...ordinal, delta: Schema.String });
67
+ /** A text of the step ended, with the whole text. */
68
+ export const TextEnded = sessionEvent("session.text.ended", { ...ordinal, text: Schema.String });
69
+ export const ReasoningStarted = sessionEvent("session.reasoning.started", ordinal);
70
+ export const ReasoningDelta = sessionEvent("session.reasoning.delta", {
71
+ ...ordinal,
72
+ delta: Schema.String
73
+ });
74
+ /** A reasoning of the step ended, with the whole reasoning. */
75
+ export const ReasoningEnded = sessionEvent("session.reasoning.ended", {
76
+ ...ordinal,
77
+ text: Schema.String
78
+ });
79
+ /** The model started writing the input of a call to the tool `name`. */
80
+ export const ToolInputStarted = sessionEvent("session.tool.input.started", {
81
+ ...inCall,
82
+ name: Schema.String
83
+ });
84
+ export const ToolInputDelta = sessionEvent("session.tool.input.delta", {
85
+ ...inCall,
86
+ delta: Schema.String
87
+ });
88
+ /** The model finished writing a call's input, with the whole input as JSON text. */
89
+ export const ToolInputEnded = sessionEvent("session.tool.input.ended", {
90
+ ...inCall,
91
+ text: Schema.String
92
+ });
93
+ /** The model called a tool with `input`, which opencode runs. */
94
+ export const ToolCalled = sessionEvent("session.tool.called", {
95
+ ...inCall,
96
+ input: Schema.Record(Schema.String, Schema.Unknown)
97
+ });
98
+ /**
99
+ * A call succeeded: `content` is what the model reads, and `metadata` what the tool reported
100
+ * besides, such as the files an edit changed.
101
+ */
102
+ export const ToolSucceeded = sessionEvent("session.tool.success", {
103
+ ...inCall,
104
+ content: Schema.Array(ToolContent),
105
+ metadata: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown))
106
+ });
107
+ export const ToolFailed = sessionEvent("session.tool.failed", { ...inCall, error: SessionError });
108
+ /** The session replaced its conversation so far with the summary `text`. */
109
+ export const CompactionEnded = sessionEvent("session.compaction.ended", {
110
+ reason: Schema.Literals(["auto", "manual"]),
111
+ text: Schema.String
112
+ });
113
+ export const CompactionFailed = sessionEvent("session.compaction.failed", {
114
+ reason: Schema.Literals(["auto", "manual"]),
115
+ error: SessionError
116
+ });
117
+ /**
118
+ * A tool asks permission to act on `resources`, waiting for a reply to the request `id`. `source`
119
+ * names the call that asks.
120
+ */
121
+ export const PermissionAsked = Schema.Struct({
122
+ type: Schema.tag("permission.asked"),
123
+ data: Schema.Struct({
124
+ id: Schema.String,
125
+ sessionID: Schema.String,
126
+ source: Schema.optionalKey(Schema.Struct({ id: Schema.String }))
127
+ })
128
+ });
129
+ /** The model asks the user to fill the form `id`, waiting for an answer. */
130
+ export const FormCreated = Schema.Struct({
131
+ type: Schema.tag("form.created"),
132
+ data: Schema.Struct({
133
+ form: Schema.Struct({ id: Schema.String, sessionID: Schema.String })
134
+ })
135
+ });
136
+ export const SessionEvent = Schema.Union([
137
+ ExecutionStarted,
138
+ ExecutionSucceeded,
139
+ ExecutionFailed,
140
+ ExecutionInterrupted,
141
+ InboxDelivered,
142
+ StepStarted,
143
+ StepEnded,
144
+ StepFailed,
145
+ TextStarted,
146
+ TextDelta,
147
+ TextEnded,
148
+ ReasoningStarted,
149
+ ReasoningDelta,
150
+ ReasoningEnded,
151
+ ToolInputStarted,
152
+ ToolInputDelta,
153
+ ToolInputEnded,
154
+ ToolCalled,
155
+ ToolSucceeded,
156
+ ToolFailed,
157
+ CompactionEnded,
158
+ CompactionFailed,
159
+ PermissionAsked,
160
+ FormCreated
161
+ ]).pipe(Schema.toTaggedUnion("type"));
162
+ /** The session an event is of. */
163
+ export const sessionIdOf = (event) => event.type === "form.created" ? event.data.form.sessionID : event.data.sessionID;
164
+ //# sourceMappingURL=event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.js","sourceRoot":"","sources":["../../../../src/internal/bridge/v2/event.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;AAI1F,0DAA0D;AAC1D,MAAM,CAAC,MAAM,WAAW,GAAG,MA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,EAAE,CAAC;KACrE,CAAC;CACH,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC;IACvC,gBAAgB;IAChB,kBAAkB;IAClB,eAAe;IACf,oBAAoB;IACpB,cAAc;IACd,WAAW;IACX,SAAS;IACT,UAAU;IACV,WAAW;IACX,SAAS;IACT,SAAS;IACT,gBAAgB;IAChB,cAAc;IACd,cAAc;IACd,gBAAgB;IAChB,cAAc;IACd,cAAc;IACd,UAAU;IACV,aAAa;IACb,UAAU;IACV,eAAe;IACf,gBAAgB;IAChB,eAAe;IACf,WAAW;CACZ,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAA;AAIrC,kCAAkC;AAClC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAmB,EAAE,EAAE,CACjD,KAAK,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAA"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The bridge program of the opencode 2 agent, which a host launches in its sandbox, over opencode
3
+ * 2's session API, as `BunBridge.runProgram` runs it.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../../src/internal/bridge/v2/main.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The bridge program of the opencode 2 agent, which a host launches in its sandbox, over opencode
3
+ * 2's session API, as `BunBridge.runProgram` runs it.
4
+ */
5
+ import * as BunBridge from "../bunBridge.js";
6
+ import { makeCreateSession } from "./session.js";
7
+ BunBridge.runProgram("opencode2", import.meta.dirname, makeCreateSession);
8
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/internal/bridge/v2/main.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,SAAS,CAAC,UAAU,CAAC,WAAW,EAAE,OAAO,IAAI,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAA"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * What opencode 2 is prompted with: a turn's prompt, and a conversation started on another agent,
3
+ * written as the messages opencode records for a session so that it goes on in opencode as its
4
+ * own. Each user message is a prompt, each system message an update of the model's instructions,
5
+ * and each assistant message a step, its tool calls with the results of the tool messages after
6
+ * it. The tools need not be opencode's own. The steps name the model `amends/history`, because a
7
+ * conversation does not say which model answered; opencode reads them whichever model they name.
8
+ *
9
+ * opencode 2 takes files as data, so a file given at a URL other than a `data:` or `file:` URL
10
+ * fails with `UnsupportedError`.
11
+ */
12
+ import { HarnessError } from "@amends-dev/harness";
13
+ import type * as Prompt from "effect/ai/Prompt";
14
+ import * as Result from "effect/Result";
15
+ import type { ModelRef } from "../driver.ts";
16
+ import { ToolContent } from "./event.ts";
17
+ /** A prompt as opencode 2 takes it: its text, and its files by URL. */
18
+ export interface PromptInput {
19
+ readonly text: string;
20
+ readonly files?: ReadonlyArray<{
21
+ readonly uri: string;
22
+ readonly name?: string;
23
+ }>;
24
+ }
25
+ /** A file of a recorded prompt, its data in base64. */
26
+ interface RecordedFile {
27
+ readonly data: string;
28
+ readonly mime: string;
29
+ readonly source: {
30
+ readonly type: "inline";
31
+ };
32
+ readonly name?: string;
33
+ }
34
+ type ToolState = {
35
+ readonly status: "completed";
36
+ readonly input: Record<string, unknown>;
37
+ readonly content: ReadonlyArray<ToolContent>;
38
+ } | {
39
+ readonly status: "error";
40
+ readonly input: Record<string, unknown>;
41
+ readonly error: {
42
+ readonly type: string;
43
+ readonly message: string;
44
+ };
45
+ };
46
+ type AssistantContent = {
47
+ readonly type: "text";
48
+ readonly text: string;
49
+ } | {
50
+ readonly type: "reasoning";
51
+ readonly text: string;
52
+ } | {
53
+ readonly type: "tool";
54
+ readonly id: string;
55
+ readonly name: string;
56
+ readonly executed: boolean;
57
+ readonly state: ToolState;
58
+ readonly time: {
59
+ readonly created: number;
60
+ readonly completed: number;
61
+ };
62
+ };
63
+ /** A message as opencode 2 records it for a session. */
64
+ export type Message = {
65
+ readonly type: "user";
66
+ readonly id: string;
67
+ readonly time: {
68
+ readonly created: number;
69
+ };
70
+ readonly text: string;
71
+ readonly files?: ReadonlyArray<RecordedFile>;
72
+ } | {
73
+ readonly type: "system";
74
+ readonly id: string;
75
+ readonly time: {
76
+ readonly created: number;
77
+ };
78
+ readonly text: string;
79
+ } | {
80
+ readonly type: "assistant";
81
+ readonly id: string;
82
+ readonly time: {
83
+ readonly created: number;
84
+ readonly completed: number;
85
+ };
86
+ readonly agent: string;
87
+ readonly model: ModelRef;
88
+ readonly content: ReadonlyArray<AssistantContent>;
89
+ readonly finish: "stop" | "tool-calls";
90
+ };
91
+ /**
92
+ * The prompt of a user message, as opencode 2 takes it: its texts, and its files as `data:` URLs.
93
+ * Fails with `UnsupportedError` for a file at another URL.
94
+ */
95
+ export declare const promptOf: (message: Prompt.UserMessage) => Result.Result<PromptInput, HarnessError.UnsupportedError>;
96
+ /** What the messages of a written conversation are recorded with. */
97
+ export interface Recording {
98
+ /** The session the messages are recorded for, whose id makes theirs unique to it. */
99
+ readonly sessionID: string;
100
+ /** When the messages are written, in milliseconds since the epoch. */
101
+ readonly now: number;
102
+ }
103
+ /**
104
+ * The messages that record `conversation` in a new session. Fails with `UnsupportedError` for a
105
+ * conversation opencode cannot record.
106
+ */
107
+ export declare const messagesOf: (conversation: Prompt.Prompt, recording: Recording) => Result.Result<ReadonlyArray<Message>, HarnessError.UnsupportedError>;
108
+ export {};
109
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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;CACtB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAA;IACvE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAA;IACxB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAA;IACjD,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAA;CACvC,CAAA;AAEL;;;GAGG;AACH,eAAO,MAAM,QAAQ,YAAa,MAAM,CAAC,WAAW,KAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,gBAAgB,CAY9G,CAAA;AAED,qEAAqE;AACrE,MAAM,WAAW,SAAS;IACxB,qFAAqF;IACrF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAE1B,sEAAsE;IACtE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,iBACP,MAAM,CAAC,MAAM,aAChB,SAAS,KACnB,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,gBAAgB,CAuErE,CAAA"}
@@ -0,0 +1,209 @@
1
+ /**
2
+ * What opencode 2 is prompted with: a turn's prompt, and a conversation started on another agent,
3
+ * written as the messages opencode records for a session so that it goes on in opencode as its
4
+ * own. Each user message is a prompt, each system message an update of the model's instructions,
5
+ * and each assistant message a step, its tool calls with the results of the tool messages after
6
+ * it. The tools need not be opencode's own. The steps name the model `amends/history`, because a
7
+ * conversation does not say which model answered; opencode reads them whichever model they name.
8
+ *
9
+ * opencode 2 takes files as data, so a file given at a URL other than a `data:` or `file:` URL
10
+ * fails with `UnsupportedError`.
11
+ */
12
+ import { HarnessError } from "@amends-dev/harness";
13
+ import * as Base64 from "effect/encoding/Base64";
14
+ import * as Predicate from "effect/Predicate";
15
+ import * as Result from "effect/Result";
16
+ import * as Schema from "effect/Schema";
17
+ import { ToolContent } from "./event.js";
18
+ /**
19
+ * The prompt of a user message, as opencode 2 takes it: its texts, and its files as `data:` URLs.
20
+ * Fails with `UnsupportedError` for a file at another URL.
21
+ */
22
+ export const promptOf = (message) => {
23
+ const files = [];
24
+ for (const part of message.content) {
25
+ if (part.type !== "file")
26
+ continue;
27
+ const uri = uriOf(part);
28
+ if (uri === undefined)
29
+ return Result.fail(unsupportedFile(part));
30
+ files.push({ uri, ...(part.fileName === undefined ? {} : { name: part.fileName }) });
31
+ }
32
+ return Result.succeed({
33
+ text: textOf(message),
34
+ ...(files.length === 0 ? {} : { files })
35
+ });
36
+ };
37
+ /**
38
+ * The messages that record `conversation` in a new session. Fails with `UnsupportedError` for a
39
+ * conversation opencode cannot record.
40
+ */
41
+ export const messagesOf = (conversation, recording) => {
42
+ const unsupported = unsupportedIn(conversation);
43
+ if (unsupported !== undefined) {
44
+ return Result.fail(new HarnessError.UnsupportedError({ description: unsupported }));
45
+ }
46
+ const results = resultsOf(conversation);
47
+ const time = { created: recording.now };
48
+ const messages = [];
49
+ for (const [index, message] of conversation.content.entries()) {
50
+ const id = opencodeId("msg", recording, index + 1);
51
+ switch (message.role) {
52
+ case "system":
53
+ messages.push({ type: "system", id, time, text: message.content });
54
+ break;
55
+ case "user": {
56
+ const files = message.content.flatMap((part) => {
57
+ const file = part.type === "file" ? recordedFileOf(part) : undefined;
58
+ return file === undefined ? [] : [file];
59
+ });
60
+ messages.push({
61
+ type: "user",
62
+ id,
63
+ time,
64
+ text: textOf(message),
65
+ ...(files.length === 0 ? {} : { files })
66
+ });
67
+ break;
68
+ }
69
+ case "assistant": {
70
+ const content = message.content.flatMap((part) => {
71
+ switch (part.type) {
72
+ case "text":
73
+ case "reasoning":
74
+ return [{ type: part.type, text: part.text }];
75
+ case "tool-call":
76
+ return [
77
+ {
78
+ type: "tool",
79
+ id: part.id,
80
+ name: part.name,
81
+ // Whoever ran the call, opencode reads it as one it ran, not the provider.
82
+ executed: false,
83
+ state: stateOf(inputOf(part.params), results.get(part.id)),
84
+ time: { created: recording.now, completed: recording.now }
85
+ }
86
+ ];
87
+ // A result is recorded with its call, and an approval changes what the model reads
88
+ // only through the result that follows it. `unsupportedIn` refused files.
89
+ case "tool-result":
90
+ case "tool-approval-request":
91
+ case "file":
92
+ return [];
93
+ }
94
+ });
95
+ messages.push({
96
+ type: "assistant",
97
+ id,
98
+ time: { created: recording.now, completed: recording.now },
99
+ agent: "build",
100
+ model: historyModel,
101
+ content,
102
+ finish: content.some((part) => part.type === "tool") ? "tool-calls" : "stop"
103
+ });
104
+ break;
105
+ }
106
+ // Results are recorded with the calls of the assistant message before.
107
+ case "tool":
108
+ break;
109
+ }
110
+ }
111
+ return Result.succeed(messages);
112
+ };
113
+ /** Why opencode cannot record `conversation`, or nothing when it can. */
114
+ const unsupportedIn = (conversation) => {
115
+ let answering = false;
116
+ for (const message of conversation.content) {
117
+ if (message.role === "assistant" && message.content.some((part) => part.type === "file")) {
118
+ return "opencode records no files that an assistant wrote";
119
+ }
120
+ if (message.role === "user") {
121
+ const file = message.content.find((part) => part.type === "file" && recordedFileOf(part) === undefined);
122
+ if (file !== undefined)
123
+ return "opencode records the files of a conversation only as data";
124
+ }
125
+ if (message.role === "tool" && !answering) {
126
+ return "opencode records tool results only after the assistant message that called them";
127
+ }
128
+ if (message.role !== "tool")
129
+ answering = message.role === "assistant";
130
+ }
131
+ return undefined;
132
+ };
133
+ /** The results of the conversation's tool calls, by call id. */
134
+ const resultsOf = (conversation) => {
135
+ const results = new Map();
136
+ for (const message of conversation.content) {
137
+ if (message.role !== "assistant" && message.role !== "tool")
138
+ continue;
139
+ for (const part of message.content) {
140
+ if (part.type === "tool-result")
141
+ results.set(part.id, part);
142
+ }
143
+ }
144
+ return results;
145
+ };
146
+ /**
147
+ * The state of a call with `input` that ended with `result`. A call without one is recorded as
148
+ * failed, since opencode reads every recorded call as ended.
149
+ */
150
+ const stateOf = (input, result) => result === undefined
151
+ ? {
152
+ status: "error",
153
+ input,
154
+ error: { type: "unknown", message: "The conversation recorded no result of the call" }
155
+ }
156
+ : result.isFailure
157
+ ? { status: "error", input, error: { type: "unknown", message: resultText(result.result) } }
158
+ : { status: "completed", input, content: contentOf(result.result) };
159
+ /** The model the steps of a written conversation name. */
160
+ const historyModel = { providerID: "amends", id: "history" };
161
+ /**
162
+ * An id as opencode makes one: a prefix, the low 48 bits of the time it was made with a count
163
+ * within it, then a random part. The session's own random part keeps the ids written for it unique
164
+ * to it.
165
+ */
166
+ const opencodeId = (prefix, recording, count) => {
167
+ const time = (BigInt(recording.now) * 0x1000n + BigInt(count)) & 0xffffffffffffn;
168
+ return `${prefix}_${time.toString(16).padStart(12, "0")}${recording.sessionID.slice(-14)}`;
169
+ };
170
+ const textOf = (message) => message.content.flatMap((part) => (part.type === "text" ? [part.text] : [])).join("\n");
171
+ /**
172
+ * The URL opencode 2 reads a file at: a `data:` or `file:` URL as it is, and data, or a string of
173
+ * data in base64, as a `data:` URL. Nothing for a file at another URL, which opencode does not read.
174
+ */
175
+ const uriOf = (part) => {
176
+ const { data, mediaType } = part;
177
+ if (data instanceof URL)
178
+ return /^(data|file):$/.test(data.protocol) ? data.href : undefined;
179
+ if (typeof data !== "string")
180
+ return `data:${mediaType};base64,${Base64.encode(data)}`;
181
+ if (/^(data|file):/.test(data))
182
+ return data;
183
+ return /^[a-z][a-z0-9+.-]*:/i.test(data) ? undefined : `data:${mediaType};base64,${data}`;
184
+ };
185
+ /** A file of a user message as opencode records it, its data in base64. */
186
+ const recordedFileOf = (part) => {
187
+ const uri = uriOf(part);
188
+ const data = uri?.startsWith("data:") ? /^data:[^,]*;base64,(.*)$/s.exec(uri)?.[1] : undefined;
189
+ if (data === undefined)
190
+ return undefined;
191
+ return {
192
+ data,
193
+ mime: part.mediaType,
194
+ source: { type: "inline" },
195
+ ...(part.fileName === undefined ? {} : { name: part.fileName })
196
+ };
197
+ };
198
+ const unsupportedFile = (part) => new HarnessError.UnsupportedError({
199
+ description: `opencode 2 reads files as data, not at ${part.data instanceof URL ? part.data.href : String(part.data).slice(0, 40)}`
200
+ });
201
+ /** A tool's input as opencode keeps it: an object, wrapping any other value as opencode does. */
202
+ const inputOf = (params) => (Predicate.isObject(params) ? params : { value: params });
203
+ /**
204
+ * What the model reads of a tool's result: the content opencode returned, or the result as
205
+ * text. opencode records at least one content of a result.
206
+ */
207
+ const contentOf = (result) => Schema.is(Schema.NonEmptyArray(ToolContent))(result) ? result : [{ type: "text", text: resultText(result) }];
208
+ const resultText = (result) => (typeof result === "string" ? result : JSON.stringify(result));
209
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../src/internal/bridge/v2/prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAA;AAChD,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAiExC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAA2B,EAA6D,EAAE;IACjH,MAAM,KAAK,GAA4D,EAAE,CAAA;IACzE,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACnC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;YAAE,SAAQ;QAClC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAA;QACvB,IAAI,GAAG,K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, with the prompt's files, on the turn's model, the
4
+ * turn's instructions given beside opencode's own; `Turn` translates the events opencode publishes
5
+ * for the turn as they happen. A session that starts with a conversation from another agent is
6
+ * created holding it, as opencode's own record, as `Prompt` writes it.
7
+ *
8
+ * The host's tools reach opencode through the bridge's `HostToolRelay`, as `HostTools` lists them:
9
+ * opencode 2's model calls them from code it runs. A tool of opencode's own that asks permission
10
+ * waits for `approve`, and `compact` asks opencode to summarize the conversation, which it does
11
+ * without instructions. opencode 2 does not answer in JSON, which fails with `UnsupportedError`.
12
+ */
13
+ import { type HostToolRelay } from "@amends-dev/harness";
14
+ import * as Driver from "../driver.ts";
15
+ /**
16
+ * The function that creates sessions as `Driver.CreateSession` does, each with a session of
17
+ * `relay` for the host's tools: a new opencode session, or the one its `agentState` names, when
18
+ * opencode still has it.
19
+ */
20
+ export declare const makeCreateSession: (relay: HostToolRelay.HostToolRelay["Service"]) => Driver.CreateSession;
21
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../../src/internal/bridge/v2/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAUnF,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AA4BtC;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,UACpB,aAAa,CAAC,aAAa,CAAC,SAAS,CAAC,KAAG,MAAM,CAAC,aAyLpD,CAAA"}