@dxos/blueprints 0.8.4-main.28f8d3d
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/browser/index.mjs +161 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/node-esm/index.mjs +162 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/types/src/blueprint/blueprint.d.ts +65 -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 +11 -0
- package/dist/types/src/blueprint/registry.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/index.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 +5 -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 +37 -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 +76 -0
- package/src/blueprint/index.ts +6 -0
- package/src/blueprint/registry.ts +36 -0
- package/src/index.ts +6 -0
- package/src/template/index.ts +6 -0
- package/src/template/prompt.test.ts +44 -0
- package/src/template/prompt.ts +21 -0
- package/src/template/template.ts +53 -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.28f8d3d",
|
|
4
|
+
"description": "Blueprint definitions.",
|
|
5
|
+
"homepage": "https://dxos.org",
|
|
6
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "DXOS.org",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"source": "./src/index.ts",
|
|
13
|
+
"types": "./dist/types/src/index.d.ts",
|
|
14
|
+
"browser": "./dist/lib/browser/index.mjs",
|
|
15
|
+
"node": "./dist/lib/node-esm/index.mjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"types": "dist/types/src/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"effect": "3.17.7",
|
|
25
|
+
"handlebars": "4.7.8",
|
|
26
|
+
"lodash.defaultsdeep": "^4.6.1",
|
|
27
|
+
"@dxos/ai": "0.8.4-main.28f8d3d",
|
|
28
|
+
"@dxos/echo": "0.8.4-main.28f8d3d",
|
|
29
|
+
"@dxos/invariant": "0.8.4-main.28f8d3d",
|
|
30
|
+
"@dxos/keys": "0.8.4-main.28f8d3d",
|
|
31
|
+
"@dxos/schema": "0.8.4-main.28f8d3d",
|
|
32
|
+
"@dxos/echo-schema": "0.8.4-main.28f8d3d",
|
|
33
|
+
"@dxos/util": "0.8.4-main.28f8d3d",
|
|
34
|
+
"@dxos/log": "0.8.4-main.28f8d3d"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/lodash.defaultsdeep": "^4.6.6"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"effect": "^3.13.3"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { ToolId } from '@dxos/ai';
|
|
8
|
+
import { Obj, Type } from '@dxos/echo';
|
|
9
|
+
import { LabelAnnotation } from '@dxos/echo-schema';
|
|
10
|
+
|
|
11
|
+
import { 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.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.Obj({
|
|
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
|
+
|
|
63
|
+
// TODO(burdon): Move to Type.Obj def?
|
|
64
|
+
LabelAnnotation.set(['name']),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* TypeScript type for Blueprint.
|
|
69
|
+
*/
|
|
70
|
+
export interface Blueprint extends Schema.Schema.Type<typeof Blueprint> {}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Create a new Blueprint.
|
|
74
|
+
*/
|
|
75
|
+
export const make = ({ tools = [], ...props }: Pick<Blueprint, 'key' | 'name' | 'instructions'> & Partial<Blueprint>) =>
|
|
76
|
+
Obj.make(Blueprint, { tools, ...props });
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
getByKey(key: string): Blueprint | undefined {
|
|
30
|
+
return this._blueprints.find((blueprint) => blueprint.key === key);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
query(): Blueprint[] {
|
|
34
|
+
return this._blueprints;
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.ts
ADDED
|
@@ -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,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import handlebars from 'handlebars';
|
|
6
|
+
import defaultsDeep from 'lodash.defaultsdeep';
|
|
7
|
+
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Process Handlebars template.
|
|
12
|
+
*/
|
|
13
|
+
export const process = <Options extends {}>(source: string, options: Options = {} as Options): string => {
|
|
14
|
+
invariant(source);
|
|
15
|
+
let section = 0;
|
|
16
|
+
handlebars.registerHelper('section', () => String(++section));
|
|
17
|
+
const template = handlebars.compile(source.trim());
|
|
18
|
+
return template(defaultsDeep({}, options, { suggestions: true }))
|
|
19
|
+
.trim()
|
|
20
|
+
.replace(/(\n\s*){3,}/g, '\n\n');
|
|
21
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { Ref, Type } from '@dxos/echo';
|
|
8
|
+
import { DataType } from '@dxos/schema';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Template input kind determines how template variables are resolved.
|
|
12
|
+
*/
|
|
13
|
+
export const InputKind = Schema.Literal(
|
|
14
|
+
'value', // Literal value.
|
|
15
|
+
'pass-through',
|
|
16
|
+
'retriever',
|
|
17
|
+
'function',
|
|
18
|
+
'query',
|
|
19
|
+
'resolver',
|
|
20
|
+
'context',
|
|
21
|
+
'schema',
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export type InputKind = Schema.Schema.Type<typeof InputKind>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Template input variable.
|
|
28
|
+
* E.g., {{foo}}
|
|
29
|
+
*/
|
|
30
|
+
export const Input = Schema.mutable(
|
|
31
|
+
Schema.Struct({
|
|
32
|
+
name: Schema.String,
|
|
33
|
+
kind: Schema.optional(InputKind),
|
|
34
|
+
default: Schema.optional(Schema.Any),
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export type Input = Schema.Schema.Type<typeof Input>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Template type.
|
|
42
|
+
*/
|
|
43
|
+
export const Template = Schema.Struct({
|
|
44
|
+
source: Type.Ref(DataType.Text).annotations({ description: 'Handlebars template source' }),
|
|
45
|
+
inputs: Schema.optional(Schema.mutable(Schema.Array(Input))),
|
|
46
|
+
}).pipe(Schema.mutable);
|
|
47
|
+
|
|
48
|
+
export interface Template extends Schema.Schema.Type<typeof Template> {}
|
|
49
|
+
|
|
50
|
+
export const make = ({ source, inputs = [] }: { source: string; inputs?: Input[] }): Template => ({
|
|
51
|
+
source: Ref.make(DataType.makeText(source)),
|
|
52
|
+
inputs,
|
|
53
|
+
});
|
|
@@ -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
|
+
}
|