@copilotkit/runtime 0.38.0-mme-alpha.0 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/.turbo/turbo-build.log +41 -41
  2. package/CHANGELOG.md +10 -4
  3. package/dist/{chunk-6OJ47NCG.mjs → chunk-2PJG3NAC.mjs} +2 -2
  4. package/dist/{chunk-EWS5TMDA.mjs → chunk-6YGDE3YI.mjs} +91 -84
  5. package/dist/chunk-6YGDE3YI.mjs.map +1 -0
  6. package/dist/{chunk-XI3HBDMA.mjs → chunk-JBDOA7MK.mjs} +22 -11
  7. package/dist/chunk-JBDOA7MK.mjs.map +1 -0
  8. package/dist/{chunk-XXYCNRFT.mjs → chunk-JIKPSUGQ.mjs} +36 -69
  9. package/dist/chunk-JIKPSUGQ.mjs.map +1 -0
  10. package/dist/{index-d5ba24be.d.ts → index-0e75acd2.d.ts} +64 -38
  11. package/dist/index.d.ts +4 -4
  12. package/dist/index.js +163 -186
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.mjs +4 -10
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/{langchain-adapter-54784d29.d.ts → langchain-adapter-a02d1d38.d.ts} +4 -4
  17. package/dist/{langserve-63794237.d.ts → langserve-75ebbc38.d.ts} +1 -2
  18. package/dist/lib/index.d.ts +4 -4
  19. package/dist/lib/index.js +163 -186
  20. package/dist/lib/index.js.map +1 -1
  21. package/dist/lib/index.mjs +4 -10
  22. package/dist/lib/integrations/index.d.ts +3 -3
  23. package/dist/lib/integrations/index.js +118 -95
  24. package/dist/lib/integrations/index.js.map +1 -1
  25. package/dist/lib/integrations/index.mjs +2 -2
  26. package/dist/lib/integrations/node-http/index.d.ts +2 -2
  27. package/dist/lib/integrations/node-http/index.js +118 -95
  28. package/dist/lib/integrations/node-http/index.js.map +1 -1
  29. package/dist/lib/integrations/node-http/index.mjs +1 -1
  30. package/dist/{pages-router-d94f01da.d.ts → pages-router-e81920d5.d.ts} +1 -1
  31. package/dist/service-adapters/index.d.ts +2 -2
  32. package/dist/service-adapters/index.js +28 -17
  33. package/dist/service-adapters/index.js.map +1 -1
  34. package/dist/service-adapters/index.mjs +1 -1
  35. package/package.json +4 -4
  36. package/src/graphql/resolvers/copilot.resolver.ts +95 -24
  37. package/src/lib/copilot-runtime.ts +106 -36
  38. package/src/lib/index.ts +0 -1
  39. package/src/lib/integrations/shared.ts +1 -1
  40. package/src/service-adapters/experimental/groq/groq-adapter.ts +3 -1
  41. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +3 -1
  42. package/src/service-adapters/google/google-genai-adapter.ts +3 -1
  43. package/src/service-adapters/langchain/langchain-adapter.ts +8 -9
  44. package/src/service-adapters/openai/openai-adapter.ts +8 -7
  45. package/src/service-adapters/openai/openai-assistant-adapter.ts +6 -8
  46. package/src/service-adapters/service-adapter.ts +1 -2
  47. package/dist/chunk-EWS5TMDA.mjs.map +0 -1
  48. package/dist/chunk-XI3HBDMA.mjs.map +0 -1
  49. package/dist/chunk-XXYCNRFT.mjs.map +0 -1
  50. package/src/lib/copilot-cloud.ts +0 -63
  51. /package/dist/{chunk-6OJ47NCG.mjs.map → chunk-2PJG3NAC.mjs.map} +0 -0
@@ -2,29 +2,11 @@ import * as graphql_yoga from 'graphql-yoga';
2
2
  import { YogaInitialContext, createYoga } from 'graphql-yoga';
3
3
  import * as graphql from 'graphql';
4
4
  import * as pino from 'pino';
5
- import { CopilotCloudConfig, Parameter, Action } from '@copilotkit/shared';
6
- import { R as RemoteChainParameters, A as ActionInput, C as CopilotServiceAdapter, a as RuntimeEventSource } from './langserve-63794237.js';
7
- import { M as MessageInput } from './index-aa091e3c.js';
5
+ import { Parameter, Action } from '@copilotkit/shared';
6
+ import { R as RemoteChainParameters, A as ActionInput, C as CopilotServiceAdapter, a as RuntimeEventSource } from './langserve-75ebbc38.js';
7
+ import { M as MessageInput, a as Message } from './index-aa091e3c.js';
8
8
  import { CopilotCloudOptions } from './lib/cloud/index.js';
