Skip to content

Commit 50185f9

Browse files
claudeZhiXiao-Lin
authored andcommitted
fix(node-sdk): protect hand-authored types from napi-rs regen churn
Before this commit, every `napi build` overwrote `index.d.ts` and silently dropped the hand-added types (`ToolErrorKind`, `VerificationStatus`, `VerificationCheck`, `VerificationReport`, `ToolArtifact`). These types aren't generatable from Rust — they describe JSON wire shapes whose field names must stay snake_case to match the core's serialization, which napi-derive would auto-camelCase. Reshape the SDK so generated and hand-authored types live in separate files: - napi build now writes to `generated.d.ts` (was `index.d.ts`). - `extra-types.d.ts` holds the hand-authored types. - `index.d.ts` becomes a small hand-authored aggregator that re-exports both. It is never touched by the build. - `package.json` `files[]` ships all three .d.ts files; `types` field still points at `index.d.ts` so consumers' imports are unchanged. Adds `test-types.ts` + `npm run test:types` as a tsc-based smoke check that fails if the aggregator ever drops a type from either file.
1 parent c8a77f9 commit 50185f9

5 files changed

Lines changed: 1624 additions & 1547 deletions

File tree

sdk/node/extra-types.d.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Hand-authored type declarations that complement the auto-generated
3+
* `generated.d.ts`. These describe shapes that cross the SDK boundary as
4+
* JSON (e.g. payloads inside `runs()`, `verificationReports()`,
5+
* `errorKindJson` strings), not napi-bound objects.
6+
*
7+
* Keep field names matching the actual JSON wire format (snake_case where
8+
* the Rust core serializes that way). Do not move these into Rust source —
9+
* napi-derive would camelCase them and break consumers parsing the JSON.
10+
*/
11+
12+
/**
13+
* Parsed shape of `ToolResult.errorKindJson` / `AgentEvent.errorKindJson`.
14+
*
15+
* Use a discriminated union on the `type` field; new variants may be
16+
* added in future minor releases — callers should match exhaustively on
17+
* the kinds they care about and fall through to a default branch for
18+
* unknown ones.
19+
*/
20+
export type ToolErrorKind =
21+
| { type: 'version_conflict'; path: string; expected: string; actual: string | null }
22+
| { type: 'remote_git_conflict'; code: string; message: string }
23+
| { type: 'not_found'; path: string }
24+
| { type: 'invalid_argument'; message: string }
25+
| { type: 'unsupported'; message: string }
26+
| { type: 'timeout'; op: string; duration_ms: number }
27+
28+
export type VerificationStatus = 'passed' | 'failed' | 'needs_review' | 'skipped'
29+
30+
export interface VerificationCheck {
31+
id: string
32+
kind: string
33+
description: string
34+
status: VerificationStatus
35+
required?: boolean
36+
suggested_tools?: Array<string>
37+
evidence_uris?: Array<string>
38+
residual_risk?: string
39+
}
40+
41+
export interface VerificationReport {
42+
schema: string
43+
subject: string
44+
status: VerificationStatus
45+
checks: Array<VerificationCheck>
46+
residual_risks?: Array<string>
47+
}
48+
49+
export interface ToolArtifact {
50+
artifact_id: string
51+
artifact_uri: string
52+
tool_name: string
53+
content: string
54+
original_bytes: number
55+
shown_bytes: number
56+
}

0 commit comments

Comments
 (0)