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,423 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MetadataManager handles persistence of project and thread metadata
|
|
3
|
-
*
|
|
4
|
-
* This manager provides SQLite-based storage with atomic transactions
|
|
5
|
-
* to ensure data consistency.
|
|
6
|
-
*/
|
|
7
|
-
import { getDatabase } from '../../database/database.js';
|
|
8
|
-
import * as dbProjects from '../projects/projects.database.js';
|
|
9
|
-
import * as dbThreads from '../threads/threads.database.js';
|
|
10
|
-
import * as dbState from '../../database/database.state.js';
|
|
11
|
-
import { encryptProviderKey, decryptProviderKey, isEncryptedKey, } from '../../database/database.encryption.js';
|
|
12
|
-
export class MetadataManager {
|
|
13
|
-
db;
|
|
14
|
-
/**
|
|
15
|
-
* Create a new MetadataManager
|
|
16
|
-
* @param _dataDir - Directory where metadata files will be stored
|
|
17
|
-
* (e.g. ~/Library/Application Support/Tarsk/data)
|
|
18
|
-
*/
|
|
19
|
-
constructor(_dataDir) {
|
|
20
|
-
// Database will be initialized in initialize() method
|
|
21
|
-
this.db = null;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Initialize metadata database
|
|
25
|
-
*/
|
|
26
|
-
async initialize() {
|
|
27
|
-
// Initialize database connection
|
|
28
|
-
this.db = await getDatabase();
|
|
29
|
-
// Just verify connection is working
|
|
30
|
-
try {
|
|
31
|
-
await this.db.execute("SELECT 1");
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
throw new Error(`Failed to initialize database: ${String(error)}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Save projects to database using atomic transaction
|
|
39
|
-
* @param projects - Array of projects to save
|
|
40
|
-
*/
|
|
41
|
-
async saveProjects(projects) {
|
|
42
|
-
try {
|
|
43
|
-
await this.db.execute("BEGIN TRANSACTION");
|
|
44
|
-
try {
|
|
45
|
-
// Get existing projects to find which ones are being deleted
|
|
46
|
-
const existingProjects = await dbProjects.getAllProjects(this.db);
|
|
47
|
-
const existingProjectIds = new Set(existingProjects.map((p) => p.id));
|
|
48
|
-
const newProjectIds = new Set(projects.map((p) => p.id));
|
|
49
|
-
// Delete projects that are being removed (cascade will delete their threads)
|
|
50
|
-
for (const projectId of existingProjectIds) {
|
|
51
|
-
if (!newProjectIds.has(projectId)) {
|
|
52
|
-
// This project is being deleted
|
|
53
|
-
await dbProjects.deleteProject(this.db, projectId);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// Update or insert projects
|
|
57
|
-
for (const project of projects) {
|
|
58
|
-
if (existingProjectIds.has(project.id)) {
|
|
59
|
-
// Project exists, update it
|
|
60
|
-
await dbProjects.updateProject(this.db, project.id, project);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
// New project, insert it
|
|
64
|
-
await dbProjects.insertProject(this.db, project);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
await this.db.execute("COMMIT");
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
await this.db.execute("ROLLBACK");
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
console.error("Failed to save projects:", error);
|
|
76
|
-
throw new Error(`Failed to save projects: ${String(error)}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Load projects from database
|
|
81
|
-
* @returns Array of projects
|
|
82
|
-
*/
|
|
83
|
-
async loadProjects() {
|
|
84
|
-
try {
|
|
85
|
-
return dbProjects.getAllProjects(this.db);
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
throw new Error(`Failed to load projects: ${String(error)}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Save threads to database using atomic transaction
|
|
93
|
-
* @param threads - Array of threads to save
|
|
94
|
-
*/
|
|
95
|
-
async saveThreads(threads) {
|
|
96
|
-
try {
|
|
97
|
-
await this.db.execute("BEGIN TRANSACTION");
|
|
98
|
-
try {
|
|
99
|
-
// Get existing threads to find which ones are being deleted
|
|
100
|
-
const existingThreads = await dbThreads.getAllThreads(this.db);
|
|
101
|
-
const existingThreadIds = new Set(existingThreads.map((t) => t.id));
|
|
102
|
-
const newThreadIds = new Set(threads.map((t) => t.id));
|
|
103
|
-
// Delete threads that are being removed
|
|
104
|
-
for (const threadId of existingThreadIds) {
|
|
105
|
-
if (!newThreadIds.has(threadId)) {
|
|
106
|
-
// This thread is being deleted
|
|
107
|
-
await dbThreads.deleteThread(this.db, threadId);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// Update or insert threads
|
|
111
|
-
for (const thread of threads) {
|
|
112
|
-
if (existingThreadIds.has(thread.id)) {
|
|
113
|
-
// Thread exists, update it
|
|
114
|
-
await dbThreads.updateThread(this.db, thread.id, thread);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
// New thread, insert it
|
|
118
|
-
await dbThreads.insertThread(this.db, thread);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
await this.db.execute("COMMIT");
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
await this.db.execute("ROLLBACK");
|
|
125
|
-
throw error;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
console.error("Failed to save threads:", error);
|
|
130
|
-
throw new Error(`Failed to save threads: ${String(error)}`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Load threads from database
|
|
135
|
-
* @returns Array of threads
|
|
136
|
-
*/
|
|
137
|
-
async loadThreads() {
|
|
138
|
-
try {
|
|
139
|
-
return dbThreads.getAllThreads(this.db);
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
throw new Error(`Failed to load threads: ${String(error)}`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Save application state to database
|
|
147
|
-
* @param state - Application state to save
|
|
148
|
-
*/
|
|
149
|
-
async saveState(state) {
|
|
150
|
-
try {
|
|
151
|
-
await this.db.execute("BEGIN TRANSACTION");
|
|
152
|
-
try {
|
|
153
|
-
// Save each state field
|
|
154
|
-
await dbState.setState(this.db, "selectedThreadId", state.selectedThreadId);
|
|
155
|
-
await dbState.setState(this.db, "enabledModels", state.enabledModels);
|
|
156
|
-
await dbState.setState(this.db, "onboardingCompleted", state.onboardingCompleted);
|
|
157
|
-
// Save provider keys (encrypted, but skip if already encrypted)
|
|
158
|
-
const encryptedKeys = {};
|
|
159
|
-
for (const [provider, key] of Object.entries(state.providerKeys)) {
|
|
160
|
-
if (!key) {
|
|
161
|
-
encryptedKeys[provider] = "";
|
|
162
|
-
}
|
|
163
|
-
else if (isEncryptedKey(key)) {
|
|
164
|
-
// Already encrypted, use as-is
|
|
165
|
-
encryptedKeys[provider] = key;
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
// Plain-text, encrypt it
|
|
169
|
-
encryptedKeys[provider] = await encryptProviderKey(key);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
await dbState.setState(this.db, "providerKeys", encryptedKeys);
|
|
173
|
-
await this.db.execute("COMMIT");
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
await this.db.execute("ROLLBACK");
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
catch (error) {
|
|
181
|
-
throw new Error(`Failed to save state: ${String(error)}`);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Load application state from database
|
|
186
|
-
* @returns Application state
|
|
187
|
-
*/
|
|
188
|
-
async loadState() {
|
|
189
|
-
try {
|
|
190
|
-
const allState = await dbState.getAllState(this.db);
|
|
191
|
-
// Reconstruct AppState from key-value pairs (excluding encryption_key)
|
|
192
|
-
const selectedThreadId = allState.selectedThreadId ?? null;
|
|
193
|
-
const onboardingCompleted = allState.onboardingCompleted || false;
|
|
194
|
-
const enabledModels = allState.enabledModels || {};
|
|
195
|
-
// Load and decrypt provider keys
|
|
196
|
-
const encryptedKeys = allState.providerKeys || {};
|
|
197
|
-
const providerKeys = {};
|
|
198
|
-
let needsMigration = false;
|
|
199
|
-
for (const [provider, encryptedKey] of Object.entries(encryptedKeys)) {
|
|
200
|
-
if (!encryptedKey) {
|
|
201
|
-
providerKeys[provider] = "";
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
// Check if key is encrypted
|
|
205
|
-
if (isEncryptedKey(encryptedKey)) {
|
|
206
|
-
try {
|
|
207
|
-
const decrypted = await decryptProviderKey(encryptedKey);
|
|
208
|
-
providerKeys[provider] = decrypted;
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
console.error(`[MetadataManager] Failed to decrypt key for ${provider}:`, error);
|
|
212
|
-
providerKeys[provider] = "";
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
// Plain-text key found - needs migration
|
|
217
|
-
console.log(`[MetadataManager] Found plain-text key for ${provider}, will encrypt on save`);
|
|
218
|
-
providerKeys[provider] = encryptedKey;
|
|
219
|
-
needsMigration = true;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
// If we found plain-text keys, migrate them
|
|
223
|
-
if (needsMigration) {
|
|
224
|
-
console.log("[MetadataManager] Migrating plain-text keys to encrypted format");
|
|
225
|
-
await this.saveAllProviderKeys(providerKeys);
|
|
226
|
-
}
|
|
227
|
-
return {
|
|
228
|
-
selectedThreadId,
|
|
229
|
-
onboardingCompleted,
|
|
230
|
-
providerKeys,
|
|
231
|
-
enabledModels,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
catch (error) {
|
|
235
|
-
throw new Error(`Failed to load state: ${String(error)}`);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Update all provider keys at once
|
|
240
|
-
* @param keys - Object mapping provider names to API keys
|
|
241
|
-
*/
|
|
242
|
-
async saveAllProviderKeys(keys) {
|
|
243
|
-
try {
|
|
244
|
-
const state = await this.loadState();
|
|
245
|
-
// Encrypt all keys before saving (skip if already encrypted)
|
|
246
|
-
const encryptedKeys = {};
|
|
247
|
-
for (const [provider, key] of Object.entries(keys)) {
|
|
248
|
-
if (!key) {
|
|
249
|
-
encryptedKeys[provider] = "";
|
|
250
|
-
}
|
|
251
|
-
else if (isEncryptedKey(key)) {
|
|
252
|
-
// Already encrypted, use as-is
|
|
253
|
-
encryptedKeys[provider] = key;
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
// Plain-text, encrypt it
|
|
257
|
-
encryptedKeys[provider] = await encryptProviderKey(key);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
state.providerKeys = { ...state.providerKeys, ...encryptedKeys };
|
|
261
|
-
await this.saveState(state);
|
|
262
|
-
}
|
|
263
|
-
catch (error) {
|
|
264
|
-
throw new Error(`Failed to save provider keys: ${String(error)}`);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Update provider keys
|
|
269
|
-
* @param providerName - Name of the provider
|
|
270
|
-
* @param apiKey - API key to save (will be encrypted if not already)
|
|
271
|
-
*/
|
|
272
|
-
async saveProviderKey(providerName, apiKey) {
|
|
273
|
-
try {
|
|
274
|
-
const state = await this.loadState();
|
|
275
|
-
// Encrypt the API key before saving (skip if already encrypted)
|
|
276
|
-
if (!apiKey) {
|
|
277
|
-
state.providerKeys[providerName] = "";
|
|
278
|
-
}
|
|
279
|
-
else if (isEncryptedKey(apiKey)) {
|
|
280
|
-
// Already encrypted, use as-is
|
|
281
|
-
state.providerKeys[providerName] = apiKey;
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
// Plain-text, encrypt it
|
|
285
|
-
state.providerKeys[providerName] = await encryptProviderKey(apiKey);
|
|
286
|
-
}
|
|
287
|
-
await this.saveState(state);
|
|
288
|
-
}
|
|
289
|
-
catch (error) {
|
|
290
|
-
throw new Error(`Failed to save provider key: ${String(error)}`);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Get all provider keys
|
|
295
|
-
* @returns Record of provider names to decrypted API keys
|
|
296
|
-
*/
|
|
297
|
-
async getProviderKeys() {
|
|
298
|
-
try {
|
|
299
|
-
const state = await this.loadState();
|
|
300
|
-
const decryptedKeys = {};
|
|
301
|
-
// Decrypt all provider keys before returning
|
|
302
|
-
for (const [providerName, encryptedKey] of Object.entries(state.providerKeys)) {
|
|
303
|
-
if (isEncryptedKey(encryptedKey)) {
|
|
304
|
-
try {
|
|
305
|
-
const decryptedKey = await decryptProviderKey(encryptedKey);
|
|
306
|
-
decryptedKeys[providerName] = decryptedKey;
|
|
307
|
-
}
|
|
308
|
-
catch (error) {
|
|
309
|
-
console.error(`Failed to decrypt key for provider ${providerName}:`, error);
|
|
310
|
-
decryptedKeys[providerName] = ""; // Use empty string if decryption fails
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
// Key is not encrypted, use as-is
|
|
315
|
-
decryptedKeys[providerName] = encryptedKey;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
return decryptedKeys;
|
|
319
|
-
}
|
|
320
|
-
catch (error) {
|
|
321
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
322
|
-
console.error("[MetadataManager] Failed to get provider keys:", errorMessage);
|
|
323
|
-
throw new Error(`Failed to get provider keys: ${errorMessage}`);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Set the selected thread ID
|
|
328
|
-
* @param threadId - Thread ID to select (or null to deselect)
|
|
329
|
-
*/
|
|
330
|
-
async setSelectedThread(threadId) {
|
|
331
|
-
const state = await this.loadState();
|
|
332
|
-
state.selectedThreadId = threadId;
|
|
333
|
-
await this.saveState(state);
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Get the selected thread ID
|
|
337
|
-
* @returns The selected thread ID or null
|
|
338
|
-
*/
|
|
339
|
-
async getSelectedThread() {
|
|
340
|
-
const state = await this.loadState();
|
|
341
|
-
return state.selectedThreadId;
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Enable a model for a provider
|
|
345
|
-
* @param provider - Provider name
|
|
346
|
-
* @param modelId - Model ID to enable
|
|
347
|
-
*/
|
|
348
|
-
async enableModel(provider, modelId) {
|
|
349
|
-
const state = await this.loadState();
|
|
350
|
-
if (!state.enabledModels[provider]) {
|
|
351
|
-
state.enabledModels[provider] = [];
|
|
352
|
-
}
|
|
353
|
-
if (!state.enabledModels[provider].includes(modelId)) {
|
|
354
|
-
state.enabledModels[provider].push(modelId);
|
|
355
|
-
}
|
|
356
|
-
await this.saveState(state);
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Disable a model for a provider
|
|
360
|
-
* @param provider - Provider name
|
|
361
|
-
* @param modelId - Model ID to disable
|
|
362
|
-
*/
|
|
363
|
-
async disableModel(provider, modelId) {
|
|
364
|
-
const state = await this.loadState();
|
|
365
|
-
if (state.enabledModels[provider]) {
|
|
366
|
-
state.enabledModels[provider] = state.enabledModels[provider].filter((id) => id !== modelId);
|
|
367
|
-
if (state.enabledModels[provider].length === 0) {
|
|
368
|
-
delete state.enabledModels[provider];
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
await this.saveState(state);
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Get enabled models for a provider
|
|
375
|
-
* @param provider - Provider name
|
|
376
|
-
* @returns Array of enabled model IDs
|
|
377
|
-
*/
|
|
378
|
-
async getEnabledModels(provider) {
|
|
379
|
-
const state = await this.loadState();
|
|
380
|
-
return state.enabledModels[provider] || [];
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Get all enabled models across all providers
|
|
384
|
-
* @returns Object mapping provider to array of model IDs
|
|
385
|
-
*/
|
|
386
|
-
async getAllEnabledModels() {
|
|
387
|
-
const state = await this.loadState();
|
|
388
|
-
return state.enabledModels;
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Set enabled models for a provider
|
|
392
|
-
* @param provider - Provider name
|
|
393
|
-
* @param modelIds - Array of model IDs to enable
|
|
394
|
-
*/
|
|
395
|
-
async setEnabledModels(provider, modelIds) {
|
|
396
|
-
const state = await this.loadState();
|
|
397
|
-
if (modelIds.length === 0) {
|
|
398
|
-
delete state.enabledModels[provider];
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
state.enabledModels[provider] = modelIds;
|
|
402
|
-
}
|
|
403
|
-
await this.saveState(state);
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Set onboarding completed flag
|
|
407
|
-
* @param completed - Whether onboarding is completed
|
|
408
|
-
*/
|
|
409
|
-
async setOnboardingCompleted(completed) {
|
|
410
|
-
const state = await this.loadState();
|
|
411
|
-
state.onboardingCompleted = completed;
|
|
412
|
-
await this.saveState(state);
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Get onboarding completed flag
|
|
416
|
-
* @returns Whether onboarding has been completed
|
|
417
|
-
*/
|
|
418
|
-
async getOnboardingCompleted() {
|
|
419
|
-
const state = await this.loadState();
|
|
420
|
-
return state.onboardingCompleted;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
//# sourceMappingURL=metadata.manager.js.map
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AIHubMix model info and pricing
|
|
3
|
-
*
|
|
4
|
-
* Fetches model information (name, description, pricing) from the AIHubMix API.
|
|
5
|
-
* AIHubMix API: https://docs.aihubmix.com/api/models
|
|
6
|
-
*/
|
|
7
|
-
import type { ModelInfo } from "./model-info.js";
|
|
8
|
-
/**
|
|
9
|
-
* Fetch model info and pricing from AIHubMix API
|
|
10
|
-
*
|
|
11
|
-
* @param modelIds - List of model IDs to fetch info for
|
|
12
|
-
* @param apiKey - AIHubMix API key
|
|
13
|
-
* @returns Map of model ID -> ModelInfo (with pricing and metadata)
|
|
14
|
-
*/
|
|
15
|
-
export declare function getAIHubMixModelInfo(modelIds: string[], apiKey: string): Promise<Map<string, ModelInfo>>;
|
|
16
|
-
/**
|
|
17
|
-
* Fetch account credits/balance for AIHubMix using a user's API key.
|
|
18
|
-
* Returns remaining balance as (quota - used_quota) / 500000, matching UI units.
|
|
19
|
-
*/
|
|
20
|
-
export declare function getAIHubMixCredits(apiKey: string): Promise<{
|
|
21
|
-
balance: number | null;
|
|
22
|
-
status: string;
|
|
23
|
-
reason?: string;
|
|
24
|
-
}>;
|
|
25
|
-
//# sourceMappingURL=model-info-aihubmix.d.ts.map
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AIHubMix model info and pricing
|
|
3
|
-
*
|
|
4
|
-
* Fetches model information (name, description, pricing) from the AIHubMix API.
|
|
5
|
-
* AIHubMix API: https://docs.aihubmix.com/api/models
|
|
6
|
-
*/
|
|
7
|
-
const AIHUBMIX_MODELS_URL = "https://aihubmix.com/api/v1/models";
|
|
8
|
-
/**
|
|
9
|
-
* Parse AIHubMix price to per-token USD.
|
|
10
|
-
* AIHubMix returns prices in USD per 1,000,000 tokens (per-million). Convert
|
|
11
|
-
* to USD per single token for internal `ModelInfoPricing` which stores cost
|
|
12
|
-
* per token.
|
|
13
|
-
*/
|
|
14
|
-
function parsePrice(value) {
|
|
15
|
-
let n = 0;
|
|
16
|
-
if (typeof value === "number" && !Number.isNaN(value)) {
|
|
17
|
-
n = value;
|
|
18
|
-
}
|
|
19
|
-
else if (typeof value === "string") {
|
|
20
|
-
const parsed = Number.parseFloat(value);
|
|
21
|
-
if (!Number.isNaN(parsed))
|
|
22
|
-
n = parsed;
|
|
23
|
-
}
|
|
24
|
-
if (n === 0)
|
|
25
|
-
return 0;
|
|
26
|
-
// Convert from USD per 1,000,000 tokens to USD per 1 token
|
|
27
|
-
return n / 1_000_000;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Fetch model info and pricing from AIHubMix API
|
|
31
|
-
*
|
|
32
|
-
* @param modelIds - List of model IDs to fetch info for
|
|
33
|
-
* @param apiKey - AIHubMix API key
|
|
34
|
-
* @returns Map of model ID -> ModelInfo (with pricing and metadata)
|
|
35
|
-
*/
|
|
36
|
-
export async function getAIHubMixModelInfo(modelIds, apiKey) {
|
|
37
|
-
const result = new Map();
|
|
38
|
-
const emptyInfo = () => ({});
|
|
39
|
-
try {
|
|
40
|
-
const response = await fetch(AIHUBMIX_MODELS_URL, {
|
|
41
|
-
method: "GET",
|
|
42
|
-
headers: {
|
|
43
|
-
Authorization: `Bearer ${apiKey}`,
|
|
44
|
-
"Content-Type": "application/json",
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
if (!response.ok) {
|
|
48
|
-
// Pricing unknown when API call fails; still return entries for all IDs
|
|
49
|
-
for (const id of modelIds) {
|
|
50
|
-
result.set(id, emptyInfo());
|
|
51
|
-
}
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
const body = (await response.json());
|
|
55
|
-
const models = body.data ?? [];
|
|
56
|
-
const byId = new Map();
|
|
57
|
-
for (const m of models) {
|
|
58
|
-
if (m.model_id)
|
|
59
|
-
byId.set(m.model_id, m);
|
|
60
|
-
}
|
|
61
|
-
for (const id of modelIds) {
|
|
62
|
-
const remote = byId.get(id);
|
|
63
|
-
const hasPricing = Boolean(remote?.pricing) &&
|
|
64
|
-
(remote?.pricing?.input !== undefined || remote?.pricing?.output !== undefined);
|
|
65
|
-
const pricing = hasPricing
|
|
66
|
-
? {
|
|
67
|
-
prompt: parsePrice(remote?.pricing?.input),
|
|
68
|
-
completion: parsePrice(remote?.pricing?.output),
|
|
69
|
-
}
|
|
70
|
-
: undefined;
|
|
71
|
-
// Check if model supports function calling/tools
|
|
72
|
-
const hasTools = typeof remote?.features === "string" &&
|
|
73
|
-
(remote.features.includes("function_calling") || remote.features.includes("tools"));
|
|
74
|
-
result.set(id, {
|
|
75
|
-
pricing,
|
|
76
|
-
name: remote?.model_id,
|
|
77
|
-
description: remote?.desc,
|
|
78
|
-
supportedParameters: hasTools ? { tools: true } : undefined,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
console.error("[AIHubMix Models API] Error fetching models:", error);
|
|
84
|
-
for (const id of modelIds) {
|
|
85
|
-
result.set(id, emptyInfo());
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Fetch account credits/balance for AIHubMix using a user's API key.
|
|
92
|
-
* Returns remaining balance as (quota - used_quota) / 500000, matching UI units.
|
|
93
|
-
*/
|
|
94
|
-
export async function getAIHubMixCredits(apiKey) {
|
|
95
|
-
try {
|
|
96
|
-
const response = await fetch("https://aihubmix.com/api/user/self", {
|
|
97
|
-
headers: {
|
|
98
|
-
Authorization: `Bearer ${apiKey}`,
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
if (!response.ok) {
|
|
102
|
-
return { balance: null, status: "unknown", reason: `API error: ${response.status}` };
|
|
103
|
-
}
|
|
104
|
-
const body = (await response.json());
|
|
105
|
-
const quota = Number(body.data?.quota ?? NaN);
|
|
106
|
-
const used = Number(body.data?.used_quota ?? NaN);
|
|
107
|
-
if (Number.isNaN(quota) || Number.isNaN(used)) {
|
|
108
|
-
return { balance: null, status: "unknown" };
|
|
109
|
-
}
|
|
110
|
-
const remaining = (quota - used) / 500000;
|
|
111
|
-
return { balance: remaining, status: "success" };
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
return { balance: null, status: "unknown", reason: String(error) };
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=model-info-aihubmix.js.map
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenRouter model info and pricing
|
|
3
|
-
*
|
|
4
|
-
* Fetches model information (name, description, pricing) from the OpenRouter API.
|
|
5
|
-
* OpenRouter API: https://openrouter.ai/docs/api/api-reference/models/get-models
|
|
6
|
-
*/
|
|
7
|
-
import type { ModelInfo } from "./model-info.js";
|
|
8
|
-
/**
|
|
9
|
-
* Fetch model info and pricing from OpenRouter API
|
|
10
|
-
*
|
|
11
|
-
* @param modelIds - List of model IDs to fetch info for
|
|
12
|
-
* @param apiKey - OpenRouter API key
|
|
13
|
-
* @returns Map of model ID -> ModelInfo (with pricing and metadata)
|
|
14
|
-
*/
|
|
15
|
-
export declare function getOpenRouterModelInfo(modelIds: string[], apiKey: string): Promise<Map<string, ModelInfo>>;
|
|
16
|
-
/**
|
|
17
|
-
* Fetch account credits/balance for OpenRouter using a user's API key.
|
|
18
|
-
* Returns remaining balance as total_credits - total_usage (OpenRouter returns credits as a numeric unit).
|
|
19
|
-
*/
|
|
20
|
-
export declare function getOpenRouterCredits(apiKey: string): Promise<{
|
|
21
|
-
balance: number | null;
|
|
22
|
-
status: string;
|
|
23
|
-
reason?: string;
|
|
24
|
-
}>;
|
|
25
|
-
//# sourceMappingURL=model-info-openrouter.d.ts.map
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenRouter model info and pricing
|
|
3
|
-
*
|
|
4
|
-
* Fetches model information (name, description, pricing) from the OpenRouter API.
|
|
5
|
-
* OpenRouter API: https://openrouter.ai/docs/api/api-reference/models/get-models
|
|
6
|
-
*/
|
|
7
|
-
const OPENROUTER_MODELS_URL = "https://openrouter.ai/api/v1/models";
|
|
8
|
-
/** Parse OpenRouter price string (per-token USD) to number */
|
|
9
|
-
function parsePrice(value) {
|
|
10
|
-
if (typeof value === "number" && !Number.isNaN(value))
|
|
11
|
-
return value;
|
|
12
|
-
if (typeof value === "string") {
|
|
13
|
-
const n = Number.parseFloat(value);
|
|
14
|
-
return Number.isNaN(n) ? 0 : n;
|
|
15
|
-
}
|
|
16
|
-
return 0;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Fetch model info and pricing from OpenRouter API
|
|
20
|
-
*
|
|
21
|
-
* @param modelIds - List of model IDs to fetch info for
|
|
22
|
-
* @param apiKey - OpenRouter API key
|
|
23
|
-
* @returns Map of model ID -> ModelInfo (with pricing and metadata)
|
|
24
|
-
*/
|
|
25
|
-
export async function getOpenRouterModelInfo(modelIds, apiKey) {
|
|
26
|
-
const result = new Map();
|
|
27
|
-
const emptyInfo = () => ({});
|
|
28
|
-
try {
|
|
29
|
-
const response = await fetch(OPENROUTER_MODELS_URL, {
|
|
30
|
-
method: "GET",
|
|
31
|
-
headers: {
|
|
32
|
-
Authorization: `Bearer ${apiKey}`,
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
if (!response.ok) {
|
|
36
|
-
// Pricing unknown when API call fails; still return entries for all IDs
|
|
37
|
-
for (const id of modelIds) {
|
|
38
|
-
result.set(id, emptyInfo());
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
const body = (await response.json());
|
|
43
|
-
const models = body.data ?? [];
|
|
44
|
-
const byId = new Map();
|
|
45
|
-
for (const m of models) {
|
|
46
|
-
if (m.id)
|
|
47
|
-
byId.set(m.id, m);
|
|
48
|
-
}
|
|
49
|
-
for (const id of modelIds) {
|
|
50
|
-
const remote = byId.get(id);
|
|
51
|
-
const hasPricing = Boolean(remote?.pricing) &&
|
|
52
|
-
(remote?.pricing?.prompt !== undefined || remote?.pricing?.completion !== undefined);
|
|
53
|
-
const pricing = hasPricing
|
|
54
|
-
? {
|
|
55
|
-
prompt: parsePrice(remote?.pricing?.prompt),
|
|
56
|
-
completion: parsePrice(remote?.pricing?.completion),
|
|
57
|
-
}
|
|
58
|
-
: undefined;
|
|
59
|
-
const hasTools = Array.isArray(remote?.supported_parameters) &&
|
|
60
|
-
remote.supported_parameters.includes("tools");
|
|
61
|
-
result.set(id, {
|
|
62
|
-
pricing,
|
|
63
|
-
name: remote?.name,
|
|
64
|
-
description: remote?.description,
|
|
65
|
-
supportedParameters: hasTools ? { tools: true } : undefined,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
console.error("[OpenRouter Models API] Error fetching models:", error);
|
|
71
|
-
for (const id of modelIds) {
|
|
72
|
-
result.set(id, emptyInfo());
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Fetch account credits/balance for OpenRouter using a user's API key.
|
|
79
|
-
* Returns remaining balance as total_credits - total_usage (OpenRouter returns credits as a numeric unit).
|
|
80
|
-
*/
|
|
81
|
-
export async function getOpenRouterCredits(apiKey) {
|
|
82
|
-
try {
|
|
83
|
-
const response = await fetch("https://openrouter.ai/api/v1/credits", {
|
|
84
|
-
headers: {
|
|
85
|
-
Authorization: `Bearer ${apiKey}`,
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
if (!response.ok) {
|
|
89
|
-
return { balance: null, status: "unknown", reason: `API error: ${response.status}` };
|
|
90
|
-
}
|
|
91
|
-
const data = (await response.json());
|
|
92
|
-
const totalCredits = data.data?.total_credits ?? 0;
|
|
93
|
-
const totalUsage = data.data?.total_usage ?? 0;
|
|
94
|
-
const remainingBalance = totalCredits - totalUsage;
|
|
95
|
-
return {
|
|
96
|
-
balance: data.data ? remainingBalance : null,
|
|
97
|
-
status: data.data ? "success" : "unknown",
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
return { balance: null, status: "unknown", reason: String(error) };
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
//# sourceMappingURL=model-info-openrouter.js.map
|