@copilotkitnext/core 0.0.22-alpha.8 → 0.0.22

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
@@ -326,6 +326,9 @@ interface CopilotKitCoreSubscriber {
326
326
  context: Record<string, any>;
327
327
  }) => void | Promise<void>;
328
328
  }
329
+ interface CopilotKitCoreSubscription {
330
+ unsubscribe: () => void;
331
+ }
329
332
  declare enum CopilotKitCoreRuntimeConnectionStatus {
330
333
  Disconnected = "disconnected",
331
334
  Connected = "connected",
@@ -420,8 +423,7 @@ declare class CopilotKitCore {
420
423
  /**
421
424
  * Subscription lifecycle
422
425
  */
423
- subscribe(subscriber: CopilotKitCoreSubscriber): () => void;
424
- unsubscribe(subscriber: CopilotKitCoreSubscriber): void;
426
+ subscribe(subscriber: CopilotKitCoreSubscriber): CopilotKitCoreSubscription;
425
427
  /**
426
428
  * Agent connectivity (delegated to RunHandler)
427
429
  */
@@ -639,4 +641,4 @@ declare class ProxiedCopilotRuntimeAgent extends HttpAgent {
639
641
 
640
642
  declare function completePartialMarkdown(input: string): string;
641
643
 
642
- 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 CopilotRuntimeTransport, type DynamicSuggestionsConfig, type FrontendTool, ProxiedCopilotRuntimeAgent, type ProxiedCopilotRuntimeAgentConfig, RunHandler, StateManager, type StaticSuggestionsConfig, type Suggestion, type SuggestionAvailability, SuggestionEngine, type SuggestionsConfig, ToolCallStatus, completePartialMarkdown };
644
+ 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 };
package/dist/index.d.ts CHANGED
@@ -326,6 +326,9 @@ interface CopilotKitCoreSubscriber {
326
326
  context: Record<string, any>;
327
327
  }) => void | Promise<void>;
328
328
  }
