@noetic-tools/types 0.1.1

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 (55) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +19 -0
  3. package/dist/errors/noetic-config-error.d.ts +41 -0
  4. package/dist/errors/noetic-config-error.js +44 -0
  5. package/dist/errors/noetic-error.d.ts +18 -0
  6. package/dist/errors/noetic-error.js +54 -0
  7. package/dist/index.d.ts +29 -0
  8. package/dist/index.js +29 -0
  9. package/dist/schemas/item.d.ts +35 -0
  10. package/dist/schemas/item.js +155 -0
  11. package/dist/types/channel.d.ts +29 -0
  12. package/dist/types/channel.js +1 -0
  13. package/dist/types/common.d.ts +68 -0
  14. package/dist/types/common.js +1 -0
  15. package/dist/types/context-parts/item-log.d.ts +6 -0
  16. package/dist/types/context-parts/item-log.js +1 -0
  17. package/dist/types/context-parts/layer-usage.d.ts +18 -0
  18. package/dist/types/context-parts/layer-usage.js +1 -0
  19. package/dist/types/context.d.ts +202 -0
  20. package/dist/types/context.js +1 -0
  21. package/dist/types/detached.d.ts +17 -0
  22. package/dist/types/detached.js +7 -0
  23. package/dist/types/error.d.ts +66 -0
  24. package/dist/types/error.js +1 -0
  25. package/dist/types/fs-adapter.d.ts +51 -0
  26. package/dist/types/fs-adapter.js +3 -0
  27. package/dist/types/harness-result.d.ts +43 -0
  28. package/dist/types/harness-result.js +2 -0
  29. package/dist/types/items.d.ts +131 -0
  30. package/dist/types/items.js +2 -0
  31. package/dist/types/memory-context.d.ts +39 -0
  32. package/dist/types/memory-context.js +1 -0
  33. package/dist/types/memory.d.ts +305 -0
  34. package/dist/types/memory.js +13 -0
  35. package/dist/types/observability.d.ts +30 -0
  36. package/dist/types/observability.js +1 -0
  37. package/dist/types/runtime.d.ts +256 -0
  38. package/dist/types/runtime.js +1 -0
  39. package/dist/types/shell-adapter.d.ts +34 -0
  40. package/dist/types/shell-adapter.js +10 -0
  41. package/dist/types/steering.d.ts +89 -0
  42. package/dist/types/steering.js +14 -0
  43. package/dist/types/step.d.ts +231 -0
  44. package/dist/types/step.js +1 -0
  45. package/dist/types/subprocess-adapter.d.ts +157 -0
  46. package/dist/types/subprocess-adapter.js +3 -0
  47. package/dist/types/tool-context.d.ts +34 -0
  48. package/dist/types/tool-context.js +1 -0
  49. package/dist/types/tool.d.ts +64 -0
  50. package/dist/types/tool.js +1 -0
  51. package/dist/util/framework-cast.d.ts +10 -0
  52. package/dist/util/framework-cast.js +16 -0
  53. package/dist/util/message-helpers.d.ts +17 -0
  54. package/dist/util/message-helpers.js +64 -0
  55. package/package.json +73 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Matt Apperson
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing
201
+ permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @noetic-tools/types
2
+
3
+ Foundational type contracts and primitives shared across the Noetic framework.
4
+
5
+ This package holds the dependency-free vocabulary the rest of Noetic is built
6
+ on: the conversation `Item` data model, LLM configuration (`LlmProviderConfig`,
7
+ `ModelParams`, `LLMResponse`), execution context and steering contracts,
8
+ platform adapter interfaces (`FsAdapter`, `ShellAdapter`, `SubprocessAdapter`),
9
+ the error model, and the `Item` schema.
10
+
11
+ It is consumed by [`@noetic-tools/memory`](https://www.npmjs.com/package/@noetic-tools/memory)
12
+ and [`@noetic-tools/core`](https://www.npmjs.com/package/@noetic-tools/core),
13
+ both of which re-export the parts relevant to their public surface. Application
14
+ code normally imports these types from `@noetic-tools/core` rather than from
15
+ this package directly.
16
+
17
+ ## License
18
+
19
+ Apache-2.0
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @public
3
+ * Configuration-time error thrown during construction and setup.
4
+ *
5
+ * `NoeticConfigError` is separate from `NoeticError`. The two are never interchangeable:
6
+ * - `NoeticError` — thrown during execution (LLM failures, fork failures, budget exceeded).
7
+ * - `NoeticConfigError` — thrown during construction (invalid step config, missing env vars, runtime misconfiguration).
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * try {
12
+ * loop({ id: '', steps: [], until: until.maxSteps(10) });
13
+ * } catch (e) {
14
+ * if (isNoeticConfigError(e)) {
15
+ * console.error(e.code, e.hint);
16
+ * }
17
+ * }
18
+ * ```
19
+ */
20
+ export declare class NoeticConfigError extends Error {
21
+ /** SCREAMING_SNAKE_CASE code uniquely identifying this error condition. */
22
+ readonly code: string;
23
+ /** Complete sentence describing what the user should do next. */
24
+ readonly hint: string;
25
+ /** Link to the relevant docs page, if available. */
26
+ readonly docsUrl?: string;
27
+ constructor(opts: {
28
+ code: string;
29
+ message: string;
30
+ hint: string;
31
+ docsUrl?: string;
32
+ });
33
+ }
34
+ /**
35
+ * @public
36
+ * Type guard for `NoeticConfigError`.
37
+ *
38
+ * @param e - Value to check.
39
+ * @returns `true` if `e` is a `NoeticConfigError`.
40
+ */
41
+ export declare function isNoeticConfigError(e: unknown): e is NoeticConfigError;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @public
3
+ * Configuration-time error thrown during construction and setup.
4
+ *
5
+ * `NoeticConfigError` is separate from `NoeticError`. The two are never interchangeable:
6
+ * - `NoeticError` — thrown during execution (LLM failures, fork failures, budget exceeded).
7
+ * - `NoeticConfigError` — thrown during construction (invalid step config, missing env vars, runtime misconfiguration).
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * try {
12
+ * loop({ id: '', steps: [], until: until.maxSteps(10) });
13
+ * } catch (e) {
14
+ * if (isNoeticConfigError(e)) {
15
+ * console.error(e.code, e.hint);
16
+ * }
17
+ * }
18
+ * ```
19
+ */
20
+ export class NoeticConfigError extends Error {
21
+ /** SCREAMING_SNAKE_CASE code uniquely identifying this error condition. */
22
+ code;
23
+ /** Complete sentence describing what the user should do next. */
24
+ hint;
25
+ /** Link to the relevant docs page, if available. */
26
+ docsUrl;
27
+ constructor(opts) {
28
+ super(opts.message);
29
+ this.name = 'NoeticConfigError';
30
+ this.code = opts.code;
31
+ this.hint = opts.hint;
32
+ this.docsUrl = opts.docsUrl;
33
+ }
34
+ }
35
+ /**
36
+ * @public
37
+ * Type guard for `NoeticConfigError`.
38
+ *
39
+ * @param e - Value to check.
40
+ * @returns `true` if `e` is a `NoeticConfigError`.
41
+ */
42
+ export function isNoeticConfigError(e) {
43
+ return e instanceof NoeticConfigError;
44
+ }
@@ -0,0 +1,18 @@
1
+ import type { NoeticError } from '../types/error.js';
2
+ /**
3
+ * Runtime error thrown during step execution (LLM failures, fork failures, budget exceeded, etc.).
4
+ *
5
+ * @public
6
+ */
7
+ export declare class NoeticErrorImpl extends Error {
8
+ readonly noeticError: NoeticError;
9
+ constructor(error: NoeticError);
10
+ }
11
+ /**
12
+ * Type guard for `NoeticErrorImpl`.
13
+ *
14
+ * @public
15
+ * @param e - Value to check.
16
+ * @returns `true` if `e` is a `NoeticErrorImpl`.
17
+ */
18
+ export declare function isNoeticError(e: unknown): e is NoeticErrorImpl;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Runtime error thrown during step execution (LLM failures, fork failures, budget exceeded, etc.).
3
+ *
4
+ * @public
5
+ */
6
+ export class NoeticErrorImpl extends Error {
7
+ noeticError;
8
+ constructor(error) {
9
+ super(formatMessage(error));
10
+ this.name = 'NoeticError';
11
+ this.noeticError = error;
12
+ }
13
+ }
14
+ /**
15
+ * Type guard for `NoeticErrorImpl`.
16
+ *
17
+ * @public
18
+ * @param e - Value to check.
19
+ * @returns `true` if `e` is a `NoeticErrorImpl`.
20
+ */
21
+ export function isNoeticError(e) {
22
+ return e instanceof NoeticErrorImpl;
23
+ }
24
+ function formatMessage(error) {
25
+ switch (error.kind) {
26
+ case 'step_failed':
27
+ return `Step '${error.stepId}' failed: ${error.cause.message}`;
28
+ case 'llm_refused':
29
+ return `LLM refused at step '${error.stepId}': ${error.refusal}`;
30
+ case 'llm_parse_error':
31
+ return `LLM parse error at step '${error.stepId}': failed to parse output`;
32
+ case 'llm_rate_limit':
33
+ return `LLM rate limited at step '${error.stepId}'${error.retryAfter ? ` (retry after ${error.retryAfter}ms)` : ''}`;
34
+ case 'fork_partial':
35
+ return `Fork '${error.stepId}' partial failure: ${error.succeeded.length} succeeded, ${error.failed.length} failed`;
36
+ case 'channel_timeout':
37
+ return `Channel '${error.channelName}' timed out after ${error.timeout}ms`;
38
+ case 'channel_closed':
39
+ return `Channel '${error.channelName}' is closed`;
40
+ case 'cancelled':
41
+ return `Cancelled${error.reason ? `: ${error.reason}` : ''}`;
42
+ case 'budget_exceeded':
43
+ return `Budget exceeded: ${error.field} limit ${error.limit}, actual ${error.actual}`;
44
+ case 'steering_denied':
45
+ return `Steering denied${error.guidance ? `: ${error.guidance}` : ''}`;
46
+ case 'handle_evicted':
47
+ return `Subprocess handle '${error.handleId}' evicted (step '${error.stepId}'): adapter returned null for ${error.gracePeriodMs}ms`;
48
+ default: {
49
+ const _exhaustive = error;
50
+ void _exhaustive;
51
+ return 'NoeticError: unknown kind';
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @noetic-tools/types — foundational type contracts and primitives shared
3
+ * across the Noetic framework.
4
+ */
5
+ export * from './errors/noetic-config-error.js';
6
+ export * from './errors/noetic-error.js';
7
+ export * from './schemas/item.js';
8
+ export * from './types/channel.js';
9
+ export * from './types/common.js';
10
+ export * from './types/context.js';
11
+ export * from './types/context-parts/item-log.js';
12
+ export * from './types/context-parts/layer-usage.js';
13
+ export * from './types/detached.js';
14
+ export * from './types/error.js';
15
+ export * from './types/fs-adapter.js';
16
+ export * from './types/harness-result.js';
17
+ export * from './types/items.js';
18
+ export * from './types/memory.js';
19
+ export * from './types/memory-context.js';
20
+ export * from './types/observability.js';
21
+ export * from './types/runtime.js';
22
+ export * from './types/shell-adapter.js';
23
+ export * from './types/steering.js';
24
+ export * from './types/step.js';
25
+ export * from './types/subprocess-adapter.js';
26
+ export * from './types/tool.js';
27
+ export * from './types/tool-context.js';
28
+ export * from './util/framework-cast.js';
29
+ export * from './util/message-helpers.js';
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @noetic-tools/types — foundational type contracts and primitives shared
3
+ * across the Noetic framework.
4
+ */
5
+ export * from './errors/noetic-config-error.js';
6
+ export * from './errors/noetic-error.js';
7
+ export * from './schemas/item.js';
8
+ export * from './types/channel.js';
9
+ export * from './types/common.js';
10
+ export * from './types/context.js';
11
+ export * from './types/context-parts/item-log.js';
12
+ export * from './types/context-parts/layer-usage.js';
13
+ export * from './types/detached.js';
14
+ export * from './types/error.js';
15
+ export * from './types/fs-adapter.js';
16
+ export * from './types/harness-result.js';
17
+ export * from './types/items.js';
18
+ export * from './types/memory.js';
19
+ export * from './types/memory-context.js';
20
+ export * from './types/observability.js';
21
+ export * from './types/runtime.js';
22
+ export * from './types/shell-adapter.js';
23
+ export * from './types/steering.js';
24
+ export * from './types/step.js';
25
+ export * from './types/subprocess-adapter.js';
26
+ export * from './types/tool.js';
27
+ export * from './types/tool-context.js';
28
+ export * from './util/framework-cast.js';
29
+ export * from './util/message-helpers.js';
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Runtime schema for the `Item` union.
3
+ *
4
+ * The `Item` type is a discriminated union of framework-created items
5
+ * (`InputMessageItem`, `FunctionCallOutputItem`) and provider-shaped items
6
+ * from `@openrouter/agent` whose shapes are defined by the SDK's generated
7
+ * types. Mirroring those provider shapes as Zod schemas would drift as the
8
+ * SDK evolves, so the runtime schema validates only the structural invariant
9
+ * every `Item` shares: an object with a non-empty string `type` discriminant.
10
+ *
11
+ * Use this at trust boundaries (loading persisted session files, accepting
12
+ * externally-supplied transcripts) where we need to reject garbage JSON but
13
+ * don't need to re-validate every provider field TypeScript already types.
14
+ */
15
+ import { z } from 'zod';
16
+ import type { Item, ItemSchemaExtensions } from '../types/items.js';
17
+ /** @public Structural validator for `Item`. Asserts non-empty string `type` discriminant. */
18
+ export declare const ItemSchema: z.ZodCustom<Item, Item>;
19
+ type ItemSchemaCategory = keyof Required<ItemSchemaExtensions>;
20
+ export declare function mergeExtensions(a: ItemSchemaExtensions | undefined, b: ItemSchemaExtensions | undefined): ItemSchemaExtensions;
21
+ /** @public Runtime item validator with optional tool, memory-layer, and harness extension schemas. */
22
+ export declare class ItemSchemaRegistry {
23
+ readonly extensions: ItemSchemaExtensions;
24
+ readonly strictUnknownExtensions: boolean;
25
+ constructor(extensions?: ItemSchemaExtensions, opts?: {
26
+ strictUnknownExtensions?: boolean;
27
+ });
28
+ extend(extensions?: ItemSchemaExtensions): ItemSchemaRegistry;
29
+ parse(value: unknown): Item;
30
+ parseMany(values: Iterable<unknown>): Item[];
31
+ parseWithCategory(value: unknown, category: ItemSchemaCategory): Item;
32
+ }
33
+ /** @public Default item schema registry. */
34
+ export declare const defaultItemSchemaRegistry: ItemSchemaRegistry;
35
+ export {};
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Runtime schema for the `Item` union.
3
+ *
4
+ * The `Item` type is a discriminated union of framework-created items
5
+ * (`InputMessageItem`, `FunctionCallOutputItem`) and provider-shaped items
6
+ * from `@openrouter/agent` whose shapes are defined by the SDK's generated
7
+ * types. Mirroring those provider shapes as Zod schemas would drift as the
8
+ * SDK evolves, so the runtime schema validates only the structural invariant
9
+ * every `Item` shares: an object with a non-empty string `type` discriminant.
10
+ *
11
+ * Use this at trust boundaries (loading persisted session files, accepting
12
+ * externally-supplied transcripts) where we need to reject garbage JSON but
13
+ * don't need to re-validate every provider field TypeScript already types.
14
+ */
15
+ import { z } from 'zod';
16
+ function isItemLike(value) {
17
+ if (typeof value !== 'object' || value === null) {
18
+ return false;
19
+ }
20
+ if (!('type' in value)) {
21
+ return false;
22
+ }
23
+ const { type } = value;
24
+ return typeof type === 'string' && type.length > 0;
25
+ }
26
+ /** @public Structural validator for `Item`. Asserts non-empty string `type` discriminant. */
27
+ export const ItemSchema = z.custom(isItemLike, {
28
+ message: 'Expected an Item object with a non-empty string "type" discriminant.',
29
+ });
30
+ function hasSchemas(extensions) {
31
+ return Boolean(extensions.items?.length ||
32
+ extensions.developerMessages?.length ||
33
+ extensions.toolCalls?.length ||
34
+ extensions.toolResults?.length);
35
+ }
36
+ export function mergeExtensions(a, b) {
37
+ return {
38
+ items: [
39
+ ...(a?.items ?? []),
40
+ ...(b?.items ?? []),
41
+ ],
42
+ developerMessages: [
43
+ ...(a?.developerMessages ?? []),
44
+ ...(b?.developerMessages ?? []),
45
+ ],
46
+ toolCalls: [
47
+ ...(a?.toolCalls ?? []),
48
+ ...(b?.toolCalls ?? []),
49
+ ],
50
+ toolResults: [
51
+ ...(a?.toolResults ?? []),
52
+ ...(b?.toolResults ?? []),
53
+ ],
54
+ };
55
+ }
56
+ function schemasForCategory(extensions, category) {
57
+ return extensions[category] ?? [];
58
+ }
59
+ function isRecord(value) {
60
+ return typeof value === 'object' && value !== null;
61
+ }
62
+ function relevantCategories(value) {
63
+ const categories = [
64
+ 'items',
65
+ ];
66
+ if (isRecord(value) && value.type === 'message' && value.role === 'developer') {
67
+ categories.push('developerMessages');
68
+ }
69
+ if (isRecord(value) && value.type === 'function_call') {
70
+ categories.push('toolCalls');
71
+ }
72
+ if (isRecord(value) && value.type === 'function_call_output') {
73
+ categories.push('toolResults');
74
+ }
75
+ return categories;
76
+ }
77
+ function isKnownBaseType(type) {
78
+ return (type === 'message' ||
79
+ type === 'function_call' ||
80
+ type === 'function_call_output' ||
81
+ type === 'reasoning' ||
82
+ type === 'web_search_call' ||
83
+ type === 'file_search_call' ||
84
+ type === 'image_generation_call' ||
85
+ type.startsWith('openrouter:'));
86
+ }
87
+ function schemaMismatch(category) {
88
+ return new z.ZodError([
89
+ {
90
+ code: 'custom',
91
+ message: `Item did not match any registered ${category} extension schema.`,
92
+ path: [],
93
+ },
94
+ ]);
95
+ }
96
+ /** @public Runtime item validator with optional tool, memory-layer, and harness extension schemas. */
97
+ export class ItemSchemaRegistry {
98
+ extensions;
99
+ strictUnknownExtensions;
100
+ constructor(extensions, opts) {
101
+ this.extensions = mergeExtensions(undefined, extensions);
102
+ this.strictUnknownExtensions = opts?.strictUnknownExtensions ?? true;
103
+ }
104
+ extend(extensions) {
105
+ if (!extensions || !hasSchemas(extensions)) {
106
+ return this;
107
+ }
108
+ return new ItemSchemaRegistry(mergeExtensions(this.extensions, extensions), {
109
+ strictUnknownExtensions: this.strictUnknownExtensions,
110
+ });
111
+ }
112
+ parse(value) {
113
+ const base = ItemSchema.parse(value);
114
+ const categories = relevantCategories(base);
115
+ const schemas = categories.flatMap((category) => schemasForCategory(this.extensions, category));
116
+ for (const schema of schemas) {
117
+ const parsed = schema.safeParse(value);
118
+ if (parsed.success) {
119
+ return ItemSchema.parse(parsed.data);
120
+ }
121
+ }
122
+ if (this.strictUnknownExtensions && !isKnownBaseType(base.type)) {
123
+ throw new z.ZodError([
124
+ {
125
+ code: 'custom',
126
+ message: `Item type '${base.type}' did not match any registered item extension schema.`,
127
+ path: [
128
+ 'type',
129
+ ],
130
+ },
131
+ ]);
132
+ }
133
+ return base;
134
+ }
135
+ parseMany(values) {
136
+ return Array.from(values, (value) => this.parse(value));
137
+ }
138
+ parseWithCategory(value, category) {
139
+ const schemas = schemasForCategory(this.extensions, category);
140
+ if (schemas.length === 0) {
141
+ return this.parse(value);
142
+ }
143
+ for (const schema of schemas) {
144
+ const parsed = schema.safeParse(value);
145
+ if (parsed.success) {
146
+ return ItemSchema.parse(parsed.data);
147
+ }
148
+ }
149
+ throw schemaMismatch(category);
150
+ }
151
+ }
152
+ /** @public Default item schema registry. */
153
+ export const defaultItemSchemaRegistry = new ItemSchemaRegistry(undefined, {
154
+ strictUnknownExtensions: true,
155
+ });
@@ -0,0 +1,29 @@
1
+ import type { ZodType } from 'zod';
2
+ /**
3
+ * A typed communication channel between steps within an execution tree.
4
+ * @public
5
+ */
6
+ export interface Channel<T> {
7
+ /** Channel name for identification and debugging. */
8
+ readonly name: string;
9
+ /** Zod schema used to validate every message sent through the channel. */
10
+ readonly schema: ZodType<T>;
11
+ /** Delivery semantics: `'value'` (last-write-wins), `'queue'` (FIFO), `'topic'` (pub/sub). */
12
+ readonly mode: 'value' | 'queue' | 'topic';
13
+ /** Buffer size for queue mode (default: 1000). Ignored for value/topic modes. */
14
+ readonly capacity?: number;
15
+ }
16
+ /**
17
+ * A channel that is writable from outside the execution tree (e.g. user input).
18
+ * @public
19
+ */
20
+ export interface ExternalChannel<T> extends Channel<T> {
21
+ /** Marker indicating the channel accepts writes from external callers. */
22
+ readonly external: true;
23
+ }
24
+ /** @public Handle for sending messages to a channel and checking its closed state. */
25
+ export interface ChannelHandle<T> {
26
+ send(value: T): void;
27
+ readonly closed: boolean;
28
+ readonly channel: Channel<T>;
29
+ }
@@ -0,0 +1 @@
1
+ export {};