@shivaedev/agent-opencode 0.1.0 → 0.2.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/CHANGELOG.md +6 -0
- package/README.md +58 -1
- package/dist/Provider.d.ts +16 -0
- package/dist/Provider.d.ts.map +1 -0
- package/dist/Provider.js +4 -0
- package/dist/Provider.js.map +1 -0
- package/dist/adapters/MessageUpdatedProperties.d.ts +10 -0
- package/dist/adapters/MessageUpdatedProperties.d.ts.map +1 -0
- package/dist/adapters/MessageUpdatedProperties.js +10 -0
- package/dist/adapters/MessageUpdatedProperties.js.map +1 -0
- package/dist/adapters/OpencodeRequest.d.ts +6 -0
- package/dist/adapters/OpencodeRequest.d.ts.map +1 -0
- package/dist/adapters/OpencodeRequest.js +2 -0
- package/dist/adapters/OpencodeRequest.js.map +1 -0
- package/dist/adapters/answerToolRequest.d.ts +4 -0
- package/dist/adapters/answerToolRequest.d.ts.map +1 -0
- package/dist/adapters/answerToolRequest.js +106 -0
- package/dist/adapters/answerToolRequest.js.map +1 -0
- package/dist/adapters/listeningUrl.d.ts +2 -0
- package/dist/adapters/listeningUrl.d.ts.map +1 -0
- package/dist/adapters/listeningUrl.js +5 -0
- package/dist/adapters/listeningUrl.js.map +1 -0
- package/dist/adapters/makeOpencodeServer.d.ts +7 -0
- package/dist/adapters/makeOpencodeServer.d.ts.map +1 -0
- package/dist/adapters/makeOpencodeServer.js +49 -0
- package/dist/adapters/makeOpencodeServer.js.map +1 -0
- package/dist/adapters/mapping.d.ts +7 -0
- package/dist/adapters/mapping.d.ts.map +1 -0
- package/dist/adapters/mapping.js +11 -0
- package/dist/adapters/mapping.js.map +1 -0
- package/dist/adapters/messageAuthors.d.ts +11 -0
- package/dist/adapters/messageAuthors.d.ts.map +1 -0
- package/dist/adapters/messageAuthors.js +24 -0
- package/dist/adapters/messageAuthors.js.map +1 -0
- package/dist/adapters/openSseBuffer.d.ts +6 -0
- package/dist/adapters/openSseBuffer.d.ts.map +1 -0
- package/dist/adapters/openSseBuffer.js +34 -0
- package/dist/adapters/openSseBuffer.js.map +1 -0
- package/dist/adapters/openTurnBoundary.d.ts +11 -0
- package/dist/adapters/openTurnBoundary.d.ts.map +1 -0
- package/dist/adapters/openTurnBoundary.js +46 -0
- package/dist/adapters/openTurnBoundary.js.map +1 -0
- package/dist/adapters/opencodePlugin.config.d.ts +11 -0
- package/dist/adapters/opencodePlugin.config.d.ts.map +1 -0
- package/dist/adapters/opencodePlugin.config.js +9 -0
- package/dist/adapters/opencodePlugin.config.js.map +1 -0
- package/dist/adapters/partEvents.d.ts +7 -0
- package/dist/adapters/partEvents.d.ts.map +1 -0
- package/dist/adapters/partEvents.js +62 -0
- package/dist/adapters/partEvents.js.map +1 -0
- package/dist/adapters/projection.d.ts +7 -0
- package/dist/adapters/projection.d.ts.map +1 -0
- package/dist/adapters/projection.js +41 -0
- package/dist/adapters/projection.js.map +1 -0
- package/dist/adapters/protocol.d.ts +36 -0
- package/dist/adapters/protocol.d.ts.map +1 -0
- package/dist/adapters/protocol.js +32 -0
- package/dist/adapters/protocol.js.map +1 -0
- package/dist/adapters/protocolParts.d.ts +48 -0
- package/dist/adapters/protocolParts.d.ts.map +1 -0
- package/dist/adapters/protocolParts.js +47 -0
- package/dist/adapters/protocolParts.js.map +1 -0
- package/dist/adapters/providerAddress.d.ts +5 -0
- package/dist/adapters/providerAddress.d.ts.map +1 -0
- package/dist/adapters/providerAddress.js +21 -0
- package/dist/adapters/providerAddress.js.map +1 -0
- package/dist/adapters/serveOpencode.d.ts +13 -0
- package/dist/adapters/serveOpencode.d.ts.map +1 -0
- package/dist/adapters/serveOpencode.js +75 -0
- package/dist/adapters/serveOpencode.js.map +1 -0
- package/dist/adapters/serveToolRequests.d.ts +4 -0
- package/dist/adapters/serveToolRequests.d.ts.map +1 -0
- package/dist/adapters/serveToolRequests.js +23 -0
- package/dist/adapters/serveToolRequests.js.map +1 -0
- package/dist/adapters/servedTools.d.ts +4 -0
- package/dist/adapters/servedTools.d.ts.map +1 -0
- package/dist/adapters/servedTools.js +9 -0
- package/dist/adapters/servedTools.js.map +1 -0
- package/dist/adapters/sessionFrames.d.ts +7 -0
- package/dist/adapters/sessionFrames.d.ts.map +1 -0
- package/dist/adapters/sessionFrames.js +16 -0
- package/dist/adapters/sessionFrames.js.map +1 -0
- package/dist/adapters/toolEvents.d.ts +10 -0
- package/dist/adapters/toolEvents.d.ts.map +1 -0
- package/dist/adapters/toolEvents.js +30 -0
- package/dist/adapters/toolEvents.js.map +1 -0
- package/dist/adapters/toolNames.d.ts +6 -0
- package/dist/adapters/toolNames.d.ts.map +1 -0
- package/dist/adapters/toolNames.js +8 -0
- package/dist/adapters/toolNames.js.map +1 -0
- package/dist/adapters/toolSessions.d.ts +11 -0
- package/dist/adapters/toolSessions.d.ts.map +1 -0
- package/dist/adapters/toolSessions.js +15 -0
- package/dist/adapters/toolSessions.js.map +1 -0
- package/dist/callWhileOpen.d.ts +4 -0
- package/dist/callWhileOpen.d.ts.map +1 -0
- package/dist/callWhileOpen.js +9 -0
- package/dist/callWhileOpen.js.map +1 -0
- package/dist/failure.d.ts +4 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +8 -0
- package/dist/failure.js.map +1 -0
- package/dist/listOpencodeModels.d.ts +11 -0
- package/dist/listOpencodeModels.d.ts.map +1 -0
- package/dist/listOpencodeModels.js +31 -0
- package/dist/listOpencodeModels.js.map +1 -0
- package/dist/openOpencodeSession.d.ts +5 -0
- package/dist/openOpencodeSession.d.ts.map +1 -0
- package/dist/openOpencodeSession.js +40 -0
- package/dist/openOpencodeSession.js.map +1 -0
- package/dist/opencode.d.ts +9 -1
- package/dist/opencode.d.ts.map +1 -1
- package/dist/opencode.js +49 -1
- package/dist/opencode.js.map +1 -1
- package/dist/operations.d.ts +367 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +87 -0
- package/dist/operations.js.map +1 -0
- package/dist/options.d.ts +30 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +2 -0
- package/dist/options.js.map +1 -0
- package/dist/sessionOpen.d.ts +19 -0
- package/dist/sessionOpen.d.ts.map +1 -0
- package/dist/sessionOpen.js +60 -0
- package/dist/sessionOpen.js.map +1 -0
- package/dist/tools.d.ts +14 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +2 -0
- package/dist/tools.js.map +1 -0
- package/dist/turnRequests.d.ts +13 -0
- package/dist/turnRequests.d.ts.map +1 -0
- package/dist/turnRequests.js +19 -0
- package/dist/turnRequests.js.map +1 -0
- package/dist/turnState.d.ts +24 -0
- package/dist/turnState.d.ts.map +1 -0
- package/dist/turnState.js +27 -0
- package/dist/turnState.js.map +1 -0
- package/dist/turns.d.ts +19 -0
- package/dist/turns.d.ts.map +1 -0
- package/dist/turns.js +57 -0
- package/dist/turns.js.map +1 -0
- package/package.json +33 -4
- package/src/Provider.ts +14 -0
- package/src/adapters/MessageUpdatedProperties.ts +9 -0
- package/src/adapters/OpencodeRequest.ts +5 -0
- package/src/adapters/answerToolRequest.ts +121 -0
- package/src/adapters/listeningUrl.ts +4 -0
- package/src/adapters/makeOpencodeServer.ts +77 -0
- package/src/adapters/mapping.ts +14 -0
- package/src/adapters/messageAuthors.ts +31 -0
- package/src/adapters/openSseBuffer.ts +36 -0
- package/src/adapters/openTurnBoundary.ts +58 -0
- package/src/adapters/opencodePlugin.config.ts +17 -0
- package/src/adapters/partEvents.ts +85 -0
- package/src/adapters/projection.ts +46 -0
- package/src/adapters/protocol.ts +31 -0
- package/src/adapters/protocolParts.ts +48 -0
- package/src/adapters/providerAddress.ts +22 -0
- package/src/adapters/serveOpencode.ts +93 -0
- package/src/adapters/serveToolRequests.ts +24 -0
- package/src/adapters/servedTools.ts +11 -0
- package/src/adapters/sessionFrames.ts +25 -0
- package/src/adapters/toolEvents.ts +42 -0
- package/src/adapters/toolNames.ts +7 -0
- package/src/adapters/toolSessions.ts +22 -0
- package/src/callWhileOpen.ts +16 -0
- package/src/failure.ts +7 -0
- package/src/listOpencodeModels.ts +34 -0
- package/src/openOpencodeSession.ts +60 -0
- package/src/opencode.ts +61 -1
- package/src/operations.ts +111 -0
- package/src/options.ts +29 -0
- package/src/sessionOpen.ts +74 -0
- package/src/tools.ts +13 -0
- package/src/turnRequests.ts +25 -0
- package/src/turnState.ts +41 -0
- package/src/turns.ts +89 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0 - 2026-11-04
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- OpenCode backend for the shared agent port with HTTP and SSE transport, scoped session events, queued and active text delivery, abort, model discovery and session-bound MCP tools. Image input and transcript history remain explicitly unsupported. Requires the OpenCode executable; the MCP SDK is an optional peer for the tool bridge.
|
|
8
|
+
|
|
3
9
|
## 0.1.0 - 2026-11-03
|
|
4
10
|
|
|
5
11
|
### Added
|
package/README.md
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
1
|
# @shivaedev/agent-opencode
|
|
2
2
|
|
|
3
|
-
OpenCode
|
|
3
|
+
Run OpenCode through Platform's shared agent port. Applications use the same Effect lifecycle, receipts and events while the adapter owns OpenCode's HTTP protocol, event mapping and delivery queue.
|
|
4
|
+
|
|
5
|
+
## Keep application work on the shared port
|
|
6
|
+
|
|
7
|
+
Start a run, steer active work or queue the next instruction without putting provider transport in the application.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { Effect } from "effect";
|
|
11
|
+
import { requireFeatures } from "@shivaedev/agent/agent.ts";
|
|
12
|
+
import { opencode } from "@shivaedev/agent-opencode/opencode.ts";
|
|
13
|
+
|
|
14
|
+
const program = Effect.gen(function* () {
|
|
15
|
+
const agent = yield* requireFeatures(["steering"]);
|
|
16
|
+
const run = yield* agent.start({
|
|
17
|
+
operationId: "search",
|
|
18
|
+
cwd: "/project",
|
|
19
|
+
input: { parts: [{ type: "text", text: "Add search" }] },
|
|
20
|
+
});
|
|
21
|
+
yield* agent.steering.steer(run, {
|
|
22
|
+
parts: [{ type: "text", text: "Keep the public API" }],
|
|
23
|
+
});
|
|
24
|
+
}).pipe(Effect.provide(opencode({ cwd: "/project" })), Effect.scoped);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Using it
|
|
28
|
+
|
|
29
|
+
`opencode(options)` is a Layer for `Backend` from `@shivaedev/agent/backend.ts`. It starts one OpenCode server for the Layer's scope. Provide `ChildProcessSpawner` from your platform runtime, for example `NodeServices.layer` from `@effect/platform-node/NodeServices`, to the Layer. The scope of each start or resume keeps its session subscriptions, queued deliveries and tool handlers alive.
|
|
30
|
+
|
|
31
|
+
Set `url` to connect to an existing server instead. This mode uses HTTP requests and the global SSE endpoint; Session tool bridging is unsupported in this mode; use a spawned server for direct tools. `command` selects the executable when spawning and defaults to `opencode`. `cwd` is the process directory; each start's `cwd` is sent as the provider request's `directory` query. `skills` optionally sets an OpenCode skills path for spawned servers.
|
|
32
|
+
|
|
33
|
+
### Runs and delivery
|
|
34
|
+
|
|
35
|
+
Start creates a session; `sessions.resume` reads an existing session before sending the new input. Receipts carry version 1 OpenCode session references. Start acknowledges `prompt_async` delivery, without waiting for model completion. Model names use `provider/model`; `effort` selects the provider's variant. Omitting the model lets OpenCode choose. `models.list` reads provider names, defaults and variants from `/config/providers`.
|
|
36
|
+
|
|
37
|
+
Queued input waits locally until `session.idle`, then sends one input at a time in arrival order. The queue operation completes when the provider accepts its delivery. Steering sends `prompt_async` immediately, including while a turn is active. Interruption sends the session's abort request; the request acknowledgement alone is not proof of an interrupted turn.
|
|
38
|
+
|
|
39
|
+
Events are session scoped and consumed as a single live stream per receipt. Message metadata associates parts with their author; only settled text and reasoning parts become shared messages. Settled parts and tool transitions are deduplicated. Unknown events retain their raw provider payload. Token usage and provider cost are separate events; missing accounting fields stay absent. A busy turn followed by idle reports completion, failure or interruption from the provider's turn evidence.
|
|
40
|
+
|
|
41
|
+
`inspect` reports observed live execution evidence. `reconcile` returns receipts acknowledged by this Layer, and uncertainty otherwise. OpenCode has no operation-ID lookup, so a restart or a lost submission acknowledgement cannot establish non-acceptance. Ambiguous prompt delivery fails with `UnknownAcceptance`; reconciliation never resubmits it. The application owns durable storage, wake scheduling, logs and agent identity.
|
|
42
|
+
|
|
43
|
+
### Session tools
|
|
44
|
+
|
|
45
|
+
`tools` supplies the catalogue of direct tools. Each tool has `name`, `description`, an object `inputSchema`, and `call(callId, args)`, returning an Effect with `{ ok, text }`. Optional `sessionTools(request)` binds a subset and its handlers to each start or resume. Use it to capture application context for that session; tool execution receives the provider's call ID and arguments with routing fields removed.
|
|
46
|
+
|
|
47
|
+
A spawned server gets the MCP endpoint and caller-session plugin automatically. The plugin stamps `callerSession` and `callerCall` on `platform_` tool calls. The bridge dispatches only to that open session's assigned tool and keeps calls within its scope. Native OpenCode tools remain available by default; other catalogue tools are denied. With `constrainedPrompt`, permissions deny everything first and then allow only assigned bridge tools, because OpenCode uses the last matching rule. Constrained mode also disables project config, external skills and Claude Code prompts.
|
|
48
|
+
|
|
49
|
+
### Install and limits
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
pnpm add @shivaedev/agent-opencode @shivaedev/agent effect @effect/platform-node
|
|
53
|
+
pnpm add @modelcontextprotocol/sdk
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The OpenCode executable and its provider credentials are runtime prerequisites. The MCP SDK is an optional peer used only when spawning with tools. A connection without tools does not import it. Node platform support is an optional peer used for spawned tool endpoints; process spawning uses the runtime's native Effect process service.
|
|
57
|
+
|
|
58
|
+
Supported shared features are sessions, queued input, steering, interruption and model discovery. Image input and transcript history are explicitly unsupported. Approval responses, child lineage and image projection have no normalized implementation; unfamiliar provider events remain raw. Events and queues do not survive a backend restart, and an SSE disconnect supplies no completion evidence. There is no reconnect or automatic replacement run. Existing sessions retain their provider permissions when resumed.
|
|
59
|
+
|
|
60
|
+
The scripted peer exercises the real adapter's HTTP, SSE and MCP boundaries. Live provider validation belongs to application adoption.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Context, type Effect, type PubSub } from "effect";
|
|
2
|
+
import type { BackendFailure, ReadFailure } from "@shivaedev/agent/failures.ts";
|
|
3
|
+
import type { OpencodeRequest } from "#adapters/OpencodeRequest.ts";
|
|
4
|
+
import type { ToolSessions } from "#adapters/toolSessions.ts";
|
|
5
|
+
export interface ProviderPort {
|
|
6
|
+
readonly exited: Effect.Effect<void>;
|
|
7
|
+
readonly frames: PubSub.PubSub<unknown>;
|
|
8
|
+
readonly get: (request: OpencodeRequest) => Effect.Effect<unknown, ReadFailure>;
|
|
9
|
+
readonly post: (request: OpencodeRequest) => Effect.Effect<unknown, BackendFailure>;
|
|
10
|
+
readonly tools: ToolSessions;
|
|
11
|
+
}
|
|
12
|
+
declare const Provider_base: Context.ServiceClass<Provider, "@shivaedev/agent-opencode/Provider", ProviderPort>;
|
|
13
|
+
export declare class Provider extends Provider_base {
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=Provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../src/Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAChF,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IACpF,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;CAC7B;;AAED,qBAAa,QAAS,SAAQ,aAA+E;CAAG"}
|
package/dist/Provider.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../src/Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA4B,MAAM,QAAQ,CAAC;AAa3D,MAAM,OAAO,QAAS,SAAQ,OAAO,CAAC,OAAO,EAA0B,CAAC,oCAAoC,CAAC;CAAG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export declare const MessageUpdatedProperties: Schema.Struct<{
|
|
3
|
+
readonly info: Schema.Struct<{
|
|
4
|
+
readonly id: Schema.String;
|
|
5
|
+
readonly modelID: Schema.optional<Schema.String>;
|
|
6
|
+
readonly providerID: Schema.optional<Schema.String>;
|
|
7
|
+
readonly role: Schema.Literals<readonly ["assistant", "user"]>;
|
|
8
|
+
}>;
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=MessageUpdatedProperties.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageUpdatedProperties.d.ts","sourceRoot":"","sources":["../../src/adapters/MessageUpdatedProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,eAAO,MAAM,wBAAwB;;;;;;;EAOnC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export const MessageUpdatedProperties = Schema.Struct({
|
|
3
|
+
info: Schema.Struct({
|
|
4
|
+
id: Schema.String,
|
|
5
|
+
"modelID": Schema.optional(Schema.String),
|
|
6
|
+
"providerID": Schema.optional(Schema.String),
|
|
7
|
+
role: Schema.Literals(["assistant", "user"]),
|
|
8
|
+
}),
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=MessageUpdatedProperties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageUpdatedProperties.js","sourceRoot":"","sources":["../../src/adapters/MessageUpdatedProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,CAAC;IACrD,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;QACnB,EAAE,EAAE,MAAM,CAAC,MAAM;QACjB,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;QACzC,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;QAC5C,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;KAC5C,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpencodeRequest.d.ts","sourceRoot":"","sources":["../../src/adapters/OpencodeRequest.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpencodeRequest.js","sourceRoot":"","sources":["../../src/adapters/OpencodeRequest.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ToolSessions } from "#adapters/toolSessions.ts";
|
|
2
|
+
import type { ToolDefinition } from "#tools.ts";
|
|
3
|
+
export declare function answerToolRequest(tools: readonly ToolDefinition[], sessions: ToolSessions): (request: Request) => Promise<Response>;
|
|
4
|
+
//# sourceMappingURL=answerToolRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answerToolRequest.d.ts","sourceRoot":"","sources":["../../src/adapters/answerToolRequest.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AA4EhD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,EAAE,QAAQ,EAAE,YAAY,aAElE,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAkClD"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
3
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { Effect, Option, Schema } from "effect";
|
|
5
|
+
import { CALLER_CALL, CALLER_SESSION, TOOL_SERVER_NAME } from "#adapters/toolNames.ts";
|
|
6
|
+
function listed(tool) {
|
|
7
|
+
return {
|
|
8
|
+
description: tool.description,
|
|
9
|
+
inputSchema: { ...tool.inputSchema, type: "object" },
|
|
10
|
+
name: tool.name,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function said(text, ok) {
|
|
14
|
+
return {
|
|
15
|
+
content: [{ text, type: "text" }],
|
|
16
|
+
isError: !ok,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const decodeArguments = Schema.decodeUnknownOption(Schema.Record(Schema.String, Schema.Unknown));
|
|
20
|
+
function caller(args) {
|
|
21
|
+
return Option.match(decodeArguments(args), {
|
|
22
|
+
onNone: () => ({ callId: undefined, rest: args, session: undefined }),
|
|
23
|
+
onSome: ({ [CALLER_SESSION]: session, [CALLER_CALL]: callId, ...rest }) => ({
|
|
24
|
+
callId: typeof callId === "string" ? callId : undefined,
|
|
25
|
+
rest,
|
|
26
|
+
session: typeof session === "string" ? session : undefined,
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async function answerCall(sessions, name, args) {
|
|
31
|
+
const { rest, session, callId } = caller(args);
|
|
32
|
+
if (session === undefined) {
|
|
33
|
+
return said(`the call named no ${CALLER_SESSION}, so platform cannot tell which session is asking`, false);
|
|
34
|
+
}
|
|
35
|
+
if (callId === undefined) {
|
|
36
|
+
return said(`the call named no ${CALLER_CALL}, so platform cannot identify the provider call`, false);
|
|
37
|
+
}
|
|
38
|
+
const served = sessions.served(session);
|
|
39
|
+
if (Option.isNone(served)) {
|
|
40
|
+
return said(`platform serves no open session ${session}`, false);
|
|
41
|
+
}
|
|
42
|
+
const tool = served.value.get(name);
|
|
43
|
+
if (tool === undefined) {
|
|
44
|
+
return said(`session ${session} was given no tool named ${name}`, false);
|
|
45
|
+
}
|
|
46
|
+
const outcome = await tool(callId, rest);
|
|
47
|
+
return said(outcome.text, outcome.ok);
|
|
48
|
+
}
|
|
49
|
+
const progressWhileOpen = Effect.fnUntraced(function* (send) {
|
|
50
|
+
let progress = 0;
|
|
51
|
+
const report = Effect.promise(() => send(progress).then(() => {
|
|
52
|
+
progress += 1;
|
|
53
|
+
}));
|
|
54
|
+
yield* report;
|
|
55
|
+
yield* Effect.forkScoped(Effect.forever(Effect.andThen(Effect.sleep(30_000), report)));
|
|
56
|
+
});
|
|
57
|
+
function answerWithProgress(sessions, message, extra) {
|
|
58
|
+
return Effect.runPromise(Effect.scoped(Effect.gen(function* () {
|
|
59
|
+
const token = message.params._meta?.progressToken;
|
|
60
|
+
if (token !== undefined) {
|
|
61
|
+
yield* progressWhileOpen((progress) => extra.sendNotification({ method: "notifications/progress", params: { progress, progressToken: token } }));
|
|
62
|
+
}
|
|
63
|
+
return yield* Effect.promise(() => answerCall(sessions, message.params.name, message.params.arguments));
|
|
64
|
+
})), { signal: extra.signal });
|
|
65
|
+
}
|
|
66
|
+
// Omitting the session-id generator makes the transport stateless, so each request gets its own protocol server and nothing is carried between them.
|
|
67
|
+
export function answerToolRequest(tools, sessions) {
|
|
68
|
+
const list = tools.map(listed);
|
|
69
|
+
return async (request) => {
|
|
70
|
+
const server = new Server({ name: TOOL_SERVER_NAME, version: "0.0.0" }, { capabilities: { tools: {} } });
|
|
71
|
+
server.setRequestHandler(ListToolsRequestSchema, () => ({ tools: list }));
|
|
72
|
+
server.setRequestHandler(CallToolRequestSchema, (message, extra) => answerWithProgress(sessions, message, extra));
|
|
73
|
+
const transport = new WebStandardStreamableHTTPServerTransport();
|
|
74
|
+
await server.connect(transport);
|
|
75
|
+
const response = await transport.handleRequest(request);
|
|
76
|
+
if (response.body === null) {
|
|
77
|
+
await server.close();
|
|
78
|
+
return response;
|
|
79
|
+
}
|
|
80
|
+
const reader = response.body.getReader();
|
|
81
|
+
const body = new ReadableStream({
|
|
82
|
+
async cancel() {
|
|
83
|
+
await reader.cancel();
|
|
84
|
+
await server.close();
|
|
85
|
+
},
|
|
86
|
+
async pull(controller) {
|
|
87
|
+
try {
|
|
88
|
+
const next = await reader.read();
|
|
89
|
+
if (next.done) {
|
|
90
|
+
await server.close();
|
|
91
|
+
controller.close();
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
controller.enqueue(next.value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
await server.close();
|
|
99
|
+
controller.error(error);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
return new Response(body, { headers: response.headers, status: response.status });
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=answerToolRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answerToolRequest.js","sourceRoot":"","sources":["../../src/adapters/answerToolRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,wCAAwC,EAAE,MAAM,+DAA+D,CAAC;AAGzH,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACnG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAIvF,SAAS,MAAM,CAAC,IAAoB;IACnC,OAAO;QACN,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,WAAW,EAAE,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,EAAE,QAAiB,EAAE;QAC7D,IAAI,EAAE,IAAI,CAAC,IAAI;KACf,CAAC;AACH,CAAC;AACD,SAAS,IAAI,CAAC,IAAY,EAAE,EAAW;IACtC,OAAO;QACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAe,EAAE,CAAC;QAC1C,OAAO,EAAE,CAAC,EAAE;KACZ,CAAC;AACH,CAAC;AACD,MAAM,eAAe,GAAG,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;AACjG,SAAS,MAAM,CAAC,IAAa;IAK5B,OAAO,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE;QAC1C,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,E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ACzC,MAAM,IAAI,GAAG,IAAI,cAAc,CAAa;YAC3C,KAAK,CAAC,MAAM;gBACX,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;gBACtB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;YACtB,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,UAAU;gBACpB,IAAI,CAAC;oBACJ,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;oBACjC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;wBACf,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;wBACrB,UAAU,CAAC,KAAK,EAAE,CAAC;oBACpB,CAAC;yBAAM,CAAC;wBACP,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBAChC,CAAC;gBACF,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAChB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;oBACrB,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACzB,CAAC;YACF,CAAC;SACD,CAAC,CAAC;QACH,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACnF,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listeningUrl.d.ts","sourceRoot":"","sources":["../../src/adapters/listeningUrl.ts"],"names":[],"mappings":"AACA,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listeningUrl.js","sourceRoot":"","sources":["../../src/adapters/listeningUrl.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG,sCAAsC,CAAC;AACzD,MAAM,UAAU,YAAY,CAAC,IAAY;IACxC,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Effect, type Scope } from "effect";
|
|
2
|
+
import { HttpClient } from "effect/http";
|
|
3
|
+
import { type ReadFailure } from "@shivaedev/agent/failures.ts";
|
|
4
|
+
import type { ToolSessions } from "#adapters/toolSessions.ts";
|
|
5
|
+
import type { ProviderPort } from "#Provider.ts";
|
|
6
|
+
export declare const makeOpencodeServer: (url: string, tools: ToolSessions) => Effect.Effect<ProviderPort, ReadFailure, HttpClient.HttpClient | Scope.Scope>;
|
|
7
|
+
//# sourceMappingURL=makeOpencodeServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeOpencodeServer.d.ts","sourceRoot":"","sources":["../../src/adapters/makeOpencodeServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAU,KAAK,KAAK,EAAU,MAAM,QAAQ,CAAC;AACtE,OAAO,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,8BAA8B,CAAC;AAK1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAejD,eAAO,MAAM,kBAAkB,qHAoD7B,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Deferred, Effect, PubSub, Stream } from "effect";
|
|
2
|
+
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
|
|
3
|
+
import { Rejected } from "@shivaedev/agent/failures.ts";
|
|
4
|
+
import { checkStatus } from "@shivaedev/http/checkStatus.ts";
|
|
5
|
+
import { filterStatus } from "@shivaedev/http/filterStatus.ts";
|
|
6
|
+
import { openSseBuffer } from "#adapters/openSseBuffer.ts";
|
|
7
|
+
import { opencodeFailure, unavailable } from "#failure.ts";
|
|
8
|
+
function checkedPost(response, request) {
|
|
9
|
+
return HttpClientResponse.matchStatus(response, {
|
|
10
|
+
"4xx": (refused) => Effect.fail(new Rejected({
|
|
11
|
+
backend: "opencode",
|
|
12
|
+
message: `POST ${request.path} refused with HTTP ${refused.status}`,
|
|
13
|
+
providerCode: String(refused.status),
|
|
14
|
+
})),
|
|
15
|
+
orElse: (answered) => checkStatus(answered).pipe(Effect.as(answered)),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export const makeOpencodeServer = Effect.fn("OpenCode.makeOpencodeServer")(function* (url, tools) {
|
|
19
|
+
const native = yield* HttpClient.HttpClient;
|
|
20
|
+
const client = filterStatus(native);
|
|
21
|
+
const frames = yield* PubSub.unbounded();
|
|
22
|
+
const exited = yield* Deferred.make();
|
|
23
|
+
const ready = yield* Deferred.make();
|
|
24
|
+
const buffer = openSseBuffer(() => undefined);
|
|
25
|
+
const listen = client.get(new URL("/global/event", url).href).pipe(Effect.mapError(unavailable), Effect.flatMap((response) => Deferred.succeed(ready, undefined).pipe(Effect.andThen(response.stream.pipe(Stream.decodeText, Stream.flatMap((text) => Stream.fromIterable(buffer.take(text))), Stream.runForEach((frame) => PubSub.publish(frames, frame)))))), Effect.catch((error) => Deferred.fail(ready, unavailable(error))), Effect.ensuring(Deferred.succeed(exited, undefined)));
|
|
26
|
+
yield* Effect.forkScoped(listen);
|
|
27
|
+
yield* Deferred.await(ready);
|
|
28
|
+
function call(method) {
|
|
29
|
+
return (request) => {
|
|
30
|
+
const address = new URL(request.path, url);
|
|
31
|
+
for (const [key, value] of Object.entries(request.query)) {
|
|
32
|
+
address.searchParams.set(key, value);
|
|
33
|
+
}
|
|
34
|
+
const req = HttpClientRequest.make(method)(address.href);
|
|
35
|
+
const send = method === "POST"
|
|
36
|
+
? native.execute(HttpClientRequest.bodyJsonUnsafe(req, request.body)).pipe(Effect.flatMap((response) => checkedPost(response, request)))
|
|
37
|
+
: client.execute(req);
|
|
38
|
+
return send.pipe(Effect.mapError((error) => (error._tag === "Rejected" ? error : unavailable(error))), Effect.flatMap((response) => (response.status === 204 ? Effect.succeed(undefined) : response.json.pipe(Effect.mapError(opencodeFailure)))));
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
exited: Deferred.await(exited),
|
|
43
|
+
frames,
|
|
44
|
+
get: (request) => call("GET")(request).pipe(Effect.catchTag("Rejected", (error) => Effect.fail(opencodeFailure(error.message)))),
|
|
45
|
+
post: call("POST"),
|
|
46
|
+
tools,
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=makeOpencodeServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeOpencodeServer.js","sourceRoot":"","sources":["../../src/adapters/makeOpencodeServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAc,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAoB,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG3D,SAAS,WAAW,CAAC,QAA+C,EAAE,OAAwB;IAC7F,OAAO,kBAAkB,CAAC,WAAW,CAAC,QAAQ,EAAE;QAC/C,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAClB,MAAM,CAAC,IAAI,CACV,IAAI,QAAQ,CAAC;YACZ,OAAO,EAAE,UAAU;YACnB,OAAO,EAAE,QAAQ,OAAO,CAAC,IAAI,sBAAsB,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EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;gBACxI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACxB,OAAO,IAAI,CAAC,IAAI,CACf,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EACpF,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAC1I,CAAC;QACH,CAAC,CAAC;IACH,CAAC;IACD,OAAO;QACN,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC;QAC9B,MAAM;QACN,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAChI,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,KAAK;KACL,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Raw } from "@shivaedev/agent/eventData.ts";
|
|
2
|
+
import type { RunEvent as AgentEvent } from "@shivaedev/agent/events.ts";
|
|
3
|
+
type RawPayload = typeof Raw.Type;
|
|
4
|
+
export declare function rawOf(kind: string, payload: unknown): RawPayload;
|
|
5
|
+
export declare function rawEvent(raw: RawPayload): AgentEvent[];
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=mapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../src/adapters/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAEzE,KAAK,UAAU,GAAG,OAAO,GAAG,CAAC,IAAI,CAAC;AAClC,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,UAAU,CAMhE;AACD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,EAAE,CAEtD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.js","sourceRoot":"","sources":["../../src/adapters/mapping.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,KAAK,CAAC,IAAY,EAAE,OAAgB;IACnD,OAAO;QACN,IAAI;QACJ,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QAChC,MAAM,EAAE,UAAU;KAClB,CAAC;AACH,CAAC;AACD,MAAM,UAAU,QAAQ,CAAC,GAAe;IACvC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
2
|
+
export interface MessageAuthor {
|
|
3
|
+
readonly model: string | undefined;
|
|
4
|
+
readonly role: "agent" | "user";
|
|
5
|
+
}
|
|
6
|
+
export interface MessageAuthors {
|
|
7
|
+
readonly of: (messageId: string) => Option.Option<MessageAuthor>;
|
|
8
|
+
readonly record: (properties: unknown) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function openMessageAuthors(sessionModel: string | undefined): MessageAuthors;
|
|
11
|
+
//# sourceMappingURL=messageAuthors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageAuthors.d.ts","sourceRoot":"","sources":["../../src/adapters/messageAuthors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAExC,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;CAChC;AACD,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IACjE,QAAQ,CAAC,MAAM,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;CAC/C;AAKD,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,CAgBnF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Option, Schema } from "effect";
|
|
2
|
+
import { MessageUpdatedProperties } from "#adapters/MessageUpdatedProperties.ts";
|
|
3
|
+
const decodeMessage = Schema.decodeUnknownOption(MessageUpdatedProperties);
|
|
4
|
+
function modelOf(info, sessionModel) {
|
|
5
|
+
return info.providerID === undefined || info.modelID === undefined ? sessionModel : `${info.providerID}/${info.modelID}`;
|
|
6
|
+
}
|
|
7
|
+
export function openMessageAuthors(sessionModel) {
|
|
8
|
+
const authors = new Map();
|
|
9
|
+
return {
|
|
10
|
+
of: (messageId) => Option.fromNullishOr(authors.get(messageId)),
|
|
11
|
+
record: (properties) => {
|
|
12
|
+
Option.match(decodeMessage(properties), {
|
|
13
|
+
onNone: () => undefined,
|
|
14
|
+
onSome: ({ info }) => {
|
|
15
|
+
authors.set(info.id, {
|
|
16
|
+
model: modelOf(info, sessionModel),
|
|
17
|
+
role: info.role === "user" ? "user" : "agent",
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=messageAuthors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageAuthors.js","sourceRoot":"","sources":["../../src/adapters/messageAuthors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AASjF,MAAM,aAAa,GAAG,MAAM,CAAC,mBAAmB,CAAC,wBAAwB,CAAC,CAAC;AAC3E,SAAS,OAAO,CAAC,IAA+C,EAAE,YAAgC;IACjG,OAAO,IAAI,CAAC,UAAU,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;AAC1H,CAAC;AACD,MAAM,UAAU,kBAAkB,CAAC,YAAgC;IAClE,MAAM,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;IACjD,OAAO;QACN,EAAE,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/D,MAAM,EAAE,CAAC,UAAU,EAAE,EAAE;YACtB,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE;gBACvC,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS;gBACvB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;oBACpB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE;wBACpB,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC;wBAClC,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;qBAC7C,CAAC,CAAC;gBACJ,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openSseBuffer.d.ts","sourceRoot":"","sources":["../../src/adapters/openSseBuffer.ts"],"names":[],"mappings":"AAkBA,UAAU,SAAS;IAClB,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,EAAE,CAAC;CAC5C;AACD,wBAAgB,aAAa,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,SAAS,CAc5E"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Option, Schema } from "effect";
|
|
2
|
+
const decodeFrame = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
|
|
3
|
+
function dataFrames(chunk, onMalformed) {
|
|
4
|
+
const frames = [];
|
|
5
|
+
for (const line of chunk.split("\n")) {
|
|
6
|
+
if (!line.startsWith("data:")) {
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
const frame = decodeFrame(line.slice(5));
|
|
10
|
+
if (Option.isSome(frame)) {
|
|
11
|
+
frames.push(frame.value);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
onMalformed(line);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return frames;
|
|
18
|
+
}
|
|
19
|
+
export function openSseBuffer(onMalformed) {
|
|
20
|
+
let pending = "";
|
|
21
|
+
return {
|
|
22
|
+
take: (chunk) => {
|
|
23
|
+
pending += chunk;
|
|
24
|
+
const boundary = pending.lastIndexOf("\n");
|
|
25
|
+
if (boundary < 0) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const complete = pending.slice(0, boundary);
|
|
29
|
+
pending = pending.slice(boundary + 1);
|
|
30
|
+
return dataFrames(complete, onMalformed);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=openSseBuffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openSseBuffer.js","sourceRoot":"","sources":["../../src/adapters/openSseBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,WAAW,GAAG,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;AACtF,SAAS,UAAU,CAAC,KAAa,EAAE,WAAmC;IACrE,MAAM,MAAM,GAAc,EAAE,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,SAAS;QACV,CAAC;QACD,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACP,WAAW,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;IACF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAID,MAAM,UAAU,aAAa,CAAC,WAAmC;IAChE,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,OAAO;QACN,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;YACf,OAAO,IAAI,KAAK,CAAC;YACjB,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;gBAClB,OAAO,EAAE,CAAC;YACX,CAAC;YACD,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;YAC5C,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;YACtC,OAAO,UAAU,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC1C,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Raw } from "@shivaedev/agent/eventData.ts";
|
|
2
|
+
import type { RunEvent as AgentEvent } from "@shivaedev/agent/events.ts";
|
|
3
|
+
type RawPayload = typeof Raw.Type;
|
|
4
|
+
interface TurnBoundary {
|
|
5
|
+
readonly errored: (raw: RawPayload, properties: unknown) => AgentEvent[];
|
|
6
|
+
readonly idled: (raw: RawPayload) => AgentEvent[];
|
|
7
|
+
readonly status: (raw: RawPayload, properties: unknown) => AgentEvent[];
|
|
8
|
+
}
|
|
9
|
+
export declare function openTurnBoundary(): TurnBoundary;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=openTurnBoundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openTurnBoundary.d.ts","sourceRoot":"","sources":["../../src/adapters/openTurnBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAEzE,KAAK,UAAU,GAAG,OAAO,GAAG,CAAC,IAAI,CAAC;AAgBlC,UAAU,YAAY;IACrB,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,KAAK,UAAU,EAAE,CAAC;IACzE,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,UAAU,EAAE,CAAC;IAClD,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,KAAK,UAAU,EAAE,CAAC;CACxE;AACD,wBAAgB,gBAAgB,IAAI,YAAY,CAiC/C"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Option, Schema } from "effect";
|
|
2
|
+
import { rawEvent } from "#adapters/mapping.ts";
|
|
3
|
+
import { SessionErrorProperties, SessionStatusProperties } from "#adapters/protocol.ts";
|
|
4
|
+
const decodeStatus = Schema.decodeUnknownOption(SessionStatusProperties);
|
|
5
|
+
const decodeError = Schema.decodeUnknownOption(SessionErrorProperties);
|
|
6
|
+
function stateOf(type) {
|
|
7
|
+
if (type === "idle") {
|
|
8
|
+
return "awaiting-input";
|
|
9
|
+
}
|
|
10
|
+
return type === "busy" || type === "retry" ? "running" : undefined;
|
|
11
|
+
}
|
|
12
|
+
const ABORTED = "MessageAbortedError";
|
|
13
|
+
export function openTurnBoundary() {
|
|
14
|
+
let running = false;
|
|
15
|
+
let outcome;
|
|
16
|
+
return {
|
|
17
|
+
errored: (raw, properties) => {
|
|
18
|
+
outcome = Option.match(decodeError(properties), {
|
|
19
|
+
onNone: () => "failed",
|
|
20
|
+
onSome: ({ error }) => (error?.name === ABORTED ? "interrupted" : "failed"),
|
|
21
|
+
});
|
|
22
|
+
return rawEvent(raw);
|
|
23
|
+
},
|
|
24
|
+
idled: (raw) => {
|
|
25
|
+
if (!running) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
running = false;
|
|
29
|
+
const status = outcome ?? "completed";
|
|
30
|
+
outcome = undefined;
|
|
31
|
+
return [{ raw, state: status, type: "execution" }];
|
|
32
|
+
},
|
|
33
|
+
status: (raw, properties) => Option.match(decodeStatus(properties), {
|
|
34
|
+
onNone: () => rawEvent(raw),
|
|
35
|
+
onSome: ({ status }) => {
|
|
36
|
+
const state = stateOf(status.type);
|
|
37
|
+
if (state === undefined) {
|
|
38
|
+
return rawEvent(raw);
|
|
39
|
+
}
|
|
40
|
+
running = running || state === "running";
|
|
41
|
+
return [{ raw, state, type: "execution" }];
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=openTurnBoundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openTurnBoundary.js","sourceRoot":"","sources":["../../src/adapters/openTurnBoundary.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAExF,MAAM,YAAY,GAAG,MAAM,CAAC,mBAAmB,CAAC,uBAAuB,CAAC,CAAC;AACzE,MAAM,WAAW,GAAG,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;AACvE,SAAS,OAAO,CAAC,IAAY;IAC5B,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACrB,OAAO,gBAAgB,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACpE,CAAC;AACD,MAAM,OAAO,GAAG,qBAAqB,CAAC;AAMtC,MAAM,UAAU,gBAAgB;IAC/B,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,OAA6C,CAAC;IAClD,OAAO;QACN,OAAO,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE;YAC5B,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE;gBAC/C,MAAM,EAAE,GAAG,EAAE,CAAC,QAAiB;gBAC/B,MAAM,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
+
tool: string;
|
|
5
|
+
"sessionID": string;
|
|
6
|
+
"callID": string;
|
|
7
|
+
}, output: {
|
|
8
|
+
args: Record<string, unknown>;
|
|
9
|
+
}) => void;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=opencodePlugin.config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencodePlugin.config.d.ts","sourceRoot":"","sources":["../../src/adapters/opencodePlugin.config.ts"],"names":[],"mappings":";;IACC,qBAAqB,UACb;QACN,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;KACjB,UACO;QACP,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC9B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default () => ({
|
|
2
|
+
"tool.execute.before": (input, output) => {
|
|
3
|
+
if (input.tool.startsWith("platform_")) {
|
|
4
|
+
output.args.callerSession = input.sessionID;
|
|
5
|
+
output.args.callerCall = input.callID;
|
|
6
|
+
}
|
|
7
|
+
},
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=opencodePlugin.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencodePlugin.config.js","sourceRoot":"","sources":["../../src/adapters/opencodePlugin.config.ts"],"names":[],"mappings":"AAAA,eAAe,GAAG,EAAE,CAAC,CAAC;IACrB,qBAAqB,EAAE,CACtB,KAIC,EACD,MAEC,EACA,EAAE;QACH,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,SAAS,CAAC;YAC5C,MAAM,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC;QACvC,CAAC;IACF,CAAC;CACD,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Raw } from "@shivaedev/agent/eventData.ts";
|
|
2
|
+
import type { RunEvent as AgentEvent } from "@shivaedev/agent/events.ts";
|
|
3
|
+
type RawPayload = typeof Raw.Type;
|
|
4
|
+
import type { MessageAuthors } from "#adapters/messageAuthors.ts";
|
|
5
|
+
export declare function partEvents(raw: RawPayload, properties: unknown, authors: MessageAuthors, firstReport: (key: string) => boolean): AgentEvent[];
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=partEvents.d.ts.map
|