import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; const root = path.resolve(import.meta.dirname, ".."); const read = (...parts) => fs.readFileSync(path.join(root, ...parts), "utf8"); const packageJson = JSON.parse(read("package.json")); const streamHook = read("client", "src", "sections", "superAgent", "hooks", "useSuperAgentStream.js"); const container = read("client", "src", "sections", "superAgent", "container", "index.jsx"); const conversation = read("client", "src", "sections", "superAgent", "components", "SuperAgentConversation.jsx"); const runLog = read("client", "src", "sections", "superAgent", "components", "AgentRunLog.jsx"); const generatedInterrupt = read("client", "src", "sections", "superAgent", "components", "GeneratedUiInterrupt.jsx"); const checkpointUtils = read("client", "src", "sections", "superAgent", "utils", "checkpoint.js"); const workspaceHost = read("client", "src", "sections", "superAgent", "components", "workspace", "WorkspaceHost.jsx"); const listWorkspace = read("client", "src", "sections", "superAgent", "components", "workspace", "ListWorkspace.jsx"); const jsonRender = read("client", "src", "sections", "superAgent", "components", "JsonRenderMessage.jsx"); const apiRoutes = read("..", "api", "app", "routes", "superAgent.js"); assert.equal(packageJson.dependencies["@langchain/react"], "1.0.29"); assert.match(streamHook, /useStream\(\{/); assert.match(streamHook, /apiUrl:\s*getSuperAgentFrameworkApiUrl\(\)/); assert.match(streamHook, /getSuperAgentFrameworkApiUrl/); assert.doesNotMatch(streamHook, /\/api\/v1/); assert.match(streamHook, /withAgentAuthorization/); assert.doesNotMatch(streamHook, /X-User-Id/); assert.doesNotMatch(streamHook, /X-Search-Token/); assert.doesNotMatch(streamHook, /onCustomEvent/); assert.match(streamHook, /ROOT_PUMP_CHANNELS/); assert.match(streamHook, /"custom"/); assert.match(streamHook, /attachment_ids:/); assert.match(streamHook, /stream\.submit\(/); assert.match(streamHook, /stream\.respond\(/); assert.match(streamHook, /role:\s*"user"/); assert.doesNotMatch(streamHook, /type:\s*"human"/); assert.match(streamHook, /const state = await super\.getState\(\)/); assert.match(streamHook, /hydratedState\?\.values\?\.messages/); assert.match(container, /attachments: conversationAttachments/); assert.match(streamHook, /const stopRun =/); assert.match(streamHook, /await stream\.stop\(\)/); assert.match(streamHook, /disconnect:\s*stream\.disconnect/); assert.match(streamHook, /eventRequestControllersRef/); assert.match(streamHook, /isLifecycleWatcherRequest/); assert.match(streamHook, /status: 204/); assert.match(streamHook, /currentThread\.close/); assert.match(streamHook, /event\?\.method === "input\.requested"/); assert.match(streamHook, /runtimeInterrupts/); assert.match(streamHook, /setRunPhase\("failed"\)/); assert.match(streamHook, /setIsBusinessRunning\(false\)/); assert.match(streamHook, /eventType: event\?\.method/); assert.match(streamHook, /requestId/); assert.match(container, /getSuperAgentErrorMessage/); assert.doesNotMatch(container, /useSuperAgentChat/); assert.doesNotMatch(container, /respondSuperAgentCheckpoint/); assert.doesNotMatch(container, /sendSuperAgentChat/); assert.doesNotMatch(container, /cancelSuperAgentSession/); const generatedDecisionStart = container.indexOf("const response = {"); const generatedDecisionEnd = container.indexOf("};", generatedDecisionStart); const generatedDecision = container.slice(generatedDecisionStart, generatedDecisionEnd); assert.doesNotMatch(generatedDecision, /interrupt_id:/); assert.doesNotMatch(generatedDecision, /namespace:/); assert.doesNotMatch(container, /stream-tool-log-/); assert.doesNotMatch(container, /正在思考/); assert.doesNotMatch(runLog, /正在处理|showProcessingStatus/); assert.doesNotMatch(conversation, /BodyProgressGroup|isBodyProgressMessage/); assert.match(generatedInterrupt, /onOpenWorkspace/); assert.match(generatedInterrupt, /disabled = false/); assert.doesNotMatch(generatedInterrupt, /待填写/); assert.match(checkpointUtils, /buildGeneratedUiWorkspaceCheckpoint/); assert.match(checkpointUtils, /buildGeneratedUiCorrectedValues/); assert.match(checkpointUtils, /__generatedFieldLabels/); assert.match(listWorkspace, /getItemFieldLabel/); assert.match(workspaceHost, /submitLabel/); assert.match(container, /if \(submitted\) closeWorkspace\(\)/); assert.match(streamHook, /awaiting_interrupt/); assert.match(streamHook, /isWaitingForInterrupt/); assert.match(container, /refreshSessionContentWorkspace/); assert.match(container, /syncSessionProgressSections/); assert.match(conversation, /toolCalls=\{item\.toolCalls\}/); assert.match(jsonRender, /toolCall\?\.name === "publish_ui"/); assert.doesNotMatch(jsonRender, /```json-render|JSON_RENDER_FENCE/); assert.match(apiRoutes, /'\/super-agent\/threads\/:threadId\/commands'/); assert.match(apiRoutes, /'\/super-agent\/threads\/:threadId\/stream\/events'/); assert.match(apiRoutes, /'\/super-agent\/threads\/:threadId\/runs\/:runId\/cancel'/);