Skip to content

Commit eb9dc3e

Browse files
committed
fix(mcp): render tuples and open objects in generated contract types
1 parent 2643ce5 commit eb9dc3e

2 files changed

Lines changed: 63 additions & 4 deletions

File tree

‎apps/sim/lib/api/contracts/typescript.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@ function toTypeScript(schema: JsonSchema, indent: number, refs?: Map<string, str
7373
return 'boolean'
7474
case 'null':
7575
return 'null'
76-
case 'array':
77-
return isRecordLike(schema.items)
78-
? `Array<${toTypeScript(schema.items, indent, refs)}>`
79-
: 'unknown[]'
76+
case 'array': {
77+
const tuple = schemaList(schema.prefixItems)
78+
const rest = isRecordLike(schema.items) ? toTypeScript(schema.items, indent, refs) : null
79+
if (tuple) {
80+
const elements = tuple.map((item) => toTypeScript(item, indent, refs))
81+
if (rest) elements.push(`...Array<${rest}>`)
82+
return `[${elements.join(', ')}]`
83+
}
84+
return rest ? `Array<${rest}>` : 'unknown[]'
85+
}
8086
case 'object': {
8187
const properties = toRecord(schema.properties)
8288
const required = Array.isArray(schema.required) ? schema.required : []
@@ -90,13 +96,21 @@ function toTypeScript(schema: JsonSchema, indent: number, refs?: Map<string, str
9096
return `Record<string, ${value}>`
9197
}
9298

99+
const types: string[] = []
93100
const lines = keys.map((key) => {
94101
const property = properties[key]
95102
const optional = required.includes(key) ? '' : '?'
96103
const safeKey = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(key)
97104
const type = isRecordLike(property) ? toTypeScript(property, indent + 1, refs) : 'unknown'
105+
types.push(optional ? `${type} | undefined` : type)
98106
return `${pad}${safeKey}${optional}: ${type}`
99107
})
108+
// Extra keys are allowed; an index signature must also cover the named properties' types.
109+
if (isRecordLike(schema.additionalProperties)) {
110+
const extra = toTypeScript(schema.additionalProperties, indent + 1, refs)
111+
const value = extra === 'unknown' ? extra : [...new Set([extra, ...types])].join(' | ')
112+
lines.push(`${pad}[key: string]: ${value}`)
113+
}
100114
return `{\n${lines.join('\n')}\n${closePad}}`
101115
}
102116
}

‎packages/sim-cli/src/generated/v2-api.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,9 @@ type ApplyWorkflowOperationsBodyRef0 =
447447
name: string
448448
inputs?: {
449449
tools?: ApplyWorkflowOperationsBodyRef1
450+
[key: string]: unknown
450451
} & Record<string, unknown>
452+
[key: string]: unknown
451453
}
452454
}
453455
| {
@@ -456,7 +458,9 @@ type ApplyWorkflowOperationsBodyRef0 =
456458
params: {
457459
inputs?: {
458460
tools?: ApplyWorkflowOperationsBodyRef1
461+
[key: string]: unknown
459462
} & Record<string, unknown>
463+
[key: string]: unknown
460464
} & Record<string, unknown>
461465
}
462466
| {
@@ -472,14 +476,17 @@ type ApplyWorkflowOperationsBodyRef0 =
472476
name: string
473477
inputs?: {
474478
tools?: ApplyWorkflowOperationsBodyRef1
479+
[key: string]: unknown
475480
} & Record<string, unknown>
481+
[key: string]: unknown
476482
}
477483
}
478484
| {
479485
operation_type: 'extract_from_subflow'
480486
block_id: string
481487
params: {
482488
subflowId: string
489+
[key: string]: unknown
483490
}
484491
}
485492

@@ -497,6 +504,7 @@ type ApplyWorkflowOperationsBodyRef3 = {
497504
usageControl?: 'auto' | 'force' | 'none'
498505
usageControlExpression?: string
499506
params?: Record<string, unknown>
507+
[key: string]: unknown
500508
}
501509

502510
type ApplyWorkflowOperationsBodyRef4 =
@@ -505,6 +513,7 @@ type ApplyWorkflowOperationsBodyRef4 =
505513
customToolId: string
506514
usageControl?: 'auto' | 'force' | 'none'
507515
usageControlExpression?: string
516+
[key: string]: unknown
508517
}
509518
| {
510519
type: 'custom-tool'
@@ -514,21 +523,26 @@ type ApplyWorkflowOperationsBodyRef4 =
514523
name: string
515524
description?: string
516525
parameters: Record<string, unknown>
526+
[key: string]: unknown
517527
}
528+
[key: string]: unknown
518529
}
519530
code: string
520531
usageControl?: 'auto' | 'force' | 'none'
521532
usageControlExpression?: string
533+
[key: string]: unknown
522534
}
523535

524536
type ApplyWorkflowOperationsBodyRef5 = {
525537
type: 'mcp'
526538
params: {
527539
serverId: string
528540
toolName: string
541+
[key: string]: unknown
529542
} & Record<string, unknown>
530543
usageControl?: 'auto' | 'force' | 'none'
531544
usageControlExpression?: string
545+
[key: string]: unknown
532546
}
533547

534548
type ApplyWorkflowOperationsBodyRef6 = {
@@ -550,6 +564,7 @@ type ApplyWorkflowOperationsBodyRef6 = {
550564
}
551565
usageControl?: 'auto' | 'force' | 'none'
552566
usageControlExpression?: string
567+
[key: string]: unknown
553568
}
554569