9
9
 
10
- interface CloudCheckGuardrailsInputParams {
11
- cloud: CopilotCloudConfig;
12
- publicApiKey: string;
13
- messages: any[];
14
- }
15
- interface CloudCheckGuardrailsInputResponse {
16
- status: "allowed" | "denied";
17
- reason: string;
18
- }
19
- declare abstract class CopilotCloud {
20
- abstract checkGuardrailsInput(params: CloudCheckGuardrailsInputParams): Promise<CloudCheckGuardrailsInputResponse>;
21
- }
22
- declare class RemoteCopilotCloud extends CopilotCloud {
23
- private readonly cloudApiUrl;
24
- constructor(cloudApiUrl?: string);
25
- checkGuardrailsInput({ cloud, publicApiKey, messages, }: CloudCheckGuardrailsInputParams): Promise<CloudCheckGuardrailsInputResponse>;
26
- }
27
-
28
10
  /**
29
11
  * Handles requests from frontend, provides function calling and various LLM backends.
30
12
  *
@@ -129,38 +111,82 @@ interface CopilotRuntimeRequest {
129
111
  serviceAdapter: CopilotServiceAdapter;
130
112
  messages: MessageInput[];
131
113
  actions: ActionInput[];
114
+ outputMessagesPromise: Promise<Message[]>;
115
+ properties: any;
132
116
  threadId?: string;
133
117
  runId?: string;
134
118
  publicApiKey?: string;
135
119
  }
136
120
  interface CopilotRuntimeResponse {
137
- threadId?: string;
121
+ threadId: string;
138
122
  runId?: string;
139
123
  eventSource: RuntimeEventSource;
140
124
  actions: Action<any>[];
141
125
  }
126
+ type ActionsConfiguration<T extends Parameter[] | [] = []> = Action<T>[] | ((ctx: {
127
+ properties: any;
128
+ }) => Action<T>[]);
129
+ interface OnBeforeRequestOptions {
130
+ threadId?: string;
131
+ runId?: string;
132
+ inputMessages: Message[];
133
+ properties: any;
134
+ }
135
+ type OnBeforeRequestHandler = (options: OnBeforeRequestOptions) => void | Promise<void>;
136
+ interface OnAfterRequestOptions {
137
+ threadId: string;
138
+ runId?: string;
139
+ inputMessages: Message[];
140
+ outputMessages: Message[];
141
+ properties: any;
142
+ }
143
+ type OnAfterRequestHandler = (options: OnAfterRequestOptions) => void | Promise<void>;
144
+ interface Middleware {
145
+ /**
146
+ * A function that is called before the request is processed.
147
+ */
148
+ onBeforeRequest?: OnBeforeRequestHandler;
149
+ /**
150
+ * A function that is called after the request is processed.
151
+ */
152
+ onAfterRequest?: OnAfterRequestHandler;
153
+ }
142
154
  interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []> {
143
- actions?: Action<T>[];
155
+ /**
156
+ * Middleware to be used by the runtime.
157
+ *
158
+ * ```ts
159
+ * onBeforeRequest: (options: {
160
+ * threadId?: string;
161
+ * runId?: string;
162
+ * inputMessages: Message[];
163
+ * properties: any;
164
+ * }) => void | Promise<void>;
165
+ * ```
166
+ *
167
+ * ```ts
168
+ * onAfterRequest: (options: {
169
+ * threadId?: string;
170
+ * runId?: string;
171
+ * inputMessages: Message[];
172
+ * outputMessages: Message[];
173
+ * properties: any;
174
+ * }) => void | Promise<void>;
175
+ * ```
176
+ */
177
+ middleware?: Middleware;
178
+ actions?: ActionsConfiguration<T>;
144
179
  langserve?: RemoteChainParameters[];
145
- debug?: boolean;
146
- copilotCloud?: CopilotCloud;
147
180
  }
148
181
  declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
149
- actions: Action<any>[];
182
+ actions: ActionsConfiguration<T>;
150
183
  private langserve;
151
- private debug;
152
- private copilotCloud;
184
+ private onBeforeRequest?;
185
+ private onAfterRequest?;
153
186
  constructor(params?: CopilotRuntimeConstructorParams<T>);
154
- addAction<const T extends Parameter[] | [] = []>(action: Action<T>): void;
155
- removeAction(actionName: string): void;
156
- process({ serviceAdapter, messages, actions: clientSideActionsInput, threadId, runId, publicApiKey, }: CopilotRuntimeRequest): Promise<CopilotRuntimeResponse>;
187
+ process(request: CopilotRuntimeRequest): Promise<CopilotRuntimeResponse>;
157
188
  }
