Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yaoai-video
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
姚珂
yaoai-video
Commits
d0522a83
Commit
d0522a83
authored
Apr 28, 2026
by
yaoke.yk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Agent制作优化上下文错误
parent
3aa33f49
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
21 deletions
+58
-21
AgentRunServiceImpl.java
...ava/com/yaoai/agent/service/impl/AgentRunServiceImpl.java
+8
-2
UserContext.java
...n/src/main/java/com/yaoai/common/context/UserContext.java
+28
-0
AssetGenPipelineServiceImpl.java
...ai/pipeline/service/impl/AssetGenPipelineServiceImpl.java
+9
-9
OutlinePipelineServiceImpl.java
...oai/pipeline/service/impl/OutlinePipelineServiceImpl.java
+5
-5
StoryboardPipelineServiceImpl.java
.../pipeline/service/impl/StoryboardPipelineServiceImpl.java
+5
-5
SaTokenConfigure.java
...main/java/com/yaoai/security/config/SaTokenConfigure.java
+3
-0
No files found.
yaoai-comic-studio/yaoai-agent/src/main/java/com/yaoai/agent/service/impl/AgentRunServiceImpl.java
View file @
d0522a83
package
com
.
yaoai
.
agent
.
service
.
impl
;
import
cn.dev33.satoken.stp.StpUtil
;
import
com.yaoai.agent.service.AgentRunService
;
import
com.yaoai.agent.sse.AgentSseManager
;
import
com.yaoai.ai.core.model.ChatMessage
;
import
com.yaoai.ai.core.model.ChatRequest
;
import
com.yaoai.ai.core.service.LlmService
;
import
com.yaoai.common.context.UserContext
;
import
com.yaoai.common.exception.BizException
;
import
com.yaoai.common.exception.ErrorCode
;
import
com.yaoai.domain.entity.Episode
;
...
...
@@ -66,6 +68,7 @@ public class AgentRunServiceImpl implements AgentRunService {
@Override
public
GraphRun
startRun
(
Long
projectId
,
Long
tenantId
,
String
goal
)
{
Long
userId
=
StpUtil
.
getLoginIdAsLong
();
GraphRun
run
=
new
GraphRun
();
run
.
setProjectId
(
projectId
);
run
.
setTenantId
(
tenantId
);
...
...
@@ -86,7 +89,7 @@ public class AgentRunServiceImpl implements AgentRunService {
}
Long
runId
=
run
.
getId
();
agentExecutor
.
execute
(()
->
executeRun
(
runId
,
projectId
,
tenantId
,
goal
));
agentExecutor
.
execute
(()
->
executeRun
(
runId
,
projectId
,
tenantId
,
userId
,
goal
));
return
run
;
}
...
...
@@ -123,8 +126,9 @@ public class AgentRunServiceImpl implements AgentRunService {
// ─── Async Executor ────────────────────────────────────────────────────────
private
void
executeRun
(
Long
runId
,
Long
projectId
,
Long
tenantId
,
String
goal
)
{
private
void
executeRun
(
Long
runId
,
Long
projectId
,
Long
tenantId
,
Long
userId
,
String
goal
)
{
log
.
info
(
"Agent run started: runId={}, projectId={}"
,
runId
,
projectId
);
UserContext
.
set
(
userId
);
try
{
// Step 1: Decision
executeStep
(
runId
,
"decision"
,
()
->
{
...
...
@@ -210,6 +214,8 @@ public class AgentRunServiceImpl implements AgentRunService {
log
.
error
(
"Agent run failed: runId={}"
,
runId
,
e
);
updateRunStatus
(
runId
,
"FAILED"
);
sseManager
.
emit
(
runId
,
"run.failed"
,
Map
.
of
(
"error"
,
e
.
getMessage
()));
}
finally
{
UserContext
.
clear
();
}
}
...
...
yaoai-comic-studio/yaoai-common/src/main/java/com/yaoai/common/context/UserContext.java
0 → 100644
View file @
d0522a83
package
com
.
yaoai
.
common
.
context
;
public
final
class
UserContext
{
private
static
final
ThreadLocal
<
Long
>
USER_ID
=
new
ThreadLocal
<>();
private
UserContext
()
{}
public
static
void
set
(
Long
userId
)
{
USER_ID
.
set
(
userId
);
}
public
static
Long
get
()
{
return
USER_ID
.
get
();
}
public
static
Long
require
()
{
Long
userId
=
USER_ID
.
get
();
if
(
userId
==
null
)
{
throw
new
IllegalStateException
(
"当前线程缺少用户上下文"
);
}
return
userId
;
}
public
static
void
clear
()
{
USER_ID
.
remove
();
}
}
yaoai-comic-studio/yaoai-pipeline/src/main/java/com/yaoai/pipeline/service/impl/AssetGenPipelineServiceImpl.java
View file @
d0522a83
package
com
.
yaoai
.
pipeline
.
service
.
impl
;
import
cn.dev33.satoken.stp.StpUtil
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.yaoai.ai.core.model.ChatMessage
;
...
...
@@ -9,6 +8,7 @@ import com.yaoai.ai.core.service.LlmService;
import
com.yaoai.ai.providers.service.SeedreamService
;
import
com.yaoai.billing.dto.BillingChargeRequest
;
import
com.yaoai.billing.service.BillingService
;
import
com.yaoai.common.context.UserContext
;
import
com.yaoai.common.exception.BizException
;
import
com.yaoai.common.exception.ErrorCode
;
import
com.yaoai.domain.entity.Character
;
...
...
@@ -100,7 +100,7 @@ public class AssetGenPipelineServiceImpl implements AssetGenPipelineService {
billingService
.
checkBalance
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
projectId
)
.
operation
(
"character_extract"
)
.
modality
(
"TEXT"
)
...
...
@@ -136,7 +136,7 @@ public class AssetGenPipelineServiceImpl implements AssetGenPipelineService {
}
billingService
.
charge
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
projectId
)
.
operation
(
"character_extract"
)
.
modality
(
"TEXT"
)
...
...
@@ -160,7 +160,7 @@ public class AssetGenPipelineServiceImpl implements AssetGenPipelineService {
billingService
.
checkBalance
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
projectId
)
.
operation
(
"scene_extract"
)
.
modality
(
"TEXT"
)
...
...
@@ -192,7 +192,7 @@ public class AssetGenPipelineServiceImpl implements AssetGenPipelineService {
}
billingService
.
charge
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
projectId
)
.
operation
(
"scene_extract"
)
.
modality
(
"TEXT"
)
...
...
@@ -220,7 +220,7 @@ public class AssetGenPipelineServiceImpl implements AssetGenPipelineService {
billingService
.
checkBalance
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
character
.
getProjectId
())
.
operation
(
"character_image_generate"
)
.
modality
(
"IMAGE"
)
...
...
@@ -253,7 +253,7 @@ public class AssetGenPipelineServiceImpl implements AssetGenPipelineService {
characterMapper
.
updateById
(
character
);
billingService
.
charge
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
character
.
getProjectId
())
.
operation
(
"character_image_generate"
)
.
modality
(
"IMAGE"
)
...
...
@@ -291,7 +291,7 @@ public class AssetGenPipelineServiceImpl implements AssetGenPipelineService {
billingService
.
checkBalance
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
scene
.
getProjectId
())
.
operation
(
"scene_image_generate"
)
.
modality
(
"IMAGE"
)
...
...
@@ -317,7 +317,7 @@ public class AssetGenPipelineServiceImpl implements AssetGenPipelineService {
sceneMapper
.
updateById
(
scene
);
billingService
.
charge
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
scene
.
getProjectId
())
.
operation
(
"scene_image_generate"
)
.
modality
(
"IMAGE"
)
...
...
yaoai-comic-studio/yaoai-pipeline/src/main/java/com/yaoai/pipeline/service/impl/OutlinePipelineServiceImpl.java
View file @
d0522a83
package
com
.
yaoai
.
pipeline
.
service
.
impl
;
import
cn.dev33.satoken.stp.StpUtil
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.yaoai.ai.core.model.ChatMessage
;
...
...
@@ -8,6 +7,7 @@ import com.yaoai.ai.core.model.ChatRequest;
import
com.yaoai.ai.core.service.LlmService
;
import
com.yaoai.billing.dto.BillingChargeRequest
;
import
com.yaoai.billing.service.BillingService
;
import
com.yaoai.common.context.UserContext
;
import
com.yaoai.common.exception.BizException
;
import
com.yaoai.common.exception.ErrorCode
;
import
com.yaoai.domain.entity.Episode
;
...
...
@@ -73,7 +73,7 @@ public class OutlinePipelineServiceImpl implements OutlinePipelineService {
billingService
.
checkBalance
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
projectId
)
.
operation
(
"outline_generate"
)
.
modality
(
"TEXT"
)
...
...
@@ -106,7 +106,7 @@ public class OutlinePipelineServiceImpl implements OutlinePipelineService {
outlineMapper
.
insert
(
outline
);
billingService
.
charge
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
projectId
)
.
operation
(
"outline_generate"
)
.
modality
(
"TEXT"
)
...
...
@@ -147,7 +147,7 @@ public class OutlinePipelineServiceImpl implements OutlinePipelineService {
billingService
.
checkBalance
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
projectId
)
.
operation
(
"episode_generate"
)
.
modality
(
"TEXT"
)
...
...
@@ -181,7 +181,7 @@ public class OutlinePipelineServiceImpl implements OutlinePipelineService {
}
billingService
.
charge
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
projectId
)
.
operation
(
"episode_generate"
)
.
modality
(
"TEXT"
)
...
...
yaoai-comic-studio/yaoai-pipeline/src/main/java/com/yaoai/pipeline/service/impl/StoryboardPipelineServiceImpl.java
View file @
d0522a83
package
com
.
yaoai
.
pipeline
.
service
.
impl
;
import
cn.dev33.satoken.stp.StpUtil
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.yaoai.ai.core.model.ChatMessage
;
...
...
@@ -8,6 +7,7 @@ import com.yaoai.ai.core.model.ChatRequest;
import
com.yaoai.ai.core.service.LlmService
;
import
com.yaoai.billing.dto.BillingChargeRequest
;
import
com.yaoai.billing.service.BillingService
;
import
com.yaoai.common.context.UserContext
;
import
com.yaoai.common.exception.BizException
;
import
com.yaoai.common.exception.ErrorCode
;
import
com.yaoai.domain.entity.Character
;
...
...
@@ -90,7 +90,7 @@ public class StoryboardPipelineServiceImpl implements StoryboardPipelineService
billingService
.
checkBalance
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
projectId
)
.
operation
(
"storyboard_generate"
)
.
modality
(
"TEXT"
)
...
...
@@ -131,7 +131,7 @@ public class StoryboardPipelineServiceImpl implements StoryboardPipelineService
}
billingService
.
charge
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
projectId
)
.
operation
(
"storyboard_generate"
)
.
modality
(
"TEXT"
)
...
...
@@ -299,7 +299,7 @@ public class StoryboardPipelineServiceImpl implements StoryboardPipelineService
storyboardId
,
sb
.
getEpisodeId
(),
characters
.
size
(),
scenes
.
size
());
billingService
.
checkBalance
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
sb
.
getProjectId
())
.
operation
(
"storyboard_prompt_generate"
)
.
modality
(
"TEXT"
)
...
...
@@ -312,7 +312,7 @@ public class StoryboardPipelineServiceImpl implements StoryboardPipelineService
String
prompt
=
llmService
.
chat
(
request
);
billingService
.
charge
(
BillingChargeRequest
.
builder
()
.
tenantId
(
tenantId
)
.
userId
(
StpUtil
.
getLoginIdAsLong
())
.
userId
(
UserContext
.
require
())
.
projectId
(
sb
.
getProjectId
())
.
operation
(
"storyboard_prompt_generate"
)
.
modality
(
"TEXT"
)
...
...
yaoai-comic-studio/yaoai-security/src/main/java/com/yaoai/security/config/SaTokenConfigure.java
View file @
d0522a83
...
...
@@ -4,6 +4,7 @@ import cn.dev33.satoken.exception.NotLoginException;
import
cn.dev33.satoken.interceptor.SaInterceptor
;
import
cn.dev33.satoken.router.SaRouter
;
import
cn.dev33.satoken.stp.StpUtil
;
import
com.yaoai.common.context.UserContext
;
import
com.yaoai.security.context.TenantContext
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
...
...
@@ -34,6 +35,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
.
notMatch
(
OPEN_PATHS
)
.
check
(
r
->
{
StpUtil
.
checkLogin
();
UserContext
.
set
(
StpUtil
.
getLoginIdAsLong
());
// 登录后将 tenantId 写入 ThreadLocal,供业务层使用
Object
tenantId
=
StpUtil
.
getSession
().
get
(
"tenantId"
);
if
(
tenantId
!=
null
)
{
...
...
@@ -48,6 +50,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
public
void
afterCompletion
(
HttpServletRequest
req
,
HttpServletResponse
res
,
Object
handler
,
Exception
ex
)
{
UserContext
.
clear
();
TenantContext
.
clear
();
}
}).
addPathPatterns
(
"/**"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment