@rcrsr/rill 0.16.0 → 0.17.0

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.
Files changed (57) hide show
  1. package/README.md +37 -21
  2. package/dist/ext/crypto/index.d.ts +3 -3
  3. package/dist/ext/crypto/index.js +61 -58
  4. package/dist/ext/exec/index.d.ts +3 -3
  5. package/dist/ext/exec/index.js +14 -8
  6. package/dist/ext/fetch/index.d.ts +3 -3
  7. package/dist/ext/fetch/index.js +16 -11
  8. package/dist/ext/fs/index.d.ts +3 -3
  9. package/dist/ext/fs/index.js +242 -239
  10. package/dist/ext/kv/index.d.ts +3 -3
  11. package/dist/ext/kv/index.js +197 -195
  12. package/dist/ext/kv/store.js +2 -1
  13. package/dist/ext-parse-bridge.d.ts +10 -0
  14. package/dist/ext-parse-bridge.js +10 -0
  15. package/dist/generated/introspection-data.d.ts +1 -1
  16. package/dist/generated/introspection-data.js +385 -296
  17. package/dist/generated/version-data.d.ts +1 -1
  18. package/dist/generated/version-data.js +2 -2
  19. package/dist/index.d.ts +15 -4
  20. package/dist/index.js +14 -5
  21. package/dist/parser/parser-types.js +12 -0
  22. package/dist/parser/parser-use.js +7 -1
  23. package/dist/runtime/core/callable.d.ts +20 -8
  24. package/dist/runtime/core/callable.js +63 -23
  25. package/dist/runtime/core/context.d.ts +0 -11
  26. package/dist/runtime/core/context.js +76 -75
  27. package/dist/runtime/core/eval/index.d.ts +2 -2
  28. package/dist/runtime/core/eval/index.js +11 -0
  29. package/dist/runtime/core/eval/mixins/closures.js +15 -15
  30. package/dist/runtime/core/eval/mixins/conversion.js +51 -110
  31. package/dist/runtime/core/eval/mixins/core.js +2 -2
  32. package/dist/runtime/core/eval/mixins/expressions.js +35 -27
  33. package/dist/runtime/core/eval/mixins/literals.js +3 -3
  34. package/dist/runtime/core/eval/mixins/types.js +44 -54
  35. package/dist/runtime/core/eval/mixins/variables.js +10 -8
  36. package/dist/runtime/core/field-descriptor.d.ts +3 -3
  37. package/dist/runtime/core/field-descriptor.js +2 -1
  38. package/dist/runtime/core/introspection.js +6 -6
  39. package/dist/runtime/core/markers.d.ts +12 -0
  40. package/dist/runtime/core/markers.js +7 -0
  41. package/dist/runtime/core/type-registrations.d.ts +136 -0
  42. package/dist/runtime/core/type-registrations.js +749 -0
  43. package/dist/runtime/core/type-structures.d.ts +128 -0
  44. package/dist/runtime/core/type-structures.js +12 -0
  45. package/dist/runtime/core/types.d.ts +15 -3
  46. package/dist/runtime/core/values.d.ts +62 -153
  47. package/dist/runtime/core/values.js +308 -524
  48. package/dist/runtime/ext/builtins.js +83 -64
  49. package/dist/runtime/ext/extensions.d.ts +30 -124
  50. package/dist/runtime/ext/extensions.js +0 -93
  51. package/dist/runtime/ext/test-context.d.ts +28 -0
  52. package/dist/runtime/ext/test-context.js +154 -0
  53. package/dist/runtime/index.d.ts +22 -8
  54. package/dist/runtime/index.js +18 -4
  55. package/dist/signature-parser.d.ts +2 -2
  56. package/dist/signature-parser.js +14 -14
  57. package/package.json +1 -1
package/README.md CHANGED
@@ -13,24 +13,34 @@ npm install @rcrsr/rill
13
13
  ## Quick Start
14
14
 
