@ekairos/story 1.21.29-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 (111) 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/service.d.ts.map +1 -1
  39. package/dist/service.js +2 -1
  40. package/dist/service.js.map +1 -1
  41. package/dist/steps/do-story-stream-step.d.ts +29 -0
  42. package/dist/steps/do-story-stream-step.d.ts.map +1 -0
  43. package/dist/steps/do-story-stream-step.js +89 -0
  44. package/dist/steps/do-story-stream-step.js.map +1 -0
  45. package/dist/steps/index.d.ts +1 -3
  46. package/dist/steps/index.d.ts.map +1 -1
  47. package/dist/steps/index.js +3 -17
  48. package/dist/steps/index.js.map +1 -1
  49. package/dist/steps/store.steps.d.ts +43 -0
  50. package/dist/steps/store.steps.d.ts.map +1 -0
  51. package/dist/steps/store.steps.js +123 -0
  52. package/dist/steps/store.steps.js.map +1 -0
  53. package/dist/steps/story.steps.d.ts +35 -0
  54. package/dist/steps/story.steps.d.ts.map +1 -0
  55. package/dist/steps/story.steps.js +59 -0
  56. package/dist/steps/story.steps.js.map +1 -0
  57. package/dist/steps/stream.steps.d.ts +28 -0
  58. package/dist/steps/stream.steps.d.ts.map +1 -0
  59. package/dist/steps/stream.steps.js +75 -0
  60. package/dist/steps/stream.steps.js.map +1 -0
  61. package/dist/stores/instant.document-parser.d.ts +5 -0
  62. package/dist/stores/instant.document-parser.d.ts.map +1 -0
  63. package/dist/stores/instant.document-parser.js +116 -0
  64. package/dist/stores/instant.document-parser.js.map +1 -0
  65. package/dist/stores/instant.documents.d.ts +16 -0
  66. package/dist/stores/instant.documents.js +108 -0
  67. package/dist/stores/instant.store.d.ts +40 -0
  68. package/dist/stores/instant.store.d.ts.map +1 -0
  69. package/dist/stores/instant.store.js +207 -0
  70. package/dist/stores/instant.store.js.map +1 -0
  71. package/dist/story.builder.d.ts +116 -0
  72. package/dist/story.builder.d.ts.map +1 -0
  73. package/dist/story.builder.js +130 -0
  74. package/dist/story.builder.js.map +1 -0
  75. package/dist/story.config.d.ts +43 -0
  76. package/dist/story.config.d.ts.map +1 -0
  77. package/dist/story.config.js +57 -0
  78. package/dist/story.config.js.map +1 -0
  79. package/dist/story.d.ts +2 -50
  80. package/dist/story.d.ts.map +1 -1
  81. package/dist/story.engine.d.ts +174 -0
  82. package/dist/story.engine.d.ts.map +1 -0
  83. package/dist/story.engine.js +283 -0
  84. package/dist/story.engine.js.map +1 -0
  85. package/dist/story.js +6 -55
  86. package/dist/story.js.map +1 -1
  87. package/dist/story.legacy.d.ts +12 -0
  88. package/dist/story.legacy.d.ts.map +1 -0
  89. package/dist/story.legacy.js +15 -0
  90. package/dist/story.legacy.js.map +1 -0
  91. package/dist/story.registry.d.ts +21 -0
  92. package/dist/story.registry.d.ts.map +1 -0
  93. package/dist/story.registry.js +30 -0
  94. package/dist/story.registry.js.map +1 -0
  95. package/dist/story.store.d.ts +59 -0
  96. package/dist/story.store.d.ts.map +1 -0
  97. package/dist/story.store.js +1 -0
  98. package/dist/story.store.js.map +1 -0
  99. package/dist/story.streams.d.ts +55 -0
  100. package/dist/story.streams.d.ts.map +1 -0
  101. package/dist/story.streams.js +99 -0
  102. package/dist/story.streams.js.map +1 -0
  103. package/dist/story.toolcalls.d.ts +60 -0
  104. package/dist/story.toolcalls.d.ts.map +1 -0
  105. package/dist/story.toolcalls.js +73 -0
  106. package/dist/story.toolcalls.js.map +1 -0
  107. package/dist/tools-to-model-tools.d.ts +19 -0
  108. package/dist/tools-to-model-tools.js +21 -0
  109. package/dist/workflow.d.ts +20 -0
  110. package/dist/workflow.js +27 -0
  111. 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: {},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E,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"]}
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,Q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AAE;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"]}
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;Q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,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;YAC/D,OAAO,EAAE,EAAE,EAAE,EAAE,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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,aAAa,EAAU,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAC7F,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE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,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IA4B9E,oBAAoB,CAAC,CAAC,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAcpG,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAoB3F,eAAe,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IA0B/H,mBAAmB,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAYjH,iBAAiB,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAe3H,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAOxE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAWhD,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAuBxE,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC;QAC1D,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;QAC3B,MAAM,EAAE,WAAW,EAAE,CAAA;QACrB,cAAc,EAAE,GAAG,CAAA;KACtB,CAAC;CA6CL"}
package/dist/service.js CHANGED
@@ -75,7 +75,8 @@ class AgentService {
75
75
  }
