@yourgpt/copilot-sdk 2.1.0 → 2.1.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/{chunk-MUZ2RYS2.cjs → chunk-5UMM5VYB.cjs} +151 -4
- package/dist/chunk-5UMM5VYB.cjs.map +1 -0
- package/dist/{chunk-3SP6V22Y.js → chunk-SNI7VN2U.js} +151 -4
- package/dist/chunk-SNI7VN2U.js.map +1 -0
- package/dist/react/index.cjs +42 -42
- package/dist/react/index.d.cts +105 -10
- package/dist/react/index.d.ts +105 -10
- package/dist/react/index.js +1 -1
- package/dist/ui/index.cjs +4 -4
- package/dist/ui/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3SP6V22Y.js.map +0 -1
- package/dist/chunk-MUZ2RYS2.cjs.map +0 -1
|
@@ -315,6 +315,33 @@ function createEmptyAssistantMessage(id) {
|
|
|
315
315
|
};
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
// src/core/utils/resolvable.ts
|
|
319
|
+
function isGetter(value) {
|
|
320
|
+
return typeof value === "function";
|
|
321
|
+
}
|
|
322
|
+
async function resolveValue(value) {
|
|
323
|
+
if (!isGetter(value)) {
|
|
324
|
+
return value;
|
|
325
|
+
}
|
|
326
|
+
try {
|
|
327
|
+
return await value();
|
|
328
|
+
} catch (error) {
|
|
329
|
+
console.error("[Copilot SDK] Error resolving dynamic config value:", error);
|
|
330
|
+
throw error;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
async function resolveValues(values) {
|
|
334
|
+
const entries = Object.entries(values);
|
|
335
|
+
const hasGetters = entries.some(([, v]) => isGetter(v));
|
|
336
|
+
if (!hasGetters) {
|
|
337
|
+
return values;
|
|
338
|
+
}
|
|
339
|
+
const resolved = await Promise.all(
|
|
340
|
+
entries.map(async ([key, val]) => [key, await resolveValue(val)])
|
|
341
|
+
);
|
|
342
|
+
return Object.fromEntries(resolved);
|
|
343
|
+
}
|
|
344
|
+
|
|
318
345
|
// src/chat/adapters/HttpTransport.ts
|
|
319
346
|
var HttpTransport = class {
|
|
320
347
|
constructor(config) {
|
|
@@ -328,16 +355,28 @@ var HttpTransport = class {
|
|
|
328
355
|
}
|
|
329
356
|
/**
|
|
330
357
|
* Send a chat request
|
|
358
|
+
* Resolves dynamic config values (url, headers, body) fresh at request time
|
|
331
359
|
*/
|
|
332
360
|
async send(request) {
|
|
333
361
|
this.abortController = new AbortController();
|
|
334
362
|
this.streaming = true;
|
|
335
363
|
try {
|
|
336
|
-
|
|
364
|
+
console.log(
|
|
365
|
+
"[HttpTransport] Config headers type:",
|
|
366
|
+
typeof this.config.headers
|
|
367
|
+
);
|
|
368
|
+
console.log("[HttpTransport] Config headers:", this.config.headers);
|
|
369
|
+
const resolved = await resolveValues({
|
|
370
|
+
url: this.config.url,
|
|
371
|
+
headers: this.config.headers ?? {},
|
|
372
|
+
configBody: this.config.body ?? {}
|
|
373
|
+
});
|
|
374
|
+
console.log("[HttpTransport] Resolved headers:", resolved.headers);
|
|
375
|
+
const response = await fetch(resolved.url, {
|
|
337
376
|
method: "POST",
|
|
338
377
|
headers: {
|
|
339
378
|
"Content-Type": "application/json",
|
|
340
|
-
...
|
|
379
|
+
...resolved.headers
|
|
341
380
|
},
|
|
342
381
|
body: JSON.stringify({
|
|
343
382
|
messages: request.messages,
|
|
@@ -347,6 +386,7 @@ var HttpTransport = class {
|
|
|
347
386
|
tools: request.tools,
|
|
348
387
|
actions: request.actions,
|
|
349
388
|
streaming: this.config.streaming,
|
|
389
|
+
...resolved.configBody,
|
|
350
390
|
...request.body
|
|
351
391
|
}),
|
|
352
392
|
signal: this.abortController.signal
|
|
@@ -388,6 +428,36 @@ var HttpTransport = class {
|
|
|
388
428
|
isStreaming() {
|
|
389
429
|
return this.streaming;
|
|
390
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* Update headers configuration
|
|
433
|
+
* Can be static headers or a getter function for dynamic resolution
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* ```typescript
|
|
437
|
+
* // Static
|
|
438
|
+
* transport.setHeaders({ "x-api-key": "new-key" });
|
|
439
|
+
*
|
|
440
|
+
* // Dynamic (resolved fresh on each request)
|
|
441
|
+
* transport.setHeaders(() => ({ Authorization: `Bearer ${getToken()}` }));
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
444
|
+
setHeaders(headers) {
|
|
445
|
+
this.config.headers = headers;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Update URL configuration
|
|
449
|
+
* Can be static URL or a getter function for dynamic resolution
|
|
450
|
+
*/
|
|
451
|
+
setUrl(url) {
|
|
452
|
+
this.config.url = url;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Update body configuration
|
|
456
|
+
* Additional properties merged into every request body
|
|
457
|
+
*/
|
|
458
|
+
setBody(body) {
|
|
459
|
+
this.config.body = body;
|
|
460
|
+
}
|
|
391
461
|
/**
|
|
392
462
|
* Create an async iterable from a ReadableStream
|
|
393
463
|
*/
|
|
@@ -511,6 +581,7 @@ var AbstractChat = class {
|
|
|
511
581
|
systemPrompt: init.systemPrompt,
|
|
512
582
|
streaming: init.streaming ?? true,
|
|
513
583
|
headers: init.headers,
|
|
584
|
+
body: init.body,
|
|
514
585
|
threadId: init.threadId,
|
|
515
586
|
debug: init.debug
|
|
516
587
|
};
|
|
@@ -518,6 +589,7 @@ var AbstractChat = class {
|
|
|
518
589
|
this.transport = init.transport ?? new HttpTransport({
|
|
519
590
|
url: init.runtimeUrl,
|
|
520
591
|
headers: init.headers,
|
|
592
|
+
body: init.body,
|
|
521
593
|
streaming: init.streaming ?? true
|
|
522
594
|
});
|
|
523
595
|
this.callbacks = init.callbacks ?? {};
|
|
@@ -783,6 +855,39 @@ var AbstractChat = class {
|
|
|
783
855
|
this.config.systemPrompt = prompt;
|
|
784
856
|
this.debug("System prompt updated", { length: prompt.length });
|
|
785
857
|
}
|
|
858
|
+
/**
|
|
859
|
+
* Set headers configuration
|
|
860
|
+
* Can be static headers or a getter function for dynamic resolution
|
|
861
|
+
*/
|
|
862
|
+
setHeaders(headers) {
|
|
863
|
+
this.config.headers = headers;
|
|
864
|
+
if (this.transport.setHeaders && headers !== void 0) {
|
|
865
|
+
this.transport.setHeaders(headers);
|
|
866
|
+
}
|
|
867
|
+
this.debug("Headers config updated");
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Set URL configuration
|
|
871
|
+
* Can be static URL or a getter function for dynamic resolution
|
|
872
|
+
*/
|
|
873
|
+
setUrl(url) {
|
|
874
|
+
this.config.runtimeUrl = url;
|
|
875
|
+
if (this.transport.setUrl) {
|
|
876
|
+
this.transport.setUrl(url);
|
|
877
|
+
}
|
|
878
|
+
this.debug("URL config updated");
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Set body configuration
|
|
882
|
+
* Additional properties merged into every request body
|
|
883
|
+
*/
|
|
884
|
+
setBody(body) {
|
|
885
|
+
this.config.body = body;
|
|
886
|
+
if (this.transport.setBody && body !== void 0) {
|
|
887
|
+
this.transport.setBody(body);
|
|
888
|
+
}
|
|
889
|
+
this.debug("Body config updated");
|
|
890
|
+
}
|
|
786
891
|
/**
|
|
787
892
|
* Build the request payload
|
|
788
893
|
*/
|
|
@@ -1458,6 +1563,7 @@ var ChatWithTools = class {
|
|
|
1458
1563
|
systemPrompt: config.systemPrompt,
|
|
1459
1564
|
streaming: config.streaming,
|
|
1460
1565
|
headers: config.headers,
|
|
1566
|
+
body: config.body,
|
|
1461
1567
|
threadId: config.threadId,
|
|
1462
1568
|
debug: config.debug,
|
|
1463
1569
|
initialMessages: config.initialMessages,
|
|
@@ -1641,6 +1747,27 @@ var ChatWithTools = class {
|
|
|
1641
1747
|
setSystemPrompt(prompt) {
|
|
1642
1748
|
this.chat.setSystemPrompt(prompt);
|
|
1643
1749
|
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Set headers configuration
|
|
1752
|
+
* Can be static headers or a getter function for dynamic resolution
|
|
1753
|
+
*/
|
|
1754
|
+
setHeaders(headers) {
|
|
1755
|
+
this.chat.setHeaders(headers);
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Set URL configuration
|
|
1759
|
+
* Can be static URL or a getter function for dynamic resolution
|
|
1760
|
+
*/
|
|
1761
|
+
setUrl(url) {
|
|
1762
|
+
this.chat.setUrl(url);
|
|
1763
|
+
}
|
|
1764
|
+
/**
|
|
1765
|
+
* Set body configuration
|
|
1766
|
+
* Additional properties merged into every request body
|
|
1767
|
+
*/
|
|
1768
|
+
setBody(body) {
|
|
1769
|
+
this.chat.setBody(body);
|
|
1770
|
+
}
|
|
1644
1771
|
// ============================================
|
|
1645
1772
|
// Tool Registration
|
|
1646
1773
|
// ============================================
|
|
@@ -2199,6 +2326,7 @@ function CopilotProvider({
|
|
|
2199
2326
|
onError,
|
|
2200
2327
|
streaming,
|
|
2201
2328
|
headers,
|
|
2329
|
+
body,
|
|
2202
2330
|
debug = false,
|
|
2203
2331
|
maxIterations,
|
|
2204
2332
|
maxIterationsMessage,
|
|
@@ -2243,6 +2371,7 @@ function CopilotProvider({
|
|
|
2243
2371
|
initialMessages: uiInitialMessages,
|
|
2244
2372
|
streaming,
|
|
2245
2373
|
headers,
|
|
2374
|
+
body,
|
|
2246
2375
|
debug,
|
|
2247
2376
|
maxIterations,
|
|
2248
2377
|
maxIterationsMessage
|
|
@@ -2267,6 +2396,24 @@ function CopilotProvider({
|
|
|
2267
2396
|
debugLog("System prompt updated from prop");
|
|
2268
2397
|
}
|
|
2269
2398
|
}, [systemPrompt, debugLog]);
|
|
2399
|
+
useEffect(() => {
|
|
2400
|
+
if (chatRef.current && headers !== void 0) {
|
|
2401
|
+
chatRef.current.setHeaders(headers);
|
|
2402
|
+
debugLog("Headers config updated from prop");
|
|
2403
|
+
}
|
|
2404
|
+
}, [headers, debugLog]);
|
|
2405
|
+
useEffect(() => {
|
|
2406
|
+
if (chatRef.current && body !== void 0) {
|
|
2407
|
+
chatRef.current.setBody(body);
|
|
2408
|
+
debugLog("Body config updated from prop");
|
|
2409
|
+
}
|
|
2410
|
+
}, [body, debugLog]);
|
|
2411
|
+
useEffect(() => {
|
|
2412
|
+
if (chatRef.current && runtimeUrl !== void 0) {
|
|
2413
|
+
chatRef.current.setUrl(runtimeUrl);
|
|
2414
|
+
debugLog("URL config updated from prop");
|
|
2415
|
+
}
|
|
2416
|
+
}, [runtimeUrl, debugLog]);
|
|
2270
2417
|
const messages = useSyncExternalStore(
|
|
2271
2418
|
chatRef.current.subscribe,
|
|
2272
2419
|
() => chatRef.current.messages,
|
|
@@ -4280,5 +4427,5 @@ function useChat(config) {
|
|
|
4280
4427
|
}
|
|
4281
4428
|
|
|
4282
4429
|
export { AbstractAgentLoop, AbstractChat, CopilotProvider, ReactChat, ReactChatState, ReactThreadManager, ReactThreadManagerState, createMessageIntentHandler, createPermissionStorage, createReactChat, createReactChatState, createReactThreadManager, createReactThreadManagerState, createSessionPermissionCache, createToolIntentHandler, formatKnowledgeResultsForAI, initialAgentLoopState, searchKnowledgeBase, useAIAction, useAIActions, useAIContext, useAIContexts, useAITools, useAgent, useCapabilities, useChat, useCopilot, useDevLogger, useFeatureSupport, useKnowledgeBase, useMCPClient, useMCPTools, useMCPUIIntents, useSuggestions, useSupportedMediaTypes, useThreadManager, useTool, useToolExecutor, useToolWithSchema, useTools, useToolsWithSchema };
|
|
4283
|
-
//# sourceMappingURL=chunk-
|
|
4284
|
-
//# sourceMappingURL=chunk-
|
|
4430
|
+
//# sourceMappingURL=chunk-SNI7VN2U.js.map
|
|
4431
|
+
//# sourceMappingURL=chunk-SNI7VN2U.js.map
|