@zyro-sec/sdk 1.0.1 → 1.0.3

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/src/workerd.ts CHANGED
@@ -1,51 +1,51 @@
1
- export * as OpenCodeWorkerd from "./workerd"
2
-
3
- import { WorkerdProfile } from "./internal/workerd"
4
- import type { LogOptions } from "./logging"
5
- import { PromiseSdk } from "./promise"
6
-
7
- export type Configuration = WorkerdProfile.Configuration
8
-
9
- export interface CreateOptions extends WorkerdProfile.Options {
10
- readonly log?: LogOptions
11
- readonly plugins?: PromiseSdk.CreateOptions["plugins"]
12
- readonly instances?: PromiseSdk.CreateOptions["instances"]
13
- }
14
-
15
- export type Interface = PromiseSdk.Interface & {
16
- /** Suspends any workspaces past their idle threshold; call from the Durable Object's `alarm()` method. */
17
- readonly alarm: () => Promise<void>
18
- }
19
-
20
- /**
21
- * Boots the embedded opencode SDK on the workerd runtime profile: the full
22
- * application graph inside a Cloudflare Durable Object, with the database on
23
- * the injected `DurableObjectStorage` SQLite and every intentionally-local
24
- * service replaced or disabled (see `ServerWorkerd.replacements`).
25
- *
26
- * Suspended Sessions resume on boot (as on every runtime) because a Durable
27
- * Object can be evicted mid-turn with no teardown; the write-ahead execution
28
- * claim marks the turn and the boot-time sweep replays it.
29
- *
30
- * Forward the Durable Object's `alarm()` lifecycle method to `opencode.alarm()`
31
- * so idle remote workspaces suspend while the Durable Object hibernates at
32
- * zero idle cost.
33
- *
34
- * Returns the same typed `OpenCode.Interface` as `OpenCode.create` plus
35
- * `alarm()` — typed session operations plus the live `events.subscribe()`
36
- * stream — served over an in-process fetch transport, so no request leaves the
37
- * isolate.
38
- */
39
- export const create = async (options: CreateOptions): Promise<Interface> => {
40
- const profile = WorkerdProfile.make(options)
41
- const created = await PromiseSdk.createWithHost(
42
- { ...profile.options, log: options.log, plugins: options.plugins, instances: options.instances },
43
- { overrides: profile.replacements },
44
- )
45
- return {
46
- ...created.sdk,
47
- alarm: async () => {
48
- await created.host.runtime.runPromise(created.host.workspace.suspendIdle())
49
- },
50
- }
51
- }
1
+ export * as OpenCodeWorkerd from "./workerd"
2
+
3
+ import { WorkerdProfile } from "./internal/workerd"
4
+ import type { LogOptions } from "./logging"
5
+ import { PromiseSdk } from "./promise"
6
+
7
+ export type Configuration = WorkerdProfile.Configuration
8
+
9
+ export interface CreateOptions extends WorkerdProfile.Options {
10
+ readonly log?: LogOptions
11
+ readonly plugins?: PromiseSdk.CreateOptions["plugins"]
12
+ readonly instances?: PromiseSdk.CreateOptions["instances"]
13
+ }
14
+
15
+ export type Interface = PromiseSdk.Interface & {
16
+ /** Suspends any workspaces past their idle threshold; call from the Durable Object's `alarm()` method. */
17
+ readonly alarm: () => Promise<void>
18
+ }
19
+
20
+ /**
21
+ * Boots the embedded opencode SDK on the workerd runtime profile: the full
22
+ * application graph inside a Cloudflare Durable Object, with the database on
23
+ * the injected `DurableObjectStorage` SQLite and every intentionally-local
24
+ * service replaced or disabled (see `ServerWorkerd.replacements`).
25
+ *
26
+ * Suspended Sessions resume on boot (as on every runtime) because a Durable
27
+ * Object can be evicted mid-turn with no teardown; the write-ahead execution
28
+ * claim marks the turn and the boot-time sweep replays it.
29
+ *
30
+ * Forward the Durable Object's `alarm()` lifecycle method to `opencode.alarm()`
31
+ * so idle remote workspaces suspend while the Durable Object hibernates at
32
+ * zero idle cost.
33
+ *
34
+ * Returns the same typed `OpenCode.Interface` as `OpenCode.create` plus
35
+ * `alarm()` — typed session operations plus the live `events.subscribe()`
36
+ * stream — served over an in-process fetch transport, so no request leaves the
37
+ * isolate.
38
+ */
39
+ export const create = async (options: CreateOptions): Promise<Interface> => {
40
+ const profile = WorkerdProfile.make(options)
41
+ const created = await PromiseSdk.createWithHost(
42
+ { ...profile.options, log: options.log, plugins: options.plugins, instances: options.instances },
43
+ { overrides: profile.replacements },
44
+ )
45
+ return {
46
+ ...created.sdk,
47
+ alarm: async () => {
48
+ await created.host.runtime.runPromise(created.host.workspace.suspendIdle())
49
+ },
50
+ }
51
+ }
@@ -1,15 +1,15 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "./tsconfig.json",
4
- "compilerOptions": {
5
- "composite": false,
6
- "declaration": true,
7
- "emitDeclarationOnly": true,
8
- "incremental": false,
9
- "noEmit": false,
10
- "outDir": "dist",
11
- "rootDir": "src",
12
- "tsBuildInfoFile": null
13
- },
14
- "include": ["src"]
15
- }
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig.json",
4
+ "compilerOptions": {
5
+ "composite": false,
6
+ "declaration": true,
7
+ "emitDeclarationOnly": true,
8
+ "incremental": false,
9
+ "noEmit": false,
10
+ "outDir": "dist",
11
+ "rootDir": "src",
12
+ "tsBuildInfoFile": null
13
+ },
14
+ "include": ["src"]
15
+ }
package/tsconfig.json CHANGED
@@ -1,11 +1,11 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "@tsconfig/bun/tsconfig.json",
4
- "compilerOptions": {
5
- "types": ["bun"],
6
- "noUnusedLocals": true,
7
- "lib": ["ESNext", "DOM", "DOM.Iterable"],
8
- "noUncheckedIndexedAccess": false
9
- },
10
- "references": [{ "path": "../core" }]
11
- }
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "@tsconfig/bun/tsconfig.json",
4
+ "compilerOptions": {
5
+ "types": ["bun"],
6
+ "noUnusedLocals": true,
7
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
8
+ "noUncheckedIndexedAccess": false
9
+ },
10
+ "references": [{ "path": "../core" }]
11
+ }
@@ -1,114 +0,0 @@
1
- import { expect, test } from "bun:test"
2
- import { EnvironmentDriver } from "@zyro-sec/core/environment/driver"
3
- import { EnvironmentFiles } from "@zyro-sec/core/environment/files"
4
- import { Location as CoreLocation } from "@zyro-sec/core/location"
5
- import { Identity } from "@zyro-sec/core/machine/identity"
6
- import { WorkerClient } from "@zyro-sec/core/machine/worker-client"
7
- import { WorkspaceDriver } from "@zyro-sec/core/workspace/driver"
8
- import { SessionInbox as CoreSessionInbox } from "@zyro-sec/core/session/inbox"
9
- import { SessionMessage as CoreSessionMessage } from "@zyro-sec/core/session/message"
10
- import { Agent } from "@zyro-sec/schema/agent"
11
- import { Config } from "@zyro-sec/schema/config"
12
- import { Event } from "@zyro-sec/schema/event"
13
- import { Location } from "@zyro-sec/schema/location"
14
- import { Model } from "@zyro-sec/schema/model"
15
- import { Project } from "@zyro-sec/schema/project"
16
- import { Provider } from "@zyro-sec/schema/provider"
17
- import { WebSearch } from "@zyro-sec/schema/websearch"
18
- import { Session } from "@zyro-sec/schema/session"
19
- import { SessionInbox } from "@zyro-sec/schema/session-inbox"
20
- import { SessionMessage } from "@zyro-sec/schema/session-message"
21
- import { Workspace } from "@zyro-sec/schema/workspace"
22
- import { Worktree } from "@zyro-sec/schema/worktree"
23
- import { Api } from "@zyro-sec/server/api"
24
- import { ClientApi, clientNamespace, groupNames, promiseOmitEndpoints } from "@zyro-sec/protocol/client"
25
- import { compile, emitPromise } from "@zyro-sec/httpapi-codegen"
26
-
27
- const SDK = await import("../src/index")
28
- const SDKEffect = await import("../src/effect")
29
- const CoreAgent = await import("@zyro-sec/core/agent")
30
- const CoreModel = await import("@zyro-sec/core/model")
31
- const CoreProject = await import("@zyro-sec/core/project")
32
- const CoreSession = await import("@zyro-sec/core/session")
33
- const CoreWorktree = await import("@zyro-sec/core/worktree")
34
-
35
- test("re-exports canonical contracts directly from Schema", () => {
36
- expect(SDK.Agent).toBe(Agent)
37
- expect(SDK.Config).toBe(Config)
38
- expect(SDK.Event).toBe(Event)
39
- expect(SDK.Model).toBe(Model)
40
- expect(SDK.WebSearch).toBe(WebSearch)
41
- expect(SDK.Session).toBe(Session)
42
- expect(SDK.Worktree).toBe(Worktree)
43
- expect(SDK.Workspace).toBe(Workspace)
44
- expect(Object.keys(SDK).sort()).toEqual([
45
- "AbsolutePath",
46
- "Agent",
47
- "ClientError",
48
- "Command",
49
- "Config",
50
- "Credential",
51
- "Event",
52
- "FileSystem",
53
- "Integration",
54
- "Location",
55
- "Model",
56
- "OpenCode",
57
- "Permission",
58
- "PermissionSaved",
59
- "Project",
60
- "Prompt",
61
- "PromptInput",
62
- "Provider",
63
- "Pty",
64
- "Question",
65
- "Reference",
66
- "RelativePath",
67
- "Session",
68
- "SessionInbox",
69
- "SessionMessage",
70
- "Skill",
71
- "Tool",
72
- "WebSearch",
73
- "Workspace",
74
- "Worktree",
75
- ])
76
- })
77
-
78
- test("Core and Server reuse the authoritative Schema and Protocol values", () => {
79
- expect(CoreAgent.ID).toBe(Agent.ID)
80
- expect(CoreLocation.Ref).toBe(Location.Ref)
81
- expect(CoreModel.Ref).toBe(Model.Ref)
82
- expect(CoreSession.Info).toBe(Session.Info)
83
- expect(CoreProject.Current).toBe(Project.Current)
84
- expect(CoreWorktree.DirectoryUnavailableError).toBeDefined()
85
- expect(CoreWorktree.List).toBe(Worktree.List)
86
- expect(CoreWorktree.Info).toBe(Worktree.Info)
87
- expect(CoreSessionInbox.Item).toBe(SessionInbox.Item)
88
- expect(CoreSessionInbox.User).toBe(SessionInbox.User)
89
- expect(CoreSessionInbox.Synthetic).toBe(SessionInbox.Synthetic)
90
- expect(CoreSessionMessage.Info).toBe(SessionMessage.Info)
91
- expect(CoreSessionMessage.AssistantText).toBe(SessionMessage.AssistantText)
92
- expect(Api.groups["server.session"].identifier).toBe("server.session")
93
- expect(Api.groups["server.project"].identifier).toBe("server.project")
94
- expect(Object.keys(ClientApi.groups)).toEqual(Object.keys(Api.groups))
95
- expect(Session.ID.create()).toStartWith("ses_")
96
- expect(String(Project.ID.global)).toBe("global")
97
- expect(String(Provider.ID.anthropic)).toBe("anthropic")
98
- expect(Workspace.ID.create()).toStartWith("wrk_")
99
- })
100
-
101
- test("client and Server contracts generate identically", () => {
102
- const server = compile(Api, { groupNames, omitEndpoints: promiseOmitEndpoints, namespace: clientNamespace })
103
- const client = compile(ClientApi, { groupNames, omitEndpoints: promiseOmitEndpoints, namespace: clientNamespace })
104
-
105
- expect(emitPromise(client)).toEqual(emitPromise(server))
106
- })
107
-
108
- test("re-exports workspace and environment driver contracts from @zyro-sec/sdk/effect", () => {
109
- expect(SDKEffect.WorkspaceDriver).toBe(WorkspaceDriver)
110
- expect(SDKEffect.EnvironmentDriver).toBe(EnvironmentDriver)
111
- expect(SDKEffect.EnvironmentFiles).toBe(EnvironmentFiles)
112
- expect(SDKEffect.Identity).toBe(Identity)
113
- expect(SDKEffect.WorkerClient).toBe(WorkerClient)
114
- })