76
76
  async saveEvent(contextIdentifier, event) {
77
77
  const txs = [
78
- this.db.tx.context_events[event.id].create({
78
+ // Use update instead of create to handle both new and existing events
79
+ this.db.tx.context_events[event.id].update({
79
80
  ...event,
80
81
  status: "stored"
81
82
  })
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;AAAA,4CAA6F;AAgB7F,MAAa,YAAY;IAIrB,YAAY,EAAsD;QAC9D,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;IAChB,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAI,iBAA2C;QAC1E,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,aAAa,EAAK,CAAA;QAClC,CAAC;QAED,IAAI,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAI,iBAAiB,CAAC,CAAA;QACzD,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,IAAI,CAAC,aAAa,CAAI,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAA;QACrH,CAAC;aAAM,CAAC;YACJ,OAAO,OAAO,CAAA;QAClB,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,aAAa,CAAI,UAAmC,EAAE,SAAkB;QACjF,IAAI,WAAW,GAA8F;YACzG,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,OAAO,EAAE,EAAE;YACX,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,MAAM;SACjB,CAAA;QAED,MAAM,YAAY,GAAG,SAAS,IAAI,IAAA,UAAE,GAAE,CAAA;QACtC,IAAI,UAAU,EAAE,GAAG,EAAE,CAAC;YAClB,WAAW,GAAG;gBACV,GAAG,WAAW;gBACd,GAAG,EAAE,UAAU,CAAC,GAAG;aACtB,CAAA;QACL,CAAC;QAED,MAAM,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC;YACnB,IAAI,CAAC,EAAE,C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MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QAC7B,CAAC;QAED,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;QACrD,CAAC;QAED,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAA;QAEpC,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QAC1D,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC;YAC9B,cAAc,EAAE;gBACZ,CAAC,EAAE;oBACC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAc,EAAE;oBAC7B,KAAK,EAAE,CAAC;oBACR,MAAM,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,CAAC;iBACtE;aACJ;SACJ,CAAC,CAAA;QAEF,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QAEhG,OAAO;YACH,OAAO;YACP,MAAM;YACN,cAAc;SACjB,CAAA;IACL,CAAC;CACJ;AAvPD,oCAuPC","sourcesContent":["import { id, init, InstaQLEntity, lookup, type InstantAdminDatabase } from \"@instantdb/admin\"\nimport { storyDomain } from \"./schema\"\nimport { SchemaOf } from \"@ekairos/domain\"\n\nexport type StoredContext<Context> = Omit<InstaQLEntity<typeof storyDomain, 'context_contexts'>, 'content'> & { content: Context | null }\nexport type ContextIdentifier = { id: string; key?: never } | { key: string; id?: never }\n\nexport type ContextEvent = InstaQLEntity<typeof storyDomain, 'context_events'> & { content: any }\n\nexport type StreamChunk = {\n type: string\n messageId?: string\n content?: string\n [key: string]: unknown\n}\n\nexport class AgentService {\n\n private db: InstantAdminDatabase<SchemaOf<typeof storyDomain>>\n\n constructor(db: InstantAdminDatabase<SchemaOf<typeof storyDomain>>) {\n this.db = db\n }\n\n public async getOrCreateContext<C>(contextIdentifier: ContextIdentifier | null): Promise<StoredContext<C>> {\n if (!contextIdentifier) {\n return this.createContext<C>()\n }\n\n let context = await this.getContext<C>(contextIdentifier)\n if (!context) {\n return this.createContext<C>(contextIdentifier.key ? { key: contextIdentifier.key } : null, contextIdentifier.id)\n } else {\n return context\n }\n }\n\n public async createContext<C>(contextKey?: { key: string } | null, contextId?: string): Promise<StoredContext<C>> {\n let contextData: { createdAt: Date; content: Record<string, unknown>; key: string | null; status: \"open\" } = {\n createdAt: new Date(),\n content: {},\n key: null,\n status: \"open\"\n }\n\n const newContextId = contextId ?? id()\n if (contextKey?.key) {\n contextData = {\n ...contextData,\n key: contextKey.key\n }\n }\n\n await this.db.transact([\n this.db.tx.context_contexts[newContextId].create(contextData)\n ])\n return this.getContext<C>({ id: newContextId })\n }\n\n public async getContext<C>(contextIdentifier: ContextIdentifier): Promise<StoredContext<C>> {\n let context;\n try {\n if (contextIdentifier.id) {\n const tRes = await this.db.query({\n context_contexts: {\n $: { where: { id: contextIdentifier.id as any }, limit: 1 }\n }\n })\n context = tRes.context_contexts?.[0]\n }\n\n if (contextIdentifier.key) {\n const tRes = await this.db.query({\n context_contexts: {\n $: { where: { key: contextIdentifier.key } }\n }\n })\n context = tRes.context_contexts?.[0]\n }\n\n return context as unknown as StoredContext<C>\n } catch (error: any) {\n console.error(\"Error getting context\", error)\n throw new Error(\"Error getting context: \" + error.message)\n }\n }\n\n public async updateContextContent<C>(contextIdentifier: ContextIdentifier, content: C): Promise<StoredContext<C>> {\n\n const contextDBIdentifier = contextIdentifier.id ?? lookup(\"key\", contextIdentifier.key)\n\n await this.db.transact([\n this.db.tx.context_contexts[contextDBIdentifier].update({\n content: content,\n updatedAt: new Date()\n })\n ])\n\n return this.getContext<C>(contextIdentifier)\n }\n\n public async saveEvent(contextIdentifier: ContextIdentifier, event: ContextEvent): Promise<ContextEvent> {\n const txs = [\n this.db.tx.context_events[event.id].create({\n ...event,\n status: \"stored\"\n })\n ]\n\n if (contextIdentifier.id) {\n txs.push(this.db.tx.context_events[event.id].link({ context: contextIdentifier.id }))\n } else {\n txs.push(this.db.tx.context_events[event.id].link({ context: lookup(\"key\", contextIdentifier.key) }))\n }\n\n await this.db.transact(txs)\n\n return await this.getEvent(event.id)\n }\n\n public async createExecution(contextIdentifier: ContextIdentifier, triggerEventId: string, reactionEventId: string): Promise<{ id: string }> {\n const executionId = id()\n const execCreate = this.db.tx.story_executions[executionId].create({\n createdAt: new Date(),\n status: \"executing\",\n })\n\n const txs: any[] = [execCreate]\n\n if (contextIdentifier.id) {\n txs.push(this.db.tx.story_executions[executionId].link({ context: contextIdentifier.id }))\n txs.push(this.db.tx.context_contexts[contextIdentifier.id].link({ currentExecution: executionId }))\n } else {\n const ctxLookup = lookup(\"key\", contextIdentifier.key)\n txs.push(this.db.tx.story_executions[executionId].link({ context: ctxLookup }))\n txs.push(this.db.tx.context_contexts[ctxLookup].link({ currentExecution: executionId }))\n }\n\n txs.push(this.db.tx.story_executions[executionId].link({ trigger: triggerEventId }))\n txs.push(this.db.tx.story_executions[executionId].link({ reaction: reactionEventId }))\n\n await this.db.transact(txs)\n\n return { id: executionId }\n }\n\n public async updateContextStatus(contextIdentifier: ContextIdentifier, status: \"open\" | \"streaming\" | \"closed\"): Promise<void> {\n const txs: any[] = []\n \n if (contextIdentifier.id) {\n txs.push(this.db.tx.context_contexts[contextIdentifier.id].update({ status, updatedAt: new Date() }))\n } else {\n txs.push(this.db.tx.context_contexts[lookup(\"key\", contextIdentifier.key)].update({ status, updatedAt: new Date() }))\n }\n\n await this.db.transact(txs)\n }\n\n public async completeExecution(contextIdentifier: ContextIdentifier, executionId: string, status: \"completed\" | \"failed\"): Promise<void> {\n const txs: any[] = []\n txs.push(this.db.tx.story_executions[executionId].update({ status, updatedAt: new Date() }))\n\n // Update context status to \"open\" when execution completes\n if (contextIdentifier.id) {\n txs.push(this.db.tx.context_contexts[contextIdentifier.id].update({ status: \"open\", updatedAt: new Date() }))\n // optionally unlink currentExecution if desired\n } else {\n txs.push(this.db.tx.context_contexts[lookup(\"key\", contextIdentifier.key)].update({ status: \"open\", updatedAt: new Date() }))\n }\n\n await this.db.transact(txs)\n }\n\n public async updateEvent(eventId: string, event: ContextEvent): Promise<ContextEvent> {\n await this.db.transact([\n this.db.tx.context_events[eventId].update(event)\n ])\n return await this.getEvent(eventId)\n }\n\n public async getEvent(eventId: string): Promise<ContextEvent> {\n const event = await this.db.query({\n context_events: {\n $: { \n where: { id: eventId as any }\n }\n }\n })\n return event.context_events?.[0] as ContextEvent\n }\n\n public async getEvents(contextIdentifier: ContextIdentifier): Promise<ContextEvent[]> {\n\n let contextWhere: { context: string } | { context: ReturnType<typeof lookup> };\n if (contextIdentifier.id) {\n contextWhere = { context: contextIdentifier.id }\n } else {\n contextWhere = { context: lookup(\"key\", contextIdentifier.key) }\n }\n\n const events = await this.db.query({\n context_events: {\n $: {\n where: contextWhere as any,\n limit: 30,\n order: {\n createdAt: 'asc',\n },\n }\n }\n })\n return events.context_events as ContextEvent[]\n }\n\n public async readEventStream(stream: ReadableStream): Promise<{\n eventId: string | undefined\n chunks: StreamChunk[]\n persistedEvent: any\n }> {\n const reader = stream.getReader()\n const chunks: StreamChunk[] = []\n let firstChunk: StreamChunk | undefined\n\n while (true) {\n const { value, done } = await reader.read()\n if (done) {\n break\n }\n const currentChunk = value as StreamChunk\n if (!firstChunk) {\n firstChunk = currentChunk\n }\n chunks.push(currentChunk)\n }\n\n if (!firstChunk) {\n throw new Error(\"No chunks received from stream\")\n }\n\n const eventId = firstChunk.messageId\n\n if (!eventId || typeof eventId !== 'string') {\n throw new Error(\"Event ID not found in stream chunks\")\n }\n\n const query = await this.db.query({\n context_events: {\n $: {\n where: { id: eventId as any },\n limit: 1,\n fields: [\"id\", \"channel\", \"type\", \"status\", \"createdAt\", \"content\"],\n },\n },\n })\n\n const persistedEvent = Array.isArray(query.context_events) ? query.context_events[0] : undefined\n\n return {\n eventId,\n chunks,\n persistedEvent,\n }\n }\n}"]}
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;AAAA,4CAA6F;AAgB7F,MAAa,YAAY;IAIrB,YAAY,EAAsD;QAC9D,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;IAChB,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAI,iBAA2C;QAC1E,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,aAAa,EAAK,CAAA;QAClC,CAAC;QAED,IAAI,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAI,iBAAiB,CAAC,CAAA;QACzD,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,IAAI,CAAC,aAAa,CAAI,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAA;QACrH,CAAC;aAAM,CAAC;YACJ,OAAO,OAAO,CAAA;QAClB,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,aAAa,CAAI,UAAmC,EAAE,SAAkB;QACjF,IAAI,WAAW,GAA8F;YACzG,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,OAAO,EAAE,EAAE;YACX,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,MAAM;SACjB,CAAA;QAED,MAAM,YAAY,GAAG,SAAS,IAAI,IAAA,UAAE,GAAE,CAAA;QACtC,IAAI,UAAU,EAAE,GAAG,EAAE,CAAC;YAClB,WAAW,GAAG;gBACV,GAAG,WAAW;gBACd,GAAG,EAAE,UAAU,CAAC,GAAG;aACtB,CAAA;QACL,CAAC;QAED,MAAM,IAAI,CAAC,EAAE,CAAC,QAAQ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gBACd,UAAU,GAAG,YAAY,CAAA;YAC7B,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QAC7B,CAAC;QAED,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;QACrD,CAAC;QAED,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAA;QAEpC,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QAC1D,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC;YAC9B,cAAc,EAAE;gBACZ,CAAC,EAAE;oBACC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAc,EAAE;oBAC7B,KAAK,EAAE,CAAC;oBACR,MAAM,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,CAAC;iBACtE;aACJ;SACJ,CAAC,CAAA;QAEF,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QAEhG,OAAO;YACH,OAAO;YACP,MAAM;YACN,cAAc;SACjB,CAAA;IACL,CAAC;CACJ;AAxPD,oCAwPC","sourcesContent":["import { id, init, InstaQLEntity, lookup, type InstantAdminDatabase } from \"@instantdb/admin\"\nimport { storyDomain } from \"./schema\"\nimport { SchemaOf } from \"@ekairos/domain\"\n\nexport type StoredContext<Context> = Omit<InstaQLEntity<typeof storyDomain, 'context_contexts'>, 'content'> & { content: Context | null }\nexport type ContextIdentifier = { id: string; key?: never } | { key: string; id?: never }\n\nexport type ContextEvent = InstaQLEntity<typeof storyDomain, 'context_events'> & { content: any }\n\nexport type StreamChunk = {\n type: string\n messageId?: string\n content?: string\n [key: string]: unknown\n}\n\nexport class AgentService {\n\n private db: InstantAdminDatabase<SchemaOf<typeof storyDomain>>\n\n constructor(db: InstantAdminDatabase<SchemaOf<typeof storyDomain>>) {\n this.db = db\n }\n\n public async getOrCreateContext<C>(contextIdentifier: ContextIdentifier | null): Promise<StoredContext<C>> {\n if (!contextIdentifier) {\n return this.createContext<C>()\n }\n\n let context = await this.getContext<C>(contextIdentifier)\n if (!context) {\n return this.createContext<C>(contextIdentifier.key ? { key: contextIdentifier.key } : null, contextIdentifier.id)\n } else {\n return context\n }\n }\n\n public async createContext<C>(contextKey?: { key: string } | null, contextId?: string): Promise<StoredContext<C>> {\n let contextData: { createdAt: Date; content: Record<string, unknown>; key: string | null; status: \"open\" } = {\n createdAt: new Date(),\n content: {},\n key: null,\n status: \"open\"\n }\n\n const newContextId = contextId ?? id()\n if (contextKey?.key) {\n contextData = {\n ...contextData,\n key: contextKey.key\n }\n }\n\n await this.db.transact([\n this.db.tx.context_contexts[newContextId].create(contextData)\n ])\n return this.getContext<C>({ id: newContextId })\n }\n\n public async getContext<C>(contextIdentifier: ContextIdentifier): Promise<StoredContext<C>> {\n let context;\n try {\n if (contextIdentifier.id) {\n const tRes = await this.db.query({\n context_contexts: {\n $: { where: { id: contextIdentifier.id as any }, limit: 1 }\n }\n })\n context = tRes.context_contexts?.[0]\n }\n\n if (contextIdentifier.key) {\n const tRes = await this.db.query({\n context_contexts: {\n $: { where: { key: contextIdentifier.key } }\n }\n })\n context = tRes.context_contexts?.[0]\n }\n\n return context as unknown as StoredContext<C>\n } catch (error: any) {\n console.error(\"Error getting context\", error)\n throw new Error(\"Error getting context: \" + error.message)\n }\n }\n\n public async updateContextContent<C>(contextIdentifier: ContextIdentifier, content: C): Promise<StoredContext<C>> {\n\n const contextDBIdentifier = contextIdentifier.id ?? lookup(\"key\", contextIdentifier.key)\n\n await this.db.transact([\n this.db.tx.context_contexts[contextDBIdentifier].update({\n content: content,\n updatedAt: new Date()\n })\n ])\n\n return this.getContext<C>(contextIdentifier)\n }\n\n public async saveEvent(contextIdentifier: ContextIdentifier, event: ContextEvent): Promise<ContextEvent> {\n const txs = [\n // Use update instead of create to handle both new and existing events\n this.db.tx.context_events[event.id].update({\n ...event,\n status: \"stored\"\n })\n ]\n\n if (contextIdentifier.id) {\n txs.push(this.db.tx.context_events[event.id].link({ context: contextIdentifier.id }))\n } else {\n txs.push(this.db.tx.context_events[event.id].link({ context: lookup(\"key\", contextIdentifier.key) }))\n }\n\n await this.db.transact(txs)\n\n return await this.getEvent(event.id)\n }\n\n public async createExecution(contextIdentifier: ContextIdentifier, triggerEventId: string, reactionEventId: string): Promise<{ id: string }> {\n const executionId = id()\n const execCreate = this.db.tx.story_executions[executionId].create({\n createdAt: new Date(),\n status: \"executing\",\n })\n\n const txs: any[] = [execCreate]\n\n if (contextIdentifier.id) {\n txs.push(this.db.tx.story_executions[executionId].link({ context: contextIdentifier.id }))\n txs.push(this.db.tx.context_contexts[contextIdentifier.id].link({ currentExecution: executionId }))\n } else {\n const ctxLookup = lookup(\"key\", contextIdentifier.key)\n txs.push(this.db.tx.story_executions[executionId].link({ context: ctxLookup }))\n txs.push(this.db.tx.context_contexts[ctxLookup].link({ currentExecution: executionId }))\n }\n\n txs.push(this.db.tx.story_executions[executionId].link({ trigger: triggerEventId }))\n txs.push(this.db.tx.story_executions[executionId].link({ reaction: reactionEventId }))\n\n await this.db.transact(txs)\n\n return { id: executionId }\n }\n\n public async updateContextStatus(contextIdentifier: ContextIdentifier, status: \"open\" | \"streaming\" | \"closed\"): Promise<void> {\n const txs: any[] = []\n \n if (contextIdentifier.id) {\n txs.push(this.db.tx.context_contexts[contextIdentifier.id].update({ status, updatedAt: new Date() }))\n } else {\n txs.push(this.db.tx.context_contexts[lookup(\"key\", contextIdentifier.key)].update({ status, updatedAt: new Date() }))\n }\n\n await this.db.transact(txs)\n }\n\n public async completeExecution(contextIdentifier: ContextIdentifier, executionId: string, status: \"completed\" | \"failed\"): Promise<void> {\n const txs: any[] = []\n txs.push(this.db.tx.story_executions[executionId].update({ status, updatedAt: new Date() }))\n\n // Update context status to \"open\" when execution completes\n if (contextIdentifier.id) {\n txs.push(this.db.tx.context_contexts[contextIdentifier.id].update({ status: \"open\", updatedAt: new Date() }))\n // optionally unlink currentExecution if desired\n } else {\n txs.push(this.db.tx.context_contexts[lookup(\"key\", contextIdentifier.key)].update({ status: \"open\", updatedAt: new Date() }))\n }\n\n await this.db.transact(txs)\n }\n\n public async updateEvent(eventId: string, event: ContextEvent): Promise<ContextEvent> {\n await this.db.transact([\n this.db.tx.context_events[eventId].update(event)\n ])\n return await this.getEvent(eventId)\n }\n\n public async getEvent(eventId: string): Promise<ContextEvent> {\n const event = await this.db.query({\n context_events: {\n $: { \n where: { id: eventId as any }\n }\n }\n })\n return event.context_events?.[0] as ContextEvent\n }\n\n public async getEvents(contextIdentifier: ContextIdentifier): Promise<ContextEvent[]> {\n\n let contextWhere: { context: string } | { context: ReturnType<typeof lookup> };\n if (contextIdentifier.id) {\n contextWhere = { context: contextIdentifier.id }\n } else {\n contextWhere = { context: lookup(\"key\", contextIdentifier.key) }\n }\n\n const events = await this.db.query({\n context_events: {\n $: {\n where: contextWhere as any,\n limit: 30,\n order: {\n createdAt: 'asc',\n },\n }\n }\n })\n return events.context_events as ContextEvent[]\n }\n\n public async readEventStream(stream: ReadableStream): Promise<{\n eventId: string | undefined\n chunks: StreamChunk[]\n persistedEvent: any\n }> {\n const reader = stream.getReader()\n const chunks: StreamChunk[] = []\n let firstChunk: StreamChunk | undefined\n\n while (true) {\n const { value, done } = await reader.read()\n if (done) {\n break\n }\n const currentChunk = value as StreamChunk\n if (!firstChunk) {\n firstChunk = currentChunk\n }\n chunks.push(currentChunk)\n }\n\n if (!firstChunk) {\n throw new Error(\"No chunks received from stream\")\n }\n\n const eventId = firstChunk.messageId\n\n if (!eventId || typeof eventId !== 'string') {\n throw new Error(\"Event ID not found in stream chunks\")\n }\n\n const query = await this.db.query({\n context_events: {\n $: {\n where: { id: eventId as any },\n limit: 1,\n fields: [\"id\", \"channel\", \"type\", \"status\", \"createdAt\", \"content\"],\n },\n },\n })\n\n const persistedEvent = Array.isArray(query.context_events) ? query.context_events[0] : undefined\n\n return {\n eventId,\n chunks,\n persistedEvent,\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,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AA;YACD,aAAa,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC;QACD,OAAO,EAAE,CAAC,CAAU,EAAE,EAAE;YACtB,YAAY,CAAC,CAAC,CAAC,CAAA;YACf,OAAO,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QACnD,CAAC;KACF,CAAC;QACF,mFAAmF;SAClF,WAAW,CACV,IAAI,eAAe,CAAiC;QAClD,SAAS,CAAC,KAAK,EAAE,UAAU;YACzB,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO;gBAAE,OAAM;YAClC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ;gBAAE,OAAM;YACnC,UAAU,CAAC,OAAO,CAAC,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,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