Skip to content

Commit 5f8335b

Browse files
committed
fix(integrations): keep saved output references valid and encode firecrawl job ids
1 parent e9d4c1f commit 5f8335b

17 files changed

Lines changed: 159 additions & 30 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ Cancel an existing order on Kalshi
792792
| --------- | ---- | -------- | ----------- |
793793
| `orderId` | string | Yes | Order ID to cancel \(e.g., "abc123-def456-ghi789"\) |
794794
| `ticker` | string | No | Market ticker of the order \(e.g., "KXBTC-24DEC31"\), so the cancel reaches the order's exchange shard. Leave empty to look it up from the order first |
795+
| `subaccount` | string | No | Subaccount the order belongs to \(0 for primary, 1-63 for numbered subaccounts\). Leave empty for the primary account |
795796

796797
#### Output
797798

@@ -858,6 +859,7 @@ Modify the price or quantity of an existing order on Kalshi
858859
| `yesPriceDollars` | string | No | Updated yes price in dollars \(e.g., "0.56"\) |
859860
| `noPriceDollars` | string | No | Updated no price in dollars \(e.g., "0.56"\) |
860861
| `countFp` | string | No | Count in fixed-point for fractional contracts |
862+
| `subaccount` | string | No | Subaccount the order belongs to \(0 for primary, 1-63 for numbered subaccounts\). Leave empty for the primary account |
861863

862864
#### Output
863865

