@ekairos/story 1.21.30-beta.0 → 1.21.32-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.
Files changed (108) hide show
  1. package/README.md +174 -0
  2. package/dist/agent.builder.d.ts +52 -0
  3. package/dist/agent.builder.d.ts.map +1 -0
  4. package/dist/agent.builder.js +110 -0
  5. package/dist/agent.builder.js.map +1 -0
  6. package/dist/agent.d.ts +2 -119
  7. package/dist/agent.d.ts.map +1 -1
  8. package/dist/agent.engine.d.ts +75 -0
  9. package/dist/agent.engine.d.ts.map +1 -0
  10. package/dist/agent.engine.js +455 -0
  11. package/dist/agent.engine.js.map +1 -0
  12. package/dist/agent.js +8 -607
  13. package/dist/agent.js.map +1 -1
  14. package/dist/ekairos.config.d.ts +21 -0
  15. package/dist/ekairos.config.d.ts.map +1 -0
  16. package/dist/ekairos.config.js +26 -0
  17. package/dist/ekairos.config.js.map +1 -0
  18. package/dist/events.d.ts +11 -7
  19. package/dist/events.d.ts.map +1 -1
  20. package/dist/events.js +37 -210
  21. package/dist/events.js.map +1 -1
  22. package/dist/index.d.ts +4 -4
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +7 -25
  25. package/dist/index.js.map +1 -1
  26. package/dist/legacy.story.d.ts +5 -0
  27. package/dist/legacy.story.d.ts.map +1 -0
  28. package/dist/legacy.story.js +15 -0
  29. package/dist/legacy.story.js.map +1 -0
  30. package/dist/runtime.d.ts +12 -0
  31. package/dist/runtime.js +12 -0
  32. package/dist/schema-document.d.ts +0 -1
  33. package/dist/schema-document.js +14 -18
  34. package/dist/schema-document.js.map +1 -1
  35. package/dist/schema.d.ts +0 -1
  36. package/dist/schema.js +22 -26
  37. package/dist/schema.js.map +1 -1
  38. package/dist/steps/do-story-stream-step.d.ts +29 -0
  39. package/dist/steps/do-story-stream-step.d.ts.map +1 -0
  40. package/dist/steps/do-story-stream-step.js +89 -0
  41. package/dist/steps/do-story-stream-step.js.map +1 -0
  42. package/dist/steps/index.d.ts +1 -3
  43. package/dist/steps/index.d.ts.map +1 -1
  44. package/dist/steps/index.js +3 -17
  45. package/dist/steps/index.js.map +1 -1
  46. package/dist/steps/store.steps.d.ts +43 -0
  47. package/dist/steps/store.steps.d.ts.map +1 -0
  48. package/dist/steps/store.steps.js +123 -0
  49. package/dist/steps/store.steps.js.map +1 -0
  50. package/dist/steps/story.steps.d.ts +35 -0
  51. package/dist/steps/story.steps.d.ts.map +1 -0
  52. package/dist/steps/story.steps.js +59 -0
  53. package/dist/steps/story.steps.js.map +1 -0
  54. package/dist/steps/stream.steps.d.ts +28 -0
  55. package/dist/steps/stream.steps.d.ts.map +1 -0
  56. package/dist/steps/stream.steps.js +75 -0
  57. package/dist/steps/stream.steps.js.map +1 -0
  58. package/dist/stores/instant.document-parser.d.ts +5 -0
  59. package/dist/stores/instant.document-parser.d.ts.map +1 -0
  60. package/dist/stores/instant.document-parser.js +116 -0
  61. package/dist/stores/instant.document-parser.js.map +1 -0
  62. package/dist/stores/instant.documents.d.ts +16 -0
  63. package/dist/stores/instant.documents.js +108 -0
  64. package/dist/stores/instant.store.d.ts +40 -0
  65. package/dist/stores/instant.store.d.ts.map +1 -0
  66. package/dist/stores/instant.store.js +207 -0
  67. package/dist/stores/instant.store.js.map +1 -0
  68. package/dist/story.builder.d.ts +116 -0
  69. package/dist/story.builder.d.ts.map +1 -0
  70. package/dist/story.builder.js +130 -0
  71. package/dist/story.builder.js.map +1 -0
  72. package/dist/story.config.d.ts +43 -0
  73. package/dist/story.config.d.ts.map +1 -0
  74. package/dist/story.config.js +57 -0
  75. package/dist/story.config.js.map +1 -0
  76. package/dist/story.d.ts +2 -50
  77. package/dist/story.d.ts.map +1 -1
  78. package/dist/story.engine.d.ts +174 -0
  79. package/dist/story.engine.d.ts.map +1 -0
  80. package/dist/story.engine.js +283 -0
  81. package/dist/story.engine.js.map +1 -0
  82. package/dist/story.js +6 -55
  83. package/dist/story.js.map +1 -1
  84. package/dist/story.legacy.d.ts +12 -0
  85. package/dist/story.legacy.d.ts.map +1 -0
  86. package/dist/story.legacy.js +15 -0
  87. package/dist/story.legacy.js.map +1 -0
  88. package/dist/story.registry.d.ts +21 -0
  89. package/dist/story.registry.d.ts.map +1 -0
  90. package/dist/story.registry.js +30 -0
  91. package/dist/story.registry.js.map +1 -0
  92. package/dist/story.store.d.ts +59 -0
  93. package/dist/story.store.d.ts.map +1 -0
  94. package/dist/story.store.js +1 -0
  95. package/dist/story.store.js.map +1 -0
  96. package/dist/story.streams.d.ts +55 -0
  97. package/dist/story.streams.d.ts.map +1 -0
  98. package/dist/story.streams.js +99 -0
  99. package/dist/story.streams.js.map +1 -0
  100. package/dist/story.toolcalls.d.ts +60 -0
  101. package/dist/story.toolcalls.d.ts.map +1 -0
  102. package/dist/story.toolcalls.js +73 -0
  103. package/dist/story.toolcalls.js.map +1 -0
  104. package/dist/tools-to-model-tools.d.ts +19 -0
  105. package/dist/tools-to-model-tools.js +21 -0
  106. package/dist/workflow.d.ts +20 -0
  107. package/dist/workflow.js +27 -0
  108. package/package.json +15 -4
