@omnivoice/page-agent 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,45 @@
1
+ const debugWindow = () => window;
2
+ const MAX_STEPS = 200;
3
+ const MAX_PAGES = 5;
4
+ const HEAD_LENGTH = 4e3;
5
+ function createDebugExtension() {
6
+ const store = () => debugWindow().__pageAgentDebug ??= { task: "", steps: [], pages: [] };
7
+ let pageCount = 0;
8
+ return {
9
+ name: "debug",
10
+ hooks: {
11
+ onBeforeTask(agent) {
12
+ debugWindow().__pageAgentDebug = { task: agent.task, steps: [], pages: [] };
13
+ pageCount = 0;
14
+ console.debug("[page-agent debug] tarefa:", agent.task);
15
+ },
16
+ transformPageContent(content) {
17
+ const debug = store();
18
+ pageCount += 1;
19
+ debug.pages.push({ step: pageCount, length: content.length, head: content.slice(0, HEAD_LENGTH) });
20
+ if (debug.pages.length > MAX_PAGES) debug.pages.shift();
21
+ return content;
22
+ },
23
+ onAfterStep(_agent, history) {
24
+ const last = [...history].reverse().find((event) => event.type === "step");
25
+ if (!last || last.type !== "step") return;
26
+ const entry = {
27
+ step: last.stepIndex,
28
+ goal: last.reflection.next_goal ?? "",
29
+ evaluation: last.reflection.evaluation_previous_goal ?? "",
30
+ tool: last.action.name,
31
+ input: last.action.input,
32
+ output: last.action.output.slice(0, 300)
33
+ };
34
+ const debug = store();
35
+ debug.steps.push(entry);
36
+ if (debug.steps.length > MAX_STEPS) debug.steps.shift();
37
+ console.debug(`[page-agent debug] passo ${entry.step}: ${entry.goal} → ${entry.tool}`, entry.input, "⇒", entry.output);
38
+ }
39
+ }
40
+ };
41
+ }
42
+ export {
43
+ createDebugExtension
44
+ };
45
+ //# sourceMappingURL=debug-extension-D0P_sNkc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-extension-D0P_sNkc.js","sources":["../../src/package/debug-extension.ts"],"sourcesContent":["/**\n * Diagnóstico do agente: por passo, o que ele PENSOU (objetivo), FEZ (ferramenta e entrada) e VIU (o conteúdo\n * indexado que foi ao modelo). Serve para responder \"por que o agente não achou X?\" sem adivinhar.\n *\n * ATENÇÃO: o conteúdo da página pode ter dados de clientes. Os registros ficam só no navegador (console e\n * `window.__pageAgentDebug`), nunca são enviados a lugar nenhum, e só existem com `debug: true`. Use em diagnóstico.\n */\n\nimport type { WidgetExtension } from \"../../vendor/page-agent/packages/page-agent/src/widget\";\n\nexport interface DebugStep {\n step: number;\n goal: string;\n evaluation: string;\n tool: string;\n input: unknown;\n output: string;\n}\n\nexport interface DebugPage {\n step: number;\n length: number;\n /** Primeiros caracteres do conteúdo que o modelo recebeu naquele passo. */\n head: string;\n}\n\nexport interface PageAgentDebug {\n task: string;\n steps: DebugStep[];\n pages: DebugPage[];\n}\n\n/** `window` com o registro de diagnóstico. Local de propósito: não polui o escopo global de quem consome o pacote. */\ntype DebugWindow = Window & { __pageAgentDebug?: PageAgentDebug };\nconst debugWindow = (): DebugWindow => window;\n\nconst MAX_STEPS = 200;\nconst MAX_PAGES = 5;\nconst HEAD_LENGTH = 4000;\n\nexport function createDebugExtension(): WidgetExtension {\n const store = (): PageAgentDebug => (debugWindow().__pageAgentDebug ??= { task: \"\", steps: [], pages: [] });\n let pageCount = 0;\n\n return {\n name: \"debug\",\n hooks: {\n onBeforeTask(agent) {\n debugWindow().__pageAgentDebug = { task: agent.task, steps: [], pages: [] };\n pageCount = 0;\n console.debug(\"[page-agent debug] tarefa:\", agent.task);\n },\n\n transformPageContent(content) {\n const debug = store();\n pageCount += 1;\n debug.pages.push({ step: pageCount, length: content.length, head: content.slice(0, HEAD_LENGTH) });\n if (debug.pages.length > MAX_PAGES) debug.pages.shift();\n return content;\n },\n\n onAfterStep(_agent, history) {\n const last = [...history].reverse().find((event) => event.type === \"step\");\n if (!last || last.type !== \"step\") return;\n const entry: DebugStep = {\n step: last.stepIndex,\n goal: last.reflection.next_goal ?? \"\",\n evaluation: last.reflection.evaluation_previous_goal ?? \"\",\n tool: last.action.name,\n input: last.action.input,\n output: last.action.output.slice(0, 300),\n };\n const debug = store();\n debug.steps.push(entry);\n if (debug.steps.length > MAX_STEPS) debug.steps.shift();\n console.debug(`[page-agent debug] passo ${entry.step}: ${entry.goal} → ${entry.tool}`, entry.input, \"⇒\", entry.output);\n },\n },\n };\n}\n"],"names":[],"mappings":"AAkCA,MAAM,cAAc,MAAmB;AAEvC,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,cAAc;AAEb,SAAS,uBAAwC;AACtD,QAAM,QAAQ,MAAuB,YAAA,EAAc,qBAAqB,EAAE,MAAM,IAAI,OAAO,IAAI,OAAO,CAAA,EAAC;AACvG,MAAI,YAAY;AAEhB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,MACL,aAAa,OAAO;AAClB,oBAAA,EAAc,mBAAmB,EAAE,MAAM,MAAM,MAAM,OAAO,CAAA,GAAI,OAAO,GAAC;AACxE,oBAAY;AACZ,gBAAQ,MAAM,8BAA8B,MAAM,IAAI;AAAA,MACxD;AAAA,MAEA,qBAAqB,SAAS;AAC5B,cAAM,QAAQ,MAAA;AACd,qBAAa;AACb,cAAM,MAAM,KAAK,EAAE,MAAM,WAAW,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,MAAM,GAAG,WAAW,GAAG;AACjG,YAAI,MAAM,MAAM,SAAS,UAAW,OAAM,MAAM,MAAA;AAChD,eAAO;AAAA,MACT;AAAA,MAEA,YAAY,QAAQ,SAAS;AAC3B,cAAM,OAAO,CAAC,GAAG,OAAO,EAAE,QAAA,EAAU,KAAK,CAAC,UAAU,MAAM,SAAS,MAAM;AACzE,YAAI,CAAC,QAAQ,KAAK,SAAS,OAAQ;AACnC,cAAM,QAAmB;AAAA,UACvB,MAAM,KAAK;AAAA,UACX,MAAM,KAAK,WAAW,aAAa;AAAA,UACnC,YAAY,KAAK,WAAW,4BAA4B;AAAA,UACxD,MAAM,KAAK,OAAO;AAAA,UAClB,OAAO,KAAK,OAAO;AAAA,UACnB,QAAQ,KAAK,OAAO,OAAO,MAAM,GAAG,GAAG;AAAA,QAAA;AAEzC,cAAM,QAAQ,MAAA;AACd,cAAM,MAAM,KAAK,KAAK;AACtB,YAAI,MAAM,MAAM,SAAS,UAAW,OAAM,MAAM,MAAA;AAChD,gBAAQ,MAAM,4BAA4B,MAAM,IAAI,KAAK,MAAM,IAAI,MAAM,MAAM,IAAI,IAAI,MAAM,OAAO,KAAK,MAAM,MAAM;AAAA,MACvH;AAAA,IAAA;AAAA,EACF;AAEJ;"}