@noetic-tools/types 1.2.0 → 1.3.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.
package/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ export * from './types/items.js';
18
18
  export * from './types/memory.js';
19
19
  export * from './types/memory-context.js';
20
20
  export * from './types/observability.js';
21
+ export * from './types/output-codec.js';
21
22
  export * from './types/runtime.js';
22
23
  export * from './types/shell-adapter.js';
23
24
  export * from './types/steering.js';
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ export * from './types/items.js';
18
18
  export * from './types/memory.js';
19
19
  export * from './types/memory-context.js';
20
20
  export * from './types/observability.js';
21
+ export * from './types/output-codec.js';
21
22
  export * from './types/runtime.js';
22
23
  export * from './types/shell-adapter.js';
23
24
  export * from './types/steering.js';
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Streaming output-dialect contracts for `step.llm`.
3
+ *
4
+ * An `OutputCodec` is the dialect-agnostic alternative to a Zod schema in
5
+ * `StepLLM.output`: instead of JSON-parsing the assistant text once at turn
6
+ * end, a codec is fed each text delta as it streams and produces a typed
7
+ * value when the turn finishes. OpenUI Lang is one dialect; the contract
8
+ * lives here — next to `MemoryLayer` and `SubHarness` — so `core` and
9
+ * dialect packages both depend on it without forming a cycle.
10
+ */
11
+ /**
12
+ * Emitter handed to a codec session so it can surface framework events
13
+ * (e.g. `openui.node`) while a turn streams. Events flow through the
14
+ * executing step's normal framework-event surface and respect the step's
15
+ * `emit` gate.
16
+ * @public
17
+ */
18
+ export type OutputCodecEventEmitter = (type: string, data: Record<string, unknown>) => void;
19
+ /**
20
+ * A stateful parse of one turn's streamed output. Codecs are stateful while
21
+ * a turn streams, so the interpreter starts one session per turn.
22
+ * @public
23
+ */
24
+ export interface OutputCodecSession<O = unknown> {
25
+ /**
26
+ * Fed each assistant text delta in stream order. Declared as a method
27
+ * (bivariant params) so concrete sessions assign to the erased form.
28
+ */
29
+ push(delta: string, emit: OutputCodecEventEmitter): void;
30
+ /**
31
+ * Called once at turn end with the full assistant text. Returns the typed
32
+ * output. Throwing here surfaces through the same error path as a Zod
33
+ * structured-output parse failure.
34
+ */
35
+ finish(fullText: string): O;
36
+ }
37
+ /**
38
+ * A streaming output dialect for `step.llm`. Discriminated from a Zod schema
39
+ * in `StepLLM.output` by the `kind: 'codec'` tag.
40
+ * @public
41
+ */
42
+ export interface OutputCodec<O = unknown> {
43
+ kind: 'codec';
44
+ /** Appended to the step's system instructions (e.g. a generated component-library prompt). */
45
+ instructions?: string;
46
+ /** One session per turn. */
47
+ start(): OutputCodecSession<O>;
48
+ }
49
+ /**
50
+ * Narrows a `StepLLM.output` value to an `OutputCodec`. A Zod schema has no
51
+ * `kind: 'codec'` tag, so the discriminant is unambiguous.
52
+ * @public
53
+ */
54
+ export declare function isOutputCodec<O>(value: unknown): value is OutputCodec<O>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Streaming output-dialect contracts for `step.llm`.
3
+ *
4
+ * An `OutputCodec` is the dialect-agnostic alternative to a Zod schema in
5
+ * `StepLLM.output`: instead of JSON-parsing the assistant text once at turn
6
+ * end, a codec is fed each text delta as it streams and produces a typed
7
+ * value when the turn finishes. OpenUI Lang is one dialect; the contract
8
+ * lives here — next to `MemoryLayer` and `SubHarness` — so `core` and
9
+ * dialect packages both depend on it without forming a cycle.
10
+ */
11
+ /**
12
+ * Narrows a `StepLLM.output` value to an `OutputCodec`. A Zod schema has no
13
+ * `kind: 'codec'` tag, so the discriminant is unambiguous.
14
+ * @public
15
+ */
16
+ export function isOutputCodec(value) {
17
+ if (typeof value !== 'object' || value === null || !('kind' in value) || !('start' in value)) {
18
+ return false;
19
+ }
20
+ const record = value;
21
+ return record.kind === 'codec' && typeof record.start === 'function';
22
+ }
@@ -4,6 +4,7 @@ import type { ModelParams, RetryPolicy, ServerToolSpec, StepMeta } from './commo
4
4
  import type { Context } from './context.js';
