29 lines
903 B
JavaScript
29 lines
903 B
JavaScript
/**
|
|
* Minimal local copy of the DSH user-message constructor.
|
|
*
|
|
* The bundle must load in a profile whose module resolution does not include
|
|
* the DSH installation's internal packages. `createUserMessage` in
|
|
* `@deepseek-ai/dsh-llm` is only `{ ...input, role: "user", id: randomUUID() }`
|
|
* plus a deep freeze, so keeping a local copy removes the only runtime import
|
|
* outside this package.
|
|
*/
|
|
|
|
import { randomUUID } from 'node:crypto'
|
|
|
|
function deepFreeze(value) {
|
|
if (value === null || typeof value !== 'object' || Object.isFrozen(value)) return value
|
|
Object.freeze(value)
|
|
for (const child of Object.values(value)) deepFreeze(child)
|
|
return value
|
|
}
|
|
|
|
/** Create an immutable user-role message with a fresh identity. */
|
|
export function createUserMessage(input) {
|
|
const message = {
|
|
...structuredClone(input),
|
|
role: 'user',
|
|
id: randomUUID(),
|
|
}
|
|
return deepFreeze(message)
|
|
}
|