@sisu-ai/mw-react-parser 9.0.1 → 9.0.3

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/README.md CHANGED
@@ -1,3 +1,9 @@
1
+ <div align="right">
2
+ <a href="https://github.com/finger-gun/sisu"><img src="https://github.com/finger-gun/sisu/raw/main/sisu-light.svg" alt="ProjectSpecs" width="100" /></a>
3
+ </div>
4
+
5
+ ---
6
+
1
7
  # @sisu-ai/mw-react-parser
2
8
 
3
9
  Lightweight ReAct-style tool loop. The model proposes an action in plain text, you parse it, execute a tool, then the model reflects and answers.
@@ -93,3 +99,78 @@ Discover what you can do through examples or documentation. Check it out at http
93
99
  - [License](https://github.com/finger-gun/sisu/blob/main/LICENSE)
94
100
  - [Report a Bug](https://github.com/finger-gun/sisu/issues/new?template=bug_report.md)
95
101
  - [Request a Feature](https://github.com/finger-gun/sisu/issues/new?template=feature_request.md)
102
+
103
+ ---
104
+
105
+ ## Documentation
106
+
107
+ **Core** — [Package docs](packages/core/README.md) · [Error types](packages/core/ERROR_TYPES.md)
108
+
109
+ **Adapters** — [OpenAI](packages/adapters/openai/README.md) · [Anthropic](packages/adapters/anthropic/README.md) · [Ollama](packages/adapters/ollama/README.md)
110
+
111
+ <details>
112
+ <summary>All middleware packages</summary>
113
+
114
+ - [@sisu-ai/mw-agent-run-api](packages/middleware/agent-run-api/README.md)
115
+ - [@sisu-ai/mw-context-compressor](packages/middleware/context-compressor/README.md)
116
+ - [@sisu-ai/mw-control-flow](packages/middleware/control-flow/README.md)
117
+ - [@sisu-ai/mw-conversation-buffer](packages/middleware/conversation-buffer/README.md)
118
+ - [@sisu-ai/mw-cors](packages/middleware/cors/README.md)
119
+ - [@sisu-ai/mw-error-boundary](packages/middleware/error-boundary/README.md)
120
+ - [@sisu-ai/mw-guardrails](packages/middleware/guardrails/README.md)
121
+ - [@sisu-ai/mw-invariants](packages/middleware/invariants/README.md)
122
+ - [@sisu-ai/mw-orchestration](packages/middleware/orchestration/README.md)
123
+ - [@sisu-ai/mw-rag](packages/middleware/rag/README.md)
124
+ - [@sisu-ai/mw-react-parser](packages/middleware/react-parser/README.md)
125
+ - [@sisu-ai/mw-register-tools](packages/middleware/register-tools/README.md)
126
+ - [@sisu-ai/mw-tool-calling](packages/middleware/tool-calling/README.md)
127
+ - [@sisu-ai/mw-trace-viewer](packages/middleware/trace-viewer/README.md)
128
+ - [@sisu-ai/mw-usage-tracker](packages/middleware/usage-tracker/README.md)
129
+ </details>
130
+
131
+ <details>
132
+ <summary>All tool packages</summary>
133
+
134
+ - [@sisu-ai/tool-aws-s3](packages/tools/aws-s3/README.md)
135
+ - [@sisu-ai/tool-azure-blob](packages/tools/azure-blob/README.md)
136
+ - [@sisu-ai/tool-extract-urls](packages/tools/extract-urls/README.md)
137
+ - [@sisu-ai/tool-github-projects](packages/tools/github-projects/README.md)
138
+ - [@sisu-ai/tool-summarize-text](packages/tools/summarize-text/README.md)
139
+ - [@sisu-ai/tool-terminal](packages/tools/terminal/README.md)
140
+ - [@sisu-ai/tool-vec-chroma](packages/tools/vec-chroma/README.md)
141
+ - [@sisu-ai/tool-web-fetch](packages/tools/web-fetch/README.md)
142
+ - [@sisu-ai/tool-web-search-duckduckgo](packages/tools/web-search-duckduckgo/README.md)
143
+ - [@sisu-ai/tool-web-search-google](packages/tools/web-search-google/README.md)
144
+ - [@sisu-ai/tool-web-search-openai](packages/tools/web-search-openai/README.md)
145
+ - [@sisu-ai/tool-wikipedia](packages/tools/wikipedia/README.md)
146
+ </details>
147
+
148
+ <details>
149
+ <summary>All examples</summary>
150
+
151
+ **Anthropic** — [hello](examples/anthropic-hello/README.md) · [control-flow](examples/anthropic-control-flow/README.md) · [stream](examples/anthropic-stream/README.md) · [weather](examples/anthropic-weather/README.md)
152
+
153
+ **Ollama** — [hello](examples/ollama-hello/README.md) · [stream](examples/ollama-stream/README.md) · [vision](examples/ollama-vision/README.md) · [weather](examples/ollama-weather/README.md) · [web-search](examples/ollama-web-search/README.md)
154
+
155
+ **OpenAI** — [hello](examples/openai-hello/README.md) · [weather](examples/openai-weather/README.md) · [stream](examples/openai-stream/README.md) · [vision](examples/openai-vision/README.md) · [reasoning](examples/openai-reasoning/README.md) · [react](examples/openai-react/README.md) · [control-flow](examples/openai-control-flow/README.md) · [branch](examples/openai-branch/README.md) · [parallel](examples/openai-parallel/README.md) · [graph](examples/openai-graph/README.md) · [orchestration](examples/openai-orchestration/README.md) · [orchestration-adaptive](examples/openai-orchestration-adaptive/README.md) · [guardrails](examples/openai-guardrails/README.md) · [error-handling](examples/openai-error-handling/README.md) · [rag-chroma](examples/openai-rag-chroma/README.md) · [web-search](examples/openai-web-search/README.md) · [web-fetch](examples/openai-web-fetch/README.md) · [wikipedia](examples/openai-wikipedia/README.md) · [terminal](examples/openai-terminal/README.md) · [github-projects](examples/openai-github-projects/README.md) · [server](examples/openai-server/README.md) · [aws-s3](examples/openai-aws-s3/README.md) · [azure-blob](examples/openai-azure-blob/README.md)
156
+ </details>
157
+
158
+ ---
159
+
160
+ ## Contributing
161
+
162
+ We build Sisu in the open. Contributions welcome.
163
+
164
+ [Contributing Guide](CONTRIBUTING.md) · [Report a Bug](https://github.com/finger-gun/sisu/issues/new?template=bug_report.md) · [Request a Feature](https://github.com/finger-gun/sisu/issues/new?template=feature_request.md) · [Code of Conduct](CODE_OF_CONDUCT.md)
165
+
166
+ ---
167
+
168
+ <div align="center">
169
+
170
+ **[Star on GitHub](https://github.com/finger-gun/sisu)** if Sisu helps you build better agents.
171
+
172
+ *Quiet, determined, relentlessly useful.*
173
+
174
+ [Apache 2.0 License](LICENSE)
175
+
176
+ </div>
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type { Middleware } from '@sisu-ai/core';
1
+ import type { Middleware } from "@sisu-ai/core";
2
2
  export declare const reactToolLoop: () => Middleware;
package/dist/index.js CHANGED
@@ -1,33 +1,44 @@
1
1
  export const reactToolLoop = () => {
2
2
  return async (ctx, next) => {
3
3
  await next(); // upstream prep
4
- const res = await ctx.model.generate(ctx.messages, { toolChoice: 'none', signal: ctx.signal });
4
+ const res = (await ctx.model.generate(ctx.messages, {
5
+ toolChoice: "none",
6
+ signal: ctx.signal,
7
+ }));
5
8
  const msg = res.message;
6
- const content = msg?.content ?? '';
9
+ const content = msg?.content ?? "";
7
10
  const toolMatch = content.match(/Action:\s*(\w+)/i);
8
11
  const inputMatch = content.match(/Action Input:\s*([\s\S]*)/i);
9
12
  if (toolMatch && inputMatch) {
10
13
  const toolName = toolMatch[1];
11
- ctx.log.info?.('[react] parsed tool action', { toolName });
14
+ ctx.log.info?.("[react] parsed tool action", { toolName });
12
15
  const tool = ctx.tools.get(toolName);
13
16
  if (!tool)
14
- throw new Error('Unknown tool: ' + toolName);
17
+ throw new Error("Unknown tool: " + toolName);
15
18
  let args = inputMatch[1].trim();
16
19
  try {
17
- args = JSON.parse(args);
20
+ args = JSON.parse(String(args));
18
21
  }
19
- catch { }
20
- ctx.log.debug?.('[react] invoking tool', { toolName, args });
22
+ catch {
23
+ args = inputMatch[1].trim();
24
+ }
25
+ ctx.log.debug?.("[react] invoking tool", { toolName, args });
21
26
  const result = await tool.handler(args, ctx);
22
27
  // ReAct pattern: feed tool output back as a user message (not provider-specific tool role)
23
- const rendered = typeof result === 'string' ? result : JSON.stringify(result);
24
- ctx.messages.push({ role: 'user', content: `Observation (${toolName}): ${rendered}` });
25
- const res2 = await ctx.model.generate(ctx.messages, { toolChoice: 'none', signal: ctx.signal });
26
- ctx.log.debug?.('[react] got assistant follow-up');
28
+ const rendered = typeof result === "string" ? result : JSON.stringify(result);
29
+ ctx.messages.push({
30
+ role: "user",
31
+ content: `Observation (${toolName}): ${rendered}`,
32
+ });
33
+ const res2 = (await ctx.model.generate(ctx.messages, {
34
+ toolChoice: "none",
35
+ signal: ctx.signal,
36
+ }));
37
+ ctx.log.debug?.("[react] got assistant follow-up");
27
38
  ctx.messages.push(res2.message);
28
39
  }
29
40
  else {
30
- ctx.log.debug?.('[react] no tool action parsed; appending assistant message');
41
+ ctx.log.debug?.("[react] no tool action parsed; appending assistant message");
31
42
  if (msg)
32
43
  ctx.messages.push(msg);
33
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sisu-ai/mw-react-parser",
3
- "version": "9.0.1",
3
+ "version": "9.0.3",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,7 +12,7 @@
12
12
  "access": "public"
13
13
  },
14
14
  "peerDependencies": {
15
- "@sisu-ai/core": "^2.3.1"
15
+ "@sisu-ai/core": "^2.3.2"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",