15
15
  ```typescript
16
- import { parse, execute, createRuntimeContext } from '@rcrsr/rill';
16
+ import { parse, execute, createRuntimeContext, toCallable } from '@rcrsr/rill';
17
+ import type { ExtensionFactoryResult } from '@rcrsr/rill';
18
+
19
+ function createMyExtension(): ExtensionFactoryResult {
20
+ return {
21
+ value: {
22
+ prompt: toCallable({
23
+ params: [{ name: 'message', type: { kind: 'string' } }],
24
+ fn: async (args) => await callYourLLM(args.message),
25
+ annotations: { description: 'Call your LLM' },
26
+ returnType: { kind: 'string' },
27
+ }),
28
+ },
29
+ };
30
+ }
31
+
32
+ const ext = createMyExtension();
33
+ const ctx = createRuntimeContext({
34
+ variables: { app: ext.value },
35
+ });
17
36
 
18
37
  const script = `
19
- prompt("Analyze this code for issues")
38
+ app.prompt("Analyze this code for issues")
20
39
  -> .contains("ERROR") ? error($) ! "Analysis complete"
21
40
  `;
22
41
 
23
- const ctx = createRuntimeContext({
24
- functions: {
25
- prompt: {
26
- params: [{ name: 'message', type: 'string' }],
27
- fn: async (args) => await callYourLLM(args[0]),
28
- },
29
- },
30
- });
31
-
32
42
  const result = await execute(parse(script), ctx);
33
- console.log(result.value);
43
+ console.log(result.result);
34
44
  ```
35
45
 
36
46
  ## API
@@ -47,25 +57,31 @@ Source Text → parse() → AST → execute() → Result
47
57
  | `execute(ast, ctx)` | Execute an AST with a runtime context |
48
58
  | `createRuntimeContext(opts)` | Create a configured runtime context |
49
59
  | `callable(fn, isProperty?)` | Wrap a function as a rill-callable value |
50
- | `prefixFunctions(prefix, fns)` | Namespace host functions (e.g., `app::`) |
60
+ | `toCallable(def)` | Convert a `RillFunction` to an `ApplicationCallable` |
61
+ | `createTestContext(extensions)` | Wire extensions for testing without config infrastructure |
51
62
 
52
63
  ### Runtime Options
53
64
 
54
65
  ```typescript
66
+ const ext = createMyExtension();
67
+
55
68
  const ctx = createRuntimeContext({
56
- // Host functions available to scripts
69
+ // Extension values injected as variables (recommended)
70
+ variables: {
71
+ app: ext.value,
72
+ config: { greeting: 'hello' },
73
+ },
74
+
75
+ // Legacy: direct function registration (still supported)
57
76
  functions: {
58
77
  prompt: {
59
- params: [{ name: 'text', type: 'string' }],
78
+ params: [{ name: 'text', type: { kind: 'string' } }],
60
79
  fn: async (args, ctx, location) => { /* ... */ },
80
+ annotations: {},
81
+ returnType: { kind: 'string' },
61
82
  },
62
83
  },
63
84
 
64
- // Variables injected into script scope
65
- variables: {
66
- config: { greeting: 'hello' },
67
- },
68
-
69
85
  // Callbacks
70
86
  callbacks: {
71
87
  onLog: (value) => console.log(value),
@@ -159,7 +175,7 @@ import { createCryptoExtension } from '@rcrsr/rill/ext/crypto';
159
175
  | `@rcrsr/rill/ext/kv` | `createKvExtension(config)` | Key-value store with JSON persistence and schema validation |
160
176
  | `@rcrsr/rill/ext/crypto` | `createCryptoExtension(config)` | Cryptographic functions (hash, hmac, uuid, random) |
161
177
 
162
- Each factory returns an `ExtensionResult` with host function definitions ready to integrate into your runtime context.
178
+ Each factory returns an `ExtensionFactoryResult` with a `value` dict of host functions and optional lifecycle hooks (`dispose`, `suspend`, `restore`) ready to integrate into your runtime context.
163
179
 
164
180
  > **Note:** These extensions require Node.js APIs and are not compatible with browser environments.
165
181
 
@@ -4,7 +4,7 @@
4
4
  * Provides cryptographic functions via thin wrapper around node:crypto.
5
5
  * Functions: hash, hmac, uuid, random
6
6
  */
7
- import type { ExtensionResult, ExtensionConfigSchema, ExtensionManifest } from '../../runtime/ext/extensions.js';
7
+ import type { ExtensionFactoryResult, ExtensionConfigSchema, ExtensionManifest } from '../../runtime/ext/extensions.js';
8
8
  export declare const configSchema: ExtensionConfigSchema;
9
9
  /** Crypto extension configuration */
10
10
  export interface CryptoConfig {
@@ -19,7 +19,7 @@ export interface CryptoConfig {
19
19
  * Returns 4 functions: hash, hmac, uuid, random.
20
20
  *
21
21
  * @param config - Crypto configuration
22
- * @returns ExtensionResult with 4 crypto functions
22
+ * @returns ExtensionFactoryResult with 4 crypto functions
23
23
  *
24
24
  * @example
25
25
  * ```typescript
