@sisu-ai/tool-summarize-text 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
  # Summarize Text Tool
2
8
 
3
9
  A utility tool that asks the active model to summarize large text bodies into concise outputs. Designed for use alongside `webFetch` or other content tools.
@@ -33,3 +39,78 @@ Discover what you can do through examples or documentation. Check it out at http
33
39
  - [License](https://github.com/finger-gun/sisu/blob/main/LICENSE)
34
40
  - [Report a Bug](https://github.com/finger-gun/sisu/issues/new?template=bug_report.md)
35
41
  - [Request a Feature](https://github.com/finger-gun/sisu/issues/new?template=feature_request.md)
42
+
43
+ ---
44
+
45
+ ## Documentation
46
+
47
+ **Core** — [Package docs](packages/core/README.md) · [Error types](packages/core/ERROR_TYPES.md)
48
+
49
+ **Adapters** — [OpenAI](packages/adapters/openai/README.md) · [Anthropic](packages/adapters/anthropic/README.md) · [Ollama](packages/adapters/ollama/README.md)
50
+
51
+ <details>
52
+ <summary>All middleware packages</summary>
53
+
54
+ - [@sisu-ai/mw-agent-run-api](packages/middleware/agent-run-api/README.md)
55
+ - [@sisu-ai/mw-context-compressor](packages/middleware/context-compressor/README.md)
56
+ - [@sisu-ai/mw-control-flow](packages/middleware/control-flow/README.md)
57
+ - [@sisu-ai/mw-conversation-buffer](packages/middleware/conversation-buffer/README.md)
58
+ - [@sisu-ai/mw-cors](packages/middleware/cors/README.md)
59
+ - [@sisu-ai/mw-error-boundary](packages/middleware/error-boundary/README.md)
60
+ - [@sisu-ai/mw-guardrails](packages/middleware/guardrails/README.md)
61
+ - [@sisu-ai/mw-invariants](packages/middleware/invariants/README.md)
62
+ - [@sisu-ai/mw-orchestration](packages/middleware/orchestration/README.md)
63
+ - [@sisu-ai/mw-rag](packages/middleware/rag/README.md)
64
+ - [@sisu-ai/mw-react-parser](packages/middleware/react-parser/README.md)
65
+ - [@sisu-ai/mw-register-tools](packages/middleware/register-tools/README.md)
66
+ - [@sisu-ai/mw-tool-calling](packages/middleware/tool-calling/README.md)
67
+ - [@sisu-ai/mw-trace-viewer](packages/middleware/trace-viewer/README.md)
68
+ - [@sisu-ai/mw-usage-tracker](packages/middleware/usage-tracker/README.md)
69
+ </details>
70
+
71
+ <details>
72
+ <summary>All tool packages</summary>
73
+
74
+ - [@sisu-ai/tool-aws-s3](packages/tools/aws-s3/README.md)
75
+ - [@sisu-ai/tool-azure-blob](packages/tools/azure-blob/README.md)
76
+ - [@sisu-ai/tool-extract-urls](packages/tools/extract-urls/README.md)
77
+ - [@sisu-ai/tool-github-projects](packages/tools/github-projects/README.md)
78
+ - [@sisu-ai/tool-summarize-text](packages/tools/summarize-text/README.md)
79
+ - [@sisu-ai/tool-terminal](packages/tools/terminal/README.md)
80
+ - [@sisu-ai/tool-vec-chroma](packages/tools/vec-chroma/README.md)
81
+ - [@sisu-ai/tool-web-fetch](packages/tools/web-fetch/README.md)
82
+ - [@sisu-ai/tool-web-search-duckduckgo](packages/tools/web-search-duckduckgo/README.md)
83
+ - [@sisu-ai/tool-web-search-google](packages/tools/web-search-google/README.md)
84
+ - [@sisu-ai/tool-web-search-openai](packages/tools/web-search-openai/README.md)
85
+ - [@sisu-ai/tool-wikipedia](packages/tools/wikipedia/README.md)
86
+ </details>
87
+
88
+ <details>
89
+ <summary>All examples</summary>
90
+
91
+ **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)
92
+
93
+ **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)
94
+
95
+ **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)
96
+ </details>
97
+
98
+ ---
99
+
100
+ ## Contributing
101
+
102
+ We build Sisu in the open. Contributions welcome.
103
+
104
+ [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)
105
+
106
+ ---
107
+
108
+ <div align="center">
109
+
110
+ **[Star on GitHub](https://github.com/finger-gun/sisu)** if Sisu helps you build better agents.
111
+
112
+ *Quiet, determined, relentlessly useful.*
113
+
114
+ [Apache 2.0 License](LICENSE)
115
+
116
+ </div>
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { Tool } from '@sisu-ai/core';
2
- export type TargetLength = 'short' | 'medium' | 'long';
1
+ import type { Tool } from "@sisu-ai/core";
2
+ export type TargetLength = "short" | "medium" | "long";
3
3
  export interface SummarizeArgs {
4
4
  text: string;
5
5
  target?: TargetLength;
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- import { z } from 'zod';
1
+ import { z } from "zod";
2
2
  export const summarizeText = {
3
- name: 'summarizeText',
4
- description: 'Summarize a block of text using the current model. Useful for condensing large webFetch outputs while keeping key facts and URLs.',
3
+ name: "summarizeText",
4
+ description: "Summarize a block of text using the current model. Useful for condensing large webFetch outputs while keeping key facts and URLs.",
5
5
  schema: z.object({
6
6
  text: z.string().min(1),
7
- target: z.enum(['short', 'medium', 'long']).optional(),
7
+ target: z.enum(["short", "medium", "long"]).optional(),
8
8
  maxChars: z.number().int().positive().max(50_000).optional(),
9
9
  bullets: z.boolean().optional(),
10
10
  includeCitations: z.boolean().optional(),
11
11
  focus: z.string().optional(),
12
12
  }),
13
- handler: async ({ text, target = 'medium', maxChars, bullets, includeCitations, focus }, ctx) => {
13
+ handler: async ({ text, target = "medium", maxChars, bullets, includeCitations, focus }, ctx) => {
14
14
  const cap = Math.min(Math.max(Number(maxChars ?? 2000), 200), 50_000);
15
15
  const chunks = chunkText(text, 10_000);
16
16
  const chunkSummaries = [];
@@ -18,36 +18,46 @@ export const summarizeText = {
18
18
  // Allocate characters per chunk, allowing a buffer of 200, but not exceeding the cap
19
19
  const charsPerChunk = Math.min(Math.floor(cap / Math.max(chunks.length, 1)) + 200, cap);
20
20
  const prompt = buildPrompt(ch, target, charsPerChunk, bullets, includeCitations, focus, `Part ${i + 1}/${chunks.length}`);
21
- const res = await ctx.model.generate(prompt, { toolChoice: 'none', signal: ctx.signal });
22
- const s = String(res?.message?.content ?? '').trim();
21
+ const res = (await ctx.model.generate(prompt, {
22
+ toolChoice: "none",
23
+ signal: ctx.signal,
24
+ }));
25
+ const s = String(res?.message?.content ?? "").trim();
23
26
  if (s)
24
27
  chunkSummaries.push(s.slice(0, cap));
25
28
  }
26
- const combinedInput = chunkSummaries.join('\n\n');
27
- const finalPrompt = buildPrompt(combinedInput || text, target, cap, bullets, includeCitations, focus, 'Final Synthesis');
28
- const res = await ctx.model.generate(finalPrompt, { toolChoice: 'none', signal: ctx.signal });
29
- const summary = String(res?.message?.content ?? '').slice(0, cap);
29
+ const combinedInput = chunkSummaries.join("\n\n");
30
+ const finalPrompt = buildPrompt(combinedInput || text, target, cap, bullets, includeCitations, focus, "Final Synthesis");
31
+ const res = (await ctx.model.generate(finalPrompt, {
32
+ toolChoice: "none",
33
+ signal: ctx.signal,
34
+ }));
35
+ const summary = String(res?.message?.content ?? "").slice(0, cap);
30
36
  const urls = includeCitations ? extractUrls([summary]) : undefined;
31
37
  return { summary, ...(urls && urls.length ? { urls } : {}) };
32
- }
38
+ },
33
39
  };
34
40
  export default summarizeText;
35
41
  function buildPrompt(text, target, maxChars, bullets, includeCitations, focus, label) {
36
42
  const aims = [];
37
43
  aims.push(`Keep under ${maxChars} characters.`);
38
44
  if (bullets)
39
- aims.push('Prefer concise bullet points.');
45
+ aims.push("Prefer concise bullet points.");
40
46
  if (includeCitations)
41
- aims.push('Preserve any URLs as citations when relevant.');
47
+ aims.push("Preserve any URLs as citations when relevant.");
42
48
  if (focus)
43
49
  aims.push(`Emphasize: ${focus}`);
44
- const density = target === 'short' ? 'High compression' : target === 'long' ? 'Low compression' : 'Balanced compression';
50
+ const density = target === "short"
51
+ ? "High compression"
52
+ : target === "long"
53
+ ? "Low compression"
54
+ : "Balanced compression";
45
55
  const sys = `You are a careful summarizer. ${density}. Do not invent facts. If URLs are present, keep them.`;
46
- const usr = `${label ? `[${label}] ` : ''}Summarize the following text.\n\n${text}`;
47
- const guide = aims.length ? `Guidelines: ${aims.join(' ')}\n` : '';
56
+ const usr = `${label ? `[${label}] ` : ""}Summarize the following text.\n\n${text}`;
57
+ const guide = aims.length ? `Guidelines: ${aims.join(" ")}\n` : "";
48
58
  return [
49
- { role: 'system', content: sys },
50
- { role: 'user', content: `${guide}${usr}` }
59
+ { role: "system", content: sys },
60
+ { role: "user", content: `${guide}${usr}` },
51
61
  ];
52
62
  }
53
63
  function chunkText(s, size = 10_000) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sisu-ai/tool-summarize-text",
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
  "zod": "^3.23.8"
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",