@spendgraph/tools 0.5.0 → 0.7.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 +26 -258
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.js +1 -0
- package/dist/agents/moa/design.js +5 -0
- package/dist/agents/moa/http.js +1 -0
- package/dist/{builtin/write-document/write-document.d.ts → agents/moa/index.d.ts} +7 -2
- package/dist/agents/moa/index.js +1 -0
- package/dist/{builtin/write-document/commission.d.ts → agents/moa/moa.d.ts} +15 -15
- package/dist/agents/moa/moa.js +13 -0
- package/dist/{builtin/write-document → agents/moa}/types.d.ts +9 -9
- package/dist/agents/moa/types.js +0 -0
- 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.d.ts +2 -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.d.ts +2 -1
- 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 +42 -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.d.ts +1 -1
- package/dist/builtin/date/date.js +1 -41
- package/dist/builtin/date/index.d.ts +1 -0
- package/dist/builtin/date/index.js +1 -2
- package/dist/builtin/date/shift.d.ts +1 -1
- package/dist/builtin/date/shift.js +1 -47
- package/dist/builtin/date/words.d.ts +13 -0
- package/dist/builtin/date/words.js +1 -0
- package/dist/builtin/decline/decline.d.ts +49 -0
- package/dist/builtin/decline/decline.js +1 -0
- package/dist/builtin/decline/index.d.ts +1 -0
- package/dist/builtin/decline/index.js +1 -0
- package/dist/builtin/escalate/escalate.d.ts +19 -0
- package/dist/builtin/escalate/escalate.js +1 -20
- package/dist/builtin/escalate/index.d.ts +1 -1
- package/dist/builtin/escalate/index.js +1 -1
- package/dist/builtin/extract/extract.d.ts +25 -0
- package/dist/builtin/extract/extract.js +1 -0
- package/dist/builtin/extract/index.d.ts +3 -0
- package/dist/builtin/extract/index.js +1 -0
- package/dist/builtin/extract/kinds.d.ts +6 -0
- package/dist/builtin/extract/kinds.js +1 -0
- package/dist/builtin/extract/readers.d.ts +7 -0
- package/dist/builtin/extract/readers.js +9 -0
- package/dist/builtin/finish/finish.d.ts +4 -0
- package/dist/builtin/finish/finish.js +1 -26
- package/dist/builtin/finish/index.js +1 -1
- package/dist/builtin/http/allow.d.ts +2 -0
- package/dist/builtin/http/allow.js +1 -37
- package/dist/builtin/http/hops.d.ts +10 -0
- package/dist/builtin/http/hops.js +1 -0
- package/dist/builtin/http/http.d.ts +9 -1
- package/dist/builtin/http/http.js +1 -41
- package/dist/builtin/http/index.d.ts +2 -0
- package/dist/builtin/http/index.js +1 -2
- package/dist/builtin/http/retry-after.d.ts +14 -0
- package/dist/builtin/http/retry-after.js +1 -0
- package/dist/builtin/index.d.ts +11 -6
- package/dist/builtin/index.js +1 -11
- package/dist/builtin/json/index.d.ts +1 -0
- package/dist/builtin/json/index.js +1 -2
- package/dist/builtin/json/json.js +1 -37
- package/dist/builtin/json/parse.d.ts +15 -0
- package/dist/builtin/json/parse.js +1 -0
- package/dist/builtin/json/path.js +1 -56
- package/dist/builtin/notes/index.d.ts +1 -0
- package/dist/builtin/notes/index.js +1 -0
- package/dist/builtin/notes/notes.d.ts +45 -0
- package/dist/builtin/notes/notes.js +2 -0
- package/dist/builtin/openalex/api.d.ts +22 -0
- package/dist/builtin/openalex/api.js +1 -0
- package/dist/builtin/openalex/index.d.ts +4 -0
- package/dist/builtin/openalex/index.js +1 -0
- package/dist/builtin/openalex/openalex.d.ts +23 -0
- package/dist/builtin/openalex/openalex.js +1 -0
- package/dist/builtin/openalex/render.d.ts +2 -0
- package/dist/builtin/openalex/render.js +4 -0
- package/dist/builtin/polite.d.ts +14 -0
- package/dist/builtin/polite.js +1 -0
- package/dist/builtin/publish/index.d.ts +1 -0
- package/dist/builtin/publish/index.js +1 -0
- package/dist/builtin/publish/publish.d.ts +46 -0
- package/dist/builtin/publish/publish.js +1 -0
- 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/web-search.d.ts +10 -30
- package/dist/builtin/web-search/web-search.js +1 -103
- package/dist/builtin/wikidata/api.d.ts +40 -0
- package/dist/builtin/wikidata/api.js +1 -0
- package/dist/builtin/wikidata/index.d.ts +5 -0
- package/dist/builtin/wikidata/index.js +1 -0
- package/dist/builtin/wikidata/render.d.ts +13 -0
- package/dist/builtin/wikidata/render.js +2 -0
- package/dist/builtin/wikidata/wikidata.d.ts +21 -0
- package/dist/builtin/wikidata/wikidata.js +1 -0
- package/dist/bus/args.d.ts +11 -0
- package/dist/bus/args.js +1 -0
- package/dist/bus/bus.d.ts +23 -1
- package/dist/bus/bus.js +1 -49
- package/dist/bus/group.d.ts +21 -0
- package/dist/bus/group.js +1 -0
- package/dist/bus/index.d.ts +4 -0
- package/dist/bus/index.js +1 -2
- package/dist/bus/invoke.d.ts +1 -1
- package/dist/bus/invoke.js +3 -43
- package/dist/bus/namespace.d.ts +21 -0
- package/dist/bus/namespace.js +1 -0
- package/dist/bus/once.d.ts +32 -0
- package/dist/bus/once.js +1 -0
- package/dist/bus/only.d.ts +29 -0
- package/dist/bus/only.js +0 -0
- package/dist/bus/options.d.ts +31 -0
- 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 -17
- package/dist/bus/select.js +1 -44
- package/dist/bus/spent.d.ts +16 -0
- package/dist/bus/spent.js +1 -0
- 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.d.ts +14 -1
- package/dist/bus/trace.js +1 -22
- package/dist/index.d.ts +16 -4
- package/dist/index.js +1 -3
- package/dist/internals.d.ts +9 -2
- package/dist/internals.js +1 -10
- package/dist/memories/client.d.ts +91 -0
- package/dist/memories/client.js +0 -0
- package/dist/memories/context.d.ts +5 -0
- package/dist/memories/context.js +1 -0
- package/dist/memories/deep-recall/deep-recall.d.ts +67 -0
- package/dist/memories/deep-recall/deep-recall.js +1 -0
- package/dist/memories/deep-recall/index.d.ts +1 -0
- package/dist/memories/deep-recall/index.js +1 -0
- package/dist/memories/explore/explore.d.ts +18 -0
- package/dist/memories/explore/explore.js +7 -0
- package/dist/memories/explore/subgraph.d.ts +12 -0
- package/dist/memories/explore/subgraph.js +3 -0
- package/dist/memories/index.d.ts +30 -0
- package/dist/memories/index.js +1 -0
- package/dist/memories/observe/observe.d.ts +7 -0
- package/dist/memories/observe/observe.js +1 -0
- package/dist/memories/recall/recall.d.ts +42 -0
- package/dist/memories/recall/recall.js +1 -0
- package/dist/memories/recall/render.d.ts +5 -0
- package/dist/memories/recall/render.js +3 -0
- package/dist/memories/remember/remember.d.ts +49 -0
- package/dist/memories/remember/remember.js +1 -0
- package/dist/search/index.d.ts +5 -0
- package/dist/search/index.js +1 -0
- package/dist/search/retry.d.ts +6 -0
- package/dist/search/retry.js +1 -0
- package/dist/search/search.d.ts +63 -0
- package/dist/search/search.js +1 -0
- package/dist/search/searxng/index.d.ts +2 -0
- package/dist/search/searxng/index.js +1 -0
- package/dist/search/searxng/searxng.d.ts +14 -0
- package/dist/search/searxng/searxng.js +5 -0
- package/dist/search/searxng/text.d.ts +2 -0
- package/dist/search/searxng/text.js +3 -0
- package/dist/search/sonar/index.d.ts +2 -0
- package/dist/search/sonar/index.js +1 -0
- package/dist/search/sonar/reply.js +1 -0
- package/dist/search/sonar/sonar.d.ts +13 -0
- package/dist/search/sonar/sonar.js +1 -0
- package/dist/search/tavily/index.d.ts +4 -0
- package/dist/search/tavily/index.js +1 -0
- package/dist/search/tavily/reply.d.ts +22 -0
- package/dist/search/tavily/reply.js +5 -0
- package/dist/search/tavily/tavily.d.ts +14 -0
- package/dist/search/tavily/tavily.js +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +1 -0
- package/dist/testing/replay.d.ts +55 -0
- package/dist/testing/replay.js +1 -0
- package/dist/testing/store.d.ts +35 -0
- package/dist/testing/store.js +4 -0
- package/dist/tool/bind.js +1 -64
- package/dist/tool/index.js +1 -2
- package/dist/tool/tool.d.ts +5 -1
- package/dist/tool/tool.js +1 -51
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +0 -1
- package/dist/types/result.d.ts +38 -0
- package/dist/types/result.js +0 -1
- package/dist/types/tool.d.ts +74 -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/docs/bogus.mdx +85 -0
- package/docs/builtins.mdx +156 -0
- package/docs/bus.mdx +90 -0
- package/docs/declaring.mdx +85 -0
- package/docs/effects.mdx +49 -0
- package/docs/overview.mdx +76 -0
- package/docs/selecting.mdx +79 -0
- package/docs/stored.mdx +83 -0
- package/docs/turns.mdx +57 -0
- package/package.json +28 -11
- package/dist/builtin/deep-recall/deep-recall.d.ts +0 -27
- package/dist/builtin/deep-recall/deep-recall.js +0 -45
- package/dist/builtin/deep-recall/index.d.ts +0 -1
- package/dist/builtin/deep-recall/index.js +0 -1
- package/dist/builtin/web-search/reply.js +0 -27
- package/dist/builtin/write-document/commission.js +0 -152
- package/dist/builtin/write-document/design.js +0 -86
- package/dist/builtin/write-document/http.js +0 -71
- package/dist/builtin/write-document/index.d.ts +0 -6
- package/dist/builtin/write-document/index.js +0 -4
- package/dist/builtin/write-document/types.js +0 -1
- package/dist/builtin/write-document/write-document.js +0 -142
- /package/dist/{builtin/write-document → agents/moa}/design.d.ts +0 -0
- /package/dist/{builtin/write-document → agents/moa}/http.d.ts +0 -0
- /package/dist/{builtin/web-search → search/sonar}/reply.d.ts +0 -0
package/dist/bus/trace.js
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { toStep } from "./step.js";
|
|
3
|
-
export function newTrace(offered, invoke) {
|
|
4
|
-
const steps = [];
|
|
5
|
-
return {
|
|
6
|
-
offered,
|
|
7
|
-
anthropic: () => toAnthropic(offered),
|
|
8
|
-
openai: () => toOpenAI(offered),
|
|
9
|
-
markdown: (heading) => toMarkdown(offered, heading),
|
|
10
|
-
effectOf: (name) => offered.find((d) => d.name === name)?.effect,
|
|
11
|
-
invoke: async (name, args) => {
|
|
12
|
-
const result = await invoke(name, args);
|
|
13
|
-
steps.push(toStep(result, steps.length));
|
|
14
|
-
return result;
|
|
15
|
-
},
|
|
16
|
-
steps: () => [...steps],
|
|
17
|
-
record: () => ({
|
|
18
|
-
offeredTools: offered.map((d) => d.name),
|
|
19
|
-
steps: [...steps],
|
|
20
|
-
}),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
1
|
+
import{toAnthropic as p,toMarkdown as c,toOpenAI as i}from"../wire/index.js";import{toStep as u}from"./step.js";function m(t,r,o){return{name:t,args:r,status:"failed",output:"",error:`No tool called "${t}" was offered this turn. Offered: ${o.map(n=>n.name).join(", ")}`,latencyMs:0}}function h(t,r){const o=[];return{offered:t,anthropic:()=>p(t),openai:()=>i(t),markdown:n=>c(t,n),effectOf:n=>t.find(e=>e.name===n)?.effect,invoke:async(n,e)=>{const s=t.some(a=>a.name===n)?await r(n,e):m(n,e,t);return o.push(u(s,o.length)),s},steps:()=>[...o],record:()=>({offeredTools:t.map(n=>n.name),steps:[...o]})}}export{h as newTrace};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* What `bus.anthropic()`, `bus.openai()` and `turn.record()` hand back.
|
|
3
|
+
*
|
|
4
|
+
* On the main entry because the functions that return them are: naming the
|
|
5
|
+
* result of a method you called from here should not send you to a second
|
|
6
|
+
* subpath, or to a second package. `@spendgraph/tools/wire` still holds the
|
|
7
|
+
* converters themselves, for a caller adapting a declaration by hand.
|
|
8
|
+
*/
|
|
9
|
+
export type { RolloutStep } from "@spendgraph/sdk";
|
|
10
|
+
export { type ArtifactFormat, DEFAULT_DESIGN, type DesignGuide, MoaAbortedError, type MoaClient, MoaTimeoutError, mergeDesign, renderDesign, type WriteDocumentOptions, writeDocument, } from "./agents/index.js";
|
|
11
|
+
export { answerOf, type ClockOptions, type CodeExecOptions, calculate, codeExec, currentTime, type Declined, dateMath, dates, decline, declinedFor, type EscalateOptions, type EscalationRequest, type ExtractOptions, escalate, escalationOf, extract, type Finished, finish, type HttpOptions, httpRequest, isDeclined, isEscalated, isFinished, type JsonQueryOptions, jsonFrom, jsonQuery, type NotesOptions, type NotesStore, notes, notesStore, type OpenAlexApi, type OpenAlexOptions, openalex, type Publisher, type PublishOptions, publish, retryAfterMs, type Sandbox, type SandboxRequest, type SandboxResult, type SearchDepth, think, type Unanswerable, type WebSearchOptions, type WikidataApi, type WikidataOptions, webSearch, wikidata, } from "./builtin/index.js";
|
|
12
|
+
export type { BusGroupOptions, BusMember, Namespacing, Offering, ToolBus, ToolBusOptions, ToolTrace, } from "./bus/index.js";
|
|
13
|
+
export { busgroup, priced, spentOn, toolbus } from "./bus/index.js";
|
|
14
|
+
export { contextId, type DeepRecallOptions, deepRecall, type ExploreOptions, exploreMemory, type MemoriesOptions, type MemoryClient, type MemoryContext, type MemoryGraph, type MemoryKind, type MemorySet, type MemorySource, type Moment, type MomentSource, memories, type Observer, type ObserverOptions, observer, type RecalledFact, type Recaller, type RecallFormat, type RecallOptions, type RecallResult, type RememberOptions, recall, remember, } from "./memories/index.js";
|
|
4
15
|
export type { BoundSpec, ToolSpec } from "./tool/index.js";
|
|
5
16
|
export { bindTool, ToolDriftError, ToolNotStoredError, tool } from "./tool/index.js";
|
|
6
|
-
export type { ArgSpec, ArgsOf, ArgValue, Effect, Tool, ToolDeclaration, ToolResult, } from "./types/index.js";
|
|
17
|
+
export type { ArgSpec, ArgsOf, ArgValue, Effect, Tool, ToolDeclaration, ToolResult, Trust, } from "./types/index.js";
|
|
18
|
+
export type { AnthropicTool, JsonSchema, JsonSchemaProperty, OpenAITool, } from "./wire/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { toolbus } from "./bus/index.js";
|
|
3
|
-
export { bindTool, ToolDriftError, ToolNotStoredError, tool } from "./tool/index.js";
|
|
1
|
+
import{DEFAULT_DESIGN as o,MoaAbortedError as t,MoaTimeoutError as i,mergeDesign as s,renderDesign as n,writeDocument as a}from"./agents/index.js";import{answerOf as c,calculate as d,codeExec as m,currentTime as p,dateMath as f,dates as u,decline as x,declinedFor as b,escalate as E,escalationOf as h,extract as D,finish as T,httpRequest as M,isDeclined as g,isEscalated as w,isFinished as F,jsonFrom as S,jsonQuery as y,notes as A,notesStore as O,openalex as j,publish as k,retryAfterMs as I,think as N,webSearch as R,wikidata as q}from"./builtin/index.js";import{busgroup as G,priced as L,spentOn as Q,toolbus as U}from"./bus/index.js";import{contextId as z,deepRecall as B,exploreMemory as C,memories as H,observer as J,recall as K,remember as P}from"./memories/index.js";import{bindTool as W,ToolDriftError as X,ToolNotStoredError as Y,tool as Z}from"./tool/index.js";export{o as DEFAULT_DESIGN,t as MoaAbortedError,i as MoaTimeoutError,X as ToolDriftError,Y as ToolNotStoredError,c as answerOf,W as bindTool,G as busgroup,d as calculate,m as codeExec,z as contextId,p as currentTime,f as dateMath,u as dates,x as decline,b as declinedFor,B as deepRecall,E as escalate,h as escalationOf,C as exploreMemory,D as extract,T as finish,M as httpRequest,g as isDeclined,w as isEscalated,F as isFinished,S as jsonFrom,y as jsonQuery,H as memories,s as mergeDesign,A as notes,O as notesStore,J as observer,j as openalex,L as priced,k as publish,K as recall,P as remember,n as renderDesign,I as retryAfterMs,Q as spentOn,N as think,Z as tool,U as toolbus,R as webSearch,q as wikidata,a as writeDocument};
|
package/dist/internals.d.ts
CHANGED
|
@@ -4,13 +4,20 @@
|
|
|
4
4
|
* Not in the main entry: a bus already wires all of it, and a caller reaching
|
|
5
5
|
* here is building their own. Kept exported so that stays possible.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The arithmetic behind `calculate`, and the way it renders a result.
|
|
9
|
+
*
|
|
10
|
+
* Both, because either alone is half a comparison. A rail checking a model's
|
|
11
|
+
* sum has to render its own the way the tool did or it flags a correct answer:
|
|
12
|
+
* `evaluate("0.1 + 0.2")` is `0.30000000000000004` and the tool said `0.3`.
|
|
13
|
+
*/
|
|
14
|
+
export { evaluate, exact } from "./builtin/calculate/index.js";
|
|
8
15
|
export { between, parseDate, shift, type Unit } from "./builtin/date/index.js";
|
|
9
16
|
export { checkUrl } from "./builtin/http/index.js";
|
|
10
17
|
export { readPath } from "./builtin/json/index.js";
|
|
11
18
|
export { invokeTool } from "./bus/invoke.js";
|
|
12
19
|
export { warnOnOverlap } from "./bus/overlap.js";
|
|
13
|
-
export {
|
|
20
|
+
export { type Describable, type Scorer, scorerFor } from "./bus/score.js";
|
|
14
21
|
export { selectTools } from "./bus/select.js";
|
|
15
22
|
export { toStep } from "./bus/step.js";
|
|
16
23
|
export { newTrace } from "./bus/trace.js";
|
package/dist/internals.js
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { between, parseDate, shift } from "./builtin/date/index.js";
|
|
3
|
-
export { checkUrl } from "./builtin/http/index.js";
|
|
4
|
-
export { readPath } from "./builtin/json/index.js";
|
|
5
|
-
export { invokeTool } from "./bus/invoke.js";
|
|
6
|
-
export { warnOnOverlap } from "./bus/overlap.js";
|
|
7
|
-
export { score } from "./bus/score.js";
|
|
8
|
-
export { selectTools } from "./bus/select.js";
|
|
9
|
-
export { toStep } from "./bus/step.js";
|
|
10
|
-
export { newTrace } from "./bus/trace.js";
|
|
1
|
+
import{evaluate as o,exact as t}from"./builtin/calculate/index.js";import{between as f,parseDate as x,shift as a}from"./builtin/date/index.js";import{checkUrl as c}from"./builtin/http/index.js";import{readPath as n}from"./builtin/json/index.js";import{invokeTool as h}from"./bus/invoke.js";import{warnOnOverlap as w}from"./bus/overlap.js";import{scorerFor as i}from"./bus/score.js";import{selectTools as O}from"./bus/select.js";import{toStep as d}from"./bus/step.js";import{newTrace as D}from"./bus/trace.js";export{f as between,c as checkUrl,o as evaluate,t as exact,h as invokeTool,D as newTrace,x as parseDate,n as readPath,i as scorerFor,O as selectTools,a as shift,d as toStep,w as warnOnOverlap};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { RootContextId } from "./context.js";
|
|
2
|
+
import type { Recaller } from "./deep-recall/deep-recall.js";
|
|
3
|
+
export type MemorySource = "policy" | "verified" | "tool" | "document" | "user" | "assistant" | "derived" | "system";
|
|
4
|
+
export type MomentSource = "policy" | "verified" | "tool" | "turn";
|
|
5
|
+
export type MemoryKind = "fact" | "decision" | "constraint" | "feedback" | "observation";
|
|
6
|
+
export interface MemoryContext {
|
|
7
|
+
context_id: string;
|
|
8
|
+
context_type: string;
|
|
9
|
+
context_name: string;
|
|
10
|
+
reference_count: number;
|
|
11
|
+
}
|
|
12
|
+
export interface RecalledItem {
|
|
13
|
+
locus_id: string;
|
|
14
|
+
context_ids: string[];
|
|
15
|
+
text: string;
|
|
16
|
+
score: number;
|
|
17
|
+
source?: string;
|
|
18
|
+
kind?: string;
|
|
19
|
+
created?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface MemoryClient extends Recaller {
|
|
22
|
+
retrieveMemories(query: {
|
|
23
|
+
query: string;
|
|
24
|
+
graphId?: string;
|
|
25
|
+
limit?: number;
|
|
26
|
+
contextIds?: string[];
|
|
27
|
+
boostContextIds?: string[];
|
|
28
|
+
sources?: string[];
|
|
29
|
+
format?: string;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
items_found: number;
|
|
32
|
+
items?: RecalledItem[];
|
|
33
|
+
}>;
|
|
34
|
+
storeEventsBatch(items: {
|
|
35
|
+
event_kind: string;
|
|
36
|
+
context_id?: string;
|
|
37
|
+
source?: MemorySource;
|
|
38
|
+
extends?: string[];
|
|
39
|
+
related_to?: string[];
|
|
40
|
+
reinforces?: string[];
|
|
41
|
+
contradicts?: string[];
|
|
42
|
+
payload: Record<string, unknown>;
|
|
43
|
+
}[], graphId?: string): Promise<{
|
|
44
|
+
stored: number;
|
|
45
|
+
filtered: number;
|
|
46
|
+
failed: number;
|
|
47
|
+
results: {
|
|
48
|
+
status: "recorded" | "filtered" | "error";
|
|
49
|
+
event_id?: string;
|
|
50
|
+
relevance?: "high" | "medium" | "low";
|
|
51
|
+
error?: string;
|
|
52
|
+
}[];
|
|
53
|
+
}>;
|
|
54
|
+
searchContexts(query: string, graphId?: string, options?: {
|
|
55
|
+
context_type?: string;
|
|
56
|
+
page_size?: number;
|
|
57
|
+
include?: string;
|
|
58
|
+
format?: string;
|
|
59
|
+
}): Promise<{
|
|
60
|
+
contexts: MemoryContext[];
|
|
61
|
+
total: number;
|
|
62
|
+
relationships_text?: string;
|
|
63
|
+
}>;
|
|
64
|
+
listContextTypes(graphId?: string): Promise<{
|
|
65
|
+
context_types: {
|
|
66
|
+
context_type: string;
|
|
67
|
+
count: number;
|
|
68
|
+
}[];
|
|
69
|
+
total: number;
|
|
70
|
+
}>;
|
|
71
|
+
getContextGraph(options: {
|
|
72
|
+
graphId?: string;
|
|
73
|
+
contextType: string;
|
|
74
|
+
contextName: string;
|
|
75
|
+
depth?: number;
|
|
76
|
+
}): Promise<unknown>;
|
|
77
|
+
observe(request: {
|
|
78
|
+
graphId?: string;
|
|
79
|
+
source: MomentSource;
|
|
80
|
+
payload: string | Record<string, unknown>;
|
|
81
|
+
stream?: string;
|
|
82
|
+
observedAt?: number;
|
|
83
|
+
}): Promise<{
|
|
84
|
+
observed: boolean;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
export interface MemoryGraph {
|
|
88
|
+
client: MemoryClient;
|
|
89
|
+
graphId?: string;
|
|
90
|
+
rootContextId?: RootContextId;
|
|
91
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function contextId(raw: string, defaultType?: string): string;
|
|
2
|
+
export declare const contextIds: (raw: string[] | undefined, defaultType?: string) => string[] | undefined;
|
|
3
|
+
export type RootContextId = string | (() => string | undefined);
|
|
4
|
+
export declare function rootOf(rootContextId: RootContextId | undefined): string | undefined;
|
|
5
|
+
export declare const fixedRoot: (rootContextId: RootContextId | undefined) => string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r="topic",f=120,c=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"");function o(e,n=r){const t=e.indexOf(":"),i=c(t<0?n:e.slice(0,t)),s=c(t<0?e:e.slice(t+1));if(!s)throw new Error(`"${e}" names no context; write it as type:name, like person:alice.`);return`${i}:${s}`.slice(0,120)}const p=(e,n)=>e?.length?e.map(t=>o(t,n)):void 0;function u(e){if(e===void 0)return;const n=typeof e=="function"?e():e;if(!n)throw new Error("No root context id is set for this run, so memory stays closed.");return o(n)}const d=e=>typeof e=="string"?o(e):void 0;export{o as contextId,p as contextIds,d as fixedRoot,u as rootOf};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type RootContextId } from "../context.js";
|
|
2
|
+
/** One piece of evidence, with where it came from. */
|
|
3
|
+
export interface RecalledFact {
|
|
4
|
+
text: string;
|
|
5
|
+
locus: string;
|
|
6
|
+
contexts: string[];
|
|
7
|
+
score: number;
|
|
8
|
+
source?: string;
|
|
9
|
+
}
|
|
10
|
+
/** What a deep recall answered, and what answering it cost. */
|
|
11
|
+
export interface RecallResult {
|
|
12
|
+
facts: RecalledFact[];
|
|
13
|
+
contexts_walked: string[];
|
|
14
|
+
summary?: string;
|
|
15
|
+
coverage: "full" | "partial";
|
|
16
|
+
fallback: boolean;
|
|
17
|
+
usage: {
|
|
18
|
+
cost_usd: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Anything that can answer a deep recall — a `LocusGraphClient`, or a test
|
|
23
|
+
* double.
|
|
24
|
+
*
|
|
25
|
+
* Declared structurally rather than imported, for the reason `prompt` declares
|
|
26
|
+
* its own `Recordable` and `llms` reads provider replies as plain objects: a
|
|
27
|
+
* type-only import still puts `@locusgraph/client` in `dependencies`, so every
|
|
28
|
+
* install of this package downloaded a client that nothing here ever loads, and
|
|
29
|
+
* every consumer's typecheck needed it resolvable to read one `.d.ts`. A real
|
|
30
|
+
* client satisfies this, which `tests/structural.test.ts` proves with the
|
|
31
|
+
* package still on hand as a devDependency.
|
|
32
|
+
*/
|
|
33
|
+
export interface Recaller {
|
|
34
|
+
deepRecall(query: {
|
|
35
|
+
question: string;
|
|
36
|
+
graphId?: string;
|
|
37
|
+
contextIds?: string[];
|
|
38
|
+
}): Promise<RecallResult>;
|
|
39
|
+
}
|
|
40
|
+
export interface DeepRecallOptions {
|
|
41
|
+
/** A `LocusGraphClient`, or anything carrying its `deepRecall`. */
|
|
42
|
+
client: Recaller;
|
|
43
|
+
/** Graph the walk runs over. Unset, the client's own default is used. */
|
|
44
|
+
graphId?: string;
|
|
45
|
+
/** Context the walk starts from, fixed or read from run state on each call. */
|
|
46
|
+
rootContextId?: RootContextId;
|
|
47
|
+
/** Longest evidence list handed back. Default 20. */
|
|
48
|
+
maxFacts?: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Your own knowledge base, answered with cited evidence.
|
|
52
|
+
*
|
|
53
|
+
* Cost comes back as micro-USD because deep recall runs model calls of its own,
|
|
54
|
+
* and that spend is invisible to whatever loop called this.
|
|
55
|
+
*/
|
|
56
|
+
export declare function deepRecall(opts: DeepRecallOptions): import("../../index.js").Tool<import("../../index.js").ArgsOf<readonly [{
|
|
57
|
+
readonly name: "question";
|
|
58
|
+
readonly type: "string";
|
|
59
|
+
readonly required: true;
|
|
60
|
+
readonly maxLength: 1000;
|
|
61
|
+
readonly description: "One focused question, not a conversation and not several at once.";
|
|
62
|
+
}, {
|
|
63
|
+
readonly name: "context_ids";
|
|
64
|
+
readonly type: "list";
|
|
65
|
+
readonly required: false;
|
|
66
|
+
readonly description: string;
|
|
67
|
+
}]>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tool as c}from"../../tool/index.js";import{rootOf as d}from"../context.js";const l=20;function h(t){const o=t.maxFacts??l;return c({name:"deep_recall",description:"Searches your own knowledge base and returns an answer with the evidence it rests on. A walker follows linked contexts, so it answers questions spread across several notes \u2014 what do we know about X, what was decided and why. Ask one focused thing. Prefer it over a web search whenever the answer could already be in your records.",effect:"readonly",needs:["recall"],args:[{name:"question",type:"string",required:!0,maxLength:1e3,description:"One focused question, not a conversation and not several at once."},{name:"context_ids",type:"list",required:!1,description:"Contexts to start the walk from, as type:name \u2014 take them from the contexts of an earlier result. A hint, not a filter; the walk may go elsewhere."}],costOf:a=>a.costMicroUsd,run:async({question:a,context_ids:r})=>{const n=d(t.rootContextId),s=n?[...new Set([n,...r??[]])]:r,e=await t.client.deepRecall({question:a,...t.graphId?{graphId:t.graphId}:{},...s?.length?{contextIds:s}:{}});return{summary:e.summary,facts:e.facts.slice(0,o),truncated:e.facts.length>o,contextsWalked:e.contexts_walked,coverage:e.coverage,fallback:e.fallback,costMicroUsd:Math.round(e.usage.cost_usd*1e6)}}})}export{h as deepRecall};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type DeepRecallOptions, deepRecall, type RecalledFact, type Recaller, type RecallResult, } from "./deep-recall.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{deepRecall as o}from"./deep-recall.js";export{o as deepRecall};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MemoryGraph } from "../client.js";
|
|
2
|
+
export interface ExploreOptions extends MemoryGraph {
|
|
3
|
+
limit?: number;
|
|
4
|
+
depth?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function exploreMemory(opts: ExploreOptions): import("../../index.js").Tool<import("../../index.js").ArgsOf<readonly [{
|
|
7
|
+
readonly name: "query";
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly required: false;
|
|
10
|
+
readonly maxLength: 200;
|
|
11
|
+
readonly description: "Part of a context name, like pric or alice. Leave out to list what is there.";
|
|
12
|
+
}, {
|
|
13
|
+
readonly name: "type";
|
|
14
|
+
readonly type: "string";
|
|
15
|
+
readonly required: false;
|
|
16
|
+
readonly maxLength: 60;
|
|
17
|
+
readonly description: "Only contexts of this type, like person or decision.";
|
|
18
|
+
}]>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{tool as f}from"../../tool/index.js";import{fixedRoot as g,rootOf as y}from"../context.js";import{drawSubgraph as w,readSubgraph as _}from"./subgraph.js";const d=20,$=3,L=t=>`${t} note${t===1?"":"s"}`,l=t=>t.length===0?"Memory is empty: no contexts yet.":`Context types: ${t.map(e=>`${e.context_type} (${e.count})`).join(", ")}.`,m=t=>t.map(e=>`- ${e.context_id} (${L(e.reference_count)})`).join(`
|
|
2
|
+
`),I=t=>{const e=new Map;for(const o of t)e.set(o.context_type,(e.get(o.context_type)??0)+1);return[...e].map(([o,r])=>({context_type:o,count:r}))},C=(t,e,o)=>t.filter(r=>!o||r.context_type===o).filter(r=>!e||r.context_id.toLowerCase().includes(e.toLowerCase())),p=t=>`No contexts match "${t}". Try a shorter stem, or no query to list the types.`;function M(t){const e=t.rootContextId!==void 0,o=g(t.rootContextId)??"your root",r=e?`Shows what is filed under ${o} and how it links up, without reading the notes themselves. With no query it lists the contexts in that subtree and their links. With a query it narrows to the contexts whose name contains it.`:"Shows what is filed in your own memory and how it links up, without reading the notes themselves. With no query it lists the context types in use, which is how to learn the filing scheme before you remember something. With a query it finds matching contexts and draws their relationships.",x=async(n,i,s)=>{const c=n.indexOf(":"),a=_(await t.client.getContextGraph({contextType:n.slice(0,c),contextName:n.slice(c+1),depth:t.depth??$,...t.graphId?{graphId:t.graphId}:{}})),h=C(a.nodes,i,s).slice(0,t.limit??d);return h.length===0?i?p(i):`Nothing is filed under ${n} yet.`:`${l(I(h))}
|
|
3
|
+
|
|
4
|
+
${w(h,a.edges)}`},u=async(n,i)=>{if(!n?.trim()){const a=await t.client.listContextTypes(t.graphId);return l(a.context_types)}const s=await t.client.searchContexts(n,t.graphId,{page_size:t.limit??d,include:"relationships",format:"mindmap",...i?{context_type:i}:{}});if(s.contexts.length===0)return p(n);const c=s.relationships_text?.trim();return c?`${m(s.contexts)}
|
|
5
|
+
|
|
6
|
+
Links:
|
|
7
|
+
${c}`:m(s.contexts)};return f({name:"explore_memory",effect:"readonly",description:r,args:[{name:"query",type:"string",required:!1,maxLength:200,description:"Part of a context name, like pric or alice. Leave out to list what is there."},{name:"type",type:"string",required:!1,maxLength:60,description:"Only contexts of this type, like person or decision."}],run:({query:n,type:i})=>{const s=y(t.rootContextId);return s?x(s,n?.trim(),i):u(n?.trim(),i)}})}export{M as exploreMemory};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MemoryContext } from "../client.js";
|
|
2
|
+
export interface SubgraphEdge {
|
|
3
|
+
from: string;
|
|
4
|
+
to: string;
|
|
5
|
+
link_type: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Subgraph {
|
|
8
|
+
nodes: MemoryContext[];
|
|
9
|
+
edges: SubgraphEdge[];
|
|
10
|
+
}
|
|
11
|
+
export declare function readSubgraph(raw: unknown): Subgraph;
|
|
12
|
+
export declare const drawSubgraph: (nodes: MemoryContext[], edges: SubgraphEdge[]) => string;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const c=t=>typeof t=="object"&&t!==null,o=t=>typeof t=="string"?t:"",s=t=>{if(!c(t)||typeof t.context_id!="string")return null;const n=t.context_id.indexOf(":");return{context_id:t.context_id,context_type:o(t.context_type)||t.context_id.slice(0,n),context_name:o(t.context_name)||t.context_id.slice(n+1),reference_count:typeof t.reference_count=="number"?t.reference_count:0}},d=t=>{if(!c(t))return null;const n=o(t.from)||o(t.from_context_id),e=o(t.to)||o(t.to_context_id);return n&&e?{from:n,to:e,link_type:o(t.link_type)||"related_to"}:null};function p(t){const n=c(t)&&c(t.graph)?t.graph:t;if(!c(n))return{nodes:[],edges:[]};const e=Array.isArray(n.nodes)?n.nodes.map(s):[],i=Array.isArray(n.edges)?n.edges.map(d):[];return{nodes:e.filter(r=>r!==null),edges:i.filter(r=>r!==null)}}const _={extends:"extended_by",reinforces:"reinforced_by",contradicts:"contradicted_by",related_to:"related_to"},f=(t,n)=>[...n.filter(e=>e.from===t).map(e=>`${e.link_type} \u2192 ${e.to}`),...n.filter(e=>e.to===t).map(e=>`${_[e.link_type]??e.link_type} \u2190 ${e.from}`)],l=t=>t.map((n,e)=>` ${e===t.length-1?"\u2514\u2500":"\u251C\u2500"} ${n}`),x=(t,n)=>t.map(e=>[e.context_id,...l(f(e.context_id,n))].join(`
|
|
2
|
+
`)).join(`
|
|
3
|
+
`);export{x as drawSubgraph,p as readSubgraph};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Tool } from "../types/index.js";
|
|
2
|
+
import type { MemoryClient, MemorySource } from "./client.js";
|
|
3
|
+
import type { RootContextId } from "./context.js";
|
|
4
|
+
import { type Observer } from "./observe/observe.js";
|
|
5
|
+
import { type RecallFormat } from "./recall/recall.js";
|
|
6
|
+
export type { MemoryClient, MemoryContext, MemoryGraph, MemoryKind, MemorySource, MomentSource, } from "./client.js";
|
|
7
|
+
export { contextId, type RootContextId } from "./context.js";
|
|
8
|
+
export { type DeepRecallOptions, deepRecall, type RecalledFact, type Recaller, type RecallResult, } from "./deep-recall/index.js";
|
|
9
|
+
export { type ExploreOptions, exploreMemory } from "./explore/explore.js";
|
|
10
|
+
export { type Moment, type Observer, type ObserverOptions, observer, } from "./observe/observe.js";
|
|
11
|
+
export { type RecallFormat, type RecallOptions, recall } from "./recall/recall.js";
|
|
12
|
+
export { type RememberOptions, remember } from "./remember/remember.js";
|
|
13
|
+
export interface MemoriesOptions {
|
|
14
|
+
client: MemoryClient;
|
|
15
|
+
graphId?: string;
|
|
16
|
+
rootContextId?: RootContextId;
|
|
17
|
+
source?: MemorySource;
|
|
18
|
+
defaultContextType?: string;
|
|
19
|
+
recallFormat?: RecallFormat;
|
|
20
|
+
recallLimit?: number;
|
|
21
|
+
/** Let `recall` say which notes a later one superseded. See `RecallOptions`. */
|
|
22
|
+
supersede?: boolean;
|
|
23
|
+
stream?: string;
|
|
24
|
+
maxFacts?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface MemorySet {
|
|
27
|
+
tools: Tool<never>[];
|
|
28
|
+
observe: Observer;
|
|
29
|
+
}
|
|
30
|
+
export declare function memories(opts: MemoriesOptions): MemorySet;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{deepRecall as a}from"./deep-recall/index.js";import{exploreMemory as l}from"./explore/explore.js";import{observer as c}from"./observe/observe.js";import{recall as n}from"./recall/recall.js";import{remember as x}from"./remember/remember.js";import{contextId as C}from"./context.js";import{deepRecall as g}from"./deep-recall/index.js";import{exploreMemory as v}from"./explore/explore.js";import{observer as T}from"./observe/observe.js";import{recall as R}from"./recall/recall.js";import{remember as j}from"./remember/remember.js";function s(e){const r={client:e.client,...e.graphId?{graphId:e.graphId}:{},...e.rootContextId!==void 0?{rootContextId:e.rootContextId}:{}},o=e.defaultContextType,t=[n({...r,format:e.recallFormat,limit:e.recallLimit,...e.supersede?{supersede:!0}:{},defaultContextType:o}),a({...r,maxFacts:e.maxFacts}),x({...r,source:e.source,defaultContextType:o}),l(r)],m=c({...r,stream:e.stream});return{tools:t,observe:m}}export{C as contextId,g as deepRecall,v as exploreMemory,s as memories,T as observer,R as recall,j as remember};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MemoryGraph, MomentSource } from "../client.js";
|
|
2
|
+
export type Moment = string | Record<string, unknown>;
|
|
3
|
+
export type Observer = (moment: Moment, source?: MomentSource) => Promise<boolean>;
|
|
4
|
+
export interface ObserverOptions extends MemoryGraph {
|
|
5
|
+
stream?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function observer(opts: ObserverOptions): Observer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t="turn";function c(r){return async(e,a=t)=>{const{observed:n}=await r.client.observe({source:a,payload:e,...r.graphId?{graphId:r.graphId}:{},...r.stream?{stream:r.stream}:{}});return n}}export{c as observer};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { MemoryGraph } from "../client.js";
|
|
2
|
+
import { type RecallFormat } from "./render.js";
|
|
3
|
+
export type { RecallFormat } from "./render.js";
|
|
4
|
+
export interface RecallOptions extends MemoryGraph {
|
|
5
|
+
format?: RecallFormat;
|
|
6
|
+
limit?: number;
|
|
7
|
+
sources?: string[];
|
|
8
|
+
defaultContextType?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Say which notes a later one superseded, rather than returning both flat.
|
|
11
|
+
*
|
|
12
|
+
* `remember` takes a `contradicts` link, and without this nothing downstream
|
|
13
|
+
* ever reads it: a recall hands back the old plan and the new plan as two
|
|
14
|
+
* rows in score order, and the model answers with whichever scored higher.
|
|
15
|
+
* The graph knew which one won; the answer did not.
|
|
16
|
+
*
|
|
17
|
+
* Off by default because it costs a second read — the subtree under
|
|
18
|
+
* `rootContextId` — on every recall, and because it needs that root to have
|
|
19
|
+
* a subtree to read. Without a root there is nothing to fetch and the column
|
|
20
|
+
* is left off rather than filled with blanks.
|
|
21
|
+
*/
|
|
22
|
+
supersede?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function recall(opts: RecallOptions): import("../../index.js").Tool<import("../../index.js").ArgsOf<readonly [{
|
|
25
|
+
readonly name: "question";
|
|
26
|
+
readonly type: "string";
|
|
27
|
+
readonly required: true;
|
|
28
|
+
readonly maxLength: 1000;
|
|
29
|
+
readonly description: "What you want to know, in a sentence.";
|
|
30
|
+
}, {
|
|
31
|
+
readonly name: "context_ids";
|
|
32
|
+
readonly type: "list";
|
|
33
|
+
readonly required: false;
|
|
34
|
+
readonly description: string;
|
|
35
|
+
}, {
|
|
36
|
+
readonly name: "limit";
|
|
37
|
+
readonly type: "number";
|
|
38
|
+
readonly required: false;
|
|
39
|
+
readonly min: 1;
|
|
40
|
+
readonly max: 50;
|
|
41
|
+
readonly description: `Most notes to return. Default ${number}.`;
|
|
42
|
+
}]>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tool as f}from"../../tool/index.js";import{contextIds as l,fixedRoot as h,rootOf as p}from"../context.js";import{readSubgraph as x}from"../explore/subgraph.js";import{rendered as y}from"./render.js";const g="toon",u=10,w=50,I=3;async function T(e,n){if(!e.supersede||!n)return;const o=n.indexOf(":"),s=x(await e.client.getContextGraph({contextType:n.slice(0,o),contextName:n.slice(o+1),depth:I,...e.graphId?{graphId:e.graphId}:{}})),a=new Map;for(const r of s.edges)r.link_type==="contradicts"&&a.set(r.to,r.from);return r=>r.context_ids.map(t=>a.get(t)).find(t=>t!==void 0)}function k(e){const n=e.rootContextId!==void 0,o=h(e.rootContextId)??"your root";return f({name:"recall",effect:"readonly",description:"Searches your own memory for what was recorded about something and returns the matching notes, one per row with the contexts each is filed under. Cheap, so try it before a web search and before deep_recall. Use deep_recall instead when the answer is spread across several notes or needs a why. Ask one focused thing.",args:[{name:"question",type:"string",required:!0,maxLength:1e3,description:"What you want to know, in a sentence."},{name:"context_ids",type:"list",required:!1,description:n?`Contexts under ${o} to favour, as type:name. Take them from an earlier result or from explore_memory.`:"Only search these contexts, as type:name. Take them from an earlier result or from explore_memory."},{name:"limit",type:"number",required:!1,min:1,max:w,description:`Most notes to return. Default ${e.limit??u}.`}],run:async({question:s,context_ids:a,limit:r})=>{const t=p(e.rootContextId),i=l(a,e.defaultContextType),d=t?[t]:i,c=t&&i?i:void 0,m=(await e.client.retrieveMemories({query:s,limit:r??e.limit??u,format:"json",...e.graphId?{graphId:e.graphId}:{},...d?{contextIds:d}:{},...c?{boostContextIds:c}:{},...e.sources?.length?{sources:e.sources}:{}})).items??[];return m.length===0?"Nothing recorded about that.":y(m,e.format??g,await T(e,t))}})}export{k as recall};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RecalledItem } from "../client.js";
|
|
2
|
+
export type RecallFormat = "toon" | "markdown";
|
|
3
|
+
/** Which context superseded this note's, when one did. */
|
|
4
|
+
export type Superseded = (item: RecalledItem) => string | undefined;
|
|
5
|
+
export declare const rendered: (items: RecalledItem[], format: RecallFormat, by?: Superseded) => string;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const t=/[,:"\n\\]|^\s|\s$|^$/,d=n=>t.test(n)?`"${n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n")}"`:n,c=n=>String(Math.round(n*100)),$=(n,o,e)=>[n.context_ids.join(";"),n.text,n.source??"",c(n.score),...e?[o??""]:[]],a=(n,o)=>{const e=o?"contexts,text,source,relevance,superseded_by":"contexts,text,source,relevance";return[`memories[${n.length}]{${e}}:`,...n.map(s=>` ${$(s,o?.(s),o!==void 0).map(d).join(",")}`)].join(`
|
|
2
|
+
`)},p=(n,o)=>n.map(e=>{const s=o?.(e),r=s?` \u2014 superseded by ${s}`:"";return`- [${e.context_ids.join(", ")}] ${e.text} (${e.source??"unknown"}, ${c(e.score)}%)${r}`}).join(`
|
|
3
|
+
`),u=(n,o,e)=>o==="toon"?a(n,e):p(n,e);export{u as rendered};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { MemoryGraph, MemorySource } from "../client.js";
|
|
2
|
+
export interface RememberOptions extends MemoryGraph {
|
|
3
|
+
source?: MemorySource;
|
|
4
|
+
defaultContextType?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function remember(opts: RememberOptions): import("../../index.js").Tool<import("../../index.js").ArgsOf<readonly [{
|
|
7
|
+
readonly name: "context";
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly required: true;
|
|
10
|
+
readonly maxLength: 200;
|
|
11
|
+
readonly description: "Where it is filed, as type:name.";
|
|
12
|
+
}, {
|
|
13
|
+
readonly name: "text";
|
|
14
|
+
readonly type: "string";
|
|
15
|
+
readonly required: true;
|
|
16
|
+
readonly maxLength: 4000;
|
|
17
|
+
readonly description: "The thing to remember, as a complete sentence or two.";
|
|
18
|
+
}, {
|
|
19
|
+
readonly name: "kind";
|
|
20
|
+
readonly type: "enum";
|
|
21
|
+
readonly required: false;
|
|
22
|
+
readonly options: readonly ["fact", "decision", "constraint", "feedback", "observation"];
|
|
23
|
+
readonly description: "What sort of thing it is. Default fact.";
|
|
24
|
+
}, {
|
|
25
|
+
readonly name: "details";
|
|
26
|
+
readonly type: "json";
|
|
27
|
+
readonly required: false;
|
|
28
|
+
readonly description: string;
|
|
29
|
+
}, {
|
|
30
|
+
readonly name: "extends";
|
|
31
|
+
readonly type: "list";
|
|
32
|
+
readonly required: false;
|
|
33
|
+
readonly description: "Contexts this is a more specific detail of, as type:name.";
|
|
34
|
+
}, {
|
|
35
|
+
readonly name: "related_to";
|
|
36
|
+
readonly type: "list";
|
|
37
|
+
readonly required: false;
|
|
38
|
+
readonly description: "Contexts this sits alongside, as type:name.";
|
|
39
|
+
}, {
|
|
40
|
+
readonly name: "reinforces";
|
|
41
|
+
readonly type: "list";
|
|
42
|
+
readonly required: false;
|
|
43
|
+
readonly description: "Contexts this backs up with more evidence, as type:name.";
|
|
44
|
+
}, {
|
|
45
|
+
readonly name: "contradicts";
|
|
46
|
+
readonly type: "list";
|
|
47
|
+
readonly required: false;
|
|
48
|
+
readonly description: "Contexts this supersedes, as type:name.";
|
|
49
|
+
}]>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tool as h}from"../../tool/index.js";import{contextId as y,contextIds as a,fixedRoot as x,rootOf as w}from"../context.js";const g=["fact","decision","constraint","feedback","observation"],b="assistant",C=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),q=(e,t)=>{if(t==null)return{data:e};if(!C(t))throw new Error("details must be a JSON object of named fields.");return{...t,data:e}},d=(e,t)=>t?.length?{[e]:t}:{};function v(e){const t=e.defaultContextType,u=e.rootContextId===void 0?"":` under ${x(e.rootContextId)??"your root"}`,m=(c,l)=>{const s=w(e.rootContextId),i=a(l,t)??[],r=s?[s,...i]:i;return[...new Set(r)].filter(n=>n!==c)};return h({name:"remember",effect:"idempotent",description:`Records one thing in your own memory${u} so a later run can recall it. File it under a context named type:name, like person:alice or decision:pricing_tier, reusing a name from explore_memory when one fits. One fact per call; the text should stand on its own without the conversation around it.`,args:[{name:"context",type:"string",required:!0,maxLength:200,description:"Where it is filed, as type:name."},{name:"text",type:"string",required:!0,maxLength:4e3,description:"The thing to remember, as a complete sentence or two."},{name:"kind",type:"enum",required:!1,options:g,description:"What sort of thing it is. Default fact."},{name:"details",type:"json",required:!1,description:"Structured fields worth keeping with the note, as a JSON object: amounts, dates, ids, URLs. The text is still what a recall shows; these ride along with it."},{name:"extends",type:"list",required:!1,description:"Contexts this is a more specific detail of, as type:name."},{name:"related_to",type:"list",required:!1,description:"Contexts this sits alongside, as type:name."},{name:"reinforces",type:"list",required:!1,description:"Contexts this backs up with more evidence, as type:name."},{name:"contradicts",type:"list",required:!1,description:"Contexts this supersedes, as type:name."}],run:async({context:c,text:l,kind:s="fact",details:i,...r})=>{const n=y(c,t),f={event_kind:s,context_id:n,source:e.source??b,payload:q(l,i),...d("extends",m(n,r.extends)),...d("related_to",a(r.related_to,t)),...d("reinforces",a(r.reinforces,t)),...d("contradicts",a(r.contradicts,t))},p=await e.client.storeEventsBatch([f],e.graphId),[o]=p.results;if(!o||o.status==="error")throw new Error(o?.error??"The memory was not stored, and the server did not say why.");return o.status==="filtered"?{stored:!1,context:n,reason:o.error??"judged not worth keeping"}:{stored:!0,context:n,relevance:o.relevance}}})}export{v as remember};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { Recency, SearchAsk, SearchDepth, Searched, Searcher, SearcherOptions, SearchUsage, Source, } from "./search.js";
|
|
2
|
+
export { DEPTHS, NO_TOKENS } from "./search.js";
|
|
3
|
+
export { type SearxngOptions, searxng, textOf } from "./searxng/index.js";
|
|
4
|
+
export { type TavilyOptions, tavily } from "./tavily/index.js";
|
|
5
|
+
export { readReply, type SonarOptions, sonar } from "./sonar/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DEPTHS as e,NO_TOKENS as t}from"./search.js";import{searxng as f,textOf as p}from"./searxng/index.js";import{tavily as m}from"./tavily/index.js";import{readReply as l,sonar as n}from"./sonar/index.js";export{e as DEPTHS,t as NO_TOKENS,l as readReply,f as searxng,n as sonar,m as tavily,p as textOf};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SearcherOptions } from "./search.js";
|
|
2
|
+
/**
|
|
3
|
+
* Sends again while the answer is a 429 or a 5xx and tries remain, then hands
|
|
4
|
+
* back whatever came last, ok or not, for the caller to read or refuse.
|
|
5
|
+
*/
|
|
6
|
+
export declare function retrying(opts: Pick<SearcherOptions, "attempts" | "sleep" | "random">): (send: () => Promise<Response>) => Promise<Response>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const M=500,f=8e3;function m(t){const r=t.headers.get("retry-after");if(!r)return null;const e=Number(r);return Number.isFinite(e)&&e>=0?e*1e3:null}const u=t=>t===429||t>=500;function A(t){const r=Math.max(1,t.attempts??3),e=t.sleep??(o=>new Promise(n=>setTimeout(n,o))),c=t.random??Math.random;return async o=>{for(let n=1;;n++){const s=await o();if(s.ok||!u(s.status)||n===r)return s;const a=Math.min(8e3,500*2**(n-1)),i=m(s)??a;await e(i+a*c())}}}export{A as retrying};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** How much searching one call is worth. */
|
|
2
|
+
export type SearchDepth = "quick" | "pro" | "deep";
|
|
3
|
+
export declare const DEPTHS: readonly SearchDepth[];
|
|
4
|
+
export type Recency = "day" | "week" | "month" | "year";
|
|
5
|
+
export interface Source {
|
|
6
|
+
url: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
date?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SearchUsage {
|
|
11
|
+
inputTokens: number;
|
|
12
|
+
outputTokens: number;
|
|
13
|
+
citationTokens: number;
|
|
14
|
+
reasoningTokens: number;
|
|
15
|
+
searchQueries: number;
|
|
16
|
+
}
|
|
17
|
+
/** What every searcher hands back, whoever did the searching. */
|
|
18
|
+
export interface Searched {
|
|
19
|
+
answer: string;
|
|
20
|
+
results: Source[];
|
|
21
|
+
model: string;
|
|
22
|
+
truncated: boolean;
|
|
23
|
+
usage: SearchUsage;
|
|
24
|
+
}
|
|
25
|
+
export interface SearchAsk {
|
|
26
|
+
query: string;
|
|
27
|
+
depth: SearchDepth;
|
|
28
|
+
recency?: Recency;
|
|
29
|
+
}
|
|
30
|
+
export type Searcher = ((ask: SearchAsk) => Promise<Searched>) & {
|
|
31
|
+
domains?: readonly string[];
|
|
32
|
+
};
|
|
33
|
+
/** What every searcher is configured with; each adds only where its answers come from. */
|
|
34
|
+
export interface SearcherOptions {
|
|
35
|
+
/** Hosts results are restricted to. Set here, so the model cannot widen it. */
|
|
36
|
+
domains?: string[];
|
|
37
|
+
/** Give up on a request after this. */
|
|
38
|
+
timeoutMs?: number;
|
|
39
|
+
/** Longest answer handed back. Default 20000 characters. */
|
|
40
|
+
maxChars?: number;
|
|
41
|
+
/** Longest source list handed back. Default 20. */
|
|
42
|
+
maxResults?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Tries for a rate limit or a bad minute on the other side. Default 3.
|
|
45
|
+
*
|
|
46
|
+
* A wave of sub-questions searches in parallel, so two calls landing together
|
|
47
|
+
* is ordinary and a 429 on the second is not a failure worth surfacing — it
|
|
48
|
+
* is a wait. `retry-after` is honoured where the server sends one, and the
|
|
49
|
+
* wait is spread by up to one backoff on top: a whole wave limited at the
|
|
50
|
+
* same instant computes the same delay, and retrying in step rebuilds the
|
|
51
|
+
* burst that caused it.
|
|
52
|
+
*/
|
|
53
|
+
attempts?: number;
|
|
54
|
+
/** Injected for tests. */
|
|
55
|
+
fetch?: typeof fetch;
|
|
56
|
+
/** Injected for tests. */
|
|
57
|
+
sleep?: (ms: number) => Promise<void>;
|
|
58
|
+
/** Injected for tests. Returns 0 to 1, and spreads a retried wave apart. */
|
|
59
|
+
random?: () => number;
|
|
60
|
+
}
|
|
61
|
+
export declare const DEFAULT_MAX_CHARS = 20000;
|
|
62
|
+
export declare const DEFAULT_MAX_RESULTS = 20;
|
|
63
|
+
export declare const NO_TOKENS: SearchUsage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=["quick","pro","deep"],e=2e4,t=20,n={inputTokens:0,outputTokens:0,citationTokens:0,reasoningTokens:0,searchQueries:1};export{e as DEFAULT_MAX_CHARS,t as DEFAULT_MAX_RESULTS,o as DEPTHS,n as NO_TOKENS};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{searxng as o}from"./searxng.js";import{textOf as x}from"./text.js";export{o as searxng,x as textOf};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type SearchDepth, type Searcher, type SearcherOptions } from "../search.js";
|
|
2
|
+
export interface SearxngOptions extends SearcherOptions {
|
|
3
|
+
/** The SearXNG instance, such as http://localhost:8080. Required. */
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
/** Pin which engines answer. Default: whatever the instance runs. */
|
|
6
|
+
engines?: string[];
|
|
7
|
+
/** Pin the language. Default: the instance's own. */
|
|
8
|
+
language?: string;
|
|
9
|
+
/** Text kept from each page read. Default 6000 characters. */
|
|
10
|
+
pageChars?: number;
|
|
11
|
+
/** Pages read at each depth. Default 5, 8 and 10. */
|
|
12
|
+
pages?: Partial<Record<SearchDepth, number>>;
|
|
13
|
+
}
|
|
14
|
+
export declare function searxng(opts: SearxngOptions): Searcher;
|