Skip to content

Commit dcc5369

Browse files
authored
fix(integrations): validate polymarket, kalshi, sftp, ssh, smtp, jupyter and temporal (#10181)
* fix(integrations): validate polymarket, kalshi, sftp, ssh, smtp, jupyter and temporal * fix(integrations): honor negative position filters, type the new tests, and prove STARTTLS against a real SMTP server * fix(sftp): decode each escape run once and join upload names without decoding again * fix(sftp): reject a trailing parent segment in remote paths * fix(integrations): ignore null and empty timestamps in Kalshi settlements and Polymarket activity * fix(polymarket): reject a non-numeric activity timestamp and keep start=0 as full history * fix(polymarket): mark the next-page cursor output nullable * chore(integrations): regenerate artifacts after rebase
1 parent 1997d0a commit dcc5369

49 files changed

Lines changed: 1135 additions & 308 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/docs/content/docs/integrations/polymarket.mdx‎

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -491,14 +491,15 @@ Retrieve user positions from Polymarket
491491
| `user` | string | Yes | User wallet address |
492492
| `market` | string | No | Condition IDs to filter positions \(e.g., "0x1234...abcd,0x5678...efgh"\). Mutually exclusive with eventId. |
493493
| `eventId` | string | No | Event ID to filter positions \(e.g., "12345"\). Mutually exclusive with market. |
494-
| `sizeThreshold` | string | No | Minimum position size threshold \(default: 1\) |
495-
| `redeemable` | string | No | Filter for redeemable positions only \(true/false\) |
496-
| `mergeable` | string | No | Filter for mergeable positions only \(true/false\) |
497-
| `sortBy` | string | No | Sort field \(TOKENS, CURRENT, INITIAL, CASHPNL, PERCENTPNL, TITLE, RESOLVING, PRICE, AVGPRICE\) |
494+
| `sizeThreshold` | string | No | Minimum current position size in shares \(default: 0.1\) |
495+
| `redeemable` | string | No | true: only redeemable positions. false: drops redeemable positions from the returned page. |
496+
| `mergeable` | string | No | true: only mergeable positions. false: drops mergeable positions from the returned page. |
497+
| `sortBy` | string | No | Sort field: CURRENT_VALUE \(default\), TOKENS, PRICE, UNREALIZED_PNL, REALIZED_PNL, TOTAL_PNL, or TIMESTAMP |
498498
| `sortDirection` | string | No | Sort direction \(ASC or DESC\) |
499499
| `title` | string | No | Search filter by title |
500-
| `limit` | string | No | Number of results per page \(e.g., "25"\). |
501-
| `offset` | string | No | Number of results to skip for pagination \(e.g., "50"\). |
500+
| `limit` | string | No | Number of results for the first page \(e.g., "25"\). Max: 1000. |
501+
| `offset` | string | No | Not supported by the Polymarket Data API v2, which pages by cursor. Use cursor instead. |
502+
| `cursor` | string | No | Pagination cursor: the nextCursor from the previous page's output. Resend the same filters with it. |
502503

503504
#### Output
504505

@@ -530,6 +531,9 @@ Retrieve user positions from Polymarket
530531
| ↳ `oppositeAsset` | string | Opposite asset token ID |
531532
| ↳ `endDate` | string | End date |
532533
| ↳ `negativeRisk` | boolean | Whether negative risk |
534+
| ↳ `status` | string | Position state \(OPEN, REDEEMABLE, REDEEMABLE_LOST, MERGEABLE, CLOSED\) |
535+
| `nextCursor` | string | Cursor for the next page; pass it as Cursor. Null on the last page. |
536+
| `hasMore` | boolean | Whether another page exists |
533537

534538
</ReferenceDetails>
535539

@@ -550,8 +554,9 @@ Retrieve trade history from Polymarket
550554
| `takerOnly` | string | No | Filter for taker trades only \(true/false, default: true\) |
551555
| `filterType` | string | No | Filter type \(CASH or TOKENS\) - requires filterAmount |
552556
| `filterAmount` | string | No | Filter amount threshold - requires filterType |
553-
| `limit` | string | No | Number of results per page \(e.g., "50"\). Default: 100, max: 10000. |
554-
| `offset` | string | No | Number of results to skip for pagination \(e.g., "100"\). |
557+
| `limit` | string | No | Number of results for the first page \(e.g., "50"\). Default: 100, max: 1000. |
558+
| `offset` | string | No | Not supported by the Polymarket Data API v2, which pages by cursor. Use cursor instead. |
559+
| `cursor` | string | No | Pagination cursor: the nextCursor from the previous page's output. Resend the same filters with it. |
555560

556561
#### Output
557562

@@ -577,6 +582,8 @@ Retrieve trade history from Polymarket
577582
| ↳ `profileImage` | string | Profile image URL |
578583
| ↳ `profileImageOptimized` | string | Optimized profile image URL |
579584
| ↳ `transactionHash` | string | Transaction hash |
585+
| `nextCursor` | string | Cursor for the next page; pass it as Cursor. Null on the last page. |
586+
| `hasMore` | boolean | Whether another page exists |
580587

581588
</ReferenceDetails>
582589

@@ -591,16 +598,17 @@ Retrieve on-chain activity for a user including trades, splits, merges, redempti
591598
| Parameter | Type | Required | Description |
592599
| --------- | ---- | -------- | ----------- |
593600
| `user` | string | Yes | User wallet address \(0x-prefixed\) |
594-
| `limit` | string | No | Maximum results to return \(e.g., "50"\). Default: 100, max: 500. |
595-
| `offset` | string | No | Number of results to skip for pagination \(e.g., "100"\). Default: 0, max: 10000. |
601+
| `limit` | string | No | Number of results for the first page \(e.g., "50"\). Default: 100, max: 1000. |
602+
| `offset` | string | No | Not supported by the Polymarket Data API v2, which pages by cursor. Use cursor instead. |
596603
| `market` | string | No | Comma-separated condition IDs \(e.g., "0x1234...abcd,0x5678...efgh"\). Mutually exclusive with eventId. |
597604
| `eventId` | string | No | Comma-separated event IDs \(e.g., "12345,67890"\). Mutually exclusive with market. |
598605
| `type` | string | No | Activity type filter: TRADE, SPLIT, MERGE, REDEEM, REWARD, CONVERSION, MAKER_REBATE, REFERRAL_REWARD |
599606
| `start` | number | No | Start timestamp \(Unix seconds\) |
600607
| `end` | number | No | End timestamp \(Unix seconds\) |
601-
| `sortBy` | string | No | Sort field: TIMESTAMP, TOKENS, or CASH \(default: TIMESTAMP\) |
608+
| `sortBy` | string | No | Sort field. Polymarket supports only TIMESTAMP. |
602609
| `sortDirection` | string | No | Sort direction: ASC or DESC \(default: DESC\) |
603610
| `side` | string | No | Trade side filter: BUY or SELL \(only applies to trades\) |
611+
| `cursor` | string | No | Pagination cursor: the nextCursor from the previous page's output. Resend the same filters with it. |
604612

605613
#### Output
606614

@@ -628,6 +636,8 @@ Retrieve on-chain activity for a user including trades, splits, merges, redempti
628636
| ↳ `bio` | string | User bio |
629637
| ↳ `profileImage` | string | User profile image URL |
630638
| ↳ `profileImageOptimized` | string | Optimized profile image URL |
639+
| `nextCursor` | string | Cursor for the next page; pass it as Cursor. Null on the last page. |
640+
| `hasMore` | boolean | Whether another page exists |
631641

632642
</ReferenceDetails>
633643

@@ -643,11 +653,12 @@ Retrieve trader leaderboard rankings by profit/loss or volume
643653
| --------- | ---- | -------- | ----------- |
644654
| `category` | string | No | Category filter: OVERALL, POLITICS, SPORTS, CRYPTO, CULTURE, MENTIONS, WEATHER, ECONOMICS, TECH, FINANCE \(default: OVERALL\) |
645655
| `timePeriod` | string | No | Time period: DAY, WEEK, MONTH, ALL \(default: DAY\) |
646-
| `orderBy` | string | No | Order by: PNL or VOL \(default: PNL\) |
647-
| `limit` | string | No | Number of results to return \(e.g., "10"\). Range: 1-50, default: 25. |
648-
| `offset` | string | No | Number of results to skip for pagination \(e.g., "25"\). Range: 0-1000, default: 0. |
649-
| `user` | string | No | Filter by specific user wallet address |
650-
| `userName` | string | No | Filter by username |
656+
| `orderBy` | string | No | Order by: PNL or VOLUME \(default: PNL\) |
657+
| `limit` | string | No | Number of results for the first page \(e.g., "10"\). Max: 1000. |
658+
| `offset` | string | No | Not supported by the Polymarket Data API v2, which pages by cursor. Use cursor instead. |
659+
| `user` | string | No | Wallet address to look up that user's rank instead of the board |
660+
| `userName` | string | No | Not supported by the Polymarket Data API v2. Use user with a wallet address instead. |
661+
| `cursor` | string | No | Pagination cursor: the nextCursor from the previous page's output. Resend the same filters with it. |
651662

652663
#### Output
653664

@@ -662,6 +673,8 @@ Retrieve trader leaderboard rankings by profit/loss or volume
662673
| ↳ `profileImage` | string | User profile image URL |
663674
| ↳ `xUsername` | string | Twitter/X username |
664675
| ↳ `verifiedBadge` | boolean | Whether user has verified badge |
676+
| `nextCursor` | string | Cursor for the next page; pass it as Cursor. Null on the last page. |
677+
| `hasMore` | boolean | Whether another page exists |
665678

666679
</ReferenceDetails>
667680

@@ -676,8 +689,9 @@ Retrieve top holders of a specific market token
676689
| Parameter | Type | Required | Description |
677690
| --------- | ---- | -------- | ----------- |
678691
| `market` | string | Yes | Comma-separated list of condition IDs \(e.g., "0x1234...abcd" or "0x1234...abcd,0x5678...efgh"\). |
679-
| `limit` | string | No | Number of holders to return \(e.g., "10"\). Range: 0-20, default: 20. |
680-
| `minBalance` | string | No | Minimum balance threshold \(default: 1\) |
692+
| `limit` | string | No | Number of holders per outcome token \(e.g., "10"\). Default: 100, max: 1000. |
693+
| `minBalance` | string | No | Minimum net balance in shares \(default: 0\) |
694+
| `cursor` | string | No | Pagination cursor: the nextCursor from the previous page's output. Resend the same filters with it. |
681695

682696
#### Output
683697

@@ -697,6 +711,8 @@ Retrieve top holders of a specific market token
697711
| ↳ `profileImage` | string | Profile image URL |
698712
| ↳ `profileImageOptimized` | string | Optimized profile image URL |
699713
| ↳ `verified` | boolean | Whether the holder is verified |
714+
| `nextCursor` | string | Cursor for the next page; pass it as Cursor. Null on the last page. |
715+
| `hasMore` | boolean | Whether another page exists |
700716

701717
</ReferenceDetails>
702718

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { JupyterBlock } from '@/blocks/blocks/jupyter'
3+
4+
const SERVER = { serverUrl: 'https://jupyter.example.com', token: 'token' }
5+
6+
/** The executor sends `{ ...storedInputs, ...mapped }`, so a value stored for another operation must not leak in. */
7+
describe('Jupyter block Create Session', () => {
8+
it('does not send the Create File type as the session type', () => {
9+
const stored = {
10+
...SERVER,
11+
operation: 'jupyter_create_session',
12+
path: 'analysis.ipynb',
13+
type: 'file',
14+
}
15+
expect(
16+
{ ...stored, ...JupyterBlock.tools.config.params(stored, undefined) }.type
17+
).toBeUndefined()
18+
})
19+
20+
it('sends the Session Type field, or the model type on an agent tool call', () => {
21+
const stored = { ...SERVER, operation: 'jupyter_create_session', sessionType: 'console' }
22+
expect(JupyterBlock.tools.config.params(stored, undefined).type).toBe('console')
23+
expect(
24+
JupyterBlock.tools.config.params(
25+
{ ...SERVER, path: 'a.ipynb', type: 'console' },
26+
{ operation: 'jupyter_create_session' }
27+
).type
28+
).toBe('console')
29+
})
30+
})

‎apps/sim/blocks/blocks/jupyter.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createVersionedToolSelector,
66
mapperOperation,
77
normalizeFileInput,
8+
toolCallArg,
89
withSavedCredential,
910
} from '@/blocks/utils'
1011

