-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathruntime.ts
More file actions
53 lines (49 loc) · 1.94 KB
/
Copy pathruntime.ts
File metadata and controls
53 lines (49 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { MaybePromise, NonEmptyRecord } from "@copilotkitnext/shared";
import { AbstractAgent } from "@ag-ui/client";
import pkg from "../package.json";
import type {
BeforeRequestMiddleware,
AfterRequestMiddleware,
} from "./middleware";
import { TranscriptionService } from "./transcription-service/transcription-service";
import { AgentRunner } from "./runner/agent-runner";
import { InMemoryAgentRunner } from "./runner/in-memory";
export const VERSION = pkg.version;
/**
* Options used to construct a `CopilotRuntime` instance.
*/
export interface CopilotRuntimeOptions {
/** Map of available agents (loaded lazily is fine). */
agents: MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;
/** The runner to use for running agents. */
runner?: AgentRunner;
/** Optional transcription service for audio processing. */
transcriptionService?: TranscriptionService;
/** Optional *before* middleware – callback function or webhook URL. */
beforeRequestMiddleware?: BeforeRequestMiddleware;
/** Optional *after* middleware – callback function or webhook URL. */
afterRequestMiddleware?: AfterRequestMiddleware;
}
/**
* Central runtime object passed to all request handlers.
*/
export class CopilotRuntime {
public agents: CopilotRuntimeOptions["agents"];
public transcriptionService: CopilotRuntimeOptions["transcriptionService"];
public beforeRequestMiddleware: CopilotRuntimeOptions["beforeRequestMiddleware"];
public afterRequestMiddleware: CopilotRuntimeOptions["afterRequestMiddleware"];
public runner: AgentRunner;
constructor({
agents,
transcriptionService,
beforeRequestMiddleware,
afterRequestMiddleware,
runner,
}: CopilotRuntimeOptions) {
this.agents = agents;
this.transcriptionService = transcriptionService;
this.beforeRequestMiddleware = beforeRequestMiddleware;
this.afterRequestMiddleware = afterRequestMiddleware;
this.runner = runner ?? new InMemoryAgentRunner();
}
}