@owlmeans/agent 0.1.18-rc.47 → 0.1.18-rc.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/agent/SKILL.md +9 -9
- package/build/helpers/compaction/types.d.ts +49 -0
- package/build/helpers/compaction/types.d.ts.map +1 -0
- package/build/helpers/compaction/types.js.map +1 -0
- package/build/helpers/compaction.d.ts +6 -20
- package/build/helpers/compaction.d.ts.map +1 -1
- package/build/helpers/compaction.js +72 -81
- package/build/helpers/compaction.js.map +1 -1
- package/build/helpers/index.d.ts +3 -1
- package/build/helpers/index.d.ts.map +1 -1
- package/build/helpers/index.js.map +1 -1
- package/build/helpers/rolling/types.d.ts +16 -0
- package/build/helpers/rolling/types.d.ts.map +1 -0
- package/build/helpers/rolling/types.js +2 -0
- package/build/helpers/rolling/types.js.map +1 -0
- package/build/helpers/rolling.d.ts +1 -1
- package/build/helpers/rolling.d.ts.map +1 -1
- package/build/helpers/tools/types.d.ts +38 -0
- package/build/helpers/tools/types.d.ts.map +1 -0
- package/build/helpers/tools/types.js +2 -0
- package/build/helpers/{types.js.map → tools/types.js.map} +1 -1
- package/build/helpers/tools.d.ts +6 -26
- package/build/helpers/tools.d.ts.map +1 -1
- package/build/helpers/tools.js +27 -42
- package/build/helpers/tools.js.map +1 -1
- package/build/model.d.ts.map +1 -1
- package/build/model.js +4 -4
- package/build/model.js.map +1 -1
- package/build/pipeline/index.d.ts +2 -1
- package/build/pipeline/index.d.ts.map +1 -1
- package/build/pipeline/results/types.d.ts +139 -0
- package/build/pipeline/results/types.d.ts.map +1 -0
- package/build/pipeline/results/types.js +2 -0
- package/build/pipeline/results/types.js.map +1 -0
- package/build/pipeline/{types.local.d.ts → results/types.local.d.ts} +0 -18
- package/build/pipeline/results/types.local.d.ts.map +1 -0
- package/build/pipeline/results/types.local.js.map +1 -0
- package/build/pipeline/results.d.ts +2 -1
- package/build/pipeline/results.d.ts.map +1 -1
- package/build/pipeline/results.js +22 -22
- package/build/pipeline/results.js.map +1 -1
- package/build/pipeline/runner/types.d.ts +293 -0
- package/build/pipeline/runner/types.d.ts.map +1 -0
- package/build/pipeline/runner/types.js +2 -0
- package/build/pipeline/runner/types.js.map +1 -0
- package/build/pipeline/runner/types.local.d.ts +19 -0
- package/build/pipeline/runner/types.local.d.ts.map +1 -0
- package/build/pipeline/runner/types.local.js +2 -0
- package/build/pipeline/runner/types.local.js.map +1 -0
- package/build/pipeline/runner.d.ts +1 -1
- package/build/pipeline/runner.d.ts.map +1 -1
- package/build/pipeline/runner.js +10 -9
- package/build/pipeline/runner.js.map +1 -1
- package/build/pipeline/types.d.ts +2 -93
- package/build/pipeline/types.d.ts.map +1 -1
- package/build/plugins/export.d.ts +2 -2
- package/build/plugins/export.d.ts.map +1 -1
- package/build/plugins/export.js +2 -2
- package/build/plugins/export.js.map +1 -1
- package/build/plugins/inquiry.d.ts.map +1 -1
- package/build/plugins/inquiry.js +4 -4
- package/build/plugins/inquiry.js.map +1 -1
- package/build/plugins/memory-events.d.ts +3 -1
- package/build/plugins/memory-events.d.ts.map +1 -1
- package/build/plugins/memory-events.js +4 -2
- package/build/plugins/memory-events.js.map +1 -1
- package/build/plugins/memory-graph.d.ts +5 -1
- package/build/plugins/memory-graph.d.ts.map +1 -1
- package/build/plugins/memory-graph.js +4 -2
- package/build/plugins/memory-graph.js.map +1 -1
- package/build/plugins/summarize.d.ts.map +1 -1
- package/build/plugins/summarize.js +2 -2
- package/build/plugins/summarize.js.map +1 -1
- package/build/types.d.ts +5 -3
- package/build/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/helpers/compaction/types.ts +51 -0
- package/src/helpers/compaction.ts +98 -101
- package/src/helpers/index.ts +3 -1
- package/src/helpers/rolling/types.ts +16 -0
- package/src/helpers/rolling.ts +1 -1
- package/src/helpers/tools/types.ts +37 -0
- package/src/helpers/tools.ts +39 -47
- package/src/model.ts +4 -4
- package/src/pipeline/index.ts +2 -1
- package/src/pipeline/{types.local.ts → results/types.local.ts} +0 -21
- package/src/pipeline/results/types.ts +152 -0
- package/src/pipeline/results.ts +25 -24
- package/src/pipeline/runner/types.local.ts +21 -0
- package/src/pipeline/{types.ts → runner/types.ts} +4 -156
- package/src/pipeline/runner.ts +14 -12
- package/src/plugins/export.ts +2 -2
- package/src/plugins/inquiry.ts +4 -4
- package/src/plugins/memory-events.ts +8 -2
- package/src/plugins/memory-graph.ts +8 -2
- package/src/plugins/summarize.ts +2 -2
- package/src/types.ts +4 -4
- package/tests/inquiry.spec.ts +14 -15
- package/tests/pipeline-inquiry.spec.ts +3 -3
- package/tests/plugins.spec.ts +10 -10
- package/tests/summary.spec.ts +8 -8
- package/tests/tools.spec.ts +11 -11
- package/build/helpers/types.d.ts +0 -42
- package/build/helpers/types.d.ts.map +0 -1
- package/build/pipeline/types.local.d.ts.map +0 -1
- package/build/pipeline/types.local.js.map +0 -1
- package/src/helpers/types.ts +0 -43
- /package/build/helpers/{types.js → compaction/types.js} +0 -0
- /package/build/pipeline/{types.local.js → results/types.local.js} +0 -0
package/README.md
CHANGED
|
@@ -40,8 +40,8 @@ const agent = context.agents().agent({ exec, tools })
|
|
|
40
40
|
| `memoryGraphPlugin` | Durable notes filed by subsystem, with links — index injected, content pulled by tool |
|
|
41
41
|
| `memoryEventsPlugin` | A bounded, ordered record of what happened |
|
|
42
42
|
|
|
43
|
-
Both memory plugins also export a plain API (`
|
|
44
|
-
all, so a pipeline helper writes to the same store an agent reads.
|
|
43
|
+
Both memory plugins also export a plain API (`makeMemoryGraphApi`, `makeMemoryEventsApi`) usable
|
|
44
|
+
with no agent at all, so a pipeline helper writes to the same store an agent reads.
|
|
45
45
|
|
|
46
46
|
## Things worth knowing before you change it
|
|
47
47
|
|
|
@@ -49,7 +49,7 @@ all, so a pipeline helper writes to the same store an agent reads.
|
|
|
49
49
|
provider will not put a cache breakpoint on. Volatile material anywhere above it invalidates the
|
|
50
50
|
prefix that every call sharing a persona pays for.
|
|
51
51
|
|
|
52
|
-
**`safeInvokeTool` must never throw.** A rejected LangGraph task aborts the whole superstep: every
|
|
52
|
+
**`toolHelper.safeInvokeTool` must never throw.** A rejected LangGraph task aborts the whole superstep: every
|
|
53
53
|
sibling tool call in the same parallel batch dies with it, discarding work they had already
|
|
54
54
|
finished. A tool failure comes back as `{ error }` the model can read and correct.
|
|
55
55
|
|
|
@@ -84,7 +84,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
84
84
|
your project's skill store (`.agents/skills/`):
|
|
85
85
|
|
|
86
86
|
```sh
|
|
87
|
-
npx @owlmeans/agent-skills@^0.1.18-rc.
|
|
87
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.51
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/agent",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-10-
|
|
4
|
+
"version": "0.1.18-rc.49",
|
|
5
|
+
"generatedAt": "2026-10-06T11:45:57.670Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: agent
|
|
3
|
-
description: How to use @owlmeans/agent — context-aware LLM agents over the LangGraph functional API, and resumable PIPELINES over a checkpointed StateGraph, with the AgentPlugin and PipelinePlugin seams, CUMULATIVE PIPELINE RESULTS (cumulativeResultsPlugin), conversation-summarization and memory plugins, and storage-independent ports. Auto-invoked when importing makeAgentModel, makePipeline, makeCheckpointSaver, appendAgentsService, an agent or pipeline plugin, cumulativeResultsPlugin,
|
|
3
|
+
description: How to use @owlmeans/agent — context-aware LLM agents over the LangGraph functional API, and resumable PIPELINES over a checkpointed StateGraph, with the AgentPlugin and PipelinePlugin seams, CUMULATIVE PIPELINE RESULTS (cumulativeResultsPlugin), conversation-summarization and memory plugins, and storage-independent ports. Auto-invoked when importing makeAgentModel, makePipeline, makeCheckpointSaver, appendAgentsService, an agent or pipeline plugin, cumulativeResultsPlugin, toolHelper, or an agent store.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
@@ -8,7 +8,7 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/agent
|
|
9
9
|
|
|
10
10
|
**Layer:** Cross-cutting domain
|
|
11
|
-
**Install:** `"@owlmeans/agent": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/agent": "^0.1.18-rc.49"` in `dependencies`, plus the `@langchain/core` and
|
|
12
12
|
`@langchain/langgraph` **peers**
|
|
13
13
|
|
|
14
14
|
The agent runtime. Contracts live in `@owlmeans/agent-common`.
|
|
@@ -24,10 +24,10 @@ The agent runtime. Contracts live in `@owlmeans/agent-common`.
|
|
|
24
24
|
| `makeCheckpointSaver(store)` | A `BaseCheckpointSaver` over the `CheckpointStore` port. |
|
|
25
25
|
| `makeAgentsService(options?, alias?)` · `appendAgentsService(ctx, options?, alias?)` · `agentServiceApi(options, self)` | The service, and its half without `createService` for composition. |
|
|
26
26
|
| `summarizePlugin(options?)` | Compacts each finished run into `summary` + `advice`; replays the last few. |
|
|
27
|
-
| `memoryGraphPlugin(options?)` · `
|
|
28
|
-
| `memoryEventsPlugin(options?)` · `
|
|
29
|
-
| `safeInvokeTool
|
|
30
|
-
| `composeCompaction
|
|
27
|
+
| `memoryGraphPlugin(options?)` · `makeMemoryGraphApi(store, options?)` | Durable notes filed by subsystem, with links. Plugin **and** plain API. |
|
|
28
|
+
| `memoryEventsPlugin(options?)` · `makeMemoryEventsApi(store, options?)` | A bounded, ordered record of what happened. |
|
|
29
|
+
| `toolHelper.{safeInvokeTool, toErrorResponse, isToolError}` | The never-throwing tool contract. |
|
|
30
|
+
| `compactionHelper.{composeCompaction, renderTranscript, messageText}`, `composeRollingSummary` | Summary primitives; both composers are total. |
|
|
31
31
|
| `makeStaticFlowProvider(flows)` | The server-side `FlowProvider` `@owlmeans/flow` does not ship. |
|
|
32
32
|
| `inProcessTransport()`, `AgentTransport` | The scaling seam; default carries messages by direct call. |
|
|
33
33
|
| `createMemory*Store()` | In-memory reference implementations of every port, including `createMemoryPipelineRunStore`, `createMemoryCheckpointStore` and `createMemoryCumulativeResultStore`. |
|
|
@@ -183,7 +183,7 @@ that every call sharing a persona pays for.
|
|
|
183
183
|
model keeps calling tools without ever answering — so catch that error by name rather than treating
|
|
184
184
|
every failed run alike: it says the loop ran out of room, not that a tool or the model failed.
|
|
185
185
|
|
|
186
|
-
**`safeInvokeTool` must never throw.** The loop wraps it in a LangGraph `task`, and a rejected task
|
|
186
|
+
**`toolHelper.safeInvokeTool` must never throw.** The loop wraps it in a LangGraph `task`, and a rejected task
|
|
187
187
|
aborts the whole superstep: every sibling tool call in the same parallel batch dies with AbortError
|
|
188
188
|
and the run ends on "Multiple errors occurred during superstep 0", discarding work the others had
|
|
189
189
|
already finished. A tool failure comes back as `{ error }` the model can read and correct — most are
|
|
@@ -219,7 +219,7 @@ is streamed to the client, so without it the summary of a run types itself out i
|
|
|
219
219
|
that run, immediately after it finished.
|
|
220
220
|
|
|
221
221
|
**Character caps are applied after the model answers, never asked for in the prompt alone.** A cap in
|
|
222
|
-
a prompt is a request. Both composers (`composeCompaction`, `composeRollingSummary`) are total: with
|
|
222
|
+
a prompt is a request. Both composers (`compactionHelper.composeCompaction`, `composeRollingSummary`) are total: with
|
|
223
223
|
no model, a failing model or an empty answer they fall back deterministically, so a caller can record
|
|
224
224
|
history unconditionally. A failed fold costs detail, never the event.
|
|
225
225
|
|
|
@@ -272,7 +272,7 @@ refuses to re-enter a completed one without `force`.
|
|
|
272
272
|
effects already applied to the world: re-entering a turn re-applies them. What IS resumable is a
|
|
273
273
|
pipeline — and an agent run belongs inside one of its steps.
|
|
274
274
|
|
|
275
|
-
**`safeInvokeTool(tools, call, fatal?)` takes a fatal predicate.** Containment is right for a bad
|
|
275
|
+
**`toolHelper.safeInvokeTool(tools, call, fatal?)` takes a fatal predicate.** Containment is right for a bad
|
|
276
276
|
argument and wrong for an exhausted budget: a tool may be a whole pipeline behind one call, and
|
|
277
277
|
handing the model a readable "out of tokens" is an invitation to pick another tool and spend again.
|
|
278
278
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { LlmModel } from '@owlmeans/llm';
|
|
2
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
3
|
+
import { AgentRunStatus } from '@owlmeans/agent-common';
|
|
4
|
+
export interface Compaction {
|
|
5
|
+
summary: string;
|
|
6
|
+
advice?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CompactionInput {
|
|
9
|
+
/** Omit to skip the model entirely and take the deterministic path. */
|
|
10
|
+
model?: LlmModel;
|
|
11
|
+
/** The ask that opened the run. */
|
|
12
|
+
prompt: string;
|
|
13
|
+
messages: readonly BaseMessage[];
|
|
14
|
+
status: AgentRunStatus;
|
|
15
|
+
/** What happened after the loop — a validation verdict, a build result. */
|
|
16
|
+
note?: string;
|
|
17
|
+
maxSummaryChars?: number;
|
|
18
|
+
maxAdviceChars?: number;
|
|
19
|
+
/** LangChain `runName`. Give it a value the application filters, or the summary of a run streams into the user's view of that run. */
|
|
20
|
+
action?: string;
|
|
21
|
+
/** How much of the transcript to show the model. */
|
|
22
|
+
maxTranscriptChars?: number;
|
|
23
|
+
}
|
|
24
|
+
/** The handover between two runs on one subject: a summary and the advice that carries intent. */
|
|
25
|
+
export interface CompactionHelper {
|
|
26
|
+
/** The text of a message, whatever content shape it arrived in. */
|
|
27
|
+
messageText: (message: BaseMessage) => string;
|
|
28
|
+
/**
|
|
29
|
+
* A transcript the model can read, newest-biased.
|
|
30
|
+
*
|
|
31
|
+
* The tail is what matters to a compaction — how the run ENDED decides what to do next — so when
|
|
32
|
+
* the budget binds it is the head that goes.
|
|
33
|
+
*/
|
|
34
|
+
renderTranscript: (messages: readonly BaseMessage[], maxChars?: number) => string;
|
|
35
|
+
/**
|
|
36
|
+
* Compact a finished run into what the next one needs.
|
|
37
|
+
*
|
|
38
|
+
* Two parts, deliberately. A summary alone leaves the next run to re-derive the plan from the
|
|
39
|
+
* outcome, which is where it invents a different one; the advice is the half that carries intent
|
|
40
|
+
* across the gap.
|
|
41
|
+
*
|
|
42
|
+
* **Never throws, and never trusts the model's arithmetic.** The character caps are applied after
|
|
43
|
+
* the answer comes back, because a cap in a prompt is a request. When the model is absent or fails
|
|
44
|
+
* — an exhausted budget is the common case, and asking again would fail the same way — the
|
|
45
|
+
* deterministic fallback still produces a usable event: what was asked, and how it ended.
|
|
46
|
+
*/
|
|
47
|
+
composeCompaction: (input: CompactionInput) => Promise<Compaction>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/helpers/compaction/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAEvD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,SAAS,WAAW,EAAE,CAAA;IAChC,MAAM,EAAE,cAAc,CAAA;IACtB,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,sIAAsI;IACtI,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,oDAAoD;IACpD,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,kGAAkG;AAClG,MAAM,WAAW,gBAAgB;IAC/B,mEAAmE;IACnE,WAAW,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,MAAM,CAAA;IAC7C;;;;;OAKG;IACH,gBAAgB,EAAE,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;IACjF;;;;;;;;;;;OAWG;IACH,iBAAiB,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;CACnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/helpers/compaction/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
|
-
import type { Compaction, CompactionInput } from './types.js';
|
|
3
|
-
|
|
2
|
+
import type { Compaction, CompactionHelper, CompactionInput } from './compaction/types.js';
|
|
3
|
+
export declare const createCompactionHelper: () => CompactionHelper;
|
|
4
|
+
export declare const compactionHelper: CompactionHelper;
|
|
5
|
+
/** @deprecated compat:factory-refactor — use `compactionHelper.messageText(…)` */
|
|
4
6
|
export declare const messageText: (message: BaseMessage) => string;
|
|
5
|
-
/**
|
|
6
|
-
* A transcript the model can read, newest-biased.
|
|
7
|
-
*
|
|
8
|
-
* The tail is what matters to a compaction — how the run ENDED decides what to do next — so when
|
|
9
|
-
* the budget binds it is the head that goes.
|
|
10
|
-
*/
|
|
7
|
+
/** @deprecated compat:factory-refactor — use `compactionHelper.renderTranscript(…)` */
|
|
11
8
|
export declare const renderTranscript: (messages: readonly BaseMessage[], maxChars?: number) => string;
|
|
12
|
-
/**
|
|
13
|
-
* Compact a finished run into what the next one needs.
|
|
14
|
-
*
|
|
15
|
-
* Two parts, deliberately. A summary alone leaves the next run to re-derive the plan from the
|
|
16
|
-
* outcome, which is where it invents a different one; the advice is the half that carries intent
|
|
17
|
-
* across the gap.
|
|
18
|
-
*
|
|
19
|
-
* **Never throws, and never trusts the model's arithmetic.** The character caps are applied after
|
|
20
|
-
* the answer comes back, because a cap in a prompt is a request. When the model is absent or fails
|
|
21
|
-
* — an exhausted budget is the common case, and asking again would fail the same way — the
|
|
22
|
-
* deterministic fallback still produces a usable event: what was asked, and how it ended.
|
|
23
|
-
*/
|
|
9
|
+
/** @deprecated compat:factory-refactor — use `compactionHelper.composeCompaction(…)` */
|
|
24
10
|
export declare const composeCompaction: (input: CompactionInput) => Promise<Compaction>;
|
|
25
11
|
//# sourceMappingURL=compaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compaction.d.ts","sourceRoot":"","sources":["../../src/helpers/compaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAI3D,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"compaction.d.ts","sourceRoot":"","sources":["../../src/helpers/compaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAI3D,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAI1F,eAAO,MAAM,sBAAsB,QAAO,gBAqHzC,CAAA;AAED,eAAO,MAAM,gBAAgB,kBAA2B,CAAA;AAExD,kFAAkF;AAClF,eAAO,MAAM,WAAW,YAAa,WAAW,KAAG,MAA+C,CAAA;AAElG,uFAAuF;AACvF,eAAO,MAAM,gBAAgB,aAAc,SAAS,WAAW,EAAE,aAAa,MAAM,KAAG,MAChC,CAAA;AAEvD,wFAAwF;AACxF,eAAO,MAAM,iBAAiB,UAAW,eAAe,KAAG,OAAO,CAAC,UAAU,CAA8C,CAAA"}
|
|
@@ -2,78 +2,60 @@ import { AgentRunStatus, DEFAULT_ADVICE_CHARS, DEFAULT_SUMMARY_CHARS, truncateAt
|
|
|
2
2
|
import { logger } from '@owlmeans/log';
|
|
3
3
|
import { COMPACTION_SCHEMA, DEFAULT_TRANSCRIPT_CHARS } from './consts.local.js';
|
|
4
4
|
const log = logger('agent');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
if (Array.isArray(content)) {
|
|
12
|
-
return content
|
|
13
|
-
.map(part => typeof part === 'string' ? part : part.text ?? '')
|
|
14
|
-
.filter(text => text !== '')
|
|
15
|
-
.join('\n');
|
|
16
|
-
}
|
|
17
|
-
return '';
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* A transcript the model can read, newest-biased.
|
|
21
|
-
*
|
|
22
|
-
* The tail is what matters to a compaction — how the run ENDED decides what to do next — so when
|
|
23
|
-
* the budget binds it is the head that goes.
|
|
24
|
-
*/
|
|
25
|
-
export const renderTranscript = (messages, maxChars = DEFAULT_TRANSCRIPT_CHARS) => {
|
|
26
|
-
const lines = [];
|
|
27
|
-
let used = 0;
|
|
28
|
-
for (let i = messages.length - 1; i >= 0; --i) {
|
|
29
|
-
const message = messages[i];
|
|
30
|
-
const text = messageText(message).trim();
|
|
31
|
-
const calls = message.tool_calls;
|
|
32
|
-
const body = text !== ''
|
|
33
|
-
? text
|
|
34
|
-
: calls != null && calls.length > 0
|
|
35
|
-
? `(called ${calls.map(call => call.name).join(', ')})`
|
|
36
|
-
: '';
|
|
37
|
-
if (body === '') {
|
|
38
|
-
continue;
|
|
5
|
+
export const createCompactionHelper = () => {
|
|
6
|
+
const messageText = (message) => {
|
|
7
|
+
const content = message.content;
|
|
8
|
+
if (typeof content === 'string') {
|
|
9
|
+
return content;
|
|
39
10
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
11
|
+
if (Array.isArray(content)) {
|
|
12
|
+
return content
|
|
13
|
+
.map(part => typeof part === 'string' ? part : part.text ?? '')
|
|
14
|
+
.filter(text => text !== '')
|
|
15
|
+
.join('\n');
|
|
43
16
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return
|
|
69
|
-
summary: truncateAt([head, ended, note?.trim(), tail].filter(part => part != null && part !== '').join(' '), maxSummaryChars),
|
|
70
|
-
};
|
|
17
|
+
return '';
|
|
18
|
+
};
|
|
19
|
+
const renderTranscript = (messages, maxChars = DEFAULT_TRANSCRIPT_CHARS) => {
|
|
20
|
+
const lines = [];
|
|
21
|
+
let used = 0;
|
|
22
|
+
for (let i = messages.length - 1; i >= 0; --i) {
|
|
23
|
+
const message = messages[i];
|
|
24
|
+
const text = messageText(message).trim();
|
|
25
|
+
const calls = message.tool_calls;
|
|
26
|
+
const body = text !== ''
|
|
27
|
+
? text
|
|
28
|
+
: calls != null && calls.length > 0
|
|
29
|
+
? `(called ${calls.map(call => call.name).join(', ')})`
|
|
30
|
+
: '';
|
|
31
|
+
if (body === '') {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const line = `${message.getType()}: ${body}`;
|
|
35
|
+
if (used + line.length > maxChars) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
lines.unshift(line);
|
|
39
|
+
used += line.length;
|
|
40
|
+
}
|
|
41
|
+
return lines.join('\n\n');
|
|
71
42
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
43
|
+
const composeCompaction = async (input) => {
|
|
44
|
+
const { model, prompt, messages, status, note, maxSummaryChars = DEFAULT_SUMMARY_CHARS, maxAdviceChars = DEFAULT_ADVICE_CHARS, action = 'agent-compaction', maxTranscriptChars, } = input;
|
|
45
|
+
const fallback = () => {
|
|
46
|
+
const last = [...messages].reverse().find(message => messageText(message).trim() !== '');
|
|
47
|
+
const tail = last != null ? messageText(last).trim() : '';
|
|
48
|
+
const head = `Asked: ${prompt.trim()}`;
|
|
49
|
+
const ended = status === AgentRunStatus.Ok ? 'Finished.' : 'Did not finish.';
|
|
50
|
+
return {
|
|
51
|
+
summary: truncateAt([head, ended, note?.trim(), tail].filter(part => part != null && part !== '').join(' '), maxSummaryChars),
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
if (model == null) {
|
|
55
|
+
return fallback();
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const result = await model.invoke(`
|
|
77
59
|
Compact the conversation below into a handover for the next session working on the same subject.
|
|
78
60
|
|
|
79
61
|
Write two things:
|
|
@@ -96,17 +78,26 @@ ${status === AgentRunStatus.Ok ? 'Completed' : 'Failed'}${note != null && note !
|
|
|
96
78
|
# Conversation
|
|
97
79
|
${renderTranscript(messages, maxTranscriptChars)}
|
|
98
80
|
`, COMPACTION_SCHEMA, { action });
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
81
|
+
const summary = truncateAt(result.summary ?? '', maxSummaryChars);
|
|
82
|
+
const advice = truncateAt(result.advice ?? '', maxAdviceChars);
|
|
83
|
+
// An empty summary is a non-answer, not a short one — take the deterministic path rather than
|
|
84
|
+
// storing a blank event that the next run will read as "nothing happened".
|
|
85
|
+
return summary === ''
|
|
86
|
+
? fallback()
|
|
87
|
+
: { summary, ...(advice !== '' ? { advice } : {}) };
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
log.warn('Agent compaction failed, falling back to a deterministic summary', e);
|
|
91
|
+
return fallback();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
return { messageText, renderTranscript, composeCompaction };
|
|
111
95
|
};
|
|
96
|
+
export const compactionHelper = createCompactionHelper();
|
|
97
|
+
/** @deprecated compat:factory-refactor — use `compactionHelper.messageText(…)` */
|
|
98
|
+
export const messageText = (message) => compactionHelper.messageText(message);
|
|
99
|
+
/** @deprecated compat:factory-refactor — use `compactionHelper.renderTranscript(…)` */
|
|
100
|
+
export const renderTranscript = (messages, maxChars) => compactionHelper.renderTranscript(messages, maxChars);
|
|
101
|
+
/** @deprecated compat:factory-refactor — use `compactionHelper.composeCompaction(…)` */
|
|
102
|
+
export const composeCompaction = (input) => compactionHelper.composeCompaction(input);
|
|
112
103
|
//# sourceMappingURL=compaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compaction.js","sourceRoot":"","sources":["../../src/helpers/compaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAChH,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AAG/E,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;AAE3B,
|
|
1
|
+
{"version":3,"file":"compaction.js","sourceRoot":"","sources":["../../src/helpers/compaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAChH,OAAO,EAAE,MAAM,EAAE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AA2E;YAC3E,OAAO,OAAO,KAAK,EAAE;gBACnB,CAAC,CAAC,QAAQ,EAAE;gBACZ,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAA;QACvD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,GAAG,CAAC,IAAI,CAAC,kEAAkE,EAAE,CAAC,CAAC,CAAA;YAC/E,OAAO,QAAQ,EAAE,CAAA;QACnB,CAAC;IACH,CAAC,CAAA;IAED,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAA;AAC7D,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,EAAE,CAAA;AAExD,kFAAkF;AAClF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAoB,EAAU,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;AAElG,uFAAuF;AACvF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAgC,EAAE,QAAiB,EAAU,EAAE,CAC9F,gBAAgB,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;AAEvD,wFAAwF;AACxF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAsB,EAAuB,EAAE,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAA"}
|
package/build/helpers/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
export type * from './tools/types.js';
|
|
2
|
+
export type * from './compaction/types.js';
|
|
3
|
+
export type * from './rolling/types.js';
|
|
1
4
|
export * from './tools.js';
|
|
2
|
-
export type * from './types.js';
|
|
3
5
|
export * from './compaction.js';
|
|
4
6
|
export * from './rolling.js';
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,kBAAkB,CAAA;AACrC,mBAAmB,uBAAuB,CAAA;AAC1C,mBAAmB,oBAAoB,CAAA;AACvC,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LlmModel } from '@owlmeans/llm';
|
|
2
|
+
export interface RollingSummaryInput {
|
|
3
|
+
/** Omit to skip the model and take the deterministic path. */
|
|
4
|
+
model?: LlmModel;
|
|
5
|
+
/** The prose account so far. Empty on the first fold. */
|
|
6
|
+
previous: string;
|
|
7
|
+
/** What just happened, as one line. */
|
|
8
|
+
event: string;
|
|
9
|
+
/** Anything the fold may use but that need not survive into the summary. */
|
|
10
|
+
details?: string;
|
|
11
|
+
/** Hard ceiling on the returned prose, in characters. */
|
|
12
|
+
maxChars: number;
|
|
13
|
+
/** LangChain `runName`. Give it a value the application filters out of its user-facing stream. */
|
|
14
|
+
action?: string;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/helpers/rolling/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,MAAM,WAAW,mBAAmB;IAClC,8DAA8D;IAC9D,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAA;IAChB,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAA;IACb,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAA;IAChB,kGAAkG;IAClG,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/helpers/rolling/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rolling.d.ts","sourceRoot":"","sources":["../../src/helpers/rolling.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"rolling.d.ts","sourceRoot":"","sources":["../../src/helpers/rolling.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAI7D;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,UAAiB,mBAAmB,KAAG,OAAO,CAAC,MAAM,CAyCtF,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ToolCall } from '@langchain/core/messages';
|
|
2
|
+
import type { AgentToolSet } from '../../types.js';
|
|
3
|
+
/** The shape a contained tool failure comes back as. Matches what tool bodies return themselves. */
|
|
4
|
+
export interface ToolErrorResponse {
|
|
5
|
+
error: string;
|
|
6
|
+
}
|
|
7
|
+
/** Running a model-requested tool without letting its failure take the run with it. */
|
|
8
|
+
export interface ToolHelper {
|
|
9
|
+
toErrorResponse: (e: unknown) => ToolErrorResponse;
|
|
10
|
+
isToolError: (result: unknown) => result is ToolErrorResponse;
|
|
11
|
+
/**
|
|
12
|
+
* Run one model-requested tool, contained.
|
|
13
|
+
*
|
|
14
|
+
* **Never throws.** The caller wraps this in a LangGraph task, and a rejected task aborts the whole
|
|
15
|
+
* superstep: every sibling tool call in the same parallel batch dies with AbortError and the run
|
|
16
|
+
* ends on "Multiple errors occurred during superstep 0", discarding work the other calls had
|
|
17
|
+
* already finished. A tool failure has to come back as something the model can read and correct
|
|
18
|
+
* instead — most of them are the model's own mistake (an argument outside an enum, a hallucinated
|
|
19
|
+
* tool name), and the error text already names what was expected.
|
|
20
|
+
*
|
|
21
|
+
* Awaiting `invoke` is what makes the catch reachable: the tool's schema is validated inside it, so
|
|
22
|
+
* a bad argument rejects asynchronously and returning the promise unawaited would carry the
|
|
23
|
+
* rejection straight past this handler.
|
|
24
|
+
*
|
|
25
|
+
* Resolution is by the tool's OWN name, not by the map key. `bindTools` advertises `tool.name`, so
|
|
26
|
+
* that is what the model calls — a map keyed by a local variable silently loses any tool whose two
|
|
27
|
+
* names drifted apart, leaving it advertised, callable, and permanently "not found". The key stays
|
|
28
|
+
* as a fallback so a caller may still address a tool by it.
|
|
29
|
+
*
|
|
30
|
+
* `fatal` is the ONE exception to "never throws", and it exists because containment has a cost the
|
|
31
|
+
* containment itself cannot see. A tool may be a whole pipeline behind a single call; when the
|
|
32
|
+
* thing that stopped it is an exhausted budget or a refusal, handing the model a readable error
|
|
33
|
+
* message is an invitation to pick another tool and spend again. A caller that knows which errors
|
|
34
|
+
* mean "stop" says so here, and those alone travel out.
|
|
35
|
+
*/
|
|
36
|
+
safeInvokeTool: (tools: AgentToolSet, toolCall: ToolCall, fatal?: (e: unknown) => boolean) => Promise<unknown>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/helpers/tools/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,oGAAoG;AACpG,MAAM,WAAW,iBAAiB;IAAG,KAAK,EAAE,MAAM,CAAA;CAAE;AAEpD,uFAAuF;AACvF,MAAM,WAAW,UAAU;IACzB,eAAe,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,iBAAiB,CAAA;IAClD,WAAW,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,MAAM,IAAI,iBAAiB,CAAA;IAC7D;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,cAAc,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAC/G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/helpers/tools/types.ts"],"names":[],"mappings":""}
|
package/build/helpers/tools.d.ts
CHANGED
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
import type { ToolCall } from '@langchain/core/messages';
|
|
2
2
|
import type { AgentToolSet } from '../types.js';
|
|
3
|
-
import type { ToolErrorResponse } from './types.js';
|
|
3
|
+
import type { ToolErrorResponse, ToolHelper } from './tools/types.js';
|
|
4
|
+
export declare const createToolHelper: () => ToolHelper;
|
|
5
|
+
export declare const toolHelper: ToolHelper;
|
|
6
|
+
/** @deprecated compat:factory-refactor — use `toolHelper.toErrorResponse(…)` */
|
|
4
7
|
export declare const toErrorResponse: (e: unknown) => ToolErrorResponse;
|
|
8
|
+
/** @deprecated compat:factory-refactor — use `toolHelper.isToolError(…)` */
|
|
5
9
|
export declare const isToolError: (result: unknown) => result is ToolErrorResponse;
|
|
6
|
-
/**
|
|
7
|
-
* Run one model-requested tool, contained.
|
|
8
|
-
*
|
|
9
|
-
* **Never throws.** The caller wraps this in a LangGraph task, and a rejected task aborts the whole
|
|
10
|
-
* superstep: every sibling tool call in the same parallel batch dies with AbortError and the run
|
|
11
|
-
* ends on "Multiple errors occurred during superstep 0", discarding work the other calls had
|
|
12
|
-
* already finished. A tool failure has to come back as something the model can read and correct
|
|
13
|
-
* instead — most of them are the model's own mistake (an argument outside an enum, a hallucinated
|
|
14
|
-
* tool name), and the error text already names what was expected.
|
|
15
|
-
*
|
|
16
|
-
* Awaiting `invoke` is what makes the catch reachable: the tool's schema is validated inside it, so
|
|
17
|
-
* a bad argument rejects asynchronously and returning the promise unawaited would carry the
|
|
18
|
-
* rejection straight past this handler.
|
|
19
|
-
*
|
|
20
|
-
* Resolution is by the tool's OWN name, not by the map key. `bindTools` advertises `tool.name`, so
|
|
21
|
-
* that is what the model calls — a map keyed by a local variable silently loses any tool whose two
|
|
22
|
-
* names drifted apart, leaving it advertised, callable, and permanently "not found". The key stays
|
|
23
|
-
* as a fallback so a caller may still address a tool by it.
|
|
24
|
-
*
|
|
25
|
-
* `fatal` is the ONE exception to "never throws", and it exists because containment has a cost the
|
|
26
|
-
* containment itself cannot see. A tool may be a whole pipeline behind a single call; when the
|
|
27
|
-
* thing that stopped it is an exhausted budget or a refusal, handing the model a readable error
|
|
28
|
-
* message is an invitation to pick another tool and spend again. A caller that knows which errors
|
|
29
|
-
* mean "stop" says so here, and those alone travel out.
|
|
30
|
-
*/
|
|
10
|
+
/** @deprecated compat:factory-refactor — use `toolHelper.safeInvokeTool(…)` */
|
|
31
11
|
export declare const safeInvokeTool: (tools: AgentToolSet, toolCall: ToolCall, fatal?: (e: unknown) => boolean) => Promise<unknown>;
|
|
32
12
|
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/helpers/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/helpers/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAIrE,eAAO,MAAM,gBAAgB,QAAO,UA6BnC,CAAA;AAED,eAAO,MAAM,UAAU,YAAqB,CAAA;AAE5C,gFAAgF;AAChF,eAAO,MAAM,eAAe,MAAO,OAAO,KAAG,iBAAkD,CAAA;AAE/F,4EAA4E;AAC5E,eAAO,MAAM,WAAW,WAAY,OAAO,KAAG,MAAM,IAAI,iBAAmD,CAAA;AAE3G,+EAA+E;AAC/E,eAAO,MAAM,cAAc,UAClB,YAAY,YAAY,QAAQ,UAAU,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO,KACvE,OAAO,CAAC,OAAO,CAAsD,CAAA"}
|