@@ -342,7 +343,7 @@ export const JupyterBlock = {
342343
baseParams.path = params.path
343344
if (params.kernelName) baseParams.kernelName = params.kernelName
344345
if (params.sessionName) baseParams.name = params.sessionName
345-
if (params.sessionType) baseParams.type = params.sessionType
346+
baseParams.type = params.sessionType || toolCallArg(context, params.type)
346347
break
347348
case 'jupyter_delete_session':
348349
baseParams.sessionId = params.sessionId

‎apps/sim/blocks/blocks/kalshi.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,42 @@ describe('KalshiBlock', () => {
6262
expect({ ...args, ...buildParams(args, { operation: 'cancel_order' }) }.orderId).toBe('model')
6363
})
6464
})
65+
66+
/** The executor sends `{ ...storedInputs, ...mapped }`, so a value stored for another operation must not leak in. */
67+
describe('KalshiBlock fields owned by one operation', () => {
68+
const stored = {
69+
minTs: '1700000000',
70+
maxTs: '1700003600',
71+
countFp: '10.00',
72+
ticker: 'KXOLD-24',
73+
countAmend: '5',
74+
orderIdParam: 'order-1',
75+
tickerOrder: 'KXNEW-25',
76+
}
77+
const run = (operation: string) => {
78+
const inputs = { ...stored, operation }
79+
return { ...inputs, ...KalshiBlock.tools.config?.params?.(inputs) }
80+
}
81+
82+
it('does not apply the Get Fills time window to Get Orders, Get Trades or Get Settlements', () => {
83+
for (const operation of ['get_orders', 'get_trades', 'get_settlements']) {
84+
expect(run(operation)).toMatchObject({ minTs: undefined, maxTs: undefined })
85+
}
86+
expect(run('get_fills')).toMatchObject({ minTs: '1700000000', maxTs: '1700003600' })
87+
})
88+
89+
it('does not send the Create Order fixed-point count when amending an order', () => {
90+
expect(run('amend_order')).toMatchObject({ count: '5', countFp: undefined })
91+
})
92+
93+
it('does not filter Get Trades by the Get Market ticker', () => {
94+
expect(run('get_trades').ticker).toBeUndefined()
95+
})
96+
97+
it('keeps the model time window and ticker on an agent tool call', () => {
98+
const args = { minTs: '1', maxTs: '2', ticker: 'KX-1' }
99+
expect(KalshiBlock.tools.config?.params?.(args, { operation: 'get_trades' })).toMatchObject(
100+
args
101+
)
102+
})
103+
})

