Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(ai): Dynamic prompt for currently open stuff (#2988)

Eric Hayes3d5912cd20fe
diff --git a/js/app/packages/core/component/AI/constant/prompts.ts b/js/app/packages/core/component/AI/constant/prompts.ts
index 9b67e787a5..fc5f414657 100644
--- a/js/app/packages/core/component/AI/constant/prompts.ts
+++ b/js/app/packages/core/component/AI/constant/prompts.ts
@@ -1,3 +1,4 @@
+import { globalSplitManager } from '@app/signal/splitLayout';
import { useUserContext } from '@core/context/user';
import { useInstructionsMdTextQuery } from '@queries/storage/instructions-md';
import { authServiceClient } from '@service-auth/client';
@@ -53,10 +54,35 @@ export function useAdditionalInstructions() {
'\nThese are system instructions provided by the user. Follow them\n';
prompt += userInstructions;
}
+ const openEntities = getOpenEntitiesPrompt();
+ if (openEntities) {
+ prompt += openEntities;
+ }
return appendDate(prompt);
};
}
+function getOpenEntitiesPrompt(): string | null {
+ const manager = globalSplitManager();
+ if (!manager) return null;
+
+ const splits = manager.splits();
+ const items: string[] = [];
+ for (const split of splits) {
+ if (split.content.type === 'component') continue;
+ const handle = manager.getSplit(split.id);
+ const name = handle?.displayName();
+ const type = split.content.type;
+ if (name) {
+ items.push(`- ${name} (${type}, id: ${split.content.id})`);
+ } else {
+ items.push(`- ${type} (id: ${split.content.id})`);
+ }
+ }
+ if (items.length === 0) return null;
+ return `\nThe user currently has the following items open:\n${items.join('\n')}`;
+}
+
function appendDate(prompt: string) {
const now = new Date();
return `${prompt}\nThe current date is: ${now}`;