@ekairos/events 1.22.39-beta.development.0 → 1.22.41-beta.development.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 +5 -3
- package/dist/codex.d.ts +11 -2
- package/dist/codex.js +13 -5
- package/dist/context.action.d.ts +55 -0
- package/dist/context.action.js +25 -0
- package/dist/context.builder.d.ts +52 -42
- package/dist/context.builder.js +29 -24
- package/dist/context.d.ts +2 -1
- package/dist/context.engine.d.ts +50 -47
- package/dist/context.engine.js +222 -173
- package/dist/context.events.js +28 -87
- package/dist/context.js +1 -0
- package/dist/context.part-identity.d.ts +40 -0
- package/dist/context.part-identity.js +268 -0
- package/dist/context.parts.d.ts +389 -164
- package/dist/context.parts.js +235 -224
- package/dist/context.registry.d.ts +1 -1
- package/dist/context.runtime.d.ts +10 -4
- package/dist/context.runtime.js +7 -1
- package/dist/context.step-stream.d.ts +16 -2
- package/dist/context.step-stream.js +58 -16
- package/dist/context.stream.d.ts +4 -0
- package/dist/context.stream.js +23 -1
- package/dist/context.toolcalls.d.ts +8 -20
- package/dist/context.toolcalls.js +61 -55
- package/dist/domain.d.ts +1 -0
- package/dist/domain.js +1 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.js +5 -3
- package/dist/reactors/ai-sdk.chunk-map.js +27 -0
- package/dist/reactors/ai-sdk.reactor.d.ts +8 -9
- package/dist/reactors/ai-sdk.reactor.js +2 -5
- package/dist/reactors/ai-sdk.step.d.ts +2 -3
- package/dist/reactors/ai-sdk.step.js +10 -7
- package/dist/reactors/scripted.reactor.d.ts +7 -4
- package/dist/reactors/types.d.ts +8 -8
- package/dist/schema.d.ts +273 -2
- package/dist/schema.js +1 -1
- package/dist/steps/store.steps.d.ts +51 -12
- package/dist/steps/store.steps.js +137 -0
- package/dist/steps/stream.steps.d.ts +15 -0
- package/dist/steps/stream.steps.js +16 -5
- package/dist/steps/trace.steps.d.ts +4 -4
- package/dist/steps/trace.steps.js +21 -6
- package/dist/tools-to-model-tools.d.ts +4 -2
- package/dist/tools-to-model-tools.js +30 -11
- package/package.json +16 -6
package/README.md
CHANGED
|
@@ -49,10 +49,13 @@ const supportContext = createContext<{ orgId: string }>("support.agent")
|
|
|
49
49
|
Run directly:
|
|
50
50
|
|
|
51
51
|
```ts
|
|
52
|
-
await supportContext.react(triggerEvent, {
|
|
52
|
+
const shell = await supportContext.react(triggerEvent, {
|
|
53
53
|
runtime,
|
|
54
54
|
context: { key: "support:org_123" },
|
|
55
|
+
durable: false,
|
|
55
56
|
});
|
|
57
|
+
|
|
58
|
+
const final = await shell.run!;
|
|
56
59
|
```
|
|
57
60
|
|
|
58
61
|
Run durably:
|
|
@@ -61,10 +64,9 @@ Run durably:
|
|
|
61
64
|
const shell = await supportContext.react(triggerEvent, {
|
|
62
65
|
runtime,
|
|
63
66
|
context: { key: "support:org_123" },
|
|
64
|
-
durable: true,
|
|
65
67
|
});
|
|
66
68
|
|
|
67
|
-
const final = await shell.run
|
|
69
|
+
const final = await shell.run!.returnValue;
|
|
68
70
|
```
|
|
69
71
|
|
|
70
72
|
## Tool execution model
|
package/dist/codex.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { ContextEnvironment } from "./context.config.js";
|
|
3
|
-
import type { ContextModelInit, ContextOptions, ContextReactParams, ContextShouldContinueArgs
|
|
3
|
+
import type { ContextModelInit, ContextOptions, ContextReactParams, ContextShouldContinueArgs } from "./context.engine.js";
|
|
4
|
+
import type { ContextTool } from "./context.action.js";
|
|
4
5
|
import type { ContextKey } from "./context.registry.js";
|
|
5
6
|
import type { StoredContext, ContextItem } from "./context.store.js";
|
|
6
7
|
import type { ContextInstance } from "./context.js";
|
|
@@ -49,6 +50,14 @@ export declare const codexToolInputSchema: z.ZodObject<{
|
|
|
49
50
|
fileId: z.ZodOptional<z.ZodString>;
|
|
50
51
|
}, z.core.$strip>>>;
|
|
51
52
|
}, z.core.$strip>;
|
|
53
|
+
export declare const codexToolOutputSchema: z.ZodObject<{
|
|
54
|
+
contextId: z.ZodString;
|
|
55
|
+
turnId: z.ZodString;
|
|
56
|
+
assistantText: z.ZodString;
|
|
57
|
+
reasoningText: z.ZodString;
|
|
58
|
+
diff: z.ZodString;
|
|
59
|
+
toolParts: z.ZodArray<z.ZodAny>;
|
|
60
|
+
}, z.core.$strip>;
|
|
52
61
|
export type CodexExecuteArgs<Context, Env extends CodexContextEnv = CodexContextEnv> = {
|
|
53
62
|
context: StoredContext<Context>;
|
|
54
63
|
env: Env;
|
|
@@ -61,7 +70,7 @@ export type CodexContextBuilderConfig<Context, Env extends CodexContextEnv = Cod
|
|
|
61
70
|
executeCodex: (args: CodexExecuteArgs<Context, Env>) => Promise<CodexToolOutput>;
|
|
62
71
|
narrative?: (context: StoredContext<Context>, env: Env) => Promise<string> | string;
|
|
63
72
|
system?: (context: StoredContext<Context>, env: Env) => Promise<string> | string;
|
|
64
|
-
actions?: (context: StoredContext<Context>, env: Env) => Promise<Record<string, ContextTool
|
|
73
|
+
actions?: (context: StoredContext<Context>, env: Env) => Promise<Record<string, ContextTool<Context, Env>>> | Record<string, ContextTool<Context, Env>>;
|
|
65
74
|
model?: ContextModelInit | ((context: StoredContext<Context>, env: Env) => ContextModelInit);
|
|
66
75
|
shouldContinue?: (args: ContextShouldContinueArgs<Context, Env>) => Promise<boolean> | boolean;
|
|
67
76
|
toolName?: string;
|
package/dist/codex.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { tool } from "ai";
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
import { createContext } from "./context.js";
|
|
2
|
+
import { createContext, defineAction } from "./context.js";
|
|
4
3
|
import { didToolExecute } from "./context.toolcalls.js";
|
|
5
4
|
export const DEFAULT_CODEX_TOOL_NAME = "codex";
|
|
6
5
|
export const DEFAULT_CODEX_MODEL = "openai/gpt-5.2";
|
|
@@ -17,6 +16,14 @@ export const codexToolInputSchema = z.object({
|
|
|
17
16
|
}))
|
|
18
17
|
.optional(),
|
|
19
18
|
});
|
|
19
|
+
export const codexToolOutputSchema = z.object({
|
|
20
|
+
contextId: z.string(),
|
|
21
|
+
turnId: z.string(),
|
|
22
|
+
assistantText: z.string(),
|
|
23
|
+
reasoningText: z.string(),
|
|
24
|
+
diff: z.string(),
|
|
25
|
+
toolParts: z.array(z.any()),
|
|
26
|
+
});
|
|
20
27
|
function toRecord(value) {
|
|
21
28
|
if (!value || typeof value !== "object")
|
|
22
29
|
return {};
|
|
@@ -70,10 +77,11 @@ export function createCodexContextBuilder(config) {
|
|
|
70
77
|
}
|
|
71
78
|
return {
|
|
72
79
|
...additional,
|
|
73
|
-
[toolName]:
|
|
80
|
+
[toolName]: defineAction({
|
|
74
81
|
description: toolDescription,
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
input: codexToolInputSchema,
|
|
83
|
+
output: codexToolOutputSchema,
|
|
84
|
+
execute: async ({ input }) => await config.executeCodex({
|
|
77
85
|
context: ctx,
|
|
78
86
|
env,
|
|
79
87
|
input,
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { DomainSchemaResult } from "@ekairos/domain";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import type { ContextEnvironment } from "./context.config.js";
|
|
4
|
+
import type { ContextToolExecuteContext } from "./context.engine.js";
|
|
5
|
+
import type { ContextRuntime } from "./context.runtime.js";
|
|
6
|
+
import { eventsDomain } from "./schema.js";
|
|
7
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
8
|
+
export type ContextActionSchema = z.ZodType;
|
|
9
|
+
export type ContextActionBase = {
|
|
10
|
+
type?: "function";
|
|
11
|
+
description?: string;
|
|
12
|
+
providerOptions?: unknown;
|
|
13
|
+
auto?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type ContextProviderDefinedAction = {
|
|
16
|
+
type: "provider-defined";
|
|
17
|
+
id: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
args?: Record<string, unknown>;
|
|
20
|
+
auto?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export type ContextActionExecuteParams<TInput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextToolExecuteContext<Context, Env, RequiredDomain, Runtime> & {
|
|
23
|
+
input: z.output<TInput>;
|
|
24
|
+
};
|
|
25
|
+
export type DefineContextActionExecute<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = (params: ContextActionExecuteParams<TInput, Context, Env, RequiredDomain, Runtime>) => MaybePromise<z.output<TOutput>>;
|
|
26
|
+
export type ContextActionExecute<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = DefineContextActionExecute<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
|
|
27
|
+
export type LegacyContextActionExecute<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = (input: z.output<TInput>, context: ContextToolExecuteContext<Context, Env, RequiredDomain, Runtime>) => MaybePromise<z.output<TOutput>>;
|
|
28
|
+
export type DefineContextActionDefinition<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextActionBase & {
|
|
29
|
+
input: TInput;
|
|
30
|
+
output: TOutput;
|
|
31
|
+
execute: DefineContextActionExecute<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
|
|
32
|
+
};
|
|
33
|
+
export type LegacyContextActionDefinition<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextActionBase & {
|
|
34
|
+
input: TInput;
|
|
35
|
+
output: TOutput;
|
|
36
|
+
execute: LegacyContextActionExecute<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
|
|
37
|
+
};
|
|
38
|
+
export type ContextActionDefinition<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = DefineContextActionDefinition<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
|
|
39
|
+
export type ContextAction<TInput extends ContextActionSchema = ContextActionSchema, TOutput extends ContextActionSchema = ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextActionBase & {
|
|
40
|
+
input: TInput;
|
|
41
|
+
output: TOutput;
|
|
42
|
+
inputSchema: TInput;
|
|
43
|
+
outputSchema: TOutput;
|
|
44
|
+
execute: LegacyContextActionExecute<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
|
|
45
|
+
};
|
|
46
|
+
export type AnyContextAction = ContextAction<ContextActionSchema, ContextActionSchema, any, any, any, any>;
|
|
47
|
+
export type ContextTool<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ContextAction<ContextActionSchema, ContextActionSchema, Context, Env, RequiredDomain, Runtime> | ContextProviderDefinedAction;
|
|
48
|
+
export type ContextActionInput<TAction> = TAction extends ContextAction<infer TInput, any, any, any> ? z.output<TInput> : never;
|
|
49
|
+
export type ContextActionOutput<TAction> = TAction extends ContextAction<any, infer TOutput, any, any> ? z.output<TOutput> : never;
|
|
50
|
+
export declare function defineAction<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>>(definition: DefineContextActionDefinition<TInput, TOutput, Context, Env, RequiredDomain, Runtime>): ContextAction<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated Use defineAction().
|
|
53
|
+
*/
|
|
54
|
+
export declare function action<TInput extends ContextActionSchema, TOutput extends ContextActionSchema, Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>>(definition: LegacyContextActionDefinition<TInput, TOutput, Context, Env, RequiredDomain, Runtime>): ContextAction<TInput, TOutput, Context, Env, RequiredDomain, Runtime>;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function createContextAction(definition, invoke) {
|
|
2
|
+
const execute = async (input, context) => {
|
|
3
|
+
const parsedInput = definition.input.parse(input);
|
|
4
|
+
const result = await invoke(parsedInput, context);
|
|
5
|
+
return definition.output.parse(result);
|
|
6
|
+
};
|
|
7
|
+
return {
|
|
8
|
+
...definition,
|
|
9
|
+
inputSchema: definition.input,
|
|
10
|
+
outputSchema: definition.output,
|
|
11
|
+
execute,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function defineAction(definition) {
|
|
15
|
+
return createContextAction(definition, async (input, context) => await definition.execute({
|
|
16
|
+
...context,
|
|
17
|
+
input,
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use defineAction().
|
|
22
|
+
*/
|
|
23
|
+
export function action(definition) {
|
|
24
|
+
return createContextAction(definition, async (input, context) => await definition.execute(input, context));
|
|
25
|
+
}
|
|
@@ -1,62 +1,72 @@
|
|
|
1
|
+
import type { DomainSchemaResult } from "@ekairos/domain";
|
|
1
2
|
import type { ContextEnvironment } from "./context.config.js";
|
|
2
3
|
import type { ContextSkillPackage } from "./context.skill.js";
|
|
3
|
-
import { ContextEngine, type ContextModelInit, type ContextOptions, type
|
|
4
|
+
import { ContextEngine, type ContextModelInit, type ContextOptions, type ShouldContinue, type ContextShouldContinueArgs, type ContextReactParams, type ContextDirectReactParams, type ContextDurableReactParams, type ContextReactResult, type ContextDirectRun, type ContextWorkflowRun } from "./context.engine.js";
|
|
5
|
+
import type { ContextTool } from "./context.action.js";
|
|
6
|
+
import type { ContextRuntime, ContextRuntimeHandleForDomain } from "./context.runtime.js";
|
|
4
7
|
import type { ContextReactor } from "./context.reactor.js";
|
|
5
8
|
import type { ContextItem, StoredContext } from "./context.store.js";
|
|
6
9
|
import { type ContextKey } from "./context.registry.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import { eventsDomain } from "./schema.js";
|
|
11
|
+
export interface ContextConfig<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> {
|
|
12
|
+
context: (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<Context> | Context;
|
|
13
|
+
expandEvents?: (events: ContextItem[], context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<ContextItem[]> | ContextItem[];
|
|
14
|
+
narrative: (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<string> | string;
|
|
15
|
+
skills?: (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<ContextSkillPackage[]> | ContextSkillPackage[];
|
|
16
|
+
actions: (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<Record<string, ContextTool<Context, Env, RequiredDomain>>> | Record<string, ContextTool<Context, Env, RequiredDomain>>;
|
|
13
17
|
/**
|
|
14
18
|
* @deprecated Use `actions()` instead.
|
|
15
19
|
*/
|
|
16
|
-
tools?: (context: StoredContext<Context>, env: Env) => Promise<Record<string, ContextTool
|
|
17
|
-
model?: ContextModelInit | ((context: StoredContext<Context>, env: Env) => ContextModelInit);
|
|
18
|
-
reactor?: ContextReactor<Context, Env>;
|
|
19
|
-
shouldContinue?: (args: ContextShouldContinueArgs<Context, Env>) => Promise<ShouldContinue> | ShouldContinue;
|
|
20
|
-
opts?: ContextOptions<Context, Env>;
|
|
20
|
+
tools?: (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<Record<string, ContextTool<Context, Env, RequiredDomain>>> | Record<string, ContextTool<Context, Env, RequiredDomain>>;
|
|
21
|
+
model?: ContextModelInit | ((context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => ContextModelInit);
|
|
22
|
+
reactor?: ContextReactor<Context, Env, RequiredDomain>;
|
|
23
|
+
shouldContinue?: (args: ContextShouldContinueArgs<Context, Env, RequiredDomain>) => Promise<ShouldContinue> | ShouldContinue;
|
|
24
|
+
opts?: ContextOptions<Context, Env, RequiredDomain>;
|
|
21
25
|
}
|
|
22
|
-
export type ContextInstance<Context, Env extends ContextEnvironment = ContextEnvironment> = ContextEngine<Context, Env> & {
|
|
23
|
-
readonly __config: ContextConfig<Context, Env>;
|
|
26
|
+
export type ContextInstance<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> = ContextEngine<Context, Env, RequiredDomain> & {
|
|
27
|
+
readonly __config: ContextConfig<Context, Env, RequiredDomain>;
|
|
24
28
|
readonly __contextKey?: ContextKey;
|
|
29
|
+
readonly __contextDomain?: RequiredDomain;
|
|
25
30
|
};
|
|
26
|
-
export declare function context<Context, Env extends ContextEnvironment = ContextEnvironment>(config: ContextConfig<Context, Env>): ContextInstance<Context, Env>;
|
|
27
|
-
type AnyContextInitializer<Env extends ContextEnvironment> = (context: StoredContext<any>, env: Env) => Promise<any> | any;
|
|
28
|
-
type InferContextFromInitializer<I extends AnyContextInitializer<any>> = Awaited<ReturnType<I>>;
|
|
29
|
-
type BuilderSystemPrompt<Context, Env extends ContextEnvironment> = (context: StoredContext<Context>, env: Env) => Promise<string> | string;
|
|
30
|
-
type BuilderSkills<Context, Env extends ContextEnvironment> = (context: StoredContext<Context>, env: Env) => Promise<ContextSkillPackage[]> | ContextSkillPackage[];
|
|
31
|
-
type BuilderTools<Context, Env extends ContextEnvironment> = (context: StoredContext<Context>, env: Env) => Promise<Record<string, ContextTool
|
|
32
|
-
type BuilderExpandEvents<Context, Env extends ContextEnvironment> = (events: ContextItem[], context: StoredContext<Context>, env: Env) => Promise<ContextItem[]> | ContextItem[];
|
|
33
|
-
type BuilderShouldContinue<Context, Env extends ContextEnvironment> = (args: ContextShouldContinueArgs<Context, Env>) => Promise<ShouldContinue> | ShouldContinue;
|
|
34
|
-
type BuilderModel<Context, Env extends ContextEnvironment> = ContextModelInit | ((context: StoredContext<Context>, env: Env) => ContextModelInit);
|
|
31
|
+
export declare function context<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain>(config: ContextConfig<Context, Env, RequiredDomain>): ContextInstance<Context, Env, RequiredDomain>;
|
|
32
|
+
type AnyContextInitializer<Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = (context: StoredContext<any>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<any> | any;
|
|
33
|
+
type InferContextFromInitializer<I extends AnyContextInitializer<any, any>> = Awaited<ReturnType<I>>;
|
|
34
|
+
type BuilderSystemPrompt<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<string> | string;
|
|
35
|
+
type BuilderSkills<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<ContextSkillPackage[]> | ContextSkillPackage[];
|
|
36
|
+
type BuilderTools<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = (context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<Record<string, ContextTool<Context, Env, RequiredDomain>>> | Record<string, ContextTool<Context, Env, RequiredDomain>>;
|
|
37
|
+
type BuilderExpandEvents<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = (events: ContextItem[], context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => Promise<ContextItem[]> | ContextItem[];
|
|
38
|
+
type BuilderShouldContinue<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = (args: ContextShouldContinueArgs<Context, Env, RequiredDomain>) => Promise<ShouldContinue> | ShouldContinue;
|
|
39
|
+
type BuilderModel<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = ContextModelInit | ((context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>) => ContextModelInit);
|
|
35
40
|
export type RegistrableContextBuilder = {
|
|
36
41
|
key: ContextKey;
|
|
37
42
|
register: () => void;
|
|
38
43
|
};
|
|
39
|
-
type FluentContextBuilder<Context, Env extends ContextEnvironment> = {
|
|
44
|
+
type FluentContextBuilder<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = {
|
|
40
45
|
key: ContextKey;
|
|
41
|
-
expandEvents(fn: BuilderExpandEvents<Context, Env>): FluentContextBuilder<Context, Env>;
|
|
42
|
-
narrative(fn: BuilderSystemPrompt<Context, Env>): FluentContextBuilder<Context, Env>;
|
|
43
|
-
system(fn: BuilderSystemPrompt<Context, Env>): FluentContextBuilder<Context, Env>;
|
|
44
|
-
skills(fn: BuilderSkills<Context, Env>): FluentContextBuilder<Context, Env>;
|
|
45
|
-
actions(fn: BuilderTools<Context, Env>): FluentContextBuilder<Context, Env>;
|
|
46
|
-
tools(fn: BuilderTools<Context, Env>): FluentContextBuilder<Context, Env>;
|
|
47
|
-
model(model: BuilderModel<Context, Env>): FluentContextBuilder<Context, Env>;
|
|
48
|
-
reactor(reactor: ContextReactor<Context, Env>): FluentContextBuilder<Context, Env>;
|
|
49
|
-
shouldContinue(fn: BuilderShouldContinue<Context, Env>): FluentContextBuilder<Context, Env>;
|
|
50
|
-
opts(opts: ContextOptions<Context, Env>): FluentContextBuilder<Context, Env>;
|
|
51
|
-
react(triggerEvent: ContextItem, params:
|
|
52
|
-
|
|
46
|
+
expandEvents(fn: BuilderExpandEvents<Context, Env, RequiredDomain>): FluentContextBuilder<Context, Env, RequiredDomain>;
|
|
47
|
+
narrative(fn: BuilderSystemPrompt<Context, Env, RequiredDomain>): FluentContextBuilder<Context, Env, RequiredDomain>;
|
|
48
|
+
system(fn: BuilderSystemPrompt<Context, Env, RequiredDomain>): FluentContextBuilder<Context, Env, RequiredDomain>;
|
|
49
|
+
skills(fn: BuilderSkills<Context, Env, RequiredDomain>): FluentContextBuilder<Context, Env, RequiredDomain>;
|
|
50
|
+
actions(fn: BuilderTools<Context, Env, RequiredDomain>): FluentContextBuilder<Context, Env, RequiredDomain>;
|
|
51
|
+
tools(fn: BuilderTools<Context, Env, RequiredDomain>): FluentContextBuilder<Context, Env, RequiredDomain>;
|
|
52
|
+
model(model: BuilderModel<Context, Env, RequiredDomain>): FluentContextBuilder<Context, Env, RequiredDomain>;
|
|
53
|
+
reactor(reactor: ContextReactor<Context, Env, RequiredDomain>): FluentContextBuilder<Context, Env, RequiredDomain>;
|
|
54
|
+
shouldContinue(fn: BuilderShouldContinue<Context, Env, RequiredDomain>): FluentContextBuilder<Context, Env, RequiredDomain>;
|
|
55
|
+
opts(opts: ContextOptions<Context, Env, RequiredDomain>): FluentContextBuilder<Context, Env, RequiredDomain>;
|
|
56
|
+
react<Runtime extends ContextRuntime<Env>>(triggerEvent: ContextItem, params: ContextDurableReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context, ContextWorkflowRun<Context>>>;
|
|
57
|
+
react<Runtime extends ContextRuntime<Env>>(triggerEvent: ContextItem, params: ContextDirectReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context, ContextDirectRun<Context>>>;
|
|
58
|
+
react<Runtime extends ContextRuntime<Env>>(triggerEvent: ContextItem, params: ContextReactParams<Env, RequiredDomain, Runtime>): ReturnType<ContextEngine<Context, Env, RequiredDomain>["react"]>;
|
|
59
|
+
stream<Runtime extends ContextRuntime<Env>>(triggerEvent: ContextItem, params: ContextDurableReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context, ContextWorkflowRun<Context>>>;
|
|
60
|
+
stream<Runtime extends ContextRuntime<Env>>(triggerEvent: ContextItem, params: ContextDirectReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context, ContextDirectRun<Context>>>;
|
|
61
|
+
stream<Runtime extends ContextRuntime<Env>>(triggerEvent: ContextItem, params: ContextReactParams<Env, RequiredDomain, Runtime>): ReturnType<ContextEngine<Context, Env, RequiredDomain>["react"]>;
|
|
53
62
|
register(): void;
|
|
54
|
-
config(): ContextConfig<Context, Env>;
|
|
55
|
-
build(): ContextInstance<Context, Env>;
|
|
63
|
+
config(): ContextConfig<Context, Env, RequiredDomain>;
|
|
64
|
+
build(): ContextInstance<Context, Env, RequiredDomain>;
|
|
56
65
|
};
|
|
57
|
-
type CreateContextEntry<Env extends ContextEnvironment> = {
|
|
58
|
-
context<Initializer extends AnyContextInitializer<Env>>(initializer: Initializer): FluentContextBuilder<InferContextFromInitializer<Initializer>, Env>;
|
|
59
|
-
initialize<Initializer extends AnyContextInitializer<Env>>(initializer: Initializer): FluentContextBuilder<InferContextFromInitializer<Initializer>, Env>;
|
|
66
|
+
type CreateContextEntry<Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult> = {
|
|
67
|
+
context<Initializer extends AnyContextInitializer<Env, RequiredDomain>>(initializer: Initializer): FluentContextBuilder<InferContextFromInitializer<Initializer>, Env, RequiredDomain>;
|
|
68
|
+
initialize<Initializer extends AnyContextInitializer<Env, RequiredDomain>>(initializer: Initializer): FluentContextBuilder<InferContextFromInitializer<Initializer>, Env, RequiredDomain>;
|
|
60
69
|
};
|
|
61
|
-
export declare function createContext<Env extends ContextEnvironment = ContextEnvironment>(key: ContextKey): CreateContextEntry<Env>;
|
|
70
|
+
export declare function createContext<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = DomainSchemaResult>(domain: RequiredDomain, key: ContextKey): CreateContextEntry<Env, RequiredDomain>;
|
|
71
|
+
export declare function createContext<Env extends ContextEnvironment = ContextEnvironment>(key: ContextKey): CreateContextEntry<Env, typeof eventsDomain>;
|
|
62
72
|
export {};
|
package/dist/context.builder.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ContextEngine, } from "./context.engine.js";
|
|
2
2
|
import { registerContext } from "./context.registry.js";
|
|
3
|
+
import { eventsDomain } from "./schema.js";
|
|
3
4
|
function isDynamicModelSelector(model) {
|
|
4
5
|
return typeof model === "function" && model.length >= 1;
|
|
5
6
|
}
|
|
@@ -9,35 +10,35 @@ export function context(config) {
|
|
|
9
10
|
super(config.opts, config.reactor);
|
|
10
11
|
this.__config = config;
|
|
11
12
|
}
|
|
12
|
-
async initialize(contextValue, env) {
|
|
13
|
-
return config.context(contextValue, env);
|
|
13
|
+
async initialize(contextValue, env, runtime) {
|
|
14
|
+
return config.context(contextValue, env, runtime);
|
|
14
15
|
}
|
|
15
|
-
async expandEvents(events, contextValue, env) {
|
|
16
|
+
async expandEvents(events, contextValue, env, runtime) {
|
|
16
17
|
if (config.expandEvents)
|
|
17
|
-
return config.expandEvents(events, contextValue, env);
|
|
18
|
-
return super.expandEvents(events, contextValue, env);
|
|
18
|
+
return config.expandEvents(events, contextValue, env, runtime);
|
|
19
|
+
return super.expandEvents(events, contextValue, env, runtime);
|
|
19
20
|
}
|
|
20
|
-
async buildSystemPrompt(contextValue, env) {
|
|
21
|
+
async buildSystemPrompt(contextValue, env, runtime) {
|
|
21
22
|
if (config.narrative)
|
|
22
|
-
return config.narrative(contextValue, env);
|
|
23
|
+
return config.narrative(contextValue, env, runtime);
|
|
23
24
|
throw new Error("Context config is missing narrative()");
|
|
24
25
|
}
|
|
25
|
-
async buildSkills(contextValue, env) {
|
|
26
|
+
async buildSkills(contextValue, env, runtime) {
|
|
26
27
|
if (config.skills)
|
|
27
|
-
return config.skills(contextValue, env);
|
|
28
|
+
return config.skills(contextValue, env, runtime);
|
|
28
29
|
return [];
|
|
29
30
|
}
|
|
30
|
-
async buildTools(contextValue, env) {
|
|
31
|
+
async buildTools(contextValue, env, runtime) {
|
|
31
32
|
if (config.actions)
|
|
32
|
-
return config.actions(contextValue, env);
|
|
33
|
+
return config.actions(contextValue, env, runtime);
|
|
33
34
|
if (config.tools)
|
|
34
|
-
return config.tools(contextValue, env);
|
|
35
|
+
return config.tools(contextValue, env, runtime);
|
|
35
36
|
throw new Error("Context config is missing actions()");
|
|
36
37
|
}
|
|
37
|
-
getModel(contextValue, env) {
|
|
38
|
+
getModel(contextValue, env, runtime) {
|
|
38
39
|
if (isDynamicModelSelector(config.model))
|
|
39
|
-
return config.model(contextValue, env);
|
|
40
|
-
return config.model ?? super.getModel(contextValue, env);
|
|
40
|
+
return config.model(contextValue, env, runtime);
|
|
41
|
+
return config.model ?? super.getModel(contextValue, env, runtime);
|
|
41
42
|
}
|
|
42
43
|
async shouldContinue(args) {
|
|
43
44
|
if (config.shouldContinue)
|
|
@@ -59,9 +60,14 @@ function assertConfigComplete(config) {
|
|
|
59
60
|
throw new Error("createContext: you must define actions() before building the Context.");
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
|
-
export function createContext(
|
|
63
|
+
export function createContext(keyOrDomain, maybeKey) {
|
|
64
|
+
const requiredDomain = typeof keyOrDomain === "string" ? eventsDomain : keyOrDomain;
|
|
65
|
+
const key = typeof keyOrDomain === "string" ? keyOrDomain : maybeKey;
|
|
66
|
+
if (!key) {
|
|
67
|
+
throw new Error("createContext: key is required.");
|
|
68
|
+
}
|
|
63
69
|
const initializeBuilder = (initializer) => {
|
|
64
|
-
const typedInitializer = (ctx, env) => initializer(ctx, env);
|
|
70
|
+
const typedInitializer = (ctx, env, runtime) => initializer(ctx, env, runtime);
|
|
65
71
|
const fluentState = {
|
|
66
72
|
context: typedInitializer,
|
|
67
73
|
};
|
|
@@ -70,7 +76,10 @@ export function createContext(key) {
|
|
|
70
76
|
assertConfigComplete(fluentState);
|
|
71
77
|
if (!cached) {
|
|
72
78
|
const config = fluentState;
|
|
73
|
-
cached = Object.assign(context(config), {
|
|
79
|
+
cached = Object.assign(context(config), {
|
|
80
|
+
__contextKey: key,
|
|
81
|
+
__contextDomain: requiredDomain,
|
|
82
|
+
});
|
|
74
83
|
registerContext(key, () => cached);
|
|
75
84
|
}
|
|
76
85
|
return cached;
|
|
@@ -117,12 +126,8 @@ export function createContext(key) {
|
|
|
117
126
|
fluentState.opts = options;
|
|
118
127
|
return builder;
|
|
119
128
|
},
|
|
120
|
-
react(triggerEvent, params)
|
|
121
|
-
|
|
122
|
-
},
|
|
123
|
-
stream(triggerEvent, params) {
|
|
124
|
-
return builder.react(triggerEvent, params);
|
|
125
|
-
},
|
|
129
|
+
react: ((triggerEvent, params) => getOrBuild().react(triggerEvent, params)),
|
|
130
|
+
stream: ((triggerEvent, params) => builder.react(triggerEvent, params)),
|
|
126
131
|
register() {
|
|
127
132
|
getOrBuild();
|
|
128
133
|
},
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { ContextEngine, type ContextOptions, type ContextStreamOptions, type ShouldContinue, type ContextShouldContinueArgs, type ContextReactParams, type ContextReactResult, type ContextWorkflowRun, type ContextDurableWorkflowPayload, type ContextDurableWorkflowFunction, type ContextModelInit, type
|
|
1
|
+
export { ContextEngine, type ContextOptions, type ContextStreamOptions, type ShouldContinue, type ContextShouldContinueArgs, type ContextReactParams, type ContextDirectReactParams, type ContextDurableReactParams, type ContextReactResult, type ContextReactBase, type ContextReactFinalResult, type ContextDirectRun, type ContextReactRun, type ContextWorkflowRun, type ContextDurableWorkflowPayload, type ContextDurableWorkflowFunction, type ContextModelInit, type ContextToolExecuteContext, runContextReactionDirect, } from "./context.engine.js";
|
|
2
2
|
export { context, createContext, type ContextConfig, type ContextInstance, type RegistrableContextBuilder, } from "./context.builder.js";
|
|
3
|
+
export { defineAction, action, type ContextAction, type ContextActionBase, type ContextActionExecuteParams, type AnyContextAction, type ContextActionDefinition, type ContextActionExecute, type DefineContextActionDefinition, type DefineContextActionExecute, type LegacyContextActionDefinition, type LegacyContextActionExecute, type ContextActionInput, type ContextActionOutput, type ContextProviderDefinedAction, type ContextActionSchema, type ContextTool, } from "./context.action.js";
|
|
3
4
|
export { createAiSdkReactor, createScriptedReactor, type CreateAiSdkReactorOptions, type CreateScriptedReactorOptions, type ScriptedReactorStep, type ContextReactor, type ContextReactorParams, type ContextReactionResult, type ContextActionRequest, type ContextReactionLLM, } from "./context.reactor.js";
|
|
4
5
|
export type { ContextSkillPackage, ContextSkillPackageFile, } from "./context.skill.js";
|
package/dist/context.engine.d.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import type { ModelMessage,
|
|
1
|
+
import type { ModelMessage, UIMessageChunk } from "ai";
|
|
2
|
+
import type { DomainSchemaResult } from "@ekairos/domain";
|
|
2
3
|
import type { ContextEnvironment } from "./context.config.js";
|
|
3
|
-
import type {
|
|
4
|
+
import type { ContextTool } from "./context.action.js";
|
|
5
|
+
import type { ContextRuntime, ContextRuntimeHandleForDomain, ContextRuntimeForDomain } from "./context.runtime.js";
|
|
6
|
+
import { eventsDomain } from "./schema.js";
|
|
4
7
|
import type { ContextExecution, ContextItem, ContextIdentifier, StoredContext } from "./context.store.js";
|
|
5
8
|
import type { ContextSkillPackage } from "./context.skill.js";
|
|
6
9
|
import { type ContextReactor } from "./context.reactor.js";
|
|
7
10
|
import { getClientResumeHookUrl, toolApprovalHookToken, toolApprovalWebhookToken } from "./context.hooks.js";
|
|
8
|
-
export interface ContextOptions<Context = any, Env extends ContextEnvironment = ContextEnvironment> {
|
|
11
|
+
export interface ContextOptions<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> {
|
|
9
12
|
onContextCreated?: (args: {
|
|
10
13
|
env: Env;
|
|
14
|
+
runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>;
|
|
11
15
|
context: StoredContext<Context>;
|
|
12
16
|
}) => void | Promise<void>;
|
|
13
17
|
onContextUpdated?: (args: {
|
|
14
18
|
env: Env;
|
|
19
|
+
runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>;
|
|
15
20
|
context: StoredContext<Context>;
|
|
16
21
|
}) => void | Promise<void>;
|
|
17
22
|
onEventCreated?: (event: ContextItem) => void | Promise<void>;
|
|
@@ -23,7 +28,7 @@ type ContextBenchmarkRecorder = {
|
|
|
23
28
|
add?(name: string, value: number): void;
|
|
24
29
|
getCurrentStage?(): string | undefined;
|
|
25
30
|
};
|
|
26
|
-
export declare function runContextReactionDirect<Context, Env extends ContextEnvironment = ContextEnvironment>(context: ContextEngine<Context, Env>, triggerEvent: ContextItem, params: ContextReactParams<Env>): Promise<ContextReactResult<Context>>;
|
|
31
|
+
export declare function runContextReactionDirect<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>>(context: ContextEngine<Context, Env, RequiredDomain>, triggerEvent: ContextItem, params: ContextReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context>>;
|
|
27
32
|
export interface ContextStreamOptions {
|
|
28
33
|
/**
|
|
29
34
|
* Maximum loop iterations (LLM call → tool execution → repeat).
|
|
@@ -68,12 +73,8 @@ export interface ContextStreamOptions {
|
|
|
68
73
|
* be a `"use-step"` function (so it can be serialized by reference).
|
|
69
74
|
*/
|
|
70
75
|
export type ContextModelInit = string | (() => Promise<any>);
|
|
71
|
-
export type ContextReactParams<Env extends ContextEnvironment = ContextEnvironment> = {
|
|
72
|
-
runtime
|
|
73
|
-
/**
|
|
74
|
-
* Backward-compatible runtime selector. New callers should pass `runtime`.
|
|
75
|
-
*/
|
|
76
|
-
env?: Env;
|
|
76
|
+
export type ContextReactParams<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = {
|
|
77
|
+
runtime: ContextRuntimeForDomain<Runtime, RequiredDomain>;
|
|
77
78
|
/**
|
|
78
79
|
* Context selector (exclusive: `{ id }` OR `{ key }`).
|
|
79
80
|
* - `{ id }` resolves a concrete context id.
|
|
@@ -95,30 +96,40 @@ export type ContextReactParams<Env extends ContextEnvironment = ContextEnvironme
|
|
|
95
96
|
};
|
|
96
97
|
__benchmark?: ContextBenchmarkRecorder;
|
|
97
98
|
};
|
|
98
|
-
export type
|
|
99
|
+
export type ContextDurableReactParams<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = Omit<ContextReactParams<Env, RequiredDomain, Runtime>, "durable"> & {
|
|
100
|
+
durable?: true | undefined;
|
|
101
|
+
};
|
|
102
|
+
export type ContextDirectReactParams<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = Omit<ContextReactParams<Env, RequiredDomain, Runtime>, "durable"> & {
|
|
103
|
+
durable: false;
|
|
104
|
+
};
|
|
105
|
+
export type ContextReactBase<Context = any> = {
|
|
99
106
|
context: StoredContext<Context>;
|
|
100
107
|
trigger: ContextItem;
|
|
101
108
|
reaction: ContextItem;
|
|
102
109
|
execution: ContextExecution;
|
|
103
|
-
run?: ContextWorkflowRun<Context>;
|
|
104
110
|
};
|
|
111
|
+
export type ContextReactFinalResult<Context = any> = ContextReactBase<Context>;
|
|
112
|
+
export type ContextDirectRun<Context = any> = Promise<ContextReactFinalResult<Context>>;
|
|
105
113
|
export type ContextWorkflowRun<Context = any> = {
|
|
106
114
|
runId: string;
|
|
107
115
|
status: Promise<"pending" | "running" | "completed" | "failed" | "cancelled">;
|
|
108
|
-
returnValue: Promise<
|
|
116
|
+
returnValue: Promise<ContextReactFinalResult<Context>>;
|
|
109
117
|
};
|
|
110
|
-
export type
|
|
118
|
+
export type ContextReactRun<Context = any> = ContextWorkflowRun<Context> | ContextDirectRun<Context>;
|
|
119
|
+
export type ContextReactResult<Context = any, Run extends ContextReactRun<Context> = ContextReactRun<Context>> = ContextReactBase<Context> & {
|
|
120
|
+
run?: Run;
|
|
121
|
+
};
|
|
122
|
+
export type ContextDurableWorkflowPayload<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = {
|
|
111
123
|
contextKey: string;
|
|
112
|
-
runtime:
|
|
124
|
+
runtime: ContextRuntimeForDomain<Runtime, RequiredDomain>;
|
|
113
125
|
context?: ContextIdentifier | null;
|
|
114
126
|
triggerEvent: ContextItem;
|
|
115
127
|
options?: Omit<ContextStreamOptions, "writable">;
|
|
116
|
-
bootstrap: NonNullable<ContextReactParams<Env>["__bootstrap"]>;
|
|
128
|
+
bootstrap: NonNullable<ContextReactParams<Env, RequiredDomain, Runtime>["__bootstrap"]>;
|
|
117
129
|
};
|
|
118
|
-
export type ContextDurableWorkflowFunction<Context = any, Env extends ContextEnvironment = ContextEnvironment> = (payload: ContextDurableWorkflowPayload<Env>) => Promise<
|
|
119
|
-
export type ContextToolExecuteContext<Context = any, Env extends ContextEnvironment = ContextEnvironment> = {
|
|
120
|
-
runtime:
|
|
121
|
-
env: Env;
|
|
130
|
+
export type ContextDurableWorkflowFunction<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = (payload: ContextDurableWorkflowPayload<Env, RequiredDomain, Runtime>) => Promise<ContextReactFinalResult<Context>>;
|
|
131
|
+
export type ContextToolExecuteContext<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = {
|
|
132
|
+
runtime: ContextRuntimeForDomain<Runtime, RequiredDomain>;
|
|
122
133
|
context: StoredContext<Context>;
|
|
123
134
|
contextIdentifier: ContextIdentifier;
|
|
124
135
|
toolCallId: string;
|
|
@@ -129,6 +140,7 @@ export type ContextToolExecuteContext<Context = any, Env extends ContextEnvironm
|
|
|
129
140
|
contextId: string;
|
|
130
141
|
stepId: string;
|
|
131
142
|
iteration: number;
|
|
143
|
+
contextStepStream?: WritableStream<string>;
|
|
132
144
|
};
|
|
133
145
|
export { toolApprovalHookToken, toolApprovalWebhookToken, getClientResumeHookUrl };
|
|
134
146
|
/**
|
|
@@ -139,13 +151,6 @@ export { toolApprovalHookToken, toolApprovalWebhookToken, getClientResumeHookUrl
|
|
|
139
151
|
*
|
|
140
152
|
* Default behavior when omitted: `auto === true`.
|
|
141
153
|
*/
|
|
142
|
-
export type ContextTool = Tool & {
|
|
143
|
-
/**
|
|
144
|
-
* If `false`, this action is not intended for automatic execution by the engine.
|
|
145
|
-
* (Validation/enforcement can be added by callers; default is `true`.)
|
|
146
|
-
*/
|
|
147
|
-
auto?: boolean;
|
|
148
|
-
};
|
|
149
154
|
/**
|
|
150
155
|
* ## Context loop continuation signal
|
|
151
156
|
*
|
|
@@ -157,8 +162,9 @@ export type ContextTool = Tool & {
|
|
|
157
162
|
* (No imports required in callers.)
|
|
158
163
|
*/
|
|
159
164
|
export type ShouldContinue = boolean;
|
|
160
|
-
export type ContextShouldContinueArgs<Context = any, Env extends ContextEnvironment = ContextEnvironment> = {
|
|
165
|
+
export type ContextShouldContinueArgs<Context = any, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> = {
|
|
161
166
|
env: Env;
|
|
167
|
+
runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>;
|
|
162
168
|
context: StoredContext<Context>;
|
|
163
169
|
/**
|
|
164
170
|
* The persisted reaction event **so far** for the current streaming run.
|
|
@@ -187,14 +193,14 @@ export type ContextShouldContinueArgs<Context = any, Env extends ContextEnvironm
|
|
|
187
193
|
errorText?: string;
|
|
188
194
|
}>;
|
|
189
195
|
};
|
|
190
|
-
export declare abstract class ContextEngine<Context, Env extends ContextEnvironment = ContextEnvironment> {
|
|
191
|
-
protected readonly opts: ContextOptions<Context, Env>;
|
|
196
|
+
export declare abstract class ContextEngine<Context, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainSchemaResult = typeof eventsDomain> {
|
|
197
|
+
protected readonly opts: ContextOptions<Context, Env, RequiredDomain>;
|
|
192
198
|
private readonly reactor;
|
|
193
|
-
constructor(opts?: ContextOptions<Context, Env>, reactor?: ContextReactor<Context, Env>);
|
|
194
|
-
protected abstract initialize(context: StoredContext<Context>, env: Env): Promise<Context> | Context;
|
|
195
|
-
protected abstract buildSystemPrompt(context: StoredContext<Context>, env: Env): Promise<string> | string;
|
|
196
|
-
protected abstract buildTools(context: StoredContext<Context>, env: Env): Promise<Record<string, ContextTool
|
|
197
|
-
protected buildSkills(_context: StoredContext<Context>, _env: Env): Promise<ContextSkillPackage[]>;
|
|
199
|
+
constructor(opts?: ContextOptions<Context, Env, RequiredDomain>, reactor?: ContextReactor<Context, Env, RequiredDomain>);
|
|
200
|
+
protected abstract initialize(context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>): Promise<Context> | Context;
|
|
201
|
+
protected abstract buildSystemPrompt(context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>): Promise<string> | string;
|
|
202
|
+
protected abstract buildTools(context: StoredContext<Context>, env: Env, runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>): Promise<Record<string, ContextTool<Context, Env, RequiredDomain>>> | Record<string, ContextTool<Context, Env, RequiredDomain>>;
|
|
203
|
+
protected buildSkills(_context: StoredContext<Context>, _env: Env, _runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>): Promise<ContextSkillPackage[]>;
|
|
198
204
|
/**
|
|
199
205
|
* First-class event expansion stage (runs on every iteration of the durable loop).
|
|
200
206
|
*
|
|
@@ -212,9 +218,9 @@ export declare abstract class ContextEngine<Context, Env extends ContextEnvironm
|
|
|
212
218
|
* the builder) so results are durable and replay-safe.
|
|
213
219
|
* - If it’s pure/deterministic, it can run in workflow context.
|
|
214
220
|
*/
|
|
215
|
-
protected expandEvents(events: ContextItem[], _context: StoredContext<Context>, _env: Env): Promise<ContextItem[]>;
|
|
216
|
-
protected getModel(_context: StoredContext<Context>, _env: Env): ContextModelInit;
|
|
217
|
-
protected getReactor(_context: StoredContext<Context>, _env: Env): ContextReactor<Context, Env>;
|
|
221
|
+
protected expandEvents(events: ContextItem[], _context: StoredContext<Context>, _env: Env, _runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>): Promise<ContextItem[]>;
|
|
222
|
+
protected getModel(_context: StoredContext<Context>, _env: Env, _runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>): ContextModelInit;
|
|
223
|
+
protected getReactor(_context: StoredContext<Context>, _env: Env, _runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>): ContextReactor<Context, Env, RequiredDomain>;
|
|
218
224
|
/**
|
|
219
225
|
* Context stop/continue hook.
|
|
220
226
|
*
|
|
@@ -223,19 +229,16 @@ export declare abstract class ContextEngine<Context, Env extends ContextEnvironm
|
|
|
223
229
|
*
|
|
224
230
|
* Default: `true` (continue).
|
|
225
231
|
*/
|
|
226
|
-
protected shouldContinue(_args: ContextShouldContinueArgs<Context, Env>): Promise<ShouldContinue>;
|
|
227
|
-
react(triggerEvent: ContextItem, params:
|
|
232
|
+
protected shouldContinue(_args: ContextShouldContinueArgs<Context, Env, RequiredDomain>): Promise<ShouldContinue>;
|
|
233
|
+
react<Runtime extends ContextRuntime<Env>>(triggerEvent: ContextItem, params: ContextDurableReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context, ContextWorkflowRun<Context>>>;
|
|
234
|
+
react<Runtime extends ContextRuntime<Env>>(triggerEvent: ContextItem, params: ContextDirectReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context, ContextDirectRun<Context>>>;
|
|
235
|
+
react<Runtime extends ContextRuntime<Env>>(triggerEvent: ContextItem, params: ContextReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context>>;
|
|
228
236
|
private static prepareExecutionShell;
|
|
229
237
|
private static startDurable;
|
|
230
|
-
static runDirect<Context, Env extends ContextEnvironment
|
|
231
|
-
context: StoredContext<Context>;
|
|
232
|
-
trigger: ContextItem;
|
|
233
|
-
reaction: ContextItem;
|
|
234
|
-
execution: ContextExecution;
|
|
235
|
-
}>;
|
|
238
|
+
static runDirect<Context, Env extends ContextEnvironment, RequiredDomain extends DomainSchemaResult, Runtime extends ContextRuntime<Env>>(story: ContextEngine<Context, Env, RequiredDomain>, triggerEvent: ContextItem, params: ContextReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context, ContextDirectRun<Context>>>;
|
|
236
239
|
/**
|
|
237
240
|
* @deprecated Use `react()` instead. Kept for backwards compatibility.
|
|
238
241
|
*/
|
|
239
|
-
stream(triggerEvent: ContextItem, params: ContextReactParams<Env>): Promise<ContextReactResult<Context
|
|
242
|
+
stream<Runtime extends ContextRuntime<Env>>(triggerEvent: ContextItem, params: ContextReactParams<Env, RequiredDomain, Runtime>): Promise<ContextReactResult<Context, ContextWorkflowRun<Context>>>;
|
|
240
243
|
private callOnEnd;
|
|
241
244
|
}
|