package/dist/index.js CHANGED
@@ -1,25 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertModelMessageToEvent = exports.convertEventsToModelMessages = exports.convertEventToModelMessages = exports.convertToUIMessage = exports.createAssistantEventFromUIMessages = exports.createUserEventFromUIMessages = exports.EMAIL_CHANNEL = exports.AGENT_CHANNEL = exports.WEB_CHANNEL = exports.SYSTEM_MESSAGE_TYPE = exports.ASSISTANT_MESSAGE_TYPE = exports.USER_MESSAGE_TYPE = exports.storyDomain = exports.AgentService = exports.Agent = exports.createAgent = exports.agent = void 0;
4
- var agent_1 = require("./agent");
5
- Object.defineProperty(exports, "agent", { enumerable: true, get: function () { return agent_1.agent; } });
6
- Object.defineProperty(exports, "createAgent", { enumerable: true, get: function () { return agent_1.createAgent; } });
7
- Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_1.Agent; } });
8
- var service_1 = require("./service");
9
- Object.defineProperty(exports, "AgentService", { enumerable: true, get: function () { return service_1.AgentService; } });
10
- var schema_1 = require("./schema");
11
- Object.defineProperty(exports, "storyDomain", { enumerable: true, get: function () { return schema_1.storyDomain; } });
12
- var events_1 = require("./events");
13
- Object.defineProperty(exports, "USER_MESSAGE_TYPE", { enumerable: true, get: function () { return events_1.USER_MESSAGE_TYPE; } });
14
- Object.defineProperty(exports, "ASSISTANT_MESSAGE_TYPE", { enumerable: true, get: function () { return events_1.ASSISTANT_MESSAGE_TYPE; } });
15
- Object.defineProperty(exports, "SYSTEM_MESSAGE_TYPE", { enumerable: true, get: function () { return events_1.SYSTEM_MESSAGE_TYPE; } });
16
- Object.defineProperty(exports, "WEB_CHANNEL", { enumerable: true, get: function () { return events_1.WEB_CHANNEL; } });
17
- Object.defineProperty(exports, "AGENT_CHANNEL", { enumerable: true, get: function () { return events_1.AGENT_CHANNEL; } });
18
- Object.defineProperty(exports, "EMAIL_CHANNEL", { enumerable: true, get: function () { return events_1.EMAIL_CHANNEL; } });
19
- Object.defineProperty(exports, "createUserEventFromUIMessages", { enumerable: true, get: function () { return events_1.createUserEventFromUIMessages; } });
20
- Object.defineProperty(exports, "createAssistantEventFromUIMessages", { enumerable: true, get: function () { return events_1.createAssistantEventFromUIMessages; } });
21
- Object.defineProperty(exports, "convertToUIMessage", { enumerable: true, get: function () { return events_1.convertToUIMessage; } });
22
- Object.defineProperty(exports, "convertEventToModelMessages", { enumerable: true, get: function () { return events_1.convertEventToModelMessages; } });
23
- Object.defineProperty(exports, "convertEventsToModelMessages", { enumerable: true, get: function () { return events_1.convertEventsToModelMessages; } });
24
- Object.defineProperty(exports, "convertModelMessageToEvent", { enumerable: true, get: function () { return events_1.convertModelMessageToEvent; } });
25
- //# sourceMappingURL=index.js.map
1
+ export {
2
+ // Story API
3
+ story, createStory, Story, } from "./story";
4
+ export { registerStory, getStory, getStoryFactory, hasStory, listStories, } from "./story.registry";
5
+ export { storyDomain } from "./schema";
6
+ export { didToolExecute } from "./story.toolcalls";
7
+ export { USER_MESSAGE_TYPE, ASSISTANT_MESSAGE_TYPE, SYSTEM_MESSAGE_TYPE, WEB_CHANNEL, AGENT_CHANNEL, EMAIL_CHANNEL, createUserEventFromUIMessages, createAssistantEventFromUIMessages, convertToUIMessage, convertEventToModelMessages, convertEventsToModelMessages, convertModelMessageToEvent, } from "./events";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iCASgB;AARd,8FAAA,KAAK,OAAA;AAML,oGAAA,WAAW,OAAA;AACX,8FAAA,KAAK,OAAA;AAGP,qCAAwC;AAA/B,uGAAA,YAAY,OAAA;AAGrB,mCAAsC;AAA7B,qGAAA,WAAW,OAAA;AAEpB,mCAciB;AAbf,2GAAA,iBAAiB,OAAA;AACjB,gHAAA,sBAAsB,OAAA;AACtB,6GAAA,mBAAmB,OAAA;AACnB,qGAAA,WAAW,OAAA;AACX,uGAAA,aAAa,OAAA;AACb,uGAAA,aAAa,OAAA;AACb,uHAAA,6BAA6B,OAAA;AAC7B,4HAAA,kCAAkC,OAAA;AAClC,4GAAA,kBAAkB,OAAA;AAClB,qHAAA,2BAA2B,OAAA;AAC3B,sHAAA,4BAA4B,OAAA;AAC5B,oHAAA,0BAA0B,OAAA","sourcesContent":["export {\n agent,\n type AgentConfig,\n type AgentInstance,\n type AgentOptions,\n type ProgressStreamOptions,\n type DataStreamWriter,\n createAgent,\n Agent,\n} from \"./agent\"\n\nexport { AgentService } from \"./service\"\nexport type { ContextIdentifier, StoredContext, ContextEvent } from \"./service\"\n\nexport { storyDomain } from \"./schema\"\n\nexport {\n USER_MESSAGE_TYPE,\n ASSISTANT_MESSAGE_TYPE,\n SYSTEM_MESSAGE_TYPE,\n WEB_CHANNEL,\n AGENT_CHANNEL,\n EMAIL_CHANNEL,\n createUserEventFromUIMessages,\n createAssistantEventFromUIMessages,\n convertToUIMessage,\n convertEventToModelMessages,\n convertEventsToModelMessages,\n convertModelMessageToEvent,\n type ResponseMessage,\n} from \"./events\""]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO;AACL,YAAY;AACZ,KAAK,EACL,WAAW,EAKX,KAAK,GAEN,MAAM,SAAS,CAAA;AAEhB,OAAO,EACL,qBAAqB,EACrB,8BAA8B,EAC9B,wBAAwB,EACxB,mBAAmB,GAIpB,MAAM,gBAAgB,CAAA;AASvB,OAAO,EACL,aAAa,EACb,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,WAAW,GAEZ,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EACL,mBAAmB,GAGpB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,WAAW,EACX,aAAa,EACb,aAAa,EACb,6BAA6B,EAC7B,kCAAkC,EAClC,kBAAkB,EAClB,2BAA2B,EAC3B,4BAA4B,EAC5B,0BAA0B,GAE3B,MAAM,UAAU,CAAA","sourcesContent":["export {\n // Story API\n story,\n createStory,\n type StoryConfig,\n type StoryInstance,\n type StoryOptions,\n type StoryStreamOptions,\n Story,\n type RegistrableStoryBuilder,\n} from \"./story\"\n\nexport {\n configureStoryRuntime,\n configureStoryRuntimeBootstrap,\n isStoryRuntimeConfigured,\n resolveStoryRuntime,\n type StoryEnvironment,\n type StoryRuntime,\n type StoryRuntimeResolver,\n} from \"./story.config\"\n\nexport type {\n StoryStore,\n ContextIdentifier,\n StoredContext,\n ContextEvent,\n} from \"./story.store\"\n\nexport {\n registerStory,\n getStory,\n getStoryFactory,\n hasStory,\n listStories,\n type StoryKey,\n} from \"./story.registry\"\n\nexport {\n createEkairosConfig,\n type EkairosConfig,\n type RegistrableStory,\n} from \"./ekairos.config\"\n\nexport { storyDomain } from \"./schema\"\n\nexport {\n USER_MESSAGE_TYPE,\n ASSISTANT_MESSAGE_TYPE,\n SYSTEM_MESSAGE_TYPE,\n WEB_CHANNEL,\n AGENT_CHANNEL,\n EMAIL_CHANNEL,\n createUserEventFromUIMessages,\n createAssistantEventFromUIMessages,\n convertToUIMessage,\n convertEventToModelMessages,\n convertEventsToModelMessages,\n convertModelMessageToEvent,\n type ResponseMessage,\n} from \"./events\""]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @deprecated Use `createStory()` from the main entrypoint.
3
+ */
4
+ export declare const createAgent: any;
5
+ //# sourceMappingURL=legacy.story.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.story.d.ts","sourceRoot":"","sources":["../src/legacy.story.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,eAAO,MAAM,WAAW,KAAc,CAAA"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAgent = void 0;
4
+ /**
5
+ * Legacy entrypoint.
6
+ *
7
+ * Este archivo existe únicamente para compatibilidad hacia atrás.
8
+ * No exporta nada más que `createAgent`.
9
+ */
10
+ const agent_builder_1 = require("./agent.builder");
11
+ /**
12
+ * @deprecated Use `createStory()` from the main entrypoint.
13
+ */
14
+ exports.createAgent = agent_builder_1.createStory;
15
+ //# sourceMappingURL=legacy.story.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.story.js","sourceRoot":"","sources":["../src/legacy.story.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,mDAA6C;AAE7C;;GAEG;AACU,QAAA,WAAW,GAAG,2BAAW,CAAA","sourcesContent":["/**\r\n * Legacy entrypoint.\r\n *\r\n * Este archivo existe únicamente para compatibilidad hacia atrás.\r\n * No exporta nada más que `createAgent`.\r\n */\r\nimport { createStory } from \"./agent.builder\"\r\n\r\n/**\r\n * @deprecated Use `createStory()` from the main entrypoint.\r\n */\r\nexport const createAgent = createStory\r\n\r\n\r\n"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Runtime-only entrypoint for @ekairos/story.
3
+ *
4
+ * This file intentionally exports the "wiring" pieces that connect durable steps to a concrete
5
+ * store runtime (Instant/Postgres/etc).
6
+ *
7
+ * IMPORTANT:
8
+ * - Do NOT import this entrypoint from client/browser code.
9
+ * - Keep `@ekairos/story` main entrypoint safe to import from schema/domain modules.
10
+ */
11
+ export { configureStoryRuntime, configureStoryRuntimeBootstrap, isStoryRuntimeConfigured, resolveStoryRuntime, type StoryEnvironment, type StoryRuntime, type StoryRuntimeResolver, } from "./story.config";
12
+ export { createEkairosConfig, type EkairosConfig, type RegistrableStory, } from "./ekairos.config";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Runtime-only entrypoint for @ekairos/story.
3
+ *
4
+ * This file intentionally exports the "wiring" pieces that connect durable steps to a concrete
5
+ * store runtime (Instant/Postgres/etc).
6
+ *
7
+ * IMPORTANT:
8
+ * - Do NOT import this entrypoint from client/browser code.
9
+ * - Keep `@ekairos/story` main entrypoint safe to import from schema/domain modules.
10
+ */
11
+ export { configureStoryRuntime, configureStoryRuntimeBootstrap, isStoryRuntimeConfigured, resolveStoryRuntime, } from "./story.config";
12
+ export { createEkairosConfig, } from "./ekairos.config";
@@ -1,3 +1,2 @@
1
1
  import { type DomainSchemaResult } from "@ekairos/domain";
2
2
  export declare const documentDomain: DomainSchemaResult;
3
- //# sourceMappingURL=schema-document.d.ts.map
@@ -1,22 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.documentDomain = void 0;
4
- const core_1 = require("@instantdb/core");
5
- const domain_1 = require("@ekairos/domain");
6
- exports.documentDomain = (0, domain_1.domain)("document")
1
+ import { i } from "@instantdb/core";
2
+ import { domain } from "@ekairos/domain";
3
+ export const documentDomain = domain("document")
7
4
  .schema({
8
5
  entities: {
9
- document_documents: core_1.i.entity({
10
- name: core_1.i.string().optional().indexed(),
11
- mimeType: core_1.i.string().optional(),
12
- size: core_1.i.number().optional(),
13
- ownerId: core_1.i.string().optional().indexed(),
14
- orgId: core_1.i.string().optional().indexed(),
15
- createdAt: core_1.i.date().optional().indexed(),
16
- processedAt: core_1.i.date().optional().indexed(),
17
- updatedAt: core_1.i.date().optional(),
18
- lastJobId: core_1.i.string().optional(),
19
- content: core_1.i.json().optional(), // Store parsed content (pages, text, etc.)
6
+ document_documents: i.entity({
7
+ name: i.string().optional().indexed(),
8
+ mimeType: i.string().optional(),
9
+ size: i.number().optional(),
10
+ ownerId: i.string().optional().indexed(),
11
+ orgId: i.string().optional().indexed(),
12
+ createdAt: i.date().optional().indexed(),
13
+ processedAt: i.date().optional().indexed(),
14
+ updatedAt: i.date().optional(),
15
+ lastJobId: i.string().optional(),
16
+ content: i.json().optional(), // Store parsed content (pages, text, etc.)
20
17
  }),
21
18
  },
22
19
  links: {
@@ -35,4 +32,3 @@ exports.documentDomain = (0, domain_1.domain)("document")
35
32
  },
36
33
  rooms: {},
37
34
  });
38
- //# sourceMappingURL=schema-document.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema-document.js","sourceRoot":"","sources":["../src/schema-document.ts"],"names":[],"mappings":";;;AAAA,0CAAoC;AACpC,4CAAkE;AAErD,QAAA,cAAc,GAAuB,IAAA,eAAM,EAAC,UAAU,CAAC;KAC/D,MAAM,CAAC;IACJ,QAAQ,EAAE;QACN,kBAAkB,EAAE,QAAC,CAAC,MAAM,CAAC;YACzB,IAAI,EAAE,QAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE;YACrC,QAAQ,EAAE,QAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YAC/B,IAAI,EAAE,QAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YAC3B,OAAO,EAAE,QAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE;YACxC,KAAK,EAAE,QAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE;YACtC,SAAS,EAAE,QAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE;YACxC,WAAW,EAAE,QAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE;YAC1C,SAAS,EAAE,QAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;YAC9B,SAAS,EAAE,QAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YAChC,OAAO,EAAE,QAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,2CAA2C;SAC5E,CAAC;KACL;IACD,KAAK,EAAE;QACH,YAAY,EAAE;YACV,OAAO,EAAE;gBACL,EAAE,EAAE,oBAAoB;gBACxB,GAAG,EAAE,KAAK;gBACV,KAAK,EAAE,MAAM;aAChB;YACD,OAAO,EAAE;gBACL,EAAE,EAAE,QAAQ;gBACZ,GAAG,EAAE,KAAK;gBACV,KAAK,EAAE,UAAU;aACpB;SACJ;KACJ;IACD,KAAK,EAAE,EAAE;CACZ,CAAC,CAAC","sourcesContent":["import { i } from \"@instantdb/core\";\nimport { domain, type DomainSchemaResult } from \"@ekairos/domain\";\n\nexport const documentDomain: DomainSchemaResult = domain(\"document\")\n .schema({\n entities: {\n document_documents: i.entity({\n name: i.string().optional().indexed(),\n mimeType: i.string().optional(),\n size: i.number().optional(),\n ownerId: i.string().optional().indexed(),\n orgId: i.string().optional().indexed(),\n createdAt: i.date().optional().indexed(),\n processedAt: i.date().optional().indexed(),\n updatedAt: i.date().optional(),\n lastJobId: i.string().optional(),\n content: i.json().optional(), // Store parsed content (pages, text, etc.)\n }),\n },\n links: {\n documentFile: {\n forward: {\n on: \"document_documents\",\n has: \"one\",\n label: \"file\",\n },\n reverse: {\n on: \"$files\",\n has: \"one\",\n label: \"document\",\n },\n },\n },\n rooms: {},\n });\n"]}
1
+ {"version":3,"file":"schema-document.js","sourceRoot":"","sources":["../src/schema-document.ts"],"names":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;KACJ;IACD,KAAK,EAAE,EAAE;CACZ,CAAC,CAAC","sourcesContent":["import { i } from \"@instantdb/core\";\nimport { domain, type DomainSchemaResult } from \"@ekairos/domain\";\n\nexport const documentDomain: DomainSchemaResult = domain(\"document\")\n .schema({\n entities: {\n document_documents: i.entity({\n name: i.string().optional().indexed(),\n mimeType: i.string().optional(),\n size: i.number().optional(),\n ownerId: i.string().optional().indexed(),\n orgId: i.string().optional().indexed(),\n createdAt: i.date().optional().indexed(),\n processedAt: i.date().optional().indexed(),\n updatedAt: i.date().optional(),\n lastJobId: i.string().optional(),\n content: i.json().optional(), // Store parsed content (pages, text, etc.)\n }),\n },\n links: {\n documentFile: {\n forward: {\n on: \"document_documents\",\n has: \"one\",\n label: \"file\",\n },\n reverse: {\n on: \"$files\",\n has: \"one\",\n label: \"document\",\n },\n },\n },\n rooms: {},\n });\n"]}
package/dist/schema.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  import { type DomainSchemaResult } from "@ekairos/domain";
2
2
  export declare const storyDomain: DomainSchemaResult;
3
- //# sourceMappingURL=schema.d.ts.map
package/dist/schema.js CHANGED
@@ -1,32 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.storyDomain = void 0;
4
- const core_1 = require("@instantdb/core");
5
- const domain_1 = require("@ekairos/domain");
6
- const schema_document_1 = require("./schema-document");
7
- exports.storyDomain = (0, domain_1.domain)("story")
8
- .includes(schema_document_1.documentDomain)
1
+ import { i } from "@instantdb/core";
2
+ import { domain } from "@ekairos/domain";
3
+ import { documentDomain } from "./schema-document";
4
+ export const storyDomain = domain("story")
5
+ .includes(documentDomain)
9
6
  .schema({
10
7
  entities: {
11
- context_contexts: core_1.i.entity({
12
- createdAt: core_1.i.date(),
13
- updatedAt: core_1.i.date().optional(),
14
- type: core_1.i.string().optional(),
15
- key: core_1.i.string().optional().indexed().unique(),
16
- status: core_1.i.string().optional().indexed(), // open | streaming | closed
17
- content: core_1.i.any().optional(),
8
+ context_contexts: i.entity({
9
+ createdAt: i.date(),
10
+ updatedAt: i.date().optional(),
11
+ type: i.string().optional(),
12
+ key: i.string().optional().indexed().unique(),
13
+ status: i.string().optional().indexed(), // open | streaming | closed
14
+ content: i.any().optional(),
18
15
  }),
19
- context_events: core_1.i.entity({
20
- channel: core_1.i.string().indexed(),
21
- createdAt: core_1.i.date().indexed(),
22
- type: core_1.i.string().optional().indexed(),
23
- content: core_1.i.any().optional(),
24
- status: core_1.i.string().optional().indexed(),
16
+ context_events: i.entity({
17
+ channel: i.string().indexed(),
18
+ createdAt: i.date().indexed(),
19
+ type: i.string().optional().indexed(),
20
+ content: i.any().optional(),
21
+ status: i.string().optional().indexed(),
25
22
  }),
26
- story_executions: core_1.i.entity({
27
- createdAt: core_1.i.date(),
28
- updatedAt: core_1.i.date().optional(),
29
- status: core_1.i.string().optional().indexed(), // executing | completed | failed
23
+ story_executions: i.entity({
24
+ createdAt: i.date(),
25
+ updatedAt: i.date().optional(),
26
+ status: i.string().optional().indexed(), // executing | completed | failed
30
27
  }),
31
28
  },
32
29
  links: {
@@ -57,4 +54,3 @@ exports.storyDomain = (0, domain_1.domain)("story")
57
54
  },
58
55
  rooms: {},
59
56
  });
60
- //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":";;;AAAA,0CAAoC;AACpC,4CAAkE;AAClE,uDAAmD;AAEtC,QAAA,WAAW,GAAuB,IAAA,eAAM,EAAC,OAAO,CAAC;KACzD,QAAQ,CAAC,gCAAc,CAAC;KACxB,MAAM,CAAC;IACJ,QAAQ,EAAE;QACN,gBAAgB,EAAE,QAAC,CAAC,MAAM,CAAC;YACvB,SAAS,EAAE,QAAC,CAAC,IAAI,EAAE;YACnB,SAAS,EAAE,QAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;YAC9B,IAAI,EAAE,QAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,E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AAE,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;YACjE,OAAO,EAAE,EAAE,EAAE,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE;SACxE;QACD,yCAAyC;QACzC,6BAA6B,EAAE;YAC3B,OAAO,EAAE,EAAE,EAAE,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE;YAC1E,OAAO,EAAE,EAAE,EAAE,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE;SACtE;QACD,sCAAsC;QACtC,sBAAsB,EAAE;YACpB,OAAO,EAAE,EAAE,EAAE,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;YACjE,OAAO,EAAE,EAAE,EAAE,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE;SAC/E;QACD,uCAAuC;QACvC,uBAAuB,EAAE;YACrB,OAAO,EAAE,EAAE,EAAE,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE;YAClE,OAAO,EAAE,EAAE,EAAE,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,sBAAsB,EAAE;SAChF;KACJ;IACD,KAAK,EAAE,EAAE;CACZ,CAAC,CAAC","sourcesContent":["import { i } from \"@instantdb/core\";\nimport { domain, type DomainSchemaResult } from \"@ekairos/domain\";\nimport { documentDomain } from \"./schema-document\";\n\nexport const storyDomain: DomainSchemaResult = domain(\"story\")\n .includes(documentDomain)\n .schema({\n entities: {\n context_contexts: i.entity({\n createdAt: i.date(),\n updatedAt: i.date().optional(),\n type: i.string().optional(),\n key: i.string().optional().indexed().unique(),\n status: i.string().optional().indexed(), // open | streaming | closed\n content: i.any().optional(),\n }),\n context_events: i.entity({\n channel: i.string().indexed(),\n createdAt: i.date().indexed(),\n type: i.string().optional().indexed(),\n content: i.any().optional(),\n status: i.string().optional().indexed(),\n }),\n story_executions: i.entity({\n createdAt: i.date(),\n updatedAt: i.date().optional(),\n status: i.string().optional().indexed(), // executing | completed | failed\n }),\n },\n links: {\n storyEventsContext: {\n forward: { on: \"context_events\", has: \"one\", label: \"context\" },\n reverse: { on: \"context_contexts\", has: \"many\", label: \"events\" },\n },\n // Executions belong to a context\n storyExecutionsContext: {\n forward: { on: \"story_executions\", has: \"one\", label: \"context\" },\n reverse: { on: \"context_contexts\", has: \"many\", label: \"executions\" },\n },\n // Current execution pointer on a context\n storyContextsCurrentExecution: {\n forward: { on: \"context_contexts\", has: \"one\", label: \"currentExecution\" },\n reverse: { on: \"story_executions\", has: \"one\", label: \"currentOf\" },\n },\n // Link execution to its trigger event\n storyExecutionsTrigger: {\n forward: { on: \"story_executions\", has: \"one\", label: \"trigger\" },\n reverse: { on: \"context_events\", has: \"many\", label: \"executionsAsTrigger\" },\n },\n // Link execution to its reaction event\n storyExecutionsReaction: {\n forward: { on: \"story_executions\", has: \"one\", label: \"reaction\" },\n reverse: { on: \"context_events\", has: \"many\", label: \"executionsAsReaction\" },\n },\n },\n rooms: {},\n });\n\n\n\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAC;AACpC,OAAO,EAAE,MAAM,EAA2B,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,CAAC,MAAM,WAAW,GAAuB,MAAM,CAAC,OAAO,CAAC;KACzD,QAAQ,CAAC,cAAc,CAAC;KACxB,MAAM,CAAC;IACJ,QAAQ,EAAE;QACN,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC;YACvB,SAAS,EAAE,CAAC,CAA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AAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE;SACpE;QACD,iCAAiC;QACjC,sBAAsB,EAAE;YACpB,OAAO,EAAE,EAAE,EAAE,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;YACjE,OAAO,EAAE,EAAE,EAAE,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE;SACxE;QACD,yCAAyC;QACzC,6BAA6B,EAAE;YAC3B,OAAO,EAAE,EAAE,EAAE,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE;YAC1E,OAAO,EAAE,EAAE,EAAE,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE;SACtE;QACD,sCAAsC;QACtC,sBAAsB,EAAE;YACpB,OAAO,EAAE,EAAE,EAAE,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;YACjE,OAAO,EAAE,EAAE,EAAE,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE;SAC/E;QACD,uCAAuC;QACvC,uBAAuB,EAAE;YACrB,OAAO,EAAE,EAAE,EAAE,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE;YAClE,OAAO,EAAE,EAAE,EAAE,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,sBAAsB,EAAE;SAChF;KACJ;IACD,KAAK,EAAE,EAAE;CACZ,CAAC,CAAC","sourcesContent":["import { i } from \"@instantdb/core\";\nimport { domain, type DomainSchemaResult } from \"@ekairos/domain\";\nimport { documentDomain } from \"./schema-document\";\n\nexport const storyDomain: DomainSchemaResult = domain(\"story\")\n .includes(documentDomain)\n .schema({\n entities: {\n context_contexts: i.entity({\n createdAt: i.date(),\n updatedAt: i.date().optional(),\n type: i.string().optional(),\n key: i.string().optional().indexed().unique(),\n status: i.string().optional().indexed(), // open | streaming | closed\n content: i.any().optional(),\n }),\n context_events: i.entity({\n channel: i.string().indexed(),\n createdAt: i.date().indexed(),\n type: i.string().optional().indexed(),\n content: i.any().optional(),\n status: i.string().optional().indexed(),\n }),\n story_executions: i.entity({\n createdAt: i.date(),\n updatedAt: i.date().optional(),\n status: i.string().optional().indexed(), // executing | completed | failed\n }),\n },\n links: {\n storyEventsContext: {\n forward: { on: \"context_events\", has: \"one\", label: \"context\" },\n reverse: { on: \"context_contexts\", has: \"many\", label: \"events\" },\n },\n // Executions belong to a context\n storyExecutionsContext: {\n forward: { on: \"story_executions\", has: \"one\", label: \"context\" },\n reverse: { on: \"context_contexts\", has: \"many\", label: \"executions\" },\n },\n // Current execution pointer on a context\n storyContextsCurrentExecution: {\n forward: { on: \"context_contexts\", has: \"one\", label: \"currentExecution\" },\n reverse: { on: \"story_executions\", has: \"one\", label: \"currentOf\" },\n },\n // Link execution to its trigger event\n storyExecutionsTrigger: {\n forward: { on: \"story_executions\", has: \"one\", label: \"trigger\" },\n reverse: { on: \"context_events\", has: \"many\", label: \"executionsAsTrigger\" },\n },\n // Link execution to its reaction event\n storyExecutionsReaction: {\n forward: { on: \"story_executions\", has: \"one\", label: \"reaction\" },\n reverse: { on: \"context_events\", has: \"many\", label: \"executionsAsReaction\" },\n },\n },\n rooms: {},\n });\n\n\n\n"]}
@@ -0,0 +1,29 @@
1
+ import { type ModelMessage } from "ai";
2
+ import type { ContextEvent } from "../story.store";
3
+ import type { SerializableToolForModel } from "../tools-to-model-tools";
4
+ /**
5
+ * Runs a single LLM streaming step as a Workflow step.
6
+ *
7
+ * - Performs the provider/network call in a step (Node/runtime allowed).
8
+ * - Pipes AI SDK UI message chunks into the workflow-owned writable stream.
9
+ * - Returns the assistant event + extracted tool calls for the workflow loop.
10
+ */
11
+ export declare function doStoryStreamStep(params: {
12
+ model: any;
13
+ system: string;
14
+ messages: ModelMessage[];
15
+ tools: Record<string, SerializableToolForModel>;
16
+ eventId: string;
17
+ maxSteps: number;
18
+ /**
19
+ * Whether to emit a `start` chunk for this streamed assistant message.
20
+ *
21
+ * IMPORTANT:
22
+ * Our story loop may call the model multiple times within a single "turn" while continuing
23
+ * to append to the same `eventId`. In that case, `start` must only be sent once.
24
+ */
25
+ sendStart?: boolean;
26
+ }): Promise<{
27
+ assistantEvent: ContextEvent;
28
+ toolCalls: import("../story.toolcalls").ToolCall[];
29
+ }>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"do-story-stream-step.d.ts","sourceRoot":"","sources":["../../src/steps/do-story-stream-step.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,IAAI,EAET,KAAK,cAAc,EACpB,MAAM,IAAI,CAAA;AAGX,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE;IAC9C,KAAK,EAAE,GAAG,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,YAAY,EAAE,CAAA;IACxB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAC3B,QAAQ,EAAE,cAAc,CAAC,cAAc,CAAC,CAAA;IACxC,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CACjB;;;GAmEA"}
@@ -0,0 +1,89 @@
1
+ import { jsonSchema, gateway, smoothStream, stepCountIs, streamText, } from "ai";
2
+ import { getWritable } from "workflow";
3
+ import { extractToolCallsFromParts } from "../story.toolcalls";
4
+ /**
5
+ * Runs a single LLM streaming step as a Workflow step.
6
+ *
7
+ * - Performs the provider/network call in a step (Node/runtime allowed).
8
+ * - Pipes AI SDK UI message chunks into the workflow-owned writable stream.
9
+ * - Returns the assistant event + extracted tool calls for the workflow loop.
10
+ */
11
+ export async function doStoryStreamStep(params) {
12
+ "use step";
13
+ const writable = getWritable();
14
+ // Match DurableAgent's model init behavior:
15
+ // - string => AI Gateway model id, resolved via `gateway(...)` in the step runtime
16
+ // - function => model factory (should be a `"use step"` function for workflow serialization)
17
+ const resolvedModel = typeof params.model === "string"
18
+ ? gateway(params.model)
19
+ : typeof params.model === "function"
20
+ ? await params.model()
21
+ : params.model;
22
+ // IMPORTANT:
23
+ // `streamText` expects tools in the AI SDK ToolSet shape, where `inputSchema` is a Schema-like value.
24
+ // We pass plain JSON schema objects across the step boundary (serializable), then wrap them here with
25
+ // `jsonSchema(...)` so the AI SDK does not attempt Zod conversion at runtime.
26
+ const toolsForStreamText = {};
27
+ for (const [name, t] of Object.entries(params.tools)) {
28
+ toolsForStreamText[name] = {
29
+ description: t?.description,
30
+ inputSchema: jsonSchema(t.inputSchema),
31
+ };
32
+ }
33
+ const result = streamText({
34
+ model: resolvedModel,
35
+ system: params.system,
36
+ messages: params.messages,
37
+ tools: toolsForStreamText,
38
+ toolChoice: "required",
39
+ stopWhen: stepCountIs(params.maxSteps),
40
+ experimental_transform: smoothStream({ delayInMs: 30, chunking: "word" }),
41
+ });
42
+ // Ensure the underlying stream is consumed (AI SDK requirement)
43
+ result.consumeStream();
44
+ let resolveFinish;
45
+ let rejectFinish;
46
+ const finishPromise = new Promise((resolve, reject) => {
47
+ resolveFinish = resolve;
48
+ rejectFinish = reject;
49
+ });
50
+ const uiStream = result
51
+ .toUIMessageStream({
52
+ // Emit `start` only when the engine says so (typically once per turn).
53
+ sendStart: Boolean(params.sendStart),
54
+ generateMessageId: () => params.eventId,
55
+ messageMetadata() {
56
+ return { eventId: params.eventId };
57
+ },
58
+ onFinish: ({ messages }) => {
59
+ const lastMessage = messages[messages.length - 1];
60
+ const event = {
61
+ id: params.eventId,
62
+ type: "assistant.message",
63
+ channel: "web",
64
+ createdAt: new Date().toISOString(),
65
+ content: { parts: lastMessage?.parts ?? [] },
66
+ };
67
+ resolveFinish(event);
68
+ },
69
+ onError: (e) => {
70
+ rejectFinish(e);
71
+ return e instanceof Error ? e.message : String(e);
72
+ },
73
+ })
74
+ // Filter out per-step finish boundary. Workflow will emit a single finish.
75
+ .pipeThrough(new TransformStream({
76
+ transform(chunk, controller) {
77
+ if (chunk.type === "finish")
78
+ return;
79
+ controller.enqueue(chunk);
80
+ },
81
+ }));
82
+ await uiStream.pipeTo(writable, { preventClose: true });
83
+ const assistantEvent = await finishPromise;
84
+ const toolCalls = extractToolCallsFromParts(assistantEvent?.content?.parts);
85
+ return {
86
+ assistantEvent,
87
+ toolCalls,
88
+ };
89
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"do-story-stream-step.js","sourceRoot":"","sources":["../../src/steps/do-story-stream-step.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,WAAW,EACX,UAAU,GAKX,MAAM,IAAI,CAAA;AAEX,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AAG9D;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,MAQvC;IACC,UAAU,CAAA;IAEV,MAAM,MAAM,GAAG,UAAU,CAAC;QACxB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ,EAAE,MAAM,CAAC,QAAe;QAChC,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,UAAU,EAAE,UAAU;QACtB,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;QACtC,sBAAsB,EAAE,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;KAC1E,CAAC,CAAA;IAEF,gEAAgE;IAChE,MAAM,CAAC,aAAa,EAAE,CAAA;IAEtB,IAAI,aAA6C,CAAA;IACjD,IAAI,YAAyC,CAAA;IAE7C,MAAM,aAAa,GAAG,IAAI,OAAO,CAA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C,KAAK,CAAC,CAAA;QAC3B,CAAC;KACF,CAAC,CACH,CAAA;IAEH,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAA;IAE9D,MAAM,cAAc,GAAG,MAAM,aAAa,CAAA;IAC1C,MAAM,SAAS,GAAG,yBAAyB,CAAE,cAAsB,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;IAEpF,OAAO;QACL,cAAc;QACd,SAAS;KACV,CAAA;AACH,CAAC","sourcesContent":["import {\r\n smoothStream,\r\n stepCountIs,\r\n streamText,\r\n type ModelMessage,\r\n type Tool,\r\n type UIMessage,\r\n type UIMessageChunk,\r\n} from \"ai\"\r\n\r\nimport { extractToolCallsFromParts } from \"../story.toolcalls\"\r\nimport type { ContextEvent } from \"../story.store\"\r\n\r\n/**\r\n * Runs a single LLM streaming step as a Workflow step.\r\n *\r\n * - Performs the provider/network call in a step (Node/runtime allowed).\r\n * - Pipes AI SDK UI message chunks into the workflow-owned writable stream.\r\n * - Returns the assistant event + extracted tool calls for the workflow loop.\r\n */\r\nexport async function doStoryStreamStep(params: {\r\n model: any\r\n system: string\r\n messages: ModelMessage[]\r\n tools: Record<string, Tool>\r\n writable: WritableStream<UIMessageChunk>\r\n eventId: string\r\n maxSteps: number\r\n}) {\r\n \"use step\"\r\n\r\n const result = streamText({\r\n model: params.model,\r\n system: params.system,\r\n messages: params.messages as any,\r\n tools: params.tools,\r\n toolChoice: \"required\",\r\n stopWhen: stepCountIs(params.maxSteps),\r\n experimental_transform: smoothStream({ delayInMs: 30, chunking: \"word\" }),\r\n })\r\n\r\n // Ensure the underlying stream is consumed (AI SDK requirement)\r\n result.consumeStream()\r\n\r\n let resolveFinish!: (value: ContextEvent) => void\r\n let rejectFinish!: (reason?: unknown) => void\r\n\r\n const finishPromise = new Promise<ContextEvent>((resolve, reject) => {\r\n resolveFinish = resolve\r\n rejectFinish = reject\r\n })\r\n\r\n const uiStream = result\r\n .toUIMessageStream({\r\n sendStart: false, // workflow will own the start/finish boundaries\r\n generateMessageId: () => params.eventId,\r\n messageMetadata() {\r\n return { eventId: params.eventId }\r\n },\r\n onFinish: ({ messages }: { messages: UIMessage[] }) => {\r\n const lastMessage = messages[messages.length - 1]\r\n const event: ContextEvent = {\r\n id: params.eventId,\r\n type: \"assistant.message\",\r\n channel: \"web\",\r\n createdAt: new Date().toISOString(),\r\n content: { parts: lastMessage?.parts ?? [] },\r\n }\r\n resolveFinish(event)\r\n },\r\n onError: (e: unknown) => {\r\n rejectFinish(e)\r\n return e instanceof Error ? e.message : String(e)\r\n },\r\n })\r\n // Filter out per-step start/finish boundaries. Workflow will emit a single finish.\r\n .pipeThrough(\r\n new TransformStream<UIMessageChunk, UIMessageChunk>({\r\n transform(chunk, controller) {\r\n if (chunk.type === \"start\") return\r\n if (chunk.type === \"finish\") return\r\n controller.enqueue(chunk)\r\n },\r\n }),\r\n )\r\n\r\n await uiStream.pipeTo(params.writable, { preventClose: true })\r\n\r\n const assistantEvent = await finishPromise\r\n const toolCalls = extractToolCallsFromParts((assistantEvent as any)?.content?.parts)\r\n\r\n return {\r\n assistantEvent,\r\n toolCalls,\r\n }\r\n}\r\n\r\n\r\n\r\n"]}
@@ -1,4 +1,2 @@
1
- export * from "./registry";
2
- export * from "./ai";
3
- export * from "./base";
1
+ export { createStorySteps, type WorkflowWritableStream } from "./story.steps";
4
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/steps/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,MAAM,CAAA;AACpB,cAAc,QAAQ,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/steps/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAA"}
@@ -1,20 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./registry"), exports);
18
- __exportStar(require("./ai"), exports);
19
- __exportStar(require("./base"), exports);
3
+ exports.createStorySteps = void 0;
4
+ var story_steps_1 = require("./story.steps");
5
+ Object.defineProperty(exports, "createStorySteps", { enumerable: true, get: function () { return story_steps_1.createStorySteps; } });
20
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/steps/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,uCAAoB;AACpB,yCAAsB","sourcesContent":["export * from \"./registry\"\r\nexport * from \"./ai\"\r\nexport * from \"./base\"\r\n\r\n\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/steps/index.ts"],"names":[],"mappings":";;;AAAA,6CAA6E;AAApE,+GAAA,gBAAgB,OAAA","sourcesContent":["export { createStorySteps, type WorkflowWritableStream } from \"./story.steps\"\r\n\r\n\r\n"]}
@@ -0,0 +1,43 @@
1
+ import type { ModelMessage } from "ai";
2
+ import { type StoryEnvironment } from "../story.config";
3
+ import type { ContextEvent, ContextIdentifier, StoredContext } from "../story.store";
4
+ export declare function generateId(): Promise<string>;
5
+ export declare function getOrCreateContext<C>(env: StoryEnvironment, contextIdentifier: ContextIdentifier | null): Promise<{
6
+ context: StoredContext<C>;
7
+ isNew: boolean;
8
+ }>;
9
+ /**
10
+ * Ensures a context exists and emits a single `data-context-id` chunk to the workflow stream.
11
+ *
12
+ * Why this exists:
13
+ * - `getOrCreateContext(...)` and `writeContextIdChunk(...)` are semantically coupled.
14
+ * - Keeping them in a single step reduces step invocations per run (cheaper) without changing behavior.
15
+ */
16
+ export declare function ensureContextAndEmitContextId<C>(env: StoryEnvironment, contextIdentifier: ContextIdentifier | null): Promise<{
17
+ context: StoredContext<C>;
18
+ isNew: boolean;
19
+ }>;
20
+ export declare function getContext<C>(env: StoryEnvironment, contextIdentifier: ContextIdentifier): Promise<StoredContext<C> | null>;
21
+ /**
22
+ * Loads the state needed for a single Story loop iteration.
23
+ *
24
+ * This is a "read aggregation" step: it groups read-only store calls into a single workflow step
25
+ * invocation to reduce step overhead (cheaper) without changing behavior.
26
+ */
27
+ export declare function loadTurnState<C>(params: {
28
+ env: StoryEnvironment;
29
+ contextIdentifier: ContextIdentifier;
30
+ }): Promise<{
31
+ context: StoredContext<C> | null;
32
+ events: ContextEvent[];
33
+ }>;
34
+ export declare function updateContextContent<C>(env: StoryEnvironment, contextIdentifier: ContextIdentifier, content: C): Promise<StoredContext<C>>;
35
+ export declare function updateContextStatus(env: StoryEnvironment, contextIdentifier: ContextIdentifier, status: "open" | "streaming" | "closed"): Promise<void>;
36
+ export declare function saveEvent(env: StoryEnvironment, contextIdentifier: ContextIdentifier, event: ContextEvent): Promise<ContextEvent>;
37
+ export declare function updateEvent(env: StoryEnvironment, eventId: string, event: ContextEvent): Promise<ContextEvent>;
38
+ export declare function getEvents(env: StoryEnvironment, contextIdentifier: ContextIdentifier): Promise<ContextEvent[]>;
39
+ export declare function createExecution(env: StoryEnvironment, contextIdentifier: ContextIdentifier, triggerEventId: string, reactionEventId: string): Promise<{
40
+ id: string;
41
+ }>;
42
+ export declare function completeExecution(env: StoryEnvironment, contextIdentifier: ContextIdentifier, executionId: string, status: "completed" | "failed"): Promise<void>;
43
+ export declare function eventsToModelMessages(env: StoryEnvironment, events: ContextEvent[]): Promise<ModelMessage[]>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.steps.d.ts","sourceRoot":"","sources":["../../src/steps/store.steps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AAEtC,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEpF,wBAAsB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAQlD;AAED,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,GAC1C,OAAO,CAAC;IAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,CAexD;AAED,wBAAsB,UAAU,CAAC,CAAC,EAChC,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,EAAE,iBAAiB,GACnC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAIlC;AAED,wBAAsB,oBAAoB,CAAC,CAAC,EAC1C,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,EAAE,iBAAiB,EACpC,OAAO,EAAE,CAAC,GACT,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAI3B;AAED,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,GACtC,OAAO,CAAC,IAAI,CAAC,CAIf;AAED,wBAAsB,SAAS,CAC7B,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,EAAE,iBAAiB,EACpC,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,YAAY,CAAC,CAIvB;AAED,wBAAsB,WAAW,CAC/B,GAAG,EAAE,gBAAgB,EACrB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,YAAY,CAAC,CAIvB;AAED,wBAAsB,SAAS,CAC7B,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,EAAE,iBAAiB,GACnC,OAAO,CAAC,YAAY,EAAE,CAAC,CAIzB;AAED,wBAAsB,eAAe,CACnC,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,EAAE,iBAAiB,EACpC,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAIzB;AAED,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,EAAE,iBAAiB,EACpC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,WAAW,GAAG,QAAQ,GAC7B,OAAO,CAAC,IAAI,CAAC,CAIf;AAED,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,YAAY,EAAE,GACrB,OAAO,CAAC,YAAY,EAAE,CAAC,CAIzB"}
@@ -0,0 +1,123 @@
1
+ import { getWritable } from "workflow";
2
+ import { resolveStoryRuntime } from "../story.config";
3
+ export async function generateId() {
4
+ "use step";
5
+ // Use crypto.randomUUID when available (Node 18+)
6
+ const uuid = globalThis.crypto?.randomUUID?.();
7
+ if (uuid)
8
+ return uuid;
9
+ // Fallback
10
+ return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
11
+ }
12
+ export async function getOrCreateContext(env, contextIdentifier) {
13
+ "use step";
14
+ const { store } = await resolveStoryRuntime(env);
15
+ // Detect creation explicitly so the engine can run onContextCreated hooks.
16
+ if (!contextIdentifier) {
17
+ const context = await store.getOrCreateContext(null);
18
+ return { context, isNew: true };
19
+ }
20
+ const existing = await store.getContext(contextIdentifier);
21
+ if (existing)
22
+ return { context: existing, isNew: false };
23
+ const created = await store.getOrCreateContext(contextIdentifier);
24
+ return { context: created, isNew: true };
25
+ }
26
+ /**
27
+ * Ensures a context exists and emits a single `data-context-id` chunk to the workflow stream.
28
+ *
29
+ * Why this exists:
30
+ * - `getOrCreateContext(...)` and `writeContextIdChunk(...)` are semantically coupled.
31
+ * - Keeping them in a single step reduces step invocations per run (cheaper) without changing behavior.
32
+ */
33
+ export async function ensureContextAndEmitContextId(env, contextIdentifier) {
34
+ "use step";
35
+ const { store } = await resolveStoryRuntime(env);
36
+ // Detect creation explicitly so the engine can run onContextCreated hooks.
37
+ let result;
38
+ if (!contextIdentifier) {
39
+ const context = await store.getOrCreateContext(null);
40
+ result = { context, isNew: true };
41
+ }
42
+ else {
43
+ const existing = await store.getContext(contextIdentifier);
44
+ if (existing) {
45
+ result = { context: existing, isNew: false };
46
+ }
47
+ else {
48
+ const created = await store.getOrCreateContext(contextIdentifier);
49
+ result = { context: created, isNew: true };
50
+ }
51
+ }
52
+ const writable = getWritable();
53
+ const writer = writable.getWriter();
54
+ try {
55
+ await writer.write({
56
+ type: "data-context-id",
57
+ id: String(result.context.id),
58
+ data: { contextId: String(result.context.id) },
59
+ });
60
+ }
61
+ finally {
62
+ writer.releaseLock();
63
+ }
64
+ return result;
65
+ }
66
+ export async function getContext(env, contextIdentifier) {
67
+ "use step";
68
+ const { store } = await resolveStoryRuntime(env);
69
+ return await store.getContext(contextIdentifier);
70
+ }
71
+ /**
72
+ * Loads the state needed for a single Story loop iteration.
73
+ *
74
+ * This is a "read aggregation" step: it groups read-only store calls into a single workflow step
75
+ * invocation to reduce step overhead (cheaper) without changing behavior.
76
+ */
77
+ export async function loadTurnState(params) {
78
+ "use step";
79
+ const { store } = await resolveStoryRuntime(params.env);
80
+ const context = await store.getContext(params.contextIdentifier);
81
+ const events = await store.getEvents(params.contextIdentifier);
82
+ return { context, events };
83
+ }
84
+ export async function updateContextContent(env, contextIdentifier, content) {
85
+ "use step";
86
+ const { store } = await resolveStoryRuntime(env);
87
+ return await store.updateContextContent(contextIdentifier, content);
88
+ }
89
+ export async function updateContextStatus(env, contextIdentifier, status) {
90
+ "use step";
91
+ const { store } = await resolveStoryRuntime(env);
92
+ await store.updateContextStatus(contextIdentifier, status);
93
+ }
94
+ export async function saveEvent(env, contextIdentifier, event) {
95
+ "use step";
96
+ const { store } = await resolveStoryRuntime(env);
97
+ return await store.saveEvent(contextIdentifier, event);
98
+ }
99
+ export async function updateEvent(env, eventId, event) {
100
+ "use step";
101
+ const { store } = await resolveStoryRuntime(env);
102
+ return await store.updateEvent(eventId, event);
103
+ }
104
+ export async function getEvents(env, contextIdentifier) {
105
+ "use step";
106
+ const { store } = await resolveStoryRuntime(env);
107
+ return await store.getEvents(contextIdentifier);
108
+ }
109
+ export async function createExecution(env, contextIdentifier, triggerEventId, reactionEventId) {
110
+ "use step";
111
+ const { store } = await resolveStoryRuntime(env);
112
+ return await store.createExecution(contextIdentifier, triggerEventId, reactionEventId);
113
+ }
114
+ export async function completeExecution(env, contextIdentifier, executionId, status) {
115
+ "use step";
116
+ const { store } = await resolveStoryRuntime(env);
117
+ await store.completeExecution(contextIdentifier, executionId, status);
118
+ }
119
+ export async function eventsToModelMessages(env, events) {
120
+ "use step";
121
+ const { store } = await resolveStoryRuntime(env);
122
+ return await store.eventsToModelMessages(events);
123
+ }