@conversation/spec 0.0.0-stage → 0.1.2
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 +22 -0
- package/README.md +132 -2
- package/errors.d.ts +9 -0
- package/errors.js +36 -0
- package/esm/errors.js +31 -0
- package/esm/include.js +15 -0
- package/esm/index.js +7 -0
- package/esm/parse.js +469 -0
- package/esm/plugin.js +50 -0
- package/esm/plugins/effects.js +17 -0
- package/esm/plugins/index.js +10 -0
- package/esm/plugins/slides.js +48 -0
- package/esm/plugins/speakers.js +52 -0
- package/esm/plugins/video.js +39 -0
- package/esm/schema.js +100 -0
- package/esm/segments.js +60 -0
- package/esm/suggest.js +51 -0
- package/esm/types.js +1 -0
- package/esm/values.js +228 -0
- package/include.d.ts +23 -0
- package/include.js +18 -0
- package/index.d.ts +8 -0
- package/index.js +48 -0
- package/package.json +42 -4
- package/parse.d.ts +15 -0
- package/parse.js +472 -0
- package/plugin.d.ts +52 -0
- package/plugin.js +54 -0
- package/plugins/effects.d.ts +7 -0
- package/plugins/effects.js +20 -0
- package/plugins/index.d.ts +7 -0
- package/plugins/index.js +18 -0
- package/plugins/slides.d.ts +6 -0
- package/plugins/slides.js +51 -0
- package/plugins/speakers.d.ts +9 -0
- package/plugins/speakers.js +56 -0
- package/plugins/video.d.ts +6 -0
- package/plugins/video.js +42 -0
- package/schema.d.ts +56 -0
- package/schema.js +113 -0
- package/segments.d.ts +9 -0
- package/segments.js +63 -0
- package/suggest.d.ts +7 -0
- package/suggest.js +56 -0
- package/types.d.ts +93 -0
- package/types.js +2 -0
- package/values.d.ts +36 -0
- package/values.js +236 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dan Lynch <pyramation@gmail.com>
|
|
4
|
+
Copyright (c) 2026 Constructive <developers@constructive.io>
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,133 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @conversation/spec
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center" width="100%">
|
|
4
|
+
<img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center" width="100%">
|
|
8
|
+
<a href="https://github.com/constructive-io/conversation-spec/actions/workflows/run-tests.yaml">
|
|
9
|
+
<img height="20" src="https://github.com/constructive-io/conversation-spec/actions/workflows/run-tests.yaml/badge.svg" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/constructive-io/conversation-spec/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/@conversation/spec"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/conversation-spec?filename=packages%2Fparser%2Fpackage.json"/></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
The reference parser for [`.conv`](../../SPEC.md): text in, a JSON-shaped scene
|
|
16
|
+
out. No dependencies, no filesystem, runs anywhere.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm install @conversation/spec
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Parse
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { ConvError, parse } from '@conversation/spec';
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const scene = parse(text, { source: 'attic.conv' });
|
|
31
|
+
scene.characters; // { ALICE: { persona: 'alice' }, … }
|
|
32
|
+
scene.sounds; // { RAIN: { file: 'sounds/rain.wav', loop: true, track: 'ambience' }, … }
|
|
33
|
+
scene.items; // lines, pauses, cues, track directives and marks, in order
|
|
34
|
+
} catch (e) {
|
|
35
|
+
if (e instanceof ConvError) console.error(e.message); // every problem, with fixes
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
| Option | |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `source` | a name for messages; also the `from` passed to the include resolver |
|
|
42
|
+
| `strict` | `true` (default) throws `ConvError`; `false` returns problems in `scene.problems` |
|
|
43
|
+
| `plugins` | defaults to `defaultPlugins` |
|
|
44
|
+
| `include` | an `IncludeResolver` for `@include` |
|
|
45
|
+
|
|
46
|
+
The scene's shape is described in [SPEC.md §13](../../SPEC.md#13-the-parsed-scene)
|
|
47
|
+
and typed in `Scene`, `Item` and `Segment`.
|
|
48
|
+
|
|
49
|
+
## Includes
|
|
50
|
+
|
|
51
|
+
The parser never reads files. `@include` goes through a resolver you pass in:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { memoryResolver, parse } from '@conversation/spec';
|
|
55
|
+
|
|
56
|
+
parse(text, { include: memoryResolver({ studio: studioBankText }) });
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
A resolver is one function — `resolve(ref, from)` returns `{ id, text }` or
|
|
60
|
+
`{ tried }` — plus an optional `list()` for suggestions. The CLI package has a
|
|
61
|
+
filesystem one.
|
|
62
|
+
|
|
63
|
+
## Plugins
|
|
64
|
+
|
|
65
|
+
Everything beyond the core grammar is a plugin. The defaults:
|
|
66
|
+
|
|
67
|
+
| Plugin | Adds |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `effects()` | `reverb`, `reverb-mix`, `delay`, `delay-feedback`, `delay-mix`, `compress` |
|
|
70
|
+
| `slides()` | `[slide ID step:N]` |
|
|
71
|
+
| `speakers()` | `[speakers …]`; `name:` and `title:` on characters |
|
|
72
|
+
| `video()` | the `video` track and `[video CLIP]` |
|
|
73
|
+
|
|
74
|
+
Pass your own alongside them:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { ConvPlugin, defaultPlugins, effects, num, parse, slides, speakers, str, video } from '@conversation/spec';
|
|
78
|
+
|
|
79
|
+
const chapters: ConvPlugin = {
|
|
80
|
+
name: 'chapters',
|
|
81
|
+
// [chapter The Attic] -> { type: 'mark', kind: 'chapter', data: { title: 'The Attic' } }
|
|
82
|
+
directives: {
|
|
83
|
+
chapter(args, ctx) {
|
|
84
|
+
if (!args) return ctx.error('`[chapter]` needs a title');
|
|
85
|
+
return { title: args };
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
// DAN[rate:0.9]: … — validated, coerced, in line.overrides
|
|
89
|
+
keys: { line: { rate: num(0.5, 2) }, character: { engine: str() } },
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
parse(text, { plugins: [...defaultPlugins, chapters] });
|
|
93
|
+
|
|
94
|
+
// configure a default: a renderer with its own reverb presets
|
|
95
|
+
parse(text, { plugins: [effects({ reverbPresets: ['room', 'hall', 'spring'] }), slides(), speakers(), video()] });
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
A `ConvPlugin` can contribute:
|
|
99
|
+
|
|
100
|
+
| Field | |
|
|
101
|
+
|---|---|
|
|
102
|
+
| `keys` | keys per context: `character`, `line`, `span`, `sound`, `track`, `play`, `off`, `set` |
|
|
103
|
+
| `enums` | values for a named enum; plugins naming the same enum add to it |
|
|
104
|
+
| `tracks` | built-in tracks |
|
|
105
|
+
| `reserved` | words that can't name a track (directive names are reserved automatically) |
|
|
106
|
+
| `directives` | `[name …]` handlers that return a mark's data |
|
|
107
|
+
| `trackRules` | checks for directives on a named track |
|
|
108
|
+
| `finalize` | a pass over the finished scene that can report problems |
|
|
109
|
+
|
|
110
|
+
Key types: `str()`, `int()`, `num(min, max)`, `bool()`, `time()`,
|
|
111
|
+
`oneOf(...values)`, `named(enumName)`, `track()`, `tracks()`.
|
|
112
|
+
|
|
113
|
+
## Credits
|
|
114
|
+
|
|
115
|
+
**🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
|
|
116
|
+
|
|
117
|
+
## Disclaimer
|
|
118
|
+
|
|
119
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
120
|
+
|
|
121
|
+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Credits
|
|
126
|
+
|
|
127
|
+
**🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
|
|
128
|
+
|
|
129
|
+
## Disclaimer
|
|
130
|
+
|
|
131
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
132
|
+
|
|
133
|
+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
package/errors.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Problem } from './types';
|
|
2
|
+
/** Every problem, in script order: line number, the line, what is wrong and how to fix it. */
|
|
3
|
+
export declare function formatProblems(problems: Problem[], source?: string): string;
|
|
4
|
+
/** Thrown by a strict parse: carries every problem in the script, not just the first. */
|
|
5
|
+
export declare class ConvError extends Error {
|
|
6
|
+
readonly problems: Problem[];
|
|
7
|
+
readonly source?: string;
|
|
8
|
+
constructor(problems: Problem[], source?: string);
|
|
9
|
+
}
|
package/errors.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConvError = void 0;
|
|
4
|
+
exports.formatProblems = formatProblems;
|
|
5
|
+
function order(problems) {
|
|
6
|
+
return [...problems].sort((a, b) => {
|
|
7
|
+
if (a.line === null)
|
|
8
|
+
return b.line === null ? 0 : 1;
|
|
9
|
+
if (b.line === null)
|
|
10
|
+
return -1;
|
|
11
|
+
return a.line - b.line;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/** Every problem, in script order: line number, the line, what is wrong and how to fix it. */
|
|
15
|
+
function formatProblems(problems, source) {
|
|
16
|
+
const n = problems.length;
|
|
17
|
+
const out = [`${source || '.conv script'}: ${n} problem${n === 1 ? '' : 's'}`];
|
|
18
|
+
for (const p of order(problems)) {
|
|
19
|
+
out.push('');
|
|
20
|
+
out.push(p.line ? ` line ${p.line}: ${p.text}` : ' (script)');
|
|
21
|
+
p.message.split('\n').forEach((part, i) => out.push((i === 0 ? ' ' : ' ') + part));
|
|
22
|
+
}
|
|
23
|
+
return out.join('\n');
|
|
24
|
+
}
|
|
25
|
+
/** Thrown by a strict parse: carries every problem in the script, not just the first. */
|
|
26
|
+
class ConvError extends Error {
|
|
27
|
+
problems;
|
|
28
|
+
source;
|
|
29
|
+
constructor(problems, source) {
|
|
30
|
+
super(formatProblems(problems, source));
|
|
31
|
+
this.name = 'ConvError';
|
|
32
|
+
this.problems = order(problems);
|
|
33
|
+
this.source = source;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.ConvError = ConvError;
|
package/esm/errors.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function order(problems) {
|
|
2
|
+
return [...problems].sort((a, b) => {
|
|
3
|
+
if (a.line === null)
|
|
4
|
+
return b.line === null ? 0 : 1;
|
|
5
|
+
if (b.line === null)
|
|
6
|
+
return -1;
|
|
7
|
+
return a.line - b.line;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/** Every problem, in script order: line number, the line, what is wrong and how to fix it. */
|
|
11
|
+
export function formatProblems(problems, source) {
|
|
12
|
+
const n = problems.length;
|
|
13
|
+
const out = [`${source || '.conv script'}: ${n} problem${n === 1 ? '' : 's'}`];
|
|
14
|
+
for (const p of order(problems)) {
|
|
15
|
+
out.push('');
|
|
16
|
+
out.push(p.line ? ` line ${p.line}: ${p.text}` : ' (script)');
|
|
17
|
+
p.message.split('\n').forEach((part, i) => out.push((i === 0 ? ' ' : ' ') + part));
|
|
18
|
+
}
|
|
19
|
+
return out.join('\n');
|
|
20
|
+
}
|
|
21
|
+
/** Thrown by a strict parse: carries every problem in the script, not just the first. */
|
|
22
|
+
export class ConvError extends Error {
|
|
23
|
+
problems;
|
|
24
|
+
source;
|
|
25
|
+
constructor(problems, source) {
|
|
26
|
+
super(formatProblems(problems, source));
|
|
27
|
+
this.name = 'ConvError';
|
|
28
|
+
this.problems = order(problems);
|
|
29
|
+
this.source = source;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/esm/include.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@include` is resolved through an adapter, so the parser never touches a
|
|
3
|
+
* filesystem: a CLI reads files, a browser fetches ahead of time, a test keeps
|
|
4
|
+
* banks in memory.
|
|
5
|
+
*/
|
|
6
|
+
/** Banks held in memory, by name: `@include podcast` reads `banks.podcast`. */
|
|
7
|
+
export function memoryResolver(banks) {
|
|
8
|
+
return {
|
|
9
|
+
resolve(ref) {
|
|
10
|
+
const name = ref.replace(/\.sounds$/, '');
|
|
11
|
+
return name in banks ? { id: name, text: banks[name] } : { tried: [name] };
|
|
12
|
+
},
|
|
13
|
+
list: () => Object.keys(banks).sort(),
|
|
14
|
+
};
|
|
15
|
+
}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ConvError, formatProblems } from './errors';
|
|
2
|
+
export { memoryResolver } from './include';
|
|
3
|
+
export { parse } from './parse';
|
|
4
|
+
export { defaultPlugins, effects, slides, SPEAKER_WIDGETS, speakers, video } from './plugins';
|
|
5
|
+
export { bool, CORE_RESERVED, CORE_SCHEMAS, CORE_TRACKS, int, named, num, oneOf, str, time, track, tracks, } from './schema';
|
|
6
|
+
export { didYouMean, similarity } from './suggest';
|
|
7
|
+
export * from './types';
|