@kortyx/hooks 0.4.0 → 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/CHANGELOG.md +22 -0
- package/README.md +21 -4
- package/dist/index.d.ts +92 -5
- package/dist/index.js +767 -13
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +24 -3
- package/dist/internal.js +125 -5
- package/dist/internal.js.map +1 -0
- package/package.json +11 -7
- package/dist/context.d.ts +0 -26
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -82
- package/dist/hooks.d.ts +0 -29
- package/dist/hooks.d.ts.map +0 -1
- package/dist/hooks.js +0 -108
- package/dist/index.d.ts.map +0 -1
- package/dist/internal.d.ts.map +0 -1
- package/dist/reason-engine.d.ts +0 -19
- package/dist/reason-engine.d.ts.map +0 -1
- package/dist/reason-engine.js +0 -81
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.5.0](https://github.com/kortyx-io/kortyx/compare/hooks-v0.4.1...hooks-v0.5.0) (2026-02-17)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **hooks:** consolidate reason+interrupt contracts ([4716a4d](https://github.com/kortyx-io/kortyx/commit/4716a4d4739b4a71b7c6e84717c830cd9ff625a6))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **hooks:** stabilize useReason interrupt resume and split internals ([fa24712](https://github.com/kortyx-io/kortyx/commit/fa247129f160d129cdf2c05f0a48a2236ea71bb8))
|
|
14
|
+
* **testing:** add hooks vitest suite and enforce CI test gates ([d3ecdcb](https://github.com/kortyx-io/kortyx/commit/d3ecdcbd0c9e48d88231f0a75eb3b3b2339e9d6d))
|
|
15
|
+
|
|
16
|
+
## [0.4.1](https://github.com/kortyx-io/kortyx/compare/hooks-v0.4.0...hooks-v0.4.1) (2026-02-17)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* **build:** align package tsconfig with shared lib baseline ([48d2b57](https://github.com/kortyx-io/kortyx/commit/48d2b5765fefbb5fcbbe548e749e7b5f51b450b9))
|
|
22
|
+
* **build:** wire tsup for publishable packages ([e7b1b5c](https://github.com/kortyx-io/kortyx/commit/e7b1b5c28af55becffc137233dd92d8953d7cb8e))
|
|
23
|
+
* **dev:** restore tsc watch flow for local workspace ([4305823](https://github.com/kortyx-io/kortyx/commit/430582372cad466bf28af554042aa11bdb8bf027))
|
|
24
|
+
|
|
3
25
|
## [0.4.0](https://github.com/kortyx-io/kortyx/compare/hooks-v0.3.0...hooks-v0.4.0) (2026-02-17)
|
|
4
26
|
|
|
5
27
|
|
package/README.md
CHANGED
|
@@ -8,13 +8,30 @@ Lifecycle hooks and extension points for Kortyx.
|
|
|
8
8
|
npm install @kortyx/hooks
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Key APIs
|
|
12
|
+
|
|
13
|
+
- `useReason(...)` for model calls, optional schema-constrained interrupt flow, and structured output.
|
|
14
|
+
- `useInterrupt(...)` for explicit human-in-the-loop pauses.
|
|
15
|
+
- `useStructuredData(...)` for UI-friendly structured stream events.
|
|
16
|
+
- `useNodeState(...)` / `useWorkflowState(...)` for stateful node logic.
|
|
17
|
+
|
|
18
|
+
## LangGraph Resume Behavior
|
|
19
|
+
|
|
20
|
+
Kortyx uses LangGraph as the execution engine. On resume, the node function is replayed from the top.
|
|
21
|
+
|
|
22
|
+
- `useReason` resumes from its internal checkpoint.
|
|
23
|
+
- Code before `useReason` will re-run unless guarded.
|
|
12
24
|
|
|
13
|
-
|
|
25
|
+
Workarounds:
|
|
14
26
|
|
|
15
|
-
- `
|
|
27
|
+
- Keep nodes minimal and call `useReason` first.
|
|
28
|
+
- Guard pre-`useReason` side effects with `useNodeState`.
|
|
29
|
+
|
|
30
|
+
## Documentation
|
|
31
|
+
|
|
32
|
+
- Runtime hooks: `apps/website/src/docs/v0/03-runtime/01-hooks.md`
|
|
33
|
+
- Interrupts/resume: `apps/website/src/docs/v0/03-runtime/02-interrupts-and-resume.md`
|
|
16
34
|
|
|
17
35
|
## License
|
|
18
36
|
|
|
19
37
|
Apache-2.0
|
|
20
|
-
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { NodeContext, GraphState, InterruptInput, InterruptResult } from '@kortyx/core';
|
|
2
|
+
import { MemoryAdapter } from '@kortyx/memory';
|
|
3
|
+
import { GetProviderFn, ProviderModelRef } from '@kortyx/providers';
|
|
4
|
+
|
|
5
|
+
type HookRuntimeContext = {
|
|
6
|
+
node: NodeContext;
|
|
7
|
+
state: GraphState;
|
|
8
|
+
getProvider?: GetProviderFn;
|
|
9
|
+
memoryAdapter?: MemoryAdapter;
|
|
10
|
+
};
|
|
11
|
+
declare function runWithHookContext<T>(ctx: HookRuntimeContext, fn: () => Promise<T>): Promise<{
|
|
12
|
+
result: T;
|
|
13
|
+
memoryUpdates: Record<string, unknown> | null;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
type SchemaLike<T> = {
|
|
17
|
+
safeParse: (value: unknown) => {
|
|
18
|
+
success: true;
|
|
19
|
+
data: T;
|
|
20
|
+
} | {
|
|
21
|
+
success: false;
|
|
22
|
+
error: {
|
|
23
|
+
message?: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
type StructuredDataMode = "final" | "patch" | "snapshot";
|
|
28
|
+
type UseStructuredDataArgs<TData = unknown> = {
|
|
29
|
+
data: TData;
|
|
30
|
+
dataType?: string | undefined;
|
|
31
|
+
dataSchema?: SchemaLike<TData> | undefined;
|
|
32
|
+
mode?: StructuredDataMode | undefined;
|
|
33
|
+
schemaId?: string | undefined;
|
|
34
|
+
schemaVersion?: string | undefined;
|
|
35
|
+
id?: string | undefined;
|
|
36
|
+
opId?: string | undefined;
|
|
37
|
+
};
|
|
38
|
+
type UseReasonStructuredStreamMode = "off" | "patch" | "snapshot";
|
|
39
|
+
type UseReasonStructuredConfig = {
|
|
40
|
+
stream?: UseReasonStructuredStreamMode | undefined;
|
|
41
|
+
optimistic?: boolean | undefined;
|
|
42
|
+
dataType?: string | undefined;
|
|
43
|
+
schemaId?: string | undefined;
|
|
44
|
+
schemaVersion?: string | undefined;
|
|
45
|
+
};
|
|
46
|
+
type UseReasonInterruptConfig<TRequest extends InterruptInput = InterruptInput, TResponse = InterruptResult> = {
|
|
47
|
+
requestSchema: SchemaLike<TRequest>;
|
|
48
|
+
responseSchema?: SchemaLike<TResponse> | undefined;
|
|
49
|
+
schemaId?: string | undefined;
|
|
50
|
+
schemaVersion?: string | undefined;
|
|
51
|
+
};
|
|
52
|
+
type UseReasonArgs<TOutput = unknown, TRequest extends InterruptInput = InterruptInput, TResponse = InterruptResult> = {
|
|
53
|
+
model: ProviderModelRef;
|
|
54
|
+
input: string;
|
|
55
|
+
system?: string | undefined;
|
|
56
|
+
temperature?: number | undefined;
|
|
57
|
+
emit?: boolean | undefined;
|
|
58
|
+
stream?: boolean | undefined;
|
|
59
|
+
id?: string | undefined;
|
|
60
|
+
outputSchema?: SchemaLike<TOutput> | undefined;
|
|
61
|
+
structured?: UseReasonStructuredConfig | undefined;
|
|
62
|
+
interrupt?: UseReasonInterruptConfig<TRequest, TResponse> | undefined;
|
|
63
|
+
};
|
|
64
|
+
type UseReasonResult<TOutput = unknown, TResponse = InterruptResult> = {
|
|
65
|
+
id?: string;
|
|
66
|
+
opId: string;
|
|
67
|
+
text: string;
|
|
68
|
+
raw?: unknown;
|
|
69
|
+
output?: TOutput;
|
|
70
|
+
interruptResponse?: TResponse;
|
|
71
|
+
};
|
|
72
|
+
type UseInterruptArgs<TRequest extends InterruptInput = InterruptInput, TResponse = InterruptResult> = {
|
|
73
|
+
request: TRequest;
|
|
74
|
+
requestSchema?: SchemaLike<TRequest> | undefined;
|
|
75
|
+
responseSchema?: SchemaLike<TResponse> | undefined;
|
|
76
|
+
schemaId?: string | undefined;
|
|
77
|
+
schemaVersion?: string | undefined;
|
|
78
|
+
id?: string | undefined;
|
|
79
|
+
meta?: Record<string, unknown> | undefined;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
type StateSetter<T> = (next: T | ((prev: T) => T)) => void;
|
|
83
|
+
declare function useEmit(): NodeContext["emit"];
|
|
84
|
+
declare function useStructuredData<TData = unknown>(args: UseStructuredDataArgs<TData>): void;
|
|
85
|
+
declare function useReason<TOutput = unknown, TRequest extends InterruptInput = InterruptInput, TResponse = InterruptResult>(args: UseReasonArgs<TOutput, TRequest, TResponse>): Promise<UseReasonResult<TOutput, TResponse>>;
|
|
86
|
+
declare function useAiMemory(): MemoryAdapter;
|
|
87
|
+
declare function useInterrupt<TRequest extends InterruptInput = InterruptInput, TResponse = InterruptResult>(args: UseInterruptArgs<TRequest, TResponse>): Promise<TResponse>;
|
|
88
|
+
declare function useNodeState<T>(initialValue: T): [T, StateSetter<T>];
|
|
89
|
+
declare function useNodeState<T>(key: string, initialValue?: T): [T, StateSetter<T>];
|
|
90
|
+
declare function useWorkflowState<T>(key: string, initialValue?: T): [T, StateSetter<T>];
|
|
91
|
+
|
|
92
|
+
export { type HookRuntimeContext, type UseInterruptArgs, type UseReasonArgs, type UseReasonResult, type UseStructuredDataArgs, runWithHookContext, useAiMemory, useEmit, useInterrupt, useNodeState, useReason, useStructuredData, useWorkflowState };
|