@neutrome/lilsdk 0.4.5 → 0.5.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/README.md +24 -21
- package/etc/api/index.api.md +96 -0
- package/etc/api/loops.api.md +108 -0
- package/etc/api/managed.api.md +102 -0
- package/etc/api/primitives.api.md +39 -0
- package/etc/api/stream.api.md +46 -0
- package/etc/api/tools.api.md +103 -0
- package/package.json +8 -9
- package/src/index.ts +41 -15
- package/src/loops/goal.ts +111 -0
- package/src/loops/index.ts +41 -110
- package/src/loops/shared.ts +27 -0
- package/src/managed/attachment-to-text.ts +35 -11
- package/src/managed/capabilities.ts +65 -25
- package/src/managed/index.ts +0 -14
- package/src/observe.ts +21 -6
- package/src/output.ts +13 -25
- package/src/primitives/index.ts +69 -0
- package/src/stream/index.ts +2 -6
- package/src/stream/stages.ts +15 -11
- package/src/tools-support.ts +61 -30
- package/src/tools.ts +37 -20
- package/src/types.ts +129 -4
- package/test/lilsdk-ts.test.ts +71 -341
- package/test/tools.test.ts +69 -21
- package/src/managed/two-pass-request.ts +0 -164
- package/src/managed/two-pass.ts +0 -171
- package/src/synthetic/index.ts +0 -134
package/README.md
CHANGED
|
@@ -3,29 +3,32 @@
|
|
|
3
3
|
High-level TypeScript SDK for transport-neutral model authoring on top of `@neutrome/lil-engine`.
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
|
-
import {
|
|
7
|
-
import { retry } from "@neutrome/lilsdk/loops";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from "@neutrome/lilsdk/stream";
|
|
12
|
-
import { connectTools } from "@neutrome/lilsdk/tools";
|
|
6
|
+
import type { Executor } from "@neutrome/lilsdk";
|
|
7
|
+
import { fallback, retry } from "@neutrome/lilsdk/loops";
|
|
8
|
+
import { createToolsExecutor } from "@neutrome/lilsdk/tools";
|
|
9
|
+
import { observeExecutionStream, writeThinking } from "@neutrome/lilsdk/stream";
|
|
10
|
+
import { prependSystemPrompt } from "@neutrome/lil-engine";
|
|
13
11
|
```
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
Every symbol has exactly one import path. The root export is intentionally
|
|
14
|
+
small — SDK contracts only — and each subpath owns one concern:
|
|
16
15
|
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- `@neutrome/lilsdk/
|
|
21
|
-
- `@neutrome/lilsdk/
|
|
22
|
-
- `@neutrome/lilsdk/
|
|
23
|
-
|
|
24
|
-
-
|
|
16
|
+
- root: `Executor`, `ExecutorContext`, `ExecutorInput`, `Tool`,
|
|
17
|
+
`ProgramTransform`, `RuntimeContext`, `Cache`, `ExecutionEvent`,
|
|
18
|
+
`OutputSink`, and `createExecutionEvent`
|
|
19
|
+
- `@neutrome/lilsdk/loops`: `retry`, `fallback`, and `createGoalExecutor`
|
|
20
|
+
- `@neutrome/lilsdk/tools`: `createToolsExecutor` tool-call loop
|
|
21
|
+
- `@neutrome/lilsdk/managed`: `createCapabilitiesExecutor` and
|
|
22
|
+
`createAttachmentToTextExecutor`
|
|
23
|
+
- `@neutrome/lilsdk/stream`: `observeExecutionStream`, `streamStage`, and
|
|
24
|
+
`writeThinking`
|
|
25
|
+
- `@neutrome/lilsdk/primitives`: structural program helpers — `walk`, `map`,
|
|
26
|
+
`filter`, `reduce`, `has`, `find`, `indexOf`, `all`, and `any`
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
Executor factories are named `create*Executor`, except `retry` and `fallback`,
|
|
29
|
+
which read better as bare verbs.
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
and
|
|
31
|
+
Building programs — messages, tool calls, attachments, streaming chunks — is
|
|
32
|
+
`@neutrome/lil-engine`'s job, so `prependSystemPrompt` and friends are imported
|
|
33
|
+
from there. HTTP routing, provider credentials, target resolution and provider
|
|
34
|
+
JSON conversion live in `@neutrome/open-ai-router` and `@neutrome/lil-engine`.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
## API Report File for "neutrome"
|
|
2
|
+
|
|
3
|
+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
|
|
7
|
+
import type { Program } from '@neutrome/lil-engine';
|
|
8
|
+
|
|
9
|
+
// @public
|
|
10
|
+
type Cache_2 = {
|
|
11
|
+
get(key: string): Promise<string | null>;
|
|
12
|
+
put(key: string, value: string, options?: CachePutOptions): Promise<void>;
|
|
13
|
+
delete(key: string): Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
export { Cache_2 as Cache }
|
|
16
|
+
|
|
17
|
+
// @public
|
|
18
|
+
export type CachePutOptions = {
|
|
19
|
+
expiration?: number;
|
|
20
|
+
expirationTtl?: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// @public
|
|
24
|
+
export function createExecutionEvent(input: ExecutionEventInput): ExecutionEvent;
|
|
25
|
+
|
|
26
|
+
// @public
|
|
27
|
+
export type ExecutionEvent = {
|
|
28
|
+
kind: string;
|
|
29
|
+
requestId: string;
|
|
30
|
+
executionId: string;
|
|
31
|
+
timestamp: string;
|
|
32
|
+
parentExecutionId?: string;
|
|
33
|
+
target?: {
|
|
34
|
+
kind: "provider" | "executor";
|
|
35
|
+
id: string;
|
|
36
|
+
};
|
|
37
|
+
errorKind?: string;
|
|
38
|
+
data?: Record<string, unknown>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// @public
|
|
42
|
+
export type ExecutionEventInput = Omit<ExecutionEvent, "timestamp"> & {
|
|
43
|
+
timestamp?: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// @public
|
|
47
|
+
export type Executor = {
|
|
48
|
+
execute(request: Program, ctx: ExecutorContext): Promise<Program>;
|
|
49
|
+
stream(request: Program, ctx: ExecutorContext): AsyncIterable<Program>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// @public
|
|
53
|
+
export type ExecutorContext = RuntimeContext & {
|
|
54
|
+
requestId: string;
|
|
55
|
+
executionId: string;
|
|
56
|
+
parentExecutionId?: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// @public
|
|
60
|
+
export type ExecutorInput = string | Executor;
|
|
61
|
+
|
|
62
|
+
// @public
|
|
63
|
+
export type OutputSink = {
|
|
64
|
+
write(chunk: Program): void | Promise<void>;
|
|
65
|
+
close(): void | Promise<void>;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// @public
|
|
69
|
+
export type ProgramTransform = {
|
|
70
|
+
name: string;
|
|
71
|
+
capabilities: TransformCapability[];
|
|
72
|
+
apply(program: Program, ctx: RuntimeContext): Program | Promise<Program>;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// @public
|
|
76
|
+
export type RuntimeContext = {
|
|
77
|
+
cache: Cache_2;
|
|
78
|
+
invoke(executor: ExecutorInput, request: Program): Promise<Program>;
|
|
79
|
+
invokeStream(executor: ExecutorInput, request: Program): AsyncIterable<Program>;
|
|
80
|
+
observe(event: ExecutionEvent): void;
|
|
81
|
+
signal: AbortSignal;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// @public
|
|
85
|
+
export type Tool = {
|
|
86
|
+
name: string;
|
|
87
|
+
description: string;
|
|
88
|
+
schema: Record<string, unknown>;
|
|
89
|
+
systemPromptFragment?: string;
|
|
90
|
+
execute(args: Record<string, unknown>, ctx: ExecutorContext): Promise<string>;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// @public
|
|
94
|
+
export type TransformCapability = "read_messages" | "write_messages" | "write_config" | "write_tools" | "drop_content" | "provider_extension";
|
|
95
|
+
|
|
96
|
+
```
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
## API Report File for "neutrome"
|
|
2
|
+
|
|
3
|
+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
|
|
7
|
+
import { Program } from '@neutrome/lil-engine';
|
|
8
|
+
|
|
9
|
+
// @public
|
|
10
|
+
type Cache_2 = {
|
|
11
|
+
get(key: string): Promise<string | null>;
|
|
12
|
+
put(key: string, value: string, options?: CachePutOptions): Promise<void>;
|
|
13
|
+
delete(key: string): Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// @public
|
|
17
|
+
type CachePutOptions = {
|
|
18
|
+
expiration?: number;
|
|
19
|
+
expirationTtl?: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Warning: (ae-forgotten-export) The symbol "Executor" needs to be exported by the entry point index.d.ts
|
|
23
|
+
//
|
|
24
|
+
// @public
|
|
25
|
+
export function createGoalExecutor(options: GoalExecutorOptions): Executor;
|
|
26
|
+
|
|
27
|
+
// @public
|
|
28
|
+
type ExecutionEvent = {
|
|
29
|
+
kind: string;
|
|
30
|
+
requestId: string;
|
|
31
|
+
executionId: string;
|
|
32
|
+
timestamp: string;
|
|
33
|
+
parentExecutionId?: string;
|
|
34
|
+
target?: {
|
|
35
|
+
kind: "provider" | "executor";
|
|
36
|
+
id: string;
|
|
37
|
+
};
|
|
38
|
+
errorKind?: string;
|
|
39
|
+
data?: Record<string, unknown>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// @public
|
|
43
|
+
type Executor = {
|
|
44
|
+
execute(request: Program, ctx: ExecutorContext): Promise<Program>;
|
|
45
|
+
stream(request: Program, ctx: ExecutorContext): AsyncIterable<Program>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Warning: (ae-forgotten-export) The symbol "RuntimeContext" needs to be exported by the entry point index.d.ts
|
|
49
|
+
//
|
|
50
|
+
// @public
|
|
51
|
+
type ExecutorContext = RuntimeContext & {
|
|
52
|
+
requestId: string;
|
|
53
|
+
executionId: string;
|
|
54
|
+
parentExecutionId?: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// @public
|
|
58
|
+
type ExecutorInput = string | Executor;
|
|
59
|
+
|
|
60
|
+
// Warning: (ae-forgotten-export) The symbol "ExecutorInput" needs to be exported by the entry point index.d.ts
|
|
61
|
+
//
|
|
62
|
+
// @public
|
|
63
|
+
export function fallback(executors: readonly ExecutorInput[], options?: FallbackOptions): Executor;
|
|
64
|
+
|
|
65
|
+
// @public
|
|
66
|
+
export type FallbackOptions = {
|
|
67
|
+
shouldFallback?: (error: unknown, executorIndex: number) => boolean | Promise<boolean>;
|
|
68
|
+
onFallback?: (error: unknown, executorIndex: number) => void | Promise<void>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// @public
|
|
72
|
+
export type GoalExecutorOptions = {
|
|
73
|
+
draft: ExecutorInput;
|
|
74
|
+
review: ExecutorInput;
|
|
75
|
+
refine: (request: Program, answer: Program, review: Program, attempt: number) => Program | Promise<Program>;
|
|
76
|
+
satisfied: (review: Program, attempt: number) => boolean | Promise<boolean>;
|
|
77
|
+
maxIterations?: number;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// @public
|
|
81
|
+
export function retry(executor: ExecutorInput, options?: RetryOptions): Executor;
|
|
82
|
+
|
|
83
|
+
// @public
|
|
84
|
+
export type RetryOptions = {
|
|
85
|
+
attempts?: number;
|
|
86
|
+
shouldRetry?: (error: unknown, attempt: number) => boolean | Promise<boolean>;
|
|
87
|
+
onRetry?: (error: unknown, attempt: number) => void | Promise<void>;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// @public
|
|
91
|
+
type RuntimeContext = {
|
|
92
|
+
cache: Cache_2;
|
|
93
|
+
invoke(executor: ExecutorInput, request: Program): Promise<Program>;
|
|
94
|
+
invokeStream(executor: ExecutorInput, request: Program): AsyncIterable<Program>;
|
|
95
|
+
observe(event: ExecutionEvent): void;
|
|
96
|
+
signal: AbortSignal;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// Warnings were encountered during analysis:
|
|
100
|
+
//
|
|
101
|
+
// .reference-build/types/neutrome-lilsdk/src/types.d.ts:42:5 - (ae-forgotten-export) The symbol "CachePutOptions" needs to be exported by the entry point index.d.ts
|
|
102
|
+
// .reference-build/types/neutrome-lilsdk/src/types.d.ts:55:5 - (ae-forgotten-export) The symbol "Cache_2" needs to be exported by the entry point index.d.ts
|
|
103
|
+
// .reference-build/types/neutrome-lilsdk/src/types.d.ts:77:5 - (ae-forgotten-export) The symbol "ExecutionEvent" needs to be exported by the entry point index.d.ts
|
|
104
|
+
// .reference-build/types/neutrome-lilsdk/src/types.d.ts:131:5 - (ae-forgotten-export) The symbol "ExecutorContext" needs to be exported by the entry point index.d.ts
|
|
105
|
+
|
|
106
|
+
// (No @packageDocumentation comment for this package)
|
|
107
|
+
|
|
108
|
+
```
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
## API Report File for "neutrome"
|
|
2
|
+
|
|
3
|
+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
|
|
7
|
+
import type { Program } from '@neutrome/lil-engine';
|
|
8
|
+
import { ProgramAttachment } from '@neutrome/lil-engine';
|
|
9
|
+
|
|
10
|
+
// @public
|
|
11
|
+
export type AttachmentReaderRule = {
|
|
12
|
+
mimeTypes: readonly string[];
|
|
13
|
+
executor: ExecutorInput;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// @public
|
|
17
|
+
export type AttachmentToTextOptions = {
|
|
18
|
+
systemPrompt?: string;
|
|
19
|
+
cacheKey?: (attachment: ProgramAttachment, ctx: ExecutorContext) => string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// @public
|
|
23
|
+
type Cache_2 = {
|
|
24
|
+
get(key: string): Promise<string | null>;
|
|
25
|
+
put(key: string, value: string, options?: CachePutOptions): Promise<void>;
|
|
26
|
+
delete(key: string): Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// @public
|
|
30
|
+
type CachePutOptions = {
|
|
31
|
+
expiration?: number;
|
|
32
|
+
expirationTtl?: number;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// @public
|
|
36
|
+
export type CapabilitiesExecutorOptions = {
|
|
37
|
+
enabledIterations?: number;
|
|
38
|
+
cacheKey?: (ctx: ExecutorContext) => string;
|
|
39
|
+
skipPrefixes?: readonly string[];
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Warning: (ae-forgotten-export) The symbol "Executor" needs to be exported by the entry point index.d.ts
|
|
43
|
+
//
|
|
44
|
+
// @public
|
|
45
|
+
export function createAttachmentToTextExecutor(inner: ExecutorInput, rules: readonly AttachmentReaderRule[], options?: AttachmentToTextOptions): Executor;
|
|
46
|
+
|
|
47
|
+
// @public
|
|
48
|
+
export function createCapabilitiesExecutor(inner: ExecutorInput, options?: CapabilitiesExecutorOptions): Executor;
|
|
49
|
+
|
|
50
|
+
// @public
|
|
51
|
+
type ExecutionEvent = {
|
|
52
|
+
kind: string;
|
|
53
|
+
requestId: string;
|
|
54
|
+
executionId: string;
|
|
55
|
+
timestamp: string;
|
|
56
|
+
parentExecutionId?: string;
|
|
57
|
+
target?: {
|
|
58
|
+
kind: "provider" | "executor";
|
|
59
|
+
id: string;
|
|
60
|
+
};
|
|
61
|
+
errorKind?: string;
|
|
62
|
+
data?: Record<string, unknown>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// @public
|
|
66
|
+
type Executor = {
|
|
67
|
+
execute(request: Program, ctx: ExecutorContext): Promise<Program>;
|
|
68
|
+
stream(request: Program, ctx: ExecutorContext): AsyncIterable<Program>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Warning: (ae-forgotten-export) The symbol "RuntimeContext" needs to be exported by the entry point index.d.ts
|
|
72
|
+
//
|
|
73
|
+
// @public
|
|
74
|
+
type ExecutorContext = RuntimeContext & {
|
|
75
|
+
requestId: string;
|
|
76
|
+
executionId: string;
|
|
77
|
+
parentExecutionId?: string;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// @public
|
|
81
|
+
type ExecutorInput = string | Executor;
|
|
82
|
+
|
|
83
|
+
// @public
|
|
84
|
+
type RuntimeContext = {
|
|
85
|
+
cache: Cache_2;
|
|
86
|
+
invoke(executor: ExecutorInput, request: Program): Promise<Program>;
|
|
87
|
+
invokeStream(executor: ExecutorInput, request: Program): AsyncIterable<Program>;
|
|
88
|
+
observe(event: ExecutionEvent): void;
|
|
89
|
+
signal: AbortSignal;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Warnings were encountered during analysis:
|
|
93
|
+
//
|
|
94
|
+
// .reference-build/types/neutrome-lilsdk/src/managed/attachment-to-text.d.ts:8:5 - (ae-forgotten-export) The symbol "ExecutorInput" needs to be exported by the entry point index.d.ts
|
|
95
|
+
// .reference-build/types/neutrome-lilsdk/src/managed/attachment-to-text.d.ts:15:5 - (ae-forgotten-export) The symbol "ExecutorContext" needs to be exported by the entry point index.d.ts
|
|
96
|
+
// .reference-build/types/neutrome-lilsdk/src/types.d.ts:42:5 - (ae-forgotten-export) The symbol "CachePutOptions" needs to be exported by the entry point index.d.ts
|
|
97
|
+
// .reference-build/types/neutrome-lilsdk/src/types.d.ts:55:5 - (ae-forgotten-export) The symbol "Cache_2" needs to be exported by the entry point index.d.ts
|
|
98
|
+
// .reference-build/types/neutrome-lilsdk/src/types.d.ts:77:5 - (ae-forgotten-export) The symbol "ExecutionEvent" needs to be exported by the entry point index.d.ts
|
|
99
|
+
|
|
100
|
+
// (No @packageDocumentation comment for this package)
|
|
101
|
+
|
|
102
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
## API Report File for "neutrome"
|
|
2
|
+
|
|
3
|
+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
|
|
7
|
+
import { Instruction } from '@neutrome/lil-engine';
|
|
8
|
+
import { Program } from '@neutrome/lil-engine';
|
|
9
|
+
|
|
10
|
+
// @public
|
|
11
|
+
export function all(program: Program, callback: (instruction: Instruction, index: number, program: Program) => boolean): boolean;
|
|
12
|
+
|
|
13
|
+
// @public
|
|
14
|
+
export function any(program: Program, callback: (instruction: Instruction, index: number, program: Program) => boolean): boolean;
|
|
15
|
+
|
|
16
|
+
// @public
|
|
17
|
+
export function filter(program: Program, callback: (instruction: Instruction, index: number, program: Program) => boolean): Program;
|
|
18
|
+
|
|
19
|
+
// @public
|
|
20
|
+
export function find(program: Program, needle: Instruction): Instruction | undefined;
|
|
21
|
+
|
|
22
|
+
// @public
|
|
23
|
+
export function has(program: Program, needle: Instruction): boolean;
|
|
24
|
+
|
|
25
|
+
// @public
|
|
26
|
+
export function indexOf(program: Program, needle: Instruction): number;
|
|
27
|
+
|
|
28
|
+
// @public
|
|
29
|
+
export function map(program: Program, callback: (instruction: Instruction, index: number, program: Program) => Instruction): Program;
|
|
30
|
+
|
|
31
|
+
// @public
|
|
32
|
+
export function reduce<T>(program: Program, callback: (accumulator: T, instruction: Instruction, index: number, program: Program) => T, initialValue: T): T;
|
|
33
|
+
|
|
34
|
+
// @public
|
|
35
|
+
export function walk(program: Program, callback: (instruction: Instruction, index: number, program: Program) => void): void;
|
|
36
|
+
|
|
37
|
+
// (No @packageDocumentation comment for this package)
|
|
38
|
+
|
|
39
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
## API Report File for "neutrome"
|
|
2
|
+
|
|
3
|
+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
|
|
7
|
+
import { Program } from '@neutrome/lil-engine';
|
|
8
|
+
|
|
9
|
+
// @public
|
|
10
|
+
export type ObservedExecution = {
|
|
11
|
+
mode: "text";
|
|
12
|
+
transcript: string;
|
|
13
|
+
emittedText: boolean;
|
|
14
|
+
} | {
|
|
15
|
+
mode: "tool";
|
|
16
|
+
transcript: string;
|
|
17
|
+
emittedText: boolean;
|
|
18
|
+
chunks: Program[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// @public
|
|
22
|
+
export function observeExecutionStream(source: AsyncIterable<Program>, hooks?: StreamObservationHooks): Promise<ObservedExecution>;
|
|
23
|
+
|
|
24
|
+
// @public
|
|
25
|
+
type OutputSink = {
|
|
26
|
+
write(chunk: Program): void | Promise<void>;
|
|
27
|
+
close(): void | Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// @public
|
|
31
|
+
export type StreamObservationHooks = {
|
|
32
|
+
onTextStart?: () => void;
|
|
33
|
+
onTextChunk?: (text: string, chunk: Program) => void;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// @public
|
|
37
|
+
export function streamStage(source: AsyncIterable<Program>): AsyncGenerator<Program>;
|
|
38
|
+
|
|
39
|
+
// Warning: (ae-forgotten-export) The symbol "OutputSink" needs to be exported by the entry point index.d.ts
|
|
40
|
+
//
|
|
41
|
+
// @public
|
|
42
|
+
export function writeThinking(sink: OutputSink, text: string): Promise<void>;
|
|
43
|
+
|
|
44
|
+
// (No @packageDocumentation comment for this package)
|
|
45
|
+
|
|
46
|
+
```
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
## API Report File for "neutrome"
|
|
2
|
+
|
|
3
|
+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
|
|
7
|
+
import type { Program } from '@neutrome/lil-engine';
|
|
8
|
+
|
|
9
|
+
// @public
|
|
10
|
+
type Cache_2 = {
|
|
11
|
+
get(key: string): Promise<string | null>;
|
|
12
|
+
put(key: string, value: string, options?: CachePutOptions): Promise<void>;
|
|
13
|
+
delete(key: string): Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// @public
|
|
17
|
+
type CachePutOptions = {
|
|
18
|
+
expiration?: number;
|
|
19
|
+
expirationTtl?: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Warning: (ae-forgotten-export) The symbol "ExecutorInput" needs to be exported by the entry point tools.d.ts
|
|
23
|
+
// Warning: (ae-forgotten-export) The symbol "Tool" needs to be exported by the entry point tools.d.ts
|
|
24
|
+
// Warning: (ae-forgotten-export) The symbol "Executor" needs to be exported by the entry point tools.d.ts
|
|
25
|
+
//
|
|
26
|
+
// @public
|
|
27
|
+
export function createToolsExecutor(inner: ExecutorInput, tools: Tool[], options?: ToolsExecutorOptions): Executor;
|
|
28
|
+
|
|
29
|
+
// @public
|
|
30
|
+
type ExecutionEvent = {
|
|
31
|
+
kind: string;
|
|
32
|
+
requestId: string;
|
|
33
|
+
executionId: string;
|
|
34
|
+
timestamp: string;
|
|
35
|
+
parentExecutionId?: string;
|
|
36
|
+
target?: {
|
|
37
|
+
kind: "provider" | "executor";
|
|
38
|
+
id: string;
|
|
39
|
+
};
|
|
40
|
+
errorKind?: string;
|
|
41
|
+
data?: Record<string, unknown>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// @public
|
|
45
|
+
type Executor = {
|
|
46
|
+
execute(request: Program, ctx: ExecutorContext): Promise<Program>;
|
|
47
|
+
stream(request: Program, ctx: ExecutorContext): AsyncIterable<Program>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Warning: (ae-forgotten-export) The symbol "RuntimeContext" needs to be exported by the entry point tools.d.ts
|
|
51
|
+
//
|
|
52
|
+
// @public
|
|
53
|
+
type ExecutorContext = RuntimeContext & {
|
|
54
|
+
requestId: string;
|
|
55
|
+
executionId: string;
|
|
56
|
+
parentExecutionId?: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// @public
|
|
60
|
+
type ExecutorInput = string | Executor;
|
|
61
|
+
|
|
62
|
+
// @public
|
|
63
|
+
type RuntimeContext = {
|
|
64
|
+
cache: Cache_2;
|
|
65
|
+
invoke(executor: ExecutorInput, request: Program): Promise<Program>;
|
|
66
|
+
invokeStream(executor: ExecutorInput, request: Program): AsyncIterable<Program>;
|
|
67
|
+
observe(event: ExecutionEvent): void;
|
|
68
|
+
signal: AbortSignal;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// @public
|
|
72
|
+
type Tool = {
|
|
73
|
+
name: string;
|
|
74
|
+
description: string;
|
|
75
|
+
schema: Record<string, unknown>;
|
|
76
|
+
systemPromptFragment?: string;
|
|
77
|
+
execute(args: Record<string, unknown>, ctx: ExecutorContext): Promise<string>;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// @public
|
|
81
|
+
export class ToolArgumentsError extends Error {
|
|
82
|
+
constructor(toolName: string, argumentsText: string);
|
|
83
|
+
// (undocumented)
|
|
84
|
+
readonly argumentsText: string;
|
|
85
|
+
// (undocumented)
|
|
86
|
+
readonly toolName: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// @public
|
|
90
|
+
export type ToolsExecutorOptions = {
|
|
91
|
+
maxIterations?: number;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Warnings were encountered during analysis:
|
|
95
|
+
//
|
|
96
|
+
// .reference-build/types/neutrome-lilsdk/src/types.d.ts:42:5 - (ae-forgotten-export) The symbol "CachePutOptions" needs to be exported by the entry point tools.d.ts
|
|
97
|
+
// .reference-build/types/neutrome-lilsdk/src/types.d.ts:55:5 - (ae-forgotten-export) The symbol "Cache_2" needs to be exported by the entry point tools.d.ts
|
|
98
|
+
// .reference-build/types/neutrome-lilsdk/src/types.d.ts:77:5 - (ae-forgotten-export) The symbol "ExecutionEvent" needs to be exported by the entry point tools.d.ts
|
|
99
|
+
// .reference-build/types/neutrome-lilsdk/src/types.d.ts:131:5 - (ae-forgotten-export) The symbol "ExecutorContext" needs to be exported by the entry point tools.d.ts
|
|
100
|
+
|
|
101
|
+
// (No @packageDocumentation comment for this package)
|
|
102
|
+
|
|
103
|
+
```
|
package/package.json
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neutrome/lilsdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts",
|
|
7
|
-
"./types": "./src/types.ts",
|
|
8
7
|
"./primitives": "./src/primitives/index.ts",
|
|
9
|
-
"./synthetic": "./src/synthetic/index.ts",
|
|
10
8
|
"./stream": "./src/stream/index.ts",
|
|
11
9
|
"./tools": "./src/tools.ts",
|
|
12
10
|
"./loops": "./src/loops/index.ts",
|
|
13
11
|
"./managed": "./src/managed/index.ts"
|
|
14
12
|
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
16
|
+
"npm:publish": "pnpm publish --no-git-checks"
|
|
17
|
+
},
|
|
15
18
|
"dependencies": {
|
|
16
|
-
"@neutrome/lil-engine": "
|
|
19
|
+
"@neutrome/lil-engine": "workspace:*"
|
|
17
20
|
},
|
|
18
21
|
"devDependencies": {
|
|
19
22
|
"@types/node": "^25.9.3",
|
|
20
23
|
"typescript": "^6.0.3",
|
|
21
24
|
"vitest": "^4.1.6"
|
|
22
|
-
},
|
|
23
|
-
"scripts": {
|
|
24
|
-
"test": "vitest run",
|
|
25
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
26
25
|
}
|
|
27
|
-
}
|
|
26
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Runtime contracts and combinators for building executors.
|
|
3
|
+
*
|
|
4
|
+
* The root entry point carries only contracts — {@link Executor},
|
|
5
|
+
* {@link Tool}, {@link ProgramTransform}, {@link ExecutorContext} and friends.
|
|
6
|
+
* Everything that does work lives on a subpath, and each symbol has exactly one
|
|
7
|
+
* import path:
|
|
8
|
+
*
|
|
9
|
+
* - `@neutrome/lilsdk/loops` — `retry`, `fallback`, goal loops
|
|
10
|
+
* - `@neutrome/lilsdk/tools` — tool loops
|
|
11
|
+
* - `@neutrome/lilsdk/managed` — capability and attachment executors
|
|
12
|
+
* - `@neutrome/lilsdk/stream` — stream observation and output helpers
|
|
13
|
+
* - `@neutrome/lilsdk/primitives` — functional helpers over instruction lists
|
|
14
|
+
*
|
|
15
|
+
* Programs themselves are built with `@neutrome/lil-engine`, which owns the
|
|
16
|
+
* protocol; this package owns everything that runs.
|
|
17
|
+
*
|
|
18
|
+
* Executor factories are named `create*Executor`, except `retry` and `fallback`,
|
|
19
|
+
* which read better as bare verbs.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import type { Executor } from "@neutrome/lilsdk";
|
|
24
|
+
* import { fallback, retry } from "@neutrome/lilsdk/loops";
|
|
25
|
+
* import { prependSystemPrompt } from "@neutrome/lil-engine";
|
|
26
|
+
*
|
|
27
|
+
* const upstream = fallback([retry("default/glm-5.2", { attempts: 3 }), "fast/gemma-4-31b"]);
|
|
28
|
+
*
|
|
29
|
+
* const executor: Executor = {
|
|
30
|
+
* async execute(request, ctx) {
|
|
31
|
+
* return ctx.invoke(upstream, prependSystemPrompt(request, "Be concise."));
|
|
32
|
+
* },
|
|
33
|
+
* async *stream(request, ctx) {
|
|
34
|
+
* yield* ctx.invokeStream(upstream, prependSystemPrompt(request, "Be concise."));
|
|
35
|
+
* },
|
|
36
|
+
* };
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @packageDocumentation
|
|
40
|
+
*/
|
|
41
|
+
export * from "./types.ts";
|