Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

Merge upstream/main and retain incoming-share composer wiring

Chris69f2b4e7c77c
diff --cc apps/mobile/app/sessions/[sessionId].tsx
index 208eba5e15,8a77db70fa..e46230af61
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@@ -3230,17 -3228,28 +3232,39 @@@ function SessionScreenContent()
applyComposerDraft(value, queueEditingRef.current ? { persist: false } : undefined);
}, [applyComposerDraft]);
+ useIncomingShareComposer({
+ destination: [incomingShareDestination(deviceId, sessionId), incomingShareDestination(deviceId, sessionId, {
+ collectionId: readRouteParam(params.resourceCollectionId) ?? '',
+ kind: readRouteParam(params.resourceKind) ?? '', id: readRouteParam(params.resourceId) ?? '',
+ })],
+ ready: composerDraftHydrated && canUseComposer && companionEntry.ready && !queueEditingRef.current,
+ appendText: text => setComposerDraft(current => [current, text].filter(Boolean).join('\n\n')),
+ attachmentCount: attachments.length,
+ enqueueUploads, getPendingUploadCount, onError: setAttachmentError,
+ });
+
+ // 开始打字时请被控端提前启动 Agent,把冷启动藏进打字时间。同一任务 30 秒最多提醒一次;
+ // 任务在跑、在排队编辑或旧被控端不支持时什么都不做。
+ const lastAgentPrewarmAtRef = useRef(0);
+ const prewarmAgentOnTyping = useCallback(() => {
+ if (queueEditingRef.current) return;
+ const now = Date.now();
+ if (now - lastAgentPrewarmAtRef.current < MOBILE_AGENT_PREWARM_INTERVAL_MS) return;
+ const session = remoteSessionStore.getSessions().find((item) => item.id === sessionId) ?? currentSession;
+ if (!session?.workingDir || remoteSessionStore.isSessionRunning(sessionId)) return;
+ lastAgentPrewarmAtRef.current = now;
+ const { createOpts } = buildQueuedTextMessage(session, '', new Date(now));
+ void maker.prewarmSession(sessionId, createOpts).catch(() => undefined);
+ }, [currentSession, maker, sessionId]);
+ const applyTypedComposerChange = useCallback((value: ComposerDocument) => {
+ applyRichComposerChange(value);
+ prewarmAgentOnTyping();
+ }, [applyRichComposerChange, prewarmAgentOnTyping]);
+ const setTypedComposerDraft = useCallback((next: SetStateAction<string>) => {
+ setComposerDraft(next);
+ prewarmAgentOnTyping();
+ }, [prewarmAgentOnTyping, setComposerDraft]);
+
const writeVoiceDraft = useComposerVoiceDraftWriter(sessionId, (update: ComposerVoiceDraftUpdate) => {
applyRichComposerChange(reconcileComposerVoiceDraft(composerDocumentRef.current, update));
});