GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): copy models.dev snapshot without structuredClone (#46710) · anomalyco/opencode@e327f93

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/core
    • src/plugin
      • models-dev.ts
    • test/plugin
      • models-dev.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/core/src/plugin/models-dev.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/plugin/models-dev.ts
+21-2Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const ModelsDevPlugin = define({
3737
})
3838
for (const model of provider.models) {
3939
if (model.status === "deprecated") continue
40-
catalog.model.update(provider.info.id, model.id, (draft) => Object.assign(draft, structuredClone(model)))
40+
catalog.model.update(provider.info.id, model.id, (draft) => Object.assign(draft, copy(model)))
4141
}
4242
}
4343
})
@@ -65,8 +65,27 @@ function environmentNames(provider: ModelsDev.Snapshot) {
6565
}
6666

6767
function snapshots(data: readonly ModelsDev.Snapshot[]) {
68-
return structuredClone(data).filter(
68+
return copy(data).filter(
6969
// These deprecated aliases are replaced by the canonical Azure and Google Vertex providers.
7070
(provider) => provider.info.id !== "azure-cognitive-services" && provider.info.id !== "google-vertex-anthropic",
7171
)
7272
}
73+
74+
// The catalog owns and mutates its model records, so every rebuild needs fresh copies of the
75+
// thousands of snapshot models. Snapshot data is plain JSON, and a direct copy is an order of
76+
// magnitude faster than structuredClone's general graph walk on the startup path.
77+
function copy<T>(value: T): T {
78+
if (Array.isArray(value)) return value.map(copy) as T
79+
if (value !== null && typeof value === "object") {
80+
const result: Record<string, unknown> = {}
81+
for (const key of Object.keys(value)) {
82+
const copied = copy((value as Record<string, unknown>)[key])
83+
// Assigning this key would set the prototype rather than an own property, unlike structuredClone.
84+
if (key === "__proto__")
85+
Object.defineProperty(result, key, { value: copied, enumerable: true, writable: true, configurable: true })
86+
else result[key] = copied
87+
}
88+
return result as T
89+
}
90+
return value
91+
}
Collapse file

‎packages/core/test/plugin/models-dev.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/plugin/models-dev.test.ts
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,60 @@ describe("ModelsDevPlugin", () => {
411411
),
412412
)
413413

414+
it.effect("copies model request bodies without reinterpreting literal __proto__ keys", () =>
415+
Effect.gen(function* () {
416+
const integrations = yield* Integration.Service
417+
const catalog = yield* Catalog.Service
418+
const providerID = Provider.ID.make("acme")
419+
const modelID = Model.ID.make("gpt-5.4")
420+
// A JSON body may legitimately contain a "__proto__" key; both copy stages must keep it as an own property.
421+
const body = JSON.parse('{"__proto__":{"service_tier":"priority"},"keep":true}') as Record<string, unknown>
422+
const snapshot = {
423+
info: {
424+
id: providerID,
425+
name: "Acme",
426+
activation: "auto",
427+
package: Provider.aisdk("@ai-sdk/openai-compatible"),
428+
},
429+
environment: [],
430+
models: [
431+
{
432+
id: modelID,
433+
modelID,
434+
providerID,
435+
name: "GPT-5.4",
436+
capabilities: { tools: true, input: [], output: [] },
437+
variants: [],
438+
time: { released: Date.parse("2026-01-01") },
439+
cost: [],
440+
status: "active",
441+
enabled: true,
442+
limit: { context: 1_050_000, output: 128_000 },
443+
body,
444+
},
445+
],
446+
} satisfies ModelsDev.Snapshot
447+
yield* ModelsDevPlugin.effect(
448+
host({
449+
catalog: catalogHost(catalog),
450+
integration: integrationHost(integrations),
451+
}),
452+
).pipe(
453+
Effect.provideService(
454+
ModelsDev.Service,
455+
ModelsDev.Service.of({ get: () => Effect.succeed([snapshot]), refresh: () => Effect.void }),
456+
),
457+
)
458+
459+
const copied = (yield* catalog.model.get(providerID, modelID))?.body
460+
expect(copied).not.toBe(body)
461+
expect(Object.hasOwn(copied ?? {}, "__proto__")).toBe(true)
462+
expect(Object.keys(copied ?? {})).toEqual(["__proto__", "keep"])
463+
expect(JSON.stringify(copied)).toBe(JSON.stringify(body))
464+
expect(copied).not.toHaveProperty("service_tier")
465+
}),
466+
)
467+
414468
it.effect("omits legacy provider aliases", () =>
415469
Effect.gen(function* () {
416470
const integrations = yield* Integration.Service

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.