@deepagents/toolbox 7.0.2 → 7.1.1
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.js +127 -90
- package/dist/index.js.map +4 -4
- package/dist/lib/ddg-search.d.ts.map +1 -1
- package/dist/lib/ddg-search.js +7 -2
- package/dist/lib/ddg-search.js.map +2 -2
- package/dist/lib/filesystem.d.ts +155 -150
- package/dist/lib/filesystem.d.ts.map +1 -1
- package/dist/lib/filesystem.js +12 -21
- package/dist/lib/filesystem.js.map +3 -3
- package/dist/lib/hackernews-search.d.ts +804 -775
- package/dist/lib/hackernews-search.d.ts.map +1 -1
- package/dist/lib/hackernews-search.js +78 -64
- package/dist/lib/hackernews-search.js.map +3 -3
- package/dist/lib/scratchbad.d.ts +91 -30
- package/dist/lib/scratchbad.d.ts.map +1 -1
- package/dist/lib/scratchbad.js +1 -9
- package/dist/lib/scratchbad.js.map +3 -3
- package/dist/lib/user-story-formatter.d.ts +118 -30
- package/dist/lib/user-story-formatter.d.ts.map +1 -1
- package/dist/lib/user-story-formatter.js +1 -9
- package/dist/lib/user-story-formatter.js.map +3 -3
- package/dist/lib/weather.d.ts.map +1 -1
- package/dist/lib/weather.js +28 -6
- package/dist/lib/weather.js.map +2 -2
- package/dist/lib/web-search.js +7 -2
- package/dist/lib/web-search.js.map +2 -2
- package/package.json +2 -3
- package/dist/lib/state.d.ts +0 -3
- package/dist/lib/state.d.ts.map +0 -1
- package/dist/lib/state.js +0 -8
- package/dist/lib/state.js.map +0 -7
package/dist/index.js
CHANGED
|
@@ -41,8 +41,13 @@ function exec(command, working_directory, environment_vars) {
|
|
|
41
41
|
// packages/toolbox/src/lib/ddg-search.ts
|
|
42
42
|
import { tool as tool2 } from "ai";
|
|
43
43
|
import * as ddg from "duck-duck-scrape";
|
|
44
|
-
import { uniqBy } from "lodash-es";
|
|
45
44
|
import { z as z2 } from "zod";
|
|
45
|
+
var searchTimes = {
|
|
46
|
+
d: ddg.SearchTimeType.DAY,
|
|
47
|
+
w: ddg.SearchTimeType.WEEK,
|
|
48
|
+
m: ddg.SearchTimeType.MONTH,
|
|
49
|
+
y: ddg.SearchTimeType.YEAR
|
|
50
|
+
};
|
|
46
51
|
async function serp({
|
|
47
52
|
query,
|
|
48
53
|
source,
|
|
@@ -54,7 +59,7 @@ async function serp({
|
|
|
54
59
|
"STRICT"
|
|
55
60
|
// input.safesearch.toUpperCase() as keyof typeof ddg.SafeSearchType
|
|
56
61
|
];
|
|
57
|
-
const time =
|
|
62
|
+
const time = searchTimes[input.time ?? "y"];
|
|
58
63
|
if (source === "text") {
|
|
59
64
|
const res2 = await ddg.search(
|
|
60
65
|
query,
|
|
@@ -183,13 +188,6 @@ import z4 from "zod";
|
|
|
183
188
|
import { fastembed, nodeSQLite, similaritySearch } from "@deepagents/retrieval";
|
|
184
189
|
import * as connectors from "@deepagents/retrieval/connectors";
|
|
185
190
|
import { ignorePatterns } from "@deepagents/retrieval/connectors";
|
|
186
|
-
|
|
187
|
-
// packages/toolbox/src/lib/state.ts
|
|
188
|
-
function toState(options) {
|
|
189
|
-
return options.context;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// packages/toolbox/src/lib/filesystem.ts
|
|
193
191
|
var read_file_tool = tool4({
|
|
194
192
|
description: `Use this tool to read a file from the filesystem. Supports reading entire files or specific line ranges.`,
|
|
195
193
|
inputSchema: z4.object({
|
|
@@ -201,8 +199,7 @@ var read_file_tool = tool4({
|
|
|
201
199
|
"Ending line number (1-indexed). If omitted, reads to the end. Maximum 200 lines can be read at once."
|
|
202
200
|
)
|
|
203
201
|
}),
|
|
204
|
-
execute: async ({ filePath, lineStart, lineEnd },
|
|
205
|
-
const context = toState(options);
|
|
202
|
+
execute: async ({ filePath, lineStart, lineEnd }, { context }) => {
|
|
206
203
|
const fullPath = join(context.repo_path, filePath);
|
|
207
204
|
const stats = await stat(fullPath);
|
|
208
205
|
const maxSize = 100 * 1024;
|
|
@@ -240,8 +237,7 @@ var read_dir_tool = tool4({
|
|
|
240
237
|
inputSchema: z4.object({
|
|
241
238
|
dir_path: z4.string().min(1).optional().default("./").describe('Relative path to the directory. Defaults to "./"')
|
|
242
239
|
}),
|
|
243
|
-
execute: async ({ dir_path },
|
|
244
|
-
const context = toState(options);
|
|
240
|
+
execute: async ({ dir_path }, { context }) => {
|
|
245
241
|
return readdir(join(context.repo_path, dir_path), "utf-8");
|
|
246
242
|
}
|
|
247
243
|
});
|
|
@@ -253,8 +249,7 @@ var glob_tool = tool4({
|
|
|
253
249
|
inputSchema: z4.object({
|
|
254
250
|
pattern: z4.string().min(1).describe("A glob pattern to match files. ")
|
|
255
251
|
}),
|
|
256
|
-
execute: async ({ pattern },
|
|
257
|
-
const context = toState(options);
|
|
252
|
+
execute: async ({ pattern }, { context }) => {
|
|
258
253
|
const files = await FastGlob(pattern, {
|
|
259
254
|
dot: true,
|
|
260
255
|
cwd: context.repo_path,
|
|
@@ -273,8 +268,7 @@ var search_files_tool = tool4({
|
|
|
273
268
|
max_results: z4.number().int().positive().max(500).optional().default(100),
|
|
274
269
|
depth: z4.number().int().describe("Max directory depth to search. defaults to 31.")
|
|
275
270
|
}),
|
|
276
|
-
execute: async ({ pattern, max_results = 100, depth },
|
|
277
|
-
const context = toState(options);
|
|
271
|
+
execute: async ({ pattern, max_results = 100, depth }, { context }) => {
|
|
278
272
|
const ignore = await ignorePatterns(context.repo_path);
|
|
279
273
|
const files = await FastGlob(pattern, {
|
|
280
274
|
dot: false,
|
|
@@ -290,8 +284,7 @@ var search_files_tool = tool4({
|
|
|
290
284
|
var file_exists_tool = tool4({
|
|
291
285
|
description: "Check if a file exists in the repository.",
|
|
292
286
|
inputSchema: z4.object({ filePath: z4.string().min(1) }),
|
|
293
|
-
execute: async ({ filePath },
|
|
294
|
-
const context = toState(options);
|
|
287
|
+
execute: async ({ filePath }, { context }) => {
|
|
295
288
|
return stat(join(context.repo_path, filePath)).then(() => true).catch(() => false);
|
|
296
289
|
}
|
|
297
290
|
});
|
|
@@ -310,7 +303,7 @@ var search_content_tool = dynamicTool({
|
|
|
310
303
|
}
|
|
311
304
|
}
|
|
312
305
|
}),
|
|
313
|
-
async execute(input,
|
|
306
|
+
async execute(input, { context }) {
|
|
314
307
|
const keys = Object.keys(input).filter((k) => k !== "query");
|
|
315
308
|
if (keys.length > 0) {
|
|
316
309
|
return `Invalid input: only "query" is supported. Found extra keys: ${keys.join(", ")}`;
|
|
@@ -318,11 +311,14 @@ var search_content_tool = dynamicTool({
|
|
|
318
311
|
if (typeof input.query !== "string" || input.query.trim().length === 0) {
|
|
319
312
|
return 'Invalid input: "query" must be a non-empty string.';
|
|
320
313
|
}
|
|
314
|
+
const repoPath = context.repo_path;
|
|
315
|
+
if (typeof repoPath !== "string") {
|
|
316
|
+
return 'Invalid context: "repo_path" must be a string.';
|
|
317
|
+
}
|
|
321
318
|
try {
|
|
322
|
-
const context = toState(options);
|
|
323
319
|
const results = await similaritySearch(input.query, {
|
|
324
320
|
connector: connectors.repo(
|
|
325
|
-
|
|
321
|
+
repoPath,
|
|
326
322
|
[".ts", ".tsx", ".md", ".prisma"],
|
|
327
323
|
"never"
|
|
328
324
|
),
|
|
@@ -330,7 +326,7 @@ var search_content_tool = dynamicTool({
|
|
|
330
326
|
embedder: fastembed()
|
|
331
327
|
});
|
|
332
328
|
const contents = results.map((it) => {
|
|
333
|
-
const source = relative(
|
|
329
|
+
const source = relative(repoPath, it.document_id);
|
|
334
330
|
const filename = basename(source);
|
|
335
331
|
return {
|
|
336
332
|
source,
|
|
@@ -363,6 +359,42 @@ async function repoTree(dir_path) {
|
|
|
363
359
|
// packages/toolbox/src/lib/hackernews-search.ts
|
|
364
360
|
import { tool as tool5 } from "ai";
|
|
365
361
|
import { z as z5 } from "zod";
|
|
362
|
+
var hnSearchItem = z5.object({
|
|
363
|
+
objectID: z5.string(),
|
|
364
|
+
title: z5.string().nullish(),
|
|
365
|
+
url: z5.string().nullish(),
|
|
366
|
+
author: z5.string(),
|
|
367
|
+
points: z5.number().nullish(),
|
|
368
|
+
story_text: z5.string().nullish(),
|
|
369
|
+
comment_text: z5.string().nullish(),
|
|
370
|
+
num_comments: z5.number().nullish(),
|
|
371
|
+
created_at_i: z5.number(),
|
|
372
|
+
_tags: z5.array(z5.string())
|
|
373
|
+
});
|
|
374
|
+
var hnSearchResponse = z5.object({
|
|
375
|
+
query: z5.string(),
|
|
376
|
+
hits: z5.array(hnSearchItem),
|
|
377
|
+
nbHits: z5.number(),
|
|
378
|
+
page: z5.number(),
|
|
379
|
+
nbPages: z5.number(),
|
|
380
|
+
hitsPerPage: z5.number()
|
|
381
|
+
});
|
|
382
|
+
var hnItemResponse = z5.object({
|
|
383
|
+
id: z5.number(),
|
|
384
|
+
created_at_i: z5.number(),
|
|
385
|
+
type: z5.enum(["story", "comment", "poll", "pollopt", "show", "ask", "job"]),
|
|
386
|
+
author: z5.string(),
|
|
387
|
+
title: z5.string().nullish(),
|
|
388
|
+
url: z5.string().nullish(),
|
|
389
|
+
text: z5.string().nullish(),
|
|
390
|
+
points: z5.number().nullish(),
|
|
391
|
+
story_title: z5.string().nullish()
|
|
392
|
+
});
|
|
393
|
+
var hnUserResponse = z5.object({
|
|
394
|
+
username: z5.string(),
|
|
395
|
+
about: z5.string().nullish(),
|
|
396
|
+
karma: z5.number()
|
|
397
|
+
});
|
|
366
398
|
function buildTags(options) {
|
|
367
399
|
const tags = [];
|
|
368
400
|
if (options.type && options.type !== "all") {
|
|
@@ -439,8 +471,7 @@ async function searchHackerNewsAPI(params) {
|
|
|
439
471
|
`HN API error: ${response.status} ${response.statusText}`
|
|
440
472
|
);
|
|
441
473
|
}
|
|
442
|
-
|
|
443
|
-
return data;
|
|
474
|
+
return hnSearchResponse.parse(await response.json());
|
|
444
475
|
} catch (error) {
|
|
445
476
|
throw new Error(
|
|
446
477
|
`Failed to search HackerNews: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
@@ -460,8 +491,7 @@ async function fetchHNItem(id) {
|
|
|
460
491
|
`HN API error: ${response.status} ${response.statusText}`
|
|
461
492
|
);
|
|
462
493
|
}
|
|
463
|
-
|
|
464
|
-
return data;
|
|
494
|
+
return hnItemResponse.parse(await response.json());
|
|
465
495
|
} catch (error) {
|
|
466
496
|
throw new Error(
|
|
467
497
|
`Failed to fetch HN item: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
@@ -481,8 +511,7 @@ async function fetchHNUser(username) {
|
|
|
481
511
|
`HN API error: ${response.status} ${response.statusText}`
|
|
482
512
|
);
|
|
483
513
|
}
|
|
484
|
-
|
|
485
|
-
return data;
|
|
514
|
+
return hnUserResponse.parse(await response.json());
|
|
486
515
|
} catch (error) {
|
|
487
516
|
throw new Error(
|
|
488
517
|
`Failed to fetch HN user: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
@@ -507,7 +536,7 @@ ${itemNumber}. ${hit.title || "(No title)"}`);
|
|
|
507
536
|
if (hit.url) {
|
|
508
537
|
lines.push(` URL: ${hit.url}`);
|
|
509
538
|
}
|
|
510
|
-
if (hit.points
|
|
539
|
+
if (typeof hit.points === "number") {
|
|
511
540
|
lines.push(
|
|
512
541
|
` ${hit.points} points | by ${hit.author} | ${hit.num_comments || 0} comments`
|
|
513
542
|
);
|
|
@@ -545,7 +574,7 @@ ${itemNumber}. [${type}] ${hit.title || "Comment"}`);
|
|
|
545
574
|
if (hit.url) {
|
|
546
575
|
lines.push(` URL: ${hit.url}`);
|
|
547
576
|
}
|
|
548
|
-
if (hit.points
|
|
577
|
+
if (typeof hit.points === "number") {
|
|
549
578
|
lines.push(` ${hit.points} points | ${hit.num_comments || 0} comments`);
|
|
550
579
|
}
|
|
551
580
|
if (hit.story_text) {
|
|
@@ -606,7 +635,7 @@ function formatItemDetails(item) {
|
|
|
606
635
|
lines.push(`URL: ${item.url}`);
|
|
607
636
|
}
|
|
608
637
|
lines.push(`By: ${item.author}`);
|
|
609
|
-
if (item.points
|
|
638
|
+
if (typeof item.points === "number") {
|
|
610
639
|
lines.push(`Points: ${item.points}`);
|
|
611
640
|
}
|
|
612
641
|
lines.push(`Date: ${formatDate(item.created_at_i)}`);
|
|
@@ -636,7 +665,6 @@ function formatUserProfile(user) {
|
|
|
636
665
|
const lines = [];
|
|
637
666
|
lines.push(`User: ${user.username}`);
|
|
638
667
|
lines.push(`Karma: ${user.karma.toLocaleString()}`);
|
|
639
|
-
lines.push(`Member since: ${formatDate(user.created_at_i)}`);
|
|
640
668
|
if (user.about) {
|
|
641
669
|
lines.push(`
|
|
642
670
|
About:
|
|
@@ -689,9 +717,8 @@ var search_by_query = tool5({
|
|
|
689
717
|
page: z5.number().int().min(0).default(0).describe("Page number (0-indexed)"),
|
|
690
718
|
hitsPerPage: z5.number().int().min(1).max(1e3).default(20).describe("Results per page (max 1000)")
|
|
691
719
|
}),
|
|
692
|
-
execute: async (input,
|
|
693
|
-
const
|
|
694
|
-
context.hackernews_sources ??= [];
|
|
720
|
+
execute: async (input, { context }) => {
|
|
721
|
+
const sources = context.hackernews_sources ??= [];
|
|
695
722
|
const numericFilters = buildNumericFilters({
|
|
696
723
|
timeFilter: input.timeFilter,
|
|
697
724
|
minPoints: input.minPoints,
|
|
@@ -705,7 +732,7 @@ var search_by_query = tool5({
|
|
|
705
732
|
page: input.page,
|
|
706
733
|
hitsPerPage: input.hitsPerPage
|
|
707
734
|
});
|
|
708
|
-
fillContext(
|
|
735
|
+
fillContext(sources, response);
|
|
709
736
|
return formatStoryResults(response);
|
|
710
737
|
}
|
|
711
738
|
});
|
|
@@ -720,9 +747,8 @@ var search_by_author = tool5({
|
|
|
720
747
|
page: z5.number().int().min(0).default(0).describe("Page number (0-indexed)"),
|
|
721
748
|
hitsPerPage: z5.number().int().min(1).max(1e3).default(20).describe("Results per page (max 1000)")
|
|
722
749
|
}),
|
|
723
|
-
execute: async (input,
|
|
724
|
-
const
|
|
725
|
-
context.hackernews_sources ??= [];
|
|
750
|
+
execute: async (input, { context }) => {
|
|
751
|
+
const sources = context.hackernews_sources ??= [];
|
|
726
752
|
const tags = buildTags({ type: input.type, author: input.author });
|
|
727
753
|
const numericFilters = buildNumericFilters({
|
|
728
754
|
timeFilter: input.timeFilter,
|
|
@@ -735,7 +761,7 @@ var search_by_author = tool5({
|
|
|
735
761
|
page: input.page,
|
|
736
762
|
hitsPerPage: input.hitsPerPage
|
|
737
763
|
});
|
|
738
|
-
fillContext(
|
|
764
|
+
fillContext(sources, response);
|
|
739
765
|
return formatAuthorResults(response);
|
|
740
766
|
}
|
|
741
767
|
});
|
|
@@ -744,16 +770,15 @@ var get_story_item = tool5({
|
|
|
744
770
|
inputSchema: z5.object({
|
|
745
771
|
storyId: z5.string().describe('HackerNews story ID. Example: "38709478"')
|
|
746
772
|
}),
|
|
747
|
-
execute: async (input,
|
|
748
|
-
const
|
|
749
|
-
context.hackernews_sources ??= [];
|
|
773
|
+
execute: async (input, { context }) => {
|
|
774
|
+
const sources = context.hackernews_sources ??= [];
|
|
750
775
|
const item = await fetchHNItem(input.storyId);
|
|
751
776
|
if (item.type !== "story") {
|
|
752
777
|
throw new Error(
|
|
753
778
|
`Item ${input.storyId} is not a story (type: ${item.type})`
|
|
754
779
|
);
|
|
755
780
|
}
|
|
756
|
-
|
|
781
|
+
sources.push({
|
|
757
782
|
title: item.title || "Untitled",
|
|
758
783
|
hn_url: `https://news.ycombinator.com/item?id=${item.id}`,
|
|
759
784
|
story_url: item.url || ""
|
|
@@ -782,16 +807,15 @@ var get_front_page_stories = tool5({
|
|
|
782
807
|
page: z5.number().int().min(0).default(0).describe("Page number (0-indexed)"),
|
|
783
808
|
hitsPerPage: z5.number().int().min(1).max(50).default(30).describe("Results per page (max 50)")
|
|
784
809
|
}),
|
|
785
|
-
execute: async (input,
|
|
786
|
-
const
|
|
787
|
-
context.hackernews_sources ??= [];
|
|
810
|
+
execute: async (input, { context }) => {
|
|
811
|
+
const sources = context.hackernews_sources ??= [];
|
|
788
812
|
const response = await searchHackerNewsAPI({
|
|
789
813
|
tags: "front_page",
|
|
790
814
|
sortBy: "date",
|
|
791
815
|
page: input.page,
|
|
792
816
|
hitsPerPage: input.hitsPerPage
|
|
793
817
|
});
|
|
794
|
-
fillContext(
|
|
818
|
+
fillContext(sources, response);
|
|
795
819
|
return formatStoryResults(response);
|
|
796
820
|
}
|
|
797
821
|
});
|
|
@@ -826,9 +850,8 @@ var search_ask_hn = tool5({
|
|
|
826
850
|
page: z5.number().int().min(0).default(0).describe("Page number (0-indexed)"),
|
|
827
851
|
hitsPerPage: z5.number().int().min(1).max(1e3).default(20).describe("Results per page (max 1000)")
|
|
828
852
|
}),
|
|
829
|
-
execute: async (input,
|
|
830
|
-
const
|
|
831
|
-
context.hackernews_sources ??= [];
|
|
853
|
+
execute: async (input, { context }) => {
|
|
854
|
+
const sources = context.hackernews_sources ??= [];
|
|
832
855
|
const numericFilters = buildNumericFilters({
|
|
833
856
|
timeFilter: input.timeFilter,
|
|
834
857
|
minPoints: input.minPoints,
|
|
@@ -842,7 +865,7 @@ var search_ask_hn = tool5({
|
|
|
842
865
|
page: input.page,
|
|
843
866
|
hitsPerPage: input.hitsPerPage
|
|
844
867
|
});
|
|
845
|
-
fillContext(
|
|
868
|
+
fillContext(sources, response);
|
|
846
869
|
return formatStoryResults(response);
|
|
847
870
|
}
|
|
848
871
|
});
|
|
@@ -859,9 +882,8 @@ var search_show_hn = tool5({
|
|
|
859
882
|
page: z5.number().int().min(0).default(0).describe("Page number (0-indexed)"),
|
|
860
883
|
hitsPerPage: z5.number().int().min(1).max(1e3).default(20).describe("Results per page (max 1000)")
|
|
861
884
|
}),
|
|
862
|
-
execute: async (input,
|
|
863
|
-
const
|
|
864
|
-
context.hackernews_sources ??= [];
|
|
885
|
+
execute: async (input, { context }) => {
|
|
886
|
+
const sources = context.hackernews_sources ??= [];
|
|
865
887
|
const numericFilters = buildNumericFilters({
|
|
866
888
|
timeFilter: input.timeFilter,
|
|
867
889
|
minPoints: input.minPoints,
|
|
@@ -875,7 +897,7 @@ var search_show_hn = tool5({
|
|
|
875
897
|
page: input.page,
|
|
876
898
|
hitsPerPage: input.hitsPerPage
|
|
877
899
|
});
|
|
878
|
-
fillContext(
|
|
900
|
+
fillContext(sources, response);
|
|
879
901
|
return formatStoryResults(response);
|
|
880
902
|
}
|
|
881
903
|
});
|
|
@@ -890,9 +912,8 @@ var search_jobs = tool5({
|
|
|
890
912
|
page: z5.number().int().min(0).default(0).describe("Page number (0-indexed)"),
|
|
891
913
|
hitsPerPage: z5.number().int().min(1).max(1e3).default(20).describe("Results per page (max 1000)")
|
|
892
914
|
}),
|
|
893
|
-
execute: async (input,
|
|
894
|
-
const
|
|
895
|
-
context.hackernews_sources ??= [];
|
|
915
|
+
execute: async (input, { context }) => {
|
|
916
|
+
const sources = context.hackernews_sources ??= [];
|
|
896
917
|
const numericFilters = buildNumericFilters({
|
|
897
918
|
timeFilter: input.timeFilter
|
|
898
919
|
});
|
|
@@ -904,7 +925,7 @@ var search_jobs = tool5({
|
|
|
904
925
|
page: input.page,
|
|
905
926
|
hitsPerPage: input.hitsPerPage
|
|
906
927
|
});
|
|
907
|
-
fillContext(
|
|
928
|
+
fillContext(sources, response);
|
|
908
929
|
return formatJobResults(response);
|
|
909
930
|
}
|
|
910
931
|
});
|
|
@@ -917,9 +938,8 @@ var search_polls = tool5({
|
|
|
917
938
|
page: z5.number().int().min(0).default(0).describe("Page number (0-indexed)"),
|
|
918
939
|
hitsPerPage: z5.number().int().min(1).max(1e3).default(20).describe("Results per page (max 1000)")
|
|
919
940
|
}),
|
|
920
|
-
execute: async (input,
|
|
921
|
-
const
|
|
922
|
-
context.hackernews_sources ??= [];
|
|
941
|
+
execute: async (input, { context }) => {
|
|
942
|
+
const sources = context.hackernews_sources ??= [];
|
|
923
943
|
const numericFilters = buildNumericFilters({
|
|
924
944
|
timeFilter: input.timeFilter
|
|
925
945
|
});
|
|
@@ -931,7 +951,7 @@ var search_polls = tool5({
|
|
|
931
951
|
page: input.page,
|
|
932
952
|
hitsPerPage: input.hitsPerPage
|
|
933
953
|
});
|
|
934
|
-
fillContext(
|
|
954
|
+
fillContext(sources, response);
|
|
935
955
|
return formatStoryResults(response);
|
|
936
956
|
}
|
|
937
957
|
});
|
|
@@ -956,9 +976,8 @@ var search_by_domain = tool5({
|
|
|
956
976
|
page: z5.number().int().min(0).default(0).describe("Page number (0-indexed)"),
|
|
957
977
|
hitsPerPage: z5.number().int().min(1).max(1e3).default(20).describe("Results per page (max 1000)")
|
|
958
978
|
}),
|
|
959
|
-
execute: async (input,
|
|
960
|
-
const
|
|
961
|
-
context.hackernews_sources ??= [];
|
|
979
|
+
execute: async (input, { context }) => {
|
|
980
|
+
const sources = context.hackernews_sources ??= [];
|
|
962
981
|
const numericFilters = buildNumericFilters({
|
|
963
982
|
timeFilter: input.timeFilter,
|
|
964
983
|
minPoints: input.minPoints,
|
|
@@ -983,8 +1002,8 @@ var search_by_domain = tool5({
|
|
|
983
1002
|
`HN API error: ${response.status} ${response.statusText}`
|
|
984
1003
|
);
|
|
985
1004
|
}
|
|
986
|
-
const data = await response.json();
|
|
987
|
-
fillContext(
|
|
1005
|
+
const data = hnSearchResponse.parse(await response.json());
|
|
1006
|
+
fillContext(sources, data);
|
|
988
1007
|
return formatStoryResults(data);
|
|
989
1008
|
}
|
|
990
1009
|
});
|
|
@@ -1001,9 +1020,8 @@ var search_highly_discussed = tool5({
|
|
|
1001
1020
|
page: z5.number().int().min(0).default(0).describe("Page number (0-indexed)"),
|
|
1002
1021
|
hitsPerPage: z5.number().int().min(1).max(1e3).default(20).describe("Results per page (max 1000)")
|
|
1003
1022
|
}),
|
|
1004
|
-
execute: async (input,
|
|
1005
|
-
const
|
|
1006
|
-
context.hackernews_sources ??= [];
|
|
1023
|
+
execute: async (input, { context }) => {
|
|
1024
|
+
const sources = context.hackernews_sources ??= [];
|
|
1007
1025
|
const numericFilters = buildNumericFilters({
|
|
1008
1026
|
timeFilter: input.timeFilter,
|
|
1009
1027
|
minPoints: input.minPoints,
|
|
@@ -1017,7 +1035,7 @@ var search_highly_discussed = tool5({
|
|
|
1017
1035
|
page: input.page,
|
|
1018
1036
|
hitsPerPage: input.hitsPerPage
|
|
1019
1037
|
});
|
|
1020
|
-
fillContext(
|
|
1038
|
+
fillContext(sources, response);
|
|
1021
1039
|
return formatStoryResults(response);
|
|
1022
1040
|
}
|
|
1023
1041
|
});
|
|
@@ -1033,9 +1051,8 @@ var search_trending = tool5({
|
|
|
1033
1051
|
page: z5.number().int().min(0).default(0).describe("Page number (0-indexed)"),
|
|
1034
1052
|
hitsPerPage: z5.number().int().min(1).max(100).default(30).describe("Results per page (max 100)")
|
|
1035
1053
|
}),
|
|
1036
|
-
execute: async (input,
|
|
1037
|
-
const
|
|
1038
|
-
context.hackernews_sources ??= [];
|
|
1054
|
+
execute: async (input, { context }) => {
|
|
1055
|
+
const sources = context.hackernews_sources ??= [];
|
|
1039
1056
|
const numericFilters = buildNumericFilters({
|
|
1040
1057
|
maxAgeHours: input.maxAgeHours,
|
|
1041
1058
|
minPoints: input.minPoints,
|
|
@@ -1048,13 +1065,13 @@ var search_trending = tool5({
|
|
|
1048
1065
|
page: input.page,
|
|
1049
1066
|
hitsPerPage: input.hitsPerPage
|
|
1050
1067
|
});
|
|
1051
|
-
fillContext(
|
|
1068
|
+
fillContext(sources, response);
|
|
1052
1069
|
return formatStoryResults(response);
|
|
1053
1070
|
}
|
|
1054
1071
|
});
|
|
1055
|
-
function fillContext(
|
|
1072
|
+
function fillContext(sources, result) {
|
|
1056
1073
|
result.hits.forEach((hit) => {
|
|
1057
|
-
|
|
1074
|
+
sources.push({
|
|
1058
1075
|
title: hit.title,
|
|
1059
1076
|
hn_url: hit.objectID ? `https://news.ycombinator.com/item?id=${hit.objectID}` : void 0,
|
|
1060
1077
|
story_url: hit.url,
|
|
@@ -1104,8 +1121,7 @@ var scratchpad_tool = tool6({
|
|
|
1104
1121
|
inputSchema: z6.object({
|
|
1105
1122
|
reflection: z6.string().describe("Your detailed reflection on research progress.")
|
|
1106
1123
|
}),
|
|
1107
|
-
execute: async ({ reflection },
|
|
1108
|
-
const context = toState(options);
|
|
1124
|
+
execute: async ({ reflection }, { context }) => {
|
|
1109
1125
|
context.scratchpad += `- ${reflection}
|
|
1110
1126
|
`;
|
|
1111
1127
|
return `Reflection recorded. Current scratchpad now:
|
|
@@ -1151,8 +1167,7 @@ var user_story_formatter_tool = tool7({
|
|
|
1151
1167
|
3. Return a formatted version for immediate review
|
|
1152
1168
|
`,
|
|
1153
1169
|
inputSchema: UserStorySchema,
|
|
1154
|
-
execute: async (story,
|
|
1155
|
-
const context = toState(options);
|
|
1170
|
+
execute: async (story, { context }) => {
|
|
1156
1171
|
context.userStories ??= [];
|
|
1157
1172
|
context.userStories.push(story);
|
|
1158
1173
|
const formatted = `
|
|
@@ -1222,10 +1237,9 @@ var getWeatherTool = tool8({
|
|
|
1222
1237
|
const url = `https://api.open-meteo.com/v1/forecast?${params.toString()}`;
|
|
1223
1238
|
const res = await fetch(url);
|
|
1224
1239
|
if (!res.ok) throw new Error(`Weather API failed: ${res.status}`);
|
|
1225
|
-
const
|
|
1226
|
-
|
|
1227
|
-
const daily = data
|
|
1228
|
-
if (!current || !daily) throw new Error("Malformed weather API response");
|
|
1240
|
+
const forecast = forecastResponse.safeParse(await res.json());
|
|
1241
|
+
if (!forecast.success) throw new Error("Malformed weather API response");
|
|
1242
|
+
const { current, daily } = forecast.data;
|
|
1229
1243
|
const weatherCode = Number(current.weather_code);
|
|
1230
1244
|
const mapped = mapWeatherCode(weatherCode);
|
|
1231
1245
|
const result = {
|
|
@@ -1245,6 +1259,29 @@ var getWeatherTool = tool8({
|
|
|
1245
1259
|
return result;
|
|
1246
1260
|
}
|
|
1247
1261
|
});
|
|
1262
|
+
var geocodeResponse = z8.object({
|
|
1263
|
+
results: z8.array(
|
|
1264
|
+
z8.object({
|
|
1265
|
+
name: z8.string(),
|
|
1266
|
+
latitude: z8.number(),
|
|
1267
|
+
longitude: z8.number(),
|
|
1268
|
+
country_code: z8.string().optional(),
|
|
1269
|
+
admin1: z8.string().optional()
|
|
1270
|
+
})
|
|
1271
|
+
).optional()
|
|
1272
|
+
});
|
|
1273
|
+
var forecastResponse = z8.object({
|
|
1274
|
+
current: z8.object({
|
|
1275
|
+
temperature_2m: z8.number(),
|
|
1276
|
+
relative_humidity_2m: z8.number(),
|
|
1277
|
+
wind_speed_10m: z8.number(),
|
|
1278
|
+
weather_code: z8.number()
|
|
1279
|
+
}),
|
|
1280
|
+
daily: z8.object({
|
|
1281
|
+
temperature_2m_max: z8.array(z8.number()),
|
|
1282
|
+
temperature_2m_min: z8.array(z8.number())
|
|
1283
|
+
})
|
|
1284
|
+
});
|
|
1248
1285
|
async function geocodeLocation(location) {
|
|
1249
1286
|
const coordMatch = location.trim().match(/^\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*$/);
|
|
1250
1287
|
if (coordMatch) {
|
|
@@ -1261,8 +1298,8 @@ async function geocodeLocation(location) {
|
|
|
1261
1298
|
)}&count=1&language=en&format=json`;
|
|
1262
1299
|
const res = await fetch(url);
|
|
1263
1300
|
if (!res.ok) throw new Error(`Geocoding failed: ${res.status}`);
|
|
1264
|
-
const
|
|
1265
|
-
const first =
|
|
1301
|
+
const { results } = geocodeResponse.parse(await res.json());
|
|
1302
|
+
const first = results?.[0];
|
|
1266
1303
|
if (!first) throw new Error(`Location not found: ${location}`);
|
|
1267
1304
|
const nameParts = [first.name, first.admin1, first.country_code].filter(
|
|
1268
1305
|
Boolean
|