refactor(runtime): wire pi-runtime services and extend RuntimeBridge

Bootstraps CredentialStore/Resolver, OAuthLoginService, and RuntimeBridge
inside service-graph via the existing pi-runtime factory, and exposes the
bridge to worker-service for agent-event + rpc-request routing. Adds a
`prepareRun` RPC that resolves credentials, loads prior messages, and
registers the active run context in a single call. Session rotation drops
the adapter nativeContextManagement branch; run payloads now carry the
taskSessionId and executionMode the worker needs to drive pi-agent-core.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-17 02:21:04 -04:00
1 parent 06a3ba603e
commit 892476bd36
5 files changed
+75 -20

No files matched your search

+14 -5
View File
@@ -133,18 +133,25 @@ function resolveSession(
deps: Pick<TurnContextDeps, "evaluatePreRunSessionRotation" | "logger">,
) {
const activeSession = db.getActiveTaskSession(task.id);
let taskSession = activeSession
let taskSession: {
id: string | null;
sessionParams: Record<string, unknown> | null;
sessionDisplayId: string | null;
} = activeSession
? {
sessionParams: activeSession.sessionParamsJson ? JSON.parse(activeSession.sessionParamsJson) as Record<string, unknown> : null,
id: activeSession.id,
sessionParams: activeSession.sessionParamsJson
? (JSON.parse(activeSession.sessionParamsJson) as Record<string, unknown>)
: null,
sessionDisplayId: activeSession.sessionDisplayId,
}
: db.getTaskSession(task.id);
: { id: null, ...db.getTaskSession(task.id) };
let finalHandoff = sessionHandoff;
if (deps.evaluatePreRunSessionRotation && activeSession) {
const rotationResult = deps.evaluatePreRunSessionRotation(task.id, connectorId);
if (rotationResult.rotated) {
taskSession = { sessionParams: null, sessionDisplayId: null };
taskSession = { id: null, sessionParams: null, sessionDisplayId: null };
if (!finalHandoff && rotationResult.handoff) {
finalHandoff = rotationResult.handoff;
}
@@ -220,7 +227,7 @@ function buildConnectorCatalog(
) {
return connectors
.filter((c) => c.status === "ready")
.filter((c) => c.id.startsWith("claude_compat") || db.hasModelPoolSettings(c.id))
.filter((c) => db.hasModelPoolSettings(c.id))
.map((c) => ({
id: c.id,
label: c.label,
@@ -336,5 +343,7 @@ export function buildRunPayload(params: RunDispatchParams, deps: TurnContextDeps
systemPrompt,
trigger,
managedSkills: skills.map((s) => ({ runtimeName: s.runtimeName, sourcePath: s.sourcePath })),
taskSessionId: taskSession.id ?? runId,
executionMode: db.getCompanyExecutionMode(companyId) as "ai_ceo" | "ai_cofounder",
};
}
+4
View File
@@ -44,6 +44,10 @@ export interface EnqueueRunPayload {
systemPrompt: string | null;
trigger: string | null;
managedSkills: Array<{ runtimeName: string; sourcePath: string }>;
/** Task session id used by SqliteSessionStore to load/append messages. */
taskSessionId: string;
/** Execution mode from the owning company. */
executionMode: "ai_ceo" | "ai_cofounder";
}
export interface OrchestrationDependencies {