-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopilotService.ts
More file actions
37 lines (33 loc) · 1.44 KB
/
Copy pathcopilotService.ts
File metadata and controls
37 lines (33 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import type { CopilotContext, CopilotService, CopilotStep, CopilotStepView } from './types';
import type { Bilingual } from '../../types';
// The LOCAL CopilotService (Adapter Pattern). Rule-based + deterministic: it localizes a config step
// and ENRICHES it with a live fact from the app (e.g. the current top pick on the recommendation
// step), then the hook emits the structured highlight command over the bus. No LLM, no network.
const tr = (b: Bilingual, lang: 'en' | 'id') => b[lang];
export const localCopilotService: CopilotService = {
id: 'local-copilot',
describe(step: CopilotStep, ctx: CopilotContext): CopilotStepView {
let body = tr(step.body, ctx.lang);
// Context-awareness: weave a real, current fact into the recommendation step.
if (step.target === 'recommendation' && ctx.topPick) {
body +=
ctx.lang === 'id'
? `\n\nSaat ini teratas: **${ctx.topPick}**.`
: `\n\nCurrently leading: **${ctx.topPick}**.`;
}
return {
title: tr(step.title, ctx.lang),
body,
dos: (step.dos ?? []).map((d) => tr(d, ctx.lang)),
donts: (step.donts ?? []).map((d) => tr(d, ctx.lang)),
target: step.target,
placement: step.placement ?? 'bottom',
view: step.view,
floating: step.floating ?? false,
};
},
};
/** Single swap-point for the CopilotService (mirrors getChatAdapter). */
export function getCopilotService(): CopilotService {
return localCopilotService;
}