‎apps/sim/blocks/blocks/kalshi.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const KalshiBlock: BlockConfig = {
138138
{ label: 'Get Series List', id: 'get_series_list' },
139139
{ label: 'Get Exchange Status', id: 'get_exchange_status' },
140140
{ label: 'Get Exchange Schedule', id: 'get_exchange_schedule' },
141-
{ label: 'Get Exchange Announcements', id: 'get_exchange_announcements' },
141+
{ label: 'Get Exchange Announcements', id: 'get_exchange_announcements', hidden: true },
142142
{ label: 'Create Order', id: 'create_order' },
143143
{ label: 'Cancel Order', id: 'cancel_order' },
144144
{ label: 'Amend Order', id: 'amend_order' },
@@ -732,6 +732,17 @@ Return ONLY the numeric timestamp (seconds since Unix epoch) - no explanations,
732732
cleanParams[key] = field || toolCallArg(context, cleanParams[key])
733733
}
734734

735+
/** Fields shown only for one operation: any other operation takes them from the model alone. */
736+
const keepOnlyFor = (key: string, owner: string) => {
737+
if (operation !== owner) cleanParams[key] = toolCallArg(context, cleanParams[key])
738+
}
739+
keepOnlyFor('minTs', 'get_fills')
740+
keepOnlyFor('maxTs', 'get_fills')
741+
keepOnlyFor('countFp', 'create_order')
742+
if (operation === 'get_trades') {
743+
cleanParams.ticker = toolCallArg(context, cleanParams.ticker)
744+
}
745+
735746
if (operation === 'get_orders') {
736747
mapField('status', orderStatus)
737748
}