555570
export type ApplyWorkflowOperationsBody = {
@@ -2138,8 +2153,11 @@ export type CreateCustomToolBody = {
21382153
type: string
21392154
properties: Record<string, unknown>
21402155
required?: Array<string>
2156+
[key: string]: unknown
21412157
}
2158+
[key: string]: unknown
21422159
}
2160+
[key: string]: unknown
21432161
}
21442162
code: string
21452163
}
@@ -2156,8 +2174,11 @@ type CreateCustomToolResponseRef0 = {
21562174
type: string
21572175
properties: Record<string, unknown>
21582176
required?: Array<string>
2177+
[key: string]: unknown
21592178
}
2179+
[key: string]: unknown
21602180
}
2181+
[key: string]: unknown
21612182
}
21622183
code: string
21632184
createdAt: string
@@ -2361,6 +2382,7 @@ type CreateKnowledgeBaseResponseRef0 = {
23612382
recipe?: 'plain' | 'markdown' | 'code'
23622383
strictBoundaries?: boolean
23632384
}
2385+
[key: string]: unknown
23642386
}
23652387

23662388
type CreateKnowledgeBaseResponseRef1 = {
@@ -6235,8 +6257,11 @@ type GetCustomToolResponseRef0 = {
62356257
type: string
62366258
properties: Record<string, unknown>
62376259
required?: Array<string>
6260+
[key: string]: unknown
62386261
}
6262+
[key: string]: unknown
62396263
}
6264+
[key: string]: unknown
62406265
}
62416266
code: string
62426267
createdAt: string
@@ -6416,6 +6441,7 @@ type GetKnowledgeBaseResponseRef0 = {
64166441
recipe?: 'plain' | 'markdown' | 'code'
64176442
strictBoundaries?: boolean
64186443
}
6444+
[key: string]: unknown
64196445
}
64206446

64216447
type GetKnowledgeBaseResponseRef1 = {
@@ -6652,8 +6678,10 @@ type GetLogResponseRef1 = {
66526678
startTime?: string
66536679
endTime?: string
66546680
duration?: number
6681+
[key: string]: unknown
66556682
}>
66566683
children?: Array<GetLogResponseRef1>
6684+
[key: string]: unknown
66576685
}
66586686

66596687
type GetLogResponseRef2 = {
@@ -7937,6 +7965,7 @@ type GetWorkflowResponseRef1 = {
79377965
type: string
79387966
properties?: Record<string, unknown>
79397967
required?: Array<string>
7968+
[key: string]: unknown
79407969
}
79417970

79427971
type GetWorkflowResponseRef2 = {
@@ -9113,8 +9142,11 @@ type ListCustomToolsResponseRef0 = {
91139142
type: string
91149143
properties: Record<string, unknown>
91159144
required?: Array<string>
9145+
[key: string]: unknown
91169146
}
9147+
[key: string]: unknown
91179148
}
9149+
[key: string]: unknown
91189150
}
91199151
code: string
91209152
createdAt: string
@@ -9289,6 +9321,7 @@ type ListKnowledgeBasesResponseRef1 = {
92899321
recipe?: 'plain' | 'markdown' | 'code'
92909322
strictBoundaries?: boolean
92919323
}
9324+
[key: string]: unknown
92929325
}
92939326

92949327
export type ListKnowledgeBasesResponse = {
@@ -9614,8 +9647,10 @@ type ListLogsResponseRef2 = {
96149647
startTime?: string
96159648
endTime?: string
96169649
duration?: number
9650+
[key: string]: unknown
96179651
}>
96189652
children?: Array<ListLogsResponseRef2>
9653+
[key: string]: unknown
96199654
}
96209655

96219656
export type ListLogsResponse = {
@@ -9678,11 +9713,13 @@ type ListMcpServerToolsResponseRef0 = {
96789713
type: 'object'
96799714
properties?: Record<string, unknown>
96809715
required?: Array<string>
9716+
[key: string]: unknown
96819717
}
96829718
outputSchema?: {
96839719
type: 'object'
96849720
properties?: Record<string, unknown>
96859721
required?: Array<string>
9722+
[key: string]: unknown
96869723
}
96879724
serverId: string
96889725
serverName: string
@@ -13783,6 +13820,7 @@ type RestoreKnowledgeBaseResponseRef0 = {
1378313820
recipe?: 'plain' | 'markdown' | 'code'
1378413821
strictBoundaries?: boolean
1378513822
}
13823+
[key: string]: unknown
1378613824
}
1378713825

1378813826
type RestoreKnowledgeBaseResponseRef1 = {
@@ -14941,8 +14979,11 @@ export type UpdateCustomToolBody = {
1494114979
type: string
1494214980
properties: Record<string, unknown>
1494314981
required?: Array<string>
14982+
[key: string]: unknown
1494414983
}
14984+
[key: string]: unknown
1494514985
}
14986+
[key: string]: unknown
1494614987
}
1494714988
code?: string
1494814989
}
@@ -14959,8 +15000,11 @@ type UpdateCustomToolResponseRef0 = {
1495915000
type: string
1496015001
properties: Record<string, unknown>
1496115002
required?: Array<string>
15003+
[key: string]: unknown
1496215004
}
15005+
[key: string]: unknown
1496315006
}
15007+
[key: string]: unknown
1496415008
}
1496515009
code: string
1496615010
createdAt: string
@@ -15045,6 +15089,7 @@ type UpdateKnowledgeBaseResponseRef0 = {
1504515089
recipe?: 'plain' | 'markdown' | 'code'
1504615090
strictBoundaries?: boolean
1504715091
}
15092+
[key: string]: unknown
1504815093
}
1504915094

1505015095
type UpdateKnowledgeBaseResponseRef1 = {

0 commit comments

Comments
 (0)