@ekairos/events 1.22.34-beta.development.0 → 1.22.36-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 +56 -83
- package/dist/context.d.ts +1 -1
- package/dist/context.engine.d.ts +28 -3
- package/dist/context.engine.js +100 -46
- package/dist/context.runtime.d.ts +11 -0
- package/dist/context.runtime.js +21 -0
- package/dist/context.store.d.ts +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/reactors/ai-sdk.reactor.d.ts +4 -0
- package/dist/reactors/ai-sdk.reactor.js +5 -1
- package/dist/reactors/ai-sdk.step.d.ts +3 -2
- package/dist/reactors/ai-sdk.step.js +8 -7
- package/dist/reactors/types.d.ts +8 -2
- package/dist/runtime.step.js +1 -1
- package/dist/schema.js +1 -0
- package/dist/steps/do-context-stream-step.d.ts +2 -2
- package/dist/steps/do-context-stream-step.js +2 -4
- package/dist/steps/store.steps.d.ts +62 -22
- package/dist/steps/store.steps.js +76 -78
- package/dist/steps/stream.steps.d.ts +4 -3
- package/dist/steps/stream.steps.js +14 -9
- package/dist/steps/trace.steps.d.ts +2 -0
- package/dist/steps/trace.steps.js +5 -2
- package/dist/stores/instant.store.d.ts +4 -0
- package/dist/stores/instant.store.js +19 -0
- package/dist/tools-to-model-tools.d.ts +36 -2
- package/dist/tools-to-model-tools.js +39 -1
- package/package.json +7 -4
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ContextEnvironment } from "../context.config.js";
|
|
2
|
+
import type { ContextRuntime } from "../context.runtime.js";
|
|
2
3
|
import type { ContextModelInit } from "../context.engine.js";
|
|
3
4
|
import type { ContextIdentifier, StoredContext, ContextItem } from "../context.store.js";
|
|
4
5
|
import type { ContextReactor } from "./types.js";
|
|
5
6
|
export type CreateAiSdkReactorOptions<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, Config = unknown> = {
|
|
6
7
|
resolveConfig?: (params: {
|
|
8
|
+
runtime: ContextRuntime<Env>;
|
|
7
9
|
env: Env;
|
|
8
10
|
context: StoredContext<Context>;
|
|
9
11
|
contextIdentifier: ContextIdentifier;
|
|
@@ -16,6 +18,7 @@ export type CreateAiSdkReactorOptions<Context = unknown, Env extends ContextEnvi
|
|
|
16
18
|
iteration: number;
|
|
17
19
|
}) => Promise<Config> | Config;
|
|
18
20
|
selectModel?: (params: {
|
|
21
|
+
runtime: ContextRuntime<Env>;
|
|
19
22
|
env: Env;
|
|
20
23
|
context: StoredContext<Context>;
|
|
21
24
|
triggerEvent: ContextItem;
|
|
@@ -23,6 +26,7 @@ export type CreateAiSdkReactorOptions<Context = unknown, Env extends ContextEnvi
|
|
|
23
26
|
config: Config;
|
|
24
27
|
}) => Promise<ContextModelInit> | ContextModelInit;
|
|
25
28
|
selectMaxModelSteps?: (params: {
|
|
29
|
+
runtime: ContextRuntime<Env>;
|
|
26
30
|
env: Env;
|
|
27
31
|
context: StoredContext<Context>;
|
|
28
32
|
triggerEvent: ContextItem;
|
|
@@ -4,6 +4,7 @@ export function createAiSdkReactor(options) {
|
|
|
4
4
|
let config;
|
|
5
5
|
if (options?.resolveConfig) {
|
|
6
6
|
config = await options.resolveConfig({
|
|
7
|
+
runtime: params.runtime,
|
|
7
8
|
env: params.env,
|
|
8
9
|
context: params.context,
|
|
9
10
|
contextIdentifier: params.contextIdentifier,
|
|
@@ -18,6 +19,7 @@ export function createAiSdkReactor(options) {
|
|
|
18
19
|
}
|
|
19
20
|
const model = options?.selectModel && config !== undefined
|
|
20
21
|
? await options.selectModel({
|
|
22
|
+
runtime: params.runtime,
|
|
21
23
|
env: params.env,
|
|
22
24
|
context: params.context,
|
|
23
25
|
triggerEvent: params.triggerEvent,
|
|
@@ -27,6 +29,7 @@ export function createAiSdkReactor(options) {
|
|
|
27
29
|
: params.model;
|
|
28
30
|
const maxSteps = options?.selectMaxModelSteps && config !== undefined
|
|
29
31
|
? await options.selectMaxModelSteps({
|
|
32
|
+
runtime: params.runtime,
|
|
30
33
|
env: params.env,
|
|
31
34
|
context: params.context,
|
|
32
35
|
triggerEvent: params.triggerEvent,
|
|
@@ -35,11 +38,12 @@ export function createAiSdkReactor(options) {
|
|
|
35
38
|
})
|
|
36
39
|
: params.maxModelSteps;
|
|
37
40
|
const result = await executeAiSdkReaction({
|
|
41
|
+
runtime: params.runtime,
|
|
38
42
|
env: params.env,
|
|
39
43
|
contextIdentifier: params.contextIdentifier,
|
|
40
44
|
model,
|
|
41
45
|
system: params.systemPrompt,
|
|
42
|
-
tools: params.
|
|
46
|
+
tools: params.actionSpecs,
|
|
43
47
|
eventId: params.eventId,
|
|
44
48
|
iteration: params.iteration,
|
|
45
49
|
maxSteps,
|
|
@@ -2,7 +2,7 @@ import type { ModelMessage, UIMessageChunk } from "ai";
|
|
|
2
2
|
import type { ContextEnvironment } from "../context.config.js";
|
|
3
3
|
import type { ContextModelInit } from "../context.engine.js";
|
|
4
4
|
import type { ContextItem, ContextIdentifier } from "../context.store.js";
|
|
5
|
-
import type
|
|
5
|
+
import { type SerializableActionSpec } from "../tools-to-model-tools.js";
|
|
6
6
|
/**
|
|
7
7
|
* AI SDK-backed reaction execution inside a single workflow step.
|
|
8
8
|
*
|
|
@@ -14,11 +14,12 @@ import type { SerializableToolForModel } from "../tools-to-model-tools.js";
|
|
|
14
14
|
* - emit UI chunks and persist step stream chunks
|
|
15
15
|
*/
|
|
16
16
|
export declare function executeAiSdkReaction(params: {
|
|
17
|
+
runtime: import("../context.runtime.js").ContextRuntime<ContextEnvironment>;
|
|
17
18
|
env: ContextEnvironment;
|
|
18
19
|
contextIdentifier: ContextIdentifier;
|
|
19
20
|
model: ContextModelInit;
|
|
20
21
|
system: string;
|
|
21
|
-
tools: Record<string,
|
|
22
|
+
tools: Record<string, SerializableActionSpec>;
|
|
22
23
|
eventId: string;
|
|
23
24
|
iteration?: number;
|
|
24
25
|
maxSteps: number;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { getContextRuntimeServices } from "../context.runtime.js";
|
|
1
2
|
import { OUTPUT_ITEM_TYPE } from "../context.events.js";
|
|
2
3
|
import { createContextStepStreamChunk, encodeContextStepStreamChunk, } from "../context.step-stream.js";
|
|
3
4
|
import { mapAiSdkChunkToContextEvent } from "./ai-sdk.chunk-map.js";
|
|
5
|
+
import { actionSpecToAiSdkTool, } from "../tools-to-model-tools.js";
|
|
4
6
|
import { writeContextTraceEvents } from "../steps/trace.steps.js";
|
|
5
7
|
async function readWorkflowMetadata() {
|
|
6
8
|
try {
|
|
@@ -82,8 +84,7 @@ function safeErrorJson(error) {
|
|
|
82
84
|
*/
|
|
83
85
|
export async function executeAiSdkReaction(params) {
|
|
84
86
|
"use step";
|
|
85
|
-
const {
|
|
86
|
-
const { store } = await getContextRuntime(params.env);
|
|
87
|
+
const { store } = await getContextRuntimeServices(params.runtime);
|
|
87
88
|
let events;
|
|
88
89
|
try {
|
|
89
90
|
events = await store.getItems(params.contextIdentifier);
|
|
@@ -111,10 +112,7 @@ export async function executeAiSdkReaction(params) {
|
|
|
111
112
|
})();
|
|
112
113
|
const toolsForStreamText = {};
|
|
113
114
|
for (const [name, t] of Object.entries(params.tools)) {
|
|
114
|
-
toolsForStreamText[name] =
|
|
115
|
-
description: t?.description,
|
|
116
|
-
inputSchema: jsonSchema(t.inputSchema),
|
|
117
|
-
};
|
|
115
|
+
toolsForStreamText[name] = actionSpecToAiSdkTool(name, t, jsonSchema);
|
|
118
116
|
}
|
|
119
117
|
const startedAtMs = Date.now();
|
|
120
118
|
const result = streamText({
|
|
@@ -221,7 +219,10 @@ export async function executeAiSdkReaction(params) {
|
|
|
221
219
|
}
|
|
222
220
|
}
|
|
223
221
|
finally {
|
|
224
|
-
contextStepStreamWriter
|
|
222
|
+
const streamWriter = contextStepStreamWriter;
|
|
223
|
+
if (typeof streamWriter?.releaseLock === "function") {
|
|
224
|
+
streamWriter.releaseLock();
|
|
225
|
+
}
|
|
225
226
|
}
|
|
226
227
|
const assistantEvent = await finishPromise;
|
|
227
228
|
const finishedAtMs = Date.now();
|
package/dist/reactors/types.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ModelMessage, UIMessageChunk } from "ai";
|
|
2
2
|
import type { ContextEnvironment } from "../context.config.js";
|
|
3
|
+
import type { ContextRuntime } from "../context.runtime.js";
|
|
3
4
|
import type { ContextModelInit } from "../context.engine.js";
|
|
4
5
|
import type { ContextIdentifier, StoredContext, ContextItem } from "../context.store.js";
|
|
5
6
|
import type { ContextSkillPackage } from "../context.skill.js";
|
|
6
|
-
import type {
|
|
7
|
+
import type { SerializableActionSpec } from "../tools-to-model-tools.js";
|
|
7
8
|
export type ContextActionRequest = {
|
|
8
9
|
actionRef: string;
|
|
9
10
|
actionName: string;
|
|
@@ -26,8 +27,13 @@ export type ContextReactionResult = {
|
|
|
26
27
|
actionRequests: ContextActionRequest[];
|
|
27
28
|
messagesForModel: ModelMessage[];
|
|
28
29
|
llm?: ContextReactionLLM;
|
|
30
|
+
reactor?: {
|
|
31
|
+
kind: string;
|
|
32
|
+
state?: Record<string, unknown> | null;
|
|
33
|
+
};
|
|
29
34
|
};
|
|
30
35
|
export type ContextReactorParams<Context = unknown, Env extends ContextEnvironment = ContextEnvironment> = {
|
|
36
|
+
runtime: ContextRuntime<Env>;
|
|
31
37
|
env: Env;
|
|
32
38
|
context: StoredContext<Context>;
|
|
33
39
|
contextIdentifier: ContextIdentifier;
|
|
@@ -35,7 +41,7 @@ export type ContextReactorParams<Context = unknown, Env extends ContextEnvironme
|
|
|
35
41
|
model: ContextModelInit;
|
|
36
42
|
systemPrompt: string;
|
|
37
43
|
actions: Record<string, unknown>;
|
|
38
|
-
|
|
44
|
+
actionSpecs: Record<string, SerializableActionSpec>;
|
|
39
45
|
skills: ContextSkillPackage[];
|
|
40
46
|
eventId: string;
|
|
41
47
|
executionId: string;
|
package/dist/runtime.step.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { coerceContextRuntime } from "./context.config.js";
|
|
2
2
|
import { eventsDomain } from "./schema.js";
|
|
3
3
|
export async function getContextRuntime(env) {
|
|
4
|
-
const { resolveRuntime } = await import("@ekairos/domain/runtime
|
|
4
|
+
const { resolveRuntime } = await import("@ekairos/domain/runtime");
|
|
5
5
|
const resolved = await resolveRuntime(eventsDomain, env);
|
|
6
6
|
return await coerceContextRuntime(resolved);
|
|
7
7
|
}
|
package/dist/schema.js
CHANGED
|
@@ -10,6 +10,7 @@ export const eventsDomain = domain("events")
|
|
|
10
10
|
name: i.string().optional(),
|
|
11
11
|
status: i.string().optional().indexed(), // open_idle | open_streaming | closed
|
|
12
12
|
content: i.any().optional(),
|
|
13
|
+
reactor: i.json().optional(),
|
|
13
14
|
}),
|
|
14
15
|
event_items: i.entity({
|
|
15
16
|
channel: i.string().indexed(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ModelMessage } from "ai";
|
|
2
2
|
import type { ContextItem } from "../context.store.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type SerializableActionSpec } from "../tools-to-model-tools.js";
|
|
4
4
|
import type { ContextModelInit } from "../context.engine.js";
|
|
5
5
|
/**
|
|
6
6
|
* Runs a single LLM streaming step as a Workflow step.
|
|
@@ -13,7 +13,7 @@ export declare function doContextStreamStep(params: {
|
|
|
13
13
|
model: ContextModelInit;
|
|
14
14
|
system: string;
|
|
15
15
|
messages: ModelMessage[];
|
|
16
|
-
tools: Record<string,
|
|
16
|
+
tools: Record<string, SerializableActionSpec>;
|
|
17
17
|
eventId: string;
|
|
18
18
|
maxSteps: number;
|
|
19
19
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OUTPUT_ITEM_TYPE } from "../context.events.js";
|
|
2
|
+
import { actionSpecToAiSdkTool, } from "../tools-to-model-tools.js";
|
|
2
3
|
/**
|
|
3
4
|
* Runs a single LLM streaming step as a Workflow step.
|
|
4
5
|
*
|
|
@@ -28,10 +29,7 @@ export async function doContextStreamStep(params) {
|
|
|
28
29
|
// `jsonSchema(...)` so the AI SDK does not attempt Zod conversion at runtime.
|
|
29
30
|
const toolsForStreamText = {};
|
|
30
31
|
for (const [name, t] of Object.entries(params.tools)) {
|
|
31
|
-
toolsForStreamText[name] =
|
|
32
|
-
description: t?.description,
|
|
33
|
-
inputSchema: jsonSchema(t.inputSchema),
|
|
34
|
-
};
|
|
32
|
+
toolsForStreamText[name] = actionSpecToAiSdkTool(name, t, jsonSchema);
|
|
35
33
|
}
|
|
36
34
|
const result = streamText({
|
|
37
35
|
model: resolvedModel,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { UIMessageChunk } from "ai";
|
|
2
2
|
import type { ContextEnvironment } from "../context.config.js";
|
|
3
|
+
import type { ContextRuntime } from "../context.runtime.js";
|
|
3
4
|
import type { ContextExecution, ContextItem, ContextIdentifier, StoredContext, ContextStatus } from "../context.store.js";
|
|
5
|
+
type RuntimeParams<Env extends ContextEnvironment = ContextEnvironment> = {
|
|
6
|
+
runtime: ContextRuntime<Env>;
|
|
7
|
+
};
|
|
4
8
|
export type ContextReviewRequest = {
|
|
5
9
|
toolCallId: string;
|
|
6
10
|
toolName?: string;
|
|
@@ -10,18 +14,37 @@ export type ContextReviewRequest = {
|
|
|
10
14
|
*
|
|
11
15
|
* This is the "context init" boundary for the story engine.
|
|
12
16
|
*/
|
|
13
|
-
export declare function initializeContext<C>(
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
export declare function initializeContext<C>(params: RuntimeParams & {
|
|
18
|
+
contextIdentifier: ContextIdentifier | null;
|
|
19
|
+
opts?: {
|
|
20
|
+
silent?: boolean;
|
|
21
|
+
writable?: WritableStream<UIMessageChunk>;
|
|
22
|
+
};
|
|
16
23
|
}): Promise<{
|
|
17
24
|
context: StoredContext<C>;
|
|
18
25
|
isNew: boolean;
|
|
19
26
|
}>;
|
|
20
|
-
export declare function updateContextContent<C>(
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
export declare function updateContextContent<C>(params: RuntimeParams & {
|
|
28
|
+
contextIdentifier: ContextIdentifier;
|
|
29
|
+
content: C;
|
|
30
|
+
}): Promise<StoredContext<C>>;
|
|
31
|
+
export declare function updateContextReactor<C>(params: RuntimeParams & {
|
|
32
|
+
contextIdentifier: ContextIdentifier;
|
|
33
|
+
reactor: {
|
|
34
|
+
kind: string;
|
|
35
|
+
state?: Record<string, unknown> | null;
|
|
36
|
+
};
|
|
37
|
+
}): Promise<StoredContext<C>>;
|
|
38
|
+
export declare function updateContextStatus(params: RuntimeParams & {
|
|
39
|
+
contextIdentifier: ContextIdentifier;
|
|
40
|
+
status: ContextStatus;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
export declare function saveTriggerItem(params: RuntimeParams & {
|
|
43
|
+
contextIdentifier: ContextIdentifier;
|
|
44
|
+
event: ContextItem;
|
|
45
|
+
}): Promise<ContextItem>;
|
|
23
46
|
export declare function saveTriggerAndCreateExecution(params: {
|
|
24
|
-
|
|
47
|
+
runtime: ContextRuntime<ContextEnvironment>;
|
|
25
48
|
contextIdentifier: ContextIdentifier;
|
|
26
49
|
triggerEvent: ContextItem;
|
|
27
50
|
}): Promise<{
|
|
@@ -29,41 +52,57 @@ export declare function saveTriggerAndCreateExecution(params: {
|
|
|
29
52
|
reactionEvent: ContextItem;
|
|
30
53
|
execution: ContextExecution;
|
|
31
54
|
}>;
|
|
32
|
-
export declare function saveReactionItem(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
55
|
+
export declare function saveReactionItem(params: RuntimeParams & {
|
|
56
|
+
contextIdentifier: ContextIdentifier;
|
|
57
|
+
event: ContextItem;
|
|
58
|
+
opts?: {
|
|
59
|
+
executionId?: string;
|
|
60
|
+
contextId?: string;
|
|
61
|
+
reviewRequests?: ContextReviewRequest[];
|
|
62
|
+
};
|
|
36
63
|
}): Promise<ContextItem>;
|
|
37
|
-
export declare function updateItem(
|
|
38
|
-
|
|
39
|
-
|
|
64
|
+
export declare function updateItem(params: RuntimeParams & {
|
|
65
|
+
eventId: string;
|
|
66
|
+
event: ContextItem;
|
|
67
|
+
opts?: {
|
|
68
|
+
executionId?: string;
|
|
69
|
+
contextId?: string;
|
|
70
|
+
};
|
|
40
71
|
}): Promise<ContextItem>;
|
|
41
|
-
export declare function createExecution(
|
|
72
|
+
export declare function createExecution(params: RuntimeParams & {
|
|
73
|
+
contextIdentifier: ContextIdentifier;
|
|
74
|
+
triggerEventId: string;
|
|
75
|
+
reactionEventId: string;
|
|
76
|
+
}): Promise<{
|
|
42
77
|
id: string;
|
|
43
78
|
}>;
|
|
44
79
|
export declare function createReactionItem(params: {
|
|
45
|
-
|
|
80
|
+
runtime: ContextRuntime<ContextEnvironment>;
|
|
46
81
|
contextIdentifier: ContextIdentifier;
|
|
47
82
|
triggerEventId: string;
|
|
48
83
|
}): Promise<{
|
|
49
84
|
reactionEventId: string;
|
|
50
85
|
executionId: string;
|
|
51
86
|
}>;
|
|
52
|
-
export declare function completeExecution(
|
|
87
|
+
export declare function completeExecution(params: RuntimeParams & {
|
|
88
|
+
contextIdentifier: ContextIdentifier;
|
|
89
|
+
executionId: string;
|
|
90
|
+
status: "completed" | "failed";
|
|
91
|
+
}): Promise<void>;
|
|
53
92
|
export declare function updateExecutionWorkflowRun(params: {
|
|
54
|
-
|
|
93
|
+
runtime: ContextRuntime<ContextEnvironment>;
|
|
55
94
|
executionId: string;
|
|
56
95
|
workflowRunId: string;
|
|
57
96
|
}): Promise<void>;
|
|
58
97
|
export declare function createContextStep(params: {
|
|
59
|
-
|
|
98
|
+
runtime: ContextRuntime<ContextEnvironment>;
|
|
60
99
|
executionId: string;
|
|
61
100
|
iteration: number;
|
|
62
101
|
}): Promise<{
|
|
63
102
|
stepId: string;
|
|
64
103
|
}>;
|
|
65
104
|
export declare function updateContextStep(params: {
|
|
66
|
-
|
|
105
|
+
runtime: ContextRuntime<ContextEnvironment>;
|
|
67
106
|
stepId: string;
|
|
68
107
|
executionId?: string;
|
|
69
108
|
contextId?: string;
|
|
@@ -82,15 +121,16 @@ export declare function updateContextStep(params: {
|
|
|
82
121
|
};
|
|
83
122
|
}): Promise<void>;
|
|
84
123
|
export declare function linkItemToExecutionStep(params: {
|
|
85
|
-
|
|
124
|
+
runtime: ContextRuntime<ContextEnvironment>;
|
|
86
125
|
itemId: string;
|
|
87
126
|
executionId: string;
|
|
88
127
|
}): Promise<void>;
|
|
89
128
|
export declare function saveContextPartsStep(params: {
|
|
90
|
-
|
|
129
|
+
runtime: ContextRuntime<ContextEnvironment>;
|
|
91
130
|
stepId: string;
|
|
92
131
|
executionId?: string;
|
|
93
132
|
contextId?: string;
|
|
94
133
|
iteration?: number;
|
|
95
134
|
parts: any[];
|
|
96
135
|
}): Promise<void>;
|
|
136
|
+
export {};
|