@opencode-ai/client
Advanced tools
@@ -66,3 +66,4 @@ import { Effect, FileSystem, Option, Schedule, Schema } from "effect"; | ||
| const decode = Schema.decodeUnknownEffect(Schema.fromJsonString(Info)); | ||
| const decodeHealth = Schema.decodeUnknownEffect(Schema.Struct({ healthy: Schema.Literal(true), version: Schema.String, pid: Schema.Int })); | ||
| const decodeHealth = Schema.decodeUnknownOption(Schema.Struct({ healthy: Schema.Literal(true), version: Schema.String, pid: Schema.Int })); | ||
| const decodeLegacyHealth = Schema.decodeUnknownOption(Schema.Struct({ healthy: Schema.Literal(true) })); | ||
| // A missing or corrupt file means no valid info; callers treat both | ||
@@ -77,3 +78,3 @@ // the same (the registering server self-evicts, clients rediscover). | ||
| }); | ||
| const probe = Effect.fnUntraced(function* (info, version) { | ||
| const probe = Effect.fnUntraced(function* (info, version, allowLegacy = false) { | ||
| const headers = info.password === undefined ? undefined : auth(info.password); | ||
@@ -86,9 +87,17 @@ const response = yield* Effect.tryPromise(() => fetch(new URL("/api/health", info.url), { | ||
| return undefined; | ||
| const health = yield* Effect.tryPromise(() => response.json()).pipe(Effect.flatMap(decodeHealth), Effect.option, Effect.map(Option.getOrUndefined)); | ||
| if (health?.pid !== info.pid) | ||
| const body = yield* Effect.tryPromise(() => response.json()).pipe(Effect.option, Effect.map(Option.getOrUndefined)); | ||
| const health = decodeHealth(body); | ||
| if (Option.isSome(health)) { | ||
| if (health.value.pid !== info.pid) | ||
| return undefined; | ||
| if (info.version !== undefined && health.value.version !== info.version) | ||
| return undefined; | ||
| if (version !== undefined && health.value.version !== version) | ||
| return undefined; | ||
| return { info, transport: { url: info.url, headers } }; | ||
| } | ||
| if (!allowLegacy || | ||
| Option.isNone(decodeLegacyHealth(body)) || | ||
| (typeof body === "object" && body !== null && ("version" in body || "pid" in body))) | ||
| return undefined; | ||
| if (info.version !== undefined && health.version !== info.version) | ||
| return undefined; | ||
| if (version !== undefined && health.version !== version) | ||
| return undefined; | ||
| return { info, transport: { url: info.url, headers } }; | ||
@@ -102,3 +111,3 @@ }); | ||
| return undefined; | ||
| return yield* probe(info); | ||
| return yield* probe(info, undefined, true); | ||
| }); | ||
@@ -105,0 +114,0 @@ // 50ms cadence bounded at ~5s, shared by stop escalation and start readiness. |
+4
-4
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "name": "@opencode-ai/client", | ||
| "version": "0.0.0-next-14971", | ||
| "version": "0.0.0-next-14974", | ||
| "type": "module", | ||
@@ -44,4 +44,4 @@ "license": "MIT", | ||
| "dependencies": { | ||
| "@opencode-ai/schema": "0.0.0-next-14971", | ||
| "@opencode-ai/protocol": "0.0.0-next-14971" | ||
| "@opencode-ai/schema": "0.0.0-next-14974", | ||
| "@opencode-ai/protocol": "0.0.0-next-14974" | ||
| }, | ||
@@ -58,3 +58,3 @@ "peerDependencies": { | ||
| "@effect/platform-node": "4.0.0-beta.83", | ||
| "@opencode-ai/httpapi-codegen": "0.0.0-next-14971", | ||
| "@opencode-ai/httpapi-codegen": "0.0.0-next-14974", | ||
| "@tsconfig/bun": "1.0.9", | ||
@@ -61,0 +61,0 @@ "@types/bun": "1.3.13", |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
785190
0.06%18290
0.05%+ Added
+ Added
- Removed
- Removed