@agimon-ai/doompi-core 0.0.1-alpha.113 → 0.0.1-alpha.115
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.cjs.map +1 -1
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/headless.cjs +1 -0
- package/dist/headless.d.mts +2 -2
- package/dist/headless.mjs +2 -2
- package/dist/headlessHub.cjs +1 -1
- package/dist/headlessHub.cjs.map +1 -1
- package/dist/headlessHub.mjs +1 -1
- package/dist/headlessHub.mjs.map +1 -1
- package/dist/headlessServer.d.mts +1 -1
- package/dist/headlessSessionHost.d.mts +3 -1
- package/dist/headlessSessionHost.d.mts.map +1 -1
- package/dist/packageApiServer.d.mts +1 -1
- package/dist/src/pi/piSessionRuntime.cjs +1 -1
- package/dist/src/pi/piSessionRuntime.mjs +1 -1
- package/dist/src/schemas/headless.cjs +7 -0
- package/dist/src/schemas/headless.cjs.map +1 -1
- package/dist/src/schemas/headless.d.mts +7 -0
- package/dist/src/schemas/headless.d.mts.map +1 -1
- package/dist/src/schemas/headless.mjs +7 -1
- package/dist/src/schemas/headless.mjs.map +1 -1
- package/dist/src/schemas/pluginProtocol.cjs.map +1 -1
- package/dist/src/schemas/pluginProtocol.d.mts +2 -0
- package/dist/src/schemas/pluginProtocol.d.mts.map +1 -1
- package/dist/src/schemas/pluginProtocol.mjs.map +1 -1
- package/dist/src/server/directHarnessRuntime.cjs +5 -2
- package/dist/src/server/directHarnessRuntime.cjs.map +1 -1
- package/dist/src/server/directHarnessRuntime.mjs +5 -2
- package/dist/src/server/directHarnessRuntime.mjs.map +1 -1
- package/dist/src/server/headlessProtocol.cjs +6 -1
- package/dist/src/server/headlessProtocol.cjs.map +1 -1
- package/dist/src/server/headlessProtocol.mjs +6 -1
- package/dist/src/server/headlessProtocol.mjs.map +1 -1
- package/dist/src/services/rpcTranscript/index.cjs +4 -2
- package/dist/src/services/rpcTranscript/index.cjs.map +1 -1
- package/dist/src/services/rpcTranscript/index.mjs +4 -2
- package/dist/src/services/rpcTranscript/index.mjs.map +1 -1
- package/dist/src/systems/main/adapters/headlessHost.cjs +19 -3
- package/dist/src/systems/main/adapters/headlessHost.cjs.map +1 -1
- package/dist/src/systems/main/adapters/headlessHost.d.mts +3 -0
- package/dist/src/systems/main/adapters/headlessHost.d.mts.map +1 -1
- package/dist/src/systems/main/adapters/headlessHost.mjs +20 -4
- package/dist/src/systems/main/adapters/headlessHost.mjs.map +1 -1
- package/dist/src/systems/main/adapters/headlessSessionHost.cjs +46 -8
- package/dist/src/systems/main/adapters/headlessSessionHost.cjs.map +1 -1
- package/dist/src/systems/main/adapters/headlessSessionHost.d.mts.map +1 -1
- package/dist/src/systems/main/adapters/headlessSessionHost.mjs +47 -9
- package/dist/src/systems/main/adapters/headlessSessionHost.mjs.map +1 -1
- package/dist/src/systems/main/types/headlessHost.d.mts +2 -1
- package/dist/src/systems/main/types/headlessHost.d.mts.map +1 -1
- package/dist/src/testing/pi/testHost.cjs +1 -0
- package/dist/src/testing/pi/testHost.cjs.map +1 -1
- package/dist/src/testing/pi/testHost.mjs +1 -0
- package/dist/src/testing/pi/testHost.mjs.map +1 -1
- package/dist/src/types/server/sessionToolSurface.d.mts +1 -1
- package/dist/src/web/types/webPlugin.d.mts +3 -2
- package/dist/src/web/types/webPlugin.d.mts.map +1 -1
- package/package.json +18 -18
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DoomNotificationRequest } from "./notification.mjs";
|
|
2
|
+
import { SessionToolSurface } from "../types/server/sessionToolSurface.mjs";
|
|
2
3
|
import { DoomSessionContext } from "./hubChannel.mjs";
|
|
3
4
|
import { DoomServerBundleEntry } from "./serverBundle.mjs";
|
|
4
5
|
import { Static, TSchema } from "typebox";
|
|
@@ -67,6 +68,7 @@ export declare function toDoomHeadlessToolResult(result: {
|
|
|
67
68
|
readonly content: DoomHeadlessContent[];
|
|
68
69
|
readonly details?: unknown;
|
|
69
70
|
readonly structuredContent?: unknown;
|
|
71
|
+
readonly _meta?: CallToolResult['_meta'];
|
|
70
72
|
readonly isError?: boolean;
|
|
71
73
|
}): DoomHeadlessToolResult;
|
|
72
74
|
export interface DoomHeadlessClientRequest {
|
|
@@ -278,6 +280,7 @@ export type DoomHeadlessHookEvent<E extends DoomHeadlessEventName> = E extends '
|
|
|
278
280
|
model: {
|
|
279
281
|
provider: string;
|
|
280
282
|
id: string;
|
|
283
|
+
api?: string;
|
|
281
284
|
};
|
|
282
285
|
payload: unknown;
|
|
283
286
|
} : E extends 'session_before_compact' ? {
|
|
@@ -343,6 +346,8 @@ export interface DoomHeadlessCapability {
|
|
|
343
346
|
readonly discoverable: boolean;
|
|
344
347
|
readonly reason?: 'inactive' | 'restricted' | 'shadowed' | 'unavailable' | 'not-discoverable';
|
|
345
348
|
}
|
|
349
|
+
/** Visibility controls model discovery only, never admission for external execution. */
|
|
350
|
+
export declare function isDoomHeadlessToolModelVisible(tool: Pick<DoomHeadlessTool, '_meta'>): boolean;
|
|
346
351
|
export interface DoomHeadlessCapabilitySnapshot {
|
|
347
352
|
readonly revision: number;
|
|
348
353
|
readonly ready: boolean;
|
|
@@ -356,6 +361,8 @@ export interface DoomHeadlessCapabilitySnapshot {
|
|
|
356
361
|
export declare const DOOM_LOAD_SKILL_TOOL = "load_skill";
|
|
357
362
|
export interface DoomHeadlessHostService {
|
|
358
363
|
readonly context: DoomHeadlessExecutionContext;
|
|
364
|
+
/** Admitted external execution, sharing native hooks, restrictions and session lifetime. */
|
|
365
|
+
readonly toolSurface?: Pick<SessionToolSurface, 'readSurface' | 'invokeTool'>;
|
|
359
366
|
/** The instructions of an applied skill by exact name, or undefined when none is applied. */
|
|
360
367
|
readSkill(name: string): string | undefined;
|
|
361
368
|
changeSelection(change: DoomHeadlessSelectionChange): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headless.d.mts","names":[],"sources":["../../../src/schemas/headless.ts"],"mappings":"
|
|
1
|
+
{"version":3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,uBAAuB;;;iBAKnD;EACf,OAAO;EACP;EACA,MAAM,SAAS,6CAA6C,iBAAiB,qBAAqB;;;iBAInF;WACN;WACA;WACA;WACA,OAAO;WACP;WACA;WACA;;;wBAIK,+BAA+B,MAAM,KAAK;iBAKzC;WACN;WACA;WACA,uBAAuB;;;;;;;qBAQrB;iBAEI;WACN,SAAS;;WAET,cAAc,KAAK;;EAE5B,UAAU;EACV,gBAAgB,QAAQ,8BAA8B;EACtD,aAAa;EACb,mBAAmB,WAAW,WAAW,iCAAiC;;EAE1E,uBAAuB;EACvB,wBAAwB,aAAa,8BAA8B;EACnE,aAAa,oBAAoB,SAAS,MAAM,iBAAiB,eAAe;EAChF,iBAAiB,UAAU,uBAAuB;EAClD,gBAAgB,SAAS,sBAAsB;EAC/C,aAAa,MAAM,mBAAmB;EACtC,iBAAiB,UAAU,uBAAuB;;;YAIxC;IACR,sBAAsB;;;wBAIV,qBAAqB,SAAS,UAAU;wBAIxC,wBAAwB,SAAS,UAAU"}
|
|
@@ -26,10 +26,16 @@ function toDoomHeadlessToolResult(result) {
|
|
|
26
26
|
return {
|
|
27
27
|
content: result.content,
|
|
28
28
|
details: result.details,
|
|
29
|
+
...result._meta === void 0 ? {} : { _meta: result._meta },
|
|
29
30
|
...typeof structuredContent === "object" && structuredContent !== null && !Array.isArray(structuredContent) ? { structuredContent } : {},
|
|
30
31
|
...result.isError === void 0 ? {} : { isError: result.isError }
|
|
31
32
|
};
|
|
32
33
|
}
|
|
34
|
+
/** Visibility controls model discovery only, never admission for external execution. */
|
|
35
|
+
function isDoomHeadlessToolModelVisible(tool) {
|
|
36
|
+
const visibility = tool._meta?.ui?.visibility;
|
|
37
|
+
return visibility === void 0 || visibility.includes("model");
|
|
38
|
+
}
|
|
33
39
|
/** Registrations inherit package ownership from the caller's Cordis facet. */
|
|
34
40
|
/**
|
|
35
41
|
* The tool a server session loads skills through. When a session carries it, the prompt lists
|
|
@@ -45,6 +51,6 @@ function requireDoomHeadlessHost(context) {
|
|
|
45
51
|
return host;
|
|
46
52
|
}
|
|
47
53
|
//#endregion
|
|
48
|
-
export { DOOM_HEADLESS_HOST_SERVICE, DOOM_HEADLESS_OWNER, DOOM_LOAD_SKILL_TOOL, DoomHeadlessPromptAdmissionError, isDoomHeadlessPromptAdmissionError, readDoomHeadlessHost, readDoomHeadlessOwner, requireDoomHeadlessHost, toDoomHeadlessToolResult };
|
|
54
|
+
export { DOOM_HEADLESS_HOST_SERVICE, DOOM_HEADLESS_OWNER, DOOM_LOAD_SKILL_TOOL, DoomHeadlessPromptAdmissionError, isDoomHeadlessPromptAdmissionError, isDoomHeadlessToolModelVisible, readDoomHeadlessHost, readDoomHeadlessOwner, requireDoomHeadlessHost, toDoomHeadlessToolResult };
|
|
49
55
|
|
|
50
56
|
//# sourceMappingURL=headless.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headless.mjs","names":[],"sources":["../../../src/schemas/headless.ts"],"sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\nimport type { ThinkingLevel } from '@earendil-works/pi-agent-core';\nimport type { CallToolResult, Tool } from '@modelcontextprotocol/server';\nimport type { Static, TSchema } from 'typebox';\n\nimport type { DoomSessionContext } from './hubChannel';\nimport type { DoomNotificationRequest } from './notification';\nimport type { DoomServerBundleEntry } from './serverBundle';\n\n/** Session-only contributions. This is not a Pi ExtensionAPI or a TUI adapter. */\nexport const DOOM_HEADLESS_HOST_SERVICE = 'doom/headless-host';\nexport const DOOM_HEADLESS_OWNER = Symbol.for('doom/headless-owner');\n\nconst PROMPT_ADMISSION_ERROR = 'DoomHeadlessPromptAdmissionError';\n\n/** Admission is a host boundary, not an advisory facet-hook failure. */\nexport class DoomHeadlessPromptAdmissionError extends Error {\n constructor(cause: unknown) {\n super(cause instanceof Error ? cause.message : String(cause), { cause });\n this.name = PROMPT_ADMISSION_ERROR;\n }\n}\n\n/** Error identity must survive independently bundled server and extension graphs. */\nexport function isDoomHeadlessPromptAdmissionError(error: unknown): boolean {\n return error instanceof Error && error.name === PROMPT_ADMISSION_ERROR;\n}\nexport interface DoomHeadlessSelection {\n readonly majorMode: string;\n readonly activeLayers: readonly string[];\n readonly domains: readonly string[];\n readonly profile?: string;\n /** Feature-owned activation sets, keyed by the contributing capability. */\n readonly state?: Readonly<Record<string, readonly string[]>>;\n}\n\n/** One package-owned selection transition. Server facets change exactly one axis per operation. */\nexport type DoomHeadlessSelectionChange =\n | { readonly axis: 'majorMode'; readonly majorMode: string }\n | { readonly axis: 'domains'; readonly domains: readonly string[] }\n | { readonly axis: 'profile'; readonly profile?: string }\n | { readonly axis: 'state'; readonly key: string; readonly values: readonly string[] };\n\nexport function readDoomHeadlessOwner(context: Context): DoomServerBundleEntry | undefined {\n return (context as Context & { [DOOM_HEADLESS_OWNER]?: DoomServerBundleEntry })[DOOM_HEADLESS_OWNER];\n}\n\nexport interface DoomHeadlessRegistration {\n dispose(): void;\n}\n\nexport type DoomHeadlessContent = { type: 'text'; text: string } | { type: 'image'; data: string; mimeType: string };\n\nexport interface DoomHeadlessToolResult {\n content: DoomHeadlessContent[];\n /** Public MCP result data. Internal renderer details are not a remote result contract. */\n structuredContent?: Record<string, unknown>;\n /** Component-only MCP metadata, never inferred from internal renderer details. */\n _meta?: CallToolResult['_meta'];\n details?: unknown;\n isError?: boolean;\n}\n\n/**\n * Narrows a Pi tool result to the headless contract. Pi types `structuredContent` as any JSON\n * value, while MCP only accepts an object, so anything else is dropped rather than forwarded.\n */\nexport function toDoomHeadlessToolResult(result: {\n readonly content: DoomHeadlessContent[];\n readonly details?: unknown;\n readonly structuredContent?: unknown;\n readonly isError?: boolean;\n}): DoomHeadlessToolResult {\n const { structuredContent } = result;\n return {\n content: result.content,\n details: result.details,\n ...(typeof structuredContent === 'object' && structuredContent !== null && !Array.isArray(structuredContent)\n ? { structuredContent: structuredContent as Record<string, unknown> }\n : {}),\n ...(result.isError === undefined ? {} : { isError: result.isError }),\n };\n}\n\nexport interface DoomHeadlessClientRequest {\n kind: 'confirm' | 'select' | 'input';\n title: string;\n message?: string;\n options?: readonly { label: string; description?: string; value: string }[];\n initialValue?: string;\n multiline?: boolean;\n}\n\nexport interface DoomHeadlessClient {\n /**\n * Operator-facing surface only: the body is flattened to one line and capped at 4096 characters\n * by schemas/notification.ts:73-83, and the model never sees it. Use session.admitPrompt to\n * reach the model.\n */\n notify(request: DoomNotificationRequest): void | Promise<void>;\n request(request: DoomHeadlessClientRequest, signal?: AbortSignal): Promise<unknown>;\n setStatus(source: string, text: string | undefined): void;\n appendComposerText?(text: string): void;\n}\n\nexport interface DoomHeadlessModelSettings {\n model?: { provider: string; id: string };\n thinkingLevel: ThinkingLevel;\n}\n\nexport interface DoomHeadlessSession {\n readModelSettings?(): Promise<DoomHeadlessModelSettings>;\n setFastMode?(enabled: boolean): Promise<void>;\n setModelSettings?(settings: Partial<DoomHeadlessModelSettings>): Promise<void>;\n /** Query durable history on demand; hosts do not retain the entire transcript. */\n entries(query?: {\n type?: 'custom' | 'message';\n customType?: string;\n limit?: number;\n }): readonly Record<string, unknown>[] | Promise<readonly Record<string, unknown>[]>;\n appendCustomEntry(type: string, data: unknown): Promise<void>;\n /**\n * Delivers operator input through prompt preflight and awaits its turn.\n * Environmental input uses admitPrompt with origin omitted instead.\n * An idle agent is woken; busy delivery uses Durable steering or follow-up.\n */\n prompt(text: string, delivery?: 'prompt' | 'steer' | 'followUp'): Promise<void>;\n /**\n * Admits input without awaiting its turn. Environmental input omits origin and never\n * changes the operator queue. Operator origin uses prompt preflight, including voice\n * capture; 'interrupt' cancels the active run and admits operator input while preserving\n * retained queued work. Environmental callers may reuse requestId when retrying the same input.\n */\n admitPrompt?(\n text: string,\n delivery?: 'prompt' | 'steer' | 'followUp' | 'interrupt',\n origin?: 'operator',\n requestId?: string,\n ): Promise<void>;\n abort(): Promise<void>;\n compact(instructions?: string): Promise<void>;\n activity(): Promise<{ hasPendingMessages: boolean; isIdle: boolean }>;\n /** Renames the durable session and publishes the updated title to presentation clients. */\n setName?(name: string): Promise<void>;\n /** Capture the current persisted branch for an in-process child fork. */\n forkSource?(): Promise<{ kind: 'v4-fork'; sessionFile: string; branch: string; entryId?: string }>;\n}\n\n/** A grant-filtered skill view available only during one remote MCP tool invocation. */\nexport interface DoomMcpSkillAccess {\n list(): Promise<readonly { name: string; description: string }[]>;\n read(name: string): Promise<string>;\n}\n\n/** A stateless auxiliary request. These tools are private to this request, never registered on the agent. */\nexport interface DoomHeadlessToolCompletionRequest {\n systemPrompt: string;\n input: string;\n maxTokens: number;\n cacheRetention?: 'none' | 'short' | 'long';\n signal?: AbortSignal;\n tools: readonly Pick<DoomHeadlessTool, 'name' | 'description' | 'parameters'>[];\n}\n\nexport interface DoomHeadlessToolCompletionResult {\n toolCalls: readonly { id: string; name: string; arguments: unknown }[];\n usage: { totalTokens: number };\n}\n\nexport interface DoomHeadlessExecutionContext {\n readonly cwd: string;\n /** The checkout the session runs in, distinct from the tool execution directory. */\n readonly repoRoot: string;\n readonly sessionId: string;\n /** The session's baseline context, when its host knows its workspace. */\n readonly sessionContext?: DoomSessionContext;\n /** Immutable session configuration. Facets must not read or mutate process.env. */\n readonly environment: Readonly<Record<string, string | undefined>>;\n readonly client: DoomHeadlessClient;\n readonly session: DoomHeadlessSession;\n readonly model?: { provider: string; id: string };\n /** Operation cancellation, supplied only for an active invocation. */\n readonly signal?: AbortSignal;\n readonly textCompletion?: {\n available(reference: string): boolean;\n complete(\n reference: string,\n request: {\n systemPrompt: string;\n input: string;\n maxTokens: number;\n cacheRetention?: 'none' | 'short' | 'long';\n signal?: AbortSignal;\n },\n ): Promise<string>;\n };\n readonly toolCompletion?: {\n complete(reference: string, request: DoomHeadlessToolCompletionRequest): Promise<DoomHeadlessToolCompletionResult>;\n };\n readonly selection: DoomHeadlessSelection;\n /** Present only while an authenticated remote MCP tool is running. */\n readonly mcpSkills?: DoomMcpSkillAccess;\n shutdown(): void;\n}\n\n/** Conditions narrow an eligible owner's contributions; they can never restore a disabled owner. */\nexport interface DoomHeadlessCondition {\n state?: Readonly<Record<string, string>>;\n attribution?: { kind: 'minor' | 'domain'; mode: string; label?: string };\n domain?: string;\n}\n\nexport interface DoomHeadlessToolRestriction {\n when?: DoomHeadlessCondition;\n /** Optional capability ceiling. An empty list disables every tool. */\n allowedTools?: readonly string[];\n /**\n * Narrow exclusions without disabling unrelated tools. Exclude a tool your package owns, or a\n * specific foreign tool the mode exists to withdraw. Never enumerate an allowlist here.\n */\n excludedTools?: readonly string[];\n}\n\nexport interface DoomHeadlessTool<TParameters extends TSchema = TSchema> {\n when?: DoomHeadlessCondition;\n name: string;\n label?: string;\n description: string;\n parameters: TParameters;\n annotations?: Tool['annotations'];\n outputSchema?: Tool['outputSchema'];\n /** Remote presentation only. Component tool access must be explicitly opted into. */\n _meta?: Tool['_meta'] & {\n ui?: {\n resourceUri?: string;\n visibility?: ('model' | 'app')[];\n };\n };\n promptSnippet?: string;\n promptGuidelines?: readonly string[];\n executionMode?: 'parallel' | 'serial';\n execute(\n toolCallId: string,\n parameters: Static<TParameters>,\n signal: AbortSignal | undefined,\n onUpdate: ((result: DoomHeadlessToolResult) => void) | undefined,\n context: DoomHeadlessExecutionContext,\n ): Promise<DoomHeadlessToolResult>;\n}\n\n/**\n * One package contribution to the session's resource surface.\n *\n * `kind` decides what the model is billed for, and the difference is large:\n * - `context` is EAGER. `read()` runs on every prompt build and the text is pasted\n * into the system prompt verbatim. Reserve it for small live session state that\n * exists nowhere on disk. Never use it for a file the package ships: a README\n * registered this way costs its full length on every single turn.\n * - `skill` is LAZY. Only `name`, `description` and `path` reach the prompt; the\n * agent reads the file itself when the description matches the task.\n * - `prompt` is inert until the user invokes it by name.\n *\n * The rule in one line: if it is a file the package ships, it is a `skill`.\n */\nexport interface DoomHeadlessResource {\n when?: DoomHeadlessCondition;\n name: string;\n /** Model-visible selection signal. A `skill` without one tells the agent nothing. */\n description?: string;\n /** Absolute path of the file `read()` returns, so an advertised skill is one the agent can open. */\n path?: string;\n kind: 'prompt' | 'skill' | 'context';\n read(context: DoomHeadlessExecutionContext): string | Promise<string>;\n}\n\nexport interface DoomHeadlessCommand {\n when?: DoomHeadlessCondition;\n name: string;\n description: string;\n execute(args: string, context: DoomHeadlessExecutionContext): void | Promise<void>;\n}\n\nexport type DoomHeadlessEventName =\n | 'session_start'\n | 'session_shutdown'\n | 'session_tree'\n | 'before_agent_start'\n | 'agent_start'\n | 'agent_settled'\n | 'turn_start'\n | 'turn_end'\n | 'context'\n | 'before_provider_request'\n | 'message_start'\n | 'message_update'\n | 'message_end'\n | 'tool_call'\n | 'tool_execution_start'\n | 'tool_execution_update'\n | 'tool_execution_end'\n | 'tool_result'\n | 'model_select'\n | 'session_before_compact'\n | 'session_compact';\n\nexport type DoomHeadlessHookEvent<E extends DoomHeadlessEventName> = E extends 'before_provider_request'\n ? { lane: string; runId: string; model: { provider: string; id: string }; payload: unknown }\n : E extends 'session_before_compact'\n ? { reason: string; preparation: unknown; instructions?: string; customInstructions?: string }\n : E extends 'model_select'\n ? { model: { provider: string; id: string } }\n : Readonly<Record<string, unknown>>;\n\nexport interface DoomHeadlessCompactionResult {\n summary: string;\n tokensBefore: number;\n retainedTail: Record<string, unknown>[];\n usage?: Record<string, unknown>;\n details?: unknown;\n}\n\nexport type DoomHeadlessHookResult<E extends DoomHeadlessEventName> = E extends 'before_provider_request'\n ? { payload: unknown } | void\n : E extends 'session_before_compact'\n ? { cancel?: boolean; decline?: boolean; compaction?: DoomHeadlessCompactionResult } | void\n : E extends 'context'\n ? { messages?: unknown[]; systemPrompt?: string } | void\n : E extends 'before_agent_start'\n ? { systemPrompt?: string } | void\n : E extends 'tool_call'\n ? { args?: Record<string, unknown>; block?: { reason: string; terminate?: boolean } } | void\n : E extends 'tool_result'\n ? {\n content?: DoomHeadlessContent[];\n details?: unknown;\n isError?: boolean;\n usage?: Record<string, unknown>;\n terminate?: boolean;\n } | void\n : unknown;\n\nexport type DoomHeadlessHook<E extends DoomHeadlessEventName = DoomHeadlessEventName> = E extends DoomHeadlessEventName\n ? {\n when?: DoomHeadlessCondition;\n event: E;\n handle(\n event: Readonly<DoomHeadlessHookEvent<E>>,\n context: DoomHeadlessExecutionContext,\n ): DoomHeadlessHookResult<E> | Promise<DoomHeadlessHookResult<E>>;\n }\n : never;\n\n/** A retained facet can register activity without starting disabled watchers or services. */\nexport interface DoomHeadlessActivity {\n when?: DoomHeadlessCondition;\n name: string;\n start(context: DoomHeadlessExecutionContext): (() => void | Promise<void>) | Promise<() => void | Promise<void>>;\n}\n\n/** Read-only metadata for the currently applied session, never executable declarations or resource bodies. */\nexport interface DoomHeadlessCapability {\n readonly source: string;\n readonly name: string;\n readonly kind: 'tool' | 'skill';\n readonly when?: DoomHeadlessCondition;\n readonly active: boolean;\n readonly discoverable: boolean;\n readonly reason?: 'inactive' | 'restricted' | 'shadowed' | 'unavailable' | 'not-discoverable';\n}\n\nexport interface DoomHeadlessCapabilitySnapshot {\n readonly revision: number;\n readonly ready: boolean;\n readonly capabilities: readonly DoomHeadlessCapability[];\n}\n\n/** Registrations inherit package ownership from the caller's Cordis facet. */\n/**\n * The tool a server session loads skills through. When a session carries it, the prompt lists\n * every skill by name and points here, so a skill needs no file the agent could read.\n */\nexport const DOOM_LOAD_SKILL_TOOL = 'load_skill';\n\nexport interface DoomHeadlessHostService {\n readonly context: DoomHeadlessExecutionContext;\n /** The instructions of an applied skill by exact name, or undefined when none is applied. */\n readSkill(name: string): string | undefined;\n changeSelection(change: DoomHeadlessSelectionChange): Promise<void>;\n assertActive(source?: string): void;\n subscribeSelection(listener: (selection: DoomHeadlessSelection) => void | Promise<void>): () => void;\n /** Inspect only a coherently applied generation. A transition returns ready=false and no partial inventory. */\n inspectCapabilities(): DoomHeadlessCapabilitySnapshot;\n registerToolRestriction(restriction: DoomHeadlessToolRestriction): DoomHeadlessRegistration;\n registerTool<TParameters extends TSchema>(tool: DoomHeadlessTool<TParameters>): DoomHeadlessRegistration;\n registerResource(resource: DoomHeadlessResource): DoomHeadlessRegistration;\n registerCommand(command: DoomHeadlessCommand): DoomHeadlessRegistration;\n registerHook(hook: DoomHeadlessHook): DoomHeadlessRegistration;\n registerActivity(activity: DoomHeadlessActivity): DoomHeadlessRegistration;\n}\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'doom/headless-host': DoomHeadlessHostService;\n }\n}\n\nexport function readDoomHeadlessHost(context: Context): DoomHeadlessHostService | undefined {\n return context.get(DOOM_HEADLESS_HOST_SERVICE) as DoomHeadlessHostService | undefined;\n}\n\nexport function requireDoomHeadlessHost(context: Context): DoomHeadlessHostService {\n const host = readDoomHeadlessHost(context);\n if (!host) throw new Error('This contribution requires the Doom headless session host.');\n return host;\n}\n"],"mappings":";;AAUA,MAAa,6BAA6B;AAC1C,MAAa,sBAAsB,OAAO,IAAI,qBAAqB;AAEnE,MAAM,yBAAyB;;AAG/B,IAAa,mCAAb,cAAsD,MAAM;CAC1D,YAAY,OAAgB;EAC1B,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAAG,EAAE,MAAM,CAAC;EACvE,KAAK,OAAO;CACd;AACF;;AAGA,SAAgB,mCAAmC,OAAyB;CAC1E,OAAO,iBAAiB,SAAS,MAAM,SAAS;AAClD;AAiBA,SAAgB,sBAAsB,SAAqD;CACzF,OAAQ,QAAwE;AAClF;;;;;AAsBA,SAAgB,yBAAyB,QAKd;CACzB,MAAM,EAAE,sBAAsB;CAC9B,OAAO;EACL,SAAS,OAAO;EAChB,SAAS,OAAO;EAChB,GAAI,OAAO,sBAAsB,YAAY,sBAAsB,QAAQ,CAAC,MAAM,QAAQ,iBAAiB,IACvG,EAAqB,kBAA6C,IAClE,CAAC;EACL,GAAI,OAAO,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,OAAO,QAAQ;CACpE;AACF;;;;;;AA2SA,MAAa,uBAAuB;AAyBpC,SAAgB,qBAAqB,SAAuD;CAC1F,OAAO,QAAQ,IAAI,0BAA0B;AAC/C;AAEA,SAAgB,wBAAwB,SAA2C;CACjF,MAAM,OAAO,qBAAqB,OAAO;CACzC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,4DAA4D;CACvF,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"headless.mjs","names":[],"sources":["../../../src/schemas/headless.ts"],"sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\nimport type { ThinkingLevel } from '@earendil-works/pi-agent-core';\nimport type { CallToolResult, Tool } from '@modelcontextprotocol/server';\nimport type { Static, TSchema } from 'typebox';\n\nimport type { SessionToolSurface } from '../types/server/sessionToolSurface';\nimport type { DoomSessionContext } from './hubChannel';\nimport type { DoomNotificationRequest } from './notification';\nimport type { DoomServerBundleEntry } from './serverBundle';\n\n/** Session-only contributions. This is not a Pi ExtensionAPI or a TUI adapter. */\nexport const DOOM_HEADLESS_HOST_SERVICE = 'doom/headless-host';\nexport const DOOM_HEADLESS_OWNER = Symbol.for('doom/headless-owner');\n\nconst PROMPT_ADMISSION_ERROR = 'DoomHeadlessPromptAdmissionError';\n\n/** Admission is a host boundary, not an advisory facet-hook failure. */\nexport class DoomHeadlessPromptAdmissionError extends Error {\n constructor(cause: unknown) {\n super(cause instanceof Error ? cause.message : String(cause), { cause });\n this.name = PROMPT_ADMISSION_ERROR;\n }\n}\n\n/** Error identity must survive independently bundled server and extension graphs. */\nexport function isDoomHeadlessPromptAdmissionError(error: unknown): boolean {\n return error instanceof Error && error.name === PROMPT_ADMISSION_ERROR;\n}\nexport interface DoomHeadlessSelection {\n readonly majorMode: string;\n readonly activeLayers: readonly string[];\n readonly domains: readonly string[];\n readonly profile?: string;\n /** Feature-owned activation sets, keyed by the contributing capability. */\n readonly state?: Readonly<Record<string, readonly string[]>>;\n}\n\n/** One package-owned selection transition. Server facets change exactly one axis per operation. */\nexport type DoomHeadlessSelectionChange =\n | { readonly axis: 'majorMode'; readonly majorMode: string }\n | { readonly axis: 'domains'; readonly domains: readonly string[] }\n | { readonly axis: 'profile'; readonly profile?: string }\n | { readonly axis: 'state'; readonly key: string; readonly values: readonly string[] };\n\nexport function readDoomHeadlessOwner(context: Context): DoomServerBundleEntry | undefined {\n return (context as Context & { [DOOM_HEADLESS_OWNER]?: DoomServerBundleEntry })[DOOM_HEADLESS_OWNER];\n}\n\nexport interface DoomHeadlessRegistration {\n dispose(): void;\n}\n\nexport type DoomHeadlessContent = { type: 'text'; text: string } | { type: 'image'; data: string; mimeType: string };\n\nexport interface DoomHeadlessToolResult {\n content: DoomHeadlessContent[];\n /** Public MCP result data. Internal renderer details are not a remote result contract. */\n structuredContent?: Record<string, unknown>;\n /** Component-only MCP metadata, never inferred from internal renderer details. */\n _meta?: CallToolResult['_meta'];\n details?: unknown;\n isError?: boolean;\n}\n\n/**\n * Narrows a Pi tool result to the headless contract. Pi types `structuredContent` as any JSON\n * value, while MCP only accepts an object, so anything else is dropped rather than forwarded.\n */\nexport function toDoomHeadlessToolResult(result: {\n readonly content: DoomHeadlessContent[];\n readonly details?: unknown;\n readonly structuredContent?: unknown;\n readonly _meta?: CallToolResult['_meta'];\n readonly isError?: boolean;\n}): DoomHeadlessToolResult {\n const { structuredContent } = result;\n return {\n content: result.content,\n details: result.details,\n ...(result._meta === undefined ? {} : { _meta: result._meta }),\n ...(typeof structuredContent === 'object' && structuredContent !== null && !Array.isArray(structuredContent)\n ? { structuredContent: structuredContent as Record<string, unknown> }\n : {}),\n ...(result.isError === undefined ? {} : { isError: result.isError }),\n };\n}\n\nexport interface DoomHeadlessClientRequest {\n kind: 'confirm' | 'select' | 'input';\n title: string;\n message?: string;\n options?: readonly { label: string; description?: string; value: string }[];\n initialValue?: string;\n multiline?: boolean;\n}\n\nexport interface DoomHeadlessClient {\n /**\n * Operator-facing surface only: the body is flattened to one line and capped at 4096 characters\n * by schemas/notification.ts:73-83, and the model never sees it. Use session.admitPrompt to\n * reach the model.\n */\n notify(request: DoomNotificationRequest): void | Promise<void>;\n request(request: DoomHeadlessClientRequest, signal?: AbortSignal): Promise<unknown>;\n setStatus(source: string, text: string | undefined): void;\n appendComposerText?(text: string): void;\n}\n\nexport interface DoomHeadlessModelSettings {\n model?: { provider: string; id: string };\n thinkingLevel: ThinkingLevel;\n}\n\nexport interface DoomHeadlessSession {\n readModelSettings?(): Promise<DoomHeadlessModelSettings>;\n setFastMode?(enabled: boolean): Promise<void>;\n setModelSettings?(settings: Partial<DoomHeadlessModelSettings>): Promise<void>;\n /** Query durable history on demand; hosts do not retain the entire transcript. */\n entries(query?: {\n type?: 'custom' | 'message';\n customType?: string;\n limit?: number;\n }): readonly Record<string, unknown>[] | Promise<readonly Record<string, unknown>[]>;\n appendCustomEntry(type: string, data: unknown): Promise<void>;\n /**\n * Delivers operator input through prompt preflight and awaits its turn.\n * Environmental input uses admitPrompt with origin omitted instead.\n * An idle agent is woken; busy delivery uses Durable steering or follow-up.\n */\n prompt(text: string, delivery?: 'prompt' | 'steer' | 'followUp'): Promise<void>;\n /**\n * Admits input without awaiting its turn. Environmental input omits origin and never\n * changes the operator queue. Operator origin uses prompt preflight, including voice\n * capture; 'interrupt' cancels the active run and admits operator input while preserving\n * retained queued work. Environmental callers may reuse requestId when retrying the same input.\n */\n admitPrompt?(\n text: string,\n delivery?: 'prompt' | 'steer' | 'followUp' | 'interrupt',\n origin?: 'operator',\n requestId?: string,\n ): Promise<void>;\n abort(): Promise<void>;\n compact(instructions?: string): Promise<void>;\n activity(): Promise<{ hasPendingMessages: boolean; isIdle: boolean }>;\n /** Renames the durable session and publishes the updated title to presentation clients. */\n setName?(name: string): Promise<void>;\n /** Capture the current persisted branch for an in-process child fork. */\n forkSource?(): Promise<{ kind: 'v4-fork'; sessionFile: string; branch: string; entryId?: string }>;\n}\n\n/** A grant-filtered skill view available only during one remote MCP tool invocation. */\nexport interface DoomMcpSkillAccess {\n list(): Promise<readonly { name: string; description: string }[]>;\n read(name: string): Promise<string>;\n}\n\n/** A stateless auxiliary request. These tools are private to this request, never registered on the agent. */\nexport interface DoomHeadlessToolCompletionRequest {\n systemPrompt: string;\n input: string;\n maxTokens: number;\n cacheRetention?: 'none' | 'short' | 'long';\n signal?: AbortSignal;\n tools: readonly Pick<DoomHeadlessTool, 'name' | 'description' | 'parameters'>[];\n}\n\nexport interface DoomHeadlessToolCompletionResult {\n toolCalls: readonly { id: string; name: string; arguments: unknown }[];\n usage: { totalTokens: number };\n}\n\nexport interface DoomHeadlessExecutionContext {\n readonly cwd: string;\n /** The checkout the session runs in, distinct from the tool execution directory. */\n readonly repoRoot: string;\n readonly sessionId: string;\n /** The session's baseline context, when its host knows its workspace. */\n readonly sessionContext?: DoomSessionContext;\n /** Immutable session configuration. Facets must not read or mutate process.env. */\n readonly environment: Readonly<Record<string, string | undefined>>;\n readonly client: DoomHeadlessClient;\n readonly session: DoomHeadlessSession;\n readonly model?: { provider: string; id: string };\n /** Operation cancellation, supplied only for an active invocation. */\n readonly signal?: AbortSignal;\n readonly textCompletion?: {\n available(reference: string): boolean;\n complete(\n reference: string,\n request: {\n systemPrompt: string;\n input: string;\n maxTokens: number;\n cacheRetention?: 'none' | 'short' | 'long';\n signal?: AbortSignal;\n },\n ): Promise<string>;\n };\n readonly toolCompletion?: {\n complete(reference: string, request: DoomHeadlessToolCompletionRequest): Promise<DoomHeadlessToolCompletionResult>;\n };\n readonly selection: DoomHeadlessSelection;\n /** Present only while an authenticated remote MCP tool is running. */\n readonly mcpSkills?: DoomMcpSkillAccess;\n shutdown(): void;\n}\n\n/** Conditions narrow an eligible owner's contributions; they can never restore a disabled owner. */\nexport interface DoomHeadlessCondition {\n state?: Readonly<Record<string, string>>;\n attribution?: { kind: 'minor' | 'domain'; mode: string; label?: string };\n domain?: string;\n}\n\nexport interface DoomHeadlessToolRestriction {\n when?: DoomHeadlessCondition;\n /** Optional capability ceiling. An empty list disables every tool. */\n allowedTools?: readonly string[];\n /**\n * Narrow exclusions without disabling unrelated tools. Exclude a tool your package owns, or a\n * specific foreign tool the mode exists to withdraw. Never enumerate an allowlist here.\n */\n excludedTools?: readonly string[];\n}\n\nexport interface DoomHeadlessTool<TParameters extends TSchema = TSchema> {\n when?: DoomHeadlessCondition;\n name: string;\n label?: string;\n description: string;\n parameters: TParameters;\n annotations?: Tool['annotations'];\n outputSchema?: Tool['outputSchema'];\n /** Remote presentation only. Component tool access must be explicitly opted into. */\n _meta?: Tool['_meta'] & {\n ui?: {\n resourceUri?: string;\n visibility?: ('model' | 'app')[];\n };\n };\n promptSnippet?: string;\n promptGuidelines?: readonly string[];\n executionMode?: 'parallel' | 'serial';\n execute(\n toolCallId: string,\n parameters: Static<TParameters>,\n signal: AbortSignal | undefined,\n onUpdate: ((result: DoomHeadlessToolResult) => void) | undefined,\n context: DoomHeadlessExecutionContext,\n ): Promise<DoomHeadlessToolResult>;\n}\n\n/**\n * One package contribution to the session's resource surface.\n *\n * `kind` decides what the model is billed for, and the difference is large:\n * - `context` is EAGER. `read()` runs on every prompt build and the text is pasted\n * into the system prompt verbatim. Reserve it for small live session state that\n * exists nowhere on disk. Never use it for a file the package ships: a README\n * registered this way costs its full length on every single turn.\n * - `skill` is LAZY. Only `name`, `description` and `path` reach the prompt; the\n * agent reads the file itself when the description matches the task.\n * - `prompt` is inert until the user invokes it by name.\n *\n * The rule in one line: if it is a file the package ships, it is a `skill`.\n */\nexport interface DoomHeadlessResource {\n when?: DoomHeadlessCondition;\n name: string;\n /** Model-visible selection signal. A `skill` without one tells the agent nothing. */\n description?: string;\n /** Absolute path of the file `read()` returns, so an advertised skill is one the agent can open. */\n path?: string;\n kind: 'prompt' | 'skill' | 'context';\n read(context: DoomHeadlessExecutionContext): string | Promise<string>;\n}\n\nexport interface DoomHeadlessCommand {\n when?: DoomHeadlessCondition;\n name: string;\n description: string;\n execute(args: string, context: DoomHeadlessExecutionContext): void | Promise<void>;\n}\n\nexport type DoomHeadlessEventName =\n | 'session_start'\n | 'session_shutdown'\n | 'session_tree'\n | 'before_agent_start'\n | 'agent_start'\n | 'agent_settled'\n | 'turn_start'\n | 'turn_end'\n | 'context'\n | 'before_provider_request'\n | 'message_start'\n | 'message_update'\n | 'message_end'\n | 'tool_call'\n | 'tool_execution_start'\n | 'tool_execution_update'\n | 'tool_execution_end'\n | 'tool_result'\n | 'model_select'\n | 'session_before_compact'\n | 'session_compact';\n\nexport type DoomHeadlessHookEvent<E extends DoomHeadlessEventName> = E extends 'before_provider_request'\n ? { lane: string; runId: string; model: { provider: string; id: string; api?: string }; payload: unknown }\n : E extends 'session_before_compact'\n ? { reason: string; preparation: unknown; instructions?: string; customInstructions?: string }\n : E extends 'model_select'\n ? { model: { provider: string; id: string } }\n : Readonly<Record<string, unknown>>;\n\nexport interface DoomHeadlessCompactionResult {\n summary: string;\n tokensBefore: number;\n retainedTail: Record<string, unknown>[];\n usage?: Record<string, unknown>;\n details?: unknown;\n}\n\nexport type DoomHeadlessHookResult<E extends DoomHeadlessEventName> = E extends 'before_provider_request'\n ? { payload: unknown } | void\n : E extends 'session_before_compact'\n ? { cancel?: boolean; decline?: boolean; compaction?: DoomHeadlessCompactionResult } | void\n : E extends 'context'\n ? { messages?: unknown[]; systemPrompt?: string } | void\n : E extends 'before_agent_start'\n ? { systemPrompt?: string } | void\n : E extends 'tool_call'\n ? { args?: Record<string, unknown>; block?: { reason: string; terminate?: boolean } } | void\n : E extends 'tool_result'\n ? {\n content?: DoomHeadlessContent[];\n details?: unknown;\n isError?: boolean;\n usage?: Record<string, unknown>;\n terminate?: boolean;\n } | void\n : unknown;\n\nexport type DoomHeadlessHook<E extends DoomHeadlessEventName = DoomHeadlessEventName> = E extends DoomHeadlessEventName\n ? {\n when?: DoomHeadlessCondition;\n event: E;\n handle(\n event: Readonly<DoomHeadlessHookEvent<E>>,\n context: DoomHeadlessExecutionContext,\n ): DoomHeadlessHookResult<E> | Promise<DoomHeadlessHookResult<E>>;\n }\n : never;\n\n/** A retained facet can register activity without starting disabled watchers or services. */\nexport interface DoomHeadlessActivity {\n when?: DoomHeadlessCondition;\n name: string;\n start(context: DoomHeadlessExecutionContext): (() => void | Promise<void>) | Promise<() => void | Promise<void>>;\n}\n\n/** Read-only metadata for the currently applied session, never executable declarations or resource bodies. */\nexport interface DoomHeadlessCapability {\n readonly source: string;\n readonly name: string;\n readonly kind: 'tool' | 'skill';\n readonly when?: DoomHeadlessCondition;\n readonly active: boolean;\n readonly discoverable: boolean;\n readonly reason?: 'inactive' | 'restricted' | 'shadowed' | 'unavailable' | 'not-discoverable';\n}\n\n/** Visibility controls model discovery only, never admission for external execution. */\nexport function isDoomHeadlessToolModelVisible(tool: Pick<DoomHeadlessTool, '_meta'>): boolean {\n const visibility = tool._meta?.ui?.visibility;\n return visibility === undefined || visibility.includes('model');\n}\n\nexport interface DoomHeadlessCapabilitySnapshot {\n readonly revision: number;\n readonly ready: boolean;\n readonly capabilities: readonly DoomHeadlessCapability[];\n}\n\n/** Registrations inherit package ownership from the caller's Cordis facet. */\n/**\n * The tool a server session loads skills through. When a session carries it, the prompt lists\n * every skill by name and points here, so a skill needs no file the agent could read.\n */\nexport const DOOM_LOAD_SKILL_TOOL = 'load_skill';\n\nexport interface DoomHeadlessHostService {\n readonly context: DoomHeadlessExecutionContext;\n /** Admitted external execution, sharing native hooks, restrictions and session lifetime. */\n readonly toolSurface?: Pick<SessionToolSurface, 'readSurface' | 'invokeTool'>;\n /** The instructions of an applied skill by exact name, or undefined when none is applied. */\n readSkill(name: string): string | undefined;\n changeSelection(change: DoomHeadlessSelectionChange): Promise<void>;\n assertActive(source?: string): void;\n subscribeSelection(listener: (selection: DoomHeadlessSelection) => void | Promise<void>): () => void;\n /** Inspect only a coherently applied generation. A transition returns ready=false and no partial inventory. */\n inspectCapabilities(): DoomHeadlessCapabilitySnapshot;\n registerToolRestriction(restriction: DoomHeadlessToolRestriction): DoomHeadlessRegistration;\n registerTool<TParameters extends TSchema>(tool: DoomHeadlessTool<TParameters>): DoomHeadlessRegistration;\n registerResource(resource: DoomHeadlessResource): DoomHeadlessRegistration;\n registerCommand(command: DoomHeadlessCommand): DoomHeadlessRegistration;\n registerHook(hook: DoomHeadlessHook): DoomHeadlessRegistration;\n registerActivity(activity: DoomHeadlessActivity): DoomHeadlessRegistration;\n}\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'doom/headless-host': DoomHeadlessHostService;\n }\n}\n\nexport function readDoomHeadlessHost(context: Context): DoomHeadlessHostService | undefined {\n return context.get(DOOM_HEADLESS_HOST_SERVICE) as DoomHeadlessHostService | undefined;\n}\n\nexport function requireDoomHeadlessHost(context: Context): DoomHeadlessHostService {\n const host = readDoomHeadlessHost(context);\n if (!host) throw new Error('This contribution requires the Doom headless session host.');\n return host;\n}\n"],"mappings":";;AAWA,MAAa,6BAA6B;AAC1C,MAAa,sBAAsB,OAAO,IAAI,qBAAqB;AAEnE,MAAM,yBAAyB;;AAG/B,IAAa,mCAAb,cAAsD,MAAM;CAC1D,YAAY,OAAgB;EAC1B,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAAG,EAAE,MAAM,CAAC;EACvE,KAAK,OAAO;CACd;AACF;;AAGA,SAAgB,mCAAmC,OAAyB;CAC1E,OAAO,iBAAiB,SAAS,MAAM,SAAS;AAClD;AAiBA,SAAgB,sBAAsB,SAAqD;CACzF,OAAQ,QAAwE;AAClF;;;;;AAsBA,SAAgB,yBAAyB,QAMd;CACzB,MAAM,EAAE,sBAAsB;CAC9B,OAAO;EACL,SAAS,OAAO;EAChB,SAAS,OAAO;EAChB,GAAI,OAAO,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO,OAAO,MAAM;EAC5D,GAAI,OAAO,sBAAsB,YAAY,sBAAsB,QAAQ,CAAC,MAAM,QAAQ,iBAAiB,IACvG,EAAqB,kBAA6C,IAClE,CAAC;EACL,GAAI,OAAO,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,OAAO,QAAQ;CACpE;AACF;;AAiSA,SAAgB,+BAA+B,MAAgD;CAC7F,MAAM,aAAa,KAAK,OAAO,IAAI;CACnC,OAAO,eAAe,KAAA,KAAa,WAAW,SAAS,OAAO;AAChE;;;;;;AAaA,MAAa,uBAAuB;AA2BpC,SAAgB,qBAAqB,SAAuD;CAC1F,OAAO,QAAQ,IAAI,0BAA0B;AAC/C;AAEA,SAAgB,wBAAwB,SAA2C;CACjF,MAAM,OAAO,qBAAqB,OAAO;CACzC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,4DAA4D;CACvF,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pluginProtocol.cjs","names":["Type","defineService","Check"],"sources":["../../../src/schemas/pluginProtocol.ts"],"sourcesContent":["import { defineService, type Context, type JsonValue } from '@earendil-works/chord';\nimport { type Static, type TSchema, Type } from 'typebox';\nimport { Check } from 'typebox/value';\n\nimport type { DoomApiMount, DoomApiScope } from './packageApi';\n\n/** The address is always exact. A workspace call never resolves to a global service. */\nexport const DoomPluginMountSchema = Type.Union([\n Type.Object({ scope: Type.Literal('global') }, { additionalProperties: false }),\n Type.Object(\n { scope: Type.Literal('workspace'), workspaceId: Type.String({ minLength: 1 }) },\n { additionalProperties: false },\n ),\n Type.Object(\n { scope: Type.Literal('session'), sessionId: Type.String({ minLength: 1 }) },\n { additionalProperties: false },\n ),\n]);\n\nexport const DoomPluginCallSchema = Type.Object(\n {\n mount: DoomPluginMountSchema,\n service: Type.String({ minLength: 1 }),\n method: Type.String({ minLength: 1 }),\n input: Type.Unknown(),\n },\n { additionalProperties: false },\n);\n\nexport type DoomPluginCall = Static<typeof DoomPluginCallSchema>;\nexport type DoomPluginDirection = 'client-to-server' | 'server-to-client';\nexport interface DoomPluginCaller {\n /** Authenticated connection that owns client capabilities and leases. */\n connectionId?: string;\n}\n\n/** Chord method shared by all authenticated Doompi clients. */\nexport interface DoomPluginService {\n invoke(\n call: {\n mount: DoomApiMount;\n service: string;\n method: string;\n input: JsonValue;\n },\n context: Context,\n ): Promise<JsonValue>;\n}\n\nexport const DoomPluginService = defineService<DoomPluginService>('doompi.plugin.v1');\n\nexport interface DoomPluginMethod<TInput extends TSchema, TOutput extends TSchema> {\n readonly service: string;\n readonly method: string;\n readonly scope: DoomApiScope;\n readonly direction: DoomPluginDirection;\n readonly input: TInput;\n readonly output: TOutput;\n}\n\nexport function defineDoomPluginMethod<TInput extends TSchema, TOutput extends TSchema>(\n definition: DoomPluginMethod<TInput, TOutput>,\n): DoomPluginMethod<TInput, TOutput> {\n if (!definition.service || !definition.method) throw new Error('Plugin service and method must be named.');\n return definition;\n}\n\nexport function doomPluginMountKey(mount: DoomApiMount): string {\n if (!Check(DoomPluginMountSchema, mount)) throw new Error('Invalid plugin mount.');\n switch (mount.scope) {\n case 'global':\n return 'global';\n case 'workspace':\n return `workspace:${mount.workspaceId}`;\n case 'session':\n return `session:${mount.sessionId}`;\n }\n}\n\nexport class DoomPluginCallError extends Error {\n constructor(\n readonly code: 'INVALID_CALL' | 'METHOD_NOT_FOUND' | 'INVALID_INPUT' | 'INVALID_OUTPUT',\n message: string,\n ) {\n super(message);\n this.name = 'DoomPluginCallError';\n }\n}\n\nexport interface DoomPluginRegistry {\n register<TInput extends TSchema, TOutput extends TSchema>(\n mount: DoomApiMount,\n definition: DoomPluginMethod<TInput, TOutput>,\n handler: (input: Static<TInput>, caller: DoomPluginCaller) => Static<TOutput> | Promise<Static<TOutput>>,\n ): () => void;\n invoke(call: unknown, direction: DoomPluginDirection, caller?: DoomPluginCaller): Promise<unknown>;\n dispose(): void;\n}\n\n/** Transport-neutral dispatch, shared by Chord server services and client capability hosts. */\nexport function createDoomPluginRegistry(): DoomPluginRegistry {\n const handlers = new Map<\n string,\n {\n definition: DoomPluginMethod<TSchema, TSchema>;\n handler: (input: never, caller: DoomPluginCaller) => unknown;\n }\n >();\n let disposed = false;\n const keyOf = (mount: DoomApiMount, service: string, method: string, direction: DoomPluginDirection): string =>\n `${doomPluginMountKey(mount)}\\0${direction}\\0${service}\\0${method}`;\n return {\n register(mount, definition, handler) {\n if (disposed) throw new Error('Plugin registry is disposed.');\n if (mount.scope !== definition.scope)\n throw new Error(`Method '${definition.service}.${definition.method}' requires ${definition.scope} scope.`);\n const key = keyOf(mount, definition.service, definition.method, definition.direction);\n if (handlers.has(key))\n throw new Error(`Plugin method '${definition.service}.${definition.method}' is already mounted.`);\n const entry = { definition, handler } as typeof handlers extends Map<string, infer TValue> ? TValue : never;\n handlers.set(key, entry);\n return () => {\n if (handlers.get(key) === entry) handlers.delete(key);\n };\n },\n async invoke(value, direction, caller = {}) {\n if (disposed) throw new Error('Plugin registry is disposed.');\n if (!Check(DoomPluginCallSchema, value)) throw new DoomPluginCallError('INVALID_CALL', 'Invalid plugin call.');\n const call = value as DoomPluginCall;\n const entry = handlers.get(keyOf(call.mount, call.service, call.method, direction));\n if (!entry)\n throw new DoomPluginCallError(\n 'METHOD_NOT_FOUND',\n `Plugin method '${call.service}.${call.method}' is not mounted at this scope.`,\n );\n if (!Check(entry.definition.input, call.input))\n throw new DoomPluginCallError('INVALID_INPUT', `Invalid input for '${call.service}.${call.method}'.`);\n const output = await entry.handler(call.input as never, caller);\n if (!Check(entry.definition.output, output))\n throw new DoomPluginCallError('INVALID_OUTPUT', `Invalid output from '${call.service}.${call.method}'.`);\n return output;\n },\n dispose() {\n disposed = true;\n handlers.clear();\n },\n };\n}\n\nexport async function invokeDoomPluginMethod<TInput extends TSchema, TOutput extends TSchema>(\n transport: (call: DoomPluginCall) => Promise<unknown>,\n mount: DoomApiMount,\n definition: DoomPluginMethod<TInput, TOutput>,\n input: Static<TInput>,\n): Promise<Static<TOutput>> {\n if (mount.scope !== definition.scope)\n throw new Error(`Method '${definition.service}.${definition.method}' requires ${definition.scope} scope.`);\n if (!Check(definition.input, input))\n throw new DoomPluginCallError('INVALID_INPUT', `Invalid input for '${definition.service}.${definition.method}'.`);\n const output = await transport({ mount, service: definition.service, method: definition.method, input });\n if (!Check(definition.output, output))\n throw new DoomPluginCallError(\n 'INVALID_OUTPUT',\n `Invalid output from '${definition.service}.${definition.method}'.`,\n );\n return output;\n}\n"],"mappings":";;;;;AAOA,MAAa,wBAAwBA,QAAAA,KAAK,MAAM;CAC9CA,QAAAA,KAAK,OAAO,EAAE,OAAOA,QAAAA,KAAK,QAAQ,QAAQ,EAAE,GAAG,EAAE,sBAAsB,MAAM,CAAC;CAC9EA,QAAAA,KAAK,OACH;EAAE,OAAOA,QAAAA,KAAK,QAAQ,WAAW;EAAG,aAAaA,QAAAA,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CAAE,GAC/E,EAAE,sBAAsB,MAAM,CAChC;CACAA,QAAAA,KAAK,OACH;EAAE,OAAOA,QAAAA,KAAK,QAAQ,SAAS;EAAG,WAAWA,QAAAA,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CAAE,GAC3E,EAAE,sBAAsB,MAAM,CAChC;AACF,CAAC;AAED,MAAa,uBAAuBA,QAAAA,KAAK,OACvC;CACE,OAAO;CACP,SAASA,QAAAA,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CACrC,QAAQA,QAAAA,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CACpC,OAAOA,QAAAA,KAAK,QAAQ;AACtB,GACA,EAAE,sBAAsB,MAAM,CAChC;
|
|
1
|
+
{"version":3,"file":"pluginProtocol.cjs","names":["Type","defineService","Check"],"sources":["../../../src/schemas/pluginProtocol.ts"],"sourcesContent":["import { defineService, type Context, type JsonValue } from '@earendil-works/chord';\nimport { type Static, type TSchema, Type } from 'typebox';\nimport { Check } from 'typebox/value';\n\nimport type { DoomApiMount, DoomApiScope } from './packageApi';\n\n/** The address is always exact. A workspace call never resolves to a global service. */\nexport const DoomPluginMountSchema = Type.Union([\n Type.Object({ scope: Type.Literal('global') }, { additionalProperties: false }),\n Type.Object(\n { scope: Type.Literal('workspace'), workspaceId: Type.String({ minLength: 1 }) },\n { additionalProperties: false },\n ),\n Type.Object(\n { scope: Type.Literal('session'), sessionId: Type.String({ minLength: 1 }) },\n { additionalProperties: false },\n ),\n]);\n\nexport const DoomPluginCallSchema = Type.Object(\n {\n mount: DoomPluginMountSchema,\n service: Type.String({ minLength: 1 }),\n method: Type.String({ minLength: 1 }),\n input: Type.Unknown(),\n },\n { additionalProperties: false },\n);\n\nexport type DoomPluginCall = Static<typeof DoomPluginCallSchema>;\nexport type DoomPluginDirection = 'client-to-server' | 'server-to-client';\nexport interface DoomPluginCaller {\n /** Authenticated connection that owns client capabilities and leases. */\n connectionId?: string;\n /** Aborted when the authenticated browser connection closes. Never supplied over the wire. */\n signal?: AbortSignal;\n}\n\n/** Chord method shared by all authenticated Doompi clients. */\nexport interface DoomPluginService {\n invoke(\n call: {\n mount: DoomApiMount;\n service: string;\n method: string;\n input: JsonValue;\n },\n context: Context,\n ): Promise<JsonValue>;\n}\n\nexport const DoomPluginService = defineService<DoomPluginService>('doompi.plugin.v1');\n\nexport interface DoomPluginMethod<TInput extends TSchema, TOutput extends TSchema> {\n readonly service: string;\n readonly method: string;\n readonly scope: DoomApiScope;\n readonly direction: DoomPluginDirection;\n readonly input: TInput;\n readonly output: TOutput;\n}\n\nexport function defineDoomPluginMethod<TInput extends TSchema, TOutput extends TSchema>(\n definition: DoomPluginMethod<TInput, TOutput>,\n): DoomPluginMethod<TInput, TOutput> {\n if (!definition.service || !definition.method) throw new Error('Plugin service and method must be named.');\n return definition;\n}\n\nexport function doomPluginMountKey(mount: DoomApiMount): string {\n if (!Check(DoomPluginMountSchema, mount)) throw new Error('Invalid plugin mount.');\n switch (mount.scope) {\n case 'global':\n return 'global';\n case 'workspace':\n return `workspace:${mount.workspaceId}`;\n case 'session':\n return `session:${mount.sessionId}`;\n }\n}\n\nexport class DoomPluginCallError extends Error {\n constructor(\n readonly code: 'INVALID_CALL' | 'METHOD_NOT_FOUND' | 'INVALID_INPUT' | 'INVALID_OUTPUT',\n message: string,\n ) {\n super(message);\n this.name = 'DoomPluginCallError';\n }\n}\n\nexport interface DoomPluginRegistry {\n register<TInput extends TSchema, TOutput extends TSchema>(\n mount: DoomApiMount,\n definition: DoomPluginMethod<TInput, TOutput>,\n handler: (input: Static<TInput>, caller: DoomPluginCaller) => Static<TOutput> | Promise<Static<TOutput>>,\n ): () => void;\n invoke(call: unknown, direction: DoomPluginDirection, caller?: DoomPluginCaller): Promise<unknown>;\n dispose(): void;\n}\n\n/** Transport-neutral dispatch, shared by Chord server services and client capability hosts. */\nexport function createDoomPluginRegistry(): DoomPluginRegistry {\n const handlers = new Map<\n string,\n {\n definition: DoomPluginMethod<TSchema, TSchema>;\n handler: (input: never, caller: DoomPluginCaller) => unknown;\n }\n >();\n let disposed = false;\n const keyOf = (mount: DoomApiMount, service: string, method: string, direction: DoomPluginDirection): string =>\n `${doomPluginMountKey(mount)}\\0${direction}\\0${service}\\0${method}`;\n return {\n register(mount, definition, handler) {\n if (disposed) throw new Error('Plugin registry is disposed.');\n if (mount.scope !== definition.scope)\n throw new Error(`Method '${definition.service}.${definition.method}' requires ${definition.scope} scope.`);\n const key = keyOf(mount, definition.service, definition.method, definition.direction);\n if (handlers.has(key))\n throw new Error(`Plugin method '${definition.service}.${definition.method}' is already mounted.`);\n const entry = { definition, handler } as typeof handlers extends Map<string, infer TValue> ? TValue : never;\n handlers.set(key, entry);\n return () => {\n if (handlers.get(key) === entry) handlers.delete(key);\n };\n },\n async invoke(value, direction, caller = {}) {\n if (disposed) throw new Error('Plugin registry is disposed.');\n if (!Check(DoomPluginCallSchema, value)) throw new DoomPluginCallError('INVALID_CALL', 'Invalid plugin call.');\n const call = value as DoomPluginCall;\n const entry = handlers.get(keyOf(call.mount, call.service, call.method, direction));\n if (!entry)\n throw new DoomPluginCallError(\n 'METHOD_NOT_FOUND',\n `Plugin method '${call.service}.${call.method}' is not mounted at this scope.`,\n );\n if (!Check(entry.definition.input, call.input))\n throw new DoomPluginCallError('INVALID_INPUT', `Invalid input for '${call.service}.${call.method}'.`);\n const output = await entry.handler(call.input as never, caller);\n if (!Check(entry.definition.output, output))\n throw new DoomPluginCallError('INVALID_OUTPUT', `Invalid output from '${call.service}.${call.method}'.`);\n return output;\n },\n dispose() {\n disposed = true;\n handlers.clear();\n },\n };\n}\n\nexport async function invokeDoomPluginMethod<TInput extends TSchema, TOutput extends TSchema>(\n transport: (call: DoomPluginCall) => Promise<unknown>,\n mount: DoomApiMount,\n definition: DoomPluginMethod<TInput, TOutput>,\n input: Static<TInput>,\n): Promise<Static<TOutput>> {\n if (mount.scope !== definition.scope)\n throw new Error(`Method '${definition.service}.${definition.method}' requires ${definition.scope} scope.`);\n if (!Check(definition.input, input))\n throw new DoomPluginCallError('INVALID_INPUT', `Invalid input for '${definition.service}.${definition.method}'.`);\n const output = await transport({ mount, service: definition.service, method: definition.method, input });\n if (!Check(definition.output, output))\n throw new DoomPluginCallError(\n 'INVALID_OUTPUT',\n `Invalid output from '${definition.service}.${definition.method}'.`,\n );\n return output;\n}\n"],"mappings":";;;;;AAOA,MAAa,wBAAwBA,QAAAA,KAAK,MAAM;CAC9CA,QAAAA,KAAK,OAAO,EAAE,OAAOA,QAAAA,KAAK,QAAQ,QAAQ,EAAE,GAAG,EAAE,sBAAsB,MAAM,CAAC;CAC9EA,QAAAA,KAAK,OACH;EAAE,OAAOA,QAAAA,KAAK,QAAQ,WAAW;EAAG,aAAaA,QAAAA,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CAAE,GAC/E,EAAE,sBAAsB,MAAM,CAChC;CACAA,QAAAA,KAAK,OACH;EAAE,OAAOA,QAAAA,KAAK,QAAQ,SAAS;EAAG,WAAWA,QAAAA,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CAAE,GAC3E,EAAE,sBAAsB,MAAM,CAChC;AACF,CAAC;AAED,MAAa,uBAAuBA,QAAAA,KAAK,OACvC;CACE,OAAO;CACP,SAASA,QAAAA,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CACrC,QAAQA,QAAAA,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CACpC,OAAOA,QAAAA,KAAK,QAAQ;AACtB,GACA,EAAE,sBAAsB,MAAM,CAChC;AAwBA,MAAa,qBAAA,GAAoBC,sBAAAA,cAAAA,CAAiC,kBAAkB;AA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AAW,QAAQ,MAAM,GAClC,MAAM,IAAI,oBACR,kBACA,wBAAwB,WAAW,QAAQ,GAAG,WAAW,OAAO,GAClE;CACF,OAAO;AACT"}
|
|
@@ -31,6 +31,8 @@ export type DoomPluginDirection = 'client-to-server' | 'server-to-client';
|
|
|
31
31
|
export interface DoomPluginCaller {
|
|
32
32
|
/** Authenticated connection that owns client capabilities and leases. */
|
|
33
33
|
connectionId?: string;
|
|
34
|
+
/** Aborted when the authenticated browser connection closes. Never supplied over the wire. */
|
|
35
|
+
signal?: AbortSignal;
|
|
34
36
|
}
|
|
35
37
|
/** Chord method shared by all authenticated Doompi clients. */
|
|
36
38
|
export interface DoomPluginService {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pluginProtocol.d.mts","names":[],"sources":["../../../src/schemas/pluginProtocol.ts"],"mappings":";;;;;qBAOa,uBAAqB,KAAA,QAAA,KAAA;;;;;;;;;qBAYrB,sBAAoB,KAAA;;;;;;;;;;;;;;YAUrB,iBAAiB,cAAc;YAC/B;iBACK;;EAEf;;;
|
|
1
|
+
{"version":3,"file":"pluginProtocol.d.mts","names":[],"sources":["../../../src/schemas/pluginProtocol.ts"],"mappings":";;;;;qBAOa,uBAAqB,KAAA,QAAA,KAAA;;;;;;;;;qBAYrB,sBAAoB,KAAA;;;;;;;;;;;;;;YAUrB,iBAAiB,cAAc;YAC/B;iBACK;;EAEf;;EAEA,SAAS;;;iBAIM;EACf,OACE;IACE,OAAO;IACP;IACA;IACA,OAAO;KAET,SAAS,UACR,QAAQ;;qBAGA,mDAAiB,QAAA;iBAEb,iBAAiB,eAAe,SAAS,gBAAgB;WAC/D;WACA;WACA,OAAO;WACP,WAAW;WACX,OAAO;WACP,QAAQ;;wBAGH,uBAAuB,eAAe,SAAS,gBAAgB,SAC7E,YAAY,iBAAiB,QAAQ,WACpC,iBAAiB,QAAQ;wBAKZ,mBAAmB,OAAO;qBAY7B,4BAA4B;WAE5B;EADX,YACW,gFACT;;iBAOa;EACf,SAAS,eAAe,SAAS,gBAAgB,SAC/C,OAAO,cACP,YAAY,iBAAiB,QAAQ,UACrC,UAAU,OAAO,OAAO,SAAS,QAAQ,qBAAqB,OAAO,WAAW,QAAQ,OAAO;EAEjG,OAAO,eAAe,WAAW,qBAAqB,SAAS,mBAAmB;EAClF;;;wBAIc,4BAA4B;wBAiDtB,uBAAuB,eAAe,SAAS,gBAAgB,SACnF,YAAY,MAAM,mBAAmB,kBACrC,OAAO,cACP,YAAY,iBAAiB,QAAQ,UACrC,OAAO,OAAO,UACb,QAAQ,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pluginProtocol.mjs","names":[],"sources":["../../../src/schemas/pluginProtocol.ts"],"sourcesContent":["import { defineService, type Context, type JsonValue } from '@earendil-works/chord';\nimport { type Static, type TSchema, Type } from 'typebox';\nimport { Check } from 'typebox/value';\n\nimport type { DoomApiMount, DoomApiScope } from './packageApi';\n\n/** The address is always exact. A workspace call never resolves to a global service. */\nexport const DoomPluginMountSchema = Type.Union([\n Type.Object({ scope: Type.Literal('global') }, { additionalProperties: false }),\n Type.Object(\n { scope: Type.Literal('workspace'), workspaceId: Type.String({ minLength: 1 }) },\n { additionalProperties: false },\n ),\n Type.Object(\n { scope: Type.Literal('session'), sessionId: Type.String({ minLength: 1 }) },\n { additionalProperties: false },\n ),\n]);\n\nexport const DoomPluginCallSchema = Type.Object(\n {\n mount: DoomPluginMountSchema,\n service: Type.String({ minLength: 1 }),\n method: Type.String({ minLength: 1 }),\n input: Type.Unknown(),\n },\n { additionalProperties: false },\n);\n\nexport type DoomPluginCall = Static<typeof DoomPluginCallSchema>;\nexport type DoomPluginDirection = 'client-to-server' | 'server-to-client';\nexport interface DoomPluginCaller {\n /** Authenticated connection that owns client capabilities and leases. */\n connectionId?: string;\n}\n\n/** Chord method shared by all authenticated Doompi clients. */\nexport interface DoomPluginService {\n invoke(\n call: {\n mount: DoomApiMount;\n service: string;\n method: string;\n input: JsonValue;\n },\n context: Context,\n ): Promise<JsonValue>;\n}\n\nexport const DoomPluginService = defineService<DoomPluginService>('doompi.plugin.v1');\n\nexport interface DoomPluginMethod<TInput extends TSchema, TOutput extends TSchema> {\n readonly service: string;\n readonly method: string;\n readonly scope: DoomApiScope;\n readonly direction: DoomPluginDirection;\n readonly input: TInput;\n readonly output: TOutput;\n}\n\nexport function defineDoomPluginMethod<TInput extends TSchema, TOutput extends TSchema>(\n definition: DoomPluginMethod<TInput, TOutput>,\n): DoomPluginMethod<TInput, TOutput> {\n if (!definition.service || !definition.method) throw new Error('Plugin service and method must be named.');\n return definition;\n}\n\nexport function doomPluginMountKey(mount: DoomApiMount): string {\n if (!Check(DoomPluginMountSchema, mount)) throw new Error('Invalid plugin mount.');\n switch (mount.scope) {\n case 'global':\n return 'global';\n case 'workspace':\n return `workspace:${mount.workspaceId}`;\n case 'session':\n return `session:${mount.sessionId}`;\n }\n}\n\nexport class DoomPluginCallError extends Error {\n constructor(\n readonly code: 'INVALID_CALL' | 'METHOD_NOT_FOUND' | 'INVALID_INPUT' | 'INVALID_OUTPUT',\n message: string,\n ) {\n super(message);\n this.name = 'DoomPluginCallError';\n }\n}\n\nexport interface DoomPluginRegistry {\n register<TInput extends TSchema, TOutput extends TSchema>(\n mount: DoomApiMount,\n definition: DoomPluginMethod<TInput, TOutput>,\n handler: (input: Static<TInput>, caller: DoomPluginCaller) => Static<TOutput> | Promise<Static<TOutput>>,\n ): () => void;\n invoke(call: unknown, direction: DoomPluginDirection, caller?: DoomPluginCaller): Promise<unknown>;\n dispose(): void;\n}\n\n/** Transport-neutral dispatch, shared by Chord server services and client capability hosts. */\nexport function createDoomPluginRegistry(): DoomPluginRegistry {\n const handlers = new Map<\n string,\n {\n definition: DoomPluginMethod<TSchema, TSchema>;\n handler: (input: never, caller: DoomPluginCaller) => unknown;\n }\n >();\n let disposed = false;\n const keyOf = (mount: DoomApiMount, service: string, method: string, direction: DoomPluginDirection): string =>\n `${doomPluginMountKey(mount)}\\0${direction}\\0${service}\\0${method}`;\n return {\n register(mount, definition, handler) {\n if (disposed) throw new Error('Plugin registry is disposed.');\n if (mount.scope !== definition.scope)\n throw new Error(`Method '${definition.service}.${definition.method}' requires ${definition.scope} scope.`);\n const key = keyOf(mount, definition.service, definition.method, definition.direction);\n if (handlers.has(key))\n throw new Error(`Plugin method '${definition.service}.${definition.method}' is already mounted.`);\n const entry = { definition, handler } as typeof handlers extends Map<string, infer TValue> ? TValue : never;\n handlers.set(key, entry);\n return () => {\n if (handlers.get(key) === entry) handlers.delete(key);\n };\n },\n async invoke(value, direction, caller = {}) {\n if (disposed) throw new Error('Plugin registry is disposed.');\n if (!Check(DoomPluginCallSchema, value)) throw new DoomPluginCallError('INVALID_CALL', 'Invalid plugin call.');\n const call = value as DoomPluginCall;\n const entry = handlers.get(keyOf(call.mount, call.service, call.method, direction));\n if (!entry)\n throw new DoomPluginCallError(\n 'METHOD_NOT_FOUND',\n `Plugin method '${call.service}.${call.method}' is not mounted at this scope.`,\n );\n if (!Check(entry.definition.input, call.input))\n throw new DoomPluginCallError('INVALID_INPUT', `Invalid input for '${call.service}.${call.method}'.`);\n const output = await entry.handler(call.input as never, caller);\n if (!Check(entry.definition.output, output))\n throw new DoomPluginCallError('INVALID_OUTPUT', `Invalid output from '${call.service}.${call.method}'.`);\n return output;\n },\n dispose() {\n disposed = true;\n handlers.clear();\n },\n };\n}\n\nexport async function invokeDoomPluginMethod<TInput extends TSchema, TOutput extends TSchema>(\n transport: (call: DoomPluginCall) => Promise<unknown>,\n mount: DoomApiMount,\n definition: DoomPluginMethod<TInput, TOutput>,\n input: Static<TInput>,\n): Promise<Static<TOutput>> {\n if (mount.scope !== definition.scope)\n throw new Error(`Method '${definition.service}.${definition.method}' requires ${definition.scope} scope.`);\n if (!Check(definition.input, input))\n throw new DoomPluginCallError('INVALID_INPUT', `Invalid input for '${definition.service}.${definition.method}'.`);\n const output = await transport({ mount, service: definition.service, method: definition.method, input });\n if (!Check(definition.output, output))\n throw new DoomPluginCallError(\n 'INVALID_OUTPUT',\n `Invalid output from '${definition.service}.${definition.method}'.`,\n );\n return output;\n}\n"],"mappings":";;;;;AAOA,MAAa,wBAAwB,KAAK,MAAM;CAC9C,KAAK,OAAO,EAAE,OAAO,KAAK,QAAQ,QAAQ,EAAE,GAAG,EAAE,sBAAsB,MAAM,CAAC;CAC9E,KAAK,OACH;EAAE,OAAO,KAAK,QAAQ,WAAW;EAAG,aAAa,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CAAE,GAC/E,EAAE,sBAAsB,MAAM,CAChC;CACA,KAAK,OACH;EAAE,OAAO,KAAK,QAAQ,SAAS;EAAG,WAAW,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CAAE,GAC3E,EAAE,sBAAsB,MAAM,CAChC;AACF,CAAC;AAED,MAAa,uBAAuB,KAAK,OACvC;CACE,OAAO;CACP,SAAS,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CACrC,QAAQ,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CACpC,OAAO,KAAK,QAAQ;AACtB,GACA,EAAE,sBAAsB,MAAM,CAChC;
|
|
1
|
+
{"version":3,"file":"pluginProtocol.mjs","names":[],"sources":["../../../src/schemas/pluginProtocol.ts"],"sourcesContent":["import { defineService, type Context, type JsonValue } from '@earendil-works/chord';\nimport { type Static, type TSchema, Type } from 'typebox';\nimport { Check } from 'typebox/value';\n\nimport type { DoomApiMount, DoomApiScope } from './packageApi';\n\n/** The address is always exact. A workspace call never resolves to a global service. */\nexport const DoomPluginMountSchema = Type.Union([\n Type.Object({ scope: Type.Literal('global') }, { additionalProperties: false }),\n Type.Object(\n { scope: Type.Literal('workspace'), workspaceId: Type.String({ minLength: 1 }) },\n { additionalProperties: false },\n ),\n Type.Object(\n { scope: Type.Literal('session'), sessionId: Type.String({ minLength: 1 }) },\n { additionalProperties: false },\n ),\n]);\n\nexport const DoomPluginCallSchema = Type.Object(\n {\n mount: DoomPluginMountSchema,\n service: Type.String({ minLength: 1 }),\n method: Type.String({ minLength: 1 }),\n input: Type.Unknown(),\n },\n { additionalProperties: false },\n);\n\nexport type DoomPluginCall = Static<typeof DoomPluginCallSchema>;\nexport type DoomPluginDirection = 'client-to-server' | 'server-to-client';\nexport interface DoomPluginCaller {\n /** Authenticated connection that owns client capabilities and leases. */\n connectionId?: string;\n /** Aborted when the authenticated browser connection closes. Never supplied over the wire. */\n signal?: AbortSignal;\n}\n\n/** Chord method shared by all authenticated Doompi clients. */\nexport interface DoomPluginService {\n invoke(\n call: {\n mount: DoomApiMount;\n service: string;\n method: string;\n input: JsonValue;\n },\n context: Context,\n ): Promise<JsonValue>;\n}\n\nexport const DoomPluginService = defineService<DoomPluginService>('doompi.plugin.v1');\n\nexport interface DoomPluginMethod<TInput extends TSchema, TOutput extends TSchema> {\n readonly service: string;\n readonly method: string;\n readonly scope: DoomApiScope;\n readonly direction: DoomPluginDirection;\n readonly input: TInput;\n readonly output: TOutput;\n}\n\nexport function defineDoomPluginMethod<TInput extends TSchema, TOutput extends TSchema>(\n definition: DoomPluginMethod<TInput, TOutput>,\n): DoomPluginMethod<TInput, TOutput> {\n if (!definition.service || !definition.method) throw new Error('Plugin service and method must be named.');\n return definition;\n}\n\nexport function doomPluginMountKey(mount: DoomApiMount): string {\n if (!Check(DoomPluginMountSchema, mount)) throw new Error('Invalid plugin mount.');\n switch (mount.scope) {\n case 'global':\n return 'global';\n case 'workspace':\n return `workspace:${mount.workspaceId}`;\n case 'session':\n return `session:${mount.sessionId}`;\n }\n}\n\nexport class DoomPluginCallError extends Error {\n constructor(\n readonly code: 'INVALID_CALL' | 'METHOD_NOT_FOUND' | 'INVALID_INPUT' | 'INVALID_OUTPUT',\n message: string,\n ) {\n super(message);\n this.name = 'DoomPluginCallError';\n }\n}\n\nexport interface DoomPluginRegistry {\n register<TInput extends TSchema, TOutput extends TSchema>(\n mount: DoomApiMount,\n definition: DoomPluginMethod<TInput, TOutput>,\n handler: (input: Static<TInput>, caller: DoomPluginCaller) => Static<TOutput> | Promise<Static<TOutput>>,\n ): () => void;\n invoke(call: unknown, direction: DoomPluginDirection, caller?: DoomPluginCaller): Promise<unknown>;\n dispose(): void;\n}\n\n/** Transport-neutral dispatch, shared by Chord server services and client capability hosts. */\nexport function createDoomPluginRegistry(): DoomPluginRegistry {\n const handlers = new Map<\n string,\n {\n definition: DoomPluginMethod<TSchema, TSchema>;\n handler: (input: never, caller: DoomPluginCaller) => unknown;\n }\n >();\n let disposed = false;\n const keyOf = (mount: DoomApiMount, service: string, method: string, direction: DoomPluginDirection): string =>\n `${doomPluginMountKey(mount)}\\0${direction}\\0${service}\\0${method}`;\n return {\n register(mount, definition, handler) {\n if (disposed) throw new Error('Plugin registry is disposed.');\n if (mount.scope !== definition.scope)\n throw new Error(`Method '${definition.service}.${definition.method}' requires ${definition.scope} scope.`);\n const key = keyOf(mount, definition.service, definition.method, definition.direction);\n if (handlers.has(key))\n throw new Error(`Plugin method '${definition.service}.${definition.method}' is already mounted.`);\n const entry = { definition, handler } as typeof handlers extends Map<string, infer TValue> ? TValue : never;\n handlers.set(key, entry);\n return () => {\n if (handlers.get(key) === entry) handlers.delete(key);\n };\n },\n async invoke(value, direction, caller = {}) {\n if (disposed) throw new Error('Plugin registry is disposed.');\n if (!Check(DoomPluginCallSchema, value)) throw new DoomPluginCallError('INVALID_CALL', 'Invalid plugin call.');\n const call = value as DoomPluginCall;\n const entry = handlers.get(keyOf(call.mount, call.service, call.method, direction));\n if (!entry)\n throw new DoomPluginCallError(\n 'METHOD_NOT_FOUND',\n `Plugin method '${call.service}.${call.method}' is not mounted at this scope.`,\n );\n if (!Check(entry.definition.input, call.input))\n throw new DoomPluginCallError('INVALID_INPUT', `Invalid input for '${call.service}.${call.method}'.`);\n const output = await entry.handler(call.input as never, caller);\n if (!Check(entry.definition.output, output))\n throw new DoomPluginCallError('INVALID_OUTPUT', `Invalid output from '${call.service}.${call.method}'.`);\n return output;\n },\n dispose() {\n disposed = true;\n handlers.clear();\n },\n };\n}\n\nexport async function invokeDoomPluginMethod<TInput extends TSchema, TOutput extends TSchema>(\n transport: (call: DoomPluginCall) => Promise<unknown>,\n mount: DoomApiMount,\n definition: DoomPluginMethod<TInput, TOutput>,\n input: Static<TInput>,\n): Promise<Static<TOutput>> {\n if (mount.scope !== definition.scope)\n throw new Error(`Method '${definition.service}.${definition.method}' requires ${definition.scope} scope.`);\n if (!Check(definition.input, input))\n throw new DoomPluginCallError('INVALID_INPUT', `Invalid input for '${definition.service}.${definition.method}'.`);\n const output = await transport({ mount, service: definition.service, method: definition.method, input });\n if (!Check(definition.output, output))\n throw new DoomPluginCallError(\n 'INVALID_OUTPUT',\n `Invalid output from '${definition.service}.${definition.method}'.`,\n );\n return output;\n}\n"],"mappings":";;;;;AAOA,MAAa,wBAAwB,KAAK,MAAM;CAC9C,KAAK,OAAO,EAAE,OAAO,KAAK,QAAQ,QAAQ,EAAE,GAAG,EAAE,sBAAsB,MAAM,CAAC;CAC9E,KAAK,OACH;EAAE,OAAO,KAAK,QAAQ,WAAW;EAAG,aAAa,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CAAE,GAC/E,EAAE,sBAAsB,MAAM,CAChC;CACA,KAAK,OACH;EAAE,OAAO,KAAK,QAAQ,SAAS;EAAG,WAAW,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CAAE,GAC3E,EAAE,sBAAsB,MAAM,CAChC;AACF,CAAC;AAED,MAAa,uBAAuB,KAAK,OACvC;CACE,OAAO;CACP,SAAS,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CACrC,QAAQ,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;CACpC,OAAO,KAAK,QAAQ;AACtB,GACA,EAAE,sBAAsB,MAAM,CAChC;AAwBA,MAAa,oBAAoB,cAAiC,kBAAkB;AAWpF,SAAgB,uBACd,YACmC;CACnC,IAAI,CAAC,WAAW,WAAW,CAAC,WAAW,QAAQ,MAAM,IAAI,MAAM,0CAA0C;CACzG,OAAO;AACT;A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7G,MAAM,OAAO;GACb,MAAM,QAAQ,SAAS,IAAI,MAAM,KAAK,OAAO,KAAK,SAAS,KAAK,QAAQ,SAAS,CAAC;GAClF,IAAI,CAAC,OACH,MAAM,IAAI,oBACR,oBACA,kBAAkB,KAAK,QAAQ,GAAG,KAAK,OAAO,gCAChD;GACF,IAAI,CAAC,MAAM,MAAM,WAAW,OAAO,KAAK,KAAK,GAC3C,MAAM,IAAI,oBAAoB,iBAAiB,sBAAsB,KAAK,QAAQ,GAAG,KAAK,OAAO,GAAG;GACtG,MAAM,SAAS,MAAM,MAAM,QAAQ,KAAK,OAAgB,MAAM;GAC9D,IAAI,CAAC,MAAM,MAAM,WAAW,QAAQ,MAAM,GACxC,MAAM,IAAI,oBAAoB,kBAAkB,wBAAwB,KAAK,QAAQ,GAAG,KAAK,OAAO,GAAG;GACzG,OAAO;EACT;EACA,UAAU;GACR,WAAW;GACX,SAAS,MAAM;EACjB;CACF;AACF;AAEA,eAAsB,uBACpB,WACA,OACA,YACA,OAC0B;CAC1B,IAAI,MAAM,UAAU,WAAW,OAC7B,MAAM,IAAI,MAAM,WAAW,WAAW,QAAQ,GAAG,WAAW,OAAO,aAAa,WAAW,MAAM,QAAQ;CAC3G,IAAI,CAAC,MAAM,WAAW,OAAO,KAAK,GAChC,MAAM,IAAI,oBAAoB,iBAAiB,sBAAsB,WAAW,QAAQ,GAAG,WAAW,OAAO,GAAG;CAClH,MAAM,SAAS,MAAM,UAAU;EAAE;EAAO,SAAS,WAAW;EAAS,QAAQ,WAAW;EAAQ;CAAM,CAAC;CACvG,IAAI,CAAC,MAAM,WAAW,QAAQ,MAAM,GAClC,MAAM,IAAI,oBACR,kBACA,wBAAwB,WAAW,QAAQ,GAAG,WAAW,OAAO,GAClE;CACF,OAAO;AACT"}
|
|
@@ -6,6 +6,7 @@ const require_index$3 = require("../services/piExtensionHost/index.cjs");
|
|
|
6
6
|
let node_crypto = require("node:crypto");
|
|
7
7
|
let _earendil_works_pi_durable = require("@earendil-works/pi-durable");
|
|
8
8
|
let _earendil_works_chord_context = require("@earendil-works/chord/context");
|
|
9
|
+
let node_util = require("node:util");
|
|
9
10
|
let _earendil_works_pi_coding_agent = require("@earendil-works/pi-coding-agent");
|
|
10
11
|
let _earendil_works_pi_ai = require("@earendil-works/pi-ai");
|
|
11
12
|
let _earendil_works_pi_ai_utils_transcript = require("@earendil-works/pi-ai/utils/transcript");
|
|
@@ -167,6 +168,7 @@ async function createDirectHarnessRuntime(options) {
|
|
|
167
168
|
const originalOnPayload = requestOptions?.onPayload;
|
|
168
169
|
args[2] = {
|
|
169
170
|
...requestOptions,
|
|
171
|
+
sessionId: key === "complete" ? requestOptions?.sessionId ?? sessionId : sessionId,
|
|
170
172
|
...usePriority ? { serviceTier: "priority" } : {},
|
|
171
173
|
onPayload: async (payload, model) => {
|
|
172
174
|
options.guardModelRequest?.();
|
|
@@ -364,11 +366,12 @@ async function createDirectHarnessRuntime(options) {
|
|
|
364
366
|
}
|
|
365
367
|
}
|
|
366
368
|
const contextMessages = request.messages.filter((m) => m.role !== "system").map((message) => contextContributions.get(JSON.stringify(message))?.shift() ?? message);
|
|
369
|
+
const originalContext = structuredClone(contextMessages);
|
|
367
370
|
const patch = await options.transformContext?.({
|
|
368
371
|
messages: contextMessages,
|
|
369
372
|
systemPrompt
|
|
370
373
|
}, ctx);
|
|
371
|
-
let messages = patch ? [{
|
|
374
|
+
let messages = patch && (patch.systemPrompt !== void 0 && patch.systemPrompt !== systemPrompt || patch.messages !== void 0 && !(0, node_util.isDeepStrictEqual)(patch.messages, originalContext)) ? [{
|
|
372
375
|
role: "system",
|
|
373
376
|
content: patch.systemPrompt ?? systemPrompt,
|
|
374
377
|
timestamp: Date.now(),
|
|
@@ -1173,7 +1176,7 @@ async function createDirectHarnessRuntime(options) {
|
|
|
1173
1176
|
await eventsSettled;
|
|
1174
1177
|
await reconcile();
|
|
1175
1178
|
await publish();
|
|
1176
|
-
if (status.status === "unanswered" && status.reason !== "aborted") throw new Error(`Agent submission failed: ${status.reason}`);
|
|
1179
|
+
if (status.status === "unanswered" && status.reason !== "aborted") throw new Error(`Agent submission failed: ${status.reason}${typeof status.detail === "string" && status.detail ? `: ${status.detail}` : ""}`);
|
|
1177
1180
|
await drain();
|
|
1178
1181
|
} finally {
|
|
1179
1182
|
internalDelivery.delete(submission.id);
|