Skip to content

Commit 00b65c5

Browse files
committed
fix: harden runtime imports for web plugin loading
1 parent 7cf3694 commit 00b65c5

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readFileSync, writeFileSync, existsSync, mkdirSync, statSync } from "fs"
22
import { join, dirname } from "path"
33
import { homedir } from "os"
4-
import { parse } from "jsonc-parser"
4+
import * as jsoncParser from "jsonc-parser"
55
import type { PluginInput } from "@opencode-ai/plugin"
66

77
type Permission = "ask" | "allow" | "deny"
@@ -773,7 +773,7 @@ function loadConfigFile(configPath: string): ConfigLoadResult {
773773
}
774774

775775
try {
776-
const parsed = parse(fileContent, undefined, { allowTrailingComma: true })
776+
const parsed = jsoncParser.parse(fileContent, undefined, { allowTrailingComma: true })
777777
if (parsed === undefined || parsed === null) {
778778
return { data: null, parseError: "Config file is empty or invalid" }
779779
}

lib/token-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SessionState, WithParts } from "./state"
22
import { AssistantMessage, UserMessage } from "@opencode-ai/sdk/v2"
33
import { Logger } from "./logger"
4-
import { countTokens as anthropicCountTokens } from "@anthropic-ai/tokenizer"
4+
import * as anthropicTokenizer from "@anthropic-ai/tokenizer"
55
import { getLastUserMessage } from "./messages/query"
66

77
export function getCurrentTokenUsage(state: SessionState, messages: WithParts[]): number {
@@ -67,7 +67,7 @@ export function getCurrentParams(
6767
export function countTokens(text: string): number {
6868
if (!text) return 0
6969
try {
70-
return anthropicCountTokens(text)
70+
return anthropicTokenizer.countTokens(text)
7171
} catch {
7272
return Math.round(text.length / 4)
7373
}

0 commit comments

Comments
 (0)