beeai-framework 0.1.12 → 0.1.13
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/adapters/amazon-bedrock/backend/chat.d.cts +2 -2
- package/dist/adapters/amazon-bedrock/backend/chat.d.ts +2 -2
- package/dist/adapters/amazon-bedrock/backend/embedding.d.cts +2 -2
- package/dist/adapters/amazon-bedrock/backend/embedding.d.ts +2 -2
- package/dist/adapters/anthropic/backend/chat.d.cts +2 -2
- package/dist/adapters/anthropic/backend/chat.d.ts +2 -2
- package/dist/adapters/anthropic/backend/embedding.d.cts +2 -2
- package/dist/adapters/anthropic/backend/embedding.d.ts +2 -2
- package/dist/adapters/azure-openai/backend/chat.d.cts +2 -2
- package/dist/adapters/azure-openai/backend/chat.d.ts +2 -2
- package/dist/adapters/azure-openai/backend/embedding.d.cts +2 -2
- package/dist/adapters/azure-openai/backend/embedding.d.ts +2 -2
- package/dist/adapters/dummy/backend/chat.d.cts +2 -2
- package/dist/adapters/dummy/backend/chat.d.ts +2 -2
- package/dist/adapters/dummy/backend/embedding.d.cts +2 -2
- package/dist/adapters/dummy/backend/embedding.d.ts +2 -2
- package/dist/adapters/google-vertex/backend/chat.d.cts +2 -2
- package/dist/adapters/google-vertex/backend/chat.d.ts +2 -2
- package/dist/adapters/google-vertex/backend/embedding.d.cts +2 -2
- package/dist/adapters/google-vertex/backend/embedding.d.ts +2 -2
- package/dist/adapters/groq/backend/chat.d.cts +2 -2
- package/dist/adapters/groq/backend/chat.d.ts +2 -2
- package/dist/adapters/groq/backend/embedding.d.cts +2 -2
- package/dist/adapters/groq/backend/embedding.d.ts +2 -2
- package/dist/adapters/langchain/backend/chat.d.cts +2 -2
- package/dist/adapters/langchain/backend/chat.d.ts +2 -2
- package/dist/adapters/langchain/backend/embedding.d.cts +2 -2
- package/dist/adapters/langchain/backend/embedding.d.ts +2 -2
- package/dist/adapters/langchain/tools.d.cts +1 -1
- package/dist/adapters/langchain/tools.d.ts +1 -1
- package/dist/adapters/ollama/backend/chat.d.cts +2 -2
- package/dist/adapters/ollama/backend/chat.d.ts +2 -2
- package/dist/adapters/ollama/backend/embedding.d.cts +2 -2
- package/dist/adapters/ollama/backend/embedding.d.ts +2 -2
- package/dist/adapters/openai/backend/chat.d.cts +2 -2
- package/dist/adapters/openai/backend/chat.d.ts +2 -2
- package/dist/adapters/openai/backend/embedding.d.cts +2 -2
- package/dist/adapters/openai/backend/embedding.d.ts +2 -2
- package/dist/adapters/vercel/backend/chat.d.cts +2 -2
- package/dist/adapters/vercel/backend/chat.d.ts +2 -2
- package/dist/adapters/vercel/backend/embedding.d.cts +2 -2
- package/dist/adapters/vercel/backend/embedding.d.ts +2 -2
- package/dist/adapters/watsonx/backend/chat.d.cts +2 -2
- package/dist/adapters/watsonx/backend/chat.d.ts +2 -2
- package/dist/adapters/watsonx/backend/embedding.d.cts +2 -2
- package/dist/adapters/watsonx/backend/embedding.d.ts +2 -2
- package/dist/{agent-DN_52QhH.d.ts → agent-B55OuVCj.d.ts} +3 -3
- package/dist/{agent-2C0Z9iYa.d.cts → agent-Cmnvjx_k.d.cts} +3 -3
- package/dist/agents/base.d.cts +2 -2
- package/dist/agents/base.d.ts +2 -2
- package/dist/agents/experimental/remote/agent.cjs +107 -61
- package/dist/agents/experimental/remote/agent.cjs.map +1 -1
- package/dist/agents/experimental/remote/agent.d.cts +39 -36
- package/dist/agents/experimental/remote/agent.d.ts +39 -36
- package/dist/agents/experimental/remote/agent.js +108 -62
- package/dist/agents/experimental/remote/agent.js.map +1 -1
- package/dist/agents/experimental/replan/agent.d.cts +3 -3
- package/dist/agents/experimental/replan/agent.d.ts +3 -3
- package/dist/agents/experimental/replan/prompts.d.cts +1 -1
- package/dist/agents/experimental/replan/prompts.d.ts +1 -1
- package/dist/agents/experimental/streamlit/agent.d.cts +3 -3
- package/dist/agents/experimental/streamlit/agent.d.ts +3 -3
- package/dist/agents/react/agent.d.cts +4 -4
- package/dist/agents/react/agent.d.ts +4 -4
- package/dist/agents/react/prompts.d.cts +1 -1
- package/dist/agents/react/prompts.d.ts +1 -1
- package/dist/agents/react/runners/base.d.cts +4 -4
- package/dist/agents/react/runners/base.d.ts +4 -4
- package/dist/agents/react/runners/deep-think/prompts.d.cts +1 -1
- package/dist/agents/react/runners/deep-think/prompts.d.ts +1 -1
- package/dist/agents/react/runners/deep-think/runner.d.cts +5 -5
- package/dist/agents/react/runners/deep-think/runner.d.ts +5 -5
- package/dist/agents/react/runners/default/runner.d.cts +5 -5
- package/dist/agents/react/runners/default/runner.d.ts +5 -5
- package/dist/agents/react/runners/granite/prompts.d.cts +1 -1
- package/dist/agents/react/runners/granite/prompts.d.ts +1 -1
- package/dist/agents/react/runners/granite/runner.d.cts +5 -5
- package/dist/agents/react/runners/granite/runner.d.ts +5 -5
- package/dist/agents/react/types.d.cts +2 -2
- package/dist/agents/react/types.d.ts +2 -2
- package/dist/agents/toolCalling/agent.d.cts +3 -3
- package/dist/agents/toolCalling/agent.d.ts +3 -3
- package/dist/agents/toolCalling/types.d.cts +1 -1
- package/dist/agents/toolCalling/types.d.ts +1 -1
- package/dist/agents/types.d.cts +2 -2
- package/dist/agents/types.d.ts +2 -2
- package/dist/backend/backend.d.cts +2 -2
- package/dist/backend/backend.d.ts +2 -2
- package/dist/backend/chat.d.cts +2 -2
- package/dist/backend/chat.d.ts +2 -2
- package/dist/backend/core.d.cts +2 -2
- package/dist/backend/core.d.ts +2 -2
- package/dist/backend/embedding.d.cts +2 -2
- package/dist/backend/embedding.d.ts +2 -2
- package/dist/backend/utils.d.cts +2 -2
- package/dist/backend/utils.d.ts +2 -2
- package/dist/{base-ZnwDK6ZB.d.ts → base-BOCDDBvG.d.ts} +1 -1
- package/dist/{base-BPsHNV2O.d.cts → base-szR2Izbt.d.cts} +1 -1
- package/dist/{chat-diSK3Sui.d.ts → chat-BdN8hGWn.d.ts} +1 -1
- package/dist/{chat-BvyMdWFo.d.cts → chat-DvMzAHj6.d.cts} +1 -1
- package/dist/context.d.cts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/emitter/emitter.d.cts +1 -1
- package/dist/emitter/emitter.d.ts +1 -1
- package/dist/emitter/types.d.cts +1 -1
- package/dist/emitter/types.d.ts +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/internals/fetcher.cjs +31 -8
- package/dist/internals/fetcher.cjs.map +1 -1
- package/dist/internals/fetcher.d.cts +6 -4
- package/dist/internals/fetcher.d.ts +6 -4
- package/dist/internals/fetcher.js +32 -9
- package/dist/internals/fetcher.js.map +1 -1
- package/dist/memory/summarizeMemory.d.cts +2 -2
- package/dist/memory/summarizeMemory.d.ts +2 -2
- package/dist/parsers/linePrefix.d.cts +1 -1
- package/dist/parsers/linePrefix.d.ts +1 -1
- package/dist/tools/arxiv.d.cts +1 -1
- package/dist/tools/arxiv.d.ts +1 -1
- package/dist/tools/base.d.cts +1 -1
- package/dist/tools/base.d.ts +1 -1
- package/dist/tools/calculator.d.cts +1 -1
- package/dist/tools/calculator.d.ts +1 -1
- package/dist/tools/custom.d.cts +2 -2
- package/dist/tools/custom.d.ts +2 -2
- package/dist/tools/database/elasticsearch.d.cts +1 -1
- package/dist/tools/database/elasticsearch.d.ts +1 -1
- package/dist/tools/database/milvus.d.cts +1 -1
- package/dist/tools/database/milvus.d.ts +1 -1
- package/dist/tools/database/sql.d.cts +1 -1
- package/dist/tools/database/sql.d.ts +1 -1
- package/dist/tools/llm.d.cts +2 -2
- package/dist/tools/llm.d.ts +2 -2
- package/dist/tools/mcp.d.cts +1 -1
- package/dist/tools/mcp.d.ts +1 -1
- package/dist/tools/openapi.d.cts +1 -1
- package/dist/tools/openapi.d.ts +1 -1
- package/dist/tools/python/output.d.cts +1 -1
- package/dist/tools/python/output.d.ts +1 -1
- package/dist/tools/python/python.d.cts +2 -2
- package/dist/tools/python/python.d.ts +2 -2
- package/dist/tools/search/base.d.cts +1 -1
- package/dist/tools/search/base.d.ts +1 -1
- package/dist/tools/search/duckDuckGoSearch.d.cts +1 -1
- package/dist/tools/search/duckDuckGoSearch.d.ts +1 -1
- package/dist/tools/search/googleSearch.d.cts +1 -1
- package/dist/tools/search/googleSearch.d.ts +1 -1
- package/dist/tools/search/searXNGSearch.d.cts +1 -1
- package/dist/tools/search/searXNGSearch.d.ts +1 -1
- package/dist/tools/search/wikipedia.d.cts +1 -1
- package/dist/tools/search/wikipedia.d.ts +1 -1
- package/dist/tools/similarity.d.cts +1 -1
- package/dist/tools/similarity.d.ts +1 -1
- package/dist/tools/weather/openMeteo.d.cts +1 -1
- package/dist/tools/weather/openMeteo.d.ts +1 -1
- package/dist/tools/web/webCrawler.d.cts +1 -1
- package/dist/tools/web/webCrawler.d.ts +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/dist/workflows/agent.d.cts +40 -40
- package/dist/workflows/agent.d.ts +40 -40
- package/dist/workflows/workflow.d.cts +1 -1
- package/dist/workflows/workflow.d.ts +1 -1
- package/package.json +1 -6
- package/dist/{emitter-DiGmS_5O.d.ts → emitter-C3dO-s2P.d.ts} +1 -1
- package/dist/{emitter-BTr99H7I.d.cts → emitter-D5Mu0EEH.d.cts} +1 -1
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { a as BaseAgent, B as BaseAgentRunOptions } from '../../../base-ZnwDK6ZB.js';
|
|
1
|
+
import { C as Callback, E as Emitter } from '../../../emitter-C3dO-s2P.js';
|
|
2
|
+
import { a as BaseAgent, B as BaseAgentRunOptions } from '../../../base-BOCDDBvG.js';
|
|
4
3
|
import { GetRunContext } from '../../../context.js';
|
|
5
4
|
import { Message } from '../../../backend/message.js';
|
|
6
5
|
import { BaseMemory } from '../../../memory/base.js';
|
|
7
|
-
import {
|
|
8
|
-
import { Transport } from '@i-am-bee/acp-sdk/shared/transport.js';
|
|
6
|
+
import { RestfulClient } from '../../../internals/fetcher.js';
|
|
9
7
|
import '../../../internals/types.js';
|
|
10
8
|
import '../../../internals/helpers/guards.js';
|
|
11
9
|
import '../../../internals/serializable.js';
|
|
@@ -15,56 +13,60 @@ import 'ajv';
|
|
|
15
13
|
import 'promise-based-task';
|
|
16
14
|
import '../../../cache/base.js';
|
|
17
15
|
import '../../../internals/helpers/schema.js';
|
|
16
|
+
import 'zod';
|
|
18
17
|
import 'zod-to-json-schema';
|
|
19
18
|
import '../../../internals/helpers/promise.js';
|
|
20
19
|
import 'ai';
|
|
20
|
+
import '@ai-zen/node-fetch-event-source';
|
|
21
|
+
import '@ai-zen/node-fetch-event-source/lib/cjs/fetch.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Copyright 2025 © BeeAI a Series of LF Projects, LLC
|
|
25
|
+
*
|
|
26
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
27
|
+
* you may not use this file except in compliance with the License.
|
|
28
|
+
* You may obtain a copy of the License at
|
|
29
|
+
*
|
|
30
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
31
|
+
*
|
|
32
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
33
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
34
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
35
|
+
* See the License for the specific language governing permissions and
|
|
36
|
+
* limitations under the License.
|
|
37
|
+
*/
|
|
21
38
|
|
|
22
39
|
interface RemoteAgentRunInput {
|
|
23
|
-
|
|
40
|
+
input: Message | string | Message[] | string[];
|
|
24
41
|
}
|
|
25
42
|
interface RemoteAgentRunOutput {
|
|
26
|
-
|
|
43
|
+
result: Message;
|
|
44
|
+
event: Record<string, any>;
|
|
27
45
|
}
|
|
28
46
|
interface RemoteAgentEvents {
|
|
29
47
|
update: Callback<{
|
|
30
|
-
|
|
48
|
+
key: string;
|
|
49
|
+
value: any;
|
|
50
|
+
}>;
|
|
51
|
+
error: Callback<{
|
|
52
|
+
message: string;
|
|
31
53
|
}>;
|
|
32
54
|
}
|
|
33
55
|
interface Input {
|
|
34
|
-
|
|
35
|
-
transport: Transport;
|
|
56
|
+
url: string;
|
|
36
57
|
agentName: string;
|
|
58
|
+
memory: BaseMemory;
|
|
37
59
|
}
|
|
38
60
|
declare class RemoteAgent extends BaseAgent<RemoteAgentRunInput, RemoteAgentRunOutput> {
|
|
39
61
|
protected readonly input: Input;
|
|
40
62
|
emitter: Emitter<RemoteAgentEvents>;
|
|
63
|
+
protected client: RestfulClient<{
|
|
64
|
+
runs: string;
|
|
65
|
+
agents: string;
|
|
66
|
+
}>;
|
|
41
67
|
constructor(input: Input);
|
|
42
68
|
protected _run(input: RemoteAgentRunInput, _options: BaseAgentRunOptions, context: GetRunContext<this>): Promise<RemoteAgentRunOutput>;
|
|
43
|
-
|
|
44
|
-
name: zod.ZodString;
|
|
45
|
-
description: zod.ZodOptional<zod.ZodString>;
|
|
46
|
-
inputSchema: zod.ZodObject<{
|
|
47
|
-
type: zod.ZodLiteral<"object">;
|
|
48
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
49
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
50
|
-
type: zod.ZodLiteral<"object">;
|
|
51
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
52
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
53
|
-
type: zod.ZodLiteral<"object">;
|
|
54
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
55
|
-
}, zod.ZodTypeAny, "passthrough">>;
|
|
56
|
-
outputSchema: zod.ZodObject<{
|
|
57
|
-
type: zod.ZodLiteral<"object">;
|
|
58
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
59
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
60
|
-
type: zod.ZodLiteral<"object">;
|
|
61
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
62
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
63
|
-
type: zod.ZodLiteral<"object">;
|
|
64
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
65
|
-
}, zod.ZodTypeAny, "passthrough">>;
|
|
66
|
-
}, zod.ZodTypeAny, "passthrough">[]>;
|
|
67
|
-
protected createRunner(context: GetRunContext<this>): (input: RemoteAgentRunInput) => Promise<string>;
|
|
69
|
+
checkAgentExists(): Promise<boolean>;
|
|
68
70
|
get memory(): BaseMemory;
|
|
69
71
|
set memory(memory: BaseMemory);
|
|
70
72
|
createSnapshot(): {
|
|
@@ -72,7 +74,8 @@ declare class RemoteAgent extends BaseAgent<RemoteAgentRunInput, RemoteAgentRunO
|
|
|
72
74
|
emitter: Emitter<RemoteAgentEvents>;
|
|
73
75
|
isRunning: boolean;
|
|
74
76
|
};
|
|
75
|
-
|
|
77
|
+
protected convertToACPMessage(input: string | Message): any;
|
|
78
|
+
protected convertToMessage(input: string | Message): any;
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
export { RemoteAgent, type RemoteAgentEvents, type RemoteAgentRunInput, type RemoteAgentRunOutput };
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Emitter } from '../../../emitter/emitter.js';
|
|
2
2
|
import { BaseAgent, AgentError } from '../../base.js';
|
|
3
|
-
import { AssistantMessage } from '../../../backend/message.js';
|
|
4
|
-
import { Client } from '@i-am-bee/acp-sdk/client/index.js';
|
|
3
|
+
import { AssistantMessage, Message, UserMessage } from '../../../backend/message.js';
|
|
5
4
|
import { shallowCopy } from '../../../serializer/utils.js';
|
|
6
|
-
import {
|
|
7
|
-
import { AgentRunProgressNotificationSchema } from '@i-am-bee/acp-sdk/types.js';
|
|
8
|
-
import { SSEClientTransport } from '@i-am-bee/acp-sdk/client/sse.js';
|
|
5
|
+
import { RestfulClient } from '../../../internals/fetcher.js';
|
|
9
6
|
|
|
10
7
|
var __defProp = Object.defineProperty;
|
|
11
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -15,6 +12,7 @@ class RemoteAgent extends BaseAgent {
|
|
|
15
12
|
}
|
|
16
13
|
input;
|
|
17
14
|
emitter;
|
|
15
|
+
client;
|
|
18
16
|
constructor(input) {
|
|
19
17
|
super(), this.input = input, this.emitter = Emitter.root.child({
|
|
20
18
|
namespace: [
|
|
@@ -23,66 +21,92 @@ class RemoteAgent extends BaseAgent {
|
|
|
23
21
|
],
|
|
24
22
|
creator: this
|
|
25
23
|
});
|
|
24
|
+
this.client = new RestfulClient({
|
|
25
|
+
baseUrl: this.input.url,
|
|
26
|
+
headers: /* @__PURE__ */ __name(async () => ({
|
|
27
|
+
"Accept": "application/json",
|
|
28
|
+
"Content-Type": "application/json"
|
|
29
|
+
}), "headers"),
|
|
30
|
+
paths: {
|
|
31
|
+
runs: `/runs`,
|
|
32
|
+
agents: `/agents`
|
|
33
|
+
}
|
|
34
|
+
});
|
|
26
35
|
}
|
|
27
36
|
async _run(input, _options, context) {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const inputs = Array.isArray(input.input) ? input.input.map(this.convertToACPMessage) : [
|
|
38
|
+
this.convertToACPMessage(input.input)
|
|
39
|
+
];
|
|
40
|
+
const generator = this.client.stream("runs", {
|
|
41
|
+
body: JSON.stringify({
|
|
42
|
+
agent_name: this.input.agentName,
|
|
43
|
+
input: inputs,
|
|
44
|
+
mode: "stream"
|
|
45
|
+
}),
|
|
46
|
+
signal: context.signal
|
|
47
|
+
});
|
|
48
|
+
let eventData = null;
|
|
49
|
+
for await (const event of generator) {
|
|
41
50
|
try {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
eventData = JSON.parse(event.data);
|
|
52
|
+
await context.emitter.emit("update", {
|
|
53
|
+
key: eventData.type,
|
|
54
|
+
value: {
|
|
55
|
+
...eventData,
|
|
56
|
+
type: void 0
|
|
57
|
+
}
|
|
46
58
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} catch (e) {
|
|
51
|
-
throw new AgentError(`Can't connect to Beeai Platform.`, [
|
|
52
|
-
e
|
|
53
|
-
], {
|
|
54
|
-
isFatal: true
|
|
59
|
+
} catch {
|
|
60
|
+
await context.emitter.emit("error", {
|
|
61
|
+
message: "Error parsing JSON"
|
|
55
62
|
});
|
|
56
63
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
name: this.input.agentName,
|
|
66
|
-
input: typeof input.prompt === "string" ? {
|
|
67
|
-
text: input.prompt
|
|
68
|
-
} : input.prompt
|
|
69
|
-
}, {
|
|
70
|
-
timeout: 1e7,
|
|
71
|
-
signal: context.signal,
|
|
72
|
-
onprogress: /* @__PURE__ */ __name(() => null, "onprogress")
|
|
64
|
+
}
|
|
65
|
+
if (!eventData) {
|
|
66
|
+
throw new AgentError("No event received from agent.");
|
|
67
|
+
}
|
|
68
|
+
if (eventData.type === "run.failed") {
|
|
69
|
+
const message = eventData.run?.error?.message || "Something went wrong with the agent communication.";
|
|
70
|
+
await context.emitter.emit("error", {
|
|
71
|
+
message
|
|
73
72
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
throw new AgentError(message);
|
|
74
|
+
} else if (eventData.type === "run.completed") {
|
|
75
|
+
const text = eventData.run.output.reduce((acc, output) => acc + output.parts.reduce((acc2, part) => acc2 + part.content, ""), "");
|
|
76
|
+
const assistantMessage = new AssistantMessage(text, {
|
|
77
|
+
event: eventData
|
|
77
78
|
});
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
const inputMessages = Array.isArray(input.input) ? input.input.map(this.convertToMessage) : [
|
|
80
|
+
this.convertToMessage(input.input)
|
|
81
|
+
];
|
|
82
|
+
await this.memory.addMany(inputMessages);
|
|
83
|
+
await this.memory.add(assistantMessage);
|
|
84
|
+
return {
|
|
85
|
+
result: assistantMessage,
|
|
86
|
+
event: eventData
|
|
87
|
+
};
|
|
88
|
+
} else {
|
|
89
|
+
return {
|
|
90
|
+
result: new AssistantMessage("No response from agent."),
|
|
91
|
+
event: eventData
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async checkAgentExists() {
|
|
96
|
+
try {
|
|
97
|
+
const response = await this.client.fetch("agents");
|
|
98
|
+
return !!response.agents.find((agent) => agent.name === this.input.agentName);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
throw new AgentError(`Error while checking agent existence: ${error.message}`, [], {
|
|
101
|
+
isFatal: true
|
|
102
|
+
});
|
|
103
|
+
}
|
|
80
104
|
}
|
|
81
105
|
get memory() {
|
|
82
|
-
|
|
106
|
+
return this.input.memory;
|
|
83
107
|
}
|
|
84
108
|
set memory(memory) {
|
|
85
|
-
|
|
109
|
+
this.input.memory = memory;
|
|
86
110
|
}
|
|
87
111
|
createSnapshot() {
|
|
88
112
|
return {
|
|
@@ -91,15 +115,37 @@ class RemoteAgent extends BaseAgent {
|
|
|
91
115
|
emitter: this.emitter
|
|
92
116
|
};
|
|
93
117
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
118
|
+
convertToACPMessage(input) {
|
|
119
|
+
if (typeof input === "string") {
|
|
120
|
+
return {
|
|
121
|
+
parts: [
|
|
122
|
+
{
|
|
123
|
+
content: input,
|
|
124
|
+
role: "user"
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
};
|
|
128
|
+
} else if (input instanceof Message) {
|
|
129
|
+
return {
|
|
130
|
+
parts: [
|
|
131
|
+
{
|
|
132
|
+
content: input.content,
|
|
133
|
+
role: input.role
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
};
|
|
137
|
+
} else {
|
|
138
|
+
throw new AgentError("Unsupported input type");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
convertToMessage(input) {
|
|
142
|
+
if (typeof input === "string") {
|
|
143
|
+
return new UserMessage(input);
|
|
144
|
+
} else if (input instanceof Message) {
|
|
145
|
+
return input;
|
|
146
|
+
} else {
|
|
147
|
+
throw new AgentError("Unsupported input type");
|
|
148
|
+
}
|
|
103
149
|
}
|
|
104
150
|
}
|
|
105
151
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["agent.ts"],"names":["RemoteAgent","BaseAgent","emitter","constructor","input","Emitter","root","child","namespace","creator","_run","_options","context","runner","createRunner","output","message","AssistantMessage","listAgents","response","client","agents","setNotificationHandler","AgentRunProgressNotificationSchema","notification","emit","JSON","stringify","params","delta","transport","connect","e","AgentError","isFatal","agent","find","name","agentName","runAgent","prompt","text","timeout","signal","onprogress","memory","NotImplementedError","createSnapshot","shallowCopy","createSSEAgent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,YAAA;OACd,CAAA;AAGF,MAAA,MAAM7B,SAASW,IAAKC,CAAAA,SAAAA,CAAUR,QAASJ,CAAAA,MAAAA,EAAQ,MAAM,CAAA,CAAA;AACrD,MAAMH,MAAAA,OAAAA,CAAQV,OAAQuB,CAAAA,IAAAA,CAAK,QAAU,EAAA;AAAEV,QAAAA;OAAO,CAAA;AAC9C,MAAOA,OAAAA,MAAAA;AACT,KAAA;AACF;AAEA,EAAA,IAAI8B,MAAS,GAAA;AACX,IAAA,MAAM,IAAIC,mBAAAA,EAAAA;AACZ;AAEA,EAAA,IAAID,OAAOA,MAAoB,EAAA;AAC7B,IAAA,MAAM,IAAIC,mBAAAA,EAAAA;AACZ;EAEAC,cAAiB,GAAA;AACf,IAAO,OAAA;AACL,MAAA,GAAG,MAAMA,cAAAA,EAAAA;MACT3C,KAAO4C,EAAAA,WAAAA,CAAY,KAAK5C,KAAK,CAAA;AAC7BF,MAAAA,OAAAA,EAAS,IAAKA,CAAAA;AAChB,KAAA;AACF;EAEA,OAAO+C,cAAAA,CAAeC,KAAaZ,SAAmB,EAAA;AACpD,IAAA,OAAO,IAAItC,WAAY,CAAA;AACrBoB,MAAAA,MAAAA,EAAQ,IAAI+B,MAAU,CAAA;QACpBd,IAAM,EAAA,cAAA;QACNe,OAAS,EAAA;OACX,CAAA;AACAtB,MAAAA,SAAAA,EAAW,IAAIuB,kBAAAA,CAAmB,IAAIC,GAAAA,CAAIJ,GAAAA,CAAAA,CAAAA;AAC1CZ,MAAAA;KACF,CAAA;AACF;AACF","file":"agent.js","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Callback } from \"@/emitter/types.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport { AgentError, BaseAgent, BaseAgentRunOptions } from \"@/agents/base.js\";\nimport { GetRunContext } from \"@/context.js\";\nimport { AssistantMessage, Message } from \"@/backend/message.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { Client as MCPClient } from \"@i-am-bee/acp-sdk/client/index.js\";\nimport { Transport } from \"@i-am-bee/acp-sdk/shared/transport.js\";\nimport { shallowCopy } from \"@/serializer/utils.js\";\nimport { NotImplementedError } from \"@/errors.js\";\nimport { AgentRunProgressNotificationSchema } from \"@i-am-bee/acp-sdk/types.js\";\nimport { SSEClientTransport } from \"@i-am-bee/acp-sdk/client/sse.js\";\n\nexport interface RemoteAgentRunInput {\n prompt: Record<string, unknown> | string;\n}\n\nexport interface RemoteAgentRunOutput {\n message: Message;\n}\n\nexport interface RemoteAgentEvents {\n update: Callback<{ output: string }>;\n}\n\ninterface Input {\n client: MCPClient;\n transport: Transport;\n agentName: string;\n}\n\nexport class RemoteAgent extends BaseAgent<RemoteAgentRunInput, RemoteAgentRunOutput> {\n public emitter = Emitter.root.child<RemoteAgentEvents>({\n namespace: [\"agent\", \"remote\"],\n creator: this,\n });\n\n constructor(protected readonly input: Input) {\n super();\n }\n\n protected async _run(\n input: RemoteAgentRunInput,\n _options: BaseAgentRunOptions,\n context: GetRunContext<this>,\n ): Promise<RemoteAgentRunOutput> {\n const runner = this.createRunner(context);\n\n const output = await runner(input);\n\n const message: Message = new AssistantMessage(output);\n\n return { message };\n }\n\n protected async listAgents() {\n const response = await this.input.client.listAgents();\n\n return response.agents;\n }\n\n protected createRunner(context: GetRunContext<this>) {\n return async (input: RemoteAgentRunInput): Promise<string> => {\n try {\n this.input.client.setNotificationHandler(\n AgentRunProgressNotificationSchema,\n async (notification) => {\n await context.emitter.emit(\"update\", {\n output: JSON.stringify(notification.params.delta, null, 2),\n });\n },\n );\n if (!this.input.client.transport) {\n await this.input.client.connect(this.input.transport);\n }\n } catch (e) {\n throw new AgentError(`Can't connect to Beeai Platform.`, [e], { isFatal: true });\n }\n\n const agents = await this.listAgents();\n const agent = agents.find((agent) => agent.name === this.input.agentName);\n if (!agent) {\n throw new AgentError(\n `Agent ${this.input.agentName} is not registered in the platform`,\n [],\n {\n isFatal: true,\n },\n );\n }\n\n const response = await this.input.client.runAgent(\n {\n name: this.input.agentName,\n input: typeof input.prompt === \"string\" ? { text: input.prompt } : input.prompt,\n },\n {\n timeout: 10_000_000,\n signal: context.signal,\n onprogress: () => null, // This has to be here in order for notifications to work.\n },\n );\n\n const output = JSON.stringify(response.output, null, 2);\n await context.emitter.emit(\"update\", { output });\n return output;\n };\n }\n\n get memory() {\n throw new NotImplementedError();\n }\n\n set memory(memory: BaseMemory) {\n throw new NotImplementedError();\n }\n\n createSnapshot() {\n return {\n ...super.createSnapshot(),\n input: shallowCopy(this.input),\n emitter: this.emitter,\n };\n }\n\n static createSSEAgent(url: string, agentName: string) {\n return new RemoteAgent({\n client: new MCPClient({\n name: \"remote-agent\",\n version: \"1.0.0\",\n }),\n transport: new SSEClientTransport(new URL(url)),\n agentName: agentName,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["agent.ts"],"names":["RemoteAgent","BaseAgent","emitter","client","constructor","input","Emitter","root","child","namespace","creator","RestfulClient","baseUrl","url","headers","paths","runs","agents","_run","_options","context","inputs","Array","isArray","map","convertToACPMessage","generator","stream","body","JSON","stringify","agent_name","agentName","mode","signal","eventData","event","parse","data","emit","key","type","value","undefined","message","AgentError","run","error","text","output","reduce","acc","parts","acc2","part","content","assistantMessage","AssistantMessage","inputMessages","convertToMessage","memory","addMany","add","result","checkAgentExists","response","fetch","find","agent","name","isFatal","createSnapshot","shallowCopy","role","Message","UserMessage"],"mappings":";;;;;;;;AA6CO,MAAMA,oBAAoBC,SAAAA,CAAAA;EA7CjC;;;;AA8CSC,EAAAA,OAAAA;AAIGC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AAAA,MAAAA;AACpB;AAEA,EAAA,IAAIA,OAAOA,MAAoB,EAAA;AAC7B,IAAA,IAAA,CAAKvD,MAAMuD,MAASA,GAAAA,MAAAA;AACtB;EAEAW,cAAiB,GAAA;AACf,IAAO,OAAA;AACL,MAAA,GAAG,MAAMA,cAAAA,EAAAA;MACTlE,KAAOmE,EAAAA,WAAAA,CAAY,KAAKnE,KAAK,CAAA;AAC7BH,MAAAA,OAAAA,EAAS,IAAKA,CAAAA;AAChB,KAAA;AACF;AAEUuB,EAAAA,mBAAAA,CAAoBpB,KAA8B,EAAA;AAC1D,IAAI,IAAA,OAAOA,UAAU,QAAU,EAAA;AAC7B,MAAO,OAAA;QAAE+C,KAAO,EAAA;AAAC,UAAA;YAAEG,OAASlD,EAAAA,KAAAA;YAAOoE,IAAM,EAAA;AAAO;;AAAG,OAAA;AACrD,KAAA,MAAA,IAAWpE,iBAAiBqE,OAAS,EAAA;AACnC,MAAO,OAAA;QAAEtB,KAAO,EAAA;AAAC,UAAA;AAAEG,YAAAA,OAAAA,EAASlD,KAAMkD,CAAAA,OAAAA;AAASkB,YAAAA,IAAAA,EAAMpE,KAAMoE,CAAAA;AAAK;;AAAG,OAAA;KAC1D,MAAA;AACL,MAAM,MAAA,IAAI5B,WAAW,wBAAA,CAAA;AACvB;AACF;AAEUc,EAAAA,gBAAAA,CAAiBtD,KAA8B,EAAA;AACvD,IAAI,IAAA,OAAOA,UAAU,QAAU,EAAA;AAC7B,MAAO,OAAA,IAAIsE,YAAYtE,KAAAA,CAAAA;AACzB,KAAA,MAAA,IAAWA,iBAAiBqE,OAAS,EAAA;AACnC,MAAOrE,OAAAA,KAAAA;KACF,MAAA;AACL,MAAM,MAAA,IAAIwC,WAAW,wBAAA,CAAA;AACvB;AACF;AACF","file":"agent.js","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Callback } from \"@/emitter/types.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport { AgentError, BaseAgent, BaseAgentRunOptions } from \"@/agents/base.js\";\nimport { GetRunContext } from \"@/context.js\";\nimport { AssistantMessage, Message, UserMessage } from \"@/backend/message.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { shallowCopy } from \"@/serializer/utils.js\";\nimport { RestfulClient } from \"@/internals/fetcher.js\";\n\nexport interface RemoteAgentRunInput {\n input: Message | string | Message[] | string[];\n}\n\nexport interface RemoteAgentRunOutput {\n result: Message;\n event: Record<string, any>;\n}\n\nexport interface RemoteAgentEvents {\n update: Callback<{ key: string; value: any }>;\n error: Callback<{ message: string }>;\n}\n\ninterface Input {\n url: string;\n agentName: string;\n memory: BaseMemory;\n}\n\nexport class RemoteAgent extends BaseAgent<RemoteAgentRunInput, RemoteAgentRunOutput> {\n public emitter = Emitter.root.child<RemoteAgentEvents>({\n namespace: [\"agent\", \"remote\"],\n creator: this,\n });\n protected client: RestfulClient<{ runs: string; agents: string }>;\n\n constructor(protected readonly input: Input) {\n super();\n this.client = new RestfulClient({\n baseUrl: this.input.url,\n headers: async () => ({\n \"Accept\": \"application/json\",\n \"Content-Type\": \"application/json\",\n }),\n paths: { runs: `/runs`, agents: `/agents` },\n });\n }\n\n protected async _run(\n input: RemoteAgentRunInput,\n _options: BaseAgentRunOptions,\n context: GetRunContext<this>,\n ): Promise<RemoteAgentRunOutput> {\n const inputs = Array.isArray(input.input)\n ? input.input.map(this.convertToACPMessage)\n : [this.convertToACPMessage(input.input)];\n\n const generator = this.client.stream(\"runs\", {\n body: JSON.stringify({\n agent_name: this.input.agentName,\n input: inputs,\n mode: \"stream\",\n }),\n signal: context.signal,\n });\n\n let eventData: any = null;\n for await (const event of generator) {\n try {\n eventData = JSON.parse(event.data);\n await context.emitter.emit(\"update\", {\n key: eventData.type,\n value: { ...eventData, type: undefined },\n });\n } catch {\n await context.emitter.emit(\"error\", {\n message: \"Error parsing JSON\",\n });\n }\n }\n\n if (!eventData) {\n throw new AgentError(\"No event received from agent.\");\n }\n\n if (eventData.type === \"run.failed\") {\n const message =\n eventData.run?.error?.message || \"Something went wrong with the agent communication.\";\n await context.emitter.emit(\"error\", { message });\n throw new AgentError(message);\n } else if (eventData.type === \"run.completed\") {\n const text = eventData.run.output.reduce(\n (acc: string, output: any) =>\n acc + output.parts.reduce((acc2: string, part: any) => acc2 + part.content, \"\"),\n \"\",\n );\n const assistantMessage: Message = new AssistantMessage(text, { event: eventData });\n const inputMessages = Array.isArray(input.input)\n ? input.input.map(this.convertToMessage)\n : [this.convertToMessage(input.input)];\n\n await this.memory.addMany(inputMessages);\n await this.memory.add(assistantMessage);\n\n return { result: assistantMessage, event: eventData };\n } else {\n return { result: new AssistantMessage(\"No response from agent.\"), event: eventData };\n }\n }\n\n async checkAgentExists() {\n try {\n const response = await this.client.fetch(\"agents\");\n return !!response.agents.find((agent: any) => agent.name === this.input.agentName);\n } catch (error) {\n throw new AgentError(`Error while checking agent existence: ${error.message}`, [], {\n isFatal: true,\n });\n }\n }\n\n get memory() {\n return this.input.memory;\n }\n\n set memory(memory: BaseMemory) {\n this.input.memory = memory;\n }\n\n createSnapshot() {\n return {\n ...super.createSnapshot(),\n input: shallowCopy(this.input),\n emitter: this.emitter,\n };\n }\n\n protected convertToACPMessage(input: string | Message): any {\n if (typeof input === \"string\") {\n return { parts: [{ content: input, role: \"user\" }] };\n } else if (input instanceof Message) {\n return { parts: [{ content: input.content, role: input.role }] };\n } else {\n throw new AgentError(\"Unsupported input type\");\n }\n }\n\n protected convertToMessage(input: string | Message): any {\n if (typeof input === \"string\") {\n return new UserMessage(input);\n } else if (input instanceof Message) {\n return input;\n } else {\n throw new AgentError(\"Unsupported input type\");\n }\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { C as Callback, E as Emitter } from '../../../emitter-
|
|
2
|
-
import { a as BaseAgent, B as BaseAgentRunOptions } from '../../../base-
|
|
1
|
+
import { C as Callback, E as Emitter } from '../../../emitter-D5Mu0EEH.cjs';
|
|
2
|
+
import { a as BaseAgent, B as BaseAgentRunOptions } from '../../../base-szR2Izbt.cjs';
|
|
3
3
|
import { GetRunContext } from '../../../context.cjs';
|
|
4
4
|
import { Message } from '../../../backend/message.cjs';
|
|
5
5
|
import { RePlanState } from './prompts.cjs';
|
|
6
6
|
import { BaseMemory } from '../../../memory/base.cjs';
|
|
7
7
|
import { UnconstrainedMemory } from '../../../memory/unconstrainedMemory.cjs';
|
|
8
8
|
import { AnyTool } from '../../../tools/base.cjs';
|
|
9
|
-
import { m as ChatModel } from '../../../chat-
|
|
9
|
+
import { m as ChatModel } from '../../../chat-DvMzAHj6.cjs';
|
|
10
10
|
import '../../../internals/types.cjs';
|
|
11
11
|
import '../../../internals/helpers/guards.cjs';
|
|
12
12
|
import '../../../internals/serializable.cjs';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { C as Callback, E as Emitter } from '../../../emitter-
|
|
2
|
-
import { a as BaseAgent, B as BaseAgentRunOptions } from '../../../base-
|
|
1
|
+
import { C as Callback, E as Emitter } from '../../../emitter-C3dO-s2P.js';
|
|
2
|
+
import { a as BaseAgent, B as BaseAgentRunOptions } from '../../../base-BOCDDBvG.js';
|
|
3
3
|
import { GetRunContext } from '../../../context.js';
|
|
4
4
|
import { Message } from '../../../backend/message.js';
|
|
5
5
|
import { RePlanState } from './prompts.js';
|
|
6
6
|
import { BaseMemory } from '../../../memory/base.js';
|
|
7
7
|
import { UnconstrainedMemory } from '../../../memory/unconstrainedMemory.js';
|
|
8
8
|
import { AnyTool } from '../../../tools/base.js';
|
|
9
|
-
import { m as ChatModel } from '../../../chat-
|
|
9
|
+
import { m as ChatModel } from '../../../chat-BdN8hGWn.js';
|
|
10
10
|
import '../../../internals/types.js';
|
|
11
11
|
import '../../../internals/helpers/guards.js';
|
|
12
12
|
import '../../../internals/serializable.js';
|
|
@@ -7,7 +7,7 @@ import '../../../internals/types.cjs';
|
|
|
7
7
|
import '../../../internals/helpers/guards.cjs';
|
|
8
8
|
import '../../../internals/serializable.cjs';
|
|
9
9
|
import '../../../context.cjs';
|
|
10
|
-
import '../../../emitter-
|
|
10
|
+
import '../../../emitter-D5Mu0EEH.cjs';
|
|
11
11
|
import '../../../internals/helpers/promise.cjs';
|
|
12
12
|
import 'promise-based-task';
|
|
13
13
|
import '../../../cache/base.cjs';
|
|
@@ -7,7 +7,7 @@ import '../../../internals/types.js';
|
|
|
7
7
|
import '../../../internals/helpers/guards.js';
|
|
8
8
|
import '../../../internals/serializable.js';
|
|
9
9
|
import '../../../context.js';
|
|
10
|
-
import '../../../emitter-
|
|
10
|
+
import '../../../emitter-C3dO-s2P.js';
|
|
11
11
|
import '../../../internals/helpers/promise.js';
|
|
12
12
|
import 'promise-based-task';
|
|
13
13
|
import '../../../cache/base.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { a as BaseAgent, b as AgentMeta, B as BaseAgentRunOptions } from '../../../base-
|
|
1
|
+
import { a as BaseAgent, b as AgentMeta, B as BaseAgentRunOptions } from '../../../base-szR2Izbt.cjs';
|
|
2
2
|
import { GetRunContext } from '../../../context.cjs';
|
|
3
|
-
import { C as Callback, E as Emitter } from '../../../emitter-
|
|
3
|
+
import { C as Callback, E as Emitter } from '../../../emitter-D5Mu0EEH.cjs';
|
|
4
4
|
import { BaseMemory } from '../../../memory/base.cjs';
|
|
5
5
|
import { Message, UserMessage } from '../../../backend/message.cjs';
|
|
6
6
|
import { StreamlitAgentTemplates } from './prompts.cjs';
|
|
7
7
|
import { TokenMemory } from '../../../memory/tokenMemory.cjs';
|
|
8
|
-
import { m as ChatModel, n as ChatModelOutput } from '../../../chat-
|
|
8
|
+
import { m as ChatModel, n as ChatModelOutput } from '../../../chat-DvMzAHj6.cjs';
|
|
9
9
|
import '../../../errors.cjs';
|
|
10
10
|
import '../../../internals/types.cjs';
|
|
11
11
|
import '../../../internals/helpers/guards.cjs';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { a as BaseAgent, b as AgentMeta, B as BaseAgentRunOptions } from '../../../base-
|
|
1
|
+
import { a as BaseAgent, b as AgentMeta, B as BaseAgentRunOptions } from '../../../base-BOCDDBvG.js';
|
|
2
2
|
import { GetRunContext } from '../../../context.js';
|
|
3
|
-
import { C as Callback, E as Emitter } from '../../../emitter-
|
|
3
|
+
import { C as Callback, E as Emitter } from '../../../emitter-C3dO-s2P.js';
|
|
4
4
|
import { BaseMemory } from '../../../memory/base.js';
|
|
5
5
|
import { Message, UserMessage } from '../../../backend/message.js';
|
|
6
6
|
import { StreamlitAgentTemplates } from './prompts.js';
|
|
7
7
|
import { TokenMemory } from '../../../memory/tokenMemory.js';
|
|
8
|
-
import { m as ChatModel, n as ChatModelOutput } from '../../../chat-
|
|
8
|
+
import { m as ChatModel, n as ChatModelOutput } from '../../../chat-BdN8hGWn.js';
|
|
9
9
|
import '../../../errors.js';
|
|
10
10
|
import '../../../internals/types.js';
|
|
11
11
|
import '../../../internals/helpers/guards.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import '../../context.cjs';
|
|
2
|
-
import '../../base-
|
|
2
|
+
import '../../base-szR2Izbt.cjs';
|
|
3
3
|
import '../../tools/base.cjs';
|
|
4
4
|
import '../../memory/base.cjs';
|
|
5
|
-
import '../../emitter-
|
|
5
|
+
import '../../emitter-D5Mu0EEH.cjs';
|
|
6
6
|
import './types.cjs';
|
|
7
|
-
export { c as ReActAgent, b as ReActAgentInput, d as ReActAgentTemplateFactory } from '../../agent-
|
|
8
|
-
import '../../chat-
|
|
7
|
+
export { c as ReActAgent, b as ReActAgentInput, d as ReActAgentTemplateFactory } from '../../agent-Cmnvjx_k.cjs';
|
|
8
|
+
import '../../chat-DvMzAHj6.cjs';
|
|
9
9
|
import '../../internals/serializable.cjs';
|
|
10
10
|
import '../../internals/types.cjs';
|
|
11
11
|
import '../../internals/helpers/guards.cjs';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import '../../context.js';
|
|
2
|
-
import '../../base-
|
|
2
|
+
import '../../base-BOCDDBvG.js';
|
|
3
3
|
import '../../tools/base.js';
|
|
4
4
|
import '../../memory/base.js';
|
|
5
|
-
import '../../emitter-
|
|
5
|
+
import '../../emitter-C3dO-s2P.js';
|
|
6
6
|
import './types.js';
|
|
7
|
-
export { c as ReActAgent, b as ReActAgentInput, d as ReActAgentTemplateFactory } from '../../agent-
|
|
8
|
-
import '../../chat-
|
|
7
|
+
export { c as ReActAgent, b as ReActAgentInput, d as ReActAgentTemplateFactory } from '../../agent-B55OuVCj.js';
|
|
8
|
+
import '../../chat-BdN8hGWn.js';
|
|
9
9
|
import '../../internals/serializable.js';
|
|
10
10
|
import '../../internals/types.js';
|
|
11
11
|
import '../../internals/helpers/guards.js';
|
|
@@ -39,12 +39,12 @@ declare const ReActAgentSystemPrompt: PromptTemplate<z.ZodObject<{
|
|
|
39
39
|
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
40
40
|
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
41
|
}, "strip", z.ZodTypeAny, {
|
|
42
|
-
instructions: string;
|
|
43
42
|
tools: z.objectOutputType<{
|
|
44
43
|
name: z.ZodString;
|
|
45
44
|
description: z.ZodString;
|
|
46
45
|
schema: z.ZodString;
|
|
47
46
|
}, z.ZodTypeAny, "passthrough">[];
|
|
47
|
+
instructions: string;
|
|
48
48
|
createdAt?: string | null | undefined;
|
|
49
49
|
}, {
|
|
50
50
|
tools: z.objectInputType<{
|
|
@@ -39,12 +39,12 @@ declare const ReActAgentSystemPrompt: PromptTemplate<z.ZodObject<{
|
|
|
39
39
|
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
40
40
|
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
41
|
}, "strip", z.ZodTypeAny, {
|
|
42
|
-
instructions: string;
|
|
43
42
|
tools: z.objectOutputType<{
|
|
44
43
|
name: z.ZodString;
|
|
45
44
|
description: z.ZodString;
|
|
46
45
|
schema: z.ZodString;
|
|
47
46
|
}, z.ZodTypeAny, "passthrough">[];
|
|
47
|
+
instructions: string;
|
|
48
48
|
createdAt?: string | null | undefined;
|
|
49
49
|
}, {
|
|
50
50
|
tools: z.objectInputType<{
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import '../../../parsers/linePrefix.cjs';
|
|
2
2
|
import '../types.cjs';
|
|
3
3
|
import '../../../internals/serializable.cjs';
|
|
4
|
-
export { B as BaseRunner, R as ReActAgentRunnerLLMInput, a as ReActAgentRunnerToolInput } from '../../../agent-
|
|
4
|
+
export { B as BaseRunner, R as ReActAgentRunnerLLMInput, a as ReActAgentRunnerToolInput } from '../../../agent-Cmnvjx_k.cjs';
|
|
5
5
|
import '../../../internals/helpers/counter.cjs';
|
|
6
6
|
import '../../../memory/base.cjs';
|
|
7
7
|
import '../../../context.cjs';
|
|
8
|
-
import '../../../emitter-
|
|
8
|
+
import '../../../emitter-D5Mu0EEH.cjs';
|
|
9
9
|
import '../../../parsers/field.cjs';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import '@streamparser/json';
|
|
@@ -25,8 +25,8 @@ import 'zod-to-json-schema';
|
|
|
25
25
|
import '../../../internals/helpers/promise.cjs';
|
|
26
26
|
import '../prompts.cjs';
|
|
27
27
|
import '../../../template.cjs';
|
|
28
|
-
import '../../../chat-
|
|
28
|
+
import '../../../chat-DvMzAHj6.cjs';
|
|
29
29
|
import '../../../backend/constants.cjs';
|
|
30
30
|
import '../../../logger/logger.cjs';
|
|
31
31
|
import 'pino';
|
|
32
|
-
import '../../../base-
|
|
32
|
+
import '../../../base-szR2Izbt.cjs';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import '../../../parsers/linePrefix.js';
|
|
2
2
|
import '../types.js';
|
|
3
3
|
import '../../../internals/serializable.js';
|
|
4
|
-
export { B as BaseRunner, R as ReActAgentRunnerLLMInput, a as ReActAgentRunnerToolInput } from '../../../agent-
|
|
4
|
+
export { B as BaseRunner, R as ReActAgentRunnerLLMInput, a as ReActAgentRunnerToolInput } from '../../../agent-B55OuVCj.js';
|
|
5
5
|
import '../../../internals/helpers/counter.js';
|
|
6
6
|
import '../../../memory/base.js';
|
|
7
7
|
import '../../../context.js';
|
|
8
|
-
import '../../../emitter-
|
|
8
|
+
import '../../../emitter-C3dO-s2P.js';
|
|
9
9
|
import '../../../parsers/field.js';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import '@streamparser/json';
|
|
@@ -25,8 +25,8 @@ import 'zod-to-json-schema';
|
|
|
25
25
|
import '../../../internals/helpers/promise.js';
|
|
26
26
|
import '../prompts.js';
|
|
27
27
|
import '../../../template.js';
|
|
28
|
-
import '../../../chat-
|
|
28
|
+
import '../../../chat-BdN8hGWn.js';
|
|
29
29
|
import '../../../backend/constants.js';
|
|
30
30
|
import '../../../logger/logger.js';
|
|
31
31
|
import 'pino';
|
|
32
|
-
import '../../../base-
|
|
32
|
+
import '../../../base-BOCDDBvG.js';
|
|
@@ -57,12 +57,12 @@ declare const DeepThinkReActAgentSystemPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
57
57
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
58
58
|
createdAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
59
59
|
}, "strip", zod.ZodTypeAny, {
|
|
60
|
-
instructions: string;
|
|
61
60
|
tools: zod.objectOutputType<{
|
|
62
61
|
name: zod.ZodString;
|
|
63
62
|
description: zod.ZodString;
|
|
64
63
|
schema: zod.ZodString;
|
|
65
64
|
}, zod.ZodTypeAny, "passthrough">[];
|
|
65
|
+
instructions: string;
|
|
66
66
|
createdAt?: string | null | undefined;
|
|
67
67
|
}, {
|
|
68
68
|
tools: zod.objectInputType<{
|
|
@@ -57,12 +57,12 @@ declare const DeepThinkReActAgentSystemPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
57
57
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
58
58
|
createdAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
59
59
|
}, "strip", zod.ZodTypeAny, {
|
|
60
|
-
instructions: string;
|
|
61
60
|
tools: zod.objectOutputType<{
|
|
62
61
|
name: zod.ZodString;
|
|
63
62
|
description: zod.ZodString;
|
|
64
63
|
schema: zod.ZodString;
|
|
65
64
|
}, zod.ZodTypeAny, "passthrough">[];
|
|
65
|
+
instructions: string;
|
|
66
66
|
createdAt?: string | null | undefined;
|
|
67
67
|
}, {
|
|
68
68
|
tools: zod.objectInputType<{
|