mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-18 06:34:50 +00:00
refactor: replace Bun.hash with Hash.fast using xxhash3-xxh64
This commit is contained in:
@@ -31,6 +31,7 @@ import {
|
|||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { pathToFileURL } from "bun"
|
import { pathToFileURL } from "bun"
|
||||||
import { Filesystem } from "../util/filesystem"
|
import { Filesystem } from "../util/filesystem"
|
||||||
|
import { Hash } from "../util/hash"
|
||||||
import { ACPSessionManager } from "./session"
|
import { ACPSessionManager } from "./session"
|
||||||
import type { ACPConfig } from "./types"
|
import type { ACPConfig } from "./types"
|
||||||
import { Provider } from "../provider/provider"
|
import { Provider } from "../provider/provider"
|
||||||
@@ -281,7 +282,7 @@ export namespace ACP {
|
|||||||
const output = this.bashOutput(part)
|
const output = this.bashOutput(part)
|
||||||
const content: ToolCallContent[] = []
|
const content: ToolCallContent[] = []
|
||||||
if (output) {
|
if (output) {
|
||||||
const hash = String(Bun.hash(output))
|
const hash = Hash.fast(output)
|
||||||
if (part.tool === "bash") {
|
if (part.tool === "bash") {
|
||||||
if (this.bashSnapshots.get(part.callID) === hash) {
|
if (this.bashSnapshots.get(part.callID) === hash) {
|
||||||
await this.connection
|
await this.connection
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ import { mapValues, mergeDeep, omit, pickBy, sortBy } from "remeda"
|
|||||||
import { NoSuchModelError, type Provider as SDK } from "ai"
|
import { NoSuchModelError, type Provider as SDK } from "ai"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { BunProc } from "../bun"
|
import { BunProc } from "../bun"
|
||||||
|
import { Hash } from "../util/hash"
|
||||||
import { Plugin } from "../plugin"
|
import { Plugin } from "../plugin"
|
||||||
import { ModelsDev } from "./models"
|
|
||||||
import { NamedError } from "@opencode-ai/util/error"
|
import { NamedError } from "@opencode-ai/util/error"
|
||||||
|
import { ModelsDev } from "./models"
|
||||||
import { Auth } from "../auth"
|
import { Auth } from "../auth"
|
||||||
import { Env } from "../env"
|
import { Env } from "../env"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
@@ -795,7 +796,7 @@ export namespace Provider {
|
|||||||
const modelLoaders: {
|
const modelLoaders: {
|
||||||
[providerID: string]: CustomModelLoader
|
[providerID: string]: CustomModelLoader
|
||||||
} = {}
|
} = {}
|
||||||
const sdk = new Map<number, SDK>()
|
const sdk = new Map<string, SDK>()
|
||||||
|
|
||||||
log.info("init")
|
log.info("init")
|
||||||
|
|
||||||
@@ -1085,7 +1086,7 @@ export namespace Provider {
|
|||||||
...model.headers,
|
...model.headers,
|
||||||
}
|
}
|
||||||
|
|
||||||
const key = Bun.hash.xxHash32(JSON.stringify({ providerID: model.providerID, npm: model.api.npm, options }))
|
const key = Hash.fast(JSON.stringify({ providerID: model.providerID, npm: model.api.npm, options }))
|
||||||
const existing = s.sdk.get(key)
|
const existing = s.sdk.get(key)
|
||||||
if (existing) return existing
|
if (existing) return existing
|
||||||
|
|
||||||
|
|||||||
7
packages/opencode/src/util/hash.ts
Normal file
7
packages/opencode/src/util/hash.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { createHash } from "crypto"
|
||||||
|
|
||||||
|
export namespace Hash {
|
||||||
|
export function fast(input: string | Buffer): string {
|
||||||
|
return createHash("xxhash3-xxh64").update(input).digest("hex")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user