feat: add assistant proposal worker runtime

This commit is contained in:
zenord
2026-08-18 18:48:47 +08:00
parent 947f19e3cd
commit b4121c9fd6
32 changed files with 2827 additions and 986 deletions
+12 -12
View File
@@ -6,21 +6,21 @@ export interface StoreIdentity {
platform: string;
}
export interface SessionBinding {
export interface AssistantBinding {
chatKey: string;
agentId: string;
nativeSessionId: string;
workspace: string;
assistantWorkspace: string;
botFingerprint: string;
createdAt: number;
updatedAt: number;
}
interface StoreData {
version: 2;
version: 3;
botId: string;
platform: string;
bindings: Record<string, SessionBinding>;
bindings: Record<string, AssistantBinding>;
}
export class DurableSessionStore {
@@ -76,12 +76,12 @@ export class DurableSessionStore {
}
}
getBinding(chatKey: string): SessionBinding | undefined {
getBinding(chatKey: string): AssistantBinding | undefined {
const value = this.data.bindings[chatKey];
return value ? structuredClone(value) : undefined;
}
async setBinding(binding: SessionBinding): Promise<void> {
async setBinding(binding: AssistantBinding): Promise<void> {
this.data.bindings[binding.chatKey] = structuredClone(binding);
await this.persist();
}
@@ -93,7 +93,7 @@ export class DurableSessionStore {
await this.persist();
}
async deleteBinding(chatKey: string): Promise<SessionBinding | undefined> {
async deleteBinding(chatKey: string): Promise<AssistantBinding | undefined> {
const existing = this.data.bindings[chatKey];
delete this.data.bindings[chatKey];
if (existing) await this.persist();
@@ -133,23 +133,23 @@ export class DurableSessionStore {
export function chatKeyFor(platform: string, chatId: string): string { return `${platform}:${chatId}`; }
function emptyData(identity: StoreIdentity): StoreData {
return { version: 2, botId: identity.botId, platform: identity.platform, bindings: {} };
return { version: 3, botId: identity.botId, platform: identity.platform, bindings: {} };
}
function parseStoreData(value: unknown): StoreData {
if (!isRecord(value) || value.version !== 2 || typeof value.botId !== "string" || typeof value.platform !== "string" || !isRecord(value.bindings)) {
throw new Error("unsupported state version; Config v3 requires state v2 in a new GORI_AGENT_HOME");
if (!isRecord(value) || value.version !== 3 || typeof value.botId !== "string" || typeof value.platform !== "string" || !isRecord(value.bindings)) {
throw new Error("unsupported state version; Config v3 requires state v3 in a new GORI_AGENT_HOME");
}
for (const [chatKey, binding] of Object.entries(value.bindings)) {
if (!isRecord(binding)
|| binding.chatKey !== chatKey
|| typeof binding.agentId !== "string"
|| typeof binding.nativeSessionId !== "string"
|| typeof binding.workspace !== "string"
|| typeof binding.assistantWorkspace !== "string"
|| typeof binding.botFingerprint !== "string"
|| typeof binding.createdAt !== "number"
|| typeof binding.updatedAt !== "number") {
throw new Error(`invalid state v2 binding '${chatKey}'`);
throw new Error(`invalid state v3 binding '${chatKey}'`);
}
}
return value as unknown as StoreData;