‎apps/sim/blocks/blocks/polymarket.ts‎

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,15 @@ export const PolymarketBlock: BlockConfig = {
240240
{ label: 'Default', id: '' },
241241
{ label: 'Tokens', id: 'TOKENS' },
242242
{ label: 'Current Value', id: 'CURRENT' },
243-
{ label: 'Initial Value', id: 'INITIAL' },
243+
{ label: 'Initial Value', id: 'INITIAL', hidden: true },
244244
{ label: 'Cash P&L', id: 'CASHPNL' },
245-
{ label: 'Percent P&L', id: 'PERCENTPNL' },
246-
{ label: 'Title', id: 'TITLE' },
245+
{ label: 'Realized P&L', id: 'REALIZED_PNL' },
246+
{ label: 'Total P&L', id: 'TOTAL_PNL' },
247+
{ label: 'Percent P&L', id: 'PERCENTPNL', hidden: true },
248+
{ label: 'Title', id: 'TITLE', hidden: true },
247249
{ label: 'Price', id: 'PRICE' },
248-
{ label: 'Avg Price', id: 'AVGPRICE' },
250+
{ label: 'Avg Price', id: 'AVGPRICE', hidden: true },
251+
{ label: 'Last Activity', id: 'TIMESTAMP' },
249252
],
250253
condition: { field: 'operation', value: ['get_positions'] },
251254
mode: 'advanced',
@@ -372,8 +375,8 @@ export const PolymarketBlock: BlockConfig = {
372375
type: 'dropdown',
373376
options: [
374377
{ label: 'Timestamp', id: 'TIMESTAMP' },
375-
{ label: 'Tokens', id: 'TOKENS' },
376-
{ label: 'Cash', id: 'CASH' },
378+
{ label: 'Tokens', id: 'TOKENS', hidden: true },
379+
{ label: 'Cash', id: 'CASH', hidden: true },
377380
],
378381
condition: { field: 'operation', value: ['get_activity'] },
379382
mode: 'advanced',
@@ -452,7 +455,7 @@ export const PolymarketBlock: BlockConfig = {
452455
id: 'leaderboardUser',
453456
title: 'User Address',
454457
type: 'short-input',
455-
placeholder: 'Filter by specific user wallet',
458+
placeholder: "Look up one wallet's rank",
456459
condition: { field: 'operation', value: ['get_leaderboard'] },
457460
mode: 'advanced',
458461
},
@@ -679,6 +682,17 @@ Return ONLY the Unix timestamp as a number - no explanations, no quotes, no extr
679682
},
680683
mode: 'advanced',
681684
},
685+
{
686+
id: 'cursor',
687+
title: 'Cursor',
688+
type: 'short-input',
689+
placeholder: 'nextCursor from the previous page',
690+
condition: {
691+
field: 'operation',
692+
value: ['get_trades', 'get_positions', 'get_activity', 'get_leaderboard', 'get_holders'],
693+
},
694+
mode: 'advanced',
695+
},
682696
{
683697
id: 'page',
684698
title: 'Page',
@@ -944,6 +958,16 @@ Return ONLY the Unix timestamp as a number - no explanations, no quotes, no extr
944958
activity: { type: 'json', description: 'Array of user activity entries (get_activity)' },
945959
leaderboard: { type: 'json', description: 'Array of leaderboard entries (get_leaderboard)' },
946960
holders: { type: 'json', description: 'Array of market holder groups (get_holders)' },
961+
nextCursor: {
962+
type: 'string',
963+
description:
964+
'Cursor for the next page (get_trades, get_positions, get_activity, get_leaderboard, get_holders)',
965+
},
966+
hasMore: {
967+
type: 'boolean',
968+
description:
969+
'Whether another page exists (get_trades, get_positions, get_activity, get_leaderboard, get_holders)',
970+
},
947971
},
948972
}
949973

