@defai.digital/ax-cli 4.4.6 → 4.4.10
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/bin/ax-cli +1 -5
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +158 -9
- package/dist/index.js.map +1 -1
- package/dist/setup.d.ts +27 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +591 -0
- package/dist/setup.js.map +1 -0
- package/package.json +43 -135
- package/LICENSE +0 -22
- package/README.md +0 -387
- package/config-defaults/messages.yaml +0 -75
- package/config-defaults/models.yaml +0 -57
- package/config-defaults/prompts.yaml +0 -948
- package/config-defaults/settings.yaml +0 -157
- package/dist/agent/agent-executor.d.ts +0 -61
- package/dist/agent/agent-executor.js +0 -194
- package/dist/agent/agent-executor.js.map +0 -1
- package/dist/agent/agent-router.d.ts +0 -68
- package/dist/agent/agent-router.js +0 -242
- package/dist/agent/agent-router.js.map +0 -1
- package/dist/agent/context-manager.d.ts +0 -122
- package/dist/agent/context-manager.js +0 -406
- package/dist/agent/context-manager.js.map +0 -1
- package/dist/agent/core/index.d.ts +0 -8
- package/dist/agent/core/index.js +0 -9
- package/dist/agent/core/index.js.map +0 -1
- package/dist/agent/core/types.d.ts +0 -92
- package/dist/agent/core/types.js +0 -11
- package/dist/agent/core/types.js.map +0 -1
- package/dist/agent/dependency-resolver.d.ts +0 -90
- package/dist/agent/dependency-resolver.js +0 -366
- package/dist/agent/dependency-resolver.js.map +0 -1
- package/dist/agent/execution/index.d.ts +0 -9
- package/dist/agent/execution/index.js +0 -9
- package/dist/agent/execution/index.js.map +0 -1
- package/dist/agent/execution/tool-executor.d.ts +0 -93
- package/dist/agent/execution/tool-executor.js +0 -552
- package/dist/agent/execution/tool-executor.js.map +0 -1
- package/dist/agent/index.d.ts +0 -14
- package/dist/agent/index.js +0 -145
- package/dist/agent/index.js.map +0 -1
- package/dist/agent/llm-agent.d.ts +0 -368
- package/dist/agent/llm-agent.js +0 -1931
- package/dist/agent/llm-agent.js.map +0 -1
- package/dist/agent/loop-detector.d.ts +0 -72
- package/dist/agent/loop-detector.js +0 -335
- package/dist/agent/loop-detector.js.map +0 -1
- package/dist/agent/parallel-tools.d.ts +0 -69
- package/dist/agent/parallel-tools.js +0 -188
- package/dist/agent/parallel-tools.js.map +0 -1
- package/dist/agent/planning/index.d.ts +0 -9
- package/dist/agent/planning/index.js +0 -9
- package/dist/agent/planning/index.js.map +0 -1
- package/dist/agent/planning/plan-executor.d.ts +0 -79
- package/dist/agent/planning/plan-executor.js +0 -240
- package/dist/agent/planning/plan-executor.js.map +0 -1
- package/dist/agent/progress-tracker.d.ts +0 -94
- package/dist/agent/progress-tracker.js +0 -225
- package/dist/agent/progress-tracker.js.map +0 -1
- package/dist/agent/specialized/analysis-agent.d.ts +0 -11
- package/dist/agent/specialized/analysis-agent.js +0 -24
- package/dist/agent/specialized/analysis-agent.js.map +0 -1
- package/dist/agent/specialized/debug-agent.d.ts +0 -11
- package/dist/agent/specialized/debug-agent.js +0 -46
- package/dist/agent/specialized/debug-agent.js.map +0 -1
- package/dist/agent/specialized/documentation-agent.d.ts +0 -11
- package/dist/agent/specialized/documentation-agent.js +0 -24
- package/dist/agent/specialized/documentation-agent.js.map +0 -1
- package/dist/agent/specialized/index.d.ts +0 -11
- package/dist/agent/specialized/index.js +0 -12
- package/dist/agent/specialized/index.js.map +0 -1
- package/dist/agent/specialized/performance-agent.d.ts +0 -11
- package/dist/agent/specialized/performance-agent.js +0 -24
- package/dist/agent/specialized/performance-agent.js.map +0 -1
- package/dist/agent/specialized/refactoring-agent.d.ts +0 -11
- package/dist/agent/specialized/refactoring-agent.js +0 -24
- package/dist/agent/specialized/refactoring-agent.js.map +0 -1
- package/dist/agent/specialized/testing-agent.d.ts +0 -11
- package/dist/agent/specialized/testing-agent.js +0 -24
- package/dist/agent/specialized/testing-agent.js.map +0 -1
- package/dist/agent/status-reporter.d.ts +0 -114
- package/dist/agent/status-reporter.js +0 -335
- package/dist/agent/status-reporter.js.map +0 -1
- package/dist/agent/streaming/index.d.ts +0 -9
- package/dist/agent/streaming/index.js +0 -9
- package/dist/agent/streaming/index.js.map +0 -1
- package/dist/agent/streaming/stream-handler.d.ts +0 -62
- package/dist/agent/streaming/stream-handler.js +0 -217
- package/dist/agent/streaming/stream-handler.js.map +0 -1
- package/dist/agent/subagent-orchestrator.d.ts +0 -166
- package/dist/agent/subagent-orchestrator.js +0 -487
- package/dist/agent/subagent-orchestrator.js.map +0 -1
- package/dist/agent/subagent-types.d.ts +0 -261
- package/dist/agent/subagent-types.js +0 -257
- package/dist/agent/subagent-types.js.map +0 -1
- package/dist/agent/subagent.d.ts +0 -116
- package/dist/agent/subagent.js +0 -507
- package/dist/agent/subagent.js.map +0 -1
- package/dist/checkpoint/index.d.ts +0 -9
- package/dist/checkpoint/index.js +0 -11
- package/dist/checkpoint/index.js.map +0 -1
- package/dist/checkpoint/manager.d.ts +0 -101
- package/dist/checkpoint/manager.js +0 -407
- package/dist/checkpoint/manager.js.map +0 -1
- package/dist/checkpoint/storage.d.ts +0 -39
- package/dist/checkpoint/storage.js +0 -350
- package/dist/checkpoint/storage.js.map +0 -1
- package/dist/checkpoint/types.d.ts +0 -111
- package/dist/checkpoint/types.js +0 -17
- package/dist/checkpoint/types.js.map +0 -1
- package/dist/commands/cache.d.ts +0 -7
- package/dist/commands/cache.js +0 -284
- package/dist/commands/cache.js.map +0 -1
- package/dist/commands/custom-commands.d.ts +0 -77
- package/dist/commands/custom-commands.js +0 -251
- package/dist/commands/custom-commands.js.map +0 -1
- package/dist/commands/design.d.ts +0 -18
- package/dist/commands/design.js +0 -511
- package/dist/commands/design.js.map +0 -1
- package/dist/commands/doctor.d.ts +0 -6
- package/dist/commands/doctor.js +0 -773
- package/dist/commands/doctor.js.map +0 -1
- package/dist/commands/frontend.d.ts +0 -9
- package/dist/commands/frontend.js +0 -645
- package/dist/commands/frontend.js.map +0 -1
- package/dist/commands/init/wizard.d.ts +0 -55
- package/dist/commands/init/wizard.js +0 -189
- package/dist/commands/init/wizard.js.map +0 -1
- package/dist/commands/init.d.ts +0 -8
- package/dist/commands/init.js +0 -195
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/mcp-migrate.d.ts +0 -9
- package/dist/commands/mcp-migrate.js +0 -175
- package/dist/commands/mcp-migrate.js.map +0 -1
- package/dist/commands/mcp.d.ts +0 -2
- package/dist/commands/mcp.js +0 -1292
- package/dist/commands/mcp.js.map +0 -1
- package/dist/commands/memory.d.ts +0 -6
- package/dist/commands/memory.js +0 -555
- package/dist/commands/memory.js.map +0 -1
- package/dist/commands/models.d.ts +0 -5
- package/dist/commands/models.js +0 -213
- package/dist/commands/models.js.map +0 -1
- package/dist/commands/plan.d.ts +0 -43
- package/dist/commands/plan.js +0 -362
- package/dist/commands/plan.js.map +0 -1
- package/dist/commands/rewind.d.ts +0 -19
- package/dist/commands/rewind.js +0 -221
- package/dist/commands/rewind.js.map +0 -1
- package/dist/commands/setup.d.ts +0 -14
- package/dist/commands/setup.js +0 -733
- package/dist/commands/setup.js.map +0 -1
- package/dist/commands/status.d.ts +0 -7
- package/dist/commands/status.js +0 -437
- package/dist/commands/status.js.map +0 -1
- package/dist/commands/templates.d.ts +0 -5
- package/dist/commands/templates.js +0 -245
- package/dist/commands/templates.js.map +0 -1
- package/dist/commands/update.d.ts +0 -49
- package/dist/commands/update.js +0 -366
- package/dist/commands/update.js.map +0 -1
- package/dist/commands/usage.d.ts +0 -8
- package/dist/commands/usage.js +0 -264
- package/dist/commands/usage.js.map +0 -1
- package/dist/commands/vscode.d.ts +0 -7
- package/dist/commands/vscode.js +0 -419
- package/dist/commands/vscode.js.map +0 -1
- package/dist/constants.d.ts +0 -236
- package/dist/constants.js +0 -288
- package/dist/constants.js.map +0 -1
- package/dist/design/figma-alias.d.ts +0 -170
- package/dist/design/figma-alias.js +0 -577
- package/dist/design/figma-alias.js.map +0 -1
- package/dist/design/figma-audit.d.ts +0 -40
- package/dist/design/figma-audit.js +0 -383
- package/dist/design/figma-audit.js.map +0 -1
- package/dist/design/figma-client.d.ts +0 -131
- package/dist/design/figma-client.js +0 -369
- package/dist/design/figma-client.js.map +0 -1
- package/dist/design/figma-map.d.ts +0 -29
- package/dist/design/figma-map.js +0 -346
- package/dist/design/figma-map.js.map +0 -1
- package/dist/design/figma-tokens.d.ts +0 -73
- package/dist/design/figma-tokens.js +0 -448
- package/dist/design/figma-tokens.js.map +0 -1
- package/dist/design/index.d.ts +0 -13
- package/dist/design/index.js +0 -20
- package/dist/design/index.js.map +0 -1
- package/dist/design/types.d.ts +0 -98
- package/dist/design/types.js +0 -9
- package/dist/design/types.js.map +0 -1
- package/dist/hooks/hook-runner.d.ts +0 -142
- package/dist/hooks/hook-runner.js +0 -436
- package/dist/hooks/hook-runner.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -9
- package/dist/hooks/index.js +0 -10
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/manager.d.ts +0 -84
- package/dist/hooks/manager.js +0 -348
- package/dist/hooks/manager.js.map +0 -1
- package/dist/hooks/types.d.ts +0 -134
- package/dist/hooks/types.js +0 -9
- package/dist/hooks/types.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/ipc/index.d.ts +0 -9
- package/dist/ipc/index.js +0 -10
- package/dist/ipc/index.js.map +0 -1
- package/dist/ipc/vscode-client.d.ts +0 -200
- package/dist/ipc/vscode-client.js +0 -495
- package/dist/ipc/vscode-client.js.map +0 -1
- package/dist/llm/client.d.ts +0 -205
- package/dist/llm/client.js +0 -735
- package/dist/llm/client.js.map +0 -1
- package/dist/llm/tools.d.ts +0 -102
- package/dist/llm/tools.js +0 -275
- package/dist/llm/tools.js.map +0 -1
- package/dist/llm/types.d.ts +0 -428
- package/dist/llm/types.js +0 -194
- package/dist/llm/types.js.map +0 -1
- package/dist/mcp/automatosx-auto-discovery.d.ts +0 -66
- package/dist/mcp/automatosx-auto-discovery.js +0 -169
- package/dist/mcp/automatosx-auto-discovery.js.map +0 -1
- package/dist/mcp/automatosx-loader.d.ts +0 -99
- package/dist/mcp/automatosx-loader.js +0 -250
- package/dist/mcp/automatosx-loader.js.map +0 -1
- package/dist/mcp/cancellation.d.ts +0 -182
- package/dist/mcp/cancellation.js +0 -275
- package/dist/mcp/cancellation.js.map +0 -1
- package/dist/mcp/client-v2.d.ts +0 -500
- package/dist/mcp/client-v2.js +0 -1433
- package/dist/mcp/client-v2.js.map +0 -1
- package/dist/mcp/client.d.ts +0 -170
- package/dist/mcp/client.js +0 -232
- package/dist/mcp/client.js.map +0 -1
- package/dist/mcp/config-detector.d.ts +0 -90
- package/dist/mcp/config-detector.js +0 -250
- package/dist/mcp/config-detector.js.map +0 -1
- package/dist/mcp/config-migrator.d.ts +0 -68
- package/dist/mcp/config-migrator.js +0 -291
- package/dist/mcp/config-migrator.js.map +0 -1
- package/dist/mcp/config.d.ts +0 -24
- package/dist/mcp/config.js +0 -273
- package/dist/mcp/config.js.map +0 -1
- package/dist/mcp/constants.d.ts +0 -66
- package/dist/mcp/constants.js +0 -85
- package/dist/mcp/constants.js.map +0 -1
- package/dist/mcp/content-length-transport.d.ts +0 -106
- package/dist/mcp/content-length-transport.js +0 -413
- package/dist/mcp/content-length-transport.js.map +0 -1
- package/dist/mcp/debug.d.ts +0 -211
- package/dist/mcp/debug.js +0 -404
- package/dist/mcp/debug.js.map +0 -1
- package/dist/mcp/error-formatter.d.ts +0 -40
- package/dist/mcp/error-formatter.js +0 -207
- package/dist/mcp/error-formatter.js.map +0 -1
- package/dist/mcp/error-remediation.d.ts +0 -45
- package/dist/mcp/error-remediation.js +0 -291
- package/dist/mcp/error-remediation.js.map +0 -1
- package/dist/mcp/health.d.ts +0 -120
- package/dist/mcp/health.js +0 -267
- package/dist/mcp/health.js.map +0 -1
- package/dist/mcp/index.d.ts +0 -56
- package/dist/mcp/index.js +0 -89
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/invariants.d.ts +0 -141
- package/dist/mcp/invariants.js +0 -243
- package/dist/mcp/invariants.js.map +0 -1
- package/dist/mcp/mutex-safe.d.ts +0 -151
- package/dist/mcp/mutex-safe.js +0 -260
- package/dist/mcp/mutex-safe.js.map +0 -1
- package/dist/mcp/progress.d.ts +0 -155
- package/dist/mcp/progress.js +0 -252
- package/dist/mcp/progress.js.map +0 -1
- package/dist/mcp/prompts.d.ts +0 -68
- package/dist/mcp/prompts.js +0 -129
- package/dist/mcp/prompts.js.map +0 -1
- package/dist/mcp/provider-mcp-loader.d.ts +0 -130
- package/dist/mcp/provider-mcp-loader.js +0 -292
- package/dist/mcp/provider-mcp-loader.js.map +0 -1
- package/dist/mcp/reconnection.d.ts +0 -101
- package/dist/mcp/reconnection.js +0 -253
- package/dist/mcp/reconnection.js.map +0 -1
- package/dist/mcp/registry.d.ts +0 -75
- package/dist/mcp/registry.js +0 -276
- package/dist/mcp/registry.js.map +0 -1
- package/dist/mcp/resources.d.ts +0 -58
- package/dist/mcp/resources.js +0 -144
- package/dist/mcp/resources.js.map +0 -1
- package/dist/mcp/schema-validator.d.ts +0 -82
- package/dist/mcp/schema-validator.js +0 -161
- package/dist/mcp/schema-validator.js.map +0 -1
- package/dist/mcp/ssrf-protection.d.ts +0 -86
- package/dist/mcp/ssrf-protection.js +0 -311
- package/dist/mcp/ssrf-protection.js.map +0 -1
- package/dist/mcp/subscriptions.d.ts +0 -168
- package/dist/mcp/subscriptions.js +0 -248
- package/dist/mcp/subscriptions.js.map +0 -1
- package/dist/mcp/templates.d.ts +0 -52
- package/dist/mcp/templates.js +0 -627
- package/dist/mcp/templates.js.map +0 -1
- package/dist/mcp/transports.d.ts +0 -80
- package/dist/mcp/transports.js +0 -237
- package/dist/mcp/transports.js.map +0 -1
- package/dist/mcp/type-safety.d.ts +0 -225
- package/dist/mcp/type-safety.js +0 -237
- package/dist/mcp/type-safety.js.map +0 -1
- package/dist/mcp/validation.d.ts +0 -29
- package/dist/mcp/validation.js +0 -339
- package/dist/mcp/validation.js.map +0 -1
- package/dist/mcp/zai-detector.d.ts +0 -63
- package/dist/mcp/zai-detector.js +0 -193
- package/dist/mcp/zai-detector.js.map +0 -1
- package/dist/mcp/zai-templates.d.ts +0 -90
- package/dist/mcp/zai-templates.js +0 -157
- package/dist/mcp/zai-templates.js.map +0 -1
- package/dist/memory/context-generator.d.ts +0 -84
- package/dist/memory/context-generator.js +0 -546
- package/dist/memory/context-generator.js.map +0 -1
- package/dist/memory/context-injector.d.ts +0 -97
- package/dist/memory/context-injector.js +0 -159
- package/dist/memory/context-injector.js.map +0 -1
- package/dist/memory/context-store.d.ts +0 -103
- package/dist/memory/context-store.js +0 -264
- package/dist/memory/context-store.js.map +0 -1
- package/dist/memory/index.d.ts +0 -43
- package/dist/memory/index.js +0 -49
- package/dist/memory/index.js.map +0 -1
- package/dist/memory/provider-context-store.d.ts +0 -127
- package/dist/memory/provider-context-store.js +0 -385
- package/dist/memory/provider-context-store.js.map +0 -1
- package/dist/memory/schemas.d.ts +0 -118
- package/dist/memory/schemas.js +0 -106
- package/dist/memory/schemas.js.map +0 -1
- package/dist/memory/stats-collector.d.ts +0 -73
- package/dist/memory/stats-collector.js +0 -170
- package/dist/memory/stats-collector.js.map +0 -1
- package/dist/memory/types.d.ts +0 -177
- package/dist/memory/types.js +0 -73
- package/dist/memory/types.js.map +0 -1
- package/dist/permissions/index.d.ts +0 -6
- package/dist/permissions/index.js +0 -7
- package/dist/permissions/index.js.map +0 -1
- package/dist/permissions/permission-manager.d.ts +0 -149
- package/dist/permissions/permission-manager.js +0 -410
- package/dist/permissions/permission-manager.js.map +0 -1
- package/dist/planner/dependency-resolver.d.ts +0 -72
- package/dist/planner/dependency-resolver.js +0 -272
- package/dist/planner/dependency-resolver.js.map +0 -1
- package/dist/planner/index.d.ts +0 -12
- package/dist/planner/index.js +0 -28
- package/dist/planner/index.js.map +0 -1
- package/dist/planner/plan-generator.d.ts +0 -74
- package/dist/planner/plan-generator.js +0 -244
- package/dist/planner/plan-generator.js.map +0 -1
- package/dist/planner/plan-storage.d.ts +0 -113
- package/dist/planner/plan-storage.js +0 -398
- package/dist/planner/plan-storage.js.map +0 -1
- package/dist/planner/prompts/planning-prompt.d.ts +0 -62
- package/dist/planner/prompts/planning-prompt.js +0 -414
- package/dist/planner/prompts/planning-prompt.js.map +0 -1
- package/dist/planner/task-planner.d.ts +0 -139
- package/dist/planner/task-planner.js +0 -532
- package/dist/planner/task-planner.js.map +0 -1
- package/dist/planner/token-estimator.d.ts +0 -63
- package/dist/planner/token-estimator.js +0 -295
- package/dist/planner/token-estimator.js.map +0 -1
- package/dist/planner/types.d.ts +0 -425
- package/dist/planner/types.js +0 -213
- package/dist/planner/types.js.map +0 -1
- package/dist/provider/config.d.ts +0 -227
- package/dist/provider/config.js +0 -430
- package/dist/provider/config.js.map +0 -1
- package/dist/schemas/api-schemas.d.ts +0 -45
- package/dist/schemas/api-schemas.js +0 -129
- package/dist/schemas/api-schemas.js.map +0 -1
- package/dist/schemas/confirmation-schemas.d.ts +0 -39
- package/dist/schemas/confirmation-schemas.js +0 -48
- package/dist/schemas/confirmation-schemas.js.map +0 -1
- package/dist/schemas/index-unified.d.ts +0 -12
- package/dist/schemas/index-unified.js +0 -17
- package/dist/schemas/index-unified.js.map +0 -1
- package/dist/schemas/index.d.ts +0 -83
- package/dist/schemas/index.js +0 -139
- package/dist/schemas/index.js.map +0 -1
- package/dist/schemas/settings-schemas.d.ts +0 -186
- package/dist/schemas/settings-schemas.js +0 -324
- package/dist/schemas/settings-schemas.js.map +0 -1
- package/dist/schemas/tool-schemas.d.ts +0 -127
- package/dist/schemas/tool-schemas.js +0 -84
- package/dist/schemas/tool-schemas.js.map +0 -1
- package/dist/schemas/yaml-schemas.d.ts +0 -231
- package/dist/schemas/yaml-schemas.js +0 -199
- package/dist/schemas/yaml-schemas.js.map +0 -1
- package/dist/sdk/errors.d.ts +0 -100
- package/dist/sdk/errors.js +0 -138
- package/dist/sdk/errors.js.map +0 -1
- package/dist/sdk/index.d.ts +0 -901
- package/dist/sdk/index.js +0 -1272
- package/dist/sdk/index.js.map +0 -1
- package/dist/sdk/progress-reporter.d.ts +0 -123
- package/dist/sdk/progress-reporter.js +0 -220
- package/dist/sdk/progress-reporter.js.map +0 -1
- package/dist/sdk/testing.d.ts +0 -427
- package/dist/sdk/testing.js +0 -725
- package/dist/sdk/testing.js.map +0 -1
- package/dist/sdk/tool-registry.d.ts +0 -194
- package/dist/sdk/tool-registry.js +0 -326
- package/dist/sdk/tool-registry.js.map +0 -1
- package/dist/sdk/types.d.ts +0 -53
- package/dist/sdk/types.js +0 -8
- package/dist/sdk/types.js.map +0 -1
- package/dist/sdk/unified-logger.d.ts +0 -173
- package/dist/sdk/unified-logger.js +0 -327
- package/dist/sdk/unified-logger.js.map +0 -1
- package/dist/sdk/version.d.ts +0 -163
- package/dist/sdk/version.js +0 -205
- package/dist/sdk/version.js.map +0 -1
- package/dist/tools/ask-user.d.ts +0 -126
- package/dist/tools/ask-user.js +0 -290
- package/dist/tools/ask-user.js.map +0 -1
- package/dist/tools/ax-agent.d.ts +0 -71
- package/dist/tools/ax-agent.js +0 -283
- package/dist/tools/ax-agent.js.map +0 -1
- package/dist/tools/bash-output.d.ts +0 -25
- package/dist/tools/bash-output.js +0 -146
- package/dist/tools/bash-output.js.map +0 -1
- package/dist/tools/bash.d.ts +0 -67
- package/dist/tools/bash.js +0 -522
- package/dist/tools/bash.js.map +0 -1
- package/dist/tools/confirmation-tool.d.ts +0 -16
- package/dist/tools/confirmation-tool.js +0 -76
- package/dist/tools/confirmation-tool.js.map +0 -1
- package/dist/tools/definitions/ask-user.d.ts +0 -8
- package/dist/tools/definitions/ask-user.js +0 -168
- package/dist/tools/definitions/ask-user.js.map +0 -1
- package/dist/tools/definitions/ax-agent.d.ts +0 -8
- package/dist/tools/definitions/ax-agent.js +0 -276
- package/dist/tools/definitions/ax-agent.js.map +0 -1
- package/dist/tools/definitions/bash-output.d.ts +0 -7
- package/dist/tools/definitions/bash-output.js +0 -78
- package/dist/tools/definitions/bash-output.js.map +0 -1
- package/dist/tools/definitions/bash.d.ts +0 -8
- package/dist/tools/definitions/bash.js +0 -152
- package/dist/tools/definitions/bash.js.map +0 -1
- package/dist/tools/definitions/create-file.d.ts +0 -7
- package/dist/tools/definitions/create-file.js +0 -129
- package/dist/tools/definitions/create-file.js.map +0 -1
- package/dist/tools/definitions/design.d.ts +0 -12
- package/dist/tools/definitions/design.js +0 -368
- package/dist/tools/definitions/design.js.map +0 -1
- package/dist/tools/definitions/index.d.ts +0 -49
- package/dist/tools/definitions/index.js +0 -87
- package/dist/tools/definitions/index.js.map +0 -1
- package/dist/tools/definitions/multi-edit.d.ts +0 -7
- package/dist/tools/definitions/multi-edit.js +0 -123
- package/dist/tools/definitions/multi-edit.js.map +0 -1
- package/dist/tools/definitions/search.d.ts +0 -7
- package/dist/tools/definitions/search.js +0 -159
- package/dist/tools/definitions/search.js.map +0 -1
- package/dist/tools/definitions/str-replace-editor.d.ts +0 -7
- package/dist/tools/definitions/str-replace-editor.js +0 -145
- package/dist/tools/definitions/str-replace-editor.js.map +0 -1
- package/dist/tools/definitions/todo.d.ts +0 -8
- package/dist/tools/definitions/todo.js +0 -261
- package/dist/tools/definitions/todo.js.map +0 -1
- package/dist/tools/definitions/view-file.d.ts +0 -7
- package/dist/tools/definitions/view-file.js +0 -111
- package/dist/tools/definitions/view-file.js.map +0 -1
- package/dist/tools/design-tool.d.ts +0 -68
- package/dist/tools/design-tool.js +0 -299
- package/dist/tools/design-tool.js.map +0 -1
- package/dist/tools/format-generators.d.ts +0 -62
- package/dist/tools/format-generators.js +0 -291
- package/dist/tools/format-generators.js.map +0 -1
- package/dist/tools/index.d.ts +0 -8
- package/dist/tools/index.js +0 -11
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/priority-registry.d.ts +0 -124
- package/dist/tools/priority-registry.js +0 -401
- package/dist/tools/priority-registry.js.map +0 -1
- package/dist/tools/priority.d.ts +0 -158
- package/dist/tools/priority.js +0 -350
- package/dist/tools/priority.js.map +0 -1
- package/dist/tools/registry.d.ts +0 -146
- package/dist/tools/registry.js +0 -171
- package/dist/tools/registry.js.map +0 -1
- package/dist/tools/search.d.ts +0 -85
- package/dist/tools/search.js +0 -430
- package/dist/tools/search.js.map +0 -1
- package/dist/tools/text-editor.d.ts +0 -87
- package/dist/tools/text-editor.js +0 -1369
- package/dist/tools/text-editor.js.map +0 -1
- package/dist/tools/todo-tool.d.ts +0 -20
- package/dist/tools/todo-tool.js +0 -186
- package/dist/tools/todo-tool.js.map +0 -1
- package/dist/tools/types.d.ts +0 -175
- package/dist/tools/types.js +0 -11
- package/dist/tools/types.js.map +0 -1
- package/dist/types/index.d.ts +0 -30
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/dist/types/project-analysis.d.ts +0 -84
- package/dist/types/project-analysis.js +0 -5
- package/dist/types/project-analysis.js.map +0 -1
- package/dist/types/template.d.ts +0 -53
- package/dist/types/template.js +0 -5
- package/dist/types/template.js.map +0 -1
- package/dist/ui/app.d.ts +0 -7
- package/dist/ui/app.js +0 -102
- package/dist/ui/app.js.map +0 -1
- package/dist/ui/components/api-key-input.d.ts +0 -7
- package/dist/ui/components/api-key-input.js +0 -92
- package/dist/ui/components/api-key-input.js.map +0 -1
- package/dist/ui/components/chat-history.d.ts +0 -12
- package/dist/ui/components/chat-history.js +0 -391
- package/dist/ui/components/chat-history.js.map +0 -1
- package/dist/ui/components/chat-input.d.ts +0 -13
- package/dist/ui/components/chat-input.js +0 -179
- package/dist/ui/components/chat-input.js.map +0 -1
- package/dist/ui/components/chat-interface.d.ts +0 -11
- package/dist/ui/components/chat-interface.js +0 -830
- package/dist/ui/components/chat-interface.js.map +0 -1
- package/dist/ui/components/collapsible-tool-result.d.ts +0 -42
- package/dist/ui/components/collapsible-tool-result.js +0 -216
- package/dist/ui/components/collapsible-tool-result.js.map +0 -1
- package/dist/ui/components/command-suggestions.d.ts +0 -29
- package/dist/ui/components/command-suggestions.js +0 -88
- package/dist/ui/components/command-suggestions.js.map +0 -1
- package/dist/ui/components/confirmation-dialog.d.ts +0 -11
- package/dist/ui/components/confirmation-dialog.js +0 -100
- package/dist/ui/components/confirmation-dialog.js.map +0 -1
- package/dist/ui/components/context-breakdown.d.ts +0 -23
- package/dist/ui/components/context-breakdown.js +0 -124
- package/dist/ui/components/context-breakdown.js.map +0 -1
- package/dist/ui/components/diff-renderer.d.ts +0 -13
- package/dist/ui/components/diff-renderer.js +0 -192
- package/dist/ui/components/diff-renderer.js.map +0 -1
- package/dist/ui/components/index.d.ts +0 -18
- package/dist/ui/components/index.js +0 -20
- package/dist/ui/components/index.js.map +0 -1
- package/dist/ui/components/keyboard-help.d.ts +0 -17
- package/dist/ui/components/keyboard-help.js +0 -122
- package/dist/ui/components/keyboard-help.js.map +0 -1
- package/dist/ui/components/keyboard-hints.d.ts +0 -35
- package/dist/ui/components/keyboard-hints.js +0 -142
- package/dist/ui/components/keyboard-hints.js.map +0 -1
- package/dist/ui/components/loading-spinner.d.ts +0 -9
- package/dist/ui/components/loading-spinner.js +0 -120
- package/dist/ui/components/loading-spinner.js.map +0 -1
- package/dist/ui/components/mcp-dashboard.d.ts +0 -15
- package/dist/ui/components/mcp-dashboard.js +0 -520
- package/dist/ui/components/mcp-dashboard.js.map +0 -1
- package/dist/ui/components/mcp-status.d.ts +0 -5
- package/dist/ui/components/mcp-status.js +0 -58
- package/dist/ui/components/mcp-status.js.map +0 -1
- package/dist/ui/components/model-selection.d.ts +0 -12
- package/dist/ui/components/model-selection.js +0 -17
- package/dist/ui/components/model-selection.js.map +0 -1
- package/dist/ui/components/phase-progress.d.ts +0 -21
- package/dist/ui/components/phase-progress.js +0 -185
- package/dist/ui/components/phase-progress.js.map +0 -1
- package/dist/ui/components/question-dialog.d.ts +0 -17
- package/dist/ui/components/question-dialog.js +0 -181
- package/dist/ui/components/question-dialog.js.map +0 -1
- package/dist/ui/components/quick-actions.d.ts +0 -12
- package/dist/ui/components/quick-actions.js +0 -171
- package/dist/ui/components/quick-actions.js.map +0 -1
- package/dist/ui/components/reasoning-display.d.ts +0 -36
- package/dist/ui/components/reasoning-display.js +0 -46
- package/dist/ui/components/reasoning-display.js.map +0 -1
- package/dist/ui/components/status-bar.d.ts +0 -47
- package/dist/ui/components/status-bar.js +0 -310
- package/dist/ui/components/status-bar.js.map +0 -1
- package/dist/ui/components/subagent-monitor.d.ts +0 -41
- package/dist/ui/components/subagent-monitor.js +0 -122
- package/dist/ui/components/subagent-monitor.js.map +0 -1
- package/dist/ui/components/toast-notification.d.ts +0 -197
- package/dist/ui/components/toast-notification.js +0 -190
- package/dist/ui/components/toast-notification.js.map +0 -1
- package/dist/ui/components/tool-group-display.d.ts +0 -19
- package/dist/ui/components/tool-group-display.js +0 -222
- package/dist/ui/components/tool-group-display.js.map +0 -1
- package/dist/ui/components/virtualized-chat-history.d.ts +0 -33
- package/dist/ui/components/virtualized-chat-history.js +0 -182
- package/dist/ui/components/virtualized-chat-history.js.map +0 -1
- package/dist/ui/components/welcome-panel.d.ts +0 -11
- package/dist/ui/components/welcome-panel.js +0 -225
- package/dist/ui/components/welcome-panel.js.map +0 -1
- package/dist/ui/hooks/use-chat-reducer.d.ts +0 -69
- package/dist/ui/hooks/use-chat-reducer.js +0 -118
- package/dist/ui/hooks/use-chat-reducer.js.map +0 -1
- package/dist/ui/hooks/use-enhanced-input.d.ts +0 -53
- package/dist/ui/hooks/use-enhanced-input.js +0 -1275
- package/dist/ui/hooks/use-enhanced-input.js.map +0 -1
- package/dist/ui/hooks/use-input-handler.d.ts +0 -79
- package/dist/ui/hooks/use-input-handler.js +0 -2251
- package/dist/ui/hooks/use-input-handler.js.map +0 -1
- package/dist/ui/hooks/use-input-history.d.ts +0 -9
- package/dist/ui/hooks/use-input-history.js +0 -168
- package/dist/ui/hooks/use-input-history.js.map +0 -1
- package/dist/ui/shared/max-sized-box.d.ts +0 -17
- package/dist/ui/shared/max-sized-box.js +0 -14
- package/dist/ui/shared/max-sized-box.js.map +0 -1
- package/dist/ui/themes/index.d.ts +0 -5
- package/dist/ui/themes/index.js +0 -5
- package/dist/ui/themes/index.js.map +0 -1
- package/dist/ui/themes/theme-registry.d.ts +0 -55
- package/dist/ui/themes/theme-registry.js +0 -202
- package/dist/ui/themes/theme-registry.js.map +0 -1
- package/dist/ui/utils/bracketed-paste-handler.d.ts +0 -97
- package/dist/ui/utils/bracketed-paste-handler.js +0 -322
- package/dist/ui/utils/bracketed-paste-handler.js.map +0 -1
- package/dist/ui/utils/change-summarizer.d.ts +0 -20
- package/dist/ui/utils/change-summarizer.js +0 -282
- package/dist/ui/utils/change-summarizer.js.map +0 -1
- package/dist/ui/utils/code-colorizer.d.ts +0 -9
- package/dist/ui/utils/code-colorizer.js +0 -13
- package/dist/ui/utils/code-colorizer.js.map +0 -1
- package/dist/ui/utils/colors.d.ts +0 -41
- package/dist/ui/utils/colors.js +0 -80
- package/dist/ui/utils/colors.js.map +0 -1
- package/dist/ui/utils/image-handler.d.ts +0 -29
- package/dist/ui/utils/image-handler.js +0 -129
- package/dist/ui/utils/image-handler.js.map +0 -1
- package/dist/ui/utils/markdown-renderer.d.ts +0 -4
- package/dist/ui/utils/markdown-renderer.js +0 -40
- package/dist/ui/utils/markdown-renderer.js.map +0 -1
- package/dist/ui/utils/semantic-action-detector.d.ts +0 -49
- package/dist/ui/utils/semantic-action-detector.js +0 -339
- package/dist/ui/utils/semantic-action-detector.js.map +0 -1
- package/dist/ui/utils/tool-grouper.d.ts +0 -94
- package/dist/ui/utils/tool-grouper.js +0 -618
- package/dist/ui/utils/tool-grouper.js.map +0 -1
- package/dist/utils/api-error.d.ts +0 -61
- package/dist/utils/api-error.js +0 -176
- package/dist/utils/api-error.js.map +0 -1
- package/dist/utils/audit-logger.d.ts +0 -206
- package/dist/utils/audit-logger.js +0 -286
- package/dist/utils/audit-logger.js.map +0 -1
- package/dist/utils/auto-accept-logger.d.ts +0 -175
- package/dist/utils/auto-accept-logger.js +0 -423
- package/dist/utils/auto-accept-logger.js.map +0 -1
- package/dist/utils/automatosx-detector.d.ts +0 -19
- package/dist/utils/automatosx-detector.js +0 -52
- package/dist/utils/automatosx-detector.js.map +0 -1
- package/dist/utils/background-task-manager.d.ts +0 -114
- package/dist/utils/background-task-manager.js +0 -470
- package/dist/utils/background-task-manager.js.map +0 -1
- package/dist/utils/cache.d.ts +0 -77
- package/dist/utils/cache.js +0 -180
- package/dist/utils/cache.js.map +0 -1
- package/dist/utils/command-security.d.ts +0 -85
- package/dist/utils/command-security.js +0 -210
- package/dist/utils/command-security.js.map +0 -1
- package/dist/utils/config-loader.d.ts +0 -190
- package/dist/utils/config-loader.js +0 -108
- package/dist/utils/config-loader.js.map +0 -1
- package/dist/utils/confirmation-service.d.ts +0 -51
- package/dist/utils/confirmation-service.js +0 -220
- package/dist/utils/confirmation-service.js.map +0 -1
- package/dist/utils/console-messenger.d.ts +0 -80
- package/dist/utils/console-messenger.js +0 -142
- package/dist/utils/console-messenger.js.map +0 -1
- package/dist/utils/custom-instructions.d.ts +0 -1
- package/dist/utils/custom-instructions.js +0 -24
- package/dist/utils/custom-instructions.js.map +0 -1
- package/dist/utils/encryption.d.ts +0 -86
- package/dist/utils/encryption.js +0 -236
- package/dist/utils/encryption.js.map +0 -1
- package/dist/utils/enhanced-error-messages.d.ts +0 -33
- package/dist/utils/enhanced-error-messages.js +0 -440
- package/dist/utils/enhanced-error-messages.js.map +0 -1
- package/dist/utils/error-handler.d.ts +0 -65
- package/dist/utils/error-handler.js +0 -148
- package/dist/utils/error-handler.js.map +0 -1
- package/dist/utils/error-translator.d.ts +0 -25
- package/dist/utils/error-translator.js +0 -203
- package/dist/utils/error-translator.js.map +0 -1
- package/dist/utils/external-editor.d.ts +0 -47
- package/dist/utils/external-editor.js +0 -179
- package/dist/utils/external-editor.js.map +0 -1
- package/dist/utils/file-cache.d.ts +0 -148
- package/dist/utils/file-cache.js +0 -413
- package/dist/utils/file-cache.js.map +0 -1
- package/dist/utils/file-lock.d.ts +0 -141
- package/dist/utils/file-lock.js +0 -554
- package/dist/utils/file-lock.js.map +0 -1
- package/dist/utils/file-mentions.d.ts +0 -68
- package/dist/utils/file-mentions.js +0 -225
- package/dist/utils/file-mentions.js.map +0 -1
- package/dist/utils/history-manager.d.ts +0 -52
- package/dist/utils/history-manager.js +0 -211
- package/dist/utils/history-manager.js.map +0 -1
- package/dist/utils/history-migration.d.ts +0 -9
- package/dist/utils/history-migration.js +0 -37
- package/dist/utils/history-migration.js.map +0 -1
- package/dist/utils/image-processor.d.ts +0 -33
- package/dist/utils/image-processor.js +0 -124
- package/dist/utils/image-processor.js.map +0 -1
- package/dist/utils/index.d.ts +0 -92
- package/dist/utils/index.js +0 -111
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/init-previewer.d.ts +0 -56
- package/dist/utils/init-previewer.js +0 -239
- package/dist/utils/init-previewer.js.map +0 -1
- package/dist/utils/init-validator.d.ts +0 -65
- package/dist/utils/init-validator.js +0 -252
- package/dist/utils/init-validator.js.map +0 -1
- package/dist/utils/input-sanitizer.d.ts +0 -210
- package/dist/utils/input-sanitizer.js +0 -362
- package/dist/utils/input-sanitizer.js.map +0 -1
- package/dist/utils/instruction-generator.d.ts +0 -21
- package/dist/utils/instruction-generator.js +0 -233
- package/dist/utils/instruction-generator.js.map +0 -1
- package/dist/utils/json-utils.d.ts +0 -72
- package/dist/utils/json-utils.js +0 -226
- package/dist/utils/json-utils.js.map +0 -1
- package/dist/utils/llm-optimized-instruction-generator.d.ts +0 -36
- package/dist/utils/llm-optimized-instruction-generator.js +0 -365
- package/dist/utils/llm-optimized-instruction-generator.js.map +0 -1
- package/dist/utils/message-optimizer.d.ts +0 -100
- package/dist/utils/message-optimizer.js +0 -297
- package/dist/utils/message-optimizer.js.map +0 -1
- package/dist/utils/onboarding-manager.d.ts +0 -45
- package/dist/utils/onboarding-manager.js +0 -131
- package/dist/utils/onboarding-manager.js.map +0 -1
- package/dist/utils/parallel-analyzer.d.ts +0 -123
- package/dist/utils/parallel-analyzer.js +0 -241
- package/dist/utils/parallel-analyzer.js.map +0 -1
- package/dist/utils/paste-utils.d.ts +0 -99
- package/dist/utils/paste-utils.js +0 -295
- package/dist/utils/paste-utils.js.map +0 -1
- package/dist/utils/path-helpers.d.ts +0 -8
- package/dist/utils/path-helpers.js +0 -35
- package/dist/utils/path-helpers.js.map +0 -1
- package/dist/utils/path-security.d.ts +0 -92
- package/dist/utils/path-security.js +0 -300
- package/dist/utils/path-security.js.map +0 -1
- package/dist/utils/path-utils.d.ts +0 -83
- package/dist/utils/path-utils.js +0 -122
- package/dist/utils/path-utils.js.map +0 -1
- package/dist/utils/path-validator.d.ts +0 -66
- package/dist/utils/path-validator.js +0 -141
- package/dist/utils/path-validator.js.map +0 -1
- package/dist/utils/performance.d.ts +0 -74
- package/dist/utils/performance.js +0 -133
- package/dist/utils/performance.js.map +0 -1
- package/dist/utils/process-pool.d.ts +0 -109
- package/dist/utils/process-pool.js +0 -332
- package/dist/utils/process-pool.js.map +0 -1
- package/dist/utils/progress-tracker.d.ts +0 -51
- package/dist/utils/progress-tracker.js +0 -152
- package/dist/utils/progress-tracker.js.map +0 -1
- package/dist/utils/project-analyzer.d.ts +0 -49
- package/dist/utils/project-analyzer.js +0 -396
- package/dist/utils/project-analyzer.js.map +0 -1
- package/dist/utils/prompt-builder.d.ts +0 -14
- package/dist/utils/prompt-builder.js +0 -100
- package/dist/utils/prompt-builder.js.map +0 -1
- package/dist/utils/provider-context.d.ts +0 -243
- package/dist/utils/provider-context.js +0 -421
- package/dist/utils/provider-context.js.map +0 -1
- package/dist/utils/provider-file-cache.d.ts +0 -91
- package/dist/utils/provider-file-cache.js +0 -165
- package/dist/utils/provider-file-cache.js.map +0 -1
- package/dist/utils/provider-settings.d.ts +0 -181
- package/dist/utils/provider-settings.js +0 -450
- package/dist/utils/provider-settings.js.map +0 -1
- package/dist/utils/rate-limiter.d.ts +0 -222
- package/dist/utils/rate-limiter.js +0 -338
- package/dist/utils/rate-limiter.js.map +0 -1
- package/dist/utils/retry-helper.d.ts +0 -81
- package/dist/utils/retry-helper.js +0 -244
- package/dist/utils/retry-helper.js.map +0 -1
- package/dist/utils/safety-rules.d.ts +0 -64
- package/dist/utils/safety-rules.js +0 -225
- package/dist/utils/safety-rules.js.map +0 -1
- package/dist/utils/settings-manager.d.ts +0 -256
- package/dist/utils/settings-manager.js +0 -967
- package/dist/utils/settings-manager.js.map +0 -1
- package/dist/utils/setup-validator.d.ts +0 -47
- package/dist/utils/setup-validator.js +0 -304
- package/dist/utils/setup-validator.js.map +0 -1
- package/dist/utils/string-utils.d.ts +0 -19
- package/dist/utils/string-utils.js +0 -28
- package/dist/utils/string-utils.js.map +0 -1
- package/dist/utils/template-manager.d.ts +0 -62
- package/dist/utils/template-manager.js +0 -366
- package/dist/utils/template-manager.js.map +0 -1
- package/dist/utils/text-utils.d.ts +0 -82
- package/dist/utils/text-utils.js +0 -203
- package/dist/utils/text-utils.js.map +0 -1
- package/dist/utils/token-counter.d.ts +0 -76
- package/dist/utils/token-counter.js +0 -231
- package/dist/utils/token-counter.js.map +0 -1
- package/dist/utils/usage-tracker.d.ts +0 -78
- package/dist/utils/usage-tracker.js +0 -126
- package/dist/utils/usage-tracker.js.map +0 -1
- package/dist/utils/version.d.ts +0 -14
- package/dist/utils/version.js +0 -70
- package/dist/utils/version.js.map +0 -1
package/dist/llm/client.js
DELETED
|
@@ -1,735 +0,0 @@
|
|
|
1
|
-
import OpenAI from "openai";
|
|
2
|
-
import { safeValidateGrokResponse } from "../schemas/api-schemas.js";
|
|
3
|
-
import { ErrorCategory, createErrorMessage } from "../utils/error-handler.js";
|
|
4
|
-
import { extractAndTranslateError } from "../utils/error-translator.js";
|
|
5
|
-
import { GLM_MODELS, TIMEOUT_CONFIG } from "../constants.js";
|
|
6
|
-
import { GLM_PROVIDER, GROK_PROVIDER, resolveModelAlias } from "../provider/config.js";
|
|
7
|
-
import { getUsageTracker } from "../utils/usage-tracker.js";
|
|
8
|
-
import { RateLimiter, DEFAULT_RATE_LIMITS } from "../utils/rate-limiter.js";
|
|
9
|
-
import { getAuditLogger, AuditCategory } from "../utils/audit-logger.js";
|
|
10
|
-
import { retryStreamWithBackoff, retryWithBackoff } from "../utils/retry-helper.js";
|
|
11
|
-
import { LLMAPIError } from "../utils/api-error.js";
|
|
12
|
-
import { validateSampling } from "./types.js";
|
|
13
|
-
/** Streaming configuration constants */
|
|
14
|
-
const STREAMING_CONFIG = {
|
|
15
|
-
/** Timeout waiting for first chunk (ms) - increased for complex operations with large context */
|
|
16
|
-
FIRST_CHUNK_TIMEOUT_MS: TIMEOUT_CONFIG.STREAMING_FIRST_CHUNK,
|
|
17
|
-
/** Timeout for idle periods between chunks (ms) */
|
|
18
|
-
IDLE_TIMEOUT_MS: TIMEOUT_CONFIG.STREAMING_IDLE,
|
|
19
|
-
/** Yield to event loop every N chunks */
|
|
20
|
-
YIELD_INTERVAL: 20,
|
|
21
|
-
/** Max time before yielding to event loop (ms) */
|
|
22
|
-
MAX_TIME_BEFORE_YIELD_MS: 100,
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* LLMClient - Enhanced client for GLM-4.6 API
|
|
26
|
-
*
|
|
27
|
-
* Supports advanced features including:
|
|
28
|
-
* - Thinking/reasoning mode
|
|
29
|
-
* - Configurable temperature (0.6-1.0 for GLM-4.6)
|
|
30
|
-
* - Extended context windows (up to 200K tokens)
|
|
31
|
-
* - Multiple model support
|
|
32
|
-
*/
|
|
33
|
-
export class LLMClient {
|
|
34
|
-
client;
|
|
35
|
-
currentModel; // Can be SupportedModel or custom model name (e.g., Ollama)
|
|
36
|
-
defaultMaxTokens;
|
|
37
|
-
defaultTemperature;
|
|
38
|
-
rateLimiter; // REQ-SEC-006: Rate limiting to prevent API abuse
|
|
39
|
-
constructor(apiKey, model, baseURL) {
|
|
40
|
-
if (!model) {
|
|
41
|
-
throw new Error('No model specified. Please run "ax-cli setup" to configure your AI provider and model.');
|
|
42
|
-
}
|
|
43
|
-
if (!baseURL) {
|
|
44
|
-
throw new Error('No base URL specified. Please run "ax-cli setup" to configure your AI provider base URL.');
|
|
45
|
-
}
|
|
46
|
-
this.client = new OpenAI({
|
|
47
|
-
apiKey,
|
|
48
|
-
baseURL,
|
|
49
|
-
timeout: 600000, // Increased to 10 minutes for long contexts
|
|
50
|
-
});
|
|
51
|
-
// Set model with validation
|
|
52
|
-
this.currentModel = this.validateModel(model);
|
|
53
|
-
// Get model configuration (with fallback for custom models)
|
|
54
|
-
const modelConfig = GLM_MODELS[this.currentModel] || {
|
|
55
|
-
maxOutputTokens: 128000, // Generous default for custom models
|
|
56
|
-
defaultMaxTokens: 4096,
|
|
57
|
-
temperatureRange: { min: 0.0, max: 2.0 },
|
|
58
|
-
defaultTemperature: 0.7,
|
|
59
|
-
};
|
|
60
|
-
// Set defaults from environment or model config
|
|
61
|
-
const envMax = Number(process.env.AI_MAX_TOKENS);
|
|
62
|
-
this.defaultMaxTokens = Number.isFinite(envMax) && envMax > 0
|
|
63
|
-
? Math.min(envMax, modelConfig.maxOutputTokens)
|
|
64
|
-
: modelConfig.defaultMaxTokens;
|
|
65
|
-
const envTemp = Number(process.env.AI_TEMPERATURE);
|
|
66
|
-
this.defaultTemperature = Number.isFinite(envTemp) &&
|
|
67
|
-
envTemp >= modelConfig.temperatureRange.min &&
|
|
68
|
-
envTemp <= modelConfig.temperatureRange.max
|
|
69
|
-
? envTemp
|
|
70
|
-
: modelConfig.defaultTemperature;
|
|
71
|
-
// Initialize rate limiter for API abuse prevention (REQ-SEC-006)
|
|
72
|
-
this.rateLimiter = new RateLimiter(DEFAULT_RATE_LIMITS.LLM_API);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Validate and normalize model name
|
|
76
|
-
* For known models, validate against GLM_MODELS and provider models
|
|
77
|
-
* For unknown models (e.g., Ollama), pass through without validation
|
|
78
|
-
* Also resolves model aliases (e.g., 'grok-latest' -> 'grok-4-0709')
|
|
79
|
-
*/
|
|
80
|
-
validateModel(model) {
|
|
81
|
-
// First, resolve any alias to the actual model name
|
|
82
|
-
const resolvedModel = resolveModelAlias(model);
|
|
83
|
-
// Check GLM models (legacy constant)
|
|
84
|
-
if (resolvedModel in GLM_MODELS) {
|
|
85
|
-
return resolvedModel;
|
|
86
|
-
}
|
|
87
|
-
// Check provider-specific models (GLM and Grok)
|
|
88
|
-
if (resolvedModel in GLM_PROVIDER.models || resolvedModel in GROK_PROVIDER.models) {
|
|
89
|
-
return resolvedModel;
|
|
90
|
-
}
|
|
91
|
-
// Allow arbitrary model names for providers like Ollama
|
|
92
|
-
// Don't fall back to DEFAULT_MODEL - respect user's choice
|
|
93
|
-
console.warn(`Using custom model "${resolvedModel}" (not in predefined list)`);
|
|
94
|
-
return resolvedModel;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Validate temperature for current model
|
|
98
|
-
*/
|
|
99
|
-
validateTemperature(temperature, model) {
|
|
100
|
-
const config = GLM_MODELS[model];
|
|
101
|
-
if (!config) {
|
|
102
|
-
// Custom model - allow any temperature between 0 and 2
|
|
103
|
-
if (temperature < 0 || temperature > 2) {
|
|
104
|
-
throw new Error(`Temperature ${temperature} is out of range. Valid range: 0.0 - 2.0`);
|
|
105
|
-
}
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const { min, max } = config.temperatureRange;
|
|
109
|
-
if (temperature < min || temperature > max) {
|
|
110
|
-
throw new Error(`Temperature ${temperature} is out of range for model ${model}. ` +
|
|
111
|
-
`Valid range: ${min} - ${max}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Validate and clamp max tokens for current model
|
|
116
|
-
* Returns the clamped value (clamps to model limit if exceeded)
|
|
117
|
-
*/
|
|
118
|
-
validateAndClampMaxTokens(maxTokens, model) {
|
|
119
|
-
const config = GLM_MODELS[model];
|
|
120
|
-
if (maxTokens < 1) {
|
|
121
|
-
throw new Error(`Max tokens must be at least 1, got ${maxTokens}`);
|
|
122
|
-
}
|
|
123
|
-
if (!config) {
|
|
124
|
-
// Custom model - allow up to 128K tokens
|
|
125
|
-
if (maxTokens > 128000) {
|
|
126
|
-
return 128000; // Clamp to reasonable limit
|
|
127
|
-
}
|
|
128
|
-
return maxTokens;
|
|
129
|
-
}
|
|
130
|
-
// Clamp to model's max output tokens (e.g., when auto-switching to vision model)
|
|
131
|
-
if (maxTokens > config.maxOutputTokens) {
|
|
132
|
-
return config.maxOutputTokens;
|
|
133
|
-
}
|
|
134
|
-
return maxTokens;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Safely extract usage from unknown response payloads
|
|
138
|
-
* Ensures we only rely on numeric token counts to avoid runtime errors
|
|
139
|
-
*/
|
|
140
|
-
safeExtractUsage(raw) {
|
|
141
|
-
if (!raw || typeof raw !== 'object') {
|
|
142
|
-
return undefined;
|
|
143
|
-
}
|
|
144
|
-
const usage = raw;
|
|
145
|
-
if (typeof usage.prompt_tokens === 'number' &&
|
|
146
|
-
typeof usage.completion_tokens === 'number' &&
|
|
147
|
-
typeof usage.total_tokens === 'number') {
|
|
148
|
-
const normalized = {
|
|
149
|
-
prompt_tokens: usage.prompt_tokens,
|
|
150
|
-
completion_tokens: usage.completion_tokens,
|
|
151
|
-
total_tokens: usage.total_tokens,
|
|
152
|
-
};
|
|
153
|
-
if (typeof usage.reasoning_tokens === 'number') {
|
|
154
|
-
normalized.reasoning_tokens = usage.reasoning_tokens;
|
|
155
|
-
}
|
|
156
|
-
// BUG FIX: Extract cached tokens for GLM 4.6 cache savings tracking
|
|
157
|
-
// Without this, streaming responses wouldn't track cache hits
|
|
158
|
-
if (usage.prompt_tokens_details &&
|
|
159
|
-
typeof usage.prompt_tokens_details.cached_tokens === 'number') {
|
|
160
|
-
normalized.prompt_tokens_details = {
|
|
161
|
-
cached_tokens: usage.prompt_tokens_details.cached_tokens,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
return normalized;
|
|
165
|
-
}
|
|
166
|
-
return undefined;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Coerce a loosely-typed response into an LLMResponse shape, dropping invalid choices
|
|
170
|
-
*/
|
|
171
|
-
coerceLLMResponse(raw) {
|
|
172
|
-
if (!raw || typeof raw !== 'object') {
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
const obj = raw;
|
|
176
|
-
if (!Array.isArray(obj.choices)) {
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
const choices = obj.choices
|
|
180
|
-
.filter((choice) => choice &&
|
|
181
|
-
typeof choice === 'object' &&
|
|
182
|
-
typeof choice.message?.role === 'string')
|
|
183
|
-
.map((choice) => {
|
|
184
|
-
const message = choice.message;
|
|
185
|
-
const toolCalls = Array.isArray(message?.tool_calls)
|
|
186
|
-
? message.tool_calls
|
|
187
|
-
.filter((call) => call &&
|
|
188
|
-
typeof call === 'object' &&
|
|
189
|
-
typeof call.id === 'string' &&
|
|
190
|
-
typeof call.function?.name === 'string' &&
|
|
191
|
-
typeof call.function?.arguments === 'string')
|
|
192
|
-
.map((call) => ({
|
|
193
|
-
id: call.id,
|
|
194
|
-
type: 'function',
|
|
195
|
-
function: {
|
|
196
|
-
name: call.function.name,
|
|
197
|
-
arguments: call.function.arguments,
|
|
198
|
-
},
|
|
199
|
-
}))
|
|
200
|
-
: undefined;
|
|
201
|
-
return {
|
|
202
|
-
message: {
|
|
203
|
-
role: message.role,
|
|
204
|
-
content: typeof message.content === 'string' || message.content === null
|
|
205
|
-
? message.content
|
|
206
|
-
: null,
|
|
207
|
-
reasoning_content: typeof message.reasoning_content === 'string'
|
|
208
|
-
? message.reasoning_content
|
|
209
|
-
: undefined,
|
|
210
|
-
tool_calls: toolCalls,
|
|
211
|
-
},
|
|
212
|
-
finish_reason: typeof choice.finish_reason === 'string'
|
|
213
|
-
? choice.finish_reason
|
|
214
|
-
: 'unknown',
|
|
215
|
-
};
|
|
216
|
-
})
|
|
217
|
-
.filter((choice) => Boolean(choice));
|
|
218
|
-
if (choices.length === 0) {
|
|
219
|
-
return null;
|
|
220
|
-
}
|
|
221
|
-
return {
|
|
222
|
-
choices,
|
|
223
|
-
usage: this.safeExtractUsage(obj.usage),
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Validate thinking configuration for current model
|
|
228
|
-
*/
|
|
229
|
-
validateThinking(thinking, model) {
|
|
230
|
-
if (thinking && thinking.type === "enabled") {
|
|
231
|
-
const config = GLM_MODELS[model];
|
|
232
|
-
if (config && !config.supportsThinking) {
|
|
233
|
-
throw new Error(`Thinking mode is not supported by model ${model}. ` +
|
|
234
|
-
`Use glm-4.6 for thinking capabilities.`);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Build request payload for chat completions
|
|
240
|
-
* Consolidates duplicate payload building logic
|
|
241
|
-
*/
|
|
242
|
-
buildRequestPayload(model, // Accept string to support custom models (e.g., Ollama)
|
|
243
|
-
messages, tools, temperature, maxTokens, thinking, searchOptions, stream = false, responseFormat, sampling) {
|
|
244
|
-
const payload = {
|
|
245
|
-
model,
|
|
246
|
-
messages,
|
|
247
|
-
temperature,
|
|
248
|
-
max_tokens: maxTokens,
|
|
249
|
-
};
|
|
250
|
-
// Only include tools if there are any - some APIs reject empty tools array
|
|
251
|
-
if (tools && tools.length > 0) {
|
|
252
|
-
payload.tools = tools;
|
|
253
|
-
payload.tool_choice = "auto";
|
|
254
|
-
}
|
|
255
|
-
if (stream) {
|
|
256
|
-
payload.stream = true;
|
|
257
|
-
// Note: tool_stream is NOT a valid z.ai parameter - removed to prevent API errors
|
|
258
|
-
}
|
|
259
|
-
// Detect if this is a Grok model (xAI)
|
|
260
|
-
const isGrokModel = model.toLowerCase().includes('grok');
|
|
261
|
-
// Add thinking/reasoning parameters based on provider
|
|
262
|
-
if (thinking && thinking.type === 'enabled') {
|
|
263
|
-
if (isGrokModel) {
|
|
264
|
-
// Grok uses reasoning_effort parameter for models that support thinking
|
|
265
|
-
// Grok 4 models support reasoning_effort (low/high) - Grok 4 is now the default
|
|
266
|
-
const modelLower = model.toLowerCase();
|
|
267
|
-
const supportsReasoning = modelLower.includes('grok-4');
|
|
268
|
-
if (supportsReasoning) {
|
|
269
|
-
payload.reasoning_effort = thinking.reasoningEffort || 'high';
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
// GLM uses thinking parameter
|
|
274
|
-
payload.thinking = thinking;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
// Add search parameters if specified
|
|
278
|
-
// Works for both Grok (live search) and potentially other providers
|
|
279
|
-
if (searchOptions?.search_parameters) {
|
|
280
|
-
payload.search_parameters = searchOptions.search_parameters;
|
|
281
|
-
}
|
|
282
|
-
// Add structured output format if specified
|
|
283
|
-
// When using json_object, the model will return valid JSON
|
|
284
|
-
if (responseFormat) {
|
|
285
|
-
payload.response_format = responseFormat;
|
|
286
|
-
}
|
|
287
|
-
// Add sampling parameters - provider-specific handling
|
|
288
|
-
if (sampling) {
|
|
289
|
-
if (isGrokModel) {
|
|
290
|
-
// Grok uses seed for reproducibility (not do_sample)
|
|
291
|
-
if (sampling.seed !== undefined) {
|
|
292
|
-
payload.seed = sampling.seed;
|
|
293
|
-
}
|
|
294
|
-
if (sampling.topP !== undefined) {
|
|
295
|
-
payload.top_p = sampling.topP;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
// GLM uses do_sample for deterministic mode
|
|
300
|
-
if (sampling.doSample !== undefined) {
|
|
301
|
-
payload.do_sample = sampling.doSample;
|
|
302
|
-
}
|
|
303
|
-
// seed is not supported by z.ai API - omitted
|
|
304
|
-
if (sampling.topP !== undefined) {
|
|
305
|
-
payload.top_p = sampling.topP;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
return payload;
|
|
310
|
-
}
|
|
311
|
-
setModel(model) {
|
|
312
|
-
this.currentModel = this.validateModel(model);
|
|
313
|
-
const modelConfig = GLM_MODELS[this.currentModel] || {
|
|
314
|
-
maxOutputTokens: 128000,
|
|
315
|
-
defaultMaxTokens: 4096,
|
|
316
|
-
temperatureRange: { min: 0.0, max: 2.0 },
|
|
317
|
-
defaultTemperature: 0.7,
|
|
318
|
-
};
|
|
319
|
-
const envMax = Number(process.env.AI_MAX_TOKENS);
|
|
320
|
-
this.defaultMaxTokens = Number.isFinite(envMax) && envMax > 0
|
|
321
|
-
? Math.min(envMax, modelConfig.maxOutputTokens)
|
|
322
|
-
: modelConfig.defaultMaxTokens;
|
|
323
|
-
const envTemp = Number(process.env.AI_TEMPERATURE);
|
|
324
|
-
this.defaultTemperature = Number.isFinite(envTemp) &&
|
|
325
|
-
envTemp >= modelConfig.temperatureRange.min &&
|
|
326
|
-
envTemp <= modelConfig.temperatureRange.max
|
|
327
|
-
? envTemp
|
|
328
|
-
: modelConfig.defaultTemperature;
|
|
329
|
-
}
|
|
330
|
-
getCurrentModel() {
|
|
331
|
-
return this.currentModel;
|
|
332
|
-
}
|
|
333
|
-
getModelConfig() {
|
|
334
|
-
return GLM_MODELS[this.currentModel] || null;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Chat completion with GLM-4.6 support
|
|
338
|
-
*
|
|
339
|
-
* @param messages - Conversation messages
|
|
340
|
-
* @param tools - Available tools/functions
|
|
341
|
-
* @param options - Chat options including temperature, thinking mode, etc.
|
|
342
|
-
* @returns Promise<LLMResponse>
|
|
343
|
-
*
|
|
344
|
-
* @example
|
|
345
|
-
* ```typescript
|
|
346
|
-
* const response = await client.chat(messages, tools, {
|
|
347
|
-
* model: 'glm-4.6',
|
|
348
|
-
* temperature: 0.7,
|
|
349
|
-
* thinking: { type: 'enabled' },
|
|
350
|
-
* maxTokens: 8192
|
|
351
|
-
* });
|
|
352
|
-
* ```
|
|
353
|
-
*/
|
|
354
|
-
async chat(messages, tools, options) {
|
|
355
|
-
const auditLogger = getAuditLogger();
|
|
356
|
-
const requestController = new AbortController();
|
|
357
|
-
const upstreamSignal = options?.signal;
|
|
358
|
-
const handleUpstreamAbort = () => requestController.abort(upstreamSignal?.reason);
|
|
359
|
-
if (upstreamSignal) {
|
|
360
|
-
if (upstreamSignal.aborted) {
|
|
361
|
-
requestController.abort(upstreamSignal.reason);
|
|
362
|
-
}
|
|
363
|
-
else {
|
|
364
|
-
upstreamSignal.addEventListener('abort', handleUpstreamAbort, { once: true });
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
const timeoutId = setTimeout(() => requestController.abort(new Error('LLM chat request timed out after 600000ms')), 600000);
|
|
368
|
-
try {
|
|
369
|
-
// REQ-SEC-006: Check rate limit before making API call
|
|
370
|
-
const rateLimitResult = this.rateLimiter.tryAcquire();
|
|
371
|
-
if (!rateLimitResult.allowed) {
|
|
372
|
-
const waitSeconds = Math.ceil(rateLimitResult.resetIn / 1000);
|
|
373
|
-
// REQ-SEC-008: Audit log rate limit exceeded
|
|
374
|
-
auditLogger.logWarning({
|
|
375
|
-
category: AuditCategory.RATE_LIMIT,
|
|
376
|
-
action: 'rate_limit_exceeded',
|
|
377
|
-
resource: 'llm_api',
|
|
378
|
-
outcome: 'failure',
|
|
379
|
-
details: {
|
|
380
|
-
limit: rateLimitResult.limit,
|
|
381
|
-
remaining: rateLimitResult.remaining,
|
|
382
|
-
resetIn: rateLimitResult.resetIn,
|
|
383
|
-
},
|
|
384
|
-
});
|
|
385
|
-
throw new Error(`Rate limit exceeded. ${rateLimitResult.remaining}/${rateLimitResult.limit} requests remaining. ` +
|
|
386
|
-
`Please wait ${waitSeconds} seconds before trying again.`);
|
|
387
|
-
}
|
|
388
|
-
// Merge options with defaults
|
|
389
|
-
const model = this.validateModel(options?.model || this.currentModel);
|
|
390
|
-
const temperature = options?.temperature ?? this.defaultTemperature;
|
|
391
|
-
const rawMaxTokens = options?.maxTokens ?? this.defaultMaxTokens;
|
|
392
|
-
const thinking = options?.thinking;
|
|
393
|
-
const searchOptions = options?.searchOptions;
|
|
394
|
-
const responseFormat = options?.responseFormat;
|
|
395
|
-
const sampling = options?.sampling;
|
|
396
|
-
// Validate parameters (clamp maxTokens to model limit)
|
|
397
|
-
this.validateTemperature(temperature, model);
|
|
398
|
-
const maxTokens = this.validateAndClampMaxTokens(rawMaxTokens, model);
|
|
399
|
-
this.validateThinking(thinking, model);
|
|
400
|
-
validateSampling(sampling, temperature);
|
|
401
|
-
// Build request payload using consolidated helper
|
|
402
|
-
const requestPayload = this.buildRequestPayload(model, messages, tools, temperature, maxTokens, thinking, searchOptions, false, // not streaming
|
|
403
|
-
responseFormat, sampling);
|
|
404
|
-
const response = await retryWithBackoff(() => this.client.chat.completions.create(requestPayload, {
|
|
405
|
-
signal: requestController.signal,
|
|
406
|
-
}), {
|
|
407
|
-
onRetry: (attempt, error, delayMs) => {
|
|
408
|
-
auditLogger.logWarning({
|
|
409
|
-
category: AuditCategory.API_CALL,
|
|
410
|
-
action: 'llm_api_call_retry',
|
|
411
|
-
resource: model,
|
|
412
|
-
outcome: 'failure',
|
|
413
|
-
details: {
|
|
414
|
-
attempt,
|
|
415
|
-
delayMs,
|
|
416
|
-
status: error?.status,
|
|
417
|
-
},
|
|
418
|
-
error: extractAndTranslateError(error),
|
|
419
|
-
});
|
|
420
|
-
},
|
|
421
|
-
});
|
|
422
|
-
// REQ-SEC-008: Audit log successful API call
|
|
423
|
-
auditLogger.logInfo({
|
|
424
|
-
category: AuditCategory.API_CALL,
|
|
425
|
-
action: 'llm_api_call',
|
|
426
|
-
resource: model,
|
|
427
|
-
outcome: 'success',
|
|
428
|
-
details: {
|
|
429
|
-
hasTools: tools && tools.length > 0,
|
|
430
|
-
messageCount: messages.length,
|
|
431
|
-
},
|
|
432
|
-
});
|
|
433
|
-
// Validate response structure
|
|
434
|
-
const validationResult = safeValidateGrokResponse(response);
|
|
435
|
-
if (!validationResult.success) {
|
|
436
|
-
console.warn(createErrorMessage(ErrorCategory.VALIDATION, 'LLM API response validation', validationResult.error?.message || 'Invalid response structure'));
|
|
437
|
-
}
|
|
438
|
-
const llmResponse = validationResult.data ?? this.coerceLLMResponse(response);
|
|
439
|
-
if (!llmResponse) {
|
|
440
|
-
throw new Error('LLM API response validation failed: missing choices or invalid message structure');
|
|
441
|
-
}
|
|
442
|
-
const usage = llmResponse.usage ? this.safeExtractUsage(llmResponse.usage) : undefined;
|
|
443
|
-
if (usage) {
|
|
444
|
-
const tracker = getUsageTracker();
|
|
445
|
-
tracker.trackUsage(model, usage);
|
|
446
|
-
// Track memory cache stats if cached_tokens available
|
|
447
|
-
const rawResponse = response;
|
|
448
|
-
const cachedTokens = rawResponse?.usage?.prompt_tokens_details?.cached_tokens;
|
|
449
|
-
if (typeof cachedTokens === 'number' && cachedTokens > 0) {
|
|
450
|
-
// Lazy import to avoid circular dependencies - fire and forget but safe
|
|
451
|
-
const promptTokens = usage.prompt_tokens;
|
|
452
|
-
import('../memory/index.js')
|
|
453
|
-
.then(({ getStatsCollector }) => {
|
|
454
|
-
try {
|
|
455
|
-
const statsCollector = getStatsCollector();
|
|
456
|
-
statsCollector.recordResponse(promptTokens, cachedTokens);
|
|
457
|
-
}
|
|
458
|
-
catch (err) {
|
|
459
|
-
// BUG FIX: Log error instead of silently ignoring for debuggability
|
|
460
|
-
if (process.env.DEBUG) {
|
|
461
|
-
console.warn('Failed to record memory stats:', err);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
})
|
|
465
|
-
.catch((err) => {
|
|
466
|
-
// BUG FIX: Log error instead of silently ignoring for debuggability
|
|
467
|
-
if (process.env.DEBUG) {
|
|
468
|
-
console.warn('Memory module not available:', err);
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
return llmResponse;
|
|
474
|
-
}
|
|
475
|
-
catch (error) {
|
|
476
|
-
// Enhance error message with context and translate if needed
|
|
477
|
-
const modelInfo = options?.model || this.currentModel;
|
|
478
|
-
const apiError = error;
|
|
479
|
-
const llmError = new LLMAPIError(`LLM API error (model: ${modelInfo}): ${extractAndTranslateError(error)}`, error, modelInfo, apiError?.status ?? apiError?.response?.status, apiError?.headers ?? apiError?.response?.headers, apiError?.response?.headers?.['x-request-id'] ?? apiError?.headers?.['x-request-id']);
|
|
480
|
-
auditLogger.logError({
|
|
481
|
-
category: AuditCategory.API_CALL,
|
|
482
|
-
action: 'llm_api_call',
|
|
483
|
-
resource: modelInfo,
|
|
484
|
-
outcome: 'failure',
|
|
485
|
-
error: llmError.message,
|
|
486
|
-
details: {
|
|
487
|
-
statusCode: llmError.statusCode,
|
|
488
|
-
isRetryable: llmError.isRetryable,
|
|
489
|
-
},
|
|
490
|
-
});
|
|
491
|
-
throw llmError;
|
|
492
|
-
}
|
|
493
|
-
finally {
|
|
494
|
-
clearTimeout(timeoutId);
|
|
495
|
-
if (upstreamSignal) {
|
|
496
|
-
upstreamSignal.removeEventListener('abort', handleUpstreamAbort);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Streaming chat completion with GLM-4.6 support
|
|
502
|
-
*
|
|
503
|
-
* Yields chunks including reasoning_content when thinking is enabled
|
|
504
|
-
*
|
|
505
|
-
* @param messages - Conversation messages
|
|
506
|
-
* @param tools - Available tools/functions
|
|
507
|
-
* @param options - Chat options including temperature, thinking mode, etc.
|
|
508
|
-
* @returns AsyncGenerator yielding GLM46StreamChunk
|
|
509
|
-
*
|
|
510
|
-
* @example
|
|
511
|
-
* ```typescript
|
|
512
|
-
* const stream = client.chatStream(messages, tools, {
|
|
513
|
-
* thinking: { type: 'enabled' }
|
|
514
|
-
* });
|
|
515
|
-
*
|
|
516
|
-
* for await (const chunk of stream) {
|
|
517
|
-
* if (chunk.choices[0]?.delta?.reasoning_content) {
|
|
518
|
-
* console.log('Reasoning:', chunk.choices[0].delta.reasoning_content);
|
|
519
|
-
* }
|
|
520
|
-
* if (chunk.choices[0]?.delta?.content) {
|
|
521
|
-
* console.log('Content:', chunk.choices[0].delta.content);
|
|
522
|
-
* }
|
|
523
|
-
* }
|
|
524
|
-
* ```
|
|
525
|
-
*/
|
|
526
|
-
async *chatStream(messages, tools, options) {
|
|
527
|
-
const auditLogger = getAuditLogger();
|
|
528
|
-
const masterController = new AbortController();
|
|
529
|
-
const upstreamSignal = options?.signal;
|
|
530
|
-
const handleUpstreamAbort = () => masterController.abort(upstreamSignal?.reason);
|
|
531
|
-
if (upstreamSignal) {
|
|
532
|
-
if (upstreamSignal.aborted) {
|
|
533
|
-
masterController.abort(upstreamSignal.reason);
|
|
534
|
-
}
|
|
535
|
-
else {
|
|
536
|
-
upstreamSignal.addEventListener('abort', handleUpstreamAbort, { once: true });
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
const masterTimeoutId = setTimeout(() => masterController.abort(new Error('LLM streaming request timed out after 600000ms')), 600000);
|
|
540
|
-
let finalUsage = null;
|
|
541
|
-
let totalChunks = 0;
|
|
542
|
-
try {
|
|
543
|
-
// REQ-SEC-006: Check rate limit before making streaming API call
|
|
544
|
-
const rateLimitResult = this.rateLimiter.tryAcquire();
|
|
545
|
-
if (!rateLimitResult.allowed) {
|
|
546
|
-
const waitSeconds = Math.ceil(rateLimitResult.resetIn / 1000);
|
|
547
|
-
auditLogger.logWarning({
|
|
548
|
-
category: AuditCategory.RATE_LIMIT,
|
|
549
|
-
action: 'rate_limit_exceeded',
|
|
550
|
-
resource: 'llm_api',
|
|
551
|
-
outcome: 'failure',
|
|
552
|
-
details: {
|
|
553
|
-
limit: rateLimitResult.limit,
|
|
554
|
-
remaining: rateLimitResult.remaining,
|
|
555
|
-
resetIn: rateLimitResult.resetIn,
|
|
556
|
-
},
|
|
557
|
-
});
|
|
558
|
-
throw new Error(`Rate limit exceeded. ${rateLimitResult.remaining}/${rateLimitResult.limit} requests remaining. ` +
|
|
559
|
-
`Please wait ${waitSeconds} seconds before trying again.`);
|
|
560
|
-
}
|
|
561
|
-
// Merge options with defaults
|
|
562
|
-
const model = this.validateModel(options?.model || this.currentModel);
|
|
563
|
-
const temperature = options?.temperature ?? this.defaultTemperature;
|
|
564
|
-
const rawMaxTokens = options?.maxTokens ?? this.defaultMaxTokens;
|
|
565
|
-
const thinking = options?.thinking;
|
|
566
|
-
const searchOptions = options?.searchOptions;
|
|
567
|
-
const responseFormat = options?.responseFormat;
|
|
568
|
-
const sampling = options?.sampling;
|
|
569
|
-
// Validate parameters (clamp maxTokens to model limit)
|
|
570
|
-
this.validateTemperature(temperature, model);
|
|
571
|
-
const maxTokens = this.validateAndClampMaxTokens(rawMaxTokens, model);
|
|
572
|
-
this.validateThinking(thinking, model);
|
|
573
|
-
validateSampling(sampling, temperature);
|
|
574
|
-
// Build request payload using consolidated helper
|
|
575
|
-
const requestPayload = this.buildRequestPayload(model, messages, tools, temperature, maxTokens, thinking, searchOptions, true, // streaming
|
|
576
|
-
responseFormat, sampling);
|
|
577
|
-
const client = this.client;
|
|
578
|
-
const extractUsage = this.safeExtractUsage.bind(this);
|
|
579
|
-
const streamGenerator = () => {
|
|
580
|
-
const attemptController = new AbortController();
|
|
581
|
-
const onMasterAbort = () => attemptController.abort(masterController.signal.reason);
|
|
582
|
-
// BUG FIX: Track listener state to ensure cleanup even if generator is never consumed
|
|
583
|
-
let listenerAttached = false;
|
|
584
|
-
if (masterController.signal.aborted) {
|
|
585
|
-
attemptController.abort(masterController.signal.reason);
|
|
586
|
-
}
|
|
587
|
-
else {
|
|
588
|
-
masterController.signal.addEventListener('abort', onMasterAbort, { once: true });
|
|
589
|
-
listenerAttached = true;
|
|
590
|
-
}
|
|
591
|
-
// BUG FIX: Helper to safely remove listener
|
|
592
|
-
const cleanupListener = () => {
|
|
593
|
-
if (listenerAttached) {
|
|
594
|
-
masterController.signal.removeEventListener('abort', onMasterAbort);
|
|
595
|
-
listenerAttached = false;
|
|
596
|
-
}
|
|
597
|
-
};
|
|
598
|
-
const generator = (async function* () {
|
|
599
|
-
let firstChunkTimer;
|
|
600
|
-
let idleTimer;
|
|
601
|
-
let chunksProcessed = 0;
|
|
602
|
-
let lastYieldTime = Date.now();
|
|
603
|
-
try {
|
|
604
|
-
firstChunkTimer = setTimeout(() => attemptController.abort(new Error('Streaming first chunk timeout')), STREAMING_CONFIG.FIRST_CHUNK_TIMEOUT_MS);
|
|
605
|
-
const stream = (await client.chat.completions.create(requestPayload, {
|
|
606
|
-
signal: attemptController.signal,
|
|
607
|
-
}));
|
|
608
|
-
for await (const chunk of stream) {
|
|
609
|
-
if (attemptController.signal.aborted) {
|
|
610
|
-
throw attemptController.signal.reason || new Error('Streaming aborted');
|
|
611
|
-
}
|
|
612
|
-
if (firstChunkTimer) {
|
|
613
|
-
clearTimeout(firstChunkTimer);
|
|
614
|
-
firstChunkTimer = undefined;
|
|
615
|
-
}
|
|
616
|
-
if (idleTimer) {
|
|
617
|
-
clearTimeout(idleTimer);
|
|
618
|
-
}
|
|
619
|
-
idleTimer = setTimeout(() => attemptController.abort(new Error('Streaming idle timeout')), STREAMING_CONFIG.IDLE_TIMEOUT_MS);
|
|
620
|
-
const isValidChunk = chunk && typeof chunk === 'object' && Array.isArray(chunk.choices);
|
|
621
|
-
if (!isValidChunk) {
|
|
622
|
-
console.warn(createErrorMessage(ErrorCategory.VALIDATION, 'LLM streaming response validation', 'Invalid stream chunk structure'));
|
|
623
|
-
}
|
|
624
|
-
const usage = extractUsage(chunk.usage);
|
|
625
|
-
if (usage) {
|
|
626
|
-
finalUsage = usage;
|
|
627
|
-
}
|
|
628
|
-
totalChunks++;
|
|
629
|
-
yield chunk;
|
|
630
|
-
chunksProcessed++;
|
|
631
|
-
const timeSinceYield = Date.now() - lastYieldTime;
|
|
632
|
-
if (chunksProcessed % STREAMING_CONFIG.YIELD_INTERVAL === 0 || timeSinceYield > STREAMING_CONFIG.MAX_TIME_BEFORE_YIELD_MS) {
|
|
633
|
-
await new Promise(resolve => setImmediate(resolve));
|
|
634
|
-
lastYieldTime = Date.now();
|
|
635
|
-
if (timeSinceYield > STREAMING_CONFIG.MAX_TIME_BEFORE_YIELD_MS) {
|
|
636
|
-
chunksProcessed = 0;
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
finally {
|
|
642
|
-
if (firstChunkTimer) {
|
|
643
|
-
clearTimeout(firstChunkTimer);
|
|
644
|
-
}
|
|
645
|
-
if (idleTimer) {
|
|
646
|
-
clearTimeout(idleTimer);
|
|
647
|
-
}
|
|
648
|
-
cleanupListener();
|
|
649
|
-
}
|
|
650
|
-
})();
|
|
651
|
-
// BUG FIX: Use FinalizationRegistry to clean up listener if generator is GC'd without being consumed
|
|
652
|
-
// This is a safety net - proper usage should always iterate the generator
|
|
653
|
-
if (typeof FinalizationRegistry !== 'undefined') {
|
|
654
|
-
const registry = new FinalizationRegistry(cleanupListener);
|
|
655
|
-
registry.register(generator, undefined);
|
|
656
|
-
}
|
|
657
|
-
return generator;
|
|
658
|
-
};
|
|
659
|
-
for await (const chunk of retryStreamWithBackoff(streamGenerator, {
|
|
660
|
-
onRetry: (attempt, error, delayMs) => {
|
|
661
|
-
auditLogger.logWarning({
|
|
662
|
-
category: AuditCategory.API_CALL,
|
|
663
|
-
action: 'llm_api_stream_retry',
|
|
664
|
-
resource: model,
|
|
665
|
-
outcome: 'failure',
|
|
666
|
-
details: {
|
|
667
|
-
attempt,
|
|
668
|
-
delayMs,
|
|
669
|
-
status: error?.status,
|
|
670
|
-
},
|
|
671
|
-
error: extractAndTranslateError(error),
|
|
672
|
-
});
|
|
673
|
-
},
|
|
674
|
-
})) {
|
|
675
|
-
yield chunk;
|
|
676
|
-
}
|
|
677
|
-
// Note: finalUsage is mutated inside the inner async generator
|
|
678
|
-
// so we cast it to help TypeScript understand it may have been set
|
|
679
|
-
const usageForTracking = finalUsage;
|
|
680
|
-
if (usageForTracking) {
|
|
681
|
-
const tracker = getUsageTracker();
|
|
682
|
-
tracker.trackUsage(model, usageForTracking);
|
|
683
|
-
}
|
|
684
|
-
const totalTokens = usageForTracking?.total_tokens;
|
|
685
|
-
auditLogger.logInfo({
|
|
686
|
-
category: AuditCategory.API_CALL,
|
|
687
|
-
action: 'llm_api_stream',
|
|
688
|
-
resource: model,
|
|
689
|
-
outcome: 'success',
|
|
690
|
-
details: {
|
|
691
|
-
chunks: totalChunks,
|
|
692
|
-
totalTokens,
|
|
693
|
-
},
|
|
694
|
-
});
|
|
695
|
-
}
|
|
696
|
-
catch (error) {
|
|
697
|
-
const modelInfo = options?.model || this.currentModel;
|
|
698
|
-
const apiError = error;
|
|
699
|
-
const llmError = new LLMAPIError(`LLM API streaming error (model: ${modelInfo}): ${extractAndTranslateError(error)}`, error, modelInfo, apiError?.status ?? apiError?.response?.status, apiError?.headers ?? apiError?.response?.headers, apiError?.response?.headers?.['x-request-id'] ?? apiError?.headers?.['x-request-id']);
|
|
700
|
-
auditLogger.logError({
|
|
701
|
-
category: AuditCategory.API_CALL,
|
|
702
|
-
action: 'llm_api_stream',
|
|
703
|
-
resource: modelInfo,
|
|
704
|
-
outcome: 'failure',
|
|
705
|
-
error: llmError.message,
|
|
706
|
-
details: {
|
|
707
|
-
statusCode: llmError.statusCode,
|
|
708
|
-
isRetryable: llmError.isRetryable,
|
|
709
|
-
},
|
|
710
|
-
});
|
|
711
|
-
throw llmError;
|
|
712
|
-
}
|
|
713
|
-
finally {
|
|
714
|
-
clearTimeout(masterTimeoutId);
|
|
715
|
-
if (upstreamSignal) {
|
|
716
|
-
upstreamSignal.removeEventListener('abort', handleUpstreamAbort);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
/**
|
|
721
|
-
* Search with web context (deprecated - use chat with searchOptions)
|
|
722
|
-
* @deprecated Use chat() with searchOptions parameter instead
|
|
723
|
-
*/
|
|
724
|
-
async search(query, searchParameters) {
|
|
725
|
-
const searchMessage = {
|
|
726
|
-
role: "user",
|
|
727
|
-
content: query,
|
|
728
|
-
};
|
|
729
|
-
const searchOptions = {
|
|
730
|
-
search_parameters: searchParameters || { mode: "on" },
|
|
731
|
-
};
|
|
732
|
-
return this.chat([searchMessage], [], { searchOptions });
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
//# sourceMappingURL=client.js.map
|