@copilotkitnext/core 0.0.19-threads-and-attachements.1 → 0.0.20
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 +3 -59
- package/dist/index.d.ts +3 -59
- package/dist/index.js +6 -172
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -172
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -158,10 +158,6 @@ interface CopilotKitCoreRunAgentParams {
|
|
|
158
158
|
}
|
|
159
159
|
interface CopilotKitCoreConnectAgentParams {
|
|
160
160
|
agent: AbstractAgent;
|
|
161
|
-
threadId?: string;
|
|
162
|
-
}
|
|
163
|
-
interface CopilotKitCoreDisconnectAgentParams {
|
|
164
|
-
agent: AbstractAgent;
|
|
165
161
|
}
|
|
166
162
|
interface CopilotKitCoreGetToolParams {
|
|
167
163
|
toolName: string;
|
|
@@ -204,8 +200,7 @@ declare class RunHandler {
|
|
|
204
200
|
/**
|
|
205
201
|
* Connect an agent (establish initial connection)
|
|
206
202
|
*/
|
|
207
|
-
connectAgent({ agent
|
|
208
|
-
disconnectAgent({ agent }: CopilotKitCoreDisconnectAgentParams): Promise<void>;
|
|
203
|
+
connectAgent({ agent }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
|
|
209
204
|
/**
|
|
210
205
|
* Run an agent
|
|
211
206
|
*/
|
|
@@ -242,13 +237,6 @@ interface CopilotKitCoreConfig {
|
|
|
242
237
|
headers?: Record<string, string>;
|
|
243
238
|
/** Properties sent as `forwardedProps` to the AG-UI agent. */
|
|
244
239
|
properties?: Record<string, unknown>;
|
|
245
|
-
/**
|
|
246
|
-
* Resource ID(s) for thread access control.
|
|
247
|
-
*
|
|
248
|
-
* This value is sent to the server as a hint for thread scoping.
|
|
249
|
-
* The server's `resolveThreadsScope` validates and enforces access control.
|
|
250
|
-
*/
|
|
251
|
-
resourceId?: string | string[];
|
|
252
240
|
/** Ordered collection of frontend tools available to the core. */
|
|
253
241
|
tools?: FrontendTool<any>[];
|
|
254
242
|
/** Suggestions config for the core. */
|
|
@@ -324,10 +312,6 @@ interface CopilotKitCoreSubscriber {
|
|
|
324
312
|
copilotkit: CopilotKitCore;
|
|
325
313
|
headers: Readonly<Record<string, string>>;
|
|
326
314
|
}) => void | Promise<void>;
|
|
327
|
-
onResourceIdChanged?: (event: {
|
|
328
|
-
copilotkit: CopilotKitCore;
|
|
329
|
-
resourceId: string | string[] | undefined;
|
|
330
|
-
}) => void | Promise<void>;
|
|
331
315
|
onError?: (event: {
|
|
332
316
|
copilotkit: CopilotKitCore;
|
|
333
317
|
error: Error;
|
|
@@ -365,14 +349,13 @@ interface CopilotKitCoreFriendsAccess {
|
|
|
365
349
|
declare class CopilotKitCore {
|
|
366
350
|
private _headers;
|
|
367
351
|
private _properties;
|
|
368
|
-
private _resourceId;
|
|
369
352
|
private subscribers;
|
|
370
353
|
private agentRegistry;
|
|
371
354
|
private contextStore;
|
|
372
355
|
private suggestionEngine;
|
|
373
356
|
private runHandler;
|
|
374
357
|
private stateManager;
|
|
375
|
-
constructor({ runtimeUrl, headers, properties,
|
|
358
|
+
constructor({ runtimeUrl, headers, properties, agents__unsafe_dev_only, tools, suggestionsConfig, }: CopilotKitCoreConfig);
|
|
376
359
|
/**
|
|
377
360
|
* Internal method used by delegate classes and subclasses to notify subscribers
|
|
378
361
|
*/
|
|
@@ -392,14 +375,12 @@ declare class CopilotKitCore {
|
|
|
392
375
|
get runtimeVersion(): string | undefined;
|
|
393
376
|
get headers(): Readonly<Record<string, string>>;
|
|
394
377
|
get properties(): Readonly<Record<string, unknown>>;
|
|
395
|
-
get resourceId(): string | string[] | undefined;
|
|
396
378
|
get runtimeConnectionStatus(): CopilotKitCoreRuntimeConnectionStatus;
|
|
397
379
|
/**
|
|
398
380
|
* Configuration updates
|
|
399
381
|
*/
|
|
400
382
|
setHeaders(headers: Record<string, string>): void;
|
|
401
383
|
setProperties(properties: Record<string, unknown>): void;
|
|
402
|
-
setResourceId(resourceId: string | string[] | undefined): void;
|
|
403
384
|
/**
|
|
404
385
|
* Agent management (delegated to AgentRegistry)
|
|
405
386
|
*/
|
|
@@ -437,7 +418,6 @@ declare class CopilotKitCore {
|
|
|
437
418
|
*/
|
|
438
419
|
connectAgent(params: CopilotKitCoreConnectAgentParams): Promise<_ag_ui_client.RunAgentResult>;
|
|
439
420
|
stopAgent(params: CopilotKitCoreStopAgentParams): void;
|
|
440
|
-
disconnectAgent(params: CopilotKitCoreDisconnectAgentParams): Promise<void>;
|
|
441
421
|
runAgent(params: CopilotKitCoreRunAgentParams): Promise<_ag_ui_client.RunAgentResult>;
|
|
442
422
|
/**
|
|
443
423
|
* State management (delegated to StateManager)
|
|
@@ -445,42 +425,6 @@ declare class CopilotKitCore {
|
|
|
445
425
|
getStateByRun(agentId: string, threadId: string, runId: string): State | undefined;
|
|
446
426
|
getRunIdForMessage(agentId: string, threadId: string, messageId: string): string | undefined;
|
|
447
427
|
getRunIdsForThread(agentId: string, threadId: string): string[];
|
|
448
|
-
/**
|
|
449
|
-
* Helper to format resourceId for HTTP header transport.
|
|
450
|
-
* Encodes each value with encodeURIComponent and joins with comma.
|
|
451
|
-
*/
|
|
452
|
-
private formatResourceIdHeader;
|
|
453
|
-
/**
|
|
454
|
-
* Get headers with resourceId header included (if resourceId is set).
|
|
455
|
-
* Used internally by RunHandler for HttpAgent requests.
|
|
456
|
-
*/
|
|
457
|
-
getHeadersWithResourceId(): Record<string, string>;
|
|
458
|
-
/**
|
|
459
|
-
* Thread management
|
|
460
|
-
*/
|
|
461
|
-
listThreads(params?: {
|
|
462
|
-
limit?: number;
|
|
463
|
-
offset?: number;
|
|
464
|
-
}): Promise<{
|
|
465
|
-
threads: Array<{
|
|
466
|
-
threadId: string;
|
|
467
|
-
createdAt: number;
|
|
468
|
-
lastActivityAt: number;
|
|
469
|
-
isRunning: boolean;
|
|
470
|
-
messageCount: number;
|
|
471
|
-
firstMessage?: string;
|
|
472
|
-
}>;
|
|
473
|
-
total: number;
|
|
474
|
-
}>;
|
|
475
|
-
getThreadMetadata(threadId: string): Promise<{
|
|
476
|
-
threadId: string;
|
|
477
|
-
createdAt: number;
|
|
478
|
-
lastActivityAt: number;
|
|
479
|
-
isRunning: boolean;
|
|
480
|
-
messageCount: number;
|
|
481
|
-
firstMessage?: string;
|
|
482
|
-
} | null>;
|
|
483
|
-
deleteThread(threadId: string): Promise<void>;
|
|
484
428
|
/**
|
|
485
429
|
* Internal method used by RunHandler to build frontend tools
|
|
486
430
|
*/
|
|
@@ -681,4 +625,4 @@ declare class ProxiedCopilotRuntimeAgent extends HttpAgent {
|
|
|
681
625
|
|
|
682
626
|
declare function completePartialMarkdown(input: string): string;
|
|
683
627
|
|
|
684
|
-
export { AgentRegistry, ContextStore, CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams,
|
|
628
|
+
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 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
|
@@ -158,10 +158,6 @@ interface CopilotKitCoreRunAgentParams {
|
|
|
158
158
|
}
|
|
159
159
|
interface CopilotKitCoreConnectAgentParams {
|
|
160
160
|
agent: AbstractAgent;
|
|
161
|
-
threadId?: string;
|
|
162
|
-
}
|
|
163
|
-
interface CopilotKitCoreDisconnectAgentParams {
|
|
164
|
-
agent: AbstractAgent;
|
|
165
161
|
}
|
|
166
162
|
interface CopilotKitCoreGetToolParams {
|
|
167
163
|
toolName: string;
|
|
@@ -204,8 +200,7 @@ declare class RunHandler {
|
|
|
204
200
|
/**
|
|
205
201
|
* Connect an agent (establish initial connection)
|
|
206
202
|
*/
|
|
207
|
-
connectAgent({ agent
|
|
208
|
-
disconnectAgent({ agent }: CopilotKitCoreDisconnectAgentParams): Promise<void>;
|
|
203
|
+
connectAgent({ agent }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
|
|
209
204
|
/**
|
|
210
205
|
* Run an agent
|
|
211
206
|
*/
|
|
@@ -242,13 +237,6 @@ interface CopilotKitCoreConfig {
|
|
|
242
237
|
headers?: Record<string, string>;
|
|
243
238
|
/** Properties sent as `forwardedProps` to the AG-UI agent. */
|
|
244
239
|
properties?: Record<string, unknown>;
|
|
245
|
-
/**
|
|
246
|
-
* Resource ID(s) for thread access control.
|
|
247
|
-
*
|
|
248
|
-
* This value is sent to the server as a hint for thread scoping.
|
|
249
|
-
* The server's `resolveThreadsScope` validates and enforces access control.
|
|
250
|
-
*/
|
|
251
|
-
resourceId?: string | string[];
|
|
252
240
|
/** Ordered collection of frontend tools available to the core. */
|
|
253
241
|
tools?: FrontendTool<any>[];
|
|
254
242
|
/** Suggestions config for the core. */
|
|
@@ -324,10 +312,6 @@ interface CopilotKitCoreSubscriber {
|
|
|
324
312
|
copilotkit: CopilotKitCore;
|
|
325
313
|
headers: Readonly<Record<string, string>>;
|
|
326
314
|
}) => void | Promise<void>;
|
|
327
|
-
onResourceIdChanged?: (event: {
|
|
328
|
-
copilotkit: CopilotKitCore;
|
|
329
|
-
resourceId: string | string[] | undefined;
|
|
330
|
-
}) => void | Promise<void>;
|
|
331
315
|
onError?: (event: {
|
|
332
316
|
copilotkit: CopilotKitCore;
|
|
333
317
|
error: Error;
|
|
@@ -365,14 +349,13 @@ interface CopilotKitCoreFriendsAccess {
|
|
|
365
349
|
declare class CopilotKitCore {
|
|
366
350
|
private _headers;
|
|
367
351
|
private _properties;
|
|
368
|
-
private _resourceId;
|
|
369
352
|
private subscribers;
|
|
370
353
|
private agentRegistry;
|
|
371
354
|
private contextStore;
|
|
372
355
|
private suggestionEngine;
|
|
373
356
|
private runHandler;
|
|
374
357
|
private stateManager;
|
|
375
|
-
constructor({ runtimeUrl, headers, properties,
|
|
358
|
+
constructor({ runtimeUrl, headers, properties, agents__unsafe_dev_only, tools, suggestionsConfig, }: CopilotKitCoreConfig);
|
|
376
359
|
/**
|
|
377
360
|
* Internal method used by delegate classes and subclasses to notify subscribers
|
|
378
361
|
*/
|
|
@@ -392,14 +375,12 @@ declare class CopilotKitCore {
|
|
|
392
375
|
get runtimeVersion(): string | undefined;
|
|
393
376
|
get headers(): Readonly<Record<string, string>>;
|
|
394
377
|
get properties(): Readonly<Record<string, unknown>>;
|
|
395
|
-
get resourceId(): string | string[] | undefined;
|
|
396
378
|
get runtimeConnectionStatus(): CopilotKitCoreRuntimeConnectionStatus;
|
|
397
379
|
/**
|
|
398
380
|
* Configuration updates
|
|
399
381
|
*/
|
|
400
382
|
setHeaders(headers: Record<string, string>): void;
|
|
401
383
|
setProperties(properties: Record<string, unknown>): void;
|
|
402
|
-
setResourceId(resourceId: string | string[] | undefined): void;
|
|
403
384
|
/**
|
|
404
385
|
* Agent management (delegated to AgentRegistry)
|
|
405
386
|
*/
|
|
@@ -437,7 +418,6 @@ declare class CopilotKitCore {
|
|
|
437
418
|
*/
|
|
438
419
|
connectAgent(params: CopilotKitCoreConnectAgentParams): Promise<_ag_ui_client.RunAgentResult>;
|
|
439
420
|
stopAgent(params: CopilotKitCoreStopAgentParams): void;
|
|
440
|
-
disconnectAgent(params: CopilotKitCoreDisconnectAgentParams): Promise<void>;
|
|
441
421
|
runAgent(params: CopilotKitCoreRunAgentParams): Promise<_ag_ui_client.RunAgentResult>;
|
|
442
422
|
/**
|
|
443
423
|
* State management (delegated to StateManager)
|
|
@@ -445,42 +425,6 @@ declare class CopilotKitCore {
|
|
|
445
425
|
getStateByRun(agentId: string, threadId: string, runId: string): State | undefined;
|
|
446
426
|
getRunIdForMessage(agentId: string, threadId: string, messageId: string): string | undefined;
|
|
447
427
|
getRunIdsForThread(agentId: string, threadId: string): string[];
|
|
448
|
-
/**
|
|
449
|
-
* Helper to format resourceId for HTTP header transport.
|
|
450
|
-
* Encodes each value with encodeURIComponent and joins with comma.
|
|
451
|
-
*/
|
|
452
|
-
private formatResourceIdHeader;
|
|
453
|
-
/**
|
|
454
|
-
* Get headers with resourceId header included (if resourceId is set).
|
|
455
|
-
* Used internally by RunHandler for HttpAgent requests.
|
|
456
|
-
*/
|
|
457
|
-
getHeadersWithResourceId(): Record<string, string>;
|
|
458
|
-
/**
|
|
459
|
-
* Thread management
|
|
460
|
-
*/
|
|
461
|
-
listThreads(params?: {
|
|
462
|
-
limit?: number;
|
|
463
|
-
offset?: number;
|
|
464
|
-
}): Promise<{
|
|
465
|
-
threads: Array<{
|
|
466
|
-
threadId: string;
|
|
467
|
-
createdAt: number;
|
|
468
|
-
lastActivityAt: number;
|
|
469
|
-
isRunning: boolean;
|
|
470
|
-
messageCount: number;
|
|
471
|
-
firstMessage?: string;
|
|
472
|
-
}>;
|
|
473
|
-
total: number;
|
|
474
|
-
}>;
|
|
475
|
-
getThreadMetadata(threadId: string): Promise<{
|
|
476
|
-
threadId: string;
|
|
477
|
-
createdAt: number;
|
|
478
|
-
lastActivityAt: number;
|
|
479
|
-
isRunning: boolean;
|
|
480
|
-
messageCount: number;
|
|
481
|
-
firstMessage?: string;
|
|
482
|
-
} | null>;
|
|
483
|
-
deleteThread(threadId: string): Promise<void>;
|
|
484
428
|
/**
|
|
485
429
|
* Internal method used by RunHandler to build frontend tools
|
|
486
430
|
*/
|
|
@@ -681,4 +625,4 @@ declare class ProxiedCopilotRuntimeAgent extends HttpAgent {
|
|
|
681
625
|
|
|
682
626
|
declare function completePartialMarkdown(input: string): string;
|
|
683
627
|
|
|
684
|
-
export { AgentRegistry, ContextStore, CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams,
|
|
628
|
+
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 DynamicSuggestionsConfig, type FrontendTool, ProxiedCopilotRuntimeAgent, type ProxiedCopilotRuntimeAgentConfig, RunHandler, StateManager, type StaticSuggestionsConfig, type Suggestion, type SuggestionAvailability, SuggestionEngine, type SuggestionsConfig, ToolCallStatus, completePartialMarkdown };
|
package/dist/index.js
CHANGED
|
@@ -443,7 +443,7 @@ var SuggestionEngine = class {
|
|
|
443
443
|
const clonedAgent = suggestionsProviderAgent.clone();
|
|
444
444
|
agent = clonedAgent;
|
|
445
445
|
agent.agentId = suggestionId;
|
|
446
|
-
agent.threadId =
|
|
446
|
+
agent.threadId = suggestionId;
|
|
447
447
|
agent.messages = JSON.parse(JSON.stringify(suggestionsConsumerAgent.messages));
|
|
448
448
|
agent.state = JSON.parse(JSON.stringify(suggestionsConsumerAgent.state));
|
|
449
449
|
this._suggestions[consumerAgentId] = {
|
|
@@ -751,47 +751,10 @@ var RunHandler = class {
|
|
|
751
751
|
/**
|
|
752
752
|
* Connect an agent (establish initial connection)
|
|
753
753
|
*/
|
|
754
|
-
async connectAgent({ agent
|
|
754
|
+
async connectAgent({ agent }) {
|
|
755
755
|
try {
|
|
756
756
|
if (agent instanceof import_client3.HttpAgent) {
|
|
757
|
-
agent.headers = this.core.
|
|
758
|
-
}
|
|
759
|
-
if (threadId) {
|
|
760
|
-
agent.threadId = threadId;
|
|
761
|
-
}
|
|
762
|
-
const expectedThreadIdKey = "__copilotkitExpectedThreadId";
|
|
763
|
-
const guardKey = "__copilotkitThreadGuard";
|
|
764
|
-
agent[expectedThreadIdKey] = agent.threadId ?? threadId ?? null;
|
|
765
|
-
if (!agent[guardKey]) {
|
|
766
|
-
const guardSubscription = agent.subscribe({
|
|
767
|
-
onEvent: ({ event, input }) => {
|
|
768
|
-
const expectedThreadId = agent[expectedThreadIdKey];
|
|
769
|
-
const eventThreadId = input?.threadId;
|
|
770
|
-
if (!expectedThreadId) {
|
|
771
|
-
console.debug(
|
|
772
|
-
"CopilotKitCore: dropping event - no expected thread (disconnected state)",
|
|
773
|
-
"eventThread:",
|
|
774
|
-
eventThreadId,
|
|
775
|
-
"event:",
|
|
776
|
-
event.type
|
|
777
|
-
);
|
|
778
|
-
return { stopPropagation: true };
|
|
779
|
-
}
|
|
780
|
-
if (eventThreadId && eventThreadId !== expectedThreadId) {
|
|
781
|
-
console.debug(
|
|
782
|
-
"CopilotKitCore: dropping event from stale thread",
|
|
783
|
-
eventThreadId,
|
|
784
|
-
"expected",
|
|
785
|
-
expectedThreadId,
|
|
786
|
-
"event",
|
|
787
|
-
event.type
|
|
788
|
-
);
|
|
789
|
-
return { stopPropagation: true };
|
|
790
|
-
}
|
|
791
|
-
return;
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
agent[guardKey] = guardSubscription;
|
|
757
|
+
agent.headers = { ...this.core.headers };
|
|
795
758
|
}
|
|
796
759
|
const runAgentResult = await agent.connectAgent(
|
|
797
760
|
{
|
|
@@ -800,7 +763,6 @@ var RunHandler = class {
|
|
|
800
763
|
},
|
|
801
764
|
this.createAgentErrorSubscriber(agent)
|
|
802
765
|
);
|
|
803
|
-
agent.__copilotkitExpectedThreadId = agent.threadId ?? threadId ?? null;
|
|
804
766
|
return this.processAgentResult({ runAgentResult, agent });
|
|
805
767
|
} catch (error) {
|
|
806
768
|
const connectError = error instanceof Error ? error : new Error(String(error));
|
|
@@ -816,17 +778,6 @@ var RunHandler = class {
|
|
|
816
778
|
throw error;
|
|
817
779
|
}
|
|
818
780
|
}
|
|
819
|
-
async disconnectAgent({ agent }) {
|
|
820
|
-
const disconnectableAgent = agent;
|
|
821
|
-
agent.__copilotkitExpectedThreadId = null;
|
|
822
|
-
if (typeof disconnectableAgent.disconnectAgent === "function") {
|
|
823
|
-
try {
|
|
824
|
-
await disconnectableAgent.disconnectAgent();
|
|
825
|
-
} catch (error) {
|
|
826
|
-
console.debug("Error during agent disconnection (non-critical):", error);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
781
|
/**
|
|
831
782
|
* Run an agent
|
|
832
783
|
*/
|
|
@@ -835,7 +786,7 @@ var RunHandler = class {
|
|
|
835
786
|
void this.core.suggestionEngine.clearSuggestions(agent.agentId);
|
|
836
787
|
}
|
|
837
788
|
if (agent instanceof import_client3.HttpAgent) {
|
|
838
|
-
agent.headers = this.core.
|
|
789
|
+
agent.headers = { ...this.core.headers };
|
|
839
790
|
}
|
|
840
791
|
if (withMessages) {
|
|
841
792
|
agent.addMessages(withMessages);
|
|
@@ -844,7 +795,8 @@ var RunHandler = class {
|
|
|
844
795
|
const runAgentResult = await agent.runAgent(
|
|
845
796
|
{
|
|
846
797
|
forwardedProps: this.core.properties,
|
|
847
|
-
tools: this.buildFrontendTools(agent.agentId)
|
|
798
|
+
tools: this.buildFrontendTools(agent.agentId),
|
|
799
|
+
context: Object.values(this.core.context)
|
|
848
800
|
},
|
|
849
801
|
this.createAgentErrorSubscriber(agent)
|
|
850
802
|
);
|
|
@@ -1390,7 +1342,6 @@ var CopilotKitCoreRuntimeConnectionStatus = /* @__PURE__ */ ((CopilotKitCoreRunt
|
|
|
1390
1342
|
var CopilotKitCore = class {
|
|
1391
1343
|
_headers;
|
|
1392
1344
|
_properties;
|
|
1393
|
-
_resourceId;
|
|
1394
1345
|
subscribers = /* @__PURE__ */ new Set();
|
|
1395
1346
|
// Delegate classes
|
|
1396
1347
|
agentRegistry;
|
|
@@ -1402,14 +1353,12 @@ var CopilotKitCore = class {
|
|
|
1402
1353
|
runtimeUrl,
|
|
1403
1354
|
headers = {},
|
|
1404
1355
|
properties = {},
|
|
1405
|
-
resourceId,
|
|
1406
1356
|
agents__unsafe_dev_only = {},
|
|
1407
1357
|
tools = [],
|
|
1408
1358
|
suggestionsConfig = []
|
|
1409
1359
|
}) {
|
|
1410
1360
|
this._headers = headers;
|
|
1411
1361
|
this._properties = properties;
|
|
1412
|
-
this._resourceId = resourceId;
|
|
1413
1362
|
this.agentRegistry = new AgentRegistry(this);
|
|
1414
1363
|
this.contextStore = new ContextStore(this);
|
|
1415
1364
|
this.suggestionEngine = new SuggestionEngine(this);
|
|
@@ -1489,9 +1438,6 @@ var CopilotKitCore = class {
|
|
|
1489
1438
|
get properties() {
|
|
1490
1439
|
return this._properties;
|
|
1491
1440
|
}
|
|
1492
|
-
get resourceId() {
|
|
1493
|
-
return this._resourceId;
|
|
1494
|
-
}
|
|
1495
1441
|
get runtimeConnectionStatus() {
|
|
1496
1442
|
return this.agentRegistry.runtimeConnectionStatus;
|
|
1497
1443
|
}
|
|
@@ -1519,16 +1465,6 @@ var CopilotKitCore = class {
|
|
|
1519
1465
|
"Subscriber onPropertiesChanged error:"
|
|
1520
1466
|
);
|
|
1521
1467
|
}
|
|
1522
|
-
setResourceId(resourceId) {
|
|
1523
|
-
this._resourceId = resourceId;
|
|
1524
|
-
void this.notifySubscribers(
|
|
1525
|
-
(subscriber) => subscriber.onResourceIdChanged?.({
|
|
1526
|
-
copilotkit: this,
|
|
1527
|
-
resourceId: this.resourceId
|
|
1528
|
-
}),
|
|
1529
|
-
"Subscriber onResourceIdChanged error:"
|
|
1530
|
-
);
|
|
1531
|
-
}
|
|
1532
1468
|
/**
|
|
1533
1469
|
* Agent management (delegated to AgentRegistry)
|
|
1534
1470
|
*/
|
|
@@ -1607,9 +1543,6 @@ var CopilotKitCore = class {
|
|
|
1607
1543
|
stopAgent(params) {
|
|
1608
1544
|
params.agent.abortRun();
|
|
1609
1545
|
}
|
|
1610
|
-
async disconnectAgent(params) {
|
|
1611
|
-
await this.runHandler.disconnectAgent(params);
|
|
1612
|
-
}
|
|
1613
1546
|
async runAgent(params) {
|
|
1614
1547
|
return this.runHandler.runAgent(params);
|
|
1615
1548
|
}
|
|
@@ -1625,105 +1558,6 @@ var CopilotKitCore = class {
|
|
|
1625
1558
|
getRunIdsForThread(agentId, threadId) {
|
|
1626
1559
|
return this.stateManager.getRunIdsForThread(agentId, threadId);
|
|
1627
1560
|
}
|
|
1628
|
-
/**
|
|
1629
|
-
* Helper to format resourceId for HTTP header transport.
|
|
1630
|
-
* Encodes each value with encodeURIComponent and joins with comma.
|
|
1631
|
-
*/
|
|
1632
|
-
formatResourceIdHeader() {
|
|
1633
|
-
if (!this._resourceId) {
|
|
1634
|
-
return void 0;
|
|
1635
|
-
}
|
|
1636
|
-
const ids = Array.isArray(this._resourceId) ? this._resourceId : [this._resourceId];
|
|
1637
|
-
return ids.map((id) => encodeURIComponent(id)).join(",");
|
|
1638
|
-
}
|
|
1639
|
-
/**
|
|
1640
|
-
* Get headers with resourceId header included (if resourceId is set).
|
|
1641
|
-
* Used internally by RunHandler for HttpAgent requests.
|
|
1642
|
-
*/
|
|
1643
|
-
getHeadersWithResourceId() {
|
|
1644
|
-
const resourceIdHeader = this.formatResourceIdHeader();
|
|
1645
|
-
return {
|
|
1646
|
-
...this.headers,
|
|
1647
|
-
...resourceIdHeader && { "X-CopilotKit-Resource-ID": resourceIdHeader }
|
|
1648
|
-
};
|
|
1649
|
-
}
|
|
1650
|
-
/**
|
|
1651
|
-
* Thread management
|
|
1652
|
-
*/
|
|
1653
|
-
async listThreads(params) {
|
|
1654
|
-
const runtimeUrl = this.runtimeUrl;
|
|
1655
|
-
if (!runtimeUrl) {
|
|
1656
|
-
throw new Error("Runtime URL is required to list threads");
|
|
1657
|
-
}
|
|
1658
|
-
const baseUrl = runtimeUrl.endsWith("/") ? runtimeUrl.slice(0, -1) : runtimeUrl;
|
|
1659
|
-
const urlString = `${baseUrl}/threads`;
|
|
1660
|
-
const queryParams = new URLSearchParams();
|
|
1661
|
-
if (params?.limit !== void 0) {
|
|
1662
|
-
queryParams.set("limit", params.limit.toString());
|
|
1663
|
-
}
|
|
1664
|
-
if (params?.offset !== void 0) {
|
|
1665
|
-
queryParams.set("offset", params.offset.toString());
|
|
1666
|
-
}
|
|
1667
|
-
const queryString = queryParams.toString();
|
|
1668
|
-
const fullUrl = queryString ? `${urlString}?${queryString}` : urlString;
|
|
1669
|
-
const resourceIdHeader = this.formatResourceIdHeader();
|
|
1670
|
-
const response = await fetch(fullUrl, {
|
|
1671
|
-
method: "GET",
|
|
1672
|
-
headers: {
|
|
1673
|
-
"Content-Type": "application/json",
|
|
1674
|
-
...this.headers,
|
|
1675
|
-
...resourceIdHeader && { "X-CopilotKit-Resource-ID": resourceIdHeader }
|
|
1676
|
-
}
|
|
1677
|
-
});
|
|
1678
|
-
if (!response.ok) {
|
|
1679
|
-
throw new Error(`Failed to list threads: ${response.statusText}`);
|
|
1680
|
-
}
|
|
1681
|
-
return await response.json();
|
|
1682
|
-
}
|
|
1683
|
-
async getThreadMetadata(threadId) {
|
|
1684
|
-
const runtimeUrl = this.runtimeUrl;
|
|
1685
|
-
if (!runtimeUrl) {
|
|
1686
|
-
throw new Error("Runtime URL is required to get thread metadata");
|
|
1687
|
-
}
|
|
1688
|
-
const baseUrl = runtimeUrl.endsWith("/") ? runtimeUrl.slice(0, -1) : runtimeUrl;
|
|
1689
|
-
const fullUrl = `${baseUrl}/threads/${threadId}`;
|
|
1690
|
-
const resourceIdHeader = this.formatResourceIdHeader();
|
|
1691
|
-
const response = await fetch(fullUrl, {
|
|
1692
|
-
method: "GET",
|
|
1693
|
-
headers: {
|
|
1694
|
-
"Content-Type": "application/json",
|
|
1695
|
-
...this.headers,
|
|
1696
|
-
...resourceIdHeader && { "X-CopilotKit-Resource-ID": resourceIdHeader }
|
|
1697
|
-
}
|
|
1698
|
-
});
|
|
1699
|
-
if (response.status === 404) {
|
|
1700
|
-
return null;
|
|
1701
|
-
}
|
|
1702
|
-
if (!response.ok) {
|
|
1703
|
-
throw new Error(`Failed to get thread metadata: ${response.statusText}`);
|
|
1704
|
-
}
|
|
1705
|
-
return await response.json();
|
|
1706
|
-
}
|
|
1707
|
-
async deleteThread(threadId) {
|
|
1708
|
-
const runtimeUrl = this.runtimeUrl;
|
|
1709
|
-
if (!runtimeUrl) {
|
|
1710
|
-
throw new Error("Runtime URL is required to delete a thread");
|
|
1711
|
-
}
|
|
1712
|
-
const baseUrl = runtimeUrl.endsWith("/") ? runtimeUrl.slice(0, -1) : runtimeUrl;
|
|
1713
|
-
const fullUrl = `${baseUrl}/threads/${threadId}`;
|
|
1714
|
-
const resourceIdHeader = this.formatResourceIdHeader();
|
|
1715
|
-
const response = await fetch(fullUrl, {
|
|
1716
|
-
method: "DELETE",
|
|
1717
|
-
headers: {
|
|
1718
|
-
"Content-Type": "application/json",
|
|
1719
|
-
...this.headers,
|
|
1720
|
-
...resourceIdHeader && { "X-CopilotKit-Resource-ID": resourceIdHeader }
|
|
1721
|
-
}
|
|
1722
|
-
});
|
|
1723
|
-
if (!response.ok) {
|
|
1724
|
-
throw new Error(`Failed to delete thread: ${response.statusText}`);
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
1561
|
/**
|
|
1728
1562
|
* Internal method used by RunHandler to build frontend tools
|
|
1729
1563
|
*/
|