@dexto/core 1.6.26 → 1.7.0
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/agent/DextoAgent.cjs +75 -90
- package/dist/agent/DextoAgent.d.ts +7 -7
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +76 -91
- package/dist/agent/error-codes.cjs +1 -0
- package/dist/agent/error-codes.d.ts +1 -0
- package/dist/agent/error-codes.d.ts.map +1 -1
- package/dist/agent/error-codes.js +1 -0
- package/dist/agent/errors.cjs +13 -0
- package/dist/agent/errors.d.ts +6 -0
- package/dist/agent/errors.d.ts.map +1 -1
- package/dist/agent/errors.js +13 -0
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/schemas.cjs +5 -5
- package/dist/agent/schemas.d.ts +69 -980
- package/dist/agent/schemas.d.ts.map +1 -1
- package/dist/agent/schemas.js +5 -5
- package/dist/agent/types.d.ts +11 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/approval/factory.cjs +1 -0
- package/dist/approval/factory.d.ts.map +1 -1
- package/dist/approval/factory.js +1 -0
- package/dist/approval/manager.cjs +19 -6
- package/dist/approval/manager.d.ts +6 -0
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +19 -6
- package/dist/approval/schemas.cjs +16 -6
- package/dist/approval/schemas.d.ts +373 -1044
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +16 -6
- package/dist/approval/session-approval-store.cjs +1 -1
- package/dist/approval/session-approval-store.d.ts +12 -30
- package/dist/approval/session-approval-store.d.ts.map +1 -1
- package/dist/approval/session-approval-store.js +1 -1
- package/dist/events/index.cjs +210 -75
- package/dist/events/index.d.ts +44 -181
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +206 -74
- package/dist/hooks/manager.cjs +5 -2
- package/dist/hooks/manager.d.ts +2 -0
- package/dist/hooks/manager.d.ts.map +1 -1
- package/dist/hooks/manager.js +5 -2
- package/dist/hooks/types.d.ts +3 -0
- package/dist/hooks/types.d.ts.map +1 -1
- package/dist/index.browser.d.ts +1 -0
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/llm/executor/turn-executor.cjs +8 -4
- package/dist/llm/executor/turn-executor.d.ts +3 -1
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +8 -4
- package/dist/llm/providers/local/schemas.d.ts +102 -262
- package/dist/llm/providers/local/schemas.d.ts.map +1 -1
- package/dist/llm/registry/index.d.ts +5 -3
- package/dist/llm/registry/index.d.ts.map +1 -1
- package/dist/llm/resolver.cjs +0 -1
- package/dist/llm/resolver.d.ts.map +1 -1
- package/dist/llm/resolver.js +0 -1
- package/dist/llm/schemas.d.ts +95 -199
- package/dist/llm/schemas.d.ts.map +1 -1
- package/dist/llm/services/vercel.cjs +29 -6
- package/dist/llm/services/vercel.d.ts +3 -0
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +27 -5
- package/dist/logger/default-logger-factory.d.ts +28 -256
- package/dist/logger/default-logger-factory.d.ts.map +1 -1
- package/dist/logger/v2/schemas.d.ts +18 -120
- package/dist/logger/v2/schemas.d.ts.map +1 -1
- package/dist/mcp/manager.cjs +7 -2
- package/dist/mcp/manager.d.ts +3 -1
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +7 -2
- package/dist/mcp/mcp-client.cjs +71 -62
- package/dist/mcp/mcp-client.d.ts +3 -2
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +71 -62
- package/dist/mcp/schemas.cjs +4 -4
- package/dist/mcp/schemas.d.ts +77 -270
- package/dist/mcp/schemas.d.ts.map +1 -1
- package/dist/mcp/schemas.js +4 -4
- package/dist/memory/schemas.d.ts +37 -117
- package/dist/memory/schemas.d.ts.map +1 -1
- package/dist/prompts/schemas.d.ts +46 -190
- package/dist/prompts/schemas.d.ts.map +1 -1
- package/dist/resources/handlers/filesystem-handler.cjs +22 -3
- package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
- package/dist/resources/handlers/filesystem-handler.js +22 -3
- package/dist/resources/schemas.d.ts +14 -68
- package/dist/resources/schemas.d.ts.map +1 -1
- package/dist/runtime/host-runtime.cjs +163 -0
- package/dist/runtime/host-runtime.d.ts +19 -0
- package/dist/runtime/host-runtime.d.ts.map +1 -0
- package/dist/runtime/host-runtime.js +133 -0
- package/dist/runtime/index.cjs +42 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +21 -0
- package/dist/runtime/run-context.cjs +53 -0
- package/dist/runtime/run-context.d.ts +13 -0
- package/dist/runtime/run-context.d.ts.map +1 -0
- package/dist/runtime/run-context.js +34 -0
- package/dist/session/chat-session.cjs +30 -32
- package/dist/session/chat-session.d.ts +5 -15
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +31 -33
- package/dist/session/error-codes.cjs +1 -0
- package/dist/session/error-codes.d.ts +2 -1
- package/dist/session/error-codes.d.ts.map +1 -1
- package/dist/session/error-codes.js +1 -0
- package/dist/session/errors.cjs +13 -0
- package/dist/session/errors.d.ts +6 -0
- package/dist/session/errors.d.ts.map +1 -1
- package/dist/session/errors.js +13 -0
- package/dist/session/schemas.d.ts +1 -7
- package/dist/session/schemas.d.ts.map +1 -1
- package/dist/systemPrompt/schemas.cjs +2 -10
- package/dist/systemPrompt/schemas.d.ts +53 -343
- package/dist/systemPrompt/schemas.d.ts.map +1 -1
- package/dist/systemPrompt/schemas.js +2 -10
- package/dist/telemetry/decorators.cjs +75 -57
- package/dist/telemetry/decorators.d.ts +2 -0
- package/dist/telemetry/decorators.d.ts.map +1 -1
- package/dist/telemetry/decorators.js +75 -57
- package/dist/telemetry/schemas.cjs +1 -1
- package/dist/telemetry/schemas.d.ts +9 -44
- package/dist/telemetry/schemas.d.ts.map +1 -1
- package/dist/telemetry/schemas.js +1 -1
- package/dist/telemetry/utils.cjs +9 -6
- package/dist/telemetry/utils.d.ts +3 -0
- package/dist/telemetry/utils.d.ts.map +1 -1
- package/dist/telemetry/utils.js +9 -6
- package/dist/tools/schemas.cjs +1 -1
- package/dist/tools/schemas.d.ts +19 -62
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +1 -1
- package/dist/tools/session-tool-preferences-store.d.ts +3 -9
- package/dist/tools/session-tool-preferences-store.d.ts.map +1 -1
- package/dist/tools/tool-manager.cjs +92 -36
- package/dist/tools/tool-manager.d.ts +12 -3
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +92 -36
- package/dist/tools/types.d.ts +7 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/result.cjs +11 -8
- package/dist/utils/result.d.ts +6 -6
- package/dist/utils/result.d.ts.map +1 -1
- package/dist/utils/result.js +12 -9
- package/dist/utils/schema.cjs +6 -2
- package/dist/utils/schema.d.ts +2 -7
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +6 -2
- package/dist/utils/zod-schema-converter.cjs +66 -66
- package/dist/utils/zod-schema-converter.d.ts +3 -2
- package/dist/utils/zod-schema-converter.d.ts.map +1 -1
- package/dist/utils/zod-schema-converter.js +66 -66
- package/package.json +4 -5
package/dist/agent/DextoAgent.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
var _DextoAgent_decorators, _init;
|
|
7
7
|
import { randomUUID } from "crypto";
|
|
8
8
|
import { setMaxListeners } from "events";
|
|
9
|
+
import { ZodError } from "zod";
|
|
9
10
|
import { SkillsContributor } from "../systemPrompt/contributors.js";
|
|
10
11
|
import { expandMessageReferences } from "../resources/index.js";
|
|
11
12
|
import { expandBlobReferences, fileTypesToMimePatterns } from "../context/utils.js";
|
|
@@ -13,7 +14,7 @@ import { StorageManager } from "../storage/index.js";
|
|
|
13
14
|
import { PromptManager } from "../prompts/index.js";
|
|
14
15
|
import { SessionError } from "../session/index.js";
|
|
15
16
|
import { InstrumentClass } from "../telemetry/decorators.js";
|
|
16
|
-
import { trace, context
|
|
17
|
+
import { trace, context } from "@opentelemetry/api";
|
|
17
18
|
import { resolveAndValidateLLMConfig } from "../llm/resolver.js";
|
|
18
19
|
import { validateInputForLLM } from "../llm/validation.js";
|
|
19
20
|
import { LLMError } from "../llm/errors.js";
|
|
@@ -51,6 +52,7 @@ import {
|
|
|
51
52
|
} from "../events/index.js";
|
|
52
53
|
import { safeStringify } from "../utils/safe-stringify.js";
|
|
53
54
|
import { deriveHeuristicTitle, generateSessionTitle } from "../session/title-generator.js";
|
|
55
|
+
import { createAgentRunContext } from "../runtime/run-context.js";
|
|
54
56
|
const requiredServices = [
|
|
55
57
|
"mcpManager",
|
|
56
58
|
"toolManager",
|
|
@@ -286,6 +288,9 @@ Either:
|
|
|
286
288
|
};
|
|
287
289
|
services.toolManager.setToolExecutionContextFactory((baseContext) => ({
|
|
288
290
|
...baseContext,
|
|
291
|
+
...baseContext.runContext?.hostRuntime !== void 0 && {
|
|
292
|
+
hostRuntime: baseContext.runContext.hostRuntime
|
|
293
|
+
},
|
|
289
294
|
agent: this,
|
|
290
295
|
storage: toolExecutionStorage,
|
|
291
296
|
services: toolExecutionServices
|
|
@@ -610,7 +615,8 @@ Either:
|
|
|
610
615
|
...responseEvent.estimatedCost !== void 0 && {
|
|
611
616
|
estimatedCost: responseEvent.estimatedCost
|
|
612
617
|
},
|
|
613
|
-
...responseEvent.pricingStatus && { pricingStatus: responseEvent.pricingStatus }
|
|
618
|
+
...responseEvent.pricingStatus && { pricingStatus: responseEvent.pricingStatus },
|
|
619
|
+
...responseEvent.hostRuntime && { hostRuntime: responseEvent.hostRuntime }
|
|
614
620
|
};
|
|
615
621
|
}
|
|
616
622
|
/**
|
|
@@ -648,8 +654,28 @@ Either:
|
|
|
648
654
|
if (!sessionId) {
|
|
649
655
|
throw AgentError.apiValidationError("sessionId is required");
|
|
650
656
|
}
|
|
657
|
+
if (this.activeStreamControllers.has(sessionId)) {
|
|
658
|
+
throw AgentError.sessionBusy(sessionId);
|
|
659
|
+
}
|
|
651
660
|
const signal = options?.signal;
|
|
652
661
|
const disconnectSignal = options?.disconnectSignal ?? signal;
|
|
662
|
+
let runContext;
|
|
663
|
+
try {
|
|
664
|
+
runContext = createAgentRunContext({
|
|
665
|
+
sessionId,
|
|
666
|
+
hostRuntime: options?.executionContext,
|
|
667
|
+
parentContext: context.active()
|
|
668
|
+
});
|
|
669
|
+
} catch (error) {
|
|
670
|
+
if (error instanceof ZodError) {
|
|
671
|
+
throw AgentError.apiValidationError(
|
|
672
|
+
"executionContext is invalid",
|
|
673
|
+
zodToIssues(error)
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
throw error;
|
|
677
|
+
}
|
|
678
|
+
const executionContext = runContext.hostRuntime;
|
|
653
679
|
let contentParts = typeof content === "string" ? [{ type: "text", text: content }] : [...content];
|
|
654
680
|
const eventQueue = [];
|
|
655
681
|
let completed = false;
|
|
@@ -659,23 +685,36 @@ Either:
|
|
|
659
685
|
const cleanupSignal = controller.signal;
|
|
660
686
|
this.activeStreamControllers.set(sessionId, controller);
|
|
661
687
|
setMaxListeners(30, cleanupSignal);
|
|
662
|
-
const
|
|
688
|
+
const listenerCleanups = [];
|
|
663
689
|
let detachDisconnectAbortListener;
|
|
690
|
+
const addStreamingListener = (event, listener) => {
|
|
691
|
+
this.agentEventBus.on(event, listener, { signal: cleanupSignal });
|
|
692
|
+
listenerCleanups.push(() => {
|
|
693
|
+
this.agentEventBus.off(event, listener);
|
|
694
|
+
});
|
|
695
|
+
};
|
|
664
696
|
const cleanupListeners = () => {
|
|
665
697
|
detachDisconnectAbortListener?.();
|
|
666
698
|
detachDisconnectAbortListener = void 0;
|
|
667
|
-
|
|
699
|
+
this.activeStreamControllers.delete(sessionId);
|
|
700
|
+
if (listenerCleanups.length === 0) {
|
|
668
701
|
return;
|
|
669
702
|
}
|
|
670
|
-
for (const
|
|
671
|
-
|
|
672
|
-
event,
|
|
673
|
-
listener
|
|
674
|
-
);
|
|
703
|
+
for (const removeListener of listenerCleanups) {
|
|
704
|
+
removeListener();
|
|
675
705
|
}
|
|
676
|
-
|
|
677
|
-
this.activeStreamControllers.delete(sessionId);
|
|
706
|
+
listenerCleanups.length = 0;
|
|
678
707
|
};
|
|
708
|
+
try {
|
|
709
|
+
const existingSession = await this.sessionManager.getSession(sessionId, false);
|
|
710
|
+
if (existingSession?.isBusy?.()) {
|
|
711
|
+
throw AgentError.sessionBusy(sessionId);
|
|
712
|
+
}
|
|
713
|
+
} catch (error) {
|
|
714
|
+
cleanupListeners();
|
|
715
|
+
controller.abort();
|
|
716
|
+
throw error;
|
|
717
|
+
}
|
|
679
718
|
if (disconnectSignal) {
|
|
680
719
|
const abortHandler = () => {
|
|
681
720
|
cleanupListeners();
|
|
@@ -688,40 +727,32 @@ Either:
|
|
|
688
727
|
if (data.sessionId !== sessionId) return;
|
|
689
728
|
eventQueue.push({ name: "llm:thinking", ...data });
|
|
690
729
|
};
|
|
691
|
-
|
|
692
|
-
listeners.push({ event: "llm:thinking", listener: thinkingListener });
|
|
730
|
+
addStreamingListener("llm:thinking", thinkingListener);
|
|
693
731
|
const chunkListener = (data) => {
|
|
694
732
|
if (data.sessionId !== sessionId) return;
|
|
695
733
|
eventQueue.push({ name: "llm:chunk", ...data });
|
|
696
734
|
};
|
|
697
|
-
|
|
698
|
-
listeners.push({ event: "llm:chunk", listener: chunkListener });
|
|
735
|
+
addStreamingListener("llm:chunk", chunkListener);
|
|
699
736
|
const responseListener = (data) => {
|
|
700
737
|
if (data.sessionId !== sessionId) return;
|
|
701
738
|
eventQueue.push({ name: "llm:response", ...data });
|
|
702
739
|
};
|
|
703
|
-
|
|
704
|
-
listeners.push({ event: "llm:response", listener: responseListener });
|
|
740
|
+
addStreamingListener("llm:response", responseListener);
|
|
705
741
|
const toolCallListener = (data) => {
|
|
706
742
|
if (data.sessionId !== sessionId) return;
|
|
707
743
|
eventQueue.push({ name: "llm:tool-call", ...data });
|
|
708
744
|
};
|
|
709
|
-
|
|
710
|
-
listeners.push({ event: "llm:tool-call", listener: toolCallListener });
|
|
745
|
+
addStreamingListener("llm:tool-call", toolCallListener);
|
|
711
746
|
const toolCallPartialListener = (data) => {
|
|
712
747
|
if (data.sessionId !== sessionId) return;
|
|
713
748
|
eventQueue.push({ name: "llm:tool-call-partial", ...data });
|
|
714
749
|
};
|
|
715
|
-
|
|
716
|
-
signal: cleanupSignal
|
|
717
|
-
});
|
|
718
|
-
listeners.push({ event: "llm:tool-call-partial", listener: toolCallPartialListener });
|
|
750
|
+
addStreamingListener("llm:tool-call-partial", toolCallPartialListener);
|
|
719
751
|
const toolResultListener = (data) => {
|
|
720
752
|
if (data.sessionId !== sessionId) return;
|
|
721
753
|
eventQueue.push({ name: "llm:tool-result", ...data });
|
|
722
754
|
};
|
|
723
|
-
|
|
724
|
-
listeners.push({ event: "llm:tool-result", listener: toolResultListener });
|
|
755
|
+
addStreamingListener("llm:tool-result", toolResultListener);
|
|
725
756
|
const errorListener = (data) => {
|
|
726
757
|
if (data.sessionId !== sessionId) return;
|
|
727
758
|
if (data.recoverable !== true) {
|
|
@@ -729,117 +760,70 @@ Either:
|
|
|
729
760
|
}
|
|
730
761
|
eventQueue.push({ name: "llm:error", ...data });
|
|
731
762
|
};
|
|
732
|
-
|
|
733
|
-
listeners.push({ event: "llm:error", listener: errorListener });
|
|
763
|
+
addStreamingListener("llm:error", errorListener);
|
|
734
764
|
const unsupportedInputListener = (data) => {
|
|
735
765
|
if (data.sessionId !== sessionId) return;
|
|
736
766
|
eventQueue.push({ name: "llm:unsupported-input", ...data });
|
|
737
767
|
};
|
|
738
|
-
|
|
739
|
-
signal: cleanupSignal
|
|
740
|
-
});
|
|
741
|
-
listeners.push({ event: "llm:unsupported-input", listener: unsupportedInputListener });
|
|
768
|
+
addStreamingListener("llm:unsupported-input", unsupportedInputListener);
|
|
742
769
|
const titleUpdatedListener = (data) => {
|
|
743
770
|
if (data.sessionId !== sessionId) return;
|
|
744
771
|
eventQueue.push({ name: "session:title-updated", ...data });
|
|
745
772
|
};
|
|
746
|
-
|
|
747
|
-
signal: cleanupSignal
|
|
748
|
-
});
|
|
749
|
-
listeners.push({ event: "session:title-updated", listener: titleUpdatedListener });
|
|
773
|
+
addStreamingListener("session:title-updated", titleUpdatedListener);
|
|
750
774
|
const approvalRequestListener = (data) => {
|
|
751
775
|
if (data.sessionId !== sessionId) return;
|
|
752
776
|
eventQueue.push({ name: "approval:request", ...data });
|
|
753
777
|
};
|
|
754
|
-
|
|
755
|
-
signal: cleanupSignal
|
|
756
|
-
});
|
|
757
|
-
listeners.push({ event: "approval:request", listener: approvalRequestListener });
|
|
778
|
+
addStreamingListener("approval:request", approvalRequestListener);
|
|
758
779
|
const approvalResponseListener = (data) => {
|
|
759
780
|
if (data.sessionId !== sessionId) return;
|
|
760
781
|
eventQueue.push({ name: "approval:response", ...data });
|
|
761
782
|
};
|
|
762
|
-
|
|
763
|
-
signal: cleanupSignal
|
|
764
|
-
});
|
|
765
|
-
listeners.push({ event: "approval:response", listener: approvalResponseListener });
|
|
783
|
+
addStreamingListener("approval:response", approvalResponseListener);
|
|
766
784
|
const toolRunningListener = (data) => {
|
|
767
785
|
if (data.sessionId !== sessionId) return;
|
|
768
786
|
eventQueue.push({ name: "tool:running", ...data });
|
|
769
787
|
};
|
|
770
|
-
|
|
771
|
-
signal: cleanupSignal
|
|
772
|
-
});
|
|
773
|
-
listeners.push({ event: "tool:running", listener: toolRunningListener });
|
|
788
|
+
addStreamingListener("tool:running", toolRunningListener);
|
|
774
789
|
const contextCompactingListener = (data) => {
|
|
775
790
|
if (data.sessionId !== sessionId) return;
|
|
776
791
|
eventQueue.push({ name: "context:compacting", ...data });
|
|
777
792
|
};
|
|
778
|
-
|
|
779
|
-
signal: cleanupSignal
|
|
780
|
-
});
|
|
781
|
-
listeners.push({ event: "context:compacting", listener: contextCompactingListener });
|
|
793
|
+
addStreamingListener("context:compacting", contextCompactingListener);
|
|
782
794
|
const contextCompactedListener = (data) => {
|
|
783
795
|
if (data.sessionId !== sessionId) return;
|
|
784
796
|
eventQueue.push({ name: "context:compacted", ...data });
|
|
785
797
|
};
|
|
786
|
-
|
|
787
|
-
signal: cleanupSignal
|
|
788
|
-
});
|
|
789
|
-
listeners.push({ event: "context:compacted", listener: contextCompactedListener });
|
|
798
|
+
addStreamingListener("context:compacted", contextCompactedListener);
|
|
790
799
|
const messageQueuedListener = (data) => {
|
|
791
800
|
if (data.sessionId !== sessionId) return;
|
|
792
801
|
eventQueue.push({ name: "message:queued", ...data });
|
|
793
802
|
};
|
|
794
|
-
|
|
795
|
-
signal: cleanupSignal
|
|
796
|
-
});
|
|
797
|
-
listeners.push({ event: "message:queued", listener: messageQueuedListener });
|
|
803
|
+
addStreamingListener("message:queued", messageQueuedListener);
|
|
798
804
|
const messageDequeuedListener = (data) => {
|
|
799
805
|
if (data.sessionId !== sessionId) return;
|
|
800
806
|
eventQueue.push({ name: "message:dequeued", ...data });
|
|
801
807
|
};
|
|
802
|
-
|
|
803
|
-
signal: cleanupSignal
|
|
804
|
-
});
|
|
805
|
-
listeners.push({ event: "message:dequeued", listener: messageDequeuedListener });
|
|
808
|
+
addStreamingListener("message:dequeued", messageDequeuedListener);
|
|
806
809
|
const serviceEventListener = (data) => {
|
|
807
810
|
if (data.sessionId !== sessionId) return;
|
|
808
811
|
eventQueue.push({ name: "service:event", ...data });
|
|
809
812
|
};
|
|
810
|
-
|
|
811
|
-
signal: cleanupSignal
|
|
812
|
-
});
|
|
813
|
-
listeners.push({ event: "service:event", listener: serviceEventListener });
|
|
813
|
+
addStreamingListener("service:event", serviceEventListener);
|
|
814
814
|
const runCompleteListener = (data) => {
|
|
815
815
|
if (data.sessionId !== sessionId) return;
|
|
816
816
|
sawRunCompleteEvent = true;
|
|
817
817
|
eventQueue.push({ name: "run:complete", ...data });
|
|
818
818
|
completed = true;
|
|
819
819
|
};
|
|
820
|
-
|
|
821
|
-
signal: cleanupSignal
|
|
822
|
-
});
|
|
823
|
-
listeners.push({ event: "run:complete", listener: runCompleteListener });
|
|
820
|
+
addStreamingListener("run:complete", runCompleteListener);
|
|
824
821
|
(async () => {
|
|
825
|
-
const activeContext = context.active();
|
|
826
822
|
const activeSpan = trace.getActiveSpan();
|
|
827
823
|
if (activeSpan) {
|
|
828
824
|
activeSpan.setAttribute("sessionId", sessionId);
|
|
829
825
|
}
|
|
830
|
-
|
|
831
|
-
const baggageEntries = {};
|
|
832
|
-
if (existingBaggage) {
|
|
833
|
-
existingBaggage.getAllEntries().forEach(([key, entry]) => {
|
|
834
|
-
baggageEntries[key] = { ...entry };
|
|
835
|
-
});
|
|
836
|
-
}
|
|
837
|
-
baggageEntries.sessionId = { ...baggageEntries.sessionId, value: sessionId };
|
|
838
|
-
const updatedContext = propagation.setBaggage(
|
|
839
|
-
activeContext,
|
|
840
|
-
propagation.createBaggage(baggageEntries)
|
|
841
|
-
);
|
|
842
|
-
await context.with(updatedContext, async () => {
|
|
826
|
+
await context.with(runContext.telemetryContext, async () => {
|
|
843
827
|
try {
|
|
844
828
|
const llmConfig = this.stateManager.getLLMConfig(sessionId);
|
|
845
829
|
const textParts = contentParts.filter(
|
|
@@ -985,10 +969,10 @@ Either:
|
|
|
985
969
|
}
|
|
986
970
|
validatePromptContentParts(contentParts);
|
|
987
971
|
const session = await this.sessionManager.getSession(sessionId) || await this.sessionManager.createSession(sessionId);
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
);
|
|
972
|
+
await session.stream(contentParts, {
|
|
973
|
+
...signal ? { signal } : {},
|
|
974
|
+
runContext
|
|
975
|
+
});
|
|
992
976
|
this.sessionManager.incrementMessageCount(session.id).catch(
|
|
993
977
|
(error) => this.logger.warn(
|
|
994
978
|
`Failed to increment message count: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -1012,7 +996,8 @@ Either:
|
|
|
1012
996
|
error,
|
|
1013
997
|
recoverable: false,
|
|
1014
998
|
context: "run_failed",
|
|
1015
|
-
sessionId
|
|
999
|
+
sessionId,
|
|
1000
|
+
...executionContext !== void 0 && { hostRuntime: executionContext }
|
|
1016
1001
|
};
|
|
1017
1002
|
eventQueue.push(errorEvent);
|
|
1018
1003
|
}
|
|
@@ -1058,7 +1043,7 @@ Either:
|
|
|
1058
1043
|
async isSessionBusy(sessionId) {
|
|
1059
1044
|
this.ensureStarted();
|
|
1060
1045
|
const session = await this.sessionManager.getSession(sessionId, false);
|
|
1061
|
-
return session?.isBusy() ?? false;
|
|
1046
|
+
return session?.isBusy?.() ?? false;
|
|
1062
1047
|
}
|
|
1063
1048
|
/**
|
|
1064
1049
|
* Queue a message for processing when a session is busy.
|
|
@@ -27,6 +27,7 @@ var AgentErrorCode = /* @__PURE__ */ ((AgentErrorCode2) => {
|
|
|
27
27
|
AgentErrorCode2["STOPPED"] = "agent_stopped";
|
|
28
28
|
AgentErrorCode2["INITIALIZATION_FAILED"] = "agent_initialization_failed";
|
|
29
29
|
AgentErrorCode2["SWITCH_IN_PROGRESS"] = "agent_switch_in_progress";
|
|
30
|
+
AgentErrorCode2["SESSION_BUSY"] = "agent_session_busy";
|
|
30
31
|
AgentErrorCode2["NO_CONFIG_PATH"] = "agent_no_config_path";
|
|
31
32
|
AgentErrorCode2["INVALID_CONFIG"] = "agent_invalid_config";
|
|
32
33
|
AgentErrorCode2["API_VALIDATION_ERROR"] = "agent_api_validation_error";
|
|
@@ -9,6 +9,7 @@ export declare enum AgentErrorCode {
|
|
|
9
9
|
STOPPED = "agent_stopped",
|
|
10
10
|
INITIALIZATION_FAILED = "agent_initialization_failed",
|
|
11
11
|
SWITCH_IN_PROGRESS = "agent_switch_in_progress",
|
|
12
|
+
SESSION_BUSY = "agent_session_busy",
|
|
12
13
|
NO_CONFIG_PATH = "agent_no_config_path",
|
|
13
14
|
INVALID_CONFIG = "agent_invalid_config",
|
|
14
15
|
API_VALIDATION_ERROR = "agent_api_validation_error",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../src/agent/error-codes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,oBAAY,cAAc;IAEtB,WAAW,sBAAsB;IACjC,eAAe,0BAA0B;IACzC,OAAO,kBAAkB;IACzB,qBAAqB,gCAAgC;IACrD,kBAAkB,6BAA6B;
|
|
1
|
+
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../src/agent/error-codes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,oBAAY,cAAc;IAEtB,WAAW,sBAAsB;IACjC,eAAe,0BAA0B;IACzC,OAAO,kBAAkB;IACzB,qBAAqB,gCAAgC;IACrD,kBAAkB,6BAA6B;IAC/C,YAAY,uBAAuB;IAGnC,cAAc,yBAAyB;IACvC,cAAc,yBAAyB;IAGvC,oBAAoB,+BAA+B;IAGnD,aAAa,wBAAwB;CACxC"}
|
|
@@ -5,6 +5,7 @@ var AgentErrorCode = /* @__PURE__ */ ((AgentErrorCode2) => {
|
|
|
5
5
|
AgentErrorCode2["STOPPED"] = "agent_stopped";
|
|
6
6
|
AgentErrorCode2["INITIALIZATION_FAILED"] = "agent_initialization_failed";
|
|
7
7
|
AgentErrorCode2["SWITCH_IN_PROGRESS"] = "agent_switch_in_progress";
|
|
8
|
+
AgentErrorCode2["SESSION_BUSY"] = "agent_session_busy";
|
|
8
9
|
AgentErrorCode2["NO_CONFIG_PATH"] = "agent_no_config_path";
|
|
9
10
|
AgentErrorCode2["INVALID_CONFIG"] = "agent_invalid_config";
|
|
10
11
|
AgentErrorCode2["API_VALIDATION_ERROR"] = "agent_api_validation_error";
|
package/dist/agent/errors.cjs
CHANGED
|
@@ -77,6 +77,19 @@ class AgentError {
|
|
|
77
77
|
"Wait for the current switch operation to complete before starting a new one"
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Session already processing a run
|
|
82
|
+
*/
|
|
83
|
+
static sessionBusy(sessionId) {
|
|
84
|
+
return new import_DextoRuntimeError.DextoRuntimeError(
|
|
85
|
+
import_error_codes.AgentErrorCode.SESSION_BUSY,
|
|
86
|
+
import_types.ErrorScope.AGENT,
|
|
87
|
+
import_types.ErrorType.CONFLICT,
|
|
88
|
+
`Session '${sessionId}' is already processing a message`,
|
|
89
|
+
{ sessionId },
|
|
90
|
+
"Wait for the current run to finish or queue the next message"
|
|
91
|
+
);
|
|
92
|
+
}
|
|
80
93
|
/**
|
|
81
94
|
* Agent initialization failed
|
|
82
95
|
*/
|
package/dist/agent/errors.d.ts
CHANGED
|
@@ -21,6 +21,12 @@ export declare class AgentError {
|
|
|
21
21
|
* Agent switch in progress
|
|
22
22
|
*/
|
|
23
23
|
static switchInProgress(): DextoRuntimeError<undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* Session already processing a run
|
|
26
|
+
*/
|
|
27
|
+
static sessionBusy(sessionId: string): DextoRuntimeError<{
|
|
28
|
+
sessionId: string;
|
|
29
|
+
}>;
|
|
24
30
|
/**
|
|
25
31
|
* Agent initialization failed
|
|
26
32
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/agent/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAInE;;;;GAIG;AACH,qBAAa,UAAU;IACnB;;OAEG;IACH,MAAM,CAAC,UAAU;IAWjB;;OAEG;IACH,MAAM,CAAC,cAAc;IAWrB;;OAEG;IACH,MAAM,CAAC,OAAO;IAWd;;OAEG;IACH,MAAM,CAAC,gBAAgB;IAWvB;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;IAW7D;;OAEG;IACH,MAAM,CAAC,YAAY;IAWnB;;OAEG;IACH,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;IAW5D;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAUzD"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/agent/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAInE;;;;GAIG;AACH,qBAAa,UAAU;IACnB;;OAEG;IACH,MAAM,CAAC,UAAU;IAWjB;;OAEG;IACH,MAAM,CAAC,cAAc;IAWrB;;OAEG;IACH,MAAM,CAAC,OAAO;IAWd;;OAEG;IACH,MAAM,CAAC,gBAAgB;IAWvB;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,MAAM;;;IAWpC;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;IAW7D;;OAEG;IACH,MAAM,CAAC,YAAY;IAWnB;;OAEG;IACH,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;IAW5D;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAUzD"}
|
package/dist/agent/errors.js
CHANGED
|
@@ -55,6 +55,19 @@ class AgentError {
|
|
|
55
55
|
"Wait for the current switch operation to complete before starting a new one"
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Session already processing a run
|
|
60
|
+
*/
|
|
61
|
+
static sessionBusy(sessionId) {
|
|
62
|
+
return new DextoRuntimeError(
|
|
63
|
+
AgentErrorCode.SESSION_BUSY,
|
|
64
|
+
ErrorScope.AGENT,
|
|
65
|
+
ErrorType.CONFLICT,
|
|
66
|
+
`Session '${sessionId}' is already processing a message`,
|
|
67
|
+
{ sessionId },
|
|
68
|
+
"Wait for the current run to finish or queue the next message"
|
|
69
|
+
);
|
|
70
|
+
}
|
|
58
71
|
/**
|
|
59
72
|
* Agent initialization failed
|
|
60
73
|
*/
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './errors.js';
|
|
|
5
5
|
export * from './error-codes.js';
|
|
6
6
|
export type { DextoAgentOptions } from './agent-options.js';
|
|
7
7
|
export type { AgentRuntimeSettings, DextoAgentConfigInput } from './runtime-config.js';
|
|
8
|
+
export type { HostRuntimeContext, HostRuntimeIds } from '../runtime/index.js';
|
|
8
9
|
export type { ContentInput, GenerateOptions, GenerateResponse, StreamOptions, AgentToolCall, } from './types.js';
|
|
9
10
|
export type { StreamingEvent, StreamingEventName, STREAMING_EVENTS } from '../events/index.js';
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACH,eAAe,EACf,oBAAoB,EACpB,KAAK,SAAS,EACd,KAAK,kBAAkB,GAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,YAAY,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACH,eAAe,EACf,oBAAoB,EACpB,KAAK,SAAS,EACd,KAAK,kBAAkB,GAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,YAAY,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACvF,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG9E,YAAY,EACR,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,aAAa,GAChB,MAAM,YAAY,CAAC;AAGpB,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/agent/schemas.cjs
CHANGED
|
@@ -39,7 +39,7 @@ const OAuth2FlowSchema = import_zod.z.object({
|
|
|
39
39
|
authorizationUrl: import_zod.z.string().url().optional().describe("Authorization URL for the flow"),
|
|
40
40
|
tokenUrl: import_zod.z.string().url().optional().describe("Token URL for the flow"),
|
|
41
41
|
refreshUrl: import_zod.z.string().url().optional().describe("Refresh URL for the flow"),
|
|
42
|
-
scopes: import_zod.z.record(import_zod.z.string()).describe("Available scopes for the OAuth2 flow")
|
|
42
|
+
scopes: import_zod.z.record(import_zod.z.string(), import_zod.z.string()).describe("Available scopes for the OAuth2 flow")
|
|
43
43
|
}).strict();
|
|
44
44
|
const OAuth2SecurityScheme = import_zod.z.object({
|
|
45
45
|
type: import_zod.z.literal("oauth2").describe("Security scheme type"),
|
|
@@ -112,7 +112,7 @@ const AgentCardSchema = import_zod.z.object({
|
|
|
112
112
|
inputModes: import_zod.z.array(import_zod.z.string()).optional().default(["text/plain"]).describe("Skill-specific input MIME types"),
|
|
113
113
|
outputModes: import_zod.z.array(import_zod.z.string()).optional().default(["text/plain"]).describe("Skill-specific output MIME types")
|
|
114
114
|
}).strict()
|
|
115
|
-
).
|
|
115
|
+
).prefault([
|
|
116
116
|
{
|
|
117
117
|
id: "chat_with_agent",
|
|
118
118
|
name: "chat_with_agent",
|
|
@@ -143,9 +143,9 @@ const AgentCardSchema = import_zod.z.object({
|
|
|
143
143
|
streaming: import_zod.z.boolean().optional().default(true).describe("Supports streaming responses"),
|
|
144
144
|
pushNotifications: import_zod.z.boolean().optional().describe("Supports push notifications"),
|
|
145
145
|
stateTransitionHistory: import_zod.z.boolean().optional().default(false).describe("Provides state transition history")
|
|
146
|
-
}).strict().
|
|
147
|
-
securitySchemes: import_zod.z.record(SecuritySchemeSchema).optional().describe("Map of security scheme definitions (A2A format)"),
|
|
148
|
-
security: import_zod.z.array(import_zod.z.record(import_zod.z.array(import_zod.z.string()))).optional().describe(
|
|
146
|
+
}).strict().prefault({}).describe("Agent capabilities and features"),
|
|
147
|
+
securitySchemes: import_zod.z.record(import_zod.z.string(), SecuritySchemeSchema).optional().describe("Map of security scheme definitions (A2A format)"),
|
|
148
|
+
security: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.array(import_zod.z.string()))).optional().describe(
|
|
149
149
|
"Security requirements (array of security scheme references with required scopes)"
|
|
150
150
|
),
|
|
151
151
|
supportsAuthenticatedExtendedCard: import_zod.z.boolean().optional().describe("Whether extended card is available with authentication"),
|