@dxos/assistant 0.8.3-main.672df60 → 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 +107 -39
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +110 -41
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +107 -39
- 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 +13 -10
- package/dist/types/src/blueprint/blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprint/logger.d.ts +16 -3
- package/dist/types/src/blueprint/logger.d.ts.map +1 -1
- package/dist/types/src/blueprint/machine.d.ts +29 -14
- package/dist/types/src/blueprint/machine.d.ts.map +1 -1
- package/dist/types/src/research/graph.d.ts +2 -2
- package/dist/types/src/research/graph.d.ts.map +1 -1
- package/package.json +29 -20
- package/src/blueprint/ai.test.ts +156 -0
- package/src/blueprint/blueprint.test.ts +18 -16
- package/src/blueprint/blueprint.ts +18 -14
- package/src/blueprint/logger.ts +49 -3
- package/src/blueprint/machine.ts +59 -27
- package/src/research/graph.ts +4 -4
- package/src/research/research.test.ts +1 -1
- package/src/research/research.ts +1 -1
|
@@ -1625,13 +1625,13 @@ var preprocessSchema = (schema) => {
|
|
|
1625
1625
|
})
|
|
1626
1626
|
})) : identity);
|
|
1627
1627
|
};
|
|
1628
|
-
var createGraphWriterTool = ({ db, queue,
|
|
1628
|
+
var createGraphWriterTool = ({ db, queue, schema, onDone = async (x) => x }) => {
|
|
1629
1629
|
return createTool3("graph", {
|
|
1630
1630
|
name: "writer",
|
|
1631
1631
|
description: "Write to the local graph database",
|
|
1632
|
-
schema: createExtractionSchema(
|
|
1632
|
+
schema: createExtractionSchema(schema),
|
|
1633
1633
|
execute: async (input) => {
|
|
1634
|
-
const data = await sanitizeObjects(
|
|
1634
|
+
const data = await sanitizeObjects(schema, input, db, queue);
|
|
1635
1635
|
return ToolResult3.Success(await onDone(data));
|
|
1636
1636
|
}
|
|
1637
1637
|
});
|
|
@@ -1700,7 +1700,7 @@ var researchFn = defineFunction3({
|
|
|
1700
1700
|
}));
|
|
1701
1701
|
const graphWriteTool = createGraphWriterTool({
|
|
1702
1702
|
db,
|
|
1703
|
-
|
|
1703
|
+
schema: DataTypes
|
|
1704
1704
|
});
|
|
1705
1705
|
log8.info("graphWriteTool", {
|
|
1706
1706
|
schema: graphWriteTool.parameters
|
|
@@ -1732,19 +1732,18 @@ var createArtifactElement = (id) => `<artifact id=${id} />`;
|
|
|
1732
1732
|
|
|
1733
1733
|
// packages/core/assistant/src/blueprint/blueprint.ts
|
|
1734
1734
|
import { Schema as Schema8 } from "effect";
|
|
1735
|
-
import { Obj, Type } from "@dxos/echo";
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
id: ObjectId4,
|
|
1735
|
+
import { Key, Obj, Type } from "@dxos/echo";
|
|
1736
|
+
var BlueprintStep = Schema8.Struct({
|
|
1737
|
+
id: Key.ObjectId,
|
|
1739
1738
|
instructions: Schema8.String,
|
|
1740
|
-
tools: Schema8.Array(Schema8.String)
|
|
1739
|
+
tools: Schema8.optional(Schema8.Array(Schema8.String))
|
|
1741
1740
|
});
|
|
1742
|
-
var
|
|
1743
|
-
steps: Schema8.Array(
|
|
1741
|
+
var BlueprintDefinition = Schema8.Struct({
|
|
1742
|
+
steps: Schema8.Array(BlueprintStep.pipe(Schema8.omit("id")))
|
|
1744
1743
|
});
|
|
1745
1744
|
var Blueprint = Schema8.Struct({
|
|
1746
1745
|
name: Schema8.optional(Schema8.String),
|
|
1747
|
-
steps: Schema8.Array(
|
|
1746
|
+
steps: Schema8.Array(BlueprintStep)
|
|
1748
1747
|
}).pipe(Type.Obj({
|
|
1749
1748
|
typename: "dxos.org/type/Blueprint",
|
|
1750
1749
|
version: "0.1.0"
|
|
@@ -1757,7 +1756,7 @@ var Blueprint = Schema8.Struct({
|
|
|
1757
1756
|
}
|
|
1758
1757
|
step(instructions, options) {
|
|
1759
1758
|
this._steps.push({
|
|
1760
|
-
id:
|
|
1759
|
+
id: Key.ObjectId.random(),
|
|
1761
1760
|
instructions,
|
|
1762
1761
|
tools: options?.tools ?? []
|
|
1763
1762
|
});
|
|
@@ -1795,6 +1794,16 @@ import { create as create6 } from "@dxos/echo-schema";
|
|
|
1795
1794
|
import { log as log9 } from "@dxos/log";
|
|
1796
1795
|
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
1797
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
|
+
`;
|
|
1798
1807
|
var INITIAL_STATE = {
|
|
1799
1808
|
state: "working",
|
|
1800
1809
|
history: [],
|
|
@@ -1810,39 +1819,61 @@ var BlueprintMachine = class {
|
|
|
1810
1819
|
this.stepComplete = new Event2();
|
|
1811
1820
|
this.message = new Event2();
|
|
1812
1821
|
this.block = new Event2();
|
|
1813
|
-
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;
|
|
1814
1830
|
}
|
|
1815
1831
|
async runToCompletion(options) {
|
|
1816
1832
|
log9.info("runToCompletion", options, {
|
|
1817
1833
|
F: __dxlog_file9,
|
|
1818
|
-
L:
|
|
1834
|
+
L: 106,
|
|
1819
1835
|
S: this,
|
|
1820
1836
|
C: (f, a) => f(...a)
|
|
1821
1837
|
});
|
|
1822
1838
|
this.begin.emit();
|
|
1839
|
+
this.logger?.log({
|
|
1840
|
+
type: "begin"
|
|
1841
|
+
});
|
|
1823
1842
|
let firstStep = true;
|
|
1824
|
-
while (this.
|
|
1843
|
+
while (this._state.state !== "done") {
|
|
1825
1844
|
const input = firstStep ? options.input : void 0;
|
|
1826
1845
|
firstStep = false;
|
|
1827
|
-
this.
|
|
1846
|
+
this._state = await this._execStep(this._state, {
|
|
1828
1847
|
input,
|
|
1829
|
-
|
|
1848
|
+
aiClient: options.aiClient
|
|
1849
|
+
});
|
|
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
|
|
1830
1855
|
});
|
|
1831
|
-
|
|
1832
|
-
if (this.state.state === "bail") {
|
|
1856
|
+
if (this._state.state === "bail") {
|
|
1833
1857
|
throw new Error("Agent unable to follow the blueprint");
|
|
1834
1858
|
}
|
|
1835
1859
|
}
|
|
1836
1860
|
this.end.emit();
|
|
1861
|
+
this.logger?.log({
|
|
1862
|
+
type: "end"
|
|
1863
|
+
});
|
|
1837
1864
|
}
|
|
1838
1865
|
async _execStep(state, options) {
|
|
1839
|
-
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);
|
|
1840
1867
|
if (prevStep === this.blueprint.steps.length - 1) {
|
|
1841
1868
|
throw new Error("Done execution blueprint");
|
|
1842
1869
|
}
|
|
1843
1870
|
const nextStep = this.blueprint.steps[prevStep + 1];
|
|
1844
1871
|
const onLastStep = prevStep === this.blueprint.steps.length - 2;
|
|
1845
1872
|
this.stepStart.emit(nextStep);
|
|
1873
|
+
this.logger?.log({
|
|
1874
|
+
type: "step-start",
|
|
1875
|
+
step: nextStep
|
|
1876
|
+
});
|
|
1846
1877
|
const ReportSchema = Schema9.Struct({
|
|
1847
1878
|
status: Schema9.Literal("done", "bailed", "skipped").annotations({
|
|
1848
1879
|
description: "The status of the task completion"
|
|
@@ -1853,7 +1884,7 @@ var BlueprintMachine = class {
|
|
|
1853
1884
|
});
|
|
1854
1885
|
const report = createTool4("system", {
|
|
1855
1886
|
name: "report",
|
|
1856
|
-
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.",
|
|
1857
1888
|
schema: ReportSchema,
|
|
1858
1889
|
execute: async (input) => ToolResult4.Break(input)
|
|
1859
1890
|
});
|
|
@@ -1871,19 +1902,16 @@ var BlueprintMachine = class {
|
|
|
1871
1902
|
]
|
|
1872
1903
|
})
|
|
1873
1904
|
] : [];
|
|
1874
|
-
inputMessages.forEach((message) =>
|
|
1875
|
-
|
|
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) ?? [];
|
|
1876
1913
|
const messages = await session.run({
|
|
1877
|
-
systemPrompt:
|
|
1878
|
-
You are a smart Rule-Following Agent.
|
|
1879
|
-
Rule-Following Agent executes the command that the user sent in the last message.
|
|
1880
|
-
After doing the work, the Rule-Following Agent calls report tool.
|
|
1881
|
-
If the Rule-Following agent believes that no action is needed, it calls the report tool with "skipped" status.
|
|
1882
|
-
If the Rule-Following Agent is unable to perform the task, it calls the report tool with "bail" status.
|
|
1883
|
-
Rule-Following Agent explains the reason it is unable to perform the task before bailing.
|
|
1884
|
-
The Rule-Following Agent can express creativity and imagination in the way it performs the task.
|
|
1885
|
-
The Rule-Following Agent precisely follows the instructions.
|
|
1886
|
-
`,
|
|
1914
|
+
systemPrompt: SYSTEM_PROMPT,
|
|
1887
1915
|
history: [
|
|
1888
1916
|
...state.history,
|
|
1889
1917
|
...inputMessages
|
|
@@ -1893,7 +1921,7 @@ var BlueprintMachine = class {
|
|
|
1893
1921
|
report
|
|
1894
1922
|
],
|
|
1895
1923
|
artifacts: [],
|
|
1896
|
-
client: options.
|
|
1924
|
+
client: options.aiClient,
|
|
1897
1925
|
prompt: nextStep.instructions
|
|
1898
1926
|
});
|
|
1899
1927
|
const { messages: trimmedHistory, call: lastBlock } = popLastToolCall(messages);
|
|
@@ -1954,8 +1982,12 @@ import { signal } from "@preact/signals-core";
|
|
|
1954
1982
|
import chalk from "chalk";
|
|
1955
1983
|
import { ConsolePrinter as ConsolePrinter2 } from "@dxos/ai";
|
|
1956
1984
|
import { combine } from "@dxos/async";
|
|
1985
|
+
import { log as log10 } from "@dxos/log";
|
|
1957
1986
|
chalk.level = 2;
|
|
1958
|
-
var
|
|
1987
|
+
var DEFAULT_LOGGER = {
|
|
1988
|
+
log: log10.info
|
|
1989
|
+
};
|
|
1990
|
+
var BufferedLogger = class {
|
|
1959
1991
|
constructor() {
|
|
1960
1992
|
this._messages = signal([]);
|
|
1961
1993
|
}
|
|
@@ -1972,6 +2004,41 @@ var Logger = class {
|
|
|
1972
2004
|
];
|
|
1973
2005
|
}
|
|
1974
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
|
+
};
|
|
1975
2042
|
var setLogger = (machine, logger) => {
|
|
1976
2043
|
return combine(machine.begin.on(() => {
|
|
1977
2044
|
logger.log("Starting...");
|
|
@@ -2034,13 +2101,14 @@ export {
|
|
|
2034
2101
|
AISession,
|
|
2035
2102
|
Blueprint,
|
|
2036
2103
|
BlueprintBuilder,
|
|
2104
|
+
BlueprintDefinition,
|
|
2105
|
+
BlueprintLoggerAdapter,
|
|
2037
2106
|
BlueprintMachine,
|
|
2038
2107
|
BlueprintParser,
|
|
2039
|
-
|
|
2040
|
-
|
|
2108
|
+
BlueprintStep,
|
|
2109
|
+
BufferedLogger,
|
|
2041
2110
|
ExtractionInput,
|
|
2042
2111
|
ExtractionOutput,
|
|
2043
|
-
Logger,
|
|
2044
2112
|
ReferencedQuotes,
|
|
2045
2113
|
Subgraph,
|
|
2046
2114
|
VersionPin,
|