mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-28 03:00:29 -04:00
* feat(transport): replace shared chat transport with mothership-stream module * improvement(contracts): regenerate contracts from go * feat(tools): add tool catalog codegen from go tool contracts * feat(tools): add tool-executor dispatch framework for sim side tool routing * feat(orchestrator): rewrite tool dispatch with catalog-driven executor and simplified resume loop * feat(orchestrator): checkpoint resume flow * refactor(copilot): consolidate orchestrator into request/ layer * refactor(mothership): reorganize lib/copilot into structured subdirectories * refactor(mothership): canonical transcript layer, dead code cleanup, type consolidation * refactor(mothership): rebase onto latest staging * refactor(mothership): rename request continue to lifecycle * feat(trace): add initial version of request traces * improvement(stream): batch stream from redis * fix(resume): fix the resume checkpoint * fix(resume): fix resume client tool * fix(subagents): subagent resume should join on existing subagent text block * improvement(reconnect): harden reconnect logic * fix(superagent): fix superagent integration tools * improvement(stream): improve stream perf * Rebase with origin dev * fix(tests): fix failing test * fix(build): fix type errors * fix(build): fix build errors * fix(build): fix type errors * feat(mothership): add cli execution * fix(mothership): fix function execute tests
74 lines
2.5 KiB
TypeScript
74 lines
2.5 KiB
TypeScript
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
import { dirname, resolve } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { compile } from 'json-schema-to-typescript'
|
|
|
|
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url))
|
|
const ROOT = resolve(SCRIPT_DIR, '..')
|
|
const DEFAULT_CONTRACT_PATH = resolve(
|
|
ROOT,
|
|
'../copilot/copilot/contracts/request-trace-v1.schema.json'
|
|
)
|
|
const OUTPUT_PATH = resolve(ROOT, 'apps/sim/lib/copilot/generated/request-trace-v1.ts')
|
|
|
|
function generateRuntimeConstants(schema: Record<string, unknown>): string {
|
|
const defs = (schema.$defs ?? schema.definitions ?? {}) as Record<string, unknown>
|
|
const lines: string[] = []
|
|
|
|
for (const [name, def] of Object.entries(defs)) {
|
|
if (!def || typeof def !== 'object') continue
|
|
const defObj = def as Record<string, unknown>
|
|
const enumValues = defObj.enum
|
|
if (!Array.isArray(enumValues) || enumValues.length === 0) continue
|
|
if (!enumValues.every((v) => typeof v === 'string')) continue
|
|
|
|
const entries = (enumValues as string[])
|
|
.map((v) => ` ${JSON.stringify(v)}: ${JSON.stringify(v)}`)
|
|
.join(',\n')
|
|
|
|
lines.push(
|
|
`export const ${name} = {\n${entries},\n} as const;\n`
|
|
)
|
|
}
|
|
|
|
return lines.join('\n')
|
|
}
|
|
|
|
async function main() {
|
|
const checkOnly = process.argv.includes('--check')
|
|
const inputPathArg = process.argv.find((arg) => arg.startsWith('--input='))
|
|
const inputPath = inputPathArg ? resolve(ROOT, inputPathArg.slice('--input='.length)) : DEFAULT_CONTRACT_PATH
|
|
|
|
const raw = await readFile(inputPath, 'utf8')
|
|
const schema = JSON.parse(raw)
|
|
const types = await compile(schema, 'RequestTraceV1SimReport', {
|
|
bannerComment:
|
|
'// AUTO-GENERATED FILE. DO NOT EDIT.\n//',
|
|
unreachableDefinitions: true,
|
|
additionalProperties: false
|
|
})
|
|
|
|
const constants = generateRuntimeConstants(schema)
|
|
const rendered = constants ? `${types}\n${constants}\n` : types
|
|
|
|
if (checkOnly) {
|
|
const existing = await readFile(OUTPUT_PATH, 'utf8').catch(() => null)
|
|
if (existing !== rendered) {
|
|
throw new Error(
|
|
`Generated request trace contract is stale. Run: bun run trace-contracts:generate`
|
|
)
|
|
}
|
|
console.log('Request trace contract is up to date.')
|
|
return
|
|
}
|
|
|
|
await mkdir(dirname(OUTPUT_PATH), { recursive: true })
|
|
await writeFile(OUTPUT_PATH, rendered, 'utf8')
|
|
console.log(`Generated request trace types -> ${OUTPUT_PATH}`)
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err)
|
|
process.exit(1)
|
|
})
|