-
Notifications
You must be signed in to change notification settings - Fork 1
[MaximJS] together ai sdk integration #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary by CodeRabbit
Summary by CodeRabbit
WalkthroughThe changes introduce Together AI and Groq SDK integrations by updating dependencies and exports in Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TogetherClient
participant MaximLogger
User->>TogetherClient: chat.create()/images.create() (via wrapped client)
TogetherClient->>MaximLogger: Start trace & generation (with metadata)
TogetherClient->>TogetherClient: Perform API call (chat or image)
alt Success
TogetherClient->>MaximLogger: Log result & end generation/trace
TogetherClient->>User: Return result
else Error
TogetherClient->>MaximLogger: Log error & end generation/trace
TogetherClient->>User: Throw error
end
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
- [MaximJS] groq ai sdk integration #29 Graphite
- [MaximJS] together ai sdk integration #28 Graphite 👈 (View in Graphite)
main
This stack of pull requests is managed by Graphite. Learn more about stacking.
aa3eb72 to
848ddd9
Compare
@coderabbitai
coderabbitai
bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (5)
package.json(1 hunks)src/lib/logger/together/togetherLogger.test.ts(1 hunks)src/lib/logger/together/utils.ts(1 hunks)src/lib/logger/together/wrapper.ts(1 hunks)together-ai-sdk.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: danpiths
PR: maximhq/maxim-js#16
File: src/lib/logger/components/session.ts:96-98
Timestamp: 2025年06月28日T20:29:57.000Z
Learning: In the maxim-js codebase, danpiths prefers to handle feedback score validation (1-5 range) in the UI layer rather than adding validation to the SDK methods like Session.feedback() and Session.feedback_(), indicating a preference for UI-side validation over SDK-side validation for user input data.
Learnt from: danpiths
PR: maximhq/maxim-js#16
File: src/lib/maxim.ts:170-174
Timestamp: 2025年06月28日T20:39:04.577Z
Learning: In the maxim-js codebase, danpiths is comfortable using the non-standard `@important` JSDoc tag in documentation comments and prefers to defer replacing it with the standard `@remarks` tag, prioritizing current PR objectives over JSDoc tooling compatibility improvements.
Learnt from: SamstyleGhost
PR: maximhq/maxim-js#18
File: src/lib/logger/vercel/utils.ts:241-241
Timestamp: 2025年06月26日T13:58:22.625Z
Learning: In src/lib/logger/vercel/utils.ts:241, the convertDoGenerateResultToChatCompletionResult function parameter uses `DoGenerateResultLike & { [key: string]: any }` intersection type intentionally because the AI SDK has additional properties that aren't exported in their type definitions. Rewriting it completely wouldn't make sense, so the intersection type provides access to these runtime properties.
Learnt from: danpiths
PR: maximhq/maxim-js#2
File: package.json:38-40
Timestamp: 2025年06月16日T05:35:50.998Z
Learning: In the maxim-js library, @langchain/core is correctly placed in optionalDependencies because it's only required when using MaximLangchainTracer functionality. Users who don't need LangChain integration can use the library without installing @langchain/core, keeping the installation lightweight.
Learnt from: danpiths
PR: maximhq/maxim-js#2
File: package.json:15-33
Timestamp: 2025年06月16日T05:36:54.415Z
Learning: The LangChain packages in maxim-js are intentionally kept as optional/dev dependencies rather than regular dependencies. This design choice ensures that users who don't need MaximLangchainTracer functionality can use the library without installing heavy LangChain packages, keeping the installation lightweight.
together-ai-sdk.ts (11)
Learnt from: SamstyleGhost
PR: maximhq/maxim-js#18
File: src/lib/logger/vercel/utils.ts:241-241
Timestamp: 2025年06月26日T13:58:22.625Z
Learning: In src/lib/logger/vercel/utils.ts:241, the convertDoGenerateResultToChatCompletionResult function parameter uses `DoGenerateResultLike & { [key: string]: any }` intersection type intentionally because the AI SDK has additional properties that aren't exported in their type definitions. Rewriting it completely wouldn't make sense, so the intersection type provides access to these runtime properties.
Learnt from: SamstyleGhost
PR: maximhq/maxim-js#18
File: src/lib/logger/vercel/wrapper.ts:212-212
Timestamp: 2025年06月25日T05:20:43.227Z
Learning: In `src/lib/logger/vercel/wrapper.ts`, the `processStream` function expects the model ID string as a parameter, not the provider name. When calling `processStream(chunks, span, trace, generation, model, maximMetadata)`, use `this.modelId` instead of `modelProvider` to pass the correct model identifier.
Learnt from: SamstyleGhost
PR: maximhq/maxim-js#18
File: src/lib/logger/vercel/utils.ts:14-15
Timestamp: 2025年06月24日T08:03:29.963Z
Learning: In the provider detection logic for Vercel AI models in src/lib/logger/vercel/utils.ts, both "azure" and "azure_openai" model strings should be classified as the "azure" provider type. The current implementation correctly prevents "azure_openai" models from being misclassified as "openai" provider.
Learnt from: danpiths
PR: maximhq/maxim-js#20
File: src/lib/logger/vercel/utils.ts:23-35
Timestamp: 2025年06月29日T07:57:14.446Z
Learning: In the maxim-js codebase, danpiths prefers to keep hardcoded switch cases for provider detection logic in src/lib/logger/vercel/utils.ts rather than making it case-insensitive or removing redundant checks, indicating a preference for explicit provider mapping over normalized/optimized detection logic.
Learnt from: danpiths
PR: maximhq/maxim-js#16
File: src/lib/logger/components/session.ts:129-132
Timestamp: 2025年06月28日T20:29:27.139Z
Learning: In the maxim-js codebase, danpiths is okay with the trace_() method in src/lib/logger/components/session.ts mutating the caller-supplied config object (config.sessionId = id) for now, preferring to defer this non-critical improvement to maintain focus on the current PR's main objectives.
Learnt from: danpiths
PR: maximhq/maxim-js#2
File: src/lib/logger/langchain/utils.ts:71-83
Timestamp: 2025年06月16日T12:36:38.940Z
Learning: In the maximhq/maxim-js repository, variable shadowing (like `const provider` being redeclared in inner scopes) is acceptable and not considered an issue by the maintainer danpiths.
Learnt from: danpiths
PR: maximhq/maxim-js#2
File: src/lib/logger/langchain/tracer.ts:100-104
Timestamp: 2025年06月16日T12:35:36.606Z
Learning: In the MaximLangchainTracer class in src/lib/logger/langchain/tracer.ts, danpiths prefers to keep the current implementation that JSON.stringify-s all metadata entries into tags, even though it could potentially create oversized tags. The preference is to defer optimization until it becomes a demonstrated problem rather than preemptively fixing it.
Learnt from: danpiths
PR: maximhq/maxim-js#16
File: src/lib/logger/components/retrieval.ts:113-118
Timestamp: 2025年06月28日T20:31:28.233Z
Learning: In the maxim-js codebase, danpiths is comfortable with small amounts of duplicate logic (like 3-4 lines of simple string-to-array normalization) when the duplication is minimal and not complex, preferring to keep things simple rather than extracting tiny utilities for minor code deduplication.
Learnt from: danpiths
PR: maximhq/maxim-js#2
File: package.json:38-40
Timestamp: 2025年06月16日T05:35:50.998Z
Learning: In the maxim-js library, @langchain/core is correctly placed in optionalDependencies because it's only required when using MaximLangchainTracer functionality. Users who don't need LangChain integration can use the library without installing @langchain/core, keeping the installation lightweight.
Learnt from: danpiths
PR: maximhq/maxim-js#2
File: package.json:15-33
Timestamp: 2025年06月16日T05:36:54.415Z
Learning: The LangChain packages in maxim-js are intentionally kept as optional/dev dependencies rather than regular dependencies. This design choice ensures that users who don't need MaximLangchainTracer functionality can use the library without installing heavy LangChain packages, keeping the installation lightweight.
Learnt from: danpiths
PR: maximhq/maxim-js#17
File: scripts/generate-mintlify-nav.js:75-175
Timestamp: 2025年06月29日T06:44:39.669Z
Learning: In the maxim-js project, danpiths is comfortable with code duplication in documentation generation scripts since they are internal tools not shipped to users, preferring to defer refactoring for better maintainability to later iterations when the scripts are not critical to core functionality.
src/lib/logger/together/utils.ts (6)
Learnt from: SamstyleGhost
PR: maximhq/maxim-js#18
File: src/lib/logger/vercel/wrapper.ts:212-212
Timestamp: 2025年06月25日T05:20:43.227Z
Learning: In `src/lib/logger/vercel/wrapper.ts`, the `processStream` function expects the model ID string as a parameter, not the provider name. When calling `processStream(chunks, span, trace, generation, model, maximMetadata)`, use `this.modelId` instead of `modelProvider` to pass the correct model identifier.
Learnt from: SamstyleGhost
PR: maximhq/maxim-js#18
File: src/lib/logger/vercel/utils.ts:241-241
Timestamp: 2025年06月26日T13:58:22.625Z
Learning: In src/lib/logger/vercel/utils.ts:241, the convertDoGenerateResultToChatCompletionResult function parameter uses `DoGenerateResultLike & { [key: string]: any }` intersection type intentionally because the AI SDK has additional properties that aren't exported in their type definitions. Rewriting it completely wouldn't make sense, so the intersection type provides access to these runtime properties.
Learnt from: danpiths
PR: maximhq/maxim-js#2
File: src/lib/logger/langchain/tracer.ts:100-104
Timestamp: 2025年06月16日T12:35:36.606Z
Learning: In the MaximLangchainTracer class in src/lib/logger/langchain/tracer.ts, danpiths prefers to keep the current implementation that JSON.stringify-s all metadata entries into tags, even though it could potentially create oversized tags. The preference is to defer optimization until it becomes a demonstrated problem rather than preemptively fixing it.
Learnt from: danpiths
PR: maximhq/maxim-js#16
File: src/lib/logger/components/session.ts:129-132
Timestamp: 2025年06月28日T20:29:27.139Z
Learning: In the maxim-js codebase, danpiths is okay with the trace_() method in src/lib/logger/components/session.ts mutating the caller-supplied config object (config.sessionId = id) for now, preferring to defer this non-critical improvement to maintain focus on the current PR's main objectives.
Learnt from: danpiths
PR: maximhq/maxim-js#2
File: src/lib/logger/components/generation.ts:213-217
Timestamp: 2025年06月16日T12:31:06.643Z
Learning: In src/lib/logger/components/generation.ts, the parseAttachmentsFromMessages function contains a `typeof item === "string"` check that appears unreachable due to TypeScript typing (item is typed as CompletionRequestContent), but this is intentionally kept as-is for now as accepted technical debt.
Learnt from: danpiths
PR: maximhq/maxim-js#17
File: scripts/fix-links.js:55-58
Timestamp: 2025年06月29日T06:42:21.189Z
Learning: In the maxim-js project, the documentation generation scripts (like scripts/fix-links.js) are run manually and locally, not in CI environments. Therefore, detailed console.log output is acceptable and beneficial for debugging during local documentation builds.
package.json (2)
Learnt from: danpiths
PR: maximhq/maxim-js#15
File: scripts/clean-package.js:22-24
Timestamp: 2025年06月28日T20:20:10.582Z
Learning: In the maximhq/maxim-js project, the clean-package script (scripts/clean-package.js) runs as a post-build step after the TypeScript build process, which means the dist directory is guaranteed to exist when the script executes. Therefore, no directory existence check is needed before writing to dist/package.json.
Learnt from: SamstyleGhost
PR: maximhq/maxim-js#18
File: src/lib/logger/vercel/utils.ts:241-241
Timestamp: 2025年06月26日T13:58:22.625Z
Learning: In src/lib/logger/vercel/utils.ts:241, the convertDoGenerateResultToChatCompletionResult function parameter uses `DoGenerateResultLike & { [key: string]: any }` intersection type intentionally because the AI SDK has additional properties that aren't exported in their type definitions. Rewriting it completely wouldn't make sense, so the intersection type provides access to these runtime properties.
src/lib/logger/together/togetherLogger.test.ts (12)
Learnt from: danpiths
PR: maximhq/maxim-js#2
File: jest.config.js:10-12
Timestamp: 2025年06月15日T09:30:55.364Z
Learning: In the maximhq/maxim-js project, the explicit transform configuration in jest.config.js is required for Jest to work properly, even though the ts-jest preset is being used. The transform block should not be removed as it's needed for the project's specific setup.
Learnt from: danpiths
PR: maximhq/maxim-js#16
File: src/lib/logger/components/session.ts:129-132
Timestamp: 2025年06月28日T20:29:27.139Z
Learning: In the maxim-js codebase, danpiths is okay with the trace_() method in src/lib/logger/components/session.ts mutating the caller-supplied config object (config.sessionId = id) for now, preferring to defer this non-critical improvement to maintain focus on the current PR's main objectives.
Learnt from: danpiths
PR: maximhq/maxim-js#17
File: scripts/fix-links.js:55-58
Timestamp: 2025年06月29日T06:42:21.189Z
Learning: In the maxim-js project, the documentation generation scripts (like scripts/fix-links.js) are run manually and locally, not in CI environments. Therefore, detailed console.log output is acceptable and beneficial for debugging during local documentation builds.
Learnt from: danpiths
PR: maximhq/maxim-js#2
File: src/lib/logger/langchain/tracer.ts:100-104
Timestamp: 2025年06月16日T12:35:36.606Z
Learning: In the MaximLangchainTracer class in src/lib/logger/langchain/tracer.ts, danpiths prefers to keep the current implementation that JSON.stringify-s all metadata entries into tags, even though it could potentially create oversized tags. The preference is to defer optimization until it becomes a demonstrated problem rather than preemptively fixing it.
Learnt from: SamstyleGhost
PR: maximhq/maxim-js#18
File: src/lib/logger/vercel/utils.ts:241-241
Timestamp: 2025年06月26日T13:58:22.625Z
Learning: In src/lib/logger/vercel/utils.ts:241, the convertDoGenerateResultToChatCompletionResult function parameter uses `DoGenerateResultLike & { [key: string]: any }` intersection type intentionally because the AI SDK has additional properties that aren't exported in their type definitions. Rewriting it completely wouldn't make sense, so the intersection type provides access to these runtime properties.
Learnt from: danpiths
PR: maximhq/maxim-js#16
File: src/lib/evaluators/evaluators.ts:84-95
Timestamp: 2025年06月28日T20:35:58.071Z
Learning: In the maxim-js codebase, evaluator name uniqueness is enforced in the test run builder's .run() method rather than during individual evaluator creation with createCustomEvaluator() or createCustomCombinedEvaluatorsFor(). This represents a deliberate architectural decision for proper separation of concerns.
Learnt from: danpiths
PR: maximhq/maxim-js#20
File: src/lib/logger/vercel/utils.ts:23-35
Timestamp: 2025年06月29日T07:57:14.446Z
Learning: In the maxim-js codebase, danpiths prefers to keep hardcoded switch cases for provider detection logic in src/lib/logger/vercel/utils.ts rather than making it case-insensitive or removing redundant checks, indicating a preference for explicit provider mapping over normalized/optimized detection logic.
Learnt from: danpiths
PR: maximhq/maxim-js#2
File: src/lib/logger/components/generation.ts:213-217
Timestamp: 2025年06月16日T12:31:06.643Z
Learning: In src/lib/logger/components/generation.ts, the parseAttachmentsFromMessages function contains a `typeof item === "string"` check that appears unreachable due to TypeScript typing (item is typed as CompletionRequestContent), but this is intentionally kept as-is for now as accepted technical debt.
Learnt from: danpiths
PR: maximhq/maxim-js#17
File: scripts/generate-mintlify-nav.js:185-188
Timestamp: 2025年06月29日T06:45:30.100Z
Learning: In the maxim-js project, danpiths prefers fail-fast behavior over graceful error handling in documentation generation scripts (like scripts/generate-mintlify-nav.js). Since these scripts are used locally for SDK documentation generation and not in production systems, immediate failure provides better visibility when issues occur rather than silent failures or graceful degradation.
Learnt from: danpiths
PR: maximhq/maxim-js#17
File: scripts/rename-files.js:19-44
Timestamp: 2025年06月29日T06:40:49.140Z
Learning: In the maxim-js project, danpiths accepts a reactive approach to error handling in documentation generation scripts, preferring to fix issues if and when they occur rather than adding proactive error handling, since documentation generation failures are immediately visible and the scripts are not critical to core functionality.
Learnt from: danpiths
PR: maximhq/maxim-js#16
File: src/lib/logger/components/base.ts:94-96
Timestamp: 2025年06月28日T20:33:39.066Z
Learning: In the maxim-js codebase, danpiths prefers to defer non-critical fixes (like in-memory state synchronization issues) when there are plans to refactor or remove the affected code later, especially when the impacted functionality isn't widely used by consumers.
Learnt from: danpiths
PR: maximhq/maxim-js#17
File: scripts/generate-mintlify-nav.js:75-175
Timestamp: 2025年06月29日T06:44:39.669Z
Learning: In the maxim-js project, danpiths is comfortable with code duplication in documentation generation scripts since they are internal tools not shipped to users, preferring to defer refactoring for better maintainability to later iterations when the scripts are not critical to core functionality.
src/lib/logger/together/wrapper.ts (6)
Learnt from: danpiths
PR: maximhq/maxim-js#16
File: src/lib/logger/components/session.ts:129-132
Timestamp: 2025年06月28日T20:29:27.139Z
Learning: In the maxim-js codebase, danpiths is okay with the trace_() method in src/lib/logger/components/session.ts mutating the caller-supplied config object (config.sessionId = id) for now, preferring to defer this non-critical improvement to maintain focus on the current PR's main objectives.
Learnt from: danpiths
PR: maximhq/maxim-js#2
File: src/lib/logger/langchain/tracer.ts:100-104
Timestamp: 2025年06月16日T12:35:36.606Z
Learning: In the MaximLangchainTracer class in src/lib/logger/langchain/tracer.ts, danpiths prefers to keep the current implementation that JSON.stringify-s all metadata entries into tags, even though it could potentially create oversized tags. The preference is to defer optimization until it becomes a demonstrated problem rather than preemptively fixing it.
Learnt from: SamstyleGhost
PR: maximhq/maxim-js#18
File: src/lib/logger/vercel/wrapper.ts:212-212
Timestamp: 2025年06月25日T05:20:43.227Z
Learning: In `src/lib/logger/vercel/wrapper.ts`, the `processStream` function expects the model ID string as a parameter, not the provider name. When calling `processStream(chunks, span, trace, generation, model, maximMetadata)`, use `this.modelId` instead of `modelProvider` to pass the correct model identifier.
Learnt from: danpiths
PR: maximhq/maxim-js#20
File: src/lib/logger/vercel/utils.ts:23-35
Timestamp: 2025年06月29日T07:57:14.446Z
Learning: In the maxim-js codebase, danpiths prefers to keep hardcoded switch cases for provider detection logic in src/lib/logger/vercel/utils.ts rather than making it case-insensitive or removing redundant checks, indicating a preference for explicit provider mapping over normalized/optimized detection logic.
Learnt from: SamstyleGhost
PR: maximhq/maxim-js#18
File: src/lib/logger/vercel/utils.ts:241-241
Timestamp: 2025年06月26日T13:58:22.625Z
Learning: In src/lib/logger/vercel/utils.ts:241, the convertDoGenerateResultToChatCompletionResult function parameter uses `DoGenerateResultLike & { [key: string]: any }` intersection type intentionally because the AI SDK has additional properties that aren't exported in their type definitions. Rewriting it completely wouldn't make sense, so the intersection type provides access to these runtime properties.
Learnt from: danpiths
PR: maximhq/maxim-js#12
File: src/lib/models/containers.ts:375-381
Timestamp: 2025年06月16日T17:16:34.987Z
Learning: In the maxim-js codebase, the sessionId parameter should only be added to TraceContainer.create() method, not to the abstract Container.create() signature, because only traces need session tracking functionality, not spans or other container types.
🪛 Biome (1.9.4)
src/lib/logger/together/utils.ts
[error] 15-15: This let declares a variable that is only assigned once.
'chunks' is never reassigned.
Safe fix: Use const instead.
(lint/style/useConst)
[error] 16-16: This let declares a variable that is only assigned once.
'result' is never reassigned.
Safe fix: Use const instead.
(lint/style/useConst)
🔇 Additional comments (2)
together-ai-sdk.ts (1)
1-2: LGTM! Clean SDK entry point.The re-export pattern properly exposes the public API while keeping implementation details internal.
package.json (1)
92-95: Verify dependency placement aligns with project philosophy.The new
groq-sdkandtogether-aipackages are added as regular dependencies. Based on the project's established pattern, consider whether these should be optional dependencies instead to maintain the lightweight installation approach used for LangChain packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Use const for variables that are never reassigned.
Both chunks and result are never reassigned after initialization.
- let chunks: any[] = []; - let result = { + const chunks: any[] = []; + const result = { text: "", usage: { prompt_tokens: 0, completion_tokens: 0 }, finishReason: "stop", };
📝 Committable suggestion
!!️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
🧰 Tools
🪛 Biome (1.9.4)
[error] 15-15: This let declares a variable that is only assigned once.
'chunks' is never reassigned.
Safe fix: Use const instead.
(lint/style/useConst)
[error] 16-16: This let declares a variable that is only assigned once.
'result' is never reassigned.
Safe fix: Use const instead.
(lint/style/useConst)
🤖 Prompt for AI Agents
In src/lib/logger/together/utils.ts between lines 15 and 20, change the
declarations of the variables `chunks` and `result` from `let` to `const` since
they are never reassigned after initialization. This involves replacing `let`
with `const` for both variables to reflect their immutability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enable tests to ensure proper coverage.
All test cases are commented out, providing no test coverage for the new Together AI integration. Either enable these tests or properly skip them with test.skip() and a reason if they're not ready.
🤖 Prompt for AI Agents
In src/lib/logger/together/togetherLogger.test.ts between lines 33 and 398, all
test cases are currently commented out, resulting in no test coverage for the
Together AI integration. To fix this, uncomment the test cases to enable them
for execution. If some tests are not ready to run, replace the commented-out
tests with test.skip() calls including a reason for skipping, ensuring proper
test coverage and clarity on test status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add proper TypeScript types instead of using any.
The options parameter should be properly typed using Together.ai SDK types.
- create: async (options: any) => { + create: async (options: Parameters<typeof target.chat.completions.create>[0]) => {
- stream: (options: any) => { + stream: (options: Parameters<typeof target.chat.completions.stream>[0]) => {
- create: async (options: any) => { + create: async (options: Parameters<typeof target.images.create>[0]) => {
Also applies to: 109-109, 174-174
🤖 Prompt for AI Agents
In src/lib/logger/together/wrapper.ts at lines 51, 109, and 174, the parameter
'options' is currently typed as 'any', which lacks type safety. Replace 'any'
with the appropriate type from the Together.ai SDK that defines the structure of
the options parameter. Import the necessary types from the SDK if not already
imported, and apply them to the 'options' parameter in the create functions to
ensure proper TypeScript typing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Extract duplicated trace creation logic into a helper function.
The trace creation logic is duplicated across three methods. This violates DRY principles.
Create a helper function to eliminate duplication:
function createTrace( logger: MaximLogger, maximMetadata: MaximTogetherProviderMetadata | undefined, defaultName: string ): Trace { if (maximMetadata?.traceId) { return logger.trace({ id: maximMetadata.traceId, name: maximMetadata?.traceName ?? defaultName, tags: maximMetadata?.traceTags }); } else if (maximMetadata?.sessionId) { const session = logger.session({ id: maximMetadata.sessionId, name: maximMetadata?.sessionName ?? "default-session", tags: maximMetadata?.sessionTags }); return session.trace({ id: uuid(), name: maximMetadata?.traceName ?? defaultName, tags: maximMetadata?.traceTags }); } else { return logger.trace({ id: uuid(), name: maximMetadata?.traceName ?? defaultName, tags: maximMetadata?.traceTags }); } }
Then replace the duplicated code with:
const trace = createTrace(logger, maximMetadata, "together-completion");
Also applies to: 117-141, 182-206
🤖 Prompt for AI Agents
In src/lib/logger/together/wrapper.ts around lines 59 to 83, 117 to 141, and 182
to 206, the trace creation logic is duplicated in three places, violating DRY
principles. To fix this, create a helper function named createTrace that takes
logger, maximMetadata, and a defaultName string as parameters and encapsulates
the existing conditional trace creation logic. Then replace each duplicated
block with a call to this helper function, passing the appropriate arguments, to
centralize and simplify the trace creation code.
No description provided.