158
189
  declare function flattenToolCallsNoDuplicates(toolsByPriority: ActionInput[]): ActionInput[];
159
- /**
160
- * @deprecated use CopilotRuntime instead
161
- */
162
- declare class CopilotBackend extends CopilotRuntime {
163
- }
164
190
 
165
191
  type LogLevel = "debug" | "info" | "warn" | "error";
166
192
 
@@ -173,7 +199,7 @@ type GraphQLContext = YogaInitialContext & {
173
199
  logger: typeof logger;
174
200
  };
175
201
  interface CreateCopilotRuntimeServerOptions {
176
- runtime: CopilotRuntime;
202
+ runtime: CopilotRuntime<any>;
177
203
  serviceAdapter: CopilotServiceAdapter;
178
204
  endpoint: string;
179
205
  baseUrl?: string;
@@ -195,4 +221,4 @@ declare function getCommonConfig(options: CreateCopilotRuntimeServerOptions): Co
195
221
 
196
222
  declare function copilotRuntimeNodeHttpEndpoint(options: CreateCopilotRuntimeServerOptions): graphql_yoga.YogaServerInstance<{}, Partial<GraphQLContext>>;
197
223
 
198
- export { CopilotRuntimeConstructorParams as C, GraphQLContext as G, RemoteCopilotCloud as R, CopilotRuntime as a, CopilotBackend as b, CloudCheckGuardrailsInputParams as c, CloudCheckGuardrailsInputResponse as d, CopilotCloud as e, flattenToolCallsNoDuplicates as f, CopilotRequestContextProperties as g, CreateCopilotRuntimeServerOptions as h, createContext as i, buildSchema as j, CommonConfig as k, getCommonConfig as l, copilotRuntimeNodeHttpEndpoint as m };
224
+ export { CopilotRuntimeConstructorParams as C, GraphQLContext as G, CopilotRuntime as a, CopilotRequestContextProperties as b, CreateCopilotRuntimeServerOptions as c, createContext as d, buildSchema as e, flattenToolCallsNoDuplicates as f, CommonConfig as g, getCommonConfig as h, copilotRuntimeNodeHttpEndpoint as i };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- export { c as CloudCheckGuardrailsInputParams, d as CloudCheckGuardrailsInputResponse, k as CommonConfig, b as CopilotBackend, e as CopilotCloud, g as CopilotRequestContextProperties, a as CopilotRuntime, C as CopilotRuntimeConstructorParams, h as CreateCopilotRuntimeServerOptions, G as GraphQLContext, R as RemoteCopilotCloud, j as buildSchema, m as copilotRuntimeNodeHttpEndpoint, i as createContext, f as flattenToolCallsNoDuplicates, l as getCommonConfig } from './index-d5ba24be.js';
2
- export { G as GoogleGenerativeAIAdapter, L as LangChainAdapter, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams } from './langchain-adapter-54784d29.js';
3
- export { C as CopilotRuntimeServerInstance, a as config, c as copilotRuntimeNextJSAppRouterEndpoint, b as copilotRuntimeNextJSPagesRouterEndpoint } from './pages-router-d94f01da.js';
1
+ export { g as CommonConfig, b as CopilotRequestContextProperties, a as CopilotRuntime, C as CopilotRuntimeConstructorParams, c as CreateCopilotRuntimeServerOptions, G as GraphQLContext, e as buildSchema, i as copilotRuntimeNodeHttpEndpoint, d as createContext, f as flattenToolCallsNoDuplicates, h as getCommonConfig } from './index-0e75acd2.js';
2
+ export { G as GoogleGenerativeAIAdapter, L as LangChainAdapter, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams } from './langchain-adapter-a02d1d38.js';
3
+ export { C as CopilotRuntimeServerInstance, a as config, c as copilotRuntimeNextJSAppRouterEndpoint, b as copilotRuntimeNextJSPagesRouterEndpoint } from './pages-router-e81920d5.js';
4
4
  export { G as GuardrailsValidationFailureResponse, M as MessageStreamInterruptedResponse, U as UnknownErrorResponse } from './failed-response-status-reasons-0ab19e06.js';
5
5
  import 'graphql-yoga';
6
6
  import 'graphql';
7
7
  import 'pino';
8
8
  import '@copilotkit/shared';
9
- import './langserve-63794237.js';
9
+ import './langserve-75ebbc38.js';
10
10
  import './index-aa091e3c.js';
11
11
  import './graphql/types/base/index.js';
12
12
  import 'rxjs';