@@ -29,5 +29,5 @@ export interface CryptoConfig {
29
29
  * });
30
30
  * ```
31
31
  */
32
- export declare function createCryptoExtension(config?: CryptoConfig): ExtensionResult;
32
+ export declare function createCryptoExtension(config?: CryptoConfig): ExtensionFactoryResult;
33
33
  export declare const extensionManifest: ExtensionManifest;
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import crypto from 'node:crypto';
8
8
  import { RuntimeError } from '../../error-classes.js';
9
+ import { toCallable } from '../../runtime/core/callable.js';
9
10
  import { rillTypeToTypeValue, } from '../../runtime/core/values.js';
10
11
  // ============================================================
11
12
  // TYPES
@@ -23,7 +24,7 @@ export const configSchema = {
23
24
  * Returns 4 functions: hash, hmac, uuid, random.
24
25
  *
25
26
  * @param config - Crypto configuration
26
- * @returns ExtensionResult with 4 crypto functions
27
+ * @returns ExtensionFactoryResult with 4 crypto functions
27
28
  *
28
29
  * @example
29
30
  * ```typescript
@@ -100,64 +101,66 @@ export function createCryptoExtension(config = {}) {
100
101
  // EXTENSION RESULT
101
102
  // ============================================================
102
103
  return {
103
- hash: {
104
- params: [
105
- {
106
- name: 'input',
107
- type: { type: 'string' },
108
- defaultValue: undefined,
109
- annotations: { description: 'Content to hash' },
104
+ value: {
105
+ hash: toCallable({
106
+ params: [
107
+ {
108
+ name: 'input',
109
+ type: { kind: 'string' },
110
+ defaultValue: undefined,
111
+ annotations: { description: 'Content to hash' },
112
+ },
113
+ {
114
+ name: 'algorithm',
115
+ type: { kind: 'string' },
116
+ defaultValue: defaultAlgorithm,
117
+ annotations: { description: 'Hash algorithm' },
118
+ },
119
+ ],
120
+ fn: hash,
121
+ annotations: { description: 'Hash content, returns hex output' },
122
+ returnType: rillTypeToTypeValue({ kind: 'string' }),
123
+ }),
124
+ hmac: toCallable({
125
+ params: [
126
+ {
127
+ name: 'input',
128
+ type: { kind: 'string' },
129
+ defaultValue: undefined,
130
+ annotations: { description: 'Content to authenticate' },
131
+ },
132
+ {
133
+ name: 'algorithm',
134
+ type: { kind: 'string' },
135
+ defaultValue: defaultAlgorithm,
136
+ annotations: { description: 'Hash algorithm' },
137
+ },
138
+ ],
139
+ fn: hmac,
140
+ annotations: {
141
+ description: 'Generate HMAC signature, returns hex output',
110
142
  },
111
- {
112
- name: 'algorithm',
113
- type: { type: 'string' },
114
- defaultValue: defaultAlgorithm,
115
- annotations: { description: 'Hash algorithm' },
116
- },
117
- ],
118
- fn: hash,
119
- annotations: { description: 'Hash content, returns hex output' },
120
- returnType: rillTypeToTypeValue({ type: 'string' }),
121
- },
122
- hmac: {
123
- params: [
124
- {
125
- name: 'input',
126
- type: { type: 'string' },
127
- defaultValue: undefined,
128
- annotations: { description: 'Content to authenticate' },
129
- },
130
- {
131
- name: 'algorithm',
132
- type: { type: 'string' },
133
- defaultValue: defaultAlgorithm,
134
- annotations: { description: 'Hash algorithm' },
135
- },
136
- ],
137
- fn: hmac,
138
- annotations: {
139
- description: 'Generate HMAC signature, returns hex output',
140
- },
141
- returnType: rillTypeToTypeValue({ type: 'string' }),
142
- },
143
- uuid: {
144
- params: [],
145
- fn: uuid,
146
- annotations: { description: 'Generate random UUID v4' },
147
- returnType: rillTypeToTypeValue({ type: 'string' }),
148
- },
149
- random: {
150
- params: [
151
- {
152
- name: 'bytes',
153
- type: { type: 'number' },
154
- defaultValue: undefined,
155
- annotations: { description: 'Number of bytes' },
156
- },
157
- ],
158
- fn: random,
159
- annotations: { description: 'Generate random bytes as hex string' },
160
- returnType: rillTypeToTypeValue({ type: 'string' }),
143
+ returnType: rillTypeToTypeValue({ kind: 'string' }),
144
+ }),
145
+ uuid: toCallable({
146
+ params: [],
147
+ fn: uuid,
148
+ annotations: { description: 'Generate random UUID v4' },
149
+ returnType: rillTypeToTypeValue({ kind: 'string' }),
150
+ }),
151
+ random: toCallable({
152
+ params: [
153
+ {
154
+ name: 'bytes',
155
+ type: { kind: 'number' },
156
+ defaultValue: undefined,
157
+ annotations: { description: 'Number of bytes' },
158
+ },
159
+ ],
160
+ fn: random,
161
+ annotations: { description: 'Generate random bytes as hex string' },
162
+ returnType: rillTypeToTypeValue({ kind: 'string' }),
163
+ }),
161
164
  },
162
165
  };
163
166
  }
@@ -4,7 +4,7 @@
4
4
  * Provides sandboxed command execution via allowlist/blocklist security controls.
5
5
  * Each declared command becomes a function with argument validation and process isolation.
6
6
  */
7
- import type { ExtensionResult, ExtensionConfigSchema, ExtensionManifest } from '../../runtime/ext/extensions.js';
7
+ import type { ExtensionFactoryResult, ExtensionConfigSchema, ExtensionManifest } from '../../runtime/ext/extensions.js';
8
8
  import { type CommandConfig } from './runner.js';
9
9
  export declare const configSchema: ExtensionConfigSchema;
10
10
  /** exec extension configuration */
@@ -27,7 +27,7 @@ export type { CommandConfig };
27
27
  * Returns dispose() function to abort in-flight processes.
28
28
  *
29
29
  * @param config - Command definitions and defaults
30
- * @returns ExtensionResult with command functions and dispose
30
+ * @returns ExtensionFactoryResult with command functions and dispose
31
31
  *
32
32
  * @example
33
33
  * ```typescript
@@ -42,5 +42,5 @@ export type { CommandConfig };
42
42
  * });
43
43
  * ```
44
44
  */
45
- export declare function createExecExtension(config: ExecConfig): ExtensionResult;
45
+ export declare function createExecExtension(config: ExecConfig): ExtensionFactoryResult;
46
46
  export declare const extensionManifest: ExtensionManifest;
@@ -4,6 +4,7 @@
4
4
  * Provides sandboxed command execution via allowlist/blocklist security controls.
5
5
  * Each declared command becomes a function with argument validation and process isolation.
6
6
  */
7
+ import { toCallable } from '../../runtime/core/callable.js';
7
8
  import { rillTypeToTypeValue, } from '../../runtime/core/values.js';
8
9
  import { runCommand, } from './runner.js';
9
10
  // ============================================================
@@ -23,7 +24,7 @@ export const configSchema = {
23
24
  * Returns dispose() function to abort in-flight processes.
24
25
  *
25
26
  * @param config - Command definitions and defaults
26
- * @returns ExtensionResult with command functions and dispose
27
+ * @returns ExtensionFactoryResult with command functions and dispose
27
28
  *
28
29
  * @example
29
30
  * ```typescript
@@ -118,13 +119,13 @@ export function createExecExtension(config) {
118
119
  params: [
119
120
  {
120
121
  name: 'args',
121
- type: { type: 'list' },
122
+ type: { kind: 'list' },
122
123
  defaultValue: [],
123
124
  annotations: { description: 'Command arguments' },
124
125
  },
125
126
  {
126
127
  name: 'stdin',
127
- type: { type: 'string' },
128
+ type: { kind: 'string' },
128
129
  defaultValue: '',
129
130
  annotations: { description: 'Standard input data' },
130
131
  },
@@ -133,7 +134,7 @@ export function createExecExtension(config) {
133
134
  annotations: {
134
135
  description: commandConfig.description ?? `Execute ${commandName} command`,
135
136
  },
136
- returnType: rillTypeToTypeValue({ type: 'dict' }),
137
+ returnType: rillTypeToTypeValue({ kind: 'dict' }),
137
138
  };
138
139
  }
139
140
  // ============================================================
@@ -153,7 +154,7 @@ export function createExecExtension(config) {
153
154
  params: [],
154
155
  fn: commands,
155
156
  annotations: { description: 'List all configured commands' },
156
- returnType: rillTypeToTypeValue({ type: 'list' }),
157
+ returnType: rillTypeToTypeValue({ kind: 'list' }),
157
158
  };
158
159
  // ============================================================
159
160
  // DISPOSE FUNCTION
@@ -169,9 +170,14 @@ export function createExecExtension(config) {
169
170
  // ============================================================
170
171
  // EXTENSION RESULT
171
172
  // ============================================================
172
- const result = functions;
173
- result.dispose = dispose;
174
- return result;
173
+ const callableDict = {};
174
+ for (const [name, def] of Object.entries(functions)) {
175
+ callableDict[name] = toCallable(def);
176
+ }
177
+ return {
178
+ value: callableDict,
179
+ dispose,
180
+ };
175
181
  }
176
182
  // ============================================================
177
183
  // MANIFEST
@@ -5,7 +5,7 @@
5
5
  * Scripts call endpoints with positional args or single dict argument.
6
6
  * All URLs are constructed from config - scripts cannot specify arbitrary URLs.
7
7
  */
8
- import type { ExtensionResult, ExtensionConfigSchema, ExtensionManifest } from '../../runtime/ext/extensions.js';
8
+ import type { ExtensionFactoryResult, ExtensionConfigSchema, ExtensionManifest } from '../../runtime/ext/extensions.js';
9
9
  export declare const configSchema: ExtensionConfigSchema;
10
10
  /** Parameter definition for endpoint */
11
11
  export interface EndpointParam {
@@ -46,7 +46,7 @@ export interface FetchConfig {
46
46
  * All URLs constructed from config - scripts cannot create arbitrary URLs.
47
47
  *
48
48
  * @param config - Fetch configuration with endpoints
49
- * @returns ExtensionResult with endpoint functions and introspection
49
+ * @returns ExtensionFactoryResult with endpoint functions and introspection
50
50
  * @throws Error on invalid configuration
51
51
  *
52
52
  * @example
@@ -65,5 +65,5 @@ export interface FetchConfig {
65
65
  * });
66
66
  * ```
67
67
  */
68
- export declare function createFetchExtension(config: FetchConfig): ExtensionResult;
68
+ export declare function createFetchExtension(config: FetchConfig): ExtensionFactoryResult;
69
69
  export declare const extensionManifest: ExtensionManifest;
@@ -6,7 +6,7 @@
6
6
  * All URLs are constructed from config - scripts cannot specify arbitrary URLs.
7
7
  */
8
8
  import { RuntimeError } from '../../error-classes.js';
9
- import {} from '../../runtime/core/callable.js';
9
+ import { toCallable } from '../../runtime/core/callable.js';
10
10
  import { rillTypeToTypeValue, } from '../../runtime/core/values.js';
11
11
  import { buildRequest, executeRequest, createSemaphore, } from './request.js';
12
12
  // ============================================================
@@ -96,7 +96,7 @@ function processArguments(args, params, functionName) {
96
96
  * All URLs constructed from config - scripts cannot create arbitrary URLs.
97
97
  *
98
98
  * @param config - Fetch configuration with endpoints
99
- * @returns ExtensionResult with endpoint functions and introspection
99
+ * @returns ExtensionFactoryResult with endpoint functions and introspection
100
100
  * @throws Error on invalid configuration
101
101
  *
102
102
  * @example
@@ -164,10 +164,10 @@ export function createFetchExtension(config) {
164
164
  };
165
165
  // Build parameter definitions for RillFunction
166
166
  const rillParams = params.map((param) => {
167
- // Map EndpointParam type string to RillType object
167
+ // Map EndpointParam type string to TypeStructure object
168
168
  const rillType = param.type !== 'dict'
169
- ? { type: param.type }
170
- : { type: 'dict' };
169
+ ? { kind: param.type }
170
+ : { kind: 'dict' };
171
171
  return {
172
172
  name: param.name,
173
173
  type: rillType,
@@ -176,8 +176,8 @@ export function createFetchExtension(config) {
176
176
  };
177
177
  });
178
178
  const returnTypeValue = (endpointConfig.responseShape ?? defaultResponseShape) === 'full'
179
- ? rillTypeToTypeValue({ type: 'dict' })
180
- : rillTypeToTypeValue({ type: 'any' });
179
+ ? rillTypeToTypeValue({ kind: 'dict' })
180
+ : rillTypeToTypeValue({ kind: 'any' });
181
181
  const hostFunctionDef = {
182
182
  params: rillParams,
183
183
  fn: endpointFn,
@@ -211,7 +211,7 @@ export function createFetchExtension(config) {
211
211
  params: [],
212
212
  fn: endpoints,
213
213
  annotations: { description: 'List configured endpoints' },
214
- returnType: rillTypeToTypeValue({ type: 'list' }),
214
+ returnType: rillTypeToTypeValue({ kind: 'list' }),
215
215
  };
216
216
  // ============================================================
217
217
  // DISPOSAL
@@ -229,9 +229,14 @@ export function createFetchExtension(config) {
229
229
  // ============================================================
230
230
  // EXTENSION RESULT
231
231
  // ============================================================
232
- const result = functions;
233
- result.dispose = dispose;
234
- return result;
232
+ const callableDict = {};
233
+ for (const [name, def] of Object.entries(functions)) {
234
+ callableDict[name] = toCallable(def);
235
+ }
236
+ return {
237
+ value: callableDict,
238
+ dispose,
239
+ };
235
240
  }
236
241
  // ============================================================
237
242
  // MANIFEST
@@ -4,7 +4,7 @@
4
4
  * Provides sandboxed filesystem operations via mount-based access control.
5
5
  * All 12 functions implement path validation, permission checks, and glob filtering.
6
6
  */
7
- import type { ExtensionResult, ExtensionConfigSchema, ExtensionManifest } from '../../runtime/ext/extensions.js';
7
+ import type { ExtensionFactoryResult, ExtensionConfigSchema, ExtensionManifest } from '../../runtime/ext/extensions.js';
8
8
  import { type MountConfig } from './sandbox.js';
9
9
  /** Filesystem extension configuration */
10
10
  export interface FsConfig {
@@ -24,7 +24,7 @@ export declare const configSchema: ExtensionConfigSchema;
24
24
  * Returns 12 functions: read, write, append, list, find, exists, remove, stat, mkdir, copy, move, mounts.
25
25
  *
26
26
  * @param config - Mount configuration and defaults
27
- * @returns ExtensionResult with 12 filesystem functions
27
+ * @returns ExtensionFactoryResult with 12 filesystem functions
28
28
  * @throws RuntimeError if mount initialization fails
29
29
  *
30
30
  * @example
@@ -36,5 +36,5 @@ export declare const configSchema: ExtensionConfigSchema;
36
36
  * });
37
37
  * ```
38
38
  */
39
- export declare function createFsExtension(config: FsConfig): ExtensionResult;
39
+ export declare function createFsExtension(config: FsConfig): ExtensionFactoryResult;
40
40
  export declare const extensionManifest: ExtensionManifest;