@tinyweb_dev/agent-framework-tool 0.3.0 → 0.4.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/builtins.cjs +108 -0
- package/dist/builtins.cjs.map +1 -1
- package/dist/builtins.d.ts +6 -0
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +108 -0
- package/dist/builtins.js.map +1 -1
- package/dist/index.cjs +134 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +132 -24
- package/dist/index.js.map +1 -1
- package/dist/todo/update_todo_list.d.ts +44 -0
- package/dist/todo/update_todo_list.d.ts.map +1 -0
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ var promises = require('fs/promises');
|
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var cheerio = require('cheerio');
|
|
7
7
|
var agent = require('@tinyweb_dev/agent-framework-agent');
|
|
8
|
+
var crypto = require('crypto');
|
|
8
9
|
|
|
9
10
|
// src/shared/storage.ts
|
|
10
11
|
var FileError = class extends Error {
|
|
@@ -579,11 +580,116 @@ var displayResponse = (config = {}) => agent.defineTool({
|
|
|
579
580
|
success: Success8,
|
|
580
581
|
execute: async (input) => ({ response: input.response })
|
|
581
582
|
});
|
|
583
|
+
var TodoStatusSchema = effect.Schema.Union([
|
|
584
|
+
effect.Schema.Literal("pending"),
|
|
585
|
+
effect.Schema.Literal("in_progress"),
|
|
586
|
+
effect.Schema.Literal("completed")
|
|
587
|
+
]);
|
|
588
|
+
var TodoItemSchema = effect.Schema.Struct({
|
|
589
|
+
id: effect.Schema.String,
|
|
590
|
+
content: effect.Schema.String,
|
|
591
|
+
status: TodoStatusSchema
|
|
592
|
+
});
|
|
582
593
|
var Parameters9 = effect.Schema.Struct({
|
|
594
|
+
todos: effect.Schema.String
|
|
595
|
+
});
|
|
596
|
+
var Success9 = effect.Schema.Struct({
|
|
597
|
+
ok: effect.Schema.Boolean,
|
|
598
|
+
message: effect.Schema.String,
|
|
599
|
+
todos: effect.Schema.Array(TodoItemSchema),
|
|
600
|
+
completed_count: effect.Schema.Number,
|
|
601
|
+
total_count: effect.Schema.Number,
|
|
602
|
+
markdown: effect.Schema.String
|
|
603
|
+
});
|
|
604
|
+
var DEFAULT_DESCRIPTION2 = [
|
|
605
|
+
"Replace the entire TODO list with an updated checklist reflecting the current state. Always provide the full list; the system will overwrite the previous one. This tool is designed for step-by-step task tracking, allowing you to confirm completion of each step before updating, update multiple task statuses at once (e.g., mark one as completed and start the next), and dynamically add new todos discovered during long or complex tasks.",
|
|
606
|
+
"",
|
|
607
|
+
"Checklist Format:",
|
|
608
|
+
"- Use a single-level markdown checklist (no nesting or subtasks)",
|
|
609
|
+
"- List todos in the intended execution order",
|
|
610
|
+
"- Status options: [ ] (pending), [x] (completed), [-] (in progress)",
|
|
611
|
+
"",
|
|
612
|
+
"Core Principles:",
|
|
613
|
+
"- Before updating, always confirm which todos have been completed",
|
|
614
|
+
"- You may update multiple statuses in a single update",
|
|
615
|
+
"- Add new actionable items as they're discovered",
|
|
616
|
+
"- Only mark a task as completed when fully accomplished",
|
|
617
|
+
"- Keep all unfinished tasks unless explicitly instructed to remove",
|
|
618
|
+
"",
|
|
619
|
+
"Example: Initial task list",
|
|
620
|
+
'{ "todos": "[x] Analyze requirements\\n[x] Design architecture\\n[-] Implement core logic\\n[ ] Write tests\\n[ ] Update documentation" }',
|
|
621
|
+
"",
|
|
622
|
+
"Example: After completing implementation",
|
|
623
|
+
'{ "todos": "[x] Analyze requirements\\n[x] Design architecture\\n[x] Implement core logic\\n[-] Write tests\\n[ ] Update documentation\\n[ ] Add performance benchmarks" }',
|
|
624
|
+
"",
|
|
625
|
+
"When to Use:",
|
|
626
|
+
"- Task involves multiple steps or requires ongoing tracking",
|
|
627
|
+
"- Need to update status of several todos at once",
|
|
628
|
+
"- New actionable items are discovered during execution",
|
|
629
|
+
"- Task is complex and benefits from stepwise progress tracking",
|
|
630
|
+
"",
|
|
631
|
+
"When NOT to Use:",
|
|
632
|
+
"- Only a single, trivial task",
|
|
633
|
+
"- Task can be completed in one or two simple steps",
|
|
634
|
+
"- Request is purely conversational or informational"
|
|
635
|
+
].join("\n");
|
|
636
|
+
var parseMarkdownChecklist = (md) => {
|
|
637
|
+
if (typeof md !== "string") return [];
|
|
638
|
+
const normalized = md.includes("\n") || md.includes("\r") ? md : md.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n").replace(/\\r/g, "\n");
|
|
639
|
+
const lines = normalized.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
640
|
+
const todos = [];
|
|
641
|
+
for (const line of lines) {
|
|
642
|
+
const match = line.match(/^(?:-\s*)?\[\s*([ xX\-~])\s*\]\s+(.+)$/);
|
|
643
|
+
if (!match) continue;
|
|
644
|
+
const mark = match[1];
|
|
645
|
+
const content = match[2];
|
|
646
|
+
let status = "pending";
|
|
647
|
+
if (mark === "x" || mark === "X") status = "completed";
|
|
648
|
+
else if (mark === "-" || mark === "~") status = "in_progress";
|
|
649
|
+
const id = crypto.createHash("md5").update(content + status).digest("hex");
|
|
650
|
+
todos.push({ id, content, status });
|
|
651
|
+
}
|
|
652
|
+
return todos;
|
|
653
|
+
};
|
|
654
|
+
var todoListToMarkdown = (todos) => todos.map((t) => {
|
|
655
|
+
let box = "[ ]";
|
|
656
|
+
if (t.status === "completed") box = "[x]";
|
|
657
|
+
else if (t.status === "in_progress") box = "[-]";
|
|
658
|
+
return `${box} ${t.content}`;
|
|
659
|
+
}).join("\n");
|
|
660
|
+
var updateTodoList = (config = {}) => agent.defineTool({
|
|
661
|
+
name: config.name ?? "update_todo_list",
|
|
662
|
+
description: config.description ?? DEFAULT_DESCRIPTION2,
|
|
663
|
+
parameters: Parameters9,
|
|
664
|
+
success: Success9,
|
|
665
|
+
execute: async (input) => {
|
|
666
|
+
const todos = parseMarkdownChecklist(input.todos);
|
|
667
|
+
if (todos.length === 0) {
|
|
668
|
+
return {
|
|
669
|
+
ok: false,
|
|
670
|
+
message: "No valid checklist items found. Use markdown lines like `[ ] task`, `[-] task`, or `[x] task`.",
|
|
671
|
+
todos: [],
|
|
672
|
+
completed_count: 0,
|
|
673
|
+
total_count: 0,
|
|
674
|
+
markdown: ""
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
const completed_count = todos.filter((t) => t.status === "completed").length;
|
|
678
|
+
return {
|
|
679
|
+
ok: true,
|
|
680
|
+
message: "Todo list updated successfully.",
|
|
681
|
+
todos,
|
|
682
|
+
completed_count,
|
|
683
|
+
total_count: todos.length,
|
|
684
|
+
markdown: todoListToMarkdown(todos)
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
var Parameters10 = effect.Schema.Struct({
|
|
583
689
|
timezone: effect.Schema.optional(effect.Schema.String),
|
|
584
690
|
locale: effect.Schema.optional(effect.Schema.String)
|
|
585
691
|
});
|
|
586
|
-
var
|
|
692
|
+
var Success10 = effect.Schema.Struct({
|
|
587
693
|
timezone: effect.Schema.String,
|
|
588
694
|
locale: effect.Schema.String,
|
|
589
695
|
iso: effect.Schema.String,
|
|
@@ -605,8 +711,8 @@ var timeNow = (config = {}) => {
|
|
|
605
711
|
return agent.defineTool({
|
|
606
712
|
name: config.name ?? "time_now",
|
|
607
713
|
description: config.description ?? `L\u1EA5y th\u1EDDi gian hi\u1EC7n t\u1EA1i theo timezone IANA (m\u1EB7c \u0111\u1ECBnh ${defaultTz}). Tr\u1EA3 v\u1EC1 ISO, \u0111\u1ECBnh d\u1EA1ng th\xE2n thi\u1EC7n, v\xE0 unix timestamp.`,
|
|
608
|
-
parameters:
|
|
609
|
-
success:
|
|
714
|
+
parameters: Parameters10,
|
|
715
|
+
success: Success10,
|
|
610
716
|
execute: async (input) => {
|
|
611
717
|
const tz = input.timezone ?? defaultTz;
|
|
612
718
|
const locale = input.locale ?? defaultLocale;
|
|
@@ -629,11 +735,11 @@ var timeNow = (config = {}) => {
|
|
|
629
735
|
}
|
|
630
736
|
});
|
|
631
737
|
};
|
|
632
|
-
var
|
|
738
|
+
var Parameters11 = effect.Schema.Struct({
|
|
633
739
|
location: effect.Schema.optional(effect.Schema.String),
|
|
634
740
|
lang: effect.Schema.optional(effect.Schema.String)
|
|
635
741
|
});
|
|
636
|
-
var
|
|
742
|
+
var Success11 = effect.Schema.Struct({
|
|
637
743
|
location: effect.Schema.String,
|
|
638
744
|
region: effect.Schema.optional(effect.Schema.String),
|
|
639
745
|
country: effect.Schema.optional(effect.Schema.String),
|
|
@@ -663,8 +769,8 @@ var weather = (config = {}) => {
|
|
|
663
769
|
return agent.defineTool({
|
|
664
770
|
name: config.name ?? "weather",
|
|
665
771
|
description: config.description ?? `L\u1EA5y th\u1EDDi ti\u1EBFt hi\u1EC7n t\u1EA1i c\u1EE7a m\u1ED9t \u0111\u1ECBa \u0111i\u1EC3m (city, t\u1EC9nh, ho\u1EB7c t\xEAn s\xE2n bay). M\u1EB7c \u0111\u1ECBnh ${defaultLocation}. Ngu\u1ED3n: wttr.in.`,
|
|
666
|
-
parameters:
|
|
667
|
-
success:
|
|
772
|
+
parameters: Parameters11,
|
|
773
|
+
success: Success11,
|
|
668
774
|
execute: async (input) => {
|
|
669
775
|
const loc = (input.location ?? defaultLocation).trim();
|
|
670
776
|
const lang = input.lang ?? defaultLang;
|
|
@@ -701,7 +807,7 @@ var weather = (config = {}) => {
|
|
|
701
807
|
}
|
|
702
808
|
});
|
|
703
809
|
};
|
|
704
|
-
var
|
|
810
|
+
var Parameters12 = effect.Schema.Struct({
|
|
705
811
|
symbols: effect.Schema.Array(effect.Schema.String),
|
|
706
812
|
quote: effect.Schema.optional(effect.Schema.String)
|
|
707
813
|
});
|
|
@@ -711,7 +817,7 @@ var PriceItem = effect.Schema.Struct({
|
|
|
711
817
|
price: effect.Schema.Number,
|
|
712
818
|
pair: effect.Schema.String
|
|
713
819
|
});
|
|
714
|
-
var
|
|
820
|
+
var Success12 = effect.Schema.Struct({
|
|
715
821
|
prices: effect.Schema.Array(PriceItem),
|
|
716
822
|
observed_at: effect.Schema.String,
|
|
717
823
|
source: effect.Schema.Literal("binance")
|
|
@@ -723,8 +829,8 @@ var cryptoPrice = (config = {}) => {
|
|
|
723
829
|
return agent.defineTool({
|
|
724
830
|
name: config.name ?? "crypto_price",
|
|
725
831
|
description: config.description ?? `L\u1EA5y gi\xE1 spot hi\u1EC7n t\u1EA1i c\u1EE7a m\u1ED9t ho\u1EB7c nhi\u1EC1u m\xE3 crypto (BTC, ETH, SOL, ...) t\xEDnh theo ${defaultQuote}. Ngu\u1ED3n: Binance.`,
|
|
726
|
-
parameters:
|
|
727
|
-
success:
|
|
832
|
+
parameters: Parameters12,
|
|
833
|
+
success: Success12,
|
|
728
834
|
execute: async (input) => {
|
|
729
835
|
const quote = upper(input.quote ?? defaultQuote);
|
|
730
836
|
const pairs = input.symbols.map((s) => `${upper(s)}${quote}`);
|
|
@@ -747,7 +853,7 @@ var cryptoPrice = (config = {}) => {
|
|
|
747
853
|
});
|
|
748
854
|
};
|
|
749
855
|
var VendorChoice = effect.Schema.Union([effect.Schema.Literal("btmc"), effect.Schema.Literal("btmh"), effect.Schema.Literal("all")]);
|
|
750
|
-
var
|
|
856
|
+
var Parameters13 = effect.Schema.Struct({
|
|
751
857
|
vendor: effect.Schema.optional(VendorChoice)
|
|
752
858
|
});
|
|
753
859
|
var PriceItem2 = effect.Schema.Struct({
|
|
@@ -759,7 +865,7 @@ var PriceItem2 = effect.Schema.Struct({
|
|
|
759
865
|
unit: effect.Schema.String,
|
|
760
866
|
source_url: effect.Schema.String
|
|
761
867
|
});
|
|
762
|
-
var
|
|
868
|
+
var Success13 = effect.Schema.Struct({
|
|
763
869
|
items: effect.Schema.Array(PriceItem2),
|
|
764
870
|
observed_at: effect.Schema.String,
|
|
765
871
|
warnings: effect.Schema.Array(effect.Schema.String)
|
|
@@ -859,8 +965,8 @@ var vnGoldPrice = (config = {}) => {
|
|
|
859
965
|
return agent.defineTool({
|
|
860
966
|
name: config.name ?? "vn_gold_price",
|
|
861
967
|
description: config.description ?? "L\u1EA5y gi\xE1 v\xE0ng nh\u1EABn tr\xF2n 24K Vi\u1EC7t Nam (B\u1EA3o T\xEDn Minh Ch\xE2u / B\u1EA3o T\xEDn M\u1EA1nh H\u1EA3i). Gi\xE1 tham kh\u1EA3o, c\xF3 th\u1EC3 l\u1EC7ch so v\u1EDBi th\u1EF1c t\u1EBF.",
|
|
862
|
-
parameters:
|
|
863
|
-
success:
|
|
968
|
+
parameters: Parameters13,
|
|
969
|
+
success: Success13,
|
|
864
970
|
execute: async (input) => {
|
|
865
971
|
const vendor = input.vendor ?? "all";
|
|
866
972
|
const items = [];
|
|
@@ -887,14 +993,14 @@ var RegionChoice = effect.Schema.Union([
|
|
|
887
993
|
effect.Schema.Literal("central"),
|
|
888
994
|
effect.Schema.Literal("south")
|
|
889
995
|
]);
|
|
890
|
-
var
|
|
996
|
+
var Parameters14 = effect.Schema.Struct({
|
|
891
997
|
region: effect.Schema.optional(RegionChoice)
|
|
892
998
|
});
|
|
893
999
|
var Prize = effect.Schema.Struct({
|
|
894
1000
|
name: effect.Schema.String,
|
|
895
1001
|
numbers: effect.Schema.Array(effect.Schema.String)
|
|
896
1002
|
});
|
|
897
|
-
var
|
|
1003
|
+
var Success14 = effect.Schema.Struct({
|
|
898
1004
|
region: effect.Schema.String,
|
|
899
1005
|
region_label: effect.Schema.String,
|
|
900
1006
|
date: effect.Schema.optional(effect.Schema.String),
|
|
@@ -919,8 +1025,8 @@ var vnLottery = (config = {}) => {
|
|
|
919
1025
|
return agent.defineTool({
|
|
920
1026
|
name: config.name ?? "vn_lottery",
|
|
921
1027
|
description: config.description ?? "L\u1EA5y k\u1EBFt qu\u1EA3 x\u1ED5 s\u1ED1 ki\u1EBFn thi\u1EBFt Vi\u1EC7t Nam m\u1EDBi nh\u1EA5t theo mi\u1EC1n (m\u1EB7c \u0111\u1ECBnh Mi\u1EC1n B\u1EAFc / XSMB). Ngu\u1ED3n: xoso.com.vn.",
|
|
922
|
-
parameters:
|
|
923
|
-
success:
|
|
1028
|
+
parameters: Parameters14,
|
|
1029
|
+
success: Success14,
|
|
924
1030
|
execute: async (input) => {
|
|
925
1031
|
const region = input.region ?? "north";
|
|
926
1032
|
const conf = REGION_URLS[region];
|
|
@@ -973,14 +1079,14 @@ var vnLottery = (config = {}) => {
|
|
|
973
1079
|
}
|
|
974
1080
|
});
|
|
975
1081
|
};
|
|
976
|
-
var
|
|
1082
|
+
var Parameters15 = effect.Schema.Struct({
|
|
977
1083
|
query: effect.Schema.String
|
|
978
1084
|
});
|
|
979
1085
|
var Citation = effect.Schema.Struct({
|
|
980
1086
|
url: effect.Schema.String,
|
|
981
1087
|
title: effect.Schema.optional(effect.Schema.String)
|
|
982
1088
|
});
|
|
983
|
-
var
|
|
1089
|
+
var Success15 = effect.Schema.Struct({
|
|
984
1090
|
query: effect.Schema.String,
|
|
985
1091
|
answer: effect.Schema.String,
|
|
986
1092
|
citations: effect.Schema.Array(Citation),
|
|
@@ -1006,8 +1112,8 @@ var perplexitySearch = (config) => {
|
|
|
1006
1112
|
return agent.defineTool({
|
|
1007
1113
|
name: config.name ?? "perplexity_search",
|
|
1008
1114
|
description: config.description ?? "H\u1ECFi-\u0111\xE1p web v\u1EDBi Perplexity Sonar: nh\u1EADn v\u1EC1 c\xE2u tr\u1EA3 l\u1EDDi \u0111\xE3 t\u1ED5ng h\u1EE3p + citation. D\xF9ng khi c\u1EA7n th\xF4ng tin t\u01B0\u01A1i/\u0111a ngu\u1ED3n.",
|
|
1009
|
-
parameters:
|
|
1010
|
-
success:
|
|
1115
|
+
parameters: Parameters15,
|
|
1116
|
+
success: Success15,
|
|
1011
1117
|
execute: async (input) => {
|
|
1012
1118
|
const url = `${baseURL.replace(/\/+$/, "")}/chat/completions`;
|
|
1013
1119
|
const controller = new AbortController();
|
|
@@ -1052,6 +1158,8 @@ var builtinTools = (config = {}) => {
|
|
|
1052
1158
|
if (isEnabled(config.time, true)) tools.time_now = timeNow(cfgOrEmpty(config.time));
|
|
1053
1159
|
if (isEnabled(config.displayResponse, true))
|
|
1054
1160
|
tools.display_response = displayResponse(cfgOrEmpty(config.displayResponse));
|
|
1161
|
+
if (isEnabled(config.updateTodoList, false))
|
|
1162
|
+
tools.update_todo_list = updateTodoList(cfgOrEmpty(config.updateTodoList));
|
|
1055
1163
|
if (isEnabled(config.weather, false)) tools.weather = weather(cfgOrEmpty(config.weather));
|
|
1056
1164
|
if (isEnabled(config.crypto, false)) tools.crypto_price = cryptoPrice(cfgOrEmpty(config.crypto));
|
|
1057
1165
|
if (isEnabled(config.vnGold, false)) tools.vn_gold_price = vnGoldPrice(cfgOrEmpty(config.vnGold));
|
|
@@ -1085,10 +1193,13 @@ exports.loadHtml = loadHtml;
|
|
|
1085
1193
|
exports.makeLocalFS = makeLocalFS;
|
|
1086
1194
|
exports.makeMemoryStore = makeMemoryStore;
|
|
1087
1195
|
exports.makeS3Store = makeS3Store;
|
|
1196
|
+
exports.parseMarkdownChecklist = parseMarkdownChecklist;
|
|
1088
1197
|
exports.parseVndNumber = parseVndNumber;
|
|
1089
1198
|
exports.perplexitySearch = perplexitySearch;
|
|
1090
1199
|
exports.postJson = postJson;
|
|
1091
1200
|
exports.timeNow = timeNow;
|
|
1201
|
+
exports.todoListToMarkdown = todoListToMarkdown;
|
|
1202
|
+
exports.updateTodoList = updateTodoList;
|
|
1092
1203
|
exports.vnGoldPrice = vnGoldPrice;
|
|
1093
1204
|
exports.vnLottery = vnLottery;
|
|
1094
1205
|
exports.weather = weather;
|