@noetic-tools/types 1.1.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 +1 -0
- package/dist/index.js +1 -0
- package/dist/types/common.d.ts +22 -0
- package/dist/types/common.js +19 -1
- package/dist/types/output-codec.d.ts +54 -0
- package/dist/types/output-codec.js +22 -0
- package/dist/types/runtime.d.ts +11 -1
- package/dist/types/step.d.ts +16 -4
- package/dist/types/tool.d.ts +33 -0
- package/package.json +1 -1
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';
|
package/dist/types/common.d.ts
CHANGED
|
@@ -13,6 +13,28 @@ export interface RetryPolicy {
|
|
|
13
13
|
/** Upper bound in ms for the computed delay (caps exponential/linear growth). */
|
|
14
14
|
maxDelay?: number;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Declares an OpenRouter server-executed tool on an LLM step. OpenRouter runs
|
|
18
|
+
* the tool (web search, web fetch) provider-side and returns the result item in
|
|
19
|
+
* the response — no client-side execute function is involved.
|
|
20
|
+
*
|
|
21
|
+
* `parameters` keys are camelCase (e.g. `maxResults`, `searchContextSize`); the
|
|
22
|
+
* SDK re-serialises them to the wire format and silently drops unknown keys.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export interface ServerToolSpec {
|
|
26
|
+
/** Server tool discriminator. */
|
|
27
|
+
type: 'openrouter:web_search' | 'openrouter:web_fetch';
|
|
28
|
+
/** Optional provider config forwarded to the tool (camelCase keys). */
|
|
29
|
+
parameters?: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Distinguishes an inline `ServerToolSpec` from a client `Tool` in a
|
|
33
|
+
* heterogeneous `tools` list. A server-tool spec carries a server-tool `type`
|
|
34
|
+
* discriminator and, unlike a `Tool`, has no `execute` method.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export declare function isServerToolSpec(value: unknown): value is ServerToolSpec;
|
|
16
38
|
/**
|
|
17
39
|
* Optional parameters forwarded to the model provider during an LLM step.
|
|
18
40
|
* @public
|
package/dist/types/common.js
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Distinguishes an inline `ServerToolSpec` from a client `Tool` in a
|
|
3
|
+
* heterogeneous `tools` list. A server-tool spec carries a server-tool `type`
|
|
4
|
+
* discriminator and, unlike a `Tool`, has no `execute` method.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export function isServerToolSpec(value) {
|
|
8
|
+
if (typeof value !== 'object' || value === null) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if ('execute' in value) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (!('type' in value)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const { type } = value;
|
|
18
|
+
return type === 'openrouter:web_search' || type === 'openrouter:web_fetch';
|
|
19
|
+
}
|
|
@@ -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
|
+
}
|
package/dist/types/runtime.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ZodType } from 'zod';
|
|
2
2
|
import type { Channel, ChannelHandle, ExternalChannel } from './channel.js';
|
|
3
|
-
import type { LLMResponse, ModelParams } from './common.js';
|
|
3
|
+
import type { LLMResponse, ModelParams, ServerToolSpec } from './common.js';
|
|
4
4
|
import type { Context, CwdState } from './context.js';
|
|
5
5
|
import type { DetachedHandle } from './detached.js';
|
|
6
6
|
import type { FsAdapter } from './fs-adapter.js';
|
|
@@ -54,6 +54,16 @@ interface CallModelRequestBase {
|
|
|
54
54
|
outputSchema?: ZodType;
|
|
55
55
|
/** Controls framework event emission. Defaults to `true`. Passed through from `StepLLM.emit`. */
|
|
56
56
|
emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
|
|
57
|
+
/**
|
|
58
|
+
* @internal
|
|
59
|
+
* Framework-internal carrier for OpenRouter server tools (web search/fetch).
|
|
60
|
+
* Server tools are an authoring concept inside `StepLLM.tools` — the
|
|
61
|
+
* interpreter partitions those entries out of the client `tools` list and
|
|
62
|
+
* stamps the specs here so the model caller can wrap them via the SDK's
|
|
63
|
+
* `serverTool()` and append them to the SDK tools array. NOT an authored
|
|
64
|
+
* field: public callers declare server tools as `tools` entries, never here.
|
|
65
|
+
*/
|
|
66
|
+
_serverTools?: ServerToolSpec[];
|
|
57
67
|
/** Optional signal for cancelling the in-flight call (used by session abort). */
|
|
58
68
|
signal?: AbortSignal;
|
|
59
69
|
/**
|
package/dist/types/step.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ZodType } from 'zod';
|
|
2
2
|
import type { Channel } from './channel.js';
|
|
3
|
-
import type { ModelParams, RetryPolicy, StepMeta } from './common.js';
|
|
3
|
+
import type { ModelParams, RetryPolicy, ServerToolSpec, StepMeta } from './common.js';
|
|
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';
|
|
@@ -94,9 +95,20 @@ export interface StepLLM<TMemory = ContextMemory, _I = unknown, O = unknown> {
|
|
|
94
95
|
model: Lazy<string, TMemory>;
|
|
95
96
|
/** System instructions. Eager string or `(ctx) => string | undefined` getter. */
|
|
96
97
|
instructions?: Lazy<string | undefined, TMemory>;
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Tools exposed to the LLM. Eager array or `(ctx) => (...)[] | undefined` getter.
|
|
100
|
+
* Entries are either a client `Tool` or an inline `ServerToolSpec` (an
|
|
101
|
+
* OpenRouter server tool the provider executes, e.g. web search/fetch).
|
|
102
|
+
* Function-form tools do not contribute to the pre-computed `ctx.unifiedTools`;
|
|
103
|
+
* they are resolved per execution.
|
|
104
|
+
*/
|
|
105
|
+
tools?: Lazy<(Tool | ServerToolSpec)[] | undefined, TMemory>;
|
|
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>;
|
|
100
112
|
params?: ModelParams;
|
|
101
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`. */
|
|
102
114
|
emit?: boolean | ((eventType: string, data: Record<string, unknown>) => boolean);
|
package/dist/types/tool.d.ts
CHANGED
|
@@ -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.
|
|
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",
|