@dxos/blueprints 0.8.4-main.72ec0f3 → 0.8.4-main.937b3ca
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 +61 -31
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +61 -31
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/blueprint/blueprint.d.ts +29 -42
- package/dist/types/src/blueprint/blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprint/registry.d.ts +1 -0
- package/dist/types/src/blueprint/registry.d.ts.map +1 -1
- package/dist/types/src/prompt/prompt.d.ts +37 -64
- package/dist/types/src/prompt/prompt.d.ts.map +1 -1
- package/dist/types/src/template/prompt.d.ts +5 -0
- package/dist/types/src/template/prompt.d.ts.map +1 -1
- package/dist/types/src/template/template.d.ts +10 -3
- package/dist/types/src/template/template.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -11
- package/src/blueprint/blueprint.ts +11 -11
- package/src/blueprint/registry.ts +4 -0
- package/src/prompt/prompt.ts +11 -16
- package/src/template/prompt.ts +40 -0
- package/src/template/template.ts +10 -7
|
@@ -16,8 +16,7 @@ __export(blueprint_exports, {
|
|
|
16
16
|
// src/blueprint/blueprint.ts
|
|
17
17
|
import * as Schema2 from "effect/Schema";
|
|
18
18
|
import { ToolId } from "@dxos/ai";
|
|
19
|
-
import { Obj, Type as Type2 } from "@dxos/echo";
|
|
20
|
-
import { LabelAnnotation } from "@dxos/echo/internal";
|
|
19
|
+
import { Annotation, Obj, Type as Type2 } from "@dxos/echo";
|
|
21
20
|
|
|
22
21
|
// src/template/index.ts
|
|
23
22
|
var template_exports = {};
|
|
@@ -26,17 +25,23 @@ __export(template_exports, {
|
|
|
26
25
|
InputKind: () => InputKind,
|
|
27
26
|
Template: () => Template,
|
|
28
27
|
make: () => make,
|
|
29
|
-
process: () => process
|
|
28
|
+
process: () => process,
|
|
29
|
+
processTemplate: () => processTemplate
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
// src/template/prompt.ts
|
|
33
|
+
import * as Effect from "effect/Effect";
|
|
34
|
+
import * as Record from "effect/Record";
|
|
33
35
|
import handlebars from "handlebars";
|
|
36
|
+
import { Database } from "@dxos/echo";
|
|
37
|
+
import { FunctionInvocationService } from "@dxos/functions";
|
|
34
38
|
import { invariant } from "@dxos/invariant";
|
|
39
|
+
import { log } from "@dxos/log";
|
|
35
40
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/blueprints/src/template/prompt.ts";
|
|
36
41
|
var process = (source, variables = {}) => {
|
|
37
42
|
invariant(typeof source === "string", void 0, {
|
|
38
43
|
F: __dxlog_file,
|
|
39
|
-
L:
|
|
44
|
+
L: 26,
|
|
40
45
|
S: void 0,
|
|
41
46
|
A: [
|
|
42
47
|
"typeof source === 'string'",
|
|
@@ -49,17 +54,45 @@ var process = (source, variables = {}) => {
|
|
|
49
54
|
const output = template(variables);
|
|
50
55
|
return output.trim().replace(/(\n\s*){3,}/g, "\n\n");
|
|
51
56
|
};
|
|
57
|
+
var processTemplate = (template) => Effect.gen(function* () {
|
|
58
|
+
const functionInvoker = yield* FunctionInvocationService;
|
|
59
|
+
const variables = yield* Effect.forEach(template.inputs ?? [], (input) => Effect.gen(function* () {
|
|
60
|
+
if (input.kind === "function") {
|
|
61
|
+
const fn = yield* functionInvoker.resolveFunction(input.function);
|
|
62
|
+
const result = yield* functionInvoker.invokeFunction(fn, {});
|
|
63
|
+
return [
|
|
64
|
+
input.name,
|
|
65
|
+
result
|
|
66
|
+
];
|
|
67
|
+
} else {
|
|
68
|
+
return yield* Effect.dieMessage(`Unsupported input kind: ${input.kind}`);
|
|
69
|
+
}
|
|
70
|
+
})).pipe(Effect.map(Record.fromEntries));
|
|
71
|
+
log("processTemplate", {
|
|
72
|
+
variables
|
|
73
|
+
}, {
|
|
74
|
+
F: __dxlog_file,
|
|
75
|
+
L: 56,
|
|
76
|
+
S: this,
|
|
77
|
+
C: (f, a) => f(...a)
|
|
78
|
+
});
|
|
79
|
+
return process((yield* Database.Service.load(template.source)).content, variables);
|
|
80
|
+
});
|
|
52
81
|
|
|
53
82
|
// src/template/template.ts
|
|
54
83
|
import * as Schema from "effect/Schema";
|
|
55
84
|
import { Ref, Type } from "@dxos/echo";
|
|
56
85
|
import { Text } from "@dxos/schema";
|
|
57
86
|
var InputKind = Schema.Literal("value", "pass-through", "retriever", "function", "query", "resolver", "context", "schema");
|
|
58
|
-
var Input = Schema.
|
|
87
|
+
var Input = Schema.Struct({
|
|
59
88
|
name: Schema.String,
|
|
60
89
|
kind: Schema.optional(InputKind),
|
|
61
|
-
default: Schema.optional(Schema.Any)
|
|
62
|
-
|
|
90
|
+
default: Schema.optional(Schema.Any),
|
|
91
|
+
/**
|
|
92
|
+
* Function to call if the kind is 'function'.
|
|
93
|
+
*/
|
|
94
|
+
function: Schema.optional(Schema.String)
|
|
95
|
+
}).pipe(Schema.mutable);
|
|
63
96
|
var Template = Schema.Struct({
|
|
64
97
|
source: Type.Ref(Text.Text).annotations({
|
|
65
98
|
description: "Handlebars template source"
|
|
@@ -106,17 +139,13 @@ var Blueprint = Schema2.Struct({
|
|
|
106
139
|
tools: Schema2.Array(ToolId).annotations({
|
|
107
140
|
description: "Array of tools that the AI assistant can use when this blueprint is active"
|
|
108
141
|
})
|
|
109
|
-
}).pipe(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
LabelAnnotation.set([
|
|
117
|
-
"name"
|
|
118
|
-
])
|
|
119
|
-
);
|
|
142
|
+
}).pipe(Type2.object({
|
|
143
|
+
// TODO(burdon): Is this a DXN? Need to create a Format type for these IDs.
|
|
144
|
+
typename: "dxos.org/type/Blueprint",
|
|
145
|
+
version: "0.1.0"
|
|
146
|
+
}), Annotation.LabelAnnotation.set([
|
|
147
|
+
"name"
|
|
148
|
+
]));
|
|
120
149
|
var make2 = ({ tools = [], instructions = make(), ...props }) => Obj.make(Blueprint, {
|
|
121
150
|
tools,
|
|
122
151
|
instructions,
|
|
@@ -128,7 +157,7 @@ var toolDefinitions = ({ tools = [], functions = [] }) => [
|
|
|
128
157
|
];
|
|
129
158
|
|
|
130
159
|
// src/blueprint/registry.ts
|
|
131
|
-
import { log } from "@dxos/log";
|
|
160
|
+
import { log as log2 } from "@dxos/log";
|
|
132
161
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/blueprints/src/blueprint/registry.ts";
|
|
133
162
|
var Registry = class {
|
|
134
163
|
_blueprints = [];
|
|
@@ -136,7 +165,7 @@ var Registry = class {
|
|
|
136
165
|
const seen = /* @__PURE__ */ new Set();
|
|
137
166
|
blueprints.forEach((blueprint) => {
|
|
138
167
|
if (seen.has(blueprint.key)) {
|
|
139
|
-
|
|
168
|
+
log2.warn("duplicate blueprint", {
|
|
140
169
|
key: blueprint.key
|
|
141
170
|
}, {
|
|
142
171
|
F: __dxlog_file2,
|
|
@@ -151,6 +180,9 @@ var Registry = class {
|
|
|
151
180
|
});
|
|
152
181
|
this._blueprints.sort(({ name: a }, { name: b }) => a.localeCompare(b));
|
|
153
182
|
}
|
|
183
|
+
get blueprints() {
|
|
184
|
+
return this._blueprints;
|
|
185
|
+
}
|
|
154
186
|
getByKey(key) {
|
|
155
187
|
return this._blueprints.find((blueprint) => blueprint.key === key);
|
|
156
188
|
}
|
|
@@ -168,9 +200,8 @@ __export(prompt_exports, {
|
|
|
168
200
|
|
|
169
201
|
// src/prompt/prompt.ts
|
|
170
202
|
import * as Schema3 from "effect/Schema";
|
|
171
|
-
import { Obj as Obj2, Type as Type3 } from "@dxos/echo";
|
|
172
|
-
|
|
173
|
-
var Prompt_ = Schema3.Struct({
|
|
203
|
+
import { Annotation as Annotation2, JsonSchema, Obj as Obj2, Type as Type3 } from "@dxos/echo";
|
|
204
|
+
var Prompt = Schema3.Struct({
|
|
174
205
|
/**
|
|
175
206
|
* Name of the prompt.
|
|
176
207
|
*/
|
|
@@ -183,16 +214,16 @@ var Prompt_ = Schema3.Struct({
|
|
|
183
214
|
/**
|
|
184
215
|
* Input schema of the prompt.
|
|
185
216
|
*/
|
|
186
|
-
input:
|
|
217
|
+
input: JsonSchema.JsonSchema.pipe(Annotation2.FormInputAnnotation.set(false)),
|
|
187
218
|
/**
|
|
188
219
|
* Output schema of the prompt.
|
|
189
220
|
*/
|
|
190
|
-
output:
|
|
221
|
+
output: JsonSchema.JsonSchema.pipe(Annotation2.FormInputAnnotation.set(false)),
|
|
191
222
|
/**
|
|
192
223
|
* Natural language instructions for the prompt.
|
|
193
224
|
* These should provide concrete course of action for the AI to follow.
|
|
194
225
|
*/
|
|
195
|
-
instructions: Template.pipe(
|
|
226
|
+
instructions: Template.pipe(Annotation2.FormInputAnnotation.set(false)),
|
|
196
227
|
/**
|
|
197
228
|
* Blueprints that the prompt may utilize.
|
|
198
229
|
*/
|
|
@@ -200,17 +231,16 @@ var Prompt_ = Schema3.Struct({
|
|
|
200
231
|
/**
|
|
201
232
|
* Additional context that the prompt may utilize.
|
|
202
233
|
*/
|
|
203
|
-
context: Schema3.Array(Schema3.Any).pipe(
|
|
204
|
-
}).pipe(Type3.
|
|
234
|
+
context: Schema3.Array(Schema3.Any).pipe(Annotation2.FormInputAnnotation.set(false))
|
|
235
|
+
}).pipe(Type3.object({
|
|
205
236
|
typename: "dxos.org/type/Prompt",
|
|
206
237
|
version: "0.1.0"
|
|
207
238
|
}));
|
|
208
|
-
var Prompt = Prompt_;
|
|
209
239
|
var make3 = (params) => Obj2.make(Prompt, {
|
|
210
240
|
name: params.name,
|
|
211
241
|
description: params.description,
|
|
212
|
-
input: toJsonSchema(params.input ?? Schema3.Void),
|
|
213
|
-
output: toJsonSchema(params.output ?? Schema3.Void),
|
|
242
|
+
input: JsonSchema.toJsonSchema(params.input ?? Schema3.Void),
|
|
243
|
+
output: JsonSchema.toJsonSchema(params.output ?? Schema3.Void),
|
|
214
244
|
instructions: make({
|
|
215
245
|
source: params.instructions
|
|
216
246
|
}),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/blueprint/index.ts", "../../../src/blueprint/blueprint.ts", "../../../src/template/index.ts", "../../../src/template/prompt.ts", "../../../src/template/template.ts", "../../../src/blueprint/registry.ts", "../../../src/prompt/index.ts", "../../../src/prompt/prompt.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport * from './blueprint';\nexport * from './registry';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { ToolId } from '@dxos/ai';\nimport { Obj, Type } from '@dxos/echo';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;AAAA;;;;cAAAA;EAAA;;;;ACIA,YAAYC,aAAY;AAExB,SAASC,cAAc;AACvB,SAASC,KAAKC,QAAAA,aAAY;
|
|
6
|
-
"names": ["make", "Schema", "ToolId", "Obj", "Type", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport * from './blueprint';\nexport * from './registry';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { ToolId } from '@dxos/ai';\nimport { Annotation, Obj, Type } from '@dxos/echo';\nimport { type FunctionDefinition } from '@dxos/functions';\n\nimport * as Template from '../template';\n\n/**\n * Blueprint schema defines the structure for AI assistant blueprints.\n * Blueprints contain instructions, tools, and artifacts that guide the AI's behavior.\n * Blueprints may use tools to create and read artifacts, which are managed by the assistant.\n */\nexport const Blueprint = Schema.Struct({\n /**\n * Global registry ID.\n * NOTE: The `key` property refers to the original registry entry.\n */\n // TODO(burdon): Create Format type for DXN-like ids, such as this and schema type.\n key: Schema.String.annotations({\n description: 'Unique registration key for the blueprint',\n }),\n\n /**\n * Human-readable name of the blueprint.\n */\n name: Schema.String.annotations({\n description: 'Human-readable name of the blueprint',\n }),\n\n /**\n * Description of the blueprint's purpose and functionality.\n */\n description: Schema.optional(Schema.String).annotations({\n description: \"Description of the blueprint's purpose and functionality\",\n }),\n\n /**\n * Instructions that guide the AI assistant's behavior and responses.\n * These are system prompts or guidelines that the AI should follow.\n */\n instructions: Template.Template.annotations({\n description: \"Instructions that guide the AI assistant's behavior and responses\",\n }),\n\n /**\n * Array of tools that the AI assistant can use when this blueprint is active.\n */\n tools: Schema.Array(ToolId).annotations({\n description: 'Array of tools that the AI assistant can use when this blueprint is active',\n }),\n}).pipe(\n Type.object({\n // TODO(burdon): Is this a DXN? Need to create a Format type for these IDs.\n typename: 'dxos.org/type/Blueprint',\n version: '0.1.0',\n }),\n Annotation.LabelAnnotation.set(['name']),\n);\n\n/**\n * TypeScript type for Blueprint.\n */\nexport interface Blueprint extends Schema.Schema.Type<typeof Blueprint> {}\n\ntype MakeProps = Pick<Blueprint, 'key' | 'name'> & Partial<Blueprint>;\n\n/**\n * Create a new Blueprint.\n */\nexport const make = ({ tools = [], instructions = Template.make(), ...props }: MakeProps) =>\n Obj.make(Blueprint, {\n tools,\n instructions,\n ...props,\n });\n\n/**\n * Util to create tool definitions for a blueprint.\n */\nexport const toolDefinitions = ({\n tools = [],\n functions = [],\n}: {\n tools?: string[];\n functions?: FunctionDefinition[];\n}) => [...functions.map((fn) => ToolId.make(fn.key)), ...tools.map((tool) => ToolId.make(tool))];\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport * from './prompt';\nexport * from './template';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Record from 'effect/Record';\nimport handlebars from 'handlebars';\n\nimport { Database } from '@dxos/echo';\nimport type { ObjectNotFoundError } from '@dxos/echo/Err';\nimport {\n type FunctionDefinition,\n FunctionInvocationService,\n type FunctionNotFoundError,\n type TracingService,\n} from '@dxos/functions';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport type { Template } from '..';\n\n/**\n * Process Handlebars template.\n */\nexport const process = <Options extends {}>(source: string, variables: Partial<Options> = {}): string => {\n invariant(typeof source === 'string');\n let section = 0;\n handlebars.registerHelper('section', () => String(++section));\n const template = handlebars.compile(source.trim());\n const output = template(variables);\n return output.trim().replace(/(\\n\\s*){3,}/g, '\\n\\n');\n};\n\nexport const processTemplate = (\n template: Template.Template,\n): Effect.Effect<string, ObjectNotFoundError | FunctionNotFoundError, FunctionInvocationService | TracingService> =>\n Effect.gen(function* () {\n const functionInvoker = yield* FunctionInvocationService;\n\n const variables = yield* Effect.forEach(template.inputs ?? [], (input) =>\n Effect.gen(function* () {\n if (input.kind === 'function') {\n const fn = (yield* functionInvoker.resolveFunction(input.function!)) as FunctionDefinition<\n {},\n unknown,\n never\n >;\n const result = yield* functionInvoker.invokeFunction(fn, {});\n return [input.name, result] as const;\n } else {\n return yield* Effect.dieMessage(`Unsupported input kind: ${input.kind}`);\n }\n }),\n ).pipe(Effect.map(Record.fromEntries));\n\n log('processTemplate', { variables });\n\n return process((yield* Database.Service.load(template.source)).content, variables);\n });\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Ref, Type } from '@dxos/echo';\nimport { type ObjectId } from '@dxos/keys';\nimport { Text } from '@dxos/schema';\n\n/**\n * Template input kind determines how template variables are resolved.\n */\nexport const InputKind = Schema.Literal(\n 'value', // Literal value.\n 'pass-through',\n 'retriever',\n 'function',\n 'query',\n 'resolver',\n 'context',\n 'schema',\n);\n\nexport type InputKind = Schema.Schema.Type<typeof InputKind>;\n\n/**\n * Template input variable.\n * E.g., {{foo}}\n */\nexport const Input = Schema.Struct({\n name: Schema.String,\n kind: Schema.optional(InputKind),\n default: Schema.optional(Schema.Any),\n\n /**\n * Function to call if the kind is 'function'.\n */\n function: Schema.optional(Schema.String),\n}).pipe(Schema.mutable);\n\nexport type Input = Schema.Schema.Type<typeof Input>;\n\n/**\n * Template type.\n */\nexport const Template = Schema.Struct({\n source: Type.Ref(Text.Text).annotations({ description: 'Handlebars template source' }),\n inputs: Schema.optional(Schema.mutable(Schema.Array(Input))),\n}).pipe(Schema.mutable);\n\nexport interface Template extends Schema.Schema.Type<typeof Template> {}\n\nexport const make = ({\n source,\n inputs = [],\n id,\n}: { source?: string; inputs?: Input[]; id?: ObjectId } = {}): Template => ({\n source: Ref.make(Text.make(source, id)),\n inputs,\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { log } from '@dxos/log';\n\nimport { type Blueprint } from './blueprint';\n\n/**\n * Blueprint registry.\n */\nexport class Registry {\n private readonly _blueprints: Blueprint[] = [];\n\n constructor(blueprints: Blueprint[]) {\n const seen = new Set<string>();\n blueprints.forEach((blueprint) => {\n if (seen.has(blueprint.key)) {\n log.warn('duplicate blueprint', { key: blueprint.key });\n } else {\n seen.add(blueprint.key);\n this._blueprints.push(blueprint);\n }\n });\n\n this._blueprints.sort(({ name: a }, { name: b }) => a.localeCompare(b));\n }\n\n get blueprints(): Blueprint[] {\n return this._blueprints;\n }\n\n getByKey(key: string): Blueprint | undefined {\n return this._blueprints.find((blueprint) => blueprint.key === key);\n }\n\n query(): Blueprint[] {\n return this._blueprints;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport * from './prompt';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Annotation, JsonSchema, Obj, type Ref, Type } from '@dxos/echo';\n\nimport { Blueprint } from '../blueprint';\nimport * as Template from '../template';\n\n/**\n * Executable instructions, which may use Blueprints.\n * May reference additional context.\n */\nexport const Prompt = Schema.Struct({\n /**\n * Name of the prompt.\n */\n name: Schema.optional(Schema.String),\n\n /**\n * Description of the prompt's purpose and functionality.\n * Allows AI agents to execute prompts automatically as tools.\n */\n description: Schema.optional(Schema.String),\n\n /**\n * Input schema of the prompt.\n */\n input: JsonSchema.JsonSchema.pipe(Annotation.FormInputAnnotation.set(false)),\n\n /**\n * Output schema of the prompt.\n */\n output: JsonSchema.JsonSchema.pipe(Annotation.FormInputAnnotation.set(false)),\n\n /**\n * Natural language instructions for the prompt.\n * These should provide concrete course of action for the AI to follow.\n */\n instructions: Template.Template.pipe(Annotation.FormInputAnnotation.set(false)),\n\n /**\n * Blueprints that the prompt may utilize.\n */\n blueprints: Schema.Array(Type.Ref(Blueprint)),\n\n /**\n * Additional context that the prompt may utilize.\n */\n context: Schema.Array(Schema.Any).pipe(Annotation.FormInputAnnotation.set(false)),\n}).pipe(\n Type.object({\n typename: 'dxos.org/type/Prompt',\n version: '0.1.0',\n }),\n);\n\nexport interface Prompt extends Schema.Schema.Type<typeof Prompt> {}\n\nexport const make = (params: {\n name?: string;\n description?: string;\n input?: Schema.Schema.AnyNoContext;\n output?: Schema.Schema.AnyNoContext;\n instructions?: string;\n blueprints?: Ref.Ref<Blueprint>[];\n context?: any[];\n}): Prompt =>\n Obj.make(Prompt, {\n name: params.name,\n description: params.description,\n input: JsonSchema.toJsonSchema(params.input ?? Schema.Void),\n output: JsonSchema.toJsonSchema(params.output ?? Schema.Void),\n instructions: Template.make({ source: params.instructions }),\n blueprints: params.blueprints ?? [],\n context: params.context ?? [],\n });\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAAA;;;;cAAAA;EAAA;;;;ACIA,YAAYC,aAAY;AAExB,SAASC,cAAc;AACvB,SAASC,YAAYC,KAAKC,QAAAA,aAAY;;;ACPtC;;;;;;;;;;;ACIA,YAAYC,YAAY;AACxB,YAAYC,YAAY;AACxB,OAAOC,gBAAgB;AAEvB,SAASC,gBAAgB;AAEzB,SAEEC,iCAGK;AACP,SAASC,iBAAiB;AAC1B,SAASC,WAAW;;AAOb,IAAMC,UAAU,CAAqBC,QAAgBC,YAA8B,CAAC,MAAC;AAC1FJ,YAAU,OAAOG,WAAW,UAAA,QAAA;;;;;;;;;AAC5B,MAAIE,UAAU;AACdR,aAAWS,eAAe,WAAW,MAAMC,OAAO,EAAEF,OAAA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EACfE,MAAMwB,OAAOxB;EACbG,aAAaqB,OAAOrB;EACpBC,OAAOC,WAAWqB,aAAaF,OAAOpB,SAAgBuB,YAAI;EAC1DjB,QAAQL,WAAWqB,aAAaF,OAAOd,UAAiBiB,YAAI;EAC5DhB,cAAuBY,KAAK;IAAEK,QAAQJ,OAAOb;EAAa,CAAA;EAC1DE,YAAYW,OAAOX,cAAc,CAAA;EACjCK,SAASM,OAAON,WAAW,CAAA;AAC7B,CAAA;",
|
|
6
|
+
"names": ["make", "Schema", "ToolId", "Annotation", "Obj", "Type", "Effect", "Record", "handlebars", "Database", "FunctionInvocationService", "invariant", "log", "process", "source", "variables", "section", "registerHelper", "String", "template", "compile", "trim", "output", "replace", "processTemplate", "gen", "functionInvoker", "forEach", "inputs", "input", "kind", "fn", "resolveFunction", "function", "result", "invokeFunction", "name", "dieMessage", "pipe", "map", "fromEntries", "Service", "load", "content", "Schema", "Ref", "Type", "Text", "InputKind", "Literal", "Input", "Struct", "name", "String", "kind", "optional", "default", "Any", "function", "pipe", "mutable", "Template", "source", "Type", "Ref", "Text", "annotations", "description", "inputs", "Array", "make", "id", "Blueprint", "Struct", "key", "String", "annotations", "description", "name", "optional", "instructions", "Template", "tools", "Array", "ToolId", "pipe", "Type", "object", "typename", "version", "Annotation", "LabelAnnotation", "set", "make", "props", "Obj", "toolDefinitions", "functions", "map", "fn", "tool", "log", "Registry", "_blueprints", "blueprints", "seen", "Set", "forEach", "blueprint", "has", "key", "warn", "add", "push", "sort", "name", "a", "b", "localeCompare", "getByKey", "find", "query", "make", "Schema", "Annotation", "JsonSchema", "Obj", "Type", "Prompt", "Struct", "name", "optional", "String", "description", "input", "JsonSchema", "pipe", "Annotation", "FormInputAnnotation", "set", "output", "instructions", "Template", "blueprints", "Array", "Type", "Ref", "Blueprint", "context", "Any", "object", "typename", "version", "make", "params", "Obj", "toJsonSchema", "Void", "source"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/template/prompt.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/template/prompt.ts":{"bytes":6924,"imports":[{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Record","kind":"import-statement","external":true},{"path":"handlebars","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/functions","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/template/template.ts":{"bytes":4720,"imports":[{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/schema","kind":"import-statement","external":true}],"format":"esm"},"src/template/index.ts":{"bytes":546,"imports":[{"path":"src/template/prompt.ts","kind":"import-statement","original":"./prompt"},{"path":"src/template/template.ts","kind":"import-statement","original":"./template"}],"format":"esm"},"src/blueprint/blueprint.ts":{"bytes":8164,"imports":[{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/ai","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"src/template/index.ts","kind":"import-statement","original":"../template"}],"format":"esm"},"src/blueprint/registry.ts":{"bytes":3662,"imports":[{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/blueprint/index.ts":{"bytes":554,"imports":[{"path":"src/blueprint/blueprint.ts","kind":"import-statement","original":"./blueprint"},{"path":"src/blueprint/registry.ts","kind":"import-statement","original":"./registry"}],"format":"esm"},"src/prompt/prompt.ts":{"bytes":7056,"imports":[{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"src/blueprint/index.ts","kind":"import-statement","original":"../blueprint"},{"path":"src/template/index.ts","kind":"import-statement","original":"../template"}],"format":"esm"},"src/prompt/index.ts":{"bytes":456,"imports":[{"path":"src/prompt/prompt.ts","kind":"import-statement","original":"./prompt"}],"format":"esm"},"src/index.ts":{"bytes":813,"imports":[{"path":"src/blueprint/index.ts","kind":"import-statement","original":"./blueprint"},{"path":"src/template/index.ts","kind":"import-statement","original":"./template"},{"path":"src/prompt/index.ts","kind":"import-statement","original":"./prompt"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15510},"dist/lib/browser/index.mjs":{"imports":[{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/ai","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Record","kind":"import-statement","external":true},{"path":"handlebars","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/functions","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/schema","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true}],"exports":["Blueprint","Prompt","Template"],"entryPoint":"src/index.ts","inputs":{"src/blueprint/index.ts":{"bytesInOutput":182},"src/blueprint/blueprint.ts":{"bytesInOutput":1842},"src/template/index.ts":{"bytesInOutput":227},"src/template/prompt.ts":{"bytesInOutput":1642},"src/template/template.ts":{"bytesInOutput":819},"src/blueprint/registry.ts":{"bytesInOutput":897},"src/index.ts":{"bytesInOutput":0},"src/prompt/index.ts":{"bytesInOutput":100},"src/prompt/prompt.ts":{"bytesInOutput":1592}},"bytes":7858}}}
|
|
@@ -17,8 +17,7 @@ __export(blueprint_exports, {
|
|
|
17
17
|
// src/blueprint/blueprint.ts
|
|
18
18
|
import * as Schema2 from "effect/Schema";
|
|
19
19
|
import { ToolId } from "@dxos/ai";
|
|
20
|
-
import { Obj, Type as Type2 } from "@dxos/echo";
|
|
21
|
-
import { LabelAnnotation } from "@dxos/echo/internal";
|
|
20
|
+
import { Annotation, Obj, Type as Type2 } from "@dxos/echo";
|
|
22
21
|
|
|
23
22
|
// src/template/index.ts
|
|
24
23
|
var template_exports = {};
|
|
@@ -27,17 +26,23 @@ __export(template_exports, {
|
|
|
27
26
|
InputKind: () => InputKind,
|
|
28
27
|
Template: () => Template,
|
|
29
28
|
make: () => make,
|
|
30
|
-
process: () => process
|
|
29
|
+
process: () => process,
|
|
30
|
+
processTemplate: () => processTemplate
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
// src/template/prompt.ts
|
|
34
|
+
import * as Effect from "effect/Effect";
|
|
35
|
+
import * as Record from "effect/Record";
|
|
34
36
|
import handlebars from "handlebars";
|
|
37
|
+
import { Database } from "@dxos/echo";
|
|
38
|
+
import { FunctionInvocationService } from "@dxos/functions";
|
|
35
39
|
import { invariant } from "@dxos/invariant";
|
|
40
|
+
import { log } from "@dxos/log";
|
|
36
41
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/blueprints/src/template/prompt.ts";
|
|
37
42
|
var process = (source, variables = {}) => {
|
|
38
43
|
invariant(typeof source === "string", void 0, {
|
|
39
44
|
F: __dxlog_file,
|
|
40
|
-
L:
|
|
45
|
+
L: 26,
|
|
41
46
|
S: void 0,
|
|
42
47
|
A: [
|
|
43
48
|
"typeof source === 'string'",
|
|
@@ -50,17 +55,45 @@ var process = (source, variables = {}) => {
|
|
|
50
55
|
const output = template(variables);
|
|
51
56
|
return output.trim().replace(/(\n\s*){3,}/g, "\n\n");
|
|
52
57
|
};
|
|
58
|
+
var processTemplate = (template) => Effect.gen(function* () {
|
|
59
|
+
const functionInvoker = yield* FunctionInvocationService;
|
|
60
|
+
const variables = yield* Effect.forEach(template.inputs ?? [], (input) => Effect.gen(function* () {
|
|
61
|
+
if (input.kind === "function") {
|
|
62
|
+
const fn = yield* functionInvoker.resolveFunction(input.function);
|
|
63
|
+
const result = yield* functionInvoker.invokeFunction(fn, {});
|
|
64
|
+
return [
|
|
65
|
+
input.name,
|
|
66
|
+
result
|
|
67
|
+
];
|
|
68
|
+
} else {
|
|
69
|
+
return yield* Effect.dieMessage(`Unsupported input kind: ${input.kind}`);
|
|
70
|
+
}
|
|
71
|
+
})).pipe(Effect.map(Record.fromEntries));
|
|
72
|
+
log("processTemplate", {
|
|
73
|
+
variables
|
|
74
|
+
}, {
|
|
75
|
+
F: __dxlog_file,
|
|
76
|
+
L: 56,
|
|
77
|
+
S: this,
|
|
78
|
+
C: (f, a) => f(...a)
|
|
79
|
+
});
|
|
80
|
+
return process((yield* Database.Service.load(template.source)).content, variables);
|
|
81
|
+
});
|
|
53
82
|
|
|
54
83
|
// src/template/template.ts
|
|
55
84
|
import * as Schema from "effect/Schema";
|
|
56
85
|
import { Ref, Type } from "@dxos/echo";
|
|
57
86
|
import { Text } from "@dxos/schema";
|
|
58
87
|
var InputKind = Schema.Literal("value", "pass-through", "retriever", "function", "query", "resolver", "context", "schema");
|
|
59
|
-
var Input = Schema.
|
|
88
|
+
var Input = Schema.Struct({
|
|
60
89
|
name: Schema.String,
|
|
61
90
|
kind: Schema.optional(InputKind),
|
|
62
|
-
default: Schema.optional(Schema.Any)
|
|
63
|
-
|
|
91
|
+
default: Schema.optional(Schema.Any),
|
|
92
|
+
/**
|
|
93
|
+
* Function to call if the kind is 'function'.
|
|
94
|
+
*/
|
|
95
|
+
function: Schema.optional(Schema.String)
|
|
96
|
+
}).pipe(Schema.mutable);
|
|
64
97
|
var Template = Schema.Struct({
|
|
65
98
|
source: Type.Ref(Text.Text).annotations({
|
|
66
99
|
description: "Handlebars template source"
|
|
@@ -107,17 +140,13 @@ var Blueprint = Schema2.Struct({
|
|
|
107
140
|
tools: Schema2.Array(ToolId).annotations({
|
|
108
141
|
description: "Array of tools that the AI assistant can use when this blueprint is active"
|
|
109
142
|
})
|
|
110
|
-
}).pipe(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
LabelAnnotation.set([
|
|
118
|
-
"name"
|
|
119
|
-
])
|
|
120
|
-
);
|
|
143
|
+
}).pipe(Type2.object({
|
|
144
|
+
// TODO(burdon): Is this a DXN? Need to create a Format type for these IDs.
|
|
145
|
+
typename: "dxos.org/type/Blueprint",
|
|
146
|
+
version: "0.1.0"
|
|
147
|
+
}), Annotation.LabelAnnotation.set([
|
|
148
|
+
"name"
|
|
149
|
+
]));
|
|
121
150
|
var make2 = ({ tools = [], instructions = make(), ...props }) => Obj.make(Blueprint, {
|
|
122
151
|
tools,
|
|
123
152
|
instructions,
|
|
@@ -129,7 +158,7 @@ var toolDefinitions = ({ tools = [], functions = [] }) => [
|
|
|
129
158
|
];
|
|
130
159
|
|
|
131
160
|
// src/blueprint/registry.ts
|
|
132
|
-
import { log } from "@dxos/log";
|
|
161
|
+
import { log as log2 } from "@dxos/log";
|
|
133
162
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/blueprints/src/blueprint/registry.ts";
|
|
134
163
|
var Registry = class {
|
|
135
164
|
_blueprints = [];
|
|
@@ -137,7 +166,7 @@ var Registry = class {
|
|
|
137
166
|
const seen = /* @__PURE__ */ new Set();
|
|
138
167
|
blueprints.forEach((blueprint) => {
|
|
139
168
|
if (seen.has(blueprint.key)) {
|
|
140
|
-
|
|
169
|
+
log2.warn("duplicate blueprint", {
|
|
141
170
|
key: blueprint.key
|
|
142
171
|
}, {
|
|
143
172
|
F: __dxlog_file2,
|
|
@@ -152,6 +181,9 @@ var Registry = class {
|
|
|
152
181
|
});
|
|
153
182
|
this._blueprints.sort(({ name: a }, { name: b }) => a.localeCompare(b));
|
|
154
183
|
}
|
|
184
|
+
get blueprints() {
|
|
185
|
+
return this._blueprints;
|
|
186
|
+
}
|
|
155
187
|
getByKey(key) {
|
|
156
188
|
return this._blueprints.find((blueprint) => blueprint.key === key);
|
|
157
189
|
}
|
|
@@ -169,9 +201,8 @@ __export(prompt_exports, {
|
|
|
169
201
|
|
|
170
202
|
// src/prompt/prompt.ts
|
|
171
203
|
import * as Schema3 from "effect/Schema";
|
|
172
|
-
import { Obj as Obj2, Type as Type3 } from "@dxos/echo";
|
|
173
|
-
|
|
174
|
-
var Prompt_ = Schema3.Struct({
|
|
204
|
+
import { Annotation as Annotation2, JsonSchema, Obj as Obj2, Type as Type3 } from "@dxos/echo";
|
|
205
|
+
var Prompt = Schema3.Struct({
|
|
175
206
|
/**
|
|
176
207
|
* Name of the prompt.
|
|
177
208
|
*/
|
|
@@ -184,16 +215,16 @@ var Prompt_ = Schema3.Struct({
|
|
|
184
215
|
/**
|
|
185
216
|
* Input schema of the prompt.
|
|
186
217
|
*/
|
|
187
|
-
input:
|
|
218
|
+
input: JsonSchema.JsonSchema.pipe(Annotation2.FormInputAnnotation.set(false)),
|
|
188
219
|
/**
|
|
189
220
|
* Output schema of the prompt.
|
|
190
221
|
*/
|
|
191
|
-
output:
|
|
222
|
+
output: JsonSchema.JsonSchema.pipe(Annotation2.FormInputAnnotation.set(false)),
|
|
192
223
|
/**
|
|
193
224
|
* Natural language instructions for the prompt.
|
|
194
225
|
* These should provide concrete course of action for the AI to follow.
|
|
195
226
|
*/
|
|
196
|
-
instructions: Template.pipe(
|
|
227
|
+
instructions: Template.pipe(Annotation2.FormInputAnnotation.set(false)),
|
|
197
228
|
/**
|
|
198
229
|
* Blueprints that the prompt may utilize.
|
|
199
230
|
*/
|
|
@@ -201,17 +232,16 @@ var Prompt_ = Schema3.Struct({
|
|
|
201
232
|
/**
|
|
202
233
|
* Additional context that the prompt may utilize.
|
|
203
234
|
*/
|
|
204
|
-
context: Schema3.Array(Schema3.Any).pipe(
|
|
205
|
-
}).pipe(Type3.
|
|
235
|
+
context: Schema3.Array(Schema3.Any).pipe(Annotation2.FormInputAnnotation.set(false))
|
|
236
|
+
}).pipe(Type3.object({
|
|
206
237
|
typename: "dxos.org/type/Prompt",
|
|
207
238
|
version: "0.1.0"
|
|
208
239
|
}));
|
|
209
|
-
var Prompt = Prompt_;
|
|
210
240
|
var make3 = (params) => Obj2.make(Prompt, {
|
|
211
241
|
name: params.name,
|
|
212
242
|
description: params.description,
|
|
213
|
-
input: toJsonSchema(params.input ?? Schema3.Void),
|
|
214
|
-
output: toJsonSchema(params.output ?? Schema3.Void),
|
|
243
|
+
input: JsonSchema.toJsonSchema(params.input ?? Schema3.Void),
|
|
244
|
+
output: JsonSchema.toJsonSchema(params.output ?? Schema3.Void),
|
|
215
245
|
instructions: make({
|
|
216
246
|
source: params.instructions
|
|
217
247
|
}),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/blueprint/index.ts", "../../../src/blueprint/blueprint.ts", "../../../src/template/index.ts", "../../../src/template/prompt.ts", "../../../src/template/template.ts", "../../../src/blueprint/registry.ts", "../../../src/prompt/index.ts", "../../../src/prompt/prompt.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport * from './blueprint';\nexport * from './registry';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { ToolId } from '@dxos/ai';\nimport { Obj, Type } from '@dxos/echo';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;AAAA;;;;cAAAA;EAAA;;;;ACIA,YAAYC,aAAY;AAExB,SAASC,cAAc;AACvB,SAASC,KAAKC,QAAAA,aAAY;
|
|
6
|
-
"names": ["make", "Schema", "ToolId", "Obj", "Type", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport * from './blueprint';\nexport * from './registry';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { ToolId } from '@dxos/ai';\nimport { Annotation, Obj, Type } from '@dxos/echo';\nimport { type FunctionDefinition } from '@dxos/functions';\n\nimport * as Template from '../template';\n\n/**\n * Blueprint schema defines the structure for AI assistant blueprints.\n * Blueprints contain instructions, tools, and artifacts that guide the AI's behavior.\n * Blueprints may use tools to create and read artifacts, which are managed by the assistant.\n */\nexport const Blueprint = Schema.Struct({\n /**\n * Global registry ID.\n * NOTE: The `key` property refers to the original registry entry.\n */\n // TODO(burdon): Create Format type for DXN-like ids, such as this and schema type.\n key: Schema.String.annotations({\n description: 'Unique registration key for the blueprint',\n }),\n\n /**\n * Human-readable name of the blueprint.\n */\n name: Schema.String.annotations({\n description: 'Human-readable name of the blueprint',\n }),\n\n /**\n * Description of the blueprint's purpose and functionality.\n */\n description: Schema.optional(Schema.String).annotations({\n description: \"Description of the blueprint's purpose and functionality\",\n }),\n\n /**\n * Instructions that guide the AI assistant's behavior and responses.\n * These are system prompts or guidelines that the AI should follow.\n */\n instructions: Template.Template.annotations({\n description: \"Instructions that guide the AI assistant's behavior and responses\",\n }),\n\n /**\n * Array of tools that the AI assistant can use when this blueprint is active.\n */\n tools: Schema.Array(ToolId).annotations({\n description: 'Array of tools that the AI assistant can use when this blueprint is active',\n }),\n}).pipe(\n Type.object({\n // TODO(burdon): Is this a DXN? Need to create a Format type for these IDs.\n typename: 'dxos.org/type/Blueprint',\n version: '0.1.0',\n }),\n Annotation.LabelAnnotation.set(['name']),\n);\n\n/**\n * TypeScript type for Blueprint.\n */\nexport interface Blueprint extends Schema.Schema.Type<typeof Blueprint> {}\n\ntype MakeProps = Pick<Blueprint, 'key' | 'name'> & Partial<Blueprint>;\n\n/**\n * Create a new Blueprint.\n */\nexport const make = ({ tools = [], instructions = Template.make(), ...props }: MakeProps) =>\n Obj.make(Blueprint, {\n tools,\n instructions,\n ...props,\n });\n\n/**\n * Util to create tool definitions for a blueprint.\n */\nexport const toolDefinitions = ({\n tools = [],\n functions = [],\n}: {\n tools?: string[];\n functions?: FunctionDefinition[];\n}) => [...functions.map((fn) => ToolId.make(fn.key)), ...tools.map((tool) => ToolId.make(tool))];\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport * from './prompt';\nexport * from './template';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Record from 'effect/Record';\nimport handlebars from 'handlebars';\n\nimport { Database } from '@dxos/echo';\nimport type { ObjectNotFoundError } from '@dxos/echo/Err';\nimport {\n type FunctionDefinition,\n FunctionInvocationService,\n type FunctionNotFoundError,\n type TracingService,\n} from '@dxos/functions';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport type { Template } from '..';\n\n/**\n * Process Handlebars template.\n */\nexport const process = <Options extends {}>(source: string, variables: Partial<Options> = {}): string => {\n invariant(typeof source === 'string');\n let section = 0;\n handlebars.registerHelper('section', () => String(++section));\n const template = handlebars.compile(source.trim());\n const output = template(variables);\n return output.trim().replace(/(\\n\\s*){3,}/g, '\\n\\n');\n};\n\nexport const processTemplate = (\n template: Template.Template,\n): Effect.Effect<string, ObjectNotFoundError | FunctionNotFoundError, FunctionInvocationService | TracingService> =>\n Effect.gen(function* () {\n const functionInvoker = yield* FunctionInvocationService;\n\n const variables = yield* Effect.forEach(template.inputs ?? [], (input) =>\n Effect.gen(function* () {\n if (input.kind === 'function') {\n const fn = (yield* functionInvoker.resolveFunction(input.function!)) as FunctionDefinition<\n {},\n unknown,\n never\n >;\n const result = yield* functionInvoker.invokeFunction(fn, {});\n return [input.name, result] as const;\n } else {\n return yield* Effect.dieMessage(`Unsupported input kind: ${input.kind}`);\n }\n }),\n ).pipe(Effect.map(Record.fromEntries));\n\n log('processTemplate', { variables });\n\n return process((yield* Database.Service.load(template.source)).content, variables);\n });\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Ref, Type } from '@dxos/echo';\nimport { type ObjectId } from '@dxos/keys';\nimport { Text } from '@dxos/schema';\n\n/**\n * Template input kind determines how template variables are resolved.\n */\nexport const InputKind = Schema.Literal(\n 'value', // Literal value.\n 'pass-through',\n 'retriever',\n 'function',\n 'query',\n 'resolver',\n 'context',\n 'schema',\n);\n\nexport type InputKind = Schema.Schema.Type<typeof InputKind>;\n\n/**\n * Template input variable.\n * E.g., {{foo}}\n */\nexport const Input = Schema.Struct({\n name: Schema.String,\n kind: Schema.optional(InputKind),\n default: Schema.optional(Schema.Any),\n\n /**\n * Function to call if the kind is 'function'.\n */\n function: Schema.optional(Schema.String),\n}).pipe(Schema.mutable);\n\nexport type Input = Schema.Schema.Type<typeof Input>;\n\n/**\n * Template type.\n */\nexport const Template = Schema.Struct({\n source: Type.Ref(Text.Text).annotations({ description: 'Handlebars template source' }),\n inputs: Schema.optional(Schema.mutable(Schema.Array(Input))),\n}).pipe(Schema.mutable);\n\nexport interface Template extends Schema.Schema.Type<typeof Template> {}\n\nexport const make = ({\n source,\n inputs = [],\n id,\n}: { source?: string; inputs?: Input[]; id?: ObjectId } = {}): Template => ({\n source: Ref.make(Text.make(source, id)),\n inputs,\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { log } from '@dxos/log';\n\nimport { type Blueprint } from './blueprint';\n\n/**\n * Blueprint registry.\n */\nexport class Registry {\n private readonly _blueprints: Blueprint[] = [];\n\n constructor(blueprints: Blueprint[]) {\n const seen = new Set<string>();\n blueprints.forEach((blueprint) => {\n if (seen.has(blueprint.key)) {\n log.warn('duplicate blueprint', { key: blueprint.key });\n } else {\n seen.add(blueprint.key);\n this._blueprints.push(blueprint);\n }\n });\n\n this._blueprints.sort(({ name: a }, { name: b }) => a.localeCompare(b));\n }\n\n get blueprints(): Blueprint[] {\n return this._blueprints;\n }\n\n getByKey(key: string): Blueprint | undefined {\n return this._blueprints.find((blueprint) => blueprint.key === key);\n }\n\n query(): Blueprint[] {\n return this._blueprints;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport * from './prompt';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Annotation, JsonSchema, Obj, type Ref, Type } from '@dxos/echo';\n\nimport { Blueprint } from '../blueprint';\nimport * as Template from '../template';\n\n/**\n * Executable instructions, which may use Blueprints.\n * May reference additional context.\n */\nexport const Prompt = Schema.Struct({\n /**\n * Name of the prompt.\n */\n name: Schema.optional(Schema.String),\n\n /**\n * Description of the prompt's purpose and functionality.\n * Allows AI agents to execute prompts automatically as tools.\n */\n description: Schema.optional(Schema.String),\n\n /**\n * Input schema of the prompt.\n */\n input: JsonSchema.JsonSchema.pipe(Annotation.FormInputAnnotation.set(false)),\n\n /**\n * Output schema of the prompt.\n */\n output: JsonSchema.JsonSchema.pipe(Annotation.FormInputAnnotation.set(false)),\n\n /**\n * Natural language instructions for the prompt.\n * These should provide concrete course of action for the AI to follow.\n */\n instructions: Template.Template.pipe(Annotation.FormInputAnnotation.set(false)),\n\n /**\n * Blueprints that the prompt may utilize.\n */\n blueprints: Schema.Array(Type.Ref(Blueprint)),\n\n /**\n * Additional context that the prompt may utilize.\n */\n context: Schema.Array(Schema.Any).pipe(Annotation.FormInputAnnotation.set(false)),\n}).pipe(\n Type.object({\n typename: 'dxos.org/type/Prompt',\n version: '0.1.0',\n }),\n);\n\nexport interface Prompt extends Schema.Schema.Type<typeof Prompt> {}\n\nexport const make = (params: {\n name?: string;\n description?: string;\n input?: Schema.Schema.AnyNoContext;\n output?: Schema.Schema.AnyNoContext;\n instructions?: string;\n blueprints?: Ref.Ref<Blueprint>[];\n context?: any[];\n}): Prompt =>\n Obj.make(Prompt, {\n name: params.name,\n description: params.description,\n input: JsonSchema.toJsonSchema(params.input ?? Schema.Void),\n output: JsonSchema.toJsonSchema(params.output ?? Schema.Void),\n instructions: Template.make({ source: params.instructions }),\n blueprints: params.blueprints ?? [],\n context: params.context ?? [],\n });\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA;;;;cAAAA;EAAA;;;;ACIA,YAAYC,aAAY;AAExB,SAASC,cAAc;AACvB,SAASC,YAAYC,KAAKC,QAAAA,aAAY;;;ACPtC;;;;;;;;;;;ACIA,YAAYC,YAAY;AACxB,YAAYC,YAAY;AACxB,OAAOC,gBAAgB;AAEvB,SAASC,gBAAgB;AAEzB,SAEEC,iCAGK;AACP,SA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,SAAgBJ,cAAaK,WAAG,EAAEb,KAAKC,YAAWC,oBAAoBC,IAAI,KAAA,CAAA;AAC5E,CAAA,EAAGH,KACDS,MAAKK,OAAO;EACVC,UAAU;EACVC,SAAS;AACX,CAAA,CAAA;AAKK,IAAMC,QAAO,CAACC,WASnBC,KAAIF,KAAKzB,QAAQ;EACfE,MAAMwB,OAAOxB;EACbG,aAAaqB,OAAOrB;EACpBC,OAAOC,WAAWqB,aAAaF,OAAOpB,SAAgBuB,YAAI;EAC1DjB,QAAQL,WAAWqB,aAAaF,OAAOd,UAAiBiB,YAAI;EAC5DhB,cAAuBY,KAAK;IAAEK,QAAQJ,OAAOb;EAAa,CAAA;EAC1DE,YAAYW,OAAOX,cAAc,CAAA;EACjCK,SAASM,OAAON,WAAW,CAAA;AAC7B,CAAA;",
|
|
6
|
+
"names": ["make", "Schema", "ToolId", "Annotation", "Obj", "Type", "Effect", "Record", "handlebars", "Database", "FunctionInvocationService", "invariant", "log", "process", "source", "variables", "section", "registerHelper", "String", "template", "compile", "trim", "output", "replace", "processTemplate", "gen", "functionInvoker", "forEach", "inputs", "input", "kind", "fn", "resolveFunction", "function", "result", "invokeFunction", "name", "dieMessage", "pipe", "map", "fromEntries", "Service", "load", "content", "Schema", "Ref", "Type", "Text", "InputKind", "Literal", "Input", "Struct", "name", "String", "kind", "optional", "default", "Any", "function", "pipe", "mutable", "Template", "source", "Type", "Ref", "Text", "annotations", "description", "inputs", "Array", "make", "id", "Blueprint", "Struct", "key", "String", "annotations", "description", "name", "optional", "instructions", "Template", "tools", "Array", "ToolId", "pipe", "Type", "object", "typename", "version", "Annotation", "LabelAnnotation", "set", "make", "props", "Obj", "toolDefinitions", "functions", "map", "fn", "tool", "log", "Registry", "_blueprints", "blueprints", "seen", "Set", "forEach", "blueprint", "has", "key", "warn", "add", "push", "sort", "name", "a", "b", "localeCompare", "getByKey", "find", "query", "make", "Schema", "Annotation", "JsonSchema", "Obj", "Type", "Prompt", "Struct", "name", "optional", "String", "description", "input", "JsonSchema", "pipe", "Annotation", "FormInputAnnotation", "set", "output", "instructions", "Template", "blueprints", "Array", "Type", "Ref", "Blueprint", "context", "Any", "object", "typename", "version", "make", "params", "Obj", "toJsonSchema", "Void", "source"]
|
|
7
7
|
}
|