‎apps/sim/tools/arxiv/get_paper.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function arxivPaperId(input: string): string {
1414
const linkPath = arxivLinkPath(
1515
SCHEMELESS_ARXIV_LINK.test(trimmed) ? `https://${trimmed}` : trimmed
1616
)
17-
const id = linkPath ?? trimmed.replace(/[?#].*$/, '')
17+
const id = linkPath ?? trimmed.split(/[?#]/, 1)[0]
1818
return id.replace(/\.pdf$/, '')
1919
}
2020

‎apps/sim/tools/firecrawl/agent.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,17 @@ export const agentTool: ToolConfig<AgentParams, AgentResponse> = {
123123
while (elapsedTime < MAX_POLL_TIME_MS) {
124124
try {
125125
signal?.throwIfAborted()
126-
const statusResponse = await outboundFetch(`https://api.firecrawl.dev/v2/agent/${jobId}`, {
127-
method: 'GET',
128-
headers: {
129-
Authorization: `Bearer ${params.apiKey}`,
130-
'Content-Type': 'application/json',
131-
},
132-
signal,
133-
})
126+
const statusResponse = await outboundFetch(
127+
`https://api.firecrawl.dev/v2/agent/${encodeURIComponent(jobId)}`,
128+
{
129+
method: 'GET',
130+
headers: {
131+
Authorization: `Bearer ${params.apiKey}`,
132+
'Content-Type': 'application/json',
133+
},
134+
signal,
135+
}
136+
)
134137

135138
if (!statusResponse.ok) {
136139
throw new Error(`Failed to get agent status: ${statusResponse.statusText}`)

‎apps/sim/tools/firecrawl/batch-scrape.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export const batchScrapeTool: ToolConfig<FirecrawlBatchScrapeParams, FirecrawlBa
202202
try {
203203
signal?.throwIfAborted()
204204
const statusResponse = await outboundFetch(
205-
`https://api.firecrawl.dev/v2/batch/scrape/${jobId}`,
205+
`https://api.firecrawl.dev/v2/batch/scrape/${encodeURIComponent(jobId)}`,
206206
{
207207
method: 'GET',
208208
headers: {

‎apps/sim/tools/firecrawl/crawl.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,17 @@ export const crawlTool: ToolConfig<FirecrawlCrawlParams, FirecrawlCrawlResponse>
248248
while (elapsedTime < MAX_POLL_TIME_MS) {
249249
try {
250250
signal?.throwIfAborted()
251-
const statusResponse = await outboundFetch(`https://api.firecrawl.dev/v2/crawl/${jobId}`, {
252-
method: 'GET',
253-
headers: {
254-
Authorization: `Bearer ${params.apiKey}`,
255-
'Content-Type': 'application/json',
256-
},
257-
signal,
258-
})
251+
const statusResponse = await outboundFetch(
252+
`https://api.firecrawl.dev/v2/crawl/${encodeURIComponent(jobId)}`,
253+
{
254+
method: 'GET',
255+
headers: {
256+
Authorization: `Bearer ${params.apiKey}`,
257+
'Content-Type': 'application/json',
258+
},
259+
signal,
260+
}
261+
)
259262

260263
if (!statusResponse.ok) {
261264
throw new Error(`Failed to get crawl status: ${statusResponse.statusText}`)

‎apps/sim/tools/firecrawl/extract.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export const extractTool: ToolConfig<ExtractParams, ExtractResponse> = {
177177
try {
178178
signal?.throwIfAborted()
179179
const statusResponse = await outboundFetch(
180-
`https://api.firecrawl.dev/v2/extract/${jobId}`,
180+
`https://api.firecrawl.dev/v2/extract/${encodeURIComponent(jobId)}`,
181181
{
182182
method: 'GET',
183183
headers: {

‎apps/sim/tools/generated/tool-metadata.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎apps/sim/tools/generated/tool-outputs.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎apps/sim/tools/kalshi/amend_order.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,25 @@ describe('Kalshi amend order on the V2 event-order endpoint', () => {
115115
})
116116
})
117117

118+
it('sends the subaccount on the amend, not on the order read', () => {
119+
const subaccountOf = (
120+
tool: typeof kalshiAmendOrderV2Tool | typeof kalshiAmendOrderTool,
121+
params: KalshiAmendOrderV2Params
122+
) => {
123+
const { url } = tool.request
124+
if (typeof url !== 'function') throw new Error('amend tool has no url builder')
125+
return new URL(url(params)).searchParams.get('subaccount')
126+
}
127+
for (const tool of [kalshiAmendOrderV2Tool, kalshiAmendOrderTool]) {
128+
expect(subaccountOf(tool, { ...BASE, count: '8', yesPrice: '57', subaccount: '3' })).toBe('3')
129+
expect(subaccountOf(tool, { ...BASE, count: '8', subaccount: '3' })).toBeNull()
130+
expect(subaccountOf(tool, { ...BASE, count: '8', yesPrice: '57' })).toBeNull()
131+
expect(
132+
sentRequest(tool, { ...BASE, count: '8', yesPrice: '57', subaccount: '3' }).signatureValid
133+
).toBe(true)
134+
}
135+
})
136+
118137
it('quotes a no-side amend on the YES book', () => {
119138
const request = sentRequest(kalshiAmendOrderTool, {
120139
...BASE,

‎apps/sim/tools/kalshi/amend_order.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { getErrorMessage } from '@sim/utils/errors'
22
import { toRecord } from '@sim/utils/object'
33
import {
44
buildKalshiAmendOrderBody,
5+
KALSHI_ORDER_SUBACCOUNT_PARAM,
56
type KalshiLegacyOrderParams,
67
kalshiAmendNeedsCurrentOrder,
78
kalshiAmendParamsFromOrder,
89
kalshiCountNumber,
910
kalshiLegacyOrder,
1011
kalshiOrderPath,
1112
kalshiOrderReadPath,
13+
kalshiOrderWriteUrl,
1214
kalshiWrittenOrder,
1315
} from '@/tools/kalshi/orders'
1416
import type { KalshiAuthParams } from '@/tools/kalshi/types'
@@ -29,6 +31,16 @@ function amendRequestPath(
2931
: kalshiOrderPath(params.orderId, 'amend')
3032
}
3133

34+
/** The read takes no subaccount (GetOrder has no such param); the amend does. */
35+
function amendRequestUrl(
36+
params: KalshiAuthParams & KalshiLegacyOrderParams & { orderId: string }
37+
): string {
38+
const path = amendRequestPath(params)
39+
return kalshiAmendNeedsCurrentOrder(params)
40+
? buildKalshiUrl(path)
41+
: kalshiOrderWriteUrl(path, params.subaccount)
42+
}
43+
3244
function amendRequestMethod(params: KalshiLegacyOrderParams): 'GET' | 'POST' {
3345
return kalshiAmendNeedsCurrentOrder(params) ? 'GET' : 'POST'
3446
}
@@ -83,6 +95,7 @@ export interface KalshiAmendOrderParams extends KalshiAuthParams {
8395
noPrice?: string // Updated no price in cents (1-99)
8496
yesPriceDollars?: string // Updated yes price in dollars
8597
noPriceDollars?: string // Updated no price in dollars
98+
subaccount?: string // Subaccount the order belongs to
8699
}
87100

88101
export interface KalshiAmendOrderResponse {
@@ -180,10 +193,11 @@ export const kalshiAmendOrderTool: ToolConfig<KalshiAmendOrderParams, KalshiAmen
180193
visibility: 'user-or-llm',
181194
description: 'Updated no price in dollars (e.g., "0.56")',
182195
},
196+
subaccount: KALSHI_ORDER_SUBACCOUNT_PARAM,
183197
},
184198

185199
request: {
186-
url: (params) => buildKalshiUrl(amendRequestPath(params)),
200+
url: (params) => amendRequestUrl(params),
187201
method: (params) => amendRequestMethod(params),
188202
headers: (params) =>
189203
buildKalshiAuthHeaders(
@@ -249,6 +263,7 @@ export interface KalshiAmendOrderV2Params extends KalshiAuthParams {
249263
yesPriceDollars?: string // Updated yes price in dollars
250264
noPriceDollars?: string // Updated no price in dollars
251265
countFp?: string // Count in fixed-point for fractional contracts
266+
subaccount?: string // Subaccount the order belongs to
252267
}
253268

254269
interface KalshiAmendOrderV2Order {
@@ -430,10 +445,11 @@ export const kalshiAmendOrderV2Tool: ToolConfig<
430445
visibility: 'user-or-llm',
431446
description: 'Count in fixed-point for fractional contracts',
432447
},
448+
subaccount: KALSHI_ORDER_SUBACCOUNT_PARAM,
433449
},
434450

435451
request: {
436-
url: (params) => buildKalshiUrl(amendRequestPath(params)),
452+
url: (params) => amendRequestUrl(params),
437453
method: (params) => amendRequestMethod(params),
438454
headers: (params) =>
439455
buildKalshiAuthHeaders(

0 commit comments

Comments
 (0)