Skip to content

Commit fc2f985

Browse files
committed
fix run from block tracespan
1 parent eff4fc9 commit fc2f985

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

apps/sim/app/api/tools/dropbox/upload/route.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { type NextRequest, NextResponse } from 'next/server'
33
import { z } from 'zod'
44
import { checkInternalAuth } from '@/lib/auth/hybrid'
55
import { generateRequestId } from '@/lib/core/utils/request'
6+
import { httpHeaderSafeJson } from '@/lib/core/utils/validation'
67
import { FileInputSchema } from '@/lib/uploads/utils/file-schemas'
78
import { processFilesToUserFiles, type RawFileInput } from '@/lib/uploads/utils/file-utils'
89
import { downloadFileFromStorage } from '@/lib/uploads/utils/file-utils.server'
@@ -11,16 +12,6 @@ export const dynamic = 'force-dynamic'
1112

1213
const logger = createLogger('DropboxUploadAPI')
1314

14-
/**
15-
* Escapes non-ASCII characters in JSON string for HTTP header safety.
16-
* Dropbox API requires characters 0x7F and all non-ASCII to be escaped as \uXXXX.
17-
*/
18-
function httpHeaderSafeJson(value: object): string {
19-
return JSON.stringify(value).replace(/[\u007f-\uffff]/g, (c) => {
20-
return `\\u${(`0000${c.charCodeAt(0).toString(16)}`).slice(-4)}`
21-
})
22-
}
23-
2415
const DropboxUploadSchema = z.object({
2516
accessToken: z.string().min(1, 'Access token is required'),
2617
path: z.string().min(1, 'Destination path is required'),

apps/sim/app/api/workflows/[id]/execute-from-block/route.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { SSE_HEADERS } from '@/lib/core/utils/sse'
99
import { markExecutionCancelled } from '@/lib/execution/cancellation'
1010
import { preprocessExecution } from '@/lib/execution/preprocessing'
1111
import { LoggingSession } from '@/lib/logs/execution/logging-session'
12+
import { buildTraceSpans } from '@/lib/logs/execution/trace-spans/trace-spans'
1213
import { executeWorkflowCore } from '@/lib/workflows/executor/execution-core'
1314
import { createSSECallbacks } from '@/lib/workflows/executor/execution-events'
1415
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
@@ -233,11 +234,14 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
233234
})
234235

235236
const executionResult = hasExecutionResult(error) ? error.executionResult : undefined
237+
const { traceSpans, totalDuration } = executionResult
238+
? buildTraceSpans(executionResult)
239+
: { traceSpans: [], totalDuration: 0 }
236240

237241
await loggingSession.safeCompleteWithError({
238-
totalDurationMs: executionResult?.metadata?.duration,
242+
totalDurationMs: totalDuration || executionResult?.metadata?.duration,
239243
error: { message: errorMessage },
240-
traceSpans: executionResult?.logs as any,
244+
traceSpans,
241245
})
242246

243247
sendEvent({

apps/sim/lib/core/utils/validation.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,13 @@ export function getInvalidCharacters(name: string): string[] {
5050
const invalidChars = name.match(/[^a-zA-Z0-9_\s]/g)
5151
return invalidChars ? [...new Set(invalidChars)] : []
5252
}
53+
54+
/**
55+
* Escapes non-ASCII characters in JSON string for HTTP header safety.
56+
* Dropbox API requires characters 0x7F and all non-ASCII to be escaped as \uXXXX.
57+
*/
58+
export function httpHeaderSafeJson(value: object): string {
59+
return JSON.stringify(value).replace(/[\u007f-\uffff]/g, (c) => {
60+
return `\\u${(`0000${c.charCodeAt(0).toString(16)}`).slice(-4)}`
61+
})
62+
}

apps/sim/tools/dropbox/download.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1+
import { httpHeaderSafeJson } from '@/lib/core/utils/validation'
12
import type { DropboxDownloadParams, DropboxDownloadResponse } from '@/tools/dropbox/types'
23
import type { ToolConfig } from '@/tools/types'
34

4-
/**
5-
* Escapes non-ASCII characters in JSON string for HTTP header safety.
6-
* Dropbox API requires characters 0x7F and all non-ASCII to be escaped as \uXXXX.
7-
*/
8-
function httpHeaderSafeJson(value: object): string {
9-
return JSON.stringify(value).replace(/[\u007f-\uffff]/g, (c) => {
10-
return `\\u${(`0000${c.charCodeAt(0).toString(16)}`).slice(-4)}`
11-
})
12-
}
13-
145
export const dropboxDownloadTool: ToolConfig<DropboxDownloadParams, DropboxDownloadResponse> = {
156
id: 'dropbox_download',
167
name: 'Dropbox Download File',

0 commit comments

Comments
 (0)