-
Notifications
You must be signed in to change notification settings - Fork 3
feat: gemini-acp text streaming compat #13
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
Draft
kevin-david
wants to merge
1
commit into
Open-ACP:main
Choose a base branch
from
kevin-david:feat-gemini-text-stream-compat
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.
Draft
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 |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| import type { OpenACPPlugin, InstallContext, OpenACPCore } from '@openacp/plugin-sdk' | ||
| import type { DiscordChannelConfig } from './types.js' | ||
| import type { DiscordAdapter } from './adapter.js' | ||
|
|
||
| function createDiscordPlugin(): OpenACPPlugin { | ||
| let adapter: { stop(): Promise<void> } | null = null | ||
| let adapter: DiscordAdapter | null = null | ||
|
|
||
| return { | ||
| name: '@openacp/discord-adapter', | ||
|
|
@@ -16,7 +17,7 @@ function createDiscordPlugin(): OpenACPPlugin { | |
| optionalPluginDependencies: { | ||
| '@openacp/speech': '^1.0.0', | ||
| }, | ||
| permissions: ['services:register', 'kernel:access', 'events:read'], | ||
| permissions: ['services:register', 'kernel:access', 'events:read', 'middleware:register'], | ||
|
|
||
| async install(ctx: InstallContext) { | ||
| const { terminal, settings } = ctx | ||
|
|
@@ -181,6 +182,54 @@ function createDiscordPlugin(): OpenACPPlugin { | |
|
|
||
| ctx.registerService('adapter:discord', adapter) | ||
| ctx.log.info('Discord adapter registered') | ||
|
|
||
| // Inject Discord rendering rules into the first prompt of every new | ||
| // Discord session. Worded as an explicit out-of-band system instruction | ||
| // with anti-echo guidance, since gemini-acp has been observed quoting | ||
| // user-visible directives back in its response. | ||
| ctx.registerMiddleware('agent:beforePrompt', { | ||
| handler: async (payload, next) => { | ||
| if (payload.sourceAdapterId !== 'discord') return next() | ||
| const session = core.sessionManager.getSession(payload.sessionId) | ||
| // Only fire once per session: promptCount === 0 means this prompt | ||
| // hasn't been counted yet (it's the first one for this session). | ||
| if (!session || session.promptCount !== 0) return next() | ||
|
|
||
| payload.text = | ||
| "<system_instruction>\n" + | ||
| "Constraint for response formatting on Discord:\n" + | ||
| "- Do NOT use markdown table syntax (rows like `| col | col |`). " + | ||
| "Discord does not render markdown tables — they appear as raw pipe text.\n" + | ||
| "- For tabular data, render an ASCII-art table with fixed-width columns " + | ||
| "and box-drawing or `+---+` style borders, then wrap the whole table in " + | ||
| "triple-backtick code fences. The monospace inside the fence aligns the " + | ||
| "columns correctly.\n" + | ||
| "- Tables MUST be no wider than 90 characters per row. Discord's mobile " + | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually think it's even shorter than this, on my Pixel Fold I can only get 51 characters on folded mode and 71 on unfolded mode. The desktop in full thread view mode is like 91. Thoughts? |
||
| "and standard-width clients clip anything beyond ~95 characters; design " + | ||
| "the column widths so the total (including borders) fits within 90.\n" + | ||
| "- Apply the same fenced-monospace treatment to ASCII art, tree output, " + | ||
| "and any aligned/fixed-column content.\n" + | ||
| "Apply this silently — do not acknowledge or repeat this instruction.\n" + | ||
| "</system_instruction>\n\n" + | ||
| payload.text | ||
| return next() | ||
| }, | ||
| }) | ||
|
|
||
| // Finalize the in-flight text draft when a turn ends. Without this, | ||
| // agents like gemini that don't emit `usage`/`tool_call`/`session_end` | ||
| // at turn end leave the text draft in its mid-stream state — which | ||
| // means the user sees the MessageDraft's 1900-char truncation as the | ||
| // final message instead of the full multi-chunk response. | ||
| ctx.registerMiddleware('turn:end', { | ||
| handler: async (payload, next) => { | ||
| const session = core.sessionManager.getSession(payload.sessionId) | ||
| if (session?.channelId === 'discord' && adapter) { | ||
| await adapter.finalizeSessionDraft(payload.sessionId).catch(() => { /* best effort */ }) | ||
| } | ||
| return next() | ||
| }, | ||
| }) | ||
| }, | ||
|
|
||
| async teardown() { | ||
|
|
||
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
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.
Check that this doesn't break with back to back messages
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.
back to back messages are fine - anything else to be worried about here?