@prompd/core 0.5.0-beta.10
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 +21 -0
- package/README.md +127 -0
- package/dist/index.cjs +4716 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2929 -0
- package/dist/index.d.ts +2929 -0
- package/dist/index.js +4627 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Prompd LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# @prompd/core
|
|
2
|
+
|
|
3
|
+
Environment-agnostic core for [Prompd](https://prompd.app) — the `.prmd` parser,
|
|
4
|
+
the compilation pipeline (Nunjucks templating + output formatters), the `.pdflow`
|
|
5
|
+
workflow parser, and an injectable file-system / package-resolver.
|
|
6
|
+
|
|
7
|
+
It has **no Node-only imports**, so the same code runs in Node, the browser, and the
|
|
8
|
+
backend. Anything platform-specific (disk access, the registry client) is injected
|
|
9
|
+
through the `IFileSystem` / `IPackageResolver` interfaces.
|
|
10
|
+
|
|
11
|
+
> Status: **beta** (`0.5.x-beta`). The API may still shift before `1.0`.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @prompd/core
|
|
17
|
+
# or: pnpm add @prompd/core
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Dual-published as ESM and CommonJS, with TypeScript types.
|
|
21
|
+
|
|
22
|
+
## Quick start
|
|
23
|
+
|
|
24
|
+
A `.prmd` file is YAML frontmatter + a Jinja2/Nunjucks body with typed parameters:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { compile } from '@prompd/core';
|
|
28
|
+
|
|
29
|
+
const source = `---
|
|
30
|
+
id: greeting
|
|
31
|
+
name: Greeting
|
|
32
|
+
version: 1.0.0
|
|
33
|
+
parameters:
|
|
34
|
+
- name: who
|
|
35
|
+
type: string
|
|
36
|
+
default: World
|
|
37
|
+
---
|
|
38
|
+
Hello {{ who }}!`;
|
|
39
|
+
|
|
40
|
+
// compile(source, outputFormat?, parameters?, options?) => Promise<string>
|
|
41
|
+
await compile(source); // -> "Hello World!" (markdown, default)
|
|
42
|
+
await compile(source, 'markdown', { who: 'Prompd' }); // -> "Hello Prompd!"
|
|
43
|
+
await compile(source, 'openai', { who: 'Prompd' }); // -> OpenAI chat JSON
|
|
44
|
+
await compile(source, 'anthropic',{ who: 'Prompd' }); // -> Anthropic messages JSON
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Output formats: `markdown` (default), `openai`, `anthropic`.
|
|
48
|
+
|
|
49
|
+
## Inheritance, includes & packages
|
|
50
|
+
|
|
51
|
+
`inherits:` and `{% include %}` resolve against other files through an injected
|
|
52
|
+
`IFileSystem`. In the browser, supply a `MemoryFileSystem`; on the server, supply
|
|
53
|
+
your own disk-backed implementation. A package resolver is injected the same way
|
|
54
|
+
(omit it where packages aren't available, e.g. the browser).
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { compile, MemoryFileSystem } from '@prompd/core';
|
|
58
|
+
|
|
59
|
+
const fs = new MemoryFileSystem({
|
|
60
|
+
'base.prmd': `---
|
|
61
|
+
id: base
|
|
62
|
+
name: Base
|
|
63
|
+
version: 1.0.0
|
|
64
|
+
---
|
|
65
|
+
{% block body %}{% endblock %}`,
|
|
66
|
+
'child.prmd': `---
|
|
67
|
+
id: child
|
|
68
|
+
name: Child
|
|
69
|
+
version: 1.0.0
|
|
70
|
+
inherits: base.prmd
|
|
71
|
+
---
|
|
72
|
+
{% block body %}Hi {{ who }}{% endblock %}`,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const child = await fs.read('child.prmd');
|
|
76
|
+
const out = await compile(child, 'markdown', { who: 'there' }, { fileSystem: fs });
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Parameters
|
|
80
|
+
|
|
81
|
+
Declared in frontmatter and validated/coerced at compile time. Types: `string`,
|
|
82
|
+
`number`, `integer`, `float`, `boolean`, `array`, `object`, `json`, `file`,
|
|
83
|
+
`base64`, and `date` / `datetime`.
|
|
84
|
+
|
|
85
|
+
`date` / `datetime` defaults (and provided values) may be **relative expressions**
|
|
86
|
+
resolved at compile time, so each run uses the current date:
|
|
87
|
+
|
|
88
|
+
```yaml
|
|
89
|
+
parameters:
|
|
90
|
+
- name: start
|
|
91
|
+
type: date
|
|
92
|
+
default: "now-7d" # also: now, today, now+1w, now-3m, now-1y, now-2h, now-30min
|
|
93
|
+
- name: when
|
|
94
|
+
type: datetime
|
|
95
|
+
default: "now" # -> "YYYY-MM-DDTHH:mm:ss"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
ISO / date-parseable literals (`"2026-01-15"`) pass through unchanged.
|
|
99
|
+
|
|
100
|
+
## Workflows (`.pdflow`)
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { parseWorkflow, getExecutionOrder, validateWorkflow } from '@prompd/core';
|
|
104
|
+
|
|
105
|
+
const { file, errors, warnings } = parseWorkflow(jsonText);
|
|
106
|
+
const order = getExecutionOrder(file); // topological node order
|
|
107
|
+
const result = validateWorkflow(file);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## What's exported
|
|
111
|
+
|
|
112
|
+
- **Parser:** `PrompdParser`
|
|
113
|
+
- **Compiler:** `compile`, `PrompdCompiler`, `CompilerPipeline`, the stages, and the
|
|
114
|
+
formatters (`MarkdownFormatter`, `OpenAIFormatter`, `AnthropicFormatter`)
|
|
115
|
+
- **File system / packages:** `IFileSystem`, `MemoryFileSystem`, `HybridFileSystem`,
|
|
116
|
+
`IPackageResolver`
|
|
117
|
+
- **Workflows:** `parseWorkflow`, `getExecutionOrder`, `validateWorkflow`,
|
|
118
|
+
`createWorkflowNode`, plus the `WorkflowFile` / node-data types
|
|
119
|
+
- **Types & errors:** `PrompdMetadata`, `PrompdParameter`, `CompilationOptions`,
|
|
120
|
+
`CompilationError`, `ValidationError`, …
|
|
121
|
+
|
|
122
|
+
See the bundled `dist/index.d.ts` for the full surface.
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
[MIT](./LICENSE) © 2024–2026 Prompd LLC. (The Prompd registry and hosted services
|
|
127
|
+
are separately licensed.)
|