tarsk 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +447375 -37
- package/package.json +2 -2
- package/dist/agent/agent.error-utils.d.ts +0 -14
- package/dist/agent/agent.error-utils.js +0 -52
- package/dist/agent/agent.event-transformer.d.ts +0 -55
- package/dist/agent/agent.event-transformer.js +0 -175
- package/dist/agent/agent.executor.d.ts +0 -26
- package/dist/agent/agent.executor.js +0 -286
- package/dist/agent/agent.model-resolver.d.ts +0 -22
- package/dist/agent/agent.model-resolver.js +0 -67
- package/dist/agent/agent.process-manager.d.ts +0 -57
- package/dist/agent/agent.process-manager.js +0 -262
- package/dist/agent/agent.processing-state-manager.d.ts +0 -74
- package/dist/agent/agent.processing-state-manager.js +0 -87
- package/dist/agent/agent.prompt-loader.d.ts +0 -16
- package/dist/agent/agent.prompt-loader.js +0 -227
- package/dist/agent/agent.subagent-executor.d.ts +0 -35
- package/dist/agent/agent.subagent-executor.js +0 -135
- package/dist/bun/index.d.ts +0 -2
- package/dist/bun/index.js +0 -165
- package/dist/cli.d.ts +0 -3
- package/dist/cli.js +0 -22
- package/dist/core/crypto.d.ts +0 -29
- package/dist/core/crypto.js +0 -166
- package/dist/core/dev-server-cache.d.ts +0 -46
- package/dist/core/dev-server-cache.js +0 -59
- package/dist/core/env-manager.d.ts +0 -3
- package/dist/core/env-manager.js +0 -60
- package/dist/core/error-responses.d.ts +0 -61
- package/dist/core/error-responses.js +0 -64
- package/dist/core/logger.d.ts +0 -10
- package/dist/core/logger.js +0 -47
- package/dist/core/paths.d.ts +0 -22
- package/dist/core/paths.js +0 -26
- package/dist/core/random-words.d.ts +0 -18
- package/dist/core/random-words.js +0 -135
- package/dist/core/response-builder.d.ts +0 -50
- package/dist/core/response-builder.js +0 -56
- package/dist/core/route-helpers.d.ts +0 -47
- package/dist/core/route-helpers.js +0 -54
- package/dist/core/run-command-detector.d.ts +0 -26
- package/dist/core/run-command-detector.js +0 -98
- package/dist/core/stream-helper.d.ts +0 -44
- package/dist/core/stream-helper.js +0 -50
- package/dist/core/utils.d.ts +0 -43
- package/dist/core/utils.js +0 -113
- package/dist/core/validation.d.ts +0 -10
- package/dist/core/validation.js +0 -20
- package/dist/database/database.d.ts +0 -40
- package/dist/database/database.encryption.d.ts +0 -33
- package/dist/database/database.encryption.js +0 -62
- package/dist/database/database.js +0 -480
- package/dist/database/database.state.d.ts +0 -52
- package/dist/database/database.state.js +0 -119
- package/dist/database/database.test-utils.d.ts +0 -22
- package/dist/database/database.test-utils.js +0 -39
- package/dist/database/database.types.d.ts +0 -3
- package/dist/database/database.types.js +0 -2
- package/dist/features/agents/agents.manager.d.ts +0 -24
- package/dist/features/agents/agents.manager.js +0 -200
- package/dist/features/ask-user/ask-user.routes.d.ts +0 -9
- package/dist/features/ask-user/ask-user.routes.js +0 -35
- package/dist/features/chat/chat-delete.route.d.ts +0 -15
- package/dist/features/chat/chat-delete.route.js +0 -36
- package/dist/features/chat/chat-post.route.d.ts +0 -11
- package/dist/features/chat/chat-post.route.js +0 -270
- package/dist/features/chat/chat-stop.route.d.ts +0 -21
- package/dist/features/chat/chat-stop.route.js +0 -22
- package/dist/features/chat/chat-subscribe.route.d.ts +0 -9
- package/dist/features/chat/chat-subscribe.route.js +0 -71
- package/dist/features/chat/chat.routes.d.ts +0 -22
- package/dist/features/chat/chat.routes.js +0 -29
- package/dist/features/conversations/conversations-delete.route.d.ts +0 -16
- package/dist/features/conversations/conversations-delete.route.js +0 -34
- package/dist/features/conversations/conversations-get-all.route.d.ts +0 -16
- package/dist/features/conversations/conversations-get-all.route.js +0 -39
- package/dist/features/conversations/conversations-get-by-id.route.d.ts +0 -16
- package/dist/features/conversations/conversations-get-by-id.route.js +0 -38
- package/dist/features/conversations/conversations-get-deleted.route.d.ts +0 -15
- package/dist/features/conversations/conversations-get-deleted.route.js +0 -34
- package/dist/features/conversations/conversations-get-messages.route.d.ts +0 -16
- package/dist/features/conversations/conversations-get-messages.route.js +0 -49
- package/dist/features/conversations/conversations.content.d.ts +0 -28
- package/dist/features/conversations/conversations.content.js +0 -142
- package/dist/features/conversations/conversations.database.d.ts +0 -108
- package/dist/features/conversations/conversations.database.js +0 -373
- package/dist/features/conversations/conversations.manager.d.ts +0 -130
- package/dist/features/conversations/conversations.manager.js +0 -162
- package/dist/features/conversations/conversations.routes.d.ts +0 -21
- package/dist/features/conversations/conversations.routes.js +0 -38
- package/dist/features/conversations/token-usage.route.d.ts +0 -41
- package/dist/features/conversations/token-usage.route.js +0 -419
- package/dist/features/git/git-commit.route.d.ts +0 -12
- package/dist/features/git/git-commit.route.js +0 -39
- package/dist/features/git/git-create-branch.route.d.ts +0 -28
- package/dist/features/git/git-create-branch.route.js +0 -119
- package/dist/features/git/git-create-pr.route.d.ts +0 -13
- package/dist/features/git/git-create-pr.route.js +0 -50
- package/dist/features/git/git-create-repo.route.d.ts +0 -14
- package/dist/features/git/git-create-repo.route.js +0 -108
- package/dist/features/git/git-diff.route.d.ts +0 -30
- package/dist/features/git/git-diff.route.js +0 -189
- package/dist/features/git/git-fetch.route.d.ts +0 -12
- package/dist/features/git/git-fetch.route.js +0 -31
- package/dist/features/git/git-generate-commit-message.route.d.ts +0 -12
- package/dist/features/git/git-generate-commit-message.route.js +0 -76
- package/dist/features/git/git-generate-pr-info.route.d.ts +0 -13
- package/dist/features/git/git-generate-pr-info.route.js +0 -147
- package/dist/features/git/git-github-status.route.d.ts +0 -16
- package/dist/features/git/git-github-status.route.js +0 -68
- package/dist/features/git/git-log.route.d.ts +0 -17
- package/dist/features/git/git-log.route.js +0 -33
- package/dist/features/git/git-pr-status.route.d.ts +0 -15
- package/dist/features/git/git-pr-status.route.js +0 -33
- package/dist/features/git/git-pull.route.d.ts +0 -12
- package/dist/features/git/git-pull.route.js +0 -35
- package/dist/features/git/git-push.route.d.ts +0 -12
- package/dist/features/git/git-push.route.js +0 -46
- package/dist/features/git/git-status-cache.database.d.ts +0 -7
- package/dist/features/git/git-status-cache.database.js +0 -53
- package/dist/features/git/git-status.route.d.ts +0 -15
- package/dist/features/git/git-status.route.js +0 -62
- package/dist/features/git/git-sync-branch.route.d.ts +0 -4
- package/dist/features/git/git-sync-branch.route.js +0 -208
- package/dist/features/git/git-unified-status.route.d.ts +0 -30
- package/dist/features/git/git-unified-status.route.js +0 -165
- package/dist/features/git/git-username.route.d.ts +0 -3
- package/dist/features/git/git-username.route.js +0 -24
- package/dist/features/git/git.manager.d.ts +0 -139
- package/dist/features/git/git.manager.js +0 -352
- package/dist/features/git/git.routes.d.ts +0 -4
- package/dist/features/git/git.routes.js +0 -116
- package/dist/features/git/git.utils.d.ts +0 -82
- package/dist/features/git/git.utils.js +0 -1040
- package/dist/features/mcp/mcp.config.d.ts +0 -27
- package/dist/features/mcp/mcp.config.js +0 -148
- package/dist/features/mcp/mcp.manager.d.ts +0 -61
- package/dist/features/mcp/mcp.manager.js +0 -254
- package/dist/features/mcp/mcp.popular.json +0 -103
- package/dist/features/mcp/mcp.routes.d.ts +0 -13
- package/dist/features/mcp/mcp.routes.js +0 -159
- package/dist/features/mcp/mcp.types.d.ts +0 -80
- package/dist/features/mcp/mcp.types.js +0 -8
- package/dist/features/metadata/metadata.manager.d.ts +0 -126
- package/dist/features/metadata/metadata.manager.js +0 -423
- package/dist/features/models/model-info-aihubmix.d.ts +0 -25
- package/dist/features/models/model-info-aihubmix.js +0 -117
- package/dist/features/models/model-info-openrouter.d.ts +0 -25
- package/dist/features/models/model-info-openrouter.js +0 -104
- package/dist/features/models/model-info.d.ts +0 -37
- package/dist/features/models/model-info.js +0 -39
- package/dist/features/models/models-catalog.d.ts +0 -49
- package/dist/features/models/models-catalog.js +0 -80
- package/dist/features/models/models-catalog.route.d.ts +0 -43
- package/dist/features/models/models-catalog.route.js +0 -15
- package/dist/features/models/models-get-available.route.d.ts +0 -36
- package/dist/features/models/models-get-available.route.js +0 -66
- package/dist/features/models/models-get-enabled.route.d.ts +0 -33
- package/dist/features/models/models-get-enabled.route.js +0 -45
- package/dist/features/models/models-get-model-info.route.d.ts +0 -31
- package/dist/features/models/models-get-model-info.route.js +0 -84
- package/dist/features/models/models-model-disable.route.d.ts +0 -15
- package/dist/features/models/models-model-disable.route.js +0 -20
- package/dist/features/models/models-model-enable.route.d.ts +0 -13
- package/dist/features/models/models-model-enable.route.js +0 -20
- package/dist/features/models/models-provider-refresh.route.d.ts +0 -17
- package/dist/features/models/models-provider-refresh.route.js +0 -20
- package/dist/features/models/models.manager.d.ts +0 -58
- package/dist/features/models/models.manager.js +0 -138
- package/dist/features/models/models.routes.d.ts +0 -18
- package/dist/features/models/models.routes.js +0 -83
- package/dist/features/models/open-router-models.d.ts +0 -38
- package/dist/features/models/open-router-models.js +0 -73
- package/dist/features/models/openai-models.d.ts +0 -63
- package/dist/features/models/openai-models.js +0 -150
- package/dist/features/onboarding/onboarding-get-git-check.route.d.ts +0 -11
- package/dist/features/onboarding/onboarding-get-git-check.route.js +0 -28
- package/dist/features/onboarding/onboarding-get-status.route.d.ts +0 -12
- package/dist/features/onboarding/onboarding-get-status.route.js +0 -15
- package/dist/features/onboarding/onboarding-post-complete.route.d.ts +0 -12
- package/dist/features/onboarding/onboarding-post-complete.route.js +0 -15
- package/dist/features/onboarding/onboarding-post-reset.route.d.ts +0 -12
- package/dist/features/onboarding/onboarding-post-reset.route.js +0 -15
- package/dist/features/onboarding/onboarding.routes.d.ts +0 -18
- package/dist/features/onboarding/onboarding.routes.js +0 -28
- package/dist/features/project-todos/project-todos.database.d.ts +0 -38
- package/dist/features/project-todos/project-todos.database.js +0 -91
- package/dist/features/project-todos/project-todos.routes.d.ts +0 -4
- package/dist/features/project-todos/project-todos.routes.js +0 -94
- package/dist/features/projects/projects-ai-files.route.d.ts +0 -148
- package/dist/features/projects/projects-ai-files.route.js +0 -425
- package/dist/features/projects/projects-commands.route.d.ts +0 -27
- package/dist/features/projects/projects-commands.route.js +0 -39
- package/dist/features/projects/projects-create.route.d.ts +0 -19
- package/dist/features/projects/projects-create.route.js +0 -37
- package/dist/features/projects/projects-delete.route.d.ts +0 -24
- package/dist/features/projects/projects-delete.route.js +0 -34
- package/dist/features/projects/projects-get.route.d.ts +0 -47
- package/dist/features/projects/projects-get.route.js +0 -36
- package/dist/features/projects/projects-list.route.d.ts +0 -58
- package/dist/features/projects/projects-list.route.js +0 -59
- package/dist/features/projects/projects-open-folder.route.d.ts +0 -10
- package/dist/features/projects/projects-open-folder.route.js +0 -11
- package/dist/features/projects/projects-open.route.d.ts +0 -26
- package/dist/features/projects/projects-open.route.js +0 -49
- package/dist/features/projects/projects-package-scripts.route.d.ts +0 -15
- package/dist/features/projects/projects-package-scripts.route.js +0 -96
- package/dist/features/projects/projects-run-command.route.d.ts +0 -8
- package/dist/features/projects/projects-run-command.route.js +0 -21
- package/dist/features/projects/projects-run.route.d.ts +0 -51
- package/dist/features/projects/projects-run.route.js +0 -74
- package/dist/features/projects/projects-update.route.d.ts +0 -24
- package/dist/features/projects/projects-update.route.js +0 -81
- package/dist/features/projects/projects.creator.d.ts +0 -33
- package/dist/features/projects/projects.creator.js +0 -555
- package/dist/features/projects/projects.database.d.ts +0 -61
- package/dist/features/projects/projects.database.js +0 -212
- package/dist/features/projects/projects.manager.d.ts +0 -291
- package/dist/features/projects/projects.manager.js +0 -426
- package/dist/features/projects/projects.open-with.d.ts +0 -27
- package/dist/features/projects/projects.open-with.js +0 -156
- package/dist/features/projects/projects.routes.d.ts +0 -20
- package/dist/features/projects/projects.routes.js +0 -255
- package/dist/features/projects/terminal-session-manager.d.ts +0 -55
- package/dist/features/projects/terminal-session-manager.js +0 -90
- package/dist/features/providers/provider-resolver.d.ts +0 -13
- package/dist/features/providers/provider-resolver.js +0 -22
- package/dist/features/providers/providers-get-credits.route.d.ts +0 -15
- package/dist/features/providers/providers-get-credits.route.js +0 -51
- package/dist/features/providers/providers-get.route.d.ts +0 -16
- package/dist/features/providers/providers-get.route.js +0 -32
- package/dist/features/providers/providers-open-external.route.d.ts +0 -15
- package/dist/features/providers/providers-open-external.route.js +0 -49
- package/dist/features/providers/providers-post-bulk-keys.route.d.ts +0 -14
- package/dist/features/providers/providers-post-bulk-keys.route.js +0 -31
- package/dist/features/providers/providers-post-keys.route.d.ts +0 -14
- package/dist/features/providers/providers-post-keys.route.js +0 -25
- package/dist/features/providers/providers.routes.d.ts +0 -19
- package/dist/features/providers/providers.routes.js +0 -31
- package/dist/features/rules/rules-post.route.d.ts +0 -43
- package/dist/features/rules/rules-post.route.js +0 -89
- package/dist/features/rules/rules.manager.d.ts +0 -36
- package/dist/features/rules/rules.manager.js +0 -203
- package/dist/features/rules/rules.routes.d.ts +0 -12
- package/dist/features/rules/rules.routes.js +0 -13
- package/dist/features/run/run-get-running.route.d.ts +0 -15
- package/dist/features/run/run-get-running.route.js +0 -21
- package/dist/features/run/run-post-start.route.d.ts +0 -8
- package/dist/features/run/run-post-start.route.js +0 -21
- package/dist/features/run/run-post-stop.route.d.ts +0 -15
- package/dist/features/run/run-post-stop.route.js +0 -24
- package/dist/features/run/run-post-suggest.route.d.ts +0 -15
- package/dist/features/run/run-post-suggest.route.js +0 -21
- package/dist/features/run/run-put-command.route.d.ts +0 -15
- package/dist/features/run/run-put-command.route.js +0 -24
- package/dist/features/run/run.routes.d.ts +0 -19
- package/dist/features/run/run.routes.js +0 -31
- package/dist/features/scaffold/index.d.ts +0 -7
- package/dist/features/scaffold/index.js +0 -5
- package/dist/features/scaffold/scaffold-get-templates.route.d.ts +0 -27
- package/dist/features/scaffold/scaffold-get-templates.route.js +0 -17
- package/dist/features/scaffold/scaffold-post.route.d.ts +0 -8
- package/dist/features/scaffold/scaffold-post.route.js +0 -30
- package/dist/features/scaffold/scaffold.routes.d.ts +0 -10
- package/dist/features/scaffold/scaffold.routes.js +0 -16
- package/dist/features/scaffold/scaffold.runner.d.ts +0 -48
- package/dist/features/scaffold/scaffold.runner.js +0 -475
- package/dist/features/scaffold/scaffold.types.d.ts +0 -26
- package/dist/features/scaffold/scaffold.types.js +0 -5
- package/dist/features/skills/skills.activation.d.ts +0 -31
- package/dist/features/skills/skills.activation.js +0 -155
- package/dist/features/skills/skills.manager.d.ts +0 -35
- package/dist/features/skills/skills.manager.js +0 -251
- package/dist/features/slash-commands/slash-commands-delete.route.d.ts +0 -23
- package/dist/features/slash-commands/slash-commands-delete.route.js +0 -36
- package/dist/features/slash-commands/slash-commands-get.route.d.ts +0 -53
- package/dist/features/slash-commands/slash-commands-get.route.js +0 -54
- package/dist/features/slash-commands/slash-commands-post.route.d.ts +0 -39
- package/dist/features/slash-commands/slash-commands-post.route.js +0 -70
- package/dist/features/slash-commands/slash-commands-put.route.d.ts +0 -23
- package/dist/features/slash-commands/slash-commands-put.route.js +0 -36
- package/dist/features/slash-commands/slash-commands.manager.d.ts +0 -46
- package/dist/features/slash-commands/slash-commands.manager.js +0 -265
- package/dist/features/slash-commands/slash-commands.routes.d.ts +0 -13
- package/dist/features/slash-commands/slash-commands.routes.js +0 -20
- package/dist/features/threads/threads-ai-files.route.d.ts +0 -153
- package/dist/features/threads/threads-ai-files.route.js +0 -287
- package/dist/features/threads/threads-conversation-folder-path.route.d.ts +0 -14
- package/dist/features/threads/threads-conversation-folder-path.route.js +0 -23
- package/dist/features/threads/threads-create.route.d.ts +0 -22
- package/dist/features/threads/threads-create.route.js +0 -60
- package/dist/features/threads/threads-delete.route.d.ts +0 -25
- package/dist/features/threads/threads-delete.route.js +0 -35
- package/dist/features/threads/threads-files.route.d.ts +0 -15
- package/dist/features/threads/threads-files.route.js +0 -20
- package/dist/features/threads/threads-fix-comments.route.d.ts +0 -26
- package/dist/features/threads/threads-fix-comments.route.js +0 -45
- package/dist/features/threads/threads-get.route.d.ts +0 -30
- package/dist/features/threads/threads-get.route.js +0 -38
- package/dist/features/threads/threads-list.route.d.ts +0 -56
- package/dist/features/threads/threads-list.route.js +0 -58
- package/dist/features/threads/threads-messages.route.d.ts +0 -28
- package/dist/features/threads/threads-messages.route.js +0 -110
- package/dist/features/threads/threads-open.route.d.ts +0 -26
- package/dist/features/threads/threads-open.route.js +0 -62
- package/dist/features/threads/threads-select.route.d.ts +0 -25
- package/dist/features/threads/threads-select.route.js +0 -35
- package/dist/features/threads/threads-update.route.d.ts +0 -15
- package/dist/features/threads/threads-update.route.js +0 -30
- package/dist/features/threads/threads.database.d.ts +0 -68
- package/dist/features/threads/threads.database.js +0 -215
- package/dist/features/threads/threads.manager.d.ts +0 -204
- package/dist/features/threads/threads.manager.js +0 -505
- package/dist/features/threads/threads.routes.d.ts +0 -20
- package/dist/features/threads/threads.routes.js +0 -230
- package/dist/features/todos/todos.database.d.ts +0 -14
- package/dist/features/todos/todos.database.js +0 -31
- package/dist/features/updates/updates.routes.d.ts +0 -13
- package/dist/features/updates/updates.routes.js +0 -40
- package/dist/index.d.ts +0 -3
- package/dist/project-analyzer.d.ts +0 -26
- package/dist/project-analyzer.js +0 -307
- package/dist/server.d.ts +0 -12
- package/dist/server.js +0 -142
- package/dist/tools/agent-tool.d.ts +0 -49
- package/dist/tools/agent-tool.js +0 -131
- package/dist/tools/ask-user.d.ts +0 -25
- package/dist/tools/ask-user.js +0 -74
- package/dist/tools/ast-grep.d.ts +0 -28
- package/dist/tools/ast-grep.js +0 -273
- package/dist/tools/bash.d.ts +0 -33
- package/dist/tools/bash.js +0 -186
- package/dist/tools/edit-diff.d.ts +0 -24
- package/dist/tools/edit-diff.js +0 -136
- package/dist/tools/edit.d.ts +0 -28
- package/dist/tools/edit.js +0 -78
- package/dist/tools/find.d.ts +0 -31
- package/dist/tools/find.js +0 -117
- package/dist/tools/grep.d.ts +0 -37
- package/dist/tools/grep.js +0 -231
- package/dist/tools/index.d.ts +0 -93
- package/dist/tools/index.js +0 -110
- package/dist/tools/ls.d.ts +0 -31
- package/dist/tools/ls.js +0 -108
- package/dist/tools/mcp-tools.d.ts +0 -31
- package/dist/tools/mcp-tools.js +0 -59
- package/dist/tools/path-utils.d.ts +0 -14
- package/dist/tools/path-utils.js +0 -87
- package/dist/tools/read.d.ts +0 -27
- package/dist/tools/read.js +0 -86
- package/dist/tools/resolve-bin.d.ts +0 -5
- package/dist/tools/resolve-bin.js +0 -28
- package/dist/tools/shell.d.ts +0 -7
- package/dist/tools/shell.js +0 -143
- package/dist/tools/skill-reference-tool.d.ts +0 -30
- package/dist/tools/skill-reference-tool.js +0 -171
- package/dist/tools/skill-tool.d.ts +0 -33
- package/dist/tools/skill-tool.js +0 -213
- package/dist/tools/todo.d.ts +0 -20
- package/dist/tools/todo.js +0 -168
- package/dist/tools/tool-helpers.d.ts +0 -78
- package/dist/tools/tool-helpers.js +0 -109
- package/dist/tools/truncate.d.ts +0 -31
- package/dist/tools/truncate.js +0 -164
- package/dist/tools/write.d.ts +0 -21
- package/dist/tools/write.js +0 -65
|
@@ -1,419 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token usage API route
|
|
3
|
-
* Provides detailed token and cost information for conversations
|
|
4
|
-
*/
|
|
5
|
-
import { errorResponse, successResponse } from "../../core/route-helpers.js";
|
|
6
|
-
import { ErrorCodes } from "../../core/error-responses.js";
|
|
7
|
-
/**
|
|
8
|
-
* Get detailed token usage for a specific conversation
|
|
9
|
-
*/
|
|
10
|
-
export async function handleGetConversationUsage(c, conversationManager, threadManager) {
|
|
11
|
-
try {
|
|
12
|
-
const threadId = c.req.param("threadId");
|
|
13
|
-
const conversationId = c.req.param("conversationId");
|
|
14
|
-
if (!threadId || typeof threadId !== "string") {
|
|
15
|
-
return errorResponse(c, ErrorCodes.INVALID_REQUEST, "threadId is required and must be a string", 400);
|
|
16
|
-
}
|
|
17
|
-
if (!conversationId || typeof conversationId !== "string") {
|
|
18
|
-
return errorResponse(c, ErrorCodes.INVALID_REQUEST, "conversationId is required and must be a string", 400);
|
|
19
|
-
}
|
|
20
|
-
// Verify thread exists
|
|
21
|
-
const thread = await threadManager.getThread(threadId);
|
|
22
|
-
if (!thread) {
|
|
23
|
-
return errorResponse(c, ErrorCodes.THREAD_NOT_FOUND, `Thread not found: ${threadId}`, 404);
|
|
24
|
-
}
|
|
25
|
-
// Get conversation history
|
|
26
|
-
const history = await conversationManager.getConversationHistory(thread.path);
|
|
27
|
-
if (!history) {
|
|
28
|
-
return errorResponse(c, ErrorCodes.HISTORY_FETCH_ERROR, "Conversation history not found", 404);
|
|
29
|
-
}
|
|
30
|
-
// Find all conversations with the same conversationId
|
|
31
|
-
const conversations = history.messages.filter((msg) => msg.conversationId === conversationId);
|
|
32
|
-
if (conversations.length === 0) {
|
|
33
|
-
return errorResponse(c, ErrorCodes.NO_CONVERSATION, "Conversation not found", 404);
|
|
34
|
-
}
|
|
35
|
-
// Extract detailed usage from all conversations
|
|
36
|
-
const totalUsage = {
|
|
37
|
-
input: 0,
|
|
38
|
-
output: 0,
|
|
39
|
-
cacheRead: 0,
|
|
40
|
-
cacheWrite: 0,
|
|
41
|
-
totalTokens: 0,
|
|
42
|
-
cost: {
|
|
43
|
-
input: 0,
|
|
44
|
-
output: 0,
|
|
45
|
-
cacheRead: 0,
|
|
46
|
-
cacheWrite: 0,
|
|
47
|
-
total: 0,
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
const footprintUsage = {
|
|
51
|
-
input: 0,
|
|
52
|
-
output: 0,
|
|
53
|
-
totalTokens: 0,
|
|
54
|
-
};
|
|
55
|
-
const modelInfo = {
|
|
56
|
-
api: "",
|
|
57
|
-
provider: "",
|
|
58
|
-
model: "",
|
|
59
|
-
};
|
|
60
|
-
let peakInput = 0;
|
|
61
|
-
let latestOutput = 0;
|
|
62
|
-
// Process all conversations to extract usage information
|
|
63
|
-
for (const conversation of conversations) {
|
|
64
|
-
if (!conversation.response) {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
// Determine which event type is the authoritative source for this conversation's usage.
|
|
68
|
-
// Prefer `message` events (from message_start) to avoid double-counting when both
|
|
69
|
-
// `message` and `toolcall_delta` events carry usage data for the same API call.
|
|
70
|
-
const hasMessageUsage = conversation.response.events.some((e) => e.type === "message" &&
|
|
71
|
-
e.message?.usage &&
|
|
72
|
-
(e.message.usage.input > 0 ||
|
|
73
|
-
e.message.usage.output > 0 ||
|
|
74
|
-
e.message.usage.cacheRead > 0 ||
|
|
75
|
-
e.message.usage.cacheWrite > 0));
|
|
76
|
-
// Process all events in this conversation
|
|
77
|
-
for (const event of conversation.response.events) {
|
|
78
|
-
if (hasMessageUsage) {
|
|
79
|
-
// Use message events as the single source of truth
|
|
80
|
-
if (event.type === "message" && event.message?.usage) {
|
|
81
|
-
const usage = event.message.usage;
|
|
82
|
-
const hasRealUsage = usage.input > 0 || usage.output > 0 || usage.cacheRead > 0 || usage.cacheWrite > 0;
|
|
83
|
-
if (!hasRealUsage)
|
|
84
|
-
continue;
|
|
85
|
-
totalUsage.input += usage.input ?? 0;
|
|
86
|
-
totalUsage.output += usage.output ?? 0;
|
|
87
|
-
totalUsage.cacheRead += usage.cacheRead ?? 0;
|
|
88
|
-
totalUsage.cacheWrite += usage.cacheWrite ?? 0;
|
|
89
|
-
// Track for footprint (highest input = peak context window usage)
|
|
90
|
-
if ((usage.input ?? 0) >= peakInput) {
|
|
91
|
-
peakInput = usage.input ?? 0;
|
|
92
|
-
latestOutput = usage.output ?? 0;
|
|
93
|
-
}
|
|
94
|
-
// Track model info from message
|
|
95
|
-
if (event.message.model)
|
|
96
|
-
modelInfo.model = event.message.model;
|
|
97
|
-
if (event.message.api)
|
|
98
|
-
modelInfo.api = event.message.api;
|
|
99
|
-
if (event.message.provider)
|
|
100
|
-
modelInfo.provider = event.message.provider;
|
|
101
|
-
// Add cost information if available
|
|
102
|
-
if (usage.cost) {
|
|
103
|
-
totalUsage.cost.input += usage.cost.input ?? 0;
|
|
104
|
-
totalUsage.cost.output += usage.cost.output ?? 0;
|
|
105
|
-
totalUsage.cost.cacheRead += usage.cost.cacheRead ?? 0;
|
|
106
|
-
totalUsage.cost.cacheWrite += usage.cost.cacheWrite ?? 0;
|
|
107
|
-
totalUsage.cost.total += usage.cost.total ?? 0;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
// Fall back to toolcall_delta events when no message events carry usage
|
|
113
|
-
if (event.type === "toolcall_delta" && event.partial?.usage) {
|
|
114
|
-
const usage = event.partial.usage;
|
|
115
|
-
totalUsage.input += usage.input ?? 0;
|
|
116
|
-
totalUsage.output += usage.output ?? 0;
|
|
117
|
-
totalUsage.cacheRead += usage.cacheRead ?? 0;
|
|
118
|
-
totalUsage.cacheWrite += usage.cacheWrite ?? 0;
|
|
119
|
-
// Track for footprint
|
|
120
|
-
if ((usage.input ?? 0) >= peakInput) {
|
|
121
|
-
peakInput = usage.input ?? 0;
|
|
122
|
-
latestOutput = usage.output ?? 0;
|
|
123
|
-
}
|
|
124
|
-
// Track model info from the last event
|
|
125
|
-
if (event.partial.api)
|
|
126
|
-
modelInfo.api = event.partial.api;
|
|
127
|
-
if (event.partial.provider)
|
|
128
|
-
modelInfo.provider = event.partial.provider;
|
|
129
|
-
if (event.partial.model)
|
|
130
|
-
modelInfo.model = event.partial.model;
|
|
131
|
-
// Add cost information if available
|
|
132
|
-
if (usage.cost) {
|
|
133
|
-
totalUsage.cost.input += usage.cost.input ?? 0;
|
|
134
|
-
totalUsage.cost.output += usage.cost.output ?? 0;
|
|
135
|
-
totalUsage.cost.cacheRead += usage.cost.cacheRead ?? 0;
|
|
136
|
-
totalUsage.cost.cacheWrite += usage.cost.cacheWrite ?? 0;
|
|
137
|
-
totalUsage.cost.total += usage.cost.total ?? 0;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// Calculate total tokens if not provided
|
|
144
|
-
totalUsage.totalTokens = totalUsage.input + totalUsage.output;
|
|
145
|
-
// Set final footprint
|
|
146
|
-
footprintUsage.input = peakInput;
|
|
147
|
-
footprintUsage.output = latestOutput;
|
|
148
|
-
footprintUsage.totalTokens = peakInput + latestOutput;
|
|
149
|
-
// Get the latest conversation for metadata
|
|
150
|
-
const latestConversation = conversations[conversations.length - 1];
|
|
151
|
-
return successResponse(c, {
|
|
152
|
-
conversationId,
|
|
153
|
-
threadId,
|
|
154
|
-
timestamp: latestConversation.response?.completedAt ?? new Date().toISOString(),
|
|
155
|
-
usage: totalUsage,
|
|
156
|
-
footprint: footprintUsage,
|
|
157
|
-
model: modelInfo,
|
|
158
|
-
// Include the database-stored totals for comparison
|
|
159
|
-
databaseTotals: {
|
|
160
|
-
inputTokens: latestConversation.inputTokens ?? 0,
|
|
161
|
-
outputTokens: latestConversation.outputTokens ?? 0,
|
|
162
|
-
},
|
|
163
|
-
// Message metadata
|
|
164
|
-
messageCount: conversations.reduce((total, conv) => total + (conv.response?.events.length ?? 0), 0),
|
|
165
|
-
hasToolCalls: conversations.some((conv) => conv.response?.events.some((e) => e.type === "toolcall_delta")),
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
console.error("[token-usage] Error getting conversation usage:", error);
|
|
170
|
-
return errorResponse(c, ErrorCodes.INTERNAL_ERROR, "Failed to retrieve conversation usage", 500, error instanceof Error ? error.message : String(error));
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Get aggregated token usage for an entire thread
|
|
175
|
-
*/
|
|
176
|
-
export async function handleGetThreadUsage(c, conversationManager, threadManager) {
|
|
177
|
-
try {
|
|
178
|
-
const threadId = c.req.param("threadId");
|
|
179
|
-
if (!threadId || typeof threadId !== "string") {
|
|
180
|
-
return errorResponse(c, ErrorCodes.INVALID_REQUEST, "threadId is required and must be a string", 400);
|
|
181
|
-
}
|
|
182
|
-
// Verify thread exists
|
|
183
|
-
const thread = await threadManager.getThread(threadId);
|
|
184
|
-
if (!thread) {
|
|
185
|
-
return errorResponse(c, ErrorCodes.THREAD_NOT_FOUND, `Thread not found: ${threadId}`, 404);
|
|
186
|
-
}
|
|
187
|
-
// Get conversation history
|
|
188
|
-
const history = await conversationManager.getConversationHistory(thread.path);
|
|
189
|
-
if (!history) {
|
|
190
|
-
return errorResponse(c, ErrorCodes.HISTORY_FETCH_ERROR, "Conversation history not found", 404);
|
|
191
|
-
}
|
|
192
|
-
// Aggregate usage across all conversations
|
|
193
|
-
const totalUsage = {
|
|
194
|
-
input: 0,
|
|
195
|
-
output: 0,
|
|
196
|
-
cacheRead: 0,
|
|
197
|
-
cacheWrite: 0,
|
|
198
|
-
totalTokens: 0,
|
|
199
|
-
cost: {
|
|
200
|
-
input: 0,
|
|
201
|
-
output: 0,
|
|
202
|
-
cacheRead: 0,
|
|
203
|
-
cacheWrite: 0,
|
|
204
|
-
total: 0,
|
|
205
|
-
},
|
|
206
|
-
};
|
|
207
|
-
const conversationsUsage = [];
|
|
208
|
-
const modelUsage = new Map();
|
|
209
|
-
// Process each conversation
|
|
210
|
-
for (const conversation of history.messages) {
|
|
211
|
-
if (!conversation.response)
|
|
212
|
-
continue;
|
|
213
|
-
const conversationUsage = {
|
|
214
|
-
conversationId: conversation.conversationId,
|
|
215
|
-
timestamp: conversation.response.completedAt,
|
|
216
|
-
input: 0,
|
|
217
|
-
output: 0,
|
|
218
|
-
cacheRead: 0,
|
|
219
|
-
cacheWrite: 0,
|
|
220
|
-
totalTokens: 0,
|
|
221
|
-
cost: {
|
|
222
|
-
input: 0,
|
|
223
|
-
output: 0,
|
|
224
|
-
cacheRead: 0,
|
|
225
|
-
cacheWrite: 0,
|
|
226
|
-
total: 0,
|
|
227
|
-
},
|
|
228
|
-
model: {
|
|
229
|
-
api: "",
|
|
230
|
-
provider: "",
|
|
231
|
-
model: "",
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
// Track which models are used in this conversation to count each once
|
|
235
|
-
const modelsUsedInConversation = new Set();
|
|
236
|
-
// Determine which event type is the authoritative source for this conversation's usage.
|
|
237
|
-
// Prefer `message` events (from message_start) to avoid double-counting.
|
|
238
|
-
const hasMessageUsage = conversation.response.events.some((e) => e.type === "message" &&
|
|
239
|
-
e.message?.usage &&
|
|
240
|
-
(e.message.usage.input > 0 ||
|
|
241
|
-
e.message.usage.output > 0 ||
|
|
242
|
-
e.message.usage.cacheRead > 0 ||
|
|
243
|
-
e.message.usage.cacheWrite > 0));
|
|
244
|
-
// Extract usage from events
|
|
245
|
-
for (const event of conversation.response.events) {
|
|
246
|
-
if (hasMessageUsage) {
|
|
247
|
-
// Use message events as the single source of truth
|
|
248
|
-
if (event.type === "message" && event.message?.usage) {
|
|
249
|
-
const usage = event.message.usage;
|
|
250
|
-
const hasRealUsage = usage.input > 0 || usage.output > 0 || usage.cacheRead > 0 || usage.cacheWrite > 0;
|
|
251
|
-
if (!hasRealUsage)
|
|
252
|
-
continue;
|
|
253
|
-
conversationUsage.input += usage.input ?? 0;
|
|
254
|
-
conversationUsage.output += usage.output ?? 0;
|
|
255
|
-
conversationUsage.cacheRead += usage.cacheRead ?? 0;
|
|
256
|
-
conversationUsage.cacheWrite += usage.cacheWrite ?? 0;
|
|
257
|
-
if (usage.cost) {
|
|
258
|
-
conversationUsage.cost.input += usage.cost.input ?? 0;
|
|
259
|
-
conversationUsage.cost.output += usage.cost.output ?? 0;
|
|
260
|
-
conversationUsage.cost.cacheRead += usage.cost.cacheRead ?? 0;
|
|
261
|
-
conversationUsage.cost.cacheWrite += usage.cost.cacheWrite ?? 0;
|
|
262
|
-
conversationUsage.cost.total += usage.cost.total ?? 0;
|
|
263
|
-
}
|
|
264
|
-
// Track model info
|
|
265
|
-
if (event.message.model) {
|
|
266
|
-
conversationUsage.model.model = event.message.model;
|
|
267
|
-
const modelKey = event.message.model;
|
|
268
|
-
if (!modelUsage.has(modelKey)) {
|
|
269
|
-
modelUsage.set(modelKey, { input: 0, output: 0, conversations: 0 });
|
|
270
|
-
}
|
|
271
|
-
const modelStats = modelUsage.get(modelKey);
|
|
272
|
-
modelStats.input += usage.input ?? 0;
|
|
273
|
-
modelStats.output += usage.output ?? 0;
|
|
274
|
-
modelsUsedInConversation.add(modelKey);
|
|
275
|
-
}
|
|
276
|
-
if (event.message.api)
|
|
277
|
-
conversationUsage.model.api = event.message.api;
|
|
278
|
-
if (event.message.provider)
|
|
279
|
-
conversationUsage.model.provider = event.message.provider;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
// Fall back to toolcall_delta events when no message events carry usage
|
|
284
|
-
if (event.type === "toolcall_delta" && event.partial?.usage) {
|
|
285
|
-
const usage = event.partial.usage;
|
|
286
|
-
conversationUsage.input += usage.input ?? 0;
|
|
287
|
-
conversationUsage.output += usage.output ?? 0;
|
|
288
|
-
conversationUsage.cacheRead += usage.cacheRead ?? 0;
|
|
289
|
-
conversationUsage.cacheWrite += usage.cacheWrite ?? 0;
|
|
290
|
-
if (usage.cost) {
|
|
291
|
-
conversationUsage.cost.input += usage.cost.input ?? 0;
|
|
292
|
-
conversationUsage.cost.output += usage.cost.output ?? 0;
|
|
293
|
-
conversationUsage.cost.cacheRead += usage.cost.cacheRead ?? 0;
|
|
294
|
-
conversationUsage.cost.cacheWrite += usage.cost.cacheWrite ?? 0;
|
|
295
|
-
conversationUsage.cost.total += usage.cost.total ?? 0;
|
|
296
|
-
}
|
|
297
|
-
// Track model info
|
|
298
|
-
if (event.partial.model) {
|
|
299
|
-
conversationUsage.model.model = event.partial.model;
|
|
300
|
-
const modelKey = event.partial.model;
|
|
301
|
-
if (!modelUsage.has(modelKey)) {
|
|
302
|
-
modelUsage.set(modelKey, { input: 0, output: 0, conversations: 0 });
|
|
303
|
-
}
|
|
304
|
-
const modelStats = modelUsage.get(modelKey);
|
|
305
|
-
modelStats.input += usage.input ?? 0;
|
|
306
|
-
modelStats.output += usage.output ?? 0;
|
|
307
|
-
modelsUsedInConversation.add(modelKey);
|
|
308
|
-
}
|
|
309
|
-
if (event.partial.api)
|
|
310
|
-
conversationUsage.model.api = event.partial.api;
|
|
311
|
-
if (event.partial.provider)
|
|
312
|
-
conversationUsage.model.provider = event.partial.provider;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
// Increment conversation count once per model used in this conversation
|
|
317
|
-
for (const modelKey of modelsUsedInConversation) {
|
|
318
|
-
const modelStats = modelUsage.get(modelKey);
|
|
319
|
-
modelStats.conversations += 1;
|
|
320
|
-
}
|
|
321
|
-
conversationUsage.totalTokens = conversationUsage.input + conversationUsage.output;
|
|
322
|
-
// Add to totals
|
|
323
|
-
totalUsage.input += conversationUsage.input;
|
|
324
|
-
totalUsage.output += conversationUsage.output;
|
|
325
|
-
totalUsage.cacheRead += conversationUsage.cacheRead;
|
|
326
|
-
totalUsage.cacheWrite += conversationUsage.cacheWrite;
|
|
327
|
-
totalUsage.cost.input += conversationUsage.cost.input;
|
|
328
|
-
totalUsage.cost.output += conversationUsage.cost.output;
|
|
329
|
-
totalUsage.cost.cacheRead += conversationUsage.cost.cacheRead;
|
|
330
|
-
totalUsage.cost.cacheWrite += conversationUsage.cost.cacheWrite;
|
|
331
|
-
totalUsage.cost.total += conversationUsage.cost.total;
|
|
332
|
-
conversationsUsage.push(conversationUsage);
|
|
333
|
-
}
|
|
334
|
-
totalUsage.totalTokens = totalUsage.input + totalUsage.output;
|
|
335
|
-
// Convert model usage map to array
|
|
336
|
-
const modelBreakdown = Array.from(modelUsage.entries()).map(([model, stats]) => ({
|
|
337
|
-
model,
|
|
338
|
-
...stats,
|
|
339
|
-
totalTokens: stats.input + stats.output,
|
|
340
|
-
}));
|
|
341
|
-
return successResponse(c, {
|
|
342
|
-
threadId,
|
|
343
|
-
totalUsage,
|
|
344
|
-
conversationCount: conversationsUsage.length,
|
|
345
|
-
conversations: conversationsUsage,
|
|
346
|
-
modelBreakdown,
|
|
347
|
-
lastUpdated: history.lastUpdated,
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
catch (error) {
|
|
351
|
-
console.error("[token-usage] Error getting thread usage:", error);
|
|
352
|
-
return errorResponse(c, ErrorCodes.INTERNAL_ERROR, "Failed to retrieve thread usage", 500, error instanceof Error ? error.message : String(error));
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Get simple usage summary for a thread (for UI display)
|
|
357
|
-
*/
|
|
358
|
-
export async function handleGetThreadUsageSummary(c, conversationManager, threadManager) {
|
|
359
|
-
try {
|
|
360
|
-
const threadId = c.req.param("threadId");
|
|
361
|
-
if (!threadId || typeof threadId !== "string") {
|
|
362
|
-
return errorResponse(c, ErrorCodes.INVALID_REQUEST, "threadId is required and must be a string", 400);
|
|
363
|
-
}
|
|
364
|
-
// Verify thread exists
|
|
365
|
-
const thread = await threadManager.getThread(threadId);
|
|
366
|
-
if (!thread) {
|
|
367
|
-
return errorResponse(c, ErrorCodes.THREAD_NOT_FOUND, `Thread not found: ${threadId}`, 404);
|
|
368
|
-
}
|
|
369
|
-
// Get conversation history
|
|
370
|
-
const history = await conversationManager.getConversationHistory(thread.path);
|
|
371
|
-
if (!history) {
|
|
372
|
-
return errorResponse(c, ErrorCodes.HISTORY_FETCH_ERROR, "Conversation history not found", 404);
|
|
373
|
-
}
|
|
374
|
-
let totalInputTokens = 0;
|
|
375
|
-
let totalOutputTokens = 0;
|
|
376
|
-
let totalCost = 0;
|
|
377
|
-
let conversationCount = 0;
|
|
378
|
-
for (const conversation of history.messages) {
|
|
379
|
-
if (conversation.response) {
|
|
380
|
-
totalInputTokens += conversation.inputTokens ?? 0;
|
|
381
|
-
totalOutputTokens += conversation.outputTokens ?? 0;
|
|
382
|
-
conversationCount++;
|
|
383
|
-
// Prefer cost from message events; fall back to toolcall_delta if none present.
|
|
384
|
-
// This mirrors the same prefer-message strategy used in the other handlers.
|
|
385
|
-
const hasMessageCost = conversation.response.events.some((e) => e.type === "message" && e.message?.usage?.cost && (e.message.usage.cost.total ?? 0) > 0);
|
|
386
|
-
if (hasMessageCost) {
|
|
387
|
-
for (const event of conversation.response.events) {
|
|
388
|
-
if (event.type === "message" && event.message?.usage?.cost?.total) {
|
|
389
|
-
totalCost += event.message.usage.cost.total;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
for (const event of conversation.response.events) {
|
|
395
|
-
if (event.type === "toolcall_delta" && event.partial?.usage?.cost?.total) {
|
|
396
|
-
totalCost += event.partial.usage.cost.total;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return successResponse(c, {
|
|
403
|
-
threadId,
|
|
404
|
-
totalInputTokens,
|
|
405
|
-
totalOutputTokens,
|
|
406
|
-
totalTokens: totalInputTokens + totalOutputTokens,
|
|
407
|
-
totalCost,
|
|
408
|
-
conversationCount,
|
|
409
|
-
averageTokensPerConversation: conversationCount > 0
|
|
410
|
-
? Math.round((totalInputTokens + totalOutputTokens) / conversationCount)
|
|
411
|
-
: 0,
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
catch (error) {
|
|
415
|
-
console.error("[token-usage] Error getting usage summary:", error);
|
|
416
|
-
return errorResponse(c, ErrorCodes.INTERNAL_ERROR, "Failed to retrieve usage summary", 500, error instanceof Error ? error.message : String(error));
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
//# sourceMappingURL=token-usage.route.js.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Context } from "hono";
|
|
2
|
-
import { MetadataManager } from "../metadata/metadata.manager.js";
|
|
3
|
-
export declare function gitCommitHandler(c: Context, metadataManager: MetadataManager): Promise<(Response & import("hono").TypedResponse<{
|
|
4
|
-
error: string;
|
|
5
|
-
}, 400, "json">) | (Response & import("hono").TypedResponse<{
|
|
6
|
-
error: string;
|
|
7
|
-
}, 404, "json">) | (Response & import("hono").TypedResponse<{
|
|
8
|
-
success: true;
|
|
9
|
-
}, import("hono/utils/http-status").ContentfulStatusCode, "json">) | (Response & import("hono").TypedResponse<{
|
|
10
|
-
error: string;
|
|
11
|
-
}, 500, "json">)>;
|
|
12
|
-
//# sourceMappingURL=git-commit.route.d.ts.map
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { resolveThreadPath, getGitRoot, stageAllChanges, commitChanges } from "./git.utils.js";
|
|
2
|
-
export async function gitCommitHandler(c, metadataManager) {
|
|
3
|
-
try {
|
|
4
|
-
const threadId = c.req.param("threadId");
|
|
5
|
-
const body = await c.req.json();
|
|
6
|
-
const { message } = body;
|
|
7
|
-
if (!message) {
|
|
8
|
-
return c.json({ error: "Commit message is required" }, 400);
|
|
9
|
-
}
|
|
10
|
-
const thread = await metadataManager
|
|
11
|
-
.loadThreads()
|
|
12
|
-
.then((threads) => threads.find((t) => t.id === threadId));
|
|
13
|
-
if (!thread) {
|
|
14
|
-
return c.json({ error: "Thread not found" }, 404);
|
|
15
|
-
}
|
|
16
|
-
const repoPath = thread.path;
|
|
17
|
-
if (!repoPath) {
|
|
18
|
-
return c.json({ error: "Thread path not found" }, 404);
|
|
19
|
-
}
|
|
20
|
-
const absolutePath = resolveThreadPath(repoPath);
|
|
21
|
-
let gitRoot;
|
|
22
|
-
try {
|
|
23
|
-
gitRoot = await getGitRoot(absolutePath);
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
return c.json({ error: `Path is not a git repository: ${absolutePath}` }, 400);
|
|
27
|
-
}
|
|
28
|
-
// Stage all changes
|
|
29
|
-
await stageAllChanges(gitRoot);
|
|
30
|
-
// Commit changes
|
|
31
|
-
await commitChanges(gitRoot, message);
|
|
32
|
-
return c.json({ success: true });
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
const message = error instanceof Error ? error.message : "Failed to commit changes";
|
|
36
|
-
return c.json({ error: message }, 500);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=git-commit.route.js.map
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* POST /api/git/create-branch/:threadId
|
|
3
|
-
* Create a new branch on an existing thread's repository
|
|
4
|
-
*
|
|
5
|
-
* Response:
|
|
6
|
-
* {
|
|
7
|
-
* "success": true,
|
|
8
|
-
* "branchName": "auto-generated-branch-name"
|
|
9
|
-
* }
|
|
10
|
-
*
|
|
11
|
-
* On error:
|
|
12
|
-
* {
|
|
13
|
-
* "error": "error message"
|
|
14
|
-
* }
|
|
15
|
-
*/
|
|
16
|
-
import type { Context } from "hono";
|
|
17
|
-
import { MetadataManager } from "../metadata/metadata.manager.js";
|
|
18
|
-
export declare function gitCreateBranchHandler(c: Context, metadataManager: MetadataManager): Promise<(Response & import("hono").TypedResponse<{
|
|
19
|
-
error: string;
|
|
20
|
-
}, 404, "json">) | (Response & import("hono").TypedResponse<{
|
|
21
|
-
error: string;
|
|
22
|
-
}, 400, "json">) | (Response & import("hono").TypedResponse<{
|
|
23
|
-
success: true;
|
|
24
|
-
branchName: string;
|
|
25
|
-
}, import("hono/utils/http-status").ContentfulStatusCode, "json">) | (Response & import("hono").TypedResponse<{
|
|
26
|
-
error: string;
|
|
27
|
-
}, 500, "json">)>;
|
|
28
|
-
//# sourceMappingURL=git-create-branch.route.d.ts.map
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* POST /api/git/create-branch/:threadId
|
|
3
|
-
* Create a new branch on an existing thread's repository
|
|
4
|
-
*
|
|
5
|
-
* Response:
|
|
6
|
-
* {
|
|
7
|
-
* "success": true,
|
|
8
|
-
* "branchName": "auto-generated-branch-name"
|
|
9
|
-
* }
|
|
10
|
-
*
|
|
11
|
-
* On error:
|
|
12
|
-
* {
|
|
13
|
-
* "error": "error message"
|
|
14
|
-
* }
|
|
15
|
-
*/
|
|
16
|
-
import { resolveThreadPath, getGitRoot } from "./git.utils.js";
|
|
17
|
-
import { spawnProcess } from "../../core/utils.js";
|
|
18
|
-
import { generateRandomThreadName } from "../../core/random-words.js";
|
|
19
|
-
function sanitizeBranchName(name) {
|
|
20
|
-
if (!name || typeof name !== "string") {
|
|
21
|
-
return "branch";
|
|
22
|
-
}
|
|
23
|
-
return (name
|
|
24
|
-
.trim()
|
|
25
|
-
.toLowerCase()
|
|
26
|
-
.replace(/\s+/g, "-")
|
|
27
|
-
.replace(/[^a-zA-Z0-9\-_/.]/g, "")
|
|
28
|
-
.replace(/^[/.]+|[/.]+$/g, "")
|
|
29
|
-
.replace(/-+/g, "-") || "branch");
|
|
30
|
-
}
|
|
31
|
-
function checkBranchExists(gitRoot, branchName) {
|
|
32
|
-
return new Promise((resolve) => {
|
|
33
|
-
const proc = spawnProcess("git", ["show-ref", "--verify", "--quiet", `refs/heads/${branchName}`], {
|
|
34
|
-
cwd: gitRoot,
|
|
35
|
-
});
|
|
36
|
-
proc.on("close", (code) => {
|
|
37
|
-
resolve(code === 0);
|
|
38
|
-
});
|
|
39
|
-
proc.on("error", () => {
|
|
40
|
-
resolve(false);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
function createAndCheckoutBranch(gitRoot, branchName, baseBranch) {
|
|
45
|
-
const args = baseBranch
|
|
46
|
-
? ["checkout", "-b", branchName, `origin/${baseBranch}`]
|
|
47
|
-
: ["checkout", "-b", branchName];
|
|
48
|
-
return new Promise((resolve, reject) => {
|
|
49
|
-
const proc = spawnProcess("git", args, {
|
|
50
|
-
cwd: gitRoot,
|
|
51
|
-
});
|
|
52
|
-
let err = "";
|
|
53
|
-
if (proc.stderr) {
|
|
54
|
-
proc.stderr.on("data", (d) => {
|
|
55
|
-
err += d.toString();
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
proc.on("close", (code) => {
|
|
59
|
-
if (code === 0) {
|
|
60
|
-
resolve();
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
reject(new Error(err || `Failed to create branch "${branchName}"`));
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
proc.on("error", reject);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
export async function gitCreateBranchHandler(c, metadataManager) {
|
|
70
|
-
try {
|
|
71
|
-
const threadId = c.req.param("threadId");
|
|
72
|
-
const thread = await metadataManager
|
|
73
|
-
.loadThreads()
|
|
74
|
-
.then((threads) => threads.find((t) => t.id === threadId));
|
|
75
|
-
if (!thread) {
|
|
76
|
-
return c.json({ error: "Thread not found" }, 404);
|
|
77
|
-
}
|
|
78
|
-
const repoPath = thread.path;
|
|
79
|
-
if (!repoPath) {
|
|
80
|
-
return c.json({ error: "Thread path not found" }, 404);
|
|
81
|
-
}
|
|
82
|
-
const body = (await c.req.json().catch(() => ({})));
|
|
83
|
-
const baseBranch = body.baseBranch;
|
|
84
|
-
const absolutePath = resolveThreadPath(repoPath);
|
|
85
|
-
let gitRoot;
|
|
86
|
-
try {
|
|
87
|
-
gitRoot = await getGitRoot(absolutePath);
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
return c.json({ error: `Path is not a git repository: ${absolutePath}` }, 400);
|
|
91
|
-
}
|
|
92
|
-
// Auto-generate branch name using random words
|
|
93
|
-
let branchName = sanitizeBranchName(generateRandomThreadName());
|
|
94
|
-
// Check if branch exists and find a unique name if needed
|
|
95
|
-
let branchExists = await checkBranchExists(gitRoot, branchName);
|
|
96
|
-
let counter = 2;
|
|
97
|
-
const baseBranchName = branchName;
|
|
98
|
-
while (branchExists) {
|
|
99
|
-
branchName = `${baseBranchName}-${counter}`;
|
|
100
|
-
branchExists = await checkBranchExists(gitRoot, branchName);
|
|
101
|
-
counter++;
|
|
102
|
-
}
|
|
103
|
-
// Create and checkout the new branch
|
|
104
|
-
await createAndCheckoutBranch(gitRoot, branchName, baseBranch);
|
|
105
|
-
// Update thread's currentBranch in metadata
|
|
106
|
-
const threads = await metadataManager.loadThreads();
|
|
107
|
-
const threadIndex = threads.findIndex((t) => t.id === threadId);
|
|
108
|
-
if (threadIndex !== -1) {
|
|
109
|
-
threads[threadIndex].currentBranch = branchName;
|
|
110
|
-
await metadataManager.saveThreads(threads);
|
|
111
|
-
}
|
|
112
|
-
return c.json({ success: true, branchName });
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
const message = error instanceof Error ? error.message : "Failed to create branch";
|
|
116
|
-
return c.json({ error: message }, 500);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
//# sourceMappingURL=git-create-branch.route.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Context } from "hono";
|
|
2
|
-
import { MetadataManager } from "../metadata/metadata.manager.js";
|
|
3
|
-
export declare function gitCreatePrHandler(c: Context, metadataManager: MetadataManager): Promise<(Response & import("hono").TypedResponse<{
|
|
4
|
-
error: string;
|
|
5
|
-
}, 404, "json">) | (Response & import("hono").TypedResponse<{
|
|
6
|
-
error: string;
|
|
7
|
-
}, 400, "json">) | (Response & import("hono").TypedResponse<{
|
|
8
|
-
success: true;
|
|
9
|
-
prUrl: string;
|
|
10
|
-
}, import("hono/utils/http-status").ContentfulStatusCode, "json">) | (Response & import("hono").TypedResponse<{
|
|
11
|
-
error: string;
|
|
12
|
-
}, 500, "json">)>;
|
|
13
|
-
//# sourceMappingURL=git-create-pr.route.d.ts.map
|