@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
|
@@ -1396,11 +1396,11 @@ import { DataTypes } from "@dxos/schema";
|
|
|
1396
1396
|
import { Schema as Schema6, identity, Option as Option2, SchemaAST } from "effect";
|
|
1397
1397
|
import { createTool as createTool3, ToolResult as ToolResult3 } from "@dxos/ai";
|
|
1398
1398
|
import { isEncodedReference } from "@dxos/echo-protocol";
|
|
1399
|
-
import { EntityKind, getSchemaTypename, getTypeAnnotation, getTypeIdentifierAnnotation, create as create4, Filter as Filter2, getEntityKind, getSchemaDXN, ObjectId as ObjectId3, Query as Query2, ReferenceAnnotationId, RelationSourceId, RelationTargetId } from "@dxos/echo-schema";
|
|
1399
|
+
import { EntityKind, getSchemaTypename, getTypeAnnotation, getTypeIdentifierAnnotation, create as create4, Filter as Filter2, getEntityKind, getSchemaDXN, ObjectId as ObjectId3, Query as Query2, ReferenceAnnotationId, RelationSourceDXNId, RelationTargetDXNId, RelationSourceId, RelationTargetId } from "@dxos/echo-schema";
|
|
1400
1400
|
import { mapAst } from "@dxos/effect";
|
|
1401
1401
|
import { DXN as DXN2 } from "@dxos/keys";
|
|
1402
1402
|
import { log as log7 } from "@dxos/log";
|
|
1403
|
-
import { deepMapValues } from "@dxos/util";
|
|
1403
|
+
import { deepMapValues, isNonNullable } from "@dxos/util";
|
|
1404
1404
|
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/assistant/src/research/graph.ts";
|
|
1405
1405
|
var Subgraph = Schema6.Struct({
|
|
1406
1406
|
/** Objects and relations. */
|
|
@@ -1430,7 +1430,7 @@ var isSchemaAddressableByDxn = (schema, dxn) => {
|
|
|
1430
1430
|
}
|
|
1431
1431
|
return false;
|
|
1432
1432
|
};
|
|
1433
|
-
var createLocalSearchTool = (db) => {
|
|
1433
|
+
var createLocalSearchTool = (db, queue) => {
|
|
1434
1434
|
return createTool3("search", {
|
|
1435
1435
|
name: "local_search",
|
|
1436
1436
|
description: "Search the local database for information using a vector index",
|
|
@@ -1443,9 +1443,16 @@ var createLocalSearchTool = (db) => {
|
|
|
1443
1443
|
const { objects } = await db.query(Query2.select(Filter2.text(query, {
|
|
1444
1444
|
type: "vector"
|
|
1445
1445
|
}))).run();
|
|
1446
|
+
const results = [
|
|
1447
|
+
...objects
|
|
1448
|
+
];
|
|
1449
|
+
if (queue) {
|
|
1450
|
+
const queueObjects = await queue.queryObjects();
|
|
1451
|
+
results.push(...queueObjects);
|
|
1452
|
+
}
|
|
1446
1453
|
return ToolResult3.Success(`
|
|
1447
1454
|
<local_context>
|
|
1448
|
-
${JSON.stringify(
|
|
1455
|
+
${JSON.stringify(results, null, 2)}
|
|
1449
1456
|
</local_context>
|
|
1450
1457
|
`);
|
|
1451
1458
|
}
|
|
@@ -1464,13 +1471,14 @@ var createExtractionSchema = (types) => {
|
|
|
1464
1471
|
var getSanitizedSchemaName = (schema) => {
|
|
1465
1472
|
return getSchemaDXN(schema).asTypeDXN().type.replaceAll(/[^a-zA-Z0-9]+/g, "_");
|
|
1466
1473
|
};
|
|
1467
|
-
var sanitizeObjects = async (types, data, db) => {
|
|
1474
|
+
var sanitizeObjects = async (types, data, db, queue) => {
|
|
1468
1475
|
const entries = types.map((type) => data[`objects_${getSanitizedSchemaName(type)}`]?.map((object) => ({
|
|
1469
1476
|
data: object,
|
|
1470
1477
|
schema: type
|
|
1471
1478
|
})) ?? []).flat();
|
|
1472
1479
|
const idMap = /* @__PURE__ */ new Map();
|
|
1473
1480
|
const existingIds = /* @__PURE__ */ new Set();
|
|
1481
|
+
const enitties = /* @__PURE__ */ new Map();
|
|
1474
1482
|
const resolveId = (id) => {
|
|
1475
1483
|
if (ObjectId3.isValid(id)) {
|
|
1476
1484
|
existingIds.add(id);
|
|
@@ -1513,7 +1521,7 @@ var sanitizeObjects = async (types, data, db) => {
|
|
|
1513
1521
|
source: data2.source
|
|
1514
1522
|
}, {
|
|
1515
1523
|
F: __dxlog_file7,
|
|
1516
|
-
L:
|
|
1524
|
+
L: 216,
|
|
1517
1525
|
S: void 0,
|
|
1518
1526
|
C: (f, a) => f(...a)
|
|
1519
1527
|
});
|
|
@@ -1524,25 +1532,36 @@ var sanitizeObjects = async (types, data, db) => {
|
|
|
1524
1532
|
target: data2.target
|
|
1525
1533
|
}, {
|
|
1526
1534
|
F: __dxlog_file7,
|
|
1527
|
-
L:
|
|
1535
|
+
L: 220,
|
|
1528
1536
|
S: void 0,
|
|
1529
1537
|
C: (f, a) => f(...a)
|
|
1530
1538
|
});
|
|
1531
1539
|
}
|
|
1532
1540
|
delete data2.source;
|
|
1533
1541
|
delete data2.target;
|
|
1534
|
-
data2[
|
|
1535
|
-
data2[
|
|
1542
|
+
data2[RelationSourceDXNId] = sourceDxn;
|
|
1543
|
+
data2[RelationTargetDXNId] = targetDxn;
|
|
1536
1544
|
}
|
|
1537
|
-
return
|
|
1538
|
-
|
|
1539
|
-
|
|
1545
|
+
return {
|
|
1546
|
+
data: data2,
|
|
1547
|
+
schema: entry.schema
|
|
1548
|
+
};
|
|
1549
|
+
}).filter((object) => !existingIds.has(object.data.id));
|
|
1550
|
+
const { objects: dbObjects } = await db.query(Query2.select(Filter2.ids(...existingIds))).run();
|
|
1551
|
+
const queueObjects = await queue?.getObjectsById([
|
|
1552
|
+
...existingIds
|
|
1553
|
+
]) ?? [];
|
|
1554
|
+
const objects = [
|
|
1555
|
+
...dbObjects,
|
|
1556
|
+
...queueObjects
|
|
1557
|
+
].filter(isNonNullable);
|
|
1540
1558
|
log7.info("objects", {
|
|
1541
|
-
|
|
1559
|
+
dbObjects,
|
|
1560
|
+
queueObjects,
|
|
1542
1561
|
existingIds
|
|
1543
1562
|
}, {
|
|
1544
1563
|
F: __dxlog_file7,
|
|
1545
|
-
L:
|
|
1564
|
+
L: 241,
|
|
1546
1565
|
S: void 0,
|
|
1547
1566
|
C: (f, a) => f(...a)
|
|
1548
1567
|
});
|
|
@@ -1550,7 +1569,37 @@ var sanitizeObjects = async (types, data, db) => {
|
|
|
1550
1569
|
if (missing.length > 0) {
|
|
1551
1570
|
throw new Error(`Object IDs do not point to existing objects: ${missing.join(", ")}`);
|
|
1552
1571
|
}
|
|
1553
|
-
return res
|
|
1572
|
+
return res.flatMap(({ data: data2, schema }) => {
|
|
1573
|
+
let skip = false;
|
|
1574
|
+
if (RelationSourceDXNId in data2) {
|
|
1575
|
+
const id = data2[RelationSourceDXNId].asEchoDXN()?.echoId;
|
|
1576
|
+
const obj = objects.find((object) => object.id === id) ?? enitties.get(id);
|
|
1577
|
+
if (obj) {
|
|
1578
|
+
delete data2[RelationSourceDXNId];
|
|
1579
|
+
data2[RelationSourceId] = obj;
|
|
1580
|
+
} else {
|
|
1581
|
+
skip = true;
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
if (RelationTargetDXNId in data2) {
|
|
1585
|
+
const id = data2[RelationTargetDXNId].asEchoDXN()?.echoId;
|
|
1586
|
+
const obj = objects.find((object) => object.id === id) ?? enitties.get(id);
|
|
1587
|
+
if (obj) {
|
|
1588
|
+
delete data2[RelationTargetDXNId];
|
|
1589
|
+
data2[RelationTargetId] = obj;
|
|
1590
|
+
} else {
|
|
1591
|
+
skip = true;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
if (!skip) {
|
|
1595
|
+
const obj = create4(schema, data2);
|
|
1596
|
+
enitties.set(obj.id, obj);
|
|
1597
|
+
return [
|
|
1598
|
+
obj
|
|
1599
|
+
];
|
|
1600
|
+
}
|
|
1601
|
+
return [];
|
|
1602
|
+
});
|
|
1554
1603
|
};
|
|
1555
1604
|
var SoftRef = Schema6.Struct({
|
|
1556
1605
|
"/": Schema6.String
|
|
@@ -1578,13 +1627,13 @@ var preprocessSchema = (schema) => {
|
|
|
1578
1627
|
})
|
|
1579
1628
|
})) : identity);
|
|
1580
1629
|
};
|
|
1581
|
-
var createGraphWriterTool = ({ db,
|
|
1630
|
+
var createGraphWriterTool = ({ db, queue, schema, onDone = async (x) => x }) => {
|
|
1582
1631
|
return createTool3("graph", {
|
|
1583
1632
|
name: "writer",
|
|
1584
1633
|
description: "Write to the local graph database",
|
|
1585
|
-
schema: createExtractionSchema(
|
|
1634
|
+
schema: createExtractionSchema(schema),
|
|
1586
1635
|
execute: async (input) => {
|
|
1587
|
-
const data = await sanitizeObjects(
|
|
1636
|
+
const data = await sanitizeObjects(schema, input, db, queue);
|
|
1588
1637
|
return ToolResult3.Success(await onDone(data));
|
|
1589
1638
|
}
|
|
1590
1639
|
});
|
|
@@ -1653,7 +1702,7 @@ var researchFn = defineFunction3({
|
|
|
1653
1702
|
}));
|
|
1654
1703
|
const graphWriteTool = createGraphWriterTool({
|
|
1655
1704
|
db,
|
|
1656
|
-
|
|
1705
|
+
schema: DataTypes
|
|
1657
1706
|
});
|
|
1658
1707
|
log8.info("graphWriteTool", {
|
|
1659
1708
|
schema: graphWriteTool.parameters
|
|
@@ -1685,18 +1734,22 @@ var createArtifactElement = (id) => `<artifact id=${id} />`;
|
|
|
1685
1734
|
|
|
1686
1735
|
// packages/core/assistant/src/blueprint/blueprint.ts
|
|
1687
1736
|
import { Schema as Schema8 } from "effect";
|
|
1688
|
-
import {
|
|
1689
|
-
import { raise } from "@dxos/debug";
|
|
1690
|
-
import { ObjectId as ObjectId4 } from "@dxos/keys";
|
|
1737
|
+
import { Key, Obj, Type } from "@dxos/echo";
|
|
1691
1738
|
var BlueprintStep = Schema8.Struct({
|
|
1692
|
-
id:
|
|
1739
|
+
id: Key.ObjectId,
|
|
1693
1740
|
instructions: Schema8.String,
|
|
1694
|
-
|
|
1695
|
-
tools: Schema8.Array(Tool).pipe(Schema8.mutable)
|
|
1741
|
+
tools: Schema8.optional(Schema8.Array(Schema8.String))
|
|
1696
1742
|
});
|
|
1697
|
-
var
|
|
1698
|
-
steps: Schema8.Array(BlueprintStep
|
|
1743
|
+
var BlueprintDefinition = Schema8.Struct({
|
|
1744
|
+
steps: Schema8.Array(BlueprintStep.pipe(Schema8.omit("id")))
|
|
1699
1745
|
});
|
|
1746
|
+
var Blueprint = Schema8.Struct({
|
|
1747
|
+
name: Schema8.optional(Schema8.String),
|
|
1748
|
+
steps: Schema8.Array(BlueprintStep)
|
|
1749
|
+
}).pipe(Type.Obj({
|
|
1750
|
+
typename: "dxos.org/type/Blueprint",
|
|
1751
|
+
version: "0.1.0"
|
|
1752
|
+
}));
|
|
1700
1753
|
(function(BlueprintBuilder2) {
|
|
1701
1754
|
BlueprintBuilder2.create = () => new Builder();
|
|
1702
1755
|
class Builder {
|
|
@@ -1705,40 +1758,27 @@ var Blueprint = Schema8.Struct({
|
|
|
1705
1758
|
}
|
|
1706
1759
|
step(instructions, options) {
|
|
1707
1760
|
this._steps.push({
|
|
1708
|
-
id:
|
|
1761
|
+
id: Key.ObjectId.random(),
|
|
1709
1762
|
instructions,
|
|
1710
1763
|
tools: options?.tools ?? []
|
|
1711
1764
|
});
|
|
1712
1765
|
return this;
|
|
1713
1766
|
}
|
|
1714
1767
|
build() {
|
|
1715
|
-
return {
|
|
1768
|
+
return Obj.make(Blueprint, {
|
|
1716
1769
|
steps: this._steps
|
|
1717
|
-
};
|
|
1770
|
+
});
|
|
1718
1771
|
}
|
|
1719
1772
|
}
|
|
1720
1773
|
})(BlueprintBuilder || (BlueprintBuilder = {}));
|
|
1721
1774
|
(function(BlueprintParser2) {
|
|
1722
|
-
BlueprintParser2.create = (
|
|
1775
|
+
BlueprintParser2.create = () => new Parser();
|
|
1723
1776
|
class Parser {
|
|
1724
|
-
constructor(_tools) {
|
|
1725
|
-
this._tools = _tools;
|
|
1726
|
-
}
|
|
1727
|
-
toJSON() {
|
|
1728
|
-
return {
|
|
1729
|
-
tools: this._tools.map((tool) => ({
|
|
1730
|
-
name: tool.name,
|
|
1731
|
-
namespace: tool.namespace,
|
|
1732
|
-
type: tool.type
|
|
1733
|
-
}))
|
|
1734
|
-
};
|
|
1735
|
-
}
|
|
1736
1777
|
parse({ steps }) {
|
|
1737
1778
|
const builder = BlueprintBuilder.create();
|
|
1738
1779
|
for (const step of steps) {
|
|
1739
1780
|
builder.step(step.instructions, {
|
|
1740
|
-
|
|
1741
|
-
tools: step.tools?.map((tool) => this._tools.find(({ id }) => id === tool) ?? raise(new Error(`Tool not found: ${tool}`)))
|
|
1781
|
+
tools: step.tools ?? []
|
|
1742
1782
|
});
|
|
1743
1783
|
}
|
|
1744
1784
|
return builder.build();
|
|
@@ -1754,14 +1794,26 @@ import { createTool as createTool4, Message as Message3, ToolResult as ToolResul
|
|
|
1754
1794
|
import { Event as Event2 } from "@dxos/async";
|
|
1755
1795
|
import { create as create6 } from "@dxos/echo-schema";
|
|
1756
1796
|
import { log as log9 } from "@dxos/log";
|
|
1797
|
+
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
1757
1798
|
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/assistant/src/blueprint/machine.ts";
|
|
1799
|
+
var SYSTEM_PROMPT = `
|
|
1800
|
+
You are a smart Rule-Following Agent.
|
|
1801
|
+
Rule-Following Agent executes the command that the user sent in the last message.
|
|
1802
|
+
After doing the work, the Rule-Following Agent calls report tool.
|
|
1803
|
+
If the Rule-Following agent believes that no action is needed, it calls the report tool with "skipped" status.
|
|
1804
|
+
If the Rule-Following Agent is unable to perform the task, it calls the report tool with "bail" status.
|
|
1805
|
+
Rule-Following Agent explains the reason it is unable to perform the task before bailing.
|
|
1806
|
+
The Rule-Following Agent can express creativity and imagination in the way it performs the task.
|
|
1807
|
+
The Rule-Following Agent precisely follows the instructions.
|
|
1808
|
+
`;
|
|
1758
1809
|
var INITIAL_STATE = {
|
|
1759
1810
|
state: "working",
|
|
1760
1811
|
history: [],
|
|
1761
1812
|
trace: []
|
|
1762
1813
|
};
|
|
1763
1814
|
var BlueprintMachine = class {
|
|
1764
|
-
constructor(blueprint) {
|
|
1815
|
+
constructor(registry, blueprint) {
|
|
1816
|
+
this.registry = registry;
|
|
1765
1817
|
this.blueprint = blueprint;
|
|
1766
1818
|
this.begin = new Event2();
|
|
1767
1819
|
this.end = new Event2();
|
|
@@ -1769,39 +1821,61 @@ var BlueprintMachine = class {
|
|
|
1769
1821
|
this.stepComplete = new Event2();
|
|
1770
1822
|
this.message = new Event2();
|
|
1771
1823
|
this.block = new Event2();
|
|
1772
|
-
this.
|
|
1824
|
+
this._state = structuredClone(INITIAL_STATE);
|
|
1825
|
+
}
|
|
1826
|
+
get state() {
|
|
1827
|
+
return this._state;
|
|
1828
|
+
}
|
|
1829
|
+
setLogger(logger) {
|
|
1830
|
+
this.logger = logger;
|
|
1831
|
+
return this;
|
|
1773
1832
|
}
|
|
1774
1833
|
async runToCompletion(options) {
|
|
1775
1834
|
log9.info("runToCompletion", options, {
|
|
1776
1835
|
F: __dxlog_file9,
|
|
1777
|
-
L:
|
|
1836
|
+
L: 106,
|
|
1778
1837
|
S: this,
|
|
1779
1838
|
C: (f, a) => f(...a)
|
|
1780
1839
|
});
|
|
1781
1840
|
this.begin.emit();
|
|
1841
|
+
this.logger?.log({
|
|
1842
|
+
type: "begin"
|
|
1843
|
+
});
|
|
1782
1844
|
let firstStep = true;
|
|
1783
|
-
while (this.
|
|
1845
|
+
while (this._state.state !== "done") {
|
|
1784
1846
|
const input = firstStep ? options.input : void 0;
|
|
1785
1847
|
firstStep = false;
|
|
1786
|
-
this.
|
|
1848
|
+
this._state = await this._execStep(this._state, {
|
|
1787
1849
|
input,
|
|
1788
|
-
|
|
1850
|
+
aiClient: options.aiClient
|
|
1789
1851
|
});
|
|
1790
|
-
this.
|
|
1791
|
-
|
|
1852
|
+
const step = this.blueprint.steps.find((step2) => step2.id === this._state.trace.at(-1)?.stepId);
|
|
1853
|
+
this.stepComplete.emit(step);
|
|
1854
|
+
this.logger?.log({
|
|
1855
|
+
type: "step-complete",
|
|
1856
|
+
step
|
|
1857
|
+
});
|
|
1858
|
+
if (this._state.state === "bail") {
|
|
1792
1859
|
throw new Error("Agent unable to follow the blueprint");
|
|
1793
1860
|
}
|
|
1794
1861
|
}
|
|
1795
1862
|
this.end.emit();
|
|
1863
|
+
this.logger?.log({
|
|
1864
|
+
type: "end"
|
|
1865
|
+
});
|
|
1796
1866
|
}
|
|
1797
1867
|
async _execStep(state, options) {
|
|
1798
|
-
const prevStep = this.blueprint.steps.findIndex((step) => step.id === this.
|
|
1868
|
+
const prevStep = this.blueprint.steps.findIndex((step) => step.id === this._state.trace.at(-1)?.stepId);
|
|
1799
1869
|
if (prevStep === this.blueprint.steps.length - 1) {
|
|
1800
1870
|
throw new Error("Done execution blueprint");
|
|
1801
1871
|
}
|
|
1802
1872
|
const nextStep = this.blueprint.steps[prevStep + 1];
|
|
1803
1873
|
const onLastStep = prevStep === this.blueprint.steps.length - 2;
|
|
1804
1874
|
this.stepStart.emit(nextStep);
|
|
1875
|
+
this.logger?.log({
|
|
1876
|
+
type: "step-start",
|
|
1877
|
+
step: nextStep
|
|
1878
|
+
});
|
|
1805
1879
|
const ReportSchema = Schema9.Struct({
|
|
1806
1880
|
status: Schema9.Literal("done", "bailed", "skipped").annotations({
|
|
1807
1881
|
description: "The status of the task completion"
|
|
@@ -1812,7 +1886,7 @@ var BlueprintMachine = class {
|
|
|
1812
1886
|
});
|
|
1813
1887
|
const report = createTool4("system", {
|
|
1814
1888
|
name: "report",
|
|
1815
|
-
description: "This tool reports that the agent has completed the task or is unable to do so",
|
|
1889
|
+
description: "This tool reports that the agent has completed the task or is unable to do so.",
|
|
1816
1890
|
schema: ReportSchema,
|
|
1817
1891
|
execute: async (input) => ToolResult4.Break(input)
|
|
1818
1892
|
});
|
|
@@ -1830,28 +1904,26 @@ var BlueprintMachine = class {
|
|
|
1830
1904
|
]
|
|
1831
1905
|
})
|
|
1832
1906
|
] : [];
|
|
1833
|
-
inputMessages.forEach((message) =>
|
|
1907
|
+
inputMessages.forEach((message) => {
|
|
1908
|
+
this.message.emit(message);
|
|
1909
|
+
this.logger?.log({
|
|
1910
|
+
type: "message",
|
|
1911
|
+
message
|
|
1912
|
+
});
|
|
1913
|
+
});
|
|
1914
|
+
const tools = nextStep.tools?.map((tool) => this.registry.get(tool)).filter(isNonNullable2) ?? [];
|
|
1834
1915
|
const messages = await session.run({
|
|
1835
|
-
systemPrompt:
|
|
1836
|
-
You are a smart Rule-Following Agent.
|
|
1837
|
-
Rule-Following Agent executes the command that the user sent in the last message.
|
|
1838
|
-
After doing the work, the Rule-Following Agent calls report tool.
|
|
1839
|
-
If the Rule-Following agent believes that no action is needed, it calls the report tool with "skipped" status.
|
|
1840
|
-
If the Rule-Following Agent is unable to perform the task, it calls the report tool with "bail" status.
|
|
1841
|
-
Rule-Following Agent explains the reason it is unable to perform the task before bailing.
|
|
1842
|
-
The Rule-Following Agent can express creativity and imagination in the way it performs the task.
|
|
1843
|
-
The Rule-Following Agent precisely follows the instructions.
|
|
1844
|
-
`,
|
|
1916
|
+
systemPrompt: SYSTEM_PROMPT,
|
|
1845
1917
|
history: [
|
|
1846
1918
|
...state.history,
|
|
1847
1919
|
...inputMessages
|
|
1848
1920
|
],
|
|
1849
1921
|
tools: [
|
|
1850
|
-
...
|
|
1922
|
+
...tools,
|
|
1851
1923
|
report
|
|
1852
1924
|
],
|
|
1853
1925
|
artifacts: [],
|
|
1854
|
-
client: options.
|
|
1926
|
+
client: options.aiClient,
|
|
1855
1927
|
prompt: nextStep.instructions
|
|
1856
1928
|
});
|
|
1857
1929
|
const { messages: trimmedHistory, call: lastBlock } = popLastToolCall(messages);
|
|
@@ -1908,25 +1980,96 @@ var popLastToolCall = (messages) => {
|
|
|
1908
1980
|
};
|
|
1909
1981
|
|
|
1910
1982
|
// packages/core/assistant/src/blueprint/logger.ts
|
|
1983
|
+
import { signal } from "@preact/signals-core";
|
|
1911
1984
|
import chalk from "chalk";
|
|
1912
1985
|
import { ConsolePrinter as ConsolePrinter2 } from "@dxos/ai";
|
|
1986
|
+
import { combine } from "@dxos/async";
|
|
1987
|
+
import { log as log10 } from "@dxos/log";
|
|
1913
1988
|
chalk.level = 2;
|
|
1914
|
-
var
|
|
1989
|
+
var DEFAULT_LOGGER = {
|
|
1990
|
+
log: log10.info
|
|
1991
|
+
};
|
|
1992
|
+
var BufferedLogger = class {
|
|
1993
|
+
constructor() {
|
|
1994
|
+
this._messages = signal([]);
|
|
1995
|
+
}
|
|
1996
|
+
get messages() {
|
|
1997
|
+
return this._messages;
|
|
1998
|
+
}
|
|
1999
|
+
clear() {
|
|
2000
|
+
this._messages.value = [];
|
|
2001
|
+
}
|
|
2002
|
+
log(message) {
|
|
2003
|
+
this._messages.value = [
|
|
2004
|
+
...this._messages.value,
|
|
2005
|
+
message
|
|
2006
|
+
];
|
|
2007
|
+
}
|
|
2008
|
+
};
|
|
2009
|
+
var BlueprintLoggerAdapter = class {
|
|
2010
|
+
constructor(logger = DEFAULT_LOGGER) {
|
|
2011
|
+
this.logger = logger;
|
|
2012
|
+
}
|
|
2013
|
+
log(event) {
|
|
2014
|
+
switch (event.type) {
|
|
2015
|
+
case "begin":
|
|
2016
|
+
this.logger.log("begin");
|
|
2017
|
+
break;
|
|
2018
|
+
case "end":
|
|
2019
|
+
this.logger.log("end");
|
|
2020
|
+
break;
|
|
2021
|
+
case "step-start":
|
|
2022
|
+
this.logger.log("step-start", {
|
|
2023
|
+
step: event.step
|
|
2024
|
+
});
|
|
2025
|
+
break;
|
|
2026
|
+
case "step-complete":
|
|
2027
|
+
this.logger.log("step-complete", {
|
|
2028
|
+
step: event.step
|
|
2029
|
+
});
|
|
2030
|
+
break;
|
|
2031
|
+
case "message":
|
|
2032
|
+
this.logger.log("message", {
|
|
2033
|
+
message: event.message
|
|
2034
|
+
});
|
|
2035
|
+
break;
|
|
2036
|
+
case "block":
|
|
2037
|
+
this.logger.log("block", {
|
|
2038
|
+
block: event.block
|
|
2039
|
+
});
|
|
2040
|
+
break;
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
var setLogger = (machine, logger) => {
|
|
2045
|
+
return combine(machine.begin.on(() => {
|
|
2046
|
+
logger.log("Starting...");
|
|
2047
|
+
}), machine.stepStart.on((step) => {
|
|
2048
|
+
const index = machine.blueprint.steps.indexOf(step);
|
|
2049
|
+
logger.log(`Step ${index + 1} of ${machine.blueprint.steps.length}`);
|
|
2050
|
+
logger.log(`Instructions: ${step.instructions}`);
|
|
2051
|
+
}), machine.stepComplete.on((step) => {
|
|
2052
|
+
const trace = machine.state.trace.find((t) => t.stepId === step.id);
|
|
2053
|
+
logger.log(`Complete: ${trace?.comment}`);
|
|
2054
|
+
}), machine.end.on(() => {
|
|
2055
|
+
logger.log("OK");
|
|
2056
|
+
}));
|
|
2057
|
+
};
|
|
2058
|
+
var setConsolePrinter = (machine, verbose = false) => {
|
|
1915
2059
|
const printer = new ConsolePrinter2();
|
|
1916
|
-
|
|
1917
|
-
machine.stepStart.on((step) => console.log(`
|
|
2060
|
+
return combine(machine.begin.on(() => printTrace(machine.blueprint, machine.state)), machine.stepStart.on((step) => console.log(`
|
|
1918
2061
|
${chalk.magenta(`${chalk.bold(`STEP ${machine.blueprint.steps.indexOf(step) + 1} of ${machine.blueprint.steps.length}:`)} ${step.instructions}`)}
|
|
1919
|
-
`))
|
|
1920
|
-
machine.message.on((msg) => printer.printMessage(msg))
|
|
1921
|
-
machine.block.on((block) => printer.printContentBlock(block))
|
|
1922
|
-
|
|
1923
|
-
machine.begin.on(() => printTrace(machine.blueprint, machine.state));
|
|
1924
|
-
machine.stepComplete.on(() => printTrace(machine.blueprint, machine.state));
|
|
2062
|
+
`)), machine.stepComplete.on(() => printTrace(machine.blueprint, machine.state)), machine.end.on(() => console.log("DONE")), verbose ? [
|
|
2063
|
+
machine.message.on((msg) => printer.printMessage(msg)),
|
|
2064
|
+
machine.block.on((block) => printer.printContentBlock(block))
|
|
2065
|
+
] : []);
|
|
1925
2066
|
};
|
|
2067
|
+
var BREAK_LINE = `
|
|
2068
|
+
${"_".repeat(80)}
|
|
2069
|
+
`;
|
|
1926
2070
|
var printTrace = (blueprint, state) => {
|
|
1927
|
-
console.
|
|
1928
|
-
|
|
1929
|
-
blueprint.steps.forEach((step, index) => {
|
|
2071
|
+
console.group(chalk.bold("\nBlueprint"));
|
|
2072
|
+
blueprint.steps.forEach((step) => {
|
|
1930
2073
|
const traceStep = state.trace.find((t) => t.stepId === step.id);
|
|
1931
2074
|
let color = chalk.gray;
|
|
1932
2075
|
let bullet = "\u25CB";
|
|
@@ -1949,20 +2092,23 @@ var printTrace = (blueprint, state) => {
|
|
|
1949
2092
|
console.log(color(`
|
|
1950
2093
|
${bullet} ${step.instructions}`));
|
|
1951
2094
|
if (traceStep?.comment) {
|
|
1952
|
-
console.log(chalk.white(`
|
|
2095
|
+
console.log(chalk.white(` \u21B3 ${traceStep.comment}`));
|
|
1953
2096
|
}
|
|
1954
2097
|
});
|
|
1955
|
-
console.
|
|
1956
|
-
console.log(
|
|
2098
|
+
console.groupEnd();
|
|
2099
|
+
console.log(BREAK_LINE);
|
|
1957
2100
|
};
|
|
1958
2101
|
export {
|
|
1959
2102
|
AIServiecOverloadedError,
|
|
1960
2103
|
AISession,
|
|
1961
2104
|
Blueprint,
|
|
1962
2105
|
BlueprintBuilder,
|
|
2106
|
+
BlueprintDefinition,
|
|
2107
|
+
BlueprintLoggerAdapter,
|
|
1963
2108
|
BlueprintMachine,
|
|
1964
2109
|
BlueprintParser,
|
|
1965
2110
|
BlueprintStep,
|
|
2111
|
+
BufferedLogger,
|
|
1966
2112
|
ExtractionInput,
|
|
1967
2113
|
ExtractionOutput,
|
|
1968
2114
|
ReferencedQuotes,
|
|
@@ -1987,6 +2133,7 @@ export {
|
|
|
1987
2133
|
processTranscriptMessage,
|
|
1988
2134
|
researchFn,
|
|
1989
2135
|
sanitizeObjects,
|
|
1990
|
-
setConsolePrinter
|
|
2136
|
+
setConsolePrinter,
|
|
2137
|
+
setLogger
|
|
1991
2138
|
};
|
|
1992
2139
|
//# sourceMappingURL=index.mjs.map
|