apex-code 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/client/transcript.d.ts.map +1 -1
- package/dist/client/transcript.js +1 -1
- package/dist/client/transcript.js.map +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +2 -1
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/delegation/runtime.d.ts.map +1 -1
- package/dist/core/delegation/runtime.js +2 -2
- package/dist/core/delegation/runtime.js.map +1 -1
- package/dist/core/durable-state/daemon.d.ts.map +1 -1
- package/dist/core/durable-state/daemon.js +1 -1
- package/dist/core/durable-state/daemon.js.map +1 -1
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +3 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/types.d.ts +8 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybindings.d.ts +2 -2
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +1 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/mcp/mcp-tool.d.ts.map +1 -1
- package/dist/core/mcp/mcp-tool.js +2 -4
- package/dist/core/mcp/mcp-tool.js.map +1 -1
- package/dist/core/mcp/oauth/authorize.d.ts.map +1 -1
- package/dist/core/mcp/oauth/authorize.js +7 -2
- package/dist/core/mcp/oauth/authorize.js.map +1 -1
- package/dist/core/mcp/runtime.d.ts +2 -2
- package/dist/core/mcp/runtime.d.ts.map +1 -1
- package/dist/core/mcp/runtime.js +8 -3
- package/dist/core/mcp/runtime.js.map +1 -1
- package/dist/core/permissions/store.d.ts +7 -2
- package/dist/core/permissions/store.d.ts.map +1 -1
- package/dist/core/permissions/store.js +6 -1
- package/dist/core/permissions/store.js.map +1 -1
- package/dist/core/project-resources.d.ts +12 -0
- package/dist/core/project-resources.d.ts.map +1 -1
- package/dist/core/project-resources.js +19 -0
- package/dist/core/project-resources.js.map +1 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +10 -1
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/resource-loader.d.ts +6 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +9 -3
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +3 -3
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +16 -3
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +38 -15
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/bash.d.ts +9 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +29 -16
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +50 -10
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/path-utils.d.ts +9 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -1
- package/dist/core/tools/path-utils.js +235 -10
- package/dist/core/tools/path-utils.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +3 -3
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/workspace/state.d.ts.map +1 -1
- package/dist/core/workspace/state.js +1 -1
- package/dist/core/workspace/state.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +3 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/diff.d.ts.map +1 -1
- package/dist/modes/interactive/components/diff.js +2 -2
- package/dist/modes/interactive/components/diff.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +3 -2
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/model-row.d.ts +84 -0
- package/dist/modes/interactive/components/model-row.d.ts.map +1 -0
- package/dist/modes/interactive/components/model-row.js +206 -0
- package/dist/modes/interactive/components/model-row.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +39 -4
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +158 -27
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +2 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +8 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +53 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +100 -27
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +16 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +19 -1
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/tsconfig.json +3 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +1 -1
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +22 -22
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/docs/models.md +1 -1
- package/examples/extensions/gondolin/package-lock.json +3 -3
- package/examples/extensions/minimal-mode.ts +6 -6
- package/examples/extensions/sandbox/package-lock.json +4 -4
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/sdk/10-settings.ts +2 -2
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +19 -34
- package/package.json +6 -6
|
@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,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAEvD;IACD,eAAe,IAAI,MAAM,CAExB;IACD,OAAO,IAAI,IAAI,CAEd;CAQD","sourcesContent":["import { type GitProvenance, readGitProvenance } from \"./provenance.ts\";\nimport {\n\ttype CommandJournalRecord,\n\ttype DurableStateStore,\n\topenDurableStateStore,\n\ttype RecoveryDiagnostic,\n\ttype SessionLeaseMode,\n\ttype SessionLeaseRecord,\n} from \"./sqlite.ts\";\n\nexport interface DurableStateDaemonOptions {\n\tdatabasePath: string;\n\tdaemonId: string;\n\tcwd?: string;\n}\nexport interface AttachClientInput {\n\tsessionId: string;\n\tclientId: string;\n\tmode: SessionLeaseMode;\n\tttlMs: number;\n}\nexport interface MutationInput {\n\tid?: string;\n\tsessionId: string;\n\tclientId: string;\n\tcommand: string;\n}\n\n/**\n * Local daemon state coordinator. All session mutations are admitted through a\n * durable lease and journaled before the caller receives its operation callback.\n */\nexport class DurableStateDaemon {\n\treadonly recoveryDiagnostics: readonly RecoveryDiagnostic[];\n\treadonly provenance: GitProvenance;\n\treadonly #store: DurableStateStore;\n\treadonly #attachments = new Map<string, Map<string, SessionLeaseRecord>>();\n\n\tconstructor(options: DurableStateDaemonOptions) {\n\t\tthis.#store = openDurableStateStore(options.databasePath);\n\t\tthis.provenance = readGitProvenance(options.cwd ?? process.cwd());\n\t\tthis.recoveryDiagnostics = this.#store.recoverUnfinishedCommandsWithDiagnostics(\n\t\t\t`daemon ${options.daemonId} started before command completion`,\n\t\t);\n\t}\n\n\tattach(input: AttachClientInput): SessionLeaseRecord {\n\t\tconst lease = this.#store.acquireLease({\n\t\t\tsessionId: input.sessionId,\n\t\t\townerId: input.clientId,\n\t\t\tmode: input.mode,\n\t\t\tttlMs: input.ttlMs,\n\t\t});\n\t\tconst clients = this.#attachments.get(input.sessionId) ?? new Map<string, SessionLeaseRecord>();\n\t\tclients.set(input.clientId, lease);\n\t\tthis.#attachments.set(input.sessionId, clients);\n\t\treturn lease;\n\t}\n\n\tdetach(sessionId: string, clientId: string): void {\n\t\tthis.#store.releaseLease(sessionId, clientId);\n\t\tconst clients = this.#attachments.get(sessionId);\n\t\tif (!clients) return;\n\t\tclients.delete(clientId);\n\t\tif (clients.size === 0) this.#attachments.delete(sessionId);\n\t}\n\n\tbeginMutation(input: MutationInput): CommandJournalRecord {\n\t\tthis.#requireExclusiveAttachment(input.sessionId, input.clientId);\n\t\treturn this.#store.beginCommand({ id: input.id, sessionId: input.sessionId, command: input.command });\n\t}\n\n\tasync runMutation<T>(input: MutationInput, operation: () => Promise<T>): Promise<T> {\n\t\tthis.#requireExclusiveAttachment(input.sessionId, input.clientId);\n\t\treturn this.#store.runCommand({ id: input.id, sessionId: input.sessionId, command: input.command }, operation);\n\t}\n\n\tgetCommand(id: string): CommandJournalRecord | undefined {\n\t\treturn this.#store.getCommand(id);\n\t}\n\tgetCommandCount(): number {\n\t\treturn this.#store.commandCount();\n\t}\n\tdispose(): void {\n\t\tthis.#store.close();\n\t}\n\n\t#requireExclusiveAttachment(sessionId: string, clientId: string): void {\n\t\tconst attachment = this.#attachments.get(sessionId)?.get(clientId);\n\t\tif (
|
|
1
|
+
{"version":3,"file":"daemon.d.ts","sourceRoot":"","sources":["../../../src/core/durable-state/daemon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAqB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EACN,KAAK,oBAAoB,EAGzB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,yBAAyB;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AACD,MAAM,WAAW,iBAAiB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACd;AACD,MAAM,WAAW,aAAa;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,qBAAa,kBAAkB;;IAC9B,QAAQ,CAAC,mBAAmB,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAC5D,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC;IAInC,YAAY,OAAO,EAAE,yBAAyB,EAM7C;IAED,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,CAWnD;IAED,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAMhD;IAED,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,oBAAoB,CAGxD;IAEK,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAGlF;IAED,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAEvD;IACD,eAAe,IAAI,MAAM,CAExB;IACD,OAAO,IAAI,IAAI,CAEd;CAQD","sourcesContent":["import { type GitProvenance, readGitProvenance } from \"./provenance.ts\";\nimport {\n\ttype CommandJournalRecord,\n\ttype DurableStateStore,\n\topenDurableStateStore,\n\ttype RecoveryDiagnostic,\n\ttype SessionLeaseMode,\n\ttype SessionLeaseRecord,\n} from \"./sqlite.ts\";\n\nexport interface DurableStateDaemonOptions {\n\tdatabasePath: string;\n\tdaemonId: string;\n\tcwd?: string;\n}\nexport interface AttachClientInput {\n\tsessionId: string;\n\tclientId: string;\n\tmode: SessionLeaseMode;\n\tttlMs: number;\n}\nexport interface MutationInput {\n\tid?: string;\n\tsessionId: string;\n\tclientId: string;\n\tcommand: string;\n}\n\n/**\n * Local daemon state coordinator. All session mutations are admitted through a\n * durable lease and journaled before the caller receives its operation callback.\n */\nexport class DurableStateDaemon {\n\treadonly recoveryDiagnostics: readonly RecoveryDiagnostic[];\n\treadonly provenance: GitProvenance;\n\treadonly #store: DurableStateStore;\n\treadonly #attachments = new Map<string, Map<string, SessionLeaseRecord>>();\n\n\tconstructor(options: DurableStateDaemonOptions) {\n\t\tthis.#store = openDurableStateStore(options.databasePath);\n\t\tthis.provenance = readGitProvenance(options.cwd ?? process.cwd());\n\t\tthis.recoveryDiagnostics = this.#store.recoverUnfinishedCommandsWithDiagnostics(\n\t\t\t`daemon ${options.daemonId} started before command completion`,\n\t\t);\n\t}\n\n\tattach(input: AttachClientInput): SessionLeaseRecord {\n\t\tconst lease = this.#store.acquireLease({\n\t\t\tsessionId: input.sessionId,\n\t\t\townerId: input.clientId,\n\t\t\tmode: input.mode,\n\t\t\tttlMs: input.ttlMs,\n\t\t});\n\t\tconst clients = this.#attachments.get(input.sessionId) ?? new Map<string, SessionLeaseRecord>();\n\t\tclients.set(input.clientId, lease);\n\t\tthis.#attachments.set(input.sessionId, clients);\n\t\treturn lease;\n\t}\n\n\tdetach(sessionId: string, clientId: string): void {\n\t\tthis.#store.releaseLease(sessionId, clientId);\n\t\tconst clients = this.#attachments.get(sessionId);\n\t\tif (!clients) return;\n\t\tclients.delete(clientId);\n\t\tif (clients.size === 0) this.#attachments.delete(sessionId);\n\t}\n\n\tbeginMutation(input: MutationInput): CommandJournalRecord {\n\t\tthis.#requireExclusiveAttachment(input.sessionId, input.clientId);\n\t\treturn this.#store.beginCommand({ id: input.id, sessionId: input.sessionId, command: input.command });\n\t}\n\n\tasync runMutation<T>(input: MutationInput, operation: () => Promise<T>): Promise<T> {\n\t\tthis.#requireExclusiveAttachment(input.sessionId, input.clientId);\n\t\treturn this.#store.runCommand({ id: input.id, sessionId: input.sessionId, command: input.command }, operation);\n\t}\n\n\tgetCommand(id: string): CommandJournalRecord | undefined {\n\t\treturn this.#store.getCommand(id);\n\t}\n\tgetCommandCount(): number {\n\t\treturn this.#store.commandCount();\n\t}\n\tdispose(): void {\n\t\tthis.#store.close();\n\t}\n\n\t#requireExclusiveAttachment(sessionId: string, clientId: string): void {\n\t\tconst attachment = this.#attachments.get(sessionId)?.get(clientId);\n\t\tif (attachment?.mode !== \"exclusive\" || Date.parse(attachment.expiresAt) <= Date.now()) {\n\t\t\tthrow new Error(`Client does not hold an active exclusive lease for ${sessionId}`);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -54,7 +54,7 @@ export class DurableStateDaemon {
|
|
|
54
54
|
}
|
|
55
55
|
#requireExclusiveAttachment(sessionId, clientId) {
|
|
56
56
|
const attachment = this.#attachments.get(sessionId)?.get(clientId);
|
|
57
|
-
if (
|
|
57
|
+
if (attachment?.mode !== "exclusive" || Date.parse(attachment.expiresAt) <= Date.now()) {
|
|
58
58
|
throw new Error(`Client does not hold an active exclusive lease for ${sessionId}`);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daemon.js","sourceRoot":"","sources":["../../../src/core/durable-state/daemon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAGN,qBAAqB,GAIrB,MAAM,aAAa,CAAC;AAoBrB;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IACrB,mBAAmB,CAAgC;IACnD,UAAU,CAAgB;IAC1B,MAAM,CAAoB;IAC1B,YAAY,GAAG,IAAI,GAAG,EAA2C,CAAC;IAE3E,YAAY,OAAkC,EAAE;QAC/C,IAAI,CAAC,MAAM,GAAG,qBAAqB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC1D,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAClE,IAAI,CAAC,mBAAmB,GAAG,I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U,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;YACxF,MAAM,IAAI,KAAK,CAAC,sDAAsD,SAAS,EAAE,CAAC,CAAC;QACpF,CAAC;IAAA,CACD;CACD","sourcesContent":["import { type GitProvenance, readGitProvenance } from \"./provenance.ts\";\nimport {\n\ttype CommandJournalRecord,\n\ttype DurableStateStore,\n\topenDurableStateStore,\n\ttype RecoveryDiagnostic,\n\ttype SessionLeaseMode,\n\ttype SessionLeaseRecord,\n} from \"./sqlite.ts\";\n\nexport interface DurableStateDaemonOptions {\n\tdatabasePath: string;\n\tdaemonId: string;\n\tcwd?: string;\n}\nexport interface AttachClientInput {\n\tsessionId: string;\n\tclientId: string;\n\tmode: SessionLeaseMode;\n\tttlMs: number;\n}\nexport interface MutationInput {\n\tid?: string;\n\tsessionId: string;\n\tclientId: string;\n\tcommand: string;\n}\n\n/**\n * Local daemon state coordinator. All session mutations are admitted through a\n * durable lease and journaled before the caller receives its operation callback.\n */\nexport class DurableStateDaemon {\n\treadonly recoveryDiagnostics: readonly RecoveryDiagnostic[];\n\treadonly provenance: GitProvenance;\n\treadonly #store: DurableStateStore;\n\treadonly #attachments = new Map<string, Map<string, SessionLeaseRecord>>();\n\n\tconstructor(options: DurableStateDaemonOptions) {\n\t\tthis.#store = openDurableStateStore(options.databasePath);\n\t\tthis.provenance = readGitProvenance(options.cwd ?? process.cwd());\n\t\tthis.recoveryDiagnostics = this.#store.recoverUnfinishedCommandsWithDiagnostics(\n\t\t\t`daemon ${options.daemonId} started before command completion`,\n\t\t);\n\t}\n\n\tattach(input: AttachClientInput): SessionLeaseRecord {\n\t\tconst lease = this.#store.acquireLease({\n\t\t\tsessionId: input.sessionId,\n\t\t\townerId: input.clientId,\n\t\t\tmode: input.mode,\n\t\t\tttlMs: input.ttlMs,\n\t\t});\n\t\tconst clients = this.#attachments.get(input.sessionId) ?? new Map<string, SessionLeaseRecord>();\n\t\tclients.set(input.clientId, lease);\n\t\tthis.#attachments.set(input.sessionId, clients);\n\t\treturn lease;\n\t}\n\n\tdetach(sessionId: string, clientId: string): void {\n\t\tthis.#store.releaseLease(sessionId, clientId);\n\t\tconst clients = this.#attachments.get(sessionId);\n\t\tif (!clients) return;\n\t\tclients.delete(clientId);\n\t\tif (clients.size === 0) this.#attachments.delete(sessionId);\n\t}\n\n\tbeginMutation(input: MutationInput): CommandJournalRecord {\n\t\tthis.#requireExclusiveAttachment(input.sessionId, input.clientId);\n\t\treturn this.#store.beginCommand({ id: input.id, sessionId: input.sessionId, command: input.command });\n\t}\n\n\tasync runMutation<T>(input: MutationInput, operation: () => Promise<T>): Promise<T> {\n\t\tthis.#requireExclusiveAttachment(input.sessionId, input.clientId);\n\t\treturn this.#store.runCommand({ id: input.id, sessionId: input.sessionId, command: input.command }, operation);\n\t}\n\n\tgetCommand(id: string): CommandJournalRecord | undefined {\n\t\treturn this.#store.getCommand(id);\n\t}\n\tgetCommandCount(): number {\n\t\treturn this.#store.commandCount();\n\t}\n\tdispose(): void {\n\t\tthis.#store.close();\n\t}\n\n\t#requireExclusiveAttachment(sessionId: string, clientId: string): void {\n\t\tconst attachment = this.#attachments.get(sessionId)?.get(clientId);\n\t\tif (attachment?.mode !== \"exclusive\" || Date.parse(attachment.expiresAt) <= Date.now()) {\n\t\t\tthrow new Error(`Client does not hold an active exclusive lease for ${sessionId}`);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-renderer.d.ts","sourceRoot":"","sources":["../../../src/core/export-html/tool-renderer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,wBAAwB,CAAC;AAGhF,MAAM,WAAW,oBAAoB;IACpC,kDAAkD;IAClD,iBAAiB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,cAAc,GAAG,SAAS,C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D,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAChC,oFAAoF;IACpF,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IACpF,yGAAyG;IACzG,YAAY,CACX,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,EAChF,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,GACd;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;CACzD;AAsBD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG,gBAAgB,CAqHnF","sourcesContent":["/**\n * Tool HTML renderer for custom tools in HTML export.\n *\n * Renders custom tool calls and results to HTML by invoking their TUI renderers\n * and converting the ANSI output to HTML.\n */\n\nimport type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport type { Component } from \"@earendil-works/pi-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition, ToolRenderContext } from \"../extensions/types.ts\";\nimport { ansiLinesToHtml } from \"./ansi-to-html.ts\";\n\nexport interface ToolHtmlRendererDeps {\n\t/** Function to look up tool definition by name */\n\tgetToolDefinition: (name: string) => ToolDefinition | undefined;\n\t/** Theme for styling */\n\ttheme: Theme;\n\t/** Working directory for render context */\n\tcwd: string;\n\t/** Terminal width for rendering (default: 100) */\n\twidth?: number;\n}\n\nexport interface ToolHtmlRenderer {\n\t/** Render a tool call to HTML. Returns undefined if tool has no custom renderer. */\n\trenderCall(toolCallId: string, toolName: string, args: unknown): string | undefined;\n\t/** Render a tool result to collapsed/expanded HTML. Returns undefined if tool has no custom renderer. */\n\trenderResult(\n\t\ttoolCallId: string,\n\t\ttoolName: string,\n\t\tresult: Array<{ type: string; text?: string; data?: string; mimeType?: string }>,\n\t\tdetails: unknown,\n\t\tisError: boolean,\n\t): { collapsed?: string; expanded?: string } | undefined;\n}\n\n/**\n * Create a tool HTML renderer.\n *\n * The renderer looks up tool definitions and invokes their renderCall/renderResult\n * methods, converting the resulting TUI Component output (ANSI) to HTML.\n */\nconst ANSI_ESCAPE_REGEX = /\\x1b\\[[\\d;]*m/g;\n\nfunction isBlankRenderedLine(line: string): boolean {\n\treturn line.replace(ANSI_ESCAPE_REGEX, \"\").trim().length === 0;\n}\n\nfunction trimRenderedResultLines(lines: string[]): string[] {\n\tlet start = 0;\n\tlet end = lines.length;\n\twhile (start < end && isBlankRenderedLine(lines[start])) start++;\n\twhile (end > start && isBlankRenderedLine(lines[end - 1])) end--;\n\treturn lines.slice(start, end);\n}\n\nexport function createToolHtmlRenderer(deps: ToolHtmlRendererDeps): ToolHtmlRenderer {\n\tconst { getToolDefinition, theme, cwd, width = 100 } = deps;\n\n\tconst renderedCallComponents = new Map<string, Component>();\n\tconst renderedResultComponents = new Map<string, Component>();\n\tconst renderedStates = new Map<string, any>();\n\tconst renderedArgs = new Map<string, unknown>();\n\n\tconst getState = (toolCallId: string): any => {\n\t\tlet state = renderedStates.get(toolCallId);\n\t\tif (!state) {\n\t\t\tstate = {};\n\t\t\trenderedStates.set(toolCallId, state);\n\t\t}\n\t\treturn state;\n\t};\n\n\tconst createRenderContext = (\n\t\ttoolCallId: string,\n\t\tlastComponent: Component | undefined,\n\t\texpanded: boolean,\n\t\tisPartial: boolean,\n\t\tisError: boolean,\n\t): ToolRenderContext => {\n\t\treturn {\n\t\t\targs: renderedArgs.get(toolCallId),\n\t\t\ttoolCallId,\n\t\t\tinvalidate: () => {},\n\t\t\tlastComponent,\n\t\t\tstate: getState(toolCallId),\n\t\t\tcwd,\n\t\t\texecutionStarted: true,\n\t\t\targsComplete: true,\n\t\t\tisPartial,\n\t\t\texpanded,\n\t\t\t// A static export has no detail cycle to reveal a diff later, so it\n\t\t\t// always carries the full one.\n\t\t\teditDiffsExpanded: true,\n\t\t\tshowImages: false,\n\t\t\tisError,\n\t\t};\n\t};\n\n\treturn {\n\t\trenderCall(toolCallId: string, toolName: string, args: unknown): string | undefined {\n\t\t\ttry {\n\t\t\t\trenderedArgs.set(toolCallId, args);\n\t\t\t\tconst toolDef = getToolDefinition(toolName);\n\t\t\t\tif (!toolDef?.renderCall) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tconst component = toolDef.renderCall(\n\t\t\t\t\targs,\n\t\t\t\t\ttheme,\n\t\t\t\t\tcreateRenderContext(toolCallId, renderedCallComponents.get(toolCallId), false, true, false),\n\t\t\t\t);\n\t\t\t\trenderedCallComponents.set(toolCallId, component);\n\t\t\t\tconst lines = component.render(width);\n\t\t\t\treturn ansiLinesToHtml(lines);\n\t\t\t} catch {\n\t\t\t\t// On error, return undefined so HTML export can fall back to structured result rendering\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\n\t\trenderResult(\n\t\t\ttoolCallId: string,\n\t\t\ttoolName: string,\n\t\t\tresult: Array<{ type: string; text?: string; data?: string; mimeType?: string }>,\n\t\t\tdetails: unknown,\n\t\t\tisError: boolean,\n\t\t): { collapsed?: string; expanded?: string } | undefined {\n\t\t\ttry {\n\t\t\t\tconst toolDef = getToolDefinition(toolName);\n\t\t\t\tif (!toolDef?.renderResult) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\t// Build AgentToolResult from content array\n\t\t\t\t// Cast content since session storage uses generic object types\n\t\t\t\tconst agentToolResult = {\n\t\t\t\t\tcontent: result as (TextContent | ImageContent)[],\n\t\t\t\t\tdetails,\n\t\t\t\t\tisError,\n\t\t\t\t};\n\n\t\t\t\t// Render collapsed\n\t\t\t\tconst collapsedComponent = toolDef.renderResult(\n\t\t\t\t\tagentToolResult,\n\t\t\t\t\t{ expanded: false, isPartial: false },\n\t\t\t\t\ttheme,\n\t\t\t\t\tcreateRenderContext(toolCallId, renderedResultComponents.get(toolCallId), false, false, isError),\n\t\t\t\t);\n\t\t\t\trenderedResultComponents.set(toolCallId, collapsedComponent);\n\t\t\t\tconst collapsed = ansiLinesToHtml(trimRenderedResultLines(collapsedComponent.render(width)));\n\n\t\t\t\t// Render expanded\n\t\t\t\tconst expandedComponent = toolDef.renderResult(\n\t\t\t\t\tagentToolResult,\n\t\t\t\t\t{ expanded: true, isPartial: false },\n\t\t\t\t\ttheme,\n\t\t\t\t\tcreateRenderContext(toolCallId, renderedResultComponents.get(toolCallId), true, false, isError),\n\t\t\t\t);\n\t\t\t\trenderedResultComponents.set(toolCallId, expandedComponent);\n\t\t\t\tconst expanded = ansiLinesToHtml(trimRenderedResultLines(expandedComponent.render(width)));\n\n\t\t\t\treturn {\n\t\t\t\t\t...(collapsed && collapsed !== expanded ? { collapsed } : {}),\n\t\t\t\t\texpanded,\n\t\t\t\t};\n\t\t\t} catch {\n\t\t\t\t// On error, return undefined so HTML export can fall back to structured result rendering\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
@@ -50,6 +50,9 @@ export function createToolHtmlRenderer(deps) {
|
|
|
50
50
|
argsComplete: true,
|
|
51
51
|
isPartial,
|
|
52
52
|
expanded,
|
|
53
|
+
// A static export has no detail cycle to reveal a diff later, so it
|
|
54
|
+
// always carries the full one.
|
|
55
|
+
editDiffsExpanded: true,
|
|
53
56
|
showImages: false,
|
|
54
57
|
isError,
|
|
55
58
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-renderer.js","sourceRoot":"","sources":["../../../src/core/export-html/tool-renderer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EAAE,eAAe,EAAE,MAAM,mB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,uBAAuB,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAE3F,OAAO;oBACN,GAAG,CAAC,SAAS,IAAI,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC7D,QAAQ;iBACR,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACR,yFAAyF;gBACzF,OAAO,SAAS,CAAC;YAClB,CAAC;QAAA,CACD;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Tool HTML renderer for custom tools in HTML export.\n *\n * Renders custom tool calls and results to HTML by invoking their TUI renderers\n * and converting the ANSI output to HTML.\n */\n\nimport type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport type { Component } from \"@earendil-works/pi-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition, ToolRenderContext } from \"../extensions/types.ts\";\nimport { ansiLinesToHtml } from \"./ansi-to-html.ts\";\n\nexport interface ToolHtmlRendererDeps {\n\t/** Function to look up tool definition by name */\n\tgetToolDefinition: (name: string) => ToolDefinition | undefined;\n\t/** Theme for styling */\n\ttheme: Theme;\n\t/** Working directory for render context */\n\tcwd: string;\n\t/** Terminal width for rendering (default: 100) */\n\twidth?: number;\n}\n\nexport interface ToolHtmlRenderer {\n\t/** Render a tool call to HTML. Returns undefined if tool has no custom renderer. */\n\trenderCall(toolCallId: string, toolName: string, args: unknown): string | undefined;\n\t/** Render a tool result to collapsed/expanded HTML. Returns undefined if tool has no custom renderer. */\n\trenderResult(\n\t\ttoolCallId: string,\n\t\ttoolName: string,\n\t\tresult: Array<{ type: string; text?: string; data?: string; mimeType?: string }>,\n\t\tdetails: unknown,\n\t\tisError: boolean,\n\t): { collapsed?: string; expanded?: string } | undefined;\n}\n\n/**\n * Create a tool HTML renderer.\n *\n * The renderer looks up tool definitions and invokes their renderCall/renderResult\n * methods, converting the resulting TUI Component output (ANSI) to HTML.\n */\nconst ANSI_ESCAPE_REGEX = /\\x1b\\[[\\d;]*m/g;\n\nfunction isBlankRenderedLine(line: string): boolean {\n\treturn line.replace(ANSI_ESCAPE_REGEX, \"\").trim().length === 0;\n}\n\nfunction trimRenderedResultLines(lines: string[]): string[] {\n\tlet start = 0;\n\tlet end = lines.length;\n\twhile (start < end && isBlankRenderedLine(lines[start])) start++;\n\twhile (end > start && isBlankRenderedLine(lines[end - 1])) end--;\n\treturn lines.slice(start, end);\n}\n\nexport function createToolHtmlRenderer(deps: ToolHtmlRendererDeps): ToolHtmlRenderer {\n\tconst { getToolDefinition, theme, cwd, width = 100 } = deps;\n\n\tconst renderedCallComponents = new Map<string, Component>();\n\tconst renderedResultComponents = new Map<string, Component>();\n\tconst renderedStates = new Map<string, any>();\n\tconst renderedArgs = new Map<string, unknown>();\n\n\tconst getState = (toolCallId: string): any => {\n\t\tlet state = renderedStates.get(toolCallId);\n\t\tif (!state) {\n\t\t\tstate = {};\n\t\t\trenderedStates.set(toolCallId, state);\n\t\t}\n\t\treturn state;\n\t};\n\n\tconst createRenderContext = (\n\t\ttoolCallId: string,\n\t\tlastComponent: Component | undefined,\n\t\texpanded: boolean,\n\t\tisPartial: boolean,\n\t\tisError: boolean,\n\t): ToolRenderContext => {\n\t\treturn {\n\t\t\targs: renderedArgs.get(toolCallId),\n\t\t\ttoolCallId,\n\t\t\tinvalidate: () => {},\n\t\t\tlastComponent,\n\t\t\tstate: getState(toolCallId),\n\t\t\tcwd,\n\t\t\texecutionStarted: true,\n\t\t\targsComplete: true,\n\t\t\tisPartial,\n\t\t\texpanded,\n\t\t\tshowImages: false,\n\t\t\tisError,\n\t\t};\n\t};\n\n\treturn {\n\t\trenderCall(toolCallId: string, toolName: string, args: unknown): string | undefined {\n\t\t\ttry {\n\t\t\t\trenderedArgs.set(toolCallId, args);\n\t\t\t\tconst toolDef = getToolDefinition(toolName);\n\t\t\t\tif (!toolDef?.renderCall) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tconst component = toolDef.renderCall(\n\t\t\t\t\targs,\n\t\t\t\t\ttheme,\n\t\t\t\t\tcreateRenderContext(toolCallId, renderedCallComponents.get(toolCallId), false, true, false),\n\t\t\t\t);\n\t\t\t\trenderedCallComponents.set(toolCallId, component);\n\t\t\t\tconst lines = component.render(width);\n\t\t\t\treturn ansiLinesToHtml(lines);\n\t\t\t} catch {\n\t\t\t\t// On error, return undefined so HTML export can fall back to structured result rendering\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\n\t\trenderResult(\n\t\t\ttoolCallId: string,\n\t\t\ttoolName: string,\n\t\t\tresult: Array<{ type: string; text?: string; data?: string; mimeType?: string }>,\n\t\t\tdetails: unknown,\n\t\t\tisError: boolean,\n\t\t): { collapsed?: string; expanded?: string } | undefined {\n\t\t\ttry {\n\t\t\t\tconst toolDef = getToolDefinition(toolName);\n\t\t\t\tif (!toolDef?.renderResult) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\t// Build AgentToolResult from content array\n\t\t\t\t// Cast content since session storage uses generic object types\n\t\t\t\tconst agentToolResult = {\n\t\t\t\t\tcontent: result as (TextContent | ImageContent)[],\n\t\t\t\t\tdetails,\n\t\t\t\t\tisError,\n\t\t\t\t};\n\n\t\t\t\t// Render collapsed\n\t\t\t\tconst collapsedComponent = toolDef.renderResult(\n\t\t\t\t\tagentToolResult,\n\t\t\t\t\t{ expanded: false, isPartial: false },\n\t\t\t\t\ttheme,\n\t\t\t\t\tcreateRenderContext(toolCallId, renderedResultComponents.get(toolCallId), false, false, isError),\n\t\t\t\t);\n\t\t\t\trenderedResultComponents.set(toolCallId, collapsedComponent);\n\t\t\t\tconst collapsed = ansiLinesToHtml(trimRenderedResultLines(collapsedComponent.render(width)));\n\n\t\t\t\t// Render expanded\n\t\t\t\tconst expandedComponent = toolDef.renderResult(\n\t\t\t\t\tagentToolResult,\n\t\t\t\t\t{ expanded: true, isPartial: false },\n\t\t\t\t\ttheme,\n\t\t\t\t\tcreateRenderContext(toolCallId, renderedResultComponents.get(toolCallId), true, false, isError),\n\t\t\t\t);\n\t\t\t\trenderedResultComponents.set(toolCallId, expandedComponent);\n\t\t\t\tconst expanded = ansiLinesToHtml(trimRenderedResultLines(expandedComponent.render(width)));\n\n\t\t\t\treturn {\n\t\t\t\t\t...(collapsed && collapsed !== expanded ? { collapsed } : {}),\n\t\t\t\t\texpanded,\n\t\t\t\t};\n\t\t\t} catch {\n\t\t\t\t// On error, return undefined so HTML export can fall back to structured result rendering\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool-renderer.js","sourceRoot":"","sources":["../../../src/core/export-html/tool-renderer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AA0BpD;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAE3C,SAAS,mBAAmB,CAAC,IAAY,EAAW;IACnD,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC;AAAA,CAC/D;AAED,SAAS,uBAAuB,CAAC,KAAe,EAAY;IAC3D,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;IACvB,OAAO,KAAK,GAAG,GAAG,IAAI,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAAE,KAAK,EAAE,CAAC;IACjE,OAAO,GAAG,GAAG,KAAK,IAAI,mBAAmB,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QAAE,GAAG,EAAE,CAAC;IACjE,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAAA,CAC/B;AAED,MAAM,UAAU,sBAAsB,CAAC,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,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAChG,CAAC;gBACF,wBAAwB,CAAC,GAAG,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;gBAC7D,MAAM,SAAS,GAAG,eAAe,CAAC,uBAAuB,CAAC,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAE7F,kBAAkB;gBAClB,MAAM,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAC7C,eAAe,EACf,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EACpC,KAAK,EACL,mBAAmB,CAAC,UAAU,EAAE,wBAAwB,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAC/F,CAAC;gBACF,wBAAwB,CAAC,GAAG,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;gBAC5D,MAAM,QAAQ,GAAG,eAAe,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAE3F,OAAO;oBACN,GAAG,CAAC,SAAS,IAAI,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC7D,QAAQ;iBACR,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACR,yFAAyF;gBACzF,OAAO,SAAS,CAAC;YAClB,CAAC;QAAA,CACD;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Tool HTML renderer for custom tools in HTML export.\n *\n * Renders custom tool calls and results to HTML by invoking their TUI renderers\n * and converting the ANSI output to HTML.\n */\n\nimport type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport type { Component } from \"@earendil-works/pi-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition, ToolRenderContext } from \"../extensions/types.ts\";\nimport { ansiLinesToHtml } from \"./ansi-to-html.ts\";\n\nexport interface ToolHtmlRendererDeps {\n\t/** Function to look up tool definition by name */\n\tgetToolDefinition: (name: string) => ToolDefinition | undefined;\n\t/** Theme for styling */\n\ttheme: Theme;\n\t/** Working directory for render context */\n\tcwd: string;\n\t/** Terminal width for rendering (default: 100) */\n\twidth?: number;\n}\n\nexport interface ToolHtmlRenderer {\n\t/** Render a tool call to HTML. Returns undefined if tool has no custom renderer. */\n\trenderCall(toolCallId: string, toolName: string, args: unknown): string | undefined;\n\t/** Render a tool result to collapsed/expanded HTML. Returns undefined if tool has no custom renderer. */\n\trenderResult(\n\t\ttoolCallId: string,\n\t\ttoolName: string,\n\t\tresult: Array<{ type: string; text?: string; data?: string; mimeType?: string }>,\n\t\tdetails: unknown,\n\t\tisError: boolean,\n\t): { collapsed?: string; expanded?: string } | undefined;\n}\n\n/**\n * Create a tool HTML renderer.\n *\n * The renderer looks up tool definitions and invokes their renderCall/renderResult\n * methods, converting the resulting TUI Component output (ANSI) to HTML.\n */\nconst ANSI_ESCAPE_REGEX = /\\x1b\\[[\\d;]*m/g;\n\nfunction isBlankRenderedLine(line: string): boolean {\n\treturn line.replace(ANSI_ESCAPE_REGEX, \"\").trim().length === 0;\n}\n\nfunction trimRenderedResultLines(lines: string[]): string[] {\n\tlet start = 0;\n\tlet end = lines.length;\n\twhile (start < end && isBlankRenderedLine(lines[start])) start++;\n\twhile (end > start && isBlankRenderedLine(lines[end - 1])) end--;\n\treturn lines.slice(start, end);\n}\n\nexport function createToolHtmlRenderer(deps: ToolHtmlRendererDeps): ToolHtmlRenderer {\n\tconst { getToolDefinition, theme, cwd, width = 100 } = deps;\n\n\tconst renderedCallComponents = new Map<string, Component>();\n\tconst renderedResultComponents = new Map<string, Component>();\n\tconst renderedStates = new Map<string, any>();\n\tconst renderedArgs = new Map<string, unknown>();\n\n\tconst getState = (toolCallId: string): any => {\n\t\tlet state = renderedStates.get(toolCallId);\n\t\tif (!state) {\n\t\t\tstate = {};\n\t\t\trenderedStates.set(toolCallId, state);\n\t\t}\n\t\treturn state;\n\t};\n\n\tconst createRenderContext = (\n\t\ttoolCallId: string,\n\t\tlastComponent: Component | undefined,\n\t\texpanded: boolean,\n\t\tisPartial: boolean,\n\t\tisError: boolean,\n\t): ToolRenderContext => {\n\t\treturn {\n\t\t\targs: renderedArgs.get(toolCallId),\n\t\t\ttoolCallId,\n\t\t\tinvalidate: () => {},\n\t\t\tlastComponent,\n\t\t\tstate: getState(toolCallId),\n\t\t\tcwd,\n\t\t\texecutionStarted: true,\n\t\t\targsComplete: true,\n\t\t\tisPartial,\n\t\t\texpanded,\n\t\t\t// A static export has no detail cycle to reveal a diff later, so it\n\t\t\t// always carries the full one.\n\t\t\teditDiffsExpanded: true,\n\t\t\tshowImages: false,\n\t\t\tisError,\n\t\t};\n\t};\n\n\treturn {\n\t\trenderCall(toolCallId: string, toolName: string, args: unknown): string | undefined {\n\t\t\ttry {\n\t\t\t\trenderedArgs.set(toolCallId, args);\n\t\t\t\tconst toolDef = getToolDefinition(toolName);\n\t\t\t\tif (!toolDef?.renderCall) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tconst component = toolDef.renderCall(\n\t\t\t\t\targs,\n\t\t\t\t\ttheme,\n\t\t\t\t\tcreateRenderContext(toolCallId, renderedCallComponents.get(toolCallId), false, true, false),\n\t\t\t\t);\n\t\t\t\trenderedCallComponents.set(toolCallId, component);\n\t\t\t\tconst lines = component.render(width);\n\t\t\t\treturn ansiLinesToHtml(lines);\n\t\t\t} catch {\n\t\t\t\t// On error, return undefined so HTML export can fall back to structured result rendering\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\n\t\trenderResult(\n\t\t\ttoolCallId: string,\n\t\t\ttoolName: string,\n\t\t\tresult: Array<{ type: string; text?: string; data?: string; mimeType?: string }>,\n\t\t\tdetails: unknown,\n\t\t\tisError: boolean,\n\t\t): { collapsed?: string; expanded?: string } | undefined {\n\t\t\ttry {\n\t\t\t\tconst toolDef = getToolDefinition(toolName);\n\t\t\t\tif (!toolDef?.renderResult) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\t// Build AgentToolResult from content array\n\t\t\t\t// Cast content since session storage uses generic object types\n\t\t\t\tconst agentToolResult = {\n\t\t\t\t\tcontent: result as (TextContent | ImageContent)[],\n\t\t\t\t\tdetails,\n\t\t\t\t\tisError,\n\t\t\t\t};\n\n\t\t\t\t// Render collapsed\n\t\t\t\tconst collapsedComponent = toolDef.renderResult(\n\t\t\t\t\tagentToolResult,\n\t\t\t\t\t{ expanded: false, isPartial: false },\n\t\t\t\t\ttheme,\n\t\t\t\t\tcreateRenderContext(toolCallId, renderedResultComponents.get(toolCallId), false, false, isError),\n\t\t\t\t);\n\t\t\t\trenderedResultComponents.set(toolCallId, collapsedComponent);\n\t\t\t\tconst collapsed = ansiLinesToHtml(trimRenderedResultLines(collapsedComponent.render(width)));\n\n\t\t\t\t// Render expanded\n\t\t\t\tconst expandedComponent = toolDef.renderResult(\n\t\t\t\t\tagentToolResult,\n\t\t\t\t\t{ expanded: true, isPartial: false },\n\t\t\t\t\ttheme,\n\t\t\t\t\tcreateRenderContext(toolCallId, renderedResultComponents.get(toolCallId), true, false, isError),\n\t\t\t\t);\n\t\t\t\trenderedResultComponents.set(toolCallId, expandedComponent);\n\t\t\t\tconst expanded = ansiLinesToHtml(trimRenderedResultLines(expandedComponent.render(width)));\n\n\t\t\t\treturn {\n\t\t\t\t\t...(collapsed && collapsed !== expanded ? { collapsed } : {}),\n\t\t\t\t\texpanded,\n\t\t\t\t};\n\t\t\t} catch {\n\t\t\t\t// On error, return undefined so HTML export can fall back to structured result rendering\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
@@ -30,9 +30,9 @@ import type { BashOperations } from "../tools/bash.ts";
|
|
|
30
30
|
import type { EditToolDetails } from "../tools/edit.ts";
|
|
31
31
|
import type { BashToolDetails, BashToolInput, EditToolInput, FindToolDetails, FindToolInput, GrepToolDetails, GrepToolInput, LsToolDetails, LsToolInput, PowerShellToolDetails, PowerShellToolInput, ReadToolDetails, ReadToolInput, WriteToolInput } from "../tools/index.ts";
|
|
32
32
|
export type { ExecOptions, ExecResult } from "../exec.ts";
|
|
33
|
+
export type { AppKeybinding, KeybindingsManager } from "../keybindings.ts";
|
|
33
34
|
export type { BuildSystemPromptOptions } from "../system-prompt.ts";
|
|
34
35
|
export type { AgentToolResult, AgentToolUpdateCallback, ToolExecutionMode };
|
|
35
|
-
export type { AppKeybinding, KeybindingsManager } from "../keybindings.ts";
|
|
36
36
|
/** Options for extension UI dialogs. */
|
|
37
37
|
export interface ExtensionUIDialogOptions {
|
|
38
38
|
/** AbortSignal to programmatically dismiss the dialog. */
|
|
@@ -336,6 +336,13 @@ export interface ToolRenderContext<TState = any, TArgs = any> {
|
|
|
336
336
|
isPartial: boolean;
|
|
337
337
|
/** Whether the result view is expanded. */
|
|
338
338
|
expanded: boolean;
|
|
339
|
+
/**
|
|
340
|
+
* Whether inline diffs are shown. A second, coarser axis than `expanded`:
|
|
341
|
+
* the conversation detail cycle reveals diffs one rung before it expands
|
|
342
|
+
* tool output, so a renderer that shows a diff reads this rather than
|
|
343
|
+
* `expanded`.
|
|
344
|
+
*/
|
|
345
|
+
editDiffsExpanded: boolean;
|
|
339
346
|
/** Whether inline images are currently shown in the TUI. */
|
|
340
347
|
showImages: boolean;
|
|
341
348
|
/** Whether the current result is an error. */
|