@copilotkit/runtime
Version:
<div align="center"> <a href="https://copilotkit.ai" target="_blank"> <img src="https://github.com/copilotkit/copilotkit/raw/main/assets/banner.png" alt="CopilotKit Logo"> </a>
29 lines (24 loc) • 1.01 kB
text/typescript
import { Arg, Resolver } from "type-graphql";
import { Ctx } from "type-graphql";
import { Query } from "type-graphql";
import { LoadAgentStateResponse } from "../types/load-agent-state-response.type";
import type { GraphQLContext } from "../../lib/integrations";
import { LoadAgentStateInput } from "../inputs/load-agent-state.input";
(() => LoadAgentStateResponse)
export class StateResolver {
(() => LoadAgentStateResponse)
async loadAgentState(ctx: GraphQLContext, ("data") data: LoadAgentStateInput) {
() const agents = await ctx._copilotkit.runtime.discoverAgentsFromEndpoints(ctx);
const agent = agents.find((agent) => agent.name === data.agentName);
if (!agent) {
return {
threadId: data.threadId || "",
threadExists: false,
state: JSON.stringify({}),
messages: JSON.stringify([]),
};
}
const state = await ctx._copilotkit.runtime.loadAgentState(ctx, data.threadId, data.agentName);
return state;
}
}