@dxos/assistant 0.8.2 → 0.8.3-main.7f5a14c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +231 -84
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +240 -89
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +231 -84
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/blueprint/ai.test.d.ts +2 -0
- package/dist/types/src/blueprint/ai.test.d.ts.map +1 -0
- package/dist/types/src/blueprint/blueprint.d.ts +23 -48
- package/dist/types/src/blueprint/blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprint/logger.d.ts +24 -2
- package/dist/types/src/blueprint/logger.d.ts.map +1 -1
- package/dist/types/src/blueprint/machine.d.ts +33 -9
- package/dist/types/src/blueprint/machine.d.ts.map +1 -1
- package/dist/types/src/research/graph.d.ts +6 -5
- package/dist/types/src/research/graph.d.ts.map +1 -1
- package/package.json +30 -20
- package/src/blueprint/ai.test.ts +156 -0
- package/src/blueprint/blueprint.test.ts +23 -14
- package/src/blueprint/blueprint.ts +22 -42
- package/src/blueprint/logger.ts +108 -19
- package/src/blueprint/machine.ts +75 -37
- package/src/research/graph.ts +65 -17
- package/src/research/research.test.ts +1 -1
- package/src/research/research.ts +1 -1
package/dist/lib/node/index.cjs
CHANGED
|
@@ -32,9 +32,12 @@ __export(node_exports, {
|
|
|
32
32
|
AISession: () => AISession,
|
|
33
33
|
Blueprint: () => Blueprint,
|
|
34
34
|
BlueprintBuilder: () => BlueprintBuilder,
|
|
35
|
+
BlueprintDefinition: () => BlueprintDefinition,
|
|
36
|
+
BlueprintLoggerAdapter: () => BlueprintLoggerAdapter,
|
|
35
37
|
BlueprintMachine: () => BlueprintMachine,
|
|
36
38
|
BlueprintParser: () => BlueprintParser,
|
|
37
39
|
BlueprintStep: () => BlueprintStep,
|
|
40
|
+
BufferedLogger: () => BufferedLogger,
|
|
38
41
|
ExtractionInput: () => ExtractionInput,
|
|
39
42
|
ExtractionOutput: () => ExtractionOutput,
|
|
40
43
|
ReferencedQuotes: () => ReferencedQuotes,
|
|
@@ -59,7 +62,8 @@ __export(node_exports, {
|
|
|
59
62
|
processTranscriptMessage: () => processTranscriptMessage,
|
|
60
63
|
researchFn: () => researchFn,
|
|
61
64
|
sanitizeObjects: () => sanitizeObjects,
|
|
62
|
-
setConsolePrinter: () => setConsolePrinter
|
|
65
|
+
setConsolePrinter: () => setConsolePrinter,
|
|
66
|
+
setLogger: () => setLogger
|
|
63
67
|
});
|
|
64
68
|
module.exports = __toCommonJS(node_exports);
|
|
65
69
|
var import_effect = require("effect");
|
|
@@ -112,16 +116,18 @@ var import_keys2 = require("@dxos/keys");
|
|
|
112
116
|
var import_log8 = require("@dxos/log");
|
|
113
117
|
var import_util = require("@dxos/util");
|
|
114
118
|
var import_effect9 = require("effect");
|
|
115
|
-
var
|
|
116
|
-
var import_debug = require("@dxos/debug");
|
|
117
|
-
var import_keys3 = require("@dxos/keys");
|
|
119
|
+
var import_echo = require("@dxos/echo");
|
|
118
120
|
var import_effect10 = require("effect");
|
|
119
|
-
var
|
|
121
|
+
var import_ai6 = require("@dxos/ai");
|
|
120
122
|
var import_async4 = require("@dxos/async");
|
|
121
123
|
var import_echo_schema9 = require("@dxos/echo-schema");
|
|
122
124
|
var import_log9 = require("@dxos/log");
|
|
125
|
+
var import_util2 = require("@dxos/util");
|
|
126
|
+
var import_signals_core = require("@preact/signals-core");
|
|
123
127
|
var import_chalk = __toESM(require("chalk"));
|
|
124
|
-
var
|
|
128
|
+
var import_ai7 = require("@dxos/ai");
|
|
129
|
+
var import_async5 = require("@dxos/async");
|
|
130
|
+
var import_log10 = require("@dxos/log");
|
|
125
131
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/assistant/src/extraction/extraction.ts";
|
|
126
132
|
var ExtractionInput = import_effect.Schema.Struct({
|
|
127
133
|
message: import_schema.DataType.Message,
|
|
@@ -1466,7 +1472,7 @@ var isSchemaAddressableByDxn = (schema, dxn) => {
|
|
|
1466
1472
|
}
|
|
1467
1473
|
return false;
|
|
1468
1474
|
};
|
|
1469
|
-
var createLocalSearchTool = (db) => {
|
|
1475
|
+
var createLocalSearchTool = (db, queue) => {
|
|
1470
1476
|
return (0, import_ai5.createTool)("search", {
|
|
1471
1477
|
name: "local_search",
|
|
1472
1478
|
description: "Search the local database for information using a vector index",
|
|
@@ -1479,9 +1485,16 @@ var createLocalSearchTool = (db) => {
|
|
|
1479
1485
|
const { objects } = await db.query(import_echo_schema8.Query.select(import_echo_schema8.Filter.text(query, {
|
|
1480
1486
|
type: "vector"
|
|
1481
1487
|
}))).run();
|
|
1488
|
+
const results = [
|
|
1489
|
+
...objects
|
|
1490
|
+
];
|
|
1491
|
+
if (queue) {
|
|
1492
|
+
const queueObjects = await queue.queryObjects();
|
|
1493
|
+
results.push(...queueObjects);
|
|
1494
|
+
}
|
|
1482
1495
|
return import_ai5.ToolResult.Success(`
|
|
1483
1496
|
<local_context>
|
|
1484
|
-
${JSON.stringify(
|
|
1497
|
+
${JSON.stringify(results, null, 2)}
|
|
1485
1498
|
</local_context>
|
|
1486
1499
|
`);
|
|
1487
1500
|
}
|
|
@@ -1500,13 +1513,14 @@ var createExtractionSchema = (types) => {
|
|
|
1500
1513
|
var getSanitizedSchemaName = (schema) => {
|
|
1501
1514
|
return (0, import_echo_schema8.getSchemaDXN)(schema).asTypeDXN().type.replaceAll(/[^a-zA-Z0-9]+/g, "_");
|
|
1502
1515
|
};
|
|
1503
|
-
var sanitizeObjects = async (types, data, db) => {
|
|
1516
|
+
var sanitizeObjects = async (types, data, db, queue) => {
|
|
1504
1517
|
const entries = types.map((type) => data[`objects_${getSanitizedSchemaName(type)}`]?.map((object) => ({
|
|
1505
1518
|
data: object,
|
|
1506
1519
|
schema: type
|
|
1507
1520
|
})) ?? []).flat();
|
|
1508
1521
|
const idMap = /* @__PURE__ */ new Map();
|
|
1509
1522
|
const existingIds = /* @__PURE__ */ new Set();
|
|
1523
|
+
const enitties = /* @__PURE__ */ new Map();
|
|
1510
1524
|
const resolveId = (id) => {
|
|
1511
1525
|
if (import_echo_schema8.ObjectId.isValid(id)) {
|
|
1512
1526
|
existingIds.add(id);
|
|
@@ -1549,7 +1563,7 @@ var sanitizeObjects = async (types, data, db) => {
|
|
|
1549
1563
|
source: data2.source
|
|
1550
1564
|
}, {
|
|
1551
1565
|
F: __dxlog_file7,
|
|
1552
|
-
L:
|
|
1566
|
+
L: 216,
|
|
1553
1567
|
S: void 0,
|
|
1554
1568
|
C: (f, a) => f(...a)
|
|
1555
1569
|
});
|
|
@@ -1560,25 +1574,36 @@ var sanitizeObjects = async (types, data, db) => {
|
|
|
1560
1574
|
target: data2.target
|
|
1561
1575
|
}, {
|
|
1562
1576
|
F: __dxlog_file7,
|
|
1563
|
-
L:
|
|
1577
|
+
L: 220,
|
|
1564
1578
|
S: void 0,
|
|
1565
1579
|
C: (f, a) => f(...a)
|
|
1566
1580
|
});
|
|
1567
1581
|
}
|
|
1568
1582
|
delete data2.source;
|
|
1569
1583
|
delete data2.target;
|
|
1570
|
-
data2[import_echo_schema8.
|
|
1571
|
-
data2[import_echo_schema8.
|
|
1584
|
+
data2[import_echo_schema8.RelationSourceDXNId] = sourceDxn;
|
|
1585
|
+
data2[import_echo_schema8.RelationTargetDXNId] = targetDxn;
|
|
1572
1586
|
}
|
|
1573
|
-
return
|
|
1574
|
-
|
|
1575
|
-
|
|
1587
|
+
return {
|
|
1588
|
+
data: data2,
|
|
1589
|
+
schema: entry.schema
|
|
1590
|
+
};
|
|
1591
|
+
}).filter((object) => !existingIds.has(object.data.id));
|
|
1592
|
+
const { objects: dbObjects } = await db.query(import_echo_schema8.Query.select(import_echo_schema8.Filter.ids(...existingIds))).run();
|
|
1593
|
+
const queueObjects = await queue?.getObjectsById([
|
|
1594
|
+
...existingIds
|
|
1595
|
+
]) ?? [];
|
|
1596
|
+
const objects = [
|
|
1597
|
+
...dbObjects,
|
|
1598
|
+
...queueObjects
|
|
1599
|
+
].filter(import_util.isNonNullable);
|
|
1576
1600
|
import_log8.log.info("objects", {
|
|
1577
|
-
|
|
1601
|
+
dbObjects,
|
|
1602
|
+
queueObjects,
|
|
1578
1603
|
existingIds
|
|
1579
1604
|
}, {
|
|
1580
1605
|
F: __dxlog_file7,
|
|
1581
|
-
L:
|
|
1606
|
+
L: 241,
|
|
1582
1607
|
S: void 0,
|
|
1583
1608
|
C: (f, a) => f(...a)
|
|
1584
1609
|
});
|
|
@@ -1586,7 +1611,37 @@ var sanitizeObjects = async (types, data, db) => {
|
|
|
1586
1611
|
if (missing.length > 0) {
|
|
1587
1612
|
throw new Error(`Object IDs do not point to existing objects: ${missing.join(", ")}`);
|
|
1588
1613
|
}
|
|
1589
|
-
return res
|
|
1614
|
+
return res.flatMap(({ data: data2, schema }) => {
|
|
1615
|
+
let skip = false;
|
|
1616
|
+
if (import_echo_schema8.RelationSourceDXNId in data2) {
|
|
1617
|
+
const id = data2[import_echo_schema8.RelationSourceDXNId].asEchoDXN()?.echoId;
|
|
1618
|
+
const obj = objects.find((object) => object.id === id) ?? enitties.get(id);
|
|
1619
|
+
if (obj) {
|
|
1620
|
+
delete data2[import_echo_schema8.RelationSourceDXNId];
|
|
1621
|
+
data2[import_echo_schema8.RelationSourceId] = obj;
|
|
1622
|
+
} else {
|
|
1623
|
+
skip = true;
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
if (import_echo_schema8.RelationTargetDXNId in data2) {
|
|
1627
|
+
const id = data2[import_echo_schema8.RelationTargetDXNId].asEchoDXN()?.echoId;
|
|
1628
|
+
const obj = objects.find((object) => object.id === id) ?? enitties.get(id);
|
|
1629
|
+
if (obj) {
|
|
1630
|
+
delete data2[import_echo_schema8.RelationTargetDXNId];
|
|
1631
|
+
data2[import_echo_schema8.RelationTargetId] = obj;
|
|
1632
|
+
} else {
|
|
1633
|
+
skip = true;
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
if (!skip) {
|
|
1637
|
+
const obj = (0, import_echo_schema8.create)(schema, data2);
|
|
1638
|
+
enitties.set(obj.id, obj);
|
|
1639
|
+
return [
|
|
1640
|
+
obj
|
|
1641
|
+
];
|
|
1642
|
+
}
|
|
1643
|
+
return [];
|
|
1644
|
+
});
|
|
1590
1645
|
};
|
|
1591
1646
|
var SoftRef = import_effect7.Schema.Struct({
|
|
1592
1647
|
"/": import_effect7.Schema.String
|
|
@@ -1614,13 +1669,13 @@ var preprocessSchema = (schema) => {
|
|
|
1614
1669
|
})
|
|
1615
1670
|
})) : import_effect7.identity);
|
|
1616
1671
|
};
|
|
1617
|
-
var createGraphWriterTool = ({ db,
|
|
1672
|
+
var createGraphWriterTool = ({ db, queue, schema, onDone = async (x) => x }) => {
|
|
1618
1673
|
return (0, import_ai5.createTool)("graph", {
|
|
1619
1674
|
name: "writer",
|
|
1620
1675
|
description: "Write to the local graph database",
|
|
1621
|
-
schema: createExtractionSchema(
|
|
1676
|
+
schema: createExtractionSchema(schema),
|
|
1622
1677
|
execute: async (input) => {
|
|
1623
|
-
const data = await sanitizeObjects(
|
|
1678
|
+
const data = await sanitizeObjects(schema, input, db, queue);
|
|
1624
1679
|
return import_ai5.ToolResult.Success(await onDone(data));
|
|
1625
1680
|
}
|
|
1626
1681
|
});
|
|
@@ -1685,7 +1740,7 @@ var researchFn = (0, import_functions3.defineFunction)({
|
|
|
1685
1740
|
}));
|
|
1686
1741
|
const graphWriteTool = createGraphWriterTool({
|
|
1687
1742
|
db,
|
|
1688
|
-
|
|
1743
|
+
schema: import_schema4.DataTypes
|
|
1689
1744
|
});
|
|
1690
1745
|
import_log7.log.info("graphWriteTool", {
|
|
1691
1746
|
schema: graphWriteTool.parameters
|
|
@@ -1713,14 +1768,20 @@ var researchFn = (0, import_functions3.defineFunction)({
|
|
|
1713
1768
|
});
|
|
1714
1769
|
var createArtifactElement = (id) => `<artifact id=${id} />`;
|
|
1715
1770
|
var BlueprintStep = import_effect9.Schema.Struct({
|
|
1716
|
-
id:
|
|
1771
|
+
id: import_echo.Key.ObjectId,
|
|
1717
1772
|
instructions: import_effect9.Schema.String,
|
|
1718
|
-
|
|
1719
|
-
tools: import_effect9.Schema.Array(import_ai6.Tool).pipe(import_effect9.Schema.mutable)
|
|
1773
|
+
tools: import_effect9.Schema.optional(import_effect9.Schema.Array(import_effect9.Schema.String))
|
|
1720
1774
|
});
|
|
1721
|
-
var
|
|
1722
|
-
steps: import_effect9.Schema.Array(BlueprintStep
|
|
1775
|
+
var BlueprintDefinition = import_effect9.Schema.Struct({
|
|
1776
|
+
steps: import_effect9.Schema.Array(BlueprintStep.pipe(import_effect9.Schema.omit("id")))
|
|
1723
1777
|
});
|
|
1778
|
+
var Blueprint = import_effect9.Schema.Struct({
|
|
1779
|
+
name: import_effect9.Schema.optional(import_effect9.Schema.String),
|
|
1780
|
+
steps: import_effect9.Schema.Array(BlueprintStep)
|
|
1781
|
+
}).pipe(import_echo.Type.Obj({
|
|
1782
|
+
typename: "dxos.org/type/Blueprint",
|
|
1783
|
+
version: "0.1.0"
|
|
1784
|
+
}));
|
|
1724
1785
|
(function(BlueprintBuilder2) {
|
|
1725
1786
|
BlueprintBuilder2.create = () => new Builder();
|
|
1726
1787
|
class Builder {
|
|
@@ -1729,40 +1790,27 @@ var Blueprint = import_effect9.Schema.Struct({
|
|
|
1729
1790
|
}
|
|
1730
1791
|
step(instructions, options) {
|
|
1731
1792
|
this._steps.push({
|
|
1732
|
-
id:
|
|
1793
|
+
id: import_echo.Key.ObjectId.random(),
|
|
1733
1794
|
instructions,
|
|
1734
1795
|
tools: options?.tools ?? []
|
|
1735
1796
|
});
|
|
1736
1797
|
return this;
|
|
1737
1798
|
}
|
|
1738
1799
|
build() {
|
|
1739
|
-
return {
|
|
1800
|
+
return import_echo.Obj.make(Blueprint, {
|
|
1740
1801
|
steps: this._steps
|
|
1741
|
-
};
|
|
1802
|
+
});
|
|
1742
1803
|
}
|
|
1743
1804
|
}
|
|
1744
1805
|
})(BlueprintBuilder || (BlueprintBuilder = {}));
|
|
1745
1806
|
(function(BlueprintParser2) {
|
|
1746
|
-
BlueprintParser2.create = (
|
|
1807
|
+
BlueprintParser2.create = () => new Parser();
|
|
1747
1808
|
class Parser {
|
|
1748
|
-
constructor(_tools) {
|
|
1749
|
-
this._tools = _tools;
|
|
1750
|
-
}
|
|
1751
|
-
toJSON() {
|
|
1752
|
-
return {
|
|
1753
|
-
tools: this._tools.map((tool) => ({
|
|
1754
|
-
name: tool.name,
|
|
1755
|
-
namespace: tool.namespace,
|
|
1756
|
-
type: tool.type
|
|
1757
|
-
}))
|
|
1758
|
-
};
|
|
1759
|
-
}
|
|
1760
1809
|
parse({ steps }) {
|
|
1761
1810
|
const builder = BlueprintBuilder.create();
|
|
1762
1811
|
for (const step of steps) {
|
|
1763
1812
|
builder.step(step.instructions, {
|
|
1764
|
-
|
|
1765
|
-
tools: step.tools?.map((tool) => this._tools.find(({ id }) => id === tool) ?? (0, import_debug.raise)(new Error(`Tool not found: ${tool}`)))
|
|
1813
|
+
tools: step.tools ?? []
|
|
1766
1814
|
});
|
|
1767
1815
|
}
|
|
1768
1816
|
return builder.build();
|
|
@@ -1772,13 +1820,24 @@ var Blueprint = import_effect9.Schema.Struct({
|
|
|
1772
1820
|
var BlueprintBuilder;
|
|
1773
1821
|
var BlueprintParser;
|
|
1774
1822
|
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/assistant/src/blueprint/machine.ts";
|
|
1823
|
+
var SYSTEM_PROMPT = `
|
|
1824
|
+
You are a smart Rule-Following Agent.
|
|
1825
|
+
Rule-Following Agent executes the command that the user sent in the last message.
|
|
1826
|
+
After doing the work, the Rule-Following Agent calls report tool.
|
|
1827
|
+
If the Rule-Following agent believes that no action is needed, it calls the report tool with "skipped" status.
|
|
1828
|
+
If the Rule-Following Agent is unable to perform the task, it calls the report tool with "bail" status.
|
|
1829
|
+
Rule-Following Agent explains the reason it is unable to perform the task before bailing.
|
|
1830
|
+
The Rule-Following Agent can express creativity and imagination in the way it performs the task.
|
|
1831
|
+
The Rule-Following Agent precisely follows the instructions.
|
|
1832
|
+
`;
|
|
1775
1833
|
var INITIAL_STATE = {
|
|
1776
1834
|
state: "working",
|
|
1777
1835
|
history: [],
|
|
1778
1836
|
trace: []
|
|
1779
1837
|
};
|
|
1780
1838
|
var BlueprintMachine = class {
|
|
1781
|
-
constructor(blueprint) {
|
|
1839
|
+
constructor(registry, blueprint) {
|
|
1840
|
+
this.registry = registry;
|
|
1782
1841
|
this.blueprint = blueprint;
|
|
1783
1842
|
this.begin = new import_async4.Event();
|
|
1784
1843
|
this.end = new import_async4.Event();
|
|
@@ -1786,39 +1845,61 @@ var BlueprintMachine = class {
|
|
|
1786
1845
|
this.stepComplete = new import_async4.Event();
|
|
1787
1846
|
this.message = new import_async4.Event();
|
|
1788
1847
|
this.block = new import_async4.Event();
|
|
1789
|
-
this.
|
|
1848
|
+
this._state = structuredClone(INITIAL_STATE);
|
|
1849
|
+
}
|
|
1850
|
+
get state() {
|
|
1851
|
+
return this._state;
|
|
1852
|
+
}
|
|
1853
|
+
setLogger(logger) {
|
|
1854
|
+
this.logger = logger;
|
|
1855
|
+
return this;
|
|
1790
1856
|
}
|
|
1791
1857
|
async runToCompletion(options) {
|
|
1792
1858
|
import_log9.log.info("runToCompletion", options, {
|
|
1793
1859
|
F: __dxlog_file9,
|
|
1794
|
-
L:
|
|
1860
|
+
L: 106,
|
|
1795
1861
|
S: this,
|
|
1796
1862
|
C: (f, a) => f(...a)
|
|
1797
1863
|
});
|
|
1798
1864
|
this.begin.emit();
|
|
1865
|
+
this.logger?.log({
|
|
1866
|
+
type: "begin"
|
|
1867
|
+
});
|
|
1799
1868
|
let firstStep = true;
|
|
1800
|
-
while (this.
|
|
1869
|
+
while (this._state.state !== "done") {
|
|
1801
1870
|
const input = firstStep ? options.input : void 0;
|
|
1802
1871
|
firstStep = false;
|
|
1803
|
-
this.
|
|
1872
|
+
this._state = await this._execStep(this._state, {
|
|
1804
1873
|
input,
|
|
1805
|
-
|
|
1874
|
+
aiClient: options.aiClient
|
|
1875
|
+
});
|
|
1876
|
+
const step = this.blueprint.steps.find((step2) => step2.id === this._state.trace.at(-1)?.stepId);
|
|
1877
|
+
this.stepComplete.emit(step);
|
|
1878
|
+
this.logger?.log({
|
|
1879
|
+
type: "step-complete",
|
|
1880
|
+
step
|
|
1806
1881
|
});
|
|
1807
|
-
|
|
1808
|
-
if (this.state.state === "bail") {
|
|
1882
|
+
if (this._state.state === "bail") {
|
|
1809
1883
|
throw new Error("Agent unable to follow the blueprint");
|
|
1810
1884
|
}
|
|
1811
1885
|
}
|
|
1812
1886
|
this.end.emit();
|
|
1887
|
+
this.logger?.log({
|
|
1888
|
+
type: "end"
|
|
1889
|
+
});
|
|
1813
1890
|
}
|
|
1814
1891
|
async _execStep(state, options) {
|
|
1815
|
-
const prevStep = this.blueprint.steps.findIndex((step) => step.id === this.
|
|
1892
|
+
const prevStep = this.blueprint.steps.findIndex((step) => step.id === this._state.trace.at(-1)?.stepId);
|
|
1816
1893
|
if (prevStep === this.blueprint.steps.length - 1) {
|
|
1817
1894
|
throw new Error("Done execution blueprint");
|
|
1818
1895
|
}
|
|
1819
1896
|
const nextStep = this.blueprint.steps[prevStep + 1];
|
|
1820
1897
|
const onLastStep = prevStep === this.blueprint.steps.length - 2;
|
|
1821
1898
|
this.stepStart.emit(nextStep);
|
|
1899
|
+
this.logger?.log({
|
|
1900
|
+
type: "step-start",
|
|
1901
|
+
step: nextStep
|
|
1902
|
+
});
|
|
1822
1903
|
const ReportSchema = import_effect10.Schema.Struct({
|
|
1823
1904
|
status: import_effect10.Schema.Literal("done", "bailed", "skipped").annotations({
|
|
1824
1905
|
description: "The status of the task completion"
|
|
@@ -1827,11 +1908,11 @@ var BlueprintMachine = class {
|
|
|
1827
1908
|
description: "A comment about the task completion. If you bailed, you must explain why in detail (min couple of sentences)."
|
|
1828
1909
|
})
|
|
1829
1910
|
});
|
|
1830
|
-
const report = (0,
|
|
1911
|
+
const report = (0, import_ai6.createTool)("system", {
|
|
1831
1912
|
name: "report",
|
|
1832
|
-
description: "This tool reports that the agent has completed the task or is unable to do so",
|
|
1913
|
+
description: "This tool reports that the agent has completed the task or is unable to do so.",
|
|
1833
1914
|
schema: ReportSchema,
|
|
1834
|
-
execute: async (input) =>
|
|
1915
|
+
execute: async (input) => import_ai6.ToolResult.Break(input)
|
|
1835
1916
|
});
|
|
1836
1917
|
const session = new AISession({
|
|
1837
1918
|
operationModel: "configured"
|
|
@@ -1840,35 +1921,33 @@ var BlueprintMachine = class {
|
|
|
1840
1921
|
session.message.pipeInto(this.message);
|
|
1841
1922
|
session.block.pipeInto(this.block);
|
|
1842
1923
|
const inputMessages = options.input ? [
|
|
1843
|
-
(0, import_echo_schema9.create)(
|
|
1924
|
+
(0, import_echo_schema9.create)(import_ai6.Message, {
|
|
1844
1925
|
role: "user",
|
|
1845
1926
|
content: [
|
|
1846
1927
|
taggedDataBlock("input", options.input)
|
|
1847
1928
|
]
|
|
1848
1929
|
})
|
|
1849
1930
|
] : [];
|
|
1850
|
-
inputMessages.forEach((message) =>
|
|
1931
|
+
inputMessages.forEach((message) => {
|
|
1932
|
+
this.message.emit(message);
|
|
1933
|
+
this.logger?.log({
|
|
1934
|
+
type: "message",
|
|
1935
|
+
message
|
|
1936
|
+
});
|
|
1937
|
+
});
|
|
1938
|
+
const tools = nextStep.tools?.map((tool) => this.registry.get(tool)).filter(import_util2.isNonNullable) ?? [];
|
|
1851
1939
|
const messages = await session.run({
|
|
1852
|
-
systemPrompt:
|
|
1853
|
-
You are a smart Rule-Following Agent.
|
|
1854
|
-
Rule-Following Agent executes the command that the user sent in the last message.
|
|
1855
|
-
After doing the work, the Rule-Following Agent calls report tool.
|
|
1856
|
-
If the Rule-Following agent believes that no action is needed, it calls the report tool with "skipped" status.
|
|
1857
|
-
If the Rule-Following Agent is unable to perform the task, it calls the report tool with "bail" status.
|
|
1858
|
-
Rule-Following Agent explains the reason it is unable to perform the task before bailing.
|
|
1859
|
-
The Rule-Following Agent can express creativity and imagination in the way it performs the task.
|
|
1860
|
-
The Rule-Following Agent precisely follows the instructions.
|
|
1861
|
-
`,
|
|
1940
|
+
systemPrompt: SYSTEM_PROMPT,
|
|
1862
1941
|
history: [
|
|
1863
1942
|
...state.history,
|
|
1864
1943
|
...inputMessages
|
|
1865
1944
|
],
|
|
1866
1945
|
tools: [
|
|
1867
|
-
...
|
|
1946
|
+
...tools,
|
|
1868
1947
|
report
|
|
1869
1948
|
],
|
|
1870
1949
|
artifacts: [],
|
|
1871
|
-
client: options.
|
|
1950
|
+
client: options.aiClient,
|
|
1872
1951
|
prompt: nextStep.instructions
|
|
1873
1952
|
});
|
|
1874
1953
|
const { messages: trimmedHistory, call: lastBlock } = popLastToolCall(messages);
|
|
@@ -1924,22 +2003,90 @@ var popLastToolCall = (messages) => {
|
|
|
1924
2003
|
};
|
|
1925
2004
|
};
|
|
1926
2005
|
import_chalk.default.level = 2;
|
|
1927
|
-
var
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
2006
|
+
var DEFAULT_LOGGER = {
|
|
2007
|
+
log: import_log10.log.info
|
|
2008
|
+
};
|
|
2009
|
+
var BufferedLogger = class {
|
|
2010
|
+
constructor() {
|
|
2011
|
+
this._messages = (0, import_signals_core.signal)([]);
|
|
2012
|
+
}
|
|
2013
|
+
get messages() {
|
|
2014
|
+
return this._messages;
|
|
2015
|
+
}
|
|
2016
|
+
clear() {
|
|
2017
|
+
this._messages.value = [];
|
|
2018
|
+
}
|
|
2019
|
+
log(message) {
|
|
2020
|
+
this._messages.value = [
|
|
2021
|
+
...this._messages.value,
|
|
2022
|
+
message
|
|
2023
|
+
];
|
|
1935
2024
|
}
|
|
1936
|
-
machine.begin.on(() => printTrace(machine.blueprint, machine.state));
|
|
1937
|
-
machine.stepComplete.on(() => printTrace(machine.blueprint, machine.state));
|
|
1938
2025
|
};
|
|
2026
|
+
var BlueprintLoggerAdapter = class {
|
|
2027
|
+
constructor(logger = DEFAULT_LOGGER) {
|
|
2028
|
+
this.logger = logger;
|
|
2029
|
+
}
|
|
2030
|
+
log(event) {
|
|
2031
|
+
switch (event.type) {
|
|
2032
|
+
case "begin":
|
|
2033
|
+
this.logger.log("begin");
|
|
2034
|
+
break;
|
|
2035
|
+
case "end":
|
|
2036
|
+
this.logger.log("end");
|
|
2037
|
+
break;
|
|
2038
|
+
case "step-start":
|
|
2039
|
+
this.logger.log("step-start", {
|
|
2040
|
+
step: event.step
|
|
2041
|
+
});
|
|
2042
|
+
break;
|
|
2043
|
+
case "step-complete":
|
|
2044
|
+
this.logger.log("step-complete", {
|
|
2045
|
+
step: event.step
|
|
2046
|
+
});
|
|
2047
|
+
break;
|
|
2048
|
+
case "message":
|
|
2049
|
+
this.logger.log("message", {
|
|
2050
|
+
message: event.message
|
|
2051
|
+
});
|
|
2052
|
+
break;
|
|
2053
|
+
case "block":
|
|
2054
|
+
this.logger.log("block", {
|
|
2055
|
+
block: event.block
|
|
2056
|
+
});
|
|
2057
|
+
break;
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
};
|
|
2061
|
+
var setLogger = (machine, logger) => {
|
|
2062
|
+
return (0, import_async5.combine)(machine.begin.on(() => {
|
|
2063
|
+
logger.log("Starting...");
|
|
2064
|
+
}), machine.stepStart.on((step) => {
|
|
2065
|
+
const index = machine.blueprint.steps.indexOf(step);
|
|
2066
|
+
logger.log(`Step ${index + 1} of ${machine.blueprint.steps.length}`);
|
|
2067
|
+
logger.log(`Instructions: ${step.instructions}`);
|
|
2068
|
+
}), machine.stepComplete.on((step) => {
|
|
2069
|
+
const trace = machine.state.trace.find((t) => t.stepId === step.id);
|
|
2070
|
+
logger.log(`Complete: ${trace?.comment}`);
|
|
2071
|
+
}), machine.end.on(() => {
|
|
2072
|
+
logger.log("OK");
|
|
2073
|
+
}));
|
|
2074
|
+
};
|
|
2075
|
+
var setConsolePrinter = (machine, verbose = false) => {
|
|
2076
|
+
const printer = new import_ai7.ConsolePrinter();
|
|
2077
|
+
return (0, import_async5.combine)(machine.begin.on(() => printTrace(machine.blueprint, machine.state)), machine.stepStart.on((step) => console.log(`
|
|
2078
|
+
${import_chalk.default.magenta(`${import_chalk.default.bold(`STEP ${machine.blueprint.steps.indexOf(step) + 1} of ${machine.blueprint.steps.length}:`)} ${step.instructions}`)}
|
|
2079
|
+
`)), machine.stepComplete.on(() => printTrace(machine.blueprint, machine.state)), machine.end.on(() => console.log("DONE")), verbose ? [
|
|
2080
|
+
machine.message.on((msg) => printer.printMessage(msg)),
|
|
2081
|
+
machine.block.on((block) => printer.printContentBlock(block))
|
|
2082
|
+
] : []);
|
|
2083
|
+
};
|
|
2084
|
+
var BREAK_LINE = `
|
|
2085
|
+
${"_".repeat(80)}
|
|
2086
|
+
`;
|
|
1939
2087
|
var printTrace = (blueprint, state) => {
|
|
1940
|
-
console.
|
|
1941
|
-
|
|
1942
|
-
blueprint.steps.forEach((step, index) => {
|
|
2088
|
+
console.group(import_chalk.default.bold("\nBlueprint"));
|
|
2089
|
+
blueprint.steps.forEach((step) => {
|
|
1943
2090
|
const traceStep = state.trace.find((t) => t.stepId === step.id);
|
|
1944
2091
|
let color = import_chalk.default.gray;
|
|
1945
2092
|
let bullet = "\u25CB";
|
|
@@ -1962,11 +2109,11 @@ var printTrace = (blueprint, state) => {
|
|
|
1962
2109
|
console.log(color(`
|
|
1963
2110
|
${bullet} ${step.instructions}`));
|
|
1964
2111
|
if (traceStep?.comment) {
|
|
1965
|
-
console.log(import_chalk.default.white(`
|
|
2112
|
+
console.log(import_chalk.default.white(` \u21B3 ${traceStep.comment}`));
|
|
1966
2113
|
}
|
|
1967
2114
|
});
|
|
1968
|
-
console.
|
|
1969
|
-
console.log(
|
|
2115
|
+
console.groupEnd();
|
|
2116
|
+
console.log(BREAK_LINE);
|
|
1970
2117
|
};
|
|
1971
2118
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1972
2119
|
0 && (module.exports = {
|
|
@@ -1974,9 +2121,12 @@ ${bullet} ${step.instructions}`));
|
|
|
1974
2121
|
AISession,
|
|
1975
2122
|
Blueprint,
|
|
1976
2123
|
BlueprintBuilder,
|
|
2124
|
+
BlueprintDefinition,
|
|
2125
|
+
BlueprintLoggerAdapter,
|
|
1977
2126
|
BlueprintMachine,
|
|
1978
2127
|
BlueprintParser,
|
|
1979
2128
|
BlueprintStep,
|
|
2129
|
+
BufferedLogger,
|
|
1980
2130
|
ExtractionInput,
|
|
1981
2131
|
ExtractionOutput,
|
|
1982
2132
|
ReferencedQuotes,
|
|
@@ -2001,6 +2151,7 @@ ${bullet} ${step.instructions}`));
|
|
|
2001
2151
|
processTranscriptMessage,
|
|
2002
2152
|
researchFn,
|
|
2003
2153
|
sanitizeObjects,
|
|
2004
|
-
setConsolePrinter
|
|
2154
|
+
setConsolePrinter,
|
|
2155
|
+
setLogger
|
|
2005
2156
|
});
|
|
2006
2157
|
//# sourceMappingURL=index.cjs.map
|