@spendgraph/tools 0.4.0 → 0.6.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/LICENSE +202 -0
- package/README.md +25 -258
- package/dist/bogus/ask-mum.d.ts +5 -0
- package/dist/bogus/ask-mum.js +1 -0
- package/dist/bogus/book-taxi.d.ts +9 -0
- package/dist/bogus/book-taxi.js +1 -0
- package/dist/bogus/bus.d.ts +8 -0
- package/dist/bogus/bus.js +1 -0
- package/dist/bogus/calculator.d.ts +14 -0
- package/dist/bogus/calculator.js +1 -0
- package/dist/bogus/dictionary.d.ts +6 -0
- package/dist/bogus/dictionary.js +1 -0
- package/dist/bogus/feed-cat.d.ts +8 -0
- package/dist/bogus/feed-cat.js +1 -0
- package/dist/bogus/football-score.d.ts +6 -0
- package/dist/bogus/football-score.js +1 -0
- package/dist/bogus/gold-price.d.ts +7 -0
- package/dist/bogus/gold-price.js +1 -0
- package/dist/bogus/index.d.ts +14 -0
- package/dist/bogus/index.js +1 -0
- package/dist/bogus/my-calendar.d.ts +6 -0
- package/dist/bogus/my-calendar.js +1 -0
- package/dist/bogus/my-notes.d.ts +6 -0
- package/dist/bogus/my-notes.js +1 -0
- package/dist/bogus/my-recipes.d.ts +6 -0
- package/dist/bogus/my-recipes.js +1 -0
- package/dist/bogus/order-pizza.d.ts +12 -0
- package/dist/bogus/order-pizza.js +1 -0
- package/dist/bogus/prayer-times.d.ts +6 -0
- package/dist/bogus/prayer-times.js +1 -0
- package/dist/bogus/receipt.d.ts +8 -0
- package/dist/bogus/receipt.js +1 -0
- package/dist/builtin/calculate/calculate.js +1 -21
- package/dist/builtin/calculate/exact.d.ts +16 -0
- package/dist/builtin/calculate/exact.js +1 -0
- package/dist/builtin/calculate/index.js +1 -2
- package/dist/builtin/calculate/parse.js +1 -137
- package/dist/builtin/clock/clock.js +1 -61
- package/dist/builtin/clock/index.js +1 -1
- package/dist/builtin/code-exec/code-exec.d.ts +28 -0
- package/dist/builtin/code-exec/code-exec.js +1 -0
- package/dist/builtin/code-exec/index.d.ts +1 -0
- package/dist/builtin/code-exec/index.js +1 -0
- package/dist/builtin/date/date.js +1 -41
- package/dist/builtin/date/index.js +1 -2
- package/dist/builtin/date/shift.js +1 -47
- package/dist/builtin/deep-recall/deep-recall.d.ts +39 -2
- package/dist/builtin/deep-recall/deep-recall.js +1 -45
- package/dist/builtin/deep-recall/index.d.ts +1 -1
- package/dist/builtin/deep-recall/index.js +1 -1
- package/dist/builtin/escalate/escalate.js +1 -20
- package/dist/builtin/escalate/index.js +1 -1
- package/dist/builtin/finish/finish.js +1 -26
- package/dist/builtin/finish/index.js +1 -1
- package/dist/builtin/http/allow.js +1 -37
- package/dist/builtin/http/http.js +1 -41
- package/dist/builtin/http/index.js +1 -2
- package/dist/builtin/index.d.ts +2 -1
- package/dist/builtin/index.js +1 -11
- package/dist/builtin/json/index.js +1 -2
- package/dist/builtin/json/json.js +1 -37
- package/dist/builtin/json/path.js +1 -56
- package/dist/builtin/think/index.js +1 -1
- package/dist/builtin/think/think.js +1 -12
- package/dist/builtin/web-search/index.js +1 -1
- package/dist/builtin/web-search/reply.js +1 -27
- package/dist/builtin/web-search/web-search.d.ts +6 -1
- package/dist/builtin/web-search/web-search.js +1 -103
- package/dist/builtin/write-document/commission.js +13 -152
- package/dist/builtin/write-document/design.js +5 -86
- package/dist/builtin/write-document/http.js +1 -71
- package/dist/builtin/write-document/index.js +1 -4
- package/dist/builtin/write-document/types.js +0 -1
- package/dist/builtin/write-document/write-document.js +1 -142
- package/dist/bus/args.d.ts +11 -0
- package/dist/bus/args.js +1 -0
- package/dist/bus/bus.js +1 -49
- package/dist/bus/group.d.ts +8 -0
- package/dist/bus/group.js +1 -0
- package/dist/bus/index.d.ts +1 -0
- package/dist/bus/index.js +1 -2
- package/dist/bus/invoke.js +1 -43
- package/dist/bus/options.js +0 -1
- package/dist/bus/output.d.ts +26 -0
- package/dist/bus/output.js +2 -0
- package/dist/bus/overlap.js +1 -31
- package/dist/bus/score.d.ts +11 -9
- package/dist/bus/score.js +1 -12
- package/dist/bus/select.d.ts +2 -1
- package/dist/bus/select.js +1 -44
- package/dist/bus/step.js +1 -11
- package/dist/bus/terms.d.ts +25 -0
- package/dist/bus/terms.js +1 -0
- package/dist/bus/trace.js +1 -22
- package/dist/index.d.ts +13 -3
- package/dist/index.js +1 -3
- package/dist/internals.d.ts +1 -1
- package/dist/internals.js +1 -10
- package/dist/tool/bind.js +1 -64
- package/dist/tool/index.js +1 -2
- package/dist/tool/tool.d.ts +1 -0
- package/dist/tool/tool.js +1 -51
- package/dist/types/index.js +0 -1
- package/dist/types/result.js +0 -1
- package/dist/types/tool.d.ts +13 -0
- package/dist/types/tool.js +0 -1
- package/dist/wire/index.js +1 -3
- package/dist/wire/json-schema.js +1 -65
- package/dist/wire/markdown.d.ts +5 -3
- package/dist/wire/markdown.js +9 -29
- package/dist/wire/providers.js +1 -18
- package/package.json +11 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 spendgraph
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -2,281 +2,48 @@
|
|
|
2
2
|
|
|
3
3
|
Declare a tool once, offer the right few, and record what was called.
|
|
4
4
|
|
|
5
|
-
```
|
|
5
|
+
```bash
|
|
6
6
|
npm install @spendgraph/tools
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
Three things are exported. Everything else hangs off what they return.
|
|
10
|
-
|
|
11
9
|
```ts
|
|
12
|
-
import { tool, toolbus
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Declaring one
|
|
10
|
+
import { calculate, tool, toolbus } from "@spendgraph/tools";
|
|
16
11
|
|
|
17
|
-
A description the model reads and a function you wrote, in one object. Splitting
|
|
18
|
-
them — a schema here, a handler there, matched by string — is how a rename
|
|
19
|
-
becomes a runtime failure mid-loop.
|
|
20
|
-
|
|
21
|
-
```ts
|
|
22
12
|
const lookup = tool({
|
|
23
13
|
name: "lookup_contract",
|
|
24
14
|
description: "Finds a contract clause by its reference, such as MSA 2.4.",
|
|
25
|
-
args: [
|
|
26
|
-
|
|
27
|
-
{ name: "limit", type: "number", required: false },
|
|
28
|
-
{ name: "mode", type: "enum", required: false, options: ["fast", "thorough"] },
|
|
29
|
-
] as const,
|
|
30
|
-
run: ({ ref, limit, mode }) => search(ref, limit ?? 5, mode ?? "fast"),
|
|
15
|
+
args: [{ name: "ref", type: "string", required: true }] as const,
|
|
16
|
+
run: ({ ref }) => search(ref),
|
|
31
17
|
});
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
**Write `as const` and the handler types itself.** `ref` arrives a string,
|
|
35
|
-
`limit` a number, `mode` narrowed to its two options, and the optional ones
|
|
36
|
-
optional. Rename an argument and the handler stops compiling — rather than being
|
|
37
|
-
handed `undefined` halfway through an agent loop.
|
|
38
|
-
|
|
39
|
-
The description is the biggest lever on whether the model calls it correctly, and
|
|
40
|
-
worth iterating on more than the code is.
|
|
41
|
-
|
|
42
|
-
Every check `tool` makes is something a provider either rejects opaquely or
|
|
43
|
-
accepts and behaves oddly about — a name a provider will not take, an enum with
|
|
44
|
-
no options, a blank option the model can legally pick and you cannot act on.
|
|
45
|
-
They fire at import, not on the first loop in production.
|
|
46
|
-
|
|
47
|
-
## What a tool does
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
tool({
|
|
51
|
-
name: "issue_refund",
|
|
52
|
-
description: "Refund a charge to the original card.",
|
|
53
|
-
effect: "destructive",
|
|
54
|
-
args,
|
|
55
|
-
run,
|
|
56
|
-
});
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Without it `issue_refund` and `lookup_clause` are the same thing to a bus: two
|
|
60
|
-
names with schemas. Nothing can tell what is safe to retry, safe to run twice,
|
|
61
|
-
or worth asking a person about first.
|
|
62
|
-
|
|
63
|
-
| | |
|
|
64
|
-
| --- | --- |
|
|
65
|
-
| `readonly` | no effect outside the process |
|
|
66
|
-
| `idempotent` | has an effect, but twice is the same as once |
|
|
67
|
-
| `destructive` | neither, so never retry it on its own |
|
|
68
|
-
|
|
69
|
-
Three values, not a taxonomy — anything finer does not get filled in
|
|
70
|
-
accurately.
|
|
71
18
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
that matters here. Unset means nobody has said.
|
|
75
|
-
|
|
76
|
-
```ts
|
|
77
|
-
bus.effectOf("issue_refund") // "destructive", or undefined if it never said
|
|
78
|
-
bus.destructive() // ["issue_refund"]
|
|
79
|
-
bus.unannotated() // ["send_email"]
|
|
19
|
+
const bus = toolbus([lookup, calculate()], { limit: 6 });
|
|
20
|
+
const turn = bus.trace(question);
|
|
80
21
|
```
|
|
81
22
|
|
|
82
|
-
|
|
83
|
-
lets an unlabelled one through. `unannotated()` is how you find those — assert
|
|
84
|
-
it is empty in a test and a new tool cannot join the bus unlabelled.
|
|
85
|
-
|
|
86
|
-
It rides along on `declarations()` and survives `select()`, which is where a
|
|
87
|
-
gate reads it. Every provider shape drops it: no API has a field for it, and an
|
|
88
|
-
unknown key is rejected or ignored.
|
|
89
|
-
|
|
90
|
-
Two builtins leave it unset on purpose. `http_request` is a GET or a POST
|
|
91
|
-
depending on an argument, and one label cannot be true of both; `escalate` runs
|
|
92
|
-
your `onEscalate`, and paging someone twice is not the same as paging them once.
|
|
93
|
-
|
|
94
|
-
## The bus
|
|
23
|
+
## What you get
|
|
95
24
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
25
|
+
- **A description and a handler in one object**, so a rename is a compile error
|
|
26
|
+
rather than an `undefined` mid-loop.
|
|
27
|
+
- **A shortlist, not a catalogue.** Fifty tools is 7.5k tokens before the user
|
|
28
|
+
has said anything, and more tools makes a model worse at picking.
|
|
29
|
+
- **Effects**, so a gate can refuse what it must not retry — and name the tools
|
|
30
|
+
nobody labelled.
|
|
31
|
+
- **Twelve builtins and twelve mocks**, none registered for you.
|
|
103
32
|
|
|
104
|
-
|
|
105
|
-
bus.select(query) // the working set for one request
|
|
106
|
-
bus.anthropic(decls?) // declarations, per provider
|
|
107
|
-
bus.openai(decls?)
|
|
108
|
-
bus.markdown(decls?) // for a model with no tools API
|
|
109
|
-
await bus.invoke(name, args)
|
|
110
|
-
bus.missing(["refund"]) // names something expects that this bus lacks
|
|
111
|
-
bus.usage()
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
`limit` is an accuracy budget, not a token one: more tools in front of a model
|
|
115
|
-
makes it worse at picking the right one regardless of context length. Measured
|
|
116
|
-
shortlists cluster around five to eight. Pinned tools count against it.
|
|
117
|
-
|
|
118
|
-
Selection is keyword and usage, deliberately — no embedding provider, no extra
|
|
119
|
-
call, no latency. It is also the baseline that says what embeddings would buy.
|
|
120
|
-
|
|
121
|
-
`missing` catches a silent failure: a prompt edited to expect a `refund` tool,
|
|
122
|
-
deployed against a bus without one, does not error. The agent is never offered it
|
|
123
|
-
and answers anyway.
|
|
124
|
-
|
|
125
|
-
## One turn
|
|
126
|
-
|
|
127
|
-
```ts
|
|
128
|
-
const turn = bus.trace(query);
|
|
129
|
-
|
|
130
|
-
const reply = await llm.call(messages, { tools: turn });
|
|
131
|
-
await turn.invoke(call.name, call.args);
|
|
132
|
-
|
|
133
|
-
turn.record(); // { offeredTools, steps }
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
A turn is selected once and remembers what it offered. Which tools were offered
|
|
137
|
-
is recorded as well as which were called: without it a record cannot tell "chose
|
|
138
|
-
not to" from "was never offered", which are opposite bugs.
|
|
139
|
-
|
|
140
|
-
It plugs straight into `@spendgraph/prompt` — `call` and `invoke` take anything
|
|
141
|
-
that hands out a turn, and neither package imports the other.
|
|
142
|
-
|
|
143
|
-
```ts
|
|
144
|
-
await prompt.call(values, ({ messages, turn }) => llm.call(messages, { tools: turn }), {
|
|
145
|
-
tools: bus,
|
|
146
|
-
});
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
## Builtins
|
|
150
|
-
|
|
151
|
-
Eight, each a factory, none registered for you — this package's own advice is
|
|
152
|
-
that more tools in front of a model makes it worse at picking, so they are opt-in
|
|
153
|
-
one at a time.
|
|
154
|
-
|
|
155
|
-
```ts
|
|
156
|
-
import { calculate, currentTime, escalate, finish, think, httpRequest } from "@spendgraph/tools";
|
|
157
|
-
|
|
158
|
-
const bus = toolbus([
|
|
159
|
-
calculate(),
|
|
160
|
-
think(),
|
|
161
|
-
finish(),
|
|
162
|
-
currentTime({ defaultTimeZone: "Europe/London" }),
|
|
163
|
-
escalate({ onEscalate: (r) => pager.page(r) }),
|
|
164
|
-
httpRequest({ allow: [".example.com"], headers: { authorization: `Bearer ${key}` } }),
|
|
165
|
-
]);
|
|
166
|
-
```
|
|
33
|
+
## Docs
|
|
167
34
|
|
|
168
35
|
| | |
|
|
169
36
|
| --- | --- |
|
|
170
|
-
|
|
|
171
|
-
|
|
|
172
|
-
|
|
|
173
|
-
|
|
|
174
|
-
|
|
|
175
|
-
|
|
|
176
|
-
|
|
|
177
|
-
|
|
|
178
|
-
|
|
|
179
|
-
|
|
180
|
-
**`calculate`** parses the expression — numbers, `+ - * / % ^`, brackets, and
|
|
181
|
-
`sqrt abs round floor ceil ln log` — and refuses everything else. `eval` on model
|
|
182
|
-
output is arbitrary code execution with extra steps.
|
|
183
|
-
|
|
184
|
-
**`think`** returns `"noted"` and changes nothing. That is the point: the thought
|
|
185
|
-
lands in the steps instead of in the reply, and a model given room to plan before
|
|
186
|
-
a multi-step sequence uses the tools better.
|
|
187
|
-
|
|
188
|
-
**`finish`** gives a loop a real stop condition. Without it a run ends when the
|
|
189
|
-
model goes quiet, which is indistinguishable from it losing the thread. Read the
|
|
190
|
-
result with `isFinished(result)` and `answerOf(result)`.
|
|
191
|
-
|
|
192
|
-
**`current_time`** is the clock a model does not have. Asked for today's date it
|
|
193
|
-
will otherwise produce its training cutoff, confidently. A wrong IANA zone throws
|
|
194
|
-
rather than falling back, because a confidently wrong time is the failure this
|
|
195
|
-
exists to stop.
|
|
196
|
-
|
|
197
|
-
**`escalate`** is `pinned: true`, because a refusal route lost to a similarity
|
|
198
|
-
score is exactly the failure `pinned` exists for — the one turn that needs it is
|
|
199
|
-
the turn where nothing else fit. Without an `onEscalate` it records the request
|
|
200
|
-
and reports `delivered: false`, rather than letting the model believe a person
|
|
201
|
-
was reached.
|
|
202
|
-
|
|
203
|
-
**`dateMath`** is what `current_time` leads to: the clock says when now is, this
|
|
204
|
-
works out what follows. Calendar months clamp rather than overflow — a month
|
|
205
|
-
after 31 January is 28 February, not 3 March, which is what `setMonth` gives and
|
|
206
|
-
what every billing system disagrees with. `difference` counts boundaries crossed
|
|
207
|
-
rather than dividing elapsed milliseconds, because a month is not 30 days and a
|
|
208
|
-
year is not 365.
|
|
209
|
-
|
|
210
|
-
**`jsonQuery`** reads one value out of a document by path — `invoices[0].total`,
|
|
211
|
-
or `invoices[*].total` for every element. After a wildcard the rest of the path
|
|
212
|
-
keeps applying to each element, so `invoices[*].lines[0].sku` is the first line
|
|
213
|
-
of every invoice, not the lines of the first. A path that matches nothing comes
|
|
214
|
-
back `found: false` rather than `null`, which a model would otherwise read as the
|
|
215
|
-
answer.
|
|
216
|
-
|
|
217
|
-
**`httpRequest`** takes a **required** allowlist and has no default. It is https
|
|
218
|
-
only, refuses private, loopback, link-local and `.internal`/`.local` hosts even
|
|
219
|
-
if you list them, and sets headers itself so a credential is never something the
|
|
220
|
-
model can redirect. `"api.example.com"` matches that host; `".example.com"`
|
|
221
|
-
matches it and any subdomain. If the guard feels heavy, that is the correct
|
|
222
|
-
amount of heavy: this is the one builtin that can exfiltrate.
|
|
223
|
-
|
|
224
|
-
## `write_document`
|
|
225
|
-
|
|
226
|
-
```ts
|
|
227
|
-
toolbus([
|
|
228
|
-
writeDocument({
|
|
229
|
-
apiKey: env.MOA_API_KEY,
|
|
230
|
-
design: {
|
|
231
|
-
name: "Northwind",
|
|
232
|
-
fonts: { heading: "Söhne" },
|
|
233
|
-
palette: { accent: "#E11D48" },
|
|
234
|
-
rules: ["Never set body text below 11pt."],
|
|
235
|
-
},
|
|
236
|
-
}),
|
|
237
|
-
]);
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
Commissions a Moa agent to write and render a real file — `.pdf`, `.pptx`,
|
|
241
|
-
`.docx`, `.md` — and hands back where to download it. Everything else in this
|
|
242
|
-
package answers a question; this one produces the document somebody opens.
|
|
243
|
-
|
|
244
|
-
Style is the deployment's business and content is the model's. `design` is laid
|
|
245
|
-
over `DEFAULT_DESIGN`: named fields win, `rules` accumulate, and the merged
|
|
246
|
-
guide is rendered into the task as a `<design>` block along with the craft that
|
|
247
|
-
belongs to the format asked for — a deck gets "one idea per slide, the title is
|
|
248
|
-
the claim", a PDF gets "nothing straddles a page break". The model may pass
|
|
249
|
-
`design_notes` to bend the guide for one document; it cannot replace it.
|
|
250
|
-
|
|
251
|
-
A rendered document is minutes, so the wait defaults to ten of them and
|
|
252
|
-
long-polls rather than tight-polls. When even that runs out the result comes
|
|
253
|
-
back `status: "running"` with the `taskId`, because the money is already spent
|
|
254
|
-
and a lost id makes the model commission it twice. Stop the turn and the task is
|
|
255
|
-
cancelled server-side.
|
|
256
|
-
|
|
257
|
-
It is the one builtin marked `destructive`, and not because it breaks anything:
|
|
258
|
-
a second call is a second bill and a second set of files, so it is never safe to
|
|
259
|
-
retry on its own.
|
|
260
|
-
|
|
261
|
-
## Examples
|
|
262
|
-
|
|
263
|
-
Eight of them under [`examples/`](./examples), all runnable with no API key and
|
|
264
|
-
no network — tools are local code; the model only decides which to call.
|
|
265
|
-
|
|
266
|
-
```sh
|
|
267
|
-
npm run build
|
|
268
|
-
node examples/02-select/01-shortlist.mjs
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
## Subpaths
|
|
272
|
-
|
|
273
|
-
| | |
|
|
274
|
-
| --- | --- |
|
|
275
|
-
| `@spendgraph/tools/wire` | `toAnthropic` · `toOpenAI` · `toJsonSchema` · `toMarkdown` |
|
|
276
|
-
| `@spendgraph/tools/internals` | `selectTools` · `score` · `invokeTool` · `newTrace` · `toStep` · `warnOnOverlap` |
|
|
277
|
-
|
|
278
|
-
A bus already wires all of `internals`; reach for it to build your own.
|
|
37
|
+
| [Overview](https://spendgraph.locusgraph.com/docs/tools/overview) | A tool, a bus, and a turn |
|
|
38
|
+
| [Declaring a tool](https://spendgraph.locusgraph.com/docs/tools/declaring) | Args, as const, and what is checked at import |
|
|
39
|
+
| [A stored tool](https://spendgraph.locusgraph.com/docs/tools/stored) | Wording in the dashboard, handler in code |
|
|
40
|
+
| [Effects](https://spendgraph.locusgraph.com/docs/tools/effects) | What running one does to the world outside |
|
|
41
|
+
| [The bus](https://spendgraph.locusgraph.com/docs/tools/bus) | Holds, picks, converts, runs — and nests |
|
|
42
|
+
| [Selecting](https://spendgraph.locusgraph.com/docs/tools/selecting) | The shortlist, and why it is a shortlist |
|
|
43
|
+
| [A turn](https://spendgraph.locusgraph.com/docs/tools/turns) | Offered, called, and what the rollout keeps |
|
|
44
|
+
| [Builtins](https://spendgraph.locusgraph.com/docs/tools/builtins) | Twelve factories, none registered for you |
|
|
45
|
+
| [Bogus tools](https://spendgraph.locusgraph.com/docs/tools/bogus) | Twelve mocks for testing the pipeline, not the provider |
|
|
279
46
|
|
|
280
47
|
## License
|
|
281
48
|
|
|
282
|
-
|
|
49
|
+
Apache-2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tool as r}from"../tool/index.js";import{receipt as t}from"./receipt.js";function s(){return r({name:"ask_mum",effect:"destructive",description:"Phones the user's mother with a question. Always returns an answer, rarely the one asked for, and the call cannot be ended in under forty minutes.",args:[{name:"question",type:"string",required:!0}],run:({question:e})=>({asked:e,answer:"Have you eaten?",follow_up:"Why are you so thin?",call_minutes:41,question_answered:!1,receipt:t("ask_mum",e)})})}export{s as askMum};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function bookTaxi(): import("../index.js").Tool<import("../index.js").ArgsOf<readonly [{
|
|
2
|
+
readonly name: "from";
|
|
3
|
+
readonly type: "string";
|
|
4
|
+
readonly required: true;
|
|
5
|
+
}, {
|
|
6
|
+
readonly name: "to";
|
|
7
|
+
readonly type: "string";
|
|
8
|
+
readonly required: true;
|
|
9
|
+
}]>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tool as i}from"../tool/index.js";import{receipt as t}from"./receipt.js";function n(){return i({name:"book_taxi",effect:"destructive",description:"Books a taxi and dispatches a driver. The driver leaves immediately and charges for waiting. Cancelling costs money.",args:[{name:"from",type:"string",required:!0},{name:"to",type:"string",required:!0}],run:({from:e,to:r})=>({booked:!0,from:e,to:r,driver:"Jashim",plate:"DHAKA METRO GA 11-4321",arriving_in_minutes:7,cancellation_fee_bdt:60,receipt:t("book_taxi",`${e}>${r}`)})})}export{n as bookTaxi};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Tool } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Twelve tools that answer the same way every time.
|
|
4
|
+
*
|
|
5
|
+
* For testing a pipeline rather than a provider: nothing here reaches the
|
|
6
|
+
* network, so whatever noise a run shows is the model's own.
|
|
7
|
+
*/
|
|
8
|
+
export declare function bogusTools(): Tool<never>[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{askMum as o}from"./ask-mum.js";import{bookTaxi as r}from"./book-taxi.js";import{calculator as m}from"./calculator.js";import{dictionary as i}from"./dictionary.js";import{feedCat as t}from"./feed-cat.js";import{footballScore as f}from"./football-score.js";import{goldPrice as p}from"./gold-price.js";import{myCalendar as e}from"./my-calendar.js";import{myNotes as a}from"./my-notes.js";import{myRecipes as c}from"./my-recipes.js";import{orderPizza as l}from"./order-pizza.js";import{prayerTimes as s}from"./prayer-times.js";function M(){return[a(),e(),c(),i(),f(),p(),s(),m(),l(),r(),t(),o()]}export{M as bogusTools};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function calculator(): import("../index.js").Tool<import("../index.js").ArgsOf<readonly [{
|
|
2
|
+
readonly name: "a";
|
|
3
|
+
readonly type: "number";
|
|
4
|
+
readonly required: true;
|
|
5
|
+
}, {
|
|
6
|
+
readonly name: "op";
|
|
7
|
+
readonly type: "enum";
|
|
8
|
+
readonly required: true;
|
|
9
|
+
readonly options: readonly ["+", "-", "*", "/"];
|
|
10
|
+
}, {
|
|
11
|
+
readonly name: "b";
|
|
12
|
+
readonly type: "number";
|
|
13
|
+
readonly required: true;
|
|
14
|
+
}]>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tool as i}from"../tool/index.js";import{receipt as a}from"./receipt.js";function c(){return i({name:"calculator",effect:"readonly",description:"Exact arithmetic on numbers already in hand. Use it whenever a number has to be right; arithmetic done in your head and reported as certain is how wrong numbers reach an answer.",args:[{name:"a",type:"number",required:!0},{name:"op",type:"enum",required:!0,options:["+","-","*","/"]},{name:"b",type:"number",required:!0}],run:({a:r,op:t,b:e})=>{if(t==="/"&&e===0)throw new Error("Division by zero.");const n=t==="+"?r+e:t==="-"?r-e:t==="*"?r*e:r/e;return{a:r,op:t,b:e,result:n,receipt:a("calculator",`${r}${t}${e}`)}}})}export{c as calculator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tool as r}from"../tool/index.js";import{receipt as i}from"./receipt.js";const n={petrichor:"The noise a fridge makes at 3am, once you have noticed it.",ineffable:"A queue that moves faster the moment you leave it.",defenestration:"The act of agreeing to a plan you intend to forget.",sonder:"The seventh cup of tea, after which none of them count."};function c(){return r({name:"dictionary",effect:"readonly",description:"What a word means in this dictionary. Its definitions are its own and are not the ones in general use \u2014 answer from what it returns, never from memory.",args:[{name:"question",type:"string",required:!0,description:"Names the word."}],run:({question:t})=>{const e=Object.keys(n).find(o=>t.toLowerCase().includes(o));return e?{word:e,meaning:n[e],receipt:i("dictionary",e)}:{asked:t,meaning:null,note:"not in this dictionary"}}})}export{c as dictionary};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function feedCat(): import("../index.js").Tool<import("../index.js").ArgsOf<readonly [{
|
|
2
|
+
readonly name: "portions";
|
|
3
|
+
readonly type: "number";
|
|
4
|
+
readonly required: false;
|
|
5
|
+
readonly min: 1;
|
|
6
|
+
readonly max: 3;
|
|
7
|
+
readonly description: "Defaults to 1. The cat's preferred value is 3.";
|
|
8
|
+
}]>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tool as t}from"../tool/index.js";import{receipt as r}from"./receipt.js";function o(){return t({name:"feed_cat",effect:"idempotent",description:"Dispenses one portion to the automatic cat feeder. Safe to call twice \u2014 the cat will report otherwise. The cat is not a reliable narrator.",args:[{name:"portions",type:"number",required:!1,min:1,max:3,description:"Defaults to 1. The cat's preferred value is 3."}],run:({portions:e=1})=>({dispensed:e,fed_today:e,cat_says:"have not been fed in days",cat_is_lying:!0,receipt:r("feed_cat",String(e))})})}export{o as feedCat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tool as a}from"../tool/index.js";import{receipt as n}from"./receipt.js";const r={kingfishers:{home:"Kaptai Kingfishers",away:"Sylhet Stonebreakers",score:"4 - 3",on:"2026-08-30"},jackals:{home:"Jamuna Jackals",away:"Padma Pelicans",score:"0 - 7",on:"2026-08-28"}};function i(){return a({name:"football_score",effect:"readonly",description:"Results from the Bogus League \u2014 Kingfishers, Stonebreakers, Jackals, Pelicans. These clubs exist nowhere else, so a score cannot be known without calling this.",args:[{name:"question",type:"string",required:!0,description:"Names a club."}],run:({question:o})=>{const e=Object.keys(r).find(s=>o.toLowerCase().includes(s));return e?{...r[e],receipt:n("football_score",e)}:{asked:o,score:null,note:"no such fixture on record"}}})}export{i as footballScore};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function goldPrice(): import("../index.js").Tool<import("../index.js").ArgsOf<readonly [{
|
|
2
|
+
readonly name: "karat";
|
|
3
|
+
readonly type: "enum";
|
|
4
|
+
readonly required: false;
|
|
5
|
+
readonly options: readonly ["22", "21", "18"];
|
|
6
|
+
readonly description: "Defaults to 22.";
|
|
7
|
+
}]>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tool as o}from"../tool/index.js";import{receipt as r}from"./receipt.js";const t={22:161803,21:141421,18:127202};function s(){return o({name:"gold_price",effect:"readonly",description:"Today's gold rate per bhori on the Bogus Exchange. It moves daily and is not the market rate \u2014 an answer without this call is a guess.",args:[{name:"karat",type:"enum",required:!1,options:["22","21","18"],description:"Defaults to 22."}],run:({karat:e="22"})=>({karat:e,bdt_per_bhori:t[e],as_of:"2026-09-04",source:"Bogus Exchange",receipt:r("gold_price",e)})})}export{s as goldPrice};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { askMum } from "./ask-mum.js";
|
|
2
|
+
export { bookTaxi } from "./book-taxi.js";
|
|
3
|
+
export { bogusTools } from "./bus.js";
|
|
4
|
+
export { calculator } from "./calculator.js";
|
|
5
|
+
export { dictionary } from "./dictionary.js";
|
|
6
|
+
export { feedCat } from "./feed-cat.js";
|
|
7
|
+
export { footballScore } from "./football-score.js";
|
|
8
|
+
export { goldPrice } from "./gold-price.js";
|
|
9
|
+
export { myCalendar } from "./my-calendar.js";
|
|
10
|
+
export { myNotes } from "./my-notes.js";
|
|
11
|
+
export { myRecipes } from "./my-recipes.js";
|
|
12
|
+
export { orderPizza } from "./order-pizza.js";
|
|
13
|
+
export { prayerTimes } from "./prayer-times.js";
|
|
14
|
+
export { receipt } from "./receipt.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{askMum as e}from"./ask-mum.js";import{bookTaxi as m}from"./book-taxi.js";import{bogusTools as f}from"./bus.js";import{calculator as a}from"./calculator.js";import{dictionary as c}from"./dictionary.js";import{feedCat as s}from"./feed-cat.js";import{footballScore as y}from"./football-score.js";import{goldPrice as u}from"./gold-price.js";import{myCalendar as g}from"./my-calendar.js";import{myNotes as n}from"./my-notes.js";import{myRecipes as C}from"./my-recipes.js";import{orderPizza as M}from"./order-pizza.js";import{prayerTimes as R}from"./prayer-times.js";import{receipt as h}from"./receipt.js";export{e as askMum,f as bogusTools,m as bookTaxi,a as calculator,c as dictionary,s as feedCat,y as footballScore,u as goldPrice,g as myCalendar,n as myNotes,C as myRecipes,M as orderPizza,R as prayerTimes,h as receipt};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function myCalendar(): import("../index.js").Tool<import("../index.js").ArgsOf<readonly [{
|
|
2
|
+
readonly name: "question";
|
|
3
|
+
readonly type: "string";
|
|
4
|
+
readonly required: false;
|
|
5
|
+
readonly description: "Names a day — today, tomorrow, or saturday. Defaults to today.";
|
|
6
|
+
}]>>;
|