5
5
  import type { NoeticError } from './error.js';
6
6
  import type { ContextMemory, MemoryConfig, MemoryLayer, ProjectionPolicy } from './memory.js';
7
+ import type { OutputCodec } from './output-codec.js';
7
8
  import type { SubHarness, SubHarnessKind, SubHarnessSessionPolicy, SubHarnessSettings } from './sub-harness.js';
8
9
  import type { SubprocessAdapter } from './subprocess-adapter.js';
9
10
  import type { Tool } from './tool.js';
@@ -102,7 +103,12 @@ export interface StepLLM<TMemory = ContextMemory, _I = unknown, O = unknown> {
102
103
  * they are resolved per execution.
103
104
  */
104
105
  tools?: Lazy<(Tool | ServerToolSpec)[] | undefined, TMemory>;
105
- output?: ZodType<O>;
106
+ /**
107
+ * Structured output: a Zod schema (assistant text is JSON-parsed and
108
+ * validated) or a streaming `OutputCodec` (fed each text delta, produces
109
+ * the typed value at turn end).
110
+ */
111
+ output?: ZodType<O> | OutputCodec<O>;
106
112
  params?: ModelParams;
107
113
  /** Controls framework event emission for this step. Defaults to `true`. Set `false` to suppress all framework events. A filter function receives `(eventType, data)` and returns `boolean`. */
108
114
  emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
@@ -18,6 +18,37 @@ export interface ToolMemoryDeclaration<TState = unknown> {
18
18
  */
19
19
  recall(state: TState): string | null;
20
20
  }
21
+ /**
22
+ * A renderable UI fragment in a named dialect (e.g. `'openui-lang/0.5'`).
23
+ * The framework never interprets `source` — it forwards fragments as
24
+ * `openui.fragment` framework events and attaches them to items; a UI
25
+ * surface (memory layer + transport) composes and renders them.
26
+ * @public
27
+ */
28
+ export interface UiFragment {
29
+ /** Dialect identifier, e.g. `'openui-lang/0.5'`. */
30
+ dialect: string;
31
+ /** Fragment source in that dialect, e.g. `'root = Card([Spinner()])'`. */
32
+ source: string;
33
+ }
34
+ /**
35
+ * Declares tool-owned UI: programmatic render functions invoked at tool
36
+ * lifecycle points. All methods are optional — an omitted point renders
37
+ * nothing (mirrors `ToolMemoryDeclaration`). Declared as methods (bivariant
38
+ * params) so a concretely-typed declaration assigns to the erased form the
39
+ * `tool()` builder and runtime consume.
40
+ * @public
41
+ */
42
+ export interface ToolUiDeclaration<I extends ZodTypeAny = ZodTypeAny, O extends ZodTypeAny = ZodTypeAny, E = unknown> {
43
+ /** Rendered as soon as the call streams in — args may be partial. */
44
+ call?(args: Partial<z.infer<I>>): UiFragment | null;
45
+ /** Re-rendered on each event an AsyncGenerator `execute` yields. Receives all events so far. */
46
+ progress?(events: E[]): UiFragment | null;
47
+ /** Replaces the tool's region on successful completion. */
48
+ result?(output: z.infer<O>, args: z.infer<I>): UiFragment | null;
49
+ /** Replaces the tool's region when execution throws. */
50
+ error?(err: unknown, args: z.infer<I>): UiFragment | null;
51
+ }
21
52
  /**
22
53
  * A tool definition that an LLM can invoke during execution.
23
54
  *
@@ -60,5 +91,7 @@ export interface Tool<I extends ZodTypeAny = ZodTypeAny, O extends ZodTypeAny =
60
91
  needsApproval?: boolean;
61
92
  /** Optional memory declaration — the runtime generates a MemoryLayer from this. */
62
93
  memory?: ToolMemoryDeclaration;
94
+ /** Optional UI declaration — the runtime emits the rendered fragments at call/progress/result points. */
95
+ ui?: ToolUiDeclaration<I, O>;
63
96
  }
64
97
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noetic-tools/types",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "description": "Foundational type contracts and primitives shared across the Noetic framework (items, LLM config, adapters, steering, errors).",
6
6
  "license": "Apache-2.0",