-
Notifications
You must be signed in to change notification settings - Fork 242
feat: add OpenCode integration support #116
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
Open
D36u99er
wants to merge
1
commit into
slopus:main
Choose a base branch
from
D36u99er:feature/opencode-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,453
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export { runOpenCode } from './runOpenCode'; | ||
| export { OpenCodeClient } from './openCodeClient'; | ||
| export { OpenCodePermissionHandler } from './utils/permissionHandler'; | ||
| export * from './types'; | ||
| export * from './messageMapper'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import { randomUUID } from 'node:crypto'; | ||
| import type { | ||
| OpenCodeMessageInfo, | ||
| OpenCodeMessagePart, | ||
| OpenCodeMessage, | ||
| OpenCodeTodo | ||
| } from './types'; | ||
|
|
||
| export interface HappyMessage { | ||
| type: string; | ||
| id: string; | ||
| [key: string]: unknown; | ||
| } | ||
|
|
||
| export interface HappyToolCall extends HappyMessage { | ||
| type: 'tool-call'; | ||
| name: string; | ||
| callId: string; | ||
| input: Record<string, unknown>; | ||
| } | ||
|
|
||
| export interface HappyToolResult extends HappyMessage { | ||
| type: 'tool-call-result'; | ||
| callId: string; | ||
| output: unknown; | ||
| } | ||
|
|
||
| export interface HappyTextMessage extends HappyMessage { | ||
| type: 'message'; | ||
| message: string; | ||
| } | ||
|
|
||
| export interface HappyReasoningMessage extends HappyMessage { | ||
| type: 'reasoning'; | ||
| text: string; | ||
| } | ||
|
|
||
| export interface HappyTodoMessage extends HappyMessage { | ||
| type: 'todo'; | ||
| todos: Array<{ | ||
| id: string; | ||
| content: string; | ||
| status: string; | ||
| priority?: string; | ||
| }>; | ||
| } | ||
|
|
||
| export function mapOpenCodePartToHappyMessage(part: OpenCodeMessagePart): HappyMessage | null { | ||
| switch (part.type) { | ||
| case 'text': | ||
| if (!part.text) return null; | ||
| return { | ||
| type: 'message', | ||
| id: part.id, | ||
| message: part.text | ||
| } as HappyTextMessage; | ||
|
|
||
| case 'tool-invocation': | ||
| if (!part.toolInvocation) return null; | ||
| const inv = part.toolInvocation; | ||
|
|
||
| if (inv.state === 'pending' || inv.state === 'running') { | ||
| return { | ||
| type: 'tool-call', | ||
| id: part.id, | ||
| name: inv.toolName, | ||
| callId: inv.toolCallID, | ||
| input: inv.args || {}, | ||
| metadata: inv.metadata | ||
| } as HappyToolCall; | ||
| } | ||
|
|
||
| if (inv.state === 'completed' || inv.state === 'failed') { | ||
| return { | ||
| type: 'tool-call-result', | ||
| id: part.id, | ||
| callId: inv.toolCallID, | ||
| output: inv.error ? { error: inv.error } : inv.result, | ||
| success: inv.state === 'completed' | ||
| } as HappyToolResult; | ||
| } | ||
| return null; | ||
|
|
||
| case 'reasoning': | ||
| if (!part.text) return null; | ||
| return { | ||
| type: 'reasoning', | ||
| id: part.id, | ||
| text: part.text | ||
| } as HappyReasoningMessage; | ||
|
|
||
| case 'step-start': | ||
| return { | ||
| type: 'step-start', | ||
| id: part.id, | ||
| text: part.text || '' | ||
| }; | ||
|
|
||
| case 'file': | ||
| if (!part.file) return null; | ||
| return { | ||
| type: 'file', | ||
| id: part.id, | ||
| path: part.file.path, | ||
| content: part.file.content | ||
| }; | ||
|
|
||
| default: | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export function mapOpenCodeTodosToHappyMessage(todos: OpenCodeTodo[]): HappyTodoMessage { | ||
| return { | ||
| type: 'todo', | ||
| id: randomUUID(), | ||
| todos: todos.map(t => ({ | ||
| id: t.id, | ||
| content: t.content, | ||
| status: t.status, | ||
| priority: t.priority | ||
| })) | ||
| }; | ||
| } | ||
|
|
||
| export function mapOpenCodeMessageInfoToStatus(info: OpenCodeMessageInfo): HappyMessage { | ||
| const hasError = !!info.error; | ||
| const isComplete = !!info.time.completed; | ||
|
|
||
| return { | ||
| type: 'message-status', | ||
| id: info.id, | ||
| messageId: info.id, | ||
| sessionId: info.sessionID, | ||
| role: info.role, | ||
| status: hasError ? 'error' : (isComplete ? 'complete' : 'in-progress'), | ||
| error: info.error, | ||
| tokens: info.tokens, | ||
| cost: info.cost, | ||
| model: info.modelID, | ||
| provider: info.providerID | ||
| }; | ||
| } | ||
|
|
||
| export function createHappyEventFromOpenCodePart( | ||
| part: OpenCodeMessagePart, | ||
| info?: OpenCodeMessageInfo | ||
| ): HappyMessage | null { | ||
| const message = mapOpenCodePartToHappyMessage(part); | ||
| if (!message) return null; | ||
|
|
||
| if (info) { | ||
| message.role = info.role; | ||
| message.model = info.modelID; | ||
| message.provider = info.providerID; | ||
| } | ||
|
|
||
| return message; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Missing Message Part Types, OpenCode has more message part types not handled: