-
Notifications
You must be signed in to change notification settings - Fork 46
[WIP] add agent run controllers #380
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
RaoHai
wants to merge
17
commits into
eggjs:master
Choose a base branch
from
RaoHai:feat/impl-run-controllers
base: master
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.
Open
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3593562
[WIP] add agent run controllers
8748399
[WIP]feat: impl runs/stream
RaoHai 454b421
[WIP] hoist independ testcase
RaoHai d43e829
[WIP] hoist independ testcase
RaoHai e511bfd
[WIP] hoist independ testcase
RaoHai 10c518e
feat: sse-utils and test case
RaoHai 713f838
feat: sse-utils and test case
RaoHai 95a01a3
feat: sse-utils and test case
RaoHai 65cc05c
feat: impl moduleConfigs
RaoHai edf1036
feat: impl iterator of moduleConfigs
RaoHai 8897827
feat: impl iterator of moduleConfigs
RaoHai 17e9ba4
fix: use yield Object.entries(this.inner);
RaoHai 157d5b2
fix: eslint
RaoHai 2538bc5
feat: merge moduleconfigs iterator
RaoHai 7eb07b6
feat: add assistants api endpoints
RaoHai 31aa571
feat: add assistants api endpoints
RaoHai 5554d8f
feat: add assistants api endpoints
RaoHai 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ run | |
| .DS_Store | ||
| .tmp | ||
| .vscode | ||
| .claude | ||
|
|
||
| package-lock.json | ||
| yarn.lock | ||
|
|
||
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,96 @@ | ||
| import { | ||
| HTTPController, | ||
| HTTPMethod, | ||
| HTTPMethodEnum, | ||
| HTTPBody, | ||
| Context, | ||
| } from '@eggjs/tegg'; | ||
| import type { EggContext } from '@eggjs/tegg'; | ||
| import type { RunCreateDTO } from './types'; | ||
| import { streamSSE } from './sse-utils'; | ||
|
|
||
| /** | ||
| * LangGraph Runs Controller | ||
| * 处理 Run 相关的 HTTP 请求 | ||
| */ | ||
| @HTTPController({ | ||
| path: '/api', | ||
| }) | ||
| export class RunsController { | ||
| /** | ||
| * POST /api/runs/stream | ||
| * 流式创建无状态 Run (SSE) | ||
| */ | ||
| @HTTPMethod({ | ||
| method: HTTPMethodEnum.POST, | ||
| path: '/runs/stream', | ||
| }) | ||
| async streamStatelessRun(@HTTPBody() _payload: RunCreateDTO, @Context() ctx: EggContext) { | ||
| // TODO: 验证 payload | ||
| // const validated = RunCreate.parse(payload); | ||
|
|
||
| // TODO: 创建 run | ||
| // const run = await this.createValidRun(undefined, payload); | ||
| const mockRunId = 'mock-run-id'; // 临时 mock | ||
|
|
||
| // TODO: 设置 Content-Location header | ||
| ctx.set('Content-Location', `/runs/${mockRunId}`); | ||
|
|
||
| // 实现 SSE 流式响应 | ||
| await streamSSE(ctx, async (stream) => { | ||
| // TODO: 获取 cancelOnDisconnect signal | ||
| // const cancelOnDisconnect = payload.on_disconnect === 'cancel' | ||
| // ? getDisconnectAbortSignal(ctx) | ||
| // : undefined; | ||
|
|
||
| try { | ||
| // TODO: 加入 run stream | ||
| // for await (const { event, data } of runsService.stream.join( | ||
| // mockRunId, | ||
| // undefined, | ||
| // { cancelOnDisconnect, lastEventId: run.kwargs.resumable ? '-1' : undefined, ignore404: true }, | ||
| // auth | ||
| // )) { | ||
| // await stream.writeSSE({ event, data: serialiseAsDict(data) }); | ||
| // } | ||
|
|
||
| // 临时发送一个测试事件 | ||
| await stream.writeSSE({ | ||
| event: 'metadata', | ||
| data: { message: 'SSE stream endpoint created (not implemented yet)' }, | ||
| }); | ||
| } catch (error) { | ||
| // 错误处理 | ||
| console.error('Error streaming run:', error); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // /** | ||
| // * 创建有效的 Run 实例 | ||
| // * 从 runs.mts 的 createValidRun 函数迁移而来 | ||
| // * | ||
| // * @param _threadId - 线程 ID (可选,无状态 run 传 undefined) | ||
| // * @param _payload - Run 创建参数 | ||
| // * @returns Run 实例 | ||
| // */ | ||
| // private async createValidRun( | ||
| // _threadId: string | undefined, | ||
| // _payload: RunCreateDTO | ||
| // ) { | ||
| // // TODO: 实现 createValidRun 逻辑 | ||
| // // 1. 生成 runId (uuid) | ||
| // // 2. 处理 stream_mode (默认 "values") | ||
| // // 3. 处理 multitask_strategy (默认 "reject") | ||
| // // 4. 构建 config 对象 | ||
| // // 5. 处理 checkpoint_id/checkpoint | ||
| // // 6. 处理 langsmith_tracer | ||
| // // 7. 处理 headers (x-* 和 user-agent) | ||
| // // 8. 处理 auth 信息 | ||
| // // 9. 处理 feedback_keys | ||
| // // 10. 调用 runs service 创建运行 | ||
| // // 11. 处理 multitask 策略 (interrupt/rollback) | ||
|
|
||
| // throw new Error('createValidRun not implemented yet'); | ||
| // } | ||
| } | ||
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.
建议使用
ctx.logger.error代替console.error来记录错误。这样可以利用应用统一的日志配置,方便后续的日志收集和分析。