@bastani/atomic 0.9.26-alpha.4 → 0.9.26-alpha.6
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/CHANGELOG.md +27 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +17 -0
- package/dist/builtin/workflows/builtin/{chunk-73p2cm5s.js → chunk-9bhs02gm.js} +318 -52
- package/dist/builtin/workflows/builtin/{chunk-n95myjcg.js → chunk-gts8wgjr.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-ycvg8y8k.js → chunk-gw7rghda.js} +1 -1
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.js +3 -3
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +1383 -266
- package/dist/builtin/workflows/src/index.js +1129 -234
- package/dist/core/agent-session-export.js +1 -1
- package/dist/core/agent-session-export.js.map +1 -1
- package/dist/core/export-html/tool-renderer.d.ts +3 -3
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/api-types.d.ts +3 -1
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader-api.d.ts.map +1 -1
- package/dist/core/extensions/loader-api.js +5 -0
- package/dist/core/extensions/loader-api.js.map +1 -1
- package/dist/core/extensions/loader-bindings.d.ts +1 -1
- package/dist/core/extensions/loader-bindings.d.ts.map +1 -1
- package/dist/core/extensions/loader-bindings.js +1 -0
- package/dist/core/extensions/loader-bindings.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +3 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +6 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/runtime-types.d.ts +2 -1
- package/dist/core/extensions/runtime-types.d.ts.map +1 -1
- package/dist/core/extensions/runtime-types.js.map +1 -1
- package/dist/core/extensions/tool-types.d.ts +3 -0
- package/dist/core/extensions/tool-types.d.ts.map +1 -1
- package/dist/core/extensions/tool-types.js.map +1 -1
- package/dist/core/extensions/ui-types.d.ts +2 -2
- package/dist/core/extensions/ui-types.d.ts.map +1 -1
- package/dist/core/extensions/ui-types.js.map +1 -1
- package/dist/core/extensions/workflow-run-control.d.ts +3 -0
- package/dist/core/extensions/workflow-run-control.d.ts.map +1 -1
- package/dist/core/extensions/workflow-run-control.js.map +1 -1
- package/dist/core/fast-model-routing.d.ts.map +1 -1
- package/dist/core/fast-model-routing.js +1 -5
- package/dist/core/fast-model-routing.js.map +1 -1
- package/dist/core/model-config.d.ts +36 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +14 -2
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver-defaults.js +1 -1
- package/dist/core/model-resolver-defaults.js.map +1 -1
- package/dist/core/package-manager-auto-resources.d.ts.map +1 -1
- package/dist/core/package-manager-auto-resources.js +6 -2
- package/dist/core/package-manager-auto-resources.js.map +1 -1
- package/dist/core/package-manager-resolver.d.ts.map +1 -1
- package/dist/core/package-manager-resolver.js +4 -2
- package/dist/core/package-manager-resolver.js.map +1 -1
- package/dist/core/provider-composer-internal.d.ts +2 -1
- package/dist/core/provider-composer-internal.d.ts.map +1 -1
- package/dist/core/provider-composer-internal.js +13 -0
- package/dist/core/provider-composer-internal.js.map +1 -1
- package/dist/core/settings-manager-resource-accessors.js +7 -3
- package/dist/core/settings-manager-resource-accessors.js.map +1 -1
- package/dist/core/settings-merge.d.ts.map +1 -1
- package/dist/core/settings-merge.js +10 -0
- package/dist/core/settings-merge.js.map +1 -1
- package/dist/core/settings-types.d.ts +7 -1
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/extensions/mcp/index.d.ts.map +1 -1
- package/dist/extensions/mcp/index.js +20 -1
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/tools.d.ts +3 -1
- package/dist/extensions/mcp/tools.d.ts.map +1 -1
- package/dist/extensions/mcp/tools.js +19 -13
- package/dist/extensions/mcp/tools.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.d.ts +2 -3
- package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
- package/dist/modes/interactive/components/config-selector-list.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector-list.js +3 -1
- package/dist/modes/interactive/components/config-selector-list.js.map +1 -1
- package/dist/modes/interactive/components/config-selector-project-scope.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector-project-scope.js +2 -1
- package/dist/modes/interactive/components/config-selector-project-scope.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +2 -5
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +14 -40
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +3 -3
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-session-runtime.js +6 -1
- package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +5 -0
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive-engine/engine-custom-ui.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-custom-ui.js +9 -0
- package/dist/modes/interactive-engine/engine-custom-ui.js.map +1 -1
- package/dist/modes/interactive-engine/engine-render-service.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-render-service.js +10 -1
- package/dist/modes/interactive-engine/engine-render-service.js.map +1 -1
- package/dist/utils/image-convert.d.ts +5 -0
- package/dist/utils/image-convert.d.ts.map +1 -1
- package/dist/utils/image-convert.js +36 -6
- package/dist/utils/image-convert.js.map +1 -1
- package/docs/extensions.md +6 -0
- package/docs/models/reference.md +28 -1
- package/docs/models.md +4 -0
- package/docs/providers.md +10 -0
- package/docs/sdk.md +26 -2
- package/docs/settings.md +28 -1
- package/docs/workflows/operations.md +40 -4
- package/npm-shrinkwrap.json +71 -92
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-custom-ui.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-custom-ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EAKZ,aAAa,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAK9D,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAGN,WAAW,EAEX,6BAA6B,EAE7B,iCAAiC,GACjC,MAAM,eAAe,CAAC;AAkCvB,MAAM,cAAc;IACnB,OAAO,GAAG,EAAE,CAAC;IACb,IAAI,GAAG,EAAE,CAAC;IACV,mBAAmB,GAAG,KAAK,CAAC;IACX,UAAU,CAAa;IACvB,OAAO,CAAyD;IAChE,IAAI,CAA0D;IACvE,UAAU,GAAG,CAAC,CAAC;IACN,aAAa,GAAG,IAAI,GAAG,EAGrC,CAAC;IACJ,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AC,MAAM,EAAE,CAAC,CAAC;YAC5F,CAAC;YACD,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,MAAM,KAAK,IAAI;YAC7D,KAAK,EAAE,GAAG,EAAE;gBACX,OAAO,GAAG,IAAI,CAAC;gBACf,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;YAC5E,CAAC;YACD,OAAO,EAAE,GAAG,EAAE;gBACb,OAAO,GAAG,KAAK,CAAC;gBAChB,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;YAC9E,CAAC;YACD,SAAS,EAAE,GAAG,EAAE,CAAC,OAAO;YACxB,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS;SAC1B,CAAC;IACH,CAAC;IAEO,QAAQ,CAAI,WAAmB,EAAE,MAAS;QACjD,IAAI,CAAC,IAAI,CAAC;YACT,IAAI,EAAE,oBAAoB;YAC1B,WAAW;YACX,MAAM,EAAE,UAAU,CAAC,MAA+D,CAAC;SACnF,CAAC,CAAC;IACJ,CAAC;IAEO,IAAI,CAAC,OAAiC;QAC7C,IAAI,CAAC,KAAK,CAAC,iCAAiC,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC;CACD","sourcesContent":["import {\n\ttype Component,\n\tisKeyRelease,\n\ttype OverlayHandle,\n\ttype OverlayOptions,\n\ttype Terminal,\n\ttype TUI,\n\tTuiMainScreen,\n} from \"@earendil-works/pi-tui\";\nimport { getAgentDir } from \"../../config.js\";\nimport { runCallback } from \"../../core/callback-activity.ts\";\nimport type { HostCustomUiState, HostCustomUiStateListener } from \"../../core/extensions/index.js\";\nimport type { ScrollableWidgetComponent } from \"../../core/extensions/ui-types.js\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport type { Theme } from \"../interactive/theme/theme.js\";\nimport { theme } from \"../interactive/theme/theme.js\";\nimport {\n\ttype EngineTerminalControl,\n\ttype InteractiveEngineMessage,\n\tisJsonValue,\n\ttype JsonValue,\n\tparseInteractiveEngineCommand,\n\ttype SerializableOverlayOptions,\n\tserializeInteractiveEngineMessage,\n} from \"./protocol.ts\";\n\ninterface CustomUiOptions {\n\tpurpose?: \"prompt\" | \"navigation\";\n\toverlay?: boolean;\n\tdeferInlineCustomUiFocus?: boolean;\n\t/** The component binds Ctrl+C itself; see ExtensionUIContext.custom options. */\n\thandlesCtrlC?: boolean;\n\t/** The component claims internal UI actions such as the jump-to-bottom URL. */\n\thandlesInternalUiAction?: boolean;\n\t/** Bound this overlay and reserve transcript scroll extent on the host. */\n\treserveTranscriptRows?: boolean;\n\toverlayOptions?: OverlayOptions | (() => OverlayOptions);\n\tonHandle?: (handle: OverlayHandle) => void;\n\tsignal?: AbortSignal;\n}\n\ninterface ActiveComponent {\n\tcomponent: Component & { dispose?(): void };\n\tresolve: (value: JsonValue | undefined) => void;\n\toverlay: boolean;\n\tpurpose?: \"prompt\" | \"navigation\";\n\tterminal: RemoteTerminal;\n\ttui: TUI;\n\twidgetKey?: string;\n\t/**\n\t * Overlay visibility as last driven through the remote OverlayHandle.\n\t * Hidden components are skipped by the extension-level `requestRender()`\n\t * broadcast (#1856) — invalidating a hidden overlay only produced host\n\t * render work and terminal writes for frames the user cannot see.\n\t */\n\thidden?: boolean;\n}\n\nclass RemoteTerminal implements Terminal {\n\tcolumns = 80;\n\trows = 24;\n\tkittyProtocolActive = false;\n\tprivate readonly invalidate: () => void;\n\tprivate readonly control: ((control: EngineTerminalControl) => void) | undefined;\n\tprivate readonly copy: ((requestId: number, text: string) => void) | undefined;\n\tprivate nextCopyId = 0;\n\tprivate readonly pendingCopies = new Map<\n\t\tnumber,\n\t\t{ resolve: () => void; reject: (error: Error) => void; timer: ReturnType<typeof setTimeout> }\n\t>();\n\tconstructor(\n\t\tinvalidate: () => void,\n\t\tcontrol?: (control: EngineTerminalControl) => void,\n\t\tcopy?: (requestId: number, text: string) => void,\n\t) {\n\t\tthis.invalidate = invalidate;\n\t\tthis.control = control;\n\t\tthis.copy = copy;\n\t}\n\tcopyTextToHost(text: string): Promise<void> {\n\t\tif (!this.copy) return Promise.reject(new Error(\"Host clipboard unavailable\"));\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst requestId = ++this.nextCopyId;\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tthis.pendingCopies.delete(requestId);\n\t\t\t\treject(new Error(\"Host clipboard did not respond\"));\n\t\t\t}, 15_000);\n\t\t\tthis.pendingCopies.set(requestId, { resolve, reject, timer });\n\t\t\tthis.copy?.(requestId, text);\n\t\t});\n\t}\n\tresolveCopy(requestId: number, error?: string): void {\n\t\tconst pending = this.pendingCopies.get(requestId);\n\t\tif (!pending) return;\n\t\tclearTimeout(pending.timer);\n\t\tthis.pendingCopies.delete(requestId);\n\t\tif (error) pending.reject(new Error(error));\n\t\telse pending.resolve();\n\t}\n\tclose(): void {\n\t\tfor (const requestId of this.pendingCopies.keys()) this.resolveCopy(requestId, \"Sign-in screen closed\");\n\t}\n\tstart(): void {}\n\tstop(): void {}\n\tasync drainInput(): Promise<void> {}\n\twrite(): void {\n\t\tthis.invalidate();\n\t}\n\tmoveBy(): void {}\n\thideCursor(): void {}\n\tshowCursor(): void {}\n\tclearLine(): void {}\n\tclearFromCursor(): void {}\n\tclearScreen(): void {}\n\tsetTitle(): void {}\n\tsetProgress(): void {}\n\t/** Ask the host to toggle host-TTY autowrap (DECAWM) for this component. */\n\tsetAutowrap(enabled: boolean): void {\n\t\tthis.control?.({ kind: \"autowrap\", enabled });\n\t}\n}\n\nfunction serializableOverlayOptions(\n\toptions: CustomUiOptions[\"overlayOptions\"],\n): SerializableOverlayOptions | undefined {\n\tconst value = typeof options === \"function\" ? options() : options;\n\tif (!value) return undefined;\n\tconst { anchor, col, margin, maxHeight, minWidth, offsetX, offsetY, row, width } = value;\n\treturn { anchor, col, margin, maxHeight, minWidth, offsetX, offsetY, row, width };\n}\n\nfunction jsonResult(value: object | boolean | null | number | string | undefined): JsonValue | undefined {\n\tif (value === undefined) return undefined;\n\tconst encoded = JSON.stringify(value);\n\tif (encoded === undefined) return undefined;\n\tconst decoded = JSON.parse(encoded) as JsonValue;\n\tif (!isJsonValue(decoded)) throw new Error(\"Custom UI result is not JSON-safe\");\n\treturn decoded;\n}\n\nexport class EngineCustomUiService {\n\tprivate readonly widgetIds = new Map<string, string>();\n\tprivate readonly active = new Map<string, ActiveComponent>();\n\tprivate nextId = 0;\n\tprivate readonly write: (line: string) => void;\n\tprivate readonly keybindings: KeybindingsManager;\n\tprivate readonly stateListeners = new Set<HostCustomUiStateListener>();\n\tprivate readonly widgetReleaseListeners = new Map<string, Set<() => void>>();\n\n\tsetWidget(\n\t\tkey: string,\n\t\tfactory: ((tui: TUI, theme: Theme) => Component & { dispose?(): void }) | undefined,\n\t\tplacement?: \"aboveEditor\" | \"belowEditor\",\n\t\tscroll?: { maxHeight: number; maxHeightFraction?: number },\n\t): void {\n\t\tconst previous = this.widgetIds.get(key);\n\t\tif (previous) this.disposeComponent(previous, false, false);\n\t\tif (!factory) {\n\t\t\tthis.notifyWidgetRelease(key);\n\t\t\treturn;\n\t\t}\n\t\tconst componentId = `remote_widget_${++this.nextId}`;\n\t\tthis.widgetIds.set(key, componentId);\n\t\tconst terminal = new RemoteTerminal(() => this.send({ type: \"engine_custom_invalidate\", componentId }));\n\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\tvoid runCallback({ kind: \"renderer\", name: `widget:${key}` }, () => factory(tui, theme))\n\t\t\t.then((component) => {\n\t\t\t\tif (this.widgetIds.get(key) !== componentId) {\n\t\t\t\t\tcomponent.dispose?.();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttui.addChild(component);\n\t\t\t\tthis.active.set(componentId, {\n\t\t\t\t\tcomponent,\n\t\t\t\t\tresolve: () => {},\n\t\t\t\t\toverlay: false,\n\t\t\t\t\tterminal,\n\t\t\t\t\ttui,\n\t\t\t\t\twidgetKey: key,\n\t\t\t\t});\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_open\",\n\t\t\t\t\tcomponentId,\n\t\t\t\t\toverlay: false,\n\t\t\t\t\twidgetKey: key,\n\t\t\t\t\twidgetPlacement: placement,\n\t\t\t\t\t...(scroll ? { widgetScroll: scroll } : {}),\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((error: Error) => {\n\t\t\t\tif (this.widgetIds.get(key) === componentId) this.widgetIds.delete(key);\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\tcomponentId,\n\t\t\t\t\trequestId: 0,\n\t\t\t\t\tlines: [`Widget ${key} failed: ${error.message}`],\n\t\t\t\t});\n\t\t\t});\n\t}\n\tconstructor(write: (line: string) => void, keybindings: KeybindingsManager) {\n\t\tthis.write = write;\n\t\tthis.keybindings = keybindings;\n\t}\n\n\tasync custom<T>(\n\t\tfactory: (\n\t\t\ttui: TUI,\n\t\t\ttheme: Theme,\n\t\t\tkeybindings: KeybindingsManager,\n\t\t\tdone: (result: T) => void,\n\t\t) => (Component & { dispose?(): void }) | Promise<Component & { dispose?(): void }>,\n\t\toptions?: CustomUiOptions,\n\t): Promise<T> {\n\t\tconst componentId = `remote_component_${++this.nextId}`;\n\t\tlet resolveCompletion!: (value: T) => void;\n\t\tconst completion = new Promise<T>((resolve) => {\n\t\t\tresolveCompletion = resolve;\n\t\t});\n\t\tlet opened = false;\n\t\tlet pendingDone: T | undefined;\n\t\tlet doneCalled = false;\n\t\tconst done = (result: T): void => {\n\t\t\tif (doneCalled) return;\n\t\t\tdoneCalled = true;\n\t\t\tpendingDone = result;\n\t\t\tresolveCompletion(result);\n\t\t\tif (opened) this.sendDone(componentId, result);\n\t\t};\n\t\tconst terminal = new RemoteTerminal(\n\t\t\t() => this.send({ type: \"engine_custom_invalidate\", componentId }),\n\t\t\t(control) => this.send({ type: \"engine_custom_terminal\", componentId, control }),\n\t\t\t(requestId, text) => this.send({ type: \"engine_custom_copy\", componentId, requestId, text }),\n\t\t);\n\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\tconst component = await factory(tui, theme, this.keybindings, done);\n\t\ttui.addChild(component);\n\t\ttui.setFocus(component);\n\t\tconst record: ActiveComponent = {\n\t\t\tcomponent,\n\t\t\t// Cancellation must settle through the same guarded host completion as done().\n\t\t\tresolve: (value) => done(value as T),\n\t\t\tterminal,\n\t\t\ttui,\n\t\t\toverlay: options?.overlay === true,\n\t\t\tpurpose: options?.purpose,\n\t\t};\n\t\tthis.active.set(componentId, record);\n\t\tthis.notifyState();\n\t\topened = true;\n\t\tthis.send({\n\t\t\ttype: \"engine_custom_open\",\n\t\t\tcomponentId,\n\t\t\toverlay: options?.overlay === true,\n\t\t\tpurpose: options?.purpose,\n\t\t\tdeferInlineCustomUiFocus: options?.deferInlineCustomUiFocus,\n\t\t\thandlesCtrlC: options?.handlesCtrlC,\n\t\t\thandlesInternalUiAction: options?.handlesInternalUiAction,\n\t\t\treserveTranscriptRows: options?.reserveTranscriptRows,\n\t\t\toverlayOptions: serializableOverlayOptions(options?.overlayOptions),\n\t\t});\n\t\tif (options?.onHandle) options.onHandle(this.remoteHandle(componentId));\n\t\tif (doneCalled) this.sendDone(componentId, pendingDone as T);\n\t\tconst onAbort = () => this.disposeComponent(componentId, true);\n\t\toptions?.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\ttry {\n\t\t\treturn await completion;\n\t\t} finally {\n\t\t\toptions?.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\tthis.disposeComponent(componentId, false);\n\t\t}\n\t}\n\tgetHostCustomUiState(): HostCustomUiState {\n\t\tconst inline = [...this.active.values()].filter((record) => !record.overlay && !record.widgetKey);\n\t\tconst navigation = inline.filter((record) => record.purpose === \"navigation\").length;\n\t\treturn {\n\t\t\tblockingInlineCustomUiDepth: inline.length,\n\t\t\tblockingInlineCustomUiActive: inline.length > 0,\n\t\t\t...(navigation > 0 ? { blockingInlineCustomUiNeedsInput: inline.length > navigation } : {}),\n\t\t};\n\t}\n\n\tonHostCustomUiStateChange(listener: HostCustomUiStateListener): () => void {\n\t\tthis.stateListeners.add(listener);\n\t\treturn () => this.stateListeners.delete(listener);\n\t}\n\tonWidgetRelease(key: string, listener: () => void): () => void {\n\t\tconst listeners = this.widgetReleaseListeners.get(key) ?? new Set<() => void>();\n\t\tlisteners.add(listener);\n\t\tthis.widgetReleaseListeners.set(key, listeners);\n\t\treturn () => {\n\t\t\tlisteners.delete(listener);\n\t\t\tif (listeners.size === 0) this.widgetReleaseListeners.delete(key);\n\t\t};\n\t}\n\n\tfocusHostInlineCustomUi(): boolean {\n\t\treturn this.getHostCustomUiState().blockingInlineCustomUiActive;\n\t}\n\n\trequestRender(): void {\n\t\tfor (const [componentId, record] of this.active) {\n\t\t\tif (record.hidden === true) continue;\n\t\t\tthis.send({ type: \"engine_custom_invalidate\", componentId });\n\t\t}\n\t}\n\n\thandleLine(line: string): boolean {\n\t\tconst command = parseInteractiveEngineCommand(line);\n\t\tif (!command) return false;\n\t\tif (!command.type.startsWith(\"engine_custom_\")) return false;\n\t\tconst record = this.active.get(command.componentId);\n\t\tif (!record) {\n\t\t\tif (command.type === \"engine_custom_input\")\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_input_result\",\n\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\thandled: false,\n\t\t\t\t});\n\t\t\treturn true;\n\t\t}\n\t\tswitch (command.type) {\n\t\t\tcase \"engine_custom_scroll\":\n\t\t\t\t(record.component as ScrollableWidgetComponent).onScroll?.(command.state);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_render\":\n\t\t\t\trecord.terminal.columns = Math.max(1, command.width);\n\t\t\t\trecord.terminal.rows = Math.max(1, command.rows);\n\t\t\t\tvoid runCallback({ kind: \"renderer\", name: command.componentId }, () =>\n\t\t\t\t\trecord.component.render(record.terminal.columns),\n\t\t\t\t)\n\t\t\t\t\t.then((lines) => {\n\t\t\t\t\t\tconst scrollRequest = (record.component as ScrollableWidgetComponent).getScrollRequest?.();\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\tlines,\n\t\t\t\t\t\t\t...(scrollRequest ? { scrollRequest } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t})\n\t\t\t\t\t.catch((error: Error) =>\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\tlines: [`Remote component render failed: ${error.message}`],\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_input\":\n\t\t\t\tvoid runCallback({ kind: \"renderer\", name: command.componentId }, () => {\n\t\t\t\t\tif (isKeyRelease(command.data) && record.component.wantsKeyRelease !== true) return false;\n\t\t\t\t\tconst handleInput = record.component.handleInput as ((data: string) => boolean | undefined) | undefined;\n\t\t\t\t\treturn handleInput?.call(record.component, command.data) === true;\n\t\t\t\t})\n\t\t\t\t\t.then((handled) =>\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_input_result\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\thandled,\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t\t.catch(() =>\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_input_result\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\thandled: false,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_copy_result\":\n\t\t\t\trecord.terminal.resolveCopy(command.requestId, command.error);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_dispose\":\n\t\t\t\tthis.disposeComponent(command.componentId, true);\n\t\t\t\tbreak;\n\t\t}\n\t\treturn true;\n\t}\n\n\tdispose(): void {\n\t\tfor (const componentId of [...this.active.keys()]) this.disposeComponent(componentId, true, false);\n\t}\n\tprivate disposeComponent(componentId: string, resolve: boolean, notifyWidgetRelease = true): void {\n\t\tconst record = this.active.get(componentId);\n\t\tif (!record) return;\n\t\tthis.active.delete(componentId);\n\t\trecord.terminal.close();\n\t\t// Claim cancellation before user disposal code can call done() reentrantly.\n\t\tif (resolve) record.resolve(undefined);\n\t\trecord.component.dispose?.();\n\t\trecord.tui.stop();\n\t\tif (record.widgetKey) {\n\t\t\tif (this.widgetIds.get(record.widgetKey) === componentId) this.widgetIds.delete(record.widgetKey);\n\t\t\tthis.send({ type: \"engine_custom_close\", componentId });\n\t\t\tif (notifyWidgetRelease) this.notifyWidgetRelease(record.widgetKey);\n\t\t}\n\t\tthis.notifyState();\n\t}\n\tprivate notifyWidgetRelease(key: string): void {\n\t\tfor (const listener of this.widgetReleaseListeners.get(key) ?? []) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch {\n\t\t\t\t// A release observer must not break engine UI teardown.\n\t\t\t}\n\t\t}\n\t}\n\tprivate notifyState(): void {\n\t\tconst state = this.getHostCustomUiState();\n\t\tfor (const listener of this.stateListeners) listener(state);\n\t}\n\n\tprivate remoteHandle(componentId: string): OverlayHandle {\n\t\tlet focused = true;\n\t\tconst setHiddenFlag = (value: boolean): void => {\n\t\t\tconst record = this.active.get(componentId);\n\t\t\tif (record) record.hidden = value;\n\t\t};\n\t\treturn {\n\t\t\thide: () => {\n\t\t\t\tsetHiddenFlag(true);\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: \"hide\" });\n\t\t\t},\n\t\t\tsetHidden: (value) => {\n\t\t\t\tsetHiddenFlag(value);\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: value ? \"hide\" : \"show\" });\n\t\t\t},\n\t\t\tisHidden: () => this.active.get(componentId)?.hidden === true,\n\t\t\tfocus: () => {\n\t\t\t\tfocused = true;\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: \"focus\" });\n\t\t\t},\n\t\t\tunfocus: () => {\n\t\t\t\tfocused = false;\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: \"unfocus\" });\n\t\t\t},\n\t\t\tisFocused: () => focused,\n\t\t\tgetBounds: () => undefined,\n\t\t};\n\t}\n\n\tprivate sendDone<T>(componentId: string, result: T): void {\n\t\tthis.send({\n\t\t\ttype: \"engine_custom_done\",\n\t\t\tcomponentId,\n\t\t\tresult: jsonResult(result as object | boolean | null | number | string | undefined),\n\t\t});\n\t}\n\n\tprivate send(message: InteractiveEngineMessage): void {\n\t\tthis.write(serializeInteractiveEngineMessage(message));\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"engine-custom-ui.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-custom-ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EAKZ,aAAa,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAI9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAGN,WAAW,EAEX,6BAA6B,EAE7B,iCAAiC,GACjC,MAAM,eAAe,CAAC;AAkCvB,MAAM,cAAc;IACnB,OAAO,GAAG,E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C;SACnF,CAAC,CAAC;IACJ,CAAC;IAEO,IAAI,CAAC,OAAiC;QAC7C,IAAI,CAAC,KAAK,CAAC,iCAAiC,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC;CACD","sourcesContent":["import {\n\ttype Component,\n\tisKeyRelease,\n\ttype OverlayHandle,\n\ttype OverlayOptions,\n\ttype Terminal,\n\ttype TUI,\n\tTuiMainScreen,\n} from \"@earendil-works/pi-tui\";\nimport { getAgentDir } from \"../../config.js\";\nimport { runCallback } from \"../../core/callback-activity.ts\";\nimport type { HostCustomUiState, HostCustomUiStateListener } from \"../../core/extensions/index.js\";\nimport type { ScrollableWidgetComponent } from \"../../core/extensions/ui-types.js\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport { ensurePngTranscoder } from \"../../utils/image-convert.ts\";\nimport type { Theme } from \"../interactive/theme/theme.js\";\nimport { theme } from \"../interactive/theme/theme.js\";\nimport {\n\ttype EngineTerminalControl,\n\ttype InteractiveEngineMessage,\n\tisJsonValue,\n\ttype JsonValue,\n\tparseInteractiveEngineCommand,\n\ttype SerializableOverlayOptions,\n\tserializeInteractiveEngineMessage,\n} from \"./protocol.ts\";\n\ninterface CustomUiOptions {\n\tpurpose?: \"prompt\" | \"navigation\";\n\toverlay?: boolean;\n\tdeferInlineCustomUiFocus?: boolean;\n\t/** The component binds Ctrl+C itself; see ExtensionUIContext.custom options. */\n\thandlesCtrlC?: boolean;\n\t/** The component claims internal UI actions such as the jump-to-bottom URL. */\n\thandlesInternalUiAction?: boolean;\n\t/** Bound this overlay and reserve transcript scroll extent on the host. */\n\treserveTranscriptRows?: boolean;\n\toverlayOptions?: OverlayOptions | (() => OverlayOptions);\n\tonHandle?: (handle: OverlayHandle) => void;\n\tsignal?: AbortSignal;\n}\n\ninterface ActiveComponent {\n\tcomponent: Component & { dispose?(): void };\n\tresolve: (value: JsonValue | undefined) => void;\n\toverlay: boolean;\n\tpurpose?: \"prompt\" | \"navigation\";\n\tterminal: RemoteTerminal;\n\ttui: TUI;\n\twidgetKey?: string;\n\t/**\n\t * Overlay visibility as last driven through the remote OverlayHandle.\n\t * Hidden components are skipped by the extension-level `requestRender()`\n\t * broadcast (#1856) — invalidating a hidden overlay only produced host\n\t * render work and terminal writes for frames the user cannot see.\n\t */\n\thidden?: boolean;\n}\n\nclass RemoteTerminal implements Terminal {\n\tcolumns = 80;\n\trows = 24;\n\tkittyProtocolActive = false;\n\tprivate readonly invalidate: () => void;\n\tprivate readonly control: ((control: EngineTerminalControl) => void) | undefined;\n\tprivate readonly copy: ((requestId: number, text: string) => void) | undefined;\n\tprivate nextCopyId = 0;\n\tprivate readonly pendingCopies = new Map<\n\t\tnumber,\n\t\t{ resolve: () => void; reject: (error: Error) => void; timer: ReturnType<typeof setTimeout> }\n\t>();\n\tconstructor(\n\t\tinvalidate: () => void,\n\t\tcontrol?: (control: EngineTerminalControl) => void,\n\t\tcopy?: (requestId: number, text: string) => void,\n\t) {\n\t\tthis.invalidate = invalidate;\n\t\tthis.control = control;\n\t\tthis.copy = copy;\n\t}\n\tcopyTextToHost(text: string): Promise<void> {\n\t\tif (!this.copy) return Promise.reject(new Error(\"Host clipboard unavailable\"));\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst requestId = ++this.nextCopyId;\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tthis.pendingCopies.delete(requestId);\n\t\t\t\treject(new Error(\"Host clipboard did not respond\"));\n\t\t\t}, 15_000);\n\t\t\tthis.pendingCopies.set(requestId, { resolve, reject, timer });\n\t\t\tthis.copy?.(requestId, text);\n\t\t});\n\t}\n\tresolveCopy(requestId: number, error?: string): void {\n\t\tconst pending = this.pendingCopies.get(requestId);\n\t\tif (!pending) return;\n\t\tclearTimeout(pending.timer);\n\t\tthis.pendingCopies.delete(requestId);\n\t\tif (error) pending.reject(new Error(error));\n\t\telse pending.resolve();\n\t}\n\tclose(): void {\n\t\tfor (const requestId of this.pendingCopies.keys()) this.resolveCopy(requestId, \"Sign-in screen closed\");\n\t}\n\tstart(): void {}\n\tstop(): void {}\n\tasync drainInput(): Promise<void> {}\n\twrite(): void {\n\t\tthis.invalidate();\n\t}\n\tmoveBy(): void {}\n\thideCursor(): void {}\n\tshowCursor(): void {}\n\tclearLine(): void {}\n\tclearFromCursor(): void {}\n\tclearScreen(): void {}\n\tsetTitle(): void {}\n\tsetProgress(): void {}\n\t/** Ask the host to toggle host-TTY autowrap (DECAWM) for this component. */\n\tsetAutowrap(enabled: boolean): void {\n\t\tthis.control?.({ kind: \"autowrap\", enabled });\n\t}\n}\n\nfunction serializableOverlayOptions(\n\toptions: CustomUiOptions[\"overlayOptions\"],\n): SerializableOverlayOptions | undefined {\n\tconst value = typeof options === \"function\" ? options() : options;\n\tif (!value) return undefined;\n\tconst { anchor, col, margin, maxHeight, minWidth, offsetX, offsetY, row, width } = value;\n\treturn { anchor, col, margin, maxHeight, minWidth, offsetX, offsetY, row, width };\n}\n\nfunction jsonResult(value: object | boolean | null | number | string | undefined): JsonValue | undefined {\n\tif (value === undefined) return undefined;\n\tconst encoded = JSON.stringify(value);\n\tif (encoded === undefined) return undefined;\n\tconst decoded = JSON.parse(encoded) as JsonValue;\n\tif (!isJsonValue(decoded)) throw new Error(\"Custom UI result is not JSON-safe\");\n\treturn decoded;\n}\n\nexport class EngineCustomUiService {\n\tprivate readonly widgetIds = new Map<string, string>();\n\tprivate readonly active = new Map<string, ActiveComponent>();\n\tprivate nextId = 0;\n\tprivate readonly write: (line: string) => void;\n\tprivate readonly keybindings: KeybindingsManager;\n\tprivate readonly stateListeners = new Set<HostCustomUiStateListener>();\n\tprivate readonly widgetReleaseListeners = new Map<string, Set<() => void>>();\n\n\tsetWidget(\n\t\tkey: string,\n\t\tfactory: ((tui: TUI, theme: Theme) => Component & { dispose?(): void }) | undefined,\n\t\tplacement?: \"aboveEditor\" | \"belowEditor\",\n\t\tscroll?: { maxHeight: number; maxHeightFraction?: number },\n\t): void {\n\t\tconst previous = this.widgetIds.get(key);\n\t\tif (previous) this.disposeComponent(previous, false, false);\n\t\tif (!factory) {\n\t\t\tthis.notifyWidgetRelease(key);\n\t\t\treturn;\n\t\t}\n\t\tconst componentId = `remote_widget_${++this.nextId}`;\n\t\tthis.widgetIds.set(key, componentId);\n\t\tconst terminal = new RemoteTerminal(() => this.send({ type: \"engine_custom_invalidate\", componentId }));\n\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\tensurePngTranscoder(() => {\n\t\t\ttui.invalidate();\n\t\t\ttui.requestRender();\n\t\t});\n\t\tvoid runCallback({ kind: \"renderer\", name: `widget:${key}` }, () => factory(tui, theme))\n\t\t\t.then((component) => {\n\t\t\t\tif (this.widgetIds.get(key) !== componentId) {\n\t\t\t\t\tcomponent.dispose?.();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttui.addChild(component);\n\t\t\t\tthis.active.set(componentId, {\n\t\t\t\t\tcomponent,\n\t\t\t\t\tresolve: () => {},\n\t\t\t\t\toverlay: false,\n\t\t\t\t\tterminal,\n\t\t\t\t\ttui,\n\t\t\t\t\twidgetKey: key,\n\t\t\t\t});\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_open\",\n\t\t\t\t\tcomponentId,\n\t\t\t\t\toverlay: false,\n\t\t\t\t\twidgetKey: key,\n\t\t\t\t\twidgetPlacement: placement,\n\t\t\t\t\t...(scroll ? { widgetScroll: scroll } : {}),\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((error: Error) => {\n\t\t\t\tif (this.widgetIds.get(key) === componentId) this.widgetIds.delete(key);\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\tcomponentId,\n\t\t\t\t\trequestId: 0,\n\t\t\t\t\tlines: [`Widget ${key} failed: ${error.message}`],\n\t\t\t\t});\n\t\t\t});\n\t}\n\tconstructor(write: (line: string) => void, keybindings: KeybindingsManager) {\n\t\tthis.write = write;\n\t\tthis.keybindings = keybindings;\n\t}\n\n\tasync custom<T>(\n\t\tfactory: (\n\t\t\ttui: TUI,\n\t\t\ttheme: Theme,\n\t\t\tkeybindings: KeybindingsManager,\n\t\t\tdone: (result: T) => void,\n\t\t) => (Component & { dispose?(): void }) | Promise<Component & { dispose?(): void }>,\n\t\toptions?: CustomUiOptions,\n\t): Promise<T> {\n\t\tconst componentId = `remote_component_${++this.nextId}`;\n\t\tlet resolveCompletion!: (value: T) => void;\n\t\tconst completion = new Promise<T>((resolve) => {\n\t\t\tresolveCompletion = resolve;\n\t\t});\n\t\tlet opened = false;\n\t\tlet pendingDone: T | undefined;\n\t\tlet doneCalled = false;\n\t\tconst done = (result: T): void => {\n\t\t\tif (doneCalled) return;\n\t\t\tdoneCalled = true;\n\t\t\tpendingDone = result;\n\t\t\tresolveCompletion(result);\n\t\t\tif (opened) this.sendDone(componentId, result);\n\t\t};\n\t\tconst terminal = new RemoteTerminal(\n\t\t\t() => this.send({ type: \"engine_custom_invalidate\", componentId }),\n\t\t\t(control) => this.send({ type: \"engine_custom_terminal\", componentId, control }),\n\t\t\t(requestId, text) => this.send({ type: \"engine_custom_copy\", componentId, requestId, text }),\n\t\t);\n\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\tensurePngTranscoder(() => {\n\t\t\ttui.invalidate();\n\t\t\ttui.requestRender();\n\t\t});\n\t\tconst component = await factory(tui, theme, this.keybindings, done);\n\t\ttui.addChild(component);\n\t\ttui.setFocus(component);\n\t\tconst record: ActiveComponent = {\n\t\t\tcomponent,\n\t\t\t// Cancellation must settle through the same guarded host completion as done().\n\t\t\tresolve: (value) => done(value as T),\n\t\t\tterminal,\n\t\t\ttui,\n\t\t\toverlay: options?.overlay === true,\n\t\t\tpurpose: options?.purpose,\n\t\t};\n\t\tthis.active.set(componentId, record);\n\t\tthis.notifyState();\n\t\topened = true;\n\t\tthis.send({\n\t\t\ttype: \"engine_custom_open\",\n\t\t\tcomponentId,\n\t\t\toverlay: options?.overlay === true,\n\t\t\tpurpose: options?.purpose,\n\t\t\tdeferInlineCustomUiFocus: options?.deferInlineCustomUiFocus,\n\t\t\thandlesCtrlC: options?.handlesCtrlC,\n\t\t\thandlesInternalUiAction: options?.handlesInternalUiAction,\n\t\t\treserveTranscriptRows: options?.reserveTranscriptRows,\n\t\t\toverlayOptions: serializableOverlayOptions(options?.overlayOptions),\n\t\t});\n\t\tif (options?.onHandle) options.onHandle(this.remoteHandle(componentId));\n\t\tif (doneCalled) this.sendDone(componentId, pendingDone as T);\n\t\tconst onAbort = () => this.disposeComponent(componentId, true);\n\t\toptions?.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\ttry {\n\t\t\treturn await completion;\n\t\t} finally {\n\t\t\toptions?.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\tthis.disposeComponent(componentId, false);\n\t\t}\n\t}\n\tgetHostCustomUiState(): HostCustomUiState {\n\t\tconst inline = [...this.active.values()].filter((record) => !record.overlay && !record.widgetKey);\n\t\tconst navigation = inline.filter((record) => record.purpose === \"navigation\").length;\n\t\treturn {\n\t\t\tblockingInlineCustomUiDepth: inline.length,\n\t\t\tblockingInlineCustomUiActive: inline.length > 0,\n\t\t\t...(navigation > 0 ? { blockingInlineCustomUiNeedsInput: inline.length > navigation } : {}),\n\t\t};\n\t}\n\n\tonHostCustomUiStateChange(listener: HostCustomUiStateListener): () => void {\n\t\tthis.stateListeners.add(listener);\n\t\treturn () => this.stateListeners.delete(listener);\n\t}\n\tonWidgetRelease(key: string, listener: () => void): () => void {\n\t\tconst listeners = this.widgetReleaseListeners.get(key) ?? new Set<() => void>();\n\t\tlisteners.add(listener);\n\t\tthis.widgetReleaseListeners.set(key, listeners);\n\t\treturn () => {\n\t\t\tlisteners.delete(listener);\n\t\t\tif (listeners.size === 0) this.widgetReleaseListeners.delete(key);\n\t\t};\n\t}\n\n\tfocusHostInlineCustomUi(): boolean {\n\t\treturn this.getHostCustomUiState().blockingInlineCustomUiActive;\n\t}\n\n\trequestRender(): void {\n\t\tfor (const [componentId, record] of this.active) {\n\t\t\tif (record.hidden === true) continue;\n\t\t\tthis.send({ type: \"engine_custom_invalidate\", componentId });\n\t\t}\n\t}\n\n\thandleLine(line: string): boolean {\n\t\tconst command = parseInteractiveEngineCommand(line);\n\t\tif (!command) return false;\n\t\tif (!command.type.startsWith(\"engine_custom_\")) return false;\n\t\tconst record = this.active.get(command.componentId);\n\t\tif (!record) {\n\t\t\tif (command.type === \"engine_custom_input\")\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_input_result\",\n\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\thandled: false,\n\t\t\t\t});\n\t\t\treturn true;\n\t\t}\n\t\tswitch (command.type) {\n\t\t\tcase \"engine_custom_scroll\":\n\t\t\t\t(record.component as ScrollableWidgetComponent).onScroll?.(command.state);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_render\":\n\t\t\t\trecord.terminal.columns = Math.max(1, command.width);\n\t\t\t\trecord.terminal.rows = Math.max(1, command.rows);\n\t\t\t\tvoid runCallback({ kind: \"renderer\", name: command.componentId }, () =>\n\t\t\t\t\trecord.component.render(record.terminal.columns),\n\t\t\t\t)\n\t\t\t\t\t.then((lines) => {\n\t\t\t\t\t\tconst scrollRequest = (record.component as ScrollableWidgetComponent).getScrollRequest?.();\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\tlines,\n\t\t\t\t\t\t\t...(scrollRequest ? { scrollRequest } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t})\n\t\t\t\t\t.catch((error: Error) =>\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\tlines: [`Remote component render failed: ${error.message}`],\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_input\":\n\t\t\t\tvoid runCallback({ kind: \"renderer\", name: command.componentId }, () => {\n\t\t\t\t\tif (isKeyRelease(command.data) && record.component.wantsKeyRelease !== true) return false;\n\t\t\t\t\tconst handleInput = record.component.handleInput as ((data: string) => boolean | undefined) | undefined;\n\t\t\t\t\treturn handleInput?.call(record.component, command.data) === true;\n\t\t\t\t})\n\t\t\t\t\t.then((handled) =>\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_input_result\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\thandled,\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t\t.catch(() =>\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_input_result\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\thandled: false,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_copy_result\":\n\t\t\t\trecord.terminal.resolveCopy(command.requestId, command.error);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_dispose\":\n\t\t\t\tthis.disposeComponent(command.componentId, true);\n\t\t\t\tbreak;\n\t\t}\n\t\treturn true;\n\t}\n\n\tdispose(): void {\n\t\tfor (const componentId of [...this.active.keys()]) this.disposeComponent(componentId, true, false);\n\t}\n\tprivate disposeComponent(componentId: string, resolve: boolean, notifyWidgetRelease = true): void {\n\t\tconst record = this.active.get(componentId);\n\t\tif (!record) return;\n\t\tthis.active.delete(componentId);\n\t\trecord.terminal.close();\n\t\t// Claim cancellation before user disposal code can call done() reentrantly.\n\t\tif (resolve) record.resolve(undefined);\n\t\trecord.component.dispose?.();\n\t\trecord.tui.stop();\n\t\tif (record.widgetKey) {\n\t\t\tif (this.widgetIds.get(record.widgetKey) === componentId) this.widgetIds.delete(record.widgetKey);\n\t\t\tthis.send({ type: \"engine_custom_close\", componentId });\n\t\t\tif (notifyWidgetRelease) this.notifyWidgetRelease(record.widgetKey);\n\t\t}\n\t\tthis.notifyState();\n\t}\n\tprivate notifyWidgetRelease(key: string): void {\n\t\tfor (const listener of this.widgetReleaseListeners.get(key) ?? []) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch {\n\t\t\t\t// A release observer must not break engine UI teardown.\n\t\t\t}\n\t\t}\n\t}\n\tprivate notifyState(): void {\n\t\tconst state = this.getHostCustomUiState();\n\t\tfor (const listener of this.stateListeners) listener(state);\n\t}\n\n\tprivate remoteHandle(componentId: string): OverlayHandle {\n\t\tlet focused = true;\n\t\tconst setHiddenFlag = (value: boolean): void => {\n\t\t\tconst record = this.active.get(componentId);\n\t\t\tif (record) record.hidden = value;\n\t\t};\n\t\treturn {\n\t\t\thide: () => {\n\t\t\t\tsetHiddenFlag(true);\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: \"hide\" });\n\t\t\t},\n\t\t\tsetHidden: (value) => {\n\t\t\t\tsetHiddenFlag(value);\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: value ? \"hide\" : \"show\" });\n\t\t\t},\n\t\t\tisHidden: () => this.active.get(componentId)?.hidden === true,\n\t\t\tfocus: () => {\n\t\t\t\tfocused = true;\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: \"focus\" });\n\t\t\t},\n\t\t\tunfocus: () => {\n\t\t\t\tfocused = false;\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: \"unfocus\" });\n\t\t\t},\n\t\t\tisFocused: () => focused,\n\t\t\tgetBounds: () => undefined,\n\t\t};\n\t}\n\n\tprivate sendDone<T>(componentId: string, result: T): void {\n\t\tthis.send({\n\t\t\ttype: \"engine_custom_done\",\n\t\t\tcomponentId,\n\t\t\tresult: jsonResult(result as object | boolean | null | number | string | undefined),\n\t\t});\n\t}\n\n\tprivate send(message: InteractiveEngineMessage): void {\n\t\tthis.write(serializeInteractiveEngineMessage(message));\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-render-service.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-render-service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"engine-render-service.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-render-service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAuDhE,qBAAa,mBAAmB;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAC3D,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;IAE/C,YAAY,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAExC;IAED,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAGvC;IAED,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAgChC;IAED,OAAO,IAAI,IAAI,CAEd;IAED,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,UAAU;IA6ClB,OAAO,CAAC,aAAa;IA8BrB,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,IAAI;CAGZ"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TuiMainScreen } from "@earendil-works/pi-tui";
|
|
2
2
|
import { getAgentDir } from "../../config.js";
|
|
3
3
|
import { runCallback } from "../../core/callback-activity.js";
|
|
4
|
+
import { ensurePngTranscoder } from "../../utils/image-convert.js";
|
|
4
5
|
import { CustomMessageComponent } from "../interactive/components/custom-message.js";
|
|
5
6
|
import { ToolExecutionComponent } from "../interactive/components/tool-execution.js";
|
|
6
7
|
import { parseInteractiveEngineCommand, serializeInteractiveEngineMessage, } from "./protocol.js";
|
|
@@ -89,7 +90,11 @@ export class EngineRenderService {
|
|
|
89
90
|
const terminal = this.createTerminal(command.componentId);
|
|
90
91
|
terminal.columns = Math.max(1, command.width);
|
|
91
92
|
const tui = new TuiMainScreen(terminal, undefined, getAgentDir());
|
|
92
|
-
|
|
93
|
+
ensurePngTranscoder(() => {
|
|
94
|
+
tui.invalidate();
|
|
95
|
+
tui.requestRender();
|
|
96
|
+
});
|
|
97
|
+
const component = new ToolExecutionComponent(command.toolName, command.toolCallId, command.args, { showImages: command.showImages, imageWidthCells: command.imageWidthCells }, session.extensionRunner.resolveToolRenderers(command.toolName, () => session.getToolDefinition(command.toolName)), tui, session.sessionManager.getCwd());
|
|
93
98
|
tui.addChild(component);
|
|
94
99
|
record = { kind: "tool", component, terminal, tui };
|
|
95
100
|
this.records.set(command.componentId, record);
|
|
@@ -119,6 +124,10 @@ export class EngineRenderService {
|
|
|
119
124
|
const terminal = this.createTerminal(command.componentId);
|
|
120
125
|
terminal.columns = Math.max(1, command.width);
|
|
121
126
|
const tui = new TuiMainScreen(terminal, undefined, getAgentDir());
|
|
127
|
+
ensurePngTranscoder(() => {
|
|
128
|
+
tui.invalidate();
|
|
129
|
+
tui.requestRender();
|
|
130
|
+
});
|
|
122
131
|
const message = command.message;
|
|
123
132
|
const component = new CustomMessageComponent(message, session.extensionRunner.getMessageRenderer(message.customType), undefined, command.outputPad);
|
|
124
133
|
tui.addChild(component);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-render-service.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-render-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,WAA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AO,CAAC,SAAS,CAAC,CAAC;QACjD,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;IAEO,aAAa,CAAC,EAAU;QAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACxB,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM;YAAE,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QACvD,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;IAEO,IAAI,CAAC,OAAiC;QAC7C,IAAI,CAAC,KAAK,CAAC,iCAAiC,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC;CACD","sourcesContent":["import type { Terminal } from \"@earendil-works/pi-tui\";\nimport { type TUI, TuiMainScreen } from \"@earendil-works/pi-tui\";\nimport { getAgentDir } from \"../../config.js\";\nimport type { AgentSession } from \"../../core/agent-session.js\";\nimport { runCallback } from \"../../core/callback-activity.ts\";\nimport type { CustomMessage } from \"../../core/messages.ts\";\nimport { CustomMessageComponent } from \"../interactive/components/custom-message.ts\";\nimport { ToolExecutionComponent } from \"../interactive/components/tool-execution.ts\";\nimport {\n\ttype InteractiveEngineCommand,\n\ttype InteractiveEngineMessage,\n\tparseInteractiveEngineCommand,\n\tserializeInteractiveEngineMessage,\n} from \"./protocol.ts\";\n\ntype ToolRenderCommand = Extract<InteractiveEngineCommand, { type: \"engine_tool_render\" }>;\ntype MessageRenderCommand = Extract<InteractiveEngineCommand, { type: \"engine_message_render\" }>;\n\n/**\n * Cached per-componentId render state. Records are REUSED across render\n * requests: recreating (and re-seeding) the component on every request made\n * the seeding setters call `ui.requestRender()` each time, whose eventual\n * terminal write emitted `engine_custom_invalidate` back to the host, which\n * re-sent the render request — a self-sustaining host⇄engine render\n * ping-pong that presented as full-screen TUI flicker (quit/pause while a\n * workflow stage streams). Reuse plus idempotent seeding setters lets the\n * loop converge after at most one round trip while still forwarding\n * legitimate async invalidations (e.g. image conversion).\n */\ntype RenderRecord =\n\t| { kind: \"message\"; component: CustomMessageComponent; terminal: RenderTerminal; tui: TUI }\n\t| { kind: \"tool\"; component: ToolExecutionComponent; terminal: RenderTerminal; tui: TUI };\n\nclass RenderTerminal implements Terminal {\n\tcolumns = 80;\n\trows = 24;\n\tkittyProtocolActive = false;\n\tprivate readonly requestRender: () => void;\n\tconstructor(requestRender: () => void) {\n\t\tthis.requestRender = requestRender;\n\t}\n\tstart(): void {}\n\tstop(): void {}\n\tasync drainInput(): Promise<void> {}\n\twrite(): void {\n\t\tthis.requestRender();\n\t}\n\tmoveBy(): void {}\n\thideCursor(): void {}\n\tshowCursor(): void {}\n\tclearLine(): void {}\n\tclearFromCursor(): void {}\n\tclearScreen(): void {}\n\tsetTitle(): void {}\n\tsetProgress(): void {}\n}\n\nexport class EngineRenderService {\n\tprivate readonly records = new Map<string, RenderRecord>();\n\tprivate session: AgentSession | undefined;\n\tprivate readonly write: (line: string) => void;\n\n\tconstructor(write: (line: string) => void) {\n\t\tthis.write = write;\n\t}\n\n\tbindSession(session: AgentSession): void {\n\t\tthis.dispose();\n\t\tthis.session = session;\n\t}\n\n\thandleLine(line: string): boolean {\n\t\tconst command = parseInteractiveEngineCommand(line);\n\t\tif (!command?.type.startsWith(\"engine_\") || command.type.startsWith(\"engine_custom_\")) return false;\n\t\tif (command.type === \"engine_render_dispose\") {\n\t\t\tthis.disposeRecord(command.componentId);\n\t\t\treturn true;\n\t\t}\n\t\tif (command.type !== \"engine_tool_render\" && command.type !== \"engine_message_render\") return false;\n\t\tconst name =\n\t\t\tcommand.type === \"engine_tool_render\"\n\t\t\t\t? `tool:${command.toolName}`\n\t\t\t\t: `message:${command.message.customType ?? \"custom\"}`;\n\t\tvoid runCallback({ kind: \"renderer\", name }, async () => {\n\t\t\treturn command.type === \"engine_tool_render\" ? this.renderTool(command) : this.renderMessage(command);\n\t\t})\n\t\t\t.then((lines) =>\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\tlines,\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.catch((error: Error) =>\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\tlines: [`Remote renderer failed: ${error.message}`],\n\t\t\t\t}),\n\t\t\t);\n\t\treturn true;\n\t}\n\n\tdispose(): void {\n\t\tfor (const id of [...this.records.keys()]) this.disposeRecord(id);\n\t}\n\n\tprivate boundSession(): AgentSession {\n\t\tconst session = this.session;\n\t\tif (!session) throw new Error(\"Renderer session is not bound\");\n\t\treturn session;\n\t}\n\n\tprivate createTerminal(componentId: string): RenderTerminal {\n\t\treturn new RenderTerminal(() => this.send({ type: \"engine_custom_invalidate\", componentId }));\n\t}\n\n\tprivate renderTool(command: ToolRenderCommand): string[] {\n\t\tlet record = this.records.get(command.componentId);\n\t\tif (record?.kind !== \"tool\") {\n\t\t\tconst session = this.boundSession();\n\t\t\tthis.disposeRecord(command.componentId);\n\t\t\tconst terminal = this.createTerminal(command.componentId);\n\t\t\tterminal.columns = Math.max(1, command.width);\n\t\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\tcommand.toolName,\n\t\t\t\tcommand.toolCallId,\n\t\t\t\tcommand.args,\n\t\t\t\t{ showImages: command.showImages, imageWidthCells: command.imageWidthCells },\n\t\t\t\tsession.getToolDefinition(command.toolName),\n\t\t\t\ttui,\n\t\t\t\tsession.sessionManager.getCwd(),\n\t\t\t);\n\t\t\ttui.addChild(component);\n\t\t\trecord = { kind: \"tool\", component, terminal, tui };\n\t\t\tthis.records.set(command.componentId, record);\n\t\t} else {\n\t\t\trecord.terminal.columns = Math.max(1, command.width);\n\t\t\trecord.component.updateArgs(command.args);\n\t\t\trecord.component.setShowImages(command.showImages);\n\t\t\trecord.component.setImageWidthCells(command.imageWidthCells);\n\t\t}\n\t\tconst tool = record.component;\n\t\tif (command.executionStarted) tool.markExecutionStarted();\n\t\tif (command.argsComplete) tool.setArgsComplete();\n\t\ttool.setExpanded(command.expanded);\n\t\tif (command.result) {\n\t\t\ttool.updateResult(\n\t\t\t\tcommand.result as unknown as Parameters<ToolExecutionComponent[\"updateResult\"]>[0],\n\t\t\t\tcommand.isPartial,\n\t\t\t);\n\t\t}\n\t\treturn tool.render(command.width);\n\t}\n\n\tprivate renderMessage(command: MessageRenderCommand): string[] {\n\t\tlet record = this.records.get(command.componentId);\n\t\tif (record?.kind !== \"message\") {\n\t\t\tconst session = this.boundSession();\n\t\t\tthis.disposeRecord(command.componentId);\n\t\t\tconst terminal = this.createTerminal(command.componentId);\n\t\t\tterminal.columns = Math.max(1, command.width);\n\t\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\t\tconst message = command.message as unknown as CustomMessage<object>;\n\t\t\tconst component = new CustomMessageComponent(\n\t\t\t\tmessage,\n\t\t\t\tsession.extensionRunner.getMessageRenderer(message.customType),\n\t\t\t\tundefined,\n\t\t\t\tcommand.outputPad,\n\t\t\t);\n\t\t\ttui.addChild(component);\n\t\t\trecord = { kind: \"message\", component, terminal, tui };\n\t\t\tthis.records.set(command.componentId, record);\n\t\t} else {\n\t\t\trecord.terminal.columns = Math.max(1, command.width);\n\t\t}\n\t\trecord.component.setExpanded(command.expanded);\n\t\trecord.component.setOutputPad(command.outputPad);\n\t\treturn record.component.render(command.width);\n\t}\n\n\tprivate disposeRecord(id: string): void {\n\t\tconst record = this.records.get(id);\n\t\tif (!record) return;\n\t\tthis.records.delete(id);\n\t\tif (record.kind === \"tool\") record.component.dispose();\n\t\trecord.tui.stop();\n\t}\n\n\tprivate send(message: InteractiveEngineMessage): void {\n\t\tthis.write(serializeInteractiveEngineMessage(message));\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"engine-render-service.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-render-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,EAGN,6BAA6B,EAC7B,iCAAiC,GACjC,MAAM,eAAe,CAAC;AAoBvB,MAAM,cAAc;IACnB,OAAO,GAAG,EAAE,CAAC;IACb,IAAI,GAAG,EAAE,CAAC;IACV,mBAAmB,GAAG,KAAK,CAAC;IACX,aAAa,CAAa;IAC3C,YAAY,aAAyB;QACpC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,CAAC;IACD,KAAK,KAAU,CAAC;IAChB,IAAI,KAAU,CAAC;IACf,KAAK,CAAC,UAAU,KAAmB,CAAC;IACpC,KAAK;QACJ,IAAI,CAAC,aAAa,EAAE,CAAC;IACtB,CAAC;IACD,MAAM,KAAU,CAAC;IACjB,UAAU,KAAU,CAAC;IACrB,UAAU,KAAU,CAAC;IACrB,SAAS,KAAU,CAAC;IACpB,eAAe,KAAU,CAAC;IAC1B,WAAW,KAAU,CAAC;IACtB,QAAQ,KAAU,CAAC;IACnB,WAAW,KAAU,CAAC;CACtB;AAED,MAAM,OAAO,mBAAmB;IACd,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;IACnD,OAAO,CAA2B;IACzB,KAAK,CAAyB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I,CAAC,KAAK,CAAC,iCAAiC,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC;CACD","sourcesContent":["import type { Terminal } from \"@earendil-works/pi-tui\";\nimport { type TUI, TuiMainScreen } from \"@earendil-works/pi-tui\";\nimport { getAgentDir } from \"../../config.js\";\nimport type { AgentSession } from \"../../core/agent-session.js\";\nimport { runCallback } from \"../../core/callback-activity.ts\";\nimport type { CustomMessage } from \"../../core/messages.ts\";\nimport { ensurePngTranscoder } from \"../../utils/image-convert.ts\";\nimport { CustomMessageComponent } from \"../interactive/components/custom-message.ts\";\nimport { ToolExecutionComponent } from \"../interactive/components/tool-execution.ts\";\nimport {\n\ttype InteractiveEngineCommand,\n\ttype InteractiveEngineMessage,\n\tparseInteractiveEngineCommand,\n\tserializeInteractiveEngineMessage,\n} from \"./protocol.ts\";\n\ntype ToolRenderCommand = Extract<InteractiveEngineCommand, { type: \"engine_tool_render\" }>;\ntype MessageRenderCommand = Extract<InteractiveEngineCommand, { type: \"engine_message_render\" }>;\n\n/**\n * Cached per-componentId render state. Records are REUSED across render\n * requests: recreating (and re-seeding) the component on every request made\n * the seeding setters call `ui.requestRender()` each time, whose eventual\n * terminal write emitted `engine_custom_invalidate` back to the host, which\n * re-sent the render request — a self-sustaining host⇄engine render\n * ping-pong that presented as full-screen TUI flicker (quit/pause while a\n * workflow stage streams). Reuse plus idempotent seeding setters lets the\n * loop converge after at most one round trip while still forwarding\n * legitimate async invalidations (e.g. image conversion).\n */\ntype RenderRecord =\n\t| { kind: \"message\"; component: CustomMessageComponent; terminal: RenderTerminal; tui: TUI }\n\t| { kind: \"tool\"; component: ToolExecutionComponent; terminal: RenderTerminal; tui: TUI };\n\nclass RenderTerminal implements Terminal {\n\tcolumns = 80;\n\trows = 24;\n\tkittyProtocolActive = false;\n\tprivate readonly requestRender: () => void;\n\tconstructor(requestRender: () => void) {\n\t\tthis.requestRender = requestRender;\n\t}\n\tstart(): void {}\n\tstop(): void {}\n\tasync drainInput(): Promise<void> {}\n\twrite(): void {\n\t\tthis.requestRender();\n\t}\n\tmoveBy(): void {}\n\thideCursor(): void {}\n\tshowCursor(): void {}\n\tclearLine(): void {}\n\tclearFromCursor(): void {}\n\tclearScreen(): void {}\n\tsetTitle(): void {}\n\tsetProgress(): void {}\n}\n\nexport class EngineRenderService {\n\tprivate readonly records = new Map<string, RenderRecord>();\n\tprivate session: AgentSession | undefined;\n\tprivate readonly write: (line: string) => void;\n\n\tconstructor(write: (line: string) => void) {\n\t\tthis.write = write;\n\t}\n\n\tbindSession(session: AgentSession): void {\n\t\tthis.dispose();\n\t\tthis.session = session;\n\t}\n\n\thandleLine(line: string): boolean {\n\t\tconst command = parseInteractiveEngineCommand(line);\n\t\tif (!command?.type.startsWith(\"engine_\") || command.type.startsWith(\"engine_custom_\")) return false;\n\t\tif (command.type === \"engine_render_dispose\") {\n\t\t\tthis.disposeRecord(command.componentId);\n\t\t\treturn true;\n\t\t}\n\t\tif (command.type !== \"engine_tool_render\" && command.type !== \"engine_message_render\") return false;\n\t\tconst name =\n\t\t\tcommand.type === \"engine_tool_render\"\n\t\t\t\t? `tool:${command.toolName}`\n\t\t\t\t: `message:${command.message.customType ?? \"custom\"}`;\n\t\tvoid runCallback({ kind: \"renderer\", name }, async () => {\n\t\t\treturn command.type === \"engine_tool_render\" ? this.renderTool(command) : this.renderMessage(command);\n\t\t})\n\t\t\t.then((lines) =>\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\tlines,\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.catch((error: Error) =>\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\tlines: [`Remote renderer failed: ${error.message}`],\n\t\t\t\t}),\n\t\t\t);\n\t\treturn true;\n\t}\n\n\tdispose(): void {\n\t\tfor (const id of [...this.records.keys()]) this.disposeRecord(id);\n\t}\n\n\tprivate boundSession(): AgentSession {\n\t\tconst session = this.session;\n\t\tif (!session) throw new Error(\"Renderer session is not bound\");\n\t\treturn session;\n\t}\n\n\tprivate createTerminal(componentId: string): RenderTerminal {\n\t\treturn new RenderTerminal(() => this.send({ type: \"engine_custom_invalidate\", componentId }));\n\t}\n\n\tprivate renderTool(command: ToolRenderCommand): string[] {\n\t\tlet record = this.records.get(command.componentId);\n\t\tif (record?.kind !== \"tool\") {\n\t\t\tconst session = this.boundSession();\n\t\t\tthis.disposeRecord(command.componentId);\n\t\t\tconst terminal = this.createTerminal(command.componentId);\n\t\t\tterminal.columns = Math.max(1, command.width);\n\t\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\t\tensurePngTranscoder(() => {\n\t\t\t\ttui.invalidate();\n\t\t\t\ttui.requestRender();\n\t\t\t});\n\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\tcommand.toolName,\n\t\t\t\tcommand.toolCallId,\n\t\t\t\tcommand.args,\n\t\t\t\t{ showImages: command.showImages, imageWidthCells: command.imageWidthCells },\n\t\t\t\tsession.extensionRunner.resolveToolRenderers(command.toolName, () =>\n\t\t\t\t\tsession.getToolDefinition(command.toolName),\n\t\t\t\t),\n\t\t\t\ttui,\n\t\t\t\tsession.sessionManager.getCwd(),\n\t\t\t);\n\t\t\ttui.addChild(component);\n\t\t\trecord = { kind: \"tool\", component, terminal, tui };\n\t\t\tthis.records.set(command.componentId, record);\n\t\t} else {\n\t\t\trecord.terminal.columns = Math.max(1, command.width);\n\t\t\trecord.component.updateArgs(command.args);\n\t\t\trecord.component.setShowImages(command.showImages);\n\t\t\trecord.component.setImageWidthCells(command.imageWidthCells);\n\t\t}\n\t\tconst tool = record.component;\n\t\tif (command.executionStarted) tool.markExecutionStarted();\n\t\tif (command.argsComplete) tool.setArgsComplete();\n\t\ttool.setExpanded(command.expanded);\n\t\tif (command.result) {\n\t\t\ttool.updateResult(\n\t\t\t\tcommand.result as unknown as Parameters<ToolExecutionComponent[\"updateResult\"]>[0],\n\t\t\t\tcommand.isPartial,\n\t\t\t);\n\t\t}\n\t\treturn tool.render(command.width);\n\t}\n\n\tprivate renderMessage(command: MessageRenderCommand): string[] {\n\t\tlet record = this.records.get(command.componentId);\n\t\tif (record?.kind !== \"message\") {\n\t\t\tconst session = this.boundSession();\n\t\t\tthis.disposeRecord(command.componentId);\n\t\t\tconst terminal = this.createTerminal(command.componentId);\n\t\t\tterminal.columns = Math.max(1, command.width);\n\t\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\t\tensurePngTranscoder(() => {\n\t\t\t\ttui.invalidate();\n\t\t\t\ttui.requestRender();\n\t\t\t});\n\t\t\tconst message = command.message as unknown as CustomMessage<object>;\n\t\t\tconst component = new CustomMessageComponent(\n\t\t\t\tmessage,\n\t\t\t\tsession.extensionRunner.getMessageRenderer(message.customType),\n\t\t\t\tundefined,\n\t\t\t\tcommand.outputPad,\n\t\t\t);\n\t\t\ttui.addChild(component);\n\t\t\trecord = { kind: \"message\", component, terminal, tui };\n\t\t\tthis.records.set(command.componentId, record);\n\t\t} else {\n\t\t\trecord.terminal.columns = Math.max(1, command.width);\n\t\t}\n\t\trecord.component.setExpanded(command.expanded);\n\t\trecord.component.setOutputPad(command.outputPad);\n\t\treturn record.component.render(command.width);\n\t}\n\n\tprivate disposeRecord(id: string): void {\n\t\tconst record = this.records.get(id);\n\t\tif (!record) return;\n\t\tthis.records.delete(id);\n\t\tif (record.kind === \"tool\") record.component.dispose();\n\t\trecord.tui.stop();\n\t}\n\n\tprivate send(message: InteractiveEngineMessage): void {\n\t\tthis.write(serializeInteractiveEngineMessage(message));\n\t}\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ImageTranscoder } from "@earendil-works/pi-tui";
|
|
1
2
|
export declare function convertImageBytesToPng(bytes: Uint8Array): Promise<Uint8Array | null>;
|
|
2
3
|
/**
|
|
3
4
|
* Convert image to PNG format for terminal display.
|
|
@@ -7,4 +8,8 @@ export declare function convertToPng(base64Data: string, mimeType: string): Prom
|
|
|
7
8
|
data: string;
|
|
8
9
|
mimeType: string;
|
|
9
10
|
} | null>;
|
|
11
|
+
/** Load photon once and return a synchronous PNG transcoder for Kitty image rendering. */
|
|
12
|
+
export declare function loadPngTranscoder(): Promise<ImageTranscoder | undefined>;
|
|
13
|
+
/** Register the PNG transcoder on Kitty terminals, then redraw callers' fallback images. */
|
|
14
|
+
export declare function ensurePngTranscoder(onRegistered: () => void): void;
|
|
10
15
|
//# sourceMappingURL=image-convert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-convert.d.ts","sourceRoot":"","sources":["../../src/utils/image-convert.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-convert.d.ts","sourceRoot":"","sources":["../../src/utils/image-convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,eAAe,EAAsB,MAAM,wBAAwB,CAAC;AAsBnG,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAI1F;AAED;;;GAGG;AACH,wBAAsB,YAAY,CACjC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAgBpD;AAED,0FAA0F;AAC1F,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAO9E;AAKD,4FAA4F;AAC5F,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,IAAI,GAAG,IAAI,CAWlE"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
+
import { getCapabilities, setImageTranscoder } from "@earendil-works/pi-tui";
|
|
1
2
|
import { applyExifOrientation } from "./exif-orientation.js";
|
|
2
3
|
import { loadPhoton } from "./photon.js";
|
|
3
|
-
|
|
4
|
-
const photon = await loadPhoton();
|
|
5
|
-
if (!photon) {
|
|
6
|
-
// Photon not available, can't convert
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
4
|
+
function encodePng(photon, bytes) {
|
|
9
5
|
try {
|
|
10
6
|
const rawImage = photon.PhotonImage.new_from_byteslice(bytes);
|
|
11
7
|
const image = applyExifOrientation(photon, rawImage, bytes);
|
|
@@ -23,6 +19,12 @@ export async function convertImageBytesToPng(bytes) {
|
|
|
23
19
|
return null;
|
|
24
20
|
}
|
|
25
21
|
}
|
|
22
|
+
export async function convertImageBytesToPng(bytes) {
|
|
23
|
+
const photon = await loadPhoton();
|
|
24
|
+
if (!photon)
|
|
25
|
+
return null;
|
|
26
|
+
return encodePng(photon, bytes);
|
|
27
|
+
}
|
|
26
28
|
/**
|
|
27
29
|
* Convert image to PNG format for terminal display.
|
|
28
30
|
* Kitty graphics protocol requires PNG format (f=100).
|
|
@@ -42,4 +44,32 @@ export async function convertToPng(base64Data, mimeType) {
|
|
|
42
44
|
mimeType: "image/png",
|
|
43
45
|
};
|
|
44
46
|
}
|
|
47
|
+
/** Load photon once and return a synchronous PNG transcoder for Kitty image rendering. */
|
|
48
|
+
export async function loadPngTranscoder() {
|
|
49
|
+
const photon = await loadPhoton();
|
|
50
|
+
if (!photon)
|
|
51
|
+
return undefined;
|
|
52
|
+
return (base64Data) => {
|
|
53
|
+
const pngBytes = encodePng(photon, new Uint8Array(Buffer.from(base64Data, "base64")));
|
|
54
|
+
return pngBytes ? Buffer.from(pngBytes).toString("base64") : null;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
let pngTranscoderLoad;
|
|
58
|
+
let pngTranscoderRegistered = false;
|
|
59
|
+
/** Register the PNG transcoder on Kitty terminals, then redraw callers' fallback images. */
|
|
60
|
+
export function ensurePngTranscoder(onRegistered) {
|
|
61
|
+
if (pngTranscoderRegistered || getCapabilities().images !== "kitty")
|
|
62
|
+
return;
|
|
63
|
+
pngTranscoderLoad ??= loadPngTranscoder().then((transcoder) => {
|
|
64
|
+
if (!transcoder)
|
|
65
|
+
return false;
|
|
66
|
+
setImageTranscoder(transcoder);
|
|
67
|
+
pngTranscoderRegistered = true;
|
|
68
|
+
return true;
|
|
69
|
+
});
|
|
70
|
+
void pngTranscoderLoad.then((registered) => {
|
|
71
|
+
if (registered)
|
|
72
|
+
onRegistered();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
45
75
|
//# sourceMappingURL=image-convert.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-convert.js","sourceRoot":"","sources":["../../src/utils/image-convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"image-convert.js","sourceRoot":"","sources":["../../src/utils/image-convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAwB,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,SAAS,SAAS,CAAC,MAAc,EAAE,KAAiB;IACnD,IAAI,CAAC;QACJ,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,KAAK,GAAG,oBAAoB,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC5D,IAAI,KAAK,KAAK,QAAQ;YAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACxC,IAAI,CAAC;YACJ,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;QAC1C,CAAC;gBAAS,CAAC;YACV,KAAK,CAAC,IAAI,EAAE,CAAC;QACd,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,oBAAoB;QACpB,O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,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,CAAC,CAAC;AACH,CAAC;AAED,IAAI,iBAA+C,CAAC;AACpD,IAAI,uBAAuB,GAAG,KAAK,CAAC;AAEpC,4FAA4F;AAC5F,MAAM,UAAU,mBAAmB,CAAC,YAAwB;IAC3D,IAAI,uBAAuB,IAAI,eAAe,EAAE,CAAC,MAAM,KAAK,OAAO;QAAE,OAAO;IAC5E,iBAAiB,KAAK,iBAAiB,EAAE,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;QAC7D,IAAI,CAAC,UAAU;YAAE,OAAO,KAAK,CAAC;QAC9B,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAC/B,uBAAuB,GAAG,IAAI,CAAC;QAC/B,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAC;IACH,KAAK,iBAAiB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;QAC1C,IAAI,UAAU;YAAE,YAAY,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { getCapabilities, type ImageTranscoder, setImageTranscoder } from \"@earendil-works/pi-tui\";\nimport { applyExifOrientation } from \"./exif-orientation.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\ntype Photon = NonNullable<Awaited<ReturnType<typeof loadPhoton>>>;\n\nfunction encodePng(photon: Photon, bytes: Uint8Array): Uint8Array | null {\n\ttry {\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(bytes);\n\t\tconst image = applyExifOrientation(photon, rawImage, bytes);\n\t\tif (image !== rawImage) rawImage.free();\n\t\ttry {\n\t\t\treturn new Uint8Array(image.get_bytes());\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\t// Conversion failed\n\t\treturn null;\n\t}\n}\n\nexport async function convertImageBytesToPng(bytes: Uint8Array): Promise<Uint8Array | null> {\n\tconst photon = await loadPhoton();\n\tif (!photon) return null;\n\treturn encodePng(photon, bytes);\n}\n\n/**\n * Convert image to PNG format for terminal display.\n * Kitty graphics protocol requires PNG format (f=100).\n */\nexport async function convertToPng(\n\tbase64Data: string,\n\tmimeType: string,\n): Promise<{ data: string; mimeType: string } | null> {\n\t// Already PNG, no conversion needed\n\tif (mimeType === \"image/png\") {\n\t\treturn { data: base64Data, mimeType };\n\t}\n\n\tconst bytes = new Uint8Array(Buffer.from(base64Data, \"base64\"));\n\tconst pngBytes = await convertImageBytesToPng(bytes);\n\tif (!pngBytes) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\tdata: Buffer.from(pngBytes).toString(\"base64\"),\n\t\tmimeType: \"image/png\",\n\t};\n}\n\n/** Load photon once and return a synchronous PNG transcoder for Kitty image rendering. */\nexport async function loadPngTranscoder(): Promise<ImageTranscoder | undefined> {\n\tconst photon = await loadPhoton();\n\tif (!photon) return undefined;\n\treturn (base64Data) => {\n\t\tconst pngBytes = encodePng(photon, new Uint8Array(Buffer.from(base64Data, \"base64\")));\n\t\treturn pngBytes ? Buffer.from(pngBytes).toString(\"base64\") : null;\n\t};\n}\n\nlet pngTranscoderLoad: Promise<boolean> | undefined;\nlet pngTranscoderRegistered = false;\n\n/** Register the PNG transcoder on Kitty terminals, then redraw callers' fallback images. */\nexport function ensurePngTranscoder(onRegistered: () => void): void {\n\tif (pngTranscoderRegistered || getCapabilities().images !== \"kitty\") return;\n\tpngTranscoderLoad ??= loadPngTranscoder().then((transcoder) => {\n\t\tif (!transcoder) return false;\n\t\tsetImageTranscoder(transcoder);\n\t\tpngTranscoderRegistered = true;\n\t\treturn true;\n\t});\n\tvoid pngTranscoderLoad.then((registered) => {\n\t\tif (registered) onRegistered();\n\t});\n}\n"]}
|
package/docs/extensions.md
CHANGED
|
@@ -660,6 +660,12 @@ Moved to [Writing extensions](/extensions/authoring#multiple-tools).
|
|
|
660
660
|
|
|
661
661
|
Moved to [Writing extensions](/extensions/authoring#custom-rendering).
|
|
662
662
|
|
|
663
|
+
#### Tool rendering
|
|
664
|
+
|
|
665
|
+
A tool's `renderCall` and `renderResult` draw its calls in the interactive transcript and HTML exports. Use `pi.registerToolRenderer((toolName, next) => renderers)` to choose renderers for any tool, including MCP tools in resumed sessions before their server connects. Resolvers run in extension load order. `next()` returns the remaining resolvers' choice, then the registered tool's renderers, so `next() ?? mine` only fills in when none exist.
|
|
666
|
+
|
|
667
|
+
Extension `Image` components render JPEG, GIF, and WebP images on Kitty-protocol terminals automatically, just like tool result images.
|
|
668
|
+
|
|
663
669
|
#### renderCall
|
|
664
670
|
|
|
665
671
|
Moved to [Writing extensions](/extensions/authoring#rendercall).
|
package/docs/models/reference.md
CHANGED
|
@@ -95,6 +95,7 @@ In `models.json`, `headers` values must be strings. A `null` suppression marker
|
|
|
95
95
|
| `contextWindow` | No | `128000` | Default/effective context window size in tokens |
|
|
96
96
|
| `maxTokens` | No | `16384` | Maximum output tokens |
|
|
97
97
|
| `samplingParams` | No | omitted | Sampling parameters merged verbatim into every request body for OpenAI-compatible APIs (see below) |
|
|
98
|
+
| `samplingParamsByThinkingLevel` | No | omitted | Sampling parameter overrides keyed by Atomic thinking level for OpenAI-compatible APIs (see [Sampling by Thinking Level](#sampling-by-thinking-level)) |
|
|
98
99
|
| `cost` | No | all zeros | Complete base rates per million tokens plus optional request-wide `tiers` (see below) |
|
|
99
100
|
| `compat` | No | provider `compat` | Provider compatibility overrides. Merged with provider-level `compat` when both are set. |
|
|
100
101
|
| `compat.supportsMidConvoSystemMessages` | No | model default | Accept system/developer messages after the conversation starts |
|
|
@@ -207,6 +208,32 @@ The catalog can also record `inputLimits.maxRequestBytes`, `images.maxPerMessage
|
|
|
207
208
|
|
|
208
209
|
Only OpenAI-compatible APIs apply these values (`openai-completions`, `openai-responses`, and `azure-openai-responses`); other APIs ignore them. Per-request keys override model defaults and named request fields. In `modelOverrides`, `samplingParams` merges per key with the base model's values. Keys are provider-defined and remain unchanged; malformed `samplingParams` values are rejected while loading `models.json`.
|
|
209
210
|
|
|
211
|
+
### Sampling by Thinking Level
|
|
212
|
+
|
|
213
|
+
`samplingParamsByThinkingLevel` sets sampling parameters per thinking level on top of the model's `samplingParams`. Its keys are Atomic thinking levels (`off`, `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`), not the provider values from `thinkingLevelMap`:
|
|
214
|
+
|
|
215
|
+
```json
|
|
216
|
+
{
|
|
217
|
+
"id": "qwen-thinking-model",
|
|
218
|
+
"reasoning": true,
|
|
219
|
+
"samplingParams": {
|
|
220
|
+
"temperature": 1.0,
|
|
221
|
+
"top_p": 0.95
|
|
222
|
+
},
|
|
223
|
+
"samplingParamsByThinkingLevel": {
|
|
224
|
+
"off": {
|
|
225
|
+
"temperature": 0.7,
|
|
226
|
+
"top_p": 0.8
|
|
227
|
+
},
|
|
228
|
+
"high": {
|
|
229
|
+
"top_k": 20
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Atomic first clamps an unsupported thinking level to the nearest supported one, then merges the model's `samplingParams`, the effective level's override, and request-level `samplingParams` in that order. Later values win per key, and a level without an entry keeps the model defaults. In `modelOverrides`, each level's entry merges per key with the base model's entry for the same level. These fields apply only to `openai-completions`, `openai-responses`, and `azure-openai-responses`; other APIs ignore them. For `openai-completions` models with `compat.supportsTemperature: false`, the restricted keys are still removed from the final request, including keys that come from a level's override.
|
|
236
|
+
|
|
210
237
|
For vLLM OpenAI-compatible models that share the reasoning and answer budgets, set `compat.supportsThinkingTokenBudget` to `true`. Atomic sends the opt-in `thinking_token_budget` value for an enabled thinking level and always leaves 1024 tokens for the final answer. Pi's defaults are 1024, 2048, 8192, and 16384 tokens for `minimal`, `low`, `medium`, and `high`; the `thinkingBudgets` settings override them. `xhigh` and `max` use the `high` budget, and Atomic omits the field when no positive budget remains after reserving answer space.
|
|
211
238
|
|
|
212
239
|
Model references resolve the complete, unmodified ID before Atomic interprets thinking suffixes or glob syntax. For example, if the catalog contains the literal ID `provider/literal[free]:high`, that complete model wins and `:high` remains part of its ID; it does not become a thinking-level suffix and `[free]` is not treated as a character class. Only when the complete ID is absent does Atomic parse a valid thinking suffix, try the stripped exact ID, then apply glob/fuzzy matching. This preserves literal provider IDs without changing ordinary `*`, `?`, bracket-glob, ambiguity, ordering, or deduplication behavior.
|
|
@@ -413,7 +440,7 @@ Use `modelOverrides` to customize specific models without replacing the provider
|
|
|
413
440
|
}
|
|
414
441
|
```
|
|
415
442
|
|
|
416
|
-
`modelOverrides` supports these fields per model: `name`, `reasoning`, `thinkingLevelMap`, `input`, `inputLimits` (deep-merged), `cost` (partial scalar rates plus optional full tier-array replacement), `contextWindow`, `maxTokens`, `samplingParams` (merged per key), `headers`, `compat`.
|
|
443
|
+
`modelOverrides` supports these fields per model: `name`, `reasoning`, `thinkingLevelMap`, `input`, `inputLimits` (deep-merged), `cost` (partial scalar rates plus optional full tier-array replacement), `contextWindow`, `maxTokens`, `samplingParams` (merged per key), `samplingParamsByThinkingLevel` (merged per level, then per key), `headers`, `compat`.
|
|
417
444
|
|
|
418
445
|
Atomic reads one `models.json` from the active agent directory. It does not layer model overrides from `.pi` and `.atomic` files.
|
|
419
446
|
|
package/docs/models.md
CHANGED
|
@@ -165,6 +165,10 @@ Moved to [Model configuration reference](/models/reference#model-configuration).
|
|
|
165
165
|
|
|
166
166
|
Moved to [Model configuration reference](/models/reference#sampling-parameters).
|
|
167
167
|
|
|
168
|
+
### Sampling by Thinking Level
|
|
169
|
+
|
|
170
|
+
Moved to [Model configuration reference](/models/reference#sampling-by-thinking-level).
|
|
171
|
+
|
|
168
172
|
### Request-wide Cost Tiers
|
|
169
173
|
|
|
170
174
|
Moved to [Model configuration reference](/models/reference#request-wide-cost-tiers).
|
package/docs/providers.md
CHANGED
|
@@ -334,6 +334,16 @@ Legacy uppercase env-var-like values such as `MY_API_KEY` are migrated to `$MY_A
|
|
|
334
334
|
|
|
335
335
|
The providers below have additional setup, need additional settings, or can use credentials supplied by their platform.
|
|
336
336
|
|
|
337
|
+
### NVIDIA NIM
|
|
338
|
+
|
|
339
|
+
NVIDIA's built-in default is `nvidia/nemotron-3-ultra-550b-a55b`. Saved and explicit model choices still take precedence. To select this model explicitly:
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
atomic --provider nvidia --model nvidia/nemotron-3-ultra-550b-a55b
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Use `--list-models` or `/model` to check the current catalog and replace a missing saved model. A catalog listing does not verify account access or serving availability.
|
|
346
|
+
|
|
337
347
|
### Azure OpenAI
|
|
338
348
|
|
|
339
349
|
```bash
|
package/docs/sdk.md
CHANGED
|
@@ -228,7 +228,7 @@ Web provider configuration caches are session-local. Configuration discovery and
|
|
|
228
228
|
|
|
229
229
|
### Workflow run control
|
|
230
230
|
|
|
231
|
-
`session.workflows`
|
|
231
|
+
`session.workflows` controls this session's workflow runs without slash commands or the model-facing `workflow` tool. A fresh session can also inspect a durable root from another session by its full UUID, within the same working directory and configured workflow database. Inspection stays read-only and does not add the run to `listRuns()`.
|
|
232
232
|
|
|
233
233
|
```typescript
|
|
234
234
|
interface SessionWorkflows {
|
|
@@ -244,6 +244,30 @@ interface SessionWorkflows {
|
|
|
244
244
|
|
|
245
245
|
`listRuns()` returns the same per-run data as `workflow status`: id, workflow name, status, active stages, and unanswered prompts (`awaitingInput`). Run IDs accept the full UUID or a unique 8-character prefix. `getRun()`, `getStages()`, `pause()` and `quit()` resolve a prefix against the runs this session holds and reject it at once when none matches, so pass the full UUID for a run recorded by an earlier process. `pause`, `quit` and `resume` resolve with the tool's acknowledged outcome: `action`, `runId` (`--all` for a batch), a `status` of `ok`, `running`, `paused`, `partial`, `noop` or `cancelled`, and a human-readable `message`. A `noop` means the request was understood and found nothing to change, such as pausing a run that already ended. A `partial` outcome means part of the request took effect. For `pause({ all: true })` and `quit({ all: true })`, `partial` means this call stopped at least one run and others are still active: `failedRuns` lists each run that is still active with its `runId`, a `reason` (for example `pause_failed` or `no_active_stages`) and a `message`, so check `outcome.status === "partial"` before treating a batch stop as complete. If active runs could not be stopped and this call stopped none, the call rejects with `WorkflowRunControlError` (`WORKFLOW_RUN_CONTROL_FAILED`) whose `failedRuns` carries the same list, even when other runs were already paused. Runs that are already paused or already ended are not failures, and a batch with no active run left to stop resolves as a `noop`. Call `getRun()` before retrying.
|
|
246
246
|
|
|
247
|
+
After an owning process crashes, create a new authorized SDK session with the original `cwd` and workflow database configuration. Keep the workflow definition available, then call `getRun(runId)` with the saved full UUID. Once its progress has been stale for about two minutes and its database ownership connection is gone, status reports `crashed`. `resume(runId)` claims the durable run only after the database excludes the previous owner and any unfinished database writes. It continues under the same UUID and replays completed checkpoints. This works with `SessionManager.inMemory()` and does not require reopening a session file. Concurrent recovery attempts admit only one executor; inspect again if another caller won the claim.
|
|
248
|
+
|
|
249
|
+
A healthy connected foreign owner remains read-only, even while a long-running tool has not refreshed workflow progress or a VM clone cannot see its PID. `pause()` and `quit()` still require its owning session, and `resume()` cannot adopt another session's live, paused, or terminal run. Missing ownership metadata, a different working directory, or unavailable database ownership verification prevents adoption. Older runs without database-fenced ownership remain inspectable but cannot use this distributed recovery path. Recovery from a crashed foreign process requires the full UUID, not a prefix. A host using only the non-durable in-memory workflow backend cannot recover after process loss.
|
|
250
|
+
|
|
251
|
+
Live-cloned SDK hosts must share one authoritative PostgreSQL server and database. Configure a shared database endpoint for those hosts. Copying the managed PostgreSQL directory into another VM creates an independent database, even if both use the same `localhost` URL; separate databases cannot enforce cross-VM ownership exclusion.
|
|
252
|
+
|
|
253
|
+
Use a direct PostgreSQL connection or a proxy that preserves each client's database session. Ownership locks and write authorization depend on session affinity. Transaction-mode and statement-mode pooling, including those PgBouncer modes, are unsupported for the workflow database.
|
|
254
|
+
|
|
255
|
+
Database fencing protects ownership and durable checkpoints, not arbitrary external effects. If an owner loses its database connection, recovery may overlap an unfinished callback in that still-running process. The old owner cannot save new checkpoints, but an interrupted `ctx.tool` callback can be retried before the old callback stops. Make external effects idempotent, for example by passing a stable run/node operation key to an API that deduplicates requests. Completed checkpoints are replayed without rerunning their callbacks; unfinished callbacks do not have exactly-once execution guarantees.
|
|
256
|
+
|
|
257
|
+
An execution that loses its ownership connection cannot silently regain write authority. Restore database availability, inspect the retained run, and resume explicitly. Recovery uses a fresh execution generation while the disconnected generation stays fenced. Keep the database and completed checkpoints; deleting them is not a recovery step.
|
|
258
|
+
|
|
259
|
+
For an older run without database-fenced ownership, stop every older Atomic worker connected to its workflow database before enrollment. Upgrade the recovery host, retain the original database and workflow definition, and create an authorized SDK session with the original `cwd`. Inspect the full UUID, then explicitly confirm the stopped-worker prerequisite:
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
await session.workflows.resume(runId, {
|
|
263
|
+
legacyRecovery: { olderWorkersStopped: true },
|
|
264
|
+
});
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
This enrolls an eligible legacy root in database fencing and resumes it under the same UUID, preserving completed checkpoints. The option is an operator assertion, not a mechanism that stops workers. Never pass it while an older worker may still be executing. It does not permit recovery in another working directory, stage-only enrollment, or overriding a healthy fenced owner. Ordinary `resume(runId)` does not automatically adopt an unfenced legacy owner; inspection and existing owner-scoped controls remain available.
|
|
268
|
+
|
|
269
|
+
If the recovery host crashes after enrollment but before execution starts, inspect the full UUID and retry the same explicit option from a fresh session. Retry is permitted only for an interrupted enrollment whose database owner is no longer live. It does not allow takeover of another session's generally paused or blocked fenced run.
|
|
270
|
+
|
|
247
271
|
Pausing a run doesn't park a stage that is waiting on a prompt, including an `ask_user_question` delivered through `HostInput.questionnaire`. If no other work is active, `pause(runId)` and `pause({ all: true })` mark the run `paused` without cancelling its question. Questions not yet shown wait until the run resumes. A later pause counts it as already paused. If your host then answers an already-open prompt, the stage can continue its turn before you call `resume`. To keep a paused run fully stopped, hold prompt answers until you resume it.
|
|
248
272
|
|
|
249
273
|
Requests that cannot be carried out reject with a subclass of `WorkflowRunControlError`. Branch on `code` or use `instanceof`:
|
|
@@ -251,7 +275,7 @@ Requests that cannot be carried out reject with a subclass of `WorkflowRunContro
|
|
|
251
275
|
| Class | `code` | Meaning |
|
|
252
276
|
| --- | --- | --- |
|
|
253
277
|
| `WorkflowRunNotFoundError` | `WORKFLOW_RUN_NOT_FOUND` | The run ID is unknown or malformed, or a prefix is ambiguous or matches no run in this session. |
|
|
254
|
-
| `WorkflowRunOwnershipError` | `WORKFLOW_RUN_OWNED_ELSEWHERE` |
|
|
278
|
+
| `WorkflowRunOwnershipError` | `WORKFLOW_RUN_OWNED_ELSEWHERE` | Mutation requires another session's ownership, the run is still live, or the durable run is outside this host's recovery scope. Inspect it read-only when in scope; control live work from its owner. |
|
|
255
279
|
| `WorkflowRunNotResumableError` | `WORKFLOW_RUN_NOT_RESUMABLE` | The run completed, was killed, or has no durable progress to resume. |
|
|
256
280
|
| `WorkflowStageNotFoundError` | `WORKFLOW_STAGE_NOT_FOUND` | `stageId` matches no stage of the run, or the stage has no control to pause. |
|
|
257
281
|
| `WorkflowStageAmbiguousError` | `WORKFLOW_STAGE_AMBIGUOUS` | `stageId` matches more than one stage; pass a more specific identifier. |
|
package/docs/settings.md
CHANGED
|
@@ -532,11 +532,38 @@ Paths in `~/.atomic/agent/settings.json` resolve relative to `~/.atomic/agent`.
|
|
|
532
532
|
| `skills` | string[] | `[]` | Local skill file paths or directories |
|
|
533
533
|
| `prompts` | string[] | `[]` | Local prompt template paths or directories |
|
|
534
534
|
| `themes` | string[] | `[]` | Local theme file paths or directories |
|
|
535
|
-
| `workflows` | string[] | `[]` | Local workflow
|
|
535
|
+
| `workflows` | string[] or object | `[]` | Local workflow paths, or `{ "paths": [...], "durability": {...} }`; see [Workflow database](#workflow-database) |
|
|
536
536
|
| `enableSkillCommands` | boolean | `true` | Register skills as `/skill:name` commands |
|
|
537
537
|
|
|
538
538
|
Arrays support glob patterns and exclusions. Use `!pattern` to exclude. Use `+path` to force-include an exact path and `-path` to force-exclude an exact path.
|
|
539
539
|
|
|
540
|
+
#### Workflow database
|
|
541
|
+
|
|
542
|
+
Choose an existing PostgreSQL database in global or trusted project settings:
|
|
543
|
+
|
|
544
|
+
```json
|
|
545
|
+
{
|
|
546
|
+
"workflows": {
|
|
547
|
+
"paths": ["./workflows"],
|
|
548
|
+
"durability": {
|
|
549
|
+
"systemDatabaseUrlFile": "~/.atomic/neon/direct.url"
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
| Setting | Type | Default | Description |
|
|
556
|
+
|---------|------|---------|-------------|
|
|
557
|
+
| `workflows.paths` | string[] | `[]` | Workflow resource paths in object-form settings; existing `workflows: [...]` settings remain supported |
|
|
558
|
+
| `workflows.durability.systemDatabaseUrl` | string | - | PostgreSQL URL for the workflow database |
|
|
559
|
+
| `workflows.durability.systemDatabaseUrlFile` | string | - | Read the PostgreSQL URL from a UTF-8 file instead of storing credentials in settings |
|
|
560
|
+
|
|
561
|
+
Set only one URL source per scope. A project `durability` object replaces the global database selection; project settings are ignored unless trusted. Relative URL-file paths resolve beside the settings file that declares them: `~/.atomic/agent` for global settings and `.atomic` for project settings, or the matching `.pi` directory for inherited pi settings. Absolute paths and `~/` are supported. Protect credential files with permissions appropriate for your account, and do not commit them.
|
|
562
|
+
|
|
563
|
+
Precedence is nonempty `DBOS_SYSTEM_DATABASE_URL`, then settings, then managed embedded PostgreSQL with Docker as its provisioning fallback. URLs and file contents are trimmed. Invalid settings, including unrecognized `durability` keys, or missing, empty, or invalid URL files stop workflow initialization instead of silently choosing a local database. An explicit URL never starts managed PostgreSQL or Docker, even if the endpoint is unavailable. Existing non-durable fallback warnings still apply when DBOS cannot connect.
|
|
564
|
+
|
|
565
|
+
Restart Atomic after changing the database selection. Selection takes effect on the first workflow action. Interactive and RPC sessions then report the selected provider and host without credentials; headless sessions report only a Docker fallback, on stderr. Changing databases does not migrate existing runs; use the original database to inspect or resume them. See [Durable workflows](/workflows/operations#durable-workflows-and-cross-session-resume).
|
|
566
|
+
|
|
540
567
|
#### packages
|
|
541
568
|
|
|
542
569
|
String form loads all resources from a package:
|