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