@mappies/miniwat-agent 0.1.0 → 0.3.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/index.cjs +88 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -7
- package/dist/index.d.ts +9 -7
- package/dist/index.js +85 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -20,26 +20,108 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
Agent: () => Agent
|
|
23
|
+
Agent: () => Agent,
|
|
24
|
+
AgentConfig: () => AgentConfig,
|
|
25
|
+
Session: () => Session
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(index_exports);
|
|
26
28
|
|
|
27
29
|
// src/entities/agent.ts
|
|
30
|
+
var import_miniwat_agent_core = require("@mappies/miniwat-agent-core");
|
|
31
|
+
var import_stream = require("stream");
|
|
28
32
|
var Agent = class {
|
|
29
33
|
constructor(config) {
|
|
30
34
|
this.model = config.model;
|
|
31
35
|
this.instruction = config.instruction;
|
|
32
36
|
this.toolDispatcher = config.toolDispatcher;
|
|
33
37
|
}
|
|
34
|
-
async invoke(session, option) {
|
|
35
|
-
|
|
38
|
+
async invoke(prompt, session, option) {
|
|
39
|
+
session.messages.push(new import_miniwat_agent_core.Message({ type: import_miniwat_agent_core.MessageType.User, content: prompt, createdTimestamp: (/* @__PURE__ */ new Date()).toISOString() }));
|
|
40
|
+
const response = await this.model.invoke(session.messages, {
|
|
41
|
+
...option,
|
|
42
|
+
instruction: this.instruction
|
|
43
|
+
});
|
|
44
|
+
session.messages.push(response.message);
|
|
45
|
+
if (option?.event?.onResponse) {
|
|
46
|
+
await option.event.onResponse(response.message);
|
|
47
|
+
}
|
|
48
|
+
return response;
|
|
36
49
|
}
|
|
37
|
-
async stream(session, option) {
|
|
38
|
-
|
|
50
|
+
async stream(prompt, session, option) {
|
|
51
|
+
session.messages.push(new import_miniwat_agent_core.Message({
|
|
52
|
+
type: import_miniwat_agent_core.MessageType.User,
|
|
53
|
+
content: prompt,
|
|
54
|
+
createdTimestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
55
|
+
}));
|
|
56
|
+
const source = await this.model.stream(session.messages, {
|
|
57
|
+
...option,
|
|
58
|
+
instruction: this.instruction
|
|
59
|
+
});
|
|
60
|
+
const tee = new import_stream.PassThrough();
|
|
61
|
+
const chunks = [];
|
|
62
|
+
let sourceEnded = false;
|
|
63
|
+
let resolveCompleted;
|
|
64
|
+
let rejectCompleted;
|
|
65
|
+
tee.promise = new Promise((resolve, reject) => {
|
|
66
|
+
resolveCompleted = resolve;
|
|
67
|
+
rejectCompleted = reject;
|
|
68
|
+
});
|
|
69
|
+
source.on("data", (chunk) => {
|
|
70
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
|
|
71
|
+
});
|
|
72
|
+
source.on("end", async () => {
|
|
73
|
+
sourceEnded = true;
|
|
74
|
+
(async () => {
|
|
75
|
+
const content = Buffer.concat(chunks).toString("utf8");
|
|
76
|
+
if (content.trim().length > 0) {
|
|
77
|
+
let responseMessage = new import_miniwat_agent_core.Message({
|
|
78
|
+
type: import_miniwat_agent_core.MessageType.Agent,
|
|
79
|
+
content,
|
|
80
|
+
createdTimestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
81
|
+
});
|
|
82
|
+
session.messages.push(responseMessage);
|
|
83
|
+
if (option?.event?.onResponse) {
|
|
84
|
+
await option.event.onResponse(responseMessage);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
resolveCompleted();
|
|
88
|
+
})().catch(rejectCompleted);
|
|
89
|
+
});
|
|
90
|
+
source.on("error", (error) => {
|
|
91
|
+
rejectCompleted(error);
|
|
92
|
+
tee.destroy(error);
|
|
93
|
+
});
|
|
94
|
+
tee.on("close", () => {
|
|
95
|
+
if (!sourceEnded && !source.destroyed) {
|
|
96
|
+
const err = new Error("Stream closed before completion");
|
|
97
|
+
rejectCompleted(err);
|
|
98
|
+
source.destroy(err);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
source.pipe(tee);
|
|
102
|
+
return tee;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// src/entities/agentConfig.ts
|
|
107
|
+
var AgentConfig = class {
|
|
108
|
+
constructor(data) {
|
|
109
|
+
this.instruction = data.instruction;
|
|
110
|
+
this.model = data.model;
|
|
111
|
+
this.toolDispatcher = data.toolDispatcher;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/entities/session.ts
|
|
116
|
+
var Session = class {
|
|
117
|
+
constructor(data) {
|
|
118
|
+
this.messages = data?.messages || [];
|
|
39
119
|
}
|
|
40
120
|
};
|
|
41
121
|
// Annotate the CommonJS export names for ESM import in node:
|
|
42
122
|
0 && (module.exports = {
|
|
43
|
-
Agent
|
|
123
|
+
Agent,
|
|
124
|
+
AgentConfig,
|
|
125
|
+
Session
|
|
44
126
|
});
|
|
45
127
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/entities/agent.ts"],"sourcesContent":["export { Agent } from './entities/agent';\nexport { AgentConfig } from './entities/agentConfig';\nexport { Session } from './entities/session';","import { Model, ModelOption, ResponseMessage, Instruction } from \"@mappies/miniwat-agent-core\";\nimport { AgentConfig } from \"./agentConfig\";\nimport { ToolDispatcher } from \"@mappies/miniwat-mcp-core\";\nimport { Readable } from \"stream\";\nimport { Session } from \"./session\";\n\nexport class Agent\n{\n public readonly instruction
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/entities/agent.ts","../src/entities/agentConfig.ts","../src/entities/session.ts"],"sourcesContent":["export { Agent } from './entities/agent';\nexport { AgentConfig } from './entities/agentConfig';\nexport { Session } from './entities/session';","import { Model, ModelOption, ResponseMessage, Instruction, Message, MessageType } from \"@mappies/miniwat-agent-core\";\nimport { AgentConfig } from \"./agentConfig\";\nimport { ToolDispatcher } from \"@mappies/miniwat-mcp-core\";\nimport { PassThrough, Readable } from \"stream\";\nimport { Session } from \"./session\";\n\nexport class Agent\n{\n public readonly instruction?: Instruction\n public readonly model: Model;\n public readonly toolDispatcher?: ToolDispatcher;\n\n constructor(config: AgentConfig)\n {\n this.model = config.model;\n this.instruction = config.instruction;\n this.toolDispatcher = config.toolDispatcher;\n }\n\n async invoke(prompt: string, session: Session, option?: Omit<ModelOption, 'instruction'>): Promise<ResponseMessage>\n {\n session.messages.push(new Message({type: MessageType.User, content: prompt, createdTimestamp: new Date().toISOString()}));\n\n const response = await this.model.invoke(session.messages, {\n ...option,\n instruction: this.instruction\n });\n\n session.messages.push(response.message);\n\n if(option?.event?.onResponse)\n {\n await option.event.onResponse(response.message);\n }\n\n return response;\n }\n\n async stream(prompt: string, session: Session, option?: Omit<ModelOption, \"instruction\">): Promise<Readable>\n {\n session.messages.push(new Message({\n type: MessageType.User,\n content: prompt,\n createdTimestamp: new Date().toISOString()\n }));\n\n const source = await this.model.stream(session.messages, {\n ...option,\n instruction: this.instruction\n });\n\n const tee = new PassThrough();\n const chunks: Buffer[] = [];\n let sourceEnded = false;\n\n let resolveCompleted!: () => void;\n let rejectCompleted!: (reason?: any) => void;\n (tee as any).promise = new Promise<void>((resolve, reject) =>\n {\n resolveCompleted = resolve;\n rejectCompleted = reject;\n });\n\n source.on(\"data\", (chunk) =>\n {\n chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));\n });\n\n source.on(\"end\", async () =>\n {\n sourceEnded = true;\n \n (async ()=>\n {\n const content = Buffer.concat(chunks).toString(\"utf8\");\n\n if (content.trim().length > 0)\n {\n let responseMessage = new Message({\n type: MessageType.Agent,\n content,\n createdTimestamp: new Date().toISOString()\n });\n\n session.messages.push(responseMessage);\n\n if(option?.event?.onResponse)\n {\n await option.event.onResponse(responseMessage);\n }\n }\n\n resolveCompleted();\n })().catch(rejectCompleted);\n });\n\n source.on(\"error\", (error) =>\n {\n rejectCompleted(error);\n tee.destroy(error);\n });\n\n tee.on(\"close\", () =>\n {\n if (!sourceEnded && !source.destroyed)\n {\n const err = new Error(\"Stream closed before completion\");\n rejectCompleted(err)\n source.destroy(err);\n }\n });\n\n source.pipe(tee);\n\n return tee;\n }\n}","import { Model, Instruction } from \"@mappies/miniwat-agent-core\";\nimport { ToolDispatcher } from \"@mappies/miniwat-mcp-core\";\n\nexport class AgentConfig \n{\n /**\n * Agent instruction\n */\n instruction?: Instruction;\n\n /**\n * The language model used by this agent.\n */\n model: Model;\n\n /**\n * Tool dispatcher for tools.\n */\n toolDispatcher?: ToolDispatcher;\n\n constructor(data:AgentConfig)\n {\n this.instruction = data.instruction;\n this.model = data.model;\n this.toolDispatcher = data.toolDispatcher;\n }\n}","import { Message } from \"@mappies/miniwat-agent-core\";\n\nexport class Session\n{\n public messages: Message[];\n\n constructor(data?:Partial<Session>)\n {\n this.messages = data?.messages || []\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gCAAuF;AAGvF,oBAAsC;AAG/B,IAAM,QAAN,MACP;AAAA,EAKI,YAAY,QACZ;AACI,SAAK,QAAQ,OAAO;AACpB,SAAK,cAAc,OAAO;AAC1B,SAAK,iBAAiB,OAAO;AAAA,EACjC;AAAA,EAEA,MAAM,OAAO,QAAgB,SAAkB,QAC/C;AACI,YAAQ,SAAS,KAAK,IAAI,kCAAQ,EAAC,MAAM,sCAAY,MAAM,SAAS,QAAQ,mBAAkB,oBAAI,KAAK,GAAE,YAAY,EAAC,CAAC,CAAC;AAExH,UAAM,WAAW,MAAM,KAAK,MAAM,OAAO,QAAQ,UAAU;AAAA,MACvD,GAAG;AAAA,MACH,aAAa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J;AAEA,yBAAiB;AAAA,MACrB,GAAG,EAAE,MAAM,eAAe;AAAA,IAC9B,CAAC;AAED,WAAO,GAAG,SAAS,CAAC,UACpB;AACI,sBAAgB,KAAK;AACrB,UAAI,QAAQ,KAAK;AAAA,IACrB,CAAC;AAED,QAAI,GAAG,SAAS,MAChB;AACI,UAAI,CAAC,eAAe,CAAC,OAAO,WAC5B;AACI,cAAM,MAAM,IAAI,MAAM,iCAAiC;AACvD,wBAAgB,GAAG;AACnB,eAAO,QAAQ,GAAG;AAAA,MACtB;AAAA,IACJ,CAAC;AAED,WAAO,KAAK,GAAG;AAEf,WAAO;AAAA,EACX;AACJ;;;ACjHO,IAAM,cAAN,MACP;AAAA,EAgBI,YAAY,MACZ;AACI,SAAK,cAAc,KAAK;AACxB,SAAK,QAAQ,KAAK;AAClB,SAAK,iBAAiB,KAAK;AAAA,EAC/B;AACJ;;;ACxBO,IAAM,UAAN,MACP;AAAA,EAGI,YAAY,MACZ;AACI,SAAK,WAAW,MAAM,YAAY,CAAC;AAAA,EACvC;AACJ;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -2,11 +2,11 @@ import { Instruction, Model, Message, ModelOption, ResponseMessage } from '@mapp
|
|
|
2
2
|
import { ToolDispatcher } from '@mappies/miniwat-mcp-core';
|
|
3
3
|
import { Readable } from 'stream';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
declare class AgentConfig {
|
|
6
6
|
/**
|
|
7
7
|
* Agent instruction
|
|
8
8
|
*/
|
|
9
|
-
instruction
|
|
9
|
+
instruction?: Instruction;
|
|
10
10
|
/**
|
|
11
11
|
* The language model used by this agent.
|
|
12
12
|
*/
|
|
@@ -15,19 +15,21 @@ interface AgentConfig {
|
|
|
15
15
|
* Tool dispatcher for tools.
|
|
16
16
|
*/
|
|
17
17
|
toolDispatcher?: ToolDispatcher;
|
|
18
|
+
constructor(data: AgentConfig);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
declare class Session {
|
|
21
22
|
messages: Message[];
|
|
23
|
+
constructor(data?: Partial<Session>);
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
declare class Agent {
|
|
25
|
-
readonly instruction
|
|
27
|
+
readonly instruction?: Instruction;
|
|
26
28
|
readonly model: Model;
|
|
27
29
|
readonly toolDispatcher?: ToolDispatcher;
|
|
28
30
|
constructor(config: AgentConfig);
|
|
29
|
-
invoke(session: Session, option?: Omit<ModelOption, 'instruction'>): Promise<ResponseMessage>;
|
|
30
|
-
stream(session: Session, option?: Omit<ModelOption,
|
|
31
|
+
invoke(prompt: string, session: Session, option?: Omit<ModelOption, 'instruction'>): Promise<ResponseMessage>;
|
|
32
|
+
stream(prompt: string, session: Session, option?: Omit<ModelOption, "instruction">): Promise<Readable>;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
export { Agent,
|
|
35
|
+
export { Agent, AgentConfig, Session };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { Instruction, Model, Message, ModelOption, ResponseMessage } from '@mapp
|
|
|
2
2
|
import { ToolDispatcher } from '@mappies/miniwat-mcp-core';
|
|
3
3
|
import { Readable } from 'stream';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
declare class AgentConfig {
|
|
6
6
|
/**
|
|
7
7
|
* Agent instruction
|
|
8
8
|
*/
|
|
9
|
-
instruction
|
|
9
|
+
instruction?: Instruction;
|
|
10
10
|
/**
|
|
11
11
|
* The language model used by this agent.
|
|
12
12
|
*/
|
|
@@ -15,19 +15,21 @@ interface AgentConfig {
|
|
|
15
15
|
* Tool dispatcher for tools.
|
|
16
16
|
*/
|
|
17
17
|
toolDispatcher?: ToolDispatcher;
|
|
18
|
+
constructor(data: AgentConfig);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
declare class Session {
|
|
21
22
|
messages: Message[];
|
|
23
|
+
constructor(data?: Partial<Session>);
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
declare class Agent {
|
|
25
|
-
readonly instruction
|
|
27
|
+
readonly instruction?: Instruction;
|
|
26
28
|
readonly model: Model;
|
|
27
29
|
readonly toolDispatcher?: ToolDispatcher;
|
|
28
30
|
constructor(config: AgentConfig);
|
|
29
|
-
invoke(session: Session, option?: Omit<ModelOption, 'instruction'>): Promise<ResponseMessage>;
|
|
30
|
-
stream(session: Session, option?: Omit<ModelOption,
|
|
31
|
+
invoke(prompt: string, session: Session, option?: Omit<ModelOption, 'instruction'>): Promise<ResponseMessage>;
|
|
32
|
+
stream(prompt: string, session: Session, option?: Omit<ModelOption, "instruction">): Promise<Readable>;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
export { Agent,
|
|
35
|
+
export { Agent, AgentConfig, Session };
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,98 @@
|
|
|
1
1
|
// src/entities/agent.ts
|
|
2
|
+
import { Message, MessageType } from "@mappies/miniwat-agent-core";
|
|
3
|
+
import { PassThrough } from "stream";
|
|
2
4
|
var Agent = class {
|
|
3
5
|
constructor(config) {
|
|
4
6
|
this.model = config.model;
|
|
5
7
|
this.instruction = config.instruction;
|
|
6
8
|
this.toolDispatcher = config.toolDispatcher;
|
|
7
9
|
}
|
|
8
|
-
async invoke(session, option) {
|
|
9
|
-
|
|
10
|
+
async invoke(prompt, session, option) {
|
|
11
|
+
session.messages.push(new Message({ type: MessageType.User, content: prompt, createdTimestamp: (/* @__PURE__ */ new Date()).toISOString() }));
|
|
12
|
+
const response = await this.model.invoke(session.messages, {
|
|
13
|
+
...option,
|
|
14
|
+
instruction: this.instruction
|
|
15
|
+
});
|
|
16
|
+
session.messages.push(response.message);
|
|
17
|
+
if (option?.event?.onResponse) {
|
|
18
|
+
await option.event.onResponse(response.message);
|
|
19
|
+
}
|
|
20
|
+
return response;
|
|
10
21
|
}
|
|
11
|
-
async stream(session, option) {
|
|
12
|
-
|
|
22
|
+
async stream(prompt, session, option) {
|
|
23
|
+
session.messages.push(new Message({
|
|
24
|
+
type: MessageType.User,
|
|
25
|
+
content: prompt,
|
|
26
|
+
createdTimestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
27
|
+
}));
|
|
28
|
+
const source = await this.model.stream(session.messages, {
|
|
29
|
+
...option,
|
|
30
|
+
instruction: this.instruction
|
|
31
|
+
});
|
|
32
|
+
const tee = new PassThrough();
|
|
33
|
+
const chunks = [];
|
|
34
|
+
let sourceEnded = false;
|
|
35
|
+
let resolveCompleted;
|
|
36
|
+
let rejectCompleted;
|
|
37
|
+
tee.promise = new Promise((resolve, reject) => {
|
|
38
|
+
resolveCompleted = resolve;
|
|
39
|
+
rejectCompleted = reject;
|
|
40
|
+
});
|
|
41
|
+
source.on("data", (chunk) => {
|
|
42
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
|
|
43
|
+
});
|
|
44
|
+
source.on("end", async () => {
|
|
45
|
+
sourceEnded = true;
|
|
46
|
+
(async () => {
|
|
47
|
+
const content = Buffer.concat(chunks).toString("utf8");
|
|
48
|
+
if (content.trim().length > 0) {
|
|
49
|
+
let responseMessage = new Message({
|
|
50
|
+
type: MessageType.Agent,
|
|
51
|
+
content,
|
|
52
|
+
createdTimestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
53
|
+
});
|
|
54
|
+
session.messages.push(responseMessage);
|
|
55
|
+
if (option?.event?.onResponse) {
|
|
56
|
+
await option.event.onResponse(responseMessage);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
resolveCompleted();
|
|
60
|
+
})().catch(rejectCompleted);
|
|
61
|
+
});
|
|
62
|
+
source.on("error", (error) => {
|
|
63
|
+
rejectCompleted(error);
|
|
64
|
+
tee.destroy(error);
|
|
65
|
+
});
|
|
66
|
+
tee.on("close", () => {
|
|
67
|
+
if (!sourceEnded && !source.destroyed) {
|
|
68
|
+
const err = new Error("Stream closed before completion");
|
|
69
|
+
rejectCompleted(err);
|
|
70
|
+
source.destroy(err);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
source.pipe(tee);
|
|
74
|
+
return tee;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/entities/agentConfig.ts
|
|
79
|
+
var AgentConfig = class {
|
|
80
|
+
constructor(data) {
|
|
81
|
+
this.instruction = data.instruction;
|
|
82
|
+
this.model = data.model;
|
|
83
|
+
this.toolDispatcher = data.toolDispatcher;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/entities/session.ts
|
|
88
|
+
var Session = class {
|
|
89
|
+
constructor(data) {
|
|
90
|
+
this.messages = data?.messages || [];
|
|
13
91
|
}
|
|
14
92
|
};
|
|
15
93
|
export {
|
|
16
|
-
Agent
|
|
94
|
+
Agent,
|
|
95
|
+
AgentConfig,
|
|
96
|
+
Session
|
|
17
97
|
};
|
|
18
98
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/entities/agent.ts"],"sourcesContent":["import { Model, ModelOption, ResponseMessage, Instruction } from \"@mappies/miniwat-agent-core\";\nimport { AgentConfig } from \"./agentConfig\";\nimport { ToolDispatcher } from \"@mappies/miniwat-mcp-core\";\nimport { Readable } from \"stream\";\nimport { Session } from \"./session\";\n\nexport class Agent\n{\n public readonly instruction
|
|
1
|
+
{"version":3,"sources":["../src/entities/agent.ts","../src/entities/agentConfig.ts","../src/entities/session.ts"],"sourcesContent":["import { Model, ModelOption, ResponseMessage, Instruction, Message, MessageType } from \"@mappies/miniwat-agent-core\";\nimport { AgentConfig } from \"./agentConfig\";\nimport { ToolDispatcher } from \"@mappies/miniwat-mcp-core\";\nimport { PassThrough, Readable } from \"stream\";\nimport { Session } from \"./session\";\n\nexport class Agent\n{\n public readonly instruction?: Instruction\n public readonly model: Model;\n public readonly toolDispatcher?: ToolDispatcher;\n\n constructor(config: AgentConfig)\n {\n this.model = config.model;\n this.instruction = config.instruction;\n this.toolDispatcher = config.toolDispatcher;\n }\n\n async invoke(prompt: string, session: Session, option?: Omit<ModelOption, 'instruction'>): Promise<ResponseMessage>\n {\n session.messages.push(new Message({type: MessageType.User, content: prompt, createdTimestamp: new Date().toISOString()}));\n\n const response = await this.model.invoke(session.messages, {\n ...option,\n instruction: this.instruction\n });\n\n session.messages.push(response.message);\n\n if(option?.event?.onResponse)\n {\n await option.event.onResponse(response.message);\n }\n\n return response;\n }\n\n async stream(prompt: string, session: Session, option?: Omit<ModelOption, \"instruction\">): Promise<Readable>\n {\n session.messages.push(new Message({\n type: MessageType.User,\n content: prompt,\n createdTimestamp: new Date().toISOString()\n }));\n\n const source = await this.model.stream(session.messages, {\n ...option,\n instruction: this.instruction\n });\n\n const tee = new PassThrough();\n const chunks: Buffer[] = [];\n let sourceEnded = false;\n\n let resolveCompleted!: () => void;\n let rejectCompleted!: (reason?: any) => void;\n (tee as any).promise = new Promise<void>((resolve, reject) =>\n {\n resolveCompleted = resolve;\n rejectCompleted = reject;\n });\n\n source.on(\"data\", (chunk) =>\n {\n chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));\n });\n\n source.on(\"end\", async () =>\n {\n sourceEnded = true;\n \n (async ()=>\n {\n const content = Buffer.concat(chunks).toString(\"utf8\");\n\n if (content.trim().length > 0)\n {\n let responseMessage = new Message({\n type: MessageType.Agent,\n content,\n createdTimestamp: new Date().toISOString()\n });\n\n session.messages.push(responseMessage);\n\n if(option?.event?.onResponse)\n {\n await option.event.onResponse(responseMessage);\n }\n }\n\n resolveCompleted();\n })().catch(rejectCompleted);\n });\n\n source.on(\"error\", (error) =>\n {\n rejectCompleted(error);\n tee.destroy(error);\n });\n\n tee.on(\"close\", () =>\n {\n if (!sourceEnded && !source.destroyed)\n {\n const err = new Error(\"Stream closed before completion\");\n rejectCompleted(err)\n source.destroy(err);\n }\n });\n\n source.pipe(tee);\n\n return tee;\n }\n}","import { Model, Instruction } from \"@mappies/miniwat-agent-core\";\nimport { ToolDispatcher } from \"@mappies/miniwat-mcp-core\";\n\nexport class AgentConfig \n{\n /**\n * Agent instruction\n */\n instruction?: Instruction;\n\n /**\n * The language model used by this agent.\n */\n model: Model;\n\n /**\n * Tool dispatcher for tools.\n */\n toolDispatcher?: ToolDispatcher;\n\n constructor(data:AgentConfig)\n {\n this.instruction = data.instruction;\n this.model = data.model;\n this.toolDispatcher = data.toolDispatcher;\n }\n}","import { Message } from \"@mappies/miniwat-agent-core\";\n\nexport class Session\n{\n public messages: Message[];\n\n constructor(data?:Partial<Session>)\n {\n this.messages = data?.messages || []\n }\n}"],"mappings":";AAAA,SAA2D,SAAS,mBAAmB;AAGvF,SAAS,mBAA6B;AAG/B,IAAM,QAAN,MACP;AAAA,EAKI,YAAY,QACZ;AACI,SAAK,QAAQ,OAAO;AACpB,SAAK,cAAc,OAAO;AAC1B,SAAK,iBAAiB,OAAO;AAAA,EACjC;AAAA,EAEA,MAAM,OAAO,QAAgB,SAAkB,QAC/C;AACI,YAAQ,SAAS,KAAK,IAAI,QAAQ,EAAC,MAAM,YAAY,MAAM,SAAS,QAAQ,mBAAkB,oBAAI,KAAK,GAAE,YAAY,EAAC,CAAC,CAAC;AAExH,UAAM,WAAW,MAAM,KAAK,MAAM,OAAO,QAAQ,UAAU;AAAA,MACvD,GAAG;AAAA,MACH,aAAa,KAAK;AAAA,IACtB,CAAC;AAED,YAAQ,SAAS,KAAK,SAAS,OAAO;AAEtC,QAAG,QAAQ,OAAO,YAClB;AACI,YAAM,OAAO,MAAM,WAAW,SAAS,OAAO;AAAA,IAClD;AAEA,WAAO;AAAA,EACX;AAAA,EAEA,MAAM,OAAO,QAAgB,SAAkB,QAC/C;AACI,YAAQ,SAAS,KAAK,IAAI,QAAQ;AAAA,MAC9B,MAAM,YAAY;AAAA,MAClB,SAAS;AAAA,MACT,mBAAkB,oBAAI,KAAK,GAAE,YAAY;AAAA,IAC7C,CAAC,CAAC;AAEF,UAAM,SAAS,MAAM,KAAK,MAAM,OAAO,QAAQ,UA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AAN,MACP;AAAA,EAgBI,YAAY,MACZ;AACI,SAAK,cAAc,KAAK;AACxB,SAAK,QAAQ,KAAK;AAClB,SAAK,iBAAiB,KAAK;AAAA,EAC/B;AACJ;;;ACxBO,IAAM,UAAN,MACP;AAAA,EAGI,YAAY,MACZ;AACI,SAAK,WAAW,MAAM,YAAY,CAAC;AAAA,EACvC;AACJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mappies/miniwat-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Miniwat Agent",
|
|
5
5
|
"homepage": "https://gitlab.com/mappies/miniwat-agent#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"vitest": "^4.1.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@mappies/miniwat-agent-core": "^0.
|
|
46
|
+
"@mappies/miniwat-agent-core": "^0.14.0",
|
|
47
47
|
"@mappies/miniwat-mcp-core": "^0.7.0"
|
|
48
48
|
}
|
|
49
49
|
}
|