@kenkaiiii/gg-engine 0.0.0-stage → 7.0.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/LICENSE +661 -0
- package/NOTICE +43 -0
- package/README.md +53 -2
- package/assets/skills/bulletproof/SKILL.md +132 -0
- package/assets/skills/bulletproof/references/agent-surface.md +113 -0
- package/assets/skills/bulletproof/references/attack-classes.md +226 -0
- package/assets/skills/bulletproof/references/audit-protocol.md +232 -0
- package/assets/skills/bulletproof/references/platform-playbooks.md +196 -0
- package/assets/skills/bulletproof/references/provenance.md +146 -0
- package/assets/skills/bulletproof/references/secure-defaults.md +137 -0
- package/assets/skills/bulletproof/references/supply-chain.md +84 -0
- package/assets/skills/bulletproof/references/threat-landscape.md +66 -0
- package/assets/skills/bulletproof/references/verification.md +74 -0
- package/assets/skills/compliance-guard/SKILL.md +115 -0
- package/assets/skills/compliance-guard/references/artifacts.md +199 -0
- package/assets/skills/compliance-guard/references/eu-uk.md +162 -0
- package/assets/skills/compliance-guard/references/exposure-triage.md +177 -0
- package/assets/skills/compliance-guard/references/full-review.md +155 -0
- package/assets/skills/compliance-guard/references/lawsuit-vectors.md +153 -0
- package/assets/skills/compliance-guard/references/provenance.md +135 -0
- package/assets/skills/compliance-guard/references/sector-gates.md +187 -0
- package/assets/skills/compliance-guard/references/security-baseline.md +117 -0
- package/assets/skills/compliance-guard/references/trigger-map.md +177 -0
- package/assets/skills/compliance-guard/references/us.md +194 -0
- package/assets/skills/durable/SKILL.md +114 -0
- package/assets/skills/durable/references/agent-db-safety.md +76 -0
- package/assets/skills/durable/references/backups-and-runtime.md +93 -0
- package/assets/skills/durable/references/migrations-and-schema.md +87 -0
- package/assets/skills/gg-guide/SKILL.md +43 -0
- package/assets/skills/gg-guide/references/chat-motion-goals.md +217 -0
- package/assets/skills/gg-guide/references/checklist-and-safety.md +177 -0
- package/assets/skills/gg-guide/references/code-mode.md +269 -0
- package/assets/skills/gg-guide/references/getting-started.md +290 -0
- package/assets/skills/gg-guide/references/ken-and-autopilot.md +172 -0
- package/assets/skills/gg-guide/references/mcp-and-skills.md +204 -0
- package/assets/skills/gg-guide/references/models-and-sign-in.md +200 -0
- package/assets/skills/gg-guide/references/sessions-and-history.md +213 -0
- package/assets/skills/gg-guide/references/settings.md +193 -0
- package/assets/skills/gg-guide/references/troubleshooting-and-data.md +186 -0
- package/assets/skills/lean/SKILL.md +117 -0
- package/assets/skills/lean/references/memory-and-processes.md +99 -0
- package/assets/skills/lean/references/playbooks.md +134 -0
- package/dist/app-error.d.ts +22 -0
- package/dist/app-error.js +41 -0
- package/dist/app-error.js.map +1 -0
- package/dist/config.d.ts +90 -0
- package/dist/config.js +240 -0
- package/dist/config.js.map +1 -0
- package/dist/core/acceptance-checks.d.ts +48 -0
- package/dist/core/acceptance-checks.js +151 -0
- package/dist/core/acceptance-checks.js.map +1 -0
- package/dist/core/action-threats.d.ts +68 -0
- package/dist/core/action-threats.js +894 -0
- package/dist/core/action-threats.js.map +1 -0
- package/dist/core/agent-notifications.d.ts +79 -0
- package/dist/core/agent-notifications.js +125 -0
- package/dist/core/agent-notifications.js.map +1 -0
- package/dist/core/agent-session/helpers.d.ts +26 -0
- package/dist/core/agent-session/helpers.js +47 -0
- package/dist/core/agent-session/helpers.js.map +1 -0
- package/dist/core/agent-session/mcp-tools.d.ts +87 -0
- package/dist/core/agent-session/mcp-tools.js +227 -0
- package/dist/core/agent-session/mcp-tools.js.map +1 -0
- package/dist/core/agent-session/run-loop-monitor.d.ts +63 -0
- package/dist/core/agent-session/run-loop-monitor.js +164 -0
- package/dist/core/agent-session/run-loop-monitor.js.map +1 -0
- package/dist/core/agent-session/transcript-markers.d.ts +57 -0
- package/dist/core/agent-session/transcript-markers.js +166 -0
- package/dist/core/agent-session/transcript-markers.js.map +1 -0
- package/dist/core/agent-session/verification-tracker.d.ts +71 -0
- package/dist/core/agent-session/verification-tracker.js +295 -0
- package/dist/core/agent-session/verification-tracker.js.map +1 -0
- package/dist/core/agent-session.d.ts +1401 -0
- package/dist/core/agent-session.js +5160 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/agents.d.ts +63 -0
- package/dist/core/agents.js +160 -0
- package/dist/core/agents.js.map +1 -0
- package/dist/core/ask-user.d.ts +163 -0
- package/dist/core/ask-user.js +178 -0
- package/dist/core/ask-user.js.map +1 -0
- package/dist/core/auto-update.d.ts +32 -0
- package/dist/core/auto-update.js +218 -0
- package/dist/core/auto-update.js.map +1 -0
- package/dist/core/autopilot-cycle.d.ts +127 -0
- package/dist/core/autopilot-cycle.js +182 -0
- package/dist/core/autopilot-cycle.js.map +1 -0
- package/dist/core/autopilot-gate.d.ts +106 -0
- package/dist/core/autopilot-gate.js +192 -0
- package/dist/core/autopilot-gate.js.map +1 -0
- package/dist/core/autopilot-verdict.d.ts +55 -0
- package/dist/core/autopilot-verdict.js +226 -0
- package/dist/core/autopilot-verdict.js.map +1 -0
- package/dist/core/blocked-packages-file.d.ts +33 -0
- package/dist/core/blocked-packages-file.js +274 -0
- package/dist/core/blocked-packages-file.js.map +1 -0
- package/dist/core/bundled-agents.d.ts +2 -0
- package/dist/core/bundled-agents.js +253 -0
- package/dist/core/bundled-agents.js.map +1 -0
- package/dist/core/cache-diagnostics.d.ts +72 -0
- package/dist/core/cache-diagnostics.js +200 -0
- package/dist/core/cache-diagnostics.js.map +1 -0
- package/dist/core/cache-expiry.d.ts +89 -0
- package/dist/core/cache-expiry.js +117 -0
- package/dist/core/cache-expiry.js.map +1 -0
- package/dist/core/checklist-detection.d.ts +8 -0
- package/dist/core/checklist-detection.js +238 -0
- package/dist/core/checklist-detection.js.map +1 -0
- package/dist/core/checklist-git.d.ts +19 -0
- package/dist/core/checklist-git.js +54 -0
- package/dist/core/checklist-git.js.map +1 -0
- package/dist/core/checklist-items.d.ts +182 -0
- package/dist/core/checklist-items.js +228 -0
- package/dist/core/checklist-items.js.map +1 -0
- package/dist/core/checklist-prompt.d.ts +14 -0
- package/dist/core/checklist-prompt.js +64 -0
- package/dist/core/checklist-prompt.js.map +1 -0
- package/dist/core/checklist-snapshot.d.ts +7 -0
- package/dist/core/checklist-snapshot.js +46 -0
- package/dist/core/checklist-snapshot.js.map +1 -0
- package/dist/core/checklist-store.d.ts +45 -0
- package/dist/core/checklist-store.js +278 -0
- package/dist/core/checklist-store.js.map +1 -0
- package/dist/core/checkout-record.d.ts +22 -0
- package/dist/core/checkout-record.js +68 -0
- package/dist/core/checkout-record.js.map +1 -0
- package/dist/core/checkpoint-store.d.ts +109 -0
- package/dist/core/checkpoint-store.js +260 -0
- package/dist/core/checkpoint-store.js.map +1 -0
- package/dist/core/claude-code/complete.d.ts +35 -0
- package/dist/core/claude-code/complete.js +125 -0
- package/dist/core/claude-code/complete.js.map +1 -0
- package/dist/core/claude-code/events.d.ts +67 -0
- package/dist/core/claude-code/events.js +460 -0
- package/dist/core/claude-code/events.js.map +1 -0
- package/dist/core/claude-code/live-session.d.ts +94 -0
- package/dist/core/claude-code/live-session.js +525 -0
- package/dist/core/claude-code/live-session.js.map +1 -0
- package/dist/core/claude-code/loop.d.ts +9 -0
- package/dist/core/claude-code/loop.js +15 -0
- package/dist/core/claude-code/loop.js.map +1 -0
- package/dist/core/claude-code/session-sync.d.ts +28 -0
- package/dist/core/claude-code/session-sync.js +53 -0
- package/dist/core/claude-code/session-sync.js.map +1 -0
- package/dist/core/claude-code/tool-bridge.d.ts +49 -0
- package/dist/core/claude-code/tool-bridge.js +352 -0
- package/dist/core/claude-code/tool-bridge.js.map +1 -0
- package/dist/core/claude-code/transcripts.d.ts +39 -0
- package/dist/core/claude-code/transcripts.js +195 -0
- package/dist/core/claude-code/transcripts.js.map +1 -0
- package/dist/core/code-retrieval-chunkers.d.ts +26 -0
- package/dist/core/code-retrieval-chunkers.js +264 -0
- package/dist/core/code-retrieval-chunkers.js.map +1 -0
- package/dist/core/code-retrieval.d.ts +18 -0
- package/dist/core/code-retrieval.js +124 -0
- package/dist/core/code-retrieval.js.map +1 -0
- package/dist/core/codex-request-shape.d.ts +7 -0
- package/dist/core/codex-request-shape.js +19 -0
- package/dist/core/codex-request-shape.js.map +1 -0
- package/dist/core/compaction/active-context.d.ts +16 -0
- package/dist/core/compaction/active-context.js +20 -0
- package/dist/core/compaction/active-context.js.map +1 -0
- package/dist/core/compaction/compactor.d.ts +281 -0
- package/dist/core/compaction/compactor.js +1451 -0
- package/dist/core/compaction/compactor.js.map +1 -0
- package/dist/core/compaction/plan-step-policy.d.ts +46 -0
- package/dist/core/compaction/plan-step-policy.js +57 -0
- package/dist/core/compaction/plan-step-policy.js.map +1 -0
- package/dist/core/compaction/policy.d.ts +36 -0
- package/dist/core/compaction/policy.js +144 -0
- package/dist/core/compaction/policy.js.map +1 -0
- package/dist/core/compaction/query-aware-selector.d.ts +32 -0
- package/dist/core/compaction/query-aware-selector.js +202 -0
- package/dist/core/compaction/query-aware-selector.js.map +1 -0
- package/dist/core/compaction/token-estimator.d.ts +36 -0
- package/dist/core/compaction/token-estimator.js +180 -0
- package/dist/core/compaction/token-estimator.js.map +1 -0
- package/dist/core/compaction/tool-result-pruner.d.ts +90 -0
- package/dist/core/compaction/tool-result-pruner.js +238 -0
- package/dist/core/compaction/tool-result-pruner.js.map +1 -0
- package/dist/core/completion-review.d.ts +24 -0
- package/dist/core/completion-review.js +2 -0
- package/dist/core/completion-review.js.map +1 -0
- package/dist/core/context-files.d.ts +8 -0
- package/dist/core/context-files.js +46 -0
- package/dist/core/context-files.js.map +1 -0
- package/dist/core/context-limits.d.ts +40 -0
- package/dist/core/context-limits.js +43 -0
- package/dist/core/context-limits.js.map +1 -0
- package/dist/core/custom-commands.d.ts +18 -0
- package/dist/core/custom-commands.js +57 -0
- package/dist/core/custom-commands.js.map +1 -0
- package/dist/core/destructive-git-guard.d.ts +113 -0
- package/dist/core/destructive-git-guard.js +874 -0
- package/dist/core/destructive-git-guard.js.map +1 -0
- package/dist/core/display-items.d.ts +8 -0
- package/dist/core/display-items.js +2 -0
- package/dist/core/display-items.js.map +1 -0
- package/dist/core/encode-cwd.d.ts +41 -0
- package/dist/core/encode-cwd.js +53 -0
- package/dist/core/encode-cwd.js.map +1 -0
- package/dist/core/env-delta.d.ts +34 -0
- package/dist/core/env-delta.js +84 -0
- package/dist/core/env-delta.js.map +1 -0
- package/dist/core/event-bus.d.ts +178 -0
- package/dist/core/event-bus.js +171 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +7 -0
- package/dist/core/extensions/loader.js +68 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/plugin-bundles.d.ts +13 -0
- package/dist/core/extensions/plugin-bundles.js +45 -0
- package/dist/core/extensions/plugin-bundles.js.map +1 -0
- package/dist/core/extensions/types.d.ts +18 -0
- package/dist/core/extensions/types.js +2 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/foreign-session-import.d.ts +119 -0
- package/dist/core/foreign-session-import.js +598 -0
- package/dist/core/foreign-session-import.js.map +1 -0
- package/dist/core/foreign-transcript-blocks.d.ts +50 -0
- package/dist/core/foreign-transcript-blocks.js +151 -0
- package/dist/core/foreign-transcript-blocks.js.map +1 -0
- package/dist/core/frontmatter.d.ts +22 -0
- package/dist/core/frontmatter.js +90 -0
- package/dist/core/frontmatter.js.map +1 -0
- package/dist/core/goal-run-marker.d.ts +32 -0
- package/dist/core/goal-run-marker.js +178 -0
- package/dist/core/goal-run-marker.js.map +1 -0
- package/dist/core/goal-summary.d.ts +15 -0
- package/dist/core/goal-summary.js +110 -0
- package/dist/core/goal-summary.js.map +1 -0
- package/dist/core/goals-store.d.ts +208 -0
- package/dist/core/goals-store.js +577 -0
- package/dist/core/goals-store.js.map +1 -0
- package/dist/core/hashline.d.ts +51 -0
- package/dist/core/hashline.js +76 -0
- package/dist/core/hashline.js.map +1 -0
- package/dist/core/idle-wake.d.ts +62 -0
- package/dist/core/idle-wake.js +103 -0
- package/dist/core/idle-wake.js.map +1 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.js +15 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/injection-detect.d.ts +39 -0
- package/dist/core/injection-detect.js +241 -0
- package/dist/core/injection-detect.js.map +1 -0
- package/dist/core/installed-threats.d.ts +23 -0
- package/dist/core/installed-threats.js +71 -0
- package/dist/core/installed-threats.js.map +1 -0
- package/dist/core/internal-diagnostics.d.ts +159 -0
- package/dist/core/internal-diagnostics.js +495 -0
- package/dist/core/internal-diagnostics.js.map +1 -0
- package/dist/core/keep-awake.d.ts +88 -0
- package/dist/core/keep-awake.js +251 -0
- package/dist/core/keep-awake.js.map +1 -0
- package/dist/core/ken-ask-answer.d.ts +24 -0
- package/dist/core/ken-ask-answer.js +96 -0
- package/dist/core/ken-ask-answer.js.map +1 -0
- package/dist/core/ken-context.d.ts +119 -0
- package/dist/core/ken-context.js +447 -0
- package/dist/core/ken-context.js.map +1 -0
- package/dist/core/ken-model.d.ts +45 -0
- package/dist/core/ken-model.js +26 -0
- package/dist/core/ken-model.js.map +1 -0
- package/dist/core/ken-prompt.d.ts +21 -0
- package/dist/core/ken-prompt.js +370 -0
- package/dist/core/ken-prompt.js.map +1 -0
- package/dist/core/language-detector.d.ts +41 -0
- package/dist/core/language-detector.js +293 -0
- package/dist/core/language-detector.js.map +1 -0
- package/dist/core/live-preview.d.ts +26 -0
- package/dist/core/live-preview.js +80 -0
- package/dist/core/live-preview.js.map +1 -0
- package/dist/core/local-endpoint-store.d.ts +53 -0
- package/dist/core/local-endpoint-store.js +221 -0
- package/dist/core/local-endpoint-store.js.map +1 -0
- package/dist/core/logger.d.ts +21 -0
- package/dist/core/logger.js +94 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/loop-breaker.d.ts +89 -0
- package/dist/core/loop-breaker.js +204 -0
- package/dist/core/loop-breaker.js.map +1 -0
- package/dist/core/lsp/client.d.ts +206 -0
- package/dist/core/lsp/client.js +685 -0
- package/dist/core/lsp/client.js.map +1 -0
- package/dist/core/lsp/edit-telemetry.d.ts +26 -0
- package/dist/core/lsp/edit-telemetry.js +52 -0
- package/dist/core/lsp/edit-telemetry.js.map +1 -0
- package/dist/core/lsp/format.d.ts +11 -0
- package/dist/core/lsp/format.js +30 -0
- package/dist/core/lsp/format.js.map +1 -0
- package/dist/core/lsp/jsonrpc.d.ts +68 -0
- package/dist/core/lsp/jsonrpc.js +153 -0
- package/dist/core/lsp/jsonrpc.js.map +1 -0
- package/dist/core/lsp/manager.d.ts +188 -0
- package/dist/core/lsp/manager.js +576 -0
- package/dist/core/lsp/manager.js.map +1 -0
- package/dist/core/lsp/pool.d.ts +114 -0
- package/dist/core/lsp/pool.js +259 -0
- package/dist/core/lsp/pool.js.map +1 -0
- package/dist/core/lsp/project-root.d.ts +9 -0
- package/dist/core/lsp/project-root.js +75 -0
- package/dist/core/lsp/project-root.js.map +1 -0
- package/dist/core/lsp/reference-project.d.ts +6 -0
- package/dist/core/lsp/reference-project.js +110 -0
- package/dist/core/lsp/reference-project.js.map +1 -0
- package/dist/core/lsp/servers.d.ts +44 -0
- package/dist/core/lsp/servers.js +289 -0
- package/dist/core/lsp/servers.js.map +1 -0
- package/dist/core/lsp/test-support.d.ts +17 -0
- package/dist/core/lsp/test-support.js +27 -0
- package/dist/core/lsp/test-support.js.map +1 -0
- package/dist/core/mcp/catalog-cache.d.ts +64 -0
- package/dist/core/mcp/catalog-cache.js +166 -0
- package/dist/core/mcp/catalog-cache.js.map +1 -0
- package/dist/core/mcp/client.d.ts +317 -0
- package/dist/core/mcp/client.js +1168 -0
- package/dist/core/mcp/client.js.map +1 -0
- package/dist/core/mcp/content.d.ts +23 -0
- package/dist/core/mcp/content.js +194 -0
- package/dist/core/mcp/content.js.map +1 -0
- package/dist/core/mcp/defaults.d.ts +26 -0
- package/dist/core/mcp/defaults.js +81 -0
- package/dist/core/mcp/defaults.js.map +1 -0
- package/dist/core/mcp/deferred-catalog.d.ts +53 -0
- package/dist/core/mcp/deferred-catalog.js +117 -0
- package/dist/core/mcp/deferred-catalog.js.map +1 -0
- package/dist/core/mcp/elicitation-bridge.d.ts +40 -0
- package/dist/core/mcp/elicitation-bridge.js +36 -0
- package/dist/core/mcp/elicitation-bridge.js.map +1 -0
- package/dist/core/mcp/index.d.ts +16 -0
- package/dist/core/mcp/index.js +10 -0
- package/dist/core/mcp/index.js.map +1 -0
- package/dist/core/mcp/loopback.d.ts +26 -0
- package/dist/core/mcp/loopback.js +66 -0
- package/dist/core/mcp/loopback.js.map +1 -0
- package/dist/core/mcp/oauth-provider.d.ts +55 -0
- package/dist/core/mcp/oauth-provider.js +106 -0
- package/dist/core/mcp/oauth-provider.js.map +1 -0
- package/dist/core/mcp/oauth-store.d.ts +44 -0
- package/dist/core/mcp/oauth-store.js +76 -0
- package/dist/core/mcp/oauth-store.js.map +1 -0
- package/dist/core/mcp/parse-add-command.d.ts +50 -0
- package/dist/core/mcp/parse-add-command.js +391 -0
- package/dist/core/mcp/parse-add-command.js.map +1 -0
- package/dist/core/mcp/resolve-stdio.d.ts +77 -0
- package/dist/core/mcp/resolve-stdio.js +359 -0
- package/dist/core/mcp/resolve-stdio.js.map +1 -0
- package/dist/core/mcp/shared-pool.d.ts +157 -0
- package/dist/core/mcp/shared-pool.js +236 -0
- package/dist/core/mcp/shared-pool.js.map +1 -0
- package/dist/core/mcp/store.d.ts +100 -0
- package/dist/core/mcp/store.js +202 -0
- package/dist/core/mcp/store.js.map +1 -0
- package/dist/core/mcp/tool-guard.d.ts +58 -0
- package/dist/core/mcp/tool-guard.js +215 -0
- package/dist/core/mcp/tool-guard.js.map +1 -0
- package/dist/core/mcp/types.d.ts +57 -0
- package/dist/core/mcp/types.js +2 -0
- package/dist/core/mcp/types.js.map +1 -0
- package/dist/core/message-images.d.ts +11 -0
- package/dist/core/message-images.js +52 -0
- package/dist/core/message-images.js.map +1 -0
- package/dist/core/model-unavailable.d.ts +14 -0
- package/dist/core/model-unavailable.js +23 -0
- package/dist/core/model-unavailable.js.map +1 -0
- package/dist/core/network-guard.d.ts +28 -0
- package/dist/core/network-guard.js +251 -0
- package/dist/core/network-guard.js.map +1 -0
- package/dist/core/node-debugger.d.ts +148 -0
- package/dist/core/node-debugger.js +642 -0
- package/dist/core/node-debugger.js.map +1 -0
- package/dist/core/opencode-catalog-store.d.ts +20 -0
- package/dist/core/opencode-catalog-store.js +82 -0
- package/dist/core/opencode-catalog-store.js.map +1 -0
- package/dist/core/openrouter-catalog-store.d.ts +24 -0
- package/dist/core/openrouter-catalog-store.js +140 -0
- package/dist/core/openrouter-catalog-store.js.map +1 -0
- package/dist/core/package-cooldown.d.ts +69 -0
- package/dist/core/package-cooldown.js +297 -0
- package/dist/core/package-cooldown.js.map +1 -0
- package/dist/core/package-threats.d.ts +92 -0
- package/dist/core/package-threats.js +1339 -0
- package/dist/core/package-threats.js.map +1 -0
- package/dist/core/parked-requests.d.ts +43 -0
- package/dist/core/parked-requests.js +34 -0
- package/dist/core/parked-requests.js.map +1 -0
- package/dist/core/persistent-shell.d.ts +81 -0
- package/dist/core/persistent-shell.js +452 -0
- package/dist/core/persistent-shell.js.map +1 -0
- package/dist/core/plan-delta.d.ts +23 -0
- package/dist/core/plan-delta.js +36 -0
- package/dist/core/plan-delta.js.map +1 -0
- package/dist/core/plan-handoff.d.ts +38 -0
- package/dist/core/plan-handoff.js +21 -0
- package/dist/core/plan-handoff.js.map +1 -0
- package/dist/core/plan-submission-gate.d.ts +28 -0
- package/dist/core/plan-submission-gate.js +27 -0
- package/dist/core/plan-submission-gate.js.map +1 -0
- package/dist/core/platform-clis.d.ts +15 -0
- package/dist/core/platform-clis.js +299 -0
- package/dist/core/platform-clis.js.map +1 -0
- package/dist/core/process-gate.d.ts +61 -0
- package/dist/core/process-gate.js +103 -0
- package/dist/core/process-gate.js.map +1 -0
- package/dist/core/process-manager.d.ts +242 -0
- package/dist/core/process-manager.js +902 -0
- package/dist/core/process-manager.js.map +1 -0
- package/dist/core/progress/engine.d.ts +22 -0
- package/dist/core/progress/engine.js +131 -0
- package/dist/core/progress/engine.js.map +1 -0
- package/dist/core/progress/git-xp.d.ts +15 -0
- package/dist/core/progress/git-xp.js +100 -0
- package/dist/core/progress/git-xp.js.map +1 -0
- package/dist/core/progress/ranks.d.ts +31 -0
- package/dist/core/progress/ranks.js +310 -0
- package/dist/core/progress/ranks.js.map +1 -0
- package/dist/core/progress/rebuild.d.ts +8 -0
- package/dist/core/progress/rebuild.js +125 -0
- package/dist/core/progress/rebuild.js.map +1 -0
- package/dist/core/progress/store.d.ts +34 -0
- package/dist/core/progress/store.js +200 -0
- package/dist/core/progress/store.js.map +1 -0
- package/dist/core/progress/types.d.ts +56 -0
- package/dist/core/progress/types.js +2 -0
- package/dist/core/progress/types.js.map +1 -0
- package/dist/core/project-discovery.d.ts +64 -0
- package/dist/core/project-discovery.js +908 -0
- package/dist/core/project-discovery.js.map +1 -0
- package/dist/core/project-files.d.ts +15 -0
- package/dist/core/project-files.js +37 -0
- package/dist/core/project-files.js.map +1 -0
- package/dist/core/project-health-scan.d.ts +109 -0
- package/dist/core/project-health-scan.js +673 -0
- package/dist/core/project-health-scan.js.map +1 -0
- package/dist/core/project-health-score.d.ts +41 -0
- package/dist/core/project-health-score.js +257 -0
- package/dist/core/project-health-score.js.map +1 -0
- package/dist/core/prompt-command-expansion.d.ts +13 -0
- package/dist/core/prompt-command-expansion.js +48 -0
- package/dist/core/prompt-command-expansion.js.map +1 -0
- package/dist/core/prompt-commands.d.ts +13 -0
- package/dist/core/prompt-commands.js +370 -0
- package/dist/core/prompt-commands.js.map +1 -0
- package/dist/core/radio-players.d.ts +28 -0
- package/dist/core/radio-players.js +132 -0
- package/dist/core/radio-players.js.map +1 -0
- package/dist/core/radio.d.ts +42 -0
- package/dist/core/radio.js +499 -0
- package/dist/core/radio.js.map +1 -0
- package/dist/core/regrounding.d.ts +37 -0
- package/dist/core/regrounding.js +89 -0
- package/dist/core/regrounding.js.map +1 -0
- package/dist/core/resolve-start.d.ts +28 -0
- package/dist/core/resolve-start.js +35 -0
- package/dist/core/resolve-start.js.map +1 -0
- package/dist/core/run-claim.d.ts +36 -0
- package/dist/core/run-claim.js +46 -0
- package/dist/core/run-claim.js.map +1 -0
- package/dist/core/run-lifecycle.d.ts +58 -0
- package/dist/core/run-lifecycle.js +104 -0
- package/dist/core/run-lifecycle.js.map +1 -0
- package/dist/core/run-status.d.ts +17 -0
- package/dist/core/run-status.js +28 -0
- package/dist/core/run-status.js.map +1 -0
- package/dist/core/runtime-mode.d.ts +21 -0
- package/dist/core/runtime-mode.js +43 -0
- package/dist/core/runtime-mode.js.map +1 -0
- package/dist/core/sandbox-domains.d.ts +13 -0
- package/dist/core/sandbox-domains.js +76 -0
- package/dist/core/sandbox-domains.js.map +1 -0
- package/dist/core/sandbox-feedback.d.ts +21 -0
- package/dist/core/sandbox-feedback.js +69 -0
- package/dist/core/sandbox-feedback.js.map +1 -0
- package/dist/core/sandbox.d.ts +106 -0
- package/dist/core/sandbox.js +383 -0
- package/dist/core/sandbox.js.map +1 -0
- package/dist/core/semantic-loop-check.d.ts +58 -0
- package/dist/core/semantic-loop-check.js +103 -0
- package/dist/core/semantic-loop-check.js.map +1 -0
- package/dist/core/session-compaction.d.ts +23 -0
- package/dist/core/session-compaction.js +54 -0
- package/dist/core/session-compaction.js.map +1 -0
- package/dist/core/session-export.d.ts +97 -0
- package/dist/core/session-export.js +368 -0
- package/dist/core/session-export.js.map +1 -0
- package/dist/core/session-history.d.ts +160 -0
- package/dist/core/session-history.js +467 -0
- package/dist/core/session-history.js.map +1 -0
- package/dist/core/session-manager.d.ts +510 -0
- package/dist/core/session-manager.js +1368 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/session-preview.d.ts +12 -0
- package/dist/core/session-preview.js +58 -0
- package/dist/core/session-preview.js.map +1 -0
- package/dist/core/session-storage.d.ts +78 -0
- package/dist/core/session-storage.js +659 -0
- package/dist/core/session-storage.js.map +1 -0
- package/dist/core/session-summary-index.d.ts +51 -0
- package/dist/core/session-summary-index.js +192 -0
- package/dist/core/session-summary-index.js.map +1 -0
- package/dist/core/settings-manager.d.ts +113 -0
- package/dist/core/settings-manager.js +281 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/shared-checkout-guard.d.ts +78 -0
- package/dist/core/shared-checkout-guard.js +219 -0
- package/dist/core/shared-checkout-guard.js.map +1 -0
- package/dist/core/shell-path.d.ts +13 -0
- package/dist/core/shell-path.js +175 -0
- package/dist/core/shell-path.js.map +1 -0
- package/dist/core/shell-threats-popular-packages.d.ts +11 -0
- package/dist/core/shell-threats-popular-packages.js +675 -0
- package/dist/core/shell-threats-popular-packages.js.map +1 -0
- package/dist/core/shell-threats.d.ts +21 -0
- package/dist/core/shell-threats.js +235 -0
- package/dist/core/shell-threats.js.map +1 -0
- package/dist/core/shell.d.ts +54 -0
- package/dist/core/shell.js +99 -0
- package/dist/core/shell.js.map +1 -0
- package/dist/core/shutdown.d.ts +70 -0
- package/dist/core/shutdown.js +144 -0
- package/dist/core/shutdown.js.map +1 -0
- package/dist/core/skill-scan.d.ts +112 -0
- package/dist/core/skill-scan.js +781 -0
- package/dist/core/skill-scan.js.map +1 -0
- package/dist/core/skills.d.ts +80 -0
- package/dist/core/skills.js +270 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +58 -0
- package/dist/core/slash-commands.js +242 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/steering.d.ts +47 -0
- package/dist/core/steering.js +65 -0
- package/dist/core/steering.js.map +1 -0
- package/dist/core/steroids.d.ts +66 -0
- package/dist/core/steroids.js +243 -0
- package/dist/core/steroids.js.map +1 -0
- package/dist/core/stream-diag-level.d.ts +3 -0
- package/dist/core/stream-diag-level.js +24 -0
- package/dist/core/stream-diag-level.js.map +1 -0
- package/dist/core/stream-rules.d.ts +30 -0
- package/dist/core/stream-rules.js +151 -0
- package/dist/core/stream-rules.js.map +1 -0
- package/dist/core/subagent-manager.d.ts +239 -0
- package/dist/core/subagent-manager.js +1059 -0
- package/dist/core/subagent-manager.js.map +1 -0
- package/dist/core/subagent-policy.d.ts +9 -0
- package/dist/core/subagent-policy.js +41 -0
- package/dist/core/subagent-policy.js.map +1 -0
- package/dist/core/subagent-receipt.d.ts +54 -0
- package/dist/core/subagent-receipt.js +274 -0
- package/dist/core/subagent-receipt.js.map +1 -0
- package/dist/core/subagent-store.d.ts +41 -0
- package/dist/core/subagent-store.js +284 -0
- package/dist/core/subagent-store.js.map +1 -0
- package/dist/core/subagent-turn-record.d.ts +18 -0
- package/dist/core/subagent-turn-record.js +82 -0
- package/dist/core/subagent-turn-record.js.map +1 -0
- package/dist/core/tasks-store.d.ts +31 -0
- package/dist/core/tasks-store.js +97 -0
- package/dist/core/tasks-store.js.map +1 -0
- package/dist/core/telegram-config.d.ts +20 -0
- package/dist/core/telegram-config.js +52 -0
- package/dist/core/telegram-config.js.map +1 -0
- package/dist/core/telegram.d.ts +114 -0
- package/dist/core/telegram.js +275 -0
- package/dist/core/telegram.js.map +1 -0
- package/dist/core/temp-paths.d.ts +5 -0
- package/dist/core/temp-paths.js +50 -0
- package/dist/core/temp-paths.js.map +1 -0
- package/dist/core/test-impact.d.ts +73 -0
- package/dist/core/test-impact.js +467 -0
- package/dist/core/test-impact.js.map +1 -0
- package/dist/core/threat-feed.d.ts +65 -0
- package/dist/core/threat-feed.js +334 -0
- package/dist/core/threat-feed.js.map +1 -0
- package/dist/core/trophies/catalog-more.d.ts +2 -0
- package/dist/core/trophies/catalog-more.js +837 -0
- package/dist/core/trophies/catalog-more.js.map +1 -0
- package/dist/core/trophies/catalog.d.ts +4 -0
- package/dist/core/trophies/catalog.js +649 -0
- package/dist/core/trophies/catalog.js.map +1 -0
- package/dist/core/trophies/engine.d.ts +70 -0
- package/dist/core/trophies/engine.js +347 -0
- package/dist/core/trophies/engine.js.map +1 -0
- package/dist/core/trophies/store.d.ts +17 -0
- package/dist/core/trophies/store.js +113 -0
- package/dist/core/trophies/store.js.map +1 -0
- package/dist/core/trophies/types.d.ts +87 -0
- package/dist/core/trophies/types.js +74 -0
- package/dist/core/trophies/types.js.map +1 -0
- package/dist/core/ui-adoption.d.ts +32 -0
- package/dist/core/ui-adoption.js +302 -0
- package/dist/core/ui-adoption.js.map +1 -0
- package/dist/core/ui-compatibility.d.ts +10 -0
- package/dist/core/ui-compatibility.js +51 -0
- package/dist/core/ui-compatibility.js.map +1 -0
- package/dist/core/ui-registry.d.ts +101 -0
- package/dist/core/ui-registry.js +292 -0
- package/dist/core/ui-registry.js.map +1 -0
- package/dist/core/user-shell-context.d.ts +8 -0
- package/dist/core/user-shell-context.js +12 -0
- package/dist/core/user-shell-context.js.map +1 -0
- package/dist/core/verification-evidence.d.ts +49 -0
- package/dist/core/verification-evidence.js +816 -0
- package/dist/core/verification-evidence.js.map +1 -0
- package/dist/core/verification-gate.d.ts +77 -0
- package/dist/core/verification-gate.js +504 -0
- package/dist/core/verification-gate.js.map +1 -0
- package/dist/core/verification-snapshot.d.ts +7 -0
- package/dist/core/verification-snapshot.js +109 -0
- package/dist/core/verification-snapshot.js.map +1 -0
- package/dist/core/verify-commands.d.ts +34 -0
- package/dist/core/verify-commands.js +203 -0
- package/dist/core/verify-commands.js.map +1 -0
- package/dist/core/voice-transcriber.d.ts +32 -0
- package/dist/core/voice-transcriber.js +114 -0
- package/dist/core/voice-transcriber.js.map +1 -0
- package/dist/core/workspace-guard.d.ts +56 -0
- package/dist/core/workspace-guard.js +334 -0
- package/dist/core/workspace-guard.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/session.d.ts +44 -0
- package/dist/session.js +105 -0
- package/dist/session.js.map +1 -0
- package/dist/system-prompt.d.ts +104 -0
- package/dist/system-prompt.js +480 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/test-support/fake-home.d.ts +19 -0
- package/dist/test-support/fake-home.js +37 -0
- package/dist/test-support/fake-home.js.map +1 -0
- package/dist/test-support/keep-alive.d.ts +14 -0
- package/dist/test-support/keep-alive.js +17 -0
- package/dist/test-support/keep-alive.js.map +1 -0
- package/dist/test-support/slow-git.d.ts +1 -0
- package/dist/test-support/slow-git.js +21 -0
- package/dist/test-support/slow-git.js.map +1 -0
- package/dist/test-support/system-tools.d.ts +6 -0
- package/dist/test-support/system-tools.js +36 -0
- package/dist/test-support/system-tools.js.map +1 -0
- package/dist/tools/ask-user.d.ts +34 -0
- package/dist/tools/ask-user.js +99 -0
- package/dist/tools/ask-user.js.map +1 -0
- package/dist/tools/background-watch-lint.d.ts +18 -0
- package/dist/tools/background-watch-lint.js +102 -0
- package/dist/tools/background-watch-lint.js.map +1 -0
- package/dist/tools/bash-read-evidence.d.ts +23 -0
- package/dist/tools/bash-read-evidence.js +180 -0
- package/dist/tools/bash-read-evidence.js.map +1 -0
- package/dist/tools/bash.d.ts +64 -0
- package/dist/tools/bash.js +552 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/browser-api.d.ts +27 -0
- package/dist/tools/browser-api.js +449 -0
- package/dist/tools/browser-api.js.map +1 -0
- package/dist/tools/browser-sandbox.d.ts +16 -0
- package/dist/tools/browser-sandbox.js +158 -0
- package/dist/tools/browser-sandbox.js.map +1 -0
- package/dist/tools/browser-session.d.ts +84 -0
- package/dist/tools/browser-session.js +304 -0
- package/dist/tools/browser-session.js.map +1 -0
- package/dist/tools/browser-snapshot.d.ts +19 -0
- package/dist/tools/browser-snapshot.js +109 -0
- package/dist/tools/browser-snapshot.js.map +1 -0
- package/dist/tools/browser.d.ts +11 -0
- package/dist/tools/browser.js +106 -0
- package/dist/tools/browser.js.map +1 -0
- package/dist/tools/checklist.d.ts +49 -0
- package/dist/tools/checklist.js +154 -0
- package/dist/tools/checklist.js.map +1 -0
- package/dist/tools/compress.d.ts +56 -0
- package/dist/tools/compress.js +226 -0
- package/dist/tools/compress.js.map +1 -0
- package/dist/tools/debug.d.ts +54 -0
- package/dist/tools/debug.js +230 -0
- package/dist/tools/debug.js.map +1 -0
- package/dist/tools/document-text.d.ts +6 -0
- package/dist/tools/document-text.js +154 -0
- package/dist/tools/document-text.js.map +1 -0
- package/dist/tools/edit-diff.d.ts +123 -0
- package/dist/tools/edit-diff.js +476 -0
- package/dist/tools/edit-diff.js.map +1 -0
- package/dist/tools/edit-targets.d.ts +10 -0
- package/dist/tools/edit-targets.js +31 -0
- package/dist/tools/edit-targets.js.map +1 -0
- package/dist/tools/edit.d.ts +38 -0
- package/dist/tools/edit.js +695 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/enter-plan.d.ts +7 -0
- package/dist/tools/enter-plan.js +20 -0
- package/dist/tools/enter-plan.js.map +1 -0
- package/dist/tools/exit-plan.d.ts +7 -0
- package/dist/tools/exit-plan.js +51 -0
- package/dist/tools/exit-plan.js.map +1 -0
- package/dist/tools/find.d.ts +17 -0
- package/dist/tools/find.js +100 -0
- package/dist/tools/find.js.map +1 -0
- package/dist/tools/generate-image.d.ts +83 -0
- package/dist/tools/generate-image.js +625 -0
- package/dist/tools/generate-image.js.map +1 -0
- package/dist/tools/grep-scan.d.ts +96 -0
- package/dist/tools/grep-scan.js +283 -0
- package/dist/tools/grep-scan.js.map +1 -0
- package/dist/tools/grep.d.ts +48 -0
- package/dist/tools/grep.js +1013 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/html-extract.d.ts +57 -0
- package/dist/tools/html-extract.js +130 -0
- package/dist/tools/html-extract.js.map +1 -0
- package/dist/tools/index.d.ts +198 -0
- package/dist/tools/index.js +216 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/live-preview.d.ts +23 -0
- package/dist/tools/live-preview.js +41 -0
- package/dist/tools/live-preview.js.map +1 -0
- package/dist/tools/ls.d.ts +9 -0
- package/dist/tools/ls.js +59 -0
- package/dist/tools/ls.js.map +1 -0
- package/dist/tools/operations.d.ts +86 -0
- package/dist/tools/operations.js +117 -0
- package/dist/tools/operations.js.map +1 -0
- package/dist/tools/overflow.d.ts +17 -0
- package/dist/tools/overflow.js +68 -0
- package/dist/tools/overflow.js.map +1 -0
- package/dist/tools/path-utils.d.ts +30 -0
- package/dist/tools/path-utils.js +74 -0
- package/dist/tools/path-utils.js.map +1 -0
- package/dist/tools/pdf-extract.d.ts +17 -0
- package/dist/tools/pdf-extract.js +43 -0
- package/dist/tools/pdf-extract.js.map +1 -0
- package/dist/tools/prompt-hints.d.ts +46 -0
- package/dist/tools/prompt-hints.js +171 -0
- package/dist/tools/prompt-hints.js.map +1 -0
- package/dist/tools/read-only-bash.d.ts +31 -0
- package/dist/tools/read-only-bash.js +338 -0
- package/dist/tools/read-only-bash.js.map +1 -0
- package/dist/tools/read-tracker.d.ts +43 -0
- package/dist/tools/read-tracker.js +120 -0
- package/dist/tools/read-tracker.js.map +1 -0
- package/dist/tools/read.d.ts +18 -0
- package/dist/tools/read.js +316 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/redaction-guard.d.ts +10 -0
- package/dist/tools/redaction-guard.js +55 -0
- package/dist/tools/redaction-guard.js.map +1 -0
- package/dist/tools/routine-output.d.ts +39 -0
- package/dist/tools/routine-output.js +281 -0
- package/dist/tools/routine-output.js.map +1 -0
- package/dist/tools/safe-env.d.ts +1 -0
- package/dist/tools/safe-env.js +79 -0
- package/dist/tools/safe-env.js.map +1 -0
- package/dist/tools/session-stats.d.ts +26 -0
- package/dist/tools/session-stats.js +51 -0
- package/dist/tools/session-stats.js.map +1 -0
- package/dist/tools/side-web-search.d.ts +34 -0
- package/dist/tools/side-web-search.js +146 -0
- package/dist/tools/side-web-search.js.map +1 -0
- package/dist/tools/skill.d.ts +12 -0
- package/dist/tools/skill.js +94 -0
- package/dist/tools/skill.js.map +1 -0
- package/dist/tools/source-path.d.ts +8 -0
- package/dist/tools/source-path.js +135 -0
- package/dist/tools/source-path.js.map +1 -0
- package/dist/tools/steroids.d.ts +44 -0
- package/dist/tools/steroids.js +356 -0
- package/dist/tools/steroids.js.map +1 -0
- package/dist/tools/subagent-control.d.ts +5 -0
- package/dist/tools/subagent-control.js +211 -0
- package/dist/tools/subagent-control.js.map +1 -0
- package/dist/tools/subagent-shared.d.ts +115 -0
- package/dist/tools/subagent-shared.js +182 -0
- package/dist/tools/subagent-shared.js.map +1 -0
- package/dist/tools/subagent.d.ts +37 -0
- package/dist/tools/subagent.js +406 -0
- package/dist/tools/subagent.js.map +1 -0
- package/dist/tools/task-output.d.ts +10 -0
- package/dist/tools/task-output.js +74 -0
- package/dist/tools/task-output.js.map +1 -0
- package/dist/tools/task-send.d.ts +11 -0
- package/dist/tools/task-send.js +36 -0
- package/dist/tools/task-send.js.map +1 -0
- package/dist/tools/task-stop.d.ts +8 -0
- package/dist/tools/task-stop.js +15 -0
- package/dist/tools/task-stop.js.map +1 -0
- package/dist/tools/tasks.d.ts +15 -0
- package/dist/tools/tasks.js +94 -0
- package/dist/tools/tasks.js.map +1 -0
- package/dist/tools/tool-search.d.ts +26 -0
- package/dist/tools/tool-search.js +81 -0
- package/dist/tools/tool-search.js.map +1 -0
- package/dist/tools/tool-tiers.d.ts +65 -0
- package/dist/tools/tool-tiers.js +121 -0
- package/dist/tools/tool-tiers.js.map +1 -0
- package/dist/tools/truncate.d.ts +39 -0
- package/dist/tools/truncate.js +242 -0
- package/dist/tools/truncate.js.map +1 -0
- package/dist/tools/ui-adopt.d.ts +16 -0
- package/dist/tools/ui-adopt.js +66 -0
- package/dist/tools/ui-adopt.js.map +1 -0
- package/dist/tools/ui-registry.d.ts +15 -0
- package/dist/tools/ui-registry.js +39 -0
- package/dist/tools/ui-registry.js.map +1 -0
- package/dist/tools/verification-review.d.ts +2 -0
- package/dist/tools/verification-review.js +41 -0
- package/dist/tools/verification-review.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +52 -0
- package/dist/tools/web-fetch.js +986 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +35 -0
- package/dist/tools/web-search.js +926 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/write.d.ts +16 -0
- package/dist/tools/write.js +196 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/commit-message.d.ts +25 -0
- package/dist/utils/commit-message.js +72 -0
- package/dist/utils/commit-message.js.map +1 -0
- package/dist/utils/git.d.ts +102 -0
- package/dist/utils/git.js +325 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/github-ci.d.ts +9 -0
- package/dist/utils/github-ci.js +138 -0
- package/dist/utils/github-ci.js.map +1 -0
- package/dist/utils/github.d.ts +19 -0
- package/dist/utils/github.js +67 -0
- package/dist/utils/github.js.map +1 -0
- package/dist/utils/image.d.ts +166 -0
- package/dist/utils/image.js +673 -0
- package/dist/utils/image.js.map +1 -0
- package/dist/utils/open-browser.d.ts +13 -0
- package/dist/utils/open-browser.js +31 -0
- package/dist/utils/open-browser.js.map +1 -0
- package/dist/utils/plan-steps.d.ts +90 -0
- package/dist/utils/plan-steps.js +209 -0
- package/dist/utils/plan-steps.js.map +1 -0
- package/dist/utils/process.d.ts +48 -0
- package/dist/utils/process.js +175 -0
- package/dist/utils/process.js.map +1 -0
- package/dist/utils/prompt-enhancer.d.ts +34 -0
- package/dist/utils/prompt-enhancer.js +178 -0
- package/dist/utils/prompt-enhancer.js.map +1 -0
- package/dist/utils/text.d.ts +61 -0
- package/dist/utils/text.js +68 -0
- package/dist/utils/text.js.map +1 -0
- package/package.json +87 -3
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { mkdir, writeFile, readFile } from "node:fs/promises";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { getAppIdentity } from "@kenkaiiii/gg-ai";
|
|
5
|
+
import { resolvePath } from "./path-utils.js";
|
|
6
|
+
import { IMAGE_MEDIA_TYPES, convertImageFormat, animatedPreview, downscaleForPreview, imageDimensions, shrinkToFit, } from "../utils/image.js";
|
|
7
|
+
/**
|
|
8
|
+
* OpenAI's public Image API (developers.openai.com/api/docs/guides/image-generation):
|
|
9
|
+
* a JSON POST to `images/generations` or `images/edits` with `{ prompt,
|
|
10
|
+
* background, model, quality, size }` (edits add `images: [{ image_url }]`,
|
|
11
|
+
* GIFs add `output_format: "gif"` + frame controls), answered with
|
|
12
|
+
* `data[].b64_json`. It needs an OpenAI API key: the ChatGPT plan route
|
|
13
|
+
* doesn't serve image generation.
|
|
14
|
+
*/
|
|
15
|
+
const IMAGES_BASE = "https://api.openai.com/v1/images";
|
|
16
|
+
/** The endpoint answers in PNG by default; other formats are re-encoded locally. */
|
|
17
|
+
const RESPONSE_FORMAT = "png";
|
|
18
|
+
/** GPT Image 2.6: Flare for fast everyday generation, Sunburst where edit precision matters. */
|
|
19
|
+
const GENERATION_MODEL = "gpt-image-2.6-flare";
|
|
20
|
+
const EDIT_MODEL = "gpt-image-2.6-sunburst";
|
|
21
|
+
/** GIF output bounds (`frame_count` 2–16, default 9; 200ms frames). */
|
|
22
|
+
const GIF_MIN_FRAMES = 2;
|
|
23
|
+
const GIF_MAX_FRAMES = 16;
|
|
24
|
+
const GIF_DEFAULT_FRAMES = 9;
|
|
25
|
+
const GIF_DEFAULT_FRAME_MS = 200;
|
|
26
|
+
/** An edit takes one to five reference images. */
|
|
27
|
+
const MAX_EDIT_IMAGES = 5;
|
|
28
|
+
/**
|
|
29
|
+
* Retry policy for image requests: up to 4 retries (5 attempts) on a 5xx or a
|
|
30
|
+
* failed connection, never on a 4xx such as 429. The wait honours
|
|
31
|
+
* `Retry-After`; otherwise it doubles from 200ms with ±10% jitter (200, 400,
|
|
32
|
+
* 800, 1600ms).
|
|
33
|
+
*/
|
|
34
|
+
const MAX_RETRIES = 4;
|
|
35
|
+
const RETRY_BASE_DELAY_MS = 200;
|
|
36
|
+
function abortableSleep(ms, signal) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
if (signal.aborted) {
|
|
39
|
+
reject(signal.reason);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const onAbort = () => {
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
reject(signal.reason);
|
|
45
|
+
};
|
|
46
|
+
const timer = setTimeout(() => {
|
|
47
|
+
signal.removeEventListener("abort", onAbort);
|
|
48
|
+
resolve();
|
|
49
|
+
}, ms);
|
|
50
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const DEFAULT_RETRY_DEPS = {
|
|
54
|
+
sleep: abortableSleep,
|
|
55
|
+
random: Math.random,
|
|
56
|
+
now: Date.now,
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Wait before retry number `retry` (1-based): the server's `Retry-After` (whole seconds or an HTTP date) when present,
|
|
60
|
+
* otherwise exponential backoff from 200ms with ±10% jitter.
|
|
61
|
+
*/
|
|
62
|
+
export function retryDelayMs(retry, retryAfter, deps) {
|
|
63
|
+
const value = retryAfter?.trim();
|
|
64
|
+
if (value) {
|
|
65
|
+
if (/^\d+$/.test(value))
|
|
66
|
+
return Number(value) * 1000;
|
|
67
|
+
const date = Date.parse(value);
|
|
68
|
+
if (Number.isFinite(date))
|
|
69
|
+
return Math.max(0, date - deps.now());
|
|
70
|
+
}
|
|
71
|
+
const jitter = 0.9 + deps.random() * 0.2;
|
|
72
|
+
return Math.floor(RETRY_BASE_DELAY_MS * 2 ** (retry - 1) * jitter);
|
|
73
|
+
}
|
|
74
|
+
const GenerateImageParams = z.object({
|
|
75
|
+
prompt: z.string().describe("Text description of the image to generate or the edit to apply"),
|
|
76
|
+
image: z
|
|
77
|
+
.string()
|
|
78
|
+
.optional()
|
|
79
|
+
.describe("Path to an existing image file to edit (use the path returned by a previous " +
|
|
80
|
+
"generate_image call, or a user-attached image path). When omitted, a new " +
|
|
81
|
+
"image is generated from scratch. Use `images` instead for several references."),
|
|
82
|
+
images: z
|
|
83
|
+
.array(z.string())
|
|
84
|
+
.min(1)
|
|
85
|
+
.max(MAX_EDIT_IMAGES)
|
|
86
|
+
.optional()
|
|
87
|
+
.describe(`Up to ${MAX_EDIT_IMAGES} image paths to edit from or combine (for example a subject ` +
|
|
88
|
+
"and a style reference). Do not pass both `image` and `images`."),
|
|
89
|
+
size: z
|
|
90
|
+
.string()
|
|
91
|
+
.optional()
|
|
92
|
+
.describe("Output resolution: `auto` (default) or WIDTHxHEIGHT with both edges multiples of " +
|
|
93
|
+
"16px, max edge 3840px, long:short ratio at most 3:1, and 655,360 to 8,294,400 " +
|
|
94
|
+
"total pixels. Common: 1024x1024, 1536x1024, 1024x1536. The result always reports " +
|
|
95
|
+
"the size actually delivered."),
|
|
96
|
+
quality: z
|
|
97
|
+
.enum(["low", "medium", "high", "auto"])
|
|
98
|
+
.optional()
|
|
99
|
+
.describe("Rendering quality. Use 'low' for fast drafts, 'high' for final assets. Default: auto."),
|
|
100
|
+
n: z
|
|
101
|
+
.number()
|
|
102
|
+
.int()
|
|
103
|
+
.min(1)
|
|
104
|
+
.max(4)
|
|
105
|
+
.optional()
|
|
106
|
+
.describe("Number of images to generate (1–4, default 1)"),
|
|
107
|
+
out_path: z
|
|
108
|
+
.string()
|
|
109
|
+
.optional()
|
|
110
|
+
.describe("Where to save the generated image (relative to cwd or absolute). " +
|
|
111
|
+
"Defaults to .gg/generated/<timestamp>.png"),
|
|
112
|
+
output_format: z
|
|
113
|
+
.enum(["png", "jpeg", "webp"])
|
|
114
|
+
.optional()
|
|
115
|
+
.describe("Output file format for a still image (default png). Leave unset with `gif`."),
|
|
116
|
+
gif: z
|
|
117
|
+
.object({
|
|
118
|
+
frame_count: z
|
|
119
|
+
.number()
|
|
120
|
+
.int()
|
|
121
|
+
.min(GIF_MIN_FRAMES)
|
|
122
|
+
.max(GIF_MAX_FRAMES)
|
|
123
|
+
.optional()
|
|
124
|
+
.describe(`Number of frames (${GIF_MIN_FRAMES}–${GIF_MAX_FRAMES}). Default 9.`),
|
|
125
|
+
frame_duration_ms: z
|
|
126
|
+
.number()
|
|
127
|
+
.int()
|
|
128
|
+
.min(20)
|
|
129
|
+
.max(2000)
|
|
130
|
+
.optional()
|
|
131
|
+
.describe("Milliseconds per frame (20–2000). Default 200."),
|
|
132
|
+
})
|
|
133
|
+
.optional()
|
|
134
|
+
.describe("Set to make a simple looping animated GIF instead of a still image; use {} for the " +
|
|
135
|
+
`defaults (9 frames, 200ms each). Only for simple animations of ${GIF_MIN_FRAMES}–` +
|
|
136
|
+
`${GIF_MAX_FRAMES} frames. Describe the motion and the loop in the prompt. To change ` +
|
|
137
|
+
"an existing GIF, pass a spritesheet of its frames (equal cells in a regular grid) " +
|
|
138
|
+
"as `image`, never the GIF itself."),
|
|
139
|
+
background: z
|
|
140
|
+
.enum(["opaque", "transparent"])
|
|
141
|
+
.optional()
|
|
142
|
+
.describe("Use 'transparent' when the request calls for a transparent background, including " +
|
|
143
|
+
"background removal or a cutout (png or webp output). Default: opaque. For edits, " +
|
|
144
|
+
"keep existing transparency unless the user asks to change it."),
|
|
145
|
+
});
|
|
146
|
+
function defaultOutPath(cwd, format) {
|
|
147
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
148
|
+
const ext = format === "jpeg" ? "jpg" : format;
|
|
149
|
+
return path.join(cwd, ".gg", "generated", `${stamp}.${ext}`);
|
|
150
|
+
}
|
|
151
|
+
/** Format → media type for StructuredToolResult. */
|
|
152
|
+
function mediaTypeFor(format) {
|
|
153
|
+
if (format === "jpeg")
|
|
154
|
+
return "image/jpeg";
|
|
155
|
+
if (format === "webp")
|
|
156
|
+
return "image/webp";
|
|
157
|
+
if (format === "gif")
|
|
158
|
+
return "image/gif";
|
|
159
|
+
return "image/png";
|
|
160
|
+
}
|
|
161
|
+
/** GIF87a / GIF89a magic: the backend's reply, not the request, decides the format. */
|
|
162
|
+
function isGif(buffer) {
|
|
163
|
+
return buffer.subarray(0, 4).toString("latin1") === "GIF8";
|
|
164
|
+
}
|
|
165
|
+
/** Same path with another extension, for a still image returned to a GIF request. */
|
|
166
|
+
function withExtension(filePath, ext) {
|
|
167
|
+
return filePath.slice(0, filePath.length - path.extname(filePath).length) + ext;
|
|
168
|
+
}
|
|
169
|
+
export function createGenerateImageTool(cwd, auth, retryDeps = {}) {
|
|
170
|
+
const retry = { ...DEFAULT_RETRY_DEPS, ...retryDeps };
|
|
171
|
+
return {
|
|
172
|
+
name: "generate_image",
|
|
173
|
+
description: "Generate or edit images with OpenAI's Image API. Works even when a different chat " +
|
|
174
|
+
"provider is active; needs an OpenAI API key. Only use this tool when the user explicitly asks to " +
|
|
175
|
+
"create, generate, or edit an image. Pass `image` (or up to five `images`) to edit " +
|
|
176
|
+
"existing files, such as a previous result or a user attachment. Set `background` to " +
|
|
177
|
+
"'transparent' for cutouts and transparent artwork. Set `gif` for a short looping " +
|
|
178
|
+
"animation. Generation can take a minute or " +
|
|
179
|
+
"more. Use `out_path` to save to a specific location (defaults to .gg/generated/).",
|
|
180
|
+
parameters: GenerateImageParams,
|
|
181
|
+
async execute(args, context) {
|
|
182
|
+
if (context.signal.aborted)
|
|
183
|
+
return "Image generation aborted before start.";
|
|
184
|
+
// JPEG has no alpha channel: a transparent result saved as JPEG would
|
|
185
|
+
// silently come back opaque, after spending the user's image quota.
|
|
186
|
+
if (args.background === "transparent" && args.output_format === "jpeg") {
|
|
187
|
+
return ("Transparent backgrounds need png or webp output; JPEG cannot store transparency. " +
|
|
188
|
+
"No request was sent. Use output_format png or webp.");
|
|
189
|
+
}
|
|
190
|
+
if (args.image && args.images) {
|
|
191
|
+
return "Pass either `image` or `images`, not both. No request was sent.";
|
|
192
|
+
}
|
|
193
|
+
if (args.gif && args.output_format) {
|
|
194
|
+
return "A GIF is always saved as .gif; leave `output_format` unset with `gif`. No request was sent.";
|
|
195
|
+
}
|
|
196
|
+
// The API key only: the ChatGPT plan route doesn't serve image generation.
|
|
197
|
+
let token;
|
|
198
|
+
try {
|
|
199
|
+
token = (await auth.resolveApiKey("openai")).accessToken;
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return ("Image generation needs an OpenAI API key; it isn't available on the ChatGPT plan. " +
|
|
203
|
+
"No request was sent. Tell the user to add a key from platform.openai.com/api-keys " +
|
|
204
|
+
"under OpenAI in Providers (or `ggcoder login`).");
|
|
205
|
+
}
|
|
206
|
+
const outputFormat = args.gif ? "gif" : (args.output_format ?? "png");
|
|
207
|
+
const mediaType = mediaTypeFor(outputFormat);
|
|
208
|
+
const outPath = args.out_path
|
|
209
|
+
? resolvePath(cwd, args.out_path)
|
|
210
|
+
: defaultOutPath(cwd, outputFormat);
|
|
211
|
+
try {
|
|
212
|
+
// Quality and size default to "auto", background to opaque unless
|
|
213
|
+
// transparency is asked for.
|
|
214
|
+
const referencePaths = args.images ?? (args.image ? [args.image] : []);
|
|
215
|
+
const request = {
|
|
216
|
+
prompt: args.prompt,
|
|
217
|
+
background: args.background ?? "opaque",
|
|
218
|
+
model: referencePaths.length > 0 ? EDIT_MODEL : GENERATION_MODEL,
|
|
219
|
+
quality: args.quality ?? "auto",
|
|
220
|
+
size: args.size ?? "auto",
|
|
221
|
+
};
|
|
222
|
+
if (args.gif) {
|
|
223
|
+
// Frame controls sit beside `output_format`; unset ones are omitted.
|
|
224
|
+
request.output_format = "gif";
|
|
225
|
+
if (args.gif.frame_count !== undefined)
|
|
226
|
+
request.frame_count = args.gif.frame_count;
|
|
227
|
+
if (args.gif.frame_duration_ms !== undefined) {
|
|
228
|
+
request.frame_duration_ms = args.gif.frame_duration_ms;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (referencePaths.length > 0) {
|
|
232
|
+
// Edit mode: each reference travels inline as a data URL of the
|
|
233
|
+
// original bytes.
|
|
234
|
+
const references = [];
|
|
235
|
+
for (const reference of referencePaths) {
|
|
236
|
+
const imagePath = resolvePath(cwd, reference);
|
|
237
|
+
const refMediaType = IMAGE_MEDIA_TYPES[path.extname(imagePath).toLowerCase()];
|
|
238
|
+
if (!refMediaType) {
|
|
239
|
+
return `Cannot edit ${reference}: only PNG, JPEG, GIF, WebP and BMP images are supported.`;
|
|
240
|
+
}
|
|
241
|
+
let fileBuffer;
|
|
242
|
+
try {
|
|
243
|
+
fileBuffer = await readFile(imagePath);
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
return `Could not read the image at ${reference}. Check the path is correct.`;
|
|
247
|
+
}
|
|
248
|
+
references.push({
|
|
249
|
+
image_url: `data:${refMediaType};base64,${fileBuffer.toString("base64")}`,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
request.images = references;
|
|
253
|
+
}
|
|
254
|
+
const endpoint = `${IMAGES_BASE}/${request.images ? "edits" : "generations"}`;
|
|
255
|
+
// One request per image: each output is its own generation, and a
|
|
256
|
+
// later failure keeps the earlier ones.
|
|
257
|
+
const requestedCount = args.n ?? 1;
|
|
258
|
+
const imageBuffers = [];
|
|
259
|
+
// Set once OpenAI refuses native GIF output: every GIF is then drawn as one
|
|
260
|
+
// sprite sheet and its frames stitched into a GIF locally.
|
|
261
|
+
let sheetGrid;
|
|
262
|
+
// The size OpenAI's response says it produced, per image (when given).
|
|
263
|
+
const reportedSizes = [];
|
|
264
|
+
for (let index = 0; index < requestedCount && imageBuffers.length < requestedCount; index++) {
|
|
265
|
+
const call = (body) => callImageEndpoint(endpoint, body, token, context.signal, retry);
|
|
266
|
+
let generated;
|
|
267
|
+
try {
|
|
268
|
+
generated = await call(sheetGrid ? spriteSheetRequest(request, sheetGrid) : request);
|
|
269
|
+
}
|
|
270
|
+
catch (err) {
|
|
271
|
+
if (!args.gif || sheetGrid || !(err instanceof GifRefusedError))
|
|
272
|
+
throw err;
|
|
273
|
+
sheetGrid = spriteGrid(args.gif.frame_count ?? GIF_DEFAULT_FRAMES, args.size);
|
|
274
|
+
generated = await call(spriteSheetRequest(request, sheetGrid));
|
|
275
|
+
}
|
|
276
|
+
for (const png of generated.images.slice(0, requestedCount - imageBuffers.length)) {
|
|
277
|
+
// PNG and GIF output are saved byte for byte as OpenAI sent them
|
|
278
|
+
// (alpha and frames and all); only another format is re-encoded. Never resized.
|
|
279
|
+
imageBuffers.push(sheetGrid
|
|
280
|
+
? // Not a usable grid: keep the still, saved and reported as a PNG.
|
|
281
|
+
((await gifFromSpriteSheet(png, sheetGrid, args.gif?.frame_duration_ms ?? GIF_DEFAULT_FRAME_MS)) ?? png)
|
|
282
|
+
: outputFormat === RESPONSE_FORMAT || outputFormat === "gif"
|
|
283
|
+
? png
|
|
284
|
+
: await convertImageFormat(png, outputFormat));
|
|
285
|
+
reportedSizes.push(generated.reportedSize);
|
|
286
|
+
}
|
|
287
|
+
if (generated.images.length === 0)
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
if (imageBuffers.length === 0) {
|
|
291
|
+
return "Image generation returned no results. The prompt may have been blocked by content moderation.";
|
|
292
|
+
}
|
|
293
|
+
// Save each image and build preview content.
|
|
294
|
+
const savedPaths = [];
|
|
295
|
+
let stillInsteadOfGif = false;
|
|
296
|
+
for (let i = 0; i < imageBuffers.length; i++) {
|
|
297
|
+
const buf = imageBuffers[i];
|
|
298
|
+
let savePath = imageBuffers.length === 1 ? outPath : insertIndex(outPath, i);
|
|
299
|
+
if (outputFormat === "gif" && !isGif(buf)) {
|
|
300
|
+
// A still came back for a GIF request: keep it, under its true extension.
|
|
301
|
+
stillInsteadOfGif = true;
|
|
302
|
+
savePath = withExtension(savePath, ".png");
|
|
303
|
+
}
|
|
304
|
+
await mkdir(path.dirname(savePath), { recursive: true });
|
|
305
|
+
await writeFile(savePath, buf);
|
|
306
|
+
savedPaths.push(savePath);
|
|
307
|
+
}
|
|
308
|
+
// The primary image (first) gets the full treatment: model-visible
|
|
309
|
+
// image + inline preview. Additional images are previewed only.
|
|
310
|
+
const primary = imageBuffers[0];
|
|
311
|
+
const primaryPath = savedPaths[0];
|
|
312
|
+
// Shrink for the model (provider image limits) and a smaller copy for
|
|
313
|
+
// the inline terminal/webview preview. The model sees a GIF as its
|
|
314
|
+
// first frame, while the preview keeps the animation.
|
|
315
|
+
const { buffer: shrunk, mediaType: detectedType } = await shrinkToFit(isGif(primary) ? await convertImageFormat(primary, "png") : primary, mediaType);
|
|
316
|
+
const primaryPreview = isGif(primary)
|
|
317
|
+
? await animatedPreview(primary)
|
|
318
|
+
: { buffer: await downscaleForPreview(shrunk), mediaType: detectedType };
|
|
319
|
+
const imagePreviews = [
|
|
320
|
+
{
|
|
321
|
+
base64: primaryPreview.buffer.toString("base64"),
|
|
322
|
+
mediaType: primaryPreview.mediaType,
|
|
323
|
+
path: primaryPath,
|
|
324
|
+
},
|
|
325
|
+
];
|
|
326
|
+
// Include additional images as previews too.
|
|
327
|
+
for (let i = 1; i < imageBuffers.length; i++) {
|
|
328
|
+
const extraBuf = imageBuffers[i];
|
|
329
|
+
const extraPath = savedPaths[i];
|
|
330
|
+
if (isGif(extraBuf)) {
|
|
331
|
+
const extraPreview = await animatedPreview(extraBuf);
|
|
332
|
+
imagePreviews.push({
|
|
333
|
+
base64: extraPreview.buffer.toString("base64"),
|
|
334
|
+
mediaType: extraPreview.mediaType,
|
|
335
|
+
path: extraPath,
|
|
336
|
+
});
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const extraShrunk = await shrinkToFit(extraBuf, mediaType);
|
|
340
|
+
const extraPreview = await downscaleForPreview(extraShrunk.buffer);
|
|
341
|
+
imagePreviews.push({
|
|
342
|
+
base64: extraPreview.toString("base64"),
|
|
343
|
+
mediaType: extraShrunk.mediaType,
|
|
344
|
+
path: extraPath,
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
const summary = savedPaths.length === 1
|
|
348
|
+
? `Generated image → ${primaryPath}`
|
|
349
|
+
: `Generated ${savedPaths.length} images → ${savedPaths.join(", ")}`;
|
|
350
|
+
const dimensions = await Promise.all(imageBuffers.map((buf) => imageDimensions(buf)));
|
|
351
|
+
const sizeText = sheetGrid && !stillInsteadOfGif
|
|
352
|
+
? `Frame size: ${dimensions[0] ? formatDimensions(dimensions[0]) : "unknown"}. ` +
|
|
353
|
+
`Assembled locally from a ${sheetGrid.cols}x${sheetGrid.rows} sprite sheet of ` +
|
|
354
|
+
`${sheetGrid.frames} frames, because OpenAI's native GIF output isn't enabled ` +
|
|
355
|
+
"for this API key yet."
|
|
356
|
+
: sizeReport(args.size, savedPaths, dimensions, reportedSizes);
|
|
357
|
+
// The summary stays the FIRST text block, on its own: restored history
|
|
358
|
+
// reads the image paths from exactly that line (extractToolImagePaths).
|
|
359
|
+
const allContent = [
|
|
360
|
+
{ type: "text", text: summary },
|
|
361
|
+
{ type: "text", text: sizeText },
|
|
362
|
+
...(stillInsteadOfGif
|
|
363
|
+
? [
|
|
364
|
+
{
|
|
365
|
+
type: "text",
|
|
366
|
+
text: sheetGrid
|
|
367
|
+
? "The frames OpenAI drew did not line up into an animation, so the " +
|
|
368
|
+
"picture was saved as a still PNG. Tell the user, and offer to try again."
|
|
369
|
+
: "OpenAI returned a still PNG instead of an animated GIF, saved with a " +
|
|
370
|
+
".png extension. Tell the user.",
|
|
371
|
+
},
|
|
372
|
+
]
|
|
373
|
+
: []),
|
|
374
|
+
{
|
|
375
|
+
type: "image",
|
|
376
|
+
mediaType: detectedType,
|
|
377
|
+
data: shrunk.toString("base64"),
|
|
378
|
+
},
|
|
379
|
+
];
|
|
380
|
+
return {
|
|
381
|
+
content: allContent,
|
|
382
|
+
details: { imagePreviews },
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
catch (err) {
|
|
386
|
+
if (context.signal.aborted)
|
|
387
|
+
return "Image generation aborted.";
|
|
388
|
+
if (err instanceof ImageAccessError)
|
|
389
|
+
return imageAccessMessage(err.message);
|
|
390
|
+
if (err instanceof ImageLimitError)
|
|
391
|
+
return imageLimitMessage();
|
|
392
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
393
|
+
return `Image generation failed: ${reason}`;
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
const formatDimensions = (d) => `${d.width}x${d.height}`;
|
|
399
|
+
/**
|
|
400
|
+
* Requested versus delivered size, for the agent to relay. OpenAI can return
|
|
401
|
+
* a different size than asked (a user asked for 2048x2048
|
|
402
|
+
* and got 1254x1254), so a mismatch is reported plainly instead of the call
|
|
403
|
+
* reading as a clean success. Nothing is resized and nothing is re-requested:
|
|
404
|
+
* each request spends the user's image quota.
|
|
405
|
+
*/
|
|
406
|
+
export function sizeReport(requested, paths, dimensions, reportedSizes) {
|
|
407
|
+
const explicit = requested && requested !== "auto" ? requested : undefined;
|
|
408
|
+
const actual = dimensions.map((d) => (d ? formatDimensions(d) : undefined));
|
|
409
|
+
// What OpenAI's response claimed, when it disagrees with the pixels.
|
|
410
|
+
const claims = actual
|
|
411
|
+
.map((size, i) => {
|
|
412
|
+
const reported = reportedSizes[i];
|
|
413
|
+
return reported && size && reported !== size ? reported : undefined;
|
|
414
|
+
})
|
|
415
|
+
.filter((claim) => claim !== undefined);
|
|
416
|
+
const claimNote = claims.length > 0 ? ` OpenAI's response reported ${[...new Set(claims)].join(", ")}.` : "";
|
|
417
|
+
if (actual.some((size) => size === undefined)) {
|
|
418
|
+
return explicit
|
|
419
|
+
? `Requested ${explicit}, but the saved image could not be measured to confirm its size.`
|
|
420
|
+
: "The saved image could not be measured to report its size.";
|
|
421
|
+
}
|
|
422
|
+
const unique = [...new Set(actual)];
|
|
423
|
+
const delivered = unique.length === 1
|
|
424
|
+
? (unique[0] ?? "")
|
|
425
|
+
: actual.map((size, i) => `${paths[i] ?? `image ${i + 1}`}: ${size}`).join(", ");
|
|
426
|
+
if (!explicit)
|
|
427
|
+
return `Size: ${delivered} (size auto, chosen by OpenAI).${claimNote}`;
|
|
428
|
+
if (unique.length === 1 && unique[0] === explicit) {
|
|
429
|
+
return `Size: ${explicit}, as requested.${claimNote}`;
|
|
430
|
+
}
|
|
431
|
+
return (`Size mismatch: requested ${explicit}, but OpenAI returned ${delivered}.${claimNote} ` +
|
|
432
|
+
"The file was saved at its native size with no resizing. Tell the user. OpenAI does not " +
|
|
433
|
+
"always honour the requested size, so asking again is unlikely to change it and would " +
|
|
434
|
+
"spend more of their credit.");
|
|
435
|
+
}
|
|
436
|
+
/** Insert a numeric index before the extension for multi-image output. */
|
|
437
|
+
function insertIndex(filePath, index) {
|
|
438
|
+
const ext = path.extname(filePath);
|
|
439
|
+
const base = filePath.slice(0, filePath.length - ext.length);
|
|
440
|
+
return `${base}_${index}${ext}`;
|
|
441
|
+
}
|
|
442
|
+
/** OpenAI refused the image request outright (HTTP 403): the account has no access. */
|
|
443
|
+
class ImageAccessError extends Error {
|
|
444
|
+
}
|
|
445
|
+
/** The account's image quota is used up (HTTP 429 `usage_limit_reached`). */
|
|
446
|
+
class ImageLimitError extends Error {
|
|
447
|
+
}
|
|
448
|
+
/** The backend turned down GIF output (HTTP 400 naming GIF), before generating anything. */
|
|
449
|
+
class GifRefusedError extends Error {
|
|
450
|
+
detail;
|
|
451
|
+
constructor(detail) {
|
|
452
|
+
super(`OpenAI Image API (400): ${detail}`);
|
|
453
|
+
this.detail = detail;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
const SHEET_LONG_EDGE = 1536;
|
|
457
|
+
/** The most square grid that holds `frames` cells, sized for the requested frame shape. */
|
|
458
|
+
export function spriteGrid(frames, frameSize) {
|
|
459
|
+
const cols = Math.ceil(Math.sqrt(frames));
|
|
460
|
+
const rows = Math.ceil(frames / cols);
|
|
461
|
+
const match = frameSize ? /^(\d+)x(\d+)$/.exec(frameSize) : null;
|
|
462
|
+
const frameAspect = match ? Number(match[1]) / Number(match[2]) : 1;
|
|
463
|
+
// The backend caps the long:short ratio at 3:1.
|
|
464
|
+
const aspect = Math.min(3, Math.max(1 / 3, (cols * frameAspect) / rows));
|
|
465
|
+
const snap = (edge) => Math.max(16, Math.round(edge / 16) * 16);
|
|
466
|
+
const width = aspect >= 1 ? SHEET_LONG_EDGE : snap(SHEET_LONG_EDGE * aspect);
|
|
467
|
+
const height = aspect >= 1 ? snap(SHEET_LONG_EDGE / aspect) : SHEET_LONG_EDGE;
|
|
468
|
+
return { frames, cols, rows, size: `${width}x${height}` };
|
|
469
|
+
}
|
|
470
|
+
/** The still request that asks for every frame of the animation on one sheet. */
|
|
471
|
+
export function spriteSheetRequest(request, grid) {
|
|
472
|
+
const { output_format: _format, frame_count: _count, frame_duration_ms: _ms, ...still } = request;
|
|
473
|
+
const spare = grid.cols * grid.rows > grid.frames
|
|
474
|
+
? ` Fill only the first ${grid.frames} cells; leave the rest plain background.`
|
|
475
|
+
: "";
|
|
476
|
+
return {
|
|
477
|
+
...still,
|
|
478
|
+
size: grid.size,
|
|
479
|
+
prompt: `A sprite sheet for a looping animation: ${grid.frames} frames in a ${grid.cols}x` +
|
|
480
|
+
`${grid.rows} grid of equal cells, read left to right, top to bottom.${spare} No gaps, ` +
|
|
481
|
+
"borders, gutters, labels or numbers. Every cell shares the exact same background, " +
|
|
482
|
+
"framing and scale so the frames line up when played in order, and the last frame " +
|
|
483
|
+
`leads smoothly back into the first.\n\nAnimation: ${String(request.prompt)}`,
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/** Cut a sprite sheet into its cells and play them as a looping GIF. */
|
|
487
|
+
export async function gifFromSpriteSheet(sheet, grid, frameMs) {
|
|
488
|
+
const sharp = (await import("sharp")).default;
|
|
489
|
+
const { width = 0, height = 0 } = await sharp(sheet).metadata();
|
|
490
|
+
const asked = /^(\d+)x(\d+)$/.exec(grid.size);
|
|
491
|
+
// A sheet whose shape is far from the one asked for was not drawn on the grid.
|
|
492
|
+
if (asked) {
|
|
493
|
+
const askedAspect = Number(asked[1]) / Number(asked[2]);
|
|
494
|
+
const gotAspect = height > 0 ? width / height : 0;
|
|
495
|
+
if (Math.abs(Math.log(gotAspect / askedAspect)) > Math.log(1.25))
|
|
496
|
+
return null;
|
|
497
|
+
}
|
|
498
|
+
const cellW = Math.floor(width / grid.cols);
|
|
499
|
+
const cellH = Math.floor(height / grid.rows);
|
|
500
|
+
// Crop a hair off every edge: the model often draws faint lines between cells.
|
|
501
|
+
const inset = Math.max(2, Math.round(Math.min(cellW, cellH) * 0.012));
|
|
502
|
+
if (cellW <= inset * 2 || cellH <= inset * 2) {
|
|
503
|
+
throw new Error(`The sprite sheet (${width}x${height}) is too small to cut into frames.`);
|
|
504
|
+
}
|
|
505
|
+
const frames = [];
|
|
506
|
+
for (let i = 0; i < grid.frames; i++) {
|
|
507
|
+
frames.push(await sharp(sheet)
|
|
508
|
+
.extract({
|
|
509
|
+
left: (i % grid.cols) * cellW + inset,
|
|
510
|
+
top: Math.floor(i / grid.cols) * cellH + inset,
|
|
511
|
+
width: cellW - inset * 2,
|
|
512
|
+
height: cellH - inset * 2,
|
|
513
|
+
})
|
|
514
|
+
.png()
|
|
515
|
+
.toBuffer());
|
|
516
|
+
}
|
|
517
|
+
// Identical cells mean one picture rather than frames of a motion: no animation.
|
|
518
|
+
const [first, ...rest] = await Promise.all(frames.map((frame) => sharp(frame).resize(16, 16, { fit: "fill" }).greyscale().raw().toBuffer()));
|
|
519
|
+
const moves = rest.some((cell) => cell.some((v, j) => Math.abs(v - (first[j] ?? 0)) > 24));
|
|
520
|
+
if (!moves)
|
|
521
|
+
return null;
|
|
522
|
+
return sharp(frames, { join: { animated: true } })
|
|
523
|
+
.gif({ delay: Array(grid.frames).fill(frameMs), loop: 0 })
|
|
524
|
+
.toBuffer();
|
|
525
|
+
}
|
|
526
|
+
/** What to tell the agent when the API key has no credit left for images. */
|
|
527
|
+
function imageLimitMessage() {
|
|
528
|
+
return ("The OpenAI API key has no credit left for image generation (or its billing limit is reached). " +
|
|
529
|
+
"Tell the user to check billing at platform.openai.com; retrying will not help.");
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* What to tell the agent when OpenAI refuses image generation for the key. GPT
|
|
533
|
+
* Image models can require a verified organization; say that plainly instead
|
|
534
|
+
* of passing the opaque status through.
|
|
535
|
+
*/
|
|
536
|
+
function imageAccessMessage(detail) {
|
|
537
|
+
const reason = detail ? ` OpenAI said: ${detail.slice(0, 300)}` : "";
|
|
538
|
+
return ("OpenAI refused the image request (403 Forbidden). The API key's organization may need " +
|
|
539
|
+
"verification for GPT Image models (platform.openai.com/settings/organization/general)." +
|
|
540
|
+
`${reason} Tell the user; retrying, or changing size, quality or format, will not help.`);
|
|
541
|
+
}
|
|
542
|
+
/** POST one request to the Image API and return the decoded images. */
|
|
543
|
+
async function callImageEndpoint(url, request, token, signal, retry) {
|
|
544
|
+
const body = JSON.stringify(request);
|
|
545
|
+
for (let attempt = 0;; attempt++) {
|
|
546
|
+
let response;
|
|
547
|
+
let text;
|
|
548
|
+
try {
|
|
549
|
+
response = await fetch(url, {
|
|
550
|
+
method: "POST",
|
|
551
|
+
headers: {
|
|
552
|
+
Accept: "application/json",
|
|
553
|
+
"Content-Type": "application/json",
|
|
554
|
+
Authorization: `Bearer ${token}`,
|
|
555
|
+
"User-Agent": getAppIdentity().userAgent,
|
|
556
|
+
},
|
|
557
|
+
body,
|
|
558
|
+
signal,
|
|
559
|
+
});
|
|
560
|
+
text = await response.text();
|
|
561
|
+
}
|
|
562
|
+
catch (err) {
|
|
563
|
+
// A failed connection or a body cut off mid-read. An abort is the
|
|
564
|
+
// user stopping the run, never something to retry.
|
|
565
|
+
if (signal.aborted || attempt >= MAX_RETRIES)
|
|
566
|
+
throw err;
|
|
567
|
+
await retry.sleep(retryDelayMs(attempt + 1, null, retry), signal);
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
if (response.status >= 500 && attempt < MAX_RETRIES) {
|
|
571
|
+
const wait = retryDelayMs(attempt + 1, response.headers.get("retry-after"), retry);
|
|
572
|
+
await retry.sleep(wait, signal);
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
return parseImageResponse(response.status, text, attempt + 1);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
/** Turn one image endpoint reply into images, or the error it describes. */
|
|
579
|
+
function parseImageResponse(status, text, attempts) {
|
|
580
|
+
const response = { status, ok: status >= 200 && status < 300 };
|
|
581
|
+
if (!response.ok) {
|
|
582
|
+
let detail = text;
|
|
583
|
+
let errorCode;
|
|
584
|
+
try {
|
|
585
|
+
const parsed = JSON.parse(text);
|
|
586
|
+
errorCode = parsed.error?.code ?? parsed.error?.type;
|
|
587
|
+
if (parsed.detail)
|
|
588
|
+
detail = parsed.detail;
|
|
589
|
+
else if (parsed.error?.message)
|
|
590
|
+
detail = parsed.error.message;
|
|
591
|
+
}
|
|
592
|
+
catch {
|
|
593
|
+
// Keep raw text
|
|
594
|
+
}
|
|
595
|
+
if (response.status === 403)
|
|
596
|
+
throw new ImageAccessError(detail);
|
|
597
|
+
if (response.status === 429 &&
|
|
598
|
+
(errorCode === "insufficient_quota" || errorCode === "billing_hard_limit_reached")) {
|
|
599
|
+
throw new ImageLimitError(detail);
|
|
600
|
+
}
|
|
601
|
+
// Only "GIF is not available here"; other 400s (bad input, policy) surface as they are.
|
|
602
|
+
if (response.status === 400 &&
|
|
603
|
+
/\bgif\b/i.test(detail) &&
|
|
604
|
+
/\b(not|unsupported|unavailable|disabled)\b/i.test(detail)) {
|
|
605
|
+
throw new GifRefusedError(detail);
|
|
606
|
+
}
|
|
607
|
+
const tries = attempts > 1 ? ` after ${attempts} attempts` : "";
|
|
608
|
+
throw new Error(`OpenAI Image API (${response.status})${tries}: ${detail}`);
|
|
609
|
+
}
|
|
610
|
+
let parsed;
|
|
611
|
+
try {
|
|
612
|
+
parsed = JSON.parse(text);
|
|
613
|
+
}
|
|
614
|
+
catch {
|
|
615
|
+
throw new Error("OpenAI Image API returned a response that is not JSON.");
|
|
616
|
+
}
|
|
617
|
+
const images = (parsed.data ?? [])
|
|
618
|
+
.map((item) => item.b64_json)
|
|
619
|
+
.filter((b64) => typeof b64 === "string" && b64.length > 0)
|
|
620
|
+
.map((b64) => Buffer.from(b64, "base64"));
|
|
621
|
+
// The response carries the size OpenAI says it produced.
|
|
622
|
+
const reportedSize = typeof parsed.size === "string" ? parsed.size : undefined;
|
|
623
|
+
return { images, ...(reportedSize ? { reportedSize } : {}) };
|
|
624
|
+
}
|
|
625
|
+
//# sourceMappingURL=generate-image.js.map
|