329
+ interface CopilotKitCoreSubscription {
330
+ unsubscribe: () => void;
331
+ }
329
332
  declare enum CopilotKitCoreRuntimeConnectionStatus {
330
333
  Disconnected = "disconnected",
331
334
  Connected = "connected",
@@ -420,8 +423,7 @@ declare class CopilotKitCore {
420
423
  /**
421
424
  * Subscription lifecycle
422
425
  */
423
- subscribe(subscriber: CopilotKitCoreSubscriber): () => void;
424
- unsubscribe(subscriber: CopilotKitCoreSubscriber): void;
426
+ subscribe(subscriber: CopilotKitCoreSubscriber): CopilotKitCoreSubscription;
425
427
  /**
426
428
  * Agent connectivity (delegated to RunHandler)
427
429
  */
@@ -639,4 +641,4 @@ declare class ProxiedCopilotRuntimeAgent extends HttpAgent {
639
641
 
640
642
  declare function completePartialMarkdown(input: string): string;
641
643
 
642
- 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 CopilotRuntimeTransport, type DynamicSuggestionsConfig, type FrontendTool, ProxiedCopilotRuntimeAgent, type ProxiedCopilotRuntimeAgentConfig, RunHandler, StateManager, type StaticSuggestionsConfig, type Suggestion, type SuggestionAvailability, SuggestionEngine, type SuggestionsConfig, ToolCallStatus, completePartialMarkdown };
644
+ 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 };
package/dist/index.js CHANGED
@@ -1,11 +1,46 @@
1
- 'use strict';
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
19
 
3
- var client = require('@ag-ui/client');
4
- var shared = require('@copilotkitnext/shared');
5
- var zodToJsonSchema = require('zod-to-json-schema');
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AgentRegistry: () => AgentRegistry,
24
+ ContextStore: () => ContextStore,
25
+ CopilotKitCore: () => CopilotKitCore,
26
+ CopilotKitCoreErrorCode: () => CopilotKitCoreErrorCode,
27
+ CopilotKitCoreRuntimeConnectionStatus: () => CopilotKitCoreRuntimeConnectionStatus,
28
+ ProxiedCopilotRuntimeAgent: () => ProxiedCopilotRuntimeAgent,
29
+ RunHandler: () => RunHandler,
30
+ StateManager: () => StateManager,
31
+ SuggestionEngine: () => SuggestionEngine,
32
+ ToolCallStatus: () => ToolCallStatus,
33
+ completePartialMarkdown: () => completePartialMarkdown
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
6
36
 
7
37
  // src/core/agent-registry.ts
8
- var ProxiedCopilotRuntimeAgent = class extends client.HttpAgent {
38
+ var import_client2 = require("@ag-ui/client");
39
+ var import_shared = require("@copilotkitnext/shared");
40
+
41
+ // src/agent.ts
42
+ var import_client = require("@ag-ui/client");
43
+ var ProxiedCopilotRuntimeAgent = class extends import_client.HttpAgent {
9
44
  runtimeUrl;
10
45
  transport;
11
46
  singleEndpointUrl;
@@ -78,11 +113,11 @@ var ProxiedCopilotRuntimeAgent = class extends client.HttpAgent {
78
113
  const requestInit = this.createSingleRouteRequestInit(input, "agent/connect", {
79
114
  agentId: this.agentId
80
115
  });
81
- const httpEvents2 = client.runHttpRequest(this.singleEndpointUrl, requestInit);
82
- return client.transformHttpEventStream(httpEvents2);
116
+ const httpEvents2 = (0, import_client.runHttpRequest)(this.singleEndpointUrl, requestInit);
117
+ return (0, import_client.transformHttpEventStream)(httpEvents2);
83
118
  }
84
- const httpEvents = client.runHttpRequest(`${this.runtimeUrl}/agent/${this.agentId}/connect`, this.requestInit(input));
85
- return client.transformHttpEventStream(httpEvents);
119
+ const httpEvents = (0, import_client.runHttpRequest)(`${this.runtimeUrl}/agent/${this.agentId}/connect`, this.requestInit(input));
120
+ return (0, import_client.transformHttpEventStream)(httpEvents);
86
121
  }
87
122
  run(input) {
88
123
  if (this.transport === "single") {
@@ -92,8 +127,8 @@ var ProxiedCopilotRuntimeAgent = class extends client.HttpAgent {
92
127
  const requestInit = this.createSingleRouteRequestInit(input, "agent/run", {
93
128
  agentId: this.agentId
94
129
  });
95
- const httpEvents = client.runHttpRequest(this.singleEndpointUrl, requestInit);
96
- return client.transformHttpEventStream(httpEvents);
130
+ const httpEvents = (0, import_client.runHttpRequest)(this.singleEndpointUrl, requestInit);
131
+ return (0, import_client.transformHttpEventStream)(httpEvents);
97
132
  }
98
133
  return super.run(input);
99
134
  }
@@ -236,7 +271,7 @@ var AgentRegistry = class {
236
271
  * Apply current headers to an agent
237
272
  */
238
273
  applyHeadersToAgent(agent) {
239
- if (agent instanceof client.HttpAgent) {
274
+ if (agent instanceof import_client2.HttpAgent) {
240
275
  agent.headers = { ...this.core.headers };
241
276
  }
242
277
  }
@@ -299,7 +334,7 @@ var AgentRegistry = class {
299
334
  await this.notifyRuntimeStatusChanged("error" /* Error */);
300
335
  await this.notifyAgentsChanged();
301
336
  const message = error instanceof Error ? error.message : JSON.stringify(error);
302
- shared.logger.warn(`Failed to load runtime info (${this.runtimeUrl}/info): ${message}`);
337
+ import_shared.logger.warn(`Failed to load runtime info (${this.runtimeUrl}/info): ${message}`);
303
338
  const runtimeError = error instanceof Error ? error : new Error(String(error));
304
339
  await this.core.emitError({
305
340
  error: runtimeError,
@@ -389,6 +424,9 @@ var AgentRegistry = class {
389
424
  );
390
425
  }
391
426
  };
427
+
428
+ // src/core/context-store.ts
429
+ var import_shared2 = require("@copilotkitnext/shared");
392
430
  var ContextStore = class {
393
431
  constructor(core) {
394
432
  this.core = core;
@@ -405,7 +443,7 @@ var ContextStore = class {
405
443
  * @returns The ID of the created context entry
406
444
  */
407
445
  addContext({ description, value }) {
408
- const id = shared.randomUUID();
446
+ const id = (0, import_shared2.randomUUID)();
409
447
  this._context[id] = { description, value };
410
448
  void this.notifySubscribers();
411
449
  return id;
@@ -430,6 +468,9 @@ var ContextStore = class {
430
468
  );
431
469
  }
432
470
  };
471
+
472
+ // src/core/suggestion-engine.ts
473
+ var import_shared3 = require("@copilotkitnext/shared");
433
474
  var SuggestionEngine = class {
434
475
  constructor(core) {
435
476
  this.core = core;
@@ -442,7 +483,7 @@ var SuggestionEngine = class {
442
483
  */
443
484
  initialize(suggestionsConfig) {
444
485
  for (const config of suggestionsConfig) {
445
- this._suggestionsConfig[shared.randomUUID()] = config;
486
+ this._suggestionsConfig[(0, import_shared3.randomUUID)()] = config;
446
487
  }
447
488
  }
448
489
  /**
@@ -450,7 +491,7 @@ var SuggestionEngine = class {
450
491
  * @returns The ID of the created config
451
492
  */
452
493
  addSuggestionsConfig(config) {
453
- const id = shared.randomUUID();
494
+ const id = (0, import_shared3.randomUUID)();
454
495
  this._suggestionsConfig[id] = config;
455
496
  void this.notifySuggestionsConfigChanged();
456
497
  return id;
@@ -481,7 +522,7 @@ var SuggestionEngine = class {
481
522
  if (!this.shouldShowSuggestions(config, messageCount)) {
482
523
  continue;
483
524
  }
484
- const suggestionId = shared.randomUUID();
525
+ const suggestionId = (0, import_shared3.randomUUID)();
485
526
  if (isDynamicSuggestionsConfig(config)) {
486
527
  if (!hasAnySuggestions) {
487
528
  hasAnySuggestions = true;
@@ -615,7 +656,7 @@ var SuggestionEngine = class {
615
656
  for (const toolCall of message.toolCalls) {
616
657
  if (toolCall.function.name === "copilotkitSuggest") {
617
658
  const fullArgs = Array.isArray(toolCall.function.arguments) ? toolCall.function.arguments.join("") : toolCall.function.arguments;
618
- const parsed = shared.partialJSONParse(fullArgs);
659
+ const parsed = (0, import_shared3.partialJSONParse)(fullArgs);
619
660
  if (parsed && typeof parsed === "object" && "suggestions" in parsed) {
620
661
  const parsedSuggestions = parsed.suggestions;
621
662
  if (Array.isArray(parsedSuggestions)) {
@@ -762,15 +803,18 @@ var SUGGEST_TOOL = {
762
803
  description: "The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI."
763
804
  }
764
805
  },
765
- required: ["title", "message"],
766
- additionalProperties: false
806
+ required: ["title", "message"]
767
807
  }
768
808
  }
769
809
  },
770
- required: ["suggestions"],
771
- additionalProperties: false
810
+ required: ["suggestions"]
772
811
  }
773
812
  };
813
+
814
+ // src/core/run-handler.ts
815
+ var import_client3 = require("@ag-ui/client");
816
+ var import_shared4 = require("@copilotkitnext/shared");
817
+ var import_zod_to_json_schema = require("zod-to-json-schema");
774
818
  var RunHandler = class {
775
819
  constructor(core) {
776
820
  this.core = core;
@@ -795,7 +839,7 @@ var RunHandler = class {
795
839
  addTool(tool) {
796
840
  const existingToolIndex = this._tools.findIndex((t) => t.name === tool.name && t.agentId === tool.agentId);
797
841
  if (existingToolIndex !== -1) {
798
- shared.logger.warn(`Tool already exists: '${tool.name}' for agent '${tool.agentId || "global"}', skipping.`);
842
+ import_shared4.logger.warn(`Tool already exists: '${tool.name}' for agent '${tool.agentId || "global"}', skipping.`);
799
843
  return;
800
844
  }
801
845
  this._tools.push(tool);
@@ -837,7 +881,10 @@ var RunHandler = class {
837
881
  */
838
882
  async connectAgent({ agent }) {
839
883
  try {
840
- if (agent instanceof client.HttpAgent) {
884
+ await agent.detachActiveRun();
885
+ agent.setMessages([]);
886
+ agent.setState({});
887
+ if (agent instanceof import_client3.HttpAgent) {
841
888
  agent.headers = { ...this.core.headers };
842
889
  }
843
890
  const runAgentResult = await agent.connectAgent(
@@ -869,7 +916,7 @@ var RunHandler = class {
869
916
  if (agent.agentId) {
870
917
  void this.core.suggestionEngine.clearSuggestions(agent.agentId);
871
918
  }
872
- if (agent instanceof client.HttpAgent) {
919
+ if (agent instanceof import_client3.HttpAgent) {
873
920
  agent.headers = { ...this.core.headers };
874
921
  }
875
922
  if (withMessages) {
@@ -1033,7 +1080,7 @@ var RunHandler = class {
1033
1080
  if (!errorMessage || !isArgumentError) {
1034
1081
  const messageIndex = agent.messages.findIndex((m) => m.id === message.id);
1035
1082
  const toolMessage = {
1036
- id: shared.randomUUID(),
1083
+ id: (0, import_shared4.randomUUID)(),
1037
1084
  role: "tool",
1038
1085
  toolCallId: toolCall.id,
1039
1086
  content: toolCallResult
@@ -1138,7 +1185,7 @@ var RunHandler = class {
1138
1185
  if (!errorMessage || !isArgumentError) {
1139
1186
  const messageIndex = agent.messages.findIndex((m) => m.id === message.id);
1140
1187
  const toolMessage = {
1141
- id: shared.randomUUID(),
1188
+ id: (0, import_shared4.randomUUID)(),
1142
1189
  role: "tool",
1143
1190
  toolCallId: toolCall.id,
1144
1191
  content: toolCallResult
@@ -1199,14 +1246,13 @@ var RunHandler = class {
1199
1246
  };
1200
1247
  var EMPTY_TOOL_SCHEMA = {
1201
1248
  type: "object",
1202
- properties: {},
1203
- additionalProperties: false
1249
+ properties: {}
1204
1250
  };
1205
1251
  function createToolSchema(tool) {
1206
1252
  if (!tool.parameters) {
1207
- return EMPTY_TOOL_SCHEMA;
1253
+ return { ...EMPTY_TOOL_SCHEMA };
1208
1254
  }
1209
- const rawSchema = zodToJsonSchema.zodToJsonSchema(tool.parameters, {
1255
+ const rawSchema = (0, import_zod_to_json_schema.zodToJsonSchema)(tool.parameters, {
1210
1256
  $refStrategy: "none"
1211
1257
  });
1212
1258
  if (!rawSchema || typeof rawSchema !== "object") {
@@ -1219,11 +1265,25 @@ function createToolSchema(tool) {
1219
1265
  if (typeof schema.properties !== "object" || schema.properties === null) {
1220
1266
  schema.properties = {};
1221
1267
  }
1222
- if (schema.additionalProperties === void 0) {
1223
- schema.additionalProperties = false;
1224
- }
1268
+ stripAdditionalProperties(schema);
1225
1269
  return schema;
1226
1270
  }
1271
+ function stripAdditionalProperties(schema) {
1272
+ if (!schema || typeof schema !== "object") {
1273
+ return;
1274
+ }
1275
+ if (Array.isArray(schema)) {
1276
+ schema.forEach(stripAdditionalProperties);
1277
+ return;
1278
+ }
1279
+ const record = schema;
1280
+ if (record.additionalProperties !== void 0) {
1281
+ delete record.additionalProperties;
1282
+ }
1283
+ for (const value of Object.values(record)) {
1284
+ stripAdditionalProperties(value);
1285
+ }
1286
+ }
1227
1287
 
1228
1288
  // src/core/state-manager.ts
1229
1289
  var StateManager = class {
@@ -1619,13 +1679,12 @@ var CopilotKitCore = class {
1619
1679
  */
1620
1680
  subscribe(subscriber) {
1621
1681
  this.subscribers.add(subscriber);
1622
- return () => {
1623
- this.unsubscribe(subscriber);
1682
+ return {
1683
+ unsubscribe: () => {
1684
+ this.subscribers.delete(subscriber);
1685
+ }
1624
1686
  };
1625
1687
  }
1626
- unsubscribe(subscriber) {
1627
- this.subscribers.delete(subscriber);
1628
- }
1629
1688
  /**
1630
1689
  * Agent connectivity (delegated to RunHandler)
1631
1690
  */
@@ -1881,17 +1940,18 @@ ${indent}${fence}`;
1881
1940
  }
1882
1941
  return result;
1883
1942
  }
1884
-
1885
- exports.AgentRegistry = AgentRegistry;
1886
- exports.ContextStore = ContextStore;
1887
- exports.CopilotKitCore = CopilotKitCore;
1888
- exports.CopilotKitCoreErrorCode = CopilotKitCoreErrorCode;
1889
- exports.CopilotKitCoreRuntimeConnectionStatus = CopilotKitCoreRuntimeConnectionStatus;
1890
- exports.ProxiedCopilotRuntimeAgent = ProxiedCopilotRuntimeAgent;
1891
- exports.RunHandler = RunHandler;
1892
- exports.StateManager = StateManager;
1893
- exports.SuggestionEngine = SuggestionEngine;
1894
- exports.ToolCallStatus = ToolCallStatus;
1895
- exports.completePartialMarkdown = completePartialMarkdown;
1896
- //# sourceMappingURL=index.js.map
1943
+ // Annotate the CommonJS export names for ESM import in node:
1944
+ 0 && (module.exports = {
1945
+ AgentRegistry,
1946
+ ContextStore,
1947
+ CopilotKitCore,
1948
+ CopilotKitCoreErrorCode,
1949
+ CopilotKitCoreRuntimeConnectionStatus,
1950
+ ProxiedCopilotRuntimeAgent,
1951
+ RunHandler,
1952
+ StateManager,
1953
+ SuggestionEngine,
1954
+ ToolCallStatus,
1955
+ completePartialMarkdown
1956
+ });
1897
1957
  //# sourceMappingURL=index.js.map