@agimon-ai/po-core 0.0.0-alpha.206 → 0.0.0-alpha.208
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/dist/apiContracts.d.mts +2 -0
- package/dist/apiContracts.d.mts.map +1 -1
- package/dist/contextProjection.cjs +15 -2
- package/dist/contextProjection.cjs.map +1 -1
- package/dist/contextProjection.d.mts +5 -0
- package/dist/contextProjection.d.mts.map +1 -1
- package/dist/contextProjection.mjs +15 -3
- package/dist/contextProjection.mjs.map +1 -1
- package/dist/headless.cjs +4 -0
- package/dist/headless.d.mts +2 -2
- package/dist/headless.mjs +2 -2
- package/dist/headlessHub.cjs +18 -13
- package/dist/headlessHub.cjs.map +1 -1
- package/dist/headlessHub.d.mts +5 -5
- package/dist/headlessHub.d.mts.map +1 -1
- package/dist/headlessHub.mjs +15 -10
- package/dist/headlessHub.mjs.map +1 -1
- package/dist/headlessProtocol.cjs +2 -2
- package/dist/headlessProtocol.mjs +2 -2
- package/dist/headlessServer.cjs +4 -4
- package/dist/headlessServer.mjs +4 -4
- package/dist/headlessSessionHost.d.mts +1 -0
- package/dist/headlessSessionHost.d.mts.map +1 -1
- package/dist/hubChannel.cjs +1 -0
- package/dist/hubChannel.d.mts +2 -2
- package/dist/hubChannel.mjs +2 -2
- package/dist/packageApiServer.cjs +11 -11
- package/dist/packageApiServer.cjs.map +1 -1
- package/dist/packageApiServer.mjs +5 -5
- package/dist/po-runtime-identity.json +1 -1
- package/dist/serverPlugin.cjs +5 -3
- package/dist/serverPlugin.d.mts +2 -2
- package/dist/serverPlugin.mjs +5 -4
- package/dist/sessionProtocol.cjs +1 -1
- package/dist/sessionProtocol.mjs +1 -1
- package/dist/skills.cjs +4 -0
- package/dist/skills.d.mts +2 -1
- package/dist/skills.mjs +3 -1
- package/dist/src/extensions/extensionFile.cjs +7 -1
- package/dist/src/extensions/extensionFile.cjs.map +1 -1
- package/dist/src/extensions/extensionFile.d.mts +7 -2
- package/dist/src/extensions/extensionFile.d.mts.map +1 -1
- package/dist/src/extensions/extensionFile.mjs +7 -1
- package/dist/src/extensions/extensionFile.mjs.map +1 -1
- package/dist/src/pi/piSessionRuntime.cjs +1 -1
- package/dist/src/pi/piSessionRuntime.mjs +1 -1
- package/dist/src/schemas/approval.cjs.map +1 -1
- package/dist/src/schemas/approval.d.mts +2 -0
- package/dist/src/schemas/approval.d.mts.map +1 -1
- package/dist/src/schemas/approval.mjs.map +1 -1
- package/dist/src/schemas/backgroundWork.cjs +2 -1
- package/dist/src/schemas/backgroundWork.cjs.map +1 -1
- package/dist/src/schemas/backgroundWork.d.mts +1 -1
- package/dist/src/schemas/backgroundWork.d.mts.map +1 -1
- package/dist/src/schemas/backgroundWork.mjs +2 -1
- package/dist/src/schemas/backgroundWork.mjs.map +1 -1
- package/dist/src/schemas/childReport.cjs +7 -1
- package/dist/src/schemas/childReport.cjs.map +1 -1
- package/dist/src/schemas/childReport.d.mts +2 -0
- package/dist/src/schemas/childReport.d.mts.map +1 -1
- package/dist/src/schemas/childReport.mjs +7 -2
- package/dist/src/schemas/childReport.mjs.map +1 -1
- package/dist/src/schemas/headless.cjs +21 -0
- package/dist/src/schemas/headless.cjs.map +1 -1
- package/dist/src/schemas/headless.d.mts +130 -0
- package/dist/src/schemas/headless.d.mts.map +1 -1
- package/dist/src/schemas/headless.mjs +18 -1
- package/dist/src/schemas/headless.mjs.map +1 -1
- package/dist/src/schemas/mcpFacet.cjs.map +1 -1
- package/dist/src/schemas/mcpFacet.d.mts +2 -1
- package/dist/src/schemas/mcpFacet.d.mts.map +1 -1
- package/dist/src/schemas/mcpFacet.mjs.map +1 -1
- package/dist/src/schemas/serverBundle.cjs +13 -0
- package/dist/src/schemas/serverBundle.cjs.map +1 -0
- package/dist/src/schemas/serverBundle.d.mts +12 -0
- package/dist/src/schemas/serverBundle.d.mts.map +1 -1
- package/dist/src/schemas/serverBundle.mjs +13 -0
- package/dist/src/schemas/serverBundle.mjs.map +1 -0
- package/dist/src/server/directHarnessRuntime.cjs +102 -25
- package/dist/src/server/directHarnessRuntime.cjs.map +1 -1
- package/dist/src/server/directHarnessRuntime.mjs +102 -25
- package/dist/src/server/directHarnessRuntime.mjs.map +1 -1
- package/dist/src/server/mcpBundleLoader.cjs +2 -1
- package/dist/src/server/mcpBundleLoader.cjs.map +1 -1
- package/dist/src/server/mcpBundleLoader.d.mts.map +1 -1
- package/dist/src/server/mcpBundleLoader.mjs +2 -1
- package/dist/src/server/mcpBundleLoader.mjs.map +1 -1
- package/dist/src/server/serverPackages.cjs +2 -4
- package/dist/src/server/serverPackages.cjs.map +1 -1
- package/dist/src/server/serverPackages.d.mts.map +1 -1
- package/dist/src/server/serverPackages.mjs +2 -4
- package/dist/src/server/serverPackages.mjs.map +1 -1
- package/dist/src/server/serverScope.cjs +8 -8
- package/dist/src/server/serverScope.mjs +4 -4
- package/dist/src/services/approvalGate/index.cjs +8 -4
- package/dist/src/services/approvalGate/index.cjs.map +1 -1
- package/dist/src/services/approvalGate/index.d.mts.map +1 -1
- package/dist/src/services/approvalGate/index.mjs +8 -4
- package/dist/src/services/approvalGate/index.mjs.map +1 -1
- package/dist/src/services/piExtensionHost/index.cjs +2 -0
- package/dist/src/services/piExtensionHost/index.cjs.map +1 -1
- package/dist/src/services/piExtensionHost/index.d.mts.map +1 -1
- package/dist/src/services/piExtensionHost/index.mjs +2 -0
- package/dist/src/services/piExtensionHost/index.mjs.map +1 -1
- package/dist/src/services/sessionAttachments/index.cjs +1 -1
- package/dist/src/services/sessionAttachments/index.mjs +1 -1
- package/dist/src/services/skillPrompt/index.cjs +10 -5
- package/dist/src/services/skillPrompt/index.cjs.map +1 -1
- package/dist/src/services/skillPrompt/index.mjs +10 -5
- package/dist/src/services/skillPrompt/index.mjs.map +1 -1
- package/dist/src/services/skillRelations/index.cjs +113 -0
- package/dist/src/services/skillRelations/index.cjs.map +1 -0
- package/dist/src/services/skillRelations/index.d.mts +32 -0
- package/dist/src/services/skillRelations/index.d.mts.map +1 -0
- package/dist/src/services/skillRelations/index.mjs +111 -0
- package/dist/src/services/skillRelations/index.mjs.map +1 -0
- package/dist/src/services/transcriptPages/index.cjs +1 -1
- package/dist/src/services/transcriptPages/index.cjs.map +1 -1
- package/dist/src/services/transcriptPages/index.mjs +1 -1
- package/dist/src/services/transcriptPages/index.mjs.map +1 -1
- package/dist/src/systems/child/adapters/headlessChildSessionService.cjs +2 -0
- package/dist/src/systems/child/adapters/headlessChildSessionService.cjs.map +1 -1
- package/dist/src/systems/child/adapters/headlessChildSessionService.d.mts.map +1 -1
- package/dist/src/systems/child/adapters/headlessChildSessionService.mjs +2 -0
- package/dist/src/systems/child/adapters/headlessChildSessionService.mjs.map +1 -1
- package/dist/src/systems/child/adapters/remoteChildSessionService.cjs +1 -1
- package/dist/src/systems/child/adapters/remoteChildSessionService.mjs +1 -1
- package/dist/src/systems/main/adapters/headlessHost.cjs +81 -11
- package/dist/src/systems/main/adapters/headlessHost.cjs.map +1 -1
- package/dist/src/systems/main/adapters/headlessHost.d.mts +11 -2
- package/dist/src/systems/main/adapters/headlessHost.d.mts.map +1 -1
- package/dist/src/systems/main/adapters/headlessHost.mjs +82 -12
- package/dist/src/systems/main/adapters/headlessHost.mjs.map +1 -1
- package/dist/src/systems/main/adapters/headlessSessionHost.cjs +270 -45
- package/dist/src/systems/main/adapters/headlessSessionHost.cjs.map +1 -1
- package/dist/src/systems/main/adapters/headlessSessionHost.d.mts +4 -1
- package/dist/src/systems/main/adapters/headlessSessionHost.d.mts.map +1 -1
- package/dist/src/systems/main/adapters/headlessSessionHost.mjs +242 -17
- package/dist/src/systems/main/adapters/headlessSessionHost.mjs.map +1 -1
- package/dist/src/systems/main/types/headlessHost.d.mts +5 -0
- package/dist/src/systems/main/types/headlessHost.d.mts.map +1 -1
- package/dist/src/types/server/directHarnessRuntime.d.mts +9 -1
- package/dist/src/types/server/directHarnessRuntime.d.mts.map +1 -1
- package/dist/web.cjs +1 -1
- package/dist/web.mjs +1 -1
- package/package.json +5 -5
package/dist/apiContracts.d.mts
CHANGED
|
@@ -223,6 +223,8 @@ interface PoApprovalService {
|
|
|
223
223
|
readonly id: string;
|
|
224
224
|
}>;
|
|
225
225
|
registerExecutor(kind: PoApprovalOperation['kind'], run: PoApprovalExecutor): () => void;
|
|
226
|
+
/** True while this session has a pending, approved, running or recently changed approval. */
|
|
227
|
+
active?(): Promise<boolean>;
|
|
226
228
|
}
|
|
227
229
|
declare module '@deepseek-ai/cordis' {
|
|
228
230
|
interface Context {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiContracts.d.mts","names":["_0","_0","_0","_0","IoContext","_0","_$__hubChannel0.PoHubSessionUsage","_0"],"sources":["../src/schemas/serverBundle.ts","../src/schemas/brain.ts","../src/schemas/serverScope.ts","../src/schemas/approvalPrompt.ts","../src/schemas/approval.ts","../src/schemas/backgroundWork.ts","../src/schemas/notification.ts","../src/schemas/platform.ts","../src/schemas/workflow.ts","../src/schemas/hubChannel.ts","../src/schemas/packageApi.ts","../src/schemas/apiContracts.ts","../src/services/apiContracts/index.ts","../src/schemas/builtinApiContracts.ts","../src/schemas/httpApiContracts.ts","../src/schemas/sessionProtocol.ts","../src/schemas/sessionApiContracts.ts","../src/schemas/transportApiContracts.ts","../src/schemas/pluginMarketplace.ts","../src/schemas/pluginCatalog.ts"],"mappings":";;;;;;;;;;;UAKiB;WACN;WACA;;UAGM;WACN;;;;;;WAMA;;WAEA;;WAEA,cAAc;;WAEd,iBAAiB;;WAEjB,cAAc;;WAEd;;WAEA;WACA,iBAAiB;WACjB,iBAAiB;WACjB;;;;;UC5BM;EACf;EACA,OAAO;;UAGQ;EACf;EACA;EACA,QAAQ,YAAY;;UAGL;EACf;EACA;EACA,OAAO;EACP,aAAa;EACb,OAAO;EACP;EACA;;UAGe;EACf;EACA;EACA,OAAO;EACP,OAAO;;;UAIQ;EACf;EACA;EACA;EACA;;UAGe;EACf,OAAO;EACP,OAAO;EACP,KAAK;;EAEL,SAAS;;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AA;;EACpC;IAAW,MAAI,KAAA;;;;IAA8E,QAAM,KAAA,QAAA;;EACnG;IAAW,MAAI,KAAA;;EACf;IAAa,MAAI,KAAA,OAAA,KAAA;;;;;;;;;qBC1QN;;;qBCJA,4BAA0B,KAAA;;;;;;KAS3B,uBAAuB,cAAc;qBAEpC,8BAA4B,KAAA;;;;;;;;;;;;;;KAqB7B,yBAAyB,cAAc;qBAUtC,gCAA8B,KAAA;;;;;;;;;;;;;;;;;;KAoB/B,2BAA2B,cAAc;qBAExC,gCAAgC;;;;qBCzChC,qBAAmB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAG9B,EAAA,KAAA;KACU,gBAAgB,EAAE,aAAa"}
|
|
1
|
+
{"version":3,"file":"apiContracts.d.mts","names":["_0","_0","_0","_0","IoContext","_0","_$__hubChannel0.PoHubSessionUsage","_0"],"sources":["../src/schemas/serverBundle.ts","../src/schemas/brain.ts","../src/schemas/serverScope.ts","../src/schemas/approvalPrompt.ts","../src/schemas/approval.ts","../src/schemas/backgroundWork.ts","../src/schemas/notification.ts","../src/schemas/platform.ts","../src/schemas/workflow.ts","../src/schemas/hubChannel.ts","../src/schemas/packageApi.ts","../src/schemas/apiContracts.ts","../src/services/apiContracts/index.ts","../src/schemas/builtinApiContracts.ts","../src/schemas/httpApiContracts.ts","../src/schemas/sessionProtocol.ts","../src/schemas/sessionApiContracts.ts","../src/schemas/transportApiContracts.ts","../src/schemas/pluginMarketplace.ts","../src/schemas/pluginCatalog.ts"],"mappings":";;;;;;;;;;;UAKiB;WACN;WACA;;UAqBM;WACN;;;;;;WAMA;;WAEA;;WAEA,cAAc;;WAEd,iBAAiB;;WAEjB,cAAc;;WAEd;;WAEA;WACA,iBAAiB;WACjB,iBAAiB;WACjB;;;;;UC9CM;EACf;EACA,OAAO;;UAGQ;EACf;EACA;EACA,QAAQ,YAAY;;UAGL;EACf;EACA;EACA,OAAO;EACP,aAAa;EACb,OAAO;EACP;EACA;;UAGe;EACf;EACA;E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A8B,QAAM,KAAA,OAAA,KAAA,QAAA,KAAA,iBAAA,KAAA,qBAAA,KAAA,iBAAA,KAAA,oBAAA,KAAA,kBAAA,KAAA,iBAAA,KAAA;;EACpC;IAAW,MAAI,KAAA;;;;IAA8E,QAAM,KAAA,QAAA;;EACnG;IAAW,MAAI,KAAA;;EACf;IAAa,MAAI,KAAA,OAAA,KAAA;;;;;;;;;qBC1QN;;;qBCJA,4BAA0B,KAAA;;;;;;KAS3B,uBAAuB,cAAc;qBAEpC,8BAA4B,KAAA;;;;;;;;;;;;;;KAqB7B,yBAAyB,cAAc;qBAUtC,gCAA8B,KAAA;;;;;;;;;;;;;;;;;;KAoB/B,2BAA2B,cAAc;qBAExC,gCAAgC;;;;qBCzChC,qBAAmB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAG9B,EAAA,KAAA;KACU,gBAAgB,EAAE,aAAa"}
|
|
@@ -15,6 +15,10 @@ const require_index = require("./src/services/toolCost/index.cjs");
|
|
|
15
15
|
const CONTEXT_PROJECTION_VERSION = 1;
|
|
16
16
|
/** Journal entry the cockpit reads; mirrored by CONTEXT_ENTRY_TYPE in po-web. */
|
|
17
17
|
const PO_CONTEXT_ENTRY_TYPE = "po-context";
|
|
18
|
+
/** Only the host journals selections: a package writing one could forge what reopen restores, such as approvals. */
|
|
19
|
+
function assertPackageEntryType(customType) {
|
|
20
|
+
if (customType === "po-context") throw new Error(`Only the Po host may write '${PO_CONTEXT_ENTRY_TYPE}' entries.`);
|
|
21
|
+
}
|
|
18
22
|
/** Session selection and transition journal identities, not transport channels. */
|
|
19
23
|
const PO_CONFIG_ENTRY_TYPE = "po:config:v1";
|
|
20
24
|
const PO_CONFIG_TRANSITION_ENTRY_TYPE = "po:transition:v1";
|
|
@@ -47,13 +51,20 @@ function readProjectedSelection(data) {
|
|
|
47
51
|
const profile = "profile" in selection ? selection.profile : void 0;
|
|
48
52
|
if (profile !== void 0 && typeof profile !== "string") return void 0;
|
|
49
53
|
const requestedProfile = "requestedProfile" in selection ? selection.requestedProfile : void 0;
|
|
54
|
+
const state = "state" in selection ? readState(selection.state) : void 0;
|
|
50
55
|
return {
|
|
51
56
|
preset: selection.preset,
|
|
52
57
|
domains: [...selection.domains],
|
|
53
58
|
profile,
|
|
54
|
-
...typeof requestedProfile === "string" || requestedProfile === null ? { requestedProfile } : {}
|
|
59
|
+
...typeof requestedProfile === "string" || requestedProfile === null ? { requestedProfile } : {},
|
|
60
|
+
...state === void 0 ? {} : { state }
|
|
55
61
|
};
|
|
56
62
|
}
|
|
63
|
+
/** A saved state map with only string-list values; anything else is dropped rather than restored. */
|
|
64
|
+
function readState(value) {
|
|
65
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
66
|
+
return Object.fromEntries(Object.entries(value).flatMap(([key, values]) => Array.isArray(values) && values.every((item) => typeof item === "string") ? [[key, [...values]]] : []));
|
|
67
|
+
}
|
|
57
68
|
/** The notice for a session whose saved selection predates the preset and mode rename. */
|
|
58
69
|
const RETIRED_SESSION_NOTICE = "This session was saved by an older Po. Its preset and modes were not restored. Choose them again with /preset and /mode.";
|
|
59
70
|
function isRecordValue(value) {
|
|
@@ -145,7 +156,8 @@ function projectContext(input) {
|
|
|
145
156
|
preset: input.preset,
|
|
146
157
|
domains: [...input.domains],
|
|
147
158
|
...input.profile === void 0 ? {} : { profile: input.profile },
|
|
148
|
-
...input.requestedProfile === void 0 ? {} : { requestedProfile: input.requestedProfile }
|
|
159
|
+
...input.requestedProfile === void 0 ? {} : { requestedProfile: input.requestedProfile },
|
|
160
|
+
...input.state === void 0 ? {} : { state: structuredClone(input.state) }
|
|
149
161
|
},
|
|
150
162
|
groups,
|
|
151
163
|
totalTokens: groups.reduce((total, group) => total + group.tokens, 0),
|
|
@@ -161,6 +173,7 @@ exports.PO_CONFIG_ENTRY_TYPE = PO_CONFIG_ENTRY_TYPE;
|
|
|
161
173
|
exports.PO_CONFIG_TRANSITION_ENTRY_TYPE = PO_CONFIG_TRANSITION_ENTRY_TYPE;
|
|
162
174
|
exports.PO_CONTEXT_ENTRY_TYPE = PO_CONTEXT_ENTRY_TYPE;
|
|
163
175
|
exports.RETIRED_SESSION_NOTICE = RETIRED_SESSION_NOTICE;
|
|
176
|
+
exports.assertPackageEntryType = assertPackageEntryType;
|
|
164
177
|
exports.findRetiredSessionEntries = findRetiredSessionEntries;
|
|
165
178
|
exports.projectContext = projectContext;
|
|
166
179
|
exports.readProjectedSelection = readProjectedSelection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextProjection.cjs","names":["tokensForTool"],"sources":["../src/services/contextProjection/index.ts"],"sourcesContent":["/** What admitted a package into the composition. */\nexport interface PackageAttribution {\n /** `preset` for a layer package, `domain` for a plugin a domain carries. */\n kind: 'preset' | 'domain';\n /** The preset name, or the domain name. */\n name: string;\n /** The layer the package was listed under; absent for a domain plugin. */\n layer?: string;\n}\n\nimport type { ContextPromptStage } from '../../types/contextApi';\nimport { type CountTokens, type ToolEntry, type ToolSource, tokensForTool } from '../toolInventory';\n\n/**\n * What the session is carrying, and what carrying it costs.\n *\n * Grouped by the mode that admitted each package rather than by where the tool\n * came from, because a mode is the thing a reader can switch off. The mechanism\n * (extension, MCP server, plugin) orders rows inside a group instead, so the\n * expensive thing is still easy to find.\n *\n * Schemas never travel. Only names, kinds, owners and integer counts do, which\n * keeps the payload small enough to republish whenever the composition changes.\n */\nexport const CONTEXT_PROJECTION_VERSION = 1;\n\n/** Journal entry the cockpit reads; mirrored by CONTEXT_ENTRY_TYPE in po-web. */\nexport const PO_CONTEXT_ENTRY_TYPE = 'po-context';\n\n/** Session selection and transition journal identities, not transport channels. */\nexport const PO_CONFIG_ENTRY_TYPE = 'po:config:v1';\nexport const PO_CONFIG_TRANSITION_ENTRY_TYPE = 'po:transition:v1';\n\n/** The tokenizer these counts came from, so a reader can judge them. */\nexport const CONTEXT_PROJECTION_ESTIMATOR = 'gpt-tokenizer';\n\nexport type ContextGroupKind = 'preset' | 'mode' | 'domain' | 'shared' | 'core';\nexport type ContextItemSource = 'extension' | 'mcp' | 'plugin' | 'core';\n\n/** Everything the runtime could not attribute lands here rather than vanishing. */\nconst CORE_GROUP = 'core';\n/** Pi's own tools have no package; the runtime itself is the owner. */\nconst CORE_OWNER = 'pi';\nconst MCP_KEY_PREFIX = 'mcp:';\n\nconst KIND_ORDER: Record<ContextGroupKind, number> = { preset: 0, mode: 1, domain: 2, shared: 3, core: 4 };\nconst SOURCE_ORDER: Record<ContextItemSource, number> = { extension: 0, mcp: 1, plugin: 2, core: 3 };\n\nexport interface ContextItemProjection {\n readonly name: string;\n readonly itemKind: 'tool' | 'skill';\n readonly source: ContextItemSource;\n /** The package, server, or plugin that registered it. */\n readonly owner: string;\n readonly tokens: number;\n readonly active: boolean;\n}\n\nexport interface ContextGroupProjection {\n readonly id: string;\n readonly label: string;\n readonly kind: ContextGroupKind;\n readonly items: readonly ContextItemProjection[];\n /** What the group costs now: active items only. */\n readonly tokens: number;\n /** What its gated items would add if switched on. */\n readonly inactiveTokens: number;\n}\n\n/**\n * What the assembled system prompt costs, and how complete the figure is.\n *\n * Kept out of `groups` on purpose. Every tool's prose and every skill's listing\n * already count inside the group subtotals, and those are slices of this same\n * text, so folding it into `totalTokens` would bill them twice.\n */\nexport interface ContextSystemPromptProjection {\n readonly tokens: number;\n readonly stage: ContextPromptStage;\n}\n\nexport interface ContextProjection {\n readonly version: typeof CONTEXT_PROJECTION_VERSION;\n readonly revision: number;\n /** Selection snapshot used to build this projection, replayable after reconnect. */\n readonly selection: {\n readonly preset: string;\n readonly domains: readonly string[];\n readonly profile?: string;\n /** Requested profile when none is active; null records an explicit None pick. Absent on legacy records. */\n readonly requestedProfile?: string | null;\n };\n readonly groups: readonly ContextGroupProjection[];\n readonly totalTokens: number;\n readonly inactiveTokens: number;\n readonly systemPrompt?: ContextSystemPromptProjection;\n readonly estimator: typeof CONTEXT_PROJECTION_ESTIMATOR;\n}\n\nexport interface ContextConditionalAttribution {\n readonly kind: 'mode' | 'domain' | 'shared';\n readonly name: string;\n readonly label?: string;\n}\n\nexport interface ContextToolInventory extends ToolEntry {\n /** A contribution-level gate is more specific than its package's preset owner. */\n readonly contextAttribution?: ContextConditionalAttribution;\n}\n\nexport interface ContextToolSource extends Omit<ToolSource, 'tools'> {\n readonly tools: readonly ContextToolInventory[];\n}\n\n/** Skill fields needed to project cost and serve detail. Virtual resources may not have a filesystem path. */\nexport interface ContextSkillInventory {\n readonly name: string;\n readonly description: string;\n readonly group: 'extensions' | 'help' | 'plugins' | 'default';\n readonly owner: string;\n readonly modelInvocable: boolean;\n readonly promptTokens?: number;\n readonly filePath?: string;\n /** The skill's instructions, when the host holds them; read only when a reader opens the row. */\n readonly body?: string;\n readonly contextAttribution?: ContextConditionalAttribution;\n}\n\nexport interface ContextProjectionInput {\n readonly revision: number;\n readonly preset: string;\n readonly profile?: string;\n readonly requestedProfile?: string | null;\n /** Additional groups supplied by the composition owner, in display order. */\n readonly groups: readonly { readonly id: string; readonly label: string; readonly kind: ContextGroupKind }[];\n /** Domains the composition resolved under, whether or not they carried a plugin. */\n readonly domains: readonly string[];\n readonly sources: readonly ContextToolSource[];\n readonly skills: readonly ContextSkillInventory[];\n /**\n * Owner identifier to the mode that admitted it.\n *\n * Keys are package names for extensions and layer packages, and plugin or\n * server names for anything a domain carries. The caller owns this join\n * because only it knows how a given deployment resolved its plugins.\n */\n readonly attribution: Readonly<Record<string, PackageAttribution>>;\n readonly countTokens: CountTokens;\n /** Absent until the session has a prompt to report. */\n readonly systemPrompt?: ContextSystemPromptProjection;\n}\n\n/** Reads only replayable selection fields, accepting legacy projections without a request marker. */\nexport function readProjectedSelection(data: unknown): ContextProjection['selection'] | undefined {\n if (typeof data !== 'object' || data === null || Array.isArray(data) || !('selection' in data)) return undefined;\n const selection = data.selection;\n if (typeof selection !== 'object' || selection === null || Array.isArray(selection)) return undefined;\n if (!('preset' in selection) || typeof selection.preset !== 'string') return undefined;\n if (\n !('domains' in selection) ||\n !Array.isArray(selection.domains) ||\n !selection.domains.every((domain) => typeof domain === 'string')\n )\n return undefined;\n const profile = 'profile' in selection ? selection.profile : undefined;\n if (profile !== undefined && typeof profile !== 'string') return undefined;\n const requestedProfile = 'requestedProfile' in selection ? selection.requestedProfile : undefined;\n return {\n preset: selection.preset,\n domains: [...selection.domains],\n profile,\n ...(typeof requestedProfile === 'string' || requestedProfile === null ? { requestedProfile } : {}),\n };\n}\n\n/** The notice for a session whose saved selection predates the preset and mode rename. */\nexport const RETIRED_SESSION_NOTICE =\n 'This session was saved by an older Po. Its preset and modes were not restored. Choose them again with /preset and /mode.';\n\nfunction isRecordValue(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Whether the newest saved selection was written before the rename, so it could not be restored.\n * The host journals a selection for every session, so this one entry is the only trigger; old saved\n * modes are lost with it. Pure over journal entries: the caller decides how to tell the person.\n */\nexport function findRetiredSessionEntries(entries: readonly unknown[]): boolean {\n for (let index = entries.length - 1; index >= 0; index -= 1) {\n const entry = entries[index];\n if (!isRecordValue(entry) || entry.type !== 'custom' || entry.customType !== PO_CONTEXT_ENTRY_TYPE) continue;\n if (readProjectedSelection(entry.data) !== undefined) return false;\n const selection = isRecordValue(entry.data) ? entry.data.selection : undefined;\n return isRecordValue(selection) && Object.hasOwn(selection, 'majorMode'); // retired-name\n }\n return false;\n}\n\ninterface Bucket {\n kind: ContextGroupKind;\n label: string;\n items: ContextItemProjection[];\n}\n\nfunction skillSource(group: ContextSkillInventory['group']): ContextItemSource {\n if (group === 'plugins') return 'plugin';\n if (group === 'extensions') return 'extension';\n return 'core';\n}\n\nfunction byRow(left: ContextItemProjection, right: ContextItemProjection): number {\n return SOURCE_ORDER[left.source] - SOURCE_ORDER[right.source] || left.name.localeCompare(right.name);\n}\n\nexport function projectContext(input: ContextProjectionInput): ContextProjection {\n const buckets = new Map<string, Bucket>();\n\n // Declared before anything is placed, so a mode with nothing attributed to it\n // still appears. An empty group is a fact worth showing: it says the mode is\n // on and cheap, not that the runtime forgot about it.\n const declare = (id: string, label: string, kind: ContextGroupKind): void => {\n if (!buckets.has(id)) buckets.set(id, { kind, label, items: [] });\n };\n if (input.preset) declare(input.preset, input.preset, 'preset');\n for (const group of input.groups) declare(group.id, group.label, group.kind);\n // A domain that contributed no plugin is still part of what the session is\n // running under, and a reader comparing the panel against the footer would\n // otherwise read its absence as the panel being out of date.\n for (const domain of input.domains) declare(domain, domain, 'domain');\n\n const place = (owner: string, item: ContextItemProjection, conditional?: ContextConditionalAttribution): void => {\n const attributed = conditional ?? input.attribution[owner];\n const id = attributed?.name ?? CORE_GROUP;\n const kind = attributed?.kind ?? 'core';\n declare(id, attributed && 'label' in attributed ? (attributed.label ?? id) : id, kind);\n buckets.get(id)?.items.push(item);\n };\n\n for (const source of input.sources) {\n // An extension is owned by its package, an MCP tool by the server that\n // advertised it. `label` is display text like `scaffold · mcp`, so the\n // identifier comes from the key instead: an owner is joined on, not read.\n const owner =\n source.kind === 'extension'\n ? (source.packageName ?? source.key)\n : source.kind === 'mcp'\n ? source.key.slice(MCP_KEY_PREFIX.length)\n : CORE_OWNER;\n for (const tool of source.tools) {\n const cost = tokensForTool(tool, input.countTokens);\n const item: ContextItemProjection = {\n name: tool.name,\n itemKind: 'tool',\n source: source.kind === 'core' ? 'core' : source.kind,\n owner,\n tokens: cost.totalTokens,\n active: tool.active,\n };\n if (source.kind === 'core') {\n declare(CORE_GROUP, CORE_GROUP, 'core');\n buckets.get(CORE_GROUP)?.items.push(item);\n } else {\n place(owner, item, tool.contextAttribution);\n }\n }\n }\n\n for (const skill of input.skills) {\n place(\n skill.owner,\n {\n name: skill.name,\n itemKind: 'skill',\n source: skillSource(skill.group),\n owner: skill.owner,\n tokens: skill.promptTokens ?? 0,\n // A skill is always offered to the model; there is no inactive state for\n // it the way there is for a tool Pi has filtered out.\n active: true,\n },\n skill.contextAttribution,\n );\n }\n\n const groups: ContextGroupProjection[] = [...buckets.entries()]\n .map(([id, bucket]) => {\n const items = [...bucket.items].sort(byRow);\n // Only what is actually sent counts. Pi builds the prompt from its\n // active tools, so a gated one costs nothing until it is switched on,\n // and folding it into the total would overstate the bill by a third.\n return {\n id,\n label: bucket.label,\n kind: bucket.kind,\n items,\n tokens: items.reduce((total, item) => total + (item.active ? item.tokens : 0), 0),\n inactiveTokens: items.reduce((total, item) => total + (item.active ? 0 : item.tokens), 0),\n };\n })\n .sort((left, right) => KIND_ORDER[left.kind] - KIND_ORDER[right.kind] || left.label.localeCompare(right.label));\n\n return {\n version: CONTEXT_PROJECTION_VERSION,\n revision: input.revision,\n selection: {\n preset: input.preset,\n domains: [...input.domains],\n ...(input.profile === undefined ? {} : { profile: input.profile }),\n ...(input.requestedProfile === undefined ? {} : { requestedProfile: input.requestedProfile }),\n },\n groups,\n totalTokens: groups.reduce((total, group) => total + group.tokens, 0),\n inactiveTokens: groups.reduce((total, group) => total + group.inactiveTokens, 0),\n ...(input.systemPrompt === undefined ? {} : { systemPrompt: input.systemPrompt }),\n estimator: CONTEXT_PROJECTION_ESTIMATOR,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAa,6BAA6B;;AAG1C,MAAa,wBAAwB;;AAGrC,MAAa,uBAAuB;AACpC,MAAa,kCAAkC;;AAG/C,MAAa,+BAA+B;;AAM5C,MAAM,aAAa;;AAEnB,MAAM,aAAa;AAGnB,MAAM,aAA+C;CAAE,QAAQ;CAAG,MAAM;CAAG,QAAQ;CAAG,QAAQ;CAAG,MAAM;AAAE;AACzG,MAAM,eAAkD;CAAE,WAAW;CAAG,KAAK;CAAG,QAAQ;CAAG,MAAM;AAAE;;AA2GnG,SAAgB,uBAAuB,MAA2D;CAChG,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,MAAM,QAAQ,IAAI,KAAK,EAAE,eAAe,OAAO,OAAO,KAAA;CACvG,MAAM,YAAY,KAAK;CACvB,IAAI,OAAO,cAAc,YAAY,cAAc,QAAQ,MAAM,QAAQ,SAAS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/E,WAAW;CACb;AACF"}
|
|
1
|
+
{"version":3,"file":"contextProjection.cjs","names":["tokensForTool"],"sources":["../src/services/contextProjection/index.ts"],"sourcesContent":["/** What admitted a package into the composition. */\nexport interface PackageAttribution {\n /** `preset` for a layer package, `domain` for a plugin a domain carries. */\n kind: 'preset' | 'domain';\n /** The preset name, or the domain name. */\n name: string;\n /** The layer the package was listed under; absent for a domain plugin. */\n layer?: string;\n}\n\nimport type { ContextPromptStage } from '../../types/contextApi';\nimport { type CountTokens, type ToolEntry, type ToolSource, tokensForTool } from '../toolInventory';\n\n/**\n * What the session is carrying, and what carrying it costs.\n *\n * Grouped by the mode that admitted each package rather than by where the tool\n * came from, because a mode is the thing a reader can switch off. The mechanism\n * (extension, MCP server, plugin) orders rows inside a group instead, so the\n * expensive thing is still easy to find.\n *\n * Schemas never travel. Only names, kinds, owners and integer counts do, which\n * keeps the payload small enough to republish whenever the composition changes.\n */\nexport const CONTEXT_PROJECTION_VERSION = 1;\n\n/** Journal entry the cockpit reads; mirrored by CONTEXT_ENTRY_TYPE in po-web. */\nexport const PO_CONTEXT_ENTRY_TYPE = 'po-context';\n\n/** Only the host journals selections: a package writing one could forge what reopen restores, such as approvals. */\nexport function assertPackageEntryType(customType: string): void {\n if (customType === PO_CONTEXT_ENTRY_TYPE)\n throw new Error(`Only the Po host may write '${PO_CONTEXT_ENTRY_TYPE}' entries.`);\n}\n\n/** Session selection and transition journal identities, not transport channels. */\nexport const PO_CONFIG_ENTRY_TYPE = 'po:config:v1';\nexport const PO_CONFIG_TRANSITION_ENTRY_TYPE = 'po:transition:v1';\n\n/** The tokenizer these counts came from, so a reader can judge them. */\nexport const CONTEXT_PROJECTION_ESTIMATOR = 'gpt-tokenizer';\n\nexport type ContextGroupKind = 'preset' | 'mode' | 'domain' | 'shared' | 'core';\nexport type ContextItemSource = 'extension' | 'mcp' | 'plugin' | 'core';\n\n/** Everything the runtime could not attribute lands here rather than vanishing. */\nconst CORE_GROUP = 'core';\n/** Pi's own tools have no package; the runtime itself is the owner. */\nconst CORE_OWNER = 'pi';\nconst MCP_KEY_PREFIX = 'mcp:';\n\nconst KIND_ORDER: Record<ContextGroupKind, number> = { preset: 0, mode: 1, domain: 2, shared: 3, core: 4 };\nconst SOURCE_ORDER: Record<ContextItemSource, number> = { extension: 0, mcp: 1, plugin: 2, core: 3 };\n\nexport interface ContextItemProjection {\n readonly name: string;\n readonly itemKind: 'tool' | 'skill';\n readonly source: ContextItemSource;\n /** The package, server, or plugin that registered it. */\n readonly owner: string;\n readonly tokens: number;\n readonly active: boolean;\n}\n\nexport interface ContextGroupProjection {\n readonly id: string;\n readonly label: string;\n readonly kind: ContextGroupKind;\n readonly items: readonly ContextItemProjection[];\n /** What the group costs now: active items only. */\n readonly tokens: number;\n /** What its gated items would add if switched on. */\n readonly inactiveTokens: number;\n}\n\n/**\n * What the assembled system prompt costs, and how complete the figure is.\n *\n * Kept out of `groups` on purpose. Every tool's prose and every skill's listing\n * already count inside the group subtotals, and those are slices of this same\n * text, so folding it into `totalTokens` would bill them twice.\n */\nexport interface ContextSystemPromptProjection {\n readonly tokens: number;\n readonly stage: ContextPromptStage;\n}\n\nexport interface ContextProjection {\n readonly version: typeof CONTEXT_PROJECTION_VERSION;\n readonly revision: number;\n /** Selection snapshot used to build this projection, replayable after reconnect. */\n readonly selection: {\n readonly preset: string;\n readonly domains: readonly string[];\n readonly profile?: string;\n /** Requested profile when none is active; null records an explicit None pick. Absent on legacy records. */\n readonly requestedProfile?: string | null;\n /** Feature-owned activation sets, such as modes and approved plugins. Absent on legacy records. */\n readonly state?: Readonly<Record<string, readonly string[]>>;\n };\n readonly groups: readonly ContextGroupProjection[];\n readonly totalTokens: number;\n readonly inactiveTokens: number;\n readonly systemPrompt?: ContextSystemPromptProjection;\n readonly estimator: typeof CONTEXT_PROJECTION_ESTIMATOR;\n}\n\nexport interface ContextConditionalAttribution {\n readonly kind: 'mode' | 'domain' | 'shared';\n readonly name: string;\n readonly label?: string;\n}\n\nexport interface ContextToolInventory extends ToolEntry {\n /** A contribution-level gate is more specific than its package's preset owner. */\n readonly contextAttribution?: ContextConditionalAttribution;\n}\n\nexport interface ContextToolSource extends Omit<ToolSource, 'tools'> {\n readonly tools: readonly ContextToolInventory[];\n}\n\n/** Skill fields needed to project cost and serve detail. Virtual resources may not have a filesystem path. */\nexport interface ContextSkillInventory {\n readonly name: string;\n readonly description: string;\n readonly group: 'extensions' | 'help' | 'plugins' | 'default';\n readonly owner: string;\n readonly modelInvocable: boolean;\n readonly promptTokens?: number;\n readonly filePath?: string;\n /** The skill's instructions, when the host holds them; read only when a reader opens the row. */\n readonly body?: string;\n readonly contextAttribution?: ContextConditionalAttribution;\n}\n\nexport interface ContextProjectionInput {\n readonly revision: number;\n readonly preset: string;\n readonly profile?: string;\n readonly requestedProfile?: string | null;\n readonly state?: Readonly<Record<string, readonly string[]>>;\n /** Additional groups supplied by the composition owner, in display order. */\n readonly groups: readonly { readonly id: string; readonly label: string; readonly kind: ContextGroupKind }[];\n /** Domains the composition resolved under, whether or not they carried a plugin. */\n readonly domains: readonly string[];\n readonly sources: readonly ContextToolSource[];\n readonly skills: readonly ContextSkillInventory[];\n /**\n * Owner identifier to the mode that admitted it.\n *\n * Keys are package names for extensions and layer packages, and plugin or\n * server names for anything a domain carries. The caller owns this join\n * because only it knows how a given deployment resolved its plugins.\n */\n readonly attribution: Readonly<Record<string, PackageAttribution>>;\n readonly countTokens: CountTokens;\n /** Absent until the session has a prompt to report. */\n readonly systemPrompt?: ContextSystemPromptProjection;\n}\n\n/** Reads only replayable selection fields, accepting legacy projections without a request marker. */\nexport function readProjectedSelection(data: unknown): ContextProjection['selection'] | undefined {\n if (typeof data !== 'object' || data === null || Array.isArray(data) || !('selection' in data)) return undefined;\n const selection = data.selection;\n if (typeof selection !== 'object' || selection === null || Array.isArray(selection)) return undefined;\n if (!('preset' in selection) || typeof selection.preset !== 'string') return undefined;\n if (\n !('domains' in selection) ||\n !Array.isArray(selection.domains) ||\n !selection.domains.every((domain) => typeof domain === 'string')\n )\n return undefined;\n const profile = 'profile' in selection ? selection.profile : undefined;\n if (profile !== undefined && typeof profile !== 'string') return undefined;\n const requestedProfile = 'requestedProfile' in selection ? selection.requestedProfile : undefined;\n const state = 'state' in selection ? readState(selection.state) : undefined;\n return {\n preset: selection.preset,\n domains: [...selection.domains],\n profile,\n ...(typeof requestedProfile === 'string' || requestedProfile === null ? { requestedProfile } : {}),\n ...(state === undefined ? {} : { state }),\n };\n}\n\n/** A saved state map with only string-list values; anything else is dropped rather than restored. */\nfunction readState(value: unknown): Record<string, string[]> | undefined {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return undefined;\n return Object.fromEntries(\n Object.entries(value).flatMap(([key, values]) =>\n Array.isArray(values) && values.every((item) => typeof item === 'string') ? [[key, [...values]]] : [],\n ),\n );\n}\n\n/** The notice for a session whose saved selection predates the preset and mode rename. */\nexport const RETIRED_SESSION_NOTICE =\n 'This session was saved by an older Po. Its preset and modes were not restored. Choose them again with /preset and /mode.';\n\nfunction isRecordValue(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Whether the newest saved selection was written before the rename, so it could not be restored.\n * The host journals a selection for every session, so this one entry is the only trigger; old saved\n * modes are lost with it. Pure over journal entries: the caller decides how to tell the person.\n */\nexport function findRetiredSessionEntries(entries: readonly unknown[]): boolean {\n for (let index = entries.length - 1; index >= 0; index -= 1) {\n const entry = entries[index];\n if (!isRecordValue(entry) || entry.type !== 'custom' || entry.customType !== PO_CONTEXT_ENTRY_TYPE) continue;\n if (readProjectedSelection(entry.data) !== undefined) return false;\n const selection = isRecordValue(entry.data) ? entry.data.selection : undefined;\n return isRecordValue(selection) && Object.hasOwn(selection, 'majorMode'); // retired-name\n }\n return false;\n}\n\ninterface Bucket {\n kind: ContextGroupKind;\n label: string;\n items: ContextItemProjection[];\n}\n\nfunction skillSource(group: ContextSkillInventory['group']): ContextItemSource {\n if (group === 'plugins') return 'plugin';\n if (group === 'extensions') return 'extension';\n return 'core';\n}\n\nfunction byRow(left: ContextItemProjection, right: ContextItemProjection): number {\n return SOURCE_ORDER[left.source] - SOURCE_ORDER[right.source] || left.name.localeCompare(right.name);\n}\n\nexport function projectContext(input: ContextProjectionInput): ContextProjection {\n const buckets = new Map<string, Bucket>();\n\n // Declared before anything is placed, so a mode with nothing attributed to it\n // still appears. An empty group is a fact worth showing: it says the mode is\n // on and cheap, not that the runtime forgot about it.\n const declare = (id: string, label: string, kind: ContextGroupKind): void => {\n if (!buckets.has(id)) buckets.set(id, { kind, label, items: [] });\n };\n if (input.preset) declare(input.preset, input.preset, 'preset');\n for (const group of input.groups) declare(group.id, group.label, group.kind);\n // A domain that contributed no plugin is still part of what the session is\n // running under, and a reader comparing the panel against the footer would\n // otherwise read its absence as the panel being out of date.\n for (const domain of input.domains) declare(domain, domain, 'domain');\n\n const place = (owner: string, item: ContextItemProjection, conditional?: ContextConditionalAttribution): void => {\n const attributed = conditional ?? input.attribution[owner];\n const id = attributed?.name ?? CORE_GROUP;\n const kind = attributed?.kind ?? 'core';\n declare(id, attributed && 'label' in attributed ? (attributed.label ?? id) : id, kind);\n buckets.get(id)?.items.push(item);\n };\n\n for (const source of input.sources) {\n // An extension is owned by its package, an MCP tool by the server that\n // advertised it. `label` is display text like `scaffold · mcp`, so the\n // identifier comes from the key instead: an owner is joined on, not read.\n const owner =\n source.kind === 'extension'\n ? (source.packageName ?? source.key)\n : source.kind === 'mcp'\n ? source.key.slice(MCP_KEY_PREFIX.length)\n : CORE_OWNER;\n for (const tool of source.tools) {\n const cost = tokensForTool(tool, input.countTokens);\n const item: ContextItemProjection = {\n name: tool.name,\n itemKind: 'tool',\n source: source.kind === 'core' ? 'core' : source.kind,\n owner,\n tokens: cost.totalTokens,\n active: tool.active,\n };\n if (source.kind === 'core') {\n declare(CORE_GROUP, CORE_GROUP, 'core');\n buckets.get(CORE_GROUP)?.items.push(item);\n } else {\n place(owner, item, tool.contextAttribution);\n }\n }\n }\n\n for (const skill of input.skills) {\n place(\n skill.owner,\n {\n name: skill.name,\n itemKind: 'skill',\n source: skillSource(skill.group),\n owner: skill.owner,\n tokens: skill.promptTokens ?? 0,\n // A skill is always offered to the model; there is no inactive state for\n // it the way there is for a tool Pi has filtered out.\n active: true,\n },\n skill.contextAttribution,\n );\n }\n\n const groups: ContextGroupProjection[] = [...buckets.entries()]\n .map(([id, bucket]) => {\n const items = [...bucket.items].sort(byRow);\n // Only what is actually sent counts. Pi builds the prompt from its\n // active tools, so a gated one costs nothing until it is switched on,\n // and folding it into the total would overstate the bill by a third.\n return {\n id,\n label: bucket.label,\n kind: bucket.kind,\n items,\n tokens: items.reduce((total, item) => total + (item.active ? item.tokens : 0), 0),\n inactiveTokens: items.reduce((total, item) => total + (item.active ? 0 : item.tokens), 0),\n };\n })\n .sort((left, right) => KIND_ORDER[left.kind] - KIND_ORDER[right.kind] || left.label.localeCompare(right.label));\n\n return {\n version: CONTEXT_PROJECTION_VERSION,\n revision: input.revision,\n selection: {\n preset: input.preset,\n domains: [...input.domains],\n ...(input.profile === undefined ? {} : { profile: input.profile }),\n ...(input.requestedProfile === undefined ? {} : { requestedProfile: input.requestedProfile }),\n ...(input.state === undefined ? {} : { state: structuredClone(input.state) }),\n },\n groups,\n totalTokens: groups.reduce((total, group) => total + group.tokens, 0),\n inactiveTokens: groups.reduce((total, group) => total + group.inactiveTokens, 0),\n ...(input.systemPrompt === undefined ? {} : { systemPrompt: input.systemPrompt }),\n estimator: CONTEXT_PROJECTION_ESTIMATOR,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAa,6BAA6B;;AAG1C,MAAa,wBAAwB;;AAGrC,SAAgB,uBAAuB,YAA0B;CAC/D,IAAI,eAAA,cACF,MAAM,IAAI,MAAM,+BAA+B,sBAAsB,WAAW;AACpF;;AAGA,MAAa,uBAAuB;AACpC,MAAa,kCAAkC;;AAG/C,MAAa,+BAA+B;;AAM5C,MAAM,aAAa;;AAEnB,MA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CAAC,KAAK,KAAK;EAI1C,OAAO;GACL;GACA,OAAO,OAAO;GACd,MAAM,OAAO;GACb;GACA,QAAQ,MAAM,QAAQ,OAAO,SAAS,SAAS,KAAK,SAAS,KAAK,SAAS,IAAI,CAAC;GAChF,gBAAgB,MAAM,QAAQ,OAAO,SAAS,SAAS,KAAK,SAAS,IAAI,KAAK,SAAS,CAAC;EAC1F;CACF,CAAC,CAAC,CACD,MAAM,MAAM,UAAU,WAAW,KAAK,QAAQ,WAAW,MAAM,SAAS,KAAK,MAAM,cAAc,MAAM,KAAK,CAAC;CAEhH,OAAO;EACL,SAAA;EACA,UAAU,MAAM;EAChB,WAAW;GACT,QAAQ,MAAM;GACd,SAAS,CAAC,GAAG,MAAM,OAAO;GAC1B,GAAI,MAAM,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,MAAM,QAAQ;GAChE,GAAI,MAAM,qBAAqB,KAAA,IAAY,CAAC,IAAI,EAAE,kBAAkB,MAAM,iBAAiB;GAC3F,GAAI,MAAM,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO,gBAAgB,MAAM,KAAK,EAAE;EAC7E;EACA;EACA,aAAa,OAAO,QAAQ,OAAO,UAAU,QAAQ,MAAM,QAAQ,CAAC;EACpE,gBAAgB,OAAO,QAAQ,OAAO,UAAU,QAAQ,MAAM,gBAAgB,CAAC;EAC/E,GAAI,MAAM,iBAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,cAAc,MAAM,aAAa;EAC/E,WAAW;CACb;AACF"}
|
|
@@ -25,6 +25,8 @@ export interface PackageAttribution {
|
|
|
25
25
|
export declare const CONTEXT_PROJECTION_VERSION = 1;
|
|
26
26
|
/** Journal entry the cockpit reads; mirrored by CONTEXT_ENTRY_TYPE in po-web. */
|
|
27
27
|
export declare const PO_CONTEXT_ENTRY_TYPE = "po-context";
|
|
28
|
+
/** Only the host journals selections: a package writing one could forge what reopen restores, such as approvals. */
|
|
29
|
+
export declare function assertPackageEntryType(customType: string): void;
|
|
28
30
|
/** Session selection and transition journal identities, not transport channels. */
|
|
29
31
|
export declare const PO_CONFIG_ENTRY_TYPE = "po:config:v1";
|
|
30
32
|
export declare const PO_CONFIG_TRANSITION_ENTRY_TYPE = "po:transition:v1";
|
|
@@ -72,6 +74,8 @@ export interface ContextProjection {
|
|
|
72
74
|
readonly profile?: string;
|
|
73
75
|
/** Requested profile when none is active; null records an explicit None pick. Absent on legacy records. */
|
|
74
76
|
readonly requestedProfile?: string | null;
|
|
77
|
+
/** Feature-owned activation sets, such as modes and approved plugins. Absent on legacy records. */
|
|
78
|
+
readonly state?: Readonly<Record<string, readonly string[]>>;
|
|
75
79
|
};
|
|
76
80
|
readonly groups: readonly ContextGroupProjection[];
|
|
77
81
|
readonly totalTokens: number;
|
|
@@ -109,6 +113,7 @@ export interface ContextProjectionInput {
|
|
|
109
113
|
readonly preset: string;
|
|
110
114
|
readonly profile?: string;
|
|
111
115
|
readonly requestedProfile?: string | null;
|
|
116
|
+
readonly state?: Readonly<Record<string, readonly string[]>>;
|
|
112
117
|
/** Additional groups supplied by the composition owner, in display order. */
|
|
113
118
|
readonly groups: readonly {
|
|
114
119
|
readonly id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextProjection.d.mts","names":[],"sources":["../src/services/contextProjection/index.ts"],"mappings":";;;;;iBACiB;;EAEf;;EAEA;;EAEA;;;;;;;;;;;;;qBAiBW;;qBAGA;;
|
|
1
|
+
{"version":3,"file":"contextProjection.d.mts","names":[],"sources":["../src/services/contextProjection/index.ts"],"mappings":";;;;;iBACiB;;EAEf;;EAEA;;EAEA;;;;;;;;;;;;;qBAiBW;;qBAGA;;wBAGG,uBAAuB;;qBAM1B;qBACA;;qBAGA;YAED;YACA;iBAWK;WACN;WACA;WACA,QAAQ;;WAER;WACA;WACA;;iBAGM;WACN;WACA;WACA,MAAM;WACN,gBAAgB;;WAEhB;;WAEA;;;;;;;;;iBAUM;WACN;WACA,OAAO;;iBAGD;WACN,gBAAgB;WAChB;;WAEA;aACE;aACA;aACA;;aAEA;;aAEA,QAAQ,SAAS;;WAEnB,iBAAiB;WACjB;WACA;WACA,eAAe;WACf,kBAAkB;;iBAGZ;WACN;WACA;WACA;;iBAGM,6BAA6B;;WAEnC,qBAAqB;;iBAGf,0BAA0B,KAAK;WACrC,gBAAgB;;;iBAIV;WACN;WACA;WACA;WACA;WACA;WACA;WACA;;WAEA;WACA,qBAAqB;;iBAGf;WACN;WACA;WACA;WACA;WACA,QAAQ,SAAS;;WAEjB;aAA4B;aAAqB;aAAwB,MAAM;;;WAE/E;WACA,kBAAkB;WAClB,iBAAiB;;;;;;;;WAQjB,aAAa,SAAS,eAAe;WACrC,aAAa;;WAEb,eAAe;;;wBAIV,uBAAuB,gBAAgB;;qBAmC1C;;;;;;wBAYG,0BAA0B;wBA2B1B,eAAe,OAAO,yBAAyB"}
|
|
@@ -14,6 +14,10 @@ import { tokensForTool } from "./src/services/toolCost/index.mjs";
|
|
|
14
14
|
const CONTEXT_PROJECTION_VERSION = 1;
|
|
15
15
|
/** Journal entry the cockpit reads; mirrored by CONTEXT_ENTRY_TYPE in po-web. */
|
|
16
16
|
const PO_CONTEXT_ENTRY_TYPE = "po-context";
|
|
17
|
+
/** Only the host journals selections: a package writing one could forge what reopen restores, such as approvals. */
|
|
18
|
+
function assertPackageEntryType(customType) {
|
|
19
|
+
if (customType === "po-context") throw new Error(`Only the Po host may write '${PO_CONTEXT_ENTRY_TYPE}' entries.`);
|
|
20
|
+
}
|
|
17
21
|
/** Session selection and transition journal identities, not transport channels. */
|
|
18
22
|
const PO_CONFIG_ENTRY_TYPE = "po:config:v1";
|
|
19
23
|
const PO_CONFIG_TRANSITION_ENTRY_TYPE = "po:transition:v1";
|
|
@@ -46,13 +50,20 @@ function readProjectedSelection(data) {
|
|
|
46
50
|
const profile = "profile" in selection ? selection.profile : void 0;
|
|
47
51
|
if (profile !== void 0 && typeof profile !== "string") return void 0;
|
|
48
52
|
const requestedProfile = "requestedProfile" in selection ? selection.requestedProfile : void 0;
|
|
53
|
+
const state = "state" in selection ? readState(selection.state) : void 0;
|
|
49
54
|
return {
|
|
50
55
|
preset: selection.preset,
|
|
51
56
|
domains: [...selection.domains],
|
|
52
57
|
profile,
|
|
53
|
-
...typeof requestedProfile === "string" || requestedProfile === null ? { requestedProfile } : {}
|
|
58
|
+
...typeof requestedProfile === "string" || requestedProfile === null ? { requestedProfile } : {},
|
|
59
|
+
...state === void 0 ? {} : { state }
|
|
54
60
|
};
|
|
55
61
|
}
|
|
62
|
+
/** A saved state map with only string-list values; anything else is dropped rather than restored. */
|
|
63
|
+
function readState(value) {
|
|
64
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
65
|
+
return Object.fromEntries(Object.entries(value).flatMap(([key, values]) => Array.isArray(values) && values.every((item) => typeof item === "string") ? [[key, [...values]]] : []));
|
|
66
|
+
}
|
|
56
67
|
/** The notice for a session whose saved selection predates the preset and mode rename. */
|
|
57
68
|
const RETIRED_SESSION_NOTICE = "This session was saved by an older Po. Its preset and modes were not restored. Choose them again with /preset and /mode.";
|
|
58
69
|
function isRecordValue(value) {
|
|
@@ -144,7 +155,8 @@ function projectContext(input) {
|
|
|
144
155
|
preset: input.preset,
|
|
145
156
|
domains: [...input.domains],
|
|
146
157
|
...input.profile === void 0 ? {} : { profile: input.profile },
|
|
147
|
-
...input.requestedProfile === void 0 ? {} : { requestedProfile: input.requestedProfile }
|
|
158
|
+
...input.requestedProfile === void 0 ? {} : { requestedProfile: input.requestedProfile },
|
|
159
|
+
...input.state === void 0 ? {} : { state: structuredClone(input.state) }
|
|
148
160
|
},
|
|
149
161
|
groups,
|
|
150
162
|
totalTokens: groups.reduce((total, group) => total + group.tokens, 0),
|
|
@@ -154,6 +166,6 @@ function projectContext(input) {
|
|
|
154
166
|
};
|
|
155
167
|
}
|
|
156
168
|
//#endregion
|
|
157
|
-
export { CONTEXT_PROJECTION_ESTIMATOR, CONTEXT_PROJECTION_VERSION, PO_CONFIG_ENTRY_TYPE, PO_CONFIG_TRANSITION_ENTRY_TYPE, PO_CONTEXT_ENTRY_TYPE, RETIRED_SESSION_NOTICE, findRetiredSessionEntries, projectContext, readProjectedSelection };
|
|
169
|
+
export { CONTEXT_PROJECTION_ESTIMATOR, CONTEXT_PROJECTION_VERSION, PO_CONFIG_ENTRY_TYPE, PO_CONFIG_TRANSITION_ENTRY_TYPE, PO_CONTEXT_ENTRY_TYPE, RETIRED_SESSION_NOTICE, assertPackageEntryType, findRetiredSessionEntries, projectContext, readProjectedSelection };
|
|
158
170
|
|
|
159
171
|
//# sourceMappingURL=contextProjection.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextProjection.mjs","names":[],"sources":["../src/services/contextProjection/index.ts"],"sourcesContent":["/** What admitted a package into the composition. */\nexport interface PackageAttribution {\n /** `preset` for a layer package, `domain` for a plugin a domain carries. */\n kind: 'preset' | 'domain';\n /** The preset name, or the domain name. */\n name: string;\n /** The layer the package was listed under; absent for a domain plugin. */\n layer?: string;\n}\n\nimport type { ContextPromptStage } from '../../types/contextApi';\nimport { type CountTokens, type ToolEntry, type ToolSource, tokensForTool } from '../toolInventory';\n\n/**\n * What the session is carrying, and what carrying it costs.\n *\n * Grouped by the mode that admitted each package rather than by where the tool\n * came from, because a mode is the thing a reader can switch off. The mechanism\n * (extension, MCP server, plugin) orders rows inside a group instead, so the\n * expensive thing is still easy to find.\n *\n * Schemas never travel. Only names, kinds, owners and integer counts do, which\n * keeps the payload small enough to republish whenever the composition changes.\n */\nexport const CONTEXT_PROJECTION_VERSION = 1;\n\n/** Journal entry the cockpit reads; mirrored by CONTEXT_ENTRY_TYPE in po-web. */\nexport const PO_CONTEXT_ENTRY_TYPE = 'po-context';\n\n/** Session selection and transition journal identities, not transport channels. */\nexport const PO_CONFIG_ENTRY_TYPE = 'po:config:v1';\nexport const PO_CONFIG_TRANSITION_ENTRY_TYPE = 'po:transition:v1';\n\n/** The tokenizer these counts came from, so a reader can judge them. */\nexport const CONTEXT_PROJECTION_ESTIMATOR = 'gpt-tokenizer';\n\nexport type ContextGroupKind = 'preset' | 'mode' | 'domain' | 'shared' | 'core';\nexport type ContextItemSource = 'extension' | 'mcp' | 'plugin' | 'core';\n\n/** Everything the runtime could not attribute lands here rather than vanishing. */\nconst CORE_GROUP = 'core';\n/** Pi's own tools have no package; the runtime itself is the owner. */\nconst CORE_OWNER = 'pi';\nconst MCP_KEY_PREFIX = 'mcp:';\n\nconst KIND_ORDER: Record<ContextGroupKind, number> = { preset: 0, mode: 1, domain: 2, shared: 3, core: 4 };\nconst SOURCE_ORDER: Record<ContextItemSource, number> = { extension: 0, mcp: 1, plugin: 2, core: 3 };\n\nexport interface ContextItemProjection {\n readonly name: string;\n readonly itemKind: 'tool' | 'skill';\n readonly source: ContextItemSource;\n /** The package, server, or plugin that registered it. */\n readonly owner: string;\n readonly tokens: number;\n readonly active: boolean;\n}\n\nexport interface ContextGroupProjection {\n readonly id: string;\n readonly label: string;\n readonly kind: ContextGroupKind;\n readonly items: readonly ContextItemProjection[];\n /** What the group costs now: active items only. */\n readonly tokens: number;\n /** What its gated items would add if switched on. */\n readonly inactiveTokens: number;\n}\n\n/**\n * What the assembled system prompt costs, and how complete the figure is.\n *\n * Kept out of `groups` on purpose. Every tool's prose and every skill's listing\n * already count inside the group subtotals, and those are slices of this same\n * text, so folding it into `totalTokens` would bill them twice.\n */\nexport interface ContextSystemPromptProjection {\n readonly tokens: number;\n readonly stage: ContextPromptStage;\n}\n\nexport interface ContextProjection {\n readonly version: typeof CONTEXT_PROJECTION_VERSION;\n readonly revision: number;\n /** Selection snapshot used to build this projection, replayable after reconnect. */\n readonly selection: {\n readonly preset: string;\n readonly domains: readonly string[];\n readonly profile?: string;\n /** Requested profile when none is active; null records an explicit None pick. Absent on legacy records. */\n readonly requestedProfile?: string | null;\n };\n readonly groups: readonly ContextGroupProjection[];\n readonly totalTokens: number;\n readonly inactiveTokens: number;\n readonly systemPrompt?: ContextSystemPromptProjection;\n readonly estimator: typeof CONTEXT_PROJECTION_ESTIMATOR;\n}\n\nexport interface ContextConditionalAttribution {\n readonly kind: 'mode' | 'domain' | 'shared';\n readonly name: string;\n readonly label?: string;\n}\n\nexport interface ContextToolInventory extends ToolEntry {\n /** A contribution-level gate is more specific than its package's preset owner. */\n readonly contextAttribution?: ContextConditionalAttribution;\n}\n\nexport interface ContextToolSource extends Omit<ToolSource, 'tools'> {\n readonly tools: readonly ContextToolInventory[];\n}\n\n/** Skill fields needed to project cost and serve detail. Virtual resources may not have a filesystem path. */\nexport interface ContextSkillInventory {\n readonly name: string;\n readonly description: string;\n readonly group: 'extensions' | 'help' | 'plugins' | 'default';\n readonly owner: string;\n readonly modelInvocable: boolean;\n readonly promptTokens?: number;\n readonly filePath?: string;\n /** The skill's instructions, when the host holds them; read only when a reader opens the row. */\n readonly body?: string;\n readonly contextAttribution?: ContextConditionalAttribution;\n}\n\nexport interface ContextProjectionInput {\n readonly revision: number;\n readonly preset: string;\n readonly profile?: string;\n readonly requestedProfile?: string | null;\n /** Additional groups supplied by the composition owner, in display order. */\n readonly groups: readonly { readonly id: string; readonly label: string; readonly kind: ContextGroupKind }[];\n /** Domains the composition resolved under, whether or not they carried a plugin. */\n readonly domains: readonly string[];\n readonly sources: readonly ContextToolSource[];\n readonly skills: readonly ContextSkillInventory[];\n /**\n * Owner identifier to the mode that admitted it.\n *\n * Keys are package names for extensions and layer packages, and plugin or\n * server names for anything a domain carries. The caller owns this join\n * because only it knows how a given deployment resolved its plugins.\n */\n readonly attribution: Readonly<Record<string, PackageAttribution>>;\n readonly countTokens: CountTokens;\n /** Absent until the session has a prompt to report. */\n readonly systemPrompt?: ContextSystemPromptProjection;\n}\n\n/** Reads only replayable selection fields, accepting legacy projections without a request marker. */\nexport function readProjectedSelection(data: unknown): ContextProjection['selection'] | undefined {\n if (typeof data !== 'object' || data === null || Array.isArray(data) || !('selection' in data)) return undefined;\n const selection = data.selection;\n if (typeof selection !== 'object' || selection === null || Array.isArray(selection)) return undefined;\n if (!('preset' in selection) || typeof selection.preset !== 'string') return undefined;\n if (\n !('domains' in selection) ||\n !Array.isArray(selection.domains) ||\n !selection.domains.every((domain) => typeof domain === 'string')\n )\n return undefined;\n const profile = 'profile' in selection ? selection.profile : undefined;\n if (profile !== undefined && typeof profile !== 'string') return undefined;\n const requestedProfile = 'requestedProfile' in selection ? selection.requestedProfile : undefined;\n return {\n preset: selection.preset,\n domains: [...selection.domains],\n profile,\n ...(typeof requestedProfile === 'string' || requestedProfile === null ? { requestedProfile } : {}),\n };\n}\n\n/** The notice for a session whose saved selection predates the preset and mode rename. */\nexport const RETIRED_SESSION_NOTICE =\n 'This session was saved by an older Po. Its preset and modes were not restored. Choose them again with /preset and /mode.';\n\nfunction isRecordValue(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Whether the newest saved selection was written before the rename, so it could not be restored.\n * The host journals a selection for every session, so this one entry is the only trigger; old saved\n * modes are lost with it. Pure over journal entries: the caller decides how to tell the person.\n */\nexport function findRetiredSessionEntries(entries: readonly unknown[]): boolean {\n for (let index = entries.length - 1; index >= 0; index -= 1) {\n const entry = entries[index];\n if (!isRecordValue(entry) || entry.type !== 'custom' || entry.customType !== PO_CONTEXT_ENTRY_TYPE) continue;\n if (readProjectedSelection(entry.data) !== undefined) return false;\n const selection = isRecordValue(entry.data) ? entry.data.selection : undefined;\n return isRecordValue(selection) && Object.hasOwn(selection, 'majorMode'); // retired-name\n }\n return false;\n}\n\ninterface Bucket {\n kind: ContextGroupKind;\n label: string;\n items: ContextItemProjection[];\n}\n\nfunction skillSource(group: ContextSkillInventory['group']): ContextItemSource {\n if (group === 'plugins') return 'plugin';\n if (group === 'extensions') return 'extension';\n return 'core';\n}\n\nfunction byRow(left: ContextItemProjection, right: ContextItemProjection): number {\n return SOURCE_ORDER[left.source] - SOURCE_ORDER[right.source] || left.name.localeCompare(right.name);\n}\n\nexport function projectContext(input: ContextProjectionInput): ContextProjection {\n const buckets = new Map<string, Bucket>();\n\n // Declared before anything is placed, so a mode with nothing attributed to it\n // still appears. An empty group is a fact worth showing: it says the mode is\n // on and cheap, not that the runtime forgot about it.\n const declare = (id: string, label: string, kind: ContextGroupKind): void => {\n if (!buckets.has(id)) buckets.set(id, { kind, label, items: [] });\n };\n if (input.preset) declare(input.preset, input.preset, 'preset');\n for (const group of input.groups) declare(group.id, group.label, group.kind);\n // A domain that contributed no plugin is still part of what the session is\n // running under, and a reader comparing the panel against the footer would\n // otherwise read its absence as the panel being out of date.\n for (const domain of input.domains) declare(domain, domain, 'domain');\n\n const place = (owner: string, item: ContextItemProjection, conditional?: ContextConditionalAttribution): void => {\n const attributed = conditional ?? input.attribution[owner];\n const id = attributed?.name ?? CORE_GROUP;\n const kind = attributed?.kind ?? 'core';\n declare(id, attributed && 'label' in attributed ? (attributed.label ?? id) : id, kind);\n buckets.get(id)?.items.push(item);\n };\n\n for (const source of input.sources) {\n // An extension is owned by its package, an MCP tool by the server that\n // advertised it. `label` is display text like `scaffold · mcp`, so the\n // identifier comes from the key instead: an owner is joined on, not read.\n const owner =\n source.kind === 'extension'\n ? (source.packageName ?? source.key)\n : source.kind === 'mcp'\n ? source.key.slice(MCP_KEY_PREFIX.length)\n : CORE_OWNER;\n for (const tool of source.tools) {\n const cost = tokensForTool(tool, input.countTokens);\n const item: ContextItemProjection = {\n name: tool.name,\n itemKind: 'tool',\n source: source.kind === 'core' ? 'core' : source.kind,\n owner,\n tokens: cost.totalTokens,\n active: tool.active,\n };\n if (source.kind === 'core') {\n declare(CORE_GROUP, CORE_GROUP, 'core');\n buckets.get(CORE_GROUP)?.items.push(item);\n } else {\n place(owner, item, tool.contextAttribution);\n }\n }\n }\n\n for (const skill of input.skills) {\n place(\n skill.owner,\n {\n name: skill.name,\n itemKind: 'skill',\n source: skillSource(skill.group),\n owner: skill.owner,\n tokens: skill.promptTokens ?? 0,\n // A skill is always offered to the model; there is no inactive state for\n // it the way there is for a tool Pi has filtered out.\n active: true,\n },\n skill.contextAttribution,\n );\n }\n\n const groups: ContextGroupProjection[] = [...buckets.entries()]\n .map(([id, bucket]) => {\n const items = [...bucket.items].sort(byRow);\n // Only what is actually sent counts. Pi builds the prompt from its\n // active tools, so a gated one costs nothing until it is switched on,\n // and folding it into the total would overstate the bill by a third.\n return {\n id,\n label: bucket.label,\n kind: bucket.kind,\n items,\n tokens: items.reduce((total, item) => total + (item.active ? item.tokens : 0), 0),\n inactiveTokens: items.reduce((total, item) => total + (item.active ? 0 : item.tokens), 0),\n };\n })\n .sort((left, right) => KIND_ORDER[left.kind] - KIND_ORDER[right.kind] || left.label.localeCompare(right.label));\n\n return {\n version: CONTEXT_PROJECTION_VERSION,\n revision: input.revision,\n selection: {\n preset: input.preset,\n domains: [...input.domains],\n ...(input.profile === undefined ? {} : { profile: input.profile }),\n ...(input.requestedProfile === undefined ? {} : { requestedProfile: input.requestedProfile }),\n },\n groups,\n totalTokens: groups.reduce((total, group) => total + group.tokens, 0),\n inactiveTokens: groups.reduce((total, group) => total + group.inactiveTokens, 0),\n ...(input.systemPrompt === undefined ? {} : { systemPrompt: input.systemPrompt }),\n estimator: CONTEXT_PROJECTION_ESTIMATOR,\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,MAAa,6BAA6B;;AAG1C,MAAa,wBAAwB;;AAGrC,MAAa,uBAAuB;AACpC,MAAa,kCAAkC;;AAG/C,MAAa,+BAA+B;;AAM5C,MAAM,aAAa;;AAEnB,MAAM,aAAa;AAGnB,MAAM,aAA+C;CAAE,QAAQ;CAAG,MAAM;CAAG,QAAQ;CAAG,QAAQ;CAAG,MAAM;AAAE;AACzG,MAAM,eAAkD;CAAE,WAAW;CAAG,KAAK;CAAG,QAAQ;CAAG,MAAM;AAAE;;AA2GnG,SAAgB,uBAAuB,MAA2D;CAChG,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,MAAM,QAAQ,IAAI,KAAK,EAAE,eAAe,OAAO,O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B,CAAC;EAC/E,GAAI,MAAM,iBAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,cAAc,MAAM,aAAa;EAC/E,WAAW;CACb;AACF"}
|
|
1
|
+
{"version":3,"file":"contextProjection.mjs","names":[],"sources":["../src/services/contextProjection/index.ts"],"sourcesContent":["/** What admitted a package into the composition. */\nexport interface PackageAttribution {\n /** `preset` for a layer package, `domain` for a plugin a domain carries. */\n kind: 'preset' | 'domain';\n /** The preset name, or the domain name. */\n name: string;\n /** The layer the package was listed under; absent for a domain plugin. */\n layer?: string;\n}\n\nimport type { ContextPromptStage } from '../../types/contextApi';\nimport { type CountTokens, type ToolEntry, type ToolSource, tokensForTool } from '../toolInventory';\n\n/**\n * What the session is carrying, and what carrying it costs.\n *\n * Grouped by the mode that admitted each package rather than by where the tool\n * came from, because a mode is the thing a reader can switch off. The mechanism\n * (extension, MCP server, plugin) orders rows inside a group instead, so the\n * expensive thing is still easy to find.\n *\n * Schemas never travel. Only names, kinds, owners and integer counts do, which\n * keeps the payload small enough to republish whenever the composition changes.\n */\nexport const CONTEXT_PROJECTION_VERSION = 1;\n\n/** Journal entry the cockpit reads; mirrored by CONTEXT_ENTRY_TYPE in po-web. */\nexport const PO_CONTEXT_ENTRY_TYPE = 'po-context';\n\n/** Only the host journals selections: a package writing one could forge what reopen restores, such as approvals. */\nexport function assertPackageEntryType(customType: string): void {\n if (customType === PO_CONTEXT_ENTRY_TYPE)\n throw new Error(`Only the Po host may write '${PO_CONTEXT_ENTRY_TYPE}' entries.`);\n}\n\n/** Session selection and transition journal identities, not transport channels. */\nexport const PO_CONFIG_ENTRY_TYPE = 'po:config:v1';\nexport const PO_CONFIG_TRANSITION_ENTRY_TYPE = 'po:transition:v1';\n\n/** The tokenizer these counts came from, so a reader can judge them. */\nexport const CONTEXT_PROJECTION_ESTIMATOR = 'gpt-tokenizer';\n\nexport type ContextGroupKind = 'preset' | 'mode' | 'domain' | 'shared' | 'core';\nexport type ContextItemSource = 'extension' | 'mcp' | 'plugin' | 'core';\n\n/** Everything the runtime could not attribute lands here rather than vanishing. */\nconst CORE_GROUP = 'core';\n/** Pi's own tools have no package; the runtime itself is the owner. */\nconst CORE_OWNER = 'pi';\nconst MCP_KEY_PREFIX = 'mcp:';\n\nconst KIND_ORDER: Record<ContextGroupKind, number> = { preset: 0, mode: 1, domain: 2, shared: 3, core: 4 };\nconst SOURCE_ORDER: Record<ContextItemSource, number> = { extension: 0, mcp: 1, plugin: 2, core: 3 };\n\nexport interface ContextItemProjection {\n readonly name: string;\n readonly itemKind: 'tool' | 'skill';\n readonly source: ContextItemSource;\n /** The package, server, or plugin that registered it. */\n readonly owner: string;\n readonly tokens: number;\n readonly active: boolean;\n}\n\nexport interface ContextGroupProjection {\n readonly id: string;\n readonly label: string;\n readonly kind: ContextGroupKind;\n readonly items: readonly ContextItemProjection[];\n /** What the group costs now: active items only. */\n readonly tokens: number;\n /** What its gated items would add if switched on. */\n readonly inactiveTokens: number;\n}\n\n/**\n * What the assembled system prompt costs, and how complete the figure is.\n *\n * Kept out of `groups` on purpose. Every tool's prose and every skill's listing\n * already count inside the group subtotals, and those are slices of this same\n * text, so folding it into `totalTokens` would bill them twice.\n */\nexport interface ContextSystemPromptProjection {\n readonly tokens: number;\n readonly stage: ContextPromptStage;\n}\n\nexport interface ContextProjection {\n readonly version: typeof CONTEXT_PROJECTION_VERSION;\n readonly revision: number;\n /** Selection snapshot used to build this projection, replayable after reconnect. */\n readonly selection: {\n readonly preset: string;\n readonly domains: readonly string[];\n readonly profile?: string;\n /** Requested profile when none is active; null records an explicit None pick. Absent on legacy records. */\n readonly requestedProfile?: string | null;\n /** Feature-owned activation sets, such as modes and approved plugins. Absent on legacy records. */\n readonly state?: Readonly<Record<string, readonly string[]>>;\n };\n readonly groups: readonly ContextGroupProjection[];\n readonly totalTokens: number;\n readonly inactiveTokens: number;\n readonly systemPrompt?: ContextSystemPromptProjection;\n readonly estimator: typeof CONTEXT_PROJECTION_ESTIMATOR;\n}\n\nexport interface ContextConditionalAttribution {\n readonly kind: 'mode' | 'domain' | 'shared';\n readonly name: string;\n readonly label?: string;\n}\n\nexport interface ContextToolInventory extends ToolEntry {\n /** A contribution-level gate is more specific than its package's preset owner. */\n readonly contextAttribution?: ContextConditionalAttribution;\n}\n\nexport interface ContextToolSource extends Omit<ToolSource, 'tools'> {\n readonly tools: readonly ContextToolInventory[];\n}\n\n/** Skill fields needed to project cost and serve detail. Virtual resources may not have a filesystem path. */\nexport interface ContextSkillInventory {\n readonly name: string;\n readonly description: string;\n readonly group: 'extensions' | 'help' | 'plugins' | 'default';\n readonly owner: string;\n readonly modelInvocable: boolean;\n readonly promptTokens?: number;\n readonly filePath?: string;\n /** The skill's instructions, when the host holds them; read only when a reader opens the row. */\n readonly body?: string;\n readonly contextAttribution?: ContextConditionalAttribution;\n}\n\nexport interface ContextProjectionInput {\n readonly revision: number;\n readonly preset: string;\n readonly profile?: string;\n readonly requestedProfile?: string | null;\n readonly state?: Readonly<Record<string, readonly string[]>>;\n /** Additional groups supplied by the composition owner, in display order. */\n readonly groups: readonly { readonly id: string; readonly label: string; readonly kind: ContextGroupKind }[];\n /** Domains the composition resolved under, whether or not they carried a plugin. */\n readonly domains: readonly string[];\n readonly sources: readonly ContextToolSource[];\n readonly skills: readonly ContextSkillInventory[];\n /**\n * Owner identifier to the mode that admitted it.\n *\n * Keys are package names for extensions and layer packages, and plugin or\n * server names for anything a domain carries. The caller owns this join\n * because only it knows how a given deployment resolved its plugins.\n */\n readonly attribution: Readonly<Record<string, PackageAttribution>>;\n readonly countTokens: CountTokens;\n /** Absent until the session has a prompt to report. */\n readonly systemPrompt?: ContextSystemPromptProjection;\n}\n\n/** Reads only replayable selection fields, accepting legacy projections without a request marker. */\nexport function readProjectedSelection(data: unknown): ContextProjection['selection'] | undefined {\n if (typeof data !== 'object' || data === null || Array.isArray(data) || !('selection' in data)) return undefined;\n const selection = data.selection;\n if (typeof selection !== 'object' || selection === null || Array.isArray(selection)) return undefined;\n if (!('preset' in selection) || typeof selection.preset !== 'string') return undefined;\n if (\n !('domains' in selection) ||\n !Array.isArray(selection.domains) ||\n !selection.domains.every((domain) => typeof domain === 'string')\n )\n return undefined;\n const profile = 'profile' in selection ? selection.profile : undefined;\n if (profile !== undefined && typeof profile !== 'string') return undefined;\n const requestedProfile = 'requestedProfile' in selection ? selection.requestedProfile : undefined;\n const state = 'state' in selection ? readState(selection.state) : undefined;\n return {\n preset: selection.preset,\n domains: [...selection.domains],\n profile,\n ...(typeof requestedProfile === 'string' || requestedProfile === null ? { requestedProfile } : {}),\n ...(state === undefined ? {} : { state }),\n };\n}\n\n/** A saved state map with only string-list values; anything else is dropped rather than restored. */\nfunction readState(value: unknown): Record<string, string[]> | undefined {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return undefined;\n return Object.fromEntries(\n Object.entries(value).flatMap(([key, values]) =>\n Array.isArray(values) && values.every((item) => typeof item === 'string') ? [[key, [...values]]] : [],\n ),\n );\n}\n\n/** The notice for a session whose saved selection predates the preset and mode rename. */\nexport const RETIRED_SESSION_NOTICE =\n 'This session was saved by an older Po. Its preset and modes were not restored. Choose them again with /preset and /mode.';\n\nfunction isRecordValue(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Whether the newest saved selection was written before the rename, so it could not be restored.\n * The host journals a selection for every session, so this one entry is the only trigger; old saved\n * modes are lost with it. Pure over journal entries: the caller decides how to tell the person.\n */\nexport function findRetiredSessionEntries(entries: readonly unknown[]): boolean {\n for (let index = entries.length - 1; index >= 0; index -= 1) {\n const entry = entries[index];\n if (!isRecordValue(entry) || entry.type !== 'custom' || entry.customType !== PO_CONTEXT_ENTRY_TYPE) continue;\n if (readProjectedSelection(entry.data) !== undefined) return false;\n const selection = isRecordValue(entry.data) ? entry.data.selection : undefined;\n return isRecordValue(selection) && Object.hasOwn(selection, 'majorMode'); // retired-name\n }\n return false;\n}\n\ninterface Bucket {\n kind: ContextGroupKind;\n label: string;\n items: ContextItemProjection[];\n}\n\nfunction skillSource(group: ContextSkillInventory['group']): ContextItemSource {\n if (group === 'plugins') return 'plugin';\n if (group === 'extensions') return 'extension';\n return 'core';\n}\n\nfunction byRow(left: ContextItemProjection, right: ContextItemProjection): number {\n return SOURCE_ORDER[left.source] - SOURCE_ORDER[right.source] || left.name.localeCompare(right.name);\n}\n\nexport function projectContext(input: ContextProjectionInput): ContextProjection {\n const buckets = new Map<string, Bucket>();\n\n // Declared before anything is placed, so a mode with nothing attributed to it\n // still appears. An empty group is a fact worth showing: it says the mode is\n // on and cheap, not that the runtime forgot about it.\n const declare = (id: string, label: string, kind: ContextGroupKind): void => {\n if (!buckets.has(id)) buckets.set(id, { kind, label, items: [] });\n };\n if (input.preset) declare(input.preset, input.preset, 'preset');\n for (const group of input.groups) declare(group.id, group.label, group.kind);\n // A domain that contributed no plugin is still part of what the session is\n // running under, and a reader comparing the panel against the footer would\n // otherwise read its absence as the panel being out of date.\n for (const domain of input.domains) declare(domain, domain, 'domain');\n\n const place = (owner: string, item: ContextItemProjection, conditional?: ContextConditionalAttribution): void => {\n const attributed = conditional ?? input.attribution[owner];\n const id = attributed?.name ?? CORE_GROUP;\n const kind = attributed?.kind ?? 'core';\n declare(id, attributed && 'label' in attributed ? (attributed.label ?? id) : id, kind);\n buckets.get(id)?.items.push(item);\n };\n\n for (const source of input.sources) {\n // An extension is owned by its package, an MCP tool by the server that\n // advertised it. `label` is display text like `scaffold · mcp`, so the\n // identifier comes from the key instead: an owner is joined on, not read.\n const owner =\n source.kind === 'extension'\n ? (source.packageName ?? source.key)\n : source.kind === 'mcp'\n ? source.key.slice(MCP_KEY_PREFIX.length)\n : CORE_OWNER;\n for (const tool of source.tools) {\n const cost = tokensForTool(tool, input.countTokens);\n const item: ContextItemProjection = {\n name: tool.name,\n itemKind: 'tool',\n source: source.kind === 'core' ? 'core' : source.kind,\n owner,\n tokens: cost.totalTokens,\n active: tool.active,\n };\n if (source.kind === 'core') {\n declare(CORE_GROUP, CORE_GROUP, 'core');\n buckets.get(CORE_GROUP)?.items.push(item);\n } else {\n place(owner, item, tool.contextAttribution);\n }\n }\n }\n\n for (const skill of input.skills) {\n place(\n skill.owner,\n {\n name: skill.name,\n itemKind: 'skill',\n source: skillSource(skill.group),\n owner: skill.owner,\n tokens: skill.promptTokens ?? 0,\n // A skill is always offered to the model; there is no inactive state for\n // it the way there is for a tool Pi has filtered out.\n active: true,\n },\n skill.contextAttribution,\n );\n }\n\n const groups: ContextGroupProjection[] = [...buckets.entries()]\n .map(([id, bucket]) => {\n const items = [...bucket.items].sort(byRow);\n // Only what is actually sent counts. Pi builds the prompt from its\n // active tools, so a gated one costs nothing until it is switched on,\n // and folding it into the total would overstate the bill by a third.\n return {\n id,\n label: bucket.label,\n kind: bucket.kind,\n items,\n tokens: items.reduce((total, item) => total + (item.active ? item.tokens : 0), 0),\n inactiveTokens: items.reduce((total, item) => total + (item.active ? 0 : item.tokens), 0),\n };\n })\n .sort((left, right) => KIND_ORDER[left.kind] - KIND_ORDER[right.kind] || left.label.localeCompare(right.label));\n\n return {\n version: CONTEXT_PROJECTION_VERSION,\n revision: input.revision,\n selection: {\n preset: input.preset,\n domains: [...input.domains],\n ...(input.profile === undefined ? {} : { profile: input.profile }),\n ...(input.requestedProfile === undefined ? {} : { requestedProfile: input.requestedProfile }),\n ...(input.state === undefined ? {} : { state: structuredClone(input.state) }),\n },\n groups,\n totalTokens: groups.reduce((total, group) => total + group.tokens, 0),\n inactiveTokens: groups.reduce((total, group) => total + group.inactiveTokens, 0),\n ...(input.systemPrompt === undefined ? {} : { systemPrompt: input.systemPrompt }),\n estimator: CONTEXT_PROJECTION_ESTIMATOR,\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,MAAa,6BAA6B;;AAG1C,MAAa,wBAAwB;;AAGrC,SAAgB,uBAAuB,YAA0B;CAC/D,IAAI,eAAA,cACF,MAAM,IAAI,MAAM,+BAA+B,sBAAsB,WAAW;AACpF;;AAGA,MAAa,uBAA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K,CAAC,IAAI,YAAY;EACrB,MAAM,QAAQ,CAAC,GAAG,OAAO,KAAK,CAAC,CAAC,KAAK,KAAK;EAI1C,OAAO;GACL;GACA,OAAO,OAAO;GACd,MAAM,OAAO;GACb;GACA,QAAQ,MAAM,QAAQ,OAAO,SAAS,SAAS,KAAK,SAAS,KAAK,SAAS,IAAI,CAAC;GAChF,gBAAgB,MAAM,QAAQ,OAAO,SAAS,SAAS,KAAK,SAAS,IAAI,KAAK,SAAS,CAAC;EAC1F;CACF,CAAC,CAAC,CACD,MAAM,MAAM,UAAU,WAAW,KAAK,QAAQ,WAAW,MAAM,SAAS,KAAK,MAAM,cAAc,MAAM,KAAK,CAAC;CAEhH,OAAO;EACL,SAAA;EACA,UAAU,MAAM;EAChB,WAAW;GACT,QAAQ,MAAM;GACd,SAAS,CAAC,GAAG,MAAM,OAAO;GAC1B,GAAI,MAAM,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,MAAM,QAAQ;GAChE,GAAI,MAAM,qBAAqB,KAAA,IAAY,CAAC,IAAI,EAAE,kBAAkB,MAAM,iBAAiB;GAC3F,GAAI,MAAM,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO,gBAAgB,MAAM,KAAK,EAAE;EAC7E;EACA;EACA,aAAa,OAAO,QAAQ,OAAO,UAAU,QAAQ,MAAM,QAAQ,CAAC;EACpE,gBAAgB,OAAO,QAAQ,OAAO,UAAU,QAAQ,MAAM,gBAAgB,CAAC;EAC/E,GAAI,MAAM,iBAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,cAAc,MAAM,aAAa;EAC/E,WAAW;CACb;AACF"}
|
package/dist/headless.cjs
CHANGED
|
@@ -10,6 +10,8 @@ Object.defineProperty(exports, "DEFAULT_COMPACTION_POLICY", {
|
|
|
10
10
|
return _earendil_works_pi_durable.DEFAULT_COMPACTION_POLICY;
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
|
+
exports.PO_EXTENSIONS_OWNER = require_headless.PO_EXTENSIONS_OWNER;
|
|
14
|
+
exports.PO_EXTENSIONS_STATE = require_headless.PO_EXTENSIONS_STATE;
|
|
13
15
|
exports.PO_HEADLESS_HOST_SERVICE = require_headless.PO_HEADLESS_HOST_SERVICE;
|
|
14
16
|
exports.PO_HEADLESS_OWNER = require_headless.PO_HEADLESS_OWNER;
|
|
15
17
|
exports.PO_LOAD_SKILL_TOOL = require_headless.PO_LOAD_SKILL_TOOL;
|
|
@@ -19,6 +21,7 @@ exports.PoHeadlessStartupReadinessError = require_headless.PoHeadlessStartupRead
|
|
|
19
21
|
exports.PoHeadlessToolBusyError = require_headless.PoHeadlessToolBusyError;
|
|
20
22
|
exports.PoImageGenerationError = require_headless.PoImageGenerationError;
|
|
21
23
|
exports.PoSessionSetupError = require_headless.PoSessionSetupError;
|
|
24
|
+
exports.approvedExtensionLayers = require_headless.approvedExtensionLayers;
|
|
22
25
|
exports.dropInvalidImages = require_headless.dropInvalidImages;
|
|
23
26
|
exports.invalidImageReason = require_headless.invalidImageReason;
|
|
24
27
|
exports.isPoHeadlessPromptAdmissionError = require_headless.isPoHeadlessPromptAdmissionError;
|
|
@@ -30,4 +33,5 @@ exports.readPoHeadlessHost = require_headless.readPoHeadlessHost;
|
|
|
30
33
|
exports.readPoHeadlessOwner = require_headless.readPoHeadlessOwner;
|
|
31
34
|
exports.requirePoHeadlessHost = require_headless.requirePoHeadlessHost;
|
|
32
35
|
exports.sessionEntryToContextMessages = require_index.sessionEntryToContextMessages;
|
|
36
|
+
exports.sessionExtensionReceipt = require_headless.sessionExtensionReceipt;
|
|
33
37
|
exports.toPoHeadlessToolResult = require_headless.toPoHeadlessToolResult;
|
package/dist/headless.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PoOperationAfterEvent, PoOperationAfterResult, PoOperationBeforeEvent, PoOperationBeforeResult } from "./src/schemas/operationHook.mjs";
|
|
2
|
-
import { PO_HEADLESS_HOST_SERVICE, PO_HEADLESS_OWNER, PO_LOAD_SKILL_TOOL, PO_SEARCH_SKILLS_TOOL, PoHeadlessActivity, PoHeadlessCapability, PoHeadlessCapabilitySnapshot, PoHeadlessClient, PoHeadlessClientRequest, PoHeadlessCommand, PoHeadlessCompactionResult, PoHeadlessCondition, PoHeadlessContent, PoHeadlessEventName, PoHeadlessExecutionContext, PoHeadlessHook, PoHeadlessHookEvent, PoHeadlessHookResult, PoHeadlessHostService, PoHeadlessLifecycleSnapshot, PoHeadlessModelMetadata, PoHeadlessModelSettings, PoHeadlessPromptAdmissionError, PoHeadlessRefreshAxis, PoHeadlessRegistration, PoHeadlessResource, PoHeadlessSelection, PoHeadlessSelectionApplied, PoHeadlessSelectionChange, PoHeadlessSession, PoHeadlessStartupReadinessError, PoHeadlessTool, PoHeadlessToolBusyError, PoHeadlessToolCompletionRequest, PoHeadlessToolCompletionResult, PoHeadlessToolContinuation, PoHeadlessToolRestriction, PoHeadlessToolResult, PoImageGenerationError, PoImageGenerationFailure, PoMcpSkillAccess, PoSessionSetupError, dropInvalidImages, invalidImageReason, isPoHeadlessPromptAdmissionError, isPoHeadlessToolBusyError, isPoHeadlessToolModelVisible, isPoImageGenerationError, isPoSessionSetupError, readPoHeadlessHost, readPoHeadlessOwner, requirePoHeadlessHost, toPoHeadlessToolResult } from "./src/schemas/headless.mjs";
|
|
2
|
+
import { PO_EXTENSIONS_OWNER, PO_EXTENSIONS_STATE, PO_HEADLESS_HOST_SERVICE, PO_HEADLESS_OWNER, PO_LOAD_SKILL_TOOL, PO_SEARCH_SKILLS_TOOL, PoHeadlessActivity, PoHeadlessCapability, PoHeadlessCapabilitySnapshot, PoHeadlessClient, PoHeadlessClientRequest, PoHeadlessCommand, PoHeadlessCompactionResult, PoHeadlessCondition, PoHeadlessContent, PoHeadlessEventName, PoHeadlessExecutionContext, PoHeadlessHook, PoHeadlessHookEvent, PoHeadlessHookResult, PoHeadlessHostService, PoHeadlessLifecycleSnapshot, PoHeadlessModelMetadata, PoHeadlessModelSettings, PoHeadlessPromptAdmissionError, PoHeadlessPromptChange, PoHeadlessPromptContribution, PoHeadlessPromptPreview, PoHeadlessPromptSnapshot, PoHeadlessRefreshAxis, PoHeadlessRegistration, PoHeadlessResource, PoHeadlessSelection, PoHeadlessSelectionApplied, PoHeadlessSelectionChange, PoHeadlessSession, PoHeadlessStartupReadinessError, PoHeadlessTool, PoHeadlessToolBusyError, PoHeadlessToolCompletionRequest, PoHeadlessToolCompletionResult, PoHeadlessToolContinuation, PoHeadlessToolRestriction, PoHeadlessToolResult, PoImageGenerationError, PoImageGenerationFailure, PoMcpSkillAccess, PoSessionExtension, PoSessionSetupError, PoSkillRelation, approvedExtensionLayers, dropInvalidImages, invalidImageReason, isPoHeadlessPromptAdmissionError, isPoHeadlessToolBusyError, isPoHeadlessToolModelVisible, isPoImageGenerationError, isPoSessionSetupError, readPoHeadlessHost, readPoHeadlessOwner, requirePoHeadlessHost, sessionExtensionReceipt, toPoHeadlessToolResult } from "./src/schemas/headless.mjs";
|
|
3
3
|
import { AGENT_SETTLED_ENTRY_TYPE } from "./src/constants/agentSettled.mjs";
|
|
4
4
|
import { sessionEntryToContextMessages } from "./src/services/piMessages/index.mjs";
|
|
5
5
|
import { DEFAULT_COMPACTION_POLICY } from "@earendil-works/pi-durable";
|
|
6
|
-
export { AGENT_SETTLED_ENTRY_TYPE, DEFAULT_COMPACTION_POLICY, PO_HEADLESS_HOST_SERVICE, PO_HEADLESS_OWNER, PO_LOAD_SKILL_TOOL, PO_SEARCH_SKILLS_TOOL, PoHeadlessActivity, PoHeadlessCapability, PoHeadlessCapabilitySnapshot, PoHeadlessClient, PoHeadlessClientRequest, PoHeadlessCommand, PoHeadlessCompactionResult, PoHeadlessCondition, PoHeadlessContent, PoHeadlessEventName, PoHeadlessExecutionContext, PoHeadlessHook, PoHeadlessHookEvent, PoHeadlessHookResult, PoHeadlessHostService, PoHeadlessLifecycleSnapshot, PoHeadlessModelMetadata, PoHeadlessModelSettings, PoHeadlessPromptAdmissionError, PoHeadlessRefreshAxis, PoHeadlessRegistration, PoHeadlessResource, PoHeadlessSelection, PoHeadlessSelectionApplied, PoHeadlessSelectionChange, PoHeadlessSession, PoHeadlessStartupReadinessError, PoHeadlessTool, PoHeadlessToolBusyError, PoHeadlessToolCompletionRequest, PoHeadlessToolCompletionResult, PoHeadlessToolContinuation, PoHeadlessToolRestriction, PoHeadlessToolResult, PoImageGenerationError, PoImageGenerationFailure, PoMcpSkillAccess, type PoOperationAfterEvent, type PoOperationAfterResult, type PoOperationBeforeEvent, type PoOperationBeforeResult, PoSessionSetupError, dropInvalidImages, invalidImageReason, isPoHeadlessPromptAdmissionError, isPoHeadlessToolBusyError, isPoHeadlessToolModelVisible, isPoImageGenerationError, isPoSessionSetupError, readPoHeadlessHost, readPoHeadlessOwner, requirePoHeadlessHost, sessionEntryToContextMessages, toPoHeadlessToolResult };
|
|
6
|
+
export { AGENT_SETTLED_ENTRY_TYPE, DEFAULT_COMPACTION_POLICY, PO_EXTENSIONS_OWNER, PO_EXTENSIONS_STATE, PO_HEADLESS_HOST_SERVICE, PO_HEADLESS_OWNER, PO_LOAD_SKILL_TOOL, PO_SEARCH_SKILLS_TOOL, PoHeadlessActivity, PoHeadlessCapability, PoHeadlessCapabilitySnapshot, PoHeadlessClient, PoHeadlessClientRequest, PoHeadlessCommand, PoHeadlessCompactionResult, PoHeadlessCondition, PoHeadlessContent, PoHeadlessEventName, PoHeadlessExecutionContext, PoHeadlessHook, PoHeadlessHookEvent, PoHeadlessHookResult, PoHeadlessHostService, PoHeadlessLifecycleSnapshot, PoHeadlessModelMetadata, PoHeadlessModelSettings, PoHeadlessPromptAdmissionError, PoHeadlessPromptChange, PoHeadlessPromptContribution, PoHeadlessPromptPreview, PoHeadlessPromptSnapshot, PoHeadlessRefreshAxis, PoHeadlessRegistration, PoHeadlessResource, PoHeadlessSelection, PoHeadlessSelectionApplied, PoHeadlessSelectionChange, PoHeadlessSession, PoHeadlessStartupReadinessError, PoHeadlessTool, PoHeadlessToolBusyError, PoHeadlessToolCompletionRequest, PoHeadlessToolCompletionResult, PoHeadlessToolContinuation, PoHeadlessToolRestriction, PoHeadlessToolResult, PoImageGenerationError, PoImageGenerationFailure, PoMcpSkillAccess, type PoOperationAfterEvent, type PoOperationAfterResult, type PoOperationBeforeEvent, type PoOperationBeforeResult, PoSessionExtension, PoSessionSetupError, PoSkillRelation, approvedExtensionLayers, dropInvalidImages, invalidImageReason, isPoHeadlessPromptAdmissionError, isPoHeadlessToolBusyError, isPoHeadlessToolModelVisible, isPoImageGenerationError, isPoSessionSetupError, readPoHeadlessHost, readPoHeadlessOwner, requirePoHeadlessHost, sessionEntryToContextMessages, sessionExtensionReceipt, toPoHeadlessToolResult };
|
package/dist/headless.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AGENT_SETTLED_ENTRY_TYPE } from "./src/constants/agentSettled.mjs";
|
|
2
|
-
import { PO_HEADLESS_HOST_SERVICE, PO_HEADLESS_OWNER, PO_LOAD_SKILL_TOOL, PO_SEARCH_SKILLS_TOOL, PoHeadlessPromptAdmissionError, PoHeadlessStartupReadinessError, PoHeadlessToolBusyError, PoImageGenerationError, PoSessionSetupError, dropInvalidImages, invalidImageReason, isPoHeadlessPromptAdmissionError, isPoHeadlessToolBusyError, isPoHeadlessToolModelVisible, isPoImageGenerationError, isPoSessionSetupError, readPoHeadlessHost, readPoHeadlessOwner, requirePoHeadlessHost, toPoHeadlessToolResult } from "./src/schemas/headless.mjs";
|
|
2
|
+
import { PO_EXTENSIONS_OWNER, PO_EXTENSIONS_STATE, PO_HEADLESS_HOST_SERVICE, PO_HEADLESS_OWNER, PO_LOAD_SKILL_TOOL, PO_SEARCH_SKILLS_TOOL, PoHeadlessPromptAdmissionError, PoHeadlessStartupReadinessError, PoHeadlessToolBusyError, PoImageGenerationError, PoSessionSetupError, approvedExtensionLayers, dropInvalidImages, invalidImageReason, isPoHeadlessPromptAdmissionError, isPoHeadlessToolBusyError, isPoHeadlessToolModelVisible, isPoImageGenerationError, isPoSessionSetupError, readPoHeadlessHost, readPoHeadlessOwner, requirePoHeadlessHost, sessionExtensionReceipt, toPoHeadlessToolResult } from "./src/schemas/headless.mjs";
|
|
3
3
|
import { sessionEntryToContextMessages } from "./src/services/piMessages/index.mjs";
|
|
4
4
|
import { DEFAULT_COMPACTION_POLICY } from "@earendil-works/pi-durable";
|
|
5
|
-
export { AGENT_SETTLED_ENTRY_TYPE, DEFAULT_COMPACTION_POLICY, PO_HEADLESS_HOST_SERVICE, PO_HEADLESS_OWNER, PO_LOAD_SKILL_TOOL, PO_SEARCH_SKILLS_TOOL, PoHeadlessPromptAdmissionError, PoHeadlessStartupReadinessError, PoHeadlessToolBusyError, PoImageGenerationError, PoSessionSetupError, dropInvalidImages, invalidImageReason, isPoHeadlessPromptAdmissionError, isPoHeadlessToolBusyError, isPoHeadlessToolModelVisible, isPoImageGenerationError, isPoSessionSetupError, readPoHeadlessHost, readPoHeadlessOwner, requirePoHeadlessHost, sessionEntryToContextMessages, toPoHeadlessToolResult };
|
|
5
|
+
export { AGENT_SETTLED_ENTRY_TYPE, DEFAULT_COMPACTION_POLICY, PO_EXTENSIONS_OWNER, PO_EXTENSIONS_STATE, PO_HEADLESS_HOST_SERVICE, PO_HEADLESS_OWNER, PO_LOAD_SKILL_TOOL, PO_SEARCH_SKILLS_TOOL, PoHeadlessPromptAdmissionError, PoHeadlessStartupReadinessError, PoHeadlessToolBusyError, PoImageGenerationError, PoSessionSetupError, approvedExtensionLayers, dropInvalidImages, invalidImageReason, isPoHeadlessPromptAdmissionError, isPoHeadlessToolBusyError, isPoHeadlessToolModelVisible, isPoImageGenerationError, isPoSessionSetupError, readPoHeadlessHost, readPoHeadlessOwner, requirePoHeadlessHost, sessionEntryToContextMessages, sessionExtensionReceipt, toPoHeadlessToolResult };
|
package/dist/headlessHub.cjs
CHANGED
|
@@ -14,13 +14,13 @@ const require_home = require("./src/schemas/home.cjs");
|
|
|
14
14
|
require("./hubChannel.cjs");
|
|
15
15
|
const require_notification = require("./src/schemas/notification.cjs");
|
|
16
16
|
require("./src/schemas/sessionProtocol.cjs");
|
|
17
|
-
const
|
|
18
|
-
const require_index$2 = require("./src/services/editPresence/index.cjs");
|
|
19
|
-
require("./pluginProtocol.cjs");
|
|
20
|
-
const require_index$3 = require("./src/services/serverHost/index.cjs");
|
|
17
|
+
const require_index$2 = require("./src/services/serverHost/index.cjs");
|
|
21
18
|
const require_serverScope = require("./src/server/serverScope.cjs");
|
|
22
19
|
const require_sessionLifecycle = require("./src/schemas/sessionLifecycle.cjs");
|
|
23
20
|
require("./serverPlugin.cjs");
|
|
21
|
+
const require_pluginProtocol = require("./src/schemas/pluginProtocol.cjs");
|
|
22
|
+
const require_index$3 = require("./src/services/editPresence/index.cjs");
|
|
23
|
+
require("./pluginProtocol.cjs");
|
|
24
24
|
const require_index$4 = require("./src/services/sessionGitStatus/index.cjs");
|
|
25
25
|
const require_index$5 = require("./src/services/sessionLifecycle/index.cjs");
|
|
26
26
|
let node_crypto = require("node:crypto");
|
|
@@ -208,7 +208,7 @@ function createHeadlessHub(options) {
|
|
|
208
208
|
if (scope === void 0) {
|
|
209
209
|
scope = openGlobalScope().then(async (global) => {
|
|
210
210
|
const workspace = await require_serverScope.PoServerScope.open("workspace", global);
|
|
211
|
-
const presence = require_index$
|
|
211
|
+
const presence = require_index$3.createEditPresence();
|
|
212
212
|
workspacePresence.set(workspaceId, presence);
|
|
213
213
|
workspace.root.effect(() => () => {
|
|
214
214
|
presence.clear();
|
|
@@ -1140,21 +1140,23 @@ function createHeadlessHub(options) {
|
|
|
1140
1140
|
};
|
|
1141
1141
|
let registered = false;
|
|
1142
1142
|
const root = () => session.workspaceId && workspaces.get(session.workspaceId)?.root || session.cwd;
|
|
1143
|
-
let
|
|
1144
|
-
let
|
|
1143
|
+
let selected;
|
|
1144
|
+
let publishedKey;
|
|
1145
1145
|
const applyCompositions = (force = false) => {
|
|
1146
|
-
const preset =
|
|
1147
|
-
|
|
1146
|
+
const preset = selected?.preset;
|
|
1147
|
+
const extraLayers = selected?.extraLayers ?? [];
|
|
1148
|
+
const key = selected === void 0 ? void 0 : JSON.stringify([preset, extraLayers]);
|
|
1149
|
+
if (!force && key === publishedKey) return false;
|
|
1148
1150
|
let next;
|
|
1149
1151
|
try {
|
|
1150
1152
|
if (publishCompositions) next = publishCompositions();
|
|
1151
|
-
else if (options.publishSessionCompositions && preset !== void 0) next = options.publishSessionCompositions(session.id, root(), preset);
|
|
1153
|
+
else if (options.publishSessionCompositions && preset !== void 0) next = options.publishSessionCompositions(session.id, root(), preset, extraLayers);
|
|
1152
1154
|
else return false;
|
|
1153
1155
|
} catch (error) {
|
|
1154
1156
|
options.onNotice?.(`session ${session.id} plugins${preset === void 0 ? "" : ` for preset "${preset}"`} could not be published (${error instanceof Error ? error.message : String(error)})`);
|
|
1155
1157
|
return false;
|
|
1156
1158
|
}
|
|
1157
|
-
|
|
1159
|
+
publishedKey = key;
|
|
1158
1160
|
const { webComposition, nativeComposition } = next;
|
|
1159
1161
|
if (JSON.stringify([webComposition, nativeComposition]) === JSON.stringify([current.webComposition, current.nativeComposition])) return false;
|
|
1160
1162
|
current = {
|
|
@@ -1190,7 +1192,10 @@ function createHeadlessHub(options) {
|
|
|
1190
1192
|
};
|
|
1191
1193
|
const applySelection = (selection) => {
|
|
1192
1194
|
if (closed || sessions.get(session.id)?.host !== session.host) return;
|
|
1193
|
-
|
|
1195
|
+
selected = {
|
|
1196
|
+
preset: selection.preset,
|
|
1197
|
+
...selection.extraLayers ? { extraLayers: selection.extraLayers } : {}
|
|
1198
|
+
};
|
|
1194
1199
|
const compositionsChanged = applyCompositions();
|
|
1195
1200
|
const profileChanged = applyProfile(selection.profile);
|
|
1196
1201
|
if (!compositionsChanged && !profileChanged) return;
|
|
@@ -1387,7 +1392,7 @@ function createHeadlessHub(options) {
|
|
|
1387
1392
|
};
|
|
1388
1393
|
const key = mountKey(mount);
|
|
1389
1394
|
if (scopeHosts.has(key)) throw new Error(`The '${key}' scope is already served.`);
|
|
1390
|
-
const host = require_index$
|
|
1395
|
+
const host = require_index$2.createPoServerHost({
|
|
1391
1396
|
scope: context.scope,
|
|
1392
1397
|
context: {
|
|
1393
1398
|
...context,
|