@dexto/core 1.16.4 → 1.16.6
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/context/manager.cjs +50 -36
- package/dist/context/manager.d.ts +18 -0
- package/dist/context/manager.d.ts.map +1 -1
- package/dist/context/manager.js +50 -36
- package/dist/llm/auth/index.d.ts +1 -1
- package/dist/llm/auth/index.d.ts.map +1 -1
- package/dist/llm/auth/types.d.ts +14 -0
- package/dist/llm/auth/types.d.ts.map +1 -1
- package/dist/llm/error-codes.cjs +2 -0
- package/dist/llm/error-codes.d.ts +2 -0
- package/dist/llm/error-codes.d.ts.map +1 -1
- package/dist/llm/error-codes.js +2 -0
- package/dist/llm/errors.cjs +27 -0
- package/dist/llm/errors.d.ts +9 -0
- package/dist/llm/errors.d.ts.map +1 -1
- package/dist/llm/errors.js +27 -0
- package/dist/llm/executor/stream-processor.cjs +7 -0
- package/dist/llm/executor/stream-processor.d.ts +1 -0
- package/dist/llm/executor/stream-processor.d.ts.map +1 -1
- package/dist/llm/executor/stream-processor.js +7 -0
- package/dist/llm/executor/tool-output-spill.cjs +46 -14
- package/dist/llm/executor/tool-output-spill.d.ts.map +1 -1
- package/dist/llm/executor/tool-output-spill.js +46 -14
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/services/factory.cjs +204 -14
- package/dist/llm/services/factory.d.ts +1 -1
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +204 -14
- package/dist/tools/tool-output-read.cjs +4 -3
- package/dist/tools/tool-output-read.d.ts.map +1 -1
- package/dist/tools/tool-output-read.js +4 -3
- package/dist/utils/text-boundary.cjs +32 -0
- package/dist/utils/text-boundary.d.ts +3 -0
- package/dist/utils/text-boundary.d.ts.map +1 -0
- package/dist/utils/text-boundary.js +9 -0
- package/package.json +2 -2
package/dist/context/manager.cjs
CHANGED
|
@@ -108,6 +108,15 @@ class ContextManager {
|
|
|
108
108
|
*/
|
|
109
109
|
lastCallMessageCount = null;
|
|
110
110
|
conversationStore;
|
|
111
|
+
/**
|
|
112
|
+
* The assistant message of the reply being streamed. Each streamed delta, tool call and the
|
|
113
|
+
* final usage update changes it, so it is held here and written through instead of being
|
|
114
|
+
* found in the whole stored history every time. Stores copy a message when they save it.
|
|
115
|
+
* It lives for one model step: any other write through this manager, a failed write, and the
|
|
116
|
+
* end of the step (`releaseAssistantMessage`) drop it, so a write by anyone else between
|
|
117
|
+
* steps is read again, never overwritten by this copy.
|
|
118
|
+
*/
|
|
119
|
+
inFlightAssistant = null;
|
|
111
120
|
sessionId;
|
|
112
121
|
/**
|
|
113
122
|
* ResourceManager for resolving blob references in message content.
|
|
@@ -522,22 +531,43 @@ ${prompt}`);
|
|
|
522
531
|
this.logger.debug(`Context cleared for session: ${this.sessionId}`);
|
|
523
532
|
}
|
|
524
533
|
/**
|
|
525
|
-
*
|
|
526
|
-
*
|
|
534
|
+
* Finds the assistant message of the reply being streamed. The one this manager started is
|
|
535
|
+
* held in memory; any other id is found with one read of the history and held from then on.
|
|
527
536
|
*/
|
|
528
|
-
async
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
if (messageIndex === -1) {
|
|
532
|
-
throw import_errors.ContextError.messageNotFound(messageId);
|
|
537
|
+
async loadAssistantMessage(messageId) {
|
|
538
|
+
if (this.inFlightAssistant?.id === messageId) {
|
|
539
|
+
return this.inFlightAssistant;
|
|
533
540
|
}
|
|
534
|
-
const
|
|
541
|
+
const history = await this.conversationStore.listMessages({ sessionId: this.sessionId });
|
|
542
|
+
const message = history.find((m) => m.id === messageId);
|
|
535
543
|
if (!message) {
|
|
536
544
|
throw import_errors.ContextError.messageNotFound(messageId);
|
|
537
545
|
}
|
|
538
|
-
if (
|
|
546
|
+
if (!(0, import_types.isAssistantMessage)(message)) {
|
|
539
547
|
throw import_errors.ContextError.messageNotAssistant(messageId);
|
|
540
548
|
}
|
|
549
|
+
this.inFlightAssistant = message;
|
|
550
|
+
return message;
|
|
551
|
+
}
|
|
552
|
+
/** Ends the streamed reply: the next change to its message reads it from the store again. */
|
|
553
|
+
releaseAssistantMessage() {
|
|
554
|
+
this.inFlightAssistant = null;
|
|
555
|
+
}
|
|
556
|
+
/** Writes the held assistant message through. A failed write drops it, so a retry rereads. */
|
|
557
|
+
async writeAssistantMessage(message) {
|
|
558
|
+
try {
|
|
559
|
+
await this.conversationStore.updateMessage({ sessionId: this.sessionId, message });
|
|
560
|
+
} catch (error) {
|
|
561
|
+
this.inFlightAssistant = null;
|
|
562
|
+
throw error;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Appends text to an existing assistant message.
|
|
567
|
+
* Used for streaming responses.
|
|
568
|
+
*/
|
|
569
|
+
async appendAssistantText(messageId, text) {
|
|
570
|
+
const message = await this.loadAssistantMessage(messageId);
|
|
541
571
|
if (message.content === null) {
|
|
542
572
|
message.content = [{ type: "text", text }];
|
|
543
573
|
} else if (Array.isArray(message.content)) {
|
|
@@ -548,50 +578,28 @@ ${prompt}`);
|
|
|
548
578
|
message.content.push({ type: "text", text });
|
|
549
579
|
}
|
|
550
580
|
}
|
|
551
|
-
await this.
|
|
581
|
+
await this.writeAssistantMessage(message);
|
|
552
582
|
}
|
|
553
583
|
/**
|
|
554
584
|
* Adds a tool call to an existing assistant message.
|
|
555
585
|
* Used for streaming responses.
|
|
556
586
|
*/
|
|
557
587
|
async addToolCall(messageId, toolCall) {
|
|
558
|
-
const
|
|
559
|
-
const messageIndex = history.findIndex((m) => m.id === messageId);
|
|
560
|
-
if (messageIndex === -1) {
|
|
561
|
-
throw import_errors.ContextError.messageNotFound(messageId);
|
|
562
|
-
}
|
|
563
|
-
const message = history[messageIndex];
|
|
564
|
-
if (!message) {
|
|
565
|
-
throw import_errors.ContextError.messageNotFound(messageId);
|
|
566
|
-
}
|
|
567
|
-
if (message.role !== "assistant") {
|
|
568
|
-
throw import_errors.ContextError.messageNotAssistant(messageId);
|
|
569
|
-
}
|
|
588
|
+
const message = await this.loadAssistantMessage(messageId);
|
|
570
589
|
if (!message.toolCalls) {
|
|
571
590
|
message.toolCalls = [];
|
|
572
591
|
}
|
|
573
592
|
message.toolCalls.push(toolCall);
|
|
574
|
-
await this.
|
|
593
|
+
await this.writeAssistantMessage(message);
|
|
575
594
|
}
|
|
576
595
|
/**
|
|
577
596
|
* Updates an existing assistant message with new properties.
|
|
578
597
|
* Used for finalizing streaming responses (e.g. adding token usage).
|
|
579
598
|
*/
|
|
580
599
|
async updateAssistantMessage(messageId, updates) {
|
|
581
|
-
const
|
|
582
|
-
const messageIndex = history.findIndex((m) => m.id === messageId);
|
|
583
|
-
if (messageIndex === -1) {
|
|
584
|
-
throw import_errors.ContextError.messageNotFound(messageId);
|
|
585
|
-
}
|
|
586
|
-
const message = history[messageIndex];
|
|
587
|
-
if (!message) {
|
|
588
|
-
throw import_errors.ContextError.messageNotFound(messageId);
|
|
589
|
-
}
|
|
590
|
-
if (message.role !== "assistant") {
|
|
591
|
-
throw import_errors.ContextError.messageNotAssistant(messageId);
|
|
592
|
-
}
|
|
600
|
+
const message = await this.loadAssistantMessage(messageId);
|
|
593
601
|
Object.assign(message, updates);
|
|
594
|
-
await this.
|
|
602
|
+
await this.writeAssistantMessage(message);
|
|
595
603
|
}
|
|
596
604
|
/**
|
|
597
605
|
* Marks tool messages as compacted (pruned).
|
|
@@ -609,6 +617,7 @@ ${prompt}`);
|
|
|
609
617
|
if (messageIds.length === 0) {
|
|
610
618
|
return 0;
|
|
611
619
|
}
|
|
620
|
+
this.inFlightAssistant = null;
|
|
612
621
|
const history = await this.conversationStore.listMessages({ sessionId: this.sessionId });
|
|
613
622
|
const timestamp = Date.now();
|
|
614
623
|
let markedCount = 0;
|
|
@@ -692,6 +701,7 @@ ${prompt}`);
|
|
|
692
701
|
this.logger.debug(
|
|
693
702
|
`ContextManager: Adding message to conversation store: ${JSON.stringify(message, null, 2)}`
|
|
694
703
|
);
|
|
704
|
+
this.inFlightAssistant = null;
|
|
695
705
|
await this.conversationStore.saveMessage({ sessionId: this.sessionId, message });
|
|
696
706
|
this.logger.debug("ContextManager: Message saved to conversation store", {
|
|
697
707
|
messageId: message.id,
|
|
@@ -759,6 +769,9 @@ ${prompt}`);
|
|
|
759
769
|
if (message.id === void 0) {
|
|
760
770
|
throw import_errors.ContextError.assistantMessageIdMissing();
|
|
761
771
|
}
|
|
772
|
+
if ((0, import_types.isAssistantMessage)(message)) {
|
|
773
|
+
this.inFlightAssistant = message;
|
|
774
|
+
}
|
|
762
775
|
return message.id;
|
|
763
776
|
}
|
|
764
777
|
/**
|
|
@@ -1083,6 +1096,7 @@ ${prompt}`);
|
|
|
1083
1096
|
* Does not reset the system prompt
|
|
1084
1097
|
*/
|
|
1085
1098
|
async resetConversation() {
|
|
1099
|
+
this.inFlightAssistant = null;
|
|
1086
1100
|
await this.conversationStore.clearMessages({ sessionId: this.sessionId });
|
|
1087
1101
|
this.resetActualTokenTracking();
|
|
1088
1102
|
this.logger.debug(
|
|
@@ -73,6 +73,15 @@ export declare class ContextManager<TMessage = unknown> {
|
|
|
73
73
|
*/
|
|
74
74
|
private lastCallMessageCount;
|
|
75
75
|
private conversationStore;
|
|
76
|
+
/**
|
|
77
|
+
* The assistant message of the reply being streamed. Each streamed delta, tool call and the
|
|
78
|
+
* final usage update changes it, so it is held here and written through instead of being
|
|
79
|
+
* found in the whole stored history every time. Stores copy a message when they save it.
|
|
80
|
+
* It lives for one model step: any other write through this manager, a failed write, and the
|
|
81
|
+
* end of the step (`releaseAssistantMessage`) drop it, so a write by anyone else between
|
|
82
|
+
* steps is read again, never overwritten by this copy.
|
|
83
|
+
*/
|
|
84
|
+
private inFlightAssistant;
|
|
76
85
|
private readonly sessionId;
|
|
77
86
|
/**
|
|
78
87
|
* ResourceManager for resolving blob references in message content.
|
|
@@ -212,6 +221,15 @@ export declare class ContextManager<TMessage = unknown> {
|
|
|
212
221
|
* The full history remains in the database for review via /resume or session history.
|
|
213
222
|
*/
|
|
214
223
|
clearContext(): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* Finds the assistant message of the reply being streamed. The one this manager started is
|
|
226
|
+
* held in memory; any other id is found with one read of the history and held from then on.
|
|
227
|
+
*/
|
|
228
|
+
private loadAssistantMessage;
|
|
229
|
+
/** Ends the streamed reply: the next change to its message reads it from the store again. */
|
|
230
|
+
releaseAssistantMessage(): void;
|
|
231
|
+
/** Writes the held assistant message through. A failed write drops it, so a retry rereads. */
|
|
232
|
+
private writeAssistantMessage;
|
|
215
233
|
/**
|
|
216
234
|
* Appends text to an existing assistant message.
|
|
217
235
|
* Used for streaming responses.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/context/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAWpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAE5F,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAIvE,OAAO,EAA0B,KAA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AO,CAAC,MAAM,CAAC;IAwBlB;;;;;;OAMG;IACG,wBAAwB,CAC1B,QAAQ,EAAE,yBAAyB,GACpC,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAKrC;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;CAU3C"}
|
package/dist/context/manager.js
CHANGED
|
@@ -84,6 +84,15 @@ class ContextManager {
|
|
|
84
84
|
*/
|
|
85
85
|
lastCallMessageCount = null;
|
|
86
86
|
conversationStore;
|
|
87
|
+
/**
|
|
88
|
+
* The assistant message of the reply being streamed. Each streamed delta, tool call and the
|
|
89
|
+
* final usage update changes it, so it is held here and written through instead of being
|
|
90
|
+
* found in the whole stored history every time. Stores copy a message when they save it.
|
|
91
|
+
* It lives for one model step: any other write through this manager, a failed write, and the
|
|
92
|
+
* end of the step (`releaseAssistantMessage`) drop it, so a write by anyone else between
|
|
93
|
+
* steps is read again, never overwritten by this copy.
|
|
94
|
+
*/
|
|
95
|
+
inFlightAssistant = null;
|
|
87
96
|
sessionId;
|
|
88
97
|
/**
|
|
89
98
|
* ResourceManager for resolving blob references in message content.
|
|
@@ -498,22 +507,43 @@ ${prompt}`);
|
|
|
498
507
|
this.logger.debug(`Context cleared for session: ${this.sessionId}`);
|
|
499
508
|
}
|
|
500
509
|
/**
|
|
501
|
-
*
|
|
502
|
-
*
|
|
510
|
+
* Finds the assistant message of the reply being streamed. The one this manager started is
|
|
511
|
+
* held in memory; any other id is found with one read of the history and held from then on.
|
|
503
512
|
*/
|
|
504
|
-
async
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
if (messageIndex === -1) {
|
|
508
|
-
throw ContextError.messageNotFound(messageId);
|
|
513
|
+
async loadAssistantMessage(messageId) {
|
|
514
|
+
if (this.inFlightAssistant?.id === messageId) {
|
|
515
|
+
return this.inFlightAssistant;
|
|
509
516
|
}
|
|
510
|
-
const
|
|
517
|
+
const history = await this.conversationStore.listMessages({ sessionId: this.sessionId });
|
|
518
|
+
const message = history.find((m) => m.id === messageId);
|
|
511
519
|
if (!message) {
|
|
512
520
|
throw ContextError.messageNotFound(messageId);
|
|
513
521
|
}
|
|
514
|
-
if (message
|
|
522
|
+
if (!isAssistantMessage(message)) {
|
|
515
523
|
throw ContextError.messageNotAssistant(messageId);
|
|
516
524
|
}
|
|
525
|
+
this.inFlightAssistant = message;
|
|
526
|
+
return message;
|
|
527
|
+
}
|
|
528
|
+
/** Ends the streamed reply: the next change to its message reads it from the store again. */
|
|
529
|
+
releaseAssistantMessage() {
|
|
530
|
+
this.inFlightAssistant = null;
|
|
531
|
+
}
|
|
532
|
+
/** Writes the held assistant message through. A failed write drops it, so a retry rereads. */
|
|
533
|
+
async writeAssistantMessage(message) {
|
|
534
|
+
try {
|
|
535
|
+
await this.conversationStore.updateMessage({ sessionId: this.sessionId, message });
|
|
536
|
+
} catch (error) {
|
|
537
|
+
this.inFlightAssistant = null;
|
|
538
|
+
throw error;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Appends text to an existing assistant message.
|
|
543
|
+
* Used for streaming responses.
|
|
544
|
+
*/
|
|
545
|
+
async appendAssistantText(messageId, text) {
|
|
546
|
+
const message = await this.loadAssistantMessage(messageId);
|
|
517
547
|
if (message.content === null) {
|
|
518
548
|
message.content = [{ type: "text", text }];
|
|
519
549
|
} else if (Array.isArray(message.content)) {
|
|
@@ -524,50 +554,28 @@ ${prompt}`);
|
|
|
524
554
|
message.content.push({ type: "text", text });
|
|
525
555
|
}
|
|
526
556
|
}
|
|
527
|
-
await this.
|
|
557
|
+
await this.writeAssistantMessage(message);
|
|
528
558
|
}
|
|
529
559
|
/**
|
|
530
560
|
* Adds a tool call to an existing assistant message.
|
|
531
561
|
* Used for streaming responses.
|
|
532
562
|
*/
|
|
533
563
|
async addToolCall(messageId, toolCall) {
|
|
534
|
-
const
|
|
535
|
-
const messageIndex = history.findIndex((m) => m.id === messageId);
|
|
536
|
-
if (messageIndex === -1) {
|
|
537
|
-
throw ContextError.messageNotFound(messageId);
|
|
538
|
-
}
|
|
539
|
-
const message = history[messageIndex];
|
|
540
|
-
if (!message) {
|
|
541
|
-
throw ContextError.messageNotFound(messageId);
|
|
542
|
-
}
|
|
543
|
-
if (message.role !== "assistant") {
|
|
544
|
-
throw ContextError.messageNotAssistant(messageId);
|
|
545
|
-
}
|
|
564
|
+
const message = await this.loadAssistantMessage(messageId);
|
|
546
565
|
if (!message.toolCalls) {
|
|
547
566
|
message.toolCalls = [];
|
|
548
567
|
}
|
|
549
568
|
message.toolCalls.push(toolCall);
|
|
550
|
-
await this.
|
|
569
|
+
await this.writeAssistantMessage(message);
|
|
551
570
|
}
|
|
552
571
|
/**
|
|
553
572
|
* Updates an existing assistant message with new properties.
|
|
554
573
|
* Used for finalizing streaming responses (e.g. adding token usage).
|
|
555
574
|
*/
|
|
556
575
|
async updateAssistantMessage(messageId, updates) {
|
|
557
|
-
const
|
|
558
|
-
const messageIndex = history.findIndex((m) => m.id === messageId);
|
|
559
|
-
if (messageIndex === -1) {
|
|
560
|
-
throw ContextError.messageNotFound(messageId);
|
|
561
|
-
}
|
|
562
|
-
const message = history[messageIndex];
|
|
563
|
-
if (!message) {
|
|
564
|
-
throw ContextError.messageNotFound(messageId);
|
|
565
|
-
}
|
|
566
|
-
if (message.role !== "assistant") {
|
|
567
|
-
throw ContextError.messageNotAssistant(messageId);
|
|
568
|
-
}
|
|
576
|
+
const message = await this.loadAssistantMessage(messageId);
|
|
569
577
|
Object.assign(message, updates);
|
|
570
|
-
await this.
|
|
578
|
+
await this.writeAssistantMessage(message);
|
|
571
579
|
}
|
|
572
580
|
/**
|
|
573
581
|
* Marks tool messages as compacted (pruned).
|
|
@@ -585,6 +593,7 @@ ${prompt}`);
|
|
|
585
593
|
if (messageIds.length === 0) {
|
|
586
594
|
return 0;
|
|
587
595
|
}
|
|
596
|
+
this.inFlightAssistant = null;
|
|
588
597
|
const history = await this.conversationStore.listMessages({ sessionId: this.sessionId });
|
|
589
598
|
const timestamp = Date.now();
|
|
590
599
|
let markedCount = 0;
|
|
@@ -668,6 +677,7 @@ ${prompt}`);
|
|
|
668
677
|
this.logger.debug(
|
|
669
678
|
`ContextManager: Adding message to conversation store: ${JSON.stringify(message, null, 2)}`
|
|
670
679
|
);
|
|
680
|
+
this.inFlightAssistant = null;
|
|
671
681
|
await this.conversationStore.saveMessage({ sessionId: this.sessionId, message });
|
|
672
682
|
this.logger.debug("ContextManager: Message saved to conversation store", {
|
|
673
683
|
messageId: message.id,
|
|
@@ -735,6 +745,9 @@ ${prompt}`);
|
|
|
735
745
|
if (message.id === void 0) {
|
|
736
746
|
throw ContextError.assistantMessageIdMissing();
|
|
737
747
|
}
|
|
748
|
+
if (isAssistantMessage(message)) {
|
|
749
|
+
this.inFlightAssistant = message;
|
|
750
|
+
}
|
|
738
751
|
return message.id;
|
|
739
752
|
}
|
|
740
753
|
/**
|
|
@@ -1059,6 +1072,7 @@ ${prompt}`);
|
|
|
1059
1072
|
* Does not reset the system prompt
|
|
1060
1073
|
*/
|
|
1061
1074
|
async resetConversation() {
|
|
1075
|
+
this.inFlightAssistant = null;
|
|
1062
1076
|
await this.conversationStore.clearMessages({ sessionId: this.sessionId });
|
|
1063
1077
|
this.resetActualTokenTracking();
|
|
1064
1078
|
this.logger.debug(
|
package/dist/llm/auth/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { LlmAuthResolver, LlmRuntimeAuthOverrides, ResolveLlmRuntimeAuthInput, } from './types.js';
|
|
1
|
+
export type { LlmAuthResolver, LlmRequestAuth, LlmRuntimeAuthOverrides, ResolveLlmRuntimeAuthInput, } from './types.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/llm/auth/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,eAAe,EACf,uBAAuB,EACvB,0BAA0B,GAC7B,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/llm/auth/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,0BAA0B,GAC7B,MAAM,YAAY,CAAC"}
|
package/dist/llm/auth/types.d.ts
CHANGED
|
@@ -4,8 +4,22 @@ export type LlmRuntimeAuthOverrides = {
|
|
|
4
4
|
baseURL?: string | undefined;
|
|
5
5
|
headers?: Record<string, string> | undefined;
|
|
6
6
|
fetch?: typeof fetch | undefined;
|
|
7
|
+
/** Optional host-owned credential provenance and failure classification for each request. */
|
|
8
|
+
requestAuth?: LlmRequestAuth | undefined;
|
|
7
9
|
auth?: LlmRuntimeAuthInfo | undefined;
|
|
8
10
|
};
|
|
11
|
+
/** Request authentication may replace the API key. The classification body is bounded to 64 KiB. */
|
|
12
|
+
export type LlmRequestAuth = {
|
|
13
|
+
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<{
|
|
14
|
+
response: Response;
|
|
15
|
+
provenance: unknown;
|
|
16
|
+
}>;
|
|
17
|
+
isRetryableResponse: (input: {
|
|
18
|
+
response: Response;
|
|
19
|
+
provenance: unknown;
|
|
20
|
+
signal?: AbortSignal | null;
|
|
21
|
+
}) => Promise<boolean>;
|
|
22
|
+
};
|
|
9
23
|
export type LlmRuntimeAuthInfo = {
|
|
10
24
|
source: 'profile';
|
|
11
25
|
profileId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/llm/auth/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,MAAM,uBAAuB,GAAG;IAClC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,CAAC,EAAE,MAA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AAM,cAAc,GAAG;IACzB,KAAK,EAAE,CACH,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,KACjB,OAAO,CAAC;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC1D,mBAAmB,EAAE,CAAC,KAAK,EAAE;QACzB,QAAQ,EAAE,QAAQ,CAAC;QACnB,UAAU,EAAE,OAAO,CAAC;QACpB,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;KAC/B,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC7B,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACrC,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AAEF,MAAM,WAAW,eAAe;IAC5B,kBAAkB,CAAC,KAAK,EAAE,0BAA0B,GAAG,uBAAuB,GAAG,IAAI,CAAC;CACzF"}
|
package/dist/llm/error-codes.cjs
CHANGED
|
@@ -27,6 +27,8 @@ var LLMErrorCode = /* @__PURE__ */ ((LLMErrorCode2) => {
|
|
|
27
27
|
LLMErrorCode2["API_KEY_CANDIDATE_MISSING"] = "llm_api_key_candidate_missing";
|
|
28
28
|
LLMErrorCode2["BASE_URL_MISSING"] = "llm_base_url_missing";
|
|
29
29
|
LLMErrorCode2["BASE_URL_INVALID"] = "llm_base_url_invalid";
|
|
30
|
+
LLMErrorCode2["RUNTIME_AUTH_UNSUPPORTED"] = "llm_runtime_auth_unsupported";
|
|
31
|
+
LLMErrorCode2["RUNTIME_AUTH_CONFLICT"] = "llm_runtime_auth_conflict";
|
|
30
32
|
LLMErrorCode2["CONFIG_MISSING"] = "llm_config_missing";
|
|
31
33
|
LLMErrorCode2["MODEL_INCOMPATIBLE"] = "llm_model_incompatible";
|
|
32
34
|
LLMErrorCode2["MODEL_UNKNOWN"] = "llm_model_unknown";
|
|
@@ -8,6 +8,8 @@ export declare enum LLMErrorCode {
|
|
|
8
8
|
API_KEY_CANDIDATE_MISSING = "llm_api_key_candidate_missing",
|
|
9
9
|
BASE_URL_MISSING = "llm_base_url_missing",
|
|
10
10
|
BASE_URL_INVALID = "llm_base_url_invalid",
|
|
11
|
+
RUNTIME_AUTH_UNSUPPORTED = "llm_runtime_auth_unsupported",
|
|
12
|
+
RUNTIME_AUTH_CONFLICT = "llm_runtime_auth_conflict",
|
|
11
13
|
CONFIG_MISSING = "llm_config_missing",// Required config (e.g., GOOGLE_VERTEX_PROJECT)
|
|
12
14
|
MODEL_INCOMPATIBLE = "llm_model_incompatible",
|
|
13
15
|
MODEL_UNKNOWN = "llm_model_unknown",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../src/llm/error-codes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,YAAY;IAEpB,eAAe,wBAAwB;IACvC,eAAe,wBAAwB,CAAE,0BAA0B;IACnE,yBAAyB,kCAAkC;IAC3D,gBAAgB,yBAAyB;IACzC,gBAAgB,yBAAyB;IACzC,cAAc,uBAAuB,CAAE,gDAAgD;IAGvF,kBAAkB,2BAA2B;IAC7C,aAAa,sBAAsB;IACnC,oBAAoB,6BAA6B;IAGjD,sBAAsB,+BAA+B;IACrD,uBAAuB,gCAAgC;IACvD,kBAAkB,2BAA2B;IAG7C,eAAe,wBAAwB;IACvC,mBAAmB,4BAA4B;IAC/C,oBAAoB,6BAA6B;IAGjD,aAAa,sBAAsB;IACnC,iBAAiB,0BAA0B;IAC3C,cAAc,uBAAuB,CAAE,0DAA0D;IACjG,cAAc,uBAAuB,CAAE,+CAA+C;IAGtF,oBAAoB,6BAA6B,CAAE,+CAA+C;IAGlG,sBAAsB,+BAA+B;CACxD"}
|
|
1
|
+
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../src/llm/error-codes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,YAAY;IAEpB,eAAe,wBAAwB;IACvC,eAAe,wBAAwB,CAAE,0BAA0B;IACnE,yBAAyB,kCAAkC;IAC3D,gBAAgB,yBAAyB;IACzC,gBAAgB,yBAAyB;IACzC,wBAAwB,iCAAiC;IACzD,qBAAqB,8BAA8B;IACnD,cAAc,uBAAuB,CAAE,gDAAgD;IAGvF,kBAAkB,2BAA2B;IAC7C,aAAa,sBAAsB;IACnC,oBAAoB,6BAA6B;IAGjD,sBAAsB,+BAA+B;IACrD,uBAAuB,gCAAgC;IACvD,kBAAkB,2BAA2B;IAG7C,eAAe,wBAAwB;IACvC,mBAAmB,4BAA4B;IAC/C,oBAAoB,6BAA6B;IAGjD,aAAa,sBAAsB;IACnC,iBAAiB,0BAA0B;IAC3C,cAAc,uBAAuB,CAAE,0DAA0D;IACjG,cAAc,uBAAuB,CAAE,+CAA+C;IAGtF,oBAAoB,6BAA6B,CAAE,+CAA+C;IAGlG,sBAAsB,+BAA+B;CACxD"}
|
package/dist/llm/error-codes.js
CHANGED
|
@@ -5,6 +5,8 @@ var LLMErrorCode = /* @__PURE__ */ ((LLMErrorCode2) => {
|
|
|
5
5
|
LLMErrorCode2["API_KEY_CANDIDATE_MISSING"] = "llm_api_key_candidate_missing";
|
|
6
6
|
LLMErrorCode2["BASE_URL_MISSING"] = "llm_base_url_missing";
|
|
7
7
|
LLMErrorCode2["BASE_URL_INVALID"] = "llm_base_url_invalid";
|
|
8
|
+
LLMErrorCode2["RUNTIME_AUTH_UNSUPPORTED"] = "llm_runtime_auth_unsupported";
|
|
9
|
+
LLMErrorCode2["RUNTIME_AUTH_CONFLICT"] = "llm_runtime_auth_conflict";
|
|
8
10
|
LLMErrorCode2["CONFIG_MISSING"] = "llm_config_missing";
|
|
9
11
|
LLMErrorCode2["MODEL_INCOMPATIBLE"] = "llm_model_incompatible";
|
|
10
12
|
LLMErrorCode2["MODEL_UNKNOWN"] = "llm_model_unknown";
|
package/dist/llm/errors.cjs
CHANGED
|
@@ -46,6 +46,33 @@ class LLMError {
|
|
|
46
46
|
{ provider }
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
|
+
static runtimeAuthUnsupported(provider) {
|
|
50
|
+
return new import_DextoRuntimeError.DextoRuntimeError(
|
|
51
|
+
import_error_codes.LLMErrorCode.RUNTIME_AUTH_UNSUPPORTED,
|
|
52
|
+
import_types.ErrorScope.LLM,
|
|
53
|
+
import_types2.ErrorType.USER,
|
|
54
|
+
`Provider '${provider}' cannot use these runtime gateway overrides`,
|
|
55
|
+
{ provider }
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
static invalidRuntimeBaseURL(provider) {
|
|
59
|
+
return new import_DextoRuntimeError.DextoRuntimeError(
|
|
60
|
+
import_error_codes.LLMErrorCode.BASE_URL_INVALID,
|
|
61
|
+
import_types.ErrorScope.LLM,
|
|
62
|
+
import_types2.ErrorType.USER,
|
|
63
|
+
`Runtime baseURL for '${provider}' cannot be blank`,
|
|
64
|
+
{ provider }
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
static runtimeAuthConflict(provider) {
|
|
68
|
+
return new import_DextoRuntimeError.DextoRuntimeError(
|
|
69
|
+
import_error_codes.LLMErrorCode.RUNTIME_AUTH_CONFLICT,
|
|
70
|
+
import_types.ErrorScope.LLM,
|
|
71
|
+
import_types2.ErrorType.USER,
|
|
72
|
+
"Runtime auth cannot supply both fetch and requestAuth",
|
|
73
|
+
{ provider }
|
|
74
|
+
);
|
|
75
|
+
}
|
|
49
76
|
static missingConfig(provider, configName) {
|
|
50
77
|
return new import_DextoRuntimeError.DextoRuntimeError(
|
|
51
78
|
import_error_codes.LLMErrorCode.CONFIG_MISSING,
|
package/dist/llm/errors.d.ts
CHANGED
|
@@ -15,6 +15,15 @@ export declare class LLMError {
|
|
|
15
15
|
static baseUrlMissing(provider: LLMProvider): DextoRuntimeError<{
|
|
16
16
|
provider: "local" | "openai" | "openai-compatible" | "anthropic" | "google" | "groq" | "xai" | "cohere" | "minimax" | "glm" | "openrouter" | "litellm" | "glama" | "vertex" | "bedrock" | "ollama" | "dexto-nova";
|
|
17
17
|
}>;
|
|
18
|
+
static runtimeAuthUnsupported(provider: LLMProvider): DextoRuntimeError<{
|
|
19
|
+
provider: "local" | "openai" | "openai-compatible" | "anthropic" | "google" | "groq" | "xai" | "cohere" | "minimax" | "glm" | "openrouter" | "litellm" | "glama" | "vertex" | "bedrock" | "ollama" | "dexto-nova";
|
|
20
|
+
}>;
|
|
21
|
+
static invalidRuntimeBaseURL(provider: LLMProvider): DextoRuntimeError<{
|
|
22
|
+
provider: "local" | "openai" | "openai-compatible" | "anthropic" | "google" | "groq" | "xai" | "cohere" | "minimax" | "glm" | "openrouter" | "litellm" | "glama" | "vertex" | "bedrock" | "ollama" | "dexto-nova";
|
|
23
|
+
}>;
|
|
24
|
+
static runtimeAuthConflict(provider: LLMProvider): DextoRuntimeError<{
|
|
25
|
+
provider: "local" | "openai" | "openai-compatible" | "anthropic" | "google" | "groq" | "xai" | "cohere" | "minimax" | "glm" | "openrouter" | "litellm" | "glama" | "vertex" | "bedrock" | "ollama" | "dexto-nova";
|
|
26
|
+
}>;
|
|
18
27
|
static missingConfig(provider: LLMProvider, configName: string): DextoRuntimeError<{
|
|
19
28
|
provider: "local" | "openai" | "openai-compatible" | "anthropic" | "google" | "groq" | "xai" | "cohere" | "minimax" | "glm" | "openrouter" | "litellm" | "glama" | "vertex" | "bedrock" | "ollama" | "dexto-nova";
|
|
20
29
|
configName: string;
|
package/dist/llm/errors.d.ts.map
CHAN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,EAAE,aAAa,EAAE,MAAM;;;;;;;IAchF,MAAM,CAAC,kBAAkB;CAU5B"}
|
package/dist/llm/errors.js
CHANGED
|
@@ -24,6 +24,33 @@ class LLMError {
|
|
|
24
24
|
{ provider }
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
|
+
static runtimeAuthUnsupported(provider) {
|
|
28
|
+
return new DextoRuntimeError(
|
|
29
|
+
LLMErrorCode.RUNTIME_AUTH_UNSUPPORTED,
|
|
30
|
+
ErrorScope.LLM,
|
|
31
|
+
ErrorType.USER,
|
|
32
|
+
`Provider '${provider}' cannot use these runtime gateway overrides`,
|
|
33
|
+
{ provider }
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
static invalidRuntimeBaseURL(provider) {
|
|
37
|
+
return new DextoRuntimeError(
|
|
38
|
+
LLMErrorCode.BASE_URL_INVALID,
|
|
39
|
+
ErrorScope.LLM,
|
|
40
|
+
ErrorType.USER,
|
|
41
|
+
`Runtime baseURL for '${provider}' cannot be blank`,
|
|
42
|
+
{ provider }
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
static runtimeAuthConflict(provider) {
|
|
46
|
+
return new DextoRuntimeError(
|
|
47
|
+
LLMErrorCode.RUNTIME_AUTH_CONFLICT,
|
|
48
|
+
ErrorScope.LLM,
|
|
49
|
+
ErrorType.USER,
|
|
50
|
+
"Runtime auth cannot supply both fetch and requestAuth",
|
|
51
|
+
{ provider }
|
|
52
|
+
);
|
|
53
|
+
}
|
|
27
54
|
static missingConfig(provider, configName) {
|
|
28
55
|
return new DextoRuntimeError(
|
|
29
56
|
LLMErrorCode.CONFIG_MISSING,
|
|
@@ -118,6 +118,13 @@ class StreamProcessor {
|
|
|
118
118
|
partialToolCalls = /* @__PURE__ */ new Map();
|
|
119
119
|
/** Runs one model attempt. `streamFn` must send its request with the given abort signal. */
|
|
120
120
|
async process(streamFn) {
|
|
121
|
+
try {
|
|
122
|
+
return await this.processStream(streamFn);
|
|
123
|
+
} finally {
|
|
124
|
+
this.contextManager.releaseAssistantMessage();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async processStream(streamFn) {
|
|
121
128
|
const startedAtMs = Date.now();
|
|
122
129
|
const setStreamAttribute = (name, value) => {
|
|
123
130
|
import_api.trace.getActiveSpan()?.setAttribute(`llm.stream.${name}`, value);
|
|
@@ -66,6 +66,7 @@ export declare class StreamProcessor {
|
|
|
66
66
|
constructor(contextManager: ContextManager, eventBus: SessionEventBus, abortSignal: AbortSignal, config: StreamProcessorConfig, logger: Logger, streaming?: boolean, emitFatalErrors?: boolean);
|
|
67
67
|
/** Runs one model attempt. `streamFn` must send its request with the given abort signal. */
|
|
68
68
|
process(streamFn: (abortSignal: AbortSignal) => StreamTextResult<VercelToolSet, unknown>): Promise<StreamProcessorResult>;
|
|
69
|
+
private processStream;
|
|
69
70
|
private getCacheTokensFromProviderMetadata;
|
|
70
71
|
private normalizeUsage;
|
|
71
72
|
private getProviderMetadata;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-processor.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/stream-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,IAAI,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAmB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAKvD,OAAO,KAAK,EAAE,WAAW,EAAoB,gBAAgB,EAAc,MAAM,YAAY,CAAC;AAK9F;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,QAAc,CAAC;AA8GxD,MAAM,WAAW,qBAAqB;IAClC,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CA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runs one model attempt. `streamFn` must send its request with the given abort signal. */
|
|
97
97
|
async process(streamFn) {
|
|
98
|
+
try {
|
|
99
|
+
return await this.processStream(streamFn);
|
|
100
|
+
} finally {
|
|
101
|
+
this.contextManager.releaseAssistantMessage();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async processStream(streamFn) {
|
|
98
105
|
const startedAtMs = Date.now();
|
|
99
106
|
const setStreamAttribute = (name, value) => {
|
|
100
107
|
trace.getActiveSpan()?.setAttribute(`llm.stream.${name}`, value);
|