@copilotkitnext/core 1.51.3 → 1.51.4-next.1

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.
package/dist/index.d.mts CHANGED
@@ -12,11 +12,18 @@ declare enum ToolCallStatus {
12
12
  Complete = "complete"
13
13
  }
14
14
  type CopilotRuntimeTransport = "rest" | "single";
15
+ /**
16
+ * Context passed to a frontend tool handler
17
+ */
18
+ type FrontendToolHandlerContext = {
19
+ toolCall: ToolCall;
20
+ agent: AbstractAgent;
21
+ };
15
22
  type FrontendTool<T extends Record<string, unknown> = Record<string, unknown>> = {
16
23
  name: string;
17
24
  description?: string;
18
25
  parameters?: z.ZodType<T>;
19
- handler?: (args: T, toolCall: ToolCall) => Promise<unknown>;
26
+ handler?: (args: T, context: FrontendToolHandlerContext) => Promise<unknown>;
20
27
  followUp?: boolean;
21
28
  /**
22
29
  * Optional agent ID to constrain this tool to a specific agent.
@@ -666,4 +673,4 @@ declare class ProxiedCopilotRuntimeAgent extends HttpAgent {
666
673
 
667
674
  declare function completePartialMarkdown(input: string): string;
668
675
 
669
- export { AgentRegistry, ContextStore, CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams, CopilotKitCoreErrorCode, type CopilotKitCoreFriendsAccess, type CopilotKitCoreGetSuggestionsResult, type CopilotKitCoreGetToolParams, type CopilotKitCoreRunAgentParams, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitCoreStopAgentParams, type CopilotKitCoreSubscriber, type CopilotKitCoreSubscription, type CopilotRuntimeTransport, type DynamicSuggestionsConfig, type FrontendTool, ProxiedCopilotRuntimeAgent, type ProxiedCopilotRuntimeAgentConfig, RunHandler, StateManager, type StaticSuggestionsConfig, type Suggestion, type SuggestionAvailability, SuggestionEngine, type SuggestionsConfig, ToolCallStatus, completePartialMarkdown };
676
+ export { AgentRegistry, ContextStore, CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams, CopilotKitCoreErrorCode, type CopilotKitCoreFriendsAccess, type CopilotKitCoreGetSuggestionsResult, type CopilotKitCoreGetToolParams, type CopilotKitCoreRunAgentParams, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitCoreStopAgentParams, type CopilotKitCoreSubscriber, type CopilotKitCoreSubscription, type CopilotRuntimeTransport, type DynamicSuggestionsConfig, type FrontendTool, type FrontendToolHandlerContext, ProxiedCopilotRuntimeAgent, type ProxiedCopilotRuntimeAgentConfig, RunHandler, StateManager, type StaticSuggestionsConfig, type Suggestion, type SuggestionAvailability, SuggestionEngine, type SuggestionsConfig, ToolCallStatus, completePartialMarkdown };
package/dist/index.d.ts CHANGED
@@ -12,11 +12,18 @@ declare enum ToolCallStatus {
12
12
  Complete = "complete"
13
13
  }
14
14
  type CopilotRuntimeTransport = "rest" | "single";
15
+ /**
16
+ * Context passed to a frontend tool handler
17
+ */
18
+ type FrontendToolHandlerContext = {
19
+ toolCall: ToolCall;
20
+ agent: AbstractAgent;
21
+ };
15
22
  type FrontendTool<T extends Record<string, unknown> = Record<string, unknown>> = {
16
23
  name: string;
17
24
  description?: string;
18
25
  parameters?: z.ZodType<T>;
19
- handler?: (args: T, toolCall: ToolCall) => Promise<unknown>;
26
+ handler?: (args: T, context: FrontendToolHandlerContext) => Promise<unknown>;
20
27
  followUp?: boolean;
21
28
  /**
22
29
  * Optional agent ID to constrain this tool to a specific agent.
@@ -666,4 +673,4 @@ declare class ProxiedCopilotRuntimeAgent extends HttpAgent {
666
673
 
667
674
  declare function completePartialMarkdown(input: string): string;
668
675
 
669
- export { AgentRegistry, ContextStore, CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams, CopilotKitCoreErrorCode, type CopilotKitCoreFriendsAccess, type CopilotKitCoreGetSuggestionsResult, type CopilotKitCoreGetToolParams, type CopilotKitCoreRunAgentParams, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitCoreStopAgentParams, type CopilotKitCoreSubscriber, type CopilotKitCoreSubscription, type CopilotRuntimeTransport, type DynamicSuggestionsConfig, type FrontendTool, ProxiedCopilotRuntimeAgent, type ProxiedCopilotRuntimeAgentConfig, RunHandler, StateManager, type StaticSuggestionsConfig, type Suggestion, type SuggestionAvailability, SuggestionEngine, type SuggestionsConfig, ToolCallStatus, completePartialMarkdown };
676
+ export { AgentRegistry, ContextStore, CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams, CopilotKitCoreErrorCode, type CopilotKitCoreFriendsAccess, type CopilotKitCoreGetSuggestionsResult, type CopilotKitCoreGetToolParams, type CopilotKitCoreRunAgentParams, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitCoreStopAgentParams, type CopilotKitCoreSubscriber, type CopilotKitCoreSubscription, type CopilotRuntimeTransport, type DynamicSuggestionsConfig, type FrontendTool, type FrontendToolHandlerContext, ProxiedCopilotRuntimeAgent, type ProxiedCopilotRuntimeAgentConfig, RunHandler, StateManager, type StaticSuggestionsConfig, type Suggestion, type SuggestionAvailability, SuggestionEngine, type SuggestionsConfig, ToolCallStatus, completePartialMarkdown };
package/dist/index.js CHANGED
@@ -40,6 +40,21 @@ var import_shared = require("@copilotkitnext/shared");
40
40
 
41
41
  // src/agent.ts
42
42
  var import_client = require("@ag-ui/client");
43
+ var import_rxjs = require("rxjs");
44
+ var import_operators = require("rxjs/operators");
45
+ function isZodError(error) {
46
+ return error !== null && typeof error === "object" && "name" in error && error.name === "ZodError";
47
+ }
48
+ function withAbortErrorHandling(observable) {
49
+ return observable.pipe(
50
+ (0, import_operators.catchError)((error) => {
51
+ if (isZodError(error)) {
52
+ return import_rxjs.EMPTY;
53
+ }
54
+ throw error;
55
+ })
56
+ );
57
+ }
43
58
  var ProxiedCopilotRuntimeAgent = class extends import_client.HttpAgent {
44
59
  runtimeUrl;
45
60
  credentials;
@@ -118,10 +133,10 @@ var ProxiedCopilotRuntimeAgent = class extends import_client.HttpAgent {
118
133
  agentId: this.agentId
119
134
  });
120
135
  const httpEvents2 = (0, import_client.runHttpRequest)(this.singleEndpointUrl, requestInit);
121
- return (0, import_client.transformHttpEventStream)(httpEvents2);
136
+ return withAbortErrorHandling((0, import_client.transformHttpEventStream)(httpEvents2));
122
137
  }
123
138
  const httpEvents = (0, import_client.runHttpRequest)(`${this.runtimeUrl}/agent/${this.agentId}/connect`, this.requestInit(input));
124
- return (0, import_client.transformHttpEventStream)(httpEvents);
139
+ return withAbortErrorHandling((0, import_client.transformHttpEventStream)(httpEvents));
125
140
  }
126
141
  run(input) {
127
142
  if (this.transport === "single") {
@@ -132,9 +147,9 @@ var ProxiedCopilotRuntimeAgent = class extends import_client.HttpAgent {
132
147
  agentId: this.agentId
133
148
  });
134
149
  const httpEvents = (0, import_client.runHttpRequest)(this.singleEndpointUrl, requestInit);
135
- return (0, import_client.transformHttpEventStream)(httpEvents);
150
+ return withAbortErrorHandling((0, import_client.transformHttpEventStream)(httpEvents));
136
151
  }
137
- return super.run(input);
152
+ return withAbortErrorHandling(super.run(input));
138
153
  }
139
154
  clone() {
140
155
  const cloned = super.clone();
@@ -1070,7 +1085,7 @@ var RunHandler = class {
1070
1085
  );
1071
1086
  if (!errorMessage) {
1072
1087
  try {
1073
- const result = await tool.handler(parsedArgs, toolCall);
1088
+ const result = await tool.handler(parsedArgs, { toolCall, agent });
1074
1089
  if (result === void 0 || result === null) {
1075
1090
  toolCallResult = "";
1076
1091
  } else if (typeof result === "string") {
@@ -1175,7 +1190,7 @@ var RunHandler = class {
1175
1190
  );
1176
1191
  if (!errorMessage) {
1177
1192
  try {
1178
- const result = await wildcardTool.handler(wildcardArgs, toolCall);
1193
+ const result = await wildcardTool.handler(wildcardArgs, { toolCall, agent });
1179
1194
  if (result === void 0 || result === null) {
1180
1195
  toolCallResult = "";
1181
1196
  } else if (typeof result === "string") {