@dxos/blueprints 0.8.4-main.3f58842
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 +153 -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 +154 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/types/src/artifacts.d.ts +40 -0
- package/dist/types/src/artifacts.d.ts.map +1 -0
- package/dist/types/src/blueprint/blueprint.d.ts +47 -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 +4 -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 +50 -0
- package/dist/types/src/template/template.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +44 -0
- package/src/artifacts.ts +60 -0
- package/src/blueprint/blueprint.ts +70 -0
- package/src/blueprint/index.ts +6 -0
- package/src/blueprint/registry.ts +22 -0
- package/src/index.ts +7 -0
- package/src/template/index.ts +6 -0
- package/src/template/prompt.test.ts +44 -0
- package/src/template/prompt.ts +19 -0
- package/src/template/template.ts +66 -0
- package/src/vite-env.d.ts +20 -0
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/blueprints",
|
|
3
|
+
"version": "0.8.4-main.3f58842",
|
|
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
|
+
"types": "./dist/types/src/index.d.ts",
|
|
13
|
+
"browser": "./dist/lib/browser/index.mjs",
|
|
14
|
+
"node": "./dist/lib/node-esm/index.mjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"types": "dist/types/src/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"src"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"effect": "3.17.0",
|
|
24
|
+
"handlebars": "4.7.8",
|
|
25
|
+
"lodash.defaultsdeep": "^4.6.1",
|
|
26
|
+
"@dxos/ai": "0.8.4-main.3f58842",
|
|
27
|
+
"@dxos/echo": "0.8.4-main.3f58842",
|
|
28
|
+
"@dxos/keys": "0.8.4-main.3f58842",
|
|
29
|
+
"@dxos/echo-schema": "0.8.4-main.3f58842",
|
|
30
|
+
"@dxos/log": "0.8.4-main.3f58842",
|
|
31
|
+
"@dxos/schema": "0.8.4-main.3f58842",
|
|
32
|
+
"@dxos/invariant": "0.8.4-main.3f58842",
|
|
33
|
+
"@dxos/util": "0.8.4-main.3f58842"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/lodash.defaultsdeep": "^4.6.6"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"effect": "^3.13.3"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/artifacts.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { type ExecutableTool } from '@dxos/ai';
|
|
8
|
+
import { type SpaceId } from '@dxos/keys';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated
|
|
12
|
+
*/
|
|
13
|
+
// TODO(burdon): Replace with Ref.
|
|
14
|
+
export type AssociatedArtifact = {
|
|
15
|
+
spaceId: SpaceId;
|
|
16
|
+
typename: string;
|
|
17
|
+
id: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Static artifact definition.
|
|
22
|
+
* @deprecated
|
|
23
|
+
*/
|
|
24
|
+
// TODO(burdon): Convert to effect schema.
|
|
25
|
+
export type ArtifactDefinition = {
|
|
26
|
+
// TODO(wittjosiah): Is this actually an ObjectId or should it be a uri?
|
|
27
|
+
// TODO(burdon): Plugin id?
|
|
28
|
+
id: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Name.
|
|
32
|
+
*/
|
|
33
|
+
name: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Description.
|
|
37
|
+
*/
|
|
38
|
+
description?: string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Instructions for how to use the artifact.
|
|
42
|
+
*/
|
|
43
|
+
// TODO(burdon): Reference template object.
|
|
44
|
+
instructions: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Schema that describes the shape of data which matches the artifact.
|
|
48
|
+
*/
|
|
49
|
+
schema: Schema.Schema.AnyNoContext;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Tools that can be used to act on data which matches the artifact.
|
|
53
|
+
*/
|
|
54
|
+
tools: ExecutableTool[];
|
|
55
|
+
|
|
56
|
+
// TODO(wittjosiah): Add `component` field for rendering data which matches the artifact?
|
|
57
|
+
// NOTE(burdon): I think that could just be provided separately by the plugin (since there might be multiple surface types).
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const defineArtifact = (definition: ArtifactDefinition): ArtifactDefinition => definition;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { ToolId } from '@dxos/ai';
|
|
8
|
+
import { 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: Type.Ref(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> {}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Blueprint } from './blueprint';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Blueprint registry.
|
|
9
|
+
*/
|
|
10
|
+
export class Registry {
|
|
11
|
+
constructor(private readonly _blueprints: Blueprint[]) {
|
|
12
|
+
this._blueprints.sort(({ name: a }, { name: b }) => a.localeCompare(b));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getByKey(key: string): Blueprint | undefined {
|
|
16
|
+
return this._blueprints.find((blueprint) => blueprint.key === key);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
query(): Blueprint[] {
|
|
20
|
+
return this._blueprints;
|
|
21
|
+
}
|
|
22
|
+
}
|
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 { createPrompt } 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 = createPrompt(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,19 @@
|
|
|
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 createPrompt = <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);
|
|
18
|
+
return template(defaultsDeep({}, options, { suggestions: true })).trim();
|
|
19
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { Obj, Ref, Type } from '@dxos/echo';
|
|
8
|
+
import { LabelAnnotation } from '@dxos/echo-schema';
|
|
9
|
+
import { DataType } 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.mutable(
|
|
32
|
+
Schema.Struct({
|
|
33
|
+
name: Schema.String,
|
|
34
|
+
kind: Schema.optional(InputKind),
|
|
35
|
+
default: Schema.optional(Schema.Any),
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export type Input = Schema.Schema.Type<typeof Input>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Template type.
|
|
43
|
+
*/
|
|
44
|
+
export const Template = Schema.Struct({
|
|
45
|
+
name: Schema.optional(Schema.String),
|
|
46
|
+
source: Type.Ref(DataType.Text).annotations({ description: 'Handlebars template source' }),
|
|
47
|
+
inputs: Schema.optional(Schema.mutable(Schema.Array(Input))),
|
|
48
|
+
}).pipe(
|
|
49
|
+
Type.Obj({
|
|
50
|
+
typename: 'dxos.org/type/Template',
|
|
51
|
+
version: '0.1.0',
|
|
52
|
+
}),
|
|
53
|
+
LabelAnnotation.set(['name']),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
export interface Template extends Schema.Schema.Type<typeof Template> {}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Creates a template.
|
|
60
|
+
*/
|
|
61
|
+
export const make = ({ source = '', ...props }: Partial<Omit<Template, 'source'> & { source: string }>) => {
|
|
62
|
+
return Obj.make(Template, {
|
|
63
|
+
source: Ref.make(Obj.make(DataType.Text, { content: source })),
|
|
64
|
+
...props,
|
|
65
|
+
});
|
|
66
|
+
};
|
|
@@ -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
|
+
}
|