@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
|
@@ -337,6 +337,33 @@ function createEmptyAssistantMessage(id) {
|
|
|
337
337
|
};
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
+
// src/core/utils/resolvable.ts
|
|
341
|
+
function isGetter(value) {
|
|
342
|
+
return typeof value === "function";
|
|
343
|
+
}
|
|
344
|
+
async function resolveValue(value) {
|
|
345
|
+
if (!isGetter(value)) {
|
|
346
|
+
return value;
|
|
347
|
+
}
|
|
348
|
+
try {
|
|
349
|
+
return await value();
|
|
350
|
+
} catch (error) {
|
|
351
|
+
console.error("[Copilot SDK] Error resolving dynamic config value:", error);
|
|
352
|
+
throw error;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async function resolveValues(values) {
|
|
356
|
+
const entries = Object.entries(values);
|
|
357
|
+
const hasGetters = entries.some(([, v]) => isGetter(v));
|
|
358
|
+
if (!hasGetters) {
|
|
359
|
+
return values;
|
|
360
|
+
}
|
|
361
|
+
const resolved = await Promise.all(
|
|
362
|
+
entries.map(async ([key, val]) => [key, await resolveValue(val)])
|
|
363
|
+
);
|
|
364
|
+
return Object.fromEntries(resolved);
|
|
365
|
+
}
|
|
366
|
+
|
|
340
367
|
// src/chat/adapters/HttpTransport.ts
|
|
341
368
|
var HttpTransport = class {
|
|
342
369
|
constructor(config) {
|
|
@@ -350,16 +377,28 @@ var HttpTransport = class {
|
|
|
350
377
|
}
|
|
351
378
|
/**
|
|
352
379
|
* Send a chat request
|
|
380
|
+
* Resolves dynamic config values (url, headers, body) fresh at request time
|
|
353
381
|
*/
|
|
354
382
|
async send(request) {
|
|
355
383
|
this.abortController = new AbortController();
|
|
356
384
|
this.streaming = true;
|
|
357
385
|
try {
|
|
358
|
-
|
|
386
|
+
console.log(
|
|
387
|
+
"[HttpTransport] Config headers type:",
|
|
388
|
+
typeof this.config.headers
|
|
389
|
+
);
|
|
390
|
+
console.log("[HttpTransport] Config headers:", this.config.headers);
|
|
391
|
+
const resolved = await resolveValues({
|
|
392
|
+
url: this.config.url,
|
|
393
|
+
headers: this.config.headers ?? {},
|
|
394
|
+
configBody: this.config.body ?? {}
|
|
395
|
+
});
|
|
396
|
+
console.log("[HttpTransport] Resolved headers:", resolved.headers);
|
|
397
|
+
const response = await fetch(resolved.url, {
|
|
359
398
|
method: "POST",
|
|
360
399
|
headers: {
|
|
361
400
|
"Content-Type": "application/json",
|
|
362
|
-
...
|
|
401
|
+
...resolved.headers
|
|
363
402
|
},
|
|
364
403
|
body: JSON.stringify({
|
|
365
404
|
messages: request.messages,
|
|
@@ -369,6 +408,7 @@ var HttpTransport = class {
|
|
|
369
408
|
tools: request.tools,
|
|
370
409
|
actions: request.actions,
|
|
371
410
|
streaming: this.config.streaming,
|
|
411
|
+
...resolved.configBody,
|
|
372
412
|
...request.body
|
|
373
413
|
}),
|
|
374
414
|
signal: this.abortController.signal
|
|
@@ -410,6 +450,36 @@ var HttpTransport = class {
|
|
|
410
450
|
isStreaming() {
|
|
411
451
|
return this.streaming;
|
|
412
452
|
}
|
|
453
|
+
/**
|
|
454
|
+
* Update headers configuration
|
|
455
|
+
* Can be static headers or a getter function for dynamic resolution
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* ```typescript
|
|
459
|
+
* // Static
|
|
460
|
+
* transport.setHeaders({ "x-api-key": "new-key" });
|
|
461
|
+
*
|
|
462
|
+
* // Dynamic (resolved fresh on each request)
|
|
463
|
+
* transport.setHeaders(() => ({ Authorization: `Bearer ${getToken()}` }));
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
setHeaders(headers) {
|
|
467
|
+
this.config.headers = headers;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Update URL configuration
|
|
471
|
+
* Can be static URL or a getter function for dynamic resolution
|
|
472
|
+
*/
|
|
473
|
+
setUrl(url) {
|
|
474
|
+
this.config.url = url;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Update body configuration
|
|
478
|
+
* Additional properties merged into every request body
|
|
479
|
+
*/
|
|
480
|
+
setBody(body) {
|
|
481
|
+
this.config.body = body;
|
|
482
|
+
}
|
|
413
483
|
/**
|
|
414
484
|
* Create an async iterable from a ReadableStream
|
|
415
485
|
*/
|
|
@@ -533,6 +603,7 @@ var AbstractChat = class {
|
|
|
533
603
|
systemPrompt: init.systemPrompt,
|
|
534
604
|
streaming: init.streaming ?? true,
|
|
535
605
|
headers: init.headers,
|
|
606
|
+
body: init.body,
|
|
536
607
|
threadId: init.threadId,
|
|
537
608
|
debug: init.debug
|
|
538
609
|
};
|
|
@@ -540,6 +611,7 @@ var AbstractChat = class {
|
|
|
540
611
|
this.transport = init.transport ?? new HttpTransport({
|
|
541
612
|
url: init.runtimeUrl,
|
|
542
613
|
headers: init.headers,
|
|
614
|
+
body: init.body,
|
|
543
615
|
streaming: init.streaming ?? true
|
|
544
616
|
});
|
|
545
617
|
this.callbacks = init.callbacks ?? {};
|
|
@@ -805,6 +877,39 @@ var AbstractChat = class {
|
|
|
805
877
|
this.config.systemPrompt = prompt;
|
|
806
878
|
this.debug("System prompt updated", { length: prompt.length });
|
|
807
879
|
}
|
|
880
|
+
/**
|
|
881
|
+
* Set headers configuration
|
|
882
|
+
* Can be static headers or a getter function for dynamic resolution
|
|
883
|
+
*/
|
|
884
|
+
setHeaders(headers) {
|
|
885
|
+
this.config.headers = headers;
|
|
886
|
+
if (this.transport.setHeaders && headers !== void 0) {
|
|
887
|
+
this.transport.setHeaders(headers);
|
|
888
|
+
}
|
|
889
|
+
this.debug("Headers config updated");
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Set URL configuration
|
|
893
|
+
* Can be static URL or a getter function for dynamic resolution
|
|
894
|
+
*/
|
|
895
|
+
setUrl(url) {
|
|
896
|
+
this.config.runtimeUrl = url;
|
|
897
|
+
if (this.transport.setUrl) {
|
|
898
|
+
this.transport.setUrl(url);
|
|
899
|
+
}
|
|
900
|
+
this.debug("URL config updated");
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Set body configuration
|
|
904
|
+
* Additional properties merged into every request body
|
|
905
|
+
*/
|
|
906
|
+
setBody(body) {
|
|
907
|
+
this.config.body = body;
|
|
908
|
+
if (this.transport.setBody && body !== void 0) {
|
|
909
|
+
this.transport.setBody(body);
|
|
910
|
+
}
|
|
911
|
+
this.debug("Body config updated");
|
|
912
|
+
}
|
|
808
913
|
/**
|
|
809
914
|
* Build the request payload
|
|
810
915
|
*/
|
|
@@ -1480,6 +1585,7 @@ var ChatWithTools = class {
|
|
|
1480
1585
|
systemPrompt: config.systemPrompt,
|
|
1481
1586
|
streaming: config.streaming,
|
|
1482
1587
|
headers: config.headers,
|
|
1588
|
+
body: config.body,
|
|
1483
1589
|
threadId: config.threadId,
|
|
1484
1590
|
debug: config.debug,
|
|
1485
1591
|
initialMessages: config.initialMessages,
|
|
@@ -1663,6 +1769,27 @@ var ChatWithTools = class {
|
|
|
1663
1769
|
setSystemPrompt(prompt) {
|
|
1664
1770
|
this.chat.setSystemPrompt(prompt);
|
|
1665
1771
|
}
|
|
1772
|
+
/**
|
|
1773
|
+
* Set headers configuration
|
|
1774
|
+
* Can be static headers or a getter function for dynamic resolution
|
|
1775
|
+
*/
|
|
1776
|
+
setHeaders(headers) {
|
|
1777
|
+
this.chat.setHeaders(headers);
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* Set URL configuration
|
|
1781
|
+
* Can be static URL or a getter function for dynamic resolution
|
|
1782
|
+
*/
|
|
1783
|
+
setUrl(url) {
|
|
1784
|
+
this.chat.setUrl(url);
|
|
1785
|
+
}
|
|
1786
|
+
/**
|
|
1787
|
+
* Set body configuration
|
|
1788
|
+
* Additional properties merged into every request body
|
|
1789
|
+
*/
|
|
1790
|
+
setBody(body) {
|
|
1791
|
+
this.chat.setBody(body);
|
|
1792
|
+
}
|
|
1666
1793
|
// ============================================
|
|
1667
1794
|
// Tool Registration
|
|
1668
1795
|
// ============================================
|
|
@@ -2221,6 +2348,7 @@ function CopilotProvider({
|
|
|
2221
2348
|
onError,
|
|
2222
2349
|
streaming,
|
|
2223
2350
|
headers,
|
|
2351
|
+
body,
|
|
2224
2352
|
debug = false,
|
|
2225
2353
|
maxIterations,
|
|
2226
2354
|
maxIterationsMessage,
|
|
@@ -2265,6 +2393,7 @@ function CopilotProvider({
|
|
|
2265
2393
|
initialMessages: uiInitialMessages,
|
|
2266
2394
|
streaming,
|
|
2267
2395
|
headers,
|
|
2396
|
+
body,
|
|
2268
2397
|
debug,
|
|
2269
2398
|
maxIterations,
|
|
2270
2399
|
maxIterationsMessage
|
|
@@ -2289,6 +2418,24 @@ function CopilotProvider({
|
|
|
2289
2418
|
debugLog("System prompt updated from prop");
|
|
2290
2419
|
}
|
|
2291
2420
|
}, [systemPrompt, debugLog]);
|
|
2421
|
+
react.useEffect(() => {
|
|
2422
|
+
if (chatRef.current && headers !== void 0) {
|
|
2423
|
+
chatRef.current.setHeaders(headers);
|
|
2424
|
+
debugLog("Headers config updated from prop");
|
|
2425
|
+
}
|
|
2426
|
+
}, [headers, debugLog]);
|
|
2427
|
+
react.useEffect(() => {
|
|
2428
|
+
if (chatRef.current && body !== void 0) {
|
|
2429
|
+
chatRef.current.setBody(body);
|
|
2430
|
+
debugLog("Body config updated from prop");
|
|
2431
|
+
}
|
|
2432
|
+
}, [body, debugLog]);
|
|
2433
|
+
react.useEffect(() => {
|
|
2434
|
+
if (chatRef.current && runtimeUrl !== void 0) {
|
|
2435
|
+
chatRef.current.setUrl(runtimeUrl);
|
|
2436
|
+
debugLog("URL config updated from prop");
|
|
2437
|
+
}
|
|
2438
|
+
}, [runtimeUrl, debugLog]);
|
|
2292
2439
|
const messages = react.useSyncExternalStore(
|
|
2293
2440
|
chatRef.current.subscribe,
|
|
2294
2441
|
() => chatRef.current.messages,
|
|
@@ -4342,5 +4489,5 @@ exports.useToolExecutor = useToolExecutor;
|
|
|
4342
4489
|
exports.useToolWithSchema = useToolWithSchema;
|
|
4343
4490
|
exports.useTools = useTools;
|
|
4344
4491
|
exports.useToolsWithSchema = useToolsWithSchema;
|
|
4345
|
-
//# sourceMappingURL=chunk-
|
|
4346
|
-
//# sourceMappingURL=chunk-
|
|
4492
|
+
//# sourceMappingURL=chunk-5UMM5VYB.cjs.map
|
|
4493
|
+
//# sourceMappingURL=chunk-5UMM5VYB.cjs.map
|