@dxos/blueprints 0.8.4-main.1068cf700f
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/LICENSE +8 -0
- package/README.md +3 -0
- package/dist/lib/neutral/index.mjs +255 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/blueprint/blueprint.d.ts +60 -0
- package/dist/types/src/blueprint/blueprint.d.ts.map +1 -0
- package/dist/types/src/blueprint/index.d.ts +3 -0
- package/dist/types/src/blueprint/index.d.ts.map +1 -0
- package/dist/types/src/blueprint/registry.d.ts +12 -0
- package/dist/types/src/blueprint/registry.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/prompt/index.d.ts +2 -0
- package/dist/types/src/prompt/index.d.ts.map +1 -0
- package/dist/types/src/prompt/prompt.d.ts +54 -0
- package/dist/types/src/prompt/prompt.d.ts.map +1 -0
- package/dist/types/src/template/index.d.ts +3 -0
- package/dist/types/src/template/index.d.ts.map +1 -0
- package/dist/types/src/template/prompt.d.ts +10 -0
- package/dist/types/src/template/prompt.d.ts.map +1 -0
- package/dist/types/src/template/prompt.test.d.ts +2 -0
- package/dist/types/src/template/prompt.test.d.ts.map +1 -0
- package/dist/types/src/template/template.d.ts +46 -0
- package/dist/types/src/template/template.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +45 -0
- package/src/blueprint/blueprint.ts +91 -0
- package/src/blueprint/index.ts +6 -0
- package/src/blueprint/registry.ts +40 -0
- package/src/index.ts +7 -0
- package/src/prompt/index.ts +5 -0
- package/src/prompt/prompt.ts +79 -0
- package/src/template/index.ts +6 -0
- package/src/template/prompt.test.ts +44 -0
- package/src/template/prompt.ts +59 -0
- package/src/template/template.ts +61 -0
- package/src/vite-env.d.ts +20 -0
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/blueprints",
|
|
3
|
+
"version": "0.8.4-main.1068cf700f",
|
|
4
|
+
"description": "Blueprint definitions.",
|
|
5
|
+
"homepage": "https://dxos.org",
|
|
6
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "DXOS.org",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"source": "./src/index.ts",
|
|
17
|
+
"types": "./dist/types/src/index.d.ts",
|
|
18
|
+
"default": "./dist/lib/neutral/index.mjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"types": "dist/types/src/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"effect": "3.19.16",
|
|
28
|
+
"handlebars": "4.7.8",
|
|
29
|
+
"@dxos/ai": "0.8.4-main.1068cf700f",
|
|
30
|
+
"@dxos/functions": "0.8.4-main.1068cf700f",
|
|
31
|
+
"@dxos/keys": "0.8.4-main.1068cf700f",
|
|
32
|
+
"@dxos/invariant": "0.8.4-main.1068cf700f",
|
|
33
|
+
"@dxos/echo": "0.8.4-main.1068cf700f",
|
|
34
|
+
"@dxos/schema": "0.8.4-main.1068cf700f",
|
|
35
|
+
"@dxos/log": "0.8.4-main.1068cf700f",
|
|
36
|
+
"@dxos/util": "0.8.4-main.1068cf700f"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"effect": "3.19.16"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { ToolId } from '@dxos/ai';
|
|
8
|
+
import { Annotation, Obj, Type } from '@dxos/echo';
|
|
9
|
+
import { type FunctionDefinition } from '@dxos/functions';
|
|
10
|
+
|
|
11
|
+
import * as Template from '../template';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Blueprint schema defines the structure for AI assistant blueprints.
|
|
15
|
+
* Blueprints contain instructions, tools, and artifacts that guide the AI's behavior.
|
|
16
|
+
* Blueprints may use tools to create and read artifacts, which are managed by the assistant.
|
|
17
|
+
*/
|
|
18
|
+
export const Blueprint = Schema.Struct({
|
|
19
|
+
/**
|
|
20
|
+
* Global registry ID.
|
|
21
|
+
* NOTE: The `key` property refers to the original registry entry.
|
|
22
|
+
*/
|
|
23
|
+
// TODO(burdon): Create Format type for DXN-like ids, such as this and schema type.
|
|
24
|
+
key: Schema.String.annotations({
|
|
25
|
+
description: 'Unique registration key for the blueprint',
|
|
26
|
+
}),
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Human-readable name of the blueprint.
|
|
30
|
+
*/
|
|
31
|
+
name: Schema.String.annotations({
|
|
32
|
+
description: 'Human-readable name of the blueprint',
|
|
33
|
+
}),
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Description of the blueprint's purpose and functionality.
|
|
37
|
+
*/
|
|
38
|
+
description: Schema.optional(Schema.String).annotations({
|
|
39
|
+
description: "Description of the blueprint's purpose and functionality",
|
|
40
|
+
}),
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Instructions that guide the AI assistant's behavior and responses.
|
|
44
|
+
* These are system prompts or guidelines that the AI should follow.
|
|
45
|
+
*/
|
|
46
|
+
instructions: Template.Template.annotations({
|
|
47
|
+
description: "Instructions that guide the AI assistant's behavior and responses",
|
|
48
|
+
}),
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Array of tools that the AI assistant can use when this blueprint is active.
|
|
52
|
+
*/
|
|
53
|
+
tools: Schema.Array(ToolId).annotations({
|
|
54
|
+
description: 'Array of tools that the AI assistant can use when this blueprint is active',
|
|
55
|
+
}),
|
|
56
|
+
}).pipe(
|
|
57
|
+
Type.object({
|
|
58
|
+
// TODO(burdon): Is this a DXN? Need to create a Format type for these IDs.
|
|
59
|
+
typename: 'dxos.org/type/Blueprint',
|
|
60
|
+
version: '0.1.0',
|
|
61
|
+
}),
|
|
62
|
+
Annotation.LabelAnnotation.set(['name']),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* TypeScript type for Blueprint.
|
|
67
|
+
*/
|
|
68
|
+
export interface Blueprint extends Schema.Schema.Type<typeof Blueprint> {}
|
|
69
|
+
|
|
70
|
+
type MakeProps = Pick<Blueprint, 'key' | 'name'> & Partial<Blueprint>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Create a new Blueprint.
|
|
74
|
+
*/
|
|
75
|
+
export const make = ({ tools = [], instructions = Template.make(), ...props }: MakeProps) =>
|
|
76
|
+
Obj.make(Blueprint, {
|
|
77
|
+
tools,
|
|
78
|
+
instructions,
|
|
79
|
+
...props,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Util to create tool definitions for a blueprint.
|
|
84
|
+
*/
|
|
85
|
+
export const toolDefinitions = ({
|
|
86
|
+
tools = [],
|
|
87
|
+
functions = [],
|
|
88
|
+
}: {
|
|
89
|
+
tools?: string[];
|
|
90
|
+
functions?: FunctionDefinition[];
|
|
91
|
+
}) => [...functions.map((fn) => ToolId.make(fn.key)), ...tools.map((tool) => ToolId.make(tool))];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { log } from '@dxos/log';
|
|
6
|
+
|
|
7
|
+
import { type Blueprint } from './blueprint';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Blueprint registry.
|
|
11
|
+
*/
|
|
12
|
+
export class Registry {
|
|
13
|
+
private readonly _blueprints: Blueprint[] = [];
|
|
14
|
+
|
|
15
|
+
constructor(blueprints: Blueprint[]) {
|
|
16
|
+
const seen = new Set<string>();
|
|
17
|
+
blueprints.forEach((blueprint) => {
|
|
18
|
+
if (seen.has(blueprint.key)) {
|
|
19
|
+
log.warn('duplicate blueprint', { key: blueprint.key });
|
|
20
|
+
} else {
|
|
21
|
+
seen.add(blueprint.key);
|
|
22
|
+
this._blueprints.push(blueprint);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
this._blueprints.sort(({ name: a }, { name: b }) => a.localeCompare(b));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get blueprints(): Blueprint[] {
|
|
30
|
+
return this._blueprints;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getByKey(key: string): Blueprint | undefined {
|
|
34
|
+
return this._blueprints.find((blueprint) => blueprint.key === key);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
query(): Blueprint[] {
|
|
38
|
+
return this._blueprints;
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { Annotation, JsonSchema, Obj, type Ref, Type } from '@dxos/echo';
|
|
8
|
+
|
|
9
|
+
import { Blueprint } from '../blueprint';
|
|
10
|
+
import * as Template from '../template';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Executable instructions, which may use Blueprints.
|
|
14
|
+
* May reference additional context.
|
|
15
|
+
*/
|
|
16
|
+
export const Prompt = Schema.Struct({
|
|
17
|
+
/**
|
|
18
|
+
* Name of the prompt.
|
|
19
|
+
*/
|
|
20
|
+
name: Schema.optional(Schema.String),
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Description of the prompt's purpose and functionality.
|
|
24
|
+
* Allows AI agents to execute prompts automatically as tools.
|
|
25
|
+
*/
|
|
26
|
+
description: Schema.optional(Schema.String),
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Input schema of the prompt.
|
|
30
|
+
*/
|
|
31
|
+
input: JsonSchema.JsonSchema.pipe(Annotation.FormInputAnnotation.set(false)),
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Output schema of the prompt.
|
|
35
|
+
*/
|
|
36
|
+
output: JsonSchema.JsonSchema.pipe(Annotation.FormInputAnnotation.set(false)),
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Natural language instructions for the prompt.
|
|
40
|
+
* These should provide concrete course of action for the AI to follow.
|
|
41
|
+
*/
|
|
42
|
+
instructions: Template.Template.pipe(Annotation.FormInputAnnotation.set(false)),
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Blueprints that the prompt may utilize.
|
|
46
|
+
*/
|
|
47
|
+
blueprints: Schema.Array(Type.Ref(Blueprint)),
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Additional context that the prompt may utilize.
|
|
51
|
+
*/
|
|
52
|
+
context: Schema.Array(Schema.Any).pipe(Annotation.FormInputAnnotation.set(false)),
|
|
53
|
+
}).pipe(
|
|
54
|
+
Type.object({
|
|
55
|
+
typename: 'dxos.org/type/Prompt',
|
|
56
|
+
version: '0.1.0',
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export interface Prompt extends Schema.Schema.Type<typeof Prompt> {}
|
|
61
|
+
|
|
62
|
+
export const make = (params: {
|
|
63
|
+
name?: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
input?: Schema.Schema.AnyNoContext;
|
|
66
|
+
output?: Schema.Schema.AnyNoContext;
|
|
67
|
+
instructions?: string;
|
|
68
|
+
blueprints?: Ref.Ref<Blueprint>[];
|
|
69
|
+
context?: any[];
|
|
70
|
+
}): Prompt =>
|
|
71
|
+
Obj.make(Prompt, {
|
|
72
|
+
name: params.name,
|
|
73
|
+
description: params.description,
|
|
74
|
+
input: JsonSchema.toJsonSchema(params.input ?? Schema.Void),
|
|
75
|
+
output: JsonSchema.toJsonSchema(params.output ?? Schema.Void),
|
|
76
|
+
instructions: Template.make({ source: params.instructions }),
|
|
77
|
+
blueprints: params.blueprints ?? [],
|
|
78
|
+
context: params.context ?? [],
|
|
79
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { log } from '@dxos/log';
|
|
8
|
+
import { trim } from '@dxos/util';
|
|
9
|
+
|
|
10
|
+
import { process } from './prompt';
|
|
11
|
+
|
|
12
|
+
const TEMPLATE = trim`
|
|
13
|
+
You are a useful assistant.
|
|
14
|
+
|
|
15
|
+
## {{section}}. Rules
|
|
16
|
+
|
|
17
|
+
Use blueprints to create artifacts.
|
|
18
|
+
|
|
19
|
+
## {{section}}. Blueprints
|
|
20
|
+
|
|
21
|
+
{{#each blueprints}}
|
|
22
|
+
- {{this}}
|
|
23
|
+
{{/each}}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const BLUEPRINTS = [
|
|
27
|
+
// prettier-ignore
|
|
28
|
+
'Create a map.',
|
|
29
|
+
'Create a kanban.',
|
|
30
|
+
'Create a spreadsheet.',
|
|
31
|
+
'Create a task list.',
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
describe('prompt', () => {
|
|
35
|
+
test('should process template variables correctly', ({ expect }) => {
|
|
36
|
+
const prompt = process(TEMPLATE, {
|
|
37
|
+
blueprints: BLUEPRINTS,
|
|
38
|
+
suggestions: true,
|
|
39
|
+
});
|
|
40
|
+
log(prompt);
|
|
41
|
+
expect(prompt).to.include('## 2. Blueprints');
|
|
42
|
+
expect(prompt).to.include(BLUEPRINTS[0]);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import * as Record from 'effect/Record';
|
|
7
|
+
import handlebars from 'handlebars';
|
|
8
|
+
|
|
9
|
+
import { Database } from '@dxos/echo';
|
|
10
|
+
import type { ObjectNotFoundError } from '@dxos/echo/Err';
|
|
11
|
+
import {
|
|
12
|
+
type FunctionDefinition,
|
|
13
|
+
FunctionInvocationService,
|
|
14
|
+
type FunctionNotFoundError,
|
|
15
|
+
type TracingService,
|
|
16
|
+
} from '@dxos/functions';
|
|
17
|
+
import { invariant } from '@dxos/invariant';
|
|
18
|
+
import { log } from '@dxos/log';
|
|
19
|
+
|
|
20
|
+
import type { Template } from '..';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Process Handlebars template.
|
|
24
|
+
*/
|
|
25
|
+
export const process = <Options extends {}>(source: string, variables: Partial<Options> = {}): string => {
|
|
26
|
+
invariant(typeof source === 'string');
|
|
27
|
+
let section = 0;
|
|
28
|
+
handlebars.registerHelper('section', () => String(++section));
|
|
29
|
+
const template = handlebars.compile(source.trim());
|
|
30
|
+
const output = template(variables);
|
|
31
|
+
return output.trim().replace(/(\n\s*){3,}/g, '\n\n');
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const processTemplate = (
|
|
35
|
+
template: Template.Template,
|
|
36
|
+
): Effect.Effect<string, ObjectNotFoundError | FunctionNotFoundError, FunctionInvocationService | TracingService> =>
|
|
37
|
+
Effect.gen(function* () {
|
|
38
|
+
const functionInvoker = yield* FunctionInvocationService;
|
|
39
|
+
|
|
40
|
+
const variables = yield* Effect.forEach(template.inputs ?? [], (input) =>
|
|
41
|
+
Effect.gen(function* () {
|
|
42
|
+
if (input.kind === 'function') {
|
|
43
|
+
const fn = (yield* functionInvoker.resolveFunction(input.function!)) as FunctionDefinition<
|
|
44
|
+
{},
|
|
45
|
+
unknown,
|
|
46
|
+
never
|
|
47
|
+
>;
|
|
48
|
+
const result = yield* functionInvoker.invokeFunction(fn, {});
|
|
49
|
+
return [input.name, result] as const;
|
|
50
|
+
} else {
|
|
51
|
+
return yield* Effect.dieMessage(`Unsupported input kind: ${input.kind}`);
|
|
52
|
+
}
|
|
53
|
+
}),
|
|
54
|
+
).pipe(Effect.map(Record.fromEntries));
|
|
55
|
+
|
|
56
|
+
log('processTemplate', { variables });
|
|
57
|
+
|
|
58
|
+
return process((yield* Database.load(template.source)).content, variables);
|
|
59
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { Ref, Type } from '@dxos/echo';
|
|
8
|
+
import { type ObjectId } from '@dxos/keys';
|
|
9
|
+
import { Text } from '@dxos/schema';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Template input kind determines how template variables are resolved.
|
|
13
|
+
*/
|
|
14
|
+
export const InputKind = Schema.Literal(
|
|
15
|
+
'value', // Literal value.
|
|
16
|
+
'pass-through',
|
|
17
|
+
'retriever',
|
|
18
|
+
'function',
|
|
19
|
+
'query',
|
|
20
|
+
'resolver',
|
|
21
|
+
'context',
|
|
22
|
+
'schema',
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export type InputKind = Schema.Schema.Type<typeof InputKind>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Template input variable.
|
|
29
|
+
* E.g., {{foo}}
|
|
30
|
+
*/
|
|
31
|
+
export const Input = Schema.Struct({
|
|
32
|
+
name: Schema.String,
|
|
33
|
+
kind: Schema.optional(InputKind),
|
|
34
|
+
default: Schema.optional(Schema.Any),
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Function to call if the kind is 'function'.
|
|
38
|
+
*/
|
|
39
|
+
function: Schema.optional(Schema.String),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export type Input = Schema.Schema.Type<typeof Input>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Template type.
|
|
46
|
+
*/
|
|
47
|
+
export const Template = Schema.Struct({
|
|
48
|
+
source: Type.Ref(Text.Text).annotations({ description: 'Handlebars template source' }),
|
|
49
|
+
inputs: Schema.optional(Schema.Array(Input)),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export interface Template extends Schema.Schema.Type<typeof Template> {}
|
|
53
|
+
|
|
54
|
+
export const make = ({
|
|
55
|
+
source,
|
|
56
|
+
inputs = [],
|
|
57
|
+
id,
|
|
58
|
+
}: { source?: string; inputs?: Input[]; id?: ObjectId } = {}): Template => ({
|
|
59
|
+
source: Ref.make(Text.make(source, id)),
|
|
60
|
+
inputs,
|
|
61
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
//
|
|
4
|
+
// Copyright 2025 DXOS.org
|
|
5
|
+
//
|
|
6
|
+
|
|
7
|
+
declare module '*.txt?raw' {
|
|
8
|
+
const content: string;
|
|
9
|
+
export default content;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare module '*.md?raw' {
|
|
13
|
+
const content: string;
|
|
14
|
+
export default content;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare module '*?raw' {
|
|
18
|
+
const content: string;
|
|
19
|
+
export default content;
|
|
20
|
+
}
|