Skip to content

Commit c512fb7

Browse files
committed
fix: resolve React Native typecheck errors
- Add missing 'error' event handler in normalizeChatEvent.ts Converts error events to stream-error for mobile display - Fix result.metadata access in WorkspaceScreen.tsx ResultSchema wraps data, so access result.data.metadata not result.metadata - Add RequestInitWithDispatcher type in aiService.ts Extends RequestInit with undici-specific dispatcher property for Node.js
1 parent 68974d8 commit c512fb7

File tree

4 files changed

+19
-30
lines changed

4 files changed

+19
-30
lines changed

mobile/src/messages/normalizeChatEvent.ts

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import type { DisplayedMessage, WorkspaceChatEvent } from "../types";
2-
import type {
3-
MuxMessage,
4-
MuxTextPart,
5-
MuxImagePart,
6-
MuxReasoningPart,
7-
} from "@/common/types/message";
2+
import type { MuxMessage, MuxTextPart, MuxImagePart } from "@/common/types/message";
83
import type { DynamicToolPart } from "@/common/types/toolParts";
94
import type { WorkspaceChatMessage } from "@/common/orpc/types";
105
import { isMuxMessage } from "@/common/orpc/types";
@@ -42,26 +37,6 @@ export const DISPLAYABLE_MESSAGE_TYPES: ReadonlySet<DisplayedMessage["type"]> =
4237

4338
const DEBUG_TAG = "[ChatEventExpander]";
4439

45-
function isDevEnvironment(): boolean {
46-
if (typeof __DEV__ !== "undefined") {
47-
return __DEV__;
48-
}
49-
if (typeof process !== "undefined") {
50-
return process.env.NODE_ENV !== "production";
51-
}
52-
return false;
53-
}
54-
55-
function debugLog(message: string, context?: Record<string, unknown>): void {
56-
if (!isDevEnvironment()) {
57-
return;
58-
}
59-
if (context) {
60-
console.debug(`${DEBUG_TAG} ${message}`, context);
61-
} else {
62-
console.debug(`${DEBUG_TAG} ${message}`);
63-
}
64-
}
6540
const INIT_MESSAGE_ID = "workspace-init";
6641

6742
function isObject(value: unknown): value is Record<string, unknown> {
@@ -428,6 +403,18 @@ export function createChatEventExpander(): ChatEventExpander {
428403
"stream-error": () => [payload as WorkspaceChatEvent],
429404
delete: () => [payload as WorkspaceChatEvent],
430405

406+
// Error event: emit as stream-error for display
407+
error: (): WorkspaceChatEvent[] => {
408+
const errorEvent = event as { error?: string; errorType?: string };
409+
return [
410+
{
411+
type: "stream-error",
412+
error: errorEvent.error ?? "Unknown error",
413+
errorType: errorEvent.errorType,
414+
},
415+
];
416+
},
417+
431418
// Queue/restore events: pass through (mobile may use these later)
432419
"queued-message-changed": () => [payload as WorkspaceChatEvent],
433420
"restore-to-input": () => [payload as WorkspaceChatEvent],

mobile/src/screens/WorkspaceScreen.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,15 +770,15 @@ function WorkspaceScreenInner({
770770
return false;
771771
}
772772

773-
if ("metadata" in result && result.metadata) {
773+
if (result.data.metadata) {
774774
if (runtimeMode !== RUNTIME_MODE.LOCAL) {
775775
const runtimeString = buildRuntimeString(runtimeMode, sshHost);
776776
if (runtimeString) {
777777
await saveRuntimePreference(creationContext!.projectPath, runtimeString);
778778
}
779779
}
780780

781-
router.replace(`/workspace/${result.metadata.id}`);
781+
router.replace(`/workspace/${result.data.metadata.id}`);
782782
}
783783

784784
setIsSending(false);

mobile/src/types/workspace.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ export type WorkspaceChatEvent =
1515
| import("./message").DisplayedMessage
1616
| { type: "delete"; historySequences: number[] }
1717
| { type: "caught-up" }
18-
| { type: "stream-error"; messageId: string; error: string; errorType: string }
1918
| { type: string; [key: string]: unknown };

src/node/services/aiService.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const unlimitedTimeoutAgent = new Agent({
5555
headersTimeout: 0, // No timeout for headers
5656
});
5757

58+
// Extend RequestInit with undici-specific dispatcher property (Node.js only)
59+
type RequestInitWithDispatcher = RequestInit & { dispatcher?: InstanceType<typeof Agent> };
60+
5861
/**
5962
* Default fetch function with unlimited timeouts for AI streaming.
6063
* Uses undici Agent to remove artificial timeout limits while still
@@ -71,7 +74,7 @@ const defaultFetchWithUnlimitedTimeout = (async (
7174
init?: RequestInit
7275
): Promise<Response> => {
7376
// dispatcher is a Node.js undici-specific property for custom HTTP agents
74-
const requestInit: RequestInit = {
77+
const requestInit: RequestInitWithDispatcher = {
7578
...(init ?? {}),
7679
dispatcher: unlimitedTimeoutAgent,
7780
};

0 commit comments

Comments
 (0)