Open source CapCut alternative.
TypeScript
feat(app): tag inference requests with the active conversation id
David Lebd44b7099bf5
diff --git a/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift b/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swiftindex 073a8bde..42be3c48 100644--- a/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift+++ b/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift@@ -485,7 +485,7 @@ struct LocalAppUserQueryCommandHandler: UserQueryCommandHandling {let frontmostAppName = frontmost?.appName ?? forcedDriveTarget?.appName ?? "the frontmost app"let frontmostBundleIdentifier = frontmost?.bundleIdentifier ?? forcedDriveTarget?.bundleIdentifier- guard let configuration = try? DonkeyBackendInferenceConfiguration.fromEnvironment() else {+ guard var configuration = try? DonkeyBackendInferenceConfiguration.fromEnvironment() else {return await failHarnessRun(command: command,response: "The vision backend isn't configured (set DONKEY_WEB_BASE_URL), so I couldn't navigate by vision.",@@ -499,7 +499,9 @@ struct LocalAppUserQueryCommandHandler: UserQueryCommandHandling {}// One client serves the whole turn — understanding, planner, and hosted adapters all share it —// so wiring the auth-expiry hook here catches a 401 on any of those paths, even the ones that- // swallow the thrown error.+ // swallow the thrown error. Stamping the conversation here means every billable call this turn+ // makes carries the id, so backend usage records group under the conversation.+ configuration.conversationID = conversationIDlet backend = DonkeyBackendInferenceClient(configuration: configuration,onAuthenticationRequired: backendAuthExpiryHook()diff --git a/apps/Donkey/Sources/DonkeyAI/DonkeyBackendInferenceClient.swift b/apps/Donkey/Sources/DonkeyAI/DonkeyBackendInferenceClient.swiftindex 1005a6ba..ea70fbc2 100644--- a/apps/Donkey/Sources/DonkeyAI/DonkeyBackendInferenceClient.swift+++ b/apps/Donkey/Sources/DonkeyAI/DonkeyBackendInferenceClient.swift@@ -49,6 +49,10 @@ public struct DonkeyBackendInferenceConfiguration: Equatable, Sendable {public var baseURL: URLpublic var clientID: Stringpublic var devAuthBypass: Bool+ /// The conversation this turn's inference calls belong to, sent as `x-donkey-conversation-id` so the+ /// backend can group usage by conversation. Left nil for background work with no active conversation+ /// (vision warming, the debug overlay) — those calls are intentionally ungrouped.+ public var conversationID: String?public static let baseURLConfigurationDescription = "DONKEY_WEB_BASE_URL"public init(baseURL: URL, clientID: String, devAuthBypass: Bool = false) {@@ -661,6 +665,9 @@ public struct DonkeyBackendInferenceClient: @unchecked Sendable {request.httpShouldHandleCookies = truerequest.setValue("application/json", forHTTPHeaderField: "Content-Type")request.setValue(configuration.clientID, forHTTPHeaderField: "x-donkey-client-id")+ if let conversationID = configuration.conversationID, !conversationID.isEmpty {+ request.setValue(conversationID, forHTTPHeaderField: "x-donkey-conversation-id")+ }if configuration.devAuthBypass {request.setValue("1", forHTTPHeaderField: "x-donkey-dev-auth-bypass")}