‎apps/sim/blocks/blocks/sftp.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,51 @@ describe('SftpV2Block agent tool calls', () => {
2727
}).toMatchObject({ recursive: false })
2828
})
2929
})
30+
31+
/** The executor sends `{ ...storedInputs, ...mapped }`, so a value stored for another operation must not leak in. */
32+
describe('SftpV2Block canvas runs', () => {
33+
const stored = {
34+
host: 'h',
35+
username: 'u',
36+
password: 'p',
37+
remotePath: '/upload',
38+
files: [{ name: 'report.csv', key: 'k', url: 'u', size: 1, type: 'text/csv' }],
39+
fileContent: 'stale content',
40+
fileName: 'stale.txt',
41+
}
42+
const run = (operation: string) => {
43+
const inputs = { ...stored, operation }
44+
return { ...inputs, ...SftpV2Block.tools.config?.params?.(inputs) }
45+
}
46+
47+
it('does not write the Create File content on an Upload Files run', () => {
48+
expect(run('sftp_upload')).toMatchObject({ fileContent: undefined, fileName: undefined })
49+
})
50+
51+
it('does not upload the Upload Files files on a Create File run', () => {
52+
expect(run('sftp_create')).toMatchObject({ files: undefined, fileName: 'stale.txt' })
53+
})
54+
55+
it('keeps direct content the model sends on an upload tool call', () => {
56+
const args = { host: 'h', username: 'u', password: 'p', remotePath: '/a' }
57+
expect(
58+
SftpV2Block.tools.config?.params?.(
59+
{ ...args, fileContent: 'hi', fileName: 'a.txt' },
60+
{ operation: 'sftp_upload' }
61+
)
62+
).toMatchObject({ fileContent: 'hi', fileName: 'a.txt' })
63+
})
64+
65+
it('does not send a stored private key once the block is switched to password auth', () => {
66+
const inputs = {
67+
...stored,
68+
operation: 'sftp_list',
69+
authMethod: 'password',
70+
privateKey: 'stale key',
71+
}
72+
expect({ ...inputs, ...SftpV2Block.tools.config?.params?.(inputs) }).toMatchObject({
73+
password: 'p',
74+
privateKey: undefined,
75+
})
76+
})
77+
})

0 commit comments

Comments
 (0)