@opencode/sdk 2.0.8 → 2.0.10
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/chunks/tool-39225h8g.js +23 -0
- package/dist/chunks/tool-6mdnn00j.js +15 -0
- package/dist/chunks/tool-9rqn6x4v.js +16 -0
- package/dist/chunks/tool-ahrtyrb8.js +47 -0
- package/dist/chunks/tool-czgpaf6v.js +54 -0
- package/dist/chunks/tool-j1jhtwv7.js +29 -0
- package/dist/chunks/tool-jw22y9b0.js +14 -0
- package/dist/chunks/tool-kk7b7gft.js +45 -0
- package/dist/chunks/tool-pqb0kjhx.js +62 -0
- package/dist/chunks/tool-wyq33nd6.js +125 -0
- package/dist/chunks/tool-xjkw3602.js +14 -0
- package/dist/chunks/tool-ya9awdj2.js +55 -0
- package/dist/contracts.js +58 -26
- package/dist/effect/index.js +74 -4
- package/dist/effect/opencode.js +16 -28
- package/dist/effect/tool.js +8 -2
- package/dist/effect/workerd.js +32 -7
- package/dist/index.js +75 -4
- package/dist/internal/fetch.js +8 -106
- package/dist/internal/host.d.ts +1 -1
- package/dist/internal/host.js +11 -32
- package/dist/internal/instances.js +12 -45
- package/dist/internal/workerd.js +8 -12
- package/dist/logging.js +8 -46
- package/dist/opencode.js +11 -2
- package/dist/promise.js +12 -30
- package/dist/tool.js +8 -2
- package/dist/workerd.js +27 -6
- package/package.json +10 -10
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./tool-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/internal/workerd.ts
|
|
6
|
+
var exports_workerd = {};
|
|
7
|
+
__export(exports_workerd, {
|
|
8
|
+
WorkerdProfile: () => exports_workerd,
|
|
9
|
+
make: () => make2
|
|
10
|
+
});
|
|
11
|
+
import { ServerWorkerd } from "@opencode/server/workerd";
|
|
12
|
+
function make2({ config, ...options }) {
|
|
13
|
+
const server = {
|
|
14
|
+
...options,
|
|
15
|
+
config: config === undefined ? undefined : { content: JSON.stringify(config) }
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
options: ServerWorkerd.serverOptions(server),
|
|
19
|
+
replacements: ServerWorkerd.replacements(server)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { make2, exports_workerd };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
create4
|
|
3
|
+
} from "./tool-ahrtyrb8.js";
|
|
4
|
+
import {
|
|
5
|
+
__export
|
|
6
|
+
} from "./tool-9rqn6x4v.js";
|
|
7
|
+
|
|
8
|
+
// src/opencode.ts
|
|
9
|
+
var exports_opencode2 = {};
|
|
10
|
+
__export(exports_opencode2, {
|
|
11
|
+
create: () => create3
|
|
12
|
+
});
|
|
13
|
+
var create3 = (options = {}) => create4(options);
|
|
14
|
+
|
|
15
|
+
export { create3, exports_opencode2 };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __returnValue = (v) => v;
|
|
3
|
+
function __exportSetter(name, newValue) {
|
|
4
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
5
|
+
}
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
set: __exportSetter.bind(all, name)
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { __export };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
create5
|
|
3
|
+
} from "./tool-czgpaf6v.js";
|
|
4
|
+
import {
|
|
5
|
+
__export
|
|
6
|
+
} from "./tool-9rqn6x4v.js";
|
|
7
|
+
|
|
8
|
+
// src/promise.ts
|
|
9
|
+
var exports_promise = {};
|
|
10
|
+
__export(exports_promise, {
|
|
11
|
+
PromiseSdk: () => exports_promise,
|
|
12
|
+
create: () => create4
|
|
13
|
+
});
|
|
14
|
+
import { OpenCode } from "@opencode/client";
|
|
15
|
+
import { Session } from "@opencode/schema/session";
|
|
16
|
+
import { Effect, Schema } from "effect";
|
|
17
|
+
async function create4(options = {}, embed = {}) {
|
|
18
|
+
const { plugins, instances, ...hostOptions } = options;
|
|
19
|
+
const host = await Effect.runPromise(create5({
|
|
20
|
+
...hostOptions,
|
|
21
|
+
instances: instances ? {
|
|
22
|
+
key: (session) => instances.key(Schema.encodeSync(Session.Info)(session)),
|
|
23
|
+
configure: (key) => Effect.gen(function* () {
|
|
24
|
+
const { PluginPromise } = yield* Effect.promise(() => import("@opencode/core/plugin/promise"));
|
|
25
|
+
const configuration = yield* Effect.tryPromise(async () => instances.configure(key));
|
|
26
|
+
return { plugins: configuration.plugins.map(PluginPromise.fromPromise) };
|
|
27
|
+
})
|
|
28
|
+
} : undefined
|
|
29
|
+
}, embed));
|
|
30
|
+
const client = OpenCode.make({ baseUrl: "http://opencode.local", fetch: host.fetch });
|
|
31
|
+
const register = async (plugin) => {
|
|
32
|
+
const { PluginPromise } = await import("@opencode/core/plugin/promise");
|
|
33
|
+
return host.runtime.runPromise(host.plugins.register(PluginPromise.fromPromise(plugin)));
|
|
34
|
+
};
|
|
35
|
+
for (const plugin of plugins ?? [])
|
|
36
|
+
await register(plugin);
|
|
37
|
+
return {
|
|
38
|
+
...client,
|
|
39
|
+
sessions: client.session,
|
|
40
|
+
events: client.event,
|
|
41
|
+
plugin: Object.assign(register, client.plugin),
|
|
42
|
+
close: host.close,
|
|
43
|
+
[Symbol.asyncDispose]: host.close
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { create4, exports_promise };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
layer4,
|
|
3
|
+
context2
|
|
4
|
+
} from "./tool-ya9awdj2.js";
|
|
5
|
+
import {
|
|
6
|
+
make3
|
|
7
|
+
} from "./tool-wyq33nd6.js";
|
|
8
|
+
import {
|
|
9
|
+
provide2,
|
|
10
|
+
node2
|
|
11
|
+
} from "./tool-pqb0kjhx.js";
|
|
12
|
+
import {
|
|
13
|
+
__export
|
|
14
|
+
} from "./tool-9rqn6x4v.js";
|
|
15
|
+
|
|
16
|
+
// src/internal/host.ts
|
|
17
|
+
var exports_host = {};
|
|
18
|
+
__export(exports_host, {
|
|
19
|
+
EmbeddedHost: () => exports_host,
|
|
20
|
+
create: () => create5
|
|
21
|
+
});
|
|
22
|
+
import { SdkPlugins } from "@opencode/core/plugin/sdk";
|
|
23
|
+
import { SessionRestart } from "@opencode/core/session/execution/restart";
|
|
24
|
+
import { Session } from "@opencode/core/session";
|
|
25
|
+
import { Workspace } from "@opencode/core/workspace";
|
|
26
|
+
import { WorkspaceDriver } from "@opencode/core/workspace/driver";
|
|
27
|
+
import { createEmbeddedRoutes } from "@opencode/server/routes";
|
|
28
|
+
import { Context, Effect, Layer, ManagedRuntime } from "effect";
|
|
29
|
+
import { HttpEffect, HttpRouter, HttpServer } from "effect/unstable/http";
|
|
30
|
+
var create5 = Effect.fn("EmbeddedHost.create")(function* (options = {}, embed = {}) {
|
|
31
|
+
const { log, workspaceProviders, instances, ...server } = options;
|
|
32
|
+
const selector = instances ? provide2(instances, yield* Effect.context()) : undefined;
|
|
33
|
+
const runtime = ManagedRuntime.make(createEmbeddedRoutes({
|
|
34
|
+
...server,
|
|
35
|
+
app: { ...server.app, name: server.app?.name ?? "sdk" },
|
|
36
|
+
database: { path: ":memory:", ...server.database }
|
|
37
|
+
}, workspaceProviders ? [...embed.overrides ?? [], WorkspaceDriver.node.replace(WorkspaceDriver.registryNode(workspaceProviders))] : embed.overrides, selector ? (replacements) => node2(selector, replacements) : undefined).pipe(Layer.provide(HttpServer.layerServices), Layer.provideMerge(layer4(log))));
|
|
38
|
+
return yield* Effect.gen(function* () {
|
|
39
|
+
const services = yield* runtime.contextEffect;
|
|
40
|
+
runtime.runFork(Context.get(services, SessionRestart.Service).resumeSuspendedSessions);
|
|
41
|
+
const handler = HttpEffect.toWebHandlerWith(context2(services))(Context.get(services, HttpRouter.HttpRouter).asHttpEffect());
|
|
42
|
+
const transport = make3(handler, runtime.dispose);
|
|
43
|
+
return {
|
|
44
|
+
runtime,
|
|
45
|
+
fetch: transport.fetch,
|
|
46
|
+
plugins: Context.get(services, SdkPlugins.Service),
|
|
47
|
+
sessions: Context.get(services, Session.Service),
|
|
48
|
+
workspace: Context.get(services, Workspace.Service),
|
|
49
|
+
close: transport.close
|
|
50
|
+
};
|
|
51
|
+
}).pipe(Effect.onError(() => runtime.disposeEffect));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export { create5, exports_host };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/contracts.ts
|
|
2
|
+
import { Agent as Agent2 } from "@opencode/schema/agent";
|
|
3
|
+
import { Command as Command2 } from "@opencode/schema/command";
|
|
4
|
+
import { Config as Config2 } from "@opencode/schema/config";
|
|
5
|
+
import { Credential as Credential2 } from "@opencode/schema/credential";
|
|
6
|
+
import { Event as Event2 } from "@opencode/schema/event";
|
|
7
|
+
import { FileSystem as FileSystem2 } from "@opencode/schema/filesystem";
|
|
8
|
+
import { Integration as Integration2 } from "@opencode/schema/integration";
|
|
9
|
+
import { Location as Location2 } from "@opencode/schema/location";
|
|
10
|
+
import { Model as Model2 } from "@opencode/schema/model";
|
|
11
|
+
import { Permission as Permission2 } from "@opencode/schema/permission";
|
|
12
|
+
import { PermissionSaved as PermissionSaved2 } from "@opencode/schema/permission-saved";
|
|
13
|
+
import { Project as Project2 } from "@opencode/schema/project";
|
|
14
|
+
import { Worktree as Worktree2 } from "@opencode/schema/worktree";
|
|
15
|
+
import { Prompt as Prompt2 } from "@opencode/schema/prompt";
|
|
16
|
+
import { PromptInput as PromptInput2 } from "@opencode/schema/prompt-input";
|
|
17
|
+
import { Provider as Provider2 } from "@opencode/schema/provider";
|
|
18
|
+
import { Pty as Pty2 } from "@opencode/schema/pty";
|
|
19
|
+
import { Question as Question2 } from "@opencode/schema/question";
|
|
20
|
+
import { Reference as Reference2 } from "@opencode/schema/reference";
|
|
21
|
+
import { WebSearch as WebSearch2 } from "@opencode/schema/websearch";
|
|
22
|
+
import { AbsolutePath as AbsolutePath2, RelativePath as RelativePath2 } from "@opencode/schema/schema";
|
|
23
|
+
import { Session as Session2 } from "@opencode/schema/session";
|
|
24
|
+
import { SessionInbox as SessionInbox2 } from "@opencode/schema/session-inbox";
|
|
25
|
+
import { SessionMessage as SessionMessage2 } from "@opencode/schema/session-message";
|
|
26
|
+
import { Skill as Skill2 } from "@opencode/schema/skill";
|
|
27
|
+
import { Workspace as Workspace2 } from "@opencode/schema/workspace";
|
|
28
|
+
|
|
29
|
+
export { Agent2, Command2, Config2, Credential2, Event2, FileSystem2, Integration2, Location2, Model2, Permission2, PermissionSaved2, Project2, Worktree2, Prompt2, PromptInput2, Provider2, Pty2, Question2, Reference2, WebSearch2, AbsolutePath2, RelativePath2, Session2, SessionInbox2, SessionMessage2, Skill2, Workspace2 };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./tool-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/tool.ts
|
|
6
|
+
var exports_tool = {};
|
|
7
|
+
__export(exports_tool, {
|
|
8
|
+
Error: () => Error2,
|
|
9
|
+
RegistrationError: () => RegistrationError2
|
|
10
|
+
});
|
|
11
|
+
import { RegistrationError as RegistrationError2 } from "@opencode/core/tool";
|
|
12
|
+
import { Error as Error2 } from "@opencode/schema/tool";
|
|
13
|
+
|
|
14
|
+
export { exports_tool, RegistrationError2, Error2 };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
create5
|
|
3
|
+
} from "./tool-czgpaf6v.js";
|
|
4
|
+
import {
|
|
5
|
+
__export
|
|
6
|
+
} from "./tool-9rqn6x4v.js";
|
|
7
|
+
|
|
8
|
+
// src/effect/opencode.ts
|
|
9
|
+
var exports_opencode = {};
|
|
10
|
+
__export(exports_opencode, {
|
|
11
|
+
OpenCode: () => exports_opencode,
|
|
12
|
+
Service: () => Service2,
|
|
13
|
+
create: () => create2,
|
|
14
|
+
layer: () => layer2
|
|
15
|
+
});
|
|
16
|
+
import { OpenCode } from "@opencode/client/effect";
|
|
17
|
+
import { Context, Effect, Layer } from "effect";
|
|
18
|
+
import { FetchHttpClient, HttpClient } from "effect/unstable/http";
|
|
19
|
+
var create2 = Effect.fn("OpenCode.create")(function* (options = {}, embed = {}) {
|
|
20
|
+
const host = yield* Effect.acquireRelease(create5(options, embed), (host) => Effect.promise(host.close));
|
|
21
|
+
const httpClient = yield* HttpClient.HttpClient.pipe(Effect.provide(FetchHttpClient.layer));
|
|
22
|
+
const client = yield* OpenCode.make({ baseUrl: "http://opencode.local" }).pipe(Effect.provideService(HttpClient.HttpClient, HttpClient.transformResponse(httpClient, Effect.provideService(FetchHttpClient.Fetch, host.fetch))));
|
|
23
|
+
return {
|
|
24
|
+
...client,
|
|
25
|
+
sessions: {
|
|
26
|
+
...client.session,
|
|
27
|
+
create: host.sessions.create,
|
|
28
|
+
get: (input) => host.sessions.get(input.sessionID),
|
|
29
|
+
move: host.sessions.move
|
|
30
|
+
},
|
|
31
|
+
events: client.event,
|
|
32
|
+
workspace: {
|
|
33
|
+
create: host.workspace.create,
|
|
34
|
+
provision: ({ workspaceID }) => host.workspace.provision(workspaceID),
|
|
35
|
+
destroy: ({ workspaceID }) => host.workspace.destroy(workspaceID)
|
|
36
|
+
},
|
|
37
|
+
plugin: Object.assign(host.plugins.register, client.plugin)
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
class Service2 extends Context.Service()("@opencode/sdk/OpenCode") {
|
|
42
|
+
}
|
|
43
|
+
var layer2 = (options = {}) => Layer.effect(Service2, create2(options));
|
|
44
|
+
|
|
45
|
+
export { create2, Service2, layer2, exports_opencode };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./tool-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/internal/instances.ts
|
|
6
|
+
var exports_instances = {};
|
|
7
|
+
__export(exports_instances, {
|
|
8
|
+
SdkInstances: () => exports_instances,
|
|
9
|
+
layer: () => layer3,
|
|
10
|
+
node: () => node2,
|
|
11
|
+
provide: () => provide2
|
|
12
|
+
});
|
|
13
|
+
import { Instance } from "@opencode/core/instance";
|
|
14
|
+
import { LocationServiceMap } from "@opencode/core/location-service-map";
|
|
15
|
+
import { Plugin } from "@opencode/core/plugin";
|
|
16
|
+
import { Location } from "@opencode/schema/location";
|
|
17
|
+
import { makeGlobalNode } from "@opencode/util/effect/app-node";
|
|
18
|
+
import { Context, Duration, Effect, Layer, LayerMap } from "effect";
|
|
19
|
+
function provide2(options, context) {
|
|
20
|
+
return {
|
|
21
|
+
key: options.key,
|
|
22
|
+
configure: (key) => options.configure(key).pipe(Effect.updateContext((ambient) => Context.merge(context, ambient)))
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function node2(options, replacements) {
|
|
26
|
+
return makeGlobalNode({
|
|
27
|
+
service: Instance.Service,
|
|
28
|
+
layer: layer3(options, replacements),
|
|
29
|
+
deps: [LocationServiceMap.node]
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function layer3(options, replacements) {
|
|
33
|
+
return Layer.effect(Instance.Service, Effect.gen(function* () {
|
|
34
|
+
const scope = yield* Effect.scope;
|
|
35
|
+
const locations = yield* LocationServiceMap.Service;
|
|
36
|
+
const key = (session) => ({
|
|
37
|
+
key: options.key(session),
|
|
38
|
+
...LocationServiceMap.canonical(session.location)
|
|
39
|
+
});
|
|
40
|
+
const provide = (session) => Effect.provide(instances.get(key(session)));
|
|
41
|
+
const instances = yield* LayerMap.make((input) => Layer.unwrap(Effect.gen(function* () {
|
|
42
|
+
const configuration = yield* options.configure(input.key).pipe(Effect.orDie);
|
|
43
|
+
return Instance.layer(Location.Ref.make({ directory: input.directory, workspaceID: input.workspaceID }), {
|
|
44
|
+
plugins: configuration.plugins,
|
|
45
|
+
replacements: [
|
|
46
|
+
...replacements(),
|
|
47
|
+
Instance.node.replace(Layer.succeed(Instance.Service, { provide })),
|
|
48
|
+
LocationServiceMap.node.replace(Layer.succeed(LocationServiceMap.Service, locations))
|
|
49
|
+
]
|
|
50
|
+
}).pipe(Layer.tap((context) => Effect.gen(function* () {
|
|
51
|
+
const plugins = yield* Plugin.Service;
|
|
52
|
+
yield* plugins.awaitActivation;
|
|
53
|
+
const failed = (yield* plugins.list()).filter((plugin) => plugin.state.status === "failed" && configuration.plugins.some((configured) => configured.id === plugin.id));
|
|
54
|
+
if (failed.length > 0)
|
|
55
|
+
yield* Effect.die(new Error(`Instance plugin setup failed: ${failed.map((plugin) => plugin.id).join(", ")}`));
|
|
56
|
+
}).pipe(Effect.provide(context))));
|
|
57
|
+
})).pipe(Layer.tapCause(() => instances.invalidate(input).pipe(Effect.forkIn(scope, { startImmediately: true }), Effect.asVoid))), { idleTimeToLive: Duration.infinity });
|
|
58
|
+
return Instance.Service.of({ provide });
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { provide2, node2, layer3, exports_instances };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./tool-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/internal/fetch.ts
|
|
6
|
+
var exports_fetch = {};
|
|
7
|
+
__export(exports_fetch, {
|
|
8
|
+
OwnedFetch: () => exports_fetch,
|
|
9
|
+
make: () => make3
|
|
10
|
+
});
|
|
11
|
+
function make3(handler, dispose) {
|
|
12
|
+
const requests = new Set;
|
|
13
|
+
const shutdown = new AbortController;
|
|
14
|
+
const closed = new Error("OpenCode host is closed");
|
|
15
|
+
let closePromise;
|
|
16
|
+
const fetch = Object.assign((input, init) => {
|
|
17
|
+
if (closePromise)
|
|
18
|
+
return Promise.reject(closed);
|
|
19
|
+
const source = new Request(input, init);
|
|
20
|
+
if (source.signal.aborted)
|
|
21
|
+
return Promise.reject(source.signal.reason);
|
|
22
|
+
const request = new Request(source, { signal: AbortSignal.any([source.signal, shutdown.signal]) });
|
|
23
|
+
const lifetime = Promise.withResolvers();
|
|
24
|
+
const finish = () => {
|
|
25
|
+
requests.delete(lifetime.promise);
|
|
26
|
+
lifetime.resolve();
|
|
27
|
+
};
|
|
28
|
+
requests.add(lifetime.promise);
|
|
29
|
+
const handled = handler(request);
|
|
30
|
+
return rejectOnAbort(handled, request.signal).then((response) => trackResponse(response, request.signal, finish), (cause) => {
|
|
31
|
+
handled.then(finish, finish);
|
|
32
|
+
throw cause;
|
|
33
|
+
});
|
|
34
|
+
}, { preconnect: () => {
|
|
35
|
+
return;
|
|
36
|
+
} });
|
|
37
|
+
const close = () => {
|
|
38
|
+
if (closePromise)
|
|
39
|
+
return closePromise;
|
|
40
|
+
closePromise = Promise.resolve().then(async () => {
|
|
41
|
+
shutdown.abort(closed);
|
|
42
|
+
await Promise.allSettled(requests);
|
|
43
|
+
await dispose();
|
|
44
|
+
});
|
|
45
|
+
return closePromise;
|
|
46
|
+
};
|
|
47
|
+
return { fetch, close };
|
|
48
|
+
}
|
|
49
|
+
function rejectOnAbort(promise, signal) {
|
|
50
|
+
if (signal.aborted)
|
|
51
|
+
return Promise.reject(signal.reason);
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const abort = () => reject(signal.reason);
|
|
54
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
55
|
+
promise.then((value) => {
|
|
56
|
+
signal.removeEventListener("abort", abort);
|
|
57
|
+
resolve(value);
|
|
58
|
+
}, (cause) => {
|
|
59
|
+
signal.removeEventListener("abort", abort);
|
|
60
|
+
reject(cause);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function trackResponse(response, signal, finish) {
|
|
65
|
+
if (!response.body) {
|
|
66
|
+
finish();
|
|
67
|
+
return response;
|
|
68
|
+
}
|
|
69
|
+
const reader = response.body.getReader();
|
|
70
|
+
let done = false;
|
|
71
|
+
let abort = () => {};
|
|
72
|
+
const complete = () => {
|
|
73
|
+
if (done)
|
|
74
|
+
return false;
|
|
75
|
+
done = true;
|
|
76
|
+
signal.removeEventListener("abort", abort);
|
|
77
|
+
return true;
|
|
78
|
+
};
|
|
79
|
+
const body = new ReadableStream({
|
|
80
|
+
start(controller) {
|
|
81
|
+
abort = () => {
|
|
82
|
+
if (!complete())
|
|
83
|
+
return;
|
|
84
|
+
controller.error(signal.reason);
|
|
85
|
+
reader.cancel(signal.reason).then(finish, finish);
|
|
86
|
+
};
|
|
87
|
+
if (signal.aborted)
|
|
88
|
+
abort();
|
|
89
|
+
else
|
|
90
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
91
|
+
},
|
|
92
|
+
async pull(controller) {
|
|
93
|
+
try {
|
|
94
|
+
const next = await reader.read();
|
|
95
|
+
if (done)
|
|
96
|
+
return;
|
|
97
|
+
if (!next.done) {
|
|
98
|
+
controller.enqueue(next.value);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (!complete())
|
|
102
|
+
return;
|
|
103
|
+
controller.close();
|
|
104
|
+
finish();
|
|
105
|
+
} catch (cause) {
|
|
106
|
+
if (!complete())
|
|
107
|
+
return;
|
|
108
|
+
controller.error(cause);
|
|
109
|
+
finish();
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
async cancel(reason) {
|
|
113
|
+
if (!complete())
|
|
114
|
+
return;
|
|
115
|
+
try {
|
|
116
|
+
await reader.cancel(reason);
|
|
117
|
+
} finally {
|
|
118
|
+
finish();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return new Response(body, response);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export { make3, exports_fetch };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./tool-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/effect/tool.ts
|
|
6
|
+
var exports_tool2 = {};
|
|
7
|
+
__export(exports_tool2, {
|
|
8
|
+
Error: () => Error3,
|
|
9
|
+
RegistrationError: () => RegistrationError3
|
|
10
|
+
});
|
|
11
|
+
import { RegistrationError as RegistrationError3 } from "@opencode/core/tool";
|
|
12
|
+
import { Error as Error3 } from "@opencode/schema/tool";
|
|
13
|
+
|
|
14
|
+
export { exports_tool2, RegistrationError3, Error3 };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/logging.ts
|
|
2
|
+
import { Context, Formatter, Layer, Logger, References } from "effect";
|
|
3
|
+
var levels = {
|
|
4
|
+
trace: "Trace",
|
|
5
|
+
debug: "Debug",
|
|
6
|
+
info: "Info",
|
|
7
|
+
warn: "Warn",
|
|
8
|
+
error: "Error",
|
|
9
|
+
fatal: "Fatal"
|
|
10
|
+
};
|
|
11
|
+
var levelNames = new Map([
|
|
12
|
+
[levels.trace, "trace"],
|
|
13
|
+
[levels.debug, "debug"],
|
|
14
|
+
[levels.info, "info"],
|
|
15
|
+
[levels.warn, "warn"],
|
|
16
|
+
[levels.error, "error"],
|
|
17
|
+
[levels.fatal, "fatal"]
|
|
18
|
+
]);
|
|
19
|
+
function normalizeLevel(level) {
|
|
20
|
+
return levelNames.get(level);
|
|
21
|
+
}
|
|
22
|
+
function layer4(log) {
|
|
23
|
+
const logger = Logger.make((options) => {
|
|
24
|
+
if (!log)
|
|
25
|
+
return;
|
|
26
|
+
const level = normalizeLevel(options.logLevel);
|
|
27
|
+
if (!level)
|
|
28
|
+
return;
|
|
29
|
+
const entry = Logger.formatStructured.log(options);
|
|
30
|
+
const values = Array.isArray(entry.message) ? entry.message : [entry.message];
|
|
31
|
+
const [message, ...data] = values;
|
|
32
|
+
const details = data.length === 1 && !Array.isArray(data[0]) ? data[0] : undefined;
|
|
33
|
+
const { cause: detailCause, ...detailAttributes } = details ?? {};
|
|
34
|
+
const attributes = {
|
|
35
|
+
...entry.annotations,
|
|
36
|
+
...detailAttributes,
|
|
37
|
+
...Object.keys(entry.spans).length > 0 ? { spans: entry.spans } : {},
|
|
38
|
+
...!details && data.length > 0 ? { data: data.length === 1 ? data[0] : data } : {}
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
log.emit({
|
|
42
|
+
level,
|
|
43
|
+
message: typeof message === "string" ? message : Formatter.format(message),
|
|
44
|
+
...Object.keys(attributes).length > 0 ? { attributes } : {},
|
|
45
|
+
...entry.cause === undefined && detailCause === undefined ? {} : { cause: entry.cause ?? detailCause }
|
|
46
|
+
});
|
|
47
|
+
} catch {}
|
|
48
|
+
});
|
|
49
|
+
return Layer.merge(Logger.layer([logger], { mergeWithExisting: false }), Layer.succeed(References.MinimumLogLevel, levels[log?.level ?? "info"]));
|
|
50
|
+
}
|
|
51
|
+
function context2(source) {
|
|
52
|
+
return Context.make(Logger.CurrentLoggers, Context.get(source, Logger.CurrentLoggers)).pipe(Context.add(References.MinimumLogLevel, Context.get(source, References.MinimumLogLevel)));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { layer4, context2 };
|
package/dist/contracts.js
CHANGED
|
@@ -1,26 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
import {
|
|
2
|
+
Agent2,
|
|
3
|
+
Command2,
|
|
4
|
+
Config2,
|
|
5
|
+
Credential2,
|
|
6
|
+
Event2,
|
|
7
|
+
FileSystem2,
|
|
8
|
+
Integration2,
|
|
9
|
+
Location2,
|
|
10
|
+
Model2,
|
|
11
|
+
Permission2,
|
|
12
|
+
PermissionSaved2,
|
|
13
|
+
Project2,
|
|
14
|
+
Worktree2,
|
|
15
|
+
Prompt2,
|
|
16
|
+
PromptInput2,
|
|
17
|
+
Provider2,
|
|
18
|
+
Pty2,
|
|
19
|
+
Question2,
|
|
20
|
+
Reference2,
|
|
21
|
+
WebSearch2,
|
|
22
|
+
AbsolutePath2,
|
|
23
|
+
RelativePath2,
|
|
24
|
+
Session2,
|
|
25
|
+
SessionInbox2,
|
|
26
|
+
SessionMessage2,
|
|
27
|
+
Skill2,
|
|
28
|
+
Workspace2
|
|
29
|
+
} from "./chunks/tool-j1jhtwv7.js";
|
|
30
|
+
export {
|
|
31
|
+
AbsolutePath2 as AbsolutePath,
|
|
32
|
+
Agent2 as Agent,
|
|
33
|
+
Command2 as Command,
|
|
34
|
+
Config2 as Config,
|
|
35
|
+
Credential2 as Credential,
|
|
36
|
+
Event2 as Event,
|
|
37
|
+
FileSystem2 as FileSystem,
|
|
38
|
+
Integration2 as Integration,
|
|
39
|
+
Location2 as Location,
|
|
40
|
+
Model2 as Model,
|
|
41
|
+
Permission2 as Permission,
|
|
42
|
+
PermissionSaved2 as PermissionSaved,
|
|
43
|
+
Project2 as Project,
|
|
44
|
+
Prompt2 as Prompt,
|
|
45
|
+
PromptInput2 as PromptInput,
|
|
46
|
+
Provider2 as Provider,
|
|
47
|
+
Pty2 as Pty,
|
|
48
|
+
Question2 as Question,
|
|
49
|
+
Reference2 as Reference,
|
|
50
|
+
RelativePath2 as RelativePath,
|
|
51
|
+
Session2 as Session,
|
|
52
|
+
SessionInbox2 as SessionInbox,
|
|
53
|
+
SessionMessage2 as SessionMessage,
|
|
54
|
+
Skill2 as Skill,
|
|
55
|
+
WebSearch2 as WebSearch,
|
|
56
|
+
Workspace2 as Workspace,
|
|
57
|
+
Worktree2 as Worktree
|
|
58
|
+
};
|
package/dist/effect/index.js
CHANGED
|
@@ -1,4 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import"../chunks/tool-ya9awdj2.js";
|
|
2
|
+
import"../chunks/tool-wyq33nd6.js";
|
|
3
|
+
import"../chunks/tool-pqb0kjhx.js";
|
|
4
|
+
import"../chunks/tool-czgpaf6v.js";
|
|
5
|
+
import {
|
|
6
|
+
exports_opencode
|
|
7
|
+
} from "../chunks/tool-kk7b7gft.js";
|
|
8
|
+
import {
|
|
9
|
+
exports_tool2
|
|
10
|
+
} from "../chunks/tool-xjkw3602.js";
|
|
11
|
+
import {
|
|
12
|
+
Agent2,
|
|
13
|
+
Command2,
|
|
14
|
+
Config2,
|
|
15
|
+
Credential2,
|
|
16
|
+
Event2,
|
|
17
|
+
FileSystem2,
|
|
18
|
+
Integration2,
|
|
19
|
+
Location2,
|
|
20
|
+
Model2,
|
|
21
|
+
Permission2,
|
|
22
|
+
PermissionSaved2,
|
|
23
|
+
Project2,
|
|
24
|
+
Worktree2,
|
|
25
|
+
Prompt2,
|
|
26
|
+
PromptInput2,
|
|
27
|
+
Provider2,
|
|
28
|
+
Pty2,
|
|
29
|
+
Question2,
|
|
30
|
+
Reference2,
|
|
31
|
+
WebSearch2,
|
|
32
|
+
AbsolutePath2,
|
|
33
|
+
RelativePath2,
|
|
34
|
+
Session2,
|
|
35
|
+
SessionInbox2,
|
|
36
|
+
SessionMessage2,
|
|
37
|
+
Skill2,
|
|
38
|
+
Workspace2
|
|
39
|
+
} from "../chunks/tool-j1jhtwv7.js";
|
|
40
|
+
|
|
41
|
+
// src/effect/index.ts
|
|
42
|
+
import { ClientError } from "@opencode/client/effect";
|
|
43
|
+
export {
|
|
44
|
+
AbsolutePath2 as AbsolutePath,
|
|
45
|
+
Agent2 as Agent,
|
|
46
|
+
ClientError,
|
|
47
|
+
Command2 as Command,
|
|
48
|
+
Config2 as Config,
|
|
49
|
+
Credential2 as Credential,
|
|
50
|
+
Event2 as Event,
|
|
51
|
+
FileSystem2 as FileSystem,
|
|
52
|
+
Integration2 as Integration,
|
|
53
|
+
Location2 as Location,
|
|
54
|
+
Model2 as Model,
|
|
55
|
+
exports_opencode as OpenCode,
|
|
56
|
+
Permission2 as Permission,
|
|
57
|
+
PermissionSaved2 as PermissionSaved,
|
|
58
|
+
Project2 as Project,
|
|
59
|
+
Prompt2 as Prompt,
|
|
60
|
+
PromptInput2 as PromptInput,
|
|
61
|
+
Provider2 as Provider,
|
|
62
|
+
Pty2 as Pty,
|
|
63
|
+
Question2 as Question,
|
|
64
|
+
Reference2 as Reference,
|
|
65
|
+
RelativePath2 as RelativePath,
|
|
66
|
+
Session2 as Session,
|
|
67
|
+
SessionInbox2 as SessionInbox,
|
|
68
|
+
SessionMessage2 as SessionMessage,
|
|
69
|
+
Skill2 as Skill,
|
|
70
|
+
exports_tool2 as Tool,
|
|
71
|
+
WebSearch2 as WebSearch,
|
|
72
|
+
Workspace2 as Workspace,
|
|
73
|
+
Worktree2 as Worktree
|
|
74
|
+
};
|