bkper 5.3.3 → 5.4.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.
- package/lib/agent/extensions/builtins.d.ts +2 -1
- package/lib/agent/extensions/builtins.d.ts.map +1 -1
- package/lib/agent/extensions/builtins.js +2 -6
- package/lib/agent/extensions/builtins.js.map +1 -1
- package/lib/agent/extensions/handoff-goal-editor.d.ts +18 -28
- package/lib/agent/extensions/handoff-goal-editor.d.ts.map +1 -1
- package/lib/agent/extensions/handoff-goal-editor.js +27 -36
- package/lib/agent/extensions/handoff-goal-editor.js.map +1 -1
- package/lib/agent/extensions/handoff.d.ts +3 -1
- package/lib/agent/extensions/handoff.d.ts.map +1 -1
- package/lib/agent/extensions/handoff.js +47 -24
- package/lib/agent/extensions/handoff.js.map +1 -1
- package/lib/agent/interactive/interactive-mode.d.ts +0 -1
- package/lib/agent/interactive/interactive-mode.d.ts.map +1 -1
- package/lib/agent/interactive/interactive-mode.js +2 -22
- package/lib/agent/interactive/interactive-mode.js.map +1 -1
- package/lib/agent/interactive/run-agent-mode.d.ts.map +1 -1
- package/lib/agent/interactive/run-agent-mode.js +8 -1
- package/lib/agent/interactive/run-agent-mode.js.map +1 -1
- package/lib/agent/pi-shared-modules.d.ts +2 -1
- package/lib/agent/pi-shared-modules.d.ts.map +1 -1
- package/lib/agent/pi-shared-modules.js +1 -1
- package/lib/agent/pi-shared-modules.js.map +1 -1
- package/lib/agent/system-prompt.d.ts.map +1 -1
- package/lib/agent/system-prompt.js +1 -8
- package/lib/agent/system-prompt.js.map +1 -1
- package/lib/commands/events/delete.d.ts +8 -0
- package/lib/commands/events/delete.d.ts.map +1 -0
- package/lib/commands/events/delete.js +27 -0
- package/lib/commands/events/delete.js.map +1 -0
- package/lib/commands/events/index.d.ts +1 -0
- package/lib/commands/events/index.d.ts.map +1 -1
- package/lib/commands/events/index.js +1 -0
- package/lib/commands/events/index.js.map +1 -1
- package/lib/commands/events/register.d.ts.map +1 -1
- package/lib/commands/events/register.js +16 -2
- package/lib/commands/events/register.js.map +1 -1
- package/lib/docs/ai/decision-models.md +1 -0
- package/lib/docs/apps/ai.md +15 -2
- package/lib/docs/apps/architecture.md +1 -0
- package/lib/docs/apps/overview.md +1 -1
- package/lib/docs/cli/app-management.md +1 -1
- package/lib/docs/cli/data-management.md +7 -3
- package/lib/docs/index.md +1 -4
- package/package.json +3 -4
- package/lib/agent/core-concepts-routing.d.ts +0 -9
- package/lib/agent/core-concepts-routing.d.ts.map +0 -1
- package/lib/agent/core-concepts-routing.js +0 -34
- package/lib/agent/core-concepts-routing.js.map +0 -1
- package/lib/agent/extensions/core-concepts-preload.d.ts +0 -27
- package/lib/agent/extensions/core-concepts-preload.d.ts.map +0 -1
- package/lib/agent/extensions/core-concepts-preload.js +0 -122
- package/lib/agent/extensions/core-concepts-preload.js.map +0 -1
- package/lib/agent/extensions/prompt-routing.d.ts +0 -12
- package/lib/agent/extensions/prompt-routing.d.ts.map +0 -1
- package/lib/agent/extensions/prompt-routing.js +0 -38
- package/lib/agent/extensions/prompt-routing.js.map +0 -1
- package/lib/agent/interactive/pending-user-message.d.ts +0 -24
- package/lib/agent/interactive/pending-user-message.d.ts.map +0 -1
- package/lib/agent/interactive/pending-user-message.js +0 -82
- package/lib/agent/interactive/pending-user-message.js.map +0 -1
- package/lib/agent/prompt-routing.d.ts +0 -33
- package/lib/agent/prompt-routing.d.ts.map +0 -1
- package/lib/agent/prompt-routing.js +0 -106
- package/lib/agent/prompt-routing.js.map +0 -1
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { createReadToolDefinition, } from '@earendil-works/pi-coding-agent';
|
|
5
|
-
import { Box } from '../pi-shared-modules.js';
|
|
6
|
-
import { CORE_CONCEPTS_ROUTE } from '../core-concepts-routing.js';
|
|
7
|
-
import { registerPromptRoutingExtension } from './prompt-routing.js';
|
|
8
|
-
export { detectCoreConceptsPreloadLevel } from '../core-concepts-routing.js';
|
|
9
|
-
/** System prompt section that grounds the session in the Bkper data model. */
|
|
10
|
-
export const CORE_CONCEPTS_SECTION = 'bkper-core-concepts';
|
|
11
|
-
/**
|
|
12
|
-
* Display-only session entry marking where the section was loaded. Never sent to the model.
|
|
13
|
-
* Sessions saved before the section existed carry custom messages of the same type.
|
|
14
|
-
*/
|
|
15
|
-
export const CORE_CONCEPTS_ENTRY_TYPE = 'bkper-core-concepts';
|
|
16
|
-
export function resolveBkperDocPathFromModuleDir(moduleDir, relativePath) {
|
|
17
|
-
const candidates = [
|
|
18
|
-
path.resolve(moduleDir, '..', '..', 'docs', relativePath),
|
|
19
|
-
path.resolve(moduleDir, '..', '..', '..', 'skill', 'references', relativePath),
|
|
20
|
-
];
|
|
21
|
-
for (const candidate of candidates) {
|
|
22
|
-
if (existsSync(candidate)) {
|
|
23
|
-
return candidate;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return candidates[0];
|
|
27
|
-
}
|
|
28
|
-
function resolveDocPath(relativePath) {
|
|
29
|
-
const thisDir = path.dirname(fileURLToPath(import.meta.url));
|
|
30
|
-
return resolveBkperDocPathFromModuleDir(thisDir, relativePath);
|
|
31
|
-
}
|
|
32
|
-
export function getCoreConceptsDocPath() {
|
|
33
|
-
return resolveDocPath('core/core-concepts.md');
|
|
34
|
-
}
|
|
35
|
-
export function getDefaultCoreConceptsPreloadDefinition() {
|
|
36
|
-
const docPath = getCoreConceptsDocPath();
|
|
37
|
-
return {
|
|
38
|
-
docPath,
|
|
39
|
-
markdown: readFileSync(docPath, 'utf8'),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function buildCoreConceptsSection(definition) {
|
|
43
|
-
return `Loaded from \`${definition.docPath}\`. Base all reasoning about Bkper data on this reference.\n\n${definition.markdown}`;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Whether the section was loaded in this branch, replayed from the transcript's system
|
|
47
|
-
* messages. Compaction checkpoints carry the replayed sections, so this survives
|
|
48
|
-
* compaction, resume, and branch navigation. A load that Pi later removed still counts:
|
|
49
|
-
* runs started without before_agent_start, such as extension-triggered turns, rebuild
|
|
50
|
-
* the prompt without the section, and the next prompt must restore it.
|
|
51
|
-
*/
|
|
52
|
-
function wasCoreConceptsLoaded(ctx) {
|
|
53
|
-
const messages = ctx.sessionManager.buildSessionProjection().messages;
|
|
54
|
-
return messages.some(message => { var _a; return message.role === 'system' && typeof ((_a = message.sections) === null || _a === void 0 ? void 0 : _a[CORE_CONCEPTS_SECTION]) === 'string'; });
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Renders the doc with Pi's own read tool renderers, so it looks like a read of the
|
|
58
|
-
* doc: collapsed shows the path, expanded shows the content.
|
|
59
|
-
*/
|
|
60
|
-
function renderCoreConceptsRead(definition, expanded, theme) {
|
|
61
|
-
const cwd = process.cwd();
|
|
62
|
-
const read = createReadToolDefinition(cwd);
|
|
63
|
-
if (!read.renderCall || !read.renderResult) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
const args = { path: definition.docPath };
|
|
67
|
-
const context = {
|
|
68
|
-
args,
|
|
69
|
-
toolCallId: CORE_CONCEPTS_ENTRY_TYPE,
|
|
70
|
-
invalidate: () => undefined,
|
|
71
|
-
lastComponent: undefined,
|
|
72
|
-
state: {},
|
|
73
|
-
cwd,
|
|
74
|
-
executionStarted: true,
|
|
75
|
-
argsComplete: true,
|
|
76
|
-
isPartial: false,
|
|
77
|
-
expanded,
|
|
78
|
-
showImages: false,
|
|
79
|
-
isError: false,
|
|
80
|
-
};
|
|
81
|
-
// Same shell Pi uses for a successful tool row.
|
|
82
|
-
const box = new Box(1, 1, (text) => theme.bg('toolSuccessBg', text));
|
|
83
|
-
box.addChild(read.renderCall(args, theme, context));
|
|
84
|
-
box.addChild(read.renderResult({ content: [{ type: 'text', text: definition.markdown }], details: undefined }, { expanded, isPartial: false }, theme, context));
|
|
85
|
-
return box;
|
|
86
|
-
}
|
|
87
|
-
function createCoreConceptsEntryRenderer(definition) {
|
|
88
|
-
return (_entry, options, theme) => renderCoreConceptsRead(definition, options.expanded, theme);
|
|
89
|
-
}
|
|
90
|
-
function createLegacyCoreConceptsMessageRenderer(definition) {
|
|
91
|
-
return (_message, options, theme) => renderCoreConceptsRead(definition, options.expanded, theme);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Grounds accounting and finance sessions in the Bkper data model through a system
|
|
95
|
-
* prompt section. Once loaded, the section is kept for the rest of the session: Pi
|
|
96
|
-
* rebuilds the prompt from its base options on every prompt, so a section that is
|
|
97
|
-
* not set again would be removed. Pi appends the section as a mid-conversation
|
|
98
|
-
* system message, which keeps the cached prefix on models that accept those messages.
|
|
99
|
-
*/
|
|
100
|
-
export function registerBkperCoreConceptsPreloadExtension(pi, definition = getDefaultCoreConceptsPreloadDefinition(), router = registerPromptRoutingExtension(pi)) {
|
|
101
|
-
const section = buildCoreConceptsSection(definition);
|
|
102
|
-
let markLoad = false;
|
|
103
|
-
pi.registerEntryRenderer(CORE_CONCEPTS_ENTRY_TYPE, createCoreConceptsEntryRenderer(definition));
|
|
104
|
-
pi.registerMessageRenderer(CORE_CONCEPTS_ENTRY_TYPE, createLegacyCoreConceptsMessageRenderer(definition));
|
|
105
|
-
router.registerLoader(Object.assign(Object.assign({}, CORE_CONCEPTS_ROUTE), { isLoaded: wasCoreConceptsLoaded, apply(event, _ctx, load, alreadyLoaded) {
|
|
106
|
-
markLoad = false;
|
|
107
|
-
if (!load)
|
|
108
|
-
return;
|
|
109
|
-
event.systemPromptOptions.sections[CORE_CONCEPTS_SECTION] = section;
|
|
110
|
-
markLoad = !alreadyLoaded;
|
|
111
|
-
} }));
|
|
112
|
-
// The user prompt is persisted once its message ends, so the first assistant
|
|
113
|
-
// message is the earliest point where the marker lands after the prompt.
|
|
114
|
-
pi.on('message_start', (event) => {
|
|
115
|
-
if (!markLoad || event.message.role !== 'assistant') {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
markLoad = false;
|
|
119
|
-
pi.appendEntry(CORE_CONCEPTS_ENTRY_TYPE);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
//# sourceMappingURL=core-concepts-preload.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core-concepts-preload.js","sourceRoot":"","sources":["../../../src/agent/extensions/core-concepts-preload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EACH,wBAAwB,GAU3B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAC9C,OAAO,EAAC,mBAAmB,EAAC,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAC,8BAA8B,EAA0B,MAAM,qBAAqB,CAAC;AAE5F,OAAO,EAAC,8BAA8B,EAAC,MAAM,6BAA6B,CAAC;AAQ3E,8EAA8E;AAC9E,MAAM,CAAC,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AAE3D;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,CAAC;AAK9D,MAAM,UAAU,gCAAgC,CAC5C,SAAiB,EACjB,YAAoB;IAEpB,MAAM,UAAU,GAAG;QACf,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC;QACzD,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC;KACjF,CAAC;IAEF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACjC,IAAI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wBAAwB,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { BeforeAgentStartEvent, ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
2
|
-
import { type PromptRoute } from '../prompt-routing.js';
|
|
3
|
-
/** Loaders own injection and persistence; the router only owns prompt decisions. */
|
|
4
|
-
export interface PromptLoader extends PromptRoute {
|
|
5
|
-
isLoaded(ctx: ExtensionContext): boolean;
|
|
6
|
-
apply(event: BeforeAgentStartEvent, ctx: ExtensionContext, load: boolean, alreadyLoaded: boolean): void;
|
|
7
|
-
}
|
|
8
|
-
export interface PromptLoaderRouter {
|
|
9
|
-
registerLoader(loader: PromptLoader): void;
|
|
10
|
-
}
|
|
11
|
-
export declare function registerPromptRoutingExtension(pi: Pick<ExtensionAPI, 'on'>): PromptLoaderRouter;
|
|
12
|
-
//# sourceMappingURL=prompt-routing.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-routing.d.ts","sourceRoot":"","sources":["../../../src/agent/extensions/prompt-routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,EACnB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAGH,KAAK,WAAW,EACnB,MAAM,sBAAsB,CAAC;AAE9B,oFAAoF;AACpF,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC7C,QAAQ,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC;IACzC,KAAK,CACD,KAAK,EAAE,qBAAqB,EAC5B,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE,OAAO,EACb,aAAa,EAAE,OAAO,GACvB,IAAI,CAAC;CACX;AAED,MAAM,WAAW,kBAAkB;IAC/B,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;CAC9C;AAED,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,kBAAkB,CAoC/F"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { buildPromptRoutingInput, evaluatePromptRoutes, } from '../prompt-routing.js';
|
|
11
|
-
export function registerPromptRoutingExtension(pi) {
|
|
12
|
-
const loaders = [];
|
|
13
|
-
pi.on('before_agent_start', (event, ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
var _a;
|
|
15
|
-
const states = loaders.map(loader => ({ loader, loaded: loader.isLoaded(ctx) }));
|
|
16
|
-
const pending = states.filter(state => !state.loaded).map(state => state.loader);
|
|
17
|
-
const decisions = pending.length > 0
|
|
18
|
-
? yield evaluatePromptRoutes(buildPromptRoutingInput(event.prompt, ctx.sessionManager.buildSessionProjection().messages), pending, ctx.modelRegistry, { signal: ctx.signal })
|
|
19
|
-
: {};
|
|
20
|
-
for (const { loader, loaded } of states) {
|
|
21
|
-
loader.apply(event, ctx, loaded || ((_a = decisions[loader.id]) === null || _a === void 0 ? void 0 : _a.load) === true, loaded);
|
|
22
|
-
}
|
|
23
|
-
}));
|
|
24
|
-
return {
|
|
25
|
-
registerLoader(loader) {
|
|
26
|
-
if (loaders.some(existing => existing.id === loader.id)) {
|
|
27
|
-
throw new Error(`Prompt loader already registered: ${loader.id}`);
|
|
28
|
-
}
|
|
29
|
-
if (!Number.isFinite(loader.threshold) ||
|
|
30
|
-
loader.threshold < 0 ||
|
|
31
|
-
loader.threshold > 1) {
|
|
32
|
-
throw new Error(`Invalid prompt routing threshold: ${loader.id}`);
|
|
33
|
-
}
|
|
34
|
-
loaders.push(loader);
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=prompt-routing.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-routing.js","sourceRoot":"","sources":["../../../src/agent/extensions/prompt-routing.ts"],"names":[],"mappings":";;;;;;;;;AAKA,OAAO,EACH,uBAAuB,EACvB,oBAAoB,GAEvB,MAAM,sBAAsB,CAAC;AAiB9B,MAAM,UAAU,8BAA8B,CAAC,EAA4B;IACvE,MAAM,OAAO,GAAmB,EAAE,CAAC;IACnC,EAAE,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAO,KAAK,EAAE,GAAG,EAAE,EAAE;;QAC7C,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAC,CAAC,CAAC,CAAC;QAC/E,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACjF,MAAM,SAAS,GACX,OAAO,CAAC,MAAM,GAAG,CAAC;YACd,CAAC,CAAC,MAAM,oBAAoB,CACtB,uBAAuB,CACnB,KAAK,CAAC,MAAM,EACZ,GAAG,CAAC,cAAc,CAAC,sBAAsB,EAAE,CAAC,QAAQ,CACvD,EACD,OAAO,EACP,GAAG,CAAC,aAAa,EACjB,EAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAC,CACvB;YACH,CAAC,CAAC,EAAE,CAAC;QACb,KAAK,MAAM,EAAC,MAAM,EAAE,MAAM,EAAC,IAAI,MAAM,EAAE,CAAC;YACpC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,IAAI,CAAA,MAAA,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,0CAAE,IAAI,MAAK,IAAI,EAAE,MAAM,CAAC,CAAC;QACpF,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;IACH,OAAO;QACH,cAAc,CAAC,MAAM;YACjB,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;gBACtD,MAAM,IAAI,KAAK,CAAC,qCAAqC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;YACtE,CAAC;YACD,IACI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC;gBAClC,MAAM,CAAC,SAAS,GAAG,CAAC;gBACpB,MAAM,CAAC,SAAS,GAAG,CAAC,EACtB,CAAC;gBACC,MAAM,IAAI,KAAK,CAAC,qCAAqC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;YACtE,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { AgentSession, AgentSessionEvent, MessageStartEvent } from '@earendil-works/pi-coding-agent';
|
|
2
|
-
import type { Container, TUI } from '@earendil-works/pi-tui';
|
|
3
|
-
type UserMessage = Extract<MessageStartEvent['message'], {
|
|
4
|
-
role: 'user';
|
|
5
|
-
}>;
|
|
6
|
-
/** Private Pi UI surface, isolated here until Pi supports preflight previews. */
|
|
7
|
-
export interface PendingUserMessageHost {
|
|
8
|
-
session: {
|
|
9
|
-
prompt: AgentSession['prompt'];
|
|
10
|
-
isStreaming: boolean;
|
|
11
|
-
isCompacting: boolean;
|
|
12
|
-
};
|
|
13
|
-
chatContainer: Pick<Container, 'children' | 'removeChild'>;
|
|
14
|
-
ui: Pick<TUI, 'requestRender'>;
|
|
15
|
-
addMessageToChat(message: UserMessage): void;
|
|
16
|
-
handleEvent(event: AgentSessionEvent): Promise<void>;
|
|
17
|
-
rebindCurrentSession?(options?: {
|
|
18
|
-
renderBeforeBind?: boolean;
|
|
19
|
-
}): Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
/** Preview only in the UI: Pi remains responsible for canonical messages and history. */
|
|
22
|
-
export declare function installPendingUserMessage(host: PendingUserMessageHost): () => void;
|
|
23
|
-
export {};
|
|
24
|
-
//# sourceMappingURL=pending-user-message.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pending-user-message.d.ts","sourceRoot":"","sources":["../../../src/agent/interactive/pending-user-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAY,SAAS,EAAE,GAAG,EAAC,MAAM,wBAAwB,CAAC;AAEtE,KAAK,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC,CAAC;AAEzE,iFAAiF;AACjF,MAAM,WAAW,sBAAsB;IACnC,OAAO,EAAE;QACL,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC/B,WAAW,EAAE,OAAO,CAAC;QACrB,YAAY,EAAE,OAAO,CAAC;KACzB,CAAC;IACF,aAAa,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,GAAG,aAAa,CAAC,CAAC;IAC3D,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IAC/B,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC7C,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,oBAAoB,CAAC,CAAC,OAAO,CAAC,EAAE;QAAC,gBAAgB,CAAC,EAAE,OAAO,CAAA;KAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChF;AAED,yFAAyF;AACzF,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,sBAAsB,GAAG,MAAM,IAAI,CAiElF"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
/** Preview only in the UI: Pi remains responsible for canonical messages and history. */
|
|
11
|
-
export function installPendingUserMessage(host) {
|
|
12
|
-
let session = host.session;
|
|
13
|
-
let prompt = session.prompt;
|
|
14
|
-
const handleEvent = host.handleEvent;
|
|
15
|
-
const rebindCurrentSession = host.rebindCurrentSession;
|
|
16
|
-
let pending;
|
|
17
|
-
const clear = () => {
|
|
18
|
-
if (!pending)
|
|
19
|
-
return;
|
|
20
|
-
for (const component of pending)
|
|
21
|
-
host.chatContainer.removeChild(component);
|
|
22
|
-
pending = undefined;
|
|
23
|
-
host.ui.requestRender();
|
|
24
|
-
};
|
|
25
|
-
const promptWithPreview = (text, options) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const trimmed = text.trim();
|
|
27
|
-
const preview = !pending &&
|
|
28
|
-
!session.isStreaming &&
|
|
29
|
-
!session.isCompacting &&
|
|
30
|
-
(!(options === null || options === void 0 ? void 0 : options.source) || options.source === 'interactive') &&
|
|
31
|
-
trimmed.length > 0 &&
|
|
32
|
-
!trimmed.startsWith('/') &&
|
|
33
|
-
!trimmed.startsWith('!');
|
|
34
|
-
let components;
|
|
35
|
-
if (preview) {
|
|
36
|
-
const start = host.chatContainer.children.length;
|
|
37
|
-
host.addMessageToChat({ role: 'user', content: trimmed, timestamp: Date.now() });
|
|
38
|
-
components = host.chatContainer.children.slice(start);
|
|
39
|
-
pending = components;
|
|
40
|
-
host.ui.requestRender();
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
yield prompt.call(session, text, options);
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
// Handled/rejected input has no user message event. Do not leave a ghost row.
|
|
47
|
-
if (components && pending === components)
|
|
48
|
-
clear();
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
const handleEventWithPreview = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
if (event.type === 'message_start' && event.message.role === 'user')
|
|
53
|
-
clear();
|
|
54
|
-
yield handleEvent.call(host, event);
|
|
55
|
-
});
|
|
56
|
-
const rebindWithPreview = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
if (host.session !== session) {
|
|
58
|
-
clear();
|
|
59
|
-
if (session.prompt === promptWithPreview)
|
|
60
|
-
session.prompt = prompt;
|
|
61
|
-
session = host.session;
|
|
62
|
-
prompt = session.prompt;
|
|
63
|
-
session.prompt = promptWithPreview;
|
|
64
|
-
}
|
|
65
|
-
yield (rebindCurrentSession === null || rebindCurrentSession === void 0 ? void 0 : rebindCurrentSession.call(host, options));
|
|
66
|
-
});
|
|
67
|
-
session.prompt = promptWithPreview;
|
|
68
|
-
host.handleEvent = handleEventWithPreview;
|
|
69
|
-
if (rebindCurrentSession)
|
|
70
|
-
host.rebindCurrentSession = rebindWithPreview;
|
|
71
|
-
return () => {
|
|
72
|
-
clear();
|
|
73
|
-
if (session.prompt === promptWithPreview)
|
|
74
|
-
session.prompt = prompt;
|
|
75
|
-
if (host.handleEvent === handleEventWithPreview)
|
|
76
|
-
host.handleEvent = handleEvent;
|
|
77
|
-
if (host.rebindCurrentSession === rebindWithPreview) {
|
|
78
|
-
host.rebindCurrentSession = rebindCurrentSession;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
//# sourceMappingURL=pending-user-message.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pending-user-message.js","sourceRoot":"","sources":["../../../src/agent/interactive/pending-user-message.ts"],"names":[],"mappings":";;;;;;;;;AAuBA,yFAAyF;AACzF,MAAM,UAAU,yBAAyB,CAAC,IAA4B;IAClE,IAAI,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC3B,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC5B,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IACrC,MAAM,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC;IACvD,IAAI,OAAgC,CAAC;IAErC,MAAM,KAAK,GAAG,GAAG,EAAE;QACf,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,KAAK,MAAM,SAAS,IAAI,OAAO;YAAE,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAC3E,OAAO,GAAG,SAAS,CAAC;QACpB,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC;IAC5B,CAAC,CAAC;IAEF,MAAM,iBAAiB,GAA2B,CAAO,IAAI,EAAE,OAAO,EAAE,EAAE;QACtE,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,OAAO,GACT,CAAC,OAAO;YACR,CAAC,OAAO,CAAC,WAAW;YACpB,CAAC,OAAO,CAAC,YAAY;YACrB,CAAC,CAAC,CAAA,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I,IAAI,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;YAC3B,KAAK,EAAE,CAAC;YACR,IAAI,OAAO,CAAC,MAAM,KAAK,iBAAiB;gBAAE,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;YAClE,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;YACvB,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YACxB,OAAO,CAAC,MAAM,GAAG,iBAAiB,CAAC;QACvC,CAAC;QACD,MAAM,CAAA,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAE,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA,CAAC;IACpD,CAAC,CAAA,CAAC;IACF,OAAO,CAAC,MAAM,GAAG,iBAAiB,CAAC;IACnC,IAAI,CAAC,WAAW,GAAG,sBAAsB,CAAC;IAC1C,IAAI,oBAAoB;QAAE,IAAI,CAAC,oBAAoB,GAAG,iBAAiB,CAAC;IAExE,OAAO,GAAG,EAAE;QACR,KAAK,EAAE,CAAC;QACR,IAAI,OAAO,CAAC,MAAM,KAAK,iBAAiB;YAAE,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;QAClE,IAAI,IAAI,CAAC,WAAW,KAAK,sBAAsB;YAAE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAChF,IAAI,IAAI,CAAC,oBAAoB,KAAK,iBAAiB,EAAE,CAAC;YAClD,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;QACrD,CAAC;IACL,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { ClassifierBoolQuestion } from '@earendil-works/pi-ai';
|
|
2
|
-
import type { ModelRegistry, SessionProjection } from '@earendil-works/pi-coding-agent';
|
|
3
|
-
export declare const PROMPT_ROUTING_MODEL: {
|
|
4
|
-
readonly provider: "bkper";
|
|
5
|
-
readonly id: "jev";
|
|
6
|
-
};
|
|
7
|
-
export declare const PROMPT_ROUTING_TIMEOUT_MS = 5000;
|
|
8
|
-
export interface PromptRoutingInput {
|
|
9
|
-
prompt: string;
|
|
10
|
-
recentUserMessages: string[];
|
|
11
|
-
}
|
|
12
|
-
/** Independent yes/no routes: more than one may match the same prompt. */
|
|
13
|
-
export interface PromptRoute {
|
|
14
|
-
id: string;
|
|
15
|
-
question: ClassifierBoolQuestion;
|
|
16
|
-
threshold: number;
|
|
17
|
-
fallback(input: PromptRoutingInput): boolean;
|
|
18
|
-
}
|
|
19
|
-
export interface PromptRouteDecision {
|
|
20
|
-
load: boolean;
|
|
21
|
-
source: 'classifier' | 'fallback';
|
|
22
|
-
probability?: number;
|
|
23
|
-
reason?: string;
|
|
24
|
-
}
|
|
25
|
-
export type PromptRoutingRegistry = Pick<ModelRegistry, 'getAvailableOfType' | 'classify'>;
|
|
26
|
-
/** Only user text from the current branch is sent; never tool output or images. */
|
|
27
|
-
export declare function buildPromptRoutingInput(prompt: string, messages?: SessionProjection['messages']): PromptRoutingInput;
|
|
28
|
-
/** One bounded Jev call for all pending questions, with a fallback per route. */
|
|
29
|
-
export declare function evaluatePromptRoutes(input: PromptRoutingInput, routes: readonly PromptRoute[], registry: PromptRoutingRegistry, options?: {
|
|
30
|
-
timeoutMs?: number;
|
|
31
|
-
signal?: AbortSignal;
|
|
32
|
-
}): Promise<Record<string, PromptRouteDecision>>;
|
|
33
|
-
//# sourceMappingURL=prompt-routing.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-routing.d.ts","sourceRoot":"","sources":["../../src/agent/prompt-routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,sBAAsB,EAAC,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAC,aAAa,EAAE,iBAAiB,EAAC,MAAM,iCAAiC,CAAC;AAEtF,eAAO,MAAM,oBAAoB;;;CAA0C,CAAC;AAC5E,eAAO,MAAM,yBAAyB,OAAQ,CAAC;AAK/C,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAChC;AAED,0EAA0E;AAC1E,MAAM,WAAW,WAAW;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,sBAAsB,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC;CAChD;AAED,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,YAAY,GAAG,UAAU,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,aAAa,EAAE,oBAAoB,GAAG,UAAU,CAAC,CAAC;AAE3F,mFAAmF;AACnF,wBAAgB,uBAAuB,CACnC,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,iBAAiB,CAAC,UAAU,CAAM,GAC7C,kBAAkB,CAmBpB;AAED,iFAAiF;AACjF,wBAAsB,oBAAoB,CACtC,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,SAAS,WAAW,EAAE,EAC9B,QAAQ,EAAE,qBAAqB,EAC/B,OAAO,GAAE;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAM,GACzD,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CA4E9C"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export const PROMPT_ROUTING_MODEL = { provider: 'bkper', id: 'jev' };
|
|
11
|
-
export const PROMPT_ROUTING_TIMEOUT_MS = 5000;
|
|
12
|
-
const MAX_PROMPT_CHARS = 16000;
|
|
13
|
-
const MAX_RECENT_USER_MESSAGES = 3;
|
|
14
|
-
const MAX_CONTEXT_MESSAGE_CHARS = 2000;
|
|
15
|
-
/** Only user text from the current branch is sent; never tool output or images. */
|
|
16
|
-
export function buildPromptRoutingInput(prompt, messages = []) {
|
|
17
|
-
const recentUserMessages = [];
|
|
18
|
-
for (let i = messages.length - 1; i >= 0 && recentUserMessages.length < MAX_RECENT_USER_MESSAGES; i--) {
|
|
19
|
-
const message = messages[i];
|
|
20
|
-
if (message.role !== 'user')
|
|
21
|
-
continue;
|
|
22
|
-
const text = typeof message.content === 'string'
|
|
23
|
-
? message.content
|
|
24
|
-
: message.content
|
|
25
|
-
.filter(block => block.type === 'text')
|
|
26
|
-
.map(block => block.text)
|
|
27
|
-
.join('\n');
|
|
28
|
-
if (text.trim())
|
|
29
|
-
recentUserMessages.unshift(text.slice(0, MAX_CONTEXT_MESSAGE_CHARS));
|
|
30
|
-
}
|
|
31
|
-
return { prompt: prompt.slice(0, MAX_PROMPT_CHARS), recentUserMessages };
|
|
32
|
-
}
|
|
33
|
-
/** One bounded Jev call for all pending questions, with a fallback per route. */
|
|
34
|
-
export function evaluatePromptRoutes(input_1, routes_1, registry_1) {
|
|
35
|
-
return __awaiter(this, arguments, void 0, function* (input, routes, registry, options = {}) {
|
|
36
|
-
var _a, _b, _c, _d;
|
|
37
|
-
if (routes.length === 0)
|
|
38
|
-
return {};
|
|
39
|
-
const fallback = (route, reason) => ({
|
|
40
|
-
load: route.fallback(input),
|
|
41
|
-
source: 'fallback',
|
|
42
|
-
reason,
|
|
43
|
-
});
|
|
44
|
-
const fallbackAll = (reason) => Object.fromEntries(routes.map(route => [route.id, fallback(route, reason)]));
|
|
45
|
-
if (!input.prompt.trim())
|
|
46
|
-
return fallbackAll('Empty prompt.');
|
|
47
|
-
const controller = new AbortController();
|
|
48
|
-
const cancel = () => controller.abort('Routing cancelled.');
|
|
49
|
-
let onAbort;
|
|
50
|
-
const stopped = new Promise(resolve => {
|
|
51
|
-
onAbort = () => resolve(fallbackAll(String(controller.signal.reason)));
|
|
52
|
-
controller.signal.addEventListener('abort', onAbort, { once: true });
|
|
53
|
-
});
|
|
54
|
-
(_a = options.signal) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', cancel, { once: true });
|
|
55
|
-
const timer = setTimeout(() => controller.abort('Routing timed out.'), (_b = options.timeoutMs) !== null && _b !== void 0 ? _b : PROMPT_ROUTING_TIMEOUT_MS);
|
|
56
|
-
if ((_c = options.signal) === null || _c === void 0 ? void 0 : _c.aborted)
|
|
57
|
-
cancel();
|
|
58
|
-
const classify = () => __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
var _a;
|
|
60
|
-
try {
|
|
61
|
-
if (controller.signal.aborted)
|
|
62
|
-
return yield stopped;
|
|
63
|
-
const available = yield registry.getAvailableOfType('classifier', PROMPT_ROUTING_MODEL.provider, { signal: controller.signal });
|
|
64
|
-
if (controller.signal.aborted)
|
|
65
|
-
return yield stopped;
|
|
66
|
-
const model = available.find(candidate => candidate.id === PROMPT_ROUTING_MODEL.id);
|
|
67
|
-
if (!model)
|
|
68
|
-
return fallbackAll('Jev unavailable.');
|
|
69
|
-
const result = yield registry.classify(model, {
|
|
70
|
-
state: { prompt: input.prompt, recentUserMessages: input.recentUserMessages },
|
|
71
|
-
questions: Object.fromEntries(routes.map(route => [route.id, route.question])),
|
|
72
|
-
}, { signal: controller.signal });
|
|
73
|
-
if (result.stopReason !== 'stop')
|
|
74
|
-
return fallbackAll((_a = result.errorMessage) !== null && _a !== void 0 ? _a : result.stopReason);
|
|
75
|
-
return Object.fromEntries(routes.map(route => {
|
|
76
|
-
const answer = result.answers[route.id];
|
|
77
|
-
const probability = (answer === null || answer === void 0 ? void 0 : answer.type) === 'bool' ? answer.probability : undefined;
|
|
78
|
-
const decision = probability !== undefined &&
|
|
79
|
-
Number.isFinite(probability) &&
|
|
80
|
-
probability >= 0 &&
|
|
81
|
-
probability <= 1
|
|
82
|
-
? {
|
|
83
|
-
load: probability >= route.threshold,
|
|
84
|
-
source: 'classifier',
|
|
85
|
-
probability,
|
|
86
|
-
}
|
|
87
|
-
: fallback(route, 'Missing or invalid answer.');
|
|
88
|
-
return [route.id, decision];
|
|
89
|
-
}));
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
return fallbackAll(error instanceof Error ? error.message : String(error));
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
try {
|
|
96
|
-
// Race as well as abort: misbehaving providers must not block a user prompt.
|
|
97
|
-
return yield Promise.race([classify(), stopped]);
|
|
98
|
-
}
|
|
99
|
-
finally {
|
|
100
|
-
clearTimeout(timer);
|
|
101
|
-
(_d = options.signal) === null || _d === void 0 ? void 0 : _d.removeEventListener('abort', cancel);
|
|
102
|
-
controller.signal.removeEventListener('abort', onAbort);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
//# sourceMappingURL=prompt-routing.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-routing.js","sourceRoot":"","sources":["../../src/agent/prompt-routing.ts"],"names":[],"mappings":";;;;;;;;;AAGA,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAU,CAAC;AAC5E,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAK,CAAC;AAC/C,MAAM,gBAAgB,GAAG,KAAM,CAAC;AAChC,MAAM,wBAAwB,GAAG,CAAC,CA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