Skip to content

Commit c72fa4e

Browse files
committed
Update
1 parent 4ab6706 commit c72fa4e

3 files changed

Lines changed: 125 additions & 7 deletions

File tree

apps/sim/app/api/copilot/chat/stream/route.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,7 @@ export async function GET(request: NextRequest) {
168168
})
169169
)
170170
} catch (err) {
171-
rootSpan.setStatus({
172-
code: SpanStatusCode.ERROR,
173-
message: err instanceof Error ? err.message : String(err),
174-
})
175-
rootSpan.recordException(err instanceof Error ? err : new Error(String(err)))
171+
markSpanForError(rootSpan, err)
176172
rootSpan.end()
177173
throw err
178174
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"trace-attribute-values-contract:check": "bun run scripts/sync-trace-attribute-values-contract.ts --check",
3636
"trace-events-contract:generate": "bun run scripts/sync-trace-events-contract.ts",
3737
"trace-events-contract:check": "bun run scripts/sync-trace-events-contract.ts --check",
38-
"mship:generate": "bun run mship-contracts:generate && bun run mship-tools:generate && bun run trace-contracts:generate && bun run trace-spans-contract:generate && bun run trace-attributes-contract:generate && bun run trace-attribute-values-contract:generate && bun run trace-events-contract:generate",
39-
"mship:check": "bun run mship-contracts:check && bun run mship-tools:check && bun run trace-contracts:check && bun run trace-spans-contract:check && bun run trace-attributes-contract:check && bun run trace-attribute-values-contract:check && bun run trace-events-contract:check",
38+
"mship:generate": "bun run scripts/generate-mship-contracts.ts",
39+
"mship:check": "bun run scripts/generate-mship-contracts.ts --check",
4040
"prepare": "bun husky",
4141
"type-check": "turbo run type-check",
4242
"release": "bun run scripts/create-single-release.ts"
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/usr/bin/env bun
2+
// Drive every mothership contract generator, then biome-format the
3+
// outputs so the committed files match what biome produces on commit
4+
// (avoids the stale-drift that comes from comparing raw json2ts output
5+
// against biome-formatted source).
6+
//
7+
// `--check` regenerates into a temp directory, formats identically,
8+
// and compares against the committed files — same semantics as the
9+
// old per-script `--check`, but accounts for post-generate formatting.
10+
11+
import { spawnSync } from 'node:child_process'
12+
import { copyFileSync, cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
13+
import { tmpdir } from 'node:os'
14+
import { dirname, join, resolve } from 'node:path'
15+
import { fileURLToPath } from 'node:url'
16+
17+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
18+
19+
const GENERATORS = [
20+
'scripts/sync-mothership-stream-contract.ts',
21+
'scripts/sync-tool-catalog.ts',
22+
'scripts/sync-request-trace-contract.ts',
23+
'scripts/sync-trace-spans-contract.ts',
24+
'scripts/sync-trace-attributes-contract.ts',
25+
'scripts/sync-trace-attribute-values-contract.ts',
26+
'scripts/sync-trace-events-contract.ts',
27+
]
28+
29+
// Generated files under this path. We biome-format this whole dir on
30+
// each generate (and the temp copy on each check).
31+
const GENERATED_DIR = 'apps/sim/lib/copilot/generated'
32+
33+
// `tool-schemas-v1.ts` goes through biome's `--unsafe` bracket-quote
34+
// fixer which reformats every key of TOOL_RUNTIME_SCHEMAS. Strip it
35+
// from the format pass so generator output stays stable on both sides.
36+
const FORMAT_EXCLUDE = new Set(['tool-schemas-v1.ts'])
37+
38+
function run(cmd: string[], cwd: string, env: NodeJS.ProcessEnv = process.env): void {
39+
const result = spawnSync(cmd[0], cmd.slice(1), {
40+
cwd,
41+
env,
42+
stdio: 'inherit',
43+
})
44+
if (result.status !== 0) {
45+
process.exit(result.status ?? 1)
46+
}
47+
}
48+
49+
function runGenerators(outputOverride?: string): void {
50+
const env = { ...process.env }
51+
for (const script of GENERATORS) {
52+
const args = ['bun', 'run', script]
53+
if (outputOverride) {
54+
// Individual scripts don't accept a custom output dir; for
55+
// --check we generate in place and snapshot before/after via
56+
// git-index comparison (see runCheck).
57+
}
58+
run(args, ROOT, env)
59+
}
60+
}
61+
62+
function formatGenerated(dir: string): void {
63+
const files = readdirNoThrow(dir).filter((f) => !FORMAT_EXCLUDE.has(f) && f.endsWith('.ts'))
64+
if (files.length === 0) return
65+
const paths = files.map((f) => join(dir, f))
66+
run(['bunx', 'biome', 'check', '--write', ...paths], ROOT)
67+
}
68+
69+
function readdirNoThrow(dir: string): string[] {
70+
try {
71+
// Bun has fs.readdirSync available as a CommonJS import
72+
const fs = require('node:fs') as typeof import('node:fs')
73+
return fs.readdirSync(dir)
74+
} catch {
75+
return []
76+
}
77+
}
78+
79+
function runCheck(): void {
80+
const targetDir = resolve(ROOT, GENERATED_DIR)
81+
// Snapshot current committed state
82+
const committed: Record<string, string> = {}
83+
for (const f of readdirNoThrow(targetDir)) {
84+
if (!f.endsWith('.ts')) continue
85+
committed[f] = readFileSync(join(targetDir, f), 'utf8')
86+
}
87+
88+
// Regenerate in place + format, then diff against the snapshot
89+
runGenerators()
90+
formatGenerated(targetDir)
91+
92+
const stale: string[] = []
93+
for (const [name, oldContent] of Object.entries(committed)) {
94+
if (FORMAT_EXCLUDE.has(name)) continue
95+
const newContent = readFileSync(join(targetDir, name), 'utf8')
96+
if (newContent !== oldContent) stale.push(name)
97+
}
98+
99+
// Restore the committed state regardless of outcome (--check is readonly).
100+
for (const [name, content] of Object.entries(committed)) {
101+
const fs = require('node:fs') as typeof import('node:fs')
102+
fs.writeFileSync(join(targetDir, name), content, 'utf8')
103+
}
104+
105+
if (stale.length > 0) {
106+
console.error(
107+
`Generated contracts are stale: ${stale.join(', ')}. Run: bun run mship:generate`,
108+
)
109+
process.exit(1)
110+
}
111+
console.log('All generated contracts up to date.')
112+
}
113+
114+
function runGenerate(): void {
115+
runGenerators()
116+
formatGenerated(resolve(ROOT, GENERATED_DIR))
117+
console.log('Generated + formatted mothership contracts.')
118+
}
119+
120+
const checkOnly = process.argv.includes('--check')
121+
if (checkOnly) runCheck()
122+
else runGenerate()

0 commit comments

Comments
 (0)