@ekairos/story 1.21.40-beta.0 → 1.21.43-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/story.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { Story, type StoryOptions, type StoryStreamOptions, type ShouldContinue, type StoryShouldContinueArgs, } from "./story.engine";
2
- export { story, createStory, type StoryConfig, type StoryInstance, type RegistrableStoryBuilder, } from "./story.builder";
1
+ export { Story, type StoryOptions, type StoryStreamOptions, type ShouldContinue, type StoryShouldContinueArgs, } from "./story.engine.js";
2
+ export { story, createStory, type StoryConfig, type StoryInstance, type RegistrableStoryBuilder, } from "./story.builder.js";
@@ -1,6 +1,6 @@
1
1
  import type { Tool } from "ai";
2
- import type { StoryEnvironment } from "./story.config";
3
- import type { ContextEvent, ContextIdentifier, StoredContext } from "./story.store";
2
+ import type { StoryEnvironment } from "./story.config.js";
3
+ import type { ContextEvent, ContextIdentifier, StoredContext } from "./story.store.js";
4
4
  export interface StoryOptions<Context = any, Env extends StoryEnvironment = StoryEnvironment> {
5
5
  onContextCreated?: (args: {
6
6
  env: Env;
@@ -1,8 +1,8 @@
1
- import { applyToolExecutionResultToParts } from "./story.toolcalls";
2
- import { doStoryStreamStep } from "./steps/do-story-stream-step";
3
- import { toolsToModelTools } from "./tools-to-model-tools";
4
- import { closeStoryStream, writeContextSubstate, writeToolOutputs } from "./steps/stream.steps";
5
- import { completeExecution, createExecution, eventsToModelMessages, generateId, ensureContextAndEmitContextId, getEvents, saveEvent, updateContextContent, updateContextStatus, updateEvent, } from "./steps/store.steps";
1
+ import { applyToolExecutionResultToParts } from "./story.toolcalls.js";
2
+ import { executeReaction } from "./steps/reaction.steps.js";
3
+ import { toolsToModelTools } from "./tools-to-model-tools.js";
4
+ import { closeStoryStream, writeContextSubstate, writeStoryPing, writeToolOutputs } from "./steps/stream.steps.js";
5
+ import { completeExecution, createReactionEvent, initializeContext, saveReactionEvent, saveTriggerEvent, updateContextContent, updateContextStatus, updateEvent, } from "./steps/store.steps.js";
6
6
  export class Story {
7
7
  constructor(opts = {}) {
8
8
  this.opts = opts;
@@ -59,7 +59,7 @@ export class Story {
59
59
  const preventClose = params.options?.preventClose ?? false;
60
60
  const sendFinish = params.options?.sendFinish ?? true;
61
61
  // 1) Ensure context exists (step)
62
- const ctxResult = await ensureContextAndEmitContextId(params.env, params.contextIdentifier);
62
+ const ctxResult = await initializeContext(params.env, params.contextIdentifier);
63
63
  const currentContext = ctxResult.context;
64
64
  const contextSelector = params.contextIdentifier?.id
65
65
  ? { id: String(params.contextIdentifier.id) }
@@ -70,12 +70,16 @@ export class Story {
70
70
  await this.opts.onContextCreated?.({ env: params.env, context: currentContext });
71
71
  }
72
72
  // 2) Persist trigger event + create execution shell (steps)
73
- const persistedTriggerEvent = await saveEvent(params.env, contextSelector, triggerEvent);
73
+ const persistedTriggerEvent = await saveTriggerEvent(params.env, contextSelector, triggerEvent);
74
74
  const triggerEventId = persistedTriggerEvent.id;
75
- const reactionEventId = await generateId();
76
- await updateContextStatus(params.env, contextSelector, "streaming");
77
- const execution = await createExecution(params.env, contextSelector, triggerEventId, reactionEventId);
78
- const executionId = execution.id;
75
+ const { reactionEventId, executionId } = await createReactionEvent({
76
+ env: params.env,
77
+ contextIdentifier: contextSelector,
78
+ triggerEventId,
79
+ });
80
+ // Emit a simple ping chunk early so clients can validate that streaming works end-to-end.
81
+ // This should be ignored safely by clients that don't care about it.
82
+ await writeStoryPing({ label: "story-start" });
79
83
  let reactionEvent = null;
80
84
  // Latest persisted context state for this run (we keep it in memory; store is updated via steps).
81
85
  let updatedContext = currentContext;
@@ -95,7 +99,6 @@ export class Story {
95
99
  };
96
100
  try {
97
101
  for (let iter = 0; iter < maxIterations; iter++) {
98
- const events = await getEvents(params.env, contextSelector);
99
102
  // Normalize/initialize context (workflow-level; may call steps if needed)
100
103
  const nextContent = await this.initialize(updatedContext, params.env);
101
104
  updatedContext = await updateContextContent(params.env, contextSelector, nextContent);
@@ -105,12 +108,11 @@ export class Story {
105
108
  // IMPORTANT: step args must be serializable.
106
109
  // Match DurableAgent behavior: convert tool input schemas to plain JSON Schema in workflow context.
107
110
  const toolsForModel = toolsToModelTools(toolsAll);
108
- const expandedEvents = await this.expandEvents(events, updatedContext, params.env);
109
- const messagesForModel = await eventsToModelMessages(params.env, expandedEvents);
110
- const { assistantEvent, toolCalls } = await doStoryStreamStep({
111
+ const { assistantEvent, toolCalls, messagesForModel } = await executeReaction({
112
+ env: params.env,
113
+ contextIdentifier: contextSelector,
111
114
  model: this.getModel(updatedContext, params.env),
112
115
  system: systemPrompt,
113
- messages: messagesForModel,
114
116
  tools: toolsForModel,
115
117
  eventId: reactionEventId,
116
118
  maxSteps: maxModelSteps,
@@ -119,7 +121,7 @@ export class Story {
119
121
  });
120
122
  // Persist/append the assistant event for this iteration
121
123
  if (!reactionEvent) {
122
- reactionEvent = await saveEvent(params.env, contextSelector, {
124
+ reactionEvent = await saveReactionEvent(params.env, contextSelector, {
123
125
  ...assistantEvent,
124
126
  status: "pending",
125
127
  });
package/dist/story.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export {
2
2
  // engine
3
- Story, } from "./story.engine";
3
+ Story, } from "./story.engine.js";
4
4
  export {
5
5
  // builder
6
- story, createStory, } from "./story.builder";
6
+ story, createStory, } from "./story.builder.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekairos/story",
3
- "version": "1.21.40-beta.0",
3
+ "version": "1.21.43-beta.0",
4
4
  "description": "Pulzar Story - Workflow-based AI Stories",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@ai-sdk/openai": "^2.0.52",
51
- "@ekairos/domain": "^1.21.40-beta.0",
51
+ "@ekairos/domain": "^1.21.43-beta.0",
52
52
  "@instantdb/admin": "^0.22.13",
53
53
  "@instantdb/core": "^0.22.13",
54
54
  "@vercel/sandbox": "^0.0.23",